Skip to content

Commit 6bc2471

Browse files
authored
Merge pull request #521 from Harbour-Enterprises/nick/fix-editor-typedefs-rollup
Fix editor type exports when rolling into SuperDoc, add annotate() types
2 parents 83207c8 + ad17199 commit 6bc2471

4 files changed

Lines changed: 25 additions & 20 deletions

File tree

examples/typescript-example/src/components/DocumentEditor.tsx

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { SuperDoc, Config } from '@harbour-enterprises/superdoc';
22
import { Editor } from '@harbour-enterprises/superdoc/super-editor'
3+
34
import '@harbour-enterprises/superdoc/style.css';
45
import { useEffect, useRef } from 'react';
56

@@ -24,15 +25,9 @@ const DocumentEditor = ({
2425
selector: '#superdoc',
2526
toolbar: 'superdoc-toolbar',
2627
documentMode: readOnly ? 'viewing' : 'editing',
27-
documents: [{
28-
id: documentId,
29-
type: documentType,
30-
data: initialData
31-
}],
32-
onReady: (editor: { superdoc: SuperDoc }) => {
33-
if (onEditorReady) {
34-
onEditorReady(editor);
35-
}
28+
onReady: (activeSuperDoc: SuperDoc) => {
29+
const superEditor = activeSuperDoc.activeEditor;
30+
console.debug('SuperDoc editor is ready', superEditor);
3631
},
3732
onEditorCreate: (editor: Editor) => {
3833
console.log('Editor created', editor);

packages/super-editor/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
],
99
"exports": {
1010
".": {
11-
"import": "./dist/super-editor.es.js"
11+
"import": "./dist/super-editor.es.js",
12+
"types": "./dist/index.d.ts"
1213
},
1314
"./converter": {
1415
"import": "./dist/converter.es.js"

packages/super-editor/src/core/Editor.js

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,17 @@ import {
2424
} from '@extensions/comment/comments-helpers.js';
2525
import DocxZipper from '@core/DocxZipper.js';
2626

27+
/**
28+
* @typedef {Object} FieldValue
29+
* @property {string} input_id The id of the input field
30+
* @property {string} input_value The value to insert into the field
31+
*/
32+
2733
/**
2834
* Editor main class.
35+
*
36+
* Expects a config object.
37+
* @class
2938
*/
3039
export class Editor extends EventEmitter {
3140
#commandService;
@@ -1213,21 +1222,23 @@ export class Editor extends EventEmitter {
12131222
* pre-process the document as needed prior to running in the annotator.
12141223
*
12151224
* Currently this is only used for table generation but additional pre-processing can be done here.
1216-
* @param {Array[Object]} annotationValues
1225+
*
1226+
* @param {FieldValue[]} annotationValues
12171227
* @returns {void}
12181228
*/
1219-
prepareForAnnotations(annotationValues = [], hiddenIds = []) {
1229+
prepareForAnnotations(annotationValues = []) {
12201230
const { tr } = this.state;
12211231
const { dispatch } = this.view;
1222-
const newTr = AnnotatorServices.processTables({ editor: this, tr, annotationValues, hiddenIds });
1232+
const newTr = AnnotatorServices.processTables({ editor: this, tr, annotationValues });
12231233
this.view.dispatch(newTr);
12241234
}
12251235

12261236
/**
12271237
* Annotate the document with the given annotation values.
12281238
*
1229-
* @param {Array[Object]} annotationValues
1230-
* @param {Array[String]} hiddenIds
1239+
* @param {FieldValue[]} annotationValues List of field values to apply.
1240+
* @param {String[]} hiddenIds List of field ids to remove from the document.
1241+
* @returns {void}
12311242
*/
12321243
annotate(annotationValues = [], hiddenIds = []) {
12331244
const { state, view, schema } = this;
@@ -1241,10 +1252,8 @@ export class Editor extends EventEmitter {
12411252
hiddenFieldIds: hiddenIds
12421253
});
12431254

1244-
// 3) Finally dispatch *once*:
1245-
if (tr.docChanged) {
1246-
view.dispatch(tr.scrollIntoView());
1247-
}
1255+
// Dispatch everything in a single transaction, which makes this undo-able in a single undo
1256+
if (tr.docChanged) view.dispatch(tr.scrollIntoView());
12481257
}
12491258

12501259
}

packages/superdoc/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
},
2222
"./super-editor": {
2323
"import": "./dist/super-editor.es.js",
24-
"types": "./dist/super-editor/src/index.d.ts"
24+
"types": "./dist/super-editor/index.d.ts"
2525
},
2626
"./super-editor/style.css": {
2727
"import": "./dist/super-editor/style.css"

0 commit comments

Comments
 (0)