@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,66 @@
1
+ /* Copyright 2021, Milkdown by Mirone. */
2
+ import type { Editor } from '@milkdown/core'
3
+ import type { PlaceHolderFeatureConfig } from './placeholder'
4
+
5
+ export enum CrepeFeature {
6
+ CodeMirror = 'code-mirror',
7
+ ListItem = 'list-item',
8
+ LinkTooltip = 'link-tooltip',
9
+ GapCursor = 'gap-cursor',
10
+ ImageBlock = 'image-block',
11
+ BlockEdit = 'block-edit',
12
+ Toolbar = 'toolbar',
13
+ Placeholder = 'placeholder',
14
+ }
15
+
16
+ export interface CrepeFeatureConfig {
17
+ [CrepeFeature.Placeholder]?: PlaceHolderFeatureConfig
18
+ }
19
+
20
+ export const defaultFeatures: Record<CrepeFeature, boolean> = {
21
+ [CrepeFeature.ListItem]: true,
22
+ [CrepeFeature.LinkTooltip]: true,
23
+ [CrepeFeature.ImageBlock]: true,
24
+ [CrepeFeature.GapCursor]: true,
25
+ [CrepeFeature.BlockEdit]: true,
26
+ [CrepeFeature.Placeholder]: true,
27
+ [CrepeFeature.Toolbar]: true,
28
+ [CrepeFeature.CodeMirror]: false,
29
+ }
30
+
31
+ export async function loadFeature(feature: CrepeFeature, editor: Editor, config?: never) {
32
+ switch (feature) {
33
+ case CrepeFeature.CodeMirror: {
34
+ const { defineFeature } = await import('./code-mirror')
35
+ return defineFeature(editor, config)
36
+ }
37
+ case CrepeFeature.ListItem: {
38
+ const { defineFeature } = await import('./list-item')
39
+ return defineFeature(editor, config)
40
+ }
41
+ case CrepeFeature.LinkTooltip: {
42
+ const { defineFeature } = await import('./link-tooltip')
43
+ return defineFeature(editor, config)
44
+ }
45
+ case CrepeFeature.ImageBlock: {
46
+ const { defineFeature } = await import('./image-block')
47
+ return defineFeature(editor, config)
48
+ }
49
+ case CrepeFeature.GapCursor: {
50
+ const { defineFeature } = await import('./gap-cursor')
51
+ return defineFeature(editor, config)
52
+ }
53
+ case CrepeFeature.BlockEdit: {
54
+ const { defineFeature } = await import('./block-edit')
55
+ return defineFeature(editor, config)
56
+ }
57
+ case CrepeFeature.Placeholder: {
58
+ const { defineFeature } = await import('./placeholder')
59
+ return defineFeature(editor, config)
60
+ }
61
+ case CrepeFeature.Toolbar: {
62
+ const { defineFeature } = await import('./toolbar')
63
+ return defineFeature(editor, config)
64
+ }
65
+ }
66
+ }
@@ -0,0 +1,47 @@
1
+ /* Copyright 2021, Milkdown by Mirone. */
2
+ import { html } from 'atomico'
3
+
4
+ export const linkIcon = html`
5
+ <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none">
6
+ <path d="M17.0385 19.5003V16.5388H14.0769V15.0388H17.0385V12.0773H18.5384V15.0388H21.5V16.5388H18.5384V19.5003H17.0385ZM10.8077 16.5388H7.03845C5.78282 16.5388 4.7125 16.0963 3.8275 15.2114C2.9425 14.3266 2.5 13.2564 2.5 12.0009C2.5 10.7454 2.9425 9.67504 3.8275 8.78979C4.7125 7.90454 5.78282 7.46191 7.03845 7.46191H10.8077V8.96186H7.03845C6.1987 8.96186 5.48235 9.25834 4.8894 9.85129C4.29645 10.4442 3.99998 11.1606 3.99998 12.0003C3.99998 12.8401 4.29645 13.5564 4.8894 14.1494C5.48235 14.7423 6.1987 15.0388 7.03845 15.0388H10.8077V16.5388ZM8.25 12.7503V11.2504H15.75V12.7503H8.25ZM21.5 12.0003H20C20 11.1606 19.7035 10.4442 19.1106 9.85129C18.5176 9.25834 17.8013 8.96186 16.9615 8.96186H13.1923V7.46191H16.9615C18.2171 7.46191 19.2875 7.90441 20.1725 8.78939C21.0575 9.67439 21.5 10.7447 21.5 12.0003Z" fill="#817567"/>
7
+ </svg>
8
+ `
9
+
10
+ export const editIcon = html`
11
+ <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none">
12
+ <g clip-path="url(#clip0_1013_1585)">
13
+ <path d="M14.06 9.02L14.98 9.94L5.92 19H5V18.08L14.06 9.02ZM17.66 3C17.41 3 17.15 3.1 16.96 3.29L15.13 5.12L18.88 8.87L20.71 7.04C21.1 6.65 21.1 6.02 20.71 5.63L18.37 3.29C18.17 3.09 17.92 3 17.66 3ZM14.06 6.19L3 17.25V21H6.75L17.81 9.94L14.06 6.19Z" fill="#817567"/>
14
+ </g>
15
+ <defs>
16
+ <clipPath id="clip0_1013_1585">
17
+ <rect width="24" height="24" fill="white"/>
18
+ </clipPath>
19
+ </defs>
20
+ </svg>
21
+ `
22
+
23
+ export const deleteIcon = html`
24
+ <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none">
25
+ <g clip-path="url(#clip0_1013_1627)">
26
+ <path d="M6 19C6 20.1 6.9 21 8 21H16C17.1 21 18 20.1 18 19V9C18 7.9 17.1 7 16 7H8C6.9 7 6 7.9 6 9V19ZM9 9H15C15.55 9 16 9.45 16 10V18C16 18.55 15.55 19 15 19H9C8.45 19 8 18.55 8 18V10C8 9.45 8.45 9 9 9ZM15.5 4L14.79 3.29C14.61 3.11 14.35 3 14.09 3H9.91C9.65 3 9.39 3.11 9.21 3.29L8.5 4H6C5.45 4 5 4.45 5 5C5 5.55 5.45 6 6 6H18C18.55 6 19 5.55 19 5C19 4.45 18.55 4 18 4H15.5Z" fill="#817567"/>
27
+ </g>
28
+ <defs>
29
+ <clipPath id="clip0_1013_1627">
30
+ <rect width="24" height="24" fill="white"/>
31
+ </clipPath>
32
+ </defs>
33
+ </svg>
34
+ `
35
+
36
+ export const confirmIcon = html`
37
+ <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none">
38
+ <g clip-path="url(#clip0_1013_1545)">
39
+ <path d="M9.00012 16.1998L5.50012 12.6998C5.11012 12.3098 4.49012 12.3098 4.10012 12.6998C3.71012 13.0898 3.71012 13.7098 4.10012 14.0998L8.29012 18.2898C8.68012 18.6798 9.31012 18.6798 9.70012 18.2898L20.3001 7.69982C20.6901 7.30982 20.6901 6.68982 20.3001 6.29982C19.9101 5.90982 19.2901 5.90982 18.9001 6.29982L9.00012 16.1998Z" fill="#817567"/>
40
+ </g>
41
+ <defs>
42
+ <clipPath id="clip0_1013_1545">
43
+ <rect width="24" height="24" fill="white"/>
44
+ </clipPath>
45
+ </defs>
46
+ </svg>
47
+ `
@@ -0,0 +1,22 @@
1
+ /* Copyright 2021, Milkdown by Mirone. */
2
+ import { configureLinkTooltip, linkTooltipConfig, linkTooltipPlugin } from '@milkdown/components/link-tooltip'
3
+ import { injectStyle } from '../../core/slice'
4
+ import type { DefineFeature } from '../shared'
5
+ import { confirmIcon, deleteIcon, editIcon, linkIcon } from './consts'
6
+ import style from './style.css?inline'
7
+
8
+ export const defineFeature: DefineFeature = (editor) => {
9
+ editor
10
+ .config(injectStyle(style))
11
+ .config(configureLinkTooltip)
12
+ .config((ctx) => {
13
+ ctx.update(linkTooltipConfig.key, config => ({
14
+ ...config,
15
+ linkIcon: () => linkIcon,
16
+ editButton: () => editIcon,
17
+ removeButton: () => deleteIcon,
18
+ confirmButton: () => confirmIcon,
19
+ }))
20
+ })
21
+ .use(linkTooltipPlugin)
22
+ }
@@ -0,0 +1,107 @@
1
+ .milkdown {
2
+ milkdown-link-preview {
3
+ & > .link-preview {
4
+ height: 32px;
5
+ display: flex;
6
+ justify-content: center;
7
+ padding: 4px 10px;
8
+ background: var(--crepe-color-surface);
9
+ gap: 10px;
10
+ border-radius: 8px;
11
+ cursor: pointer;
12
+ box-shadow: var(--crepe-shadow-1);
13
+
14
+ & > .link-display:hover:before {
15
+ display: block;
16
+ }
17
+
18
+ & > .link-display:before {
19
+ content: 'click to copy link';
20
+ position: absolute;
21
+ transform: translate(50%, -120%);
22
+ padding: 3px 10px;
23
+ font-size: 12px;
24
+ border-radius: 8px;
25
+ color: color-mix(in srgb, var(--crepe-color-on-background), transparent 60%);
26
+ background: var(--crepe-color-background);
27
+ text-align: center;
28
+
29
+ display: none;
30
+ }
31
+
32
+ & > .link-icon {
33
+ & > svg {
34
+ width: 18px;
35
+ height: 18px;
36
+ }
37
+ padding: 3px;
38
+ line-height: 24px;
39
+ }
40
+
41
+ & > .link-display {
42
+ width: 240px;
43
+ line-height: 24px;
44
+ overflow: hidden;
45
+ text-overflow: ellipsis;
46
+ font-size: 14px;
47
+ &:hover {
48
+ text-decoration: underline;
49
+ }
50
+ }
51
+
52
+ & > .button {
53
+ & > svg {
54
+ width: 18px;
55
+ height: 18px;
56
+ color: var(--crepe-color-outline);
57
+ }
58
+ padding: 3px;
59
+ border-radius: 8px;
60
+ line-height: 24px;
61
+ &:hover {
62
+ background: var(--crepe-color-hover);
63
+ }
64
+ }
65
+ }
66
+ }
67
+
68
+ milkdown-link-edit {
69
+ & > .link-edit {
70
+ height: 32px;
71
+ display: flex;
72
+ justify-content: center;
73
+ padding: 4px 10px 4px 20px;
74
+ background: var(--crepe-color-surface);
75
+ gap: 8px;
76
+ border-radius: 8px;
77
+ box-shadow: var(--crepe-shadow-1);
78
+
79
+ & > .input-area {
80
+ outline: none;
81
+ background: transparent;
82
+ width: 200px;
83
+ font-size: 14px;
84
+ color: var(--crepe-color-on-background);
85
+ }
86
+
87
+ & > .button {
88
+ & > svg {
89
+ width: 18px;
90
+ height: 18px;
91
+ color: var(--crepe-color-outline);
92
+ }
93
+ padding: 3px;
94
+ cursor: pointer;
95
+ border-radius: 8px;
96
+ font-size: 12px;
97
+ line-height: 24px;
98
+ &:hover {
99
+ background: var(--crepe-color-hover);
100
+ }
101
+ &.hidden {
102
+ visibility: hidden;
103
+ }
104
+ }
105
+ }
106
+ }
107
+ }
@@ -0,0 +1,15 @@
1
+ /* Copyright 2021, Milkdown by Mirone. */
2
+ import { html } from 'atomico'
3
+
4
+ export const bulletIcon = 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_952_6527)">
7
+ <circle cx="12" cy="12" r="3" fill="#817567"/>
8
+ </g>
9
+ <defs>
10
+ <clipPath id="clip0_952_6527">
11
+ <rect width="24" height="24" fill="white"/>
12
+ </clipPath>
13
+ </defs>
14
+ </svg>
15
+ `
@@ -0,0 +1,30 @@
1
+ /* Copyright 2021, Milkdown by Mirone. */
2
+ import type { Ctx } from '@milkdown/ctx'
3
+ import { listItemBlockComponent, listItemBlockConfig } from '@milkdown/components/list-item-block'
4
+ import { html } from 'atomico'
5
+ import { injectStyle } from '../../core/slice'
6
+ import type { DefineFeature } from '../shared'
7
+ import { bulletIcon } from './consts'
8
+ import style from './style.css?inline'
9
+
10
+ function configureListItem(ctx: Ctx) {
11
+ ctx.set(listItemBlockConfig.key, {
12
+ renderLabel: (label: string, listType, checked?: boolean) => {
13
+ if (checked == null) {
14
+ if (listType === 'bullet')
15
+ return html`<span class='label'>${bulletIcon}</span>`
16
+
17
+ return html`<span class='label'>${label}</span>`
18
+ }
19
+
20
+ return html`<input class='label' type="checkbox" checked=${checked} />`
21
+ },
22
+ })
23
+ }
24
+
25
+ export const defineFeature: DefineFeature = (editor) => {
26
+ editor
27
+ .config(injectStyle(style))
28
+ .config(configureListItem)
29
+ .use(listItemBlockComponent)
30
+ }
@@ -0,0 +1,23 @@
1
+ .milkdown {
2
+ milkdown-list-item-block {
3
+ display: block;
4
+ margin-top: 10px;
5
+
6
+ li {
7
+ gap: 10px;
8
+ .label-wrapper {
9
+ color: var(--crepe-color-outline);
10
+ height: 24px;
11
+ width: 24px;
12
+ display: flex;
13
+ justify-content: center;
14
+ align-items: center;
15
+ .label {
16
+ height: 24px;
17
+ width: 24px;
18
+ text-align: right;
19
+ }
20
+ }
21
+ }
22
+ }
23
+ }
@@ -0,0 +1,87 @@
1
+ /* Copyright 2021, Milkdown by Mirone. */
2
+ import { $ctx, $prose } from '@milkdown/utils'
3
+ import type { EditorState } from '@milkdown/prose/state'
4
+ import { Plugin, PluginKey } from '@milkdown/prose/state'
5
+ import type { Node } from '@milkdown/prose/model'
6
+ import { Decoration, DecorationSet } from '@milkdown/prose/view'
7
+ import type { DefineFeature } from '../shared'
8
+ import { injectStyle } from '../../core/slice'
9
+ import { isInCodeBlock, isInList } from '../../utils'
10
+ import style from './style.css?inline'
11
+
12
+ function isDocEmpty(doc: Node) {
13
+ return doc.childCount <= 1 && !doc.firstChild?.content.size
14
+ }
15
+
16
+ function createPlaceholderDecoration(
17
+ state: EditorState,
18
+ placeholderText: string,
19
+ ): Decoration | null {
20
+ const { selection } = state
21
+ if (!selection.empty)
22
+ return null
23
+
24
+ const $pos = selection.$anchor
25
+ const node = $pos.parent
26
+ if (node.content.size > 0)
27
+ return null
28
+
29
+ const before = $pos.before()
30
+
31
+ return Decoration.node(before, before + node.nodeSize, {
32
+ 'class': 'crepe-placeholder',
33
+ 'data-placeholder': placeholderText,
34
+ })
35
+ }
36
+
37
+ export interface PlaceholderConfig {
38
+ text: string
39
+ mode: 'doc' | 'block'
40
+ }
41
+
42
+ export type PlaceHolderFeatureConfig = Partial<PlaceholderConfig>
43
+
44
+ export const placeholderConfig = $ctx({
45
+ text: 'Please enter...',
46
+ mode: 'block',
47
+ } as PlaceholderConfig, 'placeholderConfigCtx')
48
+
49
+ export const placeholderPlugin = $prose((ctx) => {
50
+ return new Plugin({
51
+ key: new PluginKey('CREPE_PLACEHOLDER'),
52
+ props: {
53
+ decorations: (state) => {
54
+ const config = ctx.get(placeholderConfig.key)
55
+ if (config.mode === 'doc' && !isDocEmpty(state.doc))
56
+ return null
57
+
58
+ if (isInCodeBlock(state.selection) || isInList(state.selection))
59
+ return null
60
+
61
+ const placeholderText = config.text
62
+ const deco = createPlaceholderDecoration(state, placeholderText)
63
+ if (!deco)
64
+ return null
65
+
66
+ return DecorationSet.create(state.doc, [deco])
67
+ },
68
+ },
69
+ })
70
+ })
71
+
72
+ export const defineFeature: DefineFeature<PlaceHolderFeatureConfig> = (editor, config) => {
73
+ editor
74
+ .config(injectStyle(style))
75
+ .config((ctx) => {
76
+ if (config) {
77
+ ctx.update(placeholderConfig.key, (prev) => {
78
+ return {
79
+ ...prev,
80
+ ...config,
81
+ }
82
+ })
83
+ }
84
+ })
85
+ .use(placeholderPlugin)
86
+ .use(placeholderConfig)
87
+ }
@@ -0,0 +1,9 @@
1
+ .milkdown {
2
+ .crepe-placeholder::before {
3
+ position: absolute;
4
+ color: color-mix(in srgb, var(--crepe-color-on-background), transparent 60%);
5
+ pointer-events: none;
6
+ height: 0;
7
+ content: attr(data-placeholder);
8
+ }
9
+ }
@@ -0,0 +1,4 @@
1
+ /* Copyright 2021, Milkdown by Mirone. */
2
+ import type { Editor } from '@milkdown/core'
3
+
4
+ export type DefineFeature<Config = unknown> = (editor: Editor, config?: Config) => void
@@ -0,0 +1,101 @@
1
+ /* Copyright 2021, Milkdown by Mirone. */
2
+ import type { Component } from 'atomico'
3
+ import { c, html, useEffect, useUpdate } from 'atomico'
4
+ import type { Ctx } from '@milkdown/ctx'
5
+ import { commandsCtx, editorViewCtx } from '@milkdown/core'
6
+ import {
7
+ emphasisSchema,
8
+ inlineCodeSchema,
9
+ linkSchema,
10
+ strongSchema,
11
+ toggleEmphasisCommand,
12
+ toggleInlineCodeCommand,
13
+ toggleStrongCommand,
14
+ } from '@milkdown/preset-commonmark'
15
+ import type { MarkType } from '@milkdown/prose/model'
16
+ import clsx from 'clsx'
17
+ import { linkTooltipAPI } from '@milkdown/components'
18
+ import { boldIcon, codeIcon, italicIcon, linkIcon } from './consts'
19
+
20
+ export interface ToolbarProps {
21
+ ctx: Ctx
22
+ hide: () => void
23
+ show: boolean
24
+ }
25
+
26
+ export const toolbarComponent: Component<ToolbarProps> = ({ ctx, hide, show }) => {
27
+ const update = useUpdate()
28
+ useEffect(() => {
29
+ update()
30
+ }, [show])
31
+
32
+ const onClick = (fn: (ctx: Ctx) => void) => (e: MouseEvent) => {
33
+ e.preventDefault()
34
+ ctx && fn(ctx)
35
+ update()
36
+ }
37
+
38
+ const isActive = (mark: MarkType) => {
39
+ if (!ctx)
40
+ return false
41
+ const view = ctx.get(editorViewCtx)
42
+ const { state: { doc, selection } } = view
43
+ return doc.rangeHasMark(selection.from, selection.to, mark)
44
+ }
45
+
46
+ return html`<host>
47
+ <button
48
+ class=${clsx('toolbar-item', ctx && isActive(strongSchema.type(ctx)) && 'active')}
49
+ onmousedown=${onClick((ctx) => {
50
+ const commands = ctx.get(commandsCtx)
51
+ commands.call(toggleStrongCommand.key)
52
+ })}
53
+ >
54
+ ${boldIcon}
55
+ </button>
56
+ <button
57
+ class=${clsx('toolbar-item', ctx && isActive(emphasisSchema.type(ctx)) && 'active')}
58
+ onmousedown=${onClick((ctx) => {
59
+ const commands = ctx.get(commandsCtx)
60
+ commands.call(toggleEmphasisCommand.key)
61
+ })}
62
+ >
63
+ ${italicIcon}
64
+ </button>
65
+ <div class="divider"></div>
66
+ <button
67
+ class=${clsx('toolbar-item', ctx && isActive(inlineCodeSchema.type(ctx)) && 'active')}
68
+ onmousedown=${onClick((ctx) => {
69
+ const commands = ctx.get(commandsCtx)
70
+ commands.call(toggleInlineCodeCommand.key)
71
+ })}
72
+ >
73
+ ${codeIcon}
74
+ </button>
75
+ <button
76
+ class=${clsx('toolbar-item', ctx && isActive(linkSchema.type(ctx)) && 'active')}
77
+ onmousedown=${onClick((ctx) => {
78
+ const view = ctx.get(editorViewCtx)
79
+ const { selection } = view.state
80
+
81
+ if (isActive(linkSchema.type(ctx))) {
82
+ ctx.get(linkTooltipAPI.key).removeLink(selection.from, selection.to)
83
+ return
84
+ }
85
+
86
+ ctx.get(linkTooltipAPI.key).addLink(selection.from, selection.to)
87
+ hide?.()
88
+ })}
89
+ >
90
+ ${linkIcon}
91
+ </button>
92
+ </host>`
93
+ }
94
+
95
+ toolbarComponent.props = {
96
+ ctx: Object,
97
+ hide: Function,
98
+ show: Boolean,
99
+ }
100
+
101
+ export const ToolbarElement = c(toolbarComponent)
@@ -0,0 +1,26 @@
1
+ /* Copyright 2021, Milkdown by Mirone. */
2
+ import { html } from 'atomico'
3
+
4
+ export const boldIcon = html`
5
+ <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none">
6
+ <path d="M8.85758 18.625C8.4358 18.625 8.07715 18.4772 7.78163 18.1817C7.48613 17.8862 7.33838 17.5275 7.33838 17.1058V6.8942C7.33838 6.47242 7.48613 6.11377 7.78163 5.81825C8.07715 5.52275 8.4358 5.375 8.85758 5.375H12.1999C13.2191 5.375 14.1406 5.69231 14.9643 6.32693C15.788 6.96154 16.1999 7.81603 16.1999 8.89038C16.1999 9.63779 16.0194 10.2471 15.6585 10.7183C15.2976 11.1894 14.9088 11.5314 14.4922 11.7442C15.005 11.9211 15.4947 12.2708 15.9614 12.7933C16.428 13.3157 16.6614 14.0192 16.6614 14.9038C16.6614 16.182 16.1902 17.1217 15.2479 17.723C14.3056 18.3243 13.3563 18.625 12.3999 18.625H8.85758ZM9.4883 16.6327H12.3191C13.1063 16.6327 13.6627 16.4141 13.9884 15.9769C14.314 15.5397 14.4768 15.1205 14.4768 14.7192C14.4768 14.3179 14.314 13.8987 13.9884 13.4615C13.6627 13.0243 13.0909 12.8057 12.273 12.8057H9.4883V16.6327ZM9.4883 10.875H12.0826C12.6903 10.875 13.172 10.7013 13.5278 10.3539C13.8836 10.0064 14.0615 9.59037 14.0615 9.10575C14.0615 8.59035 13.8733 8.16918 13.497 7.84225C13.1207 7.51533 12.6595 7.35188 12.1133 7.35188H9.4883V10.875Z" fill="#817567"/>
7
+ </svg>
8
+ `
9
+
10
+ export const italicIcon = html`
11
+ <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none">
12
+ <path d="M6.29811 18.625C6.04505 18.625 5.83115 18.5375 5.65641 18.3626C5.48166 18.1877 5.39429 17.9736 5.39429 17.7203C5.39429 17.467 5.48166 17.2532 5.65641 17.0788C5.83115 16.9045 6.04505 16.8173 6.29811 16.8173H9.21159L12.452 7.18265H9.53851C9.28545 7.18265 9.07155 7.0952 8.89681 6.9203C8.72206 6.7454 8.63469 6.5313 8.63469 6.278C8.63469 6.02472 8.72206 5.81089 8.89681 5.63652C9.07155 5.46217 9.28545 5.375 9.53851 5.375H16.8847C17.1377 5.375 17.3516 5.46245 17.5264 5.63735C17.7011 5.81225 17.7885 6.02634 17.7885 6.27962C17.7885 6.53293 17.7011 6.74676 17.5264 6.92113C17.3516 7.09548 17.1377 7.18265 16.8847 7.18265H14.2789L11.0385 16.8173H13.6443C13.8973 16.8173 14.1112 16.9048 14.286 17.0797C14.4607 17.2546 14.5481 17.4687 14.5481 17.722C14.5481 17.9752 14.4607 18.1891 14.286 18.3634C14.1112 18.5378 13.8973 18.625 13.6443 18.625H6.29811Z" fill="#817567"/>
13
+ </svg>
14
+ `
15
+
16
+ export const codeIcon = html`
17
+ <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none">
18
+ <path d="M4.46924 12.0158L8.52694 16.0735C8.66541 16.212 8.73624 16.386 8.73944 16.5956C8.74266 16.8052 8.67183 16.9824 8.52694 17.1273C8.38208 17.2722 8.20644 17.3446 8.00004 17.3446C7.79364 17.3446 7.61801 17.2722 7.47315 17.1273L2.97892 12.6331C2.88532 12.5395 2.81929 12.4408 2.78084 12.3369C2.74238 12.2331 2.72314 12.1209 2.72314 12.0004C2.72314 11.8799 2.74238 11.7677 2.78084 11.6639C2.81929 11.56 2.88532 11.4613 2.97892 11.3677L7.47315 6.87351C7.62184 6.72479 7.79844 6.64882 8.00292 6.6456C8.2074 6.6424 8.38721 6.71837 8.54234 6.87351C8.69746 7.02862 8.77502 7.20682 8.77502 7.4081C8.77502 7.60937 8.69746 7.78757 8.54234 7.94271L4.46924 12.0158ZM19.5308 11.985L15.4731 7.9273C15.3347 7.78885 15.2638 7.61482 15.2606 7.40521C15.2574 7.19561 15.3283 7.01837 15.4731 6.87351C15.618 6.72862 15.7936 6.65618 16 6.65618C16.2064 6.65618 16.3821 6.72862 16.5269 6.87351L21.0212 11.3677C21.1148 11.4613 21.1808 11.56 21.2192 11.6639C21.2577 11.7677 21.2769 11.8799 21.2769 12.0004C21.2769 12.1209 21.2577 12.2331 21.2192 12.3369C21.1808 12.4408 21.1148 12.5395 21.0212 12.6331L16.5269 17.1273C16.3782 17.276 16.2042 17.3494 16.0048 17.3475C15.8055 17.3456 15.6283 17.2671 15.4731 17.1119C15.318 16.9568 15.2404 16.7786 15.2404 16.5773C15.2404 16.376 15.318 16.1978 15.4731 16.0427L19.5308 11.985Z" fill="#817567"/>
19
+ </svg>
20
+ `
21
+
22
+ export const linkIcon = html`
23
+ <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none">
24
+ <path d="M17.0385 19.5003V16.5388H14.0769V15.0388H17.0385V12.0773H18.5384V15.0388H21.5V16.5388H18.5384V19.5003H17.0385ZM10.8077 16.5388H7.03845C5.78282 16.5388 4.7125 16.0963 3.8275 15.2114C2.9425 14.3266 2.5 13.2564 2.5 12.0009C2.5 10.7454 2.9425 9.67504 3.8275 8.78979C4.7125 7.90454 5.78282 7.46191 7.03845 7.46191H10.8077V8.96186H7.03845C6.1987 8.96186 5.48235 9.25834 4.8894 9.85129C4.29645 10.4442 3.99998 11.1606 3.99998 12.0003C3.99998 12.8401 4.29645 13.5564 4.8894 14.1494C5.48235 14.7423 6.1987 15.0388 7.03845 15.0388H10.8077V16.5388ZM8.25 12.7503V11.2504H15.75V12.7503H8.25ZM21.5 12.0003H20C20 11.1606 19.7035 10.4442 19.1106 9.85129C18.5176 9.25834 17.8013 8.96186 16.9615 8.96186H13.1923V7.46191H16.9615C18.2171 7.46191 19.2875 7.90441 20.1725 8.78939C21.0575 9.67439 21.5 10.7447 21.5 12.0003Z" fill="#817567"/>
25
+ </svg>
26
+ `
@@ -0,0 +1,92 @@
1
+ /* Copyright 2021, Milkdown by Mirone. */
2
+ import { TooltipProvider, tooltipFactory } from '@milkdown/plugin-tooltip'
3
+ import type { EditorState, PluginView } from '@milkdown/prose/state'
4
+ import { TextSelection } from '@milkdown/prose/state'
5
+ import type { Ctx } from '@milkdown/ctx'
6
+ import type { EditorView } from '@milkdown/prose/view'
7
+ import type { AtomicoThis } from 'atomico/types/dom'
8
+ import type { DefineFeature } from '../shared'
9
+ import { injectStyle } from '../../core/slice'
10
+ import type { ToolbarProps } from './component'
11
+ import { ToolbarElement } from './component'
12
+ import style from './style.css?inline'
13
+
14
+ const toolbar = tooltipFactory('CREPE_TOOLBAR')
15
+
16
+ class ToolbarView implements PluginView {
17
+ #tooltipProvider: TooltipProvider
18
+ #content: AtomicoThis<ToolbarProps>
19
+ constructor(ctx: Ctx, view: EditorView) {
20
+ const content = new ToolbarElement()
21
+ this.#content = content
22
+ this.#content.ctx = ctx
23
+ this.#content.hide = this.hide
24
+
25
+ this.#tooltipProvider = new TooltipProvider({
26
+ content: this.#content,
27
+ debounce: 20,
28
+ tippyOptions: {
29
+ arrow: false,
30
+ delay: 0,
31
+ duration: 0,
32
+ onShow: () => {
33
+ this.#content.show = true
34
+ },
35
+ onHidden: () => {
36
+ this.#content.show = false
37
+ },
38
+ },
39
+ shouldShow(view: EditorView) {
40
+ const { doc, selection } = view.state
41
+ const { empty, from, to } = selection
42
+
43
+ const isEmptyTextBlock = !doc.textBetween(from, to).length && selection instanceof TextSelection
44
+
45
+ const isNotTextBlock = !(selection instanceof TextSelection)
46
+
47
+ const isTooltipChildren = content.contains(document.activeElement)
48
+
49
+ const notHasFocus = !view.hasFocus() && !isTooltipChildren
50
+
51
+ const isReadonly = !view.editable
52
+
53
+ if (
54
+ notHasFocus
55
+ || isNotTextBlock
56
+ || empty
57
+ || isEmptyTextBlock
58
+ || isReadonly
59
+ )
60
+ return false
61
+
62
+ return true
63
+ },
64
+ })
65
+ this.update(view)
66
+ }
67
+
68
+ update = (view: EditorView, prevState?: EditorState) => {
69
+ this.#tooltipProvider.update(view, prevState)
70
+ }
71
+
72
+ destroy = () => {
73
+ this.#tooltipProvider.destroy()
74
+ this.#content.remove()
75
+ }
76
+
77
+ hide = () => {
78
+ this.#tooltipProvider.hide()
79
+ }
80
+ }
81
+
82
+ customElements.define('milkdown-toolbar', ToolbarElement)
83
+ export const defineFeature: DefineFeature = (editor) => {
84
+ editor
85
+ .config(injectStyle(style))
86
+ .config((ctx) => {
87
+ ctx.set(toolbar.key, {
88
+ view: view => new ToolbarView(ctx, view),
89
+ })
90
+ })
91
+ .use(toolbar)
92
+ }
@@ -0,0 +1,37 @@
1
+ .milkdown {
2
+ milkdown-toolbar {
3
+ display: flex;
4
+ background: var(--crepe-color-surface);
5
+ box-shadow: var(--crepe-shadow-1);
6
+ border-radius: 8px;
7
+ overflow: hidden;
8
+
9
+ .divider {
10
+ width: 1px;
11
+ background: color-mix(in srgb, var(--crepe-color-outline), transparent 80%);
12
+ height: 24px;
13
+ margin: 10px;
14
+ }
15
+
16
+ .toolbar-item {
17
+ width: 44px;
18
+ height: 44px;
19
+ padding: 10px;
20
+ cursor: pointer;
21
+
22
+ &:hover {
23
+ background: var(--crepe-color-hover)
24
+ }
25
+
26
+ &.active {
27
+ background: var(--crepe-color-selected);
28
+ }
29
+
30
+ svg {
31
+ height: 24px;
32
+ width: 24px;
33
+ color: var(--crepe-color-outline);
34
+ }
35
+ }
36
+ }
37
+ }