@milkdown/crepe 7.11.1 → 7.12.1

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 (187) hide show
  1. package/lib/cjs/builder.js +107 -0
  2. package/lib/cjs/builder.js.map +1 -0
  3. package/lib/cjs/{index-CtTpZYVe.js → feature/block-edit/index.js} +165 -61
  4. package/lib/cjs/feature/block-edit/index.js.map +1 -0
  5. package/lib/cjs/feature/code-mirror/index.js +161 -0
  6. package/lib/cjs/feature/code-mirror/index.js.map +1 -0
  7. package/lib/cjs/feature/cursor/index.js +57 -0
  8. package/lib/cjs/feature/cursor/index.js.map +1 -0
  9. package/lib/cjs/feature/image-block/index.js +123 -0
  10. package/lib/cjs/feature/image-block/index.js.map +1 -0
  11. package/lib/cjs/{index-2icTTGim.js → feature/latex/index.js} +111 -24
  12. package/lib/cjs/feature/latex/index.js.map +1 -0
  13. package/lib/cjs/feature/link-tooltip/index.js +124 -0
  14. package/lib/cjs/feature/link-tooltip/index.js.map +1 -0
  15. package/lib/cjs/{index-Dw6lXgs6.js → feature/list-item/index.js} +39 -8
  16. package/lib/cjs/feature/list-item/index.js.map +1 -0
  17. package/lib/cjs/{index-B91KhPew.js → feature/placeholder/index.js} +46 -6
  18. package/lib/cjs/feature/placeholder/index.js.map +1 -0
  19. package/lib/cjs/{index-DEs_IHHy.js → feature/table/index.js} +78 -16
  20. package/lib/cjs/feature/table/index.js.map +1 -0
  21. package/lib/cjs/{index-k3lGvKiX.js → feature/toolbar/index.js} +133 -31
  22. package/lib/cjs/feature/toolbar/index.js.map +1 -0
  23. package/lib/cjs/index.js +2461 -17
  24. package/lib/cjs/index.js.map +1 -1
  25. package/lib/esm/builder.js +105 -0
  26. package/lib/esm/builder.js.map +1 -0
  27. package/lib/esm/{index-BEe1TpeS.js → feature/block-edit/index.js} +161 -57
  28. package/lib/esm/feature/block-edit/index.js.map +1 -0
  29. package/lib/esm/feature/code-mirror/index.js +159 -0
  30. package/lib/esm/feature/code-mirror/index.js.map +1 -0
  31. package/lib/esm/feature/cursor/index.js +55 -0
  32. package/lib/esm/feature/cursor/index.js.map +1 -0
  33. package/lib/esm/feature/image-block/index.js +121 -0
  34. package/lib/esm/feature/image-block/index.js.map +1 -0
  35. package/lib/esm/{index-ZGfGszIQ.js → feature/latex/index.js} +107 -20
  36. package/lib/esm/feature/latex/index.js.map +1 -0
  37. package/lib/esm/feature/link-tooltip/index.js +122 -0
  38. package/lib/esm/feature/link-tooltip/index.js.map +1 -0
  39. package/lib/esm/{index-E8UgFLeN.js → feature/list-item/index.js} +39 -8
  40. package/lib/esm/feature/list-item/index.js.map +1 -0
  41. package/lib/esm/{index-BCvtgOeI.js → feature/placeholder/index.js} +45 -5
  42. package/lib/esm/feature/placeholder/index.js.map +1 -0
  43. package/lib/esm/{index-CwMVnVeI.js → feature/table/index.js} +78 -16
  44. package/lib/esm/feature/table/index.js.map +1 -0
  45. package/lib/esm/{index-CTBg0aec.js → feature/toolbar/index.js} +128 -26
  46. package/lib/esm/feature/toolbar/index.js.map +1 -0
  47. package/lib/esm/index.js +2457 -11
  48. package/lib/esm/index.js.map +1 -1
  49. package/lib/tsconfig.tsbuildinfo +1 -1
  50. package/lib/types/builder.d.ts +2 -0
  51. package/lib/types/builder.d.ts.map +1 -0
  52. package/lib/types/core/builder.d.ts +23 -0
  53. package/lib/types/core/builder.d.ts.map +1 -0
  54. package/lib/types/core/crepe.d.ts +4 -15
  55. package/lib/types/core/crepe.d.ts.map +1 -1
  56. package/lib/types/core/index.d.ts +2 -1
  57. package/lib/types/core/index.d.ts.map +1 -1
  58. package/lib/types/core/slice.d.ts +6 -4
  59. package/lib/types/core/slice.d.ts.map +1 -1
  60. package/lib/types/default-config/index.d.ts +3 -0
  61. package/lib/types/default-config/index.d.ts.map +1 -0
  62. package/lib/types/feature/block-edit/handle/component.d.ts +2 -3
  63. package/lib/types/feature/block-edit/handle/component.d.ts.map +1 -1
  64. package/lib/types/feature/block-edit/index.d.ts +20 -20
  65. package/lib/types/feature/block-edit/index.d.ts.map +1 -1
  66. package/lib/types/feature/code-mirror/index.d.ts +7 -7
  67. package/lib/types/feature/code-mirror/index.d.ts.map +1 -1
  68. package/lib/types/feature/cursor/index.d.ts +1 -1
  69. package/lib/types/feature/cursor/index.d.ts.map +1 -1
  70. package/lib/types/feature/image-block/index.d.ts +9 -9
  71. package/lib/types/feature/image-block/index.d.ts.map +1 -1
  72. package/lib/types/feature/index.d.ts +2 -4
  73. package/lib/types/feature/index.d.ts.map +1 -1
  74. package/lib/types/feature/latex/index.d.ts +3 -3
  75. package/lib/types/feature/latex/index.d.ts.map +1 -1
  76. package/lib/types/feature/link-tooltip/index.d.ts +6 -6
  77. package/lib/types/feature/link-tooltip/index.d.ts.map +1 -1
  78. package/lib/types/feature/list-item/index.d.ts +5 -5
  79. package/lib/types/feature/list-item/index.d.ts.map +1 -1
  80. package/lib/types/feature/loader.d.ts +4 -0
  81. package/lib/types/feature/loader.d.ts.map +1 -0
  82. package/lib/types/feature/placeholder/index.d.ts +2 -2
  83. package/lib/types/feature/placeholder/index.d.ts.map +1 -1
  84. package/lib/types/feature/shared.d.ts +1 -2
  85. package/lib/types/feature/shared.d.ts.map +1 -1
  86. package/lib/types/feature/table/index.d.ts +11 -11
  87. package/lib/types/feature/table/index.d.ts.map +1 -1
  88. package/lib/types/feature/toolbar/index.d.ts +8 -8
  89. package/lib/types/feature/toolbar/index.d.ts.map +1 -1
  90. package/lib/types/icons/index.d.ts +1 -0
  91. package/lib/types/icons/index.d.ts.map +1 -1
  92. package/lib/types/index.d.ts +1 -1
  93. package/lib/types/index.d.ts.map +1 -1
  94. package/lib/types/utils/index.d.ts +0 -1
  95. package/lib/types/utils/index.d.ts.map +1 -1
  96. package/package.json +60 -3
  97. package/src/builder.ts +1 -0
  98. package/src/core/builder.ts +143 -0
  99. package/src/core/crepe.ts +14 -130
  100. package/src/core/index.ts +2 -1
  101. package/src/core/slice.ts +37 -8
  102. package/src/default-config/index.ts +25 -0
  103. package/src/feature/block-edit/handle/component.tsx +6 -8
  104. package/src/feature/block-edit/handle/index.ts +2 -2
  105. package/src/feature/block-edit/index.ts +23 -20
  106. package/src/feature/block-edit/menu/config.ts +19 -19
  107. package/src/feature/code-mirror/index.ts +32 -28
  108. package/src/feature/cursor/index.ts +10 -6
  109. package/src/feature/image-block/index.ts +19 -16
  110. package/src/feature/index.ts +2 -53
  111. package/src/feature/latex/index.ts +8 -10
  112. package/src/feature/latex/inline-tooltip/component.tsx +1 -1
  113. package/src/feature/link-tooltip/index.ts +13 -10
  114. package/src/feature/list-item/index.ts +11 -8
  115. package/src/feature/loader.ts +52 -0
  116. package/src/feature/placeholder/index.ts +5 -2
  117. package/src/feature/shared.ts +1 -3
  118. package/src/feature/table/index.ts +23 -23
  119. package/src/feature/toolbar/component.tsx +9 -9
  120. package/src/feature/toolbar/index.ts +14 -11
  121. package/src/icons/index.ts +1 -0
  122. package/src/index.ts +1 -1
  123. package/src/utils/index.ts +0 -8
  124. package/lib/cjs/confirm-CNveM9QH.js +0 -26
  125. package/lib/cjs/confirm-CNveM9QH.js.map +0 -1
  126. package/lib/cjs/edit-BUtBJHpV.js +0 -24
  127. package/lib/cjs/edit-BUtBJHpV.js.map +0 -1
  128. package/lib/cjs/functions-BAY51plB.js +0 -39
  129. package/lib/cjs/functions-BAY51plB.js.map +0 -1
  130. package/lib/cjs/image-BXLkOVnO.js +0 -24
  131. package/lib/cjs/image-BXLkOVnO.js.map +0 -1
  132. package/lib/cjs/index-2icTTGim.js.map +0 -1
  133. package/lib/cjs/index-B91KhPew.js.map +0 -1
  134. package/lib/cjs/index-BsrJn8Jp.js +0 -41
  135. package/lib/cjs/index-BsrJn8Jp.js.map +0 -1
  136. package/lib/cjs/index-C2CAbC2F.js +0 -26
  137. package/lib/cjs/index-C2CAbC2F.js.map +0 -1
  138. package/lib/cjs/index-CtTpZYVe.js.map +0 -1
  139. package/lib/cjs/index-DEs_IHHy.js.map +0 -1
  140. package/lib/cjs/index-DLIudQKW.js +0 -126
  141. package/lib/cjs/index-DLIudQKW.js.map +0 -1
  142. package/lib/cjs/index-Dw6lXgs6.js.map +0 -1
  143. package/lib/cjs/index-k3lGvKiX.js.map +0 -1
  144. package/lib/cjs/index-urTgNBfI.js +0 -202
  145. package/lib/cjs/index-urTgNBfI.js.map +0 -1
  146. package/lib/cjs/index-xbwf60wt.js +0 -15
  147. package/lib/cjs/index-xbwf60wt.js.map +0 -1
  148. package/lib/cjs/index-xbxqAqH2.js +0 -52
  149. package/lib/cjs/index-xbxqAqH2.js.map +0 -1
  150. package/lib/cjs/inline-latex-D0G71cGk.js +0 -54
  151. package/lib/cjs/inline-latex-D0G71cGk.js.map +0 -1
  152. package/lib/cjs/plus-XLomtlXf.js +0 -24
  153. package/lib/cjs/plus-XLomtlXf.js.map +0 -1
  154. package/lib/cjs/remove-Ba-ypwBf.js +0 -17
  155. package/lib/cjs/remove-Ba-ypwBf.js.map +0 -1
  156. package/lib/esm/confirm-DtE-HkVd.js +0 -24
  157. package/lib/esm/confirm-DtE-HkVd.js.map +0 -1
  158. package/lib/esm/edit-D--t_JAb.js +0 -22
  159. package/lib/esm/edit-D--t_JAb.js.map +0 -1
  160. package/lib/esm/functions-DlJPkGmE.js +0 -36
  161. package/lib/esm/functions-DlJPkGmE.js.map +0 -1
  162. package/lib/esm/image-DoB1o1sl.js +0 -22
  163. package/lib/esm/image-DoB1o1sl.js.map +0 -1
  164. package/lib/esm/index-BCvtgOeI.js.map +0 -1
  165. package/lib/esm/index-BEe1TpeS.js.map +0 -1
  166. package/lib/esm/index-BPG8iO8t.js +0 -12
  167. package/lib/esm/index-BPG8iO8t.js.map +0 -1
  168. package/lib/esm/index-BUBXHhHG.js +0 -39
  169. package/lib/esm/index-BUBXHhHG.js.map +0 -1
  170. package/lib/esm/index-Bvz1Yyiz.js +0 -24
  171. package/lib/esm/index-Bvz1Yyiz.js.map +0 -1
  172. package/lib/esm/index-C1aVAv1l.js +0 -124
  173. package/lib/esm/index-C1aVAv1l.js.map +0 -1
  174. package/lib/esm/index-CTBg0aec.js.map +0 -1
  175. package/lib/esm/index-ChR5Qhyf.js +0 -50
  176. package/lib/esm/index-ChR5Qhyf.js.map +0 -1
  177. package/lib/esm/index-CshFzSt2.js +0 -197
  178. package/lib/esm/index-CshFzSt2.js.map +0 -1
  179. package/lib/esm/index-CwMVnVeI.js.map +0 -1
  180. package/lib/esm/index-E8UgFLeN.js.map +0 -1
  181. package/lib/esm/index-ZGfGszIQ.js.map +0 -1
  182. package/lib/esm/inline-latex-C9IGAXXQ.js +0 -51
  183. package/lib/esm/inline-latex-C9IGAXXQ.js.map +0 -1
  184. package/lib/esm/plus-lrX0Q75O.js +0 -22
  185. package/lib/esm/plus-lrX0Q75O.js.map +0 -1
  186. package/lib/esm/remove-D3g0Cd6_.js +0 -15
  187. package/lib/esm/remove-D3g0Cd6_.js.map +0 -1
