@milkdown/plugin-tooltip 5.5.0 → 6.0.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 (75) 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 +21 -1
  15. package/lib/index.d.ts.map +1 -0
  16. package/lib/index.es.js +64 -387
  17. package/lib/index.es.js.map +1 -1
  18. package/lib/item.d.ts +34 -0
  19. package/lib/item.d.ts.map +1 -0
  20. package/lib/{src/selection-marks-tooltip.d.ts → selection-marks-tooltip.d.ts} +3 -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 +0 -0
  27. package/lib/utility/prosemirror.d.ts.map +1 -0
  28. package/lib/{src/utility → utility}/toggle.d.ts +0 -0
  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 +9 -7
  33. package/src/button-manager/filter-button.ts +1 -1
  34. package/src/button-manager/index.ts +8 -3
  35. package/src/button-manager/no-active.ts +1 -1
  36. package/src/button-manager/style.ts +11 -10
  37. package/src/index.ts +6 -20
  38. package/src/item.ts +34 -75
  39. package/src/selection-marks-tooltip.ts +8 -9
  40. package/src/utility/index.ts +0 -1
  41. package/src/utility/toggle.ts +3 -3
  42. package/lib/src/button-manager/calc-button-pos.d.ts.map +0 -1
  43. package/lib/src/button-manager/create-tooltip.d.ts.map +0 -1
  44. package/lib/src/button-manager/filter-button.d.ts.map +0 -1
  45. package/lib/src/button-manager/index.d.ts.map +0 -1
  46. package/lib/src/button-manager/no-active.d.ts.map +0 -1
  47. package/lib/src/button-manager/style.d.ts +0 -3
  48. package/lib/src/button-manager/style.d.ts.map +0 -1
  49. package/lib/src/index.d.ts +0 -21
  50. package/lib/src/index.d.ts.map +0 -1
  51. package/lib/src/input-manager/calc-input-pos.d.ts +0 -3
  52. package/lib/src/input-manager/calc-input-pos.d.ts.map +0 -1
  53. package/lib/src/input-manager/create-input.d.ts +0 -7
  54. package/lib/src/input-manager/create-input.d.ts.map +0 -1
  55. package/lib/src/input-manager/filter-input.d.ts +0 -19
  56. package/lib/src/input-manager/filter-input.d.ts.map +0 -1
  57. package/lib/src/input-manager/index.d.ts +0 -10
  58. package/lib/src/input-manager/index.d.ts.map +0 -1
  59. package/lib/src/input-manager/style.d.ts +0 -3
  60. package/lib/src/input-manager/style.d.ts.map +0 -1
  61. package/lib/src/item.d.ts +0 -53
  62. package/lib/src/item.d.ts.map +0 -1
  63. package/lib/src/selection-marks-tooltip.d.ts.map +0 -1
  64. package/lib/src/utility/element.d.ts.map +0 -1
  65. package/lib/src/utility/index.d.ts.map +0 -1
  66. package/lib/src/utility/input.d.ts +0 -9
  67. package/lib/src/utility/input.d.ts.map +0 -1
  68. package/lib/src/utility/prosemirror.d.ts.map +0 -1
  69. package/lib/src/utility/toggle.d.ts.map +0 -1
  70. package/src/input-manager/calc-input-pos.ts +0 -19
  71. package/src/input-manager/create-input.ts +0 -39
  72. package/src/input-manager/filter-input.ts +0 -33
  73. package/src/input-manager/index.ts +0 -64
  74. package/src/input-manager/style.ts +0 -66
  75. package/src/utility/input.ts +0 -137
