@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~5050.js
CHANGED
|
@@ -1,8 +1,114 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
2
|
import { Copy, Languages, MessageSquareText, Sparkles, TextQuote, WandSparkles } from "lucide-react";
|
|
3
3
|
import { showToast, createAgentProposalRequest as createWorkAgentProposalRequest } from "./6489.js";
|
|
4
|
-
const
|
|
5
|
-
|
|
4
|
+
const SURROUNDING_TEXT_LIMIT = 2000;
|
|
5
|
+
function createWorkDocumentSelectionSnapshot(editor, content) {
|
|
6
|
+
const { from, to, empty } = editor.state.selection;
|
|
7
|
+
if (empty) return null;
|
|
8
|
+
const rawText = editor.state.doc.textBetween(from, to, '\n');
|
|
9
|
+
const text = rawText.trim();
|
|
10
|
+
if (!text) return null;
|
|
11
|
+
const beforeText = editor.state.doc.textBetween(0, from, '\n').slice(-SURROUNDING_TEXT_LIMIT);
|
|
12
|
+
const afterText = editor.state.doc.textBetween(to, editor.state.doc.content.size, '\n').slice(0, SURROUNDING_TEXT_LIMIT);
|
|
13
|
+
const selectedContent = editor.state.selection.content().content.toJSON();
|
|
14
|
+
return {
|
|
15
|
+
selection: {
|
|
16
|
+
from,
|
|
17
|
+
to,
|
|
18
|
+
text,
|
|
19
|
+
rawText,
|
|
20
|
+
beforeText,
|
|
21
|
+
afterText,
|
|
22
|
+
model: {
|
|
23
|
+
type: 'doc',
|
|
24
|
+
...selectedContent?.length ? {
|
|
25
|
+
content: selectedContent
|
|
26
|
+
} : {}
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
document: {
|
|
30
|
+
content,
|
|
31
|
+
html: editor.getHTML(),
|
|
32
|
+
text: editor.state.doc.textBetween(0, editor.state.doc.content.size, '\n')
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
function createWorkDocumentSelectionAction(editor, snapshot, getTrackChanges) {
|
|
37
|
+
let from = snapshot.selection.from;
|
|
38
|
+
let to = snapshot.selection.to;
|
|
39
|
+
let stale = false;
|
|
40
|
+
let disposed = false;
|
|
41
|
+
const handleTransaction = ({ transaction })=>{
|
|
42
|
+
if (!transaction.docChanged || stale || disposed) return;
|
|
43
|
+
const mappedFrom = transaction.mapping.mapResult(from, 1);
|
|
44
|
+
const mappedTo = transaction.mapping.mapResult(to, -1);
|
|
45
|
+
from = mappedFrom.pos;
|
|
46
|
+
to = mappedTo.pos;
|
|
47
|
+
stale = mappedFrom.deletedAcross || mappedTo.deletedAcross || from > to || transaction.doc.textBetween(from, to, '\n') !== snapshot.selection.rawText;
|
|
48
|
+
};
|
|
49
|
+
editor.on('transaction', handleTransaction);
|
|
50
|
+
const currentRange = ()=>{
|
|
51
|
+
if (disposed || editor.isDestroyed) return 'editor-unavailable';
|
|
52
|
+
if (!editor.isEditable) return 'read-only';
|
|
53
|
+
if (stale || from < 0 || to < from || to > editor.state.doc.content.size || editor.state.doc.textBetween(from, to, '\n') !== snapshot.selection.rawText) return 'stale-selection';
|
|
54
|
+
return {
|
|
55
|
+
from,
|
|
56
|
+
to
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
const editText = (text, placement)=>{
|
|
60
|
+
if ('string' != typeof text || 'replace' !== placement && !text) return {
|
|
61
|
+
applied: false,
|
|
62
|
+
reason: 'invalid-text'
|
|
63
|
+
};
|
|
64
|
+
const range = currentRange();
|
|
65
|
+
if ('string' == typeof range) return {
|
|
66
|
+
applied: false,
|
|
67
|
+
reason: range
|
|
68
|
+
};
|
|
69
|
+
const editRange = 'before' === placement ? {
|
|
70
|
+
from: range.from,
|
|
71
|
+
to: range.from
|
|
72
|
+
} : 'after' === placement ? {
|
|
73
|
+
from: range.to,
|
|
74
|
+
to: range.to
|
|
75
|
+
} : range;
|
|
76
|
+
const applied = getTrackChanges() ? editor.commands.replaceDocumentTextWithTrackedChange(editRange.from, editRange.to, text) : editor.chain().focus().setTextSelection(editRange).insertContent(documentPlainTextAsHtml(text)).run();
|
|
77
|
+
return applied ? {
|
|
78
|
+
applied: true
|
|
79
|
+
} : {
|
|
80
|
+
applied: false,
|
|
81
|
+
reason: 'command-rejected'
|
|
82
|
+
};
|
|
83
|
+
};
|
|
84
|
+
return {
|
|
85
|
+
context: {
|
|
86
|
+
...snapshot,
|
|
87
|
+
commands: {
|
|
88
|
+
copyText: async ()=>{
|
|
89
|
+
try {
|
|
90
|
+
if ("u" < typeof navigator || !navigator.clipboard?.writeText) return false;
|
|
91
|
+
await navigator.clipboard.writeText(snapshot.selection.rawText);
|
|
92
|
+
return true;
|
|
93
|
+
} catch {
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
insertAfter: (text)=>editText(text, 'after'),
|
|
98
|
+
insertBefore: (text)=>editText(text, 'before'),
|
|
99
|
+
replaceText: (text)=>editText(text, 'replace')
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
dispose: ()=>{
|
|
103
|
+
if (disposed) return;
|
|
104
|
+
disposed = true;
|
|
105
|
+
editor.off('transaction', handleTransaction);
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
function documentPlainTextAsHtml(value) {
|
|
110
|
+
return value.replaceAll('&', '&').replaceAll('<', '<').replaceAll('>', '>').replaceAll('"', '"').replaceAll("'", ''').replace(/\r?\n/g, '<br>');
|
|
111
|
+
}
|
|
6
112
|
function documentAgentMenuItems(selection, onAgentRequest, proposalOptions) {
|
|
7
113
|
return [
|
|
8
114
|
{
|
|
@@ -173,8 +279,21 @@ function documentCurrentPage(editor) {
|
|
|
173
279
|
function documentWordCount(value) {
|
|
174
280
|
return Array.from(value.matchAll(/[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}]|[\p{L}\p{N}]+/gu)).length;
|
|
175
281
|
}
|
|
176
|
-
function
|
|
177
|
-
|
|
282
|
+
function documentTextStatistics(editor) {
|
|
283
|
+
const text = editor.getText({
|
|
284
|
+
blockSeparator: '\n'
|
|
285
|
+
});
|
|
286
|
+
const characters = Array.from(text).filter((character)=>'\n' !== character && '\r' !== character);
|
|
287
|
+
let paragraphCount = 0;
|
|
288
|
+
editor.state.doc.descendants((node)=>{
|
|
289
|
+
if (node.isTextblock) paragraphCount += 1;
|
|
290
|
+
});
|
|
291
|
+
return {
|
|
292
|
+
characterCountWithSpaces: characters.length,
|
|
293
|
+
characterCountWithoutSpaces: characters.filter((character)=>!/\s/u.test(character)).length,
|
|
294
|
+
paragraphCount,
|
|
295
|
+
wordCount: documentWordCount(text)
|
|
296
|
+
};
|
|
178
297
|
}
|
|
179
298
|
async function copyDocumentSelection(selection) {
|
|
180
299
|
try {
|
|
@@ -185,114 +304,6 @@ async function copyDocumentSelection(selection) {
|
|
|
185
304
|
showToast('无法访问剪贴板,请使用系统复制快捷键。', 'error');
|
|
186
305
|
}
|
|
187
306
|
}
|
|
188
|
-
const SURROUNDING_TEXT_LIMIT = 2000;
|
|
189
|
-
function createWorkDocumentSelectionSnapshot(editor, content) {
|
|
190
|
-
const { from, to, empty } = editor.state.selection;
|
|
191
|
-
if (empty) return null;
|
|
192
|
-
const rawText = editor.state.doc.textBetween(from, to, '\n');
|
|
193
|
-
const text = rawText.trim();
|
|
194
|
-
if (!text) return null;
|
|
195
|
-
const beforeText = editor.state.doc.textBetween(0, from, '\n').slice(-SURROUNDING_TEXT_LIMIT);
|
|
196
|
-
const afterText = editor.state.doc.textBetween(to, editor.state.doc.content.size, '\n').slice(0, SURROUNDING_TEXT_LIMIT);
|
|
197
|
-
const selectedContent = editor.state.selection.content().content.toJSON();
|
|
198
|
-
return {
|
|
199
|
-
selection: {
|
|
200
|
-
from,
|
|
201
|
-
to,
|
|
202
|
-
text,
|
|
203
|
-
rawText,
|
|
204
|
-
beforeText,
|
|
205
|
-
afterText,
|
|
206
|
-
model: {
|
|
207
|
-
type: 'doc',
|
|
208
|
-
...selectedContent?.length ? {
|
|
209
|
-
content: selectedContent
|
|
210
|
-
} : {}
|
|
211
|
-
}
|
|
212
|
-
},
|
|
213
|
-
document: {
|
|
214
|
-
content,
|
|
215
|
-
html: editor.getHTML(),
|
|
216
|
-
text: editor.state.doc.textBetween(0, editor.state.doc.content.size, '\n')
|
|
217
|
-
}
|
|
218
|
-
};
|
|
219
|
-
}
|
|
220
|
-
function createWorkDocumentSelectionAction(editor, snapshot, getTrackChanges) {
|
|
221
|
-
let from = snapshot.selection.from;
|
|
222
|
-
let to = snapshot.selection.to;
|
|
223
|
-
let stale = false;
|
|
224
|
-
let disposed = false;
|
|
225
|
-
const handleTransaction = ({ transaction })=>{
|
|
226
|
-
if (!transaction.docChanged || stale || disposed) return;
|
|
227
|
-
const mappedFrom = transaction.mapping.mapResult(from, 1);
|
|
228
|
-
const mappedTo = transaction.mapping.mapResult(to, -1);
|
|
229
|
-
from = mappedFrom.pos;
|
|
230
|
-
to = mappedTo.pos;
|
|
231
|
-
stale = mappedFrom.deletedAcross || mappedTo.deletedAcross || from > to || transaction.doc.textBetween(from, to, '\n') !== snapshot.selection.rawText;
|
|
232
|
-
};
|
|
233
|
-
editor.on('transaction', handleTransaction);
|
|
234
|
-
const currentRange = ()=>{
|
|
235
|
-
if (disposed || editor.isDestroyed) return 'editor-unavailable';
|
|
236
|
-
if (!editor.isEditable) return 'read-only';
|
|
237
|
-
if (stale || from < 0 || to < from || to > editor.state.doc.content.size || editor.state.doc.textBetween(from, to, '\n') !== snapshot.selection.rawText) return 'stale-selection';
|
|
238
|
-
return {
|
|
239
|
-
from,
|
|
240
|
-
to
|
|
241
|
-
};
|
|
242
|
-
};
|
|
243
|
-
const editText = (text, placement)=>{
|
|
244
|
-
if ('string' != typeof text || 'replace' !== placement && !text) return {
|
|
245
|
-
applied: false,
|
|
246
|
-
reason: 'invalid-text'
|
|
247
|
-
};
|
|
248
|
-
const range = currentRange();
|
|
249
|
-
if ('string' == typeof range) return {
|
|
250
|
-
applied: false,
|
|
251
|
-
reason: range
|
|
252
|
-
};
|
|
253
|
-
const editRange = 'before' === placement ? {
|
|
254
|
-
from: range.from,
|
|
255
|
-
to: range.from
|
|
256
|
-
} : 'after' === placement ? {
|
|
257
|
-
from: range.to,
|
|
258
|
-
to: range.to
|
|
259
|
-
} : range;
|
|
260
|
-
const applied = getTrackChanges() ? editor.commands.replaceDocumentTextWithTrackedChange(editRange.from, editRange.to, text) : editor.chain().focus().setTextSelection(editRange).insertContent(documentPlainTextAsHtml(text)).run();
|
|
261
|
-
return applied ? {
|
|
262
|
-
applied: true
|
|
263
|
-
} : {
|
|
264
|
-
applied: false,
|
|
265
|
-
reason: 'command-rejected'
|
|
266
|
-
};
|
|
267
|
-
};
|
|
268
|
-
return {
|
|
269
|
-
context: {
|
|
270
|
-
...snapshot,
|
|
271
|
-
commands: {
|
|
272
|
-
copyText: async ()=>{
|
|
273
|
-
try {
|
|
274
|
-
if ("u" < typeof navigator || !navigator.clipboard?.writeText) return false;
|
|
275
|
-
await navigator.clipboard.writeText(snapshot.selection.rawText);
|
|
276
|
-
return true;
|
|
277
|
-
} catch {
|
|
278
|
-
return false;
|
|
279
|
-
}
|
|
280
|
-
},
|
|
281
|
-
insertAfter: (text)=>editText(text, 'after'),
|
|
282
|
-
insertBefore: (text)=>editText(text, 'before'),
|
|
283
|
-
replaceText: (text)=>editText(text, 'replace')
|
|
284
|
-
}
|
|
285
|
-
},
|
|
286
|
-
dispose: ()=>{
|
|
287
|
-
if (disposed) return;
|
|
288
|
-
disposed = true;
|
|
289
|
-
editor.off('transaction', handleTransaction);
|
|
290
|
-
}
|
|
291
|
-
};
|
|
292
|
-
}
|
|
293
|
-
function documentPlainTextAsHtml(value) {
|
|
294
|
-
return value.replaceAll('&', '&').replaceAll('<', '<').replaceAll('>', '>').replaceAll('"', '"').replaceAll("'", ''').replace(/\r?\n/g, '<br>');
|
|
295
|
-
}
|
|
296
307
|
function mergeOfficeTiptapExtensions(editorName, builtInExtensions, additionalExtensions) {
|
|
297
308
|
const names = new Set();
|
|
298
309
|
for (const extension of builtInExtensions)names.add(extension.name);
|
|
@@ -305,4 +316,4 @@ function mergeOfficeTiptapExtensions(editorName, builtInExtensions, additionalEx
|
|
|
305
316
|
...additionalExtensions
|
|
306
317
|
];
|
|
307
318
|
}
|
|
308
|
-
export {
|
|
319
|
+
export { createWorkDocumentSelectionAction, createWorkDocumentSelectionSnapshot, customSelectionMenuItems, documentAgentMenuItems, documentCurrentPage, documentCustomSelectionMenuItems, documentPageCount, documentPlainTextAsHtml, documentTextStatistics, mergeOfficeTiptapExtensions };
|