@portone/docx-editor 0.1.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 (347) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/CONTRIBUTING.md +63 -0
  3. package/LICENSE +203 -0
  4. package/README.md +48 -0
  5. package/assets/editor.png +0 -0
  6. package/dist/DocxEditor.d.ts +123 -0
  7. package/dist/DocxEditor.js +348 -0
  8. package/dist/core.d.ts +36 -0
  9. package/dist/core.js +38 -0
  10. package/dist/docx/comments/constants.d.ts +8 -0
  11. package/dist/docx/comments/constants.js +20 -0
  12. package/dist/docx/comments/model.d.ts +37 -0
  13. package/dist/docx/comments/model.js +104 -0
  14. package/dist/docx/comments/reading.d.ts +36 -0
  15. package/dist/docx/comments/reading.js +149 -0
  16. package/dist/docx/comments/writing.d.ts +11 -0
  17. package/dist/docx/comments/writing.js +327 -0
  18. package/dist/docx/comments.d.ts +3 -0
  19. package/dist/docx/comments.js +4 -0
  20. package/dist/docx/container.d.ts +12 -0
  21. package/dist/docx/container.js +130 -0
  22. package/dist/docx/documentSettings.d.ts +4 -0
  23. package/dist/docx/documentSettings.js +14 -0
  24. package/dist/docx/exportDocx.d.ts +15 -0
  25. package/dist/docx/exportDocx.js +163 -0
  26. package/dist/docx/exportRefs.d.ts +16 -0
  27. package/dist/docx/exportRefs.js +10 -0
  28. package/dist/docx/formatting/direct.d.ts +30 -0
  29. package/dist/docx/formatting/direct.js +201 -0
  30. package/dist/docx/formatting/effectiveParagraph.d.ts +15 -0
  31. package/dist/docx/formatting/effectiveParagraph.js +81 -0
  32. package/dist/docx/formatting/styles.d.ts +67 -0
  33. package/dist/docx/formatting/styles.js +165 -0
  34. package/dist/docx/formatting/tabStops.d.ts +8 -0
  35. package/dist/docx/formatting/tabStops.js +65 -0
  36. package/dist/docx/formatting.d.ts +4 -0
  37. package/dist/docx/formatting.js +4 -0
  38. package/dist/docx/headersFooters.d.ts +36 -0
  39. package/dist/docx/headersFooters.js +218 -0
  40. package/dist/docx/hyperlink.d.ts +75 -0
  41. package/dist/docx/hyperlink.js +71 -0
  42. package/dist/docx/importDocx.d.ts +21 -0
  43. package/dist/docx/importDocx.js +263 -0
  44. package/dist/docx/importParagraph.d.ts +32 -0
  45. package/dist/docx/importParagraph.js +308 -0
  46. package/dist/docx/importTable.d.ts +9 -0
  47. package/dist/docx/importTable.js +275 -0
  48. package/dist/docx/media.d.ts +60 -0
  49. package/dist/docx/media.js +213 -0
  50. package/dist/docx/notes.d.ts +22 -0
  51. package/dist/docx/notes.js +71 -0
  52. package/dist/docx/pageGeometry.d.ts +75 -0
  53. package/dist/docx/pageGeometry.js +88 -0
  54. package/dist/docx/paraProps.d.ts +74 -0
  55. package/dist/docx/paraProps.js +167 -0
  56. package/dist/docx/propsXml.d.ts +49 -0
  57. package/dist/docx/propsXml.js +302 -0
  58. package/dist/docx/relationships.d.ts +42 -0
  59. package/dist/docx/relationships.js +94 -0
  60. package/dist/docx/runProps.d.ts +51 -0
  61. package/dist/docx/runProps.js +207 -0
  62. package/dist/docx/scan.d.ts +20 -0
  63. package/dist/docx/scan.js +110 -0
  64. package/dist/docx/sdt.d.ts +56 -0
  65. package/dist/docx/sdt.js +104 -0
  66. package/dist/docx/sdtProps.d.ts +18 -0
  67. package/dist/docx/sdtProps.js +11 -0
  68. package/dist/docx/serializeBlock.d.ts +4 -0
  69. package/dist/docx/serializeBlock.js +30 -0
  70. package/dist/docx/serializeParagraph.d.ts +15 -0
  71. package/dist/docx/serializeParagraph.js +208 -0
  72. package/dist/docx/serializeTable.d.ts +12 -0
  73. package/dist/docx/serializeTable.js +134 -0
  74. package/dist/docx/session.d.ts +81 -0
  75. package/dist/docx/session.js +79 -0
  76. package/dist/docx/tableFormatting/editing.d.ts +64 -0
  77. package/dist/docx/tableFormatting/editing.js +318 -0
  78. package/dist/docx/tableFormatting/reading.d.ts +96 -0
  79. package/dist/docx/tableFormatting/reading.js +221 -0
  80. package/dist/docx/tableFormatting.d.ts +2 -0
  81. package/dist/docx/tableFormatting.js +3 -0
  82. package/dist/docx/tableTemplate.d.ts +22 -0
  83. package/dist/docx/tableTemplate.js +111 -0
  84. package/dist/docx/theme.d.ts +40 -0
  85. package/dist/docx/theme.js +61 -0
  86. package/dist/docx/uniqueControls.d.ts +14 -0
  87. package/dist/docx/uniqueControls.js +62 -0
  88. package/dist/download.d.ts +57 -0
  89. package/dist/download.js +44 -0
  90. package/dist/editor/clipboard/images.d.ts +14 -0
  91. package/dist/editor/clipboard/images.js +158 -0
  92. package/dist/editor/clipboard/inlineFormatting.d.ts +21 -0
  93. package/dist/editor/clipboard/inlineFormatting.js +232 -0
  94. package/dist/editor/commands/breakCommands.d.ts +8 -0
  95. package/dist/editor/commands/breakCommands.js +19 -0
  96. package/dist/editor/commands/canRunCommand.d.ts +6 -0
  97. package/dist/editor/commands/canRunCommand.js +10 -0
  98. package/dist/editor/commands/commentCommands.d.ts +3 -0
  99. package/dist/editor/commands/commentCommands.js +4 -0
  100. package/dist/editor/commands/comments/editing.d.ts +21 -0
  101. package/dist/editor/commands/comments/editing.js +305 -0
  102. package/dist/editor/commands/comments/model.d.ts +31 -0
  103. package/dist/editor/commands/comments/model.js +0 -0
  104. package/dist/editor/commands/comments/reading.d.ts +8 -0
  105. package/dist/editor/commands/comments/reading.js +58 -0
  106. package/dist/editor/commands/formatting/editing.d.ts +32 -0
  107. package/dist/editor/commands/formatting/editing.js +138 -0
  108. package/dist/editor/commands/formatting/reading.d.ts +57 -0
  109. package/dist/editor/commands/formatting/reading.js +82 -0
  110. package/dist/editor/commands/formatting/shared.d.ts +32 -0
  111. package/dist/editor/commands/formatting/shared.js +53 -0
  112. package/dist/editor/commands/formattingCommands.d.ts +2 -0
  113. package/dist/editor/commands/formattingCommands.js +3 -0
  114. package/dist/editor/commands/historyCommands.d.ts +11 -0
  115. package/dist/editor/commands/historyCommands.js +16 -0
  116. package/dist/editor/commands/indentCommands.d.ts +15 -0
  117. package/dist/editor/commands/indentCommands.js +44 -0
  118. package/dist/editor/commands/index.d.ts +82 -0
  119. package/dist/editor/commands/index.js +171 -0
  120. package/dist/editor/commands/linkCommands.d.ts +56 -0
  121. package/dist/editor/commands/linkCommands.js +146 -0
  122. package/dist/editor/commands/listCommands.d.ts +58 -0
  123. package/dist/editor/commands/listCommands.js +140 -0
  124. package/dist/editor/commands/lockCommands.d.ts +47 -0
  125. package/dist/editor/commands/lockCommands.js +198 -0
  126. package/dist/editor/commands/noteQueries.d.ts +12 -0
  127. package/dist/editor/commands/noteQueries.js +29 -0
  128. package/dist/editor/commands/paragraphCommands.d.ts +59 -0
  129. package/dist/editor/commands/paragraphCommands.js +113 -0
  130. package/dist/editor/commands/spacingCommands.d.ts +23 -0
  131. package/dist/editor/commands/spacingCommands.js +48 -0
  132. package/dist/editor/commands/tabCommands.d.ts +5 -0
  133. package/dist/editor/commands/tabCommands.js +65 -0
  134. package/dist/editor/createEditor.d.ts +59 -0
  135. package/dist/editor/createEditor.js +160 -0
  136. package/dist/editor/documentStyles.d.ts +60 -0
  137. package/dist/editor/documentStyles.js +80 -0
  138. package/dist/editor/externalClipboard.d.ts +11 -0
  139. package/dist/editor/externalClipboard.js +323 -0
  140. package/dist/editor/imageFiles.d.ts +74 -0
  141. package/dist/editor/imageFiles.js +173 -0
  142. package/dist/editor/insertImage.d.ts +31 -0
  143. package/dist/editor/insertImage.js +35 -0
  144. package/dist/editor/insertTable.d.ts +18 -0
  145. package/dist/editor/insertTable.js +44 -0
  146. package/dist/editor/paragraphEdits.d.ts +42 -0
  147. package/dist/editor/paragraphEdits.js +59 -0
  148. package/dist/editor/plainText.d.ts +3 -0
  149. package/dist/editor/plainText.js +50 -0
  150. package/dist/editor/plugins/bookmarkProtection.d.ts +3 -0
  151. package/dist/editor/plugins/bookmarkProtection.js +28 -0
  152. package/dist/editor/plugins/columnResize.d.ts +27 -0
  153. package/dist/editor/plugins/columnResize.js +192 -0
  154. package/dist/editor/plugins/commentDecorations.d.ts +3 -0
  155. package/dist/editor/plugins/commentDecorations.js +23 -0
  156. package/dist/editor/plugins/commentReservations.d.ts +5 -0
  157. package/dist/editor/plugins/commentReservations.js +26 -0
  158. package/dist/editor/plugins/dropCaret.d.ts +10 -0
  159. package/dist/editor/plugins/dropCaret.js +11 -0
  160. package/dist/editor/plugins/imagePaste.d.ts +8 -0
  161. package/dist/editor/plugins/imagePaste.js +265 -0
  162. package/dist/editor/plugins/keymap.d.ts +5 -0
  163. package/dist/editor/plugins/keymap.js +94 -0
  164. package/dist/editor/plugins/linkPanel.d.ts +23 -0
  165. package/dist/editor/plugins/linkPanel.js +39 -0
  166. package/dist/editor/plugins/listInputRules.d.ts +14 -0
  167. package/dist/editor/plugins/listInputRules.js +36 -0
  168. package/dist/editor/plugins/lockedContent.d.ts +6 -0
  169. package/dist/editor/plugins/lockedContent.js +41 -0
  170. package/dist/editor/plugins/noteProtection.d.ts +3 -0
  171. package/dist/editor/plugins/noteProtection.js +25 -0
  172. package/dist/editor/plugins/numberingDecorations.d.ts +42 -0
  173. package/dist/editor/plugins/numberingDecorations.js +110 -0
  174. package/dist/editor/plugins/rowResize.d.ts +15 -0
  175. package/dist/editor/plugins/rowResize.js +196 -0
  176. package/dist/editor/plugins/styledParagraphs.d.ts +15 -0
  177. package/dist/editor/plugins/styledParagraphs.js +65 -0
  178. package/dist/editor/plugins/tabCaret.d.ts +3 -0
  179. package/dist/editor/plugins/tabCaret.js +126 -0
  180. package/dist/editor/plugins/tabDecorations.d.ts +11 -0
  181. package/dist/editor/plugins/tabDecorations.js +87 -0
  182. package/dist/editor/plugins/tabLayout.d.ts +16 -0
  183. package/dist/editor/plugins/tabLayout.js +328 -0
  184. package/dist/editor/plugins/tabPointer.d.ts +7 -0
  185. package/dist/editor/plugins/tabPointer.js +95 -0
  186. package/dist/editor/plugins/tableContextMenu.d.ts +21 -0
  187. package/dist/editor/plugins/tableContextMenu.js +88 -0
  188. package/dist/editor/plugins/textContextMenu.d.ts +15 -0
  189. package/dist/editor/plugins/textContextMenu.js +90 -0
  190. package/dist/editor/views/imageResize.d.ts +53 -0
  191. package/dist/editor/views/imageResize.js +167 -0
  192. package/dist/editor/views/runMarkView.d.ts +15 -0
  193. package/dist/editor/views/runMarkView.js +9 -0
  194. package/dist/editor/views/tableView.d.ts +24 -0
  195. package/dist/editor/views/tableView.js +32 -0
  196. package/dist/index.d.ts +44 -0
  197. package/dist/index.js +38 -0
  198. package/dist/model/format.d.ts +240 -0
  199. package/dist/model/format.js +305 -0
  200. package/dist/model/tabStops.d.ts +17 -0
  201. package/dist/model/tabStops.js +22 -0
  202. package/dist/numbering/listTemplate.d.ts +29 -0
  203. package/dist/numbering/listTemplate.js +83 -0
  204. package/dist/numbering/markers.d.ts +24 -0
  205. package/dist/numbering/markers.js +93 -0
  206. package/dist/numbering/parseNumbering.d.ts +65 -0
  207. package/dist/numbering/parseNumbering.js +116 -0
  208. package/dist/numbering/writeNumbering.d.ts +13 -0
  209. package/dist/numbering/writeNumbering.js +49 -0
  210. package/dist/ooxml/errors.d.ts +39 -0
  211. package/dist/ooxml/errors.js +21 -0
  212. package/dist/ooxml/image.d.ts +88 -0
  213. package/dist/ooxml/image.js +106 -0
  214. package/dist/ooxml/tabStops.d.ts +3 -0
  215. package/dist/ooxml/tabStops.js +51 -0
  216. package/dist/ooxml/units.d.ts +37 -0
  217. package/dist/ooxml/units.js +116 -0
  218. package/dist/ooxml/xml.d.ts +36 -0
  219. package/dist/ooxml/xml.js +89 -0
  220. package/dist/page/PageGuides.d.ts +16 -0
  221. package/dist/page/PageGuides.js +114 -0
  222. package/dist/page/measureBlocks.d.ts +25 -0
  223. package/dist/page/measureBlocks.js +80 -0
  224. package/dist/page/pageDecorations.d.ts +36 -0
  225. package/dist/page/pageDecorations.js +211 -0
  226. package/dist/page/pageLayout.d.ts +176 -0
  227. package/dist/page/pageLayout.js +157 -0
  228. package/dist/page/tableMeasurements.d.ts +10 -0
  229. package/dist/page/tableMeasurements.js +115 -0
  230. package/dist/page/usePageLayout.d.ts +57 -0
  231. package/dist/page/usePageLayout.js +141 -0
  232. package/dist/schema/docxSchema.d.ts +9 -0
  233. package/dist/schema/docxSchema.js +863 -0
  234. package/dist/schema/index.d.ts +2 -0
  235. package/dist/schema/index.js +9 -0
  236. package/dist/schema/locks.d.ts +112 -0
  237. package/dist/schema/locks.js +211 -0
  238. package/dist/schema/rendering.d.ts +6 -0
  239. package/dist/schema/rendering.js +46 -0
  240. package/dist/styles/classNames.d.ts +214 -0
  241. package/dist/styles/classNames.js +208 -0
  242. package/dist/styles/colors.d.ts +11 -0
  243. package/dist/styles/colors.js +14 -0
  244. package/dist/styles/fontSizes.d.ts +6 -0
  245. package/dist/styles/fontSizes.js +20 -0
  246. package/dist/styles/fontStack.d.ts +55 -0
  247. package/dist/styles/fontStack.js +262 -0
  248. package/dist/styles/fonts.d.ts +6 -0
  249. package/dist/styles/fonts.js +11 -0
  250. package/dist/styles/inlineStyle.d.ts +67 -0
  251. package/dist/styles/inlineStyle.js +212 -0
  252. package/dist/styles/lineSpacings.d.ts +11 -0
  253. package/dist/styles/lineSpacings.js +10 -0
  254. package/dist/styles.css +1650 -0
  255. package/dist/table/cellBorders.d.ts +12 -0
  256. package/dist/table/cellBorders.js +9 -0
  257. package/dist/table/cellFormatting.d.ts +57 -0
  258. package/dist/table/cellFormatting.js +173 -0
  259. package/dist/table/columns.d.ts +25 -0
  260. package/dist/table/columns.js +155 -0
  261. package/dist/table/commands.d.ts +19 -0
  262. package/dist/table/commands.js +63 -0
  263. package/dist/table/format.d.ts +35 -0
  264. package/dist/table/format.js +26 -0
  265. package/dist/table/gridBorders.d.ts +42 -0
  266. package/dist/table/gridBorders.js +192 -0
  267. package/dist/table/index.d.ts +16 -0
  268. package/dist/table/index.js +52 -0
  269. package/dist/table/merge.d.ts +36 -0
  270. package/dist/table/merge.js +125 -0
  271. package/dist/table/resize.d.ts +55 -0
  272. package/dist/table/resize.js +66 -0
  273. package/dist/table/rowResize.d.ts +14 -0
  274. package/dist/table/rowResize.js +44 -0
  275. package/dist/table/rows.d.ts +32 -0
  276. package/dist/table/rows.js +89 -0
  277. package/dist/table/widths.d.ts +69 -0
  278. package/dist/table/widths.js +97 -0
  279. package/dist/ui/AlignMenu.d.ts +15 -0
  280. package/dist/ui/AlignMenu.js +64 -0
  281. package/dist/ui/CellStyleGroup.d.ts +15 -0
  282. package/dist/ui/CellStyleGroup.js +232 -0
  283. package/dist/ui/ColorPicker.d.ts +13 -0
  284. package/dist/ui/ColorPicker.js +165 -0
  285. package/dist/ui/CommentsPanel.d.ts +15 -0
  286. package/dist/ui/CommentsPanel.js +348 -0
  287. package/dist/ui/FontFamilySelect.d.ts +14 -0
  288. package/dist/ui/FontFamilySelect.js +59 -0
  289. package/dist/ui/FontSizeSelect.d.ts +11 -0
  290. package/dist/ui/FontSizeSelect.js +49 -0
  291. package/dist/ui/InsertImageButton.d.ts +9 -0
  292. package/dist/ui/InsertImageButton.js +47 -0
  293. package/dist/ui/LinkCard.d.ts +12 -0
  294. package/dist/ui/LinkCard.js +127 -0
  295. package/dist/ui/LinkPanel.d.ts +9 -0
  296. package/dist/ui/LinkPanel.js +121 -0
  297. package/dist/ui/MenuChoice.d.ts +11 -0
  298. package/dist/ui/MenuChoice.js +32 -0
  299. package/dist/ui/NotesPanel.d.ts +6 -0
  300. package/dist/ui/NotesPanel.js +33 -0
  301. package/dist/ui/ParagraphStyleSelect.d.ts +11 -0
  302. package/dist/ui/ParagraphStyleSelect.js +62 -0
  303. package/dist/ui/Popover.d.ts +22 -0
  304. package/dist/ui/Popover.js +74 -0
  305. package/dist/ui/SpacingMenu.d.ts +12 -0
  306. package/dist/ui/SpacingMenu.js +54 -0
  307. package/dist/ui/TableMenu.d.ts +12 -0
  308. package/dist/ui/TableMenu.js +112 -0
  309. package/dist/ui/TableSizePicker.d.ts +9 -0
  310. package/dist/ui/TableSizePicker.js +53 -0
  311. package/dist/ui/TextMenu.d.ts +15 -0
  312. package/dist/ui/TextMenu.js +194 -0
  313. package/dist/ui/Toolbar.d.ts +19 -0
  314. package/dist/ui/Toolbar.js +448 -0
  315. package/dist/ui/ToolbarButton.d.ts +23 -0
  316. package/dist/ui/ToolbarButton.js +56 -0
  317. package/dist/ui/Tooltip.d.ts +19 -0
  318. package/dist/ui/Tooltip.js +47 -0
  319. package/dist/ui/ZoomSelect.d.ts +7 -0
  320. package/dist/ui/ZoomSelect.js +44 -0
  321. package/dist/ui/comments/CommentComposer.d.ts +17 -0
  322. package/dist/ui/comments/CommentComposer.js +59 -0
  323. package/dist/ui/comments/useCommentRailLayout.d.ts +18 -0
  324. package/dist/ui/comments/useCommentRailLayout.js +183 -0
  325. package/dist/ui/keyboardWalk.d.ts +22 -0
  326. package/dist/ui/keyboardWalk.js +70 -0
  327. package/dist/ui/openAddress.d.ts +11 -0
  328. package/dist/ui/openAddress.js +16 -0
  329. package/dist/ui/panelPlacement.d.ts +51 -0
  330. package/dist/ui/panelPlacement.js +71 -0
  331. package/dist/ui/presets.d.ts +11 -0
  332. package/dist/ui/presets.js +0 -0
  333. package/dist/ui/rovingFocus.d.ts +20 -0
  334. package/dist/ui/rovingFocus.js +61 -0
  335. package/dist/ui/runCommand.d.ts +5 -0
  336. package/dist/ui/runCommand.js +13 -0
  337. package/dist/ui/useDismiss.d.ts +6 -0
  338. package/dist/ui/useDismiss.js +31 -0
  339. package/dist/ui/useFitWidthZoom.d.ts +2 -0
  340. package/dist/ui/useFitWidthZoom.js +26 -0
  341. package/dist/ui/useGridKeyboard.d.ts +12 -0
  342. package/dist/ui/useGridKeyboard.js +90 -0
  343. package/dist/ui/useMenuKeyboard.d.ts +12 -0
  344. package/dist/ui/useMenuKeyboard.js +56 -0
  345. package/dist/ui/zoom.d.ts +4 -0
  346. package/dist/ui/zoom.js +21 -0
  347. package/package.json +120 -0
