@docs.plus/extension-hyperlink 1.5.2 → 2.1.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/CHANGELOG.md +572 -0
- package/LICENSE +21 -0
- package/README.md +135 -385
- package/dist/index.cjs +22 -712
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +392 -0
- package/dist/index.d.ts +392 -9
- package/dist/index.js +22 -707
- package/dist/index.js.map +1 -1
- package/dist/styles.css +362 -0
- package/package.json +85 -33
- package/dist/helpers/autoHyperlink.d.ts +0 -8
- package/dist/helpers/clickHandler.d.ts +0 -11
- package/dist/helpers/editHyperlink.d.ts +0 -9
- package/dist/helpers/pasteHandler.d.ts +0 -9
- package/dist/helpers/tippyHelper.d.ts +0 -29
- package/dist/hyperlink.d.ts +0 -77
- package/dist/index.umd.js +0 -713
- package/dist/index.umd.js.map +0 -1
- package/dist/modals/editeHyperlink.d.ts +0 -11
- package/dist/modals/icons.d.ts +0 -9
- package/dist/modals/previewHyperlink.d.ts +0 -11
- package/dist/modals/setHyperlink.d.ts +0 -14
- package/src/helpers/autoHyperlink.ts +0 -167
- package/src/helpers/clickHandler.ts +0 -80
- package/src/helpers/editHyperlink.ts +0 -59
- package/src/helpers/pasteHandler.ts +0 -46
- package/src/helpers/tippyHelper.ts +0 -136
- package/src/hyperlink.ts +0 -277
- package/src/index.ts +0 -17
- package/src/modals/editeHyperlink.ts +0 -99
- package/src/modals/icons.ts +0 -46
- package/src/modals/previewHyperlink.ts +0 -85
- package/src/modals/setHyperlink.ts +0 -97
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import { Editor } from "@tiptap/core";
|
|
2
|
-
import Tooltip, { TippyInitOptions } from "../helpers/tippyHelper";
|
|
3
|
-
import { find } from "linkifyjs";
|
|
4
|
-
|
|
5
|
-
export type TSetHyperlinkModalOptions = {
|
|
6
|
-
editor: Editor;
|
|
7
|
-
validate?: (url: string) => boolean;
|
|
8
|
-
extentionName: string;
|
|
9
|
-
attributes?: { href: string; target?: string | null };
|
|
10
|
-
Tooltip: new (options: TippyInitOptions) => Tooltip;
|
|
11
|
-
roundArrow: string;
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
let tooltip: Tooltip | undefined = undefined;
|
|
15
|
-
|
|
16
|
-
export function setHyperlinkModal(options: TSetHyperlinkModalOptions): void {
|
|
17
|
-
// Create the tooltip instance
|
|
18
|
-
if (!tooltip) tooltip = new options.Tooltip(options);
|
|
19
|
-
|
|
20
|
-
// Initialize the tooltip
|
|
21
|
-
let { tippyModal } = tooltip.init();
|
|
22
|
-
|
|
23
|
-
const hyperlinkModal = document.createElement("div");
|
|
24
|
-
const buttonsWrapper = document.createElement("div");
|
|
25
|
-
const inputsWrapper = document.createElement("div");
|
|
26
|
-
|
|
27
|
-
hyperlinkModal.classList.add("hyperlink-set-modal");
|
|
28
|
-
|
|
29
|
-
buttonsWrapper.classList.add("hyperlink-set-modal__buttons-wrapper");
|
|
30
|
-
inputsWrapper.classList.add("hyperlink-set-modal__inputs-wrapper");
|
|
31
|
-
|
|
32
|
-
// create a form that contain url input and a button for submit
|
|
33
|
-
const form = document.createElement("form");
|
|
34
|
-
const input = document.createElement("input");
|
|
35
|
-
const button = document.createElement("button");
|
|
36
|
-
|
|
37
|
-
input.setAttribute("type", "text");
|
|
38
|
-
input.setAttribute("placeholder", "https://example.com");
|
|
39
|
-
button.setAttribute("type", "submit");
|
|
40
|
-
button.innerText = "Submit";
|
|
41
|
-
|
|
42
|
-
inputsWrapper.append(input);
|
|
43
|
-
buttonsWrapper.append(button);
|
|
44
|
-
form.append(inputsWrapper, buttonsWrapper);
|
|
45
|
-
|
|
46
|
-
hyperlinkModal.append(form);
|
|
47
|
-
|
|
48
|
-
tippyModal.innerHTML = "";
|
|
49
|
-
tippyModal.append(hyperlinkModal);
|
|
50
|
-
tooltip.update(options.editor.view, {
|
|
51
|
-
arrow: options.roundArrow,
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
// make sure
|
|
55
|
-
setTimeout(() => {
|
|
56
|
-
input.focus();
|
|
57
|
-
input.style.outlineColor = " #dadce0";
|
|
58
|
-
}, 100);
|
|
59
|
-
|
|
60
|
-
input.addEventListener("keydown", () => {
|
|
61
|
-
input.style.outlineColor = " #dadce0";
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
// event listenr for submit button
|
|
65
|
-
form.addEventListener("submit", (event) => {
|
|
66
|
-
event.preventDefault();
|
|
67
|
-
const url = input.value;
|
|
68
|
-
|
|
69
|
-
if (!url) {
|
|
70
|
-
input.style.outlineColor = "red";
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
const sanitizeURL = find(url)
|
|
75
|
-
.filter((link) => link.isLink)
|
|
76
|
-
.filter((link) => {
|
|
77
|
-
if (options.validate) {
|
|
78
|
-
return options.validate(link.value);
|
|
79
|
-
}
|
|
80
|
-
return true;
|
|
81
|
-
})
|
|
82
|
-
.at(0);
|
|
83
|
-
|
|
84
|
-
if (!sanitizeURL?.href) {
|
|
85
|
-
input.style.outlineColor = "red";
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
tooltip?.hide();
|
|
90
|
-
|
|
91
|
-
return options.editor
|
|
92
|
-
.chain()
|
|
93
|
-
.setMark(options.extentionName, { href: sanitizeURL.href })
|
|
94
|
-
.setMeta("preventautohyperlink", true)
|
|
95
|
-
.run();
|
|
96
|
-
});
|
|
97
|
-
}
|