@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/README.md CHANGED
@@ -15,9 +15,9 @@ import { tooltip } from '@milkdown/plugin-tooltip';
15
15
  Editor.make().use(nord).use(commonmark).use(tooltip).create();
16
16
  ```
17
17
 
18
- # Placeholder
18
+ # Position
19
19
 
20
- Modify the input widgets of link and image.
20
+ Modify the tooltip widget's position, to show on the top or the bottom
21
21
 
22
22
  Example:
23
23
 
@@ -26,17 +26,7 @@ import { tooltipPlugin, tooltip } from '@milkdown/plugin-tooltip';
26
26
 
27
27
  Editor.make().use(
28
28
  tooltip.configure(tooltipPlugin, {
29
- link: {
30
- placeholder: 'Please input link...',
31
- buttonText: 'Confirm',
32
- },
33
- image: {
34
- placeholder: 'Please input image link...',
35
- buttonText: 'OK',
36
- },
37
- inlineMath: {
38
- placeholder: 'Please input inline math...',
39
- },
29
+ bottom: true,
40
30
  }),
41
31
  );
42
32
  ```
@@ -1,3 +1,3 @@
1
1
  import { EditorView } from '@milkdown/prose';
2
- export declare const calcButtonPos: (buttons: HTMLElement, view: EditorView) => void;
2
+ export declare const calcButtonPos: (buttons: HTMLElement, view: EditorView, isBottom: boolean) => void;
3
3
  //# sourceMappingURL=calc-button-pos.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"calc-button-pos.d.ts","sourceRoot":"","sources":["../../src/button-manager/calc-button-pos.ts"],"names":[],"mappings":"AACA,OAAO,EAAyB,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAEpE,eAAO,MAAM,aAAa,YAAa,WAAW,QAAQ,UAAU,YAAY,OAAO,SAkBtF,CAAC"}
@@ -5,6 +5,6 @@ declare type Tooltip = {
5
5
  dom: HTMLDivElement;
6
6
  render: (editorView: EditorView) => void;
7
7
  };
8
- export declare const createTooltip: (buttonMap: ButtonMap, utils: Utils) => Tooltip;
8
+ export declare const createTooltip: (buttonMap: ButtonMap, utils: Utils, className: string) => Tooltip;
9
9
  export {};
10
10
  //# sourceMappingURL=create-tooltip.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-tooltip.d.ts","sourceRoot":"","sources":["../../src/button-manager/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,aAAa,MAAM,KAAG,OAqBrF,CAAC"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"filter-button.d.ts","sourceRoot":"","sources":["../../src/button-manager/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,7 +1,7 @@
1
1
  import type { EditorView } from '@milkdown/prose';
2
2
  import type { Utils } from '@milkdown/utils';
3
3
  import type { ButtonMap } from '../item';
