@docengine/editor 0.0.0-stage → 0.0.105
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 +112 -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 +640 -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 +147 -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 +322 -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 +287 -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 +5450 -0
- package/src/themes/bridge.css +1952 -0
- package/src/themes/prime.css +116 -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 +190 -0
- package/src/ui/mapping-result-helper.ts +707 -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 +381 -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,3760 @@
|
|
|
1
|
+
import { resolveRegistry, getRegistryFromNode } from '../registry/registry-context.js';
|
|
2
|
+
import { schemaToDisplayConfig } from '../registry/schema-registry.js';
|
|
3
|
+
import { getFieldHandler } from './handlers/registry.js';
|
|
4
|
+
import { formatLogicalTokenDisplay } from './logical-display.js';
|
|
5
|
+
import { createDefaultBlockData, createDefaultSchema, resolveSchemaDefaultValue, ensureCellSchemasForRows, resolveTableInstanceRows, parseCellFieldId, isFieldEditableInFillMode, isTableCellInheritedReadonly, isSchemaReadonly } from '../core/field-schemas.js';
|
|
6
|
+
import { allocateFieldIdentity } from '../core/field-id.js';
|
|
7
|
+
import { remapperMovedSubtreeToSection } from './cross-section-reposition.js';
|
|
8
|
+
import { PALETTE_DRAG_MIME, parsePaletteDrag, isPaletteDragSessionActive } from '../design/field-palette.js';
|
|
9
|
+
import {
|
|
10
|
+
isSourcePathDragEvent,
|
|
11
|
+
parseSourcePathMeta,
|
|
12
|
+
} from '../ui/mapping-drag-drop.js';
|
|
13
|
+
import { normalizeImageValue, isImageValueEmpty } from '../services/image-upload.js';
|
|
14
|
+
import {
|
|
15
|
+
appendHtmlToFragment,
|
|
16
|
+
isPlainTextHtml,
|
|
17
|
+
sanitizeHtml,
|
|
18
|
+
isAlignmentDiv,
|
|
19
|
+
getBlockTextAlign,
|
|
20
|
+
isHtmlValueEmpty,
|
|
21
|
+
isHeadingElement,
|
|
22
|
+
plainTextNewlinesToBr,
|
|
23
|
+
restoreSelection,
|
|
24
|
+
saveSelection,
|
|
25
|
+
} from './rich-text.js';
|
|
26
|
+
import {
|
|
27
|
+
selectDesignToken,
|
|
28
|
+
getFieldSelectionContainer,
|
|
29
|
+
} from './field-selection.js';
|
|
30
|
+
import {
|
|
31
|
+
setFillFieldFocus,
|
|
32
|
+
restoreFillFieldFocusAfterPicker,
|
|
33
|
+
getNextEditableFillFieldToken,
|
|
34
|
+
shouldAdvanceFillFieldAfterPicker,
|
|
35
|
+
scheduleAfterFillModalClose,
|
|
36
|
+
scrollFillFieldIntoView,
|
|
37
|
+
} from './fill-field-focus.js';
|
|
38
|
+
import {
|
|
39
|
+
evaluateComputedField,
|
|
40
|
+
extractFormulaDependencyFieldIds,
|
|
41
|
+
} from '../core/computed-formula.js';
|
|
42
|
+
import { enrichComputedValues } from '../core/document-io.js';
|
|
43
|
+
import { formatNumericDisplay } from '@docengine/engine';
|
|
44
|
+
import {
|
|
45
|
+
formatManualEditText,
|
|
46
|
+
} from './manual-field-values.js';
|
|
47
|
+
import {
|
|
48
|
+
applyFieldDisplayStyle,
|
|
49
|
+
applyTableCellDisplayStyle,
|
|
50
|
+
clearFieldHighlightOverriddenStyles,
|
|
51
|
+
resolveTokenDisplayStyle,
|
|
52
|
+
} from './field-display-style.js';
|
|
53
|
+
import { encodeBarcodeToDataUrl } from './barcode-encode.js';
|
|
54
|
+
import {
|
|
55
|
+
renderPivotTableSegment,
|
|
56
|
+
readPivotValueFromDom,
|
|
57
|
+
wirePivotRowLabelResize,
|
|
58
|
+
refreshPivotTableInDom,
|
|
59
|
+
} from './pivot-table-field.js';
|
|
60
|
+
import {
|
|
61
|
+
buildTableElement,
|
|
62
|
+
buildPreviewTableElement,
|
|
63
|
+
getTableSchema,
|
|
64
|
+
readTableRowsFromDom,
|
|
65
|
+
syncTableRowsDataset,
|
|
66
|
+
addTableRowToWrapper,
|
|
67
|
+
addTableRowsFromText,
|
|
68
|
+
removeTableRowFromWrapper,
|
|
69
|
+
shouldShowTableRowActions,
|
|
70
|
+
reorderTableColumnsInWrapper,
|
|
71
|
+
} from './table-field.js';
|
|
72
|
+
import {
|
|
73
|
+
schemaWidthToColCss,
|
|
74
|
+
scalePercentCssWidthsToFill,
|
|
75
|
+
wireTableColumnResize,
|
|
76
|
+
} from './wire-table-column-resize.js';
|
|
77
|
+
import { wireTableColumnReorder } from './wire-table-column-reorder.js';
|
|
78
|
+
import { wireColumnsResize } from './wire-columns-resize.js';
|
|
79
|
+
import { showNotification } from '../ui/notification.js';
|
|
80
|
+
import {
|
|
81
|
+
renderRepeaterFieldPreview,
|
|
82
|
+
createInlineRepeaterSeedValue,
|
|
83
|
+
} from './repeater-field.js';
|
|
84
|
+
import { repeaterHasContent, isLegacyRepeaterInstancesWrapper, mergeRepeaterDomValues } from '../core/repeater-io.js';
|
|
85
|
+
import { createDragHandle } from '../ui/drag-handle.js';
|
|
86
|
+
|
|
87
|
+
/** Invisible caret position beside contenteditable=false field tokens. */
|
|
88
|
+
export const FIELD_TOKEN_CARET_ANCHOR = '\u200B';
|
|
89
|
+
|
|
90
|
+
export function stripFieldTokenCaretAnchors(text: any) {
|
|
91
|
+
return String(text ?? '').replace(/\u200B/g, '');
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export function isCaretAnchorOnlyTextNode(node: any) {
|
|
95
|
+
return node?.nodeType === Node.TEXT_NODE && node.textContent === FIELD_TOKEN_CARET_ANCHOR;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function isCaretAnchorTextNode(node: any) {
|
|
99
|
+
return isCaretAnchorOnlyTextNode(node);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export function hasLeadingCaretAnchor(text: any) {
|
|
103
|
+
return String(text ?? '').startsWith(FIELD_TOKEN_CARET_ANCHOR);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export function caretPositionAfterFieldToken(textNode: any) {
|
|
107
|
+
if (!textNode || textNode.nodeType !== Node.TEXT_NODE) return 0;
|
|
108
|
+
if (isCaretAnchorTextNode(textNode)) return 0;
|
|
109
|
+
return hasLeadingCaretAnchor(textNode.textContent) ? 1 : 0;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** Place the caret at a visible position beside a field-token bridge node. */
|
|
113
|
+
export function focusCaretAtFieldBridge(textNode: any) {
|
|
114
|
+
if (!textNode?.isConnected) return;
|
|
115
|
+
try {
|
|
116
|
+
const range = document.createRange();
|
|
117
|
+
if (isCaretAnchorTextNode(textNode)) {
|
|
118
|
+
// Prefer sitting inside the bridge at offset 0 — Chrome paints a caret
|
|
119
|
+
// there (visually after the field). Parent-after-ZWSP often draws nothing.
|
|
120
|
+
range.setStart(textNode, 0);
|
|
121
|
+
} else {
|
|
122
|
+
range.setStart(textNode, caretPositionAfterFieldToken(textNode));
|
|
123
|
+
}
|
|
124
|
+
range.collapse(true);
|
|
125
|
+
const sel = window.getSelection();
|
|
126
|
+
if (!sel) return;
|
|
127
|
+
sel.removeAllRanges();
|
|
128
|
+
sel.addRange(range);
|
|
129
|
+
} catch {
|
|
130
|
+
// node may have been removed from the document
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function isFieldTokenElement(node: any) {
|
|
135
|
+
return node?.nodeType === Node.ELEMENT_NODE && node.classList?.contains('field-token');
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export function ensureCaretAnchorAfter(node: any) {
|
|
139
|
+
if (!node?.isConnected || !node.parentNode) return null;
|
|
140
|
+
// Only field tokens need a ZWSP bridge. Calling this after a <br> (Enter)
|
|
141
|
+
// used to prefix the next line with an invisible anchor and made ArrowRight
|
|
142
|
+
// look stuck at the start of that line.
|
|
143
|
+
if (!isFieldTokenElement(node)) return null;
|
|
144
|
+
if (node.classList?.contains('field-token--cell')) return null;
|
|
145
|
+
|
|
146
|
+
const next = node.nextSibling;
|
|
147
|
+
if (isCaretAnchorTextNode(next)) return next;
|
|
148
|
+
|
|
149
|
+
if (next?.nodeType === Node.TEXT_NODE && stripFieldTokenCaretAnchors(next.textContent).length > 0) {
|
|
150
|
+
if (!hasLeadingCaretAnchor(next.textContent)) {
|
|
151
|
+
next.textContent = `${FIELD_TOKEN_CARET_ANCHOR}${next.textContent}`;
|
|
152
|
+
}
|
|
153
|
+
return next;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
if (
|
|
157
|
+
!next ||
|
|
158
|
+
isFieldTokenElement(next) ||
|
|
159
|
+
next.nodeName === 'BR' ||
|
|
160
|
+
(next.nodeType === Node.TEXT_NODE && !next.textContent)
|
|
161
|
+
) {
|
|
162
|
+
const anchor = document.createTextNode(FIELD_TOKEN_CARET_ANCHOR);
|
|
163
|
+
node.parentNode.insertBefore(anchor, next);
|
|
164
|
+
return anchor;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
return null;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export function ensureFieldTokenCaretAnchors(container: any) {
|
|
171
|
+
if (!container) return;
|
|
172
|
+
container.querySelectorAll('.field-token:not(.field-token--cell)').forEach((token: any) => {
|
|
173
|
+
ensureCaretAnchorAfter(token);
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/** Drop the standalone ZWSP that belongs immediately after a field token (before move/remove). */
|
|
178
|
+
export function removeTrailingCaretBridge(node: any) {
|
|
179
|
+
const bridge = node?.nextSibling;
|
|
180
|
+
if (isCaretAnchorTextNode(bridge)) {
|
|
181
|
+
bridge.remove();
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Insert `node` after `reference` without stealing its caret bridge.
|
|
187
|
+
* `insertAdjacentElement('afterend')` would place the new node between the
|
|
188
|
+
* field and its ZWSP, leaving adjacent contenteditable=false tokens with no
|
|
189
|
+
* place for the caret.
|
|
190
|
+
*/
|
|
191
|
+
export function insertElementAfterPreservingCaretBridge(reference: any, node: any) {
|
|
192
|
+
if (!reference?.parentNode || !node) return;
|
|
193
|
+
let anchor = reference;
|
|
194
|
+
const next = reference.nextSibling;
|
|
195
|
+
if (isCaretAnchorTextNode(next)) {
|
|
196
|
+
anchor = next;
|
|
197
|
+
}
|
|
198
|
+
anchor.parentNode.insertBefore(node, anchor.nextSibling);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/** Remove caret-anchor zero-width spaces from table data cells. */
|
|
202
|
+
export function pruneTableCellCaretAnchors(container: any) {
|
|
203
|
+
if (!container?.querySelectorAll) return;
|
|
204
|
+
for (const td of container.querySelectorAll('.vision-table td')) {
|
|
205
|
+
for (const child of [...td.childNodes]) {
|
|
206
|
+
if (child.nodeType !== Node.TEXT_NODE) continue;
|
|
207
|
+
if (!stripFieldTokenCaretAnchors(child.textContent).trim()) {
|
|
208
|
+
child.remove();
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
function registryFrom(context: any) {
|
|
215
|
+
return resolveRegistry(context);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
function computedFieldsAffectedByChange(changedFieldId: any, schemas: any, blocks: any = []) {
|
|
219
|
+
const computedIds = Object.keys(schemas).filter((id: any) => schemas[id]?.type === 'computed');
|
|
220
|
+
const affected = new Set();
|
|
221
|
+
let changed = true;
|
|
222
|
+
|
|
223
|
+
while (changed) {
|
|
224
|
+
changed = false;
|
|
225
|
+
for (const id of computedIds) {
|
|
226
|
+
if (affected.has(id)) continue;
|
|
227
|
+
const deps = extractFormulaDependencyFieldIds(schemas[id].formula ?? '', blocks, schemas);
|
|
228
|
+
if (deps.some((dep: any) => dep === changedFieldId || affected.has(dep))) {
|
|
229
|
+
affected.add(id);
|
|
230
|
+
changed = true;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
return affected;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
function resolveBlocksFromContext(context: any) {
|
|
239
|
+
const registry = registryFrom(context);
|
|
240
|
+
return context?.blocks ?? registry?.getBlocks?.() ?? [];
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
function resolveEditorHolder(container: any, options: any = {}) {
|
|
244
|
+
return options.editorHolder ?? container?.closest?.('[data-doc-editor]') ?? null;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
function preferLocalFieldIdSet(options: any = {}) {
|
|
248
|
+
const ids = options.preferLocalFieldIds ?? (options.changedFieldId ? [options.changedFieldId] : []);
|
|
249
|
+
return new Set((ids ?? []).filter(Boolean));
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
export function collectAllFieldValuesFromHolder(holder: any, localValues: any = {}, options: any = {}) {
|
|
253
|
+
if (!holder?.querySelectorAll) {
|
|
254
|
+
return recoverImageValuesFromDom(null, { ...(localValues ?? {}) });
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
const merged = {};
|
|
258
|
+
for (const editable of holder.querySelectorAll('.document-section__body')) {
|
|
259
|
+
Object.assign(merged, extractFieldValuesFromDom(editable));
|
|
260
|
+
}
|
|
261
|
+
const out = { ...(localValues ?? {}) };
|
|
262
|
+
const preferLocal = preferLocalFieldIdSet(options);
|
|
263
|
+
// Prefer non-empty live token values; keep stored when DOM scrape is empty (placeholders).
|
|
264
|
+
// A just-saved picker value is newer than the token until updateFieldToken runs — keep it.
|
|
265
|
+
for (const [fieldId, domVal] of Object.entries(merged)) {
|
|
266
|
+
if (preferLocal.has(fieldId) && !isFieldEmpty(out[fieldId])) continue;
|
|
267
|
+
if (!isFieldEmpty(domVal) || isFieldEmpty(out[fieldId])) {
|
|
268
|
+
out[fieldId] = domVal;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
return recoverImageValuesFromDom(holder, out);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
function resolveFieldDef(fieldId: any, context: any) {
|
|
275
|
+
const registry = registryFrom(context) ?? getRegistryFromNode(context);
|
|
276
|
+
return registry?.getFieldDef(fieldId) ?? schemaToDisplayConfig(context?.fieldSchemas?.[fieldId]);
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
export function getFieldDisplayLabel(fieldId: any, placeholder: any, context: any) {
|
|
280
|
+
const def = resolveFieldDef(fieldId, context);
|
|
281
|
+
const label = def?.label || placeholder || fieldId;
|
|
282
|
+
return String(label).trim() || fieldId;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
function formatListArray(value: any, layout: any, itemPrefix: any) {
|
|
286
|
+
switch (layout) {
|
|
287
|
+
case 'lines':
|
|
288
|
+
return value.join('\n');
|
|
289
|
+
case 'bullet':
|
|
290
|
+
return value.map((v: any) => `• ${v}`).join('\n');
|
|
291
|
+
case 'numeric':
|
|
292
|
+
return value.map((v: any, i: any) => `${i + 1}. ${v}`).join('\n');
|
|
293
|
+
case 'custom':
|
|
294
|
+
return value.map((v: any) => `${itemPrefix ?? ''}${v}`).join('\n');
|
|
295
|
+
default:
|
|
296
|
+
return value.join('; ');
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
export function formatFieldDisplay(fieldId: any, value: any, placeholder: any, context: any) {
|
|
301
|
+
const def = resolveFieldDef(fieldId, context);
|
|
302
|
+
const emptyLabel = getFieldDisplayLabel(fieldId, placeholder, context);
|
|
303
|
+
const registry = registryFrom(context);
|
|
304
|
+
const schema = registry?.getFieldSchemas()?.[fieldId] ?? context?.fieldSchemas?.[fieldId];
|
|
305
|
+
const handler = getFieldHandler(schema?.type);
|
|
306
|
+
|
|
307
|
+
if (typeof handler?.formatDisplay === 'function') {
|
|
308
|
+
const formatted = handler.formatDisplay(value, {
|
|
309
|
+
schema,
|
|
310
|
+
def,
|
|
311
|
+
emptyLabel,
|
|
312
|
+
fieldId,
|
|
313
|
+
context,
|
|
314
|
+
});
|
|
315
|
+
if (formatted != null) return formatted;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
if (!def) {
|
|
319
|
+
if (value == null || value === '' || (Array.isArray(value) && value.length === 0)) {
|
|
320
|
+
return emptyLabel;
|
|
321
|
+
}
|
|
322
|
+
if (Array.isArray(value)) return value.join('; ');
|
|
323
|
+
return String(value);
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
if (def.picker === 'image' || def.picker === 'signature') {
|
|
327
|
+
if (isImageValueEmpty(value)) return emptyLabel;
|
|
328
|
+
const img = normalizeImageValue(value);
|
|
329
|
+
return def.picker === 'signature' ? '[Signature]' : img.caption || '[Image]';
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
if (value === true || value === false) {
|
|
333
|
+
return value ? 'Yes' : 'No';
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
if (value == null || value === '' || (Array.isArray(value) && value.length === 0)) {
|
|
337
|
+
return emptyLabel;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
if (Array.isArray(value)) {
|
|
341
|
+
if (def.schemaType === 'list') {
|
|
342
|
+
return formatListArray(value, def.itemLayout ?? 'inline', def.itemPrefix);
|
|
343
|
+
}
|
|
344
|
+
return value.join('; ');
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
if (def.picker === 'integer') {
|
|
348
|
+
return formatNumericDisplay(value, {
|
|
349
|
+
displayFormat: def.displayFormat,
|
|
350
|
+
currencyCode: def.currencyCode,
|
|
351
|
+
fractionDigits: def.fractionDigits,
|
|
352
|
+
suffix: def.suffix,
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
return String(value);
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
export function isRepeaterValue(value: any) {
|
|
360
|
+
if (value == null || typeof value !== 'object' || Array.isArray(value) || 'url' in value) {
|
|
361
|
+
return false;
|
|
362
|
+
}
|
|
363
|
+
return isLegacyRepeaterInstancesWrapper(value);
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
export function isFlatRepeaterValue(value: any, repeaterSchema: any) {
|
|
367
|
+
if (value == null || typeof value !== 'object' || Array.isArray(value) || 'url' in value) {
|
|
368
|
+
return false;
|
|
369
|
+
}
|
|
370
|
+
if (isLegacyRepeaterInstancesWrapper(value)) return true;
|
|
371
|
+
if (!repeaterSchema || repeaterSchema.type !== 'child') return false;
|
|
372
|
+
const childKeys = Object.keys(repeaterSchema.fieldSchemas ?? {});
|
|
373
|
+
if (!childKeys.length) return Object.keys(value).length > 0;
|
|
374
|
+
return Object.keys(value).some((key: any) => childKeys.includes(key));
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
export function isFieldEmpty(value: any, options: any = {}) {
|
|
378
|
+
if (value === '—') return true;
|
|
379
|
+
const repeaterSchema =
|
|
380
|
+
options.repeaterSchema?.type === 'child'
|
|
381
|
+
? options.repeaterSchema
|
|
382
|
+
: options.schema?.type === 'child'
|
|
383
|
+
? options.schema
|
|
384
|
+
: undefined;
|
|
385
|
+
if (repeaterSchema) {
|
|
386
|
+
return !repeaterHasContent(value, repeaterSchema);
|
|
387
|
+
}
|
|
388
|
+
if (isLegacyRepeaterInstancesWrapper(value)) {
|
|
389
|
+
return !Object.values(value.instances ?? {}).some((inst: any) => {
|
|
390
|
+
if (!inst || typeof inst !== 'object') return false;
|
|
391
|
+
return Object.values(inst).some(
|
|
392
|
+
(entry: any) =>
|
|
393
|
+
entry != null &&
|
|
394
|
+
entry !== '' &&
|
|
395
|
+
!(Array.isArray(entry) && entry.length === 0) &&
|
|
396
|
+
!(typeof entry === 'object' && 'url' in entry && !entry.url),
|
|
397
|
+
);
|
|
398
|
+
});
|
|
399
|
+
}
|
|
400
|
+
if (value != null && typeof value === 'object' && !Array.isArray(value)) {
|
|
401
|
+
const schema = options.schema;
|
|
402
|
+
if (schema?.type) {
|
|
403
|
+
const handler = getFieldHandler(schema.type);
|
|
404
|
+
if (typeof handler?.isEmpty === 'function') {
|
|
405
|
+
const result = handler.isEmpty(value, schema);
|
|
406
|
+
if (typeof result === 'boolean') return result;
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
return isImageValueEmpty(value);
|
|
410
|
+
}
|
|
411
|
+
if (typeof value === 'string' && !stripFieldTokenCaretAnchors(value).trim()) {
|
|
412
|
+
return true;
|
|
413
|
+
}
|
|
414
|
+
if (options.htmlEditor && typeof value === 'string') {
|
|
415
|
+
return isHtmlValueEmpty(value);
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
const schema = options.schema;
|
|
419
|
+
if (schema?.type) {
|
|
420
|
+
const handler = getFieldHandler(schema.type);
|
|
421
|
+
if (typeof handler?.isEmpty === 'function') {
|
|
422
|
+
const result = handler.isEmpty(value, schema);
|
|
423
|
+
if (typeof result === 'boolean') return result;
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
return value == null || value === '' || (Array.isArray(value) && value.length === 0);
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
export function resolveComputedValue(fieldId: any, valuesMap: any, context: any) {
|
|
431
|
+
const registry = registryFrom(context);
|
|
432
|
+
const schemas = registry?.getFieldSchemas() ?? {};
|
|
433
|
+
const blocks = resolveBlocksFromContext(context);
|
|
434
|
+
return evaluateComputedField(fieldId, valuesMap ?? {}, schemas, { blocks });
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
/**
|
|
438
|
+
* In fill mode, empty fields use their schema default (e.g. current date when
|
|
439
|
+
* `defaultMode` is `today`). Design mode keeps empties so templates stay undated.
|
|
440
|
+
*/
|
|
441
|
+
export function resolveValueOrFillDefault(schema: any, currentValue: any, { designMode = false } = {}) {
|
|
442
|
+
if (designMode) {
|
|
443
|
+
return currentValue === undefined || currentValue === null ? '' : currentValue;
|
|
444
|
+
}
|
|
445
|
+
if (!isFieldEmpty(currentValue, { schema })) return currentValue;
|
|
446
|
+
if (!schema) return currentValue ?? '';
|
|
447
|
+
return resolveSchemaDefaultValue(schema, { forTemplate: false });
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
export function refreshComputedFields(container: any, valuesMap: any, options: any = {}) {
|
|
451
|
+
if (!container) return;
|
|
452
|
+
|
|
453
|
+
const registry = registryFrom(options) ?? getRegistryFromNode(container);
|
|
454
|
+
const schemas = registry?.getFieldSchemas() ?? {};
|
|
455
|
+
const blocks = options.blocks ?? registry?.getBlocks?.() ?? [];
|
|
456
|
+
const changedFieldId = options.changedFieldId;
|
|
457
|
+
const holder = resolveEditorHolder(container, options);
|
|
458
|
+
const evaluationValues = collectAllFieldValuesFromHolder(holder, valuesMap, options);
|
|
459
|
+
|
|
460
|
+
const holderSections = holder
|
|
461
|
+
? [...holder.querySelectorAll('.document-section__body')]
|
|
462
|
+
: [];
|
|
463
|
+
// Fall back to the local section when the holder query finds nothing (e.g. shadow DOM).
|
|
464
|
+
const containers = holderSections.length > 0 ? holderSections : [container];
|
|
465
|
+
|
|
466
|
+
for (const target of containers) {
|
|
467
|
+
target.querySelectorAll('.field-token').forEach((token: any) => {
|
|
468
|
+
const fieldId = token.dataset.fieldId;
|
|
469
|
+
const schema = schemas[fieldId];
|
|
470
|
+
if (schema?.type !== 'computed') return;
|
|
471
|
+
|
|
472
|
+
if (changedFieldId) {
|
|
473
|
+
const affected = computedFieldsAffectedByChange(changedFieldId, schemas, blocks);
|
|
474
|
+
if (!affected.has(fieldId)) return;
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
const { value, error } = evaluateComputedField(fieldId, evaluationValues, schemas, { blocks });
|
|
478
|
+
if (error) token.title = error;
|
|
479
|
+
else token.removeAttribute('title');
|
|
480
|
+
updateFieldToken(token, value, token.dataset.placeholder, fieldTokenUpdateContext(token, options, schemas));
|
|
481
|
+
});
|
|
482
|
+
|
|
483
|
+
ensureFieldTokenCaretAnchors(target);
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
/**
|
|
488
|
+
* Fill-mode: merge DOM + stored values, recalculate computed fields (same as preview),
|
|
489
|
+
* and push results onto tokens. Use after mapping / section render so Sub-Total etc.
|
|
490
|
+
* are not left blank until the user edits a field.
|
|
491
|
+
*/
|
|
492
|
+
export function syncFillComputedFields(container: any, valuesMap: any = {}, options: any = {}) {
|
|
493
|
+
if (!container) return { ...(valuesMap ?? {}) };
|
|
494
|
+
|
|
495
|
+
const registry = registryFrom(options) ?? getRegistryFromNode(container);
|
|
496
|
+
const schemas = registry?.getFieldSchemas() ?? {};
|
|
497
|
+
const blocks = options.blocks ?? registry?.getBlocks?.() ?? [];
|
|
498
|
+
const holder = resolveEditorHolder(container, options);
|
|
499
|
+
|
|
500
|
+
const merged = collectAllFieldValuesFromHolder(holder, valuesMap, options);
|
|
501
|
+
// Keep non-computed DOM/local values; recompute all computed (preview parity).
|
|
502
|
+
for (const [fieldId, schema] of Object.entries(schemas) as [string, { type?: string }][]) {
|
|
503
|
+
if (schema?.type === 'computed') delete merged[fieldId];
|
|
504
|
+
}
|
|
505
|
+
enrichComputedValues(merged, schemas, blocks);
|
|
506
|
+
|
|
507
|
+
const holderSections = holder
|
|
508
|
+
? [...holder.querySelectorAll('.document-section__body')]
|
|
509
|
+
: [];
|
|
510
|
+
const containers = holderSections.length > 0 ? holderSections : [container];
|
|
511
|
+
|
|
512
|
+
for (const target of containers) {
|
|
513
|
+
target.querySelectorAll('.field-token').forEach((token: any) => {
|
|
514
|
+
const fieldId = token.dataset.fieldId;
|
|
515
|
+
if (!fieldId || schemas[fieldId]?.type !== 'computed') return;
|
|
516
|
+
token.removeAttribute('title');
|
|
517
|
+
updateFieldToken(
|
|
518
|
+
token,
|
|
519
|
+
merged[fieldId] ?? '',
|
|
520
|
+
token.dataset.placeholder,
|
|
521
|
+
fieldTokenUpdateContext(token, options, schemas),
|
|
522
|
+
);
|
|
523
|
+
});
|
|
524
|
+
ensureFieldTokenCaretAnchors(target);
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
return merged;
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
export function createFieldToken(fieldId: any, value: any, placeholder: any, context?: any) {
|
|
531
|
+
const span = document.createElement('span');
|
|
532
|
+
span.className = 'field-token';
|
|
533
|
+
span.contentEditable = 'false';
|
|
534
|
+
span.spellcheck = false;
|
|
535
|
+
span.dataset.fieldId = fieldId;
|
|
536
|
+
if (placeholder) span.dataset.placeholder = placeholder;
|
|
537
|
+
|
|
538
|
+
updateFieldToken(span, value, placeholder, context);
|
|
539
|
+
return span;
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
/** Built-in default table column labels: "Column 1", "Column 2", … */
|
|
543
|
+
const DEFAULT_COLUMN_LABEL_RE = /^Column \d+$/i;
|
|
544
|
+
|
|
545
|
+
export function isTableCellDisplayPlaceholder(value: any, label: any) {
|
|
546
|
+
if (value == null || value === '') return true;
|
|
547
|
+
if (typeof value !== 'string') return false;
|
|
548
|
+
const trimmed = value.trim();
|
|
549
|
+
const normalized = String(label ?? '').trim();
|
|
550
|
+
if (normalized && trimmed === normalized) return true;
|
|
551
|
+
// After renaming default columns, "Column 1" can stick as a stored value while
|
|
552
|
+
// the header/label is already the real field name (e.g. "name").
|
|
553
|
+
if (DEFAULT_COLUMN_LABEL_RE.test(trimmed) && trimmed !== normalized) return true;
|
|
554
|
+
return false;
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
function isTableCellPlaceholderValue(token: any, value: any, placeholder: any) {
|
|
558
|
+
if (!token.classList.contains('field-token--cell')) return false;
|
|
559
|
+
return isTableCellDisplayPlaceholder(value, placeholder ?? token.dataset.placeholder);
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
function normalizeTableCellTokenValue(token: any, value: any, placeholder: any) {
|
|
563
|
+
if (!token.classList.contains('field-token--cell')) return value;
|
|
564
|
+
if (isTableCellPlaceholderValue(token, value, placeholder)) return '';
|
|
565
|
+
return value;
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
function fieldTokenUpdateContext(token: any, options: any = {}, schemas: any = {}) {
|
|
569
|
+
const isTableCell = token.classList.contains('field-token--cell');
|
|
570
|
+
return {
|
|
571
|
+
...options,
|
|
572
|
+
fieldSchemas: options.fieldSchemas ?? schemas,
|
|
573
|
+
isTableCell: options.isTableCell ?? isTableCell,
|
|
574
|
+
};
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
export function refreshTableCellTokens(root: any, context: any = {}) {
|
|
578
|
+
const scope = root?.querySelector ? root : document;
|
|
579
|
+
const registry = resolveRegistry(context);
|
|
580
|
+
const fieldSchemas =
|
|
581
|
+
context.fieldSchemas ?? registry?.getFieldSchemas?.() ?? {};
|
|
582
|
+
const cellContext = { ...context, fieldSchemas, isTableCell: true };
|
|
583
|
+
|
|
584
|
+
for (const token of scope.querySelectorAll('.field-token--cell')) {
|
|
585
|
+
const fieldId = token.dataset.fieldId;
|
|
586
|
+
if (!fieldId) continue;
|
|
587
|
+
// Computed cells are painted by syncFillComputedFields. Re-reading the
|
|
588
|
+
// formatted display (e.g. "$1,000.00") on EditorJS save restyles them.
|
|
589
|
+
if (
|
|
590
|
+
token.classList.contains('field-token--computed')
|
|
591
|
+
|| fieldSchemas[fieldId]?.type === 'computed'
|
|
592
|
+
) {
|
|
593
|
+
continue;
|
|
594
|
+
}
|
|
595
|
+
// Nested tokens inside a Child preview are not top-level document cells.
|
|
596
|
+
// Re-refreshing them (or rebuilding the parent Child from a half-read
|
|
597
|
+
// preview) wipes values just written by the Child modal.
|
|
598
|
+
const enclosingRepeater = token.closest('.field-token--repeater');
|
|
599
|
+
if (enclosingRepeater && enclosingRepeater !== token) continue;
|
|
600
|
+
|
|
601
|
+
// Child-in-cell: prefer the stored JSON over scraping the nested preview
|
|
602
|
+
// DOM (preview may omit empty cells / truncate during the post-save
|
|
603
|
+
// EditorJS save → refresh cycle).
|
|
604
|
+
const value = token.classList.contains('field-token--repeater')
|
|
605
|
+
? readRepeaterTokenDatasetValue(token)
|
|
606
|
+
: normalizeTableCellTokenValue(
|
|
607
|
+
token,
|
|
608
|
+
readTokenValue(token),
|
|
609
|
+
token.dataset.placeholder,
|
|
610
|
+
);
|
|
611
|
+
updateFieldToken(token, value, token.dataset.placeholder, cellContext);
|
|
612
|
+
}
|
|
613
|
+
pruneTableCellCaretAnchors(scope);
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
export function updateFieldToken(token: any, value: any, placeholder: any, context?: any) {
|
|
617
|
+
value = normalizeTableCellTokenValue(token, value, placeholder);
|
|
618
|
+
const fieldId = token.dataset.fieldId;
|
|
619
|
+
const registry = resolveRegistry(context) ?? getRegistryFromNode(token);
|
|
620
|
+
const registryCtx = registry
|
|
621
|
+
? {
|
|
622
|
+
getRegistry: () => registry,
|
|
623
|
+
fieldSchemas: context?.fieldSchemas,
|
|
624
|
+
fieldValueStyle: context?.fieldValueStyle,
|
|
625
|
+
hideEmptyValues: context?.hideEmptyValues,
|
|
626
|
+
previewMode: context?.previewMode,
|
|
627
|
+
}
|
|
628
|
+
: context ?? token;
|
|
629
|
+
const label = getFieldDisplayLabel(fieldId, placeholder ?? token.dataset.placeholder, registryCtx);
|
|
630
|
+
const def = resolveFieldDef(fieldId, registryCtx);
|
|
631
|
+
const schema = registry?.getFieldSchemas()?.[fieldId] ?? context?.fieldSchemas?.[fieldId];
|
|
632
|
+
if (schema?.type === 'text' && !def?.htmlEditor) {
|
|
633
|
+
value = sanitizeTextFieldValue(value);
|
|
634
|
+
}
|
|
635
|
+
token.dataset.placeholder = label;
|
|
636
|
+
|
|
637
|
+
// Keep the design grip (and its drag listeners) across content rebuilds.
|
|
638
|
+
const dragHandle = token.querySelector?.(':scope > .editor-drag-handle') ?? null;
|
|
639
|
+
if (dragHandle) dragHandle.remove();
|
|
640
|
+
|
|
641
|
+
token.textContent = '';
|
|
642
|
+
token.classList.remove(
|
|
643
|
+
'field-token--image',
|
|
644
|
+
'field-token--barcode',
|
|
645
|
+
'field-token--logical',
|
|
646
|
+
'field-token--logical-yes',
|
|
647
|
+
'field-token--logical-no',
|
|
648
|
+
'field-token--html',
|
|
649
|
+
'field-token--computed',
|
|
650
|
+
'field-token--readonly',
|
|
651
|
+
'field-token--repeater',
|
|
652
|
+
'field-token--required',
|
|
653
|
+
'field-token--required-missing',
|
|
654
|
+
);
|
|
655
|
+
token.style.removeProperty('--field-image-max-width');
|
|
656
|
+
if (token.dataset) delete token.dataset.maxWidth;
|
|
657
|
+
if (token.dataset) delete token.dataset.barcodeError;
|
|
658
|
+
|
|
659
|
+
if (def?.picker === 'computed') {
|
|
660
|
+
token.classList.add('field-token--computed');
|
|
661
|
+
} else if (
|
|
662
|
+
schema?.readonly ||
|
|
663
|
+
isTableCellInheritedReadonly(
|
|
664
|
+
fieldId,
|
|
665
|
+
registry?.getFieldSchemas?.() ?? context?.fieldSchemas,
|
|
666
|
+
)
|
|
667
|
+
) {
|
|
668
|
+
token.classList.add('field-token--readonly');
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
const emptyOptions = {
|
|
672
|
+
htmlEditor: !!def?.htmlEditor,
|
|
673
|
+
repeaterSchema: schema?.type === 'child' ? schema : undefined,
|
|
674
|
+
};
|
|
675
|
+
const isRequired = !!(def?.required ?? schema?.required);
|
|
676
|
+
// Fill/design: labels. Preview: blank for optional empties; required empties keep a placeholder.
|
|
677
|
+
const showEmptyPlaceholder = !context?.previewMode || isRequired;
|
|
678
|
+
|
|
679
|
+
if (schema?.type === 'child') {
|
|
680
|
+
token.classList.add('field-token--repeater');
|
|
681
|
+
const empty = isFieldEmpty(value, { repeaterSchema: schema });
|
|
682
|
+
const hasTemplate =
|
|
683
|
+
Object.keys(schema.fieldSchemas ?? {}).length > 0 || !!schema.template?.blocks?.length;
|
|
684
|
+
if (empty && showEmptyPlaceholder && !hasTemplate) {
|
|
685
|
+
token.textContent = label;
|
|
686
|
+
} else if (!empty || !context?.previewMode || hasTemplate) {
|
|
687
|
+
token.appendChild(renderRepeaterFieldPreview(fieldId, value, registryCtx));
|
|
688
|
+
}
|
|
689
|
+
// Optional empty preview tokens without a template stay blank.
|
|
690
|
+
} else if (def?.picker === 'image' || def?.picker === 'signature') {
|
|
691
|
+
const maxW = Number(def.maxWidth) > 0 ? Number(def.maxWidth) : 320;
|
|
692
|
+
token.style.setProperty('--field-image-max-width', `${maxW}px`);
|
|
693
|
+
token.dataset.maxWidth = String(maxW);
|
|
694
|
+
} else if (schema?.type === 'barcode' || def?.picker === 'barcode') {
|
|
695
|
+
const maxW = Number(schema?.maxWidth ?? def?.maxWidth) > 0
|
|
696
|
+
? Number(schema?.maxWidth ?? def?.maxWidth)
|
|
697
|
+
: 180;
|
|
698
|
+
token.style.setProperty('--field-image-max-width', `${maxW}px`);
|
|
699
|
+
token.dataset.maxWidth = String(maxW);
|
|
700
|
+
} else if (def?.picker === 'logical' || schema?.type === 'logical') {
|
|
701
|
+
token.classList.add('field-token--logical');
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
if (schema?.type === 'child') {
|
|
705
|
+
/* rendered above */
|
|
706
|
+
} else if (schema?.type === 'barcode' || def?.picker === 'barcode') {
|
|
707
|
+
const maxW = Number(schema?.maxWidth ?? def?.maxWidth) > 0
|
|
708
|
+
? Number(schema?.maxWidth ?? def?.maxWidth)
|
|
709
|
+
: 180;
|
|
710
|
+
const code = value == null || value === '' ? '' : String(value);
|
|
711
|
+
token.classList.add('field-token--barcode');
|
|
712
|
+
if (!code) {
|
|
713
|
+
if (showEmptyPlaceholder) token.textContent = label;
|
|
714
|
+
} else {
|
|
715
|
+
const encoded = encodeBarcodeToDataUrl(code, {
|
|
716
|
+
symbology: schema?.symbology ?? def?.symbology ?? 'code128',
|
|
717
|
+
maxWidth: maxW,
|
|
718
|
+
height: schema?.height ?? def?.height ?? 10,
|
|
719
|
+
displayValue: schema?.displayValue !== false && def?.displayValue !== false,
|
|
720
|
+
quietZone: schema?.quietZone !== false && def?.quietZone !== false,
|
|
721
|
+
});
|
|
722
|
+
if (encoded.dataUrl) {
|
|
723
|
+
token.classList.add('field-token--image');
|
|
724
|
+
const thumb = document.createElement('img');
|
|
725
|
+
thumb.className = 'field-token__thumb';
|
|
726
|
+
thumb.draggable = false;
|
|
727
|
+
thumb.src = encoded.dataUrl;
|
|
728
|
+
thumb.alt = code;
|
|
729
|
+
thumb.setAttribute('width', String(maxW));
|
|
730
|
+
thumb.style.maxWidth = `${maxW}px`;
|
|
731
|
+
thumb.style.width = `${maxW}px`;
|
|
732
|
+
thumb.style.height = 'auto';
|
|
733
|
+
token.appendChild(thumb);
|
|
734
|
+
} else {
|
|
735
|
+
token.dataset.barcodeError = encoded.error || 'Invalid barcode';
|
|
736
|
+
token.textContent = code;
|
|
737
|
+
const err = document.createElement('span');
|
|
738
|
+
err.className = 'field-token__barcode-error';
|
|
739
|
+
err.textContent = encoded.error || 'Invalid barcode';
|
|
740
|
+
token.appendChild(err);
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
} else if (
|
|
744
|
+
(def?.picker === 'image' || def?.picker === 'signature') &&
|
|
745
|
+
!isImageValueEmpty(value)
|
|
746
|
+
) {
|
|
747
|
+
const imgVal = normalizeImageValue(value);
|
|
748
|
+
rememberLiveImageValue(fieldId, imgVal);
|
|
749
|
+
token.classList.add('field-token--image');
|
|
750
|
+
const maxW = Number(def.maxWidth) > 0 ? Number(def.maxWidth) : 320;
|
|
751
|
+
const thumb = document.createElement('img');
|
|
752
|
+
thumb.className = 'field-token__thumb';
|
|
753
|
+
thumb.draggable = false;
|
|
754
|
+
thumb.src = imgVal.url;
|
|
755
|
+
thumb.alt = imgVal.caption || def.altText || label;
|
|
756
|
+
// Explicit width helps Salesforce Blob.toPdf (ignores CSS max-width).
|
|
757
|
+
thumb.setAttribute('width', String(maxW));
|
|
758
|
+
thumb.style.maxWidth = `${maxW}px`;
|
|
759
|
+
thumb.style.width = `${maxW}px`;
|
|
760
|
+
thumb.style.height = 'auto';
|
|
761
|
+
token.appendChild(thumb);
|
|
762
|
+
if (imgVal.caption) {
|
|
763
|
+
const cap = document.createElement('span');
|
|
764
|
+
cap.className = 'field-token__caption';
|
|
765
|
+
cap.textContent = imgVal.caption;
|
|
766
|
+
token.appendChild(cap);
|
|
767
|
+
}
|
|
768
|
+
} else if (
|
|
769
|
+
(def?.picker === 'image' || def?.picker === 'signature') &&
|
|
770
|
+
isImageValueEmpty(value)
|
|
771
|
+
) {
|
|
772
|
+
rememberLiveImageValue(fieldId, null);
|
|
773
|
+
// Design/fill: show the field label so an empty Image token is visible and selectable.
|
|
774
|
+
// Preview: keep optional empties blank (required empties still get a placeholder).
|
|
775
|
+
if (showEmptyPlaceholder) {
|
|
776
|
+
token.textContent = label;
|
|
777
|
+
}
|
|
778
|
+
} else if (def?.picker === 'logical' || schema?.type === 'logical') {
|
|
779
|
+
const empty = isFieldEmpty(value, { schema });
|
|
780
|
+
token.classList.add('field-token--logical');
|
|
781
|
+
if (empty && showEmptyPlaceholder) {
|
|
782
|
+
token.textContent = label;
|
|
783
|
+
} else if (!empty) {
|
|
784
|
+
if (value === true) {
|
|
785
|
+
token.classList.add('field-token--logical-yes');
|
|
786
|
+
} else {
|
|
787
|
+
token.classList.add('field-token--logical-no');
|
|
788
|
+
}
|
|
789
|
+
token.textContent = formatLogicalTokenDisplay(
|
|
790
|
+
value === true,
|
|
791
|
+
def?.trueMark ?? schema?.trueMark,
|
|
792
|
+
);
|
|
793
|
+
}
|
|
794
|
+
} else if (def?.htmlEditor) {
|
|
795
|
+
token.classList.add('field-token--html');
|
|
796
|
+
value = normalizeHtmlEditorValue(value);
|
|
797
|
+
const empty = isFieldEmpty(value, { htmlEditor: true });
|
|
798
|
+
if (empty) {
|
|
799
|
+
if (showEmptyPlaceholder) {
|
|
800
|
+
token.textContent = label;
|
|
801
|
+
}
|
|
802
|
+
} else {
|
|
803
|
+
appendHtmlToFragment(token, String(value));
|
|
804
|
+
}
|
|
805
|
+
} else {
|
|
806
|
+
const empty = isFieldEmpty(value, { htmlEditor: false });
|
|
807
|
+
if (!empty) {
|
|
808
|
+
const display = formatFieldDisplay(fieldId, value, placeholder ?? token.dataset.placeholder, registryCtx);
|
|
809
|
+
// Use <br> for newlines so Preview/PDF match the textarea even when CSS
|
|
810
|
+
// white-space is not pre-wrap on the token.
|
|
811
|
+
token.appendChild(textToFragment(String(display)));
|
|
812
|
+
} else if (showEmptyPlaceholder) {
|
|
813
|
+
token.textContent = label;
|
|
814
|
+
}
|
|
815
|
+
}
|
|
816
|
+
|
|
817
|
+
if (isFieldEmpty(value, emptyOptions)) {
|
|
818
|
+
token.classList.add('field-token--empty');
|
|
819
|
+
} else {
|
|
820
|
+
token.classList.remove('field-token--empty');
|
|
821
|
+
}
|
|
822
|
+
|
|
823
|
+
const missing = isRequired && isFieldEmpty(value, emptyOptions);
|
|
824
|
+
token.classList.toggle('field-token--required', isRequired);
|
|
825
|
+
token.classList.toggle('field-token--required-missing', missing);
|
|
826
|
+
|
|
827
|
+
writeTokenDatasetValue(token, value);
|
|
828
|
+
|
|
829
|
+
const isTableCell =
|
|
830
|
+
context?.isTableCell ?? token.classList.contains('field-token--cell');
|
|
831
|
+
const fieldSchemas =
|
|
832
|
+
context?.fieldSchemas ?? registry?.getFieldSchemas?.() ?? {};
|
|
833
|
+
if (isTableCell) {
|
|
834
|
+
applyTableCellDisplayStyle(token, fieldId, schema, fieldSchemas, context);
|
|
835
|
+
} else {
|
|
836
|
+
const displayStyle = resolveTokenDisplayStyle(
|
|
837
|
+
schema,
|
|
838
|
+
context?.fieldValueStyle?.default,
|
|
839
|
+
false,
|
|
840
|
+
context?.fieldValueStyle,
|
|
841
|
+
context,
|
|
842
|
+
token,
|
|
843
|
+
);
|
|
844
|
+
applyFieldDisplayStyle(token, displayStyle);
|
|
845
|
+
}
|
|
846
|
+
clearFieldHighlightOverriddenStyles(token, context);
|
|
847
|
+
if (dragHandle) {
|
|
848
|
+
token.insertBefore(dragHandle, token.firstChild);
|
|
849
|
+
}
|
|
850
|
+
if (token.classList.contains('field-token--cell')) {
|
|
851
|
+
pruneTableCellCaretAnchors(token.closest('.vision-table') ?? token.parentElement);
|
|
852
|
+
} else {
|
|
853
|
+
ensureCaretAnchorAfter(token);
|
|
854
|
+
}
|
|
855
|
+
}
|
|
856
|
+
|
|
857
|
+
export function readRepeaterTokenValue(token: any) {
|
|
858
|
+
const raw = readRepeaterTokenDatasetValue(token);
|
|
859
|
+
// Inline Child previews are display-only (edits go through the modal).
|
|
860
|
+
// Prefer the stored JSON over scraping nested tokens — the preview often
|
|
861
|
+
// omits empty cells and was the source of post-save value loss.
|
|
862
|
+
if (Object.keys(raw).length > 0) return raw;
|
|
863
|
+
|
|
864
|
+
const previewRoot = token.querySelector('.field-token__repeater-preview');
|
|
865
|
+
if (!previewRoot) return raw;
|
|
866
|
+
|
|
867
|
+
const repeaterFieldId = token.dataset.fieldId;
|
|
868
|
+
const registry = getRegistryFromNode(token);
|
|
869
|
+
const schema = registry?.getFieldSchemas()?.[repeaterFieldId];
|
|
870
|
+
if (!schema || schema.type !== 'child') return raw;
|
|
871
|
+
|
|
872
|
+
const domValues: Record<string, any> = {};
|
|
873
|
+
previewRoot.querySelectorAll('.field-token').forEach((childToken: any) => {
|
|
874
|
+
if (childToken.classList.contains('field-token--repeater')) return;
|
|
875
|
+
const childId = childToken.dataset.fieldId;
|
|
876
|
+
if (!childId) return;
|
|
877
|
+
const nested = normalizeTableCellTokenValue(
|
|
878
|
+
childToken,
|
|
879
|
+
readTokenValue(childToken),
|
|
880
|
+
childToken.dataset.placeholder,
|
|
881
|
+
);
|
|
882
|
+
// Skip blank nested tokens so they don't erase dataset values for sibling columns.
|
|
883
|
+
if (nested == null || nested === '') return;
|
|
884
|
+
domValues[childId] = nested;
|
|
885
|
+
});
|
|
886
|
+
|
|
887
|
+
if (!Object.keys(domValues).length) return raw;
|
|
888
|
+
return mergeRepeaterDomValues(raw, domValues, schema);
|
|
889
|
+
}
|
|
890
|
+
|
|
891
|
+
function readRepeaterTokenDatasetValue(token: any) {
|
|
892
|
+
const raw = token.dataset.value;
|
|
893
|
+
if (raw != null && raw !== '') {
|
|
894
|
+
if (raw.startsWith('{') || raw.startsWith('[')) {
|
|
895
|
+
try {
|
|
896
|
+
const parsed = JSON.parse(raw);
|
|
897
|
+
if (parsed && typeof parsed === 'object' && !Array.isArray(parsed)) {
|
|
898
|
+
return parsed;
|
|
899
|
+
}
|
|
900
|
+
} catch {
|
|
901
|
+
/* fall through */
|
|
902
|
+
}
|
|
903
|
+
}
|
|
904
|
+
}
|
|
905
|
+
return {};
|
|
906
|
+
}
|
|
907
|
+
|
|
908
|
+
/**
|
|
909
|
+
* Large data:/blob: image URLs exceed DOM/LWS data-attribute limits and throw.
|
|
910
|
+
* Keep the real URL on the live <img> (and section fieldValues); dataset stores a compact stub.
|
|
911
|
+
*/
|
|
912
|
+
const DATASET_URL_MAX_CHARS = 2048;
|
|
913
|
+
|
|
914
|
+
/** fieldId → last known image value (survives empty data-value stubs during save/preview). */
|
|
915
|
+
const liveImageValuesByFieldId = new Map();
|
|
916
|
+
|
|
917
|
+
function isEmbeddedImageDatasetStub(value: any) {
|
|
918
|
+
return !!(
|
|
919
|
+
value &&
|
|
920
|
+
typeof value === 'object' &&
|
|
921
|
+
!Array.isArray(value) &&
|
|
922
|
+
value.embedded === true &&
|
|
923
|
+
typeof value.url === 'string'
|
|
924
|
+
);
|
|
925
|
+
}
|
|
926
|
+
|
|
927
|
+
function readImageUrlFromToken(token: any) {
|
|
928
|
+
const img = token?.querySelector?.('img.field-token__thumb');
|
|
929
|
+
if (!img) return '';
|
|
930
|
+
const src = String(img.getAttribute('src') || img.src || '').trim();
|
|
931
|
+
if (!src || src.startsWith('about:')) return '';
|
|
932
|
+
return src;
|
|
933
|
+
}
|
|
934
|
+
|
|
935
|
+
function rememberLiveImageValue(fieldId: any, value: any) {
|
|
936
|
+
if (!fieldId) return;
|
|
937
|
+
if (isImageValueEmpty(value)) {
|
|
938
|
+
liveImageValuesByFieldId.delete(fieldId);
|
|
939
|
+
return;
|
|
940
|
+
}
|
|
941
|
+
liveImageValuesByFieldId.set(fieldId, normalizeImageValue(value));
|
|
942
|
+
}
|
|
943
|
+
|
|
944
|
+
function resolveImageValueFromToken(token: any, parsed: any = null) {
|
|
945
|
+
const fieldId = token?.dataset?.fieldId;
|
|
946
|
+
const caption = parsed?.caption ?? '';
|
|
947
|
+
const fromImg = readImageUrlFromToken(token);
|
|
948
|
+
if (fromImg) {
|
|
949
|
+
const value = { url: fromImg, caption };
|
|
950
|
+
rememberLiveImageValue(fieldId, value);
|
|
951
|
+
return value;
|
|
952
|
+
}
|
|
953
|
+
const fromMemory = fieldId ? liveImageValuesByFieldId.get(fieldId) : null;
|
|
954
|
+
if (fromMemory && !isImageValueEmpty(fromMemory)) {
|
|
955
|
+
return {
|
|
956
|
+
url: fromMemory.url,
|
|
957
|
+
caption: caption || fromMemory.caption || '',
|
|
958
|
+
};
|
|
959
|
+
}
|
|
960
|
+
return { url: '', caption };
|
|
961
|
+
}
|
|
962
|
+
|
|
963
|
+
/**
|
|
964
|
+
* Fill empty/stub image fieldValues from live thumbs (and the in-memory map).
|
|
965
|
+
* Call after DOM extract / editor.save so HTML preview keeps uploaded images.
|
|
966
|
+
*/
|
|
967
|
+
export function recoverImageValuesFromDom(container: any, fieldValues: any = {}) {
|
|
968
|
+
const next = fieldValues && typeof fieldValues === 'object' ? fieldValues : {};
|
|
969
|
+
if (!container?.querySelectorAll) {
|
|
970
|
+
for (const [fieldId, value] of liveImageValuesByFieldId.entries()) {
|
|
971
|
+
if (isImageValueEmpty(next[fieldId])) next[fieldId] = { ...value };
|
|
972
|
+
}
|
|
973
|
+
return next;
|
|
974
|
+
}
|
|
975
|
+
|
|
976
|
+
container.querySelectorAll('.field-token').forEach((token: any) => {
|
|
977
|
+
const fieldId = token.dataset?.fieldId;
|
|
978
|
+
if (!fieldId) return;
|
|
979
|
+
const hasImageUi =
|
|
980
|
+
token.classList.contains('field-token--image') || !!token.querySelector('img.field-token__thumb');
|
|
981
|
+
if (!hasImageUi && !liveImageValuesByFieldId.has(fieldId)) return;
|
|
982
|
+
|
|
983
|
+
const recovered = resolveImageValueFromToken(token, normalizeImageValue(next[fieldId]));
|
|
984
|
+
if (!isImageValueEmpty(recovered) && isImageValueEmpty(next[fieldId])) {
|
|
985
|
+
next[fieldId] = recovered;
|
|
986
|
+
} else if (!isImageValueEmpty(recovered)) {
|
|
987
|
+
rememberLiveImageValue(fieldId, recovered);
|
|
988
|
+
if (isImageValueEmpty(next[fieldId])) next[fieldId] = recovered;
|
|
989
|
+
}
|
|
990
|
+
});
|
|
991
|
+
|
|
992
|
+
for (const [fieldId, value] of liveImageValuesByFieldId.entries()) {
|
|
993
|
+
if (isImageValueEmpty(next[fieldId])) next[fieldId] = { ...value };
|
|
994
|
+
}
|
|
995
|
+
return next;
|
|
996
|
+
}
|
|
997
|
+
|
|
998
|
+
function toDatasetFieldValue(value: any) {
|
|
999
|
+
if (value != null && typeof value === 'object' && !Array.isArray(value) && typeof value.url === 'string') {
|
|
1000
|
+
const url = String(value.url ?? '');
|
|
1001
|
+
if (url.startsWith('data:') || url.startsWith('blob:') || url.length > DATASET_URL_MAX_CHARS) {
|
|
1002
|
+
return JSON.stringify({
|
|
1003
|
+
url: '',
|
|
1004
|
+
caption: value.caption ?? '',
|
|
1005
|
+
embedded: true,
|
|
1006
|
+
});
|
|
1007
|
+
}
|
|
1008
|
+
}
|
|
1009
|
+
if (value != null && typeof value === 'object') {
|
|
1010
|
+
return JSON.stringify(value);
|
|
1011
|
+
}
|
|
1012
|
+
if (Array.isArray(value)) {
|
|
1013
|
+
return JSON.stringify(value);
|
|
1014
|
+
}
|
|
1015
|
+
return String(value ?? '');
|
|
1016
|
+
}
|
|
1017
|
+
|
|
1018
|
+
function writeTokenDatasetValue(token: any, value: any) {
|
|
1019
|
+
try {
|
|
1020
|
+
// Normalize newline codes right before we persist the value into `data-value`.
|
|
1021
|
+
// This covers cases where value sanitization happens in some render paths
|
|
1022
|
+
// but downstream code (export / source view) relies on dataset storage.
|
|
1023
|
+
if (typeof value === 'string') {
|
|
1024
|
+
if (token.classList?.contains('field-token--html')) {
|
|
1025
|
+
value = normalizeHtmlEditorValue(value);
|
|
1026
|
+
} else {
|
|
1027
|
+
value = sanitizeTextFieldValue(value);
|
|
1028
|
+
}
|
|
1029
|
+
}
|
|
1030
|
+
token.dataset.value = toDatasetFieldValue(value);
|
|
1031
|
+
} catch (err) {
|
|
1032
|
+
try {
|
|
1033
|
+
delete token.dataset.value;
|
|
1034
|
+
} catch {
|
|
1035
|
+
/* ignore */
|
|
1036
|
+
}
|
|
1037
|
+
console.warn('[docengine] Could not store field value on token dataset', err);
|
|
1038
|
+
}
|
|
1039
|
+
}
|
|
1040
|
+
|
|
1041
|
+
export function readTokenValue(token: any) {
|
|
1042
|
+
if (token.classList.contains('field-token--repeater')) {
|
|
1043
|
+
return readRepeaterTokenValue(token);
|
|
1044
|
+
}
|
|
1045
|
+
|
|
1046
|
+
const raw = token.dataset.value;
|
|
1047
|
+
if (!raw && raw !== '0') {
|
|
1048
|
+
if (token.classList.contains('field-token--image') || token.querySelector?.('img.field-token__thumb')) {
|
|
1049
|
+
return resolveImageValueFromToken(token);
|
|
1050
|
+
}
|
|
1051
|
+
if (token.classList.contains('field-token--empty')) return '';
|
|
1052
|
+
const text = normalizeScalarTokenValue(readFieldTokenVisibleText(token).replace(/×$/, '').trim());
|
|
1053
|
+
if (isTableCellPlaceholderValue(token, text, token.dataset.placeholder)) return '';
|
|
1054
|
+
return text;
|
|
1055
|
+
}
|
|
1056
|
+
|
|
1057
|
+
if (
|
|
1058
|
+
typeof raw === 'string' &&
|
|
1059
|
+
hasSuspiciousEncodingArtifacts(raw) &&
|
|
1060
|
+
!raw.startsWith('{') &&
|
|
1061
|
+
!raw.startsWith('[')
|
|
1062
|
+
) {
|
|
1063
|
+
const visible = normalizeScalarTokenValue(readFieldTokenVisibleText(token).replace(/×$/, '').trim());
|
|
1064
|
+
if (
|
|
1065
|
+
typeof visible === 'string' &&
|
|
1066
|
+
visible &&
|
|
1067
|
+
!hasSuspiciousEncodingArtifacts(visible)
|
|
1068
|
+
) {
|
|
1069
|
+
if (isTableCellPlaceholderValue(token, visible, token.dataset.placeholder)) return '';
|
|
1070
|
+
return visible;
|
|
1071
|
+
}
|
|
1072
|
+
}
|
|
1073
|
+
|
|
1074
|
+
if (raw.startsWith('[') || raw.startsWith('{')) {
|
|
1075
|
+
try {
|
|
1076
|
+
const parsed = JSON.parse(raw);
|
|
1077
|
+
// Compact stub — recover real URL from live <img> / memory.
|
|
1078
|
+
if (
|
|
1079
|
+
isEmbeddedImageDatasetStub(parsed) ||
|
|
1080
|
+
(token.classList.contains('field-token--image') && isImageValueEmpty(parsed))
|
|
1081
|
+
) {
|
|
1082
|
+
return resolveImageValueFromToken(token, parsed);
|
|
1083
|
+
}
|
|
1084
|
+
return parsed;
|
|
1085
|
+
} catch {
|
|
1086
|
+
return normalizeScalarTokenValue(raw);
|
|
1087
|
+
}
|
|
1088
|
+
}
|
|
1089
|
+
|
|
1090
|
+
return normalizeScalarTokenValue(raw);
|
|
1091
|
+
}
|
|
1092
|
+
|
|
1093
|
+
/**
|
|
1094
|
+
* Find a connected field token after async work that may have reinited the editor.
|
|
1095
|
+
* @param {string} fieldId
|
|
1096
|
+
* @param {ParentNode | null | undefined} root
|
|
1097
|
+
* @returns {HTMLElement | null}
|
|
1098
|
+
*/
|
|
1099
|
+
export function findLiveFieldToken(fieldId: any, root: any) {
|
|
1100
|
+
if (!fieldId || !root?.querySelector) return null;
|
|
1101
|
+
try {
|
|
1102
|
+
return root.querySelector(`.field-token[data-field-id="${CSS.escape(fieldId)}"]`);
|
|
1103
|
+
} catch {
|
|
1104
|
+
return null;
|
|
1105
|
+
}
|
|
1106
|
+
}
|
|
1107
|
+
|
|
1108
|
+
function normalizeScalarTokenValue(value: any) {
|
|
1109
|
+
if (typeof value !== 'string') return value;
|
|
1110
|
+
return stripFieldTokenCaretAnchors(value);
|
|
1111
|
+
}
|
|
1112
|
+
|
|
1113
|
+
function hasSuspiciousEncodingArtifacts(value: any) {
|
|
1114
|
+
if (typeof value !== 'string') return false;
|
|
1115
|
+
return value.includes('\uFFFD') || /Ã.|Â.|�/.test(value);
|
|
1116
|
+
}
|
|
1117
|
+
|
|
1118
|
+
/**
|
|
1119
|
+
* Normalize plain-text field values. Preserve real line breaks (textarea Enter);
|
|
1120
|
+
* turn JSON-escaped "\\n" / "\\r" into real newlines. Do not strip breaks —
|
|
1121
|
+
* that collapsed multi-line Text picker input into a single line in the document.
|
|
1122
|
+
*/
|
|
1123
|
+
function sanitizeTextFieldValue(value: any) {
|
|
1124
|
+
if (typeof value !== 'string') return value;
|
|
1125
|
+
return value
|
|
1126
|
+
.replace(/\\r\\n/g, '\n')
|
|
1127
|
+
.replace(/\\n\\r/g, '\n')
|
|
1128
|
+
.replace(/\\r/g, '\n')
|
|
1129
|
+
.replace(/\\n/g, '\n')
|
|
1130
|
+
.replace(/\r\n/g, '\n')
|
|
1131
|
+
.replace(/\r/g, '\n');
|
|
1132
|
+
}
|
|
1133
|
+
|
|
1134
|
+
function normalizeHtmlEditorValue(value: any) {
|
|
1135
|
+
if (typeof value !== 'string') return value;
|
|
1136
|
+
// Normalize escaped newline pairs first so \n\r or \r\n becomes a single break.
|
|
1137
|
+
let out = value
|
|
1138
|
+
.replace(/\\r\\n/g, '\n')
|
|
1139
|
+
.replace(/\\n\\r/g, '\n')
|
|
1140
|
+
.replace(/\\r/g, '\n')
|
|
1141
|
+
.replace(/\\n/g, '\n');
|
|
1142
|
+
|
|
1143
|
+
// If it looks like authored HTML, don't add additional <br> for *real* CR/LF
|
|
1144
|
+
// that may exist as formatting whitespace.
|
|
1145
|
+
if (/<\/?[a-z][\s\S]*>/i.test(out)) {
|
|
1146
|
+
return out.replace(/\r\n/g, '\n').replace(/\r/g, '\n');
|
|
1147
|
+
}
|
|
1148
|
+
|
|
1149
|
+
// Plain text: convert real CR/LF to <br>.
|
|
1150
|
+
out = out.replace(/\r\n/g, '\n').replace(/\n\r/g, '\n').replace(/\r/g, '\n');
|
|
1151
|
+
return out.replace(/\n/g, '<br>');
|
|
1152
|
+
}
|
|
1153
|
+
|
|
1154
|
+
export function textToFragment(text: any) {
|
|
1155
|
+
const fragment = document.createDocumentFragment();
|
|
1156
|
+
const parts = String(text).split('\n');
|
|
1157
|
+
|
|
1158
|
+
parts.forEach((part: any, i: any) => {
|
|
1159
|
+
if (part) fragment.appendChild(document.createTextNode(part));
|
|
1160
|
+
if (i < parts.length - 1) fragment.appendChild(document.createElement('br'));
|
|
1161
|
+
});
|
|
1162
|
+
|
|
1163
|
+
return fragment;
|
|
1164
|
+
}
|
|
1165
|
+
|
|
1166
|
+
export function renderSegmentsToDom(segments: any, fieldValues: any, options: any = {}) {
|
|
1167
|
+
const fragment = document.createDocumentFragment();
|
|
1168
|
+
renderSegmentListInto(fragment, segments, fieldValues, options);
|
|
1169
|
+
return fragment;
|
|
1170
|
+
}
|
|
1171
|
+
|
|
1172
|
+
function alignmentDivHasContent(div: any) {
|
|
1173
|
+
const text = (div.textContent ?? '').replace(/\u200B/g, '').trim();
|
|
1174
|
+
if (text) return true;
|
|
1175
|
+
return !!div.querySelector('img, table, ul, ol, li');
|
|
1176
|
+
}
|
|
1177
|
+
|
|
1178
|
+
function renderSegmentListInto(parent: any, segments: any, fieldValues: any, options: any = {}) {
|
|
1179
|
+
const { designMode, previewMode, onEditSchema, onDeleteField, designPropertiesPanel } = options;
|
|
1180
|
+
// Preview may carry the previous section's table so a Totals columns block
|
|
1181
|
+
// in the next section can still sync to that table's last-column split.
|
|
1182
|
+
let lastTableSegForColumns: any = options.lastTableSegForColumns ?? null;
|
|
1183
|
+
|
|
1184
|
+
function renderSegmentInto(target: any, seg: any) {
|
|
1185
|
+
if (seg.type === 'text') {
|
|
1186
|
+
if (seg.html) {
|
|
1187
|
+
appendHtmlToFragment(target, seg.html);
|
|
1188
|
+
} else {
|
|
1189
|
+
target.appendChild(textToFragment(seg.content ?? ''));
|
|
1190
|
+
}
|
|
1191
|
+
return;
|
|
1192
|
+
}
|
|
1193
|
+
|
|
1194
|
+
if (seg.type === 'columns') {
|
|
1195
|
+
const useTableFallbackWidths = !!previewMode
|
|
1196
|
+
&& !!lastTableSegForColumns
|
|
1197
|
+
&& isTwoColumnSegment(seg)
|
|
1198
|
+
&& (
|
|
1199
|
+
columnsNeedAutoWidths(seg) ||
|
|
1200
|
+
columnsHaveDefaultEvenSplit(seg.widths) ||
|
|
1201
|
+
Array.isArray(seg.widths)
|
|
1202
|
+
);
|
|
1203
|
+
const fallbackWidths = useTableFallbackWidths
|
|
1204
|
+
? deriveColumnsWidthsFromTableSeg(lastTableSegForColumns, options)
|
|
1205
|
+
: null;
|
|
1206
|
+
const columnsSeg = fallbackWidths
|
|
1207
|
+
? { ...seg, widths: fallbackWidths }
|
|
1208
|
+
: seg;
|
|
1209
|
+
target.appendChild(renderColumnsSegment(columnsSeg, fieldValues, options));
|
|
1210
|
+
lastTableSegForColumns = null;
|
|
1211
|
+
return;
|
|
1212
|
+
}
|
|
1213
|
+
|
|
1214
|
+
if (seg.type === 'table') {
|
|
1215
|
+
target.appendChild(renderTableSegment(seg, fieldValues, options));
|
|
1216
|
+
lastTableSegForColumns = seg;
|
|
1217
|
+
return;
|
|
1218
|
+
}
|
|
1219
|
+
|
|
1220
|
+
if ((seg.type === 'field' || seg.type === 'child') && seg.id) {
|
|
1221
|
+
const registry = resolveRegistry(options);
|
|
1222
|
+
const schema =
|
|
1223
|
+
registry?.getFieldSchemas()?.[seg.id] ??
|
|
1224
|
+
options.fieldSchemas?.[seg.id];
|
|
1225
|
+
let value = fieldValues[seg.id];
|
|
1226
|
+
if (value === undefined && schema?.type === 'child') {
|
|
1227
|
+
value = createInlineRepeaterSeedValue(schema);
|
|
1228
|
+
fieldValues[seg.id] = value;
|
|
1229
|
+
} else if (schema?.type === 'computed' && !designMode) {
|
|
1230
|
+
const schemas = registry?.getFieldSchemas() ?? options.fieldSchemas ?? {};
|
|
1231
|
+
const blocks = resolveBlocksFromContext(options);
|
|
1232
|
+
value = evaluateComputedField(seg.id, fieldValues, schemas, { blocks }).value;
|
|
1233
|
+
fieldValues[seg.id] = value;
|
|
1234
|
+
} else {
|
|
1235
|
+
const filled = resolveValueOrFillDefault(schema, value, {
|
|
1236
|
+
designMode: !!designMode,
|
|
1237
|
+
});
|
|
1238
|
+
if (filled !== value && !isFieldEmpty(filled, { schema })) {
|
|
1239
|
+
fieldValues[seg.id] = filled;
|
|
1240
|
+
}
|
|
1241
|
+
value = filled ?? '';
|
|
1242
|
+
}
|
|
1243
|
+
const def = resolveFieldDef(seg.id, options);
|
|
1244
|
+
const emptyOpts = {
|
|
1245
|
+
htmlEditor: !!def?.htmlEditor,
|
|
1246
|
+
repeaterSchema: schema?.type === 'child' ? schema : undefined,
|
|
1247
|
+
};
|
|
1248
|
+
const isRequired = !!(def?.required ?? schema?.required);
|
|
1249
|
+
// Optional empties can be omitted; required empties always render with a placeholder.
|
|
1250
|
+
if (
|
|
1251
|
+
previewMode &&
|
|
1252
|
+
options.hideEmptyValues === true &&
|
|
1253
|
+
!isRequired &&
|
|
1254
|
+
isFieldEmpty(value, emptyOpts)
|
|
1255
|
+
) {
|
|
1256
|
+
return;
|
|
1257
|
+
}
|
|
1258
|
+
const label = getFieldDisplayLabel(seg.id, seg.placeholder, options);
|
|
1259
|
+
const token = createFieldToken(seg.id, value, label, options);
|
|
1260
|
+
if (previewMode) {
|
|
1261
|
+
token.classList.add('field-token--preview');
|
|
1262
|
+
} else if (designMode) {
|
|
1263
|
+
token.classList.add('field-token--design');
|
|
1264
|
+
attachDesignToken(token, seg.id, { onEditSchema, onDeleteField, designPropertiesPanel });
|
|
1265
|
+
}
|
|
1266
|
+
target.appendChild(token);
|
|
1267
|
+
if (!previewMode) {
|
|
1268
|
+
updateFieldToken(token, value, label, options);
|
|
1269
|
+
}
|
|
1270
|
+
ensureCaretAnchorAfter(token);
|
|
1271
|
+
lastTableSegForColumns = null;
|
|
1272
|
+
return;
|
|
1273
|
+
}
|
|
1274
|
+
|
|
1275
|
+
lastTableSegForColumns = null;
|
|
1276
|
+
}
|
|
1277
|
+
|
|
1278
|
+
let i = 0;
|
|
1279
|
+
while (i < segments.length) {
|
|
1280
|
+
const align = segments[i].align ?? null;
|
|
1281
|
+
let j = i + 1;
|
|
1282
|
+
while (j < segments.length && (segments[j].align ?? null) === align) {
|
|
1283
|
+
j += 1;
|
|
1284
|
+
}
|
|
1285
|
+
|
|
1286
|
+
const group = segments.slice(i, j);
|
|
1287
|
+
if (align) {
|
|
1288
|
+
const div = document.createElement('div');
|
|
1289
|
+
div.className = `document-align document-align--${align}`;
|
|
1290
|
+
div.style.textAlign = align;
|
|
1291
|
+
for (const seg of group) renderSegmentInto(div, seg);
|
|
1292
|
+
if (alignmentDivHasContent(div)) {
|
|
1293
|
+
parent.appendChild(div);
|
|
1294
|
+
}
|
|
1295
|
+
} else {
|
|
1296
|
+
for (const seg of group) renderSegmentInto(parent, seg);
|
|
1297
|
+
}
|
|
1298
|
+
i = j;
|
|
1299
|
+
}
|
|
1300
|
+
|
|
1301
|
+
if (typeof options.onLastTableSegForColumns === 'function') {
|
|
1302
|
+
options.onLastTableSegForColumns(lastTableSegForColumns);
|
|
1303
|
+
}
|
|
1304
|
+
|
|
1305
|
+
return parent;
|
|
1306
|
+
}
|
|
1307
|
+
|
|
1308
|
+
function renderColumnsSegment(seg: any, fieldValues: any, options: any = {}) {
|
|
1309
|
+
const { designMode, previewMode } = options;
|
|
1310
|
+
const wrapper = document.createElement('div');
|
|
1311
|
+
wrapper.className = 'document-columns';
|
|
1312
|
+
wrapper.contentEditable = 'false';
|
|
1313
|
+
const columnsId = seg.id ?? createColumnsId();
|
|
1314
|
+
wrapper.dataset.columnsId = columnsId;
|
|
1315
|
+
|
|
1316
|
+
if (designMode) {
|
|
1317
|
+
const toolbar = document.createElement('div');
|
|
1318
|
+
toolbar.className = 'document-columns__toolbar';
|
|
1319
|
+
const dragHandle = createDragHandle({ dataset: { action: 'drag-columns' } });
|
|
1320
|
+
dragHandle.draggable = true;
|
|
1321
|
+
const label = document.createElement('span');
|
|
1322
|
+
label.className = 'document-columns__label';
|
|
1323
|
+
label.textContent = '2 columns';
|
|
1324
|
+
const deleteBtn = document.createElement('button');
|
|
1325
|
+
deleteBtn.type = 'button';
|
|
1326
|
+
deleteBtn.className = 'document-columns__delete';
|
|
1327
|
+
deleteBtn.dataset.action = 'delete-columns';
|
|
1328
|
+
deleteBtn.title = 'Remove columns';
|
|
1329
|
+
deleteBtn.textContent = '×';
|
|
1330
|
+
toolbar.appendChild(label);
|
|
1331
|
+
toolbar.appendChild(dragHandle);
|
|
1332
|
+
toolbar.appendChild(deleteBtn);
|
|
1333
|
+
wrapper.appendChild(toolbar);
|
|
1334
|
+
}
|
|
1335
|
+
|
|
1336
|
+
const grid = document.createElement('div');
|
|
1337
|
+
grid.className = 'document-columns__grid';
|
|
1338
|
+
if (designMode) grid.classList.add('document-columns__grid--design');
|
|
1339
|
+
grid.style.gridTemplateColumns = resolveColumnGridTracks(seg.widths, { withSplitter: !!designMode });
|
|
1340
|
+
const w0 = sanitizeColumnWidth(seg.widths?.[0]);
|
|
1341
|
+
const w1 = sanitizeColumnWidth(seg.widths?.[1]);
|
|
1342
|
+
if (w0) wrapper.dataset.columnWidth0 = w0;
|
|
1343
|
+
if (w1) wrapper.dataset.columnWidth1 = w1;
|
|
1344
|
+
|
|
1345
|
+
const columnSegs = seg.columns ?? [[], []];
|
|
1346
|
+
for (let colIndex = 0; colIndex < 2; colIndex++) {
|
|
1347
|
+
if (designMode && colIndex === 1) {
|
|
1348
|
+
const resizer = document.createElement('span');
|
|
1349
|
+
resizer.className = 'document-columns__col-resizer';
|
|
1350
|
+
resizer.dataset.colIndex = '0';
|
|
1351
|
+
resizer.contentEditable = 'false';
|
|
1352
|
+
resizer.title = 'Drag to resize columns';
|
|
1353
|
+
resizer.setAttribute('role', 'separator');
|
|
1354
|
+
resizer.setAttribute('aria-orientation', 'vertical');
|
|
1355
|
+
resizer.setAttribute('aria-label', 'Resize columns');
|
|
1356
|
+
grid.appendChild(resizer);
|
|
1357
|
+
}
|
|
1358
|
+
const col = document.createElement('div');
|
|
1359
|
+
col.className = 'document-columns__col';
|
|
1360
|
+
col.dataset.column = String(colIndex);
|
|
1361
|
+
if (!previewMode) {
|
|
1362
|
+
col.contentEditable = 'true';
|
|
1363
|
+
col.classList.add('cke_editable');
|
|
1364
|
+
}
|
|
1365
|
+
const colContent = document.createDocumentFragment();
|
|
1366
|
+
renderSegmentListInto(colContent, columnSegs[colIndex] ?? [], fieldValues, options);
|
|
1367
|
+
col.appendChild(colContent);
|
|
1368
|
+
grid.appendChild(col);
|
|
1369
|
+
}
|
|
1370
|
+
|
|
1371
|
+
wrapper.appendChild(grid);
|
|
1372
|
+
return wrapper;
|
|
1373
|
+
}
|
|
1374
|
+
|
|
1375
|
+
function renderTableSegment(seg: any, fieldValues: any, options: any = {}) {
|
|
1376
|
+
const { designMode, previewMode } = options;
|
|
1377
|
+
const tableSchema = getTableSchema(seg.id, options);
|
|
1378
|
+
|
|
1379
|
+
if (tableSchema?.type === 'pivotTable') {
|
|
1380
|
+
return renderPivotTableSegment(seg, fieldValues, options);
|
|
1381
|
+
}
|
|
1382
|
+
|
|
1383
|
+
const tableRows = resolveTableInstanceRows(seg.rows, tableSchema);
|
|
1384
|
+
const wrapper = document.createElement('div');
|
|
1385
|
+
wrapper.className = 'document-table';
|
|
1386
|
+
wrapper.contentEditable = 'false';
|
|
1387
|
+
wrapper.dataset.tableId = seg.id;
|
|
1388
|
+
syncTableRowsDataset(wrapper, tableRows);
|
|
1389
|
+
|
|
1390
|
+
if (designMode) {
|
|
1391
|
+
const toolbar = document.createElement('div');
|
|
1392
|
+
toolbar.className = 'document-table__toolbar';
|
|
1393
|
+
const dragHandle = createDragHandle({ dataset: { action: 'drag-table' } });
|
|
1394
|
+
dragHandle.draggable = true;
|
|
1395
|
+
const label = document.createElement('span');
|
|
1396
|
+
label.className = 'document-table__label';
|
|
1397
|
+
label.textContent = 'Table';
|
|
1398
|
+
const deleteBtn = document.createElement('button');
|
|
1399
|
+
deleteBtn.type = 'button';
|
|
1400
|
+
deleteBtn.className = 'document-table__delete';
|
|
1401
|
+
deleteBtn.dataset.action = 'delete-table';
|
|
1402
|
+
deleteBtn.title = 'Remove table';
|
|
1403
|
+
deleteBtn.textContent = '×';
|
|
1404
|
+
toolbar.appendChild(label);
|
|
1405
|
+
toolbar.appendChild(dragHandle);
|
|
1406
|
+
toolbar.appendChild(deleteBtn);
|
|
1407
|
+
wrapper.appendChild(toolbar);
|
|
1408
|
+
}
|
|
1409
|
+
|
|
1410
|
+
const tableOptions = {
|
|
1411
|
+
...options,
|
|
1412
|
+
tableRows,
|
|
1413
|
+
tableContainer: null,
|
|
1414
|
+
};
|
|
1415
|
+
|
|
1416
|
+
const tableEl = previewMode
|
|
1417
|
+
? buildPreviewTableElement(seg.id, fieldValues, {
|
|
1418
|
+
...tableOptions,
|
|
1419
|
+
fieldSchemas: options.fieldSchemas,
|
|
1420
|
+
previewContext: options,
|
|
1421
|
+
})
|
|
1422
|
+
: buildTableElement(seg.id, fieldValues, tableOptions);
|
|
1423
|
+
|
|
1424
|
+
if (tableEl) {
|
|
1425
|
+
tableOptions.tableContainer = tableEl;
|
|
1426
|
+
wrapper.appendChild(tableEl);
|
|
1427
|
+
if (!previewMode) pruneTableCellCaretAnchors(tableEl);
|
|
1428
|
+
}
|
|
1429
|
+
|
|
1430
|
+
if (!previewMode && !options.mappingMode && shouldShowTableRowActions(tableSchema, !!designMode)) {
|
|
1431
|
+
const actions = document.createElement('div');
|
|
1432
|
+
actions.className = 'document-table__row-actions';
|
|
1433
|
+
const addBtn = document.createElement('button');
|
|
1434
|
+
addBtn.type = 'button';
|
|
1435
|
+
addBtn.className = 'document-table__add-row';
|
|
1436
|
+
addBtn.dataset.action = 'add-table-row';
|
|
1437
|
+
addBtn.setAttribute('aria-label', 'Add row');
|
|
1438
|
+
addBtn.innerHTML = '<span class="document-table__add-row-icon" aria-hidden="true">+</span> Add row';
|
|
1439
|
+
const pasteBtn = document.createElement('button');
|
|
1440
|
+
pasteBtn.type = 'button';
|
|
1441
|
+
pasteBtn.className = 'document-table__add-row';
|
|
1442
|
+
pasteBtn.dataset.action = 'paste-table-rows';
|
|
1443
|
+
pasteBtn.setAttribute('aria-label', 'Paste rows from clipboard');
|
|
1444
|
+
pasteBtn.title = 'Paste rows from clipboard (one label per line)';
|
|
1445
|
+
pasteBtn.textContent = 'Paste rows';
|
|
1446
|
+
const importBtn = document.createElement('button');
|
|
1447
|
+
importBtn.type = 'button';
|
|
1448
|
+
importBtn.className = 'document-table__add-row';
|
|
1449
|
+
importBtn.dataset.action = 'import-table-rows';
|
|
1450
|
+
importBtn.setAttribute('aria-label', 'Import rows from text file');
|
|
1451
|
+
importBtn.title = 'Import rows from a .txt file (one label per line)';
|
|
1452
|
+
importBtn.textContent = 'Import';
|
|
1453
|
+
const importFile = document.createElement('input');
|
|
1454
|
+
importFile.type = 'file';
|
|
1455
|
+
importFile.accept = '.txt,text/plain';
|
|
1456
|
+
importFile.hidden = true;
|
|
1457
|
+
importFile.dataset.role = 'import-table-rows-file';
|
|
1458
|
+
actions.appendChild(addBtn);
|
|
1459
|
+
actions.appendChild(pasteBtn);
|
|
1460
|
+
actions.appendChild(importBtn);
|
|
1461
|
+
actions.appendChild(importFile);
|
|
1462
|
+
wrapper.appendChild(actions);
|
|
1463
|
+
}
|
|
1464
|
+
|
|
1465
|
+
return wrapper;
|
|
1466
|
+
}
|
|
1467
|
+
|
|
1468
|
+
/**
|
|
1469
|
+
* Visible label/value text for a field token, excluding the design grip chrome.
|
|
1470
|
+
* Whole-token `draggable` would steal native text drag-and-drop and drop selected
|
|
1471
|
+
* text on failed moves — only the grip is draggable.
|
|
1472
|
+
*/
|
|
1473
|
+
function readFieldTokenVisibleText(token: any) {
|
|
1474
|
+
if (!token) return '';
|
|
1475
|
+
const parts: string[] = [];
|
|
1476
|
+
for (const child of token.childNodes ?? []) {
|
|
1477
|
+
if (child.nodeType === Node.ELEMENT_NODE && child.classList?.contains('editor-drag-handle')) {
|
|
1478
|
+
continue;
|
|
1479
|
+
}
|
|
1480
|
+
parts.push(child.textContent ?? '');
|
|
1481
|
+
}
|
|
1482
|
+
return parts.join('');
|
|
1483
|
+
}
|
|
1484
|
+
|
|
1485
|
+
function ensureFieldTokenDragHandle(token: any) {
|
|
1486
|
+
if (!token || token.classList.contains('field-token--cell')) return null;
|
|
1487
|
+
let handle = token.querySelector?.(':scope > .editor-drag-handle') ?? null;
|
|
1488
|
+
if (!handle) {
|
|
1489
|
+
handle = createDragHandle({
|
|
1490
|
+
dataset: { action: 'drag-field' },
|
|
1491
|
+
hintTitle: null,
|
|
1492
|
+
});
|
|
1493
|
+
token.insertBefore(handle, token.firstChild);
|
|
1494
|
+
} else {
|
|
1495
|
+
// Drop legacy hover bubbles / native titles left on older design tokens.
|
|
1496
|
+
handle.querySelectorAll('.editor-drag-handle__hint').forEach((el: Element) => el.remove());
|
|
1497
|
+
handle.removeAttribute('title');
|
|
1498
|
+
}
|
|
1499
|
+
return handle;
|
|
1500
|
+
}
|
|
1501
|
+
|
|
1502
|
+
function makeFieldTokenDraggable(token: any) {
|
|
1503
|
+
if (token.classList.contains('field-token--cell')) return;
|
|
1504
|
+
|
|
1505
|
+
// Never make the whole token draggable — that breaks selecting/dragging
|
|
1506
|
+
// nearby prose (browser cuts the selection, then HTML5 DnD never pastes it).
|
|
1507
|
+
token.draggable = false;
|
|
1508
|
+
const handle = ensureFieldTokenDragHandle(token);
|
|
1509
|
+
if (!handle) return;
|
|
1510
|
+
|
|
1511
|
+
handle.draggable = true;
|
|
1512
|
+
if (handle.dataset.fieldDragWired === 'true') return;
|
|
1513
|
+
handle.dataset.fieldDragWired = 'true';
|
|
1514
|
+
|
|
1515
|
+
handle.addEventListener('dragstart', (e: any) => {
|
|
1516
|
+
e.stopPropagation();
|
|
1517
|
+
draggedFieldToken = token;
|
|
1518
|
+
token.classList.add('field-token--dragging');
|
|
1519
|
+
e.dataTransfer.effectAllowed = 'move';
|
|
1520
|
+
setInternalDragData(e, token.dataset.fieldId ?? 'field');
|
|
1521
|
+
});
|
|
1522
|
+
handle.addEventListener('dragend', () => {
|
|
1523
|
+
token.classList.remove('field-token--dragging');
|
|
1524
|
+
draggedFieldToken = null;
|
|
1525
|
+
clearDropIndicators();
|
|
1526
|
+
token
|
|
1527
|
+
.closest('.document-section__body, .document-columns__col')
|
|
1528
|
+
?.classList.remove('document-section--drop-target');
|
|
1529
|
+
});
|
|
1530
|
+
}
|
|
1531
|
+
|
|
1532
|
+
function attachDesignToken(token: any, fieldId: any, { onEditSchema, designPropertiesPanel }: any) {
|
|
1533
|
+
token.removeAttribute('title');
|
|
1534
|
+
|
|
1535
|
+
token.addEventListener('click', (e: any) => {
|
|
1536
|
+
e.preventDefault();
|
|
1537
|
+
e.stopPropagation();
|
|
1538
|
+
const container = getFieldSelectionContainer(token);
|
|
1539
|
+
selectDesignToken(token, container, { additive: e.ctrlKey || e.metaKey });
|
|
1540
|
+
if (designPropertiesPanel && !e.ctrlKey && !e.metaKey) {
|
|
1541
|
+
onEditSchema?.(fieldId);
|
|
1542
|
+
}
|
|
1543
|
+
});
|
|
1544
|
+
|
|
1545
|
+
token.addEventListener('dblclick', (e: any) => {
|
|
1546
|
+
e.preventDefault();
|
|
1547
|
+
e.stopPropagation();
|
|
1548
|
+
onEditSchema?.(fieldId);
|
|
1549
|
+
});
|
|
1550
|
+
|
|
1551
|
+
makeFieldTokenDraggable(token);
|
|
1552
|
+
}
|
|
1553
|
+
|
|
1554
|
+
export function wireDesignFieldToken(token: any, { onEditSchema, onDeleteField, designPropertiesPanel }: any) {
|
|
1555
|
+
if (!token) return;
|
|
1556
|
+
token.classList.add('field-token--design');
|
|
1557
|
+
token.removeAttribute('title');
|
|
1558
|
+
if (token.dataset.designWired === 'true') {
|
|
1559
|
+
if (!token.classList.contains('field-token--cell')) {
|
|
1560
|
+
makeFieldTokenDraggable(token);
|
|
1561
|
+
}
|
|
1562
|
+
return;
|
|
1563
|
+
}
|
|
1564
|
+
token.dataset.designWired = 'true';
|
|
1565
|
+
attachDesignToken(token, token.dataset.fieldId, { onEditSchema, onDeleteField, designPropertiesPanel });
|
|
1566
|
+
}
|
|
1567
|
+
|
|
1568
|
+
const BLOCK_HTML_TAG_RE = /<\/?(?:h[1-3]|div|p|ul|ol|li|table|tr|td|th)\b/i;
|
|
1569
|
+
const INLINE_OPEN_TAG_RE = /^(?:<(?:b|i|u|span|font)\b[^>]*>)+/i;
|
|
1570
|
+
|
|
1571
|
+
function containsBlockHtml(html: any) {
|
|
1572
|
+
return BLOCK_HTML_TAG_RE.test(String(html ?? ''));
|
|
1573
|
+
}
|
|
1574
|
+
|
|
1575
|
+
function htmlStartsWithStructuralBr(html: any) {
|
|
1576
|
+
return /^<br\s*\/?>/i.test(String(html ?? '').trim());
|
|
1577
|
+
}
|
|
1578
|
+
|
|
1579
|
+
function htmlEndsWithStructuralBr(html: any) {
|
|
1580
|
+
return /<br\s*\/?>\s*$/i.test(String(html ?? '').trim());
|
|
1581
|
+
}
|
|
1582
|
+
|
|
1583
|
+
function htmlStartsWithRowSeparator(html: any) {
|
|
1584
|
+
const trimmed = String(html ?? '').trim();
|
|
1585
|
+
if (/^\.(?:<br\s*\/?>|\n)/i.test(trimmed)) return true;
|
|
1586
|
+
const withoutInline = trimmed.replace(INLINE_OPEN_TAG_RE, '');
|
|
1587
|
+
return /^\.(?:<br\s*\/?>|\n)/i.test(withoutInline);
|
|
1588
|
+
}
|
|
1589
|
+
|
|
1590
|
+
function canMergeAdjacentHtml(left: any, right: any) {
|
|
1591
|
+
if (!left || !right) return false;
|
|
1592
|
+
if (containsBlockHtml(left) || containsBlockHtml(right)) return false;
|
|
1593
|
+
if (htmlEndsWithStructuralBr(left) || htmlStartsWithStructuralBr(right)) return false;
|
|
1594
|
+
if (htmlStartsWithRowSeparator(right)) return false;
|
|
1595
|
+
if (/<\/(?:b|i|u|span|font)>\s*$/i.test(String(left).trim()) && htmlStartsWithRowSeparator(right)) {
|
|
1596
|
+
return false;
|
|
1597
|
+
}
|
|
1598
|
+
return true;
|
|
1599
|
+
}
|
|
1600
|
+
|
|
1601
|
+
function mergeAdjacentText(parts: any) {
|
|
1602
|
+
const merged = [];
|
|
1603
|
+
for (const part of parts) {
|
|
1604
|
+
const last = merged[merged.length - 1];
|
|
1605
|
+
const sameAlign = (last?.align ?? null) === (part.align ?? null);
|
|
1606
|
+
if (part.type === 'text' && last?.type === 'text' && sameAlign) {
|
|
1607
|
+
if (last.html != null || part.html != null) {
|
|
1608
|
+
if (last.html != null && part.content != null && !part.html) {
|
|
1609
|
+
merged.push({ ...part });
|
|
1610
|
+
continue;
|
|
1611
|
+
}
|
|
1612
|
+
if (last.content != null && !last.html && part.html != null) {
|
|
1613
|
+
merged.push({ ...part });
|
|
1614
|
+
continue;
|
|
1615
|
+
}
|
|
1616
|
+
if (last.html != null && part.html != null) {
|
|
1617
|
+
if (canMergeAdjacentHtml(last.html, part.html)) {
|
|
1618
|
+
last.html = last.html + part.html;
|
|
1619
|
+
delete last.content;
|
|
1620
|
+
} else {
|
|
1621
|
+
merged.push({ ...part });
|
|
1622
|
+
}
|
|
1623
|
+
continue;
|
|
1624
|
+
}
|
|
1625
|
+
const left = last.html ?? plainTextNewlinesToBr(escapeTextForHtml(last.content ?? ''));
|
|
1626
|
+
const right = part.html ?? plainTextNewlinesToBr(escapeTextForHtml(part.content ?? ''));
|
|
1627
|
+
last.html = left + right;
|
|
1628
|
+
delete last.content;
|
|
1629
|
+
} else {
|
|
1630
|
+
last.content = (last.content ?? '') + (part.content ?? '');
|
|
1631
|
+
}
|
|
1632
|
+
} else {
|
|
1633
|
+
merged.push({ ...part });
|
|
1634
|
+
}
|
|
1635
|
+
}
|
|
1636
|
+
return merged;
|
|
1637
|
+
}
|
|
1638
|
+
|
|
1639
|
+
function escapeTextForHtml(text: any) {
|
|
1640
|
+
return String(text)
|
|
1641
|
+
.replace(/&/g, '&')
|
|
1642
|
+
.replace(/</g, '<')
|
|
1643
|
+
.replace(/>/g, '>');
|
|
1644
|
+
}
|
|
1645
|
+
|
|
1646
|
+
function containsFieldToken(node: any) {
|
|
1647
|
+
return node.nodeType === Node.ELEMENT_NODE && node.querySelector?.('.field-token') != null;
|
|
1648
|
+
}
|
|
1649
|
+
|
|
1650
|
+
function isFieldTokenNode(node: any) {
|
|
1651
|
+
return node.nodeType === Node.ELEMENT_NODE && node.classList?.contains('field-token');
|
|
1652
|
+
}
|
|
1653
|
+
|
|
1654
|
+
function isColumnsNode(node: any) {
|
|
1655
|
+
return node.nodeType === Node.ELEMENT_NODE && node.classList?.contains('document-columns');
|
|
1656
|
+
}
|
|
1657
|
+
|
|
1658
|
+
let nextColumnsId = 0;
|
|
1659
|
+
|
|
1660
|
+
function createColumnsId() {
|
|
1661
|
+
nextColumnsId += 1;
|
|
1662
|
+
return `columns_${Date.now()}_${nextColumnsId}`;
|
|
1663
|
+
}
|
|
1664
|
+
|
|
1665
|
+
function sanitizeColumnWidth(value: any) {
|
|
1666
|
+
const trimmed = String(value ?? '').trim();
|
|
1667
|
+
if (!trimmed) return '';
|
|
1668
|
+
if (trimmed.length > 24) return '';
|
|
1669
|
+
if (!/^[\w%.(),\s-]+$/i.test(trimmed)) return '';
|
|
1670
|
+
return trimmed;
|
|
1671
|
+
}
|
|
1672
|
+
|
|
1673
|
+
/** Middle track holds the design-mode column splitter (see `.document-columns__col-resizer`). */
|
|
1674
|
+
const COLUMNS_SPLITTER_TRACK = '12px';
|
|
1675
|
+
|
|
1676
|
+
function resolveColumnGridTracks(widths: any, { withSplitter = false }: any = {}) {
|
|
1677
|
+
const w0 = sanitizeColumnWidth(widths?.[0]) || '1fr';
|
|
1678
|
+
const w1 = sanitizeColumnWidth(widths?.[1]) || '1fr';
|
|
1679
|
+
if (withSplitter) return `${w0} ${COLUMNS_SPLITTER_TRACK} ${w1}`;
|
|
1680
|
+
return `${w0} ${w1}`;
|
|
1681
|
+
}
|
|
1682
|
+
|
|
1683
|
+
function parsePercentWidth(value: any) {
|
|
1684
|
+
const match = String(value ?? '').trim().match(/^(\d+(?:\.\d+)?)%$/);
|
|
1685
|
+
return match ? Number(match[1]) : null;
|
|
1686
|
+
}
|
|
1687
|
+
|
|
1688
|
+
function columnsNeedAutoWidths(seg: any) {
|
|
1689
|
+
if (seg?.type !== 'columns') return false;
|
|
1690
|
+
if (!Array.isArray(seg.widths) || seg.widths.length < 2) return true;
|
|
1691
|
+
const left = sanitizeColumnWidth(seg.widths[0]).toLowerCase();
|
|
1692
|
+
const right = sanitizeColumnWidth(seg.widths[1]).toLowerCase();
|
|
1693
|
+
return !left || !right;
|
|
1694
|
+
}
|
|
1695
|
+
|
|
1696
|
+
function isTwoColumnSegment(seg: any) {
|
|
1697
|
+
return seg?.type === 'columns' && Array.isArray(seg.columns) && seg.columns.length === 2;
|
|
1698
|
+
}
|
|
1699
|
+
|
|
1700
|
+
function columnsHaveDefaultEvenSplit(widths: any) {
|
|
1701
|
+
if (!Array.isArray(widths) || widths.length < 2) return false;
|
|
1702
|
+
const left = sanitizeColumnWidth(widths[0]).toLowerCase();
|
|
1703
|
+
const right = sanitizeColumnWidth(widths[1]).toLowerCase();
|
|
1704
|
+
if (!left || !right) return false;
|
|
1705
|
+
if (left === '1fr' && right === '1fr') return true;
|
|
1706
|
+
const leftPct = parsePercentWidth(left);
|
|
1707
|
+
const rightPct = parsePercentWidth(right);
|
|
1708
|
+
if (leftPct == null || rightPct == null) return false;
|
|
1709
|
+
return Math.abs(leftPct - 50) < 0.15 && Math.abs(rightPct - 50) < 0.15;
|
|
1710
|
+
}
|
|
1711
|
+
|
|
1712
|
+
function deriveColumnsWidthsFromTableSeg(tableSeg: any, options: any = {}) {
|
|
1713
|
+
if (!tableSeg?.id) return null;
|
|
1714
|
+
const tableSchema = getTableSchema(tableSeg.id, options);
|
|
1715
|
+
const columns = tableSchema?.columns ?? [];
|
|
1716
|
+
if (columns.length < 2) return null;
|
|
1717
|
+
const scaled = scalePercentCssWidthsToFill(
|
|
1718
|
+
columns.map((col: any) => schemaWidthToColCss(col?.width)),
|
|
1719
|
+
);
|
|
1720
|
+
const percents = scaled.map(parsePercentWidth);
|
|
1721
|
+
if (percents.some((pct: any) => pct == null)) return null;
|
|
1722
|
+
const rightPct = percents[percents.length - 1];
|
|
1723
|
+
if (!(rightPct > 0 && rightPct < 100)) return null;
|
|
1724
|
+
const leftPct = Math.round((100 - rightPct) * 10) / 10;
|
|
1725
|
+
return [`${leftPct}%`, `${rightPct}%`];
|
|
1726
|
+
}
|
|
1727
|
+
|
|
1728
|
+
export function createEmptyColumnsSegment(overrides: any = {}) {
|
|
1729
|
+
return {
|
|
1730
|
+
type: 'columns',
|
|
1731
|
+
id: createColumnsId(),
|
|
1732
|
+
columns: [[], []],
|
|
1733
|
+
...overrides,
|
|
1734
|
+
};
|
|
1735
|
+
}
|
|
1736
|
+
|
|
1737
|
+
export function applyColumnWidthsToElement(columnsEl: any, widths: any) {
|
|
1738
|
+
const grid = columnsEl?.querySelector?.(':scope > .document-columns__grid');
|
|
1739
|
+
if (!grid) return;
|
|
1740
|
+
const withSplitter = !!grid.querySelector(':scope > .document-columns__col-resizer');
|
|
1741
|
+
grid.style.gridTemplateColumns = resolveColumnGridTracks(widths, { withSplitter });
|
|
1742
|
+
const w0 = sanitizeColumnWidth(widths?.[0]);
|
|
1743
|
+
const w1 = sanitizeColumnWidth(widths?.[1]);
|
|
1744
|
+
if (w0) columnsEl.dataset.columnWidth0 = w0;
|
|
1745
|
+
else delete columnsEl.dataset.columnWidth0;
|
|
1746
|
+
if (w1) columnsEl.dataset.columnWidth1 = w1;
|
|
1747
|
+
else delete columnsEl.dataset.columnWidth1;
|
|
1748
|
+
}
|
|
1749
|
+
|
|
1750
|
+
function readColumnsSegmentMeta(columnsEl: any) {
|
|
1751
|
+
const meta: any = {};
|
|
1752
|
+
const id = columnsEl.dataset.columnsId;
|
|
1753
|
+
if (id) meta.id = id;
|
|
1754
|
+
const w0 = columnsEl.dataset.columnWidth0;
|
|
1755
|
+
const w1 = columnsEl.dataset.columnWidth1;
|
|
1756
|
+
if (w0 || w1) {
|
|
1757
|
+
meta.widths = [w0 || undefined, w1 || undefined];
|
|
1758
|
+
}
|
|
1759
|
+
return meta;
|
|
1760
|
+
}
|
|
1761
|
+
|
|
1762
|
+
function getDirectColumnEls(columnsEl: any) {
|
|
1763
|
+
// Must not use descendant querySelectorAll — nested columns also use
|
|
1764
|
+
// .document-columns__col and would steal the outer right column on save.
|
|
1765
|
+
return [
|
|
1766
|
+
...(columnsEl?.querySelectorAll?.(':scope > .document-columns__grid > .document-columns__col') ??
|
|
1767
|
+
[]),
|
|
1768
|
+
];
|
|
1769
|
+
}
|
|
1770
|
+
|
|
1771
|
+
function readColumnsSegmentFromDom(columnsEl: any) {
|
|
1772
|
+
const cols = getDirectColumnEls(columnsEl);
|
|
1773
|
+
return {
|
|
1774
|
+
type: 'columns',
|
|
1775
|
+
...readColumnsSegmentMeta(columnsEl),
|
|
1776
|
+
columns: [
|
|
1777
|
+
cols[0] ? serializeEditableToSegments(cols[0]) : [],
|
|
1778
|
+
cols[1] ? serializeEditableToSegments(cols[1]) : [],
|
|
1779
|
+
],
|
|
1780
|
+
};
|
|
1781
|
+
}
|
|
1782
|
+
|
|
1783
|
+
function shouldInsertInsideColumn(sectionBody: any, anchor: any) {
|
|
1784
|
+
const col = anchor?.closest?.('.document-columns__col');
|
|
1785
|
+
return Boolean(col && sectionBody.contains(col));
|
|
1786
|
+
}
|
|
1787
|
+
|
|
1788
|
+
function isTableNode(node: any) {
|
|
1789
|
+
return node.nodeType === Node.ELEMENT_NODE && node.classList?.contains('document-table');
|
|
1790
|
+
}
|
|
1791
|
+
|
|
1792
|
+
function isVisionTableBlockNode(node: any) {
|
|
1793
|
+
return node.nodeType === Node.ELEMENT_NODE && node.classList?.contains('vision-table-block');
|
|
1794
|
+
}
|
|
1795
|
+
|
|
1796
|
+
function readVisionTableIdFromBlock(node: any, options: any = {}) {
|
|
1797
|
+
const token = node.querySelector?.('.field-token[data-field-id]');
|
|
1798
|
+
if (token?.dataset?.fieldId) {
|
|
1799
|
+
const parsed = parseCellFieldId(token.dataset.fieldId, options.fieldSchemas);
|
|
1800
|
+
if (parsed?.tableFieldId) return parsed.tableFieldId;
|
|
1801
|
+
}
|
|
1802
|
+
return null;
|
|
1803
|
+
}
|
|
1804
|
+
|
|
1805
|
+
function readVisionTableRowsFromLegacyBlock(node: any, tableId: any, options: any = {}) {
|
|
1806
|
+
const rows = readTableRowsFromDom(node);
|
|
1807
|
+
if (rows.length) return rows;
|
|
1808
|
+
const schema = getTableSchema(tableId, options);
|
|
1809
|
+
return (schema?.rows ?? []).map((row: any) => ({ key: row.key, label: row.label ?? '' }));
|
|
1810
|
+
}
|
|
1811
|
+
|
|
1812
|
+
function isRepeaterNode(node: any) {
|
|
1813
|
+
return node.nodeType === Node.ELEMENT_NODE && node.classList?.contains('document-repeater');
|
|
1814
|
+
}
|
|
1815
|
+
|
|
1816
|
+
function isEditorBlockElement(node: any) {
|
|
1817
|
+
return (
|
|
1818
|
+
node?.nodeType === Node.ELEMENT_NODE &&
|
|
1819
|
+
(node.tagName === 'DIV' || node.tagName === 'P') &&
|
|
1820
|
+
!isAlignmentDiv(node) &&
|
|
1821
|
+
!isColumnsNode(node) &&
|
|
1822
|
+
!isTableNode(node) &&
|
|
1823
|
+
!isRepeaterNode(node) &&
|
|
1824
|
+
!isFieldTokenNode(node)
|
|
1825
|
+
);
|
|
1826
|
+
}
|
|
1827
|
+
|
|
1828
|
+
function isTransparentBlockWrapper(node: any) {
|
|
1829
|
+
if (!isEditorBlockElement(node)) return false;
|
|
1830
|
+
if (containsFieldToken(node)) return false;
|
|
1831
|
+
for (const el of node.querySelectorAll('div, p, h1, h2, h3, ul, ol, li')) {
|
|
1832
|
+
if (el === node) continue;
|
|
1833
|
+
if (isAlignmentDiv(el) || isColumnsNode(el) || isTableNode(el) || isRepeaterNode(el)) continue;
|
|
1834
|
+
return false;
|
|
1835
|
+
}
|
|
1836
|
+
return true;
|
|
1837
|
+
}
|
|
1838
|
+
|
|
1839
|
+
function isBrOnlyTransparentWrapper(node: any) {
|
|
1840
|
+
if (!isTransparentBlockWrapper(node)) return false;
|
|
1841
|
+
const text = stripFieldTokenCaretAnchors(node.textContent ?? '')
|
|
1842
|
+
.replace(/\u200B/g, '')
|
|
1843
|
+
.trim();
|
|
1844
|
+
if (text) return false;
|
|
1845
|
+
return node.querySelector('br') != null;
|
|
1846
|
+
}
|
|
1847
|
+
|
|
1848
|
+
function isTopLevelLineBoundaryNode(node: any) {
|
|
1849
|
+
if (!node) return false;
|
|
1850
|
+
if (node.nodeName === 'BR') return true;
|
|
1851
|
+
if (isFieldTokenNode(node)) return true;
|
|
1852
|
+
if (isHeadingElement(node)) return true;
|
|
1853
|
+
if (isColumnsNode(node) || isTableNode(node) || isRepeaterNode(node)) return true;
|
|
1854
|
+
if (isAlignmentDiv(node)) return true;
|
|
1855
|
+
return false;
|
|
1856
|
+
}
|
|
1857
|
+
|
|
1858
|
+
/** Flatten browser-created block wrappers so vertical caret navigation sees every line. */
|
|
1859
|
+
export function normalizeEditableLineStructure(container: any) {
|
|
1860
|
+
if (!container?.childNodes?.length) return false;
|
|
1861
|
+
|
|
1862
|
+
const wrappers = [...container.childNodes].filter((node) => isTransparentBlockWrapper(node));
|
|
1863
|
+
if (!wrappers.length) return false;
|
|
1864
|
+
|
|
1865
|
+
const saved = saveSelection(container);
|
|
1866
|
+
|
|
1867
|
+
for (const wrapper of wrappers) {
|
|
1868
|
+
if (!wrapper.isConnected) continue;
|
|
1869
|
+
|
|
1870
|
+
if (isBrOnlyTransparentWrapper(wrapper)) {
|
|
1871
|
+
wrapper.replaceWith(document.createElement('br'));
|
|
1872
|
+
continue;
|
|
1873
|
+
}
|
|
1874
|
+
|
|
1875
|
+
const prev = wrapper.previousSibling;
|
|
1876
|
+
const next = wrapper.nextSibling;
|
|
1877
|
+
const needsLeadingBr = prev != null && !isTopLevelLineBoundaryNode(prev);
|
|
1878
|
+
const needsTrailingBr = next != null && !isTopLevelLineBoundaryNode(next);
|
|
1879
|
+
|
|
1880
|
+
const fragment = document.createDocumentFragment();
|
|
1881
|
+
if (needsLeadingBr) {
|
|
1882
|
+
fragment.appendChild(document.createElement('br'));
|
|
1883
|
+
}
|
|
1884
|
+
let lastMoved: ChildNode | null = null;
|
|
1885
|
+
while (wrapper.firstChild) {
|
|
1886
|
+
lastMoved = wrapper.firstChild;
|
|
1887
|
+
fragment.appendChild(wrapper.firstChild);
|
|
1888
|
+
}
|
|
1889
|
+
wrapper.replaceWith(fragment);
|
|
1890
|
+
|
|
1891
|
+
if (needsTrailingBr && lastMoved?.nodeName !== 'BR') {
|
|
1892
|
+
lastMoved.after(document.createElement('br'));
|
|
1893
|
+
}
|
|
1894
|
+
}
|
|
1895
|
+
|
|
1896
|
+
if (saved) restoreSelection(saved);
|
|
1897
|
+
return true;
|
|
1898
|
+
}
|
|
1899
|
+
|
|
1900
|
+
export function serializeEditableToSegments(container: any) {
|
|
1901
|
+
const parts: any[] = [];
|
|
1902
|
+
const buffer = document.createElement('div');
|
|
1903
|
+
let bufferAlign: any = null;
|
|
1904
|
+
const fieldSchemas =
|
|
1905
|
+
getRegistryFromNode(container)?.getFieldSchemas?.() ??
|
|
1906
|
+
getRegistryFromNode(container.closest?.('[data-doc-editor]'))?.getFieldSchemas?.() ??
|
|
1907
|
+
{};
|
|
1908
|
+
const serializeOptions = { fieldSchemas };
|
|
1909
|
+
|
|
1910
|
+
function emitBufferedText() {
|
|
1911
|
+
if (!buffer.childNodes.length) return;
|
|
1912
|
+
|
|
1913
|
+
const html = buffer.innerHTML;
|
|
1914
|
+
const text = buffer.textContent ?? '';
|
|
1915
|
+
if (!text && !html.trim()) {
|
|
1916
|
+
buffer.innerHTML = '';
|
|
1917
|
+
bufferAlign = null;
|
|
1918
|
+
return;
|
|
1919
|
+
}
|
|
1920
|
+
|
|
1921
|
+
if (isPlainTextHtml(html)) {
|
|
1922
|
+
const part: any = { type: 'text', content: stripFieldTokenCaretAnchors(text) };
|
|
1923
|
+
if (bufferAlign) part.align = bufferAlign;
|
|
1924
|
+
parts.push(part);
|
|
1925
|
+
} else {
|
|
1926
|
+
const part: any = { type: 'text', html: plainTextNewlinesToBr(sanitizeHtml(html)) };
|
|
1927
|
+
if (bufferAlign) part.align = bufferAlign;
|
|
1928
|
+
parts.push(part);
|
|
1929
|
+
}
|
|
1930
|
+
buffer.innerHTML = '';
|
|
1931
|
+
bufferAlign = null;
|
|
1932
|
+
}
|
|
1933
|
+
|
|
1934
|
+
function flushBuffer() {
|
|
1935
|
+
if (!buffer.childNodes.length) return;
|
|
1936
|
+
|
|
1937
|
+
if (buffer.querySelector('.field-token')) {
|
|
1938
|
+
const nodes = [...buffer.childNodes];
|
|
1939
|
+
buffer.innerHTML = '';
|
|
1940
|
+
for (const node of nodes) {
|
|
1941
|
+
if (isFieldTokenNode(node)) {
|
|
1942
|
+
emitBufferedText();
|
|
1943
|
+
const part: any = {
|
|
1944
|
+
type: 'field',
|
|
1945
|
+
id: (node as any).dataset.fieldId,
|
|
1946
|
+
placeholder: (node as any).dataset.placeholder || undefined,
|
|
1947
|
+
};
|
|
1948
|
+
if (bufferAlign) part.align = bufferAlign;
|
|
1949
|
+
parts.push(part);
|
|
1950
|
+
continue;
|
|
1951
|
+
}
|
|
1952
|
+
buffer.appendChild(node);
|
|
1953
|
+
}
|
|
1954
|
+
}
|
|
1955
|
+
|
|
1956
|
+
emitBufferedText();
|
|
1957
|
+
}
|
|
1958
|
+
|
|
1959
|
+
function walk(node: any, activeAlign: any = null) {
|
|
1960
|
+
const children = [...node.childNodes];
|
|
1961
|
+
for (let ci = 0; ci < children.length; ci++) {
|
|
1962
|
+
const child = children[ci];
|
|
1963
|
+
if (
|
|
1964
|
+
child.nodeType === Node.ELEMENT_NODE &&
|
|
1965
|
+
child.classList?.contains('document-columns__col-resizer')
|
|
1966
|
+
) {
|
|
1967
|
+
continue;
|
|
1968
|
+
}
|
|
1969
|
+
if (isFieldTokenNode(child)) {
|
|
1970
|
+
flushBuffer();
|
|
1971
|
+
const part: any = {
|
|
1972
|
+
type: 'field',
|
|
1973
|
+
id: child.dataset.fieldId,
|
|
1974
|
+
placeholder: child.dataset.placeholder || undefined,
|
|
1975
|
+
};
|
|
1976
|
+
if (activeAlign) part.align = activeAlign;
|
|
1977
|
+
parts.push(part);
|
|
1978
|
+
} else if (isAlignmentDiv(child)) {
|
|
1979
|
+
flushBuffer();
|
|
1980
|
+
const align = getBlockTextAlign(child.getAttribute('style') || '');
|
|
1981
|
+
walk(child, align);
|
|
1982
|
+
flushBuffer();
|
|
1983
|
+
} else if (child.nodeName === 'BR') {
|
|
1984
|
+
flushBuffer();
|
|
1985
|
+
const part: any = { type: 'text', content: '\n' };
|
|
1986
|
+
if (activeAlign) part.align = activeAlign;
|
|
1987
|
+
parts.push(part);
|
|
1988
|
+
} else if (isColumnsNode(child)) {
|
|
1989
|
+
flushBuffer();
|
|
1990
|
+
parts.push(readColumnsSegmentFromDom(child));
|
|
1991
|
+
} else if (isTableNode(child)) {
|
|
1992
|
+
flushBuffer();
|
|
1993
|
+
const rows = readTableRowsFromDom(child);
|
|
1994
|
+
const tablePart: any = {
|
|
1995
|
+
type: 'table',
|
|
1996
|
+
id: child.dataset.tableId,
|
|
1997
|
+
};
|
|
1998
|
+
if (rows.length) tablePart.rows = rows;
|
|
1999
|
+
parts.push(tablePart);
|
|
2000
|
+
} else if (isVisionTableBlockNode(child)) {
|
|
2001
|
+
flushBuffer();
|
|
2002
|
+
const tableId = readVisionTableIdFromBlock(child, serializeOptions);
|
|
2003
|
+
if (tableId) {
|
|
2004
|
+
const rows = readVisionTableRowsFromLegacyBlock(child, tableId, serializeOptions);
|
|
2005
|
+
const tablePart: any = { type: 'table', id: tableId };
|
|
2006
|
+
if (rows.length) tablePart.rows = rows;
|
|
2007
|
+
parts.push(tablePart);
|
|
2008
|
+
}
|
|
2009
|
+
} else if (isRepeaterNode(child)) {
|
|
2010
|
+
flushBuffer();
|
|
2011
|
+
parts.push({
|
|
2012
|
+
type: 'field',
|
|
2013
|
+
id: child.dataset.repeaterId,
|
|
2014
|
+
});
|
|
2015
|
+
} else if (isHeadingElement(child)) {
|
|
2016
|
+
flushBuffer();
|
|
2017
|
+
if (activeAlign) bufferAlign = activeAlign;
|
|
2018
|
+
buffer.appendChild(child.cloneNode(true));
|
|
2019
|
+
flushBuffer();
|
|
2020
|
+
} else if (isBrOnlyTransparentWrapper(child)) {
|
|
2021
|
+
flushBuffer();
|
|
2022
|
+
const part: any = { type: 'text', content: '\n' };
|
|
2023
|
+
if (activeAlign) part.align = activeAlign;
|
|
2024
|
+
parts.push(part);
|
|
2025
|
+
} else if (isTransparentBlockWrapper(child)) {
|
|
2026
|
+
walk(child, activeAlign);
|
|
2027
|
+
} else if (isEditorBlockElement(child)) {
|
|
2028
|
+
flushBuffer();
|
|
2029
|
+
walk(child, activeAlign);
|
|
2030
|
+
flushBuffer();
|
|
2031
|
+
} else if (containsFieldToken(child)) {
|
|
2032
|
+
flushBuffer();
|
|
2033
|
+
walk(child, activeAlign);
|
|
2034
|
+
} else {
|
|
2035
|
+
if (activeAlign) bufferAlign = activeAlign;
|
|
2036
|
+
buffer.appendChild(child.cloneNode(true));
|
|
2037
|
+
}
|
|
2038
|
+
}
|
|
2039
|
+
}
|
|
2040
|
+
|
|
2041
|
+
walk(container);
|
|
2042
|
+
flushBuffer();
|
|
2043
|
+
return mergeAdjacentText(parts);
|
|
2044
|
+
}
|
|
2045
|
+
|
|
2046
|
+
export function extractFieldValuesFromDom(container: any) {
|
|
2047
|
+
const values: Record<string, any> = {};
|
|
2048
|
+
container.querySelectorAll('.field-token').forEach((token: any) => {
|
|
2049
|
+
if (
|
|
2050
|
+
token.closest('.field-token--repeater') &&
|
|
2051
|
+
!token.classList.contains('field-token--repeater')
|
|
2052
|
+
) {
|
|
2053
|
+
return;
|
|
2054
|
+
}
|
|
2055
|
+
let value = token.classList.contains('field-token--repeater')
|
|
2056
|
+
? readRepeaterTokenValue(token)
|
|
2057
|
+
: readTokenValue(token);
|
|
2058
|
+
value = normalizeTableCellTokenValue(token, value, token.dataset.placeholder);
|
|
2059
|
+
values[token.dataset.fieldId] = value;
|
|
2060
|
+
});
|
|
2061
|
+
container.querySelectorAll('.document-table--pivot[data-pivot-field-id]').forEach((el: any) => {
|
|
2062
|
+
const fieldId = el.dataset.pivotFieldId;
|
|
2063
|
+
if (!fieldId) return;
|
|
2064
|
+
values[fieldId] = readPivotValueFromDom(el);
|
|
2065
|
+
});
|
|
2066
|
+
return values;
|
|
2067
|
+
}
|
|
2068
|
+
|
|
2069
|
+
function resolvePickerInitialValue(currentValue: any, fieldId: any, context: any) {
|
|
2070
|
+
const registry = registryFrom(context);
|
|
2071
|
+
const schema = registry?.getFieldSchemas()?.[fieldId];
|
|
2072
|
+
const def = registry?.getFieldDef(fieldId) ?? schemaToDisplayConfig(schema);
|
|
2073
|
+
if (!isFieldEmpty(currentValue, { htmlEditor: !!def?.htmlEditor })) return currentValue;
|
|
2074
|
+
return resolveSchemaDefaultValue(schema, { forTemplate: false });
|
|
2075
|
+
}
|
|
2076
|
+
|
|
2077
|
+
function toListPickerSelected(value: any) {
|
|
2078
|
+
if (Array.isArray(value)) return value;
|
|
2079
|
+
return value ? [value] : [];
|
|
2080
|
+
}
|
|
2081
|
+
|
|
2082
|
+
function extractFieldValuesForPicker(fieldId: any, callbacks: any) {
|
|
2083
|
+
const holder = callbacks?.editorHolder;
|
|
2084
|
+
if (!holder?.querySelectorAll) return {};
|
|
2085
|
+
|
|
2086
|
+
for (const editable of holder.querySelectorAll('.document-section__body')) {
|
|
2087
|
+
if (editable.querySelector(`[data-field-id="${fieldId}"]`)) {
|
|
2088
|
+
return extractFieldValuesFromDom(editable);
|
|
2089
|
+
}
|
|
2090
|
+
}
|
|
2091
|
+
|
|
2092
|
+
const values = {};
|
|
2093
|
+
for (const editable of holder.querySelectorAll('.document-section__body')) {
|
|
2094
|
+
Object.assign(values, extractFieldValuesFromDom(editable));
|
|
2095
|
+
}
|
|
2096
|
+
return values;
|
|
2097
|
+
}
|
|
2098
|
+
|
|
2099
|
+
function buildRemoteListSearch(fieldId: any, schema: any, callbacks: any, selected: any) {
|
|
2100
|
+
const resolveListItems = callbacks?.resolveListItems;
|
|
2101
|
+
if (!resolveListItems) {
|
|
2102
|
+
return {
|
|
2103
|
+
search: async () => {
|
|
2104
|
+
throw new Error('resolveListItems is not configured on createEditor()');
|
|
2105
|
+
},
|
|
2106
|
+
};
|
|
2107
|
+
}
|
|
2108
|
+
|
|
2109
|
+
return {
|
|
2110
|
+
search: async (query: any) => {
|
|
2111
|
+
const liveSchema =
|
|
2112
|
+
callbacks?.getRegistry?.()?.getFieldSchemas?.()?.[fieldId] ?? schema;
|
|
2113
|
+
const fieldName = String(
|
|
2114
|
+
liveSchema?.name ?? liveSchema?.label ?? schema?.name ?? fieldId ?? '',
|
|
2115
|
+
).trim();
|
|
2116
|
+
const sourceCollection = String(liveSchema?.sourceCollection ?? '').trim();
|
|
2117
|
+
|
|
2118
|
+
const raw = await resolveListItems({
|
|
2119
|
+
fieldName,
|
|
2120
|
+
schema: liveSchema,
|
|
2121
|
+
sourceCollection: sourceCollection || undefined,
|
|
2122
|
+
fieldValues: extractFieldValuesForPicker(fieldId, callbacks),
|
|
2123
|
+
query,
|
|
2124
|
+
selected,
|
|
2125
|
+
});
|
|
2126
|
+
const items = Array.isArray(raw) ? raw : [];
|
|
2127
|
+
// Normalize Apex / host payloads to picker shape.
|
|
2128
|
+
return items
|
|
2129
|
+
.map((item) => {
|
|
2130
|
+
if (item == null || typeof item !== 'object') return null;
|
|
2131
|
+
const label = item.label ?? item.Name ?? item.name ?? item.value ?? '';
|
|
2132
|
+
const id = item.id ?? item.Id ?? item.value ?? label;
|
|
2133
|
+
if (!label && !id) return null;
|
|
2134
|
+
return {
|
|
2135
|
+
id: String(id),
|
|
2136
|
+
label: String(label || id),
|
|
2137
|
+
value: item.value != null ? String(item.value) : String(label || id),
|
|
2138
|
+
code: item.code != null ? String(item.code) : undefined,
|
|
2139
|
+
};
|
|
2140
|
+
})
|
|
2141
|
+
.filter(Boolean);
|
|
2142
|
+
},
|
|
2143
|
+
};
|
|
2144
|
+
}
|
|
2145
|
+
|
|
2146
|
+
async function pickWithManualEdit({ schema, currentValue, schemaType, openStructured }: any) {
|
|
2147
|
+
const manualEdit = !!schema?.allowManualEdit;
|
|
2148
|
+
if (manualEdit) {
|
|
2149
|
+
return openStructured({
|
|
2150
|
+
allowManualEdit: true,
|
|
2151
|
+
initialText: formatManualEditText(currentValue, schemaType),
|
|
2152
|
+
});
|
|
2153
|
+
}
|
|
2154
|
+
|
|
2155
|
+
return openStructured({ allowManualEdit: false });
|
|
2156
|
+
}
|
|
2157
|
+
|
|
2158
|
+
/** Coerce stored logical values to boolean or null. */
|
|
2159
|
+
export function normalizeLogicalValue(value: unknown): boolean | null {
|
|
2160
|
+
if (value === true || value === false) return value;
|
|
2161
|
+
if (value === 'true') return true;
|
|
2162
|
+
if (value === 'false') return false;
|
|
2163
|
+
return null;
|
|
2164
|
+
}
|
|
2165
|
+
|
|
2166
|
+
/** Inline fill-mode cycle: empty → Yes, then Yes ↔ No. */
|
|
2167
|
+
export function cycleLogicalValue(value: unknown): boolean {
|
|
2168
|
+
const current = normalizeLogicalValue(value);
|
|
2169
|
+
if (current !== true && current !== false) return true;
|
|
2170
|
+
return !current;
|
|
2171
|
+
}
|
|
2172
|
+
|
|
2173
|
+
export async function openFieldPicker(fieldId: any, currentValue: any, callbacks: any) {
|
|
2174
|
+
const registry = registryFrom(callbacks);
|
|
2175
|
+
const def = registry?.getFieldDef(fieldId);
|
|
2176
|
+
if (!def || !callbacks) return currentValue;
|
|
2177
|
+
|
|
2178
|
+
if (def.picker === 'computed') return currentValue;
|
|
2179
|
+
|
|
2180
|
+
const schema = registry?.getFieldSchemas()?.[fieldId];
|
|
2181
|
+
if (!isFieldEditableInFillMode(schema, {
|
|
2182
|
+
fieldId,
|
|
2183
|
+
fieldSchemas: registry?.getFieldSchemas?.() ?? callbacks.fieldSchemas,
|
|
2184
|
+
})) return currentValue;
|
|
2185
|
+
if (def?.picker === 'child' || schema?.type === 'child') {
|
|
2186
|
+
if (callbacks.openRepeaterEditor) {
|
|
2187
|
+
return callbacks.openRepeaterEditor({
|
|
2188
|
+
fieldId,
|
|
2189
|
+
value: currentValue,
|
|
2190
|
+
title: schema?.label ?? def?.label ?? fieldId,
|
|
2191
|
+
});
|
|
2192
|
+
}
|
|
2193
|
+
return currentValue;
|
|
2194
|
+
}
|
|
2195
|
+
|
|
2196
|
+
const {
|
|
2197
|
+
openTreePicker,
|
|
2198
|
+
openListPicker,
|
|
2199
|
+
openTextPicker,
|
|
2200
|
+
openHtmlTextPicker,
|
|
2201
|
+
openIntegerPicker,
|
|
2202
|
+
openSignaturePicker,
|
|
2203
|
+
openImagePicker,
|
|
2204
|
+
openDatePicker,
|
|
2205
|
+
} = callbacks;
|
|
2206
|
+
|
|
2207
|
+
if (def.picker === 'logical' || schema?.type === 'logical') {
|
|
2208
|
+
const initial = resolvePickerInitialValue(currentValue, fieldId, callbacks);
|
|
2209
|
+
return cycleLogicalValue(initial);
|
|
2210
|
+
}
|
|
2211
|
+
|
|
2212
|
+
if (def.picker === 'integer' && openIntegerPicker) {
|
|
2213
|
+
const initial = resolvePickerInitialValue(currentValue, fieldId, callbacks);
|
|
2214
|
+
return openIntegerPicker({
|
|
2215
|
+
title: def.label,
|
|
2216
|
+
value: initial ?? '',
|
|
2217
|
+
min: def.min ?? 0,
|
|
2218
|
+
max: def.max ?? 999,
|
|
2219
|
+
});
|
|
2220
|
+
}
|
|
2221
|
+
|
|
2222
|
+
if (def.picker === 'text' && (openTextPicker || openHtmlTextPicker)) {
|
|
2223
|
+
const initial = resolvePickerInitialValue(currentValue, fieldId, callbacks);
|
|
2224
|
+
const isDefault = isFieldEmpty(currentValue, { htmlEditor: !!def?.htmlEditor });
|
|
2225
|
+
const opts = {
|
|
2226
|
+
title: def.label,
|
|
2227
|
+
value: String(initial ?? ''),
|
|
2228
|
+
placeholder: def.defaultText ?? '',
|
|
2229
|
+
selectAll: isDefault,
|
|
2230
|
+
};
|
|
2231
|
+
if (def.htmlEditor && openHtmlTextPicker) {
|
|
2232
|
+
return openHtmlTextPicker(opts);
|
|
2233
|
+
}
|
|
2234
|
+
if (openTextPicker) {
|
|
2235
|
+
return openTextPicker(opts);
|
|
2236
|
+
}
|
|
2237
|
+
}
|
|
2238
|
+
|
|
2239
|
+
if (def.picker === 'signature' && openSignaturePicker) {
|
|
2240
|
+
const initial = resolvePickerInitialValue(currentValue, fieldId, callbacks);
|
|
2241
|
+
return openSignaturePicker({
|
|
2242
|
+
title: def.label,
|
|
2243
|
+
value: normalizeImageValue(initial).url,
|
|
2244
|
+
});
|
|
2245
|
+
}
|
|
2246
|
+
|
|
2247
|
+
if (def.picker === 'image' && openImagePicker) {
|
|
2248
|
+
return openImagePicker({
|
|
2249
|
+
title: def.label,
|
|
2250
|
+
value: normalizeImageValue(currentValue),
|
|
2251
|
+
});
|
|
2252
|
+
}
|
|
2253
|
+
|
|
2254
|
+
if (def.picker === 'date' && openDatePicker) {
|
|
2255
|
+
const initial = resolvePickerInitialValue(currentValue, fieldId, callbacks);
|
|
2256
|
+
return openDatePicker({
|
|
2257
|
+
title: def.label,
|
|
2258
|
+
value: String(initial ?? ''),
|
|
2259
|
+
});
|
|
2260
|
+
}
|
|
2261
|
+
|
|
2262
|
+
if (def.picker === 'tree' && openTreePicker) {
|
|
2263
|
+
const initial = resolvePickerInitialValue(currentValue, fieldId, callbacks);
|
|
2264
|
+
return pickWithManualEdit({
|
|
2265
|
+
def,
|
|
2266
|
+
schema,
|
|
2267
|
+
fieldId,
|
|
2268
|
+
currentValue: initial,
|
|
2269
|
+
schemaType: 'tree',
|
|
2270
|
+
openStructured: ({ allowManualEdit: manualEdit, initialText = '' }: any) =>
|
|
2271
|
+
openTreePicker({
|
|
2272
|
+
title: def.label,
|
|
2273
|
+
tree: def.tree,
|
|
2274
|
+
selected: toListPickerSelected(initial),
|
|
2275
|
+
allowManualEdit: manualEdit,
|
|
2276
|
+
initialText,
|
|
2277
|
+
}),
|
|
2278
|
+
});
|
|
2279
|
+
}
|
|
2280
|
+
|
|
2281
|
+
if (def.picker === 'list' && openListPicker) {
|
|
2282
|
+
const initial = resolvePickerInitialValue(currentValue, fieldId, callbacks);
|
|
2283
|
+
const schema = registry.getFieldSchemas()?.[fieldId];
|
|
2284
|
+
const remoteSchema = { ...def, ...(schema || {}) };
|
|
2285
|
+
const isRemote = remoteSchema.listSource === 'remote'
|
|
2286
|
+
|| Boolean(String(remoteSchema.sourceCollection ?? '').trim());
|
|
2287
|
+
const isMulti = def.multi !== false;
|
|
2288
|
+
const schemaType = def.schemaType === 'choice' ? 'choice' : 'list';
|
|
2289
|
+
|
|
2290
|
+
const result = await pickWithManualEdit({
|
|
2291
|
+
def,
|
|
2292
|
+
schema,
|
|
2293
|
+
fieldId,
|
|
2294
|
+
currentValue: initial,
|
|
2295
|
+
schemaType,
|
|
2296
|
+
openStructured: ({ allowManualEdit: manualEdit, initialText = '' }: any) =>
|
|
2297
|
+
openListPicker({
|
|
2298
|
+
title: def.label,
|
|
2299
|
+
items: isRemote ? [] : (def.items ?? []),
|
|
2300
|
+
selected: isMulti ? toListPickerSelected(initial) : (toListPickerSelected(initial)[0] ?? ''),
|
|
2301
|
+
withCode: def.withCode ?? false,
|
|
2302
|
+
multi: isMulti,
|
|
2303
|
+
allowManualEdit: manualEdit,
|
|
2304
|
+
initialText,
|
|
2305
|
+
remoteSearch: isRemote
|
|
2306
|
+
? buildRemoteListSearch(fieldId, remoteSchema, callbacks, toListPickerSelected(initial))
|
|
2307
|
+
: undefined,
|
|
2308
|
+
}),
|
|
2309
|
+
});
|
|
2310
|
+
|
|
2311
|
+
if (isMulti) return result;
|
|
2312
|
+
return Array.isArray(result) ? (result[0] ?? '') : result;
|
|
2313
|
+
}
|
|
2314
|
+
|
|
2315
|
+
return currentValue;
|
|
2316
|
+
}
|
|
2317
|
+
|
|
2318
|
+
export function focusCaretAtEnd(editable: any) {
|
|
2319
|
+
if (!editable?.isConnected) return;
|
|
2320
|
+
try {
|
|
2321
|
+
editable.focus();
|
|
2322
|
+
const range = document.createRange();
|
|
2323
|
+
range.selectNodeContents(editable);
|
|
2324
|
+
range.collapse(false);
|
|
2325
|
+
const sel = window.getSelection();
|
|
2326
|
+
if (!sel) return;
|
|
2327
|
+
sel.removeAllRanges();
|
|
2328
|
+
sel.addRange(range);
|
|
2329
|
+
} catch {
|
|
2330
|
+
// editable may have been removed from the document
|
|
2331
|
+
}
|
|
2332
|
+
}
|
|
2333
|
+
|
|
2334
|
+
export function focusCaretAfter(node: any) {
|
|
2335
|
+
if (!node?.isConnected) return;
|
|
2336
|
+
try {
|
|
2337
|
+
if (isFieldTokenElement(node)) {
|
|
2338
|
+
const anchor = ensureCaretAnchorAfter(node);
|
|
2339
|
+
if (anchor) {
|
|
2340
|
+
focusCaretAtFieldBridge(anchor);
|
|
2341
|
+
return;
|
|
2342
|
+
}
|
|
2343
|
+
}
|
|
2344
|
+
|
|
2345
|
+
// After a line break, land inside the following text so arrow keys can move.
|
|
2346
|
+
const next = node.nextSibling;
|
|
2347
|
+
if (next?.nodeType === Node.TEXT_NODE) {
|
|
2348
|
+
const range = document.createRange();
|
|
2349
|
+
range.setStart(next, 0);
|
|
2350
|
+
range.collapse(true);
|
|
2351
|
+
const sel = window.getSelection();
|
|
2352
|
+
if (!sel) return;
|
|
2353
|
+
sel.removeAllRanges();
|
|
2354
|
+
sel.addRange(range);
|
|
2355
|
+
return;
|
|
2356
|
+
}
|
|
2357
|
+
|
|
2358
|
+
const range = document.createRange();
|
|
2359
|
+
range.setStartAfter(node);
|
|
2360
|
+
range.collapse(true);
|
|
2361
|
+
const sel = window.getSelection();
|
|
2362
|
+
if (!sel) return;
|
|
2363
|
+
sel.removeAllRanges();
|
|
2364
|
+
sel.addRange(range);
|
|
2365
|
+
} catch {
|
|
2366
|
+
// node may have been removed from the document
|
|
2367
|
+
}
|
|
2368
|
+
}
|
|
2369
|
+
|
|
2370
|
+
function rangeIntersectsSelector(range: any, editable: any, selector: any) {
|
|
2371
|
+
if (!range || !editable?.querySelectorAll) return false;
|
|
2372
|
+
for (const el of editable.querySelectorAll(selector)) {
|
|
2373
|
+
if (typeof range.intersectsNode === 'function') {
|
|
2374
|
+
if (range.intersectsNode(el)) return true;
|
|
2375
|
+
continue;
|
|
2376
|
+
}
|
|
2377
|
+
let ancestor = range.commonAncestorContainer;
|
|
2378
|
+
if (ancestor?.nodeType === Node.TEXT_NODE) ancestor = ancestor.parentNode;
|
|
2379
|
+
if (ancestor?.contains?.(el)) return true;
|
|
2380
|
+
}
|
|
2381
|
+
return false;
|
|
2382
|
+
}
|
|
2383
|
+
|
|
2384
|
+
function rangeToPlainText(range: any) {
|
|
2385
|
+
if (!range) return '';
|
|
2386
|
+
try {
|
|
2387
|
+
const direct = typeof range.toString === 'function' ? String(range.toString()) : '';
|
|
2388
|
+
if (direct.trim()) return direct;
|
|
2389
|
+
} catch {
|
|
2390
|
+
// linkedom / incomplete Range
|
|
2391
|
+
}
|
|
2392
|
+
try {
|
|
2393
|
+
const frag = range.cloneContents?.();
|
|
2394
|
+
if (frag) return String(frag.textContent ?? '');
|
|
2395
|
+
} catch {
|
|
2396
|
+
// ignore
|
|
2397
|
+
}
|
|
2398
|
+
return '';
|
|
2399
|
+
}
|
|
2400
|
+
|
|
2401
|
+
/**
|
|
2402
|
+
* Plain text from a non-collapsed selection inside `editable`, suitable for
|
|
2403
|
+
* field name/label when converting selected text into a field.
|
|
2404
|
+
* Returns '' when collapsed, outside editable, or intersecting field tokens / tables.
|
|
2405
|
+
*/
|
|
2406
|
+
export function resolveSelectedTextForFieldConversion(editable: any, range: any = null) {
|
|
2407
|
+
let activeRange = range;
|
|
2408
|
+
if (!activeRange) {
|
|
2409
|
+
const sel = window.getSelection();
|
|
2410
|
+
if (!sel?.rangeCount || sel.isCollapsed) return '';
|
|
2411
|
+
activeRange = sel.getRangeAt(0);
|
|
2412
|
+
}
|
|
2413
|
+
if (!activeRange || activeRange.collapsed) return '';
|
|
2414
|
+
if (!editable?.contains?.(activeRange.commonAncestorContainer)) return '';
|
|
2415
|
+
if (rangeIntersectsSelector(activeRange, editable, '.field-token')) return '';
|
|
2416
|
+
if (rangeIntersectsSelector(activeRange, editable, '.document-table')) return '';
|
|
2417
|
+
|
|
2418
|
+
const fromRange = rangeToPlainText(activeRange).trim();
|
|
2419
|
+
if (fromRange) return fromRange;
|
|
2420
|
+
|
|
2421
|
+
const sel = window.getSelection();
|
|
2422
|
+
const fromSel = typeof sel?.toString === 'function' ? String(sel.toString()) : '';
|
|
2423
|
+
return fromSel.trim();
|
|
2424
|
+
}
|
|
2425
|
+
|
|
2426
|
+
export async function insertInlineField(editable: any, fieldType: any, options: any = {}) {
|
|
2427
|
+
if (fieldType === 'table') {
|
|
2428
|
+
throw new Error(`${fieldType} must be inserted as a block, not an inline field.`);
|
|
2429
|
+
}
|
|
2430
|
+
const { designMode, onEditSchema, onDeleteField, openEditor = true, designPropertiesPanel } = options;
|
|
2431
|
+
const registry = registryFrom(options) ?? getRegistryFromNode(editable);
|
|
2432
|
+
const registryCtx = registry ? { getRegistry: () => registry } : options;
|
|
2433
|
+
|
|
2434
|
+
// Capture before focus/async work can collapse the selection.
|
|
2435
|
+
const savedRange = options.savedRange ?? saveSelection(editable);
|
|
2436
|
+
const preferredLabel =
|
|
2437
|
+
(typeof options.preferredLabel === 'string' && options.preferredLabel.trim()) ||
|
|
2438
|
+
resolveSelectedTextForFieldConversion(editable, savedRange) ||
|
|
2439
|
+
'';
|
|
2440
|
+
const { label: defaultLabel } = createDefaultBlockData(fieldType);
|
|
2441
|
+
const label = preferredLabel || defaultLabel;
|
|
2442
|
+
|
|
2443
|
+
const schema = createDefaultSchema(fieldType, label, label);
|
|
2444
|
+
const { fieldId, fieldName } = allocateFieldIdentity(editable, registry, schema.name as string);
|
|
2445
|
+
schema.name = fieldName;
|
|
2446
|
+
registry?.updateFieldSchema(fieldId, schema);
|
|
2447
|
+
|
|
2448
|
+
// Restore the original range so insert replaces selected text with the field.
|
|
2449
|
+
if (savedRange && !savedRange.collapsed && preferredLabel) {
|
|
2450
|
+
restoreSelection(savedRange);
|
|
2451
|
+
}
|
|
2452
|
+
|
|
2453
|
+
const initialValue = fieldType === 'child' ? createInlineRepeaterSeedValue(schema) : '';
|
|
2454
|
+
const token = insertFieldAtCaret(editable, fieldId, schema.label, registryCtx, initialValue);
|
|
2455
|
+
if (designMode) {
|
|
2456
|
+
wireDesignFieldToken(token, { onEditSchema, onDeleteField, designPropertiesPanel });
|
|
2457
|
+
}
|
|
2458
|
+
|
|
2459
|
+
if (onEditSchema && openEditor) {
|
|
2460
|
+
await onEditSchema(fieldId);
|
|
2461
|
+
}
|
|
2462
|
+
|
|
2463
|
+
const fieldLabel = registry?.getFieldSchemas()?.[fieldId]?.label || schema.label;
|
|
2464
|
+
updateFieldToken(token, initialValue, fieldLabel, registryCtx);
|
|
2465
|
+
|
|
2466
|
+
return { fieldId, token, schema };
|
|
2467
|
+
}
|
|
2468
|
+
|
|
2469
|
+
export function insertFieldAtCaret(editable: any, fieldId: any, placeholder: any, context: any, initialValue: any = '') {
|
|
2470
|
+
const token = createFieldToken(fieldId, initialValue, placeholder, context);
|
|
2471
|
+
token.classList.add('field-token--design');
|
|
2472
|
+
insertFieldTokenAtCaret(editable, token);
|
|
2473
|
+
updateFieldToken(token, initialValue, placeholder, context);
|
|
2474
|
+
return token;
|
|
2475
|
+
}
|
|
2476
|
+
|
|
2477
|
+
export function insertLineBreakAtCaret(editable: any) {
|
|
2478
|
+
const br = document.createElement('br');
|
|
2479
|
+
const sel = window.getSelection();
|
|
2480
|
+
|
|
2481
|
+
if (!sel?.rangeCount || !editable.contains(sel.anchorNode)) {
|
|
2482
|
+
editable.appendChild(br);
|
|
2483
|
+
ensureTrailingLineBreak(br);
|
|
2484
|
+
focusCaretAfter(br);
|
|
2485
|
+
return br;
|
|
2486
|
+
}
|
|
2487
|
+
|
|
2488
|
+
const range = sel.getRangeAt(0);
|
|
2489
|
+
range.deleteContents();
|
|
2490
|
+
range.insertNode(br);
|
|
2491
|
+
ensureTrailingLineBreak(br);
|
|
2492
|
+
focusCaretAfter(br);
|
|
2493
|
+
return br;
|
|
2494
|
+
}
|
|
2495
|
+
|
|
2496
|
+
/**
|
|
2497
|
+
* Insert clipboard/plain text at the caret as text + `<br>` lines
|
|
2498
|
+
* (same structure as Enter in design mode — not browser `<div>` blocks).
|
|
2499
|
+
*/
|
|
2500
|
+
export function insertPlainTextAtCaret(editable: any, text: any) {
|
|
2501
|
+
const normalized = String(text ?? '')
|
|
2502
|
+
.replace(/\r\n/g, '\n')
|
|
2503
|
+
.replace(/\r/g, '\n');
|
|
2504
|
+
if (!normalized) return null;
|
|
2505
|
+
|
|
2506
|
+
const fragment = textToFragment(normalized);
|
|
2507
|
+
if (!fragment.childNodes.length) return null;
|
|
2508
|
+
|
|
2509
|
+
const sel = window.getSelection();
|
|
2510
|
+
if (!sel?.rangeCount || !editable.contains(sel.anchorNode)) {
|
|
2511
|
+
const last = fragment.lastChild;
|
|
2512
|
+
editable.appendChild(fragment);
|
|
2513
|
+
if (last?.nodeName === 'BR') ensureTrailingLineBreak(last);
|
|
2514
|
+
if (last) focusCaretAfter(last);
|
|
2515
|
+
return last;
|
|
2516
|
+
}
|
|
2517
|
+
|
|
2518
|
+
const range = sel.getRangeAt(0);
|
|
2519
|
+
if (range.startContainer?.parentElement?.closest?.('.field-token')) {
|
|
2520
|
+
return null;
|
|
2521
|
+
}
|
|
2522
|
+
|
|
2523
|
+
range.deleteContents();
|
|
2524
|
+
const last = fragment.lastChild;
|
|
2525
|
+
range.insertNode(fragment);
|
|
2526
|
+
if (last?.nodeName === 'BR') ensureTrailingLineBreak(last);
|
|
2527
|
+
if (last) focusCaretAfter(last);
|
|
2528
|
+
return last;
|
|
2529
|
+
}
|
|
2530
|
+
|
|
2531
|
+
/** Browsers won't show a caret on a new line after a lone trailing `<br>`. */
|
|
2532
|
+
function ensureTrailingLineBreak(br: any) {
|
|
2533
|
+
if (!br.nextSibling) {
|
|
2534
|
+
br.after(document.createElement('br'));
|
|
2535
|
+
}
|
|
2536
|
+
}
|
|
2537
|
+
|
|
2538
|
+
export function insertFieldTokenAtCaret(editable: any, token: any) {
|
|
2539
|
+
const sel = window.getSelection();
|
|
2540
|
+
if (!sel?.rangeCount || !editable.contains(sel.anchorNode)) {
|
|
2541
|
+
editable.appendChild(token);
|
|
2542
|
+
ensureFieldTokenCaretAnchors(editable);
|
|
2543
|
+
focusCaretAfter(token);
|
|
2544
|
+
return token;
|
|
2545
|
+
}
|
|
2546
|
+
|
|
2547
|
+
const range = sel.getRangeAt(0);
|
|
2548
|
+
range.deleteContents();
|
|
2549
|
+
range.insertNode(token);
|
|
2550
|
+
ensureFieldTokenCaretAnchors(editable);
|
|
2551
|
+
focusCaretAfter(token);
|
|
2552
|
+
return token;
|
|
2553
|
+
}
|
|
2554
|
+
|
|
2555
|
+
function insertBlockAtCaret(sectionBody: any, node: any) {
|
|
2556
|
+
const sel = window.getSelection();
|
|
2557
|
+
if (!sel?.rangeCount || !sectionBody.contains(sel.anchorNode)) {
|
|
2558
|
+
sectionBody.appendChild(node);
|
|
2559
|
+
focusCaretAfter(node);
|
|
2560
|
+
return node;
|
|
2561
|
+
}
|
|
2562
|
+
|
|
2563
|
+
const range = sel.getRangeAt(0);
|
|
2564
|
+
const anchor =
|
|
2565
|
+
range.commonAncestorContainer.nodeType === Node.TEXT_NODE
|
|
2566
|
+
? range.commonAncestorContainer.parentNode
|
|
2567
|
+
: range.commonAncestorContainer;
|
|
2568
|
+
|
|
2569
|
+
if (shouldInsertInsideColumn(sectionBody, anchor)) {
|
|
2570
|
+
range.deleteContents();
|
|
2571
|
+
range.insertNode(node);
|
|
2572
|
+
focusCaretAfter(node);
|
|
2573
|
+
return node;
|
|
2574
|
+
}
|
|
2575
|
+
|
|
2576
|
+
const enclosingColumns = (anchor as any)?.closest?.('.document-columns');
|
|
2577
|
+
const enclosingTable = (anchor as any)?.closest?.('.document-table');
|
|
2578
|
+
|
|
2579
|
+
if (enclosingColumns && sectionBody.contains(enclosingColumns)) {
|
|
2580
|
+
enclosingColumns.insertAdjacentElement('afterend', node);
|
|
2581
|
+
focusCaretAfter(node);
|
|
2582
|
+
return node;
|
|
2583
|
+
}
|
|
2584
|
+
|
|
2585
|
+
if (enclosingTable && sectionBody.contains(enclosingTable)) {
|
|
2586
|
+
enclosingTable.insertAdjacentElement('afterend', node);
|
|
2587
|
+
focusCaretAfter(node);
|
|
2588
|
+
return node;
|
|
2589
|
+
}
|
|
2590
|
+
|
|
2591
|
+
range.deleteContents();
|
|
2592
|
+
range.insertNode(node);
|
|
2593
|
+
focusCaretAfter(node);
|
|
2594
|
+
return node;
|
|
2595
|
+
}
|
|
2596
|
+
|
|
2597
|
+
export function insertColumnsAtCaret(sectionBody: any, options: any = {}) {
|
|
2598
|
+
const columnsEl = renderColumnsSegment(createEmptyColumnsSegment(), {}, options);
|
|
2599
|
+
insertBlockAtCaret(sectionBody, columnsEl);
|
|
2600
|
+
wireColumnBlockRegions(sectionBody, options);
|
|
2601
|
+
return columnsEl;
|
|
2602
|
+
}
|
|
2603
|
+
|
|
2604
|
+
function placeNodeAtPoint(sectionBody: any, node: any, clientX: any, clientY: any) {
|
|
2605
|
+
const editableRoot = resolveFieldEditableRoot(sectionBody, clientX, clientY);
|
|
2606
|
+
const target = resolveInlineDropTarget(editableRoot, null, clientX, clientY);
|
|
2607
|
+
if (target) {
|
|
2608
|
+
return applyInlineDropTarget(editableRoot, node, target);
|
|
2609
|
+
}
|
|
2610
|
+
editableRoot.appendChild(node);
|
|
2611
|
+
ensureFieldTokenCaretAnchors(editableRoot);
|
|
2612
|
+
focusCaretAfter(node);
|
|
2613
|
+
return true;
|
|
2614
|
+
}
|
|
2615
|
+
|
|
2616
|
+
export async function insertPaletteFieldAtPoint(editable: any, fieldType: any, clientX: any, clientY: any, options: any = {}) {
|
|
2617
|
+
if (fieldType === 'table') {
|
|
2618
|
+
return insertPaletteTableAtPoint(editable, clientX, clientY, options);
|
|
2619
|
+
}
|
|
2620
|
+
const { designMode, onEditSchema, onDeleteField, openEditor = true, designPropertiesPanel } = options;
|
|
2621
|
+
const registry = registryFrom(options) ?? getRegistryFromNode(editable);
|
|
2622
|
+
const registryCtx = registry ? { getRegistry: () => registry } : options;
|
|
2623
|
+
const defaults = createDefaultBlockData(fieldType);
|
|
2624
|
+
const label =
|
|
2625
|
+
typeof options.label === 'string' && options.label.trim()
|
|
2626
|
+
? options.label.trim()
|
|
2627
|
+
: defaults.label;
|
|
2628
|
+
const schema = createDefaultSchema(fieldType, label, label);
|
|
2629
|
+
if (options.readonly === true) {
|
|
2630
|
+
schema.readonly = true;
|
|
2631
|
+
}
|
|
2632
|
+
const { fieldId, fieldName } = allocateFieldIdentity(editable, registry, schema.name as string);
|
|
2633
|
+
schema.name = fieldName;
|
|
2634
|
+
registry?.updateFieldSchema(fieldId, schema);
|
|
2635
|
+
|
|
2636
|
+
const initialValue = fieldType === 'child' ? createInlineRepeaterSeedValue(schema) : '';
|
|
2637
|
+
const token = createFieldToken(fieldId, initialValue, schema.label, registryCtx);
|
|
2638
|
+
token.classList.add('field-token--design');
|
|
2639
|
+
placeNodeAtPoint(editable, token, clientX, clientY);
|
|
2640
|
+
|
|
2641
|
+
// Database → canvas: insert visible "Label: " text before the field token.
|
|
2642
|
+
if (options.insertVisibleLabel === true && label) {
|
|
2643
|
+
const parent = token.parentNode;
|
|
2644
|
+
if (parent) {
|
|
2645
|
+
parent.insertBefore(document.createTextNode(`${label}: `), token);
|
|
2646
|
+
ensureFieldTokenCaretAnchors(parent);
|
|
2647
|
+
}
|
|
2648
|
+
}
|
|
2649
|
+
|
|
2650
|
+
if (designMode) {
|
|
2651
|
+
wireDesignFieldToken(token, { onEditSchema, onDeleteField, designPropertiesPanel });
|
|
2652
|
+
}
|
|
2653
|
+
|
|
2654
|
+
if (onEditSchema && openEditor) {
|
|
2655
|
+
await onEditSchema(fieldId);
|
|
2656
|
+
}
|
|
2657
|
+
|
|
2658
|
+
const fieldLabel = registry?.getFieldSchemas()?.[fieldId]?.label || schema.label;
|
|
2659
|
+
updateFieldToken(token, initialValue, fieldLabel, registryCtx);
|
|
2660
|
+
|
|
2661
|
+
return { fieldId, token, schema };
|
|
2662
|
+
}
|
|
2663
|
+
|
|
2664
|
+
export function insertColumnsAtPoint(sectionBody: any, clientX: any, clientY: any, options: any = {}) {
|
|
2665
|
+
const columnsEl = renderColumnsSegment(createEmptyColumnsSegment(), {}, options);
|
|
2666
|
+
placeNodeAtPoint(sectionBody, columnsEl, clientX, clientY);
|
|
2667
|
+
wireColumnBlockRegions(sectionBody, options);
|
|
2668
|
+
sectionBody.dispatchEvent(new InputEvent('input', { bubbles: true }));
|
|
2669
|
+
return columnsEl;
|
|
2670
|
+
}
|
|
2671
|
+
|
|
2672
|
+
export async function insertPaletteTableAtPoint(sectionBody: any, clientX: any, clientY: any, options: any = {}) {
|
|
2673
|
+
const registry = registryFrom(options);
|
|
2674
|
+
const fieldType = options.fieldType === 'pivotTable' ? 'pivotTable' : 'table';
|
|
2675
|
+
const defaultLabel =
|
|
2676
|
+
typeof options.label === 'string' && options.label.trim()
|
|
2677
|
+
? options.label.trim()
|
|
2678
|
+
: fieldType === 'pivotTable'
|
|
2679
|
+
? 'Pivot Table'
|
|
2680
|
+
: 'Table';
|
|
2681
|
+
const schema = createDefaultSchema(fieldType, defaultLabel, defaultLabel);
|
|
2682
|
+
if (options.readonly === true) {
|
|
2683
|
+
schema.readonly = true;
|
|
2684
|
+
}
|
|
2685
|
+
if (Array.isArray(options.columns) && options.columns.length) {
|
|
2686
|
+
schema.columns = options.columns.map((col: any) => ({
|
|
2687
|
+
key: col.key,
|
|
2688
|
+
label: col.label ?? col.key,
|
|
2689
|
+
name: col.name ?? col.label ?? col.key,
|
|
2690
|
+
}));
|
|
2691
|
+
}
|
|
2692
|
+
const { fieldId, fieldName } = allocateFieldIdentity(sectionBody, registry, schema.name as string);
|
|
2693
|
+
schema.name = fieldName;
|
|
2694
|
+
registry?.updateFieldSchema(fieldId, schema);
|
|
2695
|
+
|
|
2696
|
+
let seedRows: Array<{ key: string; label: string }> | undefined;
|
|
2697
|
+
if (fieldType === 'table') {
|
|
2698
|
+
seedRows = [{ key: 'row1', label: '' }];
|
|
2699
|
+
const merged = ensureCellSchemasForRows(schema, fieldId, registry?.getFieldSchemas() ?? {}, seedRows);
|
|
2700
|
+
registry?.setFieldSchemas?.(merged);
|
|
2701
|
+
}
|
|
2702
|
+
|
|
2703
|
+
const tableEl = renderTableSegment(
|
|
2704
|
+
{ type: 'table', id: fieldId, rows: seedRows },
|
|
2705
|
+
{},
|
|
2706
|
+
options,
|
|
2707
|
+
);
|
|
2708
|
+
placeNodeAtPoint(sectionBody, tableEl, clientX, clientY);
|
|
2709
|
+
wireTableRegions(sectionBody, options);
|
|
2710
|
+
sectionBody.dispatchEvent(new InputEvent('input', { bubbles: true }));
|
|
2711
|
+
|
|
2712
|
+
const { onEditSchema, openEditor = true } = options;
|
|
2713
|
+
if (onEditSchema && openEditor) {
|
|
2714
|
+
await onEditSchema(fieldId);
|
|
2715
|
+
}
|
|
2716
|
+
|
|
2717
|
+
return { fieldId, tableEl };
|
|
2718
|
+
}
|
|
2719
|
+
|
|
2720
|
+
export async function insertPaletteRepeaterAtPoint(sectionBody: any, clientX: any, clientY: any, options: any = {}) {
|
|
2721
|
+
return insertPaletteFieldAtPoint(sectionBody, 'child', clientX, clientY, options);
|
|
2722
|
+
}
|
|
2723
|
+
|
|
2724
|
+
export async function insertRepeaterAtCaret(sectionBody: any, options: any = {}) {
|
|
2725
|
+
return insertInlineField(sectionBody, 'child', options);
|
|
2726
|
+
}
|
|
2727
|
+
|
|
2728
|
+
function isPaletteDragEvent(e: any) {
|
|
2729
|
+
return isPaletteDragSessionActive() || e.dataTransfer?.types?.includes?.(PALETTE_DRAG_MIME);
|
|
2730
|
+
}
|
|
2731
|
+
|
|
2732
|
+
function wirePaletteDropGuard(element: any) {
|
|
2733
|
+
if (!element || element.dataset.paletteDropGuardWired === 'true') return;
|
|
2734
|
+
element.dataset.paletteDropGuardWired = 'true';
|
|
2735
|
+
|
|
2736
|
+
element.addEventListener(
|
|
2737
|
+
'beforeinput',
|
|
2738
|
+
(e: any) => {
|
|
2739
|
+
if (e.inputType !== 'insertFromDrop') return;
|
|
2740
|
+
if (
|
|
2741
|
+
!isInternalDragActive() &&
|
|
2742
|
+
!isPaletteDragSessionActive() &&
|
|
2743
|
+
!isSourcePathDragEvent(e.dataTransfer)
|
|
2744
|
+
) {
|
|
2745
|
+
return;
|
|
2746
|
+
}
|
|
2747
|
+
e.preventDefault();
|
|
2748
|
+
},
|
|
2749
|
+
true,
|
|
2750
|
+
);
|
|
2751
|
+
}
|
|
2752
|
+
|
|
2753
|
+
export function insertTableAtCaret(sectionBody: any, options: any = {}) {
|
|
2754
|
+
const registry = registryFrom(options);
|
|
2755
|
+
const fieldType = options.fieldType === 'pivotTable' ? 'pivotTable' : 'table';
|
|
2756
|
+
const defaultLabel = fieldType === 'pivotTable' ? 'Pivot Table' : 'Table';
|
|
2757
|
+
const schema = createDefaultSchema(fieldType, defaultLabel, defaultLabel);
|
|
2758
|
+
const { fieldId, fieldName } = allocateFieldIdentity(sectionBody, registry, schema.name as string);
|
|
2759
|
+
schema.name = fieldName;
|
|
2760
|
+
registry?.updateFieldSchema(fieldId, schema);
|
|
2761
|
+
|
|
2762
|
+
let seedRows: Array<{ key: string; label: string }> | undefined;
|
|
2763
|
+
if (fieldType === 'table') {
|
|
2764
|
+
seedRows = [{ key: 'row1', label: '' }];
|
|
2765
|
+
const merged = ensureCellSchemasForRows(schema, fieldId, registry?.getFieldSchemas() ?? {}, seedRows);
|
|
2766
|
+
registry?.setFieldSchemas?.(merged);
|
|
2767
|
+
}
|
|
2768
|
+
|
|
2769
|
+
const tableEl = renderTableSegment(
|
|
2770
|
+
{ type: 'table', id: fieldId, rows: seedRows },
|
|
2771
|
+
{},
|
|
2772
|
+
options,
|
|
2773
|
+
);
|
|
2774
|
+
insertBlockAtCaret(sectionBody, tableEl);
|
|
2775
|
+
return { fieldId, tableEl };
|
|
2776
|
+
}
|
|
2777
|
+
|
|
2778
|
+
function ensureToolbarDragHandle(blockEl: any, action: any) {
|
|
2779
|
+
const toolbar = blockEl?.querySelector?.(
|
|
2780
|
+
action === 'drag-table' ? ':scope > .document-table__toolbar' : ':scope > .document-columns__toolbar',
|
|
2781
|
+
);
|
|
2782
|
+
const handle = blockEl?.querySelector?.(`[data-action="${action}"]`);
|
|
2783
|
+
if (!toolbar || !handle) return handle;
|
|
2784
|
+
|
|
2785
|
+
if (handle.parentElement !== toolbar) {
|
|
2786
|
+
const deleteBtn = toolbar.querySelector(
|
|
2787
|
+
action === 'drag-table' ? '[data-action="delete-table"]' : '[data-action="delete-columns"]',
|
|
2788
|
+
);
|
|
2789
|
+
if (deleteBtn) toolbar.insertBefore(handle, deleteBtn);
|
|
2790
|
+
else toolbar.appendChild(handle);
|
|
2791
|
+
} else {
|
|
2792
|
+
const deleteBtn = toolbar.querySelector(
|
|
2793
|
+
action === 'drag-table' ? '[data-action="delete-table"]' : '[data-action="delete-columns"]',
|
|
2794
|
+
);
|
|
2795
|
+
if (deleteBtn && handle.nextElementSibling !== deleteBtn) {
|
|
2796
|
+
toolbar.insertBefore(handle, deleteBtn);
|
|
2797
|
+
}
|
|
2798
|
+
}
|
|
2799
|
+
|
|
2800
|
+
return handle;
|
|
2801
|
+
}
|
|
2802
|
+
|
|
2803
|
+
function removeOwnedSchemasFromDomSubtree(root: any, options: any = {}) {
|
|
2804
|
+
const registry = resolveRegistry(options);
|
|
2805
|
+
if (!registry || !root?.querySelectorAll) return;
|
|
2806
|
+
|
|
2807
|
+
const next = { ...registry.getFieldSchemas() };
|
|
2808
|
+
let changed = false;
|
|
2809
|
+
|
|
2810
|
+
const tableIds = new Set<string>();
|
|
2811
|
+
root.querySelectorAll('.document-table[data-table-id]').forEach((el: any) => {
|
|
2812
|
+
if (el.dataset.tableId) tableIds.add(el.dataset.tableId);
|
|
2813
|
+
});
|
|
2814
|
+
if (root.classList?.contains('document-table') && root.dataset?.tableId) {
|
|
2815
|
+
tableIds.add(root.dataset.tableId);
|
|
2816
|
+
}
|
|
2817
|
+
|
|
2818
|
+
for (const tableId of tableIds) {
|
|
2819
|
+
if (next[tableId]) {
|
|
2820
|
+
delete next[tableId];
|
|
2821
|
+
changed = true;
|
|
2822
|
+
}
|
|
2823
|
+
const prefix = `${tableId}_`;
|
|
2824
|
+
for (const key of Object.keys(next)) {
|
|
2825
|
+
if (!key.startsWith(prefix)) continue;
|
|
2826
|
+
delete next[key];
|
|
2827
|
+
changed = true;
|
|
2828
|
+
}
|
|
2829
|
+
}
|
|
2830
|
+
|
|
2831
|
+
root.querySelectorAll('.field-token[data-field-id]:not(.field-token--cell)').forEach((token: any) => {
|
|
2832
|
+
const fieldId = token.dataset.fieldId;
|
|
2833
|
+
if (!fieldId || tableIds.has(fieldId) || !next[fieldId]) return;
|
|
2834
|
+
delete next[fieldId];
|
|
2835
|
+
changed = true;
|
|
2836
|
+
});
|
|
2837
|
+
|
|
2838
|
+
if (!changed) return;
|
|
2839
|
+
registry.setFieldSchemas(next);
|
|
2840
|
+
options.onSchemaChange?.(next);
|
|
2841
|
+
}
|
|
2842
|
+
let draggedTableEl: any = null;
|
|
2843
|
+
let draggedColumnsEl: any = null;
|
|
2844
|
+
let draggedFieldToken: any = null;
|
|
2845
|
+
|
|
2846
|
+
const INTERNAL_DRAG_MIME = 'application/x-doc-editor-dnd';
|
|
2847
|
+
const DROP_INDICATOR_SELECTOR =
|
|
2848
|
+
'.field-token--design.is-drop-before, .field-token--design.is-drop-after, .document-table.is-drop-after, .document-columns.is-drop-after';
|
|
2849
|
+
|
|
2850
|
+
let dropCaretEl: any = null;
|
|
2851
|
+
|
|
2852
|
+
function isInternalDragActive() {
|
|
2853
|
+
return Boolean(draggedTableEl || draggedColumnsEl || draggedFieldToken);
|
|
2854
|
+
}
|
|
2855
|
+
|
|
2856
|
+
function setInternalDragData(e: any, payload: any) {
|
|
2857
|
+
e.dataTransfer.setData(INTERNAL_DRAG_MIME, payload);
|
|
2858
|
+
e.dataTransfer.setData('text/plain', '');
|
|
2859
|
+
}
|
|
2860
|
+
|
|
2861
|
+
function caretRangeFromPoint(clientX: any, clientY: any) {
|
|
2862
|
+
if (document.caretRangeFromPoint) {
|
|
2863
|
+
return document.caretRangeFromPoint(clientX, clientY);
|
|
2864
|
+
}
|
|
2865
|
+
if (document.caretPositionFromPoint) {
|
|
2866
|
+
const pos = document.caretPositionFromPoint(clientX, clientY);
|
|
2867
|
+
if (!pos) return null;
|
|
2868
|
+
const range = document.createRange();
|
|
2869
|
+
range.setStart(pos.offsetNode, pos.offset);
|
|
2870
|
+
range.collapse(true);
|
|
2871
|
+
return range;
|
|
2872
|
+
}
|
|
2873
|
+
return null;
|
|
2874
|
+
}
|
|
2875
|
+
|
|
2876
|
+
function dropAnchorFromRange(range: any) {
|
|
2877
|
+
if (!range) return null;
|
|
2878
|
+
return range.commonAncestorContainer.nodeType === Node.TEXT_NODE
|
|
2879
|
+
? range.commonAncestorContainer.parentNode
|
|
2880
|
+
: range.commonAncestorContainer;
|
|
2881
|
+
}
|
|
2882
|
+
|
|
2883
|
+
function resolveInlineDropTarget(editableRoot: any, draggedEl: any, clientX: any, clientY: any) {
|
|
2884
|
+
const range = caretRangeFromPoint(clientX, clientY);
|
|
2885
|
+
const dropAnchor = dropAnchorFromRange(range);
|
|
2886
|
+
|
|
2887
|
+
const anchorInside =
|
|
2888
|
+
(dropAnchor && editableRoot.contains(dropAnchor)) ||
|
|
2889
|
+
(range && editableRoot.contains(range.commonAncestorContainer));
|
|
2890
|
+
|
|
2891
|
+
if (!anchorInside) {
|
|
2892
|
+
// Pointer is over this section (header/chrome/padding) but not a caret position —
|
|
2893
|
+
// still allow a drop at the end so cross-section moves work reliably.
|
|
2894
|
+
const rect = editableRoot.getBoundingClientRect?.();
|
|
2895
|
+
if (
|
|
2896
|
+
rect &&
|
|
2897
|
+
clientX >= rect.left &&
|
|
2898
|
+
clientX <= rect.right &&
|
|
2899
|
+
clientY >= rect.top &&
|
|
2900
|
+
clientY <= rect.bottom
|
|
2901
|
+
) {
|
|
2902
|
+
return { mode: 'append' };
|
|
2903
|
+
}
|
|
2904
|
+
|
|
2905
|
+
const section = editableRoot.closest?.('.document-section');
|
|
2906
|
+
const sectionRect = section?.getBoundingClientRect?.();
|
|
2907
|
+
if (
|
|
2908
|
+
sectionRect &&
|
|
2909
|
+
clientX >= sectionRect.left &&
|
|
2910
|
+
clientX <= sectionRect.right &&
|
|
2911
|
+
clientY >= sectionRect.top &&
|
|
2912
|
+
clientY <= sectionRect.bottom
|
|
2913
|
+
) {
|
|
2914
|
+
return { mode: 'append' };
|
|
2915
|
+
}
|
|
2916
|
+
|
|
2917
|
+
return null;
|
|
2918
|
+
}
|
|
2919
|
+
|
|
2920
|
+
if (draggedEl && (draggedEl === dropAnchor || draggedEl.contains(dropAnchor))) {
|
|
2921
|
+
return null;
|
|
2922
|
+
}
|
|
2923
|
+
|
|
2924
|
+
const enclosingTable = dropAnchor.closest?.('.document-table');
|
|
2925
|
+
if (enclosingTable && editableRoot.contains(enclosingTable) && enclosingTable !== draggedEl) {
|
|
2926
|
+
return { mode: 'after', element: enclosingTable };
|
|
2927
|
+
}
|
|
2928
|
+
|
|
2929
|
+
const enclosingColumns = dropAnchor.closest?.('.document-columns');
|
|
2930
|
+
if (enclosingColumns && editableRoot.contains(enclosingColumns) && enclosingColumns !== draggedEl) {
|
|
2931
|
+
return { mode: 'after', element: enclosingColumns };
|
|
2932
|
+
}
|
|
2933
|
+
|
|
2934
|
+
const enclosingToken = dropAnchor.closest?.('.field-token');
|
|
2935
|
+
if (enclosingToken && enclosingToken !== draggedEl && editableRoot.contains(enclosingToken)) {
|
|
2936
|
+
const rect = enclosingToken.getBoundingClientRect();
|
|
2937
|
+
const offset = clientY - rect.top;
|
|
2938
|
+
const zone = rect.height * 0.25;
|
|
2939
|
+
if (offset < zone) {
|
|
2940
|
+
return { mode: 'before', element: enclosingToken };
|
|
2941
|
+
}
|
|
2942
|
+
return { mode: 'after', element: enclosingToken };
|
|
2943
|
+
}
|
|
2944
|
+
|
|
2945
|
+
if (!range) {
|
|
2946
|
+
return { mode: 'append' };
|
|
2947
|
+
}
|
|
2948
|
+
|
|
2949
|
+
const cloned = range.cloneRange();
|
|
2950
|
+
cloned.collapse(true);
|
|
2951
|
+
return { mode: 'range', range: cloned };
|
|
2952
|
+
}
|
|
2953
|
+
|
|
2954
|
+
function applyInlineDropTarget(editableRoot: any, node: any, target: any) {
|
|
2955
|
+
if (!target) return false;
|
|
2956
|
+
|
|
2957
|
+
if (target.mode === 'append') {
|
|
2958
|
+
editableRoot.appendChild(node);
|
|
2959
|
+
} else if (target.mode === 'before') {
|
|
2960
|
+
target.element.parentNode.insertBefore(node, target.element);
|
|
2961
|
+
} else if (target.mode === 'after') {
|
|
2962
|
+
insertElementAfterPreservingCaretBridge(target.element, node);
|
|
2963
|
+
} else {
|
|
2964
|
+
const range = target.range;
|
|
2965
|
+
if (!range || !editableRoot.contains(range.commonAncestorContainer)) {
|
|
2966
|
+
editableRoot.appendChild(node);
|
|
2967
|
+
} else {
|
|
2968
|
+
range.collapse(true);
|
|
2969
|
+
range.insertNode(node);
|
|
2970
|
+
}
|
|
2971
|
+
}
|
|
2972
|
+
|
|
2973
|
+
// Repair bridges for every field in the editable — drop/insert can leave
|
|
2974
|
+
// adjacent contenteditable=false tokens with no ZWSP between them.
|
|
2975
|
+
ensureFieldTokenCaretAnchors(editableRoot);
|
|
2976
|
+
focusCaretAfter(node);
|
|
2977
|
+
return true;
|
|
2978
|
+
}
|
|
2979
|
+
|
|
2980
|
+
function ensureDropCaret() {
|
|
2981
|
+
if (!dropCaretEl) {
|
|
2982
|
+
dropCaretEl = document.createElement('div');
|
|
2983
|
+
dropCaretEl.className = 'editor-drop-caret';
|
|
2984
|
+
dropCaretEl.style.display = 'none';
|
|
2985
|
+
document.body.appendChild(dropCaretEl);
|
|
2986
|
+
}
|
|
2987
|
+
return dropCaretEl;
|
|
2988
|
+
}
|
|
2989
|
+
|
|
2990
|
+
function clearDropIndicators() {
|
|
2991
|
+
if (dropCaretEl) {
|
|
2992
|
+
dropCaretEl.style.display = 'none';
|
|
2993
|
+
}
|
|
2994
|
+
for (const el of document.querySelectorAll(DROP_INDICATOR_SELECTOR)) {
|
|
2995
|
+
el.classList.remove('is-drop-before', 'is-drop-after');
|
|
2996
|
+
}
|
|
2997
|
+
}
|
|
2998
|
+
|
|
2999
|
+
function showDropIndicator(target: any) {
|
|
3000
|
+
clearDropIndicators();
|
|
3001
|
+
if (!target || target.mode === 'append') return;
|
|
3002
|
+
|
|
3003
|
+
if (target.mode === 'range') {
|
|
3004
|
+
const rect = target.range.getBoundingClientRect();
|
|
3005
|
+
const caret = ensureDropCaret();
|
|
3006
|
+
caret.style.display = 'block';
|
|
3007
|
+
caret.style.left = `${rect.left}px`;
|
|
3008
|
+
caret.style.top = `${rect.top}px`;
|
|
3009
|
+
caret.style.height = `${Math.max(rect.height, 18)}px`;
|
|
3010
|
+
return;
|
|
3011
|
+
}
|
|
3012
|
+
|
|
3013
|
+
if (target.mode === 'before') {
|
|
3014
|
+
target.element.classList.add('is-drop-before');
|
|
3015
|
+
return;
|
|
3016
|
+
}
|
|
3017
|
+
|
|
3018
|
+
target.element?.classList?.add('is-drop-after');
|
|
3019
|
+
}
|
|
3020
|
+
|
|
3021
|
+
function resolveFieldEditableRoot(sectionBody: any, clientX: any, clientY: any) {
|
|
3022
|
+
const range = caretRangeFromPoint(clientX, clientY);
|
|
3023
|
+
const dropAnchor = dropAnchorFromRange(range);
|
|
3024
|
+
const col = dropAnchor?.closest?.('.document-columns__col');
|
|
3025
|
+
return col && sectionBody.contains(col) ? col : sectionBody;
|
|
3026
|
+
}
|
|
3027
|
+
|
|
3028
|
+
function updateDropIndicator(container: any, clientX: any, clientY: any) {
|
|
3029
|
+
if (draggedFieldToken) {
|
|
3030
|
+
const editableRoot = resolveFieldEditableRoot(container, clientX, clientY);
|
|
3031
|
+
showDropIndicator(resolveInlineDropTarget(editableRoot, draggedFieldToken, clientX, clientY));
|
|
3032
|
+
return;
|
|
3033
|
+
}
|
|
3034
|
+
|
|
3035
|
+
const dragged = draggedTableEl || draggedColumnsEl;
|
|
3036
|
+
if (dragged) {
|
|
3037
|
+
showDropIndicator(resolveInlineDropTarget(container, dragged, clientX, clientY));
|
|
3038
|
+
return;
|
|
3039
|
+
}
|
|
3040
|
+
|
|
3041
|
+
const editableRoot = resolveFieldEditableRoot(container, clientX, clientY);
|
|
3042
|
+
showDropIndicator(resolveInlineDropTarget(editableRoot, null, clientX, clientY));
|
|
3043
|
+
}
|
|
3044
|
+
|
|
3045
|
+
function insertBlockAtRange(sectionBody: any, node: any, range: any) {
|
|
3046
|
+
if (!range || !sectionBody.contains(range.commonAncestorContainer)) {
|
|
3047
|
+
sectionBody.appendChild(node);
|
|
3048
|
+
focusCaretAfter(node);
|
|
3049
|
+
return node;
|
|
3050
|
+
}
|
|
3051
|
+
|
|
3052
|
+
const anchor =
|
|
3053
|
+
range.commonAncestorContainer.nodeType === Node.TEXT_NODE
|
|
3054
|
+
? range.commonAncestorContainer.parentNode
|
|
3055
|
+
: range.commonAncestorContainer;
|
|
3056
|
+
|
|
3057
|
+
if (shouldInsertInsideColumn(sectionBody, anchor)) {
|
|
3058
|
+
range.deleteContents();
|
|
3059
|
+
range.insertNode(node);
|
|
3060
|
+
focusCaretAfter(node);
|
|
3061
|
+
return node;
|
|
3062
|
+
}
|
|
3063
|
+
|
|
3064
|
+
const enclosingColumns = anchor?.closest?.('.document-columns');
|
|
3065
|
+
const enclosingTable = anchor?.closest?.('.document-table');
|
|
3066
|
+
|
|
3067
|
+
if (enclosingColumns && sectionBody.contains(enclosingColumns)) {
|
|
3068
|
+
enclosingColumns.insertAdjacentElement('afterend', node);
|
|
3069
|
+
focusCaretAfter(node);
|
|
3070
|
+
return node;
|
|
3071
|
+
}
|
|
3072
|
+
|
|
3073
|
+
if (enclosingTable && sectionBody.contains(enclosingTable)) {
|
|
3074
|
+
enclosingTable.insertAdjacentElement('afterend', node);
|
|
3075
|
+
focusCaretAfter(node);
|
|
3076
|
+
return node;
|
|
3077
|
+
}
|
|
3078
|
+
|
|
3079
|
+
range.collapse(true);
|
|
3080
|
+
range.insertNode(node);
|
|
3081
|
+
focusCaretAfter(node);
|
|
3082
|
+
return node;
|
|
3083
|
+
}
|
|
3084
|
+
|
|
3085
|
+
function resolveCrossSectionMove(sectionBody: any, movedEl: any) {
|
|
3086
|
+
const sourceSection = movedEl?.closest?.('.document-section');
|
|
3087
|
+
const targetSection = sectionBody?.closest?.('.document-section');
|
|
3088
|
+
const crossSection = Boolean(
|
|
3089
|
+
sourceSection && targetSection && sourceSection !== targetSection,
|
|
3090
|
+
);
|
|
3091
|
+
return {
|
|
3092
|
+
crossSection,
|
|
3093
|
+
sourceBody: crossSection ? sourceSection.querySelector('.document-section__body') : null,
|
|
3094
|
+
};
|
|
3095
|
+
}
|
|
3096
|
+
|
|
3097
|
+
function finalizeCrossSectionMove(
|
|
3098
|
+
movedEl: any,
|
|
3099
|
+
sectionBody: any,
|
|
3100
|
+
sourceBody: any,
|
|
3101
|
+
options: any,
|
|
3102
|
+
) {
|
|
3103
|
+
remapperMovedSubtreeToSection(movedEl, sectionBody, sourceBody, options);
|
|
3104
|
+
sourceBody?.dispatchEvent?.(new InputEvent('input', { bubbles: true }));
|
|
3105
|
+
}
|
|
3106
|
+
|
|
3107
|
+
function repositionLayoutBlockAtPoint(
|
|
3108
|
+
sectionBody: any,
|
|
3109
|
+
blockEl: any,
|
|
3110
|
+
clientX: any,
|
|
3111
|
+
clientY: any,
|
|
3112
|
+
options: any = {},
|
|
3113
|
+
) {
|
|
3114
|
+
if (!blockEl?.isConnected) return false;
|
|
3115
|
+
|
|
3116
|
+
const { crossSection, sourceBody } = resolveCrossSectionMove(sectionBody, blockEl);
|
|
3117
|
+
if (!crossSection && !sectionBody.contains(blockEl)) return false;
|
|
3118
|
+
|
|
3119
|
+
const target =
|
|
3120
|
+
resolveInlineDropTarget(sectionBody, blockEl, clientX, clientY) ??
|
|
3121
|
+
(crossSection ? { mode: 'append' } : null);
|
|
3122
|
+
if (!target) return false;
|
|
3123
|
+
|
|
3124
|
+
blockEl.remove();
|
|
3125
|
+
|
|
3126
|
+
const moved = applyInlineDropTarget(sectionBody, blockEl, target);
|
|
3127
|
+
|
|
3128
|
+
if (moved && crossSection) {
|
|
3129
|
+
finalizeCrossSectionMove(blockEl, sectionBody, sourceBody, options);
|
|
3130
|
+
}
|
|
3131
|
+
|
|
3132
|
+
return moved;
|
|
3133
|
+
}
|
|
3134
|
+
|
|
3135
|
+
function repositionTableAtPoint(
|
|
3136
|
+
sectionBody: any,
|
|
3137
|
+
tableEl: any,
|
|
3138
|
+
clientX: any,
|
|
3139
|
+
clientY: any,
|
|
3140
|
+
options: any = {},
|
|
3141
|
+
) {
|
|
3142
|
+
return repositionLayoutBlockAtPoint(sectionBody, tableEl, clientX, clientY, options);
|
|
3143
|
+
}
|
|
3144
|
+
|
|
3145
|
+
function repositionColumnsAtPoint(
|
|
3146
|
+
sectionBody: any,
|
|
3147
|
+
columnsEl: any,
|
|
3148
|
+
clientX: any,
|
|
3149
|
+
clientY: any,
|
|
3150
|
+
options: any = {},
|
|
3151
|
+
) {
|
|
3152
|
+
return repositionLayoutBlockAtPoint(sectionBody, columnsEl, clientX, clientY, options);
|
|
3153
|
+
}
|
|
3154
|
+
|
|
3155
|
+
function repositionFieldAtPoint(
|
|
3156
|
+
sectionBody: any,
|
|
3157
|
+
token: any,
|
|
3158
|
+
clientX: any,
|
|
3159
|
+
clientY: any,
|
|
3160
|
+
options: any = {},
|
|
3161
|
+
) {
|
|
3162
|
+
if (!token?.isConnected || token.classList.contains('field-token--cell')) return false;
|
|
3163
|
+
|
|
3164
|
+
const { crossSection, sourceBody } = resolveCrossSectionMove(sectionBody, token);
|
|
3165
|
+
|
|
3166
|
+
const editableRoot = resolveFieldEditableRoot(sectionBody, clientX, clientY);
|
|
3167
|
+
const target =
|
|
3168
|
+
resolveInlineDropTarget(editableRoot, token, clientX, clientY) ??
|
|
3169
|
+
(crossSection ? { mode: 'append' } : null);
|
|
3170
|
+
if (!target) return false;
|
|
3171
|
+
|
|
3172
|
+
removeTrailingCaretBridge(token);
|
|
3173
|
+
token.remove();
|
|
3174
|
+
const moved = applyInlineDropTarget(editableRoot, token, target);
|
|
3175
|
+
if (moved && crossSection) {
|
|
3176
|
+
finalizeCrossSectionMove(token, sectionBody, sourceBody, options);
|
|
3177
|
+
}
|
|
3178
|
+
return moved;
|
|
3179
|
+
}
|
|
3180
|
+
|
|
3181
|
+
export function wireDesignDragDrop(container: any, options: any = {}) {
|
|
3182
|
+
wireDesignDragDropContainer(container, options);
|
|
3183
|
+
}
|
|
3184
|
+
|
|
3185
|
+
function isMappableSourceDropTarget(el: any, container: any) {
|
|
3186
|
+
if (!el || !container) return false;
|
|
3187
|
+
const pivot = el.closest?.('.document-table--pivot[data-pivot-field-id]');
|
|
3188
|
+
if (pivot && container.contains(pivot)) return true;
|
|
3189
|
+
const token = el.closest?.('.field-token');
|
|
3190
|
+
if (!token || !container.contains(token)) return false;
|
|
3191
|
+
if (token.classList.contains('field-token--computed')) return false;
|
|
3192
|
+
return true;
|
|
3193
|
+
}
|
|
3194
|
+
|
|
3195
|
+
function wireDesignDragDropContainer(container: any, options: any = {}) {
|
|
3196
|
+
const { designMode, onStructureChange, onPaletteDrop, onSourcePathCanvasDrop } = options;
|
|
3197
|
+
if (!designMode || container.dataset.designDragWired === 'true') return;
|
|
3198
|
+
container.dataset.designDragWired = 'true';
|
|
3199
|
+
|
|
3200
|
+
const notifyChange = () => onStructureChange?.();
|
|
3201
|
+
const sectionHost = container.closest?.('.document-section');
|
|
3202
|
+
|
|
3203
|
+
wirePaletteDropGuard(container);
|
|
3204
|
+
|
|
3205
|
+
function onBeforeInput(e: any) {
|
|
3206
|
+
if (e.inputType !== 'insertFromDrop') return;
|
|
3207
|
+
if (
|
|
3208
|
+
!isInternalDragActive() &&
|
|
3209
|
+
!isPaletteDragSessionActive() &&
|
|
3210
|
+
!isSourcePathDragEvent(e.dataTransfer)
|
|
3211
|
+
) {
|
|
3212
|
+
return;
|
|
3213
|
+
}
|
|
3214
|
+
e.preventDefault();
|
|
3215
|
+
}
|
|
3216
|
+
|
|
3217
|
+
function onDragOver(e: any) {
|
|
3218
|
+
if (isPaletteDragEvent(e)) {
|
|
3219
|
+
e.preventDefault();
|
|
3220
|
+
e.stopPropagation();
|
|
3221
|
+
e.dataTransfer.dropEffect = 'copy';
|
|
3222
|
+
container.classList.add('document-section--drop-target');
|
|
3223
|
+
updateDropIndicator(container, e.clientX, e.clientY);
|
|
3224
|
+
return;
|
|
3225
|
+
}
|
|
3226
|
+
|
|
3227
|
+
if (isSourcePathDragEvent(e.dataTransfer)) {
|
|
3228
|
+
// When mappingMode wiring is present it handles field/cell targets.
|
|
3229
|
+
// With onSourcePathCanvasDrop we accept both canvas insert and token mapping.
|
|
3230
|
+
if (isMappableSourceDropTarget(e.target, container) && !onSourcePathCanvasDrop) {
|
|
3231
|
+
return;
|
|
3232
|
+
}
|
|
3233
|
+
e.preventDefault();
|
|
3234
|
+
e.stopPropagation();
|
|
3235
|
+
e.dataTransfer.dropEffect = 'copy';
|
|
3236
|
+
if (!isMappableSourceDropTarget(e.target, container)) {
|
|
3237
|
+
container.classList.add('document-section--drop-target');
|
|
3238
|
+
updateDropIndicator(container, e.clientX, e.clientY);
|
|
3239
|
+
}
|
|
3240
|
+
return;
|
|
3241
|
+
}
|
|
3242
|
+
|
|
3243
|
+
if (!isInternalDragActive()) return;
|
|
3244
|
+
e.preventDefault();
|
|
3245
|
+
e.stopPropagation();
|
|
3246
|
+
e.dataTransfer.dropEffect = 'move';
|
|
3247
|
+
container.classList.add('document-section--drop-target');
|
|
3248
|
+
updateDropIndicator(container, e.clientX, e.clientY);
|
|
3249
|
+
}
|
|
3250
|
+
|
|
3251
|
+
function onDragLeave(e: any) {
|
|
3252
|
+
const leaveRoot = sectionHost ?? container;
|
|
3253
|
+
if (!e.relatedTarget || !leaveRoot.contains(e.relatedTarget)) {
|
|
3254
|
+
container.classList.remove('document-section--drop-target');
|
|
3255
|
+
clearDropIndicators();
|
|
3256
|
+
}
|
|
3257
|
+
}
|
|
3258
|
+
|
|
3259
|
+
async function onDrop(e: any) {
|
|
3260
|
+
const paletteItem = parsePaletteDrag(e.dataTransfer);
|
|
3261
|
+
if (paletteItem && paletteItem.kind !== 'block') {
|
|
3262
|
+
e.preventDefault();
|
|
3263
|
+
e.stopPropagation();
|
|
3264
|
+
container.classList.remove('document-section--drop-target');
|
|
3265
|
+
clearDropIndicators();
|
|
3266
|
+
await onPaletteDrop?.(paletteItem, container, e.clientX, e.clientY);
|
|
3267
|
+
return;
|
|
3268
|
+
}
|
|
3269
|
+
|
|
3270
|
+
const sourceMeta = parseSourcePathMeta(e.dataTransfer);
|
|
3271
|
+
if (sourceMeta?.path && onSourcePathCanvasDrop) {
|
|
3272
|
+
e.preventDefault();
|
|
3273
|
+
e.stopPropagation();
|
|
3274
|
+
container.classList.remove('document-section--drop-target');
|
|
3275
|
+
clearDropIndicators();
|
|
3276
|
+
await onSourcePathCanvasDrop(sourceMeta, container, e.clientX, e.clientY, e.target);
|
|
3277
|
+
return;
|
|
3278
|
+
}
|
|
3279
|
+
|
|
3280
|
+
if (!isInternalDragActive()) return;
|
|
3281
|
+
e.preventDefault();
|
|
3282
|
+
e.stopPropagation();
|
|
3283
|
+
container.classList.remove('document-section--drop-target');
|
|
3284
|
+
clearDropIndicators();
|
|
3285
|
+
|
|
3286
|
+
if (draggedFieldToken) {
|
|
3287
|
+
const token = draggedFieldToken;
|
|
3288
|
+
if (repositionFieldAtPoint(container, token, e.clientX, e.clientY, options)) {
|
|
3289
|
+
notifyChange();
|
|
3290
|
+
}
|
|
3291
|
+
return;
|
|
3292
|
+
}
|
|
3293
|
+
|
|
3294
|
+
if (draggedColumnsEl) {
|
|
3295
|
+
const columnsEl = draggedColumnsEl;
|
|
3296
|
+
if (repositionColumnsAtPoint(container, columnsEl, e.clientX, e.clientY, options)) {
|
|
3297
|
+
notifyChange();
|
|
3298
|
+
}
|
|
3299
|
+
return;
|
|
3300
|
+
}
|
|
3301
|
+
|
|
3302
|
+
if (draggedTableEl) {
|
|
3303
|
+
const tableEl = draggedTableEl;
|
|
3304
|
+
if (repositionTableAtPoint(container, tableEl, e.clientX, e.clientY, options)) {
|
|
3305
|
+
notifyChange();
|
|
3306
|
+
}
|
|
3307
|
+
}
|
|
3308
|
+
}
|
|
3309
|
+
|
|
3310
|
+
const hosts = [container];
|
|
3311
|
+
// Accept drops on the whole section (header/chrome), not only the body —
|
|
3312
|
+
// otherwise cross-section moves show a blocked cursor over titles.
|
|
3313
|
+
if (sectionHost && sectionHost.dataset.designSectionDragWired !== 'true') {
|
|
3314
|
+
sectionHost.dataset.designSectionDragWired = 'true';
|
|
3315
|
+
hosts.push(sectionHost);
|
|
3316
|
+
}
|
|
3317
|
+
|
|
3318
|
+
for (const host of hosts) {
|
|
3319
|
+
host.addEventListener('beforeinput', onBeforeInput, true);
|
|
3320
|
+
host.addEventListener('dragover', onDragOver, true);
|
|
3321
|
+
host.addEventListener('dragleave', onDragLeave, true);
|
|
3322
|
+
host.addEventListener('drop', onDrop, true);
|
|
3323
|
+
}
|
|
3324
|
+
|
|
3325
|
+
container
|
|
3326
|
+
.querySelectorAll('.field-token--design:not(.field-token--cell)')
|
|
3327
|
+
.forEach((token: any) => {
|
|
3328
|
+
makeFieldTokenDraggable(token);
|
|
3329
|
+
});
|
|
3330
|
+
}
|
|
3331
|
+
|
|
3332
|
+
export function wireColumnBlockRegions(container: any, options: any = {}) {
|
|
3333
|
+
const { designMode, onStructureChange } = options;
|
|
3334
|
+
const notifyChange = () => onStructureChange?.();
|
|
3335
|
+
|
|
3336
|
+
wireDesignDragDropContainer(container, options);
|
|
3337
|
+
|
|
3338
|
+
container.querySelectorAll('.document-columns').forEach((columnsEl: any) => {
|
|
3339
|
+
if (designMode) {
|
|
3340
|
+
ensureColumnsDesignSplitter(columnsEl);
|
|
3341
|
+
ensureToolbarDragHandle(columnsEl, 'drag-columns');
|
|
3342
|
+
wireColumnsResize(columnsEl, {
|
|
3343
|
+
onColumnsWidthsChange: (target: any, widths: any) => {
|
|
3344
|
+
applyColumnWidthsToElement(target, widths);
|
|
3345
|
+
notifyChange();
|
|
3346
|
+
options.onColumnsWidthsChange?.(target, widths);
|
|
3347
|
+
},
|
|
3348
|
+
});
|
|
3349
|
+
}
|
|
3350
|
+
|
|
3351
|
+
if (columnsEl.dataset.columnsBlockWired === 'true') return;
|
|
3352
|
+
columnsEl.dataset.columnsBlockWired = 'true';
|
|
3353
|
+
|
|
3354
|
+
if (!designMode) return;
|
|
3355
|
+
|
|
3356
|
+
const dragHandle = columnsEl.querySelector('[data-action="drag-columns"]');
|
|
3357
|
+
dragHandle?.addEventListener('dragstart', (e: any) => {
|
|
3358
|
+
draggedColumnsEl = columnsEl;
|
|
3359
|
+
columnsEl.classList.add('document-columns--dragging');
|
|
3360
|
+
e.dataTransfer.effectAllowed = 'move';
|
|
3361
|
+
setInternalDragData(e, 'columns');
|
|
3362
|
+
});
|
|
3363
|
+
dragHandle?.addEventListener('dragend', () => {
|
|
3364
|
+
columnsEl.classList.remove('document-columns--dragging');
|
|
3365
|
+
draggedColumnsEl = null;
|
|
3366
|
+
clearDropIndicators();
|
|
3367
|
+
container.classList.remove('document-section--drop-target');
|
|
3368
|
+
});
|
|
3369
|
+
|
|
3370
|
+
const deleteBtn = columnsEl.querySelector('[data-action="delete-columns"]');
|
|
3371
|
+
deleteBtn?.addEventListener('click', (e: any) => {
|
|
3372
|
+
e.preventDefault();
|
|
3373
|
+
e.stopPropagation();
|
|
3374
|
+
removeOwnedSchemasFromDomSubtree(columnsEl, options);
|
|
3375
|
+
columnsEl.remove();
|
|
3376
|
+
notifyChange();
|
|
3377
|
+
});
|
|
3378
|
+
|
|
3379
|
+
columnsEl.querySelectorAll('.document-columns__col').forEach((col: any) => {
|
|
3380
|
+
wirePaletteDropGuard(col);
|
|
3381
|
+
});
|
|
3382
|
+
});
|
|
3383
|
+
}
|
|
3384
|
+
|
|
3385
|
+
/** Ensure design-mode columns use a middle-track splitter (migrates older DOM). */
|
|
3386
|
+
function ensureColumnsDesignSplitter(columnsEl: any) {
|
|
3387
|
+
const grid = columnsEl?.querySelector?.(':scope > .document-columns__grid');
|
|
3388
|
+
if (!grid) return;
|
|
3389
|
+
|
|
3390
|
+
grid.classList.add('document-columns__grid--design');
|
|
3391
|
+
|
|
3392
|
+
// Remove legacy in-column resizers.
|
|
3393
|
+
grid.querySelectorAll('.document-columns__col .document-columns__col-resizer').forEach((el: any) => {
|
|
3394
|
+
el.remove();
|
|
3395
|
+
});
|
|
3396
|
+
|
|
3397
|
+
let resizer = grid.querySelector(':scope > .document-columns__col-resizer');
|
|
3398
|
+
if (!resizer) {
|
|
3399
|
+
resizer = document.createElement('span');
|
|
3400
|
+
resizer.className = 'document-columns__col-resizer';
|
|
3401
|
+
resizer.dataset.colIndex = '0';
|
|
3402
|
+
resizer.contentEditable = 'false';
|
|
3403
|
+
resizer.title = 'Drag to resize columns';
|
|
3404
|
+
resizer.setAttribute('role', 'separator');
|
|
3405
|
+
resizer.setAttribute('aria-orientation', 'vertical');
|
|
3406
|
+
resizer.setAttribute('aria-label', 'Resize columns');
|
|
3407
|
+
}
|
|
3408
|
+
|
|
3409
|
+
const cols = [...grid.querySelectorAll(':scope > .document-columns__col')];
|
|
3410
|
+
if (cols.length >= 2) {
|
|
3411
|
+
// Place between the two columns: col0 | resizer | col1
|
|
3412
|
+
grid.insertBefore(resizer, cols[1]);
|
|
3413
|
+
} else if (!resizer.isConnected) {
|
|
3414
|
+
grid.appendChild(resizer);
|
|
3415
|
+
}
|
|
3416
|
+
|
|
3417
|
+
const widths = [
|
|
3418
|
+
columnsEl.dataset.columnWidth0 ?? '',
|
|
3419
|
+
columnsEl.dataset.columnWidth1 ?? '',
|
|
3420
|
+
];
|
|
3421
|
+
applyColumnWidthsToElement(columnsEl, widths);
|
|
3422
|
+
}
|
|
3423
|
+
|
|
3424
|
+
export function wireTableRegions(container: any, options: any = {}) {
|
|
3425
|
+
const { designMode, onStructureChange } = options;
|
|
3426
|
+
const notifyChange = () => onStructureChange?.();
|
|
3427
|
+
|
|
3428
|
+
wireDesignDragDropContainer(container, options);
|
|
3429
|
+
|
|
3430
|
+
container.querySelectorAll('.document-table').forEach((tableEl: any) => {
|
|
3431
|
+
if (designMode) {
|
|
3432
|
+
tableEl.querySelectorAll('[data-action="edit-table-schema"]').forEach((btn: any) => btn.remove());
|
|
3433
|
+
ensureToolbarDragHandle(tableEl, 'drag-table');
|
|
3434
|
+
}
|
|
3435
|
+
if (tableEl.dataset.tableWired === 'true') return;
|
|
3436
|
+
tableEl.dataset.tableWired = 'true';
|
|
3437
|
+
|
|
3438
|
+
const tableId = tableEl.dataset.tableId;
|
|
3439
|
+
|
|
3440
|
+
tableEl.addEventListener('click', (e: any) => {
|
|
3441
|
+
const removeBtn = e.target.closest('[data-action="remove-table-row"]');
|
|
3442
|
+
if (!removeBtn || !tableEl.contains(removeBtn)) return;
|
|
3443
|
+
e.preventDefault();
|
|
3444
|
+
e.stopPropagation();
|
|
3445
|
+
const rowKey = removeBtn.dataset.rowKey;
|
|
3446
|
+
if (removeTableRowFromWrapper(tableEl, rowKey, options)) {
|
|
3447
|
+
notifyChange();
|
|
3448
|
+
}
|
|
3449
|
+
});
|
|
3450
|
+
|
|
3451
|
+
const addBtn = tableEl.querySelector('[data-action="add-table-row"]');
|
|
3452
|
+
addBtn?.addEventListener('click', (e: any) => {
|
|
3453
|
+
e.preventDefault();
|
|
3454
|
+
e.stopPropagation();
|
|
3455
|
+
addTableRowToWrapper(tableEl, options);
|
|
3456
|
+
notifyChange();
|
|
3457
|
+
});
|
|
3458
|
+
|
|
3459
|
+
const pasteBtn = tableEl.querySelector('[data-action="paste-table-rows"]');
|
|
3460
|
+
pasteBtn?.addEventListener('click', async (e: any) => {
|
|
3461
|
+
e.preventDefault();
|
|
3462
|
+
e.stopPropagation();
|
|
3463
|
+
try {
|
|
3464
|
+
if (!navigator.clipboard?.readText) {
|
|
3465
|
+
throw new Error('Clipboard paste is not available in this browser.');
|
|
3466
|
+
}
|
|
3467
|
+
const text = await navigator.clipboard.readText();
|
|
3468
|
+
const added = addTableRowsFromText(tableEl, text, options);
|
|
3469
|
+
if (added.length) notifyChange();
|
|
3470
|
+
} catch (err: any) {
|
|
3471
|
+
showNotification(err?.message ?? 'Could not read clipboard. Use Import instead.');
|
|
3472
|
+
}
|
|
3473
|
+
});
|
|
3474
|
+
|
|
3475
|
+
const importBtn = tableEl.querySelector('[data-action="import-table-rows"]');
|
|
3476
|
+
const importFile = tableEl.querySelector('[data-role="import-table-rows-file"]');
|
|
3477
|
+
importBtn?.addEventListener('click', (e: any) => {
|
|
3478
|
+
e.preventDefault();
|
|
3479
|
+
e.stopPropagation();
|
|
3480
|
+
importFile?.click();
|
|
3481
|
+
});
|
|
3482
|
+
importFile?.addEventListener('change', async () => {
|
|
3483
|
+
const file = importFile.files?.[0];
|
|
3484
|
+
importFile.value = '';
|
|
3485
|
+
if (!file) return;
|
|
3486
|
+
try {
|
|
3487
|
+
const text = await file.text();
|
|
3488
|
+
const added = addTableRowsFromText(tableEl, text, options);
|
|
3489
|
+
if (added.length) notifyChange();
|
|
3490
|
+
} catch (err: any) {
|
|
3491
|
+
showNotification(err?.message ?? 'Could not import file.');
|
|
3492
|
+
}
|
|
3493
|
+
});
|
|
3494
|
+
|
|
3495
|
+
if (designMode) {
|
|
3496
|
+
const dragHandle = tableEl.querySelector('[data-action="drag-table"]');
|
|
3497
|
+
dragHandle?.addEventListener('dragstart', (e: any) => {
|
|
3498
|
+
draggedTableEl = tableEl;
|
|
3499
|
+
tableEl.classList.add('document-table--dragging');
|
|
3500
|
+
e.dataTransfer.effectAllowed = 'move';
|
|
3501
|
+
setInternalDragData(e, tableId ?? 'table');
|
|
3502
|
+
});
|
|
3503
|
+
dragHandle?.addEventListener('dragend', () => {
|
|
3504
|
+
tableEl.classList.remove('document-table--dragging');
|
|
3505
|
+
draggedTableEl = null;
|
|
3506
|
+
clearDropIndicators();
|
|
3507
|
+
container.classList.remove('document-section--drop-target');
|
|
3508
|
+
});
|
|
3509
|
+
|
|
3510
|
+
const deleteBtn = tableEl.querySelector('[data-action="delete-table"]');
|
|
3511
|
+
deleteBtn?.addEventListener('click', (e: any) => {
|
|
3512
|
+
e.preventDefault();
|
|
3513
|
+
e.stopPropagation();
|
|
3514
|
+
removeOwnedSchemasFromDomSubtree(tableEl, options);
|
|
3515
|
+
tableEl.remove();
|
|
3516
|
+
notifyChange();
|
|
3517
|
+
});
|
|
3518
|
+
|
|
3519
|
+
const visionTable = tableEl.querySelector('.vision-table');
|
|
3520
|
+
if (visionTable) {
|
|
3521
|
+
if (tableEl.classList.contains('document-table--pivot') || visionTable.classList.contains('pivot-table')) {
|
|
3522
|
+
wirePivotRowLabelResize(visionTable, {
|
|
3523
|
+
tableId,
|
|
3524
|
+
getRegistry: options.getRegistry,
|
|
3525
|
+
onSchemaChange: options.onSchemaChange,
|
|
3526
|
+
onTableColumnResizeStart: options.onTableColumnResizeStart,
|
|
3527
|
+
});
|
|
3528
|
+
} else {
|
|
3529
|
+
wireTableColumnResize(visionTable, {
|
|
3530
|
+
tableId,
|
|
3531
|
+
getRegistry: options.getRegistry,
|
|
3532
|
+
onSchemaChange: options.onSchemaChange,
|
|
3533
|
+
onTableColumnWidthsChange: options.onTableColumnWidthsChange,
|
|
3534
|
+
onTableColumnWidthsPreview: options.onTableColumnWidthsPreview,
|
|
3535
|
+
onTableColumnResizeStart: options.onTableColumnResizeStart,
|
|
3536
|
+
});
|
|
3537
|
+
if (options.designMode) {
|
|
3538
|
+
wireTableColumnReorder(visionTable, {
|
|
3539
|
+
tableId,
|
|
3540
|
+
onReorder: (fromIndex: number, toIndex: number) => {
|
|
3541
|
+
reorderTableColumnsInWrapper(tableEl, fromIndex, toIndex, options);
|
|
3542
|
+
},
|
|
3543
|
+
});
|
|
3544
|
+
}
|
|
3545
|
+
}
|
|
3546
|
+
}
|
|
3547
|
+
}
|
|
3548
|
+
});
|
|
3549
|
+
}
|
|
3550
|
+
|
|
3551
|
+
export function refreshFieldTokensForField(fieldId: any, context: any) {
|
|
3552
|
+
const registry = registryFrom(context);
|
|
3553
|
+
const def = registry?.getFieldDef(fieldId);
|
|
3554
|
+
if (def?.picker === 'computed') {
|
|
3555
|
+
for (const container of document.querySelectorAll('.document-section__body')) {
|
|
3556
|
+
const values = extractFieldValuesFromDom(container);
|
|
3557
|
+
refreshComputedFields(container, values, context);
|
|
3558
|
+
}
|
|
3559
|
+
return;
|
|
3560
|
+
}
|
|
3561
|
+
|
|
3562
|
+
for (const token of document.querySelectorAll('.field-token')) {
|
|
3563
|
+
const el = token as HTMLElement;
|
|
3564
|
+
if (el.dataset.fieldId !== fieldId) continue;
|
|
3565
|
+
updateFieldToken(el, readTokenValue(el), el.dataset.placeholder, context);
|
|
3566
|
+
}
|
|
3567
|
+
}
|
|
3568
|
+
|
|
3569
|
+
/**
|
|
3570
|
+
* Update live DOM after a schema edit without rebuilding Editor.js.
|
|
3571
|
+
* @param {string} fieldId
|
|
3572
|
+
* @param {object} context
|
|
3573
|
+
* @param {ParentNode} [root]
|
|
3574
|
+
*/
|
|
3575
|
+
export function refreshFieldSchemaInDom(fieldId: any, context: any, root: any = document) {
|
|
3576
|
+
refreshFieldTokensForField(fieldId, context);
|
|
3577
|
+
|
|
3578
|
+
const registry = registryFrom(context);
|
|
3579
|
+
const schema = registry?.getFieldSchemas()?.[fieldId];
|
|
3580
|
+
const label = schema?.label ?? fieldId;
|
|
3581
|
+
const scope = root?.querySelector ? root : document;
|
|
3582
|
+
|
|
3583
|
+
if (schema?.type === 'pivotTable') {
|
|
3584
|
+
refreshPivotTableInDom(fieldId, {
|
|
3585
|
+
...context,
|
|
3586
|
+
getRegistry: context?.getRegistry ?? (() => registry),
|
|
3587
|
+
fieldSchemas: registry?.getFieldSchemas?.() ?? context?.fieldSchemas,
|
|
3588
|
+
designMode: context?.designMode !== false,
|
|
3589
|
+
}, scope);
|
|
3590
|
+
}
|
|
3591
|
+
|
|
3592
|
+
for (const wrapper of scope.querySelectorAll('.template-block')) {
|
|
3593
|
+
if (!wrapper.querySelector(`.field-token[data-field-id="${fieldId}"]`)) continue;
|
|
3594
|
+
|
|
3595
|
+
const typeSpan = wrapper.querySelector('.template-block__type');
|
|
3596
|
+
if (typeSpan) typeSpan.textContent = label;
|
|
3597
|
+
|
|
3598
|
+
const fieldLabel = wrapper.querySelector('.template-block__field-label');
|
|
3599
|
+
if (fieldLabel) fieldLabel.textContent = `${label}: `;
|
|
3600
|
+
}
|
|
3601
|
+
|
|
3602
|
+
for (const container of scope.querySelectorAll('.document-section__body')) {
|
|
3603
|
+
const values = extractFieldValuesFromDom(container);
|
|
3604
|
+
refreshComputedFields(container, values, {
|
|
3605
|
+
...context,
|
|
3606
|
+
changedFieldId: fieldId,
|
|
3607
|
+
});
|
|
3608
|
+
}
|
|
3609
|
+
}
|
|
3610
|
+
|
|
3611
|
+
/**
|
|
3612
|
+
* Open the fill-mode value picker for a field token (click or keyboard).
|
|
3613
|
+
* On successful modal save (OK / Ctrl+Enter / Clear), advances to the next editable
|
|
3614
|
+
* field and opens its picker. Cancel keeps focus on the current field.
|
|
3615
|
+
* Logical (inline Yes/No) fields do not advance.
|
|
3616
|
+
* @returns {Promise<unknown | undefined>} next value, or undefined when cancelled / not editable
|
|
3617
|
+
*/
|
|
3618
|
+
export async function pickFillFieldFromToken(
|
|
3619
|
+
token: any,
|
|
3620
|
+
callbacks: any,
|
|
3621
|
+
onUpdate: any,
|
|
3622
|
+
options: any = {},
|
|
3623
|
+
) {
|
|
3624
|
+
const fieldId = token?.dataset?.fieldId;
|
|
3625
|
+
if (!fieldId || !callbacks) return undefined;
|
|
3626
|
+
|
|
3627
|
+
const registry = registryFrom(callbacks);
|
|
3628
|
+
const schema =
|
|
3629
|
+
options.schema ??
|
|
3630
|
+
registry?.getFieldSchemas()?.[fieldId] ??
|
|
3631
|
+
callbacks.fieldSchemas?.[fieldId];
|
|
3632
|
+
const fieldSchemas =
|
|
3633
|
+
registry?.getFieldSchemas?.() ?? callbacks.fieldSchemas ?? options.updateContext?.fieldSchemas;
|
|
3634
|
+
if (!isFieldEditableInFillMode(schema, { fieldId, fieldSchemas })) return undefined;
|
|
3635
|
+
|
|
3636
|
+
const holder =
|
|
3637
|
+
callbacks.editorHolder ??
|
|
3638
|
+
options.root ??
|
|
3639
|
+
(typeof token.closest === 'function'
|
|
3640
|
+
? token.closest('.codex-editor, .editor-holder, [data-docengine-editor]')
|
|
3641
|
+
: null) ??
|
|
3642
|
+
document;
|
|
3643
|
+
setFillFieldFocus(token, holder);
|
|
3644
|
+
|
|
3645
|
+
const fromDom = readTokenValue(token);
|
|
3646
|
+
const fromMap = callbacks?.fieldValues?.[fieldId];
|
|
3647
|
+
const emptyOpts = {
|
|
3648
|
+
htmlEditor: !!schema?.htmlEditor,
|
|
3649
|
+
repeaterSchema: schema?.type === 'child' ? schema : undefined,
|
|
3650
|
+
};
|
|
3651
|
+
// Prefer live fieldValues — image data URLs are not stored on data-value.
|
|
3652
|
+
const current =
|
|
3653
|
+
options.currentValue !== undefined
|
|
3654
|
+
? options.currentValue
|
|
3655
|
+
: fromMap !== undefined && !isFieldEmpty(fromMap, emptyOpts)
|
|
3656
|
+
? fromMap
|
|
3657
|
+
: fromDom;
|
|
3658
|
+
|
|
3659
|
+
const placeholder = options.placeholder ?? token.dataset.placeholder;
|
|
3660
|
+
const updateContext = options.updateContext ?? callbacks;
|
|
3661
|
+
const resolveAdvanceToNext = () => {
|
|
3662
|
+
if (options.advanceToNext !== undefined) return options.advanceToNext !== false;
|
|
3663
|
+
if (typeof callbacks.getAutoAdvanceFillFields === 'function') {
|
|
3664
|
+
return callbacks.getAutoAdvanceFillFields() !== false;
|
|
3665
|
+
}
|
|
3666
|
+
return callbacks.autoAdvanceFillFields !== false;
|
|
3667
|
+
};
|
|
3668
|
+
const advanceToNext = resolveAdvanceToNext();
|
|
3669
|
+
const def = registry?.getFieldDef?.(fieldId);
|
|
3670
|
+
|
|
3671
|
+
token.classList.add('field-token--active');
|
|
3672
|
+
try {
|
|
3673
|
+
const next = await openFieldPicker(fieldId, current, callbacks);
|
|
3674
|
+
// Paint the token before onUpdate so computed-field sync scrapes the new value.
|
|
3675
|
+
// onUpdate may still remount the node (structure/save); refresh the live token after.
|
|
3676
|
+
if (token.isConnected) {
|
|
3677
|
+
try {
|
|
3678
|
+
updateFieldToken(token, next, placeholder, updateContext);
|
|
3679
|
+
} catch (err) {
|
|
3680
|
+
console.warn('[docengine] Failed to refresh field token after pick', err);
|
|
3681
|
+
}
|
|
3682
|
+
}
|
|
3683
|
+
onUpdate?.(fieldId, next);
|
|
3684
|
+
const live =
|
|
3685
|
+
findLiveFieldToken(fieldId, holder) ?? (token.isConnected ? token : null);
|
|
3686
|
+
if (live) {
|
|
3687
|
+
live.classList.remove('field-token--active');
|
|
3688
|
+
try {
|
|
3689
|
+
updateFieldToken(live, next, placeholder ?? live.dataset.placeholder, updateContext);
|
|
3690
|
+
} catch (err) {
|
|
3691
|
+
console.warn('[docengine] Failed to refresh field token after pick', err);
|
|
3692
|
+
}
|
|
3693
|
+
}
|
|
3694
|
+
|
|
3695
|
+
const currentToken = live ?? token;
|
|
3696
|
+
const getSchemas = () =>
|
|
3697
|
+
registry?.getFieldSchemas?.() ?? callbacks.fieldSchemas ?? fieldSchemas ?? {};
|
|
3698
|
+
const nextToken =
|
|
3699
|
+
advanceToNext && shouldAdvanceFillFieldAfterPicker(schema, def)
|
|
3700
|
+
? getNextEditableFillFieldToken(holder, currentToken, getSchemas)
|
|
3701
|
+
: null;
|
|
3702
|
+
|
|
3703
|
+
if (nextToken?.isConnected) {
|
|
3704
|
+
restoreFillFieldFocusAfterPicker(nextToken.dataset.fieldId, holder, nextToken);
|
|
3705
|
+
scrollFillFieldIntoView(nextToken);
|
|
3706
|
+
scheduleAfterFillModalClose(() => {
|
|
3707
|
+
if (!nextToken.isConnected) return;
|
|
3708
|
+
const nextId = nextToken.dataset?.fieldId;
|
|
3709
|
+
const nextSchema = nextId ? getSchemas()?.[nextId] : null;
|
|
3710
|
+
if (!isFieldEditableInFillMode(nextSchema, { fieldId: nextId, fieldSchemas: getSchemas() })) {
|
|
3711
|
+
return;
|
|
3712
|
+
}
|
|
3713
|
+
void pickFillFieldFromToken(nextToken, callbacks, onUpdate, {
|
|
3714
|
+
schema: nextSchema,
|
|
3715
|
+
root: holder,
|
|
3716
|
+
});
|
|
3717
|
+
}, holder);
|
|
3718
|
+
} else {
|
|
3719
|
+
restoreFillFieldFocusAfterPicker(fieldId, holder, currentToken);
|
|
3720
|
+
}
|
|
3721
|
+
return next;
|
|
3722
|
+
} catch {
|
|
3723
|
+
// cancelled — keep focus on the field (do not advance)
|
|
3724
|
+
restoreFillFieldFocusAfterPicker(fieldId, holder, token);
|
|
3725
|
+
return undefined;
|
|
3726
|
+
} finally {
|
|
3727
|
+
token.classList.remove('field-token--active');
|
|
3728
|
+
const live = findLiveFieldToken(fieldId, holder);
|
|
3729
|
+
live?.classList.remove('field-token--active');
|
|
3730
|
+
}
|
|
3731
|
+
}
|
|
3732
|
+
|
|
3733
|
+
export function wireFieldClicks(container: any, callbacks: any, onUpdate: any, options: any = {}) {
|
|
3734
|
+
const { designMode, onEditSchema, onDeleteField, designPropertiesPanel } = options;
|
|
3735
|
+
|
|
3736
|
+
if (designMode) {
|
|
3737
|
+
container.querySelectorAll('.field-token:not(.field-token--cell)').forEach((token: any) => {
|
|
3738
|
+
if (token.dataset.designWired !== 'true') {
|
|
3739
|
+
wireDesignFieldToken(token, { onEditSchema, onDeleteField, designPropertiesPanel });
|
|
3740
|
+
}
|
|
3741
|
+
});
|
|
3742
|
+
return;
|
|
3743
|
+
}
|
|
3744
|
+
|
|
3745
|
+
container.addEventListener('click', async (e: any) => {
|
|
3746
|
+
const token = e.target.closest('.field-token');
|
|
3747
|
+
if (!token || !container.contains(token)) return;
|
|
3748
|
+
|
|
3749
|
+
const fieldId = token.dataset.fieldId;
|
|
3750
|
+
const registry = registryFrom(callbacks);
|
|
3751
|
+
const fieldSchemas = registry?.getFieldSchemas?.() ?? callbacks.fieldSchemas;
|
|
3752
|
+
const schema = fieldSchemas?.[fieldId];
|
|
3753
|
+
if (!isFieldEditableInFillMode(schema, { fieldId, fieldSchemas })) return;
|
|
3754
|
+
|
|
3755
|
+
e.preventDefault();
|
|
3756
|
+
e.stopPropagation();
|
|
3757
|
+
|
|
3758
|
+
await pickFillFieldFromToken(token, callbacks, onUpdate, { schema, root: container });
|
|
3759
|
+
});
|
|
3760
|
+
}
|