@portone/docx-editor 0.6.3 → 0.6.5

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 (79) hide show
  1. package/CHANGELOG.md +62 -0
  2. package/dist/DocxEditor.d.ts +11 -0
  3. package/dist/DocxEditor.js +7 -3
  4. package/dist/docx/comments/writing.d.ts +8 -0
  5. package/dist/docx/comments/writing.js +9 -2
  6. package/dist/docx/headersFooters.d.ts +7 -0
  7. package/dist/docx/headersFooters.js +4 -1
  8. package/dist/docx/identities.d.ts +4 -3
  9. package/dist/docx/identities.js +14 -1
  10. package/dist/docx/importDocx.js +2 -0
  11. package/dist/docx/importParagraph.d.ts +4 -0
  12. package/dist/docx/importParagraph.js +2 -0
  13. package/dist/docx/importSdtBlock.d.ts +2 -3
  14. package/dist/docx/importSdtBlock.js +7 -16
  15. package/dist/docx/invariants.js +60 -3
  16. package/dist/docx/numberingPlanner.d.ts +3 -0
  17. package/dist/docx/numberingPlanner.js +8 -2
  18. package/dist/docx/packageParts.d.ts +9 -0
  19. package/dist/docx/packageParts.js +16 -0
  20. package/dist/docx/packagePrefixes.d.ts +12 -0
  21. package/dist/docx/packagePrefixes.js +18 -0
  22. package/dist/docx/partPlan.js +3 -5
  23. package/dist/docx/sdt.d.ts +27 -0
  24. package/dist/docx/sdt.js +14 -1
  25. package/dist/docx/serializeBlock.js +4 -3
  26. package/dist/docx/serializeParagraph.d.ts +2 -1
  27. package/dist/docx/serializeParagraph.js +6 -1
  28. package/dist/docx/serializeSdtBlock.d.ts +0 -8
  29. package/dist/docx/serializeSdtBlock.js +1 -5
  30. package/dist/docx/storyParts.d.ts +3 -0
  31. package/dist/docx/storyParts.js +4 -1
  32. package/dist/docx/wrappers.d.ts +23 -8
  33. package/dist/docx/wrappers.js +33 -2
  34. package/dist/editor/blockControlEdits.d.ts +2 -2
  35. package/dist/editor/blockControlEdits.js +6 -6
  36. package/dist/editor/commands/lockCommands.js +25 -5
  37. package/dist/editor/createEditor.d.ts +4 -1
  38. package/dist/editor/createEditor.js +14 -2
  39. package/dist/editor/editRefusal.d.ts +68 -0
  40. package/dist/editor/editRefusal.js +177 -0
  41. package/dist/editor/inlineControlEdits.d.ts +20 -0
  42. package/dist/editor/inlineControlEdits.js +69 -0
  43. package/dist/editor/plugins/controlContents.d.ts +24 -0
  44. package/dist/editor/plugins/controlContents.js +260 -0
  45. package/dist/editor/plugins/controlLifecycle.js +3 -5
  46. package/dist/editor/plugins/keymap.js +18 -7
  47. package/dist/editor/stories/storyState.js +2 -0
  48. package/dist/index.d.ts +2 -0
  49. package/dist/ooxml/element.js +3 -2
  50. package/dist/ooxml/errors.d.ts +11 -0
  51. package/dist/ooxml/fragment.js +3 -2
  52. package/dist/ooxml/names.d.ts +4 -0
  53. package/dist/ooxml/names.js +8 -2
  54. package/dist/ooxml/partPrefixes.d.ts +21 -0
  55. package/dist/ooxml/partPrefixes.js +164 -0
  56. package/dist/ooxml/partSplice.d.ts +6 -1
  57. package/dist/ooxml/partSplice.js +30 -10
  58. package/dist/ooxml/tagScan.d.ts +24 -2
  59. package/dist/ooxml/tagScan.js +26 -7
  60. package/dist/ooxml/xml.d.ts +8 -0
  61. package/dist/ooxml/xml.js +27 -5
  62. package/dist/schema/attrRoles.js +11 -0
  63. package/dist/schema/clipboard.js +2 -0
  64. package/dist/schema/controlAttrs.d.ts +33 -13
  65. package/dist/schema/controlAttrs.js +18 -6
  66. package/dist/schema/docxSchema.d.ts +1 -1
  67. package/dist/schema/docxSchema.js +60 -5
  68. package/dist/schema/guards.d.ts +8 -2
  69. package/dist/schema/guards.js +14 -8
  70. package/dist/schema/locks.d.ts +62 -7
  71. package/dist/schema/locks.js +99 -25
  72. package/dist/styles/classNames.d.ts +4 -0
  73. package/dist/styles/classNames.js +4 -0
  74. package/dist/styles.css +78 -14
  75. package/dist/ui/MenuNote.d.ts +12 -0
  76. package/dist/ui/MenuNote.js +14 -0
  77. package/dist/ui/TableMenu.js +38 -19
  78. package/dist/ui/TextMenu.js +31 -25
  79. package/package.json +2 -2
