@milkdown/crepe 7.3.3

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 (241) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +11 -0
  3. package/lib/apl-p0IPP13W.js +76 -0
  4. package/lib/asciiarmor-lJsBxlJJ.js +34 -0
  5. package/lib/asn1-Q9v1zIy5.js +102 -0
  6. package/lib/asterisk-foNkeTjy.js +273 -0
  7. package/lib/brainfuck-0XqyXpNS.js +35 -0
  8. package/lib/clike-ak6Z6Yhe.js +639 -0
  9. package/lib/clojure-iYO8U8Sg.js +810 -0
  10. package/lib/clsx-7d8NmkQq.js +21 -0
  11. package/lib/cmake-SVzjkxV_.js +28 -0
  12. package/lib/cobol-APHEnAOX.js +74 -0
  13. package/lib/coffeescript-KqQa0SYG.js +182 -0
  14. package/lib/commonlisp-bwqNqR5V.js +79 -0
  15. package/lib/core/crepe.d.ts +21 -0
  16. package/lib/core/crepe.d.ts.map +1 -0
  17. package/lib/core/index.d.ts +3 -0
  18. package/lib/core/index.d.ts.map +1 -0
  19. package/lib/core/slice.d.ts +12 -0
  20. package/lib/core/slice.d.ts.map +1 -0
  21. package/lib/crystal-BViWuDpA.js +217 -0
  22. package/lib/css-KHXHXfXg.js +1572 -0
  23. package/lib/cypher-XpTt4zQ3.js +69 -0
  24. package/lib/d-fLig6yqY.js +139 -0
  25. package/lib/diff-WoKGLpy6.js +18 -0
  26. package/lib/dockerfile-u6f6Vw2s.js +194 -0
  27. package/lib/dtd-SIJRUW6K.js +91 -0
  28. package/lib/dylan-4HCLhpWP.js +238 -0
  29. package/lib/ebnf-h_0lged5.js +77 -0
  30. package/lib/ecl-Lf4FF0lf.js +133 -0
  31. package/lib/eiffel-qlw8KUyf.js +112 -0
  32. package/lib/elm-QRnB3zXs.js +108 -0
  33. package/lib/erlang-fyVKb7eK.js +488 -0
  34. package/lib/factor-BEeN4upY.js +65 -0
  35. package/lib/fcl-lRek3hEb.js +106 -0
  36. package/lib/feature/block-edit/handle/component.d.ts +9 -0
  37. package/lib/feature/block-edit/handle/component.d.ts.map +1 -0
  38. package/lib/feature/block-edit/handle/index.d.ts +12 -0
  39. package/lib/feature/block-edit/handle/index.d.ts.map +1 -0
  40. package/lib/feature/block-edit/index.d.ts +3 -0
  41. package/lib/feature/block-edit/index.d.ts.map +1 -0
  42. package/lib/feature/block-edit/menu/component.d.ts +14 -0
  43. package/lib/feature/block-edit/menu/component.d.ts.map +1 -0
  44. package/lib/feature/block-edit/menu/config.d.ts +21 -0
  45. package/lib/feature/block-edit/menu/config.d.ts.map +1 -0
  46. package/lib/feature/block-edit/menu/icons.d.ts +14 -0
  47. package/lib/feature/block-edit/menu/icons.d.ts.map +1 -0
  48. package/lib/feature/block-edit/menu/index.d.ts +9 -0
  49. package/lib/feature/block-edit/menu/index.d.ts.map +1 -0
  50. package/lib/feature/code-mirror/index.d.ts +3 -0
  51. package/lib/feature/code-mirror/index.d.ts.map +1 -0
  52. package/lib/feature/gap-cursor/index.d.ts +3 -0
  53. package/lib/feature/gap-cursor/index.d.ts.map +1 -0
  54. package/lib/feature/image-block/index.d.ts +3 -0
  55. package/lib/feature/image-block/index.d.ts.map +1 -0
  56. package/lib/feature/index.d.ts +18 -0
  57. package/lib/feature/index.d.ts.map +1 -0
  58. package/lib/feature/link-tooltip/consts.d.ts +5 -0
  59. package/lib/feature/link-tooltip/consts.d.ts.map +1 -0
  60. package/lib/feature/link-tooltip/index.d.ts +3 -0
  61. package/lib/feature/link-tooltip/index.d.ts.map +1 -0
  62. package/lib/feature/list-item/consts.d.ts +2 -0
  63. package/lib/feature/list-item/consts.d.ts.map +1 -0
  64. package/lib/feature/list-item/index.d.ts +3 -0
  65. package/lib/feature/list-item/index.d.ts.map +1 -0
  66. package/lib/feature/placeholder/index.d.ts +10 -0
  67. package/lib/feature/placeholder/index.d.ts.map +1 -0
  68. package/lib/feature/shared.d.ts +3 -0
  69. package/lib/feature/shared.d.ts.map +1 -0
  70. package/lib/feature/toolbar/component.d.ts +13 -0
  71. package/lib/feature/toolbar/component.d.ts.map +1 -0
  72. package/lib/feature/toolbar/consts.d.ts +5 -0
  73. package/lib/feature/toolbar/consts.d.ts.map +1 -0
  74. package/lib/feature/toolbar/index.d.ts +3 -0
  75. package/lib/feature/toolbar/index.d.ts.map +1 -0
  76. package/lib/forth-ua2bRd8T.js +60 -0
  77. package/lib/fortran-WnF7znuN.js +443 -0
  78. package/lib/gas-wowve1o7.js +183 -0
  79. package/lib/gherkin-m7GIChu3.js +34 -0
  80. package/lib/go-th443Dhb.js +158 -0
  81. package/lib/groovy-tR4RiZnc.js +161 -0
  82. package/lib/haskell-jxVBofv5.js +375 -0
  83. package/lib/haxe-kWPI2tq3.js +390 -0
  84. package/lib/hooks-82sqkbtE.js +21 -0
  85. package/lib/http-3GIFWUlG.js +45 -0
  86. package/lib/icons-HYkfuR-O.js +50 -0
  87. package/lib/idl-PvpMZg-l.js +947 -0
  88. package/lib/index-0RbcZMbq.js +8 -0
  89. package/lib/index-4afXjFMY.js +517 -0
  90. package/lib/index-7MeyepDG.js +78 -0
  91. package/lib/index-7QgQq3x3.js +551 -0
  92. package/lib/index-7pgP6qYs.js +107 -0
  93. package/lib/index-8DvtgRVa.js +19511 -0
  94. package/lib/index-8Gg-jEP4.js +288 -0
  95. package/lib/index-8S8qcncB.js +507 -0
  96. package/lib/index-9A_GmGh4.js +1039 -0
  97. package/lib/index-EJJfYLzA.js +928 -0
  98. package/lib/index-Eg39w5kL.js +984 -0
  99. package/lib/index-FIk_7oPb.js +168 -0
  100. package/lib/index-LlbrXb_n.js +368 -0
  101. package/lib/index-MovKtgMG.js +121 -0
  102. package/lib/index-N9GtIS4X.js +64 -0
  103. package/lib/index-Pwn25-kf.js +8 -0
  104. package/lib/index-SdFSDosa.js +1295 -0
  105. package/lib/index-W5Th22-Z.js +1744 -0
  106. package/lib/index-XiXSFLmI.js +20975 -0
  107. package/lib/index-bknOViGv.js +47 -0
  108. package/lib/index-bkuIUPFS.js +275 -0
  109. package/lib/index-jPA8J9Eo.js +8 -0
  110. package/lib/index-lsG76a9s.js +552 -0
  111. package/lib/index-oTRzPo3B.js +146 -0
  112. package/lib/index-rrf6_6DC.js +317 -0
  113. package/lib/index-vJbZIHYF.js +81 -0
  114. package/lib/index-vPRh55CO.js +137 -0
  115. package/lib/index-vxy63hib.js +323 -0
  116. package/lib/index-wn1_LgCS.js +99 -0
  117. package/lib/index-xHADmDT3.js +12 -0
  118. package/lib/index-yt2EpMtv.js +141 -0
  119. package/lib/index.d.ts +4 -0
  120. package/lib/index.d.ts.map +1 -0
  121. package/lib/index.es.js +7 -0
  122. package/lib/javascript-8ZHqHagw.js +758 -0
  123. package/lib/jinja2-vsOFe0qD.js +154 -0
  124. package/lib/julia-dlp_pbN1.js +241 -0
  125. package/lib/livescript-Gf5R-LT6.js +273 -0
  126. package/lib/lua-c5Y_JsBp.js +221 -0
  127. package/lib/mathematica-iiGTGmUs.js +35 -0
  128. package/lib/mbox-ZJh86H8B.js +78 -0
  129. package/lib/meta-tAGyVRPE.js +511 -0
  130. package/lib/mirc-i0qkCa0y.js +73 -0
  131. package/lib/mllike-Dy551fZW.js +275 -0
  132. package/lib/modelica-n6tGqUT9.js +94 -0
  133. package/lib/mscgen-aKSbB7D9.js +104 -0
  134. package/lib/mumps-lNiKA6sp.js +25 -0
  135. package/lib/nginx--YmuCfDj.js +93 -0
  136. package/lib/nsis-zhS8iA09.js +62 -0
  137. package/lib/ntriples-E3jQl3MC.js +79 -0
  138. package/lib/octave-EQvkGIeG.js +144 -0
  139. package/lib/oz-W2cpqFf6.js +152 -0
  140. package/lib/pascal-lCh6ouNZ.js +79 -0
  141. package/lib/perl-PxEQBX0B.js +915 -0
  142. package/lib/pig-Y_bNcrzS.js +56 -0
  143. package/lib/powershell-GaQP-TZr.js +249 -0
  144. package/lib/properties-mbRyn54L.js +26 -0
  145. package/lib/prosemirror-noTDkx-k.js +4 -0
  146. package/lib/protobuf-8CJideyJ.js +49 -0
  147. package/lib/puppet-ABBaChNZ.js +45 -0
  148. package/lib/python-sKdHg3Ka.js +321 -0
  149. package/lib/q-_1yG40Nm.js +89 -0
  150. package/lib/r-Ziz56bHT.js +108 -0
  151. package/lib/rpm-ORjGOHaQ.js +57 -0
  152. package/lib/ruby-jlbYq0dT.js +233 -0
  153. package/lib/sas-2n7xeUuO.js +107 -0
  154. package/lib/schema-tKk3m1fu.js +62 -0
  155. package/lib/scheme-XCs-NPeU.js +126 -0
  156. package/lib/shell-0_1Um7Dq.js +184 -0
  157. package/lib/sieve-7uyJD1x1.js +73 -0
  158. package/lib/simple-mode--HIzBxba.js +95 -0
  159. package/lib/smalltalk-PEFzrlQ-.js +48 -0
  160. package/lib/solr-BLBaHahN.js +41 -0
  161. package/lib/sparql-4F9ZWf1b.js +204 -0
  162. package/lib/spreadsheet-SGSo6blj.js +49 -0
  163. package/lib/sql-tebLBzN0.js +291 -0
  164. package/lib/stex-SFJcFGOO.js +130 -0
  165. package/lib/stylus-rwwWYWFm.js +256 -0
  166. package/lib/swift-eorJ0tCv.js +238 -0
  167. package/lib/tcl-IwXMB8U4.js +82 -0
  168. package/lib/textile-ok2VyjwC.js +299 -0
  169. package/lib/theme/classic/index.d.ts +3 -0
  170. package/lib/theme/classic/index.d.ts.map +1 -0
  171. package/lib/theme/classic-dark/index.d.ts +3 -0
  172. package/lib/theme/classic-dark/index.d.ts.map +1 -0
  173. package/lib/theme/headless/index.d.ts +3 -0
  174. package/lib/theme/headless/index.d.ts.map +1 -0
  175. package/lib/theme/index.d.ts +8 -0
  176. package/lib/theme/index.d.ts.map +1 -0
  177. package/lib/theme/shared.d.ts +3 -0
  178. package/lib/theme/shared.d.ts.map +1 -0
  179. package/lib/tiddlywiki-DLhz8_pc.js +156 -0
  180. package/lib/tiki-DFAqFElY.js +183 -0
  181. package/lib/tippy.esm-MZ2vxByW.js +1813 -0
  182. package/lib/toml-ryxpTZEV.js +49 -0
  183. package/lib/tooltip-plugin-gcwyQdiT.js +119 -0
  184. package/lib/troff-ZzZyvNct.js +36 -0
  185. package/lib/ttcn-6gvkqqpW.js +136 -0
  186. package/lib/ttcn-cfg-oSu-Dq5C.js +98 -0
  187. package/lib/turtle-10ofr5au.js +87 -0
  188. package/lib/use-css-light-dom-EKWZDmbJ.js +82 -0
  189. package/lib/utils/index.d.ts +4 -0
  190. package/lib/utils/index.d.ts.map +1 -0
  191. package/lib/vb-a6n6fzrD.js +74 -0
  192. package/lib/vbscript-dgvo8jPt.js +324 -0
  193. package/lib/velocity-CBncCrwO.js +97 -0
  194. package/lib/verilog-KlcACt6C.js +271 -0
  195. package/lib/vhdl-NMd7Gf35.js +117 -0
  196. package/lib/webidl-z1UE5DN_.js +160 -0
  197. package/lib/xquery-hDt5jWTp.js +431 -0
  198. package/lib/yacas-ftgh_qwr.js +74 -0
  199. package/lib/yaml-DnNTfjXK.js +53 -0
  200. package/lib/z80-dA1PqWe1.js +62 -0
  201. package/package.json +87 -0
  202. package/src/core/crepe.ts +98 -0
  203. package/src/core/index.ts +4 -0
  204. package/src/core/slice.ts +44 -0
  205. package/src/feature/block-edit/handle/component.ts +68 -0
  206. package/src/feature/block-edit/handle/index.ts +81 -0
  207. package/src/feature/block-edit/index.ts +17 -0
  208. package/src/feature/block-edit/menu/component.ts +210 -0
  209. package/src/feature/block-edit/menu/config.ts +335 -0
  210. package/src/feature/block-edit/menu/icons.ts +171 -0
  211. package/src/feature/block-edit/menu/index.ts +113 -0
  212. package/src/feature/block-edit/style.css +126 -0
  213. package/src/feature/code-mirror/index.ts +60 -0
  214. package/src/feature/code-mirror/style.css +159 -0
  215. package/src/feature/gap-cursor/index.ts +31 -0
  216. package/src/feature/image-block/index.ts +59 -0
  217. package/src/feature/image-block/style.css +215 -0
  218. package/src/feature/index.ts +66 -0
  219. package/src/feature/link-tooltip/consts.ts +47 -0
  220. package/src/feature/link-tooltip/index.ts +22 -0
  221. package/src/feature/link-tooltip/style.css +107 -0
  222. package/src/feature/list-item/consts.ts +15 -0
  223. package/src/feature/list-item/index.ts +30 -0
  224. package/src/feature/list-item/style.css +23 -0
  225. package/src/feature/placeholder/index.ts +87 -0
  226. package/src/feature/placeholder/style.css +9 -0
  227. package/src/feature/shared.ts +4 -0
  228. package/src/feature/toolbar/component.ts +101 -0
  229. package/src/feature/toolbar/consts.ts +26 -0
  230. package/src/feature/toolbar/index.ts +92 -0
  231. package/src/feature/toolbar/style.css +37 -0
  232. package/src/index.ts +5 -0
  233. package/src/theme/classic/index.ts +12 -0
  234. package/src/theme/classic/style.css +192 -0
  235. package/src/theme/classic-dark/index.ts +12 -0
  236. package/src/theme/classic-dark/style.css +197 -0
  237. package/src/theme/headless/index.ts +9 -0
  238. package/src/theme/index.ts +26 -0
  239. package/src/theme/shared.ts +4 -0
  240. package/src/utils/index.ts +12 -0
  241. package/src/vite-env.d.ts +2 -0
