@portone/docx-editor 0.6.4 → 0.6.6

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 (80) hide show
  1. package/CHANGELOG.md +47 -0
  2. package/CONTRIBUTING.md +4 -4
  3. package/dist/DocxEditor.d.ts +11 -0
  4. package/dist/DocxEditor.js +7 -3
  5. package/dist/core.d.ts +7 -0
  6. package/dist/core.js +2 -0
  7. package/dist/docx/commentOnlyChange.d.ts +4 -4
  8. package/dist/docx/comments/constants.d.ts +7 -0
  9. package/dist/docx/comments/constants.js +13 -1
  10. package/dist/docx/comments/dates.d.ts +22 -0
  11. package/dist/docx/comments/dates.js +102 -0
  12. package/dist/docx/comments/durable.d.ts +22 -0
  13. package/dist/docx/comments/durable.js +138 -0
  14. package/dist/docx/comments/grammar.d.ts +10 -1
  15. package/dist/docx/comments/grammar.js +49 -2
  16. package/dist/docx/comments/model.d.ts +10 -2
  17. package/dist/docx/comments/model.js +38 -8
  18. package/dist/docx/comments/parts.d.ts +53 -7
  19. package/dist/docx/comments/parts.js +163 -20
  20. package/dist/docx/comments/people.d.ts +1 -1
  21. package/dist/docx/comments/people.js +5 -15
  22. package/dist/docx/comments/reading.d.ts +26 -0
  23. package/dist/docx/comments/reading.js +109 -49
  24. package/dist/docx/comments/writing.d.ts +2 -7
  25. package/dist/docx/comments/writing.js +30 -43
  26. package/dist/docx/compareDocx.d.ts +154 -0
  27. package/dist/docx/compareDocx.js +218 -0
  28. package/dist/docx/importParagraph.js +5 -3
  29. package/dist/docx/invariants.js +19 -6
  30. package/dist/docx/packageParts.d.ts +2 -0
  31. package/dist/docx/packageParts.js +5 -1
  32. package/dist/docx/partPlan.d.ts +12 -0
  33. package/dist/docx/partPlan.js +19 -1
  34. package/dist/docx/protectionPolicy.d.ts +33 -5
  35. package/dist/docx/protectionPolicy.js +93 -47
  36. package/dist/docx/sequenceDiff.d.ts +56 -0
  37. package/dist/docx/sequenceDiff.js +252 -0
  38. package/dist/docx/storyProjection.d.ts +2 -0
  39. package/dist/docx/storyProjection.js +10 -9
  40. package/dist/docx/textDiff.d.ts +24 -0
  41. package/dist/docx/textDiff.js +38 -0
  42. package/dist/editor/commands/comments/editing.js +56 -20
  43. package/dist/editor/commands/comments/model.d.ts +3 -1
  44. package/dist/editor/createEditor.d.ts +4 -1
  45. package/dist/editor/createEditor.js +14 -2
  46. package/dist/editor/editRefusal.d.ts +68 -0
  47. package/dist/editor/editRefusal.js +177 -0
  48. package/dist/editor/editorDocument.d.ts +4 -0
  49. package/dist/editor/editorDocument.js +10 -0
  50. package/dist/editor/plugins/commentDecorations.js +6 -2
  51. package/dist/editor/plugins/controlContents.d.ts +24 -0
  52. package/dist/editor/plugins/controlContents.js +260 -0
  53. package/dist/editor/plugins/controlLifecycle.js +3 -5
  54. package/dist/editor/stories/storyState.js +2 -0
  55. package/dist/index.d.ts +2 -0
  56. package/dist/ooxml/errors.d.ts +1 -1
  57. package/dist/ooxml/names.d.ts +2 -0
  58. package/dist/ooxml/names.js +2 -0
  59. package/dist/ooxml/partSplice.d.ts +13 -3
  60. package/dist/ooxml/partSplice.js +45 -18
  61. package/dist/schema/attrRoles.js +3 -1
  62. package/dist/schema/controlAttrs.d.ts +6 -0
  63. package/dist/schema/controlAttrs.js +4 -0
  64. package/dist/schema/docxSchema.js +10 -3
  65. package/dist/schema/guards.d.ts +8 -2
  66. package/dist/schema/guards.js +14 -8
  67. package/dist/schema/locks.d.ts +25 -2
  68. package/dist/schema/locks.js +67 -11
  69. package/dist/schema/protection.js +2 -1
  70. package/dist/styles/classNames.d.ts +2 -0
  71. package/dist/styles/classNames.js +2 -0
  72. package/dist/styles.css +65 -14
  73. package/dist/ui/CommentsPanel.js +8 -13
  74. package/dist/ui/MenuNote.d.ts +12 -0
  75. package/dist/ui/MenuNote.js +14 -0
  76. package/dist/ui/TableMenu.js +38 -19
  77. package/dist/ui/TextMenu.js +31 -25
  78. package/dist/ui/comments/commentDate.d.ts +7 -0
  79. package/dist/ui/comments/commentDate.js +17 -0
  80. package/package.json +7 -7
@@ -20,18 +20,13 @@ import { commentOwned } from "../schema/protection.js";
20
20
  import { protectionOf } from "../schema/protectionState.js";
21
21
  import { editorClassNames } from "../styles/classNames.js";
22
22
  import { CommentComposer, FocusedTextarea } from "./comments/CommentComposer.js";
