@witchcraft/editor 0.0.5 → 0.0.7

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 (416) hide show
  1. package/dist/module.d.mts +15 -2
  2. package/dist/module.json +1 -1
  3. package/dist/module.mjs +67 -13
  4. package/dist/runtime/assets/base.css +1 -0
  5. package/dist/runtime/assets/handle-arrow.svg +16 -0
  6. package/dist/runtime/assets/handle-border-circles-single.svg +44 -0
  7. package/dist/runtime/assets/handle-border-circles.svg +27 -0
  8. package/dist/runtime/assets/handle-temp.svg +1 -0
  9. package/dist/runtime/assets/utils.css +1 -0
  10. package/dist/runtime/components/CodeBlockThemePicker.d.vue.ts +12 -0
  11. package/dist/runtime/components/CodeBlockThemePicker.vue +123 -0
  12. package/dist/runtime/components/CodeBlockThemePicker.vue.d.ts +12 -0
  13. package/dist/runtime/components/Commands.d.vue.ts +10 -0
  14. package/dist/runtime/components/Commands.vue +60 -0
  15. package/dist/runtime/components/Commands.vue.d.ts +10 -0
  16. package/dist/runtime/components/Editor.d.vue.ts +40 -0
  17. package/dist/runtime/components/Editor.vue +208 -0
  18. package/dist/runtime/components/Editor.vue.d.ts +40 -0
  19. package/dist/runtime/components/EditorDemoApp.d.vue.ts +2 -0
  20. package/dist/runtime/components/EditorDemoApp.vue +104 -0
  21. package/dist/runtime/components/EditorDemoApp.vue.d.ts +2 -0
  22. package/dist/runtime/components/EditorDemoControls.d.vue.ts +12 -0
  23. package/dist/runtime/components/EditorDemoControls.vue +36 -0
  24. package/dist/runtime/components/EditorDemoControls.vue.d.ts +12 -0
  25. package/dist/runtime/components/TestWrapper.d.vue.ts +11 -0
  26. package/dist/runtime/components/TestWrapper.vue +63 -0
  27. package/dist/runtime/components/TestWrapper.vue.d.ts +11 -0
  28. package/dist/runtime/composables/useEditor.d.ts +9 -0
  29. package/dist/runtime/composables/useEditor.js +21 -0
  30. package/dist/runtime/composables/useWindowDebugging.d.ts +3 -0
  31. package/dist/runtime/composables/useWindowDebugging.js +16 -0
  32. package/dist/runtime/demo/App.d.vue.ts +2 -0
  33. package/dist/runtime/demo/App.vue +101 -0
  34. package/dist/runtime/demo/App.vue.d.ts +2 -0
  35. package/dist/runtime/demo/README.md +1 -0
  36. package/dist/runtime/demo/main.d.ts +1 -0
  37. package/dist/runtime/demo/main.js +4 -0
  38. package/dist/runtime/demo/tailwind.css +1 -0
  39. package/dist/runtime/env.d.ts +2 -0
  40. package/dist/runtime/injectionKeys.d.ts +6 -0
  41. package/dist/runtime/injectionKeys.js +3 -0
  42. package/dist/runtime/main.lib.d.ts +2 -0
  43. package/dist/runtime/main.lib.js +2 -0
  44. package/dist/runtime/pm/commands/backspace.d.ts +12 -0
  45. package/dist/runtime/pm/commands/backspace.js +26 -0
  46. package/dist/runtime/pm/commands/changeAttrs.d.ts +9 -0
  47. package/dist/runtime/pm/commands/changeAttrs.js +15 -0
  48. package/dist/runtime/pm/commands/deleteSelection.d.ts +9 -0
  49. package/dist/runtime/pm/commands/deleteSelection.js +8 -0
  50. package/dist/runtime/pm/commands/enter.d.ts +14 -0
  51. package/dist/runtime/pm/commands/enter.js +9 -0
  52. package/dist/runtime/pm/commands/insertBreak.d.ts +9 -0
  53. package/dist/runtime/pm/commands/insertBreak.js +22 -0
  54. package/dist/runtime/pm/features/Base/Base.d.ts +4 -0
  55. package/dist/runtime/pm/features/Base/Base.js +32 -0
  56. package/dist/runtime/pm/features/Base/commands/deleteNodes.d.ts +10 -0
  57. package/dist/runtime/pm/features/Base/commands/deleteNodes.js +29 -0
  58. package/dist/runtime/pm/features/Base/commands/setCursorVisible.d.ts +12 -0
  59. package/dist/runtime/pm/features/Base/commands/setCursorVisible.js +7 -0
  60. package/dist/runtime/pm/features/Base/plugins/debugSelectionPlugin.d.ts +9 -0
  61. package/dist/runtime/pm/features/Base/plugins/debugSelectionPlugin.js +48 -0
  62. package/dist/runtime/pm/features/Base/plugins/isCursorVisiblePlugin.d.ts +3 -0
  63. package/dist/runtime/pm/features/Base/plugins/isCursorVisiblePlugin.js +26 -0
  64. package/dist/runtime/pm/features/Base/plugins/isUsingTouchPlugin.d.ts +3 -0
  65. package/dist/runtime/pm/features/Base/plugins/isUsingTouchPlugin.js +38 -0
  66. package/dist/runtime/pm/features/Base/plugins/selectingIndicator.d.ts +5 -0
  67. package/dist/runtime/pm/features/Base/plugins/selectingIndicator.js +35 -0
  68. package/dist/runtime/pm/features/Base/plugins/unfocusedSelectionIndicatorPlugin.d.ts +33 -0
  69. package/dist/runtime/pm/features/Base/plugins/unfocusedSelectionIndicatorPlugin.js +66 -0
  70. package/dist/runtime/pm/features/Base/types.d.ts +3 -0
  71. package/dist/runtime/pm/features/Base/types.js +0 -0
  72. package/dist/runtime/pm/features/BaseShortcuts/BaseShortcuts.d.ts +3 -0
  73. package/dist/runtime/pm/features/BaseShortcuts/BaseShortcuts.js +34 -0
  74. package/dist/runtime/pm/features/Blockquote/Blockquote.d.ts +5 -0
  75. package/dist/runtime/pm/features/Blockquote/Blockquote.js +65 -0
  76. package/dist/runtime/pm/features/Blockquote/commands/blockquoteEnter.d.ts +11 -0
  77. package/dist/runtime/pm/features/Blockquote/commands/blockquoteEnter.js +31 -0
  78. package/dist/runtime/pm/features/Blockquote/commands/blockquoteShiftEnter.d.ts +11 -0
  79. package/dist/runtime/pm/features/Blockquote/commands/blockquoteShiftEnter.js +12 -0
  80. package/dist/runtime/pm/features/Blocks/Blocks.d.ts +2 -0
  81. package/dist/runtime/pm/features/Blocks/Blocks.js +2 -0
  82. package/dist/runtime/pm/features/Blocks/Item.d.ts +11 -0
  83. package/dist/runtime/pm/features/Blocks/Item.js +157 -0
  84. package/dist/runtime/pm/features/Blocks/List.d.ts +4 -0
  85. package/dist/runtime/pm/features/Blocks/List.js +59 -0
  86. package/dist/runtime/pm/features/Blocks/commands/changeItemType.d.ts +20 -0
  87. package/dist/runtime/pm/features/Blocks/commands/changeItemType.js +40 -0
  88. package/dist/runtime/pm/features/Blocks/commands/changeTypeAttr.d.ts +14 -0
  89. package/dist/runtime/pm/features/Blocks/commands/changeTypeAttr.js +28 -0
  90. package/dist/runtime/pm/features/Blocks/commands/copyOrMoveItem.d.ts +23 -0
  91. package/dist/runtime/pm/features/Blocks/commands/copyOrMoveItem.js +124 -0
  92. package/dist/runtime/pm/features/Blocks/commands/deleteItem.d.ts +12 -0
  93. package/dist/runtime/pm/features/Blocks/commands/deleteItem.js +8 -0
  94. package/dist/runtime/pm/features/Blocks/commands/indentItem.d.ts +12 -0
  95. package/dist/runtime/pm/features/Blocks/commands/indentItem.js +58 -0
  96. package/dist/runtime/pm/features/Blocks/commands/itemMenuCommands.d.ts +18 -0
  97. package/dist/runtime/pm/features/Blocks/commands/itemMenuCommands.js +40 -0
  98. package/dist/runtime/pm/features/Blocks/commands/moveItem.d.ts +12 -0
  99. package/dist/runtime/pm/features/Blocks/commands/moveItem.js +80 -0
  100. package/dist/runtime/pm/features/Blocks/commands/setNode.d.ts +20 -0
  101. package/dist/runtime/pm/features/Blocks/commands/setNode.js +87 -0
  102. package/dist/runtime/pm/features/Blocks/commands/splitItem.d.ts +17 -0
  103. package/dist/runtime/pm/features/Blocks/commands/splitItem.js +87 -0
  104. package/dist/runtime/pm/features/Blocks/commands/unindentItem.d.ts +12 -0
  105. package/dist/runtime/pm/features/Blocks/commands/unindentItem.js +42 -0
  106. package/dist/runtime/pm/features/Blocks/components/DragTreeHandle.d.vue.ts +0 -0
  107. package/dist/runtime/pm/features/Blocks/components/DragTreeHandle.vue +129 -0
  108. package/dist/runtime/pm/features/Blocks/components/DragTreeHandle.vue.d.ts +0 -0
  109. package/dist/runtime/pm/features/Blocks/components/ItemMenu.d.vue.ts +6 -0
  110. package/dist/runtime/pm/features/Blocks/components/ItemMenu.vue +78 -0
  111. package/dist/runtime/pm/features/Blocks/components/ItemMenu.vue.d.ts +6 -0
  112. package/dist/runtime/pm/features/Blocks/components/ItemNodeView.d.vue.ts +92 -0
  113. package/dist/runtime/pm/features/Blocks/components/ItemNodeView.vue +350 -0
  114. package/dist/runtime/pm/features/Blocks/components/ItemNodeView.vue.d.ts +92 -0
  115. package/dist/runtime/pm/features/Blocks/components/defaultItemMenu.d.ts +5 -0
  116. package/dist/runtime/pm/features/Blocks/components/defaultItemMenu.js +42 -0
  117. package/dist/runtime/pm/features/Blocks/composables/useDragWithThreshold.d.ts +1 -0
  118. package/dist/runtime/pm/features/Blocks/composables/useDragWithThreshold.js +0 -0
  119. package/dist/runtime/pm/features/Blocks/composables/useHandleHeight.d.ts +5 -0
  120. package/dist/runtime/pm/features/Blocks/composables/useHandleHeight.js +22 -0
  121. package/dist/runtime/pm/features/Blocks/composables/useHasChildren.d.ts +5 -0
  122. package/dist/runtime/pm/features/Blocks/composables/useHasChildren.js +10 -0
  123. package/dist/runtime/pm/features/Blocks/composables/useNodeStates.d.ts +7 -0
  124. package/dist/runtime/pm/features/Blocks/composables/useNodeStates.js +20 -0
  125. package/dist/runtime/pm/features/Blocks/itemMenuMenuItems.d.ts +20 -0
  126. package/dist/runtime/pm/features/Blocks/itemMenuMenuItems.js +138 -0
  127. package/dist/runtime/pm/features/Blocks/plugins/ensureLastItemIsContentPlugin.d.ts +11 -0
  128. package/dist/runtime/pm/features/Blocks/plugins/ensureLastItemIsContentPlugin.js +36 -0
  129. package/dist/runtime/pm/features/Blocks/plugins/itemBlockIdPlugin.d.ts +8 -0
  130. package/dist/runtime/pm/features/Blocks/plugins/itemBlockIdPlugin.js +30 -0
  131. package/dist/runtime/pm/features/Blocks/plugins/itemHasSingularSelectionPlugin.d.ts +3 -0
  132. package/dist/runtime/pm/features/Blocks/plugins/itemHasSingularSelectionPlugin.js +30 -0
  133. package/dist/runtime/pm/features/Blocks/plugins/itemMenuPlugin.d.ts +4 -0
  134. package/dist/runtime/pm/features/Blocks/plugins/itemMenuPlugin.js +17 -0
  135. package/dist/runtime/pm/features/Blocks/states/stateful.d.ts +2 -0
  136. package/dist/runtime/pm/features/Blocks/states/stateful.js +37 -0
  137. package/dist/runtime/pm/features/Blocks/states/task/cancelled.svg +32 -0
  138. package/dist/runtime/pm/features/Blocks/states/task/checked.svg +27 -0
  139. package/dist/runtime/pm/features/Blocks/states/task/checked2.svg +24 -0
  140. package/dist/runtime/pm/features/Blocks/states/task/partial.svg +24 -0
  141. package/dist/runtime/pm/features/Blocks/states/task/partial2.svg +31 -0
  142. package/dist/runtime/pm/features/Blocks/states/task/unchecked.svg +20 -0
  143. package/dist/runtime/pm/features/Blocks/types.d.ts +43 -0
  144. package/dist/runtime/pm/features/Blocks/types.js +2 -0
  145. package/dist/runtime/pm/features/Blocks/utils/createItemMenuCommandExecuter.d.ts +3 -0
  146. package/dist/runtime/pm/features/Blocks/utils/createItemMenuCommandExecuter.js +24 -0
  147. package/dist/runtime/pm/features/Blocks/utils/fixBlockIds.d.ts +4 -0
  148. package/dist/runtime/pm/features/Blocks/utils/fixBlockIds.js +23 -0
  149. package/dist/runtime/pm/features/Blocks/utils/isValidId.d.ts +2 -0
  150. package/dist/runtime/pm/features/Blocks/utils/isValidId.js +7 -0
  151. package/dist/runtime/pm/features/CodeBlock/CodeBlock.d.ts +16 -0
  152. package/dist/runtime/pm/features/CodeBlock/CodeBlock.js +91 -0
  153. package/dist/runtime/pm/features/CodeBlock/build/generateHighlightJsInfo.d.ts +1 -0
  154. package/dist/runtime/pm/features/CodeBlock/build/generateHighlightJsInfo.js +63 -0
  155. package/dist/runtime/pm/features/CodeBlock/commands/codeBlockEnterOrSplit.d.ts +9 -0
  156. package/dist/runtime/pm/features/CodeBlock/commands/codeBlockEnterOrSplit.js +28 -0
  157. package/dist/runtime/pm/features/CodeBlock/commands/codeBlockIndent.d.ts +9 -0
  158. package/dist/runtime/pm/features/CodeBlock/commands/codeBlockIndent.js +39 -0
  159. package/dist/runtime/pm/features/CodeBlock/commands/codeBlockUnindent.d.ts +9 -0
  160. package/dist/runtime/pm/features/CodeBlock/commands/codeBlockUnindent.js +50 -0
  161. package/dist/runtime/pm/features/CodeBlock/commands/focusCodeBlockLanguage.d.ts +9 -0
  162. package/dist/runtime/pm/features/CodeBlock/commands/focusCodeBlockLanguage.js +27 -0
  163. package/dist/runtime/pm/features/CodeBlock/components/CodeBlockView.d.vue.ts +92 -0
  164. package/dist/runtime/pm/features/CodeBlock/components/CodeBlockView.vue +112 -0
  165. package/dist/runtime/pm/features/CodeBlock/components/CodeBlockView.vue.d.ts +92 -0
  166. package/dist/runtime/pm/features/CodeBlock/composables/useAsyncCodeBlockHighlighting.d.ts +28 -0
  167. package/dist/runtime/pm/features/CodeBlock/composables/useAsyncCodeBlockHighlighting.js +137 -0
  168. package/dist/runtime/pm/features/CodeBlock/composables/useHighlightJsTheme.d.ts +37 -0
  169. package/dist/runtime/pm/features/CodeBlock/composables/useHighlightJsTheme.js +101 -0
  170. package/dist/runtime/pm/features/CodeBlock/highlightJsInfo.d.ts +17 -0
  171. package/dist/runtime/pm/features/CodeBlock/highlightJsInfo.js +711 -0
  172. package/dist/runtime/pm/features/CodeBlock/types.d.ts +4 -0
  173. package/dist/runtime/pm/features/CodeBlock/types.js +2 -0
  174. package/dist/runtime/pm/features/Collaboration/Collaboration.d.ts +66 -0
  175. package/dist/runtime/pm/features/Collaboration/Collaboration.js +169 -0
  176. package/dist/runtime/pm/features/CommandsMenus/CommandBar.d.ts +19 -0
  177. package/dist/runtime/pm/features/CommandsMenus/CommandBar.js +97 -0
  178. package/dist/runtime/pm/features/CommandsMenus/commandBarMenuItems.d.ts +20 -0
  179. package/dist/runtime/pm/features/CommandsMenus/commandBarMenuItems.js +188 -0
  180. package/dist/runtime/pm/features/CommandsMenus/components/CommandBar.d.vue.ts +8 -0
  181. package/dist/runtime/pm/features/CommandsMenus/components/CommandBar.vue +58 -0
  182. package/dist/runtime/pm/features/CommandsMenus/components/CommandBar.vue.d.ts +8 -0
  183. package/dist/runtime/pm/features/CommandsMenus/components/CommandBarItem.d.vue.ts +12 -0
  184. package/dist/runtime/pm/features/CommandsMenus/components/CommandBarItem.vue +42 -0
  185. package/dist/runtime/pm/features/CommandsMenus/components/CommandBarItem.vue.d.ts +12 -0
  186. package/dist/runtime/pm/features/CommandsMenus/components/CommandMenuGroup.d.vue.ts +10 -0
  187. package/dist/runtime/pm/features/CommandsMenus/components/CommandMenuGroup.vue +55 -0
  188. package/dist/runtime/pm/features/CommandsMenus/components/CommandMenuGroup.vue.d.ts +10 -0
  189. package/dist/runtime/pm/features/CommandsMenus/components/CommandMenuItem.d.vue.ts +11 -0
  190. package/dist/runtime/pm/features/CommandsMenus/components/CommandMenuItem.vue +58 -0
  191. package/dist/runtime/pm/features/CommandsMenus/components/CommandMenuItem.vue.d.ts +11 -0
  192. package/dist/runtime/pm/features/CommandsMenus/components/CommandMenuList.d.vue.ts +11 -0
  193. package/dist/runtime/pm/features/CommandsMenus/components/CommandMenuList.vue +54 -0
  194. package/dist/runtime/pm/features/CommandsMenus/components/CommandMenuList.vue.d.ts +11 -0
  195. package/dist/runtime/pm/features/CommandsMenus/components/TextIcon.d.vue.ts +5 -0
  196. package/dist/runtime/pm/features/CommandsMenus/components/TextIcon.vue +13 -0
  197. package/dist/runtime/pm/features/CommandsMenus/components/TextIcon.vue.d.ts +5 -0
  198. package/dist/runtime/pm/features/CommandsMenus/icons/HighlightIcon.d.vue.ts +8 -0
  199. package/dist/runtime/pm/features/CommandsMenus/icons/HighlightIcon.vue +45 -0
  200. package/dist/runtime/pm/features/CommandsMenus/icons/HighlightIcon.vue.d.ts +8 -0
  201. package/dist/runtime/pm/features/CommandsMenus/icons/SubscriptIcon.d.vue.ts +2 -0
  202. package/dist/runtime/pm/features/CommandsMenus/icons/SubscriptIcon.vue +5 -0
  203. package/dist/runtime/pm/features/CommandsMenus/icons/SubscriptIcon.vue.d.ts +2 -0
  204. package/dist/runtime/pm/features/CommandsMenus/icons/SuperscriptIcon.d.vue.ts +2 -0
  205. package/dist/runtime/pm/features/CommandsMenus/icons/SuperscriptIcon.vue +5 -0
  206. package/dist/runtime/pm/features/CommandsMenus/icons/SuperscriptIcon.vue.d.ts +2 -0
  207. package/dist/runtime/pm/features/CommandsMenus/types.d.ts +61 -0
  208. package/dist/runtime/pm/features/CommandsMenus/types.js +5 -0
  209. package/dist/runtime/pm/features/CommandsMenus/utils/defaultCommandExecutor.d.ts +3 -0
  210. package/dist/runtime/pm/features/CommandsMenus/utils/defaultCommandExecutor.js +11 -0
  211. package/dist/runtime/pm/features/CommandsMenus/utils/findCommand.d.ts +10 -0
  212. package/dist/runtime/pm/features/CommandsMenus/utils/findCommand.js +16 -0
  213. package/dist/runtime/pm/features/CommandsMenus/utils/popupPositionModifier.d.ts +5 -0
  214. package/dist/runtime/pm/features/CommandsMenus/utils/popupPositionModifier.js +9 -0
  215. package/dist/runtime/pm/features/CommandsMenus/utils/popupVerticalPositioner.d.ts +5 -0
  216. package/dist/runtime/pm/features/CommandsMenus/utils/popupVerticalPositioner.js +11 -0
  217. package/dist/runtime/pm/features/Document/Document.d.ts +3 -0
  218. package/dist/runtime/pm/features/Document/Document.js +6 -0
  219. package/dist/runtime/pm/features/DocumentApi/DocumentApi.d.ts +86 -0
  220. package/dist/runtime/pm/features/DocumentApi/DocumentApi.js +170 -0
  221. package/dist/runtime/pm/features/DocumentApi/composables/useEditorContent.d.ts +13 -0
  222. package/dist/runtime/pm/features/DocumentApi/composables/useEditorContent.js +76 -0
  223. package/dist/runtime/pm/features/DocumentApi/composables/useTestDocumentApi.d.ts +23 -0
  224. package/dist/runtime/pm/features/DocumentApi/composables/useTestDocumentApi.js +70 -0
  225. package/dist/runtime/pm/features/DocumentApi/types.d.ts +133 -0
  226. package/dist/runtime/pm/features/DocumentApi/types.js +1 -0
  227. package/dist/runtime/pm/features/DocumentApi/utils/convertFullTransactionForPartialState.d.ts +3 -0
  228. package/dist/runtime/pm/features/DocumentApi/utils/convertFullTransactionForPartialState.js +37 -0
  229. package/dist/runtime/pm/features/DocumentApi/utils/convertTrForInstance.d.ts +4 -0
  230. package/dist/runtime/pm/features/DocumentApi/utils/convertTrForInstance.js +13 -0
  231. package/dist/runtime/pm/features/DocumentApi/utils/convertTransactionForFullState.d.ts +2 -0
  232. package/dist/runtime/pm/features/DocumentApi/utils/convertTransactionForFullState.js +22 -0
  233. package/dist/runtime/pm/features/DocumentApi/utils/copyMeta.d.ts +2 -0
  234. package/dist/runtime/pm/features/DocumentApi/utils/copyMeta.js +6 -0
  235. package/dist/runtime/pm/features/DocumentApi/utils/getEmbedJson.d.ts +1 -0
  236. package/dist/runtime/pm/features/DocumentApi/utils/getEmbedJson.js +14 -0
  237. package/dist/runtime/pm/features/DocumentApi/utils/getEmbedNodeFromDoc.d.ts +1 -0
  238. package/dist/runtime/pm/features/DocumentApi/utils/getEmbedNodeFromDoc.js +14 -0
  239. package/dist/runtime/pm/features/DocumentApi/utils/getStateEmbedRange.d.ts +9 -0
  240. package/dist/runtime/pm/features/DocumentApi/utils/getStateEmbedRange.js +19 -0
  241. package/dist/runtime/pm/features/DocumentApi/utils/isEmbedId.d.ts +2 -0
  242. package/dist/runtime/pm/features/DocumentApi/utils/isEmbedId.js +3 -0
  243. package/dist/runtime/pm/features/EmbeddedDocument/Embedded.d.ts +24 -0
  244. package/dist/runtime/pm/features/EmbeddedDocument/Embedded.js +73 -0
  245. package/dist/runtime/pm/features/EmbeddedDocument/EmbeddedDocument.d.ts +23 -0
  246. package/dist/runtime/pm/features/EmbeddedDocument/EmbeddedDocument.js +70 -0
  247. package/dist/runtime/pm/features/EmbeddedDocument/components/EmbeddedDocumentPicker.d.vue.ts +14 -0
  248. package/dist/runtime/pm/features/EmbeddedDocument/components/EmbeddedDocumentPicker.vue +169 -0
  249. package/dist/runtime/pm/features/EmbeddedDocument/components/EmbeddedDocumentPicker.vue.d.ts +14 -0
  250. package/dist/runtime/pm/features/EmbeddedDocument/components/EmbeddedNodeView.d.vue.ts +92 -0
  251. package/dist/runtime/pm/features/EmbeddedDocument/components/EmbeddedNodeView.vue +170 -0
  252. package/dist/runtime/pm/features/EmbeddedDocument/components/EmbeddedNodeView.vue.d.ts +92 -0
  253. package/dist/runtime/pm/features/EmbeddedDocument/composables/useEmbeddedEditor.d.ts +31 -0
  254. package/dist/runtime/pm/features/EmbeddedDocument/composables/useEmbeddedEditor.js +199 -0
  255. package/dist/runtime/pm/features/EmbeddedDocument/types.d.ts +49 -0
  256. package/dist/runtime/pm/features/EmbeddedDocument/types.js +6 -0
  257. package/dist/runtime/pm/features/EmbeddedDocument/utils/isEmbeddedBlock.d.ts +9 -0
  258. package/dist/runtime/pm/features/EmbeddedDocument/utils/isEmbeddedBlock.js +3 -0
  259. package/dist/runtime/pm/features/EmbeddedDocument/utils/redirectFromEmbedded.d.ts +28 -0
  260. package/dist/runtime/pm/features/EmbeddedDocument/utils/redirectFromEmbedded.js +17 -0
  261. package/dist/runtime/pm/features/FileLoader/FileLoader.d.ts +16 -0
  262. package/dist/runtime/pm/features/FileLoader/FileLoader.js +99 -0
  263. package/dist/runtime/pm/features/FileLoader/FileLoaderHandler/FileLoaderHandler.d.ts +28 -0
  264. package/dist/runtime/pm/features/FileLoader/FileLoaderHandler/FileLoaderHandler.js +69 -0
  265. package/dist/runtime/pm/features/FileLoader/FileLoaderHandler/TestFileLoaderHandler.d.ts +11 -0
  266. package/dist/runtime/pm/features/FileLoader/FileLoaderHandler/TestFileLoaderHandler.js +49 -0
  267. package/dist/runtime/pm/features/FileLoader/commands/insertFile.d.ts +17 -0
  268. package/dist/runtime/pm/features/FileLoader/commands/insertFile.js +39 -0
  269. package/dist/runtime/pm/features/FileLoader/components/FileLoaderNodeView.d.vue.ts +92 -0
  270. package/dist/runtime/pm/features/FileLoader/components/FileLoaderNodeView.vue +38 -0
  271. package/dist/runtime/pm/features/FileLoader/components/FileLoaderNodeView.vue.d.ts +92 -0
  272. package/dist/runtime/pm/features/FileLoader/plugins/fileLoaderPlugin.d.ts +5 -0
  273. package/dist/runtime/pm/features/FileLoader/plugins/fileLoaderPlugin.js +61 -0
  274. package/dist/runtime/pm/features/FileLoader/types.d.ts +73 -0
  275. package/dist/runtime/pm/features/FileLoader/types.js +0 -0
  276. package/dist/runtime/pm/features/FileLoader/utils/cleanupFileLoaderNode.d.ts +4 -0
  277. package/dist/runtime/pm/features/FileLoader/utils/cleanupFileLoaderNode.js +27 -0
  278. package/dist/runtime/pm/features/FileLoader/utils/cleanupFileLoaderNodes.d.ts +9 -0
  279. package/dist/runtime/pm/features/FileLoader/utils/cleanupFileLoaderNodes.js +22 -0
  280. package/dist/runtime/pm/features/FileLoader/utils/findLoadingNodePos.d.ts +2 -0
  281. package/dist/runtime/pm/features/FileLoader/utils/findLoadingNodePos.js +11 -0
  282. package/dist/runtime/pm/features/FileLoader/utils/optionsCheck.d.ts +3 -0
  283. package/dist/runtime/pm/features/FileLoader/utils/optionsCheck.js +8 -0
  284. package/dist/runtime/pm/features/FileLoader/utils/readAsDataUrl.d.ts +1 -0
  285. package/dist/runtime/pm/features/FileLoader/utils/readAsDataUrl.js +12 -0
  286. package/dist/runtime/pm/features/HardBreak/HardBreak.d.ts +5 -0
  287. package/dist/runtime/pm/features/HardBreak/HardBreak.js +14 -0
  288. package/dist/runtime/pm/features/Heading/Heading.d.ts +24 -0
  289. package/dist/runtime/pm/features/Heading/Heading.js +85 -0
  290. package/dist/runtime/pm/features/Heading/commands/changeLevelAttr.d.ts +16 -0
  291. package/dist/runtime/pm/features/Heading/commands/changeLevelAttr.js +33 -0
  292. package/dist/runtime/pm/features/Heading/types.d.ts +14 -0
  293. package/dist/runtime/pm/features/Heading/types.js +0 -0
  294. package/dist/runtime/pm/features/Highlight/Highlight.d.ts +72 -0
  295. package/dist/runtime/pm/features/Highlight/Highlight.js +163 -0
  296. package/dist/runtime/pm/features/Highlight/retyped/tiptapHighlight.d.ts +3 -0
  297. package/dist/runtime/pm/features/Highlight/retyped/tiptapHighlight.js +5 -0
  298. package/dist/runtime/pm/features/Highlight/types.d.ts +27 -0
  299. package/dist/runtime/pm/features/Highlight/types.js +2 -0
  300. package/dist/runtime/pm/features/History/History.d.ts +35 -0
  301. package/dist/runtime/pm/features/History/History.js +63 -0
  302. package/dist/runtime/pm/features/Iframe/Iframe.d.ts +21 -0
  303. package/dist/runtime/pm/features/Iframe/Iframe.js +127 -0
  304. package/dist/runtime/pm/features/Iframe/IframeParsers.d.ts +37 -0
  305. package/dist/runtime/pm/features/Iframe/IframeParsers.js +88 -0
  306. package/dist/runtime/pm/features/Iframe/components/IframeNodeView.d.vue.ts +92 -0
  307. package/dist/runtime/pm/features/Iframe/components/IframeNodeView.vue +79 -0
  308. package/dist/runtime/pm/features/Iframe/components/IframeNodeView.vue.d.ts +92 -0
  309. package/dist/runtime/pm/features/Iframe/types.d.ts +5 -0
  310. package/dist/runtime/pm/features/Iframe/types.js +0 -0
  311. package/dist/runtime/pm/features/Image/Image.d.ts +2 -0
  312. package/dist/runtime/pm/features/Image/Image.js +13 -0
  313. package/dist/runtime/pm/features/Link/Link.d.ts +38 -0
  314. package/dist/runtime/pm/features/Link/Link.js +241 -0
  315. package/dist/runtime/pm/features/Link/components/BubbleMenuExternalLink.d.vue.ts +28 -0
  316. package/dist/runtime/pm/features/Link/components/BubbleMenuExternalLink.vue +113 -0
  317. package/dist/runtime/pm/features/Link/components/BubbleMenuExternalLink.vue.d.ts +28 -0
  318. package/dist/runtime/pm/features/Link/components/BubbleMenuInternalLink.d.vue.ts +29 -0
  319. package/dist/runtime/pm/features/Link/components/BubbleMenuInternalLink.vue +104 -0
  320. package/dist/runtime/pm/features/Link/components/BubbleMenuInternalLink.vue.d.ts +29 -0
  321. package/dist/runtime/pm/features/Link/components/BubbleMenuLink.d.vue.ts +11 -0
  322. package/dist/runtime/pm/features/Link/components/BubbleMenuLink.vue +126 -0
  323. package/dist/runtime/pm/features/Link/components/BubbleMenuLink.vue.d.ts +11 -0
  324. package/dist/runtime/pm/features/Link/components/BubbleMenuLinkActions.d.vue.ts +18 -0
  325. package/dist/runtime/pm/features/Link/components/BubbleMenuLinkActions.vue +54 -0
  326. package/dist/runtime/pm/features/Link/components/BubbleMenuLinkActions.vue.d.ts +18 -0
  327. package/dist/runtime/pm/features/Link/types.d.ts +44 -0
  328. package/dist/runtime/pm/features/Link/types.js +3 -0
  329. package/dist/runtime/pm/features/Menus/Menus.d.ts +45 -0
  330. package/dist/runtime/pm/features/Menus/Menus.js +142 -0
  331. package/dist/runtime/pm/features/Menus/components/MarkMenuManager.d.vue.ts +6 -0
  332. package/dist/runtime/pm/features/Menus/components/MarkMenuManager.vue +165 -0
  333. package/dist/runtime/pm/features/Menus/components/MarkMenuManager.vue.d.ts +6 -0
  334. package/dist/runtime/pm/features/Menus/types.d.ts +51 -0
  335. package/dist/runtime/pm/features/Menus/types.js +3 -0
  336. package/dist/runtime/pm/features/Menus/utils/isMarkMenu.d.ts +2 -0
  337. package/dist/runtime/pm/features/Menus/utils/isMarkMenu.js +3 -0
  338. package/dist/runtime/pm/features/Tables/commands/tableEnter.d.ts +15 -0
  339. package/dist/runtime/pm/features/Tables/commands/tableEnter.js +19 -0
  340. package/dist/runtime/pm/features/Tables/index.d.ts +9 -0
  341. package/dist/runtime/pm/features/Tables/index.js +44 -0
  342. package/dist/runtime/pm/generator.d.ts +82 -0
  343. package/dist/runtime/pm/generator.js +205 -0
  344. package/dist/runtime/pm/schema.d.ts +4 -0
  345. package/dist/runtime/pm/schema.js +80 -0
  346. package/dist/runtime/pm/testSchema.d.ts +5 -0
  347. package/dist/runtime/pm/testSchema.js +30 -0
  348. package/dist/runtime/pm/utils/createDropIndicator.d.ts +23 -0
  349. package/dist/runtime/pm/utils/createDropIndicator.js +36 -0
  350. package/dist/runtime/pm/utils/createStateOnlyPluginApply.d.ts +2 -0
  351. package/dist/runtime/pm/utils/createStateOnlyPluginApply.js +9 -0
  352. package/dist/runtime/pm/utils/createStateOnlyPluginObjApply.d.ts +2 -0
  353. package/dist/runtime/pm/utils/createStateOnlyPluginObjApply.js +14 -0
  354. package/dist/runtime/pm/utils/dropPointInfo.d.ts +56 -0
  355. package/dist/runtime/pm/utils/dropPointInfo.js +28 -0
  356. package/dist/runtime/pm/utils/findUpwards.d.ts +20 -0
  357. package/dist/runtime/pm/utils/findUpwards.js +18 -0
  358. package/dist/runtime/pm/utils/generateRandomDoc.d.ts +23 -0
  359. package/dist/runtime/pm/utils/generateRandomDoc.js +83 -0
  360. package/dist/runtime/pm/utils/generateRandomTree.d.ts +50 -0
  361. package/dist/runtime/pm/utils/generateRandomTree.js +38 -0
  362. package/dist/runtime/pm/utils/getChildChunks.d.ts +3 -0
  363. package/dist/runtime/pm/utils/getChildChunks.js +15 -0
  364. package/dist/runtime/pm/utils/getDiffReplacementRange.d.ts +20 -0
  365. package/dist/runtime/pm/utils/getDiffReplacementRange.js +9 -0
  366. package/dist/runtime/pm/utils/getElMaxVisualSize.d.ts +9 -0
  367. package/dist/runtime/pm/utils/getElMaxVisualSize.js +7 -0
  368. package/dist/runtime/pm/utils/getElPropertyAsInt.d.ts +4 -0
  369. package/dist/runtime/pm/utils/getElPropertyAsInt.js +8 -0
  370. package/dist/runtime/pm/utils/getGroupNodeNames.d.ts +2 -0
  371. package/dist/runtime/pm/utils/getGroupNodeNames.js +7 -0
  372. package/dist/runtime/pm/utils/getMarkPosition.d.ts +11 -0
  373. package/dist/runtime/pm/utils/getMarkPosition.js +34 -0
  374. package/dist/runtime/pm/utils/getMarksInSelection.d.ts +3 -0
  375. package/dist/runtime/pm/utils/getMarksInSelection.js +16 -0
  376. package/dist/runtime/pm/utils/getTypeByName.d.ts +2 -0
  377. package/dist/runtime/pm/utils/getTypeByName.js +5 -0
  378. package/dist/runtime/pm/utils/index.d.ts +15 -0
  379. package/dist/runtime/pm/utils/index.js +15 -0
  380. package/dist/runtime/pm/utils/internal/createNodeTypesList.d.ts +2 -0
  381. package/dist/runtime/pm/utils/internal/createNodeTypesList.js +17 -0
  382. package/dist/runtime/pm/utils/internal/debugMap.d.ts +7 -0
  383. package/dist/runtime/pm/utils/internal/debugMap.js +24 -0
  384. package/dist/runtime/pm/utils/internal/debugNode.d.ts +2 -0
  385. package/dist/runtime/pm/utils/internal/debugNode.js +18 -0
  386. package/dist/runtime/pm/utils/internal/debugSel.d.ts +5 -0
  387. package/dist/runtime/pm/utils/internal/debugSel.js +8 -0
  388. package/dist/runtime/pm/utils/internal/recurse.d.ts +2 -0
  389. package/dist/runtime/pm/utils/internal/recurse.js +39 -0
  390. package/dist/runtime/pm/utils/internal/stripBlockId.d.ts +2 -0
  391. package/dist/runtime/pm/utils/internal/stripBlockId.js +9 -0
  392. package/dist/runtime/pm/utils/mapSelection.d.ts +8 -0
  393. package/dist/runtime/pm/utils/mapSelection.js +12 -0
  394. package/dist/runtime/pm/utils/nodesBetween.d.ts +21 -0
  395. package/dist/runtime/pm/utils/nodesBetween.js +21 -0
  396. package/dist/runtime/pm/utils/pointToPmPoint.d.ts +2 -0
  397. package/dist/runtime/pm/utils/pointToPmPoint.js +3 -0
  398. package/dist/runtime/pm/utils/splitIntoChunks.d.ts +32 -0
  399. package/dist/runtime/pm/utils/splitIntoChunks.js +31 -0
  400. package/dist/runtime/testDocuments.d.ts +53 -0
  401. package/dist/runtime/testDocuments.js +122 -0
  402. package/dist/runtime/types/index.d.ts +53 -0
  403. package/dist/runtime/types/index.js +9 -0
  404. package/dist/types.d.mts +2 -12
  405. package/package.json +11 -9
  406. package/src/runtime/pm/commands/changeAttrs.ts +1 -1
  407. package/src/runtime/pm/features/Blocks/Item.ts +1 -1
  408. package/src/runtime/pm/features/Blocks/commands/moveItem.ts +1 -1
  409. package/src/runtime/pm/features/Blocks/components/DragTreeHandle.vue +14 -9
  410. package/src/runtime/pm/features/EmbeddedDocument/Embedded.ts +1 -1
  411. package/src/runtime/pm/features/FileLoader/types.ts +2 -2
  412. package/src/runtime/pm/generator.ts +266 -0
  413. package/src/runtime/pm/schema.ts +1 -0
  414. package/src/runtime/pm/utils/generateRandomDoc.ts +140 -0
  415. package/src/runtime/pm/utils/generateRandomTree.ts +100 -0
  416. package/dist/module.d.cts +0 -2
