@milkdown/plugin-slash 4.14.2 → 5.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/README.md +42 -59
  2. package/lib/config.d.ts +20 -2
  3. package/lib/config.d.ts.map +1 -1
  4. package/lib/config.js +112 -81
  5. package/lib/config.js.map +1 -1
  6. package/lib/index.d.ts +22 -16
  7. package/lib/index.d.ts.map +1 -1
  8. package/lib/index.js +13 -18
  9. package/lib/index.js.map +1 -1
  10. package/lib/item.d.ts +2 -5
  11. package/lib/item.d.ts.map +1 -1
  12. package/lib/item.js +0 -2
  13. package/lib/item.js.map +1 -1
  14. package/lib/prose-plugin/dropdown.d.ts +6 -2
  15. package/lib/prose-plugin/dropdown.d.ts.map +1 -1
  16. package/lib/prose-plugin/dropdown.js +16 -23
  17. package/lib/prose-plugin/dropdown.js.map +1 -1
  18. package/lib/prose-plugin/index.d.ts +3 -4
  19. package/lib/prose-plugin/index.d.ts.map +1 -1
  20. package/lib/prose-plugin/index.js +4 -6
  21. package/lib/prose-plugin/index.js.map +1 -1
  22. package/lib/prose-plugin/input.d.ts +1 -2
  23. package/lib/prose-plugin/input.d.ts.map +1 -1
  24. package/lib/prose-plugin/input.js +18 -16
  25. package/lib/prose-plugin/input.js.map +1 -1
  26. package/lib/prose-plugin/props.d.ts +3 -3
  27. package/lib/prose-plugin/props.d.ts.map +1 -1
  28. package/lib/prose-plugin/props.js +21 -27
  29. package/lib/prose-plugin/props.js.map +1 -1
  30. package/lib/prose-plugin/status.d.ts +6 -12
  31. package/lib/prose-plugin/status.d.ts.map +1 -1
  32. package/lib/prose-plugin/status.js +16 -24
  33. package/lib/prose-plugin/status.js.map +1 -1
  34. package/lib/prose-plugin/view.d.ts +1 -2
  35. package/lib/prose-plugin/view.d.ts.map +1 -1
  36. package/lib/prose-plugin/view.js +6 -10
  37. package/lib/prose-plugin/view.js.map +1 -1
  38. package/lib/utility.d.ts +1 -2
  39. package/lib/utility.d.ts.map +1 -1
  40. package/lib/utility.js +0 -1
  41. package/lib/utility.js.map +1 -1
  42. package/package.json +3 -3
  43. package/src/config.ts +134 -82
  44. package/src/index.ts +17 -34
  45. package/src/item.ts +2 -7
  46. package/src/prose-plugin/dropdown.ts +22 -25
  47. package/src/prose-plugin/index.ts +7 -13
  48. package/src/prose-plugin/input.ts +19 -17
  49. package/src/prose-plugin/props.ts +26 -35
  50. package/src/prose-plugin/status.ts +19 -30
  51. package/src/prose-plugin/view.ts +6 -11
  52. package/src/utility.ts +1 -3
package/README.md CHANGED
@@ -19,77 +19,60 @@ Editor.make().use(nord).use(commonmark).use(slash).create();
19
19
 
20
20
  ## config
21
21
 
22
- Modify the list of slash plugin.
22
+ Configure the slash plugin placeholders & items with custom status builder.
23
23
 
24
24
  Example:
25
25
 