package/lib/index.es.js CHANGED
@@ -14,129 +14,9 @@ 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";
17
+ import { themeManagerCtx, ThemeIcon, commandsCtx, ThemeSize, ThemeBorder, ThemeShadow, ThemeColor, schemaCtx } from "@milkdown/core";
18
+ import { findParentNode, TextSelection, calculateTextPosition, PluginKey, Plugin } from "@milkdown/prose";
19
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
- if (!("key" in e) || e.key !== "Enter") {
28
- target.focus();
29
- return () => false;
30
- }
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).callByName("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).callByName("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
- if (!("key" in e) || e.key !== "Enter") {
60
- target.focus();
61
- return () => false;
62
- }
63
- }
64
- const parent = target.parentNode;
65
- if (!parent)
66
- return () => false;
67
- const inputEl = Array.from(parent.children).find((el) => el.tagName === "INPUT");
68
- if (!(inputEl instanceof HTMLInputElement))
69
- return () => false;
70
- return ctx.get(commandsCtx).callByName("ModifyImage", inputEl.value);
71
- };
72
- const updateLinkView = (view, $) => {
73
- const { marks } = view.state.schema;
74
- const { firstChild, lastElementChild } = $;
75
- if (!(firstChild instanceof HTMLInputElement) || !(lastElementChild instanceof HTMLButtonElement))
76
- return;
77
- const { selection } = view.state;
78
- let node;
79
- const { from, to } = selection;
80
- view.state.doc.nodesBetween(from, from === to ? to + 1 : to, (n) => {
81
- if (marks.link.isInSet(n.marks)) {
82
- node = n;
83
- return false;
84
- }
85
- return;
86
- });
87
- if (!node)
88
- return;
89
- const mark = node.marks.find((m) => m.type === marks.link);
90
- if (!mark)
91
- return;
92
- const value = mark.attrs["href"];
93
- firstChild.value = value;
94
- if (!value) {
95
- lastElementChild.classList.add("disable");
96
- return;
97
- }
98
- if (lastElementChild.classList.contains("disable")) {
99
- lastElementChild.classList.remove("disable");
100
- }
101
- };
102
- const updateInlineMathView = (view, $) => {
103
- const { nodes } = view.state.schema;
104
- const { firstChild, lastElementChild } = $;
105
- if (!(firstChild instanceof HTMLInputElement) || !(lastElementChild instanceof HTMLButtonElement))
106
- return;
107
- const result = findSelectedNodeOfType(view.state.selection, nodes.math_inline);
108
- if (!result)
109
- return;
110
- const { node } = result;
111
- const value = node.attrs["value"];
112
- firstChild.value = value;
113
- if (!value) {
114
- lastElementChild.classList.add("disable");
115
- return;
116
- }
117
- if (lastElementChild.classList.contains("disable")) {
118
- lastElementChild.classList.remove("disable");
119
- }
120
- };
121
- const updateImageView = (view, $) => {
122
- const { nodes } = view.state.schema;
123
- const { firstChild, lastElementChild } = $;
124
- if (!(firstChild instanceof HTMLInputElement) || !(lastElementChild instanceof HTMLButtonElement))
125
- return;
126
- const result = findSelectedNodeOfType(view.state.selection, nodes.image);
127
- if (!result)
128
- return;
129
- const { node } = result;
130
- const value = node.attrs["src"];
131
- firstChild.value = value.length > 50 ? "Url is too long to display." : value;
132
- if (!value) {
133
- lastElementChild.classList.add("disable");
134
- return;
135
- }
136
- if (lastElementChild.classList.contains("disable")) {
137
- lastElementChild.classList.remove("disable");
138
- }
139
- };
140
20
  const hasMark = (editorState, type) => {
141
21
  if (!type) {
142
22
  return false;
@@ -156,59 +36,43 @@ const isTextSelection = (editorState) => {
156
36
  };
157
37
  const isInCodeFence = (editorState) => Boolean(findParentNode((node) => !!node.type.spec.code)(editorState.selection));
158
38
  const isTextAndNotHasMark = (editorState, mark) => !isTextSelection(editorState) || isInCodeFence(editorState) || hasMark(editorState, mark);
159
- const createToggleIcon = (ctx, iconName, key2, mark, disableForMark) => ({
160
- $: ctx.get(themeToolCtx).slots.icon(iconName),
161
- command: () => ctx.get(commandsCtx).callByName(key2),
162
- active: (view) => hasMark(view.state, mark),
163
- disable: (view) => isTextAndNotHasMark(view.state, disableForMark),
164
- enable: (view) => !!mark && !!view.state.schema.marks[mark.name]
165
- });
166
- var ButtonAction;
167
- (function(ButtonAction2) {
168
- ButtonAction2[ButtonAction2["ToggleBold"] = 0] = "ToggleBold";
169
- ButtonAction2[ButtonAction2["ToggleItalic"] = 1] = "ToggleItalic";
170
- ButtonAction2[ButtonAction2["ToggleStrike"] = 2] = "ToggleStrike";
171
- ButtonAction2[ButtonAction2["ToggleCode"] = 3] = "ToggleCode";
172
- ButtonAction2[ButtonAction2["ToggleLink"] = 4] = "ToggleLink";
173
- })(ButtonAction || (ButtonAction = {}));
174
- var InputAction;
175
- (function(InputAction2) {
176
- InputAction2[InputAction2["ModifyLink"] = 0] = "ModifyLink";
177
- InputAction2[InputAction2["ModifyImage"] = 1] = "ModifyImage";
178
- InputAction2[InputAction2["ModifyInlineMath"] = 2] = "ModifyInlineMath";
179
- })(InputAction || (InputAction = {}));
180
- const inputMap = (schema, ctx, inputOptions) => {
181
- const { marks, nodes } = schema;
39
+ const createToggleIcon = (ctx, iconName, key2, mark, disableForMark) => {
40
+ var _a;
182
41
  return {
183
- [0]: __spreadValues({
184
- display: (view) => view.state.selection.empty && view.state.selection instanceof TextSelection && hasMark(view.state, marks["link"]),
185
- command: modifyLink(ctx),
186
- update: updateLinkView
187
- }, inputOptions.link),
188
- [2]: __spreadValues({
189
- display: (view) => Boolean(nodes["math_inline"] && findSelectedNodeOfType(view.state.selection, nodes["math_inline"])),
190
- command: modifyInlineMath(ctx),
191
- update: updateInlineMathView,
192
- bind: true
193
- }, inputOptions.inlineMath),
194
- [1]: __spreadValues({
195
- display: (view) => Boolean(nodes["image"] && findSelectedNodeOfType(view.state.selection, nodes["image"])),
196
- command: modifyImage(ctx),
197
- update: updateImageView
198
- }, 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]
199
47
  };
200
48
  };
201
- const buttonMap = (schema, ctx) => {
202
- const { marks } = schema;
49
+ const Buttonize = ({ icon, onClick, isHidden, isActive }, ctx) => {
50
+ var _a;
203
51
  return {
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)
57
+ };
58
+ };
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({
204
68
  [0]: createToggleIcon(ctx, "bold", "ToggleBold", marks["strong"], marks["code_inline"]),
205
69
  [1]: createToggleIcon(ctx, "italic", "ToggleItalic", marks["em"], marks["code_inline"]),
206
70
  [2]: createToggleIcon(ctx, "strikeThrough", "ToggleStrikeThrough", marks["strike_through"], marks["code_inline"]),
207
71
  [3]: createToggleIcon(ctx, "code", "ToggleInlineCode", marks["code_inline"], marks["link"]),
208
72
  [4]: createToggleIcon(ctx, "link", "ToggleLink", marks["link"], marks["code_inline"])
209
- };
73
+ }, ButtonItems);
210
74
  };
211
- const calcButtonPos = (buttons, view) => {
75
+ const calcButtonPos = (buttons, view, isBottom) => {
212
76
  buttons.classList.remove("hide");
213
77
  calculateTextPosition(view, buttons, (start, end, target, parent) => {
214
78
  const $editor = buttons.parentElement;
@@ -220,25 +84,25 @@ const calcButtonPos = (buttons, view) => {
220
84
  let top = start.top - parent.top - target.height - 14 + $editor.scrollTop;
221
85
  if (left < 0)
222
86
  left = 0;
223
- if (start.top < target.height) {
87
+ if (start.top - parent.top < target.height || isBottom && parent.bottom - start.bottom > target.height) {
224
88
  top = start.bottom - parent.top + 14 + $editor.scrollTop;
225
89
  }
226
90
  return [top, left];
227
91
  });
228
92
  };
229
- const injectStyle$1 = (themeTool, { css }) => {
230
- var _a, _b;
231
- 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");
232
96
  return css`
233
97
  display: inline-flex;
234
98
  cursor: pointer;
235
99
  justify-content: space-evenly;
236
100
  position: absolute;
237
- border-radius: ${size.radius};
101
+ border-radius: ${themeManager.get(ThemeSize, "radius")};
238
102
  z-index: 2;
239
103
 
240
- ${(_a = mixin.border) == null ? void 0 : _a.call(mixin)};
241
- ${(_b = mixin.shadow) == null ? void 0 : _b.call(mixin)};
104
+ ${themeManager.get(ThemeBorder, void 0)}
105
+ ${themeManager.get(ThemeShadow, void 0)}
242
106
 
243
107
  overflow: hidden;
244
108
  background: ${palette("surface")};
@@ -247,8 +111,8 @@ const injectStyle$1 = (themeTool, { css }) => {
247
111
  position: relative;
248
112
  color: ${palette("solid", 0.87)};
249
113
 
250
- width: 3rem;
251
- line-height: 3rem;
114
+ width: 2em;
115
+ line-height: 2em;
252
116
  text-align: center;
253
117
  transition: all 0.4s ease-in-out;
254
118
  &:hover {
@@ -261,8 +125,8 @@ const injectStyle$1 = (themeTool, { css }) => {
261
125
  content: '';
262
126
  position: absolute;
263
127
  top: 0;
264
- right: calc(-0.5 * ${size.lineWidth});
265
- width: ${size.lineWidth};
128
+ right: calc(-0.5 * ${lineWidth});
129
+ width: ${lineWidth};
266
130
  bottom: 0;
267
131
  background: ${palette("line")};
268
132
  }
@@ -273,27 +137,29 @@ const injectStyle$1 = (themeTool, { css }) => {
273
137
  }
274
138
  `;
275
139
  };
276
- const createTooltip = (buttonMap2, utils) => {
140
+ const createTooltip = (buttonMap2, utils, className) => {
277
141
  const div = document.createElement("div");
278
- const style = utils.getStyle(injectStyle$1) || "";
279
- if (style) {
280
- div.classList.add(style);
281
- }
282
- div.classList.add("tooltip");
142
+ utils.themeManager.onFlush(() => {
143
+ const style = utils.getStyle((emotion) => injectStyle(utils.themeManager, emotion)) || "";
144
+ if (style) {
145
+ div.classList.add(style);
146
+ }
147
+ });
148
+ div.classList.add(utils.getClassName({}, className));
283
149
  return {
284
150
  dom: div,
285
151
  render: (editorView) => {
286
152
  var _a;
287
- Object.values(buttonMap2).filter((item) => item.enable(editorView)).forEach(({ $ }) => div.appendChild($));
153
+ Object.values(buttonMap2).filter((item) => item.enable(editorView) && item.$ != null).forEach(({ $ }) => div.appendChild($));
288
154
  (_a = editorView.dom.parentNode) == null ? void 0 : _a.appendChild(div);
289
155
  }
290
156
  };
291
157
  };
292
158
  const noActive = (buttonMap2, view) => {
293
- return Object.values(buttonMap2).filter((item) => item.enable(view)).every(({ $ }) => $.classList.contains("hide"));
159
+ return Object.values(buttonMap2).filter((item) => item.enable(view) && item.$ != null).every(({ $ }) => $.classList.contains("hide"));
294
160
  };
295
161
  const filterButton = (buttonMap2, view) => {
296
- Object.values(buttonMap2).filter((item) => item.enable(view)).forEach((item) => {
162
+ Object.values(buttonMap2).filter((item) => item.enable(view) && item.$ != null).forEach((item) => {
297
163
  var _a;
298
164
  const disable = (_a = item.disable) == null ? void 0 : _a.call(item, view);
299
165
  if (disable) {
@@ -310,8 +176,8 @@ const filterButton = (buttonMap2, view) => {
310
176
  });
311
177
  return noActive(buttonMap2, view);
312
178
  };
313
- const createButtonManager = (buttonMap2, utils) => {
314
- const { dom: buttons, render } = createTooltip(buttonMap2, utils);
179
+ const createButtonManager = (buttonMap2, utils, bottom, containerClassName) => {
180
+ const { dom: buttons, render } = createTooltip(buttonMap2, utils, containerClassName);
315
181
  const onClick = (e) => {
316
182
  const target = Object.values(buttonMap2).find(({ $ }) => e.target instanceof Element && $.contains(e.target));
317
183
  if (!target)
@@ -336,195 +202,16 @@ const createButtonManager = (buttonMap2, utils) => {
336
202
  hide();
337
203
  return;
338
204
  }
339
- calcButtonPos(buttons, editorView);
205
+ calcButtonPos(buttons, editorView, bottom);
340
206
  },
341
207
  render
342
208
  };
343
209
  };
344
- const calcInputPos = (view, input) => {
345
- calculateTextPosition(view, input, (start, end, target, parent) => {
346
- const $editor = input.parentElement;
347
- if (!$editor) {
348
- throw new Error();
349
- }
350
- const selectionWidth = end.left - start.left;
351
- let left = start.left - parent.left - (target.width - selectionWidth) / 2;
352
- const top = start.bottom - parent.top + 14 + $editor.scrollTop;
353
- if (left < 0)
354
- left = 0;
355
- return [top, left];
356
- });
357
- };
358
- const injectStyle = (themeTool, { css }) => {
359
- var _a, _b;
360
- const { palette, mixin, size } = themeTool;
361
- return css`
362
- ${(_a = mixin.border) == null ? void 0 : _a.call(mixin)};
363
- ${(_b = mixin.shadow) == null ? void 0 : _b.call(mixin)};
364
-
365
- display: inline-flex;
366
- justify-content: space-between;
367
- align-items: center;
368
- position: absolute;
369
- background: ${palette("surface")};
370
- border-radius: ${size.radius};
371
- font-size: 1rem;
372
-
373
- height: 3.5rem;
374
- box-sizing: border-box;
375
- width: 25.5rem;
376
- padding: 0 1rem;
377
- gap: 1rem;
378
- z-index: 2;
379
-
380
- input,
381
- button {
382
- all: unset;
383
- }
384
-
385
- input {
386
- flex-grow: 1;
387
- caret-color: ${palette("primary")};
388
- &::placeholder {
389
- color: ${palette("neutral", 0.6)};
390
- }
391
- }
392
-
393
- button {
394
- cursor: pointer;
395
- height: 2.25rem;
396
- color: ${palette("primary")};
397
- font-size: 0.875rem;
398
- padding: 0 0.5rem;
399
- font-weight: 500;
400
- letter-spacing: 1.25px;
401
- &:hover {
402
- background-color: ${palette("secondary", 0.12)};
403
- }
404
- &.disable {
405
- color: ${palette("neutral", 0.38)};
406
- cursor: not-allowed;
407
- &:hover {
408
- background: transparent;
409
- }
410
- }
411
- &.hide {
412
- display: none;
413
- }
414
- }
415
-
416
- &.hide {
417
- display: none;
418
- }
419
- `;
420
- };
421
- const createInput = (utils) => {
422
- const div = document.createElement("div");
423
- const style = utils.getStyle(injectStyle);
424
- if (style) {
425
- div.classList.add(style);
426
- }
427
- div.classList.add("tooltip-input");
428
- const input = document.createElement("input");
429
- div.appendChild(input);
430
- const button = document.createElement("button");
431
- div.appendChild(button);
432
- input.addEventListener("input", (e) => {
433
- const { target } = e;
434
- if (!(target instanceof HTMLInputElement)) {
435
- return;
436
- }
437
- if (!target.value) {
438
- button.classList.add("disable");
439
- return;
440
- }
441
- button.classList.remove("disable");
442
- });
443
- return {
444
- div,
445
- input,
446
- button
447
- };
448
- };
449
- const filterInput = (currentView, inputMap2, div, input, button) => {
450
- const target = Object.values(inputMap2).find((input2) => input2.display(currentView));
451
- if (!target) {
452
- div.classList.add("hide");
453
- return;
454
- }
455
- div.classList.remove("hide");
456
- if (target.bind) {
457
- button.classList.add("hide");
458
- } else {
459
- button.classList.remove("hide");
460
- button.textContent = target.buttonText;
461
- }
462
- input.placeholder = target.placeholder;
463
- target.update(currentView, div);
464
- return target;
465
- };
466
- const createInputManager = (inputMap2, utils) => {
467
- let inputCommand;
468
- let binding = false;
469
- const setCommand = (x) => inputCommand = x;
470
- const { div, button, input } = createInput(utils);
471
- const onClick = (e) => {
472
- if (!inputCommand || button.classList.contains("disable"))
473
- return;
474
- e.stopPropagation();
475
- inputCommand(e);
476
- div.classList.add("hide");
477
- };
478
- const onInput = (e) => {
479
- if (!binding || !inputCommand)
480
- return;
481
- inputCommand(e);
482
- };
483
- const onKeydown = (e) => {
484
- if (!inputCommand)
485
- return;
486
- if ("key" in e && e.key === "Enter") {
487
- inputCommand(e);
488
- div.classList.add("hide");
489
- }
490
- };
491
- input.addEventListener("input", onInput);
492
- input.addEventListener("keydown", onKeydown);
493
- button.addEventListener("mousedown", onClick);
494
- return {
495
- destroy: () => {
496
- input.removeEventListener("input", onInput);
497
- input.removeEventListener("keydown", onKeydown);
498
- div.removeEventListener("mousedown", onClick);
499
- div.remove();
500
- },
501
- hide: () => {
502
- div.classList.add("hide");
503
- setCommand();
504
- },
505
- update: (editorView) => {
506
- const result = filterInput(editorView, inputMap2, div, input, button);
507
- if (!result)
508
- return;
509
- binding = !!result.bind;
510
- setCommand(result.command);
511
- calcInputPos(editorView, div);
512
- },
513
- render: (editorView) => {
514
- const wrapper = editorView.dom.parentNode;
515
- if (!wrapper)
516
- throw new Error();
517
- wrapper.appendChild(div);
518
- }
519
- };
520
- };
521
- const createPlugin = (buttonMap2, inputMap2, utils) => {
522
- const buttonManager = createButtonManager(buttonMap2, utils);
523
- const inputManager = createInputManager(inputMap2, utils);
210
+ const createPlugin = (buttonMap2, utils, bottom, containerClassName) => {
211
+ let buttonManager = createButtonManager(buttonMap2, utils, bottom, containerClassName);
524
212
  let shouldHide = false;
525
213
  const hide = () => {
526
214
  buttonManager.hide();
527
- inputManager.hide();
528
215
  };
529
216
  const update = (view, prevState) => {
530
217
  const { state } = view;
@@ -536,17 +223,19 @@ const createPlugin = (buttonMap2, inputMap2, utils) => {
536
223
  if (isEqualSelection)
537
224
  return;
538
225
  buttonManager.update(view);
539
- inputManager.update(view);
540
226
  };
541
227
  return {
228
+ recreate: (editorView) => {
229
+ buttonManager = createButtonManager(buttonMap2, utils, bottom, containerClassName);
230
+ buttonManager.render(editorView);
231
+ update(editorView);
232
+ },
542
233
  update,
543
234
  destroy: () => {
544
235
  buttonManager.destroy();
545
- inputManager.destroy();
546
236
  },
547
237
  render: (editorView) => {
548
238
  buttonManager.render(editorView);
549
- inputManager.render(editorView);
550
239
  update(editorView);
551
240
  },
552
241
  setHide: (isTyping) => {
@@ -559,21 +248,9 @@ const tooltipPlugin = createPlugin$1((utils, options) => {
559
248
  return {
560
249
  id: "tooltip",
561
250
  prosePlugins: (_, ctx) => {
562
- var _a, _b, _c;
251
+ var _a;
563
252
  const schema = ctx.get(schemaCtx);
564
- const manager = createPlugin(buttonMap(schema, ctx), inputMap(schema, ctx, {
565
- link: __spreadValues({
566
- placeholder: "Input Web Link",
567
- buttonText: "APPLY"
568
- }, (_a = options == null ? void 0 : options.link) != null ? _a : {}),
569
- image: __spreadValues({
570
- placeholder: "Input Image Link",
571
- buttonText: "APPLY"
572
- }, (_b = options == null ? void 0 : options.image) != null ? _b : {}),
573
- inlineMath: __spreadValues({
574
- placeholder: "Input Math"
575
- }, (_c = options == null ? void 0 : options.inlineMath) != null ? _c : {})
576
- }), utils);
253
+ const manager = createPlugin(buttonMap(schema, ctx, options == null ? void 0 : options.items), utils, (_a = options == null ? void 0 : options.bottom) != null ? _a : false, "tooltip");
577
254
  const plugin = new Plugin({
578
255
  key,
579
256
  props: {
@@ -594,7 +271,7 @@ const tooltipPlugin = createPlugin$1((utils, options) => {
594
271
  }
595
272
  },
596
273
  view: (editorView) => {
597
- manager.render(editorView);
274
+ manager.recreate(editorView);
598
275
  return {
599
276
  update: manager.update,
600
277
  destroy: manager.destroy