23
+ import { commentTime, shownCommentDate } from "./comments/commentDate.js";
23
24
  import {
24
25
  COMPOSER_POSITION,
25
26
  useCommentRailLayout
26
27
  } from "./comments/useCommentRailLayout.js";
27
28
  import { tooltipAttribute } from "./Tooltip.js";
28
29
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
29
- function shownDate(value) {
30
- if (value === null) return null;
31
- const date = new Date(value);
32
- if (Number.isNaN(date.valueOf())) return value;
33
- return `${date.toISOString().slice(0, 16).replace("T", " ")} UTC`;
34
- }
35
30
  function run(view, command) {
36
31
  const applied = command(
37
32
  view.state,
@@ -50,7 +45,7 @@ function shownBesideThePage(comment) {
50
45
  function CommentIdentity({
51
46
  comment
52
47
  }) {
53
- const date = shownDate(comment.date);
48
+ const date = shownCommentDate(comment.date);
54
49
  return /* @__PURE__ */ jsxs(Fragment, { children: [
55
50
  /* @__PURE__ */ jsx("span", { className: editorClassNames.commentAuthor, children: comment.author ?? "Unknown author" }),
56
51
  date && /* @__PURE__ */ jsx("span", { className: editorClassNames.commentDate, children: date })
@@ -79,13 +74,13 @@ function CommentsPanel({
79
74
  const composerSelectionPos = composerRange?.from ?? -1;
80
75
  const visible = useMemo(
81
76
  () => allCommentsOpen ? [...comments].sort((left, right) => {
82
- const leftTime = Date.parse(left.date ?? "");
83
- const rightTime = Date.parse(right.date ?? "");
84
- if (Number.isNaN(leftTime) && Number.isNaN(rightTime)) {
77
+ const leftTime = commentTime(left.date);
78
+ const rightTime = commentTime(right.date);
79
+ if (leftTime === null && rightTime === null) {
85
80
  return right.referencePos - left.referencePos;
86
81
  }
87
- if (Number.isNaN(leftTime)) return 1;
88
- if (Number.isNaN(rightTime)) return -1;
82
+ if (leftTime === null) return 1;
83
+ if (rightTime === null) return -1;
89
84
  return rightTime - leftTime;
90
85
  }) : comments.filter(shownBesideThePage),
91
86
  [allCommentsOpen, comments]
@@ -281,7 +276,7 @@ function CommentsPanel({
281
276
  children: [
282
277
  /* @__PURE__ */ jsxs("div", { className: editorClassNames.commentMeta, children: [
283
278
  /* @__PURE__ */ jsx("span", { className: editorClassNames.commentAuthor, children: reply.author ?? "Unknown author" }),
284
- shownDate(reply.date) && /* @__PURE__ */ jsx("span", { className: editorClassNames.commentDate, children: shownDate(reply.date) })
279
+ shownCommentDate(reply.date) && /* @__PURE__ */ jsx("span", { className: editorClassNames.commentDate, children: shownCommentDate(reply.date) })
285
280
  ] }),
286
281
  isEditing ? /* @__PURE__ */ jsx(
287
282
  FocusedTextarea,
@@ -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
  }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Null for a date that is not an instant as `toISOString` spells one: that is a date the document
3
+ * wrote as no time, which the browser would still read, `2026-02-30` as the second of March.
4
+ */
5
+ export declare function commentTime(value: string | null): number | null;
6
+ /** In the reader's zone and browser language; a date naming no instant is shown as written */
7
+ export declare function shownCommentDate(value: string | null, locales?: Intl.LocalesArgument): string | null;
@@ -0,0 +1,17 @@
1
+ // src/ui/comments/commentDate.ts
2
+ function commentTime(value) {
3
+ if (value === null) return null;
4
+ const time = Date.parse(value);
5
+ return Number.isNaN(time) || new Date(time).toISOString() !== value ? null : time;
6
+ }
7
+ function shownCommentDate(value, locales) {
8
+ const time = commentTime(value);
9
+ return time === null ? value : new Intl.DateTimeFormat(locales, {
10
+ dateStyle: "medium",
11
+ timeStyle: "short"
12
+ }).format(time);
13
+ }
14
+ export {
15
+ commentTime,
16
+ shownCommentDate
17
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@portone/docx-editor",
3
- "version": "0.6.4",
3
+ "version": "0.6.6",
4
4
  "description": "A simple DOCX editor for React, built directly on OOXML.",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -73,15 +73,15 @@
73
73
  "react": ">=18"
74
74
  },
75
75
  "devDependencies": {
76
- "@biomejs/biome": "2.5.10",
76
+ "@biomejs/biome": "2.5.14",
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",
83
- "@types/react": "19.2.18",
84
- "@types/react-dom": "19.2.7",
83
+ "@types/react": "19.3.0",
84
+ "@types/react-dom": "19.3.0",
85
85
  "@vitejs/plugin-react": "^6.0.5",
86
86
  "esbuild": "^0.28.1",
87
87
  "jsdom": "^30.0.1",
@@ -95,8 +95,8 @@
95
95
  "prosemirror-tables": "^1.8.5",
96
96
  "prosemirror-transform": "^1.12.0",
97
97
  "prosemirror-view": "^1.41.6",
98
- "react": "^19.2.8",
99
- "react-dom": "^19.2.8",
98
+ "react": "^19.3.0",
99
+ "react-dom": "^19.3.0",
100
100
  "typescript": "^7.0.2",
101
101
  "vite": "^8.0.12",
102
102
  "vitest": "^5.0.0"