@weasel-js/labkit 1.6.1 → 1.7.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/dist/_dts/{CanvasStackContext-Wo6OwIVM.d.ts → CanvasStackContext-D2jnIwfk.d.ts} +1 -1
- package/dist/_dts/{LayerList.d-BoELAMsM.d.ts → LayerList.d-DiuEArKq.d.ts} +2 -2
- package/dist/_dts/PrefsRow.d-TOZ7BgD9.d.ts +79 -0
- package/dist/_dts/PropertyPanel.d-D-1paCbE.d.ts +141 -0
- package/dist/_dts/{Select.d-Cr8-zoup.d.ts → Select.d-Bensr_MT.d.ts} +11 -1
- package/dist/_dts/{Stage-DWBBi8IU.d.ts → Stage-CCWfQQWM.d.ts} +58 -18
- package/dist/_dts/index-B2Yj5aA0.d.ts +274 -0
- package/dist/_dts/{index-CKyX0ME_.d.ts → index-CsYqUHD3.d.ts} +2 -2
- package/dist/_dts/{types-DTuViBvc.d.ts → types-CRPSGFAp.d.ts} +13 -4
- package/dist/_dts/{types-B7yBTTF9.d.ts → types-CSm9jgol.d.ts} +2 -2
- package/dist/_dts/{useTrialState-CMaV6UD4.d.ts → useTrialState-CTZPgeZ7.d.ts} +1 -1
- package/dist/canvas/index.d.ts +6 -6
- package/dist/canvas/index.js +2 -2
- package/dist/chrome/index.d.ts +5 -5
- package/dist/chrome/index.js +8 -8
- package/dist/{chunk-QGMOA2YE.js → chunk-275JRRVD.js} +67 -70
- package/dist/chunk-275JRRVD.js.map +1 -0
- package/dist/{chunk-KHK5FGER.js → chunk-4LJSC7MB.js} +8 -10
- package/dist/chunk-4LJSC7MB.js.map +1 -0
- package/dist/{chunk-SLAQPUI4.js → chunk-7BO7HNGF.js} +5 -5
- package/dist/{chunk-SLAQPUI4.js.map → chunk-7BO7HNGF.js.map} +1 -1
- package/dist/chunk-CZZPXUOU.js +3 -0
- package/dist/{chunk-SBXNQW4G.js.map → chunk-CZZPXUOU.js.map} +1 -1
- package/dist/{chunk-6FLXL3I7.js → chunk-FMK7UQ6V.js} +19 -4
- package/dist/chunk-FMK7UQ6V.js.map +1 -0
- package/dist/{chunk-O6FFFOHS.js → chunk-FZ7YFQN7.js} +16 -8
- package/dist/chunk-FZ7YFQN7.js.map +1 -0
- package/dist/{chunk-GHGO52SO.js → chunk-GOZLNM4L.js} +5 -5
- package/dist/{chunk-GHGO52SO.js.map → chunk-GOZLNM4L.js.map} +1 -1
- package/dist/{chunk-4TT3PNPR.js → chunk-I5DUQ5HM.js} +33 -36
- package/dist/chunk-I5DUQ5HM.js.map +1 -0
- package/dist/{chunk-NEXR37YJ.js → chunk-J7OWWTCW.js} +4 -5
- package/dist/chunk-J7OWWTCW.js.map +1 -0
- package/dist/{chunk-IRTGUQ5O.js → chunk-KMJ7RWD3.js} +16 -6
- package/dist/chunk-KMJ7RWD3.js.map +1 -0
- package/dist/{chunk-S4NCI32V.js → chunk-M7HP3FTK.js} +4 -4
- package/dist/{chunk-S4NCI32V.js.map → chunk-M7HP3FTK.js.map} +1 -1
- package/dist/chunk-MIM5R4ZT.js +14972 -0
- package/dist/chunk-MIM5R4ZT.js.map +1 -0
- package/dist/{chunk-ASOK76ZH.js → chunk-T5IBSPAM.js} +59 -26
- package/dist/chunk-T5IBSPAM.js.map +1 -0
- package/dist/{chunk-DWMSB4CA.js → chunk-UNAZSLWE.js} +82 -16
- package/dist/chunk-UNAZSLWE.js.map +1 -0
- package/dist/{chunk-TJ77A4A3.js → chunk-Y23G2VZL.js} +5 -9
- package/dist/chunk-Y23G2VZL.js.map +1 -0
- package/dist/{chunk-HKV7LRHY.js → chunk-YT75VYRD.js} +4 -4
- package/dist/{chunk-HKV7LRHY.js.map → chunk-YT75VYRD.js.map} +1 -1
- package/dist/{chunk-CGHF6RZV.js → chunk-ZIFPHIWZ.js} +9 -7
- package/dist/chunk-ZIFPHIWZ.js.map +1 -0
- package/dist/config/index.d.ts +16 -9
- package/dist/config/index.js +4 -4
- package/dist/controls/index.d.ts +2 -2
- package/dist/controls/index.js +5 -5
- package/dist/dragdrop/index.d.ts +3 -3
- package/dist/index.d.ts +263 -24
- package/dist/index.js +376 -237
- package/dist/index.js.map +1 -1
- package/dist/layers/index.d.ts +4 -4
- package/dist/layers/index.js +2 -2
- package/dist/loupe/index.d.ts +4 -4
- package/dist/loupe/index.js +2 -2
- package/dist/overview/index.d.ts +2 -2
- package/dist/overview/index.js +9 -8
- package/dist/overview/index.js.map +1 -1
- package/dist/passthrough/weasel-ui.d.ts +208 -38
- package/dist/passthrough/weasel-ui.js +3 -3
- package/dist/primitives/index.d.ts +3 -178
- package/dist/primitives/index.js +6 -6
- package/dist/state/index.d.ts +5 -5
- package/dist/state/index.js +4 -4
- package/dist/styles.css +91 -83
- package/dist/undo/index.d.ts +3 -3
- package/package.json +13 -12
- package/src/annotations/AnnotationOverlay.tsx +2 -2
- package/src/annotations/Annotations.less +0 -10
- package/src/annotations/MarkList.tsx +4 -8
- package/src/annotations/paint.test.ts +3 -14
- package/src/annotations/paint.ts +3 -19
- package/src/annotations/svgNodes.test.ts +6 -9
- package/src/annotations/svgNodes.ts +3 -3
- package/src/canvas/AGENTS.md +1 -0
- package/src/canvas/CameraInput.tsx +44 -33
- package/src/canvas/CanvasStack.tsx +6 -1
- package/src/canvas/LinkedCursor.less +1 -1
- package/src/canvas/Stage.test.tsx +33 -4
- package/src/canvas/Stage.tsx +6 -1
- package/src/canvas/cameraRegistry.test.ts +55 -0
- package/src/canvas/cameraRegistry.ts +86 -0
- package/src/canvas/cameraZoom.test.ts +46 -0
- package/src/canvas/cameraZoom.ts +24 -0
- package/src/canvas/index.ts +14 -2
- package/src/canvas/sharedScope.test.tsx +94 -0
- package/src/chrome/ChromeRegions.stories.tsx +1 -0
- package/src/chrome/regions/PaletteRegion.less +0 -7
- package/src/chrome/regions/SidebarRegion.less +12 -2
- package/src/config/builder.test.ts +2 -1
- package/src/config/builder.ts +12 -5
- package/src/config/fromConfigField.test.ts +14 -0
- package/src/config/fromConfigField.ts +18 -4
- package/src/config/path.ts +2 -5
- package/src/config/resolve.ts +4 -0
- package/src/config/types.ts +13 -9
- package/src/controls/ControlPanel.less +1 -1
- package/src/controls/ControlPanel.stories.tsx +3 -2
- package/src/controls/ControlPanel.test.tsx +64 -11
- package/src/controls/ControlPanel.tsx +52 -2
- package/src/index.ts +15 -1
- package/src/lab/Lab.tsx +83 -72
- package/src/lab/{LabFit.stories.less → LabFit.browser.test.less} +1 -1
- package/src/lab/{LabFit.stories.tsx → LabFit.browser.test.tsx} +41 -63
- package/src/lab/LabFullChrome.stories.tsx +1 -0
- package/src/lab/LabHeader.test.tsx +24 -14
- package/src/lab/LabHeader.tsx +11 -12
- package/src/lab/LabShell.less +8 -17
- package/src/lab/LabSwitcher.less +6 -6
- package/src/lab/LabZoom.test.tsx +223 -0
- package/src/lab/LabZoom.tsx +170 -0
- package/src/lab/index.ts +1 -0
- package/src/loupe/LoupeGestures.tsx +1 -1
- package/src/overview/TrialOverview.tsx +7 -5
- package/src/passthrough/weasel-ui.test.ts +2 -0
- package/src/passthrough/weasel-ui.ts +16 -4
- package/src/primitives/FloatingPanel.test.tsx +11 -0
- package/src/primitives/FloatingPanel.tsx +2 -5
- package/src/primitives/JobProgress.less +1 -1
- package/src/primitives/Legend.stories.tsx +1 -0
- package/src/primitives/Readout.browser.test.tsx +137 -0
- package/src/primitives/Readout.less +12 -0
- package/src/primitives/Readout.stories.tsx +58 -0
- package/src/primitives/Readout.test.tsx +93 -0
- package/src/primitives/Readout.tsx +56 -0
- package/src/primitives/index.ts +2 -0
- package/src/specimen/Specimen.stories.tsx +1 -0
- package/src/specimen/Specimen.tsx +2 -2
- package/src/state/Persistence.browser.test.tsx +47 -0
- package/src/state/store.test.ts +5 -1
- package/src/state/usePersistedState.test.tsx +1 -1
- package/src/styles.less +1 -0
- package/src/theme/Interstellar.stories.tsx +3 -1
- package/src/theme/base.less +21 -47
- package/src/theme/interstellar.test.ts +1 -1
- package/src/theme/interstellar.theme.json +10 -3
- package/src/trial/Trial.less +0 -13
- package/src/trial/Trial.tsx +12 -6
- package/src/trial/TrialChrome.tsx +21 -3
- package/dist/_dts/PrefsRow.d-DFpPIeIC.d.ts +0 -39
- package/dist/_dts/PropertyField.d-D0ndfIIt.d.ts +0 -404
- package/dist/chunk-4TT3PNPR.js.map +0 -1
- package/dist/chunk-6FLXL3I7.js.map +0 -1
- package/dist/chunk-ASOK76ZH.js.map +0 -1
- package/dist/chunk-CGHF6RZV.js.map +0 -1
- package/dist/chunk-DWMSB4CA.js.map +0 -1
- package/dist/chunk-IRTGUQ5O.js.map +0 -1
- package/dist/chunk-KHK5FGER.js.map +0 -1
- package/dist/chunk-NEXR37YJ.js.map +0 -1
- package/dist/chunk-O6FFFOHS.js.map +0 -1
- package/dist/chunk-QGMOA2YE.js.map +0 -1
- package/dist/chunk-SBXNQW4G.js +0 -3
- package/dist/chunk-TJ77A4A3.js.map +0 -1
- package/dist/chunk-TYN6MLXX.js +0 -13864
- package/dist/chunk-TYN6MLXX.js.map +0 -1
- package/src/state/Persistence.stories.tsx +0 -75
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* future without consumer churn.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
+
export { formatNumber, MINUS_SIGN } from '@weasel-js/quantity';
|
|
8
9
|
export {
|
|
9
10
|
ActionBar,
|
|
10
11
|
type ActionBarProps,
|
|
@@ -21,6 +22,7 @@ export {
|
|
|
21
22
|
type BadgeVariant,
|
|
22
23
|
type BoundsCtx,
|
|
23
24
|
type BuiltInEdgeName,
|
|
25
|
+
type BuiltInProfileName,
|
|
24
26
|
type BuiltinPref,
|
|
25
27
|
Button,
|
|
26
28
|
ButtonBar,
|
|
@@ -38,6 +40,9 @@ export {
|
|
|
38
40
|
type CheckboxProps,
|
|
39
41
|
type ChromaCurve,
|
|
40
42
|
type ChromaCurvePoint,
|
|
43
|
+
CloseButton,
|
|
44
|
+
type CloseButtonProps,
|
|
45
|
+
COLOR_MODE_OPTIONS,
|
|
41
46
|
ColorModeControl,
|
|
42
47
|
type ColorModeControlProps,
|
|
43
48
|
ComboBox,
|
|
@@ -65,8 +70,8 @@ export {
|
|
|
65
70
|
type DisclosureRowProps,
|
|
66
71
|
DragGhost,
|
|
67
72
|
type DragGhostProps,
|
|
68
|
-
|
|
69
|
-
type
|
|
73
|
+
DragGrip,
|
|
74
|
+
type DragGripProps,
|
|
70
75
|
detectPlatform,
|
|
71
76
|
dlog,
|
|
72
77
|
EDGE_PROFILES,
|
|
@@ -78,11 +83,13 @@ export {
|
|
|
78
83
|
type FieldProps,
|
|
79
84
|
type FillSettings,
|
|
80
85
|
fieldClasses,
|
|
81
|
-
formatNumber,
|
|
82
86
|
formatShortcut,
|
|
83
87
|
formatShortcutParts,
|
|
88
|
+
GestureRoute,
|
|
89
|
+
type GestureRouteProps,
|
|
84
90
|
type GradientTrackOpts,
|
|
85
91
|
type GridSettings,
|
|
92
|
+
gestureRouteSegments,
|
|
86
93
|
ICON_PATHS,
|
|
87
94
|
Icon,
|
|
88
95
|
type IconName,
|
|
@@ -98,6 +105,7 @@ export {
|
|
|
98
105
|
type KeyCapVariant,
|
|
99
106
|
type KeycapKind,
|
|
100
107
|
KeySequence,
|
|
108
|
+
type KeySequenceJoins,
|
|
101
109
|
type KeySequenceProps,
|
|
102
110
|
type KeySpec,
|
|
103
111
|
keyGlyph,
|
|
@@ -115,7 +123,6 @@ export {
|
|
|
115
123
|
MenuButton,
|
|
116
124
|
type MenuButtonItem,
|
|
117
125
|
type MenuButtonProps,
|
|
118
|
-
MINUS_SIGN,
|
|
119
126
|
moveLayers,
|
|
120
127
|
NumberField,
|
|
121
128
|
type NumberFieldProps,
|
|
@@ -138,6 +145,7 @@ export {
|
|
|
138
145
|
type PowerlineSegment,
|
|
139
146
|
type PrefBoolean,
|
|
140
147
|
type PrefBooleanControl,
|
|
148
|
+
type PrefBooleanEncoding,
|
|
141
149
|
type PrefColor,
|
|
142
150
|
type PrefCustom,
|
|
143
151
|
type PrefEnum,
|
|
@@ -191,6 +199,7 @@ export {
|
|
|
191
199
|
type StanceProps,
|
|
192
200
|
Switch,
|
|
193
201
|
type SwitchProps,
|
|
202
|
+
sampleByInterpolation,
|
|
194
203
|
Tab,
|
|
195
204
|
TabList,
|
|
196
205
|
type TabListProps,
|
|
@@ -199,6 +208,9 @@ export {
|
|
|
199
208
|
type TabProps,
|
|
200
209
|
Tabs,
|
|
201
210
|
type TabsProps,
|
|
211
|
+
ThemeSwitcher,
|
|
212
|
+
type ThemeSwitcherOption,
|
|
213
|
+
type ThemeSwitcherProps,
|
|
202
214
|
type Thumb,
|
|
203
215
|
type ThumbRenderCtx,
|
|
204
216
|
type ThumbShape,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { fireEvent, render, screen, waitFor } from '@testing-library/react';
|
|
2
|
+
import { DRAG_THRESHOLD_PX } from '@weasel-js/core';
|
|
2
3
|
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
3
4
|
import { createMemoryAdapter } from '../state/adapters';
|
|
4
5
|
import { labPrefix } from '../state/labRecords';
|
|
@@ -130,6 +131,16 @@ describe('FloatingPanel dragging', () => {
|
|
|
130
131
|
expect(panel.dataset.dragging).toBeUndefined();
|
|
131
132
|
});
|
|
132
133
|
|
|
134
|
+
it('becomes a drag at the kit drag threshold, not before', () => {
|
|
135
|
+
const { panel } = renderPanel(<FloatingPanel>x</FloatingPanel>);
|
|
136
|
+
fireEvent.pointerDown(panel, { clientX: 100, clientY: 100 });
|
|
137
|
+
fireEvent.pointerMove(panel, { clientX: 100 + DRAG_THRESHOLD_PX - 0.5, clientY: 100 });
|
|
138
|
+
expect(panel.dataset.dragging).toBeUndefined();
|
|
139
|
+
fireEvent.pointerMove(panel, { clientX: 100 + DRAG_THRESHOLD_PX, clientY: 100 });
|
|
140
|
+
expect(panel.dataset.dragging).toBe('true');
|
|
141
|
+
fireEvent.pointerUp(panel);
|
|
142
|
+
});
|
|
143
|
+
|
|
133
144
|
it('a press that never moves is not a drag', () => {
|
|
134
145
|
const { panel } = renderPanel(<FloatingPanel anchor="top-left">x</FloatingPanel>);
|
|
135
146
|
const before = panel.style.left;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { openPointerSession, type PointerSession } from '@weasel-js/core';
|
|
1
|
+
import { openPointerSession, type PointerSession, pastDragThreshold } from '@weasel-js/core';
|
|
2
2
|
import type React from 'react';
|
|
3
3
|
import { type CSSProperties, type ReactNode, useEffect, useMemo, useRef, useState } from 'react';
|
|
4
4
|
import {
|
|
@@ -41,9 +41,6 @@ function borderBoxOf(entry: ResizeObserverEntry): { w: number; h: number } {
|
|
|
41
41
|
return { w: entry.contentRect.width, h: entry.contentRect.height };
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
/** How far the pointer must travel before a press becomes a drag. */
|
|
45
|
-
const DRAG_THRESHOLD = 3;
|
|
46
|
-
|
|
47
44
|
/** A pointerdown on one of these is the child's, not a drag. */
|
|
48
45
|
function isInteractive(target: EventTarget | null): boolean {
|
|
49
46
|
if (!(target instanceof Element)) return false;
|
|
@@ -158,7 +155,7 @@ export function FloatingPanel({
|
|
|
158
155
|
{
|
|
159
156
|
onMove: (ev) => {
|
|
160
157
|
if (!dragging.current) {
|
|
161
|
-
if (
|
|
158
|
+
if (!pastDragThreshold({ clientX: start.x, clientY: start.y }, ev)) return;
|
|
162
159
|
dragging.current = { ...start };
|
|
163
160
|
setDragging(true);
|
|
164
161
|
origin.setPointerCapture?.(pointerId);
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
height: 100%;
|
|
19
19
|
background: var(--wzl-accent);
|
|
20
20
|
transform-origin: left center;
|
|
21
|
-
transition: transform
|
|
21
|
+
transition: transform var(--wzl-motion-fast) linear;
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
// A job that never reports a total sweeps instead of filling, so the bar
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import '@weasel-js/theme/tokens.css';
|
|
2
|
+
import '@weasel-js/theme/fonts.css';
|
|
3
|
+
import '../styles.less';
|
|
4
|
+
import { cleanup, render } from '@testing-library/react';
|
|
5
|
+
import { afterEach, expect, test } from 'vitest';
|
|
6
|
+
import { Readout, type ReadoutRow } from './Readout';
|
|
7
|
+
|
|
8
|
+
function must<T>(el: T | null): T {
|
|
9
|
+
if (el == null) throw new Error('expected an element');
|
|
10
|
+
return el;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// Right alignment, the figure column's minimum width and a height that holds
|
|
14
|
+
// while values come and go are all layout, which only a real browser has.
|
|
15
|
+
|
|
16
|
+
afterEach(cleanup);
|
|
17
|
+
|
|
18
|
+
const FIGURE_SPACE = ' ';
|
|
19
|
+
|
|
20
|
+
const rows = (withValues: boolean): ReadoutRow[] => [
|
|
21
|
+
{
|
|
22
|
+
label: 'Lock margin',
|
|
23
|
+
value: withValues ? <span data-v>locked +47.9°</span> : undefined,
|
|
24
|
+
status: 'success',
|
|
25
|
+
},
|
|
26
|
+
{ label: 'Score', value: withValues ? <span data-v>{`${FIGURE_SPACE}0.145`}</span> : undefined },
|
|
27
|
+
{ label: 'Error', value: withValues ? <span data-v>12.345</span> : undefined, status: 'danger' },
|
|
28
|
+
];
|
|
29
|
+
|
|
30
|
+
const box = (el: Element) => el.getBoundingClientRect();
|
|
31
|
+
|
|
32
|
+
test('values sit right-aligned at the edge of the list', () => {
|
|
33
|
+
const { container } = render(
|
|
34
|
+
<div style={{ width: 320 }}>
|
|
35
|
+
<Readout rows={rows(true)} />
|
|
36
|
+
</div>,
|
|
37
|
+
);
|
|
38
|
+
const dl = must(container.querySelector('dl'));
|
|
39
|
+
const values = [...container.querySelectorAll('[data-v]')];
|
|
40
|
+
expect(values).toHaveLength(3);
|
|
41
|
+
for (const v of values) expect(Math.abs(box(v).right - box(dl).right)).toBeLessThan(0.5);
|
|
42
|
+
expect(box(values[0]).width).not.toBeCloseTo(box(values[2]).width, 0);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
test('figures are equal width, so padding lines a column up on the decimal point', async () => {
|
|
46
|
+
// 1 and 8 differ in width wherever digits are proportional, as they are in
|
|
47
|
+
// the theme's display face, which has no tabular figures to switch on.
|
|
48
|
+
const { container } = render(
|
|
49
|
+
<div style={{ width: 320, fontFamily: 'var(--wzl-font-display)' }}>
|
|
50
|
+
<Readout
|
|
51
|
+
rows={[
|
|
52
|
+
{ label: 'a', value: <span data-v>{`${FIGURE_SPACE}1.111`}</span> },
|
|
53
|
+
{ label: 'b', value: <span data-v>88.888</span> },
|
|
54
|
+
]}
|
|
55
|
+
/>
|
|
56
|
+
</div>,
|
|
57
|
+
);
|
|
58
|
+
await document.fonts.ready;
|
|
59
|
+
const [narrow, wide] = [...container.querySelectorAll('[data-v]')];
|
|
60
|
+
expect(Math.abs(box(narrow).width - box(wide).width)).toBeLessThan(0.5);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
test('the value column holds a minimum width in a shrink-wrapped readout', () => {
|
|
64
|
+
const { container } = render(
|
|
65
|
+
<div style={{ width: 'max-content' }}>
|
|
66
|
+
<Readout rows={[{ label: 'n', value: <span data-v>1</span> }]} />
|
|
67
|
+
</div>,
|
|
68
|
+
);
|
|
69
|
+
const digit = box(must(container.querySelector('[data-v]'))).width;
|
|
70
|
+
const dd = box(must(container.querySelector('dd'))).width;
|
|
71
|
+
expect(dd).toBeGreaterThanOrEqual(8 * digit - 0.5);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
test('rows keep their place and the list its height while values are absent', () => {
|
|
75
|
+
const { container, rerender } = render(
|
|
76
|
+
<div style={{ width: 320 }}>
|
|
77
|
+
<Readout rows={rows(true)} />
|
|
78
|
+
</div>,
|
|
79
|
+
);
|
|
80
|
+
const dl = () => must(container.querySelector('dl'));
|
|
81
|
+
const rowHeights = () => [...dl().children].map((r) => box(r).height);
|
|
82
|
+
const withValues = { list: box(dl()).height, rows: rowHeights() };
|
|
83
|
+
rerender(
|
|
84
|
+
<div style={{ width: 320 }}>
|
|
85
|
+
<Readout rows={rows(false)} />
|
|
86
|
+
</div>,
|
|
87
|
+
);
|
|
88
|
+
expect(dl().querySelectorAll('[data-empty]')).toHaveLength(3);
|
|
89
|
+
expect(box(dl()).height).toBeCloseTo(withValues.list, 1);
|
|
90
|
+
expect(rowHeights()).toEqual(withValues.rows);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
test('a status dot is drawn before its value, on the same line', () => {
|
|
94
|
+
const { container } = render(
|
|
95
|
+
<div style={{ width: 320 }}>
|
|
96
|
+
<Readout rows={rows(true)} />
|
|
97
|
+
</div>,
|
|
98
|
+
);
|
|
99
|
+
const dd = must(container.querySelector('dd'));
|
|
100
|
+
const dot = box(must(dd.querySelector('[aria-hidden]')));
|
|
101
|
+
const value = box(must(dd.querySelector('[data-v]')));
|
|
102
|
+
expect(dot.width).toBeGreaterThan(0);
|
|
103
|
+
expect(dot.right).toBeLessThanOrEqual(value.left);
|
|
104
|
+
expect(dot.top).toBeGreaterThanOrEqual(value.top - 1);
|
|
105
|
+
expect(dot.bottom).toBeLessThanOrEqual(value.bottom + 1);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
test('a text row wraps inside a figures readout instead of overflowing it', () => {
|
|
109
|
+
const { container } = render(
|
|
110
|
+
<div style={{ width: 300, fontFamily: 'var(--wzl-font-display)' }}>
|
|
111
|
+
<Readout
|
|
112
|
+
rows={[
|
|
113
|
+
{ label: 'Score', value: <span data-v>0.145</span> },
|
|
114
|
+
{
|
|
115
|
+
label: 'Sides',
|
|
116
|
+
value: (
|
|
117
|
+
<span data-t>
|
|
118
|
+
1 flat, 2 tab, 3 blank, 4 blank, 5 flat, 6 tab, 7 blank, 8 blank, 9 flat
|
|
119
|
+
</span>
|
|
120
|
+
),
|
|
121
|
+
values: 'text',
|
|
122
|
+
},
|
|
123
|
+
]}
|
|
124
|
+
/>
|
|
125
|
+
</div>,
|
|
126
|
+
);
|
|
127
|
+
const dl = must(container.querySelector('dl'));
|
|
128
|
+
expect(dl.scrollWidth).toBeLessThanOrEqual(dl.clientWidth);
|
|
129
|
+
const text = must(container.querySelector('[data-t]'));
|
|
130
|
+
expect(box(text).right).toBeLessThanOrEqual(box(dl).right + 0.5);
|
|
131
|
+
expect(box(text).height).toBeGreaterThan(
|
|
132
|
+
box(must(container.querySelector('[data-v]'))).height * 1.5,
|
|
133
|
+
);
|
|
134
|
+
expect(
|
|
135
|
+
Math.abs(box(must(container.querySelector('[data-v]'))).right - box(dl).right),
|
|
136
|
+
).toBeLessThan(0.5);
|
|
137
|
+
});
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@weasel-js/forge';
|
|
2
|
+
import { useState } from 'react';
|
|
3
|
+
import { Readout } from './Readout';
|
|
4
|
+
|
|
5
|
+
const meta: Meta<typeof Readout> = {
|
|
6
|
+
title: 'labkit/Primitives/Readout',
|
|
7
|
+
component: Readout,
|
|
8
|
+
};
|
|
9
|
+
export default meta;
|
|
10
|
+
|
|
11
|
+
type Story = StoryObj<typeof Readout>;
|
|
12
|
+
|
|
13
|
+
const FIGURE_SPACE = ' ';
|
|
14
|
+
|
|
15
|
+
export const Measurements: Story = {
|
|
16
|
+
tags: ['gallery'],
|
|
17
|
+
args: {
|
|
18
|
+
rows: [
|
|
19
|
+
{ label: 'Lock margin', value: 'locked +47.9°', status: 'success' },
|
|
20
|
+
{ label: 'Score', value: `${FIGURE_SPACE}0.145` },
|
|
21
|
+
{ label: 'Residual', value: `${FIGURE_SPACE}3.020` },
|
|
22
|
+
{ label: 'Overshoot', value: 'over 12.345', status: 'danger' },
|
|
23
|
+
],
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export const WithTitleAndNote: Story = {
|
|
28
|
+
args: {
|
|
29
|
+
title: 'Fit',
|
|
30
|
+
rows: [
|
|
31
|
+
{ label: 'Score', value: '0.145' },
|
|
32
|
+
{ label: 'Iterations', value: `${FIGURE_SPACE}${FIGURE_SPACE}42` },
|
|
33
|
+
],
|
|
34
|
+
children: 'Scores under 0.2 converge within one pass.',
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
/** Values vanish while the cursor is off the picture; the rows hold their
|
|
39
|
+
* place and the readout its height. */
|
|
40
|
+
export const ValuesComeAndGo: Story = {
|
|
41
|
+
render: () => {
|
|
42
|
+
const [on, setOn] = useState(true);
|
|
43
|
+
return (
|
|
44
|
+
<div>
|
|
45
|
+
<button type="button" onClick={() => setOn((v) => !v)}>
|
|
46
|
+
{on ? 'Hide values' : 'Show values'}
|
|
47
|
+
</button>
|
|
48
|
+
<Readout
|
|
49
|
+
rows={[
|
|
50
|
+
{ label: 'x', value: on ? `${FIGURE_SPACE}12.50` : undefined },
|
|
51
|
+
{ label: 'y', value: on ? '-3.75' : undefined },
|
|
52
|
+
{ label: 'Hit', value: on ? 'inside' : undefined, status: on ? 'success' : undefined },
|
|
53
|
+
]}
|
|
54
|
+
/>
|
|
55
|
+
</div>
|
|
56
|
+
);
|
|
57
|
+
},
|
|
58
|
+
};
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { render, screen } from '@testing-library/react';
|
|
2
|
+
import { describe, expect, it } from 'vitest';
|
|
3
|
+
import * as labkit from '../index';
|
|
4
|
+
import { Readout } from './Readout';
|
|
5
|
+
|
|
6
|
+
function must<T>(el: T | null): T {
|
|
7
|
+
if (el == null) throw new Error('expected an element');
|
|
8
|
+
return el;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
describe('Readout', () => {
|
|
12
|
+
it('renders its rows as one <dl>, in order, each a label and a value', () => {
|
|
13
|
+
const { container } = render(
|
|
14
|
+
<Readout
|
|
15
|
+
rows={[
|
|
16
|
+
{ label: 'Lock margin', value: '+47.9°' },
|
|
17
|
+
{ label: 'Score', value: '0.145' },
|
|
18
|
+
]}
|
|
19
|
+
/>,
|
|
20
|
+
);
|
|
21
|
+
const dl = must(container.querySelector('dl'));
|
|
22
|
+
expect([...dl.querySelectorAll('dt')].map((d) => d.textContent)).toEqual([
|
|
23
|
+
'Lock margin',
|
|
24
|
+
'Score',
|
|
25
|
+
]);
|
|
26
|
+
expect([...dl.querySelectorAll('dd')].map((d) => d.textContent)).toEqual(['+47.9°', '0.145']);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('sets its values as figures', () => {
|
|
30
|
+
const { container } = render(<Readout rows={[{ label: 'a', value: '1' }]} />);
|
|
31
|
+
expect(must(container.querySelector('dl')).getAttribute('data-values')).toBe('figures');
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('keeps a row whose value is absent, showing a dash', () => {
|
|
35
|
+
const { container } = render(
|
|
36
|
+
<Readout
|
|
37
|
+
rows={[
|
|
38
|
+
{ label: 'Lock margin', value: undefined },
|
|
39
|
+
{ label: 'Score', value: '0.145' },
|
|
40
|
+
]}
|
|
41
|
+
/>,
|
|
42
|
+
);
|
|
43
|
+
expect(container.querySelectorAll('dl > div')).toHaveLength(2);
|
|
44
|
+
expect(must(container.querySelector('dd')).textContent).toBe('–');
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('marks a row with its status', () => {
|
|
48
|
+
const { container } = render(
|
|
49
|
+
<Readout rows={[{ label: 'Lock', value: 'locked', status: 'success' }]} />,
|
|
50
|
+
);
|
|
51
|
+
expect(must(container.querySelector('dl > div')).getAttribute('data-status')).toBe('success');
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('puts its children below the rows', () => {
|
|
55
|
+
const { container } = render(
|
|
56
|
+
<Readout rows={[{ label: 'a', value: '1' }]}>
|
|
57
|
+
<p>note</p>
|
|
58
|
+
</Readout>,
|
|
59
|
+
);
|
|
60
|
+
const root = must(container.firstElementChild);
|
|
61
|
+
expect(root.className).toContain('lk-readout');
|
|
62
|
+
const note = screen.getByText('note');
|
|
63
|
+
expect(
|
|
64
|
+
must(root.querySelector('dl')).compareDocumentPosition(note) &
|
|
65
|
+
Node.DOCUMENT_POSITION_FOLLOWING,
|
|
66
|
+
).toBeTruthy();
|
|
67
|
+
expect(note.closest('dl')).toBeNull();
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it('draws no footer without children', () => {
|
|
71
|
+
const { container } = render(<Readout rows={[{ label: 'a', value: '1' }]} />);
|
|
72
|
+
expect(container.querySelector('.lk-readout__footer')).toBeNull();
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('names the list by its title', () => {
|
|
76
|
+
render(<Readout title="Measure" rows={[{ label: 'a', value: '1' }]} />);
|
|
77
|
+
const heading = screen.getByRole('heading', { name: 'Measure' });
|
|
78
|
+
expect(
|
|
79
|
+
must(must(heading.parentElement).querySelector('dl')).getAttribute('aria-labelledby'),
|
|
80
|
+
).toBe(heading.id);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it('merges a consumer className on its root', () => {
|
|
84
|
+
const { container } = render(<Readout className="mine" rows={[]} />);
|
|
85
|
+
expect(must(container.firstElementChild).className).toMatch(/\blk-readout\b.*\bmine\b/);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it('is exported from the labkit barrel, with the list it is built on', () => {
|
|
89
|
+
expect(labkit.Readout).toBe(Readout);
|
|
90
|
+
expect(typeof labkit.DetailList).toBe('function');
|
|
91
|
+
expect(typeof labkit.DetailRow).toBe('function');
|
|
92
|
+
});
|
|
93
|
+
});
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { DetailList, type DetailListValues, DetailRow, type DetailRowStatus } from '@weasel-js/ui';
|
|
2
|
+
import type { ReactNode } from 'react';
|
|
3
|
+
|
|
4
|
+
/** One measurement in a {@link Readout}. */
|
|
5
|
+
export interface ReadoutRow {
|
|
6
|
+
/** React key. Defaults to `label` when that is a string, else the row's index. */
|
|
7
|
+
key?: string;
|
|
8
|
+
label: ReactNode;
|
|
9
|
+
/** `null` or `undefined` keeps the row in place showing an en dash, so the
|
|
10
|
+
* readout holds its height while a measurement comes and goes. */
|
|
11
|
+
value?: ReactNode;
|
|
12
|
+
/** A dot in the status color before the value. Color is never the only
|
|
13
|
+
* signal: the value has to say the same thing in words. */
|
|
14
|
+
status?: DetailRowStatus;
|
|
15
|
+
/** `text` sets this row's value as wrapping prose instead of a figure. */
|
|
16
|
+
values?: DetailListValues;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** Props for {@link Readout}. */
|
|
20
|
+
export interface ReadoutProps {
|
|
21
|
+
rows: readonly ReadoutRow[];
|
|
22
|
+
/** Heading above the rows, which also names the list. */
|
|
23
|
+
title?: ReactNode;
|
|
24
|
+
/** Drawn below the rows — a small table, a note. */
|
|
25
|
+
children?: ReactNode;
|
|
26
|
+
className?: string;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Values a lab only reads — measurements shown beside its picture, such as
|
|
31
|
+
* "Lock margin +47.9°". A {@link DetailList} set as figures: labels take the
|
|
32
|
+
* params label recipe and `--wzl-params-label-width` rail, so a readout lines
|
|
33
|
+
* up with a `ControlPanel` beside it, and values sit right-aligned in the mono
|
|
34
|
+
* face with spaces kept, so figure-space padding aligns a column on its
|
|
35
|
+
* decimal point. Rows compose by hand as `DetailRow`s inside a `DetailList`
|
|
36
|
+
* with `values="figures"`.
|
|
37
|
+
*/
|
|
38
|
+
export function Readout({ rows, title, children, className }: ReadoutProps) {
|
|
39
|
+
return (
|
|
40
|
+
<div className={className ? `lk-readout ${className}` : 'lk-readout'}>
|
|
41
|
+
<DetailList title={title} values="figures">
|
|
42
|
+
{rows.map((row, i) => (
|
|
43
|
+
<DetailRow
|
|
44
|
+
key={row.key ?? (typeof row.label === 'string' ? row.label : i)}
|
|
45
|
+
label={row.label}
|
|
46
|
+
status={row.status}
|
|
47
|
+
values={row.values}
|
|
48
|
+
>
|
|
49
|
+
{row.value}
|
|
50
|
+
</DetailRow>
|
|
51
|
+
))}
|
|
52
|
+
</DetailList>
|
|
53
|
+
{children != null && <div className="lk-readout__footer">{children}</div>}
|
|
54
|
+
</div>
|
|
55
|
+
);
|
|
56
|
+
}
|
package/src/primitives/index.ts
CHANGED
|
@@ -5,6 +5,8 @@ export type { JobProgressProps } from './JobProgress';
|
|
|
5
5
|
export { JobProgress } from './JobProgress';
|
|
6
6
|
export type { LegendEntry, LegendMark, LegendProps } from './Legend';
|
|
7
7
|
export { Legend } from './Legend';
|
|
8
|
+
export type { ReadoutProps, ReadoutRow } from './Readout';
|
|
9
|
+
export { Readout } from './Readout';
|
|
8
10
|
export type { ScaleIndicatorProps } from './ScaleIndicator';
|
|
9
11
|
export { ScaleIndicator } from './ScaleIndicator';
|
|
10
12
|
export type { SplitProps } from './Split';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { FillStyle,
|
|
1
|
+
import type { FillStyle, Track } from '@weasel-js/core';
|
|
2
2
|
import {
|
|
3
3
|
Badge,
|
|
4
4
|
type Band,
|
|
@@ -321,7 +321,7 @@ function FieldsAndPickers() {
|
|
|
321
321
|
const [rate, setRate] = useState(1);
|
|
322
322
|
const [width, setWidth] = useState(6);
|
|
323
323
|
const [color, setColor] = useState('#b08adbff');
|
|
324
|
-
const [gradient, setGradient] = useState<
|
|
324
|
+
const [gradient, setGradient] = useState<FillStyle>({
|
|
325
325
|
fill: 'linear-gradient',
|
|
326
326
|
from: { x: 0.1, y: 0.1 },
|
|
327
327
|
to: { x: 0.9, y: 0.9 },
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react';
|
|
2
|
+
import { afterEach, expect, test } from 'vitest';
|
|
3
|
+
import { createIndexedDbAdapter } from './adapters';
|
|
4
|
+
import { Persistence } from './Persistence';
|
|
5
|
+
import { usePersistedState } from './usePersistedState';
|
|
6
|
+
|
|
7
|
+
// jsdom only has fake-indexeddb, an imitation; this goes through the browser's own.
|
|
8
|
+
|
|
9
|
+
afterEach(cleanup);
|
|
10
|
+
|
|
11
|
+
function Tab() {
|
|
12
|
+
const [tab, setTab] = usePersistedState('tab', 'shape');
|
|
13
|
+
return (
|
|
14
|
+
<p>
|
|
15
|
+
<output aria-label="tab">{tab}</output>
|
|
16
|
+
<button type="button" onClick={() => setTab('color')}>
|
|
17
|
+
choose color
|
|
18
|
+
</button>
|
|
19
|
+
</p>
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const mount = (storage: ReturnType<typeof createIndexedDbAdapter>) =>
|
|
24
|
+
render(
|
|
25
|
+
<Persistence storageKey="test" storage={storage} fallback={<p>loading</p>}>
|
|
26
|
+
<Tab />
|
|
27
|
+
</Persistence>,
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
test('a value survives a remount through real IndexedDB', async () => {
|
|
31
|
+
const database = `labkit-browser-test-${Date.now()}`;
|
|
32
|
+
|
|
33
|
+
const first = mount(createIndexedDbAdapter({ database }));
|
|
34
|
+
await waitFor(() => expect(screen.getByLabelText('tab').textContent).toBe('shape'));
|
|
35
|
+
fireEvent.click(screen.getByText('choose color'));
|
|
36
|
+
await waitFor(() => expect(screen.getByLabelText('tab').textContent).toBe('color'));
|
|
37
|
+
|
|
38
|
+
// Unmounting closes the provider, whose deferred close sends the queued write.
|
|
39
|
+
first.unmount();
|
|
40
|
+
await new Promise((r) => setTimeout(r, 100));
|
|
41
|
+
|
|
42
|
+
// A fresh adapter, so nothing it reads can come from the first one's memory.
|
|
43
|
+
mount(createIndexedDbAdapter({ database }));
|
|
44
|
+
await waitFor(() => expect(screen.getByLabelText('tab').textContent).toBe('color'), {
|
|
45
|
+
timeout: 3000,
|
|
46
|
+
});
|
|
47
|
+
});
|
package/src/state/store.test.ts
CHANGED
|
@@ -420,7 +420,11 @@ describe('setInstruments', () => {
|
|
|
420
420
|
store.getState().addTrial(mappedTrial);
|
|
421
421
|
store.getState().setInstruments([{ ...small, name: 'Mapped' }]);
|
|
422
422
|
store.getState().saveSnapshot('m', 'one');
|
|
423
|
-
|
|
423
|
+
// By tag, not `toEqual(new Set(…))`: under jsdom structuredClone hands back Node's Set.
|
|
424
|
+
const seen = (store.getState().savedSnapshots[0]?.state as { seen: Set<string> } | undefined)
|
|
425
|
+
?.seen;
|
|
426
|
+
expect(Object.prototype.toString.call(seen)).toBe('[object Set]');
|
|
427
|
+
expect([...seen!]).toEqual(['a']);
|
|
424
428
|
});
|
|
425
429
|
|
|
426
430
|
it('changes neither hooks nor state when a new default config throws', () => {
|
|
@@ -109,7 +109,7 @@ describe('usePersistedState', () => {
|
|
|
109
109
|
);
|
|
110
110
|
await screen.findByLabelText('a');
|
|
111
111
|
act(() => screen.getByText('set a').click());
|
|
112
|
-
expect(shown('b')).toBe('color');
|
|
112
|
+
await waitFor(() => expect(shown('b')).toBe('color'));
|
|
113
113
|
});
|
|
114
114
|
|
|
115
115
|
it("re-renders with another tab's write", async () => {
|
package/src/styles.less
CHANGED
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
@import './primitives/FpsMeter.less';
|
|
15
15
|
@import './primitives/ScaleIndicator.less';
|
|
16
16
|
@import './primitives/Legend.less';
|
|
17
|
+
@import './primitives/Readout.less';
|
|
17
18
|
@import './primitives/FloatingPanel.less';
|
|
18
19
|
@import './lab/Lab.less';
|
|
19
20
|
@import './trial/Trial.less';
|
|
@@ -3,9 +3,11 @@ import type { TokenName } from '@weasel-js/theme';
|
|
|
3
3
|
import { useTheme } from '@weasel-js/theme/react';
|
|
4
4
|
import { PropertyField, PropertyList, PropertyPanel } from '@weasel-js/ui';
|
|
5
5
|
import './Interstellar.stories.less';
|
|
6
|
+
import { decimal } from '@weasel-js/quantity';
|
|
6
7
|
|
|
7
8
|
const meta: Meta = {
|
|
8
9
|
title: 'labkit/Themes/Interstellar',
|
|
10
|
+
tags: ['gallery'],
|
|
9
11
|
parameters: {
|
|
10
12
|
docs: {
|
|
11
13
|
description: {
|
|
@@ -150,7 +152,7 @@ function LivePanelPreview() {
|
|
|
150
152
|
max={1}
|
|
151
153
|
step={0.01}
|
|
152
154
|
onChange={() => {}}
|
|
153
|
-
|
|
155
|
+
display={decimal({ places: 2 })}
|
|
154
156
|
/>
|
|
155
157
|
<PropertyField kind="color" label="Fill" value="#b08adb" onChange={() => {}} />
|
|
156
158
|
<PropertyField kind="color" label="Stroke" value="#1a1428" onChange={() => {}} />
|