@milkdown/plugin-slash 4.10.5 → 4.12.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 (49) hide show
  1. package/README.md +50 -7
  2. package/lib/config.d.ts.map +1 -1
  3. package/lib/config.js +26 -14
  4. package/lib/config.js.map +1 -1
  5. package/lib/index.d.ts +14 -4
  6. package/lib/index.d.ts.map +1 -1
  7. package/lib/index.js +14 -12
  8. package/lib/index.js.map +1 -1
  9. package/lib/item.d.ts +2 -1
  10. package/lib/item.d.ts.map +1 -1
  11. package/lib/item.js +1 -0
  12. package/lib/item.js.map +1 -1
  13. package/lib/prose-plugin/dropdown.d.ts +4 -0
  14. package/lib/prose-plugin/dropdown.d.ts.map +1 -0
  15. package/lib/prose-plugin/dropdown.js +39 -0
  16. package/lib/prose-plugin/dropdown.js.map +1 -0
  17. package/lib/prose-plugin/index.d.ts +7 -0
  18. package/lib/prose-plugin/index.d.ts.map +1 -0
  19. package/lib/prose-plugin/index.js +16 -0
  20. package/lib/prose-plugin/index.js.map +1 -0
  21. package/lib/prose-plugin/input.d.ts +15 -0
  22. package/lib/prose-plugin/input.d.ts.map +1 -0
  23. package/lib/prose-plugin/input.js +101 -0
  24. package/lib/prose-plugin/input.js.map +1 -0
  25. package/lib/prose-plugin/props.d.ts +10 -0
  26. package/lib/prose-plugin/props.d.ts.map +1 -0
  27. package/lib/prose-plugin/props.js +80 -0
  28. package/lib/prose-plugin/props.js.map +1 -0
  29. package/lib/prose-plugin/status.d.ts +20 -0
  30. package/lib/prose-plugin/status.d.ts.map +1 -0
  31. package/lib/prose-plugin/status.js +34 -0
  32. package/lib/prose-plugin/status.js.map +1 -0
  33. package/lib/prose-plugin/view.d.ts +12 -0
  34. package/lib/prose-plugin/view.d.ts.map +1 -0
  35. package/lib/prose-plugin/view.js +56 -0
  36. package/lib/prose-plugin/view.js.map +1 -0
  37. package/lib/style.d.ts +3 -0
  38. package/lib/style.d.ts.map +1 -0
  39. package/lib/style.js +62 -0
  40. package/lib/style.js.map +1 -0
  41. package/lib/utility.d.ts +7 -6
  42. package/lib/utility.d.ts.map +1 -1
  43. package/lib/utility.js +11 -63
  44. package/lib/utility.js.map +1 -1
  45. package/package.json +2 -2
  46. package/lib/slash-plugin.d.ts +0 -5
  47. package/lib/slash-plugin.d.ts.map +0 -1
  48. package/lib/slash-plugin.js +0 -298
  49. package/lib/slash-plugin.js.map +0 -1
