@milkdown/crepe 7.8.0 → 7.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (304) hide show
  1. package/lib/cjs/confirm-CNveM9QH.js +26 -0
  2. package/lib/cjs/confirm-CNveM9QH.js.map +1 -0
  3. package/lib/cjs/edit-BUtBJHpV.js +24 -0
  4. package/lib/cjs/edit-BUtBJHpV.js.map +1 -0
  5. package/lib/cjs/functions-BAY51plB.js +39 -0
  6. package/lib/cjs/functions-BAY51plB.js.map +1 -0
  7. package/lib/cjs/image-BXLkOVnO.js +24 -0
  8. package/lib/cjs/image-BXLkOVnO.js.map +1 -0
  9. package/lib/cjs/{index-DAiGM2G1.js → index-B7gqgc1H.js} +484 -204
  10. package/lib/cjs/index-B7gqgc1H.js.map +1 -0
  11. package/lib/cjs/{index-Dub20F3z.js → index-B91KhPew.js} +4 -4
  12. package/lib/cjs/index-B91KhPew.js.map +1 -0
  13. package/lib/cjs/{index-nrFkJeLW.js → index-BsrJn8Jp.js} +22 -7
  14. package/lib/cjs/index-BsrJn8Jp.js.map +1 -0
  15. package/lib/cjs/{index-BReSN-JQ.js → index-C2CAbC2F.js} +2 -2
  16. package/lib/cjs/{index-BReSN-JQ.js.map → index-C2CAbC2F.js.map} +1 -1
  17. package/lib/cjs/{index-CGies6Iv.js → index-CnyNb_OH.js} +45 -45
  18. package/lib/cjs/index-CnyNb_OH.js.map +1 -0
  19. package/lib/cjs/{index-CJdEvN3_.js → index-CoTb-QdE.js} +123 -105
  20. package/lib/cjs/index-CoTb-QdE.js.map +1 -0
  21. package/lib/cjs/index-DEs_IHHy.js +91 -0
  22. package/lib/cjs/index-DEs_IHHy.js.map +1 -0
  23. package/lib/cjs/index-DGAwtnNK.js +349 -0
  24. package/lib/cjs/index-DGAwtnNK.js.map +1 -0
  25. package/lib/cjs/index-DLIudQKW.js +126 -0
  26. package/lib/cjs/index-DLIudQKW.js.map +1 -0
  27. package/lib/cjs/index-Dw6lXgs6.js +81 -0
  28. package/lib/cjs/index-Dw6lXgs6.js.map +1 -0
  29. package/lib/cjs/{index-AlHHvSR_.js → index-xbwf60wt.js} +1 -6
  30. package/lib/cjs/{index-AlHHvSR_.js.map → index-xbwf60wt.js.map} +1 -1
  31. package/lib/cjs/{index-CvmlYYXX.js → index-xbxqAqH2.js} +21 -7
  32. package/lib/cjs/index-xbxqAqH2.js.map +1 -0
  33. package/lib/cjs/index.js +6 -6
  34. package/lib/cjs/plus-XLomtlXf.js +24 -0
  35. package/lib/cjs/plus-XLomtlXf.js.map +1 -0
  36. package/lib/cjs/remove-Ba-ypwBf.js +17 -0
  37. package/lib/cjs/remove-Ba-ypwBf.js.map +1 -0
  38. package/lib/esm/confirm-DtE-HkVd.js +24 -0
  39. package/lib/esm/confirm-DtE-HkVd.js.map +1 -0
  40. package/lib/esm/edit-D--t_JAb.js +22 -0
  41. package/lib/esm/edit-D--t_JAb.js.map +1 -0
  42. package/lib/esm/functions-DlJPkGmE.js +36 -0
  43. package/lib/esm/functions-DlJPkGmE.js.map +1 -0
  44. package/lib/esm/image-DoB1o1sl.js +22 -0
  45. package/lib/esm/image-DoB1o1sl.js.map +1 -0
  46. package/lib/esm/index-BAQT-9au.js +347 -0
  47. package/lib/esm/index-BAQT-9au.js.map +1 -0
  48. package/lib/esm/{index-DOrkOhki.js → index-BCvtgOeI.js} +4 -4
  49. package/lib/esm/index-BCvtgOeI.js.map +1 -0
  50. package/lib/esm/{index-x2oo_GmY.js → index-BDZ_pnSv.js} +122 -104
  51. package/lib/esm/index-BDZ_pnSv.js.map +1 -0
  52. package/lib/esm/{index-D6fLMv29.js → index-BPG8iO8t.js} +2 -6
  53. package/lib/esm/{index-D6fLMv29.js.map → index-BPG8iO8t.js.map} +1 -1
  54. package/lib/esm/{index-DcRgwPLd.js → index-BUBXHhHG.js} +18 -3
  55. package/lib/esm/index-BUBXHhHG.js.map +1 -0
  56. package/lib/esm/{index-CsYl2WR5.js → index-Bvz1Yyiz.js} +2 -2
  57. package/lib/esm/{index-CsYl2WR5.js.map → index-Bvz1Yyiz.js.map} +1 -1
  58. package/lib/esm/index-C1aVAv1l.js +124 -0
  59. package/lib/esm/index-C1aVAv1l.js.map +1 -0
  60. package/lib/esm/{index-CEOsxgzJ.js → index-CM4urRY9.js} +470 -190
  61. package/lib/esm/index-CM4urRY9.js.map +1 -0
  62. package/lib/esm/{index-BFsG6770.js → index-ChR5Qhyf.js} +17 -3
  63. package/lib/esm/index-ChR5Qhyf.js.map +1 -0
  64. package/lib/esm/index-CwMVnVeI.js +89 -0
  65. package/lib/esm/index-CwMVnVeI.js.map +1 -0
  66. package/lib/esm/{index-BwTxn2hs.js → index-Dc_wWopW.js} +46 -46
  67. package/lib/esm/index-Dc_wWopW.js.map +1 -0
  68. package/lib/esm/index-E8UgFLeN.js +79 -0
  69. package/lib/esm/index-E8UgFLeN.js.map +1 -0
  70. package/lib/esm/index.js +6 -6
  71. package/lib/esm/plus-lrX0Q75O.js +22 -0
  72. package/lib/esm/plus-lrX0Q75O.js.map +1 -0
  73. package/lib/esm/remove-D3g0Cd6_.js +15 -0
  74. package/lib/esm/remove-D3g0Cd6_.js.map +1 -0
  75. package/lib/theme/_internal/classic-common.css +6 -0
  76. package/lib/theme/common/block-edit.css +23 -23
  77. package/lib/theme/common/code-mirror.css +43 -44
  78. package/lib/theme/common/image-block.css +79 -81
  79. package/lib/theme/common/latex.css +6 -6
  80. package/lib/theme/common/link-tooltip.css +21 -21
  81. package/lib/theme/common/list-item.css +11 -10
  82. package/lib/theme/common/table.css +39 -39
  83. package/lib/theme/common/toolbar.css +8 -8
  84. package/lib/tsconfig.tsbuildinfo +1 -0
  85. package/lib/types/core/crepe.d.ts +6 -6
  86. package/lib/types/core/crepe.d.ts.map +1 -1
  87. package/lib/types/core/slice.d.ts.map +1 -1
  88. package/lib/types/feature/block-edit/handle/component.d.ts +4 -8
  89. package/lib/types/feature/block-edit/handle/component.d.ts.map +1 -1
  90. package/lib/types/feature/block-edit/handle/index.d.ts +1 -1
  91. package/lib/types/feature/block-edit/handle/index.d.ts.map +1 -1
  92. package/lib/types/feature/block-edit/index.d.ts.map +1 -1
  93. package/lib/types/feature/block-edit/menu/component.d.ts +8 -11
  94. package/lib/types/feature/block-edit/menu/component.d.ts.map +1 -1
  95. package/lib/types/feature/block-edit/menu/config.d.ts.map +1 -1
  96. package/lib/types/feature/block-edit/menu/index.d.ts.map +1 -1
  97. package/lib/types/feature/block-edit/menu/utils.d.ts +2 -3
  98. package/lib/types/feature/block-edit/menu/utils.d.ts.map +1 -1
  99. package/lib/types/feature/code-mirror/index.d.ts +3 -4
  100. package/lib/types/feature/code-mirror/index.d.ts.map +1 -1
  101. package/lib/types/feature/cursor/index.d.ts.map +1 -1
  102. package/lib/types/feature/image-block/index.d.ts.map +1 -1
  103. package/lib/types/feature/index.d.ts +4 -4
  104. package/lib/types/feature/index.d.ts.map +1 -1
  105. package/lib/types/feature/latex/index.d.ts.map +1 -1
  106. package/lib/types/feature/latex/inline-tooltip/component.d.ts +6 -10
  107. package/lib/types/feature/latex/inline-tooltip/component.d.ts.map +1 -1
  108. package/lib/types/feature/latex/inline-tooltip/view.d.ts.map +1 -1
  109. package/lib/types/feature/latex/input-rule.d.ts.map +1 -1
  110. package/lib/types/feature/latex/remark.d.ts.map +1 -1
  111. package/lib/types/feature/link-tooltip/index.d.ts.map +1 -1
  112. package/lib/types/feature/list-item/index.d.ts.map +1 -1
  113. package/lib/types/feature/placeholder/index.d.ts.map +1 -1
  114. package/lib/types/feature/shared.d.ts +1 -2
  115. package/lib/types/feature/shared.d.ts.map +1 -1
  116. package/lib/types/feature/table/index.d.ts.map +1 -1
  117. package/lib/types/feature/toolbar/component.d.ts +9 -12
  118. package/lib/types/feature/toolbar/component.d.ts.map +1 -1
  119. package/lib/types/feature/toolbar/index.d.ts.map +1 -1
  120. package/lib/types/icons/align-center.d.ts +1 -1
  121. package/lib/types/icons/align-center.d.ts.map +1 -1
  122. package/lib/types/icons/align-left.d.ts +1 -1
  123. package/lib/types/icons/align-left.d.ts.map +1 -1
  124. package/lib/types/icons/align-right.d.ts +1 -1
  125. package/lib/types/icons/align-right.d.ts.map +1 -1
  126. package/lib/types/icons/bold.d.ts +1 -1
  127. package/lib/types/icons/bold.d.ts.map +1 -1
  128. package/lib/types/icons/bullet-list.d.ts +1 -1
  129. package/lib/types/icons/bullet-list.d.ts.map +1 -1
  130. package/lib/types/icons/bullet.d.ts +1 -1
  131. package/lib/types/icons/bullet.d.ts.map +1 -1
  132. package/lib/types/icons/caption.d.ts +1 -1
  133. package/lib/types/icons/caption.d.ts.map +1 -1
  134. package/lib/types/icons/check-box-checked.d.ts +1 -1
  135. package/lib/types/icons/check-box-checked.d.ts.map +1 -1
  136. package/lib/types/icons/check-box-unchecked.d.ts +1 -1
  137. package/lib/types/icons/check-box-unchecked.d.ts.map +1 -1
  138. package/lib/types/icons/chevron-down.d.ts +1 -1
  139. package/lib/types/icons/chevron-down.d.ts.map +1 -1
  140. package/lib/types/icons/clear.d.ts +1 -1
  141. package/lib/types/icons/clear.d.ts.map +1 -1
  142. package/lib/types/icons/code.d.ts +1 -1
  143. package/lib/types/icons/code.d.ts.map +1 -1
  144. package/lib/types/icons/confirm.d.ts +1 -1
  145. package/lib/types/icons/confirm.d.ts.map +1 -1
  146. package/lib/types/icons/copy.d.ts +1 -1
  147. package/lib/types/icons/copy.d.ts.map +1 -1
  148. package/lib/types/icons/divider.d.ts +1 -1
  149. package/lib/types/icons/divider.d.ts.map +1 -1
  150. package/lib/types/icons/drag-handle.d.ts +1 -1
  151. package/lib/types/icons/drag-handle.d.ts.map +1 -1
  152. package/lib/types/icons/edit.d.ts +1 -1
  153. package/lib/types/icons/edit.d.ts.map +1 -1
  154. package/lib/types/icons/functions.d.ts +1 -1
  155. package/lib/types/icons/functions.d.ts.map +1 -1
  156. package/lib/types/icons/h1.d.ts +1 -1
  157. package/lib/types/icons/h1.d.ts.map +1 -1
  158. package/lib/types/icons/h2.d.ts +1 -1
  159. package/lib/types/icons/h2.d.ts.map +1 -1
  160. package/lib/types/icons/h3.d.ts +1 -1
  161. package/lib/types/icons/h3.d.ts.map +1 -1
  162. package/lib/types/icons/h4.d.ts +1 -1
  163. package/lib/types/icons/h4.d.ts.map +1 -1
  164. package/lib/types/icons/h5.d.ts +1 -1
  165. package/lib/types/icons/h5.d.ts.map +1 -1
  166. package/lib/types/icons/h6.d.ts +1 -1
  167. package/lib/types/icons/h6.d.ts.map +1 -1
  168. package/lib/types/icons/image.d.ts +1 -1
  169. package/lib/types/icons/image.d.ts.map +1 -1
  170. package/lib/types/icons/italic.d.ts +1 -1
  171. package/lib/types/icons/italic.d.ts.map +1 -1
  172. package/lib/types/icons/link.d.ts +1 -1
  173. package/lib/types/icons/link.d.ts.map +1 -1
  174. package/lib/types/icons/menu.d.ts +1 -1
  175. package/lib/types/icons/menu.d.ts.map +1 -1
  176. package/lib/types/icons/ordered-list.d.ts +1 -1
  177. package/lib/types/icons/ordered-list.d.ts.map +1 -1
  178. package/lib/types/icons/plus.d.ts +1 -1
  179. package/lib/types/icons/plus.d.ts.map +1 -1
  180. package/lib/types/icons/quote.d.ts +1 -1
  181. package/lib/types/icons/quote.d.ts.map +1 -1
  182. package/lib/types/icons/remove.d.ts +1 -1
  183. package/lib/types/icons/remove.d.ts.map +1 -1
  184. package/lib/types/icons/search.d.ts +1 -1
  185. package/lib/types/icons/search.d.ts.map +1 -1
  186. package/lib/types/icons/strikethrough.d.ts +1 -1
  187. package/lib/types/icons/strikethrough.d.ts.map +1 -1
  188. package/lib/types/icons/table.d.ts +1 -1
  189. package/lib/types/icons/table.d.ts.map +1 -1
  190. package/lib/types/icons/text.d.ts +1 -1
  191. package/lib/types/icons/text.d.ts.map +1 -1
  192. package/lib/types/icons/todo-list.d.ts +1 -1
  193. package/lib/types/icons/todo-list.d.ts.map +1 -1
  194. package/lib/types/icons/visibility-off.d.ts +1 -1
  195. package/lib/types/icons/visibility-off.d.ts.map +1 -1
  196. package/package.json +4 -26
  197. package/src/core/crepe.ts +13 -12
  198. package/src/core/slice.ts +2 -0
  199. package/src/feature/block-edit/handle/component.tsx +60 -0
  200. package/src/feature/block-edit/handle/index.ts +22 -14
  201. package/src/feature/block-edit/index.ts +3 -1
  202. package/src/feature/block-edit/menu/component.tsx +237 -0
  203. package/src/feature/block-edit/menu/config.ts +6 -3
  204. package/src/feature/block-edit/menu/index.ts +38 -18
  205. package/src/feature/block-edit/menu/utils.ts +3 -3
  206. package/src/feature/code-mirror/index.ts +20 -20
  207. package/src/feature/cursor/index.ts +1 -1
  208. package/src/feature/image-block/index.ts +3 -1
  209. package/src/feature/index.ts +5 -4
  210. package/src/feature/latex/index.ts +8 -8
  211. package/src/feature/latex/inline-tooltip/component.tsx +57 -0
  212. package/src/feature/latex/inline-tooltip/view.ts +30 -17
  213. package/src/feature/latex/input-rule.ts +4 -3
  214. package/src/feature/latex/remark.ts +3 -2
  215. package/src/feature/link-tooltip/index.ts +3 -1
  216. package/src/feature/list-item/index.ts +8 -16
  217. package/src/feature/placeholder/index.ts +6 -3
  218. package/src/feature/shared.ts +1 -2
  219. package/src/feature/table/index.ts +2 -0
  220. package/src/feature/toolbar/component.tsx +256 -0
  221. package/src/feature/toolbar/index.ts +34 -17
  222. package/src/icons/align-center.ts +1 -3
  223. package/src/icons/align-left.ts +1 -3
  224. package/src/icons/align-right.ts +1 -3
  225. package/src/icons/bold.ts +1 -3
  226. package/src/icons/bullet-list.ts +1 -3
  227. package/src/icons/bullet.ts +1 -3
  228. package/src/icons/caption.ts +1 -3
  229. package/src/icons/check-box-checked.ts +1 -3
  230. package/src/icons/check-box-unchecked.ts +1 -3
  231. package/src/icons/chevron-down.ts +1 -3
  232. package/src/icons/clear.ts +1 -3
  233. package/src/icons/code.ts +1 -3
  234. package/src/icons/confirm.ts +1 -3
  235. package/src/icons/copy.ts +1 -3
  236. package/src/icons/divider.ts +1 -3
  237. package/src/icons/drag-handle.ts +1 -3
  238. package/src/icons/edit.ts +1 -3
  239. package/src/icons/functions.ts +1 -3
  240. package/src/icons/h1.ts +1 -3
  241. package/src/icons/h2.ts +1 -3
  242. package/src/icons/h3.ts +1 -3
  243. package/src/icons/h4.ts +1 -3
  244. package/src/icons/h5.ts +1 -3
  245. package/src/icons/h6.ts +1 -3
  246. package/src/icons/image.ts +1 -3
  247. package/src/icons/italic.ts +1 -3
  248. package/src/icons/link.ts +1 -3
  249. package/src/icons/menu.ts +1 -3
  250. package/src/icons/ordered-list.ts +1 -3
  251. package/src/icons/plus.ts +1 -3
  252. package/src/icons/quote.ts +1 -3
  253. package/src/icons/remove.ts +1 -3
  254. package/src/icons/search.ts +1 -3
  255. package/src/icons/strikethrough.ts +1 -3
  256. package/src/icons/table.ts +1 -3
  257. package/src/icons/text.ts +1 -3
  258. package/src/icons/todo-list.ts +1 -3
  259. package/src/icons/visibility-off.ts +1 -3
  260. package/src/theme/_internal/classic-common.css +6 -0
  261. package/src/theme/common/block-edit.css +2 -2
  262. package/src/theme/common/code-mirror.css +5 -6
  263. package/src/theme/common/image-block.css +9 -11
  264. package/src/theme/common/latex.css +1 -1
  265. package/src/theme/common/link-tooltip.css +2 -2
  266. package/src/theme/common/list-item.css +3 -2
  267. package/src/theme/common/table.css +2 -2
  268. package/src/theme/common/toolbar.css +1 -1
  269. package/lib/cjs/functions-Dk90yOUc.js +0 -690
  270. package/lib/cjs/functions-Dk90yOUc.js.map +0 -1
  271. package/lib/cjs/index-CGies6Iv.js.map +0 -1
  272. package/lib/cjs/index-CJdEvN3_.js.map +0 -1
  273. package/lib/cjs/index-CvmlYYXX.js.map +0 -1
  274. package/lib/cjs/index-D3lu92SA.js +0 -39
  275. package/lib/cjs/index-D3lu92SA.js.map +0 -1
  276. package/lib/cjs/index-DAiGM2G1.js.map +0 -1
  277. package/lib/cjs/index-DKY_Kri2.js +0 -272
  278. package/lib/cjs/index-DKY_Kri2.js.map +0 -1
  279. package/lib/cjs/index-DQll67YS.js +0 -65
  280. package/lib/cjs/index-DQll67YS.js.map +0 -1
  281. package/lib/cjs/index-Dub20F3z.js.map +0 -1
  282. package/lib/cjs/index-hPk2gbSt.js +0 -35
  283. package/lib/cjs/index-hPk2gbSt.js.map +0 -1
  284. package/lib/cjs/index-nrFkJeLW.js.map +0 -1
  285. package/lib/esm/functions-Bsik6ikd.js +0 -652
  286. package/lib/esm/functions-Bsik6ikd.js.map +0 -1
  287. package/lib/esm/index-B3KiKTSt.js +0 -63
  288. package/lib/esm/index-B3KiKTSt.js.map +0 -1
  289. package/lib/esm/index-BFsG6770.js.map +0 -1
  290. package/lib/esm/index-BwTxn2hs.js.map +0 -1
  291. package/lib/esm/index-CBrOT1fW.js +0 -37
  292. package/lib/esm/index-CBrOT1fW.js.map +0 -1
  293. package/lib/esm/index-CEOsxgzJ.js.map +0 -1
  294. package/lib/esm/index-Cuk7cL-r.js +0 -33
  295. package/lib/esm/index-Cuk7cL-r.js.map +0 -1
  296. package/lib/esm/index-DOrkOhki.js.map +0 -1
  297. package/lib/esm/index-DcRgwPLd.js.map +0 -1
  298. package/lib/esm/index-H9uklzH0.js +0 -270
  299. package/lib/esm/index-H9uklzH0.js.map +0 -1
  300. package/lib/esm/index-x2oo_GmY.js.map +0 -1
  301. package/src/feature/block-edit/handle/component.ts +0 -54
  302. package/src/feature/block-edit/menu/component.ts +0 -241
  303. package/src/feature/latex/inline-tooltip/component.ts +0 -38
  304. package/src/feature/toolbar/component.ts +0 -236
