@kahitsan/ksui 0.51.0-solid2.0 → 0.51.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 -89
- 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 -1
- package/src/components/composite/resource/ResourcePage.tsx +7 -21
- package/src/components/composite/resource/cells.tsx +1 -1
- package/src/icons/README.md +3 -1
- package/src/icons/artwork/bir-croc.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 +1 -0
- package/src/icons/registry.ts +1 -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.51.0
|
|
3
|
+
"version": "0.51.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";
|
|
@@ -391,45 +401,48 @@ export function DataTable<T extends DataTableRow>(props: DataTableProps<T>): JSX
|
|
|
391
401
|
props.onRefetch?.({
|
|
392
402
|
refetch: () => triggerFetch(),
|
|
393
403
|
resetAndRefetch: () => {
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
404
|
+
batch(() => {
|
|
405
|
+
setCurrentPage(1);
|
|
406
|
+
resetLoadMore();
|
|
407
|
+
triggerFetch();
|
|
408
|
+
});
|
|
397
409
|
},
|
|
398
410
|
});
|
|
399
411
|
|
|
400
412
|
// Watch refetchKey — when it changes, reset to page 1 and refetch.
|
|
401
413
|
createEffect(
|
|
402
|
-
(
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
414
|
+
on(
|
|
415
|
+
() => props.refetchKey?.(),
|
|
416
|
+
() => {
|
|
417
|
+
batch(() => {
|
|
418
|
+
setCurrentPage(1);
|
|
419
|
+
resetLoadMore();
|
|
420
|
+
triggerFetch();
|
|
421
|
+
});
|
|
422
|
+
},
|
|
423
|
+
{ defer: true },
|
|
424
|
+
),
|
|
409
425
|
);
|
|
410
426
|
|
|
411
|
-
createEffect(
|
|
412
|
-
()
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
}
|
|
430
|
-
(request) => {
|
|
431
|
-
if (!request) return;
|
|
432
|
-
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
|
+
};
|
|
433
446
|
|
|
434
447
|
if (lm) {
|
|
435
448
|
const key = `${page}:${epoch}`;
|
|
@@ -478,8 +491,7 @@ export function DataTable<T extends DataTableRow>(props: DataTableProps<T>): JSX
|
|
|
478
491
|
}
|
|
479
492
|
})
|
|
480
493
|
.finally(() => setLoading(false));
|
|
481
|
-
|
|
482
|
-
);
|
|
494
|
+
});
|
|
483
495
|
|
|
484
496
|
// ---- Auto-load (loadMore mode) ----
|
|
485
497
|
//
|
|
@@ -490,32 +502,31 @@ export function DataTable<T extends DataTableRow>(props: DataTableProps<T>): JSX
|
|
|
490
502
|
// network fetch. The autoLoadCount cap protects a degenerate grouping from
|
|
491
503
|
// chaining to the end of the dataset.
|
|
492
504
|
createEffect(
|
|
493
|
-
(
|
|
494
|
-
({ isLoading }) => {
|
|
505
|
+
on([apiConsumed, loading], ([, isLoading]) => {
|
|
495
506
|
if (!loadMoreMode()) return;
|
|
496
|
-
if (initialized
|
|
507
|
+
if (untrack(initialized) === false) return;
|
|
497
508
|
if (isLoading) return;
|
|
498
|
-
const visible = paginatedData().length;
|
|
499
|
-
if (visible >= loadTarget
|
|
500
|
-
if (apiConsumed
|
|
501
|
-
if (autoLoadCount
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
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
|
+
}),
|
|
506
519
|
);
|
|
507
520
|
|
|
508
521
|
// ---- Client-side data ----
|
|
509
522
|
|
|
510
|
-
createEffect(
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
},
|
|
518
|
-
);
|
|
523
|
+
createEffect(() => {
|
|
524
|
+
if (isServerSide()) return;
|
|
525
|
+
const d = props.data || [];
|
|
526
|
+
setTableData(d as T[]);
|
|
527
|
+
setTotalRecords(d.length);
|
|
528
|
+
setInitialized(true);
|
|
529
|
+
});
|
|
519
530
|
|
|
520
531
|
// Post-fetch row transform. No-op passthrough when no transform is supplied.
|
|
521
532
|
const transformedData = createMemo(() => {
|
|
@@ -594,24 +605,30 @@ export function DataTable<T extends DataTableRow>(props: DataTableProps<T>): JSX
|
|
|
594
605
|
// ---- Handlers ----
|
|
595
606
|
|
|
596
607
|
function handleDateFilter(date: string | null) {
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
608
|
+
batch(() => {
|
|
609
|
+
setDateFilter(date);
|
|
610
|
+
setCurrentPage(1);
|
|
611
|
+
resetLoadMore();
|
|
612
|
+
if (isServerSide()) triggerFetch();
|
|
613
|
+
});
|
|
601
614
|
}
|
|
602
615
|
|
|
603
616
|
function handleDateRangeFilter(range: { start: string | null; end: string | null }) {
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
617
|
+
batch(() => {
|
|
618
|
+
setDateFrom(range.start);
|
|
619
|
+
setDateTo(range.end);
|
|
620
|
+
setCurrentPage(1);
|
|
621
|
+
resetLoadMore();
|
|
622
|
+
if (isServerSide()) triggerFetch();
|
|
623
|
+
});
|
|
609
624
|
}
|
|
610
625
|
|
|
611
626
|
function handleSearch(value: string) {
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
627
|
+
batch(() => {
|
|
628
|
+
setSearchTerm(value);
|
|
629
|
+
setCurrentPage(1);
|
|
630
|
+
resetLoadMore();
|
|
631
|
+
});
|
|
615
632
|
if (isServerSide()) {
|
|
616
633
|
clearTimeout(debounceTimer);
|
|
617
634
|
debounceTimer = setTimeout(triggerFetch, debounceDelay());
|
|
@@ -620,15 +637,17 @@ export function DataTable<T extends DataTableRow>(props: DataTableProps<T>): JSX
|
|
|
620
637
|
|
|
621
638
|
function handleSort(key: string) {
|
|
622
639
|
if (!ordering()) return;
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
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
|
+
});
|
|
632
651
|
}
|
|
633
652
|
|
|
634
653
|
function handlePageChange(page: number) {
|
|
@@ -637,19 +656,23 @@ export function DataTable<T extends DataTableRow>(props: DataTableProps<T>): JSX
|
|
|
637
656
|
}
|
|
638
657
|
|
|
639
658
|
function handlePageSize(size: number) {
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
659
|
+
batch(() => {
|
|
660
|
+
setItemsPerPage(size);
|
|
661
|
+
setCurrentPage(1);
|
|
662
|
+
resetLoadMore();
|
|
663
|
+
if (isServerSide()) triggerFetch();
|
|
664
|
+
});
|
|
644
665
|
}
|
|
645
666
|
|
|
646
667
|
function handleShowMore() {
|
|
647
668
|
if (!loadMoreMode() || loading()) return;
|
|
648
669
|
if (apiConsumed() >= totalRecords()) return;
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
670
|
+
batch(() => {
|
|
671
|
+
setCurrentPage((p) => p + 1);
|
|
672
|
+
setAutoLoadCount(0);
|
|
673
|
+
setPendingLoadTargetBump(true);
|
|
674
|
+
triggerFetch();
|
|
675
|
+
});
|
|
653
676
|
}
|
|
654
677
|
|
|
655
678
|
// ---- Render helpers ----
|
|
@@ -800,7 +823,7 @@ export function DataTable<T extends DataTableRow>(props: DataTableProps<T>): JSX
|
|
|
800
823
|
{/* Empty state */}
|
|
801
824
|
<Show when={initialized() && !loading() && paginatedData().length === 0}>
|
|
802
825
|
<tr>
|
|
803
|
-
<td
|
|
826
|
+
<td colSpan={columns().length} class="ksui-datatable-empty">
|
|
804
827
|
{searchTerm()
|
|
805
828
|
? props.noResultsMessage || "No results found."
|
|
806
829
|
: props.emptyMessage || "No data available."}
|
|
@@ -816,8 +839,8 @@ export function DataTable<T extends DataTableRow>(props: DataTableProps<T>): JSX
|
|
|
816
839
|
return (
|
|
817
840
|
<>
|
|
818
841
|
<tr
|
|
819
|
-
class=
|
|
820
|
-
|
|
842
|
+
class="ksui-datatable-row"
|
|
843
|
+
classList={{ "ksui-datatable-row-clickable": !!props.onRowClick }}
|
|
821
844
|
onClick={() => props.onRowClick?.(row)}
|
|
822
845
|
>
|
|
823
846
|
<For each={columns()}>
|
|
@@ -837,7 +860,7 @@ export function DataTable<T extends DataTableRow>(props: DataTableProps<T>): JSX
|
|
|
837
860
|
class="ksui-datatable-expansion-row"
|
|
838
861
|
data-testid="datatable-expansion-row"
|
|
839
862
|
>
|
|
840
|
-
<td class="ksui-datatable-expansion-td"
|
|
863
|
+
<td class="ksui-datatable-expansion-td" colSpan={columns().length}>
|
|
841
864
|
{expansion()}
|
|
842
865
|
</td>
|
|
843
866
|
</tr>
|