@a3s-lab/office 0.2.2 → 0.4.0
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/COLLABORATION_ROADMAP.md +426 -0
- package/README.md +649 -10
- package/dist/0~1403.js +1 -1
- package/dist/0~2805.js +1279 -0
- package/dist/{0~use-office-draft.js → 0~345.js} +30 -1
- package/dist/0~3539.js +1 -1
- package/dist/0~3557.js +1 -1
- package/dist/0~3635.js +1 -1
- package/dist/0~4595.js +123 -12
- package/dist/0~4980.js +154 -0
- package/dist/0~5050.js +124 -113
- package/dist/{0~9512.js → 0~6090.js} +540 -3
- package/dist/0~7048.js +92 -66
- package/dist/0~7614.js +2 -1
- package/dist/0~7754.js +5653 -0
- package/dist/0~9445.js +1 -1
- package/dist/0~document-editor.js +4992 -3323
- package/dist/0~markdown-editor.js +250 -44
- package/dist/0~pdf-viewer.js +1016 -24
- package/dist/0~presentation-editor.js +179 -8
- package/dist/0~spreadsheet-editor.js +3371 -578
- package/dist/0~work-docx-export.js +6801 -658
- package/dist/0~work-docx-import.js +1388 -795
- package/dist/0~work-office-diagnostics.js +524 -30
- package/dist/0~work-pptx-export.js +2 -1
- package/dist/0~work-pptx-import.js +1 -2
- package/dist/0~work-presentation-charts.js +1 -1
- package/dist/2591.js +197 -0
- package/dist/3818.js +1090 -0
- package/dist/4104.js +970 -60
- package/dist/432.js +171 -14
- package/dist/4476.js +2008 -0
- package/dist/4560.js +674 -0
- package/dist/4650.js +70 -0
- package/dist/{1134.js → 5184.js} +183 -1
- package/dist/6489.js +18 -18
- package/dist/7060.js +132 -0
- package/dist/8715.js +2 -136
- package/dist/8928.js +16778 -0
- package/dist/9787.js +209 -0
- package/dist/core.d.ts +29 -9
- package/dist/core.js +10 -2
- package/dist/index.js +13 -3
- package/dist/internal/collaboration/office-collaboration-flat-json.d.ts +13 -0
- package/dist/internal/collaboration/office-collaboration-json.d.ts +4 -0
- package/dist/internal/collaboration/office-collaboration-presence.d.ts +86 -0
- package/dist/internal/collaboration/office-collaboration-transport.d.ts +42 -0
- package/dist/internal/collaboration/office-collaboration.d.ts +85 -0
- package/dist/internal/collaboration/office-document-collaboration-bibliography.d.ts +7 -0
- package/dist/internal/collaboration/office-document-collaboration-claims.d.ts +9 -0
- package/dist/internal/collaboration/office-document-collaboration-comments.d.ts +7 -0
- package/dist/internal/collaboration/office-document-collaboration-sidecar-utils.d.ts +27 -0
- package/dist/internal/collaboration/office-document-collaboration-sidecars.d.ts +16 -0
- package/dist/internal/collaboration/office-document-collaboration.d.ts +45 -0
- package/dist/internal/collaboration/office-markdown-collaboration.d.ts +31 -0
- package/dist/internal/collaboration/office-pdf-collaboration-claims.d.ts +4 -0
- package/dist/internal/collaboration/office-pdf-collaboration-conflicts.d.ts +2 -0
- package/dist/internal/collaboration/office-pdf-collaboration-model.d.ts +26 -0
- package/dist/internal/collaboration/office-pdf-collaboration-records.d.ts +21 -0
- package/dist/internal/collaboration/office-pdf-collaboration-types.d.ts +91 -0
- package/dist/internal/collaboration/office-pdf-collaboration-validation.d.ts +4 -0
- package/dist/internal/collaboration/office-pdf-collaboration.d.ts +35 -0
- package/dist/internal/collaboration/office-presentation-collaboration-model.d.ts +25 -0
- package/dist/internal/collaboration/office-presentation-collaboration-records.d.ts +22 -0
- package/dist/internal/collaboration/office-presentation-collaboration-validation.d.ts +4 -0
- package/dist/internal/collaboration/office-presentation-collaboration.d.ts +32 -0
- package/dist/internal/collaboration/office-spreadsheet-collaboration-cells.d.ts +13 -0
- package/dist/internal/collaboration/office-spreadsheet-collaboration-claims.d.ts +4 -0
- package/dist/internal/collaboration/office-spreadsheet-collaboration-conflicts.d.ts +2 -0
- package/dist/internal/collaboration/office-spreadsheet-collaboration-flat-json.d.ts +10 -0
- package/dist/internal/collaboration/office-spreadsheet-collaboration-model.d.ts +31 -0
- package/dist/internal/collaboration/office-spreadsheet-collaboration-records.d.ts +17 -0
- package/dist/internal/collaboration/office-spreadsheet-collaboration-validation.d.ts +4 -0
- package/dist/internal/collaboration/office-spreadsheet-collaboration.d.ts +32 -0
- package/dist/internal/design-system/primitives/navigation/tabs.d.ts +3 -1
- package/dist/internal/features/work/components/work-document-page-border.d.ts +6 -0
- package/dist/internal/features/work/editors/document-command-catalog.d.ts +536 -0
- package/dist/internal/features/work/editors/document-editor-focus.d.ts +1 -1
- package/dist/internal/features/work/editors/document-editor-support.d.ts +7 -3
- package/dist/internal/features/work/editors/document-editor.d.ts +8 -2
- package/dist/internal/features/work/editors/document-external-content.d.ts +14 -0
- package/dist/internal/features/work/editors/document-format-clipboard.d.ts +6 -0
- package/dist/internal/features/work/editors/document-format-tools.d.ts +4 -0
- package/dist/internal/features/work/editors/document-layout-panel.d.ts +4 -1
- package/dist/internal/features/work/editors/document-page-chrome-wps-shortcuts.d.ts +2 -0
- package/dist/internal/features/work/editors/document-page-layout-ribbon.d.ts +14 -0
- package/dist/internal/features/work/editors/document-page-stack.d.ts +10 -1
- package/dist/internal/features/work/editors/document-page-thumbnail.d.ts +2 -0
- package/dist/internal/features/work/editors/document-pagination-run-coordinator.d.ts +26 -0
- package/dist/internal/features/work/editors/document-picture-properties-dialog-model.d.ts +20 -1
- package/dist/internal/features/work/editors/document-review-navigation.d.ts +9 -0
- package/dist/internal/features/work/editors/document-statistics-dialog.d.ts +7 -0
- package/dist/internal/features/work/editors/document-status-bar.d.ts +2 -1
- package/dist/internal/features/work/editors/document-table-properties-dialog-model.d.ts +4 -1
- package/dist/internal/features/work/editors/document-toolbar.d.ts +19 -42
- package/dist/internal/features/work/editors/document-wps-shortcuts.d.ts +12 -0
- package/dist/internal/features/work/editors/document-zoom.d.ts +17 -0
- package/dist/internal/features/work/editors/markdown-editor-focus.d.ts +1 -1
- package/dist/internal/features/work/editors/markdown-editor.d.ts +5 -1
- package/dist/internal/features/work/editors/markdown-toolbar.d.ts +2 -1
- package/dist/internal/features/work/editors/office-collaboration-participants.d.ts +3 -0
- package/dist/internal/features/work/editors/office-collaboration-presence-context.d.ts +17 -0
- package/dist/internal/features/work/editors/office-collaboration-presence-ui.d.ts +25 -0
- package/dist/internal/features/work/editors/office-editor-focus-handoff.d.ts +27 -0
- package/dist/internal/features/work/editors/pdf-annotation-controller.d.ts +5 -0
- package/dist/internal/features/work/editors/pdf-collaboration-presence.d.ts +3 -0
- package/dist/internal/features/work/editors/pdf-collaboration-projection.d.ts +10 -0
- package/dist/internal/features/work/editors/pdf-evidence-contract.d.ts +36 -0
- package/dist/internal/features/work/editors/pdf-evidence-overlay.d.ts +37 -0
- package/dist/internal/features/work/editors/pdf-toolbar.d.ts +2 -1
- package/dist/internal/features/work/editors/pdf-viewer-controller.d.ts +7 -1
- package/dist/internal/features/work/editors/pdf-viewer.d.ts +11 -1
- package/dist/internal/features/work/editors/presentation-collaboration-presence.d.ts +5 -0
- package/dist/internal/features/work/editors/presentation-editor-focus.d.ts +3 -2
- package/dist/internal/features/work/editors/presentation-editor-types.d.ts +3 -0
- package/dist/internal/features/work/editors/presentation-editor.d.ts +1 -1
- package/dist/internal/features/work/editors/spreadsheet-auto-filter.d.ts +9 -0
- package/dist/internal/features/work/editors/spreadsheet-cell-clear.d.ts +3 -0
- package/dist/internal/features/work/editors/spreadsheet-cell-merge.d.ts +12 -0
- package/dist/internal/features/work/editors/spreadsheet-clipboard-shortcuts.d.ts +3 -7
- package/dist/internal/features/work/editors/spreadsheet-collaboration-presence.d.ts +9 -0
- package/dist/internal/features/work/editors/spreadsheet-command-catalog.d.ts +464 -0
- package/dist/internal/features/work/editors/spreadsheet-command-controller.d.ts +45 -9
- package/dist/internal/features/work/editors/spreadsheet-context-menu.d.ts +2 -0
- package/dist/internal/features/work/editors/spreadsheet-editor-ribbon.d.ts +9 -28
- package/dist/internal/features/work/editors/spreadsheet-editor.d.ts +8 -2
- package/dist/internal/features/work/editors/spreadsheet-format-painter.d.ts +27 -0
- package/dist/internal/features/work/editors/spreadsheet-freeze-panes.d.ts +14 -0
- package/dist/internal/features/work/editors/use-document-insert-commands.d.ts +3 -2
- package/dist/internal/features/work/editors/use-document-pagination.d.ts +6 -1
- package/dist/internal/features/work/editors/use-document-review-conflicts.d.ts +28 -0
- package/dist/internal/features/work/editors/use-spreadsheet-auto-filter.d.ts +21 -0
- package/dist/internal/features/work/editors/use-spreadsheet-collaboration.d.ts +27 -0
- package/dist/internal/features/work/editors/use-spreadsheet-format-painter.d.ts +18 -0
- package/dist/internal/features/work/editors/work-office-chrome.d.ts +22 -3
- package/dist/internal/features/work/editors/work-office-ribbon-overflow.d.ts +2 -0
- package/dist/internal/features/work/work-document-bookmark-references.d.ts +37 -0
- package/dist/internal/features/work/work-document-bookmarks.d.ts +29 -0
- package/dist/internal/features/work/work-document-caption-nodes.d.ts +4 -1
- package/dist/internal/features/work/work-document-comments.d.ts +1 -1
- package/dist/internal/features/work/work-document-equations.d.ts +513 -0
- package/dist/internal/features/work/work-document-extensions.d.ts +1 -0
- package/dist/internal/features/work/work-document-field-identity.d.ts +2 -0
- package/dist/internal/features/work/work-document-field-node.d.ts +2 -2
- package/dist/internal/features/work/work-document-fields.d.ts +7 -0
- package/dist/internal/features/work/work-document-image-identity.d.ts +30 -0
- package/dist/internal/features/work/work-document-image-layout.d.ts +46 -1
- package/dist/internal/features/work/work-document-image-wrap-contour.d.ts +16 -0
- package/dist/internal/features/work/work-document-incremental-layout.d.ts +2 -2
- package/dist/internal/features/work/work-document-model-codec.d.ts +4 -1
- package/dist/internal/features/work/work-document-note-integrity.d.ts +2 -0
- package/dist/internal/features/work/work-document-page-borders.d.ts +25 -0
- package/dist/internal/features/work/work-document-page-capture.d.ts +8 -0
- package/dist/internal/features/work/work-document-page-frames.d.ts +15 -0
- package/dist/internal/features/work/work-document-page-margins.d.ts +56 -0
- package/dist/internal/features/work/work-document-page-size.d.ts +47 -0
- package/dist/internal/features/work/work-document-pagination-measurement.d.ts +1 -2
- package/dist/internal/features/work/work-document-pagination-types.d.ts +7 -2
- package/dist/internal/features/work/work-document-pagination.d.ts +2 -2
- package/dist/internal/features/work/work-document-paragraph-borders.d.ts +32 -0
- package/dist/internal/features/work/work-document-paragraph-identity.d.ts +26 -0
- package/dist/internal/features/work/work-document-paragraph-shading.d.ts +18 -0
- package/dist/internal/features/work/work-document-review-conflicts.d.ts +35 -0
- package/dist/internal/features/work/work-document-section.d.ts +4 -0
- package/dist/internal/features/work/work-document-snapshot.d.ts +19 -0
- package/dist/internal/features/work/work-document-source.d.ts +23 -0
- package/dist/internal/features/work/work-document-table-column-widths.d.ts +7 -0
- package/dist/internal/features/work/work-document-table-property-changes.d.ts +3 -0
- package/dist/internal/features/work/work-document-table-row-identity.d.ts +15 -0
- package/dist/internal/features/work/work-document-table-sizing.d.ts +3 -0
- package/dist/internal/features/work/work-document-text-layout.d.ts +3 -1
- package/dist/internal/features/work/work-document-word-line-metrics.d.ts +2 -0
- package/dist/internal/features/work/work-docx-bookmark-diagnostics.d.ts +3 -0
- package/dist/internal/features/work/work-docx-bookmark-import.d.ts +24 -0
- package/dist/internal/features/work/work-docx-bookmarks.d.ts +17 -0
- package/dist/internal/features/work/work-docx-comment-durable-id-preservation.d.ts +2 -0
- package/dist/internal/features/work/work-docx-comment-export.d.ts +3 -0
- package/dist/internal/features/work/work-docx-comment-metadata.d.ts +2 -0
- package/dist/internal/features/work/work-docx-drawing-extension-preservation.d.ts +4 -0
- package/dist/internal/features/work/work-docx-equation-diagnostics.d.ts +3 -0
- package/dist/internal/features/work/work-docx-equation-export.d.ts +14 -0
- package/dist/internal/features/work/work-docx-equation-import.d.ts +30 -0
- package/dist/internal/features/work/work-docx-equation-story.d.ts +9 -0
- package/dist/internal/features/work/work-docx-export-formatting.d.ts +3 -1
- package/dist/internal/features/work/work-docx-export-image.d.ts +5 -1
- package/dist/internal/features/work/work-docx-export.d.ts +1 -1
- package/dist/internal/features/work/work-docx-field-instructions.d.ts +8 -0
- package/dist/internal/features/work/work-docx-font-table-preservation.d.ts +3 -0
- package/dist/internal/features/work/work-docx-ignorable-extension-preservation.d.ts +15 -0
- package/dist/internal/features/work/work-docx-image-crop.d.ts +12 -0
- package/dist/internal/features/work/work-docx-image-identity.d.ts +17 -0
- package/dist/internal/features/work/work-docx-image-layer.d.ts +12 -0
- package/dist/internal/features/work/work-docx-image-layout-import.d.ts +14 -2
- package/dist/internal/features/work/work-docx-image-wrap.d.ts +15 -0
- package/dist/internal/features/work/work-docx-import.d.ts +13 -3
- package/dist/internal/features/work/work-docx-list-export.d.ts +18 -0
- package/dist/internal/features/work/work-docx-list-import.d.ts +14 -0
- package/dist/internal/features/work/work-docx-note-comment-content-control-block-preservation.d.ts +18 -0
- package/dist/internal/features/work/work-docx-note-comment-content-control-model.d.ts +47 -0
- package/dist/internal/features/work/work-docx-note-comment-content-control-preservation.d.ts +4 -0
- package/dist/internal/features/work/work-docx-note-comment-content-control-properties.d.ts +17 -0
- package/dist/internal/features/work/work-docx-note-comment-content-control-table-model.d.ts +17 -0
- package/dist/internal/features/work/work-docx-note-comment-content-control-xml.d.ts +14 -0
- package/dist/internal/features/work/work-docx-note-comment-extension-preservation.d.ts +2 -0
- package/dist/internal/features/work/work-docx-note-comment-hyperlink-content.d.ts +40 -0
- package/dist/internal/features/work/work-docx-note-comment-hyperlink-preservation.d.ts +5 -0
- package/dist/internal/features/work/work-docx-note-comment-hyperlink-relationships.d.ts +35 -0
- package/dist/internal/features/work/work-docx-note-comment-identity.d.ts +15 -0
- package/dist/internal/features/work/work-docx-note-comment-run-preservation.d.ts +4 -0
- package/dist/internal/features/work/work-docx-note-comment-run-properties.d.ts +2 -0
- package/dist/internal/features/work/work-docx-note-image-import.d.ts +12 -0
- package/dist/internal/features/work/work-docx-note-image-relationships.d.ts +1 -0
- package/dist/internal/features/work/work-docx-numbering-extension-preservation.d.ts +6 -0
- package/dist/internal/features/work/work-docx-numbering.d.ts +1 -0
- package/dist/internal/features/work/work-docx-page-borders-diagnostics.d.ts +3 -0
- package/dist/internal/features/work/work-docx-page-borders-import.d.ts +10 -0
- package/dist/internal/features/work/work-docx-page-margins-diagnostics.d.ts +3 -0
- package/dist/internal/features/work/work-docx-page-margins-import.d.ts +18 -0
- package/dist/internal/features/work/work-docx-page-size-diagnostics.d.ts +2 -0
- package/dist/internal/features/work/work-docx-page-size-import.d.ts +17 -0
- package/dist/internal/features/work/work-docx-paragraph-borders-diagnostics.d.ts +3 -0
- package/dist/internal/features/work/work-docx-paragraph-borders-export.d.ts +18 -0
- package/dist/internal/features/work/work-docx-paragraph-borders-import.d.ts +24 -0
- package/dist/internal/features/work/work-docx-paragraph-default-collapsed.d.ts +19 -0
- package/dist/internal/features/work/work-docx-paragraph-extension-preservation.d.ts +2 -0
- package/dist/internal/features/work/work-docx-paragraph-identity-import.d.ts +10 -0
- package/dist/internal/features/work/work-docx-paragraph-identity.d.ts +18 -0
- package/dist/internal/features/work/work-docx-paragraph-pagination-import.d.ts +6 -1
- package/dist/internal/features/work/work-docx-paragraph-shading-diagnostics.d.ts +3 -0
- package/dist/internal/features/work/work-docx-paragraph-shading-export.d.ts +5 -0
- package/dist/internal/features/work/work-docx-paragraph-shading-import.d.ts +18 -0
- package/dist/internal/features/work/work-docx-run-formatting-import.d.ts +3 -0
- package/dist/internal/features/work/work-docx-settings-preservation.d.ts +10 -0
- package/dist/internal/features/work/work-docx-settings-xml.d.ts +16 -0
- package/dist/internal/features/work/work-docx-style-extension-preservation.d.ts +2 -0
- package/dist/internal/features/work/work-docx-table-cell-export.d.ts +2 -1
- package/dist/internal/features/work/work-docx-table-cell-import.d.ts +3 -0
- package/dist/internal/features/work/work-docx-table-extension-preservation.d.ts +2 -0
- package/dist/internal/features/work/work-docx-table-row-import.d.ts +2 -0
- package/dist/internal/features/work/work-docx-table-sizing-import.d.ts +1 -0
- package/dist/internal/features/work/work-docx-theme-reference.d.ts +23 -0
- package/dist/internal/features/work/work-docx-theme.d.ts +4 -1
- package/dist/internal/features/work/work-docx-twips.d.ts +12 -0
- package/dist/internal/features/work/work-file-contract.d.ts +1 -0
- package/dist/internal/features/work/work-file-io.d.ts +1 -1
- package/dist/internal/features/work/work-markdown-extensions.d.ts +4 -1
- package/dist/internal/features/work/work-ooxml-package-preservation.d.ts +12 -0
- package/dist/internal/features/work/work-ooxml-package-security.d.ts +6 -0
- package/dist/internal/features/work/work-ooxml-relationship-preservation.d.ts +10 -0
- package/dist/internal/features/work/work-ooxml-xml.d.ts +2 -0
- package/dist/internal/features/work/work-pdf-export.d.ts +10 -0
- package/dist/internal/features/work/work-repository.d.ts +2 -0
- package/dist/internal/features/work/work-types.d.ts +15 -2
- package/dist/internal/kernel/office-kernel-client-types.d.ts +1 -0
- package/dist/internal/kernel/office-kernel-protocol.d.ts +7 -0
- package/dist/internal/kernel/office-kernel-version.d.ts +1 -1
- package/dist/office-kernel.wasm +0 -0
- package/dist/office-kernel.worker.js +93 -41
- package/dist/react.d.ts +18 -12
- package/dist/react.js +1 -1
- package/dist/styles.css +1367 -16
- package/dist/vue.d.ts +48 -5
- package/dist/vue.js +42 -3
- package/dist/web-component.d.ts +24 -2
- package/dist/web-component.js +101 -2
- package/docs/latest/en/browser-editor-architecture.md +262 -47
- package/package.json +29 -4
- package/dist/0~152.js +0 -94
- package/dist/0~2582.js +0 -485
- package/dist/0~4750.js +0 -939
- package/dist/0~5861.js +0 -596
- package/dist/0~work-document-extensions.js +0 -3045
- package/dist/0~work-document-model-codec.js +0 -42
- package/dist/0~work-docx-bibliography.js +0 -347
- package/dist/0~work-docx-page-color.js +0 -42
- package/dist/2881.js +0 -1455
- package/dist/8728.js +0 -723
package/dist/0~152.js
DELETED
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import { descendants, attribute } from "./8715.js";
|
|
2
|
-
function docxCaptionSequenceKind(instruction) {
|
|
3
|
-
const identifier = /^\s*SEQ\s+([^\s\\]+)/i.exec(instruction)?.[1]?.toLowerCase();
|
|
4
|
-
if (!identifier) return null;
|
|
5
|
-
if ('table' === identifier || '表' === identifier) return 'table';
|
|
6
|
-
if ('figure' === identifier || 'fig' === identifier || '图' === identifier) return 'figure';
|
|
7
|
-
return null;
|
|
8
|
-
}
|
|
9
|
-
function docxCaptionReferenceTarget(instruction) {
|
|
10
|
-
return /^\s*REF\s+([^\s\\]+)/i.exec(instruction)?.[1] ?? null;
|
|
11
|
-
}
|
|
12
|
-
function docxCaptionBookmark(paragraph, field) {
|
|
13
|
-
const bookmarks = descendants(paragraph, 'bookmarkStart').filter((bookmark)=>!/^_(?:GoBack|Toc)/i.test(attribute(bookmark, 'name') ?? ''));
|
|
14
|
-
const enclosing = bookmarks.filter((bookmark)=>bookmarkContains(paragraph, bookmark, field));
|
|
15
|
-
if (enclosing.length) return enclosing.at(-1);
|
|
16
|
-
return bookmarks.filter((bookmark)=>precedes(bookmark, field.start)).at(-1) ?? bookmarks[0];
|
|
17
|
-
}
|
|
18
|
-
function bookmarkContains(paragraph, start, field) {
|
|
19
|
-
const id = attribute(start, 'id');
|
|
20
|
-
if (!id) return false;
|
|
21
|
-
const end = descendants(paragraph, 'bookmarkEnd').find((bookmark)=>attribute(bookmark, 'id') === id);
|
|
22
|
-
return Boolean(end && precedes(start, field.start) && precedes(field.end, end));
|
|
23
|
-
}
|
|
24
|
-
function precedes(candidate, target) {
|
|
25
|
-
return Boolean(candidate.compareDocumentPosition(target) & Node.DOCUMENT_POSITION_FOLLOWING);
|
|
26
|
-
}
|
|
27
|
-
function docxFieldInstructions(root) {
|
|
28
|
-
return docxFieldOccurrences(root).map((field)=>field.instruction);
|
|
29
|
-
}
|
|
30
|
-
function docxFieldOccurrences(root) {
|
|
31
|
-
const fields = descendants(root, 'fldSimple').map((field)=>({
|
|
32
|
-
instruction: attribute(field, 'instr') ?? '',
|
|
33
|
-
start: field,
|
|
34
|
-
end: field
|
|
35
|
-
}));
|
|
36
|
-
const stack = [];
|
|
37
|
-
for (const element of Array.from(root.querySelectorAll('*'))){
|
|
38
|
-
if ('fldChar' === element.localName) {
|
|
39
|
-
const fieldType = attribute(element, 'fldCharType');
|
|
40
|
-
if ('begin' === fieldType) stack.push({
|
|
41
|
-
instruction: '',
|
|
42
|
-
start: element
|
|
43
|
-
});
|
|
44
|
-
else if ('end' === fieldType && stack.length) {
|
|
45
|
-
const field = stack.pop();
|
|
46
|
-
if (field) fields.push({
|
|
47
|
-
...field,
|
|
48
|
-
end: element
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
continue;
|
|
52
|
-
}
|
|
53
|
-
if ('instrText' === element.localName && stack.length) stack[stack.length - 1].instruction += element.textContent ?? '';
|
|
54
|
-
else if ('instrText' === element.localName) fields.push({
|
|
55
|
-
instruction: element.textContent ?? '',
|
|
56
|
-
start: element,
|
|
57
|
-
end: element
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
fields.push(...stack.map((field)=>({
|
|
61
|
-
...field,
|
|
62
|
-
end: field.start
|
|
63
|
-
})));
|
|
64
|
-
return fields.map((field)=>({
|
|
65
|
-
...field,
|
|
66
|
-
instruction: field.instruction.trim()
|
|
67
|
-
})).filter((field)=>Boolean(field.instruction));
|
|
68
|
-
}
|
|
69
|
-
function docxFieldResultText(field) {
|
|
70
|
-
if ('fldSimple' === field.start.localName) return descendants(field.start, 't').map((element)=>element.textContent ?? '').join('');
|
|
71
|
-
const root = closestAncestor(field.start, 'p') ?? field.start.ownerDocument?.documentElement;
|
|
72
|
-
if (!root) return '';
|
|
73
|
-
let inside = false;
|
|
74
|
-
let separated = false;
|
|
75
|
-
const values = [];
|
|
76
|
-
for (const element of Array.from(root.querySelectorAll('*'))){
|
|
77
|
-
if (element === field.start) inside = true;
|
|
78
|
-
if (inside) {
|
|
79
|
-
if ('fldChar' === element.localName && 'separate' === attribute(element, 'fldCharType')) separated = true;
|
|
80
|
-
else if (separated && ('t' === element.localName || 'delText' === element.localName)) values.push(element.textContent ?? '');
|
|
81
|
-
if (element === field.end) break;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
return values.join('');
|
|
85
|
-
}
|
|
86
|
-
function closestAncestor(element, localName) {
|
|
87
|
-
let current = element;
|
|
88
|
-
while(current){
|
|
89
|
-
if (current.localName === localName) return current;
|
|
90
|
-
current = current.parentElement;
|
|
91
|
-
}
|
|
92
|
-
return null;
|
|
93
|
-
}
|
|
94
|
-
export { docxCaptionBookmark, docxCaptionReferenceTarget, docxCaptionSequenceKind, docxFieldInstructions, docxFieldOccurrences, docxFieldResultText };
|
package/dist/0~2582.js
DELETED
|
@@ -1,485 +0,0 @@
|
|
|
1
|
-
import { Extension } from "@tiptap/core";
|
|
2
|
-
import { TableCell, TableHeader, TableRow } from "@tiptap/extension-table";
|
|
3
|
-
import { NodeSelection } from "@tiptap/pm/state";
|
|
4
|
-
import { CellSelection } from "@tiptap/pm/tables";
|
|
5
|
-
import { renderDocumentTableBorders, setSelectedDocumentTableBorders, normalizeTableColor, uniformDocumentTableBorder, documentTableBordersFromElement, normalizeDocumentTableBorderWidth, normalizeDocumentTableBorderStyle, documentTableBordersFromAttributes, normalizeDocumentTableCellMarginOverrides, renderDocumentTableCellMarginOverrides, documentTableCellMarginOverridesFromElement, uniformDocumentTableBorders } from "./0~4750.js";
|
|
6
|
-
const DOCUMENT_TABLE_STYLE_OPTIONS = [
|
|
7
|
-
{
|
|
8
|
-
id: 'grid',
|
|
9
|
-
label: '网格',
|
|
10
|
-
headerColor: '#f1f4f9',
|
|
11
|
-
bodyColor: '#ffffff',
|
|
12
|
-
alternateColor: '#ffffff',
|
|
13
|
-
borderColor: '#cfd5df',
|
|
14
|
-
borderStyle: 'solid',
|
|
15
|
-
borderWidth: 1
|
|
16
|
-
},
|
|
17
|
-
{
|
|
18
|
-
id: 'blueStripe',
|
|
19
|
-
label: '蓝色条纹',
|
|
20
|
-
headerColor: '#d9eaf7',
|
|
21
|
-
bodyColor: '#ffffff',
|
|
22
|
-
alternateColor: '#f7fbff',
|
|
23
|
-
borderColor: '#9fbad0',
|
|
24
|
-
borderStyle: 'solid',
|
|
25
|
-
borderWidth: 1
|
|
26
|
-
},
|
|
27
|
-
{
|
|
28
|
-
id: 'greenStripe',
|
|
29
|
-
label: '绿色条纹',
|
|
30
|
-
headerColor: '#ddeee7',
|
|
31
|
-
bodyColor: '#ffffff',
|
|
32
|
-
alternateColor: '#f4faf7',
|
|
33
|
-
borderColor: '#abc8be',
|
|
34
|
-
borderStyle: 'solid',
|
|
35
|
-
borderWidth: 1
|
|
36
|
-
},
|
|
37
|
-
{
|
|
38
|
-
id: 'grayStripe',
|
|
39
|
-
label: '灰色条纹',
|
|
40
|
-
headerColor: '#e7e9ed',
|
|
41
|
-
bodyColor: '#ffffff',
|
|
42
|
-
alternateColor: '#f6f7f9',
|
|
43
|
-
borderColor: '#b9c0ca',
|
|
44
|
-
borderStyle: 'solid',
|
|
45
|
-
borderWidth: 1
|
|
46
|
-
},
|
|
47
|
-
{
|
|
48
|
-
id: 'clean',
|
|
49
|
-
label: '简洁',
|
|
50
|
-
headerColor: '#f1f4f9',
|
|
51
|
-
bodyColor: '#ffffff',
|
|
52
|
-
alternateColor: '#ffffff',
|
|
53
|
-
borderColor: '#cfd5df',
|
|
54
|
-
borderStyle: 'none',
|
|
55
|
-
borderWidth: 0
|
|
56
|
-
}
|
|
57
|
-
];
|
|
58
|
-
const DEFAULT_DOCUMENT_TABLE_CELL_FORMAT = {
|
|
59
|
-
backgroundColor: '#ffffff',
|
|
60
|
-
verticalAlign: 'top',
|
|
61
|
-
borderColor: '#cfd5df',
|
|
62
|
-
borderStyle: 'solid',
|
|
63
|
-
borderWidth: 1,
|
|
64
|
-
borders: uniformDocumentTableBorders({
|
|
65
|
-
color: '#cfd5df',
|
|
66
|
-
style: 'solid',
|
|
67
|
-
width: 1
|
|
68
|
-
}),
|
|
69
|
-
margins: null
|
|
70
|
-
};
|
|
71
|
-
const DEFAULT_DOCUMENT_TABLE_HEADER_FORMAT = {
|
|
72
|
-
...DEFAULT_DOCUMENT_TABLE_CELL_FORMAT,
|
|
73
|
-
backgroundColor: '#f1f4f9'
|
|
74
|
-
};
|
|
75
|
-
const DocumentTableCell = TableCell.extend({
|
|
76
|
-
addAttributes () {
|
|
77
|
-
return {
|
|
78
|
-
...this.parent?.(),
|
|
79
|
-
...documentTableCellAttributes(DEFAULT_DOCUMENT_TABLE_CELL_FORMAT)
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
const DocumentTableHeader = TableHeader.extend({
|
|
84
|
-
addAttributes () {
|
|
85
|
-
return {
|
|
86
|
-
...this.parent?.(),
|
|
87
|
-
...documentTableCellAttributes(DEFAULT_DOCUMENT_TABLE_HEADER_FORMAT)
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
const DocumentTableFormatting = Extension.create({
|
|
92
|
-
name: 'documentTableFormatting',
|
|
93
|
-
addCommands () {
|
|
94
|
-
return {
|
|
95
|
-
setDocumentTableCellFormat: (format)=>(props)=>setSelectedCellFormat(props, format),
|
|
96
|
-
setDocumentTableHorizontalAlignment: (alignment)=>(props)=>setSelectedCellAlignment(props, alignment),
|
|
97
|
-
applyDocumentTableStyle: (style)=>(props)=>applyTableStyle(props, style),
|
|
98
|
-
setDocumentTableBorders: (target, border)=>(props)=>setSelectedDocumentTableBorders(props, target, border)
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
});
|
|
102
|
-
function documentTableCellFormat(state) {
|
|
103
|
-
const position = selectedTableCellPositions(state.selection)[0];
|
|
104
|
-
const node = void 0 === position ? null : state.doc.nodeAt(position);
|
|
105
|
-
return node && isTableCell(node) ? formatFromAttributes(node.attrs) : null;
|
|
106
|
-
}
|
|
107
|
-
function documentTableHorizontalAlignment(state) {
|
|
108
|
-
const position = selectedTableCellPositions(state.selection)[0];
|
|
109
|
-
const cell = void 0 === position ? null : state.doc.nodeAt(position);
|
|
110
|
-
let alignment = 'left';
|
|
111
|
-
cell?.descendants((node)=>{
|
|
112
|
-
if ('paragraph' !== node.type.name && 'heading' !== node.type.name) return true;
|
|
113
|
-
if ('center' === node.attrs.textAlign || 'right' === node.attrs.textAlign) alignment = node.attrs.textAlign;
|
|
114
|
-
return false;
|
|
115
|
-
});
|
|
116
|
-
return alignment;
|
|
117
|
-
}
|
|
118
|
-
function activeDocumentTableStyle(state) {
|
|
119
|
-
const context = selectedTable(state.selection);
|
|
120
|
-
if (!context) return null;
|
|
121
|
-
for (const style of DOCUMENT_TABLE_STYLE_OPTIONS){
|
|
122
|
-
let matches = true;
|
|
123
|
-
context.node.forEach((row, _rowOffset, rowIndex)=>{
|
|
124
|
-
row.forEach((cell)=>{
|
|
125
|
-
const expected = tableStyleCellFormat(style, cell, rowIndex);
|
|
126
|
-
const actual = formatFromAttributes(cell.attrs);
|
|
127
|
-
const expectedBorder = {
|
|
128
|
-
color: style.borderColor,
|
|
129
|
-
style: style.borderStyle,
|
|
130
|
-
width: style.borderWidth
|
|
131
|
-
};
|
|
132
|
-
const actualBorder = uniformDocumentTableBorder(actual.borders);
|
|
133
|
-
if (expected.backgroundColor !== actual.backgroundColor || !actualBorder || actualBorder.color !== expectedBorder.color || actualBorder.style !== expectedBorder.style || actualBorder.width !== expectedBorder.width) matches = false;
|
|
134
|
-
});
|
|
135
|
-
});
|
|
136
|
-
if (matches) return style.id;
|
|
137
|
-
}
|
|
138
|
-
return null;
|
|
139
|
-
}
|
|
140
|
-
function documentTableCellAttributes(defaults) {
|
|
141
|
-
return {
|
|
142
|
-
backgroundColor: {
|
|
143
|
-
default: defaults.backgroundColor,
|
|
144
|
-
parseHTML: (element)=>normalizeTableColor(element.dataset.officeCellFill || element.style.backgroundColor) ?? defaults.backgroundColor,
|
|
145
|
-
renderHTML: (attributes)=>{
|
|
146
|
-
const color = normalizeTableColor(String(attributes.backgroundColor ?? '')) ?? defaults.backgroundColor;
|
|
147
|
-
return {
|
|
148
|
-
'data-office-cell-fill': color,
|
|
149
|
-
style: `background-color: ${color}`
|
|
150
|
-
};
|
|
151
|
-
}
|
|
152
|
-
},
|
|
153
|
-
verticalAlign: {
|
|
154
|
-
default: defaults.verticalAlign,
|
|
155
|
-
parseHTML: (element)=>normalizeDocumentTableVerticalAlign(element.dataset.officeCellVerticalAlign || element.style.verticalAlign) ?? defaults.verticalAlign,
|
|
156
|
-
renderHTML: (attributes)=>{
|
|
157
|
-
const alignment = normalizeDocumentTableVerticalAlign(String(attributes.verticalAlign ?? '')) ?? defaults.verticalAlign;
|
|
158
|
-
return {
|
|
159
|
-
'data-office-cell-vertical-align': alignment,
|
|
160
|
-
style: `vertical-align: ${alignment}`
|
|
161
|
-
};
|
|
162
|
-
}
|
|
163
|
-
},
|
|
164
|
-
borderColor: {
|
|
165
|
-
default: defaults.borderColor,
|
|
166
|
-
parseHTML: (element)=>normalizeTableColor(element.dataset.officeCellBorderColor || element.style.borderColor) ?? defaults.borderColor,
|
|
167
|
-
renderHTML: ()=>({})
|
|
168
|
-
},
|
|
169
|
-
borderStyle: {
|
|
170
|
-
default: defaults.borderStyle,
|
|
171
|
-
parseHTML: (element)=>normalizeDocumentTableBorderStyle(element.dataset.officeCellBorderStyle || element.style.borderStyle) ?? defaults.borderStyle,
|
|
172
|
-
renderHTML: ()=>({})
|
|
173
|
-
},
|
|
174
|
-
borderWidth: {
|
|
175
|
-
default: defaults.borderWidth,
|
|
176
|
-
parseHTML: (element)=>normalizeDocumentTableBorderWidth(element.dataset.officeCellBorderWidth || element.style.borderWidth) ?? defaults.borderWidth,
|
|
177
|
-
renderHTML: ()=>({})
|
|
178
|
-
},
|
|
179
|
-
borders: {
|
|
180
|
-
default: defaults.borders,
|
|
181
|
-
parseHTML: (element)=>documentTableBordersFromElement(element, {
|
|
182
|
-
color: defaults.borderColor,
|
|
183
|
-
style: defaults.borderStyle,
|
|
184
|
-
width: defaults.borderWidth
|
|
185
|
-
}),
|
|
186
|
-
renderHTML: (attributes)=>renderDocumentTableBorders(formatFromAttributes(attributes, defaults).borders)
|
|
187
|
-
},
|
|
188
|
-
margins: {
|
|
189
|
-
default: defaults.margins,
|
|
190
|
-
parseHTML: (element)=>documentTableCellMarginOverridesFromElement(element),
|
|
191
|
-
renderHTML: (attributes)=>renderDocumentTableCellMarginOverrides(attributes.margins)
|
|
192
|
-
}
|
|
193
|
-
};
|
|
194
|
-
}
|
|
195
|
-
function setSelectedCellFormat({ dispatch, state }, patch) {
|
|
196
|
-
const normalized = normalizeFormatPatch(patch);
|
|
197
|
-
if (!normalized) return false;
|
|
198
|
-
const positions = selectedTableCellPositions(state.selection);
|
|
199
|
-
if (!positions.length) return false;
|
|
200
|
-
const transaction = state.tr;
|
|
201
|
-
for (const position of positions){
|
|
202
|
-
const cell = transaction.doc.nodeAt(position);
|
|
203
|
-
if (!cell || !isTableCell(cell)) continue;
|
|
204
|
-
const current = formatFromAttributes(cell.attrs);
|
|
205
|
-
const changesBorder = void 0 !== normalized.borderColor || void 0 !== normalized.borderStyle || void 0 !== normalized.borderWidth;
|
|
206
|
-
const nextBorder = {
|
|
207
|
-
color: normalized.borderColor ?? current.borderColor,
|
|
208
|
-
style: normalized.borderStyle ?? current.borderStyle,
|
|
209
|
-
width: normalized.borderWidth ?? current.borderWidth
|
|
210
|
-
};
|
|
211
|
-
if ('none' === nextBorder.style) nextBorder.width = 0;
|
|
212
|
-
transaction.setNodeMarkup(position, void 0, {
|
|
213
|
-
...cell.attrs,
|
|
214
|
-
...normalized,
|
|
215
|
-
...changesBorder ? {
|
|
216
|
-
borderColor: nextBorder.color,
|
|
217
|
-
borderStyle: nextBorder.style,
|
|
218
|
-
borderWidth: nextBorder.width,
|
|
219
|
-
borders: uniformDocumentTableBorders(nextBorder)
|
|
220
|
-
} : {}
|
|
221
|
-
});
|
|
222
|
-
}
|
|
223
|
-
if (dispatch && transaction.docChanged) dispatch(transaction.scrollIntoView());
|
|
224
|
-
return true;
|
|
225
|
-
}
|
|
226
|
-
function setSelectedCellAlignment({ dispatch, state }, alignment) {
|
|
227
|
-
if ('left' !== alignment && 'center' !== alignment && 'right' !== alignment) return false;
|
|
228
|
-
const positions = selectedTableCellPositions(state.selection);
|
|
229
|
-
if (!positions.length) return false;
|
|
230
|
-
const transaction = state.tr;
|
|
231
|
-
for (const position of positions){
|
|
232
|
-
const cell = transaction.doc.nodeAt(position);
|
|
233
|
-
if (cell && isTableCell(cell)) cell.descendants((node, offset)=>{
|
|
234
|
-
if ('paragraph' !== node.type.name && 'heading' !== node.type.name) return true;
|
|
235
|
-
transaction.setNodeMarkup(position + 1 + offset, void 0, {
|
|
236
|
-
...node.attrs,
|
|
237
|
-
textAlign: alignment
|
|
238
|
-
});
|
|
239
|
-
return false;
|
|
240
|
-
});
|
|
241
|
-
}
|
|
242
|
-
if (dispatch && transaction.docChanged) dispatch(transaction.scrollIntoView());
|
|
243
|
-
return true;
|
|
244
|
-
}
|
|
245
|
-
function applyTableStyle({ dispatch, state }, styleId) {
|
|
246
|
-
const style = DOCUMENT_TABLE_STYLE_OPTIONS.find((candidate)=>candidate.id === styleId);
|
|
247
|
-
const context = selectedTable(state.selection);
|
|
248
|
-
if (!style || !context) return false;
|
|
249
|
-
const transaction = state.tr;
|
|
250
|
-
context.node.forEach((row, rowOffset, rowIndex)=>{
|
|
251
|
-
row.forEach((cell, cellOffset)=>{
|
|
252
|
-
const position = context.position + 2 + rowOffset + cellOffset;
|
|
253
|
-
const format = tableStyleCellFormat(style, cell, rowIndex);
|
|
254
|
-
const border = {
|
|
255
|
-
color: style.borderColor,
|
|
256
|
-
style: style.borderStyle,
|
|
257
|
-
width: style.borderWidth
|
|
258
|
-
};
|
|
259
|
-
transaction.setNodeMarkup(position, void 0, {
|
|
260
|
-
...cell.attrs,
|
|
261
|
-
...format,
|
|
262
|
-
borders: uniformDocumentTableBorders(border)
|
|
263
|
-
});
|
|
264
|
-
});
|
|
265
|
-
});
|
|
266
|
-
if (dispatch && transaction.docChanged) dispatch(transaction.scrollIntoView());
|
|
267
|
-
return true;
|
|
268
|
-
}
|
|
269
|
-
function selectedTableCellPositions(selection) {
|
|
270
|
-
if (selection instanceof CellSelection) {
|
|
271
|
-
const positions = [];
|
|
272
|
-
selection.forEachCell((_node, position)=>positions.push(position));
|
|
273
|
-
return positions;
|
|
274
|
-
}
|
|
275
|
-
if (selection instanceof NodeSelection && 'table' === selection.node.type.spec.tableRole) {
|
|
276
|
-
const positions = [];
|
|
277
|
-
selection.node.forEach((row, rowOffset)=>{
|
|
278
|
-
row.forEach((_cell, cellOffset)=>{
|
|
279
|
-
positions.push(selection.from + 2 + rowOffset + cellOffset);
|
|
280
|
-
});
|
|
281
|
-
});
|
|
282
|
-
return positions;
|
|
283
|
-
}
|
|
284
|
-
const position = ancestorPosition(selection.$from, isTableCell);
|
|
285
|
-
return null === position ? [] : [
|
|
286
|
-
position
|
|
287
|
-
];
|
|
288
|
-
}
|
|
289
|
-
function selectedTable(selection) {
|
|
290
|
-
if (selection instanceof NodeSelection && 'table' === selection.node.type.spec.tableRole) return {
|
|
291
|
-
node: selection.node,
|
|
292
|
-
position: selection.from
|
|
293
|
-
};
|
|
294
|
-
for(let depth = selection.$from.depth; depth > 0; depth -= 1){
|
|
295
|
-
const node = selection.$from.node(depth);
|
|
296
|
-
if ('table' === node.type.spec.tableRole) return {
|
|
297
|
-
node,
|
|
298
|
-
position: selection.$from.before(depth)
|
|
299
|
-
};
|
|
300
|
-
}
|
|
301
|
-
return null;
|
|
302
|
-
}
|
|
303
|
-
function ancestorPosition(position, predicate) {
|
|
304
|
-
for(let depth = position.depth; depth > 0; depth -= 1)if (predicate(position.node(depth))) return position.before(depth);
|
|
305
|
-
return null;
|
|
306
|
-
}
|
|
307
|
-
function isTableCell(node) {
|
|
308
|
-
return 'cell' === node.type.spec.tableRole || 'header_cell' === node.type.spec.tableRole;
|
|
309
|
-
}
|
|
310
|
-
function tableStyleCellFormat(style, cell, rowIndex) {
|
|
311
|
-
return {
|
|
312
|
-
backgroundColor: 'header_cell' === cell.type.spec.tableRole ? style.headerColor : rowIndex % 2 === 1 ? style.alternateColor : style.bodyColor,
|
|
313
|
-
borderColor: style.borderColor,
|
|
314
|
-
borderStyle: style.borderStyle,
|
|
315
|
-
borderWidth: style.borderWidth
|
|
316
|
-
};
|
|
317
|
-
}
|
|
318
|
-
function normalizeFormatPatch(patch) {
|
|
319
|
-
const normalized = {};
|
|
320
|
-
if (void 0 !== patch.backgroundColor) {
|
|
321
|
-
const color = normalizeTableColor(patch.backgroundColor);
|
|
322
|
-
if (!color) return null;
|
|
323
|
-
normalized.backgroundColor = color;
|
|
324
|
-
}
|
|
325
|
-
if (void 0 !== patch.verticalAlign) {
|
|
326
|
-
const alignment = normalizeDocumentTableVerticalAlign(patch.verticalAlign);
|
|
327
|
-
if (!alignment) return null;
|
|
328
|
-
normalized.verticalAlign = alignment;
|
|
329
|
-
}
|
|
330
|
-
if (void 0 !== patch.borderColor) {
|
|
331
|
-
const color = normalizeTableColor(patch.borderColor);
|
|
332
|
-
if (!color) return null;
|
|
333
|
-
normalized.borderColor = color;
|
|
334
|
-
}
|
|
335
|
-
if (void 0 !== patch.borderStyle) {
|
|
336
|
-
const style = normalizeDocumentTableBorderStyle(patch.borderStyle);
|
|
337
|
-
if (!style) return null;
|
|
338
|
-
normalized.borderStyle = style;
|
|
339
|
-
}
|
|
340
|
-
if (void 0 !== patch.borderWidth) {
|
|
341
|
-
const width = normalizeDocumentTableBorderWidth(patch.borderWidth);
|
|
342
|
-
if (null === width) return null;
|
|
343
|
-
normalized.borderWidth = width;
|
|
344
|
-
}
|
|
345
|
-
if (void 0 !== patch.margins) if (null === patch.margins) normalized.margins = null;
|
|
346
|
-
else {
|
|
347
|
-
const margins = normalizeDocumentTableCellMarginOverrides(patch.margins);
|
|
348
|
-
if (!margins) return null;
|
|
349
|
-
normalized.margins = margins;
|
|
350
|
-
}
|
|
351
|
-
return normalized;
|
|
352
|
-
}
|
|
353
|
-
function formatFromAttributes(attributes, defaults = DEFAULT_DOCUMENT_TABLE_CELL_FORMAT) {
|
|
354
|
-
const fallbackBorder = {
|
|
355
|
-
color: normalizeTableColor(String(attributes.borderColor ?? '')) ?? defaults.borderColor,
|
|
356
|
-
style: normalizeDocumentTableBorderStyle(String(attributes.borderStyle ?? '')) ?? defaults.borderStyle,
|
|
357
|
-
width: normalizeDocumentTableBorderWidth(attributes.borderWidth) ?? defaults.borderWidth
|
|
358
|
-
};
|
|
359
|
-
if ('none' === fallbackBorder.style) fallbackBorder.width = 0;
|
|
360
|
-
const borders = documentTableBordersFromAttributes(attributes, fallbackBorder);
|
|
361
|
-
const representative = uniformDocumentTableBorder(borders) ?? borders.top;
|
|
362
|
-
return {
|
|
363
|
-
backgroundColor: normalizeTableColor(String(attributes.backgroundColor ?? '')) ?? defaults.backgroundColor,
|
|
364
|
-
verticalAlign: normalizeDocumentTableVerticalAlign(String(attributes.verticalAlign ?? '')) ?? defaults.verticalAlign,
|
|
365
|
-
borderColor: representative.color,
|
|
366
|
-
borderStyle: representative.style,
|
|
367
|
-
borderWidth: representative.width,
|
|
368
|
-
borders,
|
|
369
|
-
margins: normalizeDocumentTableCellMarginOverrides(attributes.margins)
|
|
370
|
-
};
|
|
371
|
-
}
|
|
372
|
-
function normalizeDocumentTableVerticalAlign(value) {
|
|
373
|
-
if ('top' === value || 'middle' === value || 'bottom' === value) return value;
|
|
374
|
-
if ('center' === value) return 'middle';
|
|
375
|
-
return null;
|
|
376
|
-
}
|
|
377
|
-
const DocumentTableRow = TableRow.extend({
|
|
378
|
-
addAttributes () {
|
|
379
|
-
return {
|
|
380
|
-
...this.parent?.() ?? {},
|
|
381
|
-
cantSplit: booleanRowAttribute('cantSplit', 'officeCantSplit', 'data-office-cant-split'),
|
|
382
|
-
repeatHeader: booleanRowAttribute('repeatHeader', 'officeRepeatHeader', 'data-office-repeat-header'),
|
|
383
|
-
rowHeight: {
|
|
384
|
-
default: null,
|
|
385
|
-
parseHTML: (element)=>normalizeDocumentTableRowHeight(element.dataset.officeRowHeight || element.style.height),
|
|
386
|
-
renderHTML: (attributes)=>{
|
|
387
|
-
const height = normalizeDocumentTableRowHeight(attributes.rowHeight);
|
|
388
|
-
return null === height ? {} : {
|
|
389
|
-
'data-office-row-height': String(height),
|
|
390
|
-
style: `height: ${height}px`
|
|
391
|
-
};
|
|
392
|
-
}
|
|
393
|
-
},
|
|
394
|
-
rowHeightRule: {
|
|
395
|
-
default: null,
|
|
396
|
-
parseHTML: (element)=>normalizeDocumentTableRowHeightRule(element.dataset.officeRowHeightRule),
|
|
397
|
-
renderHTML: (attributes)=>{
|
|
398
|
-
const rule = normalizeDocumentTableRowHeightRule(attributes.rowHeightRule);
|
|
399
|
-
return null === rule ? {} : {
|
|
400
|
-
'data-office-row-height-rule': rule
|
|
401
|
-
};
|
|
402
|
-
}
|
|
403
|
-
}
|
|
404
|
-
};
|
|
405
|
-
},
|
|
406
|
-
addCommands () {
|
|
407
|
-
return {
|
|
408
|
-
...this.parent?.() ?? {},
|
|
409
|
-
setDocumentTableRowOptions: (options, commandOptions = {})=>({ chain, editor })=>{
|
|
410
|
-
if (!editor.isActive('table')) return false;
|
|
411
|
-
let commandChain = chain();
|
|
412
|
-
if (false !== commandOptions.restoreFocus) commandChain = commandChain.focus();
|
|
413
|
-
return commandChain.updateAttributes('tableRow', {
|
|
414
|
-
cantSplit: Boolean(options.cantSplit),
|
|
415
|
-
repeatHeader: Boolean(options.repeatHeader)
|
|
416
|
-
}).run();
|
|
417
|
-
}
|
|
418
|
-
};
|
|
419
|
-
}
|
|
420
|
-
});
|
|
421
|
-
function documentTableRowOptions(editor) {
|
|
422
|
-
const attributes = editor.getAttributes('tableRow');
|
|
423
|
-
return {
|
|
424
|
-
cantSplit: directBoolean(attributes.cantSplit) ?? false,
|
|
425
|
-
repeatHeader: directBoolean(attributes.repeatHeader) ?? editor.isActive('tableHeader')
|
|
426
|
-
};
|
|
427
|
-
}
|
|
428
|
-
function canSetDocumentTableRowRepeatHeader(editor) {
|
|
429
|
-
const resolved = editor.state.selection.$from;
|
|
430
|
-
for(let depth = resolved.depth; depth > 0; depth -= 1){
|
|
431
|
-
if ('tableRow' !== resolved.node(depth).type.name) continue;
|
|
432
|
-
const tableDepth = depth - 1;
|
|
433
|
-
const table = resolved.node(tableDepth);
|
|
434
|
-
if ('table' !== table.type.name) break;
|
|
435
|
-
let leadingHeaderCount = 0;
|
|
436
|
-
for(let index = 0; index < table.childCount; index += 1){
|
|
437
|
-
if (!documentTableRowRepeats(table.child(index))) break;
|
|
438
|
-
leadingHeaderCount += 1;
|
|
439
|
-
}
|
|
440
|
-
return resolved.index(tableDepth) <= leadingHeaderCount;
|
|
441
|
-
}
|
|
442
|
-
return false;
|
|
443
|
-
}
|
|
444
|
-
function documentTableRowRepeats(node) {
|
|
445
|
-
const explicit = directBoolean(node.attrs.repeatHeader);
|
|
446
|
-
if (null !== explicit) return explicit;
|
|
447
|
-
if (0 === node.childCount) return false;
|
|
448
|
-
for(let index = 0; index < node.childCount; index += 1)if ('tableHeader' !== node.child(index).type.name) return false;
|
|
449
|
-
return true;
|
|
450
|
-
}
|
|
451
|
-
function documentTableRowCantSplit(node) {
|
|
452
|
-
return directBoolean(node.attrs.cantSplit) ?? false;
|
|
453
|
-
}
|
|
454
|
-
function documentTableRowHeight(attributes) {
|
|
455
|
-
const height = normalizeDocumentTableRowHeight(attributes.rowHeight);
|
|
456
|
-
return {
|
|
457
|
-
height,
|
|
458
|
-
rule: null === height ? null : normalizeDocumentTableRowHeightRule(attributes.rowHeightRule) ?? 'atLeast'
|
|
459
|
-
};
|
|
460
|
-
}
|
|
461
|
-
function normalizeDocumentTableRowHeight(value) {
|
|
462
|
-
const height = Number.parseFloat(String(value ?? '').replace(/px$/i, ''));
|
|
463
|
-
return Number.isFinite(height) && height > 0 ? Math.round(100 * height) / 100 : null;
|
|
464
|
-
}
|
|
465
|
-
function normalizeDocumentTableRowHeightRule(value) {
|
|
466
|
-
return 'exact' === value || 'atLeast' === value ? value : null;
|
|
467
|
-
}
|
|
468
|
-
function booleanRowAttribute(modelKey, datasetKey, htmlName) {
|
|
469
|
-
return {
|
|
470
|
-
default: null,
|
|
471
|
-
parseHTML: (element)=>directBoolean(element.dataset[datasetKey]),
|
|
472
|
-
renderHTML: (attributes)=>{
|
|
473
|
-
const value = directBoolean(attributes[modelKey]);
|
|
474
|
-
return null === value ? {} : {
|
|
475
|
-
[htmlName]: String(value)
|
|
476
|
-
};
|
|
477
|
-
}
|
|
478
|
-
};
|
|
479
|
-
}
|
|
480
|
-
function directBoolean(value) {
|
|
481
|
-
if (true === value || 'true' === value || '1' === value) return true;
|
|
482
|
-
if (false === value || 'false' === value || '0' === value) return false;
|
|
483
|
-
return null;
|
|
484
|
-
}
|
|
485
|
-
export { DEFAULT_DOCUMENT_TABLE_CELL_FORMAT, DOCUMENT_TABLE_STYLE_OPTIONS, DocumentTableCell, DocumentTableFormatting, DocumentTableHeader, DocumentTableRow, activeDocumentTableStyle, canSetDocumentTableRowRepeatHeader, documentTableCellFormat, documentTableHorizontalAlignment, documentTableRowCantSplit, documentTableRowHeight, documentTableRowOptions, documentTableRowRepeats, normalizeDocumentTableRowHeightRule, normalizeDocumentTableVerticalAlign };
|