26
26
  ```typescript
27
- import { slashPlugin, slash, createDropdownItem, config, nodeExists } from '@milkdown/plugin-slash';
27
+ import { slashPlugin, slash, createDropdownItem, defaultActions } from '@milkdown/plugin-slash';
28
+ import { themeToolCtx, commandsCtx } from '@milkdown/core';
28
29
 
29
30
  Editor.make().use(
30
31
  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...',
32
+ config: (ctx) => {
33
+ // Get default slash plugin items
34
+ const actions = defaultActions(ctx);
35
+
36
+ // Define a status builder
37
+ return ({ isTopLevel, content, parentNode }) => {
38
+ // You can only show something at root level
39
+ if (!isTopLevel) return null;
40
+
41
+ // Empty content ? Set your custom empty placeholder !
42
+ if (!content) {
43
+ return { placeholder: 'Type / to use the slash commands...' };
44
+ }
45
+
46
+ // Define the placeholder & actions (dropdown items) you want to display depending on content
47
+ if (content.startsWith('/')) {
48
+ // Add some actions depending on your content's parent node
49
+ if (parentNode.type.name === 'customNode') {
50
+ actions.push({
51
+ id: 'custom',
52
+ dom: createDropdownItem(ctx.get(themeToolCtx), 'Custom', 'h1'),
53
+ command: () => ctx.get(commandsCtx).call(/* Add custom command here */),
54
+ keyword: ['custom'],
55
+ enable: () => true,
56
+ });
57
+ }
58
+
59
+ return content === '/'
60
+ ? {
61
+ placeholder: 'Type to filter...',
62
+ actions,
63
+ }
64
+ : {
65
+ actions: actions.filter(({ keyword }) =>
66
+ keyword.some((key) => key.includes(content.slice(1).toLocaleLowerCase())),
67
+ ),
68
+ };
69
+ }
70
+ };
61
71
  },
62
72
  }),
63
73
  );
64
74
  ```
65
75
 
66
- ## shouldDisplay
67
-
68
- Control wether the slash dropdown list should be displayed.
69
-
70
- Example:
71
-
72
- ```typescript
73
- import { slashPlugin, slash } from '@milkdown/plugin-slash';
74
-
75
- Editor.make().use(
76
- slash.configure(slashPlugin, {
77
- shouldDisplay: (parent, state) => {
78
- const noMoreThanOne = parent.node.childCount <= 1;
79
- const isTopLevel = state.selection.$from.depth === 1;
80
- return noMoreThanOne && isTopLevel;
81
- },
82
- }),
83
- );
84
- ```
85
-
86
- `shouldDisplay` will only be triggered when selection is in paragraph node.
87
-
88
- - parent:
89
- Paragraph node which holds the current text node.
90
- - state:
91
- Current editor state.
92
-
93
76
  # License
94
77
 
