phormat 0.0.5

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 (489) hide show
  1. package/README.md +102 -0
  2. package/dist/assets/example-test.svelte +228 -0
  3. package/dist/debug/JsonDebug.svelte +19 -0
  4. package/dist/debug/JsonDebug.svelte.d.ts +6 -0
  5. package/dist/debug/JsonDebugNode.svelte +138 -0
  6. package/dist/debug/JsonDebugNode.svelte.d.ts +11 -0
  7. package/dist/demo/documentLifecycle.d.ts +57 -0
  8. package/dist/demo/documentLifecycle.js +196 -0
  9. package/dist/demo/index.d.ts +2 -0
  10. package/dist/demo/index.js +2 -0
  11. package/dist/editor/BlockEditor.svelte +112 -0
  12. package/dist/editor/BlockEditor.svelte.d.ts +7 -0
  13. package/dist/editor/BlockRow.svelte +76 -0
  14. package/dist/editor/BlockRow.svelte.d.ts +20 -0
  15. package/dist/editor/Editor.svelte +103 -0
  16. package/dist/editor/Editor.svelte.d.ts +7 -0
  17. package/dist/editor/MarkdownEditor.svelte.d.ts +160 -0
  18. package/dist/editor/MarkdownEditor.svelte.js +1119 -0
  19. package/dist/editor/NestedRowChrome.svelte +160 -0
  20. package/dist/editor/NestedRowChrome.svelte.d.ts +20 -0
  21. package/dist/editor/PhormatEditor.svelte +206 -0
  22. package/dist/editor/PhormatEditor.svelte.d.ts +26 -0
  23. package/dist/editor/RawMarkdownPanel.svelte +39 -0
  24. package/dist/editor/RawMarkdownPanel.svelte.d.ts +6 -0
  25. package/dist/editor/block-specs/BlockSpecMissing.svelte +12 -0
  26. package/dist/editor/block-specs/BlockSpecMissing.svelte.d.ts +7 -0
  27. package/dist/editor/block-specs/blockquote/BlockquoteRenderer.svelte +32 -0
  28. package/dist/editor/block-specs/blockquote/BlockquoteRenderer.svelte.d.ts +21 -0
  29. package/dist/editor/block-specs/blockquote/commands.d.ts +2 -0
  30. package/dist/editor/block-specs/blockquote/commands.js +65 -0
  31. package/dist/editor/block-specs/blockquote/index.d.ts +6 -0
  32. package/dist/editor/block-specs/blockquote/index.js +5 -0
  33. package/dist/editor/block-specs/blockquote/inlineSecondPass.d.ts +6 -0
  34. package/dist/editor/block-specs/blockquote/inlineSecondPass.js +35 -0
  35. package/dist/editor/block-specs/blockquote/parse.d.ts +16 -0
  36. package/dist/editor/block-specs/blockquote/parse.js +188 -0
  37. package/dist/editor/block-specs/blockquote/reconcile.d.ts +2 -0
  38. package/dist/editor/block-specs/blockquote/reconcile.js +9 -0
  39. package/dist/editor/block-specs/blockquote/serialize.d.ts +6 -0
  40. package/dist/editor/block-specs/blockquote/serialize.js +55 -0
  41. package/dist/editor/block-specs/blockquote/types.d.ts +20 -0
  42. package/dist/editor/block-specs/blockquote/types.js +1 -0
  43. package/dist/editor/block-specs/blockquoteSpec.d.ts +4 -0
  44. package/dist/editor/block-specs/blockquoteSpec.js +37 -0
  45. package/dist/editor/block-specs/callout/CalloutRenderer.svelte +38 -0
  46. package/dist/editor/block-specs/callout/CalloutRenderer.svelte.d.ts +21 -0
  47. package/dist/editor/block-specs/callout/CalloutTypeIcon.svelte +14 -0
  48. package/dist/editor/block-specs/callout/CalloutTypeIcon.svelte.d.ts +7 -0
  49. package/dist/editor/block-specs/callout/commands.d.ts +2 -0
  50. package/dist/editor/block-specs/callout/commands.js +65 -0
  51. package/dist/editor/block-specs/callout/icons.d.ts +10 -0
  52. package/dist/editor/block-specs/callout/icons.js +52 -0
  53. package/dist/editor/block-specs/callout/index.d.ts +9 -0
  54. package/dist/editor/block-specs/callout/index.js +7 -0
  55. package/dist/editor/block-specs/callout/inlineSecondPass.d.ts +6 -0
  56. package/dist/editor/block-specs/callout/inlineSecondPass.js +9 -0
  57. package/dist/editor/block-specs/callout/parse.d.ts +9 -0
  58. package/dist/editor/block-specs/callout/parse.js +83 -0
  59. package/dist/editor/block-specs/callout/parseBody.d.ts +6 -0
  60. package/dist/editor/block-specs/callout/parseBody.js +290 -0
  61. package/dist/editor/block-specs/callout/reconcile.d.ts +2 -0
  62. package/dist/editor/block-specs/callout/reconcile.js +8 -0
  63. package/dist/editor/block-specs/callout/serialize.d.ts +5 -0
  64. package/dist/editor/block-specs/callout/serialize.js +65 -0
  65. package/dist/editor/block-specs/callout/types.d.ts +7 -0
  66. package/dist/editor/block-specs/callout/types.js +1 -0
  67. package/dist/editor/block-specs/calloutSpec.d.ts +2 -0
  68. package/dist/editor/block-specs/calloutSpec.js +23 -0
  69. package/dist/editor/block-specs/codeFence/CodeFenceRenderer.svelte +18 -0
  70. package/dist/editor/block-specs/codeFence/CodeFenceRenderer.svelte.d.ts +21 -0
  71. package/dist/editor/block-specs/codeFence/commands.d.ts +2 -0
  72. package/dist/editor/block-specs/codeFence/commands.js +1 -0
  73. package/dist/editor/block-specs/codeFence/index.d.ts +5 -0
  74. package/dist/editor/block-specs/codeFence/index.js +4 -0
  75. package/dist/editor/block-specs/codeFence/inlineSecondPass.d.ts +3 -0
  76. package/dist/editor/block-specs/codeFence/inlineSecondPass.js +5 -0
  77. package/dist/editor/block-specs/codeFence/reconcile.d.ts +2 -0
  78. package/dist/editor/block-specs/codeFence/reconcile.js +5 -0
  79. package/dist/editor/block-specs/codeFence/serialize.d.ts +2 -0
  80. package/dist/editor/block-specs/codeFence/serialize.js +8 -0
  81. package/dist/editor/block-specs/codeFence/types.d.ts +6 -0
  82. package/dist/editor/block-specs/codeFence/types.js +1 -0
  83. package/dist/editor/block-specs/codeFenceSpec.d.ts +2 -0
  84. package/dist/editor/block-specs/codeFenceSpec.js +23 -0
  85. package/dist/editor/block-specs/columns/ColumnsRenderer.svelte +18 -0
  86. package/dist/editor/block-specs/columns/ColumnsRenderer.svelte.d.ts +21 -0
  87. package/dist/editor/block-specs/columns/EditableColumns.svelte +16 -0
  88. package/dist/editor/block-specs/columns/EditableColumns.svelte.d.ts +4 -0
  89. package/dist/editor/block-specs/columns/commands.d.ts +2 -0
  90. package/dist/editor/block-specs/columns/commands.js +1 -0
  91. package/dist/editor/block-specs/columns/index.d.ts +6 -0
  92. package/dist/editor/block-specs/columns/index.js +5 -0
  93. package/dist/editor/block-specs/columns/inlineSecondPass.d.ts +3 -0
  94. package/dist/editor/block-specs/columns/inlineSecondPass.js +5 -0
  95. package/dist/editor/block-specs/columns/parse.d.ts +20 -0
  96. package/dist/editor/block-specs/columns/parse.js +111 -0
  97. package/dist/editor/block-specs/columns/reconcile.d.ts +2 -0
  98. package/dist/editor/block-specs/columns/reconcile.js +6 -0
  99. package/dist/editor/block-specs/columns/serialize.d.ts +2 -0
  100. package/dist/editor/block-specs/columns/serialize.js +16 -0
  101. package/dist/editor/block-specs/columns/types.d.ts +4 -0
  102. package/dist/editor/block-specs/columns/types.js +1 -0
  103. package/dist/editor/block-specs/columnsSpec.d.ts +2 -0
  104. package/dist/editor/block-specs/columnsSpec.js +24 -0
  105. package/dist/editor/block-specs/heading/HeaderRenderer.svelte +30 -0
  106. package/dist/editor/block-specs/heading/HeaderRenderer.svelte.d.ts +21 -0
  107. package/dist/editor/block-specs/heading/commands.d.ts +2 -0
  108. package/dist/editor/block-specs/heading/commands.js +41 -0
  109. package/dist/editor/block-specs/heading/edit.d.ts +10 -0
  110. package/dist/editor/block-specs/heading/edit.js +33 -0
  111. package/dist/editor/block-specs/heading/index.d.ts +7 -0
  112. package/dist/editor/block-specs/heading/index.js +6 -0
  113. package/dist/editor/block-specs/heading/inlineSecondPass.d.ts +4 -0
  114. package/dist/editor/block-specs/heading/inlineSecondPass.js +20 -0
  115. package/dist/editor/block-specs/heading/parse.d.ts +5 -0
  116. package/dist/editor/block-specs/heading/parse.js +18 -0
  117. package/dist/editor/block-specs/heading/reconcile.d.ts +2 -0
  118. package/dist/editor/block-specs/heading/reconcile.js +8 -0
  119. package/dist/editor/block-specs/heading/serialize.d.ts +2 -0
  120. package/dist/editor/block-specs/heading/serialize.js +9 -0
  121. package/dist/editor/block-specs/heading/types.d.ts +5 -0
  122. package/dist/editor/block-specs/heading/types.js +1 -0
  123. package/dist/editor/block-specs/headingSpec.d.ts +2 -0
  124. package/dist/editor/block-specs/headingSpec.js +28 -0
  125. package/dist/editor/block-specs/horizontalRule/HorizontalRuleRenderer.svelte +15 -0
  126. package/dist/editor/block-specs/horizontalRule/HorizontalRuleRenderer.svelte.d.ts +21 -0
  127. package/dist/editor/block-specs/horizontalRule/commands.d.ts +2 -0
  128. package/dist/editor/block-specs/horizontalRule/commands.js +1 -0
  129. package/dist/editor/block-specs/horizontalRule/index.d.ts +6 -0
  130. package/dist/editor/block-specs/horizontalRule/index.js +5 -0
  131. package/dist/editor/block-specs/horizontalRule/inlineSecondPass.d.ts +3 -0
  132. package/dist/editor/block-specs/horizontalRule/inlineSecondPass.js +5 -0
  133. package/dist/editor/block-specs/horizontalRule/parse.d.ts +2 -0
  134. package/dist/editor/block-specs/horizontalRule/parse.js +15 -0
  135. package/dist/editor/block-specs/horizontalRule/reconcile.d.ts +2 -0
  136. package/dist/editor/block-specs/horizontalRule/reconcile.js +5 -0
  137. package/dist/editor/block-specs/horizontalRule/serialize.d.ts +2 -0
  138. package/dist/editor/block-specs/horizontalRule/serialize.js +3 -0
  139. package/dist/editor/block-specs/horizontalRule/types.d.ts +3 -0
  140. package/dist/editor/block-specs/horizontalRule/types.js +1 -0
  141. package/dist/editor/block-specs/horizontalRuleSpec.d.ts +2 -0
  142. package/dist/editor/block-specs/horizontalRuleSpec.js +24 -0
  143. package/dist/editor/block-specs/list/ListRenderer.svelte +70 -0
  144. package/dist/editor/block-specs/list/ListRenderer.svelte.d.ts +21 -0
  145. package/dist/editor/block-specs/list/commands.d.ts +2 -0
  146. package/dist/editor/block-specs/list/commands.js +65 -0
  147. package/dist/editor/block-specs/list/index.d.ts +6 -0
  148. package/dist/editor/block-specs/list/index.js +5 -0
  149. package/dist/editor/block-specs/list/inlineSecondPass.d.ts +6 -0
  150. package/dist/editor/block-specs/list/inlineSecondPass.js +78 -0
  151. package/dist/editor/block-specs/list/parse.d.ts +11 -0
  152. package/dist/editor/block-specs/list/parse.js +312 -0
  153. package/dist/editor/block-specs/list/reconcile.d.ts +2 -0
  154. package/dist/editor/block-specs/list/reconcile.js +6 -0
  155. package/dist/editor/block-specs/list/serialize.d.ts +4 -0
  156. package/dist/editor/block-specs/list/serialize.js +83 -0
  157. package/dist/editor/block-specs/list/types.d.ts +27 -0
  158. package/dist/editor/block-specs/list/types.js +1 -0
  159. package/dist/editor/block-specs/listSpec.d.ts +4 -0
  160. package/dist/editor/block-specs/listSpec.js +24 -0
  161. package/dist/editor/block-specs/paragraph/ParagraphRenderer.svelte +22 -0
  162. package/dist/editor/block-specs/paragraph/ParagraphRenderer.svelte.d.ts +21 -0
  163. package/dist/editor/block-specs/paragraph/commands.d.ts +2 -0
  164. package/dist/editor/block-specs/paragraph/commands.js +41 -0
  165. package/dist/editor/block-specs/paragraph/edit.d.ts +10 -0
  166. package/dist/editor/block-specs/paragraph/edit.js +69 -0
  167. package/dist/editor/block-specs/paragraph/index.d.ts +7 -0
  168. package/dist/editor/block-specs/paragraph/index.js +6 -0
  169. package/dist/editor/block-specs/paragraph/inlineSecondPass.d.ts +3 -0
  170. package/dist/editor/block-specs/paragraph/inlineSecondPass.js +25 -0
  171. package/dist/editor/block-specs/paragraph/parse.d.ts +9 -0
  172. package/dist/editor/block-specs/paragraph/parse.js +76 -0
  173. package/dist/editor/block-specs/paragraph/reconcile.d.ts +2 -0
  174. package/dist/editor/block-specs/paragraph/reconcile.js +9 -0
  175. package/dist/editor/block-specs/paragraph/serialize.d.ts +4 -0
  176. package/dist/editor/block-specs/paragraph/serialize.js +39 -0
  177. package/dist/editor/block-specs/paragraph/types.d.ts +10 -0
  178. package/dist/editor/block-specs/paragraph/types.js +1 -0
  179. package/dist/editor/block-specs/paragraphSpec.d.ts +2 -0
  180. package/dist/editor/block-specs/paragraphSpec.js +24 -0
  181. package/dist/editor/block-specs/registry.d.ts +10 -0
  182. package/dist/editor/block-specs/registry.js +34 -0
  183. package/dist/editor/block-specs/table/TableRenderer.svelte +53 -0
  184. package/dist/editor/block-specs/table/TableRenderer.svelte.d.ts +21 -0
  185. package/dist/editor/block-specs/table/commands.d.ts +2 -0
  186. package/dist/editor/block-specs/table/commands.js +1 -0
  187. package/dist/editor/block-specs/table/edit.d.ts +10 -0
  188. package/dist/editor/block-specs/table/edit.js +127 -0
  189. package/dist/editor/block-specs/table/editCommands.d.ts +18 -0
  190. package/dist/editor/block-specs/table/editCommands.js +87 -0
  191. package/dist/editor/block-specs/table/index.d.ts +8 -0
  192. package/dist/editor/block-specs/table/index.js +6 -0
  193. package/dist/editor/block-specs/table/inlineSecondPass.d.ts +3 -0
  194. package/dist/editor/block-specs/table/inlineSecondPass.js +22 -0
  195. package/dist/editor/block-specs/table/parse.d.ts +17 -0
  196. package/dist/editor/block-specs/table/parse.js +181 -0
  197. package/dist/editor/block-specs/table/reconcile.d.ts +2 -0
  198. package/dist/editor/block-specs/table/reconcile.js +6 -0
  199. package/dist/editor/block-specs/table/serialize.d.ts +3 -0
  200. package/dist/editor/block-specs/table/serialize.js +32 -0
  201. package/dist/editor/block-specs/table/types.d.ts +11 -0
  202. package/dist/editor/block-specs/table/types.js +1 -0
  203. package/dist/editor/block-specs/tableSpec.d.ts +2 -0
  204. package/dist/editor/block-specs/tableSpec.js +25 -0
  205. package/dist/editor/block-specs/toc/EditableToc.svelte +16 -0
  206. package/dist/editor/block-specs/toc/EditableToc.svelte.d.ts +4 -0
  207. package/dist/editor/block-specs/toc/TocRenderer.svelte +22 -0
  208. package/dist/editor/block-specs/toc/TocRenderer.svelte.d.ts +21 -0
  209. package/dist/editor/block-specs/toc/commands.d.ts +2 -0
  210. package/dist/editor/block-specs/toc/commands.js +1 -0
  211. package/dist/editor/block-specs/toc/index.d.ts +6 -0
  212. package/dist/editor/block-specs/toc/index.js +5 -0
  213. package/dist/editor/block-specs/toc/inlineSecondPass.d.ts +3 -0
  214. package/dist/editor/block-specs/toc/inlineSecondPass.js +5 -0
  215. package/dist/editor/block-specs/toc/parse.d.ts +10 -0
  216. package/dist/editor/block-specs/toc/parse.js +43 -0
  217. package/dist/editor/block-specs/toc/reconcile.d.ts +2 -0
  218. package/dist/editor/block-specs/toc/reconcile.js +5 -0
  219. package/dist/editor/block-specs/toc/serialize.d.ts +2 -0
  220. package/dist/editor/block-specs/toc/serialize.js +6 -0
  221. package/dist/editor/block-specs/toc/types.d.ts +8 -0
  222. package/dist/editor/block-specs/toc/types.js +1 -0
  223. package/dist/editor/block-specs/tocSpec.d.ts +2 -0
  224. package/dist/editor/block-specs/tocSpec.js +24 -0
  225. package/dist/editor/block-specs/toggle/ToggleRenderer.svelte +19 -0
  226. package/dist/editor/block-specs/toggle/ToggleRenderer.svelte.d.ts +21 -0
  227. package/dist/editor/block-specs/toggle/commands.d.ts +2 -0
  228. package/dist/editor/block-specs/toggle/commands.js +1 -0
  229. package/dist/editor/block-specs/toggle/index.d.ts +7 -0
  230. package/dist/editor/block-specs/toggle/index.js +5 -0
  231. package/dist/editor/block-specs/toggle/inlineSecondPass.d.ts +3 -0
  232. package/dist/editor/block-specs/toggle/inlineSecondPass.js +5 -0
  233. package/dist/editor/block-specs/toggle/parse.d.ts +9 -0
  234. package/dist/editor/block-specs/toggle/parse.js +78 -0
  235. package/dist/editor/block-specs/toggle/reconcile.d.ts +2 -0
  236. package/dist/editor/block-specs/toggle/reconcile.js +6 -0
  237. package/dist/editor/block-specs/toggle/serialize.d.ts +4 -0
  238. package/dist/editor/block-specs/toggle/serialize.js +13 -0
  239. package/dist/editor/block-specs/toggle/types.d.ts +5 -0
  240. package/dist/editor/block-specs/toggle/types.js +1 -0
  241. package/dist/editor/block-specs/toggleSpec.d.ts +2 -0
  242. package/dist/editor/block-specs/toggleSpec.js +24 -0
  243. package/dist/editor/block-specs/types.d.ts +26 -0
  244. package/dist/editor/block-specs/types.js +1 -0
  245. package/dist/editor/blocks/EditableBlockquote.svelte +52 -0
  246. package/dist/editor/blocks/EditableBlockquote.svelte.d.ts +10 -0
  247. package/dist/editor/blocks/EditableBlockquoteNodes.svelte +134 -0
  248. package/dist/editor/blocks/EditableBlockquoteNodes.svelte.d.ts +14 -0
  249. package/dist/editor/blocks/EditableBlockquoteParagraph.svelte +44 -0
  250. package/dist/editor/blocks/EditableBlockquoteParagraph.svelte.d.ts +12 -0
  251. package/dist/editor/blocks/EditableCallout.svelte +182 -0
  252. package/dist/editor/blocks/EditableCallout.svelte.d.ts +11 -0
  253. package/dist/editor/blocks/EditableCalloutListItemRow.svelte +169 -0
  254. package/dist/editor/blocks/EditableCalloutListItemRow.svelte.d.ts +15 -0
  255. package/dist/editor/blocks/EditableCalloutNodes.svelte +91 -0
  256. package/dist/editor/blocks/EditableCalloutNodes.svelte.d.ts +13 -0
  257. package/dist/editor/blocks/EditableCalloutParagraph.svelte +39 -0
  258. package/dist/editor/blocks/EditableCalloutParagraph.svelte.d.ts +12 -0
  259. package/dist/editor/blocks/EditableCodeBlock.svelte +43 -0
  260. package/dist/editor/blocks/EditableCodeBlock.svelte.d.ts +10 -0
  261. package/dist/editor/blocks/EditableHeading.svelte +161 -0
  262. package/dist/editor/blocks/EditableHeading.svelte.d.ts +10 -0
  263. package/dist/editor/blocks/EditableHorizontalRule.svelte +20 -0
  264. package/dist/editor/blocks/EditableHorizontalRule.svelte.d.ts +10 -0
  265. package/dist/editor/blocks/EditableInlineSurface.svelte +423 -0
  266. package/dist/editor/blocks/EditableInlineSurface.svelte.d.ts +26 -0
  267. package/dist/editor/blocks/EditableList.svelte +77 -0
  268. package/dist/editor/blocks/EditableList.svelte.d.ts +17 -0
  269. package/dist/editor/blocks/EditableListItemRow.svelte +231 -0
  270. package/dist/editor/blocks/EditableListItemRow.svelte.d.ts +19 -0
  271. package/dist/editor/blocks/EditableParagraph.svelte +208 -0
  272. package/dist/editor/blocks/EditableParagraph.svelte.d.ts +10 -0
  273. package/dist/editor/blocks/EditableParagraphNodes.svelte +89 -0
  274. package/dist/editor/blocks/EditableParagraphNodes.svelte.d.ts +15 -0
  275. package/dist/editor/blocks/EditableTable.svelte +83 -0
  276. package/dist/editor/blocks/EditableTable.svelte.d.ts +10 -0
  277. package/dist/editor/blocks/EditableTableCell.svelte +89 -0
  278. package/dist/editor/blocks/EditableTableCell.svelte.d.ts +15 -0
  279. package/dist/editor/blocks/EditableToggle.svelte +94 -0
  280. package/dist/editor/blocks/EditableToggle.svelte.d.ts +10 -0
  281. package/dist/editor/commandMenu.d.ts +18 -0
  282. package/dist/editor/commandMenu.js +83 -0
  283. package/dist/editor/commandRegistry.d.ts +48 -0
  284. package/dist/editor/commandRegistry.js +133 -0
  285. package/dist/editor/context/assetBaseUrl.d.ts +6 -0
  286. package/dist/editor/context/assetBaseUrl.js +20 -0
  287. package/dist/editor/dom/editorHistoryKeydown.d.ts +6 -0
  288. package/dist/editor/dom/editorHistoryKeydown.js +31 -0
  289. package/dist/editor/dom/plainEnterKeydown.d.ts +12 -0
  290. package/dist/editor/dom/plainEnterKeydown.js +53 -0
  291. package/dist/editor/dom/plaintextCaret.d.ts +12 -0
  292. package/dist/editor/dom/plaintextCaret.js +61 -0
  293. package/dist/editor/dom/syncDocumentSelectionFocus.d.ts +17 -0
  294. package/dist/editor/dom/syncDocumentSelectionFocus.js +56 -0
  295. package/dist/editor/draftPersistence.d.ts +27 -0
  296. package/dist/editor/draftPersistence.js +83 -0
  297. package/dist/editor/editorHistoryHandle.d.ts +16 -0
  298. package/dist/editor/editorHistoryHandle.js +22 -0
  299. package/dist/editor/inlineChrome/InlineChromeCoordinator.svelte +174 -0
  300. package/dist/editor/inlineChrome/InlineChromeCoordinator.svelte.d.ts +8 -0
  301. package/dist/editor/inlineChrome/InlineFormattingToolbar.svelte +181 -0
  302. package/dist/editor/inlineChrome/InlineFormattingToolbar.svelte.d.ts +3 -0
  303. package/dist/editor/inlineChrome/inlineChromeActions.d.ts +17 -0
  304. package/dist/editor/inlineChrome/inlineChromeActions.js +148 -0
  305. package/dist/editor/inlineChrome/inlineChromeState.svelte.d.ts +23 -0
  306. package/dist/editor/inlineChrome/inlineChromeState.svelte.js +21 -0
  307. package/dist/editor/inlineChrome/inlineToolbarIcons.d.ts +14 -0
  308. package/dist/editor/inlineChrome/inlineToolbarIcons.js +14 -0
  309. package/dist/editor/inlineChrome/inlineWrapActive.d.ts +3 -0
  310. package/dist/editor/inlineChrome/inlineWrapActive.js +19 -0
  311. package/dist/editor/inlineChrome/selectionRect.d.ts +2 -0
  312. package/dist/editor/inlineChrome/selectionRect.js +23 -0
  313. package/dist/editor/model/blockEditCommands.d.ts +73 -0
  314. package/dist/editor/model/blockEditCommands.js +719 -0
  315. package/dist/editor/model/blockTree.d.ts +39 -0
  316. package/dist/editor/model/blockTree.js +185 -0
  317. package/dist/editor/model/blockTreeDrop.d.ts +9 -0
  318. package/dist/editor/model/blockTreeDrop.js +295 -0
  319. package/dist/editor/model/blockTreeMutations.d.ts +10 -0
  320. package/dist/editor/model/blockTreeMutations.js +68 -0
  321. package/dist/editor/model/calloutEditCommands.d.ts +39 -0
  322. package/dist/editor/model/calloutEditCommands.js +305 -0
  323. package/dist/editor/model/documentSelection.d.ts +8 -0
  324. package/dist/editor/model/documentSelection.js +56 -0
  325. package/dist/editor/model/documentSelectionFromSource.d.ts +3 -0
  326. package/dist/editor/model/documentSelectionFromSource.js +45 -0
  327. package/dist/editor/model/documentToRenderBlocks.d.ts +3 -0
  328. package/dist/editor/model/documentToRenderBlocks.js +13 -0
  329. package/dist/editor/model/editorPipeline.bench.d.ts +1 -0
  330. package/dist/editor/model/editorPipeline.bench.js +27 -0
  331. package/dist/editor/model/editorTransactions.d.ts +20 -0
  332. package/dist/editor/model/editorTransactions.js +68 -0
  333. package/dist/editor/model/emptyParagraph.d.ts +11 -0
  334. package/dist/editor/model/emptyParagraph.js +25 -0
  335. package/dist/editor/model/enterCommands.d.ts +16 -0
  336. package/dist/editor/model/enterCommands.js +288 -0
  337. package/dist/editor/model/extensionSyntaxWarnings.d.ts +29 -0
  338. package/dist/editor/model/extensionSyntaxWarnings.js +122 -0
  339. package/dist/editor/model/findBlockAtSourceOffset.d.ts +3 -0
  340. package/dist/editor/model/findBlockAtSourceOffset.js +20 -0
  341. package/dist/editor/model/fixtures/serialization-fidelity/reorder-gaps.svelte +4 -0
  342. package/dist/editor/model/focusOutcome.d.ts +25 -0
  343. package/dist/editor/model/focusOutcome.js +1 -0
  344. package/dist/editor/model/incrementalReparse.d.ts +16 -0
  345. package/dist/editor/model/incrementalReparse.js +111 -0
  346. package/dist/editor/model/index.d.ts +22 -0
  347. package/dist/editor/model/index.js +19 -0
  348. package/dist/editor/model/inlineDraftCommit.d.ts +17 -0
  349. package/dist/editor/model/inlineDraftCommit.js +187 -0
  350. package/dist/editor/model/inlineDraftMerge.d.ts +8 -0
  351. package/dist/editor/model/inlineDraftMerge.js +81 -0
  352. package/dist/editor/model/inlineEditCommands.d.ts +28 -0
  353. package/dist/editor/model/inlineEditCommands.js +581 -0
  354. package/dist/editor/model/inlinePlain.d.ts +3 -0
  355. package/dist/editor/model/inlinePlain.js +28 -0
  356. package/dist/editor/model/inlineSecondPass.d.ts +4 -0
  357. package/dist/editor/model/inlineSecondPass.js +47 -0
  358. package/dist/editor/model/line-utils.d.ts +14 -0
  359. package/dist/editor/model/line-utils.js +38 -0
  360. package/dist/editor/model/listEditCommands.d.ts +56 -0
  361. package/dist/editor/model/listEditCommands.js +299 -0
  362. package/dist/editor/model/nestedContainerTransactions.d.ts +36 -0
  363. package/dist/editor/model/nestedContainerTransactions.js +336 -0
  364. package/dist/editor/model/parseMarkdownDocument.d.ts +2 -0
  365. package/dist/editor/model/parseMarkdownDocument.js +324 -0
  366. package/dist/editor/model/quoteEditCommands.d.ts +39 -0
  367. package/dist/editor/model/quoteEditCommands.js +323 -0
  368. package/dist/editor/model/reconcileBlockIds.d.ts +9 -0
  369. package/dist/editor/model/reconcileBlockIds.js +297 -0
  370. package/dist/editor/model/reparseOptions.d.ts +12 -0
  371. package/dist/editor/model/reparseOptions.js +1 -0
  372. package/dist/editor/model/resolveEnterPlainSnapshot.d.ts +6 -0
  373. package/dist/editor/model/resolveEnterPlainSnapshot.js +23 -0
  374. package/dist/editor/model/richInlines.d.ts +16 -0
  375. package/dist/editor/model/richInlines.js +494 -0
  376. package/dist/editor/model/serializeInlineNodes.d.ts +3 -0
  377. package/dist/editor/model/serializeInlineNodes.js +45 -0
  378. package/dist/editor/model/serializeMarkdownDocument.d.ts +30 -0
  379. package/dist/editor/model/serializeMarkdownDocument.js +150 -0
  380. package/dist/editor/model/structureParseWarnings.d.ts +10 -0
  381. package/dist/editor/model/structureParseWarnings.js +60 -0
  382. package/dist/editor/model/syntheticInlineRanges.d.ts +3 -0
  383. package/dist/editor/model/syntheticInlineRanges.js +36 -0
  384. package/dist/editor/model/types.d.ts +185 -0
  385. package/dist/editor/model/types.js +26 -0
  386. package/dist/editor/plugins/autolinks/AutolinkRenderer.svelte +20 -0
  387. package/dist/editor/plugins/autolinks/AutolinkRenderer.svelte.d.ts +21 -0
  388. package/dist/editor/plugins/autolinks/index.d.ts +2 -0
  389. package/dist/editor/plugins/autolinks/index.js +4 -0
  390. package/dist/editor/plugins/autolinks/parse-autolinks.d.ts +2 -0
  391. package/dist/editor/plugins/autolinks/parse-autolinks.js +68 -0
  392. package/dist/editor/plugins/autolinks/types.d.ts +6 -0
  393. package/dist/editor/plugins/autolinks/types.js +1 -0
  394. package/dist/editor/plugins/emphasis/EmphasisRenderer.svelte +15 -0
  395. package/dist/editor/plugins/emphasis/EmphasisRenderer.svelte.d.ts +21 -0
  396. package/dist/editor/plugins/emphasis/index.d.ts +2 -0
  397. package/dist/editor/plugins/emphasis/index.js +4 -0
  398. package/dist/editor/plugins/emphasis/parse-emphasis.d.ts +2 -0
  399. package/dist/editor/plugins/emphasis/parse-emphasis.js +188 -0
  400. package/dist/editor/plugins/emphasis/types.d.ts +24 -0
  401. package/dist/editor/plugins/emphasis/types.js +1 -0
  402. package/dist/editor/plugins/escaping/EscapingRenderer.svelte +18 -0
  403. package/dist/editor/plugins/escaping/EscapingRenderer.svelte.d.ts +21 -0
  404. package/dist/editor/plugins/escaping/index.d.ts +2 -0
  405. package/dist/editor/plugins/escaping/index.js +4 -0
  406. package/dist/editor/plugins/escaping/parse-escaping.d.ts +6 -0
  407. package/dist/editor/plugins/escaping/parse-escaping.js +26 -0
  408. package/dist/editor/plugins/escaping/types.d.ts +10 -0
  409. package/dist/editor/plugins/escaping/types.js +1 -0
  410. package/dist/editor/plugins/extended-task-list/ExtendedTaskListRenderer.svelte +25 -0
  411. package/dist/editor/plugins/extended-task-list/ExtendedTaskListRenderer.svelte.d.ts +21 -0
  412. package/dist/editor/plugins/extended-task-list/index.d.ts +2 -0
  413. package/dist/editor/plugins/extended-task-list/index.js +4 -0
  414. package/dist/editor/plugins/extended-task-list/parse-extended-task-list.d.ts +2 -0
  415. package/dist/editor/plugins/extended-task-list/parse-extended-task-list.js +35 -0
  416. package/dist/editor/plugins/extended-task-list/types.d.ts +6 -0
  417. package/dist/editor/plugins/extended-task-list/types.js +1 -0
  418. package/dist/editor/plugins/highlight/HighlightRenderer.svelte +16 -0
  419. package/dist/editor/plugins/highlight/HighlightRenderer.svelte.d.ts +21 -0
  420. package/dist/editor/plugins/highlight/index.d.ts +2 -0
  421. package/dist/editor/plugins/highlight/index.js +4 -0
  422. package/dist/editor/plugins/highlight/parse-highlights.d.ts +4 -0
  423. package/dist/editor/plugins/highlight/parse-highlights.js +49 -0
  424. package/dist/editor/plugins/highlight/types.d.ts +6 -0
  425. package/dist/editor/plugins/highlight/types.js +1 -0
  426. package/dist/editor/plugins/index.d.ts +1 -0
  427. package/dist/editor/plugins/index.js +1 -0
  428. package/dist/editor/plugins/links-images/LinksImagesRenderer.svelte +53 -0
  429. package/dist/editor/plugins/links-images/LinksImagesRenderer.svelte.d.ts +21 -0
  430. package/dist/editor/plugins/links-images/index.d.ts +2 -0
  431. package/dist/editor/plugins/links-images/index.js +4 -0
  432. package/dist/editor/plugins/links-images/parse-image-layout.d.ts +28 -0
  433. package/dist/editor/plugins/links-images/parse-image-layout.js +147 -0
  434. package/dist/editor/plugins/links-images/parse-links-images.d.ts +25 -0
  435. package/dist/editor/plugins/links-images/parse-links-images.js +236 -0
  436. package/dist/editor/plugins/links-images/resolve-asset-url.d.ts +5 -0
  437. package/dist/editor/plugins/links-images/resolve-asset-url.js +21 -0
  438. package/dist/editor/plugins/links-images/types.d.ts +11 -0
  439. package/dist/editor/plugins/links-images/types.js +1 -0
  440. package/dist/editor/plugins/mention/MentionRenderer.svelte +18 -0
  441. package/dist/editor/plugins/mention/MentionRenderer.svelte.d.ts +21 -0
  442. package/dist/editor/plugins/mention/index.d.ts +2 -0
  443. package/dist/editor/plugins/mention/index.js +4 -0
  444. package/dist/editor/plugins/mention/parse-mentions.d.ts +2 -0
  445. package/dist/editor/plugins/mention/parse-mentions.js +54 -0
  446. package/dist/editor/plugins/mention/types.d.ts +14 -0
  447. package/dist/editor/plugins/mention/types.js +1 -0
  448. package/dist/editor/plugins/raw-text/RawTextRenderer.svelte +19 -0
  449. package/dist/editor/plugins/raw-text/RawTextRenderer.svelte.d.ts +21 -0
  450. package/dist/editor/plugins/raw-text/index.d.ts +2 -0
  451. package/dist/editor/plugins/raw-text/index.js +4 -0
  452. package/dist/editor/plugins/raw-text/types.d.ts +4 -0
  453. package/dist/editor/plugins/raw-text/types.js +1 -0
  454. package/dist/editor/plugins/shared/InlineNodes.svelte +113 -0
  455. package/dist/editor/plugins/shared/InlineNodes.svelte.d.ts +21 -0
  456. package/dist/editor/plugins/shared/InlineNodesEdit.svelte +78 -0
  457. package/dist/editor/plugins/shared/InlineNodesEdit.svelte.d.ts +21 -0
  458. package/dist/editor/plugins/strikethrough/StrikethroughRenderer.svelte +9 -0
  459. package/dist/editor/plugins/strikethrough/StrikethroughRenderer.svelte.d.ts +21 -0
  460. package/dist/editor/plugins/strikethrough/index.d.ts +2 -0
  461. package/dist/editor/plugins/strikethrough/index.js +4 -0
  462. package/dist/editor/plugins/strikethrough/parse-strikethrough.d.ts +3 -0
  463. package/dist/editor/plugins/strikethrough/parse-strikethrough.js +38 -0
  464. package/dist/editor/plugins/strikethrough/types.d.ts +4 -0
  465. package/dist/editor/plugins/strikethrough/types.js +1 -0
  466. package/dist/editor/plugins/synced-block/SyncedBlockRenderer.svelte +16 -0
  467. package/dist/editor/plugins/synced-block/SyncedBlockRenderer.svelte.d.ts +21 -0
  468. package/dist/editor/plugins/synced-block/index.d.ts +2 -0
  469. package/dist/editor/plugins/synced-block/index.js +4 -0
  470. package/dist/editor/plugins/synced-block/parse-synced-blocks.d.ts +2 -0
  471. package/dist/editor/plugins/synced-block/parse-synced-blocks.js +15 -0
  472. package/dist/editor/plugins/synced-block/types.d.ts +4 -0
  473. package/dist/editor/plugins/synced-block/types.js +1 -0
  474. package/dist/editor/plugins/types.d.ts +19 -0
  475. package/dist/editor/plugins/types.js +1 -0
  476. package/dist/editor/plugins/wiki-link/WikiLinkRenderer.svelte +15 -0
  477. package/dist/editor/plugins/wiki-link/WikiLinkRenderer.svelte.d.ts +21 -0
  478. package/dist/editor/plugins/wiki-link/index.d.ts +2 -0
  479. package/dist/editor/plugins/wiki-link/index.js +4 -0
  480. package/dist/editor/plugins/wiki-link/parse-wiki-links.d.ts +2 -0
  481. package/dist/editor/plugins/wiki-link/parse-wiki-links.js +30 -0
  482. package/dist/editor/plugins/wiki-link/types.d.ts +8 -0
  483. package/dist/editor/plugins/wiki-link/types.js +1 -0
  484. package/dist/editor/taskCheckboxStates.d.ts +5 -0
  485. package/dist/editor/taskCheckboxStates.js +28 -0
  486. package/dist/index.d.ts +6 -0
  487. package/dist/index.js +9 -0
  488. package/dist/styles/index.css +6 -0
  489. package/package.json +84 -0
