@milkdown/plugin-tooltip 5.5.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.
- package/README.md +3 -13
- package/lib/{src/button-manager → button-manager}/calc-button-pos.d.ts +1 -1
- package/lib/button-manager/calc-button-pos.d.ts.map +1 -0
- package/lib/{src/button-manager → button-manager}/create-tooltip.d.ts +0 -0
- package/lib/button-manager/create-tooltip.d.ts.map +1 -0
- package/lib/{src/button-manager → button-manager}/filter-button.d.ts +0 -0
- package/lib/button-manager/filter-button.d.ts.map +1 -0
- package/lib/{src/button-manager → button-manager}/index.d.ts +1 -1
- package/lib/button-manager/index.d.ts.map +1 -0
- package/lib/{src/button-manager → button-manager}/no-active.d.ts +0 -0
- package/lib/button-manager/no-active.d.ts.map +1 -0
- package/lib/button-manager/style.d.ts +3 -0
- package/lib/button-manager/style.d.ts.map +1 -0
- package/lib/index.d.ts +21 -1
- package/lib/index.d.ts.map +1 -0
- package/lib/index.es.js +33 -393
- package/lib/index.es.js.map +1 -1
- package/lib/{src/item.d.ts → item.d.ts} +2 -19
- package/lib/item.d.ts.map +1 -0
- package/lib/{src/selection-marks-tooltip.d.ts → selection-marks-tooltip.d.ts} +2 -2
- package/lib/selection-marks-tooltip.d.ts.map +1 -0
- package/lib/{src/utility → utility}/element.d.ts +0 -0
- package/lib/utility/element.d.ts.map +1 -0
- package/lib/{src/utility → utility}/index.d.ts +0 -1
- package/lib/utility/index.d.ts.map +1 -0
- package/lib/{src/utility → utility}/prosemirror.d.ts +0 -0
- package/lib/utility/prosemirror.d.ts.map +1 -0
- package/lib/{src/utility → utility}/toggle.d.ts +0 -0
- package/lib/utility/toggle.d.ts.map +1 -0
- package/package.json +34 -10
- package/src/button-manager/calc-button-pos.ts +2 -3
- package/src/button-manager/create-tooltip.ts +6 -4
- package/src/button-manager/index.ts +2 -2
- package/src/button-manager/style.ts +11 -10
- package/src/index.ts +3 -22
- package/src/item.ts +4 -63
- package/src/selection-marks-tooltip.ts +3 -9
- package/src/utility/index.ts +0 -1
- package/src/utility/toggle.ts +2 -2
- package/lib/src/button-manager/calc-button-pos.d.ts.map +0 -1
- package/lib/src/button-manager/create-tooltip.d.ts.map +0 -1
- package/lib/src/button-manager/filter-button.d.ts.map +0 -1
- package/lib/src/button-manager/index.d.ts.map +0 -1
- package/lib/src/button-manager/no-active.d.ts.map +0 -1
- package/lib/src/button-manager/style.d.ts +0 -3
- package/lib/src/button-manager/style.d.ts.map +0 -1
- package/lib/src/index.d.ts +0 -21
- package/lib/src/index.d.ts.map +0 -1
- package/lib/src/input-manager/calc-input-pos.d.ts +0 -3
- package/lib/src/input-manager/calc-input-pos.d.ts.map +0 -1
- package/lib/src/input-manager/create-input.d.ts +0 -7
- package/lib/src/input-manager/create-input.d.ts.map +0 -1
- package/lib/src/input-manager/filter-input.d.ts +0 -19
- package/lib/src/input-manager/filter-input.d.ts.map +0 -1
- package/lib/src/input-manager/index.d.ts +0 -10
- package/lib/src/input-manager/index.d.ts.map +0 -1
- package/lib/src/input-manager/style.d.ts +0 -3
- package/lib/src/input-manager/style.d.ts.map +0 -1
- package/lib/src/item.d.ts.map +0 -1
- package/lib/src/selection-marks-tooltip.d.ts.map +0 -1
- package/lib/src/utility/element.d.ts.map +0 -1
- package/lib/src/utility/index.d.ts.map +0 -1
- package/lib/src/utility/input.d.ts +0 -9
- package/lib/src/utility/input.d.ts.map +0 -1
- package/lib/src/utility/prosemirror.d.ts.map +0 -1
- package/lib/src/utility/toggle.d.ts.map +0 -1
- package/src/input-manager/calc-input-pos.ts +0 -19
- package/src/input-manager/create-input.ts +0 -39
- package/src/input-manager/filter-input.ts +0 -33
- package/src/input-manager/index.ts +0 -64
- package/src/input-manager/style.ts +0 -66
- package/src/utility/input.ts +0 -137
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
|
-
#
|
|
18
|
+
# Position
|
|
19
19
|
|
|
20
|
-
Modify the
|
|
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
|
-
|
|
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"}
|
|
File without changes
|
|
@@ -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"}
|
|
File without changes
|
|
@@ -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"}
|
|
File without changes
|
|
@@ -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 @@
|
|
|
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
|
-
|
|
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,142 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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
|
-
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
4
|
const hasMark = (editorState, type) => {
|
|
141
5
|
if (!type) {
|
|
142
6
|
return false;
|
|
@@ -156,46 +20,14 @@ const isTextSelection = (editorState) => {
|
|
|
156
20
|
};
|
|
157
21
|
const isInCodeFence = (editorState) => Boolean(findParentNode((node) => !!node.type.spec.code)(editorState.selection));
|
|
158
22
|
const isTextAndNotHasMark = (editorState, mark) => !isTextSelection(editorState) || isInCodeFence(editorState) || hasMark(editorState, mark);
|
|
159
|
-
const createToggleIcon = (ctx, iconName, key2, mark, disableForMark) =>
|
|
160
|
-
|
|
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;
|
|
23
|
+
const createToggleIcon = (ctx, iconName, key2, mark, disableForMark) => {
|
|
24
|
+
var _a;
|
|
182
25
|
return {
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
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)
|
|
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]
|
|
199
31
|
};
|
|
200
32
|
};
|
|
201
33
|
const buttonMap = (schema, ctx) => {
|
|
@@ -208,7 +40,7 @@ const buttonMap = (schema, ctx) => {
|
|
|
208
40
|
[4]: createToggleIcon(ctx, "link", "ToggleLink", marks["link"], marks["code_inline"])
|
|
209
41
|
};
|
|
210
42
|
};
|
|
211
|
-
const calcButtonPos = (buttons, view) => {
|
|
43
|
+
const calcButtonPos = (buttons, view, isBottom) => {
|
|
212
44
|
buttons.classList.remove("hide");
|
|
213
45
|
calculateTextPosition(view, buttons, (start, end, target, parent) => {
|
|
214
46
|
const $editor = buttons.parentElement;
|
|
@@ -220,25 +52,25 @@ const calcButtonPos = (buttons, view) => {
|
|
|
220
52
|
let top = start.top - parent.top - target.height - 14 + $editor.scrollTop;
|
|
221
53
|
if (left < 0)
|
|
222
54
|
left = 0;
|
|
223
|
-
if (start.top < target.height) {
|
|
55
|
+
if (start.top - parent.top < target.height || isBottom && parent.bottom - start.bottom > target.height) {
|
|
224
56
|
top = start.bottom - parent.top + 14 + $editor.scrollTop;
|
|
225
57
|
}
|
|
226
58
|
return [top, left];
|
|
227
59
|
});
|
|
228
60
|
};
|
|
229
|
-
const injectStyle
|
|
230
|
-
|
|
231
|
-
const
|
|
61
|
+
const injectStyle = (themeManager, { css }) => {
|
|
62
|
+
const palette = (color, opacity = 1) => themeManager.get(ThemeColor, [color, opacity]);
|
|
63
|
+
const lineWidth = themeManager.get(ThemeSize, "lineWidth");
|
|
232
64
|
return css`
|
|
233
65
|
display: inline-flex;
|
|
234
66
|
cursor: pointer;
|
|
235
67
|
justify-content: space-evenly;
|
|
236
68
|
position: absolute;
|
|
237
|
-
border-radius: ${
|
|
69
|
+
border-radius: ${themeManager.get(ThemeSize, "radius")};
|
|
238
70
|
z-index: 2;
|
|
239
71
|
|
|
240
|
-
${(
|
|
241
|
-
${(
|
|
72
|
+
${themeManager.get(ThemeBorder, void 0)}
|
|
73
|
+
${themeManager.get(ThemeShadow, void 0)}
|
|
242
74
|
|
|
243
75
|
overflow: hidden;
|
|
244
76
|
background: ${palette("surface")};
|
|
@@ -247,8 +79,8 @@ const injectStyle$1 = (themeTool, { css }) => {
|
|
|
247
79
|
position: relative;
|
|
248
80
|
color: ${palette("solid", 0.87)};
|
|
249
81
|
|
|
250
|
-
width:
|
|
251
|
-
line-height:
|
|
82
|
+
width: 2em;
|
|
83
|
+
line-height: 2em;
|
|
252
84
|
text-align: center;
|
|
253
85
|
transition: all 0.4s ease-in-out;
|
|
254
86
|
&:hover {
|
|
@@ -261,8 +93,8 @@ const injectStyle$1 = (themeTool, { css }) => {
|
|
|
261
93
|
content: '';
|
|
262
94
|
position: absolute;
|
|
263
95
|
top: 0;
|
|
264
|
-
right: calc(-0.5 * ${
|
|
265
|
-
width: ${
|
|
96
|
+
right: calc(-0.5 * ${lineWidth});
|
|
97
|
+
width: ${lineWidth};
|
|
266
98
|
bottom: 0;
|
|
267
99
|
background: ${palette("line")};
|
|
268
100
|
}
|
|
@@ -275,10 +107,12 @@ const injectStyle$1 = (themeTool, { css }) => {
|
|
|
275
107
|
};
|
|
276
108
|
const createTooltip = (buttonMap2, utils) => {
|
|
277
109
|
const div = document.createElement("div");
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
110
|
+
utils.themeManager.onFlush(() => {
|
|
111
|
+
const style = utils.getStyle(injectStyle) || "";
|
|
112
|
+
if (style) {
|
|
113
|
+
div.classList.add(style);
|
|
114
|
+
}
|
|
115
|
+
});
|
|
282
116
|
div.classList.add("tooltip");
|
|
283
117
|
return {
|
|
284
118
|
dom: div,
|
|
@@ -310,7 +144,7 @@ const filterButton = (buttonMap2, view) => {
|
|
|
310
144
|
});
|
|
311
145
|
return noActive(buttonMap2, view);
|
|
312
146
|
};
|
|
313
|
-
const createButtonManager = (buttonMap2, utils) => {
|
|
147
|
+
const createButtonManager = (buttonMap2, utils, bottom) => {
|
|
314
148
|
const { dom: buttons, render } = createTooltip(buttonMap2, utils);
|
|
315
149
|
const onClick = (e) => {
|
|
316
150
|
const target = Object.values(buttonMap2).find(({ $ }) => e.target instanceof Element && $.contains(e.target));
|
|
@@ -336,195 +170,16 @@ const createButtonManager = (buttonMap2, utils) => {
|
|
|
336
170
|
hide();
|
|
337
171
|
return;
|
|
338
172
|
}
|
|
339
|
-
calcButtonPos(buttons, editorView);
|
|
173
|
+
calcButtonPos(buttons, editorView, bottom);
|
|
340
174
|
},
|
|
341
175
|
render
|
|
342
176
|
};
|
|
343
177
|
};
|
|
344
|
-
const
|
|
345
|
-
|
|
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);
|
|
178
|
+
const createPlugin = (buttonMap2, utils, bottom) => {
|
|
179
|
+
const buttonManager = createButtonManager(buttonMap2, utils, bottom);
|
|
524
180
|
let shouldHide = false;
|
|
525
181
|
const hide = () => {
|
|
526
182
|
buttonManager.hide();
|
|
527
|
-
inputManager.hide();
|
|
528
183
|
};
|
|
529
184
|
const update = (view, prevState) => {
|
|
530
185
|
const { state } = view;
|
|
@@ -536,17 +191,14 @@ const createPlugin = (buttonMap2, inputMap2, utils) => {
|
|
|
536
191
|
if (isEqualSelection)
|
|
537
192
|
return;
|
|
538
193
|
buttonManager.update(view);
|
|
539
|
-
inputManager.update(view);
|
|
540
194
|
};
|
|
541
195
|
return {
|
|
542
196
|
update,
|
|
543
197
|
destroy: () => {
|
|
544
198
|
buttonManager.destroy();
|
|
545
|
-
inputManager.destroy();
|
|
546
199
|
},
|
|
547
200
|
render: (editorView) => {
|
|
548
201
|
buttonManager.render(editorView);
|
|
549
|
-
inputManager.render(editorView);
|
|
550
202
|
update(editorView);
|
|
551
203
|
},
|
|
552
204
|
setHide: (isTyping) => {
|
|
@@ -559,21 +211,9 @@ const tooltipPlugin = createPlugin$1((utils, options) => {
|
|
|
559
211
|
return {
|
|
560
212
|
id: "tooltip",
|
|
561
213
|
prosePlugins: (_, ctx) => {
|
|
562
|
-
var _a
|
|
214
|
+
var _a;
|
|
563
215
|
const schema = ctx.get(schemaCtx);
|
|
564
|
-
const manager = createPlugin(buttonMap(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);
|
|
216
|
+
const manager = createPlugin(buttonMap(schema, ctx), utils, (_a = options == null ? void 0 : options.bottom) != null ? _a : false);
|
|
577
217
|
const plugin = new Plugin({
|
|
578
218
|
key,
|
|
579
219
|
props: {
|