@portone/docx-editor 0.6.2 → 0.6.3
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.js +2 -2
- package/dist/docx/headersFooters.js +4 -14
- package/dist/docx/identities.d.ts +8 -2
- package/dist/docx/identities.js +31 -11
- 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 +24 -0
- package/dist/docx/importSdtBlock.js +42 -0
- package/dist/docx/importTable.js +35 -24
- 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/sdt.d.ts +52 -9
- package/dist/docx/sdt.js +108 -26
- package/dist/docx/sections.d.ts +13 -13
- package/dist/docx/sections.js +34 -20
- package/dist/docx/serializeBlock.js +9 -1
- package/dist/docx/serializeSdtBlock.d.ts +24 -0
- package/dist/docx/serializeSdtBlock.js +15 -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/wrappers.d.ts +10 -7
- package/dist/docx/wrappers.js +15 -27
- 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 +27 -19
- package/dist/editor/createEditor.js +4 -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 +23 -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/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 +45 -1
- package/dist/schema/clipboard.js +9 -0
- package/dist/schema/controlAttrs.d.ts +105 -0
- package/dist/schema/controlAttrs.js +129 -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 +180 -37
- package/dist/schema/editGuard.d.ts +1 -1
- package/dist/schema/guards.js +2 -0
- package/dist/schema/locks.d.ts +22 -6
- package/dist/schema/locks.js +88 -47
- package/dist/styles/classNames.d.ts +8 -0
- package/dist/styles/classNames.js +8 -0
- package/dist/styles.css +31 -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.js
CHANGED
|
@@ -9,42 +9,60 @@ import {
|
|
|
9
9
|
ReplaceAroundStep,
|
|
10
10
|
ReplaceStep
|
|
11
11
|
} from "prosemirror-transform";
|
|
12
|
+
import { controlAttrsOf, controlFactsOf } from "./controlAttrs.js";
|
|
12
13
|
import { docxSchema } from "./index.js";
|
|
13
14
|
import { wrappersOf } from "./wrappers.js";
|
|
14
15
|
var unlockAllowed = new PluginKey("docxEditorUnlockAllowed");
|
|
15
16
|
var historyReplay = new PluginKey("docxEditorHistoryReplay");
|
|
16
|
-
var
|
|
17
|
+
var controlLifted = new PluginKey("docxEditorControlLifted");
|
|
18
|
+
var OPEN = { contents: false, deletion: false, group: false };
|
|
19
|
+
function shutsContents(locks, inner) {
|
|
20
|
+
return locks.contents || locks.group && !inner;
|
|
21
|
+
}
|
|
22
|
+
function shutsAlone(locks) {
|
|
23
|
+
return shutsContents(locks, false);
|
|
24
|
+
}
|
|
17
25
|
function sdtMarksOf(node) {
|
|
18
26
|
return node ? wrappersOf(node, docxSchema.marks.sdt) : [];
|
|
19
27
|
}
|
|
20
28
|
function markLocks(mark) {
|
|
21
29
|
return {
|
|
22
30
|
contents: mark.attrs.contentsLocked === true,
|
|
23
|
-
deletion: mark.attrs.deletionLocked === true
|
|
31
|
+
deletion: mark.attrs.deletionLocked === true,
|
|
32
|
+
group: mark.attrs.group === true
|
|
24
33
|
};
|
|
25
34
|
}
|
|
26
35
|
function lockedMarkOf(node) {
|
|
27
|
-
return sdtMarksOf(node).find((mark) => markLocks(mark)
|
|
36
|
+
return sdtMarksOf(node).find((mark) => shutsAlone(markLocks(mark))) ?? null;
|
|
28
37
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
38
|
+
function controlsAcross($pos) {
|
|
39
|
+
const after = sdtMarksOf($pos.nodeAfter);
|
|
40
|
+
return sdtMarksOf($pos.nodeBefore).filter(
|
|
41
|
+
(mark) => after.some((other) => other.eq(mark))
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
function marksShut(marks) {
|
|
45
|
+
return marks.some(
|
|
46
|
+
(mark, index) => shutsContents(markLocks(mark), index < marks.length - 1)
|
|
47
|
+
);
|
|
33
48
|
}
|
|
34
|
-
function
|
|
35
|
-
|
|
49
|
+
function containerLocks(node) {
|
|
50
|
+
const names = controlAttrsOf(node);
|
|
51
|
+
if (!node || !names) return OPEN;
|
|
52
|
+
const facts = controlFactsOf(names, node.attrs);
|
|
36
53
|
return {
|
|
37
|
-
contents:
|
|
38
|
-
deletion:
|
|
54
|
+
contents: facts.contentsLocked,
|
|
55
|
+
deletion: facts.deletionLocked,
|
|
56
|
+
group: facts.group
|
|
39
57
|
};
|
|
40
58
|
}
|
|
41
|
-
function
|
|
42
|
-
return
|
|
59
|
+
function isLockedContainer(node) {
|
|
60
|
+
return shutsAlone(containerLocks(node));
|
|
43
61
|
}
|
|
44
62
|
function carriesLock(node) {
|
|
45
63
|
const marks = node.isInline ? sdtMarksOf(node) : [];
|
|
46
64
|
if (marks.length === 0) {
|
|
47
|
-
const locks =
|
|
65
|
+
const locks = containerLocks(node);
|
|
48
66
|
return locks.contents || locks.deletion;
|
|
49
67
|
}
|
|
50
68
|
return marks.some((mark) => {
|
|
@@ -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);
|
|
113
|
+
}
|
|
114
|
+
function insideLockedContainer(doc, pos) {
|
|
115
|
+
return lockedContainerContent(doc.resolve(pos), false) !== null;
|
|
90
116
|
}
|
|
91
|
-
function
|
|
92
|
-
const content =
|
|
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,36 @@ 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
|
+
);
|
|
105
136
|
}
|
|
106
137
|
function rangeShut(doc, range) {
|
|
107
|
-
if (
|
|
138
|
+
if (reachesLockedContainer(doc, range)) return true;
|
|
108
139
|
let shut = false;
|
|
109
140
|
doc.nodesBetween(range.from, range.to, (node, pos) => {
|
|
110
141
|
if (shut) return false;
|
|
111
|
-
if (
|
|
112
|
-
const locks =
|
|
142
|
+
if (controlAttrsOf(node) !== null) {
|
|
143
|
+
const locks = containerLocks(node);
|
|
113
144
|
if (coversWhole(range, { from: pos, to: pos + node.nodeSize })) {
|
|
114
|
-
|
|
145
|
+
const edits = shutsAlone(locks) && node.content.size > 0;
|
|
146
|
+
if (range.takesAway ? locks.deletion : edits) shut = true;
|
|
115
147
|
}
|
|
116
148
|
return !shut;
|
|
117
149
|
}
|
|
118
150
|
if (!node.isTextblock) return true;
|
|
119
|
-
|
|
120
|
-
|
|
151
|
+
const spans = controlSpans({ node, start: pos + 1 });
|
|
152
|
+
shut ||= spans.some(
|
|
153
|
+
(span) => shuts(
|
|
154
|
+
markLocks(span.mark),
|
|
155
|
+
range,
|
|
156
|
+
span,
|
|
157
|
+
supersededSpan(spans, span, range)
|
|
158
|
+
)
|
|
121
159
|
);
|
|
122
160
|
return false;
|
|
123
161
|
});
|
|
@@ -128,10 +166,8 @@ function rangeTouchesLocked(doc, from, to) {
|
|
|
128
166
|
}
|
|
129
167
|
function insertionInsideLocked(doc, pos) {
|
|
130
168
|
const $pos = doc.resolve(pos);
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
const after = lockedMarkOf($pos.nodeAfter);
|
|
134
|
-
return before !== null && after !== null && before.eq(after);
|
|
169
|
+
const inside = controlsAcross($pos);
|
|
170
|
+
return marksShut(inside) || lockedContainerContent($pos, inside.length > 0) !== null;
|
|
135
171
|
}
|
|
136
172
|
function markShut(doc, from, to) {
|
|
137
173
|
return from === to ? insertionInsideLocked(doc, from) : rangeTouchesLocked(doc, from, to);
|
|
@@ -164,7 +200,7 @@ function rangeAllowed(doc, range) {
|
|
|
164
200
|
}
|
|
165
201
|
function plantedLock(node) {
|
|
166
202
|
if (node.isInline) return lockedMarkOf(node) !== null;
|
|
167
|
-
return
|
|
203
|
+
return isLockedContainer(node) && node.content.size > 0;
|
|
168
204
|
}
|
|
169
205
|
function lockedInside(content) {
|
|
170
206
|
let found = false;
|
|
@@ -179,25 +215,29 @@ function plantsLocked(step) {
|
|
|
179
215
|
const carried = step instanceof ReplaceStep || step instanceof ReplaceAroundStep ? step.slice.content : null;
|
|
180
216
|
return carried !== null && lockedInside(carried);
|
|
181
217
|
}
|
|
182
|
-
function
|
|
218
|
+
function clearsContainerLock(step, doc) {
|
|
183
219
|
if (step instanceof AttrStep) {
|
|
184
220
|
if (step.value === true) return false;
|
|
185
|
-
const
|
|
186
|
-
|
|
187
|
-
if (
|
|
221
|
+
const at = doc.nodeAt(step.pos);
|
|
222
|
+
const names = controlAttrsOf(at);
|
|
223
|
+
if (!names) return false;
|
|
224
|
+
const locks = containerLocks(at);
|
|
225
|
+
if (step.attr === names.contentsLocked) return locks.contents;
|
|
226
|
+
if (step.attr === names.deletionLocked) return locks.deletion;
|
|
227
|
+
if (step.attr === names.group) return locks.group;
|
|
188
228
|
return false;
|
|
189
229
|
}
|
|
190
230
|
if (!(step instanceof ReplaceAroundStep)) return false;
|
|
191
|
-
const was =
|
|
192
|
-
const now =
|
|
193
|
-
return was.contents && !now.contents || was.deletion && !now.deletion;
|
|
231
|
+
const was = containerLocks(doc.nodeAt(step.from));
|
|
232
|
+
const now = containerLocks(step.slice.content.firstChild);
|
|
233
|
+
return was.contents && !now.contents || was.deletion && !now.deletion || was.group && !now.group;
|
|
194
234
|
}
|
|
195
235
|
function stepAllowed(step, doc) {
|
|
196
|
-
if (plantsLocked(step) ||
|
|
236
|
+
if (plantsLocked(step) || clearsContainerLock(step, doc)) return false;
|
|
197
237
|
const ranges = editedRanges(step);
|
|
198
238
|
if (ranges) return ranges.every((range) => rangeAllowed(doc, range));
|
|
199
239
|
if (step instanceof AttrStep || step instanceof AddNodeMarkStep || step instanceof RemoveNodeMarkStep) {
|
|
200
|
-
return
|
|
240
|
+
return lockedContainerContent(doc.resolve(step.pos), false) === null && lockedMarkOf(doc.nodeAt(step.pos)) === null;
|
|
201
241
|
}
|
|
202
242
|
return true;
|
|
203
243
|
}
|
|
@@ -206,7 +246,7 @@ function intentShut(doc, intent) {
|
|
|
206
246
|
case "insert":
|
|
207
247
|
return insertionInsideLocked(doc, intent.at);
|
|
208
248
|
case "block":
|
|
209
|
-
return
|
|
249
|
+
return insideLockedContainer(doc, intent.at);
|
|
210
250
|
case "mark":
|
|
211
251
|
return markShut(doc, intent.from, intent.to);
|
|
212
252
|
case "replace":
|
|
@@ -219,15 +259,16 @@ function intentShut(doc, intent) {
|
|
|
219
259
|
}
|
|
220
260
|
var lockGuard = {
|
|
221
261
|
name: "lock",
|
|
222
|
-
liftedBy: [unlockAllowed, historyReplay],
|
|
262
|
+
liftedBy: [unlockAllowed, historyReplay, controlLifted],
|
|
223
263
|
step: (step, before) => stepAllowed(step, before),
|
|
224
264
|
shuts: (intent, state) => intentShut(state.doc, intent)
|
|
225
265
|
};
|
|
226
266
|
export {
|
|
227
267
|
carriesLock,
|
|
268
|
+
controlLifted,
|
|
228
269
|
controlSpans,
|
|
229
270
|
historyReplay,
|
|
230
|
-
|
|
271
|
+
isLockedContainer,
|
|
231
272
|
lockGuard,
|
|
232
273
|
lockedMarkOf,
|
|
233
274
|
selectionShut,
|
|
@@ -31,11 +31,17 @@ 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";
|
|
39
45
|
/** Attached alongside it when the control says its contents may not be edited */
|
|
40
46
|
readonly sdtLocked: "docx-editor-sdt-locked";
|
|
41
47
|
/** A stretch of text inside a hyperlink (`w:hyperlink`) */
|
|
@@ -224,6 +230,8 @@ export declare const editorAttributes: {
|
|
|
224
230
|
readonly pageBreakSpace: "data-page-space";
|
|
225
231
|
/** A display-only table row that fills the remainder between page bodies */
|
|
226
232
|
readonly tablePageSpace: "data-table-page-space";
|
|
233
|
+
/** The space a block-level content control opens between two of the blocks it holds */
|
|
234
|
+
readonly containerPageSpace: "data-container-page-space";
|
|
227
235
|
/** A display-only copy of a table header row on a continued page */
|
|
228
236
|
readonly tableRepeatedHeader: "data-table-repeated-header";
|
|
229
237
|
/**
|
|
@@ -26,11 +26,17 @@ 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`,
|
|
34
40
|
/** Attached alongside it when the control says its contents may not be edited */
|
|
35
41
|
sdtLocked: `${PREFIX}-sdt-locked`,
|
|
36
42
|
/** A stretch of text inside a hyperlink (`w:hyperlink`) */
|
|
@@ -213,6 +219,8 @@ var editorAttributes = {
|
|
|
213
219
|
pageBreakSpace: "data-page-space",
|
|
214
220
|
/** A display-only table row that fills the remainder between page bodies */
|
|
215
221
|
tablePageSpace: "data-table-page-space",
|
|
222
|
+
/** The space a block-level content control opens between two of the blocks it holds */
|
|
223
|
+
containerPageSpace: "data-container-page-space",
|
|
216
224
|
/** A display-only copy of a table header row on a continued page */
|
|
217
225
|
tableRepeatedHeader: "data-table-repeated-header",
|
|
218
226
|
/**
|
package/dist/styles.css
CHANGED
|
@@ -1016,10 +1016,39 @@ 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 space a block-level content control opens between two of the blocks it holds, so what
|
|
1033
|
+
* follows starts the next page (`page/kinds/sdtBlockKind`). The control's own outline runs down
|
|
1034
|
+
* both pieces of the cut and needs nothing drawn here, but the background a shut control paints
|
|
1035
|
+
* would run down the rest of the page with it, so the space paints the paper back over it. The
|
|
1036
|
+
* gutter below is broken by `.docx-editor-page-split`, which is drawn over the sheet.
|
|
1037
|
+
*/
|
|
1038
|
+
.docx-editor-sdt-block > [data-container-page-space] {
|
|
1039
|
+
pointer-events: none;
|
|
1040
|
+
user-select: none;
|
|
1041
|
+
line-height: 0;
|
|
1042
|
+
background: #ffffff;
|
|
1043
|
+
}
|
|
1044
|
+
|
|
1045
|
+
/*
|
|
1046
|
+
* A whole cell shut by the control around it, and the cells of a whole row shut by the control
|
|
1047
|
+
* around the row, which carry no lock of their own. The same yellow, outlined just inside the cell
|
|
1020
1048
|
* border so the mark follows the cell rather than the text standing in it.
|
|
1021
1049
|
*/
|
|
1022
|
-
.docx-editor-tc-locked
|
|
1050
|
+
.docx-editor-tc-locked,
|
|
1051
|
+
.docx-editor-tr-locked > .docx-editor-tc {
|
|
1023
1052
|
background: #fff59d;
|
|
1024
1053
|
outline: 1px solid #f9a825;
|
|
1025
1054
|
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.3",
|
|
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",
|