@docs.plus/extension-hyperlink 1.3.12 → 1.5.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 +81 -55
- package/dist/helpers/clickHandler.d.ts +1 -3
- package/dist/helpers/tippyHelper.d.ts +1 -2
- package/dist/hyperlink.d.ts +6 -4
- package/dist/index.cjs +42 -41
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +5 -5
- package/dist/index.js +41 -40
- package/dist/index.js.map +1 -1
- package/dist/index.umd.js +42 -41
- package/dist/index.umd.js.map +1 -1
- package/dist/{dialogBoxs → modals}/editeHyperlink.d.ts +2 -4
- package/dist/{dialogBoxs → modals}/previewHyperlink.d.ts +2 -5
- package/dist/modals/setHyperlink.d.ts +14 -0
- package/package.json +1 -1
- package/src/helpers/clickHandler.ts +8 -9
- package/src/helpers/tippyHelper.ts +3 -4
- package/src/hyperlink.ts +14 -9
- package/src/index.ts +5 -5
- package/src/{dialogBoxs → modals}/editeHyperlink.ts +8 -10
- package/src/{dialogBoxs → modals}/previewHyperlink.ts +12 -16
- package/src/{dialogBoxs → modals}/setHyperlink.ts +14 -13
- package/dist/dialogBoxs/setHyperlink.d.ts +0 -9
- /package/dist/{dialogBoxs → modals}/icons.d.ts +0 -0
- /package/src/{dialogBoxs → modals}/icons.ts +0 -0
package/README.md
CHANGED
|
@@ -5,12 +5,10 @@
|
|
|
5
5
|
[](https://www.npmjs.com/package/@docs.plus/extension-hyperlink)
|
|
6
6
|
|
|
7
7
|
|
|
8
|
-
The Link extension adds support for `<a>` tags to the editor. The extension is headless
|
|
8
|
+
The Link extension adds support for `<a>` tags to the editor. The extension is headless, there is no actual <u>**UI**</u> to add, <u>modify</u> or <u>delete</u> links. The usage example below uses the native JavaScript prompt to show you how that could work.
|
|
9
9
|
|
|
10
10
|
In a real world application, you would probably add a more sophisticated user interface.
|
|
11
11
|
|
|
12
|
-
> Pasted URLs will be transformed to links automatically.
|
|
13
|
-
|
|
14
12
|
## Installation
|
|
15
13
|
|
|
16
14
|
````sh
|
|
@@ -92,29 +90,25 @@ Hyperlink.configure({
|
|
|
92
90
|
})
|
|
93
91
|
````
|
|
94
92
|
|
|
95
|
-
###
|
|
93
|
+
### Modals
|
|
96
94
|
|
|
97
|
-
The
|
|
95
|
+
The Modals configuration option lets you incorporate an interactive user interface similar to Google Docs for **setting** and **previewing** hyperlinks. This provides users with a more intuitive and interactive experience;
|
|
98
96
|
- [Dive into the code](https://github.com/HMarzban/extension-hyperlink/blob/4f37ffa18237f10d76c316844b1c2ab20b751fe9/packages/nextjs/src/components/Tiptap.tsx#L21-L28)
|
|
99
97
|
- [Demo](https://github.com/HMarzban/extension-hyperlink#test-drive-with-our-demo-)
|
|
100
98
|
|
|
101
99
|
<details>
|
|
102
|
-
<summary>The `
|
|
100
|
+
<summary>The `previewHyperlinkModal` function</summary>
|
|
103
101
|
|
|
104
102
|
```ts
|
|
105
|
-
|
|
106
|
-
editor: Editor;
|
|
107
|
-
validate?: (url: string) => boolean;
|
|
108
|
-
view: EditorView;
|
|
109
|
-
link: HTMLAnchorElement;
|
|
110
|
-
node?: any;
|
|
111
|
-
nodePos: number;
|
|
112
|
-
tippy: Tooltip;
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
const previewHyperlink(options: HyperlinkDialogBoxOptions): HTMLElement {
|
|
103
|
+
function previewHyperlinkModal(options) {
|
|
116
104
|
const href = options.link.href;
|
|
117
|
-
|
|
105
|
+
|
|
106
|
+
const hyperlinkModal = document.createElement("div");
|
|
107
|
+
const removeButton = document.createElement("button");
|
|
108
|
+
const copyButton = document.createElement("button");
|
|
109
|
+
|
|
110
|
+
const newBubble = document.createElement("div");
|
|
111
|
+
newBubble.classList.add("hyperlink-preview-modal__metadata");
|
|
118
112
|
|
|
119
113
|
const hrefTitle = document.createElement("a");
|
|
120
114
|
hrefTitle.setAttribute("target", "_blank");
|
|
@@ -122,43 +116,60 @@ const previewHyperlink(options: HyperlinkDialogBoxOptions): HTMLElement {
|
|
|
122
116
|
hrefTitle.setAttribute("href", href);
|
|
123
117
|
hrefTitle.innerText = href;
|
|
124
118
|
|
|
125
|
-
|
|
119
|
+
newBubble.append(hrefTitle);
|
|
120
|
+
|
|
121
|
+
hyperlinkModal.classList.add("hyperlink-preview-modal");
|
|
122
|
+
|
|
123
|
+
removeButton.classList.add("hyperlink-preview-modal__remove-button");
|
|
124
|
+
removeButton.innerHTML = "remove";
|
|
125
|
+
|
|
126
|
+
copyButton.classList.add("hyperlink-preview-modal__copy-button");
|
|
127
|
+
copyButton.innerHTML = "copy";
|
|
128
|
+
|
|
129
|
+
removeButton.addEventListener("click", () => {
|
|
130
|
+
options.tippy.hide();
|
|
131
|
+
return options.editor.chain().focus().unsetHyperlink().run();
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
copyButton.addEventListener("click", () => {
|
|
135
|
+
options.tippy.hide();
|
|
136
|
+
navigator.clipboard.writeText(href);
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
hyperlinkModal.append(newBubble, copyButton, removeButton);
|
|
126
140
|
|
|
127
|
-
return
|
|
141
|
+
return hyperlinkModal;
|
|
128
142
|
}
|
|
143
|
+
|
|
129
144
|
```
|
|
130
145
|
|
|
131
146
|
</details>
|
|
132
147
|
|
|
133
148
|
<details>
|
|
134
|
-
<summary>The `
|
|
149
|
+
<summary>The `setHyperlinkModal` function</summary>
|
|
135
150
|
|
|
136
151
|
```ts
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
extentionName: string;
|
|
141
|
-
attributes: Record<string, any>;
|
|
142
|
-
};
|
|
143
|
-
|
|
144
|
-
let tooltip: Tooltip = undefined;
|
|
152
|
+
import { Editor } from "@tiptap/core";
|
|
153
|
+
import Tooltip, { TippyInitOptions } from "../helpers/tippyHelper";
|
|
154
|
+
import { find } from "linkifyjs";
|
|
145
155
|
|
|
146
156
|
|
|
147
|
-
|
|
157
|
+
let tooltip: Tooltip | undefined = undefined;
|
|
158
|
+
function setHyperlinkModal(options) {
|
|
148
159
|
// Create the tooltip instance
|
|
149
|
-
if (!tooltip) tooltip = new Tooltip(
|
|
160
|
+
if (!tooltip) tooltip = new options.Tooltip(options);
|
|
150
161
|
|
|
151
162
|
// Initialize the tooltip
|
|
152
163
|
let { tippyModal } = tooltip.init();
|
|
153
164
|
|
|
154
|
-
const
|
|
165
|
+
const hyperlinkModal = document.createElement("div");
|
|
155
166
|
const buttonsWrapper = document.createElement("div");
|
|
156
167
|
const inputsWrapper = document.createElement("div");
|
|
157
168
|
|
|
158
|
-
|
|
169
|
+
hyperlinkModal.classList.add("hyperlink-set-modal");
|
|
159
170
|
|
|
160
|
-
buttonsWrapper.classList.add("
|
|
161
|
-
inputsWrapper.classList.add("
|
|
171
|
+
buttonsWrapper.classList.add("hyperlink-set-modal__buttons-wrapper");
|
|
172
|
+
inputsWrapper.classList.add("hyperlink-set-modal__inputs-wrapper");
|
|
162
173
|
|
|
163
174
|
// create a form that contain url input and a button for submit
|
|
164
175
|
const form = document.createElement("form");
|
|
@@ -174,20 +185,41 @@ const setHyperlink(options: setHyperlinkDialogOptions): void {
|
|
|
174
185
|
buttonsWrapper.append(button);
|
|
175
186
|
form.append(inputsWrapper, buttonsWrapper);
|
|
176
187
|
|
|
177
|
-
|
|
188
|
+
hyperlinkModal.append(form);
|
|
178
189
|
|
|
179
190
|
tippyModal.innerHTML = "";
|
|
180
|
-
tippyModal.append(
|
|
191
|
+
tippyModal.append(hyperlinkModal);
|
|
192
|
+
tooltip.update(options.editor.view, {
|
|
193
|
+
arrow: options.roundArrow,
|
|
194
|
+
});
|
|
181
195
|
|
|
182
|
-
|
|
196
|
+
// make sure
|
|
197
|
+
setTimeout(() => input.focus();, 100);
|
|
198
|
+
|
|
199
|
+
// event listenr for submit button
|
|
183
200
|
form.addEventListener("submit", (event) => {
|
|
184
201
|
event.preventDefault();
|
|
185
202
|
const url = input.value;
|
|
186
|
-
|
|
203
|
+
|
|
204
|
+
if (!url) return;
|
|
205
|
+
|
|
206
|
+
const sanitizeURL = find(url)
|
|
207
|
+
.filter((link) => link.isLink)
|
|
208
|
+
.filter((link) => {
|
|
209
|
+
if (options.validate) {
|
|
210
|
+
return options.validate(link.value);
|
|
211
|
+
}
|
|
212
|
+
return true;
|
|
213
|
+
})
|
|
214
|
+
.at(0);
|
|
215
|
+
|
|
216
|
+
if (!sanitizeURL?.href) return;
|
|
217
|
+
|
|
218
|
+
tooltip?.hide();
|
|
187
219
|
|
|
188
220
|
return options.editor
|
|
189
221
|
.chain()
|
|
190
|
-
.setMark(options.extentionName, { href:
|
|
222
|
+
.setMark(options.extentionName, { href: sanitizeURL.href })
|
|
191
223
|
.setMeta("preventautohyperlink", true)
|
|
192
224
|
.run();
|
|
193
225
|
});
|
|
@@ -199,22 +231,22 @@ const setHyperlink(options: setHyperlinkDialogOptions): void {
|
|
|
199
231
|
````ts
|
|
200
232
|
import {
|
|
201
233
|
Hyperlink,
|
|
202
|
-
|
|
203
|
-
|
|
234
|
+
previewHyperlinkModal,
|
|
235
|
+
setHyperlinkModal
|
|
204
236
|
} from "@docs.plus/extension-hyperlink";
|
|
205
237
|
|
|
206
238
|
Hyperlink.configure({
|
|
207
|
-
|
|
239
|
+
modals: {
|
|
208
240
|
previewHyperlink: (data) => {
|
|
209
|
-
return
|
|
241
|
+
return previewHyperlinkModal(data);
|
|
210
242
|
},
|
|
211
243
|
setHyperlink: (data) => {
|
|
212
|
-
return
|
|
244
|
+
return setHyperlinkModal(data);
|
|
213
245
|
},
|
|
214
246
|
},
|
|
215
247
|
})
|
|
216
248
|
````
|
|
217
|
-
> Note: The `
|
|
249
|
+
> Note: The `previewHyperlinkModal` and `setHyperlinkModal` modals are prebuilt modal boxes. You can use them or create your own modal boxes. To learn how to create your own modal boxes, please check the [source code](https://github.com/HMarzban/extension-hyperlink/tree/main/packages/extension-hyperlink/src/modals)
|
|
218
250
|
|
|
219
251
|
|
|
220
252
|
### Removing and overriding existing html attributes
|
|
@@ -311,14 +343,8 @@ this.editor.getAttributes('link').href
|
|
|
311
343
|
|
|
312
344
|
## Inspiration and Acknowledgment, Let's Connect
|
|
313
345
|
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
Let us share a little behind-the-scenes story with you. Our extension was inspired by Tiptap's [extension-link](https://github.com/ueberdosis/tiptap/tree/main/packages/extension-link). We were so impressed by their "headless" approach that we decided to take it further and add our own touch to make it even more user-friendly and versatile.
|
|
317
|
-
|
|
318
|
-
Now, let's be clear, we're not officially affiliated with Tiptap, but we firmly believe in giving credit where it's due. Their brilliant work laid the foundation for our extension, and we're truly grateful for that!
|
|
319
|
-
|
|
320
|
-
But enough about us, let's talk about you! We genuinely appreciate your interest in our work. If you have any ideas or suggestions on how we can make this extension even better, or if you're simply curious about Docs.plus, we'd love to chat.
|
|
346
|
+
Thank you for exploring our Hyperlink extension from docs.plus! We aim to make collaboration and knowledge sharing not just easy, but also enjoyable.
|
|
321
347
|
|
|
322
|
-
|
|
348
|
+
Our extension is inspired by Tiptap's [extension-link](https://github.com/ueberdosis/tiptap/tree/main/packages/extension-link). While we've incorporated our own enhancements, we'd like to tip our hats to Tiptap for pioneering the "headless" approach that we admire greatly. Please note: We're not affiliated with Tiptap, but we believe in recognizing foundational work.
|
|
323
349
|
|
|
324
|
-
|
|
350
|
+
Your feedback and interest in docs.plus are invaluable to us. Share your thoughts, suggestions, or dive deeper into our mission at the [docs.plus](https://github.com/docs-plus/docs.plus) repository. Wish to converse? Connect with us [here](https://github.com/docs-plus/docs.plus#-connect-with-us).
|
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import { MarkType } from "@tiptap/pm/model";
|
|
2
2
|
import { Plugin } from "@tiptap/pm/state";
|
|
3
3
|
import { Editor } from "@tiptap/core";
|
|
4
|
-
import { EditorView } from "@tiptap/pm/view";
|
|
5
4
|
type ClickHandlerOptions = {
|
|
6
5
|
type: MarkType;
|
|
7
6
|
editor: Editor;
|
|
8
7
|
validate?: (url: string) => boolean;
|
|
9
|
-
|
|
10
|
-
dialogBox?: ((options: any) => void | HTMLElement) | null;
|
|
8
|
+
modal?: ((options: any) => void | HTMLElement) | null;
|
|
11
9
|
};
|
|
12
10
|
export default function clickHandler(options: ClickHandlerOptions): Plugin;
|
|
13
11
|
export {};
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { Instance, Props } from "tippy.js";
|
|
2
2
|
import { Editor } from "@tiptap/core";
|
|
3
3
|
import { EditorView } from "@tiptap/pm/view";
|
|
4
|
-
interface TippyInitOptions {
|
|
4
|
+
export interface TippyInitOptions {
|
|
5
5
|
editor: Editor;
|
|
6
6
|
validate?: (url: string) => boolean;
|
|
7
|
-
view: EditorView;
|
|
8
7
|
}
|
|
9
8
|
declare class Tooltip {
|
|
10
9
|
private tippyInstance?;
|
package/dist/hyperlink.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { Mark } from "@tiptap/core";
|
|
2
|
+
import { TSetHyperlinkModalOptions } from "./modals/setHyperlink";
|
|
3
|
+
import { THyperlinkPreviewModalOptions } from "./modals/previewHyperlink";
|
|
2
4
|
export interface LinkProtocolOptions {
|
|
3
5
|
scheme: string;
|
|
4
6
|
optionalSlashes?: boolean;
|
|
@@ -25,13 +27,13 @@ export interface HyperlinkOptions {
|
|
|
25
27
|
*/
|
|
26
28
|
HTMLAttributes: Record<string, any>;
|
|
27
29
|
/**
|
|
28
|
-
* A list of
|
|
30
|
+
* A list of modals to be rendered.
|
|
29
31
|
* @default null
|
|
30
32
|
* @example
|
|
31
33
|
*/
|
|
32
|
-
|
|
33
|
-
previewHyperlink?: ((options:
|
|
34
|
-
setHyperlink?: ((options:
|
|
34
|
+
modals: {
|
|
35
|
+
previewHyperlink?: ((options: THyperlinkPreviewModalOptions) => void | HTMLElement) | null;
|
|
36
|
+
setHyperlink?: ((options: TSetHyperlinkModalOptions) => void | HTMLElement) | null;
|
|
35
37
|
};
|
|
36
38
|
/**
|
|
37
39
|
* A validation function that modifies link verification for the auto linker.
|
package/dist/index.cjs
CHANGED
|
@@ -128,7 +128,7 @@ class Tooltip {
|
|
|
128
128
|
this.blurHandler({ event });
|
|
129
129
|
};
|
|
130
130
|
this.editor = options.editor;
|
|
131
|
-
this.view =
|
|
131
|
+
this.view = this.editor.view;
|
|
132
132
|
this.tippyWrapper = document.createElement("div");
|
|
133
133
|
this.tippyWrapper.addEventListener("mousedown", this.mousedownHandler, {
|
|
134
134
|
capture: true,
|
|
@@ -227,8 +227,8 @@ function clickHandler(options) {
|
|
|
227
227
|
// Extract href and target attributes from the link element or the state
|
|
228
228
|
const href = (_a = link === null || link === void 0 ? void 0 : link.href) !== null && _a !== void 0 ? _a : attrs.href;
|
|
229
229
|
const target = (_b = link === null || link === void 0 ? void 0 : link.target) !== null && _b !== void 0 ? _b : attrs.target;
|
|
230
|
-
// If there is no previewHyperlink
|
|
231
|
-
if (!options.
|
|
230
|
+
// If there is no previewHyperlink modal provided, then open the link in new window
|
|
231
|
+
if (!options.modal) {
|
|
232
232
|
if (link && href) {
|
|
233
233
|
window.open(href, target);
|
|
234
234
|
}
|
|
@@ -238,22 +238,22 @@ function clickHandler(options) {
|
|
|
238
238
|
if (!(link === null || link === void 0 ? void 0 : link.href))
|
|
239
239
|
return tooltip.hide();
|
|
240
240
|
// Create a preview of the hyperlink
|
|
241
|
-
const hyperlinkPreview = options.
|
|
241
|
+
const hyperlinkPreview = options.modal({
|
|
242
242
|
link,
|
|
243
243
|
nodePos,
|
|
244
244
|
tippy: tooltip,
|
|
245
245
|
...options,
|
|
246
246
|
});
|
|
247
|
-
// If there is no hyperlink preview, hide the
|
|
247
|
+
// If there is no hyperlink preview, hide the modal
|
|
248
248
|
if (!hyperlinkPreview)
|
|
249
249
|
return tooltip.hide();
|
|
250
|
-
// Empty the
|
|
250
|
+
// Empty the modal and append the hyperlink preview box
|
|
251
251
|
while (tippyModal.firstChild) {
|
|
252
252
|
tippyModal.removeChild(tippyModal.firstChild);
|
|
253
253
|
}
|
|
254
254
|
tippyModal.append(hyperlinkPreview);
|
|
255
|
-
// Update the
|
|
256
|
-
tooltip.update(options.view);
|
|
255
|
+
// Update the modal position
|
|
256
|
+
tooltip.update(options.editor.view);
|
|
257
257
|
return false;
|
|
258
258
|
},
|
|
259
259
|
},
|
|
@@ -360,7 +360,7 @@ const Hyperlink = core.Mark.create({
|
|
|
360
360
|
rel: "noopener noreferrer nofollow",
|
|
361
361
|
class: null,
|
|
362
362
|
},
|
|
363
|
-
|
|
363
|
+
modals: {
|
|
364
364
|
previewHyperlink: null,
|
|
365
365
|
setHyperlink: null,
|
|
366
366
|
},
|
|
@@ -389,18 +389,20 @@ const Hyperlink = core.Mark.create({
|
|
|
389
389
|
addCommands() {
|
|
390
390
|
return {
|
|
391
391
|
setHyperlink: (attributes) => ({ editor, chain }) => {
|
|
392
|
-
if (!this.options.
|
|
392
|
+
if (!this.options.modals.setHyperlink) {
|
|
393
393
|
return chain()
|
|
394
394
|
.setMark(this.name, attributes)
|
|
395
395
|
.setMeta("preventAutohyperlink", true)
|
|
396
396
|
.run();
|
|
397
397
|
}
|
|
398
398
|
else {
|
|
399
|
-
this.options.
|
|
399
|
+
this.options.modals.setHyperlink({
|
|
400
400
|
editor,
|
|
401
401
|
validate: this.options.validate,
|
|
402
402
|
extentionName: this.name,
|
|
403
403
|
attributes,
|
|
404
|
+
Tooltip,
|
|
405
|
+
roundArrow: tippy.roundArrow,
|
|
404
406
|
});
|
|
405
407
|
return true;
|
|
406
408
|
}
|
|
@@ -473,8 +475,7 @@ const Hyperlink = core.Mark.create({
|
|
|
473
475
|
type: this.type,
|
|
474
476
|
editor: this.editor,
|
|
475
477
|
validate: this.options.validate,
|
|
476
|
-
|
|
477
|
-
dialogBox: this.options.dialogBoxs.previewHyperlink,
|
|
478
|
+
modal: this.options.modals.previewHyperlink,
|
|
478
479
|
}));
|
|
479
480
|
}
|
|
480
481
|
if (this.options.hyperlinkOnPaste) {
|
|
@@ -487,7 +488,7 @@ const Hyperlink = core.Mark.create({
|
|
|
487
488
|
},
|
|
488
489
|
});
|
|
489
490
|
|
|
490
|
-
const
|
|
491
|
+
const editHyperlinkHandler = (options) => {
|
|
491
492
|
var _a;
|
|
492
493
|
// Create the form
|
|
493
494
|
const form = document.createElement("form");
|
|
@@ -496,8 +497,8 @@ const editeHyperlinkHandler = (options) => {
|
|
|
496
497
|
const linkTextInput = document.createElement("input");
|
|
497
498
|
const hrefInput = document.createElement("input");
|
|
498
499
|
const applyButton = document.createElement("button");
|
|
499
|
-
buttonsWrapper.classList.add("
|
|
500
|
-
inputsWrapper.classList.add("
|
|
500
|
+
buttonsWrapper.classList.add("hyperlink-edit-modal__buttons-wrapper");
|
|
501
|
+
inputsWrapper.classList.add("hyperlink-edit-modal__inputs-wrapper");
|
|
501
502
|
linkTextInput.type = "text";
|
|
502
503
|
linkTextInput.value = ((_a = options.link) === null || _a === void 0 ? void 0 : _a.innerText) || "";
|
|
503
504
|
linkTextInput.placeholder = "Enter link text";
|
|
@@ -505,14 +506,14 @@ const editeHyperlinkHandler = (options) => {
|
|
|
505
506
|
hrefInput.value = options.link.href;
|
|
506
507
|
hrefInput.placeholder = "Enter href";
|
|
507
508
|
applyButton.type = "submit";
|
|
508
|
-
applyButton.classList.add("
|
|
509
|
+
applyButton.classList.add("hyperlink-edit-modal__apply-button");
|
|
509
510
|
applyButton.innerText = "Apply";
|
|
510
511
|
buttonsWrapper.append(applyButton);
|
|
511
512
|
inputsWrapper.append(linkTextInput, hrefInput);
|
|
512
513
|
// Append to form
|
|
513
514
|
form.append(inputsWrapper, buttonsWrapper);
|
|
514
|
-
options.
|
|
515
|
-
options.
|
|
515
|
+
options.hyperlinkModal.innerHTML = "";
|
|
516
|
+
options.hyperlinkModal.appendChild(form);
|
|
516
517
|
hrefInput.addEventListener("keydown", () => {
|
|
517
518
|
hrefInput.style.outlineColor = " #dadce0";
|
|
518
519
|
});
|
|
@@ -551,7 +552,7 @@ const editeHyperlinkHandler = (options) => {
|
|
|
551
552
|
options.tippy.hide();
|
|
552
553
|
});
|
|
553
554
|
// Show tooltip
|
|
554
|
-
options.tippy.update(options.view, {
|
|
555
|
+
options.tippy.update(options.editor.view, {
|
|
555
556
|
arrow: tippy.roundArrow,
|
|
556
557
|
});
|
|
557
558
|
setTimeout(() => linkTextInput.focus());
|
|
@@ -580,14 +581,14 @@ const Pencil = ({ size = 24, fill = "rgb(104, 81, 255)", } = {}) => {
|
|
|
580
581
|
`;
|
|
581
582
|
};
|
|
582
583
|
|
|
583
|
-
function
|
|
584
|
+
function previewHyperlinkModal(options) {
|
|
584
585
|
const href = options.link.href;
|
|
585
|
-
const
|
|
586
|
+
const hyperlinkModal = document.createElement("div");
|
|
586
587
|
const removeButton = document.createElement("button");
|
|
587
588
|
const copyButton = document.createElement("button");
|
|
588
589
|
const editButton = document.createElement("button");
|
|
589
590
|
const newBubble = document.createElement("div");
|
|
590
|
-
newBubble.classList.add("
|
|
591
|
+
newBubble.classList.add("hyperlink-preview-modal__metadata");
|
|
591
592
|
const hrefTitle = document.createElement("a");
|
|
592
593
|
hrefTitle.setAttribute("target", "_blank");
|
|
593
594
|
hrefTitle.setAttribute("rel", "noreferrer");
|
|
@@ -616,39 +617,39 @@ function previewHyperlink(options) {
|
|
|
616
617
|
.catch((error) => {
|
|
617
618
|
console.error("Error fetching metadata:", error);
|
|
618
619
|
});
|
|
619
|
-
|
|
620
|
-
removeButton.classList.add("
|
|
620
|
+
hyperlinkModal.classList.add("hyperlink-preview-modal");
|
|
621
|
+
removeButton.classList.add("hyperlink-preview-modal__remove-button");
|
|
621
622
|
removeButton.innerHTML = LinkSlash();
|
|
622
|
-
editButton.classList.add("
|
|
623
|
+
editButton.classList.add("hyperlink-preview-modal__edit-button");
|
|
623
624
|
editButton.innerHTML = Pencil();
|
|
624
|
-
copyButton.classList.add("
|
|
625
|
+
copyButton.classList.add("hyperlink-preview-modal__copy-button");
|
|
625
626
|
copyButton.innerHTML = Copy();
|
|
626
627
|
removeButton.addEventListener("click", () => {
|
|
627
628
|
options.tippy.hide();
|
|
628
629
|
return options.editor.chain().focus().unsetHyperlink().run();
|
|
629
630
|
});
|
|
630
|
-
editButton.addEventListener("click", () =>
|
|
631
|
+
editButton.addEventListener("click", () => editHyperlinkHandler({ ...options, hyperlinkModal }));
|
|
631
632
|
copyButton.addEventListener("click", () => {
|
|
632
633
|
options.tippy.hide();
|
|
633
634
|
navigator.clipboard.writeText(href);
|
|
634
635
|
});
|
|
635
|
-
|
|
636
|
-
return
|
|
636
|
+
hyperlinkModal.append(newBubble, copyButton, editButton, removeButton);
|
|
637
|
+
return hyperlinkModal;
|
|
637
638
|
}
|
|
638
639
|
|
|
639
640
|
let tooltip = undefined;
|
|
640
|
-
function
|
|
641
|
+
function setHyperlinkModal(options) {
|
|
641
642
|
// Create the tooltip instance
|
|
642
643
|
if (!tooltip)
|
|
643
|
-
tooltip = new Tooltip(
|
|
644
|
+
tooltip = new options.Tooltip(options);
|
|
644
645
|
// Initialize the tooltip
|
|
645
646
|
let { tippyModal } = tooltip.init();
|
|
646
|
-
const
|
|
647
|
+
const hyperlinkModal = document.createElement("div");
|
|
647
648
|
const buttonsWrapper = document.createElement("div");
|
|
648
649
|
const inputsWrapper = document.createElement("div");
|
|
649
|
-
|
|
650
|
-
buttonsWrapper.classList.add("
|
|
651
|
-
inputsWrapper.classList.add("
|
|
650
|
+
hyperlinkModal.classList.add("hyperlink-set-modal");
|
|
651
|
+
buttonsWrapper.classList.add("hyperlink-set-modal__buttons-wrapper");
|
|
652
|
+
inputsWrapper.classList.add("hyperlink-set-modal__inputs-wrapper");
|
|
652
653
|
// create a form that contain url input and a button for submit
|
|
653
654
|
const form = document.createElement("form");
|
|
654
655
|
const input = document.createElement("input");
|
|
@@ -660,11 +661,11 @@ function setHyperlink(options) {
|
|
|
660
661
|
inputsWrapper.append(input);
|
|
661
662
|
buttonsWrapper.append(button);
|
|
662
663
|
form.append(inputsWrapper, buttonsWrapper);
|
|
663
|
-
|
|
664
|
+
hyperlinkModal.append(form);
|
|
664
665
|
tippyModal.innerHTML = "";
|
|
665
|
-
tippyModal.append(
|
|
666
|
+
tippyModal.append(hyperlinkModal);
|
|
666
667
|
tooltip.update(options.editor.view, {
|
|
667
|
-
arrow:
|
|
668
|
+
arrow: options.roundArrow,
|
|
668
669
|
});
|
|
669
670
|
// make sure
|
|
670
671
|
setTimeout(() => {
|
|
@@ -706,6 +707,6 @@ function setHyperlink(options) {
|
|
|
706
707
|
|
|
707
708
|
exports.Hyperlink = Hyperlink;
|
|
708
709
|
exports.Tooltip = Tooltip;
|
|
709
|
-
exports.
|
|
710
|
-
exports.
|
|
710
|
+
exports.previewHyperlinkModal = previewHyperlinkModal;
|
|
711
|
+
exports.setHyperlinkModal = setHyperlinkModal;
|
|
711
712
|
//# sourceMappingURL=index.cjs.map
|