@stacksjs/components 0.2.855 → 0.2.858

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.
Files changed (100) hide show
  1. package/dist/ContextMenu-43g3w5tp.stx +188 -0
  2. package/dist/DataGrid-7rt7v865.stx +376 -0
  3. package/dist/GraphView-0t3t9mec.stx +320 -0
  4. package/dist/JsonTree-satc4010.stx +317 -0
  5. package/dist/PreviewFrame-erbgvzj8.stx +257 -0
  6. package/dist/SplitPane-7sqfdwqa.stx +159 -0
  7. package/dist/component-api/component-api.js +36 -0
  8. package/dist/context-menu/context-menu.js +575 -0
  9. package/dist/data-grid/data-grid.js +1244 -0
  10. package/dist/graph-view/graph-view.js +1408 -0
  11. package/dist/index.d.ts +8 -0
  12. package/dist/index.js +22 -20
  13. package/dist/json-tree/json-tree.js +1121 -0
  14. package/dist/preview-frame/preview-frame.js +356 -0
  15. package/dist/split-pane/split-pane.js +364 -0
  16. package/dist/ui/context-menu/ContextMenu.d.ts +14 -0
  17. package/dist/ui/context-menu/context-menu.d.ts +8 -0
  18. package/dist/ui/context-menu/core.d.ts +74 -0
  19. package/dist/ui/context-menu/index.d.ts +11 -0
  20. package/dist/ui/context-menu/view.d.ts +36 -0
  21. package/dist/ui/data-grid/DataGrid.d.ts +30 -0
  22. package/dist/ui/data-grid/core.d.ts +141 -0
  23. package/dist/ui/data-grid/data-grid.d.ts +9 -0
  24. package/dist/ui/data-grid/index.d.ts +20 -0
  25. package/dist/ui/data-grid/view.d.ts +56 -0
  26. package/dist/ui/graph-view/GraphView.d.ts +21 -0
  27. package/dist/ui/graph-view/core/edges.d.ts +34 -0
  28. package/dist/ui/graph-view/core/force.d.ts +10 -0
  29. package/dist/ui/graph-view/core/graph.d.ts +83 -0
  30. package/dist/ui/graph-view/core/index.d.ts +5 -0
  31. package/dist/ui/graph-view/core/layered.d.ts +24 -0
  32. package/dist/ui/graph-view/core/viewport.d.ts +34 -0
  33. package/dist/ui/graph-view/graph-view.d.ts +9 -0
  34. package/dist/ui/graph-view/index.d.ts +21 -0
  35. package/dist/ui/graph-view/view.d.ts +51 -0
  36. package/dist/ui/json-tree/JsonTree.d.ts +18 -0
  37. package/dist/ui/json-tree/core.d.ts +108 -0
  38. package/dist/ui/json-tree/index.d.ts +18 -0
  39. package/dist/ui/json-tree/json-tree.d.ts +10 -0
  40. package/dist/ui/json-tree/tinker.d.ts +84 -0
  41. package/dist/ui/json-tree/view.d.ts +59 -0
  42. package/dist/ui/preview-frame/PreviewFrame.d.ts +44 -0
  43. package/dist/ui/preview-frame/core.d.ts +81 -0
  44. package/dist/ui/preview-frame/index.d.ts +19 -0
  45. package/dist/ui/preview-frame/preview-frame.d.ts +8 -0
  46. package/dist/ui/preview-frame/view.d.ts +37 -0
  47. package/dist/ui/split-pane/SplitPane.d.ts +18 -0
  48. package/dist/ui/split-pane/core.d.ts +58 -0
  49. package/dist/ui/split-pane/index.d.ts +15 -0
  50. package/dist/ui/split-pane/split-pane.d.ts +8 -0
  51. package/dist/ui/split-pane/view.d.ts +27 -0
  52. package/dist/ui/virtual-table/index.d.ts +6 -0
  53. package/dist/utils/component-api.d.ts +4 -0
  54. package/package.json +38 -3
  55. package/src/index.ts +8 -0
  56. package/src/ui/code-editor/README.md +2 -1
  57. package/src/ui/context-menu/ContextMenu.stx +188 -0
  58. package/src/ui/context-menu/README.md +117 -0
  59. package/src/ui/context-menu/context-menu.ts +8 -0
  60. package/src/ui/context-menu/core.ts +250 -0
  61. package/src/ui/context-menu/index.ts +16 -0
  62. package/src/ui/context-menu/view.ts +540 -0
  63. package/src/ui/data-grid/DataGrid.stx +376 -0
  64. package/src/ui/data-grid/README.md +204 -0
  65. package/src/ui/data-grid/core.ts +813 -0
  66. package/src/ui/data-grid/data-grid.ts +9 -0
  67. package/src/ui/data-grid/index.ts +34 -0
  68. package/src/ui/data-grid/view.ts +806 -0
  69. package/src/ui/graph-view/GraphView.stx +320 -0
  70. package/src/ui/graph-view/README.md +210 -0
  71. package/src/ui/graph-view/core/edges.ts +180 -0
  72. package/src/ui/graph-view/core/force.ts +237 -0
  73. package/src/ui/graph-view/core/graph.ts +277 -0
  74. package/src/ui/graph-view/core/index.ts +5 -0
  75. package/src/ui/graph-view/core/layered.ts +256 -0
  76. package/src/ui/graph-view/core/viewport.ts +141 -0
  77. package/src/ui/graph-view/graph-view.ts +9 -0
  78. package/src/ui/graph-view/index.ts +35 -0
  79. package/src/ui/graph-view/view.ts +809 -0
  80. package/src/ui/json-tree/JsonTree.stx +317 -0
  81. package/src/ui/json-tree/README.md +193 -0
  82. package/src/ui/json-tree/core.ts +588 -0
  83. package/src/ui/json-tree/index.ts +28 -0
  84. package/src/ui/json-tree/json-tree.ts +10 -0
  85. package/src/ui/json-tree/tinker.ts +349 -0
  86. package/src/ui/json-tree/view.ts +665 -0
  87. package/src/ui/preview-frame/PreviewFrame.stx +257 -0
  88. package/src/ui/preview-frame/README.md +107 -0
  89. package/src/ui/preview-frame/core.ts +195 -0
  90. package/src/ui/preview-frame/index.ts +31 -0
  91. package/src/ui/preview-frame/preview-frame.ts +8 -0
  92. package/src/ui/preview-frame/view.ts +336 -0
  93. package/src/ui/split-pane/README.md +87 -0
  94. package/src/ui/split-pane/SplitPane.stx +159 -0
  95. package/src/ui/split-pane/core.ts +200 -0
  96. package/src/ui/split-pane/index.ts +24 -0
  97. package/src/ui/split-pane/split-pane.ts +8 -0
  98. package/src/ui/split-pane/view.ts +305 -0
  99. package/src/ui/virtual-table/index.ts +6 -0
  100. package/src/utils/component-api.ts +72 -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,14 @@