package/README.md CHANGED
@@ -8,14 +8,57 @@ Add support for slash commands.
8
8
  ```typescript
9
9
  import { Editor } from '@milkdown/core';
10
10
  import { commonmark } from '@milkdown/preset-commonmark';
11
-
12
- // import theme and style
13
- import '@milkdown/theme-nord/lib/theme.css';
14
- import '@milkdown/preset-commonmark/lib/style.css';
11
+ import { nord } from '@milkdown/theme-nord';
15
12
 
16
13
  import { slash } from '@milkdown/plugin-slash';
17
- // import style
18
- import '@milkdown/plugin-slash/lib/style.css';
19
14
 
20
- new Editor().use(commonmark).use(slash).create();
15
+ Editor.make().use(nord).use(commonmark).use(slash).create();
16
+ ```
17
+
18
+ # Options
19
+
20
+ ## config
21
+
22
+ Modify the list of slash plugin.
23
+
24
+ Example:
25
+
26
+ ```typescript
27
+ import { slashPlugin, slash, createDropdownItem, config, nodeExists } from '@milkdown/plugin-slash';
28
+
29
+ Editor.make().use(
30
+ slash.configure(slashPlugin, {
31
+ config: (utils) =>
32
+ config(utils)
33
+ .filter((c) => !['h1', 'h2', 'h3'].includes(c.id))
34
+ .concat([
35
+ {
36
+ id: 'h1',
37
+ dom: createDropdownItem(utils.ctx.get(themeToolCtx), 'My Heading Tips', 'h1'),
38
+ command: () => utils.ctx.get(commandsCtx).call(TurnIntoHeading),
39
+ keyword: ['h1', 'my heading', 'heading'],
40
+ enable: nodeExists('heading'),
41
+ },
42
+ ]),
43
+ }),
44
+ );
45
+ ```
46
+
47
+ ## placeholder
48
+
49
+ Modify the placeholder of slash plugin.
50
+
51
+ Example:
52
+
53
+ ```typescript
54
+ import { slashPlugin, slash, CursorStatus } from '@milkdown/plugin-slash';
55
+
56
+ Editor.make().use(
57
+ slash.configure(slashPlugin, {
58
+ placeholder: {
59
+ [CursorStatus.Empty]: 'Now you need to type a / ...',
60
+ [CursorStatus.Slash]: 'Keep typing to search...',
61
+ },
62
+ }),
63
+ );
21
64
  ```
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,GAAG,CAAC;AAIrC,eAAO,MAAM,MAAM,EAAE,WAmEpB,CAAC"}
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,GAAG,CAAC;AAGrC,eAAO,MAAM,MAAM,EAAE,WA8EpB,CAAC"}
package/lib/config.js CHANGED
@@ -1,69 +1,81 @@
1
- import { InsertHr, InsertImage, TurnIntoCodeFence, TurnIntoHeading, WrapInBlockquote, WrapInBulletList, WrapInOrderedList, TurnIntoTaskList, InsertTable, } from '@milkdown/preset-gfm';
1
+ /* Copyright 2021, Milkdown by Mirone. */
2
+ import { commandsCtx, themeToolCtx } from '@milkdown/core';
3
+ import { InsertHr, InsertImage, InsertTable, TurnIntoCodeFence, TurnIntoHeading, TurnIntoTaskList, WrapInBlockquote, WrapInBulletList, WrapInOrderedList, } from '@milkdown/preset-gfm';
2
4
  import { createDropdownItem, nodeExists } from './utility';