@@ -18,8 +18,8 @@ import { TextSelection } from '@milkdown/kit/prose/state'
18
18
  import type { BlockEditFeatureConfig } from '../index'
19
19
  import type { MenuItemGroup } from './utils'
20
20
 
21
- import { CrepeFeature } from '../../..'
22
- import { FeaturesCtx } from '../../../core/slice'
21
+ import { useCrepeFeatures } from '../../../core/slice'
22
+ import { CrepeFeature } from '../../../feature'
23
23
  import {
24
24
  bulletListIcon,
25
25
  codeIcon,
@@ -51,7 +51,7 @@ export function getGroups(
51
51
  config?: BlockEditFeatureConfig,
52
52
  ctx?: Ctx
53
53
  ) {
54
- const flags = ctx?.get(FeaturesCtx)
54
+ const flags = ctx && useCrepeFeatures(ctx).get()
55
55
  const isLatexEnabled = flags?.includes(CrepeFeature.Latex)
56
56
  const isImageBlockEnabled = flags?.includes(CrepeFeature.ImageBlock)
57
57
  const isTableEnabled = flags?.includes(CrepeFeature.Table)
@@ -61,7 +61,7 @@ export function getGroups(
61
61
  .addGroup('text', config?.slashMenuTextGroupLabel ?? 'Text')
62
62
  .addItem('text', {
63
63
  label: config?.slashMenuTextLabel ?? 'Text',
64
- icon: config?.slashMenuTextIcon?.() ?? textIcon,
64
+ icon: config?.slashMenuTextIcon ?? textIcon,
65
65
  onRun: (ctx) => {
66
66
  const view = ctx.get(editorViewCtx)
67
67
  const { dispatch, state } = view
@@ -72,7 +72,7 @@ export function getGroups(
72
72
  })
73
73
  .addItem('h1', {
74
74
  label: config?.slashMenuH1Label ?? 'Heading 1',
75
- icon: config?.slashMenuH1Icon?.() ?? h1Icon,
75
+ icon: config?.slashMenuH1Icon ?? h1Icon,
76
76
  onRun: (ctx) => {
77
77
  const view = ctx.get(editorViewCtx)
78
78
  const { dispatch, state } = view
@@ -85,7 +85,7 @@ export function getGroups(
85
85
  })
86
86
  .addItem('h2', {
87
87
  label: config?.slashMenuH2Label ?? 'Heading 2',
88
- icon: config?.slashMenuH2Icon?.() ?? h2Icon,
88
+ icon: config?.slashMenuH2Icon ?? h2Icon,
89
89
  onRun: (ctx) => {
90
90
  const view = ctx.get(editorViewCtx)
91
91
  const { dispatch, state } = view
@@ -98,7 +98,7 @@ export function getGroups(
98
98
  })
99
99
  .addItem('h3', {
100
100
  label: config?.slashMenuH3Label ?? 'Heading 3',
101
- icon: config?.slashMenuH3Icon?.() ?? h3Icon,
101
+ icon: config?.slashMenuH3Icon ?? h3Icon,
102
102
  onRun: (ctx) => {
103
103
  const view = ctx.get(editorViewCtx)
104
104
  const { dispatch, state } = view
@@ -111,7 +111,7 @@ export function getGroups(
111
111
  })
112
112
  .addItem('h4', {
113
113
  label: config?.slashMenuH4Label ?? 'Heading 4',
114
- icon: config?.slashMenuH4Icon?.() ?? h4Icon,
114
+ icon: config?.slashMenuH4Icon ?? h4Icon,
115
115
  onRun: (ctx) => {
116
116
  const view = ctx.get(editorViewCtx)
117
117
  const { dispatch, state } = view
@@ -124,7 +124,7 @@ export function getGroups(
124
124
  })
125
125
  .addItem('h5', {
126
126
  label: config?.slashMenuH5Label ?? 'Heading 5',
127
- icon: config?.slashMenuH5Icon?.() ?? h5Icon,
127
+ icon: config?.slashMenuH5Icon ?? h5Icon,
128
128
  onRun: (ctx) => {
129
129
  const view = ctx.get(editorViewCtx)
130
130
  const { dispatch, state } = view
@@ -137,7 +137,7 @@ export function getGroups(
137
137
  })
138
138
  .addItem('h6', {
139
139
  label: config?.slashMenuH6Label ?? 'Heading 6',
140
- icon: config?.slashMenuH6Icon?.() ?? h6Icon,
140
+ icon: config?.slashMenuH6Icon ?? h6Icon,
141
141
  onRun: (ctx) => {
142
142
  const view = ctx.get(editorViewCtx)
143
143
  const { dispatch, state } = view
@@ -150,7 +150,7 @@ export function getGroups(
150
150
  })
151
151
  .addItem('quote', {
152
152
  label: config?.slashMenuQuoteLabel ?? 'Quote',
153
- icon: config?.slashMenuQuoteIcon?.() ?? quoteIcon,
153
+ icon: config?.slashMenuQuoteIcon ?? quoteIcon,
154
154
  onRun: (ctx) => {
155
155
  const view = ctx.get(editorViewCtx)
156
156
  const { dispatch, state } = view
@@ -163,7 +163,7 @@ export function getGroups(
163
163
  })
164
164
  .addItem('divider', {
165
165
  label: config?.slashMenuDividerLabel ?? 'Divider',
166
- icon: config?.slashMenuDividerIcon?.() ?? dividerIcon,
166
+ icon: config?.slashMenuDividerIcon ?? dividerIcon,
167
167
  onRun: (ctx) => {
168
168
  const view = ctx.get(editorViewCtx)
169
169
  const { dispatch, state } = view
@@ -177,7 +177,7 @@ export function getGroups(
177
177
  .addGroup('list', config?.slashMenuListGroupLabel ?? 'List')
178
178
  .addItem('bullet-list', {
179
179
  label: config?.slashMenuBulletListLabel ?? 'Bullet List',
180
- icon: config?.slashMenuBulletListIcon?.() ?? bulletListIcon,
180
+ icon: config?.slashMenuBulletListIcon ?? bulletListIcon,
181
181
  onRun: (ctx) => {
182
182
  const view = ctx.get(editorViewCtx)
183
183
  const { dispatch, state } = view
@@ -190,7 +190,7 @@ export function getGroups(
190
190
  })
191
191
  .addItem('ordered-list', {
192
192
  label: config?.slashMenuOrderedListLabel ?? 'Ordered List',
193
- icon: config?.slashMenuOrderedListIcon?.() ?? orderedListIcon,
193
+ icon: config?.slashMenuOrderedListIcon ?? orderedListIcon,
194
194
  onRun: (ctx) => {
195
195
  const view = ctx.get(editorViewCtx)
196
196
  const { dispatch, state } = view
@@ -203,7 +203,7 @@ export function getGroups(
203
203
  })
204
204
  .addItem('todo-list', {
205
205
  label: config?.slashMenuTaskListLabel ?? 'Todo List',
206
- icon: config?.slashMenuTaskListIcon?.() ?? todoListIcon,
206
+ icon: config?.slashMenuTaskListIcon ?? todoListIcon,
207
207
  onRun: (ctx) => {
208
208
  const view = ctx.get(editorViewCtx)
209
209
  const { dispatch, state } = view
@@ -224,7 +224,7 @@ export function getGroups(
224
224
  if (isImageBlockEnabled) {
225
225
  advancedGroup.addItem('image', {
226
226
  label: config?.slashMenuImageLabel ?? 'Image',
227
- icon: config?.slashMenuImageIcon?.() ?? imageIcon,
227
+ icon: config?.slashMenuImageIcon ?? imageIcon,
228
228
  onRun: (ctx) => {
229
229
  const view = ctx.get(editorViewCtx)
230
230
  const { dispatch, state } = view
@@ -237,7 +237,7 @@ export function getGroups(
237
237
 
238
238
  advancedGroup.addItem('code', {
239
239
  label: config?.slashMenuCodeBlockLabel ?? 'Code',
240
- icon: config?.slashMenuCodeBlockIcon?.() ?? codeIcon,
240
+ icon: config?.slashMenuCodeBlockIcon ?? codeIcon,
241
241
  onRun: (ctx) => {
242
242
  const view = ctx.get(editorViewCtx)
243
243
  const { dispatch, state } = view
@@ -250,7 +250,7 @@ export function getGroups(
250
250
  if (isTableEnabled) {
251
251
  advancedGroup.addItem('table', {
252
252
  label: config?.slashMenuTableLabel ?? 'Table',
253
- icon: config?.slashMenuTableIcon?.() ?? tableIcon,
253
+ icon: config?.slashMenuTableIcon ?? tableIcon,
254
254
  onRun: (ctx) => {
255
255
  const view = ctx.get(editorViewCtx)
256
256
  const { dispatch, state } = view
@@ -278,7 +278,7 @@ export function getGroups(
278
278
  if (isLatexEnabled) {
279
279
  advancedGroup.addItem('math', {
280
280
  label: config?.slashMenuMathLabel ?? 'Math',
281
- icon: config?.slashMenuMathIcon?.() ?? functionsIcon,
281
+ icon: config?.slashMenuMathIcon ?? functionsIcon,
282
282
  onRun: (ctx) => {
283
283
  const view = ctx.get(editorViewCtx)
284
284
  const { dispatch, state } = view
@@ -9,19 +9,26 @@ import {
9
9
  } from '@milkdown/kit/component/code-block'
10
10
  import { basicSetup } from 'codemirror'
11
11
 
12
- import type { DefineFeature, Icon } from '../shared'
12
+ import type { DefineFeature } from '../shared'
13
13
 
14
- import { chevronDownIcon, clearIcon, editIcon, searchIcon } from '../../icons'
15
- import { visibilityOffIcon } from '../../icons/visibility-off'
14
+ import { crepeFeatureConfig } from '../../core/slice'
15
+ import {
16
+ chevronDownIcon,
17
+ clearIcon,
18
+ editIcon,
19
+ searchIcon,
20
+ visibilityOffIcon,
21
+ } from '../../icons'
22
+ import { CrepeFeature } from '../index'
16
23
 
17
24
  interface CodeMirrorConfig {
18
25
  extensions: Extension[]
19
26
  languages: LanguageDescription[]
20
27
  theme: Extension
21
28
 
22
- expandIcon: Icon
23
- searchIcon: Icon
24
- clearSearchIcon: Icon
29
+ expandIcon: string
30
+ searchIcon: string
31
+ clearSearchIcon: string
25
32
 
26
33
  searchPlaceholder: string
27
34
  noResultText: string
@@ -33,41 +40,38 @@ interface CodeMirrorConfig {
33
40
  content: string
34
41
  ) => string | HTMLElement | null
35
42
 
36
- previewToggleIcon: (previewOnlyMode: boolean) => ReturnType<Icon>
43
+ previewToggleIcon: (previewOnlyMode: boolean) => string
37
44
  previewToggleText: (previewOnlyMode: boolean) => string
38
- previewLabel: () => string
45
+ previewLabel: string
39
46
  }
40
47
  export type CodeMirrorFeatureConfig = Partial<CodeMirrorConfig>
41
48
 
42
- export const defineFeature: DefineFeature<CodeMirrorFeatureConfig> = (
49
+ export const codeMirror: DefineFeature<CodeMirrorFeatureConfig> = (
43
50
  editor,
44
51
  config = {}
45
52
  ) => {
46
53
  editor
47
- .config(async (ctx) => {
48
- let { languages, theme } = config
49
- if (!languages) {
50
- const { languages: langList } = await import(
51
- '@codemirror/language-data'
52
- )
53
- languages = langList
54
+ .config(crepeFeatureConfig(CrepeFeature.CodeMirror))
55
+ .config((ctx) => {
56
+ const { languages = [], theme } = config
57
+ const extensions = [
58
+ keymap.of(defaultKeymap.concat(indentWithTab)),
59
+ basicSetup,
60
+ ]
61
+ if (theme) {
62
+ extensions.push(theme)
54
63
  }
55
- if (!theme) {
56
- const { oneDark } = await import('@codemirror/theme-one-dark')
57
- theme = oneDark
64
+ if (config.extensions) {
65
+ extensions.push(...config.extensions)
58
66
  }
67
+
59
68
  ctx.update(codeBlockConfig.key, (defaultConfig) => ({
60
- extensions: [
61
- keymap.of(defaultKeymap.concat(indentWithTab)),
62
- basicSetup,
63
- theme,
64
- ...(config?.extensions ?? []),
65
- ],
69
+ extensions,
66
70
  languages,
67
71
 
68
- expandIcon: () => config.expandIcon?.() || chevronDownIcon,
69
- searchIcon: () => config.searchIcon?.() || searchIcon,
70
- clearSearchIcon: () => config.clearSearchIcon?.() || clearIcon,
72
+ expandIcon: config.expandIcon || chevronDownIcon,
73
+ searchIcon: config.searchIcon || searchIcon,
74
+ clearSearchIcon: config.clearSearchIcon || clearIcon,
71
75
  searchPlaceholder: config.searchPlaceholder || 'Search language',
72
76
  noResultText: config.noResultText || 'No result',
73
77
  renderLanguage: config.renderLanguage || defaultConfig.renderLanguage,
@@ -1,9 +1,15 @@
1
- import { cursor, dropCursorConfig } from '@milkdown/kit/plugin/cursor'
1
+ import {
2
+ cursor as cursorPlugin,
3
+ dropCursorConfig,
4
+ } from '@milkdown/kit/plugin/cursor'
2
5
  import { $prose } from '@milkdown/kit/utils'
3
6
  import { createVirtualCursor } from 'prosemirror-virtual-cursor'
4
7
 
5
8
  import type { DefineFeature } from '../shared'
6
9
 
10
+ import { crepeFeatureConfig } from '../../core/slice'
11
+ import { CrepeFeature } from '../index'
12
+
7
13
  interface CursorConfig {
8
14
  color: string | false
9
15
  width: number
@@ -11,11 +17,9 @@ interface CursorConfig {
11
17
  }
12
18
  export type CursorFeatureConfig = Partial<CursorConfig>
13
19
 
14
- export const defineFeature: DefineFeature<CursorFeatureConfig> = (
15
- editor,
16
- config
17
- ) => {
20
+ export const cursor: DefineFeature<CursorFeatureConfig> = (editor, config) => {
18
21
  editor
22
+ .config(crepeFeatureConfig(CrepeFeature.Cursor))
19
23
  .config((ctx) => {
20
24
  ctx.update(dropCursorConfig.key, () => ({
21
25
  class: 'crepe-drop-cursor',
@@ -23,7 +27,7 @@ export const defineFeature: DefineFeature<CursorFeatureConfig> = (
23
27
  color: config?.color ?? false,
24
28
  }))
25
29
  })
26
- .use(cursor)
30
+ .use(cursorPlugin)
27
31
 
28
32
  if (config?.virtual === false) {
29
33
  return
@@ -7,24 +7,26 @@ import {
7
7
  inlineImageConfig,
8
8
  } from '@milkdown/kit/component/image-inline'
9
9
 
10
- import type { DefineFeature, Icon } from '../shared'
10
+ import type { DefineFeature } from '../shared'
11
11
 
12
+ import { crepeFeatureConfig } from '../../core/slice'
12
13
  import { captionIcon, imageIcon, confirmIcon } from '../../icons'
14
+ import { CrepeFeature } from '../index'
13
15
 
14
16
  interface ImageBlockConfig {
15
17
  onUpload: (file: File) => Promise<string>
16
18
  proxyDomURL: (url: string) => Promise<string> | string
17
19
 
18
- inlineImageIcon: Icon
19
- inlineConfirmButton: Icon
20
- inlineUploadButton: Icon
20
+ inlineImageIcon: string
21
+ inlineConfirmButton: string
22
+ inlineUploadButton: string
21
23
  inlineUploadPlaceholderText: string
22
24
  inlineOnUpload: (file: File) => Promise<string>
23
25
 
24
- blockImageIcon: Icon
25
- blockConfirmButton: Icon
26
- blockCaptionIcon: Icon
27
- blockUploadButton: Icon
26
+ blockImageIcon: string
27
+ blockConfirmButton: string
28
+ blockCaptionIcon: string
29
+ blockUploadButton: string
28
30
  blockCaptionPlaceholderText: string
29
31
  blockUploadPlaceholderText: string
30
32
  blockOnUpload: (file: File) => Promise<string>
@@ -32,26 +34,27 @@ interface ImageBlockConfig {
32
34
 
33
35
  export type ImageBlockFeatureConfig = Partial<ImageBlockConfig>
34
36
 
35
- export const defineFeature: DefineFeature<ImageBlockFeatureConfig> = (
37
+ export const imageBlock: DefineFeature<ImageBlockFeatureConfig> = (
36
38
  editor,
37
39
  config
38
40
  ) => {
39
41
  editor
42
+ .config(crepeFeatureConfig(CrepeFeature.ImageBlock))
40
43
  .config((ctx) => {
41
44
  ctx.update(inlineImageConfig.key, (value) => ({
42
- uploadButton: config?.inlineUploadButton ?? (() => 'Upload'),
43
- imageIcon: config?.inlineImageIcon ?? (() => imageIcon),
44
- confirmButton: config?.inlineConfirmButton ?? (() => confirmIcon),
45
+ uploadButton: config?.inlineUploadButton ?? 'Upload',
46
+ imageIcon: config?.inlineImageIcon ?? imageIcon,
47
+ confirmButton: config?.inlineConfirmButton ?? confirmIcon,
45
48
  uploadPlaceholderText:
46
49
  config?.inlineUploadPlaceholderText ?? 'or paste link',
47
50
  onUpload: config?.inlineOnUpload ?? config?.onUpload ?? value.onUpload,
48
51
  proxyDomURL: config?.proxyDomURL,
49
52
  }))
50
53
  ctx.update(imageBlockConfig.key, (value) => ({
51
- uploadButton: config?.blockUploadButton ?? (() => 'Upload file'),
52
- imageIcon: config?.blockImageIcon ?? (() => imageIcon),
53
- captionIcon: config?.blockCaptionIcon ?? (() => captionIcon),
54
- confirmButton: config?.blockConfirmButton ?? (() => 'Confirm'),
54
+ uploadButton: config?.blockUploadButton ?? 'Upload file',
55
+ imageIcon: config?.blockImageIcon ?? imageIcon,
56
+ captionIcon: config?.blockCaptionIcon ?? captionIcon,
57
+ confirmButton: config?.blockConfirmButton ?? 'Confirm',
55
58
  captionPlaceholderText:
56
59
  config?.blockCaptionPlaceholderText ?? 'Write Image Caption',
57
60
  uploadPlaceholderText:
@@ -1,5 +1,3 @@
1
- import type { Editor } from '@milkdown/kit/core'
2
-
3
1
  import type { BlockEditFeatureConfig } from './block-edit'
4
2
  import type { CodeMirrorFeatureConfig } from './code-mirror'
5
3
  import type { CursorFeatureConfig } from './cursor'
@@ -7,7 +5,7 @@ import type { ImageBlockFeatureConfig } from './image-block'
7
5
  import type { LatexFeatureConfig } from './latex'
8
6
  import type { LinkTooltipFeatureConfig } from './link-tooltip'
9
7
  import type { ListItemFeatureConfig } from './list-item'
10
- import type { PlaceHolderFeatureConfig } from './placeholder'
8
+ import type { PlaceholderFeatureConfig } from './placeholder'
11
9
  import type { TableFeatureConfig } from './table'
12
10
  import type { ToolbarFeatureConfig } from './toolbar'
13
11
 
@@ -52,7 +50,7 @@ export interface CrepeFeatureConfig {
52
50
  [CrepeFeature.LinkTooltip]?: LinkTooltipFeatureConfig
53
51
  [CrepeFeature.ImageBlock]?: ImageBlockFeatureConfig
54
52
  [CrepeFeature.BlockEdit]?: BlockEditFeatureConfig
55
- [CrepeFeature.Placeholder]?: PlaceHolderFeatureConfig
53
+ [CrepeFeature.Placeholder]?: PlaceholderFeatureConfig
56
54
  [CrepeFeature.Toolbar]?: ToolbarFeatureConfig
57
55
  [CrepeFeature.CodeMirror]?: CodeMirrorFeatureConfig
58
56
  [CrepeFeature.Table]?: TableFeatureConfig
@@ -71,52 +69,3 @@ export const defaultFeatures: Record<CrepeFeature, boolean> = {
71
69
  [CrepeFeature.Table]: true,
72
70
  [CrepeFeature.Latex]: true,
73
71
  }
74
-
75
- export async function loadFeature(
76
- feature: CrepeFeature,
77
- editor: Editor,
78
- config?: never
79
- ) {
80
- switch (feature) {
81
- case CrepeFeature.CodeMirror: {
82
- const { defineFeature } = await import('./code-mirror')
83
- return defineFeature(editor, config)
84
- }
85
- case CrepeFeature.ListItem: {
86
- const { defineFeature } = await import('./list-item')
87
- return defineFeature(editor, config)
88
- }
89
- case CrepeFeature.LinkTooltip: {
90
- const { defineFeature } = await import('./link-tooltip')
91
- return defineFeature(editor, config)
92
- }
93
- case CrepeFeature.ImageBlock: {
94
- const { defineFeature } = await import('./image-block')
95
- return defineFeature(editor, config)
96
- }
97
- case CrepeFeature.Cursor: {
98
- const { defineFeature } = await import('./cursor')
99
- return defineFeature(editor, config)
100
- }
101
- case CrepeFeature.BlockEdit: {
102
- const { defineFeature } = await import('./block-edit')
103
- return defineFeature(editor, config)
104
- }
105
- case CrepeFeature.Placeholder: {
106
- const { defineFeature } = await import('./placeholder')
107
- return defineFeature(editor, config)
108
- }
109
- case CrepeFeature.Toolbar: {
110
- const { defineFeature } = await import('./toolbar')
111
- return defineFeature(editor, config)
112
- }
113
- case CrepeFeature.Table: {
114
- const { defineFeature } = await import('./table')
115
- return defineFeature(editor, config)
116
- }
117
- case CrepeFeature.Latex: {
118
- const { defineFeature } = await import('./latex')
119
- return defineFeature(editor, config)
120
- }
121
- }
122
- }
@@ -3,10 +3,10 @@ import type { KatexOptions } from 'katex'
3
3
  import { codeBlockConfig } from '@milkdown/kit/component/code-block'
4
4
  import katex from 'katex'
5
5
 
6
- import type { DefineFeature, Icon } from '../shared'
6
+ import type { DefineFeature } from '../shared'
7
7
 
8
- import { CrepeFeature } from '../..'
9
- import { FeaturesCtx } from '../../core/slice'
8
+ import { crepeFeatureConfig, useCrepeFeatures } from '../../core/slice'
9
+ import { CrepeFeature } from '../../feature'
10
10
  import { confirmIcon } from '../../icons'
11
11
  import { blockLatexSchema } from './block-latex'
12
12
  import { mathInlineSchema } from './inline-latex'
@@ -17,18 +17,16 @@ import { remarkMathBlockPlugin, remarkMathPlugin } from './remark'
17
17
 
18
18
  export interface LatexConfig {
19
19
  katexOptions: KatexOptions
20
- inlineEditConfirm: Icon
20
+ inlineEditConfirm: string
21
21
  }
22
22
 
23
23
  export type LatexFeatureConfig = Partial<LatexConfig>
24
24
 
25
- export const defineFeature: DefineFeature<LatexFeatureConfig> = (
26
- editor,
27
- config
28
- ) => {
25
+ export const latex: DefineFeature<LatexFeatureConfig> = (editor, config) => {
29
26
  editor
27
+ .config(crepeFeatureConfig(CrepeFeature.Latex))
30
28
  .config((ctx) => {
31
- const flags = ctx.get(FeaturesCtx)
29
+ const flags = useCrepeFeatures(ctx).get()
32
30
  const isCodeMirrorEnabled = flags.includes(CrepeFeature.CodeMirror)
33
31
  if (!isCodeMirrorEnabled) {
34
32
  throw new Error('You need to enable CodeMirror to use LaTeX feature')
@@ -48,7 +46,7 @@ export const defineFeature: DefineFeature<LatexFeatureConfig> = (
48
46
  ctx.set(inlineLatexTooltip.key, {
49
47
  view: (view) => {
50
48
  return new LatexInlineTooltip(ctx, view, {
51
- inlineEditConfirm: config?.inlineEditConfirm ?? (() => confirmIcon),
49
+ inlineEditConfirm: config?.inlineEditConfirm ?? confirmIcon,
52
50
  ...config,
53
51
  })
54
52
  },
@@ -48,7 +48,7 @@ export const LatexTooltip = defineComponent<LatexTooltipProps>({
48
48
  <div class="container">
49
49
  {props.innerView && <div ref={innerViewRef} />}
50
50
  <button onPointerdown={onUpdate}>
51
- <Icon icon={props.config.inlineEditConfirm?.()} />
51
+ <Icon icon={props.config.inlineEditConfirm} />
52
52
  </button>
53
53
  </div>
54
54
  )
@@ -4,34 +4,37 @@ import {
4
4
  linkTooltipPlugin,
5
5
  } from '@milkdown/kit/component/link-tooltip'
6
6
 
7
- import type { DefineFeature, Icon } from '../shared'
7
+ import type { DefineFeature } from '../shared'
8
8
 
9
+ import { crepeFeatureConfig } from '../../core/slice'
9
10
  import { copyIcon, editIcon, removeIcon, confirmIcon } from '../../icons'
11
+ import { CrepeFeature } from '../index'
10
12
 
11
13
  interface LinkTooltipConfig {
12
- linkIcon: Icon
13
- editButton: Icon
14
- removeButton: Icon
15
- confirmButton: Icon
14
+ linkIcon: string
15
+ editButton: string
16
+ removeButton: string
17
+ confirmButton: string
16
18
  inputPlaceholder: string
17
19
  onCopyLink: (link: string) => void
18
20
  }
19
21
 
20
22
  export type LinkTooltipFeatureConfig = Partial<LinkTooltipConfig>
21
23
 
22
- export const defineFeature: DefineFeature<LinkTooltipFeatureConfig> = (
24
+ export const linkTooltip: DefineFeature<LinkTooltipFeatureConfig> = (
23
25
  editor,
24
26
  config
25
27
  ) => {
26
28
  editor
29
+ .config(crepeFeatureConfig(CrepeFeature.LinkTooltip))
27
30
  .config(configureLinkTooltip)
28
31
  .config((ctx) => {
29
32
  ctx.update(linkTooltipConfig.key, (prev) => ({
30
33
  ...prev,
31
- linkIcon: config?.linkIcon ?? (() => copyIcon),
32
- editButton: config?.editButton ?? (() => editIcon),
33
- removeButton: config?.removeButton ?? (() => removeIcon),
34
- confirmButton: config?.confirmButton ?? (() => confirmIcon),
34
+ linkIcon: config?.linkIcon ?? copyIcon,
35
+ editButton: config?.editButton ?? editIcon,
36
+ removeButton: config?.removeButton ?? removeIcon,
37
+ confirmButton: config?.confirmButton ?? confirmIcon,
35
38
  inputPlaceholder: config?.inputPlaceholder ?? 'Paste link...',
36
39
  onCopyLink: config?.onCopyLink ?? (() => {}),
37
40
  }))
@@ -5,18 +5,20 @@ import {
5
5
  listItemBlockConfig,
6
6
  } from '@milkdown/kit/component/list-item-block'
7
7
 
8
- import type { DefineFeature, Icon } from '../shared'
8
+ import type { DefineFeature } from '../shared'
9
9
 
10
+ import { crepeFeatureConfig } from '../../core/slice'
10
11
  import {
11
12
  bulletIcon,
12
13
  checkBoxCheckedIcon,
13
14
  checkBoxUncheckedIcon,
14
15
  } from '../../icons'
16
+ import { CrepeFeature } from '../index'
15
17
 
16
18
  export interface ListItemConfig {
17
- bulletIcon: Icon
18
- checkBoxCheckedIcon: Icon
19
- checkBoxUncheckedIcon: Icon
19
+ bulletIcon: string
20
+ checkBoxCheckedIcon: string
21
+ checkBoxUncheckedIcon: string
20
22
  }
21
23
 
22
24
  export type ListItemFeatureConfig = Partial<ListItemConfig>
@@ -25,23 +27,24 @@ function configureListItem(ctx: Ctx, config?: ListItemFeatureConfig) {
25
27
  ctx.set(listItemBlockConfig.key, {
26
28
  renderLabel: ({ label, listType, checked }) => {
27
29
  if (checked == null) {
28
- if (listType === 'bullet') return config?.bulletIcon?.() ?? bulletIcon
30
+ if (listType === 'bullet') return config?.bulletIcon ?? bulletIcon
29
31
 
30
32
  return label
31
33
  }
32
34
 
33
- if (checked) return config?.checkBoxCheckedIcon?.() ?? checkBoxCheckedIcon
35
+ if (checked) return config?.checkBoxCheckedIcon ?? checkBoxCheckedIcon
34
36
 
35
- return config?.checkBoxUncheckedIcon?.() ?? checkBoxUncheckedIcon
37
+ return config?.checkBoxUncheckedIcon ?? checkBoxUncheckedIcon
36
38
  },
37
39
  })
38
40
  }
39
41
 
40
- export const defineFeature: DefineFeature<ListItemFeatureConfig> = (
42
+ export const listItem: DefineFeature<ListItemFeatureConfig> = (
41
43
  editor,
42
44
  config
43
45
  ) => {
44
46
  editor
47
+ .config(crepeFeatureConfig(CrepeFeature.ListItem))
45
48
  .config((ctx) => configureListItem(ctx, config))
46
49
  .use(listItemBlockComponent)
47
50
  }
@@ -0,0 +1,52 @@
1
+ import type { Editor } from '@milkdown/kit/core'
2
+
3
+ import { blockEdit } from './block-edit'
4
+ import { codeMirror } from './code-mirror'
5
+ import { cursor } from './cursor'
6
+ import { imageBlock } from './image-block'
7
+ import { CrepeFeature } from './index'
8
+ import { latex } from './latex'
9
+ import { linkTooltip } from './link-tooltip'
10
+ import { listItem } from './list-item'
11
+ import { placeholder } from './placeholder'
12
+ import { table } from './table'
13
+ import { toolbar } from './toolbar'
14
+
15
+ export function loadFeature(
16
+ feature: CrepeFeature,
17
+ editor: Editor,
18
+ config?: never
19
+ ) {
20
+ switch (feature) {
21
+ case CrepeFeature.CodeMirror: {
22
+ return codeMirror(editor, config)
23
+ }
24
+ case CrepeFeature.ListItem: {
25
+ return listItem(editor, config)
26
+ }
27
+ case CrepeFeature.LinkTooltip: {
28
+ return linkTooltip(editor, config)
29
+ }
30
+ case CrepeFeature.ImageBlock: {
31
+ return imageBlock(editor, config)
32
+ }
33
+ case CrepeFeature.Cursor: {
34
+ return cursor(editor, config)
35
+ }
36
+ case CrepeFeature.BlockEdit: {
37
+ return blockEdit(editor, config)
38
+ }
39
+ case CrepeFeature.Placeholder: {
40
+ return placeholder(editor, config)
41
+ }
42
+ case CrepeFeature.Toolbar: {
43
+ return toolbar(editor, config)
44
+ }
45
+ case CrepeFeature.Table: {
46
+ return table(editor, config)
47
+ }
48
+ case CrepeFeature.Latex: {
49
+ return latex(editor, config)
50
+ }
51
+ }
52
+ }