@milkdown/plugin-tooltip 5.4.1 → 6.0.0-next.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 (74) hide show
  1. package/README.md +3 -13
  2. package/lib/{src/button-manager → button-manager}/calc-button-pos.d.ts +1 -1
  3. package/lib/button-manager/calc-button-pos.d.ts.map +1 -0
  4. package/lib/{src/button-manager → button-manager}/create-tooltip.d.ts +1 -1
  5. package/lib/button-manager/create-tooltip.d.ts.map +1 -0
  6. package/lib/{src/button-manager → button-manager}/filter-button.d.ts +0 -0
  7. package/lib/button-manager/filter-button.d.ts.map +1 -0
  8. package/lib/{src/button-manager → button-manager}/index.d.ts +1 -1
  9. package/lib/button-manager/index.d.ts.map +1 -0
  10. package/lib/{src/button-manager → button-manager}/no-active.d.ts +0 -0
  11. package/lib/button-manager/no-active.d.ts.map +1 -0
  12. package/lib/button-manager/style.d.ts +3 -0
  13. package/lib/button-manager/style.d.ts.map +1 -0
  14. package/lib/index.d.ts +19 -1
  15. package/lib/index.d.ts.map +1 -0
  16. package/lib/index.es.js +65 -376
  17. package/lib/index.es.js.map +1 -1
  18. package/lib/item.d.ts +35 -0
  19. package/lib/item.d.ts.map +1 -0
  20. package/lib/{src/selection-marks-tooltip.d.ts → selection-marks-tooltip.d.ts} +2 -2
  21. package/lib/selection-marks-tooltip.d.ts.map +1 -0
  22. package/lib/{src/utility → utility}/element.d.ts +0 -0
  23. package/lib/utility/element.d.ts.map +1 -0
  24. package/lib/{src/utility → utility}/index.d.ts +0 -1
  25. package/lib/utility/index.d.ts.map +1 -0
  26. package/lib/{src/utility → utility}/prosemirror.d.ts +2 -2
  27. package/lib/utility/prosemirror.d.ts.map +1 -0
  28. package/lib/{src/utility → utility}/toggle.d.ts +1 -1
  29. package/lib/utility/toggle.d.ts.map +1 -0
  30. package/package.json +34 -10
  31. package/src/button-manager/calc-button-pos.ts +2 -3
  32. package/src/button-manager/create-tooltip.ts +8 -6
  33. package/src/button-manager/index.ts +8 -3
  34. package/src/button-manager/style.ts +11 -10
  35. package/src/index.ts +6 -22
  36. package/src/item.ts +47 -80
  37. package/src/selection-marks-tooltip.ts +3 -9
  38. package/src/utility/index.ts +0 -1
  39. package/src/utility/prosemirror.ts +5 -2
  40. package/src/utility/toggle.ts +5 -5
  41. package/lib/src/button-manager/calc-button-pos.d.ts.map +0 -1
  42. package/lib/src/button-manager/create-tooltip.d.ts.map +0 -1
  43. package/lib/src/button-manager/filter-button.d.ts.map +0 -1
  44. package/lib/src/button-manager/index.d.ts.map +0 -1
  45. package/lib/src/button-manager/no-active.d.ts.map +0 -1
  46. package/lib/src/button-manager/style.d.ts +0 -3
  47. package/lib/src/button-manager/style.d.ts.map +0 -1
  48. package/lib/src/index.d.ts +0 -21
  49. package/lib/src/index.d.ts.map +0 -1
  50. package/lib/src/input-manager/calc-input-pos.d.ts +0 -3
  51. package/lib/src/input-manager/calc-input-pos.d.ts.map +0 -1
  52. package/lib/src/input-manager/create-input.d.ts +0 -7
  53. package/lib/src/input-manager/create-input.d.ts.map +0 -1
  54. package/lib/src/input-manager/filter-input.d.ts +0 -19
  55. package/lib/src/input-manager/filter-input.d.ts.map +0 -1
  56. package/lib/src/input-manager/index.d.ts +0 -10
  57. package/lib/src/input-manager/index.d.ts.map +0 -1
  58. package/lib/src/input-manager/style.d.ts +0 -3
  59. package/lib/src/input-manager/style.d.ts.map +0 -1
  60. package/lib/src/item.d.ts +0 -53
  61. package/lib/src/item.d.ts.map +0 -1
  62. package/lib/src/selection-marks-tooltip.d.ts.map +0 -1
  63. package/lib/src/utility/element.d.ts.map +0 -1
  64. package/lib/src/utility/index.d.ts.map +0 -1
  65. package/lib/src/utility/input.d.ts +0 -9
  66. package/lib/src/utility/input.d.ts.map +0 -1
  67. package/lib/src/utility/prosemirror.d.ts.map +0 -1
  68. package/lib/src/utility/toggle.d.ts.map +0 -1
  69. package/src/input-manager/calc-input-pos.ts +0 -19
  70. package/src/input-manager/create-input.ts +0 -39
  71. package/src/input-manager/filter-input.ts +0 -33
  72. package/src/input-manager/index.ts +0 -55
  73. package/src/input-manager/style.ts +0 -66
  74. package/src/utility/input.ts +0 -132
