@milkdown/plugin-slash 4.13.0 → 4.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -62,3 +62,34 @@ Editor.make().use(
62
62
  }),
63
63
  );
64
64
  ```
65
+
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
+ # License
94
+
95
+ Milkdown is open sourced software licensed under [MIT license](https://github.com/Saul-Mirone/milkdown/blob/main/LICENSE).
package/lib/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { EditorState, NodeWithPos } from '@milkdown/prose';
1
2
  import { AtomList, Utils } from '@milkdown/utils';
2
3
  import { WrappedAction } from './item';
3
4
  import { CursorStatus } from './prose-plugin/status';
@@ -6,12 +7,13 @@ export { CursorStatus } from './prose-plugin/status';
6
7
  export { createDropdownItem, nodeExists } from './utility';
7
8
  export declare type SlashConfig = (utils: Utils) => WrappedAction[];
8
9
  export declare type Options = {
10
+ shouldDisplay: (parent: NodeWithPos, state: EditorState) => boolean;
9
11
  config: SlashConfig;
10
12
  placeholder: {
11
13
  [CursorStatus.Empty]: string;
12
14
  [CursorStatus.Slash]: string;
13
15
  };
14
16
  };
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>>>;
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>>>;
17
19
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
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"}
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"}
package/lib/index.js CHANGED
@@ -1,4 +1,3 @@
1
- /* Copyright 2021, Milkdown by Mirone. */
2
1
  import { AtomList, createProsePlugin } from '@milkdown/utils';
3
2
  import { config } from './config';
4
3
  import { createSlashPlugin } from './prose-plugin';
@@ -7,11 +6,19 @@ export { config } from './config';
7
6
  export { CursorStatus } from './prose-plugin/status';
8
7
  export { createDropdownItem, nodeExists } from './utility';
9
8
  export const slashPlugin = createProsePlugin((options, utils) => {
10
- var _a, _b;
9
+ var _a, _b, _c;
11
10
  const slashConfig = (_a = options === null || options === void 0 ? void 0 : options.config) !== null && _a !== void 0 ? _a : config;
12
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 : {}));
13
12
  const cfg = slashConfig(utils);
14
- return createSlashPlugin(utils, cfg, placeholder);
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);
18
+ return {
19
+ id: 'slash',
20
+ plugin,
21
+ };
15
22
  });
16
23
  export const slash = AtomList.create([slashPlugin()]);
17
24
  //# 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,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,C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,MAAM,EAAE,KAAK,EAAE,EAAE;QACf,MAAM,UAAU,GAAG,KAAK,CAAC,SAAS,CAAC,KAAK,CAAC,KAAK,KAAK,CAAC,CAAC;QACrD,OAAO,MAAM,CAAC,IAAI,CAAC,UAAU,IAAI,CAAC,IAAI,UAAU,CAAC;IACrD,CAAC,CAAC,CAAC;IAEP,MAAM,MAAM,GAAG,iBAAiB,CAAC,KAAK,EAAE,GAAG,EAAE,WAAW,EAAE,aAAa,CAAC,CAAC;IACzE,OAAO;QACH,EAAE,EAAE,OAAO;QACX,MAAM;KACT,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,5 +1,4 @@
1
- import type { Command } from 'prosemirror-commands';
2
- import type { Schema } from 'prosemirror-model';
1
+ import type { Command, Schema } from '@milkdown/prose';
3
2
  export declare type Action = {
4
3
  id: string;
5
4
  $: HTMLElement;
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,sBAAsB,CAAC;AACpD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAIhD,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,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"}
package/lib/item.js.map CHANGED
@@ -1 +1 @@
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"}
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,7 +1,7 @@
1
+ import { EditorState, NodeWithPos, Plugin } from '@milkdown/prose';
1
2
  import { Utils } from '@milkdown/utils';
2
- import { Plugin } from 'prosemirror-state';
3
3
  import { WrappedAction } from '../item';
4
4
  import { CursorStatus } from './status';
5
5
  export declare const key = "MILKDOWN_PLUGIN_SLASH";
6
- export declare const createSlashPlugin: (utils: Utils, items: WrappedAction[], placeholder: Record<CursorStatus, string>) => Plugin<any, any>;
6
+ export declare const createSlashPlugin: (utils: Utils, items: WrappedAction[], placeholder: Record<CursorStatus, string>, shouldDisplay: (parent: NodeWithPos, state: EditorState) => boolean) => Plugin<any, any>;
7
7
  //# 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,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"}
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,15 +1,16 @@
1
- import { Plugin, PluginKey } from 'prosemirror-state';
1
+ /* Copyright 2021, Milkdown by Mirone. */
2
+ import { Plugin, PluginKey } from '@milkdown/prose';
2
3
  import { transformAction } from '../item';
3
4
  import { createProps } from './props';
4
5
  import { createStatus } from './status';
5
6
  import { createView } from './view';
6
7
  export const key = 'MILKDOWN_PLUGIN_SLASH';
7
- export const createSlashPlugin = (utils, items, placeholder) => {
8
+ export const createSlashPlugin = (utils, items, placeholder, shouldDisplay) => {
8
9
  const status = createStatus();
9
10
  const actions = items.map(transformAction);
10
11
  return new Plugin({
11
12
  key: new PluginKey(key),
12
- props: createProps(status, utils, placeholder),
13
+ props: createProps(status, utils, placeholder, shouldDisplay),
13
14
  view: (view) => createView(status, actions, view, utils),
14
15
  });
15
16
  };
@@ -1 +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,S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C,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,EAAE,aAAa,CAAC;QAC7D,IAAI,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,UAAU,CAAC,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,CAAC;KAC3D,CAAC,CAAC;AACP,CAAC,CAAC"}
@@ -1,4 +1,4 @@
1
- import { EditorView } from 'prosemirror-view';
1
+ import { EditorView } from '@milkdown/prose';
2
2
  import { Action } from '../item';
3
3
  import { Status } from './status';
4
4
  export declare const createMouseManager: () => {
@@ -1 +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"}
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,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"}
@@ -1,9 +1,8 @@
1
+ import { DecorationSet, EditorState, EditorView, NodeWithPos } from '@milkdown/prose';
1
2
  import { Utils } from '@milkdown/utils';
2
- import { EditorState } from 'prosemirror-state';
3
- import { DecorationSet, EditorView } from 'prosemirror-view';
4
3
  import { CursorStatus, Status } from './status';
5
4
  export declare type Props = ReturnType<typeof createProps>;
6
- export declare const createProps: (status: Status, utils: Utils, placeholder: Record<CursorStatus, string>) => {
5
+ export declare const createProps: (status: Status, utils: Utils, placeholder: Record<CursorStatus, string>, shouldDisplay: (parent: NodeWithPos, state: EditorState) => boolean) => {
7
6
  handleKeyDown: (_: EditorView, event: Event) => boolean;
8
7
  decorations: (state: EditorState) => DecorationSet<any> | null | undefined;
9
8
  };
@@ -1 +1 @@
1
- {"version":3,"file":"props.d.ts","sourceRoot":"","sources":["../../src/prose-plugin/props.ts"],"names":[],"mappings":"AAGA,OAAO,EAAkB,KAAK,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAc,aAAa,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEzE,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAEhD,oBAAY,KAAK,GAAG,UAAU,CAAC,OAAO,WAAW,CAAC,CAAC;AAuBnD,eAAO,MAAM,WAAW,WAAY,MAAM,SAAS,KAAK,eAAe,OAAO,YAAY,EAAE,MAAM,CAAC;uBAKxE,UAAU,SAAS,KAAK;yBAetB,WAAW;CA4CvC,CAAC"}
1
+ {"version":3,"file":"props.d.ts","sourceRoot":"","sources":["../../src/prose-plugin/props.ts"],"names":[],"mappings":"AAGA,OAAO,EAAc,aAAa,EAAE,WAAW,EAAE,UAAU,EAAkB,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAClH,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAExC,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAEhD,oBAAY,KAAK,GAAG,UAAU,CAAC,OAAO,WAAW,CAAC,CAAC;AAuBnD,eAAO,MAAM,WAAW,WACZ,MAAM,SACP,KAAK,eACC,OAAO,YAAY,EAAE,MAAM,CAAC,0BACjB,WAAW,SAAS,WAAW,KAAK,OAAO;uBAM5C,UAAU,SAAS,KAAK;yBAetB,WAAW;CA2CvC,CAAC"}
@@ -1,7 +1,6 @@
1
1
  /* Copyright 2021, Milkdown by Mirone. */
2
2
  import { css } from '@emotion/css';
3
- import { findParentNode } from '@milkdown/utils';
4
- import { Decoration, DecorationSet } from 'prosemirror-view';
3
+ import { Decoration, DecorationSet, findParentNode } from '@milkdown/prose';
5
4
  import { CursorStatus } from './status';
6
5
  const createEmptyStyle = ({ font, palette }) => css `
