@cascivo/editor 0.2.2 → 0.2.5
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/dist/editor.css +1 -1
- package/dist/index.d.ts +24 -1
- package/dist/index.js +496 -302
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { cn as e,
|
|
3
|
-
import { builtin as
|
|
4
|
-
import { forwardRef as
|
|
5
|
-
import { jsx as
|
|
2
|
+
import { cn as e, useAnchorPosition as t, useControllableSignal as n, useId as r, useSignal as i, useSignalEffect as a, useSignals as o } from "@cascivo/core";
|
|
3
|
+
import { builtin as s, t as c } from "@cascivo/i18n";
|
|
4
|
+
import { forwardRef as l, useImperativeHandle as ee, useRef as u } from "react";
|
|
5
|
+
import { jsx as d, jsxs as f } from "react/jsx-runtime";
|
|
6
6
|
//#region src/engine/tokenize.ts
|
|
7
|
-
var
|
|
8
|
-
function
|
|
9
|
-
let r = `${e.name}${
|
|
7
|
+
var p = /* @__PURE__ */ new Map(), m = "\0", h = 0;
|
|
8
|
+
function g(e, t, n) {
|
|
9
|
+
let r = `${e.name}${m}${n}${m}${t}`, i = p.get(r);
|
|
10
10
|
if (i) return i;
|
|
11
|
-
|
|
11
|
+
h++;
|
|
12
12
|
let { tokens: a, state: o } = e.tokenizeLine(t, n), s = {
|
|
13
13
|
tokens: a,
|
|
14
14
|
endState: o
|
|
15
15
|
};
|
|
16
|
-
return
|
|
16
|
+
return p.set(r, s), s;
|
|
17
17
|
}
|
|
18
|
-
function
|
|
18
|
+
function _(e, t) {
|
|
19
19
|
let n = t.split("\n"), r = [], i = e.initialState;
|
|
20
20
|
for (let t of n) {
|
|
21
|
-
let n =
|
|
21
|
+
let n = g(e, t, i);
|
|
22
22
|
r.push(n.tokens), i = n.endState;
|
|
23
23
|
}
|
|
24
24
|
return r;
|
|
@@ -26,7 +26,7 @@ function h(e, t) {
|
|
|
26
26
|
function te(e, t, n, r, i) {
|
|
27
27
|
let a = Math.max(0, Math.min(n, t.length)), o = Math.max(a, Math.min(r, t.length)), s = i.startStateOf(t, a), c = [];
|
|
28
28
|
for (let n = a; n < o; n++) {
|
|
29
|
-
let r =
|
|
29
|
+
let r = g(e, t[n], s);
|
|
30
30
|
c.push(r.tokens), i.setEndState(n, r.endState), s = r.endState;
|
|
31
31
|
}
|
|
32
32
|
return c;
|
|
@@ -39,7 +39,7 @@ function ne(e) {
|
|
|
39
39
|
if (a > i) return;
|
|
40
40
|
let o = a === 0 ? e.initialState : t[a - 1];
|
|
41
41
|
for (; a <= i; a++) {
|
|
42
|
-
let r =
|
|
42
|
+
let r = g(e, n[a], o);
|
|
43
43
|
t[a] = r.endState, o = r.endState;
|
|
44
44
|
}
|
|
45
45
|
};
|
|
@@ -61,7 +61,7 @@ function ne(e) {
|
|
|
61
61
|
}
|
|
62
62
|
//#endregion
|
|
63
63
|
//#region src/engine/registry.ts
|
|
64
|
-
var
|
|
64
|
+
var v = /* @__PURE__ */ new Map(), y = {
|
|
65
65
|
name: "plaintext",
|
|
66
66
|
initialState: "default",
|
|
67
67
|
tokenizeLine: (e) => ({
|
|
@@ -72,23 +72,23 @@ var g = /* @__PURE__ */ new Map(), _ = {
|
|
|
72
72
|
state: "default"
|
|
73
73
|
})
|
|
74
74
|
};
|
|
75
|
-
|
|
76
|
-
function
|
|
77
|
-
|
|
75
|
+
v.set(y.name, y);
|
|
76
|
+
function b(e) {
|
|
77
|
+
v.set(e.name, e);
|
|
78
78
|
}
|
|
79
79
|
function re(e) {
|
|
80
80
|
if (e !== void 0) {
|
|
81
|
-
let t =
|
|
81
|
+
let t = v.get(e);
|
|
82
82
|
if (t) return t;
|
|
83
83
|
}
|
|
84
|
-
return
|
|
84
|
+
return v.get("plaintext");
|
|
85
85
|
}
|
|
86
|
-
function
|
|
87
|
-
return [...
|
|
86
|
+
function x() {
|
|
87
|
+
return [...v.keys()];
|
|
88
88
|
}
|
|
89
89
|
//#endregion
|
|
90
90
|
//#region src/grammars/rules.ts
|
|
91
|
-
function
|
|
91
|
+
function S(e) {
|
|
92
92
|
let t = {};
|
|
93
93
|
for (let [n, r] of Object.entries(e.states)) t[n] = r.map((e) => {
|
|
94
94
|
let t = `${e.match.flags.replace(/[gy]/g, "")}y`, n = {
|
|
@@ -131,7 +131,7 @@ function b(e) {
|
|
|
131
131
|
}
|
|
132
132
|
//#endregion
|
|
133
133
|
//#region src/grammars/plaintext.ts
|
|
134
|
-
var
|
|
134
|
+
var ie = {
|
|
135
135
|
name: "plaintext",
|
|
136
136
|
initialState: "default",
|
|
137
137
|
tokenizeLine: (e) => ({
|
|
@@ -142,10 +142,10 @@ var x = {
|
|
|
142
142
|
state: "default"
|
|
143
143
|
})
|
|
144
144
|
};
|
|
145
|
-
|
|
145
|
+
b(ie);
|
|
146
146
|
//#endregion
|
|
147
147
|
//#region src/grammars/json.ts
|
|
148
|
-
var
|
|
148
|
+
var ae = S({
|
|
149
149
|
name: "json",
|
|
150
150
|
states: { default: [
|
|
151
151
|
{
|
|
@@ -174,14 +174,14 @@ var S = b({
|
|
|
174
174
|
}
|
|
175
175
|
] }
|
|
176
176
|
});
|
|
177
|
-
|
|
177
|
+
b(ae);
|
|
178
178
|
//#endregion
|
|
179
179
|
//#region src/grammars/clike.ts
|
|
180
|
-
var
|
|
181
|
-
function
|
|
180
|
+
var oe = /* @__PURE__ */ "async.await.break.case.catch.class.const.continue.debugger.default.delete.do.else.export.extends.finally.for.function.if.import.in.instanceof.let.new.of.return.static.super.switch.this.throw.try.typeof.var.void.while.with.yield.as.from.get.set".split(".");
|
|
181
|
+
function se(e) {
|
|
182
182
|
return RegExp(`(?:${e.join("|")})\\b`);
|
|
183
183
|
}
|
|
184
|
-
function
|
|
184
|
+
function C(e, t, n = []) {
|
|
185
185
|
let r = [
|
|
186
186
|
{
|
|
187
187
|
match: /\/\/.*/,
|
|
@@ -215,10 +215,10 @@ function T(e, t, n = []) {
|
|
|
215
215
|
}
|
|
216
216
|
];
|
|
217
217
|
return n.length > 0 && r.push({
|
|
218
|
-
match:
|
|
218
|
+
match: se(n),
|
|
219
219
|
kind: "type"
|
|
220
220
|
}), r.push({
|
|
221
|
-
match:
|
|
221
|
+
match: se(t),
|
|
222
222
|
kind: "keyword"
|
|
223
223
|
}, {
|
|
224
224
|
match: /[A-Za-z_$][\w$]*(?=\s*\()/,
|
|
@@ -235,7 +235,7 @@ function T(e, t, n = []) {
|
|
|
235
235
|
}, {
|
|
236
236
|
match: /[{}()[\];,.:]/,
|
|
237
237
|
kind: "punctuation"
|
|
238
|
-
}),
|
|
238
|
+
}), S({
|
|
239
239
|
name: e,
|
|
240
240
|
states: {
|
|
241
241
|
default: r,
|
|
@@ -282,9 +282,9 @@ function T(e, t, n = []) {
|
|
|
282
282
|
}
|
|
283
283
|
//#endregion
|
|
284
284
|
//#region src/grammars/javascript.ts
|
|
285
|
-
var
|
|
286
|
-
|
|
287
|
-
var
|
|
285
|
+
var ce = C("javascript", oe);
|
|
286
|
+
b(ce);
|
|
287
|
+
var le = C("typescript", oe, [
|
|
288
288
|
"interface",
|
|
289
289
|
"type",
|
|
290
290
|
"enum",
|
|
@@ -310,10 +310,10 @@ var ae = T("typescript", C, [
|
|
|
310
310
|
"never",
|
|
311
311
|
"object"
|
|
312
312
|
]);
|
|
313
|
-
|
|
313
|
+
b(le);
|
|
314
314
|
//#endregion
|
|
315
315
|
//#region src/grammars/css.ts
|
|
316
|
-
var
|
|
316
|
+
var w = S({
|
|
317
317
|
name: "css",
|
|
318
318
|
states: {
|
|
319
319
|
default: [
|
|
@@ -380,10 +380,10 @@ var oe = b({
|
|
|
380
380
|
]
|
|
381
381
|
}
|
|
382
382
|
});
|
|
383
|
-
|
|
383
|
+
b(w);
|
|
384
384
|
//#endregion
|
|
385
385
|
//#region src/grammars/html.ts
|
|
386
|
-
var
|
|
386
|
+
var ue = S({
|
|
387
387
|
name: "html",
|
|
388
388
|
states: {
|
|
389
389
|
default: [
|
|
@@ -442,10 +442,10 @@ var se = b({
|
|
|
442
442
|
]
|
|
443
443
|
}
|
|
444
444
|
});
|
|
445
|
-
|
|
445
|
+
b(ue);
|
|
446
446
|
//#endregion
|
|
447
447
|
//#region src/grammars/markdown.ts
|
|
448
|
-
var
|
|
448
|
+
var de = S({
|
|
449
449
|
name: "markdown",
|
|
450
450
|
states: {
|
|
451
451
|
default: [
|
|
@@ -518,10 +518,10 @@ var ce = b({
|
|
|
518
518
|
}]
|
|
519
519
|
}
|
|
520
520
|
});
|
|
521
|
-
|
|
521
|
+
b(de);
|
|
522
522
|
//#endregion
|
|
523
523
|
//#region src/grammars/bash.ts
|
|
524
|
-
var
|
|
524
|
+
var fe = S({
|
|
525
525
|
name: "bash",
|
|
526
526
|
states: { default: [
|
|
527
527
|
{
|
|
@@ -558,8 +558,8 @@ var le = b({
|
|
|
558
558
|
}
|
|
559
559
|
] }
|
|
560
560
|
});
|
|
561
|
-
|
|
562
|
-
var
|
|
561
|
+
b(fe);
|
|
562
|
+
var T = {
|
|
563
563
|
root: "_root_1m6ns_2",
|
|
564
564
|
gutter: "_gutter_1m6ns_17",
|
|
565
565
|
gutterLine: "_gutterLine_1m6ns_28",
|
|
@@ -588,77 +588,77 @@ var E = {
|
|
|
588
588
|
};
|
|
589
589
|
//#endregion
|
|
590
590
|
//#region src/editor/view.tsx
|
|
591
|
-
function
|
|
591
|
+
function pe(e, t) {
|
|
592
592
|
let n = "";
|
|
593
593
|
for (let r of t) e >= r.start && e < r.end && (n = n ? `${n} ${r.className}` : r.className);
|
|
594
594
|
return n;
|
|
595
595
|
}
|
|
596
|
-
function
|
|
596
|
+
function me(t, n, r, i) {
|
|
597
597
|
let a = n + t.value.length, o = new Set([n, a]);
|
|
598
598
|
for (let e of r) e.start > n && e.start < a && o.add(e.start), e.end > n && e.end < a && o.add(e.end);
|
|
599
599
|
if (o.size === 2) {
|
|
600
|
-
let a =
|
|
601
|
-
return /* @__PURE__ */
|
|
602
|
-
className: a ? e(
|
|
600
|
+
let a = pe(n, r);
|
|
601
|
+
return /* @__PURE__ */ d("span", {
|
|
602
|
+
className: a ? e(T[t.kind], a) : T[t.kind],
|
|
603
603
|
children: t.value
|
|
604
604
|
}, i);
|
|
605
605
|
}
|
|
606
606
|
let s = [...o].sort((e, t) => e - t), c = [];
|
|
607
607
|
for (let i = 0; i < s.length - 1; i++) {
|
|
608
|
-
let a = s[i], o = s[i + 1], l =
|
|
609
|
-
c.push(/* @__PURE__ */
|
|
610
|
-
className: l ? e(
|
|
608
|
+
let a = s[i], o = s[i + 1], l = pe(a, r);
|
|
609
|
+
c.push(/* @__PURE__ */ d("span", {
|
|
610
|
+
className: l ? e(T[t.kind], l) : T[t.kind],
|
|
611
611
|
children: t.value.slice(a - n, o - n)
|
|
612
612
|
}, a));
|
|
613
613
|
}
|
|
614
|
-
return /* @__PURE__ */
|
|
614
|
+
return /* @__PURE__ */ d("span", { children: c }, i);
|
|
615
615
|
}
|
|
616
|
-
function
|
|
616
|
+
function he(e, t = 0, n = t + e.length, r) {
|
|
617
617
|
let i = [];
|
|
618
618
|
for (let a = t; a < n; a++) {
|
|
619
619
|
let n = e[a - t], o = r?.filter((e) => e.line === a);
|
|
620
|
-
i.push(/* @__PURE__ */
|
|
621
|
-
className:
|
|
620
|
+
i.push(/* @__PURE__ */ d("span", {
|
|
621
|
+
className: T.line,
|
|
622
622
|
children: n.length === 0 ? "" : o && o.length > 0 ? (() => {
|
|
623
623
|
let e = 0;
|
|
624
624
|
return n.map((t, n) => {
|
|
625
|
-
let r =
|
|
625
|
+
let r = me(t, e, o, n);
|
|
626
626
|
return e += t.value.length, r;
|
|
627
627
|
});
|
|
628
|
-
})() : n.map((e, t) => /* @__PURE__ */
|
|
629
|
-
className:
|
|
628
|
+
})() : n.map((e, t) => /* @__PURE__ */ d("span", {
|
|
629
|
+
className: T[e.kind],
|
|
630
630
|
children: e.value
|
|
631
631
|
}, t))
|
|
632
632
|
}, a));
|
|
633
633
|
}
|
|
634
634
|
return i;
|
|
635
635
|
}
|
|
636
|
-
function
|
|
636
|
+
function ge({ count: e, className: t, gutterRef: n, start: r = 0, end: i = e, topPad: a = 0, bottomPad: o = 0, activeLine: s = !1 }) {
|
|
637
637
|
let c = [];
|
|
638
|
-
for (let e = r + 1; e <= i; e++) c.push(/* @__PURE__ */
|
|
639
|
-
className:
|
|
638
|
+
for (let e = r + 1; e <= i; e++) c.push(/* @__PURE__ */ d("span", {
|
|
639
|
+
className: T.gutterLine,
|
|
640
640
|
children: e
|
|
641
641
|
}, e));
|
|
642
|
-
return /* @__PURE__ */
|
|
642
|
+
return /* @__PURE__ */ f("div", {
|
|
643
643
|
ref: n,
|
|
644
644
|
className: t,
|
|
645
645
|
"aria-hidden": "true",
|
|
646
646
|
children: [
|
|
647
|
-
s && /* @__PURE__ */
|
|
648
|
-
a > 0 && /* @__PURE__ */
|
|
647
|
+
s && /* @__PURE__ */ d("div", { className: T.gutterActive }),
|
|
648
|
+
a > 0 && /* @__PURE__ */ d("div", { style: { blockSize: a } }),
|
|
649
649
|
c,
|
|
650
|
-
o > 0 && /* @__PURE__ */
|
|
650
|
+
o > 0 && /* @__PURE__ */ d("div", { style: { blockSize: o } })
|
|
651
651
|
]
|
|
652
652
|
});
|
|
653
653
|
}
|
|
654
|
-
var
|
|
654
|
+
var E = {
|
|
655
655
|
root: "_root_18xci_2",
|
|
656
656
|
textarea: "_textarea_18xci_18",
|
|
657
657
|
gutter: "_gutter_18xci_23",
|
|
658
658
|
codeArea: "_codeArea_18xci_36",
|
|
659
659
|
pre: "_pre_18xci_43",
|
|
660
660
|
currentLine: "_currentLine_18xci_58"
|
|
661
|
-
},
|
|
661
|
+
}, D = {
|
|
662
662
|
panel: "_panel_hawkv_2",
|
|
663
663
|
row: "_row_hawkv_20",
|
|
664
664
|
input: "_input_hawkv_26",
|
|
@@ -669,32 +669,32 @@ var D = {
|
|
|
669
669
|
};
|
|
670
670
|
//#endregion
|
|
671
671
|
//#region src/editor/code-editor/find-panel.tsx
|
|
672
|
-
function
|
|
673
|
-
|
|
674
|
-
let n = t.matchCount === 0 ?
|
|
672
|
+
function _e(t) {
|
|
673
|
+
o();
|
|
674
|
+
let n = t.matchCount === 0 ? c(s.editor.noMatches) : c(s.editor.findCount, {
|
|
675
675
|
current: t.currentIndex + 1,
|
|
676
676
|
total: t.matchCount
|
|
677
677
|
});
|
|
678
|
-
return /* @__PURE__ */
|
|
679
|
-
className:
|
|
678
|
+
return /* @__PURE__ */ f("div", {
|
|
679
|
+
className: D.panel,
|
|
680
680
|
role: "search",
|
|
681
|
-
"aria-label":
|
|
682
|
-
children: [/* @__PURE__ */
|
|
683
|
-
className:
|
|
681
|
+
"aria-label": c(s.editor.find),
|
|
682
|
+
children: [/* @__PURE__ */ f("div", {
|
|
683
|
+
className: D.row,
|
|
684
684
|
children: [
|
|
685
|
-
/* @__PURE__ */
|
|
685
|
+
/* @__PURE__ */ d("button", {
|
|
686
686
|
type: "button",
|
|
687
|
-
className:
|
|
688
|
-
"aria-label":
|
|
687
|
+
className: D.toggle,
|
|
688
|
+
"aria-label": c(s.editor.toggleReplace),
|
|
689
689
|
"aria-expanded": t.replaceMode,
|
|
690
690
|
onClick: t.onToggleReplace,
|
|
691
691
|
children: t.replaceMode ? "▾" : "▸"
|
|
692
692
|
}),
|
|
693
|
-
/* @__PURE__ */
|
|
694
|
-
className:
|
|
693
|
+
/* @__PURE__ */ d("input", {
|
|
694
|
+
className: D.input,
|
|
695
695
|
value: t.query,
|
|
696
|
-
placeholder:
|
|
697
|
-
"aria-label":
|
|
696
|
+
placeholder: c(s.editor.findPlaceholder),
|
|
697
|
+
"aria-label": c(s.editor.find),
|
|
698
698
|
autoFocus: !0,
|
|
699
699
|
autoComplete: "off",
|
|
700
700
|
spellCheck: !1,
|
|
@@ -703,49 +703,49 @@ function me(t) {
|
|
|
703
703
|
e.key === "Enter" ? (e.preventDefault(), e.shiftKey ? t.onPrev() : t.onNext()) : e.key === "Escape" && (e.preventDefault(), t.onClose());
|
|
704
704
|
}
|
|
705
705
|
}),
|
|
706
|
-
/* @__PURE__ */
|
|
707
|
-
className:
|
|
706
|
+
/* @__PURE__ */ d("span", {
|
|
707
|
+
className: D.count,
|
|
708
708
|
"aria-live": "polite",
|
|
709
709
|
children: n
|
|
710
710
|
}),
|
|
711
|
-
/* @__PURE__ */
|
|
711
|
+
/* @__PURE__ */ d("button", {
|
|
712
712
|
type: "button",
|
|
713
|
-
className:
|
|
714
|
-
"aria-label":
|
|
713
|
+
className: D.button,
|
|
714
|
+
"aria-label": c(s.editor.previous),
|
|
715
715
|
onClick: t.onPrev,
|
|
716
716
|
children: "‹"
|
|
717
717
|
}),
|
|
718
|
-
/* @__PURE__ */
|
|
718
|
+
/* @__PURE__ */ d("button", {
|
|
719
719
|
type: "button",
|
|
720
|
-
className:
|
|
721
|
-
"aria-label":
|
|
720
|
+
className: D.button,
|
|
721
|
+
"aria-label": c(s.editor.next),
|
|
722
722
|
onClick: t.onNext,
|
|
723
723
|
children: "›"
|
|
724
724
|
}),
|
|
725
|
-
/* @__PURE__ */
|
|
725
|
+
/* @__PURE__ */ d("button", {
|
|
726
726
|
type: "button",
|
|
727
|
-
className: e(
|
|
727
|
+
className: e(D.button, t.caseSensitive && D.active),
|
|
728
728
|
"aria-pressed": t.caseSensitive,
|
|
729
|
-
"aria-label":
|
|
729
|
+
"aria-label": c(s.editor.matchCase),
|
|
730
730
|
onClick: t.onToggleCase,
|
|
731
731
|
children: "Aa"
|
|
732
732
|
}),
|
|
733
|
-
/* @__PURE__ */
|
|
733
|
+
/* @__PURE__ */ d("button", {
|
|
734
734
|
type: "button",
|
|
735
|
-
className:
|
|
736
|
-
"aria-label":
|
|
735
|
+
className: D.button,
|
|
736
|
+
"aria-label": c(s.editor.close),
|
|
737
737
|
onClick: t.onClose,
|
|
738
738
|
children: "×"
|
|
739
739
|
})
|
|
740
740
|
]
|
|
741
|
-
}), t.replaceMode && /* @__PURE__ */
|
|
742
|
-
className:
|
|
741
|
+
}), t.replaceMode && /* @__PURE__ */ f("div", {
|
|
742
|
+
className: D.row,
|
|
743
743
|
children: [
|
|
744
|
-
/* @__PURE__ */
|
|
745
|
-
className:
|
|
744
|
+
/* @__PURE__ */ d("input", {
|
|
745
|
+
className: D.input,
|
|
746
746
|
value: t.replaceQuery,
|
|
747
|
-
placeholder:
|
|
748
|
-
"aria-label":
|
|
747
|
+
placeholder: c(s.editor.replacePlaceholder),
|
|
748
|
+
"aria-label": c(s.editor.replace),
|
|
749
749
|
autoComplete: "off",
|
|
750
750
|
spellCheck: !1,
|
|
751
751
|
onChange: (e) => t.onReplaceChange(e.currentTarget.value),
|
|
@@ -753,17 +753,17 @@ function me(t) {
|
|
|
753
753
|
e.key === "Escape" ? (e.preventDefault(), t.onClose()) : e.key === "Enter" && (e.preventDefault(), t.onReplace());
|
|
754
754
|
}
|
|
755
755
|
}),
|
|
756
|
-
/* @__PURE__ */
|
|
756
|
+
/* @__PURE__ */ d("button", {
|
|
757
757
|
type: "button",
|
|
758
|
-
className:
|
|
758
|
+
className: D.button,
|
|
759
759
|
onClick: t.onReplace,
|
|
760
|
-
children:
|
|
760
|
+
children: c(s.editor.replaceOne)
|
|
761
761
|
}),
|
|
762
|
-
/* @__PURE__ */
|
|
762
|
+
/* @__PURE__ */ d("button", {
|
|
763
763
|
type: "button",
|
|
764
|
-
className:
|
|
764
|
+
className: D.button,
|
|
765
765
|
onClick: t.onReplaceAll,
|
|
766
|
-
children:
|
|
766
|
+
children: c(s.editor.replaceAll)
|
|
767
767
|
})
|
|
768
768
|
]
|
|
769
769
|
})]
|
|
@@ -771,25 +771,25 @@ function me(t) {
|
|
|
771
771
|
}
|
|
772
772
|
//#endregion
|
|
773
773
|
//#region src/editor/code-editor/find.ts
|
|
774
|
-
var
|
|
775
|
-
function
|
|
776
|
-
return e !== void 0 &&
|
|
774
|
+
var O = /\w/;
|
|
775
|
+
function ve(e) {
|
|
776
|
+
return e !== void 0 && O.test(e);
|
|
777
777
|
}
|
|
778
|
-
function
|
|
778
|
+
function ye(e, t, n = {}) {
|
|
779
779
|
if (t.length === 0) return [];
|
|
780
780
|
let r = n.caseSensitive ? e : e.toLowerCase(), i = n.caseSensitive ? t : t.toLowerCase(), a = [], o = 0;
|
|
781
781
|
for (;;) {
|
|
782
782
|
let t = r.indexOf(i, o);
|
|
783
783
|
if (t === -1) break;
|
|
784
784
|
let s = t + i.length;
|
|
785
|
-
(!n.wholeWord || !
|
|
785
|
+
(!n.wholeWord || !ve(e[t - 1]) && !ve(e[s])) && a.push({
|
|
786
786
|
start: t,
|
|
787
787
|
end: s
|
|
788
788
|
}), o = s > t ? s : t + 1;
|
|
789
789
|
}
|
|
790
790
|
return a;
|
|
791
791
|
}
|
|
792
|
-
function
|
|
792
|
+
function be(e, t) {
|
|
793
793
|
let n = 0, r = 0;
|
|
794
794
|
for (let i = 0; i < t && i < e.length; i++) e[i] === "\n" && (n++, r = i + 1);
|
|
795
795
|
return {
|
|
@@ -797,9 +797,9 @@ function _e(e, t) {
|
|
|
797
797
|
col: t - r
|
|
798
798
|
};
|
|
799
799
|
}
|
|
800
|
-
function
|
|
800
|
+
function xe(e, t, n, r) {
|
|
801
801
|
return t.map((t, i) => {
|
|
802
|
-
let { line: a, col: o } =
|
|
802
|
+
let { line: a, col: o } = be(e, t.start);
|
|
803
803
|
return {
|
|
804
804
|
line: a,
|
|
805
805
|
start: o,
|
|
@@ -808,7 +808,7 @@ function ve(e, t, n, r) {
|
|
|
808
808
|
};
|
|
809
809
|
});
|
|
810
810
|
}
|
|
811
|
-
function
|
|
811
|
+
function Se(e, t, n) {
|
|
812
812
|
let r = e;
|
|
813
813
|
for (let e = t.length - 1; e >= 0; e--) {
|
|
814
814
|
let i = t[e];
|
|
@@ -818,16 +818,16 @@ function ye(e, t, n) {
|
|
|
818
818
|
}
|
|
819
819
|
//#endregion
|
|
820
820
|
//#region src/editor/code-editor/brackets.ts
|
|
821
|
-
var
|
|
821
|
+
var k = {
|
|
822
822
|
"(": ")",
|
|
823
823
|
"[": "]",
|
|
824
824
|
"{": "}"
|
|
825
|
-
},
|
|
825
|
+
}, A = {
|
|
826
826
|
")": "(",
|
|
827
827
|
"]": "[",
|
|
828
828
|
"}": "}"
|
|
829
829
|
};
|
|
830
|
-
function
|
|
830
|
+
function j(e, t, n, r) {
|
|
831
831
|
let i = 0;
|
|
832
832
|
for (let a = t; a < e.length; a++) {
|
|
833
833
|
let t = e[a];
|
|
@@ -836,7 +836,7 @@ function M(e, t, n, r) {
|
|
|
836
836
|
}
|
|
837
837
|
return -1;
|
|
838
838
|
}
|
|
839
|
-
function
|
|
839
|
+
function M(e, t, n, r) {
|
|
840
840
|
let i = 0;
|
|
841
841
|
for (let a = t; a >= 0; a--) {
|
|
842
842
|
let t = e[a];
|
|
@@ -845,41 +845,41 @@ function N(e, t, n, r) {
|
|
|
845
845
|
}
|
|
846
846
|
return -1;
|
|
847
847
|
}
|
|
848
|
-
function
|
|
848
|
+
function Ce(e, t) {
|
|
849
849
|
let n = e[t];
|
|
850
|
-
if (n && n in
|
|
851
|
-
let r =
|
|
850
|
+
if (n && n in k) {
|
|
851
|
+
let r = j(e, t, n, k[n]);
|
|
852
852
|
if (r !== -1) return {
|
|
853
853
|
open: t,
|
|
854
854
|
close: r
|
|
855
855
|
};
|
|
856
856
|
}
|
|
857
857
|
let r = e[t - 1];
|
|
858
|
-
if (r && r in
|
|
859
|
-
let n =
|
|
858
|
+
if (r && r in A) {
|
|
859
|
+
let n = M(e, t - 1, A[r], r);
|
|
860
860
|
if (n !== -1) return {
|
|
861
861
|
open: n,
|
|
862
862
|
close: t - 1
|
|
863
863
|
};
|
|
864
864
|
}
|
|
865
|
-
if (r && r in
|
|
866
|
-
let n =
|
|
865
|
+
if (r && r in k) {
|
|
866
|
+
let n = j(e, t - 1, r, k[r]);
|
|
867
867
|
if (n !== -1) return {
|
|
868
868
|
open: t - 1,
|
|
869
869
|
close: n
|
|
870
870
|
};
|
|
871
871
|
}
|
|
872
|
-
if (n && n in
|
|
873
|
-
let r =
|
|
872
|
+
if (n && n in A) {
|
|
873
|
+
let r = M(e, t, A[n], n);
|
|
874
874
|
if (r !== -1) return {
|
|
875
875
|
open: r,
|
|
876
876
|
close: t
|
|
877
877
|
};
|
|
878
878
|
}
|
|
879
879
|
}
|
|
880
|
-
function
|
|
880
|
+
function we(e, t, n) {
|
|
881
881
|
return [t.open, t.close].map((t) => {
|
|
882
|
-
let { line: r, col: i } =
|
|
882
|
+
let { line: r, col: i } = be(e, t);
|
|
883
883
|
return {
|
|
884
884
|
line: r,
|
|
885
885
|
start: i,
|
|
@@ -890,7 +890,7 @@ function xe(e, t, n) {
|
|
|
890
890
|
}
|
|
891
891
|
//#endregion
|
|
892
892
|
//#region src/editor/code-editor/history.ts
|
|
893
|
-
function
|
|
893
|
+
function Te(e = 200) {
|
|
894
894
|
let t = [], n = -1, r = !1;
|
|
895
895
|
return {
|
|
896
896
|
record(i, a) {
|
|
@@ -916,23 +916,23 @@ function Se(e = 200) {
|
|
|
916
916
|
}
|
|
917
917
|
//#endregion
|
|
918
918
|
//#region src/editor/code-editor/keymap.ts
|
|
919
|
-
var
|
|
920
|
-
function
|
|
919
|
+
var N = typeof navigator < "u" && /Mac|iPhone|iPad|iPod/.test(navigator.platform || navigator.userAgent || "");
|
|
920
|
+
function P(e) {
|
|
921
921
|
let t = [];
|
|
922
|
-
(
|
|
922
|
+
(N ? e.metaKey : e.ctrlKey) && t.push("Mod"), e.altKey && t.push("Alt"), e.shiftKey && t.push("Shift");
|
|
923
923
|
let n = e.key;
|
|
924
924
|
return n.length === 1 && (n = n.toLowerCase()), t.push(n), t.join("-");
|
|
925
925
|
}
|
|
926
|
-
function
|
|
926
|
+
function Ee(e, t) {
|
|
927
927
|
let n = new Map(Object.entries(e));
|
|
928
928
|
if (t) for (let [e, r] of Object.entries(t)) n.set(e, r);
|
|
929
929
|
return n;
|
|
930
930
|
}
|
|
931
|
-
function
|
|
932
|
-
let n = e.get(
|
|
931
|
+
function De(e, t) {
|
|
932
|
+
let n = e.get(P(t.event));
|
|
933
933
|
return n ? n(t) : !1;
|
|
934
934
|
}
|
|
935
|
-
function
|
|
935
|
+
function Oe(e) {
|
|
936
936
|
let t = () => e.insertSpaces ? " ".repeat(e.tabSize) : " ";
|
|
937
937
|
return {
|
|
938
938
|
indent: ({ textarea: e, setText: n }) => {
|
|
@@ -952,7 +952,7 @@ function Te(e) {
|
|
|
952
952
|
}
|
|
953
953
|
//#endregion
|
|
954
954
|
//#region src/editor/code-editor/sync.ts
|
|
955
|
-
function
|
|
955
|
+
function ke(e, t) {
|
|
956
956
|
if (e === t) return {
|
|
957
957
|
from: e.length,
|
|
958
958
|
to: e.length,
|
|
@@ -968,30 +968,124 @@ function Ee(e, t) {
|
|
|
968
968
|
insert: t.slice(r, a)
|
|
969
969
|
};
|
|
970
970
|
}
|
|
971
|
-
function
|
|
971
|
+
function F(e, t) {
|
|
972
972
|
return e <= t.from ? e : e >= t.to ? e + (t.insert.length - (t.to - t.from)) : t.from + t.insert.length;
|
|
973
973
|
}
|
|
974
|
-
function
|
|
974
|
+
function Ae(e, t, n) {
|
|
975
975
|
return {
|
|
976
|
-
start:
|
|
977
|
-
end:
|
|
976
|
+
start: F(e, n),
|
|
977
|
+
end: F(t, n)
|
|
978
978
|
};
|
|
979
979
|
}
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
let
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
980
|
+
//#endregion
|
|
981
|
+
//#region src/editor/code-editor/caret.ts
|
|
982
|
+
function I(e, t) {
|
|
983
|
+
let n = 0;
|
|
984
|
+
for (let r of e) r === " " ? n += t - n % t : n += 1;
|
|
985
|
+
return n;
|
|
986
|
+
}
|
|
987
|
+
function je(e, t, n) {
|
|
988
|
+
let { line: r, col: i } = be(e, t), a = I(e.slice(t - i, t), n.tabSize);
|
|
989
|
+
return {
|
|
990
|
+
top: r * n.lineHeight - n.scrollTop + n.padTop,
|
|
991
|
+
left: a * n.charWidth - n.scrollLeft + n.padLeft
|
|
992
|
+
};
|
|
993
|
+
}
|
|
994
|
+
function Me(e, t) {
|
|
995
|
+
if (typeof document > "u") return null;
|
|
996
|
+
let n = document.createTreeWalker(e, NodeFilter.SHOW_TEXT), r = 0, i = n.nextNode();
|
|
997
|
+
for (; i;) {
|
|
998
|
+
let e = i.textContent?.length ?? 0;
|
|
999
|
+
if (t <= r + e) {
|
|
1000
|
+
let e = document.createRange();
|
|
1001
|
+
e.setStart(i, Math.max(0, t - r)), e.collapse(!0);
|
|
1002
|
+
let n = e.getClientRects();
|
|
1003
|
+
return n.length > 0 ? n[0] : e.getBoundingClientRect();
|
|
1004
|
+
}
|
|
1005
|
+
r += e, i = n.nextNode();
|
|
1006
|
+
}
|
|
1007
|
+
return null;
|
|
1008
|
+
}
|
|
1009
|
+
function Ne(e) {
|
|
1010
|
+
if (typeof document > "u") return 0;
|
|
1011
|
+
let t = getComputedStyle(e), n = document.createElement("span");
|
|
1012
|
+
n.style.position = "absolute", n.style.visibility = "hidden", n.style.whiteSpace = "pre", n.style.font = t.font, n.style.letterSpacing = t.letterSpacing, n.style.tabSize = t.tabSize, n.textContent = "0".repeat(10), document.body.appendChild(n);
|
|
1013
|
+
let r = n.getBoundingClientRect().width / 10;
|
|
1014
|
+
return n.remove(), r;
|
|
1015
|
+
}
|
|
1016
|
+
//#endregion
|
|
1017
|
+
//#region src/editor/code-editor/slash-trigger.ts
|
|
1018
|
+
function Pe(e, t) {
|
|
1019
|
+
for (let n = t - 1; n >= 0; n--) {
|
|
1020
|
+
let r = e[n];
|
|
1021
|
+
if (r === "/") {
|
|
1022
|
+
let r = e[n - 1];
|
|
1023
|
+
return r === void 0 || /\s/.test(r) ? {
|
|
1024
|
+
start: n,
|
|
1025
|
+
query: e.slice(n + 1, t)
|
|
1026
|
+
} : null;
|
|
1027
|
+
}
|
|
1028
|
+
if (r === void 0 || /\s/.test(r)) return null;
|
|
1029
|
+
}
|
|
1030
|
+
return null;
|
|
1031
|
+
}
|
|
1032
|
+
function Fe(e, t) {
|
|
1033
|
+
if (t === "") return [...e];
|
|
1034
|
+
let n = t.toLowerCase();
|
|
1035
|
+
return e.filter((e) => e.label.toLowerCase().includes(n) || (e.keywords?.some((e) => e.toLowerCase().includes(n)) ?? !1));
|
|
1036
|
+
}
|
|
1037
|
+
var L = {
|
|
1038
|
+
menu: "_menu_zkolh_2",
|
|
1039
|
+
option: "_option_zkolh_24",
|
|
1040
|
+
active: "_active_zkolh_35",
|
|
1041
|
+
label: "_label_zkolh_39",
|
|
1042
|
+
hint: "_hint_zkolh_44",
|
|
1043
|
+
empty: "_empty_zkolh_50"
|
|
1044
|
+
}, Ie = l(function({ id: t, items: n, activeIndex: r, onSelect: i, onHover: a, style: l }, ee) {
|
|
1045
|
+
return o(), /* @__PURE__ */ d("ul", {
|
|
1046
|
+
ref: ee,
|
|
1047
|
+
id: t,
|
|
1048
|
+
className: L.menu,
|
|
1049
|
+
role: "listbox",
|
|
1050
|
+
"aria-label": c(s.editor.commandMenu),
|
|
1051
|
+
style: l,
|
|
1052
|
+
children: n.length === 0 ? /* @__PURE__ */ d("li", {
|
|
1053
|
+
className: L.empty,
|
|
1054
|
+
role: "presentation",
|
|
1055
|
+
children: c(s.editor.commandMenuEmpty)
|
|
1056
|
+
}) : n.map((n, o) => /* @__PURE__ */ f("li", {
|
|
1057
|
+
id: `${t}-opt-${o}`,
|
|
1058
|
+
role: "option",
|
|
1059
|
+
"aria-selected": o === r,
|
|
1060
|
+
className: e(L.option, o === r && L.active),
|
|
1061
|
+
onMouseEnter: () => a(o),
|
|
1062
|
+
onMouseDown: (e) => {
|
|
1063
|
+
e.preventDefault(), i(o);
|
|
1064
|
+
},
|
|
1065
|
+
children: [/* @__PURE__ */ d("span", {
|
|
1066
|
+
className: L.label,
|
|
1067
|
+
children: n.label
|
|
1068
|
+
}), n.hint !== void 0 && /* @__PURE__ */ d("span", {
|
|
1069
|
+
className: L.hint,
|
|
1070
|
+
children: n.hint
|
|
1071
|
+
})]
|
|
1072
|
+
}, n.id))
|
|
1073
|
+
});
|
|
1074
|
+
}), R = l(function({ value: l, defaultValue: p, onValueChange: m, language: h = "plaintext", lineNumbers: g = !0, tabSize: _ = 2, insertSpaces: v = !0, wrap: y = !1, virtualize: b, readOnly: x = !1, disabled: S = !1, spellCheck: ie = !1, label: ae, onSave: oe, keymap: se, decorations: C, theme: ce, bracketMatching: le = !1, commands: w, className: ue, style: de, onKeyDown: fe, ...pe }, me) {
|
|
1075
|
+
o();
|
|
1076
|
+
let D = u(oe);
|
|
1077
|
+
D.current = oe;
|
|
1078
|
+
let [O, ve] = n({
|
|
1079
|
+
value: l,
|
|
1080
|
+
defaultValue: p ?? "",
|
|
1081
|
+
onChange: m
|
|
1082
|
+
}), k = u(null), A = u(null), j = u(null), M = u(null), N = u(null);
|
|
1083
|
+
N.current === null && (N.current = Te(), N.current.reset({
|
|
990
1084
|
text: O.value,
|
|
991
1085
|
selectionStart: 0,
|
|
992
1086
|
selectionEnd: 0
|
|
993
1087
|
}));
|
|
994
|
-
let P = N.current, F =
|
|
1088
|
+
let P = N.current, F = u(null), I = u(void 0), L = u(O.value), R = u(void 0), z = u(!1), B = u({
|
|
995
1089
|
start: 0,
|
|
996
1090
|
end: 0
|
|
997
1091
|
}), V = (e, t, n) => {
|
|
@@ -999,30 +1093,30 @@ var L = s(function({ value: s, defaultValue: f, onValueChange: p, language: ee =
|
|
|
999
1093
|
text: e,
|
|
1000
1094
|
selectionStart: t.start,
|
|
1001
1095
|
selectionEnd: t.end
|
|
1002
|
-
}, { coalesce: n }),
|
|
1003
|
-
},
|
|
1096
|
+
}, { coalesce: n }), ve(e);
|
|
1097
|
+
}, Le = (e) => {
|
|
1004
1098
|
let t = M.current;
|
|
1005
1099
|
V(e, t ? {
|
|
1006
1100
|
start: t.selectionStart,
|
|
1007
1101
|
end: t.selectionEnd
|
|
1008
1102
|
} : B.current, !1);
|
|
1009
|
-
},
|
|
1103
|
+
}, Re = (e) => {
|
|
1010
1104
|
let t = M.current;
|
|
1011
1105
|
if (!t) return;
|
|
1012
|
-
z.current = !0, t.value = e.text, t.setSelectionRange(e.selectionStart, e.selectionEnd),
|
|
1106
|
+
z.current = !0, t.value = e.text, t.setSelectionRange(e.selectionStart, e.selectionEnd), ve(e.text), R.current = e.text, L.current = e.text, B.current = {
|
|
1013
1107
|
start: e.selectionStart,
|
|
1014
1108
|
end: e.selectionEnd
|
|
1015
|
-
},
|
|
1109
|
+
}, G.value = e.selectionStart;
|
|
1016
1110
|
let n = e.text.slice(0, e.selectionStart).split("\n").length - 1;
|
|
1017
1111
|
k.current?.style.setProperty("--cascivo-editor-caret-line", String(n)), z.current = !1;
|
|
1018
|
-
},
|
|
1112
|
+
}, ze = () => {
|
|
1019
1113
|
let e = P.undo();
|
|
1020
|
-
e &&
|
|
1021
|
-
},
|
|
1114
|
+
e && Re(e);
|
|
1115
|
+
}, Be = () => {
|
|
1022
1116
|
let e = P.redo();
|
|
1023
|
-
e &&
|
|
1024
|
-
}, H =
|
|
1025
|
-
|
|
1117
|
+
e && Re(e);
|
|
1118
|
+
}, H = i(O.value), Ve = i(0), He = i(0), Ue = i(0), U = i(!1), We = i(""), Ge = i(""), Ke = i(!1), qe = i(!1), W = i(0), G = i(0), K = i(!1), Je = i(0), Ye = i(""), q = i(0), Xe = i(-1), Ze = i(0), Qe = u(null), $e = u(null), et = r("slash-menu");
|
|
1119
|
+
a(() => {
|
|
1026
1120
|
let e = O.value;
|
|
1027
1121
|
if (typeof requestAnimationFrame != "function") {
|
|
1028
1122
|
H.value = e;
|
|
@@ -1032,102 +1126,149 @@ var L = s(function({ value: s, defaultValue: f, onValueChange: p, language: ee =
|
|
|
1032
1126
|
H.value = e;
|
|
1033
1127
|
});
|
|
1034
1128
|
return () => cancelAnimationFrame(t);
|
|
1035
|
-
}),
|
|
1129
|
+
}), a(() => {
|
|
1036
1130
|
let e = O.value;
|
|
1037
1131
|
if (z.current || e === L.current) return;
|
|
1038
1132
|
if (e === R.current) {
|
|
1039
1133
|
L.current = e;
|
|
1040
1134
|
return;
|
|
1041
1135
|
}
|
|
1042
|
-
let t = M.current, n =
|
|
1136
|
+
let t = M.current, n = ke(L.current, e), r = Ae(B.current.start, B.current.end, n);
|
|
1043
1137
|
t && (z.current = !0, t.value !== e && (t.value = e), t.setSelectionRange(r.start, r.end), z.current = !1), B.current = r, P.reset({
|
|
1044
1138
|
text: e,
|
|
1045
1139
|
selectionStart: r.start,
|
|
1046
1140
|
selectionEnd: r.end
|
|
1047
1141
|
}), L.current = e;
|
|
1048
|
-
}),
|
|
1142
|
+
}), a(() => {
|
|
1049
1143
|
let e = M.current;
|
|
1050
1144
|
if (!e) return;
|
|
1051
1145
|
let t = () => {
|
|
1052
1146
|
let t = Number.parseFloat(getComputedStyle(e).lineHeight);
|
|
1053
|
-
|
|
1147
|
+
Ue.value = Number.isFinite(t) && t > 0 ? t : 0, He.value = e.clientHeight, Ze.value === 0 && (Ze.value = Ne(e));
|
|
1054
1148
|
}, n = () => {
|
|
1055
|
-
|
|
1149
|
+
Ve.value = e.scrollTop, He.value = e.clientHeight, A.current && (A.current.scrollTop = e.scrollTop, A.current.scrollLeft = e.scrollLeft), j.current && (j.current.scrollTop = e.scrollTop);
|
|
1056
1150
|
}, r = () => {
|
|
1057
1151
|
let t = e.value.slice(0, e.selectionStart).split("\n").length - 1;
|
|
1058
1152
|
k.current?.style.setProperty("--cascivo-editor-caret-line", String(t)), B.current = {
|
|
1059
1153
|
start: e.selectionStart,
|
|
1060
1154
|
end: e.selectionEnd
|
|
1061
|
-
},
|
|
1155
|
+
}, G.value = e.selectionStart;
|
|
1062
1156
|
}, i = () => {
|
|
1063
1157
|
document.activeElement === e && r();
|
|
1064
1158
|
};
|
|
1065
1159
|
return t(), r(), e.addEventListener("scroll", n), e.addEventListener("keyup", r), e.addEventListener("click", r), e.addEventListener("input", r), document.addEventListener("selectionchange", i), () => {
|
|
1066
1160
|
e.removeEventListener("scroll", n), e.removeEventListener("keyup", r), e.removeEventListener("click", r), e.removeEventListener("input", r), document.removeEventListener("selectionchange", i);
|
|
1067
1161
|
};
|
|
1162
|
+
}), a(() => {
|
|
1163
|
+
let e = G.value, t = O.value;
|
|
1164
|
+
if (!w || w.length === 0 || x || S) {
|
|
1165
|
+
K.value &&= !1;
|
|
1166
|
+
return;
|
|
1167
|
+
}
|
|
1168
|
+
let n = Pe(t, e);
|
|
1169
|
+
if (!n) {
|
|
1170
|
+
Xe.value = -1, K.value &&= !1;
|
|
1171
|
+
return;
|
|
1172
|
+
}
|
|
1173
|
+
if (n.start === Xe.value) {
|
|
1174
|
+
K.value &&= !1;
|
|
1175
|
+
return;
|
|
1176
|
+
}
|
|
1177
|
+
K.value || (q.value = 0), K.value = !0, Je.value = n.start, Ye.value = n.query;
|
|
1178
|
+
}), a(() => {
|
|
1179
|
+
if (!K.value) return;
|
|
1180
|
+
let e = Qe.current, t = M.current;
|
|
1181
|
+
if (!e || !t) return;
|
|
1182
|
+
let n = Je.value, r = e.offsetParent, i, a, o = A.current, s = (y || O.value.includes(" ")) && o ? Me(o, n) : null;
|
|
1183
|
+
if (s && r) {
|
|
1184
|
+
let e = r.getBoundingClientRect();
|
|
1185
|
+
i = s.bottom - e.top, a = s.left - e.left;
|
|
1186
|
+
} else {
|
|
1187
|
+
let e = getComputedStyle(t), r = je(O.value, n, {
|
|
1188
|
+
charWidth: Ze.value,
|
|
1189
|
+
lineHeight: Ue.value,
|
|
1190
|
+
scrollTop: t.scrollTop,
|
|
1191
|
+
scrollLeft: t.scrollLeft,
|
|
1192
|
+
padTop: Number.parseFloat(e.paddingTop) || 0,
|
|
1193
|
+
padLeft: Number.parseFloat(e.paddingLeft) || 0,
|
|
1194
|
+
tabSize: _
|
|
1195
|
+
});
|
|
1196
|
+
i = r.top + Ue.value, a = r.left;
|
|
1197
|
+
}
|
|
1198
|
+
e.style.top = `${i}px`, e.style.left = `${a}px`;
|
|
1068
1199
|
});
|
|
1069
|
-
let
|
|
1070
|
-
(F.current === null || F.current.grammar !==
|
|
1071
|
-
let
|
|
1072
|
-
if (
|
|
1073
|
-
let e =
|
|
1074
|
-
let e =
|
|
1075
|
-
return
|
|
1200
|
+
let tt = re(h);
|
|
1201
|
+
(F.current === null || F.current.grammar !== tt) && (F.current = ne(tt), I.current = void 0);
|
|
1202
|
+
let nt = F.current, rt = H.value.split("\n"), J = rt.length, it = H.value, at = I.current;
|
|
1203
|
+
if (it !== at) {
|
|
1204
|
+
let e = at === void 0 ? 0 : (() => {
|
|
1205
|
+
let e = ke(at, it);
|
|
1206
|
+
return at.slice(0, e.from).split("\n").length - 1;
|
|
1076
1207
|
})();
|
|
1077
|
-
|
|
1208
|
+
nt.invalidateFrom(e), I.current = it;
|
|
1078
1209
|
}
|
|
1079
|
-
let
|
|
1080
|
-
if (
|
|
1081
|
-
|
|
1082
|
-
let e = Math.ceil(
|
|
1083
|
-
|
|
1210
|
+
let Y = Ue.value, ot = (b ?? J > 1e3) && !y && Y > 0, X = 0, Z = J;
|
|
1211
|
+
if (ot) {
|
|
1212
|
+
X = Math.max(0, Math.floor(Ve.value / Y) - 12);
|
|
1213
|
+
let e = Math.ceil(He.value / Y);
|
|
1214
|
+
Z = Math.min(J, X + e + 24);
|
|
1084
1215
|
}
|
|
1085
|
-
let
|
|
1086
|
-
|
|
1087
|
-
let
|
|
1088
|
-
match:
|
|
1089
|
-
current:
|
|
1090
|
-
}) : [],
|
|
1091
|
-
if (
|
|
1092
|
-
let e =
|
|
1093
|
-
e && (
|
|
1216
|
+
let st = te(tt, rt, X, Z, nt), ct = X * Y, lt = (J - Z) * Y, Q = U.value ? ye(H.value, We.value, { caseSensitive: Ke.value }) : [];
|
|
1217
|
+
W.value >= Q.length && (W.value = Math.max(0, Q.length - 1));
|
|
1218
|
+
let ut = Q.length > 0 ? xe(H.value, Q, W.value, {
|
|
1219
|
+
match: T.match,
|
|
1220
|
+
current: T.matchCurrent
|
|
1221
|
+
}) : [], dt = typeof C == "function" ? C(H.value) : C ?? [], ft = [];
|
|
1222
|
+
if (le) {
|
|
1223
|
+
let e = Ce(H.value, G.value);
|
|
1224
|
+
e && (ft = we(H.value, e, T.bracketMatch));
|
|
1094
1225
|
}
|
|
1095
|
-
let
|
|
1096
|
-
...
|
|
1097
|
-
...
|
|
1098
|
-
...
|
|
1099
|
-
],
|
|
1100
|
-
let t =
|
|
1226
|
+
let pt = [
|
|
1227
|
+
...dt,
|
|
1228
|
+
...ft,
|
|
1229
|
+
...ut
|
|
1230
|
+
], mt = pt.length > 0 ? pt : void 0, ht = (e) => {
|
|
1231
|
+
let t = Q[e], n = M.current;
|
|
1101
1232
|
if (!(!t || !n) && (n.focus(), n.setSelectionRange(t.start, t.end), B.current = {
|
|
1102
1233
|
start: t.start,
|
|
1103
1234
|
end: t.end
|
|
1104
|
-
},
|
|
1105
|
-
let { line: e } =
|
|
1106
|
-
(r < n.scrollTop || r > n.scrollTop + n.clientHeight -
|
|
1235
|
+
}, Y > 0)) {
|
|
1236
|
+
let { line: e } = be(n.value, t.start), r = e * Y;
|
|
1237
|
+
(r < n.scrollTop || r > n.scrollTop + n.clientHeight - Y) && (n.scrollTop = Math.max(0, r - n.clientHeight / 2));
|
|
1107
1238
|
}
|
|
1108
|
-
},
|
|
1109
|
-
|
|
1110
|
-
},
|
|
1111
|
-
|
|
1112
|
-
},
|
|
1113
|
-
let e =
|
|
1114
|
-
!e || !t ||
|
|
1239
|
+
}, gt = () => {
|
|
1240
|
+
Q.length !== 0 && (W.value = (W.value + 1) % Q.length, ht(W.value));
|
|
1241
|
+
}, _t = () => {
|
|
1242
|
+
Q.length !== 0 && (W.value = (W.value - 1 + Q.length) % Q.length, ht(W.value));
|
|
1243
|
+
}, vt = () => {
|
|
1244
|
+
let e = Q[W.value], t = M.current;
|
|
1245
|
+
!e || !t || x || S || (t.setRangeText(Ge.value, e.start, e.end, "end"), V(t.value, {
|
|
1115
1246
|
start: t.selectionStart,
|
|
1116
1247
|
end: t.selectionEnd
|
|
1117
1248
|
}, !1));
|
|
1118
|
-
},
|
|
1119
|
-
if (
|
|
1120
|
-
let e =
|
|
1249
|
+
}, yt = () => {
|
|
1250
|
+
if (Q.length === 0 || x || S) return;
|
|
1251
|
+
let e = Se(H.value, Q, Ge.value), t = M.current;
|
|
1121
1252
|
t && (t.value = e), V(e, {
|
|
1122
1253
|
start: t?.selectionStart ?? 0,
|
|
1123
1254
|
end: t?.selectionEnd ?? 0
|
|
1124
1255
|
}, !1);
|
|
1125
|
-
},
|
|
1126
|
-
|
|
1127
|
-
},
|
|
1256
|
+
}, bt = (e) => {
|
|
1257
|
+
qe.value = e, U.value = !0;
|
|
1258
|
+
}, xt = () => {
|
|
1128
1259
|
U.value = !1, M.current?.focus();
|
|
1129
|
-
};
|
|
1130
|
-
|
|
1260
|
+
}, $ = K.value ? Fe(w ?? [], Ye.value) : [];
|
|
1261
|
+
q.value >= $.length && (q.value = Math.max(0, $.length - 1));
|
|
1262
|
+
let St = $.map((e) => ({
|
|
1263
|
+
id: e.id,
|
|
1264
|
+
label: e.label,
|
|
1265
|
+
...e.hint !== void 0 && { hint: e.hint }
|
|
1266
|
+
})), { anchorStyle: Ct, floatingStyle: wt } = t({
|
|
1267
|
+
anchorRef: Qe,
|
|
1268
|
+
floatingRef: $e,
|
|
1269
|
+
placement: "bottom-start",
|
|
1270
|
+
enabled: K
|
|
1271
|
+
}), Tt = {
|
|
1131
1272
|
applyEdit: ({ from: e, to: t }, n) => {
|
|
1132
1273
|
let r = M.current;
|
|
1133
1274
|
r && (r.setRangeText(n, e, t, "end"), V(r.value, {
|
|
@@ -1143,66 +1284,97 @@ var L = s(function({ value: s, defaultValue: f, onValueChange: p, language: ee =
|
|
|
1143
1284
|
} : { ...B.current };
|
|
1144
1285
|
},
|
|
1145
1286
|
focus: () => M.current?.focus(),
|
|
1146
|
-
undo:
|
|
1147
|
-
redo:
|
|
1148
|
-
openFind: () =>
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1287
|
+
undo: ze,
|
|
1288
|
+
redo: Be,
|
|
1289
|
+
openFind: () => bt(!1),
|
|
1290
|
+
openCommandMenu: () => {
|
|
1291
|
+
let e = M.current;
|
|
1292
|
+
!e || !w || w.length === 0 || x || S || (e.focus(), e.setRangeText("/", e.selectionStart, e.selectionEnd, "end"), V(e.value, {
|
|
1293
|
+
start: e.selectionStart,
|
|
1294
|
+
end: e.selectionEnd
|
|
1295
|
+
}, !1), G.value = e.selectionStart, B.current = {
|
|
1296
|
+
start: e.selectionStart,
|
|
1297
|
+
end: e.selectionEnd
|
|
1298
|
+
});
|
|
1299
|
+
}
|
|
1300
|
+
};
|
|
1301
|
+
ee(me, () => Tt);
|
|
1302
|
+
let Et = (e) => {
|
|
1303
|
+
let t = $[e], n = M.current;
|
|
1304
|
+
if (!t || !n || x || S) return;
|
|
1305
|
+
let r = Je.value, i = n.selectionStart;
|
|
1306
|
+
n.setRangeText(t.insert ?? "", r, i, "end"), V(n.value, {
|
|
1307
|
+
start: n.selectionStart,
|
|
1308
|
+
end: n.selectionEnd
|
|
1309
|
+
}, !1), G.value = n.selectionStart, B.current = {
|
|
1310
|
+
start: n.selectionStart,
|
|
1311
|
+
end: n.selectionEnd
|
|
1312
|
+
}, K.value = !1, q.value = 0, n.focus(), t.run?.(Tt);
|
|
1313
|
+
}, Dt = (e) => {
|
|
1314
|
+
let t = e.currentTarget, n = !x && !S, r = {};
|
|
1152
1315
|
if (n) {
|
|
1153
|
-
let { indent: e, dedent: t } =
|
|
1154
|
-
tabSize:
|
|
1155
|
-
insertSpaces:
|
|
1316
|
+
let { indent: e, dedent: t } = Oe({
|
|
1317
|
+
tabSize: _,
|
|
1318
|
+
insertSpaces: v
|
|
1156
1319
|
});
|
|
1157
|
-
r.Tab = e, r["Shift-Tab"] = t, r["Mod-z"] = () => (
|
|
1158
|
-
let n = () => (
|
|
1320
|
+
r.Tab = e, r["Shift-Tab"] = t, r["Mod-z"] = () => (ze(), !0);
|
|
1321
|
+
let n = () => (Be(), !0);
|
|
1159
1322
|
r["Mod-Shift-z"] = n, r["Mod-y"] = n;
|
|
1160
1323
|
}
|
|
1161
|
-
r["Mod-f"] = () => (
|
|
1162
|
-
let e =
|
|
1324
|
+
if (r["Mod-f"] = () => (bt(!1), !0), r["Mod-Alt-f"] = () => (bt(!0), !0), r["Mod-s"] = () => {
|
|
1325
|
+
let e = D.current;
|
|
1163
1326
|
return e ? (e(O.value), !0) : !1;
|
|
1164
|
-
}, U.value && (r.Escape = () => (
|
|
1327
|
+
}, U.value && (r.Escape = () => (xt(), !0)), K.value) {
|
|
1328
|
+
let e = (e) => () => {
|
|
1329
|
+
let t = $.length;
|
|
1330
|
+
return t > 0 && (q.value = (q.value + e + t) % t), !0;
|
|
1331
|
+
};
|
|
1332
|
+
r.ArrowDown = e(1), r.ArrowUp = e(-1);
|
|
1333
|
+
let t = () => ($.length > 0 && Et(q.value), !0);
|
|
1334
|
+
r.Enter = t, r.Tab = t, r.Escape = () => (Xe.value = Je.value, K.value = !1, !0);
|
|
1335
|
+
}
|
|
1336
|
+
De(Ee(r, se), {
|
|
1165
1337
|
textarea: t,
|
|
1166
1338
|
event: e,
|
|
1167
|
-
setText:
|
|
1168
|
-
}) && e.preventDefault(),
|
|
1169
|
-
},
|
|
1170
|
-
"--cascivo-editor-tab-size":
|
|
1171
|
-
...
|
|
1172
|
-
...
|
|
1339
|
+
setText: Le
|
|
1340
|
+
}) && e.preventDefault(), fe?.(e);
|
|
1341
|
+
}, Ot = {
|
|
1342
|
+
"--cascivo-editor-tab-size": _,
|
|
1343
|
+
...ce,
|
|
1344
|
+
...de
|
|
1173
1345
|
};
|
|
1174
|
-
return /* @__PURE__ */
|
|
1346
|
+
return /* @__PURE__ */ f("div", {
|
|
1175
1347
|
ref: k,
|
|
1176
|
-
className: e(
|
|
1177
|
-
"data-wrap":
|
|
1178
|
-
"data-line-numbers":
|
|
1179
|
-
style:
|
|
1180
|
-
children: [
|
|
1348
|
+
className: e(E.root, ue),
|
|
1349
|
+
"data-wrap": y,
|
|
1350
|
+
"data-line-numbers": g,
|
|
1351
|
+
style: Ot,
|
|
1352
|
+
children: [g && /* @__PURE__ */ d(ge, {
|
|
1181
1353
|
count: J,
|
|
1182
|
-
className:
|
|
1354
|
+
className: E.gutter,
|
|
1183
1355
|
gutterRef: j,
|
|
1184
|
-
start:
|
|
1185
|
-
end:
|
|
1186
|
-
topPad:
|
|
1187
|
-
bottomPad:
|
|
1356
|
+
start: X,
|
|
1357
|
+
end: Z,
|
|
1358
|
+
topPad: ct,
|
|
1359
|
+
bottomPad: lt,
|
|
1188
1360
|
activeLine: !0
|
|
1189
|
-
}), /* @__PURE__ */
|
|
1190
|
-
className:
|
|
1361
|
+
}), /* @__PURE__ */ f("div", {
|
|
1362
|
+
className: E.codeArea,
|
|
1191
1363
|
children: [
|
|
1192
|
-
/* @__PURE__ */
|
|
1364
|
+
/* @__PURE__ */ f("pre", {
|
|
1193
1365
|
ref: A,
|
|
1194
|
-
className:
|
|
1366
|
+
className: E.pre,
|
|
1195
1367
|
"aria-hidden": "true",
|
|
1196
1368
|
children: [
|
|
1197
|
-
/* @__PURE__ */
|
|
1198
|
-
|
|
1199
|
-
/* @__PURE__ */
|
|
1200
|
-
|
|
1369
|
+
/* @__PURE__ */ d("div", { className: E.currentLine }),
|
|
1370
|
+
ct > 0 && /* @__PURE__ */ d("div", { style: { blockSize: ct } }),
|
|
1371
|
+
/* @__PURE__ */ d("code", { children: he(st, X, Z, mt) }),
|
|
1372
|
+
lt > 0 && /* @__PURE__ */ d("div", { style: { blockSize: lt } })
|
|
1201
1373
|
]
|
|
1202
1374
|
}),
|
|
1203
|
-
/* @__PURE__ */
|
|
1375
|
+
/* @__PURE__ */ d("textarea", {
|
|
1204
1376
|
ref: M,
|
|
1205
|
-
className:
|
|
1377
|
+
className: E.textarea,
|
|
1206
1378
|
value: O.value,
|
|
1207
1379
|
onChange: (e) => {
|
|
1208
1380
|
let t = e.currentTarget, n = t.value, r = Math.abs(n.length - L.current.length) === 1;
|
|
@@ -1211,35 +1383,57 @@ var L = s(function({ value: s, defaultValue: f, onValueChange: p, language: ee =
|
|
|
1211
1383
|
end: t.selectionEnd
|
|
1212
1384
|
}, r);
|
|
1213
1385
|
},
|
|
1214
|
-
onKeyDown:
|
|
1215
|
-
readOnly:
|
|
1216
|
-
disabled:
|
|
1217
|
-
spellCheck:
|
|
1218
|
-
"aria-label":
|
|
1386
|
+
onKeyDown: Dt,
|
|
1387
|
+
readOnly: x,
|
|
1388
|
+
disabled: S,
|
|
1389
|
+
spellCheck: ie,
|
|
1390
|
+
"aria-label": ae ?? c(s.editor.label),
|
|
1391
|
+
"aria-expanded": K.value,
|
|
1392
|
+
"aria-controls": K.value ? et : void 0,
|
|
1393
|
+
"aria-activedescendant": K.value ? `${et}-opt-${q.value}` : void 0,
|
|
1219
1394
|
autoCapitalize: "off",
|
|
1220
1395
|
autoCorrect: "off",
|
|
1221
1396
|
autoComplete: "off",
|
|
1222
|
-
wrap:
|
|
1223
|
-
...
|
|
1397
|
+
wrap: y ? "soft" : "off",
|
|
1398
|
+
...pe
|
|
1399
|
+
}),
|
|
1400
|
+
/* @__PURE__ */ d("div", {
|
|
1401
|
+
ref: Qe,
|
|
1402
|
+
"aria-hidden": "true",
|
|
1403
|
+
style: {
|
|
1404
|
+
position: "absolute",
|
|
1405
|
+
inlineSize: 0,
|
|
1406
|
+
blockSize: 0,
|
|
1407
|
+
...Ct
|
|
1408
|
+
}
|
|
1224
1409
|
}),
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1410
|
+
K.value && /* @__PURE__ */ d(Ie, {
|
|
1411
|
+
ref: $e,
|
|
1412
|
+
id: et,
|
|
1413
|
+
items: St,
|
|
1414
|
+
activeIndex: q.value,
|
|
1415
|
+
onSelect: Et,
|
|
1416
|
+
onHover: (e) => q.value = e,
|
|
1417
|
+
style: wt
|
|
1418
|
+
}),
|
|
1419
|
+
U.value && /* @__PURE__ */ d(_e, {
|
|
1420
|
+
query: We.value,
|
|
1421
|
+
replaceQuery: Ge.value,
|
|
1422
|
+
replaceMode: qe.value,
|
|
1423
|
+
caseSensitive: Ke.value,
|
|
1424
|
+
matchCount: Q.length,
|
|
1425
|
+
currentIndex: Q.length > 0 ? W.value : -1,
|
|
1232
1426
|
onQueryChange: (e) => {
|
|
1233
|
-
|
|
1427
|
+
We.value = e, W.value = 0;
|
|
1234
1428
|
},
|
|
1235
|
-
onReplaceChange: (e) =>
|
|
1236
|
-
onNext:
|
|
1237
|
-
onPrev:
|
|
1238
|
-
onReplace:
|
|
1239
|
-
onReplaceAll:
|
|
1240
|
-
onToggleCase: () =>
|
|
1241
|
-
onToggleReplace: () =>
|
|
1242
|
-
onClose:
|
|
1429
|
+
onReplaceChange: (e) => Ge.value = e,
|
|
1430
|
+
onNext: gt,
|
|
1431
|
+
onPrev: _t,
|
|
1432
|
+
onReplace: vt,
|
|
1433
|
+
onReplaceAll: yt,
|
|
1434
|
+
onToggleCase: () => Ke.value = !Ke.value,
|
|
1435
|
+
onToggleReplace: () => qe.value = !qe.value,
|
|
1436
|
+
onClose: xt
|
|
1243
1437
|
})
|
|
1244
1438
|
]
|
|
1245
1439
|
})]
|
|
@@ -1247,32 +1441,32 @@ var L = s(function({ value: s, defaultValue: f, onValueChange: p, language: ee =
|
|
|
1247
1441
|
});
|
|
1248
1442
|
//#endregion
|
|
1249
1443
|
//#region src/editor/highlight/highlight.tsx
|
|
1250
|
-
function
|
|
1251
|
-
|
|
1444
|
+
function z({ value: t, language: n = "plaintext", lineNumbers: r = !1, wrap: i = !1, tabSize: a = 2, label: s, className: c, preRef: l, gutterRef: ee, style: u, ...p }) {
|
|
1445
|
+
o();
|
|
1252
1446
|
let m = re(n), h = t.split("\n"), g = te(m, h, 0, h.length, ne(m)), _ = {
|
|
1253
|
-
"--cascivo-editor-tab-size":
|
|
1254
|
-
...
|
|
1447
|
+
"--cascivo-editor-tab-size": a,
|
|
1448
|
+
...u
|
|
1255
1449
|
};
|
|
1256
|
-
return /* @__PURE__ */
|
|
1257
|
-
className: e(
|
|
1258
|
-
"data-wrap":
|
|
1450
|
+
return /* @__PURE__ */ f("div", {
|
|
1451
|
+
className: e(T.root, c),
|
|
1452
|
+
"data-wrap": i,
|
|
1259
1453
|
"data-line-numbers": r,
|
|
1260
1454
|
style: _,
|
|
1261
1455
|
"aria-label": s,
|
|
1262
|
-
...
|
|
1263
|
-
children: [r && /* @__PURE__ */
|
|
1456
|
+
...p,
|
|
1457
|
+
children: [r && /* @__PURE__ */ d(ge, {
|
|
1264
1458
|
count: g.length,
|
|
1265
|
-
className:
|
|
1266
|
-
gutterRef:
|
|
1267
|
-
}), /* @__PURE__ */
|
|
1459
|
+
className: T.gutter,
|
|
1460
|
+
gutterRef: ee
|
|
1461
|
+
}), /* @__PURE__ */ d("pre", {
|
|
1268
1462
|
ref: l,
|
|
1269
|
-
className:
|
|
1270
|
-
children: /* @__PURE__ */
|
|
1271
|
-
className:
|
|
1272
|
-
children:
|
|
1463
|
+
className: T.pre,
|
|
1464
|
+
children: /* @__PURE__ */ d("code", {
|
|
1465
|
+
className: T.code,
|
|
1466
|
+
children: he(g)
|
|
1273
1467
|
})
|
|
1274
1468
|
})]
|
|
1275
1469
|
});
|
|
1276
1470
|
}
|
|
1277
1471
|
//#endregion
|
|
1278
|
-
export {
|
|
1472
|
+
export { R as CodeEditor, z as Highlight, fe as bash, ne as createLineStateIndex, S as createRuleGrammar, w as css, re as getGrammar, ue as html, ce as javascript, ae as json, x as listGrammars, de as markdown, ie as plaintext, b as registerGrammar, g as tokenize, _ as tokenizeDocument, te as tokenizeRange, le as typescript };
|