@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.
Files changed (107) hide show
  1. package/CHANGELOG.md +91 -0
  2. package/dist/DocxEditor.js +2 -2
  3. package/dist/docx/comments/writing.d.ts +8 -0
  4. package/dist/docx/comments/writing.js +9 -2
  5. package/dist/docx/headersFooters.d.ts +7 -0
  6. package/dist/docx/headersFooters.js +8 -15
  7. package/dist/docx/identities.d.ts +9 -2
  8. package/dist/docx/identities.js +45 -12
  9. package/dist/docx/importDocx.js +2 -0
  10. package/dist/docx/importParagraph.d.ts +4 -0
  11. package/dist/docx/importParagraph.js +2 -0
  12. package/dist/docx/importPolicy.d.ts +2 -2
  13. package/dist/docx/importPolicy.js +12 -5
  14. package/dist/docx/importPreserved.d.ts +3 -3
  15. package/dist/docx/importSdtBlock.d.ts +23 -0
  16. package/dist/docx/importSdtBlock.js +33 -0
  17. package/dist/docx/importTable.js +35 -24
  18. package/dist/docx/invariants.js +60 -3
  19. package/dist/docx/notes/numbering.js +4 -4
  20. package/dist/docx/notes/references.d.ts +0 -2
  21. package/dist/docx/notes/references.js +2 -7
  22. package/dist/docx/numberingPlanner.d.ts +3 -0
  23. package/dist/docx/numberingPlanner.js +8 -2
  24. package/dist/docx/packageParts.d.ts +9 -0
  25. package/dist/docx/packageParts.js +16 -0
  26. package/dist/docx/packagePrefixes.d.ts +12 -0
  27. package/dist/docx/packagePrefixes.js +18 -0
  28. package/dist/docx/partPlan.js +3 -5
  29. package/dist/docx/sdt.d.ts +79 -9
  30. package/dist/docx/sdt.js +121 -26
  31. package/dist/docx/sections.d.ts +13 -13
  32. package/dist/docx/sections.js +34 -20
  33. package/dist/docx/serializeBlock.js +10 -1
  34. package/dist/docx/serializeParagraph.d.ts +2 -1
  35. package/dist/docx/serializeParagraph.js +6 -1
  36. package/dist/docx/serializeSdtBlock.d.ts +16 -0
  37. package/dist/docx/serializeSdtBlock.js +11 -0
  38. package/dist/docx/serializeTable.d.ts +8 -2
  39. package/dist/docx/serializeTable.js +14 -20
  40. package/dist/docx/story.d.ts +10 -4
  41. package/dist/docx/story.js +25 -20
  42. package/dist/docx/storyBlocks.d.ts +32 -0
  43. package/dist/docx/storyBlocks.js +65 -0
  44. package/dist/docx/storyParts.d.ts +3 -0
  45. package/dist/docx/storyParts.js +4 -1
  46. package/dist/docx/wrappers.d.ts +33 -15
  47. package/dist/docx/wrappers.js +45 -26
  48. package/dist/editor/blockControlEdits.d.ts +15 -0
  49. package/dist/editor/blockControlEdits.js +79 -0
  50. package/dist/editor/clipboard/normalizers.js +1 -1
  51. package/dist/editor/commands/lockCommands.d.ts +5 -1
  52. package/dist/editor/commands/lockCommands.js +51 -23
  53. package/dist/editor/createEditor.js +4 -0
  54. package/dist/editor/inlineControlEdits.d.ts +20 -0
  55. package/dist/editor/inlineControlEdits.js +69 -0
  56. package/dist/editor/notes/noteSurface.js +4 -3
  57. package/dist/editor/plugins/controlLifecycle.d.ts +18 -0
  58. package/dist/editor/plugins/controlLifecycle.js +130 -0
  59. package/dist/editor/plugins/keymap.js +34 -5
  60. package/dist/editor/plugins/rowResize.js +2 -4
  61. package/dist/editor/stories/storyState.d.ts +2 -0
  62. package/dist/editor/stories/storyState.js +2 -0
  63. package/dist/ooxml/element.js +3 -2
  64. package/dist/ooxml/errors.d.ts +11 -0
  65. package/dist/ooxml/fragment.js +3 -2
  66. package/dist/ooxml/names.d.ts +4 -0
  67. package/dist/ooxml/names.js +8 -2
  68. package/dist/ooxml/partPrefixes.d.ts +21 -0
  69. package/dist/ooxml/partPrefixes.js +164 -0
  70. package/dist/ooxml/partSplice.d.ts +6 -1
  71. package/dist/ooxml/partSplice.js +30 -10
  72. package/dist/ooxml/tagScan.d.ts +24 -2
  73. package/dist/ooxml/tagScan.js +26 -7
  74. package/dist/ooxml/xml.d.ts +8 -0
  75. package/dist/ooxml/xml.js +27 -5
  76. package/dist/page/blockKinds.d.ts +24 -2
  77. package/dist/page/blockKinds.js +6 -1
  78. package/dist/page/kinds/index.d.ts +5 -0
  79. package/dist/page/kinds/index.js +2 -0
  80. package/dist/page/kinds/sdtBlockKind.d.ts +14 -0
  81. package/dist/page/kinds/sdtBlockKind.js +143 -0
  82. package/dist/page/measureBlocks.js +4 -2
  83. package/dist/page/pageDecorations.js +3 -2
  84. package/dist/page/pageLayout.d.ts +16 -15
  85. package/dist/page/pageLayout.js +134 -67
  86. package/dist/page/usePageLayout.d.ts +2 -2
  87. package/dist/page/usePageLayout.js +5 -5
  88. package/dist/schema/attrRoles.js +56 -1
  89. package/dist/schema/clipboard.js +11 -0
  90. package/dist/schema/controlAttrs.d.ts +119 -0
  91. package/dist/schema/controlAttrs.js +137 -0
  92. package/dist/schema/controlEdges.d.ts +22 -0
  93. package/dist/schema/controlEdges.js +50 -0
  94. package/dist/schema/docxSchema.d.ts +1 -1
  95. package/dist/schema/docxSchema.js +235 -37
  96. package/dist/schema/editGuard.d.ts +1 -1
  97. package/dist/schema/guards.js +2 -0
  98. package/dist/schema/locks.d.ts +56 -8
  99. package/dist/schema/locks.js +115 -56
  100. package/dist/styles/classNames.d.ts +10 -0
  101. package/dist/styles/classNames.js +10 -0
  102. package/dist/styles.css +44 -2
  103. package/dist/table/merge.js +11 -3
  104. package/dist/table/rowResize.d.ts +9 -0
  105. package/dist/table/rowResize.js +9 -5
  106. package/dist/ui/TextMenu.js +2 -0
  107. package/package.json +3 -3
@@ -23,23 +23,26 @@ function pagePixels(geometry) {
23
23
  pageStep: marginTop + marginBottom + PAGE_SPLIT_PX
24
24
  };
25
25
  }
26
+ function samePaper(a, b) {
27
+ return a.pageWidth === b.pageWidth && a.pageHeight === b.pageHeight && a.marginTop === b.marginTop && a.marginRight === b.marginRight && a.marginBottom === b.marginBottom && a.marginLeft === b.marginLeft;
28
+ }
26
29
  var A4_PAGE_PIXELS = pagePixels(A4_PORTRAIT);
27
30
  var A4_SECTION_PIXELS = [
28
31
  { untilPos: Number.POSITIVE_INFINITY, pixels: A4_PAGE_PIXELS, type: null }
29
32
  ];
30
33
  function sectionPixels(sections) {
31
- return sections.map(({ anchor, props }) => ({
32
- untilPos: anchor.kind === "paragraph" ? anchor.pos : Number.POSITIVE_INFINITY,
34
+ return sections.map(({ anchor, to, props }) => ({
35
+ untilPos: anchor.kind === "paragraph" ? to : Number.POSITIVE_INFINITY,
33
36
  pixels: pagePixels(props.geometry),
34
37
  type: props.type
35
38
  }));
36
39
  }
37
40
  function sectionIndexAt(sections, pos) {
38
41
  const reaching = sections.findIndex((section) => pos <= section.untilPos);
39
- return reaching === -1 ? sections.length - 1 : reaching;
42
+ return reaching === -1 ? Math.max(0, sections.length - 1) : reaching;
40
43
  }
41
- function sectionPaperAt(sections, pos) {
42
- return sections[sectionIndexAt(sections, pos)]?.pixels ?? A4_PAGE_PIXELS;
44
+ function sectionPaper(sections, index) {
45
+ return sections[index]?.pixels ?? A4_PAGE_PIXELS;
43
46
  }
44
47
  function px(value) {
45
48
  return `${Math.round(value * 100) / 100}px`;
@@ -55,6 +58,31 @@ function pageGeometryStyle(page) {
55
58
  ].join(";");
56
59
  }
57
60
  var TOLERANCE_PX = 0.5;
61
+ function laidOut(blocks, sections, roomy) {
62
+ const pieceAt = (pos) => {
63
+ const section = sectionIndexAt(sections, pos);
64
+ const pixels = sections[section]?.pixels;
65
+ return {
66
+ section,
67
+ paper: pixels && pixels.bodyHeight > 0 ? pixels : roomy
68
+ };
69
+ };
70
+ const opensPageAt = (before2, piece) => piece.section !== before2.section && (sections[piece.section]?.type !== "continuous" || !samePaper(before2.paper, piece.paper));
71
+ let before = null;
72
+ return blocks.map((block) => {
73
+ const first = pieceAt(block.pos);
74
+ let last = first;
75
+ const candidates = block.candidates.map((candidate) => {
76
+ const piece = pieceAt(candidate.at);
77
+ const boundary = opensPageAt(last, piece);
78
+ last = piece;
79
+ return boundary ? { ...candidate, ...piece, forced: true, kept: false } : { ...candidate, ...piece };
80
+ });
81
+ const opensPage = before !== null && opensPageAt(before, first);
82
+ before = last;
83
+ return { block, ...first, candidates, last, opensPage };
84
+ });
85
+ }
58
86
  function round(value) {
59
87
  return Math.round(value * 100) / 100;
60
88
  }
@@ -112,20 +140,53 @@ function demandsInOrder(block) {
112
140
  const demands = block.demands ?? NO_DEMANDS;
113
141
  return demands.length < 2 ? demands : [...demands].sort((a, b) => a.offset - b.offset);
114
142
  }
115
- function withinSections(pages, sections) {
143
+ function withinSections(pages) {
116
144
  let section = null;
117
145
  let within = 0;
118
146
  return pages.map((page) => {
119
- const index = sectionIndexAt(sections, page.pos);
120
- within = index === section ? within + 1 : 1;
121
- section = index;
147
+ within = page.section === section ? within + 1 : 1;
148
+ section = page.section;
122
149
  return { ...page, pageInSection: within };
123
150
  });
124
151
  }
125
- function keepsWithNext(block, next, opensPage) {
126
- return block.keepWithNext && !opensPage && block.candidates.length === 0 && !block.breakAfter && !next.breakBefore;
152
+ function keepsWithNext(laid, next) {
153
+ return laid.block.keepWithNext && !next.opensPage && !laid.candidates.some((candidate) => candidate.forced) && !laid.block.breakAfter && !next.block.breakBefore;
154
+ }
155
+ function offered(laid) {
156
+ const { block } = laid;
157
+ const all = laid.candidates;
158
+ if (!all.some((candidate) => candidate.kept)) {
159
+ return { candidates: all, firstPiece: block.minFirstPiece };
160
+ }
161
+ const candidates = [];
162
+ let firstKeptClosed = false;
163
+ let runStart = 0;
164
+ let runPaper = laid.paper;
165
+ let index = 0;
166
+ while (index < all.length) {
167
+ const candidate = all[index];
168
+ if (!candidate) break;
169
+ if (!candidate.kept) {
170
+ candidates.push(candidate);
171
+ runStart = candidate.offset;
172
+ runPaper = candidate.paper;
173
+ index += 1;
174
+ continue;
175
+ }
176
+ let end = index;
177
+ while (all[end]?.kept) end += 1;
178
+ const runEnd = all[end]?.offset ?? block.height;
179
+ if (runEnd - runStart > runPaper.bodyHeight + TOLERANCE_PX) {
180
+ candidates.push(...all.slice(index, end));
181
+ } else if (index === 0) {
182
+ firstKeptClosed = true;
183
+ }
184
+ index = end;
185
+ }
186
+ const firstPiece = firstKeptClosed ? Math.max(block.minFirstPiece, candidates[0]?.offset ?? block.height) : block.minFirstPiece;
187
+ return { candidates, firstPiece };
127
188
  }
128
- function keptExtents(blocks, laid) {
189
+ function keptExtents(laid) {
129
190
  const fitsPage = (extent, index) => {
130
191
  const height = laid[index]?.paper.bodyHeight ?? 0;
131
192
  return extent <= height + TOLERANCE_PX;
@@ -141,13 +202,12 @@ function keptExtents(blocks, laid) {
141
202
  }
142
203
  run = [];
143
204
  };
144
- for (let index = blocks.length - 2; index >= 0; index -= 1) {
145
- const block = blocks[index];
146
- const next = blocks[index + 1];
147
- const opensPage = laid[index + 1]?.opensPage === true;
148
- if (block && next && keepsWithNext(block, next, opensPage)) {
149
- const below = run.at(-1)?.extent ?? next.minFirstPiece;
150
- run.push({ index, extent: block.height + next.gap + below });
205
+ for (let index = laid.length - 2; index >= 0; index -= 1) {
206
+ const block = laid[index];
207
+ const next = laid[index + 1];
208
+ if (block && next && keepsWithNext(block, next)) {
209
+ const below = run.at(-1)?.extent ?? offered(next).firstPiece;
210
+ run.push({ index, extent: block.block.height + next.block.gap + below });
151
211
  } else {
152
212
  settle();
153
213
  }
@@ -166,10 +226,6 @@ function pageLayout({
166
226
  const splits = [];
167
227
  const reserved = [];
168
228
  const trailing = [];
169
- let blockPos = blocks[0]?.pos ?? 0;
170
- const opened = [
171
- { page: 1, bodyStart: 0, pos: blockPos, crossed: false }
172
- ];
173
229
  const roomy = sections.find(
174
230
  (section) => section.pixels.bodyHeight > 0
175
231
  )?.pixels;
@@ -178,35 +234,39 @@ function pageLayout({
178
234
  pushes,
179
235
  cuts,
180
236
  splits,
181
- pages: withinSections(opened, sections),
237
+ pages: withinSections([
238
+ {
239
+ page: 1,
240
+ bodyStart: 0,
241
+ section: sectionIndexAt(sections, blocks[0]?.pos ?? 0),
242
+ crossed: false
243
+ }
244
+ ]),
182
245
  bodyHeight: 0,
183
246
  marginBottom: 0,
184
247
  reserved,
185
248
  trailing
186
249
  };
187
250
  }
188
- const blockSections = blocks.map(
189
- (block) => sectionIndexAt(sections, block.pos)
190
- );
191
- const laid = blockSections.map((section, index) => {
192
- const pixels = sections[section]?.pixels;
193
- return {
194
- paper: pixels && pixels.bodyHeight > 0 ? pixels : roomy,
195
- opensPage: index > 0 && section !== blockSections[index - 1] && sections[section]?.type !== "continuous"
196
- };
197
- });
251
+ const laid = laidOut(blocks, sections, roomy);
198
252
  let pageStart = 0;
199
253
  let cursor = 0;
200
- let paper = laid[0]?.paper ?? roomy;
201
- const stepTo = (opening) => paper.pageStep - paper.marginTop + opening.marginTop;
254
+ let piece = laid[0] ?? { section: 0, paper: roomy };
255
+ const opened = [
256
+ { page: 1, bodyStart: 0, section: piece.section, crossed: false }
257
+ ];
258
+ const stepTo = (opening) => piece.paper.pageStep - piece.paper.marginTop + opening.marginTop;
202
259
  let room = emptyRoom();
203
260
  let carried = [];
204
261
  let reached = 0;
205
262
  let held = 0;
206
- const reservedHere = () => Math.min(room.height, Math.max(0, pageStart + paper.bodyHeight - held));
207
- const bodyEnd = () => pageStart + paper.bodyHeight - reservedHere();
208
- const endsOnPage = (bottom) => bottom <= pageStart + paper.bodyHeight + TOLERANCE_PX;
209
- const settle = (floor, onPaper = paper) => {
263
+ const reservedHere = () => Math.min(
264
+ room.height,
265
+ Math.max(0, pageStart + piece.paper.bodyHeight - held)
266
+ );
267
+ const bodyEnd = () => pageStart + piece.paper.bodyHeight - reservedHere();
268
+ const endsOnPage = (bottom) => bottom <= pageStart + piece.paper.bodyHeight + TOLERANCE_PX;
269
+ const settle = (floor, onPaper = piece.paper) => {
210
270
  held = Math.max(held, floor);
211
271
  while (held + room.height > pageStart + onPaper.bodyHeight + TOLERANCE_PX) {
212
272
  const last = room.kept.at(-1);
@@ -235,25 +295,30 @@ function pageLayout({
235
295
  top += height;
236
296
  }
237
297
  };
238
- const split = (y, crossed, forced, opening = paper) => {
298
+ const split = (y, crossed, forced, opening = piece) => {
239
299
  const page = splits.length + 2;
240
300
  recordRoom(page - 1);
241
301
  splits.push({ y: round(y), page, forced, crossed });
242
- pageStart = crossed ? y : y + stepTo(opening);
243
- opened.push({ page, bodyStart: round(pageStart), pos: blockPos, crossed });
302
+ pageStart = crossed ? y : y + stepTo(opening.paper);
303
+ opened.push({
304
+ page,
305
+ bodyStart: round(pageStart),
306
+ section: opening.section,
307
+ crossed
308
+ });
244
309
  room = emptyRoom();
245
310
  held = pageStart;
246
311
  const waiting = carried;
247
312
  carried = [];
248
313
  waiting.sort((a, b) => a.order - b.order);
249
314
  for (const taken of waiting) keep(bands, room, taken);
250
- settle(pageStart, opening);
315
+ settle(pageStart, opening.paper);
251
316
  };
252
317
  const crossTo = (y) => {
253
318
  while (y > bodyEnd() + TOLERANCE_PX) {
254
319
  const end = bodyEnd();
255
320
  split(
256
- end > pageStart + TOLERANCE_PX ? end : pageStart + paper.bodyHeight,
321
+ end > pageStart + TOLERANCE_PX ? end : pageStart + piece.paper.bodyHeight,
257
322
  true,
258
323
  false
259
324
  );
@@ -276,24 +341,25 @@ function pageLayout({
276
341
  if (endsOnPage(bottom)) settle(bottom);
277
342
  crossTo(bottom);
278
343
  };
279
- const kept = keptExtents(blocks, laid);
344
+ const kept = keptExtents(laid);
280
345
  let breakAfterPrevious = false;
281
- for (const [index, block] of blocks.entries()) {
282
- blockPos = block.pos;
283
- const opening = laid[index]?.paper ?? paper;
284
- const startsSection = laid[index]?.opensPage === true;
285
- const pageEnd = pageStart + paper.bodyHeight;
346
+ for (const [index, laidBlock] of laid.entries()) {
347
+ const { block } = laidBlock;
348
+ const opening = laidBlock.paper;
349
+ const startsSection = laidBlock.opensPage;
350
+ const pageEnd = pageStart + piece.paper.bodyHeight;
286
351
  const top = cursor + block.gap;
287
352
  const startsPage = (block.breakBefore || breakAfterPrevious || startsSection) && top > pageStart + TOLERANCE_PX;
288
- const first = kept.get(index) ?? block.minFirstPiece;
353
+ const { candidates, firstPiece } = offered(laidBlock);
354
+ const first = kept.get(index) ?? firstPiece;
289
355
  const overflows = top + first > pageEnd + TOLERANCE_PX;
290
356
  const fits = first <= opening.bodyHeight + TOLERANCE_PX;
291
357
  const demands = demandsInOrder(block);
292
358
  const firstDemands = demands.length === 0 ? NO_DEMANDS : demands.filter((demand) => demand.offset < first);
293
359
  const crowded = top > pageStart + TOLERANCE_PX && top + first + roomAdded(bands, room, firstDemands) > bodyEnd() + TOLERANCE_PX && first + roomAdded(bands, emptyRoom(), firstDemands) <= opening.bodyHeight + TOLERANCE_PX;
294
360
  const push = startsPage || overflows && fits || crowded ? Math.max(0, pageEnd + stepTo(opening) - top) : 0;
295
- if (push > 0 || startsPage) split(pageEnd, false, startsPage, opening);
296
- paper = opening;
361
+ if (push > 0 || startsPage) split(pageEnd, false, startsPage, laidBlock);
362
+ piece = laidBlock;
297
363
  if (push > 0) {
298
364
  pushes.push({
299
365
  pos: block.pos,
@@ -302,13 +368,12 @@ function pageLayout({
302
368
  });
303
369
  }
304
370
  const contentTop = top + push;
305
- const pageBodyHeight = paper.bodyHeight;
306
371
  let added = 0;
307
372
  let pieceStart = 0;
308
373
  let untaken = 0;
309
- for (let index2 = 0; index2 <= block.candidates.length; index2 += 1) {
310
- const cut = index2 === 0 ? null : block.candidates[index2 - 1];
311
- const next = block.candidates[index2];
374
+ for (let index2 = 0; index2 <= candidates.length; index2 += 1) {
375
+ const cut = index2 === 0 ? null : candidates[index2 - 1];
376
+ const next = candidates[index2];
312
377
  const pieceEnd = next?.offset ?? block.height;
313
378
  const taken = untaken;
314
379
  while (untaken < demands.length && (next === void 0 || (demands[untaken]?.offset ?? 0) < pieceEnd)) {
@@ -319,16 +384,17 @@ function pageLayout({
319
384
  let pieceBottom = contentTop + pieceEnd + added;
320
385
  if (cut) {
321
386
  if (cut.forced) crossTo(pieceTop);
322
- const pageBottom = pageStart + pageBodyHeight;
387
+ const pageBottom = pageStart + piece.paper.bodyHeight;
323
388
  const size = pieceEnd - pieceStart;
324
- const cutHere = cut.forced || pieceTop > pageStart + TOLERANCE_PX && (pieceBottom > pageBottom + TOLERANCE_PX && size <= pageBodyHeight + TOLERANCE_PX || pieceBottom + roomAdded(bands, room, pieceDemands) > bodyEnd() + TOLERANCE_PX && size + roomAdded(bands, emptyRoom(), pieceDemands) <= pageBodyHeight + TOLERANCE_PX);
389
+ const cutHere = cut.forced || pieceTop > pageStart + TOLERANCE_PX && (pieceBottom > pageBottom + TOLERANCE_PX && size <= cut.paper.bodyHeight + TOLERANCE_PX || pieceBottom + roomAdded(bands, room, pieceDemands) > bodyEnd() + TOLERANCE_PX && size + roomAdded(bands, emptyRoom(), pieceDemands) <= cut.paper.bodyHeight + TOLERANCE_PX);
325
390
  if (cutHere) {
326
- split(pageBottom, false, cut.forced);
391
+ split(pageBottom, false, cut.forced, cut);
327
392
  const height = Math.max(0, pageStart - pieceTop);
328
393
  cuts.push({ at: cut.at, height: round(height) });
329
394
  added += height + cut.repeatHeight;
330
395
  pieceBottom += height + cut.repeatHeight;
331
396
  }
397
+ piece = cut;
332
398
  }
333
399
  const shift = contentTop + added;
334
400
  place(pieceBottom, pieceDemands, (demand) => shift + demand.offset);
@@ -336,10 +402,11 @@ function pageLayout({
336
402
  }
337
403
  cursor = contentTop + block.height + added;
338
404
  breakAfterPrevious = block.breakAfter;
405
+ piece = laidBlock.last;
339
406
  }
340
407
  const drainCarried = () => {
341
408
  while (carried.length > 0) {
342
- split(pageStart + paper.bodyHeight, false, false);
409
+ split(pageStart + piece.paper.bodyHeight, false, false);
343
410
  }
344
411
  };
345
412
  drainCarried();
@@ -350,7 +417,7 @@ function pageLayout({
350
417
  const opens = below + above + row.height > bodyEnd() + TOLERANCE_PX && below > pageStart + TOLERANCE_PX;
351
418
  if (opens) {
352
419
  laidHere = void 0;
353
- split(pageStart + paper.bodyHeight, false, false);
420
+ split(pageStart + piece.paper.bodyHeight, false, false);
354
421
  below = pageStart;
355
422
  }
356
423
  const top = below + above;
@@ -375,10 +442,10 @@ function pageLayout({
375
442
  pushes,
376
443
  cuts,
377
444
  splits,
378
- pages: withinSections(opened, sections),
445
+ pages: withinSections(opened),
379
446
  // The last page is filled out in full on the paper of the section it opens with
380
- bodyHeight: round(pageStart + paper.bodyHeight),
381
- marginBottom: paper.marginBottom,
447
+ bodyHeight: round(pageStart + piece.paper.bodyHeight),
448
+ marginBottom: piece.paper.marginBottom,
382
449
  reserved,
383
450
  trailing
384
451
  };
@@ -390,6 +457,6 @@ export {
390
457
  pageGeometryStyle,
391
458
  pageLayout,
392
459
  pagePixels,
393
- sectionPaperAt,
460
+ sectionPaper,
394
461
  sectionPixels
395
462
  };
@@ -50,8 +50,8 @@ export interface TrailingRoom {
50
50
  /** The paper area of one visual page, used to place its header and footer stories. */
51
51
  export interface PageFace {
52
52
  page: number;
53
- /** The position of the block this page opens with, which says which section it belongs to */
54
- pos: number;
53
+ /** The index of the section this page opens in, which its header and footer come from */
54
+ section: number;
55
55
  /**
56
56
  * The place this page takes within that section, counted from 1 again at every section, which is
57
57
  * what its header and footer variant is chosen by (`docx/headersFooters`)
@@ -12,7 +12,7 @@ import {
12
12
  A4_SECTION_PIXELS,
13
13
  PAGE_SPLIT_PX,
14
14
  pageLayout,
15
- sectionPaperAt
15
+ sectionPaper
16
16
  } from "./pageLayout.js";
17
17
  var NO_ROOM = [];
18
18
  function trailingOn(placement, contentTop, bodyBottom) {
@@ -88,7 +88,7 @@ function usePageLayout({
88
88
  const laidOn = new Map(
89
89
  layout.trailing.map((placement) => [placement.page, placement])
90
90
  );
91
- const paperOf = (pos) => sectionPaperAt(papers, pos);
91
+ const paperOf = (section) => sectionPaper(papers, section);
92
92
  const sheet = paperOf(0);
93
93
  setPageMarks(view, { pushes: layout.pushes, cuts: layout.cuts });
94
94
  const sheetHeight = measured.contentTop + layout.bodyHeight + Math.max(measured.contentBottom, layout.marginBottom);
@@ -102,18 +102,18 @@ function usePageLayout({
102
102
  // the band is drawn under
103
103
  marks: layout.splits.map((split) => ({
104
104
  page: split.page,
105
- top: measured.contentTop + split.y + (split.crossed ? 0 : paperOf(layout.pages[split.page - 2]?.pos ?? 0).marginBottom),
105
+ top: measured.contentTop + split.y + (split.crossed ? 0 : paperOf(layout.pages[split.page - 2]?.section ?? 0).marginBottom),
106
106
  height: split.crossed ? 0 : PAGE_SPLIT_PX,
107
107
  crossed: split.crossed
108
108
  })),
109
109
  // A page crossed into has no margin, so the place it was split at is its top corner
110
110
  pages: layout.pages.map((start) => {
111
- const paper = paperOf(start.pos);
111
+ const paper = paperOf(start.section);
112
112
  const paperTop = measured.contentTop + start.bodyStart - (start.crossed ? 0 : paper.marginTop);
113
113
  const bodyBottom = measured.contentTop + start.bodyStart + paper.bodyHeight;
114
114
  return {
115
115
  page: start.page,
116
- pos: start.pos,
116
+ section: start.section,
117
117
  pageInSection: start.pageInSection,
118
118
  headerTop: paperTop + paper.marginTop / 2,
119
119
  footerTop: paperTop + paper.pageHeight - paper.marginBottom / 2,
@@ -41,6 +41,14 @@ var NODE_ATTR_ROLES = {
41
41
  tblPrEx: { role: "source", class: "preserved" },
42
42
  trPr: { role: "source", class: "preserved" },
43
43
  format: { role: "display", class: "derived" },
44
+ // The control a `w:sdt` under `w:tbl` put around this row, read and compared for the same
45
+ // reasons a wrapped cell's is
46
+ sdtPrefix: { role: "source", class: "preserved" },
47
+ sdtContentsLocked: { role: "source", class: "derived" },
48
+ sdtDeletionLocked: { role: "source", class: "derived" },
49
+ sdtGroup: { role: "source", class: "derived" },
50
+ sdtTemporary: { role: "source", class: "derived" },
51
+ sdtShowingPlaceholder: { role: "source", class: "derived" },
44
52
  leadingXml: { role: "source", class: "preserved" },
45
53
  trailingXml: { role: "source", class: "preserved" }
46
54
  },
@@ -59,8 +67,52 @@ var NODE_ATTR_ROLES = {
59
67
  sdtPrefix: { role: "source", class: "preserved" },
60
68
  sdtContentsLocked: { role: "source", class: "derived" },
61
69
  sdtDeletionLocked: { role: "source", class: "derived" },
70
+ sdtGroup: { role: "source", class: "derived" },
71
+ sdtTemporary: { role: "source", class: "derived" },
72
+ sdtShowingPlaceholder: { role: "source", class: "derived" },
62
73
  trailingXml: { role: "source", class: "preserved" }
63
74
  },
75
+ sdtBlock: {
76
+ srcId: { role: "session", class: "identity" },
77
+ sdtPrefix: { role: "source", class: "preserved" },
78
+ // Which control this is, counted as the document was opened. Export reads it to tell one
79
+ // control from another (`docx/identities`) and never works it out again
80
+ key: { role: "session", class: "identity" },
81
+ // Read from `sdtPrefix` rather than from the file, and compared for the same reason a cell's
82
+ // are: leaving a lock out would let a step that unlocks a control pass as a re-derivation
83
+ contentsLocked: { role: "source", class: "derived" },
84
+ deletionLocked: { role: "source", class: "derived" },
85
+ group: { role: "source", class: "derived" },
86
+ // What the control says about outliving an edit, read off `sdtPrefix` as the locks are.
87
+ // A step clears them beside the prefix they were read from, so a comparison has to see them
88
+ temporary: { role: "source", class: "derived" },
89
+ showingPlaceholder: { role: "source", class: "derived" }
90
+ },
91
+ // The same facts ride on a control holding nothing as on one holding blocks, so the rows mirror
92
+ // `sdtBlock`'s. Nothing ever clears `temporary` or `showingPlaceholder` here - there is nothing
93
+ // inside to edit, so `editor/plugins/controlLifecycle` passes the node by - and they are
94
+ // compared exactly as they were read.
95
+ sdtEmpty: {
96
+ srcId: { role: "session", class: "identity" },
97
+ sdtPrefix: { role: "source", class: "preserved" },
98
+ key: { role: "session", class: "identity" },
99
+ contentsLocked: { role: "source", class: "derived" },
100
+ deletionLocked: { role: "source", class: "derived" },
101
+ group: { role: "source", class: "derived" },
102
+ temporary: { role: "source", class: "derived" },
103
+ showingPlaceholder: { role: "source", class: "derived" }
104
+ },
105
+ // The same rows again for the control standing inside a paragraph, less the `srcId`: it is no
106
+ // block of the story, so it names no fragment of the session to be written back from.
107
+ sdtEmptyInline: {
108
+ sdtPrefix: { role: "source", class: "preserved" },
109
+ key: { role: "session", class: "identity" },
110
+ contentsLocked: { role: "source", class: "derived" },
111
+ deletionLocked: { role: "source", class: "derived" },
112
+ group: { role: "source", class: "derived" },
113
+ temporary: { role: "source", class: "derived" },
114
+ showingPlaceholder: { role: "source", class: "derived" }
115
+ },
64
116
  rawBlock: {
65
117
  xml: { role: "source", class: "preserved" },
66
118
  srcId: { role: "session", class: "identity" },
@@ -141,7 +193,10 @@ var MARK_ATTR_ROLES = {
141
193
  sdtPrefix: { role: "source", class: "preserved" },
142
194
  ...WRAPPER_ATTR_ROLES,
143
195
  contentsLocked: { role: "source", class: "derived" },
144
- deletionLocked: { role: "source", class: "derived" }
196
+ deletionLocked: { role: "source", class: "derived" },
197
+ group: { role: "source", class: "derived" },
198
+ temporary: { role: "source", class: "derived" },
199
+ showingPlaceholder: { role: "source", class: "derived" }
145
200
  },
146
201
  link: {
147
202
  linkPrefix: { role: "source", class: "preserved" },
@@ -128,6 +128,17 @@ var CLIPBOARD_NODES = {
128
128
  // own and a nested table all say what they hold on the one line this cell stands on
129
129
  toClipboardText: (_node, children) => oneLine(children.join(" "))
130
130
  },
131
+ // A control is drawn through: what it holds is content a paste should keep, while its opening
132
+ // XML names a `w:id` and may name a `w:dataBinding`, neither of which may travel in a copy
133
+ sdtBlock: {
134
+ toClipboardDOM: () => ["div", 0],
135
+ toClipboardText: (_node, children) => children.join("\n")
136
+ },
137
+ // A control holding nothing says only that something is not there, which a copy carries by
138
+ // leaving it out
139
+ sdtEmpty: WRITES_NOTHING,
140
+ // The same of the one standing inside a paragraph, which says nothing the words around it do not
141
+ sdtEmptyInline: WRITES_NOTHING,
131
142
  rawBlock: WRITES_NOTHING,
132
143
  hardBreak: {
133
144
  toClipboardDOM: () => ["br"],
@@ -0,0 +1,119 @@
1
+ /**
2
+ * The attributes each carrier of a content control writes what the control states in.
3
+ *
4
+ * Six carriers state the same facts: the `sdt` mark, the `sdtBlock` container and the two nodes a
5
+ * control holding nothing stands as - `sdtEmpty` between blocks, `sdtEmptyInline` inside a
6
+ * paragraph - under the control's own names, and a cell or a row the file wrapped
7
+ * (`docx/importTable`) under `sdt`-prefixed ones, beside that node's own attributes. The names
8
+ * stand here once, so that a fact the editor reads off a control is declared, drawn, parsed,
9
+ * imported, merged and cleared from one table rather than from a list written out afresh in every
10
+ * module that touches one.
11
+ *
12
+ * Nothing is imported here: the schema itself reads this table (`./docxSchema`), and so does the
13
+ * export, which must reach no editor code at all (`core.test`).
14
+ */
15
+ import type { Node as PMNode } from "prosemirror-model";
16
+ /** The node a block-level content control is read as, which `./docxSchema` declares it under */
17
+ export declare const SDT_BLOCK_NODE = "sdtBlock";
18
+ /** The node a control holding nothing at all is read as, which `./docxSchema` declares beside it */
19
+ export declare const SDT_EMPTY_BLOCK_NODE = "sdtEmpty";
20
+ /** The same control standing inside a paragraph, which is an inline node rather than a block one */
21
+ export declare const SDT_EMPTY_INLINE_NODE = "sdtEmptyInline";
22
+ /** Which attribute one carrier writes each fact under */
23
+ export interface ControlAttrNames {
24
+ prefix: string;
25
+ contentsLocked: string;
26
+ deletionLocked: string;
27
+ group: string;
28
+ temporary: string;
29
+ showingPlaceholder: string;
30
+ }
31
+ /** What a control states, in the shape every carrier reads it as (`docx/sdt`) */
32
+ export interface ControlFacts {
33
+ /** The `<w:sdt>` opening tag with everything that stood ahead of `<w:sdtContent>` */
34
+ prefix: string | null;
35
+ /** Whether its `w:lock` says the contents may not be edited */
36
+ contentsLocked: boolean;
37
+ /** Whether its `w:lock` says it may not be deleted, not even whole */
38
+ deletionLocked: boolean;
39
+ /** Whether it is a `w:group` */
40
+ group: boolean;
41
+ /** Whether `w:temporary` says the control goes once its contents are edited (§17.5.2.43) */
42
+ temporary: boolean;
43
+ /** Whether `w:showingPlcHdr` says what stands inside is placeholder text (§17.5.2.39) */
44
+ showingPlaceholder: boolean;
45
+ }
46
+ /** Everything a control states other than the opening XML the carrier preserves */
47
+ export type ControlFlags = Omit<ControlFacts, "prefix">;
48
+ /** The control's own names, which the mark and the block-level container both carry */
49
+ export declare const OWN_CONTROL_ATTRS: ControlAttrNames;
50
+ /**
51
+ * A wrapped cell or row carries the control beside its own attributes, so every name is prefixed.
52
+ * Both are one node the file put a `w:sdt` around, so they read it under the same names.
53
+ */
54
+ export declare const WRAPPED_CONTROL_ATTRS: ControlAttrNames;
55
+ /** What a carrier no control stands around says, which is what each of them defaults to */
56
+ export declare const NO_CONTROL: ControlFacts;
57
+ /** The DOM attribute every carrier draws the control's opening XML under (`./docxSchema`) */
58
+ export declare const PREFIX_DOM_ATTR = "data-sdt-prefix";
59
+ /** These facts as the attributes of one carrier, to be spread over its own */
60
+ export declare function controlAttrs(names: ControlAttrNames, facts: ControlFacts): Record<string, string | boolean | null>;
61
+ /** What one carrier's attributes say the control standing there states */
62
+ export declare function controlFactsOf(names: ControlAttrNames, attrs: Record<string, unknown>): ControlFacts;
63
+ /** What one carrier declares for them, each defaulting to no control standing there */
64
+ export declare function controlAttrSpecs(names: ControlAttrNames): Record<string, {
65
+ default: string | boolean | null;
66
+ }>;
67
+ /**
68
+ * The control as a carrier draws it, beside the attributes and the class of the carrier's own.
69
+ * Every carrier draws it the same way, so what its node spec keeps is the class names alone.
70
+ */
71
+ export declare function controlToDom(facts: ControlFacts): Record<string, string | undefined>;
72
+ /**
73
+ * The class the carrier wears, which is its own until the control shuts what stands inside it.
74
+ * A `w:group` shuts its contents as a lock does, so it is drawn as one (`./locks`).
75
+ */
76
+ export declare function controlClassName(facts: ControlFacts, base: string, locked: string): string;
77
+ /**
78
+ * The control read back off a carrier that was drawn, as that carrier's attributes. The opening
79
+ * XML is handed over already validated, since what a carrier accepts there is the schema's to say.
80
+ */
81
+ export declare function controlAttrsFromDom(names: ControlAttrNames, dom: HTMLElement, prefix: string | null): Record<string, string | boolean | null>;
82
+ /**
83
+ * Whether this node is a block-level content control (`docx/importSdtBlock`).
84
+ *
85
+ * The comparison is by type name, so a schema built beside the editor's own
86
+ * (`table/__testing__/tables`) is read as well.
87
+ */
88
+ export declare function isBlockControl(node: PMNode | null | undefined): boolean;
89
+ /**
90
+ * Whether this node is a block-level content control with nothing inside it
91
+ * (`docx/importSdtBlock`).
92
+ *
93
+ * Deliberately not folded into `isBlockControl`: every caller of that one asks about the blocks a
94
+ * control holds, and this control holds none, so it is no container and stands as an atom.
95
+ */
96
+ export declare function isEmptyBlockControl(node: PMNode | null | undefined): boolean;
97
+ /**
98
+ * Whether this node is a content control with nothing inside it standing in a paragraph
99
+ * (`docx/wrappers`).
100
+ *
101
+ * The two shapes are told apart rather than counted together, because where such a control stands
102
+ * is the whole of what a caller does with it: one is a block among blocks and the other an atom
103
+ * among runs, and no caller acts on both.
104
+ */
105
+ export declare function isEmptyInlineControl(node: PMNode | null | undefined): boolean;
106
+ /**
107
+ * Which attributes the control standing at this node writes what it states in, and null where no
108
+ * control stands there.
109
+ *
110
+ * These are the containers a control stands around whole: a cell or a row the file wrapped
111
+ * (`docx/importTable`), which carries the control's opening XML beside its own attributes, and a
112
+ * block-level control, which is the wrapper itself. A control holding nothing is a carrier as
113
+ * well, block or inline, its extent being the node itself rather than anything standing inside it.
114
+ * A cell or a row no control wrapped carries none of this, and counting it as a control would end
115
+ * the walk out of the tree at the first one and open every lock standing around the table
116
+ * (`./locks`). The wrapped nodes are found by their table role, so a schema built beside the
117
+ * editor's own is read as well.
118
+ */
119
+ export declare function controlAttrsOf(node: PMNode | null | undefined): ControlAttrNames | null;