@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,265 @@
1
+ // src/editor/plugins/imagePaste.ts
2
+ import { isHistoryTransaction } from "prosemirror-history";
3
+ import { Plugin, PluginKey } from "prosemirror-state";
4
+ import { Decoration, DecorationSet } from "prosemirror-view";
5
+ import { replacementShut } from "../../schema/locks.js";
6
+ import {
7
+ hasResolvableClipboardImages,
8
+ resolveClipboardImages
9
+ } from "../clipboard/images.js";
10
+ import { documentBodyHeightPx, documentBodyWidthPx } from "../documentStyles.js";
11
+ import { richHtmlSlice } from "../externalClipboard.js";
12
+ import { insertPlainTextAt } from "../plainText.js";
13
+ var LOAD_TIMEOUT_MS = 15e3;
14
+ var imagePasteKey = new PluginKey("docxImagePaste");
15
+ function marker(view) {
16
+ const element = view.dom.ownerDocument.createElement("span");
17
+ element.hidden = true;
18
+ return element;
19
+ }
20
+ function taskRange(decorations, id) {
21
+ const found = decorations.find(
22
+ void 0,
23
+ void 0,
24
+ (spec) => spec.task === id
25
+ );
26
+ const from = found.find((decoration) => decoration.spec.edge === "from");
27
+ const to = found.find((decoration) => decoration.spec.edge === "to");
28
+ return from && to ? { from: from.from, to: to.from } : null;
29
+ }
30
+ function rangesConflict(first, second) {
31
+ if (first.from === first.to) {
32
+ return second.from === second.to ? first.from === second.from : second.from <= first.from && first.from < second.to;
33
+ }
34
+ if (second.from === second.to) {
35
+ return first.from <= second.from && second.from < first.to;
36
+ }
37
+ return first.from < second.to && second.from < first.to;
38
+ }
39
+ function transactionTouchesRange(transaction, initial) {
40
+ let { from, to } = initial;
41
+ for (const [index, step] of transaction.steps.entries()) {
42
+ const map = transaction.mapping.maps[index];
43
+ if (!map) return true;
44
+ let described = false;
45
+ let touched = false;
46
+ map.forEach((oldStart, oldEnd) => {
47
+ described = true;
48
+ if (oldStart === oldEnd ? from <= oldStart && oldStart < to : oldStart < to && from < oldEnd) {
49
+ touched = true;
50
+ }
51
+ });
52
+ if (touched) return true;
53
+ if (!described) {
54
+ const json = step.toJSON();
55
+ if (typeof json.from !== "number" || typeof json.to !== "number") {
56
+ return true;
57
+ }
58
+ if (json.from < to && from < json.to) return true;
59
+ }
60
+ from = map.map(from, -1);
61
+ to = map.map(to, -1);
62
+ }
63
+ return false;
64
+ }
65
+ function imagePaste() {
66
+ const tasks = [];
67
+ let working = false;
68
+ const cancel = (task) => {
69
+ task.canceled = true;
70
+ task.controller?.abort();
71
+ };
72
+ const cancelAll = () => {
73
+ for (const task of tasks) cancel(task);
74
+ };
75
+ const removeMarker = (task) => {
76
+ if (task.view.isDestroyed) return;
77
+ task.view.dispatch(
78
+ task.view.state.tr.setMeta(imagePasteKey, {
79
+ remove: [task.id]
80
+ }).setMeta("addToHistory", false)
81
+ );
82
+ };
83
+ const finish = (task, resolved) => {
84
+ if (task.canceled || task.view.isDestroyed) return;
85
+ const state = imagePasteKey.getState(task.view.state);
86
+ const range = state && taskRange(state.decorations, task.id);
87
+ if (!range) return;
88
+ removeMarker(task);
89
+ if (task.view.isDestroyed) return;
90
+ const slice = resolved === null || resolved.images.size === 0 ? null : richHtmlSlice(
91
+ task.view.state,
92
+ task.view.dom.ownerDocument,
93
+ resolved.source,
94
+ resolved.images
95
+ );
96
+ if (slice !== null) {
97
+ task.view.dispatch(
98
+ task.view.state.tr.replaceRange(range.from, range.to, slice).scrollIntoView()
99
+ );
100
+ } else {
101
+ insertPlainTextAt(task.view, task.text, range.from, range.to);
102
+ }
103
+ };
104
+ const work = async () => {
105
+ if (working) return;
106
+ working = true;
107
+ try {
108
+ while (tasks.length > 0) {
109
+ const task = tasks[0];
110
+ if (!task || task.canceled || task.view.isDestroyed) {
111
+ tasks.shift();
112
+ continue;
113
+ }
114
+ const controller = new AbortController();
115
+ task.controller = controller;
116
+ const timeout = setTimeout(() => controller.abort(), LOAD_TIMEOUT_MS);
117
+ let resolved = null;
118
+ try {
119
+ const request = resolveClipboardImages(
120
+ task.view.dom.ownerDocument,
121
+ task.html,
122
+ {
123
+ maxWidthPx: task.maxWidthPx,
124
+ maxHeightPx: task.maxHeightPx,
125
+ signal: controller.signal
126
+ }
127
+ );
128
+ resolved = request === null ? null : await request;
129
+ } catch {
130
+ resolved = null;
131
+ } finally {
132
+ clearTimeout(timeout);
133
+ task.controller = null;
134
+ }
135
+ finish(task, resolved);
136
+ tasks.shift();
137
+ }
138
+ } finally {
139
+ working = false;
140
+ }
141
+ };
142
+ return new Plugin({
143
+ key: imagePasteKey,
144
+ state: {
145
+ init: () => ({
146
+ decorations: DecorationSet.empty,
147
+ cancelVersion: 0
148
+ }),
149
+ apply(transaction, current) {
150
+ if (isHistoryTransaction(transaction)) {
151
+ return {
152
+ decorations: DecorationSet.empty,
153
+ cancelVersion: current.cancelVersion + 1
154
+ };
155
+ }
156
+ let decorations = current.decorations;
157
+ if (transaction.docChanged) {
158
+ const ids = /* @__PURE__ */ new Set();
159
+ for (const decoration of decorations.find()) {
160
+ ids.add(decoration.spec.task);
161
+ }
162
+ const invalidated = /* @__PURE__ */ new Set();
163
+ for (const id of ids) {
164
+ const range = taskRange(decorations, id);
165
+ if (range !== null && range.from !== range.to && transactionTouchesRange(transaction, range)) {
166
+ invalidated.add(id);
167
+ }
168
+ }
169
+ decorations = decorations.remove(
170
+ decorations.find(
171
+ void 0,
172
+ void 0,
173
+ (spec) => invalidated.has(spec.task)
174
+ )
175
+ );
176
+ }
177
+ decorations = decorations.map(transaction.mapping, transaction.doc);
178
+ const meta = transaction.getMeta(imagePasteKey);
179
+ if (meta?.remove) {
180
+ const removed = new Set(meta.remove);
181
+ decorations = decorations.remove(
182
+ decorations.find(
183
+ void 0,
184
+ void 0,
185
+ (spec) => removed.has(spec.task)
186
+ )
187
+ );
188
+ }
189
+ if (meta?.add) {
190
+ const { id, from, to } = meta.add;
191
+ decorations = decorations.add(transaction.doc, [
192
+ Decoration.widget(from, marker, {
193
+ task: id,
194
+ edge: "from",
195
+ side: -1
196
+ }),
197
+ Decoration.widget(to, marker, {
198
+ task: id,
199
+ edge: "to",
200
+ side: -1
201
+ })
202
+ ]);
203
+ }
204
+ return { decorations, cancelVersion: current.cancelVersion };
205
+ }
206
+ },
207
+ view: () => ({
208
+ update(view, previous) {
209
+ const before = imagePasteKey.getState(previous);
210
+ const current = imagePasteKey.getState(view.state);
211
+ if (!current) return;
212
+ if (before && before.cancelVersion !== current.cancelVersion) {
213
+ cancelAll();
214
+ return;
215
+ }
216
+ for (const task of tasks) {
217
+ if (!taskRange(current.decorations, task.id)) cancel(task);
218
+ }
219
+ },
220
+ destroy: cancelAll
221
+ }),
222
+ props: {
223
+ decorations: (state) => imagePasteKey.getState(state)?.decorations,
224
+ handlePaste(view, event) {
225
+ if (replacementShut(view.state.selection, view.state.doc)) return false;
226
+ if (view.state.selection.ranges.length > 1) return false;
227
+ const html = event.clipboardData?.getData("text/html") ?? "";
228
+ if (!hasResolvableClipboardImages(view.dom.ownerDocument, html)) {
229
+ return false;
230
+ }
231
+ const text = event.clipboardData?.getData("text/plain") ?? "";
232
+ const { from, to } = view.state.selection;
233
+ const current = imagePasteKey.getState(view.state);
234
+ const replaced = tasks.filter((task) => {
235
+ if (!current || task.canceled) return false;
236
+ const range = taskRange(current.decorations, task.id);
237
+ return range !== null && rangesConflict(range, { from, to });
238
+ });
239
+ for (const task of replaced) cancel(task);
240
+ const id = {};
241
+ view.dispatch(
242
+ view.state.tr.setMeta(imagePasteKey, {
243
+ add: { id, from, to },
244
+ remove: replaced.map((task) => task.id)
245
+ }).setMeta("addToHistory", false)
246
+ );
247
+ tasks.push({
248
+ id,
249
+ view,
250
+ html,
251
+ text,
252
+ maxWidthPx: documentBodyWidthPx(view.state),
253
+ maxHeightPx: documentBodyHeightPx(view.state),
254
+ canceled: false,
255
+ controller: null
256
+ });
257
+ void work();
258
+ return true;
259
+ }
260
+ }
261
+ });
262
+ }
263
+ export {
264
+ imagePaste
265
+ };
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Keys not handled here are taken by ProseMirror's base keymap.
3
+ */
4
+ import type { Command } from "prosemirror-state";
5
+ export declare const docxKeymap: Record<string, Command>;
@@ -0,0 +1,94 @@
1
+ // src/editor/plugins/keymap.ts
2
+ import { chainCommands } from "prosemirror-commands";
3
+ import { undoInputRule } from "prosemirror-inputrules";
4
+ import { goToNextCell } from "prosemirror-tables";
5
+ import { canSplit } from "prosemirror-transform";
6
+ import { toParagraphFormat } from "../../model/format.js";
7
+ import { docxSchema } from "../../schema/index.js";
8
+ import { insertLineBreak, insertPageBreak } from "../commands/breakCommands.js";
9
+ import {
10
+ toggleBold,
11
+ toggleItalic,
12
+ toggleStrike,
13
+ toggleUnderline
14
+ } from "../commands/formattingCommands.js";
15
+ import { redo, undo } from "../commands/historyCommands.js";
16
+ import { activeLinkSpan } from "../commands/linkCommands.js";
17
+ import {
18
+ decreaseListLevel,
19
+ increaseListLevel,
20
+ leaveEmptyListItem
21
+ } from "../commands/listCommands.js";
22
+ import { insertTab, moveAcrossTab } from "../commands/tabCommands.js";
23
+ import { openLinkPanel } from "./linkPanel.js";
24
+ var insertTabFromKeyboard = (state, dispatch, view) => {
25
+ if (!state.selection.empty && activeLinkSpan(state)) return false;
26
+ return insertTab(state, dispatch, view);
27
+ };
28
+ function listLevelCommand(command) {
29
+ return (state, dispatch, view) => {
30
+ const format = toParagraphFormat(state.selection.$from.parent.attrs.format);
31
+ if (!format?.numbering) return false;
32
+ command(state, dispatch, view);
33
+ return true;
34
+ };
35
+ }
36
+ var splitParagraph = (state, dispatch) => {
37
+ if (state.selection.$from.parent.type !== docxSchema.nodes.paragraph) {
38
+ return false;
39
+ }
40
+ const tr = state.tr;
41
+ if (!state.selection.empty) tr.deleteSelection();
42
+ const at = tr.mapping.map(state.selection.$from.pos);
43
+ const parent = tr.doc.resolve(at).parent;
44
+ if (parent.type !== docxSchema.nodes.paragraph) return false;
45
+ const types = [{ type: docxSchema.nodes.paragraph, attrs: parent.attrs }];
46
+ if (!canSplit(tr.doc, at, 1, types)) return false;
47
+ if (dispatch) dispatch(tr.split(at, 1, types).scrollIntoView());
48
+ return true;
49
+ };
50
+ var preserveTableFollowingParagraph = (state) => {
51
+ const { $from } = state.selection;
52
+ if (!state.selection.empty || $from.depth !== 1 || $from.parent.type !== docxSchema.nodes.paragraph || $from.parent.content.size !== 0 || $from.parentOffset !== 0) {
53
+ return false;
54
+ }
55
+ const paragraphIndex = $from.index(0);
56
+ return paragraphIndex > 0 && state.doc.child(paragraphIndex - 1).type.spec.tableRole === "table";
57
+ };
58
+ var docxKeymap = {
59
+ Enter: chainCommands(leaveEmptyListItem, splitParagraph),
60
+ "Shift-Enter": insertLineBreak,
61
+ // Word and Google Docs both put a page break on this key, so it needs no learning
62
+ "Mod-Enter": insertPageBreak,
63
+ // The paragraph keeps adjacent tables separate without changing imported documents.
64
+ Backspace: chainCommands(preserveTableFollowingParagraph, undoInputRule),
65
+ "Mod-z": undo,
66
+ "Mod-y": redo,
67
+ "Shift-Mod-z": redo,
68
+ "Mod-b": toggleBold,
69
+ "Mod-i": toggleItalic,
70
+ "Mod-u": toggleUnderline,
71
+ // The one strikethrough key Word and Google Docs agree on
72
+ "Mod-Shift-x": toggleStrike,
73
+ // The link key Word and Google Docs share. It opens the panel over the selection, and with
74
+ // nothing there to link it reports that it did nothing, so the browser keeps its own Cmd+K
75
+ "Mod-k": openLinkPanel,
76
+ // Inside a table, moving between cells comes first (Word does the same).
77
+ // In a list paragraph outside a table it shifts the level; an ordinary paragraph gets a document tab.
78
+ Tab: chainCommands(
79
+ goToNextCell(1),
80
+ listLevelCommand(increaseListLevel),
81
+ insertTabFromKeyboard
82
+ ),
83
+ "Shift-Tab": chainCommands(
84
+ goToNextCell(-1),
85
+ listLevelCommand(decreaseListLevel)
86
+ ),
87
+ ArrowLeft: moveAcrossTab("left", false),
88
+ ArrowRight: moveAcrossTab("right", false),
89
+ "Shift-ArrowLeft": moveAcrossTab("left", true),
90
+ "Shift-ArrowRight": moveAcrossTab("right", true)
91
+ };
92
+ export {
93
+ docxKeymap
94
+ };
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Whether the panel that reads and writes a link's address stands open.
3
+ *
4
+ * Like the two context menus, this file only records that the panel was asked for; drawing it is
5
+ * the React side's job (`ui/LinkPanel`). One state serves both ways in - Cmd+K
6
+ * (`editor/plugins/keymap`) and the toolbar button - so the panel is the same panel however it was
7
+ * opened, and it opens where the link is going rather than under whichever control asked for it.
8
+ *
9
+ * It closes on the document changing, which is what applying a link or taking one off does: the
10
+ * panel is about the selection it opened over, and after an edit that selection has been answered.
11
+ */
12
+ import { type Command, type EditorState, Plugin } from "prosemirror-state";
13
+ /** Whether the link panel is open */
14
+ export declare function isLinkPanelOpen(state: EditorState): boolean;
15
+ /**
16
+ * Opens the panel. It reports false where a link could not go on anyway - a caret standing in no
17
+ * link, a selection a lock leaves nothing of - so that Cmd+K there is a key this editor did not
18
+ * take, and a control drawn from it is drawn dead.
19
+ */
20
+ export declare const openLinkPanel: Command;
21
+ /** Closes it. Called on applying, on Escape, and on a click outside */
22
+ export declare const closeLinkPanel: Command;
23
+ export declare function linkPanel(): Plugin<boolean>;
@@ -0,0 +1,39 @@
1
+ // src/editor/plugins/linkPanel.ts
2
+ import {
3
+ Plugin,
4
+ PluginKey
5
+ } from "prosemirror-state";
6
+ import { canSetLink } from "../commands/linkCommands.js";
7
+ var panelKey = new PluginKey("docxEditorLinkPanel");
8
+ function isLinkPanelOpen(state) {
9
+ return panelKey.getState(state) === true;
10
+ }
11
+ var openLinkPanel = (state, dispatch) => {
12
+ if (isLinkPanelOpen(state) || !canSetLink(state)) return false;
13
+ if (dispatch) dispatch(state.tr.setMeta(panelKey, true));
14
+ return true;
15
+ };
16
+ var closeLinkPanel = (state, dispatch) => {
17
+ if (!isLinkPanelOpen(state)) return false;
18
+ if (dispatch) dispatch(state.tr.setMeta(panelKey, false));
19
+ return true;
20
+ };
21
+ function linkPanel() {
22
+ return new Plugin({
23
+ key: panelKey,
24
+ state: {
25
+ init: () => false,
26
+ apply: (tr, open) => {
27
+ const meta = tr.getMeta(panelKey);
28
+ if (typeof meta === "boolean") return meta;
29
+ return tr.docChanged ? false : open;
30
+ }
31
+ }
32
+ });
33
+ }
34
+ export {
35
+ closeLinkPanel,
36
+ isLinkPanelOpen,
37
+ linkPanel,
38
+ openLinkPanel
39
+ };
@@ -0,0 +1,14 @@
1
+ /**
2
+ * The prefixes that start a list when they are typed at the beginning of a line.
3
+ *
4
+ * Word and Google Docs both turn a line beginning with a list-looking prefix into a list item
5
+ * the moment the space after the prefix is typed, and drop the prefix. This does the same by
6
+ * running the very commands the list buttons run, so a list started by typing is in every
7
+ * respect the list the button makes.
8
+ */
9
+ import type { Plugin } from "prosemirror-state";
10
+ /**
11
+ * The plugin that watches for the prefixes.
12
+ * A conversion is taken back by `undoInputRule`, which Backspace is bound to.
13
+ */
14
+ export declare function listInputRules(): Plugin;
@@ -0,0 +1,36 @@
1
+ // src/editor/plugins/listInputRules.ts
2
+ import { InputRule, inputRules } from "prosemirror-inputrules";
3
+ import { docxSchema } from "../../schema/index.js";
4
+ import {
5
+ listRefOf,
6
+ toggleBulletList,
7
+ toggleNumberedList
8
+ } from "../commands/listCommands.js";
9
+ var NUMBERED_PREFIX = /^1\. $/;
10
+ var BULLET_PREFIX = /^[-*] $/;
11
+ function transactionOf(state, command) {
12
+ const dispatched = [];
13
+ command(state, (tr) => dispatched.push(tr));
14
+ return dispatched[0] ?? null;
15
+ }
16
+ function startListByTyping(toggle) {
17
+ return (state, _match, start, end) => {
18
+ const $start = state.doc.resolve(start);
19
+ if ($start.parent.type !== docxSchema.nodes.paragraph) return null;
20
+ if ($start.parentOffset > 0) return null;
21
+ if (listRefOf($start.parent)) return null;
22
+ const listed = transactionOf(state, toggle);
23
+ return listed?.delete(start, end) ?? null;
24
+ };
25
+ }
26
+ function listInputRules() {
27
+ return inputRules({
28
+ rules: [
29
+ new InputRule(NUMBERED_PREFIX, startListByTyping(toggleNumberedList)),
30
+ new InputRule(BULLET_PREFIX, startListByTyping(toggleBulletList))
31
+ ]
32
+ });
33
+ }
34
+ export {
35
+ listInputRules
36
+ };
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Rejects transactions disallowed by `schema/locks`. A rejected IME edit also ends the browser
3
+ * composition on the next frame so ProseMirror cannot remain stuck in composing state.
4
+ */
5
+ import { Plugin } from "prosemirror-state";
6
+ export declare function lockedContent(): Plugin;
@@ -0,0 +1,41 @@
1
+ // src/editor/plugins/lockedContent.ts
2
+ import { Plugin } from "prosemirror-state";
3
+ import { transactionAllowed } from "../../schema/locks.js";
4
+ function endComposition(view) {
5
+ if (!view.composing) return;
6
+ const marks = view.state.storedMarks ?? view.state.selection.$from.marks();
7
+ view.dispatch(
8
+ view.state.tr.setStoredMarks(marks).setMeta("addToHistory", false)
9
+ );
10
+ }
11
+ function lockedContent() {
12
+ let live = null;
13
+ let frame = 0;
14
+ const afterRefusal = () => {
15
+ if (live?.composing !== true || frame !== 0) return;
16
+ frame = requestAnimationFrame(() => {
17
+ frame = 0;
18
+ if (live) endComposition(live);
19
+ });
20
+ };
21
+ return new Plugin({
22
+ view(view) {
23
+ live = view;
24
+ return {
25
+ destroy() {
26
+ if (frame !== 0) cancelAnimationFrame(frame);
27
+ frame = 0;
28
+ live = null;
29
+ }
30
+ };
31
+ },
32
+ filterTransaction(tr, state) {
33
+ const allowed = transactionAllowed(tr, state.doc);
34
+ if (!allowed) afterRefusal();
35
+ return allowed;
36
+ }
37
+ });
38
+ }
39
+ export {
40
+ lockedContent
41
+ };
@@ -0,0 +1,3 @@
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;
@@ -0,0 +1,25 @@
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
+ };
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Draws list markers and inherited indentation as decorations so display-only values never create
3
+ * new OOXML on export. The plugin also exposes numbering definitions to list commands.
4
+ */
5
+ import type { Node as PMNode } from "prosemirror-model";
6
+ import { type EditorState, Plugin } from "prosemirror-state";
7
+ import { DecorationSet } from "prosemirror-view";
8
+ import { type Numbering } from "../../numbering/parseNumbering";
9
+ /** A number to draw on screen and the paragraph position it attaches to */
10
+ export interface PlacedMarker {
11
+ from: number;
12
+ to: number;
13
+ text: string;
14
+ /** The width of the hanging indent the number sits in */
15
+ widthPt: number;
16
+ /** Logical indentation taken from the level and overlaid only when the paragraph writes none. */
17
+ indentStartPt: number | null;
18
+ indentEndPt: number | null;
19
+ /** The first-line indentation, under the same rule */
20
+ textIndentPt: number | null;
21
+ }
22
+ /** Walks a document to find the paragraphs that get numbers and what those numbers are */
23
+ export declare function paragraphMarkers(doc: PMNode, numbering: Numbering): PlacedMarker[];
24
+ export declare function markerDecorations(doc: PMNode, numbering: Numbering): DecorationSet;
25
+ /** What the plugin holds: the document's list definitions and the numbers to draw right now */
26
+ interface NumberingState {
27
+ numbering: Numbering;
28
+ /** Whether the document has a place (numbering.xml) to write the definition of a new list */
29
+ canStartNewList: boolean;
30
+ decorations: DecorationSet;
31
+ }
32
+ /** This document's list definitions. Empty when the editor does not know them */
33
+ export declare function documentNumbering(state: EditorState): Numbering;
34
+ /**
35
+ * Whether a new list can be started in this document.
36
+ * A document without numbering.xml has nowhere to write a new definition, so it would be
37
+ * blocked at export time. In such a document the commands that start a list do not apply
38
+ * in the first place.
39
+ */
40
+ export declare function canStartNewList(state: EditorState): boolean;
41
+ export declare function numberingMarkers(numbering?: Numbering, canStartNewList?: boolean): Plugin<NumberingState>;
42
+ export {};