@kahitsan/ksui 0.50.0 → 0.51.0-solid2.1
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 +10 -0
- package/package.json +8 -6
- package/src/components/base/AccountAvatar.tsx +1 -1
- package/src/components/base/ActionMenu.tsx +7 -5
- package/src/components/base/AddAttachmentTile.tsx +6 -6
- package/src/components/base/BadgeSelect.tsx +11 -9
- package/src/components/base/Button.test.tsx +23 -0
- package/src/components/base/Button.tsx +35 -41
- package/src/components/base/CameraCapture.tsx +5 -2
- package/src/components/base/CopyButton.tsx +2 -1
- package/src/components/base/DataTable.tsx +91 -112
- package/src/components/base/DatePicker.tsx +15 -17
- package/src/components/base/DateTile.tsx +14 -12
- package/src/components/base/Dropdown.tsx +6 -5
- package/src/components/base/ExistingAttachmentTile.test.tsx +3 -3
- package/src/components/base/ExistingAttachmentTile.tsx +6 -4
- package/src/components/base/EyebrowBadge.tsx +2 -1
- package/src/components/base/FormErrorBanner.tsx +2 -1
- package/src/components/base/FormField.tsx +1 -1
- package/src/components/base/ImageCropper.tsx +3 -3
- package/src/components/base/ImageViewer.test.tsx +2 -0
- package/src/components/base/ImageViewer.tsx +4 -3
- package/src/components/base/KpiCard.tsx +3 -2
- package/src/components/base/Modal.test.tsx +3 -2
- package/src/components/base/Modal.tsx +11 -12
- package/src/components/base/ModalHeader.tsx +2 -1
- package/src/components/base/MonthCalendar.tsx +2 -1
- package/src/components/base/MultiSelectGroup.tsx +7 -5
- package/src/components/base/ProgressBar.tsx +8 -17
- package/src/components/base/RadioCardGroup.tsx +14 -12
- package/src/components/base/SectionHeading.tsx +2 -1
- package/src/components/base/SegmentedFilter.tsx +10 -8
- package/src/components/base/SocialLinksBar.tsx +2 -1
- package/src/components/base/StatusIndicator.tsx +2 -1
- package/src/components/base/StatusPill.tsx +1 -1
- package/src/components/base/TagPill.tsx +1 -1
- package/src/components/base/ThemeToggle.tsx +5 -11
- package/src/components/base/Tooltip.tsx +2 -1
- package/src/components/composite/AccountRadioPicker.tsx +14 -11
- package/src/components/composite/ComboBox.tsx +18 -13
- package/src/components/composite/CustomRenderer.tsx +1 -1
- package/src/components/composite/FileField.tsx +6 -3
- package/src/components/composite/FlowGraph.tsx +15 -12
- package/src/components/composite/FlowRunner.test.tsx +2 -0
- package/src/components/composite/FlowRunner.tsx +2 -1
- package/src/components/composite/FormActions.tsx +1 -1
- package/src/components/composite/FormAdvancedSection.tsx +13 -13
- package/src/components/composite/LiveTimer.tsx +8 -14
- package/src/components/composite/MarkdownNotes.tsx +2 -1
- package/src/components/composite/MentionTextarea.tsx +31 -22
- package/src/components/composite/MultiPeriodPicker.tsx +11 -9
- package/src/components/composite/NotFound.tsx +4 -15
- package/src/components/composite/PaymentAccountPicker.tsx +19 -24
- package/src/components/composite/SalesBodyEditor.tsx +10 -7
- package/src/components/composite/SearchableSelect.tsx +14 -13
- package/src/components/composite/SecretReveal.tsx +2 -2
- package/src/components/composite/TransactionForm.tsx +52 -42
- package/src/components/composite/TransferAccountsPicker.tsx +11 -10
- package/src/components/composite/TransferFeeChip.tsx +7 -6
- package/src/components/composite/VoucherPicker.test.tsx +55 -48
- package/src/components/composite/VoucherPicker.tsx +36 -27
- package/src/components/composite/picker-engine.ts +20 -14
- package/src/components/composite/resource/ResourcePage.test.tsx +21 -1
- package/src/components/composite/resource/ResourcePage.tsx +23 -8
- package/src/components/composite/resource/cells.tsx +1 -1
- package/src/icons/README.md +1 -1
- package/src/icons/create-artwork-icon.test.tsx +4 -1
- package/src/icons/create-artwork-icon.tsx +10 -24
- package/src/utils/account-icons.ts +2 -1
- package/src/utils/accounts-index.tsx +8 -5
- package/src/utils/aria.ts +13 -0
- package/src/utils/confirm.tsx +1 -1
- package/src/utils/dom.ts +7 -6
- package/src/utils/fetch-resource.ts +59 -0
- package/src/utils/highlight.tsx +1 -1
- package/src/utils/modal-layer.ts +3 -3
- package/src/utils/object-url-resource.ts +11 -8
- package/src/utils/top-layer.ts +9 -8
|
@@ -8,8 +8,9 @@
|
|
|
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
|
|
12
|
-
import {
|
|
11
|
+
import { createSignal, For, Show, type Component } from "solid-js";
|
|
12
|
+
import type { JSX } from "@solidjs/web";
|
|
13
|
+
import { createStore } from "solid-js";
|
|
13
14
|
import Plus from "../../../icons/plus";
|
|
14
15
|
import X from "../../../icons/x";
|
|
15
16
|
import Archive from "../../../icons/archive";
|
|
@@ -132,14 +133,21 @@ export function ResourcePage<T extends ResourceRow>(
|
|
|
132
133
|
);
|
|
133
134
|
const [saving, setSaving] = createSignal(false);
|
|
134
135
|
const [error, setError] = createSignal("");
|
|
135
|
-
const setValue = (key: string, value: string) =>
|
|
136
|
+
const setValue = (key: string, value: string) =>
|
|
137
|
+
setForm((draft) => {
|
|
138
|
+
draft[key] = value;
|
|
139
|
+
});
|
|
136
140
|
|
|
137
141
|
function resetForm() {
|
|
138
|
-
setForm(
|
|
142
|
+
setForm((draft) => {
|
|
143
|
+
Object.assign(draft, emptyFormValues(spec));
|
|
144
|
+
});
|
|
139
145
|
setError("");
|
|
140
146
|
}
|
|
141
147
|
function populateForm(row: ResourceRow) {
|
|
142
|
-
setForm(
|
|
148
|
+
setForm((draft) => {
|
|
149
|
+
Object.assign(draft, rowToFormValues(spec, row));
|
|
150
|
+
});
|
|
143
151
|
setError("");
|
|
144
152
|
}
|
|
145
153
|
|
|
@@ -292,7 +300,8 @@ export function ResourcePage<T extends ResourceRow>(
|
|
|
292
300
|
}
|
|
293
301
|
>
|
|
294
302
|
<DataTable<ResourceRow>
|
|
295
|
-
|
|
303
|
+
// The table runs fetchFn untracked, so filter changes must be part of the key.
|
|
304
|
+
refetchKey={() => `${String(refetchKey?.())}|${JSON.stringify(filterState)}`}
|
|
296
305
|
fetchFn={async (
|
|
297
306
|
params: FetchParams
|
|
298
307
|
): Promise<FetchResult<ResourceRow>> => {
|
|
@@ -317,14 +326,20 @@ export function ResourcePage<T extends ResourceRow>(
|
|
|
317
326
|
<SegmentedFilter
|
|
318
327
|
options={[...f.options]}
|
|
319
328
|
value={filterState[f.param]}
|
|
320
|
-
onChange={(v: string) =>
|
|
329
|
+
onChange={(v: string) =>
|
|
330
|
+
setFilterState((draft) => {
|
|
331
|
+
draft[f.param] = v;
|
|
332
|
+
})
|
|
333
|
+
}
|
|
321
334
|
testIdPrefix={f.testIdPrefix}
|
|
322
335
|
/>
|
|
323
336
|
) : (
|
|
324
337
|
<select
|
|
325
338
|
value={filterState[f.param]}
|
|
326
339
|
onChange={(e) =>
|
|
327
|
-
setFilterState(
|
|
340
|
+
setFilterState((draft) => {
|
|
341
|
+
draft[f.param] = e.currentTarget.value;
|
|
342
|
+
})
|
|
328
343
|
}
|
|
329
344
|
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"
|
|
330
345
|
>
|
|
@@ -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 "@solidjs/web";
|
|
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` (string, array, or object form), 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
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { cleanup, render } from "@solidjs/testing-library";
|
|
2
|
-
import { createSignal } from "solid-js";
|
|
2
|
+
import { createSignal, flush } from "solid-js";
|
|
3
3
|
import { afterEach, describe, expect, it } from "vitest";
|
|
4
4
|
import { createArtworkIcon } from "./create-artwork-icon";
|
|
5
5
|
|
|
@@ -47,6 +47,7 @@ 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();
|
|
50
51
|
expect(view.container.querySelector("image")).toBeNull();
|
|
51
52
|
expect(view.container.querySelector("path")).not.toBeNull();
|
|
52
53
|
});
|
|
@@ -80,6 +81,7 @@ describe("original artwork icon contract", () => {
|
|
|
80
81
|
expect(svg.getAttribute("role")).toBe("img");
|
|
81
82
|
expect(svg.hasAttribute("aria-hidden")).toBe(false);
|
|
82
83
|
setSize(24);
|
|
84
|
+
flush();
|
|
83
85
|
expect(svg.getAttribute("width")).toBe("24");
|
|
84
86
|
expect(svg.getAttribute("class")).toContain("indicator");
|
|
85
87
|
});
|
|
@@ -109,6 +111,7 @@ describe("original artwork icon contract", () => {
|
|
|
109
111
|
const images = view.container.querySelectorAll("image");
|
|
110
112
|
expect(images[0].getAttribute("href")).toBe(regular);
|
|
111
113
|
setWeight(3);
|
|
114
|
+
flush();
|
|
112
115
|
expect(images[0].getAttribute("href")).toBe(bold);
|
|
113
116
|
expect(images[1].getAttribute("href")).toBe(filled);
|
|
114
117
|
expect(view.container.querySelector("svg")?.getAttribute("fill")).toBe(
|
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
/// <reference path="./asset-modules.d.ts" />
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
splitProps,
|
|
6
|
-
type Component,
|
|
7
|
-
type JSX,
|
|
8
|
-
} from "solid-js";
|
|
2
|
+
import { ariaBool } from "../utils/aria";
|
|
3
|
+
import { Show, createUniqueId, omit, type Component } from "solid-js";
|
|
4
|
+
import type { JSX } from "@solidjs/web";
|
|
9
5
|
|
|
10
6
|
export type IconProps = JSX.SvgSVGAttributes<SVGSVGElement> & {
|
|
11
7
|
size?: number | string;
|
|
@@ -74,7 +70,11 @@ function accessibility(props: IconProps, titleId: string) {
|
|
|
74
70
|
"aria-label": props["aria-label"],
|
|
75
71
|
"aria-labelledby":
|
|
76
72
|
props["aria-labelledby"] ?? (props.title ? titleId : undefined),
|
|
77
|
-
"aria-hidden":
|
|
73
|
+
"aria-hidden": ariaBool(
|
|
74
|
+
typeof props["aria-hidden"] === "string"
|
|
75
|
+
? props["aria-hidden"] === "true"
|
|
76
|
+
: (props["aria-hidden"] ?? (labelled ? undefined : true)),
|
|
77
|
+
),
|
|
78
78
|
} as const;
|
|
79
79
|
}
|
|
80
80
|
|
|
@@ -85,22 +85,8 @@ export function createArtworkIcon(
|
|
|
85
85
|
variants: ArtworkVariants = {}
|
|
86
86
|
): ArtworkIconComponent {
|
|
87
87
|
return function ArtworkIcon(props) {
|
|
88
|
-
const
|
|
89
|
-
|
|
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
|
-
]);
|
|
88
|
+
const local = props;
|
|
89
|
+
const rest = omit(props, "size", "width", "height", "title", "children", "fill", "role", "aria-hidden", "aria-label", "aria-labelledby", "strokeWidth", "stroke-width", "absoluteStrokeWidth", "weight");
|
|
104
90
|
const id = `artwork-${createUniqueId()}`;
|
|
105
91
|
const titleId = `${id}-title`;
|
|
106
92
|
const artwork = () => {
|
|
@@ -12,7 +12,8 @@ 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
|
|
15
|
+
import type { Component } from "solid-js";
|
|
16
|
+
import type { JSX } from "@solidjs/web";
|
|
16
17
|
|
|
17
18
|
export type IconComponent = Component<JSX.SvgSVGAttributes<SVGSVGElement> & { size?: number }>;
|
|
18
19
|
|
|
@@ -17,7 +17,8 @@
|
|
|
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 {
|
|
20
|
+
import { createRoot, runWithOwner } from "solid-js";
|
|
21
|
+
import { createFetchResource, type FetchResource } from "./fetch-resource";
|
|
21
22
|
import { getActiveWorkspaceId } from "./integration";
|
|
22
23
|
import type { AvatarAccount } from "../components/base/AccountAvatar";
|
|
23
24
|
|
|
@@ -71,12 +72,14 @@ async function fetchAccountsIndex(wsId: number | string | null): Promise<IndexSh
|
|
|
71
72
|
|
|
72
73
|
// Module-level singletons so a page with N rows fires one fetch per org, not
|
|
73
74
|
// 2*N. Created on first useAccountsIndex() call.
|
|
74
|
-
let sharedResource:
|
|
75
|
+
let sharedResource: FetchResource<IndexShape> | undefined;
|
|
75
76
|
|
|
76
|
-
export function useAccountsIndex():
|
|
77
|
+
export function useAccountsIndex(): FetchResource<IndexShape> {
|
|
77
78
|
if (!sharedResource) {
|
|
78
|
-
|
|
79
|
-
sharedResource =
|
|
79
|
+
// Detached: the shared index must outlive whichever component asked first.
|
|
80
|
+
sharedResource = runWithOwner(null, () =>
|
|
81
|
+
createRoot(() => createFetchResource(() => getActiveWorkspaceId(), fetchAccountsIndex)),
|
|
82
|
+
)!;
|
|
80
83
|
}
|
|
81
84
|
return sharedResource;
|
|
82
85
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
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
|
+
}
|
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 "@solidjs/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,15 +69,16 @@ 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
|
|
72
|
+
* Use this from a ref callback, keeping the teardown for an owner-level
|
|
73
|
+
* onCleanup (Solid 2 forbids onCleanup inside a ref callback):
|
|
73
74
|
*
|
|
74
|
-
*
|
|
75
|
+
* let release: (() => void) | undefined;
|
|
76
|
+
* onCleanup(() => release?.());
|
|
77
|
+
* <div ref={(el) => { release = useFocusTrap(el); }}>
|
|
75
78
|
*
|
|
76
|
-
* Or from an effect:
|
|
79
|
+
* Or from an effect, returning the teardown:
|
|
77
80
|
*
|
|
78
|
-
* createEffect(() =>
|
|
79
|
-
* if (containerRef) onCleanup(useFocusTrap(containerRef));
|
|
80
|
-
* });
|
|
81
|
+
* createEffect(() => containerRef, (el) => (el ? useFocusTrap(el) : undefined));
|
|
81
82
|
*
|
|
82
83
|
* The trap only intercepts Tab. Escape, click-outside, and submit handling
|
|
83
84
|
* remain the modal's responsibility, the trap is purely a focus-keeper.
|
|
@@ -0,0 +1,59 @@
|
|
|
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
|
+
}
|
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 {
|
|
11
|
+
import type { JSX } from "@solidjs/web";
|
|
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;
|
|
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 element accessor — not a reactive signal — is enough.
|
|
24
24
|
*/
|
|
25
|
-
export function usePopoverMount(): () =>
|
|
25
|
+
export function usePopoverMount(): () => HTMLElement {
|
|
26
26
|
const layer = useContext(ModalLayerContext);
|
|
27
27
|
return () => layer() ?? document.body;
|
|
28
28
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createEffect, onCleanup } from "solid-js";
|
|
2
|
+
import { createFetchResource, type FetchResource } from "./fetch-resource";
|
|
2
3
|
|
|
3
4
|
export interface ObjectUrlOptions {
|
|
4
5
|
/** Extra fetch init, merged after `credentials: "include"` (e.g. tenant headers). */
|
|
@@ -25,8 +26,8 @@ export interface ObjectUrlOptions {
|
|
|
25
26
|
export function createObjectUrlResource(
|
|
26
27
|
href: () => string | null | undefined,
|
|
27
28
|
options: ObjectUrlOptions = {},
|
|
28
|
-
):
|
|
29
|
-
const
|
|
29
|
+
): FetchResource<string | null> {
|
|
30
|
+
const url = createFetchResource(
|
|
30
31
|
() => href() || null,
|
|
31
32
|
async (src) => {
|
|
32
33
|
const res = await fetch(src, { credentials: "include", ...options.init });
|
|
@@ -40,11 +41,13 @@ export function createObjectUrlResource(
|
|
|
40
41
|
// final one on unmount. During a refetch the resource holds its prior value
|
|
41
42
|
// (cur === prev), so an in-flight reload doesn't revoke a URL still on screen.
|
|
42
43
|
let prev: string | null = null;
|
|
43
|
-
createEffect(
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
44
|
+
createEffect(
|
|
45
|
+
() => url() ?? null,
|
|
46
|
+
(cur) => {
|
|
47
|
+
if (prev && prev !== cur) URL.revokeObjectURL(prev);
|
|
48
|
+
prev = cur;
|
|
49
|
+
},
|
|
50
|
+
);
|
|
48
51
|
onCleanup(() => {
|
|
49
52
|
if (prev) URL.revokeObjectURL(prev);
|
|
50
53
|
});
|
package/src/utils/top-layer.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { onMount } from "solid-js";
|
|
2
1
|
import { injectCSS } from "./inject-css";
|
|
3
2
|
|
|
4
3
|
const STYLE_ID = "ksui-toplayer-style";
|
|
@@ -23,17 +22,16 @@ const STYLE_CSS = `
|
|
|
23
22
|
* ksui popup keeps its own mousedown/Escape listeners unchanged.
|
|
24
23
|
*
|
|
25
24
|
* Call from the portaled panel's ref, mirroring useFocusTrap's shape:
|
|
26
|
-
* ref={(el) => { popupRef = el;
|
|
25
|
+
* ref={(el) => { popupRef = el; useTopLayer(el); }}
|
|
27
26
|
*
|
|
28
|
-
* showPopover() is deferred to
|
|
27
|
+
* showPopover() is deferred to a microtask, not called inline here: this
|
|
29
28
|
* function runs synchronously inside <Portal>'s ref callback, which fires
|
|
30
29
|
* while the node is still detached (Portal appends its container to
|
|
31
30
|
* document.body *after* building the subtree) — el.isConnected is false
|
|
32
31
|
* and el.ownerDocument !== document at that point, so an inline call
|
|
33
|
-
* always throws InvalidStateError.
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
* the node is guaranteed connected. (Same fix shape as Modal's DialogModal,
|
|
32
|
+
* always throws InvalidStateError. A microtask runs only after the whole synchronous
|
|
33
|
+
* render pass — including Portal's appendChild — has finished, so by the
|
|
34
|
+
* time it runs the node is connected. (Same fix shape as Modal's DialogModal,
|
|
37
35
|
* which calls showModal() in onMount rather than in dialogEl's ref.)
|
|
38
36
|
*/
|
|
39
37
|
export function useTopLayer(el: HTMLElement | undefined): () => void {
|
|
@@ -41,7 +39,10 @@ export function useTopLayer(el: HTMLElement | undefined): () => void {
|
|
|
41
39
|
injectCSS(STYLE_ID, STYLE_CSS);
|
|
42
40
|
el.setAttribute("popover", "manual");
|
|
43
41
|
el.setAttribute("data-ksui-toplayer", "");
|
|
44
|
-
|
|
42
|
+
// Primitives are forbidden in a ref callback, so a microtask stands in for
|
|
43
|
+
// onSettled. The element leaves the top layer by itself when its portal is removed.
|
|
44
|
+
queueMicrotask(() => {
|
|
45
|
+
if (!el.isConnected) return;
|
|
45
46
|
// No Popover API (e.g. jsdom in unit tests) — nothing to promote, not an error.
|
|
46
47
|
if (typeof el.showPopover !== "function") return;
|
|
47
48
|
try {
|