@@ -1,26 +1,41 @@
1
1
  import type { Ctx } from '@milkdown/kit/ctx'
2
- import { TooltipProvider } from '@milkdown/kit/plugin/tooltip'
3
2
  import type { PluginView } from '@milkdown/kit/prose/state'
3
+
4
+ import { TooltipProvider } from '@milkdown/kit/plugin/tooltip'
5
+ import { redo, undo } from '@milkdown/kit/prose/history'
6
+ import { keymap } from '@milkdown/kit/prose/keymap'
7
+ import { Schema } from '@milkdown/kit/prose/model'
4
8
  import { EditorState, NodeSelection } from '@milkdown/kit/prose/state'
5
9
  import { EditorView } from '@milkdown/kit/prose/view'
6
- import { mathInlineId } from '../inline-latex'
7
- import { LatexInlineEditElement } from './component'
10
+ import { createApp, shallowRef, type App, type ShallowRef } from 'vue'
11
+
8
12
  import type { LatexConfig } from '..'
9
- import { keymap } from '@milkdown/kit/prose/keymap'
10
- import { redo, undo } from '@milkdown/kit/prose/history'
11
- import { Schema } from '@milkdown/kit/prose/model'
13
+
14
+ import { mathInlineId } from '../inline-latex'
15
+ import { LatexTooltip } from './component'
12
16
 