95
78
  Milkdown is open sourced software licensed under [MIT license](https://github.com/Saul-Mirone/milkdown/blob/main/LICENSE).
package/lib/config.d.ts CHANGED
@@ -1,3 +1,21 @@
1
- import type { SlashConfig } from '.';
2
- export declare const config: SlashConfig;
1
+ /// <reference types="prosemirror-model" />
2
+ import type { Ctx } from '@milkdown/ctx';
3
+ import { EditorState, Node } from '@milkdown/prose';
4
+ import { WrappedAction } from './item';
5
+ declare type Nullable<T> = T | null | undefined;
6
+ export declare type StatusConfig = {
7
+ placeholder?: Nullable<string>;
8
+ actions?: Nullable<WrappedAction[]>;
9
+ };
10
+ export declare type StatusConfigBuilderParams = {
11
+ content: string;
12
+ isTopLevel: boolean;
13
+ parentNode: Node;
14
+ state: EditorState;
15
+ };
16
+ export declare type StatusConfigBuilder = (params: StatusConfigBuilderParams) => Nullable<StatusConfig>;
17
+ export declare type Config = (ctx: Ctx) => StatusConfigBuilder;
18
+ export declare const defaultActions: (ctx: Ctx, input?: string) => WrappedAction[];
19
+ export declare const defaultConfig: Config;
20
+ export {};
3
21
  //# sourceMappingURL=config.d.ts.map
@@ -1 +1 @@
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"}
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":";AAEA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AAYzC,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/config.js CHANGED
@@ -1,84 +1,115 @@
1
+ import { __rest } from "tslib";
1
2
  /* Copyright 2021, Milkdown by Mirone. */
2
- import { commandsCtx, themeToolCtx } from '@milkdown/core';
3
+ import { commandsCtx, schemaCtx, themeToolCtx } from '@milkdown/core';
3
4
  import { InsertHr, InsertImage, InsertTable, TurnIntoCodeFence, TurnIntoHeading, TurnIntoTaskList, WrapInBlockquote, WrapInBulletList, WrapInOrderedList, } from '@milkdown/preset-gfm';
4
- import { createDropdownItem, nodeExists } from './utility';
5
- export const config = ({ ctx }) => [
6
- {
7
- id: 'h1',
8
- dom: createDropdownItem(ctx.get(themeToolCtx), 'Large Heading', 'h1'),
9
- command: () => ctx.get(commandsCtx).call(TurnIntoHeading, 1),
10
- keyword: ['h1', 'large heading'],
11
- enable: nodeExists('heading'),
12
- },
13
- {
14
- id: 'h2',
15
- dom: createDropdownItem(ctx.get(themeToolCtx), 'Medium Heading', 'h2'),
16
- command: () => ctx.get(commandsCtx).call(TurnIntoHeading, 2),
17
- keyword: ['h2', 'medium heading'],
18
- enable: nodeExists('heading'),
19
- },
20
- {
21
- id: 'h3',
22
- dom: createDropdownItem(ctx.get(themeToolCtx), 'Small Heading', 'h3'),
23
- command: () => ctx.get(commandsCtx).call(TurnIntoHeading, 3),
24
- keyword: ['h3', 'small heading'],
25
- enable: nodeExists('heading'),
26
- },
27
- {
28
- id: 'bulletList',
29
- dom: createDropdownItem(ctx.get(themeToolCtx), 'Bullet List', 'bulletList'),
30
- command: () => ctx.get(commandsCtx).call(WrapInBulletList),
31
- keyword: ['bullet list', 'ul'],
32
- enable: nodeExists('bullet_list'),
33
- },
34
- {
35
- id: 'orderedList',
36
- dom: createDropdownItem(ctx.get(themeToolCtx), 'Ordered List', 'orderedList'),
37
- command: () => ctx.get(commandsCtx).call(WrapInOrderedList),
38
- keyword: ['ordered list', 'ol'],
39
- enable: nodeExists('ordered_list'),
40
- },
41
- {
42
- id: 'taskList',
43
- dom: createDropdownItem(ctx.get(themeToolCtx), 'Task List', 'taskList'),
44
- command: () => ctx.get(commandsCtx).call(TurnIntoTaskList),
45
- keyword: ['task list', 'task'],
46
- enable: nodeExists('task_list_item'),
47
- },
48
- {
49
- id: 'image',
50
- dom: createDropdownItem(ctx.get(themeToolCtx), 'Image', 'image'),
51
- command: () => ctx.get(commandsCtx).call(InsertImage),
52
- keyword: ['image'],
53
- enable: nodeExists('image'),
54
- },
55
- {
56
- id: 'blockquote',
57
- dom: createDropdownItem(ctx.get(themeToolCtx), 'Quote', 'quote'),
58
- command: () => ctx.get(commandsCtx).call(WrapInBlockquote),
59
- keyword: ['quote', 'blockquote'],
60
- enable: nodeExists('blockquote'),
61
- },
62
- {
63
- id: 'table',
64
- dom: createDropdownItem(ctx.get(themeToolCtx), 'Table', 'table'),
65
- command: () => ctx.get(commandsCtx).call(InsertTable),
66
- keyword: ['table'],
67
- enable: nodeExists('table'),
68
- },
69
- {
70
- id: 'code',
71
- dom: createDropdownItem(ctx.get(themeToolCtx), 'Code Fence', 'code'),
72
- command: () => ctx.get(commandsCtx).call(TurnIntoCodeFence),
73
- keyword: ['code'],
74
- enable: nodeExists('fence'),
75
- },
76
- {
77
- id: 'divider',
78
- dom: createDropdownItem(ctx.get(themeToolCtx), 'Divide Line', 'divider'),
79
- command: () => ctx.get(commandsCtx).call(InsertHr),
80
- keyword: ['divider', 'hr'],
81
- enable: nodeExists('hr'),
82
- },
83
- ];
5
+ import { createDropdownItem } from './utility';
6
+ export const defaultActions = (ctx, input = '/') => {
7
+ const { nodes } = ctx.get(schemaCtx);
8
+ const actions = [
9
+ {
10
+ id: 'h1',
11
+ dom: createDropdownItem(ctx.get(themeToolCtx), 'Large Heading', 'h1'),
12
+ command: () => ctx.get(commandsCtx).call(TurnIntoHeading, 1),
13
+ keyword: ['h1', 'large heading'],
14
+ typeName: 'heading',
15
+ },
16
+ {
17
+ id: 'h2',
18
+ dom: createDropdownItem(ctx.get(themeToolCtx), 'Medium Heading', 'h2'),
19
+ command: () => ctx.get(commandsCtx).call(TurnIntoHeading, 2),
20
+ keyword: ['h2', 'medium heading'],
21
+ typeName: 'heading',
22
+ },
23
+ {
24
+ id: 'h3',
25
+ dom: createDropdownItem(ctx.get(themeToolCtx), 'Small Heading', 'h3'),
26
+ command: () => ctx.get(commandsCtx).call(TurnIntoHeading, 3),
27
+ keyword: ['h3', 'small heading'],
28
+ typeName: 'heading',
29
+ },
30
+ {
31
+ id: 'bulletList',
32
+ dom: createDropdownItem(ctx.get(themeToolCtx), 'Bullet List', 'bulletList'),
33
+ command: () => ctx.get(commandsCtx).call(WrapInBulletList),
34
+ keyword: ['bullet list', 'ul'],
35
+ typeName: 'bullet_list',
36
+ },
37
+ {
38
+ id: 'orderedList',
39
+ dom: createDropdownItem(ctx.get(themeToolCtx), 'Ordered List', 'orderedList'),
40
+ command: () => ctx.get(commandsCtx).call(WrapInOrderedList),
41
+ keyword: ['ordered list', 'ol'],
42
+ typeName: 'ordered_list',
43
+ },
44
+ {
45
+ id: 'taskList',
46
+ dom: createDropdownItem(ctx.get(themeToolCtx), 'Task List', 'taskList'),
47
+ command: () => ctx.get(commandsCtx).call(TurnIntoTaskList),
48
+ keyword: ['task list', 'task'],
49
+ typeName: 'task_list_item',
50
+ },
51
+ {
52
+ id: 'image',
53
+ dom: createDropdownItem(ctx.get(themeToolCtx), 'Image', 'image'),
54
+ command: () => ctx.get(commandsCtx).call(InsertImage),
55
+ keyword: ['image'],
56
+ typeName: 'image',
57
+ },
58
+ {
59
+ id: 'blockquote',
60
+ dom: createDropdownItem(ctx.get(themeToolCtx), 'Quote', 'quote'),
61
+ command: () => ctx.get(commandsCtx).call(WrapInBlockquote),
62
+ keyword: ['quote', 'blockquote'],
63
+ typeName: 'blockquote',
64
+ },
65
+ {
66
+ id: 'table',
67
+ dom: createDropdownItem(ctx.get(themeToolCtx), 'Table', 'table'),
68
+ command: () => ctx.get(commandsCtx).call(InsertTable),
69
+ keyword: ['table'],
70
+ typeName: 'table',
71
+ },
72
+ {
73
+ id: 'code',
74
+ dom: createDropdownItem(ctx.get(themeToolCtx), 'Code Fence', 'code'),
75
+ command: () => ctx.get(commandsCtx).call(TurnIntoCodeFence),
76
+ keyword: ['code'],
77
+ typeName: 'fence',
78
+ },
79
+ {
80
+ id: 'divider',
81
+ dom: createDropdownItem(ctx.get(themeToolCtx), 'Divide Line', 'divider'),
82
+ command: () => ctx.get(commandsCtx).call(InsertHr),
83
+ keyword: ['divider', 'hr'],
84
+ typeName: 'hr',
85
+ },
86
+ ];
87
+ const userInput = input.slice(1).toLocaleLowerCase();
88
+ return actions
89
+ .filter((action) => !!nodes[action.typeName] && action.keyword.some((keyword) => keyword.includes(userInput)))
90
+ .map((_a) => {
91
+ var { keyword, typeName } = _a, action = __rest(_a, ["keyword", "typeName"]);
92
+ return action;
93
+ });
94
+ };
95
+ export const defaultConfig = (ctx) => {
96
+ return ({ content, isTopLevel }) => {
97
+ if (!isTopLevel)
98
+ return null;
99
+ if (!content) {
100
+ return { placeholder: 'Type / to use the slash commands...' };
101
+ }
102
+ if (content.startsWith('/')) {
103
+ return content === '/'
104
+ ? {
105
+ placeholder: 'Type to filter...',
106
+ actions: defaultActions(ctx),
107
+ }
108
+ : {
109
+ actions: defaultActions(ctx, content),
110
+ };
111
+ }
112
+ return null;
113
+ };
114
+ };
84
115
  //# sourceMappingURL=config.js.map
package/lib/config.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,yCAAyC;AACzC,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC3D,OAAO,EACH,QAAQ,EACR,WAAW,EACX,WAAW,EACX,iBAAiB,EACjB,eAAe,EACf,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,EAChB,iBAAiB,GACpB,MAAM,sBAAsB,CAAC;AAG9B,OAAO,EAAE,kBAAkB,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAE3D,MAAM,CAAC,MAAM,MAAM,GAAgB,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC;IAC5C;QACI,EAAE,EAAE,IAAI;QACR,GAAG,EAAE,kBAAkB,CAAC,GAAG,CAAC,GAAG,CAAC,YAAY,CAAC,EAAE,eAAe,EAAE,IAAI,CAAC;QACrE,OAAO,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,eAAe,EAAE,CAAC,CAAC;QAC5D,OAAO,EAAE,CAAC,IAAI,EAAE,eAAe,CAAC;QAChC,MAAM,EAAE,UAAU,CAAC,SAAS,CAAC;KAChC;IACD;QACI,EAAE,EAAE,IAAI;QACR,GAAG,EAAE,kBAAkB,CAAC,GAAG,CAAC,GAAG,CAAC,YAAY,CAAC,EAAE,gBAAgB,EAAE,IAAI,CAAC;QACtE,OAAO,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,eAAe,EAAE,CAAC,CAAC;QAC5D,OAAO,EAAE,CAAC,IAAI,EAAE,gBAAgB,CAAC;QACjC,MAAM,EAAE,UAAU,CAAC,SAAS,CAAC;KAChC;IACD;QACI,EAAE,EAAE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CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,aAAa,GAAW,CAAC,GAAG,EAAE,EAAE;IACzC,OAAO,CAAC,EAAE,OAAO,EAAE,UAAU,EAAE,EAAE,EAAE;QAC/B,IAAI,CAAC,UAAU;YAAE,OAAO,IAAI,CAAC;QAE7B,IAAI,CAAC,OAAO,EAAE;YACV,OAAO,EAAE,WAAW,EAAE,qCAAqC,EAAE,CAAC;SACjE;QAED,IAAI,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE;YACzB,OAAO,OAAO,KAAK,GAAG;gBAClB,CAAC,CAAC;oBACI,WAAW,EAAE,mBAAmB;oBAChC,OAAO,EAAE,cAAc,CAAC,GAAG,CAAC;iBAC/B;gBACH,CAAC,CAAC;oBACI,OAAO,EAAE,cAAc,CAAC,GAAG,EAAE,OAAO,CAAC;iBACxC,CAAC;SACX;QAED,OAAO,IAAI,CAAC;IAChB,CAAC,CAAC;AACN,CAAC,CAAC"}
package/lib/index.d.ts CHANGED
@@ -1,19 +1,25 @@
1
- import { EditorState, NodeWithPos } from '@milkdown/prose';
2
- import { AtomList, Utils } from '@milkdown/utils';
3
- import { WrappedAction } from './item';
4
- import { CursorStatus } from './prose-plugin/status';
5
- export { config } from './config';
6
- export { CursorStatus } from './prose-plugin/status';
7
- export { createDropdownItem, nodeExists } from './utility';
8
- export declare type SlashConfig = (utils: Utils) => WrappedAction[];
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';
9
6
  export declare type Options = {
10
- shouldDisplay: (parent: NodeWithPos, state: EditorState) => boolean;
11
- config: SlashConfig;
12
- placeholder: {
13
- [CursorStatus.Empty]: string;
14
- [CursorStatus.Slash]: string;
15
- };
7
+ config: Config;
16
8
  };
17
- export declare const slashPlugin: import("@milkdown/utils/lib/types").Origin<string, Options, import("prosemirror-state").Plugin<any, any>>;
18
- export declare const slash: AtomList<import("@milkdown/utils/lib/types").PluginWithMetadata<string, Options, import("prosemirror-state").Plugin<any, any>>>;
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/ctx").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/ctx").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/ctx").MilkdownPlugin>;
19
25
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC3D,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,aAAa,EAAE,CAAC,MAAM,EAAE,WAAW,EAAE,KAAK,EAAE,WAAW,KAAK,OAAO,CAAC;IACpE,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;AAEF,eAAO,MAAM,WAAW,2GAoBtB,CAAC;AAEH,eAAO,MAAM,KAAK,iIAAmC,CAAC"}
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,iKAAmC,CAAC"}
package/lib/index.js CHANGED
@@ -1,23 +1,18 @@
1
- import { AtomList, createProsePlugin } from '@milkdown/utils';
2
- import { config } from './config';
1
+ /* Copyright 2021, Milkdown by Mirone. */
2
+ import { AtomList, createPlugin } from '@milkdown/utils';
3
+ import { defaultConfig } from './config';
3
4
  import { createSlashPlugin } from './prose-plugin';
