@portone/docx-editor 0.2.0 → 0.3.0

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 (256) hide show
  1. package/CHANGELOG.md +174 -0
  2. package/CONTRIBUTING.md +9 -1
  3. package/dist/DocxEditor.d.ts +6 -0
  4. package/dist/DocxEditor.js +12 -29
  5. package/dist/core.d.ts +23 -8
  6. package/dist/core.js +9 -4
  7. package/dist/docx/cloning.d.ts +38 -0
  8. package/dist/docx/cloning.js +74 -0
  9. package/dist/docx/commentOnlyChange.d.ts +14 -7
  10. package/dist/docx/commentOnlyChange.js +9 -139
  11. package/dist/docx/comments/constants.d.ts +3 -4
  12. package/dist/docx/comments/constants.js +4 -5
  13. package/dist/docx/comments/grammar.d.ts +86 -0
  14. package/dist/docx/comments/grammar.js +223 -0
  15. package/dist/docx/comments/parts.d.ts +52 -0
  16. package/dist/docx/comments/parts.js +279 -0
  17. package/dist/docx/comments/people.d.ts +11 -2
  18. package/dist/docx/comments/people.js +28 -106
  19. package/dist/docx/comments/policy.d.ts +7 -0
  20. package/dist/docx/comments/policy.js +43 -0
  21. package/dist/docx/comments/reading.d.ts +5 -3
  22. package/dist/docx/comments/reading.js +30 -29
  23. package/dist/docx/comments/writing.d.ts +19 -7
  24. package/dist/docx/comments/writing.js +105 -137
  25. package/dist/docx/documentSettings.d.ts +7 -0
  26. package/dist/docx/documentSettings.js +10 -2
  27. package/dist/docx/exportDocx.d.ts +40 -5
  28. package/dist/docx/exportDocx.js +71 -72
  29. package/dist/docx/exportRefs.d.ts +5 -2
  30. package/dist/docx/exportRefs.js +3 -1
  31. package/dist/docx/fidelity.d.ts +43 -0
  32. package/dist/docx/fidelity.js +64 -0
  33. package/dist/docx/formatting/attrs.d.ts +27 -0
  34. package/dist/docx/formatting/attrs.js +31 -0
  35. package/dist/docx/formatting/context.d.ts +31 -0
  36. package/dist/docx/formatting/context.js +42 -0
  37. package/dist/docx/formatting/direct.d.ts +6 -5
  38. package/dist/docx/formatting/direct.js +52 -81
  39. package/dist/docx/formatting/resolve.d.ts +45 -0
  40. package/dist/docx/formatting/resolve.js +140 -0
  41. package/dist/docx/formatting/runProperties.d.ts +93 -0
  42. package/dist/docx/formatting/runProperties.js +316 -0
  43. package/dist/docx/formatting/styles.js +3 -3
  44. package/dist/docx/formatting/tabStops.js +7 -22
  45. package/dist/docx/formatting.d.ts +4 -1
  46. package/dist/docx/formatting.js +4 -1
  47. package/dist/docx/headersFooters.js +13 -22
  48. package/dist/docx/identities.d.ts +67 -0
  49. package/dist/docx/identities.js +174 -0
  50. package/dist/docx/importDocx.d.ts +12 -1
  51. package/dist/docx/importDocx.js +72 -79
  52. package/dist/docx/importParagraph.d.ts +1 -1
  53. package/dist/docx/importParagraph.js +4 -3
  54. package/dist/docx/importTable.d.ts +1 -1
  55. package/dist/docx/importTable.js +17 -1
  56. package/dist/docx/invariants.d.ts +33 -0
  57. package/dist/docx/invariants.js +256 -0
  58. package/dist/docx/media.d.ts +6 -4
  59. package/dist/docx/media.js +6 -37
  60. package/dist/docx/newLists.d.ts +20 -0
  61. package/dist/docx/newLists.js +36 -0
  62. package/dist/docx/notes.js +6 -12
  63. package/dist/docx/numberingPlanner.d.ts +8 -0
  64. package/dist/docx/numberingPlanner.js +19 -0
  65. package/dist/docx/packageParts.d.ts +42 -0
  66. package/dist/docx/packageParts.js +135 -0
  67. package/dist/docx/pageGeometry.d.ts +2 -0
  68. package/dist/docx/pageGeometry.js +18 -9
  69. package/dist/docx/paraProps.d.ts +10 -22
  70. package/dist/docx/paraProps.js +75 -99
  71. package/dist/docx/partPlan.d.ts +36 -0
  72. package/dist/docx/partPlan.js +59 -0
  73. package/dist/docx/protectionPolicy.d.ts +127 -0
  74. package/dist/docx/protectionPolicy.js +169 -0
  75. package/dist/docx/relationships.d.ts +1 -1
  76. package/dist/docx/relationships.js +15 -15
  77. package/dist/docx/runProps.d.ts +9 -22
  78. package/dist/docx/runProps.js +15 -168
  79. package/dist/docx/scan.js +20 -52
  80. package/dist/docx/sdt.js +14 -37
  81. package/dist/docx/sdtProps.d.ts +8 -1
  82. package/dist/docx/sdtProps.js +10 -0
  83. package/dist/docx/serializeBlock.d.ts +2 -0
  84. package/dist/docx/serializeBlock.js +9 -7
  85. package/dist/docx/serializeParagraph.d.ts +2 -1
  86. package/dist/docx/serializeParagraph.js +25 -14
  87. package/dist/docx/serializeTable.js +63 -32
  88. package/dist/docx/session.d.ts +42 -14
  89. package/dist/docx/session.js +43 -17
  90. package/dist/docx/storyProjection.d.ts +36 -0
  91. package/dist/docx/storyProjection.js +23 -0
  92. package/dist/docx/tableFormatting/editing.js +130 -185
  93. package/dist/docx/tableFormatting/reading.d.ts +16 -6
  94. package/dist/docx/tableFormatting/reading.js +40 -20
  95. package/dist/docx/tableTemplate.js +37 -5
  96. package/dist/docx/theme.d.ts +0 -6
  97. package/dist/docx/theme.js +0 -8
  98. package/dist/download.d.ts +8 -5
  99. package/dist/download.js +2 -0
  100. package/dist/editor/clipboard/images.js +17 -3
  101. package/dist/editor/clipboard/inlineFormatting.d.ts +7 -0
  102. package/dist/editor/clipboard/inlineFormatting.js +20 -30
  103. package/dist/editor/commands/breakCommands.js +4 -3
  104. package/dist/editor/commands/canRunCommand.d.ts +2 -2
  105. package/dist/editor/commands/canRunCommand.js +1 -1
  106. package/dist/editor/commands/comments/editing.d.ts +6 -2
  107. package/dist/editor/commands/comments/editing.js +21 -36
  108. package/dist/editor/commands/exportQueries.d.ts +15 -0
  109. package/dist/editor/commands/exportQueries.js +14 -0
  110. package/dist/editor/commands/fidelityQueries.d.ts +12 -0
  111. package/dist/editor/commands/fidelityQueries.js +8 -0
  112. package/dist/editor/commands/formatting/editing.d.ts +2 -2
  113. package/dist/editor/commands/formatting/editing.js +26 -108
  114. package/dist/editor/commands/formatting/propertyCommands.d.ts +21 -0
  115. package/dist/editor/commands/formatting/propertyCommands.js +103 -0
  116. package/dist/editor/commands/formatting/shared.d.ts +3 -3
  117. package/dist/editor/commands/formatting/shared.js +5 -2
  118. package/dist/editor/commands/historyCommands.js +2 -1
  119. package/dist/editor/commands/indentCommands.js +5 -4
  120. package/dist/editor/commands/index.d.ts +11 -0
  121. package/dist/editor/commands/index.js +5 -0
  122. package/dist/editor/commands/linkCommands.js +5 -6
  123. package/dist/editor/commands/listCommands.js +8 -10
  124. package/dist/editor/commands/lockCommands.d.ts +7 -1
  125. package/dist/editor/commands/lockCommands.js +35 -37
  126. package/dist/editor/commands/paragraphCommands.js +28 -31
  127. package/dist/editor/commands/spacingCommands.js +1 -1
  128. package/dist/editor/commands/tabCommands.js +4 -3
  129. package/dist/editor/createEditor.d.ts +17 -29
  130. package/dist/editor/createEditor.js +61 -67
  131. package/dist/editor/documentStyles.d.ts +11 -35
  132. package/dist/editor/documentStyles.js +9 -52
  133. package/dist/editor/editorDocument.d.ts +56 -0
  134. package/dist/editor/editorDocument.js +74 -0
  135. package/dist/editor/externalClipboard.js +166 -33
  136. package/dist/editor/insertImage.js +4 -3
  137. package/dist/editor/insertTable.js +4 -3
  138. package/dist/editor/paragraphEdits.d.ts +11 -18
  139. package/dist/editor/paragraphEdits.js +7 -16
  140. package/dist/editor/plugins/displayDerivation.d.ts +47 -0
  141. package/dist/editor/plugins/displayDerivation.js +78 -0
  142. package/dist/editor/plugins/documentProtection.d.ts +3 -3
  143. package/dist/editor/plugins/imagePaste.js +4 -3
  144. package/dist/editor/plugins/keymap.js +18 -3
  145. package/dist/editor/plugins/lockedContent.d.ts +4 -4
  146. package/dist/editor/plugins/lockedContent.js +1 -1
  147. package/dist/editor/plugins/numberingDecorations.d.ts +5 -11
  148. package/dist/editor/plugins/numberingDecorations.js +7 -17
  149. package/dist/editor/plugins/paragraphDisplay.d.ts +7 -0
  150. package/dist/editor/plugins/paragraphDisplay.js +51 -0
  151. package/dist/editor/plugins/tabLayout.js +1 -1
  152. package/dist/editor/plugins/tableDisplay.d.ts +6 -0
  153. package/dist/editor/plugins/tableDisplay.js +16 -0
  154. package/dist/index.d.ts +2 -0
  155. package/dist/model/format.d.ts +30 -8
  156. package/dist/model/format.js +35 -22
  157. package/dist/model/tabStops.d.ts +9 -0
  158. package/dist/model/tabStops.js +18 -0
  159. package/dist/numbering/listTemplate.js +49 -10
  160. package/dist/numbering/parseNumbering.d.ts +14 -1
  161. package/dist/numbering/parseNumbering.js +35 -22
  162. package/dist/numbering/writeNumbering.d.ts +3 -4
  163. package/dist/numbering/writeNumbering.js +14 -25
  164. package/dist/ooxml/childOrder.d.ts +34 -0
  165. package/dist/ooxml/childOrder.js +496 -0
  166. package/dist/ooxml/element.d.ts +65 -0
  167. package/dist/ooxml/element.js +68 -0
  168. package/dist/ooxml/errors.d.ts +3 -2
  169. package/dist/ooxml/fragment.d.ts +53 -0
  170. package/dist/ooxml/fragment.js +76 -0
  171. package/dist/ooxml/image.d.ts +4 -0
  172. package/dist/ooxml/image.js +3 -5
  173. package/dist/ooxml/names.d.ts +27 -0
  174. package/dist/ooxml/names.js +29 -0
  175. package/dist/ooxml/partSplice.d.ts +67 -0
  176. package/dist/ooxml/partSplice.js +169 -0
  177. package/dist/ooxml/precedence.d.ts +31 -0
  178. package/dist/ooxml/precedence.js +51 -0
  179. package/dist/ooxml/props.d.ts +112 -0
  180. package/dist/ooxml/props.js +214 -0
  181. package/dist/ooxml/simpleTypes.d.ts +103 -0
  182. package/dist/ooxml/simpleTypes.js +182 -0
  183. package/dist/ooxml/tabStops.js +8 -27
  184. package/dist/ooxml/tagScan.d.ts +34 -0
  185. package/dist/ooxml/tagScan.js +108 -0
  186. package/dist/ooxml/units.d.ts +25 -13
  187. package/dist/ooxml/units.js +65 -31
  188. package/dist/ooxml/xml.d.ts +52 -0
  189. package/dist/ooxml/xml.js +64 -5
  190. package/dist/page/blockKinds.d.ts +103 -0
  191. package/dist/page/blockKinds.js +11 -0
  192. package/dist/page/kinds/index.d.ts +6 -0
  193. package/dist/page/kinds/index.js +10 -0
  194. package/dist/page/kinds/paragraphKind.d.ts +10 -0
  195. package/dist/page/kinds/paragraphKind.js +71 -0
  196. package/dist/page/kinds/tableKind.d.ts +10 -0
  197. package/dist/page/kinds/tableKind.js +178 -0
  198. package/dist/page/measureBlocks.d.ts +3 -1
  199. package/dist/page/measureBlocks.js +24 -25
  200. package/dist/page/pageDecorations.d.ts +27 -28
  201. package/dist/page/pageDecorations.js +70 -151
  202. package/dist/page/pageLayout.d.ts +10 -62
  203. package/dist/page/pageLayout.js +60 -53
  204. package/dist/page/usePageLayout.d.ts +2 -2
  205. package/dist/page/usePageLayout.js +3 -11
  206. package/dist/schema/attrRoles.d.ts +42 -0
  207. package/dist/schema/attrRoles.js +141 -0
  208. package/dist/schema/displayDerivation.d.ts +82 -0
  209. package/dist/schema/displayDerivation.js +130 -0
  210. package/dist/schema/docxSchema.d.ts +9 -0
  211. package/dist/schema/docxSchema.js +237 -114
  212. package/dist/schema/editGuard.d.ts +99 -0
  213. package/dist/schema/editGuard.js +43 -0
  214. package/dist/schema/guards.d.ts +91 -0
  215. package/dist/schema/guards.js +108 -0
  216. package/dist/schema/index.d.ts +2 -0
  217. package/dist/schema/index.js +2 -0
  218. package/dist/schema/locks.d.ts +17 -77
  219. package/dist/schema/locks.js +26 -70
  220. package/dist/schema/preservedGuards.d.ts +50 -0
  221. package/dist/schema/preservedGuards.js +80 -0
  222. package/dist/schema/protection.d.ts +17 -4
  223. package/dist/schema/protection.js +4 -2
  224. package/dist/schema/sourceEquality.d.ts +19 -0
  225. package/dist/schema/sourceEquality.js +39 -0
  226. package/dist/styles/inlineStyle.js +15 -6
  227. package/dist/table/cellFormatting.d.ts +8 -1
  228. package/dist/table/cellFormatting.js +10 -17
  229. package/dist/table/commands.d.ts +2 -2
  230. package/dist/table/commands.js +20 -18
  231. package/dist/table/format.d.ts +3 -0
  232. package/dist/table/format.js +3 -9
  233. package/dist/table/gridBorders.d.ts +14 -16
  234. package/dist/table/gridBorders.js +3 -41
  235. package/dist/table/index.d.ts +2 -2
  236. package/dist/table/merge.d.ts +4 -8
  237. package/dist/table/merge.js +5 -5
  238. package/package.json +10 -3
  239. package/dist/docx/comments/contentTypes.d.ts +0 -7
  240. package/dist/docx/comments/contentTypes.js +0 -38
  241. package/dist/docx/formatting/effectiveParagraph.d.ts +0 -15
  242. package/dist/docx/formatting/effectiveParagraph.js +0 -81
  243. package/dist/docx/propsXml.d.ts +0 -49
  244. package/dist/docx/propsXml.js +0 -302
  245. package/dist/docx/uniqueControls.d.ts +0 -14
  246. package/dist/docx/uniqueControls.js +0 -62
  247. package/dist/editor/plugins/bookmarkProtection.d.ts +0 -3
  248. package/dist/editor/plugins/bookmarkProtection.js +0 -28
  249. package/dist/editor/plugins/commentReservations.d.ts +0 -5
  250. package/dist/editor/plugins/commentReservations.js +0 -26
  251. package/dist/editor/plugins/noteProtection.d.ts +0 -3
  252. package/dist/editor/plugins/noteProtection.js +0 -25
  253. package/dist/editor/plugins/styledParagraphs.d.ts +0 -15
  254. package/dist/editor/plugins/styledParagraphs.js +0 -65
  255. package/dist/page/tableMeasurements.d.ts +0 -10
  256. package/dist/page/tableMeasurements.js +0 -115
