@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.
- package/CHANGELOG.md +40 -0
- package/dist/DocxEditor.js +84 -26
- package/dist/core.d.ts +4 -3
- package/dist/docx/exportDocx.d.ts +3 -2
- package/dist/docx/exportDocx.js +6 -10
- package/dist/docx/headersFooters.js +35 -23
- package/dist/docx/identities.d.ts +30 -0
- package/dist/docx/identities.js +43 -10
- package/dist/docx/importDocx.js +25 -26
- package/dist/docx/importParagraph.d.ts +1 -4
- package/dist/docx/importParagraph.js +4 -18
- package/dist/docx/invariants.d.ts +13 -10
- package/dist/docx/invariants.js +300 -116
- package/dist/docx/newLists.js +12 -3
- package/dist/docx/notes/newNote.d.ts +39 -0
- package/dist/docx/notes/newNote.js +122 -0
- package/dist/docx/notes/numbering.d.ts +27 -0
- package/dist/docx/notes/numbering.js +113 -0
- package/dist/docx/notes/reading.d.ts +58 -0
- package/dist/docx/notes/reading.js +98 -0
- package/dist/docx/notes/references.d.ts +33 -0
- package/dist/docx/notes/references.js +37 -0
- package/dist/docx/notes/writing.d.ts +19 -0
- package/dist/docx/notes/writing.js +95 -0
- package/dist/docx/partPlan.d.ts +3 -0
- package/dist/docx/partPlanners.d.ts +13 -0
- package/dist/docx/partPlanners.js +48 -0
- package/dist/docx/sections.d.ts +5 -0
- package/dist/docx/sections.js +7 -2
- package/dist/docx/serializeParagraph.js +7 -2
- package/dist/docx/serializePreserved.d.ts +5 -1
- package/dist/docx/serializePreserved.js +24 -7
- package/dist/docx/session.d.ts +5 -0
- package/dist/docx/session.js +6 -0
- package/dist/docx/storyParts.d.ts +133 -0
- package/dist/docx/storyParts.js +314 -0
- package/dist/editor/clipboard/htmlReader.d.ts +24 -4
- package/dist/editor/clipboard/htmlReader.js +39 -4
- package/dist/editor/clipboard/internalChannel.d.ts +30 -3
- package/dist/editor/clipboard/internalChannel.js +43 -3
- package/dist/editor/clipboard/normalizers.d.ts +35 -8
- package/dist/editor/clipboard/normalizers.js +60 -11
- package/dist/editor/clipboard/plugin.js +42 -22
- package/dist/editor/commands/exportQueries.d.ts +4 -3
- package/dist/editor/commands/index.d.ts +2 -1
- package/dist/editor/commands/index.js +18 -0
- package/dist/editor/commands/noteCommands.d.ts +47 -0
- package/dist/editor/commands/noteCommands.js +95 -0
- package/dist/editor/commands/noteQueries.d.ts +22 -3
- package/dist/editor/commands/noteQueries.js +21 -13
- package/dist/editor/createEditor.js +21 -3
- package/dist/editor/documentStyles.d.ts +3 -0
- package/dist/editor/documentStyles.js +2 -1
- package/dist/editor/editorDocument.d.ts +24 -0
- package/dist/editor/editorDocument.js +34 -4
- package/dist/editor/notes/noteSurface.d.ts +53 -0
- package/dist/editor/notes/noteSurface.js +246 -0
- package/dist/editor/plugins/compositionSelection.d.ts +20 -0
- package/dist/editor/plugins/compositionSelection.js +19 -0
- package/dist/editor/plugins/keymap.d.ts +14 -0
- package/dist/editor/plugins/keymap.js +13 -1
- package/dist/editor/plugins/noteLifecycle.d.ts +18 -0
- package/dist/editor/plugins/noteLifecycle.js +117 -0
- package/dist/editor/plugins/noteNavigation.d.ts +45 -0
- package/dist/editor/plugins/noteNavigation.js +86 -0
- package/dist/editor/plugins/noteNumbering.d.ts +13 -0
- package/dist/editor/plugins/noteNumbering.js +58 -0
- package/dist/editor/plugins/rowResize.js +2 -7
- package/dist/editor/plugins/tabLayout.js +2 -7
- package/dist/editor/stories/storyMarkup.d.ts +24 -0
- package/dist/editor/stories/storyMarkup.js +35 -0
- package/dist/editor/stories/storyState.d.ts +34 -0
- package/dist/editor/stories/storyState.js +74 -0
- package/dist/editor/stories/storyView.d.ts +115 -0
- package/dist/editor/stories/storyView.js +144 -0
- package/dist/index.d.ts +2 -2
- package/dist/numbering/spellers.d.ts +1 -1
- package/dist/numbering/spellers.js +6 -1
- package/dist/ooxml/errors.d.ts +135 -2
- package/dist/ooxml/errors.js +6 -0
- package/dist/page/blockKinds.d.ts +23 -4
- package/dist/page/demands/footnoteDemands.d.ts +18 -0
- package/dist/page/demands/footnoteDemands.js +51 -0
- package/dist/page/demands/index.d.ts +43 -0
- package/dist/page/demands/index.js +8 -0
- package/dist/page/kinds/paragraphKind.js +7 -1
- package/dist/page/kinds/tableKind.js +9 -1
- package/dist/page/measureBlocks.d.ts +2 -0
- package/dist/page/measureBlocks.js +31 -10
- package/dist/page/pageDecorations.d.ts +9 -2
- package/dist/page/pageDecorations.js +18 -5
- package/dist/page/pageLayout.d.ts +77 -1
- package/dist/page/pageLayout.js +186 -9
- package/dist/page/usePageLayout.d.ts +57 -2
- package/dist/page/usePageLayout.js +50 -5
- package/dist/schema/attrRoles.js +3 -2
- package/dist/schema/docxSchema.js +5 -2
- package/dist/schema/editGuard.d.ts +1 -1
- package/dist/schema/guards.js +1 -2
- package/dist/schema/preservedGuards.d.ts +4 -6
- package/dist/schema/preservedGuards.js +0 -9
- package/dist/schema/stories.d.ts +42 -2
- package/dist/schema/stories.js +28 -5
- package/dist/styles/classNames.d.ts +21 -6
- package/dist/styles/classNames.js +21 -6
- package/dist/styles/inlineStyle.d.ts +7 -0
- package/dist/styles/inlineStyle.js +11 -5
- package/dist/styles/visualScale.d.ts +19 -0
- package/dist/styles/visualScale.js +26 -0
- package/dist/styles.css +89 -32
- package/dist/ui/InsertImageButton.d.ts +3 -1
- package/dist/ui/InsertImageButton.js +3 -2
- package/dist/ui/TableMenu.d.ts +5 -2
- package/dist/ui/TableMenu.js +18 -1
- package/dist/ui/TextMenu.d.ts +5 -2
- package/dist/ui/TextMenu.js +21 -6
- package/dist/ui/Toolbar.d.ts +17 -2
- package/dist/ui/Toolbar.js +23 -10
- package/dist/ui/comments/useCommentRailLayout.js +2 -4
- package/dist/ui/noteItems.d.ts +21 -0
- package/dist/ui/noteItems.js +30 -0
- package/dist/ui/notes/NoteAreas.d.ts +73 -0
- package/dist/ui/notes/NoteAreas.js +131 -0
- package/dist/ui/notes/NoteList.d.ts +25 -0
- package/dist/ui/notes/NoteList.js +58 -0
- package/dist/ui/notes/StoryRow.d.ts +75 -0
- package/dist/ui/notes/StoryRow.js +122 -0
- package/dist/ui/notes/noteBands.d.ts +100 -0
- package/dist/ui/notes/noteBands.js +142 -0
- package/dist/ui/notes/noteHeights.d.ts +10 -0
- package/dist/ui/notes/noteHeights.js +24 -0
- package/dist/ui/notes/noteSeparator.d.ts +12 -0
- package/dist/ui/notes/noteSeparator.js +9 -0
- package/dist/ui/notes/useStorySurface.d.ts +68 -0
- package/dist/ui/notes/useStorySurface.js +95 -0
- package/dist/ui/runCommand.d.ts +8 -1
- package/dist/ui/runCommand.js +2 -2
- package/dist/ui/shortcutLabels.d.ts +16 -0
- package/dist/ui/shortcutLabels.js +9 -0
- package/dist/ui/usePageRoom.d.ts +13 -0
- package/dist/ui/usePageRoom.js +31 -0
- package/package.json +1 -1
- package/dist/docx/notes.d.ts +0 -27
- package/dist/docx/notes.js +0 -55
- package/dist/ui/NotesPanel.d.ts +0 -6
- 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
package/dist/docx/notes.d.ts
DELETED
|
@@ -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;
|
package/dist/docx/notes.js
DELETED
|
@@ -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
|
-
};
|
package/dist/ui/NotesPanel.d.ts
DELETED
package/dist/ui/NotesPanel.js
DELETED
|
@@ -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
|
-
};
|