@docs.plus/extension-hyperlink 1.1.0 → 1.2.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.
- package/dist/helpers/tippyHelper.d.ts +24 -14
- package/dist/index.cjs +102 -108
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +102 -108
- package/dist/index.js.map +1 -1
- package/dist/index.umd.js +103 -109
- package/dist/index.umd.js.map +1 -1
- package/package.json +1 -1
- package/src/helpers/clickHandler.ts +15 -7
- package/src/helpers/tippyHelper.ts +110 -100
- package/src/index.ts +2 -1
|
@@ -3,124 +3,134 @@ import { Editor } from "@tiptap/core";
|
|
|
3
3
|
import { EditorView } from "@tiptap/pm/view";
|
|
4
4
|
import { getAttributes, posToDOMRect } from "@tiptap/core";
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
let preventHide: boolean = false;
|
|
8
|
-
let tippyWrapper: HTMLDivElement;
|
|
9
|
-
let editor: Editor;
|
|
10
|
-
let view: EditorView;
|
|
11
|
-
|
|
12
|
-
type TippyInitOptions = {
|
|
6
|
+
interface TippyInitOptions {
|
|
13
7
|
editor: Editor;
|
|
14
8
|
validate?: (url: string) => boolean;
|
|
15
9
|
view: EditorView;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
class Tooltip {
|
|
13
|
+
private tippyInstance?: Instance;
|
|
14
|
+
private preventHide: boolean = false;
|
|
15
|
+
private tippyWrapper: HTMLDivElement;
|
|
16
|
+
private editor: Editor;
|
|
17
|
+
private view: EditorView;
|
|
18
|
+
|
|
19
|
+
constructor(options: TippyInitOptions) {
|
|
20
|
+
this.editor = options.editor;
|
|
21
|
+
this.view = options.view;
|
|
22
|
+
this.tippyWrapper = document.createElement("div");
|
|
23
|
+
this.tippyWrapper.addEventListener("mousedown", this.mousedownHandler, {
|
|
24
24
|
capture: true,
|
|
25
25
|
});
|
|
26
|
-
view.dom.addEventListener("dragstart", dragstartHandler);
|
|
27
|
-
editor.on("
|
|
28
|
-
editor.on("blur", blurHandler);
|
|
26
|
+
this.view.dom.addEventListener("dragstart", this.dragstartHandler);
|
|
27
|
+
this.editor.on("blur", this.blurHandler);
|
|
29
28
|
}
|
|
30
29
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
export const show = () => {
|
|
35
|
-
tippyInstance?.show();
|
|
36
|
-
return true;
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
export const hide = () => {
|
|
40
|
-
setTimeout(() => tippyInstance?.hide());
|
|
41
|
-
return false;
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
export const mousedownHandler = () => {
|
|
45
|
-
preventHide = true;
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
export const dragstartHandler = () => {
|
|
49
|
-
hide();
|
|
50
|
-
};
|
|
30
|
+
init() {
|
|
31
|
+
this.tippyWrapper.innerHTML = "";
|
|
51
32
|
|
|
52
|
-
|
|
53
|
-
setTimeout(() => update(editor.view));
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
const blurHandler = ({ event }: { event: FocusEvent }) => {
|
|
57
|
-
if (preventHide) {
|
|
58
|
-
preventHide = false;
|
|
59
|
-
return;
|
|
33
|
+
return { tippyModal: this.tippyWrapper, tippyInstance: this.tippyInstance };
|
|
60
34
|
}
|
|
61
|
-
|
|
62
|
-
|
|
35
|
+
|
|
36
|
+
show() {
|
|
37
|
+
this.tippyInstance?.show();
|
|
38
|
+
return true;
|
|
63
39
|
}
|
|
64
|
-
hide();
|
|
65
|
-
};
|
|
66
40
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
41
|
+
hide() {
|
|
42
|
+
setTimeout(() => this.tippyInstance?.hide());
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
70
45
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
46
|
+
private mousedownHandler = () => {
|
|
47
|
+
this.preventHide = true;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
private dragstartHandler = () => {
|
|
51
|
+
this.hide();
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
private blurHandler = ({ event }: { event: FocusEvent }) => {
|
|
55
|
+
if (this.preventHide) {
|
|
56
|
+
this.preventHide = false;
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
if (
|
|
60
|
+
event?.relatedTarget &&
|
|
61
|
+
this.tippyWrapper.parentNode?.contains(event.relatedTarget as Node)
|
|
62
|
+
) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
this.hide();
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
private tippyBlurHandler = (event: FocusEvent) => {
|
|
69
|
+
this.blurHandler({ event });
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
private createTooltip() {
|
|
73
|
+
if (!this.editor || !this.editor.options) return;
|
|
74
|
+
const { element: editorElement } = this.editor.options;
|
|
75
|
+
const editorIsAttached = !!editorElement.parentElement;
|
|
76
|
+
|
|
77
|
+
if (this.tippyInstance || !editorIsAttached) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
this.tippyInstance = tippy(editorElement, {
|
|
82
|
+
duration: 0,
|
|
83
|
+
getReferenceClientRect: null,
|
|
84
|
+
content: this.tippyWrapper,
|
|
85
|
+
interactive: true,
|
|
86
|
+
trigger: "manual",
|
|
87
|
+
placement: "bottom",
|
|
88
|
+
hideOnClick: "toggle",
|
|
89
|
+
onClickOutside: (instance, event) => {
|
|
90
|
+
this.hide();
|
|
91
|
+
},
|
|
92
|
+
onAfterUpdate: (instance, partialProps) => {
|
|
93
|
+
this.show();
|
|
94
|
+
},
|
|
95
|
+
});
|
|
75
96
|
|
|
76
|
-
|
|
77
|
-
|
|
97
|
+
if (this.tippyInstance.popper.firstChild) {
|
|
98
|
+
(this.tippyInstance.popper.firstChild as HTMLElement).addEventListener(
|
|
99
|
+
"blur",
|
|
100
|
+
this.tippyBlurHandler
|
|
101
|
+
);
|
|
102
|
+
}
|
|
78
103
|
}
|
|
79
104
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
getReferenceClientRect: null,
|
|
83
|
-
content: tippyWrapper,
|
|
84
|
-
interactive: true,
|
|
85
|
-
trigger: "manual",
|
|
86
|
-
placement: "bottom",
|
|
87
|
-
hideOnClick: "toggle",
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
if (tippyInstance.popper.firstChild) {
|
|
91
|
-
(tippyInstance.popper.firstChild as HTMLElement).addEventListener("blur", tippyBlurHandler);
|
|
92
|
-
}
|
|
93
|
-
};
|
|
105
|
+
update(view: EditorView, option: any = {}) {
|
|
106
|
+
this.createTooltip();
|
|
94
107
|
|
|
95
|
-
|
|
96
|
-
createTooltip();
|
|
108
|
+
option.arrow = option?.arrow ?? false;
|
|
97
109
|
|
|
98
|
-
|
|
99
|
-
|
|
110
|
+
if (this.tippyInstance) {
|
|
111
|
+
this.tippyInstance.setProps({
|
|
112
|
+
...option,
|
|
113
|
+
getReferenceClientRect: () => {
|
|
114
|
+
const pos = view.state.selection.from;
|
|
115
|
+
return posToDOMRect(view, pos, pos);
|
|
116
|
+
},
|
|
117
|
+
});
|
|
118
|
+
}
|
|
100
119
|
|
|
101
|
-
|
|
102
|
-
tippyInstance.setProps({
|
|
103
|
-
...option,
|
|
104
|
-
getReferenceClientRect: () => {
|
|
105
|
-
const pos = view.state.selection.from;
|
|
106
|
-
return posToDOMRect(view, pos, pos);
|
|
107
|
-
},
|
|
108
|
-
});
|
|
109
|
-
show();
|
|
120
|
+
return {};
|
|
110
121
|
}
|
|
111
122
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
}
|
|
122
|
-
view.dom.removeEventListener("dragstart", dragstartHandler);
|
|
123
|
-
editor.off("focus", focusHandler);
|
|
124
|
-
editor.off("blur", blurHandler);
|
|
123
|
+
destroyTooltip() {
|
|
124
|
+
if (this.tippyInstance) {
|
|
125
|
+
this.tippyInstance.destroy();
|
|
126
|
+
this.tippyInstance = undefined;
|
|
127
|
+
this.tippyWrapper.removeEventListener("mousedown", this.mousedownHandler, {
|
|
128
|
+
capture: true,
|
|
129
|
+
});
|
|
130
|
+
this.view.dom.removeEventListener("dragstart", this.dragstartHandler);
|
|
131
|
+
this.editor.off("blur", this.blurHandler);
|
|
132
|
+
}
|
|
125
133
|
}
|
|
126
|
-
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export default Tooltip;
|