13
17
  export class LatexInlineTooltip implements PluginView {
14
- #content = new LatexInlineEditElement()
18
+ #content: HTMLElement
15
19
  #provider: TooltipProvider
16
20
  #dom: HTMLElement
17
- #innerView: EditorView | null
21
+ #innerView: ShallowRef<EditorView | null> = shallowRef(null)
22
+ #updateValue: ShallowRef<() => void> = shallowRef(() => {})
23
+ #app: App
18
24
 
19
25
  constructor(
20
26
  readonly ctx: Ctx,
21
27
  view: EditorView,
22
28
  config: Partial<LatexConfig>
23
29
  ) {
30
+ const content = document.createElement('div')
31
+ content.className = 'milkdown-latex-inline-edit'
32
+ this.#content = content
33
+ this.#app = createApp(LatexTooltip, {
34
+ config,
35
+ innerView: this.#innerView,
36
+ updateValue: this.#updateValue,
37
+ })
38
+ this.#app.mount(content)
24
39
  this.#provider = new TooltipProvider({
25
40
  debounce: 0,
26
41
  content: this.#content,
@@ -30,16 +45,14 @@ export class LatexInlineTooltip implements PluginView {
30
45
  placement: 'bottom',
31
46
  },
32
47
  })
33
- this.#content.config = config
34
48
  this.#provider.update(view)
