@milkdown/plugin-slash 5.5.0 → 6.0.0-next.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.
Files changed (44) hide show
  1. package/lib/{src/config.d.ts → config.d.ts} +1 -0
  2. package/lib/config.d.ts.map +1 -0
  3. package/lib/index.d.ts +25 -1
  4. package/lib/index.d.ts.map +1 -0
  5. package/lib/index.es.js +67 -58
  6. package/lib/index.es.js.map +1 -1
  7. package/lib/{src/item.d.ts → item.d.ts} +0 -0
  8. package/lib/item.d.ts.map +1 -0
  9. package/lib/{src/prose-plugin → prose-plugin}/dropdown.d.ts +0 -0
  10. package/lib/prose-plugin/dropdown.d.ts.map +1 -0
  11. package/lib/{src/prose-plugin → prose-plugin}/index.d.ts +0 -0
  12. package/lib/prose-plugin/index.d.ts.map +1 -0
  13. package/lib/{src/prose-plugin → prose-plugin}/input.d.ts +0 -0
  14. package/lib/prose-plugin/input.d.ts.map +1 -0
  15. package/lib/{src/prose-plugin → prose-plugin}/props.d.ts +0 -0
  16. package/lib/prose-plugin/props.d.ts.map +1 -0
  17. package/lib/{src/prose-plugin → prose-plugin}/status.d.ts +0 -0
  18. package/lib/prose-plugin/status.d.ts.map +1 -0
  19. package/lib/{src/prose-plugin → prose-plugin}/view.d.ts +0 -0
  20. package/lib/prose-plugin/view.d.ts.map +1 -0
  21. package/lib/style.d.ts +3 -0
  22. package/lib/style.d.ts.map +1 -0
  23. package/lib/{src/utility.d.ts → utility.d.ts} +2 -2
  24. package/lib/utility.d.ts.map +1 -0
  25. package/package.json +33 -9
  26. package/src/config.ts +12 -12
  27. package/src/prose-plugin/dropdown.ts +3 -2
  28. package/src/prose-plugin/props.ts +25 -20
  29. package/src/prose-plugin/view.ts +1 -1
  30. package/src/style.ts +30 -20
  31. package/src/utility.ts +20 -8
  32. package/lib/src/config.d.ts.map +0 -1
  33. package/lib/src/index.d.ts +0 -25
  34. package/lib/src/index.d.ts.map +0 -1
  35. package/lib/src/item.d.ts.map +0 -1
  36. package/lib/src/prose-plugin/dropdown.d.ts.map +0 -1
  37. package/lib/src/prose-plugin/index.d.ts.map +0 -1
  38. package/lib/src/prose-plugin/input.d.ts.map +0 -1
  39. package/lib/src/prose-plugin/props.d.ts.map +0 -1
  40. package/lib/src/prose-plugin/status.d.ts.map +0 -1
  41. package/lib/src/prose-plugin/view.d.ts.map +0 -1
  42. package/lib/src/style.d.ts +0 -3
  43. package/lib/src/style.d.ts.map +0 -1
  44. package/lib/src/utility.d.ts.map +0 -1
@@ -1,3 +1,4 @@
1
+ /// <reference types="prosemirror-model" />
1
2
  import { Ctx } from '@milkdown/core';
2
3
  import { EditorState, Node } from '@milkdown/prose';
3
4
  import { WrappedAction } from './item';
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":";AACA,OAAO,EAAe,GAAG,EAA8B,MAAM,gBAAgB,CAAC;AAC9E,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAEpD,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAGvC,aAAK,QAAQ,CAAC,CAAC,IAAI,CAAC,GAAG,IAAI,GAAG,SAAS,CAAC;AAExC,oBAAY,YAAY,GAAG;IACvB,WAAW,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC/B,OAAO,CAAC,EAAE,QAAQ,CAAC,aAAa,EAAE,CAAC,CAAC;CACvC,CAAC;AAEF,oBAAY,yBAAyB,GAAG;IACpC,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,OAAO,CAAC;IACpB,UAAU,EAAE,IAAI,CAAC;IACjB,KAAK,EAAE,WAAW,CAAC;CACtB,CAAC;AAEF,oBAAY,mBAAmB,GAAG,CAAC,MAAM,EAAE,yBAAyB,KAAK,QAAQ,CAAC,YAAY,CAAC,CAAC;AAEhG,oBAAY,MAAM,GAAG,CAAC,GAAG,EAAE,GAAG,KAAK,mBAAmB,CAAC;AAEvD,eAAO,MAAM,cAAc,QAAS,GAAG,qBAAgB,aAAa,EAuFnE,CAAC;AAEF,eAAO,MAAM,aAAa,EAAE,MAqB3B,CAAC"}
package/lib/index.d.ts CHANGED
@@ -1 +1,25 @@
1
- export * from './src/index'
1
+ import { AtomList } from '@milkdown/utils';
2
+ import type { Config } from './config';
3
+ export type { Config, StatusConfig, StatusConfigBuilder, StatusConfigBuilderParams } from './config';
4
+ export { defaultActions, defaultConfig } from './config';
5
+ export { createDropdownItem } from './utility';
6
+ export declare type Options = {
7
+ config: Config;
8
+ };
9
+ export declare const slashPlugin: import("@milkdown/utils/lib/types").WithExtend<string, Options, {
10
+ [x: string]: import("prosemirror-model").NodeType<any>;
11
+ } & {
12
+ [x: string]: import("prosemirror-model").MarkType<any>;
13
+ }, {
14
+ schema?: ((ctx: import("@milkdown/core").Ctx) => {
15
+ node?: Record<string, import("@milkdown/core").NodeSchema> | undefined;
16
+ mark?: Record<string, import("@milkdown/core").MarkSchema> | undefined;
17
+ }) | undefined;
18
+ view?: ((ctx: import("@milkdown/core").Ctx) => Partial<{
19
+ [x: string]: import("@milkdown/prose").NodeViewFactory;
20
+ } & {
21
+ [x: string]: import("@milkdown/prose").MarkViewFactory;
22
+ }>) | undefined;
23
+ }>;
24
+ export declare const slash: AtomList<import("@milkdown/utils/lib/types").Metadata<import("@milkdown/utils/lib/types").GetPlugin<string, Options>> & import("@milkdown/core").MilkdownPlugin>;
25
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAgB,MAAM,iBAAiB,CAAC;AAEzD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAIvC,YAAY,EAAE,MAAM,EAAE,YAAY,EAAE,mBAAmB,EAAE,yBAAyB,EAAE,MAAM,UAAU,CAAC;AACrG,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzD,OAAO,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAE/C,oBAAY,OAAO,GAAG;IAClB,MAAM,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,eAAO,MAAM,WAAW;;;;;;;;;;;;;;EAYtB,CAAC;AAEH,eAAO,MAAM,KAAK,kKAAmC,CAAC"}
package/lib/index.es.js CHANGED
@@ -14,22 +14,23 @@ var __objRest = (source, exclude) => {
14
14
  return target;
15
15
  };
16
16
  import { createPlugin, AtomList } from "@milkdown/utils";
17
- import { schemaCtx, themeToolCtx, commandsCtx } from "@milkdown/core";
17
+ import { ThemeSize, ThemeColor, ThemeBorder, ThemeShadow, ThemeScrollbar, ThemeFont, ThemeIcon, schemaCtx, themeManagerCtx, commandsCtx } from "@milkdown/core";
18
18
  import { findParentNode, DecorationSet, Decoration, calculateNodePosition, Plugin, PluginKey } from "@milkdown/prose";
19
19
  import scrollIntoView from "smooth-scroll-into-view-if-needed";
