@stll/folio-core 0.71.1 → 0.73.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/README.md +14 -8
- package/dist/ai-edits/apply.d.ts +6 -114
- package/dist/ai-edits/apply.js +9 -131
- package/dist/ai-edits/applyTypes.d.ts +85 -0
- package/dist/ai-edits/applyTypes.js +24 -0
- package/dist/ai-edits/clean-text.d.ts +7 -1
- package/dist/ai-edits/clean-text.js +23 -2
- package/dist/ai-edits/finalSectionReview.d.ts +1 -1
- package/dist/ai-edits/headless.d.ts +29 -147
- package/dist/ai-edits/headless.js +213 -1634
- package/dist/ai-edits/index.d.ts +3 -3
- package/dist/ai-edits/index.js +2 -3
- package/dist/ai-edits/pending-suggestions.d.ts +14 -4
- package/dist/ai-edits/pending-suggestions.js +183 -90
- package/dist/ai-edits/result-validation.js +1 -1
- package/dist/ai-edits/retired-comment-receipts.d.ts +1 -1
- package/dist/ai-edits/snapshot.js +8 -3
- package/dist/ai-edits/table-cell-mutations.d.ts +1 -1
- package/dist/ai-edits/table-cell-mutations.js +1 -1
- package/dist/ai-edits/table-geometry.d.ts +1 -1
- package/dist/ai-edits/table-geometry.js +1 -1
- package/dist/ai-edits/table-row-column-mutations.d.ts +1 -1
- package/dist/ai-edits/table-row-column-mutations.js +1 -1
- package/dist/ai-edits/tableNodes.d.ts +38 -0
- package/dist/ai-edits/tableNodes.js +86 -0
- package/dist/ai-edits/tracked-batch-fidelity.d.ts +1 -1
- package/dist/ai-edits/undefinedReferences.d.ts +7 -0
- package/dist/canonical/batchCommentReferences.js +1 -0
- package/dist/canonical/canonicalInlineProjection.js +1 -1
- package/dist/canonical/canonicalPublicOperations.js +228 -64
- package/dist/canonical/canonicalSession.d.ts +9 -1
- package/dist/canonical/canonicalSession.js +95 -15
- package/dist/compare/compare.d.ts +1 -1
- package/dist/compare/inline-atoms-model.d.ts +1 -1
- package/dist/compare/inline-atoms.d.ts +2 -2
- package/dist/compare/inline-provenance-model.d.ts +1 -1
- package/dist/compare/inline-provenance.d.ts +2 -2
- package/dist/compat/eigenpal.d.ts +3 -4
- package/dist/compat/eigenpal.js +2 -4
- package/dist/controller/canonicalClipboard.d.ts +13 -3
- package/dist/controller/canonicalClipboard.js +185 -49
- package/dist/controller/canonicalClipboardResources.d.ts +9 -1
- package/dist/controller/canonicalClipboardResources.js +22 -2
- package/dist/controller/canonicalReview.d.ts +1 -1
- package/dist/controller/canonicalReview.js +1 -1
- package/dist/controller/canonicalStructure.js +1 -1
- package/dist/controller/canonicalWatermark.d.ts +10 -0
- package/dist/controller/canonicalWatermark.js +37 -0
- package/dist/controller/canonicalYjsRoom.d.ts +1 -1
- package/dist/controller/headerFooterEditorManager.d.ts +11 -7
- package/dist/controller/headerFooterEditorManager.js +39 -151
- package/dist/controller/hiddenEditorApi.d.ts +1 -1
- package/dist/controller/hiddenEditorManager.d.ts +6 -40
- package/dist/controller/hiddenEditorManager.js +173 -306
- package/dist/controller/noteEditorManager.d.ts +3 -10
- package/dist/controller/noteEditorManager.js +33 -206
- package/dist/document-operations-apply.d.ts +15 -0
- package/dist/document-operations-apply.js +280 -0
- package/dist/document-operations.d.ts +1 -14
- package/dist/document-operations.js +2 -279
- package/dist/docx/modelValidation.js +1 -1
- package/dist/docx/paragraphParser.js +2 -2
- package/dist/docx/paragraphPropertySource.d.ts +1 -1
- package/dist/docx/reviewResolutionProvenance.d.ts +3 -2
- package/dist/docx/reviewResolutionProvenance.js +32 -9
- package/dist/docx/revisionIdNormalization.js +30 -7
- package/dist/docx/rezip.js +1 -1
- package/dist/docx/serializer/borderSerializer.js +1 -1
- package/dist/docx/serializer/commentSerializer.js +1 -1
- package/dist/docx/serializer/documentSerializer.js +1 -1
- package/dist/docx/serializer/paragraphSerializer.js +3 -3
- package/dist/docx/serializer/runSerializer.js +1 -1
- package/dist/docx/serializer/sectionPropertiesSerializer.js +1 -1
- package/dist/docx/serializer/tableSerializer.js +5 -37
- package/dist/docx/serializer/textFormattingSerializer.js +1 -1
- package/dist/docx/serializer/trackedChangeAttributes.js +1 -1
- package/dist/docx/server/templatePlan/apply.d.ts +15 -0
- package/dist/docx/server/templatePlan/apply.js +600 -0
- package/dist/docx/server/templatePlan/blocks.d.ts +97 -0
- package/dist/docx/server/templatePlan/blocks.js +355 -0
- package/dist/docx/server/templatePlan/builders.d.ts +72 -0
- package/dist/docx/server/templatePlan/builders.js +237 -0
- package/dist/docx/server/templatePlan/emit.d.ts +118 -0
- package/dist/docx/server/templatePlan/emit.js +466 -0
- package/dist/docx/server/templatePlan/emphasis.d.ts +62 -0
- package/dist/docx/server/templatePlan/emphasis.js +173 -0
- package/dist/docx/server/templatePlan/inspect.d.ts +22 -0
- package/dist/docx/server/templatePlan/inspect.js +177 -0
- package/dist/docx/server/templatePlan/labels.d.ts +36 -0
- package/dist/docx/server/templatePlan/labels.js +126 -0
- package/dist/docx/server/templatePlan/package.d.ts +34 -0
- package/dist/docx/server/templatePlan/package.js +99 -0
- package/dist/docx/server/templatePlan/plan.d.ts +143 -0
- package/dist/docx/server/templatePlan/plan.js +841 -0
- package/dist/docx/server/templatePlan/planShape.d.ts +9 -0
- package/dist/docx/server/templatePlan/planShape.js +161 -0
- package/dist/docx/server/templatePlan/resources.d.ts +41 -0
- package/dist/docx/server/templatePlan/resources.js +136 -0
- package/dist/docx/server/templatePlan/story.d.ts +128 -0
- package/dist/docx/server/templatePlan/story.js +440 -0
- package/dist/docx/server/templatePlan/types.d.ts +406 -0
- package/dist/docx/server/templatePlan/types.js +28 -0
- package/dist/docx/server/templatePlan/verify.d.ts +40 -0
- package/dist/docx/server/templatePlan/verify.js +968 -0
- package/dist/docx/server/templatePlan/xml.d.ts +69 -0
- package/dist/docx/server/templatePlan/xml.js +119 -0
- package/dist/docx/settingsHeaderFooterUpdate.d.ts +9 -0
- package/dist/docx/settingsHeaderFooterUpdate.js +45 -10
- package/dist/docx/storyBlockReplay.js +1 -1
- package/dist/docx/structuralXmlPatch.js +9 -1
- package/dist/docx/tableGridXml.d.ts +30 -0
- package/dist/docx/tableGridXml.js +54 -0
- package/dist/docx/tableParser.js +7 -0
- package/dist/docx/xmlParser.js +1 -1
- package/dist/index.d.ts +3 -4
- package/dist/index.js +2 -4
- package/dist/internal/paragraphFormattingSerialization.js +1 -1
- package/dist/internal/wholeStoryRevisionResolution.js +1 -1
- package/dist/managers/ContextMenuManager.js +2 -1
- package/dist/managers/DocumentLoaderManager.d.ts +0 -4
- package/dist/managers/DocumentLoaderManager.js +4 -12
- package/dist/managers/editorShortcuts.d.ts +1 -1
- package/dist/prosemirror/anchoredTextBoxes.d.ts +1 -1
- package/dist/prosemirror/canonicalCommands.d.ts +1 -1
- package/dist/prosemirror/canonicalSelectionRange.d.ts +1 -1
- package/dist/prosemirror/canonicalTableCommands.js +2 -2
- package/dist/prosemirror/commands/comments.js +3 -3
- package/dist/prosemirror/commands/contentControls.d.ts +1 -1
- package/dist/prosemirror/commands/formatPainter.d.ts +1 -1
- package/dist/prosemirror/commands/formatting.d.ts +1 -1
- package/dist/prosemirror/commands/pastePlainText.d.ts +1 -1
- package/dist/prosemirror/commands/sectionBreak.js +1 -1
- package/dist/prosemirror/commands/tableCellMergeResolution.d.ts +1 -1
- package/dist/prosemirror/commands/tableMergeFoldDecisions.d.ts +1 -1
- package/dist/prosemirror/commentRecords.d.ts +1 -1
- package/dist/prosemirror/contentControlRevisions.d.ts +1 -1
- package/dist/prosemirror/conversion/fromProseDoc.js +1 -1
- package/dist/prosemirror/documentStructureCounts.d.ts +24 -0
- package/dist/prosemirror/documentStructureCounts.js +76 -0
- package/dist/prosemirror/extensions/ExtensionManager.d.ts +1 -1
- package/dist/prosemirror/extensions/StarterKit.d.ts +1 -1
- package/dist/prosemirror/extensions/core/HistoryExtension.d.ts +1 -7
- package/dist/prosemirror/extensions/core/HistoryExtension.js +5 -13
- package/dist/prosemirror/extensions/core/ParagraphExtension.js +1 -1
- package/dist/prosemirror/extensions/core/historyCommands.d.ts +16 -0
- package/dist/prosemirror/extensions/core/historyCommands.js +19 -0
- package/dist/prosemirror/extensions/features/AutoBidiDetectionExtension.js +1 -1
- package/dist/prosemirror/extensions/features/ParaIdAllocatorExtension.d.ts +2 -35
- package/dist/prosemirror/extensions/features/ParaIdAllocatorExtension.js +4 -142
- package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.d.ts +3 -87
- package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.js +7 -162
- package/dist/prosemirror/extensions/features/pastedCellSections.d.ts +1 -1
- package/dist/prosemirror/extensions/features/pastedHeadingStyles.js +1 -1
- package/dist/prosemirror/extensions/marks/markUtils.d.ts +1 -1
- package/dist/prosemirror/extensions/nodes/TableExtension.d.ts +1 -1
- package/dist/prosemirror/extensions/nodes/TableExtension.js +2 -2
- package/dist/prosemirror/extensions/types.d.ts +1 -1
- package/dist/prosemirror/findReplaceSelection.d.ts +1 -1
- package/dist/prosemirror/hyperlinkRemoval.d.ts +1 -1
- package/dist/prosemirror/index.d.ts +1 -1
- package/dist/prosemirror/index.js +1 -1
- package/dist/prosemirror/insertionGaps.d.ts +1 -1
- package/dist/prosemirror/keptRangeBoundaries.d.ts +1 -1
- package/dist/prosemirror/listNumbering.d.ts +1 -1
- package/dist/prosemirror/lockedControls.d.ts +1 -1
- package/dist/prosemirror/markupViewProjection.d.ts +1 -1
- package/dist/prosemirror/noteReferenceOccurrences.d.ts +1 -1
- package/dist/prosemirror/noteReferenceReview.js +1 -1
- package/dist/prosemirror/numberingAttr.d.ts +1 -2
- package/dist/prosemirror/numberingAttr.js +1 -2
- package/dist/prosemirror/outlineLevelAttr.d.ts +1 -2
- package/dist/prosemirror/outlineLevelAttr.js +1 -2
- package/dist/prosemirror/paraIds.d.ts +46 -0
- package/dist/prosemirror/paraIds.js +152 -0
- package/dist/prosemirror/paragraphChangeTrackerMeta.d.ts +97 -0
- package/dist/prosemirror/paragraphChangeTrackerMeta.js +87 -0
- package/dist/prosemirror/paragraphMarkJoin.d.ts +1 -1
- package/dist/prosemirror/paragraphPropertyCarry.d.ts +1 -1
- package/dist/prosemirror/pastedCommentCopies.d.ts +1 -1
- package/dist/prosemirror/pastedCommentCopies.js +1 -1
- package/dist/prosemirror/plugins/createDocScanPlugin.d.ts +1 -1
- package/dist/prosemirror/plugins/documentNumbering.d.ts +1 -1
- package/dist/prosemirror/plugins/suggestionMode.d.ts +1 -1
- package/dist/prosemirror/plugins/templateDirectives.d.ts +1 -1
- package/dist/prosemirror/rebaseParagraphRunFormatting.d.ts +1 -1
- package/dist/prosemirror/rebaseParagraphRuns.d.ts +1 -1
- package/dist/prosemirror/rejoinRunCarriers.d.ts +1 -1
- package/dist/prosemirror/replacedAnnotations.d.ts +1 -1
- package/dist/prosemirror/replacedAnnotations.js +16 -1
- package/dist/prosemirror/revisionCarriers.d.ts +1 -1
- package/dist/prosemirror/runFormattingInlineCarriers.d.ts +1 -1
- package/dist/prosemirror/sectionMarkEdits.d.ts +1 -1
- package/dist/prosemirror/selectionBounds.d.ts +10 -0
- package/dist/prosemirror/selectionBounds.js +22 -0
- package/dist/prosemirror/storyListNumbering.d.ts +1 -1
- package/dist/prosemirror/tableCellPaste.d.ts +1 -1
- package/dist/prosemirror/tableGridMutation.d.ts +1 -1
- package/dist/prosemirror/textInput.d.ts +1 -1
- package/dist/server.d.ts +7 -5
- package/dist/server.js +6 -4
- package/dist/types/canonicalCapabilities.d.ts +8 -41
- package/dist/types/canonicalCapabilities.js +6 -34
- package/package.json +4 -6
- package/dist/controller/collaborationModules.d.ts +0 -3
- package/dist/controller/collaborationModules.js +0 -14
- package/dist/docx/server/materializeYjsDocx.d.ts +0 -30
- package/dist/docx/server/materializeYjsDocx.js +0 -96
- package/dist/docx/server/migrateYjsAttrSchema.d.ts +0 -53
- package/dist/docx/server/migrateYjsAttrSchema.js +0 -111
- package/dist/prosemirror/plugins/derivedFields.d.ts +0 -8
- package/dist/prosemirror/plugins/derivedFields.js +0 -52
- package/dist/prosemirror/yjsDocumentMetadata.d.ts +0 -89
- package/dist/prosemirror/yjsDocumentMetadata.js +0 -697
|
@@ -4,7 +4,6 @@ import { CanonicalPublicOperations } from "../canonical/canonicalPublicOperation
|
|
|
4
4
|
import { restoreCanonicalSelection } from "../canonical/canonicalSelection.js";
|
|
5
5
|
import { CanonicalSessionError, createCanonicalSession, publishCanonicalProjection } from "../canonical/canonicalSession.js";
|
|
6
6
|
import { derivedFieldOps, fieldInsertionParagraph } from "../canonical/derivedFields.js";
|
|
7
|
-
import { parseFieldType } from "../docx/fieldParser.js";
|
|
8
7
|
import { parseDocx } from "../docx/parser.js";
|
|
9
8
|
import { editingFontContextOf, editingFontFamily } from "../layout-bridge/convert/editingFont.js";
|
|
10
9
|
import { recordHiddenEditorPhase, recordHiddenEditorStateCreate } from "../layout-engine/layoutInstrumentation.js";
|
|
@@ -18,37 +17,44 @@ import { createCommentRecordsPlugin, isCommentRecordsSync } from "../prosemirror
|
|
|
18
17
|
import { createEmptyDoc, toProseDoc } from "../prosemirror/conversion/toProseDoc.js";
|
|
19
18
|
import { registerEditorCommandOwner } from "../prosemirror/executeEditorCommand.js";
|
|
20
19
|
import { ensureBaseDirectionInState } from "../prosemirror/extensions/features/AutoBidiDetectionExtension.js";
|
|
21
|
-
import { ensureParaIdsInDoc, ensureParaIdsInState } from "../prosemirror/extensions/features/ParaIdAllocatorExtension.js";
|
|
22
20
|
import { toggleMarkForAllScripts, toggleUnderlineMark } from "../prosemirror/extensions/marks/markUtils.js";
|
|
23
21
|
import { HyperlinkRemovalRefusal } from "../prosemirror/hyperlinkRemoval.js";
|
|
24
22
|
import { REVISION_MARK_NAMES } from "../prosemirror/keptRangeBoundaries.js";
|
|
25
23
|
import { adoptNativeSelection, createNativeNavigationPlugin, createNativeSelectionRefreshPlugin, isCompositionKeyDown } from "../prosemirror/nativeSelection.js";
|
|
26
|
-
import {
|
|
24
|
+
import { noteReferenceTransactionIssue } from "../prosemirror/noteReferenceOccurrences.js";
|
|
25
|
+
import { ensureParaIdsInDoc } from "../prosemirror/paraIds.js";
|
|
27
26
|
import { createDocumentNumberingPlugin } from "../prosemirror/plugins/documentNumbering.js";
|
|
28
27
|
import { createDocumentStyleContextPlugin, createDocumentStylesPlugin } from "../prosemirror/plugins/documentStyles.js";
|
|
29
28
|
import { schema } from "../prosemirror/schema/index.js";
|
|
30
|
-
import {
|
|
31
|
-
import { applyAttrSchemaMigrations, proseDocumentParagraphSourceContract, readYjsAttrSchemaVersion, readYjsParagraphSourceContract, withParagraphSourceContract, writeYjsDocumentMetadata } from "../prosemirror/yjsDocumentMetadata.js";
|
|
32
|
-
import { CANONICAL_GAP, CANONICAL_RULE, usesCanonicalSession } from "../types/canonicalCapabilities.js";
|
|
29
|
+
import { CANONICAL_GAP, CANONICAL_RULE } from "../types/canonicalCapabilities.js";
|
|
33
30
|
import { readModel } from "../types/documentModel.js";
|
|
31
|
+
import { INTERNAL_CLIPBOARD_TYPE } from "../utils/clipboard.js";
|
|
34
32
|
import { NO_ANONYMIZATION_TERMS, createAnonymizationHighlights } from "./anonymizationHighlights.js";
|
|
35
|
-
import { canTriggerAutocomplete, classifyAutocompleteEdit, createAutocompleteSuggestion,
|
|
33
|
+
import { canTriggerAutocomplete, classifyAutocompleteEdit, createAutocompleteSuggestion, nextAutocompleteWord } from "./autocompleteSuggestion.js";
|
|
36
34
|
import { prepareCanonicalPaste } from "./canonicalClipboard.js";
|
|
37
35
|
import { createCanonicalInputBoundary, unclassifiedMutationMessage } from "./canonicalInput.js";
|
|
38
|
-
import { openCanonicalRoomEditor
|
|
36
|
+
import { openCanonicalRoomEditor } from "./canonicalRoomEditor.js";
|
|
39
37
|
import { isCanonicalListParagraph, prepareCanonicalAutoformat, prepareCanonicalCommands } from "./canonicalStructure.js";
|
|
40
38
|
import { createHiddenEditorApi } from "./hiddenEditorApi.js";
|
|
41
|
-
import { legacyTextAddressAt } from "./legacyTextAddress.js";
|
|
42
39
|
import { handleReadOnlySelectionKeyDown } from "./readOnlySelection.js";
|
|
43
|
-
import {
|
|
44
|
-
import { Result, TaggedError, panic } from "better-result";
|
|
40
|
+
import { Result, TaggedError } from "better-result";
|
|
45
41
|
import { DOMParser, DOMSerializer } from "prosemirror-model";
|
|
46
42
|
import { CellSelection } from "prosemirror-tables";
|
|
47
43
|
import { OP_STORIES, documentStories, freshCommentId, sameStory } from "@stll/docx-core/ops";
|
|
48
|
-
import { EditorState, Plugin,
|
|
49
|
-
import { closeHistory } from "prosemirror-history";
|
|
44
|
+
import { EditorState, Plugin, Selection } from "prosemirror-state";
|
|
50
45
|
import { EditorView } from "prosemirror-view";
|
|
51
46
|
// src/controller/hiddenEditorManager.ts
|
|
47
|
+
/**
|
|
48
|
+
* Hidden-editor view lifecycle manager
|
|
49
|
+
*
|
|
50
|
+
* Framework-agnostic owner of the off-screen ProseMirror EditorView. Holds the
|
|
51
|
+
* view plus the bookkeeping that decides when an incoming document is a truly
|
|
52
|
+
* external change (vs. an internal edit echoed back through props), builds the
|
|
53
|
+
* editor state and `editorProps`, and composes the slice-2a imperative API so
|
|
54
|
+
* the API and the lifecycle share one view owner. The React adapter
|
|
55
|
+
* (`HiddenProseMirror`) keeps the input refs and its effects (which decide
|
|
56
|
+
* *when* to act) and drives this manager through the methods below.
|
|
57
|
+
*/
|
|
52
58
|
const CanonicalSessionRefusalErrorBase = TaggedError("CanonicalSessionRefusalError");
|
|
53
59
|
/** A refused input, with whether the session lacks the capability or the document forbids it. */
|
|
54
60
|
var CanonicalSessionRefusalError = class extends CanonicalSessionRefusalErrorBase {};
|
|
@@ -73,59 +79,7 @@ const parseCanonicalClipboardText = (text, $context, _plain, view) => {
|
|
|
73
79
|
context: $context
|
|
74
80
|
});
|
|
75
81
|
};
|
|
76
|
-
const normalizeSeedState = (state) => ensureBaseDirectionInState(ensureParaIdsInState(state));
|
|
77
82
|
const normalizeLocalSeedState = (state) => ensureBaseDirectionInState(state);
|
|
78
|
-
const isObjectRecord = (value) => typeof value === "object" && value !== null;
|
|
79
|
-
const isYSyncState = (value, yjs) => {
|
|
80
|
-
if (!isObjectRecord(value)) return false;
|
|
81
|
-
const binding = value["binding"];
|
|
82
|
-
return value["doc"] instanceof yjs.Doc && value["type"] instanceof yjs.XmlFragment && isObjectRecord(binding) && binding["mapping"] instanceof Map;
|
|
83
|
-
};
|
|
84
|
-
const readAwarenessCursor = (state) => {
|
|
85
|
-
if (!isObjectRecord(state)) return null;
|
|
86
|
-
const cursor = state["cursor"];
|
|
87
|
-
if (!isObjectRecord(cursor)) return null;
|
|
88
|
-
const anchor = cursor["anchor"];
|
|
89
|
-
const head = cursor["head"];
|
|
90
|
-
if (!isObjectRecord(anchor) || !isObjectRecord(head)) return null;
|
|
91
|
-
return {
|
|
92
|
-
anchor,
|
|
93
|
-
head
|
|
94
|
-
};
|
|
95
|
-
};
|
|
96
|
-
const readAwarenessUser = (state, clientId) => {
|
|
97
|
-
if (!isObjectRecord(state) || !isObjectRecord(state["user"])) return {
|
|
98
|
-
color: "var(--doc-image-selection)",
|
|
99
|
-
name: `User ${clientId}`
|
|
100
|
-
};
|
|
101
|
-
const user = state["user"];
|
|
102
|
-
return {
|
|
103
|
-
color: remoteSelectionColor(user["color"]),
|
|
104
|
-
name: typeof user["name"] === "string" ? user["name"] : `User ${clientId}`
|
|
105
|
-
};
|
|
106
|
-
};
|
|
107
|
-
const collectRemoteSelections = (state, awareness, collaborationModules) => {
|
|
108
|
-
const syncState = collaborationModules.yProseMirror.ySyncPluginKey.getState(state);
|
|
109
|
-
if (!isYSyncState(syncState, collaborationModules.yjs)) return [];
|
|
110
|
-
const selections = [];
|
|
111
|
-
for (const [clientId, remoteState] of awareness.getStates()) {
|
|
112
|
-
if (clientId === awareness.clientID) continue;
|
|
113
|
-
const cursor = readAwarenessCursor(remoteState);
|
|
114
|
-
if (cursor === null) continue;
|
|
115
|
-
const anchor = collaborationModules.yProseMirror.relativePositionToAbsolutePosition(syncState.doc, syncState.type, collaborationModules.yjs.createRelativePositionFromJSON(cursor.anchor), syncState.binding.mapping);
|
|
116
|
-
const head = collaborationModules.yProseMirror.relativePositionToAbsolutePosition(syncState.doc, syncState.type, collaborationModules.yjs.createRelativePositionFromJSON(cursor.head), syncState.binding.mapping);
|
|
117
|
-
if (anchor === null || head === null) continue;
|
|
118
|
-
const user = readAwarenessUser(remoteState, clientId);
|
|
119
|
-
selections.push({
|
|
120
|
-
anchor,
|
|
121
|
-
peer: String(clientId),
|
|
122
|
-
color: user.color,
|
|
123
|
-
head,
|
|
124
|
-
name: user.name
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
return selections;
|
|
128
|
-
};
|
|
129
83
|
const HIDDEN_EDITOR_ATTRIBUTES = {
|
|
130
84
|
"aria-label": "Document content",
|
|
131
85
|
"aria-multiline": "true",
|
|
@@ -137,7 +91,7 @@ const HIDDEN_EDITOR_ATTRIBUTES = {
|
|
|
137
91
|
translate: "no"
|
|
138
92
|
};
|
|
139
93
|
function createHiddenEditorState(options) {
|
|
140
|
-
const { document: model, styles, manager, externalPlugins = [],
|
|
94
|
+
const { document: model, styles, manager, externalPlugins = [], reason = "mount" } = options;
|
|
141
95
|
recordHiddenEditorStateCreate(reason);
|
|
142
96
|
const document = model && readModel(model);
|
|
143
97
|
const activeSchema = manager?.getSchema() ?? schema;
|
|
@@ -153,52 +107,8 @@ function createHiddenEditorState(options) {
|
|
|
153
107
|
createDocumentNumberingPlugin(document?.package.numbering),
|
|
154
108
|
createCommentRecordsPlugin(document?.package.document.comments ?? []),
|
|
155
109
|
...externalPlugins,
|
|
156
|
-
...manager?.getPlugins() ?? [createTextInputPlugin()],
|
|
157
110
|
styleResolverPlugin
|
|
158
111
|
];
|
|
159
|
-
if (collaboration) {
|
|
160
|
-
if (!collaborationModules) panic("Collaboration modules must be loaded before creating collaborative editor state.");
|
|
161
|
-
if (collaboration.shouldSeed && collaboration.yXmlFragment.length === 0) {
|
|
162
|
-
const seedState = normalizeLocalSeedState(EditorState.create({
|
|
163
|
-
doc: localDoc,
|
|
164
|
-
schema: activeSchema,
|
|
165
|
-
plugins
|
|
166
|
-
}));
|
|
167
|
-
collaborationModules.yProseMirror.prosemirrorToYXmlFragment(seedState.doc, collaboration.yXmlFragment);
|
|
168
|
-
const collaborationDocument = collaboration.yXmlFragment.doc;
|
|
169
|
-
if (!collaborationDocument) panic("A collaboration fragment must belong to a Yjs document before seeding.");
|
|
170
|
-
writeYjsDocumentMetadata(collaborationDocument, seedState.doc);
|
|
171
|
-
collaboration.onSeeded?.();
|
|
172
|
-
}
|
|
173
|
-
const collaborationDocument = collaboration.yXmlFragment.doc;
|
|
174
|
-
if (!collaborationDocument) panic("A collaboration fragment must belong to a Yjs document before loading.");
|
|
175
|
-
const attrSchemaVersion = readYjsAttrSchemaVersion(collaborationDocument);
|
|
176
|
-
if (attrSchemaVersion.isErr()) throw attrSchemaVersion.error;
|
|
177
|
-
applyAttrSchemaMigrations(collaborationDocument, collaboration.yXmlFragment, attrSchemaVersion.value);
|
|
178
|
-
let { doc } = collaborationModules.yProseMirror.initProseMirrorDoc(collaboration.yXmlFragment, activeSchema);
|
|
179
|
-
const collaborationContract = readYjsParagraphSourceContract(collaborationDocument);
|
|
180
|
-
const localContract = proseDocumentParagraphSourceContract(localDoc);
|
|
181
|
-
if (localContract && collaborationContract !== localContract) panic("The collaboration state belongs to a different paragraph-property source.");
|
|
182
|
-
if (collaborationContract) doc = withParagraphSourceContract(doc, collaborationContract);
|
|
183
|
-
const initializedState = normalizeSeedState(EditorState.create({
|
|
184
|
-
doc,
|
|
185
|
-
schema: activeSchema,
|
|
186
|
-
plugins
|
|
187
|
-
}));
|
|
188
|
-
if (!initializedState.doc.eq(doc)) {
|
|
189
|
-
collaborationModules.yProseMirror.prosemirrorToYXmlFragment(initializedState.doc, collaboration.yXmlFragment);
|
|
190
|
-
({doc} = collaborationModules.yProseMirror.initProseMirrorDoc(collaboration.yXmlFragment, activeSchema));
|
|
191
|
-
if (collaborationContract) doc = withParagraphSourceContract(doc, collaborationContract);
|
|
192
|
-
}
|
|
193
|
-
const startedAt = performance.now();
|
|
194
|
-
const state = normalizeSeedState(EditorState.create({
|
|
195
|
-
doc,
|
|
196
|
-
schema: activeSchema,
|
|
197
|
-
plugins
|
|
198
|
-
}));
|
|
199
|
-
recordHiddenEditorPhase(reason, "editor-state", performance.now() - startedAt);
|
|
200
|
-
return state;
|
|
201
|
-
}
|
|
202
112
|
const startedAt = performance.now();
|
|
203
113
|
const state = normalizeLocalSeedState(EditorState.create({
|
|
204
114
|
doc: localDoc,
|
|
@@ -265,7 +175,7 @@ const createHiddenEditorManager = (hostDeps) => {
|
|
|
265
175
|
} };
|
|
266
176
|
};
|
|
267
177
|
let releaseCommandOwner;
|
|
268
|
-
let editorSession = { type: "
|
|
178
|
+
let editorSession = { type: "unopened" };
|
|
269
179
|
let canonicalSessionEpoch = 0;
|
|
270
180
|
let modeOverride = null;
|
|
271
181
|
const syncCanonicalMode = () => {
|
|
@@ -297,12 +207,6 @@ const createHiddenEditorManager = (hostDeps) => {
|
|
|
297
207
|
offAutocompleteEdits = () => {};
|
|
298
208
|
leaveRoom();
|
|
299
209
|
const canonicalRoom = deps.getCanonicalRoom?.();
|
|
300
|
-
if (!usesCanonicalSession(deps.getExperimentalSession?.(), CANONICAL_GAP.authorityRouting)) {
|
|
301
|
-
if (canonicalRoom !== void 0) panic("A canonical room is joined by the canonical session; select it with experimentalSession.");
|
|
302
|
-
editorSession = { type: "prosemirror" };
|
|
303
|
-
return true;
|
|
304
|
-
}
|
|
305
|
-
if (deps.getCollaboration() !== void 0) panic("A canonical session collaborates in a canonical room (collaboration.connect); a Yjs fragment binds the legacy session.");
|
|
306
210
|
const documentIdentity = deps.getDocumentIdentity();
|
|
307
211
|
if (editorSession.type === "refused" && editorSession.documentIdentity === documentIdentity) return false;
|
|
308
212
|
if (!document) {
|
|
@@ -429,62 +333,43 @@ const createHiddenEditorManager = (hostDeps) => {
|
|
|
429
333
|
}
|
|
430
334
|
publishCanonical(prepared.value, refuse);
|
|
431
335
|
};
|
|
432
|
-
/** Insert a field in place of the selection
|
|
336
|
+
/** Insert a field in place of the selection. */
|
|
433
337
|
const insertField = (field) => {
|
|
434
|
-
if (!view || isDestroying || deps.getReadOnly()) return false;
|
|
338
|
+
if (!view || isDestroying || deps.getReadOnly() || editorSession.type !== "canonical") return false;
|
|
435
339
|
const { state } = view;
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
refuse(prepared.error.message, prepared.error.ground);
|
|
468
|
-
return false;
|
|
469
|
-
}
|
|
470
|
-
return publishCommit(prepared.value);
|
|
471
|
-
}
|
|
472
|
-
case "prosemirror": {
|
|
473
|
-
const fieldType = state.schema.nodes["field"];
|
|
474
|
-
if (fieldType === void 0) return false;
|
|
475
|
-
const insertion = state.tr.replaceSelectionWith(fieldType.create({
|
|
476
|
-
fieldType: parseFieldType(field.instruction),
|
|
477
|
-
instruction: field.instruction,
|
|
478
|
-
displayText: field.displayText,
|
|
479
|
-
fieldKind: "simple",
|
|
480
|
-
...field.locked === void 0 ? {} : { fldLock: field.locked }
|
|
481
|
-
}), false).scrollIntoView();
|
|
482
|
-
view.dispatch(closeHistory(insertion));
|
|
483
|
-
return true;
|
|
484
|
-
}
|
|
485
|
-
case "refused": return false;
|
|
486
|
-
default: return panic("Unhandled editor session");
|
|
340
|
+
const { session } = editorSession;
|
|
341
|
+
if (state.selection instanceof CellSelection) {
|
|
342
|
+
refuse("A field goes in at a text selection, not over cells.");
|
|
343
|
+
return false;
|
|
344
|
+
}
|
|
345
|
+
const range = canonicalSelectionRange(state);
|
|
346
|
+
const from = session.projection.addressAt(range.from);
|
|
347
|
+
if (from.isErr()) {
|
|
348
|
+
refuse(from.error.message, from.error.ground);
|
|
349
|
+
return false;
|
|
350
|
+
}
|
|
351
|
+
const to = session.projection.addressAt(range.to);
|
|
352
|
+
if (to.isErr()) {
|
|
353
|
+
refuse(to.error.message, to.error.ground);
|
|
354
|
+
return false;
|
|
355
|
+
}
|
|
356
|
+
syncCanonicalMode();
|
|
357
|
+
const prepared = session.prepareIntents(state, {
|
|
358
|
+
intents: [{
|
|
359
|
+
type: "replaceFragment",
|
|
360
|
+
from: from.value,
|
|
361
|
+
to: to.value,
|
|
362
|
+
paragraphs: [fieldInsertionParagraph(field)],
|
|
363
|
+
openStart: 1,
|
|
364
|
+
openEnd: 1
|
|
365
|
+
}],
|
|
366
|
+
semantic: "paste"
|
|
367
|
+
});
|
|
368
|
+
if (prepared.isErr()) {
|
|
369
|
+
refuse(prepared.error.message, prepared.error.ground);
|
|
370
|
+
return false;
|
|
487
371
|
}
|
|
372
|
+
return publishCommit(prepared.value);
|
|
488
373
|
};
|
|
489
374
|
/**
|
|
490
375
|
* Show a peer's edit the room sequenced: the same publication as a local
|
|
@@ -514,13 +399,8 @@ const createHiddenEditorManager = (hostDeps) => {
|
|
|
514
399
|
return Result.ok(void 0);
|
|
515
400
|
};
|
|
516
401
|
const autocompletePositionAt = (position) => {
|
|
517
|
-
if (!view || isDestroying) return null;
|
|
518
|
-
|
|
519
|
-
case "canonical": return editorSession.session.projection.positionAt(position).unwrapOr(null);
|
|
520
|
-
case "prosemirror": return legacyEditorPositionAt(view.state.doc, position);
|
|
521
|
-
case "refused": return null;
|
|
522
|
-
default: return editorSession;
|
|
523
|
-
}
|
|
402
|
+
if (!view || isDestroying || editorSession.type !== "canonical") return null;
|
|
403
|
+
return editorSession.session.projection.positionAt(position).unwrapOr(null);
|
|
524
404
|
};
|
|
525
405
|
/** Where the suggestion's anchor shows in the body's editor document. */
|
|
526
406
|
const autocompleteEditorAnchor = () => {
|
|
@@ -529,10 +409,9 @@ const createHiddenEditorManager = (hostDeps) => {
|
|
|
529
409
|
};
|
|
530
410
|
/** The caret as a body text position. */
|
|
531
411
|
const caretTextPosition = () => {
|
|
532
|
-
if (!view) return null;
|
|
412
|
+
if (!view || editorSession.type !== "canonical") return null;
|
|
533
413
|
const { head } = view.state.selection;
|
|
534
|
-
|
|
535
|
-
return legacyTextAddressAt(view.state.doc, head);
|
|
414
|
+
return editorSession.session.projection.addressAt(head).unwrapOr(null);
|
|
536
415
|
};
|
|
537
416
|
/**
|
|
538
417
|
* Insert the suggestion, or its next word, at its anchor as the person's
|
|
@@ -542,44 +421,35 @@ const createHiddenEditorManager = (hostDeps) => {
|
|
|
542
421
|
const acceptAutocomplete = (scope) => {
|
|
543
422
|
const current = autocomplete.get();
|
|
544
423
|
if (current.status === "idle" || current.text.length === 0) return false;
|
|
545
|
-
if (!view || deps.getReadOnly() || isDestroying) return false;
|
|
424
|
+
if (!view || deps.getReadOnly() || isDestroying || editorSession.type !== "canonical") return false;
|
|
546
425
|
const at = autocompleteEditorAnchor();
|
|
547
426
|
if (at === null) return false;
|
|
548
427
|
const text = scope === "word" ? nextAutocompleteWord(current.text) : current.text;
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
if (prepared.
|
|
560
|
-
|
|
561
|
-
return false;
|
|
562
|
-
}
|
|
563
|
-
const published = publishCommit(prepared.value);
|
|
564
|
-
session.breakUndoGroup();
|
|
565
|
-
return published;
|
|
428
|
+
syncCanonicalMode();
|
|
429
|
+
const session = editorSession.session;
|
|
430
|
+
session.breakUndoGroup();
|
|
431
|
+
const prepared = session.prepareReplace(view.state, {
|
|
432
|
+
from: at,
|
|
433
|
+
to: at,
|
|
434
|
+
text,
|
|
435
|
+
semantic: "typing"
|
|
436
|
+
});
|
|
437
|
+
if (prepared.isErr()) {
|
|
438
|
+
if (prepared.error.reason !== "noChange") refuse(prepared.error.message, prepared.error.ground);
|
|
439
|
+
return false;
|
|
566
440
|
}
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
view.dispatch(transaction.setSelection(TextSelection.create(transaction.doc, at + text.length)));
|
|
571
|
-
if (!view || view.state.doc.eq(previous)) return false;
|
|
572
|
-
view.dispatch(closeHistory(view.state.tr));
|
|
573
|
-
return true;
|
|
441
|
+
const published = publishCommit(prepared.value);
|
|
442
|
+
session.breakUndoGroup();
|
|
443
|
+
return published;
|
|
574
444
|
};
|
|
575
445
|
let autocompleteRequests = 0;
|
|
576
446
|
const autocompleteApi = {
|
|
577
447
|
start: (options) => {
|
|
578
448
|
const anchor = options?.at ?? caretTextPosition();
|
|
579
|
-
if (anchor === null || !view) return null;
|
|
449
|
+
if (anchor === null || !view || editorSession.type !== "canonical") return null;
|
|
580
450
|
const position = autocompletePositionAt(anchor);
|
|
581
451
|
if (position === null) return null;
|
|
582
|
-
const resolved = editorSession.
|
|
452
|
+
const resolved = editorSession.session.projection.addressAt(position).unwrapOr(null);
|
|
583
453
|
if (resolved === null) return null;
|
|
584
454
|
autocompleteRequests += 1;
|
|
585
455
|
const requestId = options?.requestId ?? `autocomplete-${String(autocompleteRequests)}`;
|
|
@@ -661,6 +531,29 @@ const createHiddenEditorManager = (hostDeps) => {
|
|
|
661
531
|
return publishCommit(prepared.value);
|
|
662
532
|
};
|
|
663
533
|
let clipboardDrag = { type: "idle" };
|
|
534
|
+
let clipboardCopy = { type: "none" };
|
|
535
|
+
/**
|
|
536
|
+
* Write the selection to the clipboard once, under a token minted for this
|
|
537
|
+
* copy alone, and return what was written.
|
|
538
|
+
*/
|
|
539
|
+
const writeClipboard = (pmView, data) => {
|
|
540
|
+
const serialized = pmView.serializeForClipboard(pmView.state.selection.content());
|
|
541
|
+
const html = serialized.dom.innerHTML;
|
|
542
|
+
const token = crypto.randomUUID();
|
|
543
|
+
data.setData("text/html", html);
|
|
544
|
+
data.setData("text/plain", serialized.text);
|
|
545
|
+
data.setData(INTERNAL_CLIPBOARD_TYPE, token);
|
|
546
|
+
return {
|
|
547
|
+
html,
|
|
548
|
+
token
|
|
549
|
+
};
|
|
550
|
+
};
|
|
551
|
+
/** The copied document, when the pasted clipboard is the editor's own copy. */
|
|
552
|
+
const copiedSource = (event) => {
|
|
553
|
+
const data = event.clipboardData;
|
|
554
|
+
if (clipboardCopy.type !== "copied" || data === null) return {};
|
|
555
|
+
return data.getData("application/x-stella-folio") === clipboardCopy.token && data.getData("text/html").includes(clipboardCopy.html) ? { sourceDocument: clipboardCopy.document } : {};
|
|
556
|
+
};
|
|
664
557
|
let lastInputRule;
|
|
665
558
|
const canonicalStructuralInput = {
|
|
666
559
|
command: (name) => {
|
|
@@ -846,6 +739,7 @@ const createHiddenEditorManager = (hostDeps) => {
|
|
|
846
739
|
return true;
|
|
847
740
|
}
|
|
848
741
|
syncCanonicalMode();
|
|
742
|
+
const source = readModel(editorSession.session.document);
|
|
849
743
|
const session = editorSession.session;
|
|
850
744
|
const { from, to } = pmView.state.selection;
|
|
851
745
|
const prepared = session.prepareReplace(pmView.state, {
|
|
@@ -858,19 +752,24 @@ const createHiddenEditorManager = (hostDeps) => {
|
|
|
858
752
|
refuse(prepared.error.message, prepared.error.ground);
|
|
859
753
|
return true;
|
|
860
754
|
}
|
|
755
|
+
const data = event.clipboardData;
|
|
861
756
|
const copied = Result.try({
|
|
862
|
-
try: () =>
|
|
863
|
-
const serialized = pmView.serializeForClipboard(pmView.state.selection.content());
|
|
864
|
-
event.clipboardData?.setData("text/html", serialized.dom.innerHTML);
|
|
865
|
-
event.clipboardData?.setData("text/plain", serialized.text);
|
|
866
|
-
},
|
|
757
|
+
try: () => writeClipboard(pmView, data),
|
|
867
758
|
catch: () => new CanonicalSessionRefusalError({
|
|
868
759
|
ground: { gap: CANONICAL_GAP.dispatch },
|
|
869
760
|
message: "The clipboard could not receive the cut content."
|
|
870
761
|
})
|
|
871
762
|
});
|
|
872
|
-
if (copied.isErr())
|
|
873
|
-
|
|
763
|
+
if (copied.isErr()) {
|
|
764
|
+
refuse(copied.error.message, copied.error.ground);
|
|
765
|
+
return true;
|
|
766
|
+
}
|
|
767
|
+
clipboardCopy = {
|
|
768
|
+
type: "copied",
|
|
769
|
+
document: source,
|
|
770
|
+
...copied.value
|
|
771
|
+
};
|
|
772
|
+
publishCommit(prepared.value);
|
|
874
773
|
return true;
|
|
875
774
|
},
|
|
876
775
|
...canonicalInputLifecycle,
|
|
@@ -905,36 +804,16 @@ const createHiddenEditorManager = (hostDeps) => {
|
|
|
905
804
|
let requested = false;
|
|
906
805
|
let isInitialized = false;
|
|
907
806
|
let lastDocumentId = null;
|
|
908
|
-
let lastCollaborationFragment = null;
|
|
909
807
|
let lastCanonicalRoom = null;
|
|
910
808
|
const tryCreate = () => {
|
|
911
809
|
if (!requested || view !== null || isDestroying) return;
|
|
912
810
|
const host = deps.getHost();
|
|
913
811
|
if (!host) return;
|
|
914
|
-
const collaboration = deps.getCollaboration();
|
|
915
|
-
const collaborationModules = deps.getCollaborationModules();
|
|
916
|
-
if (collaboration && !collaborationModules && !usesCanonicalSession(deps.getExperimentalSession?.(), CANONICAL_GAP.authorityRouting)) return;
|
|
917
812
|
const document = deps.getDocument();
|
|
918
|
-
const styles = deps.getStyles();
|
|
919
|
-
const extensionManager = deps.getExtensionManager();
|
|
920
|
-
const externalPlugins = deps.getExternalPlugins();
|
|
921
813
|
input.reset();
|
|
922
|
-
if (!seedSession(document)) return;
|
|
814
|
+
if (!seedSession(document) || editorSession.type !== "canonical") return;
|
|
923
815
|
const editorProps = {
|
|
924
|
-
state: (
|
|
925
|
-
if (editorSession.type === "canonical") return canonicalState(editorSession.session);
|
|
926
|
-
const precomputedInitialState = collaboration ? null : deps.getPrecomputedInitialState();
|
|
927
|
-
if (precomputedInitialState) return precomputedInitialState;
|
|
928
|
-
return createHiddenEditorState({
|
|
929
|
-
document: document && readModel(document),
|
|
930
|
-
styles,
|
|
931
|
-
manager: extensionManager,
|
|
932
|
-
externalPlugins,
|
|
933
|
-
collaboration,
|
|
934
|
-
collaborationModules,
|
|
935
|
-
reason: "mount"
|
|
936
|
-
});
|
|
937
|
-
})(),
|
|
816
|
+
state: canonicalState(editorSession.session),
|
|
938
817
|
attributes: HIDDEN_EDITOR_ATTRIBUTES,
|
|
939
818
|
markViews: editingMarkViews(document),
|
|
940
819
|
editable: () => !deps.getReadOnly() && editorSession.type !== "refused",
|
|
@@ -944,32 +823,25 @@ const createHiddenEditorManager = (hostDeps) => {
|
|
|
944
823
|
deps.onReadOnlyEditAttempt();
|
|
945
824
|
return;
|
|
946
825
|
}
|
|
947
|
-
if (editorSession.type
|
|
948
|
-
if (
|
|
826
|
+
if (editorSession.type !== "canonical") return;
|
|
827
|
+
if (transaction.docChanged) {
|
|
949
828
|
if (input.acceptComposition(view, transaction)) return;
|
|
950
829
|
if (!input.commitNativeProposal(view, transaction)) input.refuseNativeMutation(view, transaction);
|
|
951
830
|
view.updateState(view.state);
|
|
952
831
|
return;
|
|
953
832
|
}
|
|
954
|
-
if (
|
|
833
|
+
if (transaction.selectionSet && !input.isComposing) {
|
|
955
834
|
lastInputRule = void 0;
|
|
956
835
|
editorSession.session.breakUndoGroup();
|
|
957
836
|
}
|
|
958
|
-
const modules = deps.getCollaborationModules();
|
|
959
|
-
if (modules && transaction.getMeta(modules.yProseMirror.ySyncPluginKey) !== void 0) markNoteReferenceReplay(transaction);
|
|
960
837
|
const applied = view.state.applyTransaction(transaction);
|
|
961
838
|
const noteIssue = noteReferenceTransactionIssue(transaction);
|
|
962
839
|
if (noteIssue) deps.onSessionRefusal?.(noteIssue.message, { gap: CANONICAL_GAP.dispatch }, noteIssue);
|
|
963
|
-
if (
|
|
840
|
+
if (!applied.state.doc.eq(view.state.doc)) {
|
|
964
841
|
refuse(unclassifiedMutationMessage(applied.transactions, "A plugin attempted an unclassified canonical document mutation."));
|
|
965
842
|
return;
|
|
966
843
|
}
|
|
967
844
|
const documentEdits = applied.transactions.filter((appliedTransaction) => appliedTransaction.docChanged && !isCommentRecordsSync(appliedTransaction));
|
|
968
|
-
let autocompleteEdit;
|
|
969
|
-
if (editorSession.type !== "canonical" && documentEdits.length > 0) {
|
|
970
|
-
const only = documentEdits.at(0);
|
|
971
|
-
autocompleteEdit = documentEdits.length === 1 && only === transaction ? legacyAutocompleteEdit(transaction) : { type: "other" };
|
|
972
|
-
}
|
|
973
845
|
view.updateState(applied.state);
|
|
974
846
|
const docChanged = documentEdits.length > 0;
|
|
975
847
|
const selectionChanged = applied.transactions.some((appliedTransaction) => appliedTransaction.selectionSet || appliedTransaction.docChanged && !isCommentRecordsSync(appliedTransaction));
|
|
@@ -979,10 +851,6 @@ const createHiddenEditorManager = (hostDeps) => {
|
|
|
979
851
|
docChanged
|
|
980
852
|
});
|
|
981
853
|
if (selectionChanged) deps.onSelectionChange(applied.state);
|
|
982
|
-
const currentCollaboration = deps.getCollaboration();
|
|
983
|
-
const currentCollaborationModules = deps.getCollaborationModules();
|
|
984
|
-
if (currentCollaboration?.awareness && currentCollaborationModules) deps.onRemoteSelectionsChange(collectRemoteSelections(applied.state, currentCollaboration.awareness, currentCollaborationModules));
|
|
985
|
-
if (autocompleteEdit !== void 0) autocomplete.noteEdit(view?.state === applied.state ? autocompleteEdit : { type: "other" });
|
|
986
854
|
},
|
|
987
855
|
handleKeyDown: (pmView, event) => {
|
|
988
856
|
if (handleAutocompleteKeyDown(event)) return true;
|
|
@@ -997,7 +865,7 @@ const createHiddenEditorManager = (hostDeps) => {
|
|
|
997
865
|
},
|
|
998
866
|
handleTextInput: (pmView, from, to, text) => editorSession.type === "canonical" ? input.handleTextInput(pmView, from, to, text) : false,
|
|
999
867
|
handleKeyPress: (pmView, event) => editorSession.type === "canonical" && !deps.getReadOnly() && input.handleKeyPress(pmView, event),
|
|
1000
|
-
handlePaste: (pmView,
|
|
868
|
+
handlePaste: (pmView, event, slice) => {
|
|
1001
869
|
if (editorSession.type !== "canonical") return false;
|
|
1002
870
|
if (deps.getReadOnly()) {
|
|
1003
871
|
deps.onReadOnlyEditAttempt();
|
|
@@ -1007,7 +875,8 @@ const createHiddenEditorManager = (hostDeps) => {
|
|
|
1007
875
|
const prepared = prepareCanonicalPaste({
|
|
1008
876
|
session: editorSession.session,
|
|
1009
877
|
state: pmView.state,
|
|
1010
|
-
slice
|
|
878
|
+
slice,
|
|
879
|
+
...copiedSource(event)
|
|
1011
880
|
});
|
|
1012
881
|
if (prepared.isErr()) {
|
|
1013
882
|
if (prepared.error.reason !== "noChange") refuse(prepared.error.message, prepared.error.ground);
|
|
@@ -1066,6 +935,27 @@ const createHiddenEditorManager = (hostDeps) => {
|
|
|
1066
935
|
focus: () => false,
|
|
1067
936
|
blur: (pmView) => editorSession.type === "canonical" ? input.handleDOMEvents.blur(pmView) : false,
|
|
1068
937
|
...createHiddenEditorClipboardHandlers(deps),
|
|
938
|
+
copy: (pmView, event) => {
|
|
939
|
+
const data = event.clipboardData;
|
|
940
|
+
if (editorSession.type !== "canonical" || data === null || pmView.state.selection.empty) {
|
|
941
|
+
clipboardCopy = { type: "none" };
|
|
942
|
+
return createHiddenEditorClipboardHandlers(deps).copy();
|
|
943
|
+
}
|
|
944
|
+
const source = readModel(editorSession.session.document);
|
|
945
|
+
const written = Result.try(() => writeClipboard(pmView, data));
|
|
946
|
+
if (written.isErr()) {
|
|
947
|
+
clipboardCopy = { type: "none" };
|
|
948
|
+
return createHiddenEditorClipboardHandlers(deps).copy();
|
|
949
|
+
}
|
|
950
|
+
event.preventDefault();
|
|
951
|
+
clipboardCopy = {
|
|
952
|
+
type: "copied",
|
|
953
|
+
document: source,
|
|
954
|
+
...written.value
|
|
955
|
+
};
|
|
956
|
+
deps.onCopy?.();
|
|
957
|
+
return true;
|
|
958
|
+
},
|
|
1069
959
|
compositionstart: (pmView) => editorSession.type === "canonical" ? input.handleDOMEvents.compositionstart(pmView) : false,
|
|
1070
960
|
compositionend: (pmView, event) => editorSession.type === "canonical" ? input.handleDOMEvents.compositionend(pmView, event) : false,
|
|
1071
961
|
input: (pmView) => editorSession.type === "canonical" ? input.handleDOMEvents.input(pmView) : false,
|
|
@@ -1133,7 +1023,6 @@ const createHiddenEditorManager = (hostDeps) => {
|
|
|
1133
1023
|
syncHiddenEditorAccessibility(view, deps.getReadOnly());
|
|
1134
1024
|
isInitialized = true;
|
|
1135
1025
|
lastDocumentId = deps.getDocumentIdentity();
|
|
1136
|
-
lastCollaborationFragment = collaboration?.yXmlFragment ?? null;
|
|
1137
1026
|
lastCanonicalRoom = deps.getCanonicalRoom?.() ?? null;
|
|
1138
1027
|
deps.onEditorViewReady(view);
|
|
1139
1028
|
};
|
|
@@ -1163,40 +1052,23 @@ const createHiddenEditorManager = (hostDeps) => {
|
|
|
1163
1052
|
};
|
|
1164
1053
|
const syncExternalDocument = () => {
|
|
1165
1054
|
if (isDestroying) return;
|
|
1166
|
-
const canonicalRequested = usesCanonicalSession(deps.getExperimentalSession?.(), CANONICAL_GAP.authorityRouting);
|
|
1167
1055
|
if (!view) {
|
|
1168
|
-
if (
|
|
1056
|
+
if (deps.getDocument() !== null) ensureView();
|
|
1169
1057
|
return;
|
|
1170
1058
|
}
|
|
1171
|
-
const collaboration = deps.getCollaboration();
|
|
1172
|
-
const collaborationModules = deps.getCollaborationModules();
|
|
1173
|
-
if (collaboration && !collaborationModules && !canonicalRequested) return;
|
|
1174
1059
|
const document = deps.getDocument();
|
|
1175
1060
|
const currentDocId = deps.getDocumentIdentity();
|
|
1176
|
-
const currentCollaborationFragment = collaboration?.yXmlFragment ?? null;
|
|
1177
1061
|
const currentCanonicalRoom = deps.getCanonicalRoom?.() ?? null;
|
|
1178
|
-
|
|
1179
|
-
const sessionChanged = editorSession.type !== "prosemirror" !== canonicalRequested;
|
|
1180
|
-
if (collaboration && !collaborationSourceChanged && !sessionChanged) return;
|
|
1181
|
-
if (isInitialized && currentDocId === lastDocumentId && !collaborationSourceChanged && !sessionChanged) return;
|
|
1062
|
+
if (isInitialized && currentDocId === lastDocumentId && !(currentCanonicalRoom !== lastCanonicalRoom)) return;
|
|
1182
1063
|
input.reset();
|
|
1183
|
-
if (!seedSession(document)) {
|
|
1064
|
+
if (!seedSession(document) || editorSession.type !== "canonical") {
|
|
1184
1065
|
destroyView();
|
|
1185
1066
|
return;
|
|
1186
1067
|
}
|
|
1187
1068
|
isInitialized = true;
|
|
1188
1069
|
lastDocumentId = currentDocId;
|
|
1189
|
-
lastCollaborationFragment = currentCollaborationFragment;
|
|
1190
1070
|
lastCanonicalRoom = currentCanonicalRoom;
|
|
1191
|
-
const newState =
|
|
1192
|
-
document: document && readModel(document),
|
|
1193
|
-
styles: deps.getStyles(),
|
|
1194
|
-
manager: deps.getExtensionManager(),
|
|
1195
|
-
externalPlugins: deps.getExternalPlugins(),
|
|
1196
|
-
collaboration,
|
|
1197
|
-
collaborationModules,
|
|
1198
|
-
reason: "external-document"
|
|
1199
|
-
});
|
|
1071
|
+
const newState = canonicalState(editorSession.session);
|
|
1200
1072
|
const updateStartedAt = performance.now();
|
|
1201
1073
|
view.updateState(newState);
|
|
1202
1074
|
recordHiddenEditorPhase("external-document", "update-state", performance.now() - updateStartedAt);
|
|
@@ -1302,28 +1174,19 @@ const createHiddenEditorManager = (hostDeps) => {
|
|
|
1302
1174
|
};
|
|
1303
1175
|
return executor;
|
|
1304
1176
|
};
|
|
1305
|
-
const isCanonicalModelSessionRequested = () => usesCanonicalSession(deps.getExperimentalSession?.(), CANONICAL_GAP.authorityRouting);
|
|
1306
1177
|
const anonymization = createAnonymizationHighlights();
|
|
1307
1178
|
const anonymizationSources = () => {
|
|
1308
|
-
if (editorSession.type
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
}
|
|
1320
|
-
if (!view) return [];
|
|
1321
|
-
const doc = view.state.doc;
|
|
1322
|
-
return [{
|
|
1323
|
-
story: OP_STORIES.MAIN,
|
|
1324
|
-
doc,
|
|
1325
|
-
addressAt: (position) => legacyTextAddressAt(doc, position)
|
|
1326
|
-
}];
|
|
1179
|
+
if (editorSession.type !== "canonical") return [];
|
|
1180
|
+
const session = editorSession.session;
|
|
1181
|
+
return documentStories(readModel(session.document)).flatMap((story) => {
|
|
1182
|
+
const projected = story === OP_STORIES.MAIN ? session.projection : session.projectStory(story).unwrapOr(null);
|
|
1183
|
+
if (projected === null) return [];
|
|
1184
|
+
return [{
|
|
1185
|
+
story,
|
|
1186
|
+
doc: projected.doc,
|
|
1187
|
+
addressAt: (position) => projected.addressAt(position).unwrapOr(null)
|
|
1188
|
+
}];
|
|
1189
|
+
});
|
|
1327
1190
|
};
|
|
1328
1191
|
return {
|
|
1329
1192
|
ensureView,
|
|
@@ -1419,10 +1282,7 @@ const createHiddenEditorManager = (hostDeps) => {
|
|
|
1419
1282
|
};
|
|
1420
1283
|
};
|
|
1421
1284
|
if (editorSession.type === "refused") return fail(editorSession.reason);
|
|
1422
|
-
if (editorSession.type !== "canonical")
|
|
1423
|
-
if (isCanonicalModelSessionRequested()) return fail("The canonical document is not ready for section changes.");
|
|
1424
|
-
return null;
|
|
1425
|
-
}
|
|
1285
|
+
if (editorSession.type !== "canonical") return fail("The document is not ready for section changes.");
|
|
1426
1286
|
if (!view || deps.getReadOnly() || isDestroying) return fail("The document is not editable.");
|
|
1427
1287
|
const session = editorSession.session;
|
|
1428
1288
|
if (session.isComposing) return fail("Section properties cannot change during composition.");
|
|
@@ -1449,10 +1309,7 @@ const createHiddenEditorManager = (hostDeps) => {
|
|
|
1449
1309
|
};
|
|
1450
1310
|
};
|
|
1451
1311
|
if (editorSession.type === "refused") return fail(editorSession.reason);
|
|
1452
|
-
if (editorSession.type !== "canonical")
|
|
1453
|
-
if (isCanonicalModelSessionRequested()) return fail("The canonical document is not ready for comment changes.");
|
|
1454
|
-
return null;
|
|
1455
|
-
}
|
|
1312
|
+
if (editorSession.type !== "canonical") return fail("The document is not ready for comment changes.");
|
|
1456
1313
|
if (!view || deps.getReadOnly()) return fail("The document is not editable.");
|
|
1457
1314
|
const session = editorSession.session;
|
|
1458
1315
|
if (session.isComposing) return fail("Comments cannot change during composition.", "afterComposition");
|
|
@@ -1465,8 +1322,18 @@ const createHiddenEditorManager = (hostDeps) => {
|
|
|
1465
1322
|
case "selection": {
|
|
1466
1323
|
const projection = session.projectStory(request.anchor.story);
|
|
1467
1324
|
if (projection.isErr()) return fail(projection.error.message);
|
|
1468
|
-
const
|
|
1469
|
-
const
|
|
1325
|
+
const { doc } = projection.value;
|
|
1326
|
+
const textEdge = (position, bias) => {
|
|
1327
|
+
if (position < 0 || position > doc.content.size) return position;
|
|
1328
|
+
const resolved = doc.resolve(position);
|
|
1329
|
+
if (resolved.parent.isTextblock) return position;
|
|
1330
|
+
const found = Selection.findFrom(resolved, bias, true);
|
|
1331
|
+
if (found === null) return position;
|
|
1332
|
+
return bias > 0 ? found.from : found.to;
|
|
1333
|
+
};
|
|
1334
|
+
const collapsed = request.anchor.from === request.anchor.to;
|
|
1335
|
+
const from = projection.value.addressAt(collapsed ? request.anchor.from : textEdge(request.anchor.from, 1));
|
|
1336
|
+
const to = projection.value.addressAt(collapsed ? request.anchor.to : textEdge(request.anchor.to, -1));
|
|
1470
1337
|
if (from.isErr()) return fail(from.error.message);
|
|
1471
1338
|
if (to.isErr()) return fail(to.error.message);
|
|
1472
1339
|
anchor = request.anchor.from === request.anchor.to ? {
|
|
@@ -1627,4 +1494,4 @@ const createHiddenEditorManager = (hostDeps) => {
|
|
|
1627
1494
|
}
|
|
1628
1495
|
};
|
|
1629
1496
|
};
|
|
1630
|
-
export { CanonicalSessionRefusalError,
|
|
1497
|
+
export { CanonicalSessionRefusalError, createHiddenEditorClipboardHandlers, createHiddenEditorManager, createHiddenEditorState };
|