35
49
  this.#dom = document.createElement('div')
36
- this.#innerView = null
37
50
  }
38
51
 
39
52
  #onHide = () => {
40
- if (this.#innerView) {
41
- this.#innerView.destroy()
42
- this.#innerView = null
53
+ if (this.#innerView.value) {
54
+ this.#innerView.value.destroy()
55
+ this.#innerView.value = null
43
56
  }
44
57
  }
45
58
 
@@ -85,7 +98,7 @@ export class LatexInlineTooltip implements PluginView {
85
98
  'Mod-Z': redo,
86
99
  'Mod-y': redo,
87
100
  Enter: () => {
88
- this.#content.updateValue?.()
101
+ this.#updateValue.value()
89
102
  return true
90
103
  },
91
104
  }),
@@ -93,9 +106,8 @@ export class LatexInlineTooltip implements PluginView {
93
106
  }),
94
107
  })
95
108
 
96
- this.#innerView = innerView
97
- this.#content.innerView = this.#innerView
98
- this.#content.updateValue = () => {
109
+ this.#innerView.value = innerView
110
+ this.#updateValue.value = () => {
99
111
  const { tr } = view.state
100
112
  tr.setNodeAttribute(textFrom, 'value', innerView.state.doc.textContent)
101
113
  view.dispatch(tr)
