strata-react 1.0.6 → 1.0.7
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 +1 -0
- package/dist/components/file-intake.d.ts +40 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +301 -3
- package/dist/index.js.map +1 -1
- package/dist/lib/file-intake.d.ts +60 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -134,6 +134,7 @@ function KilnRoom() {
|
|
|
134
134
|
| Overlays | `Dialog`, `DialogProps`, `AlertDialog`, `Popover`, `Tooltip` | React Aria underneath. A dialog always has a title and, via `actions`'s close render prop, a way out; `closable={false}` while work cannot stop; `placement="end"` is a sheet. `AlertDialog` is the only confirm: required verb on the confirm button, Cancel focused first, no outside dismiss, stays open with the reason when an async confirm fails. `Popover` needs a `label`. `Tooltip` opens on hover and focus and `IconButton` uses it. All portal onto the `layer-*` stacking utilities |
|
|
135
135
|
| Value controls | `NumberField`, `Slider`, `ColorField` | Set a number or colour precisely, inside `Field`. `NumberField` and `Slider` are React Aria's; the number field runs with `commitBehavior="validate"`, so a typed value outside `min`/`max` is kept on screen, explained in the `Field` ("Enter a value from 0% to 500%.") and never passed to `onChange`. A value that is not known is `null` and shows an en dash, never 0 or NaN. Digits and decimal mark follow `locale`. The unit sits inside the control, and in the slider's spoken value when `Intl` has it (%, °, ms, s, kB, MB, GB, kbps, Mbps). Arrows step, Home/End jump to the limits; `Slider editable` adds a number field. `ColorField`: platform picker, typed hex that is normalised, app suggestions, and a contrast note against `against`. No motion on value changes |
|
|
136
136
|
| Notices and progress | `Alert`, `toast`, `StrataToastRegion`, `useClientWork`, `JobStatus` | Three weights. A `toast` confirms finished work and goes by itself (5 s plus 40 ms a character, 8 s minimum with an action, paused under the pointer or focus, always dismissable); it has no danger tone, because an error a person must act on is an inline `Alert` with its recovery as `action` (`announce` makes it `role="alert"` only when it answers something the person just did). `StrataToastRegion` goes once at the app root. `useClientWork` runs browser work with progress, cancel (aborts its `signal`, ends `cancelled`, never `failed`) and a double-start guard; `JobStatus` shows it exactly as it shows a server job, with `onCancel`, `cancelled` and `onDismiss` |
|
|
137
|
+
| File intake | `FileButton`, `FileDropZone`, `FileOutcomes`, `MissingFile`, `useFileIntake` | Pick or drop local files, then one outcome per file. `FileButton` is React Aria's `FileTrigger` behind a real named button (the keyboard and phone route); `FileDropZone` is its `DropZone` and says what it takes while a drag is over it. `useFileIntake({ accept, acceptLabel, process })` judges each file after the drop, so a wrong one is named with its reason (type, `maxBytes`, your `check`), runs your own `process` per file (a throw becomes `Failed` with its message and a retry), and never blocks the rest. `FileOutcomes` draws the rows and announces one summary per batch. `MissingFile` is a status word and a "Relink" that opens the picker for that item. Nothing assumes a server |
|
|
137
138
|
| Inspector | `Inspector`, `InspectorSection`, `PropertyRow`, `PropertyList` | Properties of the selected thing. `Inspector` is a labelled region with the selection's name as its heading and the empty state (`empty`, required) when `title` is `null`; `selectionKey` gives a new selection fresh controls and keeps focus in the panel. `InspectorSection` is React Aria's `Disclosure` with the body mounted only while open; open and closed are remembered under `storageKey` (storage that throws just means defaults). `PropertyRow` is a `Field` with a "Reset <label>" that shows only while `modified`. `PropertyList` is a `dl`: missing values print an en dash heard as "Not known", units follow a non-breaking space, long values truncate with the whole value in a tooltip |
|
|
138
139
|
| Feedback | `UndoBar`, `useUndoable`, `Done` | Undo before confirm; the hook owns which rows are out of view (`isRemoved`), a failed commit brings the row back with Try again in the same bar, and `flush()` commits before a dependent action; `Done` is the one celebration, and it must say what happens next |
|
|
139
140
|
| Helpers | `cn`, `format`, `createFormat`, `NBSP` | `cn` knows `type-*`; all numbers and dates through `Intl`; `format.integer(n)`, `.decimal(n)`, `.percent(n)` are callable and keep Intl's methods; `format.bytes(n, unit?)` writes sizes in decimal units (`byteUnit` shares one unit across figures); `format.date(at)` ("8 Nov 2026") and `format.dateTime(at)` ("8 Nov 2026, 06:05"), like `clock`, `day` and `shortDay`, take a Date, ISO string or epoch ms; `format.ago(at, now?)` ("3 weeks ago"), `format.compact(n)` ("1.2k", and `count(n, one, many, { compact: true })`), `format.runningTime(seconds)` ("1:02:09") and `format.share(n)` ("<1%" for a part that rounds to 0); every number and date formatter prints the placeholder (`format.missing`, an en dash) for `null` or `undefined`; `createFormat(locale, { timeZone, missing })` fixes the zone and the placeholder; units and counts join with a non-breaking space |
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { FileIntake } from '../lib/file-intake';
|
|
2
|
+
import { IconComponent } from '../lib/icon';
|
|
3
|
+
import { ButtonProps } from './button';
|
|
4
|
+
import * as React from "react";
|
|
5
|
+
/** The picker as a button. `children` is its visible name ("Add files"); `accept` narrows what the dialog shows. */
|
|
6
|
+
export declare function FileButton({ accept, multiple, onFiles, icon: Icon, children, ...props }: Omit<ButtonProps, "onChange" | "children"> & {
|
|
7
|
+
/** What the dialog offers: extensions (`.gpx`), exact types or families (`video/*`). */
|
|
8
|
+
accept: readonly string[];
|
|
9
|
+
multiple?: boolean;
|
|
10
|
+
/** Called with the files chosen. Not called when the dialog is cancelled. */
|
|
11
|
+
onFiles: (files: File[]) => void;
|
|
12
|
+
icon?: IconComponent;
|
|
13
|
+
children: string;
|
|
14
|
+
}): React.JSX.Element;
|
|
15
|
+
/** A region that takes dropped files and offers the picker as its keyboard alternative. */
|
|
16
|
+
export declare function FileDropZone({ onFiles, acceptLabel, title, disabled, children, className, }: {
|
|
17
|
+
onFiles: (files: File[]) => void;
|
|
18
|
+
/** What it takes, in words ("a video, an audio file or a GPX track"). Shown while a drag is over it. */
|
|
19
|
+
acceptLabel: string;
|
|
20
|
+
/** The resting prompt ("Drag files here"). */
|
|
21
|
+
title: string;
|
|
22
|
+
disabled?: boolean;
|
|
23
|
+
/** The `FileButton` (required in practice: it is how a keyboard or phone gets files in). */
|
|
24
|
+
children?: React.ReactNode;
|
|
25
|
+
className?: string;
|
|
26
|
+
}): React.JSX.Element;
|
|
27
|
+
/** One row per file offered: its name, a status word, and for a rejected or failed file the reason and (for failed) a retry. Announces a summary politely when a batch finishes. */
|
|
28
|
+
export declare function FileOutcomes({ intake, className }: {
|
|
29
|
+
intake: FileIntake;
|
|
30
|
+
className?: string;
|
|
31
|
+
}): React.JSX.Element;
|
|
32
|
+
/** A saved item whose file is gone: the item's name, a "File missing" status (a word and an icon) and a "Relink" button that opens the picker for this one item. */
|
|
33
|
+
export declare function MissingFile({ name, accept, onRelink, className, }: {
|
|
34
|
+
/** The item's name as the person knows it ("run-02.mp4"). */
|
|
35
|
+
name: string;
|
|
36
|
+
accept: readonly string[];
|
|
37
|
+
/** Called with the file the person chose to stand in for it. */
|
|
38
|
+
onRelink: (file: File) => void;
|
|
39
|
+
className?: string;
|
|
40
|
+
}): React.JSX.Element;
|
package/dist/index.d.ts
CHANGED
|
@@ -34,6 +34,8 @@ export { useClientWork, type ClientWork, type WorkContext, type WorkPhase } from
|
|
|
34
34
|
export { JobStatus, type JobStatusProps, type JobFailure, type JobWords } from './components/job-status';
|
|
35
35
|
export { Thumbnail, ThumbnailSkeleton, type ThumbnailProps, type AspectRatio } from './components/thumbnail';
|
|
36
36
|
export { DataTable, TableSkeleton, parseSort, serialiseSort, type CellValue, type Column, type Sort, type DataTableProps, type RowSelection, type RowExpansion, } from './components/data-table';
|
|
37
|
+
export { FileButton, FileDropZone, FileOutcomes, MissingFile } from './components/file-intake';
|
|
38
|
+
export { useFileIntake, matchesAccept, type FileIntake, type FileIntakeOptions, type FileOutcome } from './lib/file-intake';
|
|
37
39
|
export { Inspector, InspectorSection, PropertyRow, PropertyList, type InspectorProps, type InspectorSectionProps, type PropertyRowProps, type Property, type PropertyListProps } from './components/inspector';
|
|
38
40
|
export { Disclosure, useExpanded, type DisclosureProps, type DisclosureOpenProps, type Expanded, type ExpandedOptions } from './components/disclosure';
|
|
39
41
|
export { BulkBar, useSelection, type InitialSelection } from './components/selection';
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
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, 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, 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";
|
|
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, History, ImageOff, Info, LoaderCircle, Maximize, Minimize, Minus, RotateCcw, Scan, Search, Trash2, TriangleAlert, X, ZoomIn, ZoomOut } from "lucide-react";
|
|
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";
|
|
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";
|
|
@@ -2874,6 +2874,304 @@ function TableSkeleton({ rows = 4, columns = 5 }) {
|
|
|
2874
2874
|
}, r))]
|
|
2875
2875
|
});
|
|
2876
2876
|
}
|
|
2877
|
+
// src/components/file-intake.tsx
|
|
2878
|
+
/** The picker as a button. `children` is its visible name ("Add files"); `accept` narrows what the dialog shows. */
|
|
2879
|
+
function FileButton({ accept, multiple = false, onFiles, icon: Icon, children, ...props }) {
|
|
2880
|
+
return /* @__PURE__ */ jsx(FileTrigger, {
|
|
2881
|
+
acceptedFileTypes: accept,
|
|
2882
|
+
allowsMultiple: multiple,
|
|
2883
|
+
onSelect: (list) => {
|
|
2884
|
+
const files = list ? Array.from(list) : [];
|
|
2885
|
+
if (files.length) onFiles(files);
|
|
2886
|
+
},
|
|
2887
|
+
children: /* @__PURE__ */ jsxs(Button, {
|
|
2888
|
+
...props,
|
|
2889
|
+
children: [Icon && /* @__PURE__ */ jsx(Icon, { "aria-hidden": true }), children]
|
|
2890
|
+
})
|
|
2891
|
+
});
|
|
2892
|
+
}
|
|
2893
|
+
/** A region that takes dropped files and offers the picker as its keyboard alternative. */
|
|
2894
|
+
function FileDropZone({ onFiles, acceptLabel, title, disabled, children, className }) {
|
|
2895
|
+
const onDrop = async (e) => {
|
|
2896
|
+
const items = e.items.filter((i) => i.kind === "file");
|
|
2897
|
+
const files = await Promise.all(items.map((i) => i.getFile()));
|
|
2898
|
+
if (files.length) onFiles(files);
|
|
2899
|
+
};
|
|
2900
|
+
return /* @__PURE__ */ jsx(DropZone, {
|
|
2901
|
+
"aria-label": title,
|
|
2902
|
+
isDisabled: disabled,
|
|
2903
|
+
onDrop,
|
|
2904
|
+
className: ({ isDropTarget, isFocusVisible }) => cn("grid min-w-0 justify-items-center gap-2 rounded-surface border border-dashed border-input px-4 py-6 text-center", isDropTarget && "border-solid border-primary bg-muted", isFocusVisible && "outline-2 outline-offset-2 outline-ring", className),
|
|
2905
|
+
children: ({ isDropTarget }) => /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
2906
|
+
/* @__PURE__ */ jsx(Upload, {
|
|
2907
|
+
"aria-hidden": true,
|
|
2908
|
+
className: "size-5 text-muted-foreground"
|
|
2909
|
+
}),
|
|
2910
|
+
/* @__PURE__ */ jsx("p", {
|
|
2911
|
+
className: "type-body",
|
|
2912
|
+
children: isDropTarget ? `Drop to add ${acceptLabel}` : title
|
|
2913
|
+
}),
|
|
2914
|
+
children
|
|
2915
|
+
] })
|
|
2916
|
+
});
|
|
2917
|
+
}
|
|
2918
|
+
var rowStatus = {
|
|
2919
|
+
processing: {
|
|
2920
|
+
tone: "info",
|
|
2921
|
+
word: "Adding…",
|
|
2922
|
+
icon: Loader
|
|
2923
|
+
},
|
|
2924
|
+
added: {
|
|
2925
|
+
tone: "success",
|
|
2926
|
+
word: "Added",
|
|
2927
|
+
icon: CircleCheck
|
|
2928
|
+
},
|
|
2929
|
+
rejected: {
|
|
2930
|
+
tone: "warning",
|
|
2931
|
+
word: "Not added",
|
|
2932
|
+
icon: CircleAlert
|
|
2933
|
+
},
|
|
2934
|
+
failed: {
|
|
2935
|
+
tone: "danger",
|
|
2936
|
+
word: "Failed",
|
|
2937
|
+
icon: CircleAlert
|
|
2938
|
+
}
|
|
2939
|
+
};
|
|
2940
|
+
/** One row per file offered: its name, a status word, and for a rejected or failed file the reason and (for failed) a retry. Announces a summary politely when a batch finishes. */
|
|
2941
|
+
function FileOutcomes({ intake, className }) {
|
|
2942
|
+
const { outcomes, retry, dismiss, pending } = intake;
|
|
2943
|
+
const [summary, setSummary] = React.useState("");
|
|
2944
|
+
const announced = React.useRef(/* @__PURE__ */ new Set());
|
|
2945
|
+
React.useEffect(() => {
|
|
2946
|
+
if (pending > 0) return;
|
|
2947
|
+
const fresh = outcomes.filter((o) => !announced.current.has(o.id));
|
|
2948
|
+
if (!fresh.length) return;
|
|
2949
|
+
for (const o of fresh) announced.current.add(o.id);
|
|
2950
|
+
const added = fresh.filter((o) => o.status === "added").length;
|
|
2951
|
+
const problems = fresh.length - added;
|
|
2952
|
+
setSummary([added && `${added} added`, problems && `${problems} not added`].filter(Boolean).join(", "));
|
|
2953
|
+
}, [pending, outcomes]);
|
|
2954
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
2955
|
+
className: cn("min-w-0", className),
|
|
2956
|
+
children: [/* @__PURE__ */ jsx("p", {
|
|
2957
|
+
role: "status",
|
|
2958
|
+
className: "sr-only",
|
|
2959
|
+
children: summary
|
|
2960
|
+
}), outcomes.length > 0 && /* @__PURE__ */ jsx("ul", {
|
|
2961
|
+
className: "grid divide-y divide-border border-y border-border",
|
|
2962
|
+
children: outcomes.map((o) => {
|
|
2963
|
+
const s = rowStatus[o.status];
|
|
2964
|
+
const reason = o.status === "rejected" || o.status === "failed" ? o.reason : void 0;
|
|
2965
|
+
return /* @__PURE__ */ jsxs("li", {
|
|
2966
|
+
className: "grid gap-1 py-2",
|
|
2967
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
2968
|
+
className: "flex items-center gap-3",
|
|
2969
|
+
children: [
|
|
2970
|
+
/* @__PURE__ */ jsx("span", {
|
|
2971
|
+
className: "min-w-0 flex-1 truncate type-body",
|
|
2972
|
+
title: o.name,
|
|
2973
|
+
children: o.name
|
|
2974
|
+
}),
|
|
2975
|
+
/* @__PURE__ */ jsx(Status, {
|
|
2976
|
+
tone: s.tone,
|
|
2977
|
+
icon: s.icon,
|
|
2978
|
+
children: s.word
|
|
2979
|
+
}),
|
|
2980
|
+
o.status === "failed" && /* @__PURE__ */ jsx(RowAction, {
|
|
2981
|
+
label: "Try again",
|
|
2982
|
+
subject: o.name,
|
|
2983
|
+
onClick: () => retry(o.id)
|
|
2984
|
+
}),
|
|
2985
|
+
o.status !== "processing" && /* @__PURE__ */ jsx(IconButton, {
|
|
2986
|
+
icon: X,
|
|
2987
|
+
label: `Dismiss ${o.name}`,
|
|
2988
|
+
onClick: () => dismiss(o.id)
|
|
2989
|
+
})
|
|
2990
|
+
]
|
|
2991
|
+
}), reason && /* @__PURE__ */ jsx("p", {
|
|
2992
|
+
className: "type-body-sm text-muted-foreground",
|
|
2993
|
+
children: reason
|
|
2994
|
+
})]
|
|
2995
|
+
}, o.id);
|
|
2996
|
+
})
|
|
2997
|
+
})]
|
|
2998
|
+
});
|
|
2999
|
+
}
|
|
3000
|
+
/** A saved item whose file is gone: the item's name, a "File missing" status (a word and an icon) and a "Relink" button that opens the picker for this one item. */
|
|
3001
|
+
function MissingFile({ name, accept, onRelink, className }) {
|
|
3002
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
3003
|
+
className: cn("flex min-w-0 items-center gap-3", className),
|
|
3004
|
+
children: [
|
|
3005
|
+
/* @__PURE__ */ jsx("span", {
|
|
3006
|
+
className: "min-w-0 flex-1 truncate type-body",
|
|
3007
|
+
title: name,
|
|
3008
|
+
children: name
|
|
3009
|
+
}),
|
|
3010
|
+
/* @__PURE__ */ jsx(Status, {
|
|
3011
|
+
tone: "warning",
|
|
3012
|
+
icon: FileQuestion,
|
|
3013
|
+
children: "File missing"
|
|
3014
|
+
}),
|
|
3015
|
+
/* @__PURE__ */ jsx(FileButton, {
|
|
3016
|
+
accept,
|
|
3017
|
+
variant: "ghost",
|
|
3018
|
+
size: "sm",
|
|
3019
|
+
"aria-label": `Relink ${name}`,
|
|
3020
|
+
onFiles: ([file]) => onRelink(file),
|
|
3021
|
+
children: "Relink"
|
|
3022
|
+
})
|
|
3023
|
+
]
|
|
3024
|
+
});
|
|
3025
|
+
}
|
|
3026
|
+
// src/lib/file-intake.ts
|
|
3027
|
+
/** Whether a file matches one entry of an `accept` list: extension, exact type or `family/*`, ignoring case. */
|
|
3028
|
+
function matchesAccept(file, accept) {
|
|
3029
|
+
const name = file.name.toLowerCase();
|
|
3030
|
+
const type = file.type.toLowerCase();
|
|
3031
|
+
return accept.some((entry) => {
|
|
3032
|
+
const a = entry.trim().toLowerCase();
|
|
3033
|
+
if (a.startsWith(".")) return name.endsWith(a);
|
|
3034
|
+
if (a.endsWith("/*")) return type.startsWith(a.slice(0, -1));
|
|
3035
|
+
return type === a;
|
|
3036
|
+
});
|
|
3037
|
+
}
|
|
3038
|
+
var MB = 1048576;
|
|
3039
|
+
var sizeWords = (bytes) => bytes >= MB ? `${(bytes / MB).toFixed(bytes >= 100 * MB ? 0 : 1)} MB` : `${Math.max(1, Math.round(bytes / 1024))} kB`;
|
|
3040
|
+
/** Per-file outcomes for files picked or dropped: type and size checks with a named reason, the app's own `process` per file, retry and dismiss. */
|
|
3041
|
+
function useFileIntake(options) {
|
|
3042
|
+
const [outcomes, setOutcomes] = React.useState([]);
|
|
3043
|
+
const opts = React.useRef(options);
|
|
3044
|
+
opts.current = options;
|
|
3045
|
+
const files = React.useRef(/* @__PURE__ */ new Map());
|
|
3046
|
+
const controllers = React.useRef(/* @__PURE__ */ new Map());
|
|
3047
|
+
const counter = React.useRef(0);
|
|
3048
|
+
const alive = React.useRef(true);
|
|
3049
|
+
const patch = React.useCallback((id, next) => {
|
|
3050
|
+
setOutcomes((all) => all.map((o) => o.id === id ? next(o) : o));
|
|
3051
|
+
}, []);
|
|
3052
|
+
const run = React.useCallback((id, file) => {
|
|
3053
|
+
const controller = new AbortController();
|
|
3054
|
+
controllers.current.set(id, controller);
|
|
3055
|
+
const base = {
|
|
3056
|
+
id,
|
|
3057
|
+
name: file.name,
|
|
3058
|
+
size: file.size
|
|
3059
|
+
};
|
|
3060
|
+
patch(id, () => ({
|
|
3061
|
+
...base,
|
|
3062
|
+
status: "processing"
|
|
3063
|
+
}));
|
|
3064
|
+
Promise.resolve().then(() => opts.current.process?.(file, { signal: controller.signal })).then(() => !controller.signal.aborted && patch(id, () => ({
|
|
3065
|
+
...base,
|
|
3066
|
+
status: "added"
|
|
3067
|
+
})), (error) => {
|
|
3068
|
+
if (controller.signal.aborted) return;
|
|
3069
|
+
const reason = error instanceof Error && error.message ? error.message : `${file.name} could not be added. Try again.`;
|
|
3070
|
+
patch(id, () => ({
|
|
3071
|
+
...base,
|
|
3072
|
+
status: "failed",
|
|
3073
|
+
reason
|
|
3074
|
+
}));
|
|
3075
|
+
}).finally(() => controllers.current.delete(id));
|
|
3076
|
+
}, [patch]);
|
|
3077
|
+
const start = React.useCallback((id, file) => {
|
|
3078
|
+
const base = {
|
|
3079
|
+
id,
|
|
3080
|
+
name: file.name,
|
|
3081
|
+
size: file.size
|
|
3082
|
+
};
|
|
3083
|
+
patch(id, () => ({
|
|
3084
|
+
...base,
|
|
3085
|
+
status: "processing"
|
|
3086
|
+
}));
|
|
3087
|
+
Promise.resolve().then(() => opts.current.check?.(file)).then((reason) => {
|
|
3088
|
+
if (!alive.current || !files.current.has(id)) return;
|
|
3089
|
+
if (reason) {
|
|
3090
|
+
files.current.delete(id);
|
|
3091
|
+
patch(id, () => ({
|
|
3092
|
+
...base,
|
|
3093
|
+
status: "rejected",
|
|
3094
|
+
reason
|
|
3095
|
+
}));
|
|
3096
|
+
} else run(id, file);
|
|
3097
|
+
}, (error) => {
|
|
3098
|
+
if (!alive.current || !files.current.has(id)) return;
|
|
3099
|
+
const reason = error instanceof Error && error.message ? error.message : `${file.name} could not be checked. Try again.`;
|
|
3100
|
+
patch(id, () => ({
|
|
3101
|
+
...base,
|
|
3102
|
+
status: "failed",
|
|
3103
|
+
reason
|
|
3104
|
+
}));
|
|
3105
|
+
});
|
|
3106
|
+
}, [patch, run]);
|
|
3107
|
+
const add = React.useCallback((offered) => {
|
|
3108
|
+
const list = Array.from(offered);
|
|
3109
|
+
const { accept, acceptLabel, multiple = true, maxBytes } = opts.current;
|
|
3110
|
+
list.forEach((file, index) => {
|
|
3111
|
+
const id = `f${++counter.current}`;
|
|
3112
|
+
const base = {
|
|
3113
|
+
id,
|
|
3114
|
+
name: file.name,
|
|
3115
|
+
size: file.size
|
|
3116
|
+
};
|
|
3117
|
+
const reject = (reason) => setOutcomes((all) => [...all, {
|
|
3118
|
+
...base,
|
|
3119
|
+
status: "rejected",
|
|
3120
|
+
reason
|
|
3121
|
+
}]);
|
|
3122
|
+
if (!multiple && index > 0) return reject(`${file.name} was not added: this takes one file at a time.`);
|
|
3123
|
+
if (!matchesAccept(file, accept)) return reject(`${file.name} is not a type this accepts. Add ${acceptLabel}.`);
|
|
3124
|
+
if (maxBytes !== void 0 && file.size > maxBytes) return reject(`${file.name} is ${sizeWords(file.size)}, over the ${sizeWords(maxBytes)} limit.`);
|
|
3125
|
+
files.current.set(id, file);
|
|
3126
|
+
setOutcomes((all) => [...all, {
|
|
3127
|
+
...base,
|
|
3128
|
+
status: "processing"
|
|
3129
|
+
}]);
|
|
3130
|
+
start(id, file);
|
|
3131
|
+
});
|
|
3132
|
+
}, [patch, start]);
|
|
3133
|
+
const dismiss = React.useCallback((id) => {
|
|
3134
|
+
controllers.current.get(id)?.abort();
|
|
3135
|
+
controllers.current.delete(id);
|
|
3136
|
+
files.current.delete(id);
|
|
3137
|
+
setOutcomes((all) => all.filter((o) => o.id !== id));
|
|
3138
|
+
}, []);
|
|
3139
|
+
const retry = React.useCallback((id) => {
|
|
3140
|
+
const file = files.current.get(id);
|
|
3141
|
+
if (file) start(id, file);
|
|
3142
|
+
}, [start]);
|
|
3143
|
+
const clear = React.useCallback(() => {
|
|
3144
|
+
setOutcomes((all) => {
|
|
3145
|
+
for (const o of all) if (o.status !== "processing") files.current.delete(o.id);
|
|
3146
|
+
return all.filter((o) => o.status === "processing");
|
|
3147
|
+
});
|
|
3148
|
+
}, []);
|
|
3149
|
+
React.useEffect(() => {
|
|
3150
|
+
alive.current = true;
|
|
3151
|
+
const live = controllers.current;
|
|
3152
|
+
return () => {
|
|
3153
|
+
alive.current = false;
|
|
3154
|
+
for (const c of live.values()) c.abort();
|
|
3155
|
+
live.clear();
|
|
3156
|
+
};
|
|
3157
|
+
}, []);
|
|
3158
|
+
const pending = outcomes.filter((o) => o.status === "processing").length;
|
|
3159
|
+
return React.useMemo(() => ({
|
|
3160
|
+
outcomes,
|
|
3161
|
+
add,
|
|
3162
|
+
retry,
|
|
3163
|
+
dismiss,
|
|
3164
|
+
clear,
|
|
3165
|
+
pending
|
|
3166
|
+
}), [
|
|
3167
|
+
outcomes,
|
|
3168
|
+
add,
|
|
3169
|
+
retry,
|
|
3170
|
+
dismiss,
|
|
3171
|
+
clear,
|
|
3172
|
+
pending
|
|
3173
|
+
]);
|
|
3174
|
+
}
|
|
2877
3175
|
// src/components/inspector.tsx
|
|
2878
3176
|
function readRemembered(key) {
|
|
2879
3177
|
if (!key) return {};
|
|
@@ -5260,6 +5558,6 @@ function CompareGrid({ label, items, blind, missing, actions, columns = 3, keys
|
|
|
5260
5558
|
})
|
|
5261
5559
|
});
|
|
5262
5560
|
}
|
|
5263
|
-
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, 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, 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, matchesChord, parseChord, parseSort, readErrorBody, readPixels, resample, serialiseSort, staleOf, toDate, toLoad, toast, toastTimeout, typeSteps, useActiveItem, useAsyncAction, useClientWork, useColorScheme, useCommands, useDifference, useExpanded, useHotkeys, useInView, useInfiniteLoad, useJob, useLoad, useSelection, useSystemColorScheme, useUndoable, useViewport, zoomAt };
|
|
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 };
|
|
5264
5562
|
|
|
5265
5563
|
//# sourceMappingURL=index.js.map
|