@portone/docx-editor 0.6.2 → 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 +91 -0
- package/dist/DocxEditor.js +2 -2
- 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 +8 -15
- package/dist/docx/identities.d.ts +9 -2
- package/dist/docx/identities.js +45 -12
- 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/importPolicy.d.ts +2 -2
- package/dist/docx/importPolicy.js +12 -5
- package/dist/docx/importPreserved.d.ts +3 -3
- package/dist/docx/importSdtBlock.d.ts +23 -0
- package/dist/docx/importSdtBlock.js +33 -0
- package/dist/docx/importTable.js +35 -24
- package/dist/docx/invariants.js +60 -3
- package/dist/docx/notes/numbering.js +4 -4
- package/dist/docx/notes/references.d.ts +0 -2
- package/dist/docx/notes/references.js +2 -7
- 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 +79 -9
- package/dist/docx/sdt.js +121 -26
- package/dist/docx/sections.d.ts +13 -13
- package/dist/docx/sections.js +34 -20
- package/dist/docx/serializeBlock.js +10 -1
- package/dist/docx/serializeParagraph.d.ts +2 -1
- package/dist/docx/serializeParagraph.js +6 -1
- package/dist/docx/serializeSdtBlock.d.ts +16 -0
- package/dist/docx/serializeSdtBlock.js +11 -0
- package/dist/docx/serializeTable.d.ts +8 -2
- package/dist/docx/serializeTable.js +14 -20
- package/dist/docx/story.d.ts +10 -4
- package/dist/docx/story.js +25 -20
- package/dist/docx/storyBlocks.d.ts +32 -0
- package/dist/docx/storyBlocks.js +65 -0
- package/dist/docx/storyParts.d.ts +3 -0
- package/dist/docx/storyParts.js +4 -1
- package/dist/docx/wrappers.d.ts +33 -15
- package/dist/docx/wrappers.js +45 -26
- package/dist/editor/blockControlEdits.d.ts +15 -0
- package/dist/editor/blockControlEdits.js +79 -0
- package/dist/editor/clipboard/normalizers.js +1 -1
- package/dist/editor/commands/lockCommands.d.ts +5 -1
- package/dist/editor/commands/lockCommands.js +51 -23
- package/dist/editor/createEditor.js +4 -0
- package/dist/editor/inlineControlEdits.d.ts +20 -0
- package/dist/editor/inlineControlEdits.js +69 -0
- package/dist/editor/notes/noteSurface.js +4 -3
- package/dist/editor/plugins/controlLifecycle.d.ts +18 -0
- package/dist/editor/plugins/controlLifecycle.js +130 -0
- package/dist/editor/plugins/keymap.js +34 -5
- package/dist/editor/plugins/rowResize.js +2 -4
- package/dist/editor/stories/storyState.d.ts +2 -0
- package/dist/editor/stories/storyState.js +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/page/blockKinds.d.ts +24 -2
- package/dist/page/blockKinds.js +6 -1
- package/dist/page/kinds/index.d.ts +5 -0
- package/dist/page/kinds/index.js +2 -0
- package/dist/page/kinds/sdtBlockKind.d.ts +14 -0
- package/dist/page/kinds/sdtBlockKind.js +143 -0
- package/dist/page/measureBlocks.js +4 -2
- package/dist/page/pageDecorations.js +3 -2
- package/dist/page/pageLayout.d.ts +16 -15
- package/dist/page/pageLayout.js +134 -67
- package/dist/page/usePageLayout.d.ts +2 -2
- package/dist/page/usePageLayout.js +5 -5
- package/dist/schema/attrRoles.js +56 -1
- package/dist/schema/clipboard.js +11 -0
- package/dist/schema/controlAttrs.d.ts +119 -0
- package/dist/schema/controlAttrs.js +137 -0
- package/dist/schema/controlEdges.d.ts +22 -0
- package/dist/schema/controlEdges.js +50 -0
- package/dist/schema/docxSchema.d.ts +1 -1
- package/dist/schema/docxSchema.js +235 -37
- package/dist/schema/editGuard.d.ts +1 -1
- package/dist/schema/guards.js +2 -0
- package/dist/schema/locks.d.ts +56 -8
- package/dist/schema/locks.js +115 -56
- package/dist/styles/classNames.d.ts +10 -0
- package/dist/styles/classNames.js +10 -0
- package/dist/styles.css +44 -2
- package/dist/table/merge.js +11 -3
- package/dist/table/rowResize.d.ts +9 -0
- package/dist/table/rowResize.js +9 -5
- package/dist/ui/TextMenu.js +2 -0
- package/package.json +3 -3
package/dist/schema/locks.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Evaluates OOXML content and deletion locks for inline controls
|
|
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.
|
|
3
5
|
*
|
|
4
6
|
* `lockGuard` is what `./guards` registers all of this as, and it is the only way in: a caller
|
|
5
7
|
* asking about a lock asks the one guard list, which asks the locks along with every other rule an
|
|
@@ -23,22 +25,42 @@ export declare const unlockAllowed: PluginKey<boolean>;
|
|
|
23
25
|
* refusal would take the whole history behind it down as well.
|
|
24
26
|
*/
|
|
25
27
|
export declare const historyReplay: PluginKey<boolean>;
|
|
26
|
-
|
|
28
|
+
/**
|
|
29
|
+
* The pass the one transaction that settles a control carries
|
|
30
|
+
* (`editor/plugins/controlLifecycle`).
|
|
31
|
+
*
|
|
32
|
+
* A `w:temporary` control is removed when its contents are edited (§17.5.2.43) and a
|
|
33
|
+
* `w:showingPlcHdr` one stops claiming to hold placeholder text, neither of which a user asks for
|
|
34
|
+
* and neither of which a lock or a control's edge would let through. The transaction carrying this
|
|
35
|
+
* holds nothing but those two writes, and what a lock does say about them - that a control locked
|
|
36
|
+
* against deletion keeps its wrapper - is settled there rather than by a refusal here
|
|
37
|
+
* (`spec/notes/contentControls.md`).
|
|
38
|
+
*/
|
|
39
|
+
export declare const controlLifted: PluginKey<boolean>;
|
|
40
|
+
/** The stretch a judgement or an edit runs over */
|
|
41
|
+
export interface StepRange {
|
|
27
42
|
from: number;
|
|
28
43
|
to: number;
|
|
29
44
|
}
|
|
30
45
|
/**
|
|
31
46
|
* The control shutting the contents this inline node is part of. Null when it sits in no control,
|
|
32
|
-
* or in
|
|
47
|
+
* or in none that shuts, a control locked against deletion alone included.
|
|
48
|
+
*
|
|
49
|
+
* This is about the node rather than about a spot inside it, so nothing here supersedes a group.
|
|
33
50
|
*/
|
|
34
51
|
export declare function lockedMarkOf(node: PMNode | null | undefined): Mark | null;
|
|
35
|
-
/** Whether the control
|
|
36
|
-
export declare function
|
|
52
|
+
/** Whether the control this container stands for shuts its contents (`schema`) */
|
|
53
|
+
export declare function isLockedContainer(node: PMNode | null | undefined): boolean;
|
|
37
54
|
/**
|
|
38
55
|
* Whether this node carries a lock of either clause, an inline one wearing a control's mark and a
|
|
39
|
-
*
|
|
56
|
+
* carrier standing for one alike.
|
|
40
57
|
* This is the question about the document holding a lock at all rather than about editing a spot,
|
|
41
|
-
* so a control locked against deletion alone counts (`editor/commands/lockCommands`).
|
|
58
|
+
* so a control locked against deletion alone counts (`editor/commands/lockCommands`). A `w:group`
|
|
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.
|
|
42
64
|
*/
|
|
43
65
|
export declare function carriesLock(node: PMNode): boolean;
|
|
44
66
|
/** A textblock a judgement or an edit runs through, and where its content begins */
|
|
@@ -61,6 +83,33 @@ export interface ControlSpan extends StepRange {
|
|
|
61
83
|
* overlap: each locks on its own terms.
|
|
62
84
|
*/
|
|
63
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[];
|
|
64
113
|
/**
|
|
65
114
|
* Whether a lock shuts editing where this selection stands, which is what a menu that would lift a
|
|
66
115
|
* lock is built on (`editor/commands/lockCommands`).
|
|
@@ -80,4 +129,3 @@ export declare function selectionShut(selection: Selection, doc: PMNode): boolea
|
|
|
80
129
|
* history replays is the reverse of a step that passed the guard when it was made.
|
|
81
130
|
*/
|
|
82
131
|
export declare const lockGuard: StepGuard;
|
|
83
|
-
export {};
|
package/dist/schema/locks.js
CHANGED
|
@@ -9,48 +9,66 @@ import {
|
|
|
9
9
|
ReplaceAroundStep,
|
|
10
10
|
ReplaceStep
|
|
11
11
|
} from "prosemirror-transform";
|
|
12
|
+
import {
|
|
13
|
+
controlAttrsOf,
|
|
14
|
+
controlFactsOf,
|
|
15
|
+
isEmptyInlineControl
|
|
16
|
+
} from "./controlAttrs.js";
|
|
12
17
|
import { docxSchema } from "./index.js";
|
|
13
18
|
import { wrappersOf } from "./wrappers.js";
|
|
14
19
|
var unlockAllowed = new PluginKey("docxEditorUnlockAllowed");
|
|
15
20
|
var historyReplay = new PluginKey("docxEditorHistoryReplay");
|
|
16
|
-
var
|
|
21
|
+
var controlLifted = new PluginKey("docxEditorControlLifted");
|
|
22
|
+
var OPEN = { contents: false, deletion: false, group: false };
|
|
23
|
+
function shutsContents(locks, inner) {
|
|
24
|
+
return locks.contents || locks.group && !inner;
|
|
25
|
+
}
|
|
26
|
+
function shutsAlone(locks) {
|
|
27
|
+
return shutsContents(locks, false);
|
|
28
|
+
}
|
|
17
29
|
function sdtMarksOf(node) {
|
|
18
30
|
return node ? wrappersOf(node, docxSchema.marks.sdt) : [];
|
|
19
31
|
}
|
|
20
32
|
function markLocks(mark) {
|
|
21
33
|
return {
|
|
22
34
|
contents: mark.attrs.contentsLocked === true,
|
|
23
|
-
deletion: mark.attrs.deletionLocked === true
|
|
35
|
+
deletion: mark.attrs.deletionLocked === true,
|
|
36
|
+
group: mark.attrs.group === true
|
|
24
37
|
};
|
|
25
38
|
}
|
|
26
39
|
function lockedMarkOf(node) {
|
|
27
|
-
return sdtMarksOf(node).find((mark) => markLocks(mark)
|
|
40
|
+
return sdtMarksOf(node).find((mark) => shutsAlone(markLocks(mark))) ?? null;
|
|
28
41
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
42
|
+
function controlsAcross($pos) {
|
|
43
|
+
const after = sdtMarksOf($pos.nodeAfter);
|
|
44
|
+
return sdtMarksOf($pos.nodeBefore).filter(
|
|
45
|
+
(mark) => after.some((other) => other.eq(mark))
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
function marksShut(marks) {
|
|
49
|
+
return marks.some(
|
|
50
|
+
(mark, index) => shutsContents(markLocks(mark), index < marks.length - 1)
|
|
51
|
+
);
|
|
33
52
|
}
|
|
34
|
-
function
|
|
35
|
-
|
|
53
|
+
function containerLocks(node) {
|
|
54
|
+
const names = controlAttrsOf(node);
|
|
55
|
+
if (!node || !names) return OPEN;
|
|
56
|
+
const facts = controlFactsOf(names, node.attrs);
|
|
36
57
|
return {
|
|
37
|
-
contents:
|
|
38
|
-
deletion:
|
|
58
|
+
contents: facts.contentsLocked,
|
|
59
|
+
deletion: facts.deletionLocked,
|
|
60
|
+
group: facts.group
|
|
39
61
|
};
|
|
40
62
|
}
|
|
41
|
-
function
|
|
42
|
-
return
|
|
63
|
+
function isLockedContainer(node) {
|
|
64
|
+
return shutsAlone(containerLocks(node));
|
|
65
|
+
}
|
|
66
|
+
function statesLock(locks) {
|
|
67
|
+
return locks.contents || locks.deletion;
|
|
43
68
|
}
|
|
44
69
|
function carriesLock(node) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
const locks = cellLocks(node);
|
|
48
|
-
return locks.contents || locks.deletion;
|
|
49
|
-
}
|
|
50
|
-
return marks.some((mark) => {
|
|
51
|
-
const locks = markLocks(mark);
|
|
52
|
-
return locks.contents || locks.deletion;
|
|
53
|
-
});
|
|
70
|
+
if (statesLock(containerLocks(node))) return true;
|
|
71
|
+
return sdtMarksOf(node).some((mark) => statesLock(markLocks(mark)));
|
|
54
72
|
}
|
|
55
73
|
function controlSpans(block) {
|
|
56
74
|
const spans = [];
|
|
@@ -76,20 +94,28 @@ function controlSpans(block) {
|
|
|
76
94
|
});
|
|
77
95
|
return spans;
|
|
78
96
|
}
|
|
79
|
-
function
|
|
97
|
+
function lockedContainerContent($pos, inner) {
|
|
98
|
+
let passed = inner;
|
|
80
99
|
for (let depth = $pos.depth; depth > 0; depth -= 1) {
|
|
81
100
|
const node = $pos.node(depth);
|
|
82
|
-
if (
|
|
83
|
-
|
|
84
|
-
|
|
101
|
+
if (controlAttrsOf(node) === null) continue;
|
|
102
|
+
if (shutsContents(containerLocks(node), passed)) {
|
|
103
|
+
const from = $pos.before(depth) + 1;
|
|
104
|
+
return { from, to: from + node.content.size };
|
|
105
|
+
}
|
|
106
|
+
passed = true;
|
|
85
107
|
}
|
|
86
108
|
return null;
|
|
87
109
|
}
|
|
88
|
-
function
|
|
89
|
-
|
|
110
|
+
function lockedContentAt(doc, pos) {
|
|
111
|
+
const $pos = doc.resolve(pos);
|
|
112
|
+
return lockedContainerContent($pos, controlsAcross($pos).length > 0);
|
|
90
113
|
}
|
|
91
|
-
function
|
|
92
|
-
|
|
114
|
+
function insideLockedContainer(doc, pos) {
|
|
115
|
+
return lockedContainerContent(doc.resolve(pos), false) !== null;
|
|
116
|
+
}
|
|
117
|
+
function reachesLockedContainer(doc, range) {
|
|
118
|
+
const content = lockedContentAt(doc, range.from) ?? lockedContentAt(doc, range.to);
|
|
93
119
|
if (!content) return false;
|
|
94
120
|
if (range.from === range.to) return true;
|
|
95
121
|
return range.from < content.to && range.to > content.from;
|
|
@@ -100,24 +126,52 @@ function coversWhole(range, span) {
|
|
|
100
126
|
function overlaps(range, span) {
|
|
101
127
|
return range.from < span.to && range.to > span.from;
|
|
102
128
|
}
|
|
103
|
-
function shuts(locks, range, span) {
|
|
104
|
-
return range.takesAway && coversWhole(range, span) ? locks.deletion : locks
|
|
129
|
+
function shuts(locks, range, span, inner) {
|
|
130
|
+
return range.takesAway && coversWhole(range, span) ? locks.deletion : shutsContents(locks, inner) && overlaps(range, span);
|
|
131
|
+
}
|
|
132
|
+
function supersededSpan(spans, span, range) {
|
|
133
|
+
return spans.some(
|
|
134
|
+
(inner) => inner !== span && coversWhole(span, inner) && coversWhole(inner, range)
|
|
135
|
+
);
|
|
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;
|
|
105
150
|
}
|
|
106
151
|
function rangeShut(doc, range) {
|
|
107
|
-
if (
|
|
152
|
+
if (reachesLockedContainer(doc, range)) return true;
|
|
108
153
|
let shut = false;
|
|
109
154
|
doc.nodesBetween(range.from, range.to, (node, pos) => {
|
|
110
155
|
if (shut) return false;
|
|
111
|
-
if (
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
if (range.takesAway ? locks.deletion : locks.contents) shut = true;
|
|
156
|
+
if (controlAttrsOf(node) !== null) {
|
|
157
|
+
if (containerShut(node, { from: pos, to: pos + node.nodeSize }, range)) {
|
|
158
|
+
shut = true;
|
|
115
159
|
}
|
|
116
160
|
return !shut;
|
|
117
161
|
}
|
|
118
162
|
if (!node.isTextblock) return true;
|
|
119
|
-
|
|
120
|
-
|
|
163
|
+
const block = { node, start: pos + 1 };
|
|
164
|
+
const spans = controlSpans(block);
|
|
165
|
+
shut ||= spans.some(
|
|
166
|
+
(span) => shuts(
|
|
167
|
+
markLocks(span.mark),
|
|
168
|
+
range,
|
|
169
|
+
span,
|
|
170
|
+
supersededSpan(spans, span, range)
|
|
171
|
+
)
|
|
172
|
+
);
|
|
173
|
+
shut ||= emptyControlsIn(block).some(
|
|
174
|
+
(control) => containerShut(control.node, control.span, range)
|
|
121
175
|
);
|
|
122
176
|
return false;
|
|
123
177
|
});
|
|
@@ -128,10 +182,8 @@ function rangeTouchesLocked(doc, from, to) {
|
|
|
128
182
|
}
|
|
129
183
|
function insertionInsideLocked(doc, pos) {
|
|
130
184
|
const $pos = doc.resolve(pos);
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
const after = lockedMarkOf($pos.nodeAfter);
|
|
134
|
-
return before !== null && after !== null && before.eq(after);
|
|
185
|
+
const inside = controlsAcross($pos);
|
|
186
|
+
return marksShut(inside) || lockedContainerContent($pos, inside.length > 0) !== null;
|
|
135
187
|
}
|
|
136
188
|
function markShut(doc, from, to) {
|
|
137
189
|
return from === to ? insertionInsideLocked(doc, from) : rangeTouchesLocked(doc, from, to);
|
|
@@ -164,7 +216,7 @@ function rangeAllowed(doc, range) {
|
|
|
164
216
|
}
|
|
165
217
|
function plantedLock(node) {
|
|
166
218
|
if (node.isInline) return lockedMarkOf(node) !== null;
|
|
167
|
-
return
|
|
219
|
+
return isLockedContainer(node) && node.content.size > 0;
|
|
168
220
|
}
|
|
169
221
|
function lockedInside(content) {
|
|
170
222
|
let found = false;
|
|
@@ -179,25 +231,29 @@ function plantsLocked(step) {
|
|
|
179
231
|
const carried = step instanceof ReplaceStep || step instanceof ReplaceAroundStep ? step.slice.content : null;
|
|
180
232
|
return carried !== null && lockedInside(carried);
|
|
181
233
|
}
|
|
182
|
-
function
|
|
234
|
+
function clearsContainerLock(step, doc) {
|
|
183
235
|
if (step instanceof AttrStep) {
|
|
184
236
|
if (step.value === true) return false;
|
|
185
|
-
const
|
|
186
|
-
|
|
187
|
-
if (
|
|
237
|
+
const at = doc.nodeAt(step.pos);
|
|
238
|
+
const names = controlAttrsOf(at);
|
|
239
|
+
if (!names) return false;
|
|
240
|
+
const locks = containerLocks(at);
|
|
241
|
+
if (step.attr === names.contentsLocked) return locks.contents;
|
|
242
|
+
if (step.attr === names.deletionLocked) return locks.deletion;
|
|
243
|
+
if (step.attr === names.group) return locks.group;
|
|
188
244
|
return false;
|
|
189
245
|
}
|
|
190
246
|
if (!(step instanceof ReplaceAroundStep)) return false;
|
|
191
|
-
const was =
|
|
192
|
-
const now =
|
|
193
|
-
return was.contents && !now.contents || was.deletion && !now.deletion;
|
|
247
|
+
const was = containerLocks(doc.nodeAt(step.from));
|
|
248
|
+
const now = containerLocks(step.slice.content.firstChild);
|
|
249
|
+
return was.contents && !now.contents || was.deletion && !now.deletion || was.group && !now.group;
|
|
194
250
|
}
|
|
195
251
|
function stepAllowed(step, doc) {
|
|
196
|
-
if (plantsLocked(step) ||
|
|
252
|
+
if (plantsLocked(step) || clearsContainerLock(step, doc)) return false;
|
|
197
253
|
const ranges = editedRanges(step);
|
|
198
254
|
if (ranges) return ranges.every((range) => rangeAllowed(doc, range));
|
|
199
255
|
if (step instanceof AttrStep || step instanceof AddNodeMarkStep || step instanceof RemoveNodeMarkStep) {
|
|
200
|
-
return
|
|
256
|
+
return lockedContainerContent(doc.resolve(step.pos), false) === null && lockedMarkOf(doc.nodeAt(step.pos)) === null;
|
|
201
257
|
}
|
|
202
258
|
return true;
|
|
203
259
|
}
|
|
@@ -206,7 +262,7 @@ function intentShut(doc, intent) {
|
|
|
206
262
|
case "insert":
|
|
207
263
|
return insertionInsideLocked(doc, intent.at);
|
|
208
264
|
case "block":
|
|
209
|
-
return
|
|
265
|
+
return insideLockedContainer(doc, intent.at);
|
|
210
266
|
case "mark":
|
|
211
267
|
return markShut(doc, intent.from, intent.to);
|
|
212
268
|
case "replace":
|
|
@@ -219,15 +275,18 @@ function intentShut(doc, intent) {
|
|
|
219
275
|
}
|
|
220
276
|
var lockGuard = {
|
|
221
277
|
name: "lock",
|
|
222
|
-
liftedBy: [unlockAllowed, historyReplay],
|
|
278
|
+
liftedBy: [unlockAllowed, historyReplay, controlLifted],
|
|
223
279
|
step: (step, before) => stepAllowed(step, before),
|
|
224
280
|
shuts: (intent, state) => intentShut(state.doc, intent)
|
|
225
281
|
};
|
|
226
282
|
export {
|
|
227
283
|
carriesLock,
|
|
284
|
+
controlLifted,
|
|
228
285
|
controlSpans,
|
|
286
|
+
coversWhole,
|
|
287
|
+
emptyControlsIn,
|
|
229
288
|
historyReplay,
|
|
230
|
-
|
|
289
|
+
isLockedContainer,
|
|
231
290
|
lockGuard,
|
|
232
291
|
lockedMarkOf,
|
|
233
292
|
selectionShut,
|
|
@@ -31,11 +31,19 @@ export declare const editorClassNames: {
|
|
|
31
31
|
readonly imageHandle: "docx-editor-img-handle";
|
|
32
32
|
readonly table: "docx-editor-tbl";
|
|
33
33
|
readonly tableRow: "docx-editor-tr";
|
|
34
|
+
/** Attached alongside it when the control around the row says the row may not be edited */
|
|
35
|
+
readonly rowLocked: "docx-editor-tr-locked";
|
|
34
36
|
readonly tableCell: "docx-editor-tc";
|
|
35
37
|
/** Attached alongside it when the control around the cell says the cell may not be edited */
|
|
36
38
|
readonly cellLocked: "docx-editor-tc-locked";
|
|
37
39
|
/** A stretch of text sitting inside a content control (`w:sdt`) */
|
|
38
40
|
readonly sdt: "docx-editor-sdt";
|
|
41
|
+
/** The blocks a block-level content control (`w:sdt` under the body or a cell) holds */
|
|
42
|
+
readonly sdtBlock: "docx-editor-sdt-block";
|
|
43
|
+
/** A content control with nothing inside it, which stands on the page as nothing */
|
|
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";
|
|
39
47
|
/** Attached alongside it when the control says its contents may not be edited */
|
|
40
48
|
readonly sdtLocked: "docx-editor-sdt-locked";
|
|
41
49
|
/** A stretch of text inside a hyperlink (`w:hyperlink`) */
|
|
@@ -224,6 +232,8 @@ export declare const editorAttributes: {
|
|
|
224
232
|
readonly pageBreakSpace: "data-page-space";
|
|
225
233
|
/** A display-only table row that fills the remainder between page bodies */
|
|
226
234
|
readonly tablePageSpace: "data-table-page-space";
|
|
235
|
+
/** The space a block-level content control opens between two of the blocks it holds */
|
|
236
|
+
readonly containerPageSpace: "data-container-page-space";
|
|
227
237
|
/** A display-only copy of a table header row on a continued page */
|
|
228
238
|
readonly tableRepeatedHeader: "data-table-repeated-header";
|
|
229
239
|
/**
|
|
@@ -26,11 +26,19 @@ var editorClassNames = {
|
|
|
26
26
|
imageHandle: `${PREFIX}-img-handle`,
|
|
27
27
|
table: `${PREFIX}-tbl`,
|
|
28
28
|
tableRow: `${PREFIX}-tr`,
|
|
29
|
+
/** Attached alongside it when the control around the row says the row may not be edited */
|
|
30
|
+
rowLocked: `${PREFIX}-tr-locked`,
|
|
29
31
|
tableCell: `${PREFIX}-tc`,
|
|
30
32
|
/** Attached alongside it when the control around the cell says the cell may not be edited */
|
|
31
33
|
cellLocked: `${PREFIX}-tc-locked`,
|
|
32
34
|
/** A stretch of text sitting inside a content control (`w:sdt`) */
|
|
33
35
|
sdt: `${PREFIX}-sdt`,
|
|
36
|
+
/** The blocks a block-level content control (`w:sdt` under the body or a cell) holds */
|
|
37
|
+
sdtBlock: `${PREFIX}-sdt-block`,
|
|
38
|
+
/** A content control with nothing inside it, which stands on the page as nothing */
|
|
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`,
|
|
34
42
|
/** Attached alongside it when the control says its contents may not be edited */
|
|
35
43
|
sdtLocked: `${PREFIX}-sdt-locked`,
|
|
36
44
|
/** A stretch of text inside a hyperlink (`w:hyperlink`) */
|
|
@@ -213,6 +221,8 @@ var editorAttributes = {
|
|
|
213
221
|
pageBreakSpace: "data-page-space",
|
|
214
222
|
/** A display-only table row that fills the remainder between page bodies */
|
|
215
223
|
tablePageSpace: "data-table-page-space",
|
|
224
|
+
/** The space a block-level content control opens between two of the blocks it holds */
|
|
225
|
+
containerPageSpace: "data-container-page-space",
|
|
216
226
|
/** A display-only copy of a table header row on a continued page */
|
|
217
227
|
tableRepeatedHeader: "data-table-repeated-header",
|
|
218
228
|
/**
|
package/dist/styles.css
CHANGED
|
@@ -1016,10 +1016,52 @@ button.docx-editor-comment-body {
|
|
|
1016
1016
|
}
|
|
1017
1017
|
|
|
1018
1018
|
/*
|
|
1019
|
-
* A
|
|
1019
|
+
* A content control that holds nothing occupies nothing on the page: the file says a clause is not
|
|
1020
|
+
* there, and a box drawn for it would be a clause of its own.
|
|
1021
|
+
* A shut control wears the yellow above beside this class, and an outline is painted outside the
|
|
1022
|
+
* box rather than clipped by it, so a zero height alone would leave a 1px rule across the page.
|
|
1023
|
+
*/
|
|
1024
|
+
.docx-editor-sdt-empty {
|
|
1025
|
+
display: block;
|
|
1026
|
+
height: 0;
|
|
1027
|
+
overflow: hidden;
|
|
1028
|
+
outline: none;
|
|
1029
|
+
}
|
|
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
|
+
|
|
1044
|
+
/*
|
|
1045
|
+
* The space a block-level content control opens between two of the blocks it holds, so what
|
|
1046
|
+
* follows starts the next page (`page/kinds/sdtBlockKind`). The control's own outline runs down
|
|
1047
|
+
* both pieces of the cut and needs nothing drawn here, but the background a shut control paints
|
|
1048
|
+
* would run down the rest of the page with it, so the space paints the paper back over it. The
|
|
1049
|
+
* gutter below is broken by `.docx-editor-page-split`, which is drawn over the sheet.
|
|
1050
|
+
*/
|
|
1051
|
+
.docx-editor-sdt-block > [data-container-page-space] {
|
|
1052
|
+
pointer-events: none;
|
|
1053
|
+
user-select: none;
|
|
1054
|
+
line-height: 0;
|
|
1055
|
+
background: #ffffff;
|
|
1056
|
+
}
|
|
1057
|
+
|
|
1058
|
+
/*
|
|
1059
|
+
* A whole cell shut by the control around it, and the cells of a whole row shut by the control
|
|
1060
|
+
* around the row, which carry no lock of their own. The same yellow, outlined just inside the cell
|
|
1020
1061
|
* border so the mark follows the cell rather than the text standing in it.
|
|
1021
1062
|
*/
|
|
1022
|
-
.docx-editor-tc-locked
|
|
1063
|
+
.docx-editor-tc-locked,
|
|
1064
|
+
.docx-editor-tr-locked > .docx-editor-tc {
|
|
1023
1065
|
background: #fff59d;
|
|
1024
1066
|
outline: 1px solid #f9a825;
|
|
1025
1067
|
outline-offset: -1px;
|
package/dist/table/merge.js
CHANGED
|
@@ -11,6 +11,12 @@ import {
|
|
|
11
11
|
widthNumber,
|
|
12
12
|
withWidthNumber
|
|
13
13
|
} from "../model/format.js";
|
|
14
|
+
import {
|
|
15
|
+
controlAttrs,
|
|
16
|
+
controlFactsOf,
|
|
17
|
+
NO_CONTROL,
|
|
18
|
+
WRAPPED_CONTROL_ATTRS
|
|
19
|
+
} from "../schema/controlAttrs.js";
|
|
14
20
|
import { guardedCommand } from "../schema/guards.js";
|
|
15
21
|
import { inheritCellAttrs } from "./format.js";
|
|
16
22
|
import { cellWidthForGridCol, gridSpanWidth, tableGridCols } from "./widths.js";
|
|
@@ -98,9 +104,11 @@ function writeSplitFormats(tr, rect, source) {
|
|
|
98
104
|
...cell.attrs,
|
|
99
105
|
...inheritCellAttrs(source, {
|
|
100
106
|
tcW: cellWidthForGridCol(gridCols, col, width, colspan),
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
107
|
+
// Only the cell the merge started at keeps the control the source cell sat inside
|
|
108
|
+
...controlAttrs(
|
|
109
|
+
WRAPPED_CONTROL_ATTRS,
|
|
110
|
+
isOriginalSpot ? controlFactsOf(WRAPPED_CONTROL_ATTRS, source.attrs) : NO_CONTROL
|
|
111
|
+
)
|
|
104
112
|
})
|
|
105
113
|
});
|
|
106
114
|
}
|
|
@@ -11,4 +11,13 @@ export interface RowResize {
|
|
|
11
11
|
export declare function resizedRowHeight(startPt: number, deltaPx: number, scale: number): number;
|
|
12
12
|
/** Absolute document position immediately before one row in a table. */
|
|
13
13
|
export declare function rowPositionAt(tablePos: number, table: PMNode, row: number): number;
|
|
14
|
+
/**
|
|
15
|
+
* Whether this row of the table may be given a height.
|
|
16
|
+
*
|
|
17
|
+
* A row a control shuts, and a row holding a cell a control shuts, are both rows whose content the
|
|
18
|
+
* document says may not be edited, and a height is what that content is drawn in. The pointer
|
|
19
|
+
* affordance asks the same question, so the handle never appears where the drag would be refused
|
|
20
|
+
* (`editor/plugins/rowResize`).
|
|
21
|
+
*/
|
|
22
|
+
export declare function isRowResizable(table: PMNode, row: number): boolean;
|
|
14
23
|
export declare function buildResizeRowTransaction(state: EditorState, resize: RowResize): Transaction | null;
|
package/dist/table/rowResize.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// src/table/rowResize.ts
|
|
2
2
|
import { editRowHeight } from "../docx/tableFormatting.js";
|
|
3
3
|
import { toRowFormat } from "../model/format.js";
|
|
4
|
-
import {
|
|
4
|
+
import { isLockedContainer } from "../schema/locks.js";
|
|
5
5
|
var MIN_ROW_HEIGHT_PT = 6;
|
|
6
6
|
function resizedRowHeight(startPt, deltaPx, scale) {
|
|
7
7
|
const effectiveScale = Number.isFinite(scale) && scale > 0 ? scale : 1;
|
|
@@ -14,13 +14,16 @@ function rowPositionAt(tablePos, table, row) {
|
|
|
14
14
|
pos += table.child(index).nodeSize;
|
|
15
15
|
return pos;
|
|
16
16
|
}
|
|
17
|
+
function isRowResizable(table, row) {
|
|
18
|
+
if (row < 0 || row >= table.childCount) return false;
|
|
19
|
+
const node = table.child(row);
|
|
20
|
+
return !isLockedContainer(node) && !node.children.some(isLockedContainer);
|
|
21
|
+
}
|
|
17
22
|
function buildResizeRowTransaction(state, resize) {
|
|
18
23
|
const table = state.doc.nodeAt(resize.tablePos);
|
|
19
|
-
if (
|
|
20
|
-
|
|
21
|
-
}
|
|
24
|
+
if (table?.type.spec.tableRole !== "table") return null;
|
|
25
|
+
if (!isRowResizable(table, resize.row)) return null;
|
|
22
26
|
const row = table.child(resize.row);
|
|
23
|
-
if (row.children.some(isLockedCell)) return null;
|
|
24
27
|
const edited = editRowHeight(
|
|
25
28
|
typeof row.attrs.trPr === "string" ? row.attrs.trPr : null,
|
|
26
29
|
resize.heightPt
|
|
@@ -39,6 +42,7 @@ function buildResizeRowTransaction(state, resize) {
|
|
|
39
42
|
export {
|
|
40
43
|
MIN_ROW_HEIGHT_PT,
|
|
41
44
|
buildResizeRowTransaction,
|
|
45
|
+
isRowResizable,
|
|
42
46
|
resizedRowHeight,
|
|
43
47
|
rowPositionAt
|
|
44
48
|
};
|
package/dist/ui/TextMenu.js
CHANGED
|
@@ -79,6 +79,8 @@ function lockItem(lock, run) {
|
|
|
79
79
|
};
|
|
80
80
|
switch (lock) {
|
|
81
81
|
case "none":
|
|
82
|
+
// Contents a control shuts on its own terms offer neither a lock nor a lift
|
|
83
|
+
case "shut":
|
|
82
84
|
return { ...locking, enabled: false };
|
|
83
85
|
case "lockable":
|
|
84
86
|
return { ...locking, enabled: true };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@portone/docx-editor",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.4",
|
|
4
4
|
"description": "A simple DOCX editor for React, built directly on OOXML.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
@@ -81,7 +81,7 @@
|
|
|
81
81
|
"@types/jsdom": "^30.0.0",
|
|
82
82
|
"@types/node": "^26.2.0",
|
|
83
83
|
"@types/react": "19.2.18",
|
|
84
|
-
"@types/react-dom": "19.2.
|
|
84
|
+
"@types/react-dom": "19.2.7",
|
|
85
85
|
"@vitejs/plugin-react": "^6.0.5",
|
|
86
86
|
"esbuild": "^0.28.1",
|
|
87
87
|
"jsdom": "^30.0.1",
|
|
@@ -99,7 +99,7 @@
|
|
|
99
99
|
"react-dom": "^19.2.8",
|
|
100
100
|
"typescript": "^7.0.2",
|
|
101
101
|
"vite": "^8.0.12",
|
|
102
|
-
"vitest": "^
|
|
102
|
+
"vitest": "^5.0.0"
|
|
103
103
|
},
|
|
104
104
|
"scripts": {
|
|
105
105
|
"build": "node scripts/build.mjs && tsc -p tsconfig.build.json",
|