@cosmicdrift/kumiko-renderer-web 0.200.1 → 0.201.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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cosmicdrift/kumiko-renderer-web",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.201.0",
|
|
4
4
|
"description": "Web-platform bindings for @cosmicdrift/kumiko-renderer. HTML default-primitives, browser history-based navigation, EventSource-backed live events, and a one-call createKumikoApp that mounts the whole stack via react-dom.",
|
|
5
5
|
"license": "BUSL-1.1",
|
|
6
6
|
"author": "Marc Frost <marc@cosmicdriftgamestudio.com>",
|
|
@@ -16,9 +16,9 @@
|
|
|
16
16
|
"./styles.css": "./src/styles.css"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@cosmicdrift/kumiko-dispatcher-live": "0.
|
|
20
|
-
"@cosmicdrift/kumiko-headless": "0.
|
|
21
|
-
"@cosmicdrift/kumiko-renderer": "0.
|
|
19
|
+
"@cosmicdrift/kumiko-dispatcher-live": "0.201.0",
|
|
20
|
+
"@cosmicdrift/kumiko-headless": "0.201.0",
|
|
21
|
+
"@cosmicdrift/kumiko-renderer": "0.201.0",
|
|
22
22
|
"@radix-ui/react-dialog": "^1.1.15",
|
|
23
23
|
"@radix-ui/react-dropdown-menu": "^2.1.16",
|
|
24
24
|
"@radix-ui/react-label": "^2.1.8",
|
|
@@ -3076,6 +3076,68 @@ describe("RenderEdit hideActions (host-driven action bar)", () => {
|
|
|
3076
3076
|
data: { id: "42" },
|
|
3077
3077
|
});
|
|
3078
3078
|
});
|
|
3079
|
+
|
|
3080
|
+
test("onChange's submitting is false on mount", () => {
|
|
3081
|
+
const seen: RenderEditChangeState<TestValues>[] = [];
|
|
3082
|
+
render(
|
|
3083
|
+
<DispatcherProvider dispatcher={makeDispatcher()}>
|
|
3084
|
+
<RenderEdit<TestValues>
|
|
3085
|
+
screen={makeScreen()}
|
|
3086
|
+
entity={orderEntity}
|
|
3087
|
+
featureName="orders"
|
|
3088
|
+
initial={{ title: "Acme", count: 1, isUrgent: false }}
|
|
3089
|
+
writeCommand="order:create"
|
|
3090
|
+
onChange={(state) => seen.push(state)}
|
|
3091
|
+
/>
|
|
3092
|
+
</DispatcherProvider>,
|
|
3093
|
+
);
|
|
3094
|
+
|
|
3095
|
+
expect(seen.at(-1)?.submitting).toBe(false);
|
|
3096
|
+
});
|
|
3097
|
+
|
|
3098
|
+
test("onChange's submitting is true while a customSubmit is in flight and false again after", async () => {
|
|
3099
|
+
let resolveSubmit: (() => void) | undefined;
|
|
3100
|
+
const customSubmit = mock(
|
|
3101
|
+
(_snapshot: FormSnapshot<TestValues>): Promise<SubmitResult<unknown>> =>
|
|
3102
|
+
new Promise((resolve) => {
|
|
3103
|
+
resolveSubmit = () =>
|
|
3104
|
+
resolve({ validationBlocked: false, isSuccess: true, data: { id: "42" } });
|
|
3105
|
+
}),
|
|
3106
|
+
);
|
|
3107
|
+
const seen: RenderEditChangeState<TestValues>[] = [];
|
|
3108
|
+
let controls: RenderEditControls<TestValues> | undefined;
|
|
3109
|
+
render(
|
|
3110
|
+
<DispatcherProvider dispatcher={makeDispatcher()}>
|
|
3111
|
+
<RenderEdit<TestValues>
|
|
3112
|
+
screen={makeScreen()}
|
|
3113
|
+
entity={orderEntity}
|
|
3114
|
+
featureName="orders"
|
|
3115
|
+
initial={{ title: "Acme", count: 1, isUrgent: false }}
|
|
3116
|
+
customSubmit={customSubmit}
|
|
3117
|
+
onChange={(state) => seen.push(state)}
|
|
3118
|
+
onControlsReady={(c) => {
|
|
3119
|
+
controls = c;
|
|
3120
|
+
}}
|
|
3121
|
+
/>
|
|
3122
|
+
</DispatcherProvider>,
|
|
3123
|
+
);
|
|
3124
|
+
|
|
3125
|
+
expect(seen.at(-1)?.submitting).toBe(false);
|
|
3126
|
+
|
|
3127
|
+
let submitPromise: Promise<void> | undefined;
|
|
3128
|
+
act(() => {
|
|
3129
|
+
submitPromise = controls?.submit();
|
|
3130
|
+
});
|
|
3131
|
+
|
|
3132
|
+
expect(seen.at(-1)?.submitting).toBe(true);
|
|
3133
|
+
|
|
3134
|
+
await act(async () => {
|
|
3135
|
+
resolveSubmit?.();
|
|
3136
|
+
await submitPromise;
|
|
3137
|
+
});
|
|
3138
|
+
|
|
3139
|
+
expect(seen.at(-1)?.submitting).toBe(false);
|
|
3140
|
+
});
|
|
3079
3141
|
});
|
|
3080
3142
|
|
|
3081
3143
|
describe("RenderEdit fields filter", () => {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { describe, expect, mock, test } from "bun:test";
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, mock, test } from "bun:test";
|
|
2
2
|
import { fireEvent, render, screen } from "../../__tests__/test-utils";
|
|
3
3
|
import { Drawer } from "../drawer";
|
|
4
4
|
|
|
@@ -376,4 +376,99 @@ describe("Drawer", () => {
|
|
|
376
376
|
expect(screen.queryByRole("button", { name: /maximize drawer width/i })).toBeNull();
|
|
377
377
|
});
|
|
378
378
|
});
|
|
379
|
+
|
|
380
|
+
describe("narrow viewport", () => {
|
|
381
|
+
// matchMedia is set via Object.defineProperty on window, same leak trap
|
|
382
|
+
// as innerWidth above (resize describe): without restoring the original
|
|
383
|
+
// descriptor in afterEach, the mock survives into the next test file's
|
|
384
|
+
// happy-dom instance and corrupts unrelated tests there.
|
|
385
|
+
let originalDescriptor: PropertyDescriptor | undefined;
|
|
386
|
+
|
|
387
|
+
function mockMatchMedia(matches: boolean): void {
|
|
388
|
+
Object.defineProperty(window, "matchMedia", {
|
|
389
|
+
configurable: true,
|
|
390
|
+
writable: true,
|
|
391
|
+
value: (query: string) => ({
|
|
392
|
+
matches,
|
|
393
|
+
media: query,
|
|
394
|
+
addEventListener: () => {},
|
|
395
|
+
removeEventListener: () => {},
|
|
396
|
+
}),
|
|
397
|
+
});
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
beforeEach(() => {
|
|
401
|
+
originalDescriptor = Object.getOwnPropertyDescriptor(window, "matchMedia");
|
|
402
|
+
});
|
|
403
|
+
|
|
404
|
+
afterEach(() => {
|
|
405
|
+
if (originalDescriptor) {
|
|
406
|
+
Object.defineProperty(window, "matchMedia", originalDescriptor);
|
|
407
|
+
} else {
|
|
408
|
+
delete (window as unknown as { matchMedia?: unknown }).matchMedia;
|
|
409
|
+
}
|
|
410
|
+
});
|
|
411
|
+
|
|
412
|
+
test("narrow: full-screen classes replace the floating panel treatment", () => {
|
|
413
|
+
mockMatchMedia(true);
|
|
414
|
+
render(
|
|
415
|
+
<Drawer open={true} onOpenChange={() => {}} side="right" testId="drawer">
|
|
416
|
+
<div>Body</div>
|
|
417
|
+
</Drawer>,
|
|
418
|
+
);
|
|
419
|
+
const content = screen.getByTestId("drawer");
|
|
420
|
+
expect(content.className).toContain("inset-0");
|
|
421
|
+
expect(content.className).toContain("w-full");
|
|
422
|
+
expect(content.className).not.toContain("rounded-[2rem]");
|
|
423
|
+
expect(content.className).not.toContain("inset-y-8");
|
|
424
|
+
});
|
|
425
|
+
|
|
426
|
+
test("narrow with resize set: no inline width style", () => {
|
|
427
|
+
mockMatchMedia(true);
|
|
428
|
+
render(
|
|
429
|
+
<Drawer open={true} onOpenChange={() => {}} side="right" testId="drawer" resize={{}}>
|
|
430
|
+
<div>Body</div>
|
|
431
|
+
</Drawer>,
|
|
432
|
+
);
|
|
433
|
+
expect(screen.getByTestId("drawer").style.width).toBe("");
|
|
434
|
+
});
|
|
435
|
+
|
|
436
|
+
test("narrow: resize handle is not rendered", () => {
|
|
437
|
+
mockMatchMedia(true);
|
|
438
|
+
render(
|
|
439
|
+
<Drawer open={true} onOpenChange={() => {}} side="right" testId="drawer" resize={{}}>
|
|
440
|
+
<div>Body</div>
|
|
441
|
+
</Drawer>,
|
|
442
|
+
);
|
|
443
|
+
expect(screen.queryByRole("separator")).toBeNull();
|
|
444
|
+
});
|
|
445
|
+
|
|
446
|
+
test("narrow: maximize button is not rendered", () => {
|
|
447
|
+
mockMatchMedia(true);
|
|
448
|
+
render(
|
|
449
|
+
<Drawer open={true} onOpenChange={() => {}} side="right" testId="drawer" resize={{}}>
|
|
450
|
+
<div>Body</div>
|
|
451
|
+
</Drawer>,
|
|
452
|
+
);
|
|
453
|
+
expect(screen.queryByRole("button", { name: /maximize drawer width/i })).toBeNull();
|
|
454
|
+
});
|
|
455
|
+
|
|
456
|
+
test("wide (regression clamp): inline width and handle still present with resize set", () => {
|
|
457
|
+
mockMatchMedia(false);
|
|
458
|
+
render(
|
|
459
|
+
<Drawer
|
|
460
|
+
open={true}
|
|
461
|
+
onOpenChange={() => {}}
|
|
462
|
+
side="right"
|
|
463
|
+
testId="drawer"
|
|
464
|
+
resize={{ defaultWidthPx: 400, minWidthPx: 300, maxWidthPx: 500 }}
|
|
465
|
+
>
|
|
466
|
+
<div>Body</div>
|
|
467
|
+
</Drawer>,
|
|
468
|
+
);
|
|
469
|
+
const content = screen.getByTestId("drawer");
|
|
470
|
+
expect(content.style.width).toBe("400px");
|
|
471
|
+
expect(screen.getByRole("separator")).toBeTruthy();
|
|
472
|
+
});
|
|
473
|
+
});
|
|
379
474
|
});
|
package/src/widgets/drawer.tsx
CHANGED
|
@@ -3,6 +3,7 @@ import { Maximize2Icon, Minimize2Icon } from "lucide-react";
|
|
|
3
3
|
import { type ReactNode, useRef, useState } from "react";
|
|
4
4
|
import { clamp } from "../lib/clamp";
|
|
5
5
|
import { cn } from "../lib/cn";
|
|
6
|
+
import { useIsNarrowViewport } from "../primitives/use-narrow-viewport";
|
|
6
7
|
import {
|
|
7
8
|
Sheet,
|
|
8
9
|
SheetContent,
|
|
@@ -63,8 +64,12 @@ function defaultWidthFromViewport(): number {
|
|
|
63
64
|
}
|
|
64
65
|
|
|
65
66
|
// 32px margin + 32px radius so the panel reads as detached from the
|
|
66
|
-
// viewport edge, unlike the sheet primitive's flush-edge default.
|
|
67
|
-
|
|
67
|
+
// viewport edge, unlike the sheet primitive's flush-edge default. Below the
|
|
68
|
+
// narrow-viewport breakpoint the floating treatment doesn't fit — the JS
|
|
69
|
+
// hook decides, not a `sm:` Tailwind prefix, since the resize width below
|
|
70
|
+
// already comes from JS and two decision sources is the bug this avoids.
|
|
71
|
+
function floatingSideClass(side: "left" | "right" | "top" | "bottom", narrow: boolean): string {
|
|
72
|
+
if (narrow) return "inset-0 h-full w-full max-w-none rounded-none border-0 overflow-hidden";
|
|
68
73
|
switch (side) {
|
|
69
74
|
case "left":
|
|
70
75
|
return "inset-y-8 left-8 h-auto w-[max(600px,37.5vw)] max-w-[85vw] sm:max-w-[max(600px,37.5vw)] rounded-[2rem] border shadow-2xl overflow-hidden";
|
|
@@ -94,6 +99,7 @@ export function Drawer({
|
|
|
94
99
|
backdrop,
|
|
95
100
|
}: DrawerProps): ReactNode {
|
|
96
101
|
const t = useTranslation();
|
|
102
|
+
const narrow = useIsNarrowViewport();
|
|
97
103
|
const canResize = resize !== undefined && (side === "left" || side === "right");
|
|
98
104
|
const minWidthPx = resize?.minWidthPx ?? MIN_WIDTH_PX;
|
|
99
105
|
const maxWidthPx = resize?.maxWidthPx ?? MAX_WIDTH_PX;
|
|
@@ -160,10 +166,10 @@ export function Drawer({
|
|
|
160
166
|
data-testid={testId}
|
|
161
167
|
overlayStyle={overlayStyle}
|
|
162
168
|
showCloseButton={showCloseButton}
|
|
163
|
-
className={floatingSideClass(side)}
|
|
164
|
-
style={canResize ? { width: effectiveWidthPx, maxWidth: "none" } : undefined}
|
|
169
|
+
className={floatingSideClass(side, narrow)}
|
|
170
|
+
style={canResize && !narrow ? { width: effectiveWidthPx, maxWidth: "none" } : undefined}
|
|
165
171
|
>
|
|
166
|
-
{canResize && (
|
|
172
|
+
{canResize && !narrow && (
|
|
167
173
|
<button
|
|
168
174
|
type="button"
|
|
169
175
|
onClick={() => setMaximized((m) => !m)}
|
|
@@ -188,7 +194,7 @@ export function Drawer({
|
|
|
188
194
|
)}
|
|
189
195
|
<div className="flex-1 overflow-y-auto px-4">{children}</div>
|
|
190
196
|
{footer !== undefined && <SheetFooter>{footer}</SheetFooter>}
|
|
191
|
-
{canResize && (
|
|
197
|
+
{canResize && !narrow && (
|
|
192
198
|
// biome-ignore lint/a11y/useSemanticElements: <hr> can't carry pointer/keyboard drag interaction or a live width value — a draggable separator needs a div with the ARIA role.
|
|
193
199
|
<div
|
|
194
200
|
role="separator"
|