@docengine/editor 0.0.0-stage → 0.0.106
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +116 -2
- package/dist/DocEnginePdfViewer.zip +0 -0
- package/dist/editor-lwc.css +7425 -0
- package/dist/editor-lwc.js +1595 -0
- package/dist/editor-lwc.js.map +1 -0
- package/dist/editor.js +89754 -0
- package/dist/pdf-viewer/viewer.html +40 -0
- package/dist/pdf-viewer/viewer.js +1 -0
- package/lib/.tsbuildinfo +1 -0
- package/lib/catalog/catalog-provider.d.ts +27 -0
- package/lib/catalog/catalog-provider.d.ts.map +1 -0
- package/lib/catalog/catalog-provider.js +88 -0
- package/lib/catalog/catalog-provider.js.map +1 -0
- package/lib/core/computed-formula.d.ts +3 -0
- package/lib/core/computed-formula.d.ts.map +1 -0
- package/lib/core/computed-formula.js +2 -0
- package/lib/core/computed-formula.js.map +1 -0
- package/lib/core/computed-formula.test.d.ts +2 -0
- package/lib/core/computed-formula.test.d.ts.map +1 -0
- package/lib/core/computed-formula.test.js +204 -0
- package/lib/core/computed-formula.test.js.map +1 -0
- package/lib/core/document-display-defaults.d.ts +2 -0
- package/lib/core/document-display-defaults.d.ts.map +1 -0
- package/lib/core/document-display-defaults.js +2 -0
- package/lib/core/document-display-defaults.js.map +1 -0
- package/lib/core/document-history.d.ts +23 -0
- package/lib/core/document-history.d.ts.map +1 -0
- package/lib/core/document-history.js +87 -0
- package/lib/core/document-history.js.map +1 -0
- package/lib/core/document-history.test.d.ts +2 -0
- package/lib/core/document-history.test.d.ts.map +1 -0
- package/lib/core/document-history.test.js +47 -0
- package/lib/core/document-history.test.js.map +1 -0
- package/lib/core/document-io.d.ts +2 -0
- package/lib/core/document-io.d.ts.map +1 -0
- package/lib/core/document-io.js +2 -0
- package/lib/core/document-io.js.map +1 -0
- package/lib/core/document-io.test.d.ts +2 -0
- package/lib/core/document-io.test.d.ts.map +1 -0
- package/lib/core/document-io.test.js +616 -0
- package/lib/core/document-io.test.js.map +1 -0
- package/lib/core/document-section-defaults.d.ts +27 -0
- package/lib/core/document-section-defaults.d.ts.map +1 -0
- package/lib/core/document-section-defaults.js +60 -0
- package/lib/core/document-section-defaults.js.map +1 -0
- package/lib/core/document-section-defaults.test.d.ts +2 -0
- package/lib/core/document-section-defaults.test.d.ts.map +1 -0
- package/lib/core/document-section-defaults.test.js +47 -0
- package/lib/core/document-section-defaults.test.js.map +1 -0
- package/lib/core/field-id.d.ts +2 -0
- package/lib/core/field-id.d.ts.map +1 -0
- package/lib/core/field-id.js +2 -0
- package/lib/core/field-id.js.map +1 -0
- package/lib/core/field-id.test.d.ts +2 -0
- package/lib/core/field-id.test.d.ts.map +1 -0
- package/lib/core/field-id.test.js +253 -0
- package/lib/core/field-id.test.js.map +1 -0
- package/lib/core/field-io/sectioned-document-io.d.ts +2 -0
- package/lib/core/field-io/sectioned-document-io.d.ts.map +1 -0
- package/lib/core/field-io/sectioned-document-io.js +2 -0
- package/lib/core/field-io/sectioned-document-io.js.map +1 -0
- package/lib/core/field-io/sectioned-document-io.test.d.ts +2 -0
- package/lib/core/field-io/sectioned-document-io.test.d.ts.map +1 -0
- package/lib/core/field-io/sectioned-document-io.test.js +511 -0
- package/lib/core/field-io/sectioned-document-io.test.js.map +1 -0
- package/lib/core/field-io/table-field-io.d.ts +2 -0
- package/lib/core/field-io/table-field-io.d.ts.map +1 -0
- package/lib/core/field-io/table-field-io.js +2 -0
- package/lib/core/field-io/table-field-io.js.map +1 -0
- package/lib/core/field-io/table-field-io.test.d.ts +2 -0
- package/lib/core/field-io/table-field-io.test.d.ts.map +1 -0
- package/lib/core/field-io/table-field-io.test.js +193 -0
- package/lib/core/field-io/table-field-io.test.js.map +1 -0
- package/lib/core/field-schemas.d.ts +2 -0
- package/lib/core/field-schemas.d.ts.map +1 -0
- package/lib/core/field-schemas.js +7 -0
- package/lib/core/field-schemas.js.map +1 -0
- package/lib/core/field-schemas.test.d.ts +2 -0
- package/lib/core/field-schemas.test.d.ts.map +1 -0
- package/lib/core/field-schemas.test.js +369 -0
- package/lib/core/field-schemas.test.js.map +1 -0
- package/lib/core/formula-field-index.d.ts +2 -0
- package/lib/core/formula-field-index.d.ts.map +1 -0
- package/lib/core/formula-field-index.js +2 -0
- package/lib/core/formula-field-index.js.map +1 -0
- package/lib/core/formula-field-index.test.d.ts +2 -0
- package/lib/core/formula-field-index.test.d.ts.map +1 -0
- package/lib/core/formula-field-index.test.js +110 -0
- package/lib/core/formula-field-index.test.js.map +1 -0
- package/lib/core/page-setup-styles.d.ts +69 -0
- package/lib/core/page-setup-styles.d.ts.map +1 -0
- package/lib/core/page-setup-styles.js +147 -0
- package/lib/core/page-setup-styles.js.map +1 -0
- package/lib/core/page-setup-styles.test.d.ts +2 -0
- package/lib/core/page-setup-styles.test.d.ts.map +1 -0
- package/lib/core/page-setup-styles.test.js +204 -0
- package/lib/core/page-setup-styles.test.js.map +1 -0
- package/lib/core/repeater-io.d.ts +2 -0
- package/lib/core/repeater-io.d.ts.map +1 -0
- package/lib/core/repeater-io.js +2 -0
- package/lib/core/repeater-io.js.map +1 -0
- package/lib/core/repeater-io.test.d.ts +2 -0
- package/lib/core/repeater-io.test.d.ts.map +1 -0
- package/lib/core/repeater-io.test.js +754 -0
- package/lib/core/repeater-io.test.js.map +1 -0
- package/lib/core/segment-tree.d.ts +2 -0
- package/lib/core/segment-tree.d.ts.map +1 -0
- package/lib/core/segment-tree.js +2 -0
- package/lib/core/segment-tree.js.map +1 -0
- package/lib/core/segment-tree.test.d.ts +2 -0
- package/lib/core/segment-tree.test.d.ts.map +1 -0
- package/lib/core/segment-tree.test.js +39 -0
- package/lib/core/segment-tree.test.js.map +1 -0
- package/lib/create-editor.d.ts +160 -0
- package/lib/create-editor.d.ts.map +1 -0
- package/lib/create-editor.js +3373 -0
- package/lib/create-editor.js.map +1 -0
- package/lib/design/collection-tree-picker.d.ts +17 -0
- package/lib/design/collection-tree-picker.d.ts.map +1 -0
- package/lib/design/collection-tree-picker.js +295 -0
- package/lib/design/collection-tree-picker.js.map +1 -0
- package/lib/design/collection-tree-picker.test.d.ts +2 -0
- package/lib/design/collection-tree-picker.test.d.ts.map +1 -0
- package/lib/design/collection-tree-picker.test.js +94 -0
- package/lib/design/collection-tree-picker.test.js.map +1 -0
- package/lib/design/design-mode.d.ts +3 -0
- package/lib/design/design-mode.d.ts.map +1 -0
- package/lib/design/design-mode.js +7 -0
- package/lib/design/design-mode.js.map +1 -0
- package/lib/design/design-shell.d.ts +16 -0
- package/lib/design/design-shell.d.ts.map +1 -0
- package/lib/design/design-shell.js +68 -0
- package/lib/design/design-shell.js.map +1 -0
- package/lib/design/display-style-form.d.ts +10 -0
- package/lib/design/display-style-form.d.ts.map +1 -0
- package/lib/design/display-style-form.js +182 -0
- package/lib/design/display-style-form.js.map +1 -0
- package/lib/design/display-style-form.test.d.ts +2 -0
- package/lib/design/display-style-form.test.d.ts.map +1 -0
- package/lib/design/display-style-form.test.js +137 -0
- package/lib/design/display-style-form.test.js.map +1 -0
- package/lib/design/field-highlight-form.d.ts +10 -0
- package/lib/design/field-highlight-form.d.ts.map +1 -0
- package/lib/design/field-highlight-form.js +160 -0
- package/lib/design/field-highlight-form.js.map +1 -0
- package/lib/design/field-highlight-form.test.d.ts +2 -0
- package/lib/design/field-highlight-form.test.d.ts.map +1 -0
- package/lib/design/field-highlight-form.test.js +58 -0
- package/lib/design/field-highlight-form.test.js.map +1 -0
- package/lib/design/field-palette.d.ts +55 -0
- package/lib/design/field-palette.d.ts.map +1 -0
- package/lib/design/field-palette.js +216 -0
- package/lib/design/field-palette.js.map +1 -0
- package/lib/design/field-palette.test.d.ts +2 -0
- package/lib/design/field-palette.test.d.ts.map +1 -0
- package/lib/design/field-palette.test.js +79 -0
- package/lib/design/field-palette.test.js.map +1 -0
- package/lib/design/formula-field-picker.d.ts +15 -0
- package/lib/design/formula-field-picker.d.ts.map +1 -0
- package/lib/design/formula-field-picker.js +170 -0
- package/lib/design/formula-field-picker.js.map +1 -0
- package/lib/design/formula-field-picker.test.d.ts +2 -0
- package/lib/design/formula-field-picker.test.d.ts.map +1 -0
- package/lib/design/formula-field-picker.test.js +136 -0
- package/lib/design/formula-field-picker.test.js.map +1 -0
- package/lib/design/palette-block-drop.d.ts +7 -0
- package/lib/design/palette-block-drop.d.ts.map +1 -0
- package/lib/design/palette-block-drop.js +62 -0
- package/lib/design/palette-block-drop.js.map +1 -0
- package/lib/design/properties-panel.d.ts +22 -0
- package/lib/design/properties-panel.d.ts.map +1 -0
- package/lib/design/properties-panel.js +848 -0
- package/lib/design/properties-panel.js.map +1 -0
- package/lib/design/schema-editor-controller.d.ts +22 -0
- package/lib/design/schema-editor-controller.d.ts.map +1 -0
- package/lib/design/schema-editor-controller.js +1033 -0
- package/lib/design/schema-editor-controller.js.map +1 -0
- package/lib/design/schema-editor-controller.test.d.ts +2 -0
- package/lib/design/schema-editor-controller.test.d.ts.map +1 -0
- package/lib/design/schema-editor-controller.test.js +259 -0
- package/lib/design/schema-editor-controller.test.js.map +1 -0
- package/lib/design/schema-editor-modal.d.ts +4 -0
- package/lib/design/schema-editor-modal.d.ts.map +1 -0
- package/lib/design/schema-editor-modal.js +68 -0
- package/lib/design/schema-editor-modal.js.map +1 -0
- package/lib/design/schema-items-designer-modal.d.ts +3 -0
- package/lib/design/schema-items-designer-modal.d.ts.map +1 -0
- package/lib/design/schema-items-designer-modal.js +187 -0
- package/lib/design/schema-items-designer-modal.js.map +1 -0
- package/lib/design/schema-items-designer.d.ts +20 -0
- package/lib/design/schema-items-designer.d.ts.map +1 -0
- package/lib/design/schema-items-designer.js +394 -0
- package/lib/design/schema-items-designer.js.map +1 -0
- package/lib/design/schema-items-designer.test.d.ts +2 -0
- package/lib/design/schema-items-designer.test.d.ts.map +1 -0
- package/lib/design/schema-items-designer.test.js +115 -0
- package/lib/design/schema-items-designer.test.js.map +1 -0
- package/lib/design/style-toolbar-shared.d.ts +53 -0
- package/lib/design/style-toolbar-shared.d.ts.map +1 -0
- package/lib/design/style-toolbar-shared.js +196 -0
- package/lib/design/style-toolbar-shared.js.map +1 -0
- package/lib/domain/ophthalmology/catalogs.d.ts +107 -0
- package/lib/domain/ophthalmology/catalogs.d.ts.map +1 -0
- package/lib/domain/ophthalmology/catalogs.js +65 -0
- package/lib/domain/ophthalmology/catalogs.js.map +1 -0
- package/lib/domain/ophthalmology/life-anamnesis-tree.d.ts +13 -0
- package/lib/domain/ophthalmology/life-anamnesis-tree.d.ts.map +1 -0
- package/lib/domain/ophthalmology/life-anamnesis-tree.js +44 -0
- package/lib/domain/ophthalmology/life-anamnesis-tree.js.map +1 -0
- package/lib/domain/ophthalmology/norm-options.d.ts +9 -0
- package/lib/domain/ophthalmology/norm-options.d.ts.map +1 -0
- package/lib/domain/ophthalmology/norm-options.js +24 -0
- package/lib/domain/ophthalmology/norm-options.js.map +1 -0
- package/lib/domain/ophthalmology/ophthalmology-complaints-tree.d.ts +13 -0
- package/lib/domain/ophthalmology/ophthalmology-complaints-tree.d.ts.map +1 -0
- package/lib/domain/ophthalmology/ophthalmology-complaints-tree.js +48 -0
- package/lib/domain/ophthalmology/ophthalmology-complaints-tree.js.map +1 -0
- package/lib/domain/ophthalmology/ophthalmology-diagnoses.d.ts +6 -0
- package/lib/domain/ophthalmology/ophthalmology-diagnoses.d.ts.map +1 -0
- package/lib/domain/ophthalmology/ophthalmology-diagnoses.js +13 -0
- package/lib/domain/ophthalmology/ophthalmology-diagnoses.js.map +1 -0
- package/lib/domain/ophthalmology/vision-values.d.ts +21 -0
- package/lib/domain/ophthalmology/vision-values.d.ts.map +1 -0
- package/lib/domain/ophthalmology/vision-values.js +55 -0
- package/lib/domain/ophthalmology/vision-values.js.map +1 -0
- package/lib/export/document-pdf.d.ts +20 -0
- package/lib/export/document-pdf.d.ts.map +1 -0
- package/lib/export/document-pdf.js +39 -0
- package/lib/export/document-pdf.js.map +1 -0
- package/lib/export/document-pdf.sf-stub.d.ts +13 -0
- package/lib/export/document-pdf.sf-stub.d.ts.map +1 -0
- package/lib/export/document-pdf.sf-stub.js +19 -0
- package/lib/export/document-pdf.sf-stub.js.map +1 -0
- package/lib/export/preview-export-options.d.ts +17 -0
- package/lib/export/preview-export-options.d.ts.map +1 -0
- package/lib/export/preview-export-options.js +28 -0
- package/lib/export/preview-export-options.js.map +1 -0
- package/lib/export/preview-html-document.d.ts +10 -0
- package/lib/export/preview-html-document.d.ts.map +1 -0
- package/lib/export/preview-html-document.js +29 -0
- package/lib/export/preview-html-document.js.map +1 -0
- package/lib/export/preview-html-styles.d.ts +10 -0
- package/lib/export/preview-html-styles.d.ts.map +1 -0
- package/lib/export/preview-html-styles.js +527 -0
- package/lib/export/preview-html-styles.js.map +1 -0
- package/lib/export/preview-html-styles.test.d.ts +2 -0
- package/lib/export/preview-html-styles.test.d.ts.map +1 -0
- package/lib/export/preview-html-styles.test.js +56 -0
- package/lib/export/preview-html-styles.test.js.map +1 -0
- package/lib/export/preview-pdf-mount.d.ts +14 -0
- package/lib/export/preview-pdf-mount.d.ts.map +1 -0
- package/lib/export/preview-pdf-mount.js +41 -0
- package/lib/export/preview-pdf-mount.js.map +1 -0
- package/lib/export/preview-pdf-parity.test.d.ts +2 -0
- package/lib/export/preview-pdf-parity.test.d.ts.map +1 -0
- package/lib/export/preview-pdf-parity.test.js +217 -0
- package/lib/export/preview-pdf-parity.test.js.map +1 -0
- package/lib/fields/barcode-encode.d.ts +33 -0
- package/lib/fields/barcode-encode.d.ts.map +1 -0
- package/lib/fields/barcode-encode.js +118 -0
- package/lib/fields/barcode-encode.js.map +1 -0
- package/lib/fields/barcode-encode.test.d.ts +2 -0
- package/lib/fields/barcode-encode.test.d.ts.map +1 -0
- package/lib/fields/barcode-encode.test.js +38 -0
- package/lib/fields/barcode-encode.test.js.map +1 -0
- package/lib/fields/collect-field-values.test.d.ts +2 -0
- package/lib/fields/collect-field-values.test.d.ts.map +1 -0
- package/lib/fields/collect-field-values.test.js +71 -0
- package/lib/fields/collect-field-values.test.js.map +1 -0
- package/lib/fields/columns-serialize.test.d.ts +2 -0
- package/lib/fields/columns-serialize.test.d.ts.map +1 -0
- package/lib/fields/columns-serialize.test.js +68 -0
- package/lib/fields/columns-serialize.test.js.map +1 -0
- package/lib/fields/cross-section-reposition.d.ts +19 -0
- package/lib/fields/cross-section-reposition.d.ts.map +1 -0
- package/lib/fields/cross-section-reposition.js +185 -0
- package/lib/fields/cross-section-reposition.js.map +1 -0
- package/lib/fields/cross-section-reposition.test.d.ts +2 -0
- package/lib/fields/cross-section-reposition.test.d.ts.map +1 -0
- package/lib/fields/cross-section-reposition.test.js +190 -0
- package/lib/fields/cross-section-reposition.test.js.map +1 -0
- package/lib/fields/document-preview.d.ts +10 -0
- package/lib/fields/document-preview.d.ts.map +1 -0
- package/lib/fields/document-preview.js +781 -0
- package/lib/fields/document-preview.js.map +1 -0
- package/lib/fields/document-preview.test.d.ts +2 -0
- package/lib/fields/document-preview.test.d.ts.map +1 -0
- package/lib/fields/document-preview.test.js +1433 -0
- package/lib/fields/document-preview.test.js.map +1 -0
- package/lib/fields/field-clipboard.d.ts +32 -0
- package/lib/fields/field-clipboard.d.ts.map +1 -0
- package/lib/fields/field-clipboard.js +642 -0
- package/lib/fields/field-clipboard.js.map +1 -0
- package/lib/fields/field-clipboard.test.d.ts +2 -0
- package/lib/fields/field-clipboard.test.d.ts.map +1 -0
- package/lib/fields/field-clipboard.test.js +281 -0
- package/lib/fields/field-clipboard.test.js.map +1 -0
- package/lib/fields/field-display-style.d.ts +76 -0
- package/lib/fields/field-display-style.d.ts.map +1 -0
- package/lib/fields/field-display-style.js +429 -0
- package/lib/fields/field-display-style.js.map +1 -0
- package/lib/fields/field-display-style.test.d.ts +2 -0
- package/lib/fields/field-display-style.test.d.ts.map +1 -0
- package/lib/fields/field-display-style.test.js +299 -0
- package/lib/fields/field-display-style.test.js.map +1 -0
- package/lib/fields/field-keyboard.d.ts +9 -0
- package/lib/fields/field-keyboard.d.ts.map +1 -0
- package/lib/fields/field-keyboard.js +1118 -0
- package/lib/fields/field-keyboard.js.map +1 -0
- package/lib/fields/field-keyboard.test.d.ts +2 -0
- package/lib/fields/field-keyboard.test.d.ts.map +1 -0
- package/lib/fields/field-keyboard.test.js +390 -0
- package/lib/fields/field-keyboard.test.js.map +1 -0
- package/lib/fields/field-selection.d.ts +12 -0
- package/lib/fields/field-selection.d.ts.map +1 -0
- package/lib/fields/field-selection.js +123 -0
- package/lib/fields/field-selection.js.map +1 -0
- package/lib/fields/field-selection.test.d.ts +2 -0
- package/lib/fields/field-selection.test.d.ts.map +1 -0
- package/lib/fields/field-selection.test.js +67 -0
- package/lib/fields/field-selection.test.js.map +1 -0
- package/lib/fields/field-token-drag.test.d.ts +2 -0
- package/lib/fields/field-token-drag.test.d.ts.map +1 -0
- package/lib/fields/field-token-drag.test.js +55 -0
- package/lib/fields/field-token-drag.test.js.map +1 -0
- package/lib/fields/fill-defaults.test.d.ts +2 -0
- package/lib/fields/fill-defaults.test.d.ts.map +1 -0
- package/lib/fields/fill-defaults.test.js +70 -0
- package/lib/fields/fill-defaults.test.js.map +1 -0
- package/lib/fields/fill-field-focus.d.ts +51 -0
- package/lib/fields/fill-field-focus.d.ts.map +1 -0
- package/lib/fields/fill-field-focus.js +230 -0
- package/lib/fields/fill-field-focus.js.map +1 -0
- package/lib/fields/fill-field-focus.test.d.ts +2 -0
- package/lib/fields/fill-field-focus.test.d.ts.map +1 -0
- package/lib/fields/fill-field-focus.test.js +201 -0
- package/lib/fields/fill-field-focus.test.js.map +1 -0
- package/lib/fields/handlers/builtins.d.ts +3 -0
- package/lib/fields/handlers/builtins.d.ts.map +1 -0
- package/lib/fields/handlers/builtins.js +869 -0
- package/lib/fields/handlers/builtins.js.map +1 -0
- package/lib/fields/handlers/index.d.ts +4 -0
- package/lib/fields/handlers/index.d.ts.map +1 -0
- package/lib/fields/handlers/index.js +5 -0
- package/lib/fields/handlers/index.js.map +1 -0
- package/lib/fields/handlers/registry.d.ts +27 -0
- package/lib/fields/handlers/registry.d.ts.map +1 -0
- package/lib/fields/handlers/registry.js +69 -0
- package/lib/fields/handlers/registry.js.map +1 -0
- package/lib/fields/handlers/registry.test.d.ts +2 -0
- package/lib/fields/handlers/registry.test.d.ts.map +1 -0
- package/lib/fields/handlers/registry.test.js +203 -0
- package/lib/fields/handlers/registry.test.js.map +1 -0
- package/lib/fields/handlers/schema-form-dom.d.ts +36 -0
- package/lib/fields/handlers/schema-form-dom.d.ts.map +1 -0
- package/lib/fields/handlers/schema-form-dom.js +114 -0
- package/lib/fields/handlers/schema-form-dom.js.map +1 -0
- package/lib/fields/heading-line-breaks.test.d.ts +2 -0
- package/lib/fields/heading-line-breaks.test.d.ts.map +1 -0
- package/lib/fields/heading-line-breaks.test.js +755 -0
- package/lib/fields/heading-line-breaks.test.js.map +1 -0
- package/lib/fields/inline-field-from-selection.test.d.ts +2 -0
- package/lib/fields/inline-field-from-selection.test.d.ts.map +1 -0
- package/lib/fields/inline-field-from-selection.test.js +185 -0
- package/lib/fields/inline-field-from-selection.test.js.map +1 -0
- package/lib/fields/inline-fields.d.ts +150 -0
- package/lib/fields/inline-fields.d.ts.map +1 -0
- package/lib/fields/inline-fields.js +3408 -0
- package/lib/fields/inline-fields.js.map +1 -0
- package/lib/fields/logical-display.d.ts +8 -0
- package/lib/fields/logical-display.d.ts.map +1 -0
- package/lib/fields/logical-display.js +29 -0
- package/lib/fields/logical-display.js.map +1 -0
- package/lib/fields/logical-display.test.d.ts +2 -0
- package/lib/fields/logical-display.test.d.ts.map +1 -0
- package/lib/fields/logical-display.test.js +31 -0
- package/lib/fields/logical-display.test.js.map +1 -0
- package/lib/fields/manual-field-values.d.ts +87 -0
- package/lib/fields/manual-field-values.d.ts.map +1 -0
- package/lib/fields/manual-field-values.js +189 -0
- package/lib/fields/manual-field-values.js.map +1 -0
- package/lib/fields/manual-field-values.test.d.ts +2 -0
- package/lib/fields/manual-field-values.test.d.ts.map +1 -0
- package/lib/fields/manual-field-values.test.js +84 -0
- package/lib/fields/manual-field-values.test.js.map +1 -0
- package/lib/fields/pivot-table-field.d.ts +25 -0
- package/lib/fields/pivot-table-field.d.ts.map +1 -0
- package/lib/fields/pivot-table-field.js +408 -0
- package/lib/fields/pivot-table-field.js.map +1 -0
- package/lib/fields/plain-text-newlines.test.d.ts +2 -0
- package/lib/fields/plain-text-newlines.test.d.ts.map +1 -0
- package/lib/fields/plain-text-newlines.test.js +40 -0
- package/lib/fields/plain-text-newlines.test.js.map +1 -0
- package/lib/fields/repeater-field.d.ts +10 -0
- package/lib/fields/repeater-field.d.ts.map +1 -0
- package/lib/fields/repeater-field.js +48 -0
- package/lib/fields/repeater-field.js.map +1 -0
- package/lib/fields/rich-text.d.ts +27 -0
- package/lib/fields/rich-text.d.ts.map +1 -0
- package/lib/fields/rich-text.js +984 -0
- package/lib/fields/rich-text.js.map +1 -0
- package/lib/fields/table-field.d.ts +57 -0
- package/lib/fields/table-field.d.ts.map +1 -0
- package/lib/fields/table-field.js +836 -0
- package/lib/fields/table-field.js.map +1 -0
- package/lib/fields/table-field.test.d.ts +2 -0
- package/lib/fields/table-field.test.d.ts.map +1 -0
- package/lib/fields/table-field.test.js +456 -0
- package/lib/fields/table-field.test.js.map +1 -0
- package/lib/fields/tree-paths.d.ts +5 -0
- package/lib/fields/tree-paths.d.ts.map +1 -0
- package/lib/fields/tree-paths.js +7 -0
- package/lib/fields/tree-paths.js.map +1 -0
- package/lib/fields/tree-selection.d.ts +9 -0
- package/lib/fields/tree-selection.d.ts.map +1 -0
- package/lib/fields/tree-selection.js +39 -0
- package/lib/fields/tree-selection.js.map +1 -0
- package/lib/fields/tree.d.ts +7 -0
- package/lib/fields/tree.d.ts.map +1 -0
- package/lib/fields/tree.js +7 -0
- package/lib/fields/tree.js.map +1 -0
- package/lib/fields/wire-columns-resize.d.ts +6 -0
- package/lib/fields/wire-columns-resize.d.ts.map +1 -0
- package/lib/fields/wire-columns-resize.js +130 -0
- package/lib/fields/wire-columns-resize.js.map +1 -0
- package/lib/fields/wire-columns-resize.test.d.ts +2 -0
- package/lib/fields/wire-columns-resize.test.d.ts.map +1 -0
- package/lib/fields/wire-columns-resize.test.js +38 -0
- package/lib/fields/wire-columns-resize.test.js.map +1 -0
- package/lib/fields/wire-editorjs-native-drop-guard.d.ts +34 -0
- package/lib/fields/wire-editorjs-native-drop-guard.d.ts.map +1 -0
- package/lib/fields/wire-editorjs-native-drop-guard.js +453 -0
- package/lib/fields/wire-editorjs-native-drop-guard.js.map +1 -0
- package/lib/fields/wire-editorjs-native-drop-guard.test.d.ts +2 -0
- package/lib/fields/wire-editorjs-native-drop-guard.test.d.ts.map +1 -0
- package/lib/fields/wire-editorjs-native-drop-guard.test.js +230 -0
- package/lib/fields/wire-editorjs-native-drop-guard.test.js.map +1 -0
- package/lib/fields/wire-table-column-reorder.d.ts +23 -0
- package/lib/fields/wire-table-column-reorder.d.ts.map +1 -0
- package/lib/fields/wire-table-column-reorder.js +207 -0
- package/lib/fields/wire-table-column-reorder.js.map +1 -0
- package/lib/fields/wire-table-column-reorder.test.d.ts +2 -0
- package/lib/fields/wire-table-column-reorder.test.d.ts.map +1 -0
- package/lib/fields/wire-table-column-reorder.test.js +133 -0
- package/lib/fields/wire-table-column-reorder.test.js.map +1 -0
- package/lib/fields/wire-table-column-resize.d.ts +118 -0
- package/lib/fields/wire-table-column-resize.d.ts.map +1 -0
- package/lib/fields/wire-table-column-resize.js +406 -0
- package/lib/fields/wire-table-column-resize.js.map +1 -0
- package/lib/fields/wire-table-column-resize.test.d.ts +2 -0
- package/lib/fields/wire-table-column-resize.test.d.ts.map +1 -0
- package/lib/fields/wire-table-column-resize.test.js +407 -0
- package/lib/fields/wire-table-column-resize.test.js.map +1 -0
- package/lib/index.d.ts +39 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +37 -0
- package/lib/index.js.map +1 -0
- package/lib/node.d.ts +20 -0
- package/lib/node.d.ts.map +1 -0
- package/lib/node.js +20 -0
- package/lib/node.js.map +1 -0
- package/lib/registry/registry-context.d.ts +6 -0
- package/lib/registry/registry-context.d.ts.map +1 -0
- package/lib/registry/registry-context.js +39 -0
- package/lib/registry/registry-context.js.map +1 -0
- package/lib/registry/schema-registry.d.ts +18 -0
- package/lib/registry/schema-registry.d.ts.map +1 -0
- package/lib/registry/schema-registry.js +67 -0
- package/lib/registry/schema-registry.js.map +1 -0
- package/lib/services/image-upload.d.ts +27 -0
- package/lib/services/image-upload.d.ts.map +1 -0
- package/lib/services/image-upload.js +159 -0
- package/lib/services/image-upload.js.map +1 -0
- package/lib/services/image-upload.test.d.ts +2 -0
- package/lib/services/image-upload.test.d.ts.map +1 -0
- package/lib/services/image-upload.test.js +141 -0
- package/lib/services/image-upload.test.js.map +1 -0
- package/lib/sf-entry.d.ts +5 -0
- package/lib/sf-entry.d.ts.map +1 -0
- package/lib/sf-entry.js +15 -0
- package/lib/sf-entry.js.map +1 -0
- package/lib/sf-pdf-viewer/main.d.ts +2 -0
- package/lib/sf-pdf-viewer/main.d.ts.map +1 -0
- package/lib/sf-pdf-viewer/main.js +57 -0
- package/lib/sf-pdf-viewer/main.js.map +1 -0
- package/lib/tools/document-section.d.ts +54 -0
- package/lib/tools/document-section.d.ts.map +1 -0
- package/lib/tools/document-section.js +591 -0
- package/lib/tools/document-section.js.map +1 -0
- package/lib/tools/template-block.d.ts +18 -0
- package/lib/tools/template-block.d.ts.map +1 -0
- package/lib/tools/template-block.js +243 -0
- package/lib/tools/template-block.js.map +1 -0
- package/lib/ui/action-icons.d.ts +10 -0
- package/lib/ui/action-icons.d.ts.map +1 -0
- package/lib/ui/action-icons.js +11 -0
- package/lib/ui/action-icons.js.map +1 -0
- package/lib/ui/document-actions.d.ts +12 -0
- package/lib/ui/document-actions.d.ts.map +1 -0
- package/lib/ui/document-actions.js +37 -0
- package/lib/ui/document-actions.js.map +1 -0
- package/lib/ui/drag-handle.d.ts +11 -0
- package/lib/ui/drag-handle.d.ts.map +1 -0
- package/lib/ui/drag-handle.js +38 -0
- package/lib/ui/drag-handle.js.map +1 -0
- package/lib/ui/existing-image-modal.d.ts +10 -0
- package/lib/ui/existing-image-modal.d.ts.map +1 -0
- package/lib/ui/existing-image-modal.js +153 -0
- package/lib/ui/existing-image-modal.js.map +1 -0
- package/lib/ui/field-form-modal.d.ts +33 -0
- package/lib/ui/field-form-modal.d.ts.map +1 -0
- package/lib/ui/field-form-modal.js +103 -0
- package/lib/ui/field-form-modal.js.map +1 -0
- package/lib/ui/field-form-modal.test.d.ts +2 -0
- package/lib/ui/field-form-modal.test.d.ts.map +1 -0
- package/lib/ui/field-form-modal.test.js +81 -0
- package/lib/ui/field-form-modal.test.js.map +1 -0
- package/lib/ui/field-mapping-badges.d.ts +9 -0
- package/lib/ui/field-mapping-badges.d.ts.map +1 -0
- package/lib/ui/field-mapping-badges.js +208 -0
- package/lib/ui/field-mapping-badges.js.map +1 -0
- package/lib/ui/field-mapping-badges.test.d.ts +2 -0
- package/lib/ui/field-mapping-badges.test.d.ts.map +1 -0
- package/lib/ui/field-mapping-badges.test.js +81 -0
- package/lib/ui/field-mapping-badges.test.js.map +1 -0
- package/lib/ui/field-mapping-modal-open.test.d.ts +2 -0
- package/lib/ui/field-mapping-modal-open.test.d.ts.map +1 -0
- package/lib/ui/field-mapping-modal-open.test.js +58 -0
- package/lib/ui/field-mapping-modal-open.test.js.map +1 -0
- package/lib/ui/field-mapping-modal.d.ts +4 -0
- package/lib/ui/field-mapping-modal.d.ts.map +1 -0
- package/lib/ui/field-mapping-modal.js +992 -0
- package/lib/ui/field-mapping-modal.js.map +1 -0
- package/lib/ui/filename-prompt.d.ts +6 -0
- package/lib/ui/filename-prompt.d.ts.map +1 -0
- package/lib/ui/filename-prompt.js +85 -0
- package/lib/ui/filename-prompt.js.map +1 -0
- package/lib/ui/format-icons.d.ts +23 -0
- package/lib/ui/format-icons.d.ts.map +1 -0
- package/lib/ui/format-icons.js +23 -0
- package/lib/ui/format-icons.js.map +1 -0
- package/lib/ui/html-text-modal.d.ts +6 -0
- package/lib/ui/html-text-modal.d.ts.map +1 -0
- package/lib/ui/html-text-modal.js +195 -0
- package/lib/ui/html-text-modal.js.map +1 -0
- package/lib/ui/image-modal.d.ts +6 -0
- package/lib/ui/image-modal.d.ts.map +1 -0
- package/lib/ui/image-modal.js +237 -0
- package/lib/ui/image-modal.js.map +1 -0
- package/lib/ui/integer-modal.d.ts +12 -0
- package/lib/ui/integer-modal.d.ts.map +1 -0
- package/lib/ui/integer-modal.js +71 -0
- package/lib/ui/integer-modal.js.map +1 -0
- package/lib/ui/list-modal.d.ts +6 -0
- package/lib/ui/list-modal.d.ts.map +1 -0
- package/lib/ui/list-modal.js +627 -0
- package/lib/ui/list-modal.js.map +1 -0
- package/lib/ui/list-modal.test.d.ts +2 -0
- package/lib/ui/list-modal.test.d.ts.map +1 -0
- package/lib/ui/list-modal.test.js +185 -0
- package/lib/ui/list-modal.test.js.map +1 -0
- package/lib/ui/logical-modal.d.ts +11 -0
- package/lib/ui/logical-modal.d.ts.map +1 -0
- package/lib/ui/logical-modal.js +104 -0
- package/lib/ui/logical-modal.js.map +1 -0
- package/lib/ui/mapping-drag-drop.d.ts +44 -0
- package/lib/ui/mapping-drag-drop.d.ts.map +1 -0
- package/lib/ui/mapping-drag-drop.js +339 -0
- package/lib/ui/mapping-drag-drop.js.map +1 -0
- package/lib/ui/mapping-drag-drop.test.d.ts +2 -0
- package/lib/ui/mapping-drag-drop.test.d.ts.map +1 -0
- package/lib/ui/mapping-drag-drop.test.js +47 -0
- package/lib/ui/mapping-drag-drop.test.js.map +1 -0
- package/lib/ui/mapping-result-helper.d.ts +130 -0
- package/lib/ui/mapping-result-helper.d.ts.map +1 -0
- package/lib/ui/mapping-result-helper.js +659 -0
- package/lib/ui/mapping-result-helper.js.map +1 -0
- package/lib/ui/mapping-result-helper.test.d.ts +2 -0
- package/lib/ui/mapping-result-helper.test.d.ts.map +1 -0
- package/lib/ui/mapping-result-helper.test.js +185 -0
- package/lib/ui/mapping-result-helper.test.js.map +1 -0
- package/lib/ui/modal-picker-keyboard.d.ts +12 -0
- package/lib/ui/modal-picker-keyboard.d.ts.map +1 -0
- package/lib/ui/modal-picker-keyboard.js +72 -0
- package/lib/ui/modal-picker-keyboard.js.map +1 -0
- package/lib/ui/modal-picker-keyboard.test.d.ts +2 -0
- package/lib/ui/modal-picker-keyboard.test.d.ts.map +1 -0
- package/lib/ui/modal-picker-keyboard.test.js +53 -0
- package/lib/ui/modal-picker-keyboard.test.js.map +1 -0
- package/lib/ui/modal-picker-pills.d.ts +2 -0
- package/lib/ui/modal-picker-pills.d.ts.map +1 -0
- package/lib/ui/modal-picker-pills.js +26 -0
- package/lib/ui/modal-picker-pills.js.map +1 -0
- package/lib/ui/notification.d.ts +2 -0
- package/lib/ui/notification.d.ts.map +1 -0
- package/lib/ui/notification.js +47 -0
- package/lib/ui/notification.js.map +1 -0
- package/lib/ui/palette-icons.d.ts +5 -0
- package/lib/ui/palette-icons.d.ts.map +1 -0
- package/lib/ui/palette-icons.js +28 -0
- package/lib/ui/palette-icons.js.map +1 -0
- package/lib/ui/pdf-canvas-preview.d.ts +11 -0
- package/lib/ui/pdf-canvas-preview.d.ts.map +1 -0
- package/lib/ui/pdf-canvas-preview.js +88 -0
- package/lib/ui/pdf-canvas-preview.js.map +1 -0
- package/lib/ui/preview-modal.d.ts +24 -0
- package/lib/ui/preview-modal.d.ts.map +1 -0
- package/lib/ui/preview-modal.js +536 -0
- package/lib/ui/preview-modal.js.map +1 -0
- package/lib/ui/recent-fill-colors.d.ts +21 -0
- package/lib/ui/recent-fill-colors.d.ts.map +1 -0
- package/lib/ui/recent-fill-colors.js +95 -0
- package/lib/ui/recent-fill-colors.js.map +1 -0
- package/lib/ui/recent-fill-colors.test.d.ts +2 -0
- package/lib/ui/recent-fill-colors.test.d.ts.map +1 -0
- package/lib/ui/recent-fill-colors.test.js +56 -0
- package/lib/ui/recent-fill-colors.test.js.map +1 -0
- package/lib/ui/repeater-editor-modal.d.ts +10 -0
- package/lib/ui/repeater-editor-modal.d.ts.map +1 -0
- package/lib/ui/repeater-editor-modal.js +124 -0
- package/lib/ui/repeater-editor-modal.js.map +1 -0
- package/lib/ui/rich-text-toolbar.d.ts +13 -0
- package/lib/ui/rich-text-toolbar.d.ts.map +1 -0
- package/lib/ui/rich-text-toolbar.js +670 -0
- package/lib/ui/rich-text-toolbar.js.map +1 -0
- package/lib/ui/rich-text-toolbar.test.d.ts +2 -0
- package/lib/ui/rich-text-toolbar.test.d.ts.map +1 -0
- package/lib/ui/rich-text-toolbar.test.js +167 -0
- package/lib/ui/rich-text-toolbar.test.js.map +1 -0
- package/lib/ui/signature-modal.d.ts +13 -0
- package/lib/ui/signature-modal.d.ts.map +1 -0
- package/lib/ui/signature-modal.js +219 -0
- package/lib/ui/signature-modal.js.map +1 -0
- package/lib/ui/source-path-canvas-drop.d.ts +121 -0
- package/lib/ui/source-path-canvas-drop.d.ts.map +1 -0
- package/lib/ui/source-path-canvas-drop.js +300 -0
- package/lib/ui/source-path-canvas-drop.js.map +1 -0
- package/lib/ui/source-path-canvas-drop.test.d.ts +2 -0
- package/lib/ui/source-path-canvas-drop.test.d.ts.map +1 -0
- package/lib/ui/source-path-canvas-drop.test.js +216 -0
- package/lib/ui/source-path-canvas-drop.test.js.map +1 -0
- package/lib/ui/source-schema-tree.d.ts +33 -0
- package/lib/ui/source-schema-tree.d.ts.map +1 -0
- package/lib/ui/source-schema-tree.js +326 -0
- package/lib/ui/source-schema-tree.js.map +1 -0
- package/lib/ui/text-modal.d.ts +13 -0
- package/lib/ui/text-modal.d.ts.map +1 -0
- package/lib/ui/text-modal.js +31 -0
- package/lib/ui/text-modal.js.map +1 -0
- package/lib/ui/tree-modal.d.ts +8 -0
- package/lib/ui/tree-modal.d.ts.map +1 -0
- package/lib/ui/tree-modal.js +586 -0
- package/lib/ui/tree-modal.js.map +1 -0
- package/lib/ui/tree-modal.test.d.ts +2 -0
- package/lib/ui/tree-modal.test.d.ts.map +1 -0
- package/lib/ui/tree-modal.test.js +390 -0
- package/lib/ui/tree-modal.test.js.map +1 -0
- package/lib/ui/wire-modal-escape.d.ts +13 -0
- package/lib/ui/wire-modal-escape.d.ts.map +1 -0
- package/lib/ui/wire-modal-escape.js +26 -0
- package/lib/ui/wire-modal-escape.js.map +1 -0
- package/lib/ui/wire-modal-escape.test.d.ts +2 -0
- package/lib/ui/wire-modal-escape.test.d.ts.map +1 -0
- package/lib/ui/wire-modal-escape.test.js +57 -0
- package/lib/ui/wire-modal-escape.test.js.map +1 -0
- package/lib/ui/wire-modal-focus-trap.test.d.ts +2 -0
- package/lib/ui/wire-modal-focus-trap.test.d.ts.map +1 -0
- package/lib/ui/wire-modal-focus-trap.test.js +264 -0
- package/lib/ui/wire-modal-focus-trap.test.js.map +1 -0
- package/lib/ui/wire-modal-move.d.ts +23 -0
- package/lib/ui/wire-modal-move.d.ts.map +1 -0
- package/lib/ui/wire-modal-move.js +179 -0
- package/lib/ui/wire-modal-move.js.map +1 -0
- package/lib/ui/wire-modal-move.test.d.ts +2 -0
- package/lib/ui/wire-modal-move.test.d.ts.map +1 -0
- package/lib/ui/wire-modal-move.test.js +84 -0
- package/lib/ui/wire-modal-move.test.js.map +1 -0
- package/lib/ui/wire-modal-palette.d.ts +56 -0
- package/lib/ui/wire-modal-palette.d.ts.map +1 -0
- package/lib/ui/wire-modal-palette.js +501 -0
- package/lib/ui/wire-modal-palette.js.map +1 -0
- package/lib/ui/wire-modal-resize.d.ts +27 -0
- package/lib/ui/wire-modal-resize.d.ts.map +1 -0
- package/lib/ui/wire-modal-resize.js +146 -0
- package/lib/ui/wire-modal-resize.js.map +1 -0
- package/lib/ui/wire-modal-resize.test.d.ts +2 -0
- package/lib/ui/wire-modal-resize.test.d.ts.map +1 -0
- package/lib/ui/wire-modal-resize.test.js +61 -0
- package/lib/ui/wire-modal-resize.test.js.map +1 -0
- package/lib/ui/wire-panel-splitter.d.ts +67 -0
- package/lib/ui/wire-panel-splitter.d.ts.map +1 -0
- package/lib/ui/wire-panel-splitter.js +361 -0
- package/lib/ui/wire-panel-splitter.js.map +1 -0
- package/lib/ui/wire-panel-splitter.test.d.ts +2 -0
- package/lib/ui/wire-panel-splitter.test.d.ts.map +1 -0
- package/lib/ui/wire-panel-splitter.test.js +152 -0
- package/lib/ui/wire-panel-splitter.test.js.map +1 -0
- package/lib/utils/export-filename.d.ts +24 -0
- package/lib/utils/export-filename.d.ts.map +1 -0
- package/lib/utils/export-filename.js +42 -0
- package/lib/utils/export-filename.js.map +1 -0
- package/lib/utils/export-filename.test.d.ts +2 -0
- package/lib/utils/export-filename.test.d.ts.map +1 -0
- package/lib/utils/export-filename.test.js +42 -0
- package/lib/utils/export-filename.test.js.map +1 -0
- package/lib/utils/print-document.d.ts +17 -0
- package/lib/utils/print-document.d.ts.map +1 -0
- package/lib/utils/print-document.js +132 -0
- package/lib/utils/print-document.js.map +1 -0
- package/lib/utils/save-blob.d.ts +9 -0
- package/lib/utils/save-blob.d.ts.map +1 -0
- package/lib/utils/save-blob.js +41 -0
- package/lib/utils/save-blob.js.map +1 -0
- package/lib/web-component.d.ts +6 -0
- package/lib/web-component.d.ts.map +1 -0
- package/lib/web-component.js +59 -0
- package/lib/web-component.js.map +1 -0
- package/package.json +61 -6
- package/src/catalog/catalog-provider.ts +91 -0
- package/src/core/computed-formula.test.ts +258 -0
- package/src/core/computed-formula.ts +18 -0
- package/src/core/document-display-defaults.ts +13 -0
- package/src/core/document-history.test.ts +54 -0
- package/src/core/document-history.ts +102 -0
- package/src/core/document-io.test.ts +739 -0
- package/src/core/document-io.ts +27 -0
- package/src/core/document-section-defaults.test.ts +56 -0
- package/src/core/document-section-defaults.ts +67 -0
- package/src/core/field-id.test.ts +299 -0
- package/src/core/field-id.ts +23 -0
- package/src/core/field-io/sectioned-document-io.test.ts +568 -0
- package/src/core/field-io/sectioned-document-io.ts +15 -0
- package/src/core/field-io/table-field-io.test.ts +242 -0
- package/src/core/field-io/table-field-io.ts +13 -0
- package/src/core/field-schemas.test.ts +472 -0
- package/src/core/field-schemas.ts +46 -0
- package/src/core/formula-field-index.test.ts +140 -0
- package/src/core/formula-field-index.ts +16 -0
- package/src/core/page-setup-styles.test.ts +274 -0
- package/src/core/page-setup-styles.ts +213 -0
- package/src/core/repeater-io.test.ts +899 -0
- package/src/core/repeater-io.ts +37 -0
- package/src/core/segment-tree.test.ts +41 -0
- package/src/core/segment-tree.ts +6 -0
- package/src/create-editor.ts +3848 -0
- package/src/design/collection-tree-picker.test.ts +105 -0
- package/src/design/collection-tree-picker.ts +340 -0
- package/src/design/design-mode.ts +7 -0
- package/src/design/design-shell.ts +76 -0
- package/src/design/display-style-form.test.ts +174 -0
- package/src/design/display-style-form.ts +217 -0
- package/src/design/field-highlight-form.test.ts +64 -0
- package/src/design/field-highlight-form.ts +169 -0
- package/src/design/field-palette.test.ts +97 -0
- package/src/design/field-palette.ts +250 -0
- package/src/design/formula-field-picker.test.ts +158 -0
- package/src/design/formula-field-picker.ts +189 -0
- package/src/design/palette-block-drop.ts +66 -0
- package/src/design/properties-panel.ts +900 -0
- package/src/design/schema-editor-controller.test.ts +296 -0
- package/src/design/schema-editor-controller.ts +1122 -0
- package/src/design/schema-editor-modal.ts +83 -0
- package/src/design/schema-items-designer-modal.ts +209 -0
- package/src/design/schema-items-designer.test.ts +148 -0
- package/src/design/schema-items-designer.ts +442 -0
- package/src/design/style-toolbar-shared.ts +218 -0
- package/src/dom-pragmatic.d.ts +83 -0
- package/src/domain/ophthalmology/catalogs.ts +72 -0
- package/src/domain/ophthalmology/life-anamnesis-tree.ts +43 -0
- package/src/domain/ophthalmology/norm-options.ts +24 -0
- package/src/domain/ophthalmology/ophthalmology-complaints-tree.ts +47 -0
- package/src/domain/ophthalmology/ophthalmology-diagnoses.ts +12 -0
- package/src/domain/ophthalmology/vision-values.ts +58 -0
- package/src/editorjs-shim.d.ts +2 -0
- package/src/export/document-pdf.sf-stub.ts +23 -0
- package/src/export/document-pdf.ts +44 -0
- package/src/export/preview-export-options.ts +29 -0
- package/src/export/preview-html-document.ts +34 -0
- package/src/export/preview-html-styles.test.ts +60 -0
- package/src/export/preview-html-styles.ts +551 -0
- package/src/export/preview-pdf-mount.ts +48 -0
- package/src/export/preview-pdf-parity.test.ts +237 -0
- package/src/fields/barcode-encode.test.ts +43 -0
- package/src/fields/barcode-encode.ts +147 -0
- package/src/fields/collect-field-values.test.ts +95 -0
- package/src/fields/columns-serialize.test.ts +75 -0
- package/src/fields/cross-section-reposition.test.ts +206 -0
- package/src/fields/cross-section-reposition.ts +214 -0
- package/src/fields/document-preview.test.ts +1621 -0
- package/src/fields/document-preview.ts +910 -0
- package/src/fields/field-clipboard.test.ts +312 -0
- package/src/fields/field-clipboard.ts +705 -0
- package/src/fields/field-display-style.test.ts +403 -0
- package/src/fields/field-display-style.ts +435 -0
- package/src/fields/field-keyboard.test.ts +446 -0
- package/src/fields/field-keyboard.ts +1281 -0
- package/src/fields/field-selection.test.ts +85 -0
- package/src/fields/field-selection.ts +137 -0
- package/src/fields/field-token-drag.test.ts +65 -0
- package/src/fields/fill-defaults.test.ts +89 -0
- package/src/fields/fill-field-focus.test.ts +239 -0
- package/src/fields/fill-field-focus.ts +249 -0
- package/src/fields/handlers/builtins.ts +879 -0
- package/src/fields/handlers/index.ts +16 -0
- package/src/fields/handlers/registry.test.ts +266 -0
- package/src/fields/handlers/registry.ts +88 -0
- package/src/fields/handlers/schema-form-dom.ts +135 -0
- package/src/fields/heading-line-breaks.test.ts +931 -0
- package/src/fields/inline-field-from-selection.test.ts +202 -0
- package/src/fields/inline-fields.ts +3760 -0
- package/src/fields/logical-display.test.ts +37 -0
- package/src/fields/logical-display.ts +29 -0
- package/src/fields/manual-field-values.test.ts +152 -0
- package/src/fields/manual-field-values.ts +207 -0
- package/src/fields/pivot-table-field.ts +458 -0
- package/src/fields/plain-text-newlines.test.ts +48 -0
- package/src/fields/repeater-field.ts +61 -0
- package/src/fields/rich-text.ts +1018 -0
- package/src/fields/table-field.test.ts +504 -0
- package/src/fields/table-field.ts +1026 -0
- package/src/fields/tree-paths.ts +6 -0
- package/src/fields/tree-selection.ts +50 -0
- package/src/fields/tree.ts +11 -0
- package/src/fields/wire-columns-resize.test.ts +40 -0
- package/src/fields/wire-columns-resize.ts +138 -0
- package/src/fields/wire-editorjs-native-drop-guard.test.ts +273 -0
- package/src/fields/wire-editorjs-native-drop-guard.ts +491 -0
- package/src/fields/wire-table-column-reorder.test.ts +163 -0
- package/src/fields/wire-table-column-reorder.ts +223 -0
- package/src/fields/wire-table-column-resize.test.ts +459 -0
- package/src/fields/wire-table-column-resize.ts +433 -0
- package/src/index.ts +290 -0
- package/src/node.ts +114 -0
- package/src/registry/registry-context.ts +36 -0
- package/src/registry/schema-registry.ts +80 -0
- package/src/services/image-upload.test.ts +180 -0
- package/src/services/image-upload.ts +185 -0
- package/src/sf-entry.ts +19 -0
- package/src/sf-pdf-viewer/main.ts +57 -0
- package/src/sf-pdf-viewer/viewer.html +40 -0
- package/src/styles/editor.css +5472 -0
- package/src/themes/bridge.css +2071 -0
- package/src/themes/prime.css +207 -0
- package/src/themes/slds.css +123 -0
- package/src/tools/document-section.ts +692 -0
- package/src/tools/template-block.ts +289 -0
- package/src/types.d.ts +1782 -0
- package/src/ui/action-icons.ts +13 -0
- package/src/ui/document-actions.ts +41 -0
- package/src/ui/drag-handle.ts +52 -0
- package/src/ui/existing-image-modal.ts +164 -0
- package/src/ui/field-form-modal.test.ts +92 -0
- package/src/ui/field-form-modal.ts +168 -0
- package/src/ui/field-mapping-badges.test.ts +93 -0
- package/src/ui/field-mapping-badges.ts +243 -0
- package/src/ui/field-mapping-modal-open.test.ts +72 -0
- package/src/ui/field-mapping-modal.ts +1277 -0
- package/src/ui/filename-prompt.ts +96 -0
- package/src/ui/format-icons.ts +42 -0
- package/src/ui/html-text-modal.ts +224 -0
- package/src/ui/image-modal.ts +264 -0
- package/src/ui/integer-modal.ts +76 -0
- package/src/ui/list-modal.test.ts +220 -0
- package/src/ui/list-modal.ts +701 -0
- package/src/ui/mapping-drag-drop.test.ts +61 -0
- package/src/ui/mapping-drag-drop.ts +382 -0
- package/src/ui/mapping-result-helper.test.ts +231 -0
- package/src/ui/mapping-result-helper.ts +725 -0
- package/src/ui/modal-picker-keyboard.test.ts +65 -0
- package/src/ui/modal-picker-keyboard.ts +87 -0
- package/src/ui/modal-picker-pills.ts +31 -0
- package/src/ui/notification.ts +54 -0
- package/src/ui/palette-icons.ts +64 -0
- package/src/ui/pdf-canvas-preview.ts +93 -0
- package/src/ui/preview-modal.ts +580 -0
- package/src/ui/recent-fill-colors.test.ts +66 -0
- package/src/ui/recent-fill-colors.ts +91 -0
- package/src/ui/repeater-editor-modal.ts +137 -0
- package/src/ui/rich-text-toolbar.test.ts +180 -0
- package/src/ui/rich-text-toolbar.ts +740 -0
- package/src/ui/signature-modal.ts +240 -0
- package/src/ui/source-path-canvas-drop.test.ts +256 -0
- package/src/ui/source-path-canvas-drop.ts +367 -0
- package/src/ui/source-schema-tree.ts +384 -0
- package/src/ui/text-modal.ts +37 -0
- package/src/ui/tree-modal.test.ts +484 -0
- package/src/ui/tree-modal.ts +682 -0
- package/src/ui/wire-modal-escape.test.ts +66 -0
- package/src/ui/wire-modal-escape.ts +23 -0
- package/src/ui/wire-modal-focus-trap.test.ts +307 -0
- package/src/ui/wire-modal-move.test.ts +107 -0
- package/src/ui/wire-modal-move.ts +201 -0
- package/src/ui/wire-modal-palette.ts +533 -0
- package/src/ui/wire-modal-resize.test.ts +76 -0
- package/src/ui/wire-modal-resize.ts +176 -0
- package/src/ui/wire-panel-splitter.test.ts +178 -0
- package/src/ui/wire-panel-splitter.ts +381 -0
- package/src/utils/export-filename.test.ts +54 -0
- package/src/utils/export-filename.ts +58 -0
- package/src/utils/print-document.ts +136 -0
- package/src/utils/save-blob.ts +40 -0
- package/src/web-component.ts +68 -0
|
@@ -0,0 +1,3373 @@
|
|
|
1
|
+
import { wireEditorJsNativeDropGuard } from './fields/wire-editorjs-native-drop-guard.js';
|
|
2
|
+
import EditorJS from '@editorjs/editorjs';
|
|
3
|
+
// EditorJS CJS typings conflict with verbatimModuleSyntax; treat as any constructable.
|
|
4
|
+
const EditorJSCtor = EditorJS;
|
|
5
|
+
import DocumentSection from './tools/document-section.js';
|
|
6
|
+
import TemplateBlock from './tools/template-block.js';
|
|
7
|
+
import { createTreeModal } from './ui/tree-modal.js';
|
|
8
|
+
import { createListModal } from './ui/list-modal.js';
|
|
9
|
+
import { createTextModal } from './ui/text-modal.js';
|
|
10
|
+
import { createHtmlTextModal } from './ui/html-text-modal.js';
|
|
11
|
+
import { createIntegerModal } from './ui/integer-modal.js';
|
|
12
|
+
import { createSignatureModal } from './ui/signature-modal.js';
|
|
13
|
+
import { createImageModal } from './ui/image-modal.js';
|
|
14
|
+
import { resolveFieldModalParent, resolvePreviewModalParent } from './ui/wire-modal-palette.js';
|
|
15
|
+
import { createSchemaEditorModal } from './design/schema-editor-modal.js';
|
|
16
|
+
import { configureSchemaItemsDesignerModal } from './design/schema-items-designer-modal.js';
|
|
17
|
+
import { createFieldPalette } from './design/field-palette.js';
|
|
18
|
+
import { createDesignShell } from './design/design-shell.js';
|
|
19
|
+
import { createPropertiesPanel } from './design/properties-panel.js';
|
|
20
|
+
import { wirePaletteBlockDrop } from './design/palette-block-drop.js';
|
|
21
|
+
import { createRichTextToolbar } from './ui/rich-text-toolbar.js';
|
|
22
|
+
import { createPreviewModal } from './ui/preview-modal.js';
|
|
23
|
+
import { createFieldMappingModal } from './ui/field-mapping-modal.js';
|
|
24
|
+
import { createRepeaterEditorModal } from './ui/repeater-editor-modal.js';
|
|
25
|
+
import { extractRepeaterValueFromDocument, getRepeaterFieldSchemas, ensureRepeaterChildSchemas, ensureRepeaterSchemasFromBlockValues, sanitizeRepeaterChildSchemas, normalizeRepeaterValue, normalizeRepeaterSchema, parseRepeaterTemplateImport, applyRepeaterTemplateImport, syncRepeaterTemplateFromFillDocument, extractRepeaterFieldValueFromBlocks, stripForeignKeysFromRepeaterValue, buildRepeaterFillDocument, repeaterHasTemplate, } from './core/repeater-io.js';
|
|
26
|
+
import { createDocumentActions } from './ui/document-actions.js';
|
|
27
|
+
import { DEFAULT_FIELD_VALUE_STYLE_OPTIONS, DOCUMENT_TABLE_TEXT_STYLE } from './core/document-display-defaults.js';
|
|
28
|
+
import { cloneHistorySnapshot, createDocumentHistory } from './core/document-history.js';
|
|
29
|
+
import { applyDocumentBodyTextStyle, applyDocumentTextStyleCssVars, refreshDocumentFieldTokenStyles, resolvePageSetupFieldValueStyle, resolvePageSetupTextStyle, resolvePageSetupFieldHighlightStyle, applyFieldHighlightCssVars, applyPageFormatCssVars, FILL_MODE_PAGE_SCALE, migratePageSetup, } from './core/page-setup-styles.js';
|
|
30
|
+
import { generateDocumentPdfBlob, isClientPdfAvailable } from './export/document-pdf.js';
|
|
31
|
+
import { buildPreviewHtmlBlob, buildPreviewHtmlDocument } from './export/preview-html-document.js';
|
|
32
|
+
import { resolvePreviewExportOptions } from './export/preview-export-options.js';
|
|
33
|
+
import { saveBlobToDisk } from './utils/save-blob.js';
|
|
34
|
+
import { buildExportFilename } from './utils/export-filename.js';
|
|
35
|
+
import { applyDesignMode } from './design/design-mode.js';
|
|
36
|
+
import { showNotification } from './ui/notification.js';
|
|
37
|
+
import { applyFieldMapping as runFieldMapping, previewFieldMapping as runFieldMappingPreview, normalizeFieldMappingSpec, syncFieldMappingSpecToSchema, evaluateSectionVisibility, registerFormulaFunction, omitMappedFields, createMappingRulesFromDrop, } from '@docengine/engine';
|
|
38
|
+
import { applyMappingBadges } from './ui/field-mapping-badges.js';
|
|
39
|
+
import { classifySourcePathDrop, buildTableMappingRulesFromSourceDrop, mergeMappingRulesIntoSpec, } from './ui/source-path-canvas-drop.js';
|
|
40
|
+
import { buildTemplateExport, buildFieldsExport, buildDocExport, applyDocumentValues, normalizeImportedDoc, normalizeDocumentValues, validateRequiredFields, collectAllValues, isFieldsExport, materializeRepeatableSectionInstances, } from './core/document-io.js';
|
|
41
|
+
import { resolveRepeatablePagePlan } from './core/field-io/sectioned-document-io.js';
|
|
42
|
+
import { createDefaultSchema, createDefaultBlockData, ensureCellSchemas, syncBlocksAfterSchemaChange, applyFieldIdChange, listColumnCellFieldIds, parseCellFieldId, syncColumnListSourceSettings, syncTableColumnKeyChanges, ensureSchemaForFieldProperties, resolveSchemaDefaultValue, } from './core/field-schemas.js';
|
|
43
|
+
import { findFieldPlacement, migrateFieldIds, rebuildFieldIdsForSection, resolveSectionName, allocateUniqueSectionName, collectUsedSectionNames, DEFAULT_SECTION_NAME, } from './core/field-id.js';
|
|
44
|
+
import { renameSectionInFormulas } from './core/formula-field-index.js';
|
|
45
|
+
import { SchemaRegistry } from './registry/schema-registry.js';
|
|
46
|
+
import { createCatalogProvider } from './catalog/catalog-provider.js';
|
|
47
|
+
import { attachRegistryToHolder, detachRegistryFromHolder } from './registry/registry-context.js';
|
|
48
|
+
import { insertInlineField, focusCaretAtEnd, focusCaretAfter, refreshFieldSchemaInDom, refreshTableCellTokens, pruneTableCellCaretAnchors, insertTableAtCaret, insertColumnsAtCaret, insertColumnsAtPoint, insertPaletteFieldAtPoint, insertPaletteTableAtPoint, wireTableRegions, applyColumnWidthsToElement, updateFieldToken, findLiveFieldToken, collectAllFieldValuesFromHolder, resolveSelectedTextForFieldConversion, syncFillComputedFields, recoverImageValuesFromDom, } from './fields/inline-fields.js';
|
|
49
|
+
import { saveSelection } from './fields/rich-text.js';
|
|
50
|
+
import { readTableRowsFromDom, refreshTableHeadersInDom, applyTableColumnWidthsToElement, addTableColumnToWrapper } from './fields/table-field.js';
|
|
51
|
+
import { setFieldSelectionChangeCallback, clearAllDesignTokenSelection, } from './fields/field-selection.js';
|
|
52
|
+
import { isEmptyFieldDisplayStyle, normalizeFieldDisplayStyle, refreshTableColumnStylesForFieldIds, resolveFieldDisplayStyle, resolveTableCellDisplayStyle, } from './fields/field-display-style.js';
|
|
53
|
+
import { configureImageUpload } from './services/image-upload.js';
|
|
54
|
+
import { getFieldHandler, isInlineFieldType } from './fields/handlers/index.js';
|
|
55
|
+
import { createEmptyDocumentSectionBlock, ensureAtLeastOneDocumentSection, } from './core/document-section-defaults.js';
|
|
56
|
+
const DEFAULT_EMPTY_DOCUMENT = {
|
|
57
|
+
time: Date.now(),
|
|
58
|
+
fieldSchemas: {},
|
|
59
|
+
blocks: [createEmptyDocumentSectionBlock()],
|
|
60
|
+
};
|
|
61
|
+
/** Types that change document structure and require an Editor.js remount. */
|
|
62
|
+
function isStructuralFieldType(type) {
|
|
63
|
+
return type === 'table' || type === 'child';
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Inline↔inline type switches (text/choice/image/…) can refresh tokens in place.
|
|
67
|
+
* Table/child transitions still remount.
|
|
68
|
+
*/
|
|
69
|
+
function canRefreshFieldTypeInDom(previousType, newType) {
|
|
70
|
+
if (!previousType || !newType || previousType === newType)
|
|
71
|
+
return false;
|
|
72
|
+
if (isStructuralFieldType(previousType) || isStructuralFieldType(newType))
|
|
73
|
+
return false;
|
|
74
|
+
return isInlineFieldType(previousType) && isInlineFieldType(newType);
|
|
75
|
+
}
|
|
76
|
+
function migrateFieldSchemas(schemas) {
|
|
77
|
+
const next = { ...schemas };
|
|
78
|
+
for (const [id, schema] of Object.entries(next)) {
|
|
79
|
+
if (schema?.type === 'group')
|
|
80
|
+
delete next[id];
|
|
81
|
+
const migrated = schema?.type === 'repeater' ? { ...schema, type: 'child' } : schema;
|
|
82
|
+
if (migrated?.type === 'child') {
|
|
83
|
+
next[id] = normalizeRepeaterSchema(migrated);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return next;
|
|
87
|
+
}
|
|
88
|
+
function migrateBlocks(blocks, options = {}) {
|
|
89
|
+
const { visionTableFieldId = 'visionTable' } = options;
|
|
90
|
+
return blocks
|
|
91
|
+
.filter((block) => {
|
|
92
|
+
if (block.type === 'image')
|
|
93
|
+
return false;
|
|
94
|
+
if (block.type === 'templateBlock' && block.data?.fieldType === 'group')
|
|
95
|
+
return false;
|
|
96
|
+
return true;
|
|
97
|
+
})
|
|
98
|
+
.map((block) => {
|
|
99
|
+
if (block.type === 'templateBlock' && block.data?.fieldType === 'repeater') {
|
|
100
|
+
block = { ...block, data: { ...block.data, fieldType: 'child' } };
|
|
101
|
+
}
|
|
102
|
+
if (block.type === 'documentSection' && Array.isArray(block.data?.segments)) {
|
|
103
|
+
const segments = block.data.segments.map((seg) => seg?.type === 'repeater' ? { ...seg, type: 'child' } : seg);
|
|
104
|
+
block = { ...block, data: { ...block.data, segments } };
|
|
105
|
+
}
|
|
106
|
+
if (block.type !== 'visionTable')
|
|
107
|
+
return block;
|
|
108
|
+
const fieldId = block.data?.fieldId ?? visionTableFieldId;
|
|
109
|
+
const cells = {};
|
|
110
|
+
for (const [key, val] of Object.entries(block.data?.cells ?? {})) {
|
|
111
|
+
if (key.startsWith(`${visionTableFieldId}_`) || key.startsWith(`${fieldId}_`)) {
|
|
112
|
+
cells[key] = val;
|
|
113
|
+
}
|
|
114
|
+
else if (/^(od|os)_/.test(key)) {
|
|
115
|
+
cells[`${fieldId}_${key}`] = val;
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
cells[key] = val;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
const tableSchema = options.defaultDocument?.fieldSchemas?.[fieldId]
|
|
122
|
+
?? options.fieldSchemas?.[fieldId];
|
|
123
|
+
const schemaRows = Array.isArray(tableSchema?.rows)
|
|
124
|
+
? tableSchema.rows.map((row) => ({
|
|
125
|
+
key: String(row.key),
|
|
126
|
+
label: String(row.label ?? ''),
|
|
127
|
+
}))
|
|
128
|
+
: [
|
|
129
|
+
{ key: 'row1', label: '' },
|
|
130
|
+
{ key: 'row2', label: '' },
|
|
131
|
+
];
|
|
132
|
+
return {
|
|
133
|
+
type: 'documentSection',
|
|
134
|
+
data: {
|
|
135
|
+
name: tableSchema?.name ?? 'Visual acuity',
|
|
136
|
+
label: tableSchema?.label ?? tableSchema?.name ?? 'Visual acuity',
|
|
137
|
+
segments: [
|
|
138
|
+
{
|
|
139
|
+
type: 'table',
|
|
140
|
+
id: fieldId,
|
|
141
|
+
rows: schemaRows,
|
|
142
|
+
},
|
|
143
|
+
],
|
|
144
|
+
fieldValues: cells,
|
|
145
|
+
},
|
|
146
|
+
};
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
function normalizeRepeaterValuesInBlocks(blocks, fieldSchemas) {
|
|
150
|
+
return (blocks ?? []).map((block) => {
|
|
151
|
+
if (block.type !== 'documentSection' || !block.data?.fieldValues)
|
|
152
|
+
return block;
|
|
153
|
+
const fieldValues = { ...block.data.fieldValues };
|
|
154
|
+
for (const [fieldId, value] of Object.entries(fieldValues)) {
|
|
155
|
+
const schema = fieldSchemas?.[fieldId];
|
|
156
|
+
if (schema?.type === 'child') {
|
|
157
|
+
fieldValues[fieldId] = normalizeRepeaterValue(value, schema);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
return {
|
|
161
|
+
...block,
|
|
162
|
+
data: {
|
|
163
|
+
...block.data,
|
|
164
|
+
fieldValues,
|
|
165
|
+
},
|
|
166
|
+
};
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
function normalizeDocument(data, options = {}) {
|
|
170
|
+
const fallback = options.defaultDocument ?? DEFAULT_EMPTY_DOCUMENT;
|
|
171
|
+
let result;
|
|
172
|
+
if (data?.blocks) {
|
|
173
|
+
result = {
|
|
174
|
+
time: data.time ?? Date.now(),
|
|
175
|
+
fieldSchemas: migrateFieldSchemas(data.fieldSchemas ?? { ...fallback.fieldSchemas }),
|
|
176
|
+
blocks: migrateBlocks(data.blocks, {
|
|
177
|
+
...options,
|
|
178
|
+
fieldSchemas: migrateFieldSchemas(data.fieldSchemas ?? { ...fallback.fieldSchemas }),
|
|
179
|
+
}),
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
else {
|
|
183
|
+
result = {
|
|
184
|
+
time: fallback.time ?? Date.now(),
|
|
185
|
+
fieldSchemas: { ...fallback.fieldSchemas },
|
|
186
|
+
blocks: migrateBlocks(fallback.blocks ?? [], options),
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
const migrated = migrateFieldIds(result.blocks, result.fieldSchemas);
|
|
190
|
+
let fieldSchemas = { ...migrated.fieldSchemas };
|
|
191
|
+
for (const [fieldId, schema] of Object.entries(fieldSchemas)) {
|
|
192
|
+
if (schema?.type === 'child') {
|
|
193
|
+
fieldSchemas[fieldId] = sanitizeRepeaterChildSchemas(schema, fieldSchemas, migrated.blocks);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
fieldSchemas = ensureRepeaterSchemasFromBlockValues(fieldSchemas, migrated.blocks);
|
|
197
|
+
const resultDoc = {
|
|
198
|
+
...result,
|
|
199
|
+
fieldSchemas,
|
|
200
|
+
blocks: ensureAtLeastOneDocumentSection(normalizeRepeaterValuesInBlocks(migrated.blocks, fieldSchemas)),
|
|
201
|
+
};
|
|
202
|
+
if (data?.pageSetup && typeof data.pageSetup === 'object') {
|
|
203
|
+
resultDoc.pageSetup = JSON.parse(JSON.stringify(data.pageSetup));
|
|
204
|
+
}
|
|
205
|
+
if (data?.fieldMapping && typeof data.fieldMapping === 'object') {
|
|
206
|
+
resultDoc.fieldMapping = JSON.parse(JSON.stringify(data.fieldMapping));
|
|
207
|
+
}
|
|
208
|
+
return resultDoc;
|
|
209
|
+
}
|
|
210
|
+
function resolveHolder(holder) {
|
|
211
|
+
if (!holder)
|
|
212
|
+
throw new Error('createEditor: holder is required');
|
|
213
|
+
if (typeof holder === 'string') {
|
|
214
|
+
const el = document.querySelector(holder);
|
|
215
|
+
if (!el)
|
|
216
|
+
throw new Error(`createEditor: holder not found: ${holder}`);
|
|
217
|
+
return el;
|
|
218
|
+
}
|
|
219
|
+
return holder;
|
|
220
|
+
}
|
|
221
|
+
function resolveElement(target) {
|
|
222
|
+
if (!target)
|
|
223
|
+
return null;
|
|
224
|
+
if (typeof target === 'string')
|
|
225
|
+
return document.querySelector(target);
|
|
226
|
+
return target;
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Mount a UI element relative to the editor holder.
|
|
230
|
+
* - paletteAfter / toolbarBefore: insert immediately after/before a sibling anchor
|
|
231
|
+
* - paletteParent with holder inside parent: insertBefore(holder)
|
|
232
|
+
* - paletteParent without holder as child: insert after parent (e.g. after page header)
|
|
233
|
+
* - default: insert before holder in holder.parentElement
|
|
234
|
+
*/
|
|
235
|
+
function mountAdjacentUi(element, holder, parentOption, anchorOption, mode = 'before-holder') {
|
|
236
|
+
const anchor = resolveElement(anchorOption);
|
|
237
|
+
if (anchor) {
|
|
238
|
+
if (mode === 'before-holder') {
|
|
239
|
+
anchor.after(element);
|
|
240
|
+
}
|
|
241
|
+
else {
|
|
242
|
+
anchor.before(element);
|
|
243
|
+
}
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
const parent = resolveElement(parentOption) ?? holder.parentElement;
|
|
247
|
+
if (parent?.contains(holder)) {
|
|
248
|
+
parent.insertBefore(element, holder);
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
if (parent) {
|
|
252
|
+
parent.after(element);
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
holder.parentElement?.insertBefore(element, holder);
|
|
256
|
+
}
|
|
257
|
+
function mountInContainer(element, containerOption) {
|
|
258
|
+
const container = resolveElement(containerOption);
|
|
259
|
+
if (container) {
|
|
260
|
+
container.appendChild(element);
|
|
261
|
+
return true;
|
|
262
|
+
}
|
|
263
|
+
return false;
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Mount palette + format toolbar wrapper relative to holder or host chrome container.
|
|
267
|
+
*/
|
|
268
|
+
function mountTopChrome(topChrome, holder, ui) {
|
|
269
|
+
const chromeParent = resolveElement(ui.chromeParent ?? ui.paletteParent);
|
|
270
|
+
if (chromeParent) {
|
|
271
|
+
chromeParent.appendChild(topChrome);
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
const anchorAfter = resolveElement(ui.paletteAfter);
|
|
275
|
+
if (anchorAfter) {
|
|
276
|
+
anchorAfter.after(topChrome);
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
const anchorBefore = resolveElement(ui.toolbarBefore);
|
|
280
|
+
if (anchorBefore) {
|
|
281
|
+
anchorBefore.before(topChrome);
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
const toolbarParent = resolveElement(ui.toolbarParent);
|
|
285
|
+
if (toolbarParent?.contains(holder)) {
|
|
286
|
+
toolbarParent.insertBefore(topChrome, holder);
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
289
|
+
holder.parentElement?.insertBefore(topChrome, holder);
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* @param {object} options
|
|
293
|
+
* @returns {import('./types.js').DocEditorInstance}
|
|
294
|
+
*/
|
|
295
|
+
export function createEditor(options = {}) {
|
|
296
|
+
const holder = resolveHolder(options.holder);
|
|
297
|
+
if (!holder.id) {
|
|
298
|
+
holder.id = `doc-editor-${Date.now().toString(36)}`;
|
|
299
|
+
}
|
|
300
|
+
let designMode = !!options.designMode;
|
|
301
|
+
let showFieldsInFillMode = options.ui?.showFieldsInFillMode !== false;
|
|
302
|
+
let editor = null;
|
|
303
|
+
/** Serializes setDesignMode so concurrent reinits don't call EditorJS.destroy() twice. */
|
|
304
|
+
let setDesignModeInFlight = null;
|
|
305
|
+
let destroyed = false;
|
|
306
|
+
let lastFocusedEditable = null;
|
|
307
|
+
let historyTimer = null;
|
|
308
|
+
let historyBusy = false;
|
|
309
|
+
const documentHistory = createDocumentHistory({ maxDepth: 50 });
|
|
310
|
+
const fieldValueStyle = {
|
|
311
|
+
...DEFAULT_FIELD_VALUE_STYLE_OPTIONS,
|
|
312
|
+
...options.fieldValueStyle,
|
|
313
|
+
default: {
|
|
314
|
+
...DEFAULT_FIELD_VALUE_STYLE_OPTIONS.default,
|
|
315
|
+
...options.fieldValueStyle?.default,
|
|
316
|
+
},
|
|
317
|
+
};
|
|
318
|
+
function getFillModeHighlightContext() {
|
|
319
|
+
return {
|
|
320
|
+
fillModeFieldHighlight: !designMode && showFieldsInFillMode && !options.mappingMode,
|
|
321
|
+
mappingMode: !!options.mappingMode,
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
function syncStylesFromPageSetup() {
|
|
325
|
+
const resolved = resolvePageSetupFieldValueStyle(documentPageSetup, options.fieldValueStyle);
|
|
326
|
+
Object.assign(fieldValueStyle.default, resolved.default);
|
|
327
|
+
const textStyle = resolvePageSetupTextStyle(documentPageSetup);
|
|
328
|
+
// Scope Default text style to the template canvas only — never Interface chrome.
|
|
329
|
+
applyDocumentTextStyleCssVars(holder, textStyle);
|
|
330
|
+
for (const body of holder.querySelectorAll('.document-section__body')) {
|
|
331
|
+
applyDocumentBodyTextStyle(body, textStyle);
|
|
332
|
+
}
|
|
333
|
+
syncFieldHighlightStyles();
|
|
334
|
+
syncPageFormatLayout();
|
|
335
|
+
const highlightContext = getFillModeHighlightContext();
|
|
336
|
+
refreshDocumentFieldTokenStyles(holder, fieldValueStyle, highlightContext);
|
|
337
|
+
refreshTableCellTokens(holder, {
|
|
338
|
+
getRegistry: () => registry,
|
|
339
|
+
fieldValueStyle,
|
|
340
|
+
...highlightContext,
|
|
341
|
+
});
|
|
342
|
+
refreshTableHeadersInDom(holder, {
|
|
343
|
+
getRegistry: () => registry,
|
|
344
|
+
fieldValueStyle,
|
|
345
|
+
getDocumentTextStyle: () => resolvePageSetupTextStyle(documentPageSetup),
|
|
346
|
+
});
|
|
347
|
+
}
|
|
348
|
+
/** Editor window sized from Page Setup format/orientation (+10%), fill and design. */
|
|
349
|
+
function syncPageFormatLayout() {
|
|
350
|
+
const chromeHosts = collectFillPageChromeHosts();
|
|
351
|
+
applyPageFormatCssVars(holder, documentPageSetup, {
|
|
352
|
+
scale: FILL_MODE_PAGE_SCALE,
|
|
353
|
+
fillPage: true,
|
|
354
|
+
});
|
|
355
|
+
for (const host of chromeHosts) {
|
|
356
|
+
applyPageFormatCssVars(host, documentPageSetup, {
|
|
357
|
+
scale: FILL_MODE_PAGE_SCALE,
|
|
358
|
+
fillPage: false,
|
|
359
|
+
});
|
|
360
|
+
if (host.classList.contains('doc-shell')) {
|
|
361
|
+
host.classList.add('doc-shell--fill-page');
|
|
362
|
+
}
|
|
363
|
+
if (host.classList.contains('page')) {
|
|
364
|
+
host.classList.add('page--fill-page');
|
|
365
|
+
}
|
|
366
|
+
if (host.classList.contains('design-panel__editor-scroll')) {
|
|
367
|
+
host.classList.add('design-panel__editor-scroll--fill-page');
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
function collectFillPageChromeHosts() {
|
|
372
|
+
/** @type {HTMLElement[]} */
|
|
373
|
+
const hosts = [];
|
|
374
|
+
const seen = new Set();
|
|
375
|
+
const add = (el) => {
|
|
376
|
+
if (!(el instanceof HTMLElement) || el === holder || seen.has(el))
|
|
377
|
+
return;
|
|
378
|
+
seen.add(el);
|
|
379
|
+
hosts.push(el);
|
|
380
|
+
};
|
|
381
|
+
add(holder.closest?.('.doc-shell'));
|
|
382
|
+
add(holder.closest?.('.page'));
|
|
383
|
+
add(designEditorScroll);
|
|
384
|
+
add(holder.closest?.('.design-panel__editor-scroll'));
|
|
385
|
+
const modalParent = resolveFieldModalParent(holder);
|
|
386
|
+
if (modalParent && modalParent !== document.body) {
|
|
387
|
+
add(modalParent);
|
|
388
|
+
}
|
|
389
|
+
return hosts;
|
|
390
|
+
}
|
|
391
|
+
function resolveFieldHighlightStyle() {
|
|
392
|
+
return resolvePageSetupFieldHighlightStyle(documentPageSetup, options.ui?.fieldHighlight);
|
|
393
|
+
}
|
|
394
|
+
function syncFieldHighlightStyles() {
|
|
395
|
+
const style = resolveFieldHighlightStyle();
|
|
396
|
+
applyFieldHighlightCssVars(holder, style);
|
|
397
|
+
// Field dialogs mount on .doc-shell (sibling of holder) — mirror vars so
|
|
398
|
+
// dialog chrome can use --me-field-fill-color (empty-field style).
|
|
399
|
+
const modalParent = resolveFieldModalParent(holder);
|
|
400
|
+
if (modalParent && modalParent !== holder) {
|
|
401
|
+
applyFieldHighlightCssVars(modalParent, style);
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
const ui = options.ui ?? {};
|
|
405
|
+
const useDesignPanels = ui.designLayout === 'panels';
|
|
406
|
+
let designShell = null;
|
|
407
|
+
let propertiesPanel = null;
|
|
408
|
+
let selectedSectionBlockIndex = -1;
|
|
409
|
+
let selectedColumnsEl = null;
|
|
410
|
+
let selectedTableEl = null;
|
|
411
|
+
let designToolbarWrap = null;
|
|
412
|
+
let designEditorScroll = null;
|
|
413
|
+
/** @type {import('./types.d.ts').TemplatePageSetup} */
|
|
414
|
+
let documentPageSetup = {};
|
|
415
|
+
/** @type {import('./types.d.ts').FieldMappingSpec | null} */
|
|
416
|
+
let documentFieldMapping = null;
|
|
417
|
+
/** Set once the field palette is created (vertical Source / Database tab). */
|
|
418
|
+
let refreshDatabaseSourceTree = null;
|
|
419
|
+
const getFormTextStyle = () => resolvePageSetupTextStyle(documentPageSetup);
|
|
420
|
+
/** @type {Record<string, import('./types.d.ts').DocumentSectionValues> | null} */
|
|
421
|
+
let loadedDocumentSections = null;
|
|
422
|
+
const catalogProvider = createCatalogProvider(options.catalogs ?? {});
|
|
423
|
+
const registry = new SchemaRegistry(catalogProvider);
|
|
424
|
+
attachRegistryToHolder(holder, registry);
|
|
425
|
+
if (useDesignPanels) {
|
|
426
|
+
designShell = createDesignShell(holder);
|
|
427
|
+
if (designMode)
|
|
428
|
+
designShell.show();
|
|
429
|
+
else
|
|
430
|
+
designShell.hide();
|
|
431
|
+
}
|
|
432
|
+
function syncShowFieldsHighlight() {
|
|
433
|
+
holder.classList.toggle('editor-holder--show-fields', !designMode && showFieldsInFillMode);
|
|
434
|
+
syncFieldHighlightStyles();
|
|
435
|
+
if (!designMode && showFieldsInFillMode) {
|
|
436
|
+
const highlightContext = getFillModeHighlightContext();
|
|
437
|
+
refreshDocumentFieldTokenStyles(holder, fieldValueStyle, highlightContext);
|
|
438
|
+
refreshTableCellTokens(holder, {
|
|
439
|
+
getRegistry: () => registry,
|
|
440
|
+
fieldValueStyle,
|
|
441
|
+
...highlightContext,
|
|
442
|
+
});
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
function scheduleEditorStylesSync() {
|
|
446
|
+
const current = editor;
|
|
447
|
+
if (!current)
|
|
448
|
+
return;
|
|
449
|
+
void current.isReady.then(() => {
|
|
450
|
+
if (destroyed || editor !== current)
|
|
451
|
+
return;
|
|
452
|
+
syncPageFormatLayout();
|
|
453
|
+
syncShowFieldsHighlight();
|
|
454
|
+
});
|
|
455
|
+
}
|
|
456
|
+
function syncDesignChromeVisibility() {
|
|
457
|
+
if (useDesignPanels) {
|
|
458
|
+
if (designMode) {
|
|
459
|
+
designShell?.show();
|
|
460
|
+
}
|
|
461
|
+
else {
|
|
462
|
+
designShell?.hide();
|
|
463
|
+
propertiesPanel?.showEmpty();
|
|
464
|
+
selectedSectionBlockIndex = -1;
|
|
465
|
+
clearStructureSelection();
|
|
466
|
+
updateSectionSelectionHighlight();
|
|
467
|
+
}
|
|
468
|
+
if (designToolbarWrap)
|
|
469
|
+
designToolbarWrap.hidden = !designMode;
|
|
470
|
+
}
|
|
471
|
+
// Format toolbar is design-only; Preview lives in document actions / host chrome.
|
|
472
|
+
if (richTextToolbar?.element)
|
|
473
|
+
richTextToolbar.element.hidden = !designMode;
|
|
474
|
+
syncShowFieldsHighlight();
|
|
475
|
+
}
|
|
476
|
+
if (options.imageUpload) {
|
|
477
|
+
configureImageUpload(options.imageUpload);
|
|
478
|
+
}
|
|
479
|
+
if (Array.isArray(options.formulaFunctions)) {
|
|
480
|
+
for (const def of options.formulaFunctions) {
|
|
481
|
+
if (def)
|
|
482
|
+
registerFormulaFunction(def);
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
const fieldModalParent = resolveFieldModalParent(holder);
|
|
486
|
+
const previewModalParent = resolvePreviewModalParent(holder);
|
|
487
|
+
const treeModal = createTreeModal({ parent: fieldModalParent });
|
|
488
|
+
const listModal = createListModal({ parent: fieldModalParent });
|
|
489
|
+
const textModal = createTextModal({ parent: fieldModalParent });
|
|
490
|
+
const htmlTextModal = createHtmlTextModal({ parent: fieldModalParent });
|
|
491
|
+
const integerModal = createIntegerModal({ parent: fieldModalParent });
|
|
492
|
+
const signatureModal = createSignatureModal({ parent: fieldModalParent });
|
|
493
|
+
const imageModal = createImageModal({ parent: fieldModalParent });
|
|
494
|
+
const repeaterEditorModal = createRepeaterEditorModal({
|
|
495
|
+
getEditorOptions: () => options,
|
|
496
|
+
});
|
|
497
|
+
const schemaEditor = createSchemaEditorModal({
|
|
498
|
+
getRegistry: () => registry,
|
|
499
|
+
onRepeaterTemplateChange: (fieldId, schema) => applyRepeaterSchemaUpdate(fieldId, schema),
|
|
500
|
+
getRemoteListCollections: options.remoteListCollections ?? null,
|
|
501
|
+
getRemoteListLabelFields: options.remoteListLabelFields ?? null,
|
|
502
|
+
});
|
|
503
|
+
configureSchemaItemsDesignerModal();
|
|
504
|
+
const previewModal = createPreviewModal({
|
|
505
|
+
getFieldValueStyle: () => fieldValueStyle,
|
|
506
|
+
defaultPdfFilename: ui.pdfFilename ?? 'document.pdf',
|
|
507
|
+
pdfTitle: ui.pdfTitle,
|
|
508
|
+
getPageSetup: () => documentPageSetup,
|
|
509
|
+
getTextStyle: getFormTextStyle,
|
|
510
|
+
generatePdfBlob: options.generatePdfBlob ?? null,
|
|
511
|
+
pdfAvailable: options.pdfAvailable,
|
|
512
|
+
embedPdfInIframe: ui.embedPdfInIframe !== false,
|
|
513
|
+
parent: previewModalParent,
|
|
514
|
+
onOpenChange: (open) => {
|
|
515
|
+
options.onPreviewStateChange?.(!!open);
|
|
516
|
+
},
|
|
517
|
+
onShareDocument: typeof options.onShareDocument === 'function' ? options.onShareDocument : null,
|
|
518
|
+
});
|
|
519
|
+
const fieldMappingModal = options.mappingMode
|
|
520
|
+
? null
|
|
521
|
+
: createFieldMappingModal({
|
|
522
|
+
getTemplate: () => ({
|
|
523
|
+
blocks: registry.getBlocks(),
|
|
524
|
+
fieldSchemas: registry.getFieldSchemas(),
|
|
525
|
+
}),
|
|
526
|
+
onSave: (spec) => {
|
|
527
|
+
documentFieldMapping = spec;
|
|
528
|
+
refreshDatabaseSourceTree?.();
|
|
529
|
+
refreshDesignMappingBadges();
|
|
530
|
+
},
|
|
531
|
+
});
|
|
532
|
+
const richTextToolbar = createRichTextToolbar();
|
|
533
|
+
/** Depth of open nested field dialogs — keeps host Escape blockers accurate when stacked. */
|
|
534
|
+
let nestedModalDepth = 0;
|
|
535
|
+
function notifyNestedModal(open) {
|
|
536
|
+
if (open)
|
|
537
|
+
nestedModalDepth += 1;
|
|
538
|
+
else
|
|
539
|
+
nestedModalDepth = Math.max(0, nestedModalDepth - 1);
|
|
540
|
+
options.onNestedModalStateChange?.(nestedModalDepth > 0);
|
|
541
|
+
}
|
|
542
|
+
function guardNestedModal(promise) {
|
|
543
|
+
notifyNestedModal(true);
|
|
544
|
+
return Promise.resolve(promise).then((result) => {
|
|
545
|
+
// Resolved (OK / Clear) — not Close/Escape/cancel.
|
|
546
|
+
options.onFieldPickerApplied?.();
|
|
547
|
+
return result;
|
|
548
|
+
}, (err) => {
|
|
549
|
+
throw err;
|
|
550
|
+
}).finally(() => {
|
|
551
|
+
notifyNestedModal(false);
|
|
552
|
+
});
|
|
553
|
+
}
|
|
554
|
+
const openTree = options.pickers?.openTreePicker ??
|
|
555
|
+
((opts) => treeModal.open({ ...opts, textStyle: getFormTextStyle() }));
|
|
556
|
+
const openList = options.pickers?.openListPicker ??
|
|
557
|
+
((opts) => listModal.open({ ...opts, textStyle: getFormTextStyle() }));
|
|
558
|
+
const openText = options.pickers?.openTextPicker ??
|
|
559
|
+
((opts) => textModal.open({ ...opts, textStyle: getFormTextStyle() }));
|
|
560
|
+
const openHtmlText = options.pickers?.openHtmlTextPicker ??
|
|
561
|
+
((opts) => htmlTextModal.open({ ...opts, textStyle: getFormTextStyle() }));
|
|
562
|
+
const openInteger = options.pickers?.openIntegerPicker ?? ((opts) => integerModal.open(opts));
|
|
563
|
+
const openSignature = options.pickers?.openSignaturePicker ?? ((opts) => signatureModal.open(opts));
|
|
564
|
+
const openImage = options.pickers?.openImagePicker ?? ((opts) => imageModal.open(opts));
|
|
565
|
+
const openDate = options.pickers?.openDatePicker;
|
|
566
|
+
const pickerCallbacks = {
|
|
567
|
+
...(options.pickers ?? {}),
|
|
568
|
+
openTreePicker: (opts) => guardNestedModal(Promise.resolve(openTree(opts))),
|
|
569
|
+
openListPicker: (opts) => guardNestedModal(Promise.resolve(openList(opts))),
|
|
570
|
+
openTextPicker: (opts) => guardNestedModal(Promise.resolve(openText(opts))),
|
|
571
|
+
openHtmlTextPicker: (opts) => guardNestedModal(Promise.resolve(openHtmlText(opts))),
|
|
572
|
+
openIntegerPicker: (opts) => guardNestedModal(Promise.resolve(openInteger(opts))),
|
|
573
|
+
openSignaturePicker: (opts) => guardNestedModal(Promise.resolve(openSignature(opts))),
|
|
574
|
+
openImagePicker: (opts) => guardNestedModal(Promise.resolve(openImage(opts))),
|
|
575
|
+
openDatePicker: openDate
|
|
576
|
+
? (opts) => guardNestedModal(Promise.resolve(openDate({ ...opts, parent: fieldModalParent })))
|
|
577
|
+
: undefined,
|
|
578
|
+
};
|
|
579
|
+
function getAllDocumentEditables() {
|
|
580
|
+
return [...holder.querySelectorAll('.document-section__body')];
|
|
581
|
+
}
|
|
582
|
+
function resolveTargetEditable() {
|
|
583
|
+
if (lastFocusedEditable?.isConnected)
|
|
584
|
+
return lastFocusedEditable;
|
|
585
|
+
if (editor) {
|
|
586
|
+
const currentIndex = editor.blocks.getCurrentBlockIndex();
|
|
587
|
+
if (currentIndex >= 0) {
|
|
588
|
+
const blocks = holder.querySelectorAll('.ce-block');
|
|
589
|
+
const editable = blocks[currentIndex]?.querySelector('.document-section__body');
|
|
590
|
+
if (editable)
|
|
591
|
+
return editable;
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
const all = getAllDocumentEditables();
|
|
595
|
+
return all[all.length - 1] ?? null;
|
|
596
|
+
}
|
|
597
|
+
async function ensureDocumentSectionAtEnd() {
|
|
598
|
+
await editor.isReady;
|
|
599
|
+
let editable = resolveTargetEditable();
|
|
600
|
+
if (!editable) {
|
|
601
|
+
const count = editor.blocks.getBlocksCount();
|
|
602
|
+
await editor.blocks.insert('documentSection', createUniqueSectionData(), {}, count);
|
|
603
|
+
await editor.isReady;
|
|
604
|
+
editable = getAllDocumentEditables().at(-1) ?? null;
|
|
605
|
+
}
|
|
606
|
+
if (editable) {
|
|
607
|
+
lastFocusedEditable = editable;
|
|
608
|
+
focusCaretAtEnd(editable);
|
|
609
|
+
}
|
|
610
|
+
return editable;
|
|
611
|
+
}
|
|
612
|
+
function applyLiveTableColumnWidths(tableId, columns) {
|
|
613
|
+
if (!tableId || !Array.isArray(columns))
|
|
614
|
+
return;
|
|
615
|
+
const schema = registry.getFieldSchemas()?.[tableId];
|
|
616
|
+
if (!schema || schema.type !== 'table')
|
|
617
|
+
return;
|
|
618
|
+
registry.updateFieldSchema(tableId, { ...schema, columns });
|
|
619
|
+
applyTableColumnWidthsToElement(findLiveTableEl(tableId), columns);
|
|
620
|
+
options.onSchemaChange?.(registry.getFieldSchemas());
|
|
621
|
+
}
|
|
622
|
+
function syncTableWidthsToProperties(tableId, columns) {
|
|
623
|
+
if (!propertiesPanel || !tableId)
|
|
624
|
+
return;
|
|
625
|
+
propertiesPanel.cancelPersist?.();
|
|
626
|
+
propertiesPanel.syncTableColumnWidths?.(tableId, columns);
|
|
627
|
+
}
|
|
628
|
+
function handleTableColumnWidthsChange(tableId, columns) {
|
|
629
|
+
// Same path as typing in Properties — splitter updates schema already, but
|
|
630
|
+
// must re-apply col + header widths or the canvas can stay equal-width.
|
|
631
|
+
applyTableColumnWidthsToElement(findLiveTableEl(tableId), columns);
|
|
632
|
+
options.onSchemaChange?.(registry.getFieldSchemas());
|
|
633
|
+
syncTableWidthsToProperties(tableId, columns);
|
|
634
|
+
}
|
|
635
|
+
function handleTableColumnWidthsPreview(tableId, columns) {
|
|
636
|
+
syncTableWidthsToProperties(tableId, columns);
|
|
637
|
+
}
|
|
638
|
+
function handleTableColumnResizeStart(tableId) {
|
|
639
|
+
const columns = propertiesPanel?.commitLiveTableColumnWidths?.(tableId);
|
|
640
|
+
if (columns)
|
|
641
|
+
applyLiveTableColumnWidths(tableId, columns);
|
|
642
|
+
propertiesPanel?.cancelPersist?.();
|
|
643
|
+
}
|
|
644
|
+
function isTableWidthOnlyChange(prev, next) {
|
|
645
|
+
if (!prev || prev.type !== 'table' || next?.type !== 'table')
|
|
646
|
+
return false;
|
|
647
|
+
if (!!prev.hideHeader !== !!next.hideHeader)
|
|
648
|
+
return false;
|
|
649
|
+
if (!!prev.hideBorders !== !!next.hideBorders)
|
|
650
|
+
return false;
|
|
651
|
+
if (!!prev.allowAddRows !== !!next.allowAddRows)
|
|
652
|
+
return false;
|
|
653
|
+
if (String(prev.name ?? prev.label ?? '') !== String(next.name ?? next.label ?? ''))
|
|
654
|
+
return false;
|
|
655
|
+
if (String(prev.label ?? '') !== String(next.label ?? ''))
|
|
656
|
+
return false;
|
|
657
|
+
const prevCols = prev.columns ?? [];
|
|
658
|
+
const nextCols = next.columns ?? [];
|
|
659
|
+
if (prevCols.length !== nextCols.length)
|
|
660
|
+
return false;
|
|
661
|
+
return prevCols.every((col, index) => (col.key === nextCols[index].key &&
|
|
662
|
+
col.label === nextCols[index].label &&
|
|
663
|
+
(col.name ?? col.label) === (nextCols[index].name ?? nextCols[index].label)));
|
|
664
|
+
}
|
|
665
|
+
function refreshDesignMappingBadges() {
|
|
666
|
+
if (!holder || options.mappingMode)
|
|
667
|
+
return;
|
|
668
|
+
applyMappingBadges(holder, documentFieldMapping?.rules ?? [], {
|
|
669
|
+
getRegistry: () => registry,
|
|
670
|
+
fieldValueStyle,
|
|
671
|
+
});
|
|
672
|
+
}
|
|
673
|
+
/**
|
|
674
|
+
* Keep fieldMapping.rules section/field/child names (and fieldIds) aligned with
|
|
675
|
+
* the live template after renames.
|
|
676
|
+
*/
|
|
677
|
+
function syncDocumentFieldMappingNames(blocks = registry.getBlocks() ?? [], fieldSchemas = registry.getFieldSchemas(), fieldIdRenames = null) {
|
|
678
|
+
if (!documentFieldMapping?.rules?.length)
|
|
679
|
+
return;
|
|
680
|
+
documentFieldMapping = syncFieldMappingSpecToSchema(documentFieldMapping, blocks, fieldSchemas, fieldIdRenames ? { fieldIdRenames } : undefined);
|
|
681
|
+
refreshDesignMappingBadges();
|
|
682
|
+
}
|
|
683
|
+
function commitMappingRules(rules) {
|
|
684
|
+
if (!rules?.length)
|
|
685
|
+
return;
|
|
686
|
+
documentFieldMapping = normalizeFieldMappingSpec(mergeMappingRulesIntoSpec(documentFieldMapping, rules));
|
|
687
|
+
refreshDesignMappingBadges();
|
|
688
|
+
scheduleHistoryRecord();
|
|
689
|
+
}
|
|
690
|
+
function getInlineFieldOptions() {
|
|
691
|
+
return {
|
|
692
|
+
getRegistry: () => registry,
|
|
693
|
+
fieldValueStyle,
|
|
694
|
+
designMode,
|
|
695
|
+
designPropertiesPanel: useDesignPanels && designMode,
|
|
696
|
+
openEditor: !(useDesignPanels && designMode),
|
|
697
|
+
onEditSchema: handleEditSchema,
|
|
698
|
+
onDeleteField: (fieldId, token) => {
|
|
699
|
+
token?.remove();
|
|
700
|
+
handleDeleteSchema(fieldId);
|
|
701
|
+
},
|
|
702
|
+
onPaletteDrop: handlePaletteDrop,
|
|
703
|
+
onSourcePathCanvasDrop: handleSourcePathCanvasDrop,
|
|
704
|
+
onSchemaChange: (schemas) => options.onSchemaChange?.(schemas),
|
|
705
|
+
onTableColumnWidthsChange: handleTableColumnWidthsChange,
|
|
706
|
+
onTableColumnWidthsPreview: handleTableColumnWidthsPreview,
|
|
707
|
+
onTableColumnResizeStart: handleTableColumnResizeStart,
|
|
708
|
+
onTableColumnsChange: (tableId, columns) => {
|
|
709
|
+
propertiesPanel?.cancelPersist?.();
|
|
710
|
+
propertiesPanel?.syncTableColumns?.(tableId, columns);
|
|
711
|
+
options.onSchemaChange?.(registry.getFieldSchemas());
|
|
712
|
+
scheduleHistoryRecord();
|
|
713
|
+
},
|
|
714
|
+
onColumnsWidthsChange: (columnsEl) => {
|
|
715
|
+
// Keep the columns block selected in the properties panel after a splitter drag.
|
|
716
|
+
if (columnsEl?.isConnected) {
|
|
717
|
+
selectColumnsEl(columnsEl);
|
|
718
|
+
}
|
|
719
|
+
},
|
|
720
|
+
};
|
|
721
|
+
}
|
|
722
|
+
function syncSectionDataToRegistry(sectionData, sectionEl = null) {
|
|
723
|
+
if (!sectionData)
|
|
724
|
+
return;
|
|
725
|
+
const blocks = [...(registry.getBlocks() ?? [])];
|
|
726
|
+
let index = -1;
|
|
727
|
+
// Prefer DOM block index so duplicate section names (legacy Untitled…) do not
|
|
728
|
+
// overwrite the wrong registry entry.
|
|
729
|
+
if (sectionEl?.closest) {
|
|
730
|
+
const ceBlock = sectionEl.closest('.ce-block');
|
|
731
|
+
if (ceBlock) {
|
|
732
|
+
const allBlocks = [...holder.querySelectorAll('.ce-block')];
|
|
733
|
+
index = allBlocks.indexOf(ceBlock);
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
if (index < 0 || blocks[index]?.type !== 'documentSection') {
|
|
737
|
+
const sectionName = resolveSectionName(sectionData);
|
|
738
|
+
index = blocks.findIndex((block) => block.type === 'documentSection' && resolveSectionName(block.data ?? {}) === sectionName);
|
|
739
|
+
}
|
|
740
|
+
if (index < 0 || blocks[index]?.type !== 'documentSection')
|
|
741
|
+
return;
|
|
742
|
+
blocks[index] = {
|
|
743
|
+
...blocks[index],
|
|
744
|
+
data: {
|
|
745
|
+
...blocks[index].data,
|
|
746
|
+
...sectionData,
|
|
747
|
+
},
|
|
748
|
+
};
|
|
749
|
+
registry.setBlocks(blocks);
|
|
750
|
+
scheduleHistoryRecord();
|
|
751
|
+
}
|
|
752
|
+
function collectLiveSectionNames() {
|
|
753
|
+
const used = collectUsedSectionNames(registry.getBlocks() ?? []);
|
|
754
|
+
holder.querySelectorAll?.('.document-section[data-section-name]')?.forEach((el) => {
|
|
755
|
+
const name = el.getAttribute('data-section-name');
|
|
756
|
+
if (name)
|
|
757
|
+
used.add(name);
|
|
758
|
+
});
|
|
759
|
+
return used;
|
|
760
|
+
}
|
|
761
|
+
/** Names allocated for in-flight inserts before registry/DOM catch up. */
|
|
762
|
+
const pendingSectionNames = new Set();
|
|
763
|
+
function allocateSectionName() {
|
|
764
|
+
const used = collectLiveSectionNames();
|
|
765
|
+
for (const name of pendingSectionNames)
|
|
766
|
+
used.add(name);
|
|
767
|
+
const next = allocateUniqueSectionName(used, DEFAULT_SECTION_NAME);
|
|
768
|
+
pendingSectionNames.add(next);
|
|
769
|
+
queueMicrotask(() => {
|
|
770
|
+
const live = collectLiveSectionNames();
|
|
771
|
+
for (const name of [...pendingSectionNames]) {
|
|
772
|
+
if (live.has(name))
|
|
773
|
+
pendingSectionNames.delete(name);
|
|
774
|
+
}
|
|
775
|
+
});
|
|
776
|
+
return next;
|
|
777
|
+
}
|
|
778
|
+
function createUniqueSectionData(extra = {}) {
|
|
779
|
+
const name = allocateSectionName();
|
|
780
|
+
return {
|
|
781
|
+
name,
|
|
782
|
+
label: '',
|
|
783
|
+
segments: [],
|
|
784
|
+
fieldValues: {},
|
|
785
|
+
...extra,
|
|
786
|
+
};
|
|
787
|
+
}
|
|
788
|
+
function getHistorySnapshot() {
|
|
789
|
+
const snap = {
|
|
790
|
+
fieldSchemas: registry.getFieldSchemas() ?? {},
|
|
791
|
+
blocks: registry.getBlocks() ?? [],
|
|
792
|
+
};
|
|
793
|
+
if (Object.keys(documentPageSetup).length > 0) {
|
|
794
|
+
snap.pageSetup = documentPageSetup;
|
|
795
|
+
}
|
|
796
|
+
if (documentFieldMapping) {
|
|
797
|
+
snap.fieldMapping = documentFieldMapping;
|
|
798
|
+
}
|
|
799
|
+
return cloneHistorySnapshot(snap);
|
|
800
|
+
}
|
|
801
|
+
function scheduleHistoryRecord(immediate = false) {
|
|
802
|
+
if (destroyed || historyBusy || documentHistory.isSuspended())
|
|
803
|
+
return;
|
|
804
|
+
const run = () => {
|
|
805
|
+
historyTimer = null;
|
|
806
|
+
if (destroyed || historyBusy || documentHistory.isSuspended())
|
|
807
|
+
return;
|
|
808
|
+
documentHistory.record(getHistorySnapshot());
|
|
809
|
+
};
|
|
810
|
+
if (immediate) {
|
|
811
|
+
if (historyTimer) {
|
|
812
|
+
clearTimeout(historyTimer);
|
|
813
|
+
historyTimer = null;
|
|
814
|
+
}
|
|
815
|
+
run();
|
|
816
|
+
return;
|
|
817
|
+
}
|
|
818
|
+
if (historyTimer)
|
|
819
|
+
clearTimeout(historyTimer);
|
|
820
|
+
historyTimer = setTimeout(run, 400);
|
|
821
|
+
}
|
|
822
|
+
function flushHistoryRecord() {
|
|
823
|
+
if (historyTimer) {
|
|
824
|
+
clearTimeout(historyTimer);
|
|
825
|
+
historyTimer = null;
|
|
826
|
+
if (!destroyed && !historyBusy && !documentHistory.isSuspended()) {
|
|
827
|
+
documentHistory.record(getHistorySnapshot());
|
|
828
|
+
}
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
function canSoftRestoreHistory(snapshot) {
|
|
832
|
+
if (!editor || !snapshot || destroyed)
|
|
833
|
+
return false;
|
|
834
|
+
const snapBlocks = snapshot.blocks ?? [];
|
|
835
|
+
const liveBlocks = listEditorBlocks();
|
|
836
|
+
if (liveBlocks.length !== snapBlocks.length)
|
|
837
|
+
return false;
|
|
838
|
+
for (let i = 0; i < snapBlocks.length; i += 1) {
|
|
839
|
+
const snapBlock = snapBlocks[i];
|
|
840
|
+
if (!snapBlock || snapBlock.type !== 'documentSection')
|
|
841
|
+
return false;
|
|
842
|
+
const section = liveBlocks[i]?.querySelector?.('.document-section');
|
|
843
|
+
if (!section?.__documentSectionTool?.applyHistoryData)
|
|
844
|
+
return false;
|
|
845
|
+
}
|
|
846
|
+
return true;
|
|
847
|
+
}
|
|
848
|
+
function softRestoreHistory(snapshot) {
|
|
849
|
+
const normalized = normalizeDocument(snapshot, {
|
|
850
|
+
defaultDocument: options.defaultDocument,
|
|
851
|
+
visionTableFieldId: options.visionTableFieldId,
|
|
852
|
+
});
|
|
853
|
+
registry.setFieldSchemas({ ...normalized.fieldSchemas });
|
|
854
|
+
registry.setBlocks(normalized.blocks ?? []);
|
|
855
|
+
options.onSchemaChange?.(registry.getFieldSchemas());
|
|
856
|
+
documentPageSetup = snapshot.pageSetup
|
|
857
|
+
? migratePageSetup(JSON.parse(JSON.stringify(snapshot.pageSetup)))
|
|
858
|
+
: {};
|
|
859
|
+
documentFieldMapping = snapshot.fieldMapping
|
|
860
|
+
? normalizeFieldMappingSpec(snapshot.fieldMapping)
|
|
861
|
+
: null;
|
|
862
|
+
refreshDatabaseSourceTree?.();
|
|
863
|
+
refreshDesignMappingBadges();
|
|
864
|
+
syncStylesFromPageSetup();
|
|
865
|
+
const liveBlocks = listEditorBlocks();
|
|
866
|
+
const snapBlocks = normalized.blocks ?? [];
|
|
867
|
+
for (let i = 0; i < snapBlocks.length; i += 1) {
|
|
868
|
+
const block = snapBlocks[i];
|
|
869
|
+
if (block?.type !== 'documentSection')
|
|
870
|
+
continue;
|
|
871
|
+
const section = liveBlocks[i]?.querySelector?.('.document-section');
|
|
872
|
+
section?.__documentSectionTool?.applyHistoryData?.(block.data ?? {});
|
|
873
|
+
}
|
|
874
|
+
refreshSectionVisibility();
|
|
875
|
+
}
|
|
876
|
+
async function restoreHistorySnapshot(snapshot, focusHint = null) {
|
|
877
|
+
if (!snapshot || historyBusy || destroyed)
|
|
878
|
+
return false;
|
|
879
|
+
historyBusy = true;
|
|
880
|
+
const resume = documentHistory.suspend();
|
|
881
|
+
try {
|
|
882
|
+
if (historyTimer) {
|
|
883
|
+
clearTimeout(historyTimer);
|
|
884
|
+
historyTimer = null;
|
|
885
|
+
}
|
|
886
|
+
if (canSoftRestoreHistory(snapshot)) {
|
|
887
|
+
softRestoreHistory(snapshot);
|
|
888
|
+
}
|
|
889
|
+
else {
|
|
890
|
+
initEditor(snapshot);
|
|
891
|
+
if (editor)
|
|
892
|
+
await editor.isReady;
|
|
893
|
+
}
|
|
894
|
+
if (useDesignPanels && designMode && propertiesPanel) {
|
|
895
|
+
syncPropertiesPanel();
|
|
896
|
+
}
|
|
897
|
+
options.onChange?.(await getDocument());
|
|
898
|
+
restoreEditorFocusAfterHistory(focusHint);
|
|
899
|
+
return true;
|
|
900
|
+
}
|
|
901
|
+
catch {
|
|
902
|
+
return false;
|
|
903
|
+
}
|
|
904
|
+
finally {
|
|
905
|
+
resume();
|
|
906
|
+
historyBusy = false;
|
|
907
|
+
}
|
|
908
|
+
}
|
|
909
|
+
function captureHistoryFocusHint() {
|
|
910
|
+
const active = document.activeElement;
|
|
911
|
+
const editable = active?.closest?.('.document-section__body') ??
|
|
912
|
+
(lastFocusedEditable?.isConnected ? lastFocusedEditable : null) ??
|
|
913
|
+
null;
|
|
914
|
+
if (!editable || !holder.contains(editable)) {
|
|
915
|
+
return { sectionIndex: 0 };
|
|
916
|
+
}
|
|
917
|
+
const sections = [...holder.querySelectorAll('.document-section__body')];
|
|
918
|
+
const sectionIndex = Math.max(0, sections.indexOf(editable));
|
|
919
|
+
const sectionName = editable.closest?.('.document-section')?.getAttribute?.('data-section-name') ?? null;
|
|
920
|
+
return { sectionIndex, sectionName };
|
|
921
|
+
}
|
|
922
|
+
function resolveHistoryFocusEditable(focusHint = null) {
|
|
923
|
+
const editables = [...holder.querySelectorAll('.document-section__body')];
|
|
924
|
+
if (!editables.length)
|
|
925
|
+
return null;
|
|
926
|
+
if (focusHint?.sectionName) {
|
|
927
|
+
const byName = editables.find((el) => el.closest?.('.document-section')?.getAttribute?.('data-section-name') ===
|
|
928
|
+
focusHint.sectionName);
|
|
929
|
+
if (byName)
|
|
930
|
+
return byName;
|
|
931
|
+
}
|
|
932
|
+
const index = Number(focusHint?.sectionIndex);
|
|
933
|
+
if (Number.isFinite(index) && index >= 0 && index < editables.length) {
|
|
934
|
+
return editables[index];
|
|
935
|
+
}
|
|
936
|
+
return editables[0];
|
|
937
|
+
}
|
|
938
|
+
function restoreEditorFocusAfterHistory(focusHint = null) {
|
|
939
|
+
if (destroyed)
|
|
940
|
+
return;
|
|
941
|
+
const editable = resolveHistoryFocusEditable(focusHint);
|
|
942
|
+
if (!editable || typeof editable.focus !== 'function')
|
|
943
|
+
return;
|
|
944
|
+
lastFocusedEditable = editable;
|
|
945
|
+
const focusEditable = () => {
|
|
946
|
+
if (!editable.isConnected || destroyed)
|
|
947
|
+
return;
|
|
948
|
+
editable.focus({ preventScroll: true });
|
|
949
|
+
try {
|
|
950
|
+
const sel = window.getSelection();
|
|
951
|
+
const range = document.createRange();
|
|
952
|
+
range.selectNodeContents(editable);
|
|
953
|
+
range.collapse(false);
|
|
954
|
+
sel?.removeAllRanges();
|
|
955
|
+
sel?.addRange(range);
|
|
956
|
+
}
|
|
957
|
+
catch {
|
|
958
|
+
// linkedom / restricted selections
|
|
959
|
+
}
|
|
960
|
+
if (!options.mappingMode) {
|
|
961
|
+
richTextToolbar?.show?.(editable);
|
|
962
|
+
}
|
|
963
|
+
};
|
|
964
|
+
// Remount finishes asynchronously; focus after the new editable is interactive.
|
|
965
|
+
requestAnimationFrame(() => {
|
|
966
|
+
requestAnimationFrame(focusEditable);
|
|
967
|
+
});
|
|
968
|
+
}
|
|
969
|
+
async function undoDocument() {
|
|
970
|
+
flushHistoryRecord();
|
|
971
|
+
const focusHint = captureHistoryFocusHint();
|
|
972
|
+
const snapshot = documentHistory.undo();
|
|
973
|
+
if (!snapshot)
|
|
974
|
+
return false;
|
|
975
|
+
return restoreHistorySnapshot(snapshot, focusHint);
|
|
976
|
+
}
|
|
977
|
+
async function redoDocument() {
|
|
978
|
+
flushHistoryRecord();
|
|
979
|
+
const focusHint = captureHistoryFocusHint();
|
|
980
|
+
const snapshot = documentHistory.redo();
|
|
981
|
+
if (!snapshot)
|
|
982
|
+
return false;
|
|
983
|
+
return restoreHistorySnapshot(snapshot, focusHint);
|
|
984
|
+
}
|
|
985
|
+
function shouldHandleHistoryShortcut(e) {
|
|
986
|
+
const raw = e.target;
|
|
987
|
+
const el = raw?.nodeType === Node.ELEMENT_NODE ? raw : raw?.parentElement;
|
|
988
|
+
if (!el)
|
|
989
|
+
return false;
|
|
990
|
+
if (el.closest?.('.modal-overlay:not([hidden])'))
|
|
991
|
+
return false;
|
|
992
|
+
if (el.closest?.('input, textarea, select')) {
|
|
993
|
+
// Let native undo work in property forms / prompts outside the canvas.
|
|
994
|
+
if (!el.closest?.('.document-section__body, .document-columns__col'))
|
|
995
|
+
return false;
|
|
996
|
+
}
|
|
997
|
+
return true;
|
|
998
|
+
}
|
|
999
|
+
function refreshSectionVisibility() {
|
|
1000
|
+
if (designMode || options.mappingMode)
|
|
1001
|
+
return;
|
|
1002
|
+
const blocks = registry.getBlocks() ?? [];
|
|
1003
|
+
const values = collectAllFieldValuesFromHolder(holder);
|
|
1004
|
+
const schemas = registry.getFieldSchemas();
|
|
1005
|
+
const blockEls = [...holder.querySelectorAll('.ce-block')];
|
|
1006
|
+
for (let index = 0; index < blockEls.length; index += 1) {
|
|
1007
|
+
const blockEl = blockEls[index];
|
|
1008
|
+
const block = blocks[index];
|
|
1009
|
+
if (block?.type !== 'documentSection') {
|
|
1010
|
+
blockEl.hidden = false;
|
|
1011
|
+
continue;
|
|
1012
|
+
}
|
|
1013
|
+
blockEl.hidden = !evaluateSectionVisibility(block.data?.visibility, values, schemas);
|
|
1014
|
+
}
|
|
1015
|
+
}
|
|
1016
|
+
async function getBlocksForProperties() {
|
|
1017
|
+
await editor.isReady;
|
|
1018
|
+
let blocks = registry.getBlocks() ?? [];
|
|
1019
|
+
if (!blocks.length) {
|
|
1020
|
+
const saved = await editor.save();
|
|
1021
|
+
blocks = saved.blocks ?? [];
|
|
1022
|
+
registry.setBlocks(blocks);
|
|
1023
|
+
}
|
|
1024
|
+
return blocks;
|
|
1025
|
+
}
|
|
1026
|
+
/**
|
|
1027
|
+
* When a table cell token is selected but its schema was never materialised
|
|
1028
|
+
* (or was pruned), recreate cell schemas so the properties panel can open.
|
|
1029
|
+
*/
|
|
1030
|
+
function ensureFieldSchemaForProperties(fieldId, token = null) {
|
|
1031
|
+
const schemas = registry.getFieldSchemas();
|
|
1032
|
+
if (schemas[fieldId])
|
|
1033
|
+
return schemas[fieldId];
|
|
1034
|
+
const tableId = token?.dataset?.tableId;
|
|
1035
|
+
const wrapper = tableId
|
|
1036
|
+
? (token?.closest?.('.document-table') ??
|
|
1037
|
+
holder.querySelector(`.document-table[data-table-id="${CSS.escape(tableId)}"]`))
|
|
1038
|
+
: null;
|
|
1039
|
+
const { fieldSchemas: next, schema } = ensureSchemaForFieldProperties(fieldId, schemas, {
|
|
1040
|
+
tableId,
|
|
1041
|
+
rowKey: token?.dataset?.rowKey,
|
|
1042
|
+
colKey: token?.dataset?.colKey,
|
|
1043
|
+
rows: wrapper ? readTableRowsFromDom(wrapper) : undefined,
|
|
1044
|
+
});
|
|
1045
|
+
if (!schema)
|
|
1046
|
+
return null;
|
|
1047
|
+
if (next !== schemas)
|
|
1048
|
+
registry.setFieldSchemas(next);
|
|
1049
|
+
return schema;
|
|
1050
|
+
}
|
|
1051
|
+
async function loadFieldProperties(fieldId, token = null) {
|
|
1052
|
+
if (!propertiesPanel || !editor)
|
|
1053
|
+
return;
|
|
1054
|
+
const schema = registry.getFieldSchemas()[fieldId] ??
|
|
1055
|
+
ensureFieldSchemaForProperties(fieldId, token ?? findLiveFieldToken(fieldId, holder));
|
|
1056
|
+
if (!schema)
|
|
1057
|
+
return;
|
|
1058
|
+
try {
|
|
1059
|
+
const blocks = await getBlocksForProperties();
|
|
1060
|
+
const schemas = registry.getFieldSchemas();
|
|
1061
|
+
const liveSchema = schemas[fieldId] ?? schema;
|
|
1062
|
+
const placement = findFieldPlacement(fieldId, blocks);
|
|
1063
|
+
selectedSectionBlockIndex = -1;
|
|
1064
|
+
updateSectionSelectionHighlight();
|
|
1065
|
+
clearColumnsSelection();
|
|
1066
|
+
if (liveSchema.type === 'table' || liveSchema.type === 'pivotTable') {
|
|
1067
|
+
const tableEl = findLiveTableEl(fieldId);
|
|
1068
|
+
if (tableEl) {
|
|
1069
|
+
clearTableSelection();
|
|
1070
|
+
selectedTableEl = tableEl;
|
|
1071
|
+
tableEl.classList.add('document-table--selected');
|
|
1072
|
+
}
|
|
1073
|
+
else {
|
|
1074
|
+
clearTableSelection();
|
|
1075
|
+
}
|
|
1076
|
+
}
|
|
1077
|
+
else {
|
|
1078
|
+
clearTableSelection();
|
|
1079
|
+
}
|
|
1080
|
+
propertiesPanel.showField(fieldId, liveSchema, {
|
|
1081
|
+
sectionName: placement.sectionName,
|
|
1082
|
+
sectionLabel: placement.sectionName,
|
|
1083
|
+
blocks,
|
|
1084
|
+
fieldSchemas: schemas,
|
|
1085
|
+
});
|
|
1086
|
+
}
|
|
1087
|
+
catch {
|
|
1088
|
+
// editor not ready
|
|
1089
|
+
}
|
|
1090
|
+
}
|
|
1091
|
+
async function applySchemaSaveResult(result, previousType, previousSchema) {
|
|
1092
|
+
const { fieldId: newFieldId, previousFieldId, schema: updated } = result;
|
|
1093
|
+
const idChanged = newFieldId !== previousFieldId;
|
|
1094
|
+
const typeChanged = previousType !== updated.type;
|
|
1095
|
+
// Compatible inline type change — update schema + tokens without remounting Editor.js.
|
|
1096
|
+
if (!idChanged && typeChanged && canRefreshFieldTypeInDom(previousType, updated.type)) {
|
|
1097
|
+
const defaultValue = resolveSchemaDefaultValue(updated, { forTemplate: true });
|
|
1098
|
+
let nextSchemas = syncColumnListSourceSettings(previousFieldId, updated, {
|
|
1099
|
+
...registry.getFieldSchemas(),
|
|
1100
|
+
[previousFieldId]: updated,
|
|
1101
|
+
});
|
|
1102
|
+
registry.setFieldSchemas(nextSchemas);
|
|
1103
|
+
const registryBlocks = registry.getBlocks() ?? [];
|
|
1104
|
+
if (registryBlocks.length) {
|
|
1105
|
+
registry.setBlocks(syncBlocksAfterSchemaChange(registryBlocks, previousFieldId, updated));
|
|
1106
|
+
}
|
|
1107
|
+
const tokenSelector = `.field-token[data-field-id="${CSS.escape(previousFieldId)}"]`;
|
|
1108
|
+
for (const section of holder.querySelectorAll('.document-section')) {
|
|
1109
|
+
const tool = section.__documentSectionTool;
|
|
1110
|
+
if (!tool?.data)
|
|
1111
|
+
continue;
|
|
1112
|
+
if (!section.querySelector(tokenSelector))
|
|
1113
|
+
continue;
|
|
1114
|
+
if (!tool.data.fieldValues || typeof tool.data.fieldValues !== 'object') {
|
|
1115
|
+
tool.data.fieldValues = {};
|
|
1116
|
+
}
|
|
1117
|
+
tool.data.fieldValues[previousFieldId] = defaultValue;
|
|
1118
|
+
}
|
|
1119
|
+
const ctx = { getRegistry: () => registry, fieldValueStyle };
|
|
1120
|
+
for (const token of holder.querySelectorAll(tokenSelector)) {
|
|
1121
|
+
updateFieldToken(token, defaultValue, updated.label ?? token.dataset.placeholder, ctx);
|
|
1122
|
+
}
|
|
1123
|
+
for (const wrapper of holder.querySelectorAll('.template-block')) {
|
|
1124
|
+
if (!wrapper.querySelector(tokenSelector))
|
|
1125
|
+
continue;
|
|
1126
|
+
for (const cls of [...wrapper.classList]) {
|
|
1127
|
+
if (cls.startsWith('template-block--'))
|
|
1128
|
+
wrapper.classList.remove(cls);
|
|
1129
|
+
}
|
|
1130
|
+
wrapper.classList.add(`template-block--${updated.type}`);
|
|
1131
|
+
}
|
|
1132
|
+
refreshFieldSchemaInDom(previousFieldId, ctx, holder);
|
|
1133
|
+
const cellRef = parseCellFieldId(previousFieldId, registry.getFieldSchemas());
|
|
1134
|
+
if (cellRef) {
|
|
1135
|
+
refreshTableColumnStylesForFieldIds([previousFieldId], registry.getFieldSchemas(), holder, fieldValueStyle);
|
|
1136
|
+
}
|
|
1137
|
+
options.onSchemaChange?.(registry.getFieldSchemas());
|
|
1138
|
+
syncDocumentFieldMappingNames();
|
|
1139
|
+
scheduleHistoryRecord(true);
|
|
1140
|
+
return true;
|
|
1141
|
+
}
|
|
1142
|
+
if (idChanged || typeChanged) {
|
|
1143
|
+
const saved = await editor.save();
|
|
1144
|
+
let nextSchemas = registry.getFieldSchemas();
|
|
1145
|
+
let nextBlocks = saved.blocks;
|
|
1146
|
+
if (idChanged) {
|
|
1147
|
+
try {
|
|
1148
|
+
const changeResult = applyFieldIdChange(previousFieldId, newFieldId, updated, nextSchemas, nextBlocks);
|
|
1149
|
+
nextSchemas = changeResult.fieldSchemas;
|
|
1150
|
+
nextBlocks = changeResult.blocks;
|
|
1151
|
+
}
|
|
1152
|
+
catch (err) {
|
|
1153
|
+
showNotification(err.message ?? 'Could not rename field ID.');
|
|
1154
|
+
return false;
|
|
1155
|
+
}
|
|
1156
|
+
}
|
|
1157
|
+
else {
|
|
1158
|
+
registry.updateFieldSchema(previousFieldId, updated);
|
|
1159
|
+
nextSchemas = registry.getFieldSchemas();
|
|
1160
|
+
nextBlocks = syncBlocksAfterSchemaChange(nextBlocks, previousFieldId, updated);
|
|
1161
|
+
}
|
|
1162
|
+
if (updated.type === 'table') {
|
|
1163
|
+
const migrated = syncTableColumnKeyChanges(newFieldId, previousSchema.columns, updated.columns, nextSchemas, nextBlocks);
|
|
1164
|
+
nextSchemas = migrated.fieldSchemas;
|
|
1165
|
+
nextBlocks = migrated.blocks;
|
|
1166
|
+
nextSchemas = ensureCellSchemas(updated, newFieldId, nextSchemas, undefined);
|
|
1167
|
+
}
|
|
1168
|
+
if (updated.type === 'child') {
|
|
1169
|
+
nextBlocks = normalizeRepeaterFieldInBlocks(nextBlocks, newFieldId, updated);
|
|
1170
|
+
}
|
|
1171
|
+
registry.setFieldSchemas(nextSchemas);
|
|
1172
|
+
options.onSchemaChange?.(registry.getFieldSchemas());
|
|
1173
|
+
syncDocumentFieldMappingNames(nextBlocks, nextSchemas, idChanged ? { [previousFieldId]: newFieldId } : null);
|
|
1174
|
+
initEditor({
|
|
1175
|
+
time: saved.time,
|
|
1176
|
+
fieldSchemas: registry.getFieldSchemas(),
|
|
1177
|
+
blocks: nextBlocks,
|
|
1178
|
+
});
|
|
1179
|
+
return true;
|
|
1180
|
+
}
|
|
1181
|
+
if (updated.type === 'table') {
|
|
1182
|
+
if (!idChanged && isTableWidthOnlyChange(previousSchema, updated)) {
|
|
1183
|
+
registry.updateFieldSchema(previousFieldId, {
|
|
1184
|
+
...previousSchema,
|
|
1185
|
+
...updated,
|
|
1186
|
+
columns: updated.columns,
|
|
1187
|
+
});
|
|
1188
|
+
applyTableColumnWidthsToElement(findLiveTableEl(previousFieldId), updated.columns);
|
|
1189
|
+
options.onSchemaChange?.(registry.getFieldSchemas());
|
|
1190
|
+
return true;
|
|
1191
|
+
}
|
|
1192
|
+
const saved = await editor.save();
|
|
1193
|
+
let nextSchemas = registry.getFieldSchemas();
|
|
1194
|
+
let nextBlocks = saved.blocks;
|
|
1195
|
+
if (previousSchema.type === 'table') {
|
|
1196
|
+
const migrated = syncTableColumnKeyChanges(previousFieldId, previousSchema.columns, updated.columns, nextSchemas, nextBlocks);
|
|
1197
|
+
nextSchemas = migrated.fieldSchemas;
|
|
1198
|
+
nextBlocks = migrated.blocks;
|
|
1199
|
+
}
|
|
1200
|
+
registry.updateFieldSchema(previousFieldId, updated);
|
|
1201
|
+
nextSchemas = ensureCellSchemas(updated, previousFieldId, {
|
|
1202
|
+
...nextSchemas,
|
|
1203
|
+
[previousFieldId]: updated,
|
|
1204
|
+
}, undefined);
|
|
1205
|
+
registry.setFieldSchemas(nextSchemas);
|
|
1206
|
+
options.onSchemaChange?.(registry.getFieldSchemas());
|
|
1207
|
+
syncDocumentFieldMappingNames(nextBlocks, nextSchemas);
|
|
1208
|
+
initEditor({
|
|
1209
|
+
time: saved.time,
|
|
1210
|
+
fieldSchemas: registry.getFieldSchemas(),
|
|
1211
|
+
blocks: nextBlocks,
|
|
1212
|
+
});
|
|
1213
|
+
return true;
|
|
1214
|
+
}
|
|
1215
|
+
if (updated.type === 'child') {
|
|
1216
|
+
const saved = await editor.save();
|
|
1217
|
+
let nextBlocks = saved.blocks;
|
|
1218
|
+
registry.updateFieldSchema(previousFieldId, updated);
|
|
1219
|
+
nextBlocks = normalizeRepeaterFieldInBlocks(nextBlocks, previousFieldId, updated);
|
|
1220
|
+
registry.setFieldSchemas(registry.getFieldSchemas());
|
|
1221
|
+
options.onSchemaChange?.(registry.getFieldSchemas());
|
|
1222
|
+
syncDocumentFieldMappingNames(nextBlocks, registry.getFieldSchemas());
|
|
1223
|
+
initEditor({
|
|
1224
|
+
time: saved.time,
|
|
1225
|
+
fieldSchemas: registry.getFieldSchemas(),
|
|
1226
|
+
blocks: nextBlocks,
|
|
1227
|
+
});
|
|
1228
|
+
return true;
|
|
1229
|
+
}
|
|
1230
|
+
const nextSchemas = syncColumnListSourceSettings(previousFieldId, updated, {
|
|
1231
|
+
...registry.getFieldSchemas(),
|
|
1232
|
+
[previousFieldId]: updated,
|
|
1233
|
+
});
|
|
1234
|
+
registry.setFieldSchemas(nextSchemas);
|
|
1235
|
+
options.onSchemaChange?.(registry.getFieldSchemas());
|
|
1236
|
+
refreshFieldSchemaInDom(previousFieldId, { getRegistry: () => registry, fieldValueStyle }, holder);
|
|
1237
|
+
const cellRef = parseCellFieldId(previousFieldId, registry.getFieldSchemas());
|
|
1238
|
+
if (cellRef) {
|
|
1239
|
+
refreshTableColumnStylesForFieldIds([previousFieldId], registry.getFieldSchemas(), holder, fieldValueStyle);
|
|
1240
|
+
}
|
|
1241
|
+
syncDocumentFieldMappingNames();
|
|
1242
|
+
return true;
|
|
1243
|
+
}
|
|
1244
|
+
async function handlePaletteDrop(item, container, clientX, clientY) {
|
|
1245
|
+
const opts = getInlineFieldOptions();
|
|
1246
|
+
if (item.kind === 'layout' && item.type === 'columns') {
|
|
1247
|
+
insertColumnsAtPoint(container, clientX, clientY, opts);
|
|
1248
|
+
return;
|
|
1249
|
+
}
|
|
1250
|
+
if (item.kind !== 'field')
|
|
1251
|
+
return;
|
|
1252
|
+
if (getFieldHandler(item.type)?.insertion === 'table' || item.type === 'table') {
|
|
1253
|
+
const { fieldId } = await insertPaletteTableAtPoint(container, clientX, clientY, {
|
|
1254
|
+
...opts,
|
|
1255
|
+
fieldType: item.type === 'pivotTable' ? 'pivotTable' : 'table',
|
|
1256
|
+
});
|
|
1257
|
+
options.onSchemaChange?.(registry.getFieldSchemas());
|
|
1258
|
+
await handleEditSchema(fieldId);
|
|
1259
|
+
return;
|
|
1260
|
+
}
|
|
1261
|
+
if (item.type === 'child') {
|
|
1262
|
+
const { fieldId } = await insertPaletteFieldAtPoint(container, 'child', clientX, clientY, opts);
|
|
1263
|
+
options.onSchemaChange?.(registry.getFieldSchemas());
|
|
1264
|
+
await handleEditSchema(fieldId);
|
|
1265
|
+
return;
|
|
1266
|
+
}
|
|
1267
|
+
if (isInlineFieldType(item.type)) {
|
|
1268
|
+
const { fieldId } = await insertPaletteFieldAtPoint(container, item.type, clientX, clientY, opts);
|
|
1269
|
+
options.onSchemaChange?.(registry.getFieldSchemas());
|
|
1270
|
+
await handleEditSchema(fieldId);
|
|
1271
|
+
}
|
|
1272
|
+
}
|
|
1273
|
+
async function handleSourcePathCanvasDrop(meta, container, clientX, clientY, dropTarget) {
|
|
1274
|
+
const sourcePath = String(meta?.path ?? '').trim();
|
|
1275
|
+
if (!sourcePath)
|
|
1276
|
+
return;
|
|
1277
|
+
const sample = documentFieldMapping?.sourceSample;
|
|
1278
|
+
const plan = classifySourcePathDrop({
|
|
1279
|
+
path: sourcePath,
|
|
1280
|
+
type: meta?.type,
|
|
1281
|
+
label: meta?.label,
|
|
1282
|
+
sample,
|
|
1283
|
+
});
|
|
1284
|
+
// Prefer mapping onto an existing field/cell/pivot when dropped on one
|
|
1285
|
+
// (except array-member drops onto a table, which add a column instead).
|
|
1286
|
+
const pivot = dropTarget?.closest?.('.document-table--pivot[data-pivot-field-id]');
|
|
1287
|
+
const token = dropTarget?.closest?.('.field-token');
|
|
1288
|
+
const tableWrapper = dropTarget?.closest?.('.document-table[data-table-id]:not(.document-table--pivot)') ?? null;
|
|
1289
|
+
const mapTargetId = pivot?.dataset?.pivotFieldId || pivot?.dataset?.tableId || token?.dataset?.fieldId;
|
|
1290
|
+
const droppingArrayColumnOntoTable = plan.kind === 'table-column' && tableWrapper && !pivot;
|
|
1291
|
+
if (mapTargetId && !token?.classList?.contains?.('field-token--computed') && !droppingArrayColumnOntoTable) {
|
|
1292
|
+
let blocks = registry.getBlocks() ?? [];
|
|
1293
|
+
if (editor) {
|
|
1294
|
+
const saved = await editor.save();
|
|
1295
|
+
blocks = saved.blocks ?? blocks;
|
|
1296
|
+
registry.setBlocks(blocks);
|
|
1297
|
+
}
|
|
1298
|
+
const rules = createMappingRulesFromDrop(mapTargetId, sourcePath, blocks, registry.getFieldSchemas(), {
|
|
1299
|
+
childFieldIds: [],
|
|
1300
|
+
bulkChild: !!token?.classList?.contains?.('field-token--repeater'),
|
|
1301
|
+
});
|
|
1302
|
+
commitMappingRules(rules);
|
|
1303
|
+
return;
|
|
1304
|
+
}
|
|
1305
|
+
const opts = {
|
|
1306
|
+
...getInlineFieldOptions(),
|
|
1307
|
+
openEditor: false,
|
|
1308
|
+
};
|
|
1309
|
+
async function syncBlocks() {
|
|
1310
|
+
let blocks = registry.getBlocks() ?? [];
|
|
1311
|
+
if (editor) {
|
|
1312
|
+
const saved = await editor.save();
|
|
1313
|
+
blocks = saved.blocks ?? blocks;
|
|
1314
|
+
registry.setBlocks(blocks);
|
|
1315
|
+
}
|
|
1316
|
+
return blocks;
|
|
1317
|
+
}
|
|
1318
|
+
// 1) Scalar → simple typed field (with visible "Label: " before the token)
|
|
1319
|
+
if (plan.kind === 'field') {
|
|
1320
|
+
const { fieldId } = await insertPaletteFieldAtPoint(container, plan.fieldType, clientX, clientY, { ...opts, label: plan.label, insertVisibleLabel: true, readonly: true });
|
|
1321
|
+
options.onSchemaChange?.(registry.getFieldSchemas());
|
|
1322
|
+
const blocks = await syncBlocks();
|
|
1323
|
+
const rules = createMappingRulesFromDrop(fieldId, plan.sourcePath, blocks, registry.getFieldSchemas());
|
|
1324
|
+
commitMappingRules(rules);
|
|
1325
|
+
return;
|
|
1326
|
+
}
|
|
1327
|
+
// 2) Array member → add column only when dropped on a table; otherwise new 1-col table
|
|
1328
|
+
if (plan.kind === 'table-column') {
|
|
1329
|
+
if (tableWrapper) {
|
|
1330
|
+
const added = addTableColumnToWrapper(tableWrapper, plan.column, {
|
|
1331
|
+
...opts,
|
|
1332
|
+
getRegistry: () => registry,
|
|
1333
|
+
onSchemaChange: (schemas) => options.onSchemaChange?.(schemas),
|
|
1334
|
+
});
|
|
1335
|
+
if (added) {
|
|
1336
|
+
const sectionBody = tableWrapper.closest?.('.document-section__body') ?? container;
|
|
1337
|
+
sectionBody?.dispatchEvent?.(new InputEvent('input', { bubbles: true }));
|
|
1338
|
+
const blocks = await syncBlocks();
|
|
1339
|
+
const rules = buildTableMappingRulesFromSourceDrop({
|
|
1340
|
+
tableFieldId: added.tableId,
|
|
1341
|
+
blocks,
|
|
1342
|
+
fieldSchemas: registry.getFieldSchemas(),
|
|
1343
|
+
columnSourcePaths: [{ columnKey: added.columnKey, sourcePath: plan.sourcePath }],
|
|
1344
|
+
});
|
|
1345
|
+
commitMappingRules(rules);
|
|
1346
|
+
return;
|
|
1347
|
+
}
|
|
1348
|
+
}
|
|
1349
|
+
const { fieldId } = await insertPaletteTableAtPoint(container, clientX, clientY, {
|
|
1350
|
+
...opts,
|
|
1351
|
+
fieldType: 'table',
|
|
1352
|
+
label: plan.label,
|
|
1353
|
+
columns: [plan.column],
|
|
1354
|
+
readonly: true,
|
|
1355
|
+
});
|
|
1356
|
+
options.onSchemaChange?.(registry.getFieldSchemas());
|
|
1357
|
+
const blocks = await syncBlocks();
|
|
1358
|
+
const rules = buildTableMappingRulesFromSourceDrop({
|
|
1359
|
+
tableFieldId: fieldId,
|
|
1360
|
+
blocks,
|
|
1361
|
+
fieldSchemas: registry.getFieldSchemas(),
|
|
1362
|
+
columnSourcePaths: [{ columnKey: plan.column.key, sourcePath: plan.sourcePath }],
|
|
1363
|
+
});
|
|
1364
|
+
commitMappingRules(rules);
|
|
1365
|
+
return;
|
|
1366
|
+
}
|
|
1367
|
+
// 3) Whole array → multi-column table
|
|
1368
|
+
const { fieldId } = await insertPaletteTableAtPoint(container, clientX, clientY, {
|
|
1369
|
+
...opts,
|
|
1370
|
+
fieldType: 'table',
|
|
1371
|
+
label: plan.label,
|
|
1372
|
+
columns: plan.columns,
|
|
1373
|
+
readonly: true,
|
|
1374
|
+
});
|
|
1375
|
+
options.onSchemaChange?.(registry.getFieldSchemas());
|
|
1376
|
+
const blocks = await syncBlocks();
|
|
1377
|
+
const rules = buildTableMappingRulesFromSourceDrop({
|
|
1378
|
+
tableFieldId: fieldId,
|
|
1379
|
+
blocks,
|
|
1380
|
+
fieldSchemas: registry.getFieldSchemas(),
|
|
1381
|
+
columnSourcePaths: plan.columnSourcePaths,
|
|
1382
|
+
});
|
|
1383
|
+
commitMappingRules(rules);
|
|
1384
|
+
}
|
|
1385
|
+
async function insertDocumentSection(atIndex) {
|
|
1386
|
+
if (!editor)
|
|
1387
|
+
return;
|
|
1388
|
+
await editor.isReady;
|
|
1389
|
+
const count = editor.blocks.getBlocksCount();
|
|
1390
|
+
const index = atIndex ?? count;
|
|
1391
|
+
const sectionData = createUniqueSectionData();
|
|
1392
|
+
await editor.blocks.insert('documentSection', sectionData, {}, index);
|
|
1393
|
+
selectedSectionBlockIndex = index;
|
|
1394
|
+
if (propertiesPanel) {
|
|
1395
|
+
propertiesPanel.showSection(index, {
|
|
1396
|
+
name: sectionData.name,
|
|
1397
|
+
label: sectionData.label,
|
|
1398
|
+
});
|
|
1399
|
+
updateSectionSelectionHighlight();
|
|
1400
|
+
}
|
|
1401
|
+
}
|
|
1402
|
+
async function insertColumnsIntoTargetSection() {
|
|
1403
|
+
await editor.isReady;
|
|
1404
|
+
let editable = resolveTargetEditable();
|
|
1405
|
+
if (!editable) {
|
|
1406
|
+
editable = await ensureDocumentSectionAtEnd();
|
|
1407
|
+
}
|
|
1408
|
+
else {
|
|
1409
|
+
editable.focus();
|
|
1410
|
+
}
|
|
1411
|
+
if (!editable)
|
|
1412
|
+
return;
|
|
1413
|
+
insertColumnsAtCaret(editable, getInlineFieldOptions());
|
|
1414
|
+
editable.dispatchEvent(new InputEvent('input', { bubbles: true }));
|
|
1415
|
+
lastFocusedEditable = editable;
|
|
1416
|
+
}
|
|
1417
|
+
async function handleSaveSection({ blockIndex, name, label, repeatable, hideTitleInPreview, borderTop, borderBottom, eachRowOnNewPage, keepOnOnePage, visibility, sectionEl, }) {
|
|
1418
|
+
if (!editor)
|
|
1419
|
+
return;
|
|
1420
|
+
const saved = await editor.save();
|
|
1421
|
+
const blocks = [...saved.blocks];
|
|
1422
|
+
const block = blocks[blockIndex];
|
|
1423
|
+
if (!block || block.type !== 'documentSection')
|
|
1424
|
+
return;
|
|
1425
|
+
const oldSectionName = resolveSectionName(block.data);
|
|
1426
|
+
const clearedRepeatableIndexes = [];
|
|
1427
|
+
if (repeatable) {
|
|
1428
|
+
for (let i = 0; i < blocks.length; i += 1) {
|
|
1429
|
+
if (i === blockIndex)
|
|
1430
|
+
continue;
|
|
1431
|
+
const other = blocks[i];
|
|
1432
|
+
if (other.type === 'documentSection' && other.data?.repeatable) {
|
|
1433
|
+
other.data = { ...other.data, repeatable: false };
|
|
1434
|
+
blocks[i] = other;
|
|
1435
|
+
clearedRepeatableIndexes.push(i);
|
|
1436
|
+
}
|
|
1437
|
+
}
|
|
1438
|
+
}
|
|
1439
|
+
block.data = {
|
|
1440
|
+
...block.data,
|
|
1441
|
+
name,
|
|
1442
|
+
label,
|
|
1443
|
+
repeatable: !!repeatable,
|
|
1444
|
+
hideTitleInPreview: !!hideTitleInPreview,
|
|
1445
|
+
borderTop: !!borderTop,
|
|
1446
|
+
borderBottom: !!borderBottom,
|
|
1447
|
+
eachRowOnNewPage: !!eachRowOnNewPage,
|
|
1448
|
+
keepOnOnePage: !!keepOnOnePage,
|
|
1449
|
+
visibility: visibility ?? null,
|
|
1450
|
+
};
|
|
1451
|
+
blocks[blockIndex] = block;
|
|
1452
|
+
const newSectionName = resolveSectionName(block.data);
|
|
1453
|
+
const nameChanged = oldSectionName !== newSectionName;
|
|
1454
|
+
if (!nameChanged) {
|
|
1455
|
+
registry.setBlocks(blocks);
|
|
1456
|
+
const section = sectionEl ??
|
|
1457
|
+
listEditorBlocks()[blockIndex]?.querySelector('.document-section') ??
|
|
1458
|
+
null;
|
|
1459
|
+
const tool = section?.__documentSectionTool;
|
|
1460
|
+
if (tool?.applyPropertiesPatch) {
|
|
1461
|
+
tool.applyPropertiesPatch({
|
|
1462
|
+
name,
|
|
1463
|
+
label,
|
|
1464
|
+
repeatable: !!repeatable,
|
|
1465
|
+
hideTitleInPreview: !!hideTitleInPreview,
|
|
1466
|
+
borderTop: !!borderTop,
|
|
1467
|
+
borderBottom: !!borderBottom,
|
|
1468
|
+
eachRowOnNewPage: !!eachRowOnNewPage,
|
|
1469
|
+
keepOnOnePage: !!keepOnOnePage,
|
|
1470
|
+
visibility: visibility ?? null,
|
|
1471
|
+
});
|
|
1472
|
+
}
|
|
1473
|
+
for (const index of clearedRepeatableIndexes) {
|
|
1474
|
+
const otherSection = listEditorBlocks()[index]?.querySelector('.document-section');
|
|
1475
|
+
const otherTool = otherSection?.__documentSectionTool;
|
|
1476
|
+
otherTool?.applyPropertiesPatch?.({ repeatable: false });
|
|
1477
|
+
}
|
|
1478
|
+
selectedSectionBlockIndex = blockIndex;
|
|
1479
|
+
updateSectionSelectionHighlight();
|
|
1480
|
+
scheduleHistoryRecord(true);
|
|
1481
|
+
options.onChange?.(await getDocument());
|
|
1482
|
+
return;
|
|
1483
|
+
}
|
|
1484
|
+
let nextSchemas = registry.getFieldSchemas();
|
|
1485
|
+
nextSchemas = renameSectionInFormulas(nextSchemas, oldSectionName, newSectionName);
|
|
1486
|
+
const result = rebuildFieldIdsForSection(block, nextSchemas, blocks);
|
|
1487
|
+
nextSchemas = result.fieldSchemas;
|
|
1488
|
+
const nextBlocks = result.blocks;
|
|
1489
|
+
registry.setFieldSchemas(nextSchemas);
|
|
1490
|
+
options.onSchemaChange?.(registry.getFieldSchemas());
|
|
1491
|
+
selectedSectionBlockIndex = blockIndex;
|
|
1492
|
+
syncDocumentFieldMappingNames(nextBlocks, nextSchemas, result.idRenames);
|
|
1493
|
+
initEditor({
|
|
1494
|
+
time: saved.time,
|
|
1495
|
+
fieldSchemas: nextSchemas,
|
|
1496
|
+
blocks: nextBlocks,
|
|
1497
|
+
pageSetup: documentPageSetup,
|
|
1498
|
+
});
|
|
1499
|
+
if (!designMode || !useDesignPanels)
|
|
1500
|
+
return;
|
|
1501
|
+
try {
|
|
1502
|
+
await editor.isReady;
|
|
1503
|
+
await loadSelectedSectionProperties();
|
|
1504
|
+
}
|
|
1505
|
+
catch {
|
|
1506
|
+
// editor not ready
|
|
1507
|
+
}
|
|
1508
|
+
}
|
|
1509
|
+
function openPageSetupPanel() {
|
|
1510
|
+
selectedSectionBlockIndex = -1;
|
|
1511
|
+
clearStructureSelection();
|
|
1512
|
+
clearAllDesignTokenSelection(holder);
|
|
1513
|
+
updateSectionSelectionHighlight();
|
|
1514
|
+
propertiesPanel?.showDocument(documentPageSetup);
|
|
1515
|
+
}
|
|
1516
|
+
async function handleSaveDocument(pageSetup) {
|
|
1517
|
+
documentPageSetup = pageSetup ? JSON.parse(JSON.stringify(pageSetup)) : {};
|
|
1518
|
+
syncStylesFromPageSetup();
|
|
1519
|
+
scheduleHistoryRecord(true);
|
|
1520
|
+
options.onChange?.(await getDocument());
|
|
1521
|
+
}
|
|
1522
|
+
function clearColumnsSelection(columnsEl = null) {
|
|
1523
|
+
const selector = columnsEl
|
|
1524
|
+
? null
|
|
1525
|
+
: '.document-columns--selected';
|
|
1526
|
+
if (columnsEl) {
|
|
1527
|
+
columnsEl.classList.remove('document-columns--selected');
|
|
1528
|
+
}
|
|
1529
|
+
else {
|
|
1530
|
+
holder.querySelectorAll(selector).forEach((el) => {
|
|
1531
|
+
el.classList.remove('document-columns--selected');
|
|
1532
|
+
});
|
|
1533
|
+
}
|
|
1534
|
+
if (!columnsEl || selectedColumnsEl === columnsEl) {
|
|
1535
|
+
selectedColumnsEl = null;
|
|
1536
|
+
}
|
|
1537
|
+
}
|
|
1538
|
+
function clearTableSelection(tableEl = null) {
|
|
1539
|
+
const selector = tableEl ? null : '.document-table--selected';
|
|
1540
|
+
if (tableEl) {
|
|
1541
|
+
tableEl.classList.remove('document-table--selected');
|
|
1542
|
+
}
|
|
1543
|
+
else {
|
|
1544
|
+
holder.querySelectorAll(selector).forEach((el) => {
|
|
1545
|
+
el.classList.remove('document-table--selected');
|
|
1546
|
+
});
|
|
1547
|
+
}
|
|
1548
|
+
if (!tableEl || selectedTableEl === tableEl) {
|
|
1549
|
+
selectedTableEl = null;
|
|
1550
|
+
}
|
|
1551
|
+
}
|
|
1552
|
+
function clearStructureSelection() {
|
|
1553
|
+
clearColumnsSelection();
|
|
1554
|
+
clearTableSelection();
|
|
1555
|
+
}
|
|
1556
|
+
/** Section / table / columns chrome — not free prose the user is typing into. */
|
|
1557
|
+
function isDesignStructureTarget(target) {
|
|
1558
|
+
if (!target?.closest)
|
|
1559
|
+
return false;
|
|
1560
|
+
if (target.closest('.document-section__header, .document-table__toolbar, .document-columns__toolbar, .editor-drag-handle, .vision-table__col-resizer, .document-columns__col-resizer')) {
|
|
1561
|
+
return true;
|
|
1562
|
+
}
|
|
1563
|
+
if (target.closest('.document-table'))
|
|
1564
|
+
return true;
|
|
1565
|
+
// Columns wrapper chrome, but not the editable column body.
|
|
1566
|
+
if (target.closest('.document-columns') && !target.closest('.document-columns__col')) {
|
|
1567
|
+
return true;
|
|
1568
|
+
}
|
|
1569
|
+
return false;
|
|
1570
|
+
}
|
|
1571
|
+
function shouldClearObjectSelectionForTextTarget(target) {
|
|
1572
|
+
if (!target || !designMode || !useDesignPanels)
|
|
1573
|
+
return false;
|
|
1574
|
+
if (target.closest?.('.field-token'))
|
|
1575
|
+
return false;
|
|
1576
|
+
if (isDesignStructureTarget(target))
|
|
1577
|
+
return false;
|
|
1578
|
+
const prose = target.closest?.('.document-section__body, .document-columns__col');
|
|
1579
|
+
return !!(prose && holder.contains(prose));
|
|
1580
|
+
}
|
|
1581
|
+
/** Drop Section/Table/Columns/Setup selection when the caret moves into plain text. */
|
|
1582
|
+
function clearObjectSelectionForTextEdit() {
|
|
1583
|
+
if (!useDesignPanels || !designMode || !propertiesPanel)
|
|
1584
|
+
return;
|
|
1585
|
+
const mode = propertiesPanel.getMode?.();
|
|
1586
|
+
const hadObjectSelection = selectedSectionBlockIndex >= 0 ||
|
|
1587
|
+
!!selectedTableEl?.isConnected ||
|
|
1588
|
+
!!selectedColumnsEl?.isConnected ||
|
|
1589
|
+
mode === 'section' ||
|
|
1590
|
+
mode === 'columns' ||
|
|
1591
|
+
mode === 'document';
|
|
1592
|
+
if (!hadObjectSelection)
|
|
1593
|
+
return;
|
|
1594
|
+
selectedSectionBlockIndex = -1;
|
|
1595
|
+
clearStructureSelection();
|
|
1596
|
+
updateSectionSelectionHighlight();
|
|
1597
|
+
if (!getSelectedDesignFieldTokens().length) {
|
|
1598
|
+
propertiesPanel.showEmpty();
|
|
1599
|
+
}
|
|
1600
|
+
}
|
|
1601
|
+
function findLiveTableEl(tableId) {
|
|
1602
|
+
if (!tableId)
|
|
1603
|
+
return null;
|
|
1604
|
+
try {
|
|
1605
|
+
return holder.querySelector(`.document-table[data-table-id="${CSS.escape(tableId)}"]`);
|
|
1606
|
+
}
|
|
1607
|
+
catch {
|
|
1608
|
+
return null;
|
|
1609
|
+
}
|
|
1610
|
+
}
|
|
1611
|
+
function removeTableSchemas(tableId) {
|
|
1612
|
+
if (!tableId)
|
|
1613
|
+
return;
|
|
1614
|
+
const next = { ...registry.getFieldSchemas() };
|
|
1615
|
+
delete next[tableId];
|
|
1616
|
+
const prefix = `${tableId}_`;
|
|
1617
|
+
for (const key of Object.keys(next)) {
|
|
1618
|
+
if (key.startsWith(prefix))
|
|
1619
|
+
delete next[key];
|
|
1620
|
+
}
|
|
1621
|
+
registry.setFieldSchemas(next);
|
|
1622
|
+
options.onSchemaChange?.(next);
|
|
1623
|
+
}
|
|
1624
|
+
function removeOwnedSchemasFromSubtree(root) {
|
|
1625
|
+
if (!root?.querySelectorAll)
|
|
1626
|
+
return;
|
|
1627
|
+
const tableIds = new Set();
|
|
1628
|
+
root.querySelectorAll('.document-table[data-table-id]').forEach((el) => {
|
|
1629
|
+
if (el.dataset.tableId)
|
|
1630
|
+
tableIds.add(el.dataset.tableId);
|
|
1631
|
+
});
|
|
1632
|
+
for (const tableId of tableIds) {
|
|
1633
|
+
removeTableSchemas(tableId);
|
|
1634
|
+
}
|
|
1635
|
+
root.querySelectorAll('.field-token[data-field-id]:not(.field-token--cell)').forEach((token) => {
|
|
1636
|
+
const fieldId = token.dataset.fieldId;
|
|
1637
|
+
if (!fieldId || tableIds.has(fieldId))
|
|
1638
|
+
return;
|
|
1639
|
+
handleDeleteSchema(fieldId);
|
|
1640
|
+
});
|
|
1641
|
+
}
|
|
1642
|
+
function selectColumnsEl(columnsEl) {
|
|
1643
|
+
if (!columnsEl?.isConnected)
|
|
1644
|
+
return;
|
|
1645
|
+
clearAllDesignTokenSelection(holder);
|
|
1646
|
+
selectedSectionBlockIndex = -1;
|
|
1647
|
+
updateSectionSelectionHighlight();
|
|
1648
|
+
clearStructureSelection();
|
|
1649
|
+
selectedColumnsEl = columnsEl;
|
|
1650
|
+
columnsEl.classList.add('document-columns--selected');
|
|
1651
|
+
focusStructureTarget(columnsEl);
|
|
1652
|
+
loadSelectedColumnsProperties(columnsEl);
|
|
1653
|
+
}
|
|
1654
|
+
function selectTableEl(tableEl) {
|
|
1655
|
+
if (!tableEl?.isConnected)
|
|
1656
|
+
return;
|
|
1657
|
+
const tableId = tableEl.dataset.tableId;
|
|
1658
|
+
const alreadyShowing = selectedTableEl === tableEl
|
|
1659
|
+
&& propertiesPanel?.getCurrentFieldId?.() === tableId;
|
|
1660
|
+
if (alreadyShowing) {
|
|
1661
|
+
tableEl.classList.add('document-table--selected');
|
|
1662
|
+
focusStructureTarget(tableEl);
|
|
1663
|
+
return;
|
|
1664
|
+
}
|
|
1665
|
+
clearAllDesignTokenSelection(holder);
|
|
1666
|
+
selectedSectionBlockIndex = -1;
|
|
1667
|
+
updateSectionSelectionHighlight();
|
|
1668
|
+
clearStructureSelection();
|
|
1669
|
+
selectedTableEl = tableEl;
|
|
1670
|
+
tableEl.classList.add('document-table--selected');
|
|
1671
|
+
focusStructureTarget(tableEl);
|
|
1672
|
+
if (tableId)
|
|
1673
|
+
void loadFieldProperties(tableId, null);
|
|
1674
|
+
}
|
|
1675
|
+
function loadSelectedColumnsProperties(columnsEl = selectedColumnsEl) {
|
|
1676
|
+
if (!columnsEl?.isConnected || !propertiesPanel)
|
|
1677
|
+
return;
|
|
1678
|
+
const widths = [
|
|
1679
|
+
columnsEl.dataset.columnWidth0 ?? '',
|
|
1680
|
+
columnsEl.dataset.columnWidth1 ?? '',
|
|
1681
|
+
];
|
|
1682
|
+
propertiesPanel.showColumns(columnsEl, { widths });
|
|
1683
|
+
}
|
|
1684
|
+
function notifyStructureRemoved(sectionBody) {
|
|
1685
|
+
sectionBody?.dispatchEvent?.(new InputEvent('input', { bubbles: true }));
|
|
1686
|
+
scheduleHistoryRecord(true);
|
|
1687
|
+
if (propertiesPanel && designMode && useDesignPanels) {
|
|
1688
|
+
propertiesPanel.showEmpty();
|
|
1689
|
+
}
|
|
1690
|
+
}
|
|
1691
|
+
function deleteSelectedColumnsBlock() {
|
|
1692
|
+
const columnsEl = selectedColumnsEl;
|
|
1693
|
+
if (!columnsEl?.isConnected)
|
|
1694
|
+
return false;
|
|
1695
|
+
const sectionBody = columnsEl.closest('.document-section__body');
|
|
1696
|
+
removeOwnedSchemasFromSubtree(columnsEl);
|
|
1697
|
+
clearColumnsSelection(columnsEl);
|
|
1698
|
+
columnsEl.remove();
|
|
1699
|
+
notifyStructureRemoved(sectionBody);
|
|
1700
|
+
return true;
|
|
1701
|
+
}
|
|
1702
|
+
function deleteSelectedTableBlock() {
|
|
1703
|
+
const tableEl = selectedTableEl;
|
|
1704
|
+
if (!tableEl?.isConnected)
|
|
1705
|
+
return false;
|
|
1706
|
+
const sectionBody = tableEl.closest('.document-section__body');
|
|
1707
|
+
const tableId = tableEl.dataset.tableId;
|
|
1708
|
+
clearTableSelection(tableEl);
|
|
1709
|
+
tableEl.remove();
|
|
1710
|
+
removeTableSchemas(tableId);
|
|
1711
|
+
notifyStructureRemoved(sectionBody);
|
|
1712
|
+
return true;
|
|
1713
|
+
}
|
|
1714
|
+
async function deleteSelectedSectionBlock() {
|
|
1715
|
+
if (!editor || selectedSectionBlockIndex < 0)
|
|
1716
|
+
return false;
|
|
1717
|
+
const index = selectedSectionBlockIndex;
|
|
1718
|
+
const before = countLiveDocumentSections();
|
|
1719
|
+
if (before <= 1) {
|
|
1720
|
+
showNotification('At least one section is required.', { type: 'status' });
|
|
1721
|
+
return false;
|
|
1722
|
+
}
|
|
1723
|
+
const sectionEl = listEditorBlocks()[index]?.querySelector('.document-section') ?? null;
|
|
1724
|
+
if (sectionEl)
|
|
1725
|
+
removeOwnedSchemasFromSubtree(sectionEl);
|
|
1726
|
+
editor.blocks.delete(index);
|
|
1727
|
+
// Guard may no-op when only one section remains.
|
|
1728
|
+
if (countLiveDocumentSections() >= before)
|
|
1729
|
+
return false;
|
|
1730
|
+
selectedSectionBlockIndex = -1;
|
|
1731
|
+
clearStructureSelection();
|
|
1732
|
+
clearAllDesignTokenSelection(holder);
|
|
1733
|
+
updateSectionSelectionHighlight();
|
|
1734
|
+
propertiesPanel?.showEmpty();
|
|
1735
|
+
scheduleHistoryRecord(true);
|
|
1736
|
+
return true;
|
|
1737
|
+
}
|
|
1738
|
+
function focusStructureTarget(el) {
|
|
1739
|
+
if (!el?.isConnected)
|
|
1740
|
+
return;
|
|
1741
|
+
if (!el.hasAttribute('tabindex'))
|
|
1742
|
+
el.setAttribute('tabindex', '-1');
|
|
1743
|
+
try {
|
|
1744
|
+
el.focus({ preventScroll: true });
|
|
1745
|
+
}
|
|
1746
|
+
catch {
|
|
1747
|
+
// ignore focus failures (hidden / detached)
|
|
1748
|
+
}
|
|
1749
|
+
}
|
|
1750
|
+
function shouldIgnoreStructureDeleteKey(e) {
|
|
1751
|
+
const candidates = [];
|
|
1752
|
+
if (typeof e.composedPath === 'function') {
|
|
1753
|
+
for (const node of e.composedPath()) {
|
|
1754
|
+
if (node instanceof Element) {
|
|
1755
|
+
candidates.push(node);
|
|
1756
|
+
break;
|
|
1757
|
+
}
|
|
1758
|
+
}
|
|
1759
|
+
}
|
|
1760
|
+
const target = e.target;
|
|
1761
|
+
if (target instanceof Element)
|
|
1762
|
+
candidates.push(target);
|
|
1763
|
+
else if (target && target.parentElement)
|
|
1764
|
+
candidates.push(target.parentElement);
|
|
1765
|
+
if (document.activeElement instanceof Element)
|
|
1766
|
+
candidates.push(document.activeElement);
|
|
1767
|
+
for (const el of candidates) {
|
|
1768
|
+
if (!el)
|
|
1769
|
+
continue;
|
|
1770
|
+
if (el.closest?.('.modal-overlay:not([hidden])'))
|
|
1771
|
+
return true;
|
|
1772
|
+
// Allow Delete to remove a selected section/table even when caret is in a
|
|
1773
|
+
// section body; only skip real form controls (e.g. Properties inputs).
|
|
1774
|
+
if (el.closest?.('input, textarea, select, .schema-editor, .document-section__label-input, .document-section__name-input')) {
|
|
1775
|
+
return true;
|
|
1776
|
+
}
|
|
1777
|
+
}
|
|
1778
|
+
// Prefer field-token Delete handling when fields are selected.
|
|
1779
|
+
if (getSelectedDesignFieldTokens().length)
|
|
1780
|
+
return true;
|
|
1781
|
+
return false;
|
|
1782
|
+
}
|
|
1783
|
+
async function handleSaveColumns({ columnsEl, widths }) {
|
|
1784
|
+
if (!columnsEl?.isConnected)
|
|
1785
|
+
return;
|
|
1786
|
+
applyColumnWidthsToElement(columnsEl, widths);
|
|
1787
|
+
const sectionBody = columnsEl.closest('.document-section__body');
|
|
1788
|
+
sectionBody?.dispatchEvent(new InputEvent('input', { bubbles: true }));
|
|
1789
|
+
selectedColumnsEl = columnsEl;
|
|
1790
|
+
scheduleHistoryRecord(true);
|
|
1791
|
+
}
|
|
1792
|
+
function syncPropertiesPanel() {
|
|
1793
|
+
if (!useDesignPanels || !designMode || !propertiesPanel)
|
|
1794
|
+
return;
|
|
1795
|
+
const tokens = getSelectedDesignFieldTokens();
|
|
1796
|
+
if (tokens.length >= 1) {
|
|
1797
|
+
const token = tokens[0];
|
|
1798
|
+
const fieldId = token.dataset.fieldId;
|
|
1799
|
+
if (fieldId) {
|
|
1800
|
+
const schema = registry.getFieldSchemas()[fieldId] ??
|
|
1801
|
+
ensureFieldSchemaForProperties(fieldId, token);
|
|
1802
|
+
if (schema) {
|
|
1803
|
+
selectedSectionBlockIndex = -1;
|
|
1804
|
+
clearStructureSelection();
|
|
1805
|
+
updateSectionSelectionHighlight();
|
|
1806
|
+
void loadFieldProperties(fieldId, token);
|
|
1807
|
+
return;
|
|
1808
|
+
}
|
|
1809
|
+
}
|
|
1810
|
+
// Keep selection highlighted; do not wipe the panel to empty while a
|
|
1811
|
+
// field token is still selected (e.g. schema briefly unavailable).
|
|
1812
|
+
return;
|
|
1813
|
+
}
|
|
1814
|
+
if (selectedSectionBlockIndex >= 0) {
|
|
1815
|
+
clearStructureSelection();
|
|
1816
|
+
void loadSelectedSectionProperties();
|
|
1817
|
+
return;
|
|
1818
|
+
}
|
|
1819
|
+
if (selectedColumnsEl?.isConnected) {
|
|
1820
|
+
updateSectionSelectionHighlight();
|
|
1821
|
+
clearTableSelection();
|
|
1822
|
+
loadSelectedColumnsProperties();
|
|
1823
|
+
return;
|
|
1824
|
+
}
|
|
1825
|
+
if (selectedTableEl?.isConnected) {
|
|
1826
|
+
updateSectionSelectionHighlight();
|
|
1827
|
+
clearColumnsSelection();
|
|
1828
|
+
return;
|
|
1829
|
+
}
|
|
1830
|
+
updateSectionSelectionHighlight();
|
|
1831
|
+
clearStructureSelection();
|
|
1832
|
+
propertiesPanel.showEmpty();
|
|
1833
|
+
}
|
|
1834
|
+
async function insertPaletteFieldInline(fieldType) {
|
|
1835
|
+
await editor.isReady;
|
|
1836
|
+
let editable = resolveTargetEditable();
|
|
1837
|
+
// Capture before focus() collapses the selection in some browsers.
|
|
1838
|
+
const savedRange = editable ? saveSelection(editable) : null;
|
|
1839
|
+
const preferredLabel = editable
|
|
1840
|
+
? resolveSelectedTextForFieldConversion(editable, savedRange)
|
|
1841
|
+
: '';
|
|
1842
|
+
if (!editable) {
|
|
1843
|
+
editable = await ensureDocumentSectionAtEnd();
|
|
1844
|
+
}
|
|
1845
|
+
else {
|
|
1846
|
+
editable.focus();
|
|
1847
|
+
}
|
|
1848
|
+
if (!editable)
|
|
1849
|
+
return;
|
|
1850
|
+
const { fieldId, token } = await insertInlineField(editable, fieldType, {
|
|
1851
|
+
...getInlineFieldOptions(),
|
|
1852
|
+
...(preferredLabel ? { preferredLabel, savedRange } : {}),
|
|
1853
|
+
});
|
|
1854
|
+
if (useDesignPanels && designMode && fieldId) {
|
|
1855
|
+
await handleEditSchema(fieldId);
|
|
1856
|
+
}
|
|
1857
|
+
if (token.isConnected) {
|
|
1858
|
+
focusCaretAfter(token);
|
|
1859
|
+
}
|
|
1860
|
+
else {
|
|
1861
|
+
focusCaretAtEnd(editable);
|
|
1862
|
+
}
|
|
1863
|
+
lastFocusedEditable = editable;
|
|
1864
|
+
}
|
|
1865
|
+
async function insertPaletteTableInline(fieldType = 'table') {
|
|
1866
|
+
await editor.isReady;
|
|
1867
|
+
let editable = resolveTargetEditable();
|
|
1868
|
+
if (!editable) {
|
|
1869
|
+
editable = await ensureDocumentSectionAtEnd();
|
|
1870
|
+
}
|
|
1871
|
+
else {
|
|
1872
|
+
editable.focus();
|
|
1873
|
+
}
|
|
1874
|
+
if (!editable)
|
|
1875
|
+
return;
|
|
1876
|
+
const { fieldId } = insertTableAtCaret(editable, {
|
|
1877
|
+
...getInlineFieldOptions(),
|
|
1878
|
+
fieldType: fieldType === 'pivotTable' ? 'pivotTable' : 'table',
|
|
1879
|
+
});
|
|
1880
|
+
options.onSchemaChange?.(registry.getFieldSchemas());
|
|
1881
|
+
wireTableRegions(editable, {
|
|
1882
|
+
...getInlineFieldOptions(),
|
|
1883
|
+
onStructureChange: () => {
|
|
1884
|
+
editable.dispatchEvent(new InputEvent('input', { bubbles: true }));
|
|
1885
|
+
},
|
|
1886
|
+
});
|
|
1887
|
+
editable.dispatchEvent(new InputEvent('input', { bubbles: true }));
|
|
1888
|
+
await handleEditSchema(fieldId);
|
|
1889
|
+
lastFocusedEditable = editable;
|
|
1890
|
+
}
|
|
1891
|
+
async function insertPaletteRepeaterInline() {
|
|
1892
|
+
await insertPaletteFieldInline('child');
|
|
1893
|
+
}
|
|
1894
|
+
void insertPaletteRepeaterInline;
|
|
1895
|
+
function normalizeRepeaterFieldInBlocks(blocks, fieldId, repeaterSchema) {
|
|
1896
|
+
const updated = normalizeRepeaterSchema(repeaterSchema);
|
|
1897
|
+
return blocks.map((block) => {
|
|
1898
|
+
if (block.type === 'documentSection' && block.data?.fieldValues?.[fieldId] !== undefined) {
|
|
1899
|
+
return {
|
|
1900
|
+
...block,
|
|
1901
|
+
data: {
|
|
1902
|
+
...block.data,
|
|
1903
|
+
fieldValues: {
|
|
1904
|
+
...block.data.fieldValues,
|
|
1905
|
+
[fieldId]: normalizeRepeaterValue(block.data.fieldValues[fieldId], updated),
|
|
1906
|
+
},
|
|
1907
|
+
},
|
|
1908
|
+
};
|
|
1909
|
+
}
|
|
1910
|
+
if (block.type === 'templateBlock' &&
|
|
1911
|
+
block.data?.fieldId === fieldId &&
|
|
1912
|
+
block.data?.fieldType === 'child') {
|
|
1913
|
+
return {
|
|
1914
|
+
...block,
|
|
1915
|
+
data: {
|
|
1916
|
+
...block.data,
|
|
1917
|
+
value: normalizeRepeaterValue(block.data.value, updated),
|
|
1918
|
+
},
|
|
1919
|
+
};
|
|
1920
|
+
}
|
|
1921
|
+
return block;
|
|
1922
|
+
});
|
|
1923
|
+
}
|
|
1924
|
+
async function handleSectionNameChange() {
|
|
1925
|
+
if (!editor)
|
|
1926
|
+
return;
|
|
1927
|
+
const saved = await editor.save();
|
|
1928
|
+
let nextSchemas = registry.getFieldSchemas();
|
|
1929
|
+
let nextBlocks = saved.blocks;
|
|
1930
|
+
/** @type {Record<string, string>} */
|
|
1931
|
+
const idRenames = {};
|
|
1932
|
+
for (const block of nextBlocks) {
|
|
1933
|
+
if (block.type !== 'documentSection')
|
|
1934
|
+
continue;
|
|
1935
|
+
const result = rebuildFieldIdsForSection(block, nextSchemas, nextBlocks);
|
|
1936
|
+
nextSchemas = result.fieldSchemas;
|
|
1937
|
+
nextBlocks = result.blocks;
|
|
1938
|
+
Object.assign(idRenames, result.idRenames);
|
|
1939
|
+
}
|
|
1940
|
+
registry.setFieldSchemas(nextSchemas);
|
|
1941
|
+
options.onSchemaChange?.(registry.getFieldSchemas());
|
|
1942
|
+
syncDocumentFieldMappingNames(nextBlocks, nextSchemas, idRenames);
|
|
1943
|
+
initEditor({
|
|
1944
|
+
time: saved.time,
|
|
1945
|
+
fieldSchemas: nextSchemas,
|
|
1946
|
+
blocks: nextBlocks,
|
|
1947
|
+
});
|
|
1948
|
+
}
|
|
1949
|
+
async function applyRepeaterSchemaUpdate(fieldId, schema, { reinit = true } = {}) {
|
|
1950
|
+
let blocks = registry.getBlocks() ?? [];
|
|
1951
|
+
let savedTime = Date.now();
|
|
1952
|
+
if (editor && reinit) {
|
|
1953
|
+
const saved = await editor.save();
|
|
1954
|
+
blocks = saved.blocks ?? blocks;
|
|
1955
|
+
savedTime = saved.time;
|
|
1956
|
+
}
|
|
1957
|
+
const sanitized = sanitizeRepeaterChildSchemas(normalizeRepeaterSchema(schema), registry.getFieldSchemas(), blocks);
|
|
1958
|
+
registry.updateFieldSchema(fieldId, sanitized);
|
|
1959
|
+
options.onSchemaChange?.(registry.getFieldSchemas());
|
|
1960
|
+
if (editor && reinit) {
|
|
1961
|
+
const nextBlocks = normalizeRepeaterFieldInBlocks(blocks, fieldId, sanitized);
|
|
1962
|
+
syncDocumentFieldMappingNames(nextBlocks, registry.getFieldSchemas());
|
|
1963
|
+
initEditor({
|
|
1964
|
+
time: savedTime,
|
|
1965
|
+
fieldSchemas: registry.getFieldSchemas(),
|
|
1966
|
+
blocks: nextBlocks,
|
|
1967
|
+
});
|
|
1968
|
+
}
|
|
1969
|
+
else {
|
|
1970
|
+
syncDocumentFieldMappingNames(blocks, registry.getFieldSchemas());
|
|
1971
|
+
}
|
|
1972
|
+
return sanitized;
|
|
1973
|
+
}
|
|
1974
|
+
/**
|
|
1975
|
+
* Persist repeater schema without destroying the live editor DOM.
|
|
1976
|
+
* Used while a fill-mode Child modal is open so the click handler's token
|
|
1977
|
+
* (and section callbacks) stay connected.
|
|
1978
|
+
*/
|
|
1979
|
+
async function applyRepeaterSchemaUpdateSoft(fieldId, schema) {
|
|
1980
|
+
return applyRepeaterSchemaUpdate(fieldId, schema, { reinit: false });
|
|
1981
|
+
}
|
|
1982
|
+
/**
|
|
1983
|
+
* Prefer the repeater value that carries more child keys (token vs last save).
|
|
1984
|
+
* An empty `{}` stored value must not eclipse a populated token value.
|
|
1985
|
+
*/
|
|
1986
|
+
function pickRicherRepeaterValue(storedValue, tokenValue) {
|
|
1987
|
+
const storedObj = storedValue && typeof storedValue === 'object' && !Array.isArray(storedValue)
|
|
1988
|
+
? storedValue
|
|
1989
|
+
: null;
|
|
1990
|
+
const tokenObj = tokenValue && typeof tokenValue === 'object' && !Array.isArray(tokenValue)
|
|
1991
|
+
? tokenValue
|
|
1992
|
+
: null;
|
|
1993
|
+
if (!storedObj && tokenObj)
|
|
1994
|
+
return tokenValue;
|
|
1995
|
+
if (storedObj && !tokenObj)
|
|
1996
|
+
return storedValue;
|
|
1997
|
+
if (!storedObj && !tokenObj) {
|
|
1998
|
+
return storedValue !== undefined ? storedValue : tokenValue;
|
|
1999
|
+
}
|
|
2000
|
+
const storedKeys = Object.keys(storedObj).filter((key) => key !== 'instances').length;
|
|
2001
|
+
const tokenKeys = Object.keys(tokenObj).filter((key) => key !== 'instances').length;
|
|
2002
|
+
if (tokenKeys > storedKeys)
|
|
2003
|
+
return tokenValue;
|
|
2004
|
+
if (storedKeys > 0)
|
|
2005
|
+
return storedValue;
|
|
2006
|
+
return tokenValue !== undefined ? tokenValue : storedValue;
|
|
2007
|
+
}
|
|
2008
|
+
function promptRepeaterTemplateUpload(fieldId) {
|
|
2009
|
+
return new Promise((resolve) => {
|
|
2010
|
+
const input = document.createElement('input');
|
|
2011
|
+
input.type = 'file';
|
|
2012
|
+
input.accept = '.json,application/json';
|
|
2013
|
+
input.hidden = true;
|
|
2014
|
+
document.body.appendChild(input);
|
|
2015
|
+
const finish = (result) => {
|
|
2016
|
+
input.remove();
|
|
2017
|
+
resolve(result);
|
|
2018
|
+
};
|
|
2019
|
+
input.addEventListener('change', async () => {
|
|
2020
|
+
const file = input.files?.[0];
|
|
2021
|
+
if (!file) {
|
|
2022
|
+
finish(null);
|
|
2023
|
+
return;
|
|
2024
|
+
}
|
|
2025
|
+
try {
|
|
2026
|
+
const text = await file.text();
|
|
2027
|
+
finish(parseRepeaterTemplateImport(JSON.parse(text), fieldId));
|
|
2028
|
+
}
|
|
2029
|
+
catch (err) {
|
|
2030
|
+
showNotification(err?.message ?? 'Could not read repeater template file.', { type: 'error' });
|
|
2031
|
+
finish(null);
|
|
2032
|
+
}
|
|
2033
|
+
});
|
|
2034
|
+
input.addEventListener('cancel', () => finish(null));
|
|
2035
|
+
input.click();
|
|
2036
|
+
});
|
|
2037
|
+
}
|
|
2038
|
+
async function handleOpenRepeaterEditor({ fieldId, value }) {
|
|
2039
|
+
const parentSchemas = registry.getFieldSchemas();
|
|
2040
|
+
let blocks = [];
|
|
2041
|
+
if (editor) {
|
|
2042
|
+
const saved = await editor.save();
|
|
2043
|
+
blocks = saved.blocks ?? [];
|
|
2044
|
+
}
|
|
2045
|
+
let schema = parentSchemas[fieldId];
|
|
2046
|
+
if (!schema || schema.type !== 'child') {
|
|
2047
|
+
return extractRepeaterFieldValueFromBlocks(fieldId, blocks) ?? value;
|
|
2048
|
+
}
|
|
2049
|
+
const storedValue = extractRepeaterFieldValueFromBlocks(fieldId, blocks);
|
|
2050
|
+
// Prefer the richer of DOM token value vs last saved section value.
|
|
2051
|
+
const resolvedValue = stripForeignKeysFromRepeaterValue(pickRicherRepeaterValue(storedValue, value), parentSchemas, schema);
|
|
2052
|
+
// Soft schema updates only — never reinitEditor here. A full reinit would
|
|
2053
|
+
// detach the token/callback that opened this modal, so Save couldn't update
|
|
2054
|
+
// the live Child cell in the main form.
|
|
2055
|
+
const persistSchema = (next) => applyRepeaterSchemaUpdateSoft(fieldId, next);
|
|
2056
|
+
if (!schema.template?.blocks?.length) {
|
|
2057
|
+
const previousChildKeys = Object.keys(getRepeaterFieldSchemas(schema)).sort();
|
|
2058
|
+
schema = sanitizeRepeaterChildSchemas(schema, parentSchemas, blocks);
|
|
2059
|
+
const cleanedChildKeys = Object.keys(getRepeaterFieldSchemas(schema)).sort();
|
|
2060
|
+
if (cleanedChildKeys.join(',') !== previousChildKeys.join(',')) {
|
|
2061
|
+
schema = (await persistSchema(schema)) ?? schema;
|
|
2062
|
+
}
|
|
2063
|
+
}
|
|
2064
|
+
schema = ensureRepeaterChildSchemas(schema, resolvedValue, parentSchemas, blocks);
|
|
2065
|
+
const currentChildKeys = Object.keys(getRepeaterFieldSchemas(registry.getFieldSchemas()[fieldId] ?? {})).sort();
|
|
2066
|
+
const ensuredChildKeys = Object.keys(getRepeaterFieldSchemas(schema)).sort();
|
|
2067
|
+
if (ensuredChildKeys.join(',') !== currentChildKeys.join(',')) {
|
|
2068
|
+
schema = (await persistSchema(schema)) ?? schema;
|
|
2069
|
+
}
|
|
2070
|
+
if (!repeaterHasTemplate(schema)) {
|
|
2071
|
+
const imported = await promptRepeaterTemplateUpload(fieldId);
|
|
2072
|
+
if (imported) {
|
|
2073
|
+
schema = applyRepeaterTemplateImport(schema, imported);
|
|
2074
|
+
schema = (await persistSchema(schema)) ?? schema;
|
|
2075
|
+
}
|
|
2076
|
+
}
|
|
2077
|
+
if (!repeaterHasTemplate(schema)) {
|
|
2078
|
+
showNotification('Repeater has no template. Upload a template JSON (kind: "template") when prompted, or upload one in design mode field properties.', { type: 'warning', key: `repeater-no-template:${fieldId}` });
|
|
2079
|
+
return resolvedValue;
|
|
2080
|
+
}
|
|
2081
|
+
// Migrate legacy short storage keys (e.g. colliding "name"/"id") from the template.
|
|
2082
|
+
const migrated = normalizeRepeaterSchema(schema);
|
|
2083
|
+
if (migrated &&
|
|
2084
|
+
Object.keys(getRepeaterFieldSchemas(migrated)).join(',') !==
|
|
2085
|
+
Object.keys(getRepeaterFieldSchemas(schema)).join(',')) {
|
|
2086
|
+
schema = (await persistSchema(migrated)) ?? migrated;
|
|
2087
|
+
}
|
|
2088
|
+
const normalized = normalizeRepeaterValue(resolvedValue, schema);
|
|
2089
|
+
const doc = buildRepeaterFillDocument(schema, normalized);
|
|
2090
|
+
const result = await repeaterEditorModal.open({
|
|
2091
|
+
title: schema.label ?? fieldId,
|
|
2092
|
+
data: doc,
|
|
2093
|
+
designMode: false,
|
|
2094
|
+
});
|
|
2095
|
+
// Use modal live fieldSchemas so newly added nested table rows are mapped.
|
|
2096
|
+
const extractSchema = {
|
|
2097
|
+
...schema,
|
|
2098
|
+
template: {
|
|
2099
|
+
...(schema.template ?? {}),
|
|
2100
|
+
fieldSchemas: {
|
|
2101
|
+
...(schema.template?.fieldSchemas ?? {}),
|
|
2102
|
+
...(result?.fieldSchemas ?? {}),
|
|
2103
|
+
},
|
|
2104
|
+
},
|
|
2105
|
+
};
|
|
2106
|
+
const extracted = extractRepeaterValueFromDocument(result, extractSchema);
|
|
2107
|
+
const synced = syncRepeaterTemplateFromFillDocument(schema, result);
|
|
2108
|
+
if (synced) {
|
|
2109
|
+
await persistSchema(synced);
|
|
2110
|
+
}
|
|
2111
|
+
// Update the live main-form token immediately so Save is visible even if
|
|
2112
|
+
// the click-handler token reference is stale or structure-change races.
|
|
2113
|
+
const liveToken = findLiveFieldToken(fieldId, holder);
|
|
2114
|
+
if (liveToken) {
|
|
2115
|
+
updateFieldToken(liveToken, extracted, liveToken.dataset.placeholder, {
|
|
2116
|
+
getRegistry: () => registry,
|
|
2117
|
+
isTableCell: liveToken.classList.contains('field-token--cell'),
|
|
2118
|
+
});
|
|
2119
|
+
}
|
|
2120
|
+
return extracted;
|
|
2121
|
+
}
|
|
2122
|
+
function buildToolConfig() {
|
|
2123
|
+
return {
|
|
2124
|
+
...pickerCallbacks,
|
|
2125
|
+
openRepeaterEditor: (opts) => handleOpenRepeaterEditor(opts),
|
|
2126
|
+
editorHolder: holder,
|
|
2127
|
+
getRegistry: () => registry,
|
|
2128
|
+
resolveListItems: options.resolveListItems,
|
|
2129
|
+
fieldValueStyle,
|
|
2130
|
+
getDocumentTextStyle: () => resolvePageSetupTextStyle(documentPageSetup),
|
|
2131
|
+
getProtectFieldsInFillMode: () => documentPageSetup.protectFieldsInFillMode !== false,
|
|
2132
|
+
getAutoAdvanceFillFields: () => documentPageSetup.autoAdvanceFillFields !== false,
|
|
2133
|
+
designMode,
|
|
2134
|
+
fillModeFieldHighlight: !designMode && showFieldsInFillMode && !options.mappingMode,
|
|
2135
|
+
mappingMode: !!options.mappingMode,
|
|
2136
|
+
onMappingRuleChange: options.onMappingRuleChange,
|
|
2137
|
+
getMappingRules: options.getMappingRules,
|
|
2138
|
+
designPropertiesPanel: useDesignPanels && designMode,
|
|
2139
|
+
openEditor: !(useDesignPanels && designMode),
|
|
2140
|
+
onEditSchema: handleEditSchema,
|
|
2141
|
+
onDeleteSchema: handleDeleteSchema,
|
|
2142
|
+
onSectionNameChange: handleSectionNameChange,
|
|
2143
|
+
onPaletteDrop: handlePaletteDrop,
|
|
2144
|
+
onSourcePathCanvasDrop: handleSourcePathCanvasDrop,
|
|
2145
|
+
allocateSectionName,
|
|
2146
|
+
onSectionDataChange: syncSectionDataToRegistry,
|
|
2147
|
+
onFieldValueChange: refreshSectionVisibility,
|
|
2148
|
+
onSchemaChange: (schemas) => options.onSchemaChange?.(schemas),
|
|
2149
|
+
onTableColumnWidthsChange: handleTableColumnWidthsChange,
|
|
2150
|
+
onTableColumnWidthsPreview: handleTableColumnWidthsPreview,
|
|
2151
|
+
onTableColumnResizeStart: handleTableColumnResizeStart,
|
|
2152
|
+
onTableColumnsChange: (tableId, columns) => {
|
|
2153
|
+
propertiesPanel?.cancelPersist?.();
|
|
2154
|
+
propertiesPanel?.syncTableColumns?.(tableId, columns);
|
|
2155
|
+
options.onSchemaChange?.(registry.getFieldSchemas());
|
|
2156
|
+
scheduleHistoryRecord();
|
|
2157
|
+
},
|
|
2158
|
+
onColumnsWidthsChange: (columnsEl) => {
|
|
2159
|
+
if (columnsEl?.isConnected) {
|
|
2160
|
+
selectColumnsEl(columnsEl);
|
|
2161
|
+
}
|
|
2162
|
+
},
|
|
2163
|
+
};
|
|
2164
|
+
}
|
|
2165
|
+
async function handleEditSchema(fieldId) {
|
|
2166
|
+
const token = findLiveFieldToken(fieldId, holder);
|
|
2167
|
+
const schema = registry.getFieldSchemas()[fieldId] ??
|
|
2168
|
+
ensureFieldSchemaForProperties(fieldId, token);
|
|
2169
|
+
if (!schema)
|
|
2170
|
+
return;
|
|
2171
|
+
if (useDesignPanels && designMode && propertiesPanel) {
|
|
2172
|
+
await loadFieldProperties(fieldId, token);
|
|
2173
|
+
return;
|
|
2174
|
+
}
|
|
2175
|
+
const schemas = registry.getFieldSchemas();
|
|
2176
|
+
const previousType = schema.type;
|
|
2177
|
+
try {
|
|
2178
|
+
const saved = await editor.save();
|
|
2179
|
+
const placement = findFieldPlacement(fieldId, saved.blocks);
|
|
2180
|
+
const result = await schemaEditor.open(fieldId, schema, {
|
|
2181
|
+
sectionName: placement.sectionName,
|
|
2182
|
+
sectionLabel: placement.sectionName,
|
|
2183
|
+
blocks: saved.blocks,
|
|
2184
|
+
fieldSchemas: schemas,
|
|
2185
|
+
});
|
|
2186
|
+
await applySchemaSaveResult(result, previousType, schema);
|
|
2187
|
+
}
|
|
2188
|
+
catch {
|
|
2189
|
+
// cancelled
|
|
2190
|
+
}
|
|
2191
|
+
}
|
|
2192
|
+
function handleDeleteSchema(fieldId) {
|
|
2193
|
+
registry.removeFieldSchema(fieldId);
|
|
2194
|
+
options.onSchemaChange?.(registry.getFieldSchemas());
|
|
2195
|
+
}
|
|
2196
|
+
function buildToolsMap(config) {
|
|
2197
|
+
const enabled = options.tools ?? ['documentSection', 'templateBlock'];
|
|
2198
|
+
const tools = {};
|
|
2199
|
+
if (enabled.includes('documentSection')) {
|
|
2200
|
+
tools.documentSection = { class: DocumentSection, config };
|
|
2201
|
+
}
|
|
2202
|
+
if (enabled.includes('templateBlock')) {
|
|
2203
|
+
tools.templateBlock = { class: TemplateBlock, config };
|
|
2204
|
+
}
|
|
2205
|
+
if (enabled.includes('visionTable') && options.visionTableTool) {
|
|
2206
|
+
tools.visionTable = { class: options.visionTableTool, config };
|
|
2207
|
+
}
|
|
2208
|
+
return tools;
|
|
2209
|
+
}
|
|
2210
|
+
function countLiveDocumentSections() {
|
|
2211
|
+
if (!editor)
|
|
2212
|
+
return 0;
|
|
2213
|
+
const count = editor.blocks.getBlocksCount();
|
|
2214
|
+
let sections = 0;
|
|
2215
|
+
for (let i = 0; i < count; i += 1) {
|
|
2216
|
+
if (editor.blocks.getBlockByIndex(i)?.name === 'documentSection') {
|
|
2217
|
+
sections += 1;
|
|
2218
|
+
}
|
|
2219
|
+
}
|
|
2220
|
+
return sections;
|
|
2221
|
+
}
|
|
2222
|
+
let restoringRequiredSection = false;
|
|
2223
|
+
async function ensureLiveDocumentSection() {
|
|
2224
|
+
if (!editor || destroyed || restoringRequiredSection)
|
|
2225
|
+
return;
|
|
2226
|
+
if (countLiveDocumentSections() > 0)
|
|
2227
|
+
return;
|
|
2228
|
+
restoringRequiredSection = true;
|
|
2229
|
+
try {
|
|
2230
|
+
await editor.isReady;
|
|
2231
|
+
if (destroyed || !editor || countLiveDocumentSections() > 0)
|
|
2232
|
+
return;
|
|
2233
|
+
await editor.blocks.insert('documentSection', createUniqueSectionData(), {}, 0, true);
|
|
2234
|
+
showNotification('At least one section is required.', { type: 'status' });
|
|
2235
|
+
}
|
|
2236
|
+
finally {
|
|
2237
|
+
restoringRequiredSection = false;
|
|
2238
|
+
}
|
|
2239
|
+
}
|
|
2240
|
+
function guardDocumentSectionDeletion() {
|
|
2241
|
+
if (!editor)
|
|
2242
|
+
return;
|
|
2243
|
+
const blocksApi = editor.blocks;
|
|
2244
|
+
const originalDelete = blocksApi.delete.bind(blocksApi);
|
|
2245
|
+
const originalClear = blocksApi.clear.bind(blocksApi);
|
|
2246
|
+
blocksApi.delete = (index) => {
|
|
2247
|
+
const blockIndex = index ?? blocksApi.getCurrentBlockIndex();
|
|
2248
|
+
const block = blocksApi.getBlockByIndex(blockIndex);
|
|
2249
|
+
if (block?.name === 'documentSection' && countLiveDocumentSections() <= 1) {
|
|
2250
|
+
showNotification('At least one section is required.', { type: 'status' });
|
|
2251
|
+
return;
|
|
2252
|
+
}
|
|
2253
|
+
return originalDelete(index);
|
|
2254
|
+
};
|
|
2255
|
+
blocksApi.clear = async () => {
|
|
2256
|
+
await originalClear();
|
|
2257
|
+
await ensureLiveDocumentSection();
|
|
2258
|
+
};
|
|
2259
|
+
}
|
|
2260
|
+
function initEditor(docData) {
|
|
2261
|
+
const normalized = normalizeDocument(docData, {
|
|
2262
|
+
defaultDocument: options.defaultDocument,
|
|
2263
|
+
visionTableFieldId: options.visionTableFieldId,
|
|
2264
|
+
});
|
|
2265
|
+
registry.setFieldSchemas({ ...normalized.fieldSchemas });
|
|
2266
|
+
registry.setBlocks(normalized.blocks ?? []);
|
|
2267
|
+
options.onSchemaChange?.(registry.getFieldSchemas());
|
|
2268
|
+
if (docData && Object.prototype.hasOwnProperty.call(docData, 'pageSetup')) {
|
|
2269
|
+
documentPageSetup = docData.pageSetup
|
|
2270
|
+
? migratePageSetup(JSON.parse(JSON.stringify(docData.pageSetup)))
|
|
2271
|
+
: {};
|
|
2272
|
+
}
|
|
2273
|
+
else if (normalized.pageSetup) {
|
|
2274
|
+
documentPageSetup = migratePageSetup(JSON.parse(JSON.stringify(normalized.pageSetup)));
|
|
2275
|
+
}
|
|
2276
|
+
if (docData && Object.prototype.hasOwnProperty.call(docData, 'fieldMapping')) {
|
|
2277
|
+
documentFieldMapping = docData.fieldMapping
|
|
2278
|
+
? normalizeFieldMappingSpec(docData.fieldMapping)
|
|
2279
|
+
: null;
|
|
2280
|
+
}
|
|
2281
|
+
else if (normalized.fieldMapping) {
|
|
2282
|
+
documentFieldMapping = normalizeFieldMappingSpec(normalized.fieldMapping);
|
|
2283
|
+
}
|
|
2284
|
+
// Heal stale section/field names left over from renames before re-init.
|
|
2285
|
+
if (documentFieldMapping?.rules?.length) {
|
|
2286
|
+
documentFieldMapping = syncFieldMappingSpecToSchema(documentFieldMapping, registry.getBlocks() ?? [], registry.getFieldSchemas());
|
|
2287
|
+
}
|
|
2288
|
+
// Palette may already exist on re-init; keep Database tab + badges in sync.
|
|
2289
|
+
refreshDatabaseSourceTree?.();
|
|
2290
|
+
refreshDesignMappingBadges();
|
|
2291
|
+
syncStylesFromPageSetup();
|
|
2292
|
+
// EditorJS.destroy() deletes its own methods; never call destroy twice on the same instance.
|
|
2293
|
+
if (editor) {
|
|
2294
|
+
const prev = editor;
|
|
2295
|
+
editor = null;
|
|
2296
|
+
if (typeof prev.destroy === 'function') {
|
|
2297
|
+
try {
|
|
2298
|
+
prev.destroy();
|
|
2299
|
+
}
|
|
2300
|
+
catch {
|
|
2301
|
+
// already torn down or mid-destroy from a concurrent reinit
|
|
2302
|
+
}
|
|
2303
|
+
}
|
|
2304
|
+
}
|
|
2305
|
+
const config = buildToolConfig();
|
|
2306
|
+
// Must run before EditorJS so our capture listener beats DragNDrop.processDrop
|
|
2307
|
+
// (which deletes the selection then crashes in processHTML on text DnD).
|
|
2308
|
+
wireEditorJsNativeDropGuard(holder);
|
|
2309
|
+
editor = new EditorJSCtor({
|
|
2310
|
+
// Pass the element — string IDs fail under LWC shadow DOM (getElementById).
|
|
2311
|
+
holder,
|
|
2312
|
+
autofocus: false,
|
|
2313
|
+
minHeight: 0,
|
|
2314
|
+
defaultBlock: 'documentSection',
|
|
2315
|
+
data: { blocks: normalized.blocks },
|
|
2316
|
+
tools: buildToolsMap(config),
|
|
2317
|
+
onChange: async () => {
|
|
2318
|
+
if (destroyed)
|
|
2319
|
+
return;
|
|
2320
|
+
try {
|
|
2321
|
+
await ensureLiveDocumentSection();
|
|
2322
|
+
scheduleHistoryRecord();
|
|
2323
|
+
options.onChange?.(await getDocument());
|
|
2324
|
+
}
|
|
2325
|
+
catch {
|
|
2326
|
+
// editor not ready
|
|
2327
|
+
}
|
|
2328
|
+
},
|
|
2329
|
+
onReady: () => {
|
|
2330
|
+
if (destroyed || !editor)
|
|
2331
|
+
return;
|
|
2332
|
+
guardDocumentSectionDeletion();
|
|
2333
|
+
refreshSectionVisibility();
|
|
2334
|
+
if (!documentHistory.hasPresent()) {
|
|
2335
|
+
documentHistory.reset(getHistorySnapshot());
|
|
2336
|
+
}
|
|
2337
|
+
else if (!historyBusy && !documentHistory.isSuspended()) {
|
|
2338
|
+
scheduleHistoryRecord(true);
|
|
2339
|
+
}
|
|
2340
|
+
},
|
|
2341
|
+
});
|
|
2342
|
+
applyDesignMode(designMode);
|
|
2343
|
+
syncFieldStyleToolbar();
|
|
2344
|
+
syncStylesFromPageSetup();
|
|
2345
|
+
scheduleEditorStylesSync();
|
|
2346
|
+
return editor;
|
|
2347
|
+
}
|
|
2348
|
+
async function getDocument() {
|
|
2349
|
+
if (!editor) {
|
|
2350
|
+
const doc = normalizeDocument(options.data ?? options.defaultDocument, {
|
|
2351
|
+
defaultDocument: options.defaultDocument,
|
|
2352
|
+
visionTableFieldId: options.visionTableFieldId,
|
|
2353
|
+
});
|
|
2354
|
+
if (Object.keys(documentPageSetup).length > 0) {
|
|
2355
|
+
doc.pageSetup = JSON.parse(JSON.stringify(documentPageSetup));
|
|
2356
|
+
}
|
|
2357
|
+
if (documentFieldMapping) {
|
|
2358
|
+
doc.fieldMapping = JSON.parse(JSON.stringify(documentFieldMapping));
|
|
2359
|
+
}
|
|
2360
|
+
attachRepeatableInstances(doc);
|
|
2361
|
+
return doc;
|
|
2362
|
+
}
|
|
2363
|
+
// Ensure preview/export always sees the latest live token state (including
|
|
2364
|
+
// table-cell values) even before EditorJS serialization runs.
|
|
2365
|
+
refreshTableCellTokens(holder, {
|
|
2366
|
+
getRegistry: () => registry,
|
|
2367
|
+
fieldValueStyle,
|
|
2368
|
+
fillModeFieldHighlight: !designMode && showFieldsInFillMode && !options.mappingMode,
|
|
2369
|
+
});
|
|
2370
|
+
syncFillComputedFields(holder, {}, {
|
|
2371
|
+
getRegistry: () => registry,
|
|
2372
|
+
editorHolder: holder,
|
|
2373
|
+
fieldValueStyle,
|
|
2374
|
+
fillModeFieldHighlight: !designMode && showFieldsInFillMode && !options.mappingMode,
|
|
2375
|
+
});
|
|
2376
|
+
const saved = await editor.save();
|
|
2377
|
+
registry.setBlocks(saved.blocks ?? []);
|
|
2378
|
+
// Re-attach image data URLs from live thumbs (dataset only keeps a compact stub under LWS).
|
|
2379
|
+
for (const block of saved.blocks ?? []) {
|
|
2380
|
+
if (block?.type !== 'documentSection' || !block.data)
|
|
2381
|
+
continue;
|
|
2382
|
+
block.data.fieldValues = recoverImageValuesFromDom(holder, block.data.fieldValues ?? {});
|
|
2383
|
+
}
|
|
2384
|
+
const doc = {
|
|
2385
|
+
time: saved.time,
|
|
2386
|
+
fieldSchemas: registry.getFieldSchemas(),
|
|
2387
|
+
blocks: saved.blocks,
|
|
2388
|
+
};
|
|
2389
|
+
if (Object.keys(documentPageSetup).length > 0) {
|
|
2390
|
+
doc.pageSetup = JSON.parse(JSON.stringify(documentPageSetup));
|
|
2391
|
+
}
|
|
2392
|
+
if (documentFieldMapping) {
|
|
2393
|
+
doc.fieldMapping = JSON.parse(JSON.stringify(documentFieldMapping));
|
|
2394
|
+
}
|
|
2395
|
+
attachRepeatableInstances(doc);
|
|
2396
|
+
return doc;
|
|
2397
|
+
}
|
|
2398
|
+
function attachRepeatableInstances(doc) {
|
|
2399
|
+
// Clone from loaded instance arrays and/or explicit `repeatable` — never from `_source` alone.
|
|
2400
|
+
const plan = resolveRepeatablePagePlan(doc.blocks ?? [], doc.fieldSchemas ?? {}, collectAllValues(doc.blocks ?? []), loadedDocumentSections);
|
|
2401
|
+
if (plan && plan.instances.length > 1) {
|
|
2402
|
+
doc.repeatablePagePlan = plan;
|
|
2403
|
+
doc.repeatableSectionInstances = { [plan.sectionName]: plan.instances };
|
|
2404
|
+
return;
|
|
2405
|
+
}
|
|
2406
|
+
delete doc.repeatablePagePlan;
|
|
2407
|
+
delete doc.repeatableSectionInstances;
|
|
2408
|
+
}
|
|
2409
|
+
async function addBlock(fieldType) {
|
|
2410
|
+
if (!editor)
|
|
2411
|
+
return;
|
|
2412
|
+
if (isInlineFieldType(fieldType)) {
|
|
2413
|
+
await insertPaletteFieldInline(fieldType);
|
|
2414
|
+
return;
|
|
2415
|
+
}
|
|
2416
|
+
const handler = getFieldHandler(fieldType);
|
|
2417
|
+
if (handler?.insertion === 'table' || fieldType === 'table') {
|
|
2418
|
+
await insertPaletteTableInline(fieldType === 'pivotTable' ? 'pivotTable' : 'table');
|
|
2419
|
+
return;
|
|
2420
|
+
}
|
|
2421
|
+
const blockData = createDefaultBlockData(fieldType);
|
|
2422
|
+
const schema = createDefaultSchema(fieldType, blockData.label);
|
|
2423
|
+
registry.updateFieldSchema(blockData.fieldId, schema);
|
|
2424
|
+
if (fieldType === 'table') {
|
|
2425
|
+
const merged = ensureCellSchemas(schema, blockData.fieldId, registry.getFieldSchemas(), undefined);
|
|
2426
|
+
registry.setFieldSchemas(merged);
|
|
2427
|
+
}
|
|
2428
|
+
options.onSchemaChange?.(registry.getFieldSchemas());
|
|
2429
|
+
await editor.isReady;
|
|
2430
|
+
const count = editor.blocks.getBlocksCount();
|
|
2431
|
+
await editor.blocks.insert('templateBlock', blockData, {}, count);
|
|
2432
|
+
}
|
|
2433
|
+
async function addPaletteItem(item) {
|
|
2434
|
+
if (!editor)
|
|
2435
|
+
return;
|
|
2436
|
+
if (item.kind === 'block' && item.type === 'documentSection') {
|
|
2437
|
+
await insertDocumentSection(undefined);
|
|
2438
|
+
return;
|
|
2439
|
+
}
|
|
2440
|
+
if (item.kind === 'layout' && item.type === 'columns') {
|
|
2441
|
+
await insertColumnsIntoTargetSection();
|
|
2442
|
+
return;
|
|
2443
|
+
}
|
|
2444
|
+
if (item.kind === 'field') {
|
|
2445
|
+
await addBlock(item.type);
|
|
2446
|
+
}
|
|
2447
|
+
}
|
|
2448
|
+
const palette = createFieldPalette((item) => addPaletteItem(item), {
|
|
2449
|
+
layout: useDesignPanels ? 'vertical' : 'horizontal',
|
|
2450
|
+
excludeTypes: ui.embedded ? ['child'] : [],
|
|
2451
|
+
getSourceSample: () => documentFieldMapping?.sourceSample ?? null,
|
|
2452
|
+
onSourceSampleChange: (sample) => {
|
|
2453
|
+
documentFieldMapping = normalizeFieldMappingSpec({
|
|
2454
|
+
...(documentFieldMapping ?? {}),
|
|
2455
|
+
sourceSample: sample,
|
|
2456
|
+
rules: documentFieldMapping?.rules ?? [],
|
|
2457
|
+
});
|
|
2458
|
+
scheduleHistoryRecord();
|
|
2459
|
+
},
|
|
2460
|
+
});
|
|
2461
|
+
refreshDatabaseSourceTree = () => palette.refreshDatabase();
|
|
2462
|
+
// Declared later on the public instance; Preview chrome must use the same
|
|
2463
|
+
// mapping-aware path (nested $values rows), not a bare getDocument() open.
|
|
2464
|
+
let runPreview = async () => { };
|
|
2465
|
+
const documentActions = createDocumentActions({
|
|
2466
|
+
onPreview: ui.showPreview === false ? null : () => {
|
|
2467
|
+
void runPreview().catch((err) => {
|
|
2468
|
+
showNotification(err?.message ?? 'Preview failed.', { type: 'error' });
|
|
2469
|
+
});
|
|
2470
|
+
},
|
|
2471
|
+
});
|
|
2472
|
+
let topChrome = null;
|
|
2473
|
+
const showPalette = ui.palette !== false && !useDesignPanels;
|
|
2474
|
+
const showToolbar = ui.richTextToolbar !== false;
|
|
2475
|
+
if (useDesignPanels && designShell) {
|
|
2476
|
+
designShell.leftPanel.appendChild(palette.element);
|
|
2477
|
+
propertiesPanel = createPropertiesPanel({
|
|
2478
|
+
getRegistry: () => registry,
|
|
2479
|
+
onRepeaterTemplateChange: (fieldId, schema) => applyRepeaterSchemaUpdate(fieldId, schema),
|
|
2480
|
+
getRemoteListCollections: options.remoteListCollections ?? null,
|
|
2481
|
+
getRemoteListLabelFields: options.remoteListLabelFields ?? null,
|
|
2482
|
+
onSaveField: async (result) => {
|
|
2483
|
+
const previousSchema = registry.getFieldSchemas()[result.previousFieldId];
|
|
2484
|
+
const previousType = previousSchema?.type;
|
|
2485
|
+
if (!previousSchema || !previousType)
|
|
2486
|
+
return;
|
|
2487
|
+
const widthOnly = isTableWidthOnlyChange(previousSchema, result.schema);
|
|
2488
|
+
const ok = await applySchemaSaveResult(result, previousType, previousSchema);
|
|
2489
|
+
if (ok && !widthOnly)
|
|
2490
|
+
await loadFieldProperties(result.fieldId);
|
|
2491
|
+
},
|
|
2492
|
+
onLiveTableColumnWidths: applyLiveTableColumnWidths,
|
|
2493
|
+
onSaveSection: handleSaveSection,
|
|
2494
|
+
onSaveColumns: handleSaveColumns,
|
|
2495
|
+
onSaveDocument: handleSaveDocument,
|
|
2496
|
+
onOpenPageSetup: openPageSetupPanel,
|
|
2497
|
+
});
|
|
2498
|
+
designShell.rightPanel.appendChild(propertiesPanel.element);
|
|
2499
|
+
if (showToolbar) {
|
|
2500
|
+
designToolbarWrap = document.createElement('div');
|
|
2501
|
+
designToolbarWrap.className = 'design-panel__toolbar';
|
|
2502
|
+
designToolbarWrap.appendChild(richTextToolbar.element);
|
|
2503
|
+
designShell.centerPanel.insertBefore(designToolbarWrap, holder);
|
|
2504
|
+
}
|
|
2505
|
+
designEditorScroll = document.createElement('div');
|
|
2506
|
+
designEditorScroll.className = 'design-panel__editor-scroll';
|
|
2507
|
+
designShell.centerPanel.insertBefore(designEditorScroll, holder);
|
|
2508
|
+
designEditorScroll.appendChild(holder);
|
|
2509
|
+
wirePaletteBlockDrop(holder, {
|
|
2510
|
+
onInsertSection: (index) => insertDocumentSection(index),
|
|
2511
|
+
});
|
|
2512
|
+
palette.refreshDatabase();
|
|
2513
|
+
refreshDesignMappingBadges();
|
|
2514
|
+
}
|
|
2515
|
+
if (showPalette || (showToolbar && !useDesignPanels)) {
|
|
2516
|
+
topChrome = document.createElement('div');
|
|
2517
|
+
topChrome.className = 'editor-top-chrome';
|
|
2518
|
+
if (showPalette)
|
|
2519
|
+
topChrome.appendChild(palette.element);
|
|
2520
|
+
if (showToolbar)
|
|
2521
|
+
topChrome.appendChild(richTextToolbar.element);
|
|
2522
|
+
if (ui.stickyChrome !== false && !ui.chromeParent) {
|
|
2523
|
+
topChrome.classList.add('editor-top-chrome--sticky');
|
|
2524
|
+
}
|
|
2525
|
+
mountTopChrome(topChrome, holder, ui);
|
|
2526
|
+
}
|
|
2527
|
+
// Always sync after mount — chrome fill mode (SF modal / no design panels) also
|
|
2528
|
+
// mounts the toolbar, and must hide it when designMode is false.
|
|
2529
|
+
syncDesignChromeVisibility();
|
|
2530
|
+
if (ui.documentActions !== false) {
|
|
2531
|
+
if (!mountInContainer(documentActions.element, ui.documentActionsContainer)) {
|
|
2532
|
+
mountAdjacentUi(documentActions.element, holder, ui.documentActionsParent, ui.documentActionsAfter, 'before-holder');
|
|
2533
|
+
}
|
|
2534
|
+
}
|
|
2535
|
+
function getSelectedDesignFieldTokens() {
|
|
2536
|
+
return [...holder.querySelectorAll('.field-token--selected.field-token--design')];
|
|
2537
|
+
}
|
|
2538
|
+
function listEditorBlocks() {
|
|
2539
|
+
return [...holder.querySelectorAll('.ce-block')];
|
|
2540
|
+
}
|
|
2541
|
+
function resolveSectionBlockIndex(sectionEl) {
|
|
2542
|
+
const block = sectionEl?.closest('.ce-block');
|
|
2543
|
+
if (!block || !holder.contains(block))
|
|
2544
|
+
return -1;
|
|
2545
|
+
return listEditorBlocks().indexOf(block);
|
|
2546
|
+
}
|
|
2547
|
+
async function loadSelectedSectionProperties(sectionEl = null) {
|
|
2548
|
+
if (selectedSectionBlockIndex < 0 || !propertiesPanel || !editor)
|
|
2549
|
+
return;
|
|
2550
|
+
try {
|
|
2551
|
+
await editor.isReady;
|
|
2552
|
+
const saved = await editor.save();
|
|
2553
|
+
const block = saved.blocks?.[selectedSectionBlockIndex];
|
|
2554
|
+
if (block?.type !== 'documentSection')
|
|
2555
|
+
return;
|
|
2556
|
+
const section = sectionEl ??
|
|
2557
|
+
listEditorBlocks()[selectedSectionBlockIndex]?.querySelector('.document-section') ??
|
|
2558
|
+
null;
|
|
2559
|
+
propertiesPanel.showSection(selectedSectionBlockIndex, {
|
|
2560
|
+
name: block.data?.name ?? '',
|
|
2561
|
+
label: block.data?.label ?? '',
|
|
2562
|
+
repeatable: !!block.data?.repeatable,
|
|
2563
|
+
hideTitleInPreview: !!block.data?.hideTitleInPreview,
|
|
2564
|
+
borderTop: !!block.data?.borderTop,
|
|
2565
|
+
borderBottom: !!block.data?.borderBottom,
|
|
2566
|
+
eachRowOnNewPage: !!block.data?.eachRowOnNewPage,
|
|
2567
|
+
keepOnOnePage: !!block.data?.keepOnOnePage,
|
|
2568
|
+
visibility: block.data?.visibility ?? null,
|
|
2569
|
+
}, section);
|
|
2570
|
+
updateSectionSelectionHighlight();
|
|
2571
|
+
}
|
|
2572
|
+
catch {
|
|
2573
|
+
// editor not ready
|
|
2574
|
+
}
|
|
2575
|
+
}
|
|
2576
|
+
function updateSectionSelectionHighlight() {
|
|
2577
|
+
holder.querySelectorAll('.document-section--selected').forEach((el) => {
|
|
2578
|
+
el.classList.remove('document-section--selected');
|
|
2579
|
+
});
|
|
2580
|
+
if (selectedSectionBlockIndex < 0)
|
|
2581
|
+
return;
|
|
2582
|
+
listEditorBlocks()[selectedSectionBlockIndex]
|
|
2583
|
+
?.querySelector('.document-section')
|
|
2584
|
+
?.classList.add('document-section--selected');
|
|
2585
|
+
}
|
|
2586
|
+
function onDesignHolderClick(e) {
|
|
2587
|
+
if (!designMode || !useDesignPanels || !propertiesPanel)
|
|
2588
|
+
return;
|
|
2589
|
+
// Ignore leftover clicks from a table or columns resize / reorder drag.
|
|
2590
|
+
if (document.body.classList.contains('vision-table-col-resize-active'))
|
|
2591
|
+
return;
|
|
2592
|
+
if (document.body.classList.contains('vision-table-col-reorder-active'))
|
|
2593
|
+
return;
|
|
2594
|
+
if (document.body.classList.contains('document-columns-col-resize-active'))
|
|
2595
|
+
return;
|
|
2596
|
+
if (e.target?.closest?.('.vision-table__col-resizer'))
|
|
2597
|
+
return;
|
|
2598
|
+
if (e.target?.closest?.('.document-columns__col-resizer'))
|
|
2599
|
+
return;
|
|
2600
|
+
if (e.target === holder ||
|
|
2601
|
+
e.target === designEditorScroll ||
|
|
2602
|
+
e.target.classList?.contains('codex-editor') ||
|
|
2603
|
+
e.target.classList?.contains('codex-editor__redactor') ||
|
|
2604
|
+
e.target.classList?.contains('ce-block') ||
|
|
2605
|
+
e.target.classList?.contains('ce-block__content')) {
|
|
2606
|
+
selectedSectionBlockIndex = -1;
|
|
2607
|
+
clearStructureSelection();
|
|
2608
|
+
clearAllDesignTokenSelection(holder);
|
|
2609
|
+
updateSectionSelectionHighlight();
|
|
2610
|
+
propertiesPanel.showDocument(documentPageSetup);
|
|
2611
|
+
return;
|
|
2612
|
+
}
|
|
2613
|
+
const columnsToolbar = e.target.closest('.document-columns__toolbar');
|
|
2614
|
+
if (columnsToolbar && holder.contains(columnsToolbar)) {
|
|
2615
|
+
if (e.target.closest('[data-action="delete-columns"]')) {
|
|
2616
|
+
return;
|
|
2617
|
+
}
|
|
2618
|
+
const columnsEl = columnsToolbar.closest('.document-columns');
|
|
2619
|
+
if (!columnsEl)
|
|
2620
|
+
return;
|
|
2621
|
+
e.preventDefault();
|
|
2622
|
+
e.stopPropagation();
|
|
2623
|
+
selectColumnsEl(columnsEl);
|
|
2624
|
+
return;
|
|
2625
|
+
}
|
|
2626
|
+
const tableToolbar = e.target.closest('.document-table__toolbar');
|
|
2627
|
+
if (tableToolbar && holder.contains(tableToolbar)) {
|
|
2628
|
+
if (e.target.closest('[data-action="delete-table"]')) {
|
|
2629
|
+
return;
|
|
2630
|
+
}
|
|
2631
|
+
const tableEl = tableToolbar.closest('.document-table');
|
|
2632
|
+
if (!tableEl)
|
|
2633
|
+
return;
|
|
2634
|
+
e.preventDefault();
|
|
2635
|
+
e.stopPropagation();
|
|
2636
|
+
selectTableEl(tableEl);
|
|
2637
|
+
return;
|
|
2638
|
+
}
|
|
2639
|
+
// Pivot has no cell tokens — clicking the grid should still select the block.
|
|
2640
|
+
const pivotEl = e.target.closest('.document-table--pivot');
|
|
2641
|
+
if (pivotEl && holder.contains(pivotEl)) {
|
|
2642
|
+
if (e.target.closest('[data-action="delete-table"], .pivot-table__row-label-resizer, .vision-table__col-resizer')) {
|
|
2643
|
+
return;
|
|
2644
|
+
}
|
|
2645
|
+
e.preventDefault();
|
|
2646
|
+
e.stopPropagation();
|
|
2647
|
+
selectTableEl(pivotEl);
|
|
2648
|
+
return;
|
|
2649
|
+
}
|
|
2650
|
+
// Clicking into prose clears Section/Table selection so Properties don't stick.
|
|
2651
|
+
if (shouldClearObjectSelectionForTextTarget(e.target)) {
|
|
2652
|
+
clearObjectSelectionForTextEdit();
|
|
2653
|
+
return;
|
|
2654
|
+
}
|
|
2655
|
+
const header = e.target.closest('.document-section__header');
|
|
2656
|
+
if (!header || !holder.contains(header))
|
|
2657
|
+
return;
|
|
2658
|
+
if (e.target.closest('.document-section__body, .field-token')) {
|
|
2659
|
+
return;
|
|
2660
|
+
}
|
|
2661
|
+
const section = header.closest('.document-section');
|
|
2662
|
+
const blockIndex = resolveSectionBlockIndex(section);
|
|
2663
|
+
if (blockIndex < 0)
|
|
2664
|
+
return;
|
|
2665
|
+
e.preventDefault();
|
|
2666
|
+
e.stopPropagation();
|
|
2667
|
+
selectedSectionBlockIndex = blockIndex;
|
|
2668
|
+
clearStructureSelection();
|
|
2669
|
+
clearAllDesignTokenSelection(holder);
|
|
2670
|
+
updateSectionSelectionHighlight();
|
|
2671
|
+
focusStructureTarget(section);
|
|
2672
|
+
void loadSelectedSectionProperties(section);
|
|
2673
|
+
}
|
|
2674
|
+
holder.addEventListener('click', onDesignHolderClick);
|
|
2675
|
+
function getStyleTargetFieldIds() {
|
|
2676
|
+
const schemas = registry.getFieldSchemas();
|
|
2677
|
+
const ids = new Set();
|
|
2678
|
+
for (const token of getSelectedDesignFieldTokens()) {
|
|
2679
|
+
if (token.classList.contains('field-token--cell')) {
|
|
2680
|
+
const tableId = token.dataset.tableId;
|
|
2681
|
+
const colKey = token.dataset.colKey;
|
|
2682
|
+
if (tableId && colKey) {
|
|
2683
|
+
for (const id of listColumnCellFieldIds(tableId, colKey, schemas)) {
|
|
2684
|
+
ids.add(id);
|
|
2685
|
+
}
|
|
2686
|
+
}
|
|
2687
|
+
else if (token.dataset.fieldId) {
|
|
2688
|
+
ids.add(token.dataset.fieldId);
|
|
2689
|
+
}
|
|
2690
|
+
continue;
|
|
2691
|
+
}
|
|
2692
|
+
if (token.dataset.fieldId)
|
|
2693
|
+
ids.add(token.dataset.fieldId);
|
|
2694
|
+
}
|
|
2695
|
+
return [...ids];
|
|
2696
|
+
}
|
|
2697
|
+
function getPrimaryStyleFieldId() {
|
|
2698
|
+
const tokens = getSelectedDesignFieldTokens();
|
|
2699
|
+
if (!tokens.length)
|
|
2700
|
+
return null;
|
|
2701
|
+
const anchor = tokens.find((token) => token.classList.contains('field-token--column-anchor')) ?? tokens[0];
|
|
2702
|
+
return anchor?.dataset.fieldId ?? null;
|
|
2703
|
+
}
|
|
2704
|
+
function isTableColumnSelection() {
|
|
2705
|
+
const tokens = getSelectedDesignFieldTokens();
|
|
2706
|
+
return tokens.length > 0 && tokens.every((token) => token.classList.contains('field-token--cell'));
|
|
2707
|
+
}
|
|
2708
|
+
function getTableColumnSelectionHint() {
|
|
2709
|
+
const tokens = getSelectedDesignFieldTokens();
|
|
2710
|
+
const token = tokens.find((t) => t.classList.contains('field-token--column-anchor')) ?? tokens[0];
|
|
2711
|
+
const colKey = String(token?.dataset?.colKey ?? '').trim();
|
|
2712
|
+
const label = colKey ? `“${colKey}”` : 'Table column';
|
|
2713
|
+
return `${label} column selected — formatting applies to the whole column.`;
|
|
2714
|
+
}
|
|
2715
|
+
function applyDisplayStyleToFieldIds(fieldIds, normalized) {
|
|
2716
|
+
const schemas = registry.getFieldSchemas();
|
|
2717
|
+
for (const fieldId of fieldIds) {
|
|
2718
|
+
const schema = schemas[fieldId];
|
|
2719
|
+
if (!schema)
|
|
2720
|
+
continue;
|
|
2721
|
+
const updated = { ...schema };
|
|
2722
|
+
if (isEmptyFieldDisplayStyle(normalized)) {
|
|
2723
|
+
delete updated.displayStyle;
|
|
2724
|
+
}
|
|
2725
|
+
else {
|
|
2726
|
+
updated.displayStyle = normalized;
|
|
2727
|
+
}
|
|
2728
|
+
registry.updateFieldSchema(fieldId, updated);
|
|
2729
|
+
refreshFieldSchemaInDom(fieldId, { getRegistry: () => registry, fieldValueStyle }, holder);
|
|
2730
|
+
}
|
|
2731
|
+
refreshTableColumnStylesForFieldIds(fieldIds, registry.getFieldSchemas(), holder, fieldValueStyle);
|
|
2732
|
+
options.onSchemaChange?.(registry.getFieldSchemas());
|
|
2733
|
+
syncFieldStyleToolbar();
|
|
2734
|
+
}
|
|
2735
|
+
function applyDisplayStyleToSelectedFields(override) {
|
|
2736
|
+
applyDisplayStyleToFieldIds(getStyleTargetFieldIds(), normalizeFieldDisplayStyle(override));
|
|
2737
|
+
}
|
|
2738
|
+
function syncFieldStyleToolbar() {
|
|
2739
|
+
if (!designMode || !showToolbar) {
|
|
2740
|
+
if (richTextToolbar.isFieldModeActive()) {
|
|
2741
|
+
richTextToolbar.clearFieldMode();
|
|
2742
|
+
if (lastFocusedEditable?.isConnected) {
|
|
2743
|
+
richTextToolbar.show(lastFocusedEditable);
|
|
2744
|
+
}
|
|
2745
|
+
else {
|
|
2746
|
+
richTextToolbar.clearActive();
|
|
2747
|
+
}
|
|
2748
|
+
}
|
|
2749
|
+
return;
|
|
2750
|
+
}
|
|
2751
|
+
const tokens = getSelectedDesignFieldTokens();
|
|
2752
|
+
if (!tokens.length) {
|
|
2753
|
+
richTextToolbar.clearFieldMode();
|
|
2754
|
+
if (lastFocusedEditable?.isConnected) {
|
|
2755
|
+
richTextToolbar.show(lastFocusedEditable);
|
|
2756
|
+
}
|
|
2757
|
+
else {
|
|
2758
|
+
richTextToolbar.clearActive();
|
|
2759
|
+
}
|
|
2760
|
+
return;
|
|
2761
|
+
}
|
|
2762
|
+
richTextToolbar.showForField({
|
|
2763
|
+
getResolvedStyle: () => {
|
|
2764
|
+
const fieldId = getPrimaryStyleFieldId();
|
|
2765
|
+
const schemas = registry.getFieldSchemas();
|
|
2766
|
+
const schema = schemas[fieldId];
|
|
2767
|
+
const cellRef = fieldId ? parseCellFieldId(fieldId, schemas) : null;
|
|
2768
|
+
if (cellRef) {
|
|
2769
|
+
return resolveTableCellDisplayStyle(cellRef.tableFieldId, cellRef.colKey, schema, schemas, fieldValueStyle);
|
|
2770
|
+
}
|
|
2771
|
+
return resolveFieldDisplayStyle(schema, fieldValueStyle?.default);
|
|
2772
|
+
},
|
|
2773
|
+
getOverrideStyle: () => {
|
|
2774
|
+
const fieldId = getPrimaryStyleFieldId();
|
|
2775
|
+
return normalizeFieldDisplayStyle(registry.getFieldSchemas()[fieldId]?.displayStyle);
|
|
2776
|
+
},
|
|
2777
|
+
getGlobalDefault: () => isTableColumnSelection()
|
|
2778
|
+
? { ...DOCUMENT_TABLE_TEXT_STYLE, ...(fieldValueStyle?.default ?? {}) }
|
|
2779
|
+
: (fieldValueStyle?.default ?? {}),
|
|
2780
|
+
hint: isTableColumnSelection() ? getTableColumnSelectionHint() : undefined,
|
|
2781
|
+
onStyleChange: (override) => {
|
|
2782
|
+
applyDisplayStyleToSelectedFields(override);
|
|
2783
|
+
},
|
|
2784
|
+
onClearStyle: () => {
|
|
2785
|
+
applyDisplayStyleToFieldIds(getStyleTargetFieldIds(), {});
|
|
2786
|
+
},
|
|
2787
|
+
});
|
|
2788
|
+
}
|
|
2789
|
+
function eventFocusTarget(e) {
|
|
2790
|
+
// Prefer composedPath; under LWS document listeners may still retarget — prefer shell listeners.
|
|
2791
|
+
const path = typeof e.composedPath === 'function' ? e.composedPath() : [];
|
|
2792
|
+
for (const node of path) {
|
|
2793
|
+
if (node instanceof Element)
|
|
2794
|
+
return node;
|
|
2795
|
+
}
|
|
2796
|
+
return e.target instanceof Element ? e.target : null;
|
|
2797
|
+
}
|
|
2798
|
+
function activateToolbarForTarget(target) {
|
|
2799
|
+
if (!target)
|
|
2800
|
+
return false;
|
|
2801
|
+
if (designMode && target.closest?.('.field-token--design')) {
|
|
2802
|
+
syncFieldStyleToolbar();
|
|
2803
|
+
return true;
|
|
2804
|
+
}
|
|
2805
|
+
if (shouldClearObjectSelectionForTextTarget(target)) {
|
|
2806
|
+
clearObjectSelectionForTextEdit();
|
|
2807
|
+
}
|
|
2808
|
+
const columnEditable = target.closest?.('.document-columns__col');
|
|
2809
|
+
if (columnEditable && holder.contains(columnEditable)) {
|
|
2810
|
+
lastFocusedEditable = columnEditable;
|
|
2811
|
+
if (designMode && getSelectedDesignFieldTokens().length) {
|
|
2812
|
+
syncFieldStyleToolbar();
|
|
2813
|
+
return true;
|
|
2814
|
+
}
|
|
2815
|
+
richTextToolbar.show(columnEditable);
|
|
2816
|
+
return true;
|
|
2817
|
+
}
|
|
2818
|
+
const editable = target.closest?.('.document-section__body');
|
|
2819
|
+
if (editable && holder.contains(editable)) {
|
|
2820
|
+
// Focusing a selected table/columns block lives inside the section body —
|
|
2821
|
+
// don't treat that as prose editing.
|
|
2822
|
+
if (isDesignStructureTarget(target)) {
|
|
2823
|
+
return false;
|
|
2824
|
+
}
|
|
2825
|
+
lastFocusedEditable = editable;
|
|
2826
|
+
if (designMode && getSelectedDesignFieldTokens().length) {
|
|
2827
|
+
syncFieldStyleToolbar();
|
|
2828
|
+
return true;
|
|
2829
|
+
}
|
|
2830
|
+
richTextToolbar.show(editable);
|
|
2831
|
+
return true;
|
|
2832
|
+
}
|
|
2833
|
+
if (target.closest('.rich-text-toolbar')) {
|
|
2834
|
+
return true;
|
|
2835
|
+
}
|
|
2836
|
+
if (designMode && getSelectedDesignFieldTokens().length) {
|
|
2837
|
+
syncFieldStyleToolbar();
|
|
2838
|
+
return true;
|
|
2839
|
+
}
|
|
2840
|
+
return false;
|
|
2841
|
+
}
|
|
2842
|
+
function onFocusIn(e) {
|
|
2843
|
+
const target = eventFocusTarget(e);
|
|
2844
|
+
if (!activateToolbarForTarget(target)) {
|
|
2845
|
+
richTextToolbar.clearActive();
|
|
2846
|
+
}
|
|
2847
|
+
}
|
|
2848
|
+
/** Click/mouseup backup — LWS can swallow document focusin into the shadow tree. */
|
|
2849
|
+
function onEditorPointerActivate(e) {
|
|
2850
|
+
const target = eventFocusTarget(e);
|
|
2851
|
+
activateToolbarForTarget(target);
|
|
2852
|
+
}
|
|
2853
|
+
/** Block Salesforce page shortcuts (e.g. "e" → Edit). Class cke_editable is the reliable SF bypass. */
|
|
2854
|
+
function onEditorKeyDown(e) {
|
|
2855
|
+
e.stopPropagation();
|
|
2856
|
+
if (e.defaultPrevented)
|
|
2857
|
+
return;
|
|
2858
|
+
const mod = e.ctrlKey || e.metaKey;
|
|
2859
|
+
if (!mod || e.altKey)
|
|
2860
|
+
return;
|
|
2861
|
+
if (!shouldHandleHistoryShortcut(e))
|
|
2862
|
+
return;
|
|
2863
|
+
const key = e.key.toLowerCase();
|
|
2864
|
+
if (key === 'z' && !e.shiftKey) {
|
|
2865
|
+
e.preventDefault();
|
|
2866
|
+
void undoDocument();
|
|
2867
|
+
return;
|
|
2868
|
+
}
|
|
2869
|
+
if (key === 'y' || (key === 'z' && e.shiftKey)) {
|
|
2870
|
+
e.preventDefault();
|
|
2871
|
+
void redoDocument();
|
|
2872
|
+
}
|
|
2873
|
+
}
|
|
2874
|
+
function onDesignStructureDeleteKeyDown(e) {
|
|
2875
|
+
if (!designMode)
|
|
2876
|
+
return;
|
|
2877
|
+
if (e.key !== 'Delete' && e.key !== 'Backspace')
|
|
2878
|
+
return;
|
|
2879
|
+
if (e.ctrlKey || e.metaKey || e.altKey)
|
|
2880
|
+
return;
|
|
2881
|
+
if (e.defaultPrevented)
|
|
2882
|
+
return;
|
|
2883
|
+
if (shouldIgnoreStructureDeleteKey(e))
|
|
2884
|
+
return;
|
|
2885
|
+
if (selectedColumnsEl?.isConnected) {
|
|
2886
|
+
e.preventDefault();
|
|
2887
|
+
e.stopPropagation();
|
|
2888
|
+
deleteSelectedColumnsBlock();
|
|
2889
|
+
return;
|
|
2890
|
+
}
|
|
2891
|
+
if (selectedTableEl?.isConnected) {
|
|
2892
|
+
e.preventDefault();
|
|
2893
|
+
e.stopPropagation();
|
|
2894
|
+
deleteSelectedTableBlock();
|
|
2895
|
+
return;
|
|
2896
|
+
}
|
|
2897
|
+
if (selectedSectionBlockIndex >= 0) {
|
|
2898
|
+
e.preventDefault();
|
|
2899
|
+
e.stopPropagation();
|
|
2900
|
+
void deleteSelectedSectionBlock();
|
|
2901
|
+
}
|
|
2902
|
+
}
|
|
2903
|
+
setFieldSelectionChangeCallback(() => {
|
|
2904
|
+
syncFieldStyleToolbar();
|
|
2905
|
+
syncPropertiesPanel();
|
|
2906
|
+
});
|
|
2907
|
+
// Listen on the shell/holder (same tree as contenteditable) — not document alone (LWS retargets).
|
|
2908
|
+
// Also listen on document so Delete still works after selecting a non-focusable header
|
|
2909
|
+
// (focus often moves to <body> and never reaches the shell).
|
|
2910
|
+
const focusRoot = designShell?.element ?? holder;
|
|
2911
|
+
focusRoot.addEventListener('focusin', onFocusIn);
|
|
2912
|
+
focusRoot.addEventListener('mouseup', onEditorPointerActivate);
|
|
2913
|
+
focusRoot.addEventListener('keydown', onEditorKeyDown);
|
|
2914
|
+
focusRoot.addEventListener('keydown', onDesignStructureDeleteKeyDown, true);
|
|
2915
|
+
holder.addEventListener('keydown', onEditorKeyDown);
|
|
2916
|
+
holder.addEventListener('keydown', onDesignStructureDeleteKeyDown, true);
|
|
2917
|
+
document.addEventListener('keydown', onDesignStructureDeleteKeyDown, true);
|
|
2918
|
+
syncShowFieldsHighlight();
|
|
2919
|
+
initEditor(options.data ?? options.defaultDocument ?? DEFAULT_EMPTY_DOCUMENT);
|
|
2920
|
+
async function applyFieldMappingToEditor(payload, specOverride = null) {
|
|
2921
|
+
const doc = await getDocument();
|
|
2922
|
+
const spec = specOverride
|
|
2923
|
+
? normalizeFieldMappingSpec(specOverride)
|
|
2924
|
+
: documentFieldMapping;
|
|
2925
|
+
if (specOverride) {
|
|
2926
|
+
documentFieldMapping = spec;
|
|
2927
|
+
}
|
|
2928
|
+
if (!spec?.rules?.length && !spec?.expression?.trim()) {
|
|
2929
|
+
throw new Error('No field mapping configured.');
|
|
2930
|
+
}
|
|
2931
|
+
const result = runFieldMapping(payload, spec, {
|
|
2932
|
+
blocks: doc.blocks,
|
|
2933
|
+
fieldSchemas: doc.fieldSchemas,
|
|
2934
|
+
});
|
|
2935
|
+
loadedDocumentSections = result.fieldsExport.sections
|
|
2936
|
+
? JSON.parse(JSON.stringify(result.fieldsExport.sections))
|
|
2937
|
+
: null;
|
|
2938
|
+
const mappedMaterialized = materializeRepeatableSectionInstances(result.blocks, result.fieldSchemas, loadedDocumentSections);
|
|
2939
|
+
initEditor({
|
|
2940
|
+
time: Date.now(),
|
|
2941
|
+
fieldSchemas: mappedMaterialized.fieldSchemas,
|
|
2942
|
+
blocks: mappedMaterialized.blocks,
|
|
2943
|
+
pageSetup: documentPageSetup,
|
|
2944
|
+
fieldMapping: documentFieldMapping,
|
|
2945
|
+
});
|
|
2946
|
+
// Wait for sections to mount, then recompute like preview (sum of mapped table columns).
|
|
2947
|
+
if (editor)
|
|
2948
|
+
await editor.isReady;
|
|
2949
|
+
syncFillComputedFields(holder, {}, {
|
|
2950
|
+
getRegistry: () => registry,
|
|
2951
|
+
editorHolder: holder,
|
|
2952
|
+
fieldValueStyle,
|
|
2953
|
+
fillModeFieldHighlight: !designMode && showFieldsInFillMode && !options.mappingMode,
|
|
2954
|
+
});
|
|
2955
|
+
return result;
|
|
2956
|
+
}
|
|
2957
|
+
runPreview = async (previewOptions = {}) => {
|
|
2958
|
+
if (editor)
|
|
2959
|
+
await editor.save();
|
|
2960
|
+
documentActions.setBusy(true);
|
|
2961
|
+
try {
|
|
2962
|
+
// Re-apply mapping in memory (do not remount the editor). Remounting lets
|
|
2963
|
+
// EditorJS mutate the shared blocks reference back to a single seed row
|
|
2964
|
+
// before Preview clones them — dropping nested $values detail rows.
|
|
2965
|
+
const sample = documentFieldMapping?.sourceSample;
|
|
2966
|
+
const hasRules = Array.isArray(documentFieldMapping?.rules) && documentFieldMapping.rules.length > 0;
|
|
2967
|
+
let previewDoc = null;
|
|
2968
|
+
if (sample != null && hasRules) {
|
|
2969
|
+
try {
|
|
2970
|
+
const doc = await getDocument();
|
|
2971
|
+
const result = runFieldMapping(sample, documentFieldMapping, {
|
|
2972
|
+
blocks: doc.blocks,
|
|
2973
|
+
fieldSchemas: doc.fieldSchemas,
|
|
2974
|
+
});
|
|
2975
|
+
const sections = result.fieldsExport?.sections
|
|
2976
|
+
? JSON.parse(JSON.stringify(result.fieldsExport.sections))
|
|
2977
|
+
: null;
|
|
2978
|
+
loadedDocumentSections = sections;
|
|
2979
|
+
previewDoc = {
|
|
2980
|
+
time: Date.now(),
|
|
2981
|
+
blocks: JSON.parse(JSON.stringify(result.blocks)),
|
|
2982
|
+
fieldSchemas: JSON.parse(JSON.stringify(result.fieldSchemas)),
|
|
2983
|
+
loadedDocumentSections: sections,
|
|
2984
|
+
};
|
|
2985
|
+
if (Object.keys(documentPageSetup).length > 0) {
|
|
2986
|
+
previewDoc.pageSetup = JSON.parse(JSON.stringify(documentPageSetup));
|
|
2987
|
+
}
|
|
2988
|
+
if (documentFieldMapping) {
|
|
2989
|
+
previewDoc.fieldMapping = JSON.parse(JSON.stringify(documentFieldMapping));
|
|
2990
|
+
}
|
|
2991
|
+
attachRepeatableInstances(previewDoc);
|
|
2992
|
+
}
|
|
2993
|
+
catch (err) {
|
|
2994
|
+
console.warn('[docengine] preview mapping apply failed', err);
|
|
2995
|
+
showNotification(err?.message ?? 'Preview mapping failed.', { type: 'error' });
|
|
2996
|
+
previewDoc = null;
|
|
2997
|
+
}
|
|
2998
|
+
}
|
|
2999
|
+
await previewModal.open(previewDoc ?? (await getDocument()), {
|
|
3000
|
+
hideEmptyValues: previewOptions.hideEmptyValues === true,
|
|
3001
|
+
});
|
|
3002
|
+
}
|
|
3003
|
+
finally {
|
|
3004
|
+
documentActions.setBusy(false);
|
|
3005
|
+
refreshTableCellTokens(holder, { getRegistry: () => registry, fieldValueStyle });
|
|
3006
|
+
pruneTableCellCaretAnchors(holder);
|
|
3007
|
+
}
|
|
3008
|
+
};
|
|
3009
|
+
/**
|
|
3010
|
+
* Build an HTML or PDF blob for the host to email / Slack / attach.
|
|
3011
|
+
* Use `format: 'current'` to follow the open preview view mode (defaults to html).
|
|
3012
|
+
*/
|
|
3013
|
+
async function getPreviewArtifact(callOptions = {}) {
|
|
3014
|
+
if (editor)
|
|
3015
|
+
await editor.save();
|
|
3016
|
+
const doc = await getDocument();
|
|
3017
|
+
const { format: formatOption, filename: filenameOption, generatePdfBlob: generateOverride, hideEmptyValues: hideEmptyOption, title: titleOption, ...restExport } = callOptions;
|
|
3018
|
+
const format = formatOption === 'pdf' || formatOption === 'html'
|
|
3019
|
+
? formatOption
|
|
3020
|
+
: previewModal.isOpen()
|
|
3021
|
+
? previewModal.getViewMode()
|
|
3022
|
+
: 'html';
|
|
3023
|
+
const hideEmptyValues = typeof hideEmptyOption === 'boolean'
|
|
3024
|
+
? hideEmptyOption
|
|
3025
|
+
: previewModal.isOpen()
|
|
3026
|
+
? previewModal.getHideEmptyValues()
|
|
3027
|
+
: false;
|
|
3028
|
+
const exportOptions = resolvePreviewExportOptions(doc, {
|
|
3029
|
+
...restExport,
|
|
3030
|
+
hideEmptyValues,
|
|
3031
|
+
fieldValueStyle,
|
|
3032
|
+
title: titleOption ?? documentPageSetup.title ?? ui.pdfTitle,
|
|
3033
|
+
});
|
|
3034
|
+
const title = titleOption ??
|
|
3035
|
+
exportOptions.title ??
|
|
3036
|
+
documentPageSetup.title ??
|
|
3037
|
+
ui.pdfTitle ??
|
|
3038
|
+
'document';
|
|
3039
|
+
if (format === 'pdf') {
|
|
3040
|
+
const pdfOk = options.pdfAvailable !== undefined
|
|
3041
|
+
? !!(await Promise.resolve(typeof options.pdfAvailable === 'function'
|
|
3042
|
+
? options.pdfAvailable()
|
|
3043
|
+
: options.pdfAvailable))
|
|
3044
|
+
: typeof options.generatePdfBlob === 'function' ||
|
|
3045
|
+
typeof generateOverride === 'function' ||
|
|
3046
|
+
isClientPdfAvailable;
|
|
3047
|
+
if (!pdfOk) {
|
|
3048
|
+
throw new Error('PDF generation is not available.');
|
|
3049
|
+
}
|
|
3050
|
+
const generate = typeof generateOverride === 'function'
|
|
3051
|
+
? generateOverride
|
|
3052
|
+
: typeof options.generatePdfBlob === 'function'
|
|
3053
|
+
? options.generatePdfBlob
|
|
3054
|
+
: null;
|
|
3055
|
+
const blob = generate
|
|
3056
|
+
? await generate(doc, exportOptions)
|
|
3057
|
+
: await generateDocumentPdfBlob(doc, exportOptions);
|
|
3058
|
+
const filename = filenameOption ??
|
|
3059
|
+
buildExportFilename({ title, baseName: ui.pdfFilename, format: 'pdf' });
|
|
3060
|
+
return { blob, filename, mimeType: 'application/pdf', format: 'pdf' };
|
|
3061
|
+
}
|
|
3062
|
+
const blob = buildPreviewHtmlBlob(doc, exportOptions);
|
|
3063
|
+
const filename = filenameOption ??
|
|
3064
|
+
buildExportFilename({ title, baseName: ui.pdfFilename, format: 'html' });
|
|
3065
|
+
return { blob, filename, mimeType: 'text/html;charset=utf-8', format: 'html' };
|
|
3066
|
+
}
|
|
3067
|
+
const instance = {
|
|
3068
|
+
holder,
|
|
3069
|
+
registry,
|
|
3070
|
+
palette,
|
|
3071
|
+
richTextToolbar,
|
|
3072
|
+
documentActions,
|
|
3073
|
+
get ready() {
|
|
3074
|
+
return editor?.isReady ?? Promise.resolve();
|
|
3075
|
+
},
|
|
3076
|
+
getDocument,
|
|
3077
|
+
exportDoc: async () => buildDocExport(await getDocument()),
|
|
3078
|
+
exportFields: async (exportOptions = {}) => {
|
|
3079
|
+
const doc = await getDocument();
|
|
3080
|
+
let exported = buildFieldsExport(doc, exportOptions);
|
|
3081
|
+
if (exportOptions?.omitMappedFields === true) {
|
|
3082
|
+
exported = omitMappedFields(exported, documentFieldMapping ?? doc.fieldMapping);
|
|
3083
|
+
}
|
|
3084
|
+
return exported;
|
|
3085
|
+
},
|
|
3086
|
+
exportTemplate: async () => buildTemplateExport(await getDocument()),
|
|
3087
|
+
/** @deprecated Use exportFields() */
|
|
3088
|
+
exportDocument: async (exportOptions = {}) => {
|
|
3089
|
+
const doc = await getDocument();
|
|
3090
|
+
let exported = buildFieldsExport(doc, exportOptions);
|
|
3091
|
+
if (exportOptions?.omitMappedFields === true) {
|
|
3092
|
+
exported = omitMappedFields(exported, documentFieldMapping ?? doc.fieldMapping);
|
|
3093
|
+
}
|
|
3094
|
+
return exported;
|
|
3095
|
+
},
|
|
3096
|
+
async load(data, loadOptions = {}) {
|
|
3097
|
+
if (editor)
|
|
3098
|
+
await editor.save();
|
|
3099
|
+
if (isFieldsExport(data)) {
|
|
3100
|
+
const doc = await getDocument();
|
|
3101
|
+
let fieldsPayload = data;
|
|
3102
|
+
if (loadOptions?.omitMappedFields === true) {
|
|
3103
|
+
fieldsPayload = omitMappedFields(data, documentFieldMapping ?? doc.fieldMapping);
|
|
3104
|
+
}
|
|
3105
|
+
loadedDocumentSections = fieldsPayload.sections
|
|
3106
|
+
? JSON.parse(JSON.stringify(fieldsPayload.sections))
|
|
3107
|
+
: null;
|
|
3108
|
+
const values = normalizeDocumentValues(fieldsPayload, doc.blocks, doc.fieldSchemas);
|
|
3109
|
+
const applied = applyDocumentValues(doc.blocks, values, doc.fieldSchemas);
|
|
3110
|
+
// Expand `_source` section arrays into concrete fill blocks (one per
|
|
3111
|
+
// instance, including nested table rows). Preview/PDF already clones via
|
|
3112
|
+
// repeatableSectionInstances; without this the editor only shows [0].
|
|
3113
|
+
const materialized = materializeRepeatableSectionInstances(applied.blocks, applied.fieldSchemas, loadedDocumentSections);
|
|
3114
|
+
const resume = documentHistory.suspend();
|
|
3115
|
+
try {
|
|
3116
|
+
initEditor({
|
|
3117
|
+
time: fieldsPayload.time ?? Date.now(),
|
|
3118
|
+
fieldSchemas: materialized.fieldSchemas,
|
|
3119
|
+
blocks: materialized.blocks,
|
|
3120
|
+
pageSetup: documentPageSetup,
|
|
3121
|
+
});
|
|
3122
|
+
if (editor)
|
|
3123
|
+
await editor.isReady;
|
|
3124
|
+
documentHistory.reset(getHistorySnapshot());
|
|
3125
|
+
}
|
|
3126
|
+
finally {
|
|
3127
|
+
resume();
|
|
3128
|
+
}
|
|
3129
|
+
}
|
|
3130
|
+
else {
|
|
3131
|
+
loadedDocumentSections = null;
|
|
3132
|
+
const resume = documentHistory.suspend();
|
|
3133
|
+
try {
|
|
3134
|
+
initEditor(normalizeImportedDoc(data));
|
|
3135
|
+
if (editor)
|
|
3136
|
+
await editor.isReady;
|
|
3137
|
+
documentHistory.reset(getHistorySnapshot());
|
|
3138
|
+
}
|
|
3139
|
+
finally {
|
|
3140
|
+
resume();
|
|
3141
|
+
}
|
|
3142
|
+
}
|
|
3143
|
+
// Keep parity with mapping apply: after import/load remounts EditorJS and
|
|
3144
|
+
// tokens are seeded, recompute all computed values from loaded fields so
|
|
3145
|
+
// table totals/subtotals are immediately correct before manual edits.
|
|
3146
|
+
syncFillComputedFields(holder, {}, {
|
|
3147
|
+
getRegistry: () => registry,
|
|
3148
|
+
editorHolder: holder,
|
|
3149
|
+
fieldValueStyle,
|
|
3150
|
+
fillModeFieldHighlight: !designMode && showFieldsInFillMode && !options.mappingMode,
|
|
3151
|
+
});
|
|
3152
|
+
// Version switch / import remounts EditorJS; drop stale section selection
|
|
3153
|
+
// and show Page Setup so the properties panel matches the new document.
|
|
3154
|
+
if (useDesignPanels && designMode) {
|
|
3155
|
+
openPageSetupPanel();
|
|
3156
|
+
}
|
|
3157
|
+
},
|
|
3158
|
+
undo: () => undoDocument(),
|
|
3159
|
+
redo: () => redoDocument(),
|
|
3160
|
+
canUndo: () => {
|
|
3161
|
+
flushHistoryRecord();
|
|
3162
|
+
return documentHistory.canUndo();
|
|
3163
|
+
},
|
|
3164
|
+
canRedo: () => {
|
|
3165
|
+
flushHistoryRecord();
|
|
3166
|
+
return documentHistory.canRedo();
|
|
3167
|
+
},
|
|
3168
|
+
async setDesignMode(enabled) {
|
|
3169
|
+
if (setDesignModeInFlight) {
|
|
3170
|
+
await setDesignModeInFlight;
|
|
3171
|
+
}
|
|
3172
|
+
const run = (async () => {
|
|
3173
|
+
if (typeof propertiesPanel?.flush === 'function') {
|
|
3174
|
+
try {
|
|
3175
|
+
await propertiesPanel.flush();
|
|
3176
|
+
}
|
|
3177
|
+
catch {
|
|
3178
|
+
// keep switching mode even if properties save fails
|
|
3179
|
+
}
|
|
3180
|
+
}
|
|
3181
|
+
if (editor) {
|
|
3182
|
+
try {
|
|
3183
|
+
await editor.isReady;
|
|
3184
|
+
await editor.save();
|
|
3185
|
+
}
|
|
3186
|
+
catch {
|
|
3187
|
+
// editor not ready
|
|
3188
|
+
}
|
|
3189
|
+
}
|
|
3190
|
+
designMode = !!enabled;
|
|
3191
|
+
applyDesignMode(designMode);
|
|
3192
|
+
syncDesignChromeVisibility();
|
|
3193
|
+
const doc = await getDocument();
|
|
3194
|
+
initEditor(doc);
|
|
3195
|
+
if (editor) {
|
|
3196
|
+
try {
|
|
3197
|
+
await editor.isReady;
|
|
3198
|
+
}
|
|
3199
|
+
catch {
|
|
3200
|
+
// ignore
|
|
3201
|
+
}
|
|
3202
|
+
}
|
|
3203
|
+
})();
|
|
3204
|
+
setDesignModeInFlight = run.finally(() => {
|
|
3205
|
+
if (setDesignModeInFlight === run)
|
|
3206
|
+
setDesignModeInFlight = null;
|
|
3207
|
+
});
|
|
3208
|
+
await setDesignModeInFlight;
|
|
3209
|
+
},
|
|
3210
|
+
getDesignMode: () => designMode,
|
|
3211
|
+
setShowFieldsInFillMode(enabled) {
|
|
3212
|
+
showFieldsInFillMode = !!enabled;
|
|
3213
|
+
syncShowFieldsHighlight();
|
|
3214
|
+
},
|
|
3215
|
+
getShowFieldsInFillMode: () => showFieldsInFillMode,
|
|
3216
|
+
async preview(options = {}) {
|
|
3217
|
+
return runPreview(options);
|
|
3218
|
+
},
|
|
3219
|
+
isPreviewOpen: () => previewModal.isOpen(),
|
|
3220
|
+
closePreview: () => {
|
|
3221
|
+
previewModal.close();
|
|
3222
|
+
},
|
|
3223
|
+
/**
|
|
3224
|
+
* Render Simple preview HTML (optionally hiding empty fields) for export/attach.
|
|
3225
|
+
* @returns {Promise<string>}
|
|
3226
|
+
*/
|
|
3227
|
+
async exportPreviewHtml(callOptions = {}) {
|
|
3228
|
+
if (editor)
|
|
3229
|
+
await editor.save();
|
|
3230
|
+
const doc = await getDocument();
|
|
3231
|
+
const exportOptions = resolvePreviewExportOptions(doc, {
|
|
3232
|
+
hideEmptyValues: callOptions.hideEmptyValues === true,
|
|
3233
|
+
fieldValueStyle,
|
|
3234
|
+
title: callOptions.title,
|
|
3235
|
+
});
|
|
3236
|
+
return buildPreviewHtmlDocument(doc, exportOptions);
|
|
3237
|
+
},
|
|
3238
|
+
getPreviewArtifact,
|
|
3239
|
+
async exportPdf(callOptions) {
|
|
3240
|
+
try {
|
|
3241
|
+
const artifact = await getPreviewArtifact({
|
|
3242
|
+
...callOptions,
|
|
3243
|
+
format: 'pdf',
|
|
3244
|
+
filename: callOptions?.filename ??
|
|
3245
|
+
(ui.pdfFilename
|
|
3246
|
+
? buildExportFilename({
|
|
3247
|
+
baseName: ui.pdfFilename,
|
|
3248
|
+
format: 'pdf',
|
|
3249
|
+
unique: false,
|
|
3250
|
+
})
|
|
3251
|
+
: undefined),
|
|
3252
|
+
});
|
|
3253
|
+
await saveBlobToDisk(artifact.blob, artifact.filename, 'application/pdf');
|
|
3254
|
+
}
|
|
3255
|
+
catch (err) {
|
|
3256
|
+
showNotification(err?.message ?? 'PDF export failed.');
|
|
3257
|
+
}
|
|
3258
|
+
},
|
|
3259
|
+
validate: async () => validateRequiredFields(await getDocument()),
|
|
3260
|
+
getFieldMapping() {
|
|
3261
|
+
return documentFieldMapping ? JSON.parse(JSON.stringify(documentFieldMapping)) : null;
|
|
3262
|
+
},
|
|
3263
|
+
setFieldMapping(spec) {
|
|
3264
|
+
documentFieldMapping = spec ? normalizeFieldMappingSpec(spec) : null;
|
|
3265
|
+
if (documentFieldMapping?.rules?.length) {
|
|
3266
|
+
syncDocumentFieldMappingNames();
|
|
3267
|
+
}
|
|
3268
|
+
else {
|
|
3269
|
+
refreshDesignMappingBadges();
|
|
3270
|
+
}
|
|
3271
|
+
refreshDatabaseSourceTree?.();
|
|
3272
|
+
},
|
|
3273
|
+
async previewFieldMapping(payload) {
|
|
3274
|
+
const doc = await getDocument();
|
|
3275
|
+
const spec = documentFieldMapping ?? normalizeFieldMappingSpec(null);
|
|
3276
|
+
return runFieldMappingPreview(payload, spec, {
|
|
3277
|
+
blocks: doc.blocks,
|
|
3278
|
+
fieldSchemas: doc.fieldSchemas,
|
|
3279
|
+
});
|
|
3280
|
+
},
|
|
3281
|
+
async applyFieldMapping(payload) {
|
|
3282
|
+
return applyFieldMappingToEditor(payload);
|
|
3283
|
+
},
|
|
3284
|
+
async openFieldMapping(options = {}) {
|
|
3285
|
+
if (!fieldMappingModal) {
|
|
3286
|
+
throw new Error('Field mapping editor is not available in this editor.');
|
|
3287
|
+
}
|
|
3288
|
+
// Persist live canvas tokens into registry blocks before the modal reads
|
|
3289
|
+
// getTemplate(). Palette drops update fieldSchemas immediately but blocks
|
|
3290
|
+
// stay stale until EditorJS save — without this, new fields (e.g. _root_text)
|
|
3291
|
+
// are pruned from buildTemplateExport and missing from Template fields.
|
|
3292
|
+
if (editor) {
|
|
3293
|
+
try {
|
|
3294
|
+
await editor.isReady;
|
|
3295
|
+
const live = await editor.save();
|
|
3296
|
+
registry.setBlocks(live.blocks ?? []);
|
|
3297
|
+
}
|
|
3298
|
+
catch {
|
|
3299
|
+
// editor not ready — fall through with current registry state
|
|
3300
|
+
}
|
|
3301
|
+
}
|
|
3302
|
+
const spec = options.spec ?? documentFieldMapping ?? normalizeFieldMappingSpec(null);
|
|
3303
|
+
// Keep Database tab Source payload in sync with the sample Mapping will show.
|
|
3304
|
+
if (spec?.sourceSample != null) {
|
|
3305
|
+
documentFieldMapping = normalizeFieldMappingSpec({
|
|
3306
|
+
...(documentFieldMapping ?? spec),
|
|
3307
|
+
sourceSample: spec.sourceSample,
|
|
3308
|
+
rules: documentFieldMapping?.rules ?? spec.rules ?? [],
|
|
3309
|
+
expression: documentFieldMapping?.expression ?? spec.expression ?? '',
|
|
3310
|
+
});
|
|
3311
|
+
}
|
|
3312
|
+
else if (!documentFieldMapping && spec) {
|
|
3313
|
+
documentFieldMapping = normalizeFieldMappingSpec(spec);
|
|
3314
|
+
}
|
|
3315
|
+
// Align rule section/field names with current template before editing.
|
|
3316
|
+
syncDocumentFieldMappingNames();
|
|
3317
|
+
refreshDatabaseSourceTree?.();
|
|
3318
|
+
const saved = await fieldMappingModal.open({
|
|
3319
|
+
spec: documentFieldMapping ?? spec,
|
|
3320
|
+
onApply: (payload, mappingSpec) => applyFieldMappingToEditor(payload, mappingSpec ?? null),
|
|
3321
|
+
onExpandSourcePath: options.onExpandSourcePath,
|
|
3322
|
+
});
|
|
3323
|
+
documentFieldMapping = saved;
|
|
3324
|
+
refreshDatabaseSourceTree?.();
|
|
3325
|
+
refreshDesignMappingBadges();
|
|
3326
|
+
options.onChange?.(await getDocument());
|
|
3327
|
+
return saved;
|
|
3328
|
+
},
|
|
3329
|
+
async save() {
|
|
3330
|
+
if (editor)
|
|
3331
|
+
await editor.save();
|
|
3332
|
+
return getDocument();
|
|
3333
|
+
},
|
|
3334
|
+
destroy() {
|
|
3335
|
+
destroyed = true;
|
|
3336
|
+
if (historyTimer) {
|
|
3337
|
+
clearTimeout(historyTimer);
|
|
3338
|
+
historyTimer = null;
|
|
3339
|
+
}
|
|
3340
|
+
focusRoot.removeEventListener('focusin', onFocusIn);
|
|
3341
|
+
focusRoot.removeEventListener('mouseup', onEditorPointerActivate);
|
|
3342
|
+
focusRoot.removeEventListener('keydown', onEditorKeyDown);
|
|
3343
|
+
focusRoot.removeEventListener('keydown', onDesignStructureDeleteKeyDown, true);
|
|
3344
|
+
holder.removeEventListener('keydown', onEditorKeyDown);
|
|
3345
|
+
holder.removeEventListener('keydown', onDesignStructureDeleteKeyDown, true);
|
|
3346
|
+
document.removeEventListener('keydown', onDesignStructureDeleteKeyDown, true);
|
|
3347
|
+
holder.removeEventListener('click', onDesignHolderClick);
|
|
3348
|
+
if (editor) {
|
|
3349
|
+
const prev = editor;
|
|
3350
|
+
editor = null;
|
|
3351
|
+
if (typeof prev.destroy === 'function') {
|
|
3352
|
+
try {
|
|
3353
|
+
prev.destroy();
|
|
3354
|
+
}
|
|
3355
|
+
catch {
|
|
3356
|
+
// ignore
|
|
3357
|
+
}
|
|
3358
|
+
}
|
|
3359
|
+
}
|
|
3360
|
+
topChrome?.remove();
|
|
3361
|
+
designToolbarWrap?.remove();
|
|
3362
|
+
if (designEditorScroll?.contains(holder) && designShell?.centerPanel) {
|
|
3363
|
+
designShell.centerPanel.insertBefore(holder, designEditorScroll);
|
|
3364
|
+
}
|
|
3365
|
+
designEditorScroll?.remove();
|
|
3366
|
+
designShell?.destroy();
|
|
3367
|
+
documentActions.element.remove();
|
|
3368
|
+
detachRegistryFromHolder(holder);
|
|
3369
|
+
},
|
|
3370
|
+
};
|
|
3371
|
+
return instance;
|
|
3372
|
+
}
|
|
3373
|
+
//# sourceMappingURL=create-editor.js.map
|