@stll/folio-core 0.54.2 → 0.56.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/apply.js +185 -33
- package/dist/ai-edits/headless.js +3 -2
- package/dist/ai-edits/types.d.ts +7 -1
- package/dist/compare/compare.js +1 -0
- package/dist/compare/content-types.d.ts +3 -15
- package/dist/compare/reproducible-package.d.ts +0 -17
- package/dist/compare/reproducible-package.js +12 -18
- package/dist/controller/canonicalClipboard.d.ts +23 -0
- package/dist/controller/canonicalClipboard.js +476 -0
- package/dist/controller/canonicalClipboardResources.d.ts +21 -0
- package/dist/controller/canonicalClipboardResources.js +382 -0
- package/dist/controller/canonicalComposition.d.ts +53 -0
- package/dist/controller/canonicalComposition.js +296 -0
- package/dist/controller/canonicalInlineProjection.d.ts +113 -0
- package/dist/controller/canonicalInlineProjection.js +393 -0
- package/dist/controller/canonicalInput.d.ts +54 -0
- package/dist/controller/canonicalInput.js +377 -0
- package/dist/controller/canonicalInputTimer.d.ts +7 -0
- package/dist/controller/canonicalInputTimer.js +11 -0
- package/dist/controller/canonicalOperations.d.ts +22 -0
- package/dist/controller/canonicalOperations.js +85 -0
- package/dist/controller/canonicalPublicOperations.d.ts +48 -0
- package/dist/controller/canonicalPublicOperations.js +556 -0
- package/dist/controller/canonicalReview.d.ts +12 -0
- package/dist/controller/canonicalReview.js +19 -0
- package/dist/controller/canonicalSession.d.ts +167 -0
- package/dist/controller/canonicalSession.js +1186 -0
- package/dist/controller/canonicalStoryEditor.d.ts +36 -0
- package/dist/controller/canonicalStoryEditor.js +87 -0
- package/dist/controller/canonicalStructure.d.ts +16 -0
- package/dist/controller/canonicalStructure.js +322 -0
- package/dist/controller/canonicalTocSelection.d.ts +11 -0
- package/dist/controller/canonicalTocSelection.js +43 -0
- package/dist/controller/folioEditor.d.ts +3 -10
- package/dist/controller/folioEditor.js +14 -4
- package/dist/controller/headerFooterEditorManager.d.ts +5 -0
- package/dist/controller/headerFooterEditorManager.js +72 -3
- package/dist/controller/hiddenEditorApi.d.ts +45 -0
- package/dist/controller/hiddenEditorApi.js +29 -8
- package/dist/controller/hiddenEditorManager.d.ts +13 -2
- package/dist/controller/hiddenEditorManager.js +639 -31
- package/dist/controller/layoutPipeline.d.ts +1 -1
- package/dist/controller/layoutPipeline.js +2 -0
- package/dist/controller/noteEditorManager.d.ts +5 -0
- package/dist/controller/noteEditorManager.js +114 -15
- package/dist/document-operations.d.ts +8 -1
- package/dist/document-operations.js +6 -4
- package/dist/docx/attributeRemainder.js +1 -0
- package/dist/docx/blockPlainText.d.ts +1 -1
- package/dist/docx/blockPlainText.js +11 -3
- package/dist/docx/canonicalResourceSave.d.ts +16 -0
- package/dist/docx/canonicalResourceSave.js +27 -0
- package/dist/docx/canonicalSave.d.ts +29 -0
- package/dist/docx/canonicalSave.js +101 -0
- package/dist/docx/canonicalSessionInput.d.ts +11 -0
- package/dist/docx/canonicalSessionInput.js +27 -0
- package/dist/docx/canonicalStoryRepack.d.ts +10 -0
- package/dist/docx/canonicalStoryRepack.js +74 -0
- package/dist/docx/contentTypeRegistry.d.ts +8 -0
- package/dist/docx/contentTypeRegistry.js +64 -0
- package/dist/docx/documentParser.d.ts +1 -13
- package/dist/docx/documentParser.js +1 -47
- package/dist/docx/ensureParaIds.d.ts +7 -1
- package/dist/docx/ensureParaIds.js +173 -215
- package/dist/docx/foldedListNumberFields.d.ts +85 -0
- package/dist/docx/foldedListNumberFields.js +267 -0
- package/dist/docx/footnoteParser.d.ts +1 -11
- package/dist/docx/footnoteParser.js +1 -16
- package/dist/docx/headerFooterParser.d.ts +1 -9
- package/dist/docx/headerFooterParser.js +1 -12
- package/dist/docx/headerFooterVerbatim.d.ts +39 -1
- package/dist/docx/headerFooterVerbatim.js +173 -2
- package/dist/docx/imageParser.d.ts +13 -1
- package/dist/docx/imageParser.js +20 -11
- package/dist/docx/metadataPrivacy.js +6 -1
- package/dist/docx/noteIds.d.ts +5 -0
- package/dist/docx/noteIds.js +6 -2
- package/dist/docx/noteReferenceMark.d.ts +3 -1
- package/dist/docx/noteReferenceMark.js +15 -14
- package/dist/docx/numberingParser.d.ts +3 -1
- package/dist/docx/numberingParser.js +17 -3
- package/dist/docx/packageParts.d.ts +3 -1
- package/dist/docx/packageParts.js +74 -19
- package/dist/docx/paragraphMarkPropertyPresence.d.ts +9 -0
- package/dist/docx/paragraphMarkPropertyPresence.js +21 -0
- package/dist/docx/paragraphParser.js +101 -53
- package/dist/docx/paragraphPropertySource.d.ts +15 -1
- package/dist/docx/paragraphPropertySource.js +77 -22
- package/dist/docx/parser.js +3 -1
- package/dist/docx/removeHeaderFooterParts.js +17 -6
- package/dist/docx/reviewHistoryNamespace.d.ts +4 -0
- package/dist/docx/reviewHistoryNamespace.js +4 -0
- package/dist/docx/reviewResolutionProvenance.d.ts +25 -0
- package/dist/docx/reviewResolutionProvenance.js +153 -0
- package/dist/docx/rezip.d.ts +54 -6
- package/dist/docx/rezip.js +835 -257
- package/dist/docx/runConsolidator.d.ts +2 -58
- package/dist/docx/runConsolidator.js +3 -175
- package/dist/docx/runParser.d.ts +2 -1
- package/dist/docx/runParser.js +156 -116
- package/dist/docx/saveDiagnostics.d.ts +22 -0
- package/dist/docx/saveDiagnostics.js +0 -0
- package/dist/docx/selectiveSave.d.ts +3 -1
- package/dist/docx/selectiveSave.js +36 -4
- package/dist/docx/selectiveXmlPatch.d.ts +16 -8
- package/dist/docx/selectiveXmlPatch.js +81 -7
- package/dist/docx/serializer/documentSerializer.d.ts +9 -2
- package/dist/docx/serializer/documentSerializer.js +29 -10
- package/dist/docx/serializer/headerFooterSerializer.d.ts +5 -1
- package/dist/docx/serializer/headerFooterSerializer.js +19 -11
- package/dist/docx/serializer/noteSerializer.d.ts +2 -2
- package/dist/docx/serializer/noteSerializer.js +24 -8
- package/dist/docx/serializer/paragraphSerializer.js +41 -4
- package/dist/docx/serializer/partNamespaces.js +2 -1
- package/dist/docx/serializer/runSerializer.js +3 -1
- package/dist/docx/server/applyDocxXmlPatchProposal.js +14 -9
- package/dist/docx/settingsHeaderFooterUpdate.d.ts +5 -0
- package/dist/docx/settingsHeaderFooterUpdate.js +90 -0
- package/dist/docx/settingsParser.d.ts +1 -2
- package/dist/docx/settingsParser.js +5 -6
- package/dist/docx/storyBlockReplay.d.ts +31 -0
- package/dist/docx/storyBlockReplay.js +471 -0
- package/dist/docx/storyPlainText.d.ts +20 -0
- package/dist/docx/storyPlainText.js +23 -0
- package/dist/docx/streamingXmlParser.d.ts +22 -1
- package/dist/docx/streamingXmlParser.js +49 -3
- package/dist/docx/structuralXmlPatch.js +18 -23
- package/dist/docx/styleParser.d.ts +5 -1
- package/dist/docx/styleParser.js +1 -1
- package/dist/docx/tableParser.d.ts +1 -8
- package/dist/docx/tableParser.js +1 -28
- package/dist/docx/textBoxParser.d.ts +1 -5
- package/dist/docx/textBoxParser.js +1 -20
- package/dist/docx/unzip.js +6 -1
- package/dist/docx/verbatimCapture.d.ts +3 -1
- package/dist/docx/verbatimCapture.js +49 -6
- package/dist/i18n/messages/ar.gen.d.ts +5 -0
- package/dist/i18n/messages/ar.gen.js +656 -0
- package/dist/i18n/messages/cs.gen.d.ts +5 -0
- package/dist/i18n/messages/cs.gen.js +656 -0
- package/dist/i18n/messages/de.gen.d.ts +5 -0
- package/dist/i18n/messages/de.gen.js +656 -0
- package/dist/i18n/messages/en.gen.d.ts +5 -0
- package/dist/i18n/messages/en.gen.js +656 -0
- package/dist/i18n/messages/es.gen.d.ts +5 -0
- package/dist/i18n/messages/es.gen.js +656 -0
- package/dist/i18n/messages/et.gen.d.ts +5 -0
- package/dist/i18n/messages/et.gen.js +656 -0
- package/dist/i18n/messages/fr.gen.d.ts +5 -0
- package/dist/i18n/messages/fr.gen.js +656 -0
- package/dist/i18n/messages/he.gen.d.ts +5 -0
- package/dist/i18n/messages/he.gen.js +656 -0
- package/dist/i18n/messages/hi.gen.d.ts +5 -0
- package/dist/i18n/messages/hi.gen.js +656 -0
- package/dist/i18n/messages/hu.gen.d.ts +5 -0
- package/dist/i18n/messages/hu.gen.js +656 -0
- package/dist/i18n/messages/locales.d.ts +5 -0
- package/dist/i18n/messages/locales.js +22 -0
- package/dist/i18n/messages/lt.gen.d.ts +5 -0
- package/dist/i18n/messages/lt.gen.js +656 -0
- package/dist/i18n/messages/lv.gen.d.ts +5 -0
- package/dist/i18n/messages/lv.gen.js +656 -0
- package/dist/i18n/messages/pl.gen.d.ts +5 -0
- package/dist/i18n/messages/pl.gen.js +656 -0
- package/dist/i18n/messages/pt-BR.gen.d.ts +5 -0
- package/dist/i18n/messages/pt-BR.gen.js +656 -0
- package/dist/i18n/messages/sk.gen.d.ts +5 -0
- package/dist/i18n/messages/sk.gen.js +656 -0
- package/dist/i18n/messages/tr.gen.d.ts +5 -0
- package/dist/i18n/messages/tr.gen.js +656 -0
- package/dist/i18n/messages/zh-CN.gen.d.ts +5 -0
- package/dist/i18n/messages/zh-CN.gen.js +656 -0
- package/dist/i18n/messages.d.ts +2 -3
- package/dist/i18n/messages.js +1 -19
- package/dist/internal/acceptedBlockProjection.d.ts +12 -0
- package/dist/internal/acceptedBlockProjection.js +45 -0
- package/dist/internal/noteMarkerAttrs.d.ts +8 -0
- package/dist/internal/noteMarkerAttrs.js +16 -0
- package/dist/internal/pageBreakRunSourceDescendantIndex.js +1 -0
- package/dist/internal/prosemirrorAttrBoundary.d.ts +21 -0
- package/dist/internal/prosemirrorAttrBoundary.js +50 -0
- package/dist/layout-bridge/convert/footnoteLayout.d.ts +1 -0
- package/dist/layout-bridge/convert/footnoteLayout.js +3 -3
- package/dist/layout-bridge/convert/headerFooterLayout.d.ts +1 -0
- package/dist/layout-bridge/convert/headerFooterLayout.js +1 -0
- package/dist/layout-bridge/convert/noteReferences.d.ts +1 -3
- package/dist/layout-bridge/convert/noteReferences.js +1 -6
- package/dist/layout-bridge/convert/paragraphRuns.js +2 -4
- package/dist/layout-bridge/convert/toFlowBlocks.d.ts +2 -2
- package/dist/layout-bridge/convert/toFlowBlocks.js +2 -2
- package/dist/managers/DocumentLoaderManager.d.ts +1 -0
- package/dist/managers/DocumentLoaderManager.js +9 -1
- package/dist/markdown/escape.d.ts +3 -1
- package/dist/markdown/escape.js +9 -2
- package/dist/markdown/renderBlock.js +20 -121
- package/dist/markdown/renderParagraph.js +13 -15
- package/dist/markdown/renderRuns.d.ts +7 -1
- package/dist/markdown/renderRuns.js +35 -15
- package/dist/markdown/renderTable.js +2 -0
- package/dist/markdown/types.d.ts +3 -9
- package/dist/prosemirror/attrs/index.d.ts +2 -12
- package/dist/prosemirror/attrs/index.js +22 -48
- package/dist/prosemirror/bookmarkBoundaryAttrs.d.ts +2 -1
- package/dist/prosemirror/canonicalCommands.d.ts +121 -0
- package/dist/prosemirror/canonicalCommands.js +35 -0
- package/dist/prosemirror/canonicalSelectionRange.d.ts +9 -0
- package/dist/prosemirror/canonicalSelectionRange.js +15 -0
- package/dist/prosemirror/clipboardIntent.d.ts +7 -0
- package/dist/prosemirror/clipboardIntent.js +9 -0
- package/dist/prosemirror/commands/pageBreak.js +15 -1
- package/dist/prosemirror/commands/pastePlainText.js +2 -1
- package/dist/prosemirror/commentReferenceAttrs.d.ts +2 -1
- package/dist/prosemirror/conversion/fromProseDoc.js +91 -19
- package/dist/prosemirror/conversion/hyphenTextCarriers.d.ts +8 -0
- package/dist/prosemirror/conversion/hyphenTextCarriers.js +8 -0
- package/dist/prosemirror/conversion/listRenderingDefinition.d.ts +6 -0
- package/dist/prosemirror/conversion/listRenderingDefinition.js +97 -0
- package/dist/prosemirror/conversion/toProseDoc.d.ts +11 -4
- package/dist/prosemirror/conversion/toProseDoc.js +55 -14
- package/dist/prosemirror/executeEditorCommand.d.ts +11 -0
- package/dist/prosemirror/executeEditorCommand.js +26 -0
- package/dist/prosemirror/extensions/StarterKit.js +2 -0
- package/dist/prosemirror/extensions/core/ParagraphExtension.js +88 -48
- package/dist/prosemirror/extensions/features/ListExtension.js +18 -5
- package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.d.ts +5 -2
- package/dist/prosemirror/extensions/features/ParagraphChangeTrackerExtension.js +13 -1
- package/dist/prosemirror/extensions/marks/HyperlinkExtension.js +56 -28
- package/dist/prosemirror/extensions/marks/TextColorExtension.js +3 -2
- package/dist/prosemirror/extensions/marks/TrackedChangeExtensions.js +2 -0
- package/dist/prosemirror/extensions/marks/markUtils.js +72 -8
- package/dist/prosemirror/extensions/nodes/NoteMarkerExtension.d.ts +6 -0
- package/dist/prosemirror/extensions/nodes/NoteMarkerExtension.js +36 -0
- package/dist/prosemirror/extensions/nodes/PreservedXmlExtension.js +4 -2
- package/dist/prosemirror/insertOperations.js +2 -1
- package/dist/prosemirror/listMarker.d.ts +1 -0
- package/dist/prosemirror/listMarker.js +16 -7
- package/dist/prosemirror/listNumbering.js +26 -5
- package/dist/prosemirror/listRenderingAttrs.d.ts +1 -0
- package/dist/prosemirror/listRenderingAttrs.js +3 -0
- package/dist/prosemirror/markupViewNotes.js +3 -2
- package/dist/prosemirror/moveRangeBoundaryAttrs.d.ts +2 -1
- package/dist/prosemirror/noteReferenceReview.js +5 -3
- package/dist/prosemirror/paragraphPropertyCarry.d.ts +7 -1
- package/dist/prosemirror/paragraphPropertyCarry.js +8 -3
- package/dist/prosemirror/plugins/suggestionMode.js +57 -7
- package/dist/prosemirror/rangeAnchorAttrs.d.ts +2 -1
- package/dist/prosemirror/runFormattingFromMarks.d.ts +4 -1
- package/dist/prosemirror/runFormattingFromMarks.js +15 -1
- package/dist/prosemirror/runFormattingInlineCarriers.d.ts +2 -1
- package/dist/prosemirror/runFormattingInlineCarriers.js +4 -1
- package/dist/prosemirror/schema/marks.d.ts +2 -0
- package/dist/prosemirror/schema/nodes.d.ts +10 -2
- package/dist/prosemirror/textBoxAnchorAttrs.d.ts +2 -1
- package/dist/prosemirror/textInput.js +5 -1
- package/dist/prosemirror/trackedRevisionPath.js +2 -1
- package/dist/prosemirror/trackedRunInlineAtoms.d.ts +1 -0
- package/dist/prosemirror/trackedRunInlineAtoms.js +1 -0
- package/dist/prosemirror/validation.js +4 -0
- package/dist/types/canonicalCapabilities.d.ts +215 -0
- package/dist/types/canonicalCapabilities.js +212 -0
- package/dist/types/canonicalSave.d.ts +11 -0
- package/dist/types/canonicalSave.js +0 -0
- package/dist/types/content.d.ts +2 -2
- package/dist/types/docxSerialization.d.ts +14 -0
- package/dist/types/docxSerialization.js +7 -0
- package/dist/utils/createDocument.js +2 -2
- package/package.json +16 -4
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { CanonicalGap } from "../types/canonicalCapabilities.js";
|
|
2
|
+
import { HiddenEditorApi } from "./hiddenEditorApi.js";
|
|
3
|
+
import { Transaction } from "prosemirror-state";
|
|
4
|
+
import { EditorView } from "prosemirror-view";
|
|
5
|
+
import { OpStory } from "@stll/docx-core/ops";
|
|
6
|
+
//#region src/controller/canonicalStoryEditor.d.ts
|
|
7
|
+
type CanonicalStoryEditorOptions = {
|
|
8
|
+
story: OpStory;
|
|
9
|
+
getView: () => EditorView;
|
|
10
|
+
getApi: () => HiddenEditorApi | null;
|
|
11
|
+
enabled: () => boolean;
|
|
12
|
+
onSelectionChange: () => void;
|
|
13
|
+
onRefusal: ((reason: string, gap: CanonicalGap) => void) | undefined;
|
|
14
|
+
};
|
|
15
|
+
/** Secondary views compile classified native input into the shared Document journal. */
|
|
16
|
+
declare const createCanonicalStoryEditor: ({ story, getView, getApi, enabled, onRefusal, onSelectionChange }: CanonicalStoryEditorOptions) => {
|
|
17
|
+
dispatch: (transaction: Transaction) => boolean;
|
|
18
|
+
props: {
|
|
19
|
+
handleKeyDown: (view: EditorView, event: KeyboardEvent) => boolean;
|
|
20
|
+
handleTextInput: (view: EditorView, from: number, to: number, text: string) => boolean;
|
|
21
|
+
handleDOMEvents: {
|
|
22
|
+
keydown: (view: EditorView, event: KeyboardEvent) => boolean;
|
|
23
|
+
beforeinput: (view: EditorView, event: InputEvent) => boolean;
|
|
24
|
+
mousedown: (view: EditorView) => boolean;
|
|
25
|
+
compositionstart: (view: EditorView) => boolean;
|
|
26
|
+
compositionend: (view: EditorView) => boolean;
|
|
27
|
+
input: (view: EditorView) => boolean;
|
|
28
|
+
blur: (view: EditorView) => boolean;
|
|
29
|
+
paste: (view: EditorView, event: ClipboardEvent) => boolean;
|
|
30
|
+
cut: (view: EditorView, event: ClipboardEvent) => boolean;
|
|
31
|
+
drop: (view: EditorView, event: Event) => boolean;
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
//#endregion
|
|
36
|
+
export { createCanonicalStoryEditor };
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { CANONICAL_GAP } from "../types/canonicalCapabilities.js";
|
|
2
|
+
import { createCanonicalInputBoundary } from "./canonicalInput.js";
|
|
3
|
+
import { CanonicalSessionError } from "./canonicalSession.js";
|
|
4
|
+
//#region src/controller/canonicalStoryEditor.ts
|
|
5
|
+
/** Secondary views compile classified native input into the shared Document journal. */
|
|
6
|
+
const createCanonicalStoryEditor = ({ story, getView, getApi, enabled, onRefusal, onSelectionChange }) => {
|
|
7
|
+
const refuse = (reason) => {
|
|
8
|
+
const gap = CANONICAL_GAP.dispatch;
|
|
9
|
+
const message = reason;
|
|
10
|
+
if (onRefusal) onRefusal(message, gap);
|
|
11
|
+
else throw new CanonicalSessionError({
|
|
12
|
+
gap,
|
|
13
|
+
message,
|
|
14
|
+
reason: "refused"
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
const history = (direction) => {
|
|
18
|
+
const view = getView();
|
|
19
|
+
const accepted = getApi()?.applyCanonicalStoryHistory({
|
|
20
|
+
view,
|
|
21
|
+
story,
|
|
22
|
+
direction
|
|
23
|
+
}) ?? false;
|
|
24
|
+
if (accepted && !view.isDestroyed) onSelectionChange();
|
|
25
|
+
return accepted;
|
|
26
|
+
};
|
|
27
|
+
const boundary = createCanonicalInputBoundary({
|
|
28
|
+
breakUndoGroup: () => {
|
|
29
|
+
getApi()?.updateCanonicalInputLifecycle("breakUndoGroup");
|
|
30
|
+
},
|
|
31
|
+
beginComposition: () => getApi()?.updateCanonicalInputLifecycle("beginComposition") ?? false,
|
|
32
|
+
endComposition: () => {
|
|
33
|
+
getApi()?.updateCanonicalInputLifecycle("endComposition");
|
|
34
|
+
},
|
|
35
|
+
replace: (intent) => {
|
|
36
|
+
const view = getView();
|
|
37
|
+
if (getApi()?.replaceCanonicalStoryText({
|
|
38
|
+
view,
|
|
39
|
+
story,
|
|
40
|
+
intent
|
|
41
|
+
}) && !view.isDestroyed) onSelectionChange();
|
|
42
|
+
},
|
|
43
|
+
undo: () => history("undo"),
|
|
44
|
+
redo: () => history("redo"),
|
|
45
|
+
refuse
|
|
46
|
+
});
|
|
47
|
+
return {
|
|
48
|
+
dispatch: (transaction) => {
|
|
49
|
+
if (!enabled()) return false;
|
|
50
|
+
const view = getView();
|
|
51
|
+
if (transaction.docChanged) {
|
|
52
|
+
if (boundary.acceptComposition(view, transaction)) return true;
|
|
53
|
+
if (!boundary.commitNativeProposal(view, transaction)) boundary.refuseNativeMutation(view);
|
|
54
|
+
view.updateState(view.state);
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
if (transaction.selectionSet && !boundary.isComposing) getApi()?.updateCanonicalInputLifecycle("breakUndoGroup");
|
|
58
|
+
const applied = view.state.applyTransaction(transaction);
|
|
59
|
+
if (!applied.state.doc.eq(view.state.doc)) {
|
|
60
|
+
refuse("A plugin attempted an unclassified canonical story mutation.");
|
|
61
|
+
view.updateState(view.state);
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
view.updateState(applied.state);
|
|
65
|
+
if (applied.transactions.some((step) => step.selectionSet)) onSelectionChange();
|
|
66
|
+
return true;
|
|
67
|
+
},
|
|
68
|
+
props: {
|
|
69
|
+
handleKeyDown: (view, event) => enabled() && boundary.handleKeyDown(view, event),
|
|
70
|
+
handleTextInput: (view, from, to, text) => enabled() && boundary.handleTextInput(view, from, to, text),
|
|
71
|
+
handleDOMEvents: {
|
|
72
|
+
keydown: (view, event) => enabled() && boundary.handleDOMEvents.keydown(view, event),
|
|
73
|
+
beforeinput: (view, event) => enabled() && boundary.handleDOMEvents.beforeinput(view, event),
|
|
74
|
+
mousedown: (view) => enabled() && boundary.handleDOMEvents.mousedown(view),
|
|
75
|
+
compositionstart: (view) => enabled() && boundary.handleDOMEvents.compositionstart(view),
|
|
76
|
+
compositionend: (view) => enabled() && boundary.handleDOMEvents.compositionend(view),
|
|
77
|
+
input: (view) => enabled() && boundary.handleDOMEvents.input(view),
|
|
78
|
+
blur: (view) => enabled() && boundary.handleDOMEvents.blur(view),
|
|
79
|
+
paste: (view, event) => enabled() && boundary.handleDOMEvents.paste(view, event),
|
|
80
|
+
cut: (view, event) => enabled() && boundary.handleDOMEvents.cut(view, event),
|
|
81
|
+
drop: (view, event) => enabled() && boundary.handleDOMEvents.drop(view, event)
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
};
|
|
86
|
+
//#endregion
|
|
87
|
+
export { createCanonicalStoryEditor };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { CanonicalCommit, CanonicalSession, CanonicalSessionError } from "./canonicalSession.js";
|
|
2
|
+
import { CanonicalCommandIntent } from "../prosemirror/canonicalCommands.js";
|
|
3
|
+
import { EditorState } from "prosemirror-state";
|
|
4
|
+
import { Result } from "better-result";
|
|
5
|
+
//#region src/controller/canonicalStructure.d.ts
|
|
6
|
+
/** Toolbar meanings enter the same operation journal as native input. */
|
|
7
|
+
declare const prepareCanonicalCommands: (session: CanonicalSession, state: EditorState, commands: readonly CanonicalCommandIntent[]) => Result<CanonicalCommit, CanonicalSessionError>;
|
|
8
|
+
type CanonicalAutoformatInput = {
|
|
9
|
+
from: number;
|
|
10
|
+
to: number;
|
|
11
|
+
text: string;
|
|
12
|
+
};
|
|
13
|
+
/** Rules compile their replacement and paragraph change as one atomic edit. */
|
|
14
|
+
declare const prepareCanonicalAutoformat: (session: CanonicalSession, state: EditorState, { from, to, text }: CanonicalAutoformatInput) => Result<CanonicalCommit, CanonicalSessionError> | undefined;
|
|
15
|
+
//#endregion
|
|
16
|
+
export { prepareCanonicalAutoformat, prepareCanonicalCommands };
|
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
import { BUILT_IN_STYLE_NAME, createBuiltInStyleIndex } from "../docx/builtInStyles.js";
|
|
2
|
+
import { getCachedNumberingMap, numberingLevelUsesBulletMarker } from "../docx/numberingParser.js";
|
|
3
|
+
import { listRequestsForMarker } from "../prosemirror/listAutoformatMarkers.js";
|
|
4
|
+
import { CANONICAL_GAP } from "../types/canonicalCapabilities.js";
|
|
5
|
+
import { collectHeadings } from "../utils/headingCollector.js";
|
|
6
|
+
import { CanonicalSessionError } from "./canonicalSession.js";
|
|
7
|
+
import { Result } from "better-result";
|
|
8
|
+
import { headingOutlineLevel, paragraphNumberingReference } from "@stll/docx-core/model";
|
|
9
|
+
import { OP_STORIES } from "@stll/docx-core/ops";
|
|
10
|
+
//#region src/controller/canonicalStructure.ts
|
|
11
|
+
const DEFAULT_TOC_PAGE_WIDTH_TWIPS = 12240;
|
|
12
|
+
const DEFAULT_TOC_MARGIN_TWIPS = 1440;
|
|
13
|
+
const refuse = (message) => Result.err(new CanonicalSessionError({
|
|
14
|
+
gap: CANONICAL_GAP.commands,
|
|
15
|
+
message,
|
|
16
|
+
reason: "refused"
|
|
17
|
+
}));
|
|
18
|
+
const selectedParagraphs = (session, state) => {
|
|
19
|
+
const ids = /* @__PURE__ */ new Set();
|
|
20
|
+
state.doc.nodesBetween(state.selection.from, state.selection.to, (node) => {
|
|
21
|
+
if (node.type.name === "paragraph" && typeof node.attrs["paraId"] === "string") ids.add(node.attrs["paraId"]);
|
|
22
|
+
});
|
|
23
|
+
return session.document.package.document.content.filter((paragraph) => paragraph.type === "paragraph" && ids.has(paragraph.paraId ?? ""));
|
|
24
|
+
};
|
|
25
|
+
const numberingIntent = (session, paragraphs, request) => {
|
|
26
|
+
const definitions = session.document.package.numbering;
|
|
27
|
+
const map = definitions === void 0 ? void 0 : getCachedNumberingMap(definitions);
|
|
28
|
+
const body = session.document.package.document.content;
|
|
29
|
+
const first = body.findIndex((item) => item === paragraphs.at(0));
|
|
30
|
+
const last = body.findIndex((item) => item === paragraphs.at(-1));
|
|
31
|
+
const neighbor = [first > 0 ? body.at(first - 1) : void 0, body.at(last + 1)].find((item) => {
|
|
32
|
+
if (item?.type !== "paragraph" || item.formatting?.numPr?.kind !== "reference" || item.formatting.numPrFromStyle !== void 0) return false;
|
|
33
|
+
const level = map?.getLevel(item.formatting.numPr.numId, item.formatting.numPr.ilvl ?? 0);
|
|
34
|
+
if (level == null || numberingLevelUsesBulletMarker(level) !== (request.kind === "bullet")) return false;
|
|
35
|
+
return request.format === void 0 || level.numFmt === request.format.numFmt && level.lvlText === request.format.lvlText;
|
|
36
|
+
});
|
|
37
|
+
let numId;
|
|
38
|
+
let ilvl = 0;
|
|
39
|
+
let target;
|
|
40
|
+
if (neighbor?.type === "paragraph" && neighbor.formatting?.numPr?.kind === "reference") {
|
|
41
|
+
numId = neighbor.formatting.numPr.numId;
|
|
42
|
+
ilvl = neighbor.formatting.numPr.ilvl ?? 0;
|
|
43
|
+
target = {
|
|
44
|
+
type: "existing",
|
|
45
|
+
numId
|
|
46
|
+
};
|
|
47
|
+
} else {
|
|
48
|
+
numId = Math.max(0, ...definitions?.nums.map((num) => num.numId) ?? []) + 1;
|
|
49
|
+
const abstractNumId = Math.max(-1, ...definitions?.abstractNums.map((num) => num.abstractNumId) ?? []) + 1;
|
|
50
|
+
const levels = Array.from({ length: 9 }, (_, level) => ({
|
|
51
|
+
ilvl: level,
|
|
52
|
+
start: level === 0 ? request.start ?? 1 : 1,
|
|
53
|
+
numFmt: request.kind === "bullet" ? "bullet" : request.format?.numFmt ?? "decimal",
|
|
54
|
+
lvlText: request.kind === "bullet" ? "•" : (request.format?.lvlText ?? "%1.").replaceAll("%1", `%${level + 1}`),
|
|
55
|
+
suffix: "tab",
|
|
56
|
+
pPr: {
|
|
57
|
+
indentLeft: (level + 1) * 720,
|
|
58
|
+
indentFirstLine: 360,
|
|
59
|
+
hangingIndent: true
|
|
60
|
+
}
|
|
61
|
+
}));
|
|
62
|
+
target = {
|
|
63
|
+
type: "new",
|
|
64
|
+
num: {
|
|
65
|
+
numId,
|
|
66
|
+
abstractNumId
|
|
67
|
+
},
|
|
68
|
+
abstractNum: {
|
|
69
|
+
abstractNumId,
|
|
70
|
+
multiLevelType: "multilevel",
|
|
71
|
+
levels
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
return {
|
|
76
|
+
type: "setList",
|
|
77
|
+
target,
|
|
78
|
+
items: paragraphs.map((paragraph) => ({
|
|
79
|
+
at: {
|
|
80
|
+
story: OP_STORIES.MAIN,
|
|
81
|
+
blockId: paragraph.paraId ?? "",
|
|
82
|
+
offset: 0
|
|
83
|
+
},
|
|
84
|
+
ilvl
|
|
85
|
+
}))
|
|
86
|
+
};
|
|
87
|
+
};
|
|
88
|
+
/** Toolbar meanings enter the same operation journal as native input. */
|
|
89
|
+
const prepareCanonicalCommands = (session, state, commands) => {
|
|
90
|
+
const intents = [];
|
|
91
|
+
const paragraphs = selectedParagraphs(session, state);
|
|
92
|
+
for (const command of commands) switch (command.type) {
|
|
93
|
+
case "generateTOC": {
|
|
94
|
+
const at = session.projection.addressAt(command.at);
|
|
95
|
+
if (at.isErr()) return at;
|
|
96
|
+
const definitions = session.document.package.styles;
|
|
97
|
+
const styles = createBuiltInStyleIndex(definitions?.styles ?? [], definitions?.docDefaults);
|
|
98
|
+
const headings = [];
|
|
99
|
+
for (const heading of collectHeadings(session.projection.doc, styles)) {
|
|
100
|
+
const address = session.projection.addressAt(heading.pmPos + 1);
|
|
101
|
+
if (address.isErr()) return address;
|
|
102
|
+
const outline = headingOutlineLevel(heading.level);
|
|
103
|
+
if (outline?.kind !== "heading") return refuse("A TOC heading has an invalid outline level.");
|
|
104
|
+
const styleId = styles.styleIdForTableOfContentsLevel(outline.level + 1);
|
|
105
|
+
headings.push({
|
|
106
|
+
blockId: address.value.blockId,
|
|
107
|
+
text: heading.text,
|
|
108
|
+
level: outline.level,
|
|
109
|
+
...styleId === void 0 ? {} : { styleId }
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
if (headings.length === 0) break;
|
|
113
|
+
const titleStyleId = styles.styleIdForBuiltInName(BUILT_IN_STYLE_NAME.tocHeading);
|
|
114
|
+
const section = session.document.package.document.content.find((item) => item.type === "paragraph" && (item.sectionProperties?.pageWidth ?? 0) > 0);
|
|
115
|
+
const properties = section?.type === "paragraph" ? section.sectionProperties : void 0;
|
|
116
|
+
intents.push({
|
|
117
|
+
type: "generateTOC",
|
|
118
|
+
at: at.value,
|
|
119
|
+
title: command.title,
|
|
120
|
+
headings,
|
|
121
|
+
tabPosition: (properties?.pageWidth ?? DEFAULT_TOC_PAGE_WIDTH_TWIPS) - (properties?.marginLeft ?? DEFAULT_TOC_MARGIN_TWIPS) - (properties?.marginRight ?? DEFAULT_TOC_MARGIN_TWIPS),
|
|
122
|
+
...titleStyleId === void 0 ? {} : { titleStyleId }
|
|
123
|
+
});
|
|
124
|
+
break;
|
|
125
|
+
}
|
|
126
|
+
case "setHyperlink":
|
|
127
|
+
case "removeHyperlink":
|
|
128
|
+
case "insertHyperlink": {
|
|
129
|
+
const from = session.projection.addressAt(command.from);
|
|
130
|
+
if (from.isErr()) return from;
|
|
131
|
+
const to = session.projection.addressAt(command.to);
|
|
132
|
+
if (to.isErr()) return to;
|
|
133
|
+
intents.push({
|
|
134
|
+
...command,
|
|
135
|
+
from: from.value,
|
|
136
|
+
to: to.value
|
|
137
|
+
});
|
|
138
|
+
break;
|
|
139
|
+
}
|
|
140
|
+
case "insertBreak": {
|
|
141
|
+
const from = session.projection.addressAt(command.from);
|
|
142
|
+
if (from.isErr()) return from;
|
|
143
|
+
const to = session.projection.addressAt(command.to);
|
|
144
|
+
if (to.isErr()) return to;
|
|
145
|
+
intents.push({
|
|
146
|
+
type: "insertAtom",
|
|
147
|
+
from: from.value,
|
|
148
|
+
to: to.value,
|
|
149
|
+
atom: {
|
|
150
|
+
type: "break",
|
|
151
|
+
breakType: command.breakType
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
break;
|
|
155
|
+
}
|
|
156
|
+
case "formatRun": {
|
|
157
|
+
const from = session.projection.addressAt(command.from);
|
|
158
|
+
if (from.isErr()) return from;
|
|
159
|
+
const to = session.projection.addressAt(command.to);
|
|
160
|
+
if (to.isErr()) return to;
|
|
161
|
+
intents.push({
|
|
162
|
+
type: "formatRun",
|
|
163
|
+
from: from.value,
|
|
164
|
+
to: to.value,
|
|
165
|
+
patch: command.patch
|
|
166
|
+
});
|
|
167
|
+
break;
|
|
168
|
+
}
|
|
169
|
+
case "formatParagraph": {
|
|
170
|
+
const at = session.projection.addressAt(command.at);
|
|
171
|
+
if (at.isErr()) return at;
|
|
172
|
+
intents.push({
|
|
173
|
+
type: "formatParagraph",
|
|
174
|
+
at: at.value,
|
|
175
|
+
patch: command.patch
|
|
176
|
+
});
|
|
177
|
+
break;
|
|
178
|
+
}
|
|
179
|
+
case "toggleList": {
|
|
180
|
+
const definitions = session.document.package.numbering;
|
|
181
|
+
const map = definitions === void 0 ? void 0 : getCachedNumberingMap(definitions);
|
|
182
|
+
if (!(paragraphs.length > 0 && paragraphs.every(({ formatting }) => {
|
|
183
|
+
const numPr = formatting?.numPr;
|
|
184
|
+
return numPr?.kind === "reference" && numberingLevelUsesBulletMarker(map?.getLevel(numPr.numId, numPr.ilvl ?? 0)) === (command.kind === "bullet");
|
|
185
|
+
}))) {
|
|
186
|
+
intents.push(numberingIntent(session, paragraphs, { kind: command.kind === "bullet" ? "bullet" : "numbered" }));
|
|
187
|
+
break;
|
|
188
|
+
}
|
|
189
|
+
for (const paragraph of paragraphs) intents.push({
|
|
190
|
+
type: "formatParagraph",
|
|
191
|
+
at: {
|
|
192
|
+
story: OP_STORIES.MAIN,
|
|
193
|
+
blockId: paragraph.paraId ?? "",
|
|
194
|
+
offset: 0
|
|
195
|
+
},
|
|
196
|
+
patch: { numPr: { kind: "none" } }
|
|
197
|
+
});
|
|
198
|
+
break;
|
|
199
|
+
}
|
|
200
|
+
case "removeList":
|
|
201
|
+
for (const paragraph of paragraphs) intents.push({
|
|
202
|
+
type: "formatParagraph",
|
|
203
|
+
at: {
|
|
204
|
+
story: OP_STORIES.MAIN,
|
|
205
|
+
blockId: paragraph.paraId ?? "",
|
|
206
|
+
offset: 0
|
|
207
|
+
},
|
|
208
|
+
patch: { numPr: { kind: "none" } }
|
|
209
|
+
});
|
|
210
|
+
break;
|
|
211
|
+
case "changeListLevel":
|
|
212
|
+
for (const paragraph of paragraphs) {
|
|
213
|
+
const numPr = paragraph.formatting?.numPr;
|
|
214
|
+
if (numPr?.kind !== "reference") continue;
|
|
215
|
+
const at = {
|
|
216
|
+
story: OP_STORIES.MAIN,
|
|
217
|
+
blockId: paragraph.paraId ?? "",
|
|
218
|
+
offset: 0
|
|
219
|
+
};
|
|
220
|
+
const level = (numPr.ilvl ?? 0) + (command.direction === "increase" ? 1 : -1);
|
|
221
|
+
if (level > 8) return refuse("The list is already at its deepest level.");
|
|
222
|
+
intents.push({
|
|
223
|
+
type: "formatParagraph",
|
|
224
|
+
at,
|
|
225
|
+
patch: { numPr: level < 0 ? { kind: "none" } : paragraphNumberingReference({
|
|
226
|
+
numId: numPr.numId,
|
|
227
|
+
ilvl: level
|
|
228
|
+
}) }
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
break;
|
|
232
|
+
case "restartNumbering":
|
|
233
|
+
case "continueNumbering": {
|
|
234
|
+
const source = paragraphs.at(0);
|
|
235
|
+
const numPr = source?.formatting?.numPr;
|
|
236
|
+
const definitions = session.document.package.numbering;
|
|
237
|
+
if (source === void 0 || numPr?.kind !== "reference" || definitions === void 0) return refuse("Numbering changes require a list paragraph.");
|
|
238
|
+
const body = session.document.package.document.content;
|
|
239
|
+
const index = body.findIndex((item) => item === source);
|
|
240
|
+
const affected = body.slice(index).filter((item) => item.type === "paragraph" && item.formatting?.numPr?.kind === "reference" && item.formatting.numPr.numId === numPr.numId);
|
|
241
|
+
let targetId;
|
|
242
|
+
let target;
|
|
243
|
+
if (command.type === "continueNumbering") {
|
|
244
|
+
const map = getCachedNumberingMap(definitions);
|
|
245
|
+
const bullet = numberingLevelUsesBulletMarker(map.getLevel(numPr.numId, numPr.ilvl ?? 0));
|
|
246
|
+
const earlier = body.slice(0, index).findLast((item) => item.type === "paragraph" && item.formatting?.numPr?.kind === "reference" && item.formatting.numPr.numId !== numPr.numId && numberingLevelUsesBulletMarker(map.getLevel(item.formatting.numPr.numId, item.formatting.numPr.ilvl ?? 0)) === bullet);
|
|
247
|
+
if (earlier?.type !== "paragraph" || earlier.formatting?.numPr?.kind !== "reference") return refuse("There is no preceding compatible list.");
|
|
248
|
+
targetId = earlier.formatting.numPr.numId;
|
|
249
|
+
target = {
|
|
250
|
+
type: "existing",
|
|
251
|
+
numId: targetId
|
|
252
|
+
};
|
|
253
|
+
} else {
|
|
254
|
+
const start = command.start ?? 1;
|
|
255
|
+
if (!Number.isSafeInteger(start) || start < 0) return refuse("The numbering start must be a non-negative integer.");
|
|
256
|
+
const original = definitions.nums.find((num) => num.numId === numPr.numId);
|
|
257
|
+
if (original === void 0) return refuse("The numbering instance does not exist.");
|
|
258
|
+
targetId = Math.max(0, ...definitions.nums.map((num) => num.numId)) + 1;
|
|
259
|
+
const level = numPr.ilvl ?? 0;
|
|
260
|
+
target = {
|
|
261
|
+
type: "new",
|
|
262
|
+
num: {
|
|
263
|
+
...original,
|
|
264
|
+
numId: targetId,
|
|
265
|
+
levelOverrides: [...(original.levelOverrides ?? []).filter(({ ilvl }) => ilvl !== level), {
|
|
266
|
+
...original.levelOverrides?.find(({ ilvl }) => ilvl === level),
|
|
267
|
+
ilvl: level,
|
|
268
|
+
startOverride: start
|
|
269
|
+
}]
|
|
270
|
+
}
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
intents.push({
|
|
274
|
+
type: "setList",
|
|
275
|
+
target,
|
|
276
|
+
items: affected.map((paragraph) => ({
|
|
277
|
+
at: {
|
|
278
|
+
story: OP_STORIES.MAIN,
|
|
279
|
+
blockId: paragraph.paraId ?? "",
|
|
280
|
+
offset: 0
|
|
281
|
+
},
|
|
282
|
+
ilvl: paragraph.formatting?.numPr?.kind === "reference" ? paragraph.formatting.numPr.ilvl ?? 0 : 0
|
|
283
|
+
}))
|
|
284
|
+
});
|
|
285
|
+
break;
|
|
286
|
+
}
|
|
287
|
+
default: return command;
|
|
288
|
+
}
|
|
289
|
+
return session.prepareIntents(state, { intents });
|
|
290
|
+
};
|
|
291
|
+
/** Rules compile their replacement and paragraph change as one atomic edit. */
|
|
292
|
+
const prepareCanonicalAutoformat = (session, state, { from, to, text }) => {
|
|
293
|
+
if (text !== " " || from !== to) return void 0;
|
|
294
|
+
const at = session.projection.addressAt(from);
|
|
295
|
+
if (at.isErr()) return void 0;
|
|
296
|
+
const address = session.projection.paragraph(at.value.blockId);
|
|
297
|
+
if (address === void 0 || address.source.formatting?.numPr?.kind === "reference") return void 0;
|
|
298
|
+
const source = address.source;
|
|
299
|
+
const prefix = address.text.slice(0, at.value.offset) + text;
|
|
300
|
+
const requests = listRequestsForMarker(prefix);
|
|
301
|
+
const heading = /^(?<hashes>#{1,6}) $/u.exec(prefix)?.groups?.["hashes"];
|
|
302
|
+
if (requests === null && heading === void 0) return void 0;
|
|
303
|
+
const start = {
|
|
304
|
+
...at.value,
|
|
305
|
+
offset: 0
|
|
306
|
+
};
|
|
307
|
+
const request = requests?.at(0);
|
|
308
|
+
const styleId = `Heading${heading?.length ?? 1}`;
|
|
309
|
+
if (request === void 0 && !session.hasStyle(styleId)) return void 0;
|
|
310
|
+
return session.prepareIntents(state, { intents: [{
|
|
311
|
+
type: "replaceText",
|
|
312
|
+
from: start,
|
|
313
|
+
to: at.value,
|
|
314
|
+
text: ""
|
|
315
|
+
}, request === void 0 ? {
|
|
316
|
+
type: "formatParagraph",
|
|
317
|
+
at: start,
|
|
318
|
+
patch: { styleId }
|
|
319
|
+
} : numberingIntent(session, [source], request)] });
|
|
320
|
+
};
|
|
321
|
+
//#endregion
|
|
322
|
+
export { prepareCanonicalAutoformat, prepareCanonicalCommands };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { DocumentOp, TextPosition } from "@stll/docx-core/ops";
|
|
2
|
+
//#region src/controller/canonicalTocSelection.d.ts
|
|
3
|
+
type TocSelectionMapping = {
|
|
4
|
+
at: TextPosition;
|
|
5
|
+
after: TextPosition;
|
|
6
|
+
ops: readonly DocumentOp[];
|
|
7
|
+
};
|
|
8
|
+
/** TOC insertion retains the selected text and maps its endpoints through the canonical split. */
|
|
9
|
+
declare const mapTocSelection: (point: TextPosition, { at, after, ops }: TocSelectionMapping) => TextPosition;
|
|
10
|
+
//#endregion
|
|
11
|
+
export { mapTocSelection };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { panic } from "better-result";
|
|
2
|
+
import { DOCUMENT_OP_TYPES, SPLIT_HALVES, compareGaps, idKey, mapTocBookmarkPosition, sameStory } from "@stll/docx-core/ops";
|
|
3
|
+
//#region src/controller/canonicalTocSelection.ts
|
|
4
|
+
/** TOC insertion retains the selected text and maps its endpoints through the canonical split. */
|
|
5
|
+
const mapTocSelection = (point, { at, after, ops }) => {
|
|
6
|
+
if (!sameStory(point.story, at.story)) return point;
|
|
7
|
+
point = mapTocBookmarkPosition({
|
|
8
|
+
...point,
|
|
9
|
+
zeroWidthBefore: point.zeroWidthBefore ?? 0
|
|
10
|
+
}, ops);
|
|
11
|
+
at = mapTocBookmarkPosition({
|
|
12
|
+
...at,
|
|
13
|
+
zeroWidthBefore: at.zeroWidthBefore ?? 0
|
|
14
|
+
}, ops);
|
|
15
|
+
if (idKey(point.blockId) !== idKey(at.blockId)) return point;
|
|
16
|
+
const split = ops.find((op) => op.type === DOCUMENT_OP_TYPES.SPLIT_BLOCK);
|
|
17
|
+
if (split === void 0) return point;
|
|
18
|
+
if (point.offset === at.offset && (point.zeroWidthBefore ?? 0) === (at.zeroWidthBefore ?? 0)) return after;
|
|
19
|
+
if (split.type !== DOCUMENT_OP_TYPES.SPLIT_BLOCK || split.newHalf !== SPLIT_HALVES.FIRST) return panic("TOC insertion must retain its following paragraph identity.");
|
|
20
|
+
const pointGap = {
|
|
21
|
+
offset: point.offset,
|
|
22
|
+
zeroWidthBefore: point.zeroWidthBefore ?? 0
|
|
23
|
+
};
|
|
24
|
+
const splitGap = {
|
|
25
|
+
offset: split.at.offset,
|
|
26
|
+
zeroWidthBefore: split.at.zeroWidthBefore ?? 0
|
|
27
|
+
};
|
|
28
|
+
if (compareGaps(pointGap, splitGap) < 0) return {
|
|
29
|
+
...point,
|
|
30
|
+
blockId: split.newBlockId
|
|
31
|
+
};
|
|
32
|
+
if (point.offset === split.at.offset) return {
|
|
33
|
+
...point,
|
|
34
|
+
offset: 0,
|
|
35
|
+
zeroWidthBefore: pointGap.zeroWidthBefore - splitGap.zeroWidthBefore
|
|
36
|
+
};
|
|
37
|
+
return {
|
|
38
|
+
...point,
|
|
39
|
+
offset: point.offset - split.at.offset
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
//#endregion
|
|
43
|
+
export { mapTocSelection };
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { document_d_exports } from "../types/document.js";
|
|
2
2
|
import { DocxInput } from "../utils/docxInput.js";
|
|
3
|
+
import { FOLIO_DOCX_SERIALIZATION_MODE, FolioDocxSerializationMode, FolioGetDocxOptions } from "../types/docxSerialization.js";
|
|
3
4
|
import { Layout } from "../layout-engine/types.js";
|
|
4
|
-
import { HiddenEditorApi } from "./hiddenEditorApi.js";
|
|
5
5
|
import { FolioEditorEmitter } from "./folioEditorEvents.js";
|
|
6
|
+
import { HiddenEditorApi } from "./hiddenEditorApi.js";
|
|
6
7
|
import { LayoutRunOptions } from "./layoutRunOptions.js";
|
|
7
8
|
import { EditorState } from "prosemirror-state";
|
|
8
9
|
//#region src/controller/folioEditor.d.ts
|
|
@@ -14,14 +15,6 @@ type FolioEditorDeps = {
|
|
|
14
15
|
getDocumentIO?: () => FolioEditorDocumentIO;
|
|
15
16
|
emitter: FolioEditorEmitter;
|
|
16
17
|
};
|
|
17
|
-
declare const FOLIO_DOCX_SERIALIZATION_MODE: Readonly<{
|
|
18
|
-
readonly full: "full";
|
|
19
|
-
readonly preferSelective: "prefer-selective";
|
|
20
|
-
}>;
|
|
21
|
-
type FolioDocxSerializationMode = (typeof FOLIO_DOCX_SERIALIZATION_MODE)[keyof typeof FOLIO_DOCX_SERIALIZATION_MODE];
|
|
22
|
-
type FolioGetDocxOptions = {
|
|
23
|
-
mode?: FolioDocxSerializationMode;
|
|
24
|
-
};
|
|
25
18
|
/**
|
|
26
19
|
* Document lifecycle operations supplied by a host integration.
|
|
27
20
|
*
|
|
@@ -45,4 +38,4 @@ type FolioEditor = HiddenEditorApi & {
|
|
|
45
38
|
};
|
|
46
39
|
declare const createFolioEditor: (deps: FolioEditorDeps) => FolioEditor;
|
|
47
40
|
//#endregion
|
|
48
|
-
export { FOLIO_DOCX_SERIALIZATION_MODE, FolioDocxSerializationMode, FolioEditor, FolioEditorDeps, FolioEditorDocumentIO, FolioGetDocxOptions, createFolioEditor };
|
|
41
|
+
export { FOLIO_DOCX_SERIALIZATION_MODE, type FolioDocxSerializationMode, FolioEditor, FolioEditorDeps, FolioEditorDocumentIO, type FolioGetDocxOptions, createFolioEditor };
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
+
import { FOLIO_DOCX_SERIALIZATION_MODE } from "../types/docxSerialization.js";
|
|
1
2
|
import { panic } from "better-result";
|
|
2
3
|
//#region src/controller/folioEditor.ts
|
|
3
|
-
const FOLIO_DOCX_SERIALIZATION_MODE = Object.freeze({
|
|
4
|
-
full: "full",
|
|
5
|
-
preferSelective: "prefer-selective"
|
|
6
|
-
});
|
|
7
4
|
const createFolioEditor = (deps) => {
|
|
8
5
|
const getDocumentIO = () => deps.getDocumentIO?.() ?? panic("FolioEditor document I/O requires a getDocumentIO dependency");
|
|
9
6
|
return {
|
|
@@ -15,6 +12,19 @@ const createFolioEditor = (deps) => {
|
|
|
15
12
|
getState: () => deps.getEditorApi()?.getState() ?? null,
|
|
16
13
|
getView: () => deps.getEditorApi()?.getView() ?? null,
|
|
17
14
|
getDocument: () => deps.getEditorApi()?.getDocument() ?? null,
|
|
15
|
+
updateCanonicalInputLifecycle: (action) => deps.getEditorApi()?.updateCanonicalInputLifecycle(action) ?? false,
|
|
16
|
+
applyCanonicalStoryHistory: (options) => deps.getEditorApi()?.applyCanonicalStoryHistory(options) ?? false,
|
|
17
|
+
applyCanonicalOperations: (ops) => deps.getEditorApi()?.applyCanonicalOperations(ops) ?? false,
|
|
18
|
+
getCanonicalStorySelection: (story) => deps.getEditorApi()?.getCanonicalStorySelection(story) ?? null,
|
|
19
|
+
getCanonicalStoryProjection: (story) => deps.getEditorApi()?.getCanonicalStoryProjection(story) ?? null,
|
|
20
|
+
replaceCanonicalStoryText: (options) => deps.getEditorApi()?.replaceCanonicalStoryText(options) ?? false,
|
|
21
|
+
isCanonicalSaveCurrent: (version) => deps.getEditorApi()?.isCanonicalSaveCurrent(version) ?? false,
|
|
22
|
+
captureCanonicalSave: () => deps.getEditorApi()?.captureCanonicalSave() ?? null,
|
|
23
|
+
applyCanonicalDocumentOperations: (options) => deps.getEditorApi()?.applyCanonicalDocumentOperations(options) ?? null,
|
|
24
|
+
undoCanonicalDocumentOperations: (handle) => deps.getEditorApi()?.undoCanonicalDocumentOperations(handle) ?? null,
|
|
25
|
+
getCanonicalDocument: () => deps.getEditorApi()?.getCanonicalDocument() ?? null,
|
|
26
|
+
setCanonicalMode: (mode) => deps.getEditorApi()?.setCanonicalMode(mode) ?? false,
|
|
27
|
+
resolveCanonicalRevisions: (revisionIds, resolution) => deps.getEditorApi()?.resolveCanonicalRevisions(revisionIds, resolution) ?? false,
|
|
18
28
|
focus: () => deps.getEditorApi()?.focus(),
|
|
19
29
|
blur: () => deps.getEditorApi()?.blur(),
|
|
20
30
|
isFocused: () => deps.getEditorApi()?.isFocused() ?? false,
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { document_d_exports } from "../types/document.js";
|
|
2
|
+
import { CanonicalGap } from "../types/canonicalCapabilities.js";
|
|
3
|
+
import { HiddenEditorApi } from "./hiddenEditorApi.js";
|
|
2
4
|
import { DirectEditorProps, EditorView } from "prosemirror-view";
|
|
3
5
|
//#region src/controller/headerFooterEditorManager.d.ts
|
|
4
6
|
type HeaderFooterPartKind = "header" | "footer";
|
|
@@ -16,6 +18,9 @@ type HeaderFooterEditorTransaction = {
|
|
|
16
18
|
type HeaderFooterEditorManagerDeps = {
|
|
17
19
|
createView?: ((mountNode: HTMLElement, props: DirectEditorProps) => EditorView) | undefined;
|
|
18
20
|
getDocument: () => document_d_exports.Document | null;
|
|
21
|
+
getCanonicalApi?: (() => HiddenEditorApi | null) | undefined;
|
|
22
|
+
getExperimentalSession?: (() => "canonical" | undefined) | undefined;
|
|
23
|
+
onSessionRefusal?: ((reason: string, gap: CanonicalGap) => void) | undefined;
|
|
19
24
|
getHost: () => HTMLElement | null;
|
|
20
25
|
getStyles: () => document_d_exports.StyleDefinitions | null | undefined;
|
|
21
26
|
getTheme: () => document_d_exports.Theme | null | undefined;
|