@portone/docx-editor 0.6.1 → 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.
Files changed (92) hide show
  1. package/CHANGELOG.md +78 -0
  2. package/dist/DocxEditor.js +2 -2
  3. package/dist/core.d.ts +4 -3
  4. package/dist/docx/exportDocx.d.ts +1 -1
  5. package/dist/docx/exportDocx.js +3 -1
  6. package/dist/docx/headersFooters.js +4 -14
  7. package/dist/docx/identities.d.ts +10 -2
  8. package/dist/docx/identities.js +32 -11
  9. package/dist/docx/importPolicy.d.ts +2 -2
  10. package/dist/docx/importPolicy.js +12 -5
  11. package/dist/docx/importPreserved.d.ts +3 -3
  12. package/dist/docx/importSdtBlock.d.ts +24 -0
  13. package/dist/docx/importSdtBlock.js +42 -0
  14. package/dist/docx/importTable.js +35 -24
  15. package/dist/docx/invariants.d.ts +13 -10
  16. package/dist/docx/invariants.js +269 -126
  17. package/dist/docx/newLists.js +12 -3
  18. package/dist/docx/notes/numbering.js +5 -12
  19. package/dist/docx/notes/references.d.ts +31 -0
  20. package/dist/docx/notes/references.js +32 -0
  21. package/dist/docx/notes/writing.js +5 -6
  22. package/dist/docx/sdt.d.ts +52 -9
  23. package/dist/docx/sdt.js +108 -26
  24. package/dist/docx/sections.d.ts +13 -13
  25. package/dist/docx/sections.js +34 -20
  26. package/dist/docx/serializeBlock.js +9 -1
  27. package/dist/docx/serializePreserved.d.ts +5 -1
  28. package/dist/docx/serializePreserved.js +24 -7
  29. package/dist/docx/serializeSdtBlock.d.ts +24 -0
  30. package/dist/docx/serializeSdtBlock.js +15 -0
  31. package/dist/docx/serializeTable.d.ts +8 -2
  32. package/dist/docx/serializeTable.js +14 -20
  33. package/dist/docx/story.d.ts +10 -4
  34. package/dist/docx/story.js +25 -20
  35. package/dist/docx/storyBlocks.d.ts +32 -0
  36. package/dist/docx/storyBlocks.js +65 -0
  37. package/dist/docx/storyParts.d.ts +29 -8
  38. package/dist/docx/storyParts.js +40 -15
  39. package/dist/docx/wrappers.d.ts +10 -7
  40. package/dist/docx/wrappers.js +15 -27
  41. package/dist/editor/blockControlEdits.d.ts +15 -0
  42. package/dist/editor/blockControlEdits.js +79 -0
  43. package/dist/editor/clipboard/normalizers.js +1 -1
  44. package/dist/editor/commands/exportQueries.d.ts +4 -3
  45. package/dist/editor/commands/index.d.ts +1 -1
  46. package/dist/editor/commands/lockCommands.d.ts +5 -1
  47. package/dist/editor/commands/lockCommands.js +27 -19
  48. package/dist/editor/createEditor.js +4 -0
  49. package/dist/editor/notes/noteSurface.js +4 -3
  50. package/dist/editor/plugins/controlLifecycle.d.ts +18 -0
  51. package/dist/editor/plugins/controlLifecycle.js +130 -0
  52. package/dist/editor/plugins/keymap.js +23 -5
  53. package/dist/editor/plugins/rowResize.js +2 -4
  54. package/dist/editor/stories/storyState.d.ts +2 -0
  55. package/dist/editor/stories/storyState.js +2 -0
  56. package/dist/index.d.ts +2 -2
  57. package/dist/ooxml/errors.d.ts +135 -2
  58. package/dist/ooxml/errors.js +6 -0
  59. package/dist/page/blockKinds.d.ts +24 -2
  60. package/dist/page/blockKinds.js +6 -1
  61. package/dist/page/kinds/index.d.ts +5 -0
  62. package/dist/page/kinds/index.js +2 -0
  63. package/dist/page/kinds/sdtBlockKind.d.ts +14 -0
  64. package/dist/page/kinds/sdtBlockKind.js +143 -0
  65. package/dist/page/measureBlocks.js +4 -2
  66. package/dist/page/pageDecorations.js +3 -2
  67. package/dist/page/pageLayout.d.ts +16 -15
  68. package/dist/page/pageLayout.js +134 -67
  69. package/dist/page/usePageLayout.d.ts +2 -2
  70. package/dist/page/usePageLayout.js +5 -5
  71. package/dist/schema/attrRoles.js +45 -1
  72. package/dist/schema/clipboard.js +9 -0
  73. package/dist/schema/controlAttrs.d.ts +105 -0
  74. package/dist/schema/controlAttrs.js +129 -0
  75. package/dist/schema/controlEdges.d.ts +22 -0
  76. package/dist/schema/controlEdges.js +50 -0
  77. package/dist/schema/docxSchema.d.ts +1 -1
  78. package/dist/schema/docxSchema.js +180 -37
  79. package/dist/schema/editGuard.d.ts +1 -1
  80. package/dist/schema/guards.js +2 -0
  81. package/dist/schema/locks.d.ts +22 -6
  82. package/dist/schema/locks.js +88 -47
  83. package/dist/schema/stories.d.ts +11 -3
  84. package/dist/schema/stories.js +9 -3
  85. package/dist/styles/classNames.d.ts +8 -0
  86. package/dist/styles/classNames.js +8 -0
  87. package/dist/styles.css +31 -2
  88. package/dist/table/merge.js +11 -3
  89. package/dist/table/rowResize.d.ts +9 -0
  90. package/dist/table/rowResize.js +9 -5
  91. package/dist/ui/TextMenu.js +2 -0
  92. package/package.json +3 -3
