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
13 changes: 4 additions & 9 deletions examples/typescript-example/src/components/DocumentEditor.tsx
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion packages/super-editor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
27 changes: 18 additions & 9 deletions packages/super-editor/src/core/Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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());
}

}
2 changes: 1 addition & 1 deletion packages/superdoc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading