@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
@@ -0,0 +1,129 @@
1
+ // src/schema/controlAttrs.ts
2
+ var SDT_BLOCK_NODE = "sdtBlock";
3
+ var SDT_EMPTY_NODE = "sdtEmpty";
4
+ var OWN_CONTROL_ATTRS = {
5
+ prefix: "sdtPrefix",
6
+ contentsLocked: "contentsLocked",
7
+ deletionLocked: "deletionLocked",
8
+ group: "group",
9
+ temporary: "temporary",
10
+ showingPlaceholder: "showingPlaceholder"
11
+ };
12
+ var WRAPPED_CONTROL_ATTRS = {
13
+ prefix: "sdtPrefix",
14
+ contentsLocked: "sdtContentsLocked",
15
+ deletionLocked: "sdtDeletionLocked",
16
+ group: "sdtGroup",
17
+ temporary: "sdtTemporary",
18
+ showingPlaceholder: "sdtShowingPlaceholder"
19
+ };
20
+ var NO_CONTROL = {
21
+ prefix: null,
22
+ contentsLocked: false,
23
+ deletionLocked: false,
24
+ group: false,
25
+ temporary: false,
26
+ showingPlaceholder: false
27
+ };
28
+ var PREFIX_DOM_ATTR = "data-sdt-prefix";
29
+ var FLAG_DOM_ATTRS = {
30
+ contentsLocked: "data-sdt-contents-locked",
31
+ deletionLocked: "data-sdt-deletion-locked",
32
+ group: "data-sdt-group",
33
+ temporary: "data-sdt-temporary",
34
+ showingPlaceholder: "data-sdt-placeholder"
35
+ };
36
+ function controlAttrs(names, facts) {
37
+ return {
38
+ [names.prefix]: facts.prefix,
39
+ [names.contentsLocked]: facts.contentsLocked,
40
+ [names.deletionLocked]: facts.deletionLocked,
41
+ [names.group]: facts.group,
42
+ [names.temporary]: facts.temporary,
43
+ [names.showingPlaceholder]: facts.showingPlaceholder
44
+ };
45
+ }
46
+ function controlFactsOf(names, attrs) {
47
+ const prefix = attrs[names.prefix];
48
+ return {
49
+ prefix: typeof prefix === "string" ? prefix : null,
50
+ contentsLocked: attrs[names.contentsLocked] === true,
51
+ deletionLocked: attrs[names.deletionLocked] === true,
52
+ group: attrs[names.group] === true,
53
+ temporary: attrs[names.temporary] === true,
54
+ showingPlaceholder: attrs[names.showingPlaceholder] === true
55
+ };
56
+ }
57
+ function controlAttrSpecs(names) {
58
+ return Object.fromEntries(
59
+ Object.entries(controlAttrs(names, NO_CONTROL)).map(([attr, value]) => [
60
+ attr,
61
+ { default: value }
62
+ ])
63
+ );
64
+ }
65
+ var drawn = (flag) => flag ? "1" : void 0;
66
+ function controlFlagsToDom(facts) {
67
+ return {
68
+ [FLAG_DOM_ATTRS.contentsLocked]: drawn(facts.contentsLocked),
69
+ [FLAG_DOM_ATTRS.deletionLocked]: drawn(facts.deletionLocked),
70
+ [FLAG_DOM_ATTRS.group]: drawn(facts.group),
71
+ [FLAG_DOM_ATTRS.temporary]: drawn(facts.temporary),
72
+ [FLAG_DOM_ATTRS.showingPlaceholder]: drawn(facts.showingPlaceholder)
73
+ };
74
+ }
75
+ function controlFlagsFromDom(dom) {
76
+ const set = (attr) => dom.getAttribute(attr) === "1";
77
+ return {
78
+ contentsLocked: set(FLAG_DOM_ATTRS.contentsLocked),
79
+ deletionLocked: set(FLAG_DOM_ATTRS.deletionLocked),
80
+ group: set(FLAG_DOM_ATTRS.group),
81
+ temporary: set(FLAG_DOM_ATTRS.temporary),
82
+ showingPlaceholder: set(FLAG_DOM_ATTRS.showingPlaceholder)
83
+ };
84
+ }
85
+ function controlToDom(facts) {
86
+ return {
87
+ [PREFIX_DOM_ATTR]: facts.prefix ?? void 0,
88
+ ...controlFlagsToDom(facts)
89
+ };
90
+ }
91
+ function controlClassName(facts, base, locked) {
92
+ return facts.contentsLocked || facts.group ? `${base} ${locked}` : base;
93
+ }
94
+ function controlAttrsFromDom(names, dom, prefix) {
95
+ return controlAttrs(names, { prefix, ...controlFlagsFromDom(dom) });
96
+ }
97
+ var WRAPPED_TABLE_ROLES = ["cell", "row"];
98
+ function isBlockControl(node) {
99
+ return node?.type.name === SDT_BLOCK_NODE;
100
+ }
101
+ function isEmptyControl(node) {
102
+ return node?.type.name === SDT_EMPTY_NODE;
103
+ }
104
+ function controlAttrsOf(node) {
105
+ if (!node) return null;
106
+ if (isBlockControl(node) || isEmptyControl(node)) return OWN_CONTROL_ATTRS;
107
+ const role = node.type.spec.tableRole;
108
+ if (typeof role !== "string" || !WRAPPED_TABLE_ROLES.includes(role)) {
109
+ return null;
110
+ }
111
+ return typeof node.attrs[WRAPPED_CONTROL_ATTRS.prefix] === "string" ? WRAPPED_CONTROL_ATTRS : null;
112
+ }
113
+ export {
114
+ NO_CONTROL,
115
+ OWN_CONTROL_ATTRS,
116
+ PREFIX_DOM_ATTR,
117
+ SDT_BLOCK_NODE,
118
+ SDT_EMPTY_NODE,
119
+ WRAPPED_CONTROL_ATTRS,
120
+ controlAttrSpecs,
121
+ controlAttrs,
122
+ controlAttrsFromDom,
123
+ controlAttrsOf,
124
+ controlClassName,
125
+ controlFactsOf,
126
+ controlToDom,
127
+ isBlockControl,
128
+ isEmptyControl
129
+ };
@@ -0,0 +1,22 @@
1
+ /**
2
+ * The edge of a block-level content control, which a keystroke's join may not carry blocks across
3
+ * (`spec/notes/contentControls.md`).
4
+ *
5
+ * A control is not isolating (`./docxSchema`), so ProseMirror's base keymap will join across its
6
+ * edge: the join a keystroke builds there may not carry blocks into a control or out of one, and
7
+ * it is refused here rather than in the keymap, as one rule the whole guard list asks (`./guards`).
8
+ *
9
+ * Judging one step at a time is what confines the rule to the join. A cut and a paste, and the
10
+ * drag that is the two in one transaction, are the user saying where the text goes; taking the
11
+ * control away whole carries nothing across at all, and `./locks` answers that under the deletion
12
+ * clause.
13
+ */
14
+ import type { StepGuard } from "./editGuard";
15
+ /**
16
+ * The edges of the document's block controls, as `./guards` registers them.
17
+ *
18
+ * The history pass lifts it for the reason it lifts the locks: every step replayed is the reverse
19
+ * of one that passed the guard when it was made, and a control the user deleted whole is put back
20
+ * whole by the step that undoes it.
21
+ */
22
+ export declare const controlEdgeGuard: StepGuard;
@@ -0,0 +1,50 @@
1
+ // src/schema/controlEdges.ts
2
+ import {
3
+ ReplaceAroundStep,
4
+ ReplaceStep
5
+ } from "prosemirror-transform";
6
+ import { isBlockControl } from "./controlAttrs.js";
7
+ import { controlLifted, historyReplay } from "./locks.js";
8
+ function controlsAround($pos) {
9
+ const starts = [];
10
+ for (let depth = 1; depth <= $pos.depth; depth += 1) {
11
+ if (isBlockControl($pos.node(depth))) starts.push($pos.before(depth));
12
+ }
13
+ return starts;
14
+ }
15
+ function sameControls(a, b) {
16
+ return a.length === b.length && a.every((start, index) => start === b[index]);
17
+ }
18
+ function crossesAnEdge(doc, from, to) {
19
+ if (from === to) return false;
20
+ return !sameControls(
21
+ controlsAround(doc.resolve(from)),
22
+ controlsAround(doc.resolve(to))
23
+ );
24
+ }
25
+ function movesGapAcross(step, before, after) {
26
+ if (!(step instanceof ReplaceAroundStep)) return false;
27
+ const map = step.getMap();
28
+ const was = controlsAround(before.resolve(step.gapFrom)).map(
29
+ (start) => map.map(start, -1)
30
+ );
31
+ return !sameControls(
32
+ was,
33
+ controlsAround(after.resolve(step.from + step.insert))
34
+ );
35
+ }
36
+ function stepAllowed(step, before, after) {
37
+ if (!(step instanceof ReplaceStep || step instanceof ReplaceAroundStep)) {
38
+ return true;
39
+ }
40
+ return !crossesAnEdge(before, step.from, step.to) && !movesGapAcross(step, before, after);
41
+ }
42
+ var controlEdgeGuard = {
43
+ name: "controlEdge",
44
+ liftedBy: [controlLifted, historyReplay],
45
+ step: (step, before, after) => stepAllowed(step, before, after),
46
+ shuts: (intent, state) => intent.kind === "replace" && crossesAnEdge(state.doc, intent.from, intent.to)
47
+ };
48
+ export {
49
+ controlEdgeGuard
50
+ };
@@ -23,4 +23,4 @@ export declare function isPageBreak(brAttrs: unknown): boolean;
23
23
  * ends the line where it stood, and `chip` draws a small box naming the element.
24
24
  */
25
25
  export type PreservedDisplay = "hidden" | "text" | "break" | "chip";
26
- export declare const docxSchema: Schema<"commentEnd" | "commentReference" | "commentStart" | "doc" | "hardBreak" | "image" | "noteReference" | "paragraph" | "rawBlock" | "rawInline" | "rawRunContent" | "table" | "tableCell" | "tableRow" | "text", "link" | "run" | "sdt" | "tab">;
26
+ export declare const docxSchema: Schema<"commentEnd" | "commentReference" | "commentStart" | "doc" | "hardBreak" | "image" | "noteReference" | "paragraph" | "rawBlock" | "rawInline" | "rawRunContent" | "sdtBlock" | "sdtEmpty" | "table" | "tableCell" | "tableRow" | "text", "link" | "run" | "sdt" | "tab">;
@@ -34,6 +34,18 @@ import {
34
34
  rowStyle,
35
35
  tableStyle
36
36
  } from "../styles/inlineStyle.js";
37
+ import {
38
+ controlAttrSpecs,
39
+ controlAttrsFromDom,
40
+ controlClassName,
41
+ controlFactsOf,
42
+ controlToDom,
43
+ OWN_CONTROL_ATTRS,
44
+ PREFIX_DOM_ATTR,
45
+ SDT_BLOCK_NODE,
46
+ SDT_EMPTY_NODE,
47
+ WRAPPED_CONTROL_ATTRS
48
+ } from "./controlAttrs.js";
37
49
  import { imageNodeSpec, runMarkSpec } from "./rendering.js";
38
50
  import { noteName } from "./stories.js";
39
51
  import { WRAPPER_ATTRS, WRAPPER_GROUP } from "./wrappers.js";
@@ -379,6 +391,12 @@ var docxSchema = new Schema({
379
391
  /** The whole `<w:trPr>...</w:trPr>` XML */
380
392
  trPr: { default: null },
381
393
  format: { default: null },
394
+ /**
395
+ * What the content control this row sat inside states (`CT_SdtRow`, §17.5.2.30), under the
396
+ * same `sdt`-prefixed names a wrapped cell carries (`./controlAttrs`), since both are one
397
+ * node the file put a `w:sdt` around.
398
+ */
399
+ ...controlAttrSpecs(WRAPPED_CONTROL_ATTRS),
382
400
  /** The markers that stood ahead of this row's first cell (`docx/importTable`) */
383
401
  leadingXml: { default: null },
384
402
  /** The markers that stood between this row and the next one, under the table */
@@ -386,15 +404,21 @@ var docxSchema = new Schema({
386
404
  },
387
405
  toDOM(node) {
388
406
  const format = toRowFormat(node.attrs.format);
407
+ const control = controlFactsOf(WRAPPED_CONTROL_ATTRS, node.attrs);
389
408
  return [
390
409
  "tr",
391
410
  {
392
- class: editorClassNames.tableRow,
411
+ class: controlClassName(
412
+ control,
413
+ editorClassNames.tableRow,
414
+ editorClassNames.rowLocked
415
+ ),
393
416
  style: rowStyle(format),
394
417
  "data-trattrs": text(node.attrs.trAttrs),
395
418
  "data-tblprex": text(node.attrs.tblPrEx),
396
419
  "data-trpr": text(node.attrs.trPr),
397
420
  "data-fmt": formatJson(format),
421
+ ...controlToDom(control),
398
422
  "data-leading": text(node.attrs.leadingXml),
399
423
  "data-trailing": text(node.attrs.trailingXml)
400
424
  },
@@ -408,9 +432,10 @@ var docxSchema = new Schema({
408
432
  const trAttrs = rawXml(dom, "data-trattrs", ATTRIBUTES);
409
433
  const tblPrEx = rawXml(dom, "data-tblprex", ELEMENT("tblPrEx"));
410
434
  const trPr = rawXml(dom, "data-trpr", ELEMENT("trPr"));
435
+ const sdtPrefix = rawXml(dom, PREFIX_DOM_ATTR, SDT_PREFIX);
411
436
  const leadingXml = rawXml(dom, "data-leading", ANY_ELEMENTS);
412
437
  const trailingXml = rawXml(dom, "data-trailing", ANY_ELEMENTS);
413
- if (trAttrs === false || tblPrEx === false || trPr === false || leadingXml === false || trailingXml === false) {
438
+ if (trAttrs === false || tblPrEx === false || trPr === false || sdtPrefix === false || leadingXml === false || trailingXml === false) {
414
439
  return false;
415
440
  }
416
441
  return {
@@ -418,6 +443,7 @@ var docxSchema = new Schema({
418
443
  tblPrEx,
419
444
  trPr,
420
445
  format: toRowFormat(parseJson(dom.getAttribute("data-fmt"))),
446
+ ...controlAttrsFromDom(WRAPPED_CONTROL_ATTRS, dom, sdtPrefix),
421
447
  leadingXml,
422
448
  trailingXml
423
449
  };
@@ -445,15 +471,13 @@ var docxSchema = new Schema({
445
471
  /** The cell width read out of tcPr */
446
472
  tcW: { default: null },
447
473
  format: { default: null },
448
- /** The opening XML of the `<w:sdt>` content control this cell sat inside */
449
- sdtPrefix: { default: null },
450
474
  /**
451
- * The two clauses of that control's lock, which mean the same as `contentsLocked` and
452
- * `deletionLocked` on the sdt mark. Both only ever stand alongside an `sdtPrefix`, since
453
- * the lock lives inside that very XML.
475
+ * What the content control this cell sat inside states, under names of its own so that it
476
+ * stands beside the cell's (`./controlAttrs`). The lock's two clauses mean the same as
477
+ * `contentsLocked` and `deletionLocked` on the sdt mark, and all of them only ever stand
478
+ * alongside an `sdtPrefix`, since the control's own XML is where they are read from.
454
479
  */
455
- sdtContentsLocked: { default: false },
456
- sdtDeletionLocked: { default: false },
480
+ ...controlAttrSpecs(WRAPPED_CONTROL_ATTRS),
457
481
  /** The markers that stood between this cell and the next one, under the row */
458
482
  trailingXml: { default: null }
459
483
  },
@@ -462,11 +486,15 @@ var docxSchema = new Schema({
462
486
  const colspan = spanCount(node.attrs.colspan);
463
487
  const rowspan = spanCount(node.attrs.rowspan);
464
488
  const colwidth = toColWidth(node.attrs.colwidth);
465
- const locked = node.attrs.sdtContentsLocked === true;
489
+ const control = controlFactsOf(WRAPPED_CONTROL_ATTRS, node.attrs);
466
490
  return [
467
491
  "td",
468
492
  {
469
- class: locked ? `${editorClassNames.tableCell} ${editorClassNames.cellLocked}` : editorClassNames.tableCell,
493
+ class: controlClassName(
494
+ control,
495
+ editorClassNames.tableCell,
496
+ editorClassNames.cellLocked
497
+ ),
470
498
  style: cellStyle(format),
471
499
  colspan: colspan > 1 ? `${colspan}` : void 0,
472
500
  rowspan: rowspan > 1 ? `${rowspan}` : void 0,
@@ -475,9 +503,7 @@ var docxSchema = new Schema({
475
503
  "data-tcpr": text(node.attrs.tcPr),
476
504
  "data-tcw": formatJson(toTableWidth(node.attrs.tcW)),
477
505
  "data-fmt": formatJson(format),
478
- "data-sdt-prefix": text(node.attrs.sdtPrefix),
479
- "data-sdt-contents-locked": locked ? "1" : void 0,
480
- "data-sdt-deletion-locked": node.attrs.sdtDeletionLocked === true ? "1" : void 0,
506
+ ...controlToDom(control),
481
507
  "data-trailing": text(node.attrs.trailingXml)
482
508
  },
483
509
  0
@@ -489,7 +515,7 @@ var docxSchema = new Schema({
489
515
  getAttrs: (dom) => {
490
516
  const tcAttrs = rawXml(dom, "data-tcattrs", ATTRIBUTES);
491
517
  const tcPr = rawXml(dom, "data-tcpr", ELEMENT("tcPr"));
492
- const sdtPrefix = rawXml(dom, "data-sdt-prefix", SDT_PREFIX);
518
+ const sdtPrefix = rawXml(dom, PREFIX_DOM_ATTR, SDT_PREFIX);
493
519
  const trailingXml = rawXml(dom, "data-trailing", ANY_ELEMENTS);
494
520
  if (tcAttrs === false || tcPr === false || sdtPrefix === false || trailingXml === false) {
495
521
  return false;
@@ -504,15 +530,132 @@ var docxSchema = new Schema({
504
530
  tcPr,
505
531
  tcW: toTableWidth(parseJson(dom.getAttribute("data-tcw"))),
506
532
  format: toCellFormat(parseJson(dom.getAttribute("data-fmt"))),
507
- sdtPrefix,
508
- sdtContentsLocked: dom.getAttribute("data-sdt-contents-locked") === "1",
509
- sdtDeletionLocked: dom.getAttribute("data-sdt-deletion-locked") === "1",
533
+ ...controlAttrsFromDom(WRAPPED_CONTROL_ATTRS, dom, sdtPrefix),
510
534
  trailingXml
511
535
  };
512
536
  }
513
537
  }
514
538
  ]
515
539
  },
540
+ /**
541
+ * The blocks a block-level content control (`w:sdt` under the body, a cell, or another
542
+ * control) holds, as a container of its own.
543
+ *
544
+ * How deeply controls are nested is what the tree says here, where the inline mark has to
545
+ * carry it as `depth`, since several marks stand on one and the same text.
546
+ */
547
+ [SDT_BLOCK_NODE]: {
548
+ group: "block modelled",
549
+ content: "block+",
550
+ // A control may be deleted whole when its lock allows it, so it has to be selectable; it is
551
+ // not isolating, because an isolating node is one a deletion cannot reach across at all
552
+ selectable: true,
553
+ attrs: {
554
+ /**
555
+ * The fragment of the session this control was opened from, as a table names its own.
556
+ * null for one opened inside a cell or inside another control, which was never a fragment
557
+ * of its own.
558
+ */
559
+ srcId: { default: null },
560
+ /** Which control of the document this is, counted as the file was opened (`docx/wrappers`) */
561
+ key: { default: 0 },
562
+ /**
563
+ * What the control states, under the same names the inline mark carries them by
564
+ * (`./controlAttrs`): the opening XML of the `<w:sdt>`, the two clauses of its lock,
565
+ * whether it is a `w:group`, and what it says about outliving an edit of its contents
566
+ * (`editor/plugins/controlLifecycle`).
567
+ */
568
+ ...controlAttrSpecs(OWN_CONTROL_ATTRS)
569
+ },
570
+ toDOM(node) {
571
+ const control = controlFactsOf(OWN_CONTROL_ATTRS, node.attrs);
572
+ return [
573
+ "div",
574
+ {
575
+ class: controlClassName(
576
+ control,
577
+ editorClassNames.sdtBlock,
578
+ editorClassNames.sdtLocked
579
+ ),
580
+ "data-src": text(node.attrs.srcId),
581
+ "data-key": numberText(node.attrs.key),
582
+ ...controlToDom(control)
583
+ },
584
+ 0
585
+ ];
586
+ },
587
+ parseDOM: [
588
+ {
589
+ tag: `div.${editorClassNames.sdtBlock}`,
590
+ getAttrs: (dom) => {
591
+ const prefix = rawXml(dom, PREFIX_DOM_ATTR, SDT_PREFIX);
592
+ if (prefix === null || prefix === false) return false;
593
+ return {
594
+ srcId: srcIdOf(dom),
595
+ key: parseInt10(dom.getAttribute("data-key"), 0),
596
+ ...controlAttrsFromDom(OWN_CONTROL_ATTRS, dom, prefix)
597
+ };
598
+ }
599
+ }
600
+ ]
601
+ },
602
+ /**
603
+ * A content control holding nothing at all, which is a `w:sdtContent` with no element inside
604
+ * it or none written at all (§17.5.2.34).
605
+ *
606
+ * It is no container: `block+` has no way to say "nothing", and a paragraph made up for it
607
+ * would write a blank line the file never held. So it stands as an atom that draws nothing,
608
+ * which is what a server's condition-failed clause is meant to look like, and what it states
609
+ * about itself rides back out in the same attributes the container carries.
610
+ */
611
+ [SDT_EMPTY_NODE]: {
612
+ group: "block modelled",
613
+ atom: true,
614
+ // Deleted whole under its deletion clause like the container, and there is nothing else a
615
+ // selection could reach here: the node holds no spot a caret can stand in
616
+ selectable: true,
617
+ attrs: {
618
+ /**
619
+ * The fragment of the session this control was opened from, as the container names its
620
+ * own. null for one opened inside a cell or inside another control.
621
+ */
622
+ srcId: { default: null },
623
+ /** Which control of the document this is, counted as the file was opened (`docx/wrappers`) */
624
+ key: { default: 0 },
625
+ /** What the control states, under the names the container carries them by (`./controlAttrs`) */
626
+ ...controlAttrSpecs(OWN_CONTROL_ATTRS)
627
+ },
628
+ toDOM(node) {
629
+ const control = controlFactsOf(OWN_CONTROL_ATTRS, node.attrs);
630
+ return [
631
+ "div",
632
+ {
633
+ class: controlClassName(
634
+ control,
635
+ editorClassNames.sdtEmpty,
636
+ editorClassNames.sdtLocked
637
+ ),
638
+ "data-src": text(node.attrs.srcId),
639
+ "data-key": numberText(node.attrs.key),
640
+ ...controlToDom(control)
641
+ }
642
+ ];
643
+ },
644
+ parseDOM: [
645
+ {
646
+ tag: `div.${editorClassNames.sdtEmpty}`,
647
+ getAttrs: (dom) => {
648
+ const prefix = rawXml(dom, PREFIX_DOM_ATTR, SDT_PREFIX);
649
+ if (prefix === null || prefix === false) return false;
650
+ return {
651
+ srcId: srcIdOf(dom),
652
+ key: parseInt10(dom.getAttribute("data-key"), 0),
653
+ ...controlAttrsFromDom(OWN_CONTROL_ATTRS, dom, prefix)
654
+ };
655
+ }
656
+ }
657
+ ]
658
+ },
516
659
  /**
517
660
  * The one node a block the editor has no model for stands as, wherever it stood: under the
518
661
  * body, or inside a table cell.
@@ -904,31 +1047,33 @@ var docxSchema = new Schema({
904
1047
  // which stands inside which is what `depth` says (`./wrappers`)
905
1048
  excludes: "",
906
1049
  attrs: {
907
- /** The opening XML of the `<w:sdt>`, the same string a wrapped cell carries */
908
- sdtPrefix: { default: null },
909
1050
  ...WRAPPER_ATTRS,
910
1051
  /**
911
- * The two clauses of the control's lock: whether its contents may not be edited, and
912
- * whether the control itself may not be deleted, not even whole. The `w:lock` inside
913
- * sdtPrefix is where both come from, and reading it once on import saves parsing that
914
- * string again on every draw.
915
- * The two are independent: a control may be un-editable yet removable, or editable yet
916
- * not removable.
1052
+ * What the control states, under the names a block-level control carries them by too
1053
+ * (`./controlAttrs`): the opening XML of the `<w:sdt>`, which a wrapped cell carries as
1054
+ * well; the two clauses of its lock, which are independent, so a control may be
1055
+ * un-editable yet removable or editable yet not removable; whether it is a `w:group`,
1056
+ * which shuts its contents without a `w:lock` saying so and which the editor never writes
1057
+ * (`spec/notes/contentControls.md`); and `w:temporary` (§17.5.2.43) and `w:showingPlcHdr`
1058
+ * (§17.5.2.39), which `editor/plugins/controlLifecycle` acts on.
1059
+ * All of them are read off the prefix on import, which saves parsing that string again on
1060
+ * every draw.
917
1061
  */
918
- contentsLocked: { default: false },
919
- deletionLocked: { default: false }
1062
+ ...controlAttrSpecs(OWN_CONTROL_ATTRS)
920
1063
  },
921
1064
  toDOM(mark) {
922
- const locked = mark.attrs.contentsLocked === true;
1065
+ const control = controlFactsOf(OWN_CONTROL_ATTRS, mark.attrs);
923
1066
  return [
924
1067
  "span",
925
1068
  {
926
- class: locked ? `${editorClassNames.sdt} ${editorClassNames.sdtLocked}` : editorClassNames.sdt,
927
- "data-sdt-prefix": text(mark.attrs.sdtPrefix),
1069
+ class: controlClassName(
1070
+ control,
1071
+ editorClassNames.sdt,
1072
+ editorClassNames.sdtLocked
1073
+ ),
928
1074
  "data-key": numberText(mark.attrs.key),
929
1075
  "data-depth": numberText(mark.attrs.depth),
930
- "data-sdt-contents-locked": locked ? "1" : void 0,
931
- "data-sdt-deletion-locked": mark.attrs.deletionLocked === true ? "1" : void 0
1076
+ ...controlToDom(control)
932
1077
  },
933
1078
  0
934
1079
  ];
@@ -937,14 +1082,12 @@ var docxSchema = new Schema({
937
1082
  {
938
1083
  tag: `span.${editorClassNames.sdt}`,
939
1084
  getAttrs: (dom) => {
940
- const prefix = rawXml(dom, "data-sdt-prefix", SDT_PREFIX);
1085
+ const prefix = rawXml(dom, PREFIX_DOM_ATTR, SDT_PREFIX);
941
1086
  if (prefix === null || prefix === false) return false;
942
1087
  return {
943
- sdtPrefix: prefix,
944
1088
  key: parseInt10(dom.getAttribute("data-key"), 0),
945
1089
  depth: parseInt10(dom.getAttribute("data-depth"), 0),
946
- contentsLocked: dom.getAttribute("data-sdt-contents-locked") === "1",
947
- deletionLocked: dom.getAttribute("data-sdt-deletion-locked") === "1"
1090
+ ...controlAttrsFromDom(OWN_CONTROL_ATTRS, dom, prefix)
948
1091
  };
949
1092
  }
950
1093
  }
@@ -46,7 +46,7 @@ export type EditIntent =
46
46
  * against the places it puts that guard to the test, and a place naming a guard that no longer
47
47
  * stands has to be a mistake the compiler catches rather than an annotation answering for nothing.
48
48
  */
49
- export type EditGuardName = "protection" | "lock" | "preserved" | "section";
49
+ export type EditGuardName = "protection" | "lock" | "controlEdge" | "preserved" | "section";
50
50
  /** What every guard answers, whichever of the two judgements it is written as */
51
51
  interface GuardCommon {
52
52
  readonly name: EditGuardName;
@@ -1,4 +1,5 @@
1
1
  // src/schema/guards.ts
2
+ import { controlEdgeGuard } from "./controlEdges.js";
2
3
  import { changesOnlyDisplayAttrs, displayOnly } from "./displayDerivation.js";
3
4
  import {
4
5
  transactionReaches
@@ -36,6 +37,7 @@ var protectionGuard = {
36
37
  var EDIT_GUARDS = [
37
38
  protectionGuard,
38
39
  lockGuard,
40
+ controlEdgeGuard,
39
41
  preservedGuard,
40
42
  sectionGuard
41
43
  ];
@@ -1,5 +1,6 @@
1
1
  /**
2
- * Evaluates OOXML content and deletion locks for inline controls and whole table cells.
2
+ * Evaluates OOXML content and deletion locks for inline controls and for the containers a control
3
+ * stands around whole: a table cell, and a block-level control.
3
4
  *
4
5
  * `lockGuard` is what `./guards` registers all of this as, and it is the only way in: a caller
5
6
  * asking about a lock asks the one guard list, which asks the locks along with every other rule an
@@ -23,22 +24,37 @@ export declare const unlockAllowed: PluginKey<boolean>;
23
24
  * refusal would take the whole history behind it down as well.
24
25
  */
25
26
  export declare const historyReplay: PluginKey<boolean>;
27
+ /**
28
+ * The pass the one transaction that settles a control carries
29
+ * (`editor/plugins/controlLifecycle`).
30
+ *
31
+ * A `w:temporary` control is removed when its contents are edited (§17.5.2.43) and a
32
+ * `w:showingPlcHdr` one stops claiming to hold placeholder text, neither of which a user asks for
33
+ * and neither of which a lock or a control's edge would let through. The transaction carrying this
34
+ * holds nothing but those two writes, and what a lock does say about them - that a control locked
35
+ * against deletion keeps its wrapper - is settled there rather than by a refusal here
36
+ * (`spec/notes/contentControls.md`).
37
+ */
38
+ export declare const controlLifted: PluginKey<boolean>;
26
39
  interface StepRange {
27
40
  from: number;
28
41
  to: number;
29
42
  }
30
43
  /**
31
44
  * The control shutting the contents this inline node is part of. Null when it sits in no control,
32
- * or in one whose contents stand open, a control locked against deletion alone included.
45
+ * or in none that shuts, a control locked against deletion alone included.
46
+ *
47
+ * This is about the node rather than about a spot inside it, so nothing here supersedes a group.
33
48
  */
34
49
  export declare function lockedMarkOf(node: PMNode | null | undefined): Mark | null;
35
- /** Whether the control around this cell shuts its contents (`sdtContentsLocked` in `schema`) */
36
- export declare function isLockedCell(node: PMNode | null | undefined): boolean;
50
+ /** Whether the control this container stands for shuts its contents (`schema`) */
51
+ export declare function isLockedContainer(node: PMNode | null | undefined): boolean;
37
52
  /**
38
53
  * Whether this node carries a lock of either clause, an inline one wearing a control's mark and a
39
- * wrapped cell alike.
54
+ * container standing for one alike.
40
55
  * 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`).
56
+ * so a control locked against deletion alone counts (`editor/commands/lockCommands`). A `w:group`
57
+ * is not a lock and does not: it shuts its contents, and there is nothing in it to lift.
42
58
  */
43
59
  export declare function carriesLock(node: PMNode): boolean;
44
60
  /** A textblock a judgement or an edit runs through, and where its content begins */