@rcarls/rc-textarea 0.1.0 → 0.3.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 +173 -1176
- package/dist/custom-elements.json +168 -72
- package/dist/{line-actions-controller-BsM6DJ0b.js → line-actions-controller-ChmbiQ-G.js} +573 -532
- package/dist/line-actions-controller-ChmbiQ-G.js.map +1 -0
- package/dist/rc-textarea-define.js +2 -2
- package/dist/rc-textarea.js +1 -1
- package/dist/types/packages/rc-textarea/src/blots.d.ts +7 -7
- package/dist/types/packages/rc-textarea/src/decoration.d.ts +5 -2
- package/dist/types/packages/rc-textarea/src/document.d.ts +7 -9
- package/dist/types/packages/rc-textarea/src/line-actions-controller.d.ts +12 -9
- package/dist/types/packages/rc-textarea/src/line-decorator.d.ts +9 -8
- package/dist/types/packages/rc-textarea/src/pattern-matcher.d.ts +4 -2
- package/dist/types/packages/rc-textarea/src/rc-textarea.d.ts +101 -32
- package/dist/types/packages/rc-textarea/src/selection.d.ts +17 -13
- package/dist/types/packages/rc-textarea/src/test-helpers.d.ts +6 -4
- package/dist/types/packages/rc-textarea/src/types.d.ts +119 -40
- package/package.json +7 -8
- package/dist/demo.css +0 -85
- package/dist/demo.js +0 -40
- package/dist/line-actions-controller-BsM6DJ0b.js.map +0 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { css as
|
|
2
|
-
import { property as
|
|
3
|
-
|
|
1
|
+
import { css as Ot, LitElement as st, html as Tt } from "lit";
|
|
2
|
+
import { property as y, query as tt } from "lit/decorators.js";
|
|
3
|
+
import { NativeChildController as kt } from "@rcarls/rc-common";
|
|
4
|
+
const Bt = Ot`
|
|
4
5
|
:host {
|
|
5
6
|
display: block;
|
|
6
7
|
box-sizing: border-box;
|
|
@@ -11,8 +12,6 @@ const Tt = St`
|
|
|
11
12
|
display: none;
|
|
12
13
|
}
|
|
13
14
|
|
|
14
|
-
/* ── Root layout ──────────────────────────────────────────────────────── */
|
|
15
|
-
|
|
16
15
|
#root {
|
|
17
16
|
display: flex;
|
|
18
17
|
align-items: stretch;
|
|
@@ -24,8 +23,6 @@ const Tt = St`
|
|
|
24
23
|
min-height: var(--_rc-textarea-min-height, auto);
|
|
25
24
|
}
|
|
26
25
|
|
|
27
|
-
/* ── Gutter ───────────────────────────────────────────────────────────── */
|
|
28
|
-
|
|
29
26
|
#gutter {
|
|
30
27
|
display: none;
|
|
31
28
|
flex-shrink: 0;
|
|
@@ -61,8 +58,6 @@ const Tt = St`
|
|
|
61
58
|
color: var(--rc-textarea-color, var(--rc-text, FieldText));
|
|
62
59
|
}
|
|
63
60
|
|
|
64
|
-
/* ── Editor area ──────────────────────────────────────────────────────── */
|
|
65
|
-
|
|
66
61
|
#editor-area {
|
|
67
62
|
position: relative;
|
|
68
63
|
flex: 1;
|
|
@@ -81,10 +76,7 @@ const Tt = St`
|
|
|
81
76
|
font-size: var(--rc-textarea-font-size, 1em);
|
|
82
77
|
line-height: var(--rc-textarea-line-height, 1.5);
|
|
83
78
|
color: var(--rc-textarea-color, var(--rc-text, FieldText));
|
|
84
|
-
caret-color: var(
|
|
85
|
-
--rc-textarea-caret-color,
|
|
86
|
-
var(--rc-textarea-color, FieldText)
|
|
87
|
-
);
|
|
79
|
+
caret-color: var(--rc-textarea-caret-color, var(--rc-textarea-color, FieldText));
|
|
88
80
|
background: transparent;
|
|
89
81
|
outline: none;
|
|
90
82
|
overflow: auto;
|
|
@@ -131,12 +123,8 @@ const Tt = St`
|
|
|
131
123
|
outline-offset: -1px;
|
|
132
124
|
}
|
|
133
125
|
|
|
134
|
-
/*
|
|
135
|
-
|
|
126
|
+
/* Slotted textarea is hidden on host upgrade */
|
|
136
127
|
::slotted(textarea) {
|
|
137
|
-
/* Visually hidden but accessible to form submission.
|
|
138
|
-
Inline styles applied via JS take precedence and are more reliable,
|
|
139
|
-
but this provides a baseline in case of timing issues. */
|
|
140
128
|
position: absolute !important;
|
|
141
129
|
width: 1px !important;
|
|
142
130
|
height: 1px !important;
|
|
@@ -149,23 +137,18 @@ const Tt = St`
|
|
|
149
137
|
pointer-events: none !important;
|
|
150
138
|
}
|
|
151
139
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
.v2-line {
|
|
140
|
+
.line {
|
|
155
141
|
position: relative;
|
|
156
142
|
display: block;
|
|
157
143
|
}
|
|
158
144
|
|
|
159
145
|
/* Active line highlight — opt-in via CSS custom property. */
|
|
160
|
-
.
|
|
146
|
+
.line--active {
|
|
161
147
|
background: var(--rc-textarea-active-line-bg, transparent);
|
|
162
148
|
}
|
|
163
149
|
|
|
164
|
-
/* Error-lens style end-of-line message
|
|
165
|
-
|
|
166
|
-
Using ::after keeps the annotation completely outside the DOM selection
|
|
167
|
-
and clipboard path — no user-select tricks needed. */
|
|
168
|
-
.v2-line[data-message]::after {
|
|
150
|
+
/* Error-lens -style end-of-line diagnostic message */
|
|
151
|
+
.line[data-message]::after {
|
|
169
152
|
content: attr(data-message);
|
|
170
153
|
display: inline;
|
|
171
154
|
margin-left: 4ch;
|
|
@@ -176,34 +159,26 @@ const Tt = St`
|
|
|
176
159
|
font-style: italic;
|
|
177
160
|
}
|
|
178
161
|
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
.v2-mark {
|
|
182
|
-
/* Base class; formatting applied via inline style by V2InlineBlot */
|
|
162
|
+
.mark {
|
|
183
163
|
border-radius: 2px;
|
|
184
164
|
}
|
|
185
165
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
.v2-widget {
|
|
166
|
+
.widget {
|
|
189
167
|
display: inline-block;
|
|
190
168
|
user-select: none;
|
|
191
169
|
cursor: default;
|
|
192
170
|
vertical-align: middle;
|
|
193
171
|
}
|
|
194
|
-
|
|
195
|
-
/* ── Scrollbar sync between editor and gutter ─────────────────────────── */
|
|
196
|
-
/* Gutter doesn't scroll independently; editor scroll is handled in JS */
|
|
197
172
|
`;
|
|
198
|
-
var
|
|
173
|
+
var d = /* @__PURE__ */ ((n) => (n[n.TYPE = 3] = "TYPE", n[n.LEVEL = 12] = "LEVEL", n[n.ATTRIBUTE = 13] = "ATTRIBUTE", n[n.BLOT = 14] = "BLOT", n[n.INLINE = 7] = "INLINE", n[n.BLOCK = 11] = "BLOCK", n[n.BLOCK_BLOT = 10] = "BLOCK_BLOT", n[n.INLINE_BLOT = 6] = "INLINE_BLOT", n[n.BLOCK_ATTRIBUTE = 9] = "BLOCK_ATTRIBUTE", n[n.INLINE_ATTRIBUTE = 5] = "INLINE_ATTRIBUTE", n[n.ANY = 15] = "ANY", n))(d || {});
|
|
199
174
|
class T {
|
|
200
175
|
constructor(t, e, s = {}) {
|
|
201
176
|
this.attrName = t, this.keyName = e;
|
|
202
|
-
const i =
|
|
177
|
+
const i = d.TYPE & d.ATTRIBUTE;
|
|
203
178
|
this.scope = s.scope != null ? (
|
|
204
179
|
// Ignore type bits, force attribute bit
|
|
205
|
-
s.scope &
|
|
206
|
-
) :
|
|
180
|
+
s.scope & d.LEVEL | i
|
|
181
|
+
) : d.ATTRIBUTE, s.whitelist != null && (this.whitelist = s.whitelist);
|
|
207
182
|
}
|
|
208
183
|
static keys(t) {
|
|
209
184
|
return Array.from(t.attributes).map((e) => e.name);
|
|
@@ -222,12 +197,12 @@ class T {
|
|
|
222
197
|
return this.canAdd(t, e) && e ? e : "";
|
|
223
198
|
}
|
|
224
199
|
}
|
|
225
|
-
class
|
|
200
|
+
class L extends Error {
|
|
226
201
|
constructor(t) {
|
|
227
202
|
t = "[Parchment] " + t, super(t), this.message = t, this.name = this.constructor.name;
|
|
228
203
|
}
|
|
229
204
|
}
|
|
230
|
-
const
|
|
205
|
+
const ut = class X {
|
|
231
206
|
constructor() {
|
|
232
207
|
this.attributes = {}, this.classes = {}, this.tags = {}, this.types = {};
|
|
233
208
|
}
|
|
@@ -250,27 +225,27 @@ const ht = class j {
|
|
|
250
225
|
create(t, e, s) {
|
|
251
226
|
const i = this.query(e);
|
|
252
227
|
if (i == null)
|
|
253
|
-
throw new
|
|
228
|
+
throw new L(`Unable to create ${e} blot`);
|
|
254
229
|
const r = i, o = (
|
|
255
230
|
// @ts-expect-error Fix me later
|
|
256
231
|
e instanceof Node || e.nodeType === Node.TEXT_NODE ? e : r.create(s)
|
|
257
232
|
), a = new r(t, o, s);
|
|
258
|
-
return
|
|
233
|
+
return X.blots.set(a.domNode, a), a;
|
|
259
234
|
}
|
|
260
235
|
find(t, e = !1) {
|
|
261
|
-
return
|
|
236
|
+
return X.find(t, e);
|
|
262
237
|
}
|
|
263
|
-
query(t, e =
|
|
238
|
+
query(t, e = d.ANY) {
|
|
264
239
|
let s;
|
|
265
|
-
return typeof t == "string" ? s = this.types[t] || this.attributes[t] : t instanceof Text || t.nodeType === Node.TEXT_NODE ? s = this.types.text : typeof t == "number" ? t &
|
|
240
|
+
return typeof t == "string" ? s = this.types[t] || this.attributes[t] : t instanceof Text || t.nodeType === Node.TEXT_NODE ? s = this.types.text : typeof t == "number" ? t & d.LEVEL & d.BLOCK ? s = this.types.block : t & d.LEVEL & d.INLINE && (s = this.types.inline) : t instanceof Element && ((t.getAttribute("class") || "").split(/\s+/).some((i) => (s = this.classes[i], !!s)), s = s || this.tags[t.tagName]), s == null ? null : "scope" in s && e & d.LEVEL & s.scope && e & d.TYPE & s.scope ? s : null;
|
|
266
241
|
}
|
|
267
242
|
register(...t) {
|
|
268
243
|
return t.map((e) => {
|
|
269
244
|
const s = "blotName" in e, i = "attrName" in e;
|
|
270
245
|
if (!s && !i)
|
|
271
|
-
throw new
|
|
246
|
+
throw new L("Invalid definition");
|
|
272
247
|
if (s && e.blotName === "abstract")
|
|
273
|
-
throw new
|
|
248
|
+
throw new L("Cannot register abstract class");
|
|
274
249
|
const r = s ? e.blotName : i ? e.attrName : void 0;
|
|
275
250
|
return this.types[r] = e, i ? typeof e.keyName == "string" && (this.attributes[e.keyName] = e) : s && (e.className && (this.classes[e.className] = e), e.tagName && (Array.isArray(e.tagName) ? e.tagName = e.tagName.map((o) => o.toUpperCase()) : e.tagName = e.tagName.toUpperCase(), (Array.isArray(e.tagName) ? e.tagName : [e.tagName]).forEach((o) => {
|
|
276
251
|
(this.tags[o] == null || e.className == null) && (this.tags[o] = e);
|
|
@@ -278,12 +253,12 @@ const ht = class j {
|
|
|
278
253
|
});
|
|
279
254
|
}
|
|
280
255
|
};
|
|
281
|
-
|
|
282
|
-
let
|
|
283
|
-
function
|
|
256
|
+
ut.blots = /* @__PURE__ */ new WeakMap();
|
|
257
|
+
let M = ut;
|
|
258
|
+
function it(n, t) {
|
|
284
259
|
return (n.getAttribute("class") || "").split(/\s+/).filter((e) => e.indexOf(`${t}-`) === 0);
|
|
285
260
|
}
|
|
286
|
-
class
|
|
261
|
+
class Dt extends T {
|
|
287
262
|
static keys(t) {
|
|
288
263
|
return (t.getAttribute("class") || "").split(/\s+/).map((e) => e.split("-").slice(0, -1).join("-"));
|
|
289
264
|
}
|
|
@@ -291,21 +266,21 @@ class kt extends T {
|
|
|
291
266
|
return this.canAdd(t, e) ? (this.remove(t), t.classList.add(`${this.keyName}-${e}`), !0) : !1;
|
|
292
267
|
}
|
|
293
268
|
remove(t) {
|
|
294
|
-
|
|
269
|
+
it(t, this.keyName).forEach((e) => {
|
|
295
270
|
t.classList.remove(e);
|
|
296
271
|
}), t.classList.length === 0 && t.removeAttribute("class");
|
|
297
272
|
}
|
|
298
273
|
value(t) {
|
|
299
|
-
const e = (
|
|
274
|
+
const e = (it(t, this.keyName)[0] || "").slice(this.keyName.length + 1);
|
|
300
275
|
return this.canAdd(t, e) ? e : "";
|
|
301
276
|
}
|
|
302
277
|
}
|
|
303
|
-
const
|
|
278
|
+
const It = Dt;
|
|
304
279
|
function F(n) {
|
|
305
280
|
const t = n.split("-"), e = t.slice(1).map((s) => s[0].toUpperCase() + s.slice(1)).join("");
|
|
306
281
|
return t[0] + e;
|
|
307
282
|
}
|
|
308
|
-
class
|
|
283
|
+
class $t extends T {
|
|
309
284
|
static keys(t) {
|
|
310
285
|
return (t.getAttribute("style") || "").split(";").map((e) => e.split(":")[0].trim());
|
|
311
286
|
}
|
|
@@ -320,8 +295,8 @@ class Dt extends T {
|
|
|
320
295
|
return this.canAdd(t, e) ? e : "";
|
|
321
296
|
}
|
|
322
297
|
}
|
|
323
|
-
const
|
|
324
|
-
class
|
|
298
|
+
const Rt = $t;
|
|
299
|
+
class Pt {
|
|
325
300
|
constructor(t) {
|
|
326
301
|
this.attributes = {}, this.domNode = t, this.build();
|
|
327
302
|
}
|
|
@@ -330,12 +305,12 @@ class Rt {
|
|
|
330
305
|
}
|
|
331
306
|
build() {
|
|
332
307
|
this.attributes = {};
|
|
333
|
-
const t =
|
|
308
|
+
const t = M.find(this.domNode);
|
|
334
309
|
if (t == null)
|
|
335
310
|
return;
|
|
336
|
-
const e = T.keys(this.domNode), s =
|
|
311
|
+
const e = T.keys(this.domNode), s = It.keys(this.domNode), i = Rt.keys(this.domNode);
|
|
337
312
|
e.concat(s).concat(i).forEach((r) => {
|
|
338
|
-
const o = t.scroll.query(r,
|
|
313
|
+
const o = t.scroll.query(r, d.ATTRIBUTE);
|
|
339
314
|
o instanceof T && (this.attributes[o.attrName] = o);
|
|
340
315
|
});
|
|
341
316
|
}
|
|
@@ -357,13 +332,13 @@ class Rt {
|
|
|
357
332
|
);
|
|
358
333
|
}
|
|
359
334
|
}
|
|
360
|
-
const
|
|
335
|
+
const dt = Pt, ft = class {
|
|
361
336
|
constructor(t, e) {
|
|
362
|
-
this.scroll = t, this.domNode = e,
|
|
337
|
+
this.scroll = t, this.domNode = e, M.blots.set(e, this), this.prev = null, this.next = null;
|
|
363
338
|
}
|
|
364
339
|
static create(t) {
|
|
365
340
|
if (this.tagName == null)
|
|
366
|
-
throw new
|
|
341
|
+
throw new L("Blot definition missing tagName");
|
|
367
342
|
let e, s;
|
|
368
343
|
return Array.isArray(this.tagName) ? (typeof t == "string" ? (s = t.toUpperCase(), parseInt(s, 10).toString() === s && (s = parseInt(s, 10))) : typeof t == "number" && (s = t), typeof s == "number" ? e = document.createElement(this.tagName[s - 1]) : s && this.tagName.indexOf(s) > -1 ? e = document.createElement(s) : e = document.createElement(this.tagName[0])) : e = document.createElement(this.tagName), this.className && e.classList.add(this.className), e;
|
|
369
344
|
}
|
|
@@ -378,16 +353,16 @@ const ut = Rt, dt = class {
|
|
|
378
353
|
return this.scroll.create(t);
|
|
379
354
|
}
|
|
380
355
|
detach() {
|
|
381
|
-
this.parent != null && this.parent.removeChild(this),
|
|
356
|
+
this.parent != null && this.parent.removeChild(this), M.blots.delete(this.domNode);
|
|
382
357
|
}
|
|
383
358
|
deleteAt(t, e) {
|
|
384
359
|
this.isolate(t, e).remove();
|
|
385
360
|
}
|
|
386
361
|
formatAt(t, e, s, i) {
|
|
387
362
|
const r = this.isolate(t, e);
|
|
388
|
-
if (this.scroll.query(s,
|
|
363
|
+
if (this.scroll.query(s, d.BLOT) != null && i)
|
|
389
364
|
r.wrap(s, i);
|
|
390
|
-
else if (this.scroll.query(s,
|
|
365
|
+
else if (this.scroll.query(s, d.ATTRIBUTE) != null) {
|
|
391
366
|
const o = this.scroll.create(this.statics.scope);
|
|
392
367
|
r.wrap(o), o.format(s, i);
|
|
393
368
|
}
|
|
@@ -426,13 +401,13 @@ const ut = Rt, dt = class {
|
|
|
426
401
|
wrap(t, e) {
|
|
427
402
|
const s = typeof t == "string" ? this.scroll.create(t, e) : t;
|
|
428
403
|
if (this.parent != null && this.parent.insertBefore(s, this.next || void 0), typeof s.appendChild != "function")
|
|
429
|
-
throw new
|
|
404
|
+
throw new L(`Cannot wrap ${t}`);
|
|
430
405
|
return s.appendChild(this), s;
|
|
431
406
|
}
|
|
432
407
|
};
|
|
433
|
-
|
|
434
|
-
let
|
|
435
|
-
const
|
|
408
|
+
ft.blotName = "abstract";
|
|
409
|
+
let pt = ft;
|
|
410
|
+
const mt = class extends pt {
|
|
436
411
|
/**
|
|
437
412
|
* Returns the value represented by domNode if it is this Blot's type
|
|
438
413
|
* No checking that domNode can represent this Blot type is required so
|
|
@@ -467,10 +442,10 @@ const pt = class extends ft {
|
|
|
467
442
|
};
|
|
468
443
|
}
|
|
469
444
|
};
|
|
470
|
-
|
|
471
|
-
let
|
|
472
|
-
const
|
|
473
|
-
class
|
|
445
|
+
mt.scope = d.INLINE_BLOT;
|
|
446
|
+
let Mt = mt;
|
|
447
|
+
const V = Mt;
|
|
448
|
+
class zt {
|
|
474
449
|
constructor() {
|
|
475
450
|
this.head = null, this.tail = null, this.length = 0;
|
|
476
451
|
}
|
|
@@ -572,20 +547,20 @@ class Mt {
|
|
|
572
547
|
return e;
|
|
573
548
|
}
|
|
574
549
|
}
|
|
575
|
-
function
|
|
550
|
+
function rt(n, t) {
|
|
576
551
|
const e = t.find(n);
|
|
577
552
|
if (e)
|
|
578
553
|
return e;
|
|
579
554
|
try {
|
|
580
555
|
return t.create(n);
|
|
581
556
|
} catch {
|
|
582
|
-
const s = t.create(
|
|
557
|
+
const s = t.create(d.INLINE);
|
|
583
558
|
return Array.from(n.childNodes).forEach((i) => {
|
|
584
559
|
s.domNode.appendChild(i);
|
|
585
560
|
}), n.parentNode && n.parentNode.replaceChild(s.domNode, n), s.attach(), s;
|
|
586
561
|
}
|
|
587
562
|
}
|
|
588
|
-
const
|
|
563
|
+
const gt = class N extends pt {
|
|
589
564
|
constructor(t, e) {
|
|
590
565
|
super(t, e), this.uiNode = null, this.build();
|
|
591
566
|
}
|
|
@@ -604,12 +579,12 @@ const mt = class N extends ft {
|
|
|
604
579
|
* Called during construction, should fill its own children LinkedList.
|
|
605
580
|
*/
|
|
606
581
|
build() {
|
|
607
|
-
this.children = new
|
|
582
|
+
this.children = new zt(), Array.from(this.domNode.childNodes).filter((t) => t !== this.uiNode).reverse().forEach((t) => {
|
|
608
583
|
try {
|
|
609
|
-
const e =
|
|
584
|
+
const e = rt(t, this.scroll);
|
|
610
585
|
this.insertBefore(e, this.children.head || void 0);
|
|
611
586
|
} catch (e) {
|
|
612
|
-
if (e instanceof
|
|
587
|
+
if (e instanceof L)
|
|
613
588
|
return;
|
|
614
589
|
throw e;
|
|
615
590
|
}
|
|
@@ -648,7 +623,7 @@ const mt = class N extends ft {
|
|
|
648
623
|
this.children.forEach((e) => {
|
|
649
624
|
t || this.statics.allowedChildren.some(
|
|
650
625
|
(s) => e instanceof s
|
|
651
|
-
) || (e.statics.scope ===
|
|
626
|
+
) || (e.statics.scope === d.BLOCK_BLOT ? (e.next != null && this.splitAfter(e), e.prev != null && this.splitAfter(e.prev), e.parent.unwrap(), t = !0) : e instanceof N ? e.unwrap() : e.remove());
|
|
652
627
|
});
|
|
653
628
|
}
|
|
654
629
|
formatAt(t, e, s, i) {
|
|
@@ -732,15 +707,15 @@ const mt = class N extends ft {
|
|
|
732
707
|
}), s.filter((r) => r.parentNode === this.domNode && r !== this.uiNode).sort((r, o) => r === o ? 0 : r.compareDocumentPosition(o) & Node.DOCUMENT_POSITION_FOLLOWING ? 1 : -1).forEach((r) => {
|
|
733
708
|
let o = null;
|
|
734
709
|
r.nextSibling != null && (o = this.scroll.find(r.nextSibling));
|
|
735
|
-
const a =
|
|
710
|
+
const a = rt(r, this.scroll);
|
|
736
711
|
(a.next !== o || a.next == null) && (a.parent != null && a.parent.removeChild(this), this.insertBefore(a, o || void 0));
|
|
737
712
|
}), this.enforceAllowedChildren();
|
|
738
713
|
}
|
|
739
714
|
};
|
|
740
|
-
|
|
741
|
-
let
|
|
742
|
-
const
|
|
743
|
-
function
|
|
715
|
+
gt.uiClass = "";
|
|
716
|
+
let Ut = gt;
|
|
717
|
+
const O = Ut;
|
|
718
|
+
function Ht(n, t) {
|
|
744
719
|
if (Object.keys(n).length !== Object.keys(t).length)
|
|
745
720
|
return !1;
|
|
746
721
|
for (const e in n)
|
|
@@ -748,12 +723,12 @@ function Ut(n, t) {
|
|
|
748
723
|
return !1;
|
|
749
724
|
return !0;
|
|
750
725
|
}
|
|
751
|
-
const
|
|
726
|
+
const E = class C extends O {
|
|
752
727
|
static create(t) {
|
|
753
728
|
return super.create(t);
|
|
754
729
|
}
|
|
755
730
|
static formats(t, e) {
|
|
756
|
-
const s = e.query(
|
|
731
|
+
const s = e.query(C.blotName);
|
|
757
732
|
if (!(s != null && t.tagName === s.tagName)) {
|
|
758
733
|
if (typeof this.tagName == "string")
|
|
759
734
|
return !0;
|
|
@@ -762,15 +737,15 @@ const w = class A extends L {
|
|
|
762
737
|
}
|
|
763
738
|
}
|
|
764
739
|
constructor(t, e) {
|
|
765
|
-
super(t, e), this.attributes = new
|
|
740
|
+
super(t, e), this.attributes = new dt(this.domNode);
|
|
766
741
|
}
|
|
767
742
|
format(t, e) {
|
|
768
743
|
if (t === this.statics.blotName && !e)
|
|
769
744
|
this.children.forEach((s) => {
|
|
770
|
-
s instanceof
|
|
745
|
+
s instanceof C || (s = s.wrap(C.blotName, !0)), this.attributes.copy(s);
|
|
771
746
|
}), this.unwrap();
|
|
772
747
|
else {
|
|
773
|
-
const s = this.scroll.query(t,
|
|
748
|
+
const s = this.scroll.query(t, d.INLINE);
|
|
774
749
|
if (s == null)
|
|
775
750
|
return;
|
|
776
751
|
s instanceof T ? this.attributes.attribute(s, e) : e && (t !== this.statics.blotName || this.formats()[t] !== e) && this.replaceWith(t, e);
|
|
@@ -781,7 +756,7 @@ const w = class A extends L {
|
|
|
781
756
|
return e != null && (t[this.statics.blotName] = e), t;
|
|
782
757
|
}
|
|
783
758
|
formatAt(t, e, s, i) {
|
|
784
|
-
this.formats()[s] != null || this.scroll.query(s,
|
|
759
|
+
this.formats()[s] != null || this.scroll.query(s, d.ATTRIBUTE) ? this.isolate(t, e).format(s, i) : super.formatAt(t, e, s, i);
|
|
785
760
|
}
|
|
786
761
|
optimize(t) {
|
|
787
762
|
super.optimize(t);
|
|
@@ -789,7 +764,7 @@ const w = class A extends L {
|
|
|
789
764
|
if (Object.keys(e).length === 0)
|
|
790
765
|
return this.unwrap();
|
|
791
766
|
const s = this.next;
|
|
792
|
-
s instanceof
|
|
767
|
+
s instanceof C && s.prev === this && Ht(e, s.formats()) && (s.moveChildren(this), s.remove());
|
|
793
768
|
}
|
|
794
769
|
replaceWith(t, e) {
|
|
795
770
|
const s = super.replaceWith(t, e);
|
|
@@ -802,17 +777,17 @@ const w = class A extends L {
|
|
|
802
777
|
}
|
|
803
778
|
wrap(t, e) {
|
|
804
779
|
const s = super.wrap(t, e);
|
|
805
|
-
return s instanceof
|
|
780
|
+
return s instanceof C && this.attributes.move(s), s;
|
|
806
781
|
}
|
|
807
782
|
};
|
|
808
|
-
|
|
809
|
-
let
|
|
810
|
-
const
|
|
783
|
+
E.allowedChildren = [E, V], E.blotName = "inline", E.scope = d.INLINE_BLOT, E.tagName = "SPAN";
|
|
784
|
+
let Kt = E;
|
|
785
|
+
const _t = Kt, A = class Y extends O {
|
|
811
786
|
static create(t) {
|
|
812
787
|
return super.create(t);
|
|
813
788
|
}
|
|
814
789
|
static formats(t, e) {
|
|
815
|
-
const s = e.query(
|
|
790
|
+
const s = e.query(Y.blotName);
|
|
816
791
|
if (!(s != null && t.tagName === s.tagName)) {
|
|
817
792
|
if (typeof this.tagName == "string")
|
|
818
793
|
return !0;
|
|
@@ -821,21 +796,21 @@ const gt = Ht, C = class X extends L {
|
|
|
821
796
|
}
|
|
822
797
|
}
|
|
823
798
|
constructor(t, e) {
|
|
824
|
-
super(t, e), this.attributes = new
|
|
799
|
+
super(t, e), this.attributes = new dt(this.domNode);
|
|
825
800
|
}
|
|
826
801
|
format(t, e) {
|
|
827
|
-
const s = this.scroll.query(t,
|
|
828
|
-
s != null && (s instanceof T ? this.attributes.attribute(s, e) : t === this.statics.blotName && !e ? this.replaceWith(
|
|
802
|
+
const s = this.scroll.query(t, d.BLOCK);
|
|
803
|
+
s != null && (s instanceof T ? this.attributes.attribute(s, e) : t === this.statics.blotName && !e ? this.replaceWith(Y.blotName) : e && (t !== this.statics.blotName || this.formats()[t] !== e) && this.replaceWith(t, e));
|
|
829
804
|
}
|
|
830
805
|
formats() {
|
|
831
806
|
const t = this.attributes.values(), e = this.statics.formats(this.domNode, this.scroll);
|
|
832
807
|
return e != null && (t[this.statics.blotName] = e), t;
|
|
833
808
|
}
|
|
834
809
|
formatAt(t, e, s, i) {
|
|
835
|
-
this.scroll.query(s,
|
|
810
|
+
this.scroll.query(s, d.BLOCK) != null ? this.format(s, i) : super.formatAt(t, e, s, i);
|
|
836
811
|
}
|
|
837
812
|
insertAt(t, e, s) {
|
|
838
|
-
if (s == null || this.scroll.query(e,
|
|
813
|
+
if (s == null || this.scroll.query(e, d.INLINE) != null)
|
|
839
814
|
super.insertAt(t, e, s);
|
|
840
815
|
else {
|
|
841
816
|
const i = this.split(t);
|
|
@@ -856,13 +831,13 @@ const gt = Ht, C = class X extends L {
|
|
|
856
831
|
) && this.attributes.build();
|
|
857
832
|
}
|
|
858
833
|
};
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
834
|
+
A.blotName = "block", A.scope = d.BLOCK_BLOT, A.tagName = "P", A.allowedChildren = [
|
|
835
|
+
_t,
|
|
836
|
+
A,
|
|
837
|
+
V
|
|
863
838
|
];
|
|
864
|
-
let
|
|
865
|
-
const
|
|
839
|
+
let Vt = A;
|
|
840
|
+
const Z = Vt, J = class extends O {
|
|
866
841
|
checkMerge() {
|
|
867
842
|
return this.next !== null && this.next.statics.blotName === this.statics.blotName;
|
|
868
843
|
}
|
|
@@ -879,10 +854,10 @@ const Y = Kt, J = class extends L {
|
|
|
879
854
|
super.optimize(t), this.children.length > 0 && this.next != null && this.checkMerge() && (this.next.moveChildren(this), this.next.remove());
|
|
880
855
|
}
|
|
881
856
|
};
|
|
882
|
-
J.blotName = "container", J.scope =
|
|
857
|
+
J.blotName = "container", J.scope = d.BLOCK_BLOT;
|
|
883
858
|
let qt = J;
|
|
884
|
-
const
|
|
885
|
-
class
|
|
859
|
+
const Ft = qt;
|
|
860
|
+
class Wt extends V {
|
|
886
861
|
static formats(t, e) {
|
|
887
862
|
}
|
|
888
863
|
format(t, e) {
|
|
@@ -895,17 +870,17 @@ class $t extends W {
|
|
|
895
870
|
return this.statics.formats(this.domNode, this.scroll);
|
|
896
871
|
}
|
|
897
872
|
}
|
|
898
|
-
const
|
|
873
|
+
const Gt = Wt, jt = {
|
|
899
874
|
attributes: !0,
|
|
900
875
|
characterData: !0,
|
|
901
876
|
characterDataOldValue: !0,
|
|
902
877
|
childList: !0,
|
|
903
878
|
subtree: !0
|
|
904
|
-
},
|
|
879
|
+
}, Xt = 100, S = class extends O {
|
|
905
880
|
constructor(t, e) {
|
|
906
881
|
super(null, e), this.registry = t, this.scroll = this, this.build(), this.observer = new MutationObserver((s) => {
|
|
907
882
|
this.update(s);
|
|
908
|
-
}), this.observer.observe(this.domNode,
|
|
883
|
+
}), this.observer.observe(this.domNode, jt), this.attach();
|
|
909
884
|
}
|
|
910
885
|
create(t, e) {
|
|
911
886
|
return this.registry.create(this, t, e);
|
|
@@ -914,7 +889,7 @@ const Ft = $t, Gt = {
|
|
|
914
889
|
const s = this.registry.find(t, e);
|
|
915
890
|
return s ? s.scroll === this ? s : e ? this.find(s.scroll.domNode.parentNode, !0) : null : null;
|
|
916
891
|
}
|
|
917
|
-
query(t, e =
|
|
892
|
+
query(t, e = d.ANY) {
|
|
918
893
|
return this.registry.query(t, e);
|
|
919
894
|
}
|
|
920
895
|
register(...t) {
|
|
@@ -946,17 +921,17 @@ const Ft = $t, Gt = {
|
|
|
946
921
|
const r = (l, h = !0) => {
|
|
947
922
|
l == null || l === this || l.domNode.parentNode != null && (s.has(l.domNode) || s.set(l.domNode, []), h && r(l.parent));
|
|
948
923
|
}, o = (l) => {
|
|
949
|
-
s.has(l.domNode) && (l instanceof
|
|
924
|
+
s.has(l.domNode) && (l instanceof O && l.children.forEach(o), s.delete(l.domNode), l.optimize(e));
|
|
950
925
|
};
|
|
951
926
|
let a = t;
|
|
952
927
|
for (let l = 0; a.length > 0; l += 1) {
|
|
953
|
-
if (l >=
|
|
928
|
+
if (l >= Xt)
|
|
954
929
|
throw new Error("[Parchment] Maximum optimize iterations reached");
|
|
955
930
|
for (a.forEach((h) => {
|
|
956
931
|
const c = this.find(h.target, !0);
|
|
957
|
-
c != null && (c.domNode === h.target && (h.type === "childList" ? (r(this.find(h.previousSibling, !1)), Array.from(h.addedNodes).forEach((
|
|
958
|
-
const g = this.find(
|
|
959
|
-
r(g, !1), g instanceof
|
|
932
|
+
c != null && (c.domNode === h.target && (h.type === "childList" ? (r(this.find(h.previousSibling, !1)), Array.from(h.addedNodes).forEach((f) => {
|
|
933
|
+
const g = this.find(f, !1);
|
|
934
|
+
r(g, !1), g instanceof O && g.children.forEach((u) => {
|
|
960
935
|
r(u, !1);
|
|
961
936
|
});
|
|
962
937
|
})) : h.type === "attributes" && r(c.prev)), r(c));
|
|
@@ -975,9 +950,9 @@ const Ft = $t, Gt = {
|
|
|
975
950
|
}), e.mutationsMap = s, s.has(this.domNode) && super.update(s.get(this.domNode), e), this.optimize(t, e);
|
|
976
951
|
}
|
|
977
952
|
};
|
|
978
|
-
|
|
979
|
-
let
|
|
980
|
-
const
|
|
953
|
+
S.blotName = "scroll", S.defaultChild = Z, S.allowedChildren = [Z, Ft], S.scope = d.BLOCK_BLOT, S.tagName = "DIV";
|
|
954
|
+
let Yt = S;
|
|
955
|
+
const Zt = Yt, nt = class vt extends V {
|
|
981
956
|
static create(t) {
|
|
982
957
|
return document.createTextNode(t);
|
|
983
958
|
}
|
|
@@ -1022,8 +997,8 @@ const Xt = jt, it = class vt extends W {
|
|
|
1022
997
|
return this.text;
|
|
1023
998
|
}
|
|
1024
999
|
};
|
|
1025
|
-
|
|
1026
|
-
const
|
|
1000
|
+
nt.blotName = "text", nt.scope = d.INLINE_BLOT;
|
|
1001
|
+
const et = class et extends Zt {
|
|
1027
1002
|
constructor(t, e) {
|
|
1028
1003
|
super(t, e), this.observer.disconnect();
|
|
1029
1004
|
}
|
|
@@ -1033,39 +1008,39 @@ const Q = class Q extends Xt {
|
|
|
1033
1008
|
optimize(t, e) {
|
|
1034
1009
|
}
|
|
1035
1010
|
};
|
|
1036
|
-
|
|
1037
|
-
let
|
|
1038
|
-
const B = class B extends
|
|
1011
|
+
et.blotName = "rc-scroll";
|
|
1012
|
+
let Q = et;
|
|
1013
|
+
const B = class B extends Z {
|
|
1039
1014
|
};
|
|
1040
|
-
B.blotName = "
|
|
1041
|
-
let
|
|
1042
|
-
const D = class D extends
|
|
1015
|
+
B.blotName = "rc-block", B.tagName = "DIV", B.className = "line";
|
|
1016
|
+
let z = B;
|
|
1017
|
+
const D = class D extends _t {
|
|
1043
1018
|
static create(t) {
|
|
1044
1019
|
const e = super.create();
|
|
1045
|
-
return t &&
|
|
1020
|
+
return t && Jt(e, t), e;
|
|
1046
1021
|
}
|
|
1047
1022
|
};
|
|
1048
|
-
D.blotName = "
|
|
1049
|
-
let
|
|
1050
|
-
function
|
|
1023
|
+
D.blotName = "rc-inline", D.tagName = "SPAN", D.className = "mark";
|
|
1024
|
+
let U = D;
|
|
1025
|
+
function Jt(n, t) {
|
|
1051
1026
|
if (t.className)
|
|
1052
1027
|
for (const e of t.className.split(/\s+/).filter(Boolean))
|
|
1053
1028
|
n.classList.add(e);
|
|
1054
1029
|
t.bold && (n.style.fontWeight = "bold"), t.italic && (n.style.fontStyle = "italic"), t.color && (n.style.color = t.color), t.background && (n.style.backgroundColor = t.background), t.underline && (n.style.textDecoration = `${t.underline} underline`, t.underlineColor && (n.style.textDecorationColor = t.underlineColor));
|
|
1055
1030
|
}
|
|
1056
|
-
const I = class I extends
|
|
1031
|
+
const I = class I extends Gt {
|
|
1057
1032
|
static create() {
|
|
1058
1033
|
const t = super.create();
|
|
1059
1034
|
return t.contentEditable = "false", t.setAttribute("aria-hidden", "true"), t;
|
|
1060
1035
|
}
|
|
1061
1036
|
};
|
|
1062
|
-
I.blotName = "
|
|
1063
|
-
let
|
|
1064
|
-
function
|
|
1065
|
-
const n = new
|
|
1066
|
-
return n.register(U, H
|
|
1037
|
+
I.blotName = "rc-widget", I.tagName = "SPAN", I.className = "widget";
|
|
1038
|
+
let H = I;
|
|
1039
|
+
function Qt() {
|
|
1040
|
+
const n = new M();
|
|
1041
|
+
return n.register(z, U, H), n;
|
|
1067
1042
|
}
|
|
1068
|
-
function
|
|
1043
|
+
function te(n, t, e, s, i) {
|
|
1069
1044
|
if (t.length === 0) {
|
|
1070
1045
|
n.appendChild(document.createElement("br"));
|
|
1071
1046
|
return;
|
|
@@ -1081,93 +1056,90 @@ function Zt(n, t, e, s, i) {
|
|
|
1081
1056
|
for (let a = 0; a < o.length - 1; a++) {
|
|
1082
1057
|
const l = o[a], h = o[a + 1];
|
|
1083
1058
|
for (const u of i)
|
|
1084
|
-
u.offset - e === l && (u.side ?? "before") === "before" && n.appendChild(
|
|
1059
|
+
u.offset - e === l && (u.side ?? "before") === "before" && n.appendChild(W(u));
|
|
1085
1060
|
const c = t.slice(l, h);
|
|
1086
|
-
if (!c)
|
|
1087
|
-
|
|
1061
|
+
if (!c)
|
|
1062
|
+
continue;
|
|
1063
|
+
let f, g = 1 / 0;
|
|
1088
1064
|
for (const u of s) {
|
|
1089
1065
|
const m = u.from - e, p = u.to - e;
|
|
1090
1066
|
if (m <= l && p >= h) {
|
|
1091
1067
|
const k = p - m;
|
|
1092
|
-
k < g && (g = k,
|
|
1068
|
+
k < g && (g = k, f = u);
|
|
1093
1069
|
}
|
|
1094
1070
|
}
|
|
1095
|
-
if (
|
|
1096
|
-
const u =
|
|
1097
|
-
if (
|
|
1098
|
-
for (const [m, p] of Object.entries(
|
|
1071
|
+
if (f) {
|
|
1072
|
+
const u = U.create(f);
|
|
1073
|
+
if (f.attributes)
|
|
1074
|
+
for (const [m, p] of Object.entries(f.attributes))
|
|
1099
1075
|
u.setAttribute(m, p);
|
|
1100
1076
|
u.appendChild(document.createTextNode(c)), n.appendChild(u);
|
|
1101
1077
|
} else
|
|
1102
1078
|
n.appendChild(document.createTextNode(c));
|
|
1103
1079
|
for (const u of i)
|
|
1104
|
-
u.offset - e === h && u.side === "after" && n.appendChild(
|
|
1080
|
+
u.offset - e === h && u.side === "after" && n.appendChild(W(u));
|
|
1105
1081
|
}
|
|
1106
1082
|
for (const a of i)
|
|
1107
|
-
a.offset - e === t.length && (a.side ?? "before") === "before" && n.appendChild(
|
|
1083
|
+
a.offset - e === t.length && (a.side ?? "before") === "before" && n.appendChild(W(a));
|
|
1108
1084
|
}
|
|
1109
|
-
function
|
|
1110
|
-
const t =
|
|
1085
|
+
function W(n) {
|
|
1086
|
+
const t = H.create();
|
|
1111
1087
|
return t.appendChild(n.create()), t;
|
|
1112
1088
|
}
|
|
1113
|
-
class
|
|
1089
|
+
class ee {
|
|
1114
1090
|
constructor(t) {
|
|
1115
|
-
const e =
|
|
1116
|
-
this.scroll = new
|
|
1091
|
+
const e = Qt();
|
|
1092
|
+
this.scroll = new Q(e, t);
|
|
1117
1093
|
}
|
|
1118
1094
|
/**
|
|
1119
|
-
* Rebuild the document tree
|
|
1120
|
-
*
|
|
1095
|
+
* Rebuild the document tree.
|
|
1096
|
+
*
|
|
1097
|
+
* Reuses existing `.line` elements in place to preserve DOM identity
|
|
1121
1098
|
* across renders (fixes DevTools node tracking and mouse gesture continuity).
|
|
1122
|
-
* Only the children of each line are replaced; the line element itself survives.
|
|
1123
1099
|
*/
|
|
1124
1100
|
build(t, e) {
|
|
1125
1101
|
const s = this.scroll.domNode, i = t.split(`
|
|
1126
|
-
`), r = Array.from(s.querySelectorAll(".
|
|
1102
|
+
`), r = Array.from(s.querySelectorAll(".line")), o = /* @__PURE__ */ new Map(), a = [], l = [];
|
|
1127
1103
|
for (const c of e)
|
|
1128
1104
|
if (c.type === "line") {
|
|
1129
|
-
const
|
|
1130
|
-
|
|
1105
|
+
const f = o.get(c.line) ?? [];
|
|
1106
|
+
f.push(c), o.set(c.line, f);
|
|
1131
1107
|
} else c.type === "mark" ? a.push(c) : l.push(c);
|
|
1132
|
-
a.sort((c,
|
|
1108
|
+
a.sort((c, f) => c.from - f.from || c.to - f.to), l.sort((c, f) => c.offset - f.offset);
|
|
1133
1109
|
let h = 0;
|
|
1134
1110
|
for (let c = 0; c < i.length; c++) {
|
|
1135
|
-
const
|
|
1111
|
+
const f = i[c], g = c + 1, u = h, m = u + f.length;
|
|
1136
1112
|
let p;
|
|
1137
1113
|
if (c < r.length) {
|
|
1138
1114
|
for (p = r[c]; p.attributes.length > 0; )
|
|
1139
1115
|
p.removeAttribute(p.attributes[0].name);
|
|
1140
|
-
for (p.className = "
|
|
1116
|
+
for (p.className = "line"; p.firstChild; )
|
|
1141
1117
|
p.removeChild(p.firstChild);
|
|
1142
1118
|
} else
|
|
1143
|
-
p =
|
|
1119
|
+
p = z.create(), s.appendChild(p);
|
|
1144
1120
|
const k = o.get(g) ?? [];
|
|
1145
1121
|
for (const v of k) {
|
|
1146
1122
|
if (v.className)
|
|
1147
|
-
for (const
|
|
1148
|
-
p.classList.add(
|
|
1123
|
+
for (const x of v.className.split(/\s+/).filter(Boolean))
|
|
1124
|
+
p.classList.add(x);
|
|
1149
1125
|
if (v.attributes)
|
|
1150
|
-
for (const [
|
|
1151
|
-
p.setAttribute(
|
|
1126
|
+
for (const [x, w] of Object.entries(v.attributes))
|
|
1127
|
+
p.setAttribute(x, w);
|
|
1152
1128
|
}
|
|
1153
|
-
const
|
|
1154
|
-
|
|
1155
|
-
);
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
if ($.length > 0) {
|
|
1159
|
-
const v = $.map((x) => x.message).join(" · ");
|
|
1160
|
-
p.dataset.message = v, p.title = v;
|
|
1161
|
-
const E = [
|
|
1129
|
+
const St = a.filter((v) => v.from < m && v.to > u), Lt = l.filter((v) => v.offset >= u && v.offset <= m);
|
|
1130
|
+
te(p, f, u, St, Lt);
|
|
1131
|
+
const q = k.filter((v) => v.message);
|
|
1132
|
+
if (q.length > 0) {
|
|
1133
|
+
const v = q.map((w) => w.message).join(" · "), x = [
|
|
1162
1134
|
...new Set(
|
|
1163
|
-
|
|
1164
|
-
(
|
|
1135
|
+
q.flatMap(
|
|
1136
|
+
(w) => w.messageClassName ? w.messageClassName.split(/\s+/).filter(Boolean) : []
|
|
1165
1137
|
)
|
|
1166
1138
|
)
|
|
1167
1139
|
];
|
|
1168
|
-
|
|
1140
|
+
p.dataset.message = v, p.title = v, x.length > 0 && (p.dataset.messageClass = x.join(" "));
|
|
1169
1141
|
}
|
|
1170
|
-
h +=
|
|
1142
|
+
h += f.length + 1;
|
|
1171
1143
|
}
|
|
1172
1144
|
for (; s.children.length > i.length; )
|
|
1173
1145
|
s.removeChild(s.lastChild);
|
|
@@ -1178,24 +1150,28 @@ class Qt {
|
|
|
1178
1150
|
t.removeChild(t.firstChild);
|
|
1179
1151
|
}
|
|
1180
1152
|
}
|
|
1181
|
-
function
|
|
1182
|
-
const t = Array.from(n.querySelectorAll(".
|
|
1183
|
-
return t.length > 0 ? t.map((e) =>
|
|
1184
|
-
`) :
|
|
1153
|
+
function se(n) {
|
|
1154
|
+
const t = Array.from(n.querySelectorAll(".line"));
|
|
1155
|
+
return t.length > 0 ? t.map((e) => ie(e)).join(`
|
|
1156
|
+
`) : yt(n);
|
|
1185
1157
|
}
|
|
1186
|
-
function
|
|
1158
|
+
function ie(n) {
|
|
1187
1159
|
let t = "";
|
|
1188
|
-
for (const e of n.childNodes)
|
|
1160
|
+
for (const e of n.childNodes)
|
|
1161
|
+
t += bt(e);
|
|
1189
1162
|
return t;
|
|
1190
1163
|
}
|
|
1191
|
-
function
|
|
1192
|
-
if (n.nodeType === Node.TEXT_NODE)
|
|
1193
|
-
|
|
1164
|
+
function bt(n) {
|
|
1165
|
+
if (n.nodeType === Node.TEXT_NODE)
|
|
1166
|
+
return n.data;
|
|
1167
|
+
if (!(n instanceof Element) || n.classList.contains("widget") || n.classList.contains("line-message") || n.tagName === "BR")
|
|
1168
|
+
return "";
|
|
1194
1169
|
let t = "";
|
|
1195
|
-
for (const e of n.childNodes)
|
|
1170
|
+
for (const e of n.childNodes)
|
|
1171
|
+
t += bt(e);
|
|
1196
1172
|
return t;
|
|
1197
1173
|
}
|
|
1198
|
-
function
|
|
1174
|
+
function yt(n) {
|
|
1199
1175
|
let t = "", e = !0;
|
|
1200
1176
|
for (const s of n.childNodes)
|
|
1201
1177
|
if (s.nodeType === Node.TEXT_NODE)
|
|
@@ -1206,64 +1182,65 @@ function bt(n) {
|
|
|
1206
1182
|
`, e = !1;
|
|
1207
1183
|
continue;
|
|
1208
1184
|
}
|
|
1209
|
-
if (s.classList.contains("
|
|
1185
|
+
if (s.classList.contains("widget"))
|
|
1186
|
+
continue;
|
|
1210
1187
|
(s.tagName === "DIV" || s.tagName === "P") && !e && (t += `
|
|
1211
|
-
`), e = !1, t +=
|
|
1188
|
+
`), e = !1, t += yt(s);
|
|
1212
1189
|
}
|
|
1213
1190
|
return t;
|
|
1214
1191
|
}
|
|
1215
|
-
function
|
|
1216
|
-
if (n.nodeType === Node.TEXT_NODE)
|
|
1217
|
-
|
|
1192
|
+
function $(n) {
|
|
1193
|
+
if (n.nodeType === Node.TEXT_NODE)
|
|
1194
|
+
return n.length;
|
|
1195
|
+
if (!(n instanceof Element) || n.classList.contains("widget") || n.tagName === "BR")
|
|
1196
|
+
return 0;
|
|
1218
1197
|
let t = 0;
|
|
1219
|
-
for (const e of n.childNodes)
|
|
1198
|
+
for (const e of n.childNodes)
|
|
1199
|
+
t += $(e);
|
|
1220
1200
|
return t;
|
|
1221
1201
|
}
|
|
1222
|
-
function
|
|
1223
|
-
const s = Array.from(n.querySelectorAll(".
|
|
1202
|
+
function ot(n, t, e) {
|
|
1203
|
+
const s = Array.from(n.querySelectorAll(".line"));
|
|
1224
1204
|
let i = 0;
|
|
1225
1205
|
for (let r = 0; r < s.length; r++) {
|
|
1226
1206
|
r > 0 && i++;
|
|
1227
|
-
const o = s[r], a =
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
i
|
|
1232
|
-
);
|
|
1233
|
-
if (a.found) return a.offset;
|
|
1234
|
-
i += R(o);
|
|
1207
|
+
const o = s[r], a = Nt(o, t, e, i);
|
|
1208
|
+
if (a.found)
|
|
1209
|
+
return a.offset;
|
|
1210
|
+
i += $(o);
|
|
1235
1211
|
}
|
|
1236
1212
|
return i;
|
|
1237
1213
|
}
|
|
1238
|
-
function
|
|
1214
|
+
function Nt(n, t, e, s) {
|
|
1239
1215
|
if (n === t) {
|
|
1240
1216
|
if (n.nodeType === Node.TEXT_NODE)
|
|
1241
1217
|
return { found: !0, offset: s + e };
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
for (let o = 0; o < e && o <
|
|
1245
|
-
|
|
1246
|
-
return { found: !0, offset:
|
|
1218
|
+
const i = Array.from(n.childNodes);
|
|
1219
|
+
let r = s;
|
|
1220
|
+
for (let o = 0; o < e && o < i.length; o++)
|
|
1221
|
+
r += $(i[o]);
|
|
1222
|
+
return { found: !0, offset: r };
|
|
1247
1223
|
}
|
|
1248
1224
|
if (n.nodeType === Node.TEXT_NODE)
|
|
1249
1225
|
return { found: !1, offset: s + n.length };
|
|
1250
1226
|
if (n instanceof Element) {
|
|
1251
|
-
if (n.classList.contains("
|
|
1227
|
+
if (n.classList.contains("widget"))
|
|
1252
1228
|
return { found: !1, offset: s };
|
|
1253
1229
|
if (n.tagName === "BR")
|
|
1254
1230
|
return { found: !1, offset: s };
|
|
1255
1231
|
let i = s;
|
|
1256
1232
|
for (const r of n.childNodes) {
|
|
1257
|
-
const o =
|
|
1258
|
-
if (o.found)
|
|
1233
|
+
const o = Nt(r, t, e, i);
|
|
1234
|
+
if (o.found)
|
|
1235
|
+
return o;
|
|
1259
1236
|
i = o.offset;
|
|
1260
1237
|
}
|
|
1261
1238
|
return { found: !1, offset: i };
|
|
1262
1239
|
}
|
|
1263
1240
|
return { found: !1, offset: s };
|
|
1264
1241
|
}
|
|
1265
|
-
function
|
|
1266
|
-
const e = Array.from(n.querySelectorAll(".
|
|
1242
|
+
function at(n, t) {
|
|
1243
|
+
const e = Array.from(n.querySelectorAll(".line"));
|
|
1267
1244
|
let s = t;
|
|
1268
1245
|
for (let r = 0; r < e.length; r++) {
|
|
1269
1246
|
if (r > 0) {
|
|
@@ -1271,9 +1248,9 @@ function nt(n, t) {
|
|
|
1271
1248
|
return { node: e[r], offset: 0 };
|
|
1272
1249
|
s--;
|
|
1273
1250
|
}
|
|
1274
|
-
const o = e[r], a =
|
|
1251
|
+
const o = e[r], a = $(o);
|
|
1275
1252
|
if (s <= a) {
|
|
1276
|
-
const l =
|
|
1253
|
+
const l = xt(o, s);
|
|
1277
1254
|
return l || { node: o, offset: o.childNodes.length };
|
|
1278
1255
|
}
|
|
1279
1256
|
s -= a;
|
|
@@ -1281,18 +1258,19 @@ function nt(n, t) {
|
|
|
1281
1258
|
const i = e[e.length - 1];
|
|
1282
1259
|
return i ? { node: i, offset: i.childNodes.length } : { node: n, offset: n.childNodes.length };
|
|
1283
1260
|
}
|
|
1284
|
-
function
|
|
1261
|
+
function xt(n, t) {
|
|
1285
1262
|
if (n.nodeType === Node.TEXT_NODE) {
|
|
1286
1263
|
const e = n;
|
|
1287
1264
|
return t <= e.length ? { node: e, offset: t } : null;
|
|
1288
1265
|
}
|
|
1289
1266
|
if (n instanceof Element) {
|
|
1290
|
-
if (n.classList.contains("
|
|
1267
|
+
if (n.classList.contains("widget") || n.tagName === "BR")
|
|
1268
|
+
return null;
|
|
1291
1269
|
let e = 0;
|
|
1292
1270
|
for (const s of n.childNodes) {
|
|
1293
|
-
const i =
|
|
1271
|
+
const i = $(s);
|
|
1294
1272
|
if (t <= i) {
|
|
1295
|
-
const r =
|
|
1273
|
+
const r = xt(s, t);
|
|
1296
1274
|
return r || { node: n, offset: e + 1 };
|
|
1297
1275
|
}
|
|
1298
1276
|
t -= i, e++;
|
|
@@ -1300,37 +1278,32 @@ function Nt(n, t) {
|
|
|
1300
1278
|
}
|
|
1301
1279
|
return null;
|
|
1302
1280
|
}
|
|
1303
|
-
function
|
|
1281
|
+
function R(n) {
|
|
1304
1282
|
const e = n.getRootNode().getSelection?.() ?? window.getSelection();
|
|
1305
|
-
if (!e || e.rangeCount === 0)
|
|
1283
|
+
if (!e || e.rangeCount === 0)
|
|
1284
|
+
return null;
|
|
1306
1285
|
const s = e.getRangeAt(0);
|
|
1307
|
-
if (!n.contains(s.commonAncestorContainer))
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
s.startContainer,
|
|
1311
|
-
s.startOffset
|
|
1312
|
-
), r = rt(
|
|
1313
|
-
n,
|
|
1314
|
-
s.endContainer,
|
|
1315
|
-
s.endOffset
|
|
1316
|
-
);
|
|
1286
|
+
if (!n.contains(s.commonAncestorContainer))
|
|
1287
|
+
return null;
|
|
1288
|
+
const i = ot(n, s.startContainer, s.startOffset), r = ot(n, s.endContainer, s.endOffset);
|
|
1317
1289
|
return { anchorOffset: i, focusOffset: r };
|
|
1318
1290
|
}
|
|
1319
|
-
function
|
|
1320
|
-
const e =
|
|
1291
|
+
function re(n, t) {
|
|
1292
|
+
const e = at(n, t.anchorOffset), s = at(n, t.focusOffset);
|
|
1321
1293
|
if (!(!e || !s))
|
|
1322
1294
|
try {
|
|
1323
1295
|
const i = window.getSelection();
|
|
1324
|
-
if (!i)
|
|
1296
|
+
if (!i)
|
|
1297
|
+
return;
|
|
1325
1298
|
const r = document.createRange();
|
|
1326
1299
|
r.setStart(e.node, e.offset), r.setEnd(s.node, s.offset), i.removeAllRanges(), i.addRange(r);
|
|
1327
1300
|
} catch {
|
|
1328
1301
|
}
|
|
1329
1302
|
}
|
|
1330
|
-
function
|
|
1303
|
+
function P() {
|
|
1331
1304
|
return crypto.randomUUID();
|
|
1332
1305
|
}
|
|
1333
|
-
function
|
|
1306
|
+
function wt(n, t) {
|
|
1334
1307
|
let e = 0;
|
|
1335
1308
|
for (; e < n.length && e < t.length && n[e] === t[e]; )
|
|
1336
1309
|
e++;
|
|
@@ -1339,58 +1312,61 @@ function Et(n, t) {
|
|
|
1339
1312
|
s--, i--;
|
|
1340
1313
|
return { start: e, removed: s - e, inserted: i - e };
|
|
1341
1314
|
}
|
|
1342
|
-
function
|
|
1315
|
+
function lt(n, t, e) {
|
|
1343
1316
|
const s = e.start + e.removed, i = e.inserted - e.removed;
|
|
1344
|
-
if (t <= e.start)
|
|
1345
|
-
|
|
1317
|
+
if (t <= e.start)
|
|
1318
|
+
return { from: n, to: t };
|
|
1319
|
+
if (n >= s)
|
|
1320
|
+
return { from: n + i, to: t + i };
|
|
1346
1321
|
const r = Math.min(n, e.start), o = Math.max(
|
|
1347
1322
|
t > s ? t + i : e.start + e.inserted,
|
|
1348
1323
|
e.start + e.inserted
|
|
1349
1324
|
);
|
|
1350
1325
|
return r >= o ? null : { from: r, to: o };
|
|
1351
1326
|
}
|
|
1352
|
-
function
|
|
1327
|
+
function ne(n, t) {
|
|
1353
1328
|
let e = 0;
|
|
1354
1329
|
for (let s = 0; s < t && s < n.length; s++)
|
|
1355
1330
|
n[s] === `
|
|
1356
1331
|
` && e++;
|
|
1357
1332
|
return e;
|
|
1358
1333
|
}
|
|
1359
|
-
function
|
|
1360
|
-
const s =
|
|
1334
|
+
function oe(n, t, e) {
|
|
1335
|
+
const s = wt(t, e), i = s.start + s.removed, r = t.slice(s.start, i), o = e.slice(s.start, s.start + s.inserted), a = (r.match(/\n/g) ?? []).length, h = (o.match(/\n/g) ?? []).length - a, c = ne(t, s.start) + 1, f = c + a, g = [];
|
|
1361
1336
|
for (const u of n)
|
|
1362
1337
|
if (u.type === "mark") {
|
|
1363
|
-
const m =
|
|
1338
|
+
const m = lt(u.from, u.to, s);
|
|
1364
1339
|
m && g.push({ ...u, from: m.from, to: m.to });
|
|
1365
1340
|
} else if (u.type === "line")
|
|
1366
|
-
u.line < c ? g.push(u) : u.line <=
|
|
1341
|
+
u.line < c ? g.push(u) : u.line <= f || g.push({ ...u, line: u.line + h });
|
|
1367
1342
|
else {
|
|
1368
|
-
const m =
|
|
1343
|
+
const m = lt(u.offset, u.offset + 1, s);
|
|
1369
1344
|
m && g.push({ ...u, offset: m.from });
|
|
1370
1345
|
}
|
|
1371
1346
|
return g;
|
|
1372
1347
|
}
|
|
1373
|
-
function
|
|
1374
|
-
if (n.length === 0)
|
|
1348
|
+
function ae(n, t) {
|
|
1349
|
+
if (n.length === 0)
|
|
1350
|
+
return !1;
|
|
1375
1351
|
const e = Math.max(t.removed, t.inserted);
|
|
1376
1352
|
return e > 50 && e > n.length * 0.5;
|
|
1377
1353
|
}
|
|
1378
|
-
function
|
|
1379
|
-
const s =
|
|
1380
|
-
return
|
|
1354
|
+
function G(n, t, e) {
|
|
1355
|
+
const s = wt(t, e);
|
|
1356
|
+
return ae(t, s) ? [] : oe(n, t, e);
|
|
1381
1357
|
}
|
|
1382
|
-
function
|
|
1358
|
+
function ct(n, t) {
|
|
1383
1359
|
const e = crypto.randomUUID();
|
|
1384
1360
|
return n.set(e, { ...t, id: e }), e;
|
|
1385
1361
|
}
|
|
1386
|
-
function
|
|
1362
|
+
function le(n, t) {
|
|
1387
1363
|
n.clear();
|
|
1388
1364
|
for (const e of t) {
|
|
1389
1365
|
const s = crypto.randomUUID();
|
|
1390
1366
|
n.set(s, { ...e, id: s });
|
|
1391
1367
|
}
|
|
1392
1368
|
}
|
|
1393
|
-
function
|
|
1369
|
+
function ce(n, t) {
|
|
1394
1370
|
const e = [], s = [];
|
|
1395
1371
|
for (const i of t) {
|
|
1396
1372
|
let r = i.pattern.flags.includes("g") ? i.pattern.flags : i.pattern.flags + "g";
|
|
@@ -1406,11 +1382,12 @@ function ae(n, t) {
|
|
|
1406
1382
|
if (i.captureGroups) {
|
|
1407
1383
|
const h = a.indices?.groups;
|
|
1408
1384
|
if (h)
|
|
1409
|
-
for (const [c,
|
|
1385
|
+
for (const [c, f] of Object.entries(i.captureGroups)) {
|
|
1410
1386
|
const g = h[c];
|
|
1411
|
-
if (g === void 0)
|
|
1387
|
+
if (g === void 0)
|
|
1388
|
+
continue;
|
|
1412
1389
|
const [u, m] = g;
|
|
1413
|
-
e.push({ type: "mark", from: u, to: m, ...
|
|
1390
|
+
e.push({ type: "mark", from: u, to: m, ...f });
|
|
1414
1391
|
}
|
|
1415
1392
|
} else {
|
|
1416
1393
|
const h = l + a[0].length;
|
|
@@ -1440,13 +1417,13 @@ function ae(n, t) {
|
|
|
1440
1417
|
}
|
|
1441
1418
|
return { markDecorations: e, lineDecorations: s };
|
|
1442
1419
|
}
|
|
1443
|
-
var
|
|
1444
|
-
for (var i = s > 1 ? void 0 : s ?
|
|
1420
|
+
var he = Object.defineProperty, ue = Object.getOwnPropertyDescriptor, b = (n, t, e, s) => {
|
|
1421
|
+
for (var i = s > 1 ? void 0 : s ? ue(t, e) : t, r = n.length - 1, o; r >= 0; r--)
|
|
1445
1422
|
(o = n[r]) && (i = (s ? o(t, e, i) : o(i)) || i);
|
|
1446
|
-
return s && i &&
|
|
1423
|
+
return s && i && he(t, e, i), i;
|
|
1447
1424
|
};
|
|
1448
|
-
const
|
|
1449
|
-
function
|
|
1425
|
+
const de = 100;
|
|
1426
|
+
function j(n) {
|
|
1450
1427
|
const t = document.createElement("div");
|
|
1451
1428
|
t.innerHTML = n;
|
|
1452
1429
|
const e = [];
|
|
@@ -1456,7 +1433,8 @@ function lt(n) {
|
|
|
1456
1433
|
s += r.length;
|
|
1457
1434
|
return;
|
|
1458
1435
|
}
|
|
1459
|
-
if (!(r instanceof HTMLElement))
|
|
1436
|
+
if (!(r instanceof HTMLElement))
|
|
1437
|
+
return;
|
|
1460
1438
|
const o = r.tagName === "SPAN" && r.className, a = s;
|
|
1461
1439
|
for (const l of r.childNodes)
|
|
1462
1440
|
i(l);
|
|
@@ -1467,32 +1445,42 @@ function lt(n) {
|
|
|
1467
1445
|
className: r.className
|
|
1468
1446
|
});
|
|
1469
1447
|
}
|
|
1470
|
-
for (const r of t.childNodes)
|
|
1448
|
+
for (const r of t.childNodes)
|
|
1449
|
+
i(r);
|
|
1471
1450
|
return e;
|
|
1472
1451
|
}
|
|
1473
|
-
const
|
|
1452
|
+
const K = class K extends st {
|
|
1474
1453
|
constructor() {
|
|
1475
|
-
super(...arguments), this.lineNumbers = !1, this.
|
|
1454
|
+
super(...arguments), this.lineNumbers = !1, this._listNumbers = !1, this.gutter = !1, this.wordWrap = !1, this.autoGrow = !1, this.readOnly = !1, this._label = null, this._value = "", this._initialValueResolved = !1, this._valueSetByHost = !1, this._document = null, this._$textareaRef = null, this._textareaController = new kt(this, {
|
|
1455
|
+
selector: ":scope > textarea",
|
|
1456
|
+
observe: !0,
|
|
1457
|
+
onChange: (t, e) => this._setupTextarea(t, e),
|
|
1458
|
+
onMissing: () => {
|
|
1459
|
+
}
|
|
1460
|
+
}), this._pluginDecorations = /* @__PURE__ */ new Map(), this._patternDecorations = [], this._externalDecorations = [], this._patterns = /* @__PURE__ */ new Map(), this._plugin = null, this._pluginProperty = null, this._pluginApi = null, this._pluginSeq = 0, this._pluginSheets = /* @__PURE__ */ new Set(), this._savedSelection = null, this._rafHandle = null, this._composing = !1, this._isRendering = !1, this._$activeLine = null, this._cursorCallbacks = /* @__PURE__ */ new Set(), this._docSelectionChangeHandler = () => {
|
|
1476
1461
|
document.activeElement === this && this._onSelectionChange();
|
|
1477
|
-
}, this._undoStack = [], this._undoIndex = -1, this._resizeObserver = null, this._gutterLabels = [], this.
|
|
1462
|
+
}, this._undoStack = [], this._undoIndex = -1, this._resizeObserver = null, this._gutterLabels = [], this._onTextareaInvalid = () => {
|
|
1463
|
+
this._$editor && this._$editor.setAttribute("aria-invalid", "true");
|
|
1464
|
+
}, this._onInputEvent = () => {
|
|
1478
1465
|
this._composing || this._onInput();
|
|
1479
1466
|
}, this._onSelectionChange = () => {
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
const
|
|
1483
|
-
if (
|
|
1484
|
-
this._savedSelection =
|
|
1467
|
+
if (!this._$editor)
|
|
1468
|
+
return;
|
|
1469
|
+
const t = R(this._$editor);
|
|
1470
|
+
if (t) {
|
|
1471
|
+
this._savedSelection = t, this.dispatchEvent(
|
|
1485
1472
|
new CustomEvent("rc-textarea-select", {
|
|
1486
1473
|
bubbles: !0,
|
|
1487
1474
|
composed: !0,
|
|
1488
1475
|
detail: {
|
|
1489
|
-
selectionStart:
|
|
1490
|
-
selectionEnd:
|
|
1476
|
+
selectionStart: t.anchorOffset,
|
|
1477
|
+
selectionEnd: t.focusOffset
|
|
1491
1478
|
}
|
|
1492
1479
|
})
|
|
1493
1480
|
), this._updateActiveLine();
|
|
1494
|
-
const
|
|
1495
|
-
for (const
|
|
1481
|
+
const e = Math.min(t.anchorOffset, t.focusOffset), s = Math.max(t.anchorOffset, t.focusOffset);
|
|
1482
|
+
for (const i of this._cursorCallbacks)
|
|
1483
|
+
i(e, s);
|
|
1496
1484
|
}
|
|
1497
1485
|
}, this._onKeyDown = (t) => {
|
|
1498
1486
|
if (t.key === "Tab" && !t.ctrlKey && !t.metaKey && !t.altKey) {
|
|
@@ -1508,13 +1496,34 @@ const q = class q extends tt {
|
|
|
1508
1496
|
}, this._onPaste = (t) => {
|
|
1509
1497
|
t.preventDefault();
|
|
1510
1498
|
const e = t.clipboardData?.getData("text/plain") ?? "";
|
|
1511
|
-
if (!e)
|
|
1499
|
+
if (!e)
|
|
1500
|
+
return;
|
|
1512
1501
|
const s = e.replace(/\r\n/g, `
|
|
1513
1502
|
`).replace(/\r/g, `
|
|
1514
1503
|
`);
|
|
1515
1504
|
this._insertText(s);
|
|
1516
1505
|
};
|
|
1517
1506
|
}
|
|
1507
|
+
get listNumbers() {
|
|
1508
|
+
return this._listNumbers;
|
|
1509
|
+
}
|
|
1510
|
+
set listNumbers(t) {
|
|
1511
|
+
t && console.warn(
|
|
1512
|
+
"[rc-textarea] `listNumbers` / `list-numbers` is deprecated and will be removed before v1.0. Use a plugin with `LineDecoration.gutterContent` to implement sparse line numbering."
|
|
1513
|
+
);
|
|
1514
|
+
const e = this._listNumbers;
|
|
1515
|
+
this._listNumbers = t, this.requestUpdate("listNumbers", e);
|
|
1516
|
+
}
|
|
1517
|
+
get label() {
|
|
1518
|
+
return this._label;
|
|
1519
|
+
}
|
|
1520
|
+
set label(t) {
|
|
1521
|
+
t && console.warn(
|
|
1522
|
+
"[rc-textarea] `label` is deprecated and will be removed before v1.0. Set `aria-label` on the slotted `<textarea>`, or associate a `<label>` element via its `for`/`id` pair instead."
|
|
1523
|
+
);
|
|
1524
|
+
const e = this._label;
|
|
1525
|
+
this._label = t, this.requestUpdate("label", e);
|
|
1526
|
+
}
|
|
1518
1527
|
get plugin() {
|
|
1519
1528
|
return this._pluginProperty;
|
|
1520
1529
|
}
|
|
@@ -1539,47 +1548,31 @@ const q = class q extends tt {
|
|
|
1539
1548
|
get defaultValue() {
|
|
1540
1549
|
return this._defaultValue;
|
|
1541
1550
|
}
|
|
1542
|
-
/** Initial uncontrolled editor value. */
|
|
1543
1551
|
set defaultValue(t) {
|
|
1544
1552
|
const e = this._defaultValue;
|
|
1545
1553
|
this._defaultValue = t, !this._valueSetByHost && !this._initialValueResolved && t !== void 0 && (this._value = t, this._initialValueResolved = !0, this._syncTextareaValue(), this._scheduleRender()), this.requestUpdate("defaultValue", e);
|
|
1546
1554
|
}
|
|
1547
|
-
// ── Lifecycle ─────────────────────────────────────────────────────────
|
|
1548
1555
|
connectedCallback() {
|
|
1549
|
-
super.connectedCallback(), document.addEventListener(
|
|
1550
|
-
"selectionchange",
|
|
1551
|
-
this._docSelectionChangeHandler
|
|
1552
|
-
);
|
|
1556
|
+
super.connectedCallback(), document.addEventListener("selectionchange", this._docSelectionChangeHandler);
|
|
1553
1557
|
}
|
|
1554
1558
|
disconnectedCallback() {
|
|
1555
|
-
super.disconnectedCallback(), document.removeEventListener(
|
|
1556
|
-
"selectionchange",
|
|
1557
|
-
this._docSelectionChangeHandler
|
|
1558
|
-
), this._plugin?.destroy?.(), this._plugin = null, this._pluginApi = null, this._clearPluginSheets(), this._cursorCallbacks.clear(), this._resizeObserver?.disconnect(), this._rafHandle !== null && (cancelAnimationFrame(this._rafHandle), this._rafHandle = null);
|
|
1559
|
+
super.disconnectedCallback(), document.removeEventListener("selectionchange", this._docSelectionChangeHandler), this._plugin?.destroy?.(), this._plugin = null, this._pluginApi = null, this._clearPluginSheets(), this._cursorCallbacks.clear(), this._resizeObserver?.disconnect(), this._$textareaRef?.deref()?.removeEventListener("invalid", this._onTextareaInvalid), this._rafHandle !== null && (cancelAnimationFrame(this._rafHandle), this._rafHandle = null);
|
|
1559
1560
|
}
|
|
1560
1561
|
firstUpdated() {
|
|
1561
|
-
|
|
1562
|
-
t && (this._document = new Qt(t), this._bindEditorEvents(t)), this._resizeObserver = new ResizeObserver(() => {
|
|
1562
|
+
this._$editor && (this._document = new ee(this._$editor), this._bindEditorEvents(this._$editor)), this._resizeObserver = new ResizeObserver(() => {
|
|
1563
1563
|
this._syncGutter(), this._syncGutterHeights();
|
|
1564
1564
|
}), this._resizeObserver.observe(this), this._scheduleRender();
|
|
1565
1565
|
}
|
|
1566
1566
|
updated(t) {
|
|
1567
|
-
|
|
1568
|
-
const e = this._getEditorEl();
|
|
1569
|
-
e && (e.contentEditable = this.readOnly ? "false" : "true"), this._syncGutterHeights();
|
|
1570
|
-
}
|
|
1571
|
-
if (t.has("label")) {
|
|
1572
|
-
const e = this._getEditorEl();
|
|
1573
|
-
e && this.label && e.setAttribute("aria-label", this.label);
|
|
1574
|
-
}
|
|
1567
|
+
t.has("readOnly") && (this._$editor && (this._$editor.contentEditable = this.readOnly ? "false" : "true"), this._syncGutterHeights(), this._textareaController.sync()), t.has("label") && this._syncLabel();
|
|
1575
1568
|
}
|
|
1576
|
-
// ── Template ──────────────────────────────────────────────────────────
|
|
1577
1569
|
render() {
|
|
1578
|
-
return
|
|
1570
|
+
return Tt`
|
|
1579
1571
|
<div id="root" part="root">
|
|
1580
1572
|
<div id="gutter" part="gutter" aria-hidden="true">
|
|
1581
1573
|
<div id="gutter-cells" part="gutter-cells"></div>
|
|
1582
1574
|
</div>
|
|
1575
|
+
|
|
1583
1576
|
<div id="editor-area" part="editor-area">
|
|
1584
1577
|
<div
|
|
1585
1578
|
id="editor"
|
|
@@ -1590,24 +1583,22 @@ const q = class q extends tt {
|
|
|
1590
1583
|
spellcheck="false"
|
|
1591
1584
|
autocorrect="off"
|
|
1592
1585
|
autocapitalize="off"
|
|
1593
|
-
aria-label=${this.label ?? ""}
|
|
1594
1586
|
></div>
|
|
1587
|
+
|
|
1595
1588
|
<slot @slotchange=${this._onSlotChange}></slot>
|
|
1596
1589
|
</div>
|
|
1597
1590
|
</div>
|
|
1598
1591
|
`;
|
|
1599
1592
|
}
|
|
1600
|
-
// ── Slot change — lightDOM textarea wiring ────────────────────────────
|
|
1601
1593
|
_onSlotChange() {
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
if (!t)
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
if (
|
|
1610
|
-
this._textareaRef = new WeakRef(e), Object.assign(e.style, {
|
|
1594
|
+
this._textareaController.sync();
|
|
1595
|
+
}
|
|
1596
|
+
_setupTextarea(t, e) {
|
|
1597
|
+
if (e && e !== t && e.removeEventListener("invalid", this._onTextareaInvalid), !t) {
|
|
1598
|
+
this._$textareaRef = null;
|
|
1599
|
+
return;
|
|
1600
|
+
}
|
|
1601
|
+
if (this._$textareaRef = new WeakRef(t), Object.assign(t.style, {
|
|
1611
1602
|
position: "absolute",
|
|
1612
1603
|
width: "1px",
|
|
1613
1604
|
height: "1px",
|
|
@@ -1619,22 +1610,13 @@ const q = class q extends tt {
|
|
|
1619
1610
|
opacity: "0",
|
|
1620
1611
|
pointerEvents: "none",
|
|
1621
1612
|
tabIndex: "-1"
|
|
1622
|
-
}),
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
"aria-label",
|
|
1627
|
-
e.getAttribute("aria-label")
|
|
1628
|
-
);
|
|
1629
|
-
const i = e.getAttribute("placeholder");
|
|
1630
|
-
i && s.setAttribute("aria-placeholder", i);
|
|
1613
|
+
}), t.setAttribute("aria-hidden", "true"), t.tabIndex = -1, this._$editor) {
|
|
1614
|
+
this._syncLabel();
|
|
1615
|
+
const s = t.getAttribute("placeholder");
|
|
1616
|
+
s && this._$editor.setAttribute("aria-placeholder", s);
|
|
1631
1617
|
}
|
|
1632
|
-
this._initialValueResolved ?
|
|
1633
|
-
const i = this._getEditorEl();
|
|
1634
|
-
i && i.setAttribute("aria-invalid", "true");
|
|
1635
|
-
}), this._syncTypography(e), this._scheduleRender();
|
|
1618
|
+
this._initialValueResolved ? t.value = this._value : (this._value = t.value, this._initialValueResolved = !0), t.addEventListener("invalid", this._onTextareaInvalid), this._syncTypography(t), this._scheduleRender();
|
|
1636
1619
|
}
|
|
1637
|
-
// ── Editor event binding ──────────────────────────────────────────────
|
|
1638
1620
|
_bindEditorEvents(t) {
|
|
1639
1621
|
t.addEventListener("compositionstart", () => {
|
|
1640
1622
|
this._composing = !0;
|
|
@@ -1653,80 +1635,82 @@ const q = class q extends tt {
|
|
|
1653
1635
|
bubbles: !0,
|
|
1654
1636
|
composed: !0
|
|
1655
1637
|
})
|
|
1656
|
-
), this.
|
|
1638
|
+
), this._$activeLine?.classList.remove("line--active"), this._$activeLine = null;
|
|
1657
1639
|
});
|
|
1658
1640
|
}
|
|
1659
1641
|
_onInput() {
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
const
|
|
1663
|
-
if (
|
|
1664
|
-
|
|
1642
|
+
if (!this._$editor)
|
|
1643
|
+
return;
|
|
1644
|
+
const t = se(this._$editor);
|
|
1645
|
+
if (t === this._value)
|
|
1646
|
+
return;
|
|
1647
|
+
const e = this._value, s = this._savedSelection, i = G(
|
|
1665
1648
|
[...this._pluginDecorations.values()],
|
|
1666
|
-
|
|
1667
|
-
|
|
1649
|
+
e,
|
|
1650
|
+
t
|
|
1668
1651
|
);
|
|
1669
1652
|
this._pluginDecorations.clear();
|
|
1670
|
-
for (const
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1653
|
+
for (const r of i)
|
|
1654
|
+
this._pluginDecorations.set(r.id, r);
|
|
1655
|
+
this._value = t, this._syncTextareaValue(!0), this._savedSelection = R(this._$editor), this._undoStack.length === 0 && (this._undoStack.push({
|
|
1656
|
+
value: e,
|
|
1657
|
+
anchorOffset: s?.anchorOffset ?? 0,
|
|
1658
|
+
focusOffset: s?.focusOffset ?? 0
|
|
1659
|
+
}), this._undoIndex = 0), this._pushUndo(this._savedSelection), this._dispatchChange(t), this._scheduleRender();
|
|
1676
1660
|
}
|
|
1677
1661
|
_updateActiveLine() {
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
const
|
|
1681
|
-
let
|
|
1682
|
-
if (
|
|
1683
|
-
let
|
|
1684
|
-
for (;
|
|
1685
|
-
if (
|
|
1686
|
-
|
|
1662
|
+
if (!this._$editor)
|
|
1663
|
+
return;
|
|
1664
|
+
const t = this.shadowRoot.getSelection?.() ?? window.getSelection();
|
|
1665
|
+
let e = null;
|
|
1666
|
+
if (t?.focusNode && this._$editor.contains(t.focusNode)) {
|
|
1667
|
+
let s = t.focusNode;
|
|
1668
|
+
for (; s && s !== this._$editor; ) {
|
|
1669
|
+
if (s instanceof HTMLElement && s.classList.contains("line")) {
|
|
1670
|
+
e = s;
|
|
1687
1671
|
break;
|
|
1688
1672
|
}
|
|
1689
|
-
|
|
1673
|
+
s = s.parentNode;
|
|
1690
1674
|
}
|
|
1691
1675
|
}
|
|
1692
|
-
|
|
1676
|
+
e !== this._$activeLine && (this._$activeLine?.classList.remove("line--active"), this._$activeLine = e, this._$activeLine?.classList.add("line--active"), this._updateActiveGutterCell());
|
|
1693
1677
|
}
|
|
1694
1678
|
_updateActiveGutterCell() {
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
const
|
|
1698
|
-
if (
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
const
|
|
1702
|
-
for (let
|
|
1703
|
-
if (
|
|
1704
|
-
const
|
|
1705
|
-
|
|
1679
|
+
if (!this._$gutterCells)
|
|
1680
|
+
return;
|
|
1681
|
+
const t = this._$gutterCells.querySelector(".gutter-cell--active");
|
|
1682
|
+
if (t && t.classList.remove("gutter-cell--active"), this._$activeLine) {
|
|
1683
|
+
if (!this._$editor)
|
|
1684
|
+
return;
|
|
1685
|
+
const e = this._$editor.querySelectorAll(".line");
|
|
1686
|
+
for (let s = 0; s < e.length; s++)
|
|
1687
|
+
if (e[s] === this._$activeLine) {
|
|
1688
|
+
const i = this._$gutterCells.children[s];
|
|
1689
|
+
i && i.classList.add("gutter-cell--active");
|
|
1706
1690
|
break;
|
|
1707
1691
|
}
|
|
1708
1692
|
}
|
|
1709
1693
|
}
|
|
1710
1694
|
_insertText(t) {
|
|
1711
|
-
|
|
1712
|
-
if (e) {
|
|
1695
|
+
if (this._$editor) {
|
|
1713
1696
|
if (t.includes(`
|
|
1714
1697
|
`)) {
|
|
1715
|
-
const
|
|
1698
|
+
const e = R(this._$editor) ?? this._savedSelection, s = Math.min(e?.anchorOffset ?? 0, e?.focusOffset ?? 0), i = Math.max(e?.anchorOffset ?? 0, e?.focusOffset ?? 0), r = this._value, o = r.slice(0, s) + t + r.slice(i), a = s + t.length, l = G(
|
|
1716
1699
|
[...this._pluginDecorations.values()],
|
|
1717
|
-
|
|
1718
|
-
|
|
1700
|
+
r,
|
|
1701
|
+
o
|
|
1719
1702
|
);
|
|
1720
1703
|
this._pluginDecorations.clear();
|
|
1721
|
-
for (const
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1704
|
+
for (const h of l)
|
|
1705
|
+
this._pluginDecorations.set(h.id, h);
|
|
1706
|
+
this._value = o, this._syncTextareaValue(!0), this._savedSelection = {
|
|
1707
|
+
anchorOffset: a,
|
|
1708
|
+
focusOffset: a
|
|
1725
1709
|
}, this._undoStack.length === 0 && (this._undoStack.push({
|
|
1726
|
-
value:
|
|
1727
|
-
anchorOffset:
|
|
1728
|
-
focusOffset:
|
|
1729
|
-
}), this._undoIndex = 0), this._pushUndo(this._savedSelection), this._dispatchChange(
|
|
1710
|
+
value: r,
|
|
1711
|
+
anchorOffset: e?.anchorOffset ?? 0,
|
|
1712
|
+
focusOffset: e?.focusOffset ?? 0
|
|
1713
|
+
}), this._undoIndex = 0), this._pushUndo(this._savedSelection), this._dispatchChange(o), this._scheduleRender();
|
|
1730
1714
|
return;
|
|
1731
1715
|
}
|
|
1732
1716
|
document.execCommand("insertText", !1, t), this._onInput();
|
|
@@ -1742,17 +1726,23 @@ const q = class q extends tt {
|
|
|
1742
1726
|
* anchor/focus offsets.
|
|
1743
1727
|
*/
|
|
1744
1728
|
wrapSelection(t, e) {
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
const
|
|
1748
|
-
if (!
|
|
1749
|
-
|
|
1729
|
+
if (!this._$editor)
|
|
1730
|
+
return;
|
|
1731
|
+
const s = R(this._$editor) ?? this._savedSelection;
|
|
1732
|
+
if (!s || s.anchorOffset === s.focusOffset)
|
|
1733
|
+
return;
|
|
1734
|
+
const i = Math.min(s.anchorOffset, s.focusOffset), r = Math.max(s.anchorOffset, s.focusOffset), o = this._value.slice(i, r), a = this._value, l = a.slice(0, i) + t + o + e + a.slice(r), h = G(
|
|
1735
|
+
[...this._pluginDecorations.values()],
|
|
1736
|
+
a,
|
|
1737
|
+
l
|
|
1738
|
+
);
|
|
1750
1739
|
this._pluginDecorations.clear();
|
|
1751
|
-
for (const
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1740
|
+
for (const c of h)
|
|
1741
|
+
this._pluginDecorations.set(c.id, c);
|
|
1742
|
+
this._value = l, this._syncTextareaValue(!0), this._savedSelection = {
|
|
1743
|
+
anchorOffset: i + t.length,
|
|
1744
|
+
focusOffset: i + t.length + o.length
|
|
1745
|
+
}, this._pushUndo(this._savedSelection), this._dispatchChange(l), this._scheduleRender();
|
|
1756
1746
|
}
|
|
1757
1747
|
/**
|
|
1758
1748
|
* Replace the current selection with `text`.
|
|
@@ -1761,8 +1751,7 @@ const q = class q extends tt {
|
|
|
1761
1751
|
replaceSelection(t) {
|
|
1762
1752
|
this._insertText(t);
|
|
1763
1753
|
}
|
|
1764
|
-
|
|
1765
|
-
/** Reset the undo/redo history. Call when the editor receives entirely new content. */
|
|
1754
|
+
/** Reset the undo/redo history. Call when the field receives entirely new content. */
|
|
1766
1755
|
clearHistory() {
|
|
1767
1756
|
this._undoStack = [], this._undoIndex = -1;
|
|
1768
1757
|
}
|
|
@@ -1772,7 +1761,7 @@ const q = class q extends tt {
|
|
|
1772
1761
|
anchorOffset: t?.anchorOffset ?? 0,
|
|
1773
1762
|
focusOffset: t?.focusOffset ?? 0
|
|
1774
1763
|
};
|
|
1775
|
-
this._undoStack = this._undoStack.slice(0, this._undoIndex + 1), this._undoStack.push(e), this._undoStack.length >
|
|
1764
|
+
this._undoStack = this._undoStack.slice(0, this._undoIndex + 1), this._undoStack.push(e), this._undoStack.length > de && this._undoStack.shift(), this._undoIndex = this._undoStack.length - 1;
|
|
1776
1765
|
}
|
|
1777
1766
|
_undo() {
|
|
1778
1767
|
this._undoIndex <= 0 || (this._undoIndex--, this._applyUndoEntry(this._undoStack[this._undoIndex]));
|
|
@@ -1786,10 +1775,15 @@ const q = class q extends tt {
|
|
|
1786
1775
|
focusOffset: t.focusOffset
|
|
1787
1776
|
}, this._syncTextareaValue(!0), this._dispatchChange(this._value), this._scheduleRender();
|
|
1788
1777
|
}
|
|
1789
|
-
|
|
1778
|
+
/**
|
|
1779
|
+
* Register and mount a plugin imperatively.
|
|
1780
|
+
* Replaces any currently active plugin. Prefer the `plugin` property for
|
|
1781
|
+
* reactive-framework integrations.
|
|
1782
|
+
*/
|
|
1790
1783
|
usePlugin(t) {
|
|
1791
1784
|
this._plugin?.destroy?.(), this._clearPluginSheets(), this._pluginDecorations.clear(), this._cursorCallbacks.clear(), this._pluginSeq++, this._plugin = t, this._pluginApi = this._buildPluginApi(), t.mount?.(this._pluginApi), this._scheduleRender();
|
|
1792
1785
|
}
|
|
1786
|
+
/** Unmount the active plugin, clear its decorations, and release its stylesheets. */
|
|
1793
1787
|
removePlugin() {
|
|
1794
1788
|
this._plugin?.destroy?.(), this._clearPluginSheets(), this._plugin = null, this._pluginApi = null, this._pluginDecorations.clear(), this._cursorCallbacks.clear(), this._pluginSeq++, this._scheduleRender();
|
|
1795
1789
|
}
|
|
@@ -1817,25 +1811,27 @@ const q = class q extends tt {
|
|
|
1817
1811
|
},
|
|
1818
1812
|
getCursorRect() {
|
|
1819
1813
|
const e = window.getSelection();
|
|
1820
|
-
if (!e?.focusNode
|
|
1821
|
-
|
|
1822
|
-
if (!s || !s.contains(e.focusNode)) return null;
|
|
1814
|
+
if (!e?.focusNode || !t._$editor || !t._$editor.contains(e.focusNode))
|
|
1815
|
+
return null;
|
|
1823
1816
|
try {
|
|
1824
|
-
const
|
|
1825
|
-
|
|
1826
|
-
const
|
|
1827
|
-
return
|
|
1817
|
+
const s = document.createRange();
|
|
1818
|
+
s.setStart(e.focusNode, e.focusOffset), s.collapse(!0);
|
|
1819
|
+
const i = s.getBoundingClientRect();
|
|
1820
|
+
return i.height > 0 ? i : null;
|
|
1828
1821
|
} catch {
|
|
1829
1822
|
return null;
|
|
1830
1823
|
}
|
|
1831
1824
|
},
|
|
1832
1825
|
getWordAtCursor() {
|
|
1833
1826
|
const e = t._savedSelection?.focusOffset ?? 0, s = t._value;
|
|
1834
|
-
if (!s)
|
|
1827
|
+
if (!s)
|
|
1828
|
+
return null;
|
|
1835
1829
|
let i = e;
|
|
1836
|
-
for (; i > 0 && /\w/.test(s[i - 1]); )
|
|
1830
|
+
for (; i > 0 && /\w/.test(s[i - 1]); )
|
|
1831
|
+
i--;
|
|
1837
1832
|
let r = e;
|
|
1838
|
-
for (; r < s.length && /\w/.test(s[r]); )
|
|
1833
|
+
for (; r < s.length && /\w/.test(s[r]); )
|
|
1834
|
+
r++;
|
|
1839
1835
|
return i === r ? null : { word: s.slice(i, r), from: i, to: r };
|
|
1840
1836
|
},
|
|
1841
1837
|
onCursorMove(e) {
|
|
@@ -1844,7 +1840,7 @@ const q = class q extends tt {
|
|
|
1844
1840
|
};
|
|
1845
1841
|
},
|
|
1846
1842
|
addDecoration(e) {
|
|
1847
|
-
return
|
|
1843
|
+
return ct(t._pluginDecorations, e);
|
|
1848
1844
|
},
|
|
1849
1845
|
removeDecoration(e) {
|
|
1850
1846
|
t._pluginDecorations.delete(e);
|
|
@@ -1853,7 +1849,7 @@ const q = class q extends tt {
|
|
|
1853
1849
|
t._pluginDecorations.clear();
|
|
1854
1850
|
},
|
|
1855
1851
|
setDecorations(e) {
|
|
1856
|
-
|
|
1852
|
+
le(t._pluginDecorations, e);
|
|
1857
1853
|
},
|
|
1858
1854
|
getDecorations() {
|
|
1859
1855
|
return [...t._pluginDecorations.values()];
|
|
@@ -1873,14 +1869,23 @@ const q = class q extends tt {
|
|
|
1873
1869
|
(i) => i !== e
|
|
1874
1870
|
)), t._pluginSheets.delete(e);
|
|
1875
1871
|
},
|
|
1872
|
+
parseDecorationsFromHtml(e) {
|
|
1873
|
+
return j(e);
|
|
1874
|
+
},
|
|
1875
|
+
/** @deprecated Use `parseDecorationsFromHtml` instead. */
|
|
1876
1876
|
decorationsFromHtml(e) {
|
|
1877
|
-
return
|
|
1877
|
+
return j(e);
|
|
1878
1878
|
},
|
|
1879
1879
|
decorationsFromTokens(e, s) {
|
|
1880
1880
|
const i = [];
|
|
1881
1881
|
for (const r of e) {
|
|
1882
1882
|
const o = s[r.type];
|
|
1883
|
-
o && i.push({
|
|
1883
|
+
o && i.push({
|
|
1884
|
+
type: "mark",
|
|
1885
|
+
from: r.from,
|
|
1886
|
+
to: r.to,
|
|
1887
|
+
...o
|
|
1888
|
+
});
|
|
1884
1889
|
}
|
|
1885
1890
|
return i;
|
|
1886
1891
|
},
|
|
@@ -1896,72 +1901,82 @@ const q = class q extends tt {
|
|
|
1896
1901
|
};
|
|
1897
1902
|
}
|
|
1898
1903
|
_clearPluginSheets() {
|
|
1899
|
-
if (this._pluginSheets.size === 0)
|
|
1904
|
+
if (this._pluginSheets.size === 0)
|
|
1905
|
+
return;
|
|
1900
1906
|
const t = this.shadowRoot;
|
|
1901
1907
|
t && (t.adoptedStyleSheets = t.adoptedStyleSheets.filter(
|
|
1902
1908
|
(e) => !this._pluginSheets.has(e)
|
|
1903
1909
|
)), this._pluginSheets.clear();
|
|
1904
1910
|
}
|
|
1905
|
-
|
|
1911
|
+
/**
|
|
1912
|
+
* Register a text pattern that generates decorations on every render pass.
|
|
1913
|
+
* Returns the pattern ID, which can be passed to `removePattern` to unregister it.
|
|
1914
|
+
*/
|
|
1906
1915
|
addPattern(t) {
|
|
1907
|
-
const e =
|
|
1916
|
+
const e = P();
|
|
1908
1917
|
return this._patterns.set(e, { ...t, id: e }), this._scheduleRender(), e;
|
|
1909
1918
|
}
|
|
1919
|
+
/** Remove a previously registered pattern by the ID returned from `addPattern`. */
|
|
1910
1920
|
removePattern(t) {
|
|
1911
1921
|
this._patterns.delete(t), this._scheduleRender();
|
|
1912
1922
|
}
|
|
1923
|
+
/** Remove all registered patterns and trigger a re-render. */
|
|
1913
1924
|
clearPatterns() {
|
|
1914
1925
|
this._patterns.clear(), this._scheduleRender();
|
|
1915
1926
|
}
|
|
1916
|
-
// ── Render pipeline ───────────────────────────────────────────────────
|
|
1917
1927
|
_scheduleRender() {
|
|
1918
1928
|
this._rafHandle === null && (this._rafHandle = requestAnimationFrame(() => {
|
|
1919
1929
|
this._rafHandle = null, this._performRender();
|
|
1920
1930
|
}));
|
|
1921
1931
|
}
|
|
1922
1932
|
async _performRender() {
|
|
1923
|
-
if (!this._document)
|
|
1933
|
+
if (!this._document)
|
|
1934
|
+
return;
|
|
1924
1935
|
this._isRendering = !0;
|
|
1925
1936
|
const t = ++this._pluginSeq;
|
|
1926
1937
|
try {
|
|
1927
1938
|
let e = this._value;
|
|
1928
1939
|
if (this._plugin && this._pluginApi && this._plugin.transform && this.readOnly) {
|
|
1929
|
-
const
|
|
1930
|
-
typeof
|
|
1940
|
+
const o = this._plugin.transform(this._value, this._pluginApi);
|
|
1941
|
+
typeof o == "string" && (e = o);
|
|
1931
1942
|
}
|
|
1932
|
-
const { markDecorations: s, lineDecorations: i } =
|
|
1943
|
+
const { markDecorations: s, lineDecorations: i } = ce(
|
|
1944
|
+
e,
|
|
1945
|
+
[...this._patterns.values()]
|
|
1946
|
+
);
|
|
1933
1947
|
if (this._patternDecorations = [
|
|
1934
|
-
...s.map((
|
|
1935
|
-
...i.map((
|
|
1948
|
+
...s.map((o) => ({ ...o, id: P() })),
|
|
1949
|
+
...i.map((o) => ({ ...o, id: P() }))
|
|
1936
1950
|
], this._plugin && this._pluginApi) {
|
|
1937
|
-
const
|
|
1938
|
-
if (this._plugin.update && (await this._plugin.update(e,
|
|
1951
|
+
const o = this._pluginApi;
|
|
1952
|
+
if (this._plugin.update && (await this._plugin.update(e, o), t !== this._pluginSeq))
|
|
1939
1953
|
return;
|
|
1940
1954
|
if (this._plugin.highlight) {
|
|
1941
|
-
const
|
|
1942
|
-
if (t !== this._pluginSeq)
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1955
|
+
const a = await this._plugin.highlight(e, o);
|
|
1956
|
+
if (t !== this._pluginSeq)
|
|
1957
|
+
return;
|
|
1958
|
+
if (typeof a == "string") {
|
|
1959
|
+
const l = j(a);
|
|
1960
|
+
for (const h of l)
|
|
1961
|
+
ct(this._pluginDecorations, h);
|
|
1947
1962
|
}
|
|
1948
1963
|
}
|
|
1949
1964
|
}
|
|
1950
1965
|
const r = [
|
|
1951
1966
|
...this._pluginDecorations.values(),
|
|
1952
1967
|
...this._patternDecorations,
|
|
1953
|
-
...this._externalDecorations.map((
|
|
1954
|
-
]
|
|
1955
|
-
if (!
|
|
1956
|
-
|
|
1968
|
+
...this._externalDecorations.map((o) => ({ ...o, id: P() }))
|
|
1969
|
+
];
|
|
1970
|
+
if (!this._$editor)
|
|
1971
|
+
return;
|
|
1972
|
+
this._document.build(e, r), this._savedSelection && re(this._$editor, this._savedSelection), this._$activeLine = null, this._updateActiveLine(), this._syncGutter(this._computeGutterLabels(r, e)), this._syncGutterHeights();
|
|
1957
1973
|
} finally {
|
|
1958
1974
|
this._isRendering = !1;
|
|
1959
1975
|
}
|
|
1960
1976
|
}
|
|
1961
|
-
// ── Gutter ────────────────────────────────────────────────────────────
|
|
1962
1977
|
/**
|
|
1963
1978
|
* Compute the label string for each gutter cell based on the current gutter
|
|
1964
|
-
* mode (`lineNumbers`, `listNumbers
|
|
1979
|
+
* mode (`lineNumbers`, `listNumbers` (deprecated), `gutter`) and any
|
|
1965
1980
|
* `LineDecoration.gutterContent` overrides in `allDecorations`.
|
|
1966
1981
|
*
|
|
1967
1982
|
* Returns one entry per line (same length as `value.split('\n')`):
|
|
@@ -1981,7 +1996,7 @@ const q = class q extends tt {
|
|
|
1981
1996
|
}
|
|
1982
1997
|
/**
|
|
1983
1998
|
* Synchronize the pixel height of each gutter cell to match the
|
|
1984
|
-
* corresponding `.
|
|
1999
|
+
* corresponding `.line` element in the editor.
|
|
1985
2000
|
*
|
|
1986
2001
|
* In non-word-wrap mode the gutter uses a uniform `line-height` mirrored
|
|
1987
2002
|
* from the editor's first line. In word-wrap mode each cell gets an explicit
|
|
@@ -1990,24 +2005,24 @@ const q = class q extends tt {
|
|
|
1990
2005
|
* gutter to compensate for browser UA overrides on contenteditable.
|
|
1991
2006
|
*/
|
|
1992
2007
|
_syncGutterHeights() {
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
const
|
|
1996
|
-
|
|
1997
|
-
const
|
|
2008
|
+
if (!this._$gutterCells || !this._$editor)
|
|
2009
|
+
return;
|
|
2010
|
+
const t = getComputedStyle(this._$editor), e = t.paddingTop, s = t.paddingBottom;
|
|
2011
|
+
this._$gutterCells.style.paddingTop !== e && (this._$gutterCells.style.paddingTop = e), this._$gutterCells.style.paddingBottom !== s && (this._$gutterCells.style.paddingBottom = s);
|
|
2012
|
+
const i = this._$editor.querySelectorAll(".line"), r = this._$gutterCells.children;
|
|
1998
2013
|
if (!this.wordWrap) {
|
|
1999
|
-
if (
|
|
2000
|
-
const
|
|
2001
|
-
|
|
2014
|
+
if (i.length > 0) {
|
|
2015
|
+
const o = `${i[0].getBoundingClientRect().height}px`;
|
|
2016
|
+
this._$gutterCells.style.lineHeight !== o && (this._$gutterCells.style.lineHeight = o);
|
|
2002
2017
|
}
|
|
2003
|
-
for (let
|
|
2004
|
-
|
|
2018
|
+
for (let o = 0; o < r.length; o++)
|
|
2019
|
+
r[o].style.height = "";
|
|
2005
2020
|
return;
|
|
2006
2021
|
}
|
|
2007
|
-
|
|
2008
|
-
for (let
|
|
2009
|
-
const
|
|
2010
|
-
|
|
2022
|
+
this._$gutterCells.style.lineHeight && (this._$gutterCells.style.lineHeight = "");
|
|
2023
|
+
for (let o = 0; o < i.length && o < r.length; o++) {
|
|
2024
|
+
const l = `${i[o].getBoundingClientRect().height}px`, h = r[o];
|
|
2025
|
+
h.style.height !== l && (h.style.height = l);
|
|
2011
2026
|
}
|
|
2012
2027
|
}
|
|
2013
2028
|
/**
|
|
@@ -2017,27 +2032,46 @@ const q = class q extends tt {
|
|
|
2017
2032
|
* (called by the `ResizeObserver` without a new render pass).
|
|
2018
2033
|
*/
|
|
2019
2034
|
_syncGutter(t) {
|
|
2020
|
-
if (!this.lineNumbers && !this.listNumbers && !this.gutter)
|
|
2021
|
-
|
|
2022
|
-
if (!e) return;
|
|
2035
|
+
if (!this.lineNumbers && !this.listNumbers && !this.gutter || !this._$gutterCells)
|
|
2036
|
+
return;
|
|
2023
2037
|
t !== void 0 && (this._gutterLabels = t);
|
|
2024
|
-
const
|
|
2025
|
-
for (;
|
|
2026
|
-
const
|
|
2027
|
-
|
|
2038
|
+
const e = this._gutterLabels;
|
|
2039
|
+
for (; this._$gutterCells.children.length < e.length; ) {
|
|
2040
|
+
const s = document.createElement("span");
|
|
2041
|
+
s.className = "gutter-cell", this._$gutterCells.appendChild(s);
|
|
2028
2042
|
}
|
|
2029
|
-
for (;
|
|
2030
|
-
|
|
2031
|
-
for (let
|
|
2032
|
-
const
|
|
2033
|
-
|
|
2043
|
+
for (; this._$gutterCells.children.length > e.length; )
|
|
2044
|
+
this._$gutterCells.removeChild(this._$gutterCells.lastChild);
|
|
2045
|
+
for (let s = 0; s < e.length; s++) {
|
|
2046
|
+
const i = e[s] ?? "", r = this._$gutterCells.children[s];
|
|
2047
|
+
r.textContent !== i && (r.textContent = i);
|
|
2034
2048
|
}
|
|
2035
2049
|
}
|
|
2036
|
-
|
|
2050
|
+
_syncLabel() {
|
|
2051
|
+
if (!this._$editor)
|
|
2052
|
+
return;
|
|
2053
|
+
const t = this._$textareaRef?.deref(), e = t?.getAttribute("aria-label");
|
|
2054
|
+
if (e) {
|
|
2055
|
+
this._$editor.setAttribute("aria-label", e);
|
|
2056
|
+
return;
|
|
2057
|
+
}
|
|
2058
|
+
if (t) {
|
|
2059
|
+
const s = Array.from(t.labels ?? []).map((i) => i.textContent?.trim()).filter(Boolean).join(" ");
|
|
2060
|
+
if (s) {
|
|
2061
|
+
this._$editor.setAttribute("aria-label", s);
|
|
2062
|
+
return;
|
|
2063
|
+
}
|
|
2064
|
+
}
|
|
2065
|
+
if (this._label) {
|
|
2066
|
+
this._$editor.setAttribute("aria-label", this._label);
|
|
2067
|
+
return;
|
|
2068
|
+
}
|
|
2069
|
+
this._$editor.removeAttribute("aria-label");
|
|
2070
|
+
}
|
|
2037
2071
|
_syncTypography(t) {
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
const
|
|
2072
|
+
if (!this._$editor)
|
|
2073
|
+
return;
|
|
2074
|
+
const e = window.getComputedStyle(t), s = [
|
|
2041
2075
|
"fontFamily",
|
|
2042
2076
|
"fontSize",
|
|
2043
2077
|
"fontWeight",
|
|
@@ -2050,14 +2084,13 @@ const q = class q extends tt {
|
|
|
2050
2084
|
"tabSize"
|
|
2051
2085
|
];
|
|
2052
2086
|
if (!window.getComputedStyle(this).getPropertyValue("--rc-textarea-font-family"))
|
|
2053
|
-
for (const
|
|
2054
|
-
const
|
|
2055
|
-
|
|
2087
|
+
for (const r of s) {
|
|
2088
|
+
const o = e[r];
|
|
2089
|
+
o && typeof o == "string" && (this._$editor.style[r] = o);
|
|
2056
2090
|
}
|
|
2057
2091
|
}
|
|
2058
|
-
// ── Form integration ──────────────────────────────────────────────────
|
|
2059
2092
|
_syncTextareaValue(t = !1) {
|
|
2060
|
-
const e = this.
|
|
2093
|
+
const e = this._$textareaRef?.deref();
|
|
2061
2094
|
e && (e.value = this._value, t && e.dispatchEvent(new InputEvent("input", { bubbles: !0 })));
|
|
2062
2095
|
}
|
|
2063
2096
|
_dispatchChange(t) {
|
|
@@ -2069,50 +2102,55 @@ const q = class q extends tt {
|
|
|
2069
2102
|
})
|
|
2070
2103
|
);
|
|
2071
2104
|
}
|
|
2072
|
-
// ── Helpers ───────────────────────────────────────────────────────────
|
|
2073
|
-
_getEditorEl() {
|
|
2074
|
-
return this.shadowRoot?.getElementById("editor");
|
|
2075
|
-
}
|
|
2076
2105
|
};
|
|
2077
|
-
|
|
2078
|
-
...
|
|
2106
|
+
K.styles = Bt, K.shadowRootOptions = {
|
|
2107
|
+
...st.shadowRootOptions,
|
|
2079
2108
|
delegatesFocus: !0
|
|
2080
2109
|
};
|
|
2081
|
-
let _ =
|
|
2082
|
-
|
|
2083
|
-
|
|
2110
|
+
let _ = K;
|
|
2111
|
+
b([
|
|
2112
|
+
y({ type: Boolean, attribute: "line-numbers", reflect: !0 })
|
|
2084
2113
|
], _.prototype, "lineNumbers", 2);
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
], _.prototype, "listNumbers",
|
|
2088
|
-
|
|
2089
|
-
|
|
2114
|
+
b([
|
|
2115
|
+
y({ type: Boolean, attribute: "list-numbers", reflect: !0 })
|
|
2116
|
+
], _.prototype, "listNumbers", 1);
|
|
2117
|
+
b([
|
|
2118
|
+
y({ type: Boolean, attribute: "gutter", reflect: !0 })
|
|
2090
2119
|
], _.prototype, "gutter", 2);
|
|
2091
|
-
|
|
2092
|
-
|
|
2120
|
+
b([
|
|
2121
|
+
y({ type: Boolean, attribute: "word-wrap", reflect: !0 })
|
|
2093
2122
|
], _.prototype, "wordWrap", 2);
|
|
2094
|
-
|
|
2095
|
-
|
|
2123
|
+
b([
|
|
2124
|
+
y({ type: Boolean, attribute: "auto-grow", reflect: !0 })
|
|
2096
2125
|
], _.prototype, "autoGrow", 2);
|
|
2097
|
-
|
|
2098
|
-
|
|
2126
|
+
b([
|
|
2127
|
+
y({ type: Boolean, attribute: "read-only", reflect: !0 })
|
|
2099
2128
|
], _.prototype, "readOnly", 2);
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
], _.prototype, "label",
|
|
2103
|
-
|
|
2104
|
-
|
|
2129
|
+
b([
|
|
2130
|
+
y({ type: String })
|
|
2131
|
+
], _.prototype, "label", 1);
|
|
2132
|
+
b([
|
|
2133
|
+
y({ attribute: !1 })
|
|
2105
2134
|
], _.prototype, "plugin", 1);
|
|
2106
|
-
|
|
2107
|
-
|
|
2135
|
+
b([
|
|
2136
|
+
y({ attribute: !1 })
|
|
2108
2137
|
], _.prototype, "decorations", 1);
|
|
2109
|
-
|
|
2110
|
-
|
|
2138
|
+
b([
|
|
2139
|
+
tt("#editor", !0)
|
|
2140
|
+
], _.prototype, "_$editor", 2);
|
|
2141
|
+
b([
|
|
2142
|
+
tt("#gutter-cells", !0)
|
|
2143
|
+
], _.prototype, "_$gutterCells", 2);
|
|
2144
|
+
b([
|
|
2145
|
+
tt("slot", !0)
|
|
2146
|
+
], _.prototype, "_$slot", 2);
|
|
2147
|
+
b([
|
|
2148
|
+
y({ type: String })
|
|
2111
2149
|
], _.prototype, "value", 1);
|
|
2112
|
-
|
|
2113
|
-
|
|
2150
|
+
b([
|
|
2151
|
+
y({ type: String })
|
|
2114
2152
|
], _.prototype, "defaultValue", 1);
|
|
2115
|
-
function
|
|
2153
|
+
function we(n, t = {}) {
|
|
2116
2154
|
const e = [];
|
|
2117
2155
|
return {
|
|
2118
2156
|
mount(s) {
|
|
@@ -2144,8 +2182,8 @@ function ye(n, t = {}) {
|
|
|
2144
2182
|
}
|
|
2145
2183
|
};
|
|
2146
2184
|
}
|
|
2147
|
-
const
|
|
2148
|
-
|
|
2185
|
+
const Et = new CSSStyleSheet();
|
|
2186
|
+
Et.replaceSync(`
|
|
2149
2187
|
.rc-line-actions {
|
|
2150
2188
|
display: inline-flex;
|
|
2151
2189
|
align-items: center;
|
|
@@ -2175,7 +2213,7 @@ xt.replaceSync(`
|
|
|
2175
2213
|
color: var(--rc-line-action-hover-color, inherit);
|
|
2176
2214
|
}
|
|
2177
2215
|
`);
|
|
2178
|
-
const
|
|
2216
|
+
const ht = "rc-line-actions-popover-style", fe = `
|
|
2179
2217
|
.rc-line-actions-popover {
|
|
2180
2218
|
position: fixed;
|
|
2181
2219
|
z-index: 9999;
|
|
@@ -2211,9 +2249,9 @@ const ct = "rc-line-actions-popover-style", ue = `
|
|
|
2211
2249
|
background: var(--rc-line-action-hover-bg, ButtonFace);
|
|
2212
2250
|
}
|
|
2213
2251
|
`;
|
|
2214
|
-
class
|
|
2252
|
+
class Ct {
|
|
2215
2253
|
constructor(t, e) {
|
|
2216
|
-
this._popover = null, this._lastActionsKey = "", this._api = t, this._options = e ?? {}, t.adoptStyleSheet(
|
|
2254
|
+
this._popover = null, this._lastActionsKey = "", this._api = t, this._options = e ?? {}, t.adoptStyleSheet(Et), this._blurHandler = () => this._hidePopover(), t.host.addEventListener("rc-textarea-blur", this._blurHandler);
|
|
2217
2255
|
}
|
|
2218
2256
|
/**
|
|
2219
2257
|
* Call from plugin's `update()`. Pass the line index, its actions, the full
|
|
@@ -2227,15 +2265,19 @@ class wt {
|
|
|
2227
2265
|
getDecorations(t, e, s, i) {
|
|
2228
2266
|
if (i === "popover")
|
|
2229
2267
|
return e.length === 0 ? this._hidePopover() : this._showPopover(e), [];
|
|
2230
|
-
if (this._hidePopover(), e.length === 0)
|
|
2231
|
-
|
|
2268
|
+
if (this._hidePopover(), e.length === 0)
|
|
2269
|
+
return [];
|
|
2270
|
+
const r = Ct._lineEndOffset(s, t), o = [...e], a = {
|
|
2271
|
+
renderButton: this._options.renderButton,
|
|
2272
|
+
createIcon: this._options.createIcon
|
|
2273
|
+
};
|
|
2232
2274
|
return [
|
|
2233
2275
|
{
|
|
2234
2276
|
type: "widget",
|
|
2235
2277
|
offset: r,
|
|
2236
2278
|
side: "after",
|
|
2237
2279
|
create() {
|
|
2238
|
-
return
|
|
2280
|
+
return pe(o, a);
|
|
2239
2281
|
}
|
|
2240
2282
|
}
|
|
2241
2283
|
];
|
|
@@ -2268,7 +2310,6 @@ class wt {
|
|
|
2268
2310
|
return t.slice(0, e).split(`
|
|
2269
2311
|
`).length - 1;
|
|
2270
2312
|
}
|
|
2271
|
-
// ── Private helpers ───────────────────────────────────────────────────────
|
|
2272
2313
|
/**
|
|
2273
2314
|
* Character offset of the end of the given 0-based line (points at the
|
|
2274
2315
|
* newline character, or end-of-string for the last line).
|
|
@@ -2283,21 +2324,21 @@ class wt {
|
|
|
2283
2324
|
}
|
|
2284
2325
|
_showPopover(t) {
|
|
2285
2326
|
const e = t.map((s) => s.id).join(",");
|
|
2286
|
-
if (!document.getElementById(
|
|
2327
|
+
if (!document.getElementById(ht)) {
|
|
2287
2328
|
const s = document.createElement("style");
|
|
2288
|
-
s.id =
|
|
2329
|
+
s.id = ht, s.textContent = fe, document.head.appendChild(s);
|
|
2289
2330
|
}
|
|
2290
|
-
this._popover || (this._popover = document.createElement("div"), this._popover.className = "rc-line-actions-popover", this._popover.addEventListener("mousedown", (s) => s.preventDefault()), document.body.appendChild(this._popover)), e !== this._lastActionsKey && (this._lastActionsKey = e, this._popover.innerHTML = "",
|
|
2331
|
+
this._popover || (this._popover = document.createElement("div"), this._popover.className = "rc-line-actions-popover", this._popover.addEventListener("mousedown", (s) => s.preventDefault()), document.body.appendChild(this._popover)), e !== this._lastActionsKey && (this._lastActionsKey = e, this._popover.innerHTML = "", me(this._popover, t, this._options)), this._positionPopover();
|
|
2291
2332
|
}
|
|
2292
2333
|
_positionPopover() {
|
|
2293
|
-
if (!this._popover)
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
t ? (
|
|
2334
|
+
if (!this._popover)
|
|
2335
|
+
return;
|
|
2336
|
+
const t = this._api.getCursorRect(), e = this._api.host.getBoundingClientRect(), s = this._popover.offsetHeight || 32;
|
|
2337
|
+
let i;
|
|
2338
|
+
t ? (i = t.bottom + 4, i + s > window.innerHeight && (i = t.top - s - 4)) : i = e.bottom + 4;
|
|
2298
2339
|
const r = this._popover.offsetWidth || 120;
|
|
2299
2340
|
let o = e.left;
|
|
2300
|
-
o = Math.min(o, window.innerWidth - r - 8), o = Math.max(o, 8), this._popover.style.top = `${
|
|
2341
|
+
o = Math.min(o, window.innerWidth - r - 8), o = Math.max(o, 8), this._popover.style.top = `${i}px`, this._popover.style.left = `${o}px`;
|
|
2301
2342
|
}
|
|
2302
2343
|
_hidePopover() {
|
|
2303
2344
|
this._popover && (this._popover.remove(), this._popover = null, this._lastActionsKey = "");
|
|
@@ -2307,28 +2348,28 @@ function At(n, t) {
|
|
|
2307
2348
|
const e = document.createElement("button");
|
|
2308
2349
|
if (e.className = "rc-line-action-btn", e.type = "button", e.setAttribute("title", n.label), t.renderButton)
|
|
2309
2350
|
t.renderButton(n, e);
|
|
2310
|
-
else if (n.
|
|
2311
|
-
const s = t.createIcon?.(n.
|
|
2312
|
-
s ? (e.setAttribute("aria-label", n.label), e.appendChild(s)) : (e.dataset.icon = n.
|
|
2351
|
+
else if (n.iconName) {
|
|
2352
|
+
const s = t.createIcon?.(n.iconName) ?? null;
|
|
2353
|
+
s ? (e.setAttribute("aria-label", n.label), e.appendChild(s)) : (e.dataset.icon = n.iconName, e.setAttribute("aria-label", n.label));
|
|
2313
2354
|
} else
|
|
2314
2355
|
e.textContent = n.label;
|
|
2315
2356
|
return e.addEventListener("mousedown", (s) => s.preventDefault()), e.addEventListener("click", () => n.onClick()), e;
|
|
2316
2357
|
}
|
|
2317
|
-
function
|
|
2358
|
+
function pe(n, t) {
|
|
2318
2359
|
const e = document.createElement("span");
|
|
2319
2360
|
e.className = "rc-line-actions";
|
|
2320
2361
|
for (const s of n)
|
|
2321
2362
|
e.appendChild(At(s, t));
|
|
2322
2363
|
return e;
|
|
2323
2364
|
}
|
|
2324
|
-
function
|
|
2365
|
+
function me(n, t, e) {
|
|
2325
2366
|
for (const s of t)
|
|
2326
2367
|
n.appendChild(At(s, e));
|
|
2327
2368
|
}
|
|
2328
2369
|
export {
|
|
2329
|
-
|
|
2370
|
+
Ct as L,
|
|
2330
2371
|
_ as R,
|
|
2331
|
-
|
|
2332
|
-
|
|
2372
|
+
we as c,
|
|
2373
|
+
ce as m
|
|
2333
2374
|
};
|
|
2334
|
-
//# sourceMappingURL=line-actions-controller-
|
|
2375
|
+
//# sourceMappingURL=line-actions-controller-ChmbiQ-G.js.map
|