@kahitsan/ksui 0.51.0-solid2.1 → 0.52.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -10
- package/package.json +6 -8
- package/src/components/base/AccountAvatar.tsx +1 -1
- package/src/components/base/ActionMenu.tsx +5 -7
- package/src/components/base/AddAttachmentTile.tsx +6 -6
- package/src/components/base/BadgeSelect.tsx +9 -11
- package/src/components/base/Button.tsx +41 -35
- package/src/components/base/CameraCapture.tsx +2 -5
- package/src/components/base/CopyButton.tsx +1 -2
- package/src/components/base/DataTable.tsx +112 -91
- package/src/components/base/DatePicker.tsx +17 -15
- package/src/components/base/DateTile.tsx +12 -14
- package/src/components/base/Dropdown.tsx +5 -6
- package/src/components/base/ExistingAttachmentTile.test.tsx +3 -3
- package/src/components/base/ExistingAttachmentTile.tsx +4 -6
- package/src/components/base/EyebrowBadge.tsx +1 -2
- package/src/components/base/FormErrorBanner.tsx +1 -2
- package/src/components/base/FormField.tsx +1 -1
- package/src/components/base/ImageCropper.tsx +3 -3
- package/src/components/base/ImageViewer.test.tsx +0 -2
- package/src/components/base/ImageViewer.tsx +3 -4
- package/src/components/base/KpiCard.tsx +2 -3
- package/src/components/base/Modal.test.tsx +2 -3
- package/src/components/base/Modal.tsx +12 -11
- package/src/components/base/ModalHeader.tsx +1 -2
- package/src/components/base/MonthCalendar.tsx +1 -2
- package/src/components/base/MultiSelectGroup.tsx +5 -7
- package/src/components/base/ProgressBar.tsx +17 -8
- package/src/components/base/RadioCardGroup.tsx +12 -14
- package/src/components/base/SectionHeading.tsx +1 -2
- package/src/components/base/SegmentedFilter.tsx +8 -10
- package/src/components/base/SocialLinksBar.tsx +1 -2
- package/src/components/base/StatusIndicator.tsx +1 -2
- package/src/components/base/StatusPill.tsx +1 -1
- package/src/components/base/TagPill.tsx +1 -1
- package/src/components/base/ThemeToggle.tsx +11 -5
- package/src/components/base/Tooltip.tsx +1 -2
- package/src/components/composite/AccountRadioPicker.tsx +11 -14
- package/src/components/composite/ComboBox.tsx +13 -18
- package/src/components/composite/CustomRenderer.tsx +1 -1
- package/src/components/composite/FileField.tsx +3 -6
- package/src/components/composite/FlowGraph.tsx +12 -15
- package/src/components/composite/FlowRunner.test.tsx +0 -2
- package/src/components/composite/FlowRunner.tsx +1 -2
- package/src/components/composite/FormActions.tsx +1 -1
- package/src/components/composite/FormAdvancedSection.tsx +13 -13
- package/src/components/composite/LiveTimer.tsx +14 -8
- package/src/components/composite/MarkdownNotes.tsx +1 -2
- package/src/components/composite/MentionTextarea.tsx +22 -31
- package/src/components/composite/MultiPeriodPicker.tsx +9 -11
- package/src/components/composite/NotFound.tsx +15 -4
- package/src/components/composite/PaymentAccountPicker.tsx +24 -19
- package/src/components/composite/SalesBodyEditor.tsx +7 -10
- package/src/components/composite/SearchableSelect.tsx +13 -14
- package/src/components/composite/SecretReveal.tsx +2 -2
- package/src/components/composite/TransactionForm.tsx +42 -52
- package/src/components/composite/TransferAccountsPicker.tsx +10 -11
- package/src/components/composite/TransferFeeChip.tsx +6 -7
- package/src/components/composite/VoucherPicker.test.tsx +48 -55
- package/src/components/composite/VoucherPicker.tsx +27 -36
- package/src/components/composite/picker-engine.ts +14 -20
- package/src/components/composite/resource/ResourcePage.test.tsx +1 -21
- package/src/components/composite/resource/ResourcePage.tsx +8 -23
- package/src/components/composite/resource/cells.tsx +1 -1
- package/src/icons/README.md +5 -1
- package/src/icons/artwork/bir-croc.ts +2 -0
- package/src/icons/artwork/overview.ts +2 -0
- package/src/icons/bir-croc.tsx +4 -0
- package/src/icons/create-artwork-icon.test.tsx +1 -4
- package/src/icons/create-artwork-icon.tsx +24 -10
- package/src/icons/index.ts +2 -0
- package/src/icons/overview.tsx +4 -0
- package/src/icons/registry.ts +2 -0
- package/src/utils/account-icons.ts +1 -2
- package/src/utils/accounts-index.tsx +5 -8
- package/src/utils/confirm.tsx +1 -1
- package/src/utils/dom.ts +6 -7
- package/src/utils/highlight.tsx +1 -1
- package/src/utils/modal-layer.ts +3 -3
- package/src/utils/object-url-resource.ts +8 -11
- package/src/utils/top-layer.ts +8 -9
- package/src/components/base/Button.test.tsx +0 -23
- package/src/utils/aria.ts +0 -13
- package/src/utils/fetch-resource.ts +0 -59
package/README.md
CHANGED
|
@@ -87,16 +87,6 @@ You also need a SolidJS app. If you are starting fresh, set one up with
|
|
|
87
87
|
[`vite-plugin-solid`](https://github.com/solidjs/vite-plugin-solid), which is the
|
|
88
88
|
tool that compiles Solid components.
|
|
89
89
|
|
|
90
|
-
### Solid 2 prerelease
|
|
91
|
-
|
|
92
|
-
The `solid2` dist-tag carries prereleases built for Solid 2 (`solid-js` and
|
|
93
|
-
`@solidjs/web` `^2.0.0`, `vite-plugin-solid` 3, Vite 8). Pin an exact version;
|
|
94
|
-
`latest` stays on Solid 1.
|
|
95
|
-
|
|
96
|
-
```
|
|
97
|
-
npm install @kahitsan/ksui@solid2
|
|
98
|
-
```
|
|
99
|
-
|
|
100
90
|
## A tiny usage example
|
|
101
91
|
|
|
102
92
|
```tsx
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kahitsan/ksui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.52.0",
|
|
4
4
|
"description": "Standalone SolidJS UI components with original owned icon artwork. Ships source for the consumer compiler and has no runtime dependency beyond solid-js.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.ts",
|
|
@@ -62,8 +62,7 @@
|
|
|
62
62
|
"test:icon-sources": "node --test scripts/icon-source-manifest.test.mjs scripts/write-icon-modules.test.mjs scripts/trace-icon-artwork.test.mjs"
|
|
63
63
|
},
|
|
64
64
|
"peerDependencies": {
|
|
65
|
-
"
|
|
66
|
-
"solid-js": "^2.0.0",
|
|
65
|
+
"solid-js": "^1.9.0",
|
|
67
66
|
"tailwindcss": ">=3.0.0"
|
|
68
67
|
},
|
|
69
68
|
"peerDependenciesMeta": {
|
|
@@ -74,16 +73,15 @@
|
|
|
74
73
|
"devDependencies": {
|
|
75
74
|
"@changesets/cli": "^2.31.0",
|
|
76
75
|
"@playwright/test": "^1.50.0",
|
|
77
|
-
"@solidjs/testing-library": "
|
|
78
|
-
"@solidjs/web": "2.0.4",
|
|
76
|
+
"@solidjs/testing-library": "^0.8.0",
|
|
79
77
|
"jsdom": "^26.0.0",
|
|
80
78
|
"potrace": "^2.1.8",
|
|
81
79
|
"sharp": "^0.35.5",
|
|
82
|
-
"solid-js": "
|
|
80
|
+
"solid-js": "^1.9.0",
|
|
83
81
|
"svgo": "^4.1.0",
|
|
84
82
|
"typescript": "^5.6.0",
|
|
85
|
-
"vite": "^
|
|
86
|
-
"vite-plugin-solid": "
|
|
83
|
+
"vite": "^6.0.0",
|
|
84
|
+
"vite-plugin-solid": "^2.11.0",
|
|
87
85
|
"vitest": "^4.0.0"
|
|
88
86
|
},
|
|
89
87
|
"publishConfig": {
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
// <img> so chip sizing is identical regardless of source.
|
|
21
21
|
|
|
22
22
|
import { Show } from "solid-js";
|
|
23
|
-
import { Dynamic } from "
|
|
23
|
+
import { Dynamic } from "solid-js/web";
|
|
24
24
|
import { getAccountIcon } from "../../utils/account-icons";
|
|
25
25
|
import { buildLogoSrc } from "../../utils/account-logo-url";
|
|
26
26
|
|
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import { For, Show, createSignal, createUniqueId, onCleanup,
|
|
2
|
-
import
|
|
3
|
-
import { Dynamic, Portal } from "@solidjs/web";
|
|
1
|
+
import { For, Show, createSignal, createUniqueId, onCleanup, onMount, type Component, type JSX } from "solid-js";
|
|
2
|
+
import { Dynamic, Portal } from "solid-js/web";
|
|
4
3
|
import MoreHorizontal from "../../icons/more-horizontal";
|
|
5
4
|
import { injectCSS } from "../../utils/inject-css";
|
|
6
5
|
import { usePopoverMount } from "../../utils/modal-layer";
|
|
7
6
|
import { useTopLayer } from "../../utils/top-layer";
|
|
8
|
-
import { ariaBool } from "../../utils/aria";
|
|
9
7
|
|
|
10
8
|
const STYLE_ID = "ksui-action-menu-style";
|
|
11
9
|
const STYLE_CSS = `
|
|
@@ -119,7 +117,7 @@ export default function ActionMenu(props: ActionMenuProps): JSX.Element {
|
|
|
119
117
|
event.preventDefault();
|
|
120
118
|
items[next]?.focus();
|
|
121
119
|
};
|
|
122
|
-
|
|
120
|
+
onMount(() => {
|
|
123
121
|
document.addEventListener("keydown", onDocumentKeyDown);
|
|
124
122
|
document.addEventListener("mousedown", onDocumentPointerDown);
|
|
125
123
|
window.addEventListener("resize", updatePosition);
|
|
@@ -138,7 +136,7 @@ export default function ActionMenu(props: ActionMenuProps): JSX.Element {
|
|
|
138
136
|
type="button"
|
|
139
137
|
aria-label={props.label}
|
|
140
138
|
aria-haspopup="menu"
|
|
141
|
-
aria-expanded={
|
|
139
|
+
aria-expanded={open()}
|
|
142
140
|
aria-controls={open() ? menuId : undefined}
|
|
143
141
|
data-testid={props.testId}
|
|
144
142
|
class={`ksui-action-menu__trigger ${props.triggerClass ?? ""}`}
|
|
@@ -157,7 +155,7 @@ export default function ActionMenu(props: ActionMenuProps): JSX.Element {
|
|
|
157
155
|
<div
|
|
158
156
|
ref={(element) => {
|
|
159
157
|
menu = element;
|
|
160
|
-
useTopLayer(element);
|
|
158
|
+
onCleanup(useTopLayer(element));
|
|
161
159
|
queueMicrotask(updatePosition);
|
|
162
160
|
}}
|
|
163
161
|
id={menuId}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// Vendored into plugin remotes.
|
|
2
2
|
// Dashed "Add" tile with a small Camera / Image-or-file popover menu.
|
|
3
3
|
|
|
4
|
-
import { createSignal, onCleanup,
|
|
5
|
-
import { Portal } from "
|
|
4
|
+
import { createSignal, onCleanup, onMount, Show } from "solid-js";
|
|
5
|
+
import { Portal } from "solid-js/web";
|
|
6
6
|
import { useTopLayer } from "../../utils/top-layer";
|
|
7
7
|
import { usePopoverMount } from "../../utils/modal-layer";
|
|
8
8
|
import Plus from "../../icons/plus";
|
|
@@ -28,7 +28,7 @@ export default function AddAttachmentTile(props: Props) {
|
|
|
28
28
|
setPos({ top: r.bottom + 8, left: r.left });
|
|
29
29
|
};
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
onMount(() => {
|
|
32
32
|
const handler = (e: MouseEvent) => {
|
|
33
33
|
if (btn && !btn.contains(e.target as Node) && menu && !menu.contains(e.target as Node)) {
|
|
34
34
|
setOpen(false);
|
|
@@ -37,11 +37,11 @@ export default function AddAttachmentTile(props: Props) {
|
|
|
37
37
|
document.addEventListener("click", handler);
|
|
38
38
|
window.addEventListener("scroll", place, true);
|
|
39
39
|
window.addEventListener("resize", place);
|
|
40
|
-
|
|
40
|
+
onCleanup(() => {
|
|
41
41
|
document.removeEventListener("click", handler);
|
|
42
42
|
window.removeEventListener("scroll", place, true);
|
|
43
43
|
window.removeEventListener("resize", place);
|
|
44
|
-
};
|
|
44
|
+
});
|
|
45
45
|
});
|
|
46
46
|
|
|
47
47
|
return (
|
|
@@ -67,7 +67,7 @@ export default function AddAttachmentTile(props: Props) {
|
|
|
67
67
|
<div
|
|
68
68
|
ref={(el) => {
|
|
69
69
|
menu = el;
|
|
70
|
-
useTopLayer(el);
|
|
70
|
+
onCleanup(useTopLayer(el));
|
|
71
71
|
}}
|
|
72
72
|
style={{ top: `${pos().top}px`, left: `${pos().left}px` }}
|
|
73
73
|
class="fixed z-[60] min-w-[160px] rounded-lg border border-[var(--ks-border-strong,#3f3f46)] bg-[var(--ks-surface-raised,#1a1a1a)] shadow-2xl p-1 ks-hud-clip-top-left-bottom-right"
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import { createEffect, createMemo, createSignal, For, onCleanup, Show } from "solid-js";
|
|
2
|
-
import
|
|
3
|
-
import { Portal } from "@solidjs/web";
|
|
1
|
+
import { createEffect, createMemo, createSignal, For, onCleanup, Show, type JSX } from "solid-js";
|
|
2
|
+
import { Portal } from "solid-js/web";
|
|
4
3
|
import { useTopLayer } from "../../utils/top-layer";
|
|
5
4
|
import { usePopoverMount } from "../../utils/modal-layer";
|
|
6
|
-
import { ariaBool } from "../../utils/aria";
|
|
7
5
|
|
|
8
6
|
export interface BadgeSelectOption {
|
|
9
7
|
/** Stable identity of the option (what `value` matches and `onChange` emits). */
|
|
@@ -113,8 +111,8 @@ export default function BadgeSelect(props: BadgeSelectProps): JSX.Element {
|
|
|
113
111
|
});
|
|
114
112
|
};
|
|
115
113
|
|
|
116
|
-
createEffect(
|
|
117
|
-
if (!
|
|
114
|
+
createEffect(() => {
|
|
115
|
+
if (!open()) return;
|
|
118
116
|
setQuery("");
|
|
119
117
|
updatePosition();
|
|
120
118
|
if (showSearch()) queueMicrotask(() => searchRef?.focus());
|
|
@@ -134,12 +132,12 @@ export default function BadgeSelect(props: BadgeSelectProps): JSX.Element {
|
|
|
134
132
|
document.addEventListener("keydown", onEsc);
|
|
135
133
|
window.addEventListener("resize", onReflow);
|
|
136
134
|
window.addEventListener("scroll", onReflow, true);
|
|
137
|
-
|
|
135
|
+
onCleanup(() => {
|
|
138
136
|
document.removeEventListener("mousedown", onDocClick);
|
|
139
137
|
document.removeEventListener("keydown", onEsc);
|
|
140
138
|
window.removeEventListener("resize", onReflow);
|
|
141
139
|
window.removeEventListener("scroll", onReflow, true);
|
|
142
|
-
};
|
|
140
|
+
});
|
|
143
141
|
});
|
|
144
142
|
|
|
145
143
|
const handleSelect = async (next: string) => {
|
|
@@ -166,7 +164,7 @@ export default function BadgeSelect(props: BadgeSelectProps): JSX.Element {
|
|
|
166
164
|
type="button"
|
|
167
165
|
data-testid={props.testId}
|
|
168
166
|
aria-haspopup="listbox"
|
|
169
|
-
aria-expanded={
|
|
167
|
+
aria-expanded={open()}
|
|
170
168
|
disabled={props.disabled || busy()}
|
|
171
169
|
onClick={() => !props.disabled && setOpen((o) => !o)}
|
|
172
170
|
class={`text-xs font-medium px-1.5 py-0.5 rounded cursor-pointer transition-colors hover:ring-1 hover:ring-[color-mix(in_srgb,var(--ks-accent,#fbbf24)_40%,transparent)] ${badgeClass()} ${
|
|
@@ -181,7 +179,7 @@ export default function BadgeSelect(props: BadgeSelectProps): JSX.Element {
|
|
|
181
179
|
<div
|
|
182
180
|
ref={(el) => {
|
|
183
181
|
popupRef = el;
|
|
184
|
-
useTopLayer(el);
|
|
182
|
+
onCleanup(useTopLayer(el));
|
|
185
183
|
}}
|
|
186
184
|
role="listbox"
|
|
187
185
|
class="z-[100] rounded-md border border-[var(--ks-border-strong,#3f3f46)] bg-[color-mix(in_srgb,var(--ks-surface-raised,#1a1a1a)_95%,transparent)] backdrop-blur shadow-xl overflow-hidden flex flex-col"
|
|
@@ -209,7 +207,7 @@ export default function BadgeSelect(props: BadgeSelectProps): JSX.Element {
|
|
|
209
207
|
<button
|
|
210
208
|
type="button"
|
|
211
209
|
role="option"
|
|
212
|
-
aria-selected={
|
|
210
|
+
aria-selected={opt.value === props.value}
|
|
213
211
|
onClick={() => handleSelect(opt.value)}
|
|
214
212
|
class={`w-full text-left px-3 py-2 text-xs hover:bg-[color-mix(in_srgb,var(--ks-accent,#fbbf24)_10%,transparent)] transition-colors flex items-center justify-between gap-2 ${
|
|
215
213
|
opt.value === props.value ? "text-[var(--ks-accent,#fbbf24)]" : "text-[var(--ks-fg,#ffffff)]"
|
|
@@ -11,9 +11,18 @@
|
|
|
11
11
|
// injected once per page via a runtime <style> tag and referenced with plain,
|
|
12
12
|
// unscoped class names so the bundle stays self-contained.
|
|
13
13
|
|
|
14
|
-
import {
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
import {
|
|
15
|
+
splitProps,
|
|
16
|
+
createSignal,
|
|
17
|
+
onCleanup,
|
|
18
|
+
createMemo,
|
|
19
|
+
mergeProps,
|
|
20
|
+
Show,
|
|
21
|
+
For,
|
|
22
|
+
type JSX,
|
|
23
|
+
type Component,
|
|
24
|
+
} from "solid-js";
|
|
25
|
+
import { Dynamic } from "solid-js/web";
|
|
17
26
|
import { injectCSS } from "../../utils/inject-css";
|
|
18
27
|
|
|
19
28
|
const BUTTON_STYLE_ID = "ks-button-inline-style";
|
|
@@ -233,40 +242,37 @@ interface Ripple {
|
|
|
233
242
|
const Button = (props: ButtonProps): JSX.Element => {
|
|
234
243
|
ensureButtonStyle();
|
|
235
244
|
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
245
|
+
const merged = mergeProps(
|
|
246
|
+
{
|
|
247
|
+
as: "button" as ButtonProps["as"],
|
|
248
|
+
intent: "primary" as ButtonIntent,
|
|
249
|
+
variant: "clip1" as ButtonVariant,
|
|
250
|
+
size: "md" as ButtonSize,
|
|
251
|
+
noRipple: false,
|
|
252
|
+
noScanline: false,
|
|
253
|
+
noGlow: false,
|
|
254
|
+
noPulse: false,
|
|
255
|
+
iconPosition: "left" as const,
|
|
241
256
|
},
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
},
|
|
245
|
-
get variant() {
|
|
246
|
-
return props.variant ?? ("clip1" as ButtonVariant);
|
|
247
|
-
},
|
|
248
|
-
get size() {
|
|
249
|
-
return props.size ?? ("md" as ButtonSize);
|
|
250
|
-
},
|
|
251
|
-
get noRipple() {
|
|
252
|
-
return props.noRipple ?? false;
|
|
253
|
-
},
|
|
254
|
-
get noScanline() {
|
|
255
|
-
return props.noScanline ?? false;
|
|
256
|
-
},
|
|
257
|
-
get noGlow() {
|
|
258
|
-
return props.noGlow ?? false;
|
|
259
|
-
},
|
|
260
|
-
get noPulse() {
|
|
261
|
-
return props.noPulse ?? false;
|
|
262
|
-
},
|
|
263
|
-
get iconPosition() {
|
|
264
|
-
return props.iconPosition ?? ("left" as const);
|
|
265
|
-
},
|
|
266
|
-
});
|
|
257
|
+
props,
|
|
258
|
+
);
|
|
267
259
|
|
|
268
|
-
const local = merged
|
|
269
|
-
|
|
260
|
+
const [local, others] = splitProps(merged, [
|
|
261
|
+
"as",
|
|
262
|
+
"intent",
|
|
263
|
+
"variant",
|
|
264
|
+
"size",
|
|
265
|
+
"noRipple",
|
|
266
|
+
"noScanline",
|
|
267
|
+
"noGlow",
|
|
268
|
+
"noPulse",
|
|
269
|
+
"icon",
|
|
270
|
+
"iconPosition",
|
|
271
|
+
"class",
|
|
272
|
+
"children",
|
|
273
|
+
"onClick",
|
|
274
|
+
"disabled",
|
|
275
|
+
]);
|
|
270
276
|
|
|
271
277
|
const [ripples, setRipples] = createSignal<Ripple[]>([]);
|
|
272
278
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Vendored into plugin remotes.
|
|
2
2
|
// getUserMedia camera capture modal. Button is ksui's own base primitive.
|
|
3
3
|
|
|
4
|
-
import { createSignal, onCleanup,
|
|
4
|
+
import { createSignal, onCleanup, onMount, Show } from "solid-js";
|
|
5
5
|
import Button from "./Button";
|
|
6
6
|
import Camera from "../../icons/camera";
|
|
7
7
|
import X from "../../icons/x";
|
|
@@ -18,8 +18,7 @@ export default function CameraCapture(props: Props) {
|
|
|
18
18
|
const [error, setError] = createSignal("");
|
|
19
19
|
const [captured, setCaptured] = createSignal<string | null>(null);
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
void (async () => {
|
|
21
|
+
onMount(async () => {
|
|
23
22
|
stream()
|
|
24
23
|
?.getTracks()
|
|
25
24
|
.forEach((t) => t.stop());
|
|
@@ -36,8 +35,6 @@ export default function CameraCapture(props: Props) {
|
|
|
36
35
|
} catch {
|
|
37
36
|
setError("Could not access camera. Check permissions or try the Browse button instead.");
|
|
38
37
|
}
|
|
39
|
-
|
|
40
|
-
})();
|
|
41
38
|
});
|
|
42
39
|
|
|
43
40
|
onCleanup(() => {
|
|
@@ -26,8 +26,18 @@
|
|
|
26
26
|
// `base/` (and is re-exported as base) to preserve its existing import path —
|
|
27
27
|
// the only ksui dependency is DatePicker, itself a self-contained primitive.
|
|
28
28
|
|
|
29
|
-
import {
|
|
30
|
-
|
|
29
|
+
import {
|
|
30
|
+
batch,
|
|
31
|
+
createSignal,
|
|
32
|
+
createMemo,
|
|
33
|
+
createEffect,
|
|
34
|
+
on,
|
|
35
|
+
untrack,
|
|
36
|
+
For,
|
|
37
|
+
Show,
|
|
38
|
+
type JSX,
|
|
39
|
+
type ParentComponent,
|
|
40
|
+
} from "solid-js";
|
|
31
41
|
import Search from "../../icons/search";
|
|
32
42
|
import Filter from "../../icons/filter";
|
|
33
43
|
import ChevronLeft from "../../icons/chevron-left";
|
|
@@ -213,8 +223,6 @@ export interface DataTableProps<T extends DataTableRow> {
|
|
|
213
223
|
/**
|
|
214
224
|
* Reactive key that triggers a refetch + page-1 reset when it changes.
|
|
215
225
|
* Typical usage: `refetchKey={() => activeWorkspace()?.ws_id}`.
|
|
216
|
-
* `fetchFn` runs untracked, so any signal it reads (an external filter, say)
|
|
217
|
-
* must also be read in this key, or changing it will not refetch.
|
|
218
226
|
*/
|
|
219
227
|
refetchKey?: () => unknown;
|
|
220
228
|
|
|
@@ -393,45 +401,48 @@ export function DataTable<T extends DataTableRow>(props: DataTableProps<T>): JSX
|
|
|
393
401
|
props.onRefetch?.({
|
|
394
402
|
refetch: () => triggerFetch(),
|
|
395
403
|
resetAndRefetch: () => {
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
404
|
+
batch(() => {
|
|
405
|
+
setCurrentPage(1);
|
|
406
|
+
resetLoadMore();
|
|
407
|
+
triggerFetch();
|
|
408
|
+
});
|
|
399
409
|
},
|
|
400
410
|
});
|
|
401
411
|
|
|
402
412
|
// Watch refetchKey — when it changes, reset to page 1 and refetch.
|
|
403
413
|
createEffect(
|
|
404
|
-
(
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
414
|
+
on(
|
|
415
|
+
() => props.refetchKey?.(),
|
|
416
|
+
() => {
|
|
417
|
+
batch(() => {
|
|
418
|
+
setCurrentPage(1);
|
|
419
|
+
resetLoadMore();
|
|
420
|
+
triggerFetch();
|
|
421
|
+
});
|
|
422
|
+
},
|
|
423
|
+
{ defer: true },
|
|
424
|
+
),
|
|
411
425
|
);
|
|
412
426
|
|
|
413
|
-
createEffect(
|
|
414
|
-
()
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
}
|
|
432
|
-
(request) => {
|
|
433
|
-
if (!request) return;
|
|
434
|
-
const { fn, params, page, limit, lm, epoch } = request;
|
|
427
|
+
createEffect(() => {
|
|
428
|
+
void fetchTrigger(); // track
|
|
429
|
+
if (!props.fetchFn) return;
|
|
430
|
+
|
|
431
|
+
const fn = props.fetchFn;
|
|
432
|
+
const limit = itemsPerPage();
|
|
433
|
+
const lm = loadMoreMode();
|
|
434
|
+
const page = currentPage();
|
|
435
|
+
const epoch = loadEpoch();
|
|
436
|
+
const params: FetchParams = {
|
|
437
|
+
page,
|
|
438
|
+
limit,
|
|
439
|
+
search: searchTerm(),
|
|
440
|
+
sortBy: sortBy(),
|
|
441
|
+
sortDir: sortDir(),
|
|
442
|
+
dateFilter: props.dateRangeMode ? null : dateFilter(),
|
|
443
|
+
dateFrom: props.dateRangeMode ? dateFrom() : null,
|
|
444
|
+
dateTo: props.dateRangeMode ? dateTo() : null,
|
|
445
|
+
};
|
|
435
446
|
|
|
436
447
|
if (lm) {
|
|
437
448
|
const key = `${page}:${epoch}`;
|
|
@@ -480,8 +491,7 @@ export function DataTable<T extends DataTableRow>(props: DataTableProps<T>): JSX
|
|
|
480
491
|
}
|
|
481
492
|
})
|
|
482
493
|
.finally(() => setLoading(false));
|
|
483
|
-
|
|
484
|
-
);
|
|
494
|
+
});
|
|
485
495
|
|
|
486
496
|
// ---- Auto-load (loadMore mode) ----
|
|
487
497
|
//
|
|
@@ -492,32 +502,31 @@ export function DataTable<T extends DataTableRow>(props: DataTableProps<T>): JSX
|
|
|
492
502
|
// network fetch. The autoLoadCount cap protects a degenerate grouping from
|
|
493
503
|
// chaining to the end of the dataset.
|
|
494
504
|
createEffect(
|
|
495
|
-
(
|
|
496
|
-
({ isLoading }) => {
|
|
505
|
+
on([apiConsumed, loading], ([, isLoading]) => {
|
|
497
506
|
if (!loadMoreMode()) return;
|
|
498
|
-
if (initialized
|
|
507
|
+
if (untrack(initialized) === false) return;
|
|
499
508
|
if (isLoading) return;
|
|
500
|
-
const visible = paginatedData().length;
|
|
501
|
-
if (visible >= loadTarget
|
|
502
|
-
if (apiConsumed
|
|
503
|
-
if (autoLoadCount
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
509
|
+
const visible = untrack(() => paginatedData().length);
|
|
510
|
+
if (visible >= untrack(loadTarget)) return;
|
|
511
|
+
if (untrack(apiConsumed) >= untrack(totalRecords)) return;
|
|
512
|
+
if (untrack(autoLoadCount) >= AUTO_LOAD_CAP) return;
|
|
513
|
+
batch(() => {
|
|
514
|
+
setAutoLoadCount((c) => c + 1);
|
|
515
|
+
setCurrentPage((p) => p + 1);
|
|
516
|
+
triggerFetch();
|
|
517
|
+
});
|
|
518
|
+
}),
|
|
508
519
|
);
|
|
509
520
|
|
|
510
521
|
// ---- Client-side data ----
|
|
511
522
|
|
|
512
|
-
createEffect(
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
},
|
|
520
|
-
);
|
|
523
|
+
createEffect(() => {
|
|
524
|
+
if (isServerSide()) return;
|
|
525
|
+
const d = props.data || [];
|
|
526
|
+
setTableData(d as T[]);
|
|
527
|
+
setTotalRecords(d.length);
|
|
528
|
+
setInitialized(true);
|
|
529
|
+
});
|
|
521
530
|
|
|
522
531
|
// Post-fetch row transform. No-op passthrough when no transform is supplied.
|
|
523
532
|
const transformedData = createMemo(() => {
|
|
@@ -596,24 +605,30 @@ export function DataTable<T extends DataTableRow>(props: DataTableProps<T>): JSX
|
|
|
596
605
|
// ---- Handlers ----
|
|
597
606
|
|
|
598
607
|
function handleDateFilter(date: string | null) {
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
608
|
+
batch(() => {
|
|
609
|
+
setDateFilter(date);
|
|
610
|
+
setCurrentPage(1);
|
|
611
|
+
resetLoadMore();
|
|
612
|
+
if (isServerSide()) triggerFetch();
|
|
613
|
+
});
|
|
603
614
|
}
|
|
604
615
|
|
|
605
616
|
function handleDateRangeFilter(range: { start: string | null; end: string | null }) {
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
617
|
+
batch(() => {
|
|
618
|
+
setDateFrom(range.start);
|
|
619
|
+
setDateTo(range.end);
|
|
620
|
+
setCurrentPage(1);
|
|
621
|
+
resetLoadMore();
|
|
622
|
+
if (isServerSide()) triggerFetch();
|
|
623
|
+
});
|
|
611
624
|
}
|
|
612
625
|
|
|
613
626
|
function handleSearch(value: string) {
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
627
|
+
batch(() => {
|
|
628
|
+
setSearchTerm(value);
|
|
629
|
+
setCurrentPage(1);
|
|
630
|
+
resetLoadMore();
|
|
631
|
+
});
|
|
617
632
|
if (isServerSide()) {
|
|
618
633
|
clearTimeout(debounceTimer);
|
|
619
634
|
debounceTimer = setTimeout(triggerFetch, debounceDelay());
|
|
@@ -622,15 +637,17 @@ export function DataTable<T extends DataTableRow>(props: DataTableProps<T>): JSX
|
|
|
622
637
|
|
|
623
638
|
function handleSort(key: string) {
|
|
624
639
|
if (!ordering()) return;
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
640
|
+
batch(() => {
|
|
641
|
+
if (sortBy() === key) {
|
|
642
|
+
setSortDir((d) => (d === "asc" ? "desc" : "asc"));
|
|
643
|
+
} else {
|
|
644
|
+
setSortBy(key);
|
|
645
|
+
setSortDir("desc");
|
|
646
|
+
}
|
|
647
|
+
setCurrentPage(1);
|
|
648
|
+
resetLoadMore();
|
|
649
|
+
if (isServerSide()) triggerFetch();
|
|
650
|
+
});
|
|
634
651
|
}
|
|
635
652
|
|
|
636
653
|
function handlePageChange(page: number) {
|
|
@@ -639,19 +656,23 @@ export function DataTable<T extends DataTableRow>(props: DataTableProps<T>): JSX
|
|
|
639
656
|
}
|
|
640
657
|
|
|
641
658
|
function handlePageSize(size: number) {
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
659
|
+
batch(() => {
|
|
660
|
+
setItemsPerPage(size);
|
|
661
|
+
setCurrentPage(1);
|
|
662
|
+
resetLoadMore();
|
|
663
|
+
if (isServerSide()) triggerFetch();
|
|
664
|
+
});
|
|
646
665
|
}
|
|
647
666
|
|
|
648
667
|
function handleShowMore() {
|
|
649
668
|
if (!loadMoreMode() || loading()) return;
|
|
650
669
|
if (apiConsumed() >= totalRecords()) return;
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
670
|
+
batch(() => {
|
|
671
|
+
setCurrentPage((p) => p + 1);
|
|
672
|
+
setAutoLoadCount(0);
|
|
673
|
+
setPendingLoadTargetBump(true);
|
|
674
|
+
triggerFetch();
|
|
675
|
+
});
|
|
655
676
|
}
|
|
656
677
|
|
|
657
678
|
// ---- Render helpers ----
|
|
@@ -802,7 +823,7 @@ export function DataTable<T extends DataTableRow>(props: DataTableProps<T>): JSX
|
|
|
802
823
|
{/* Empty state */}
|
|
803
824
|
<Show when={initialized() && !loading() && paginatedData().length === 0}>
|
|
804
825
|
<tr>
|
|
805
|
-
<td
|
|
826
|
+
<td colSpan={columns().length} class="ksui-datatable-empty">
|
|
806
827
|
{searchTerm()
|
|
807
828
|
? props.noResultsMessage || "No results found."
|
|
808
829
|
: props.emptyMessage || "No data available."}
|
|
@@ -818,8 +839,8 @@ export function DataTable<T extends DataTableRow>(props: DataTableProps<T>): JSX
|
|
|
818
839
|
return (
|
|
819
840
|
<>
|
|
820
841
|
<tr
|
|
821
|
-
class=
|
|
822
|
-
|
|
842
|
+
class="ksui-datatable-row"
|
|
843
|
+
classList={{ "ksui-datatable-row-clickable": !!props.onRowClick }}
|
|
823
844
|
onClick={() => props.onRowClick?.(row)}
|
|
824
845
|
>
|
|
825
846
|
<For each={columns()}>
|
|
@@ -839,7 +860,7 @@ export function DataTable<T extends DataTableRow>(props: DataTableProps<T>): JSX
|
|
|
839
860
|
class="ksui-datatable-expansion-row"
|
|
840
861
|
data-testid="datatable-expansion-row"
|
|
841
862
|
>
|
|
842
|
-
<td class="ksui-datatable-expansion-td"
|
|
863
|
+
<td class="ksui-datatable-expansion-td" colSpan={columns().length}>
|
|
843
864
|
{expansion()}
|
|
844
865
|
</td>
|
|
845
866
|
</tr>
|