@stacksjs/components 0.2.854 → 0.2.857
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/CodeEditor-jg4w7e15.stx +497 -0
- package/dist/ContextMenu-43g3w5tp.stx +188 -0
- package/dist/DataGrid-7rt7v865.stx +376 -0
- package/dist/GraphView-0t3t9mec.stx +320 -0
- package/dist/JsonTree-satc4010.stx +317 -0
- package/dist/PreviewFrame-erbgvzj8.stx +257 -0
- package/dist/SplitPane-7sqfdwqa.stx +159 -0
- package/dist/code-editor/editor.js +2166 -0
- package/dist/component-api/component-api.js +36 -0
- package/dist/components/CodeBlock.d.ts +12 -5
- package/dist/context-menu/context-menu.js +575 -0
- package/dist/data-grid/data-grid.js +1244 -0
- package/dist/graph-view/graph-view.js +1408 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +34 -15
- package/dist/json-tree/json-tree.js +1121 -0
- package/dist/preview-frame/preview-frame.js +356 -0
- package/dist/split-pane/split-pane.js +364 -0
- package/dist/ui/code-editor/CodeEditor.d.ts +46 -0
- package/dist/ui/code-editor/controller.d.ts +103 -0
- package/dist/ui/code-editor/core/commands.d.ts +55 -0
- package/dist/ui/code-editor/core/completion.d.ts +40 -0
- package/dist/ui/code-editor/core/editor.d.ts +69 -0
- package/dist/ui/code-editor/core/highlight.d.ts +61 -0
- package/dist/ui/code-editor/core/history.d.ts +27 -0
- package/dist/ui/code-editor/core/index.d.ts +13 -0
- package/dist/ui/code-editor/core/keymap.d.ts +38 -0
- package/dist/ui/code-editor/core/selection.d.ts +30 -0
- package/dist/ui/code-editor/core/text.d.ts +64 -0
- package/dist/ui/code-editor/editor.d.ts +15 -0
- package/dist/ui/code-editor/index.d.ts +29 -0
- package/dist/ui/code-editor/tokenizer.d.ts +18 -0
- package/dist/ui/code-editor/view.d.ts +59 -0
- package/dist/ui/context-menu/ContextMenu.d.ts +14 -0
- package/dist/ui/context-menu/context-menu.d.ts +8 -0
- package/dist/ui/context-menu/core.d.ts +74 -0
- package/dist/ui/context-menu/index.d.ts +11 -0
- package/dist/ui/context-menu/view.d.ts +36 -0
- package/dist/ui/data-grid/DataGrid.d.ts +30 -0
- package/dist/ui/data-grid/core.d.ts +141 -0
- package/dist/ui/data-grid/data-grid.d.ts +9 -0
- package/dist/ui/data-grid/index.d.ts +20 -0
- package/dist/ui/data-grid/view.d.ts +56 -0
- package/dist/ui/graph-view/GraphView.d.ts +21 -0
- package/dist/ui/graph-view/core/edges.d.ts +34 -0
- package/dist/ui/graph-view/core/force.d.ts +10 -0
- package/dist/ui/graph-view/core/graph.d.ts +83 -0
- package/dist/ui/graph-view/core/index.d.ts +5 -0
- package/dist/ui/graph-view/core/layered.d.ts +24 -0
- package/dist/ui/graph-view/core/viewport.d.ts +34 -0
- package/dist/ui/graph-view/graph-view.d.ts +9 -0
- package/dist/ui/graph-view/index.d.ts +21 -0
- package/dist/ui/graph-view/view.d.ts +51 -0
- package/dist/ui/json-tree/JsonTree.d.ts +18 -0
- package/dist/ui/json-tree/core.d.ts +108 -0
- package/dist/ui/json-tree/index.d.ts +18 -0
- package/dist/ui/json-tree/json-tree.d.ts +10 -0
- package/dist/ui/json-tree/tinker.d.ts +84 -0
- package/dist/ui/json-tree/view.d.ts +59 -0
- package/dist/ui/preview-frame/PreviewFrame.d.ts +44 -0
- package/dist/ui/preview-frame/core.d.ts +81 -0
- package/dist/ui/preview-frame/index.d.ts +19 -0
- package/dist/ui/preview-frame/preview-frame.d.ts +8 -0
- package/dist/ui/preview-frame/view.d.ts +37 -0
- package/dist/ui/split-pane/SplitPane.d.ts +18 -0
- package/dist/ui/split-pane/core.d.ts +58 -0
- package/dist/ui/split-pane/index.d.ts +15 -0
- package/dist/ui/split-pane/split-pane.d.ts +8 -0
- package/dist/ui/split-pane/view.d.ts +27 -0
- package/dist/ui/virtual-table/index.d.ts +6 -0
- package/dist/utils/component-api.d.ts +4 -0
- package/dist/utils/highlighter.d.ts +19 -1
- package/dist/utils/highlighter.js +24 -7
- package/dist/utils/syntax-theme.d.ts +44 -0
- package/package.json +44 -4
- package/src/components/CodeBlock.stx +195 -17
- package/src/index.ts +10 -0
- package/src/ui/code-editor/CodeEditor.stx +497 -0
- package/src/ui/code-editor/README.md +135 -0
- package/src/ui/code-editor/controller.ts +517 -0
- package/src/ui/code-editor/core/commands.ts +381 -0
- package/src/ui/code-editor/core/completion.ts +212 -0
- package/src/ui/code-editor/core/editor.ts +319 -0
- package/src/ui/code-editor/core/highlight.ts +203 -0
- package/src/ui/code-editor/core/history.ts +190 -0
- package/src/ui/code-editor/core/index.ts +14 -0
- package/src/ui/code-editor/core/keymap.ts +125 -0
- package/src/ui/code-editor/core/selection.ts +104 -0
- package/src/ui/code-editor/core/text.ts +252 -0
- package/src/ui/code-editor/editor.ts +16 -0
- package/src/ui/code-editor/index.ts +46 -0
- package/src/ui/code-editor/tokenizer.ts +74 -0
- package/src/ui/code-editor/view.ts +1066 -0
- package/src/ui/context-menu/ContextMenu.stx +188 -0
- package/src/ui/context-menu/README.md +117 -0
- package/src/ui/context-menu/context-menu.ts +8 -0
- package/src/ui/context-menu/core.ts +250 -0
- package/src/ui/context-menu/index.ts +16 -0
- package/src/ui/context-menu/view.ts +540 -0
- package/src/ui/data-grid/DataGrid.stx +376 -0
- package/src/ui/data-grid/README.md +204 -0
- package/src/ui/data-grid/core.ts +813 -0
- package/src/ui/data-grid/data-grid.ts +9 -0
- package/src/ui/data-grid/index.ts +34 -0
- package/src/ui/data-grid/view.ts +806 -0
- package/src/ui/graph-view/GraphView.stx +320 -0
- package/src/ui/graph-view/README.md +210 -0
- package/src/ui/graph-view/core/edges.ts +180 -0
- package/src/ui/graph-view/core/force.ts +237 -0
- package/src/ui/graph-view/core/graph.ts +277 -0
- package/src/ui/graph-view/core/index.ts +5 -0
- package/src/ui/graph-view/core/layered.ts +256 -0
- package/src/ui/graph-view/core/viewport.ts +141 -0
- package/src/ui/graph-view/graph-view.ts +9 -0
- package/src/ui/graph-view/index.ts +35 -0
- package/src/ui/graph-view/view.ts +809 -0
- package/src/ui/json-tree/JsonTree.stx +317 -0
- package/src/ui/json-tree/README.md +193 -0
- package/src/ui/json-tree/core.ts +588 -0
- package/src/ui/json-tree/index.ts +28 -0
- package/src/ui/json-tree/json-tree.ts +10 -0
- package/src/ui/json-tree/tinker.ts +349 -0
- package/src/ui/json-tree/view.ts +665 -0
- package/src/ui/preview-frame/PreviewFrame.stx +257 -0
- package/src/ui/preview-frame/README.md +107 -0
- package/src/ui/preview-frame/core.ts +195 -0
- package/src/ui/preview-frame/index.ts +31 -0
- package/src/ui/preview-frame/preview-frame.ts +8 -0
- package/src/ui/preview-frame/view.ts +336 -0
- package/src/ui/split-pane/README.md +87 -0
- package/src/ui/split-pane/SplitPane.stx +159 -0
- package/src/ui/split-pane/core.ts +200 -0
- package/src/ui/split-pane/index.ts +24 -0
- package/src/ui/split-pane/split-pane.ts +8 -0
- package/src/ui/split-pane/view.ts +305 -0
- package/src/ui/virtual-table/index.ts +6 -0
- package/src/utils/component-api.ts +72 -0
- package/src/utils/highlighter.ts +121 -218
- package/src/utils/syntax-theme.ts +144 -0
|
@@ -0,0 +1,364 @@
|
|
|
1
|
+
// src/ui/split-pane/core.ts
|
|
2
|
+
var EPSILON = 0.000000001;
|
|
3
|
+
function equalSizes(count) {
|
|
4
|
+
return Array.from({ length: count }, () => 1 / count);
|
|
5
|
+
}
|
|
6
|
+
function normalizeSizes(sizes, count) {
|
|
7
|
+
if (count <= 0)
|
|
8
|
+
return [];
|
|
9
|
+
if (!sizes || sizes.length !== count || sizes.some((size) => typeof size !== "number" || !Number.isFinite(size) || size <= 0))
|
|
10
|
+
return equalSizes(count);
|
|
11
|
+
const total = sizes.reduce((sum, size) => sum + size, 0);
|
|
12
|
+
return sizes.map((size) => size / total);
|
|
13
|
+
}
|
|
14
|
+
function parseSizes(value) {
|
|
15
|
+
let list = value;
|
|
16
|
+
if (typeof value === "string") {
|
|
17
|
+
const text = value.trim();
|
|
18
|
+
if (text === "")
|
|
19
|
+
return null;
|
|
20
|
+
if (text.charAt(0) === "[") {
|
|
21
|
+
try {
|
|
22
|
+
list = JSON.parse(text);
|
|
23
|
+
} catch {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
} else {
|
|
27
|
+
list = text.split(/[\s,]+/).map((part) => Number.parseFloat(part));
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
if (!Array.isArray(list) || list.length === 0)
|
|
31
|
+
return null;
|
|
32
|
+
const numbers = list.map((entry) => typeof entry === "string" ? Number.parseFloat(entry) : entry);
|
|
33
|
+
return numbers.every((entry) => typeof entry === "number" && Number.isFinite(entry) && entry > 0) ? numbers : null;
|
|
34
|
+
}
|
|
35
|
+
function parseLength(value, fallback) {
|
|
36
|
+
if (typeof value === "number")
|
|
37
|
+
return Number.isFinite(value) && value >= 0 ? value : fallback;
|
|
38
|
+
if (typeof value !== "string" || value.trim() === "")
|
|
39
|
+
return fallback;
|
|
40
|
+
const parsed = Number.parseFloat(value);
|
|
41
|
+
return Number.isFinite(parsed) && parsed >= 0 ? parsed : fallback;
|
|
42
|
+
}
|
|
43
|
+
function fitSizes(sizes, total, limits) {
|
|
44
|
+
const count = sizes.length;
|
|
45
|
+
if (count === 0 || total <= 0)
|
|
46
|
+
return [...sizes];
|
|
47
|
+
const minimums = limits.map((limit) => Math.max(0, limit.min));
|
|
48
|
+
const minimumTotal = minimums.reduce((sum, min) => sum + min, 0);
|
|
49
|
+
if (minimumTotal >= total)
|
|
50
|
+
return minimumTotal === 0 ? [...sizes] : minimums.map((min) => min / minimumTotal);
|
|
51
|
+
const pixels = sizes.map((size) => size * total);
|
|
52
|
+
for (let pass = 0;pass <= count; pass++) {
|
|
53
|
+
let surplus = 0;
|
|
54
|
+
for (let index = 0;index < count; index++) {
|
|
55
|
+
const clamped = Math.min(Math.max(pixels[index], minimums[index]), limits[index].max);
|
|
56
|
+
surplus += pixels[index] - clamped;
|
|
57
|
+
pixels[index] = clamped;
|
|
58
|
+
}
|
|
59
|
+
if (Math.abs(surplus) < EPSILON)
|
|
60
|
+
break;
|
|
61
|
+
const room = pixels.map((size, index) => surplus > 0 ? limits[index].max - size : size - minimums[index]);
|
|
62
|
+
const roomTotal = room.reduce((sum, value) => sum + (Number.isFinite(value) ? value : total), 0);
|
|
63
|
+
if (roomTotal < EPSILON)
|
|
64
|
+
break;
|
|
65
|
+
for (let index = 0;index < count; index++) {
|
|
66
|
+
const share = (Number.isFinite(room[index]) ? room[index] : total) / roomTotal;
|
|
67
|
+
pixels[index] += surplus * share;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
const sum = pixels.reduce((a, b) => a + b, 0);
|
|
71
|
+
return pixels.map((size) => size / sum);
|
|
72
|
+
}
|
|
73
|
+
function resizeAt(sizes, index, delta, total, limits) {
|
|
74
|
+
const count = sizes.length;
|
|
75
|
+
if (index < 0 || index >= count - 1 || total <= 0 || delta === 0)
|
|
76
|
+
return [...sizes];
|
|
77
|
+
const pixels = sizes.map((size) => size * total);
|
|
78
|
+
const forward = delta > 0;
|
|
79
|
+
const grower = forward ? index : index + 1;
|
|
80
|
+
const step = forward ? 1 : -1;
|
|
81
|
+
let wanted = Math.min(Math.abs(delta), limits[grower].max - pixels[grower]);
|
|
82
|
+
if (wanted <= 0)
|
|
83
|
+
return [...sizes];
|
|
84
|
+
let taken = 0;
|
|
85
|
+
for (let pane = forward ? index + 1 : index;pane >= 0 && pane < count && wanted > EPSILON; pane += step) {
|
|
86
|
+
const give = Math.min(wanted, Math.max(0, pixels[pane] - Math.max(0, limits[pane].min)));
|
|
87
|
+
pixels[pane] -= give;
|
|
88
|
+
taken += give;
|
|
89
|
+
wanted -= give;
|
|
90
|
+
}
|
|
91
|
+
pixels[grower] += taken;
|
|
92
|
+
return pixels.map((size) => size / total);
|
|
93
|
+
}
|
|
94
|
+
function dividerRange(sizes, index, total, limits) {
|
|
95
|
+
const pixels = sizes.map((size) => size * total);
|
|
96
|
+
const room = (from, to) => {
|
|
97
|
+
let sum = 0;
|
|
98
|
+
for (let pane = from;pane <= to; pane++)
|
|
99
|
+
sum += Math.max(0, pixels[pane] - Math.max(0, limits[pane].min));
|
|
100
|
+
return sum;
|
|
101
|
+
};
|
|
102
|
+
return {
|
|
103
|
+
back: Math.min(room(0, index), limits[index + 1].max - pixels[index + 1]),
|
|
104
|
+
forward: Math.min(room(index + 1, sizes.length - 1), limits[index].max - pixels[index])
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
function separatorValue(sizes, index, total, limits) {
|
|
108
|
+
const range = dividerRange(sizes, index, total, limits);
|
|
109
|
+
const now = sizes[index] * 100;
|
|
110
|
+
const span = total > 0 ? 100 / total : 0;
|
|
111
|
+
return {
|
|
112
|
+
now: Math.round(now),
|
|
113
|
+
min: Math.round(now - range.back * span),
|
|
114
|
+
max: Math.round(now + range.forward * span)
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
function storageName(key) {
|
|
118
|
+
return `stx:split-pane:${key}`;
|
|
119
|
+
}
|
|
120
|
+
function serializeSizes(sizes) {
|
|
121
|
+
return JSON.stringify(sizes.map((size) => Math.round(size * 1e4) / 1e4));
|
|
122
|
+
}
|
|
123
|
+
// src/ui/split-pane/view.ts
|
|
124
|
+
var SEPARATOR = "data-split-separator";
|
|
125
|
+
|
|
126
|
+
class SplitPaneView {
|
|
127
|
+
root;
|
|
128
|
+
callbacks;
|
|
129
|
+
direction;
|
|
130
|
+
panes = [];
|
|
131
|
+
separators = [];
|
|
132
|
+
sizes = [];
|
|
133
|
+
initial = [];
|
|
134
|
+
limits = [];
|
|
135
|
+
minSize;
|
|
136
|
+
step;
|
|
137
|
+
label;
|
|
138
|
+
storageKey;
|
|
139
|
+
observer = null;
|
|
140
|
+
drag = null;
|
|
141
|
+
disposers = [];
|
|
142
|
+
constructor(root, options = {}, callbacks = {}) {
|
|
143
|
+
this.root = root;
|
|
144
|
+
this.callbacks = callbacks;
|
|
145
|
+
this.direction = options.direction === "vertical" ? "vertical" : "horizontal";
|
|
146
|
+
this.minSize = options.minSize ?? 48;
|
|
147
|
+
this.step = options.step ?? 16;
|
|
148
|
+
this.label = options.label || "Resize panes";
|
|
149
|
+
this.storageKey = options.storageKey || "";
|
|
150
|
+
this.collect();
|
|
151
|
+
this.initial = this.startingSizes(options.sizes);
|
|
152
|
+
this.sizes = normalizeSizes(this.stored() ?? this.initial, this.panes.length);
|
|
153
|
+
this.build();
|
|
154
|
+
this.apply(false);
|
|
155
|
+
if (typeof ResizeObserver !== "undefined") {
|
|
156
|
+
this.observer = new ResizeObserver(() => this.apply(false));
|
|
157
|
+
this.observer.observe(this.root);
|
|
158
|
+
}
|
|
159
|
+
this.root.setAttribute("data-split-ready", "");
|
|
160
|
+
}
|
|
161
|
+
getSizes() {
|
|
162
|
+
return [...this.sizes];
|
|
163
|
+
}
|
|
164
|
+
setSizes(sizes) {
|
|
165
|
+
if (!sizes || sizes.length !== this.panes.length)
|
|
166
|
+
return;
|
|
167
|
+
this.sizes = normalizeSizes(sizes, this.panes.length);
|
|
168
|
+
this.apply(true);
|
|
169
|
+
this.report(-1, "api", true);
|
|
170
|
+
}
|
|
171
|
+
reset(index = -1) {
|
|
172
|
+
this.sizes = [...this.initial];
|
|
173
|
+
this.apply(true);
|
|
174
|
+
this.report(index, "reset", true);
|
|
175
|
+
}
|
|
176
|
+
setDirection(direction) {
|
|
177
|
+
const next = direction === "vertical" ? "vertical" : "horizontal";
|
|
178
|
+
if (next === this.direction)
|
|
179
|
+
return;
|
|
180
|
+
this.direction = next;
|
|
181
|
+
this.root.setAttribute("data-direction", next);
|
|
182
|
+
for (const separator of this.separators)
|
|
183
|
+
separator.setAttribute("aria-orientation", next === "horizontal" ? "vertical" : "horizontal");
|
|
184
|
+
this.apply(false);
|
|
185
|
+
}
|
|
186
|
+
destroy() {
|
|
187
|
+
this.observer?.disconnect();
|
|
188
|
+
for (const dispose of this.disposers)
|
|
189
|
+
dispose();
|
|
190
|
+
for (const separator of this.separators)
|
|
191
|
+
separator.remove();
|
|
192
|
+
for (const pane of this.panes) {
|
|
193
|
+
pane.style.removeProperty("flex");
|
|
194
|
+
pane.removeAttribute("data-split-pane");
|
|
195
|
+
}
|
|
196
|
+
this.root.removeAttribute("data-split-ready");
|
|
197
|
+
}
|
|
198
|
+
available() {
|
|
199
|
+
const box = this.root.getBoundingClientRect();
|
|
200
|
+
const length = this.direction === "horizontal" ? box.width : box.height;
|
|
201
|
+
let taken = 0;
|
|
202
|
+
for (const separator of this.separators) {
|
|
203
|
+
const size = separator.getBoundingClientRect();
|
|
204
|
+
taken += this.direction === "horizontal" ? size.width : size.height;
|
|
205
|
+
}
|
|
206
|
+
return Math.max(0, length - taken);
|
|
207
|
+
}
|
|
208
|
+
collect() {
|
|
209
|
+
this.panes = Array.from(this.root.children).filter((child) => child instanceof HTMLElement && !child.hasAttribute(SEPARATOR));
|
|
210
|
+
this.limits = this.panes.map((pane) => ({
|
|
211
|
+
min: parseLength(pane.getAttribute("data-min-size"), this.minSize),
|
|
212
|
+
max: parseLength(pane.getAttribute("data-max-size"), Number.POSITIVE_INFINITY)
|
|
213
|
+
}));
|
|
214
|
+
}
|
|
215
|
+
startingSizes(sizes) {
|
|
216
|
+
const own = this.panes.map((pane) => Number.parseFloat(pane.getAttribute("data-size") || ""));
|
|
217
|
+
const fromPanes = own.every((size) => Number.isFinite(size) && size > 0) ? own : null;
|
|
218
|
+
return normalizeSizes(sizes && sizes.length === this.panes.length ? sizes : fromPanes, this.panes.length);
|
|
219
|
+
}
|
|
220
|
+
stored() {
|
|
221
|
+
if (!this.storageKey)
|
|
222
|
+
return null;
|
|
223
|
+
try {
|
|
224
|
+
const sizes = parseSizes(localStorage.getItem(storageName(this.storageKey)));
|
|
225
|
+
return sizes && sizes.length === this.panes.length ? sizes : null;
|
|
226
|
+
} catch {
|
|
227
|
+
return null;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
store() {
|
|
231
|
+
if (!this.storageKey)
|
|
232
|
+
return;
|
|
233
|
+
try {
|
|
234
|
+
localStorage.setItem(storageName(this.storageKey), serializeSizes(this.sizes));
|
|
235
|
+
} catch {}
|
|
236
|
+
}
|
|
237
|
+
build() {
|
|
238
|
+
const prefix = this.root.id || `split-${Math.random().toString(36).slice(2, 8)}`;
|
|
239
|
+
this.panes.forEach((pane, index) => {
|
|
240
|
+
pane.setAttribute("data-split-pane", "");
|
|
241
|
+
if (!pane.id)
|
|
242
|
+
pane.id = `${prefix}-pane-${index}`;
|
|
243
|
+
if (index === this.panes.length - 1)
|
|
244
|
+
return;
|
|
245
|
+
const separator = document.createElement("div");
|
|
246
|
+
separator.setAttribute(SEPARATOR, "");
|
|
247
|
+
separator.setAttribute("role", "separator");
|
|
248
|
+
separator.setAttribute("tabindex", "0");
|
|
249
|
+
separator.setAttribute("aria-orientation", this.direction === "horizontal" ? "vertical" : "horizontal");
|
|
250
|
+
separator.setAttribute("aria-controls", pane.id);
|
|
251
|
+
separator.setAttribute("aria-label", this.panes.length > 2 ? `${this.label} ${index + 1} and ${index + 2}` : this.label);
|
|
252
|
+
separator.className = "stx-split-separator";
|
|
253
|
+
pane.after(separator);
|
|
254
|
+
this.separators.push(separator);
|
|
255
|
+
const listen = (type, handler) => {
|
|
256
|
+
separator.addEventListener(type, handler);
|
|
257
|
+
this.disposers.push(() => separator.removeEventListener(type, handler));
|
|
258
|
+
};
|
|
259
|
+
listen("pointerdown", (event) => this.onPointerDown(event, index));
|
|
260
|
+
listen("pointermove", (event) => this.onPointerMove(event));
|
|
261
|
+
listen("pointerup", (event) => this.onPointerEnd(event));
|
|
262
|
+
listen("pointercancel", (event) => this.onPointerEnd(event));
|
|
263
|
+
listen("dblclick", () => this.reset(index));
|
|
264
|
+
listen("keydown", (event) => this.onKeyDown(event, index));
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
apply(persist) {
|
|
268
|
+
const total = this.available();
|
|
269
|
+
if (total > 0)
|
|
270
|
+
this.sizes = fitSizes(this.sizes, total, this.limits);
|
|
271
|
+
this.panes.forEach((pane, index) => {
|
|
272
|
+
pane.style.flex = `${(this.sizes[index] * 1000).toFixed(3)} 1 0px`;
|
|
273
|
+
});
|
|
274
|
+
this.separators.forEach((separator, index) => {
|
|
275
|
+
const value = separatorValue(this.sizes, index, total, this.limits);
|
|
276
|
+
separator.setAttribute("aria-valuenow", String(value.now));
|
|
277
|
+
separator.setAttribute("aria-valuemin", String(value.min));
|
|
278
|
+
separator.setAttribute("aria-valuemax", String(value.max));
|
|
279
|
+
});
|
|
280
|
+
if (persist)
|
|
281
|
+
this.store();
|
|
282
|
+
}
|
|
283
|
+
report(index, source, end) {
|
|
284
|
+
const total = this.available();
|
|
285
|
+
const detail = { sizes: [...this.sizes], pixels: this.sizes.map((size) => Math.round(size * total)), index, source };
|
|
286
|
+
this.callbacks.onResize?.(detail);
|
|
287
|
+
if (end)
|
|
288
|
+
this.callbacks.onResizeEnd?.(detail);
|
|
289
|
+
}
|
|
290
|
+
position(event) {
|
|
291
|
+
return this.direction === "horizontal" ? event.clientX : event.clientY;
|
|
292
|
+
}
|
|
293
|
+
onPointerDown(event, index) {
|
|
294
|
+
if (event.button !== 0)
|
|
295
|
+
return;
|
|
296
|
+
event.preventDefault();
|
|
297
|
+
const separator = this.separators[index];
|
|
298
|
+
try {
|
|
299
|
+
separator.setPointerCapture(event.pointerId);
|
|
300
|
+
} catch {}
|
|
301
|
+
this.drag = { index, start: this.position(event), sizes: [...this.sizes], pointer: event.pointerId };
|
|
302
|
+
this.root.setAttribute("data-dragging", "");
|
|
303
|
+
separator.setAttribute("data-active", "");
|
|
304
|
+
}
|
|
305
|
+
onPointerMove(event) {
|
|
306
|
+
const drag = this.drag;
|
|
307
|
+
if (!drag || event.pointerId !== drag.pointer)
|
|
308
|
+
return;
|
|
309
|
+
this.sizes = resizeAt(drag.sizes, drag.index, this.position(event) - drag.start, this.available(), this.limits);
|
|
310
|
+
this.apply(false);
|
|
311
|
+
this.report(drag.index, "pointer", false);
|
|
312
|
+
}
|
|
313
|
+
onPointerEnd(event) {
|
|
314
|
+
const drag = this.drag;
|
|
315
|
+
if (!drag || event.pointerId !== drag.pointer)
|
|
316
|
+
return;
|
|
317
|
+
this.drag = null;
|
|
318
|
+
this.root.removeAttribute("data-dragging");
|
|
319
|
+
this.separators[drag.index].removeAttribute("data-active");
|
|
320
|
+
try {
|
|
321
|
+
this.separators[drag.index].releasePointerCapture(event.pointerId);
|
|
322
|
+
} catch {}
|
|
323
|
+
this.store();
|
|
324
|
+
this.report(drag.index, "pointer", true);
|
|
325
|
+
}
|
|
326
|
+
onKeyDown(event, index) {
|
|
327
|
+
const horizontal = this.direction === "horizontal";
|
|
328
|
+
const total = this.available();
|
|
329
|
+
const stride = this.step * (event.shiftKey ? 5 : 1);
|
|
330
|
+
let delta = 0;
|
|
331
|
+
if (event.key === (horizontal ? "ArrowLeft" : "ArrowUp"))
|
|
332
|
+
delta = -stride;
|
|
333
|
+
else if (event.key === (horizontal ? "ArrowRight" : "ArrowDown"))
|
|
334
|
+
delta = stride;
|
|
335
|
+
else if (event.key === "Home")
|
|
336
|
+
delta = -dividerRange(this.sizes, index, total, this.limits).back;
|
|
337
|
+
else if (event.key === "End")
|
|
338
|
+
delta = dividerRange(this.sizes, index, total, this.limits).forward;
|
|
339
|
+
else if (event.key === "Enter") {
|
|
340
|
+
event.preventDefault();
|
|
341
|
+
this.reset(index);
|
|
342
|
+
return;
|
|
343
|
+
} else {
|
|
344
|
+
return;
|
|
345
|
+
}
|
|
346
|
+
event.preventDefault();
|
|
347
|
+
this.sizes = resizeAt(this.sizes, index, delta, total, this.limits);
|
|
348
|
+
this.apply(true);
|
|
349
|
+
this.report(index, "keyboard", true);
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
export {
|
|
353
|
+
SplitPaneView,
|
|
354
|
+
dividerRange,
|
|
355
|
+
equalSizes,
|
|
356
|
+
fitSizes,
|
|
357
|
+
normalizeSizes,
|
|
358
|
+
parseLength,
|
|
359
|
+
parseSizes,
|
|
360
|
+
resizeAt,
|
|
361
|
+
separatorValue,
|
|
362
|
+
serializeSizes,
|
|
363
|
+
storageName
|
|
364
|
+
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { DefineComponent } from '@stacksjs/stx';
|
|
2
|
+
declare const __dtsx_component__: __DtsxStxComponentType;
|
|
3
|
+
export declare const value: unknown;
|
|
4
|
+
export declare const language: unknown;
|
|
5
|
+
export declare const readonly: ReturnType<typeof $bool>;
|
|
6
|
+
export declare const disabled: ReturnType<typeof $bool>;
|
|
7
|
+
export declare const lineNumbers: unknown;
|
|
8
|
+
export declare const highlight: unknown;
|
|
9
|
+
export declare const autoComplete: unknown;
|
|
10
|
+
export declare const inlineDiagnostics: unknown;
|
|
11
|
+
export declare const insertSpaces: unknown;
|
|
12
|
+
export declare const autofocus: ReturnType<typeof $bool>;
|
|
13
|
+
export declare const tabSize: unknown;
|
|
14
|
+
export declare const placeholder: unknown;
|
|
15
|
+
export declare const label: unknown;
|
|
16
|
+
export declare const name: unknown;
|
|
17
|
+
export declare const className: unknown;
|
|
18
|
+
/*
|
|
19
|
+
* A CSS length. Left out, the editor is 20rem tall; `height="100%"` fills a
|
|
20
|
+
* sized parent, which is what a pane in a split layout wants.
|
|
21
|
+
*/
|
|
22
|
+
export declare const height: unknown;
|
|
23
|
+
/*
|
|
24
|
+
* `light` or `dark` pins the code colours for this editor whatever the page is
|
|
25
|
+
* doing; anything else follows the page.
|
|
26
|
+
*/
|
|
27
|
+
export declare const theme: unknown;
|
|
28
|
+
/*
|
|
29
|
+
* Ids unique to this instance: the field, the popup it controls and the
|
|
30
|
+
* status line it is described by all have to be findable when two editors
|
|
31
|
+
* share a page.
|
|
32
|
+
*/
|
|
33
|
+
export declare const inputId: unknown;
|
|
34
|
+
export declare const popupId: string;
|
|
35
|
+
export declare const statusId: string;
|
|
36
|
+
export declare const editorClasses: unknown;
|
|
37
|
+
/*
|
|
38
|
+
* Arrays that arrive as plain props. A bound one (`:completions="names()"`)
|
|
39
|
+
* is read live by the client script; these are what it starts from.
|
|
40
|
+
*/
|
|
41
|
+
export declare const completions: unknown;
|
|
42
|
+
export declare const widgets: unknown;
|
|
43
|
+
export declare const diagnostics: unknown;
|
|
44
|
+
export declare const ghostText: boolean;
|
|
45
|
+
declare type __DtsxStxComponentType = DefineComponent<{ value?: string, language?: string, readonly?: unknown, disabled?: unknown, lineNumbers?: unknown, highlight?: unknown, autoComplete?: unknown, inlineDiagnostics?: unknown, insertSpaces?: unknown, autofocus?: unknown, tabSize?: unknown, placeholder?: string, label?: string, name?: string, className?: string, height?: string, theme?: unknown, id?: string, completions?: unknown, widgets?: unknown, diagnostics?: unknown, ghostText?: unknown }> & { readonly __stxEmits?: ["input", "change", "selection", "run", "run-selection", "complete", "completion-accept", "ghost", "focus", "blur"] }
|
|
46
|
+
export default __dtsx_component__;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { EditorCore } from './core/index';
|
|
2
|
+
import { EditorView } from './view';
|
|
3
|
+
import type { CompletionItem, Keymap, Transaction } from './core/index';
|
|
4
|
+
import type { EditorDiagnostic, EditorWidget } from './view';
|
|
5
|
+
export declare interface CodeEditorConfig {
|
|
6
|
+
value?: string
|
|
7
|
+
language?: string
|
|
8
|
+
tabSize?: number
|
|
9
|
+
insertSpaces?: boolean
|
|
10
|
+
readOnly?: boolean
|
|
11
|
+
lineNumbers?: boolean
|
|
12
|
+
highlight?: boolean
|
|
13
|
+
autoComplete?: boolean
|
|
14
|
+
completions?: readonly CompletionItem[]
|
|
15
|
+
keymap?: Keymap
|
|
16
|
+
inlineDiagnostics?: boolean
|
|
17
|
+
}
|
|
18
|
+
export declare interface SelectionDetail {
|
|
19
|
+
anchor: number
|
|
20
|
+
head: number
|
|
21
|
+
from: number
|
|
22
|
+
to: number
|
|
23
|
+
line: number
|
|
24
|
+
column: number
|
|
25
|
+
text: string
|
|
26
|
+
empty: boolean
|
|
27
|
+
}
|
|
28
|
+
export declare interface RunDetail {
|
|
29
|
+
value: string
|
|
30
|
+
selection: SelectionDetail
|
|
31
|
+
}
|
|
32
|
+
export declare interface RunSelectionDetail {
|
|
33
|
+
text: string
|
|
34
|
+
from: number
|
|
35
|
+
to: number
|
|
36
|
+
line: number
|
|
37
|
+
selected: boolean
|
|
38
|
+
}
|
|
39
|
+
export declare interface CompletionRequest {
|
|
40
|
+
query: string
|
|
41
|
+
from: number
|
|
42
|
+
to: number
|
|
43
|
+
line: number
|
|
44
|
+
column: number
|
|
45
|
+
textBefore: string
|
|
46
|
+
explicit: boolean
|
|
47
|
+
trigger: string
|
|
48
|
+
}
|
|
49
|
+
export declare interface PopupItem {
|
|
50
|
+
id: string
|
|
51
|
+
index: number
|
|
52
|
+
label: string
|
|
53
|
+
detail: string
|
|
54
|
+
kind: string
|
|
55
|
+
selected: boolean
|
|
56
|
+
}
|
|
57
|
+
export declare interface PopupState {
|
|
58
|
+
open: boolean
|
|
59
|
+
items: PopupItem[]
|
|
60
|
+
activeId: string
|
|
61
|
+
left: number
|
|
62
|
+
top: number
|
|
63
|
+
placement: 'below' | 'above'
|
|
64
|
+
}
|
|
65
|
+
export declare interface CodeEditorHooks {
|
|
66
|
+
onChange?: (value: string, transaction: Transaction) => void
|
|
67
|
+
onSelection?: (detail: SelectionDetail) => void
|
|
68
|
+
onRun?: (detail: RunDetail) => void
|
|
69
|
+
onRunSelection?: (detail: RunSelectionDetail) => void
|
|
70
|
+
onCompleteRequest?: (request: CompletionRequest) => void
|
|
71
|
+
onCompletionAccept?: (item: CompletionItem) => void
|
|
72
|
+
onPopup?: (state: PopupState) => void
|
|
73
|
+
onGhost?: (outcome: 'accept' | 'dismiss', text: string) => void
|
|
74
|
+
onFocus?: () => void
|
|
75
|
+
onBlur?: () => void
|
|
76
|
+
}
|
|
77
|
+
export declare class CodeEditorController {
|
|
78
|
+
readonly core: EditorCore;
|
|
79
|
+
readonly view: EditorView;
|
|
80
|
+
constructor(root: HTMLElement, config?: CodeEditorConfig, hooks?: CodeEditorHooks);
|
|
81
|
+
get value(): string;
|
|
82
|
+
setValue(value: string): void;
|
|
83
|
+
get selection(): SelectionDetail;
|
|
84
|
+
setSelection(anchor: number, head?: number): void;
|
|
85
|
+
focus(): void;
|
|
86
|
+
setLanguage(language: string): void;
|
|
87
|
+
setHighlight(highlight: boolean): void;
|
|
88
|
+
setReadOnly(readOnly: boolean): void;
|
|
89
|
+
setLineNumbers(show: boolean): void;
|
|
90
|
+
setTabSize(tabSize: number): void;
|
|
91
|
+
setInsertSpaces(insertSpaces: boolean): void;
|
|
92
|
+
setAutoComplete(autoComplete: boolean): void;
|
|
93
|
+
setKeymap(keymap: Keymap): void;
|
|
94
|
+
setCompletions(completions: readonly CompletionItem[]): void;
|
|
95
|
+
setWidgets(widgets: readonly EditorWidget[]): void;
|
|
96
|
+
setDiagnostics(diagnostics: readonly EditorDiagnostic[]): void;
|
|
97
|
+
setGhostText(text: string | null): void;
|
|
98
|
+
showCompletions(items: readonly CompletionItem[], options?: { from?: number }): void;
|
|
99
|
+
closeCompletions(): void;
|
|
100
|
+
acceptCompletion(index?: number): boolean;
|
|
101
|
+
selectCompletion(index: number): void;
|
|
102
|
+
destroy(): void;
|
|
103
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { Command, EditorCore } from './editor';
|
|
2
|
+
/** First and last line the main range touches. */
|
|
3
|
+
declare function selectedLines(editor: EditorCore): { first: number, last: number };
|
|
4
|
+
/**
|
|
5
|
+
* Where the selection goes when whole lines are changed under it.
|
|
6
|
+
*
|
|
7
|
+
* The end that sits at the very start of a line stays there. Left to the
|
|
8
|
+
* default, indenting would push it in with the text, and a selection that
|
|
9
|
+
* covered three whole lines would cover two and most of a third.
|
|
10
|
+
*/
|
|
11
|
+
declare function linewiseSelection(editor: EditorCore, changes: readonly ChangeSpec[]): SelectionRange;
|
|
12
|
+
/**
|
|
13
|
+
* A typed character, where the editor has an opinion about it.
|
|
14
|
+
*
|
|
15
|
+
* Opening a bracket closes it. Typing a closer that is already there steps
|
|
16
|
+
* over it instead of doubling it. A closing brace on a line of nothing but
|
|
17
|
+
* indentation drops back a level. With text selected, an opener wraps it.
|
|
18
|
+
*
|
|
19
|
+
* Returns false for everything else, and the text field inserts the character
|
|
20
|
+
* itself - which is what keeps input methods and dead keys working, since the
|
|
21
|
+
* editor never sees a composition as individual keys.
|
|
22
|
+
*/
|
|
23
|
+
export declare function handleTextInput(editor: EditorCore, text: string): boolean;
|
|
24
|
+
export declare function registerDefaultCommands(editor: EditorCore): void;
|
|
25
|
+
/**
|
|
26
|
+
* Enter: a new line that starts where the old one did.
|
|
27
|
+
*
|
|
28
|
+
* One level deeper after an opening bracket. Between a pair, the closer goes
|
|
29
|
+
* to a line of its own and the caret is left on the indented line between.
|
|
30
|
+
*/
|
|
31
|
+
export declare const insertNewlineAndIndent: Command;
|
|
32
|
+
/** Tab: indent the selected lines, or move the caret to the next tab stop. */
|
|
33
|
+
export declare const indentMore: Command;
|
|
34
|
+
/** Shift-Tab: take one level of indentation off every selected line. */
|
|
35
|
+
export declare const indentLess: Command;
|
|
36
|
+
/**
|
|
37
|
+
* Comment the selected lines, or uncomment them if every one already is.
|
|
38
|
+
*
|
|
39
|
+
* The markers line up at the shallowest indentation among the lines rather
|
|
40
|
+
* than at column zero or at each line's own, so a commented block still reads
|
|
41
|
+
* as a block and uncommenting gives back exactly what was there.
|
|
42
|
+
*/
|
|
43
|
+
export declare const toggleLineComment: Command;
|
|
44
|
+
/**
|
|
45
|
+
* Backspace, where it means more than one character.
|
|
46
|
+
*
|
|
47
|
+
* Between an empty pair it takes both halves, since the closer was never
|
|
48
|
+
* typed. In leading spaces it goes back a whole tab stop. Anything else is
|
|
49
|
+
* left to the text field.
|
|
50
|
+
*/
|
|
51
|
+
export declare const deleteBackward: Command;
|
|
52
|
+
export declare const undo: Command;
|
|
53
|
+
export declare const redo: Command;
|
|
54
|
+
/** The commands every editor starts with, by the name a keymap refers to. */
|
|
55
|
+
export declare const defaultCommands: Readonly<Record<string, Command>>;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { ChangeSpec } from './text';
|
|
2
|
+
/** Where the word ending at `offset` begins. */
|
|
3
|
+
export declare function wordStart(text: string, offset: number): number;
|
|
4
|
+
/**
|
|
5
|
+
* How well `query` matches `text`, or null when it does not.
|
|
6
|
+
*
|
|
7
|
+
* Every character of the query has to appear in order. A match that starts at
|
|
8
|
+
* the beginning beats one that does not, a run of adjacent characters beats
|
|
9
|
+
* the same characters scattered, a match at the start of a word (`gU` for
|
|
10
|
+
* `getUser`) beats one in the middle of it, and an exact case match breaks ties.
|
|
11
|
+
*/
|
|
12
|
+
export declare function matchScore(query: string, text: string): { score: number, matches: number[] } | null;
|
|
13
|
+
/** The items a query leaves, best first. Order among equals is the host's. */
|
|
14
|
+
export declare function rankCompletions(items: readonly CompletionItem[], query: string): RankedCompletion[];
|
|
15
|
+
export declare interface CompletionItem {
|
|
16
|
+
label: string
|
|
17
|
+
insert?: string
|
|
18
|
+
detail?: string
|
|
19
|
+
kind?: string
|
|
20
|
+
filterText?: string
|
|
21
|
+
boost?: number
|
|
22
|
+
}
|
|
23
|
+
export declare interface RankedCompletion {
|
|
24
|
+
item: CompletionItem
|
|
25
|
+
score: number
|
|
26
|
+
matches: number[]
|
|
27
|
+
}
|
|
28
|
+
export declare class CompletionList {
|
|
29
|
+
get isOpen(): boolean;
|
|
30
|
+
get visible(): readonly RankedCompletion[];
|
|
31
|
+
get selectedIndex(): number;
|
|
32
|
+
get selected(): CompletionItem | undefined;
|
|
33
|
+
get from(): number;
|
|
34
|
+
open(items: readonly CompletionItem[], from: number, query: string): void;
|
|
35
|
+
filter(query: string): void;
|
|
36
|
+
move(delta: number): void;
|
|
37
|
+
select(index: number): void;
|
|
38
|
+
close(): void;
|
|
39
|
+
accept(head: number): { change: ChangeSpec, item: CompletionItem } | null;
|
|
40
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { History } from './history';
|
|
2
|
+
import { TextDocument } from './text';
|
|
3
|
+
import type { AppliedChange, ChangeSpec, Position } from './text';
|
|
4
|
+
import type { EditorSelection, SelectionRange } from './selection';
|
|
5
|
+
export declare function languageConfig(language: string | undefined): LanguageConfig;
|
|
6
|
+
export declare const DEFAULT_LANGUAGE: LanguageConfig;
|
|
7
|
+
/** Per-language overrides, by the id the highlighter knows the language as. */
|
|
8
|
+
export declare const LANGUAGE_CONFIGS: Readonly<Record<string, Partial<LanguageConfig>>>;
|
|
9
|
+
export declare interface LanguageConfig {
|
|
10
|
+
lineComment: string
|
|
11
|
+
brackets: Record<string, string>
|
|
12
|
+
quotes: string[]
|
|
13
|
+
}
|
|
14
|
+
export declare interface EditorOptions {
|
|
15
|
+
value?: string
|
|
16
|
+
tabSize?: number
|
|
17
|
+
insertSpaces?: boolean
|
|
18
|
+
readOnly?: boolean
|
|
19
|
+
language?: Partial<LanguageConfig>
|
|
20
|
+
historyDepth?: number
|
|
21
|
+
now?: () => number
|
|
22
|
+
}
|
|
23
|
+
export declare interface TransactionSpec {
|
|
24
|
+
changes?: ChangeSpec[]
|
|
25
|
+
selection?: EditorSelection | SelectionRange
|
|
26
|
+
kind?: string
|
|
27
|
+
origin?: TransactionOrigin
|
|
28
|
+
addToHistory?: boolean
|
|
29
|
+
scrollIntoView?: boolean
|
|
30
|
+
}
|
|
31
|
+
export declare interface Transaction {
|
|
32
|
+
changes: AppliedChange[]
|
|
33
|
+
before: EditorSelection
|
|
34
|
+
selection: EditorSelection
|
|
35
|
+
docChanged: boolean
|
|
36
|
+
selectionChanged: boolean
|
|
37
|
+
kind: string
|
|
38
|
+
origin: TransactionOrigin
|
|
39
|
+
scrollIntoView: boolean
|
|
40
|
+
}
|
|
41
|
+
/** Where a transaction came from, which decides who still has to be told. */
|
|
42
|
+
export type TransactionOrigin = 'input' | 'command' | 'api' | 'history';
|
|
43
|
+
export type TransactionListener = (transaction: Transaction, editor: EditorCore) => void;
|
|
44
|
+
/** A command answers whether it did anything, so a key can fall through. */
|
|
45
|
+
export type Command = (editor: EditorCore) => boolean;
|
|
46
|
+
export declare class EditorCore {
|
|
47
|
+
readonly doc: TextDocument;
|
|
48
|
+
readonly history: History;
|
|
49
|
+
readonly commands: Map<string, Command>;
|
|
50
|
+
tabSize: number;
|
|
51
|
+
insertSpaces: boolean;
|
|
52
|
+
readOnly: boolean;
|
|
53
|
+
language: LanguageConfig;
|
|
54
|
+
constructor(options?: EditorOptions);
|
|
55
|
+
get selection(): EditorSelection;
|
|
56
|
+
get main(): SelectionRange;
|
|
57
|
+
get value(): string;
|
|
58
|
+
get indentUnit(): string;
|
|
59
|
+
get cursor(): Position;
|
|
60
|
+
get selectedText(): string;
|
|
61
|
+
subscribe(listener: TransactionListener): () => void;
|
|
62
|
+
dispatch(spec: TransactionSpec): Transaction;
|
|
63
|
+
setSelection(anchor: number, head?: number, origin?: TransactionOrigin): Transaction;
|
|
64
|
+
setValue(text: string, options?: { keepHistory?: boolean }): Transaction;
|
|
65
|
+
syncInput(value: string, selectionStart: number, selectionEnd: number, backward?: boolean): Transaction;
|
|
66
|
+
undo(): boolean;
|
|
67
|
+
redo(): boolean;
|
|
68
|
+
exec(name: string): boolean;
|
|
69
|
+
}
|