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