@aquera/nile-elements 0.1.67-beta-2.0 → 0.1.67-beta-2.2
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/demo/index.html +18 -0
- package/dist/index.js +11 -5
- 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 +10 -4
- package/dist/nile-rich-text-editor/nile-rich-text-editor.esm.js +1 -1
- package/dist/src/nile-rich-text-editor/nile-rich-text-editor.css.js +10 -4
- 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 +2 -0
- package/dist/src/nile-rich-text-editor/nile-rich-text-editor.js +34 -0
- package/dist/src/nile-rich-text-editor/nile-rich-text-editor.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/nile-rich-text-editor/nile-rich-text-editor.css.ts +10 -4
- package/src/nile-rich-text-editor/nile-rich-text-editor.ts +42 -0
package/package.json
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
"description": "Webcomponent nile-elements following open-wc recommendations",
|
4
4
|
"license": "MIT",
|
5
5
|
"author": "nile-elements",
|
6
|
-
"version": "0.1.67-beta-2.
|
6
|
+
"version": "0.1.67-beta-2.2",
|
7
7
|
"main": "dist/src/index.js",
|
8
8
|
"type": "module",
|
9
9
|
"module": "dist/src/index.js",
|
@@ -3,6 +3,8 @@ import { css } from 'lit';
|
|
3
3
|
|
4
4
|
export const styles = css`
|
5
5
|
|
6
|
+
|
7
|
+
.editor {all: revert;}
|
6
8
|
|
7
9
|
nile-rich-text-editor { position: relative; display: block; font-family: inherit; }
|
8
10
|
|
@@ -21,6 +23,8 @@ nile-rte-preview {
|
|
21
23
|
|
22
24
|
|
23
25
|
.toolbar, nile-rte-toolbar {
|
26
|
+
|
27
|
+
width:486px;
|
24
28
|
display:flex; align-items:center; gap:6px; padding:8px;
|
25
29
|
border:1px solid #e5e7eb; border-bottom:none; border-radius:8px 8px 0 0; background:#fff;
|
26
30
|
}
|
@@ -40,7 +44,7 @@ nile-rte-preview {
|
|
40
44
|
nile-rte-divider { width:1px; height:20px; background:#e5e7eb; display:inline-block; margin:0 4px; }
|
41
45
|
|
42
46
|
.editor p { margin:1em 0; }
|
43
|
-
.editor h1, .preview h1 { font-size:2em,
|
47
|
+
.editor h1, .preview h1 { all: revert; font-size:2em, display: block;
|
44
48
|
font-size: 2em;
|
45
49
|
margin-top: 0.67em;
|
46
50
|
margin-bottom: 0.67em;
|
@@ -59,10 +63,12 @@ font-weight: bold;}
|
|
59
63
|
.editor h5 { font-size:0.83em }
|
60
64
|
.editor h6 { font-size:0.67em }
|
61
65
|
|
62
|
-
.editor {
|
66
|
+
.editor { min-height:160px; max-width:478px; padding:12px; border:1px solid #e5e7eb; border-radius:0 0 8px 8px; background:#fff; outline:none;
|
63
67
|
tab-size: 4;
|
64
|
-
-moz-tab-size: 4;
|
65
|
-
|
68
|
+
-moz-tab-size: 4;
|
69
|
+
word-break: break-word;
|
70
|
+
}
|
71
|
+
nile-rte-preview { display:block; margin-top:10px; padding:10px; border:1px dashed #cbd5e1; border-radius:8px; background:#fafafa; max-width:478px; }
|
66
72
|
|
67
73
|
.rte-color-trigger {
|
68
74
|
display: inline-flex;
|
@@ -196,10 +196,52 @@ private bgSwatchEl: HTMLElement | null = null;
|
|
196
196
|
}
|
197
197
|
this.ensureAtLeastOneParagraph();
|
198
198
|
}
|
199
|
+
|
200
|
+
|
201
|
+
private unwrapMention(span: HTMLElement, preserveText = true) {
|
202
|
+
const parent = span.parentNode;
|
203
|
+
if (!parent) return;
|
204
|
+
|
205
|
+
const txt = preserveText ? (span.textContent ?? '').replace(/\u200B/g, '') : '';
|
206
|
+
const textNode = document.createTextNode(txt);
|
207
|
+
parent.insertBefore(textNode, span);
|
208
|
+
parent.removeChild(span);
|
209
|
+
const r = document.createRange();
|
210
|
+
r.setStartAfter(textNode);
|
211
|
+
r.collapse(true);
|
212
|
+
const sel = window.getSelection();
|
213
|
+
sel?.removeAllRanges();
|
214
|
+
sel?.addRange(r);
|
215
|
+
}
|
216
|
+
|
217
|
+
private scrubBrokenMentions() {
|
218
|
+
if (!this.editorEl) return;
|
219
|
+
const mentions = this.editorEl.querySelectorAll('span.mention');
|
220
|
+
|
221
|
+
mentions.forEach((m) => {
|
222
|
+
const span = m as HTMLElement;
|
223
|
+
const key = span.getAttribute('data-mention-key');
|
224
|
+
const label = span.getAttribute('data-mention-label');
|
225
|
+
const trigger = span.getAttribute('data-mention-trigger') || '';
|
226
|
+
const text = (span.textContent ?? '').replace(/\u200B/g, '').trim();
|
227
|
+
|
228
|
+
|
229
|
+
const looksValid = !!key && !!label && text.length > 0 &&
|
230
|
+
text.startsWith(trigger) && text.includes(label);
|
231
|
+
|
232
|
+
|
233
|
+
if (!text || !looksValid) {
|
234
|
+
this.unwrapMention(span, true);
|
235
|
+
return;
|
236
|
+
}
|
237
|
+
});
|
238
|
+
}
|
199
239
|
|
240
|
+
|
200
241
|
private wireEditor() {
|
201
242
|
this.editorEl.addEventListener('input', () => {
|
202
243
|
this.ensureAtLeastOneParagraph();
|
244
|
+
this.scrubBrokenMentions();
|
203
245
|
this.updateContent();
|
204
246
|
});
|
205
247
|
this.editorEl.addEventListener('mouseup', () => this.saveSelection());
|