strata-react 1.0.7 → 1.0.9

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/index.js CHANGED
@@ -1,12 +1,14 @@
1
1
  import { C as readErrorBody, E as typeSteps, S as fieldErrorsOf, T as cn, _ as Textarea, a as toLoad, b as describeActionError, c as ColorSchemeChoice, d as useColorScheme, f as useSystemColorScheme, g as NativeSelect, h as Input, i as staleOf, l as ThemeProvider, m as Field, n as createQueryClient, o as useLoad, p as ChoiceGroup, r as fetchJson, s as COLOR_SCHEME_STORAGE_KEY, t as StrataQueryProvider, u as colorSchemeScript, v as useFieldControl, w as Tooltip, x as describeHttpError, y as HttpError } from "./query-CXlmWmrY.js";
2
2
  import * as React from "react";
3
- import { Autocomplete, Button as Button$1, Checkbox as Checkbox$1, Dialog as Dialog$1, DialogTrigger, Disclosure as Disclosure$1, DisclosurePanel, DropZone, FileTrigger, Header, Heading, I18nProvider, Input as Input$1, Keyboard, Menu as Menu$1, MenuItem, MenuSection, MenuTrigger, Modal, ModalOverlay, NumberField as NumberField$1, Popover as Popover$1, SearchField, Separator, Slider as Slider$1, SliderOutput, SliderThumb, SliderTrack, SubmenuTrigger, Switch as Switch$1, Tab, TabList, TabPanel, Tabs as Tabs$1, Text, ToggleButton, ToggleButtonGroup, Toolbar as Toolbar$1, UNSTABLE_Toast, UNSTABLE_ToastContent, UNSTABLE_ToastQueue, UNSTABLE_ToastRegion, useFilter } from "react-aria-components";
3
+ import { Autocomplete, Button as Button$1, Checkbox as Checkbox$1, Dialog as Dialog$1, DialogTrigger, Disclosure as Disclosure$1, DisclosurePanel, DropIndicator, DropZone, FileTrigger, GridList, GridListItem, Header, Heading, I18nProvider, Input as Input$1, Keyboard, Menu as Menu$1, MenuItem, MenuSection, MenuTrigger, Modal, ModalOverlay, NumberField as NumberField$1, Popover as Popover$1, SearchField, Separator, Slider as Slider$1, SliderOutput, SliderThumb, SliderTrack, SubmenuTrigger, Switch as Switch$1, Tab, TabList, TabPanel, Tabs as Tabs$1, Text, ToggleButton, ToggleButtonGroup, Toolbar as Toolbar$1, UNSTABLE_Toast, UNSTABLE_ToastContent, UNSTABLE_ToastQueue, UNSTABLE_ToastRegion, useDragAndDrop, useFilter } from "react-aria-components";
4
4
  import { cva } from "class-variance-authority";
5
5
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
6
- import { ArrowDown, ArrowUp, ArrowUpDown, ArrowUpRight, Ban, Check, ChevronRight, CircleAlert, CircleCheck, FileQuestion, History, ImageOff, Info, Loader, LoaderCircle, Maximize, Minimize, Minus, RotateCcw, Scan, Search, Trash2, TriangleAlert, Upload, X, ZoomIn, ZoomOut } from "lucide-react";
6
+ import { ArrowDown, ArrowUp, ArrowUpDown, ArrowUpRight, Ban, Check, ChevronRight, CircleAlert, CircleCheck, FileQuestion, GripVertical, History, ImageOff, Info, Loader, LoaderCircle, Maximize, Maximize2, Minimize, Minus, RotateCcw, Scan, Search, Trash2, TriangleAlert, Upload, X, ZoomIn, ZoomOut } from "lucide-react";
7
7
  import { Link, NavLink, useSearchParams } from "react-router";
8
8
  import { createSortedRowModel, flexRender, rowSortingFeature, tableFeatures, useTable } from "@tanstack/react-table";
9
9
  import { useVirtualizer } from "@tanstack/react-virtual";
10
+ import { VisuallyHidden, mergeProps, useFocusRing, useSlider, useSliderThumb } from "react-aria";
11
+ import { useSliderState } from "react-stately";
10
12
  import { hashKey, useInfiniteQuery, useQuery, useQueryClient } from "@tanstack/react-query";
11
13
  import pixelmatch from "pixelmatch";
12
14
  // src/lib/format.ts
@@ -2874,6 +2876,788 @@ function TableSkeleton({ rows = 4, columns = 5 }) {
2874
2876
  }, r))]
2875
2877
  });
2876
2878
  }
