@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
@@ -1,47 +1,36 @@
1
1
  /* Copyright 2021, Milkdown by Mirone. */
2
- import { Action } from '../item';
3
-
4
- export enum CursorStatus {
5
- Empty = 'empty',
6
- Slash = 'slash',
7
- }
2
+ import { StatusConfigBuilder, StatusConfigBuilderParams } from '..';
3
+ import { Action, transformAction } from '../item';
8
4
 
9
5
  export type StatusCtx = {
10
- cursorStatus: CursorStatus;
11
- filter: string;
12
- activeActions: Action[];
6
+ placeholder: string | null;
7
+ actions: Action[];
13
8
  };
14
9
 
15
10
  const createStatusCtx = (): StatusCtx => {
16
11
  return {
17
- cursorStatus: CursorStatus.Empty,
18
- filter: '',
19
- activeActions: [],
12
+ placeholder: null,
13
+ actions: [],
20
14
  };
21
15
  };
22
16
 
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
17
  export type Status = ReturnType<typeof createStatus>;
34
18
 
35
- export const createStatus = () => {
19
+ export const createStatus = (builder: StatusConfigBuilder) => {
36
20
  const statusCtx = createStatusCtx();
21
+
37
22
  return {
38
- clearStatus: () => clearStatus(statusCtx),
39
- setSlash: (filter = '') => setSlash(statusCtx, filter),
40
- setActions: (actions: Action[]) => {
41
- statusCtx.activeActions = actions;
42
- },
43
23
  get: () => statusCtx,
44
- isEmpty: () => statusCtx.cursorStatus === CursorStatus.Empty,
45
- isSlash: () => statusCtx.cursorStatus === CursorStatus.Slash,
24
+ clear: () => {
25
+ statusCtx.placeholder = null;
26
+ statusCtx.actions = [];
27
+ },
28
+ update: (builderParams: StatusConfigBuilderParams) => {
29
+ const config = builder(builderParams);
30
+ statusCtx.placeholder = config?.placeholder ?? null;
31
+ statusCtx.actions = (config?.actions ?? []).map(transformAction);
32
+ return statusCtx;
33
+ },
34
+ isEmpty: () => statusCtx.actions.length === 0,
46
35
  };
47
36
  };
@@ -2,7 +2,6 @@
2
2
  import { calculateNodePosition, EditorView } from '@milkdown/prose';
3
3
  import { Utils } from '@milkdown/utils';
4
4
 
5
- import { Action } from '../item';
6
5
  import { createDropdown } from '../utility';
7
6
  import { renderDropdown } from './dropdown';
8
7
  import {
@@ -31,7 +30,7 @@ const calculatePosition = (view: EditorView, dropdownElement: HTMLElement) => {
31
30
  });
32
31
  };
33
32
 
34
- export const createView = (status: Status, items: Action[], view: EditorView, utils: Utils) => {
33
+ export const createView = (status: Status, view: EditorView, utils: Utils) => {
35
34
  const wrapper = view.dom.parentNode;
36
35
  if (!wrapper) return {};
37
36
 
@@ -40,25 +39,21 @@ export const createView = (status: Status, items: Action[], view: EditorView, ut
40
39
  wrapper.appendChild(dropdownElement);
41
40
 
42
41
  const _mouseMove = handleMouseMove(mouseManager);
43
- const _mouseDown = handleClick(status, items, view, dropdownElement);
42
+ const _mouseDown = handleClick(status, view, dropdownElement);
44
43
  const _keydown = handleKeydown(status, view, dropdownElement, mouseManager);
45
44
  const _mouseEnter = handleMouseEnter(status, mouseManager);
46
45
  const _mouseLeave = handleMouseLeave();
47
46
 
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
47
  wrapper.addEventListener('mousemove', _mouseMove);
56
48
  wrapper.addEventListener('mousedown', _mouseDown);
57
49
  wrapper.addEventListener('keydown', _keydown);
58
50
 
59
51
  return {
60
52
  update: (view: EditorView) => {
61
- const show = renderDropdown(status, dropdownElement, items);
53
+ const show = renderDropdown(status, dropdownElement, {
54
+ mouseEnter: _mouseEnter as EventListener,
55
+ mouseLeave: _mouseLeave as EventListener,
56
+ });
62
57
 
63
58
  if (!show) return;
64
59
 
package/src/utility.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /* Copyright 2021, Milkdown by Mirone. */
2
2
  import type { ThemeTool } from '@milkdown/core';
3
3
  import type { Icon } from '@milkdown/design-system';
4
- import type { Command, Node, Schema } from '@milkdown/prose';
4
+ import type { Command, Node } from '@milkdown/prose';
5
5
  import type { Utils } from '@milkdown/utils';
6
6
 
7
7
  import { injectStyle } from './style';
@@ -71,5 +71,3 @@ export const cleanUpAndCreateNode =
71
71
  }
72
72
  return true;
73
73
  };
74
-
75
- export const nodeExists = (name: string) => (schema: Schema) => Boolean(schema.nodes[name]);