1
+ import type { DefineComponent } from '@stacksjs/stx';
2
+ declare const __dtsx_component__: __DtsxStxComponentType;
3
+ /*
4
+ * The items, when they arrive as a plain prop. A bound list (`:items="list()"`)
5
+ * or a function that builds one for the element clicked on (`:items="menuFor"`)
6
+ * is read live by the client script.
7
+ */
8
+ export declare const items: unknown;
9
+ export declare const label: unknown;
10
+ export declare const disabled: ReturnType<typeof $bool>;
11
+ export declare const className: unknown;
12
+ export declare const menuId: unknown;
13
+ declare type __DtsxStxComponentType = DefineComponent<{ items?: unknown, label?: string, disabled?: unknown, className?: string, id?: string }> & { readonly __stxEmits?: ["select", "open", "close"] }
14
+ export default __dtsx_component__;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * The context menu without its stx template.
3
+ *
4
+ * `@stacksjs/components/context-menu`. What a menu is and how it is moved
5
+ * through (`./core`, no DOM), and the view that draws one over any element.
6
+ */
7
+ export * from './core';
8
+ export * from './view';
@@ -0,0 +1,74 @@
1
+ /**
2
+ * Settle a list of items: every item gets an id, and separators that divide
3
+ * nothing are dropped (one at either end, or two in a row), so a host can
4
+ * build a list out of optional groups without tidying it.
5
+ */
6
+ export declare function resolveItems(items: readonly MenuItem[] | null | undefined, parent?: number[]): ResolvedItem[];
7
+ /** Whether the keyboard can land on an item. A disabled item can be read, so it can; a separator cannot. */
8
+ export declare function isFocusable(item: MenuItem | undefined): boolean;
9
+ /** Whether choosing the item does anything. */
10
+ export declare function isActionable(item: MenuItem | undefined): boolean;
11
+ export declare function hasSubmenu(item: MenuItem | undefined): boolean;
12
+ /**
13
+ * The item an arrow key moves to from `from`, wrapping at the ends.
14
+ * `from` of -1 is "nothing yet": down goes to the first item and up to the last.
15
+ */
16
+ export declare function stepIndex(items: readonly MenuItem[], from: number, direction: 1 | -1): number;
17
+ export declare function firstIndex(items: readonly MenuItem[]): number;
18
+ export declare function lastIndex(items: readonly MenuItem[]): number;
19
+ /**
20
+ * The item a typed string jumps to. A single repeated letter cycles through
21
+ * the items starting with it; anything longer is a prefix, searched from the
22
+ * current item so typing more keeps the match.
23
+ */
24
+ export declare function typeAheadIndex(items: readonly MenuItem[], from: number, typed: string): number;
25
+ /** Find an item anywhere in the tree by id. */
26
+ export declare function findItem(items: readonly ResolvedItem[], id: string): ResolvedItem | null;
27
+ /**
28
+ * Where a menu opened at a point goes.
29
+ *
30
+ * Down and to the right of the point, as a pointer expects. A menu that would
31
+ * leave the viewport on a side opens the other way from the point instead; one
32
+ * that fits neither way is pushed back inside, so its first items stay
33
+ * reachable.
34
+ */
35
+ export declare function placeAtPoint(point: MenuPoint, menu: MenuSize, viewport: MenuSize, margin?: number): MenuPoint;
36
+ /** Where a menu anchored to an element goes: under it, aligned to its left edge, or above when there is no room. */
37
+ export declare function placeAtBox(anchor: MenuBox, menu: MenuSize, viewport: MenuSize, margin?: number, gap?: number): MenuPoint;
38
+ /**
39
+ * Where a submenu goes: beside the item that opens it, level with it. To the
40
+ * right when it fits, otherwise to the left, and pushed up when it would run
41
+ * off the bottom. `overlap` tucks it slightly under its parent's edge.
42
+ */
43
+ export declare function placeSubmenu(item: MenuBox, menu: MenuSize, viewport: MenuSize, margin?: number, overlap?: number): MenuPoint & { side: 'right' | 'left' };
44
+ /** A shortcut as this platform writes it: `⇧⌘P` on a Mac, `Ctrl+Shift+P` elsewhere. */
45
+ export declare function formatShortcut(shortcut: string | undefined, apple: boolean): string;
46
+ /** The same shortcut for `aria-keyshortcuts`, which has its own spelling. */
47
+ export declare function ariaShortcut(shortcut: string | undefined, apple: boolean): string;
48
+ /**
49
+ * What a menu is and how one is moved through. No DOM.
50
+ *
51
+ * The items, which of them the arrow keys can land on, what a typed letter
52
+ * jumps to, where a menu goes so that it stays on screen, and how a shortcut
53
+ * is written on this platform.
54
+ */
55
+ export declare interface MenuItem {
56
+ id?: string
57
+ label?: string
58
+ shortcut?: string
59
+ disabled?: boolean
60
+ separator?: boolean
61
+ children?: MenuItem[]
62
+ checked?: boolean
63
+ danger?: boolean
64
+ value?: unknown
65
+ }
66
+ /** An item as the view draws it: with its id settled and its place in the tree. */
67
+ export declare interface ResolvedItem extends MenuItem {
68
+ id: string
69
+ path: number[]
70
+ children?: ResolvedItem[]
71
+ }
72
+ export declare interface MenuPoint { x: number, y: number }
73
+ export declare interface MenuSize { width: number, height: number }
74
+ export declare interface MenuBox { left: number, top: number, right: number, bottom: number }
@@ -0,0 +1,11 @@
1
+ import type { MenuItem } from './core';
2
+ export declare interface ContextMenuProps {
3
+ items?: MenuItem[] | ((target: Element | null) => MenuItem[] | null | undefined)
4
+ label?: string
5
+ disabled?: boolean
6
+ id?: string
7
+ className?: string
8
+ }
9
+ export { default as ContextMenu } from './ContextMenu';
10
+ export * from './core';
11
+ export * from './view';
@@ -0,0 +1,36 @@
1
+ import type { MenuItem, MenuPoint } from './core';
2
+ export declare interface ContextMenuOptions {
3
+ items?: MenuItemsSource | null
4
+ label?: string
5
+ disabled?: boolean
6
+ apple?: boolean
7
+ }
8
+ export declare interface MenuSelectDetail {
9
+ item: MenuItem
10
+ id: string
11
+ path: number[]
12
+ target: Element | null
13
+ }
14
+ export declare interface MenuOpenDetail {
15
+ x: number
16
+ y: number
17
+ target: Element | null
18
+ keyboard: boolean
19
+ }
20
+ export declare interface ContextMenuCallbacks {
21
+ onSelect?: (detail: MenuSelectDetail) => void
22
+ onOpen?: (detail: MenuOpenDetail) => void
23
+ onClose?: (detail: { reason: MenuCloseReason }) => void
24
+ }
25
+ export type MenuItemsSource = MenuItem[] | ((target: Element | null) => MenuItem[] | null | undefined);
26
+ export type MenuCloseReason = 'select' | 'escape' | 'outside' | 'blur' | 'tab' | 'api';
27
+ export declare class ContextMenuView {
28
+ constructor(root: HTMLElement, options?: ContextMenuOptions, callbacks?: ContextMenuCallbacks);
29
+ get isOpen(): boolean;
30
+ setItems(items: MenuItemsSource | null | undefined): void;
31
+ setDisabled(disabled: boolean): void;
32
+ setLabel(label: string): void;
33
+ open(at: MenuPoint | Element, items?: MenuItem[] | null, options?: { keyboard?: boolean, target?: Element | null }): boolean;
34
+ close(reason?: MenuCloseReason, restoreFocus?: boolean): void;
35
+ destroy(): void;
36
+ }
@@ -0,0 +1,30 @@
1
+ import type { DefineComponent } from '@stacksjs/stx';
2
+ declare const __dtsx_component__: __DtsxStxComponentType;
3
+ /*
4
+ * Rows written into the page as a plain prop. A bound one (`:rows="rows()"`)
5
+ * is read live by the client script; this is what it starts from.
6
+ */
7
+ export declare const rows: unknown;
8
+ export declare const columns: unknown;
9
+ export declare const rowHeight: unknown;
10
+ export declare const headerHeight: unknown;
11
+ /* A CSS length. `100%` fills a sized parent, which is what a pane wants. */
12
+ export declare const height: unknown;
13
+ export declare const filterable: unknown;
14
+ export declare const exportable: unknown;
15
+ export declare const selectable: unknown;
16
+ export declare const contextMenu: ReturnType<typeof $bool>;
17
+ export declare const filter: boolean;
18
+ export declare const label: unknown;
19
+ export declare const fileName: unknown;
20
+ export declare const className: unknown;
21
+ /*
22
+ * Ids unique to this instance: the grid, its filter and its status line all
23
+ * have to be findable when two grids share a page.
24
+ */
25
+ export declare const gridId: unknown;
26
+ export declare const filterId: string;
27
+ export declare const statusId: string;
28
+ export declare const hasToolbar: unknown;
29
+ declare type __DtsxStxComponentType = DefineComponent<{ rows?: unknown, columns?: unknown, rowHeight?: unknown, headerHeight?: unknown, height?: string, filterable?: unknown, exportable?: unknown, selectable?: unknown, contextMenu?: unknown, filter?: unknown, label?: string, fileName?: string, className?: string, id?: string }> & { readonly __stxEmits?: ["sort", "filter", "select", "cell", "activate", "copy", "export", "context"] }
30
+ export default __dtsx_component__;
@@ -0,0 +1,141 @@
1
+ /** The cell a column shows for a row. */
2
+ export declare function cellValue<Row>(row: Row, column: GridColumn<Row>): unknown;
3
+ /**
4
+ * What kind of column a list of values makes.
5
+ *
6
+ * Nulls say nothing and are skipped. A column is a number column only when
7
+ * every value is a number or reads as one: a single `n/a` among the figures
8
+ * makes it text, because sorting it as numbers would have to put that
9
+ * somewhere it does not belong.
10
+ */
11
+ export declare function inferType(values: readonly unknown[]): GridColumnType;
12
+ /**
13
+ * Columns for rows nobody described: every key of the first `sample` rows, in
14
+ * the order first seen. Rows that are arrays get a column per position.
15
+ */
16
+ export declare function inferColumns<Row>(rows: readonly Row[], sample?: number): GridColumn<Row>[];
17
+ /** Whether a cell is empty, and which kind of empty. */
18
+ export declare function cellKind(value: unknown): 'null' | 'undefined' | 'value';
19
+ /**
20
+ * The text of a cell.
21
+ *
22
+ * A number is shown as it is, digit for digit: a grid of results is for
23
+ * reading values, and grouping or rounding would show something other than
24
+ * what is there. Lining the digits up is the stylesheet's job.
25
+ */
26
+ export declare function formatCell(value: unknown, type?: GridColumnType): string;
27
+ /** A cell as JSON, the way it is copied. */
28
+ export declare function cellJson(value: unknown): string;
29
+ /** A row as an object of its columns. */
30
+ export declare function projectRow<Row>(row: Row, columns: readonly GridColumn<Row>[]): Record<string, unknown>;
31
+ /** A row as JSON, the way it is copied: its columns, indented. */
32
+ export declare function rowJson<Row>(row: Row, columns: readonly GridColumn<Row>[]): string;
33
+ /** Rows as a JSON array of objects, one property per column. */
34
+ export declare function toJson<Row>(rows: readonly Row[], columns: readonly GridColumn<Row>[]): string;
35
+ /** Rows as CSV: a header row, CRLF line ends, RFC 4180 quoting. */
36
+ export declare function toCsv<Row>(rows: readonly Row[], columns: readonly GridColumn<Row>[]): string;
37
+ /** The rows (or columns) that intersect a viewport, widened by `overscan`. */
38
+ export declare function rowRange(scroll: number, viewport: number, rowHeight: number, count: number, overscan?: number): GridRange;
39
+ /**
40
+ * Where a key takes the active cell.
41
+ *
42
+ * Row -1 is the header, so the header is part of the grid a keyboard can
43
+ * reach: up from the first row lands on it, and down leaves it.
44
+ */
45
+ export declare function moveCell(cell: GridCell, key: string, bounds: { rows: number, columns: number, page: number, mod?: boolean }): GridCell;
46
+ /** The next sort after a click on a column: ascending, descending, then none. */
47
+ export declare function cycleSort(sort: readonly GridSort[], key: string, additive?: boolean): GridSort[];
48
+ export declare const DEFAULT_MIN_WIDTH: 48;
49
+ export declare const DEFAULT_MAX_WIDTH: 2000;
50
+ /** A column fitted to its content stops here, however long a value is. */
51
+ export declare const FIT_MAX_WIDTH: 420;
52
+ /** JSON shown in a cell is cut here. The whole value is still what is copied. */
53
+ export declare const JSON_PREVIEW_LENGTH: 160;
54
+ export declare interface GridColumn<Row = any> {
55
+ key: string
56
+ label?: string
57
+ type?: GridColumnType
58
+ width?: number
59
+ minWidth?: number
60
+ maxWidth?: number
61
+ align?: GridAlign
62
+ sortable?: boolean
63
+ accessor?: (row: Row) => unknown
64
+ }
65
+ export declare interface ResolvedColumn<Row = any> extends GridColumn<Row> {
66
+ label: string
67
+ type: GridColumnType
68
+ width: number
69
+ minWidth: number
70
+ maxWidth: number
71
+ align: GridAlign
72
+ sortable: boolean
73
+ }
74
+ export declare interface GridSort {
75
+ key: string
76
+ direction: SortDirection
77
+ }
78
+ export declare interface GridCell {
79
+ row: number
80
+ column: number
81
+ }
82
+ export declare interface GridRange {
83
+ start: number
84
+ end: number
85
+ }
86
+ export declare interface GridModelOptions {
87
+ charWidth?: number
88
+ cellPadding?: number
89
+ }
90
+ /**
91
+ * The model of a data grid. No DOM.
92
+ *
93
+ * A grid is a list of rows somebody else owns, a list of columns, and a view:
94
+ * the source indices of the rows that pass the filter, in sorted order. The
95
+ * rows are never copied or reordered, so a hundred thousand of them cost one
96
+ * `Uint32Array` to show, and selection (kept as source indices) survives a
97
+ * sort or a filter.
98
+ *
99
+ * Everything that is slow to work out per row is worked out once and kept:
100
+ * the text a filter searches, and a number per cell to sort by. A second
101
+ * filter is then a plain `includes` over strings, and a second sort compares
102
+ * numbers whatever the column holds.
103
+ */
104
+ export type GridColumnType = 'string' | 'number' | 'date' | 'boolean' | 'json';
105
+ export type GridAlign = 'left' | 'right' | 'center';
106
+ export type SortDirection = 'asc' | 'desc';
107
+ export declare class GridModel<Row = any> {
108
+ rows: readonly Row[];
109
+ columns: ResolvedColumn<Row>[];
110
+ view: Uint32Array;
111
+ sort: GridSort[];
112
+ filter: string;
113
+ readonly selected: Set<number>;
114
+ readonly rows: Row[];
115
+ readonly columns: GridColumn<Row>[] | null;
116
+ constructor(rows?: readonly Row[], columns?: readonly GridColumn<Row>[] | null, options?: GridModelOptions);
117
+ get count(): number;
118
+ get totalWidth(): number;
119
+ setRows(rows: readonly Row[] | null | undefined): void;
120
+ setColumns(columns: readonly GridColumn<Row>[] | null | undefined): void;
121
+ setFilter(text: string | null | undefined): number;
122
+ setSort(sort: readonly GridSort[] | null | undefined): void;
123
+ toggleSort(key: string, additive?: boolean): GridSort[];
124
+ sortOf(key: string): { direction: SortDirection, priority: number } | null;
125
+ rowAt(viewIndex: number): Row | undefined;
126
+ valueAt(viewIndex: number, columnIndex: number): unknown;
127
+ viewRows(): Row[];
128
+ toCsv(): string;
129
+ toJson(): string;
130
+ select(viewIndex: number, mode?: 'replace' | 'toggle' | 'range'): void;
131
+ selectAll(): void;
132
+ clearSelection(): void;
133
+ isSelected(viewIndex: number): boolean;
134
+ selectedIndices(): number[];
135
+ selectedRows(): Row[];
136
+ offsetOf(columnIndex: number): number;
137
+ columnAt(x: number): number;
138
+ columnRange(scrollLeft: number, viewportWidth: number, overscan?: number): GridRange;
139
+ resizeColumn(columnIndex: number, width: number): number;
140
+ autoWidth(columnIndex: number, sample?: number): number;
141
+ }