@@ -0,0 +1,336 @@
1
+ import { serializeListRegion } from '../block-specs/list/serialize';
2
+ import { serializeEditorBlock, serializeTopLevelBlockSpan } from './serializeMarkdownDocument';
3
+ import { cloneInlineNodeDeep, inlineTextNode, wrapInlineSelection } from './inlineEditCommands';
4
+ import { inlineNodesToPlainText } from './inlinePlain';
5
+ import { deepCloneBlocks, findBlockLocation, listRegionBounds, sourceRangeForBlockSpan } from './blockTree';
6
+ import { normalizeBlockSliceReplacement } from './blockEditCommands';
7
+ import { blockTreeDropTransaction } from './blockTreeDrop';
8
+ import { findListItemPath, listDeleteItem, listDuplicateItem, listMoveSibling, resolveListItem, siblingFocusIdForListDelete } from './listEditCommands';
9
+ import { calloutDeleteChild, calloutDuplicateChild, calloutExitReplacementMarkdown, calloutMoveSibling, siblingFocusIdForCalloutDelete } from './calloutEditCommands';
10
+ import { findQuoteBlockPath, quoteDeleteBlock, quoteDuplicateBlock, quoteMoveSibling } from './quoteEditCommands';
11
+ export { applyBlockTreeDrop, blockTreeDropTransaction, canBlockTreeDrop } from './blockTreeDrop';
12
+ export { isDescendantBlock, nestUnderPreviousSibling, nestUnderTarget, promoteOneLevel, removeBlockFromTree } from './blockTreeMutations';
13
+ function sliceReplaceTransaction(source, range, nextMarkdown, caret, txId) {
14
+ const text = normalizeBlockSliceReplacement(source, range.start, range.end, nextMarkdown);
15
+ return {
16
+ ok: true,
17
+ transaction: {
18
+ id: txId,
19
+ operations: [{ type: 'replaceSlice', range, text }],
20
+ selection: { anchor: caret, focus: caret }
21
+ }
22
+ };
23
+ }
24
+ function topLevelStructSpanForBlock(blocks, blockId) {
25
+ const loc = findBlockLocation(blocks, blockId);
26
+ if (!loc)
27
+ return null;
28
+ if (blocks[loc.topLevelIndex]?.type === 'listItem') {
29
+ return listRegionBounds(blocks, loc.topLevelIndex);
30
+ }
31
+ return { start: loc.topLevelIndex, end: loc.topLevelIndex + 1 };
32
+ }
33
+ export function listRegionStructMutation(source, doc, itemId, mutate, txId, caretBlockId) {
34
+ const bounds = topLevelStructSpanForBlock(doc.blocks, itemId);
35
+ if (!bounds)
36
+ return { ok: false, error: 'Block not found.' };
37
+ const clone = deepCloneBlocks(doc.blocks);
38
+ const nextBlocks = mutate(clone);
39
+ if (!nextBlocks)
40
+ return { ok: false, error: 'List edit failed.' };
41
+ const range = sourceRangeForBlockSpan(doc.blocks, bounds.start, bounds.end, source);
42
+ if (!range)
43
+ return { ok: false, error: 'List region has no source range.' };
44
+ const topLevelDelta = nextBlocks.length - doc.blocks.length;
45
+ const nextEnd = Math.max(bounds.start, Math.min(nextBlocks.length, bounds.end + topLevelDelta));
46
+ const md = serializeTopLevelBlockSpan(nextBlocks, bounds.start, nextEnd, source);
47
+ let caret = range.start;
48
+ if (caretBlockId) {
49
+ const loc = findBlockLocation(nextBlocks, caretBlockId);
50
+ if (loc?.block.sourceRange.start !== undefined && loc.block.sourceRange.start >= 0) {
51
+ caret = loc.block.sourceRange.start;
52
+ }
53
+ }
54
+ return sliceReplaceTransaction(source, range, md, caret, txId);
55
+ }
56
+ function blockquoteMutationTransaction(source, doc, blockIndex, mutate, txId, caretBlockId) {
57
+ const block = doc.blocks[blockIndex];
58
+ if (!block || block.type !== 'blockquote')
59
+ return { ok: false, error: 'Expected blockquote block.' };
60
+ const nextRoot = mutate(deepCloneBlocks([block])[0]);
61
+ if (!nextRoot)
62
+ return { ok: false, error: 'Blockquote edit failed.' };
63
+ const md = serializeEditorBlock(nextRoot, source);
64
+ let caret = block.sourceRange.start;
65
+ if (caretBlockId) {
66
+ const loc = findBlockLocation([nextRoot], caretBlockId);
67
+ if (loc?.block.sourceRange.start !== undefined && loc.block.sourceRange.start >= 0) {
68
+ caret = loc.block.sourceRange.start;
69
+ }
70
+ }
71
+ if (block.sourceRange.start < 0)
72
+ return { ok: false, error: 'Cannot edit synthetic block.' };
73
+ return sliceReplaceTransaction(source, { start: block.sourceRange.start, end: block.sourceRange.end }, md, caret, txId);
74
+ }
75
+ export function moveListItemSiblingTransaction(source, doc, _itemIndex, itemId, direction) {
76
+ return listRegionStructMutation(source, doc, itemId, (blocks) => listMoveSibling(blocks, itemId, direction), `list-item-move-${direction}:${itemId}`, itemId);
77
+ }
78
+ export function listItemTreeDropTransaction(source, doc, _blockIndex, draggedId, targetId, placement) {
79
+ return blockTreeDropTransaction(source, doc, draggedId, targetId, placement);
80
+ }
81
+ export function deleteListItemTransaction(source, doc, _blockIndex, itemId, focusAfterId) {
82
+ return listRegionStructMutation(source, doc, itemId, (blocks) => listDeleteItem(blocks, itemId), `list-item-delete:${itemId}`, focusAfterId);
83
+ }
84
+ export function duplicateListItemTransaction(source, doc, _blockIndex, itemId) {
85
+ let duplicateId;
86
+ return listRegionStructMutation(source, doc, itemId, (blocks) => {
87
+ const before = findListItemPath(blocks, itemId);
88
+ const next = listDuplicateItem(blocks, itemId);
89
+ if (!next || !before)
90
+ return null;
91
+ const nav = resolveListItem(next, before);
92
+ duplicateId = nav?.siblings[nav.itemIndex + 1]?.id;
93
+ return next;
94
+ }, `list-item-duplicate:${itemId}`, duplicateId);
95
+ }
96
+ export { siblingFocusIdForListDelete };
97
+ export function moveQuoteBlockSiblingTransaction(source, doc, blockIndex, quoteBlockId, direction) {
98
+ const block = doc.blocks[blockIndex];
99
+ if (!block || block.type !== 'blockquote')
100
+ return { ok: false, error: 'Expected blockquote.' };
101
+ const path = findQuoteBlockPath(block, quoteBlockId);
102
+ if (!path)
103
+ return { ok: false, error: 'Blockquote node not found.' };
104
+ return blockquoteMutationTransaction(source, doc, blockIndex, (root) => quoteMoveSibling(root, path, direction), `quote-move-${direction}:${quoteBlockId}`, quoteBlockId);
105
+ }
106
+ export function deleteQuoteBlockTransaction(source, doc, blockIndex, quoteBlockId, focusAfterId) {
107
+ const block = doc.blocks[blockIndex];
108
+ if (!block || block.type !== 'blockquote')
109
+ return { ok: false, error: 'Expected blockquote.' };
110
+ const path = findQuoteBlockPath(block, quoteBlockId);
111
+ if (!path)
112
+ return { ok: false, error: 'Blockquote node not found.' };
113
+ return blockquoteMutationTransaction(source, doc, blockIndex, (root) => quoteDeleteBlock(root, path), `quote-delete:${quoteBlockId}`, focusAfterId);
114
+ }
115
+ export function duplicateQuoteBlockTransaction(source, doc, blockIndex, quoteBlockId) {
116
+ const block = doc.blocks[blockIndex];
117
+ if (!block || block.type !== 'blockquote')
118
+ return { ok: false, error: 'Expected blockquote.' };
119
+ const path = findQuoteBlockPath(block, quoteBlockId);
120
+ if (!path)
121
+ return { ok: false, error: 'Blockquote node not found.' };
122
+ let duplicateId;
123
+ return blockquoteMutationTransaction(source, doc, blockIndex, (root) => {
124
+ const next = quoteDuplicateBlock(root, path);
125
+ if (!next)
126
+ return null;
127
+ const p = findQuoteBlockPath(next, quoteBlockId);
128
+ if (p) {
129
+ let parent = next;
130
+ for (let i = 0; i < p.length - 1; i++)
131
+ parent = parent.children[p[i]];
132
+ duplicateId = parent.children?.[p[p.length - 1] + 1]?.id;
133
+ }
134
+ return next;
135
+ }, `quote-duplicate:${quoteBlockId}`, duplicateId);
136
+ }
137
+ export function applyListItemInlineWrapTransaction(source, doc, _blockIndex, itemId, plainStart, plainEnd, kind, linkHref) {
138
+ const path = findListItemPath(doc.blocks, itemId);
139
+ if (!path)
140
+ return { ok: false, error: 'List item not found.' };
141
+ const a = Math.min(plainStart, plainEnd);
142
+ const b = Math.max(plainStart, plainEnd);
143
+ return listRegionStructMutation(source, doc, itemId, (blocks) => {
144
+ const nav = resolveListItem(blocks, path);
145
+ if (!nav)
146
+ return null;
147
+ const bodyPlain = nav.item.inlines?.length ? inlineNodesToPlainText(nav.item.inlines) : '';
148
+ const baseNodes = nav.item.inlines?.length
149
+ ? nav.item.inlines.map(cloneInlineNodeDeep)
150
+ : bodyPlain.length > 0
151
+ ? [inlineTextNode(bodyPlain)]
152
+ : [];
153
+ const wrapped = wrapInlineSelection(baseNodes, a, b, kind, linkHref);
154
+ if (!wrapped)
155
+ return null;
156
+ nav.item.inlines = wrapped;
157
+ return blocks;
158
+ }, `list-item-inline:${itemId}:${kind}`, itemId);
159
+ }
160
+ export function applyQuoteBlockInlineWrapTransaction(source, doc, blockIndex, quoteBlockId, plainStart, plainEnd, kind, linkHref) {
161
+ const block = doc.blocks[blockIndex];
162
+ if (!block || block.type !== 'blockquote')
163
+ return { ok: false, error: 'Expected blockquote.' };
164
+ const path = findQuoteBlockPath(block, quoteBlockId);
165
+ if (!path)
166
+ return { ok: false, error: 'Blockquote node not found.' };
167
+ const a = Math.min(plainStart, plainEnd);
168
+ const b = Math.max(plainStart, plainEnd);
169
+ return blockquoteMutationTransaction(source, doc, blockIndex, (root) => {
170
+ let node = root;
171
+ if (path.length === 0) {
172
+ node = root;
173
+ }
174
+ else {
175
+ for (const i of path)
176
+ node = node.children[i];
177
+ }
178
+ if (node.type !== 'blockquote')
179
+ return null;
180
+ const bodyPlain = node.inlines?.length ? inlineNodesToPlainText(node.inlines) : '';
181
+ const baseNodes = node.inlines?.length
182
+ ? node.inlines.map(cloneInlineNodeDeep)
183
+ : bodyPlain.length > 0
184
+ ? [inlineTextNode(bodyPlain)]
185
+ : [];
186
+ const wrapped = wrapInlineSelection(baseNodes, a, b, kind, linkHref);
187
+ if (!wrapped)
188
+ return null;
189
+ node.inlines = wrapped;
190
+ return root;
191
+ }, `quote-inline:${quoteBlockId}:${kind}`, quoteBlockId);
192
+ }
193
+ export function quoteStructMutationTransaction(source, doc, blockIndex, quoteBlockId, mutate, txId, caretBlockId) {
194
+ return blockquoteMutationTransaction(source, doc, blockIndex, mutate, txId, caretBlockId);
195
+ }
196
+ export const moveQuoteParagraphSiblingTransaction = moveQuoteBlockSiblingTransaction;
197
+ export const deleteQuoteParagraphTransaction = deleteQuoteBlockTransaction;
198
+ export const duplicateQuoteParagraphTransaction = duplicateQuoteBlockTransaction;
199
+ export const applyQuoteParagraphInlineWrapTransaction = applyQuoteBlockInlineWrapTransaction;
200
+ export function siblingFocusIdForQuoteDelete(block, quoteBlockId) {
201
+ if (block.type !== 'blockquote')
202
+ return undefined;
203
+ const path = findQuoteBlockPath(block, quoteBlockId);
204
+ if (!path)
205
+ return undefined;
206
+ let parent = block;
207
+ for (let i = 0; i < path.length - 1; i++)
208
+ parent = parent.children[path[i]];
209
+ const idx = path[path.length - 1];
210
+ const chs = parent.children ?? [];
211
+ if (idx > 0)
212
+ return chs[idx - 1]?.id;
213
+ if (idx + 1 < chs.length)
214
+ return chs[idx + 1]?.id;
215
+ return undefined;
216
+ }
217
+ export function quoteParagraphReorderTransaction(source, doc, blockIndex, quotePath, fromIndex, toIndex, paragraphId) {
218
+ const block = doc.blocks[blockIndex];
219
+ if (!block || block.type !== 'blockquote')
220
+ return { ok: false, error: 'Expected blockquote.' };
221
+ return blockquoteMutationTransaction(source, doc, blockIndex, (root) => quoteMoveSibling(root, quotePath, fromIndex < toIndex ? 'down' : 'up'), `quote-reorder:${paragraphId}`, paragraphId);
222
+ }
223
+ function calloutMutationTransaction(source, doc, blockIndex, mutate, txId, caretBlockId) {
224
+ const block = doc.blocks[blockIndex];
225
+ if (!block || block.type !== 'callout')
226
+ return { ok: false, error: 'Expected callout block.' };
227
+ if (block.sourceRange.start < 0)
228
+ return { ok: false, error: 'Cannot edit synthetic callout.' };
229
+ const nextRoot = mutate(deepCloneBlocks([block])[0]);
230
+ if (!nextRoot)
231
+ return { ok: false, error: 'Callout edit failed.' };
232
+ const md = serializeEditorBlock(nextRoot, source);
233
+ let caret = block.sourceRange.start;
234
+ if (caretBlockId) {
235
+ const loc = findBlockLocation([nextRoot], caretBlockId);
236
+ if (loc?.block.sourceRange.start !== undefined && loc.block.sourceRange.start >= 0) {
237
+ caret = loc.block.sourceRange.start;
238
+ }
239
+ }
240
+ return sliceReplaceTransaction(source, { start: block.sourceRange.start, end: block.sourceRange.end }, md, caret, txId);
241
+ }
242
+ function calloutBlocksStructMutation(source, doc, calloutBlockIndex, draggedId, mutate, txId, caretBlockId) {
243
+ const oldCallout = doc.blocks[calloutBlockIndex];
244
+ if (!oldCallout || oldCallout.type !== 'callout')
245
+ return { ok: false, error: 'Expected callout.' };
246
+ if (oldCallout.sourceRange.start < 0)
247
+ return { ok: false, error: 'Cannot edit synthetic callout.' };
248
+ const clone = deepCloneBlocks(doc.blocks);
249
+ const nextBlocks = mutate(clone);
250
+ if (!nextBlocks)
251
+ return { ok: false, error: 'Callout edit failed.' };
252
+ let idx = calloutBlockIndex;
253
+ const newCallout = nextBlocks[idx];
254
+ if (!newCallout || newCallout.type !== 'callout') {
255
+ idx = nextBlocks.findIndex((b) => b.id === oldCallout.id);
256
+ if (idx < 0 || nextBlocks[idx]?.type !== 'callout') {
257
+ return { ok: false, error: 'Callout block lost after edit.' };
258
+ }
259
+ }
260
+ const liveCallout = nextBlocks[idx];
261
+ let spanStart = oldCallout.sourceRange.start;
262
+ let spanEnd = oldCallout.sourceRange.end;
263
+ if (nextBlocks.length !== doc.blocks.length && draggedId) {
264
+ const draggedOld = findBlockLocation(doc.blocks, draggedId);
265
+ if (draggedOld?.parent === null && draggedOld.topLevelIndex !== calloutBlockIndex) {
266
+ spanStart = Math.min(spanStart, draggedOld.block.sourceRange.start);
267
+ }
268
+ }
269
+ const parts = [serializeEditorBlock(liveCallout, source)];
270
+ let i = idx + 1;
271
+ while (i < nextBlocks.length) {
272
+ const b = nextBlocks[i];
273
+ const oldLoc = findBlockLocation(doc.blocks, b.id);
274
+ if (oldLoc?.topLevelIndex === calloutBlockIndex && oldLoc.parent?.id === oldCallout.id) {
275
+ parts.push(serializeEditorBlock(b, source));
276
+ const oldEnd = oldLoc.block.sourceRange.end;
277
+ if (oldEnd > spanEnd)
278
+ spanEnd = oldEnd;
279
+ i++;
280
+ continue;
281
+ }
282
+ break;
283
+ }
284
+ const md = parts.join('\n\n');
285
+ let caret = spanStart;
286
+ if (caretBlockId) {
287
+ const loc = findBlockLocation(nextBlocks, caretBlockId);
288
+ if (loc?.block.sourceRange.start !== undefined && loc.block.sourceRange.start >= 0) {
289
+ caret = loc.block.sourceRange.start;
290
+ }
291
+ }
292
+ return sliceReplaceTransaction(source, { start: spanStart, end: spanEnd }, md, caret, txId);
293
+ }
294
+ export function calloutStructMutationTransaction(source, doc, blockIndex, childBlockId, mutate, txId, caretBlockId) {
295
+ return calloutMutationTransaction(source, doc, blockIndex, mutate, txId, caretBlockId);
296
+ }
297
+ export function calloutExitTransaction(source, doc, blockIndex, rootAfterExit) {
298
+ const block = doc.blocks[blockIndex];
299
+ if (!block || block.type !== 'callout')
300
+ return { ok: false, error: 'Expected callout.' };
301
+ const calloutMd = serializeEditorBlock(rootAfterExit, source);
302
+ const { replacement, caret } = calloutExitReplacementMarkdown(calloutMd, block.sourceRange.start);
303
+ return sliceReplaceTransaction(source, { start: block.sourceRange.start, end: block.sourceRange.end }, replacement, caret, `callout-exit:${block.id}`);
304
+ }
305
+ export function moveCalloutChildSiblingTransaction(source, doc, blockIndex, childId, direction) {
306
+ return calloutMutationTransaction(source, doc, blockIndex, (root) => calloutMoveSibling(root, childId, direction), `callout-move-${direction}:${childId}`, childId);
307
+ }
308
+ export function deleteCalloutChildTransaction(source, doc, blockIndex, childId, focusAfterId) {
309
+ const block = doc.blocks[blockIndex];
310
+ if (!block || block.type !== 'callout')
311
+ return { ok: false, error: 'Expected callout.' };
312
+ return calloutMutationTransaction(source, doc, blockIndex, (root) => calloutDeleteChild(root, childId), `callout-delete:${childId}`, focusAfterId);
313
+ }
314
+ export function duplicateCalloutChildTransaction(source, doc, blockIndex, childId) {
315
+ const block = doc.blocks[blockIndex];
316
+ if (!block || block.type !== 'callout')
317
+ return { ok: false, error: 'Expected callout.' };
318
+ let duplicateId;
319
+ return calloutMutationTransaction(source, doc, blockIndex, (root) => {
320
+ const clone = deepCloneBlocks([root])[0];
321
+ const before = findBlockLocation([clone], childId);
322
+ const next = calloutDuplicateChild(clone, childId);
323
+ if (!next || !before)
324
+ return null;
325
+ const after = findBlockLocation([next], childId);
326
+ duplicateId = after?.siblings[before.index + 1]?.id;
327
+ return next;
328
+ }, `callout-duplicate:${childId}`, duplicateId);
329
+ }
330
+ export function calloutBodyTreeDropTransaction(source, doc, _blockIndex, draggedId, targetId, placement) {
331
+ return blockTreeDropTransaction(source, doc, draggedId, targetId, placement);
332
+ }
333
+ export function calloutDocumentStructMutation(source, doc, calloutBlockIndex, anchorBlockId, mutate, txId, caretBlockId) {
334
+ return calloutBlocksStructMutation(source, doc, calloutBlockIndex, undefined, mutate, txId, caretBlockId ?? anchorBlockId);
335
+ }
336
+ export { siblingFocusIdForCalloutDelete };
@@ -0,0 +1,2 @@
1
+ import type { EditorDocument } from './types';
2
+ export declare function parseMarkdownDocument(source: string, fileName?: string | null): EditorDocument;
@@ -0,0 +1,324 @@
1
+ import { buildBlockquoteAtDepth, parseBlockquoteLine, parseBlockquoteLineInfo } from '../block-specs/blockquote/parse';
2
+ import { buildListItemForest, parseListLine } from '../block-specs/list/parse';
3
+ import { paragraphBlocksFromLines } from '../block-specs/paragraph/parse';
4
+ import { tryParseCalloutAt } from '../block-specs/callout/parse';
5
+ import { isHorizontalRuleLine } from '../block-specs/horizontalRule/parse';
6
+ import { couldStartTableAt, tryParseTableAt } from '../block-specs/table/parse';
7
+ import { tryParseToggleAt } from '../block-specs/toggle/parse';
8
+ import { COLUMN_LINE_SCANNER, tryParseColumnsAt } from '../block-specs/columns/parse';
9
+ import { ATX_HEADING, stripClosingHashes } from '../block-specs/heading/parse';
10
+ import { tryParseTocAt, TOC_LINE } from '../block-specs/toc/parse';
11
+ import { collectExtensionSyntaxWarnings } from './extensionSyntaxWarnings';
12
+ import { collectToggleStructureWarnings, explainTableParseFailure } from './structureParseWarnings';
13
+ import { afterLineTerminator, splitLinesWithOffsets } from './line-utils';
14
+ import { stableBlockId } from './types';
15
+ /** Opening fence: optional indent, run of 3+ backticks, optional info (e.g. language). */
16
+ const FENCE_OPEN = /^(\s*)(`{3,})(.*)$/;
17
+ /** Callout opener `> [!type] Title` — must run before generic blockquotes. */
18
+ const CALLOUT_OPENER = /^\s*>\s*\[!([^\]]+)\]\s*(.*)$/;
19
+ const TOGGLE_OPEN = /^\s*\+\+\+\s+(.+)$/;
20
+ function parseLanguage(infoLine) {
21
+ const trimmed = infoLine.trim();
22
+ if (trimmed === '')
23
+ return null;
24
+ return trimmed.split(/\s+/)[0] ?? null;
25
+ }
26
+ /** Lines that look like an opening fence but never close before EOF. */
27
+ function collectUnclosedFenceWarnings(rows) {
28
+ const warns = [];
29
+ let i = 0;
30
+ while (i < rows.length) {
31
+ const open = rows[i].line.match(FENCE_OPEN);
32
+ if (!open) {
33
+ i++;
34
+ continue;
35
+ }
36
+ const fenceLen = open[2].length;
37
+ let j = i + 1;
38
+ while (j < rows.length) {
39
+ const close = rows[j].line.match(/^(\s*)(`{3,})\s*$/);
40
+ if (close && close[2].length >= fenceLen)
41
+ break;
42
+ j++;
43
+ }
44
+ if (j >= rows.length) {
45
+ warns.push(`Unclosed code fence starting at line ${i + 1}.`);
46
+ i++;
47
+ }
48
+ else {
49
+ i = j + 1;
50
+ }
51
+ }
52
+ return warns;
53
+ }
54
+ function collectFencedBlocks(source, rows) {
55
+ const out = [];
56
+ let i = 0;
57
+ while (i < rows.length) {
58
+ const open = rows[i].line.match(FENCE_OPEN);
59
+ if (!open) {
60
+ i++;
61
+ continue;
62
+ }
63
+ const fenceLen = open[2].length;
64
+ const lang = parseLanguage(open[3]);
65
+ const bodyLines = [];
66
+ let j = i + 1;
67
+ while (j < rows.length) {
68
+ const close = rows[j].line.match(/^(\s*)(`{3,})\s*$/);
69
+ if (close && close[2].length >= fenceLen)
70
+ break;
71
+ bodyLines.push(rows[j].line);
72
+ j++;
73
+ }
74
+ if (j >= rows.length) {
75
+ i++;
76
+ continue;
77
+ }
78
+ out.push({
79
+ openLine: i,
80
+ closeLine: j,
81
+ language: lang,
82
+ code: bodyLines.join('\n'),
83
+ startOffset: rows[i].start,
84
+ endOffset: afterLineTerminator(source, rows[j])
85
+ });
86
+ i = j + 1;
87
+ }
88
+ return out;
89
+ }
90
+ /* --------------------------------- main pass -------------------------------- */
91
+ export function parseMarkdownDocument(source, fileName = null) {
92
+ const rows = splitLinesWithOffsets(source);
93
+ const fenceWarnings = collectUnclosedFenceWarnings(rows);
94
+ const fences = collectFencedBlocks(source, rows);
95
+ const fenceAtOpenLine = new Map();
96
+ for (const f of fences)
97
+ fenceAtOpenLine.set(f.openLine, f);
98
+ const blocks = [];
99
+ const structureWarnings = [];
100
+ let i = 0;
101
+ while (i < rows.length) {
102
+ const fence = fenceAtOpenLine.get(i);
103
+ if (fence) {
104
+ const sourceRange = {
105
+ start: fence.startOffset,
106
+ end: fence.endOffset,
107
+ startLine: fence.openLine,
108
+ endLine: fence.closeLine
109
+ };
110
+ const data = {
111
+ kind: 'fenced',
112
+ language: fence.language,
113
+ code: fence.code,
114
+ startLine: fence.openLine
115
+ };
116
+ blocks.push({
117
+ type: 'codeFence',
118
+ id: stableBlockId('codeFence', sourceRange),
119
+ sourceRange,
120
+ data
121
+ });
122
+ i = fence.closeLine + 1;
123
+ continue;
124
+ }
125
+ const row = rows[i];
126
+ if (row.line.trim() === '' && row.line !== ' ') {
127
+ i++;
128
+ continue;
129
+ }
130
+ if (TOC_LINE.test(row.line)) {
131
+ const tocHit = tryParseTocAt(i, rows, source);
132
+ if (tocHit) {
133
+ blocks.push(tocHit.block);
134
+ i = tocHit.nextLine;
135
+ continue;
136
+ }
137
+ }
138
+ const hm = row.line.match(ATX_HEADING);
139
+ if (hm) {
140
+ const level = hm[2].length;
141
+ const text = stripClosingHashes(hm[4]).trim();
142
+ const sourceRange = {
143
+ start: row.start,
144
+ end: afterLineTerminator(source, row),
145
+ startLine: i,
146
+ endLine: i
147
+ };
148
+ const data = { level, text, lineIndex: i };
149
+ blocks.push({
150
+ type: 'heading',
151
+ id: stableBlockId('heading', sourceRange),
152
+ sourceRange,
153
+ data
154
+ });
155
+ i++;
156
+ continue;
157
+ }
158
+ if (isHorizontalRuleLine(row.line)) {
159
+ const sourceRange = {
160
+ start: row.start,
161
+ end: afterLineTerminator(source, row),
162
+ startLine: i,
163
+ endLine: i
164
+ };
165
+ const data = { lineIndex: i };
166
+ blocks.push({
167
+ type: 'horizontalRule',
168
+ id: stableBlockId('horizontalRule', sourceRange),
169
+ sourceRange,
170
+ data
171
+ });
172
+ i++;
173
+ continue;
174
+ }
175
+ const tableHit = tryParseTableAt(i, rows, source, fenceAtOpenLine);
176
+ if (tableHit) {
177
+ blocks.push(tableHit.block);
178
+ i = tableHit.nextLine;
179
+ continue;
180
+ }
181
+ const tableExplain = explainTableParseFailure(i, rows, fenceAtOpenLine);
182
+ if (tableExplain)
183
+ structureWarnings.push(tableExplain);
184
+ const calloutHit = tryParseCalloutAt(i, rows, source, fenceAtOpenLine);
185
+ if (calloutHit) {
186
+ blocks.push(calloutHit.block);
187
+ i = calloutHit.nextLine;
188
+ continue;
189
+ }
190
+ const toggleHit = tryParseToggleAt(i, rows, source, fenceAtOpenLine);
191
+ if (toggleHit) {
192
+ blocks.push(toggleHit.block);
193
+ i = toggleHit.nextLine;
194
+ continue;
195
+ }
196
+ const colHit = tryParseColumnsAt(i, rows, source, fenceAtOpenLine);
197
+ if (colHit) {
198
+ blocks.push(colHit.block);
199
+ i = colHit.nextLine;
200
+ continue;
201
+ }
202
+ if (parseBlockquoteLine(row.line)) {
203
+ const startLine = i;
204
+ const lineInfos = [];
205
+ while (i < rows.length) {
206
+ const info = parseBlockquoteLineInfo(rows[i], i, source);
207
+ if (!info)
208
+ break;
209
+ lineInfos.push(info);
210
+ i++;
211
+ }
212
+ if (lineInfos.length === 0)
213
+ continue;
214
+ const tree = buildBlockquoteAtDepth(lineInfos, 1, source);
215
+ const endLine = i - 1;
216
+ tree.sourceRange = {
217
+ start: rows[startLine].start,
218
+ end: afterLineTerminator(source, rows[endLine]),
219
+ startLine,
220
+ endLine
221
+ };
222
+ tree.id = stableBlockId('blockquote', tree.sourceRange);
223
+ blocks.push(tree);
224
+ continue;
225
+ }
226
+ const listHead = parseListLine(rows[i].line, i);
227
+ if (listHead) {
228
+ const startLine = i;
229
+ const chunk = [listHead];
230
+ i++;
231
+ while (i < rows.length) {
232
+ const raw = rows[i].line;
233
+ if (raw.trim() === '')
234
+ break;
235
+ const next = parseListLine(raw, i);
236
+ if (!next)
237
+ break;
238
+ chunk.push(next);
239
+ i++;
240
+ }
241
+ const endLine = i - 1;
242
+ const items = buildListItemForest(chunk, source, rows);
243
+ if (items.length === 0)
244
+ continue;
245
+ const fullStart = rows[startLine].start;
246
+ const fullEnd = afterLineTerminator(source, rows[endLine]);
247
+ items[0].sourceRange = {
248
+ ...items[0].sourceRange,
249
+ start: fullStart,
250
+ startLine
251
+ };
252
+ items[items.length - 1].sourceRange = {
253
+ ...items[items.length - 1].sourceRange,
254
+ end: fullEnd,
255
+ endLine
256
+ };
257
+ for (const item of items) {
258
+ item.id = stableBlockId('listItem', item.sourceRange);
259
+ blocks.push(item);
260
+ }
261
+ continue;
262
+ }
263
+ const pStart = i;
264
+ const buf = [];
265
+ while (i < rows.length) {
266
+ if (fenceAtOpenLine.has(i))
267
+ break;
268
+ const r = rows[i];
269
+ if (r.line.trim() === '' && r.line !== ' ')
270
+ break;
271
+ if (TOC_LINE.test(r.line))
272
+ break;
273
+ if (r.line.match(ATX_HEADING))
274
+ break;
275
+ if (isHorizontalRuleLine(r.line))
276
+ break;
277
+ if (couldStartTableAt(i, rows, fenceAtOpenLine))
278
+ break;
279
+ if (CALLOUT_OPENER.test(r.line))
280
+ break;
281
+ if (TOGGLE_OPEN.test(r.line))
282
+ break;
283
+ if (COLUMN_LINE_SCANNER.test(r.line))
284
+ break;
285
+ if (parseBlockquoteLine(r.line))
286
+ break;
287
+ if (parseListLine(r.line, i))
288
+ break;
289
+ buf.push(r.line);
290
+ i++;
291
+ }
292
+ if (buf.length === 0)
293
+ continue;
294
+ const paras = paragraphBlocksFromLines(buf, pStart);
295
+ let lineOffset = 0;
296
+ for (const para of paras) {
297
+ const numLines = para.lines.length;
298
+ const startLine = pStart + lineOffset;
299
+ const endLine = pStart + lineOffset + numLines - 1;
300
+ const sourceRange = {
301
+ start: rows[startLine].start,
302
+ end: afterLineTerminator(source, rows[endLine]),
303
+ startLine,
304
+ endLine
305
+ };
306
+ blocks.push({
307
+ type: 'paragraph',
308
+ id: stableBlockId('paragraph', sourceRange),
309
+ sourceRange,
310
+ data: para
311
+ });
312
+ lineOffset += numLines;
313
+ }
314
+ }
315
+ const fencePairs = fences.map((f) => ({ openLine: f.openLine, closeLine: f.closeLine }));
316
+ const fenceCharRanges = fences.map((f) => ({ start: f.startOffset, end: f.endOffset }));
317
+ const parseWarnings = [
318
+ ...fenceWarnings,
319
+ ...structureWarnings,
320
+ ...collectToggleStructureWarnings(rows, fenceAtOpenLine),
321
+ ...collectExtensionSyntaxWarnings(source, fencePairs, fenceCharRanges)
322
+ ];
323
+ return { source, fileName, blocks, parseWarnings };
324
+ }