@@ -116,6 +128,7 @@ export class LatexInlineTooltip implements PluginView {
116
128
  }
117
129
 
118
130
  destroy = () => {
131
+ this.#app.unmount()
119
132
  this.#provider.destroy()
120
133
  this.#content.remove()
121
134
  }
@@ -1,8 +1,9 @@
1
- import { $inputRule } from '@milkdown/kit/utils'
2
- import { nodeRule } from '@milkdown/kit/prose'
3
- import { mathInlineSchema } from './inline-latex'
4
1
  import { codeBlockSchema } from '@milkdown/kit/preset/commonmark'
2
+ import { nodeRule } from '@milkdown/kit/prose'
5
3
  import { textblockTypeInputRule } from '@milkdown/kit/prose/inputrules'
4
+ import { $inputRule } from '@milkdown/kit/utils'
5
+
6
+ import { mathInlineSchema } from './inline-latex'
6
7
 
7
8
  /// Input rule for inline math.
8
9
  /// When you type $E=MC^2$, it will create an inline math node.
@@ -1,6 +1,7 @@
1
- import remarkMath from 'remark-math'
2
- import { $remark } from '@milkdown/kit/utils'
3
1
  import type { Node } from '@milkdown/kit/transformer'
2
+
3
+ import { $remark } from '@milkdown/kit/utils'
4
+ import remarkMath from 'remark-math'
4
5
  import { visit } from 'unist-util-visit'
5
6
 