2879
+ // src/lib/timeline.ts
2880
+ /** Steps a person would write on a scale, in seconds: 1, 2, 5 and 10 × 10ⁿ below a minute, then 15 s, 30 s, minutes, quarter hours, hours, days. ux-research components.md §3.8: ticks land on values people would write. */
2881
+ var STEPS = [
2882
+ .01,
2883
+ .02,
2884
+ .05,
2885
+ .1,
2886
+ .2,
2887
+ .5,
2888
+ 1,
2889
+ 2,
2890
+ 5,
2891
+ 10,
2892
+ 15,
2893
+ 30,
2894
+ 60,
2895
+ 120,
2896
+ 300,
2897
+ 600,
2898
+ 900,
2899
+ 1800,
2900
+ 3600,
2901
+ 7200,
2902
+ 14400,
2903
+ 21600,
2904
+ 43200,
2905
+ 86400
2906
+ ];
2907
+ /** The smallest step whose ticks are at least `minGapPx` apart at this zoom, so labels thin out instead of colliding. */
2908
+ function tickStep(pxPerUnit, minGapPx = 80) {
2909
+ return STEPS.find((s) => s * pxPerUnit >= minGapPx) ?? STEPS[STEPS.length - 1];
2910
+ }
2911
+ /** Tick times from `from` to `to` inclusive, on multiples of `step`. */
2912
+ function ticksBetween(from, to, step) {
2913
+ const out = [];
2914
+ const first = Math.ceil(from / step - 1e-9);
2915
+ for (let i = first; i * step <= to + 1e-9; i++) out.push(Math.round(i * step * 1e6) / 1e6 || 0);
2916
+ return out;
2917
+ }
2918
+ /** A tick's label: m:ss, h:mm:ss, with tenths or hundredths when the step is under a second. */
2919
+ function tickLabel(time, step) {
2920
+ const decimals = step < .1 ? 2 : step < 1 ? 1 : 0;
2921
+ const whole = Math.floor(time + 1e-9);
2922
+ const h = Math.floor(whole / 3600);
2923
+ const m = Math.floor(whole % 3600 / 60);
2924
+ const s = whole % 60;
2925
+ const two = (n) => String(n).padStart(2, "0");
2926
+ const base = h > 0 ? `${h}:${two(m)}:${two(s)}` : `${m}:${two(s)}`;
2927
+ return decimals ? `${base}.${String(Math.round((time - whole) * 10 ** decimals)).padStart(decimals, "0")}` : base;
2928
+ }
2929
+ function clamp(value, min, max) {
2930
+ return Math.min(Math.max(value, min), max);
2931
+ }
2932
+ /** The point to snap `time` to: the nearest of `points` within `thresholdPx` at this zoom, or `null`. */
2933
+ function snapTo(time, points, pxPerUnit, thresholdPx = 8) {
2934
+ let best = null;
2935
+ for (const p of points) if (Math.abs(p - time) * pxPerUnit <= thresholdPx && (best === null || Math.abs(p - time) < Math.abs(best - time))) best = p;
2936
+ return best === null ? null : {
2937
+ time: best,
2938
+ point: best
2939
+ };
2940
+ }
2941
+ /** Round away float noise from adding steps (0.1 + 0.2). */
2942
+ var tidy = (n) => Math.round(n * 1e6) / 1e6;
2943
+ // src/components/timeline.tsx
2944
+ var HEADER_W = "w-40";
2945
+ var EDGE_PX = 8;
2946
+ var DRAG_THRESHOLD = 3;
2947
+ var defaultFormat = (t) => tickLabel(t, 1);
2948
+ /** Zoom state for a timeline: `zoomIn`, `zoomOut`, and `fit` to a viewport width. Pass `zoom` and `setZoom` as the timeline's `zoom` and `onZoomChange`. */
2949
+ function useTimelineZoom({ initial = 20, min = .5, max = 400 } = {}) {
2950
+ const [zoom, set] = React.useState(initial);
2951
+ const setZoom = React.useCallback((z) => set(clamp(z, min, max)), [min, max]);
2952
+ return {
2953
+ zoom,
2954
+ setZoom,
2955
+ zoomIn: () => setZoom(zoom * 1.5),
2956
+ zoomOut: () => setZoom(zoom / 1.5),
2957
+ /** Zoom so `duration` fills `viewportWidth` pixels. */
2958
+ fit: (viewportWidth, duration) => setZoom(viewportWidth / Math.max(duration, 1e-6))
2959
+ };
2960
+ }
2961
+ /** Zoom in, zoom out and fit, as named icon buttons for a timeline's toolbar. */
2962
+ function TimelineZoomControls({ zoom }) {
2963
+ return /* @__PURE__ */ jsxs("div", {
2964
+ className: "flex items-center gap-1",
2965
+ children: [
2966
+ /* @__PURE__ */ jsx(IconButton, {
2967
+ icon: ZoomOut,
2968
+ label: "Zoom out",
2969
+ hint: "-",
2970
+ onClick: zoom.zoomOut
2971
+ }),
2972
+ /* @__PURE__ */ jsx(IconButton, {
2973
+ icon: ZoomIn,
2974
+ label: "Zoom in",
2975
+ hint: "+",
2976
+ onClick: zoom.zoomIn
2977
+ }),
2978
+ /* @__PURE__ */ jsx(IconButton, {
2979
+ icon: Maximize2,
2980
+ label: "Fit to view",
2981
+ hint: "0",
2982
+ onClick: zoom.fit
2983
+ })
2984
+ ]
2985
+ });
2986
+ }
2987
+ /** A rule that refuses an item overlapping another in its lane, for `validate`: names the item in the way. */
2988
+ function noOverlap(items) {
2989
+ return (id, next) => {
2990
+ const me = items.find((i) => i.id === id);
2991
+ const other = items.find((i) => i.id !== id && i.lane === next.lane && i.start < next.start + next.length - 1e-9 && next.start < i.start + i.length - 1e-9);
2992
+ return other ? `${me?.label ?? "This"} would overlap ${other.label}.` : null;
2993
+ };
2994
+ }
2995
+ /** Items placed on a zoomable time axis in lanes, with a current-time rule and markers. Reports every move, trim, selection and time change; the app applies them. Keyboard-complete, and only the items near the view are rendered. */
2996
+ function Timeline({ label, lanes, items, from = 0, to, zoom, onZoomChange, position, onPositionChange, follow, markers = [], selectedIds, onSelect, onItemChange, onDelete, validate, snapPoints = [], snap = true, step = 1, minLength, renderItem, formatTime = defaultFormat, empty, className }) {
2997
+ const min = minLength ?? step;
2998
+ const scroller = React.useRef(null);
2999
+ const laneRefs = React.useRef(/* @__PURE__ */ new Map());
3000
+ const [view, setView] = React.useState({
3001
+ left: 0,
3002
+ width: 640
3003
+ });
3004
+ const [drag, setDrag] = React.useState(null);
3005
+ const dragRef = React.useRef(null);
3006
+ const [focusId, setFocusId] = React.useState(null);
3007
+ const [said, setSaid] = React.useState("");
3008
+ const refocus = React.useRef(null);
3009
+ const selected = selectedIds ?? /* @__PURE__ */ new Set();
3010
+ const laneIndex = React.useMemo(() => new Map(lanes.map((l, i) => [l.id, i])), [lanes]);
3011
+ const laneLabel = (id) => lanes.find((l) => l.id === id)?.label ?? id;
3012
+ const width = Math.max((to - from) * zoom, 1);
3013
+ const x = (t) => (t - from) * zoom;
3014
+ React.useEffect(() => {
3015
+ const el = scroller.current;
3016
+ if (!el) return;
3017
+ const read = () => setView({
3018
+ left: el.scrollLeft,
3019
+ width: el.clientWidth || 640
3020
+ });
3021
+ read();
3022
+ const ro = new ResizeObserver(read);
3023
+ ro.observe(el);
3024
+ el.addEventListener("scroll", read, { passive: true });
3025
+ return () => {
3026
+ ro.disconnect();
3027
+ el.removeEventListener("scroll", read);
3028
+ };
3029
+ }, []);
3030
+ React.useEffect(() => {
3031
+ const el = scroller.current;
3032
+ if (!follow || position === void 0 || !el) return;
3033
+ const px = x(position);
3034
+ if (px < el.scrollLeft || px > el.scrollLeft + el.clientWidth - 24) el.scrollLeft = Math.max(px - el.clientWidth * .25, 0);
3035
+ }, [
3036
+ follow,
3037
+ position,
3038
+ zoom
3039
+ ]);
3040
+ React.useEffect(() => {
3041
+ const id = refocus.current;
3042
+ if (!id) return;
3043
+ refocus.current = null;
3044
+ const el = scroller.current?.querySelector(`[data-item="${CSS.escape(id)}"]`);
3045
+ if (el && document.activeElement !== el && (!document.activeElement || document.activeElement === document.body || !scroller.current?.contains(document.activeElement))) el.focus();
3046
+ }, [items]);
3047
+ const sorted = React.useMemo(() => {
3048
+ const byLane = /* @__PURE__ */ new Map();
3049
+ for (const l of lanes) byLane.set(l.id, []);
3050
+ for (const i of items) byLane.get(i.lane)?.push(i);
3051
+ for (const list of byLane.values()) list.sort((a, b) => a.start - b.start);
3052
+ return byLane;
3053
+ }, [lanes, items]);
3054
+ const snapTimes = React.useMemo(() => {
3055
+ const pts = [...snapPoints, ...markers.map((m) => m.time)];
3056
+ if (position !== void 0) pts.push(position);
3057
+ return pts;
3058
+ }, [
3059
+ snapPoints,
3060
+ markers,
3061
+ position
3062
+ ]);
3063
+ /** Apply a change: validate, report, and say it. Returns the refusal, if any. */
3064
+ const commit = (item, next) => {
3065
+ const reason = validate?.(item.id, next) ?? null;
3066
+ if (reason) {
3067
+ setSaid(reason);
3068
+ return reason;
3069
+ }
3070
+ refocus.current = item.id;
3071
+ onItemChange?.(item.id, next);
3072
+ const where = next.lane !== item.lane ? `, ${laneLabel(next.lane)}` : "";
3073
+ setSaid(next.start !== item.start && next.length === item.length ? `${item.label} moved to ${formatTime(next.start)}${where}.` : next.lane !== item.lane ? `${item.label} moved to ${laneLabel(next.lane)}.` : `${item.label} now ${formatTime(next.start)} to ${formatTime(next.start + next.length)}.`);
3074
+ return null;
3075
+ };
3076
+ const select = (id, add) => {
3077
+ const next = add ? selected.has(id) ? [...selected].filter((s) => s !== id) : [...selected, id] : [id];
3078
+ onSelect?.(next);
3079
+ };
3080
+ const focusItem = (id) => {
3081
+ setFocusId(id);
3082
+ requestAnimationFrame(() => scroller.current?.querySelector(`[data-item="${CSS.escape(id)}"]`)?.focus());
3083
+ scroller.current?.querySelector(`[data-item="${CSS.escape(id)}"]`)?.focus();
3084
+ const item = items.find((i) => i.id === id);
3085
+ if (item && scroller.current) {
3086
+ const el = scroller.current;
3087
+ if (x(item.start) < el.scrollLeft) el.scrollLeft = x(item.start) - 16;
3088
+ else if (x(item.start + item.length) > el.scrollLeft + el.clientWidth) el.scrollLeft = x(item.start + item.length) - el.clientWidth + 16;
3089
+ }
3090
+ };
3091
+ const onItemKeyDown = (e, item) => {
3092
+ const k = e.key;
3093
+ const big = e.shiftKey ? 10 : 1;
3094
+ const lane = sorted.get(item.lane) ?? [];
3095
+ const idx = lane.findIndex((i) => i.id === item.id);
3096
+ const handled = () => {
3097
+ e.preventDefault();
3098
+ e.stopPropagation();
3099
+ };
3100
+ if (e.ctrlKey || e.metaKey) {
3101
+ if (k === "ArrowLeft" || k === "ArrowRight") {
3102
+ handled();
3103
+ const dir = k === "ArrowLeft" ? -1 : 1;
3104
+ commit(item, {
3105
+ start: clamp(tidy(item.start + dir * step * big), from, to - item.length),
3106
+ length: item.length,
3107
+ lane: item.lane
3108
+ });
3109
+ } else if (k === "ArrowUp" || k === "ArrowDown") {
3110
+ handled();
3111
+ const target = lanes[(laneIndex.get(item.lane) ?? 0) + (k === "ArrowUp" ? -1 : 1)];
3112
+ if (target) commit(item, {
3113
+ start: item.start,
3114
+ length: item.length,
3115
+ lane: target.id
3116
+ });
3117
+ return;
3118
+ }
3119
+ if (k !== "Enter" && k !== " ") return;
3120
+ }
3121
+ if (e.altKey && (k === "ArrowLeft" || k === "ArrowRight")) {
3122
+ handled();
3123
+ const dir = k === "ArrowLeft" ? -1 : 1;
3124
+ if (e.shiftKey) {
3125
+ const start = clamp(tidy(item.start + dir * step), from, item.start + item.length - min);
3126
+ commit(item, {
3127
+ start,
3128
+ length: tidy(item.start + item.length - start),
3129
+ lane: item.lane
3130
+ });
3131
+ } else commit(item, {
3132
+ start: item.start,
3133
+ length: clamp(tidy(item.length + dir * step), min, to - item.start),
3134
+ lane: item.lane
3135
+ });
3136
+ return;
3137
+ }
3138
+ switch (k) {
3139
+ case "ArrowLeft":
3140
+ handled();
3141
+ if (lane[idx - 1]) focusItem(lane[idx - 1].id);
3142
+ break;
3143
+ case "ArrowRight":
3144
+ handled();
3145
+ if (lane[idx + 1]) focusItem(lane[idx + 1].id);
3146
+ break;
3147
+ case "ArrowUp":
3148
+ case "ArrowDown": {
3149
+ handled();
3150
+ const neighbour = lanes[(laneIndex.get(item.lane) ?? 0) + (k === "ArrowUp" ? -1 : 1)];
3151
+ const nearest = (neighbour ? sorted.get(neighbour.id) ?? [] : []).reduce((best, c) => !best || Math.abs(c.start - item.start) < Math.abs(best.start - item.start) ? c : best, null);
3152
+ if (nearest) focusItem(nearest.id);
3153
+ break;
3154
+ }
3155
+ case "Home":
3156
+ handled();
3157
+ if (lane[0]) focusItem(lane[0].id);
3158
+ break;
3159
+ case "End":
3160
+ handled();
3161
+ if (lane.length) focusItem(lane[lane.length - 1].id);
3162
+ break;
3163
+ case "Enter":
3164
+ case " ":
3165
+ handled();
3166
+ select(item.id, e.shiftKey || e.ctrlKey || e.metaKey);
3167
+ break;
3168
+ case "Delete":
3169
+ case "Backspace": if (selected.size && onDelete) {
3170
+ handled();
3171
+ onDelete([...selected]);
3172
+ }
3173
+ }
3174
+ };
3175
+ const begin = (e, item, mode) => {
3176
+ if (e.button !== 0) return;
3177
+ e.stopPropagation();
3178
+ e.currentTarget.setPointerCapture?.(e.pointerId);
3179
+ const d = {
3180
+ id: item.id,
3181
+ mode,
3182
+ originX: e.clientX,
3183
+ origin: item,
3184
+ next: {
3185
+ start: item.start,
3186
+ length: item.length,
3187
+ lane: item.lane
3188
+ },
3189
+ reason: null,
3190
+ guide: null,
3191
+ moved: false
3192
+ };
3193
+ dragRef.current = d;
3194
+ setDrag(d);
3195
+ };
3196
+ const laneAt = (clientY, fallback) => {
3197
+ for (const [id, el] of laneRefs.current) {
3198
+ const r = el.getBoundingClientRect();
3199
+ if (clientY >= r.top && clientY < r.bottom) return id;
3200
+ }
3201
+ return fallback;
3202
+ };
3203
+ const onPointerMove = (e) => {
3204
+ const d = dragRef.current;
3205
+ if (!d) return;
3206
+ const dx = e.clientX - d.originX;
3207
+ if (!d.moved && Math.abs(dx) < DRAG_THRESHOLD && d.mode !== "move") return;
3208
+ const dt = dx / zoom;
3209
+ const o = d.origin;
3210
+ let next = {
3211
+ start: o.start,
3212
+ length: o.length,
3213
+ lane: o.lane
3214
+ };
3215
+ let guide = null;
3216
+ const edges = [...snapTimes, ...items.filter((i) => i.id !== o.id).flatMap((i) => [i.start, i.start + i.length])];
3217
+ const snapped = (t) => {
3218
+ const s = snap ? snapTo(t, edges, zoom) : null;
3219
+ if (s) guide = s.point;
3220
+ return s ? s.time : t;
3221
+ };
3222
+ if (d.mode === "move") {
3223
+ let start = o.start + dt;
3224
+ const a = snap ? snapTo(start, edges, zoom) : null;
3225
+ const b = snap ? snapTo(start + o.length, edges, zoom) : null;
3226
+ if (a && (!b || Math.abs(a.time - start) <= Math.abs(b.time - (start + o.length)))) {
3227
+ start = a.time;
3228
+ guide = a.point;
3229
+ } else if (b) {
3230
+ start = b.time - o.length;
3231
+ guide = b.point;
3232
+ }
3233
+ next = {
3234
+ start: clamp(tidy(start), from, to - o.length),
3235
+ length: o.length,
3236
+ lane: laneAt(e.clientY, o.lane)
3237
+ };
3238
+ } else if (d.mode === "end") next = {
3239
+ start: o.start,
3240
+ length: clamp(tidy(snapped(o.start + o.length + dt) - o.start), min, to - o.start),
3241
+ lane: o.lane
3242
+ };
3243
+ else {
3244
+ const start = clamp(tidy(snapped(o.start + dt)), from, o.start + o.length - min);
3245
+ next = {
3246
+ start,
3247
+ length: tidy(o.start + o.length - start),
3248
+ lane: o.lane
3249
+ };
3250
+ }
3251
+ const moved = d.moved || Math.abs(dx) >= DRAG_THRESHOLD || next.lane !== o.lane;
3252
+ const updated = {
3253
+ ...d,
3254
+ next,
3255
+ guide,
3256
+ moved,
3257
+ reason: moved ? validate?.(o.id, next) ?? null : null
3258
+ };
3259
+ dragRef.current = updated;
3260
+ setDrag(updated);
3261
+ };
3262
+ const onPointerUp = (e) => {
3263
+ const d = dragRef.current;
3264
+ dragRef.current = null;
3265
+ setDrag(null);
3266
+ if (!d) return;
3267
+ e.currentTarget.releasePointerCapture?.(e.pointerId);
3268
+ if (!d.moved) {
3269
+ if (d.mode === "move") select(d.id, e.shiftKey || e.ctrlKey || e.metaKey);
3270
+ return;
3271
+ }
3272
+ if (d.reason) setSaid(d.reason);
3273
+ else commit(d.origin, d.next);
3274
+ };
3275
+ const stepSize = tickStep(zoom);
3276
+ const ticks = React.useMemo(() => ticksBetween(from, to, stepSize), [
3277
+ from,
3278
+ to,
3279
+ stepSize
3280
+ ]);
3281
+ const setPosition = (t) => onPositionChange?.(clamp(tidy(t), from, to));
3282
+ const scrubTrack = React.useRef(null);
3283
+ const scrubInput = React.useRef(null);
3284
+ const spokenTime = React.useMemo(() => ({
3285
+ format: formatTime,
3286
+ formatRange: (a, b) => `${formatTime(a)} to ${formatTime(b)}`,
3287
+ resolvedOptions: () => ({ locale: "en-US" })
3288
+ }), [formatTime]);
3289
+ const scrubState = useSliderState({
3290
+ minValue: from,
3291
+ maxValue: Math.max(to, from + 1e-9),
3292
+ step: .001,
3293
+ value: [clamp(position ?? from, from, to)],
3294
+ onChange: ([t]) => setPosition(t),
3295
+ numberFormatter: spokenTime,
3296
+ isDisabled: position === void 0 || !onPositionChange
3297
+ });
3298
+ const { trackProps: rulerProps } = useSlider({
3299
+ "aria-label": "Current time",
3300
+ isDisabled: position === void 0 || !onPositionChange
3301
+ }, scrubState, scrubTrack);
3302
+ const { thumbProps, inputProps } = useSliderThumb({
3303
+ index: 0,
3304
+ trackRef: scrubTrack,
3305
+ inputRef: scrubInput,
3306
+ "aria-label": "Current time",
3307
+ isDisabled: position === void 0 || !onPositionChange
3308
+ }, scrubState);
3309
+ const { focusProps, isFocusVisible } = useFocusRing();
3310
+ const onSliderKey = (e) => {
3311
+ if (position === void 0) return;
3312
+ const big = e.shiftKey ? 10 : 1;
3313
+ const moves = {
3314
+ ArrowLeft: -step * big,
3315
+ ArrowDown: -step * big,
3316
+ ArrowRight: step * big,
3317
+ ArrowUp: step * big,
3318
+ PageDown: -step * 10,
3319
+ PageUp: step * 10
3320
+ };
3321
+ if (e.key in moves) setPosition(position + moves[e.key]);
3322
+ else if (e.key === "Home") setPosition(from);
3323
+ else if (e.key === "End") setPosition(to);
3324
+ else return;
3325
+ e.preventDefault();
3326
+ e.stopPropagation();
3327
+ };
3328
+ const onKeyDown = (e) => {
3329
+ if (!onZoomChange || e.ctrlKey || e.metaKey || e.altKey) return;
3330
+ if (e.key === "+" || e.key === "=") onZoomChange(zoom * 1.5);
3331
+ else if (e.key === "-") onZoomChange(zoom / 1.5);
3332
+ else if (e.key === "0") onZoomChange(view.width / Math.max(to - from, 1e-6));
3333
+ else return;
3334
+ e.preventDefault();
3335
+ };
3336
+ React.useEffect(() => {
3337
+ const el = scroller.current;
3338
+ if (!el || !onZoomChange) return;
3339
+ const onWheel = (e) => {
3340
+ if (!e.ctrlKey && !e.metaKey) return;
3341
+ e.preventDefault();
3342
+ onZoomChange(e.deltaY < 0 ? zoom * 1.25 : zoom / 1.25);
3343
+ };
3344
+ el.addEventListener("wheel", onWheel, { passive: false });
3345
+ return () => el.removeEventListener("wheel", onWheel);
3346
+ }, [onZoomChange, zoom]);
3347
+ const rovingId = focusId && items.some((i) => i.id === focusId) ? focusId : sorted.get(lanes[0]?.id ?? "")?.[0]?.id ?? items[0]?.id ?? null;
3348
+ const lo = view.left - view.width;
3349
+ const hi = view.left + 2 * view.width;
3350
+ const visible = (i) => i.id === focusId || i.id === rovingId || x(i.start + i.length) >= lo && x(i.start) <= hi;
3351
+ const itemLabel = (i) => `${i.label}, ${formatTime(i.start)} to ${formatTime(i.start + i.length)}, ${laneLabel(i.lane)}`;
3352
+ return /* @__PURE__ */ jsxs("div", {
3353
+ role: "group",
3354
+ "aria-label": label,
3355
+ onKeyDown,
3356
+ className: cn("min-w-0 text-foreground", className),
3357
+ children: [
3358
+ /* @__PURE__ */ jsx("p", {
3359
+ role: "status",
3360
+ className: "sr-only",
3361
+ children: said
3362
+ }),
3363
+ /* @__PURE__ */ jsxs("div", {
3364
+ className: "flex",
3365
+ children: [/* @__PURE__ */ jsxs("div", {
3366
+ className: cn("shrink-0 border-r border-border", HEADER_W),
3367
+ children: [/* @__PURE__ */ jsx("div", {
3368
+ className: "h-8 border-b border-border",
3369
+ "aria-hidden": true
3370
+ }), lanes.map((l) => /* @__PURE__ */ jsxs("div", {
3371
+ className: "flex h-(--control-h) items-center gap-1 border-b border-border px-2 type-label",
3372
+ children: [/* @__PURE__ */ jsx("span", {
3373
+ className: "min-w-0 flex-1 truncate",
3374
+ title: l.label,
3375
+ children: l.label
3376
+ }), l.header]
3377
+ }, l.id))]
3378
+ }), /* @__PURE__ */ jsx("div", {
3379
+ ref: scroller,
3380
+ className: "relative min-w-0 flex-1 overflow-x-auto",
3381
+ children: /* @__PURE__ */ jsxs("div", {
3382
+ className: "relative",
3383
+ style: { width },
3384
+ children: [
3385
+ /* @__PURE__ */ jsxs("div", {
3386
+ ...rulerProps,
3387
+ ref: scrubTrack,
3388
+ className: "relative h-8 touch-none border-b border-border",
3389
+ "data-ruler": true,
3390
+ children: [
3391
+ ticks.map((t) => {
3392
+ const px = x(t);
3393
+ const last = px > width - 40;
3394
+ return /* @__PURE__ */ jsx("span", {
3395
+ "aria-hidden": true,
3396
+ className: "absolute top-0 h-full border-l border-border pl-1 type-caption text-muted-foreground tabular-nums",
3397
+ style: {
3398
+ left: px,
3399
+ transform: last ? "translateX(-100%)" : void 0,
3400
+ borderLeftWidth: last ? 0 : 1,
3401
+ paddingRight: last ? 4 : 0
3402
+ },
3403
+ children: formatTime === defaultFormat ? tickLabel(t, stepSize) : formatTime(t)
3404
+ }, t);
3405
+ }),
3406
+ markers.map((m) => /* @__PURE__ */ jsx("button", {
3407
+ type: "button",
3408
+ "aria-label": `Marker: ${m.label}, ${formatTime(m.time)}`,
3409
+ onPointerDown: (e) => e.stopPropagation(),
3410
+ onMouseDown: (e) => e.stopPropagation(),
3411
+ onClick: () => setPosition(m.time),
3412
+ className: "absolute bottom-0 max-w-32 -translate-x-px truncate rounded-control border-l-2 border-foreground bg-muted px-1 type-caption",
3413
+ style: { left: x(m.time) },
3414
+ children: m.label
3415
+ }, m.id)),
3416
+ position !== void 0 && /* @__PURE__ */ jsxs("div", {
3417
+ ...thumbProps,
3418
+ className: cn("absolute top-0 -ml-2 h-full w-4 cursor-ew-resize", isFocusVisible && "outline-2 outline-offset-2 outline-ring"),
3419
+ style: { left: x(position) },
3420
+ children: [/* @__PURE__ */ jsx("span", {
3421
+ "aria-hidden": true,
3422
+ className: "mx-auto block size-3 rounded-pill bg-primary"
3423
+ }), /* @__PURE__ */ jsx(VisuallyHidden, { children: /* @__PURE__ */ jsx("input", {
3424
+ ref: scrubInput,
3425
+ ...mergeProps(inputProps, focusProps),
3426
+ "aria-labelledby": void 0,
3427
+ onKeyDownCapture: onSliderKey
3428
+ }) })]
3429
+ })
3430
+ ]
3431
+ }),
3432
+ lanes.length === 0 && /* @__PURE__ */ jsx("div", {
3433
+ className: "p-4",
3434
+ children: empty
3435
+ }),
3436
+ lanes.map((l) => /* @__PURE__ */ jsx("div", {
3437
+ role: "group",
3438
+ "aria-label": l.label,
3439
+ ref: (el) => void (el ? laneRefs.current.set(l.id, el) : laneRefs.current.delete(l.id)),
3440
+ className: "relative h-(--control-h) border-b border-border",
3441
+ children: (sorted.get(l.id) ?? []).filter(visible).map((item) => {
3442
+ const live = drag?.id === item.id && drag.moved ? drag : null;
3443
+ const shown = live ? live.next : item;
3444
+ const laneShift = live ? (laneIndex.get(live.next.lane) ?? 0) - (laneIndex.get(item.lane) ?? 0) : 0;
3445
+ const isSel = selected.has(item.id);
3446
+ const px = x(shown.start);
3447
+ const w = Math.max(shown.length * zoom, 4);
3448
+ return /* @__PURE__ */ jsxs("div", {
3449
+ "data-item": item.id,
3450
+ role: "button",
3451
+ "aria-pressed": isSel,
3452
+ "aria-label": itemLabel(item),
3453
+ tabIndex: item.id === rovingId ? 0 : -1,
3454
+ onFocus: () => setFocusId(item.id),
3455
+ onKeyDown: (e) => onItemKeyDown(e, item),
3456
+ onPointerDown: (e) => begin(e, item, "move"),
3457
+ onPointerMove,
3458
+ onPointerUp,
3459
+ className: cn("absolute top-1 bottom-1 min-w-1 cursor-grab touch-none overflow-hidden rounded-control border border-input border-t-4 bg-background px-1.5 type-caption select-none", isSel && "bg-muted font-medium outline-2 outline-offset-1 outline-primary", live?.reason && "border-dashed border-danger bg-danger-subtle"),
3460
+ style: {
3461
+ left: px,
3462
+ width: w,
3463
+ borderTopColor: item.kind ? kindColour(item.kind, items) : void 0,
3464
+ transform: laneShift ? `translateY(calc(var(--control-h) * ${laneShift}))` : void 0,
3465
+ zIndex: live ? 10 : void 0
3466
+ },
3467
+ children: [
3468
+ renderItem ? renderItem(item, {
3469
+ selected: isSel,
3470
+ width: w
3471
+ }) : /* @__PURE__ */ jsx(DefaultItem, {
3472
+ item,
3473
+ width: w
3474
+ }),
3475
+ /* @__PURE__ */ jsx("span", {
3476
+ "aria-hidden": true,
3477
+ className: "absolute inset-y-0 left-0 cursor-ew-resize touch-none",
3478
+ style: { width: EDGE_PX },
3479
+ onPointerDown: (e) => begin(e, item, "start"),
3480
+ onPointerMove,
3481
+ onPointerUp
3482
+ }),
3483
+ /* @__PURE__ */ jsx("span", {
3484
+ "aria-hidden": true,
3485
+ className: "absolute inset-y-0 right-0 cursor-ew-resize touch-none",
3486
+ style: { width: EDGE_PX },
3487
+ onPointerDown: (e) => begin(e, item, "end"),
3488
+ onPointerMove,
3489
+ onPointerUp
3490
+ })
3491
+ ]
3492
+ }, item.id);
3493
+ })
3494
+ }, l.id)),
3495
+ position !== void 0 && /* @__PURE__ */ jsx("div", {
3496
+ "aria-hidden": true,
3497
+ className: "pointer-events-none absolute top-8 bottom-0 w-0.5 bg-primary",
3498
+ style: { left: x(position) - 1 }
3499
+ }),
3500
+ drag?.moved && drag.guide !== null && /* @__PURE__ */ jsx("div", {
3501
+ "aria-hidden": true,
3502
+ className: "pointer-events-none absolute top-0 bottom-0 w-px bg-foreground",
3503
+ style: { left: x(drag.guide) }
3504
+ })
3505
+ ]
3506
+ })
3507
+ })]
3508
+ }),
3509
+ drag?.moved && /* @__PURE__ */ jsx("p", {
3510
+ "aria-hidden": true,
3511
+ className: "mt-1 flex items-center gap-1.5 type-body-sm tabular-nums text-muted-foreground",
3512
+ children: drag.reason ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(Ban, { className: "size-4 shrink-0 text-danger" }), /* @__PURE__ */ jsx("span", {
3513
+ className: "text-danger",
3514
+ children: drag.reason
3515
+ })] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
3516
+ formatTime(drag.next.start),
3517
+ " to ",
3518
+ formatTime(drag.next.start + drag.next.length),
3519
+ ", ",
3520
+ laneLabel(drag.next.lane)
3521
+ ] })
3522
+ })
3523
+ ]
3524
+ });
3525
+ }
3526
+ function kindColour(kind, items) {
3527
+ const kinds = [...new Set(items.map((i) => i.kind).filter(Boolean))];
3528
+ return `var(--chart-${Math.max(kinds.indexOf(kind), 0) % 5 + 1})`;
3529
+ }
3530
+ function DefaultItem({ item, width }) {
3531
+ return /* @__PURE__ */ jsxs("span", {
3532
+ className: "flex h-full min-w-0 items-center gap-1.5",
3533
+ children: [/* @__PURE__ */ jsx("span", {
3534
+ className: "min-w-0 flex-1 truncate",
3535
+ children: item.label
3536
+ }), item.kind && width > 120 && /* @__PURE__ */ jsx("span", {
3537
+ className: "shrink-0 text-muted-foreground",
3538
+ children: item.kind
3539
+ })]
3540
+ });
3541
+ }
3542
+ // src/components/sortable-list.tsx
3543
+ var KIND = "strata-kind/";
3544
+ var ID = "strata-item/id";
3545
+ var LIST = "strata-list/";
3546
+ /** A list that reorders by drag and by keyboard, and takes items from other lists by kind. It reports what was asked and never changes the data itself. */
3547
+ function SortableList({ label, items, getKey, getLabel, children, renderActions, empty, onReorder, onInsert, getKind = () => "item", accepts = [], refuses = {}, selectionMode = "none", selectedKeys, onSelectionChange, className }) {
3548
+ const listId = React.useId();
3549
+ const byKey = React.useMemo(() => new Map(items.map((i) => [getKey(i), i])), [items, getKey]);
3550
+ const [refused, setRefused] = React.useState(null);
3551
+ const root = React.useRef(null);
3552
+ React.useEffect(() => {
3553
+ if (!refused) return;
3554
+ const clear = () => setRefused(null);
3555
+ document.addEventListener("dragend", clear);
3556
+ document.addEventListener("drop", clear);
3557
+ return () => {
3558
+ document.removeEventListener("dragend", clear);
3559
+ document.removeEventListener("drop", clear);
3560
+ };
3561
+ }, [refused]);
3562
+ const toTarget = (t) => t.type === "root" ? {
3563
+ key: null,
3564
+ position: "root"
3565
+ } : {
3566
+ key: String(t.key),
3567
+ position: t.dropPosition
3568
+ };
3569
+ const { dragAndDropHooks } = useDragAndDrop({
3570
+ getItems: (keys) => [...keys].map((k) => {
3571
+ const item = byKey.get(String(k));
3572
+ return {
3573
+ [`${KIND}${item ? getKind(item) : "item"}`]: "",
3574
+ [`${LIST}${listId}`]: "",
3575
+ [ID]: String(k),
3576
+ "text/plain": item ? getLabel(item) : String(k)
3577
+ };
3578
+ }),
3579
+ acceptedDragTypes: "all",
3580
+ getDropOperation: (_target, types) => {
3581
+ if (types.has(`${LIST}${listId}`) || accepts.some((k) => types.has(`${KIND}${k}`))) {
3582
+ setRefused(null);
3583
+ return "move";
3584
+ }
3585
+ const kind = Object.keys(refuses).find((k) => types.has(`${KIND}${k}`));
3586
+ if (kind) setRefused(refuses[kind]);
3587
+ return "cancel";
3588
+ },
3589
+ onReorder: (e) => onReorder([...e.keys].map(String), toTarget(e.target)),
3590
+ onInsert: async (e) => {
3591
+ const ids = (await Promise.all(e.items.filter((i) => i.kind === "text").map((i) => i.getText(ID)))).filter(Boolean);
3592
+ onInsert?.(ids, toTarget(e.target));
3593
+ },
3594
+ onRootDrop: async (e) => {
3595
+ const ids = (await Promise.all(e.items.filter((i) => i.kind === "text").map((i) => i.getText(ID)))).filter(Boolean);
3596
+ onInsert?.(ids, {
3597
+ key: null,
3598
+ position: "root"
3599
+ });
3600
+ },
3601
+ renderDropIndicator: (target) => /* @__PURE__ */ jsx(DropIndicator, {
3602
+ target,
3603
+ className: ({ isDropTarget }) => cn("relative h-0 data-[drop-target]:after:absolute data-[drop-target]:after:inset-x-0 data-[drop-target]:after:-top-px data-[drop-target]:after:h-0.5 data-[drop-target]:after:rounded-pill data-[drop-target]:after:bg-primary", isDropTarget && "z-10")
3604
+ })
3605
+ });
3606
+ return /* @__PURE__ */ jsxs("div", {
3607
+ ref: root,
3608
+ className: cn("min-w-0", className),
3609
+ onDragLeaveCapture: (e) => !e.currentTarget.contains(e.relatedTarget) && setRefused(null),
3610
+ children: [/* @__PURE__ */ jsx(GridList, {
3611
+ "aria-label": label,
3612
+ items: items.map((item) => ({
3613
+ item,
3614
+ id: getKey(item)
3615
+ })),
3616
+ dragAndDropHooks,
3617
+ selectionMode,
3618
+ selectedKeys,
3619
+ onSelectionChange: (keys) => onSelectionChange?.(keys === "all" ? new Set(items.map(getKey)) : new Set([...keys].map(String))),
3620
+ renderEmptyState: ({ isDropTarget }) => /* @__PURE__ */ jsx("div", {
3621
+ className: cn("rounded-surface border border-dashed py-6 text-center", isDropTarget ? "border-solid border-primary bg-muted" : "border-input"),
3622
+ children: isDropTarget ? /* @__PURE__ */ jsx("p", {
3623
+ className: "type-body",
3624
+ children: "Drop here"
3625
+ }) : empty
3626
+ }),
3627
+ className: ({ isDropTarget }) => cn("grid divide-y divide-border border-y border-border", isDropTarget && "outline-2 outline-offset-2 outline-primary"),
3628
+ children: ({ item }) => /* @__PURE__ */ jsxs(GridListItem, {
3629
+ id: getKey(item),
3630
+ textValue: getLabel(item),
3631
+ className: "group relative flex min-h-(--control-h) cursor-default items-center gap-2 py-1 pr-1 pl-1 outline-none data-[focus-visible]:outline-2 data-[focus-visible]:-outline-offset-2 data-[focus-visible]:outline-ring data-[selected]:bg-muted data-[selected]:before:absolute data-[selected]:before:inset-y-1 data-[selected]:before:left-0 data-[selected]:before:w-0.5 data-[selected]:before:rounded-pill data-[selected]:before:bg-primary data-[dragging]:opacity-50",
3632
+ children: [
3633
+ /* @__PURE__ */ jsx(Button$1, {
3634
+ slot: "drag",
3635
+ className: "grid size-(--control-h-sm) shrink-0 cursor-grab place-items-center rounded-control text-muted-foreground hover:bg-muted data-[focus-visible]:outline-2 data-[focus-visible]:outline-ring",
3636
+ children: /* @__PURE__ */ jsx(GripVertical, {
3637
+ "aria-hidden": true,
3638
+ className: "size-4"
3639
+ })
3640
+ }),
3641
+ /* @__PURE__ */ jsx("div", {
3642
+ className: "min-w-0 flex-1",
3643
+ children: children(item)
3644
+ }),
3645
+ renderActions && /* @__PURE__ */ jsx("div", {
3646
+ className: "flex shrink-0 items-center gap-1",
3647
+ children: renderActions(item)
3648
+ })
3649
+ ]
3650
+ })
3651
+ }), refused && /* @__PURE__ */ jsxs("p", {
3652
+ role: "status",
3653
+ className: "mt-2 flex items-start gap-1.5 type-body-sm text-danger",
3654
+ children: [/* @__PURE__ */ jsx(Ban, {
3655
+ "aria-hidden": true,
3656
+ className: "mt-0.5 size-4 shrink-0"
3657
+ }), refused]
3658
+ })]
3659
+ });
3660
+ }
2877
3661
  // src/components/file-intake.tsx
