Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"@superdoc-dev/template-builder": "link:../.",
"react": "^19.2.0",
"react-dom": "^19.2.0",
"superdoc": "^0.31.2"
"superdoc": "^0.35.3"
},
"devDependencies": {
"@types/react": "^19.2.6",
Expand Down
10 changes: 5 additions & 5 deletions demo/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"peerDependencies": {
"react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0",
"react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0",
"superdoc": "^0.31.2"
"superdoc": "^0.35.3"
},
"devDependencies": {
"@commitlint/cli": "^20.1.0",
Expand Down
10 changes: 5 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

163 changes: 81 additions & 82 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
type Editor = NonNullable<SuperDoc['activeEditor']>;

const getTemplateFieldsFromEditor = (editor: Editor): Types.TemplateField[] => {
const structuredContentHelpers = (editor.helpers as any)?.structuredContentCommands;

Check warning on line 12 in src/index.tsx

View workflow job for this annotation

GitHub Actions / validate

Unexpected any. Specify a different type

if (!structuredContentHelpers?.getStructuredContentTags) {
return [];
Expand All @@ -17,7 +17,7 @@

const tags = structuredContentHelpers.getStructuredContentTags(editor.state) || [];

return tags.map((entry: any) => {

Check warning on line 20 in src/index.tsx

View workflow job for this annotation

GitHub Actions / validate

Unexpected any. Specify a different type
const node = entry?.node ?? entry;
const attrs = node?.attrs ?? {};
const nodeType = node?.type?.name || '';
Expand Down Expand Up @@ -151,7 +151,7 @@

const trigger = menu.trigger || '{{';

const availableFields = fieldsRef.current.available || [];

Check warning on line 154 in src/index.tsx

View workflow job for this annotation

GitHub Actions / validate

The 'availableFields' logical expression could make the dependencies of useCallback Hook (at line 166) change on every render. Move it inside the useCallback callback. Alternatively, wrap the initialization of 'availableFields' in its own useMemo() Hook

const computeFilteredFields = useCallback(
(query: string) => {
Expand Down Expand Up @@ -367,101 +367,100 @@
const initSuperDoc = async () => {
const { SuperDoc } = await import('superdoc');

const config: Record<string, unknown> = {
selector: containerRef.current!,
document: document?.source,
documentMode: document?.mode || 'editing',
onReady: () => {
if (instance.activeEditor) {
const editor = instance.activeEditor;

editor.on('update', ({ editor: e }: any) => {
const { state } = e;
const { from } = state.selection;

if (from >= trigger.length) {
const triggerStart = from - trigger.length;
const text = state.doc.textBetween(triggerStart, from);

if (text === trigger) {
const coords = e.view.coordsAtPos(from);
const bounds = clampToViewport(new DOMRect(coords.left, coords.top, 0, 0));

const cleanup = () => {
const editor = superdocRef.current?.activeEditor;
if (!editor) return;
const currentPos = editor.state.selection.from;
const tr = editor.state.tr.delete(triggerStart, currentPos);
(editor as any).view.dispatch(tr);
};

triggerCleanupRef.current = cleanup;
menuTriggerFromRef.current = from;
setMenuPosition(bounds);
setMenuVisible(true);
resetMenuFilter();

onTrigger?.({
position: { from: triggerStart, to: from },
bounds,
cleanup,
});

return;
}
}

if (!menuVisibleRef.current) {
return;
}
const modules: Record<string, unknown> = {
comments: false,
...(toolbarSettings && {
toolbar: {
selector: toolbarSettings.selector,
toolbarGroups: toolbarSettings.config.toolbarGroups || ['center'],
excludeItems: toolbarSettings.config.excludeItems || [],
...toolbarSettings.config,
},
}),
};

if (menuTriggerFromRef.current == null) {
setMenuVisible(false);
const handleReady = () => {
if (instance.activeEditor) {
const editor = instance.activeEditor;

editor.on('update', ({ editor: e }: any) => {

Check warning on line 386 in src/index.tsx

View workflow job for this annotation

GitHub Actions / validate

Unexpected any. Specify a different type
const { state } = e;
const { from } = state.selection;

if (from >= trigger.length) {
const triggerStart = from - trigger.length;
const text = state.doc.textBetween(triggerStart, from);

if (text === trigger) {
const coords = e.view.coordsAtPos(from);
const bounds = clampToViewport(new DOMRect(coords.left, coords.top, 0, 0));

const cleanup = () => {
const editor = superdocRef.current?.activeEditor;
if (!editor) return;
const currentPos = editor.state.selection.from;
const tr = editor.state.tr.delete(triggerStart, currentPos);
(editor as any).view.dispatch(tr);

Check warning on line 403 in src/index.tsx

View workflow job for this annotation

GitHub Actions / validate

Unexpected any. Specify a different type
};

triggerCleanupRef.current = cleanup;
menuTriggerFromRef.current = from;
setMenuPosition(bounds);
setMenuVisible(true);
resetMenuFilter();
return;
}

if (from < menuTriggerFromRef.current) {
setMenuVisible(false);
menuTriggerFromRef.current = null;
resetMenuFilter();
onTrigger?.({
position: { from: triggerStart, to: from },
bounds,
cleanup,
});

return;
}
}

if (!menuVisibleRef.current) {
return;
}

if (menuTriggerFromRef.current == null) {
setMenuVisible(false);
resetMenuFilter();
return;
}

if (from < menuTriggerFromRef.current) {
setMenuVisible(false);
menuTriggerFromRef.current = null;
resetMenuFilter();
return;
}

const queryText = state.doc.textBetween(menuTriggerFromRef.current, from);
updateMenuFilter(queryText);

const coords = e.view.coordsAtPos(from);
const bounds = clampToViewport(new DOMRect(coords.left, coords.top, 0, 0));
setMenuPosition(bounds);
});

const queryText = state.doc.textBetween(menuTriggerFromRef.current, from);
updateMenuFilter(queryText);

const coords = e.view.coordsAtPos(from);
const bounds = clampToViewport(new DOMRect(coords.left, coords.top, 0, 0));
setMenuPosition(bounds);
});

editor.on('update', () => {
discoverFields(editor);
});

editor.on('update', () => {
discoverFields(editor);
}
});

discoverFields(editor);
}

onReady?.();
},
onReady?.();
};

const instance = new SuperDoc({
selector: containerRef.current!,
document: document?.source,
documentMode: document?.mode || 'editing',
...config,
...(toolbarSettings && {
toolbar: toolbarSettings.selector,
modules: {
toolbar: {
selector: toolbarSettings.selector,
toolbarGroups: toolbarSettings.config.toolbarGroups || ['center'],
excludeItems: toolbarSettings.config.excludeItems || [],
...toolbarSettings.config,
},
},
}),
modules,
toolbar: toolbarSettings?.selector,
onReady: handleReady,
});

superdocRef.current = instance;
Expand All @@ -481,7 +480,7 @@

superdocRef.current = null;
};
}, [document?.source, document?.mode, trigger, discoverFields, onReady, onTrigger, toolbar]);

Check warning on line 483 in src/index.tsx

View workflow job for this annotation

GitHub Actions / validate

React Hook useEffect has missing dependencies: 'resetMenuFilter', 'toolbarSettings', and 'updateMenuFilter'. Either include them or remove the dependency array

const handleMenuSelect = useCallback(
async (field: Types.FieldDefinition) => {
Expand Down Expand Up @@ -531,7 +530,7 @@
const editor = superdocRef.current?.activeEditor;
if (!editor) return;

const structuredContentHelpers = (editor.helpers as any)?.structuredContentCommands;

Check warning on line 533 in src/index.tsx

View workflow job for this annotation

GitHub Actions / validate

Unexpected any. Specify a different type

if (!structuredContentHelpers) return;

Expand Down
Loading