package/dist/styles.css CHANGED
@@ -629,9 +629,6 @@ button.docx-editor-comment-body {
629
629
  }
630
630
  }
631
631
 
632
- @media (max-width: 420px) {
633
- }
634
-
635
632
  .docx-editor-sheet {
636
633
  /*
637
634
  * The paper size, and the margins printed inside it.
@@ -1004,21 +1001,39 @@ button.docx-editor-comment-body {
1004
1001
  }
1005
1002
 
1006
1003
  /*
1007
- * A content control that says its contents may not be edited (`editor/plugins/lockedContent` refuses
1008
- * the edits). Yellow is what the contract templates already paint their settled parts with.
1009
- * A background the run itself carries (`w:shd`, a highlight) paints over this one, so the
1010
- * outline is drawn as well: outlines go on last, whatever the content paints.
1004
+ * A content control that shuts its contents (`editor/plugins/lockedContent` refuses the edits), and
1005
+ * one that leaves them open, each drawn from a pair of properties a host may set (`--docx-editor-
1006
+ * locked-*`, `--docx-editor-control-*`).
1007
+ *
1008
+ * The tint is painted as a background image rather than a background colour: a run, a paragraph
1009
+ * and a cell write the document's own shading as an inline `background-color`, which would win
1010
+ * over a colour set here - a cell whose `w:shd` says `auto` draws as `transparent` - while an
1011
+ * image layer is painted over it. The default tint is a translucent yellow that lands on #fff59d
1012
+ * over white paper, so a shaded cell's own colour still shows through it.
1013
+ * A run's own shading is a box inside the control and paints over the tint, so an outline is drawn
1014
+ * as well: outlines go on last, whatever the content paints. An open control is not marked unless
1015
+ * the host asks for it.
1011
1016
  */
1012
1017
  .docx-editor-sdt-locked {
1013
- background: #fff59d;
1014
- outline: 1px solid #f9a825;
1018
+ background-image: linear-gradient(
1019
+ var(--docx-editor-locked-background, rgb(255 235 59 / 50%)) 0 0
1020
+ );
1021
+ outline: var(--docx-editor-locked-outline, 1px solid #f9a825);
1015
1022
  cursor: not-allowed;
1016
1023
  }
1017
1024
 
1025
+ .docx-editor-sdt:not(.docx-editor-sdt-locked),
1026
+ .docx-editor-sdt-block:not(.docx-editor-sdt-locked) {
1027
+ background-image: linear-gradient(
1028
+ var(--docx-editor-control-background, transparent) 0 0
1029
+ );
1030
+ outline: var(--docx-editor-control-outline, none);
1031
+ }
1032
+
1018
1033
  /*
1019
1034
  * A content control that holds nothing occupies nothing on the page: the file says a clause is not
1020
1035
  * 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
1036
+ * A shut control wears the marks above beside this class, and an outline is painted outside the
1022
1037
  * box rather than clipped by it, so a zero height alone would leave a 1px rule across the page.
1023
1038
  */
1024
1039
  .docx-editor-sdt-empty {
@@ -1028,6 +1043,19 @@ button.docx-editor-comment-body {
1028
1043
  outline: none;
1029
1044
  }
1030
1045
 
1046
+ /*
1047
+ * The same control standing inside a paragraph, which takes no width between the words either
1048
+ * side of it: the file says a phrase is not there, and a box drawn for it would be a phrase of its
1049
+ * own. This is the shape a preserved fragment with nothing to show takes above.
1050
+ */
1051
+ .docx-editor-sdt-empty-inline {
1052
+ display: inline-block;
1053
+ width: 0;
1054
+ overflow: hidden;
1055
+ outline: none;
1056
+ vertical-align: baseline;
1057
+ }
1058
+
1031
1059
  /*
1032
1060
  * The space a block-level content control opens between two of the blocks it holds, so what
1033
1061
  * follows starts the next page (`page/kinds/sdtBlockKind`). The control's own outline runs down
@@ -1044,17 +1072,46 @@ button.docx-editor-comment-body {
1044
1072
 
1045
1073
  /*
1046
1074
  * 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
1048
- * border so the mark follows the cell rather than the text standing in it.
1075
+ * around the row, which carry no lock of their own. The same marks as above, outlined just inside
1076
+ * the cell border so the mark follows the cell rather than the text standing in it. A cell or a row
1077
+ * carries the control's opening XML only when a control stands around it.
1049
1078
  */
1050
1079
  .docx-editor-tc-locked,
1051
1080
  .docx-editor-tr-locked > .docx-editor-tc {
1052
- background: #fff59d;
1053
- outline: 1px solid #f9a825;
1081
+ background-image: linear-gradient(
1082
+ var(--docx-editor-locked-background, rgb(255 235 59 / 50%)) 0 0
1083
+ );
1084
+ outline: var(--docx-editor-locked-outline, 1px solid #f9a825);
1054
1085
  outline-offset: -1px;
1055
1086
  cursor: not-allowed;
1056
1087
  }
1057
1088
 
1089
+ .docx-editor-tc[data-sdt-prefix]:not(.docx-editor-tc-locked),
1090
+ .docx-editor-tr[data-sdt-prefix]:not(.docx-editor-tr-locked)
1091
+ > .docx-editor-tc:not(.docx-editor-tc-locked) {
1092
+ background-image: linear-gradient(
1093
+ var(--docx-editor-control-background, transparent) 0 0
1094
+ );
1095
+ outline: var(--docx-editor-control-outline, none);
1096
+ outline-offset: -1px;
1097
+ }
1098
+
1099
+ /*
1100
+ * A lock shuts every control inside it (`spec/notes/contentControls.md`), so an open control there
1101
+ * is drawn as the shut content around it rather than as a place to type. A group is superseded by
1102
+ * the controls it holds, and draws them as open.
1103
+ */
1104
+ [data-sdt-contents-locked] .docx-editor-sdt:not(.docx-editor-sdt-locked),
1105
+ [data-sdt-contents-locked] .docx-editor-sdt-block:not(.docx-editor-sdt-locked),
1106
+ [data-sdt-contents-locked]
1107
+ .docx-editor-tc[data-sdt-prefix]:not(.docx-editor-tc-locked),
1108
+ [data-sdt-contents-locked]
1109
+ .docx-editor-tr[data-sdt-prefix]:not(.docx-editor-tr-locked)
1110
+ > .docx-editor-tc:not(.docx-editor-tc-locked) {
1111
+ background-image: none;
1112
+ outline: none;
1113
+ }
1114
+
1058
1115
  /*
1059
1116
  * A preserved fragment inside a paragraph or inside a run. What it draws is the `display` the
1060
1117
  * preservation rule gave it (`docx/importPolicy`), so the rule is read here as an attribute
@@ -1683,6 +1740,13 @@ button.docx-editor-comment-body {
1683
1740
  border-top: 1px solid #e6e6e6;
1684
1741
  }
1685
1742
 
1743
+ .docx-editor-menu-note {
1744
+ margin: 0 0 4px;
1745
+ padding: 6px 10px;
1746
+ border-bottom: 1px solid #e6e6e6;
1747
+ color: #5f6368;
1748
+ }
1749
+
1686
1750
  @media (max-width: 720px) {
1687
1751
  .docx-editor-popover,
1688
1752
  .docx-editor-menu,
@@ -0,0 +1,12 @@
1
+ /**
2
+ * A line at the head of a right-click menu saying why its editing entries stand disabled.
3
+ *
4
+ * A menu holds only its items, so the line is presentational and the menu names it as its
5
+ * description instead, which is what a screen reader reads out when the menu opens.
6
+ */
7
+ import type { ReactElement } from "react";
8
+ export declare const LOCKED_NOTE = "Locked content can't be edited.";
9
+ export declare function MenuNote({ id, text, }: {
10
+ id: string;
11
+ text: string;
12
+ }): ReactElement;
@@ -0,0 +1,14 @@
1
+ // src/ui/MenuNote.tsx
2
+ import { editorClassNames } from "../styles/classNames.js";
3
+ import { jsx } from "react/jsx-runtime";
4
+ var LOCKED_NOTE = "Locked content can't be edited.";
5
+ function MenuNote({
6
+ id,
7
+ text
8
+ }) {
9
+ return /* @__PURE__ */ jsx("p", { id, role: "none", className: editorClassNames.menuNote, children: text });
10
+ }
11
+ export {
12
+ LOCKED_NOTE,
13
+ MenuNote
14
+ };
@@ -1,6 +1,10 @@
1
1
  // src/ui/TableMenu.tsx
2
- import { Fragment, useCallback, useRef } from "react";
3
- import { unlockSelection } from "../editor/commands/lockCommands.js";
2
+ import { Fragment, useCallback, useId, useRef } from "react";
3
+ import {
4
+ documentHasLocked,
5
+ selectionTouchesLocked,
6
+ unlockSelection
7
+ } from "../editor/commands/lockCommands.js";
4
8
  import {
5
9
  closeTableMenu
6
10
  } from "../editor/plugins/tableContextMenu.js";
@@ -16,6 +20,7 @@ import {
16
20
  mergeCells,
17
21
  splitCell
18
22
  } from "../table/index.js";
23
+ import { LOCKED_NOTE, MenuNote } from "./MenuNote.js";
19
24
  import { noteItems } from "./noteItems.js";
20
25
  import { usePanelAtPoint } from "./panelPlacement.js";
21
26
  import { commandRunner } from "./runCommand.js";
@@ -65,6 +70,14 @@ function noteGroup(takes) {
65
70
  }))
66
71
  };
67
72
  }