@@ -0,0 +1,170 @@
1
+ import { debounce } from "@alanscodelog/utils/debounce";
2
+ import { unreachable } from "@alanscodelog/utils/unreachable";
3
+ import { Editor } from "@tiptap/vue-3";
4
+ import { isProxy } from "vue";
5
+ import { convertTransactionForFullState } from "./utils/convertTransactionForFullState.js";
6
+ import { getEmbedJson } from "./utils/getEmbedJson.js";
7
+ import { getEmbedNodeFromDoc } from "./utils/getEmbedNodeFromDoc.js";
8
+ export class DocumentApi {
9
+ _callbacks = { update: [], saved: [], saving: [] };
10
+ _load;
11
+ _save;
12
+ _saveQueue = {};
13
+ save;
14
+ _cache;
15
+ /**
16
+ * The refCounter is called every time an editor loads or unloads a document. It's used to keep track of the number of editors that are using a document, and to unload it when no editors are using it.
17
+ *
18
+ * Note that you need not immediately unload the cached document. So long as the count is immediatly updated you can set a timeout to actually delete the cache entry (be sure to check the count it still 0 and you can delete it).
19
+ */
20
+ _refCounter;
21
+ getSuggestions;
22
+ getEmbedTitle;
23
+ postEditorInit;
24
+ // editor + updateState does not work :/
25
+ preEditorInit = (_docId, options, state) => {
26
+ options.content = state.doc.toJSON();
27
+ return options;
28
+ };
29
+ updateFilter = () => true;
30
+ editor;
31
+ constructor({
32
+ editorOptions,
33
+ getTitle,
34
+ getSuggestions,
35
+ load,
36
+ save,
37
+ saveDebounce = 1e3,
38
+ cache,
39
+ refCounter,
40
+ postEditorInit,
41
+ preEditorInit,
42
+ updateFilter
43
+ }) {
44
+ this.updateFilter = updateFilter;
45
+ this.getEmbedTitle = getTitle ? ({ docId, blockId }) => getTitle(docId, blockId) : ({ docId, blockId }) => `${docId}${blockId ? `#${blockId}` : ""}`;
46
+ this._load = load;
47
+ this._cache = cache;
48
+ this._refCounter = refCounter;
49
+ this._save = save;
50
+ const debouncedSave = debounce(this._saveDocument.bind(this), saveDebounce, {
51
+ queue: this._saveQueue,
52
+ // even though save is async, promisified debounce is slightly more expensive because it creates a new function with every call
53
+ // and we don't really need that
54
+ promisify: false
55
+ });
56
+ this.save = function save2(docId) {
57
+ for (const cb of this._callbacks.saving) {
58
+ cb(docId);
59
+ }
60
+ debouncedSave(docId);
61
+ };
62
+ this.postEditorInit = postEditorInit ?? (() => {
63
+ });
64
+ if (preEditorInit) this.preEditorInit = preEditorInit;
65
+ this.getSuggestions = getSuggestions;
66
+ this.editor = new Editor({
67
+ ...editorOptions,
68
+ extensions: [...editorOptions.extensions],
69
+ injectCSS: false
70
+ });
71
+ }
72
+ // eslint-disable-next-line @typescript-eslint/naming-convention
73
+ async _saveDocument(docId) {
74
+ if (this._save) {
75
+ await this._save(docId);
76
+ for (const cb of this._callbacks.saved) {
77
+ cb(docId);
78
+ }
79
+ } else {
80
+ console.warn("No save function provided, ignoring save request.");
81
+ }
82
+ }
83
+ updateDocument(embedId, tr, updaterSymbol) {
84
+ if (this.updateFilter && this.updateFilter(tr) === false) return;
85
+ const stateBefore = this.getFromCache(embedId, { errorIfNotFound: true });
86
+ const modifiedTr = convertTransactionForFullState(stateBefore, tr);
87
+ const newState = stateBefore.apply(modifiedTr);
88
+ this._cache.set(embedId.docId, newState);
89
+ for (const cb of this._callbacks.update) {
90
+ cb(embedId, modifiedTr, stateBefore, newState, updaterSymbol);
91
+ }
92
+ }
93
+ addEventListener(type, cb) {
94
+ this._callbacks[type].push(cb);
95
+ }
96
+ removeEventListener(type, cb) {
97
+ const cbIndex = this._callbacks[type].indexOf(cb);
98
+ if (cbIndex === -1) {
99
+ throw new Error("Tried to remove a callback that was not registered.");
100
+ }
101
+ this._callbacks[type].splice(cbIndex, 1);
102
+ }
103
+ unload({ docId }) {
104
+ this._refCounter.unload(docId);
105
+ }
106
+ _loading = {};
107
+ async load({ docId }) {
108
+ this._loading[docId] ??= this._loadInternal({ docId });
109
+ const res = await this._loading[docId];
110
+ if (res === void 0) unreachable();
111
+ this._loading[docId] = void 0;
112
+ this._refCounter.load(docId, res);
113
+ if (isProxy(res.state)) {
114
+ throw new Error("State cannot be a reactive proxy. You can use toRaw as a temporary workaround but you should ideally not make it reactive");
115
+ }
116
+ this._cache.set(docId, res.state);
117
+ return res;
118
+ }
119
+ async _loadInternal({ docId }) {
120
+ const cachedState = this.getFromCache({ docId }, { errorIfNotFound: false });
121
+ if (isProxy(cachedState)) {
122
+ throw new Error("State cannot be a reactive proxy. You can use toRaw as a temporary workaround but you should ideally not make it reactive");
123
+ }
124
+ if (cachedState) {
125
+ const res = { state: cachedState };
126
+ this._refCounter.load(docId, res);
127
+ return res;
128
+ }
129
+ const schema = this.editor.schema;
130
+ const loaded = await this._load(
131
+ docId,
132
+ schema,
133
+ [...this.editor.extensionManager.plugins]
134
+ );
135
+ let state = loaded.state;
136
+ const tr = state.tr;
137
+ tr.setMeta("addToHistory", false);
138
+ for (const plugin of state.plugins) {
139
+ if (plugin.spec.stateInit) {
140
+ plugin.spec.stateInit(tr);
141
+ }
142
+ }
143
+ state = state.apply(tr);
144
+ return { data: loaded.data, state };
145
+ }
146
+ getFullState(docId) {
147
+ return this.getFromCache(docId, { errorIfNotFound: true });
148
+ }
149
+ getFromCache({ docId }, options) {
150
+ const cached = this._cache.get(docId);
151
+ if (cached) return cached;
152
+ if (options?.errorIfNotFound) {
153
+ throw new Error(`Could not find cached state for document ${docId}. Expected document to be loaded.`);
154
+ }
155
+ if (isProxy(cached)) {
156
+ throw new Error("State cannot be a reactive proxy. You can use toRaw as a temporary workaround but you should ideally not make it reactive");
157
+ }
158
+ return void 0;
159
+ }
160
+ getEmbeddedContent(embedId) {
161
+ const state = this.getFullState(embedId);
162
+ const json = state.doc.toJSON();
163
+ const nodeWanted = getEmbedNodeFromDoc(json, embedId.blockId);
164
+ if (embedId.blockId && !nodeWanted) {
165
+ return void 0;
166
+ } else {
167
+ return getEmbedJson(nodeWanted) ?? json;
168
+ }
169
+ }
170
+ }
@@ -0,0 +1,13 @@
1
+ import type { Content, Editor, EditorOptions } from "@tiptap/core";
2
+ import { type Ref, type ShallowRef } from "vue";
3
+ import type { DocumentApiInterface } from "../types.js";
4
+ /**
5
+ * Provides two ways to load content into the editor.
6
+ *
7
+ * The simple one, which is just to provide a content ref.
8
+ *
9
+ * And the more advanced one which uses the document api to load the content. This requires passing the embed api and an id to load.
10
+ *
11
+ * The second option is usually the best, as multiple editors can load the same content and it's automatically kept in sync. See {@link DocumentApi} for more info.
12
+ */
13
+ export declare function useEditorContent(editor: ShallowRef<Editor | undefined>, content: Ref<Content | undefined>, id: Ref<string | undefined>, documentApi: DocumentApiInterface | undefined, recreate: (modifyOptions?: (options: Partial<EditorOptions>) => Partial<EditorOptions>) => void): void;
@@ -0,0 +1,76 @@
1
+ import { nextTick, onBeforeUnmount, watch } from "vue";
2
+ import { convertTrForInstance } from "../utils/convertTrForInstance.js";
3
+ export function useEditorContent(editor, content, id, documentApi, recreate) {
4
+ const selfSymbol = Symbol(`self${Math.random()}`);
5
+ function onTransaction({ transaction: tr }) {
6
+ if (!documentApi || !id.value || !tr.docChanged || tr.getMeta("ignore")) {
7
+ return;
8
+ }
9
+ tr.setMeta("no-step-convert", true);
10
+ documentApi.updateDocument({ docId: id.value }, tr, selfSymbol);
11
+ }
12
+ const onUpdateDocument = (embedId, tr, __, ___, symbol) => {
13
+ if (symbol !== selfSymbol && !tr.getMeta("ignore") && tr.docChanged && embedId.docId === id.value) {
14
+ tr.setMeta("ignore", true);
15
+ const convertedTr = convertTrForInstance(
16
+ tr,
17
+ editor.value.state
18
+ );
19
+ editor.value?.view.dispatch(convertedTr);
20
+ }
21
+ if (tr.docChanged) {
22
+ void documentApi?.save(embedId.docId);
23
+ }
24
+ };
25
+ let attached = false;
26
+ async function load(changed) {
27
+ if (content.value) {
28
+ editor.value?.commands.setContent(content.value);
29
+ } else if (documentApi) {
30
+ if (changed && id.value) {
31
+ await documentApi.load({ docId: id.value });
32
+ const state = documentApi.getFullState({ docId: id.value });
33
+ recreate((options) => documentApi.preEditorInit?.(id.value, { ...options }, state));
34
+ await nextTick(async () => {
35
+ editor.value.on("transaction", onTransaction);
36
+ documentApi.addEventListener("update", onUpdateDocument);
37
+ documentApi.postEditorInit(id.value, editor.value);
38
+ attached = true;
39
+ });
40
+ }
41
+ }
42
+ }
43
+ function unload(oldId) {
44
+ if (oldId !== void 0 && documentApi) {
45
+ documentApi.unload({ docId: oldId });
46
+ if (attached) {
47
+ documentApi.removeEventListener("update", onUpdateDocument);
48
+ editor.value?.off("transaction", onTransaction);
49
+ attached = false;
50
+ }
51
+ }
52
+ }
53
+ watch([content, id, editor], async ([_newContent, newId], [_oldContent, oldId]) => {
54
+ if (!editor.value) {
55
+ return;
56
+ }
57
+ if (!content.value && (!id.value || !documentApi)) {
58
+ throw new Error("No content or id and document api provided.");
59
+ }
60
+ if (id.value && !documentApi) {
61
+ throw new Error("Id provided but no document api provided.");
62
+ }
63
+ if (oldId !== void 0 && newId !== oldId && documentApi) {
64
+ unload(oldId);
65
+ await load(true);
66
+ } else if (_newContent) {
67
+ await load(false);
68
+ }
69
+ }, { deep: false });
70
+ void load(true);
71
+ onBeforeUnmount(() => {
72
+ if (id.value) {
73
+ unload(id.value);
74
+ }
75
+ });
76
+ }
@@ -0,0 +1,23 @@
1
+ import type { EditorOptions } from "@tiptap/core";
2
+ import { EditorState } from "@tiptap/pm/state";
3
+ import { type Ref } from "vue";
4
+ import type { DocumentApiInterface } from "../types.js";
5
+ type Cache = Record<string, {
6
+ state?: EditorState;
7
+ count: number;
8
+ }>;
9
+ /** Creates a simple instance of the DocumentApi for testing purposes. */
10
+ export declare function useTestDocumentApi(editorOptions: Partial<EditorOptions>, embeds: Record<string, {
11
+ content: any;
12
+ title?: string;
13
+ }>, { loadDelay }?: {
14
+ loadDelay?: number;
15
+ }): {
16
+ cache: Ref<Cache>;
17
+ documentApi: DocumentApiInterface;
18
+ embeds: Record<string, {
19
+ content: any;
20
+ title?: string;
21
+ }>;
22
+ };
23
+ export {};
@@ -0,0 +1,70 @@
1
+ import { delay } from "@alanscodelog/utils/delay";
2
+ import { keys } from "@alanscodelog/utils/keys";
3
+ import { unreachable } from "@alanscodelog/utils/unreachable";
4
+ import { createDocument, generateJSON } from "@tiptap/core";
5
+ import { EditorState } from "@tiptap/pm/state";
6
+ import { ref, toRaw } from "vue";
7
+ import { testExtensions } from "../../../testSchema.js";
8
+ import { DocumentApi } from "../DocumentApi.js";
9
+ export function useTestDocumentApi(editorOptions, embeds, { loadDelay = 0 } = {}) {
10
+ const cache = ref({});
11
+ const documentApi = new DocumentApi({
12
+ editorOptions,
13
+ getSuggestions: async (searchString) => {
14
+ const res = [];
15
+ for (const docId of keys(embeds)) {
16
+ const title = embeds[docId].title ?? docId;
17
+ if (title.includes(searchString)) {
18
+ res.push({ title, docId });
19
+ }
20
+ }
21
+ if (loadDelay) {
22
+ await delay(loadDelay);
23
+ }
24
+ return res;
25
+ },
26
+ getTitle: (docId, blockId) => (embeds[docId]?.title ?? docId) + (blockId ? `#${blockId}` : ""),
27
+ cache: {
28
+ get(docId) {
29
+ return toRaw(cache.value[docId]?.state);
30
+ },
31
+ set(docId, state) {
32
+ cache.value[docId].state = state;
33
+ }
34
+ },
35
+ load: async (docId, schema, plugins) => {
36
+ if (loadDelay) {
37
+ await delay(loadDelay);
38
+ }
39
+ if (!embeds[docId]) {
40
+ throw new Error(`No embed found for docId ${docId} in: ${JSON.stringify(embeds, null, " ")}`);
41
+ }
42
+ const json = generateJSON(embeds[docId].content, testExtensions);
43
+ const doc = createDocument(json, schema);
44
+ const state = EditorState.create({
45
+ doc,
46
+ schema,
47
+ plugins
48
+ });
49
+ return { state };
50
+ },
51
+ refCounter: {
52
+ load(docId, loaded) {
53
+ cache.value[docId] ??= { ...loaded, count: 0 };
54
+ cache.value[docId].count++;
55
+ },
56
+ unload: (docId) => {
57
+ if (cache.value[docId]) {
58
+ if (cache.value[docId].count === 1) {
59
+ delete cache.value[docId];
60
+ } else {
61
+ cache.value[docId].count--;
62
+ }
63
+ } else {
64
+ unreachable();
65
+ }
66
+ }
67
+ }
68
+ });
69
+ return { documentApi, cache, embeds };
70
+ }
@@ -0,0 +1,133 @@
1
+ import type { Content, Editor, EditorOptions } from "@tiptap/core";
2
+ import type { EditorState, Transaction } from "@tiptap/pm/state";
3
+ import type { InjectionKey } from "vue";
4
+ export declare const documentApiInjectionKey: InjectionKey<DocumentApiInterface>;
5
+ export type DocId = {
6
+ docId: string;
7
+ };
8
+ export type BlockId = {
9
+ blockId?: string;
10
+ };
11
+ /** When the user initially creates an embed, it's docId will be undefined. */
12
+ export type MaybeEmbedId = Partial<DocId> & BlockId;
13
+ export type EmbedId = DocId & BlockId;
14
+ export type OnUpdateDocumentCallback = (embedId: DocId, tr: Transaction, oldEditorState: EditorState, newEditorState: EditorState, selfSymbol?: symbol) => void;
15
+ export type OnSaveDocumentCallback = (docId: string) => void;
16
+ export type DocumentApiInterface<T extends Record<string, any> = Record<string, any>> = {
17
+ /** Debounced save (to storage) function. Use the event listeners to get notified when saving finishes. */
18
+ save: (docId: string) => void;
19
+ getEmbeddedContent: (embedId: EmbedId) => Content | undefined;
20
+ getFromCache: (docId: DocId, options?: {
21
+ errorIfNotFound?: boolean;
22
+ }) => EditorState | undefined;
23
+ /** Load should be called the first time, before attempting to load the state. */
24
+ getFullState: (docId: DocId) => EditorState;
25
+ /** Like {@link DocumentApi.preEditorInit}, but after initializing and loading the document (and before the transaction listeners are added). */
26
+ postEditorInit: (docId: string, editor: Editor) => void;
27
+ /**
28
+ * Sets options before initializing the editor. By default just does `options.content = state.doc.toJSON()`, but can be useful when managing the document state in some other way (e.g. collab.
29
+ *
30
+ * Also useful for creating per-doc instances for certain extensions, such as Collaboration.
31
+ *
32
+ * This is a bit tricky to do normally since the editor component initializes the editor before the document is loaded and is re-used (the wrapper Editor *component*, not the editor) when the document changes.
33
+ *
34
+ * So this hook can be used to add these additional per-doc instances of extensions. Be sure to clone the properties you are modifying. They are only shallow cloned before being passed to the function.
35
+ *
36
+ * ```ts
37
+ * preEditorInit(docId, options: Partial<EditorOptions>, state: EditorState) {
38
+ * // we do not need to set options.content when using collab
39
+ * // so no options.content = state.doc.toJSON()
40
+ * const ydoc = cache.value[docId].ydoc
41
+ * // it's suggested you add the collab extension only here
42
+ * // otherwise you would have to initially configure it with a dummy document
43
+ * const collabExt = Collaboration.configure({
44
+ * document: ydoc
45
+ * }) as any
46
+ * options.extensions = [
47
+ * ...(options.extensions ?? []),
48
+ * collabExt
49
+ * ]
50
+ * return options
51
+ * },
52
+ * load: async (
53
+ * docId: string,
54
+ * schema: Schema,
55
+ * plugins: Plugin[],
56
+ * ) => {
57
+ * if (cache.value[docId]?.state) {
58
+ * return { state: toRaw(cache.value[docId].state) }
59
+ * }
60
+ * const doc = getFromYourDb(docId)
61
+ * const decoded = toUint8Array(doc.contentBinary)
62
+ * const yDoc = new Y.Doc()
63
+ * Y.applyUpdate(yDoc, decoded)
64
+ *
65
+ * const yjs = initProseMirrorDoc(yDoc.getXmlFragment("prosemirror"), schema)
66
+ * const state = EditorState.create({
67
+ * doc: yjs.doc,
68
+ * schema,
69
+ * plugins:[
70
+ * ...plugins,
71
+ * // the document api's yjs instance
72
+ * ySyncPlugin(yDoc.getXmlFragment("prosemirror"), {mapping:yjs.mapping}),
73
+ * ]
74
+ * })
75
+ * // return the state and any additional data we want refCounter.load to be called with.
76
+ * return { state, doc, yDoc }
77
+ * },
78
+ * updateFilter(tr:Transaction) {
79
+ * const meta = tr.getMeta(ySyncPluginKey)
80
+ * if (meta) return false
81
+ * return true
82
+ * },
83
+ * ```
84
+ * See {@link DocumentApi.updateFilter} for why yjs (and other syncronization mechanisms) might need to ignore transactions.
85
+ */
86
+ preEditorInit: (docId: string, options: Partial<EditorOptions>, state: EditorState) => Partial<EditorOptions>;
87
+ /**
88
+ * Return false to ignore the transaction.
89
+ *
90
+ * This is useful when using a secondary syncronization mechanism, such as yjs.
91
+ *
92
+ * If you load all editors of a file with yjs's plugin and point to the same ydoc, yjs's plugin will sync them. But that means that when the DocumentApi tries to sync the transactions they will have already been applied and the document update will fail.
93
+ *
94
+ * So we have to ignore all of yjs's transactions, but NOT transactions from partially embedded docs => full state, as these do not pass through yjs.
95
+ */
96
+ updateFilter?: (tr: Transaction) => boolean | undefined;
97
+ updateDocument: (embedId: DocId, tr: Transaction, selfSymbol?: symbol) => void;
98
+ addEventListener(type: "saving" | "saved", cb: OnSaveDocumentCallback): void;
99
+ addEventListener(type: "update", cb: OnUpdateDocumentCallback): void;
100
+ removeEventListener(type: "saving" | "saved", cb: OnSaveDocumentCallback): void;
101
+ removeEventListener(type: "update", cb: OnUpdateDocumentCallback): void;
102
+ /** For the embedded document picker, should return suggestions for the search string. */
103
+ getSuggestions: (searchString: string) => Promise<{
104
+ title: string;
105
+ docId: string;
106
+ }[]>;
107
+ /** How to format the title of the embedded document. Defaults to docId#blockId */
108
+ getEmbedTitle: (embedId: EmbedId) => string;
109
+ /**
110
+ * Tells the document api how to load an unloaded document and any additional data. Whatever this function returns will be passed to the refCounter.load option in the default DocumentApi implementation.
111
+ *
112
+ * ```ts
113
+ * load: async ( docId: string, schema: Schema, plugins: Plugin[],) => {
114
+ * const dbDoc = getFromYourDb(docId)
115
+ *
116
+ * const state = EditorState.create({
117
+ * doc: yjs.doc,
118
+ * schema,
119
+ * plugins
120
+ * })
121
+ * // return the state and any additional data we want to cache
122
+ * return { state, data: { dbDoc } }
123
+ * },
124
+ * ```
125
+ * See {@link DocumentApi.preEditorInit} for how to set this up with sync (e.g. yjs).
126
+ */
127
+ load: (docId: DocId) => Promise<{
128
+ state: EditorState;
129
+ data?: T;
130
+ }>;
131
+ /** Notifies the document api that an editor has unloaded the document. */
132
+ unload: (docId: DocId) => void;
133
+ };
@@ -0,0 +1 @@
1
+ export const documentApiInjectionKey = Symbol("documentApiInjectionKey");
@@ -0,0 +1,3 @@
1
+ import type { EditorState, Transaction } from "@tiptap/pm/state";
2
+ import type { EmbedId } from "../types.js";
3
+ export declare function convertFullTransactionForPartialState(state: EditorState, tr: Transaction, embedId: EmbedId): Transaction | undefined;
@@ -0,0 +1,37 @@
1
+ import { Step } from "@tiptap/pm/transform";
2
+ import { copyMeta } from "./copyMeta.js";
3
+ import { getStateEmbedRange } from "./getStateEmbedRange.js";
4
+ import { getDiffReplacementRange } from "../../../utils/getDiffReplacementRange.js";
5
+ export function convertFullTransactionForPartialState(state, tr, embedId) {
6
+ const blockId = embedId.blockId;
7
+ if (!blockId) {
8
+ const steps = JSON.parse(
9
+ JSON.stringify(tr.steps)
10
+ ).map((step) => Step.fromJSON(state.schema, step));
11
+ const intTr2 = state.tr;
12
+ copyMeta(tr, intTr2);
13
+ intTr2.setMeta("ignore", true);
14
+ for (const step of steps) {
15
+ intTr2.step(step);
16
+ }
17
+ return intTr2;
18
+ }
19
+ const { start: nodeStartExisting } = getStateEmbedRange(state.doc, embedId);
20
+ const { start: nodeStart } = getStateEmbedRange(
21
+ tr.doc,
22
+ embedId
23
+ );
24
+ if (nodeStart === void 0 || nodeStartExisting === void 0) return void 0;
25
+ const intTr = state.tr;
26
+ copyMeta(tr, intTr);
27
+ intTr.setMeta("ignore", true);
28
+ const existingNode = state.doc.nodeAt(nodeStartExisting);
29
+ const newNode = tr.doc.nodeAt(nodeStart);
30
+ const convertedNewNode = newNode ? state.schema.nodeFromJSON(newNode.toJSON()) : void 0;
31
+ if (!existingNode || !convertedNewNode) return void 0;
32
+ const diff = getDiffReplacementRange(existingNode, convertedNewNode, nodeStartExisting - 1);
33
+ if (diff) {
34
+ intTr.replace(2 + diff.start, 2 + diff.end, convertedNewNode.slice(diff.sliceStart, diff.sliceEnd));
35
+ }
36
+ return intTr;
37
+ }
@@ -0,0 +1,4 @@
1
+ import type { EditorState, Transaction } from "@tiptap/pm/state";
2
+ export declare function convertTrForInstance(tr: Transaction,
3
+ /** We convert to the schema from this state. */
4
+ otherState: EditorState): Transaction;
@@ -0,0 +1,13 @@
1
+ import { Step } from "@tiptap/pm/transform";
2
+ import { copyMeta } from "./copyMeta.js";
3
+ export function convertTrForInstance(tr, otherState) {
4
+ const extTr = otherState.tr;
5
+ copyMeta(tr, extTr);
6
+ const steps = JSON.parse(
7
+ JSON.stringify(tr.steps)
8
+ ).map((step) => Step.fromJSON(otherState.schema, step));
9
+ for (const step of steps) {
10
+ extTr.step(step);
11
+ }
12
+ return extTr;
13
+ }
@@ -0,0 +1,2 @@
1
+ import type { EditorState, Transaction } from "@tiptap/pm/state";
2
+ export declare function convertTransactionForFullState(state: EditorState, tr: Transaction): Transaction;
@@ -0,0 +1,22 @@
1
+ import { unreachable } from "@alanscodelog/utils/unreachable";
2
+ import { Step, StepMap } from "@tiptap/pm/transform";
3
+ import { copyMeta } from "./copyMeta.js";
4
+ import { getStateEmbedRange } from "./getStateEmbedRange.js";
5
+ export function convertTransactionForFullState(state, tr) {
6
+ const steps = tr.getMeta("no-schema-convert") ? tr.steps : JSON.parse(
7
+ JSON.stringify(tr.steps)
8
+ ).map((step) => Step.fromJSON(state.schema, step));
9
+ const extTr = state.tr;
10
+ copyMeta(tr, extTr);
11
+ const trSubId = tr.doc.nodeAt(1)?.attrs.blockId;
12
+ if (!trSubId && !tr.getMeta("no-step-convert")) {
13
+ unreachable();
14
+ }
15
+ const embedRange = trSubId ? getStateEmbedRange(tr.doc, trSubId) : void 0;
16
+ const offsetMap = embedRange && !tr.getMeta("no-step-convert") ? StepMap.offset(embedRange.start !== void 0 ? embedRange.start - 1 : 0) : void 0;
17
+ for (const step of steps) {
18
+ const mapped = offsetMap ? step.map(offsetMap) : step;
19
+ extTr.step(mapped);
20
+ }
21
+ return extTr;
22
+ }
@@ -0,0 +1,2 @@
1
+ import type { Transaction } from "@tiptap/pm/state";
2
+ export declare function copyMeta(from: Transaction, to: Transaction): void;
@@ -0,0 +1,6 @@
1
+ import { keys } from "@alanscodelog/utils/keys";
2
+ export function copyMeta(from, to) {
3
+ for (const key of keys(from.meta)) {
4
+ to.setMeta(key, from.getMeta(key));
5
+ }
6
+ }
@@ -0,0 +1 @@
1
+ export declare function getEmbedJson(nodeWanted: Record<string, any> | undefined): Record<string, any> | undefined;
@@ -0,0 +1,14 @@
1
+ export function getEmbedJson(nodeWanted) {
2
+ if (nodeWanted) {
3
+ return {
4
+ type: "doc",
5
+ content: [
6
+ {
7
+ type: "list",
8
+ content: [nodeWanted]
9
+ }
10
+ ]
11
+ };
12
+ }
13
+ return void 0;
14
+ }
@@ -0,0 +1 @@
1
+ export declare function getEmbedNodeFromDoc(json: Record<string, any>, subId: string | undefined): Record<string, any> | undefined;
@@ -0,0 +1,14 @@
1
+ import { walk } from "@alanscodelog/utils/walk";
2
+ export function getEmbedNodeFromDoc(json, subId) {
3
+ if (!subId) return;
4
+ let nodeWanted;
5
+ walk(json.content, (el) => {
6
+ if (!nodeWanted && el && el.type === "item") {
7
+ if (el.attrs.blockId === subId) {
8
+ nodeWanted = el;
9
+ }
10
+ }
11
+ return el;
12
+ }, { before: true });
13
+ return nodeWanted;
14
+ }
@@ -0,0 +1,9 @@
1
+ import type { Node } from "@tiptap/pm/model";
2
+ import type { BlockId } from "../types.js";
3
+ export declare function getStateEmbedRange(doc: Node, blockId: BlockId): {
4
+ start: number;
5
+ end: number;
6
+ } | {
7
+ start: undefined;
8
+ end: undefined;
9
+ };
@@ -0,0 +1,19 @@
1
+ export function getStateEmbedRange(doc, blockId) {
2
+ const id = blockId.blockId;
3
+ let start;
4
+ let end;
5
+ doc.nodesBetween(0, doc.content.size, (node, pos) => {
6
+ if (start === void 0 && node.type.name === "item" && node.attrs.blockId === id) {
7
+ start = pos;
8
+ end = pos + node.nodeSize;
9
+ return false;
10
+ }
11
+ if (start !== void 0) return false;
12
+ return true;
13
+ });
14
+ if (start === void 0 || end === void 0) {
15
+ return { start: void 0, end: void 0 };
16
+ } else {
17
+ return { start, end };
18
+ }
19
+ }
@@ -0,0 +1,2 @@
1
+ import type { EmbedId, MaybeEmbedId } from "../types.js";
2
+ export declare function isEmbedId(embedId: MaybeEmbedId): embedId is EmbedId;
@@ -0,0 +1,3 @@
1
+ export function isEmbedId(embedId) {
2
+ return embedId.docId !== void 0;
3
+ }