@@ -0,0 +1,335 @@
1
+ /* Copyright 2021, Milkdown by Mirone. */
2
+ import type { html } from 'atomico'
3
+ import type { Ctx } from '@milkdown/ctx'
4
+ import { editorViewCtx } from '@milkdown/core'
5
+ import {
6
+ blockquoteSchema,
7
+ bulletListSchema,
8
+ codeBlockSchema,
9
+ headingSchema,
10
+ hrSchema,
11
+ orderedListSchema,
12
+ paragraphSchema,
13
+ } from '@milkdown/preset-commonmark'
14
+ import type { Attrs, NodeType } from '@milkdown/prose/model'
15
+ import { findWrapping } from '@milkdown/prose/transform'
16
+ import type { Command, Transaction } from '@milkdown/prose/state'
17
+ import { imageBlockSchema } from '@milkdown/components'
18
+ import {
19
+ bulletListIcon,
20
+ codeIcon,
21
+ dividerIcon,
22
+ h1Icon,
23
+ h2Icon,
24
+ h3Icon,
25
+ h4Icon,
26
+ h5Icon,
27
+ h6Icon,
28
+ imageIcon,
29
+ orderedListIcon,
30
+ quoteIcon,
31
+ textIcon,
32
+ } from './icons'
33
+
34
+ interface MenuItem {
35
+ index: number
36
+ key: string
37
+ label: string
38
+ icon: ReturnType<typeof html>
39
+ onRun: (ctx: Ctx) => void
40
+ }
41
+
42
+ type WithRange<T, HasIndex extends true | false = true> = HasIndex extends true ? T & { range: [start: number, end: number] } : T
43
+
44
+ type MenuItemGroup<HasIndex extends true | false = true> = WithRange<{
45
+ key: string
46
+ label: string
47
+ items: HasIndex extends true ? MenuItem[] : Omit<MenuItem, 'index'>[]
48
+ }, HasIndex>
49
+
50
+ function clearRange(tr: Transaction) {
51
+ const { $from, $to } = tr.selection
52
+ const { pos: from } = $from
53
+ const { pos: to } = $to
54
+ tr = tr.deleteRange(from - $from.node().content.size, to)
55
+ return tr
56
+ }
57
+
58
+ function setBlockType(tr: Transaction, nodeType: NodeType, attrs: Attrs | null = null) {
59
+ const { from, to } = tr.selection
60
+ return tr.setBlockType(from, to, nodeType, attrs)
61
+ }
62
+
63
+ function wrapInBlockType(tr: Transaction, nodeType: NodeType, attrs: Attrs | null = null) {
64
+ const { $from, $to } = tr.selection
65
+
66
+ const range = $from.blockRange($to)
67
+ const wrapping = range && findWrapping(range, nodeType, attrs)
68
+ if (!wrapping)
69
+ return null
70
+
71
+ return tr.wrap(range, wrapping)
72
+ }
73
+
74
+ function addBlockType(tr: Transaction, nodeType: NodeType, attrs: Attrs | null = null) {
75
+ const node = nodeType.createAndFill(attrs)
76
+ if (!node)
77
+ return null
78
+
79
+ return tr.replaceSelectionWith(node)
80
+ }
81
+
82
+ function clearContentAndSetBlockType(nodeType: NodeType, attrs: Attrs | null = null): Command {
83
+ return (state, dispatch) => {
84
+ if (dispatch) {
85
+ const tr = setBlockType(clearRange(state.tr), nodeType, attrs)
86
+ dispatch(tr.scrollIntoView())
87
+ }
88
+ return true
89
+ }
90
+ }
91
+
92
+ function clearContentAndWrapInBlockType(nodeType: NodeType, attrs: Attrs | null = null): Command {
93
+ return (state, dispatch) => {
94
+ const tr = wrapInBlockType(clearRange(state.tr), nodeType, attrs)
95
+ if (!tr)
96
+ return false
97
+
98
+ if (dispatch)
99
+ dispatch(tr.scrollIntoView())
100
+
101
+ return true
102
+ }
103
+ }
104
+
105
+ function clearContentAndAddBlockType(nodeType: NodeType, attrs: Attrs | null = null): Command {
106
+ return (state, dispatch) => {
107
+ const tr = addBlockType(clearRange(state.tr), nodeType, attrs)
108
+ if (!tr)
109
+ return false
110
+
111
+ if (dispatch)
112
+ dispatch(tr.scrollIntoView())
113
+
114
+ return true
115
+ }
116
+ }
117
+
118
+ export function getGroups(filter?: string) {
119
+ let groups: MenuItemGroup<false>[] = [
120
+ {
121
+ key: 'text',
122
+ label: 'Text',
123
+ items: [
124
+ {
125
+ key: 'text',
126
+ label: 'Text',
127
+ icon: textIcon,
128
+ onRun: (ctx) => {
129
+ const view = ctx.get(editorViewCtx)
130
+ const { dispatch, state } = view
131
+
132
+ const command = clearContentAndSetBlockType(paragraphSchema.type(ctx))
133
+ command(state, dispatch)
134
+ },
135
+ },
136
+ {
137
+ key: 'h1',
138
+ label: 'Heading 1',
139
+ icon: h1Icon,
140
+ onRun: (ctx) => {
141
+ const view = ctx.get(editorViewCtx)
142
+ const { dispatch, state } = view
143
+
144
+ const command = clearContentAndSetBlockType(headingSchema.type(ctx), { level: 1 })
145
+ command(state, dispatch)
146
+ },
147
+ },
148
+ {
149
+ key: 'h2',
150
+ label: 'Heading 2',
151
+ icon: h2Icon,
152
+ onRun: (ctx) => {
153
+ const view = ctx.get(editorViewCtx)
154
+ const { dispatch, state } = view
155
+
156
+ const command = clearContentAndSetBlockType(headingSchema.type(ctx), { level: 2 })
157
+ command(state, dispatch)
158
+ },
159
+ },
160
+ {
161
+ key: 'h3',
162
+ label: 'Heading 3',
163
+ icon: h3Icon,
164
+ onRun: (ctx) => {
165
+ const view = ctx.get(editorViewCtx)
166
+ const { dispatch, state } = view
167
+
168
+ const command = clearContentAndSetBlockType(headingSchema.type(ctx), { level: 3 })
169
+ command(state, dispatch)
170
+ },
171
+ },
172
+ {
173
+ key: 'h4',
174
+ label: 'Heading 4',
175
+ icon: h4Icon,
176
+ onRun: (ctx) => {
177
+ const view = ctx.get(editorViewCtx)
178
+ const { dispatch, state } = view
179
+
180
+ const command = clearContentAndSetBlockType(headingSchema.type(ctx), { level: 4 })
181
+ command(state, dispatch)
182
+ },
183
+ },
184
+ {
185
+ key: 'h5',
186
+ label: 'Heading 5',
187
+ icon: h5Icon,
188
+ onRun: (ctx) => {
189
+ const view = ctx.get(editorViewCtx)
190
+ const { dispatch, state } = view
191
+
192
+ const command = clearContentAndSetBlockType(headingSchema.type(ctx), { level: 5 })
193
+ command(state, dispatch)
194
+ },
195
+ },
196
+ {
197
+ key: 'h6',
198
+ label: 'Heading 6',
199
+ icon: h6Icon,
200
+ onRun: (ctx) => {
201
+ const view = ctx.get(editorViewCtx)
202
+ const { dispatch, state } = view
203
+
204
+ const command = clearContentAndSetBlockType(headingSchema.type(ctx), { level: 6 })
205
+ command(state, dispatch)
206
+ },
207
+ },
208
+ {
209
+ key: 'quote',
210
+ label: 'Quote',
211
+ icon: quoteIcon,
212
+ onRun: (ctx) => {
213
+ const view = ctx.get(editorViewCtx)
214
+ const { dispatch, state } = view
215
+
216
+ const command = clearContentAndWrapInBlockType(blockquoteSchema.type(ctx))
217
+ command(state, dispatch)
218
+ },
219
+ },
220
+ {
221
+ key: 'divider',
222
+ label: 'Divider',
223
+ icon: dividerIcon,
224
+ onRun: (ctx) => {
225
+ const view = ctx.get(editorViewCtx)
226
+ const { dispatch, state } = view
227
+
228
+ const command = clearContentAndAddBlockType(hrSchema.type(ctx))
229
+ command(state, dispatch)
230
+ },
231
+ },
232
+ ],
233
+ },
234
+ {
235
+ key: 'list',
236
+ label: 'List',
237
+ items: [
238
+ {
239
+ key: 'bullet-list',
240
+ label: 'Bullet List',
241
+ icon: bulletListIcon,
242
+ onRun: (ctx) => {
243
+ const view = ctx.get(editorViewCtx)
244
+ const { dispatch, state } = view
245
+
246
+ const command = clearContentAndWrapInBlockType(bulletListSchema.type(ctx))
247
+ command(state, dispatch)
248
+ },
249
+ },
250
+ {
251
+ key: 'ordered-list',
252
+ label: 'Ordered List',
253
+ icon: orderedListIcon,
254
+ onRun: (ctx) => {
255
+ const view = ctx.get(editorViewCtx)
256
+ const { dispatch, state } = view
257
+
258
+ const command = clearContentAndWrapInBlockType(orderedListSchema.type(ctx))
259
+ command(state, dispatch)
260
+ },
261
+ },
262
+ ],
263
+ },
264
+ {
265
+ key: 'advanced',
266
+ label: 'Advanced',
267
+ items: [
268
+ {
269
+ key: 'image',
270
+ label: 'Image',
271
+ icon: imageIcon,
272
+ onRun: (ctx) => {
273
+ const view = ctx.get(editorViewCtx)
274
+ const { dispatch, state } = view
275
+
276
+ const command = clearContentAndAddBlockType(imageBlockSchema.type(ctx))
277
+ command(state, dispatch)
278
+ },
279
+ },
280
+ {
281
+ key: 'code',
282
+ label: 'Code',
283
+ icon: codeIcon,
284
+ onRun: (ctx) => {
285
+ const view = ctx.get(editorViewCtx)
286
+ const { dispatch, state } = view
287
+
288
+ const command = clearContentAndAddBlockType(codeBlockSchema.type(ctx))
289
+ command(state, dispatch)
290
+ },
291
+ },
292
+ ],
293
+ },
294
+ ]
295
+
296
+ if (filter) {
297
+ groups = groups
298
+ .map((group) => {
299
+ const items = group
300
+ .items
301
+ .filter(item =>
302
+ item
303
+ .label
304
+ .toLowerCase()
305
+ .includes(filter.toLowerCase()))
306
+
307
+ return {
308
+ ...group,
309
+ items,
310
+ }
311
+ })
312
+ .filter(group => group.items.length > 0)
313
+ }
314
+
315
+ const items = groups.flatMap(groups => groups.items)
316
+ items
317
+ .forEach(((item, index) => {
318
+ Object.assign(item, {
319
+ index,
320
+ })
321
+ }))
322
+
323
+ groups.reduce((acc, group) => {
324
+ const end = acc + group.items.length
325
+ Object.assign(group, {
326
+ range: [acc, end],
327
+ })
328
+ return end
329
+ }, 0)
330
+
331
+ return {
332
+ groups: groups as unknown as MenuItemGroup[],
333
+ size: items.length,
334
+ }
335
+ }
@@ -0,0 +1,171 @@
1
+ /* Copyright 2021, Milkdown by Mirone. */
2
+ import { html } from 'atomico'
3
+
4
+ export const textIcon = html`
5
+ <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none">
6
+ <g clip-path="url(#clip0_992_5547)">
7
+ <path d="M5 5.5C5 6.33 5.67 7 6.5 7H10.5V17.5C10.5 18.33 11.17 19 12 19C12.83 19 13.5 18.33 13.5 17.5V7H17.5C18.33 7 19 6.33 19 5.5C19 4.67 18.33 4 17.5 4H6.5C5.67 4 5 4.67 5 5.5Z" fill="#817567"/>
8
+ </g>
9
+ <defs>
10
+ <clipPath id="clip0_992_5547">
11
+ <rect width="24" height="24" fill="white"/>
12
+ </clipPath>
13
+ </defs>
14
+ </svg>
15
+ `
16
+
17
+ export const h1Icon = html`
18
+ <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none">
19
+ <g clip-path="url(#clip0_992_5553)">
20
+ <path d="M19 3H5C3.9 3 3 3.9 3 5V19C3 20.1 3.9 21 5 21H19C20.1 21 21 20.1 21 19V5C21 3.9 20.1 3 19 3ZM19 19H5V5H19V19ZM12 17H14V7H10V9H12V17Z" fill="#817567"/>
21
+ </g>
22
+ <defs>
23
+ <clipPath id="clip0_992_5553">
24
+ <rect width="24" height="24" fill="white"/>
25
+ </clipPath>
26
+ </defs>
27
+ </svg>
28
+ `
29
+
30
+ export const h2Icon = html`
31
+ <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none">
32
+ <g clip-path="url(#clip0_992_5559)">
33
+ <path d="M19 3H5C3.9 3 3 3.9 3 5V19C3 20.1 3.9 21 5 21H19C20.1 21 21 20.1 21 19V5C21 3.9 20.1 3 19 3ZM19 19H5V5H19V19ZM15 15H11V13H13C14.1 13 15 12.11 15 11V9C15 7.89 14.1 7 13 7H9V9H13V11H11C9.9 11 9 11.89 9 13V17H15V15Z" fill="#817567"/>
34
+ </g>
35
+ <defs>
36
+ <clipPath id="clip0_992_5559">
37
+ <rect width="24" height="24" fill="white"/>
38
+ </clipPath>
39
+ </defs>
40
+ </svg>
41
+ `
42
+
43
+ export const h3Icon = html`
44
+ <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none">
45
+ <g clip-path="url(#clip0_992_5565)">
46
+ <path d="M19 3H5C3.9 3 3 3.9 3 5V19C3 20.1 3.9 21 5 21H19C20.1 21 21 20.1 21 19V5C21 3.9 20.1 3 19 3ZM19 19H5V5H19V19ZM15 15V13.5C15 12.67 14.33 12 13.5 12C14.33 12 15 11.33 15 10.5V9C15 7.89 14.1 7 13 7H9V9H13V11H11V13H13V15H9V17H13C14.1 17 15 16.11 15 15Z" fill="#817567"/>
47
+ </g>
48
+ <defs>
49
+ <clipPath id="clip0_992_5565">
50
+ <rect width="24" height="24" fill="white"/>
51
+ </clipPath>
52
+ </defs>
53
+ </svg>
54
+ `
55
+
56
+ export const h4Icon = html`
57
+ <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none">
58
+ <g clip-path="url(#clip0_977_7757)">
59
+ <path d="M19.04 3H5.04004C3.94004 3 3.04004 3.9 3.04004 5V19C3.04004 20.1 3.94004 21 5.04004 21H19.04C20.14 21 21.04 20.1 21.04 19V5C21.04 3.9 20.14 3 19.04 3ZM19.04 19H5.04004V5H19.04V19ZM13.04 17H15.04V7H13.04V11H11.04V7H9.04004V13H13.04V17Z" fill="#817567"/>
60
+ </g>
61
+ <defs>
62
+ <clipPath id="clip0_977_7757">
63
+ <rect width="24" height="24" fill="white"/>
64
+ </clipPath>
65
+ </defs>
66
+ </svg>
67
+ `
68
+
69
+ export const h5Icon = html`
70
+ <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none">
71
+ <g clip-path="url(#clip0_977_7760)">
72
+ <path d="M19 3H5C3.9 3 3 3.9 3 5V19C3 20.1 3.9 21 5 21H19C20.1 21 21 20.1 21 19V5C21 3.9 20.1 3 19 3ZM19 19H5V5H19V19ZM15 15V13C15 11.89 14.1 11 13 11H11V9H15V7H9V13H13V15H9V17H13C14.1 17 15 16.11 15 15Z" fill="#817567"/>
73
+ </g>
74
+ <defs>
75
+ <clipPath id="clip0_977_7760">
76
+ <rect width="24" height="24" fill="white"/>
77
+ </clipPath>
78
+ </defs>
79
+ </svg>
80
+ `
81
+
82
+ export const h6Icon = html`
83
+ <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none">
84
+ <g clip-path="url(#clip0_977_7763)">
85
+ <path d="M11 17H13C14.1 17 15 16.11 15 15V13C15 11.89 14.1 11 13 11H11V9H15V7H11C9.9 7 9 7.89 9 9V15C9 16.11 9.9 17 11 17ZM11 13H13V15H11V13ZM19 3H5C3.9 3 3 3.9 3 5V19C3 20.1 3.9 21 5 21H19C20.1 21 21 20.1 21 19V5C21 3.9 20.1 3 19 3ZM19 19H5V5H19V19Z" fill="#817567"/>
86
+ </g>
87
+ <defs>
88
+ <clipPath id="clip0_977_7763">
89
+ <rect width="24" height="24" fill="white"/>
90
+ </clipPath>
91
+ </defs>
92
+ </svg>
93
+ `
94
+
95
+ export const bulletListIcon = html`
96
+ <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none">
97
+ <g clip-path="url(#clip0_977_8070)">
98
+ <path d="M4 10.5C3.17 10.5 2.5 11.17 2.5 12C2.5 12.83 3.17 13.5 4 13.5C4.83 13.5 5.5 12.83 5.5 12C5.5 11.17 4.83 10.5 4 10.5ZM4 4.5C3.17 4.5 2.5 5.17 2.5 6C2.5 6.83 3.17 7.5 4 7.5C4.83 7.5 5.5 6.83 5.5 6C5.5 5.17 4.83 4.5 4 4.5ZM4 16.5C3.17 16.5 2.5 17.18 2.5 18C2.5 18.82 3.18 19.5 4 19.5C4.82 19.5 5.5 18.82 5.5 18C5.5 17.18 4.83 16.5 4 16.5ZM8 19H20C20.55 19 21 18.55 21 18C21 17.45 20.55 17 20 17H8C7.45 17 7 17.45 7 18C7 18.55 7.45 19 8 19ZM8 13H20C20.55 13 21 12.55 21 12C21 11.45 20.55 11 20 11H8C7.45 11 7 11.45 7 12C7 12.55 7.45 13 8 13ZM7 6C7 6.55 7.45 7 8 7H20C20.55 7 21 6.55 21 6C21 5.45 20.55 5 20 5H8C7.45 5 7 5.45 7 6Z" fill="#817567"/>
99
+ </g>
100
+ <defs>
101
+ <clipPath id="clip0_977_8070">
102
+ <rect width="24" height="24" fill="white"/>
103
+ </clipPath>
104
+ </defs>
105
+ </svg>
106
+ `
107
+
108
+ export const orderedListIcon = html`
109
+ <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none">
110
+ <g clip-path="url(#clip0_977_8067)">
111
+ <path d="M8 7H20C20.55 7 21 6.55 21 6C21 5.45 20.55 5 20 5H8C7.45 5 7 5.45 7 6C7 6.55 7.45 7 8 7ZM20 17H8C7.45 17 7 17.45 7 18C7 18.55 7.45 19 8 19H20C20.55 19 21 18.55 21 18C21 17.45 20.55 17 20 17ZM20 11H8C7.45 11 7 11.45 7 12C7 12.55 7.45 13 8 13H20C20.55 13 21 12.55 21 12C21 11.45 20.55 11 20 11ZM4.5 16H2.5C2.22 16 2 16.22 2 16.5C2 16.78 2.22 17 2.5 17H4V17.5H3.5C3.22 17.5 3 17.72 3 18C3 18.28 3.22 18.5 3.5 18.5H4V19H2.5C2.22 19 2 19.22 2 19.5C2 19.78 2.22 20 2.5 20H4.5C4.78 20 5 19.78 5 19.5V16.5C5 16.22 4.78 16 4.5 16ZM2.5 5H3V7.5C3 7.78 3.22 8 3.5 8C3.78 8 4 7.78 4 7.5V4.5C4 4.22 3.78 4 3.5 4H2.5C2.22 4 2 4.22 2 4.5C2 4.78 2.22 5 2.5 5ZM4.5 10H2.5C2.22 10 2 10.22 2 10.5C2 10.78 2.22 11 2.5 11H3.8L2.12 12.96C2.04 13.05 2 13.17 2 13.28V13.5C2 13.78 2.22 14 2.5 14H4.5C4.78 14 5 13.78 5 13.5C5 13.22 4.78 13 4.5 13H3.2L4.88 11.04C4.96 10.95 5 10.83 5 10.72V10.5C5 10.22 4.78 10 4.5 10Z" fill="#817567"/>
112
+ </g>
113
+ <defs>
114
+ <clipPath id="clip0_977_8067">
115
+ <rect width="24" height="24" fill="white"/>
116
+ </clipPath>
117
+ </defs>
118
+ </svg>
119
+ `
120
+
121
+ export const quoteIcon = html`
122
+ <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none">
123
+ <g clip-path="url(#clip0_977_7897)">
124
+ <path d="M7.17 17C7.68 17 8.15 16.71 8.37 16.26L9.79 13.42C9.93 13.14 10 12.84 10 12.53V8C10 7.45 9.55 7 9 7H5C4.45 7 4 7.45 4 8V12C4 12.55 4.45 13 5 13H7L5.97 15.06C5.52 15.95 6.17 17 7.17 17ZM17.17 17C17.68 17 18.15 16.71 18.37 16.26L19.79 13.42C19.93 13.14 20 12.84 20 12.53V8C20 7.45 19.55 7 19 7H15C14.45 7 14 7.45 14 8V12C14 12.55 14.45 13 15 13H17L15.97 15.06C15.52 15.95 16.17 17 17.17 17Z" fill="#817567"/>
125
+ </g>
126
+ <defs>
127
+ <clipPath id="clip0_977_7897">
128
+ <rect width="24" height="24" fill="white"/>
129
+ </clipPath>
130
+ </defs>
131
+ </svg>
132
+ `
133
+
134
+ export const dividerIcon = html`
135
+ <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none">
136
+ <g clip-path="url(#clip0_977_7900)">
137
+ <path fill-rule="evenodd" clip-rule="evenodd" d="M19 13H5C4.45 13 4 12.55 4 12C4 11.45 4.45 11 5 11H19C19.55 11 20 11.45 20 12C20 12.55 19.55 13 19 13Z" fill="#817567"/>
138
+ </g>
139
+ <defs>
140
+ <clipPath id="clip0_977_7900">
141
+ <rect width="24" height="24" fill="white"/>
142
+ </clipPath>
143
+ </defs>
144
+ </svg>
145
+ `
146
+
147
+ export const imageIcon = html`
148
+ <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none">
149
+ <g clip-path="url(#clip0_977_8075)">
150
+ <path d="M19 5V19H5V5H19ZM19 3H5C3.9 3 3 3.9 3 5V19C3 20.1 3.9 21 5 21H19C20.1 21 21 20.1 21 19V5C21 3.9 20.1 3 19 3ZM14.14 11.86L11.14 15.73L9 13.14L6 17H18L14.14 11.86Z" fill="#817567"/>
151
+ </g>
152
+ <defs>
153
+ <clipPath id="clip0_977_8075">
154
+ <rect width="24" height="24" fill="white"/>
155
+ </clipPath>
156
+ </defs>
157
+ </svg>
158
+ `
159
+
160
+ export const codeIcon = html`
161
+ <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none">
162
+ <g clip-path="url(#clip0_977_8081)">
163
+ <path d="M9.4 16.6L4.8 12L9.4 7.4L8 6L2 12L8 18L9.4 16.6ZM14.6 16.6L19.2 12L14.6 7.4L16 6L22 12L16 18L14.6 16.6Z" fill="#817567"/>
164
+ </g>
165
+ <defs>
166
+ <clipPath id="clip0_977_8081">
167
+ <rect width="24" height="24" fill="white"/>
168
+ </clipPath>
169
+ </defs>
170
+ </svg>
171
+ `
@@ -0,0 +1,113 @@
1
+ /* Copyright 2021, Milkdown by Mirone. */
2
+ import type { PluginView } from '@milkdown/prose/state'
3
+ import type { EditorView } from '@milkdown/prose/view'
4
+ import { SlashProvider, slashFactory } from '@milkdown/plugin-slash'
5
+ import type { Ctx } from '@milkdown/ctx'
6
+ import type { AtomicoThis } from 'atomico/types/dom'
7
+ import { $ctx } from '@milkdown/utils'
8
+ import { isInCodeBlock, isInList } from '../../../utils'
9
+ import type { MenuProps } from './component'
10
+ import { MenuElement } from './component'
11
+
12
+ export const menu = slashFactory('CREPE_MENU')
13
+
14
+ export interface MenuAPI {
15
+ show: (pos: number) => void
16
+ hide: () => void
17
+ }
18
+
19
+ export const menuAPI = $ctx({
20
+ show: () => {},
21
+ hide: () => {},
22
+ } as MenuAPI, 'menuAPICtx')
23
+
24
+ customElements.define('milkdown-slash-menu', MenuElement)
25
+ export function configureMenu(ctx: Ctx) {
26
+ ctx.set(menu.key, {
27
+ view: view => new MenuView(ctx, view),
28
+ })
29
+ }
30
+
31
+ class MenuView implements PluginView {
32
+ readonly #content: AtomicoThis<MenuProps, HTMLElement>
33
+ readonly #slashProvider: SlashProvider
34
+ #programmaticallyPos: number | null = null
35
+
36
+ constructor(ctx: Ctx, view: EditorView) {
37
+ this.#content = new MenuElement()
38
+ this.#content.hide = this.hide
39
+ this.#content.ctx = ctx
40
+ // eslint-disable-next-line ts/no-this-alias
41
+ const self = this
42
+ this.#slashProvider = new SlashProvider({
43
+ content: this.#content,
44
+ debounce: 20,
45
+ tippyOptions: {
46
+ arrow: false,
47
+ delay: 0,
48
+ duration: 0,
49
+ onShow: () => {
50
+ this.#content.show = true
51
+ },
52
+ onHidden: () => {
53
+ this.#content.show = false
54
+ },
55
+ },
56
+ shouldShow(this: SlashProvider, view: EditorView) {
57
+ if (isInCodeBlock(view.state.selection) || isInList(view.state.selection))
58
+ return false
59
+
60
+ const currentText = this.getContent(view, node =>
61
+ ['paragraph', 'heading'].includes(node.type.name))
62
+
63
+ if (currentText == null)
64
+ return false
65
+
66
+ const pos = self.#programmaticallyPos
67
+
68
+ self.#content.filter = currentText.startsWith('/') ? currentText.slice(1) : currentText
69
+
70
+ if (typeof pos === 'number') {
71
+ if (view.state.doc.resolve(pos).node() !== view.state.doc.resolve(view.state.selection.from).node()) {
72
+ self.#programmaticallyPos = null
73
+
74
+ return false
75
+ }
76
+
77
+ return true
78
+ }
79
+
80
+ if (!currentText.startsWith('/'))
81
+ return false
82
+
83
+ return true
84
+ },
85
+ })
86
+ this.update(view)
87
+
88
+ ctx.set(menuAPI.key, {
89
+ show: pos => this.show(pos),
90
+ hide: () => this.hide(),
91
+ })
92
+ }
93
+
94
+ update = (view: EditorView) => {
95
+ this.#slashProvider.update(view)
96
+ }
97
+
98
+ show = (pos: number) => {
99
+ this.#programmaticallyPos = pos
100
+ this.#content.filter = ''
101
+ this.#slashProvider.show()
102
+ }
103
+
104
+ hide = () => {
105
+ this.#programmaticallyPos = null
106
+ this.#slashProvider.hide()
107
+ }
108
+
109
+ destroy = () => {
110
+ this.#slashProvider.destroy()
111
+ this.#content.remove()
112
+ }
113
+ }