@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
|
@@ -8,9 +8,8 @@
|
|
|
8
8
|
// layout, a permission check, per-request init (auth headers / credentials), a
|
|
9
9
|
// refetch trigger, and any extra header actions — so the component carries no
|
|
10
10
|
// app, transport, or auth assumptions of its own.
|
|
11
|
-
import { createSignal, For, Show, type Component } from "solid-js";
|
|
12
|
-
import
|
|
13
|
-
import { createStore } from "solid-js";
|
|
11
|
+
import { createSignal, For, Show, type Component, type JSX } from "solid-js";
|
|
12
|
+
import { createStore } from "solid-js/store";
|
|
14
13
|
import Plus from "../../../icons/plus";
|
|
15
14
|
import X from "../../../icons/x";
|
|
16
15
|
import Archive from "../../../icons/archive";
|
|
@@ -133,21 +132,14 @@ export function ResourcePage<T extends ResourceRow>(
|
|
|
133
132
|
);
|
|
134
133
|
const [saving, setSaving] = createSignal(false);
|
|
135
134
|
const [error, setError] = createSignal("");
|
|
136
|
-
const setValue = (key: string, value: string) =>
|
|
137
|
-
setForm((draft) => {
|
|
138
|
-
draft[key] = value;
|
|
139
|
-
});
|
|
135
|
+
const setValue = (key: string, value: string) => setForm(key, value);
|
|
140
136
|
|
|
141
137
|
function resetForm() {
|
|
142
|
-
setForm((
|
|
143
|
-
Object.assign(draft, emptyFormValues(spec));
|
|
144
|
-
});
|
|
138
|
+
setForm(emptyFormValues(spec));
|
|
145
139
|
setError("");
|
|
146
140
|
}
|
|
147
141
|
function populateForm(row: ResourceRow) {
|
|
148
|
-
setForm((
|
|
149
|
-
Object.assign(draft, rowToFormValues(spec, row));
|
|
150
|
-
});
|
|
142
|
+
setForm(rowToFormValues(spec, row));
|
|
151
143
|
setError("");
|
|
152
144
|
}
|
|
153
145
|
|
|
@@ -325,20 +317,14 @@ export function ResourcePage<T extends ResourceRow>(
|
|
|
325
317
|
<SegmentedFilter
|
|
326
318
|
options={[...f.options]}
|
|
327
319
|
value={filterState[f.param]}
|
|
328
|
-
onChange={(v: string) =>
|
|
329
|
-
setFilterState((draft) => {
|
|
330
|
-
draft[f.param] = v;
|
|
331
|
-
})
|
|
332
|
-
}
|
|
320
|
+
onChange={(v: string) => setFilterState(f.param, v)}
|
|
333
321
|
testIdPrefix={f.testIdPrefix}
|
|
334
322
|
/>
|
|
335
323
|
) : (
|
|
336
324
|
<select
|
|
337
325
|
value={filterState[f.param]}
|
|
338
326
|
onChange={(e) =>
|
|
339
|
-
setFilterState(
|
|
340
|
-
draft[f.param] = e.currentTarget.value;
|
|
341
|
-
})
|
|
327
|
+
setFilterState(f.param, e.currentTarget.value)
|
|
342
328
|
}
|
|
343
329
|
class="rounded-lg border border-[var(--ks-border,rgba(39,39,42,0.5))] bg-[var(--ks-input-bg,#18181b)] px-3 py-1.5 text-xs text-[var(--ks-fg-muted,#a1a1aa)] cursor-pointer"
|
|
344
330
|
>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Column-cell rendering for the datatable. One pure function maps a column's
|
|
2
2
|
// declared render hint (title / enum / status / text) to its cell markup.
|
|
3
|
-
import type { JSX } from "
|
|
3
|
+
import type { JSX } from "solid-js";
|
|
4
4
|
import StatusPill from "../../base/StatusPill";
|
|
5
5
|
import type { ResourceRow, ResourceUiSpec, UiColumn } from "./spec";
|
|
6
6
|
|
package/src/icons/README.md
CHANGED
|
@@ -12,7 +12,7 @@ import Search from "@kahitsan/ksui/icons/search";
|
|
|
12
12
|
|
|
13
13
|
Named imports are also available from `@kahitsan/ksui/icons`. A tree-shaking bundler can discard unused icon modules.
|
|
14
14
|
|
|
15
|
-
The components retain an SVG root. `size`, `width`, `height`, `class`
|
|
15
|
+
The components retain an SVG root. `size`, `width`, `height`, `class`, `classList`, SVG refs, style, events, and accessible attributes remain available. Artwork uses `currentColor`, so normal text and theme colors apply. Icons are decorative by default. Supply `title` or an accessible label when the image itself conveys information.
|
|
16
16
|
|
|
17
17
|
The Star includes a distinct filled rendition. Its fill inherits the SVG fill value, including CSS classes. Use `fill="currentColor"` to show the filled rendition.
|
|
18
18
|
|
|
@@ -27,3 +27,5 @@ Raster imports use Vite's `?url&no-inline` asset support. Vite 6 builds are veri
|
|
|
27
27
|
Directional components share an original source design with an intrinsic rotation. The public component name keeps its direction, and caller SVG transforms still apply. Existing public exports outside the refreshed set remain available. `Sales` provides a revenue meaning; `ShoppingBag` retains its existing public artwork.
|
|
28
28
|
|
|
29
29
|
BIR document identities are available as `BirForm2307`, `BirForm0619E`, and `BirForm1601Eq`, or their `bir-form-*` deep imports. Use a visible form label or accessible name with each document identity.
|
|
30
|
+
|
|
31
|
+
`BirCroc` (`bir-croc`) is the section identity for BIR forms: a crocodile head with an open mouth. It is not a document identity, so pair it with a visible section label.
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
// Generated by scripts/build-icon-assets.mjs.
|
|
2
|
+
export const artwork = "M50 33q-7 2-13 9l-8 8c-12 8-15 12-16 20q-2 7 4 7l6 1 9 8 11 9a186 186 0 0 0 61 15q8-3 4-7l-2-6q-1-5-2-5-1-4-6 3l-5 6-5-2q-4 0-6-8l-3-11q-2 0-5 6l-4 5-3-2c-4-2-18-15-20-18q-3-6 3-5l9-2c4-2 20-5 23-5l3 4 3 6 4-5c3-6 4-7 12-7q5-1 5 4l3 3q2 0 4-5c2-3 2-4 8-4q5-1 7-4t-3-10-14-4q-3 1-4 3-1 4-19 5c-14 1-16 0-22-6q-9-9-19-6m4 7-4 3q-2 5 2 9 4 5 10 0l2-2-2-1q-4 0-3-3 0-3 2-3 3 0 1-2a8 8 0 0 0-8-1m62 1q0 4 3 4 5 0 4-4z";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { cleanup, render } from "@solidjs/testing-library";
|
|
2
|
-
import { createSignal
|
|
2
|
+
import { createSignal } from "solid-js";
|
|
3
3
|
import { afterEach, describe, expect, it } from "vitest";
|
|
4
4
|
import { createArtworkIcon } from "./create-artwork-icon";
|
|
5
5
|
|
|
@@ -47,7 +47,6 @@ describe("original artwork icon contract", () => {
|
|
|
47
47
|
const view = render(() => <Mixed strokeWidth={weight()} />);
|
|
48
48
|
expect(view.container.querySelector("image")).not.toBeNull();
|
|
49
49
|
setWeight(3);
|
|
50
|
-
flush();
|
|
51
50
|
expect(view.container.querySelector("image")).toBeNull();
|
|
52
51
|
expect(view.container.querySelector("path")).not.toBeNull();
|
|
53
52
|
});
|
|
@@ -81,7 +80,6 @@ describe("original artwork icon contract", () => {
|
|
|
81
80
|
expect(svg.getAttribute("role")).toBe("img");
|
|
82
81
|
expect(svg.hasAttribute("aria-hidden")).toBe(false);
|
|
83
82
|
setSize(24);
|
|
84
|
-
flush();
|
|
85
83
|
expect(svg.getAttribute("width")).toBe("24");
|
|
86
84
|
expect(svg.getAttribute("class")).toContain("indicator");
|
|
87
85
|
});
|
|
@@ -111,7 +109,6 @@ describe("original artwork icon contract", () => {
|
|
|
111
109
|
const images = view.container.querySelectorAll("image");
|
|
112
110
|
expect(images[0].getAttribute("href")).toBe(regular);
|
|
113
111
|
setWeight(3);
|
|
114
|
-
flush();
|
|
115
112
|
expect(images[0].getAttribute("href")).toBe(bold);
|
|
116
113
|
expect(images[1].getAttribute("href")).toBe(filled);
|
|
117
114
|
expect(view.container.querySelector("svg")?.getAttribute("fill")).toBe(
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
/// <reference path="./asset-modules.d.ts" />
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
import {
|
|
3
|
+
Show,
|
|
4
|
+
createUniqueId,
|
|
5
|
+
splitProps,
|
|
6
|
+
type Component,
|
|
7
|
+
type JSX,
|
|
8
|
+
} from "solid-js";
|
|
5
9
|
|
|
6
10
|
export type IconProps = JSX.SvgSVGAttributes<SVGSVGElement> & {
|
|
7
11
|
size?: number | string;
|
|
@@ -70,11 +74,7 @@ function accessibility(props: IconProps, titleId: string) {
|
|
|
70
74
|
"aria-label": props["aria-label"],
|
|
71
75
|
"aria-labelledby":
|
|
72
76
|
props["aria-labelledby"] ?? (props.title ? titleId : undefined),
|
|
73
|
-
"aria-hidden":
|
|
74
|
-
typeof props["aria-hidden"] === "string"
|
|
75
|
-
? props["aria-hidden"] === "true"
|
|
76
|
-
: (props["aria-hidden"] ?? (labelled ? undefined : true)),
|
|
77
|
-
),
|
|
77
|
+
"aria-hidden": props["aria-hidden"] ?? (labelled ? undefined : true),
|
|
78
78
|
} as const;
|
|
79
79
|
}
|
|
80
80
|
|
|
@@ -85,8 +85,22 @@ export function createArtworkIcon(
|
|
|
85
85
|
variants: ArtworkVariants = {}
|
|
86
86
|
): ArtworkIconComponent {
|
|
87
87
|
return function ArtworkIcon(props) {
|
|
88
|
-
const local = props
|
|
89
|
-
|
|
88
|
+
const [local, rest] = splitProps(props, [
|
|
89
|
+
"size",
|
|
90
|
+
"width",
|
|
91
|
+
"height",
|
|
92
|
+
"title",
|
|
93
|
+
"children",
|
|
94
|
+
"fill",
|
|
95
|
+
"role",
|
|
96
|
+
"aria-hidden",
|
|
97
|
+
"aria-label",
|
|
98
|
+
"aria-labelledby",
|
|
99
|
+
"strokeWidth",
|
|
100
|
+
"stroke-width",
|
|
101
|
+
"absoluteStrokeWidth",
|
|
102
|
+
"weight",
|
|
103
|
+
]);
|
|
90
104
|
const id = `artwork-${createUniqueId()}`;
|
|
91
105
|
const titleId = `${id}-title`;
|
|
92
106
|
const artwork = () => {
|
package/src/icons/index.ts
CHANGED
|
@@ -169,6 +169,7 @@ export { default as Sales } from "./sales";
|
|
|
169
169
|
export { default as BirForm2307 } from "./bir-form-2307";
|
|
170
170
|
export { default as BirForm0619E } from "./bir-form-0619-e";
|
|
171
171
|
export { default as BirForm1601Eq } from "./bir-form-1601-eq";
|
|
172
|
+
export { default as BirCroc } from "./bir-croc";
|
|
172
173
|
export { default as AlertCircle } from "./circle-alert";
|
|
173
174
|
export { default as AlertTriangle } from "./triangle-alert";
|
|
174
175
|
export { default as BarChart3 } from "./chart-column";
|
package/src/icons/registry.ts
CHANGED
|
@@ -172,6 +172,7 @@ const loaders = {
|
|
|
172
172
|
"bir-form-2307": () => import("./bir-form-2307"),
|
|
173
173
|
"bir-form-0619-e": () => import("./bir-form-0619-e"),
|
|
174
174
|
"bir-form-1601-eq": () => import("./bir-form-1601-eq"),
|
|
175
|
+
"bir-croc": () => import("./bir-croc"),
|
|
175
176
|
"bar-chart-3": () => import("./chart-column"),
|
|
176
177
|
"loader-2": () => import("./loader-circle"),
|
|
177
178
|
"alert-triangle": () => import("./triangle-alert"),
|
|
@@ -12,8 +12,7 @@ import Coins from "../icons/coins";
|
|
|
12
12
|
import PiggyBank from "../icons/piggy-bank";
|
|
13
13
|
import DollarSign from "../icons/dollar-sign";
|
|
14
14
|
import Receipt from "../icons/receipt";
|
|
15
|
-
import type { Component } from "solid-js";
|
|
16
|
-
import type { JSX } from "@solidjs/web";
|
|
15
|
+
import type { Component, JSX } from "solid-js";
|
|
17
16
|
|
|
18
17
|
export type IconComponent = Component<JSX.SvgSVGAttributes<SVGSVGElement> & { size?: number }>;
|
|
19
18
|
|
|
@@ -17,8 +17,7 @@
|
|
|
17
17
|
// fetch 404s/fails and the index stays empty, so resolveAccount() then falls back
|
|
18
18
|
// to the type-default glyph.
|
|
19
19
|
|
|
20
|
-
import {
|
|
21
|
-
import { createFetchResource, type FetchResource } from "./fetch-resource";
|
|
20
|
+
import { createResource, type Resource } from "solid-js";
|
|
22
21
|
import { getActiveWorkspaceId } from "./integration";
|
|
23
22
|
import type { AvatarAccount } from "../components/base/AccountAvatar";
|
|
24
23
|
|
|
@@ -72,14 +71,12 @@ async function fetchAccountsIndex(wsId: number | string | null): Promise<IndexSh
|
|
|
72
71
|
|
|
73
72
|
// Module-level singletons so a page with N rows fires one fetch per org, not
|
|
74
73
|
// 2*N. Created on first useAccountsIndex() call.
|
|
75
|
-
let sharedResource:
|
|
74
|
+
let sharedResource: Resource<IndexShape> | undefined;
|
|
76
75
|
|
|
77
|
-
export function useAccountsIndex():
|
|
76
|
+
export function useAccountsIndex(): Resource<IndexShape> {
|
|
78
77
|
if (!sharedResource) {
|
|
79
|
-
|
|
80
|
-
sharedResource =
|
|
81
|
-
createRoot(() => createFetchResource(() => getActiveWorkspaceId(), fetchAccountsIndex)),
|
|
82
|
-
)!;
|
|
78
|
+
const [data] = createResource(() => getActiveWorkspaceId(), fetchAccountsIndex);
|
|
79
|
+
sharedResource = data;
|
|
83
80
|
}
|
|
84
81
|
return sharedResource;
|
|
85
82
|
}
|
package/src/utils/confirm.tsx
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
// kit, no Tailwind — Modal and Button inject their own styles.
|
|
9
9
|
|
|
10
10
|
import { createSignal, Show } from "solid-js";
|
|
11
|
-
import { render } from "
|
|
11
|
+
import { render } from "solid-js/web";
|
|
12
12
|
import Modal from "../components/base/Modal";
|
|
13
13
|
import Button from "../components/base/Button";
|
|
14
14
|
|
package/src/utils/dom.ts
CHANGED
|
@@ -69,16 +69,15 @@ export function unlockPullToRefresh() {
|
|
|
69
69
|
* a teardown function the caller can use to deactivate the trap explicitly
|
|
70
70
|
* (also runs automatically when called inside a Solid `onCleanup`).
|
|
71
71
|
*
|
|
72
|
-
* Use this from a ref callback
|
|
73
|
-
* onCleanup (Solid 2 forbids onCleanup inside a ref callback):
|
|
72
|
+
* Use this from a ref callback or Solid effect:
|
|
74
73
|
*
|
|
75
|
-
*
|
|
76
|
-
* onCleanup(() => release?.());
|
|
77
|
-
* <div ref={(el) => { release = useFocusTrap(el); }}>
|
|
74
|
+
* <div ref={(el) => { onCleanup(useFocusTrap(el)); }}>
|
|
78
75
|
*
|
|
79
|
-
* Or from an effect
|
|
76
|
+
* Or from an effect:
|
|
80
77
|
*
|
|
81
|
-
* createEffect(() =>
|
|
78
|
+
* createEffect(() => {
|
|
79
|
+
* if (containerRef) onCleanup(useFocusTrap(containerRef));
|
|
80
|
+
* });
|
|
82
81
|
*
|
|
83
82
|
* The trap only intercepts Tab. Escape, click-outside, and submit handling
|
|
84
83
|
* remain the modal's responsibility, the trap is purely a focus-keeper.
|
package/src/utils/highlight.tsx
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
// /helper class is added once per page via a runtime <style> tag. Callers can
|
|
9
9
|
// still pass their own `markClass` to override.
|
|
10
10
|
|
|
11
|
-
import type
|
|
11
|
+
import { type JSX } from "solid-js";
|
|
12
12
|
import { injectCSS } from "./inject-css";
|
|
13
13
|
|
|
14
14
|
const MARK_STYLE_ID = "ksui-mark-style";
|
package/src/utils/modal-layer.ts
CHANGED
|
@@ -14,15 +14,15 @@ import { createContext, useContext, type Accessor } from "solid-js";
|
|
|
14
14
|
// both mean "mount to document.body", today's behavior.
|
|
15
15
|
const ModalLayerContext = createContext<Accessor<HTMLElement | null>>(() => null);
|
|
16
16
|
|
|
17
|
-
export const ModalLayerProvider = ModalLayerContext;
|
|
17
|
+
export const ModalLayerProvider = ModalLayerContext.Provider;
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
20
|
* Mount target for a Portal-based popover: the nearest ancestor dialog's
|
|
21
21
|
* element when rendered inside a dialog-variant Modal, else document.body.
|
|
22
22
|
* Called once per popover-open (the Portal itself only reads `mount` at
|
|
23
|
-
* creation), so a plain
|
|
23
|
+
* creation), so a plain `Node` accessor — not a reactive signal — is enough.
|
|
24
24
|
*/
|
|
25
|
-
export function usePopoverMount(): () =>
|
|
25
|
+
export function usePopoverMount(): () => Node {
|
|
26
26
|
const layer = useContext(ModalLayerContext);
|
|
27
27
|
return () => layer() ?? document.body;
|
|
28
28
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { createEffect, onCleanup } from "solid-js";
|
|
2
|
-
import { createFetchResource, type FetchResource } from "./fetch-resource";
|
|
1
|
+
import { createResource, createEffect, onCleanup, type Resource } from "solid-js";
|
|
3
2
|
|
|
4
3
|
export interface ObjectUrlOptions {
|
|
5
4
|
/** Extra fetch init, merged after `credentials: "include"` (e.g. tenant headers). */
|
|
@@ -26,8 +25,8 @@ export interface ObjectUrlOptions {
|
|
|
26
25
|
export function createObjectUrlResource(
|
|
27
26
|
href: () => string | null | undefined,
|
|
28
27
|
options: ObjectUrlOptions = {},
|
|
29
|
-
):
|
|
30
|
-
const url =
|
|
28
|
+
): Resource<string | null> {
|
|
29
|
+
const [url] = createResource(
|
|
31
30
|
() => href() || null,
|
|
32
31
|
async (src) => {
|
|
33
32
|
const res = await fetch(src, { credentials: "include", ...options.init });
|
|
@@ -41,13 +40,11 @@ export function createObjectUrlResource(
|
|
|
41
40
|
// final one on unmount. During a refetch the resource holds its prior value
|
|
42
41
|
// (cur === prev), so an in-flight reload doesn't revoke a URL still on screen.
|
|
43
42
|
let prev: string | null = null;
|
|
44
|
-
createEffect(
|
|
45
|
-
|
|
46
|
-
(cur)
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
},
|
|
50
|
-
);
|
|
43
|
+
createEffect(() => {
|
|
44
|
+
const cur = url() ?? null;
|
|
45
|
+
if (prev && prev !== cur) URL.revokeObjectURL(prev);
|
|
46
|
+
prev = cur;
|
|
47
|
+
});
|
|
51
48
|
onCleanup(() => {
|
|
52
49
|
if (prev) URL.revokeObjectURL(prev);
|
|
53
50
|
});
|
package/src/utils/top-layer.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { onMount } from "solid-js";
|
|
1
2
|
import { injectCSS } from "./inject-css";
|
|
2
3
|
|
|
3
4
|
const STYLE_ID = "ksui-toplayer-style";
|
|
@@ -22,16 +23,17 @@ const STYLE_CSS = `
|
|
|
22
23
|
* ksui popup keeps its own mousedown/Escape listeners unchanged.
|
|
23
24
|
*
|
|
24
25
|
* Call from the portaled panel's ref, mirroring useFocusTrap's shape:
|
|
25
|
-
* ref={(el) => { popupRef = el; useTopLayer(el); }}
|
|
26
|
+
* ref={(el) => { popupRef = el; onCleanup(useTopLayer(el)); }}
|
|
26
27
|
*
|
|
27
|
-
* showPopover() is deferred to
|
|
28
|
+
* showPopover() is deferred to onMount, not called inline here: this
|
|
28
29
|
* function runs synchronously inside <Portal>'s ref callback, which fires
|
|
29
30
|
* while the node is still detached (Portal appends its container to
|
|
30
31
|
* document.body *after* building the subtree) — el.isConnected is false
|
|
31
32
|
* and el.ownerDocument !== document at that point, so an inline call
|
|
32
|
-
* always throws InvalidStateError.
|
|
33
|
-
*
|
|
34
|
-
*
|
|
33
|
+
* always throws InvalidStateError. onMount queues onto Solid's render-effect
|
|
34
|
+
* list, which only flushes once the whole synchronous render pass —
|
|
35
|
+
* including Portal's appendChild — has finished, so by the time it runs
|
|
36
|
+
* the node is guaranteed connected. (Same fix shape as Modal's DialogModal,
|
|
35
37
|
* which calls showModal() in onMount rather than in dialogEl's ref.)
|
|
36
38
|
*/
|
|
37
39
|
export function useTopLayer(el: HTMLElement | undefined): () => void {
|
|
@@ -39,10 +41,7 @@ export function useTopLayer(el: HTMLElement | undefined): () => void {
|
|
|
39
41
|
injectCSS(STYLE_ID, STYLE_CSS);
|
|
40
42
|
el.setAttribute("popover", "manual");
|
|
41
43
|
el.setAttribute("data-ksui-toplayer", "");
|
|
42
|
-
|
|
43
|
-
// onSettled. The element leaves the top layer by itself when its portal is removed.
|
|
44
|
-
queueMicrotask(() => {
|
|
45
|
-
if (!el.isConnected) return;
|
|
44
|
+
onMount(() => {
|
|
46
45
|
// No Popover API (e.g. jsdom in unit tests) — nothing to promote, not an error.
|
|
47
46
|
if (typeof el.showPopover !== "function") return;
|
|
48
47
|
try {
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
import { render } from "@solidjs/testing-library";
|
|
3
|
-
import Button from "./Button";
|
|
4
|
-
|
|
5
|
-
describe("Button defaults", () => {
|
|
6
|
-
// Wrappers forward optional props; an explicit undefined must keep the default.
|
|
7
|
-
it("keeps the default element when `as` is forwarded as undefined", () => {
|
|
8
|
-
const { container } = render(() => <Button as={undefined}>Go</Button>);
|
|
9
|
-
expect(container.querySelector("button")).not.toBeNull();
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
it("keeps the left icon position when forwarded as undefined", () => {
|
|
13
|
-
const Icon = () => <svg data-testid="icon" />;
|
|
14
|
-
const { container } = render(() => (
|
|
15
|
-
<Button icon={Icon} iconPosition={undefined}>
|
|
16
|
-
Go
|
|
17
|
-
</Button>
|
|
18
|
-
));
|
|
19
|
-
const html = container.querySelector("button")!.innerHTML;
|
|
20
|
-
expect(html.indexOf("<svg")).toBeGreaterThanOrEqual(0);
|
|
21
|
-
expect(html.indexOf("<svg")).toBeLessThan(html.indexOf("Go"));
|
|
22
|
-
});
|
|
23
|
-
});
|
package/src/utils/aria.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
// Solid 2 removes a boolean-false attribute, which would drop aria-expanded="false";
|
|
2
|
-
// ARIA state attributes must be serialized as strings.
|
|
3
|
-
export function ariaBool(value: boolean | undefined | null): "true" | "false" | undefined {
|
|
4
|
-
if (value === undefined || value === null) return undefined;
|
|
5
|
-
return value ? "true" : "false";
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
/** For aria-pressed / aria-checked, which also allow "mixed". */
|
|
9
|
-
export function ariaTri(
|
|
10
|
-
value: boolean | "mixed" | undefined | null,
|
|
11
|
-
): "true" | "false" | "mixed" | undefined {
|
|
12
|
-
return value === "mixed" ? "mixed" : ariaBool(value);
|
|
13
|
-
}
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { createEffect, createSignal, onCleanup, untrack, type Accessor } from "solid-js";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Value accessor with load state, the shape `createResource` gave callers.
|
|
5
|
-
* Solid 2 async memos throw to a <Loading> boundary instead; consumers of these
|
|
6
|
-
* hooks read `value()` unguarded, so loading stays a plain flag here.
|
|
7
|
-
*/
|
|
8
|
-
export interface FetchResource<T> extends Accessor<T | undefined> {
|
|
9
|
-
readonly loading: boolean;
|
|
10
|
-
readonly error: unknown;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Fetch `fetcher(source())` whenever `source` changes to a truthy value.
|
|
15
|
-
* A falsy source skips the fetch and keeps the last value; a refetch keeps the
|
|
16
|
-
* previous value until the new one lands; a superseded response is dropped.
|
|
17
|
-
*/
|
|
18
|
-
export function createFetchResource<S, T>(
|
|
19
|
-
source: () => S | false | null | undefined,
|
|
20
|
-
fetcher: (source: S) => Promise<T>,
|
|
21
|
-
): FetchResource<T> {
|
|
22
|
-
const [value, setValue] = createSignal<T | undefined>(undefined);
|
|
23
|
-
// Seeded from the source so an initial read matches createResource's loading=true.
|
|
24
|
-
const [loading, setLoading] = createSignal(!!untrack(source));
|
|
25
|
-
const [error, setError] = createSignal<unknown>(undefined);
|
|
26
|
-
let token = 0;
|
|
27
|
-
|
|
28
|
-
createEffect(source, (src) => {
|
|
29
|
-
const mine = ++token;
|
|
30
|
-
if (!src) {
|
|
31
|
-
setLoading(false);
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
setLoading(true);
|
|
35
|
-
setError(undefined);
|
|
36
|
-
fetcher(src).then(
|
|
37
|
-
(next) => {
|
|
38
|
-
if (mine !== token) return;
|
|
39
|
-
setValue(() => next);
|
|
40
|
-
setLoading(false);
|
|
41
|
-
},
|
|
42
|
-
(err: unknown) => {
|
|
43
|
-
if (mine !== token) return;
|
|
44
|
-
setError(err);
|
|
45
|
-
setLoading(false);
|
|
46
|
-
},
|
|
47
|
-
);
|
|
48
|
-
});
|
|
49
|
-
onCleanup(() => {
|
|
50
|
-
token++;
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
const read = (() => value()) as FetchResource<T>;
|
|
54
|
-
Object.defineProperties(read, {
|
|
55
|
-
loading: { get: loading },
|
|
56
|
-
error: { get: error },
|
|
57
|
-
});
|
|
58
|
-
return read;
|
|
59
|
-
}
|