@portone/docx-editor 0.6.3 → 0.6.4
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 +29 -0
- 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/inlineControlEdits.d.ts +20 -0
- package/dist/editor/inlineControlEdits.js +69 -0
- package/dist/editor/plugins/keymap.js +18 -7
- 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 +27 -13
- package/dist/schema/controlAttrs.js +14 -6
- package/dist/schema/docxSchema.d.ts +1 -1
- package/dist/schema/docxSchema.js +60 -5
- package/dist/schema/locks.d.ts +37 -5
- package/dist/schema/locks.js +33 -15
- package/dist/styles/classNames.d.ts +2 -0
- package/dist/styles/classNames.js +2 -0
- package/dist/styles.css +13 -0
- package/package.json +1 -1
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,8 @@ export declare const historyReplay: PluginKey<boolean>;
|
|
|
36
37
|
* (`spec/notes/contentControls.md`).
|
|
37
38
|
*/
|
|
38
39
|
export declare const controlLifted: PluginKey<boolean>;
|
|
39
|
-
|
|
40
|
+
/** The stretch a judgement or an edit runs over */
|
|
41
|
+
export interface StepRange {
|
|
40
42
|
from: number;
|
|
41
43
|
to: number;
|
|
42
44
|
}
|
|
@@ -51,10 +53,14 @@ export declare function lockedMarkOf(node: PMNode | null | undefined): Mark | nu
|
|
|
51
53
|
export declare function isLockedContainer(node: PMNode | null | undefined): boolean;
|
|
52
54
|
/**
|
|
53
55
|
* Whether this node carries a lock of either clause, an inline one wearing a control's mark and a
|
|
54
|
-
*
|
|
56
|
+
* carrier standing for one alike.
|
|
55
57
|
* This is the question about the document holding a lock at all rather than about editing a spot,
|
|
56
58
|
* so a control locked against deletion alone counts (`editor/commands/lockCommands`). A `w:group`
|
|
57
59
|
* is not a lock and does not: it shuts its contents, and there is nothing in it to lift.
|
|
60
|
+
*
|
|
61
|
+
* Both are asked of every node rather than one or the other: a control holding nothing states its
|
|
62
|
+
* own lock in its attributes and wears the marks of the wrappers around it at the same time
|
|
63
|
+
* (`docx/wrappers`), so reading only the marks would miss the lock it states itself.
|
|
58
64
|
*/
|
|
59
65
|
export declare function carriesLock(node: PMNode): boolean;
|
|
60
66
|
/** A textblock a judgement or an edit runs through, and where its content begins */
|
|
@@ -77,6 +83,33 @@ export interface ControlSpan extends StepRange {
|
|
|
77
83
|
* overlap: each locks on its own terms.
|
|
78
84
|
*/
|
|
79
85
|
export declare function controlSpans(block: Textblock): ControlSpan[];
|
|
86
|
+
/**
|
|
87
|
+
* Whether the stretch covers this control from end to end, which is the control going whole.
|
|
88
|
+
*
|
|
89
|
+
* This is also what reaches a control that draws nothing, since it holds no spot a caret could
|
|
90
|
+
* stand in: a selection merely resting at its edge points at no control the user can see
|
|
91
|
+
* (`editor/commands/lockCommands`).
|
|
92
|
+
*/
|
|
93
|
+
export declare function coversWhole(range: StepRange, span: StepRange): boolean;
|
|
94
|
+
/** One content control holding nothing, standing as a node of its own, as the one spot it covers */
|
|
95
|
+
export interface EmptyControl {
|
|
96
|
+
node: PMNode;
|
|
97
|
+
span: StepRange;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Every control holding nothing that stands among the inlines of this textblock, each as the one
|
|
101
|
+
* spot it covers.
|
|
102
|
+
*
|
|
103
|
+
* Such a control carries what it states in its own attributes rather than in a mark
|
|
104
|
+
* (`docx/wrappers`), so `controlSpans` never meets it and the walk below never reaches it:
|
|
105
|
+
* a textblock is where `nodesBetween` is told to stop.
|
|
106
|
+
*
|
|
107
|
+
* One walk answers both the lock guard and the menu that lifts a lock
|
|
108
|
+
* (`editor/commands/lockCommands`), so the two cannot come to disagree about what stands here. It
|
|
109
|
+
* looks for controls holding nothing and for no other carrier: both callers judge what it finds by
|
|
110
|
+
* rules written for a node with nothing inside it.
|
|
111
|
+
*/
|
|
112
|
+
export declare function emptyControlsIn(block: Textblock): EmptyControl[];
|
|
80
113
|
/**
|
|
81
114
|
* Whether a lock shuts editing where this selection stands, which is what a menu that would lift a
|
|
82
115
|
* lock is built on (`editor/commands/lockCommands`).
|
|
@@ -96,4 +129,3 @@ export declare function selectionShut(selection: Selection, doc: PMNode): boolea
|
|
|
96
129
|
* history replays is the reverse of a step that passed the guard when it was made.
|
|
97
130
|
*/
|
|
98
131
|
export declare const lockGuard: StepGuard;
|
|
99
|
-
export {};
|
package/dist/schema/locks.js
CHANGED
|
@@ -9,7 +9,11 @@ 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");
|
|
@@ -59,16 +63,12 @@ function containerLocks(node) {
|
|
|
59
63
|
function isLockedContainer(node) {
|
|
60
64
|
return shutsAlone(containerLocks(node));
|
|
61
65
|
}
|
|
66
|
+
function statesLock(locks) {
|
|
67
|
+
return locks.contents || locks.deletion;
|
|
68
|
+
}
|
|
62
69
|
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
|
-
});
|
|
70
|
+
if (statesLock(containerLocks(node))) return true;
|
|
71
|
+
return sdtMarksOf(node).some((mark) => statesLock(markLocks(mark)));
|
|
72
72
|
}
|
|
73
73
|
function controlSpans(block) {
|
|
74
74
|
const spans = [];
|
|
@@ -134,21 +134,34 @@ function supersededSpan(spans, span, range) {
|
|
|
134
134
|
(inner) => inner !== span && coversWhole(span, inner) && coversWhole(inner, range)
|
|
135
135
|
);
|
|
136
136
|
}
|
|
137
|
+
function containerShut(node, span, range) {
|
|
138
|
+
if (!coversWhole(range, span)) return false;
|
|
139
|
+
const locks = containerLocks(node);
|
|
140
|
+
return range.takesAway ? locks.deletion : shutsAlone(locks) && node.content.size > 0;
|
|
141
|
+
}
|
|
142
|
+
function emptyControlsIn(block) {
|
|
143
|
+
const found = [];
|
|
144
|
+
block.node.forEach((child, offset) => {
|
|
145
|
+
if (!isEmptyInlineControl(child)) return;
|
|
146
|
+
const from = block.start + offset;
|
|
147
|
+
found.push({ node: child, span: { from, to: from + child.nodeSize } });
|
|
148
|
+
});
|
|
149
|
+
return found;
|
|
150
|
+
}
|
|
137
151
|
function rangeShut(doc, range) {
|
|
138
152
|
if (reachesLockedContainer(doc, range)) return true;
|
|
139
153
|
let shut = false;
|
|
140
154
|
doc.nodesBetween(range.from, range.to, (node, pos) => {
|
|
141
155
|
if (shut) return false;
|
|
142
156
|
if (controlAttrsOf(node) !== null) {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
const edits = shutsAlone(locks) && node.content.size > 0;
|
|
146
|
-
if (range.takesAway ? locks.deletion : edits) shut = true;
|
|
157
|
+
if (containerShut(node, { from: pos, to: pos + node.nodeSize }, range)) {
|
|
158
|
+
shut = true;
|
|
147
159
|
}
|
|
148
160
|
return !shut;
|
|
149
161
|
}
|
|
150
162
|
if (!node.isTextblock) return true;
|
|
151
|
-
const
|
|
163
|
+
const block = { node, start: pos + 1 };
|
|
164
|
+
const spans = controlSpans(block);
|
|
152
165
|
shut ||= spans.some(
|
|
153
166
|
(span) => shuts(
|
|
154
167
|
markLocks(span.mark),
|
|
@@ -157,6 +170,9 @@ function rangeShut(doc, range) {
|
|
|
157
170
|
supersededSpan(spans, span, range)
|
|
158
171
|
)
|
|
159
172
|
);
|
|
173
|
+
shut ||= emptyControlsIn(block).some(
|
|
174
|
+
(control) => containerShut(control.node, control.span, range)
|
|
175
|
+
);
|
|
160
176
|
return false;
|
|
161
177
|
});
|
|
162
178
|
return shut;
|
|
@@ -267,6 +283,8 @@ export {
|
|
|
267
283
|
carriesLock,
|
|
268
284
|
controlLifted,
|
|
269
285
|
controlSpans,
|
|
286
|
+
coversWhole,
|
|
287
|
+
emptyControlsIn,
|
|
270
288
|
historyReplay,
|
|
271
289
|
isLockedContainer,
|
|
272
290
|
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`) */
|
|
@@ -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`) */
|
package/dist/styles.css
CHANGED
|
@@ -1028,6 +1028,19 @@ button.docx-editor-comment-body {
|
|
|
1028
1028
|
outline: none;
|
|
1029
1029
|
}
|
|
1030
1030
|
|
|
1031
|
+
/*
|
|
1032
|
+
* The same control standing inside a paragraph, which takes no width between the words either
|
|
1033
|
+
* side of it: the file says a phrase is not there, and a box drawn for it would be a phrase of its
|
|
1034
|
+
* own. This is the shape a preserved fragment with nothing to show takes above.
|
|
1035
|
+
*/
|
|
1036
|
+
.docx-editor-sdt-empty-inline {
|
|
1037
|
+
display: inline-block;
|
|
1038
|
+
width: 0;
|
|
1039
|
+
overflow: hidden;
|
|
1040
|
+
outline: none;
|
|
1041
|
+
vertical-align: baseline;
|
|
1042
|
+
}
|
|
1043
|
+
|
|
1031
1044
|
/*
|
|
1032
1045
|
* The space a block-level content control opens between two of the blocks it holds, so what
|
|
1033
1046
|
* follows starts the next page (`page/kinds/sdtBlockKind`). The control's own outline runs down
|