@aquera/nile-elements 1.5.9 → 1.6.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/README.md +6 -0
- package/dist/index.cjs.js +1 -1
- package/dist/index.esm.js +1 -1
- package/dist/index.js +382 -227
- package/dist/nile-floating-panel/index.cjs.js +1 -1
- package/dist/nile-floating-panel/index.esm.js +1 -1
- package/dist/nile-floating-panel/nile-floating-panel.cjs.js +1 -1
- package/dist/nile-floating-panel/nile-floating-panel.cjs.js.map +1 -1
- package/dist/nile-floating-panel/nile-floating-panel.css.cjs.js +1 -1
- package/dist/nile-floating-panel/nile-floating-panel.css.cjs.js.map +1 -1
- package/dist/nile-floating-panel/nile-floating-panel.css.esm.js +137 -21
- package/dist/nile-floating-panel/nile-floating-panel.esm.js +1 -1
- package/dist/nile-lite-tooltip/index.cjs.js +1 -1
- package/dist/nile-lite-tooltip/index.esm.js +1 -1
- package/dist/nile-lite-tooltip/nile-lite-tooltip.cjs.js +1 -1
- package/dist/nile-lite-tooltip/nile-lite-tooltip.cjs.js.map +1 -1
- package/dist/nile-lite-tooltip/nile-lite-tooltip.esm.js +1 -1
- package/dist/nile-rich-text-editor/nile-rich-text-editor.cjs.js +1 -1
- package/dist/nile-rich-text-editor/nile-rich-text-editor.cjs.js.map +1 -1
- package/dist/nile-rich-text-editor/nile-rich-text-editor.css.cjs.js +1 -1
- package/dist/nile-rich-text-editor/nile-rich-text-editor.css.cjs.js.map +1 -1
- package/dist/nile-rich-text-editor/nile-rich-text-editor.css.esm.js +24 -0
- package/dist/nile-rich-text-editor/nile-rich-text-editor.esm.js +1 -1
- package/dist/nile-rich-text-editor/nile-rte-link.cjs.js +1 -1
- package/dist/nile-rich-text-editor/nile-rte-link.cjs.js.map +1 -1
- package/dist/nile-rich-text-editor/nile-rte-link.esm.js +59 -44
- package/dist/nile-rich-text-editor/utils/inline-utils.cjs.js +1 -1
- package/dist/nile-rich-text-editor/utils/inline-utils.cjs.js.map +1 -1
- package/dist/nile-rich-text-editor/utils/inline-utils.esm.js +1 -1
- package/dist/src/index.d.ts +1 -1
- package/dist/src/index.js +1 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/nile-floating-panel/index.js.map +1 -1
- package/dist/src/nile-floating-panel/nile-floating-panel.css.d.ts +1 -1
- package/dist/src/nile-floating-panel/nile-floating-panel.css.js +147 -20
- package/dist/src/nile-floating-panel/nile-floating-panel.css.js.map +1 -1
- package/dist/src/nile-floating-panel/nile-floating-panel.d.ts +90 -24
- package/dist/src/nile-floating-panel/nile-floating-panel.js +478 -159
- package/dist/src/nile-floating-panel/nile-floating-panel.js.map +1 -1
- package/dist/src/nile-rich-text-editor/nile-rich-text-editor.css.js +24 -0
- package/dist/src/nile-rich-text-editor/nile-rich-text-editor.css.js.map +1 -1
- package/dist/src/nile-rich-text-editor/nile-rich-text-editor.d.ts +6 -0
- package/dist/src/nile-rich-text-editor/nile-rich-text-editor.js +62 -24
- package/dist/src/nile-rich-text-editor/nile-rich-text-editor.js.map +1 -1
- package/dist/src/nile-rich-text-editor/nile-rte-link.d.ts +12 -0
- package/dist/src/nile-rich-text-editor/nile-rte-link.js +239 -130
- package/dist/src/nile-rich-text-editor/nile-rte-link.js.map +1 -1
- package/dist/src/nile-rich-text-editor/nile-rte-link.test.d.ts +1 -0
- package/dist/src/nile-rich-text-editor/nile-rte-link.test.js +469 -0
- package/dist/src/nile-rich-text-editor/nile-rte-link.test.js.map +1 -0
- package/dist/src/nile-rich-text-editor/utils/inline-utils.js +13 -4
- package/dist/src/nile-rich-text-editor/utils/inline-utils.js.map +1 -1
- package/dist/src/version.js +1 -1
- package/dist/src/version.js.map +1 -1
- package/dist/tippy.esm-57628c2b.esm.js +1 -0
- package/dist/tippy.esm-78baa8f2.cjs.js +2 -0
- package/dist/tippy.esm-78baa8f2.cjs.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -3
- package/src/index.ts +2 -2
- package/src/nile-floating-panel/index.ts +0 -1
- package/src/nile-floating-panel/nile-floating-panel.css.ts +149 -21
- package/src/nile-floating-panel/nile-floating-panel.ts +489 -190
- package/src/nile-rich-text-editor/nile-rich-text-editor.css.ts +24 -0
- package/src/nile-rich-text-editor/nile-rich-text-editor.ts +66 -26
- package/src/nile-rich-text-editor/nile-rte-link.test.ts +682 -0
- package/src/nile-rich-text-editor/nile-rte-link.ts +195 -100
- package/src/nile-rich-text-editor/utils/inline-utils.ts +11 -4
- package/vscode-html-custom-data.json +229 -25
- package/dist/nile-floating-panel/anchor-manager.cjs.js +0 -2
- package/dist/nile-floating-panel/anchor-manager.cjs.js.map +0 -1
- package/dist/nile-floating-panel/anchor-manager.esm.js +0 -1
- package/dist/nile-floating-panel/content-manager.cjs.js +0 -2
- package/dist/nile-floating-panel/content-manager.cjs.js.map +0 -1
- package/dist/nile-floating-panel/content-manager.esm.js +0 -1
- package/dist/nile-floating-panel/event-manager.cjs.js +0 -2
- package/dist/nile-floating-panel/event-manager.cjs.js.map +0 -1
- package/dist/nile-floating-panel/event-manager.esm.js +0 -1
- package/dist/nile-floating-panel/position-manager.cjs.js +0 -2
- package/dist/nile-floating-panel/position-manager.cjs.js.map +0 -1
- package/dist/nile-floating-panel/position-manager.esm.js +0 -1
- package/dist/nile-floating-panel/style-manager.cjs.js +0 -2
- package/dist/nile-floating-panel/style-manager.cjs.js.map +0 -1
- package/dist/nile-floating-panel/style-manager.esm.js +0 -1
- package/dist/nile-floating-panel/types.cjs.js +0 -2
- package/dist/nile-floating-panel/types.cjs.js.map +0 -1
- package/dist/nile-floating-panel/types.esm.js +0 -1
- package/dist/src/nile-floating-panel/anchor-manager.d.ts +0 -6
- package/dist/src/nile-floating-panel/anchor-manager.js +0 -27
- package/dist/src/nile-floating-panel/anchor-manager.js.map +0 -1
- package/dist/src/nile-floating-panel/content-manager.d.ts +0 -5
- package/dist/src/nile-floating-panel/content-manager.js +0 -44
- package/dist/src/nile-floating-panel/content-manager.js.map +0 -1
- package/dist/src/nile-floating-panel/event-manager.d.ts +0 -14
- package/dist/src/nile-floating-panel/event-manager.js +0 -52
- package/dist/src/nile-floating-panel/event-manager.js.map +0 -1
- package/dist/src/nile-floating-panel/position-manager.d.ts +0 -17
- package/dist/src/nile-floating-panel/position-manager.js +0 -72
- package/dist/src/nile-floating-panel/position-manager.js.map +0 -1
- package/dist/src/nile-floating-panel/style-manager.d.ts +0 -9
- package/dist/src/nile-floating-panel/style-manager.js +0 -44
- package/dist/src/nile-floating-panel/style-manager.js.map +0 -1
- package/dist/src/nile-floating-panel/types.d.ts +0 -11
- package/dist/src/nile-floating-panel/types.js +0 -2
- package/dist/src/nile-floating-panel/types.js.map +0 -1
- package/src/nile-floating-panel/anchor-manager.ts +0 -33
- package/src/nile-floating-panel/content-manager.ts +0 -54
- package/src/nile-floating-panel/event-manager.ts +0 -74
- package/src/nile-floating-panel/position-manager.ts +0 -102
- package/src/nile-floating-panel/style-manager.ts +0 -54
- package/src/nile-floating-panel/types.ts +0 -15
|
@@ -5,9 +5,13 @@ let NileRteLink = class NileRteLink extends LitElement {
|
|
|
5
5
|
constructor() {
|
|
6
6
|
super(...arguments);
|
|
7
7
|
this.newTab = false;
|
|
8
|
+
this.disabled = false;
|
|
9
|
+
this.showTextSupport = false;
|
|
8
10
|
this.placeholder = 'Type or paste link here';
|
|
11
|
+
this.textPlaceholder = 'Display text';
|
|
9
12
|
this.label = 'Link';
|
|
10
13
|
this.linkValue = '';
|
|
14
|
+
this.textValue = '';
|
|
11
15
|
this.hasActiveLink = false;
|
|
12
16
|
this.popoverStyle = '';
|
|
13
17
|
this.selectionRange = null;
|
|
@@ -17,6 +21,108 @@ let NileRteLink = class NileRteLink extends LitElement {
|
|
|
17
21
|
this.onScroll = () => {
|
|
18
22
|
this.closePopover();
|
|
19
23
|
};
|
|
24
|
+
this.onOpen = () => {
|
|
25
|
+
if (this.disabled)
|
|
26
|
+
return;
|
|
27
|
+
const sel = document.getSelection();
|
|
28
|
+
if (!sel || sel.rangeCount === 0)
|
|
29
|
+
return;
|
|
30
|
+
if (!this.editorEl.contains(sel.getRangeAt(0).commonAncestorContainer))
|
|
31
|
+
return;
|
|
32
|
+
this.selectionRange = sel.getRangeAt(0).cloneRange();
|
|
33
|
+
this.activeAnchor = null;
|
|
34
|
+
this.hasActiveLink = false;
|
|
35
|
+
let n = this.selectionRange.startContainer;
|
|
36
|
+
while (n && n !== this.editorEl) {
|
|
37
|
+
if (n instanceof HTMLAnchorElement) {
|
|
38
|
+
this.activeAnchor = n;
|
|
39
|
+
this.hasActiveLink = true;
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
n = n.parentNode;
|
|
43
|
+
}
|
|
44
|
+
this.linkValue = this.activeAnchor
|
|
45
|
+
? this.displayUrl(this.activeAnchor.href)
|
|
46
|
+
: '';
|
|
47
|
+
if (this.showTextSupport) {
|
|
48
|
+
if (this.activeAnchor) {
|
|
49
|
+
this.textValue = this.activeAnchor.textContent || '';
|
|
50
|
+
}
|
|
51
|
+
else if (!this.selectionRange.collapsed) {
|
|
52
|
+
this.textValue = this.selectionRange.toString();
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
this.textValue = '';
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
this.positionPopover();
|
|
59
|
+
this.openPopover();
|
|
60
|
+
requestAnimationFrame(() => {
|
|
61
|
+
const inputs = this.querySelectorAll('nile-input');
|
|
62
|
+
const target = inputs.length > 1 ? inputs[1] : inputs[0];
|
|
63
|
+
target?.focus();
|
|
64
|
+
});
|
|
65
|
+
};
|
|
66
|
+
this.onInputKeydown = (e) => {
|
|
67
|
+
if (e.key !== 'Escape' && e.key !== 'Enter')
|
|
68
|
+
return;
|
|
69
|
+
e.preventDefault();
|
|
70
|
+
e.stopPropagation();
|
|
71
|
+
if (e.key === 'Escape') {
|
|
72
|
+
this.closePopover();
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
this.isApplying = true;
|
|
76
|
+
try {
|
|
77
|
+
this.applyLink();
|
|
78
|
+
}
|
|
79
|
+
finally {
|
|
80
|
+
this.isApplying = false;
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
this.onInputBlur = () => {
|
|
84
|
+
if (this.ignoreBlur || this.isApplying)
|
|
85
|
+
return;
|
|
86
|
+
requestAnimationFrame(() => {
|
|
87
|
+
if (this.ignoreBlur || this.isApplying)
|
|
88
|
+
return;
|
|
89
|
+
const pop = this.querySelector('nile-popover');
|
|
90
|
+
if (pop?.matches(':focus-within'))
|
|
91
|
+
return;
|
|
92
|
+
this.closePopover();
|
|
93
|
+
});
|
|
94
|
+
};
|
|
95
|
+
this.onLinkInput = (e) => {
|
|
96
|
+
this.linkValue = e.detail.value;
|
|
97
|
+
};
|
|
98
|
+
this.onTextInput = (e) => {
|
|
99
|
+
this.textValue = e.detail.value;
|
|
100
|
+
};
|
|
101
|
+
this.onPopoverMousedown = () => {
|
|
102
|
+
this.ignoreBlur = true;
|
|
103
|
+
};
|
|
104
|
+
this.onPopoverMouseup = () => {
|
|
105
|
+
this.ignoreBlur = false;
|
|
106
|
+
};
|
|
107
|
+
this.onToolbarButtonMousedown = (e) => {
|
|
108
|
+
e.preventDefault();
|
|
109
|
+
};
|
|
110
|
+
this.onActionMousedown = (e) => {
|
|
111
|
+
e.preventDefault();
|
|
112
|
+
this.ignoreBlur = true;
|
|
113
|
+
};
|
|
114
|
+
this.onApplyClick = () => {
|
|
115
|
+
this.isApplying = true;
|
|
116
|
+
this.applyLink();
|
|
117
|
+
this.isApplying = false;
|
|
118
|
+
this.ignoreBlur = false;
|
|
119
|
+
};
|
|
120
|
+
this.onUnlinkClick = () => {
|
|
121
|
+
this.isApplying = true;
|
|
122
|
+
this.onRemove();
|
|
123
|
+
this.isApplying = false;
|
|
124
|
+
this.ignoreBlur = false;
|
|
125
|
+
};
|
|
20
126
|
}
|
|
21
127
|
createRenderRoot() {
|
|
22
128
|
return this;
|
|
@@ -25,41 +131,57 @@ let NileRteLink = class NileRteLink extends LitElement {
|
|
|
25
131
|
super.connectedCallback();
|
|
26
132
|
this.injectCss(`
|
|
27
133
|
nile-popover.rte-link-popover::part(popover) {
|
|
28
|
-
min-width:
|
|
134
|
+
min-width: 340px;
|
|
135
|
+
max-width: 420px;
|
|
29
136
|
background: white;
|
|
30
|
-
border: 1px solid var(--nile-colors-neutral-400,var(--ng-componentcolors-utility-gray-400));
|
|
31
|
-
border-radius:
|
|
137
|
+
border: 1px solid var(--nile-colors-neutral-400, var(--ng-componentcolors-utility-gray-400));
|
|
138
|
+
border-radius: 8px;
|
|
32
139
|
padding: 0;
|
|
33
140
|
gap: 0;
|
|
141
|
+
overflow: hidden;
|
|
142
|
+
height: auto;
|
|
143
|
+
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
.link-popup-wrap {
|
|
147
|
+
display: flex;
|
|
148
|
+
flex-direction: column;
|
|
149
|
+
gap: 12px;
|
|
150
|
+
padding: 12px;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
.link-popup-wrap nile-input {
|
|
154
|
+
width: 100%;
|
|
34
155
|
}
|
|
35
156
|
|
|
36
|
-
.link-popup {
|
|
157
|
+
.link-popup-wrap .link-input-row {
|
|
158
|
+
width: 100%;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
.link-popup-wrap .link-actions-row {
|
|
37
162
|
display: flex;
|
|
38
|
-
align-items:
|
|
39
|
-
gap:
|
|
40
|
-
|
|
163
|
+
align-items: flex-end;
|
|
164
|
+
gap: 4px;
|
|
165
|
+
width: 100%;
|
|
41
166
|
}
|
|
42
167
|
|
|
43
|
-
.link-input {
|
|
168
|
+
.link-popup-wrap .link-actions-row nile-input {
|
|
44
169
|
flex: 1;
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
border:
|
|
51
|
-
|
|
170
|
+
min-width: 0;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
nile-button.rte-link-button::part(base) {
|
|
175
|
+
border: none;
|
|
176
|
+
height: 32px;
|
|
177
|
+
width: 32px;
|
|
178
|
+
}
|
|
179
|
+
nile-button.rte-edit-button::part(base) {
|
|
180
|
+
border: none;
|
|
181
|
+
height: 32px;
|
|
182
|
+
width: 32px;
|
|
183
|
+
flex-shrink: 0;
|
|
52
184
|
}
|
|
53
|
-
nile-button.rte-link-button::part(base) {
|
|
54
|
-
border: none;
|
|
55
|
-
height: 32px;
|
|
56
|
-
width: 32px;
|
|
57
|
-
}
|
|
58
|
-
nile-button.rte-edit-button::part(base) {
|
|
59
|
-
border: none;
|
|
60
|
-
height: 38px;
|
|
61
|
-
width: 38px;
|
|
62
|
-
}
|
|
63
185
|
`);
|
|
64
186
|
}
|
|
65
187
|
injectCss(cssText) {
|
|
@@ -76,7 +198,7 @@ let NileRteLink = class NileRteLink extends LitElement {
|
|
|
76
198
|
return `https://${url}`;
|
|
77
199
|
}
|
|
78
200
|
displayUrl(url) {
|
|
79
|
-
return url
|
|
201
|
+
return url;
|
|
80
202
|
}
|
|
81
203
|
getSelectionRect() {
|
|
82
204
|
if (!this.selectionRange)
|
|
@@ -116,6 +238,7 @@ let NileRteLink = class NileRteLink extends LitElement {
|
|
|
116
238
|
pop && (pop.isShow = false);
|
|
117
239
|
window.removeEventListener('scroll', this.onScroll, true);
|
|
118
240
|
this.linkValue = '';
|
|
241
|
+
this.textValue = '';
|
|
119
242
|
this.selectionRange = null;
|
|
120
243
|
this.activeAnchor = null;
|
|
121
244
|
this.hasActiveLink = false;
|
|
@@ -126,78 +249,31 @@ let NileRteLink = class NileRteLink extends LitElement {
|
|
|
126
249
|
a.parentNode?.insertBefore(a.firstChild, a);
|
|
127
250
|
a.remove();
|
|
128
251
|
}
|
|
129
|
-
onOpen() {
|
|
130
|
-
const sel = document.getSelection();
|
|
131
|
-
if (!sel || sel.rangeCount === 0)
|
|
132
|
-
return;
|
|
133
|
-
this.selectionRange = sel.getRangeAt(0).cloneRange();
|
|
134
|
-
this.activeAnchor = null;
|
|
135
|
-
this.hasActiveLink = false;
|
|
136
|
-
let n = this.selectionRange.startContainer;
|
|
137
|
-
while (n && n !== this.editorEl) {
|
|
138
|
-
if (n instanceof HTMLAnchorElement) {
|
|
139
|
-
this.activeAnchor = n;
|
|
140
|
-
this.hasActiveLink = true;
|
|
141
|
-
break;
|
|
142
|
-
}
|
|
143
|
-
n = n.parentNode;
|
|
144
|
-
}
|
|
145
|
-
this.linkValue = this.activeAnchor
|
|
146
|
-
? this.displayUrl(this.activeAnchor.href)
|
|
147
|
-
: '';
|
|
148
|
-
this.positionPopover();
|
|
149
|
-
this.openPopover();
|
|
150
|
-
requestAnimationFrame(() => {
|
|
151
|
-
this.querySelector('.link-input')?.focus();
|
|
152
|
-
});
|
|
153
|
-
}
|
|
154
|
-
onInputKeydown(e) {
|
|
155
|
-
if (e.key !== 'Escape' && e.key !== 'Enter')
|
|
156
|
-
return;
|
|
157
|
-
e.preventDefault();
|
|
158
|
-
e.stopPropagation();
|
|
159
|
-
if (e.key === 'Escape') {
|
|
160
|
-
this.closePopover();
|
|
161
|
-
return;
|
|
162
|
-
}
|
|
163
|
-
this.isApplying = true;
|
|
164
|
-
try {
|
|
165
|
-
this.applyLink();
|
|
166
|
-
}
|
|
167
|
-
finally {
|
|
168
|
-
this.isApplying = false;
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
onInputBlur() {
|
|
172
|
-
if (this.ignoreBlur || this.isApplying)
|
|
173
|
-
return;
|
|
174
|
-
this.closePopover();
|
|
175
|
-
}
|
|
176
252
|
applyLink() {
|
|
177
253
|
if (!(this.selectionRange instanceof Range))
|
|
178
254
|
return;
|
|
179
255
|
let url = this.linkValue.trim();
|
|
180
256
|
if (!url)
|
|
181
257
|
return;
|
|
182
|
-
|
|
183
|
-
try {
|
|
184
|
-
parsed = new URL(url, window.location.href);
|
|
185
|
-
if (!['http:', 'https:', 'mailto:', 'tel:'].includes(parsed.protocol))
|
|
186
|
-
return;
|
|
187
|
-
}
|
|
188
|
-
catch {
|
|
258
|
+
if (/^javascript:/i.test(url))
|
|
189
259
|
return;
|
|
260
|
+
if (!/^(https?:\/\/|mailto:|tel:|\/)/i.test(url)) {
|
|
261
|
+
url = `https://${url}`;
|
|
190
262
|
}
|
|
191
|
-
url = parsed.href;
|
|
192
|
-
url = this.normalizeUrl(url);
|
|
193
263
|
this.editorEl.focus();
|
|
194
264
|
const sel = document.getSelection();
|
|
195
265
|
if (!sel)
|
|
196
266
|
return;
|
|
197
267
|
sel.removeAllRanges();
|
|
198
268
|
sel.addRange(this.selectionRange);
|
|
269
|
+
const displayText = this.showTextSupport && this.textValue.trim()
|
|
270
|
+
? this.textValue.trim()
|
|
271
|
+
: '';
|
|
199
272
|
if (this.activeAnchor) {
|
|
200
273
|
this.activeAnchor.href = url;
|
|
274
|
+
if (displayText) {
|
|
275
|
+
this.activeAnchor.textContent = displayText;
|
|
276
|
+
}
|
|
201
277
|
if (this.newTab) {
|
|
202
278
|
this.activeAnchor.target = '_blank';
|
|
203
279
|
this.activeAnchor.rel = 'noopener noreferrer';
|
|
@@ -218,7 +294,12 @@ let NileRteLink = class NileRteLink extends LitElement {
|
|
|
218
294
|
link.removeAttribute('target');
|
|
219
295
|
link.removeAttribute('rel');
|
|
220
296
|
}
|
|
221
|
-
if (
|
|
297
|
+
if (displayText) {
|
|
298
|
+
this.selectionRange.deleteContents();
|
|
299
|
+
link.textContent = displayText;
|
|
300
|
+
this.selectionRange.insertNode(link);
|
|
301
|
+
}
|
|
302
|
+
else if (this.selectionRange.collapsed) {
|
|
222
303
|
link.textContent = url;
|
|
223
304
|
this.selectionRange.insertNode(link);
|
|
224
305
|
}
|
|
@@ -251,57 +332,73 @@ let NileRteLink = class NileRteLink extends LitElement {
|
|
|
251
332
|
}));
|
|
252
333
|
}
|
|
253
334
|
render() {
|
|
335
|
+
const iconColor = this.disabled
|
|
336
|
+
? 'var(--nile-colors-neutral-500, var(--ng-colors-fg-disabled-subtle))'
|
|
337
|
+
: 'var(--nile-colors-dark-900, var(--ng-colors-text-primary-900))';
|
|
254
338
|
return html `
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
339
|
+
<nile-lite-tooltip content=${this.label}>
|
|
340
|
+
<nile-button
|
|
341
|
+
variant="tertiary"
|
|
342
|
+
size="small"
|
|
343
|
+
?disabled=${this.disabled}
|
|
344
|
+
@mousedown=${this.onToolbarButtonMousedown}
|
|
345
|
+
@click=${this.onOpen}
|
|
346
|
+
class="rte-link-button"
|
|
347
|
+
>
|
|
348
|
+
<nile-icon name="link_2" color=${iconColor}></nile-icon>
|
|
349
|
+
</nile-button>
|
|
350
|
+
</nile-lite-tooltip>
|
|
266
351
|
|
|
267
352
|
<nile-popover
|
|
268
353
|
class="rte-link-popover"
|
|
269
354
|
.arrow=${false}
|
|
270
355
|
style=${this.popoverStyle}
|
|
271
|
-
@mousedown=${
|
|
272
|
-
@mouseup=${
|
|
356
|
+
@mousedown=${this.onPopoverMousedown}
|
|
357
|
+
@mouseup=${this.onPopoverMouseup}
|
|
273
358
|
>
|
|
274
|
-
<div class="link-popup">
|
|
275
|
-
|
|
276
|
-
class="link-input"
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
359
|
+
<div class="link-popup-wrap">
|
|
360
|
+
${this.showTextSupport ? html `
|
|
361
|
+
<div class="link-input-row">
|
|
362
|
+
<nile-input
|
|
363
|
+
label="Text"
|
|
364
|
+
placeholder=${this.textPlaceholder}
|
|
365
|
+
.value=${this.textValue}
|
|
366
|
+
@nile-input=${this.onTextInput}
|
|
367
|
+
@keydown=${this.onInputKeydown}
|
|
368
|
+
@nile-blur=${this.onInputBlur}
|
|
369
|
+
></nile-input>
|
|
370
|
+
</div>
|
|
371
|
+
` : null}
|
|
372
|
+
<div class="link-actions-row">
|
|
373
|
+
<nile-input
|
|
374
|
+
label=${this.showTextSupport ? 'URL' : ''}
|
|
375
|
+
placeholder=${this.placeholder}
|
|
376
|
+
.value=${this.linkValue}
|
|
377
|
+
@nile-input=${this.onLinkInput}
|
|
378
|
+
@keydown=${this.onInputKeydown}
|
|
379
|
+
@nile-blur=${this.onInputBlur}
|
|
380
|
+
></nile-input>
|
|
381
|
+
${this.hasActiveLink ? html `
|
|
382
|
+
<nile-button
|
|
383
|
+
size="small"
|
|
384
|
+
variant="tertiary"
|
|
385
|
+
class="rte-edit-button"
|
|
386
|
+
@mousedown=${this.onActionMousedown}
|
|
387
|
+
@click=${this.onApplyClick}
|
|
388
|
+
>
|
|
389
|
+
<nile-icon name="pencil"></nile-icon>
|
|
390
|
+
</nile-button>
|
|
391
|
+
<nile-button
|
|
392
|
+
size="small"
|
|
393
|
+
variant="tertiary"
|
|
394
|
+
class="rte-edit-button"
|
|
395
|
+
@mousedown=${this.onActionMousedown}
|
|
396
|
+
@click=${this.onUnlinkClick}
|
|
397
|
+
>
|
|
398
|
+
<nile-icon name="unlink"></nile-icon>
|
|
399
|
+
</nile-button>
|
|
400
|
+
` : null}
|
|
401
|
+
</div>
|
|
305
402
|
</div>
|
|
306
403
|
</nile-popover>
|
|
307
404
|
`;
|
|
@@ -311,17 +408,29 @@ __decorate([
|
|
|
311
408
|
property({ attribute: false })
|
|
312
409
|
], NileRteLink.prototype, "editorEl", void 0);
|
|
313
410
|
__decorate([
|
|
314
|
-
property({ type: Boolean })
|
|
411
|
+
property({ type: Boolean, reflect: true, attribute: true })
|
|
315
412
|
], NileRteLink.prototype, "newTab", void 0);
|
|
316
413
|
__decorate([
|
|
317
|
-
property({ type:
|
|
414
|
+
property({ type: Boolean, reflect: true, attribute: true })
|
|
415
|
+
], NileRteLink.prototype, "disabled", void 0);
|
|
416
|
+
__decorate([
|
|
417
|
+
property({ type: Boolean, reflect: true, attribute: true })
|
|
418
|
+
], NileRteLink.prototype, "showTextSupport", void 0);
|
|
419
|
+
__decorate([
|
|
420
|
+
property({ type: String, reflect: true, attribute: true })
|
|
318
421
|
], NileRteLink.prototype, "placeholder", void 0);
|
|
319
422
|
__decorate([
|
|
320
|
-
property({ type: String })
|
|
423
|
+
property({ type: String, reflect: true, attribute: true })
|
|
424
|
+
], NileRteLink.prototype, "textPlaceholder", void 0);
|
|
425
|
+
__decorate([
|
|
426
|
+
property({ type: String, reflect: true, attribute: true })
|
|
321
427
|
], NileRteLink.prototype, "label", void 0);
|
|
322
428
|
__decorate([
|
|
323
429
|
state()
|
|
324
430
|
], NileRteLink.prototype, "linkValue", void 0);
|
|
431
|
+
__decorate([
|
|
432
|
+
state()
|
|
433
|
+
], NileRteLink.prototype, "textValue", void 0);
|
|
325
434
|
__decorate([
|
|
326
435
|
state()
|
|
327
436
|
], NileRteLink.prototype, "hasActiveLink", void 0);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nile-rte-link.js","sourceRoot":"","sources":["../../../src/nile-rich-text-editor/nile-rte-link.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,KAAK,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAG5D,IAAM,WAAW,GAAjB,MAAM,WAAY,SAAQ,UAAU;IAApC;;QAMwB,WAAM,GAAG,KAAK,CAAC;QAChB,gBAAW,GAAG,yBAAyB,CAAC;QACxC,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AC,CAAC,CAAC,cAAc,EAAE;iBACpC,GAAG,EAAE,CAAC,IAAI,CAAC,MAAM,EAAE;;;;;;;;;iBASnB,KAAK;gBACN,IAAI,CAAC,YAAY;qBACZ,GAAG,EAAE,CAAC,CAAC,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;mBAChC,GAAG,EAAE,CAAC,CAAC,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC;;;;;0BAKxB,IAAI,CAAC,WAAW;qBACrB,IAAI,CAAC,SAAS;qBACd,CAAC,CAAQ,EAAE,EAAE,CACpB,CAAC,IAAI,CAAC,SAAS,GAAI,CAAC,CAAC,MAA2B,CAAC,KAAK,CAAC;uBAC9C,IAAI,CAAC,cAAc;oBACtB,IAAI,CAAC,WAAW;;;YAGxB,IAAI,CAAC,aAAa;YAClB,CAAC,CAAC,IAAI,CAAA;;;;;2BAKS,GAAG,EAAE,CAAC,IAAI,CAAC,SAAS,EAAE;;;;;;;;;2BAStB,GAAG,EAAE,CAAC,IAAI,CAAC,QAAQ,EAAE;;;;eAIjC;YACH,CAAC,CAAC,IAAI;;;KAGb,CAAC;IACJ,CAAC;CACF,CAAA;AArViC;IAA/B,QAAQ,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;6CAAwB;AAC1B;IAA5B,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;2CAAgB;AAChB;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;gDAAyC;AACxC;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;0CAAgB;AAG1B;IAAhB,KAAK,EAAE;8CAAwB;AACf;IAAhB,KAAK,EAAE;kDAA+B;AACtB;IAAhB,KAAK,EAAE;iDAA2B;AAbxB,WAAW;IADvB,aAAa,CAAC,eAAe,CAAC;GAClB,WAAW,CA0VvB","sourcesContent":["import { LitElement, html } from 'lit';\nimport { customElement, property, state } from 'lit/decorators.js';\n\n@customElement('nile-rte-link')\nexport class NileRteLink extends LitElement {\n protected createRenderRoot() {\n return this;\n }\n\n @property({ attribute: false }) editorEl!: HTMLElement;\n @property({ type: Boolean }) newTab = false;\n @property({ type: String }) placeholder = 'Type or paste link here';\n @property({ type: String }) label = 'Link';\n\n\n @state() private linkValue = '';\n @state() private hasActiveLink = false;\n @state() private popoverStyle = '';\n\n private selectionRange: Range | null = null;\n private activeAnchor: HTMLAnchorElement | null = null;\n\n private ignoreBlur = false;\n private isApplying = false;\n\n \n\n connectedCallback() {\n super.connectedCallback();\n\n this.injectCss(`\n nile-popover.rte-link-popover::part(popover) {\n min-width: 316px;\n background: white;\n border: 1px solid var(--nile-colors-neutral-400,var(--ng-componentcolors-utility-gray-400));\n border-radius: 4px;\n padding: 0;\n gap: 0;\n }\n\n .link-popup {\n display: flex;\n align-items: center;\n gap: 8px;\n padding: 6px 8px;\n }\n\n .link-input {\n flex: 1;\n padding: 6px 8px;\n font-size: 14px;\n width: 276px;\n height: 14px;\n padding: 12px;\n border: 1px solid var(--nile-colors-primary-600, var(--ng-colors-border-brand));\n border-radius: 4px;\n }\n nile-button.rte-link-button::part(base) {\n border: none;\n height: 32px; \n width: 32px;\n }\n nile-button.rte-edit-button::part(base) {\n border: none;\n height: 38px; \n width: 38px;\n }\n `);\n }\n\n private injectCss(cssText: string) {\n if (this.querySelector('style[data-rte-link-style]')) return;\n const style = document.createElement('style');\n style.setAttribute('data-rte-link-style', 'true');\n style.textContent = cssText;\n this.insertBefore(style, this.firstChild);\n }\n\n \n\n private normalizeUrl(url: string) {\n if (/^(https?:|mailto:|tel:)/i.test(url)) return url;\n return `https://${url}`;\n }\n\n private displayUrl(url: string): string {\n return url.replace(/^https?:\\/\\//i, '');\n }\n\n private getSelectionRect(): DOMRect | null {\n if (!this.selectionRange) return null;\n\n let rect = this.selectionRange.getBoundingClientRect();\n if (rect.width === 0 && rect.height === 0) {\n const span = document.createElement('span');\n span.textContent = '\\u200b';\n const tempRange = this.selectionRange.cloneRange();\n tempRange.insertNode(span);\n rect = span.getBoundingClientRect();\n span.remove(); \n }\n return rect;\n }\n\n private positionPopover() {\n const rect = this.getSelectionRect();\n if (!rect) return;\n\n this.popoverStyle = `\n position: fixed;\n top: ${rect.bottom + 8}px;\n left: ${rect.left + rect.width / 2}px;\n transform: translateX(-50%);\n z-index: 1000;\n `;\n }\n\n private onScroll = () => {\n this.closePopover();\n };\n\n private openPopover() {\n requestAnimationFrame(() => {\n const pop = this.querySelector('nile-popover') as any;\n pop && (pop.isShow = true);\n window.addEventListener('scroll', this.onScroll, true);\n });\n }\n\n private closePopover() {\n const pop = this.querySelector('nile-popover') as any;\n pop && (pop.isShow = false);\n\n window.removeEventListener('scroll', this.onScroll, true);\n\n this.linkValue = '';\n this.selectionRange = null;\n this.activeAnchor = null;\n this.hasActiveLink = false;\n this.popoverStyle = '';\n }\n\n private unwrapLink(a: HTMLAnchorElement) {\n while (a.firstChild) a.parentNode?.insertBefore(a.firstChild, a);\n a.remove();\n }\n\n \n\n private onOpen() {\n const sel = document.getSelection();\n if (!sel || sel.rangeCount === 0) return;\n\n this.selectionRange = sel.getRangeAt(0).cloneRange();\n this.activeAnchor = null;\n this.hasActiveLink = false;\n\n let n: Node | null = this.selectionRange.startContainer;\n while (n && n !== this.editorEl) {\n if (n instanceof HTMLAnchorElement) {\n this.activeAnchor = n;\n this.hasActiveLink = true;\n break;\n }\n n = n.parentNode;\n }\n\n this.linkValue = this.activeAnchor\n ? this.displayUrl(this.activeAnchor.href)\n : '';\n\n this.positionPopover();\n this.openPopover();\n\n requestAnimationFrame(() => {\n this.querySelector<HTMLInputElement>('.link-input')?.focus();\n });\n }\n\n \n\n private onInputKeydown(e: KeyboardEvent) {\n if (e.key !== 'Escape' && e.key !== 'Enter') return;\n \n e.preventDefault();\n e.stopPropagation();\n \n if (e.key === 'Escape') {\n this.closePopover();\n return;\n }\n \n this.isApplying = true;\n try {\n this.applyLink();\n } finally {\n this.isApplying = false;\n }\n }\n \n\n private onInputBlur() {\n if (this.ignoreBlur || this.isApplying) return;\n this.closePopover();\n }\n\n \n\n private applyLink() {\n if (!(this.selectionRange instanceof Range)) return;\n\n let url = this.linkValue.trim();\n if (!url) return;\n \n let parsed: URL;\n try {\n parsed = new URL(url, window.location.href);\n if (!['http:', 'https:', 'mailto:', 'tel:'].includes(parsed.protocol)) return;\n } catch {\n return;\n }\n \n url = parsed.href;\n \n\n url = this.normalizeUrl(url);\n\n this.editorEl.focus();\n\n const sel = document.getSelection();\n if (!sel) return;\n\n sel.removeAllRanges();\n sel.addRange(this.selectionRange);\n\n if (this.activeAnchor) {\n this.activeAnchor.href = url;\n\n if (this.newTab) {\n this.activeAnchor.target = '_blank';\n this.activeAnchor.rel = 'noopener noreferrer';\n } else {\n this.activeAnchor.removeAttribute('target');\n this.activeAnchor.removeAttribute('rel');\n }\n \n } else {\n const link = document.createElement('a');\n link.href = url;\n \n if (this.newTab) {\n link.target = '_blank';\n link.rel = 'noopener noreferrer';\n } else {\n link.removeAttribute('target');\n link.removeAttribute('rel');\n } \n\n if (this.selectionRange.collapsed) {\n link.textContent = url;\n this.selectionRange.insertNode(link);\n } else {\n try {\n this.selectionRange.surroundContents(link);\n } catch {\n const frag = this.selectionRange.extractContents();\n link.appendChild(frag);\n this.selectionRange.insertNode(link);\n }\n }\n }\n\n this.emit(url);\n this.closePopover();\n }\n\n private onRemove() {\n if (!this.activeAnchor) return;\n this.unwrapLink(this.activeAnchor);\n this.emit('');\n this.closePopover();\n }\n\n private emit(href: string) {\n this.dispatchEvent(\n new CustomEvent('nile-link-changed', {\n detail: { href },\n bubbles: true,\n composed: true,\n })\n );\n }\n\n render() {\n return html`\n <nile-lite-tooltip content=${this.label}> \n <nile-button\n variant=\"tertiary\"\n size=\"small\"\n @mousedown=${(e: Event) => e.preventDefault()}\n @click=${() => this.onOpen()}\n class=\"rte-link-button\"\n >\n <nile-icon name=\"link_2\"></nile-icon>\n </nile-button>\n </nile-lite-tooltip>\n\n <nile-popover\n class=\"rte-link-popover\"\n .arrow=${false}\n style=${this.popoverStyle}\n @mousedown=${() => (this.ignoreBlur = true)}\n @mouseup=${() => (this.ignoreBlur = false)}\n >\n <div class=\"link-popup\">\n <input\n class=\"link-input\"\n placeholder=${this.placeholder}\n .value=${this.linkValue}\n @input=${(e: Event) =>\n (this.linkValue = (e.target as HTMLInputElement).value)}\n @keydown=${this.onInputKeydown}\n @blur=${this.onInputBlur}\n />\n\n ${this.hasActiveLink\n ? html`\n <nile-button\n size=\"small\"\n variant=\"tertiary\"\n class=\"rte-edit-button\"\n @click=${() => this.applyLink()}\n >\n <nile-icon name=\"pencil\"></nile-icon>\n </nile-button>\n\n <nile-button\n size=\"small\"\n variant=\"tertiary\"\n class=\"rte-edit-button\"\n @click=${() => this.onRemove()}\n >\n <nile-icon name=\"unlink\"></nile-icon>\n </nile-button>\n `\n : null}\n </div>\n </nile-popover>\n `;\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'nile-rte-link': NileRteLink;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"nile-rte-link.js","sourceRoot":"","sources":["../../../src/nile-rich-text-editor/nile-rte-link.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,KAAK,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAG5D,IAAM,WAAW,GAAjB,MAAM,WAAY,SAAQ,UAAU;IAApC;;QAMwD,WAAM,GAAG,KAAK,CAAC;QACf,aAAQ,GAAG,KAAK,CAAC;QACjB,oBAAe,GAAG,KAAK,CAAC;QACzB,gBAAW,GAAG,yBAAyB,CAAC;QACxC,oBAAe,GAAG,cAAc,CAAC;QACjC,UAAK,GAAG,MAAM,CAAC;QAE1D,cAAS,GAAG,EAAE,CAAC;QACf,cAAS,GAAG,EAAE,CAAC;QACf,kBAAa,GAAG,KAAK,CAAC;QACtB,iBAAY,GAAG,EAAE,CAAC;QA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I,EAAE,CAAC;oDAAyB;AACzB;IAA3D,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;gDAAyC;AACxC;IAA3D,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;oDAAkC;AACjC;IAA3D,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;0CAAgB;AAE1D;IAAhB,KAAK,EAAE;8CAAwB;AACf;IAAhB,KAAK,EAAE;8CAAwB;AACf;IAAhB,KAAK,EAAE;kDAA+B;AACtB;IAAhB,KAAK,EAAE;iDAA2B;AAhBxB,WAAW;IADvB,aAAa,CAAC,eAAe,CAAC;GAClB,WAAW,CAybvB","sourcesContent":["import { LitElement, html } from 'lit';\nimport { customElement, property, state } from 'lit/decorators.js';\n\n@customElement('nile-rte-link')\nexport class NileRteLink extends LitElement {\n protected createRenderRoot() {\n return this;\n }\n\n @property({ attribute: false }) editorEl!: HTMLElement;\n @property({ type: Boolean, reflect: true, attribute: true }) newTab = false;\n @property({ type: Boolean, reflect: true, attribute: true }) disabled = false;\n @property({ type: Boolean, reflect: true, attribute: true }) showTextSupport = false;\n @property({ type: String, reflect: true, attribute: true }) placeholder = 'Type or paste link here';\n @property({ type: String, reflect: true, attribute: true }) textPlaceholder = 'Display text';\n @property({ type: String, reflect: true, attribute: true }) label = 'Link';\n\n @state() private linkValue = '';\n @state() private textValue = '';\n @state() private hasActiveLink = false;\n @state() private popoverStyle = '';\n\n private selectionRange: Range | null = null;\n private activeAnchor: HTMLAnchorElement | null = null;\n\n private ignoreBlur = false;\n private isApplying = false;\n\n \n\n connectedCallback() {\n super.connectedCallback();\n\n this.injectCss(`\n nile-popover.rte-link-popover::part(popover) {\n min-width: 340px;\n max-width: 420px;\n background: white;\n border: 1px solid var(--nile-colors-neutral-400, var(--ng-componentcolors-utility-gray-400));\n border-radius: 8px;\n padding: 0;\n gap: 0;\n overflow: hidden;\n height: auto;\n box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);\n }\n\n .link-popup-wrap {\n display: flex;\n flex-direction: column;\n gap: 12px;\n padding: 12px;\n }\n\n .link-popup-wrap nile-input {\n width: 100%;\n }\n\n .link-popup-wrap .link-input-row {\n width: 100%;\n }\n\n .link-popup-wrap .link-actions-row {\n display: flex;\n align-items: flex-end;\n gap: 4px;\n width: 100%;\n }\n\n .link-popup-wrap .link-actions-row nile-input {\n flex: 1;\n min-width: 0;\n }\n\n \n nile-button.rte-link-button::part(base) {\n border: none;\n height: 32px;\n width: 32px;\n }\n nile-button.rte-edit-button::part(base) {\n border: none;\n height: 32px;\n width: 32px;\n flex-shrink: 0;\n }\n `);\n }\n\n private injectCss(cssText: string) {\n if (this.querySelector('style[data-rte-link-style]')) return;\n const style = document.createElement('style');\n style.setAttribute('data-rte-link-style', 'true');\n style.textContent = cssText;\n this.insertBefore(style, this.firstChild);\n }\n\n \n\n private normalizeUrl(url: string) {\n if (/^(https?:|mailto:|tel:)/i.test(url)) return url;\n return `https://${url}`;\n }\n\n private displayUrl(url: string): string {\n return url;\n }\n\n private getSelectionRect(): DOMRect | null {\n if (!this.selectionRange) return null;\n\n let rect = this.selectionRange.getBoundingClientRect();\n if (rect.width === 0 && rect.height === 0) {\n const span = document.createElement('span');\n span.textContent = '\\u200b';\n const tempRange = this.selectionRange.cloneRange();\n tempRange.insertNode(span);\n rect = span.getBoundingClientRect();\n span.remove(); \n }\n return rect;\n }\n\n private positionPopover() {\n const rect = this.getSelectionRect();\n if (!rect) return;\n\n this.popoverStyle = `\n position: fixed;\n top: ${rect.bottom + 8}px;\n left: ${rect.left + rect.width / 2}px;\n transform: translateX(-50%);\n z-index: 1000;\n `;\n }\n\n private onScroll = () => {\n this.closePopover();\n };\n\n private openPopover() {\n requestAnimationFrame(() => {\n const pop = this.querySelector('nile-popover') as any;\n pop && (pop.isShow = true);\n window.addEventListener('scroll', this.onScroll, true);\n });\n }\n\n private closePopover() {\n const pop = this.querySelector('nile-popover') as any;\n pop && (pop.isShow = false);\n\n window.removeEventListener('scroll', this.onScroll, true);\n\n this.linkValue = '';\n this.textValue = '';\n this.selectionRange = null;\n this.activeAnchor = null;\n this.hasActiveLink = false;\n this.popoverStyle = '';\n }\n\n private unwrapLink(a: HTMLAnchorElement) {\n while (a.firstChild) a.parentNode?.insertBefore(a.firstChild, a);\n a.remove();\n }\n\n \n\n private onOpen = () => {\n if (this.disabled) return;\n\n const sel = document.getSelection();\n if (!sel || sel.rangeCount === 0) return;\n if (!this.editorEl.contains(sel.getRangeAt(0).commonAncestorContainer)) return;\n\n this.selectionRange = sel.getRangeAt(0).cloneRange();\n this.activeAnchor = null;\n this.hasActiveLink = false;\n\n let n: Node | null = this.selectionRange.startContainer;\n while (n && n !== this.editorEl) {\n if (n instanceof HTMLAnchorElement) {\n this.activeAnchor = n;\n this.hasActiveLink = true;\n break;\n }\n n = n.parentNode;\n }\n\n this.linkValue = this.activeAnchor\n ? this.displayUrl(this.activeAnchor.href)\n : '';\n\n if (this.showTextSupport) {\n if (this.activeAnchor) {\n this.textValue = this.activeAnchor.textContent || '';\n } else if (!this.selectionRange.collapsed) {\n this.textValue = this.selectionRange.toString();\n } else {\n this.textValue = '';\n }\n }\n\n this.positionPopover();\n this.openPopover();\n\n requestAnimationFrame(() => {\n const inputs = this.querySelectorAll('nile-input');\n const target = inputs.length > 1 ? inputs[1] : inputs[0];\n (target as any)?.focus();\n });\n }\n\n \n\n private onInputKeydown = (e: KeyboardEvent) => {\n if (e.key !== 'Escape' && e.key !== 'Enter') return;\n e.preventDefault();\n e.stopPropagation();\n if (e.key === 'Escape') {\n this.closePopover();\n return;\n }\n this.isApplying = true;\n try {\n this.applyLink();\n } finally {\n this.isApplying = false;\n }\n };\n private onInputBlur = () => {\n if (this.ignoreBlur || this.isApplying) return;\n requestAnimationFrame(() => {\n if (this.ignoreBlur || this.isApplying) return;\n const pop = this.querySelector('nile-popover');\n if (pop?.matches(':focus-within')) return;\n this.closePopover();\n });\n };\n\n private onLinkInput = (e: CustomEvent) => {\n this.linkValue = e.detail.value;\n };\n\n private onTextInput = (e: CustomEvent) => {\n this.textValue = e.detail.value;\n };\n\n private onPopoverMousedown = () => {\n this.ignoreBlur = true;\n };\n\n private onPopoverMouseup = () => {\n this.ignoreBlur = false;\n };\n\n private onToolbarButtonMousedown = (e: Event) => {\n e.preventDefault();\n };\n\n private onActionMousedown = (e: Event) => {\n e.preventDefault();\n this.ignoreBlur = true;\n };\n\n private onApplyClick = () => {\n this.isApplying = true;\n this.applyLink();\n this.isApplying = false;\n this.ignoreBlur = false;\n };\n\n private onUnlinkClick = () => {\n this.isApplying = true;\n this.onRemove();\n this.isApplying = false;\n this.ignoreBlur = false;\n };\n\n \n\n private applyLink() {\n if (!(this.selectionRange instanceof Range)) return;\n\n let url = this.linkValue.trim();\n if (!url) return;\n\n if (/^javascript:/i.test(url)) return;\n\n if (!/^(https?:\\/\\/|mailto:|tel:|\\/)/i.test(url)) {\n url = `https://${url}`;\n }\n\n this.editorEl.focus();\n\n const sel = document.getSelection();\n if (!sel) return;\n\n sel.removeAllRanges();\n sel.addRange(this.selectionRange);\n\n const displayText = this.showTextSupport && this.textValue.trim()\n ? this.textValue.trim()\n : '';\n\n if (this.activeAnchor) {\n this.activeAnchor.href = url;\n\n if (displayText) {\n this.activeAnchor.textContent = displayText;\n }\n\n if (this.newTab) {\n this.activeAnchor.target = '_blank';\n this.activeAnchor.rel = 'noopener noreferrer';\n } else {\n this.activeAnchor.removeAttribute('target');\n this.activeAnchor.removeAttribute('rel');\n }\n \n } else {\n const link = document.createElement('a');\n link.href = url;\n \n if (this.newTab) {\n link.target = '_blank';\n link.rel = 'noopener noreferrer';\n } else {\n link.removeAttribute('target');\n link.removeAttribute('rel');\n } \n\n if (displayText) {\n this.selectionRange.deleteContents();\n link.textContent = displayText;\n this.selectionRange.insertNode(link);\n } else if (this.selectionRange.collapsed) {\n link.textContent = url;\n this.selectionRange.insertNode(link);\n } else {\n try {\n this.selectionRange.surroundContents(link);\n } catch {\n const frag = this.selectionRange.extractContents();\n link.appendChild(frag);\n this.selectionRange.insertNode(link);\n }\n }\n }\n\n this.emit(url);\n this.closePopover();\n }\n\n private onRemove() {\n if (!this.activeAnchor) return;\n this.unwrapLink(this.activeAnchor);\n this.emit('');\n this.closePopover();\n }\n\n private emit(href: string) {\n this.dispatchEvent(\n new CustomEvent('nile-link-changed', {\n detail: { href },\n bubbles: true,\n composed: true,\n })\n );\n }\n\n render() {\n const iconColor = this.disabled\n ? 'var(--nile-colors-neutral-500, var(--ng-colors-fg-disabled-subtle))'\n : 'var(--nile-colors-dark-900, var(--ng-colors-text-primary-900))';\n\n return html`\n <nile-lite-tooltip content=${this.label}>\n <nile-button\n variant=\"tertiary\"\n size=\"small\"\n ?disabled=${this.disabled}\n @mousedown=${this.onToolbarButtonMousedown}\n @click=${this.onOpen}\n class=\"rte-link-button\"\n >\n <nile-icon name=\"link_2\" color=${iconColor}></nile-icon>\n </nile-button>\n </nile-lite-tooltip>\n\n <nile-popover\n class=\"rte-link-popover\"\n .arrow=${false}\n style=${this.popoverStyle}\n @mousedown=${this.onPopoverMousedown}\n @mouseup=${this.onPopoverMouseup}\n >\n <div class=\"link-popup-wrap\">\n ${this.showTextSupport ? html`\n <div class=\"link-input-row\">\n <nile-input\n label=\"Text\"\n placeholder=${this.textPlaceholder}\n .value=${this.textValue}\n @nile-input=${this.onTextInput}\n @keydown=${this.onInputKeydown}\n @nile-blur=${this.onInputBlur}\n ></nile-input>\n </div>\n ` : null}\n <div class=\"link-actions-row\">\n <nile-input\n label=${this.showTextSupport ? 'URL' : ''}\n placeholder=${this.placeholder}\n .value=${this.linkValue}\n @nile-input=${this.onLinkInput}\n @keydown=${this.onInputKeydown}\n @nile-blur=${this.onInputBlur}\n ></nile-input>\n ${this.hasActiveLink ? html`\n <nile-button\n size=\"small\"\n variant=\"tertiary\"\n class=\"rte-edit-button\"\n @mousedown=${this.onActionMousedown}\n @click=${this.onApplyClick}\n >\n <nile-icon name=\"pencil\"></nile-icon>\n </nile-button>\n <nile-button\n size=\"small\"\n variant=\"tertiary\"\n class=\"rte-edit-button\"\n @mousedown=${this.onActionMousedown}\n @click=${this.onUnlinkClick}\n >\n <nile-icon name=\"unlink\"></nile-icon>\n </nile-button>\n ` : null}\n </div>\n </div>\n </nile-popover>\n `;\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'nile-rte-link': NileRteLink;\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import './nile-rte-link';
|