@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/4560.js
ADDED
|
@@ -0,0 +1,674 @@
|
|
|
1
|
+
import { initializeWorkOfficeCollaborationMetadata, assertWorkOfficeCollaborationEditable, OfficeCollaborationError as WorkOfficeCollaborationError, readOfficeCollaborationMetadata as readWorkOfficeCollaborationMetadata, registerWorkOfficeCollaborationInitializer, markWorkOfficeCollaborationInitialized, assertWorkOfficeCollaborationOrigin } from "./9787.js";
|
|
2
|
+
import { workOfficeCollaborationJsonEqual, isWorkOfficeCollaborationRecord, cloneWorkOfficeCollaborationJson } from "./4650.js";
|
|
3
|
+
import * as __rspack_external_yjs from "yjs";
|
|
4
|
+
function validateWorkOfficePresentationContent(content) {
|
|
5
|
+
if (!content || 'presentation' !== content.type) invalidWorkOfficePresentationInput('a Presentation content value');
|
|
6
|
+
const result = {
|
|
7
|
+
type: 'presentation',
|
|
8
|
+
slides: validateRecords(content.slides, 'slide', validateSlide)
|
|
9
|
+
};
|
|
10
|
+
if (void 0 !== content.width) result.width = requiredFiniteNumber(content.width, 'presentation width');
|
|
11
|
+
if (void 0 !== content.height) result.height = requiredFiniteNumber(content.height, 'presentation height');
|
|
12
|
+
if (void 0 !== content.masters) result.masters = validateRecords(content.masters, 'presentation master', validateMaster);
|
|
13
|
+
if (void 0 !== content.layouts) result.layouts = validateRecords(content.layouts, 'presentation layout', validateLayout);
|
|
14
|
+
assertPresentationReferences(result);
|
|
15
|
+
return result;
|
|
16
|
+
}
|
|
17
|
+
function validateSharedWorkOfficePresentationContent(content) {
|
|
18
|
+
try {
|
|
19
|
+
return validateWorkOfficePresentationContent(content);
|
|
20
|
+
} catch (error) {
|
|
21
|
+
if (error instanceof WorkOfficeCollaborationError) throw new WorkOfficeCollaborationError('office.collaboration.content_invalid', `The shared Presentation collaboration content is invalid: ${error.message}`);
|
|
22
|
+
throw error;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
function invalidWorkOfficePresentationShared(label) {
|
|
26
|
+
throw new WorkOfficeCollaborationError('office.collaboration.content_invalid', `The shared Presentation collaboration ${label} is invalid.`);
|
|
27
|
+
}
|
|
28
|
+
function validateRecords(value, label, validate) {
|
|
29
|
+
if (!Array.isArray(value)) invalidWorkOfficePresentationInput(`an array of ${label}s`);
|
|
30
|
+
const ids = new Set();
|
|
31
|
+
return value.map((item)=>{
|
|
32
|
+
const validated = validate(item);
|
|
33
|
+
if (ids.has(validated.id)) invalidWorkOfficePresentationInput(`a unique ${label} ID; '${validated.id}' is repeated`);
|
|
34
|
+
ids.add(validated.id);
|
|
35
|
+
return validated;
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
function validateSlide(value) {
|
|
39
|
+
const record = requiredInputRecord(value, 'slide');
|
|
40
|
+
const slide = validateJsonRecord(record, 'slide');
|
|
41
|
+
slide.id = requiredIdentifier(record.id, 'slide');
|
|
42
|
+
slide.name = requiredString(record.name, 'slide name');
|
|
43
|
+
slide.background = requiredString(record.background, 'slide background');
|
|
44
|
+
slide.elements = validateRecords(record.elements, `element in slide '${slide.id}'`, validateElement);
|
|
45
|
+
if (void 0 !== record.layoutId) slide.layoutId = requiredIdentifier(record.layoutId, 'slide layout');
|
|
46
|
+
if (void 0 !== record.comments) slide.comments = validateRecords(record.comments, `comment in slide '${slide.id}'`, validateComment);
|
|
47
|
+
return slide;
|
|
48
|
+
}
|
|
49
|
+
function validateMaster(value) {
|
|
50
|
+
const record = requiredInputRecord(value, 'presentation master');
|
|
51
|
+
const master = validateJsonRecord(record, 'presentation master');
|
|
52
|
+
master.id = requiredIdentifier(record.id, 'presentation master');
|
|
53
|
+
master.name = requiredString(record.name, 'presentation master name');
|
|
54
|
+
master.background = requiredString(record.background, 'presentation master background');
|
|
55
|
+
master.elements = validateRecords(record.elements, `element in presentation master '${master.id}'`, validateElement);
|
|
56
|
+
return master;
|
|
57
|
+
}
|
|
58
|
+
function validateLayout(value) {
|
|
59
|
+
const record = requiredInputRecord(value, 'presentation layout');
|
|
60
|
+
const layout = validateJsonRecord(record, 'presentation layout');
|
|
61
|
+
layout.id = requiredIdentifier(record.id, 'presentation layout');
|
|
62
|
+
layout.name = requiredString(record.name, 'presentation layout name');
|
|
63
|
+
layout.masterId = requiredIdentifier(record.masterId, 'presentation layout master');
|
|
64
|
+
layout.elements = validateRecords(record.elements, `element in presentation layout '${layout.id}'`, validateElement);
|
|
65
|
+
return layout;
|
|
66
|
+
}
|
|
67
|
+
function validateElement(value) {
|
|
68
|
+
const record = requiredInputRecord(value, 'presentation element');
|
|
69
|
+
const element = validateJsonRecord(record, 'presentation element');
|
|
70
|
+
element.id = requiredIdentifier(record.id, 'presentation element');
|
|
71
|
+
element.type = requiredString(record.type, 'presentation element type');
|
|
72
|
+
if ('text' !== element.type && 'shape' !== element.type && 'image' !== element.type && 'table' !== element.type && 'chart' !== element.type && 'line' !== element.type) invalidWorkOfficePresentationInput('a supported presentation element type');
|
|
73
|
+
for (const key of [
|
|
74
|
+
'x',
|
|
75
|
+
'y',
|
|
76
|
+
'width',
|
|
77
|
+
'height',
|
|
78
|
+
'fontSize'
|
|
79
|
+
])element[key] = requiredFiniteNumber(record[key], `presentation element ${key}`);
|
|
80
|
+
element.text = requiredString(record.text, 'presentation element text');
|
|
81
|
+
element.color = requiredString(record.color, 'presentation element color');
|
|
82
|
+
element.fill = requiredString(record.fill, 'presentation element fill');
|
|
83
|
+
if ('boolean' != typeof record.bold) invalidWorkOfficePresentationInput('a boolean presentation element bold value');
|
|
84
|
+
element.bold = record.bold;
|
|
85
|
+
if ('left' !== record.align && 'center' !== record.align && 'right' !== record.align) invalidWorkOfficePresentationInput('a supported presentation text alignment');
|
|
86
|
+
element.align = record.align;
|
|
87
|
+
return element;
|
|
88
|
+
}
|
|
89
|
+
function validateComment(value) {
|
|
90
|
+
const record = requiredInputRecord(value, 'slide comment');
|
|
91
|
+
const comment = validateJsonRecord(record, 'slide comment');
|
|
92
|
+
comment.id = requiredIdentifier(record.id, 'slide comment');
|
|
93
|
+
comment.author = requiredString(record.author, 'slide comment author');
|
|
94
|
+
comment.date = requiredString(record.date, 'slide comment date');
|
|
95
|
+
comment.text = requiredString(record.text, 'slide comment text');
|
|
96
|
+
comment.x = requiredFiniteNumber(record.x, 'slide comment x');
|
|
97
|
+
comment.y = requiredFiniteNumber(record.y, 'slide comment y');
|
|
98
|
+
if (void 0 !== record.initials) comment.initials = requiredString(record.initials, 'slide comment initials');
|
|
99
|
+
return comment;
|
|
100
|
+
}
|
|
101
|
+
function validateJsonRecord(value, label) {
|
|
102
|
+
try {
|
|
103
|
+
return cloneWorkOfficeCollaborationJson(value);
|
|
104
|
+
} catch (error) {
|
|
105
|
+
throw new WorkOfficeCollaborationError('office.collaboration.content_invalid', `Presentation collaboration requires a JSON-compatible ${label}: ${error instanceof Error ? error.message : String(error)}`);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
function assertPresentationReferences(content) {
|
|
109
|
+
const masterIds = new Set((content.masters ?? []).map(({ id })=>id));
|
|
110
|
+
for (const layout of content.layouts ?? [])if (!masterIds.has(layout.masterId)) invalidWorkOfficePresentationInput(`presentation layout '${layout.id}' to reference an existing master`);
|
|
111
|
+
const layoutIds = new Set((content.layouts ?? []).map(({ id })=>id));
|
|
112
|
+
for (const slide of content.slides)if (void 0 !== slide.layoutId && !layoutIds.has(slide.layoutId)) invalidWorkOfficePresentationInput(`slide '${slide.id}' to reference an existing presentation layout`);
|
|
113
|
+
}
|
|
114
|
+
function requiredInputRecord(value, label) {
|
|
115
|
+
if (!isWorkOfficeCollaborationRecord(value)) invalidWorkOfficePresentationInput(`a valid ${label} record`);
|
|
116
|
+
return value;
|
|
117
|
+
}
|
|
118
|
+
function requiredIdentifier(value, label) {
|
|
119
|
+
const result = requiredString(value, `${label} ID`);
|
|
120
|
+
if (!result || result !== result.trim() || result.length > 256) invalidWorkOfficePresentationInput(`a ${label} ID containing 1 to 256 characters`);
|
|
121
|
+
return result;
|
|
122
|
+
}
|
|
123
|
+
function requiredString(value, label) {
|
|
124
|
+
if ('string' != typeof value) invalidWorkOfficePresentationInput(`a string ${label}`);
|
|
125
|
+
return value;
|
|
126
|
+
}
|
|
127
|
+
function requiredFiniteNumber(value, label) {
|
|
128
|
+
if ('number' != typeof value || !Number.isFinite(value)) invalidWorkOfficePresentationInput(`a finite number for ${label}`);
|
|
129
|
+
return value;
|
|
130
|
+
}
|
|
131
|
+
function invalidWorkOfficePresentationInput(expected) {
|
|
132
|
+
throw new WorkOfficeCollaborationError('office.collaboration.content_invalid', `Presentation collaboration requires ${expected}.`);
|
|
133
|
+
}
|
|
134
|
+
const PRESENTATION_RECORD_ELEMENTS = 'elements';
|
|
135
|
+
const PRESENTATION_RECORD_ELEMENT_ORDER = 'elementOrder';
|
|
136
|
+
const PRESENTATION_RECORD_COMMENTS = 'comments';
|
|
137
|
+
const PRESENTATION_RECORD_COMMENT_ORDER = 'commentOrder';
|
|
138
|
+
const PRESENTATION_RECORD_COMMENTS_PRESENT = 'commentsPresent';
|
|
139
|
+
function nestedPresentationMap(parent, key, label) {
|
|
140
|
+
const existing = parent.get(key);
|
|
141
|
+
if (existing instanceof __rspack_external_yjs.Map) return existing;
|
|
142
|
+
if (void 0 !== existing) invalidWorkOfficePresentationShared(label);
|
|
143
|
+
const value = new __rspack_external_yjs.Map();
|
|
144
|
+
parent.set(key, value);
|
|
145
|
+
return value;
|
|
146
|
+
}
|
|
147
|
+
function nestedPresentationArray(parent, key, label) {
|
|
148
|
+
const existing = parent.get(key);
|
|
149
|
+
if (existing instanceof __rspack_external_yjs.Array) return existing;
|
|
150
|
+
if (void 0 !== existing) invalidWorkOfficePresentationShared(label);
|
|
151
|
+
const value = new __rspack_external_yjs.Array();
|
|
152
|
+
parent.set(key, value);
|
|
153
|
+
return value;
|
|
154
|
+
}
|
|
155
|
+
function requiredPresentationMap(parent, key, label) {
|
|
156
|
+
const value = parent.get(key);
|
|
157
|
+
if (!(value instanceof __rspack_external_yjs.Map)) invalidWorkOfficePresentationShared(label);
|
|
158
|
+
return value;
|
|
159
|
+
}
|
|
160
|
+
function requiredPresentationArray(parent, key, label) {
|
|
161
|
+
const value = parent.get(key);
|
|
162
|
+
if (!(value instanceof __rspack_external_yjs.Array)) invalidWorkOfficePresentationShared(label);
|
|
163
|
+
return value;
|
|
164
|
+
}
|
|
165
|
+
function validatedPresentationOrder(order, records, label) {
|
|
166
|
+
const seen = new Set();
|
|
167
|
+
const values = [];
|
|
168
|
+
for (const value of order.toArray()){
|
|
169
|
+
if ('string' != typeof value || !value.trim()) invalidWorkOfficePresentationShared(`${label} order`);
|
|
170
|
+
if (!seen.has(value)) {
|
|
171
|
+
seen.add(value);
|
|
172
|
+
values.push(value);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
if (seen.size !== records.size || Array.from(records.keys()).some((id)=>!seen.has(id))) invalidWorkOfficePresentationShared(`${label} order and record set`);
|
|
176
|
+
return values;
|
|
177
|
+
}
|
|
178
|
+
function readPresentationCollection(records, order, label) {
|
|
179
|
+
return validatedPresentationOrder(order, records, label).map((id)=>{
|
|
180
|
+
const record = requiredPresentationMap(records, id, label);
|
|
181
|
+
assertCommentRootsMatchRecordKind(record, label);
|
|
182
|
+
const value = {};
|
|
183
|
+
for (const [key, item] of record.entries()){
|
|
184
|
+
if (key === PRESENTATION_RECORD_COMMENTS_PRESENT) {
|
|
185
|
+
if ('slide' !== label || true !== item) invalidWorkOfficePresentationShared(`${label} comment presence`);
|
|
186
|
+
continue;
|
|
187
|
+
}
|
|
188
|
+
if (!isNestedPresentationField(key)) {
|
|
189
|
+
if (item instanceof __rspack_external_yjs.AbstractType) invalidWorkOfficePresentationShared(`${label} field '${key}'`);
|
|
190
|
+
value[key] = cloneWorkOfficeCollaborationJson(item);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
if (value.id !== id) invalidWorkOfficePresentationShared(`${label} identity`);
|
|
194
|
+
value.elements = readIdRecords(requiredPresentationMap(record, PRESENTATION_RECORD_ELEMENTS, `${label} elements`), requiredPresentationArray(record, PRESENTATION_RECORD_ELEMENT_ORDER, `${label} element order`), `${label} element`);
|
|
195
|
+
if ('slide' === label) readSlideComments(record, value);
|
|
196
|
+
return value;
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
function patchPresentationElements(records, order, previous, next, parentLabel) {
|
|
200
|
+
patchPresentationIdRecords(records, order, previous, next, `${parentLabel} element`);
|
|
201
|
+
}
|
|
202
|
+
function patchPresentationIdRecords(records, order, previous, next, label) {
|
|
203
|
+
const previousById = new Map(previous.map((value)=>[
|
|
204
|
+
value.id,
|
|
205
|
+
value
|
|
206
|
+
]));
|
|
207
|
+
const nextById = new Map(next.map((value)=>[
|
|
208
|
+
value.id,
|
|
209
|
+
value
|
|
210
|
+
]));
|
|
211
|
+
for (const value of previous)if (!nextById.has(value.id)) records.delete(value.id);
|
|
212
|
+
for (const value of next){
|
|
213
|
+
const before = previousById.get(value.id);
|
|
214
|
+
if (before && workOfficeCollaborationJsonEqual(before, value)) continue;
|
|
215
|
+
let record = records.get(value.id);
|
|
216
|
+
if (void 0 === record) {
|
|
217
|
+
record = new __rspack_external_yjs.Map();
|
|
218
|
+
records.set(value.id, record);
|
|
219
|
+
}
|
|
220
|
+
if (!(record instanceof __rspack_external_yjs.Map)) invalidWorkOfficePresentationShared(label);
|
|
221
|
+
patchPresentationJsonMap(record, before ?? {}, value);
|
|
222
|
+
}
|
|
223
|
+
patchPresentationOrder(order, previous.map((value)=>value.id), next.map((value)=>value.id));
|
|
224
|
+
}
|
|
225
|
+
function patchPresentationOrder(order, previous, next) {
|
|
226
|
+
if (workOfficeCollaborationJsonEqual(previous, next)) return;
|
|
227
|
+
const nextIds = new Set(next);
|
|
228
|
+
for (const id of previous)if (!nextIds.has(id)) removeAll(order, id);
|
|
229
|
+
const previousIds = new Set(previous);
|
|
230
|
+
for (const id of next)if (!(previousIds.has(id) || order.toArray().includes(id))) insertRelative(order, next, id);
|
|
231
|
+
if (!sameRelativeOrder(previous, next)) {
|
|
232
|
+
const changedIds = next.filter((id)=>previousIds.has(id));
|
|
233
|
+
for (const id of changedIds)removeAll(order, id);
|
|
234
|
+
for (const id of next)if (!order.toArray().includes(id)) insertRelative(order, next, id);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
function assertCommentRootsMatchRecordKind(record, label) {
|
|
238
|
+
if ('slide' !== label && (record.has(PRESENTATION_RECORD_COMMENTS) || record.has(PRESENTATION_RECORD_COMMENT_ORDER) || record.has(PRESENTATION_RECORD_COMMENTS_PRESENT))) invalidWorkOfficePresentationShared(`${label} comments`);
|
|
239
|
+
}
|
|
240
|
+
function isNestedPresentationField(key) {
|
|
241
|
+
return key === PRESENTATION_RECORD_ELEMENTS || key === PRESENTATION_RECORD_ELEMENT_ORDER || key === PRESENTATION_RECORD_COMMENTS || key === PRESENTATION_RECORD_COMMENT_ORDER;
|
|
242
|
+
}
|
|
243
|
+
function readSlideComments(record, value) {
|
|
244
|
+
const commentRecords = requiredPresentationMap(record, PRESENTATION_RECORD_COMMENTS, 'slide comments');
|
|
245
|
+
const commentOrder = requiredPresentationArray(record, PRESENTATION_RECORD_COMMENT_ORDER, 'slide comment order');
|
|
246
|
+
if (commentRecords.size > 0 || commentOrder.length > 0) value.comments = readIdRecords(commentRecords, commentOrder, 'slide comment');
|
|
247
|
+
else if (true === record.get(PRESENTATION_RECORD_COMMENTS_PRESENT)) value.comments = [];
|
|
248
|
+
}
|
|
249
|
+
function readIdRecords(records, order, label) {
|
|
250
|
+
return validatedPresentationOrder(order, records, label).map((id)=>readJsonMap(requiredPresentationMap(records, id, label), id, label));
|
|
251
|
+
}
|
|
252
|
+
function readJsonMap(record, expectedId, label) {
|
|
253
|
+
const value = {};
|
|
254
|
+
for (const [key, item] of record.entries()){
|
|
255
|
+
if (item instanceof __rspack_external_yjs.AbstractType) invalidWorkOfficePresentationShared(`${label} field '${key}'`);
|
|
256
|
+
value[key] = cloneWorkOfficeCollaborationJson(item);
|
|
257
|
+
}
|
|
258
|
+
if (value.id !== expectedId) invalidWorkOfficePresentationShared(`${label} identity`);
|
|
259
|
+
return value;
|
|
260
|
+
}
|
|
261
|
+
function patchPresentationJsonMap(target, previous, next) {
|
|
262
|
+
const keys = new Set([
|
|
263
|
+
...Object.keys(previous),
|
|
264
|
+
...Object.keys(next)
|
|
265
|
+
]);
|
|
266
|
+
for (const key of keys)if (!workOfficeCollaborationJsonEqual(previous[key], next[key])) if (void 0 === next[key]) target.delete(key);
|
|
267
|
+
else target.set(key, cloneWorkOfficeCollaborationJson(next[key]));
|
|
268
|
+
}
|
|
269
|
+
function insertRelative(order, desired, id) {
|
|
270
|
+
const desiredIndex = desired.indexOf(id);
|
|
271
|
+
for(let index = desiredIndex - 1; index >= 0; index -= 1){
|
|
272
|
+
const currentIndex = order.toArray().indexOf(desired[index]);
|
|
273
|
+
if (currentIndex >= 0) return void order.insert(currentIndex + 1, [
|
|
274
|
+
id
|
|
275
|
+
]);
|
|
276
|
+
}
|
|
277
|
+
for(let index = desiredIndex + 1; index < desired.length; index += 1){
|
|
278
|
+
const currentIndex = order.toArray().indexOf(desired[index]);
|
|
279
|
+
if (currentIndex >= 0) return void order.insert(currentIndex, [
|
|
280
|
+
id
|
|
281
|
+
]);
|
|
282
|
+
}
|
|
283
|
+
order.push([
|
|
284
|
+
id
|
|
285
|
+
]);
|
|
286
|
+
}
|
|
287
|
+
function sameRelativeOrder(previous, next) {
|
|
288
|
+
const nextIds = new Set(next);
|
|
289
|
+
const previousIds = new Set(previous);
|
|
290
|
+
return workOfficeCollaborationJsonEqual(previous.filter((id)=>nextIds.has(id)), next.filter((id)=>previousIds.has(id)));
|
|
291
|
+
}
|
|
292
|
+
function removeAll(order, id) {
|
|
293
|
+
for(let index = order.length - 1; index >= 0; index -= 1)if (order.get(index) === id) order.delete(index, 1);
|
|
294
|
+
}
|
|
295
|
+
const PRESENTATION_OPTIONS_ROOT = 'presentation.options';
|
|
296
|
+
const PRESENTATION_SLIDES_ROOT = 'presentation.slides';
|
|
297
|
+
const PRESENTATION_SLIDE_ORDER_ROOT = 'presentation.slide-order';
|
|
298
|
+
const PRESENTATION_MASTERS_ROOT = 'presentation.masters';
|
|
299
|
+
const PRESENTATION_MASTER_ORDER_ROOT = 'presentation.master-order';
|
|
300
|
+
const PRESENTATION_LAYOUTS_ROOT = 'presentation.layouts';
|
|
301
|
+
const PRESENTATION_LAYOUT_ORDER_ROOT = 'presentation.layout-order';
|
|
302
|
+
function workOfficePresentationRoots(document, rootName) {
|
|
303
|
+
return {
|
|
304
|
+
options: document.getMap(rootName(PRESENTATION_OPTIONS_ROOT)),
|
|
305
|
+
slides: document.getMap(rootName(PRESENTATION_SLIDES_ROOT)),
|
|
306
|
+
slideOrder: document.getArray(rootName(PRESENTATION_SLIDE_ORDER_ROOT)),
|
|
307
|
+
masters: document.getMap(rootName(PRESENTATION_MASTERS_ROOT)),
|
|
308
|
+
masterOrder: document.getArray(rootName(PRESENTATION_MASTER_ORDER_ROOT)),
|
|
309
|
+
layouts: document.getMap(rootName(PRESENTATION_LAYOUTS_ROOT)),
|
|
310
|
+
layoutOrder: document.getArray(rootName(PRESENTATION_LAYOUT_ORDER_ROOT))
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
function initializeWorkOfficePresentationRoots(roots, content) {
|
|
314
|
+
patchOptionalJson(roots.options, 'width', void 0, content.width);
|
|
315
|
+
patchOptionalJson(roots.options, 'height', void 0, content.height);
|
|
316
|
+
patchCollection({
|
|
317
|
+
label: 'slide',
|
|
318
|
+
order: roots.slideOrder,
|
|
319
|
+
previous: [],
|
|
320
|
+
records: roots.slides,
|
|
321
|
+
next: content.slides
|
|
322
|
+
});
|
|
323
|
+
patchCollection({
|
|
324
|
+
label: 'presentation master',
|
|
325
|
+
order: roots.masterOrder,
|
|
326
|
+
previous: [],
|
|
327
|
+
records: roots.masters,
|
|
328
|
+
next: content.masters ?? []
|
|
329
|
+
});
|
|
330
|
+
patchCollection({
|
|
331
|
+
label: 'presentation layout',
|
|
332
|
+
order: roots.layoutOrder,
|
|
333
|
+
previous: [],
|
|
334
|
+
records: roots.layouts,
|
|
335
|
+
next: content.layouts ?? []
|
|
336
|
+
});
|
|
337
|
+
}
|
|
338
|
+
function readWorkOfficePresentationRoots(roots) {
|
|
339
|
+
const width = optionalSharedNumber(roots.options.get('width'), 'presentation width');
|
|
340
|
+
const height = optionalSharedNumber(roots.options.get('height'), 'presentation height');
|
|
341
|
+
const result = {
|
|
342
|
+
type: 'presentation',
|
|
343
|
+
slides: readPresentationCollection(roots.slides, roots.slideOrder, 'slide')
|
|
344
|
+
};
|
|
345
|
+
if (void 0 !== width) result.width = width;
|
|
346
|
+
if (void 0 !== height) result.height = height;
|
|
347
|
+
const masters = readPresentationCollection(roots.masters, roots.masterOrder, 'presentation master');
|
|
348
|
+
const layouts = readPresentationCollection(roots.layouts, roots.layoutOrder, 'presentation layout');
|
|
349
|
+
if (masters.length > 0) result.masters = masters;
|
|
350
|
+
if (layouts.length > 0) result.layouts = layouts;
|
|
351
|
+
return validateSharedWorkOfficePresentationContent(result);
|
|
352
|
+
}
|
|
353
|
+
function patchWorkOfficePresentationRoots(roots, previous, next) {
|
|
354
|
+
const shared = readWorkOfficePresentationRoots(roots);
|
|
355
|
+
assertChangedRecordsStillExist(previous, next, shared);
|
|
356
|
+
patchOptionalJson(roots.options, 'width', previous.width, next.width);
|
|
357
|
+
patchOptionalJson(roots.options, 'height', previous.height, next.height);
|
|
358
|
+
patchCollection({
|
|
359
|
+
label: 'slide',
|
|
360
|
+
order: roots.slideOrder,
|
|
361
|
+
previous: previous.slides,
|
|
362
|
+
records: roots.slides,
|
|
363
|
+
next: next.slides
|
|
364
|
+
});
|
|
365
|
+
patchCollection({
|
|
366
|
+
label: 'presentation master',
|
|
367
|
+
order: roots.masterOrder,
|
|
368
|
+
previous: previous.masters ?? [],
|
|
369
|
+
records: roots.masters,
|
|
370
|
+
next: next.masters ?? []
|
|
371
|
+
});
|
|
372
|
+
patchCollection({
|
|
373
|
+
label: 'presentation layout',
|
|
374
|
+
order: roots.layoutOrder,
|
|
375
|
+
previous: previous.layouts ?? [],
|
|
376
|
+
records: roots.layouts,
|
|
377
|
+
next: next.layouts ?? []
|
|
378
|
+
});
|
|
379
|
+
}
|
|
380
|
+
function assertChangedRecordsStillExist(previous, next, shared) {
|
|
381
|
+
assertChangedCollectionExists(previous.slides, next.slides, shared.slides, 'slide');
|
|
382
|
+
assertChangedCollectionExists(previous.masters ?? [], next.masters ?? [], shared.masters ?? [], 'presentation master');
|
|
383
|
+
assertChangedCollectionExists(previous.layouts ?? [], next.layouts ?? [], shared.layouts ?? [], 'presentation layout');
|
|
384
|
+
}
|
|
385
|
+
function assertChangedCollectionExists(previous, next, shared, label) {
|
|
386
|
+
const previousById = new Map(previous.map((value)=>[
|
|
387
|
+
value.id,
|
|
388
|
+
value
|
|
389
|
+
]));
|
|
390
|
+
const sharedById = new Map(shared.map((value)=>[
|
|
391
|
+
value.id,
|
|
392
|
+
value
|
|
393
|
+
]));
|
|
394
|
+
for (const value of next){
|
|
395
|
+
const before = previousById.get(value.id);
|
|
396
|
+
const current = sharedById.get(value.id);
|
|
397
|
+
if (before && !workOfficeCollaborationJsonEqual(before, value) && !current) throw new WorkOfficeCollaborationError('office.collaboration.content_invalid', `The ${label} '${value.id}' was removed before this change could be applied. Refresh the shared snapshot before retrying.`);
|
|
398
|
+
if (before && current) {
|
|
399
|
+
assertChangedChildRecordsExist(before.elements, value.elements, current.elements, `element in ${label} '${value.id}'`);
|
|
400
|
+
if ('slide' === label) assertChangedChildRecordsExist(before.comments ?? [], value.comments ?? [], current.comments ?? [], `comment in slide '${value.id}'`);
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
function assertChangedChildRecordsExist(previous, next, shared, label) {
|
|
405
|
+
const previousById = new Map(previous.map((value)=>[
|
|
406
|
+
value.id,
|
|
407
|
+
value
|
|
408
|
+
]));
|
|
409
|
+
const sharedIds = new Set(shared.map((value)=>value.id));
|
|
410
|
+
for (const value of next){
|
|
411
|
+
const before = previousById.get(value.id);
|
|
412
|
+
if (before && !workOfficeCollaborationJsonEqual(before, value) && !sharedIds.has(value.id)) throw new WorkOfficeCollaborationError('office.collaboration.content_invalid', `The ${label} '${value.id}' was removed before this change could be applied. Refresh the shared snapshot before retrying.`);
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
function assertWorkOfficePresentationRootsEmpty(roots) {
|
|
416
|
+
if (roots.options.size > 0 || roots.slides.size > 0 || roots.slideOrder.length > 0 || roots.masters.size > 0 || roots.masterOrder.length > 0 || roots.layouts.size > 0 || roots.layoutOrder.length > 0) throw new WorkOfficeCollaborationError('office.collaboration.bootstrap_ambiguous', 'The Presentation collaboration roots contain data without initialized metadata.');
|
|
417
|
+
}
|
|
418
|
+
function workOfficePresentationUndoScope(roots) {
|
|
419
|
+
return [
|
|
420
|
+
roots.options,
|
|
421
|
+
roots.slides,
|
|
422
|
+
roots.slideOrder,
|
|
423
|
+
roots.masters,
|
|
424
|
+
roots.masterOrder,
|
|
425
|
+
roots.layouts,
|
|
426
|
+
roots.layoutOrder
|
|
427
|
+
];
|
|
428
|
+
}
|
|
429
|
+
function patchCollection({ label, order, previous, records, next }) {
|
|
430
|
+
const previousById = new Map(previous.map((value)=>[
|
|
431
|
+
value.id,
|
|
432
|
+
value
|
|
433
|
+
]));
|
|
434
|
+
const nextById = new Map(next.map((value)=>[
|
|
435
|
+
value.id,
|
|
436
|
+
value
|
|
437
|
+
]));
|
|
438
|
+
for (const value of previous)if (!nextById.has(value.id)) {
|
|
439
|
+
records.delete(value.id);
|
|
440
|
+
office_presentation_collaboration_model_removeAll(order, value.id);
|
|
441
|
+
}
|
|
442
|
+
for (const value of next){
|
|
443
|
+
const before = previousById.get(value.id);
|
|
444
|
+
if (before && workOfficeCollaborationJsonEqual(before, value)) continue;
|
|
445
|
+
let record = records.get(value.id);
|
|
446
|
+
if (void 0 === record) {
|
|
447
|
+
record = new __rspack_external_yjs.Map();
|
|
448
|
+
records.set(value.id, record);
|
|
449
|
+
}
|
|
450
|
+
if (!(record instanceof __rspack_external_yjs.Map)) invalidWorkOfficePresentationShared(label);
|
|
451
|
+
patchRecord(record, before, value, label);
|
|
452
|
+
}
|
|
453
|
+
patchPresentationOrder(order, previous.map((value)=>value.id), next.map((value)=>value.id));
|
|
454
|
+
}
|
|
455
|
+
function patchRecord(record, previous, next, label) {
|
|
456
|
+
const elements = nestedPresentationMap(record, PRESENTATION_RECORD_ELEMENTS, `${label} elements`);
|
|
457
|
+
const elementOrder = nestedPresentationArray(record, PRESENTATION_RECORD_ELEMENT_ORDER, `${label} element order`);
|
|
458
|
+
const nextRecord = next;
|
|
459
|
+
const previousRecord = previous;
|
|
460
|
+
const keys = new Set([
|
|
461
|
+
...Object.keys(previousRecord ?? {}),
|
|
462
|
+
...Object.keys(nextRecord)
|
|
463
|
+
]);
|
|
464
|
+
keys.delete('elements');
|
|
465
|
+
keys.delete('comments');
|
|
466
|
+
for (const key of keys)if (!(previous && workOfficeCollaborationJsonEqual(previousRecord?.[key], nextRecord[key]))) if (void 0 === nextRecord[key]) record.delete(key);
|
|
467
|
+
else record.set(key, cloneWorkOfficeCollaborationJson(nextRecord[key]));
|
|
468
|
+
const comments = 'slide' === label ? nestedPresentationMap(record, PRESENTATION_RECORD_COMMENTS, 'slide comments') : void 0;
|
|
469
|
+
const commentOrder = 'slide' === label ? nestedPresentationArray(record, PRESENTATION_RECORD_COMMENT_ORDER, 'slide comment order') : void 0;
|
|
470
|
+
patchPresentationElements(elements, elementOrder, previous?.elements ?? [], next.elements, label);
|
|
471
|
+
if (comments && commentOrder) {
|
|
472
|
+
const previousComments = previousRecord?.comments;
|
|
473
|
+
const nextComments = nextRecord.comments;
|
|
474
|
+
if (void 0 !== previousComments || void 0 !== nextComments) {
|
|
475
|
+
if (void 0 !== nextComments) record.set(PRESENTATION_RECORD_COMMENTS_PRESENT, true);
|
|
476
|
+
else record.delete(PRESENTATION_RECORD_COMMENTS_PRESENT);
|
|
477
|
+
patchPresentationIdRecords(comments, commentOrder, previousComments ?? [], nextComments ?? [], 'slide comment');
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
function optionalSharedNumber(value, label) {
|
|
482
|
+
if (void 0 === value) return;
|
|
483
|
+
if ('number' != typeof value || !Number.isFinite(value)) invalidWorkOfficePresentationShared(label);
|
|
484
|
+
return value;
|
|
485
|
+
}
|
|
486
|
+
function office_presentation_collaboration_model_removeAll(order, id) {
|
|
487
|
+
for(let index = order.length - 1; index >= 0; index -= 1)if (order.get(index) === id) order.delete(index, 1);
|
|
488
|
+
}
|
|
489
|
+
function patchOptionalJson(target, key, previous, next) {
|
|
490
|
+
if (workOfficeCollaborationJsonEqual(previous, next)) return;
|
|
491
|
+
if (void 0 === next) target.delete(key);
|
|
492
|
+
else target.set(key, cloneWorkOfficeCollaborationJson(next));
|
|
493
|
+
}
|
|
494
|
+
function initializeWorkOfficePresentationCollaboration(session, content) {
|
|
495
|
+
assertPresentationSession(session);
|
|
496
|
+
assertWorkOfficeCollaborationEditable(session);
|
|
497
|
+
const prepared = validateWorkOfficePresentationContent(content);
|
|
498
|
+
const existing = readWorkOfficeCollaborationMetadata(session);
|
|
499
|
+
if (existing?.initialized) return {
|
|
500
|
+
initialized: false,
|
|
501
|
+
content: readWorkOfficePresentationCollaboration(session)
|
|
502
|
+
};
|
|
503
|
+
const roots = presentationRoots(session);
|
|
504
|
+
assertWorkOfficePresentationRootsEmpty(roots);
|
|
505
|
+
const origin = session.createOrigin('bootstrap');
|
|
506
|
+
session.transact(()=>{
|
|
507
|
+
const metadata = initializeWorkOfficeCollaborationMetadata(session);
|
|
508
|
+
if (metadata.initialized) return;
|
|
509
|
+
registerWorkOfficeCollaborationInitializer(session);
|
|
510
|
+
initializeWorkOfficePresentationRoots(roots, prepared);
|
|
511
|
+
markWorkOfficeCollaborationInitialized(session);
|
|
512
|
+
}, origin);
|
|
513
|
+
return {
|
|
514
|
+
initialized: true,
|
|
515
|
+
content: readWorkOfficePresentationCollaboration(session)
|
|
516
|
+
};
|
|
517
|
+
}
|
|
518
|
+
function readWorkOfficePresentationCollaboration(session) {
|
|
519
|
+
assertInitializedPresentationSession(session);
|
|
520
|
+
return readWorkOfficePresentationRoots(presentationRoots(session));
|
|
521
|
+
}
|
|
522
|
+
function replaceWorkOfficePresentationCollaboration(session, previous, next, origin = session.localOrigin) {
|
|
523
|
+
assertInitializedPresentationSession(session);
|
|
524
|
+
assertWorkOfficeCollaborationEditable(session);
|
|
525
|
+
const before = validateWorkOfficePresentationContent(previous);
|
|
526
|
+
const after = validateWorkOfficePresentationContent(next);
|
|
527
|
+
if (workOfficeCollaborationJsonEqual(before, after)) return false;
|
|
528
|
+
session.transact(()=>{
|
|
529
|
+
patchWorkOfficePresentationRoots(presentationRoots(session), before, after);
|
|
530
|
+
}, origin);
|
|
531
|
+
return true;
|
|
532
|
+
}
|
|
533
|
+
function createWorkOfficePresentationCollaborationBinding(session, options = {}) {
|
|
534
|
+
assertInitializedPresentationSession(session);
|
|
535
|
+
return new WorkOfficePresentationCollaborationBindingImpl(session, options);
|
|
536
|
+
}
|
|
537
|
+
class WorkOfficePresentationCollaborationBindingImpl {
|
|
538
|
+
origin;
|
|
539
|
+
#session;
|
|
540
|
+
#undoManager;
|
|
541
|
+
#roots;
|
|
542
|
+
#undoScope;
|
|
543
|
+
#listeners = new Set();
|
|
544
|
+
#errorListeners = new Set();
|
|
545
|
+
#historyListeners = new Set();
|
|
546
|
+
#destroyed = false;
|
|
547
|
+
#pendingChange = false;
|
|
548
|
+
#pendingLocal = true;
|
|
549
|
+
#pendingOrigin;
|
|
550
|
+
constructor(session, options){
|
|
551
|
+
this.#session = session;
|
|
552
|
+
this.#roots = presentationRoots(session);
|
|
553
|
+
this.origin = options.origin ?? session.createOrigin(session.localOrigin.kind);
|
|
554
|
+
assertWorkOfficeCollaborationOrigin(this.origin);
|
|
555
|
+
this.#undoScope = workOfficePresentationUndoScope(this.#roots);
|
|
556
|
+
this.#undoManager = new __rspack_external_yjs.UndoManager(this.#undoScope, {
|
|
557
|
+
captureTimeout: options.captureTimeoutMs ?? 500,
|
|
558
|
+
trackedOrigins: new Set([
|
|
559
|
+
this.origin
|
|
560
|
+
])
|
|
561
|
+
});
|
|
562
|
+
session.document.on('afterTransaction', this.#onTransaction);
|
|
563
|
+
this.#undoManager.on('stack-item-added', this.#onHistoryChange);
|
|
564
|
+
this.#undoManager.on('stack-item-popped', this.#onHistoryChange);
|
|
565
|
+
this.#undoManager.on('stack-item-updated', this.#onHistoryChange);
|
|
566
|
+
}
|
|
567
|
+
content() {
|
|
568
|
+
this.ensureActive();
|
|
569
|
+
return readWorkOfficePresentationRoots(this.#roots);
|
|
570
|
+
}
|
|
571
|
+
replace(previous, next) {
|
|
572
|
+
this.ensureActive();
|
|
573
|
+
return replaceWorkOfficePresentationCollaboration(this.#session, previous, next, this.origin);
|
|
574
|
+
}
|
|
575
|
+
canUndo() {
|
|
576
|
+
this.ensureActive();
|
|
577
|
+
return this.#undoManager.canUndo();
|
|
578
|
+
}
|
|
579
|
+
canRedo() {
|
|
580
|
+
this.ensureActive();
|
|
581
|
+
return this.#undoManager.canRedo();
|
|
582
|
+
}
|
|
583
|
+
undo() {
|
|
584
|
+
this.ensureActive();
|
|
585
|
+
assertWorkOfficeCollaborationEditable(this.#session);
|
|
586
|
+
return null !== this.#undoManager.undo();
|
|
587
|
+
}
|
|
588
|
+
redo() {
|
|
589
|
+
this.ensureActive();
|
|
590
|
+
assertWorkOfficeCollaborationEditable(this.#session);
|
|
591
|
+
return null !== this.#undoManager.redo();
|
|
592
|
+
}
|
|
593
|
+
stopCapturing() {
|
|
594
|
+
this.ensureActive();
|
|
595
|
+
this.#undoManager.stopCapturing();
|
|
596
|
+
}
|
|
597
|
+
subscribe(listener) {
|
|
598
|
+
this.ensureActive();
|
|
599
|
+
this.#listeners.add(listener);
|
|
600
|
+
return ()=>this.#listeners.delete(listener);
|
|
601
|
+
}
|
|
602
|
+
subscribeError(listener) {
|
|
603
|
+
this.ensureActive();
|
|
604
|
+
this.#errorListeners.add(listener);
|
|
605
|
+
return ()=>this.#errorListeners.delete(listener);
|
|
606
|
+
}
|
|
607
|
+
subscribeHistory(listener) {
|
|
608
|
+
this.ensureActive();
|
|
609
|
+
this.#historyListeners.add(listener);
|
|
610
|
+
return ()=>this.#historyListeners.delete(listener);
|
|
611
|
+
}
|
|
612
|
+
destroy() {
|
|
613
|
+
if (this.#destroyed) return;
|
|
614
|
+
this.#destroyed = true;
|
|
615
|
+
this.#pendingChange = false;
|
|
616
|
+
this.#session.document.off('afterTransaction', this.#onTransaction);
|
|
617
|
+
this.#undoManager.off('stack-item-added', this.#onHistoryChange);
|
|
618
|
+
this.#undoManager.off('stack-item-popped', this.#onHistoryChange);
|
|
619
|
+
this.#undoManager.off('stack-item-updated', this.#onHistoryChange);
|
|
620
|
+
this.#undoManager.destroy();
|
|
621
|
+
this.#listeners.clear();
|
|
622
|
+
this.#errorListeners.clear();
|
|
623
|
+
this.#historyListeners.clear();
|
|
624
|
+
}
|
|
625
|
+
#onTransaction = (transaction)=>{
|
|
626
|
+
const changedParents = new Set(transaction.changedParentTypes.keys());
|
|
627
|
+
if (this.#destroyed || !this.#undoScope.some((root)=>changedParents.has(root))) return;
|
|
628
|
+
const local = transaction.origin === this.origin || transaction.origin === this.#undoManager;
|
|
629
|
+
this.#pendingLocal = this.#pendingChange ? this.#pendingLocal && local : local;
|
|
630
|
+
this.#pendingOrigin = transaction.origin;
|
|
631
|
+
if (this.#pendingChange) return;
|
|
632
|
+
this.#pendingChange = true;
|
|
633
|
+
queueMicrotask(this.#flushChange);
|
|
634
|
+
};
|
|
635
|
+
#flushChange = ()=>{
|
|
636
|
+
if (this.#destroyed || !this.#pendingChange) return;
|
|
637
|
+
const local = this.#pendingLocal;
|
|
638
|
+
const origin = this.#pendingOrigin;
|
|
639
|
+
this.#pendingChange = false;
|
|
640
|
+
this.#pendingLocal = true;
|
|
641
|
+
this.#pendingOrigin = void 0;
|
|
642
|
+
try {
|
|
643
|
+
const change = {
|
|
644
|
+
content: this.content(),
|
|
645
|
+
local,
|
|
646
|
+
origin
|
|
647
|
+
};
|
|
648
|
+
for (const listener of this.#listeners)listener(change);
|
|
649
|
+
} catch (error) {
|
|
650
|
+
for (const listener of this.#errorListeners)listener(error);
|
|
651
|
+
}
|
|
652
|
+
};
|
|
653
|
+
#onHistoryChange = ()=>{
|
|
654
|
+
for (const listener of this.#historyListeners)listener();
|
|
655
|
+
};
|
|
656
|
+
ensureActive() {
|
|
657
|
+
if (!this.#destroyed) return;
|
|
658
|
+
throw new WorkOfficeCollaborationError('office.collaboration.binding_destroyed', 'The Presentation collaboration binding has been destroyed.');
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
function presentationRoots(session) {
|
|
662
|
+
return workOfficePresentationRoots(session.document, session.rootName.bind(session));
|
|
663
|
+
}
|
|
664
|
+
function assertPresentationSession(session) {
|
|
665
|
+
if ('presentation' === session.kind) return;
|
|
666
|
+
throw new WorkOfficeCollaborationError('office.collaboration.kind_mismatch', `A Presentation collaboration binding cannot use a '${session.kind}' session.`);
|
|
667
|
+
}
|
|
668
|
+
function assertInitializedPresentationSession(session) {
|
|
669
|
+
assertPresentationSession(session);
|
|
670
|
+
const metadata = readWorkOfficeCollaborationMetadata(session);
|
|
671
|
+
if (metadata?.initialized) return;
|
|
672
|
+
throw new WorkOfficeCollaborationError('office.collaboration.not_initialized', 'The Presentation collaboration session has not been initialized.');
|
|
673
|
+
}
|
|
674
|
+
export { createWorkOfficePresentationCollaborationBinding as createOfficePresentationCollaborationBinding, initializeWorkOfficePresentationCollaboration as initializeOfficePresentationCollaboration, readWorkOfficePresentationCollaboration as readOfficePresentationCollaboration, replaceWorkOfficePresentationCollaboration as replaceOfficePresentationCollaboration };
|