@portone/docx-editor 0.6.0 → 0.6.2

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 (146) hide show
  1. package/CHANGELOG.md +40 -0
  2. package/dist/DocxEditor.js +84 -26
  3. package/dist/core.d.ts +4 -3
  4. package/dist/docx/exportDocx.d.ts +3 -2
  5. package/dist/docx/exportDocx.js +6 -10
  6. package/dist/docx/headersFooters.js +35 -23
  7. package/dist/docx/identities.d.ts +30 -0
  8. package/dist/docx/identities.js +43 -10
  9. package/dist/docx/importDocx.js +25 -26
  10. package/dist/docx/importParagraph.d.ts +1 -4
  11. package/dist/docx/importParagraph.js +4 -18
  12. package/dist/docx/invariants.d.ts +13 -10
  13. package/dist/docx/invariants.js +300 -116
  14. package/dist/docx/newLists.js +12 -3
  15. package/dist/docx/notes/newNote.d.ts +39 -0
  16. package/dist/docx/notes/newNote.js +122 -0
  17. package/dist/docx/notes/numbering.d.ts +27 -0
  18. package/dist/docx/notes/numbering.js +113 -0
  19. package/dist/docx/notes/reading.d.ts +58 -0
  20. package/dist/docx/notes/reading.js +98 -0
  21. package/dist/docx/notes/references.d.ts +33 -0
  22. package/dist/docx/notes/references.js +37 -0
  23. package/dist/docx/notes/writing.d.ts +19 -0
  24. package/dist/docx/notes/writing.js +95 -0
  25. package/dist/docx/partPlan.d.ts +3 -0
  26. package/dist/docx/partPlanners.d.ts +13 -0
  27. package/dist/docx/partPlanners.js +48 -0
  28. package/dist/docx/sections.d.ts +5 -0
  29. package/dist/docx/sections.js +7 -2
  30. package/dist/docx/serializeParagraph.js +7 -2
  31. package/dist/docx/serializePreserved.d.ts +5 -1
  32. package/dist/docx/serializePreserved.js +24 -7
  33. package/dist/docx/session.d.ts +5 -0
  34. package/dist/docx/session.js +6 -0
  35. package/dist/docx/storyParts.d.ts +133 -0
  36. package/dist/docx/storyParts.js +314 -0
  37. package/dist/editor/clipboard/htmlReader.d.ts +24 -4
  38. package/dist/editor/clipboard/htmlReader.js +39 -4
  39. package/dist/editor/clipboard/internalChannel.d.ts +30 -3
  40. package/dist/editor/clipboard/internalChannel.js +43 -3
  41. package/dist/editor/clipboard/normalizers.d.ts +35 -8
  42. package/dist/editor/clipboard/normalizers.js +60 -11
  43. package/dist/editor/clipboard/plugin.js +42 -22
  44. package/dist/editor/commands/exportQueries.d.ts +4 -3
  45. package/dist/editor/commands/index.d.ts +2 -1
  46. package/dist/editor/commands/index.js +18 -0
  47. package/dist/editor/commands/noteCommands.d.ts +47 -0
  48. package/dist/editor/commands/noteCommands.js +95 -0
  49. package/dist/editor/commands/noteQueries.d.ts +22 -3
  50. package/dist/editor/commands/noteQueries.js +21 -13
  51. package/dist/editor/createEditor.js +21 -3
  52. package/dist/editor/documentStyles.d.ts +3 -0
  53. package/dist/editor/documentStyles.js +2 -1
  54. package/dist/editor/editorDocument.d.ts +24 -0
  55. package/dist/editor/editorDocument.js +34 -4
  56. package/dist/editor/notes/noteSurface.d.ts +53 -0
  57. package/dist/editor/notes/noteSurface.js +246 -0
  58. package/dist/editor/plugins/compositionSelection.d.ts +20 -0
  59. package/dist/editor/plugins/compositionSelection.js +19 -0
  60. package/dist/editor/plugins/keymap.d.ts +14 -0
  61. package/dist/editor/plugins/keymap.js +13 -1
  62. package/dist/editor/plugins/noteLifecycle.d.ts +18 -0
  63. package/dist/editor/plugins/noteLifecycle.js +117 -0
  64. package/dist/editor/plugins/noteNavigation.d.ts +45 -0
  65. package/dist/editor/plugins/noteNavigation.js +86 -0
  66. package/dist/editor/plugins/noteNumbering.d.ts +13 -0
  67. package/dist/editor/plugins/noteNumbering.js +58 -0
  68. package/dist/editor/plugins/rowResize.js +2 -7
  69. package/dist/editor/plugins/tabLayout.js +2 -7
  70. package/dist/editor/stories/storyMarkup.d.ts +24 -0
  71. package/dist/editor/stories/storyMarkup.js +35 -0
  72. package/dist/editor/stories/storyState.d.ts +34 -0
  73. package/dist/editor/stories/storyState.js +74 -0
  74. package/dist/editor/stories/storyView.d.ts +115 -0
  75. package/dist/editor/stories/storyView.js +144 -0
  76. package/dist/index.d.ts +2 -2
  77. package/dist/numbering/spellers.d.ts +1 -1
  78. package/dist/numbering/spellers.js +6 -1
  79. package/dist/ooxml/errors.d.ts +135 -2
  80. package/dist/ooxml/errors.js +6 -0
  81. package/dist/page/blockKinds.d.ts +23 -4
  82. package/dist/page/demands/footnoteDemands.d.ts +18 -0
  83. package/dist/page/demands/footnoteDemands.js +51 -0
  84. package/dist/page/demands/index.d.ts +43 -0
  85. package/dist/page/demands/index.js +8 -0
  86. package/dist/page/kinds/paragraphKind.js +7 -1
  87. package/dist/page/kinds/tableKind.js +9 -1
  88. package/dist/page/measureBlocks.d.ts +2 -0
  89. package/dist/page/measureBlocks.js +31 -10
  90. package/dist/page/pageDecorations.d.ts +9 -2
  91. package/dist/page/pageDecorations.js +18 -5
  92. package/dist/page/pageLayout.d.ts +77 -1
  93. package/dist/page/pageLayout.js +186 -9
  94. package/dist/page/usePageLayout.d.ts +57 -2
  95. package/dist/page/usePageLayout.js +50 -5
  96. package/dist/schema/attrRoles.js +3 -2
  97. package/dist/schema/docxSchema.js +5 -2
  98. package/dist/schema/editGuard.d.ts +1 -1
  99. package/dist/schema/guards.js +1 -2
  100. package/dist/schema/preservedGuards.d.ts +4 -6
  101. package/dist/schema/preservedGuards.js +0 -9
  102. package/dist/schema/stories.d.ts +42 -2
  103. package/dist/schema/stories.js +28 -5
  104. package/dist/styles/classNames.d.ts +21 -6
  105. package/dist/styles/classNames.js +21 -6
  106. package/dist/styles/inlineStyle.d.ts +7 -0
  107. package/dist/styles/inlineStyle.js +11 -5
  108. package/dist/styles/visualScale.d.ts +19 -0
  109. package/dist/styles/visualScale.js +26 -0
  110. package/dist/styles.css +89 -32
  111. package/dist/ui/InsertImageButton.d.ts +3 -1
  112. package/dist/ui/InsertImageButton.js +3 -2
  113. package/dist/ui/TableMenu.d.ts +5 -2
  114. package/dist/ui/TableMenu.js +18 -1
  115. package/dist/ui/TextMenu.d.ts +5 -2
  116. package/dist/ui/TextMenu.js +21 -6
  117. package/dist/ui/Toolbar.d.ts +17 -2
  118. package/dist/ui/Toolbar.js +23 -10
  119. package/dist/ui/comments/useCommentRailLayout.js +2 -4
  120. package/dist/ui/noteItems.d.ts +21 -0
  121. package/dist/ui/noteItems.js +30 -0
  122. package/dist/ui/notes/NoteAreas.d.ts +73 -0
  123. package/dist/ui/notes/NoteAreas.js +131 -0
  124. package/dist/ui/notes/NoteList.d.ts +25 -0
  125. package/dist/ui/notes/NoteList.js +58 -0
  126. package/dist/ui/notes/StoryRow.d.ts +75 -0
  127. package/dist/ui/notes/StoryRow.js +122 -0
  128. package/dist/ui/notes/noteBands.d.ts +100 -0
  129. package/dist/ui/notes/noteBands.js +142 -0
  130. package/dist/ui/notes/noteHeights.d.ts +10 -0
  131. package/dist/ui/notes/noteHeights.js +24 -0
  132. package/dist/ui/notes/noteSeparator.d.ts +12 -0
  133. package/dist/ui/notes/noteSeparator.js +9 -0
  134. package/dist/ui/notes/useStorySurface.d.ts +68 -0
  135. package/dist/ui/notes/useStorySurface.js +95 -0
  136. package/dist/ui/runCommand.d.ts +8 -1
  137. package/dist/ui/runCommand.js +2 -2
  138. package/dist/ui/shortcutLabels.d.ts +16 -0
  139. package/dist/ui/shortcutLabels.js +9 -0
  140. package/dist/ui/usePageRoom.d.ts +13 -0
  141. package/dist/ui/usePageRoom.js +31 -0
  142. package/package.json +1 -1
  143. package/dist/docx/notes.d.ts +0 -27
  144. package/dist/docx/notes.js +0 -55
  145. package/dist/ui/NotesPanel.d.ts +0 -6
  146. package/dist/ui/NotesPanel.js +0 -33
