@stll/folio-core 0.71.1 → 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 +100 -293
- 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) {
|
|
@@ -429,62 +334,43 @@ const createHiddenEditorManager = (hostDeps) => {
|
|
|
429
334
|
}
|
|
430
335
|
publishCanonical(prepared.value, refuse);
|
|
431
336
|
};
|
|
432
|
-
/** Insert a field in place of the selection
|
|
337
|
+
/** Insert a field in place of the selection. */
|
|
433
338
|
const insertField = (field) => {
|
|
434
|
-
if (!view || isDestroying || deps.getReadOnly()) return false;
|
|
339
|
+
if (!view || isDestroying || deps.getReadOnly() || editorSession.type !== "canonical") return false;
|
|
435
340
|
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");
|
|
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;
|
|
487
372
|
}
|
|
373
|
+
return publishCommit(prepared.value);
|
|
488
374
|
};
|
|
489
375
|
/**
|
|
490
376
|
* Show a peer's edit the room sequenced: the same publication as a local
|
|
@@ -514,13 +400,8 @@ const createHiddenEditorManager = (hostDeps) => {
|
|
|
514
400
|
return Result.ok(void 0);
|
|
515
401
|
};
|
|
516
402
|
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
|
-
}
|
|
403
|
+
if (!view || isDestroying || editorSession.type !== "canonical") return null;
|
|
404
|
+
return editorSession.session.projection.positionAt(position).unwrapOr(null);
|
|
524
405
|
};
|
|
525
406
|
/** Where the suggestion's anchor shows in the body's editor document. */
|
|
526
407
|
const autocompleteEditorAnchor = () => {
|
|
@@ -529,10 +410,9 @@ const createHiddenEditorManager = (hostDeps) => {
|
|
|
529
410
|
};
|
|
530
411
|
/** The caret as a body text position. */
|
|
531
412
|
const caretTextPosition = () => {
|
|
532
|
-
if (!view) return null;
|
|
413
|
+
if (!view || editorSession.type !== "canonical") return null;
|
|
533
414
|
const { head } = view.state.selection;
|
|
534
|
-
|
|
535
|
-
return legacyTextAddressAt(view.state.doc, head);
|
|
415
|
+
return editorSession.session.projection.addressAt(head).unwrapOr(null);
|
|
536
416
|
};
|
|
537
417
|
/**
|
|
538
418
|
* Insert the suggestion, or its next word, at its anchor as the person's
|
|
@@ -542,44 +422,35 @@ const createHiddenEditorManager = (hostDeps) => {
|
|
|
542
422
|
const acceptAutocomplete = (scope) => {
|
|
543
423
|
const current = autocomplete.get();
|
|
544
424
|
if (current.status === "idle" || current.text.length === 0) return false;
|
|
545
|
-
if (!view || deps.getReadOnly() || isDestroying) return false;
|
|
425
|
+
if (!view || deps.getReadOnly() || isDestroying || editorSession.type !== "canonical") return false;
|
|
546
426
|
const at = autocompleteEditorAnchor();
|
|
547
427
|
if (at === null) return false;
|
|
548
428
|
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;
|
|
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;
|
|
566
441
|
}
|
|
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;
|
|
442
|
+
const published = publishCommit(prepared.value);
|
|
443
|
+
session.breakUndoGroup();
|
|
444
|
+
return published;
|
|
574
445
|
};
|
|
575
446
|
let autocompleteRequests = 0;
|
|
576
447
|
const autocompleteApi = {
|
|
577
448
|
start: (options) => {
|
|
578
449
|
const anchor = options?.at ?? caretTextPosition();
|
|
579
|
-
if (anchor === null || !view) return null;
|
|
450
|
+
if (anchor === null || !view || editorSession.type !== "canonical") return null;
|
|
580
451
|
const position = autocompletePositionAt(anchor);
|
|
581
452
|
if (position === null) return null;
|
|
582
|
-
const resolved = editorSession.
|
|
453
|
+
const resolved = editorSession.session.projection.addressAt(position).unwrapOr(null);
|
|
583
454
|
if (resolved === null) return null;
|
|
584
455
|
autocompleteRequests += 1;
|
|
585
456
|
const requestId = options?.requestId ?? `autocomplete-${String(autocompleteRequests)}`;
|
|
@@ -905,36 +776,16 @@ const createHiddenEditorManager = (hostDeps) => {
|
|
|
905
776
|
let requested = false;
|
|
906
777
|
let isInitialized = false;
|
|
907
778
|
let lastDocumentId = null;
|
|
908
|
-
let lastCollaborationFragment = null;
|
|
909
779
|
let lastCanonicalRoom = null;
|
|
910
780
|
const tryCreate = () => {
|
|
911
781
|
if (!requested || view !== null || isDestroying) return;
|
|
912
782
|
const host = deps.getHost();
|
|
913
783
|
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
784
|
const document = deps.getDocument();
|
|
918
|
-
const styles = deps.getStyles();
|
|
919
|
-
const extensionManager = deps.getExtensionManager();
|
|
920
|
-
const externalPlugins = deps.getExternalPlugins();
|
|
921
785
|
input.reset();
|
|
922
|
-
if (!seedSession(document)) return;
|
|
786
|
+
if (!seedSession(document) || editorSession.type !== "canonical") return;
|
|
923
787
|
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
|
-
})(),
|
|
788
|
+
state: canonicalState(editorSession.session),
|
|
938
789
|
attributes: HIDDEN_EDITOR_ATTRIBUTES,
|
|
939
790
|
markViews: editingMarkViews(document),
|
|
940
791
|
editable: () => !deps.getReadOnly() && editorSession.type !== "refused",
|
|
@@ -944,32 +795,25 @@ const createHiddenEditorManager = (hostDeps) => {
|
|
|
944
795
|
deps.onReadOnlyEditAttempt();
|
|
945
796
|
return;
|
|
946
797
|
}
|
|
947
|
-
if (editorSession.type
|
|
948
|
-
if (
|
|
798
|
+
if (editorSession.type !== "canonical") return;
|
|
799
|
+
if (transaction.docChanged) {
|
|
949
800
|
if (input.acceptComposition(view, transaction)) return;
|
|
950
801
|
if (!input.commitNativeProposal(view, transaction)) input.refuseNativeMutation(view, transaction);
|
|
951
802
|
view.updateState(view.state);
|
|
952
803
|
return;
|
|
953
804
|
}
|
|
954
|
-
if (
|
|
805
|
+
if (transaction.selectionSet && !input.isComposing) {
|
|
955
806
|
lastInputRule = void 0;
|
|
956
807
|
editorSession.session.breakUndoGroup();
|
|
957
808
|
}
|
|
958
|
-
const modules = deps.getCollaborationModules();
|
|
959
|
-
if (modules && transaction.getMeta(modules.yProseMirror.ySyncPluginKey) !== void 0) markNoteReferenceReplay(transaction);
|
|
960
809
|
const applied = view.state.applyTransaction(transaction);
|
|
961
810
|
const noteIssue = noteReferenceTransactionIssue(transaction);
|
|
962
811
|
if (noteIssue) deps.onSessionRefusal?.(noteIssue.message, { gap: CANONICAL_GAP.dispatch }, noteIssue);
|
|
963
|
-
if (
|
|
812
|
+
if (!applied.state.doc.eq(view.state.doc)) {
|
|
964
813
|
refuse(unclassifiedMutationMessage(applied.transactions, "A plugin attempted an unclassified canonical document mutation."));
|
|
965
814
|
return;
|
|
966
815
|
}
|
|
967
816
|
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
817
|
view.updateState(applied.state);
|
|
974
818
|
const docChanged = documentEdits.length > 0;
|
|
975
819
|
const selectionChanged = applied.transactions.some((appliedTransaction) => appliedTransaction.selectionSet || appliedTransaction.docChanged && !isCommentRecordsSync(appliedTransaction));
|
|
@@ -979,10 +823,6 @@ const createHiddenEditorManager = (hostDeps) => {
|
|
|
979
823
|
docChanged
|
|
980
824
|
});
|
|
981
825
|
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
826
|
},
|
|
987
827
|
handleKeyDown: (pmView, event) => {
|
|
988
828
|
if (handleAutocompleteKeyDown(event)) return true;
|
|
@@ -1133,7 +973,6 @@ const createHiddenEditorManager = (hostDeps) => {
|
|
|
1133
973
|
syncHiddenEditorAccessibility(view, deps.getReadOnly());
|
|
1134
974
|
isInitialized = true;
|
|
1135
975
|
lastDocumentId = deps.getDocumentIdentity();
|
|
1136
|
-
lastCollaborationFragment = collaboration?.yXmlFragment ?? null;
|
|
1137
976
|
lastCanonicalRoom = deps.getCanonicalRoom?.() ?? null;
|
|
1138
977
|
deps.onEditorViewReady(view);
|
|
1139
978
|
};
|
|
@@ -1163,40 +1002,23 @@ const createHiddenEditorManager = (hostDeps) => {
|
|
|
1163
1002
|
};
|
|
1164
1003
|
const syncExternalDocument = () => {
|
|
1165
1004
|
if (isDestroying) return;
|
|
1166
|
-
const canonicalRequested = usesCanonicalSession(deps.getExperimentalSession?.(), CANONICAL_GAP.authorityRouting);
|
|
1167
1005
|
if (!view) {
|
|
1168
|
-
if (
|
|
1006
|
+
if (deps.getDocument() !== null) ensureView();
|
|
1169
1007
|
return;
|
|
1170
1008
|
}
|
|
1171
|
-
const collaboration = deps.getCollaboration();
|
|
1172
|
-
const collaborationModules = deps.getCollaborationModules();
|
|
1173
|
-
if (collaboration && !collaborationModules && !canonicalRequested) return;
|
|
1174
1009
|
const document = deps.getDocument();
|
|
1175
1010
|
const currentDocId = deps.getDocumentIdentity();
|
|
1176
|
-
const currentCollaborationFragment = collaboration?.yXmlFragment ?? null;
|
|
1177
1011
|
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;
|
|
1012
|
+
if (isInitialized && currentDocId === lastDocumentId && !(currentCanonicalRoom !== lastCanonicalRoom)) return;
|
|
1182
1013
|
input.reset();
|
|
1183
|
-
if (!seedSession(document)) {
|
|
1014
|
+
if (!seedSession(document) || editorSession.type !== "canonical") {
|
|
1184
1015
|
destroyView();
|
|
1185
1016
|
return;
|
|
1186
1017
|
}
|
|
1187
1018
|
isInitialized = true;
|
|
1188
1019
|
lastDocumentId = currentDocId;
|
|
1189
|
-
lastCollaborationFragment = currentCollaborationFragment;
|
|
1190
1020
|
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
|
-
});
|
|
1021
|
+
const newState = canonicalState(editorSession.session);
|
|
1200
1022
|
const updateStartedAt = performance.now();
|
|
1201
1023
|
view.updateState(newState);
|
|
1202
1024
|
recordHiddenEditorPhase("external-document", "update-state", performance.now() - updateStartedAt);
|
|
@@ -1302,28 +1124,19 @@ const createHiddenEditorManager = (hostDeps) => {
|
|
|
1302
1124
|
};
|
|
1303
1125
|
return executor;
|
|
1304
1126
|
};
|
|
1305
|
-
const isCanonicalModelSessionRequested = () => usesCanonicalSession(deps.getExperimentalSession?.(), CANONICAL_GAP.authorityRouting);
|
|
1306
1127
|
const anonymization = createAnonymizationHighlights();
|
|
1307
1128
|
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
|
-
}];
|
|
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
|
+
});
|
|
1327
1140
|
};
|
|
1328
1141
|
return {
|
|
1329
1142
|
ensureView,
|
|
@@ -1419,10 +1232,7 @@ const createHiddenEditorManager = (hostDeps) => {
|
|
|
1419
1232
|
};
|
|
1420
1233
|
};
|
|
1421
1234
|
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
|
-
}
|
|
1235
|
+
if (editorSession.type !== "canonical") return fail("The document is not ready for section changes.");
|
|
1426
1236
|
if (!view || deps.getReadOnly() || isDestroying) return fail("The document is not editable.");
|
|
1427
1237
|
const session = editorSession.session;
|
|
1428
1238
|
if (session.isComposing) return fail("Section properties cannot change during composition.");
|
|
@@ -1449,10 +1259,7 @@ const createHiddenEditorManager = (hostDeps) => {
|
|
|
1449
1259
|
};
|
|
1450
1260
|
};
|
|
1451
1261
|
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
|
-
}
|
|
1262
|
+
if (editorSession.type !== "canonical") return fail("The document is not ready for comment changes.");
|
|
1456
1263
|
if (!view || deps.getReadOnly()) return fail("The document is not editable.");
|
|
1457
1264
|
const session = editorSession.session;
|
|
1458
1265
|
if (session.isComposing) return fail("Comments cannot change during composition.", "afterComposition");
|
|
@@ -1627,4 +1434,4 @@ const createHiddenEditorManager = (hostDeps) => {
|
|
|
1627
1434
|
}
|
|
1628
1435
|
};
|
|
1629
1436
|
};
|
|
1630
|
-
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[];
|