@portone/docx-editor 0.6.3 → 0.6.5
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/CHANGELOG.md +62 -0
- package/dist/DocxEditor.d.ts +11 -0
- package/dist/DocxEditor.js +7 -3
- package/dist/docx/comments/writing.d.ts +8 -0
- package/dist/docx/comments/writing.js +9 -2
- package/dist/docx/headersFooters.d.ts +7 -0
- package/dist/docx/headersFooters.js +4 -1
- package/dist/docx/identities.d.ts +4 -3
- package/dist/docx/identities.js +14 -1
- package/dist/docx/importDocx.js +2 -0
- package/dist/docx/importParagraph.d.ts +4 -0
- package/dist/docx/importParagraph.js +2 -0
- package/dist/docx/importSdtBlock.d.ts +2 -3
- package/dist/docx/importSdtBlock.js +7 -16
- package/dist/docx/invariants.js +60 -3
- package/dist/docx/numberingPlanner.d.ts +3 -0
- package/dist/docx/numberingPlanner.js +8 -2
- package/dist/docx/packageParts.d.ts +9 -0
- package/dist/docx/packageParts.js +16 -0
- package/dist/docx/packagePrefixes.d.ts +12 -0
- package/dist/docx/packagePrefixes.js +18 -0
- package/dist/docx/partPlan.js +3 -5
- package/dist/docx/sdt.d.ts +27 -0
- package/dist/docx/sdt.js +14 -1
- package/dist/docx/serializeBlock.js +4 -3
- package/dist/docx/serializeParagraph.d.ts +2 -1
- package/dist/docx/serializeParagraph.js +6 -1
- package/dist/docx/serializeSdtBlock.d.ts +0 -8
- package/dist/docx/serializeSdtBlock.js +1 -5
- package/dist/docx/storyParts.d.ts +3 -0
- package/dist/docx/storyParts.js +4 -1
- package/dist/docx/wrappers.d.ts +23 -8
- package/dist/docx/wrappers.js +33 -2
- package/dist/editor/blockControlEdits.d.ts +2 -2
- package/dist/editor/blockControlEdits.js +6 -6
- package/dist/editor/commands/lockCommands.js +25 -5
- package/dist/editor/createEditor.d.ts +4 -1
- package/dist/editor/createEditor.js +14 -2
- package/dist/editor/editRefusal.d.ts +68 -0
- package/dist/editor/editRefusal.js +177 -0
- package/dist/editor/inlineControlEdits.d.ts +20 -0
- package/dist/editor/inlineControlEdits.js +69 -0
- package/dist/editor/plugins/controlContents.d.ts +24 -0
- package/dist/editor/plugins/controlContents.js +260 -0
- package/dist/editor/plugins/controlLifecycle.js +3 -5
- package/dist/editor/plugins/keymap.js +18 -7
- package/dist/editor/stories/storyState.js +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/ooxml/element.js +3 -2
- package/dist/ooxml/errors.d.ts +11 -0
- package/dist/ooxml/fragment.js +3 -2
- package/dist/ooxml/names.d.ts +4 -0
- package/dist/ooxml/names.js +8 -2
- package/dist/ooxml/partPrefixes.d.ts +21 -0
- package/dist/ooxml/partPrefixes.js +164 -0
- package/dist/ooxml/partSplice.d.ts +6 -1
- package/dist/ooxml/partSplice.js +30 -10
- package/dist/ooxml/tagScan.d.ts +24 -2
- package/dist/ooxml/tagScan.js +26 -7
- package/dist/ooxml/xml.d.ts +8 -0
- package/dist/ooxml/xml.js +27 -5
- package/dist/schema/attrRoles.js +11 -0
- package/dist/schema/clipboard.js +2 -0
- package/dist/schema/controlAttrs.d.ts +33 -13
- package/dist/schema/controlAttrs.js +18 -6
- package/dist/schema/docxSchema.d.ts +1 -1
- package/dist/schema/docxSchema.js +60 -5
- package/dist/schema/guards.d.ts +8 -2
- package/dist/schema/guards.js +14 -8
- package/dist/schema/locks.d.ts +62 -7
- package/dist/schema/locks.js +99 -25
- package/dist/styles/classNames.d.ts +4 -0
- package/dist/styles/classNames.js +4 -0
- package/dist/styles.css +78 -14
- package/dist/ui/MenuNote.d.ts +12 -0
- package/dist/ui/MenuNote.js +14 -0
- package/dist/ui/TableMenu.js +38 -19
- package/dist/ui/TextMenu.js +31 -25
- package/package.json +2 -2
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
// src/schema/controlAttrs.ts
|
|
2
2
|
var SDT_BLOCK_NODE = "sdtBlock";
|
|
3
|
-
var
|
|
3
|
+
var SDT_EMPTY_BLOCK_NODE = "sdtEmpty";
|
|
4
|
+
var SDT_EMPTY_INLINE_NODE = "sdtEmptyInline";
|
|
5
|
+
function goesWithEdit(control) {
|
|
6
|
+
return control.temporary && !control.deletionLocked;
|
|
7
|
+
}
|
|
4
8
|
var OWN_CONTROL_ATTRS = {
|
|
5
9
|
prefix: "sdtPrefix",
|
|
6
10
|
contentsLocked: "contentsLocked",
|
|
@@ -98,12 +102,17 @@ var WRAPPED_TABLE_ROLES = ["cell", "row"];
|
|
|
98
102
|
function isBlockControl(node) {
|
|
99
103
|
return node?.type.name === SDT_BLOCK_NODE;
|
|
100
104
|
}
|
|
101
|
-
function
|
|
102
|
-
return node?.type.name ===
|
|
105
|
+
function isEmptyBlockControl(node) {
|
|
106
|
+
return node?.type.name === SDT_EMPTY_BLOCK_NODE;
|
|
107
|
+
}
|
|
108
|
+
function isEmptyInlineControl(node) {
|
|
109
|
+
return node?.type.name === SDT_EMPTY_INLINE_NODE;
|
|
103
110
|
}
|
|
104
111
|
function controlAttrsOf(node) {
|
|
105
112
|
if (!node) return null;
|
|
106
|
-
if (isBlockControl(node) ||
|
|
113
|
+
if (isBlockControl(node) || isEmptyBlockControl(node) || isEmptyInlineControl(node)) {
|
|
114
|
+
return OWN_CONTROL_ATTRS;
|
|
115
|
+
}
|
|
107
116
|
const role = node.type.spec.tableRole;
|
|
108
117
|
if (typeof role !== "string" || !WRAPPED_TABLE_ROLES.includes(role)) {
|
|
109
118
|
return null;
|
|
@@ -115,7 +124,8 @@ export {
|
|
|
115
124
|
OWN_CONTROL_ATTRS,
|
|
116
125
|
PREFIX_DOM_ATTR,
|
|
117
126
|
SDT_BLOCK_NODE,
|
|
118
|
-
|
|
127
|
+
SDT_EMPTY_BLOCK_NODE,
|
|
128
|
+
SDT_EMPTY_INLINE_NODE,
|
|
119
129
|
WRAPPED_CONTROL_ATTRS,
|
|
120
130
|
controlAttrSpecs,
|
|
121
131
|
controlAttrs,
|
|
@@ -124,6 +134,8 @@ export {
|
|
|
124
134
|
controlClassName,
|
|
125
135
|
controlFactsOf,
|
|
126
136
|
controlToDom,
|
|
137
|
+
goesWithEdit,
|
|
127
138
|
isBlockControl,
|
|
128
|
-
|
|
139
|
+
isEmptyBlockControl,
|
|
140
|
+
isEmptyInlineControl
|
|
129
141
|
};
|
|
@@ -23,4 +23,4 @@ export declare function isPageBreak(brAttrs: unknown): boolean;
|
|
|
23
23
|
* ends the line where it stood, and `chip` draws a small box naming the element.
|
|
24
24
|
*/
|
|
25
25
|
export type PreservedDisplay = "hidden" | "text" | "break" | "chip";
|
|
26
|
-
export declare const docxSchema: Schema<"commentEnd" | "commentReference" | "commentStart" | "doc" | "hardBreak" | "image" | "noteReference" | "paragraph" | "rawBlock" | "rawInline" | "rawRunContent" | "sdtBlock" | "sdtEmpty" | "table" | "tableCell" | "tableRow" | "text", "link" | "run" | "sdt" | "tab">;
|
|
26
|
+
export declare const docxSchema: Schema<"commentEnd" | "commentReference" | "commentStart" | "doc" | "hardBreak" | "image" | "noteReference" | "paragraph" | "rawBlock" | "rawInline" | "rawRunContent" | "sdtBlock" | "sdtEmpty" | "sdtEmptyInline" | "table" | "tableCell" | "tableRow" | "text", "link" | "run" | "sdt" | "tab">;
|
|
@@ -43,7 +43,8 @@ import {
|
|
|
43
43
|
OWN_CONTROL_ATTRS,
|
|
44
44
|
PREFIX_DOM_ATTR,
|
|
45
45
|
SDT_BLOCK_NODE,
|
|
46
|
-
|
|
46
|
+
SDT_EMPTY_BLOCK_NODE,
|
|
47
|
+
SDT_EMPTY_INLINE_NODE,
|
|
47
48
|
WRAPPED_CONTROL_ATTRS
|
|
48
49
|
} from "./controlAttrs.js";
|
|
49
50
|
import { imageNodeSpec, runMarkSpec } from "./rendering.js";
|
|
@@ -608,12 +609,12 @@ var docxSchema = new Schema({
|
|
|
608
609
|
* which is what a server's condition-failed clause is meant to look like, and what it states
|
|
609
610
|
* about itself rides back out in the same attributes the container carries.
|
|
610
611
|
*/
|
|
611
|
-
[
|
|
612
|
+
[SDT_EMPTY_BLOCK_NODE]: {
|
|
612
613
|
group: "block modelled",
|
|
613
614
|
atom: true,
|
|
614
|
-
//
|
|
615
|
-
//
|
|
616
|
-
selectable:
|
|
615
|
+
// It draws nothing, so a node selection would put the user in a state with nothing on screen
|
|
616
|
+
// to show it: it goes with a stretch that covers it instead
|
|
617
|
+
selectable: false,
|
|
617
618
|
attrs: {
|
|
618
619
|
/**
|
|
619
620
|
* The fragment of the session this control was opened from, as the container names its
|
|
@@ -1004,6 +1005,60 @@ var docxSchema = new Schema({
|
|
|
1004
1005
|
}
|
|
1005
1006
|
]
|
|
1006
1007
|
},
|
|
1008
|
+
/**
|
|
1009
|
+
* A content control holding nothing that the file wrote inside a paragraph, which is the
|
|
1010
|
+
* `sdtEmpty` node's inline counterpart (§17.5.2.34).
|
|
1011
|
+
*
|
|
1012
|
+
* The inline control is otherwise a mark on the runs it wrapped (`./wrappers`), and a control
|
|
1013
|
+
* holding no run leaves a mark nothing to sit on. So it stands as an atom of its own, taking
|
|
1014
|
+
* no width between the words either side of it, and what it states about itself rides back out
|
|
1015
|
+
* in the attributes every other carrier uses.
|
|
1016
|
+
*
|
|
1017
|
+
* It wears the wrapper marks rather than carrying a `depth` of its own: what it stands inside
|
|
1018
|
+
* is what has to close around it on export, while the control it is has nothing to nest.
|
|
1019
|
+
*/
|
|
1020
|
+
[SDT_EMPTY_INLINE_NODE]: {
|
|
1021
|
+
group: "inline",
|
|
1022
|
+
inline: true,
|
|
1023
|
+
atom: true,
|
|
1024
|
+
marks: "wrapper",
|
|
1025
|
+
// No selection settles on it, for the reason `sdtEmpty` above states
|
|
1026
|
+
selectable: false,
|
|
1027
|
+
attrs: {
|
|
1028
|
+
/** Which control of the document this is, counted as the file was opened (`docx/wrappers`) */
|
|
1029
|
+
key: { default: 0 },
|
|
1030
|
+
/** What the control states, under the names every carrier holds them by (`./controlAttrs`) */
|
|
1031
|
+
...controlAttrSpecs(OWN_CONTROL_ATTRS)
|
|
1032
|
+
},
|
|
1033
|
+
toDOM(node) {
|
|
1034
|
+
const control = controlFactsOf(OWN_CONTROL_ATTRS, node.attrs);
|
|
1035
|
+
return [
|
|
1036
|
+
"span",
|
|
1037
|
+
{
|
|
1038
|
+
class: controlClassName(
|
|
1039
|
+
control,
|
|
1040
|
+
editorClassNames.sdtEmptyInline,
|
|
1041
|
+
editorClassNames.sdtLocked
|
|
1042
|
+
),
|
|
1043
|
+
"data-key": numberText(node.attrs.key),
|
|
1044
|
+
...controlToDom(control)
|
|
1045
|
+
}
|
|
1046
|
+
];
|
|
1047
|
+
},
|
|
1048
|
+
parseDOM: [
|
|
1049
|
+
{
|
|
1050
|
+
tag: `span.${editorClassNames.sdtEmptyInline}`,
|
|
1051
|
+
getAttrs: (dom) => {
|
|
1052
|
+
const prefix = rawXml(dom, PREFIX_DOM_ATTR, SDT_PREFIX);
|
|
1053
|
+
if (prefix === null || prefix === false) return false;
|
|
1054
|
+
return {
|
|
1055
|
+
key: parseInt10(dom.getAttribute("data-key"), 0),
|
|
1056
|
+
...controlAttrsFromDom(OWN_CONTROL_ATTRS, dom, prefix)
|
|
1057
|
+
};
|
|
1058
|
+
}
|
|
1059
|
+
}
|
|
1060
|
+
]
|
|
1061
|
+
},
|
|
1007
1062
|
/** The node that carries a non-run element inside a paragraph (a bookmark, for instance) exactly as it came */
|
|
1008
1063
|
rawInline: {
|
|
1009
1064
|
group: "inline",
|
package/dist/schema/guards.d.ts
CHANGED
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
* is open at all, which is a question about the editor rather than about an edit.
|
|
23
23
|
*/
|
|
24
24
|
import type { Command, EditorState, Selection, Transaction } from "prosemirror-state";
|
|
25
|
-
import { type EditGuard, type EditIntent } from "./editGuard";
|
|
25
|
+
import { type EditGuard, type EditGuardName, type EditIntent } from "./editGuard";
|
|
26
26
|
import { type ProtectionState } from "./protection";
|
|
27
27
|
export type { EditGuard, EditGuardName, EditIntent } from "./editGuard";
|
|
28
28
|
export { stepReaches } from "./editGuard";
|
|
@@ -42,7 +42,8 @@ export declare function transactionTouchesComments(tr: Transaction): boolean;
|
|
|
42
42
|
export declare function protectionAllowsTransaction(tr: Transaction, rules: ProtectionState): boolean;
|
|
43
43
|
export declare const EDIT_GUARDS: readonly EditGuard[];
|
|
44
44
|
/**
|
|
45
|
-
*
|
|
45
|
+
* The first guard that would turn this transaction down, decided and nothing else. Null when every
|
|
46
|
+
* guard lets it through.
|
|
46
47
|
*
|
|
47
48
|
* The refusal a guard itself answers with carries a side effect - the composition it ends
|
|
48
49
|
* (`editor/plugins/lockedContent`) - which a query about a button's state may not set off, so the
|
|
@@ -53,7 +54,12 @@ export declare const EDIT_GUARDS: readonly EditGuard[];
|
|
|
53
54
|
* whole-change judgements then come first and take no pass, since a pass lifts one guard's
|
|
54
55
|
* reading of a step rather than another guard's reading of the change. What is left is judged
|
|
55
56
|
* step by step, each step over the document it was built against.
|
|
57
|
+
*
|
|
58
|
+
* Which guard answers is what a refusal is reported under (`editor/editRefusal`), so the list is
|
|
59
|
+
* asked in its own order and the first refusal is the one named.
|
|
56
60
|
*/
|
|
61
|
+
export declare function transactionRefusal(tr: Transaction, state: EditorState): EditGuardName | null;
|
|
62
|
+
/** Whether every guard would let this transaction through (`transactionRefusal`) */
|
|
57
63
|
export declare function transactionAllowed(tr: Transaction, state: EditorState): boolean;
|
|
58
64
|
/**
|
|
59
65
|
* Whether any guard shuts this intent where it stands.
|
package/dist/schema/guards.js
CHANGED
|
@@ -52,16 +52,17 @@ function displayOnlyTransaction(tr, state) {
|
|
|
52
52
|
(step, index) => changesOnlyDisplayAttrs(step, tr.docs[index] ?? state.doc)
|
|
53
53
|
);
|
|
54
54
|
}
|
|
55
|
-
function
|
|
56
|
-
if (!tr.docChanged) return
|
|
57
|
-
if (displayOnlyTransaction(tr, state)) return
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
55
|
+
function transactionRefusal(tr, state) {
|
|
56
|
+
if (!tr.docChanged) return null;
|
|
57
|
+
if (displayOnlyTransaction(tr, state)) return null;
|
|
58
|
+
const changeRefusal = EDIT_GUARDS.find(
|
|
59
|
+
(guard) => guard.change?.(tr, state) === false
|
|
60
|
+
);
|
|
61
|
+
if (changeRefusal) return changeRefusal.name;
|
|
62
|
+
const stepRefusal = EDIT_GUARDS.filter(judgesSteps).filter((guard) => !lifted(guard, tr)).find(
|
|
62
63
|
(guard) => (
|
|
63
64
|
// Each step counts positions in the document it was built against, which `docs` holds
|
|
64
|
-
tr.steps.every(
|
|
65
|
+
!tr.steps.every(
|
|
65
66
|
(step, index) => guard.step(
|
|
66
67
|
step,
|
|
67
68
|
tr.docs[index] ?? state.doc,
|
|
@@ -71,6 +72,10 @@ function transactionAllowed(tr, state) {
|
|
|
71
72
|
)
|
|
72
73
|
)
|
|
73
74
|
);
|
|
75
|
+
return stepRefusal?.name ?? null;
|
|
76
|
+
}
|
|
77
|
+
function transactionAllowed(tr, state) {
|
|
78
|
+
return transactionRefusal(tr, state) === null;
|
|
74
79
|
}
|
|
75
80
|
function editShut(state, intent) {
|
|
76
81
|
return EDIT_GUARDS.some((guard) => guard.shuts(intent, state));
|
|
@@ -105,5 +110,6 @@ export {
|
|
|
105
110
|
selectionIntents,
|
|
106
111
|
stepReaches,
|
|
107
112
|
transactionAllowed,
|
|
113
|
+
transactionRefusal,
|
|
108
114
|
transactionTouchesComments
|
|
109
115
|
};
|
package/dist/schema/locks.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Evaluates OOXML content and deletion locks for inline controls
|
|
3
|
-
* stands around whole
|
|
2
|
+
* Evaluates OOXML content and deletion locks for inline controls, for the containers a control
|
|
3
|
+
* stands around whole - a table cell, a block-level control - and for a control holding nothing,
|
|
4
|
+
* whose extent is the node it stands as, between blocks or inside a paragraph.
|
|
4
5
|
*
|
|
5
6
|
* `lockGuard` is what `./guards` registers all of this as, and it is the only way in: a caller
|
|
6
7
|
* asking about a lock asks the one guard list, which asks the locks along with every other rule an
|
|
@@ -36,7 +37,20 @@ export declare const historyReplay: PluginKey<boolean>;
|
|
|
36
37
|
* (`spec/notes/contentControls.md`).
|
|
37
38
|
*/
|
|
38
39
|
export declare const controlLifted: PluginKey<boolean>;
|
|
39
|
-
|
|
40
|
+
/**
|
|
41
|
+
* The pass the transaction that keeps an inline control through an edit of its contents carries
|
|
42
|
+
* (`editor/plugins/controlContents`).
|
|
43
|
+
*
|
|
44
|
+
* Writing over everything a control holds is an edit of its contents rather than its deletion
|
|
45
|
+
* (`controlsWrittenInto`), and that transaction is what keeps the control standing: it lays the
|
|
46
|
+
* control back over what was written, or leaves the control standing as one holding nothing. When
|
|
47
|
+
* the caret then writes into a control it emptied, the node it stood as goes, since the control
|
|
48
|
+
* stands as the new text instead. That removal is the one step here a lock against deletion would
|
|
49
|
+
* refuse, and it removes no control.
|
|
50
|
+
*/
|
|
51
|
+
export declare const controlKept: PluginKey<boolean>;
|
|
52
|
+
/** The stretch a judgement or an edit runs over */
|
|
53
|
+
export interface StepRange {
|
|
40
54
|
from: number;
|
|
41
55
|
to: number;
|
|
42
56
|
}
|
|
@@ -51,10 +65,14 @@ export declare function lockedMarkOf(node: PMNode | null | undefined): Mark | nu
|
|
|
51
65
|
export declare function isLockedContainer(node: PMNode | null | undefined): boolean;
|
|
52
66
|
/**
|
|
53
67
|
* Whether this node carries a lock of either clause, an inline one wearing a control's mark and a
|
|
54
|
-
*
|
|
68
|
+
* carrier standing for one alike.
|
|
55
69
|
* This is the question about the document holding a lock at all rather than about editing a spot,
|
|
56
70
|
* so a control locked against deletion alone counts (`editor/commands/lockCommands`). A `w:group`
|
|
57
71
|
* is not a lock and does not: it shuts its contents, and there is nothing in it to lift.
|
|
72
|
+
*
|
|
73
|
+
* Both are asked of every node rather than one or the other: a control holding nothing states its
|
|
74
|
+
* own lock in its attributes and wears the marks of the wrappers around it at the same time
|
|
75
|
+
* (`docx/wrappers`), so reading only the marks would miss the lock it states itself.
|
|
58
76
|
*/
|
|
59
77
|
export declare function carriesLock(node: PMNode): boolean;
|
|
60
78
|
/** A textblock a judgement or an edit runs through, and where its content begins */
|
|
@@ -77,6 +95,43 @@ export interface ControlSpan extends StepRange {
|
|
|
77
95
|
* overlap: each locks on its own terms.
|
|
78
96
|
*/
|
|
79
97
|
export declare function controlSpans(block: Textblock): ControlSpan[];
|
|
98
|
+
/**
|
|
99
|
+
* Whether the stretch covers this control from end to end, which is the control going whole.
|
|
100
|
+
*
|
|
101
|
+
* This is also what reaches a control that draws nothing, since it holds no spot a caret could
|
|
102
|
+
* stand in: a selection merely resting at its edge points at no control the user can see
|
|
103
|
+
* (`editor/commands/lockCommands`).
|
|
104
|
+
*/
|
|
105
|
+
export declare function coversWhole(range: StepRange, span: StepRange): boolean;
|
|
106
|
+
/**
|
|
107
|
+
* The inline controls replacing this stretch writes into rather than takes away, each as the
|
|
108
|
+
* whole stretch it covers, outermost first.
|
|
109
|
+
*
|
|
110
|
+
* These are the controls the stretch stands within (`standsWithin`) whose contents no lock of
|
|
111
|
+
* their own shuts, which is what the lock guard reads as an edit of the contents rather than a
|
|
112
|
+
* deletion. What takes the stretch's place belongs inside each of them, and a control the
|
|
113
|
+
* replacement leaves holding nothing still stands (`editor/plugins/controlContents`).
|
|
114
|
+
*/
|
|
115
|
+
export declare function controlsWrittenInto(doc: PMNode, from: number, to: number): ControlSpan[];
|
|
116
|
+
/** One content control holding nothing, standing as a node of its own, as the one spot it covers */
|
|
117
|
+
export interface EmptyControl {
|
|
118
|
+
node: PMNode;
|
|
119
|
+
span: StepRange;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Every control holding nothing that stands among the inlines of this textblock, each as the one
|
|
123
|
+
* spot it covers.
|
|
124
|
+
*
|
|
125
|
+
* Such a control carries what it states in its own attributes rather than in a mark
|
|
126
|
+
* (`docx/wrappers`), so `controlSpans` never meets it and the walk below never reaches it:
|
|
127
|
+
* a textblock is where `nodesBetween` is told to stop.
|
|
128
|
+
*
|
|
129
|
+
* One walk answers both the lock guard and the menu that lifts a lock
|
|
130
|
+
* (`editor/commands/lockCommands`), so the two cannot come to disagree about what stands here. It
|
|
131
|
+
* looks for controls holding nothing and for no other carrier: both callers judge what it finds by
|
|
132
|
+
* rules written for a node with nothing inside it.
|
|
133
|
+
*/
|
|
134
|
+
export declare function emptyControlsIn(block: Textblock): EmptyControl[];
|
|
80
135
|
/**
|
|
81
136
|
* Whether a lock shuts editing where this selection stands, which is what a menu that would lift a
|
|
82
137
|
* lock is built on (`editor/commands/lockCommands`).
|
|
@@ -92,8 +147,8 @@ export declare function selectionShut(selection: Selection, doc: PMNode): boolea
|
|
|
92
147
|
/**
|
|
93
148
|
* The locks the document carries, as `./guards` registers them.
|
|
94
149
|
*
|
|
95
|
-
*
|
|
96
|
-
* history replays is the reverse of a step that passed the guard when it was made
|
|
150
|
+
* Every pass lifts it: unlocking is the one edit that may reach into a lock, every step the
|
|
151
|
+
* history replays is the reverse of a step that passed the guard when it was made, and the other
|
|
152
|
+
* two carry what an edit that passed does to a control (`controlLifted`, `controlKept`).
|
|
97
153
|
*/
|
|
98
154
|
export declare const lockGuard: StepGuard;
|
|
99
|
-
export {};
|
package/dist/schema/locks.js
CHANGED
|
@@ -9,12 +9,17 @@ import {
|
|
|
9
9
|
ReplaceAroundStep,
|
|
10
10
|
ReplaceStep
|
|
11
11
|
} from "prosemirror-transform";
|
|
12
|
-
import {
|
|
12
|
+
import {
|
|
13
|
+
controlAttrsOf,
|
|
14
|
+
controlFactsOf,
|
|
15
|
+
isEmptyInlineControl
|
|
16
|
+
} from "./controlAttrs.js";
|
|
13
17
|
import { docxSchema } from "./index.js";
|
|
14
18
|
import { wrappersOf } from "./wrappers.js";
|
|
15
19
|
var unlockAllowed = new PluginKey("docxEditorUnlockAllowed");
|
|
16
20
|
var historyReplay = new PluginKey("docxEditorHistoryReplay");
|
|
17
21
|
var controlLifted = new PluginKey("docxEditorControlLifted");
|
|
22
|
+
var controlKept = new PluginKey("docxEditorControlKept");
|
|
18
23
|
var OPEN = { contents: false, deletion: false, group: false };
|
|
19
24
|
function shutsContents(locks, inner) {
|
|
20
25
|
return locks.contents || locks.group && !inner;
|
|
@@ -59,16 +64,12 @@ function containerLocks(node) {
|
|
|
59
64
|
function isLockedContainer(node) {
|
|
60
65
|
return shutsAlone(containerLocks(node));
|
|
61
66
|
}
|
|
67
|
+
function statesLock(locks) {
|
|
68
|
+
return locks.contents || locks.deletion;
|
|
69
|
+
}
|
|
62
70
|
function carriesLock(node) {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
const locks = containerLocks(node);
|
|
66
|
-
return locks.contents || locks.deletion;
|
|
67
|
-
}
|
|
68
|
-
return marks.some((mark) => {
|
|
69
|
-
const locks = markLocks(mark);
|
|
70
|
-
return locks.contents || locks.deletion;
|
|
71
|
-
});
|
|
71
|
+
if (statesLock(containerLocks(node))) return true;
|
|
72
|
+
return sdtMarksOf(node).some((mark) => statesLock(markLocks(mark)));
|
|
72
73
|
}
|
|
73
74
|
function controlSpans(block) {
|
|
74
75
|
const spans = [];
|
|
@@ -126,36 +127,105 @@ function coversWhole(range, span) {
|
|
|
126
127
|
function overlaps(range, span) {
|
|
127
128
|
return range.from < span.to && range.to > span.from;
|
|
128
129
|
}
|
|
129
|
-
function
|
|
130
|
-
|
|
130
|
+
function drawsNothing(node) {
|
|
131
|
+
switch (node.type.name) {
|
|
132
|
+
case "commentStart":
|
|
133
|
+
case "commentEnd":
|
|
134
|
+
return true;
|
|
135
|
+
case "rawInline":
|
|
136
|
+
case "rawRunContent":
|
|
137
|
+
return node.attrs.display === "hidden";
|
|
138
|
+
default:
|
|
139
|
+
return isEmptyInlineControl(node);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
function visibleStretch(block, range, span) {
|
|
143
|
+
let { from, to } = range;
|
|
144
|
+
const children = [];
|
|
145
|
+
block.node.forEach((node, offset) => {
|
|
146
|
+
children.push({ node, at: block.start + offset });
|
|
147
|
+
});
|
|
148
|
+
for (const { node, at } of children) {
|
|
149
|
+
if (at === from && from < span.from && drawsNothing(node)) {
|
|
150
|
+
from = at + node.nodeSize;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
for (const { node, at } of children.reverse()) {
|
|
154
|
+
if (at + node.nodeSize === to && to > span.to && drawsNothing(node)) {
|
|
155
|
+
to = at;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
return { from, to };
|
|
159
|
+
}
|
|
160
|
+
function standsWithin(block, range, span) {
|
|
161
|
+
if (range.from >= range.to) return false;
|
|
162
|
+
const end = block.start + block.node.content.size;
|
|
163
|
+
if (range.from < block.start || range.to > end) return false;
|
|
164
|
+
const visible = visibleStretch(block, range, span);
|
|
165
|
+
return visible.from >= span.from && visible.to <= span.to;
|
|
166
|
+
}
|
|
167
|
+
function shuts(locks, range, span, inner, within) {
|
|
168
|
+
const open = !shutsContents(locks, inner);
|
|
169
|
+
return range.takesAway && coversWhole(range, span) && !(within && open) ? locks.deletion : !open && overlaps(range, span);
|
|
170
|
+
}
|
|
171
|
+
function spanShut(block, spans, span, range) {
|
|
172
|
+
return shuts(
|
|
173
|
+
markLocks(span.mark),
|
|
174
|
+
range,
|
|
175
|
+
span,
|
|
176
|
+
supersededSpan(spans, span, range),
|
|
177
|
+
standsWithin(block, range, span)
|
|
178
|
+
);
|
|
179
|
+
}
|
|
180
|
+
function controlsWrittenInto(doc, from, to) {
|
|
181
|
+
if (from >= to) return [];
|
|
182
|
+
const $from = doc.resolve(from);
|
|
183
|
+
if (!$from.parent.isTextblock || !$from.sameParent(doc.resolve(to))) {
|
|
184
|
+
return [];
|
|
185
|
+
}
|
|
186
|
+
const block = { node: $from.parent, start: $from.start() };
|
|
187
|
+
const range = { from, to };
|
|
188
|
+
const spans = controlSpans(block);
|
|
189
|
+
return spans.filter(
|
|
190
|
+
(span) => standsWithin(block, range, span) && !shutsContents(markLocks(span.mark), supersededSpan(spans, span, range))
|
|
191
|
+
);
|
|
131
192
|
}
|
|
132
193
|
function supersededSpan(spans, span, range) {
|
|
133
194
|
return spans.some(
|
|
134
195
|
(inner) => inner !== span && coversWhole(span, inner) && coversWhole(inner, range)
|
|
135
196
|
);
|
|
136
197
|
}
|
|
198
|
+
function containerShut(node, span, range) {
|
|
199
|
+
if (!coversWhole(range, span)) return false;
|
|
200
|
+
const locks = containerLocks(node);
|
|
201
|
+
return range.takesAway ? locks.deletion : shutsAlone(locks) && node.content.size > 0;
|
|
202
|
+
}
|
|
203
|
+
function emptyControlsIn(block) {
|
|
204
|
+
const found = [];
|
|
205
|
+
block.node.forEach((child, offset) => {
|
|
206
|
+
if (!isEmptyInlineControl(child)) return;
|
|
207
|
+
const from = block.start + offset;
|
|
208
|
+
found.push({ node: child, span: { from, to: from + child.nodeSize } });
|
|
209
|
+
});
|
|
210
|
+
return found;
|
|
211
|
+
}
|
|
137
212
|
function rangeShut(doc, range) {
|
|
138
213
|
if (reachesLockedContainer(doc, range)) return true;
|
|
139
214
|
let shut = false;
|
|
140
215
|
doc.nodesBetween(range.from, range.to, (node, pos) => {
|
|
141
216
|
if (shut) return false;
|
|
142
217
|
if (controlAttrsOf(node) !== null) {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
const edits = shutsAlone(locks) && node.content.size > 0;
|
|
146
|
-
if (range.takesAway ? locks.deletion : edits) shut = true;
|
|
218
|
+
if (containerShut(node, { from: pos, to: pos + node.nodeSize }, range)) {
|
|
219
|
+
shut = true;
|
|
147
220
|
}
|
|
148
221
|
return !shut;
|
|
149
222
|
}
|
|
150
223
|
if (!node.isTextblock) return true;
|
|
151
|
-
const
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
span,
|
|
157
|
-
supersededSpan(spans, span, range)
|
|
158
|
-
)
|
|
224
|
+
const block = { node, start: pos + 1 };
|
|
225
|
+
const spans = controlSpans(block);
|
|
226
|
+
shut ||= spans.some((span) => spanShut(block, spans, span, range));
|
|
227
|
+
shut ||= emptyControlsIn(block).some(
|
|
228
|
+
(control) => containerShut(control.node, control.span, range)
|
|
159
229
|
);
|
|
160
230
|
return false;
|
|
161
231
|
});
|
|
@@ -259,14 +329,18 @@ function intentShut(doc, intent) {
|
|
|
259
329
|
}
|
|
260
330
|
var lockGuard = {
|
|
261
331
|
name: "lock",
|
|
262
|
-
liftedBy: [unlockAllowed, historyReplay, controlLifted],
|
|
332
|
+
liftedBy: [unlockAllowed, historyReplay, controlLifted, controlKept],
|
|
263
333
|
step: (step, before) => stepAllowed(step, before),
|
|
264
334
|
shuts: (intent, state) => intentShut(state.doc, intent)
|
|
265
335
|
};
|
|
266
336
|
export {
|
|
267
337
|
carriesLock,
|
|
338
|
+
controlKept,
|
|
268
339
|
controlLifted,
|
|
269
340
|
controlSpans,
|
|
341
|
+
controlsWrittenInto,
|
|
342
|
+
coversWhole,
|
|
343
|
+
emptyControlsIn,
|
|
270
344
|
historyReplay,
|
|
271
345
|
isLockedContainer,
|
|
272
346
|
lockGuard,
|
|
@@ -42,6 +42,8 @@ export declare const editorClassNames: {
|
|
|
42
42
|
readonly sdtBlock: "docx-editor-sdt-block";
|
|
43
43
|
/** A content control with nothing inside it, which stands on the page as nothing */
|
|
44
44
|
readonly sdtEmpty: "docx-editor-sdt-empty";
|
|
45
|
+
/** The same control standing inside a paragraph, which takes no width between the words */
|
|
46
|
+
readonly sdtEmptyInline: "docx-editor-sdt-empty-inline";
|
|
45
47
|
/** Attached alongside it when the control says its contents may not be edited */
|
|
46
48
|
readonly sdtLocked: "docx-editor-sdt-locked";
|
|
47
49
|
/** A stretch of text inside a hyperlink (`w:hyperlink`) */
|
|
@@ -120,6 +122,8 @@ export declare const editorClassNames: {
|
|
|
120
122
|
/** The keyboard shortcut written on the right of a menu row */
|
|
121
123
|
readonly menuHint: "docx-editor-menu-hint";
|
|
122
124
|
readonly menuSeparator: "docx-editor-menu-sep";
|
|
125
|
+
/** The line at the head of a menu saying why its editing entries stand disabled */
|
|
126
|
+
readonly menuNote: "docx-editor-menu-note";
|
|
123
127
|
/** The panel that reads and writes a link's address, floated over the selection */
|
|
124
128
|
readonly linkPanel: "docx-editor-link-panel";
|
|
125
129
|
/** The field the address is typed into */
|
|
@@ -37,6 +37,8 @@ var editorClassNames = {
|
|
|
37
37
|
sdtBlock: `${PREFIX}-sdt-block`,
|
|
38
38
|
/** A content control with nothing inside it, which stands on the page as nothing */
|
|
39
39
|
sdtEmpty: `${PREFIX}-sdt-empty`,
|
|
40
|
+
/** The same control standing inside a paragraph, which takes no width between the words */
|
|
41
|
+
sdtEmptyInline: `${PREFIX}-sdt-empty-inline`,
|
|
40
42
|
/** Attached alongside it when the control says its contents may not be edited */
|
|
41
43
|
sdtLocked: `${PREFIX}-sdt-locked`,
|
|
42
44
|
/** A stretch of text inside a hyperlink (`w:hyperlink`) */
|
|
@@ -116,6 +118,8 @@ var editorClassNames = {
|
|
|
116
118
|
/** The keyboard shortcut written on the right of a menu row */
|
|
117
119
|
menuHint: `${PREFIX}-menu-hint`,
|
|
118
120
|
menuSeparator: `${PREFIX}-menu-sep`,
|
|
121
|
+
/** The line at the head of a menu saying why its editing entries stand disabled */
|
|
122
|
+
menuNote: `${PREFIX}-menu-note`,
|
|
119
123
|
/** The panel that reads and writes a link's address, floated over the selection */
|
|
120
124
|
linkPanel: `${PREFIX}-link-panel`,
|
|
121
125
|
/** The field the address is typed into */
|