7
6
  position: relative;
@@ -22,7 +21,7 @@ const createSlashStyle = () => css `
22
21
  left: 0.5rem;
23
22
  }
24
23
  `;
25
- export const createProps = (status, utils, placeholder) => {
24
+ export const createProps = (status, utils, placeholder, shouldDisplay) => {
26
25
  const emptyStyle = utils.getStyle(createEmptyStyle);
27
26
  const slashStyle = utils.getStyle(createSlashStyle);
28
27
  return {
@@ -41,8 +40,7 @@ export const createProps = (status, utils, placeholder) => {
41
40
  },
42
41
  decorations: (state) => {
43
42
  const parent = findParentNode(({ type }) => type.name === 'paragraph')(state.selection);
44
- const isTopLevel = state.selection.$from.depth === 1;
45
- if (!parent || parent.node.childCount > 1 || !isTopLevel) {
43
+ if (!parent || !shouldDisplay(parent, state)) {
46
44
  status.clearStatus();
47
45
  return;
48
46
  }
@@ -1 +1 @@
1
- {"version":3,"file":"props.js","sourceRoot":"","sources":["../../src/prose-plugin/props.ts"],"names":[],"mappings":"AAAA,yCAAyC;AACzC,OAAO,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AAEnC,OAAO,EAAE,cAAc,EAAS,MAAM,iBAAiB,CAAC;AAExD,OAAO,EAAE,UAAU,EAAE,aAAa,EAAc,MAAM,kBAAkB,CAAC;AAEzE,OAAO,EAAE,YAAY,EAAU,MAAM,UAAU,CAAC;AAIhD,MAAM,gBAAgB,GAAG,CAAC,EAAE,IAAI,EAAE,OAAO,EAAa,EAAE,EAAE,CAAC,GAAG,CAAA;;;;;uBAKvC,IAAI,CAAC,UAAU;;iBAErB,OAAO,CAAC,SAAS,EAAE,GAAG,CAAC;;;;;;CAMvC,CAAC;AAEF,MAAM,gBAAgB,GAAG,GAAG,EAAE,CAAC,GAAG,CAAA;;;;CAIjC,CAAC;AAEF,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,MAAc,EAAE,KAAY,EAAE,WAAyC,EAAE,EAAE;IACnG,MAAM,UAAU,GAAG,KAAK,CAAC,QAAQ,CAAC,gBAAgB,CAAC,CAAC;IACpD,MAAM,UAAU,GAAG,KAAK,CAAC,QAAQ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CAAC,CAAC;YACP,CAAC,CAAC;YAEF,IAAI,OAAO,EAAE;gBACT,MAAM,CAAC,WAAW,EAAE,CAAC;gBACrB,MAAM,IAAI,GAAG,WAAW,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;gBAC7C,OAAO,gBAAgB,CAAC,IAAI,EAAE,CAAC,UAAU,EAAE,YAAY,CAAC,CAAC,CAAC;aAC7D;YAED,IAAI,OAAO,EAAE;gBACT,MAAM,CAAC,QAAQ,EAAE,CAAC;gBAClB,MAAM,IAAI,GAAG,WAAW,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;gBAC7C,OAAO,gBAAgB,CAAC,IAAI,EAAE,CAAC,UAAU,EAAE,UAAU,EAAE,YAAY,EAAE,UAAU,CAAC,CAAC,CAAC;aACrF;YAED,IAAI,QAAQ,EAAE;gBACV,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;gBAClD,OAAO,IAAI,CAAC;aACf;YAED,MAAM,CAAC,WAAW,EAAE,CAAC;YACrB,OAAO,IAAI,CAAC;QAChB,CAAC;KACJ,CAAC;AACN,CAAC,CAAC"}
@@ -1,5 +1,5 @@
1
+ import { EditorView } from '@milkdown/prose';
1
2
  import { Utils } from '@milkdown/utils';
2
- import { EditorView } from 'prosemirror-view';
3
3
  import { Action } from '../item';
4
4
  import { Status } from './status';
5
5
  export declare const createView: (status: Status, items: Action[], view: EditorView, utils: Utils) => {
@@ -1 +1 @@
1
- {"version":3,"file":"view.d.ts","sourceRoot":"","sources":["../../src/prose-plugin/view.ts"],"names":[],"mappings":"AACA,OAAO,EAAyB,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAC/D,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAWjC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAkBlC,eAAO,MAAM,UAAU,WAAY,MAAM,SAAS,MAAM,EAAE,QAAQ,UAAU,SAAS,KAAK;;;;mBA0BnE,UAAU;;CAehC,CAAC"}
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;AAExC,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAWjC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAkBlC,eAAO,MAAM,UAAU,WAAY,MAAM,SAAS,MAAM,EAAE,QAAQ,UAAU,SAAS,KAAK;;;;mBA0BnE,UAAU;;CAehC,CAAC"}
@@ -1,5 +1,5 @@
1
1
  /* Copyright 2021, Milkdown by Mirone. */
2
- import { calculateNodePosition } from '@milkdown/utils';
2
+ import { calculateNodePosition } from '@milkdown/prose';
3
3
  import { createDropdown } from '../utility';
4
4
  import { renderDropdown } from './dropdown';
5
5
  import { createMouseManager, handleClick, handleKeydown, handleMouseEnter, handleMouseLeave, handleMouseMove, } from './input';
@@ -1 +1 @@
1
- {"version":3,"file":"view.js","sourceRoot":"","sources":["../../src/prose-plugin/view.ts"],"names":[],"mappings":"AAAA,yCAAyC;AACzC,OAAO,EAAE,qBAAqB,EAAS,MAAM,iBAAiB,CAAC;AAI/D,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EACH,kBAAkB,EAClB,WAAW,EACX,aAAa,EACb,gBAAgB,EAChB,gBAAgB,EAChB,eAAe,GAClB,MAAM,SAAS,CAAC;AAGjB,MAAM,iBAAiB,GAAG,CAAC,IAAgB,EAAE,eAA4B,EAAE,EAAE;IACzE,qBAAqB,CAAC,IAAI,EAAE,eAAe,EAAE,CAAC,QAAQ,EAAE,MAA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AmB,CAAC,WAAW,EAAE,UAAU,CAAC,CAAC;YACrD,OAAO,CAAC,mBAAmB,CAAC,WAAW,EAAE,UAAU,CAAC,CAAC;YACrD,OAAO,CAAC,mBAAmB,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;YACjD,eAAe,CAAC,MAAM,EAAE,CAAC;QAC7B,CAAC;KACJ,CAAC;AACN,CAAC,CAAC"}
package/lib/utility.d.ts CHANGED
@@ -1,8 +1,7 @@
1
1
  import type { ThemeTool } from '@milkdown/core';
2
2
  import type { Icon } from '@milkdown/design-system';
3
+ import type { Command, Node, Schema } from '@milkdown/prose';
3
4
  import type { Utils } from '@milkdown/utils';
4
- import type { Command } from 'prosemirror-commands';
5
- import type { Node, Schema } from 'prosemirror-model';
6
5
  export declare const createDropdown: (utils: Utils) => HTMLDivElement;
7
6
  declare type ItemOptions = {
8
7
  textClassName: string;
@@ -1 +1 @@
1
- {"version":3,"file":"utility.d.ts","sourceRoot":"","sources":["../src/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,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAItD,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;AAEN,eAAO,MAAM,UAAU,SAAU,MAAM,cAAc,MAAM,YAAgC,CAAC"}
1
+ {"version":3,"file":"utility.d.ts","sourceRoot":"","sources":["../src/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,EAAE,MAAM,iBAAiB,CAAC;AAC7D,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;AAEN,eAAO,MAAM,UAAU,SAAU,MAAM,cAAc,MAAM,YAAgC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"utility.js","sourceRoot":"","sources":["../src/utility.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEtC,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,KAAY,EAAE,EAAE;IAC3C,MAAM,GAAG,GAAG,QAAQ,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;IAC1C,GAAG,CAAC,YAAY,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IACpC,GAAG,CAAC,YAAY,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;IACnC,MAAM,KAAK,GAAG,KAAK,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;IAE1C,IAAI,KAAK,EAAE;QACP,GAAG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,CAAC;QACnB,KAAK,IAAI,CAAC,CAAC;KACd;IAED,OAAO,KAAK,CAAC;AACjB,CAAC,CAAC;AAEF,MAAM,OAAO,GAAY,CAAC,KAAK,EAAE,QAAQ,EAAE,EAAE;IACzC,MAAM,EAAE,SAAS,EAAE,GAAG,KAAK,CAAC;IAC5B,MAAM,EAAE,KAAK,EAAE,GAAG,SAAS,CAAC;IAC5B,MAAM,EAAE,GAAG,KAAK,CAAC,EAAE,CAAC,WAAW,CAAC,KAAK,CAAC,KAAK,EAAE,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC;IAC1D,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAG,EAAE,CAAC,CAAC;IACf,OAAO,KAAK,CAAC;AACjB,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,oBAAoB,GAC7B,CAAC,aAAyB,EAAW,EAAE,CACvC,CAAC,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,EAAE;IACtB,IAAI,IAAI,EAAE;QACN,OAAO,CAAC,KAAK,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAC;QAC/B,aAAa,EAAE,CAAC;KACnB;IACD,OAAO,IAAI,CAAC;AAChB,CAAC,CAAC;AAEN,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,IAAY,EAAE,EAAE,CAAC,CAAC,MAAc,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,13 +1,14 @@
1
1
  {
2
2
  "name": "@milkdown/plugin-slash",
3
- "version": "4.13.0",
3
+ "version": "4.14.0",
4
4
  "main": "lib/index.js",
5
5
  "module": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
7
7
  "sideEffects": false,
8
8
  "license": "MIT",
9
9
  "files": [
10
- "lib"
10
+ "lib",
11
+ "src"
11
12
  ],
12
13
  "keywords": [
13
14
  "milkdown",
@@ -19,7 +20,7 @@
19
20
  },
20
21
  "dependencies": {
21
22
  "@emotion/css": "^11.1.3",
22
- "@milkdown/utils": "4.13.0",
23
+ "@milkdown/utils": "4.14.0",
23
24
  "smooth-scroll-into-view-if-needed": "^1.1.32",
24
25
  "tslib": "^2.2.0"
25
26
  },
package/src/config.ts ADDED
@@ -0,0 +1,96 @@
1
+ /* Copyright 2021, Milkdown by Mirone. */
2
+ import { commandsCtx, themeToolCtx } from '@milkdown/core';
3
+ import {
4
+ InsertHr,
5
+ InsertImage,
6
+ InsertTable,
7
+ TurnIntoCodeFence,
8
+ TurnIntoHeading,
9
+ TurnIntoTaskList,
10
+ WrapInBlockquote,
11
+ WrapInBulletList,
12
+ WrapInOrderedList,
13
+ } from '@milkdown/preset-gfm';
14
+
15
+ import type { SlashConfig } from '.';
16
+ import { createDropdownItem, nodeExists } from './utility';
17
+
18
+ export const config: SlashConfig = ({ ctx }) => [
19
+ {
20
+ id: 'h1',
21
+ dom: createDropdownItem(ctx.get(themeToolCtx), 'Large Heading', 'h1'),
22
+ command: () => ctx.get(commandsCtx).call(TurnIntoHeading, 1),
23
+ keyword: ['h1', 'large heading'],
24
+ enable: nodeExists('heading'),
25
+ },
26
+ {
27
+ id: 'h2',
28
+ dom: createDropdownItem(ctx.get(themeToolCtx), 'Medium Heading', 'h2'),
29
+ command: () => ctx.get(commandsCtx).call(TurnIntoHeading, 2),
30
+ keyword: ['h2', 'medium heading'],
31
+ enable: nodeExists('heading'),
32
+ },
33
+ {
34
+ id: 'h3',
35
+ dom: createDropdownItem(ctx.get(themeToolCtx), 'Small Heading', 'h3'),
36
+ command: () => ctx.get(commandsCtx).call(TurnIntoHeading, 3),
37
+ keyword: ['h3', 'small heading'],
38
+ enable: nodeExists('heading'),
39
+ },
40
+ {
41
+ id: 'bulletList',
42
+ dom: createDropdownItem(ctx.get(themeToolCtx), 'Bullet List', 'bulletList'),
43
+ command: () => ctx.get(commandsCtx).call(WrapInBulletList),
44
+ keyword: ['bullet list', 'ul'],
45
+ enable: nodeExists('bullet_list'),
46
+ },
47
+ {
48
+ id: 'orderedList',
49
+ dom: createDropdownItem(ctx.get(themeToolCtx), 'Ordered List', 'orderedList'),
50
+ command: () => ctx.get(commandsCtx).call(WrapInOrderedList),
51
+ keyword: ['ordered list', 'ol'],
52
+ enable: nodeExists('ordered_list'),
53
+ },
54
+ {
55
+ id: 'taskList',
56
+ dom: createDropdownItem(ctx.get(themeToolCtx), 'Task List', 'taskList'),
57
+ command: () => ctx.get(commandsCtx).call(TurnIntoTaskList),
58
+ keyword: ['task list', 'task'],
59
+ enable: nodeExists('task_list_item'),
60
+ },
61
+ {
62
+ id: 'image',
63
+ dom: createDropdownItem(ctx.get(themeToolCtx), 'Image', 'image'),
64
+ command: () => ctx.get(commandsCtx).call(InsertImage),
65
+ keyword: ['image'],
66
+ enable: nodeExists('image'),
67
+ },
68
+ {
69
+ id: 'blockquote',
70
+ dom: createDropdownItem(ctx.get(themeToolCtx), 'Quote', 'quote'),
71
+ command: () => ctx.get(commandsCtx).call(WrapInBlockquote),
72
+ keyword: ['quote', 'blockquote'],
73
+ enable: nodeExists('blockquote'),
74
+ },
75
+ {
76
+ id: 'table',
77
+ dom: createDropdownItem(ctx.get(themeToolCtx), 'Table', 'table'),
78
+ command: () => ctx.get(commandsCtx).call(InsertTable),
79
+ keyword: ['table'],
80
+ enable: nodeExists('table'),
81
+ },
82
+ {
83
+ id: 'code',
84
+ dom: createDropdownItem(ctx.get(themeToolCtx), 'Code Fence', 'code'),
85
+ command: () => ctx.get(commandsCtx).call(TurnIntoCodeFence),
86
+ keyword: ['code'],
87
+ enable: nodeExists('fence'),
88
+ },
89
+ {
90
+ id: 'divider',
91
+ dom: createDropdownItem(ctx.get(themeToolCtx), 'Divide Line', 'divider'),
92
+ command: () => ctx.get(commandsCtx).call(InsertHr),
93
+ keyword: ['divider', 'hr'],
94
+ enable: nodeExists('hr'),
95
+ },
96
+ ];
package/src/index.ts ADDED
@@ -0,0 +1,47 @@
1
+ /* Copyright 2021, Milkdown by Mirone. */
2
+ import { EditorState, NodeWithPos } from '@milkdown/prose';
3
+ import { AtomList, createProsePlugin, Utils } from '@milkdown/utils';
4
+
5
+ import { config } from './config';
6
+ import { WrappedAction } from './item';
7
+ import { createSlashPlugin } from './prose-plugin';
8
+ import { CursorStatus } from './prose-plugin/status';
9
+
10
+ export { config } from './config';
11
+ export { CursorStatus } from './prose-plugin/status';
12
+ export { createDropdownItem, nodeExists } from './utility';
13
+
14
+ export type SlashConfig = (utils: Utils) => WrappedAction[];
15
+
16
+ export type Options = {
17
+ shouldDisplay: (parent: NodeWithPos, state: EditorState) => boolean;
18
+ config: SlashConfig;
19
+ placeholder: {
20
+ [CursorStatus.Empty]: string;
21
+ [CursorStatus.Slash]: string;
22
+ };
23
+ };
24
+
25
+ export const slashPlugin = createProsePlugin<Options>((options, utils) => {
26
+ const slashConfig = options?.config ?? config;
27
+ const placeholder = {
28
+ [CursorStatus.Empty]: 'Type / to use the slash commands...',
29
+ [CursorStatus.Slash]: 'Type to filter...',
30
+ ...(options?.placeholder ?? {}),
31
+ };
32
+ const cfg = slashConfig(utils);
33
+ const shouldDisplay =
34
+ options?.shouldDisplay ??
35
+ ((parent, state) => {
36
+ const isTopLevel = state.selection.$from.depth === 1;
37
+ return parent.node.childCount <= 1 && isTopLevel;
38
+ });
39
+
40
+ const plugin = createSlashPlugin(utils, cfg, placeholder, shouldDisplay);
41
+ return {
42
+ id: 'slash',
43
+ plugin,
44
+ };
45
+ });
46
+
47
+ export const slash = AtomList.create([slashPlugin()]);
package/src/item.ts ADDED
@@ -0,0 +1,26 @@
1
+ /* Copyright 2021, Milkdown by Mirone. */
2
+ import type { Command, Schema } from '@milkdown/prose';
3
+
4
+ import { cleanUpAndCreateNode } from './utility';
5
+
6
+ export type Action = {
7
+ id: string;
8
+ $: HTMLElement;
9
+ keyword: string[];
10
+ command: Command;
11
+ enable: (schema: Schema) => boolean;
12
+ };
13
+
14
+ export type WrappedAction = Pick<Action, 'keyword' | 'id'> & {
15
+ enable: (schema: Schema) => boolean;
16
+ command: () => void;
17
+ dom: HTMLElement;
18
+ };
19
+
20
+ export const transformAction = (action: WrappedAction): Action => ({
21
+ id: action.id,
22
+ keyword: action.keyword,
23
+ $: action.dom,
24
+ command: cleanUpAndCreateNode(action.command),
25
+ enable: action.enable,
26
+ });
@@ -0,0 +1,49 @@
1
+ /* Copyright 2021, Milkdown by Mirone. */
2
+ import scrollIntoView from 'smooth-scroll-into-view-if-needed';
3
+
4
+ import { Action } from '../item';
5
+ import { Status } from './status';
6
+
7
+ export const renderDropdown = (status: Status, dropdownElement: HTMLElement, items: Action[]): boolean => {
8
+ const { filter } = status.get();
9
+
10
+ if (!status.isSlash()) {
11
+ dropdownElement.classList.add('hide');
12
+ return false;
13
+ }
14
+
15
+ const activeList = items
16
+ .filter((item) => {
17
+ item.$.classList.remove('active');
18
+ const result = item.keyword.some((key) => key.includes(filter.toLocaleLowerCase()));
19
+ if (result) {
20
+ return true;
21
+ }
22
+ item.$.classList.add('hide');
23
+ return false;
24
+ })
25
+ .map((item) => {
26
+ item.$.classList.remove('hide');
27
+ return item;
28
+ });
29
+
30
+ status.setActions(activeList);
31
+
32
+ if (activeList.length === 0) {
33
+ dropdownElement.classList.add('hide');
34
+ return false;
35
+ }
36
+
37
+ dropdownElement.classList.remove('hide');
38
+
39
+ activeList[0].$.classList.add('active');
40
+ requestAnimationFrame(() => {
41
+ scrollIntoView(activeList[0].$, {
42
+ scrollMode: 'if-needed',
43
+ block: 'nearest',
44
+ inline: 'nearest',
45
+ });
46
+ });
47
+
48
+ return true;
49
+ };
@@ -0,0 +1,26 @@
1
+ /* Copyright 2021, Milkdown by Mirone. */
2
+ import { EditorState, NodeWithPos, Plugin, PluginKey } from '@milkdown/prose';
3
+ import { Utils } from '@milkdown/utils';
4
+
5
+ import { transformAction, WrappedAction } from '../item';
6
+ import { createProps } from './props';
7
+ import { createStatus, CursorStatus } from './status';
8
+ import { createView } from './view';
9
+
10
+ export const key = 'MILKDOWN_PLUGIN_SLASH';
11
+
12
+ export const createSlashPlugin = (
13
+ utils: Utils,
14
+ items: WrappedAction[],
15
+ placeholder: Record<CursorStatus, string>,
16
+ shouldDisplay: (parent: NodeWithPos, state: EditorState) => boolean,
17
+ ) => {
18
+ const status = createStatus();
19
+ const actions = items.map(transformAction);
20
+
21
+ return new Plugin({
22
+ key: new PluginKey(key),
23
+ props: createProps(status, utils, placeholder, shouldDisplay),
24
+ view: (view) => createView(status, actions, view, utils),
25
+ });
26
+ };
@@ -0,0 +1,120 @@
1
+ /* Copyright 2021, Milkdown by Mirone. */
2
+
3
+ import { EditorView } from '@milkdown/prose';
4
+ import scrollIntoView from 'smooth-scroll-into-view-if-needed';
5
+
6
+ import { Action } from '../item';
7
+ import { Status } from './status';
8
+
9
+ export const createMouseManager = () => {
10
+ let mouseLock = false;
11
+
12
+ return {
13
+ isLock: () => mouseLock,
14
+ lock: () => {
15
+ mouseLock = true;
16
+ },
17
+ unlock: () => {
18
+ mouseLock = false;
19
+ },
20
+ };
21
+ };
22
+ export type MouseManager = ReturnType<typeof createMouseManager>;
23
+
24
+ export const handleMouseMove = (mouseManager: MouseManager) => () => {
25
+ mouseManager.unlock();
26
+ };
27
+
28
+ export const handleMouseEnter = (status: Status, mouseManager: MouseManager) => (e: MouseEvent) => {
29
+ if (mouseManager.isLock()) return;
30
+ const active = status.get().activeActions.findIndex((x) => x.$.classList.contains('active'));
31
+ if (active >= 0) {
32
+ status.get().activeActions[active].$.classList.remove('active');
33
+ }
34
+ const { target } = e;
35
+ if (!(target instanceof HTMLElement)) return;
36
+ target.classList.add('active');
37
+ };
38
+
39
+ export const handleMouseLeave = () => (e: MouseEvent) => {
40
+ const { target } = e;
41
+ if (!(target instanceof HTMLElement)) return;
42
+ target.classList.remove('active');
43
+ };
44
+
45
+ export const handleClick =
46
+ (status: Status, items: Action[], view: EditorView, dropdownElement: HTMLElement) =>
47
+ (e: Event): void => {
48
+ const { target } = e;
49
+ if (!(target instanceof HTMLElement)) return;
50
+ if (!view) return;
51
+
52
+ const stop = () => {
53
+ e.stopPropagation();
54
+ e.preventDefault();
55
+ };
56
+
57
+ const el = Object.values(items).find(({ $ }) => $.contains(target));
58
+ if (!el) {
59
+ if (status.isEmpty()) return;
60
+
61
+ status.clearStatus();
62
+ dropdownElement.classList.add('hide');
63
+ stop();
64
+
65
+ return;
66
+ }
67
+
68
+ stop();
69
+ el.command(view.state, view.dispatch, view);
70
+ };
71
+
72
+ export const handleKeydown =
73
+ (status: Status, view: EditorView, dropdownElement: HTMLElement, mouseManager: MouseManager) => (e: Event) => {
74
+ if (!(e instanceof KeyboardEvent)) return;
75
+ if (!mouseManager.isLock()) mouseManager.lock();
76
+
77
+ const { key } = e;
78
+ if (!status.isSlash()) return;
79
+ if (!['ArrowDown', 'ArrowUp', 'Enter', 'Escape'].includes(key)) return;
80
+
81
+ const { activeActions } = status.get();
82
+
83
+ let active = activeActions.findIndex(({ $ }) => $.classList.contains('active'));
84
+ if (active < 0) active = 0;
85
+
86
+ const moveActive = (next: number) => {
87
+ activeActions[active].$.classList.remove('active');
88
+ activeActions[next].$.classList.add('active');
89
+ scrollIntoView(activeActions[next].$, {
90
+ scrollMode: 'if-needed',
91
+ block: 'nearest',
92
+ inline: 'nearest',
93
+ });
94
+ };
95
+
96
+ if (key === 'ArrowDown') {
97
+ const next = active === activeActions.length - 1 ? 0 : active + 1;
98
+
99
+ moveActive(next);
100
+ return;
101
+ }
102
+
103
+ if (key === 'ArrowUp') {
104
+ const next = active === 0 ? activeActions.length - 1 : active - 1;
105
+
106
+ moveActive(next);
107
+ return;
108
+ }
109
+
110
+ if (key === 'Escape') {
111
+ if (status.isEmpty()) return;
112
+
113
+ status.clearStatus();
114
+ dropdownElement.classList.add('hide');
115
+ return;
116
+ }
117
+
118
+ activeActions[active].command(view.state, view.dispatch, view);
119
+ activeActions[active].$.classList.remove('active');
120
+ };
@@ -0,0 +1,100 @@
1
+ /* Copyright 2021, Milkdown by Mirone. */
2
+ import { css } from '@emotion/css';
3
+ import { ThemeTool } from '@milkdown/core';
4
+ import { Decoration, DecorationSet, EditorState, EditorView, findParentNode, NodeWithPos } from '@milkdown/prose';
5
+ import { Utils } from '@milkdown/utils';
6
+
7
+ import { CursorStatus, Status } from './status';
8
+
9
+ export type Props = ReturnType<typeof createProps>;
10
+
11
+ const createEmptyStyle = ({ font, palette }: ThemeTool) => css`
12
+ position: relative;
13
+ &::before {
14
+ position: absolute;
15
+ cursor: text;
16
+ font-family: ${font.typography};
17
+ font-size: 0.875rem;
18
+ color: ${palette('neutral', 0.6)};
19
+ content: attr(data-text);
20
+ height: 100%;
21
+ display: flex;
22
+ align-items: center;
23
+ }
24
+ `;
25
+
26
+ const createSlashStyle = () => css`
27
+ &::before {
28
+ left: 0.5rem;
29
+ }
30
+ `;
31
+
32
+ export const createProps = (
33
+ status: Status,
34
+ utils: Utils,
35
+ placeholder: Record<CursorStatus, string>,
36
+ shouldDisplay: (parent: NodeWithPos, state: EditorState) => boolean,
37
+ ) => {
38
+ const emptyStyle = utils.getStyle(createEmptyStyle);
39
+ const slashStyle = utils.getStyle(createSlashStyle);
40
+
41
+ return {
42
+ handleKeyDown: (_: EditorView, event: Event) => {
43
+ const { cursorStatus, activeActions } = status.get();
44
+ if (cursorStatus !== CursorStatus.Slash || activeActions.length === 0) {
45
+ return false;
46
+ }
47
+ if (!(event instanceof KeyboardEvent)) {
48
+ return false;
49
+ }
50
+
51
+ if (!['ArrowUp', 'ArrowDown', 'Enter'].includes(event.key)) {
52
+ return false;
53
+ }
54
+
55
+ return true;
56
+ },
57
+ decorations: (state: EditorState) => {
58
+ const parent = findParentNode(({ type }) => type.name === 'paragraph')(state.selection);
59
+
60
+ if (!parent || !shouldDisplay(parent, state)) {
61
+ status.clearStatus();
62
+ return;
63
+ }
64
+
65
+ const isEmpty = parent.node.content.size === 0;
66
+ const isSlash = parent.node.textContent === '/' && state.selection.$from.parentOffset > 0;
67
+ const isSearch = parent.node.textContent.startsWith('/') && state.selection.$from.parentOffset > 1;
68
+
69
+ const createDecoration = (text: string, className: (string | undefined)[]) => {
70
+ const pos = parent.pos;
71
+ return DecorationSet.create(state.doc, [
72
+ Decoration.node(pos, pos + parent.node.nodeSize, {
73
+ class: className.filter((x) => x).join(' '),
74
+ 'data-text': text,
75
+ }),
76
+ ]);
77
+ };
78
+
79
+ if (isEmpty) {
80
+ status.clearStatus();
81
+ const text = placeholder[CursorStatus.Empty];
82
+ return createDecoration(text, [emptyStyle, 'empty-node']);
83
+ }
84
+
85
+ if (isSlash) {
86
+ status.setSlash();
87
+ const text = placeholder[CursorStatus.Slash];
88
+ return createDecoration(text, [emptyStyle, slashStyle, 'empty-node', 'is-slash']);
89
+ }
90
+
91
+ if (isSearch) {
92
+ status.setSlash(parent.node.textContent.slice(1));
93
+ return null;
94
+ }
95
+
96
+ status.clearStatus();
97
+ return null;
98
+ },
99
+ };
100
+ };
@@ -0,0 +1,47 @@
1
+ /* Copyright 2021, Milkdown by Mirone. */
2
+ import { Action } from '../item';
3
+
4
+ export enum CursorStatus {
5
+ Empty = 'empty',
6
+ Slash = 'slash',
7
+ }
8
+
9
+ export type StatusCtx = {
10
+ cursorStatus: CursorStatus;
11
+ filter: string;
12
+ activeActions: Action[];
13
+ };
14
+
15
+ const createStatusCtx = (): StatusCtx => {
16
+ return {
17
+ cursorStatus: CursorStatus.Empty,
18
+ filter: '',
19
+ activeActions: [],
20
+ };
21
+ };
22
+
23
+ const clearStatus = (status: StatusCtx) => {
24
+ status.cursorStatus = CursorStatus.Empty;
25
+ status.filter = '';
26
+ };
27
+
28
+ const setSlash = (status: StatusCtx, filter = '') => {
29
+ status.cursorStatus = CursorStatus.Slash;
30
+ status.filter = filter;
31
+ };
32
+
33
+ export type Status = ReturnType<typeof createStatus>;
34
+
35
+ export const createStatus = () => {
36
+ const statusCtx = createStatusCtx();
37
+ return {
38
+ clearStatus: () => clearStatus(statusCtx),
39
+ setSlash: (filter = '') => setSlash(statusCtx, filter),
40
+ setActions: (actions: Action[]) => {
41
+ statusCtx.activeActions = actions;
42
+ },
43
+ get: () => statusCtx,
44
+ isEmpty: () => statusCtx.cursorStatus === CursorStatus.Empty,
45
+ isSlash: () => statusCtx.cursorStatus === CursorStatus.Slash,
46
+ };
47
+ };
@@ -0,0 +1,75 @@
1
+ /* Copyright 2021, Milkdown by Mirone. */
2
+ import { calculateNodePosition, EditorView } from '@milkdown/prose';
3
+ import { Utils } from '@milkdown/utils';
4
+
5
+ import { Action } from '../item';
6
+ import { createDropdown } from '../utility';
7
+ import { renderDropdown } from './dropdown';
8
+ import {
9
+ createMouseManager,
10
+ handleClick,
11
+ handleKeydown,
12
+ handleMouseEnter,
13
+ handleMouseLeave,
14
+ handleMouseMove,
15
+ } from './input';
16
+ import { Status } from './status';
17
+
18
+ const calculatePosition = (view: EditorView, dropdownElement: HTMLElement) => {
19
+ calculateNodePosition(view, dropdownElement, (selected, target, parent) => {
20
+ let left = selected.left - parent.left;
21
+ let top = selected.bottom - parent.top + 14;
22
+
23
+ if (left < 0) {
24
+ left = 0;
25
+ }
26
+
27
+ if (window.innerHeight - selected.bottom < target.height) {
28
+ top = selected.top - parent.top - target.height - 14;
29
+ }
30
+ return [top, left];
31
+ });
32
+ };
33
+
34
+ export const createView = (status: Status, items: Action[], view: EditorView, utils: Utils) => {
35
+ const wrapper = view.dom.parentNode;
36
+ if (!wrapper) return {};
37
+
38
+ const dropdownElement = createDropdown(utils);
39
+ const mouseManager = createMouseManager();
40
+ wrapper.appendChild(dropdownElement);
41
+
42
+ const _mouseMove = handleMouseMove(mouseManager);
43
+ const _mouseDown = handleClick(status, items, view, dropdownElement);
44
+ const _keydown = handleKeydown(status, view, dropdownElement, mouseManager);
45
+ const _mouseEnter = handleMouseEnter(status, mouseManager);
46
+ const _mouseLeave = handleMouseLeave();
47
+
48
+ items
49
+ .filter((item) => item.enable(view.state.schema))
50
+ .forEach(({ $ }) => {
51
+ $.addEventListener('mouseenter', _mouseEnter);
52
+ $.addEventListener('mouseleave', _mouseLeave);
53
+ dropdownElement.appendChild($);
54
+ });
55
+ wrapper.addEventListener('mousemove', _mouseMove);
56
+ wrapper.addEventListener('mousedown', _mouseDown);
57
+ wrapper.addEventListener('keydown', _keydown);
58
+
59
+ return {
60
+ update: (view: EditorView) => {
61
+ const show = renderDropdown(status, dropdownElement, items);
62
+
63
+ if (!show) return;
64
+
65
+ calculatePosition(view, dropdownElement);
66
+ },
67
+
68
+ destroy: () => {
69
+ wrapper.removeEventListener('mousemove', _mouseMove);
70
+ wrapper.removeEventListener('mousedown', _mouseDown);
71
+ wrapper.removeEventListener('keydown', _keydown);
72
+ dropdownElement.remove();
73
+ },
74
+ };
75
+ };
package/src/style.ts ADDED
@@ -0,0 +1,63 @@
1
+ /* Copyright 2021, Milkdown by Mirone. */
2
+ import { css } from '@emotion/css';
3
+ import { ThemeTool } from '@milkdown/core';
4
+
5
+ const itemStyle = ({ font, palette }: ThemeTool) => {
6
+ return css`
7
+ .slash-dropdown-item {
8
+ display: flex;
9
+ gap: 2rem;
10
+ height: 3rem;
11
+ padding: 0 1rem;
12
+ align-items: center;
13
+ justify-content: flex-start;
14
+ cursor: pointer;
15
+ line-height: 2;
16
+ font-family: ${font.typography};
17
+ font-size: 0.875rem;
18
+
19
+ transition: all 0.2s ease-in-out;
20
+
21
+ &,
22
+ .icon {
23
+ color: ${palette('neutral', 0.87)};
24
+ transition: all 0.2s ease-in-out;
25
+ }
26
+
27
+ &.hide {
28
+ display: none;
29
+ }
30
+
31
+ &.active {
32
+ background: ${palette('secondary', 0.12)};
33
+ &,
34
+ .icon {
35
+ color: ${palette('primary')};
36
+ }
37
+ }
38
+ `;
39
+ };
40
+
41
+ export const injectStyle = (themeTool: ThemeTool) => {
42
+ const { mixin, size, palette } = themeTool;
43
+ const style = css`
44
+ width: 20.5rem;
45
+ max-height: 20.5rem;
46
+ overflow-y: auto;
47
+ ${mixin.border?.()};
48
+ border-radius: ${size.radius};
49
+ position: absolute;
50
+ background: ${palette('surface')};
51
+
52
+ ${mixin.shadow?.()};
53
+
54
+ &.hide {
55
+ display: none;
56
+ }
57
+
58
+ ${mixin.scrollbar?.()};
59
+
60
+ ${itemStyle(themeTool)}
61
+ `;
62
+ return style;
63
+ };
package/src/utility.ts ADDED
@@ -0,0 +1,75 @@
1
+ /* Copyright 2021, Milkdown by Mirone. */
2
+ import type { ThemeTool } from '@milkdown/core';
3
+ import type { Icon } from '@milkdown/design-system';
4
+ import type { Command, Node, Schema } from '@milkdown/prose';
5
+ import type { Utils } from '@milkdown/utils';
6
+
7
+ import { injectStyle } from './style';
8
+
9
+ export const createDropdown = (utils: Utils) => {
10
+ const div = document.createElement('div');
11
+ div.setAttribute('role', 'listbox');
12
+ div.setAttribute('tabindex', '-1');
13
+ const style = utils.getStyle(injectStyle);
14
+
15
+ if (style) {
16
+ div.classList.add(style);
17
+ }
18
+
19
+ div.classList.add('slash-dropdown', 'hide');
20
+
21
+ return div;
22
+ };
23
+
24
+ type ItemOptions = {
25
+ textClassName: string;
26
+ };
27
+ export const createDropdownItem = (themeTool: ThemeTool, text: string, icon: Icon, options?: Partial<ItemOptions>) => {
28
+ const textClassName = options?.textClassName ?? 'text';
29
+
30
+ const div = document.createElement('div');
31
+ div.setAttribute('role', 'option');
32
+ div.classList.add('slash-dropdown-item');
33
+
34
+ const iconSpan = themeTool.slots.icon(icon);
35
+
36
+ const textSpan = document.createElement('span');
37
+ textSpan.textContent = text;
38
+ textSpan.className = textClassName;
39
+
40
+ div.appendChild(iconSpan);
41
+ div.appendChild(textSpan);
42
+
43
+ return div;
44
+ };
45
+
46
+ export const getDepth = (node: Node) => {
47
+ let cur = node;
48
+ let depth = 0;
49
+ while (cur.childCount) {
50
+ cur = cur.child(0);
51
+ depth += 1;
52
+ }
53
+
54
+ return depth;
55
+ };
56
+
57
+ const cleanUp: Command = (state, dispatch) => {
58
+ const { selection } = state;
59
+ const { $from } = selection;
60
+ const tr = state.tr.deleteRange($from.start(), $from.pos);
61
+ dispatch?.(tr);
62
+ return false;
63
+ };
64
+
65
+ export const cleanUpAndCreateNode =
66
+ (createCommand: () => void): Command =>
67
+ (state, dispatch, view) => {
68
+ if (view) {
69
+ cleanUp(state, dispatch, view);
70
+ createCommand();
71
+ }
72
+ return true;
73
+ };
74
+
75
+ export const nodeExists = (name: string) => (schema: Schema) => Boolean(schema.nodes[name]);