@milkdown/crepe 7.7.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-Dac851tb.js → index-B7gqgc1H.js} +494 -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-BuSAwj4j.js → index-C2CAbC2F.js} +8 -1
- package/lib/cjs/index-C2CAbC2F.js.map +1 -0
- package/lib/cjs/{index-ooYXC5xk.js → index-CnyNb_OH.js} +45 -45
- package/lib/cjs/index-CnyNb_OH.js.map +1 -0
- package/lib/cjs/{index-7pgPMFV4.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-s33c_M2f.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-CxJ9fxJm.js → index-Bvz1Yyiz.js} +8 -1
- package/lib/esm/index-Bvz1Yyiz.js.map +1 -0
- package/lib/esm/index-C1aVAv1l.js +124 -0
- package/lib/esm/index-C1aVAv1l.js.map +1 -0
- package/lib/esm/{index-uHWmZXqe.js → index-CM4urRY9.js} +480 -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-CLpluqvF.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 +7 -1
- package/lib/theme/common/block-edit.css +23 -23
- package/lib/theme/common/code-mirror.css +43 -44
- package/lib/theme/common/cursor.css +5 -0
- 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 +1 -0
- 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 +5 -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 +55 -17
- 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 +10 -0
- 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 +7 -1
- package/src/theme/common/block-edit.css +2 -2
- package/src/theme/common/code-mirror.css +5 -6
- package/src/theme/common/cursor.css +5 -0
- 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-7pgPMFV4.js.map +0 -1
- package/lib/cjs/index-Bjy2DUKs.js +0 -272
- package/lib/cjs/index-Bjy2DUKs.js.map +0 -1
- package/lib/cjs/index-BuSAwj4j.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-DQll67YS.js +0 -65
- package/lib/cjs/index-DQll67YS.js.map +0 -1
- package/lib/cjs/index-Dac851tb.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/cjs/index-ooYXC5xk.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-CBrOT1fW.js +0 -37
- package/lib/esm/index-CBrOT1fW.js.map +0 -1
- package/lib/esm/index-CLpluqvF.js.map +0 -1
- package/lib/esm/index-CsEtSFhk.js +0 -270
- package/lib/esm/index-CsEtSFhk.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-CxJ9fxJm.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-s33c_M2f.js.map +0 -1
- package/lib/esm/index-uHWmZXqe.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,236 +0,0 @@
|
|
|
1
|
-
import type { Component } from 'atomico'
|
|
2
|
-
import { c, html, useEffect, useUpdate } from 'atomico'
|
|
3
|
-
import type { Ctx } from '@milkdown/kit/ctx'
|
|
4
|
-
import { commandsCtx, editorViewCtx } from '@milkdown/kit/core'
|
|
5
|
-
import {
|
|
6
|
-
emphasisSchema,
|
|
7
|
-
inlineCodeSchema,
|
|
8
|
-
linkSchema,
|
|
9
|
-
strongSchema,
|
|
10
|
-
toggleEmphasisCommand,
|
|
11
|
-
toggleInlineCodeCommand,
|
|
12
|
-
toggleStrongCommand,
|
|
13
|
-
} from '@milkdown/kit/preset/commonmark'
|
|
14
|
-
import type { MarkType, Node, NodeType } from '@milkdown/kit/prose/model'
|
|
15
|
-
import type { Selection } from '@milkdown/kit/prose/state'
|
|
16
|
-
import clsx from 'clsx'
|
|
17
|
-
import { linkTooltipAPI } from '@milkdown/kit/component/link-tooltip'
|
|
18
|
-
import {
|
|
19
|
-
strikethroughSchema,
|
|
20
|
-
toggleStrikethroughCommand,
|
|
21
|
-
} from '@milkdown/kit/preset/gfm'
|
|
22
|
-
import {
|
|
23
|
-
boldIcon,
|
|
24
|
-
codeIcon,
|
|
25
|
-
italicIcon,
|
|
26
|
-
linkIcon,
|
|
27
|
-
strikethroughIcon,
|
|
28
|
-
functionsIcon,
|
|
29
|
-
} from '../../icons'
|
|
30
|
-
import type { ToolbarFeatureConfig } from './index'
|
|
31
|
-
import { NodeSelection, TextSelection } from '@milkdown/kit/prose/state'
|
|
32
|
-
import { mathInlineSchema } from '../latex/inline-latex'
|
|
33
|
-
import { FeaturesCtx } from '../../core/slice'
|
|
34
|
-
import { CrepeFeature } from '../..'
|
|
35
|
-
|
|
36
|
-
export interface ToolbarProps {
|
|
37
|
-
ctx: Ctx
|
|
38
|
-
hide: () => void
|
|
39
|
-
show: boolean
|
|
40
|
-
selection: Selection
|
|
41
|
-
config?: ToolbarFeatureConfig
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export const toolbarComponent: Component<ToolbarProps> = ({
|
|
45
|
-
ctx,
|
|
46
|
-
hide,
|
|
47
|
-
show,
|
|
48
|
-
config,
|
|
49
|
-
selection,
|
|
50
|
-
}) => {
|
|
51
|
-
const update = useUpdate()
|
|
52
|
-
useEffect(() => {
|
|
53
|
-
update()
|
|
54
|
-
}, [show])
|
|
55
|
-
|
|
56
|
-
const onClick = (fn: (ctx: Ctx) => void) => (e: MouseEvent) => {
|
|
57
|
-
e.preventDefault()
|
|
58
|
-
ctx && fn(ctx)
|
|
59
|
-
update()
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
const isActive = (mark: MarkType) => {
|
|
63
|
-
if (!ctx || !selection) return false
|
|
64
|
-
const view = ctx.get(editorViewCtx)
|
|
65
|
-
const {
|
|
66
|
-
state: { doc },
|
|
67
|
-
} = view
|
|
68
|
-
return doc.rangeHasMark(selection.from, selection.to, mark)
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
const containsNode = (node: NodeType) => {
|
|
72
|
-
if (!ctx || !selection) return false
|
|
73
|
-
const view = ctx.get(editorViewCtx)
|
|
74
|
-
const {
|
|
75
|
-
state: { doc },
|
|
76
|
-
} = view
|
|
77
|
-
if (selection instanceof NodeSelection) {
|
|
78
|
-
return selection.node.type === node
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
const { from, to } = selection
|
|
82
|
-
|
|
83
|
-
let hasNode = false
|
|
84
|
-
doc.nodesBetween(from, to, (n) => {
|
|
85
|
-
if (n.type === node) {
|
|
86
|
-
hasNode = true
|
|
87
|
-
return false
|
|
88
|
-
}
|
|
89
|
-
return true
|
|
90
|
-
})
|
|
91
|
-
|
|
92
|
-
return hasNode
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
const flags = ctx?.get(FeaturesCtx)
|
|
96
|
-
const isLatexEnabled = flags?.includes(CrepeFeature.Latex)
|
|
97
|
-
|
|
98
|
-
const toggleLatex = (ctx: Ctx) => {
|
|
99
|
-
const hasLatex = containsNode(mathInlineSchema.type(ctx))
|
|
100
|
-
const view = ctx.get(editorViewCtx)
|
|
101
|
-
const { selection, doc, tr } = view.state
|
|
102
|
-
if (!hasLatex) {
|
|
103
|
-
const text = doc.textBetween(selection.from, selection.to)
|
|
104
|
-
let _tr = tr.replaceSelectionWith(
|
|
105
|
-
mathInlineSchema.type(ctx).create({
|
|
106
|
-
value: text,
|
|
107
|
-
})
|
|
108
|
-
)
|
|
109
|
-
view.dispatch(
|
|
110
|
-
_tr.setSelection(NodeSelection.create(_tr.doc, selection.from))
|
|
111
|
-
)
|
|
112
|
-
return
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
const { from, to } = selection
|
|
116
|
-
let pos = -1
|
|
117
|
-
let node: Node | null = null
|
|
118
|
-
doc.nodesBetween(from, to, (n, p) => {
|
|
119
|
-
if (node) return false
|
|
120
|
-
if (n.type === mathInlineSchema.type(ctx)) {
|
|
121
|
-
pos = p
|
|
122
|
-
node = n
|
|
123
|
-
return false
|
|
124
|
-
}
|
|
125
|
-
return true
|
|
126
|
-
})
|
|
127
|
-
if (!node || pos < 0) return
|
|
128
|
-
|
|
129
|
-
let _tr = tr.delete(pos, pos + 1)
|
|
130
|
-
const content = (node as Node).attrs.value
|
|
131
|
-
_tr = _tr.insertText(content, pos)
|
|
132
|
-
view.dispatch(
|
|
133
|
-
_tr.setSelection(
|
|
134
|
-
TextSelection.create(_tr.doc, from, to + content.length - 1)
|
|
135
|
-
)
|
|
136
|
-
)
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
return html`<host>
|
|
140
|
-
<button
|
|
141
|
-
type="button"
|
|
142
|
-
class=${clsx(
|
|
143
|
-
'toolbar-item',
|
|
144
|
-
ctx && isActive(strongSchema.type(ctx)) && 'active'
|
|
145
|
-
)}
|
|
146
|
-
onmousedown=${onClick((ctx) => {
|
|
147
|
-
const commands = ctx.get(commandsCtx)
|
|
148
|
-
commands.call(toggleStrongCommand.key)
|
|
149
|
-
})}
|
|
150
|
-
>
|
|
151
|
-
${config?.boldIcon?.() ?? boldIcon}
|
|
152
|
-
</button>
|
|
153
|
-
<button
|
|
154
|
-
type="button"
|
|
155
|
-
class=${clsx(
|
|
156
|
-
'toolbar-item',
|
|
157
|
-
ctx && isActive(emphasisSchema.type(ctx)) && 'active'
|
|
158
|
-
)}
|
|
159
|
-
onmousedown=${onClick((ctx) => {
|
|
160
|
-
const commands = ctx.get(commandsCtx)
|
|
161
|
-
commands.call(toggleEmphasisCommand.key)
|
|
162
|
-
})}
|
|
163
|
-
>
|
|
164
|
-
${config?.italicIcon?.() ?? italicIcon}
|
|
165
|
-
</button>
|
|
166
|
-
<button
|
|
167
|
-
type="button"
|
|
168
|
-
class=${clsx(
|
|
169
|
-
'toolbar-item',
|
|
170
|
-
ctx && isActive(strikethroughSchema.type(ctx)) && 'active'
|
|
171
|
-
)}
|
|
172
|
-
onmousedown=${onClick((ctx) => {
|
|
173
|
-
const commands = ctx.get(commandsCtx)
|
|
174
|
-
commands.call(toggleStrikethroughCommand.key)
|
|
175
|
-
})}
|
|
176
|
-
>
|
|
177
|
-
${config?.strikethroughIcon?.() ?? strikethroughIcon}
|
|
178
|
-
</button>
|
|
179
|
-
<div class="divider"></div>
|
|
180
|
-
<button
|
|
181
|
-
type="button"
|
|
182
|
-
class=${clsx(
|
|
183
|
-
'toolbar-item',
|
|
184
|
-
ctx && isActive(inlineCodeSchema.type(ctx)) && 'active'
|
|
185
|
-
)}
|
|
186
|
-
onmousedown=${onClick((ctx) => {
|
|
187
|
-
const commands = ctx.get(commandsCtx)
|
|
188
|
-
commands.call(toggleInlineCodeCommand.key)
|
|
189
|
-
})}
|
|
190
|
-
>
|
|
191
|
-
${config?.codeIcon?.() ?? codeIcon}
|
|
192
|
-
</button>
|
|
193
|
-
${isLatexEnabled &&
|
|
194
|
-
html`<button
|
|
195
|
-
type="button"
|
|
196
|
-
class=${clsx(
|
|
197
|
-
'toolbar-item',
|
|
198
|
-
ctx && containsNode(mathInlineSchema.type(ctx)) && 'active'
|
|
199
|
-
)}
|
|
200
|
-
onmousedown=${onClick(toggleLatex)}
|
|
201
|
-
>
|
|
202
|
-
${config?.latexIcon?.() ?? functionsIcon}
|
|
203
|
-
</button>`}
|
|
204
|
-
<button
|
|
205
|
-
type="button"
|
|
206
|
-
class=${clsx(
|
|
207
|
-
'toolbar-item',
|
|
208
|
-
ctx && isActive(linkSchema.type(ctx)) && 'active'
|
|
209
|
-
)}
|
|
210
|
-
onmousedown=${onClick((ctx) => {
|
|
211
|
-
const view = ctx.get(editorViewCtx)
|
|
212
|
-
const { selection } = view.state
|
|
213
|
-
|
|
214
|
-
if (isActive(linkSchema.type(ctx))) {
|
|
215
|
-
ctx.get(linkTooltipAPI.key).removeLink(selection.from, selection.to)
|
|
216
|
-
return
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
ctx.get(linkTooltipAPI.key).addLink(selection.from, selection.to)
|
|
220
|
-
hide?.()
|
|
221
|
-
})}
|
|
222
|
-
>
|
|
223
|
-
${config?.linkIcon?.() ?? linkIcon}
|
|
224
|
-
</button>
|
|
225
|
-
</host>`
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
toolbarComponent.props = {
|
|
229
|
-
ctx: Object,
|
|
230
|
-
hide: Function,
|
|
231
|
-
show: Boolean,
|
|
232
|
-
config: Object,
|
|
233
|
-
selection: Object,
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
export const ToolbarElement = c(toolbarComponent)
|