@stll/folio-core 0.71.0 → 0.72.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 +2 -2
- package/dist/compat/eigenpal.d.ts +1 -2
- package/dist/compat/eigenpal.js +1 -2
- 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/hiddenEditorManager.d.ts +2 -37
- package/dist/controller/hiddenEditorManager.js +102 -294
- package/dist/controller/noteEditorManager.d.ts +3 -10
- package/dist/controller/noteEditorManager.js +33 -206
- package/dist/index.d.ts +1 -2
- package/dist/index.js +1 -2
- package/dist/managers/DocumentLoaderManager.d.ts +0 -4
- package/dist/managers/DocumentLoaderManager.js +4 -12
- 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/server.d.ts +1 -4
- package/dist/server.js +1 -4
- package/package.json +1 -3
- 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
|
|
20
|
+
import { ensureParaIdsInDoc } from "../prosemirror/extensions/features/ParaIdAllocatorExtension.js";
|
|
22
21
|
import { toggleMarkForAllScripts, toggleUnderlineMark } from "../prosemirror/extensions/marks/markUtils.js";
|
|
23
22
|
import { HyperlinkRemovalRefusal } from "../prosemirror/hyperlinkRemoval.js";
|
|
24
23
|
import { REVISION_MARK_NAMES } from "../prosemirror/keptRangeBoundaries.js";
|
|
25
24
|
import { adoptNativeSelection, createNativeNavigationPlugin, createNativeSelectionRefreshPlugin, isCompositionKeyDown } from "../prosemirror/nativeSelection.js";
|
|
26
|
-
import {
|
|
25
|
+
import { noteReferenceTransactionIssue } from "../prosemirror/noteReferenceOccurrences.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
29
|
import { createTextInputPlugin } from "../prosemirror/textInput.js";
|
|
31
|
-
import {
|
|
32
|
-
import { CANONICAL_GAP, CANONICAL_RULE, usesCanonicalSession } from "../types/canonicalCapabilities.js";
|
|
30
|
+
import { CANONICAL_GAP, CANONICAL_RULE } from "../types/canonicalCapabilities.js";
|
|
33
31
|
import { readModel } from "../types/documentModel.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 } 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;
|
|
@@ -156,49 +110,6 @@ function createHiddenEditorState(options) {
|
|
|
156
110
|
...manager?.getPlugins() ?? [createTextInputPlugin()],
|
|
157
111
|
styleResolverPlugin
|
|
158
112
|
];
|
|
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
113
|
const startedAt = performance.now();
|
|
203
114
|
const state = normalizeLocalSeedState(EditorState.create({
|
|
204
115
|
doc: localDoc,
|
|
@@ -265,7 +176,7 @@ const createHiddenEditorManager = (hostDeps) => {
|
|
|
265
176
|
} };
|
|
266
177
|
};
|
|
267
178
|
let releaseCommandOwner;
|
|
268
|
-
let editorSession = { type: "
|
|
179
|
+
let editorSession = { type: "unopened" };
|
|
269
180
|
let canonicalSessionEpoch = 0;
|
|
270
181
|
let modeOverride = null;
|
|
271
182
|
const syncCanonicalMode = () => {
|
|
@@ -297,12 +208,6 @@ const createHiddenEditorManager = (hostDeps) => {
|
|
|
297
208
|
offAutocompleteEdits = () => {};
|
|
298
209
|
leaveRoom();
|
|
299
210
|
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
211
|
const documentIdentity = deps.getDocumentIdentity();
|
|
307
212
|
if (editorSession.type === "refused" && editorSession.documentIdentity === documentIdentity) return false;
|
|
308
213
|
if (!document) {
|
|
@@ -367,7 +272,8 @@ const createHiddenEditorManager = (hostDeps) => {
|
|
|
367
272
|
...props.clipboardTextSerializer === void 0 ? {} : { clipboardTextSerializer: props.clipboardTextSerializer },
|
|
368
273
|
...props.transformPastedHTML === void 0 ? {} : { transformPastedHTML: props.transformPastedHTML },
|
|
369
274
|
...props.transformPasted === void 0 ? {} : { transformPasted: props.transformPasted }
|
|
370
|
-
} })])
|
|
275
|
+
} })]),
|
|
276
|
+
...deps.getExternalPlugins().flatMap(({ spec }) => spec.view === void 0 ? [] : [new Plugin({ view: spec.view })])
|
|
371
277
|
]
|
|
372
278
|
});
|
|
373
279
|
};
|
|
@@ -428,62 +334,43 @@ const createHiddenEditorManager = (hostDeps) => {
|
|
|
428
334
|
}
|
|
429
335
|
publishCanonical(prepared.value, refuse);
|
|
430
336
|
};
|
|
431
|
-
/** Insert a field in place of the selection
|
|
337
|
+
/** Insert a field in place of the selection. */
|
|
432
338
|
const insertField = (field) => {
|
|
433
|
-
if (!view || isDestroying || deps.getReadOnly()) return false;
|
|
339
|
+
if (!view || isDestroying || deps.getReadOnly() || editorSession.type !== "canonical") return false;
|
|
434
340
|
const { state } = view;
|
|
435
|
-
|
|
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
|
-
refuse(prepared.error.message, prepared.error.ground);
|
|
467
|
-
return false;
|
|
468
|
-
}
|
|
469
|
-
return publishCommit(prepared.value);
|
|
470
|
-
}
|
|
471
|
-
case "prosemirror": {
|
|
472
|
-
const fieldType = state.schema.nodes["field"];
|
|
473
|
-
if (fieldType === void 0) return false;
|
|
474
|
-
const insertion = state.tr.replaceSelectionWith(fieldType.create({
|
|
475
|
-
fieldType: parseFieldType(field.instruction),
|
|
476
|
-
instruction: field.instruction,
|
|
477
|
-
displayText: field.displayText,
|
|
478
|
-
fieldKind: "simple",
|
|
479
|
-
...field.locked === void 0 ? {} : { fldLock: field.locked }
|
|
480
|
-
}), false).scrollIntoView();
|
|
481
|
-
view.dispatch(closeHistory(insertion));
|
|
482
|
-
return true;
|
|
483
|
-
}
|
|
484
|
-
case "refused": return false;
|
|
485
|
-
default: return panic("Unhandled editor session");
|
|
341
|
+
const { session } = editorSession;
|
|
342
|
+
if (state.selection instanceof CellSelection) {
|
|
343
|
+
refuse("A field goes in at a text selection, not over cells.");
|
|
344
|
+
return false;
|
|
345
|
+
}
|
|
346
|
+
const range = canonicalSelectionRange(state);
|
|
347
|
+
const from = session.projection.addressAt(range.from);
|
|
348
|
+
if (from.isErr()) {
|
|
349
|
+
refuse(from.error.message, from.error.ground);
|
|
350
|
+
return false;
|
|
351
|
+
}
|
|
352
|
+
const to = session.projection.addressAt(range.to);
|
|
353
|
+
if (to.isErr()) {
|
|
354
|
+
refuse(to.error.message, to.error.ground);
|
|
355
|
+
return false;
|
|
356
|
+
}
|
|
357
|
+
syncCanonicalMode();
|
|
358
|
+
const prepared = session.prepareIntents(state, {
|
|
359
|
+
intents: [{
|
|
360
|
+
type: "replaceFragment",
|
|
361
|
+
from: from.value,
|
|
362
|
+
to: to.value,
|
|
363
|
+
paragraphs: [fieldInsertionParagraph(field)],
|
|
364
|
+
openStart: 1,
|
|
365
|
+
openEnd: 1
|
|
366
|
+
}],
|
|
367
|
+
semantic: "paste"
|
|
368
|
+
});
|
|
369
|
+
if (prepared.isErr()) {
|
|
370
|
+
refuse(prepared.error.message, prepared.error.ground);
|
|
371
|
+
return false;
|
|
486
372
|
}
|
|
373
|
+
return publishCommit(prepared.value);
|
|
487
374
|
};
|
|
488
375
|
/**
|
|
489
376
|
* Show a peer's edit the room sequenced: the same publication as a local
|
|
@@ -513,13 +400,8 @@ const createHiddenEditorManager = (hostDeps) => {
|
|
|
513
400
|
return Result.ok(void 0);
|
|
514
401
|
};
|
|
515
402
|
const autocompletePositionAt = (position) => {
|
|
516
|
-
if (!view || isDestroying) return null;
|
|
517
|
-
|
|
518
|
-
case "canonical": return editorSession.session.projection.positionAt(position).unwrapOr(null);
|
|
519
|
-
case "prosemirror": return legacyEditorPositionAt(view.state.doc, position);
|
|
520
|
-
case "refused": return null;
|
|
521
|
-
default: return editorSession;
|
|
522
|
-
}
|
|
403
|
+
if (!view || isDestroying || editorSession.type !== "canonical") return null;
|
|
404
|
+
return editorSession.session.projection.positionAt(position).unwrapOr(null);
|
|
523
405
|
};
|
|
524
406
|
/** Where the suggestion's anchor shows in the body's editor document. */
|
|
525
407
|
const autocompleteEditorAnchor = () => {
|
|
@@ -528,10 +410,9 @@ const createHiddenEditorManager = (hostDeps) => {
|
|
|
528
410
|
};
|
|
529
411
|
/** The caret as a body text position. */
|
|
530
412
|
const caretTextPosition = () => {
|
|
531
|
-
if (!view) return null;
|
|
413
|
+
if (!view || editorSession.type !== "canonical") return null;
|
|
532
414
|
const { head } = view.state.selection;
|
|
533
|
-
|
|
534
|
-
return legacyTextAddressAt(view.state.doc, head);
|
|
415
|
+
return editorSession.session.projection.addressAt(head).unwrapOr(null);
|
|
535
416
|
};
|
|
536
417
|
/**
|
|
537
418
|
* Insert the suggestion, or its next word, at its anchor as the person's
|
|
@@ -541,44 +422,35 @@ const createHiddenEditorManager = (hostDeps) => {
|
|
|
541
422
|
const acceptAutocomplete = (scope) => {
|
|
542
423
|
const current = autocomplete.get();
|
|
543
424
|
if (current.status === "idle" || current.text.length === 0) return false;
|
|
544
|
-
if (!view || deps.getReadOnly() || isDestroying) return false;
|
|
425
|
+
if (!view || deps.getReadOnly() || isDestroying || editorSession.type !== "canonical") return false;
|
|
545
426
|
const at = autocompleteEditorAnchor();
|
|
546
427
|
if (at === null) return false;
|
|
547
428
|
const text = scope === "word" ? nextAutocompleteWord(current.text) : current.text;
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
if (prepared.
|
|
559
|
-
|
|
560
|
-
return false;
|
|
561
|
-
}
|
|
562
|
-
const published = publishCommit(prepared.value);
|
|
563
|
-
session.breakUndoGroup();
|
|
564
|
-
return published;
|
|
429
|
+
syncCanonicalMode();
|
|
430
|
+
const session = editorSession.session;
|
|
431
|
+
session.breakUndoGroup();
|
|
432
|
+
const prepared = session.prepareReplace(view.state, {
|
|
433
|
+
from: at,
|
|
434
|
+
to: at,
|
|
435
|
+
text,
|
|
436
|
+
semantic: "typing"
|
|
437
|
+
});
|
|
438
|
+
if (prepared.isErr()) {
|
|
439
|
+
if (prepared.error.reason !== "noChange") refuse(prepared.error.message, prepared.error.ground);
|
|
440
|
+
return false;
|
|
565
441
|
}
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
view.dispatch(transaction.setSelection(TextSelection.create(transaction.doc, at + text.length)));
|
|
570
|
-
if (!view || view.state.doc.eq(previous)) return false;
|
|
571
|
-
view.dispatch(closeHistory(view.state.tr));
|
|
572
|
-
return true;
|
|
442
|
+
const published = publishCommit(prepared.value);
|
|
443
|
+
session.breakUndoGroup();
|
|
444
|
+
return published;
|
|
573
445
|
};
|
|
574
446
|
let autocompleteRequests = 0;
|
|
575
447
|
const autocompleteApi = {
|
|
576
448
|
start: (options) => {
|
|
577
449
|
const anchor = options?.at ?? caretTextPosition();
|
|
578
|
-
if (anchor === null || !view) return null;
|
|
450
|
+
if (anchor === null || !view || editorSession.type !== "canonical") return null;
|
|
579
451
|
const position = autocompletePositionAt(anchor);
|
|
580
452
|
if (position === null) return null;
|
|
581
|
-
const resolved = editorSession.
|
|
453
|
+
const resolved = editorSession.session.projection.addressAt(position).unwrapOr(null);
|
|
582
454
|
if (resolved === null) return null;
|
|
583
455
|
autocompleteRequests += 1;
|
|
584
456
|
const requestId = options?.requestId ?? `autocomplete-${String(autocompleteRequests)}`;
|
|
@@ -904,36 +776,16 @@ const createHiddenEditorManager = (hostDeps) => {
|
|
|
904
776
|
let requested = false;
|
|
905
777
|
let isInitialized = false;
|
|
906
778
|
let lastDocumentId = null;
|
|
907
|
-
let lastCollaborationFragment = null;
|
|
908
779
|
let lastCanonicalRoom = null;
|
|
909
780
|
const tryCreate = () => {
|
|
910
781
|
if (!requested || view !== null || isDestroying) return;
|
|
911
782
|
const host = deps.getHost();
|
|
912
783
|
if (!host) return;
|
|
913
|
-
const collaboration = deps.getCollaboration();
|
|
914
|
-
const collaborationModules = deps.getCollaborationModules();
|
|
915
|
-
if (collaboration && !collaborationModules && !usesCanonicalSession(deps.getExperimentalSession?.(), CANONICAL_GAP.authorityRouting)) return;
|
|
916
784
|
const document = deps.getDocument();
|
|
917
|
-
const styles = deps.getStyles();
|
|
918
|
-
const extensionManager = deps.getExtensionManager();
|
|
919
|
-
const externalPlugins = deps.getExternalPlugins();
|
|
920
785
|
input.reset();
|
|
921
|
-
if (!seedSession(document)) return;
|
|
786
|
+
if (!seedSession(document) || editorSession.type !== "canonical") return;
|
|
922
787
|
const editorProps = {
|
|
923
|
-
state: (
|
|
924
|
-
if (editorSession.type === "canonical") return canonicalState(editorSession.session);
|
|
925
|
-
const precomputedInitialState = collaboration ? null : deps.getPrecomputedInitialState();
|
|
926
|
-
if (precomputedInitialState) return precomputedInitialState;
|
|
927
|
-
return createHiddenEditorState({
|
|
928
|
-
document: document && readModel(document),
|
|
929
|
-
styles,
|
|
930
|
-
manager: extensionManager,
|
|
931
|
-
externalPlugins,
|
|
932
|
-
collaboration,
|
|
933
|
-
collaborationModules,
|
|
934
|
-
reason: "mount"
|
|
935
|
-
});
|
|
936
|
-
})(),
|
|
788
|
+
state: canonicalState(editorSession.session),
|
|
937
789
|
attributes: HIDDEN_EDITOR_ATTRIBUTES,
|
|
938
790
|
markViews: editingMarkViews(document),
|
|
939
791
|
editable: () => !deps.getReadOnly() && editorSession.type !== "refused",
|
|
@@ -943,32 +795,25 @@ const createHiddenEditorManager = (hostDeps) => {
|
|
|
943
795
|
deps.onReadOnlyEditAttempt();
|
|
944
796
|
return;
|
|
945
797
|
}
|
|
946
|
-
if (editorSession.type
|
|
947
|
-
if (
|
|
798
|
+
if (editorSession.type !== "canonical") return;
|
|
799
|
+
if (transaction.docChanged) {
|
|
948
800
|
if (input.acceptComposition(view, transaction)) return;
|
|
949
801
|
if (!input.commitNativeProposal(view, transaction)) input.refuseNativeMutation(view, transaction);
|
|
950
802
|
view.updateState(view.state);
|
|
951
803
|
return;
|
|
952
804
|
}
|
|
953
|
-
if (
|
|
805
|
+
if (transaction.selectionSet && !input.isComposing) {
|
|
954
806
|
lastInputRule = void 0;
|
|
955
807
|
editorSession.session.breakUndoGroup();
|
|
956
808
|
}
|
|
957
|
-
const modules = deps.getCollaborationModules();
|
|
958
|
-
if (modules && transaction.getMeta(modules.yProseMirror.ySyncPluginKey) !== void 0) markNoteReferenceReplay(transaction);
|
|
959
809
|
const applied = view.state.applyTransaction(transaction);
|
|
960
810
|
const noteIssue = noteReferenceTransactionIssue(transaction);
|
|
961
811
|
if (noteIssue) deps.onSessionRefusal?.(noteIssue.message, { gap: CANONICAL_GAP.dispatch }, noteIssue);
|
|
962
|
-
if (
|
|
812
|
+
if (!applied.state.doc.eq(view.state.doc)) {
|
|
963
813
|
refuse(unclassifiedMutationMessage(applied.transactions, "A plugin attempted an unclassified canonical document mutation."));
|
|
964
814
|
return;
|
|
965
815
|
}
|
|
966
816
|
const documentEdits = applied.transactions.filter((appliedTransaction) => appliedTransaction.docChanged && !isCommentRecordsSync(appliedTransaction));
|
|
967
|
-
let autocompleteEdit;
|
|
968
|
-
if (editorSession.type !== "canonical" && documentEdits.length > 0) {
|
|
969
|
-
const only = documentEdits.at(0);
|
|
970
|
-
autocompleteEdit = documentEdits.length === 1 && only === transaction ? legacyAutocompleteEdit(transaction) : { type: "other" };
|
|
971
|
-
}
|
|
972
817
|
view.updateState(applied.state);
|
|
973
818
|
const docChanged = documentEdits.length > 0;
|
|
974
819
|
const selectionChanged = applied.transactions.some((appliedTransaction) => appliedTransaction.selectionSet || appliedTransaction.docChanged && !isCommentRecordsSync(appliedTransaction));
|
|
@@ -978,10 +823,6 @@ const createHiddenEditorManager = (hostDeps) => {
|
|
|
978
823
|
docChanged
|
|
979
824
|
});
|
|
980
825
|
if (selectionChanged) deps.onSelectionChange(applied.state);
|
|
981
|
-
const currentCollaboration = deps.getCollaboration();
|
|
982
|
-
const currentCollaborationModules = deps.getCollaborationModules();
|
|
983
|
-
if (currentCollaboration?.awareness && currentCollaborationModules) deps.onRemoteSelectionsChange(collectRemoteSelections(applied.state, currentCollaboration.awareness, currentCollaborationModules));
|
|
984
|
-
if (autocompleteEdit !== void 0) autocomplete.noteEdit(view?.state === applied.state ? autocompleteEdit : { type: "other" });
|
|
985
826
|
},
|
|
986
827
|
handleKeyDown: (pmView, event) => {
|
|
987
828
|
if (handleAutocompleteKeyDown(event)) return true;
|
|
@@ -1132,7 +973,6 @@ const createHiddenEditorManager = (hostDeps) => {
|
|
|
1132
973
|
syncHiddenEditorAccessibility(view, deps.getReadOnly());
|
|
1133
974
|
isInitialized = true;
|
|
1134
975
|
lastDocumentId = deps.getDocumentIdentity();
|
|
1135
|
-
lastCollaborationFragment = collaboration?.yXmlFragment ?? null;
|
|
1136
976
|
lastCanonicalRoom = deps.getCanonicalRoom?.() ?? null;
|
|
1137
977
|
deps.onEditorViewReady(view);
|
|
1138
978
|
};
|
|
@@ -1162,40 +1002,23 @@ const createHiddenEditorManager = (hostDeps) => {
|
|
|
1162
1002
|
};
|
|
1163
1003
|
const syncExternalDocument = () => {
|
|
1164
1004
|
if (isDestroying) return;
|
|
1165
|
-
const canonicalRequested = usesCanonicalSession(deps.getExperimentalSession?.(), CANONICAL_GAP.authorityRouting);
|
|
1166
1005
|
if (!view) {
|
|
1167
|
-
if (
|
|
1006
|
+
if (deps.getDocument() !== null) ensureView();
|
|
1168
1007
|
return;
|
|
1169
1008
|
}
|
|
1170
|
-
const collaboration = deps.getCollaboration();
|
|
1171
|
-
const collaborationModules = deps.getCollaborationModules();
|
|
1172
|
-
if (collaboration && !collaborationModules && !canonicalRequested) return;
|
|
1173
1009
|
const document = deps.getDocument();
|
|
1174
1010
|
const currentDocId = deps.getDocumentIdentity();
|
|
1175
|
-
const currentCollaborationFragment = collaboration?.yXmlFragment ?? null;
|
|
1176
1011
|
const currentCanonicalRoom = deps.getCanonicalRoom?.() ?? null;
|
|
1177
|
-
|
|
1178
|
-
const sessionChanged = editorSession.type !== "prosemirror" !== canonicalRequested;
|
|
1179
|
-
if (collaboration && !collaborationSourceChanged && !sessionChanged) return;
|
|
1180
|
-
if (isInitialized && currentDocId === lastDocumentId && !collaborationSourceChanged && !sessionChanged) return;
|
|
1012
|
+
if (isInitialized && currentDocId === lastDocumentId && !(currentCanonicalRoom !== lastCanonicalRoom)) return;
|
|
1181
1013
|
input.reset();
|
|
1182
|
-
if (!seedSession(document)) {
|
|
1014
|
+
if (!seedSession(document) || editorSession.type !== "canonical") {
|
|
1183
1015
|
destroyView();
|
|
1184
1016
|
return;
|
|
1185
1017
|
}
|
|
1186
1018
|
isInitialized = true;
|
|
1187
1019
|
lastDocumentId = currentDocId;
|
|
1188
|
-
lastCollaborationFragment = currentCollaborationFragment;
|
|
1189
1020
|
lastCanonicalRoom = currentCanonicalRoom;
|
|
1190
|
-
const newState =
|
|
1191
|
-
document: document && readModel(document),
|
|
1192
|
-
styles: deps.getStyles(),
|
|
1193
|
-
manager: deps.getExtensionManager(),
|
|
1194
|
-
externalPlugins: deps.getExternalPlugins(),
|
|
1195
|
-
collaboration,
|
|
1196
|
-
collaborationModules,
|
|
1197
|
-
reason: "external-document"
|
|
1198
|
-
});
|
|
1021
|
+
const newState = canonicalState(editorSession.session);
|
|
1199
1022
|
const updateStartedAt = performance.now();
|
|
1200
1023
|
view.updateState(newState);
|
|
1201
1024
|
recordHiddenEditorPhase("external-document", "update-state", performance.now() - updateStartedAt);
|
|
@@ -1301,28 +1124,19 @@ const createHiddenEditorManager = (hostDeps) => {
|
|
|
1301
1124
|
};
|
|
1302
1125
|
return executor;
|
|
1303
1126
|
};
|
|
1304
|
-
const isCanonicalModelSessionRequested = () => usesCanonicalSession(deps.getExperimentalSession?.(), CANONICAL_GAP.authorityRouting);
|
|
1305
1127
|
const anonymization = createAnonymizationHighlights();
|
|
1306
1128
|
const anonymizationSources = () => {
|
|
1307
|
-
if (editorSession.type
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
}
|
|
1319
|
-
if (!view) return [];
|
|
1320
|
-
const doc = view.state.doc;
|
|
1321
|
-
return [{
|
|
1322
|
-
story: OP_STORIES.MAIN,
|
|
1323
|
-
doc,
|
|
1324
|
-
addressAt: (position) => legacyTextAddressAt(doc, position)
|
|
1325
|
-
}];
|
|
1129
|
+
if (editorSession.type !== "canonical") return [];
|
|
1130
|
+
const session = editorSession.session;
|
|
1131
|
+
return documentStories(readModel(session.document)).flatMap((story) => {
|
|
1132
|
+
const projected = story === OP_STORIES.MAIN ? session.projection : session.projectStory(story).unwrapOr(null);
|
|
1133
|
+
if (projected === null) return [];
|
|
1134
|
+
return [{
|
|
1135
|
+
story,
|
|
1136
|
+
doc: projected.doc,
|
|
1137
|
+
addressAt: (position) => projected.addressAt(position).unwrapOr(null)
|
|
1138
|
+
}];
|
|
1139
|
+
});
|
|
1326
1140
|
};
|
|
1327
1141
|
return {
|
|
1328
1142
|
ensureView,
|
|
@@ -1418,10 +1232,7 @@ const createHiddenEditorManager = (hostDeps) => {
|
|
|
1418
1232
|
};
|
|
1419
1233
|
};
|
|
1420
1234
|
if (editorSession.type === "refused") return fail(editorSession.reason);
|
|
1421
|
-
if (editorSession.type !== "canonical")
|
|
1422
|
-
if (isCanonicalModelSessionRequested()) return fail("The canonical document is not ready for section changes.");
|
|
1423
|
-
return null;
|
|
1424
|
-
}
|
|
1235
|
+
if (editorSession.type !== "canonical") return fail("The document is not ready for section changes.");
|
|
1425
1236
|
if (!view || deps.getReadOnly() || isDestroying) return fail("The document is not editable.");
|
|
1426
1237
|
const session = editorSession.session;
|
|
1427
1238
|
if (session.isComposing) return fail("Section properties cannot change during composition.");
|
|
@@ -1448,10 +1259,7 @@ const createHiddenEditorManager = (hostDeps) => {
|
|
|
1448
1259
|
};
|
|
1449
1260
|
};
|
|
1450
1261
|
if (editorSession.type === "refused") return fail(editorSession.reason);
|
|
1451
|
-
if (editorSession.type !== "canonical")
|
|
1452
|
-
if (isCanonicalModelSessionRequested()) return fail("The canonical document is not ready for comment changes.");
|
|
1453
|
-
return null;
|
|
1454
|
-
}
|
|
1262
|
+
if (editorSession.type !== "canonical") return fail("The document is not ready for comment changes.");
|
|
1455
1263
|
if (!view || deps.getReadOnly()) return fail("The document is not editable.");
|
|
1456
1264
|
const session = editorSession.session;
|
|
1457
1265
|
if (session.isComposing) return fail("Comments cannot change during composition.", "afterComposition");
|
|
@@ -1626,4 +1434,4 @@ const createHiddenEditorManager = (hostDeps) => {
|
|
|
1626
1434
|
}
|
|
1627
1435
|
};
|
|
1628
1436
|
};
|
|
1629
|
-
export { CanonicalSessionRefusalError,
|
|
1437
|
+
export { CanonicalSessionRefusalError, createHiddenEditorClipboardHandlers, createHiddenEditorManager, createHiddenEditorState };
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
import { CanonicalRefusalGround, EditorSession } from "../types/canonicalCapabilities.js";
|
|
1
|
+
import { CanonicalRefusalGround } from "../types/canonicalCapabilities.js";
|
|
3
2
|
import { document_d_exports } from "../types/document.js";
|
|
4
3
|
import { DeepReadonly, ReadonlyDocument } from "../types/documentModel.js";
|
|
5
4
|
import { NoteStoryKey } from "../types/editor-story.js";
|
|
6
5
|
import { HiddenEditorApi } from "./hiddenEditorApi.js";
|
|
7
|
-
import { Plugin } from "prosemirror-state";
|
|
8
6
|
import { DirectEditorProps, EditorView } from "prosemirror-view";
|
|
9
7
|
export type NoteStoryKind = NoteStoryKey["kind"];
|
|
10
8
|
export type NoteEditorTransaction = NoteStoryKey & {
|
|
@@ -14,19 +12,15 @@ export type NoteEditorTransaction = NoteStoryKey & {
|
|
|
14
12
|
};
|
|
15
13
|
export type NoteEditorManagerDeps = {
|
|
16
14
|
createView?: ((mountNode: HTMLElement, props: DirectEditorProps) => EditorView) | undefined;
|
|
17
|
-
getDocument: () => ReadonlyDocument | null;
|
|
18
15
|
getCanonicalApi?: (() => HiddenEditorApi | null) | undefined;
|
|
19
16
|
/**
|
|
20
17
|
* The canonical session's own document, read without a copy (see
|
|
21
18
|
* `HiddenEditorManager.readCanonicalDocument`); null outside a session.
|
|
22
19
|
*/
|
|
23
20
|
readCanonicalDocument: () => ReadonlyDocument | null;
|
|
24
|
-
getExperimentalSession?: (() => EditorSession | undefined) | undefined;
|
|
25
21
|
onSessionRefusal?: ((reason: string, ground: CanonicalRefusalGround, error?: Error) => void) | undefined;
|
|
26
22
|
getHost: () => HTMLElement | null;
|
|
27
|
-
getPlugins?: (() => Plugin[]) | undefined;
|
|
28
23
|
getStyles: () => DeepReadonly<document_d_exports.StyleDefinitions> | null | undefined;
|
|
29
|
-
getTheme: () => DeepReadonly<document_d_exports.Theme> | null | undefined;
|
|
30
24
|
onTransaction?: ((transaction: NoteEditorTransaction) => void) | undefined;
|
|
31
25
|
};
|
|
32
26
|
export type NoteEditorManager = {
|
|
@@ -36,11 +30,10 @@ export type NoteEditorManager = {
|
|
|
36
30
|
getView: (story: NoteStoryKey) => EditorView | null;
|
|
37
31
|
listStories: () => NoteStoryKey[];
|
|
38
32
|
/**
|
|
39
|
-
* The
|
|
40
|
-
* touched with `model` and with the mounted editors, so it is read-only: a
|
|
33
|
+
* The session's document with every story's edits. It is read-only: a
|
|
41
34
|
* writer copies it first (`cloneDocumentWithParagraphPropertySources`).
|
|
42
35
|
*/
|
|
43
|
-
snapshotDocument: (
|
|
36
|
+
snapshotDocument: () => ReadonlyDocument;
|
|
44
37
|
sync: () => void;
|
|
45
38
|
};
|
|
46
39
|
export declare const enumerateDocumentNoteStories: (document: document_d_exports.Document | null) => NoteStoryKey[];
|