@@ -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 OPEN = { contents: false, deletion: false };
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).contents) ?? null;
36
+ return sdtMarksOf(node).find((mark) => shutsAlone(markLocks(mark))) ?? null;
28
37
  }
29
- var CELL_CONTENTS_ATTR = "sdtContentsLocked";
30
- var CELL_DELETION_ATTR = "sdtDeletionLocked";
31
- function isCell(node) {
32
- return node?.type.spec.tableRole === "cell";
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 cellLocks(node) {
35
- if (!node || !isCell(node)) return OPEN;
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: node.attrs[CELL_CONTENTS_ATTR] === true,
38
- deletion: node.attrs[CELL_DELETION_ATTR] === true
54
+ contents: facts.contentsLocked,
55
+ deletion: facts.deletionLocked,
56
+ group: facts.group
39
57
  };
40
58
  }
41
- function isLockedCell(node) {
42
- return cellLocks(node).contents;
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 = cellLocks(node);
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 lockedCellContent($pos) {
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 (!isLockedCell(node)) continue;
83
- const from = $pos.before(depth) + 1;
84
- return { from, to: from + node.content.size };
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 insideLockedCell(doc, pos) {
89
- return lockedCellContent(doc.resolve(pos)) !== null;
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 reachesLockedCell(doc, range) {
92
- const content = lockedCellContent(doc.resolve(range.from)) ?? lockedCellContent(doc.resolve(range.to));
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.contents && overlaps(range, span);
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 (reachesLockedCell(doc, range)) return true;
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 (isCell(node)) {
112
- const locks = cellLocks(node);
142
+ if (controlAttrsOf(node) !== null) {
143
+ const locks = containerLocks(node);
113
144
  if (coversWhole(range, { from: pos, to: pos + node.nodeSize })) {
114
- if (range.takesAway ? locks.deletion : locks.contents) shut = true;
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
- shut ||= controlSpans({ node, start: pos + 1 }).some(
120
- (span) => shuts(markLocks(span.mark), range, span)
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
- if (lockedCellContent($pos)) return true;
132
- const before = lockedMarkOf($pos.nodeBefore);
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 isLockedCell(node) && node.content.size > 0;
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 clearsCellLock(step, doc) {
218
+ function clearsContainerLock(step, doc) {
183
219
  if (step instanceof AttrStep) {
184
220
  if (step.value === true) return false;
185
- const locks = cellLocks(doc.nodeAt(step.pos));
186
- if (step.attr === CELL_CONTENTS_ATTR) return locks.contents;
187
- if (step.attr === CELL_DELETION_ATTR) return locks.deletion;
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 = cellLocks(doc.nodeAt(step.from));
192
- const now = cellLocks(step.slice.content.firstChild);
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) || clearsCellLock(step, doc)) return false;
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 lockedCellContent(doc.resolve(step.pos)) === null && lockedMarkOf(doc.nodeAt(step.pos)) === null;
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 insideLockedCell(doc, intent.at);
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
- isLockedCell,
271
+ isLockedContainer,
231
272
  lockGuard,
232
273
  lockedMarkOf,
233
274
  selectionShut,
@@ -35,12 +35,20 @@ export declare const STORIES_ATTR = "stories";
35
35
  export declare function storyKey<K extends StoryKind>(kind: K, id: string): `${K}:${string}`;
36
36
  /** The key of a story that is a note: `footnote:2`, `endnote:3` */
37
37
  export type NoteKey = `${NoteKind}:${string}`;
38
+ /** What a key names: which kind of story it is, and the id it stands under */
39
+ export interface StoryName {
40
+ readonly kind: StoryKind;
41
+ readonly id: string;
42
+ }
38
43
  /**
39
- * The note this key names, and null for a key naming a story of another kind.
44
+ * The kind and the id a key names.
40
45
  *
41
- * A note's id never carries a colon - a note is identified by a whole number (§17.11.2, §17.11.8)
42
- * - so the kind is everything up to the first one.
46
+ * An id carries colons of its own - a header is named by its part path - so the kind is everything
47
+ * up to the first one. A key is spelled `${StoryKind}:${string}`, so the kind always reads back;
48
+ * text that may spell no kind at all comes through `asStoryKey` first.
43
49
  */
50
+ export declare function splitStoryKey(key: StoryKey): StoryName;
51
+ /** The note this key names, and null for a key naming a story of another kind */
44
52
  export declare function noteKeyOf(key: StoryKey): {
45
53
  readonly kind: NoteKind;
46
54
  readonly id: string;
@@ -15,11 +15,16 @@ var STORIES_ATTR = "stories";
15
15
  function storyKey(kind, id) {
16
16
  return `${kind}:${id}`;
17
17
  }
18
- function noteKeyOf(key) {
18
+ function splitStoryKey(key) {
19
19
  const at = key.indexOf(":");
20
20
  const named = key.slice(0, at);
21
- const kind = NOTE_KINDS.find((candidate) => candidate === named);
22
- return kind === void 0 ? null : { kind, id: key.slice(at + 1) };
21
+ const kind = STORY_KINDS.find((candidate) => candidate === named);
22
+ return { kind: kind ?? "comment", id: key.slice(at + 1) };
23
+ }
24
+ function noteKeyOf(key) {
25
+ const { kind, id } = splitStoryKey(key);
26
+ const note = NOTE_KINDS.find((candidate) => candidate === kind);
27
+ return note === void 0 ? null : { kind: note, id };
23
28
  }
24
29
  var EDITABLE_NOTE_KINDS = NOTE_KINDS;
25
30
  function asStoryKey(text) {
@@ -88,6 +93,7 @@ export {
88
93
  noteKeyOf,
89
94
  noteName,
90
95
  sameStory,
96
+ splitStoryKey,
91
97
  storiesOf,
92
98
  storyKey,
93
99
  storyNodeOf,
@@ -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 whole cell shut by the control around it. The same yellow, outlined just inside the cell
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;
@@ -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
- sdtPrefix: isOriginalSpot ? source.attrs.sdtPrefix : null,
102
- sdtContentsLocked: isOriginalSpot ? source.attrs.sdtContentsLocked : false,
103
- sdtDeletionLocked: isOriginalSpot ? source.attrs.sdtDeletionLocked : false
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;
@@ -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 { isLockedCell } from "../schema/locks.js";
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 (!table || table.type.spec.tableRole !== "table" || resize.row < 0 || resize.row >= table.childCount) {
20
- return null;
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
  };
@@ -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.1",
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.5",
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": "^4.1.6"
102
+ "vitest": "^5.0.0"
103
103
  },
104
104
  "scripts": {
105
105
  "build": "node scripts/build.mjs && tsc -p tsconfig.build.json",