4
- import { CursorStatus } from './prose-plugin/status';
5
- export { config } from './config';
6
- export { CursorStatus } from './prose-plugin/status';
7
- export { createDropdownItem, nodeExists } from './utility';
8
- export const slashPlugin = createProsePlugin((options, utils) => {
9
- var _a, _b, _c;
10
- const slashConfig = (_a = options === null || options === void 0 ? void 0 : options.config) !== null && _a !== void 0 ? _a : config;
11
- 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 : {}));
12
- const cfg = slashConfig(utils);
13
- const shouldDisplay = (_c = options === null || options === void 0 ? void 0 : options.shouldDisplay) !== null && _c !== void 0 ? _c : ((parent, state) => {
14
- const isTopLevel = state.selection.$from.depth === 1;
15
- return parent.node.childCount <= 1 && isTopLevel;
16
- });
17
- const plugin = createSlashPlugin(utils, cfg, placeholder, shouldDisplay);
5
+ export { defaultActions, defaultConfig } from './config';
6
+ export { createDropdownItem } from './utility';
7
+ export const slashPlugin = createPlugin((utils, options) => {
8
+ var _a;
9
+ const slashConfig = (_a = options === null || options === void 0 ? void 0 : options.config) !== null && _a !== void 0 ? _a : defaultConfig;
18
10
  return {
19
- id: 'slash',
20
- plugin,
11
+ prosePlugins: (_, ctx) => {
12
+ const config = slashConfig(ctx);
13
+ const plugin = createSlashPlugin(utils, config);
14
+ return [plugin];
15
+ },
21
16
  };
22
17
  });