@@ -1,81 +0,0 @@
1
- // src/docx/formatting/effectiveParagraph.ts
2
- import { toParagraphFormat } from "../../model/format.js";
3
- import { mergeTabStops } from "../../model/tabStops.js";
4
- import {
5
- EMPTY_NUMBERING,
6
- levelIndentPt
7
- } from "../../numbering/parseNumbering.js";
8
- import { parsePropsXml } from "../propsXml.js";
9
- import { readParagraphFormat } from "./direct.js";
10
- import {
11
- paragraphStyleFormat
12
- } from "./styles.js";
13
- import { layerParagraphValues } from "./tabStops.js";
14
- var NO_PARAGRAPH_FORMATTING = {
15
- styles: /* @__PURE__ */ new Map(),
16
- defaultStyleId: null,
17
- defaults: {},
18
- numbering: EMPTY_NUMBERING
19
- };
20
- function numberingRef(defaults, style, direct) {
21
- let value = defaults.numbering;
22
- if (style.numbering !== void 0) value = style.numbering;
23
- if (direct.numbering !== void 0) value = direct.numbering;
24
- return value;
25
- }
26
- function numberingLayer(ref, numbering) {
27
- if (!ref) return {};
28
- const level = numbering.lists.get(ref.numId)?.levels.get(ref.ilvl);
29
- if (!level) return {};
30
- const indent = levelIndentPt(level.indent);
31
- const leadingIndentPt = indent.startPt;
32
- const implicitHangingStop = leadingIndentPt !== null && indent.textIndentPt !== null && indent.textIndentPt < 0 ? [{ positionPt: leadingIndentPt, align: "start" }] : [];
33
- return {
34
- tabStops: [...implicitHangingStop, ...level.tabStops ?? []]
35
- };
36
- }
37
- function withImplicitHangingStop(format) {
38
- const leadingIndentPt = format?.indentStartPt ?? format?.indentLeftPt;
39
- if (format?.textIndentPt === void 0 || format.textIndentPt >= 0 || leadingIndentPt === void 0) {
40
- return format;
41
- }
42
- const implicit = {
43
- positionPt: leadingIndentPt,
44
- align: "start"
45
- };
46
- return {
47
- ...format,
48
- tabStops: mergeTabStops([implicit], format.tabStops ?? [])
49
- };
50
- }
51
- function directLayer(pPr) {
52
- if (typeof pPr !== "string") return {};
53
- return readParagraphFormat(parsePropsXml(pPr)) ?? {};
54
- }
55
- function styleFor(pPr, context) {
56
- return paragraphStyleFormat(pPr, context.styles, context.defaultStyleId);
57
- }
58
- function effectiveParagraphFormat(pPr, context) {
59
- const direct = directLayer(pPr);
60
- const style = styleFor(pPr, context)?.paragraph ?? {};
61
- const level = numberingLayer(
62
- numberingRef(context.defaults, style, direct),
63
- context.numbering
64
- );
65
- const layered = [level, style, direct].reduce(
66
- layerParagraphValues,
67
- context.defaults
68
- );
69
- const format = toParagraphFormat(layered);
70
- return withImplicitHangingStop(
71
- format !== null && Object.keys(format).length === 0 ? null : format
72
- );
73
- }
74
- function effectiveParagraphStyle(pPr, context) {
75
- return styleFor(pPr, context);
76
- }
77
- export {
78
- NO_PARAGRAPH_FORMATTING,
79
- effectiveParagraphFormat,
80
- effectiveParagraphStyle
81
- };
@@ -1,49 +0,0 @@
1
- /**
2
- * Handles the XML fragments that carry formatting, such as `<w:rPr>`, `<w:pPr>`, and `<w:tcPr>`.
3
- *
4
- * A fragment is never rebuilt: only the one child a job names is sliced out and swapped, so the
5
- * rest (borders, shading, margins) stays as the original text wrote it. OOXML lays down the order
6
- * of the children, so the spot to insert a child that was not there is found by that same order.
7
- */
8
- export interface PropsChild {
9
- /** The name with its namespace prefix stripped off (e.g. `gridSpan`) */
10
- name: string;
11
- /** This child's original XML fragment exactly as it was */
12
- xml: string;
13
- }
14
- export interface Props {
15
- /** The opening tag name exactly as written (e.g. `w:tcPr`) */
16
- tag: string;
17
- attrs: string | null;
18
- children: PropsChild[];
19
- }
20
- /** The order the children are laid out in under `w:rPr` (CT_RPr) */
21
- export declare const RUN_PR_ORDER: readonly string[];
22
- /** The order the children are laid out in under `w:pPr` (CT_PPr) */
23
- export declare const P_PR_ORDER: readonly string[];
24
- /** The order the children are laid out in under `w:tcPr` (CT_TcPr) */
25
- export declare const TC_PR_ORDER: readonly string[];
26
- /** The conventional order of children under `w:trPr` (CT_TrPr). */
27
- export declare const TR_PR_ORDER: readonly string[];
28
- /** The order the children are laid out in under `w:tblPr` (CT_TblPr) */
29
- export declare const TBL_PR_ORDER: readonly string[];
30
- /**
31
- * Splits a formatting fragment into its opening tag and its list of children.
32
- * null if its shape cannot be made out (in which case leaving the original untouched is the safe move).
33
- */
34
- export declare function parseProps(xml: string): Props | null;
35
- /** With no children at all, the formatting fragment itself is not written */
36
- export declare function renderProps(props: Props): string;
37
- /**
38
- * Replaces a single child with new XML.
39
- * A null `xml` removes that child. A child that was not there goes into the spot the order calls for.
40
- */
41
- export declare function setPropsChild(children: PropsChild[], name: string, xml: string | null, order: readonly string[]): PropsChild[];
42
- export declare function propsChild(children: PropsChild[], name: string): PropsChild | undefined;
43
- /**
44
- * Reads a single formatting fragment into an element.
45
- *
46
- * A fragment carries no namespace declarations, so they are put back on as it is wrapped.
47
- * null if its shape cannot be made out, in which case the caller leaves the display values alone.
48
- */
49
- export declare function parsePropsXml(xml: string): Element | null;
@@ -1,302 +0,0 @@
1
- // src/docx/propsXml.ts
2
- import { elementChildren, localPart, parseXml, W_NS } from "../ooxml/xml.js";
3
- var RUN_PR_ORDER = [
4
- "rStyle",
5
- "rFonts",
6
- "b",
7
- "bCs",
8
- "i",
9
- "iCs",
10
- "caps",
11
- "smallCaps",
12
- "strike",
13
- "dstrike",
14
- "outline",
15
- "shadow",
16
- "emboss",
17
- "imprint",
18
- "noProof",
19
- "snapToGrid",
20
- "vanish",
21
- "webHidden",
22
- "color",
23
- "spacing",
24
- "w",
25
- "kern",
26
- "position",
27
- "sz",
28
- "szCs",
29
- "highlight",
30
- "u",
31
- "effect",
32
- "bdr",
33
- "shd",
34
- "fitText",
35
- "vertAlign",
36
- "rtl",
37
- "cs",
38
- "em",
39
- "lang",
40
- "eastAsianLayout",
41
- "specVanish",
42
- "oMath",
43
- "rPrChange"
44
- ];
45
- var P_PR_ORDER = [
46
- "pStyle",
47
- "keepNext",
48
- "keepLines",
49
- "pageBreakBefore",
50
- "framePr",
51
- "widowControl",
52
- "numPr",
53
- "suppressLineNumbers",
54
- "pBdr",
55
- "shd",
56
- "tabs",
57
- "suppressAutoHyphens",
58
- "kinsoku",
59
- "wordWrap",
60
- "overflowPunct",
61
- "topLinePunct",
62
- "autoSpaceDE",
63
- "autoSpaceDN",
64
- "bidi",
65
- "adjustRightInd",
66
- "snapToGrid",
67
- "spacing",
68
- "ind",
69
- "contextualSpacing",
70
- "mirrorIndents",
71
- "suppressOverlap",
72
- "jc",
73
- "textDirection",
74
- "textAlignment",
75
- "textboxTightWrap",
76
- "outlineLvl",
77
- "divId",
78
- "cnfStyle",
79
- "rPr",
80
- "sectPr",
81
- "pPrChange"
82
- ];
83
- var TC_PR_ORDER = [
84
- "cnfStyle",
85
- "tcW",
86
- "gridSpan",
87
- "hMerge",
88
- "vMerge",
89
- "tcBorders",
90
- "shd",
91
- "noWrap",
92
- "tcMar",
93
- "textDirection",
94
- "tcFitText",
95
- "vAlign",
96
- "hideMark",
97
- "headers",
98
- "cellIns",
99
- "cellDel",
100
- "cellMerge",
101
- "tcPrChange"
102
- ];
103
- var TR_PR_ORDER = [
104
- "cnfStyle",
105
- "divId",
106
- "gridBefore",
107
- "gridAfter",
108
- "wBefore",
109
- "wAfter",
110
- "cantSplit",
111
- "trHeight",
112
- "tblHeader",
113
- "tblCellSpacing",
114
- "jc",
115
- "hidden",
116
- "ins",
117
- "del",
118
- "trPrChange"
119
- ];
120
- var TBL_PR_ORDER = [
121
- "tblStyle",
122
- "tblpPr",
123
- "tblOverlap",
124
- "bidiVisual",
125
- "tblStyleRowBandSize",
126
- "tblStyleColBandSize",
127
- "tblW",
128
- "jc",
129
- "tblCellSpacing",
130
- "tblInd",
131
- "tblBorders",
132
- "shd",
133
- "tblLayout",
134
- "tblCellMar",
135
- "tblLook",
136
- "tblCaption",
137
- "tblDescription",
138
- "tblPrChange"
139
- ];
140
- function skipPast(source, from, marker) {
141
- const at = source.indexOf(marker, from);
142
- return at === -1 ? -1 : at + marker.length;
143
- }
144
- function otherTag(end) {
145
- return end === -1 ? null : { kind: "other", name: "", nameEnd: end, end };
146
- }
147
- function readTag(source, lt) {
148
- if (source.startsWith("<?", lt)) return otherTag(skipPast(source, lt, "?>"));
149
- if (source.startsWith("<!--", lt))
150
- return otherTag(skipPast(source, lt, "-->"));
151
- if (source.startsWith("<![CDATA[", lt))
152
- return otherTag(skipPast(source, lt, "]]>"));
153
- if (source.startsWith("<!", lt)) return otherTag(skipPast(source, lt, ">"));
154
- const closing = source.startsWith("</", lt);
155
- let i = lt + (closing ? 2 : 1);
156
- const nameStart = i;
157
- while (i < source.length && !" \r\n/>".includes(source[i])) i += 1;
158
- const name = source.slice(nameStart, i);
159
- if (!name) return null;
160
- const nameEnd = i;
161
- let quote = null;
162
- while (i < source.length) {
163
- const ch = source[i];
164
- if (quote !== null) {
165
- if (ch === quote) quote = null;
166
- } else if (ch === '"' || ch === "'") {
167
- quote = ch;
168
- } else if (ch === ">") {
169
- const selfClosing = source[i - 1] === "/";
170
- const kind = closing ? "close" : selfClosing ? "empty" : "open";
171
- return { kind, name, nameEnd, end: i + 1 };
172
- }
173
- i += 1;
174
- }
175
- return null;
176
- }
177
- function attrsOf(source, tag) {
178
- const closeLength = tag.kind === "empty" ? 2 : 1;
179
- const attrs = source.slice(tag.nameEnd, tag.end - closeLength).trim();
180
- return attrs.length > 0 ? attrs : null;
181
- }
182
- function parseProps(xml) {
183
- const open = readTag(xml, 0);
184
- if (!open || xml[0] !== "<") return null;
185
- const attrs = attrsOf(xml, open);
186
- if (open.kind === "empty") {
187
- return open.end === xml.length ? { tag: open.name, attrs, children: [] } : null;
188
- }
189
- if (open.kind !== "open") return null;
190
- const children = [];
191
- let depth = 0;
192
- let childStart = -1;
193
- let childName = "";
194
- let i = open.end;
195
- while (i < xml.length) {
196
- const lt = xml.indexOf("<", i);
197
- if (lt === -1) return null;
198
- const tag = readTag(xml, lt);
199
- if (!tag) return null;
200
- if (tag.kind === "other") {
201
- i = tag.end;
202
- continue;
203
- }
204
- if (depth === 0) {
205
- if (tag.kind === "close") {
206
- if (tag.name !== open.name || tag.end !== xml.length) return null;
207
- return { tag: open.name, attrs, children };
208
- }
209
- childStart = lt;
210
- childName = tag.name;
211
- if (tag.kind === "empty") {
212
- children.push({
213
- name: localPart(childName),
214
- xml: xml.slice(childStart, tag.end)
215
- });
216
- } else {
217
- depth = 1;
218
- }
219
- } else if (tag.kind === "open") {
220
- depth += 1;
221
- } else if (tag.kind === "close") {
222
- depth -= 1;
223
- if (depth === 0) {
224
- children.push({
225
- name: localPart(childName),
226
- xml: xml.slice(childStart, tag.end)
227
- });
228
- }
229
- }
230
- i = tag.end;
231
- }
232
- return null;
233
- }
234
- function renderProps(props) {
235
- if (props.children.length === 0) return "";
236
- const open = props.attrs ? `<${props.tag} ${props.attrs}>` : `<${props.tag}>`;
237
- return open + props.children.map((child) => child.xml).join("") + `</${props.tag}>`;
238
- }
239
- function insertIndex(children, name, order) {
240
- const target = order.indexOf(name);
241
- if (target === -1) return children.length;
242
- let previous = -1;
243
- for (const [index, child] of children.entries()) {
244
- const known = order.indexOf(child.name);
245
- const effective = known === -1 ? previous : known;
246
- if (effective > target) return index;
247
- previous = effective;
248
- }
249
- return children.length;
250
- }
251
- function setPropsChild(children, name, xml, order) {
252
- const without = children.filter((child2) => child2.name !== name);
253
- if (xml === null) return without;
254
- const child = { name, xml };
255
- const at = children.findIndex((entry) => entry.name === name);
256
- if (at === -1) {
257
- const index = insertIndex(without, name, order);
258
- return [...without.slice(0, index), child, ...without.slice(index)];
259
- }
260
- return [
261
- ...children.slice(0, at),
262
- child,
263
- ...children.slice(at + 1).filter((entry) => entry.name !== name)
264
- ];
265
- }
266
- function propsChild(children, name) {
267
- return children.find((child) => child.name === name);
268
- }
269
- function namespaceDecls(xml) {
270
- const prefixes = /* @__PURE__ */ new Set(["w"]);
271
- for (const [, prefix] of xml.matchAll(/<\/?([A-Za-z_][\w.-]*):/g)) {
272
- prefixes.add(prefix);
273
- }
274
- for (const [, prefix] of xml.matchAll(/[\s"']([A-Za-z_][\w.-]*):[\w.-]+=/g)) {
275
- prefixes.add(prefix);
276
- }
277
- prefixes.delete("xml");
278
- prefixes.delete("xmlns");
279
- return Array.from(prefixes).map(
280
- (prefix) => `xmlns:${prefix}="${prefix === "w" ? W_NS : `urn:docx-editor:${prefix}`}"`
281
- ).join(" ");
282
- }
283
- function parsePropsXml(xml) {
284
- try {
285
- const wrapped = `<props ${namespaceDecls(xml)}>${xml}</props>`;
286
- return elementChildren(parseXml(wrapped).documentElement)[0] ?? null;
287
- } catch {
288
- return null;
289
- }
290
- }
291
- export {
292
- P_PR_ORDER,
293
- RUN_PR_ORDER,
294
- TBL_PR_ORDER,
295
- TC_PR_ORDER,
296
- TR_PR_ORDER,
297
- parseProps,
298
- parsePropsXml,
299
- propsChild,
300
- renderProps,
301
- setPropsChild
302
- };
@@ -1,14 +0,0 @@
1
- /**
2
- * Keeping one content control from going out twice under the same name.
3
- *
4
- * A control cannot cross a paragraph, so splitting a paragraph in the middle of one leaves that
5
- * same control standing in two, and dropping unmarked text into the middle of one breaks it in
6
- * two within the paragraph. Each piece then writes a `w:sdt` of its own (see `docx/sdt` for what
7
- * a copy must not carry along).
8
- *
9
- * A document nobody broke apart comes back node for node as it was, which is what keeps an
10
- * unedited block going out as its original XML.
11
- */
12
- import { type Node as PMNode } from "prosemirror-model";
13
- /** The document with every copy of a control opening under a name of its own */
14
- export declare function withUniqueControls(doc: PMNode): PMNode;
@@ -1,62 +0,0 @@
1
- // src/docx/uniqueControls.ts
2
- import { Fragment } from "prosemirror-model";
3
- import { docxSchema } from "../schema/index.js";
4
- import { copiedControlPrefix, newControlId } from "./sdt.js";
5
- function sdtMarkOf(node) {
6
- return node.marks.find((mark) => mark.type === docxSchema.marks.sdt) ?? null;
7
- }
8
- function controlName(mark) {
9
- const key = mark.attrs.sdtKey;
10
- const prefix = mark.attrs.sdtPrefix;
11
- return `${typeof key === "number" ? key : 0} ${typeof prefix === "string" ? prefix : ""}`;
12
- }
13
- function copiedMark(mark) {
14
- const prefix = mark.attrs.sdtPrefix;
15
- if (typeof prefix !== "string") return mark;
16
- return mark.type.create({
17
- ...mark.attrs,
18
- sdtPrefix: copiedControlPrefix(prefix, newControlId())
19
- });
20
- }
21
- function claim(mark, written) {
22
- const name = controlName(mark);
23
- const copy = written.has(name) ? copiedMark(mark) : null;
24
- written.add(name);
25
- return { mark, copy };
26
- }
27
- function rewriteParagraph(paragraph, written) {
28
- const inline = [];
29
- let running = null;
30
- let renamed = false;
31
- paragraph.forEach((child) => {
32
- const mark = sdtMarkOf(child);
33
- if (!mark) {
34
- running = null;
35
- inline.push(child);
36
- return;
37
- }
38
- const control = running?.mark.eq(mark) ? running : claim(mark, written);
39
- running = control;
40
- if (!control.copy) {
41
- inline.push(child);
42
- return;
43
- }
44
- renamed = true;
45
- inline.push(
46
- child.mark(control.copy.addToSet(mark.removeFromSet(child.marks)))
47
- );
48
- });
49
- return renamed ? paragraph.copy(Fragment.fromArray(inline)) : paragraph;
50
- }
51
- function rewriteBlock(node, written) {
52
- if (node.type.name === "paragraph") return rewriteParagraph(node, written);
53
- if (node.childCount === 0) return node;
54
- const children = node.children.map((child) => rewriteBlock(child, written));
55
- return children.every((child, index) => child === node.child(index)) ? node : node.copy(Fragment.fromArray(children));
56
- }
57
- function withUniqueControls(doc) {
58
- return rewriteBlock(doc, /* @__PURE__ */ new Set());
59
- }
60
- export {
61
- withUniqueControls
62
- };
@@ -1,3 +0,0 @@
1
- /** Prevents ordinary editor transactions from dropping imported bookmark range markers. */
2
- import { Plugin } from "prosemirror-state";
3
- export declare function bookmarkProtection(): Plugin;
@@ -1,28 +0,0 @@
1
- // src/editor/plugins/bookmarkProtection.ts
2
- import { Plugin } from "prosemirror-state";
3
- var BOOKMARK_XML = /<(?:[\w.-]+:)?bookmark(?:Start|End)\b/;
4
- function signatures(doc) {
5
- const found = [];
6
- doc.descendants((node) => {
7
- if (node.type.name === "bookmarkBlock") {
8
- found.push(`block:${node.attrs.srcId}:${node.attrs.name}`);
9
- } else if (node.type.name === "rawInline" && typeof node.attrs.xml === "string" && BOOKMARK_XML.test(node.attrs.xml)) {
10
- found.push(`inline:${node.attrs.xml}`);
11
- }
12
- return true;
13
- });
14
- return found;
15
- }
16
- function same(a, b) {
17
- return a.length === b.length && a.every((value, index) => value === b[index]);
18
- }
19
- function bookmarkProtection() {
20
- return new Plugin({
21
- filterTransaction(transaction, state) {
22
- return !transaction.docChanged || same(signatures(state.doc), signatures(transaction.doc));
23
- }
24
- });
25
- }
26
- export {
27
- bookmarkProtection
28
- };
@@ -1,5 +0,0 @@
1
- /** Keeps identifiers from the opened Comments parts reserved for the lifetime of the editor state. */
2
- import { type EditorState, Plugin } from "prosemirror-state";
3
- export declare function commentReservations(ids: Iterable<string>, paraIds: Iterable<string>): Plugin;
4
- export declare function reservedCommentIds(state: EditorState): ReadonlySet<string>;
5
- export declare function reservedCommentParaIds(state: EditorState): ReadonlySet<string>;
@@ -1,26 +0,0 @@
1
- // src/editor/plugins/commentReservations.ts
2
- import { Plugin, PluginKey } from "prosemirror-state";
3
- var commentReservationsKey = new PluginKey(
4
- "docxCommentReservations"
5
- );
6
- function commentReservations(ids, paraIds) {
7
- const reserved = { ids: new Set(ids), paraIds: new Set(paraIds) };
8
- return new Plugin({
9
- key: commentReservationsKey,
10
- state: {
11
- init: () => reserved,
12
- apply: (_transaction, value) => value
13
- }
14
- });
15
- }
16
- function reservedCommentIds(state) {
17
- return commentReservationsKey.getState(state)?.ids ?? /* @__PURE__ */ new Set();
18
- }
19
- function reservedCommentParaIds(state) {
20
- return commentReservationsKey.getState(state)?.paraIds ?? /* @__PURE__ */ new Set();
21
- }
22
- export {
23
- commentReservations,
24
- reservedCommentIds,
25
- reservedCommentParaIds
26
- };
@@ -1,3 +0,0 @@
1
- /** Keeps imported footnote and endnote references intact while their bodies are display-only. */
2
- import { Plugin } from "prosemirror-state";
3
- export declare function noteProtection(): Plugin;
@@ -1,25 +0,0 @@
1
- // src/editor/plugins/noteProtection.ts
2
- import { Plugin } from "prosemirror-state";
3
- function signatures(doc) {
4
- const found = [];
5
- doc.descendants((node) => {
6
- if (node.type.name === "noteReference") {
7
- found.push(JSON.stringify(node.attrs));
8
- }
9
- return true;
10
- });
11
- return found;
12
- }
13
- function same(a, b) {
14
- return a.length === b.length && a.every((value, index) => value === b[index]);
15
- }
16
- function noteProtection() {
17
- return new Plugin({
18
- filterTransaction(transaction, state) {
19
- return !transaction.docChanged || same(signatures(state.doc), signatures(transaction.doc));
20
- }
21
- });
22
- }
23
- export {
24
- noteProtection
25
- };
@@ -1,15 +0,0 @@
1
- /**
2
- * Applies inherited style display values to paragraphs created in the editor. The paragraph under
3
- * active IME composition is deferred to avoid redrawing and canceling the composition.
4
- */
5
- import { Plugin } from "prosemirror-state";
6
- /**
7
- * Reads the document's styles into the paragraphs an edit built.
8
- *
9
- * No transaction of its own goes to the history: ProseMirror hands an appended transaction to the
10
- * history as part of the same event, so a single undo takes the edit and these values back together.
11
- *
12
- * An appended transaction is handed nothing but states, so the view an open composition is read
13
- * from is the one the plugin is given when it mounts.
14
- */
15
- export declare function styledParagraphs(): Plugin;
@@ -1,65 +0,0 @@
1
- // src/editor/plugins/styledParagraphs.ts
2
- import { Plugin } from "prosemirror-state";
3
- import {
4
- effectiveParagraphFormat,
5
- effectiveParagraphStyle,
6
- layerRunFormat
7
- } from "../../docx/formatting.js";
8
- import { docxSchema } from "../../schema/index.js";
9
- import { documentParagraphFormatting } from "../documentStyles.js";
10
- function needsFormatting(node) {
11
- return node.attrs.format === null && node.attrs.styleRun === null;
12
- }
13
- function paragraphSpots(doc) {
14
- const found = [];
15
- doc.descendants((node, pos) => {
16
- if (node.type !== docxSchema.nodes.paragraph) return true;
17
- if (needsFormatting(node)) found.push({ pos, node });
18
- return false;
19
- });
20
- return found;
21
- }
22
- function styledAttrs(node, state) {
23
- const context = documentParagraphFormatting(state);
24
- const style = effectiveParagraphStyle(node.attrs.pPr, context);
25
- const format = effectiveParagraphFormat(node.attrs.pPr, context);
26
- const styleRun = style ? layerRunFormat(style.run, null) : null;
27
- return { ...node.attrs, format, styleRun };
28
- }
29
- function composingAt(view, state) {
30
- return view?.composing === true ? state.selection.from : null;
31
- }
32
- function holdsComposition(paragraph, composing) {
33
- return composing !== null && composing >= paragraph.pos && composing <= paragraph.pos + paragraph.node.nodeSize;
34
- }
35
- function styledParagraphs() {
36
- let live = null;
37
- return new Plugin({
38
- view(view) {
39
- live = view;
40
- return {
41
- destroy() {
42
- live = null;
43
- }
44
- };
45
- },
46
- appendTransaction(transactions, _oldState, newState) {
47
- if (!transactions.some((transaction) => transaction.docChanged)) {
48
- return null;
49
- }
50
- const composing = composingAt(live, newState);
51
- const tr = newState.tr;
52
- for (const paragraph of paragraphSpots(newState.doc)) {
53
- if (holdsComposition(paragraph, composing)) continue;
54
- const attrs = styledAttrs(paragraph.node, newState);
55
- if (!paragraph.node.hasMarkup(paragraph.node.type, attrs)) {
56
- tr.setNodeMarkup(paragraph.pos, null, attrs);
57
- }
58
- }
59
- return tr.docChanged ? tr : null;
60
- }
61
- });
62
- }
63
- export {
64
- styledParagraphs
65
- };