/
config.ts
124 lines (103 loc) · 2.8 KB
/
config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*!
* Jodit Editor (https://xdsoft.net/jodit/)
* Released under MIT see LICENSE.txt in the project root for license information.
* Copyright (c) 2013-2024 Valeriy Chupurnov. All rights reserved. https://xdsoft.net
*/
/**
* @module plugins/link
*/
import type { IControlType, IJodit, IUIForm, IUIOption } from 'jodit/types';
import { Dom } from 'jodit/core/dom/dom';
import { Icon } from 'jodit/core/ui/icon';
import { Config } from 'jodit/config';
import linkIcon from './icons/link.svg';
import unlinkIcon from './icons/unlink.svg';
import { formTemplate } from './template';
declare module 'jodit/config' {
interface Config {
link: {
/**
* Template for the link dialog form
*/
formTemplate: (editor: IJodit) => string | HTMLElement | IUIForm;
formClassName?: string;
/**
* Follow link address after dblclick
*/
followOnDblClick: boolean;
/**
* Replace inserted youtube/vimeo link to `iframe`
*/
processVideoLink: boolean;
/**
* Wrap inserted link
*/
processPastedLink: boolean;
/**
* Show `no follow` checkbox in link dialog.
*/
noFollowCheckbox: boolean;
/**
* Show `Open in new tab` checkbox in link dialog.
*/
openInNewTabCheckbox: boolean;
/**
* Use an input text to ask the classname or a select or not ask
*/
modeClassName: 'input' | 'select';
/**
* Allow multiple choises (to use with modeClassName="select")
*/
selectMultipleClassName: boolean;
/**
* The size of the select (to use with modeClassName="select")
*/
selectSizeClassName?: number;
/**
* The list of the option for the select (to use with modeClassName="select")
*/
selectOptionsClassName: IUIOption[];
hotkeys: string[];
};
}
}
Config.prototype.link = {
formTemplate,
followOnDblClick: false,
processVideoLink: true,
processPastedLink: true,
noFollowCheckbox: true,
openInNewTabCheckbox: true,
modeClassName: 'input',
selectMultipleClassName: true,
selectSizeClassName: 3,
selectOptionsClassName: [],
hotkeys: ['ctrl+k', 'cmd+k']
};
Icon.set('link', linkIcon).set('unlink', unlinkIcon);
Config.prototype.controls.unlink = {
exec: (editor: IJodit, current: Node) => {
const anchor: HTMLAnchorElement | false = Dom.closest(
current,
'a',
editor.editor
) as HTMLAnchorElement;
if (anchor) {
Dom.unwrap(anchor);
}
editor.synchronizeValues();
editor.e.fire('hidePopup');
},
tooltip: 'Unlink'
} as IControlType;
Config.prototype.controls.link = {
isActive: (editor: IJodit): boolean => {
const current = editor.s.current();
return Boolean(current && Dom.closest(current, 'a', editor.editor));
},
popup: (editor: IJodit, current, close: () => void) => {
return editor.e.fire('generateLinkForm.link', current, close);
},
tags: ['a'],
tooltip: 'Insert link'
} as IControlType;