@stll/folio-core 0.68.0 → 0.69.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/dist/ai-edits/headless.js +2 -2
- package/dist/ai-edits/newListNumbering.d.ts +14 -1
- package/dist/ai-edits/newListNumbering.js +24 -1
- package/dist/ai-edits/pending-suggestions.js +2 -2
- package/dist/controller/canonicalClipboard.js +2 -2
- package/dist/controller/canonicalComposition.js +34 -5
- package/dist/controller/canonicalInput.js +4 -6
- package/dist/controller/canonicalLockGuard.d.ts +17 -2
- package/dist/controller/canonicalLockGuard.js +46 -1
- package/dist/controller/canonicalProjectionBlocks.d.ts +79 -0
- package/dist/controller/canonicalProjectionBlocks.js +75 -0
- package/dist/controller/canonicalPublicOperations.js +476 -100
- package/dist/controller/canonicalSeedContent.d.ts +12 -0
- package/dist/controller/canonicalSeedContent.js +131 -0
- package/dist/controller/canonicalSession.d.ts +53 -21
- package/dist/controller/canonicalSession.js +489 -210
- package/dist/controller/canonicalSourceNormalization.d.ts +21 -0
- package/dist/controller/canonicalSourceNormalization.js +148 -0
- package/dist/controller/canonicalStoryEditor.d.ts +1 -1
- package/dist/controller/canonicalStoryEditor.js +16 -12
- package/dist/controller/folioEditor.js +3 -0
- package/dist/controller/headerFooterEditorManager.d.ts +5 -0
- package/dist/controller/headerFooterEditorManager.js +7 -2
- package/dist/controller/hiddenEditorApi.d.ts +11 -2
- package/dist/controller/hiddenEditorApi.js +3 -0
- package/dist/controller/hiddenEditorManager.d.ts +7 -0
- package/dist/controller/hiddenEditorManager.js +66 -11
- package/dist/controller/layoutPipeline.js +2 -1
- package/dist/controller/layoutSession.d.ts +3 -0
- package/dist/controller/layoutSession.js +3 -1
- package/dist/controller/noteEditorManager.d.ts +5 -0
- package/dist/controller/noteEditorManager.js +7 -2
- package/dist/display-list/dom/renderDisplayListToDom.js +9 -7
- package/dist/document-operations.d.ts +1 -1
- package/dist/docx/canonicalSave.js +7 -2
- package/dist/docx/commentAnchorIndex.d.ts +19 -0
- package/dist/docx/commentAnchorIndex.js +55 -1
- package/dist/docx/containerChildren.js +1 -1
- package/dist/docx/contentTypeRegistry.js +1 -1
- package/dist/docx/hostCommentThreads.d.ts +11 -1
- package/dist/docx/hostCommentThreads.js +25 -2
- package/dist/docx/listModelNormalization.js +4 -5
- package/dist/docx/listNumberingInstances.d.ts +1 -1
- package/dist/docx/listNumberingInstances.js +2 -2
- package/dist/docx/numberingIds.d.ts +6 -0
- package/dist/docx/numberingIds.js +6 -1
- package/dist/docx/numberingReferenceNormalization.d.ts +4 -0
- package/dist/docx/numberingReferenceNormalization.js +12 -2
- package/dist/docx/paragraphPropertySource.d.ts +22 -0
- package/dist/docx/paragraphPropertySource.js +85 -16
- package/dist/docx/parser.js +2 -0
- package/dist/docx/removeHeaderFooterParts.js +1 -1
- package/dist/docx/reviewResolutionProvenance.js +72 -19
- package/dist/docx/serializer/documentSerializer.js +2 -1
- package/dist/docx/serializer/partNamespaces.d.ts +1 -1
- package/dist/docx/serializer/partNamespaces.js +1 -1
- package/dist/docx/server/build.d.ts +1 -1
- package/dist/docx/storyBlockReplay.js +15 -2
- package/dist/docx/structuralXmlPatch.js +25 -4
- package/dist/docx/xmlParser.d.ts +1 -1
- package/dist/docx/xmlParser.js +2 -3
- package/dist/i18n/messages/ar.gen.js +1 -0
- package/dist/i18n/messages/catalogs.gen.d.ts +17 -0
- package/dist/i18n/messages/catalogs.gen.js +17 -0
- package/dist/i18n/messages/cs.gen.js +1 -0
- package/dist/i18n/messages/de.gen.js +1 -0
- package/dist/i18n/messages/en.gen.js +1 -0
- package/dist/i18n/messages/es.gen.js +1 -0
- package/dist/i18n/messages/et.gen.js +1 -0
- package/dist/i18n/messages/fr.gen.js +1 -0
- package/dist/i18n/messages/he.gen.js +1 -0
- package/dist/i18n/messages/hi.gen.js +1 -0
- package/dist/i18n/messages/hu.gen.js +1 -0
- package/dist/i18n/messages/lt.gen.js +1 -0
- package/dist/i18n/messages/lv.gen.js +1 -0
- package/dist/i18n/messages/messages.gen.d.ts +1 -0
- package/dist/i18n/messages/pl.gen.js +1 -0
- package/dist/i18n/messages/pt-BR.gen.js +1 -0
- package/dist/i18n/messages/sk.gen.js +1 -0
- package/dist/i18n/messages/tr.gen.js +1 -0
- package/dist/i18n/messages/zh-CN.gen.js +1 -0
- package/dist/internal/pageBreakRunDescendantIndex.d.ts +7 -2
- package/dist/internal/pageBreakRunDescendantIndex.js +12 -3
- package/dist/internal/subtreeHolds.d.ts +12 -0
- package/dist/internal/subtreeHolds.js +25 -0
- package/dist/internal/wholeStoryRevisionResolution.js +1 -1
- package/dist/layout-bridge/cellSelectionHighlight.js +3 -3
- package/dist/layout-bridge/convert/flowBlockPostprocessing.js +20 -12
- package/dist/layout-bridge/convert/flowConversionShared.d.ts +15 -1
- package/dist/layout-bridge/convert/flowConversionShared.js +9 -1
- package/dist/layout-bridge/convert/paragraphAttrs.d.ts +15 -4
- package/dist/layout-bridge/convert/paragraphAttrs.js +11 -4
- package/dist/layout-bridge/convert/paragraphBlockCache.d.ts +26 -0
- package/dist/layout-bridge/convert/paragraphBlockCache.js +137 -0
- package/dist/layout-bridge/convert/paragraphConversion.d.ts +12 -2
- package/dist/layout-bridge/convert/paragraphConversion.js +37 -5
- package/dist/layout-bridge/convert/paragraphRuns.d.ts +2 -2
- package/dist/layout-bridge/convert/sectionBoundaries.js +16 -0
- package/dist/layout-bridge/convert/toFlowBlocks.js +144 -15
- package/dist/layout-bridge/convert/topLevelConversion.d.ts +74 -0
- package/dist/layout-bridge/convert/topLevelConversion.js +109 -0
- package/dist/layout-bridge/dom/clickToPositionDom.js +41 -40
- package/dist/layout-bridge/dom/findBodyPmSpans.js +4 -3
- package/dist/layout-bridge/dom/findHfPmSpans.js +10 -15
- package/dist/layout-bridge/dom/imeCaretAnchor.d.ts +8 -0
- package/dist/layout-bridge/dom/imeCaretAnchor.js +71 -7
- package/dist/layout-bridge/dom/textStreamDom.js +3 -2
- package/dist/layout-bridge/headerFooterLayout.js +12 -11
- package/dist/layout-bridge/tableInsertHover.js +2 -1
- package/dist/layout-engine/measure/cache.d.ts +2 -0
- package/dist/layout-engine/measure/cache.js +6 -1
- package/dist/layout-engine/measure/paragraphKeyMemo.d.ts +8 -0
- package/dist/layout-engine/measure/paragraphKeyMemo.js +92 -0
- package/dist/layout-engine/types.d.ts +6 -0
- package/dist/layout-painter/imageLayout.js +2 -1
- package/dist/layout-painter/pageShellStyles.d.ts +10 -0
- package/dist/layout-painter/pageShellStyles.js +32 -0
- package/dist/layout-painter/reconcileRenderedContent.d.ts +19 -0
- package/dist/layout-painter/reconcileRenderedContent.js +117 -0
- package/dist/layout-painter/renderFragment.js +4 -6
- package/dist/layout-painter/renderImage.js +2 -2
- package/dist/layout-painter/renderPage.js +8 -29
- package/dist/layout-painter/renderParagraph.js +3 -3
- package/dist/layout-painter/renderTable.js +9 -12
- package/dist/layout-painter/renderTextBox.js +2 -2
- package/dist/layout-painter/sdtBoundary.js +3 -2
- package/dist/paged-layout/blockGeometry.js +3 -2
- package/dist/paged-layout/editorScrollRoot.d.ts +9 -0
- package/dist/paged-layout/editorScrollRoot.js +10 -1
- package/dist/paged-layout/rangeProjection.js +5 -4
- package/dist/paged-layout/scrollToPmPosition.js +3 -3
- package/dist/paged-layout/selectionViewportRect.d.ts +6 -0
- package/dist/paged-layout/selectionViewportRect.js +8 -2
- package/dist/prosemirror/attrs/index.js +1 -0
- package/dist/prosemirror/commands/comments.d.ts +5 -2
- package/dist/prosemirror/commands/comments.js +88 -8
- package/dist/prosemirror/commentRecords.d.ts +137 -0
- package/dist/prosemirror/commentRecords.js +400 -0
- package/dist/prosemirror/conversion/fromProseDoc.js +9 -3
- package/dist/prosemirror/conversion/index.d.ts +1 -1
- package/dist/prosemirror/conversion/toProseDoc.d.ts +13 -4
- package/dist/prosemirror/conversion/toProseDoc.js +126 -38
- package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.d.ts +22 -0
- package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.js +61 -32
- package/dist/prosemirror/extensions/marks/CommentExtension.js +3 -1
- package/dist/prosemirror/extensions/nodes/CommentReferenceExtension.js +3 -1
- package/dist/prosemirror/index.d.ts +1 -1
- package/dist/prosemirror/nativeSelection.d.ts +33 -0
- package/dist/prosemirror/nativeSelection.js +74 -0
- package/dist/prosemirror/numberedRefFields.d.ts +2 -0
- package/dist/prosemirror/numberedRefFields.js +16 -5
- package/dist/prosemirror/paragraphMarkJoin.d.ts +6 -8
- package/dist/prosemirror/paragraphMarkJoin.js +155 -16
- package/dist/prosemirror/plugins/contentControlWidgets.js +2 -2
- package/dist/prosemirror/plugins/documentNumbering.js +33 -14
- package/dist/prosemirror/plugins/suggestionMode.js +13 -1
- package/dist/prosemirror/runIdentityAcrossRevisions.d.ts +23 -1
- package/dist/prosemirror/runIdentityAcrossRevisions.js +57 -8
- package/dist/prosemirror/schema/marks.d.ts +7 -1
- package/dist/prosemirror/storyListNumbering.js +7 -2
- package/dist/prosemirror/tableResize.d.ts +10 -9
- package/dist/prosemirror/tableResize.js +60 -49
- package/dist/prosemirror/textInput.d.ts +30 -1
- package/dist/prosemirror/textInput.js +144 -17
- package/dist/prosemirror/utils/visualLineNavigation.js +20 -18
- package/dist/prosemirror/validation.d.ts +19 -0
- package/dist/prosemirror/validation.js +78 -5
- package/dist/render-dom/HeaderFooterSelectionOverlay.js +5 -4
- package/dist/render-dom/RenderedDomContext.js +7 -6
- package/dist/types/canonicalCapabilities.d.ts +12 -11
- package/dist/types/canonicalCapabilities.js +12 -13
- package/dist/utils/findMatchView.js +4 -3
- package/dist/utils/formatToStyle.d.ts +1 -1
- package/dist/utils/mergeDocumentContent.js +2 -2
- package/dist/utils/paintedPositions.d.ts +60 -0
- package/dist/utils/paintedPositions.js +101 -0
- package/package.json +2 -3
|
@@ -3,7 +3,7 @@ import { resolveColorValueToHex } from "../../docx/drawingUtils.js";
|
|
|
3
3
|
import { isInlineSdtContent, isTrackedChangeWrapperChild } from "../../docx/inlineWrapperContent.js";
|
|
4
4
|
import { listRenderingDefinitionsMatch, resolveListRenderingDefinition } from "../../docx/listRendering.js";
|
|
5
5
|
import { getCachedNumberingMap } from "../../docx/numberingParser.js";
|
|
6
|
-
import { PROSE_PARAGRAPH_SOURCE_CONTRACT_ATTR, createProseParagraphWithPropertySource, getDocumentParagraphPropertySourceContract, paragraphFormattingWithAuthoredIndentation,
|
|
6
|
+
import { PROSE_PARAGRAPH_SOURCE_CONTRACT_ATTR, createProseParagraphWithPropertySource, getDocumentParagraphPropertySourceContract, paragraphFormattingWithAuthoredIndentation, paragraphPropertySourceStamp, paragraphPropertySourceStampMatches, proseParagraphAttrsWithoutPropertySource, recreateProseNodeWithParagraphPropertySource, transportTableCellsWithParagraphPropertySources } from "../../docx/paragraphPropertySource.js";
|
|
7
7
|
import { visitInlineContentSlots, visitInlineContentSlotsInContent } from "../../docx/paragraphTraversal.js";
|
|
8
8
|
import { isBaselineVertAlign } from "../../docx/runParser.js";
|
|
9
9
|
import { replayableShapeAlternateContent } from "../../docx/shapeAlternateContent.js";
|
|
@@ -50,7 +50,7 @@ import { paragraphIndentationFromFormatting } from "../paragraphIndentation.js";
|
|
|
50
50
|
import { lineSpacingProvenanceFromSpacing } from "../paragraphSpacing.js";
|
|
51
51
|
import { isRunContentProjectionNode } from "../runContentProjection.js";
|
|
52
52
|
import { RUN_IDENTITY_MARK_NAME, hasRunIdentityPayload, runIdentityAttrs } from "../runIdentity.js";
|
|
53
|
-
import { continueSourceCarrierIdentitiesAcrossInsertedParagraphMarks, continueSourceCarrierIdentitiesAcrossRevisions } from "../runIdentityAcrossRevisions.js";
|
|
53
|
+
import { CarrierContinuationCache, continueSourceCarrierIdentitiesAcrossInsertedParagraphMarks, continueSourceCarrierIdentitiesAcrossRevisions, continueSourceCarrierIdentitiesKeeping } from "../runIdentityAcrossRevisions.js";
|
|
54
54
|
import { getParagraphMarkSuppressionOverrides, hasDirectRunFormatting, isParagraphMarkSuppressionEligible, resolveParagraphInheritedRunFormatting, stripParagraphMarkOnlyFormatting, suppressParagraphMarkFormatting } from "../runStyleFormatting.js";
|
|
55
55
|
import { schema } from "../schema/index.js";
|
|
56
56
|
import { PRESERVED_XML_LEVELS } from "../schema/nodes.js";
|
|
@@ -59,7 +59,7 @@ import { listIndentationProvenancePatch } from "../styles/resolvedStyleAttrs.js"
|
|
|
59
59
|
import { cascadeStyleTextFormatting } from "../styles/styleToggleCascade.js";
|
|
60
60
|
import { tableCellStyleRegions, tableRowBand } from "../styles/tableStyleRegions.js";
|
|
61
61
|
import { canCarryTrackedRunMark, trackedRunInlineAtomDisposition } from "../trackedRunInlineAtoms.js";
|
|
62
|
-
import { assertValidProseMirrorDocument } from "../validation.js";
|
|
62
|
+
import { assertValidProseMirrorDocument, assertValidProseMirrorDocumentKeeping } from "../validation.js";
|
|
63
63
|
import { resolveEffectiveTableCellFormatting } from "./effectiveTableCellFormatting.js";
|
|
64
64
|
import { HYPHEN_ELEMENT_MARK_NAME, HYPHEN_TEXT_CARRIERS } from "./hyphenTextCarriers.js";
|
|
65
65
|
import { createMarkInterner } from "./markInterner.js";
|
|
@@ -122,28 +122,12 @@ const createNoteReferenceOccurrenceAllocator = () => {
|
|
|
122
122
|
return () => `source-note:${index++}`;
|
|
123
123
|
};
|
|
124
124
|
/**
|
|
125
|
-
*
|
|
126
|
-
*
|
|
127
|
-
*
|
|
125
|
+
* Every bookmark boundary of a story's blocks, in the document order the
|
|
126
|
+
* conversion meets them, across every editable inline wrapper. Each endpoint
|
|
127
|
+
* is converted at its own structural position, so a range may start outside
|
|
128
|
+
* a hyperlink and end inside it (or the inverse).
|
|
128
129
|
*/
|
|
129
|
-
const
|
|
130
|
-
const counts = /* @__PURE__ */ new Map();
|
|
131
|
-
let position = 0;
|
|
132
|
-
const countBoundary = (id, type) => {
|
|
133
|
-
const count = counts.get(id) ?? {
|
|
134
|
-
starts: 0,
|
|
135
|
-
ends: 0
|
|
136
|
-
};
|
|
137
|
-
if (type === "start") {
|
|
138
|
-
count.starts += 1;
|
|
139
|
-
count.firstStart ??= position;
|
|
140
|
-
} else {
|
|
141
|
-
count.ends += 1;
|
|
142
|
-
count.firstEnd ??= position;
|
|
143
|
-
}
|
|
144
|
-
position += 1;
|
|
145
|
-
counts.set(id, count);
|
|
146
|
-
};
|
|
130
|
+
const visitBookmarkBoundaries = (blocks, countBoundary) => {
|
|
147
131
|
const countMarkersWhere = (markers, stands) => {
|
|
148
132
|
for (const { index, marker } of markers ?? []) if (stands(index)) countBoundary(marker.id, marker.type === "bookmarkStart" ? "start" : "end");
|
|
149
133
|
};
|
|
@@ -255,6 +239,26 @@ const collectPairedBookmarkIds = (blocks) => {
|
|
|
255
239
|
}
|
|
256
240
|
};
|
|
257
241
|
visitBlocks(blocks);
|
|
242
|
+
};
|
|
243
|
+
/** The bookmarks of a story's blocks whose one start opens before their one end. */
|
|
244
|
+
const collectPairedBookmarkIds = (blocks) => {
|
|
245
|
+
const counts = /* @__PURE__ */ new Map();
|
|
246
|
+
let position = 0;
|
|
247
|
+
visitBookmarkBoundaries(blocks, (id, type) => {
|
|
248
|
+
const count = counts.get(id) ?? {
|
|
249
|
+
starts: 0,
|
|
250
|
+
ends: 0
|
|
251
|
+
};
|
|
252
|
+
if (type === "start") {
|
|
253
|
+
count.starts += 1;
|
|
254
|
+
count.firstStart ??= position;
|
|
255
|
+
} else {
|
|
256
|
+
count.ends += 1;
|
|
257
|
+
count.firstEnd ??= position;
|
|
258
|
+
}
|
|
259
|
+
position += 1;
|
|
260
|
+
counts.set(id, count);
|
|
261
|
+
});
|
|
258
262
|
return new Set([...counts].flatMap(([id, count]) => count.starts === 1 && count.ends === 1 && count.firstStart !== void 0 && count.firstEnd !== void 0 && count.firstStart < count.firstEnd ? [id] : []));
|
|
259
263
|
};
|
|
260
264
|
/** A membership whose answers a block's conversion read, recorded to check later. */
|
|
@@ -285,7 +289,48 @@ const advanceStory = (reads, state) => {
|
|
|
285
289
|
for (const id of reads.openCommentIds.end) state.openCommentIds.add(id);
|
|
286
290
|
};
|
|
287
291
|
const setReadsOf = (set) => ({ answers: set.answers });
|
|
288
|
-
|
|
292
|
+
/**
|
|
293
|
+
* Where the facts kept outside the fields of a block's paragraphs stood, a
|
|
294
|
+
* table's in document order: a converted block is reused only while none of
|
|
295
|
+
* them changed.
|
|
296
|
+
*/
|
|
297
|
+
const blockSourceStamps = (block) => {
|
|
298
|
+
const stamps = [];
|
|
299
|
+
const visit = (blocks) => {
|
|
300
|
+
for (const child of blocks) switch (child.type) {
|
|
301
|
+
case "paragraph":
|
|
302
|
+
stamps.push({
|
|
303
|
+
paragraph: child,
|
|
304
|
+
stamp: paragraphPropertySourceStamp(child)
|
|
305
|
+
});
|
|
306
|
+
break;
|
|
307
|
+
case "table":
|
|
308
|
+
for (const row of child.rows) for (const cell of row.cells) visit(cell.content);
|
|
309
|
+
break;
|
|
310
|
+
case "blockSdt":
|
|
311
|
+
case "blockCustomXml":
|
|
312
|
+
visit(child.content);
|
|
313
|
+
break;
|
|
314
|
+
case "preservedBlock":
|
|
315
|
+
case "bookmarkStart":
|
|
316
|
+
case "bookmarkEnd":
|
|
317
|
+
case "commentRangeStart":
|
|
318
|
+
case "commentRangeEnd":
|
|
319
|
+
case "moveFromRangeStart":
|
|
320
|
+
case "moveFromRangeEnd":
|
|
321
|
+
case "moveToRangeStart":
|
|
322
|
+
case "moveToRangeEnd": break;
|
|
323
|
+
default: return child;
|
|
324
|
+
}
|
|
325
|
+
};
|
|
326
|
+
visit([block]);
|
|
327
|
+
return stamps;
|
|
328
|
+
};
|
|
329
|
+
/**
|
|
330
|
+
* Whether no fact kept outside the fields of the paragraphs of `block`, the
|
|
331
|
+
* same object the stamps were read from, changed since.
|
|
332
|
+
*/
|
|
333
|
+
const sourceStampsHold = (stamps) => stamps.every(({ paragraph, stamp }) => paragraphPropertySourceStampMatches(paragraph, stamp));
|
|
289
334
|
/**
|
|
290
335
|
* Converted blocks kept across projections of one story.
|
|
291
336
|
*
|
|
@@ -298,6 +343,10 @@ const sameState = (left, right) => left.length === right.length && left.every((v
|
|
|
298
343
|
*/
|
|
299
344
|
var ProjectionBlockCache = class {
|
|
300
345
|
salt = newTextBoxGroupSalt();
|
|
346
|
+
/** The story's top-level blocks as the last pass continued them. */
|
|
347
|
+
carriers = new CarrierContinuationCache();
|
|
348
|
+
/** The last story document that passed validation. */
|
|
349
|
+
validated;
|
|
301
350
|
inputs;
|
|
302
351
|
context;
|
|
303
352
|
blocks = /* @__PURE__ */ new WeakMap();
|
|
@@ -322,10 +371,9 @@ var ProjectionBlockCache = class {
|
|
|
322
371
|
* The nodes of `paragraph` from the story state it starts at, reused when
|
|
323
372
|
* every story fact its last conversion read still holds, else converted.
|
|
324
373
|
*/
|
|
325
|
-
|
|
326
|
-
const known = this.blocks.get(
|
|
327
|
-
|
|
328
|
-
if (known !== void 0 && sameState(known.sourceState, sourceState) && storyReadsHold(known.reads, state)) {
|
|
374
|
+
block(block, state, convert) {
|
|
375
|
+
const known = this.blocks.get(block);
|
|
376
|
+
if (known !== void 0 && sourceStampsHold(known.sourceStamps) && storyReadsHold(known.reads, state)) {
|
|
329
377
|
advanceStory(known.reads, state);
|
|
330
378
|
return known.nodes;
|
|
331
379
|
}
|
|
@@ -370,7 +418,7 @@ var ProjectionBlockCache = class {
|
|
|
370
418
|
warnPageBreakProjection: context.warnPageBreakProjection,
|
|
371
419
|
createMark: context.createMark,
|
|
372
420
|
...story
|
|
373
|
-
}
|
|
421
|
+
});
|
|
374
422
|
const saltMark = `"${this.salt}:`;
|
|
375
423
|
const reads = {
|
|
376
424
|
textBoxGroups: {
|
|
@@ -386,10 +434,10 @@ var ProjectionBlockCache = class {
|
|
|
386
434
|
end: [...state.openCommentIds]
|
|
387
435
|
}
|
|
388
436
|
};
|
|
389
|
-
this.blocks.set(
|
|
437
|
+
this.blocks.set(block, {
|
|
390
438
|
nodes,
|
|
391
439
|
reads,
|
|
392
|
-
|
|
440
|
+
sourceStamps: blockSourceStamps(block)
|
|
393
441
|
});
|
|
394
442
|
return nodes;
|
|
395
443
|
}
|
|
@@ -443,13 +491,13 @@ function toProseDoc(document, options) {
|
|
|
443
491
|
out.push(...cache === void 0 ? convertParagraphWithTextBoxes(block, styleResolver, {
|
|
444
492
|
textBoxGroupId: conversionContext.nextTextBoxGroupId(),
|
|
445
493
|
context: conversionContext
|
|
446
|
-
}) : cache.
|
|
447
|
-
textBoxGroupId,
|
|
494
|
+
}) : cache.block(block, story, (context) => convertParagraphWithTextBoxes(block, styleResolver, {
|
|
495
|
+
textBoxGroupId: context.nextTextBoxGroupId(),
|
|
448
496
|
context
|
|
449
497
|
})));
|
|
450
498
|
break;
|
|
451
499
|
case "table":
|
|
452
|
-
out.push(convertTable(block, styleResolver, conversionContext));
|
|
500
|
+
out.push(...cache === void 0 ? [convertTable(block, styleResolver, conversionContext)] : cache.block(block, story, (context) => [convertTable(block, styleResolver, context)]));
|
|
453
501
|
break;
|
|
454
502
|
case "blockSdt":
|
|
455
503
|
out.push(convertBlockSdt(block, convertBodyBlocks));
|
|
@@ -480,6 +528,8 @@ function toProseDoc(document, options) {
|
|
|
480
528
|
};
|
|
481
529
|
nodes.push(...convertBodyBlocks(paragraphs));
|
|
482
530
|
if (nodes.length === 0) nodes.push(schema.node("paragraph", {}, []));
|
|
531
|
+
const suggestedComments = suggestedCommentIdsOf(document);
|
|
532
|
+
if (suggestedComments.size > 0) for (const [index, node] of nodes.entries()) nodes[index] = withSuggestedCommentMarks(node, suggestedComments);
|
|
483
533
|
const finalSectionStart = document.package.document.sections?.at(-1)?.properties.sectionStart ?? null;
|
|
484
534
|
const adjustLineHeightInTable = document.package.settings?.adjustLineHeightInTable === true;
|
|
485
535
|
const doNotUseIndentAsNumberingTabStop = document.package.settings?.doNotUseIndentAsNumberingTabStop === true;
|
|
@@ -488,10 +538,48 @@ function toProseDoc(document, options) {
|
|
|
488
538
|
_finalSectionStart: finalSectionStart,
|
|
489
539
|
_adjustLineHeightInTable: adjustLineHeightInTable,
|
|
490
540
|
_doNotUseIndentAsNumberingTabStop: doNotUseIndentAsNumberingTabStop
|
|
491
|
-
}, [...continueSourceCarrierIdentitiesAcrossInsertedParagraphMarks(nodes)]));
|
|
492
|
-
|
|
541
|
+
}, [...cache === void 0 ? continueSourceCarrierIdentitiesAcrossInsertedParagraphMarks(nodes) : continueSourceCarrierIdentitiesKeeping(nodes, cache.carriers)]));
|
|
542
|
+
const invalid = "Document conversion produced an invalid ProseMirror document";
|
|
543
|
+
if (cache === void 0) assertValidProseMirrorDocument(pmDoc, invalid);
|
|
544
|
+
else cache.validated = assertValidProseMirrorDocumentKeeping(pmDoc, invalid, cache.validated);
|
|
493
545
|
return pmDoc;
|
|
494
546
|
}
|
|
547
|
+
/** The comments pending suggestions propose, by comment id. */
|
|
548
|
+
const suggestedCommentIdsOf = (document) => {
|
|
549
|
+
const suggested = /* @__PURE__ */ new Map();
|
|
550
|
+
for (const comment of document.package.document.comments ?? []) if (comment.suggestionId !== void 0) suggested.set(comment.id, comment.suggestionId);
|
|
551
|
+
return suggested;
|
|
552
|
+
};
|
|
553
|
+
/**
|
|
554
|
+
* Give the comment marks of a proposed comment the suggestion that proposes
|
|
555
|
+
* it, so the editor lists, accepts and rejects the comment with it. Nodes
|
|
556
|
+
* with nothing to stamp are returned as they are.
|
|
557
|
+
*/
|
|
558
|
+
const withSuggestedCommentMarks = (node, suggested) => {
|
|
559
|
+
let marks = node.marks;
|
|
560
|
+
for (const mark of node.marks) {
|
|
561
|
+
if (mark.type.name !== "comment") continue;
|
|
562
|
+
const suggestionId = suggested.get(mark.attrs["commentId"]);
|
|
563
|
+
if (suggestionId === void 0 || mark.attrs["suggestionId"] === suggestionId) continue;
|
|
564
|
+
marks = node.type.schema.mark(mark.type, {
|
|
565
|
+
...mark.attrs,
|
|
566
|
+
suggestionId
|
|
567
|
+
}).addToSet(mark.removeFromSet(marks));
|
|
568
|
+
}
|
|
569
|
+
if (node.childCount === 0) return marks === node.marks ? node : node.mark(marks);
|
|
570
|
+
const children = [];
|
|
571
|
+
let changed = marks !== node.marks;
|
|
572
|
+
for (let index = 0; index < node.childCount; index += 1) {
|
|
573
|
+
const child = node.child(index);
|
|
574
|
+
const stamped = withSuggestedCommentMarks(child, suggested);
|
|
575
|
+
changed ||= stamped !== child;
|
|
576
|
+
children.push(stamped);
|
|
577
|
+
}
|
|
578
|
+
return changed ? recreateProseNodeWithParagraphPropertySource(node, {
|
|
579
|
+
content: children,
|
|
580
|
+
marks
|
|
581
|
+
}) : node;
|
|
582
|
+
};
|
|
495
583
|
/**
|
|
496
584
|
* Carry a block folio does not model into the editor as a zero-width node.
|
|
497
585
|
*
|
|
@@ -3265,4 +3353,4 @@ function footnoteToProseDoc(content, options) {
|
|
|
3265
3353
|
function createEmptyDoc() {
|
|
3266
3354
|
return schema.node("doc", null, [schema.node("paragraph", {}, [])]);
|
|
3267
3355
|
}
|
|
3268
|
-
export { ProjectionBlockCache, collectPairedBookmarkIds, createEmptyDoc, footnoteToProseDoc, headerFooterToProseDoc, hostParagraphAttrs, standaloneTableCellToProseMirror, toProseDoc };
|
|
3356
|
+
export { ProjectionBlockCache, collectPairedBookmarkIds, createEmptyDoc, footnoteToProseDoc, headerFooterToProseDoc, hostParagraphAttrs, standaloneTableCellToProseMirror, toProseDoc, visitBookmarkBoundaries };
|
|
@@ -35,6 +35,28 @@ type InternalParagraphChangeTrackerState = ParagraphChangeTrackerState & {
|
|
|
35
35
|
/** The section records themselves, by identity. */
|
|
36
36
|
sectionRecords: ReadonlySet<document_d_exports.SectionProperties>;
|
|
37
37
|
};
|
|
38
|
+
type DocumentStructureCounts = {
|
|
39
|
+
blockStructureFingerprint: string;
|
|
40
|
+
sectionRecords: ReadonlySet<document_d_exports.SectionProperties>;
|
|
41
|
+
paragraphs: number;
|
|
42
|
+
/**
|
|
43
|
+
* Distinct section records the paragraphs carry, which is the number of
|
|
44
|
+
* `w:sectPr` the package states for them. A split copies a node's attrs, so
|
|
45
|
+
* both halves of a split section-ending paragraph hold one record until the
|
|
46
|
+
* from-leg keeps it on the trailing half: one section, not two.
|
|
47
|
+
*/
|
|
48
|
+
sectionEndpoints: number;
|
|
49
|
+
sectionEndpointFingerprint: string;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* Count the structural values the tracker compares for every transaction.
|
|
53
|
+
*
|
|
54
|
+
* Each top-level block's records are kept for the block node, so a keystroke
|
|
55
|
+
* recomputes only the block it changed. The fingerprint joins the blocks'
|
|
56
|
+
* records in order: two documents' fingerprints are equal exactly when their
|
|
57
|
+
* full record lists (every block and nested block with its path) are.
|
|
58
|
+
*/
|
|
59
|
+
export declare function countDocumentStructure(doc: Node): DocumentStructureCounts;
|
|
38
60
|
export declare function createParagraphChangeTrackerPlugin(): Plugin<InternalParagraphChangeTrackerState>;
|
|
39
61
|
/**
|
|
40
62
|
* Get the change tracker state from an EditorState
|
|
@@ -30,43 +30,72 @@ const isRemovedSectionReference = (value) => typeof value === "object" && value
|
|
|
30
30
|
const isTrackedSectionEndpointRemoval = (value) => typeof value === "object" && value !== null && "type" in value && value.type === "tracked-section-endpoint-removal" && "sourceParagraphEndpointCount" in value && typeof value.sourceParagraphEndpointCount === "number" && Number.isSafeInteger(value.sourceParagraphEndpointCount) && "expectedParagraphEndpointCount" in value && typeof value.expectedParagraphEndpointCount === "number" && Number.isSafeInteger(value.expectedParagraphEndpointCount) && value.sourceParagraphEndpointCount > value.expectedParagraphEndpointCount && value.expectedParagraphEndpointCount >= 0 && "sourceEndpointFingerprint" in value && typeof value.sourceEndpointFingerprint === "string" && "expectedEndpointFingerprint" in value && typeof value.expectedEndpointFingerprint === "string" && "removedReferences" in value && Array.isArray(value.removedReferences) && value.removedReferences.every(isRemovedSectionReference);
|
|
31
31
|
const isTrackedSectionEndpointRemovalMeta = (value) => typeof value === "object" && value !== null && "type" in value && value.type === "tracked-section-endpoint-removal-meta" && "authorization" in value && isTrackedSectionEndpointRemoval(value.authorization);
|
|
32
32
|
const isSectionEditMeta = (value) => typeof value === "object" && value !== null && "type" in value && value.type === "section-edit-meta" && "authorization" in value && (value.authorization === null || isTrackedSectionEndpointRemoval(value.authorization)) && "expectedEndpointFingerprint" in value && typeof value.expectedEndpointFingerprint === "string";
|
|
33
|
-
|
|
33
|
+
const blockStructures = /* @__PURE__ */ new WeakMap();
|
|
34
|
+
const relativePath = (parentPath, index) => parentPath.length === 0 ? `${index}` : `${parentPath}.${index}`;
|
|
35
|
+
const blockStructureOf = (block) => {
|
|
36
|
+
const cached = blockStructures.get(block);
|
|
37
|
+
if (cached) return cached;
|
|
38
|
+
const records = [];
|
|
39
|
+
const endpoints = [];
|
|
40
|
+
let paragraphs = 0;
|
|
41
|
+
const visit = (node, path) => {
|
|
42
|
+
records.push(node.type.name === "paragraph" ? [
|
|
43
|
+
path,
|
|
44
|
+
node.type.name,
|
|
45
|
+
node.attrs["paraId"] ?? null
|
|
46
|
+
] : [
|
|
47
|
+
path,
|
|
48
|
+
node.type.name,
|
|
49
|
+
canonicalJson(node.attrs)
|
|
50
|
+
]);
|
|
51
|
+
if (node.type.name === "paragraph") {
|
|
52
|
+
paragraphs++;
|
|
53
|
+
const sectionProperties = sectionPropertiesOf(node);
|
|
54
|
+
if (sectionProperties !== null) endpoints.push({
|
|
55
|
+
path,
|
|
56
|
+
paraId: node.attrs["paraId"] ?? null,
|
|
57
|
+
sectionProperties
|
|
58
|
+
});
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
node.forEach((child, _offset, index) => visit(child, relativePath(path, index)));
|
|
62
|
+
};
|
|
63
|
+
visit(block, "");
|
|
64
|
+
const structure = {
|
|
65
|
+
records: JSON.stringify(records),
|
|
66
|
+
paragraphs,
|
|
67
|
+
endpoints
|
|
68
|
+
};
|
|
69
|
+
blockStructures.set(block, structure);
|
|
70
|
+
return structure;
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* Count the structural values the tracker compares for every transaction.
|
|
74
|
+
*
|
|
75
|
+
* Each top-level block's records are kept for the block node, so a keystroke
|
|
76
|
+
* recomputes only the block it changed. The fingerprint joins the blocks'
|
|
77
|
+
* records in order: two documents' fingerprints are equal exactly when their
|
|
78
|
+
* full record lists (every block and nested block with its path) are.
|
|
79
|
+
*/
|
|
34
80
|
function countDocumentStructure(doc) {
|
|
35
81
|
let paragraphs = 0;
|
|
36
82
|
const sectionRecords = /* @__PURE__ */ new Set();
|
|
37
83
|
const blockRecords = [];
|
|
38
84
|
const endpointRecords = [];
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
path
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
if (node.type.name === "paragraph") {
|
|
52
|
-
paragraphs++;
|
|
53
|
-
const sectionProperties = sectionPropertiesOf(node);
|
|
54
|
-
if (sectionProperties !== null) {
|
|
55
|
-
sectionRecords.add(sectionProperties);
|
|
56
|
-
endpointRecords.push({
|
|
57
|
-
path: parentPath.length === 0 ? `${index}` : `${parentPath}.${index}`,
|
|
58
|
-
paraId: node.attrs["paraId"] ?? null,
|
|
59
|
-
sectionProperties
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
if (node.childCount > 0) visit(node, path);
|
|
65
|
-
});
|
|
66
|
-
};
|
|
67
|
-
visit(doc, "");
|
|
85
|
+
doc.forEach((block, _offset, index) => {
|
|
86
|
+
const structure = blockStructureOf(block);
|
|
87
|
+
blockRecords.push(structure.records);
|
|
88
|
+
paragraphs += structure.paragraphs;
|
|
89
|
+
for (const endpoint of structure.endpoints) {
|
|
90
|
+
sectionRecords.add(endpoint.sectionProperties);
|
|
91
|
+
endpointRecords.push({
|
|
92
|
+
...endpoint,
|
|
93
|
+
path: endpoint.path.length === 0 ? `${index}` : `${index}.${endpoint.path}`
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
});
|
|
68
97
|
return {
|
|
69
|
-
blockStructureFingerprint:
|
|
98
|
+
blockStructureFingerprint: blockRecords.join(""),
|
|
70
99
|
sectionRecords,
|
|
71
100
|
paragraphs,
|
|
72
101
|
sectionEndpoints: sectionRecords.size,
|
|
@@ -543,4 +572,4 @@ const ParagraphChangeTrackerExtension = createExtension({
|
|
|
543
572
|
return { plugins: [createParagraphChangeTrackerPlugin()] };
|
|
544
573
|
}
|
|
545
574
|
});
|
|
546
|
-
export { ParagraphChangeTrackerExtension, clearTrackedChanges, createParagraphChangeTrackerPlugin, getChangeTrackerState, getChangedParagraphIds, getTrackedSectionEndpointRemoval, hasStructuralChanges, hasUntrackedChanges, ignoreTrackedChanges, markChangedParagraphRanges, markPackageChange, markSectionBreakRemoval, markStructuralChange, markTrackedSectionEndpointRemoval, paragraphChangeTrackerKey, repackWithEditorSectionRemovals };
|
|
575
|
+
export { ParagraphChangeTrackerExtension, clearTrackedChanges, countDocumentStructure, createParagraphChangeTrackerPlugin, getChangeTrackerState, getChangedParagraphIds, getTrackedSectionEndpointRemoval, hasStructuralChanges, hasUntrackedChanges, ignoreTrackedChanges, markChangedParagraphRanges, markPackageChange, markSectionBreakRemoval, markStructuralChange, markTrackedSectionEndpointRemoval, paragraphChangeTrackerKey, repackWithEditorSectionRemovals };
|
|
@@ -16,7 +16,9 @@ const CommentExtension = createMarkExtension({
|
|
|
16
16
|
/** Comment ID (matches Comment.id) */
|
|
17
17
|
commentId: { default: 0 },
|
|
18
18
|
/** Shown at a point comment's reference; see `CommentAttrs.point`. */
|
|
19
|
-
point: { default: false }
|
|
19
|
+
point: { default: false },
|
|
20
|
+
/** The pending suggestion proposing it; see `CommentAttrs.suggestionId`. */
|
|
21
|
+
suggestionId: { default: null }
|
|
20
22
|
},
|
|
21
23
|
inclusive: false,
|
|
22
24
|
parseDOM: [{
|
|
@@ -2,7 +2,7 @@ import { readCommentReferenceAttrs } from "../../commentReferenceAttrs.js";
|
|
|
2
2
|
import { COMMENT_REFERENCE_NODE_NAME, resolveCommentReferences } from "../../commentReferenceIntegrity.js";
|
|
3
3
|
import { createNodeExtension } from "../create.js";
|
|
4
4
|
import { INLINE_ANCHOR_DOM_STYLE } from "./inlineAnchorDom.js";
|
|
5
|
-
import { Plugin } from "prosemirror-state";
|
|
5
|
+
import { Plugin, TextSelection } from "prosemirror-state";
|
|
6
6
|
// src/prosemirror/extensions/nodes/CommentReferenceExtension.ts
|
|
7
7
|
/** Zero-width `w:commentReference`: where a comment's visible mark is painted. */
|
|
8
8
|
const CommentReferenceExtension = createNodeExtension({
|
|
@@ -41,6 +41,8 @@ const CommentReferenceExtension = createNodeExtension({
|
|
|
41
41
|
if (!resolution) return null;
|
|
42
42
|
const transaction = newState.tr;
|
|
43
43
|
for (const step of resolution.steps) transaction.step(step);
|
|
44
|
+
const { selection } = newState;
|
|
45
|
+
if (selection instanceof TextSelection && selection.empty) transaction.setSelection(TextSelection.create(transaction.doc, transaction.mapping.map(selection.head, -1)));
|
|
44
46
|
return transaction;
|
|
45
47
|
} })] })
|
|
46
48
|
});
|
|
@@ -2,6 +2,7 @@ import { FontFamilyAttrs, FontSizeAttrs, HyperlinkAttrs, TextColorAttrs, Underli
|
|
|
2
2
|
import { ImageAttrs, ParagraphAttrs } from "./schema/nodes.js";
|
|
3
3
|
import { ResolvedParagraphStyle, StyleResolver, createStyleResolver } from "./styles/styleResolver.js";
|
|
4
4
|
import { clearFormatting, getMarkAttr, isMarkActive } from "./extensions/marks/markUtils.js";
|
|
5
|
+
import { ProseMirrorDocumentValidationIssue, ValidateProseMirrorDocumentResult, assertValidProseMirrorDocument, formatProseMirrorDocumentIssues, validateProseMirrorDocument } from "./validation.js";
|
|
5
6
|
import { ToProseDocOptions, createEmptyDoc, toProseDoc } from "./conversion/toProseDoc.js";
|
|
6
7
|
import { schema, singletonManager } from "./schema/index.js";
|
|
7
8
|
import { getParagraphAlignment, getParagraphBidi, getStyleId } from "./extensions/core/ParagraphExtension.js";
|
|
@@ -18,7 +19,6 @@ import { addColumnLeft, addColumnRight, addRowAbove, addRowBelow, applyTableStyl
|
|
|
18
19
|
import { insertPageBreak } from "./commands/pageBreak.js";
|
|
19
20
|
import "./commands/index.js";
|
|
20
21
|
import { FromProseDocOptions, ProjectionReuse, fromProseDoc, updateDocumentContent } from "./conversion/fromProseDoc.js";
|
|
21
|
-
import { ProseMirrorDocumentValidationIssue, ValidateProseMirrorDocumentResult, assertValidProseMirrorDocument, formatProseMirrorDocumentIssues, validateProseMirrorDocument } from "./validation.js";
|
|
22
22
|
import "./conversion/index.js";
|
|
23
23
|
import { ActiveListState, ListState, ListType, NO_LIST_STATE, isInListState, listStateLevel, resolveListState, sameListState } from "./listState.js";
|
|
24
24
|
import { SelectionChangeCallback, SelectionContext, createSelectionTrackerPlugin, extractSelectionContext, getSelectionContext, selectionTrackerKey } from "./plugins/selectionTracker.js";
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Plugin } from "prosemirror-state";
|
|
2
|
+
import { EditorView } from "prosemirror-view";
|
|
3
|
+
/** Take the caret the browser shows into the editor state before input. */
|
|
4
|
+
export declare const adoptNativeSelection: (view: EditorView) => void;
|
|
5
|
+
/** Whether a keydown belongs to an input method composition. */
|
|
6
|
+
export declare const isCompositionKeyDown: (event: KeyboardEvent) => boolean;
|
|
7
|
+
/**
|
|
8
|
+
* Where a browser caret for the editor's collapsed selection belongs: in the
|
|
9
|
+
* text before it, or at a paragraph's start in the first text. ProseMirror
|
|
10
|
+
* treats the end of one text node and the start of the next run as one
|
|
11
|
+
* position, but the browser types and composes into the node it holds.
|
|
12
|
+
* `null` when the selection is not a caret in text.
|
|
13
|
+
*/
|
|
14
|
+
export declare const textCaretOf: (view: EditorView) => {
|
|
15
|
+
node: Node;
|
|
16
|
+
offset: number;
|
|
17
|
+
} | null;
|
|
18
|
+
/**
|
|
19
|
+
* Sets the browser's selection again after an update that changed the
|
|
20
|
+
* document, unless it was just set where it belongs.
|
|
21
|
+
*
|
|
22
|
+
* ProseMirror leaves a DOM selection it reads as the same position, such as
|
|
23
|
+
* the start of the next run instead of the end of the previous one, or a
|
|
24
|
+
* caret beside a redrawn paragraph. Chromium's input method then resolves the
|
|
25
|
+
* next composition's start from the start of the editable content, and it
|
|
26
|
+
* picks the text node to compose into before `compositionstart`, so the
|
|
27
|
+
* text in progress shows elsewhere. A caret goes into the text before it,
|
|
28
|
+
* where a composition continues the run it follows.
|
|
29
|
+
*
|
|
30
|
+
* A selection the browser or ProseMirror set since the last update has a new
|
|
31
|
+
* range; one left alone keeps its range and is set again.
|
|
32
|
+
*/
|
|
33
|
+
export declare const createNativeSelectionRefreshPlugin: () => Plugin;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { Plugin, TextSelection } from "prosemirror-state";
|
|
2
|
+
// src/prosemirror/nativeSelection.ts
|
|
3
|
+
/** Take the caret the browser shows into the editor state before input. */
|
|
4
|
+
const adoptNativeSelection = (view) => {
|
|
5
|
+
if (view.composing || view.isDestroyed) return;
|
|
6
|
+
const { selection } = view.state;
|
|
7
|
+
const native = view.dom.ownerDocument.getSelection();
|
|
8
|
+
if (!(selection instanceof TextSelection || native?.isCollapsed === true) || !native?.anchorNode || !native.focusNode || !view.dom.contains(native.anchorNode) || !view.dom.contains(native.focusNode)) return;
|
|
9
|
+
const anchor = view.posAtDOM(native.anchorNode, native.anchorOffset);
|
|
10
|
+
const head = view.posAtDOM(native.focusNode, native.focusOffset);
|
|
11
|
+
if (anchor === selection.anchor && head === selection.head) return;
|
|
12
|
+
const { doc } = view.state;
|
|
13
|
+
if (!doc.resolve(anchor).parent.inlineContent || !doc.resolve(head).parent.inlineContent) return;
|
|
14
|
+
view.dispatch(view.state.tr.setSelection(TextSelection.create(doc, anchor, head)));
|
|
15
|
+
};
|
|
16
|
+
/** Whether a keydown belongs to an input method composition. */
|
|
17
|
+
const isCompositionKeyDown = (event) => event.isComposing || event.key === "Process";
|
|
18
|
+
const nativeRange = (view) => {
|
|
19
|
+
const native = view.dom.ownerDocument.getSelection();
|
|
20
|
+
return native !== null && native.rangeCount > 0 ? native.getRangeAt(0) : null;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Where a browser caret for the editor's collapsed selection belongs: in the
|
|
24
|
+
* text before it, or at a paragraph's start in the first text. ProseMirror
|
|
25
|
+
* treats the end of one text node and the start of the next run as one
|
|
26
|
+
* position, but the browser types and composes into the node it holds.
|
|
27
|
+
* `null` when the selection is not a caret in text.
|
|
28
|
+
*/
|
|
29
|
+
const textCaretOf = (view) => {
|
|
30
|
+
const { selection } = view.state;
|
|
31
|
+
if (!selection.empty) return null;
|
|
32
|
+
const before = view.domAtPos(selection.from, -1);
|
|
33
|
+
const { node, offset } = before.node.nodeType === before.node.TEXT_NODE ? before : view.domAtPos(selection.from, 1);
|
|
34
|
+
return node.nodeType === node.TEXT_NODE ? {
|
|
35
|
+
node,
|
|
36
|
+
offset
|
|
37
|
+
} : null;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Sets the browser's selection again after an update that changed the
|
|
41
|
+
* document, unless it was just set where it belongs.
|
|
42
|
+
*
|
|
43
|
+
* ProseMirror leaves a DOM selection it reads as the same position, such as
|
|
44
|
+
* the start of the next run instead of the end of the previous one, or a
|
|
45
|
+
* caret beside a redrawn paragraph. Chromium's input method then resolves the
|
|
46
|
+
* next composition's start from the start of the editable content, and it
|
|
47
|
+
* picks the text node to compose into before `compositionstart`, so the
|
|
48
|
+
* text in progress shows elsewhere. A caret goes into the text before it,
|
|
49
|
+
* where a composition continues the run it follows.
|
|
50
|
+
*
|
|
51
|
+
* A selection the browser or ProseMirror set since the last update has a new
|
|
52
|
+
* range; one left alone keeps its range and is set again.
|
|
53
|
+
*/
|
|
54
|
+
const createNativeSelectionRefreshPlugin = () => new Plugin({ view: (view) => {
|
|
55
|
+
let held = nativeRange(view);
|
|
56
|
+
return { update: (current, previous) => {
|
|
57
|
+
const native = current.dom.ownerDocument.getSelection();
|
|
58
|
+
const range = nativeRange(current);
|
|
59
|
+
if (native !== null && range !== null && current.state.doc !== previous.doc && !current.composing && current.hasFocus() && current.dom.contains(range.startContainer) && current.dom.contains(range.endContainer)) {
|
|
60
|
+
const stale = range === held;
|
|
61
|
+
const caret = native.isCollapsed ? textCaretOf(current) : null;
|
|
62
|
+
const { anchorNode, anchorOffset, focusNode, focusOffset } = native;
|
|
63
|
+
if (caret !== null && (stale || anchorNode !== caret.node || anchorOffset !== caret.offset)) {
|
|
64
|
+
native.removeAllRanges();
|
|
65
|
+
native.collapse(caret.node, caret.offset);
|
|
66
|
+
} else if (caret === null && stale && anchorNode && focusNode) {
|
|
67
|
+
native.removeAllRanges();
|
|
68
|
+
native.setBaseAndExtent(anchorNode, anchorOffset, focusNode, focusOffset);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
held = nativeRange(current);
|
|
72
|
+
} };
|
|
73
|
+
} });
|
|
74
|
+
export { adoptNativeSelection, createNativeSelectionRefreshPlugin, isCompositionKeyDown, textCaretOf };
|
|
@@ -19,4 +19,6 @@ export declare function stampNumberedRefFieldBaselines(doc: Node): Node;
|
|
|
19
19
|
* Unsupported or uncalibrated fields are absent from the returned map and retain their cache.
|
|
20
20
|
*/
|
|
21
21
|
export declare function resolveNumberedRefFields(doc: Node, options?: NumberedRefResolutionOptions): ReadonlyMap<Node, string>;
|
|
22
|
+
/** The resolution visiting every node, skipping none: the reference for the skip. */
|
|
23
|
+
export declare function resolveNumberedRefFieldsVisitingEveryNode(doc: Node, options?: NumberedRefResolutionOptions): ReadonlyMap<Node, string>;
|
|
22
24
|
export {};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { resolveListTemplateWithComponents } from "../docx/listTemplate.js";
|
|
2
|
+
import { subtreeHolds } from "../internal/subtreeHolds.js";
|
|
2
3
|
import { expectFieldAttrs, expectParagraphAttrs } from "./attrs/index.js";
|
|
3
4
|
import { expectBookmarkBoundaryAttrs } from "./bookmarkBoundaryAttrs.js";
|
|
4
5
|
import { advanceVisibleListMarker, createListCounterState } from "./listMarker.js";
|
|
@@ -164,10 +165,13 @@ function relativeNumber(target, source) {
|
|
|
164
165
|
function normalizeCachedResult(value) {
|
|
165
166
|
return value.replaceAll("\xA0", " ").replace(/\s+/gu, " ").trim();
|
|
166
167
|
}
|
|
167
|
-
|
|
168
|
+
const isFieldNode = (node) => node.type.name === "field" || node.type.name === "structuredField";
|
|
169
|
+
const holdsField = subtreeHolds(isFieldNode);
|
|
170
|
+
function collectNumberedRefCandidates(doc, options, skip) {
|
|
168
171
|
const fields = [];
|
|
169
172
|
doc.descendants((node) => {
|
|
170
|
-
if (node
|
|
173
|
+
if (skip(node)) return false;
|
|
174
|
+
if (!isFieldNode(node)) return true;
|
|
171
175
|
if (fields.length >= MAX_NUMBERED_REF_FIELDS) return false;
|
|
172
176
|
const attrs = expectFieldAttrs(node);
|
|
173
177
|
if (attrs.fieldType !== "REF" || attrs.fldLock) return false;
|
|
@@ -254,7 +258,7 @@ const mapDocument = (node, transform) => {
|
|
|
254
258
|
function stampNumberedRefFieldBaselines(doc) {
|
|
255
259
|
const baselines = /* @__PURE__ */ new WeakMap();
|
|
256
260
|
let hasBaselines = false;
|
|
257
|
-
for (const candidate of collectNumberedRefCandidates(doc, {})) if (isCalibratedCandidate(candidate)) {
|
|
261
|
+
for (const candidate of collectNumberedRefCandidates(doc, {}, (node) => !holdsField(node))) if (isCalibratedCandidate(candidate)) {
|
|
258
262
|
baselines.set(candidate.node, candidate.cached);
|
|
259
263
|
hasBaselines = true;
|
|
260
264
|
}
|
|
@@ -273,8 +277,15 @@ function stampNumberedRefFieldBaselines(doc) {
|
|
|
273
277
|
* Unsupported or uncalibrated fields are absent from the returned map and retain their cache.
|
|
274
278
|
*/
|
|
275
279
|
function resolveNumberedRefFields(doc, options = {}) {
|
|
280
|
+
return resolveCandidates(collectNumberedRefCandidates(doc, options, (node) => !holdsField(node)));
|
|
281
|
+
}
|
|
282
|
+
/** The resolution visiting every node, skipping none: the reference for the skip. */
|
|
283
|
+
function resolveNumberedRefFieldsVisitingEveryNode(doc, options = {}) {
|
|
284
|
+
return resolveCandidates(collectNumberedRefCandidates(doc, options, () => false));
|
|
285
|
+
}
|
|
286
|
+
function resolveCandidates(candidates) {
|
|
276
287
|
const results = /* @__PURE__ */ new Map();
|
|
277
|
-
for (const candidate of
|
|
288
|
+
for (const candidate of candidates) if (isCalibratedCandidate(candidate)) results.set(candidate.node, candidate.value);
|
|
278
289
|
return results;
|
|
279
290
|
}
|
|
280
|
-
export { parseNumberedRefInstruction, resolveNumberedRefFields, stampNumberedRefFieldBaselines };
|
|
291
|
+
export { parseNumberedRefInstruction, resolveNumberedRefFields, resolveNumberedRefFieldsVisitingEveryNode, stampNumberedRefFieldBaselines };
|
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
import { RunStyleResolver } from "./runStyleFormatting.js";
|
|
2
2
|
import { Node } from "prosemirror-model";
|
|
3
3
|
import { Transaction } from "prosemirror-state";
|
|
4
|
+
/** The attributes a join decides, for a check that the schema adds none undecided. */
|
|
5
|
+
export declare const JOINED_PARAGRAPH_ATTR_NAMES: readonly string[];
|
|
4
6
|
/**
|
|
5
|
-
* The attrs the paragraph a join leaves
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* A split copies the paragraph's attrs onto both halves, and a save writes
|
|
9
|
-
* the sessions on the first half only, the first record in document order.
|
|
10
|
-
* Rejecting the split removes that first half, so the paragraph left names
|
|
11
|
-
* none of them, live as after a save.
|
|
7
|
+
* The attrs of the paragraph a join leaves, each by its rule in
|
|
8
|
+
* `JOINED_PARAGRAPH_ATTRS`. `between` is the inline size the join places
|
|
9
|
+
* between the two paragraphs' content.
|
|
12
10
|
*/
|
|
13
|
-
export declare const joinedParagraphAttrs: (paragraph: Node, next: Node) => Node["attrs"];
|
|
11
|
+
export declare const joinedParagraphAttrs: (paragraph: Node, next: Node, between?: number) => Node["attrs"];
|
|
14
12
|
type JoinAtParagraphMarkOptions = {
|
|
15
13
|
tr: Transaction;
|
|
16
14
|
/** Position of the paragraph whose mark goes. */
|