2878
3662
  /** The picker as a button. `children` is its visible name ("Add files"); `accept` narrows what the dialog shows. */
2879
3663
  function FileButton({ accept, multiple = false, onFiles, icon: Icon, children, ...props }) {
@@ -5558,6 +6342,6 @@ function CompareGrid({ label, items, blind, missing, actions, columns = 3, keys
5558
6342
  })
5559
6343
  });
5560
6344
  }
5561
- export { ActiveList, Alert, AlertDialog, AppShell, AsyncButton, Breadcrumb, BulkBar, Button, COLOR_SCHEME_STORAGE_KEY, Checkbox, ChoiceGroup, ColorField, ColorSchemeChoice, CommandLegend, CommandMenu, Compare, CompareGrid, CompositionBar, ContextMenu, DEFAULT_TOLERANCE, DataTable, DataView, Dialog, Disclosure, Done, EmptyState, FIT, Field, FileButton, FileDropZone, FileOutcomes, FullscreenFrame, HttpError, IconButton, InfiniteList, Input, Inspector, InspectorSection, JobStatus, KeysLegend, LineChart, LinkCard, LinkCardList, LoadError, LoadMore, MAX_SCALE, MAX_SIDE, MIN_SCALE, MISSING, Menu, Meter, Metric, MetricStrip, MissingFile, NBSP, NativeSelect, NumberField, PageHeader, Popover, PropertyList, PropertyRow, RowAction, SelectableGrid, SideNav, Skeleton, Slider, StaleNotice, Status, StrataQueryProvider, StrataToastRegion, Switch, TableSkeleton, Tabs, Textarea, ThemeProvider, Thumbnail, ThumbnailSkeleton, Toggle, ToggleGroup, Toolbar, ToolbarSeparator, Tooltip, UndoBar, ViewportFrame, VirtualList, actualPixelsScale, buttonVariants, canFullscreen, clampViewport, cn, colorSchemeScript, commandShortcut, createFormat, createQueryClient, crossedThreshold, describeActionError, describeHttpError, detectPlatform, differences, fetchJson, fieldErrorsOf, format, formatChord, isReservedChord, isTypingTarget, labelOf, matchesAccept, matchesChord, parseChord, parseSort, readErrorBody, readPixels, resample, serialiseSort, staleOf, toDate, toLoad, toast, toastTimeout, typeSteps, useActiveItem, useAsyncAction, useClientWork, useColorScheme, useCommands, useDifference, useExpanded, useFileIntake, useHotkeys, useInView, useInfiniteLoad, useJob, useLoad, useSelection, useSystemColorScheme, useUndoable, useViewport, zoomAt };
6345
+ export { ActiveList, Alert, AlertDialog, AppShell, AsyncButton, Breadcrumb, BulkBar, Button, COLOR_SCHEME_STORAGE_KEY, Checkbox, ChoiceGroup, ColorField, ColorSchemeChoice, CommandLegend, CommandMenu, Compare, CompareGrid, CompositionBar, ContextMenu, DEFAULT_TOLERANCE, DataTable, DataView, Dialog, Disclosure, Done, EmptyState, FIT, Field, FileButton, FileDropZone, FileOutcomes, FullscreenFrame, HttpError, IconButton, InfiniteList, Input, Inspector, InspectorSection, JobStatus, KeysLegend, LineChart, LinkCard, LinkCardList, LoadError, LoadMore, MAX_SCALE, MAX_SIDE, MIN_SCALE, MISSING, Menu, Meter, Metric, MetricStrip, MissingFile, NBSP, NativeSelect, NumberField, PageHeader, Popover, PropertyList, PropertyRow, RowAction, SelectableGrid, SideNav, Skeleton, Slider, SortableList, StaleNotice, Status, StrataQueryProvider, StrataToastRegion, Switch, TableSkeleton, Tabs, Textarea, ThemeProvider, Thumbnail, ThumbnailSkeleton, Timeline, TimelineZoomControls, Toggle, ToggleGroup, Toolbar, ToolbarSeparator, Tooltip, UndoBar, ViewportFrame, VirtualList, actualPixelsScale, buttonVariants, canFullscreen, clampViewport, cn, colorSchemeScript, commandShortcut, createFormat, createQueryClient, crossedThreshold, describeActionError, describeHttpError, detectPlatform, differences, fetchJson, fieldErrorsOf, format, formatChord, isReservedChord, isTypingTarget, labelOf, matchesAccept, matchesChord, noOverlap, parseChord, parseSort, readErrorBody, readPixels, resample, serialiseSort, staleOf, tickLabel, tickStep, ticksBetween, toDate, toLoad, toast, toastTimeout, typeSteps, useActiveItem, useAsyncAction, useClientWork, useColorScheme, useCommands, useDifference, useExpanded, useFileIntake, useHotkeys, useInView, useInfiniteLoad, useJob, useLoad, useSelection, useSystemColorScheme, useTimelineZoom, useUndoable, useViewport, zoomAt };
5562
6346
 
5563
6347
  //# sourceMappingURL=index.js.map