@@ -0,0 +1,146 @@
1
+ // src/editor/commands/linkCommands.ts
2
+ import { docxSchema } from "../../schema/index.js";
3
+ import { rangeTouchesLocked } from "../../schema/locks.js";
4
+ var linkType = docxSchema.marks.link;
5
+ function text(value) {
6
+ return typeof value === "string" ? value : null;
7
+ }
8
+ var NAMES_SCHEME = /^[a-z][a-z0-9+.-]*:/i;
9
+ var MEANS_A_PLACE = /^[./#]/;
10
+ function settled(address) {
11
+ const typed = address.trim();
12
+ if (NAMES_SCHEME.test(typed) || MEANS_A_PLACE.test(typed)) return typed;
13
+ const host = typed.split(/[/?#]/, 1)[0];
14
+ return host.includes(".") ? `http://${typed}` : typed;
15
+ }
16
+ function linkMarkOf(marks) {
17
+ return marks.find((mark) => mark.type === linkType) ?? null;
18
+ }
19
+ function linkable(node, parent) {
20
+ if (parent === null || !parent.type.allowsMarkType(linkType)) return false;
21
+ return node.isText || node.type.allowsMarkType(linkType);
22
+ }
23
+ function piecesIn(doc, from, to) {
24
+ const pieces = [];
25
+ doc.nodesBetween(from, to, (node, pos, parent) => {
26
+ if (!node.isInline) return true;
27
+ if (!linkable(node, parent)) return false;
28
+ const start = Math.max(pos, from);
29
+ const end = Math.min(pos + node.nodeSize, to);
30
+ if (start < end) {
31
+ pieces.push({ from: start, to: end, link: linkMarkOf(node.marks) });
32
+ }
33
+ return false;
34
+ });
35
+ return pieces;
36
+ }
37
+ function linkSpans(parent, start) {
38
+ const spans = [];
39
+ parent.forEach((child, offset) => {
40
+ const link = linkMarkOf(child.marks);
41
+ if (!link) return;
42
+ const from = start + offset;
43
+ const to = from + child.nodeSize;
44
+ const last = spans.at(-1);
45
+ if (last && last.to === from && last.link.eq(link)) last.to = to;
46
+ else spans.push({ from, to, link });
47
+ });
48
+ return spans;
49
+ }
50
+ function caretSpan(state) {
51
+ const $from = state.selection.$from;
52
+ const link = linkMarkOf($from.marks());
53
+ if (!link) return null;
54
+ return linkSpans($from.parent, $from.start()).find(
55
+ (span) => span.link.eq(link) && span.from <= $from.pos && $from.pos <= span.to
56
+ ) ?? null;
57
+ }
58
+ function selectionSpan(state) {
59
+ const { $from, $to } = state.selection;
60
+ if (!$from.parent.isTextblock || $from.parent !== $to.parent) return null;
61
+ return linkSpans($from.parent, $from.start()).find(
62
+ (span) => span.from <= $from.pos && $to.pos <= span.to
63
+ ) ?? null;
64
+ }
65
+ function linkSpansTouching(doc, from, to) {
66
+ const spans = [];
67
+ doc.nodesBetween(from, to, (node, pos) => {
68
+ if (!node.isTextblock) return true;
69
+ for (const span of linkSpans(node, pos + 1)) {
70
+ if (span.from < to && from < span.to) spans.push(span);
71
+ }
72
+ return false;
73
+ });
74
+ return spans;
75
+ }
76
+ function openPieces(state) {
77
+ const found = state.selection.empty ? caretPieces(state) : selectionPieces(state);
78
+ return found.filter(
79
+ (piece) => !rangeTouchesLocked(state.doc, piece.from, piece.to)
80
+ );
81
+ }
82
+ function caretPieces(state) {
83
+ const span = caretSpan(state);
84
+ return span === null ? [] : [span];
85
+ }
86
+ function selectionPieces(state) {
87
+ return state.selection.ranges.flatMap((range) => [
88
+ ...linkSpansTouching(state.doc, range.$from.pos, range.$to.pos),
89
+ ...piecesIn(state.doc, range.$from.pos, range.$to.pos).filter(
90
+ (piece) => piece.link === null
91
+ )
92
+ ]);
93
+ }
94
+ function linkMarkFor(piece, href) {
95
+ return linkType.create({ ...piece.link?.attrs, href });
96
+ }
97
+ function setLink(url) {
98
+ return (state, dispatch) => {
99
+ const href = settled(url);
100
+ if (href === "") return false;
101
+ const pieces = openPieces(state).filter(
102
+ (piece) => text(piece.link?.attrs.href) !== href
103
+ );
104
+ if (pieces.length === 0) return false;
105
+ if (dispatch) {
106
+ const tr = state.tr;
107
+ for (const piece of pieces) {
108
+ tr.addMark(piece.from, piece.to, linkMarkFor(piece, href));
109
+ }
110
+ dispatch(tr);
111
+ }
112
+ return true;
113
+ };
114
+ }
115
+ var removeLink = (state, dispatch) => {
116
+ const pieces = openPieces(state).filter((piece) => piece.link !== null);
117
+ if (pieces.length === 0) return false;
118
+ if (dispatch) {
119
+ const tr = state.tr;
120
+ for (const piece of pieces) {
121
+ tr.removeMark(piece.from, piece.to, linkType);
122
+ }
123
+ dispatch(tr);
124
+ }
125
+ return true;
126
+ };
127
+ function canSetLink(state) {
128
+ return openPieces(state).length > 0;
129
+ }
130
+ function activeLink(state) {
131
+ const pieces = openPieces(state);
132
+ const first = text(pieces[0]?.link?.attrs.href);
133
+ return pieces.every((piece) => text(piece.link?.attrs.href) === first) ? first : null;
134
+ }
135
+ function activeLinkSpan(state) {
136
+ const span = state.selection.empty ? caretSpan(state) : selectionSpan(state);
137
+ if (!span) return null;
138
+ return { from: span.from, to: span.to, href: text(span.link.attrs.href) };
139
+ }
140
+ export {
141
+ activeLink,
142
+ activeLinkSpan,
143
+ canSetLink,
144
+ removeLink,
145
+ setLink
146
+ };
@@ -0,0 +1,58 @@
1
+ /**
2
+ * List editing commands.
3
+ *
4
+ * All they do is change a paragraph's place in a list (its numbering id and level).
5
+ * Editing the formatting fragments belongs to `docx/paraProps`, and the list's appearance
6
+ * belongs to `numbering/`.
7
+ * The definition of a new list is not put into the document; numbering.xml picks it up on export.
8
+ */
9
+ import type { Node as PMNode } from "prosemirror-model";
10
+ import type { Command, EditorState } from "prosemirror-state";
11
+ import { type ListChange } from "../../docx/paraProps";
12
+ import { type NumberingRef } from "../../model/format";
13
+ import { type ListKind } from "../../numbering/listTemplate";
14
+ import type { Numbering } from "../../numbering/parseNumbering";
15
+ /** This paragraph's place in a list. Null when it is not a list */
16
+ export declare function listRefOf(node: PMNode): NumberingRef | null;
17
+ /**
18
+ * The change that moves a list paragraph `delta` levels.
19
+ * Null when the paragraph is not in a list or already sits at the first or the last level.
20
+ * The indent buttons reuse this, so moving a level is the same edit however it is asked for.
21
+ */
22
+ export declare function listLevelChange(numbering: Numbering, node: PMNode, delta: 1 | -1): ListChange | null;
23
+ /** Moves a list item one level deeper, which is not the paragraph's own indent. What Tab does */
24
+ export declare const increaseListLevel: Command;
25
+ /** Moves a list item one level back up, which is not the paragraph's own indent. What Shift+Tab does */
26
+ export declare const decreaseListLevel: Command;
27
+ /**
28
+ * Takes the selected paragraphs out of the list.
29
+ * Only the hanging indentation the marker sat in goes with it; an indentation the paragraph had
30
+ * of its own stays, putting it back where it was before it joined the list.
31
+ */
32
+ export declare const removeFromList: Command;
33
+ /**
34
+ * The kind of list the selected paragraphs belong to. Null when they are not a list or the kinds
35
+ * are mixed.
36
+ * It reads the paragraphs a lock leaves open, the same ones `editParagraphs` writes to: counting a
37
+ * locked paragraph that stays out of the list would keep the answer mixed, so the button would make
38
+ * a list a second time instead of taking it off.
39
+ */
40
+ export declare function activeListKind(state: EditorState): ListKind | null;
41
+ export declare const toggleNumberedList: Command;
42
+ export declare const toggleBulletList: Command;
43
+ /**
44
+ * Whether the selected paragraphs hold a list item, which is a fact about the document and so is
45
+ * answered whatever the lock says, as `activeListKind` beside it is.
46
+ * What a level shift would actually move is the level-shift command's own answer, the lock already
47
+ * part of it, and that is what a button runs on.
48
+ */
49
+ export declare function isInList(state: EditorState): boolean;
50
+ /**
51
+ * Pressing Enter in an empty list item does not open a new item.
52
+ *
53
+ * A deeper item comes up one level and stays in the list, and only an item already at the first
54
+ * level leaves it, so a nested list is climbed one press at a time (the same as Word).
55
+ * The paragraph itself stays where it is, which leaves the items after it in the list with their
56
+ * numbering slots untouched; they simply stop counting the item that was given up.
57
+ */
58
+ export declare const leaveEmptyListItem: Command;
@@ -0,0 +1,140 @@
1
+ // src/editor/commands/listCommands.ts
2
+ import {
3
+ withLeftIndent,
4
+ withListNumbering
5
+ } from "../../docx/paraProps.js";
6
+ import { toParagraphFormat } from "../../model/format.js";
7
+ import {
8
+ listFor,
9
+ listKindOf,
10
+ MAX_ILVL,
11
+ nextNumId
12
+ } from "../../numbering/listTemplate.js";
13
+ import { docxSchema } from "../../schema/index.js";
14
+ import {
15
+ editableParagraphs,
16
+ editParagraphs,
17
+ paragraphPPr,
18
+ selectedParagraphs
19
+ } from "../paragraphEdits.js";
20
+ import {
21
+ canStartNewList,
22
+ documentNumbering
23
+ } from "../plugins/numberingDecorations.js";
24
+ function listRefOf(node) {
25
+ return toParagraphFormat(node.attrs.format)?.numbering ?? null;
26
+ }
27
+ function changeParagraphs(state, dispatch, plan) {
28
+ return editParagraphs(state, dispatch, (node, styles, defaultStyleId) => {
29
+ const change = plan(node);
30
+ return change && withListNumbering(paragraphPPr(node), change, styles, defaultStyleId);
31
+ });
32
+ }
33
+ function indentForLevel(numbering, node, ref) {
34
+ const format = toParagraphFormat(node.attrs.format);
35
+ if (format?.indentStartPt === void 0 && format?.indentLeftPt === void 0) {
36
+ return { kind: "keep" };
37
+ }
38
+ const indent = listFor(numbering, ref.numId).levels.get(ref.ilvl)?.indent;
39
+ return indent ? { kind: "level", indent } : { kind: "keep" };
40
+ }
41
+ function listLevelChange(numbering, node, delta) {
42
+ const ref = listRefOf(node);
43
+ if (!ref) return null;
44
+ const ilvl = ref.ilvl + delta;
45
+ if (ilvl < 0 || ilvl > MAX_ILVL) return null;
46
+ const next = { numId: ref.numId, ilvl };
47
+ return { numbering: next, indent: indentForLevel(numbering, node, next) };
48
+ }
49
+ function levelShift(delta) {
50
+ return (state, dispatch) => {
51
+ const numbering = documentNumbering(state);
52
+ return changeParagraphs(
53
+ state,
54
+ dispatch,
55
+ (node) => listLevelChange(numbering, node, delta)
56
+ );
57
+ };
58
+ }
59
+ var increaseListLevel = levelShift(1);
60
+ var decreaseListLevel = levelShift(-1);
61
+ function usedNumIds(state, numbering) {
62
+ const used = new Set(numbering.lists.keys());
63
+ state.doc.descendants((node) => {
64
+ if (node.type !== docxSchema.nodes.paragraph) return true;
65
+ const ref = listRefOf(node);
66
+ if (ref) used.add(ref.numId);
67
+ return false;
68
+ });
69
+ return used;
70
+ }
71
+ function startList(kind) {
72
+ return (state, dispatch) => {
73
+ if (!canStartNewList(state)) return false;
74
+ const numId = nextNumId(usedNumIds(state, documentNumbering(state)), kind);
75
+ return changeParagraphs(state, dispatch, (node) => ({
76
+ numbering: { numId, ilvl: listRefOf(node)?.ilvl ?? 0 },
77
+ indent: { kind: "keep" }
78
+ }));
79
+ };
80
+ }
81
+ var removeFromList = (state, dispatch) => changeParagraphs(
82
+ state,
83
+ dispatch,
84
+ (node) => listRefOf(node) ? { numbering: null, indent: { kind: "clearHanging" } } : null
85
+ );
86
+ function kindOf(numbering, ref) {
87
+ const level = listFor(numbering, ref.numId).levels.get(ref.ilvl);
88
+ if (!level) return listKindOf(ref.numId);
89
+ return level.format === "bullet" ? "bullet" : "numbered";
90
+ }
91
+ function activeListKind(state) {
92
+ const numbering = documentNumbering(state);
93
+ const kinds = editableParagraphs(state).map(({ node }) => {
94
+ const ref = listRefOf(node);
95
+ return ref === null ? null : kindOf(numbering, ref);
96
+ });
97
+ const first = kinds[0] ?? null;
98
+ return kinds.every((kind) => kind === first) ? first : null;
99
+ }
100
+ function toggleList(kind) {
101
+ return (state, dispatch) => activeListKind(state) === kind ? removeFromList(state, dispatch) : startList(kind)(state, dispatch);
102
+ }
103
+ var toggleNumberedList = toggleList("numbered");
104
+ var toggleBulletList = toggleList("bullet");
105
+ function isInList(state) {
106
+ return selectedParagraphs(state).some(
107
+ (spot) => listRefOf(spot.node) !== null
108
+ );
109
+ }
110
+ var leaveListAtLineStart = (state, dispatch) => editParagraphs(state, dispatch, (node, styles, defaultStyleId) => {
111
+ if (!listRefOf(node)) return null;
112
+ const unlisted = withListNumbering(
113
+ paragraphPPr(node),
114
+ { numbering: null, indent: { kind: "clearHanging" } },
115
+ styles,
116
+ defaultStyleId
117
+ );
118
+ return unlisted && withLeftIndent(unlisted.pPr, 0, styles, defaultStyleId);
119
+ });
120
+ var leaveEmptyListItem = (state, dispatch) => {
121
+ const { empty, $from } = state.selection;
122
+ const paragraph = $from.parent;
123
+ if (!empty || paragraph.type !== docxSchema.nodes.paragraph) return false;
124
+ if (paragraph.content.size > 0) return false;
125
+ const ref = listRefOf(paragraph);
126
+ if (!ref) return false;
127
+ return ref.ilvl > 0 ? decreaseListLevel(state, dispatch) : leaveListAtLineStart(state, dispatch);
128
+ };
129
+ export {
130
+ activeListKind,
131
+ decreaseListLevel,
132
+ increaseListLevel,
133
+ isInList,
134
+ leaveEmptyListItem,
135
+ listLevelChange,
136
+ listRefOf,
137
+ removeFromList,
138
+ toggleBulletList,
139
+ toggleNumberedList
140
+ };
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Adds or removes OOXML content locks. Multi-paragraph selections become separate controls, and
3
+ * unlocking preserves the control metadata while removing only its lock.
4
+ */
5
+ import type { Node as PMNode } from "prosemirror-model";
6
+ import { type Command, type EditorState } from "prosemirror-state";
7
+ /**
8
+ * The lock state of the selection, which is the one answer the lock commands and the menus are
9
+ * built on.
10
+ *
11
+ * A selection holding both something to lock and a lock to lift is `mixed`, a state of its own
12
+ * rather than a pair of booleans a menu has to read a combination out of.
13
+ *
14
+ * A control the document locked against deletion alone leaves its contents open, so it reads as
15
+ * text to lock rather than as a lock in reach: lifting that one clause by itself is not a state
16
+ * this answer can name. The guard still refuses taking such a control away.
17
+ */
18
+ export type SelectionLock = "none" | "lockable" | "locked" | "mixed";
19
+ /** What locking and unlocking would do where the selection stands */
20
+ export declare function selectionLock(state: EditorState): SelectionLock;
21
+ /**
22
+ * Locks the selected text, as one content control per paragraph it runs through.
23
+ * A control of the same type replaces the one already worn rather than being laid over it, so
24
+ * shutting a control that already stands there is the very same step as wrapping a new one.
25
+ * A selection that also reaches a lock still locks what that lock leaves open.
26
+ */
27
+ export declare const lockSelection: Command;
28
+ /** Lifts the lock off every control the selection reaches, over that control's whole stretch */
29
+ export declare const unlockSelection: Command;
30
+ /**
31
+ * Whether editing where the selection stands is shut.
32
+ * This is the same question the guard asks, so a menu built on it offers nothing that would
33
+ * then be refused: for a caret that means sitting inside a control rather than against its edge.
34
+ *
35
+ * A different question from `selectionLock`, deliberately: a caret against an edge lifts that
36
+ * control's lock, and is not itself shut by it.
37
+ */
38
+ export declare function selectionTouchesLocked(state: EditorState): boolean;
39
+ /**
40
+ * Whether the document holds any locked control at all, which is what registering a template turns
41
+ * on.
42
+ *
43
+ * Either clause counts: a control whose contents may not be edited, and one that may only not be
44
+ * taken away. This is a question about the document rather than about editing where the selection
45
+ * stands, and a document carrying the second kind is a document with a lock in it.
46
+ */
47
+ export declare function documentHasLocked(doc: PMNode): boolean;
@@ -0,0 +1,198 @@
1
+ // src/editor/commands/lockCommands.ts
2
+ import {
3
+ TextSelection
4
+ } from "prosemirror-state";
5
+ import { namesNothing, newControlId } from "../../docx/sdt.js";
6
+ import { withContentLock } from "../../docx/sdtProps.js";
7
+ import { docxSchema } from "../../schema/index.js";
8
+ import {
9
+ carriesLock,
10
+ controlSpans,
11
+ isLockedCell,
12
+ rangeTouchesLocked,
13
+ selectionShut,
14
+ unlockAllowed
15
+ } from "../../schema/locks.js";
16
+ function lockedControlMark(id) {
17
+ return docxSchema.marks.sdt.create({
18
+ sdtPrefix: `<w:sdt><w:sdtPr><w:id w:val="${id}"/><w:lock w:val="sdtContentLocked"/></w:sdtPr>`,
19
+ contentsLocked: true,
20
+ deletionLocked: true
21
+ });
22
+ }
23
+ function isLocked(mark) {
24
+ return mark.attrs.contentsLocked === true;
25
+ }
26
+ function prefixOf(attrs) {
27
+ const prefix = attrs.sdtPrefix;
28
+ return typeof prefix === "string" ? prefix : null;
29
+ }
30
+ function withLock(mark, locked) {
31
+ const prefix = prefixOf(mark.attrs);
32
+ const next = prefix === null ? null : withContentLock(prefix, locked);
33
+ if (next === null) return null;
34
+ return mark.type.create({
35
+ ...mark.attrs,
36
+ sdtPrefix: next,
37
+ contentsLocked: locked,
38
+ deletionLocked: locked
39
+ });
40
+ }
41
+ function overlaps(a, b) {
42
+ return a.from < b.to && a.to > b.from;
43
+ }
44
+ function reaches(a, b) {
45
+ return a.from <= b.to && a.to >= b.from;
46
+ }
47
+ function stretchIn(block, reach) {
48
+ const from = Math.max(block.start, reach.from);
49
+ const to = Math.min(block.start + block.node.content.size, reach.to);
50
+ return from < to ? { from, to } : null;
51
+ }
52
+ function gapsIn(stretch, spans) {
53
+ const gaps = [];
54
+ let at = stretch.from;
55
+ for (const span of spans) {
56
+ const to = Math.min(span.from, stretch.to);
57
+ if (at < to) gaps.push({ from: at, to });
58
+ at = Math.max(at, span.to);
59
+ }
60
+ if (at < stretch.to) gaps.push({ from: at, to: stretch.to });
61
+ return gaps;
62
+ }
63
+ function takeover(met, stretch, open) {
64
+ const only = met.length === 1 ? met[0] : null;
65
+ const prefix = only && prefixOf(only.mark.attrs);
66
+ if (!only || isLocked(only.mark) || !prefix || !namesNothing(prefix)) {
67
+ return null;
68
+ }
69
+ const mark = open(stretch) ? withLock(only.mark, true) : null;
70
+ return mark ? {
71
+ from: Math.min(stretch.from, only.from),
72
+ to: Math.max(stretch.to, only.to),
73
+ mark
74
+ } : null;
75
+ }
76
+ function blockLockEdits(doc, block, spans, reach) {
77
+ const stretch = stretchIn(block, reach);
78
+ if (!stretch) return [];
79
+ const open = (at) => !rangeTouchesLocked(doc, at.from, at.to);
80
+ const met = spans.filter((span) => overlaps(span, stretch));
81
+ const taken = takeover(met, stretch, open);
82
+ if (taken) return [taken];
83
+ const shut = met.filter((span) => !isLocked(span.mark) && open(span)).flatMap((span) => {
84
+ const mark = withLock(span.mark, true);
85
+ return mark ? [{ from: span.from, to: span.to, mark }] : [];
86
+ });
87
+ const fresh = gapsIn(stretch, spans).filter(open).map((gap) => ({ ...gap, mark: lockedControlMark(newControlId()) }));
88
+ return [...shut, ...fresh];
89
+ }
90
+ function selectionLockDetail(state) {
91
+ const selection = state.selection;
92
+ const locking = !selection.empty && selection instanceof TextSelection;
93
+ const edits = [];
94
+ const spans = [];
95
+ const cells = /* @__PURE__ */ new Map();
96
+ for (const range of selection.ranges) {
97
+ const reach = { from: range.$from.pos, to: range.$to.pos };
98
+ state.doc.nodesBetween(reach.from, reach.to, (node, pos) => {
99
+ if (isLockedCell(node)) cells.set(pos, node);
100
+ if (!node.isTextblock) return true;
101
+ const block = { node, start: pos + 1 };
102
+ const controls = controlSpans(block);
103
+ for (const span of controls) {
104
+ if (isLocked(span.mark) && reaches(span, reach)) spans.push(span);
105
+ }
106
+ if (locking) {
107
+ edits.push(...blockLockEdits(state.doc, block, controls, reach));
108
+ }
109
+ return false;
110
+ });
111
+ }
112
+ const locked = {
113
+ spans,
114
+ cells: Array.from(cells, ([pos, node]) => ({ pos, node }))
115
+ };
116
+ const anyLocked = spans.length > 0 || locked.cells.length > 0;
117
+ if (edits.length === 0) {
118
+ return anyLocked ? { kind: "locked", ...locked } : { kind: "none" };
119
+ }
120
+ return anyLocked ? { kind: "mixed", edits, ...locked } : { kind: "lockable", edits };
121
+ }
122
+ function selectionLock(state) {
123
+ return selectionLockDetail(state).kind;
124
+ }
125
+ function lockEditsOf(lock) {
126
+ switch (lock.kind) {
127
+ case "lockable":
128
+ case "mixed":
129
+ return lock.edits;
130
+ case "none":
131
+ case "locked":
132
+ return [];
133
+ }
134
+ }
135
+ var NOTHING_LOCKED = { spans: [], cells: [] };
136
+ function lockedOf(lock) {
137
+ switch (lock.kind) {
138
+ case "locked":
139
+ case "mixed":
140
+ return lock;
141
+ case "none":
142
+ case "lockable":
143
+ return NOTHING_LOCKED;
144
+ }
145
+ }
146
+ var lockSelection = (state, dispatch) => {
147
+ const edits = lockEditsOf(selectionLockDetail(state));
148
+ if (edits.length === 0) return false;
149
+ if (dispatch) {
150
+ const tr = state.tr;
151
+ for (const edit of edits) tr.addMark(edit.from, edit.to, edit.mark);
152
+ dispatch(tr);
153
+ }
154
+ return true;
155
+ };
156
+ function unlockCell(tr, cell) {
157
+ const prefix = prefixOf(cell.node.attrs);
158
+ tr.setNodeMarkup(cell.pos, null, {
159
+ ...cell.node.attrs,
160
+ sdtPrefix: prefix === null ? null : withContentLock(prefix, false),
161
+ sdtContentsLocked: false,
162
+ sdtDeletionLocked: false
163
+ });
164
+ }
165
+ var unlockSelection = (state, dispatch) => {
166
+ const { spans, cells } = lockedOf(selectionLockDetail(state));
167
+ if (spans.length === 0 && cells.length === 0) return false;
168
+ if (dispatch) {
169
+ const tr = state.tr.setMeta(unlockAllowed, true);
170
+ for (const span of spans) {
171
+ const opened = withLock(span.mark, false);
172
+ if (opened) tr.addMark(span.from, span.to, opened);
173
+ else tr.removeMark(span.from, span.to, span.mark);
174
+ }
175
+ for (const cell of cells) unlockCell(tr, cell);
176
+ dispatch(tr);
177
+ }
178
+ return true;
179
+ };
180
+ function selectionTouchesLocked(state) {
181
+ return selectionShut(state.selection, state.doc);
182
+ }
183
+ function documentHasLocked(doc) {
184
+ let found = false;
185
+ doc.descendants((node) => {
186
+ if (found) return false;
187
+ if (carriesLock(node)) found = true;
188
+ return !found;
189
+ });
190
+ return found;
191
+ }
192
+ export {
193
+ documentHasLocked,
194
+ lockSelection,
195
+ selectionLock,
196
+ selectionTouchesLocked,
197
+ unlockSelection
198
+ };
@@ -0,0 +1,12 @@
1
+ /** Document-level readers for imported footnotes and endnotes. */
2
+ import type { EditorState } from "prosemirror-state";
3
+ import type { NoteKind } from "../../docx/notes";
4
+ export interface DocumentNote {
5
+ kind: NoteKind;
6
+ id: string;
7
+ label: string;
8
+ text: string;
9
+ referencePos: number;
10
+ }
11
+ /** The distinct notes referenced by the main document story, in first-reference order. */
12
+ export declare function documentNotes(state: EditorState): readonly DocumentNote[];
@@ -0,0 +1,29 @@
1
+ // src/editor/commands/noteQueries.ts
2
+ function stringAttr(value) {
3
+ return typeof value === "string" ? value : null;
4
+ }
5
+ function documentNotes(state) {
6
+ const notes = [];
7
+ const seen = /* @__PURE__ */ new Set();
8
+ state.doc.descendants((node, pos) => {
9
+ if (node.type.name !== "noteReference") return true;
10
+ const id = stringAttr(node.attrs.id);
11
+ if (id === null) return true;
12
+ const kind = node.attrs.kind === "endnote" ? "endnote" : "footnote";
13
+ const key = `${kind}:${id}`;
14
+ if (seen.has(key)) return true;
15
+ seen.add(key);
16
+ notes.push({
17
+ kind,
18
+ id,
19
+ label: stringAttr(node.attrs.label) ?? "?",
20
+ text: stringAttr(node.attrs.text) ?? "",
21
+ referencePos: pos
22
+ });
23
+ return true;
24
+ });
25
+ return notes;
26
+ }
27
+ export {
28
+ documentNotes
29
+ };
@@ -0,0 +1,59 @@
1
+ /**
2
+ * Paragraph formatting commands: the alignment, and the style the paragraph points at.
3
+ *
4
+ * Alignment swaps the `w:jc` of the selected paragraphs and leaves the rest of the paragraph
5
+ * formatting untouched.
6
+ * Applying a style writes nothing but the `w:pStyle`, the same as Word: the values the style
7
+ * lays down are inherited rather than copied, so the direct formatting already written keeps
8
+ * beating them.
9
+ * All XML handling belongs to `docx/paraProps`; this file only calls those functions.
10
+ */
11
+ import type { Command, EditorState } from "prosemirror-state";
12
+ import { type ParagraphAlign } from "../../model/format";
13
+ /**
14
+ * Sets the alignment of the selected paragraphs.
15
+ * Exactly one alignment is always on, so there is no command to clear it (the same as Word).
16
+ */
17
+ export declare function setParagraphAlign(align: ParagraphAlign): Command;
18
+ /**
19
+ * Whether there is a paragraph to align at all, which is what the alignment menu is drawn from.
20
+ *
21
+ * The four alignments are one choice, so no single one of them answers for the menu: the one the
22
+ * selection already wears would report that it has nothing to do. What settles it is whether the
23
+ * lock leaves any of the selected paragraphs open (`editor/paragraphEdits`), the same question
24
+ * `canSetLineSpacing` asks for the menu beside it.
25
+ */
26
+ export declare function canSetParagraphAlign(state: EditorState): boolean;
27
+ /** The alignment of the selected paragraphs */
28
+ export type ActiveParagraphAlign =
29
+ /** They are all drawn with the same one */
30
+ {
31
+ kind: "shared";
32
+ align: ParagraphAlign;
33
+ }
34
+ /** They are drawn with several different ones, or the selection holds no paragraph at all */
35
+ | {
36
+ kind: "mixed";
37
+ };
38
+ export declare function activeParagraphAlign(state: EditorState): ActiveParagraphAlign;
39
+ /**
40
+ * Points the selected paragraphs at one of the styles the document defines.
41
+ * A null id takes the `w:pStyle` away, which is how a paragraph wears the default style.
42
+ */
43
+ export declare function setParagraphStyle(styleId: string | null): Command;
44
+ /** The style the selected paragraphs point at */
45
+ export type ActiveParagraphStyle =
46
+ /** They all point at the same one. A null id is a paragraph wearing the default style */
47
+ {
48
+ kind: "shared";
49
+ styleId: string | null;
50
+ }
51
+ /** They point at several different ones */
52
+ | {
53
+ kind: "mixed";
54
+ }
55
+ /** The selection holds no paragraph at all, so there is no style to show or to change */
56
+ | {
57
+ kind: "none";
58
+ };
59
+ export declare function activeParagraphStyle(state: EditorState): ActiveParagraphStyle;