@@ -0,0 +1,31 @@
1
+ // src/ui/usePageRoom.ts
2
+ import { useLayoutEffect } from "react";
3
+ function usePageRoom(box, layer, scale) {
4
+ useLayoutEffect(() => {
5
+ if (!box || !layer) return;
6
+ const frameWindow = box.ownerDocument.defaultView;
7
+ let frame = 0;
8
+ const hold = () => {
9
+ const next = `${layer.getBoundingClientRect().height}px`;
10
+ if (box.style.height !== next) box.style.height = next;
11
+ };
12
+ const schedule = () => {
13
+ if (frame !== 0 || !frameWindow) return;
14
+ frame = frameWindow.requestAnimationFrame(() => {
15
+ frame = 0;
16
+ hold();
17
+ });
18
+ };
19
+ hold();
20
+ const observer = typeof ResizeObserver === "undefined" ? null : new ResizeObserver(schedule);
21
+ observer?.observe(layer);
22
+ return () => {
23
+ observer?.disconnect();
24
+ if (frame !== 0) frameWindow?.cancelAnimationFrame(frame);
25
+ box.style.removeProperty("height");
26
+ };
27
+ }, [box, layer, scale]);
28
+ }
29
+ export {
30
+ usePageRoom
31
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@portone/docx-editor",
3
- "version": "0.6.0",
3
+ "version": "0.6.2",
4
4
  "description": "A simple DOCX editor for React, built directly on OOXML.",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -1,27 +0,0 @@
1
- /** Reads footnote and endnote bodies related from the main document story. */
2
- export type NoteKind = "footnote" | "endnote";
3
- /**
4
- * One entry of a notes part as it arrived. What the note says is a story of its own, held on the
5
- * document node under `footnote:<id>` or `endnote:<id>` (`docx/story`).
6
- */
7
- export interface ImportedNote {
8
- kind: NoteKind;
9
- id: string;
10
- label: string;
11
- type: string | null;
12
- }
13
- export interface ImportedNotePart {
14
- partPath: string | null;
15
- /** The raw text of the part, which is what the note stories are sliced out of. null for none */
16
- xml: string | null;
17
- ordered: readonly ImportedNote[];
18
- byId: ReadonlyMap<string, ImportedNote>;
19
- }
20
- export interface ImportedNotes {
21
- footnotes: ImportedNotePart;
22
- endnotes: ImportedNotePart;
23
- }
24
- export declare const NO_NOTES: ImportedNotes;
25
- /** Reads both note parts without modifying their original package bytes. */
26
- export declare function readNotes(parts: Map<string, Uint8Array>, mainPartPath: string): ImportedNotes;
27
- export declare function noteById(notes: ImportedNotes, kind: NoteKind, id: string): ImportedNote | undefined;
@@ -1,55 +0,0 @@
1
- // src/docx/notes.ts
2
- import {
3
- attributeByLocalName,
4
- decodeUtf8,
5
- elementChildren,
6
- parseXml,
7
- R_NS
8
- } from "../ooxml/xml.js";
9
- import { relatedPartPath } from "./packageParts.js";
10
- var EMPTY_PART = {
11
- partPath: null,
12
- xml: null,
13
- ordered: [],
14
- byId: /* @__PURE__ */ new Map()
15
- };
16
- var NO_NOTES = {
17
- footnotes: EMPTY_PART,
18
- endnotes: EMPTY_PART
19
- };
20
- function notePart(parts, mainPartPath, kind) {
21
- const partPath = relatedPartPath(parts, mainPartPath, `${R_NS}/${kind}s`);
22
- if (partPath === null) return EMPTY_PART;
23
- const bytes = parts.get(partPath);
24
- if (!bytes) return { ...EMPTY_PART, partPath };
25
- const xml = decodeUtf8(bytes).text;
26
- const root = parseXml(xml).documentElement;
27
- const elements = elementChildren(root).filter((el) => el.localName === kind);
28
- const ordered = elements.flatMap((el) => {
29
- const id = attributeByLocalName(el, "id");
30
- if (id === null) return [];
31
- const type = attributeByLocalName(el, "type");
32
- const regular = type === null || type === "normal";
33
- const label = regular ? "?" : "";
34
- return [{ kind, id, label, type }];
35
- });
36
- const byId = /* @__PURE__ */ new Map();
37
- for (const note of ordered) {
38
- if (!byId.has(note.id)) byId.set(note.id, note);
39
- }
40
- return { partPath, xml, ordered, byId };
41
- }
42
- function readNotes(parts, mainPartPath) {
43
- return {
44
- footnotes: notePart(parts, mainPartPath, "footnote"),
45
- endnotes: notePart(parts, mainPartPath, "endnote")
46
- };
47
- }
48
- function noteById(notes, kind, id) {
49
- return notes[`${kind}s`].byId.get(id);
50
- }
51
- export {
52
- NO_NOTES,
53
- noteById,
54
- readNotes
55
- };
@@ -1,6 +0,0 @@
1
- import type { EditorState } from "prosemirror-state";
2
- import type { ReactElement } from "react";
3
- export declare function NotesPanel({ state, pageWidth, }: {
4
- state: EditorState;
5
- pageWidth: number;
6
- }): ReactElement | null;
@@ -1,33 +0,0 @@
1
- // src/ui/NotesPanel.tsx
2
- import { noteProjection } from "../editor/commands/noteQueries.js";
3
- import { editorClassNames } from "../styles/classNames.js";
4
- import { jsx, jsxs } from "react/jsx-runtime";
5
- function NotesPanel({
6
- state,
7
- pageWidth
8
- }) {
9
- const { notes } = noteProjection.read(state);
10
- if (notes.length === 0) return null;
11
- return /* @__PURE__ */ jsxs(
12
- "section",
13
- {
14
- className: editorClassNames.notesPanel,
15
- "aria-label": "Document notes",
16
- style: { width: `${pageWidth}px` },
17
- children: [
18
- /* @__PURE__ */ jsx("h2", { className: editorClassNames.notesHeading, children: "Footnotes and endnotes" }),
19
- /* @__PURE__ */ jsx("ol", { className: editorClassNames.notesList, children: notes.map((note) => /* @__PURE__ */ jsxs("li", { children: [
20
- /* @__PURE__ */ jsxs("span", { className: editorClassNames.noteLabel, children: [
21
- note.kind === "footnote" ? "Footnote" : "Endnote",
22
- " ",
23
- note.label
24
- ] }),
25
- /* @__PURE__ */ jsx("p", { className: editorClassNames.noteBody, children: note.text })
26
- ] }, `${note.kind}:${note.id}`)) })
27
- ]
28
- }
29
- );
30
- }
31
- export {
32
- NotesPanel
33
- };