4
- export declare const createButtonManager: (buttonMap: ButtonMap, utils: Utils) => {
4
+ export declare const createButtonManager: (buttonMap: ButtonMap, utils: Utils, bottom: boolean, containerClassName: string) => {
5
5
  destroy: () => void;
6
6
  hide: () => void;
7
7
  update: (editorView: EditorView) => void;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/button-manager/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,cACjB,SAAS,SACb,KAAK,UACJ,OAAO,sBACK,MAAM;;;yBAyBD,UAAU;;CAUtC,CAAC"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"no-active.d.ts","sourceRoot":"","sources":["../../src/button-manager/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"}
@@ -0,0 +1,3 @@
1
+ import { Emotion, ThemeManager } from '@milkdown/core';
2
+ export declare const injectStyle: (themeManager: ThemeManager, { css }: Emotion) => string;
3
+ //# sourceMappingURL=style.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"style.d.ts","sourceRoot":"","sources":["../../src/button-manager/style.ts"],"names":[],"mappings":"AACA,OAAO,EAAS,OAAO,EAA2B,YAAY,EAA0B,MAAM,gBAAgB,CAAC;AAE/G,eAAO,MAAM,WAAW,iBAAkB,YAAY,WAAW,OAAO,WA8CvE,CAAC"}
package/lib/index.d.ts CHANGED
@@ -1 +1,19 @@
1
- export * from './src/index'
1
+ import { PluginKey } from '@milkdown/prose';
2
+ import { TooltipOptions } from './item';
3
+ export declare const key: PluginKey<any, any>;
4
+ export declare const tooltip: import("@milkdown/utils/lib/types").WithExtend<string, TooltipOptions, {
5
+ [x: string]: import("prosemirror-model").NodeType<any>;
6
+ } & {
7
+ [x: string]: import("prosemirror-model").MarkType<any>;
8
+ }, {
9
+ schema?: ((ctx: import("@milkdown/core").Ctx) => {
10
+ node?: Record<string, import("@milkdown/core").NodeSchema> | undefined;
11
+ mark?: Record<string, import("@milkdown/core").MarkSchema> | undefined;
12
+ }) | undefined;
13
+ view?: ((ctx: import("@milkdown/core").Ctx) => Partial<{
14
+ [x: string]: import("@milkdown/prose").NodeViewFactory;
15
+ } & {
16
+ [x: string]: import("@milkdown/prose").MarkViewFactory;
17
+ }>) | undefined;
18
+ }>;
19
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAU,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAGpD,OAAO,EAAa,cAAc,EAAE,MAAM,QAAQ,CAAC;AAGnD,eAAO,MAAM,GAAG,qBAA2C,CAAC;AAE5D,eAAO,MAAM,OAAO;;;;;;;;;;;;;;EAyClB,CAAC"}
package/lib/index.es.js CHANGED
@@ -14,125 +14,13 @@ var __spreadValues = (a, b) => {
14
14
  }
15
15
  return a;
16
16
  };
17
- import { commandsCtx, themeToolCtx, schemaCtx } from "@milkdown/core";
18
- import { findSelectedNodeOfType, findParentNode, TextSelection, calculateTextPosition, PluginKey, Plugin } from "@milkdown/prose";
19
- import { createPlugin as createPlugin$1, AtomList } from "@milkdown/utils";
20
- const elementIsTag = (element, tagName) => element.tagName === tagName.toUpperCase();
21
- const modifyLink = (ctx) => (e) => {
22
- const { target } = e;
23
- if (!(target instanceof HTMLElement)) {
24
- return () => true;
25
- }
26
- if (elementIsTag(target, "input")) {
27
- target.focus();
28
- return () => false;
29
- }
30
- const parent = target.parentNode;
31
- if (!parent)
32
- return () => false;
33
- const inputEl = Array.from(parent.children).find((el) => el.tagName === "INPUT");
34
- if (!(inputEl instanceof HTMLInputElement))
35
- return () => false;
36
- return ctx.get(commandsCtx).callByName("ModifyLink", inputEl.value);
37
- };
38
- const modifyInlineMath = (ctx) => (e) => {
39
- const { target } = e;
40
- if (!(target instanceof HTMLElement)) {
41
- return () => true;
42
- }
43
- const parent = target.parentNode;
44
- if (!parent)
45
- return () => false;
46
- const inputEl = Array.from(parent.children).find((el) => el.tagName === "INPUT");
47
- if (!(inputEl instanceof HTMLInputElement))
48
- return () => false;
49
- return ctx.get(commandsCtx).callByName("ModifyInlineMath", inputEl.value);
50
- };
51
- const modifyImage = (ctx) => (e) => {
52
- const { target } = e;
53
- if (!(target instanceof HTMLElement)) {
54
- return () => true;
55
- }
56
- if (elementIsTag(target, "input")) {
57
- target.focus();
58
- return () => false;
59
- }
60
- const parent = target.parentNode;
61
- if (!parent)
62
- return () => false;
63
- const inputEl = Array.from(parent.children).find((el) => el.tagName === "INPUT");
64
- if (!(inputEl instanceof HTMLInputElement))
65
- return () => false;
66
- return ctx.get(commandsCtx).callByName("ModifyImage", inputEl.value);
67
- };
68
- const updateLinkView = (view, $) => {
69
- const { marks } = view.state.schema;
70
- const { firstChild, lastElementChild } = $;
71
- if (!(firstChild instanceof HTMLInputElement) || !(lastElementChild instanceof HTMLButtonElement))
72
- return;
73
- const { selection } = view.state;
74
- let node;
75
- view.state.doc.nodesBetween(selection.from, selection.to, (n) => {
76
- if (marks.link.isInSet(n.marks)) {
77
- node = n;
78
- return false;
79
- }
80
- return;
81
- });
82
- if (!node)
83
- return;
84
- const mark = node.marks.find((m) => m.type === marks.link);
85
- if (!mark)
86
- return;
87
- const value = mark.attrs.href;
88
- firstChild.value = value;
89
- if (!value) {
90
- lastElementChild.classList.add("disable");
91
- return;
92
- }
93
- if (lastElementChild.classList.contains("disable")) {
94
- lastElementChild.classList.remove("disable");
95
- }
96
- };
97
- const updateInlineMathView = (view, $) => {
98
- const { nodes } = view.state.schema;
99
- const { firstChild, lastElementChild } = $;
100
- if (!(firstChild instanceof HTMLInputElement) || !(lastElementChild instanceof HTMLButtonElement))
101
- return;
102
- const result = findSelectedNodeOfType(view.state.selection, nodes.math_inline);
103
- if (!result)
104
- return;
105
- const { node } = result;
106
- const value = node.attrs.value;
107
- firstChild.value = value;
108
- if (!value) {
109
- lastElementChild.classList.add("disable");
110
- return;
111
- }
112
- if (lastElementChild.classList.contains("disable")) {
113
- lastElementChild.classList.remove("disable");
114
- }
115
- };
116
- const updateImageView = (view, $) => {
117
- const { nodes } = view.state.schema;
118
- const { firstChild, lastElementChild } = $;
119
- if (!(firstChild instanceof HTMLInputElement) || !(lastElementChild instanceof HTMLButtonElement))
120
- return;
121
- const result = findSelectedNodeOfType(view.state.selection, nodes.image);
122
- if (!result)
123
- return;
124
- const { node } = result;
125
- const value = node.attrs.src;
126
- firstChild.value = value.length > 50 ? "Url is too long to display." : value;
127
- if (!value) {
128
- lastElementChild.classList.add("disable");
129
- return;
130
- }
131
- if (lastElementChild.classList.contains("disable")) {
132
- lastElementChild.classList.remove("disable");
133
- }
134
- };
17
+ import { themeManagerCtx, ThemeIcon, commandsCtx, ThemeSize, ThemeBorder, ThemeShadow, ThemeColor, schemaCtx } from "@milkdown/core";
18
+ import { findParentNode, TextSelection, calculateTextPosition, PluginKey, Plugin } from "@milkdown/prose";
19
+ import { createPlugin as createPlugin$1 } from "@milkdown/utils";
135
20
  const hasMark = (editorState, type) => {
21
+ if (!type) {
22
+ return false;
23
+ }
136
24
  const { from, to } = editorState.selection;
137
25
  return editorState.doc.rangeHasMark(from, from === to ? to + 1 : to, type);
138
26
  };
@@ -148,59 +36,43 @@ const isTextSelection = (editorState) => {
148
36
  };
149
37
  const isInCodeFence = (editorState) => Boolean(findParentNode((node) => !!node.type.spec.code)(editorState.selection));
150
38
  const isTextAndNotHasMark = (editorState, mark) => !isTextSelection(editorState) || isInCodeFence(editorState) || hasMark(editorState, mark);
151
- const createToggleIcon = (ctx, iconName, key2, mark, disableForMark) => ({
152
- $: ctx.get(themeToolCtx).slots.icon(iconName),
153
- command: () => ctx.get(commandsCtx).callByName(key2),
154
- active: (view) => hasMark(view.state, mark),
155
- disable: (view) => isTextAndNotHasMark(view.state, disableForMark),
156
- enable: (view) => !!mark && !!view.state.schema.marks[mark.name]
157
- });
158
- var ButtonAction;
159
- (function(ButtonAction2) {
160
- ButtonAction2[ButtonAction2["ToggleBold"] = 0] = "ToggleBold";
161
- ButtonAction2[ButtonAction2["ToggleItalic"] = 1] = "ToggleItalic";
162
- ButtonAction2[ButtonAction2["ToggleStrike"] = 2] = "ToggleStrike";
163
- ButtonAction2[ButtonAction2["ToggleCode"] = 3] = "ToggleCode";
164
- ButtonAction2[ButtonAction2["ToggleLink"] = 4] = "ToggleLink";
165
- })(ButtonAction || (ButtonAction = {}));
166
- var InputAction;
167
- (function(InputAction2) {
168
- InputAction2[InputAction2["ModifyLink"] = 0] = "ModifyLink";
169
- InputAction2[InputAction2["ModifyImage"] = 1] = "ModifyImage";
170
- InputAction2[InputAction2["ModifyInlineMath"] = 2] = "ModifyInlineMath";
171
- })(InputAction || (InputAction = {}));
172
- const inputMap = (schema, ctx, inputOptions) => {
173
- const { marks, nodes } = schema;
39
+ const createToggleIcon = (ctx, iconName, key2, mark, disableForMark) => {
40
+ var _a;
174
41
  return {
175
- [0]: __spreadValues({
176
- display: (view) => view.state.selection.empty && view.state.selection instanceof TextSelection && hasMark(view.state, marks.link),
177
- command: modifyLink(ctx),
178
- update: updateLinkView
179
- }, inputOptions.link),
180
- [2]: __spreadValues({
181
- display: (view) => Boolean(findSelectedNodeOfType(view.state.selection, nodes.math_inline)),
182
- command: modifyInlineMath(ctx),
183
- update: updateInlineMathView,
184
- bind: true
185
- }, inputOptions.inlineMath),
186
- [1]: __spreadValues({
187
- display: (view) => Boolean(findSelectedNodeOfType(view.state.selection, nodes.image)),
188
- command: modifyImage(ctx),
189
- update: updateImageView
190
- }, inputOptions.image)
42
+ $: (_a = ctx.get(themeManagerCtx).get(ThemeIcon, iconName)) == null ? void 0 : _a.dom,
43
+ command: () => ctx.get(commandsCtx).call(key2),
44
+ active: (view) => hasMark(view.state, mark),
45
+ disable: (view) => isTextAndNotHasMark(view.state, disableForMark),
46
+ enable: (view) => !!mark && !!view.state.schema.marks[mark.name]
191
47
  };
192
48
  };
193
- const buttonMap = (schema, ctx) => {
194
- const { marks } = schema;
49
+ const Buttonize = ({ icon, onClick, isHidden, isActive }, ctx) => {
50
+ var _a;
195
51
  return {
196
- [0]: createToggleIcon(ctx, "bold", "ToggleBold", marks.strong, marks.code_inline),
197
- [1]: createToggleIcon(ctx, "italic", "ToggleItalic", marks.em, marks.code_inline),
198
- [2]: createToggleIcon(ctx, "strikeThrough", "ToggleStrikeThrough", marks.strike_through, marks.code_inline),
199
- [3]: createToggleIcon(ctx, "code", "ToggleInlineCode", marks.code_inline, marks.link),
200
- [4]: createToggleIcon(ctx, "link", "ToggleLink", marks.link, marks.code_inline)
52
+ $: typeof icon === "function" ? icon(ctx) : (_a = ctx.get(themeManagerCtx).get(ThemeIcon, icon)) == null ? void 0 : _a.dom,
53
+ command: typeof onClick === "string" ? () => ctx.get(commandsCtx).call(onClick) : onClick(ctx),
54
+ disable: isHidden(ctx),
55
+ active: isActive(ctx),
56
+ enable: (view) => !isHidden(ctx)(view)
201
57
  };
202
58
  };
203
- const calcButtonPos = (buttons, view) => {
59
+ const buttonMap = (schema, ctx, items) => {
60
+ const { marks } = schema;
61
+ const ButtonItems = Array();
62
+ if (typeof items !== "undefined") {
63
+ items.forEach((item) => {
64
+ ButtonItems.push(Buttonize(item, ctx));
65
+ });
66
+ }
67
+ return __spreadValues({
68
+ [0]: createToggleIcon(ctx, "bold", "ToggleBold", marks["strong"], marks["code_inline"]),
69
+ [1]: createToggleIcon(ctx, "italic", "ToggleItalic", marks["em"], marks["code_inline"]),
70
+ [2]: createToggleIcon(ctx, "strikeThrough", "ToggleStrikeThrough", marks["strike_through"], marks["code_inline"]),
71
+ [3]: createToggleIcon(ctx, "code", "ToggleInlineCode", marks["code_inline"], marks["link"]),
72
+ [4]: createToggleIcon(ctx, "link", "ToggleLink", marks["link"], marks["code_inline"])
73
+ }, ButtonItems);
74
+ };
75
+ const calcButtonPos = (buttons, view, isBottom) => {
204
76
  buttons.classList.remove("hide");
205
77
  calculateTextPosition(view, buttons, (start, end, target, parent) => {
206
78
  const $editor = buttons.parentElement;
@@ -212,25 +84,25 @@ const calcButtonPos = (buttons, view) => {
212
84
  let top = start.top - parent.top - target.height - 14 + $editor.scrollTop;
213
85
  if (left < 0)
214
86
  left = 0;
215
- if (start.top < target.height) {
87
+ if (start.top - parent.top < target.height || isBottom && parent.bottom - start.bottom > target.height) {
216
88
  top = start.bottom - parent.top + 14 + $editor.scrollTop;
217
89
  }
218
90
  return [top, left];
219
91
  });
220
92
  };
221
- const injectStyle$1 = (themeTool, { css }) => {
222
- var _a, _b;
223
- const { palette, mixin, size } = themeTool;
93
+ const injectStyle = (themeManager, { css }) => {
94
+ const palette = (color, opacity = 1) => themeManager.get(ThemeColor, [color, opacity]);
95
+ const lineWidth = themeManager.get(ThemeSize, "lineWidth");
224
96
  return css`
225
97
  display: inline-flex;
226
98
  cursor: pointer;
227
99
  justify-content: space-evenly;
228
100
  position: absolute;
229
- border-radius: ${size.radius};
101
+ border-radius: ${themeManager.get(ThemeSize, "radius")};
230
102
  z-index: 2;
231
103
 
232
- ${(_a = mixin.border) == null ? void 0 : _a.call(mixin)};
233
- ${(_b = mixin.shadow) == null ? void 0 : _b.call(mixin)};
104
+ ${themeManager.get(ThemeBorder, void 0)}
105
+ ${themeManager.get(ThemeShadow, void 0)}
234
106
 
235
107
  overflow: hidden;
236
108
  background: ${palette("surface")};
@@ -239,8 +111,8 @@ const injectStyle$1 = (themeTool, { css }) => {
239
111
  position: relative;
240
112
  color: ${palette("solid", 0.87)};
241
113
 
242
- width: 3rem;
243
- line-height: 3rem;
114
+ width: 2em;
115
+ line-height: 2em;
244
116
  text-align: center;
245
117
  transition: all 0.4s ease-in-out;
246
118
  &:hover {
@@ -253,8 +125,8 @@ const injectStyle$1 = (themeTool, { css }) => {
253
125
  content: '';
254
126
  position: absolute;
255
127
  top: 0;
256
- right: calc(-0.5 * ${size.lineWidth});
257
- width: ${size.lineWidth};
128
+ right: calc(-0.5 * ${lineWidth});
129
+ width: ${lineWidth};
258
130
  bottom: 0;
259
131
  background: ${palette("line")};
260
132
  }
@@ -265,13 +137,15 @@ const injectStyle$1 = (themeTool, { css }) => {
265
137
  }
266
138
  `;
267
139
  };
268
- const createTooltip = (buttonMap2, utils) => {
140
+ const createTooltip = (buttonMap2, utils, className) => {
269
141
  const div = document.createElement("div");
270
- const style = utils.getStyle(injectStyle$1) || "";
271
- if (style) {
272
- div.classList.add(style);
273
- }
274
- div.classList.add("tooltip");
142
+ utils.themeManager.onFlush(() => {
143
+ const style = utils.getStyle(injectStyle) || "";
144
+ if (style) {
145
+ div.classList.add(style);
146
+ }
147
+ });
148
+ div.classList.add(className);
275
149
  return {
276
150
  dom: div,
277
151
  render: (editorView) => {
@@ -302,8 +176,8 @@ const filterButton = (buttonMap2, view) => {
302
176
  });
303
177
  return noActive(buttonMap2, view);
304
178
  };
305
- const createButtonManager = (buttonMap2, utils) => {
306
- const { dom: buttons, render } = createTooltip(buttonMap2, utils);
179
+ const createButtonManager = (buttonMap2, utils, bottom, containerClassName) => {
180
+ const { dom: buttons, render } = createTooltip(buttonMap2, utils, containerClassName);
307
181
  const onClick = (e) => {
308
182
  const target = Object.values(buttonMap2).find(({ $ }) => e.target instanceof Element && $.contains(e.target));
309
183
  if (!target)
@@ -328,185 +202,16 @@ const createButtonManager = (buttonMap2, utils) => {
328
202
  hide();
329
203
  return;
330
204
  }
331
- calcButtonPos(buttons, editorView);
205
+ calcButtonPos(buttons, editorView, bottom);
332
206
  },
333
207
  render
334
208
  };
335
209
  };
336
- const calcInputPos = (view, input) => {
337
- calculateTextPosition(view, input, (start, end, target, parent) => {
338
- const $editor = input.parentElement;
339
- if (!$editor) {
340
- throw new Error();
341
- }
342
- const selectionWidth = end.left - start.left;
343
- let left = start.left - parent.left - (target.width - selectionWidth) / 2;
344
- const top = start.bottom - parent.top + 14 + $editor.scrollTop;
345
- if (left < 0)
346
- left = 0;
347
- return [top, left];
348
- });
349
- };
350
- const injectStyle = (themeTool, { css }) => {
351
- var _a, _b;
352
- const { palette, mixin, size } = themeTool;
353
- return css`
354
- ${(_a = mixin.border) == null ? void 0 : _a.call(mixin)};
355
- ${(_b = mixin.shadow) == null ? void 0 : _b.call(mixin)};
356
-
357
- display: inline-flex;
358
- justify-content: space-between;
359
- align-items: center;
360
- position: absolute;
361
- background: ${palette("surface")};
362
- border-radius: ${size.radius};
363
- font-size: 1rem;
364
-
365
- height: 3.5rem;
366
- box-sizing: border-box;
367
- width: 25.5rem;
368
- padding: 0 1rem;
369
- gap: 1rem;
370
- z-index: 2;
371
-
372
- input,
373
- button {
374
- all: unset;
375
- }
376
-
377
- input {
378
- flex-grow: 1;
379
- caret-color: ${palette("primary")};
380
- &::placeholder {
381
- color: ${palette("neutral", 0.6)};
382
- }
383
- }
384
-
385
- button {
386
- cursor: pointer;
387
- height: 2.25rem;
388
- color: ${palette("primary")};
389
- font-size: 0.875rem;
390
- padding: 0 0.5rem;
391
- font-weight: 500;
392
- letter-spacing: 1.25px;
393
- &:hover {
394
- background-color: ${palette("secondary", 0.12)};
395
- }
396
- &.disable {
397
- color: ${palette("neutral", 0.38)};
398
- cursor: not-allowed;
399
- &:hover {
400
- background: transparent;
401
- }
402
- }
403
- &.hide {
404
- display: none;
405
- }
406
- }
407
-
408
- &.hide {
409
- display: none;
410
- }
411
- `;
412
- };
413
- const createInput = (utils) => {
414
- const div = document.createElement("div");
415
- const style = utils.getStyle(injectStyle);
416
- if (style) {
417
- div.classList.add(style);
418
- }
419
- div.classList.add("tooltip-input");
420
- const input = document.createElement("input");
421
- div.appendChild(input);
422
- const button = document.createElement("button");
423
- div.appendChild(button);
424
- input.addEventListener("input", (e) => {
425
- const { target } = e;
426
- if (!(target instanceof HTMLInputElement)) {
427
- return;
428
- }
429
- if (!target.value) {
430
- button.classList.add("disable");
431
- return;
432
- }
433
- button.classList.remove("disable");
434
- });
435
- return {
436
- div,
437
- input,
438
- button
439
- };
440
- };
441
- const filterInput = (currentView, inputMap2, div, input, button) => {
442
- const target = Object.values(inputMap2).find((input2) => input2.display(currentView));
443
- if (!target) {
444
- div.classList.add("hide");
445
- return;
446
- }
447
- div.classList.remove("hide");
448
- if (target.bind) {
449
- button.classList.add("hide");
450
- } else {
451
- button.classList.remove("hide");
452
- button.textContent = target.buttonText;
453
- }
454
- input.placeholder = target.placeholder;
455
- target.update(currentView, div);
456
- return target;
457
- };
458
- const createInputManager = (inputMap2, utils) => {
459
- let inputCommand;
460
- let binding = false;
461
- const setCommand = (x) => inputCommand = x;
462
- const { div, button, input } = createInput(utils);
463
- const onClick = (e) => {
464
- if (!inputCommand || button.classList.contains("disable"))
465
- return;
466
- e.stopPropagation();
467
- inputCommand(e);
468
- div.classList.add("hide");
469
- };
470
- const onInput = (e) => {
471
- if (!binding || !inputCommand)
472
- return;
473
- inputCommand(e);
474
- };
475
- input.addEventListener("input", onInput);
476
- button.addEventListener("mousedown", onClick);
477
- return {
478
- destroy: () => {
479
- input.removeEventListener("input", onInput);
480
- div.removeEventListener("mousedown", onClick);
481
- div.remove();
482
- },
483
- hide: () => {
484
- div.classList.add("hide");
485
- setCommand();
486
- },
487
- update: (editorView) => {
488
- const result = filterInput(editorView, inputMap2, div, input, button);
489
- if (!result)
490
- return;
491
- binding = !!result.bind;
492
- setCommand(result.command);
493
- calcInputPos(editorView, div);
494
- },
495
- render: (editorView) => {
496
- const wrapper = editorView.dom.parentNode;
497
- if (!wrapper)
498
- throw new Error();
499
- wrapper.appendChild(div);
500
- }
501
- };
502
- };
503
- const createPlugin = (buttonMap2, inputMap2, utils) => {
504
- const buttonManager = createButtonManager(buttonMap2, utils);
505
- const inputManager = createInputManager(inputMap2, utils);
210
+ const createPlugin = (buttonMap2, utils, bottom, containerClassName) => {
211
+ const buttonManager = createButtonManager(buttonMap2, utils, bottom, containerClassName);
506
212
  let shouldHide = false;
507
213
  const hide = () => {
508
214
  buttonManager.hide();
509
- inputManager.hide();
510
215
  };
511
216
  const update = (view, prevState) => {
512
217
  const { state } = view;
@@ -518,17 +223,14 @@ const createPlugin = (buttonMap2, inputMap2, utils) => {
518
223
  if (isEqualSelection)
519
224
  return;
520
225
  buttonManager.update(view);
521
- inputManager.update(view);
522
226
  };
523
227
  return {
524
228
  update,
525
229
  destroy: () => {
526
230
  buttonManager.destroy();
527
- inputManager.destroy();
528
231
  },
529
232
  render: (editorView) => {
530
233
  buttonManager.render(editorView);
531
- inputManager.render(editorView);
532
234
  update(editorView);
533
235
  },
534
236
  setHide: (isTyping) => {
@@ -537,25 +239,13 @@ const createPlugin = (buttonMap2, inputMap2, utils) => {
537
239
  };
538
240
  };
539
241
  const key = new PluginKey("MILKDOWN_PLUGIN_TOOLTIP");
540
- const tooltipPlugin = createPlugin$1((utils, options) => {
242
+ const tooltip = createPlugin$1((utils, options) => {
541
243
  return {
542
244
  id: "tooltip",
543
245
  prosePlugins: (_, ctx) => {
544
- var _a, _b, _c;
246
+ var _a, _b;
545
247
  const schema = ctx.get(schemaCtx);
546
- const manager = createPlugin(buttonMap(schema, ctx), inputMap(schema, ctx, {
547
- link: __spreadValues({
548
- placeholder: "Input Web Link",
549
- buttonText: "APPLY"
550
- }, (_a = options == null ? void 0 : options.link) != null ? _a : {}),
551
- image: __spreadValues({
552
- placeholder: "Input Image Link",
553
- buttonText: "APPLY"
554
- }, (_b = options == null ? void 0 : options.image) != null ? _b : {}),
555
- inlineMath: __spreadValues({
556
- placeholder: "Input Math"
557
- }, (_c = options == null ? void 0 : options.inlineMath) != null ? _c : {})
558
- }), utils);
248
+ const manager = createPlugin(buttonMap(schema, ctx, options == null ? void 0 : options.items), utils, (_a = options == null ? void 0 : options.bottom) != null ? _a : false, (_b = options == null ? void 0 : options.className) != null ? _b : "tooltip");
559
249
  const plugin = new Plugin({
560
250
  key,
561
251
  props: {
@@ -587,6 +277,5 @@ const tooltipPlugin = createPlugin$1((utils, options) => {
587
277
  }
588
278
  };
589
279
  });
590
- const tooltip = AtomList.create([tooltipPlugin()]);
591
- export { key, tooltip, tooltipPlugin };
280
+ export { key, tooltip };
592
281
  //# sourceMappingURL=index.es.js.map