6
7
  export const remarkMathPlugin = $remark<'remarkMath', undefined>(
@@ -3,8 +3,10 @@ import {
3
3
  linkTooltipConfig,
4
4
  linkTooltipPlugin,
5
5
  } from '@milkdown/kit/component/link-tooltip'
6
+
6
7
  import type { DefineFeature, Icon } from '../shared'
7
- import { confirmIcon, copyIcon, editIcon, removeIcon } from '../../icons'
8
+
9
+ import { copyIcon, editIcon, removeIcon, confirmIcon } from '../../icons'
8
10
 
9
11
  interface LinkTooltipConfig {
10
12
  linkIcon: Icon
@@ -1,11 +1,12 @@
1
1
  import type { Ctx } from '@milkdown/kit/ctx'
2
+
2
3
  import {
3
4
  listItemBlockComponent,
4
5
  listItemBlockConfig,
5
6
  } from '@milkdown/kit/component/list-item-block'
6
- import { html } from 'atomico'
7
- import clsx from 'clsx'
7
+
8
8
  import type { DefineFeature, Icon } from '../shared'
9
+
9
10
  import {
10
11
  bulletIcon,
11
12
  checkBoxCheckedIcon,
@@ -22,25 +23,16 @@ export type ListItemFeatureConfig = Partial<ListItemConfig>
22
23
 
23
24
  function configureListItem(ctx: Ctx, config?: ListItemFeatureConfig) {
24
25
  ctx.set(listItemBlockConfig.key, {
25
- renderLabel: ({ label, listType, checked, readonly }) => {
26
+ renderLabel: ({ label, listType, checked }) => {
26
27
  if (checked == null) {
27
- if (listType === 'bullet')
28
- return html`<span class="label"
29
- >${config?.bulletIcon?.() ?? bulletIcon}</span
30
- >`
28
+ if (listType === 'bullet') return config?.bulletIcon?.() ?? bulletIcon
31
29
 
32
- return html`<span class="label">${label}</span>`
30
+ return label
33
31
  }
34
32
 
35
- if (checked)
36
- return html`<span
37
- class=${clsx('label checkbox', readonly && 'readonly')}
38
- >${config?.checkBoxCheckedIcon?.() ?? checkBoxCheckedIcon}</span
39
- >`
33
+ if (checked) return config?.checkBoxCheckedIcon?.() ?? checkBoxCheckedIcon
40
34
 
41
- return html`<span class=${clsx('label checkbox', readonly && 'readonly')}
42
- >${config?.checkBoxUncheckedIcon?.() ?? checkBoxUncheckedIcon}</span
43
- >`
35
+ return config?.checkBoxUncheckedIcon?.() ?? checkBoxUncheckedIcon
44
36
  },
45
37
  })
46
38
  }
@@ -1,10 +1,13 @@
1
- import { $ctx, $prose } from '@milkdown/kit/utils'
1
+ import type { Node } from '@milkdown/kit/prose/model'
2
2
  import type { EditorState } from '@milkdown/kit/prose/state'
3
+
4
+ import { findParent } from '@milkdown/kit/prose'
3
5
  import { Plugin, PluginKey } from '@milkdown/kit/prose/state'
4
- import type { Node } from '@milkdown/kit/prose/model'
5
6
  import { Decoration, DecorationSet } from '@milkdown/kit/prose/view'
6
- import { findParent } from '@milkdown/kit/prose'
7
+ import { $ctx, $prose } from '@milkdown/kit/utils'
8
+
7
9
  import type { DefineFeature } from '../shared'
10
+
8
11
  import { isInCodeBlock, isInList } from '../../utils'
9
12
 
10
13
  function isDocEmpty(doc: Node) {
@@ -1,9 +1,8 @@
1
1
  import type { Editor } from '@milkdown/kit/core'
2
- import type { html } from 'atomico'
3
2
 
4
3
  export type DefineFeature<Config = unknown> = (
5
4
  editor: Editor,
6
5
  config?: Config
7
6
  ) => void | Promise<void>
8
7
 
9
- export type Icon = () => ReturnType<typeof html> | string | null
8
+ export type Icon = () => string
@@ -2,7 +2,9 @@ import {
2
2
  tableBlock,
3
3
  tableBlockConfig,
4
4
  } from '@milkdown/kit/component/table-block'
5
+
5
6
  import type { DefineFeature, Icon } from '../shared'
7
+
6
8
  import {
7
9
  alignCenterIcon,
8
10
  alignLeftIcon,
@@ -0,0 +1,256 @@
1
+ import type { Ctx } from '@milkdown/kit/ctx'
2
+ import type { MarkType, NodeType, Node } from '@milkdown/kit/prose/model'
3
+
4
+ import { Icon } from '@milkdown/kit/component'
5
+ import { linkTooltipAPI } from '@milkdown/kit/component/link-tooltip'
6
+ import { commandsCtx, editorViewCtx } from '@milkdown/kit/core'
7
+ import {
8
+ emphasisSchema,
9
+ inlineCodeSchema,
10
+ linkSchema,
11
+ strongSchema,
12
+ toggleEmphasisCommand,
13
+ toggleInlineCodeCommand,
14
+ toggleStrongCommand,
15
+ } from '@milkdown/kit/preset/commonmark'
16
+ import {
17
+ strikethroughSchema,
18
+ toggleStrikethroughCommand,
19
+ } from '@milkdown/kit/preset/gfm'
20
+ import {
21
+ NodeSelection,
22
+ TextSelection,
23
+ type Selection,
24
+ } from '@milkdown/kit/prose/state'
25
+ import clsx from 'clsx'
26
+ import { defineComponent, type Ref, type ShallowRef, h, Fragment } from 'vue'
27
+
28
+ import type { ToolbarFeatureConfig } from '.'
29
+
30
+ import { CrepeFeature } from '../..'
31
+ import { FeaturesCtx } from '../../core/slice'
32
+ import {
33
+ boldIcon,
34
+ codeIcon,
35
+ functionsIcon,
36
+ italicIcon,
37
+ linkIcon,
38
+ strikethroughIcon,
39
+ } from '../../icons'
40
+ import { mathInlineSchema } from '../latex/inline-latex'
41
+
42
+ h
43
+ Fragment
44
+
45
+ type ToolbarProps = {
46
+ ctx: Ctx
47
+ hide: () => void
48
+ show: Ref<boolean>
49
+ selection: ShallowRef<Selection>
50
+ config?: ToolbarFeatureConfig
51
+ }
52
+
53
+ export const Toolbar = defineComponent<ToolbarProps>({
54
+ props: {
55
+ ctx: {
56
+ type: Object,
57
+ required: true,
58
+ },
59
+ hide: {
60
+ type: Function,
61
+ required: true,
62
+ },
63
+ show: {
64
+ type: Object,
65
+ required: true,
66
+ },
67
+ selection: {
68
+ type: Object,
69
+ required: true,
70
+ },
71
+ config: {
72
+ type: Object,
73
+ required: false,
74
+ },
75
+ },
76
+ setup(props) {
77
+ const { ctx, hide, config } = props
78
+
79
+ const onClick = (fn: (ctx: Ctx) => void) => (e: MouseEvent) => {
80
+ e.preventDefault()
81
+ ctx && fn(ctx)
82
+ }
83
+
84
+ const isActive = (mark: MarkType) => {
85
+ const selection = props.selection.value
86
+ if (!ctx || !selection) return false
87
+ const { state } = ctx.get(editorViewCtx)
88
+ if (!state) return false
89
+ const { doc } = state
90
+ return doc.rangeHasMark(selection.from, selection.to, mark)
91
+ }
92
+
93
+ const containsNode = (node: NodeType) => {
94
+ const selection = props.selection.value
95
+ if (!ctx || !selection) return false
96
+ const { state } = ctx.get(editorViewCtx)
97
+ if (!state) return false
98
+ const { doc } = state
99
+ if (selection instanceof NodeSelection) {
100
+ return selection.node.type === node
101
+ }
102
+
103
+ const { from, to } = selection
104
+
105
+ let hasNode = false
106
+ doc.nodesBetween(from, to, (n) => {
107
+ if (n.type === node) {
108
+ hasNode = true
109
+ return false
110
+ }
111
+ return true
112
+ })
113
+
114
+ return hasNode
115
+ }
116
+
117
+ const flags = ctx?.get(FeaturesCtx)
118
+ const isLatexEnabled = flags?.includes(CrepeFeature.Latex)
119
+
120
+ const toggleLatex = (ctx: Ctx) => {
121
+ const hasLatex = containsNode(mathInlineSchema.type(ctx))
122
+ const view = ctx.get(editorViewCtx)
123
+ const { selection, doc, tr } = view.state
124
+ if (!hasLatex) {
125
+ const text = doc.textBetween(selection.from, selection.to)
126
+ let _tr = tr.replaceSelectionWith(
127
+ mathInlineSchema.type(ctx).create({
128
+ value: text,
129
+ })
130
+ )
131
+ view.dispatch(
132
+ _tr.setSelection(NodeSelection.create(_tr.doc, selection.from))
133
+ )
134
+ return
135
+ }
136
+
137
+ const { from, to } = selection
138
+ let pos = -1
139
+ let node: Node | null = null
140
+ doc.nodesBetween(from, to, (n, p) => {
141
+ if (node) return false
142
+ if (n.type === mathInlineSchema.type(ctx)) {
143
+ pos = p
144
+ node = n
145
+ return false
146
+ }
147
+ return true
148
+ })
149
+ if (!node || pos < 0) return
150
+
151
+ let _tr = tr.delete(pos, pos + 1)
152
+ const content = (node as Node).attrs.value
153
+ _tr = _tr.insertText(content, pos)
154
+ view.dispatch(
155
+ _tr.setSelection(
156
+ TextSelection.create(_tr.doc, from, to + content.length - 1)
157
+ )
158
+ )
159
+ }
160
+
161
+ return () => {
162
+ return (
163
+ <>
164
+ <button
165
+ type="button"
166
+ class={clsx(
167
+ 'toolbar-item',
168
+ ctx && isActive(strongSchema.type(ctx)) && 'active'
169
+ )}
170
+ onPointerdown={onClick((ctx) => {
171
+ const commands = ctx.get(commandsCtx)
172
+ commands.call(toggleStrongCommand.key)
173
+ })}
174
+ >
175
+ <Icon icon={config?.boldIcon?.() ?? boldIcon} />
176
+ </button>
177
+ <button
178
+ type="button"
179
+ class={clsx(
180
+ 'toolbar-item',
181
+ ctx && isActive(emphasisSchema.type(ctx)) && 'active'
182
+ )}
183
+ onPointerdown={onClick((ctx) => {
184
+ const commands = ctx.get(commandsCtx)
185
+ commands.call(toggleEmphasisCommand.key)
186
+ })}
187
+ >
188
+ <Icon icon={config?.italicIcon?.() ?? italicIcon} />
189
+ </button>
190
+ <button
191
+ type="button"
192
+ class={clsx(
193
+ 'toolbar-item',
194
+ ctx && isActive(strikethroughSchema.type(ctx)) && 'active'
195
+ )}
196
+ onPointerdown={onClick((ctx) => {
197
+ const commands = ctx.get(commandsCtx)
198
+ commands.call(toggleStrikethroughCommand.key)
199
+ })}
200
+ >
201
+ <Icon icon={config?.strikethroughIcon?.() ?? strikethroughIcon} />
202
+ </button>
203
+ <div class="divider"></div>
204
+ <button
205
+ type="button"
206
+ class={clsx(
207
+ 'toolbar-item',
208
+ ctx && isActive(inlineCodeSchema.type(ctx)) && 'active'
209
+ )}
210
+ onPointerdown={onClick((ctx) => {
211
+ const commands = ctx.get(commandsCtx)
212
+ commands.call(toggleInlineCodeCommand.key)
213
+ })}
214
+ >
215
+ <Icon icon={config?.codeIcon?.() ?? codeIcon} />
216
+ </button>
217
+ {isLatexEnabled && (
218
+ <button
219
+ type="button"
220
+ class={clsx(
221
+ 'toolbar-item',
222
+ ctx && containsNode(mathInlineSchema.type(ctx)) && 'active'
223
+ )}
224
+ onPointerdown={onClick(toggleLatex)}
225
+ >
226
+ <Icon icon={config?.latexIcon?.() ?? functionsIcon} />
227
+ </button>
228
+ )}
229
+ <button
230
+ type="button"
231
+ class={clsx(
232
+ 'toolbar-item',
233
+ ctx && isActive(linkSchema.type(ctx)) && 'active'
234
+ )}
235
+ onPointerdown={onClick((ctx) => {
236
+ const view = ctx.get(editorViewCtx)
237
+ const { selection } = view.state
238
+
239
+ if (isActive(linkSchema.type(ctx))) {
240
+ ctx
241
+ .get(linkTooltipAPI.key)
242
+ .removeLink(selection.from, selection.to)
243
+ return
244
+ }
245
+
246
+ ctx.get(linkTooltipAPI.key).addLink(selection.from, selection.to)
247
+ hide?.()
248
+ })}
249
+ >
250
+ <Icon icon={config?.linkIcon?.() ?? linkIcon} />
251
+ </button>
252
+ </>
253
+ )
254
+ }
255
+ },
256
+ })
@@ -1,13 +1,18 @@
1
- import { TooltipProvider, tooltipFactory } from '@milkdown/kit/plugin/tooltip'
2
- import type { EditorState, PluginView } from '@milkdown/kit/prose/state'
3
- import { TextSelection } from '@milkdown/kit/prose/state'
4
1
  import type { Ctx } from '@milkdown/kit/ctx'
2
+ import type {
3
+ EditorState,
4
+ PluginView,
5
+ Selection,
6
+ } from '@milkdown/kit/prose/state'
5
7
  import type { EditorView } from '@milkdown/kit/prose/view'
6
- import type { AtomicoThis } from 'atomico/types/dom'
8
+
9
+ import { TooltipProvider, tooltipFactory } from '@milkdown/kit/plugin/tooltip'
10
+ import { TextSelection } from '@milkdown/kit/prose/state'
11
+ import { createApp, ref, shallowRef, type App, type ShallowRef } from 'vue'
12
+
7
13
  import type { DefineFeature, Icon } from '../shared'
8
- import { defIfNotExists } from '../../utils'
9
- import type { ToolbarProps } from './component'
10
- import { ToolbarElement } from './component'
14
+
15
+ import { Toolbar } from './component'
11
16
 
12
17
  interface ToolbarConfig {
13
18
  boldIcon: Icon
@@ -24,14 +29,26 @@ const toolbar = tooltipFactory('CREPE_TOOLBAR')
24
29
 
25
30
  class ToolbarView implements PluginView {
26
31
  #tooltipProvider: TooltipProvider
27
- #content: AtomicoThis<ToolbarProps>
32
+ #content: HTMLElement
33
+ #app: App
34
+ #selection: ShallowRef<Selection>
35
+ #show = ref(false)
36
+
28
37
  constructor(ctx: Ctx, view: EditorView, config?: ToolbarFeatureConfig) {
29
- const content = new ToolbarElement()
38
+ const content = document.createElement('div')
39
+ content.className = 'milkdown-toolbar'
40
+ this.#selection = shallowRef(view.state.selection)
41
+ const app = createApp(Toolbar, {
42
+ ctx,
43
+ hide: this.hide,
44
+ config,
45
+ selection: this.#selection,
46
+ show: this.#show,
47
+ })
48
+ app.mount(content)
30
49
  this.#content = content
31
- this.#content.ctx = ctx
32
- this.#content.hide = this.hide
33
- this.#content.config = config
34
- this.#content.selection = view.state.selection
50
+ this.#app = app
51
+
35
52
  this.#tooltipProvider = new TooltipProvider({
36
53
  content: this.#content,
37
54
  debounce: 20,
@@ -67,21 +84,22 @@ class ToolbarView implements PluginView {
67
84
  },
68
85
  })
69
86
  this.#tooltipProvider.onShow = () => {
70
- this.#content.show = true
87
+ this.#show.value = true
71
88
  }
72
89
  this.#tooltipProvider.onHide = () => {
73
- this.#content.show = false
90
+ this.#show.value = false
74
91
  }
75
92
  this.update(view)
76
93
  }
77
94
 
78
95
  update = (view: EditorView, prevState?: EditorState) => {
79
96
  this.#tooltipProvider.update(view, prevState)
80
- this.#content.selection = view.state.selection
97
+ this.#selection.value = view.state.selection
81
98
  }
82
99
 
83
100
  destroy = () => {
84
101
  this.#tooltipProvider.destroy()
102
+ this.#app.unmount()
85
103
  this.#content.remove()
86
104
  }
87
105
 
@@ -90,7 +108,6 @@ class ToolbarView implements PluginView {
90
108
  }
91
109
  }
92
110
 
93
- defIfNotExists('milkdown-toolbar', ToolbarElement)
94
111
  export const defineFeature: DefineFeature<ToolbarFeatureConfig> = (
95
112
  editor,
96
113
  config
@@ -1,6 +1,4 @@
1
- import { html } from 'atomico'
2
-
3
- export const alignCenterIcon = html`
1
+ export const alignCenterIcon = `
4
2
  <svg
5
3
  xmlns="http://www.w3.org/2000/svg"
6
4
  width="24"
@@ -1,6 +1,4 @@
1
- import { html } from 'atomico'
2
-
3
- export const alignLeftIcon = html`
1
+ export const alignLeftIcon = `
4
2
  <svg
5
3
  xmlns="http://www.w3.org/2000/svg"
6
4
  width="24"
@@ -1,6 +1,4 @@
1
- import { html } from 'atomico'
2
-
3
- export const alignRightIcon = html`
1
+ export const alignRightIcon = `
4
2
  <svg
5
3
  xmlns="http://www.w3.org/2000/svg"
6
4
  width="24"
package/src/icons/bold.ts CHANGED
@@ -1,6 +1,4 @@
1
- import { html } from 'atomico'
2
-
3
- export const boldIcon = html`
1
+ export const boldIcon = `
4
2
  <svg
5
3
  xmlns="http://www.w3.org/2000/svg"
6
4
  width="24"
@@ -1,6 +1,4 @@
1
- import { html } from 'atomico'
2
-
3
- export const bulletListIcon = html`
1
+ export const bulletListIcon = `
4
2
  <svg
5
3
  xmlns="http://www.w3.org/2000/svg"
6
4
  width="24"
@@ -1,6 +1,4 @@
1
- import { html } from 'atomico'
2
-
3
- export const bulletIcon = html`
1
+ export const bulletIcon = `
4
2
  <svg
5
3
  xmlns="http://www.w3.org/2000/svg"
6
4
  width="24"
@@ -1,6 +1,4 @@
1
- import { html } from 'atomico'
2
-
3
- export const captionIcon = html`
1
+ export const captionIcon = `
4
2
  <svg
5
3
  xmlns="http://www.w3.org/2000/svg"
6
4
  width="32"
@@ -1,6 +1,4 @@
1
- import { html } from 'atomico'
2
-
3
- export const checkBoxCheckedIcon = html`
1
+ export const checkBoxCheckedIcon = `
4
2
  <svg
5
3
  xmlns="http://www.w3.org/2000/svg"
6
4
  width="24"
@@ -1,6 +1,4 @@
1
- import { html } from 'atomico'
2
-
3
- export const checkBoxUncheckedIcon = html`
1
+ export const checkBoxUncheckedIcon = `
4
2
  <svg
5
3
  xmlns="http://www.w3.org/2000/svg"
6
4
  width="24"
@@ -1,6 +1,4 @@
1
- import { html } from 'atomico'
2
-
3
- export const chevronDownIcon = html`
1
+ export const chevronDownIcon = `
4
2
  <svg
5
3
  xmlns="http://www.w3.org/2000/svg"
6
4
  fill="none"
@@ -1,6 +1,4 @@
1
- import { html } from 'atomico'
2
-
3
- export const clearIcon = html`
1
+ export const clearIcon = `
4
2
  <svg
5
3
  xmlns="http://www.w3.org/2000/svg"
6
4
  width="24"
package/src/icons/code.ts CHANGED
@@ -1,6 +1,4 @@
1
- import { html } from 'atomico'
2
-
3
- export const codeIcon = html`
1
+ export const codeIcon = `
4
2
  <svg
5
3
  xmlns="http://www.w3.org/2000/svg"
6
4
  width="24"