73
+ function tableHoldsLock(state) {
74
+ const { $from } = state.selection;
75
+ for (let depth = $from.depth; depth > 0; depth -= 1) {
76
+ const node = $from.node(depth);
77
+ if (node.type.spec.tableRole === "table") return documentHasLocked(node);
78
+ }
79
+ return false;
80
+ }
68
81
  function TableMenu({
69
82
  view,
70
83
  state,
@@ -81,6 +94,8 @@ function TableMenu({
81
94
  }, [view]);
82
95
  useDismiss(box, true, close);
83
96
  const keys = useMenuKeyboard({ menu: box, onClose: close });
97
+ const noteId = useId();
98
+ const lockInReach = selectionTouchesLocked(state) || tableHoldsLock(state);
84
99
  const choose = (command) => {
85
100
  if (!command(state)) return;
86
101
  run(command);
@@ -92,35 +107,39 @@ function TableMenu({
92
107
  ...note === null ? [] : [note],
93
108
  ...allowLocking ? [UNLOCK_GROUP] : []
94
109
  ];
95
- return /* @__PURE__ */ jsx(
110
+ return /* @__PURE__ */ jsxs(
96
111
  "div",
97
112
  {
98
113
  ref: box,
99
114
  className: editorClassNames.menu,
100
115
  role: "menu",
101
116
  "aria-label": "Table actions",
117
+ "aria-describedby": lockInReach ? noteId : void 0,
102
118
  ...keys,
103
119
  style: {
104
120
  left: placement?.left ?? anchor.clientX,
105
121
  top: placement?.top ?? anchor.clientY,
106
122
  visibility: placement ? void 0 : "hidden"
107
123
  },
108
- children: groups.map((group, index) => /* @__PURE__ */ jsxs(Fragment, { children: [
109
- index > 0 && /* @__PURE__ */ jsx("hr", { className: editorClassNames.menuSeparator }),
110
- group.items.map((item) => /* @__PURE__ */ jsx(
111
- "button",
112
- {
113
- type: "button",
114
- role: "menuitem",
115
- className: editorClassNames.menuItem,
116
- "aria-disabled": !item.command(state),
117
- onMouseDown: (event) => event.preventDefault(),
118
- onClick: () => choose(item.command),
119
- children: item.label
120
- },
121
- item.label
122
- ))
123
- ] }, group.name))
124
+ children: [
125
+ lockInReach && /* @__PURE__ */ jsx(MenuNote, { id: noteId, text: LOCKED_NOTE }),
126
+ groups.map((group, index) => /* @__PURE__ */ jsxs(Fragment, { children: [
127
+ index > 0 && /* @__PURE__ */ jsx("hr", { className: editorClassNames.menuSeparator }),
128
+ group.items.map((item) => /* @__PURE__ */ jsx(
129
+ "button",
130
+ {
131
+ type: "button",
132
+ role: "menuitem",
133
+ className: editorClassNames.menuItem,
134
+ "aria-disabled": !item.command(state),
135
+ onMouseDown: (event) => event.preventDefault(),
136
+ onClick: () => choose(item.command),
137
+ children: item.label
138
+ },
139
+ item.label
140
+ ))
141
+ ] }, group.name))
142
+ ]
124
143
  }
125
144
  );
126
145
  }
@@ -9,7 +9,7 @@ import {
9
9
  Trash2
10
10
  } from "lucide-react";
11
11
  import { deleteSelection } from "prosemirror-commands";
12
- import { Fragment, useCallback, useRef } from "react";
12
+ import { Fragment, useCallback, useId, useRef } from "react";
13
13
  import { canAddComment } from "../editor/commands/commentCommands.js";
14
14
  import {
15
15
  lockSelection,
@@ -23,6 +23,7 @@ import {
23
23
  } from "../editor/plugins/textContextMenu.js";
24
24
  import { editsShut } from "../schema/protectionState.js";
25
25
  import { editorClassNames } from "../styles/classNames.js";
26
+ import { LOCKED_NOTE, MenuNote } from "./MenuNote.js";
26
27
  import { noteItems } from "./noteItems.js";
27
28
  import { usePanelAtPoint } from "./panelPlacement.js";
28
29
  import { commandRunner } from "./runCommand.js";
@@ -110,6 +111,7 @@ function TextMenu({
110
111
  }, [view]);
111
112
  useDismiss(box, true, close);
112
113
  const keys = useMenuKeyboard({ menu: box, onClose: close });
114
+ const noteId = useId();
113
115
  const selected = !state.selection.empty;
114
116
  const shut = selectionTouchesLocked(state);
115
117
  const { mod } = modifierLabels();
@@ -176,42 +178,46 @@ function TextMenu({
176
178
  item.run();
177
179
  close();
178
180
  };
179
- return /* @__PURE__ */ jsx(
181
+ return /* @__PURE__ */ jsxs(
180
182
  "div",
181
183
  {
182
184
  ref: box,
183
185
  className: editorClassNames.menu,
184
186
  role: "menu",
185
187
  "aria-label": "Text actions",
188
+ "aria-describedby": bodyOpen && shut ? noteId : void 0,
186
189
  ...keys,
187
190
  style: {
188
191
  left: placement?.left ?? anchor.clientX,
189
192
  top: placement?.top ?? anchor.clientY,
190
193
  visibility: placement ? void 0 : "hidden"
191
194
  },
192
- children: groups.map((group, index) => /* @__PURE__ */ jsxs(Fragment, { children: [
193
- index > 0 && /* @__PURE__ */ jsx("hr", { className: editorClassNames.menuSeparator }),
194
- group.map((item) => {
195
- const Icon = item.icon;
196
- return /* @__PURE__ */ jsxs(
197
- "button",
198
- {
199
- type: "button",
200
- role: "menuitem",
201
- className: editorClassNames.menuItem,
202
- "aria-disabled": !item.enabled,
203
- onMouseDown: (event) => event.preventDefault(),
204
- onClick: () => choose(item),
205
- children: [
206
- /* @__PURE__ */ jsx(Icon, { size: ICON_SIZE, "aria-hidden": "true" }),
207
- item.label,
208
- item.hint && /* @__PURE__ */ jsx("span", { className: editorClassNames.menuHint, children: item.hint })
209
- ]
210
- },
211
- item.label
212
- );
213
- })
214
- ] }, group[0].label))
195
+ children: [
196
+ bodyOpen && shut && /* @__PURE__ */ jsx(MenuNote, { id: noteId, text: LOCKED_NOTE }),
197
+ groups.map((group, index) => /* @__PURE__ */ jsxs(Fragment, { children: [
198
+ index > 0 && /* @__PURE__ */ jsx("hr", { className: editorClassNames.menuSeparator }),
199
+ group.map((item) => {
200
+ const Icon = item.icon;
201
+ return /* @__PURE__ */ jsxs(
202
+ "button",
203
+ {
204
+ type: "button",
205
+ role: "menuitem",
206
+ className: editorClassNames.menuItem,
207
+ "aria-disabled": !item.enabled,
208
+ onMouseDown: (event) => event.preventDefault(),
209
+ onClick: () => choose(item),
210
+ children: [
211
+ /* @__PURE__ */ jsx(Icon, { size: ICON_SIZE, "aria-hidden": "true" }),
212
+ item.label,
213
+ item.hint && /* @__PURE__ */ jsx("span", { className: editorClassNames.menuHint, children: item.hint })
214
+ ]
215
+ },
216
+ item.label
217
+ );
218
+ })
219
+ ] }, group[0].label))
220
+ ]
215
221
  }
216
222
  );
217
223
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@portone/docx-editor",
3
- "version": "0.6.3",
3
+ "version": "0.6.5",
4
4
  "description": "A simple DOCX editor for React, built directly on OOXML.",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -76,7 +76,7 @@
76
76
  "@biomejs/biome": "2.5.10",
77
77
  "@changesets/changelog-github": "^1.0.0",
78
78
  "@changesets/cli": "^3.0.1",
79
- "@microsoft/api-extractor": "7.59.0",
79
+ "@microsoft/api-extractor": "7.59.1",
80
80
  "@playwright/test": "^1.62.1",
81
81
  "@types/jsdom": "^30.0.0",
82
82
  "@types/node": "^26.2.0",