3
- import { commandsCtx } from '@milkdown/core';
4
- export const config = (ctx) => [
5
+ export const config = ({ ctx }) => [
5
6
  {
6
- dom: createDropdownItem('Large Heading', 'looks_one'),
7
+ id: 'h1',
8
+ dom: createDropdownItem(ctx.get(themeToolCtx), 'Large Heading', 'h1'),
7
9
  command: () => ctx.get(commandsCtx).call(TurnIntoHeading, 1),
8
10
  keyword: ['h1', 'large heading'],
9
11
  enable: nodeExists('heading'),
10
12
  },
11
13
  {
12
- dom: createDropdownItem('Medium Heading', 'looks_two'),
14
+ id: 'h2',
15
+ dom: createDropdownItem(ctx.get(themeToolCtx), 'Medium Heading', 'h2'),
13
16
  command: () => ctx.get(commandsCtx).call(TurnIntoHeading, 2),
14
17
  keyword: ['h2', 'medium heading'],
15
18
  enable: nodeExists('heading'),
16
19
  },
17
20
  {
18
- dom: createDropdownItem('Small Heading', 'looks_3'),
21
+ id: 'h3',
22
+ dom: createDropdownItem(ctx.get(themeToolCtx), 'Small Heading', 'h3'),
19
23
  command: () => ctx.get(commandsCtx).call(TurnIntoHeading, 3),
20
24
  keyword: ['h3', 'small heading'],
21
25
  enable: nodeExists('heading'),
22
26
  },
23
27
  {
24
- dom: createDropdownItem('Bullet List', 'format_list_bulleted'),
28
+ id: 'bulletList',
29
+ dom: createDropdownItem(ctx.get(themeToolCtx), 'Bullet List', 'bulletList'),
25
30
  command: () => ctx.get(commandsCtx).call(WrapInBulletList),
26
31
  keyword: ['bullet list', 'ul'],
27
32
  enable: nodeExists('bullet_list'),
28
33
  },
29
34
  {
30
- dom: createDropdownItem('Ordered List', 'format_list_numbered'),
35
+ id: 'orderedList',
36
+ dom: createDropdownItem(ctx.get(themeToolCtx), 'Ordered List', 'orderedList'),
31
37
  command: () => ctx.get(commandsCtx).call(WrapInOrderedList),
32
38
  keyword: ['ordered list', 'ol'],
33
39
  enable: nodeExists('ordered_list'),
34
40
  },
35
41
  {
36
- dom: createDropdownItem('Task List', 'checklist'),
42
+ id: 'taskList',
43
+ dom: createDropdownItem(ctx.get(themeToolCtx), 'Task List', 'taskList'),
37
44
  command: () => ctx.get(commandsCtx).call(TurnIntoTaskList),
38
45
  keyword: ['task list', 'task'],
39
46
  enable: nodeExists('task_list_item'),
40
47
  },
41
48
  {
42
- dom: createDropdownItem('Image', 'image'),
49
+ id: 'image',
50
+ dom: createDropdownItem(ctx.get(themeToolCtx), 'Image', 'image'),
43
51
  command: () => ctx.get(commandsCtx).call(InsertImage),
44
52
  keyword: ['image'],
45
53
  enable: nodeExists('image'),
46
54
  },
47
55
  {
48
- dom: createDropdownItem('Quote', 'format_quote'),
56
+ id: 'blockquote',
57
+ dom: createDropdownItem(ctx.get(themeToolCtx), 'Quote', 'quote'),
49
58
  command: () => ctx.get(commandsCtx).call(WrapInBlockquote),
50
59
  keyword: ['quote', 'blockquote'],
51
60
  enable: nodeExists('blockquote'),
52
61
  },
53
62
  {
54
- dom: createDropdownItem('Table', 'table_chart'),
63
+ id: 'table',
64
+ dom: createDropdownItem(ctx.get(themeToolCtx), 'Table', 'table'),
55
65
  command: () => ctx.get(commandsCtx).call(InsertTable),
56
66
  keyword: ['table'],
57
67
  enable: nodeExists('table'),
58
68
  },
59
69
  {
60
- dom: createDropdownItem('Code Fence', 'code'),
70
+ id: 'code',
71
+ dom: createDropdownItem(ctx.get(themeToolCtx), 'Code Fence', 'code'),
61
72
  command: () => ctx.get(commandsCtx).call(TurnIntoCodeFence),
62
73
  keyword: ['code'],
63
74
  enable: nodeExists('fence'),
64
75
  },
65
76
  {
66
- dom: createDropdownItem('Divide Line', 'horizontal_rule'),
77
+ id: 'divider',
78
+ dom: createDropdownItem(ctx.get(themeToolCtx), 'Divide Line', 'divider'),
67
79
  command: () => ctx.get(commandsCtx).call(InsertHr),
68
80
  keyword: ['divider', 'hr'],
69
81
  enable: nodeExists('hr'),
package/lib/config.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,QAAQ,EACR,WAAW,EACX,iBAAiB,EACjB,eAAe,EACf,gBAAgB,EAChB,gBAAgB,EAChB,iBAAiB,EACjB,gBAAgB,EAChB,WAAW,GACd,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EAAE,kBAAkB,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAC3D,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,MAAM,CAAC,MAAM,MAAM,GAAgB,CAAC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AAO,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC;QACrD,OAAO,EAAE,CAAC,OAAO,CAAC;QAClB,MAAM,EAAE,UAAU,CAAC,OAAO,CAAC;KAC9B;IACD;QACI,EAAE,EAAE,MAAM;QACV,GAAG,EAAE,kBAAkB,CAAC,GAAG,CAAC,GAAG,CAAC,YAAY,CAAC,EAAE,YAAY,EAAE,MAAM,CAAC;QACpE,OAAO,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,iBAAiB,CAAC;QAC3D,OAAO,EAAE,CAAC,MAAM,CAAC;QACjB,MAAM,EAAE,UAAU,CAAC,OAAO,CAAC;KAC9B;IACD;QACI,EAAE,EAAE,SAAS;QACb,GAAG,EAAE,kBAAkB,CAAC,GAAG,CAAC,GAAG,CAAC,YAAY,CAAC,EAAE,aAAa,EAAE,SAAS,CAAC;QACxE,OAAO,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC;QAClD,OAAO,EAAE,CAAC,SAAS,EAAE,IAAI,CAAC;QAC1B,MAAM,EAAE,UAAU,CAAC,IAAI,CAAC;KAC3B;CACJ,CAAC"}
package/lib/index.d.ts CHANGED
@@ -1,7 +1,17 @@
1
- import { Ctx, MilkdownPlugin } from '@milkdown/core';
1
+ import { AtomList, Utils } from '@milkdown/utils';
2
2
  import { WrappedAction } from './item';
3
+ import { CursorStatus } from './prose-plugin/status';
4
+ export { config } from './config';
5
+ export { CursorStatus } from './prose-plugin/status';
3
6
  export { createDropdownItem, nodeExists } from './utility';
4
- export declare type SlashConfig = (ctx: Ctx) => WrappedAction[];
5
- export declare const slashCtx: import("@milkdown/core").Meta<SlashConfig>;
6
- export declare const slash: MilkdownPlugin;
7
+ export declare type SlashConfig = (utils: Utils) => WrappedAction[];
8
+ export declare type Options = {
9
+ config: SlashConfig;
10
+ placeholder: {
11
+ [CursorStatus.Empty]: string;
12
+ [CursorStatus.Slash]: string;
13
+ };
14
+ };
15
+ export declare const slashPlugin: import("@milkdown/utils/lib/atom/types").Origin<string, Options, import("prosemirror-state").Plugin<any, any>>;
16
+ export declare const slash: AtomList<import("@milkdown/utils/lib/atom/types").PluginWithMetadata<string, Options, import("prosemirror-state").Plugin<any, any>>>;
7
17
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAA4B,GAAG,EAAE,cAAc,EAAmB,MAAM,gBAAgB,CAAC;AAEhG,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAGvC,OAAO,EAAE,kBAAkB,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAE3D,oBAAY,WAAW,GAAG,CAAC,GAAG,EAAE,GAAG,KAAK,aAAa,EAAE,CAAC;AAExD,eAAO,MAAM,QAAQ,4CAAmC,CAAC;AAEzD,eAAO,MAAM,KAAK,EAAE,cAQnB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAqB,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAGrE,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAEvC,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAErD,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAE,kBAAkB,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAE3D,oBAAY,WAAW,GAAG,CAAC,KAAK,EAAE,KAAK,KAAK,aAAa,EAAE,CAAC;AAE5D,oBAAY,OAAO,GAAG;IAClB,MAAM,EAAE,WAAW,CAAC;IACpB,WAAW,EAAE;QACT,CAAC,YAAY,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;QAC7B,CAAC,YAAY,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;KAChC,CAAC;CACL,CAAC;AACF,eAAO,MAAM,WAAW,gHAUtB,CAAC;AAEH,eAAO,MAAM,KAAK,sIAAmC,CAAC"}
package/lib/index.js CHANGED
@@ -1,15 +1,17 @@
1
- import { __awaiter } from "tslib";
2
- import { CommandsReady, createCtx, prosePluginsCtx } from '@milkdown/core';
1
+ /* Copyright 2021, Milkdown by Mirone. */
2
+ import { AtomList, createProsePlugin } from '@milkdown/utils';
3
3
  import { config } from './config';
4
- import { slashPlugin } from './slash-plugin';
4
+ import { createSlashPlugin } from './prose-plugin';
5
+ import { CursorStatus } from './prose-plugin/status';
6
+ export { config } from './config';
7
+ export { CursorStatus } from './prose-plugin/status';
5
8
  export { createDropdownItem, nodeExists } from './utility';
6
- export const slashCtx = createCtx(() => []);
7
- export const slash = (pre) => {
8
- pre.inject(slashCtx, config);
9
- return (ctx) => __awaiter(void 0, void 0, void 0, function* () {
10
- yield ctx.wait(CommandsReady);
11
- const config = ctx.get(slashCtx);
12
- ctx.update(prosePluginsCtx, (prev) => prev.concat([slashPlugin(ctx, config(ctx))].flat()));
13
- });
14
- };
9
+ export const slashPlugin = createProsePlugin((options, utils) => {
10
+ var _a, _b;
11
+ const slashConfig = (_a = options === null || options === void 0 ? void 0 : options.config) !== null && _a !== void 0 ? _a : config;
12
+ const placeholder = Object.assign({ [CursorStatus.Empty]: 'Type / to use the slash commands...', [CursorStatus.Slash]: 'Type to filter...' }, ((_b = options === null || options === void 0 ? void 0 : options.placeholder) !== null && _b !== void 0 ? _b : {}));
13
+ const cfg = slashConfig(utils);
14
+ return createSlashPlugin(utils, cfg, placeholder);
15
+ });
16
+ export const slash = AtomList.create([slashPlugin()]);
15
17
  //# sourceMappingURL=index.js.map
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,aAAa,EAAE,SAAS,EAAuB,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAChG,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,OAAO,EAAE,kBAAkB,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAI3D,MAAM,CAAC,MAAM,QAAQ,GAAG,SAAS,CAAc,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC;AAEzD,MAAM,CAAC,MAAM,KAAK,GAAmB,CAAC,GAAG,EAAE,EAAE;IACzC,GAAG,CAAC,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;IAE7B,OAAO,CAAO,GAAG,EAAE,EAAE;QACjB,MAAM,GAAG,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;QAC9B,MAAM,MAAM,GAAG,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QACjC,GAAG,CAAC,MAAM,CAAC,eAAe,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,WAAW,CAAC,GAAG,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;IAC/F,CAAC,CAAA,CAAC;AACN,CAAC,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,yCAAyC;AACzC,OAAO,EAAE,QAAQ,EAAE,iBAAiB,EAAS,MAAM,iBAAiB,CAAC;AAErE,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAErD,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAE,kBAAkB,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAW3D,MAAM,CAAC,MAAM,WAAW,GAAG,iBAAiB,CAAU,CAAC,OAAO,EAAE,KAAK,EAAE,EAAE;;IACrE,MAAM,WAAW,GAAG,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,MAAM,mCAAI,MAAM,CAAC;IAC9C,MAAM,WAAW,mBACb,CAAC,YAAY,CAAC,KAAK,CAAC,EAAE,qCAAqC,EAC3D,CAAC,YAAY,CAAC,KAAK,CAAC,EAAE,mBAAmB,IACtC,CAAC,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,WAAW,mCAAI,EAAE,CAAC,CAClC,CAAC;IACF,MAAM,GAAG,GAAG,WAAW,CAAC,KAAK,CAAC,CAAC;IAE/B,OAAO,iBAAiB,CAAC,KAAK,EAAE,GAAG,EAAE,WAAW,CAAC,CAAC;AACtD,CAAC,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,KAAK,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC"}
package/lib/item.d.ts CHANGED
@@ -1,12 +1,13 @@
1
1
  import type { Command } from 'prosemirror-commands';
2
2
  import type { Schema } from 'prosemirror-model';
3
3
  export declare type Action = {
4
+ id: string;
4
5
  $: HTMLElement;
5
6
  keyword: string[];
6
7
  command: Command;
7
8
  enable: (schema: Schema) => boolean;
8
9
  };
9
- export declare type WrappedAction = Pick<Action, 'keyword'> & {
10
+ export declare type WrappedAction = Pick<Action, 'keyword' | 'id'> & {
10
11
  enable: (schema: Schema) => boolean;
11
12
  command: () => void;
12
13
  dom: HTMLElement;
package/lib/item.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"item.d.ts","sourceRoot":"","sources":["../src/item.ts"],"names":[],"mappings":"AAA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,CAAC"}
package/lib/item.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { cleanUpAndCreateNode } from './utility';
2
2
  export const transformAction = (action) => ({
3
+ id: action.id,
3
4
  keyword: action.keyword,
4
5
  $: action.dom,
5
6
  command: cleanUpAndCreateNode(action.command),
package/lib/item.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"item.js","sourceRoot":"","sources":["../src/item.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AAejD,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,MAAqB,EAAU,EAAE,CAAC,CAAC;IAC/D,OAAO,EAAE,MAAM,CAAC,OAAO;IACvB,CAAC,EAAE,MAAM,CAAC,GAAG;IACb,OAAO,EAAE,oBAAoB,CAAC,MAAM,CAAC,OAAO,CAAC;IAC7C,MAAM,EAAE,MAAM,CAAC,MAAM;CACxB,CAAC,CAAC"}
1
+ {"version":3,"file":"item.js","sourceRoot":"","sources":["../src/item.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AAgBjD,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,MAAqB,EAAU,EAAE,CAAC,CAAC;IAC/D,EAAE,EAAE,MAAM,CAAC,EAAE;IACb,OAAO,EAAE,MAAM,CAAC,OAAO;IACvB,CAAC,EAAE,MAAM,CAAC,GAAG;IACb,OAAO,EAAE,oBAAoB,CAAC,MAAM,CAAC,OAAO,CAAC;IAC7C,MAAM,EAAE,MAAM,CAAC,MAAM;CACxB,CAAC,CAAC"}
@@ -0,0 +1,4 @@
1
+ import { Action } from '../item';
2
+ import { Status } from './status';
3
+ export declare const renderDropdown: (status: Status, dropdownElement: HTMLElement, items: Action[]) => boolean;
4
+ //# sourceMappingURL=dropdown.d.ts.map
@@ -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,SAAS,CAAC;AACjC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC,eAAO,MAAM,cAAc,WAAY,MAAM,mBAAmB,WAAW,SAAS,MAAM,EAAE,KAAG,OA0C9F,CAAC"}
@@ -0,0 +1,39 @@
1
+ /* Copyright 2021, Milkdown by Mirone. */
2
+ import scrollIntoView from 'smooth-scroll-into-view-if-needed';
3
+ export const renderDropdown = (status, dropdownElement, items) => {
4
+ const { filter } = status.get();
5
+ if (!status.isSlash()) {
6
+ dropdownElement.classList.add('hide');
7
+ return false;
8
+ }
9
+ const activeList = items
10
+ .filter((item) => {
11
+ item.$.classList.remove('active');
12
+ const result = item.keyword.some((key) => key.includes(filter.toLocaleLowerCase()));
13
+ if (result) {
14
+ return true;
15
+ }
16
+ item.$.classList.add('hide');
17
+ return false;
18
+ })
19
+ .map((item) => {
20
+ item.$.classList.remove('hide');
21
+ return item;
22
+ });
23
+ status.setActions(activeList);
24
+ if (activeList.length === 0) {
25
+ dropdownElement.classList.add('hide');
26
+ return false;
27
+ }
28
+ dropdownElement.classList.remove('hide');
29
+ activeList[0].$.classList.add('active');
30
+ requestAnimationFrame(() => {
31
+ scrollIntoView(activeList[0].$, {
32
+ scrollMode: 'if-needed',
33
+ block: 'nearest',
34
+ inline: 'nearest',
35
+ });
36
+ });
37
+ return true;
38
+ };
39
+ //# sourceMappingURL=dropdown.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dropdown.js","sourceRoot":"","sources":["../../src/prose-plugin/dropdown.ts"],"names":[],"mappings":"AAAA,yCAAyC;AACzC,OAAO,cAAc,MAAM,mCAAmC,CAAC;AAK/D,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,MAAc,EAAE,eAA4B,EAAE,KAAe,EAAW,EAAE;IACrG,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC,GAAG,EAAE,CAAC;IAEhC,IAAI,CAAC,MAAM,CAAC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EAAE,SAAS;SACpB,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;IAEH,OAAO,IAAI,CAAC;AAChB,CAAC,CAAC"}
@@ -0,0 +1,7 @@
1
+ import { Utils } from '@milkdown/utils';
2
+ import { Plugin } from 'prosemirror-state';
3
+ import { WrappedAction } from '../item';
4
+ import { CursorStatus } from './status';
5
+ export declare const key = "MILKDOWN_PLUGIN_SLASH";
6
+ export declare const createSlashPlugin: (utils: Utils, items: WrappedAction[], placeholder: Record<CursorStatus, string>) => Plugin<any, any>;
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/prose-plugin/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AACxC,OAAO,EAAE,MAAM,EAAa,MAAM,mBAAmB,CAAC;AAEtD,OAAO,EAAmB,aAAa,EAAE,MAAM,SAAS,CAAC;AAEzD,OAAO,EAAgB,YAAY,EAAE,MAAM,UAAU,CAAC;AAGtD,eAAO,MAAM,GAAG,0BAA0B,CAAC;AAE3C,eAAO,MAAM,iBAAiB,UAAW,KAAK,SAAS,aAAa,EAAE,eAAe,OAAO,YAAY,EAAE,MAAM,CAAC,qBAShH,CAAC"}
@@ -0,0 +1,16 @@
1
+ import { Plugin, PluginKey } from 'prosemirror-state';
2
+ import { transformAction } from '../item';
3
+ import { createProps } from './props';
4
+ import { createStatus } from './status';
5
+ import { createView } from './view';
6
+ export const key = 'MILKDOWN_PLUGIN_SLASH';
7
+ export const createSlashPlugin = (utils, items, placeholder) => {
8
+ const status = createStatus();
9
+ const actions = items.map(transformAction);
10
+ return new Plugin({
11
+ key: new PluginKey(key),
12
+ props: createProps(status, utils, placeholder),
13
+ view: (view) => createView(status, actions, view, utils),
14
+ });
15
+ };
16
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/prose-plugin/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAEtD,OAAO,EAAE,eAAe,EAAiB,MAAM,SAAS,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AACtC,OAAO,EAAE,YAAY,EAAgB,MAAM,UAAU,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAEpC,MAAM,CAAC,MAAM,GAAG,GAAG,uBAAuB,CAAC;AAE3C,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,KAAY,EAAE,KAAsB,EAAE,WAAyC,EAAE,EAAE;IACjH,MAAM,MAAM,GAAG,YAAY,EAAE,CAAC;IAC9B,MAAM,OAAO,GAAG,KAAK,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;IAE3C,OAAO,IAAI,MAAM,CAAC;QACd,GAAG,EAAE,IAAI,SAAS,CAAC,GAAG,CAAC;QACvB,KAAK,EAAE,WAAW,CAAC,MAAM,EAAE,KAAK,EAAE,WAAW,CAAC;QAC9C,IAAI,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,UAAU,CAAC,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,CAAC;KAC3D,CAAC,CAAC;AACP,CAAC,CAAC"}
@@ -0,0 +1,15 @@
1
+ import { EditorView } from 'prosemirror-view';
2
+ import { Action } from '../item';
3
+ import { Status } from './status';
4
+ export declare const createMouseManager: () => {
5
+ isLock: () => boolean;
6
+ lock: () => void;
7
+ unlock: () => void;
8
+ };
9
+ export declare type MouseManager = ReturnType<typeof createMouseManager>;
10
+ export declare const handleMouseMove: (mouseManager: MouseManager) => () => void;
11
+ export declare const handleMouseEnter: (status: Status, mouseManager: MouseManager) => (e: MouseEvent) => void;
12
+ export declare const handleMouseLeave: () => (e: MouseEvent) => void;
13
+ export declare const handleClick: (status: Status, items: Action[], view: EditorView, dropdownElement: HTMLElement) => (e: Event) => void;
14
+ export declare const handleKeydown: (status: Status, view: EditorView, dropdownElement: HTMLElement, mouseManager: MouseManager) => (e: Event) => void;
15
+ //# sourceMappingURL=input.d.ts.map
@@ -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,kBAAkB,CAAC;AAG9C,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,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,SAS7F,CAAC;AAEF,eAAO,MAAM,gBAAgB,YAAa,UAAU,SAInD,CAAC;AAEF,eAAO,MAAM,WAAW,WACX,MAAM,SAAS,MAAM,EAAE,QAAQ,UAAU,mBAAmB,WAAW,SAC5E,KAAK,KAAG,IAuBX,CAAC;AAEN,eAAO,MAAM,aAAa,WACb,MAAM,QAAQ,UAAU,mBAAmB,WAAW,gBAAgB,YAAY,SAAS,KAAK,SA+CxG,CAAC"}
@@ -0,0 +1,101 @@
1
+ /* Copyright 2021, Milkdown by Mirone. */
2
+ import scrollIntoView from 'smooth-scroll-into-view-if-needed';
3
+ export const createMouseManager = () => {
4
+ let mouseLock = false;
5
+ return {
6
+ isLock: () => mouseLock,
7
+ lock: () => {
8
+ mouseLock = true;
9
+ },
10
+ unlock: () => {
11
+ mouseLock = false;
12
+ },
13
+ };
14
+ };
15
+ export const handleMouseMove = (mouseManager) => () => {
16
+ mouseManager.unlock();
17
+ };
18
+ export const handleMouseEnter = (status, mouseManager) => (e) => {
19
+ if (mouseManager.isLock())
20
+ return;
21
+ const active = status.get().activeActions.findIndex((x) => x.$.classList.contains('active'));
22
+ if (active >= 0) {
23
+ status.get().activeActions[active].$.classList.remove('active');
24
+ }
25
+ const { target } = e;
26
+ if (!(target instanceof HTMLElement))
27
+ return;
28
+ target.classList.add('active');
29
+ };
30
+ export const handleMouseLeave = () => (e) => {
31
+ const { target } = e;
32
+ if (!(target instanceof HTMLElement))
33
+ return;
34
+ target.classList.remove('active');
35
+ };
36
+ export const handleClick = (status, items, view, dropdownElement) => (e) => {
37
+ const { target } = e;
38
+ if (!(target instanceof HTMLElement))
39
+ return;
40
+ if (!view)
41
+ return;
42
+ const stop = () => {
43
+ e.stopPropagation();
44
+ e.preventDefault();
45
+ };
46
+ const el = Object.values(items).find(({ $ }) => $.contains(target));
47
+ if (!el) {
48
+ if (status.isEmpty())
49
+ return;
50
+ status.clearStatus();
51
+ dropdownElement.classList.add('hide');
52
+ stop();
53
+ return;
54
+ }
55
+ stop();
56
+ el.command(view.state, view.dispatch, view);
57
+ };
58
+ export const handleKeydown = (status, view, dropdownElement, mouseManager) => (e) => {
59
+ if (!(e instanceof KeyboardEvent))
60
+ return;
61
+ if (!mouseManager.isLock())
62
+ mouseManager.lock();
63
+ const { key } = e;
64
+ if (!status.isSlash())
65
+ return;
66
+ if (!['ArrowDown', 'ArrowUp', 'Enter', 'Escape'].includes(key))
67
+ return;
68
+ const { activeActions } = status.get();
69
+ let active = activeActions.findIndex(({ $ }) => $.classList.contains('active'));
70
+ if (active < 0)
71
+ active = 0;
72
+ const moveActive = (next) => {
73
+ activeActions[active].$.classList.remove('active');
74
+ activeActions[next].$.classList.add('active');
75
+ scrollIntoView(activeActions[next].$, {
76
+ scrollMode: 'if-needed',
77
+ block: 'nearest',
78
+ inline: 'nearest',
79
+ });
80
+ };
81
+ if (key === 'ArrowDown') {
82
+ const next = active === activeActions.length - 1 ? 0 : active + 1;
83
+ moveActive(next);
84
+ return;
85
+ }
86
+ if (key === 'ArrowUp') {
87
+ const next = active === 0 ? activeActions.length - 1 : active - 1;
88
+ moveActive(next);
89
+ return;
90
+ }
91
+ if (key === 'Escape') {
92
+ if (status.isEmpty())
93
+ return;
94
+ status.clearStatus();
95
+ dropdownElement.classList.add('hide');
96
+ return;
97
+ }
98
+ activeActions[active].command(view.state, view.dispatch, view);
99
+ activeActions[active].$.classList.remove('active');
100
+ };
101
+ //# sourceMappingURL=input.js.map