diff --git a/examples/typescript-example/src/components/DocumentEditor.tsx b/examples/typescript-example/src/components/DocumentEditor.tsx index 8b0052205c..007103749d 100644 --- a/examples/typescript-example/src/components/DocumentEditor.tsx +++ b/examples/typescript-example/src/components/DocumentEditor.tsx @@ -1,5 +1,6 @@ import { SuperDoc, Config } from '@harbour-enterprises/superdoc'; import { Editor } from '@harbour-enterprises/superdoc/super-editor' + import '@harbour-enterprises/superdoc/style.css'; import { useEffect, useRef } from 'react'; @@ -24,15 +25,9 @@ const DocumentEditor = ({ selector: '#superdoc', toolbar: 'superdoc-toolbar', documentMode: readOnly ? 'viewing' : 'editing', - documents: [{ - id: documentId, - type: documentType, - data: initialData - }], - onReady: (editor: { superdoc: SuperDoc }) => { - if (onEditorReady) { - onEditorReady(editor); - } + onReady: (activeSuperDoc: SuperDoc) => { + const superEditor = activeSuperDoc.activeEditor; + console.debug('SuperDoc editor is ready', superEditor); }, onEditorCreate: (editor: Editor) => { console.log('Editor created', editor); diff --git a/packages/super-editor/package.json b/packages/super-editor/package.json index efd232a221..e0ed687d72 100644 --- a/packages/super-editor/package.json +++ b/packages/super-editor/package.json @@ -8,7 +8,8 @@ ], "exports": { ".": { - "import": "./dist/super-editor.es.js" + "import": "./dist/super-editor.es.js", + "types": "./dist/index.d.ts" }, "./converter": { "import": "./dist/converter.es.js" diff --git a/packages/super-editor/src/core/Editor.js b/packages/super-editor/src/core/Editor.js index 1a1dfc19a5..493e68e185 100644 --- a/packages/super-editor/src/core/Editor.js +++ b/packages/super-editor/src/core/Editor.js @@ -24,8 +24,17 @@ import { } from '@extensions/comment/comments-helpers.js'; import DocxZipper from '@core/DocxZipper.js'; +/** + * @typedef {Object} FieldValue + * @property {string} input_id The id of the input field + * @property {string} input_value The value to insert into the field + */ + /** * Editor main class. + * + * Expects a config object. + * @class */ export class Editor extends EventEmitter { #commandService; @@ -1213,21 +1222,23 @@ export class Editor extends EventEmitter { * pre-process the document as needed prior to running in the annotator. * * Currently this is only used for table generation but additional pre-processing can be done here. - * @param {Array[Object]} annotationValues + * + * @param {FieldValue[]} annotationValues * @returns {void} */ - prepareForAnnotations(annotationValues = [], hiddenIds = []) { + prepareForAnnotations(annotationValues = []) { const { tr } = this.state; const { dispatch } = this.view; - const newTr = AnnotatorServices.processTables({ editor: this, tr, annotationValues, hiddenIds }); + const newTr = AnnotatorServices.processTables({ editor: this, tr, annotationValues }); this.view.dispatch(newTr); } /** * Annotate the document with the given annotation values. * - * @param {Array[Object]} annotationValues - * @param {Array[String]} hiddenIds + * @param {FieldValue[]} annotationValues List of field values to apply. + * @param {String[]} hiddenIds List of field ids to remove from the document. + * @returns {void} */ annotate(annotationValues = [], hiddenIds = []) { const { state, view, schema } = this; @@ -1241,10 +1252,8 @@ export class Editor extends EventEmitter { hiddenFieldIds: hiddenIds }); - // 3) Finally dispatch *once*: - if (tr.docChanged) { - view.dispatch(tr.scrollIntoView()); - } + // Dispatch everything in a single transaction, which makes this undo-able in a single undo + if (tr.docChanged) view.dispatch(tr.scrollIntoView()); } } diff --git a/packages/superdoc/package.json b/packages/superdoc/package.json index ce9cb901a0..8bf9cb412a 100644 --- a/packages/superdoc/package.json +++ b/packages/superdoc/package.json @@ -21,7 +21,7 @@ }, "./super-editor": { "import": "./dist/super-editor.es.js", - "types": "./dist/super-editor/src/index.d.ts" + "types": "./dist/super-editor/index.d.ts" }, "./super-editor/style.css": { "import": "./dist/super-editor/style.css"