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