23
18
  export const slash = AtomList.create([slashPlugin()]);
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,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,k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AAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAGnD,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzD,OAAO,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAM/C,MAAM,CAAC,MAAM,WAAW,GAAG,YAAY,CAAkB,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE;;IACxE,MAAM,WAAW,GAAG,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,MAAM,mCAAI,aAAa,CAAC;IAErD,OAAO;QACH,YAAY,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE,EAAE;YACrB,MAAM,MAAM,GAAG,WAAW,CAAC,GAAG,CAAC,CAAC;YAEhC,MAAM,MAAM,GAAG,iBAAiB,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;YAEhD,OAAO,CAAC,MAAM,CAAC,CAAC;QACpB,CAAC;KACJ,CAAC;AACN,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,13 +1,10 @@
1
- import type { Command, Schema } from '@milkdown/prose';
1
+ import type { Command } from '@milkdown/prose';
2
2
  export declare type Action = {
3
3
  id: string;
4
4
  $: HTMLElement;
5
- keyword: string[];
6
5
  command: Command;
7
- enable: (schema: Schema) => boolean;
8
6
  };
9
- export declare type WrappedAction = Pick<Action, 'keyword' | 'id'> & {
10
- enable: (schema: Schema) => boolean;
7
+ export declare type WrappedAction = Pick<Action, 'id'> & {
11
8
  command: () => void;
12
9
  dom: HTMLElement;
13
10
  };
package/lib/item.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"item.d.ts","sourceRoot":"","sources":["../src/item.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAIvD,oBAAY,MAAM,GAAG;IACjB,EAAE,EAAE,MAAM,CAAC;IACX,CAAC,EAAE,WAAW,CAAC;IACf,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC;CACvC,CAAC;AAEF,oBAAY,aAAa,GAAG,IAAI,CAAC,MAAM,EAAE,SAAS,GAAG,IAAI,CAAC,GAAG;IACzD,MAAM,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC;IACpC,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,GAAG,EAAE,WAAW,CAAC;CACpB,CAAC;AAEF,eAAO,MAAM,eAAe,WAAY,aAAa,KAAG,MAMtD,CAAC"}
1
+ {"version":3,"file":"item.d.ts","sourceRoot":"","sources":["../src/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"}
package/lib/item.js CHANGED
@@ -1,9 +1,7 @@
1
1
  import { cleanUpAndCreateNode } from './utility';
2
2
  export const transformAction = (action) => ({
3
3
  id: action.id,
4
- keyword: action.keyword,
5
4
  $: action.dom,
6
5
  command: cleanUpAndCreateNode(action.command),
7
- enable: action.enable,
8
6
  });
9
7
  //# sourceMappingURL=item.js.map
package/lib/item.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"item.js","sourceRoot":"","sources":["../src/item.ts"],"names":[],"mappings":"AAGA,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"}
1
+ {"version":3,"file":"item.js","sourceRoot":"","sources":["../src/item.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AAajD,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,MAAqB,EAAU,EAAE,CAAC,CAAC;IAC/D,EAAE,EAAE,MAAM,CAAC,EAAE;IACb,CAAC,EAAE,MAAM,CAAC,GAAG;IACb,OAAO,EAAE,oBAAoB,CAAC,MAAM,CAAC,OAAO,CAAC;CAChD,CAAC,CAAC"}
@@ -1,4 +1,8 @@
1
- import { Action } from '../item';
2
1
  import { Status } from './status';
3
- export declare const renderDropdown: (status: Status, dropdownElement: HTMLElement, items: Action[]) => boolean;
2
+ declare type Listeners = {
3
+ mouseEnter: EventListener;
4
+ mouseLeave: EventListener;
5
+ };
6
+ export declare const renderDropdown: (status: Status, dropdownElement: HTMLElement, listeners: Listeners) => boolean;
7
+ export {};
4
8
  //# sourceMappingURL=dropdown.d.ts.map
@@ -1 +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"}
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,OAmCnG,CAAC"}
@@ -1,34 +1,27 @@
1
1
  /* Copyright 2021, Milkdown by Mirone. */
2
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()) {
3
+ export const renderDropdown = (status, dropdownElement, listeners) => {
4
+ const { actions } = status.get();
5
+ if (!actions.length) {
6
6
  dropdownElement.classList.add('hide');
7
7
  return false;
8
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;
9
+ dropdownElement.childNodes.forEach((child) => {
10
+ child.removeEventListener('mouseenter', listeners.mouseEnter);
11
+ child.removeEventListener('mouseleave', listeners.mouseLeave);
12
+ });
13
+ // Reset dropdownElement children
14
+ dropdownElement.textContent = '';
15
+ actions.forEach(({ $ }) => {
16
+ $.classList.remove('active');
17
+ $.addEventListener('mouseenter', listeners.mouseEnter);
18
+ $.addEventListener('mouseleave', listeners.mouseLeave);
19
+ dropdownElement.appendChild($);
22
20
  });
23
- status.setActions(activeList);
24
- if (activeList.length === 0) {
25
- dropdownElement.classList.add('hide');
26
- return false;
27
- }
28
21
  dropdownElement.classList.remove('hide');
29
- activeList[0].$.classList.add('active');
22
+ actions[0].$.classList.add('active');
30
23
  requestAnimationFrame(() => {
31
- scrollIntoView(activeList[0].$, {
24
+ scrollIntoView(actions[0].$, {
32
25
  scrollMode: 'if-needed',
33
26
  block: 'nearest',
34
27
  inline: 'nearest',
@@ -1 +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,OAAO,EAAE,EAAE;QACnB,eAAe,CAAC,SAAS,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QACtC,OAAO,KAAK,CAAC;KAChB;IAED,MAAM,UAAU,GAAG,KAAK;SACnB,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE;QACb,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QAClC,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,QAAQ,CAAC,MAAM,CAAC,iBAAiB,EAAE,CAAC,CAAC,CAAC;QACpF,IAAI,MAAM,EAAE;YACR,OAAO,IAAI,CAAC;SACf;QACD,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QAC7B,OAAO,KAAK,CAAC;IACjB,CAAC,CAAC;SACD,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;QACV,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QAChC,OAAO,IAAI,CAAC;IA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AU,CAAC,CAAC;IAClE,CAAC,CAAC,CAAC;IAEH,iCAAiC;IACjC,eAAe,CAAC,WAAW,GAAG,EAAE,CAAC;IAEjC,OAAO,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE;QACtB,CAAC,CAAC,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QAC7B,CAAC,CAAC,gBAAgB,CAAC,YAAY,EAAE,SAAS,CAAC,UAAU,CAAC,CAAC;QACvD,CAAC,CAAC,gBAAgB,CAAC,YAAY,EAAE,SAAS,CAAC,UAAU,CAAC,CAAC;QACvD,eAAe,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;IACnC,CAAC,CAAC,CAAC;IAEH,eAAe,CAAC,SAAS,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAEzC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IACrC,qBAAqB,CAAC,GAAG,EAAE;QACvB,cAAc,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE;YACzB,UAAU,EAAE,WAAW;YACvB,KAAK,EAAE,SAAS;YAChB,MAAM,EAAE,SAAS;SACpB,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;IAEH,OAAO,IAAI,CAAC;AAChB,CAAC,CAAC"}
@@ -1,7 +1,6 @@
1
- import { EditorState, NodeWithPos, Plugin } from '@milkdown/prose';
1
+ import { Plugin } from '@milkdown/prose';
2
2
  import { Utils } from '@milkdown/utils';
3
- import { WrappedAction } from '../item';
4
- import { CursorStatus } from './status';
3
+ import type { StatusConfigBuilder } from '..';
5
4
  export declare const key = "MILKDOWN_PLUGIN_SLASH";
6
- export declare const createSlashPlugin: (utils: Utils, items: WrappedAction[], placeholder: Record<CursorStatus, string>, shouldDisplay: (parent: NodeWithPos, state: EditorState) => boolean) => Plugin<any, any>;
5
+ export declare const createSlashPlugin: (utils: Utils, builder: StatusConfigBuilder) => Plugin<any, any>;
7
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/prose-plugin/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,EAAa,MAAM,iBAAiB,CAAC;AAC9E,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAExC,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,UACnB,KAAK,SACL,aAAa,EAAE,eACT,OAAO,YAAY,EAAE,MAAM,CAAC,0BACjB,WAAW,SAAS,WAAW,KAAK,OAAO,qBAUtE,CAAC"}
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"}