@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.
- package/lib/cjs/builder.js +107 -0
- package/lib/cjs/builder.js.map +1 -0
- package/lib/cjs/{index-CtTpZYVe.js → feature/block-edit/index.js} +165 -61
- package/lib/cjs/feature/block-edit/index.js.map +1 -0
- package/lib/cjs/feature/code-mirror/index.js +161 -0
- package/lib/cjs/feature/code-mirror/index.js.map +1 -0
- package/lib/cjs/feature/cursor/index.js +57 -0
- package/lib/cjs/feature/cursor/index.js.map +1 -0
- package/lib/cjs/feature/image-block/index.js +123 -0
- package/lib/cjs/feature/image-block/index.js.map +1 -0
- package/lib/cjs/{index-2icTTGim.js → feature/latex/index.js} +111 -24
- package/lib/cjs/feature/latex/index.js.map +1 -0
- package/lib/cjs/feature/link-tooltip/index.js +124 -0
- package/lib/cjs/feature/link-tooltip/index.js.map +1 -0
- package/lib/cjs/{index-Dw6lXgs6.js → feature/list-item/index.js} +39 -8
- package/lib/cjs/feature/list-item/index.js.map +1 -0
- package/lib/cjs/{index-B91KhPew.js → feature/placeholder/index.js} +46 -6
- package/lib/cjs/feature/placeholder/index.js.map +1 -0
- package/lib/cjs/{index-DEs_IHHy.js → feature/table/index.js} +78 -16
- package/lib/cjs/feature/table/index.js.map +1 -0
- package/lib/cjs/{index-k3lGvKiX.js → feature/toolbar/index.js} +133 -31
- package/lib/cjs/feature/toolbar/index.js.map +1 -0
- package/lib/cjs/index.js +2461 -17
- package/lib/cjs/index.js.map +1 -1
- package/lib/esm/builder.js +105 -0
- package/lib/esm/builder.js.map +1 -0
- package/lib/esm/{index-BEe1TpeS.js → feature/block-edit/index.js} +161 -57
- package/lib/esm/feature/block-edit/index.js.map +1 -0
- package/lib/esm/feature/code-mirror/index.js +159 -0
- package/lib/esm/feature/code-mirror/index.js.map +1 -0
- package/lib/esm/feature/cursor/index.js +55 -0
- package/lib/esm/feature/cursor/index.js.map +1 -0
- package/lib/esm/feature/image-block/index.js +121 -0
- package/lib/esm/feature/image-block/index.js.map +1 -0
- package/lib/esm/{index-ZGfGszIQ.js → feature/latex/index.js} +107 -20
- package/lib/esm/feature/latex/index.js.map +1 -0
- package/lib/esm/feature/link-tooltip/index.js +122 -0
- package/lib/esm/feature/link-tooltip/index.js.map +1 -0
- package/lib/esm/{index-E8UgFLeN.js → feature/list-item/index.js} +39 -8
- package/lib/esm/feature/list-item/index.js.map +1 -0
- package/lib/esm/{index-BCvtgOeI.js → feature/placeholder/index.js} +45 -5
- package/lib/esm/feature/placeholder/index.js.map +1 -0
- package/lib/esm/{index-CwMVnVeI.js → feature/table/index.js} +78 -16
- package/lib/esm/feature/table/index.js.map +1 -0
- package/lib/esm/{index-CTBg0aec.js → feature/toolbar/index.js} +128 -26
- package/lib/esm/feature/toolbar/index.js.map +1 -0
- package/lib/esm/index.js +2457 -11
- package/lib/esm/index.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/types/builder.d.ts +2 -0
- package/lib/types/builder.d.ts.map +1 -0
- package/lib/types/core/builder.d.ts +23 -0
- package/lib/types/core/builder.d.ts.map +1 -0
- package/lib/types/core/crepe.d.ts +4 -15
- package/lib/types/core/crepe.d.ts.map +1 -1
- package/lib/types/core/index.d.ts +2 -1
- package/lib/types/core/index.d.ts.map +1 -1
- package/lib/types/core/slice.d.ts +6 -4
- package/lib/types/core/slice.d.ts.map +1 -1
- package/lib/types/default-config/index.d.ts +3 -0
- package/lib/types/default-config/index.d.ts.map +1 -0
- package/lib/types/feature/block-edit/handle/component.d.ts +2 -3
- package/lib/types/feature/block-edit/handle/component.d.ts.map +1 -1
- package/lib/types/feature/block-edit/index.d.ts +20 -20
- package/lib/types/feature/block-edit/index.d.ts.map +1 -1
- package/lib/types/feature/code-mirror/index.d.ts +7 -7
- package/lib/types/feature/code-mirror/index.d.ts.map +1 -1
- package/lib/types/feature/cursor/index.d.ts +1 -1
- package/lib/types/feature/cursor/index.d.ts.map +1 -1
- package/lib/types/feature/image-block/index.d.ts +9 -9
- package/lib/types/feature/image-block/index.d.ts.map +1 -1
- package/lib/types/feature/index.d.ts +2 -4
- package/lib/types/feature/index.d.ts.map +1 -1
- package/lib/types/feature/latex/index.d.ts +3 -3
- package/lib/types/feature/latex/index.d.ts.map +1 -1
- package/lib/types/feature/link-tooltip/index.d.ts +6 -6
- package/lib/types/feature/link-tooltip/index.d.ts.map +1 -1
- package/lib/types/feature/list-item/index.d.ts +5 -5
- package/lib/types/feature/list-item/index.d.ts.map +1 -1
- package/lib/types/feature/loader.d.ts +4 -0
- package/lib/types/feature/loader.d.ts.map +1 -0
- package/lib/types/feature/placeholder/index.d.ts +2 -2
- 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 +11 -11
- package/lib/types/feature/table/index.d.ts.map +1 -1
- package/lib/types/feature/toolbar/index.d.ts +8 -8
- package/lib/types/feature/toolbar/index.d.ts.map +1 -1
- package/lib/types/icons/index.d.ts +1 -0
- package/lib/types/icons/index.d.ts.map +1 -1
- package/lib/types/index.d.ts +1 -1
- package/lib/types/index.d.ts.map +1 -1
- package/lib/types/utils/index.d.ts +0 -1
- package/lib/types/utils/index.d.ts.map +1 -1
- package/package.json +60 -3
- package/src/builder.ts +1 -0
- package/src/core/builder.ts +143 -0
- package/src/core/crepe.ts +14 -130
- package/src/core/index.ts +2 -1
- package/src/core/slice.ts +37 -8
- package/src/default-config/index.ts +25 -0
- package/src/feature/block-edit/handle/component.tsx +6 -8
- package/src/feature/block-edit/handle/index.ts +2 -2
- package/src/feature/block-edit/index.ts +23 -20
- package/src/feature/block-edit/menu/config.ts +19 -19
- package/src/feature/code-mirror/index.ts +32 -28
- package/src/feature/cursor/index.ts +10 -6
- package/src/feature/image-block/index.ts +19 -16
- package/src/feature/index.ts +2 -53
- package/src/feature/latex/index.ts +8 -10
- package/src/feature/latex/inline-tooltip/component.tsx +1 -1
- package/src/feature/link-tooltip/index.ts +13 -10
- package/src/feature/list-item/index.ts +11 -8
- package/src/feature/loader.ts +52 -0
- package/src/feature/placeholder/index.ts +5 -2
- package/src/feature/shared.ts +1 -3
- package/src/feature/table/index.ts +23 -23
- package/src/feature/toolbar/component.tsx +9 -9
- package/src/feature/toolbar/index.ts +14 -11
- package/src/icons/index.ts +1 -0
- package/src/index.ts +1 -1
- package/src/utils/index.ts +0 -8
- package/lib/cjs/confirm-CNveM9QH.js +0 -26
- package/lib/cjs/confirm-CNveM9QH.js.map +0 -1
- package/lib/cjs/edit-BUtBJHpV.js +0 -24
- package/lib/cjs/edit-BUtBJHpV.js.map +0 -1
- package/lib/cjs/functions-BAY51plB.js +0 -39
- package/lib/cjs/functions-BAY51plB.js.map +0 -1
- package/lib/cjs/image-BXLkOVnO.js +0 -24
- package/lib/cjs/image-BXLkOVnO.js.map +0 -1
- package/lib/cjs/index-2icTTGim.js.map +0 -1
- package/lib/cjs/index-B91KhPew.js.map +0 -1
- package/lib/cjs/index-BsrJn8Jp.js +0 -41
- package/lib/cjs/index-BsrJn8Jp.js.map +0 -1
- package/lib/cjs/index-C2CAbC2F.js +0 -26
- package/lib/cjs/index-C2CAbC2F.js.map +0 -1
- package/lib/cjs/index-CtTpZYVe.js.map +0 -1
- package/lib/cjs/index-DEs_IHHy.js.map +0 -1
- package/lib/cjs/index-DLIudQKW.js +0 -126
- package/lib/cjs/index-DLIudQKW.js.map +0 -1
- package/lib/cjs/index-Dw6lXgs6.js.map +0 -1
- package/lib/cjs/index-k3lGvKiX.js.map +0 -1
- package/lib/cjs/index-urTgNBfI.js +0 -202
- package/lib/cjs/index-urTgNBfI.js.map +0 -1
- package/lib/cjs/index-xbwf60wt.js +0 -15
- package/lib/cjs/index-xbwf60wt.js.map +0 -1
- package/lib/cjs/index-xbxqAqH2.js +0 -52
- package/lib/cjs/index-xbxqAqH2.js.map +0 -1
- package/lib/cjs/inline-latex-D0G71cGk.js +0 -54
- package/lib/cjs/inline-latex-D0G71cGk.js.map +0 -1
- package/lib/cjs/plus-XLomtlXf.js +0 -24
- package/lib/cjs/plus-XLomtlXf.js.map +0 -1
- package/lib/cjs/remove-Ba-ypwBf.js +0 -17
- package/lib/cjs/remove-Ba-ypwBf.js.map +0 -1
- package/lib/esm/confirm-DtE-HkVd.js +0 -24
- package/lib/esm/confirm-DtE-HkVd.js.map +0 -1
- package/lib/esm/edit-D--t_JAb.js +0 -22
- package/lib/esm/edit-D--t_JAb.js.map +0 -1
- package/lib/esm/functions-DlJPkGmE.js +0 -36
- package/lib/esm/functions-DlJPkGmE.js.map +0 -1
- package/lib/esm/image-DoB1o1sl.js +0 -22
- package/lib/esm/image-DoB1o1sl.js.map +0 -1
- package/lib/esm/index-BCvtgOeI.js.map +0 -1
- package/lib/esm/index-BEe1TpeS.js.map +0 -1
- package/lib/esm/index-BPG8iO8t.js +0 -12
- package/lib/esm/index-BPG8iO8t.js.map +0 -1
- package/lib/esm/index-BUBXHhHG.js +0 -39
- package/lib/esm/index-BUBXHhHG.js.map +0 -1
- package/lib/esm/index-Bvz1Yyiz.js +0 -24
- package/lib/esm/index-Bvz1Yyiz.js.map +0 -1
- package/lib/esm/index-C1aVAv1l.js +0 -124
- package/lib/esm/index-C1aVAv1l.js.map +0 -1
- package/lib/esm/index-CTBg0aec.js.map +0 -1
- package/lib/esm/index-ChR5Qhyf.js +0 -50
- package/lib/esm/index-ChR5Qhyf.js.map +0 -1
- package/lib/esm/index-CshFzSt2.js +0 -197
- package/lib/esm/index-CshFzSt2.js.map +0 -1
- package/lib/esm/index-CwMVnVeI.js.map +0 -1
- package/lib/esm/index-E8UgFLeN.js.map +0 -1
- package/lib/esm/index-ZGfGszIQ.js.map +0 -1
- package/lib/esm/inline-latex-C9IGAXXQ.js +0 -51
- package/lib/esm/inline-latex-C9IGAXXQ.js.map +0 -1
- package/lib/esm/plus-lrX0Q75O.js +0 -22
- package/lib/esm/plus-lrX0Q75O.js.map +0 -1
- package/lib/esm/remove-D3g0Cd6_.js +0 -15
- package/lib/esm/remove-D3g0Cd6_.js.map +0 -1
|
@@ -4,7 +4,47 @@ var prose = require('@milkdown/kit/prose');
|
|
|
4
4
|
var state = require('@milkdown/kit/prose/state');
|
|
5
5
|
var view = require('@milkdown/kit/prose/view');
|
|
6
6
|
var utils = require('@milkdown/kit/utils');
|
|
7
|
-
var
|
|
7
|
+
var ctx = require('@milkdown/kit/ctx');
|
|
8
|
+
|
|
9
|
+
ctx.createSlice([], "FeaturesCtx");
|
|
10
|
+
ctx.createSlice({}, "CrepeCtx");
|
|
11
|
+
function useCrepeFeatures(ctx) {
|
|
12
|
+
return ctx.use("FeaturesCtx");
|
|
13
|
+
}
|
|
14
|
+
function crepeFeatureConfig(feature) {
|
|
15
|
+
return (ctx) => {
|
|
16
|
+
useCrepeFeatures(ctx).update((features) => {
|
|
17
|
+
if (features.includes(feature)) {
|
|
18
|
+
return features;
|
|
19
|
+
}
|
|
20
|
+
return [...features, feature];
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function isInCodeBlock(selection) {
|
|
26
|
+
const type = selection.$from.parent.type;
|
|
27
|
+
return type.name === "code_block";
|
|
28
|
+
}
|
|
29
|
+
function isInList(selection) {
|
|
30
|
+
var _a;
|
|
31
|
+
const type = (_a = selection.$from.node(selection.$from.depth - 1)) == null ? void 0 : _a.type;
|
|
32
|
+
return (type == null ? void 0 : type.name) === "list_item";
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
var CrepeFeature = /* @__PURE__ */ ((CrepeFeature2) => {
|
|
36
|
+
CrepeFeature2["CodeMirror"] = "code-mirror";
|
|
37
|
+
CrepeFeature2["ListItem"] = "list-item";
|
|
38
|
+
CrepeFeature2["LinkTooltip"] = "link-tooltip";
|
|
39
|
+
CrepeFeature2["Cursor"] = "cursor";
|
|
40
|
+
CrepeFeature2["ImageBlock"] = "image-block";
|
|
41
|
+
CrepeFeature2["BlockEdit"] = "block-edit";
|
|
42
|
+
CrepeFeature2["Toolbar"] = "toolbar";
|
|
43
|
+
CrepeFeature2["Placeholder"] = "placeholder";
|
|
44
|
+
CrepeFeature2["Table"] = "table";
|
|
45
|
+
CrepeFeature2["Latex"] = "latex";
|
|
46
|
+
return CrepeFeature2;
|
|
47
|
+
})(CrepeFeature || {});
|
|
8
48
|
|
|
9
49
|
function isDocEmpty(doc) {
|
|
10
50
|
var _a;
|
|
@@ -39,7 +79,7 @@ const placeholderPlugin = utils.$prose((ctx) => {
|
|
|
39
79
|
var _a;
|
|
40
80
|
const config = ctx.get(placeholderConfig.key);
|
|
41
81
|
if (config.mode === "doc" && !isDocEmpty(state.doc)) return null;
|
|
42
|
-
if (
|
|
82
|
+
if (isInCodeBlock(state.selection) || isInList(state.selection))
|
|
43
83
|
return null;
|
|
44
84
|
const placeholderText = (_a = config.text) != null ? _a : "Please enter...";
|
|
45
85
|
const deco = createPlaceholderDecoration(state, placeholderText);
|
|
@@ -49,8 +89,8 @@ const placeholderPlugin = utils.$prose((ctx) => {
|
|
|
49
89
|
}
|
|
50
90
|
});
|
|
51
91
|
});
|
|
52
|
-
const
|
|
53
|
-
editor.config((ctx) => {
|
|
92
|
+
const placeholder = (editor, config) => {
|
|
93
|
+
editor.config(crepeFeatureConfig(CrepeFeature.Placeholder)).config((ctx) => {
|
|
54
94
|
if (config) {
|
|
55
95
|
ctx.update(placeholderConfig.key, (prev) => {
|
|
56
96
|
return {
|
|
@@ -62,7 +102,7 @@ const defineFeature = (editor, config) => {
|
|
|
62
102
|
}).use(placeholderPlugin).use(placeholderConfig);
|
|
63
103
|
};
|
|
64
104
|
|
|
65
|
-
exports.
|
|
105
|
+
exports.placeholder = placeholder;
|
|
66
106
|
exports.placeholderConfig = placeholderConfig;
|
|
67
107
|
exports.placeholderPlugin = placeholderPlugin;
|
|
68
|
-
//# sourceMappingURL=index
|
|
108
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../../src/core/slice.ts","../../../../src/utils/index.ts","../../../../src/feature/index.ts","../../../../src/feature/placeholder/index.ts"],"sourcesContent":["import { createSlice, type Ctx } from '@milkdown/kit/ctx'\n\nimport type { CrepeFeature } from '../feature'\nimport type { CrepeBuilder } from './builder'\n\n/// @internal\n/// The feature flags context.\n/// ⚠️ Most of the time, you should use `useCrepeFeatures` to get the features.\nexport const FeaturesCtx = createSlice([] as CrepeFeature[], 'FeaturesCtx')\n\n/// @internal\n/// The crepe editor context.\n/// ⚠️ Most of the time, you should use `useCrepe` to get the crepe editor instance.\nexport const CrepeCtx = createSlice({} as CrepeBuilder, 'CrepeCtx')\n\n/// The crepe editor context.\n/// You can use this context to access the crepe editor instance within Milkdown plugins.\n/// ```ts\n/// import { crepeCtx } from '@milkdown/crepe'\n/// const plugin = (ctx: Ctx) => {\n/// return () => {\n/// const crepe = useCrepe(ctx)\n/// crepe.setReadonly(true)\n/// }\n/// }\n/// ```\nexport function useCrepe(ctx: Ctx) {\n // We should use string slice here to avoid the slice to be bundled in multiple entries\n return ctx.get<CrepeBuilder, 'CrepeCtx'>('CrepeCtx')\n}\n\n/// Check the enabled FeatureFlags\n/// ```ts\n/// import { useCrepeFeatures } from '@milkdown/crepe'\n/// const plugin = (ctx: Ctx) => {\n/// const features = useCrepeFeatures(ctx)\n/// if (features.get().includes(CrepeFeature.CodeMirror)) {\n/// // Do something with CodeMirror\n/// }\n/// }\nexport function useCrepeFeatures(ctx: Ctx) {\n // We should use string slice here to avoid the slice to be bundled in multiple entries\n return ctx.use<CrepeFeature[], 'FeaturesCtx'>('FeaturesCtx')\n}\n\n/// @internal\nexport function crepeFeatureConfig(feature: CrepeFeature) {\n return (ctx: Ctx) => {\n useCrepeFeatures(ctx).update((features) => {\n if (features.includes(feature)) {\n return features\n }\n return [...features, feature]\n })\n }\n}\n","import type { Selection } from '@milkdown/kit/prose/state'\n\nexport function isInCodeBlock(selection: Selection) {\n const type = selection.$from.parent.type\n return type.name === 'code_block'\n}\n\nexport function isInList(selection: Selection) {\n const type = selection.$from.node(selection.$from.depth - 1)?.type\n return type?.name === 'list_item'\n}\n","import type { BlockEditFeatureConfig } from './block-edit'\nimport type { CodeMirrorFeatureConfig } from './code-mirror'\nimport type { CursorFeatureConfig } from './cursor'\nimport type { ImageBlockFeatureConfig } from './image-block'\nimport type { LatexFeatureConfig } from './latex'\nimport type { LinkTooltipFeatureConfig } from './link-tooltip'\nimport type { ListItemFeatureConfig } from './list-item'\nimport type { PlaceholderFeatureConfig } from './placeholder'\nimport type { TableFeatureConfig } from './table'\nimport type { ToolbarFeatureConfig } from './toolbar'\n\n/// The crepe editor feature flags.\n/// Every feature is enabled by default.\n/// Every feature is a string literal type.\nexport enum CrepeFeature {\n /// Syntax highlighting and editing for code blocks with language support, theme customization, and preview capabilities.\n CodeMirror = 'code-mirror',\n\n /// Support for bullet lists, ordered lists, and todo lists with customizable icons and formatting.\n ListItem = 'list-item',\n\n /// Enhanced link editing and preview with customizable tooltips, edit/remove actions, and copy functionality.\n LinkTooltip = 'link-tooltip',\n\n /// Enhanced cursor experience with drop cursor and gap cursor for better content placement.\n Cursor = 'cursor',\n\n /// Image upload and management with resizing, captions, and support for both inline and block images.\n ImageBlock = 'image-block',\n\n /// Drag-and-drop block management and slash commands for quick content insertion and organization.\n BlockEdit = 'block-edit',\n\n /// Formatting toolbar for selected text with customizable icons and actions.\n Toolbar = 'toolbar',\n\n /// Document or block level placeholders to guide users when content is empty.\n Placeholder = 'placeholder',\n\n /// Full-featured table editing with row/column management, alignment options, and drag-and-drop functionality.\n Table = 'table',\n\n /// Mathematical formula support with both inline and block math rendering using KaTeX.\n Latex = 'latex',\n}\n\nexport interface CrepeFeatureConfig {\n [CrepeFeature.Cursor]?: CursorFeatureConfig\n [CrepeFeature.ListItem]?: ListItemFeatureConfig\n [CrepeFeature.LinkTooltip]?: LinkTooltipFeatureConfig\n [CrepeFeature.ImageBlock]?: ImageBlockFeatureConfig\n [CrepeFeature.BlockEdit]?: BlockEditFeatureConfig\n [CrepeFeature.Placeholder]?: PlaceholderFeatureConfig\n [CrepeFeature.Toolbar]?: ToolbarFeatureConfig\n [CrepeFeature.CodeMirror]?: CodeMirrorFeatureConfig\n [CrepeFeature.Table]?: TableFeatureConfig\n [CrepeFeature.Latex]?: LatexFeatureConfig\n}\n\nexport const defaultFeatures: Record<CrepeFeature, boolean> = {\n [CrepeFeature.Cursor]: true,\n [CrepeFeature.ListItem]: true,\n [CrepeFeature.LinkTooltip]: true,\n [CrepeFeature.ImageBlock]: true,\n [CrepeFeature.BlockEdit]: true,\n [CrepeFeature.Placeholder]: true,\n [CrepeFeature.Toolbar]: true,\n [CrepeFeature.CodeMirror]: true,\n [CrepeFeature.Table]: true,\n [CrepeFeature.Latex]: true,\n}\n","import type { Node } from '@milkdown/kit/prose/model'\nimport type { EditorState } from '@milkdown/kit/prose/state'\n\nimport { findParent } from '@milkdown/kit/prose'\nimport { Plugin, PluginKey } from '@milkdown/kit/prose/state'\nimport { Decoration, DecorationSet } from '@milkdown/kit/prose/view'\nimport { $ctx, $prose } from '@milkdown/kit/utils'\n\nimport type { DefineFeature } from '../shared'\n\nimport { crepeFeatureConfig } from '../../core/slice'\nimport { isInCodeBlock, isInList } from '../../utils'\nimport { CrepeFeature } from '../index'\n\nfunction isDocEmpty(doc: Node) {\n return doc.childCount <= 1 && !doc.firstChild?.content.size\n}\n\nfunction createPlaceholderDecoration(\n state: EditorState,\n placeholderText: string\n): Decoration | null {\n const { selection } = state\n if (!selection.empty) return null\n\n const $pos = selection.$anchor\n const node = $pos.parent\n if (node.content.size > 0) return null\n\n const inTable = findParent((node) => node.type.name === 'table')($pos)\n if (inTable) return null\n\n const before = $pos.before()\n\n return Decoration.node(before, before + node.nodeSize, {\n class: 'crepe-placeholder',\n 'data-placeholder': placeholderText,\n })\n}\n\ninterface PlaceholderConfig {\n text: string\n mode: 'doc' | 'block'\n}\n\nexport type PlaceholderFeatureConfig = Partial<PlaceholderConfig>\n\nexport const placeholderConfig = $ctx(\n {\n text: 'Please enter...',\n mode: 'block',\n } as PlaceholderConfig,\n 'placeholderConfigCtx'\n)\n\nexport const placeholderPlugin = $prose((ctx) => {\n return new Plugin({\n key: new PluginKey('CREPE_PLACEHOLDER'),\n props: {\n decorations: (state) => {\n const config = ctx.get(placeholderConfig.key)\n if (config.mode === 'doc' && !isDocEmpty(state.doc)) return null\n\n if (isInCodeBlock(state.selection) || isInList(state.selection))\n return null\n\n const placeholderText = config.text ?? 'Please enter...'\n const deco = createPlaceholderDecoration(state, placeholderText)\n if (!deco) return null\n\n return DecorationSet.create(state.doc, [deco])\n },\n },\n })\n})\n\nexport const placeholder: DefineFeature<PlaceholderFeatureConfig> = (\n editor,\n config\n) => {\n editor\n .config(crepeFeatureConfig(CrepeFeature.Placeholder))\n .config((ctx) => {\n if (config) {\n ctx.update(placeholderConfig.key, (prev) => {\n return {\n ...prev,\n ...config,\n }\n })\n }\n })\n .use(placeholderPlugin)\n .use(placeholderConfig)\n}\n"],"names":["createSlice","CrepeFeature","findParent","node","Decoration","$ctx","$prose","Plugin","PluginKey","DecorationSet"],"mappings":";;;;;;;;AAQ2BA,eAAA,CAAY,EAAC,EAAqB,aAAa;AAKlDA,eAAA,CAAY,EAAC,EAAmB,UAAU;AA2B3D,SAAS,iBAAiB,GAAU,EAAA;AAEzC,EAAO,OAAA,GAAA,CAAI,IAAmC,aAAa,CAAA;AAC7D;AAGO,SAAS,mBAAmB,OAAuB,EAAA;AACxD,EAAA,OAAO,CAAC,GAAa,KAAA;AACnB,IAAA,gBAAA,CAAiB,GAAG,CAAA,CAAE,MAAO,CAAA,CAAC,QAAa,KAAA;AACzC,MAAI,IAAA,QAAA,CAAS,QAAS,CAAA,OAAO,CAAG,EAAA;AAC9B,QAAO,OAAA,QAAA;AAAA;AAET,MAAO,OAAA,CAAC,GAAG,QAAA,EAAU,OAAO,CAAA;AAAA,KAC7B,CAAA;AAAA,GAC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CAAS,MAAM,SAAS,CAAA;AAC5D,UAAO,OAAA,IAAA;AAET,QAAM,MAAA,eAAA,GAAA,CAAkB,EAAO,GAAA,MAAA,CAAA,IAAA,KAAP,IAAe,GAAA,EAAA,GAAA,iBAAA;AACvC,QAAM,MAAA,IAAA,GAAO,2BAA4B,CAAA,KAAA,EAAO,eAAe,CAAA;AAC/D,QAAI,IAAA,CAAC,MAAa,OAAA,IAAA;AAElB,QAAA,OAAOC,mBAAc,MAAO,CAAA,KAAA,CAAM,GAAK,EAAA,CAAC,IAAI,CAAC,CAAA;AAAA;AAC/C;AACF,GACD,CAAA;AACH,CAAC;AAEY,MAAA,WAAA,GAAuD,CAClE,MAAA,EACA,MACG,KAAA;AACH,EACG,MAAA,CAAA,MAAA,CAAO,mBAAmB,YAAa,CAAA,WAAW,CAAC,CACnD,CAAA,MAAA,CAAO,CAAC,GAAQ,KAAA;AACf,IAAA,IAAI,MAAQ,EAAA;AACV,MAAA,GAAA,CAAI,MAAO,CAAA,iBAAA,CAAkB,GAAK,EAAA,CAAC,IAAS,KAAA;AAC1C,QAAO,OAAA;AAAA,UACL,GAAG,IAAA;AAAA,UACH,GAAG;AAAA,SACL;AAAA,OACD,CAAA;AAAA;AACH,GACD,CACA,CAAA,GAAA,CAAI,iBAAiB,CAAA,CACrB,IAAI,iBAAiB,CAAA;AAC1B;;;;;;"}
|
|
@@ -1,8 +1,23 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var tableBlock = require('@milkdown/kit/component/table-block');
|
|
4
|
-
var
|
|
5
|
-
|
|
4
|
+
var ctx = require('@milkdown/kit/ctx');
|
|
5
|
+
|
|
6
|
+
ctx.createSlice([], "FeaturesCtx");
|
|
7
|
+
ctx.createSlice({}, "CrepeCtx");
|
|
8
|
+
function useCrepeFeatures(ctx) {
|
|
9
|
+
return ctx.use("FeaturesCtx");
|
|
10
|
+
}
|
|
11
|
+
function crepeFeatureConfig(feature) {
|
|
12
|
+
return (ctx) => {
|
|
13
|
+
useCrepeFeatures(ctx).update((features) => {
|
|
14
|
+
if (features.includes(feature)) {
|
|
15
|
+
return features;
|
|
16
|
+
}
|
|
17
|
+
return [...features, feature];
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
}
|
|
6
21
|
|
|
7
22
|
const alignCenterIcon = `
|
|
8
23
|
<svg
|
|
@@ -56,36 +71,83 @@ const dragHandleIcon = `
|
|
|
56
71
|
</svg>
|
|
57
72
|
`;
|
|
58
73
|
|
|
59
|
-
const
|
|
60
|
-
|
|
74
|
+
const plusIcon = `
|
|
75
|
+
<svg
|
|
76
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
77
|
+
width="24"
|
|
78
|
+
height="24"
|
|
79
|
+
viewBox="0 0 24 24"
|
|
80
|
+
>
|
|
81
|
+
<g clip-path="url(#clip0_971_7676)">
|
|
82
|
+
<path
|
|
83
|
+
d="M18 13H13V18C13 18.55 12.55 19 12 19C11.45 19 11 18.55 11 18V13H6C5.45 13 5 12.55 5 12C5 11.45 5.45 11 6 11H11V6C11 5.45 11.45 5 12 5C12.55 5 13 5.45 13 6V11H18C18.55 11 19 11.45 19 12C19 12.55 18.55 13 18 13Z"
|
|
84
|
+
/>
|
|
85
|
+
</g>
|
|
86
|
+
<defs>
|
|
87
|
+
<clipPath id="clip0_971_7676">
|
|
88
|
+
<rect width="24" height="24" />
|
|
89
|
+
</clipPath>
|
|
90
|
+
</defs>
|
|
91
|
+
</svg>
|
|
92
|
+
`;
|
|
93
|
+
|
|
94
|
+
const removeIcon = `
|
|
95
|
+
<svg
|
|
96
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
97
|
+
width="24"
|
|
98
|
+
height="24"
|
|
99
|
+
viewBox="0 0 24 24"
|
|
100
|
+
>
|
|
101
|
+
<path
|
|
102
|
+
d="M7.30775 20.4997C6.81058 20.4997 6.385 20.3227 6.031 19.9687C5.677 19.6147 5.5 19.1892 5.5 18.692V5.99973H5.25C5.0375 5.99973 4.85942 5.92782 4.71575 5.78398C4.57192 5.64015 4.5 5.46198 4.5 5.24948C4.5 5.03682 4.57192 4.85873 4.71575 4.71523C4.85942 4.57157 5.0375 4.49973 5.25 4.49973H9C9 4.2549 9.08625 4.04624 9.25875 3.87374C9.43108 3.7014 9.63967 3.61523 9.8845 3.61523H14.1155C14.3603 3.61523 14.5689 3.7014 14.7413 3.87374C14.9138 4.04624 15 4.2549 15 4.49973H18.75C18.9625 4.49973 19.1406 4.57165 19.2843 4.71548C19.4281 4.85932 19.5 5.03748 19.5 5.24998C19.5 5.46265 19.4281 5.64073 19.2843 5.78423C19.1406 5.9279 18.9625 5.99973 18.75 5.99973H18.5V18.692C18.5 19.1892 18.323 19.6147 17.969 19.9687C17.615 20.3227 17.1894 20.4997 16.6923 20.4997H7.30775ZM17 5.99973H7V18.692C7 18.7818 7.02883 18.8556 7.0865 18.9132C7.14417 18.9709 7.21792 18.9997 7.30775 18.9997H16.6923C16.7821 18.9997 16.8558 18.9709 16.9135 18.9132C16.9712 18.8556 17 18.7818 17 18.692V5.99973ZM10.1543 16.9997C10.3668 16.9997 10.5448 16.9279 10.6885 16.7842C10.832 16.6404 10.9037 16.4622 10.9037 16.2497V8.74973C10.9037 8.53723 10.8318 8.35907 10.688 8.21523C10.5443 8.07157 10.3662 7.99973 10.1535 7.99973C9.941 7.99973 9.76292 8.07157 9.61925 8.21523C9.47575 8.35907 9.404 8.53723 9.404 8.74973V16.2497C9.404 16.4622 9.47583 16.6404 9.6195 16.7842C9.76333 16.9279 9.94158 16.9997 10.1543 16.9997ZM13.8465 16.9997C14.059 16.9997 14.2371 16.9279 14.3807 16.7842C14.5243 16.6404 14.596 16.4622 14.596 16.2497V8.74973C14.596 8.53723 14.5242 8.35907 14.3805 8.21523C14.2367 8.07157 14.0584 7.99973 13.8458 7.99973C13.6333 7.99973 13.4552 8.07157 13.3115 8.21523C13.168 8.35907 13.0962 8.53723 13.0962 8.74973V16.2497C13.0962 16.4622 13.1682 16.6404 13.312 16.7842C13.4557 16.9279 13.6338 16.9997 13.8465 16.9997Z"
|
|
103
|
+
/>
|
|
104
|
+
</svg>
|
|
105
|
+
`;
|
|
106
|
+
|
|
107
|
+
var CrepeFeature = /* @__PURE__ */ ((CrepeFeature2) => {
|
|
108
|
+
CrepeFeature2["CodeMirror"] = "code-mirror";
|
|
109
|
+
CrepeFeature2["ListItem"] = "list-item";
|
|
110
|
+
CrepeFeature2["LinkTooltip"] = "link-tooltip";
|
|
111
|
+
CrepeFeature2["Cursor"] = "cursor";
|
|
112
|
+
CrepeFeature2["ImageBlock"] = "image-block";
|
|
113
|
+
CrepeFeature2["BlockEdit"] = "block-edit";
|
|
114
|
+
CrepeFeature2["Toolbar"] = "toolbar";
|
|
115
|
+
CrepeFeature2["Placeholder"] = "placeholder";
|
|
116
|
+
CrepeFeature2["Table"] = "table";
|
|
117
|
+
CrepeFeature2["Latex"] = "latex";
|
|
118
|
+
return CrepeFeature2;
|
|
119
|
+
})(CrepeFeature || {});
|
|
120
|
+
|
|
121
|
+
const table = (editor, config) => {
|
|
122
|
+
editor.config(crepeFeatureConfig(CrepeFeature.Table)).config((ctx) => {
|
|
61
123
|
ctx.update(tableBlock.tableBlockConfig.key, (defaultConfig) => ({
|
|
62
124
|
...defaultConfig,
|
|
63
125
|
renderButton: (renderType) => {
|
|
64
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i
|
|
126
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
65
127
|
switch (renderType) {
|
|
66
128
|
case "add_row":
|
|
67
|
-
return (
|
|
129
|
+
return (_a = config == null ? void 0 : config.addRowIcon) != null ? _a : plusIcon;
|
|
68
130
|
case "add_col":
|
|
69
|
-
return (
|
|
131
|
+
return (_b = config == null ? void 0 : config.addColIcon) != null ? _b : plusIcon;
|
|
70
132
|
case "delete_row":
|
|
71
|
-
return (
|
|
133
|
+
return (_c = config == null ? void 0 : config.deleteRowIcon) != null ? _c : removeIcon;
|
|
72
134
|
case "delete_col":
|
|
73
|
-
return (
|
|
135
|
+
return (_d = config == null ? void 0 : config.deleteColIcon) != null ? _d : removeIcon;
|
|
74
136
|
case "align_col_left":
|
|
75
|
-
return (
|
|
137
|
+
return (_e = config == null ? void 0 : config.alignLeftIcon) != null ? _e : alignLeftIcon;
|
|
76
138
|
case "align_col_center":
|
|
77
|
-
return (
|
|
139
|
+
return (_f = config == null ? void 0 : config.alignCenterIcon) != null ? _f : alignCenterIcon;
|
|
78
140
|
case "align_col_right":
|
|
79
|
-
return (
|
|
141
|
+
return (_g = config == null ? void 0 : config.alignRightIcon) != null ? _g : alignRightIcon;
|
|
80
142
|
case "col_drag_handle":
|
|
81
|
-
return (
|
|
143
|
+
return (_h = config == null ? void 0 : config.colDragHandleIcon) != null ? _h : dragHandleIcon;
|
|
82
144
|
case "row_drag_handle":
|
|
83
|
-
return (
|
|
145
|
+
return (_i = config == null ? void 0 : config.rowDragHandleIcon) != null ? _i : dragHandleIcon;
|
|
84
146
|
}
|
|
85
147
|
}
|
|
86
148
|
}));
|
|
87
149
|
}).use(tableBlock.tableBlock);
|
|
88
150
|
};
|
|
89
151
|
|
|
90
|
-
exports.
|
|
91
|
-
//# sourceMappingURL=index
|
|
152
|
+
exports.table = table;
|
|
153
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../../src/core/slice.ts","../../../../src/icons/align-center.ts","../../../../src/icons/align-left.ts","../../../../src/icons/align-right.ts","../../../../src/icons/drag-handle.ts","../../../../src/icons/plus.ts","../../../../src/icons/remove.ts","../../../../src/feature/index.ts","../../../../src/feature/table/index.ts"],"sourcesContent":["import { createSlice, type Ctx } from '@milkdown/kit/ctx'\n\nimport type { CrepeFeature } from '../feature'\nimport type { CrepeBuilder } from './builder'\n\n/// @internal\n/// The feature flags context.\n/// ⚠️ Most of the time, you should use `useCrepeFeatures` to get the features.\nexport const FeaturesCtx = createSlice([] as CrepeFeature[], 'FeaturesCtx')\n\n/// @internal\n/// The crepe editor context.\n/// ⚠️ Most of the time, you should use `useCrepe` to get the crepe editor instance.\nexport const CrepeCtx = createSlice({} as CrepeBuilder, 'CrepeCtx')\n\n/// The crepe editor context.\n/// You can use this context to access the crepe editor instance within Milkdown plugins.\n/// ```ts\n/// import { crepeCtx } from '@milkdown/crepe'\n/// const plugin = (ctx: Ctx) => {\n/// return () => {\n/// const crepe = useCrepe(ctx)\n/// crepe.setReadonly(true)\n/// }\n/// }\n/// ```\nexport function useCrepe(ctx: Ctx) {\n // We should use string slice here to avoid the slice to be bundled in multiple entries\n return ctx.get<CrepeBuilder, 'CrepeCtx'>('CrepeCtx')\n}\n\n/// Check the enabled FeatureFlags\n/// ```ts\n/// import { useCrepeFeatures } from '@milkdown/crepe'\n/// const plugin = (ctx: Ctx) => {\n/// const features = useCrepeFeatures(ctx)\n/// if (features.get().includes(CrepeFeature.CodeMirror)) {\n/// // Do something with CodeMirror\n/// }\n/// }\nexport function useCrepeFeatures(ctx: Ctx) {\n // We should use string slice here to avoid the slice to be bundled in multiple entries\n return ctx.use<CrepeFeature[], 'FeaturesCtx'>('FeaturesCtx')\n}\n\n/// @internal\nexport function crepeFeatureConfig(feature: CrepeFeature) {\n return (ctx: Ctx) => {\n useCrepeFeatures(ctx).update((features) => {\n if (features.includes(feature)) {\n return features\n }\n return [...features, feature]\n })\n }\n}\n","export const alignCenterIcon = `\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n width=\"24\"\n height=\"24\"\n viewBox=\"0 0 24 24\"\n >\n <path\n d=\"M4.25 20.5C4.0375 20.5 3.85942 20.4281 3.71575 20.2843C3.57192 20.1404 3.5 19.9622 3.5 19.7498C3.5 19.5371 3.57192 19.359 3.71575 19.2155C3.85942 19.0718 4.0375 19 4.25 19H19.75C19.9625 19 20.1406 19.0719 20.2843 19.2158C20.4281 19.3596 20.5 19.5378 20.5 19.7502C20.5 19.9629 20.4281 20.141 20.2843 20.2845C20.1406 20.4282 19.9625 20.5 19.75 20.5H4.25ZM8.25 16.625C8.0375 16.625 7.85942 16.5531 7.71575 16.4093C7.57192 16.2654 7.5 16.0872 7.5 15.8748C7.5 15.6621 7.57192 15.484 7.71575 15.3405C7.85942 15.1968 8.0375 15.125 8.25 15.125H15.75C15.9625 15.125 16.1406 15.1969 16.2843 15.3408C16.4281 15.4846 16.5 15.6628 16.5 15.8753C16.5 16.0879 16.4281 16.266 16.2843 16.4095C16.1406 16.5532 15.9625 16.625 15.75 16.625H8.25ZM4.25 12.75C4.0375 12.75 3.85942 12.6781 3.71575 12.5343C3.57192 12.3904 3.5 12.2122 3.5 11.9998C3.5 11.7871 3.57192 11.609 3.71575 11.4655C3.85942 11.3218 4.0375 11.25 4.25 11.25H19.75C19.9625 11.25 20.1406 11.3219 20.2843 11.4658C20.4281 11.6096 20.5 11.7878 20.5 12.0003C20.5 12.2129 20.4281 12.391 20.2843 12.5345C20.1406 12.6782 19.9625 12.75 19.75 12.75H4.25ZM8.25 8.875C8.0375 8.875 7.85942 8.80308 7.71575 8.65925C7.57192 8.51542 7.5 8.33725 7.5 8.12475C7.5 7.91208 7.57192 7.734 7.71575 7.5905C7.85942 7.44683 8.0375 7.375 8.25 7.375H15.75C15.9625 7.375 16.1406 7.44692 16.2843 7.59075C16.4281 7.73458 16.5 7.91275 16.5 8.12525C16.5 8.33792 16.4281 8.516 16.2843 8.6595C16.1406 8.80317 15.9625 8.875 15.75 8.875H8.25ZM4.25 5C4.0375 5 3.85942 4.92808 3.71575 4.78425C3.57192 4.64042 3.5 4.46225 3.5 4.24975C3.5 4.03708 3.57192 3.859 3.71575 3.7155C3.85942 3.57183 4.0375 3.5 4.25 3.5H19.75C19.9625 3.5 20.1406 3.57192 20.2843 3.71575C20.4281 3.85958 20.5 4.03775 20.5 4.25025C20.5 4.46292 20.4281 4.641 20.2843 4.7845C20.1406 4.92817 19.9625 5 19.75 5H4.25Z\"\n />\n </svg>\n`\n","export const alignLeftIcon = `\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n width=\"24\"\n height=\"24\"\n viewBox=\"0 0 24 24\"\n >\n <path\n d=\"M4.25 20.5C4.0375 20.5 3.85942 20.4281 3.71575 20.2843C3.57192 20.1404 3.5 19.9622 3.5 19.7498C3.5 19.5371 3.57192 19.359 3.71575 19.2155C3.85942 19.0718 4.0375 19 4.25 19H19.75C19.9625 19 20.1406 19.0719 20.2843 19.2158C20.4281 19.3596 20.5 19.5378 20.5 19.7502C20.5 19.9629 20.4281 20.141 20.2843 20.2845C20.1406 20.4282 19.9625 20.5 19.75 20.5H4.25ZM4.25 16.625C4.0375 16.625 3.85942 16.5531 3.71575 16.4093C3.57192 16.2654 3.5 16.0872 3.5 15.8748C3.5 15.6621 3.57192 15.484 3.71575 15.3405C3.85942 15.1968 4.0375 15.125 4.25 15.125H13.75C13.9625 15.125 14.1406 15.1969 14.2843 15.3408C14.4281 15.4846 14.5 15.6628 14.5 15.8753C14.5 16.0879 14.4281 16.266 14.2843 16.4095C14.1406 16.5532 13.9625 16.625 13.75 16.625H4.25ZM4.25 12.75C4.0375 12.75 3.85942 12.6781 3.71575 12.5343C3.57192 12.3904 3.5 12.2122 3.5 11.9998C3.5 11.7871 3.57192 11.609 3.71575 11.4655C3.85942 11.3218 4.0375 11.25 4.25 11.25H19.75C19.9625 11.25 20.1406 11.3219 20.2843 11.4658C20.4281 11.6096 20.5 11.7878 20.5 12.0003C20.5 12.2129 20.4281 12.391 20.2843 12.5345C20.1406 12.6782 19.9625 12.75 19.75 12.75H4.25ZM4.25 8.875C4.0375 8.875 3.85942 8.80308 3.71575 8.65925C3.57192 8.51542 3.5 8.33725 3.5 8.12475C3.5 7.91208 3.57192 7.734 3.71575 7.5905C3.85942 7.44683 4.0375 7.375 4.25 7.375H13.75C13.9625 7.375 14.1406 7.44692 14.2843 7.59075C14.4281 7.73458 14.5 7.91275 14.5 8.12525C14.5 8.33792 14.4281 8.516 14.2843 8.6595C14.1406 8.80317 13.9625 8.875 13.75 8.875H4.25ZM4.25 5C4.0375 5 3.85942 4.92808 3.71575 4.78425C3.57192 4.64042 3.5 4.46225 3.5 4.24975C3.5 4.03708 3.57192 3.859 3.71575 3.7155C3.85942 3.57183 4.0375 3.5 4.25 3.5H19.75C19.9625 3.5 20.1406 3.57192 20.2843 3.71575C20.4281 3.85958 20.5 4.03775 20.5 4.25025C20.5 4.46292 20.4281 4.641 20.2843 4.7845C20.1406 4.92817 19.9625 5 19.75 5H4.25Z\"\n />\n </svg>\n`\n","export const alignRightIcon = `\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n width=\"24\"\n height=\"24\"\n viewBox=\"0 0 24 24\"\n >\n <path\n d=\"M4.25 5C4.0375 5 3.85942 4.92808 3.71575 4.78425C3.57192 4.64042 3.5 4.46225 3.5 4.24975C3.5 4.03708 3.57192 3.859 3.71575 3.7155C3.85942 3.57183 4.0375 3.5 4.25 3.5H19.75C19.9625 3.5 20.1406 3.57192 20.2843 3.71575C20.4281 3.85958 20.5 4.03775 20.5 4.25025C20.5 4.46292 20.4281 4.641 20.2843 4.7845C20.1406 4.92817 19.9625 5 19.75 5H4.25ZM10.25 8.875C10.0375 8.875 9.85942 8.80308 9.71575 8.65925C9.57192 8.51542 9.5 8.33725 9.5 8.12475C9.5 7.91208 9.57192 7.734 9.71575 7.5905C9.85942 7.44683 10.0375 7.375 10.25 7.375H19.75C19.9625 7.375 20.1406 7.44692 20.2843 7.59075C20.4281 7.73458 20.5 7.91275 20.5 8.12525C20.5 8.33792 20.4281 8.516 20.2843 8.6595C20.1406 8.80317 19.9625 8.875 19.75 8.875H10.25ZM4.25 12.75C4.0375 12.75 3.85942 12.6781 3.71575 12.5343C3.57192 12.3904 3.5 12.2122 3.5 11.9998C3.5 11.7871 3.57192 11.609 3.71575 11.4655C3.85942 11.3218 4.0375 11.25 4.25 11.25H19.75C19.9625 11.25 20.1406 11.3219 20.2843 11.4658C20.4281 11.6096 20.5 11.7878 20.5 12.0003C20.5 12.2129 20.4281 12.391 20.2843 12.5345C20.1406 12.6782 19.9625 12.75 19.75 12.75H4.25ZM10.25 16.625C10.0375 16.625 9.85942 16.5531 9.71575 16.4093C9.57192 16.2654 9.5 16.0872 9.5 15.8748C9.5 15.6621 9.57192 15.484 9.71575 15.3405C9.85942 15.1968 10.0375 15.125 10.25 15.125H19.75C19.9625 15.125 20.1406 15.1969 20.2843 15.3408C20.4281 15.4846 20.5 15.6628 20.5 15.8753C20.5 16.0879 20.4281 16.266 20.2843 16.4095C20.1406 16.5532 19.9625 16.625 19.75 16.625H10.25ZM4.25 20.5C4.0375 20.5 3.85942 20.4281 3.71575 20.2843C3.57192 20.1404 3.5 19.9622 3.5 19.7498C3.5 19.5371 3.57192 19.359 3.71575 19.2155C3.85942 19.0718 4.0375 19 4.25 19H19.75C19.9625 19 20.1406 19.0719 20.2843 19.2158C20.4281 19.3596 20.5 19.5378 20.5 19.7502C20.5 19.9629 20.4281 20.141 20.2843 20.2845C20.1406 20.4282 19.9625 20.5 19.75 20.5H4.25Z\"\n />\n </svg>\n`\n","export const dragHandleIcon = `\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n width=\"16\"\n height=\"16\"\n viewBox=\"0 0 16 16\"\n >\n <path\n d=\"M3.5 9.83366C3.35833 9.83366 3.23961 9.78571 3.14383 9.68983C3.04794 9.59394 3 9.47516 3 9.33349C3 9.19171 3.04794 9.07299 3.14383 8.97733C3.23961 8.88155 3.35833 8.83366 3.5 8.83366H12.5C12.6417 8.83366 12.7604 8.8816 12.8562 8.97749C12.9521 9.07338 13 9.19216 13 9.33383C13 9.4756 12.9521 9.59433 12.8562 9.68999C12.7604 9.78577 12.6417 9.83366 12.5 9.83366H3.5ZM3.5 7.16699C3.35833 7.16699 3.23961 7.11905 3.14383 7.02316C3.04794 6.92727 3 6.80849 3 6.66683C3 6.52505 3.04794 6.40633 3.14383 6.31066C3.23961 6.21488 3.35833 6.16699 3.5 6.16699H12.5C12.6417 6.16699 12.7604 6.21494 12.8562 6.31083C12.9521 6.40671 13 6.52549 13 6.66716C13 6.80894 12.9521 6.92766 12.8562 7.02333C12.7604 7.1191 12.6417 7.16699 12.5 7.16699H3.5Z\"\n />\n </svg>\n`\n","export const plusIcon = `\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n width=\"24\"\n height=\"24\"\n viewBox=\"0 0 24 24\"\n >\n <g clip-path=\"url(#clip0_971_7676)\">\n <path\n d=\"M18 13H13V18C13 18.55 12.55 19 12 19C11.45 19 11 18.55 11 18V13H6C5.45 13 5 12.55 5 12C5 11.45 5.45 11 6 11H11V6C11 5.45 11.45 5 12 5C12.55 5 13 5.45 13 6V11H18C18.55 11 19 11.45 19 12C19 12.55 18.55 13 18 13Z\"\n />\n </g>\n <defs>\n <clipPath id=\"clip0_971_7676\">\n <rect width=\"24\" height=\"24\" />\n </clipPath>\n </defs>\n </svg>\n`\n","export const removeIcon = `\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n width=\"24\"\n height=\"24\"\n viewBox=\"0 0 24 24\"\n >\n <path\n d=\"M7.30775 20.4997C6.81058 20.4997 6.385 20.3227 6.031 19.9687C5.677 19.6147 5.5 19.1892 5.5 18.692V5.99973H5.25C5.0375 5.99973 4.85942 5.92782 4.71575 5.78398C4.57192 5.64015 4.5 5.46198 4.5 5.24948C4.5 5.03682 4.57192 4.85873 4.71575 4.71523C4.85942 4.57157 5.0375 4.49973 5.25 4.49973H9C9 4.2549 9.08625 4.04624 9.25875 3.87374C9.43108 3.7014 9.63967 3.61523 9.8845 3.61523H14.1155C14.3603 3.61523 14.5689 3.7014 14.7413 3.87374C14.9138 4.04624 15 4.2549 15 4.49973H18.75C18.9625 4.49973 19.1406 4.57165 19.2843 4.71548C19.4281 4.85932 19.5 5.03748 19.5 5.24998C19.5 5.46265 19.4281 5.64073 19.2843 5.78423C19.1406 5.9279 18.9625 5.99973 18.75 5.99973H18.5V18.692C18.5 19.1892 18.323 19.6147 17.969 19.9687C17.615 20.3227 17.1894 20.4997 16.6923 20.4997H7.30775ZM17 5.99973H7V18.692C7 18.7818 7.02883 18.8556 7.0865 18.9132C7.14417 18.9709 7.21792 18.9997 7.30775 18.9997H16.6923C16.7821 18.9997 16.8558 18.9709 16.9135 18.9132C16.9712 18.8556 17 18.7818 17 18.692V5.99973ZM10.1543 16.9997C10.3668 16.9997 10.5448 16.9279 10.6885 16.7842C10.832 16.6404 10.9037 16.4622 10.9037 16.2497V8.74973C10.9037 8.53723 10.8318 8.35907 10.688 8.21523C10.5443 8.07157 10.3662 7.99973 10.1535 7.99973C9.941 7.99973 9.76292 8.07157 9.61925 8.21523C9.47575 8.35907 9.404 8.53723 9.404 8.74973V16.2497C9.404 16.4622 9.47583 16.6404 9.6195 16.7842C9.76333 16.9279 9.94158 16.9997 10.1543 16.9997ZM13.8465 16.9997C14.059 16.9997 14.2371 16.9279 14.3807 16.7842C14.5243 16.6404 14.596 16.4622 14.596 16.2497V8.74973C14.596 8.53723 14.5242 8.35907 14.3805 8.21523C14.2367 8.07157 14.0584 7.99973 13.8458 7.99973C13.6333 7.99973 13.4552 8.07157 13.3115 8.21523C13.168 8.35907 13.0962 8.53723 13.0962 8.74973V16.2497C13.0962 16.4622 13.1682 16.6404 13.312 16.7842C13.4557 16.9279 13.6338 16.9997 13.8465 16.9997Z\"\n />\n </svg>\n`\n","import type { BlockEditFeatureConfig } from './block-edit'\nimport type { CodeMirrorFeatureConfig } from './code-mirror'\nimport type { CursorFeatureConfig } from './cursor'\nimport type { ImageBlockFeatureConfig } from './image-block'\nimport type { LatexFeatureConfig } from './latex'\nimport type { LinkTooltipFeatureConfig } from './link-tooltip'\nimport type { ListItemFeatureConfig } from './list-item'\nimport type { PlaceholderFeatureConfig } from './placeholder'\nimport type { TableFeatureConfig } from './table'\nimport type { ToolbarFeatureConfig } from './toolbar'\n\n/// The crepe editor feature flags.\n/// Every feature is enabled by default.\n/// Every feature is a string literal type.\nexport enum CrepeFeature {\n /// Syntax highlighting and editing for code blocks with language support, theme customization, and preview capabilities.\n CodeMirror = 'code-mirror',\n\n /// Support for bullet lists, ordered lists, and todo lists with customizable icons and formatting.\n ListItem = 'list-item',\n\n /// Enhanced link editing and preview with customizable tooltips, edit/remove actions, and copy functionality.\n LinkTooltip = 'link-tooltip',\n\n /// Enhanced cursor experience with drop cursor and gap cursor for better content placement.\n Cursor = 'cursor',\n\n /// Image upload and management with resizing, captions, and support for both inline and block images.\n ImageBlock = 'image-block',\n\n /// Drag-and-drop block management and slash commands for quick content insertion and organization.\n BlockEdit = 'block-edit',\n\n /// Formatting toolbar for selected text with customizable icons and actions.\n Toolbar = 'toolbar',\n\n /// Document or block level placeholders to guide users when content is empty.\n Placeholder = 'placeholder',\n\n /// Full-featured table editing with row/column management, alignment options, and drag-and-drop functionality.\n Table = 'table',\n\n /// Mathematical formula support with both inline and block math rendering using KaTeX.\n Latex = 'latex',\n}\n\nexport interface CrepeFeatureConfig {\n [CrepeFeature.Cursor]?: CursorFeatureConfig\n [CrepeFeature.ListItem]?: ListItemFeatureConfig\n [CrepeFeature.LinkTooltip]?: LinkTooltipFeatureConfig\n [CrepeFeature.ImageBlock]?: ImageBlockFeatureConfig\n [CrepeFeature.BlockEdit]?: BlockEditFeatureConfig\n [CrepeFeature.Placeholder]?: PlaceholderFeatureConfig\n [CrepeFeature.Toolbar]?: ToolbarFeatureConfig\n [CrepeFeature.CodeMirror]?: CodeMirrorFeatureConfig\n [CrepeFeature.Table]?: TableFeatureConfig\n [CrepeFeature.Latex]?: LatexFeatureConfig\n}\n\nexport const defaultFeatures: Record<CrepeFeature, boolean> = {\n [CrepeFeature.Cursor]: true,\n [CrepeFeature.ListItem]: true,\n [CrepeFeature.LinkTooltip]: true,\n [CrepeFeature.ImageBlock]: true,\n [CrepeFeature.BlockEdit]: true,\n [CrepeFeature.Placeholder]: true,\n [CrepeFeature.Toolbar]: true,\n [CrepeFeature.CodeMirror]: true,\n [CrepeFeature.Table]: true,\n [CrepeFeature.Latex]: true,\n}\n","import {\n tableBlock,\n tableBlockConfig,\n} from '@milkdown/kit/component/table-block'\n\nimport type { DefineFeature } from '../shared'\n\nimport { crepeFeatureConfig } from '../../core/slice'\nimport {\n alignCenterIcon,\n alignLeftIcon,\n alignRightIcon,\n dragHandleIcon,\n plusIcon,\n removeIcon,\n} from '../../icons'\nimport { CrepeFeature } from '../index'\n\ninterface TableConfig {\n addRowIcon: string\n addColIcon: string\n deleteRowIcon: string\n deleteColIcon: string\n alignLeftIcon: string\n alignCenterIcon: string\n alignRightIcon: string\n colDragHandleIcon: string\n rowDragHandleIcon: string\n}\n\nexport type TableFeatureConfig = Partial<TableConfig>\n\nexport const table: DefineFeature<TableFeatureConfig> = (editor, config) => {\n editor\n .config(crepeFeatureConfig(CrepeFeature.Table))\n .config((ctx) => {\n ctx.update(tableBlockConfig.key, (defaultConfig) => ({\n ...defaultConfig,\n renderButton: (renderType) => {\n switch (renderType) {\n case 'add_row':\n return config?.addRowIcon ?? plusIcon\n case 'add_col':\n return config?.addColIcon ?? plusIcon\n case 'delete_row':\n return config?.deleteRowIcon ?? removeIcon\n case 'delete_col':\n return config?.deleteColIcon ?? removeIcon\n case 'align_col_left':\n return config?.alignLeftIcon ?? alignLeftIcon\n case 'align_col_center':\n return config?.alignCenterIcon ?? alignCenterIcon\n case 'align_col_right':\n return config?.alignRightIcon ?? alignRightIcon\n case 'col_drag_handle':\n return config?.colDragHandleIcon ?? dragHandleIcon\n case 'row_drag_handle':\n return config?.rowDragHandleIcon ?? dragHandleIcon\n }\n },\n }))\n })\n .use(tableBlock)\n}\n"],"names":["createSlice","CrepeFeature","tableBlockConfig","tableBlock"],"mappings":";;;;;AAQ2BA,eAAA,CAAY,EAAC,EAAqB,aAAa;AAKlDA,eAAA,CAAY,EAAC,EAAmB,UAAU;AA2B3D,SAAS,iBAAiB,GAAU,EAAA;AAEzC,EAAO,OAAA,GAAA,CAAI,IAAmC,aAAa,CAAA;AAC7D;AAGO,SAAS,mBAAmB,OAAuB,EAAA;AACxD,EAAA,OAAO,CAAC,GAAa,KAAA;AACnB,IAAA,gBAAA,CA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AA,UAAA;AAAA,UAClC,KAAK,gBAAA;AACH,YAAO,OAAA,CAAA,EAAA,GAAA,MAAA,IAAA,IAAA,GAAA,MAAA,GAAA,MAAA,CAAQ,kBAAR,IAAyB,GAAA,EAAA,GAAA,aAAA;AAAA,UAClC,KAAK,kBAAA;AACH,YAAO,OAAA,CAAA,EAAA,GAAA,MAAA,IAAA,IAAA,GAAA,MAAA,GAAA,MAAA,CAAQ,oBAAR,IAA2B,GAAA,EAAA,GAAA,eAAA;AAAA,UACpC,KAAK,iBAAA;AACH,YAAO,OAAA,CAAA,EAAA,GAAA,MAAA,IAAA,IAAA,GAAA,MAAA,GAAA,MAAA,CAAQ,mBAAR,IAA0B,GAAA,EAAA,GAAA,cAAA;AAAA,UACnC,KAAK,iBAAA;AACH,YAAO,OAAA,CAAA,EAAA,GAAA,MAAA,IAAA,IAAA,GAAA,MAAA,GAAA,MAAA,CAAQ,sBAAR,IAA6B,GAAA,EAAA,GAAA,cAAA;AAAA,UACtC,KAAK,iBAAA;AACH,YAAO,OAAA,CAAA,EAAA,GAAA,MAAA,IAAA,IAAA,GAAA,MAAA,GAAA,MAAA,CAAQ,sBAAR,IAA6B,GAAA,EAAA,GAAA,cAAA;AAAA;AACxC;AACF,KACA,CAAA,CAAA;AAAA,GACH,CACA,CAAA,GAAA,CAAIC,qBAAU,CAAA;AACnB;;;;"}
|
|
@@ -3,23 +3,45 @@
|
|
|
3
3
|
var tooltip = require('@milkdown/kit/plugin/tooltip');
|
|
4
4
|
var state = require('@milkdown/kit/prose/state');
|
|
5
5
|
var vue = require('vue');
|
|
6
|
+
var ctx = require('@milkdown/kit/ctx');
|
|
6
7
|
var component = require('@milkdown/kit/component');
|
|
7
8
|
var linkTooltip = require('@milkdown/kit/component/link-tooltip');
|
|
8
9
|
var core = require('@milkdown/kit/core');
|
|
9
10
|
var commonmark = require('@milkdown/kit/preset/commonmark');
|
|
10
11
|
var gfm = require('@milkdown/kit/preset/gfm');
|
|
11
12
|
var clsx = require('clsx');
|
|
12
|
-
var
|
|
13
|
-
var
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
13
|
+
var utils = require('@milkdown/kit/utils');
|
|
14
|
+
var katex = require('katex');
|
|
15
|
+
|
|
16
|
+
ctx.createSlice([], "FeaturesCtx");
|
|
17
|
+
ctx.createSlice({}, "CrepeCtx");
|
|
18
|
+
function useCrepeFeatures(ctx) {
|
|
19
|
+
return ctx.use("FeaturesCtx");
|
|
20
|
+
}
|
|
21
|
+
function crepeFeatureConfig(feature) {
|
|
22
|
+
return (ctx) => {
|
|
23
|
+
useCrepeFeatures(ctx).update((features) => {
|
|
24
|
+
if (features.includes(feature)) {
|
|
25
|
+
return features;
|
|
26
|
+
}
|
|
27
|
+
return [...features, feature];
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
var CrepeFeature = /* @__PURE__ */ ((CrepeFeature2) => {
|
|
33
|
+
CrepeFeature2["CodeMirror"] = "code-mirror";
|
|
34
|
+
CrepeFeature2["ListItem"] = "list-item";
|
|
35
|
+
CrepeFeature2["LinkTooltip"] = "link-tooltip";
|
|
36
|
+
CrepeFeature2["Cursor"] = "cursor";
|
|
37
|
+
CrepeFeature2["ImageBlock"] = "image-block";
|
|
38
|
+
CrepeFeature2["BlockEdit"] = "block-edit";
|
|
39
|
+
CrepeFeature2["Toolbar"] = "toolbar";
|
|
40
|
+
CrepeFeature2["Placeholder"] = "placeholder";
|
|
41
|
+
CrepeFeature2["Table"] = "table";
|
|
42
|
+
CrepeFeature2["Latex"] = "latex";
|
|
43
|
+
return CrepeFeature2;
|
|
44
|
+
})(CrepeFeature || {});
|
|
23
45
|
|
|
24
46
|
const boldIcon = `
|
|
25
47
|
<svg
|
|
@@ -34,6 +56,26 @@ const boldIcon = `
|
|
|
34
56
|
</svg>
|
|
35
57
|
`;
|
|
36
58
|
|
|
59
|
+
const codeIcon = `
|
|
60
|
+
<svg
|
|
61
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
62
|
+
width="24"
|
|
63
|
+
height="24"
|
|
64
|
+
viewBox="0 0 24 24"
|
|
65
|
+
>
|
|
66
|
+
<g clip-path="url(#clip0_977_8081)">
|
|
67
|
+
<path
|
|
68
|
+
d="M9.4 16.6L4.8 12L9.4 7.4L8 6L2 12L8 18L9.4 16.6ZM14.6 16.6L19.2 12L14.6 7.4L16 6L22 12L16 18L14.6 16.6Z"
|
|
69
|
+
/>
|
|
70
|
+
</g>
|
|
71
|
+
<defs>
|
|
72
|
+
<clipPath id="clip0_977_8081">
|
|
73
|
+
<rect width="24" height="24" />
|
|
74
|
+
</clipPath>
|
|
75
|
+
</defs>
|
|
76
|
+
</svg>
|
|
77
|
+
`;
|
|
78
|
+
|
|
37
79
|
const italicIcon = `
|
|
38
80
|
<svg
|
|
39
81
|
xmlns="http://www.w3.org/2000/svg"
|
|
@@ -73,6 +115,66 @@ const strikethroughIcon = `
|
|
|
73
115
|
</svg>
|
|
74
116
|
`;
|
|
75
117
|
|
|
118
|
+
const functionsIcon = `
|
|
119
|
+
<svg
|
|
120
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
121
|
+
width="32"
|
|
122
|
+
height="32"
|
|
123
|
+
viewBox="0 0 24 24"
|
|
124
|
+
>
|
|
125
|
+
<path
|
|
126
|
+
fill="currentColor"
|
|
127
|
+
d="M7 19v-.808L13.096 12L7 5.808V5h10v1.25H9.102L14.727 12l-5.625 5.77H17V19z"
|
|
128
|
+
/>
|
|
129
|
+
</svg>
|
|
130
|
+
`;
|
|
131
|
+
|
|
132
|
+
const mathInlineId = "math_inline";
|
|
133
|
+
const mathInlineSchema = utils.$nodeSchema(mathInlineId, () => ({
|
|
134
|
+
group: "inline",
|
|
135
|
+
inline: true,
|
|
136
|
+
draggable: true,
|
|
137
|
+
atom: true,
|
|
138
|
+
attrs: {
|
|
139
|
+
value: {
|
|
140
|
+
default: ""
|
|
141
|
+
}
|
|
142
|
+
},
|
|
143
|
+
parseDOM: [
|
|
144
|
+
{
|
|
145
|
+
tag: `span[data-type="${mathInlineId}"]`,
|
|
146
|
+
getAttrs: (dom) => {
|
|
147
|
+
var _a;
|
|
148
|
+
return {
|
|
149
|
+
value: (_a = dom.dataset.value) != null ? _a : ""
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
],
|
|
154
|
+
toDOM: (node) => {
|
|
155
|
+
const code = node.attrs.value;
|
|
156
|
+
const dom = document.createElement("span");
|
|
157
|
+
dom.dataset.type = mathInlineId;
|
|
158
|
+
dom.dataset.value = code;
|
|
159
|
+
katex.render(code, dom, {
|
|
160
|
+
throwOnError: false
|
|
161
|
+
});
|
|
162
|
+
return dom;
|
|
163
|
+
},
|
|
164
|
+
parseMarkdown: {
|
|
165
|
+
match: (node) => node.type === "inlineMath",
|
|
166
|
+
runner: (state, node, type) => {
|
|
167
|
+
state.addNode(type, { value: node.value });
|
|
168
|
+
}
|
|
169
|
+
},
|
|
170
|
+
toMarkdown: {
|
|
171
|
+
match: (node) => node.type.name === mathInlineId,
|
|
172
|
+
runner: (state, node) => {
|
|
173
|
+
state.addNode("inlineMath", void 0, node.attrs.value);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}));
|
|
177
|
+
|
|
76
178
|
const Toolbar = vue.defineComponent({
|
|
77
179
|
props: {
|
|
78
180
|
ctx: {
|
|
@@ -130,16 +232,16 @@ const Toolbar = vue.defineComponent({
|
|
|
130
232
|
});
|
|
131
233
|
return hasNode;
|
|
132
234
|
};
|
|
133
|
-
const flags = ctx
|
|
134
|
-
const isLatexEnabled = flags == null ? void 0 : flags.includes(
|
|
235
|
+
const flags = useCrepeFeatures(ctx).get();
|
|
236
|
+
const isLatexEnabled = flags == null ? void 0 : flags.includes(CrepeFeature.Latex);
|
|
135
237
|
const toggleLatex = (ctx2) => {
|
|
136
|
-
const hasLatex = containsNode(
|
|
238
|
+
const hasLatex = containsNode(mathInlineSchema.type(ctx2));
|
|
137
239
|
const view = ctx2.get(core.editorViewCtx);
|
|
138
240
|
const { selection, doc, tr } = view.state;
|
|
139
241
|
if (!hasLatex) {
|
|
140
242
|
const text = doc.textBetween(selection.from, selection.to);
|
|
141
243
|
let _tr2 = tr.replaceSelectionWith(
|
|
142
|
-
|
|
244
|
+
mathInlineSchema.type(ctx2).create({
|
|
143
245
|
value: text
|
|
144
246
|
})
|
|
145
247
|
);
|
|
@@ -153,7 +255,7 @@ const Toolbar = vue.defineComponent({
|
|
|
153
255
|
let node = null;
|
|
154
256
|
doc.nodesBetween(from, to, (n, p) => {
|
|
155
257
|
if (node) return false;
|
|
156
|
-
if (n.type ===
|
|
258
|
+
if (n.type === mathInlineSchema.type(ctx2)) {
|
|
157
259
|
pos = p;
|
|
158
260
|
node = n;
|
|
159
261
|
return false;
|
|
@@ -171,7 +273,7 @@ const Toolbar = vue.defineComponent({
|
|
|
171
273
|
);
|
|
172
274
|
};
|
|
173
275
|
return () => {
|
|
174
|
-
var _a, _b, _c, _d, _e, _f
|
|
276
|
+
var _a, _b, _c, _d, _e, _f;
|
|
175
277
|
return /* @__PURE__ */ vue.h(vue.Fragment, null, /* @__PURE__ */ vue.h(
|
|
176
278
|
"button",
|
|
177
279
|
{
|
|
@@ -185,7 +287,7 @@ const Toolbar = vue.defineComponent({
|
|
|
185
287
|
commands.call(commonmark.toggleStrongCommand.key);
|
|
186
288
|
})
|
|
187
289
|
},
|
|
188
|
-
/* @__PURE__ */ vue.h(component.Icon, { icon: (
|
|
290
|
+
/* @__PURE__ */ vue.h(component.Icon, { icon: (_a = config == null ? void 0 : config.boldIcon) != null ? _a : boldIcon })
|
|
189
291
|
), /* @__PURE__ */ vue.h(
|
|
190
292
|
"button",
|
|
191
293
|
{
|
|
@@ -199,7 +301,7 @@ const Toolbar = vue.defineComponent({
|
|
|
199
301
|
commands.call(commonmark.toggleEmphasisCommand.key);
|
|
200
302
|
})
|
|
201
303
|
},
|
|
202
|
-
/* @__PURE__ */ vue.h(component.Icon, { icon: (
|
|
304
|
+
/* @__PURE__ */ vue.h(component.Icon, { icon: (_b = config == null ? void 0 : config.italicIcon) != null ? _b : italicIcon })
|
|
203
305
|
), /* @__PURE__ */ vue.h(
|
|
204
306
|
"button",
|
|
205
307
|
{
|
|
@@ -213,7 +315,7 @@ const Toolbar = vue.defineComponent({
|
|
|
213
315
|
commands.call(gfm.toggleStrikethroughCommand.key);
|
|
214
316
|
})
|
|
215
317
|
},
|
|
216
|
-
/* @__PURE__ */ vue.h(component.Icon, { icon: (
|
|
318
|
+
/* @__PURE__ */ vue.h(component.Icon, { icon: (_c = config == null ? void 0 : config.strikethroughIcon) != null ? _c : strikethroughIcon })
|
|
217
319
|
), /* @__PURE__ */ vue.h("div", { class: "divider" }), /* @__PURE__ */ vue.h(
|
|
218
320
|
"button",
|
|
219
321
|
{
|
|
@@ -227,18 +329,18 @@ const Toolbar = vue.defineComponent({
|
|
|
227
329
|
commands.call(commonmark.toggleInlineCodeCommand.key);
|
|
228
330
|
})
|
|
229
331
|
},
|
|
230
|
-
/* @__PURE__ */ vue.h(component.Icon, { icon: (
|
|
332
|
+
/* @__PURE__ */ vue.h(component.Icon, { icon: (_d = config == null ? void 0 : config.codeIcon) != null ? _d : codeIcon })
|
|
231
333
|
), isLatexEnabled && /* @__PURE__ */ vue.h(
|
|
232
334
|
"button",
|
|
233
335
|
{
|
|
234
336
|
type: "button",
|
|
235
337
|
class: clsx(
|
|
236
338
|
"toolbar-item",
|
|
237
|
-
ctx && containsNode(
|
|
339
|
+
ctx && containsNode(mathInlineSchema.type(ctx)) && "active"
|
|
238
340
|
),
|
|
239
341
|
onPointerdown: onClick(toggleLatex)
|
|
240
342
|
},
|
|
241
|
-
/* @__PURE__ */ vue.h(component.Icon, { icon: (
|
|
343
|
+
/* @__PURE__ */ vue.h(component.Icon, { icon: (_e = config == null ? void 0 : config.latexIcon) != null ? _e : functionsIcon })
|
|
242
344
|
), /* @__PURE__ */ vue.h(
|
|
243
345
|
"button",
|
|
244
346
|
{
|
|
@@ -258,7 +360,7 @@ const Toolbar = vue.defineComponent({
|
|
|
258
360
|
hide == null ? void 0 : hide();
|
|
259
361
|
})
|
|
260
362
|
},
|
|
261
|
-
/* @__PURE__ */ vue.h(component.Icon, { icon: (
|
|
363
|
+
/* @__PURE__ */ vue.h(component.Icon, { icon: (_f = config == null ? void 0 : config.linkIcon) != null ? _f : linkIcon })
|
|
262
364
|
));
|
|
263
365
|
};
|
|
264
366
|
}
|
|
@@ -272,7 +374,7 @@ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read fr
|
|
|
272
374
|
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
273
375
|
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), member.set(obj, value), value);
|
|
274
376
|
var _tooltipProvider, _content, _app, _selection, _show;
|
|
275
|
-
const
|
|
377
|
+
const toolbarTooltip = tooltip.tooltipFactory("CREPE_TOOLBAR");
|
|
276
378
|
class ToolbarView {
|
|
277
379
|
constructor(ctx, view, config) {
|
|
278
380
|
__privateAdd(this, _tooltipProvider);
|
|
@@ -337,13 +439,13 @@ _content = new WeakMap();
|
|
|
337
439
|
_app = new WeakMap();
|
|
338
440
|
_selection = new WeakMap();
|
|
339
441
|
_show = new WeakMap();
|
|
340
|
-
const
|
|
341
|
-
editor.config((ctx) => {
|
|
342
|
-
ctx.set(
|
|
442
|
+
const toolbar = (editor, config) => {
|
|
443
|
+
editor.config(crepeFeatureConfig(CrepeFeature.Toolbar)).config((ctx) => {
|
|
444
|
+
ctx.set(toolbarTooltip.key, {
|
|
343
445
|
view: (view) => new ToolbarView(ctx, view, config)
|
|
344
446
|
});
|
|
345
|
-
}).use(
|
|
447
|
+
}).use(toolbarTooltip);
|
|
346
448
|
};
|
|
347
449
|
|
|
348
|
-
exports.
|
|
349
|
-
//# sourceMappingURL=index
|
|
450
|
+
exports.toolbar = toolbar;
|
|
451
|
+
//# sourceMappingURL=index.js.map
|