20
- const itemStyle = ({ font, palette }, { css }) => {
20
+ const itemStyle = (themeManager, { css }) => {
21
+ const palette = (color, opacity = 1) => themeManager.get(ThemeColor, [color, opacity]);
21
22
  return css`
22
23
  .slash-dropdown-item {
23
24
  display: flex;
24
- gap: 2rem;
25
- height: 3rem;
26
- padding: 0 1rem;
25
+ gap: 2em;
26
+ height: 3.4286em;
27
+ padding: 0 1em;
27
28
  align-items: center;
28
29
  justify-content: flex-start;
29
30
  cursor: pointer;
30
- line-height: 2;
31
- font-family: ${font.typography};
32
- font-size: 0.875rem;
31
+ line-height: 3.4286em;
32
+ font-family: ${themeManager.get(ThemeFont, "typography")};
33
+ font-size: 0.875em;
33
34
 
34
35
  transition: all 0.2s ease-in-out;
35
36
 
@@ -52,52 +53,54 @@ const itemStyle = ({ font, palette }, { css }) => {
52
53
  }
53
54
  `;
54
55
  };
55
- const injectStyle = (themeTool, emotion) => {
56
- var _a, _b, _c;
57
- const { mixin, size, palette } = themeTool;
58
- const style = emotion.css`
59
- width: 20.5rem;
60
- max-height: 20.5rem;
56
+ const injectStyle = (themeManager, emotion) => {
57
+ const palette = (color, opacity = 1) => themeManager.get(ThemeColor, [color, opacity]);
58
+ return emotion.css`
59
+ width: 20.5em;
60
+ max-height: 20.5em;
61
61
  overflow-y: auto;
62
- ${(_a = mixin.border) == null ? void 0 : _a.call(mixin)};
63
- border-radius: ${size.radius};
62
+ border-radius: ${themeManager.get(ThemeSize, "radius")};
64
63
  position: absolute;
65
64
  background: ${palette("surface")};
66
65
 
67
- ${(_b = mixin.shadow) == null ? void 0 : _b.call(mixin)};
66
+ ${themeManager.get(ThemeBorder, void 0)}
67
+ ${themeManager.get(ThemeShadow, void 0)}
68
+ ${themeManager.get(ThemeScrollbar, void 0)}
68
69
 
69
70
  &.hide {
70
71
  display: none;
71
72
  }
72
73
 
73
- ${(_c = mixin.scrollbar) == null ? void 0 : _c.call(mixin)};
74
-
75
- ${itemStyle(themeTool, emotion)}
74
+ ${itemStyle(themeManager, emotion)}
76
75
  `;
77
- return style;
78
76
  };
79
77
  const createDropdown = (utils) => {
80
78
  const div = document.createElement("div");
81
79
  div.setAttribute("role", "listbox");
82
80
  div.setAttribute("tabindex", "-1");
83
- const style = utils.getStyle(injectStyle);
84
- if (style) {
85
- div.classList.add(style);
86
- }
81
+ utils.themeManager.onFlush(() => {
82
+ const style = utils.getStyle(injectStyle);
83
+ if (style) {
84
+ div.classList.add(style);
85
+ }
86
+ });
87
87
  div.classList.add("slash-dropdown", "hide");
88
88
  return div;
89
89
  };
90
- const createDropdownItem = (themeTool, text, icon, options) => {
90
+ const createDropdownItem = (themeManager, text, icon, options) => {
91
91
  var _a;
92
92
  const textClassName = (_a = options == null ? void 0 : options.textClassName) != null ? _a : "text";
93
93
  const div = document.createElement("div");
94
94
  div.setAttribute("role", "option");
95
95
  div.classList.add("slash-dropdown-item");
96
- const iconSpan = themeTool.slots.icon(icon);
96
+ const iconSpan = themeManager.get(ThemeIcon, icon);
97
+ if (!iconSpan) {
98
+ throw new Error("icon not found");
99
+ }
97
100
  const textSpan = document.createElement("span");
98
101
  textSpan.textContent = text;
99
102
  textSpan.className = textClassName;
100
- div.appendChild(iconSpan);
103
+ div.appendChild(iconSpan.dom);
101
104
  div.appendChild(textSpan);
102
105
  return div;
103
106
  };
@@ -120,77 +123,77 @@ const defaultActions = (ctx, input = "/") => {
120
123
  const actions = [
121
124
  {
122
125
  id: "h1",
123
- dom: createDropdownItem(ctx.get(themeToolCtx), "Large Heading", "h1"),
126
+ dom: createDropdownItem(ctx.get(themeManagerCtx), "Large Heading", "h1"),
124
127
  command: () => ctx.get(commandsCtx).callByName("TurnIntoHeading", 1),
125
128
  keyword: ["h1", "large heading"],
126
129
  typeName: "heading"
127
130
  },
128
131
  {
129
132
  id: "h2",
130
- dom: createDropdownItem(ctx.get(themeToolCtx), "Medium Heading", "h2"),
133
+ dom: createDropdownItem(ctx.get(themeManagerCtx), "Medium Heading", "h2"),
131
134
  command: () => ctx.get(commandsCtx).callByName("TurnIntoHeading", 2),
132
135
  keyword: ["h2", "medium heading"],
133
136
  typeName: "heading"
134
137
  },
135
138
  {
136
139
  id: "h3",
137
- dom: createDropdownItem(ctx.get(themeToolCtx), "Small Heading", "h3"),
140
+ dom: createDropdownItem(ctx.get(themeManagerCtx), "Small Heading", "h3"),
138
141
  command: () => ctx.get(commandsCtx).callByName("TurnIntoHeading", 3),
139
142
  keyword: ["h3", "small heading"],
140
143
  typeName: "heading"
141
144
  },
142
145
  {
143
146
  id: "bulletList",
144
- dom: createDropdownItem(ctx.get(themeToolCtx), "Bullet List", "bulletList"),
147
+ dom: createDropdownItem(ctx.get(themeManagerCtx), "Bullet List", "bulletList"),
145
148
  command: () => ctx.get(commandsCtx).callByName("WrapInBulletList"),
146
149
  keyword: ["bullet list", "ul"],
147
150
  typeName: "bullet_list"
148
151
  },
149
152
  {
150
153
  id: "orderedList",
151
- dom: createDropdownItem(ctx.get(themeToolCtx), "Ordered List", "orderedList"),
154
+ dom: createDropdownItem(ctx.get(themeManagerCtx), "Ordered List", "orderedList"),
152
155
  command: () => ctx.get(commandsCtx).callByName("WrapInOrderedList"),
153
156
  keyword: ["ordered list", "ol"],
154
157
  typeName: "ordered_list"
155
158
  },
156
159
  {
157
160
  id: "taskList",
158
- dom: createDropdownItem(ctx.get(themeToolCtx), "Task List", "taskList"),
161
+ dom: createDropdownItem(ctx.get(themeManagerCtx), "Task List", "taskList"),
159
162
  command: () => ctx.get(commandsCtx).callByName("TurnIntoTaskList"),
160
163
  keyword: ["task list", "task"],
161
164
  typeName: "task_list_item"
162
165
  },
163
166
  {
164
167
  id: "image",
165
- dom: createDropdownItem(ctx.get(themeToolCtx), "Image", "image"),
168
+ dom: createDropdownItem(ctx.get(themeManagerCtx), "Image", "image"),
166
169
  command: () => ctx.get(commandsCtx).callByName("InsertImage"),
167
170
  keyword: ["image"],
168
171
  typeName: "image"
169
172
  },
170
173
  {
171
174
  id: "blockquote",
172
- dom: createDropdownItem(ctx.get(themeToolCtx), "Quote", "quote"),
175
+ dom: createDropdownItem(ctx.get(themeManagerCtx), "Quote", "quote"),
173
176
  command: () => ctx.get(commandsCtx).callByName("WrapInBlockquote"),
174
177
  keyword: ["quote", "blockquote"],
175
178
  typeName: "blockquote"
176
179
  },
177
180
  {
178
181
  id: "table",
179
- dom: createDropdownItem(ctx.get(themeToolCtx), "Table", "table"),
182
+ dom: createDropdownItem(ctx.get(themeManagerCtx), "Table", "table"),
180
183
  command: () => ctx.get(commandsCtx).callByName("InsertTable"),
181
184
  keyword: ["table"],
182
185
  typeName: "table"
183
186
  },
184
187
  {
185
188
  id: "code",
186
- dom: createDropdownItem(ctx.get(themeToolCtx), "Code Fence", "code"),
189
+ dom: createDropdownItem(ctx.get(themeManagerCtx), "Code Fence", "code"),
187
190
  command: () => ctx.get(commandsCtx).callByName("TurnIntoCodeFence"),
188
191
  keyword: ["code"],
189
192
  typeName: "fence"
190
193
  },
191
194
  {
192
195
  id: "divider",
193
- dom: createDropdownItem(ctx.get(themeToolCtx), "Divide Line", "divider"),
196
+ dom: createDropdownItem(ctx.get(themeManagerCtx), "Divide Line", "divider"),
194
197
  command: () => ctx.get(commandsCtx).callByName("InsertHr"),
195
198
  keyword: ["divider", "hr"],
196
199
  typeName: "hr"
@@ -220,28 +223,30 @@ const defaultConfig = (ctx) => {
220
223
  return null;
221
224
  };
222
225
  };
223
- const createEmptyStyle = ({ font, palette }, { css }) => css`
224
- position: relative;
225
- &::before {
226
- position: absolute;
227
- cursor: text;
228
- font-family: ${font.typography};
229
- font-size: 0.875rem;
230
- color: ${palette("neutral", 0.6)};
231
- content: attr(data-text);
232
- height: 100%;
233
- display: flex;
234
- align-items: center;
235
- }
236
- `;
226
+ const createEmptyStyle = (themeManager, { css }) => {
227
+ const palette = (color, opacity = 1) => themeManager.get(ThemeColor, [color, opacity]);
228
+ const typography = themeManager.get(ThemeFont, "typography");
229
+ return css`
230
+ position: relative;
231
+ &::before {
232
+ position: absolute;
233
+ cursor: text;
234
+ font-family: ${typography};
235
+ font-size: 0.875em;
236
+ color: ${palette("neutral", 0.6)};
237
+ content: attr(data-text);
238
+ height: 100%;
239
+ display: flex;
240
+ align-items: center;
241
+ }
242
+ `;
243
+ };
237
244
  const createSlashStyle = (_, { css }) => css`
238
245
  &::before {
239
- left: 0.5rem;
246
+ left: 0.5em;
240
247
  }
241
248
  `;
242
249
  const createProps = (status, utils) => {
243
- const emptyStyle = utils.getStyle(createEmptyStyle);
244
- const slashStyle = utils.getStyle(createSlashStyle);
245
250
  return {
246
251
  handleKeyDown: (_, event) => {
247
252
  if (status.isEmpty()) {
@@ -285,6 +290,8 @@ const createProps = (status, utils) => {
285
290
  })
286
291
  ]);
287
292
  };
293
+ const emptyStyle = utils.getStyle(createEmptyStyle);
294
+ const slashStyle = utils.getStyle(createSlashStyle);
288
295
  if (actions.length) {
289
296
  return createDecoration(placeholder, [emptyStyle, slashStyle, "empty-node", "is-slash"]);
290
297
  }
@@ -331,7 +338,9 @@ const renderDropdown = (status, dropdownElement, listeners) => {
331
338
  child.removeEventListener("mouseenter", listeners.mouseEnter);
332
339
  child.removeEventListener("mouseleave", listeners.mouseLeave);
333
340
  });
334
- dropdownElement.textContent = "";
341
+ while (dropdownElement.firstChild) {
342
+ dropdownElement.firstChild.remove();
343
+ }
335
344
  actions.forEach(({ $ }) => {
336
345
  $.classList.remove("active");
337
346
  $.addEventListener("mouseenter", listeners.mouseEnter);
@@ -471,7 +480,7 @@ const calculatePosition = (view, dropdownElement) => {
471
480
  if (left < 0) {
472
481
  left = 0;
473
482
  }
474
- if (window.innerHeight - selected.bottom < target.height) {
483
+ if (parent.height + parent.top - selected.bottom < target.height) {
475
484
  top = selected.top - parent.top - target.height - 14 + $editor.scrollTop;
476
485
  }
477
486
  return [top, left];
@@ -1 +1 @@
1
- {"version":3,"file":"index.es.js","sources":["../src/style.ts","../src/utility.ts","../src/config.ts","../src/prose-plugin/props.ts","../src/item.ts","../src/prose-plugin/status.ts","../src/prose-plugin/dropdown.ts","../src/prose-plugin/input.ts","../src/prose-plugin/view.ts","../src/prose-plugin/index.ts","../src/index.ts"],"sourcesContent":["/* Copyright 2021, Milkdown by Mirone. */\nimport { Emotion, ThemeTool } from '@milkdown/core';\n\nconst itemStyle = ({ font, palette }: ThemeTool, { css }: Emotion) => {\n return css`\n .slash-dropdown-item {\n display: flex;\n gap: 2rem;\n height: 3rem;\n padding: 0 1rem;\n align-items: center;\n justify-content: flex-start;\n cursor: pointer;\n line-height: 2;\n font-family: ${font.typography};\n font-size: 0.875rem;\n\n transition: all 0.2s ease-in-out;\n\n &,\n .icon {\n color: ${palette('neutral', 0.87)};\n transition: all 0.2s ease-in-out;\n }\n\n &.hide {\n display: none;\n }\n\n &.active {\n background: ${palette('secondary', 0.12)};\n &,\n .icon {\n color: ${palette('primary')};\n }\n }\n `;\n};\n\nexport const injectStyle = (themeTool: ThemeTool, emotion: Emotion) => {\n const { mixin, size, palette } = themeTool;\n const style = emotion.css`\n width: 20.5rem;\n max-height: 20.5rem;\n overflow-y: auto;\n ${mixin.border?.()};\n border-radius: ${size.radius};\n position: absolute;\n background: ${palette('surface')};\n\n ${mixin.shadow?.()};\n\n &.hide {\n display: none;\n }\n\n ${mixin.scrollbar?.()};\n\n ${itemStyle(themeTool, emotion)}\n `;\n return style;\n};\n","/* Copyright 2021, Milkdown by Mirone. */\nimport type { ThemeTool } from '@milkdown/core';\nimport type { Icon } from '@milkdown/design-system';\nimport type { Command, Node } from '@milkdown/prose';\nimport type { Utils } from '@milkdown/utils';\n\nimport { injectStyle } from './style';\n\nexport const createDropdown = (utils: Utils) => {\n const div = document.createElement('div');\n div.setAttribute('role', 'listbox');\n div.setAttribute('tabindex', '-1');\n const style = utils.getStyle(injectStyle);\n\n if (style) {\n div.classList.add(style);\n }\n\n div.classList.add('slash-dropdown', 'hide');\n\n return div;\n};\n\ntype ItemOptions = {\n textClassName: string;\n};\nexport const createDropdownItem = (themeTool: ThemeTool, text: string, icon: Icon, options?: Partial<ItemOptions>) => {\n const textClassName = options?.textClassName ?? 'text';\n\n const div = document.createElement('div');\n div.setAttribute('role', 'option');\n div.classList.add('slash-dropdown-item');\n\n const iconSpan = themeTool.slots.icon(icon);\n\n const textSpan = document.createElement('span');\n textSpan.textContent = text;\n textSpan.className = textClassName;\n\n div.appendChild(iconSpan);\n div.appendChild(textSpan);\n\n return div;\n};\n\nexport const getDepth = (node: Node) => {\n let cur = node;\n let depth = 0;\n while (cur.childCount) {\n cur = cur.child(0);\n depth += 1;\n }\n\n return depth;\n};\n\nconst cleanUp: Command = (state, dispatch) => {\n const { selection } = state;\n const { $from } = selection;\n const tr = state.tr.deleteRange($from.start(), $from.pos);\n dispatch?.(tr);\n return false;\n};\n\nexport const cleanUpAndCreateNode =\n (createCommand: () => void): Command =>\n (state, dispatch, view) => {\n if (view) {\n cleanUp(state, dispatch, view);\n createCommand();\n }\n return true;\n };\n","/* Copyright 2021, Milkdown by Mirone. */\nimport { commandsCtx, Ctx, schemaCtx, themeToolCtx } from '@milkdown/core';\nimport { EditorState, Node } from '@milkdown/prose';\n\nimport { WrappedAction } from './item';\nimport { createDropdownItem } from './utility';\n\ntype Nullable<T> = T | null | undefined;\n\nexport type StatusConfig = {\n placeholder?: Nullable<string>;\n actions?: Nullable<WrappedAction[]>;\n};\n\nexport type StatusConfigBuilderParams = {\n content: string;\n isTopLevel: boolean;\n parentNode: Node;\n state: EditorState;\n};\n\nexport type StatusConfigBuilder = (params: StatusConfigBuilderParams) => Nullable<StatusConfig>;\n\nexport type Config = (ctx: Ctx) => StatusConfigBuilder;\n\nexport const defaultActions = (ctx: Ctx, input = '/'): WrappedAction[] => {\n const { nodes } = ctx.get(schemaCtx);\n const actions: Array<WrappedAction & { keyword: string[]; typeName: string }> = [\n {\n id: 'h1',\n dom: createDropdownItem(ctx.get(themeToolCtx), 'Large Heading', 'h1'),\n command: () => ctx.get(commandsCtx).callByName('TurnIntoHeading', 1),\n keyword: ['h1', 'large heading'],\n typeName: 'heading',\n },\n {\n id: 'h2',\n dom: createDropdownItem(ctx.get(themeToolCtx), 'Medium Heading', 'h2'),\n command: () => ctx.get(commandsCtx).callByName('TurnIntoHeading', 2),\n keyword: ['h2', 'medium heading'],\n typeName: 'heading',\n },\n {\n id: 'h3',\n dom: createDropdownItem(ctx.get(themeToolCtx), 'Small Heading', 'h3'),\n command: () => ctx.get(commandsCtx).callByName('TurnIntoHeading', 3),\n keyword: ['h3', 'small heading'],\n typeName: 'heading',\n },\n {\n id: 'bulletList',\n dom: createDropdownItem(ctx.get(themeToolCtx), 'Bullet List', 'bulletList'),\n command: () => ctx.get(commandsCtx).callByName('WrapInBulletList'),\n keyword: ['bullet list', 'ul'],\n typeName: 'bullet_list',\n },\n {\n id: 'orderedList',\n dom: createDropdownItem(ctx.get(themeToolCtx), 'Ordered List', 'orderedList'),\n command: () => ctx.get(commandsCtx).callByName('WrapInOrderedList'),\n keyword: ['ordered list', 'ol'],\n typeName: 'ordered_list',\n },\n {\n id: 'taskList',\n dom: createDropdownItem(ctx.get(themeToolCtx), 'Task List', 'taskList'),\n command: () => ctx.get(commandsCtx).callByName('TurnIntoTaskList'),\n keyword: ['task list', 'task'],\n typeName: 'task_list_item',\n },\n {\n id: 'image',\n dom: createDropdownItem(ctx.get(themeToolCtx), 'Image', 'image'),\n command: () => ctx.get(commandsCtx).callByName('InsertImage'),\n keyword: ['image'],\n typeName: 'image',\n },\n {\n id: 'blockquote',\n dom: createDropdownItem(ctx.get(themeToolCtx), 'Quote', 'quote'),\n command: () => ctx.get(commandsCtx).callByName('WrapInBlockquote'),\n keyword: ['quote', 'blockquote'],\n typeName: 'blockquote',\n },\n {\n id: 'table',\n dom: createDropdownItem(ctx.get(themeToolCtx), 'Table', 'table'),\n command: () => ctx.get(commandsCtx).callByName('InsertTable'),\n keyword: ['table'],\n typeName: 'table',\n },\n {\n id: 'code',\n dom: createDropdownItem(ctx.get(themeToolCtx), 'Code Fence', 'code'),\n command: () => ctx.get(commandsCtx).callByName('TurnIntoCodeFence'),\n keyword: ['code'],\n typeName: 'fence',\n },\n {\n id: 'divider',\n dom: createDropdownItem(ctx.get(themeToolCtx), 'Divide Line', 'divider'),\n command: () => ctx.get(commandsCtx).callByName('InsertHr'),\n keyword: ['divider', 'hr'],\n typeName: 'hr',\n },\n ];\n\n const userInput = input.slice(1).toLocaleLowerCase();\n\n return actions\n .filter((action) => !!nodes[action.typeName] && action.keyword.some((keyword) => keyword.includes(userInput)))\n .map(({ keyword, typeName, ...action }) => action);\n};\n\nexport const defaultConfig: Config = (ctx) => {\n return ({ content, isTopLevel }) => {\n if (!isTopLevel) return null;\n\n if (!content) {\n return { placeholder: 'Type / to use the slash commands...' };\n }\n\n if (content.startsWith('/')) {\n return content === '/'\n ? {\n placeholder: 'Type to filter...',\n actions: defaultActions(ctx),\n }\n : {\n actions: defaultActions(ctx, content),\n };\n }\n\n return null;\n };\n};\n","/* Copyright 2021, Milkdown by Mirone. */\nimport { Emotion, ThemeTool } from '@milkdown/core';\nimport { Decoration, DecorationSet, EditorState, EditorView, findParentNode } from '@milkdown/prose';\nimport { Utils } from '@milkdown/utils';\n\nimport type { Status } from './status';\n\nexport type Props = ReturnType<typeof createProps>;\n\nconst createEmptyStyle = ({ font, palette }: ThemeTool, { css }: Emotion) => css`\n position: relative;\n &::before {\n position: absolute;\n cursor: text;\n font-family: ${font.typography};\n font-size: 0.875rem;\n color: ${palette('neutral', 0.6)};\n content: attr(data-text);\n height: 100%;\n display: flex;\n align-items: center;\n }\n`;\n\nconst createSlashStyle = (_: ThemeTool, { css }: Emotion) => css`\n &::before {\n left: 0.5rem;\n }\n`;\n\nexport const createProps = (status: Status, utils: Utils) => {\n const emptyStyle = utils.getStyle(createEmptyStyle);\n const slashStyle = utils.getStyle(createSlashStyle);\n\n return {\n handleKeyDown: (_: EditorView, event: Event) => {\n if (status.isEmpty()) {\n return false;\n }\n if (!(event instanceof KeyboardEvent)) {\n return false;\n }\n\n if (!['ArrowUp', 'ArrowDown', 'Enter'].includes(event.key)) {\n return false;\n }\n\n return true;\n },\n decorations: (state: EditorState) => {\n const paragraph = findParentNode(({ type }) => type.name === 'paragraph')(state.selection);\n const uploadPlugin = state.plugins.find(\n (x) => (x as unknown as { key: string }).key === 'MILKDOWN_PLUGIN_UPLOAD$',\n );\n const decorations: DecorationSet = uploadPlugin?.getState(state);\n if (decorations != null && decorations.find(state.selection.from, state.selection.to).length > 0) {\n status.clear();\n return;\n }\n\n if (\n !paragraph ||\n paragraph.node.childCount > 1 ||\n state.selection.$from.parentOffset !== paragraph.node.textContent.length ||\n (paragraph.node.firstChild && paragraph.node.firstChild.type.name !== 'text')\n ) {\n status.clear();\n return;\n }\n\n const { placeholder, actions } = status.update({\n parentNode: state.selection.$from.node(state.selection.$from.depth - 1),\n isTopLevel: state.selection.$from.depth === 1,\n content: paragraph.node.textContent,\n state,\n });\n\n if (!placeholder) {\n return null;\n }\n\n const createDecoration = (text: string, className: (string | undefined)[]) => {\n const pos = paragraph.pos;\n return DecorationSet.create(state.doc, [\n Decoration.node(pos, pos + paragraph.node.nodeSize, {\n class: className.filter((x) => x).join(' '),\n 'data-text': text,\n }),\n ]);\n };\n\n if (actions.length) {\n return createDecoration(placeholder, [emptyStyle, slashStyle, 'empty-node', 'is-slash']);\n }\n\n return createDecoration(placeholder, [emptyStyle, 'empty-node']);\n },\n };\n};\n","/* Copyright 2021, Milkdown by Mirone. */\nimport type { Command } from '@milkdown/prose';\n\nimport { cleanUpAndCreateNode } from './utility';\n\nexport type Action = {\n id: string;\n $: HTMLElement;\n command: Command;\n};\n\nexport type WrappedAction = Pick<Action, 'id'> & {\n command: () => void;\n dom: HTMLElement;\n};\n\nexport const transformAction = (action: WrappedAction): Action => ({\n id: action.id,\n $: action.dom,\n command: cleanUpAndCreateNode(action.command),\n});\n","/* Copyright 2021, Milkdown by Mirone. */\nimport { StatusConfigBuilder, StatusConfigBuilderParams } from '..';\nimport { Action, transformAction } from '../item';\n\nexport type StatusCtx = {\n placeholder: string | null;\n actions: Action[];\n};\n\nconst createStatusCtx = (): StatusCtx => {\n return {\n placeholder: null,\n actions: [],\n };\n};\n\nexport type Status = ReturnType<typeof createStatus>;\n\nexport const createStatus = (builder: StatusConfigBuilder) => {\n const statusCtx = createStatusCtx();\n\n return {\n get: () => statusCtx,\n clear: () => {\n statusCtx.placeholder = null;\n statusCtx.actions = [];\n },\n update: (builderParams: StatusConfigBuilderParams) => {\n const config = builder(builderParams);\n statusCtx.placeholder = config?.placeholder ?? null;\n statusCtx.actions = (config?.actions ?? []).map(transformAction);\n return statusCtx;\n },\n isEmpty: () => statusCtx.actions.length === 0,\n };\n};\n","/* Copyright 2021, Milkdown by Mirone. */\nimport scrollIntoView from 'smooth-scroll-into-view-if-needed';\n\nimport { Status } from './status';\n\ntype Listeners = {\n mouseEnter: EventListener;\n mouseLeave: EventListener;\n};\n\nexport const renderDropdown = (status: Status, dropdownElement: HTMLElement, listeners: Listeners): boolean => {\n const { actions } = status.get();\n\n if (!actions.length) {\n dropdownElement.classList.add('hide');\n return false;\n }\n\n dropdownElement.childNodes.forEach((child) => {\n child.removeEventListener('mouseenter', listeners.mouseEnter);\n child.removeEventListener('mouseleave', listeners.mouseLeave);\n });\n\n // Reset dropdownElement children\n dropdownElement.textContent = '';\n\n actions.forEach(({ $ }) => {\n $.classList.remove('active');\n $.addEventListener('mouseenter', listeners.mouseEnter);\n $.addEventListener('mouseleave', listeners.mouseLeave);\n dropdownElement.appendChild($);\n });\n\n dropdownElement.classList.remove('hide');\n\n const first$ = actions[0];\n if (first$) {\n first$.$.classList.add('active');\n requestAnimationFrame(() => {\n scrollIntoView(first$.$, {\n scrollMode: 'if-needed',\n block: 'nearest',\n inline: 'nearest',\n });\n });\n }\n\n return true;\n};\n","/* Copyright 2021, Milkdown by Mirone. */\n\nimport { EditorView } from '@milkdown/prose';\nimport scrollIntoView from 'smooth-scroll-into-view-if-needed';\n\nimport { Status } from './status';\n\nexport const createMouseManager = () => {\n let mouseLock = false;\n\n return {\n isLock: () => mouseLock,\n lock: () => {\n mouseLock = true;\n },\n unlock: () => {\n mouseLock = false;\n },\n };\n};\nexport type MouseManager = ReturnType<typeof createMouseManager>;\n\nexport const handleMouseMove = (mouseManager: MouseManager) => () => {\n mouseManager.unlock();\n};\n\nexport const handleMouseEnter = (status: Status, mouseManager: MouseManager) => (e: MouseEvent) => {\n if (mouseManager.isLock()) return;\n const { actions } = status.get();\n const active = actions.findIndex((x) => x.$.classList.contains('active'));\n const active$ = actions[active];\n if (active$ && active >= 0) {\n active$.$.classList.remove('active');\n }\n const { target } = e;\n if (!(target instanceof HTMLElement)) return;\n target.classList.add('active');\n};\n\nexport const handleMouseLeave = () => (e: MouseEvent) => {\n const { target } = e;\n if (!(target instanceof HTMLElement)) return;\n target.classList.remove('active');\n};\n\nexport const handleClick =\n (status: Status, view: EditorView, dropdownElement: HTMLElement) =>\n (e: Event): void => {\n const { target } = e;\n if (!(target instanceof HTMLElement)) return;\n if (!view) return;\n\n const stop = () => {\n e.stopPropagation();\n e.preventDefault();\n };\n\n const { actions } = status.get();\n\n const el = Object.values(actions).find(({ $ }) => $.contains(target));\n if (!el) {\n if (status.isEmpty()) return;\n\n status.clear();\n dropdownElement.classList.add('hide');\n stop();\n\n return;\n }\n\n stop();\n el.command(view.state, view.dispatch, view);\n };\n\nexport const handleKeydown =\n (status: Status, view: EditorView, dropdownElement: HTMLElement, mouseManager: MouseManager) => (e: Event) => {\n if (!(e instanceof KeyboardEvent)) return;\n if (!mouseManager.isLock()) mouseManager.lock();\n\n const { key } = e;\n if (status.isEmpty()) return;\n if (!['ArrowDown', 'ArrowUp', 'Enter', 'Escape'].includes(key)) return;\n\n const { actions } = status.get();\n\n let active = actions.findIndex(({ $ }) => $.classList.contains('active'));\n if (active < 0) active = 0;\n\n const moveActive = (next: number) => {\n const active$ = actions[active];\n const next$ = actions[next];\n if (!active$ || !next$) return;\n active$.$.classList.remove('active');\n next$.$.classList.add('active');\n scrollIntoView(next$.$, {\n scrollMode: 'if-needed',\n block: 'nearest',\n inline: 'nearest',\n });\n };\n\n if (key === 'ArrowDown') {\n const next = active === actions.length - 1 ? 0 : active + 1;\n\n moveActive(next);\n return;\n }\n\n if (key === 'ArrowUp') {\n const next = active === 0 ? actions.length - 1 : active - 1;\n\n moveActive(next);\n return;\n }\n\n if (key === 'Escape') {\n if (status.isEmpty()) return;\n\n status.clear();\n dropdownElement.classList.add('hide');\n return;\n }\n\n const active$ = actions[active];\n if (!active$) return;\n active$.command(view.state, view.dispatch, view);\n active$.$.classList.remove('active');\n };\n","/* Copyright 2021, Milkdown by Mirone. */\nimport { calculateNodePosition, EditorView } from '@milkdown/prose';\nimport { Utils } from '@milkdown/utils';\n\nimport { createDropdown } from '../utility';\nimport { renderDropdown } from './dropdown';\nimport {\n createMouseManager,\n handleClick,\n handleKeydown,\n handleMouseEnter,\n handleMouseLeave,\n handleMouseMove,\n} from './input';\nimport { Status } from './status';\n\nconst calculatePosition = (view: EditorView, dropdownElement: HTMLElement) => {\n calculateNodePosition(view, dropdownElement, (selected, target, parent) => {\n const $editor = dropdownElement.parentElement;\n if (!$editor) {\n throw new Error();\n }\n\n let left = selected.left - parent.left;\n let top = selected.bottom - parent.top + 14 + $editor.scrollTop;\n\n if (left < 0) {\n left = 0;\n }\n\n if (window.innerHeight - selected.bottom < target.height) {\n top = selected.top - parent.top - target.height - 14 + $editor.scrollTop;\n }\n return [top, left];\n });\n};\n\nexport const createView = (status: Status, view: EditorView, utils: Utils) => {\n const wrapper = view.dom.parentNode;\n if (!wrapper) return {};\n\n const dropdownElement = createDropdown(utils);\n const mouseManager = createMouseManager();\n wrapper.appendChild(dropdownElement);\n\n const _mouseMove = handleMouseMove(mouseManager);\n const _mouseDown = handleClick(status, view, dropdownElement);\n const _keydown = handleKeydown(status, view, dropdownElement, mouseManager);\n const _mouseEnter = handleMouseEnter(status, mouseManager);\n const _mouseLeave = handleMouseLeave();\n\n wrapper.addEventListener('mousemove', _mouseMove);\n wrapper.addEventListener('mousedown', _mouseDown);\n wrapper.addEventListener('keydown', _keydown);\n\n return {\n update: (view: EditorView) => {\n const show = renderDropdown(status, dropdownElement, {\n mouseEnter: _mouseEnter as EventListener,\n mouseLeave: _mouseLeave as EventListener,\n });\n\n if (!show) return;\n\n calculatePosition(view, dropdownElement);\n },\n\n destroy: () => {\n wrapper.removeEventListener('mousemove', _mouseMove);\n wrapper.removeEventListener('mousedown', _mouseDown);\n wrapper.removeEventListener('keydown', _keydown);\n dropdownElement.remove();\n },\n };\n};\n","/* Copyright 2021, Milkdown by Mirone. */\nimport { Plugin, PluginKey } from '@milkdown/prose';\nimport { Utils } from '@milkdown/utils';\n\nimport type { StatusConfigBuilder } from '..';\nimport { createProps } from './props';\nimport { createStatus } from './status';\nimport { createView } from './view';\n\nexport const key = 'MILKDOWN_PLUGIN_SLASH';\n\nexport const createSlashPlugin = (utils: Utils, builder: StatusConfigBuilder) => {\n const status = createStatus(builder);\n\n return new Plugin({\n key: new PluginKey(key),\n props: createProps(status, utils),\n view: (view) => createView(status, view, utils),\n });\n};\n","/* Copyright 2021, Milkdown by Mirone. */\nimport { AtomList, createPlugin } from '@milkdown/utils';\n\nimport type { Config } from './config';\nimport { defaultConfig } from './config';\nimport { createSlashPlugin } from './prose-plugin';\n\nexport type { Config, StatusConfig, StatusConfigBuilder, StatusConfigBuilderParams } from './config';\nexport { defaultActions, defaultConfig } from './config';\nexport { createDropdownItem } from './utility';\n\nexport type Options = {\n config: Config;\n};\n\nexport const slashPlugin = createPlugin<string, Options>((utils, options) => {\n const slashConfig = options?.config ?? defaultConfig;\n\n return {\n prosePlugins: (_, ctx) => {\n const config = slashConfig(ctx);\n\n const plugin = createSlashPlugin(utils, config);\n\n return [plugin];\n },\n };\n});\n\nexport const slash = AtomList.create([slashPlugin()]);\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;AAGA,MAAM,YAAY,CAAC,EAAE,MAAM,WAAsB,EAAE,UAAmB;SAC3D;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,2BAUgB,KAAK;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,yBAOP,QAAQ,WAAW;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,8BASd,QAAQ,aAAa;AAAA;AAAA;AAAA,6BAGtB,QAAQ;AAAA;AAAA;AAAA;AAAA;MAMxB,cAAc,CAAC,WAAsB,YAAqB;;QAC7D,EAAE,OAAO,MAAM,YAAY;QAC3B,QAAQ,QAAQ;AAAA;AAAA;AAAA;AAAA,UAIhB,YAAM,WAAN;AAAA,yBACe,KAAK;AAAA;AAAA,sBAER,QAAQ;AAAA;AAAA,UAEpB,YAAM,WAAN;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,UAMA,YAAM,cAAN;AAAA;AAAA,UAEA,UAAU,WAAW;AAAA;SAEpB;AAAA;MCpDE,iBAAiB,CAAC,UAAiB;QACtC,MAAM,SAAS,cAAc;MAC/B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IAAI,UAAU;AAAA,IACnB,OAAO,YAAY,QAAQ;AAAA,IAC3B,MAAM,CAAC,SAAS,WAAW,QAAQ,MAAM;AAAA;AAAA;MCFpC,cAAc,aAA8B,CAAC,OAAO,YAAY;;QACnE,cAAc,yCAAS,WAAT,YAAmB;SAEhC;AAAA,IACH,cAAc,CAAC,GAAG,QAAQ;YAChB,SAAS,YAAY;YAErB,SAAS,kBAAkB,OAAO;aAEjC,CAAC;AAAA;AAAA;AAAA;MAKP,QAAQ,SAAS,OAAO,CAAC;;"}
1
+ {"version":3,"file":"index.es.js","sources":["../src/style.ts","../src/utility.ts","../src/config.ts","../src/prose-plugin/props.ts","../src/item.ts","../src/prose-plugin/status.ts","../src/prose-plugin/dropdown.ts","../src/prose-plugin/input.ts","../src/prose-plugin/view.ts","../src/prose-plugin/index.ts","../src/index.ts"],"sourcesContent":["/* Copyright 2021, Milkdown by Mirone. */\nimport {\n Color,\n Emotion,\n ThemeBorder,\n ThemeColor,\n ThemeFont,\n ThemeManager,\n ThemeScrollbar,\n ThemeShadow,\n ThemeSize,\n} from '@milkdown/core';\n\nconst itemStyle = (themeManager: ThemeManager, { css }: Emotion) => {\n const palette = (color: Color, opacity = 1) => themeManager.get(ThemeColor, [color, opacity]);\n return css`\n .slash-dropdown-item {\n display: flex;\n gap: 2em;\n height: 3.4286em;\n padding: 0 1em;\n align-items: center;\n justify-content: flex-start;\n cursor: pointer;\n line-height: 3.4286em;\n font-family: ${themeManager.get(ThemeFont, 'typography')};\n font-size: 0.875em;\n\n transition: all 0.2s ease-in-out;\n\n &,\n .icon {\n color: ${palette('neutral', 0.87)};\n transition: all 0.2s ease-in-out;\n }\n\n &.hide {\n display: none;\n }\n\n &.active {\n background: ${palette('secondary', 0.12)};\n &,\n .icon {\n color: ${palette('primary')};\n }\n }\n `;\n};\n\nexport const injectStyle = (themeManager: ThemeManager, emotion: Emotion) => {\n const palette = (color: Color, opacity = 1) => themeManager.get(ThemeColor, [color, opacity]);\n\n return emotion.css`\n width: 20.5em;\n max-height: 20.5em;\n overflow-y: auto;\n border-radius: ${themeManager.get(ThemeSize, 'radius')};\n position: absolute;\n background: ${palette('surface')};\n\n ${themeManager.get(ThemeBorder, undefined)}\n ${themeManager.get(ThemeShadow, undefined)}\n ${themeManager.get(ThemeScrollbar, undefined)}\n\n &.hide {\n display: none;\n }\n\n ${itemStyle(themeManager, emotion)}\n `;\n};\n","/* Copyright 2021, Milkdown by Mirone. */\nimport { ThemeIcon, ThemeManager } from '@milkdown/core';\nimport type { Icon } from '@milkdown/design-system';\nimport type { Command, Node } from '@milkdown/prose';\nimport type { Utils } from '@milkdown/utils';\n\nimport { injectStyle } from './style';\n\nexport const createDropdown = (utils: Utils) => {\n const div = document.createElement('div');\n div.setAttribute('role', 'listbox');\n div.setAttribute('tabindex', '-1');\n utils.themeManager.onFlush(() => {\n const style = utils.getStyle(injectStyle);\n\n if (style) {\n div.classList.add(style);\n }\n });\n\n div.classList.add('slash-dropdown', 'hide');\n\n return div;\n};\n\ntype ItemOptions = {\n textClassName: string;\n};\nexport const createDropdownItem = (\n themeManager: ThemeManager,\n text: string,\n icon: Icon,\n options?: Partial<ItemOptions>,\n) => {\n const textClassName = options?.textClassName ?? 'text';\n\n const div = document.createElement('div');\n div.setAttribute('role', 'option');\n div.classList.add('slash-dropdown-item');\n\n // const iconSpan = themeManager.slots.icon(icon);\n const iconSpan = themeManager.get(ThemeIcon, icon);\n\n if (!iconSpan) {\n throw new Error('icon not found');\n }\n\n const textSpan = document.createElement('span');\n textSpan.textContent = text;\n textSpan.className = textClassName;\n\n div.appendChild(iconSpan.dom);\n div.appendChild(textSpan);\n\n return div;\n};\n\nexport const getDepth = (node: Node) => {\n let cur = node;\n let depth = 0;\n while (cur.childCount) {\n cur = cur.child(0);\n depth += 1;\n }\n\n return depth;\n};\n\nconst cleanUp: Command = (state, dispatch) => {\n const { selection } = state;\n const { $from } = selection;\n const tr = state.tr.deleteRange($from.start(), $from.pos);\n dispatch?.(tr);\n return false;\n};\n\nexport const cleanUpAndCreateNode =\n (createCommand: () => void): Command =>\n (state, dispatch, view) => {\n if (view) {\n cleanUp(state, dispatch, view);\n createCommand();\n }\n return true;\n };\n","/* Copyright 2021, Milkdown by Mirone. */\nimport { commandsCtx, Ctx, schemaCtx, themeManagerCtx } from '@milkdown/core';\nimport { EditorState, Node } from '@milkdown/prose';\n\nimport { WrappedAction } from './item';\nimport { createDropdownItem } from './utility';\n\ntype Nullable<T> = T | null | undefined;\n\nexport type StatusConfig = {\n placeholder?: Nullable<string>;\n actions?: Nullable<WrappedAction[]>;\n};\n\nexport type StatusConfigBuilderParams = {\n content: string;\n isTopLevel: boolean;\n parentNode: Node;\n state: EditorState;\n};\n\nexport type StatusConfigBuilder = (params: StatusConfigBuilderParams) => Nullable<StatusConfig>;\n\nexport type Config = (ctx: Ctx) => StatusConfigBuilder;\n\nexport const defaultActions = (ctx: Ctx, input = '/'): WrappedAction[] => {\n const { nodes } = ctx.get(schemaCtx);\n const actions: Array<WrappedAction & { keyword: string[]; typeName: string }> = [\n {\n id: 'h1',\n dom: createDropdownItem(ctx.get(themeManagerCtx), 'Large Heading', 'h1'),\n command: () => ctx.get(commandsCtx).callByName('TurnIntoHeading', 1),\n keyword: ['h1', 'large heading'],\n typeName: 'heading',\n },\n {\n id: 'h2',\n dom: createDropdownItem(ctx.get(themeManagerCtx), 'Medium Heading', 'h2'),\n command: () => ctx.get(commandsCtx).callByName('TurnIntoHeading', 2),\n keyword: ['h2', 'medium heading'],\n typeName: 'heading',\n },\n {\n id: 'h3',\n dom: createDropdownItem(ctx.get(themeManagerCtx), 'Small Heading', 'h3'),\n command: () => ctx.get(commandsCtx).callByName('TurnIntoHeading', 3),\n keyword: ['h3', 'small heading'],\n typeName: 'heading',\n },\n {\n id: 'bulletList',\n dom: createDropdownItem(ctx.get(themeManagerCtx), 'Bullet List', 'bulletList'),\n command: () => ctx.get(commandsCtx).callByName('WrapInBulletList'),\n keyword: ['bullet list', 'ul'],\n typeName: 'bullet_list',\n },\n {\n id: 'orderedList',\n dom: createDropdownItem(ctx.get(themeManagerCtx), 'Ordered List', 'orderedList'),\n command: () => ctx.get(commandsCtx).callByName('WrapInOrderedList'),\n keyword: ['ordered list', 'ol'],\n typeName: 'ordered_list',\n },\n {\n id: 'taskList',\n dom: createDropdownItem(ctx.get(themeManagerCtx), 'Task List', 'taskList'),\n command: () => ctx.get(commandsCtx).callByName('TurnIntoTaskList'),\n keyword: ['task list', 'task'],\n typeName: 'task_list_item',\n },\n {\n id: 'image',\n dom: createDropdownItem(ctx.get(themeManagerCtx), 'Image', 'image'),\n command: () => ctx.get(commandsCtx).callByName('InsertImage'),\n keyword: ['image'],\n typeName: 'image',\n },\n {\n id: 'blockquote',\n dom: createDropdownItem(ctx.get(themeManagerCtx), 'Quote', 'quote'),\n command: () => ctx.get(commandsCtx).callByName('WrapInBlockquote'),\n keyword: ['quote', 'blockquote'],\n typeName: 'blockquote',\n },\n {\n id: 'table',\n dom: createDropdownItem(ctx.get(themeManagerCtx), 'Table', 'table'),\n command: () => ctx.get(commandsCtx).callByName('InsertTable'),\n keyword: ['table'],\n typeName: 'table',\n },\n {\n id: 'code',\n dom: createDropdownItem(ctx.get(themeManagerCtx), 'Code Fence', 'code'),\n command: () => ctx.get(commandsCtx).callByName('TurnIntoCodeFence'),\n keyword: ['code'],\n typeName: 'fence',\n },\n {\n id: 'divider',\n dom: createDropdownItem(ctx.get(themeManagerCtx), 'Divide Line', 'divider'),\n command: () => ctx.get(commandsCtx).callByName('InsertHr'),\n keyword: ['divider', 'hr'],\n typeName: 'hr',\n },\n ];\n\n const userInput = input.slice(1).toLocaleLowerCase();\n\n return actions\n .filter((action) => !!nodes[action.typeName] && action.keyword.some((keyword) => keyword.includes(userInput)))\n .map(({ keyword, typeName, ...action }) => action);\n};\n\nexport const defaultConfig: Config = (ctx) => {\n return ({ content, isTopLevel }) => {\n if (!isTopLevel) return null;\n\n if (!content) {\n return { placeholder: 'Type / to use the slash commands...' };\n }\n\n if (content.startsWith('/')) {\n return content === '/'\n ? {\n placeholder: 'Type to filter...',\n actions: defaultActions(ctx),\n }\n : {\n actions: defaultActions(ctx, content),\n };\n }\n\n return null;\n };\n};\n","/* Copyright 2021, Milkdown by Mirone. */\nimport { Color, Emotion, ThemeColor, ThemeFont, ThemeManager } from '@milkdown/core';\nimport { Decoration, DecorationSet, EditorState, EditorView, findParentNode } from '@milkdown/prose';\nimport { Utils } from '@milkdown/utils';\n\nimport type { Status } from './status';\n\nexport type Props = ReturnType<typeof createProps>;\n\nconst createEmptyStyle = (themeManager: ThemeManager, { css }: Emotion) => {\n const palette = (color: Color, opacity = 1) => themeManager.get(ThemeColor, [color, opacity]);\n const typography = themeManager.get(ThemeFont, 'typography');\n\n return css`\n position: relative;\n &::before {\n position: absolute;\n cursor: text;\n font-family: ${typography};\n font-size: 0.875em;\n color: ${palette('neutral', 0.6)};\n content: attr(data-text);\n height: 100%;\n display: flex;\n align-items: center;\n }\n `;\n};\n\nconst createSlashStyle = (_: ThemeManager, { css }: Emotion) => css`\n &::before {\n left: 0.5em;\n }\n`;\n\nexport const createProps = (status: Status, utils: Utils) => {\n return {\n handleKeyDown: (_: EditorView, event: Event) => {\n if (status.isEmpty()) {\n return false;\n }\n if (!(event instanceof KeyboardEvent)) {\n return false;\n }\n\n if (!['ArrowUp', 'ArrowDown', 'Enter'].includes(event.key)) {\n return false;\n }\n\n return true;\n },\n decorations: (state: EditorState) => {\n const paragraph = findParentNode(({ type }) => type.name === 'paragraph')(state.selection);\n const uploadPlugin = state.plugins.find(\n (x) => (x as unknown as { key: string }).key === 'MILKDOWN_PLUGIN_UPLOAD$',\n );\n const decorations: DecorationSet = uploadPlugin?.getState(state);\n if (decorations != null && decorations.find(state.selection.from, state.selection.to).length > 0) {\n status.clear();\n return;\n }\n\n if (\n !paragraph ||\n paragraph.node.childCount > 1 ||\n state.selection.$from.parentOffset !== paragraph.node.textContent.length ||\n (paragraph.node.firstChild && paragraph.node.firstChild.type.name !== 'text')\n ) {\n status.clear();\n return;\n }\n\n const { placeholder, actions } = status.update({\n parentNode: state.selection.$from.node(state.selection.$from.depth - 1),\n isTopLevel: state.selection.$from.depth === 1,\n content: paragraph.node.textContent,\n state,\n });\n\n if (!placeholder) {\n return null;\n }\n\n const createDecoration = (text: string, className: (string | undefined)[]) => {\n const pos = paragraph.pos;\n return DecorationSet.create(state.doc, [\n Decoration.node(pos, pos + paragraph.node.nodeSize, {\n class: className.filter((x) => x).join(' '),\n 'data-text': text,\n }),\n ]);\n };\n\n const emptyStyle = utils.getStyle(createEmptyStyle);\n const slashStyle = utils.getStyle(createSlashStyle);\n\n if (actions.length) {\n return createDecoration(placeholder, [emptyStyle, slashStyle, 'empty-node', 'is-slash']);\n }\n\n return createDecoration(placeholder, [emptyStyle, 'empty-node']);\n },\n };\n};\n","/* Copyright 2021, Milkdown by Mirone. */\nimport type { Command } from '@milkdown/prose';\n\nimport { cleanUpAndCreateNode } from './utility';\n\nexport type Action = {\n id: string;\n $: HTMLElement;\n command: Command;\n};\n\nexport type WrappedAction = Pick<Action, 'id'> & {\n command: () => void;\n dom: HTMLElement;\n};\n\nexport const transformAction = (action: WrappedAction): Action => ({\n id: action.id,\n $: action.dom,\n command: cleanUpAndCreateNode(action.command),\n});\n","/* Copyright 2021, Milkdown by Mirone. */\nimport { StatusConfigBuilder, StatusConfigBuilderParams } from '..';\nimport { Action, transformAction } from '../item';\n\nexport type StatusCtx = {\n placeholder: string | null;\n actions: Action[];\n};\n\nconst createStatusCtx = (): StatusCtx => {\n return {\n placeholder: null,\n actions: [],\n };\n};\n\nexport type Status = ReturnType<typeof createStatus>;\n\nexport const createStatus = (builder: StatusConfigBuilder) => {\n const statusCtx = createStatusCtx();\n\n return {\n get: () => statusCtx,\n clear: () => {\n statusCtx.placeholder = null;\n statusCtx.actions = [];\n },\n update: (builderParams: StatusConfigBuilderParams) => {\n const config = builder(builderParams);\n statusCtx.placeholder = config?.placeholder ?? null;\n statusCtx.actions = (config?.actions ?? []).map(transformAction);\n return statusCtx;\n },\n isEmpty: () => statusCtx.actions.length === 0,\n };\n};\n","/* Copyright 2021, Milkdown by Mirone. */\nimport scrollIntoView from 'smooth-scroll-into-view-if-needed';\n\nimport { Status } from './status';\n\ntype Listeners = {\n mouseEnter: EventListener;\n mouseLeave: EventListener;\n};\n\nexport const renderDropdown = (status: Status, dropdownElement: HTMLElement, listeners: Listeners): boolean => {\n const { actions } = status.get();\n\n if (!actions.length) {\n dropdownElement.classList.add('hide');\n return false;\n }\n\n dropdownElement.childNodes.forEach((child) => {\n child.removeEventListener('mouseenter', listeners.mouseEnter);\n child.removeEventListener('mouseleave', listeners.mouseLeave);\n });\n\n while (dropdownElement.firstChild) {\n dropdownElement.firstChild.remove();\n }\n\n actions.forEach(({ $ }) => {\n $.classList.remove('active');\n $.addEventListener('mouseenter', listeners.mouseEnter);\n $.addEventListener('mouseleave', listeners.mouseLeave);\n dropdownElement.appendChild($);\n });\n\n dropdownElement.classList.remove('hide');\n\n const first$ = actions[0];\n if (first$) {\n first$.$.classList.add('active');\n requestAnimationFrame(() => {\n scrollIntoView(first$.$, {\n scrollMode: 'if-needed',\n block: 'nearest',\n inline: 'nearest',\n });\n });\n }\n\n return true;\n};\n","/* Copyright 2021, Milkdown by Mirone. */\n\nimport { EditorView } from '@milkdown/prose';\nimport scrollIntoView from 'smooth-scroll-into-view-if-needed';\n\nimport { Status } from './status';\n\nexport const createMouseManager = () => {\n let mouseLock = false;\n\n return {\n isLock: () => mouseLock,\n lock: () => {\n mouseLock = true;\n },\n unlock: () => {\n mouseLock = false;\n },\n };\n};\nexport type MouseManager = ReturnType<typeof createMouseManager>;\n\nexport const handleMouseMove = (mouseManager: MouseManager) => () => {\n mouseManager.unlock();\n};\n\nexport const handleMouseEnter = (status: Status, mouseManager: MouseManager) => (e: MouseEvent) => {\n if (mouseManager.isLock()) return;\n const { actions } = status.get();\n const active = actions.findIndex((x) => x.$.classList.contains('active'));\n const active$ = actions[active];\n if (active$ && active >= 0) {\n active$.$.classList.remove('active');\n }\n const { target } = e;\n if (!(target instanceof HTMLElement)) return;\n target.classList.add('active');\n};\n\nexport const handleMouseLeave = () => (e: MouseEvent) => {\n const { target } = e;\n if (!(target instanceof HTMLElement)) return;\n target.classList.remove('active');\n};\n\nexport const handleClick =\n (status: Status, view: EditorView, dropdownElement: HTMLElement) =>\n (e: Event): void => {\n const { target } = e;\n if (!(target instanceof HTMLElement)) return;\n if (!view) return;\n\n const stop = () => {\n e.stopPropagation();\n e.preventDefault();\n };\n\n const { actions } = status.get();\n\n const el = Object.values(actions).find(({ $ }) => $.contains(target));\n if (!el) {\n if (status.isEmpty()) return;\n\n status.clear();\n dropdownElement.classList.add('hide');\n stop();\n\n return;\n }\n\n stop();\n el.command(view.state, view.dispatch, view);\n };\n\nexport const handleKeydown =\n (status: Status, view: EditorView, dropdownElement: HTMLElement, mouseManager: MouseManager) => (e: Event) => {\n if (!(e instanceof KeyboardEvent)) return;\n if (!mouseManager.isLock()) mouseManager.lock();\n\n const { key } = e;\n if (status.isEmpty()) return;\n if (!['ArrowDown', 'ArrowUp', 'Enter', 'Escape'].includes(key)) return;\n\n const { actions } = status.get();\n\n let active = actions.findIndex(({ $ }) => $.classList.contains('active'));\n if (active < 0) active = 0;\n\n const moveActive = (next: number) => {\n const active$ = actions[active];\n const next$ = actions[next];\n if (!active$ || !next$) return;\n active$.$.classList.remove('active');\n next$.$.classList.add('active');\n scrollIntoView(next$.$, {\n scrollMode: 'if-needed',\n block: 'nearest',\n inline: 'nearest',\n });\n };\n\n if (key === 'ArrowDown') {\n const next = active === actions.length - 1 ? 0 : active + 1;\n\n moveActive(next);\n return;\n }\n\n if (key === 'ArrowUp') {\n const next = active === 0 ? actions.length - 1 : active - 1;\n\n moveActive(next);\n return;\n }\n\n if (key === 'Escape') {\n if (status.isEmpty()) return;\n\n status.clear();\n dropdownElement.classList.add('hide');\n return;\n }\n\n const active$ = actions[active];\n if (!active$) return;\n active$.command(view.state, view.dispatch, view);\n active$.$.classList.remove('active');\n };\n","/* Copyright 2021, Milkdown by Mirone. */\nimport { calculateNodePosition, EditorView } from '@milkdown/prose';\nimport { Utils } from '@milkdown/utils';\n\nimport { createDropdown } from '../utility';\nimport { renderDropdown } from './dropdown';\nimport {\n createMouseManager,\n handleClick,\n handleKeydown,\n handleMouseEnter,\n handleMouseLeave,\n handleMouseMove,\n} from './input';\nimport { Status } from './status';\n\nconst calculatePosition = (view: EditorView, dropdownElement: HTMLElement) => {\n calculateNodePosition(view, dropdownElement, (selected, target, parent) => {\n const $editor = dropdownElement.parentElement;\n if (!$editor) {\n throw new Error();\n }\n\n let left = selected.left - parent.left;\n let top = selected.bottom - parent.top + 14 + $editor.scrollTop;\n\n if (left < 0) {\n left = 0;\n }\n\n if (parent.height + parent.top - selected.bottom < target.height) {\n top = selected.top - parent.top - target.height - 14 + $editor.scrollTop;\n }\n return [top, left];\n });\n};\n\nexport const createView = (status: Status, view: EditorView, utils: Utils) => {\n const wrapper = view.dom.parentNode;\n if (!wrapper) return {};\n\n const dropdownElement = createDropdown(utils);\n const mouseManager = createMouseManager();\n wrapper.appendChild(dropdownElement);\n\n const _mouseMove = handleMouseMove(mouseManager);\n const _mouseDown = handleClick(status, view, dropdownElement);\n const _keydown = handleKeydown(status, view, dropdownElement, mouseManager);\n const _mouseEnter = handleMouseEnter(status, mouseManager);\n const _mouseLeave = handleMouseLeave();\n\n wrapper.addEventListener('mousemove', _mouseMove);\n wrapper.addEventListener('mousedown', _mouseDown);\n wrapper.addEventListener('keydown', _keydown);\n\n return {\n update: (view: EditorView) => {\n const show = renderDropdown(status, dropdownElement, {\n mouseEnter: _mouseEnter as EventListener,\n mouseLeave: _mouseLeave as EventListener,\n });\n\n if (!show) return;\n\n calculatePosition(view, dropdownElement);\n },\n\n destroy: () => {\n wrapper.removeEventListener('mousemove', _mouseMove);\n wrapper.removeEventListener('mousedown', _mouseDown);\n wrapper.removeEventListener('keydown', _keydown);\n dropdownElement.remove();\n },\n };\n};\n","/* Copyright 2021, Milkdown by Mirone. */\nimport { Plugin, PluginKey } from '@milkdown/prose';\nimport { Utils } from '@milkdown/utils';\n\nimport type { StatusConfigBuilder } from '..';\nimport { createProps } from './props';\nimport { createStatus } from './status';\nimport { createView } from './view';\n\nexport const key = 'MILKDOWN_PLUGIN_SLASH';\n\nexport const createSlashPlugin = (utils: Utils, builder: StatusConfigBuilder) => {\n const status = createStatus(builder);\n\n return new Plugin({\n key: new PluginKey(key),\n props: createProps(status, utils),\n view: (view) => createView(status, view, utils),\n });\n};\n","/* Copyright 2021, Milkdown by Mirone. */\nimport { AtomList, createPlugin } from '@milkdown/utils';\n\nimport type { Config } from './config';\nimport { defaultConfig } from './config';\nimport { createSlashPlugin } from './prose-plugin';\n\nexport type { Config, StatusConfig, StatusConfigBuilder, StatusConfigBuilderParams } from './config';\nexport { defaultActions, defaultConfig } from './config';\nexport { createDropdownItem } from './utility';\n\nexport type Options = {\n config: Config;\n};\n\nexport const slashPlugin = createPlugin<string, Options>((utils, options) => {\n const slashConfig = options?.config ?? defaultConfig;\n\n return {\n prosePlugins: (_, ctx) => {\n const config = slashConfig(ctx);\n\n const plugin = createSlashPlugin(utils, config);\n\n return [plugin];\n },\n };\n});\n\nexport const slash = AtomList.create([slashPlugin()]);\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;AAaA,MAAM,YAAY,CAAC,cAA4B,EAAE,UAAmB;QAC1D,UAAU,CAAC,OAAc,UAAU,MAAM,aAAa,IAAI,YAAY,CAAC,OAAO;SAC7E;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,2BAUgB,aAAa,IAAI,WAAW;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,yBAO9B,QAAQ,WAAW;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,8BASd,QAAQ,aAAa;AAAA;AAAA;AAAA,6BAGtB,QAAQ;AAAA;AAAA;AAAA;AAAA;MAMxB,cAAc,C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;AAEF,oBAAY,aAAa,GAAG,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,GAAG;IAC7C,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,GAAG,EAAE,WAAW,CAAC;CACpB,CAAC;AAEF,eAAO,MAAM,eAAe,WAAY,aAAa,KAAG,MAItD,CAAC"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dropdown.d.ts","sourceRoot":"","sources":["../../src/prose-plugin/dropdown.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC,aAAK,SAAS,GAAG;IACb,UAAU,EAAE,aAAa,CAAC;IAC1B,UAAU,EAAE,aAAa,CAAC;CAC7B,CAAC;AAEF,eAAO,MAAM,cAAc,WAAY,MAAM,mBAAmB,WAAW,aAAa,SAAS,KAAG,OAuCnG,CAAC"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/prose-plugin/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAa,MAAM,iBAAiB,CAAC;AACpD,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAExC,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,IAAI,CAAC;AAK9C,eAAO,MAAM,GAAG,0BAA0B,CAAC;AAE3C,eAAO,MAAM,iBAAiB,UAAW,KAAK,WAAW,mBAAmB,qBAQ3E,CAAC"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"input.d.ts","sourceRoot":"","sources":["../../src/prose-plugin/input.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAG7C,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC,eAAO,MAAM,kBAAkB;;;;CAY9B,CAAC;AACF,oBAAY,YAAY,GAAG,UAAU,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAEjE,eAAO,MAAM,eAAe,iBAAkB,YAAY,eAEzD,CAAC;AAEF,eAAO,MAAM,gBAAgB,WAAY,MAAM,gBAAgB,YAAY,SAAS,UAAU,SAW7F,CAAC;AAEF,eAAO,MAAM,gBAAgB,YAAa,UAAU,SAInD,CAAC;AAEF,eAAO,MAAM,WAAW,WACX,MAAM,QAAQ,UAAU,mBAAmB,WAAW,SAC3D,KAAK,KAAG,IAyBX,CAAC;AAEN,eAAO,MAAM,aAAa,WACb,MAAM,QAAQ,UAAU,mBAAmB,WAAW,gBAAgB,YAAY,SAAS,KAAK,SAoDxG,CAAC"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"props.d.ts","sourceRoot":"","sources":["../../src/prose-plugin/props.ts"],"names":[],"mappings":"AAEA,OAAO,EAAc,aAAa,EAAE,WAAW,EAAE,UAAU,EAAkB,MAAM,iBAAiB,CAAC;AACrG,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAExC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAEvC,oBAAY,KAAK,GAAG,UAAU,CAAC,OAAO,WAAW,CAAC,CAAC;AA4BnD,eAAO,MAAM,WAAW,WAAY,MAAM,SAAS,KAAK;uBAE7B,UAAU,SAAS,KAAK;yBActB,WAAW;CAoDvC,CAAC"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"status.d.ts","sourceRoot":"","sources":["../../src/prose-plugin/status.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,yBAAyB,EAAE,MAAM,IAAI,CAAC;AACpE,OAAO,EAAE,MAAM,EAAmB,MAAM,SAAS,CAAC;AAElD,oBAAY,SAAS,GAAG;IACpB,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,OAAO,EAAE,MAAM,EAAE,CAAC;CACrB,CAAC;AASF,oBAAY,MAAM,GAAG,UAAU,CAAC,OAAO,YAAY,CAAC,CAAC;AAErD,eAAO,MAAM,YAAY,YAAa,mBAAmB;;;4BASzB,yBAAyB;;CAQxD,CAAC"}
File without changes
@@ -0,0 +1 @@
1
+ {"version":3,"file":"view.d.ts","sourceRoot":"","sources":["../../src/prose-plugin/view.ts"],"names":[],"mappings":"AACA,OAAO,EAAyB,UAAU,EAAE,MAAM,iBAAiB,CAAC;AACpE,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAYxC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAuBlC,eAAO,MAAM,UAAU,WAAY,MAAM,QAAQ,UAAU,SAAS,KAAK;;;;mBAmBlD,UAAU;;CAkBhC,CAAC"}
package/lib/style.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ import { Emotion, ThemeManager } from '@milkdown/core';
2
+ export declare const injectStyle: (themeManager: ThemeManager, emotion: Emotion) => string;
3
+ //# sourceMappingURL=style.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"style.d.ts","sourceRoot":"","sources":["../src/style.ts"],"names":[],"mappings":"AACA,OAAO,EAEH,OAAO,EAIP,YAAY,EAIf,MAAM,gBAAgB,CAAC;AAuCxB,eAAO,MAAM,WAAW,iBAAkB,YAAY,WAAW,OAAO,WAqBvE,CAAC"}
@@ -1,4 +1,4 @@
1
- import type { ThemeTool } from '@milkdown/core';
1
+ import { ThemeManager } from '@milkdown/core';
2
2
  import type { Icon } from '@milkdown/design-system';
3
3
  import type { Command, Node } from '@milkdown/prose';
4
4
  import type { Utils } from '@milkdown/utils';
@@ -6,7 +6,7 @@ export declare const createDropdown: (utils: Utils) => HTMLDivElement;
6
6
  declare type ItemOptions = {
7
7
  textClassName: string;
8
8
  };
9
- export declare const createDropdownItem: (themeTool: ThemeTool, text: string, icon: Icon, options?: Partial<ItemOptions> | undefined) => HTMLDivElement;
9
+ export declare const createDropdownItem: (themeManager: ThemeManager, text: string, icon: Icon, options?: Partial<ItemOptions> | undefined) => HTMLDivElement;
10
10
  export declare const getDepth: (node: Node) => number;
11
11
  export declare const cleanUpAndCreateNode: (createCommand: () => void) => Command;
12
12
  export {};
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utility.d.ts","sourceRoot":"","sources":["../src/utility.ts"],"names":[],"mappings":"AACA,OAAO,EAAa,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACzD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAI7C,eAAO,MAAM,cAAc,UAAW,KAAK,mBAe1C,CAAC;AAEF,aAAK,WAAW,GAAG;IACf,aAAa,EAAE,MAAM,CAAC;CACzB,CAAC;AACF,eAAO,MAAM,kBAAkB,iBACb,YAAY,QACpB,MAAM,QACN,IAAI,+DAwBb,CAAC;AAEF,eAAO,MAAM,QAAQ,SAAU,IAAI,WASlC,CAAC;AAUF,eAAO,MAAM,oBAAoB,kBACb,MAAM,IAAI,KAAG,OAO5B,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@milkdown/plugin-slash",
3
- "version": "5.5.0",
3
+ "version": "6.0.0-next.0",
4
4
  "type": "module",
5
5
  "main": "./lib/index.es.js",
6
6
  "types": "./lib/index.d.ts",
@@ -15,24 +15,48 @@
15
15
  "milkdown plugin"
16
16
  ],
17
17
  "devDependencies": {
18
- "@milkdown/core": "5.5.0",
19
- "@milkdown/prose": "5.5.0",
20
- "@milkdown/design-system": "5.5.0"
18
+ "@milkdown/core": "6.0.0-next.0",
19
+ "@milkdown/prose": "6.0.0-next.0",
20
+ "@milkdown/design-system": "6.0.0-next.0"
21
21
  },
22
22
  "peerDependencies": {
23
- "@milkdown/core": "^5.4.0",
24
- "@milkdown/prose": "^5.4.0"
23
+ "@milkdown/core": "^6.0.0-next.0",
24
+ "@milkdown/prose": "^6.0.0-next.0"
25
25
  },
26
26
  "dependencies": {
27
- "@milkdown/utils": "5.5.0",
27
+ "@milkdown/utils": "6.0.0-next.0",
28
28
  "smooth-scroll-into-view-if-needed": "^1.1.32",
29
29
  "tslib": "^2.3.1"
30
30
  },
31
+ "nx": {
32
+ "targets": {
33
+ "build": {
34
+ "outputs": [
35
+ "packages/plugin-slash/lib"
36
+ ],
37
+ "dependsOn": [
38
+ {
39
+ "target": "build",
40
+ "projects": "dependencies"
41
+ }
42
+ ]
43
+ },
44
+ "tsc": {
45
+ "outputs": [],
46
+ "dependsOn": [
47
+ {
48
+ "target": "build",
49
+ "projects": "dependencies"
50
+ }
51
+ ]
52
+ }
53
+ }
54
+ },
31
55
  "scripts": {
32
- "start": "vite build --watch",
56
+ "start": "concurrently -n es,dts \"vite build --watch\" \"tsc --emitDeclarationOnly --watch\"",
33
57
  "test": "vitest",
34
58
  "tsc": "tsc --noEmit",
35
- "build": "vite build"
59
+ "build": "vite build && tsc --emitDeclarationOnly"
36
60
  },
37
61
  "readme": "# @milkdown/plugin-slash\n\nSlash plugin for [milkdown](https://saul-mirone.github.io/milkdown/).\nAdd support for slash commands.\n\n# Example Usage\n\n```typescript\nimport { Editor } from '@milkdown/core';\nimport { commonmark } from '@milkdown/preset-commonmark';\nimport { nord } from '@milkdown/theme-nord';\n\nimport { slash } from '@milkdown/plugin-slash';\n\nEditor.make().use(nord).use(commonmark).use(slash).create();\n```\n\n# Options\n\n## config\n\nConfigure the slash plugin placeholders & items with custom status builder.\n\nExample:\n\n```typescript\nimport { slashPlugin, slash, createDropdownItem, defaultActions } from '@milkdown/plugin-slash';\nimport { themeToolCtx, commandsCtx } from '@milkdown/core';\n\nEditor.make().use(\n slash.configure(slashPlugin, {\n config: (ctx) => {\n // Get default slash plugin items\n const actions = defaultActions(ctx);\n\n // Define a status builder\n return ({ isTopLevel, content, parentNode }) => {\n // You can only show something at root level\n if (!isTopLevel) return null;\n\n // Empty content ? Set your custom empty placeholder !\n if (!content) {\n return { placeholder: 'Type / to use the slash commands...' };\n }\n\n // Define the placeholder & actions (dropdown items) you want to display depending on content\n if (content.startsWith('/')) {\n // Add some actions depending on your content's parent node\n if (parentNode.type.name === 'customNode') {\n actions.push({\n id: 'custom',\n dom: createDropdownItem(ctx.get(themeToolCtx), 'Custom', 'h1'),\n command: () => ctx.get(commandsCtx).call(/* Add custom command here */),\n keyword: ['custom'],\n enable: () => true,\n });\n }\n\n return content === '/'\n ? {\n placeholder: 'Type to filter...',\n actions,\n }\n : {\n actions: actions.filter(({ keyword }) =>\n keyword.some((key) => key.includes(content.slice(1).toLocaleLowerCase())),\n ),\n };\n }\n };\n },\n }),\n);\n```\n\n# License\n\nMilkdown is open sourced software licensed under [MIT license](https://github.com/Saul-Mirone/milkdown/blob/main/LICENSE).\n"
38
62
  }
package/src/config.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /* Copyright 2021, Milkdown by Mirone. */
2
- import { commandsCtx, Ctx, schemaCtx, themeToolCtx } from '@milkdown/core';
2
+ import { commandsCtx, Ctx, schemaCtx, themeManagerCtx } from '@milkdown/core';
3
3
  import { EditorState, Node } from '@milkdown/prose';
4
4
 
5
5
  import { WrappedAction } from './item';
@@ -28,77 +28,77 @@ export const defaultActions = (ctx: Ctx, input = '/'): WrappedAction[] => {
28
28
  const actions: Array<WrappedAction & { keyword: string[]; typeName: string }> = [
29
29
  {
30
30
  id: 'h1',
31
- dom: createDropdownItem(ctx.get(themeToolCtx), 'Large Heading', 'h1'),
31
+ dom: createDropdownItem(ctx.get(themeManagerCtx), 'Large Heading', 'h1'),
32
32
  command: () => ctx.get(commandsCtx).callByName('TurnIntoHeading', 1),
33
33
  keyword: ['h1', 'large heading'],
34
34
  typeName: 'heading',
35
35
  },
36
36
  {
37
37
  id: 'h2',
38
- dom: createDropdownItem(ctx.get(themeToolCtx), 'Medium Heading', 'h2'),
38
+ dom: createDropdownItem(ctx.get(themeManagerCtx), 'Medium Heading', 'h2'),
39
39
  command: () => ctx.get(commandsCtx).callByName('TurnIntoHeading', 2),
40
40
  keyword: ['h2', 'medium heading'],
41
41
  typeName: 'heading',
42
42
  },
43
43
  {
44
44
  id: 'h3',
45
- dom: createDropdownItem(ctx.get(themeToolCtx), 'Small Heading', 'h3'),
45
+ dom: createDropdownItem(ctx.get(themeManagerCtx), 'Small Heading', 'h3'),
46
46
  command: () => ctx.get(commandsCtx).callByName('TurnIntoHeading', 3),
47
47
  keyword: ['h3', 'small heading'],
48
48
  typeName: 'heading',
49
49
  },
50
50
  {
51
51
  id: 'bulletList',
52
- dom: createDropdownItem(ctx.get(themeToolCtx), 'Bullet List', 'bulletList'),
52
+ dom: createDropdownItem(ctx.get(themeManagerCtx), 'Bullet List', 'bulletList'),
53
53
  command: () => ctx.get(commandsCtx).callByName('WrapInBulletList'),
54
54
  keyword: ['bullet list', 'ul'],
55
55
  typeName: 'bullet_list',
56
56
  },
57
57
  {
58
58
  id: 'orderedList',
59
- dom: createDropdownItem(ctx.get(themeToolCtx), 'Ordered List', 'orderedList'),
59
+ dom: createDropdownItem(ctx.get(themeManagerCtx), 'Ordered List', 'orderedList'),
60
60
  command: () => ctx.get(commandsCtx).callByName('WrapInOrderedList'),
61
61
  keyword: ['ordered list', 'ol'],
62
62
  typeName: 'ordered_list',
63
63
  },
64
64
  {
65
65
  id: 'taskList',
66
- dom: createDropdownItem(ctx.get(themeToolCtx), 'Task List', 'taskList'),
66
+ dom: createDropdownItem(ctx.get(themeManagerCtx), 'Task List', 'taskList'),
67
67
  command: () => ctx.get(commandsCtx).callByName('TurnIntoTaskList'),
68
68
  keyword: ['task list', 'task'],
69
69
  typeName: 'task_list_item',
70
70
  },
71
71
  {
72
72
  id: 'image',
73
- dom: createDropdownItem(ctx.get(themeToolCtx), 'Image', 'image'),
73
+ dom: createDropdownItem(ctx.get(themeManagerCtx), 'Image', 'image'),
74
74
  command: () => ctx.get(commandsCtx).callByName('InsertImage'),
75
75
  keyword: ['image'],
76
76
  typeName: 'image',
77
77
  },
78
78
  {
79
79
  id: 'blockquote',
80
- dom: createDropdownItem(ctx.get(themeToolCtx), 'Quote', 'quote'),
80
+ dom: createDropdownItem(ctx.get(themeManagerCtx), 'Quote', 'quote'),
81
81
  command: () => ctx.get(commandsCtx).callByName('WrapInBlockquote'),
82
82
  keyword: ['quote', 'blockquote'],
83
83
  typeName: 'blockquote',
84
84
  },
85
85
  {
86
86
  id: 'table',
87
- dom: createDropdownItem(ctx.get(themeToolCtx), 'Table', 'table'),
87
+ dom: createDropdownItem(ctx.get(themeManagerCtx), 'Table', 'table'),
88
88
  command: () => ctx.get(commandsCtx).callByName('InsertTable'),
89
89
  keyword: ['table'],
90
90
  typeName: 'table',
91
91
  },
92
92
  {
93
93
  id: 'code',
94
- dom: createDropdownItem(ctx.get(themeToolCtx), 'Code Fence', 'code'),
94
+ dom: createDropdownItem(ctx.get(themeManagerCtx), 'Code Fence', 'code'),
95
95
  command: () => ctx.get(commandsCtx).callByName('TurnIntoCodeFence'),
96
96
  keyword: ['code'],
97
97
  typeName: 'fence',
98
98
  },
99
99
  {
100
100
  id: 'divider',
101
- dom: createDropdownItem(ctx.get(themeToolCtx), 'Divide Line', 'divider'),
101
+ dom: createDropdownItem(ctx.get(themeManagerCtx), 'Divide Line', 'divider'),
102
102
  command: () => ctx.get(commandsCtx).callByName('InsertHr'),
103
103
  keyword: ['divider', 'hr'],
104
104
  typeName: 'hr',
@@ -21,8 +21,9 @@ export const renderDropdown = (status: Status, dropdownElement: HTMLElement, lis
21
21
  child.removeEventListener('mouseleave', listeners.mouseLeave);
22
22
  });
23
23
 
24
- // Reset dropdownElement children
25
- dropdownElement.textContent = '';
24
+ while (dropdownElement.firstChild) {
25
+ dropdownElement.firstChild.remove();
26
+ }
26
27
 
27
28
  actions.forEach(({ $ }) => {
28
29
  $.classList.remove('active');
@@ -1,5 +1,5 @@
1
1
  /* Copyright 2021, Milkdown by Mirone. */
2
- import { Emotion, ThemeTool } from '@milkdown/core';
2
+ import { Color, Emotion, ThemeColor, ThemeFont, ThemeManager } from '@milkdown/core';
3
3
  import { Decoration, DecorationSet, EditorState, EditorView, findParentNode } from '@milkdown/prose';
4
4
  import { Utils } from '@milkdown/utils';
5
5
 
@@ -7,31 +7,33 @@ import type { Status } from './status';
7
7
 
8
8
  export type Props = ReturnType<typeof createProps>;
9
9
 
10
- const createEmptyStyle = ({ font, palette }: ThemeTool, { css }: Emotion) => css`
11
- position: relative;
12
- &::before {
13
- position: absolute;
14
- cursor: text;
15
- font-family: ${font.typography};
16
- font-size: 0.875rem;
17
- color: ${palette('neutral', 0.6)};
18
- content: attr(data-text);
19
- height: 100%;
20
- display: flex;
21
- align-items: center;
22
- }
23
- `;
10
+ const createEmptyStyle = (themeManager: ThemeManager, { css }: Emotion) => {
11
+ const palette = (color: Color, opacity = 1) => themeManager.get(ThemeColor, [color, opacity]);
12
+ const typography = themeManager.get(ThemeFont, 'typography');
24
13
 
25
- const createSlashStyle = (_: ThemeTool, { css }: Emotion) => css`
14
+ return css`
15
+ position: relative;
16
+ &::before {
17
+ position: absolute;
18
+ cursor: text;
19
+ font-family: ${typography};
20
+ font-size: 0.875em;
21
+ color: ${palette('neutral', 0.6)};
22
+ content: attr(data-text);
23
+ height: 100%;
24
+ display: flex;
25
+ align-items: center;
26
+ }
27
+ `;
28
+ };
29
+
30
+ const createSlashStyle = (_: ThemeManager, { css }: Emotion) => css`
26
31
  &::before {
27
- left: 0.5rem;
32
+ left: 0.5em;
28
33
  }
29
34
  `;
30
35
 
31
36
  export const createProps = (status: Status, utils: Utils) => {
32
- const emptyStyle = utils.getStyle(createEmptyStyle);
33
- const slashStyle = utils.getStyle(createSlashStyle);
34
-
35
37
  return {
36
38
  handleKeyDown: (_: EditorView, event: Event) => {
37
39
  if (status.isEmpty()) {
@@ -89,6 +91,9 @@ export const createProps = (status: Status, utils: Utils) => {
89
91
  ]);
90
92
  };
91
93
 
94
+ const emptyStyle = utils.getStyle(createEmptyStyle);
95
+ const slashStyle = utils.getStyle(createSlashStyle);
96
+
92
97
  if (actions.length) {
93
98
  return createDecoration(placeholder, [emptyStyle, slashStyle, 'empty-node', 'is-slash']);
94
99
  }
@@ -28,7 +28,7 @@ const calculatePosition = (view: EditorView, dropdownElement: HTMLElement) => {
28
28
  left = 0;
29
29
  }
30
30
 
31
- if (window.innerHeight - selected.bottom < target.height) {
31
+ if (parent.height + parent.top - selected.bottom < target.height) {
32
32
  top = selected.top - parent.top - target.height - 14 + $editor.scrollTop;
33
33
  }
34
34
  return [top, left];
package/src/style.ts CHANGED
@@ -1,19 +1,30 @@
1
1
  /* Copyright 2021, Milkdown by Mirone. */
2
- import { Emotion, ThemeTool } from '@milkdown/core';
2
+ import {
3
+ Color,
4
+ Emotion,
5
+ ThemeBorder,
6
+ ThemeColor,
7
+ ThemeFont,
8
+ ThemeManager,
9
+ ThemeScrollbar,
10
+ ThemeShadow,
11
+ ThemeSize,
12
+ } from '@milkdown/core';
3
13
 
4
- const itemStyle = ({ font, palette }: ThemeTool, { css }: Emotion) => {
14
+ const itemStyle = (themeManager: ThemeManager, { css }: Emotion) => {
15
+ const palette = (color: Color, opacity = 1) => themeManager.get(ThemeColor, [color, opacity]);
5
16
  return css`
6
17
  .slash-dropdown-item {
7
18
  display: flex;
8
- gap: 2rem;
9
- height: 3rem;
10
- padding: 0 1rem;
19
+ gap: 2em;
20
+ height: 3.4286em;
21
+ padding: 0 1em;
11
22
  align-items: center;
12
23
  justify-content: flex-start;
13
24
  cursor: pointer;
14
- line-height: 2;
15
- font-family: ${font.typography};
16
- font-size: 0.875rem;
25
+ line-height: 3.4286em;
26
+ font-family: ${themeManager.get(ThemeFont, 'typography')};
27
+ font-size: 0.875em;
17
28
 
18
29
  transition: all 0.2s ease-in-out;
19
30
 
@@ -37,26 +48,25 @@ const itemStyle = ({ font, palette }: ThemeTool, { css }: Emotion) => {
37
48
  `;
38
49
  };
39
50
 
40
- export const injectStyle = (themeTool: ThemeTool, emotion: Emotion) => {
41
- const { mixin, size, palette } = themeTool;
42
- const style = emotion.css`
43
- width: 20.5rem;
44
- max-height: 20.5rem;
51
+ export const injectStyle = (themeManager: ThemeManager, emotion: Emotion) => {
52
+ const palette = (color: Color, opacity = 1) => themeManager.get(ThemeColor, [color, opacity]);
53
+
54
+ return emotion.css`
55
+ width: 20.5em;
56
+ max-height: 20.5em;
45
57
  overflow-y: auto;
46
- ${mixin.border?.()};
47
- border-radius: ${size.radius};
58
+ border-radius: ${themeManager.get(ThemeSize, 'radius')};
48
59
  position: absolute;
49
60
  background: ${palette('surface')};
50
61
 
51
- ${mixin.shadow?.()};
62
+ ${themeManager.get(ThemeBorder, undefined)}
63
+ ${themeManager.get(ThemeShadow, undefined)}
64
+ ${themeManager.get(ThemeScrollbar, undefined)}
52
65
 
53
66
  &.hide {
54
67
  display: none;
55
68
  }
56
69
 
57
- ${mixin.scrollbar?.()};
58
-
59
- ${itemStyle(themeTool, emotion)}
70
+ ${itemStyle(themeManager, emotion)}
60
71
  `;
61
- return style;
62
72
  };
package/src/utility.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /* Copyright 2021, Milkdown by Mirone. */
2
- import type { ThemeTool } from '@milkdown/core';
2
+ import { ThemeIcon, ThemeManager } from '@milkdown/core';
3
3
  import type { Icon } from '@milkdown/design-system';
4
4
  import type { Command, Node } from '@milkdown/prose';
5
5
  import type { Utils } from '@milkdown/utils';
@@ -10,11 +10,13 @@ export const createDropdown = (utils: Utils) => {
10
10
  const div = document.createElement('div');
11
11
  div.setAttribute('role', 'listbox');
12
12
  div.setAttribute('tabindex', '-1');
13
- const style = utils.getStyle(injectStyle);
13
+ utils.themeManager.onFlush(() => {
14
+ const style = utils.getStyle(injectStyle);
14
15
 
15
- if (style) {
16
- div.classList.add(style);
17
- }
16
+ if (style) {
17
+ div.classList.add(style);
18
+ }
19
+ });
18
20
 
19
21
  div.classList.add('slash-dropdown', 'hide');
20
22
 
@@ -24,20 +26,30 @@ export const createDropdown = (utils: Utils) => {
24
26
  type ItemOptions = {
25
27
  textClassName: string;
26
28
  };
27
- export const createDropdownItem = (themeTool: ThemeTool, text: string, icon: Icon, options?: Partial<ItemOptions>) => {
29
+ export const createDropdownItem = (
30
+ themeManager: ThemeManager,
31
+ text: string,
32
+ icon: Icon,
33
+ options?: Partial<ItemOptions>,
34
+ ) => {
28
35
  const textClassName = options?.textClassName ?? 'text';
29
36
 
30
37
  const div = document.createElement('div');
31
38
  div.setAttribute('role', 'option');
32
39
  div.classList.add('slash-dropdown-item');
33
40
 
34
- const iconSpan = themeTool.slots.icon(icon);
41
+ // const iconSpan = themeManager.slots.icon(icon);
42
+ const iconSpan = themeManager.get(ThemeIcon, icon);
43
+
44
+ if (!iconSpan) {
45
+ throw new Error('icon not found');
46
+ }
35
47
 
36
48
  const textSpan = document.createElement('span');
37
49
  textSpan.textContent = text;
38
50
  textSpan.className = textClassName;
39
51
 
40
- div.appendChild(iconSpan);
52
+ div.appendChild(iconSpan.dom);
41
53
  div.appendChild(textSpan);
42
54
 
43
55
  return div;
@@ -1 +0,0 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["config.ts"],"names":[],"mappings":"AACA,OAAO,EAAe,GAAG,EAA2B,MAAM,gBAAgB,CAAC;AAC3E,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAEpD,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAGvC,aAAK,QAAQ,CAAC,CAAC,IAAI,CAAC,GAAG,IAAI,GAAG,SAAS,CAAC;AAExC,oBAAY,YAAY,GAAG;IACvB,WAAW,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC/B,OAAO,CAAC,EAAE,QAAQ,CAAC,aAAa,EAAE,CAAC,CAAC;CACvC,CAAC;AAEF,oBAAY,yBAAyB,GAAG;IACpC,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,OAAO,CAAC;IACpB,UAAU,EAAE,IAAI,CAAC;IACjB,KAAK,EAAE,WAAW,CAAC;CACtB,CAAC;AAEF,oBAAY,mBAAmB,GAAG,CAAC,MAAM,EAAE,yBAAyB,KAAK,QAAQ,CAAC,YAAY,CAAC,CAAC;AAEhG,oBAAY,MAAM,GAAG,CAAC,GAAG,EAAE,GAAG,KAAK,mBAAmB,CAAC;AAEvD,eAAO,MAAM,cAAc,QAAS,GAAG,qBAAgB,aAAa,EAuFnE,CAAC;AAEF,eAAO,MAAM,aAAa,EAAE,MAqB3B,CAAC"}
@@ -1,25 +0,0 @@
1
- import { AtomList } from '@milkdown/utils';
2
- import type { Config } from './config';
3
- export type { Config, StatusConfig, StatusConfigBuilder, StatusConfigBuilderParams } from './config';
4
- export { defaultActions, defaultConfig } from './config';
5
- export { createDropdownItem } from './utility';
6
- export declare type Options = {
7
- config: Config;
8
- };
9
- export declare const slashPlugin: import("@milkdown/utils/lib/src/types").WithExtend<string, Options, {
10
- [x: string]: import("prosemirror-model").NodeType<any>;
11
- } & {
12
- [x: string]: import("prosemirror-model").MarkType<any>;
13
- }, {
14
- schema?: ((ctx: import("@milkdown/core").Ctx) => {
15
- node?: Record<string, import("@milkdown/core").NodeSchema> | undefined;
16
- mark?: Record<string, import("@milkdown/core").MarkSchema> | undefined;
17
- }) | undefined;
18
- view?: ((ctx: import("@milkdown/core").Ctx) => Partial<{
19
- [x: string]: import("@milkdown/prose").NodeViewFactory;
20
- } & {
21
- [x: string]: import("@milkdown/prose").MarkViewFactory;
22
- }>) | undefined;
23
- }>;
24
- export declare const slash: AtomList<import("@milkdown/utils/lib/src/types").Metadata<import("@milkdown/utils/lib/src/types").GetPlugin<string, Options>> & import("@milkdown/core").MilkdownPlugin>;
25
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAgB,MAAM,iBAAiB,CAAC;AAEzD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAIvC,YAAY,EAAE,MAAM,EAAE,YAAY,EAAE,mBAAmB,EAAE,yBAAyB,EAAE,MAAM,UAAU,CAAC;AACrG,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzD,OAAO,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAE/C,oBAAY,OAAO,GAAG;IAClB,MAAM,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,eAAO,MAAM,WAAW;;;;;;;;;;;;;;EAYtB,CAAC;AAEH,eAAO,MAAM,KAAK,0KAAmC,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"item.d.ts","sourceRoot":"","sources":["item.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAI/C,oBAAY,MAAM,GAAG;IACjB,EAAE,EAAE,MAAM,CAAC;IACX,CAAC,EAAE,WAAW,CAAC;IACf,OAAO,EAAE,OAAO,CAAC;CACpB,CAAC;AAEF,oBAAY,aAAa,GAAG,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,GAAG;IAC7C,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,GAAG,EAAE,WAAW,CAAC;CACpB,CAAC;AAEF,eAAO,MAAM,eAAe,WAAY,aAAa,KAAG,MAItD,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"dropdown.d.ts","sourceRoot":"","sources":["dropdown.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC,aAAK,SAAS,GAAG;IACb,UAAU,EAAE,aAAa,CAAC;IAC1B,UAAU,EAAE,aAAa,CAAC;CAC7B,CAAC;AAEF,eAAO,MAAM,cAAc,WAAY,MAAM,mBAAmB,WAAW,aAAa,SAAS,KAAG,OAsCnG,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAa,MAAM,iBAAiB,CAAC;AACpD,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAExC,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,IAAI,CAAC;AAK9C,eAAO,MAAM,GAAG,0BAA0B,CAAC;AAE3C,eAAO,MAAM,iBAAiB,UAAW,KAAK,WAAW,mBAAmB,qBAQ3E,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"input.d.ts","sourceRoot":"","sources":["input.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAG7C,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC,eAAO,MAAM,kBAAkB;;;;CAY9B,CAAC;AACF,oBAAY,YAAY,GAAG,UAAU,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAEjE,eAAO,MAAM,eAAe,iBAAkB,YAAY,eAEzD,CAAC;AAEF,eAAO,MAAM,gBAAgB,WAAY,MAAM,gBAAgB,YAAY,SAAS,UAAU,SAW7F,CAAC;AAEF,eAAO,MAAM,gBAAgB,YAAa,UAAU,SAInD,CAAC;AAEF,eAAO,MAAM,WAAW,WACX,MAAM,QAAQ,UAAU,mBAAmB,WAAW,SAC3D,KAAK,KAAG,IAyBX,CAAC;AAEN,eAAO,MAAM,aAAa,WACb,MAAM,QAAQ,UAAU,mBAAmB,WAAW,gBAAgB,YAAY,SAAS,KAAK,SAoDxG,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"props.d.ts","sourceRoot":"","sources":["props.ts"],"names":[],"mappings":"AAEA,OAAO,EAAc,aAAa,EAAE,WAAW,EAAE,UAAU,EAAkB,MAAM,iBAAiB,CAAC;AACrG,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAExC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAEvC,oBAAY,KAAK,GAAG,UAAU,CAAC,OAAO,WAAW,CAAC,CAAC;AAuBnD,eAAO,MAAM,WAAW,WAAY,MAAM,SAAS,KAAK;uBAK7B,UAAU,SAAS,KAAK;yBActB,WAAW;CAiDvC,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"status.d.ts","sourceRoot":"","sources":["status.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,yBAAyB,EAAE,MAAM,IAAI,CAAC;AACpE,OAAO,EAAE,MAAM,EAAmB,MAAM,SAAS,CAAC;AAElD,oBAAY,SAAS,GAAG;IACpB,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,OAAO,EAAE,MAAM,EAAE,CAAC;CACrB,CAAC;AASF,oBAAY,MAAM,GAAG,UAAU,CAAC,OAAO,YAAY,CAAC,CAAC;AAErD,eAAO,MAAM,YAAY,YAAa,mBAAmB;;;4BASzB,yBAAyB;;CAQxD,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"view.d.ts","sourceRoot":"","sources":["view.ts"],"names":[],"mappings":"AACA,OAAO,EAAyB,UAAU,EAAE,MAAM,iBAAiB,CAAC;AACpE,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAYxC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAuBlC,eAAO,MAAM,UAAU,WAAY,MAAM,QAAQ,UAAU,SAAS,KAAK;;;;mBAmBlD,UAAU;;CAkBhC,CAAC"}
@@ -1,3 +0,0 @@
1
- import { Emotion, ThemeTool } from '@milkdown/core';
2
- export declare const injectStyle: (themeTool: ThemeTool, emotion: Emotion) => string;
3
- //# sourceMappingURL=style.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"style.d.ts","sourceRoot":"","sources":["style.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAsCpD,eAAO,MAAM,WAAW,cAAe,SAAS,WAAW,OAAO,WAsBjE,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"utility.d.ts","sourceRoot":"","sources":["utility.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAI7C,eAAO,MAAM,cAAc,UAAW,KAAK,mBAa1C,CAAC;AAEF,aAAK,WAAW,GAAG;IACf,aAAa,EAAE,MAAM,CAAC;CACzB,CAAC;AACF,eAAO,MAAM,kBAAkB,cAAe,SAAS,QAAQ,MAAM,QAAQ,IAAI,+DAiBhF,CAAC;AAEF,eAAO,MAAM,QAAQ,SAAU,IAAI,WASlC,CAAC;AAUF,eAAO,MAAM,oBAAoB,kBACb,MAAM,IAAI,KAAG,OAO5B,CAAC"}