package/src/item.ts CHANGED
@@ -1,22 +1,26 @@
1
1
  /* Copyright 2021, Milkdown by Mirone. */
2
- import { Ctx } from '@milkdown/core';
3
- import { EditorView, findSelectedNodeOfType, Schema, TextSelection } from '@milkdown/prose';
2
+ import { commandsCtx, Ctx, ThemeIcon, themeManagerCtx } from '@milkdown/core';
3
+ import type { Icon } from '@milkdown/design-system';
4
+ import { EditorView, Schema } from '@milkdown/prose';
4
5
 
5
- import {
6
- createToggleIcon,
7
- hasMark,
8
- modifyImage,
9
- modifyInlineMath,
10
- modifyLink,
11
- updateImageView,
12
- updateInlineMathView,
13
- updateLinkView,
14
- } from './utility';
6
+ import { createToggleIcon } from './utility';
15
7
 
16
8
  export type Pred = (view: EditorView) => boolean;
17
9
  export type Updater = (view: EditorView, $: HTMLElement) => void;
18
10
  export type Event2Command = (e: Event) => void;
19
11
 
12
+ export type OnClick = (ctx: Ctx) => void;
13
+
14
+ export type Item = {
15
+ icon: Icon | ((ctx: Ctx) => HTMLElement);
16
+
17
+ onClick: string | ((ctx: Ctx) => () => void);
18
+
19
+ isHidden: (ctx: Ctx) => Pred;
20
+
21
+ isActive: (ctx: Ctx) => Pred;
22
+ };
23
+
20
24
  export type ButtonItem = {
21
25
  $: HTMLElement;
22
26
  command: () => void;
@@ -25,20 +29,13 @@ export type ButtonItem = {
25
29
  enable: Pred;
26
30
  };
27
31
 
28
- export type InputItem = {
29
- command: Event2Command;
30
- display: Pred;
31
- update: Updater;
32
- placeholder: string;
33
- } & (
34
- | {
35
- bind: true;
36
- }
37
- | {
38
- bind?: false;
39
- buttonText: string;
40
- }
41
- );
32
+ const Buttonize = ({ icon, onClick, isHidden, isActive }: Item, ctx: Ctx): ButtonItem => ({
33
+ $: typeof icon === 'function' ? icon(ctx) : (ctx.get(themeManagerCtx).get(ThemeIcon, icon)?.dom as HTMLElement),
34
+ command: typeof onClick === 'string' ? () => ctx.get(commandsCtx).call(onClick) : onClick(ctx),
35
+ disable: isHidden(ctx),
36
+ active: isActive(ctx),
37
+ enable: (view: EditorView) => !isHidden(ctx)(view),
38
+ });
42
39
 
43
40
  export enum ButtonAction {
44
41
  ToggleBold,
@@ -48,70 +45,40 @@ export enum ButtonAction {
48
45
  ToggleLink,
49
46
  }
50
47
 
51
- export enum InputAction {
52
- ModifyLink,
53
- ModifyImage,
54
- ModifyInlineMath,
55
- }
56
-
57
48
  export type ButtonMap = Record<ButtonAction, ButtonItem>;
58
- export type InputMap = Record<InputAction, InputItem>;
59
49
 
60
- export type InputOptions = {
61
- link: {
62
- placeholder: string;
63
- buttonText: string;
64
- };
65
- image: {
66
- placeholder: string;
67
- buttonText: string;
68
- };
69
- inlineMath: {
70
- placeholder: string;
71
- };
72
- };
73
-
74
- export const inputMap = (schema: Schema, ctx: Ctx, inputOptions: InputOptions): InputMap => {
75
- const { marks, nodes } = schema;
76
- return {
77
- [InputAction.ModifyLink]: {
78
- display: (view) =>
79
- view.state.selection.empty &&
80
- view.state.selection instanceof TextSelection &&
81
- hasMark(view.state, marks.link),
82
- command: modifyLink(ctx),
83
- update: updateLinkView,
84
- ...inputOptions.link,
85
- },
86
- [InputAction.ModifyInlineMath]: {
87
- display: (view) => Boolean(findSelectedNodeOfType(view.state.selection, nodes.math_inline)),
88
- command: modifyInlineMath(ctx),
89
- update: updateInlineMathView,
90
- bind: true,
91
- ...inputOptions.inlineMath,
92
- },
93
- [InputAction.ModifyImage]: {
94
- display: (view) => Boolean(findSelectedNodeOfType(view.state.selection, nodes.image)),
95
- command: modifyImage(ctx),
96
- update: updateImageView,
97
- ...inputOptions.image,
98
- },
99
- };
50
+ export type TooltipOptions = {
51
+ bottom: boolean;
52
+ className: string;
53
+ items: Array<Item> | undefined;
100
54
  };
101
55
 
102
- export const buttonMap = (schema: Schema, ctx: Ctx): ButtonMap => {
56
+ export const buttonMap = (schema: Schema, ctx: Ctx, items: Array<Item> | undefined): ButtonMap => {
103
57
  const { marks } = schema;
58
+ const ButtonItems = Array<ButtonItem>();
59
+ if (typeof items !== 'undefined') {
60
+ (items as Array<Item>).forEach((item) => {
61
+ ButtonItems.push(Buttonize(item, ctx));
62
+ });
63
+ }
104
64
  return {
105
- [ButtonAction.ToggleBold]: createToggleIcon(ctx, 'bold', 'ToggleBold', marks.strong, marks.code_inline),
106
- [ButtonAction.ToggleItalic]: createToggleIcon(ctx, 'italic', 'ToggleItalic', marks.em, marks.code_inline),
65
+ [ButtonAction.ToggleBold]: createToggleIcon(ctx, 'bold', 'ToggleBold', marks['strong'], marks['code_inline']),
66
+ [ButtonAction.ToggleItalic]: createToggleIcon(ctx, 'italic', 'ToggleItalic', marks['em'], marks['code_inline']),
107
67
  [ButtonAction.ToggleStrike]: createToggleIcon(
108
68
  ctx,
109
69
  'strikeThrough',
110
70
  'ToggleStrikeThrough',
111
- marks.strike_through,
112
- marks.code_inline,
71
+ marks['strike_through'],
72
+ marks['code_inline'],
73
+ ),
74
+ [ButtonAction.ToggleCode]: createToggleIcon(
75
+ ctx,
76
+ 'code',
77
+ 'ToggleInlineCode',
78
+ marks['code_inline'],
79
+ marks['link'],
113
80
  ),
114
- [ButtonAction.ToggleCode]: createToggleIcon(ctx, 'code', 'ToggleInlineCode', marks.code_inline, marks.link),
115
- [ButtonAction.ToggleLink]: createToggleIcon(ctx, 'link', 'ToggleLink', marks.link, marks.code_inline),
81
+ [ButtonAction.ToggleLink]: createToggleIcon(ctx, 'link', 'ToggleLink', marks['link'], marks['code_inline']),
82
+ ...ButtonItems,
116
83
  };
117
84
  };
@@ -3,17 +3,14 @@ import type { EditorState, EditorView } from '@milkdown/prose';
3
3
  import { Utils } from '@milkdown/utils';
4
4
 
5
5
  import { createButtonManager } from './button-manager';
6
- import { createInputManager } from './input-manager';
7
- import type { ButtonMap, InputMap } from './item';
6
+ import type { ButtonMap } from './item';
8
7
 
9
- export const createPlugin = (buttonMap: ButtonMap, inputMap: InputMap, utils: Utils) => {
10
- const buttonManager = createButtonManager(buttonMap, utils);
11
- const inputManager = createInputManager(inputMap, utils);
8
+ export const createPlugin = (buttonMap: ButtonMap, utils: Utils, bottom: boolean, containerClassName: string) => {
9
+ const buttonManager = createButtonManager(buttonMap, utils, bottom, containerClassName);
12
10
  let shouldHide = false;
13
11
 
14
12
  const hide = () => {
15
13
  buttonManager.hide();
16
- inputManager.hide();
17
14
  };
18
15
 
19
16
  const update = (view: EditorView, prevState?: EditorState) => {
@@ -28,18 +25,15 @@ export const createPlugin = (buttonMap: ButtonMap, inputMap: InputMap, utils: Ut
28
25
  if (isEqualSelection) return;
29
26
 
30
27
  buttonManager.update(view);
31
- inputManager.update(view);
32
28
  };
33
29
 
34
30
  return {
35
31
  update,
36
32
  destroy: () => {
37
33
  buttonManager.destroy();
38
- inputManager.destroy();
39
34
  },
40
35
  render: (editorView: EditorView) => {
41
36
  buttonManager.render(editorView);
42
- inputManager.render(editorView);
43
37
  update(editorView);
44
38
  },
45
39
  setHide: (isTyping: boolean) => {
@@ -1,5 +1,4 @@
1
1
  /* Copyright 2021, Milkdown by Mirone. */
2
2
  export * from './element';
3
- export * from './input';
4
3
  export * from './prosemirror';
5
4
  export * from './toggle';
@@ -6,7 +6,10 @@ export type Position = {
6
6
  end: number;
7
7
  };
8
8
 
9
- export const hasMark = (editorState: EditorState, type: MarkType): boolean => {
9
+ export const hasMark = (editorState: EditorState, type?: MarkType): boolean => {
10
+ if (!type) {
11
+ return false;
12
+ }
10
13
  const { from, to } = editorState.selection;
11
14
 
12
15
  return editorState.doc.rangeHasMark(from, from === to ? to + 1 : to, type);
@@ -27,7 +30,7 @@ export const isTextSelection = (editorState: EditorState): boolean => {
27
30
  export const isInCodeFence = (editorState: EditorState): boolean =>
28
31
  Boolean(findParentNode((node) => !!node.type.spec.code)(editorState.selection));
29
32
 
30
- export const isTextAndNotHasMark = (editorState: EditorState, mark: MarkType): boolean =>
33
+ export const isTextAndNotHasMark = (editorState: EditorState, mark?: MarkType): boolean =>
31
34
  !isTextSelection(editorState) || isInCodeFence(editorState) || hasMark(editorState, mark);
32
35
 
33
36
  export const equalNodeType = (nodeType: NodeType, node: Node) => {
@@ -1,5 +1,5 @@
1
1
  /* Copyright 2021, Milkdown by Mirone. */
2
- import { commandsCtx, Ctx, themeToolCtx } from '@milkdown/core';
2
+ import { commandsCtx, Ctx, ThemeIcon, themeManagerCtx } from '@milkdown/core';
3
3
  import type { Icon } from '@milkdown/design-system';
4
4
  import type { MarkType } from '@milkdown/prose';
5
5
 
@@ -10,11 +10,11 @@ export const createToggleIcon = (
10
10
  ctx: Ctx,
11
11
  iconName: Icon,
12
12
  key: string,
13
- mark: MarkType,
14
- disableForMark: MarkType,
13
+ mark: MarkType | undefined,
14
+ disableForMark: MarkType | undefined,
15
15
  ): ButtonItem => ({
16
- $: ctx.get(themeToolCtx).slots.icon(iconName),
17
- command: () => ctx.get(commandsCtx).callByName(key),
16
+ $: ctx.get(themeManagerCtx).get(ThemeIcon, iconName)?.dom as HTMLElement,
17
+ command: () => ctx.get(commandsCtx).call(key),
18
18
  active: (view) => hasMark(view.state, mark),
19
19
  disable: (view) => isTextAndNotHasMark(view.state, disableForMark),
20
20
  enable: (view) => !!mark && !!view.state.schema.marks[mark.name],
@@ -1 +0,0 @@
1
- {"version":3,"file":"calc-button-pos.d.ts","sourceRoot":"","sources":["calc-button-pos.ts"],"names":[],"mappings":"AACA,OAAO,EAAyB,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAEpE,eAAO,MAAM,aAAa,YAAa,WAAW,QAAQ,UAAU,SAmBnE,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"create-tooltip.d.ts","sourceRoot":"","sources":["create-tooltip.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAE7C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAGzC,aAAK,OAAO,GAAG;IACX,GAAG,EAAE,cAAc,CAAC;IACpB,MAAM,EAAE,CAAC,UAAU,EAAE,UAAU,KAAK,IAAI,CAAC;CAC5C,CAAC;AAEF,eAAO,MAAM,aAAa,cAAe,SAAS,SAAS,KAAK,KAAG,OAmBlE,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"filter-button.d.ts","sourceRoot":"","sources":["filter-button.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAGpC,eAAO,MAAM,YAAY,cAAe,SAAS,QAAQ,UAAU,YAqBlE,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAE7C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAKzC,eAAO,MAAM,mBAAmB,cAAe,SAAS,SAAS,KAAK;;;yBAwBzC,UAAU;;CAUtC,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"no-active.d.ts","sourceRoot":"","sources":["no-active.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAEpC,eAAO,MAAM,QAAQ,cAAe,SAAS,QAAQ,UAAU,YAI9D,CAAC"}
@@ -1,3 +0,0 @@
1
- import { Emotion, ThemeTool } from '@milkdown/core';
2
- export declare const injectStyle: (themeTool: ThemeTool, { css }: Emotion) => string;
3
- //# sourceMappingURL=style.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"style.d.ts","sourceRoot":"","sources":["style.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEpD,eAAO,MAAM,WAAW,cAAe,SAAS,WAAW,OAAO,WA6CjE,CAAC"}
@@ -1,21 +0,0 @@
1
- import { PluginKey } from '@milkdown/prose';
2
- import { AtomList } from '@milkdown/utils';
3
- import { InputOptions } from './item';
4
- export declare const key: PluginKey<any, any>;
5
- export declare const tooltipPlugin: import("@milkdown/utils/lib/src/types").WithExtend<string, InputOptions, {
6
- [x: string]: import("prosemirror-model").NodeType<any>;
7
- } & {
8
- [x: string]: import("prosemirror-model").MarkType<any>;
9
- }, {
10
- schema?: ((ctx: import("@milkdown/core").Ctx) => {
11
- node?: Record<string, import("@milkdown/core").NodeSchema> | undefined;
12
- mark?: Record<string, import("@milkdown/core").MarkSchema> | undefined;
13
- }) | undefined;
14
- view?: ((ctx: import("@milkdown/core").Ctx) => Partial<{
15
- [x: string]: import("@milkdown/prose").NodeViewFactory;
16
- } & {
17
- [x: string]: import("@milkdown/prose").MarkViewFactory;
18
- }>) | undefined;
19
- }>;
20
- export declare const tooltip: AtomList<import("@milkdown/utils/lib/src/types").Metadata<import("@milkdown/utils/lib/src/types").GetPlugin<string, InputOptions>> & import("@milkdown/core").MilkdownPlugin>;
21
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAU,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,EAAE,QAAQ,EAA0B,MAAM,iBAAiB,CAAC;AAEnE,OAAO,EAAuB,YAAY,EAAE,MAAM,QAAQ,CAAC;AAG3D,eAAO,MAAM,GAAG,qBAA2C,CAAC;AAE5D,eAAO,MAAM,aAAa;;;;;;;;;;;;;;EAuDxB,CAAC;AAEH,eAAO,MAAM,OAAO,+KAAqC,CAAC"}
@@ -1,3 +0,0 @@
1
- import { EditorView } from '@milkdown/prose';
2
- export declare const calcInputPos: (view: EditorView, input: HTMLDivElement) => void;
3
- //# sourceMappingURL=calc-input-pos.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"calc-input-pos.d.ts","sourceRoot":"","sources":["calc-input-pos.ts"],"names":[],"mappings":"AACA,OAAO,EAAyB,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAEpE,eAAO,MAAM,YAAY,SAAU,UAAU,SAAS,cAAc,SAenE,CAAC"}
@@ -1,7 +0,0 @@
1
- import type { Utils } from '@milkdown/utils';
2
- export declare const createInput: (utils: Utils) => {
3
- readonly div: HTMLDivElement;
4
- readonly input: HTMLInputElement;
5
- readonly button: HTMLButtonElement;
6
- };
7
- //# sourceMappingURL=create-input.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"create-input.d.ts","sourceRoot":"","sources":["create-input.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAI7C,eAAO,MAAM,WAAW,UAAW,KAAK;;;;CAiCvC,CAAC"}
@@ -1,19 +0,0 @@
1
- import type { EditorView } from '@milkdown/prose';
2
- import type { InputMap } from '../item';
3
- export declare const filterInput: (currentView: EditorView, inputMap: InputMap, div: HTMLDivElement, input: HTMLInputElement, button: HTMLButtonElement) => ({
4
- command: import("../item").Event2Command;
5
- display: import("../item").Pred;
6
- update: import("../item").Updater;
7
- placeholder: string;
8
- } & {
9
- bind: true;
10
- }) | ({
11
- command: import("../item").Event2Command;
12
- display: import("../item").Pred;
13
- update: import("../item").Updater;
14
- placeholder: string;
15
- } & {
16
- bind?: false | undefined;
17
- buttonText: string;
18
- }) | undefined;
19
- //# sourceMappingURL=filter-input.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"filter-input.d.ts","sourceRoot":"","sources":["filter-input.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAElD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAExC,eAAO,MAAM,WAAW,gBACP,UAAU,YACb,QAAQ,OACb,cAAc,SACZ,gBAAgB,UACf,iBAAiB;;;;;;;;;;;;;;;cAsB5B,CAAC"}
@@ -1,10 +0,0 @@
1
- import type { EditorView } from '@milkdown/prose';
2
- import { Utils } from '@milkdown/utils';
3
- import type { InputMap } from '../item';
4
- export declare const createInputManager: (inputMap: InputMap, utils: Utils) => {
5
- destroy: () => void;
6
- hide: () => void;
7
- update: (editorView: EditorView) => void;
8
- render: (editorView: EditorView) => void;
9
- };
10
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAExC,OAAO,KAAK,EAAiB,QAAQ,EAAE,MAAM,SAAS,CAAC;AAKvD,eAAO,MAAM,kBAAkB,aAAc,QAAQ,SAAS,KAAK;;;yBAgCtC,UAAU;yBAOV,UAAU;CAMtC,CAAC"}
@@ -1,3 +0,0 @@
1
- import { Emotion, ThemeTool } from '@milkdown/core';
2
- export declare const injectStyle: (themeTool: ThemeTool, { css }: Emotion) => string;
3
- //# sourceMappingURL=style.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"style.d.ts","sourceRoot":"","sources":["style.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEpD,eAAO,MAAM,WAAW,cAAe,SAAS,WAAW,OAAO,WA8DjE,CAAC"}
package/lib/src/item.d.ts DELETED
@@ -1,53 +0,0 @@
1
- import { Ctx } from '@milkdown/core';
2
- import { EditorView, Schema } from '@milkdown/prose';
3
- export declare type Pred = (view: EditorView) => boolean;
4
- export declare type Updater = (view: EditorView, $: HTMLElement) => void;
5
- export declare type Event2Command = (e: Event) => void;
6
- export declare type ButtonItem = {
7
- $: HTMLElement;
8
- command: () => void;
9
- active: Pred;
10
- disable?: Pred;
11
- enable: Pred;
12
- };
13
- export declare type InputItem = {
14
- command: Event2Command;
15
- display: Pred;
16
- update: Updater;
17
- placeholder: string;
18
- } & ({
19
- bind: true;
20
- } | {
21
- bind?: false;
22
- buttonText: string;
23
- });
24
- export declare enum ButtonAction {
25
- ToggleBold = 0,
26
- ToggleItalic = 1,
27
- ToggleStrike = 2,
28
- ToggleCode = 3,
29
- ToggleLink = 4
30
- }
31
- export declare enum InputAction {
32
- ModifyLink = 0,
33
- ModifyImage = 1,
34
- ModifyInlineMath = 2
35
- }
36
- export declare type ButtonMap = Record<ButtonAction, ButtonItem>;
37
- export declare type InputMap = Record<InputAction, InputItem>;
38
- export declare type InputOptions = {
39
- link: {
40
- placeholder: string;
41
- buttonText: string;
42
- };
43
- image: {
44
- placeholder: string;
45
- buttonText: string;
46
- };
47
- inlineMath: {
48
- placeholder: string;
49
- };
50
- };
51
- export declare const inputMap: (schema: Schema, ctx: Ctx, inputOptions: InputOptions) => InputMap;
52
- export declare const buttonMap: (schema: Schema, ctx: Ctx) => ButtonMap;
53
- //# sourceMappingURL=item.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"item.d.ts","sourceRoot":"","sources":["item.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AACrC,OAAO,EAAE,UAAU,EAA0B,MAAM,EAAiB,MAAM,iBAAiB,CAAC;AAa5F,oBAAY,IAAI,GAAG,CAAC,IAAI,EAAE,UAAU,KAAK,OAAO,CAAC;AACjD,oBAAY,OAAO,GAAG,CAAC,IAAI,EAAE,UAAU,EAAE,CAAC,EAAE,WAAW,KAAK,IAAI,CAAC;AACjE,oBAAY,aAAa,GAAG,CAAC,CAAC,EAAE,KAAK,KAAK,IAAI,CAAC;AAE/C,oBAAY,UAAU,GAAG;IACrB,CAAC,EAAE,WAAW,CAAC;IACf,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,MAAM,EAAE,IAAI,CAAC;IACb,OAAO,CAAC,EAAE,IAAI,CAAC;IACf,MAAM,EAAE,IAAI,CAAC;CAChB,CAAC;AAEF,oBAAY,SAAS,GAAG;IACpB,OAAO,EAAE,aAAa,CAAC;IACvB,OAAO,EAAE,IAAI,CAAC;IACd,MAAM,EAAE,OAAO,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;CACvB,GAAG,CACE;IACI,IAAI,EAAE,IAAI,CAAC;CACd,GACD;IACI,IAAI,CAAC,EAAE,KAAK,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;CACtB,CACN,CAAC;AAEF,oBAAY,YAAY;IACpB,UAAU,IAAA;IACV,YAAY,IAAA;IACZ,YAAY,IAAA;IACZ,UAAU,IAAA;IACV,UAAU,IAAA;CACb;AAED,oBAAY,WAAW;IACnB,UAAU,IAAA;IACV,WAAW,IAAA;IACX,gBAAgB,IAAA;CACnB;AAED,oBAAY,SAAS,GAAG,MAAM,CAAC,YAAY,EAAE,UAAU,CAAC,CAAC;AACzD,oBAAY,QAAQ,GAAG,MAAM,CAAC,WAAW,EAAE,SAAS,CAAC,CAAC;AAEtD,oBAAY,YAAY,GAAG;IACvB,IAAI,EAAE;QACF,WAAW,EAAE,MAAM,CAAC;QACpB,UAAU,EAAE,MAAM,CAAC;KACtB,CAAC;IACF,KAAK,EAAE;QACH,WAAW,EAAE,MAAM,CAAC;QACpB,UAAU,EAAE,MAAM,CAAC;KACtB,CAAC;IACF,UAAU,EAAE;QACR,WAAW,EAAE,MAAM,CAAC;KACvB,CAAC;CACL,CAAC;AAEF,eAAO,MAAM,QAAQ,WAAY,MAAM,OAAO,GAAG,gBAAgB,YAAY,KAAG,QA0B/E,CAAC;AAEF,eAAO,MAAM,SAAS,WAAY,MAAM,OAAO,GAAG,KAAG,SAepD,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"selection-marks-tooltip.d.ts","sourceRoot":"","sources":["selection-marks-tooltip.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC/D,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAIxC,OAAO,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAElD,eAAO,MAAM,YAAY,cAAe,SAAS,YAAY,QAAQ,SAAS,KAAK;mBAUzD,UAAU;;yBAqBP,UAAU;wBAKX,OAAO;CAIlC,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"element.d.ts","sourceRoot":"","sources":["element.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,YAAY,YAAa,WAAW,WAAW,MAAM,KAAG,OACxB,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AACA,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,eAAe,CAAC;AAC9B,cAAc,UAAU,CAAC"}
@@ -1,9 +0,0 @@
1
- import { Ctx } from '@milkdown/core';
2
- import { Event2Command, Updater } from '../item';
3
- export declare const modifyLink: (ctx: Ctx) => Event2Command;
4
- export declare const modifyInlineMath: (ctx: Ctx) => Event2Command;
5
- export declare const modifyImage: (ctx: Ctx) => Event2Command;
6
- export declare const updateLinkView: Updater;
7
- export declare const updateInlineMathView: Updater;
8
- export declare const updateImageView: Updater;
9
- //# sourceMappingURL=input.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"input.d.ts","sourceRoot":"","sources":["input.ts"],"names":[],"mappings":"AACA,OAAO,EAAe,GAAG,EAAE,MAAM,gBAAgB,CAAC;AAGlD,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAGjD,eAAO,MAAM,UAAU,QACb,GAAG,KAAG,aAiBX,CAAC;AAEN,eAAO,MAAM,gBAAgB,QACnB,GAAG,KAAG,aAaX,CAAC;AAEN,eAAO,MAAM,WAAW,QACd,GAAG,KAAG,aAiBX,CAAC;AAEN,eAAO,MAAM,cAAc,EAAE,OA4B5B,CAAC;AAEF,eAAO,MAAM,oBAAoB,EAAE,OAkBlC,CAAC;AAEF,eAAO,MAAM,eAAe,EAAE,OAkB7B,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"prosemirror.d.ts","sourceRoot":"","sources":["prosemirror.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAkB,QAAQ,EAAE,IAAI,EAAE,QAAQ,EAAiB,MAAM,iBAAiB,CAAC;AAEvG,oBAAY,QAAQ,GAAG;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,eAAO,MAAM,OAAO,gBAAiB,WAAW,QAAQ,QAAQ,KAAG,OAIlE,CAAC;AAEF,eAAO,MAAM,eAAe,gBAAiB,WAAW,KAAG,OAU1D,CAAC;AAEF,eAAO,MAAM,aAAa,gBAAiB,WAAW,KAAG,OAC0B,CAAC;AAEpF,eAAO,MAAM,mBAAmB,gBAAiB,WAAW,QAAQ,QAAQ,KAAG,OACc,CAAC;AAE9F,eAAO,MAAM,aAAa,aAAc,QAAQ,QAAQ,IAAI,YAE3D,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"toggle.d.ts","sourceRoot":"","sources":["toggle.ts"],"names":[],"mappings":"AACA,OAAO,EAAe,GAAG,EAAgB,MAAM,gBAAgB,CAAC;AAChE,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAEhD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAG1C,eAAO,MAAM,gBAAgB,QACpB,GAAG,YACE,IAAI,OACT,MAAM,QACL,QAAQ,kBACE,QAAQ,KACzB,UAMD,CAAC"}
@@ -1,19 +0,0 @@
1
- /* Copyright 2021, Milkdown by Mirone. */
2
- import { calculateTextPosition, EditorView } from '@milkdown/prose';
3
-
4
- export const calcInputPos = (view: EditorView, input: HTMLDivElement) => {
5
- calculateTextPosition(view, input, (start, end, target, parent) => {
6
- const $editor = input.parentElement;
7
- if (!$editor) {
8
- throw new Error();
9
- }
10
-
11
- const selectionWidth = end.left - start.left;
12
- let left = start.left - parent.left - (target.width - selectionWidth) / 2;
13
- const top = start.bottom - parent.top + 14 + $editor.scrollTop;
14
-
15
- if (left < 0) left = 0;
16
-
17
- return [top, left];
18
- });
19
- };
@@ -1,39 +0,0 @@
1
- /* Copyright 2021, Milkdown by Mirone. */
2
- import type { Utils } from '@milkdown/utils';
3
-
4
- import { injectStyle } from './style';
5
-
6
- export const createInput = (utils: Utils) => {
7
- const div = document.createElement('div');
8
- const style = utils.getStyle(injectStyle);
9
- if (style) {
10
- div.classList.add(style);
11
- }
12
-
13
- div.classList.add('tooltip-input');
14
-
15
- const input = document.createElement('input');
16
- div.appendChild(input);
17
- const button = document.createElement('button');
18
- div.appendChild(button);
19
-
20
- input.addEventListener('input', (e) => {
21
- const { target } = e;
22
- if (!(target instanceof HTMLInputElement)) {
23
- return;
24
- }
25
-
26
- if (!target.value) {
27
- button.classList.add('disable');
28
- return;
29
- }
30
-
31
- button.classList.remove('disable');
32
- });
33
-
34
- return {
35
- div,
36
- input,
37
- button,
38
- } as const;
39
- };
@@ -1,33 +0,0 @@
1
- /* Copyright 2021, Milkdown by Mirone. */
2
- import type { EditorView } from '@milkdown/prose';
3
-
4
- import type { InputMap } from '../item';
5
-
6
- export const filterInput = (
7
- currentView: EditorView,
8
- inputMap: InputMap,
9
- div: HTMLDivElement,
10
- input: HTMLInputElement,
11
- button: HTMLButtonElement,
12
- ) => {
13
- const target = Object.values(inputMap).find((input) => input.display(currentView));
14
-
15
- if (!target) {
16
- div.classList.add('hide');
17
- return;
18
- }
19
-
20
- div.classList.remove('hide');
21
-
22
- if (target.bind) {
23
- button.classList.add('hide');
24
- } else {
25
- button.classList.remove('hide');
26
- button.textContent = target.buttonText;
27
- }
28
-
29
- input.placeholder = target.placeholder;
30
- target.update(currentView, div);
31
-
32
- return target;
33
- };
@@ -1,55 +0,0 @@
1
- /* Copyright 2021, Milkdown by Mirone. */
2
- import type { EditorView } from '@milkdown/prose';
3
- import { Utils } from '@milkdown/utils';
4
-
5
- import type { Event2Command, InputMap } from '../item';
6
- import { calcInputPos } from './calc-input-pos';
7
- import { createInput } from './create-input';
8
- import { filterInput } from './filter-input';
9
-
10
- export const createInputManager = (inputMap: InputMap, utils: Utils) => {
11
- let inputCommand: Event2Command | undefined;
12
- let binding = false;
13
- const setCommand = (x?: Event2Command) => (inputCommand = x);
14
-
15
- const { div, button, input } = createInput(utils);
16
-
17
- const onClick = (e: Event) => {
18
- if (!inputCommand || button.classList.contains('disable')) return;
19
-
20
- e.stopPropagation();
21
- inputCommand(e);
22
- div.classList.add('hide');
23
- };
24
- const onInput = (e: Event) => {
25
- if (!binding || !inputCommand) return;
26
- inputCommand(e);
27
- };
28
-
29
- input.addEventListener('input', onInput);
30
- button.addEventListener('mousedown', onClick);
31
-
32
- return {
33
- destroy: () => {
34
- input.removeEventListener('input', onInput);
35
- div.removeEventListener('mousedown', onClick);
36
- div.remove();
37
- },
38
- hide: () => {
39
- div.classList.add('hide');
40
- setCommand();
41
- },
42
- update: (editorView: EditorView) => {
43
- const result = filterInput(editorView, inputMap, div, input, button);
44
- if (!result) return;
45
- binding = !!result.bind;
46
- setCommand(result.command);
47
- calcInputPos(editorView, div);
48
- },
49
- render: (editorView: EditorView) => {
50
- const wrapper = editorView.dom.parentNode;
51
- if (!wrapper) throw new Error();
52
- wrapper.appendChild(div);
53
- },
54
- };
55
- };