@particle-academy/react-fancy 6.6.1 → 6.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -0
- package/README.md +1 -0
- package/dist/chunk-5WMVBFBD.js +3 -0
- package/dist/{chunk-VXHFR5MV.js.map → chunk-5WMVBFBD.js.map} +1 -1
- package/dist/chunk-7STOB5MB.cjs +4 -0
- package/dist/{chunk-O5IO7TCO.cjs.map → chunk-7STOB5MB.cjs.map} +1 -1
- package/dist/chunk-LY3RQB3H.js +139 -0
- package/dist/chunk-LY3RQB3H.js.map +1 -0
- package/dist/{chunk-JEHV7PYP.js → chunk-SCGTO3PX.js} +21 -5
- package/dist/chunk-SCGTO3PX.js.map +1 -0
- package/dist/chunk-XBFTO64U.cjs +141 -0
- package/dist/chunk-XBFTO64U.cjs.map +1 -0
- package/dist/{chunk-AGO4AA3K.cjs → chunk-XHUV3VSM.cjs} +21 -5
- package/dist/chunk-XHUV3VSM.cjs.map +1 -0
- package/dist/file-upload.cjs +3 -3
- package/dist/file-upload.d.cts +17 -2
- package/dist/file-upload.d.ts +17 -2
- package/dist/file-upload.js +1 -1
- package/dist/index.cjs +9 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/dist/inputs.cjs +6 -1
- package/dist/inputs.d.cts +1 -0
- package/dist/inputs.d.ts +1 -0
- package/dist/inputs.js +2 -1
- package/dist/number-field.cjs +30 -0
- package/dist/number-field.cjs.map +1 -0
- package/dist/number-field.d.cts +48 -0
- package/dist/number-field.d.ts +48 -0
- package/dist/number-field.js +21 -0
- package/dist/number-field.js.map +1 -0
- package/docs/FileUpload.md +32 -2
- package/docs/Input.md +2 -0
- package/docs/NumberField.md +85 -0
- package/package.json +11 -1
- package/dist/chunk-AGO4AA3K.cjs.map +0 -1
- package/dist/chunk-JEHV7PYP.js.map +0 -1
- package/dist/chunk-O5IO7TCO.cjs +0 -4
- package/dist/chunk-VXHFR5MV.js +0 -3
package/CHANGELOG.md
CHANGED
|
@@ -11,6 +11,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
11
11
|
|
|
12
12
|
## [Unreleased]
|
|
13
13
|
|
|
14
|
+
## [6.7.1] - 2026-11-03
|
|
15
|
+
|
|
16
|
+
### Security
|
|
17
|
+
|
|
18
|
+
- **`NumberField` reads a very long run of digits in linear time.** Its number pattern could backtrack badly, so a very long pasted string could freeze the tab. Every number it accepted is still accepted. **Consumer action:** update if you use `NumberField`, which is new in 6.7.0.
|
|
19
|
+
|
|
20
|
+
## [6.7.0] - 2026-11-03
|
|
21
|
+
|
|
22
|
+
### Added
|
|
23
|
+
|
|
24
|
+
- **`FileUpload` reports what it refuses: `onReject(rejections)`.** A file failing `accept` or `maxSize`, the overflow past `maxFiles`, and the extra files of a batch dropped on a `multiple={false}` field were all dropped in silence, leaving a host nothing to tell the person with. Each entry is plain JSON (`{ name, size, type, reason }`, with `reason` one of `"accept"`, `"maxSize"`, `"maxFiles"`), one per file under the first rule it failed. It covers the picker, a drop and `useFileUpload().addFiles`, fires after `onChange`, and does not fire when nothing was refused. New types: `FileRejection`, `FileRejectionReason`. **Consumer action:** none. Nothing changes unless you pass it.
|
|
25
|
+
- **`NumberField`: a numeric field whose value is `number | null`.** Blank is `null`, never `0`. Partial text (`-`, `.`, `1e`) and unreadable text (`0x10`, `1,000`) are `null`, never a wrong number. The mouse wheel does not change it. `min` and `max` stop the arrow keys and report a typed value outside them as invalid through native form validation, without rewriting it. A declared `step` moves the arrow keys and makes off-grid values invalid. Takes a unit through the existing `suffix` prop, posts the number (not the text) under `name`, and has a `./number-field` subpath. **Consumer action:** none. `<Input type="number">` is unchanged.
|
|
26
|
+
|
|
14
27
|
## [6.6.1] - 2026-11-03
|
|
15
28
|
|
|
16
29
|
### Fixed
|
package/README.md
CHANGED
|
@@ -103,6 +103,7 @@ npx vite build # Build demo app (verifies imports work)
|
|
|
103
103
|
| Checkbox / CheckboxGroup | Checkbox inputs | [docs](docs/Checkbox.md) |
|
|
104
104
|
| RadioGroup | Radio button group | [docs](docs/RadioGroup.md) |
|
|
105
105
|
| Switch | Toggle switch | [docs](docs/Switch.md) |
|
|
106
|
+
| NumberField | Numeric input with a `number \| null` value: blank stays null, partial text never emits a wrong number, no wheel changes | [docs](docs/NumberField.md) |
|
|
106
107
|
| Slider | Range slider (single and range modes) | [docs](docs/Slider.md) |
|
|
107
108
|
| MultiSwitch | Segmented toggle between multiple options | [docs](docs/MultiSwitch.md) |
|
|
108
109
|
| DatePicker | Date selection (single and range modes) | [docs](docs/DatePicker.md) |
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":"","file":"chunk-
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"chunk-5WMVBFBD.js"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":"","file":"chunk-
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"chunk-7STOB5MB.cjs"}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { Input } from './chunk-PJNUGSKI.js';
|
|
2
|
+
import { useControllableState } from './chunk-EDYAXGUM.js';
|
|
3
|
+
import { forwardRef, useState, useRef, useEffect } from 'react';
|
|
4
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
5
|
+
|
|
6
|
+
var NUMBER = /^[+-]?(\d+(\.\d*)?|\.\d+)([eE][+-]?\d+)?$/;
|
|
7
|
+
var WHOLE = /^[+-]?\d+$/;
|
|
8
|
+
function parseNumber(text) {
|
|
9
|
+
const trimmed = text.trim();
|
|
10
|
+
if (!NUMBER.test(trimmed)) return null;
|
|
11
|
+
const n = Number(trimmed);
|
|
12
|
+
if (!Number.isFinite(n)) return null;
|
|
13
|
+
if (WHOLE.test(trimmed) && !Number.isSafeInteger(n)) return null;
|
|
14
|
+
return n === 0 ? 0 : n;
|
|
15
|
+
}
|
|
16
|
+
function formatNumber(value) {
|
|
17
|
+
return value === null ? "" : String(value);
|
|
18
|
+
}
|
|
19
|
+
function decimals(n) {
|
|
20
|
+
const [mantissa, exponent] = String(n).split("e");
|
|
21
|
+
const places = (mantissa.split(".")[1] ?? "").length - Number(exponent ?? 0);
|
|
22
|
+
return Math.min(Math.max(places, 0), 100);
|
|
23
|
+
}
|
|
24
|
+
function stepped(current, direction, min, max, step) {
|
|
25
|
+
const base = min ?? 0;
|
|
26
|
+
const places = Math.max(decimals(step), decimals(base));
|
|
27
|
+
const at = (k2) => Number((base + k2 * step).toFixed(places));
|
|
28
|
+
const position = ((current ?? 0) - base) / step;
|
|
29
|
+
const nudge = 1e-9;
|
|
30
|
+
let k = direction === 1 ? Math.floor(position + nudge) + 1 : Math.ceil(position - nudge) - 1;
|
|
31
|
+
if (max !== void 0 && at(k) > max) k = Math.floor((max - base) / step + nudge);
|
|
32
|
+
if (min !== void 0 && at(k) < min) k = 0;
|
|
33
|
+
return at(k);
|
|
34
|
+
}
|
|
35
|
+
var NumberField = forwardRef(
|
|
36
|
+
({
|
|
37
|
+
value,
|
|
38
|
+
defaultValue = null,
|
|
39
|
+
onValueChange,
|
|
40
|
+
min,
|
|
41
|
+
max,
|
|
42
|
+
step,
|
|
43
|
+
messages,
|
|
44
|
+
name,
|
|
45
|
+
form,
|
|
46
|
+
inputMode,
|
|
47
|
+
onKeyDown,
|
|
48
|
+
onBlur,
|
|
49
|
+
...rest
|
|
50
|
+
}, ref) => {
|
|
51
|
+
const [held, setValue] = useControllableState(
|
|
52
|
+
value,
|
|
53
|
+
defaultValue,
|
|
54
|
+
onValueChange
|
|
55
|
+
);
|
|
56
|
+
const current = typeof held === "number" && Number.isFinite(held) ? held : null;
|
|
57
|
+
const [text, setText] = useState(() => formatNumber(current));
|
|
58
|
+
if (parseNumber(text) !== current && text !== formatNumber(current)) {
|
|
59
|
+
setText(formatNumber(current));
|
|
60
|
+
}
|
|
61
|
+
const stepSize = typeof step === "number" && step > 0 ? step : 1;
|
|
62
|
+
const problem = (() => {
|
|
63
|
+
if (text.trim() !== "" && parseNumber(text) === null) {
|
|
64
|
+
return messages?.invalid ?? "Enter a number.";
|
|
65
|
+
}
|
|
66
|
+
if (current === null) return "";
|
|
67
|
+
if (min !== void 0 && current < min) return messages?.min ?? `Must be at least ${min}.`;
|
|
68
|
+
if (max !== void 0 && current > max) return messages?.max ?? `Must be at most ${max}.`;
|
|
69
|
+
if (typeof step === "number" && step > 0) {
|
|
70
|
+
const position = (current - (min ?? 0)) / step;
|
|
71
|
+
if (Math.abs(position - Math.round(position)) > 1e-9) {
|
|
72
|
+
return messages?.step ?? `Must be in steps of ${step}.`;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return "";
|
|
76
|
+
})();
|
|
77
|
+
const inputRef = useRef(null);
|
|
78
|
+
useEffect(() => {
|
|
79
|
+
inputRef.current?.setCustomValidity(problem);
|
|
80
|
+
});
|
|
81
|
+
const handleKeyDown = (e) => {
|
|
82
|
+
onKeyDown?.(e);
|
|
83
|
+
if (e.defaultPrevented || rest.disabled || rest.readOnly) return;
|
|
84
|
+
if (e.key !== "ArrowUp" && e.key !== "ArrowDown") return;
|
|
85
|
+
e.preventDefault();
|
|
86
|
+
const next = stepped(current, e.key === "ArrowUp" ? 1 : -1, min, max, stepSize);
|
|
87
|
+
setText(formatNumber(next));
|
|
88
|
+
if (next !== current) setValue(next);
|
|
89
|
+
};
|
|
90
|
+
return /* @__PURE__ */ jsxs("div", { "data-react-fancy-number-field": "", children: [
|
|
91
|
+
/* @__PURE__ */ jsx(
|
|
92
|
+
Input,
|
|
93
|
+
{
|
|
94
|
+
"aria-invalid": problem ? true : void 0,
|
|
95
|
+
"aria-valuemax": max,
|
|
96
|
+
"aria-valuemin": min,
|
|
97
|
+
"aria-valuenow": current ?? void 0,
|
|
98
|
+
inputMode: inputMode ?? // A numeric or decimal keypad has no minus sign on iOS, so those are
|
|
99
|
+
// only offered where a negative number cannot be valid.
|
|
100
|
+
(min !== void 0 && min >= 0 ? typeof step === "number" && Number.isInteger(step) ? "numeric" : "decimal" : "text"),
|
|
101
|
+
role: "spinbutton",
|
|
102
|
+
...rest,
|
|
103
|
+
ref: (el) => {
|
|
104
|
+
inputRef.current = el;
|
|
105
|
+
if (typeof ref === "function") ref(el);
|
|
106
|
+
else if (ref) ref.current = el;
|
|
107
|
+
},
|
|
108
|
+
type: "text",
|
|
109
|
+
value: text,
|
|
110
|
+
onValueChange: (next) => {
|
|
111
|
+
setText(next);
|
|
112
|
+
const parsed = parseNumber(next);
|
|
113
|
+
if (parsed !== current) setValue(parsed);
|
|
114
|
+
},
|
|
115
|
+
onKeyDown: handleKeyDown,
|
|
116
|
+
onBlur: (e) => {
|
|
117
|
+
setText(formatNumber(current));
|
|
118
|
+
onBlur?.(e);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
),
|
|
122
|
+
name ? /* @__PURE__ */ jsx(
|
|
123
|
+
"input",
|
|
124
|
+
{
|
|
125
|
+
type: "hidden",
|
|
126
|
+
name,
|
|
127
|
+
form,
|
|
128
|
+
disabled: rest.disabled,
|
|
129
|
+
value: formatNumber(current)
|
|
130
|
+
}
|
|
131
|
+
) : null
|
|
132
|
+
] });
|
|
133
|
+
}
|
|
134
|
+
);
|
|
135
|
+
NumberField.displayName = "NumberField";
|
|
136
|
+
|
|
137
|
+
export { NumberField };
|
|
138
|
+
//# sourceMappingURL=chunk-LY3RQB3H.js.map
|
|
139
|
+
//# sourceMappingURL=chunk-LY3RQB3H.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/components/inputs/NumberField/NumberField.tsx"],"names":["k"],"mappings":";;;;;AASA,IAAM,MAAA,GAAS,2CAAA;AACf,IAAM,KAAA,GAAQ,YAAA;AAGd,SAAS,YAAY,IAAA,EAA6B;AAChD,EAAA,MAAM,OAAA,GAAU,KA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A,CAAS,OAAA,GAAU,EAAA;AACnB,YAAA,IAAI,OAAO,GAAA,KAAQ,UAAA,EAAY,GAAA,CAAI,EAAE,CAAA;AAAA,iBAAA,IAC5B,GAAA,MAAS,OAAA,GAAU,EAAA;AAAA,UAC9B,CAAA;AAAA,UAIA,IAAA,EAAK,MAAA;AAAA,UACL,KAAA,EAAO,IAAA;AAAA,UACP,aAAA,EAAe,CAAC,IAAA,KAAS;AACvB,YAAA,OAAA,CAAQ,IAAI,CAAA;AACZ,YAAA,MAAM,MAAA,GAAS,YAAY,IAAI,CAAA;AAC/B,YAAA,IAAI,MAAA,KAAW,OAAA,EAAS,QAAA,CAAS,MAAM,CAAA;AAAA,UACzC,CAAA;AAAA,UACA,SAAA,EAAW,aAAA;AAAA,UACX,MAAA,EAAQ,CAAC,CAAA,KAAM;AACb,YAAA,OAAA,CAAQ,YAAA,CAAa,OAAO,CAAC,CAAA;AAC7B,YAAA,MAAA,GAAS,CAAC,CAAA;AAAA,UACZ;AAAA;AAAA,OACF;AAAA,MAEC,IAAA,mBACC,GAAA;AAAA,QAAC,OAAA;AAAA,QAAA;AAAA,UACC,IAAA,EAAK,QAAA;AAAA,UACL,IAAA;AAAA,UACA,IAAA;AAAA,UACA,UAAU,IAAA,CAAK,QAAA;AAAA,UACf,KAAA,EAAO,aAAa,OAAO;AAAA;AAAA,OAC7B,GACE;AAAA,KAAA,EACN,CAAA;AAAA,EAEJ;AACF;AAEA,WAAA,CAAY,WAAA,GAAc,aAAA","file":"chunk-LY3RQB3H.js","sourcesContent":["import { forwardRef, useEffect, useRef, useState, type KeyboardEvent } from \"react\";\nimport { useControllableState } from \"../../../hooks/use-controllable-state\";\nimport { Input } from \"../Input\";\nimport type { NumberFieldProps } from \"./NumberField.types\";\n\n/**\n * Plain decimal notation only. `Number()` alone is not safe here: it reads \"0x10\"\n * as 16 and \"Infinity\" as a number, and those are wrong numbers to emit.\n */\nconst NUMBER = /^[+-]?(\\d+(\\.\\d*)?|\\.\\d+)([eE][+-]?\\d+)?$/;\nconst WHOLE = /^[+-]?\\d+$/;\n\n/** The number the text says, or `null` if it does not say one. */\nfunction parseNumber(text: string): number | null {\n const trimmed = text.trim();\n if (!NUMBER.test(trimmed)) return null;\n\n const n = Number(trimmed);\n if (!Number.isFinite(n)) return null;\n // Past 2^53 a whole number rounds to a different one than was typed.\n if (WHOLE.test(trimmed) && !Number.isSafeInteger(n)) return null;\n\n return n === 0 ? 0 : n; // -0 is 0\n}\n\nfunction formatNumber(value: number | null): string {\n return value === null ? \"\" : String(value);\n}\n\n/** Decimal places in a number, so stepping can round away floating-point dust. */\nfunction decimals(n: number): number {\n const [mantissa, exponent] = String(n).split(\"e\");\n const places = (mantissa.split(\".\")[1] ?? \"\").length - Number(exponent ?? 0);\n return Math.min(Math.max(places, 0), 100);\n}\n\nfunction stepped(\n current: number | null,\n direction: 1 | -1,\n min: number | undefined,\n max: number | undefined,\n step: number,\n): number {\n const base = min ?? 0;\n const places = Math.max(decimals(step), decimals(base));\n const at = (k: number) => Number((base + k * step).toFixed(places));\n const position = ((current ?? 0) - base) / step;\n const nudge = 1e-9;\n\n // The next grid line in that direction, so an off-grid value lands on the grid.\n let k =\n direction === 1\n ? Math.floor(position + nudge) + 1\n : Math.ceil(position - nudge) - 1;\n\n if (max !== undefined && at(k) > max) k = Math.floor((max - base) / step + nudge);\n if (min !== undefined && at(k) < min) k = 0;\n\n return at(k);\n}\n\nexport const NumberField = forwardRef<HTMLInputElement, NumberFieldProps>(\n (\n {\n value,\n defaultValue = null,\n onValueChange,\n min,\n max,\n step,\n messages,\n name,\n form,\n inputMode,\n onKeyDown,\n onBlur,\n ...rest\n },\n ref,\n ) => {\n const [held, setValue] = useControllableState<number | null>(\n value,\n defaultValue,\n onValueChange,\n );\n // A host's NaN or Infinity has no text form, so it reads as no number.\n const current = typeof held === \"number\" && Number.isFinite(held) ? held : null;\n\n /*\n * The text is held apart from the number because \"1.\" and \"-\" have no number\n * that displays them. It only moves on its own when the number moved to\n * something the text does not say: a change from outside, or a parent refusing\n * this one.\n */\n const [text, setText] = useState(() => formatNumber(current));\n if (parseNumber(text) !== current && text !== formatNumber(current)) {\n setText(formatNumber(current));\n }\n\n const stepSize = typeof step === \"number\" && step > 0 ? step : 1;\n\n const problem = (() => {\n if (text.trim() !== \"\" && parseNumber(text) === null) {\n return messages?.invalid ?? \"Enter a number.\";\n }\n if (current === null) return \"\";\n if (min !== undefined && current < min) return messages?.min ?? `Must be at least ${min}.`;\n if (max !== undefined && current > max) return messages?.max ?? `Must be at most ${max}.`;\n if (typeof step === \"number\" && step > 0) {\n const position = (current - (min ?? 0)) / step;\n if (Math.abs(position - Math.round(position)) > 1e-9) {\n return messages?.step ?? `Must be in steps of ${step}.`;\n }\n }\n return \"\";\n })();\n\n // The text input has no min/max/step of its own, so a form learns of them here.\n // Runs every render: click-to-edit mounts a fresh input.\n const inputRef = useRef<HTMLInputElement | null>(null);\n useEffect(() => {\n inputRef.current?.setCustomValidity(problem);\n });\n\n const handleKeyDown = (e: KeyboardEvent<HTMLInputElement>) => {\n onKeyDown?.(e);\n if (e.defaultPrevented || rest.disabled || rest.readOnly) return;\n if (e.key !== \"ArrowUp\" && e.key !== \"ArrowDown\") return;\n\n e.preventDefault(); // or the caret jumps to the end of the text\n const next = stepped(current, e.key === \"ArrowUp\" ? 1 : -1, min, max, stepSize);\n setText(formatNumber(next));\n if (next !== current) setValue(next);\n };\n\n return (\n <div data-react-fancy-number-field=\"\">\n <Input\n aria-invalid={problem ? true : undefined}\n aria-valuemax={max}\n aria-valuemin={min}\n aria-valuenow={current ?? undefined}\n inputMode={\n inputMode ??\n // A numeric or decimal keypad has no minus sign on iOS, so those are\n // only offered where a negative number cannot be valid.\n (min !== undefined && min >= 0\n ? typeof step === \"number\" && Number.isInteger(step)\n ? \"numeric\"\n : \"decimal\"\n : \"text\")\n }\n role=\"spinbutton\"\n {...rest}\n ref={(el) => {\n inputRef.current = el;\n if (typeof ref === \"function\") ref(el);\n else if (ref) ref.current = el;\n }}\n // Text, not `number`: a browser reports \"-\" and \"1e\" in a number input as\n // an empty value, indistinguishable from blank, and turns the wheel into\n // a value change on a focused field. Neither applies to a text input.\n type=\"text\"\n value={text}\n onValueChange={(next) => {\n setText(next);\n const parsed = parseNumber(next);\n if (parsed !== current) setValue(parsed);\n }}\n onKeyDown={handleKeyDown}\n onBlur={(e) => {\n setText(formatNumber(current));\n onBlur?.(e);\n }}\n />\n {/* What a native submit posts: the number, never the half-typed text. */}\n {name ? (\n <input\n type=\"hidden\"\n name={name}\n form={form}\n disabled={rest.disabled}\n value={formatNumber(current)}\n />\n ) : null}\n </div>\n );\n },\n);\n\nNumberField.displayName = \"NumberField\";\n"]}
|
|
@@ -201,10 +201,14 @@ function matchesAccept(file, accept) {
|
|
|
201
201
|
return type === rule;
|
|
202
202
|
});
|
|
203
203
|
}
|
|
204
|
+
function rejection(file, reason) {
|
|
205
|
+
return { name: file.name, size: file.size, type: file.type, reason };
|
|
206
|
+
}
|
|
204
207
|
function FileUploadRoot({
|
|
205
208
|
children,
|
|
206
209
|
value,
|
|
207
210
|
onChange,
|
|
211
|
+
onReject,
|
|
208
212
|
accept,
|
|
209
213
|
multiple = true,
|
|
210
214
|
maxFiles,
|
|
@@ -217,25 +221,37 @@ function FileUploadRoot({
|
|
|
217
221
|
const addFiles = useCallback(
|
|
218
222
|
(newFiles) => {
|
|
219
223
|
let toAdd = Array.from(newFiles);
|
|
224
|
+
const rejections = [];
|
|
225
|
+
const keepOnly = (passes, reason) => {
|
|
226
|
+
toAdd = toAdd.filter((f) => {
|
|
227
|
+
if (passes(f)) return true;
|
|
228
|
+
rejections.push(rejection(f, reason));
|
|
229
|
+
return false;
|
|
230
|
+
});
|
|
231
|
+
};
|
|
220
232
|
if (accept) {
|
|
221
|
-
|
|
233
|
+
keepOnly((f) => matchesAccept(f, accept), "accept");
|
|
222
234
|
}
|
|
223
235
|
if (maxSize) {
|
|
224
|
-
|
|
236
|
+
keepOnly((f) => f.size <= maxSize, "maxSize");
|
|
225
237
|
}
|
|
226
238
|
if (multiple === false) {
|
|
227
239
|
const replacement = toAdd.slice(0, 1);
|
|
228
240
|
const next = replacement.length > 0 ? replacement : files;
|
|
241
|
+
for (const f of toAdd.slice(1)) rejections.push(rejection(f, "maxFiles"));
|
|
229
242
|
if (value === void 0) setInternalFiles(next);
|
|
230
243
|
onChange?.(next);
|
|
244
|
+
if (rejections.length > 0) onReject?.(rejections);
|
|
231
245
|
return;
|
|
232
246
|
}
|
|
233
247
|
const updated = [...files, ...toAdd];
|
|
234
248
|
const limited = maxFiles ? updated.slice(0, maxFiles) : updated;
|
|
249
|
+
for (const f of updated.slice(limited.length)) rejections.push(rejection(f, "maxFiles"));
|
|
235
250
|
if (value === void 0) setInternalFiles(limited);
|
|
236
251
|
onChange?.(limited);
|
|
252
|
+
if (rejections.length > 0) onReject?.(rejections);
|
|
237
253
|
},
|
|
238
|
-
[accept, files, maxFiles, maxSize, multiple, onChange, value]
|
|
254
|
+
[accept, files, maxFiles, maxSize, multiple, onChange, onReject, value]
|
|
239
255
|
);
|
|
240
256
|
const removeFile = useCallback(
|
|
241
257
|
(index) => {
|
|
@@ -257,5 +273,5 @@ var FileUpload = Object.assign(FileUploadRoot, {
|
|
|
257
273
|
});
|
|
258
274
|
|
|
259
275
|
export { FileUpload, useFileUpload };
|
|
260
|
-
//# sourceMappingURL=chunk-
|
|
261
|
-
//# sourceMappingURL=chunk-
|
|
276
|
+
//# sourceMappingURL=chunk-SCGTO3PX.js.map
|
|
277
|
+
//# sourceMappingURL=chunk-SCGTO3PX.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/components/FileUpload/FileUpload.context.ts","../src/components/FileUpload/FileUploadDropzone.tsx","../src/components/FileUpload/FileUploadList.tsx","../src/components/FileUpload/matchesAccept.ts","../src/components/FileUpload/FileUpload.tsx"],"names":["jsxs","jsx","useState","useCallback","useMemo"],"mappings":";;;;;AAGO,IAAM,iBAAA,GACX,cAA6C,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AO,QAAA,EAAU,UAAA,EAAY,QAAA,EAAU,QAAQ,QAAQ;AAAA,GAC1D;AAEA,EAAA,uBACEH,GAAAA,CAAC,iBAAA,CAAkB,QAAA,EAAlB,EAA2B,OAAO,GAAA,EACjC,QAAA,kBAAAA,GAAAA,CAAC,KAAA,EAAA,EAAI,gCAA6B,EAAA,EAAG,SAAA,EAAW,GAAG,SAAS,CAAA,EAAI,UAAS,CAAA,EAC3E,CAAA;AAEJ;AAEO,IAAM,UAAA,GAAa,MAAA,CAAO,MAAA,CAAO,cAAA,EAAgB;AAAA,EACtD,QAAA,EAAU,kBAAA;AAAA,EACV,IAAA,EAAM;AACR,CAAC","file":"chunk-SCGTO3PX.js","sourcesContent":["import { createContext, useContext } from \"react\";\nimport type { FileUploadContextValue } from \"./FileUpload.types\";\n\nexport const FileUploadContext =\n createContext<FileUploadContextValue | null>(null);\n\nexport function useFileUpload(): FileUploadContextValue {\n const ctx = useContext(FileUploadContext);\n if (!ctx) {\n throw new Error(\n \"FileUpload compound components must be used within <FileUpload>\",\n );\n }\n return ctx;\n}\n","import { useCallback, useId, useRef, useState } from \"react\";\nimport { Upload } from \"lucide-react\";\nimport { cn } from \"../../utils/cn\";\nimport { useFileUpload } from \"./FileUpload.context\";\nimport type { FileUploadDropzoneProps } from \"./FileUpload.types\";\n\n/** Accessible name of the browse trigger when the zone has custom children. */\nconst DEFAULT_BROWSE_LABEL = \"Browse files\";\n\n/** The default zone copy; it doubles as the trigger's accessible name. */\nconst DEFAULT_COPY = \"Drop files here or click to browse\";\n\n/*\n * Keyboard access (after 5.59.0). Until then the zone was a clickable div around a\n * display:none input: no tab stop, no role, no key handler, so a keyboard or\n * switch user could not open the picker at all.\n *\n * The trigger is a REAL <button type=\"button\">, not a div with role=\"button\":\n * focus, Enter and Space (Space on keyup, cancelled by moving off) then come\n * from the platform instead of a key handler that has to get those right.\n *\n * - Default content: the button wraps the icon and the copy, so the visible\n * text IS its accessible name and the look is unchanged.\n * - Custom children: they may contain their own interactive content, which a\n * button must not wrap, so the button is visually hidden beside them and the\n * ZONE draws the focus ring (has-focus-visible) — the focus indicator is\n * never invisible.\n *\n * A click anywhere on the zone still opens the picker, as before; a click on\n * the button bubbles to the zone and is handled there once.\n */\nexport function FileUploadDropzone({\n children,\n className,\n browseLabel,\n}: FileUploadDropzoneProps) {\n const { addFiles, disabled, accept, multiple } = useFileUpload();\n const [dragOver, setDragOver] = useState(false);\n const inputRef = useRef<HTMLInputElement>(null);\n const inputId = useId();\n const custom = children !== undefined && children !== null;\n const inputLabel = browseLabel ?? (custom ? DEFAULT_BROWSE_LABEL : DEFAULT_COPY);\n\n const handleDrop = useCallback(\n (e: React.DragEvent) => {\n e.preventDefault();\n setDragOver(false);\n if (disabled) return;\n addFiles(e.dataTransfer.files);\n },\n [addFiles, disabled],\n );\n\n const handleDragOver = useCallback((e: React.DragEvent) => {\n e.preventDefault();\n setDragOver(true);\n }, []);\n\n const handleDragLeave = useCallback(() => setDragOver(false), []);\n\n const handleClick = useCallback(\n (e: React.MouseEvent) => {\n if (disabled) return;\n // The input's own click bubbles back up here; re-entering would ask for a\n // second picker.\n if (e.target === inputRef.current) return;\n inputRef.current?.click();\n },\n [disabled],\n );\n\n return (\n <div\n data-react-fancy-file-upload-dropzone=\"\"\n data-drag-over={dragOver ? \"\" : undefined}\n data-disabled={disabled ? \"\" : undefined}\n aria-disabled={disabled || undefined}\n onDrop={handleDrop}\n onDragOver={handleDragOver}\n onDragLeave={handleDragLeave}\n onClick={handleClick}\n className={cn(\n \"flex cursor-pointer flex-col items-center justify-center rounded-xl border-2 border-dashed p-8 text-center transition-[color,background-color,border-color,box-shadow]\",\n // Full opacity on purpose: a translucent 2px ring over a dashed border\n // falls under WCAG 2.2's 3:1 for a focus indicator. The offset gap is\n // painted with the surface token so it matches the page in dark mode.\n \"has-focus-visible:ring-2 has-focus-visible:ring-offset-2 has-focus-visible:ring-[color:var(--fancy-focus,var(--color-blue-500))] has-focus-visible:ring-offset-[color:var(--fancy-surface,var(--color-white))] dark:has-focus-visible:ring-[color:var(--fancy-focus-dark,var(--color-blue-400))] dark:has-focus-visible:ring-offset-[color:var(--fancy-surface-dark,var(--color-zinc-900))]\",\n dragOver\n ? \"border-blue-400 bg-blue-50 dark:border-blue-500 dark:bg-blue-950\"\n : \"border-[color:var(--fancy-border-strong,var(--color-zinc-300))] hover:border-zinc-400 dark:border-[color:var(--fancy-border-strong-dark,var(--color-zinc-700))] dark:hover:border-zinc-500\",\n disabled && \"cursor-not-allowed opacity-50\",\n className,\n )}\n >\n <input\n ref={inputRef}\n id={inputId}\n type=\"file\"\n className=\"hidden\"\n tabIndex={-1}\n aria-label={inputLabel}\n onChange={(e) => {\n if (e.target.files) addFiles(e.target.files);\n\n // Reset, or choosing the SAME file again fires no `change` event at\n // all and the gesture is simply dead — \"remove it, then re-add it\"\n // and \"retry the import that just failed\" both stop working. The\n // component never sees those files to reject them; it is not asked.\n e.target.value = \"\";\n }}\n accept={accept}\n multiple={multiple}\n disabled={disabled}\n />\n {custom ? (\n <>\n {children}\n <button\n type=\"button\"\n data-react-fancy-file-upload-browse=\"\"\n aria-controls={inputId}\n disabled={disabled}\n className=\"sr-only\"\n >\n {browseLabel ?? DEFAULT_BROWSE_LABEL}\n </button>\n </>\n ) : (\n <button\n type=\"button\"\n data-react-fancy-file-upload-browse=\"\"\n aria-controls={inputId}\n aria-label={browseLabel}\n disabled={disabled}\n className=\"flex cursor-pointer flex-col items-center rounded-md outline-none disabled:cursor-not-allowed\"\n >\n <Upload size={32} strokeWidth={1.5} aria-hidden=\"true\" className=\"mb-2 text-zinc-400\" />\n <span className=\"text-sm text-zinc-500\">{DEFAULT_COPY}</span>\n </button>\n )}\n </div>\n );\n}\n\nFileUploadDropzone.displayName = \"FileUploadDropzone\";\n","import { useEffect, useMemo } from \"react\";\nimport { File, X } from \"lucide-react\";\nimport { cn } from \"../../utils/cn\";\nimport { useFileUpload } from \"./FileUpload.context\";\nimport type { FileUploadListProps } from \"./FileUpload.types\";\n\nfunction formatSize(bytes: number): string {\n if (bytes < 1024) return `${bytes} B`;\n if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;\n return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;\n}\n\nfunction getExtension(name: string): string {\n const parts = name.split(\".\");\n return parts.length > 1 ? parts.pop()!.toUpperCase() : \"\";\n}\n\nfunction ThumbnailItem({ file, index, onRemove }: { file: File; index: number; onRemove: (i: number) => void }) {\n const isImage = file.type.startsWith(\"image/\");\n const objectUrl = useMemo(() => (isImage ? URL.createObjectURL(file) : null), [file, isImage]);\n\n useEffect(() => {\n return () => {\n if (objectUrl) URL.revokeObjectURL(objectUrl);\n };\n }, [objectUrl]);\n\n return (\n <div className=\"group relative flex w-20 flex-col items-center gap-1\">\n <div className=\"relative h-20 w-20 overflow-hidden rounded-lg border border-[color:var(--fancy-border,var(--color-zinc-200))] bg-zinc-50 dark:border-[color:var(--fancy-border-dark,var(--color-zinc-700))] dark:bg-zinc-800\">\n {isImage && objectUrl ? (\n <img src={objectUrl} alt={file.name} className=\"h-full w-full object-cover\" />\n ) : (\n <div className=\"flex h-full w-full flex-col items-center justify-center gap-1\">\n <File size={20} className=\"text-zinc-400\" />\n <span className=\"text-[10px] font-medium text-zinc-500\">{getExtension(file.name)}</span>\n </div>\n )}\n <button\n type=\"button\"\n onClick={() => onRemove(index)}\n className=\"absolute top-1 right-1 flex h-5 w-5 items-center justify-center rounded-full bg-black/60 text-white opacity-0 transition-opacity hover:bg-black/80 group-hover:opacity-100\"\n aria-label={`Remove ${file.name}`}\n >\n <X size={10} />\n </button>\n </div>\n <span className=\"w-full truncate text-center text-xs text-zinc-500\">{file.name}</span>\n </div>\n );\n}\n\nexport function FileUploadList({ thumbnail, className }: FileUploadListProps) {\n const { files, removeFile } = useFileUpload();\n\n if (files.length === 0) return null;\n\n if (thumbnail) {\n return (\n <div data-react-fancy-file-upload-list=\"\" className={cn(\"mt-3 flex flex-wrap gap-3\", className)}>\n {files.map((file, i) => (\n <ThumbnailItem key={`${file.name}-${i}`} file={file} index={i} onRemove={removeFile} />\n ))}\n </div>\n );\n }\n\n return (\n <ul data-react-fancy-file-upload-list=\"\" className={cn(\"mt-3 space-y-2\", className)}>\n {files.map((file, i) => (\n <li\n key={`${file.name}-${i}`}\n className=\"flex items-center gap-3 rounded-lg border border-[color:var(--fancy-border,var(--color-zinc-200))] px-3 py-2 text-sm dark:border-[color:var(--fancy-border-dark,var(--color-zinc-700))]\"\n >\n <File size={16} className=\"shrink-0 text-zinc-400\" />\n <span className=\"flex-1 truncate\">{file.name}</span>\n <span className=\"shrink-0 text-xs text-zinc-400\">\n {formatSize(file.size)}\n </span>\n <button\n type=\"button\"\n onClick={() => removeFile(i)}\n className=\"shrink-0 text-zinc-400 hover:text-zinc-600 dark:hover:text-zinc-300\"\n aria-label={`Remove ${file.name}`}\n >\n <X size={14} />\n </button>\n </li>\n ))}\n </ul>\n );\n}\n\nFileUploadList.displayName = \"FileUploadList\";\n","/**\n * Does a file satisfy an `accept` string?\n *\n * The browser enforces `accept` in the FILE PICKER only. A drag-and-drop never\n * opens a picker, so on the drop path this is the only thing standing between an\n * image-only dropzone and a dropped executable. Forwarding the attribute to the\n * hidden input is half the job; this is the other half.\n *\n * Follows the HTML `accept` grammar: a comma-separated list of extensions\n * (`.csv`), exact MIME types (`text/plain`) and type wildcards (`image/*`).\n * Matching is case-insensitive, because a drop reports whatever the OS says and\n * `TEXT/PLAIN` is a real thing to receive.\n *\n * A dropped file often carries an EMPTY `type` — the OS may not know it and\n * `File.type` is a hint, never a guarantee. That is why extension rules are\n * checked against the name and not the type: an `accept=\".csv\"` zone has to work\n * for a .csv whose type is `\"\"`, which is the common case rather than the edge.\n */\nexport function matchesAccept(file: File, accept: string): boolean {\n const rules = accept\n .split(\",\")\n .map((rule) => rule.trim().toLowerCase())\n .filter(Boolean);\n\n // An accept string that lists nothing constrains nothing. Failing closed here\n // would turn `accept=\"\"` into a dropzone that silently swallows every file.\n if (rules.length === 0) return true;\n\n const type = file.type.toLowerCase();\n const name = file.name.toLowerCase();\n\n return rules.some((rule) => {\n if (rule.startsWith(\".\")) return name.endsWith(rule);\n if (rule.endsWith(\"/*\")) return type.startsWith(rule.slice(0, -1));\n return type === rule;\n });\n}\n","import { useCallback, useMemo, useState } from \"react\";\nimport { cn } from \"../../utils/cn\";\nimport { FileUploadContext } from \"./FileUpload.context\";\nimport { FileUploadDropzone } from \"./FileUploadDropzone\";\nimport { FileUploadList } from \"./FileUploadList\";\nimport { matchesAccept } from \"./matchesAccept\";\nimport type {\n FileRejection,\n FileRejectionReason,\n FileUploadProps,\n} from \"./FileUpload.types\";\n\nfunction rejection(file: File, reason: FileRejectionReason): FileRejection {\n return { name: file.name, size: file.size, type: file.type, reason };\n}\n\nfunction FileUploadRoot({\n children,\n value,\n onChange,\n onReject,\n accept,\n multiple = true,\n maxFiles,\n maxSize,\n disabled = false,\n className,\n}: FileUploadProps) {\n const [internalFiles, setInternalFiles] = useState<File[]>([]);\n const files = value ?? internalFiles;\n\n const addFiles = useCallback(\n (newFiles: FileList | File[]) => {\n let toAdd = Array.from(newFiles);\n const rejections: FileRejection[] = [];\n\n // Each file is reported once, under the first rule it failed.\n const keepOnly = (\n passes: (f: File) => boolean,\n reason: FileRejectionReason,\n ) => {\n toAdd = toAdd.filter((f) => {\n if (passes(f)) return true;\n rejections.push(rejection(f, reason));\n return false;\n });\n };\n\n // `accept` is enforced HERE, not only on the input: the input's attribute\n // governs the picker, and a drop never opens one.\n if (accept) {\n keepOnly((f) => matchesAccept(f, accept), \"accept\");\n }\n\n if (maxSize) {\n keepOnly((f) => f.size <= maxSize, \"maxSize\");\n }\n\n /*\n * `multiple={false}` REPLACES; `maxFiles` refuses the overflow.\n *\n * These used to be the same rule — a cap of one, first-wins — on the\n * reasoning that the two props must not disagree about what a single-file\n * upload means. But they are different statements:\n *\n * - `maxFiles={n}` is a QUOTA. Dropping five files into a three-file\n * field should keep three, not the last three.\n * - `multiple={false}` is a FIELD SHAPE: this input holds one file. Its\n * analogue is a radio group, where choosing again MOVES the selection.\n *\n * Under the old rule a single-file field could never change its mind: the\n * second choice computed `[old, new].slice(0, 1)` and discarded the new\n * file in silence. The YouGene estate worked around it by remounting the\n * component with a `key`, which is the shape of a bug rather than a\n * preference.\n */\n if (multiple === false) {\n /*\n * The FIRST of the incoming batch, not the last.\n *\n * Two separate questions hide here, and only one of them was the bug:\n *\n * - ACROSS gestures — choose a file, then choose another. The second\n * must win, or the field cannot change its mind. That is the fix.\n * - WITHIN one gesture — drop two files at once onto a single-file\n * field. Which one wins is arbitrary, and taking the first is what\n * has always shipped; there is no replacement intent in a single\n * ambiguous drop.\n *\n * Taking `slice(-1)` would have answered both with \"the last\", quietly\n * changing the second. The existing drop test caught it.\n */\n const replacement = toAdd.slice(0, 1);\n // Nothing survived the accept/size filters — leave the field alone\n // rather than clearing a file the user never asked to remove.\n const next = replacement.length > 0 ? replacement : files;\n\n // The file being replaced was not refused; the rest of this batch was,\n // by a field that holds one.\n for (const f of toAdd.slice(1)) rejections.push(rejection(f, \"maxFiles\"));\n\n if (value === undefined) setInternalFiles(next);\n onChange?.(next);\n if (rejections.length > 0) onReject?.(rejections);\n\n return;\n }\n\n const updated = [...files, ...toAdd];\n const limited = maxFiles ? updated.slice(0, maxFiles) : updated;\n\n for (const f of updated.slice(limited.length)) rejections.push(rejection(f, \"maxFiles\"));\n\n if (value === undefined) setInternalFiles(limited);\n onChange?.(limited);\n if (rejections.length > 0) onReject?.(rejections);\n },\n [accept, files, maxFiles, maxSize, multiple, onChange, onReject, value],\n );\n\n const removeFile = useCallback(\n (index: number) => {\n const updated = files.filter((_, i) => i !== index);\n if (value === undefined) setInternalFiles(updated);\n onChange?.(updated);\n },\n [files, onChange, value],\n );\n\n const ctx = useMemo(\n () => ({ files, addFiles, removeFile, disabled, accept, multiple }),\n [files, addFiles, removeFile, disabled, accept, multiple],\n );\n\n return (\n <FileUploadContext.Provider value={ctx}>\n <div data-react-fancy-file-upload=\"\" className={cn(className)}>{children}</div>\n </FileUploadContext.Provider>\n );\n}\n\nexport const FileUpload = Object.assign(FileUploadRoot, {\n Dropzone: FileUploadDropzone,\n List: FileUploadList,\n});\n"]}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkHNJXBMHI_cjs = require('./chunk-HNJXBMHI.cjs');
|
|
4
|
+
var chunkSNHU2AI4_cjs = require('./chunk-SNHU2AI4.cjs');
|
|
5
|
+
var react = require('react');
|
|
6
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
7
|
+
|
|
8
|
+
var NUMBER = /^[+-]?(\d+(\.\d*)?|\.\d+)([eE][+-]?\d+)?$/;
|
|
9
|
+
var WHOLE = /^[+-]?\d+$/;
|
|
10
|
+
function parseNumber(text) {
|
|
11
|
+
const trimmed = text.trim();
|
|
12
|
+
if (!NUMBER.test(trimmed)) return null;
|
|
13
|
+
const n = Number(trimmed);
|
|
14
|
+
if (!Number.isFinite(n)) return null;
|
|
15
|
+
if (WHOLE.test(trimmed) && !Number.isSafeInteger(n)) return null;
|
|
16
|
+
return n === 0 ? 0 : n;
|
|
17
|
+
}
|
|
18
|
+
function formatNumber(value) {
|
|
19
|
+
return value === null ? "" : String(value);
|
|
20
|
+
}
|
|
21
|
+
function decimals(n) {
|
|
22
|
+
const [mantissa, exponent] = String(n).split("e");
|
|
23
|
+
const places = (mantissa.split(".")[1] ?? "").length - Number(exponent ?? 0);
|
|
24
|
+
return Math.min(Math.max(places, 0), 100);
|
|
25
|
+
}
|
|
26
|
+
function stepped(current, direction, min, max, step) {
|
|
27
|
+
const base = min ?? 0;
|
|
28
|
+
const places = Math.max(decimals(step), decimals(base));
|
|
29
|
+
const at = (k2) => Number((base + k2 * step).toFixed(places));
|
|
30
|
+
const position = ((current ?? 0) - base) / step;
|
|
31
|
+
const nudge = 1e-9;
|
|
32
|
+
let k = direction === 1 ? Math.floor(position + nudge) + 1 : Math.ceil(position - nudge) - 1;
|
|
33
|
+
if (max !== void 0 && at(k) > max) k = Math.floor((max - base) / step + nudge);
|
|
34
|
+
if (min !== void 0 && at(k) < min) k = 0;
|
|
35
|
+
return at(k);
|
|
36
|
+
}
|
|
37
|
+
var NumberField = react.forwardRef(
|
|
38
|
+
({
|
|
39
|
+
value,
|
|
40
|
+
defaultValue = null,
|
|
41
|
+
onValueChange,
|
|
42
|
+
min,
|
|
43
|
+
max,
|
|
44
|
+
step,
|
|
45
|
+
messages,
|
|
46
|
+
name,
|
|
47
|
+
form,
|
|
48
|
+
inputMode,
|
|
49
|
+
onKeyDown,
|
|
50
|
+
onBlur,
|
|
51
|
+
...rest
|
|
52
|
+
}, ref) => {
|
|
53
|
+
const [held, setValue] = chunkSNHU2AI4_cjs.useControllableState(
|
|
54
|
+
value,
|
|
55
|
+
defaultValue,
|
|
56
|
+
onValueChange
|
|
57
|
+
);
|
|
58
|
+
const current = typeof held === "number" && Number.isFinite(held) ? held : null;
|
|
59
|
+
const [text, setText] = react.useState(() => formatNumber(current));
|
|
60
|
+
if (parseNumber(text) !== current && text !== formatNumber(current)) {
|
|
61
|
+
setText(formatNumber(current));
|
|
62
|
+
}
|
|
63
|
+
const stepSize = typeof step === "number" && step > 0 ? step : 1;
|
|
64
|
+
const problem = (() => {
|
|
65
|
+
if (text.trim() !== "" && parseNumber(text) === null) {
|
|
66
|
+
return messages?.invalid ?? "Enter a number.";
|
|
67
|
+
}
|
|
68
|
+
if (current === null) return "";
|
|
69
|
+
if (min !== void 0 && current < min) return messages?.min ?? `Must be at least ${min}.`;
|
|
70
|
+
if (max !== void 0 && current > max) return messages?.max ?? `Must be at most ${max}.`;
|
|
71
|
+
if (typeof step === "number" && step > 0) {
|
|
72
|
+
const position = (current - (min ?? 0)) / step;
|
|
73
|
+
if (Math.abs(position - Math.round(position)) > 1e-9) {
|
|
74
|
+
return messages?.step ?? `Must be in steps of ${step}.`;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return "";
|
|
78
|
+
})();
|
|
79
|
+
const inputRef = react.useRef(null);
|
|
80
|
+
react.useEffect(() => {
|
|
81
|
+
inputRef.current?.setCustomValidity(problem);
|
|
82
|
+
});
|
|
83
|
+
const handleKeyDown = (e) => {
|
|
84
|
+
onKeyDown?.(e);
|
|
85
|
+
if (e.defaultPrevented || rest.disabled || rest.readOnly) return;
|
|
86
|
+
if (e.key !== "ArrowUp" && e.key !== "ArrowDown") return;
|
|
87
|
+
e.preventDefault();
|
|
88
|
+
const next = stepped(current, e.key === "ArrowUp" ? 1 : -1, min, max, stepSize);
|
|
89
|
+
setText(formatNumber(next));
|
|
90
|
+
if (next !== current) setValue(next);
|
|
91
|
+
};
|
|
92
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { "data-react-fancy-number-field": "", children: [
|
|
93
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
94
|
+
chunkHNJXBMHI_cjs.Input,
|
|
95
|
+
{
|
|
96
|
+
"aria-invalid": problem ? true : void 0,
|
|
97
|
+
"aria-valuemax": max,
|
|
98
|
+
"aria-valuemin": min,
|
|
99
|
+
"aria-valuenow": current ?? void 0,
|
|
100
|
+
inputMode: inputMode ?? // A numeric or decimal keypad has no minus sign on iOS, so those are
|
|
101
|
+
// only offered where a negative number cannot be valid.
|
|
102
|
+
(min !== void 0 && min >= 0 ? typeof step === "number" && Number.isInteger(step) ? "numeric" : "decimal" : "text"),
|
|
103
|
+
role: "spinbutton",
|
|
104
|
+
...rest,
|
|
105
|
+
ref: (el) => {
|
|
106
|
+
inputRef.current = el;
|
|
107
|
+
if (typeof ref === "function") ref(el);
|
|
108
|
+
else if (ref) ref.current = el;
|
|
109
|
+
},
|
|
110
|
+
type: "text",
|
|
111
|
+
value: text,
|
|
112
|
+
onValueChange: (next) => {
|
|
113
|
+
setText(next);
|
|
114
|
+
const parsed = parseNumber(next);
|
|
115
|
+
if (parsed !== current) setValue(parsed);
|
|
116
|
+
},
|
|
117
|
+
onKeyDown: handleKeyDown,
|
|
118
|
+
onBlur: (e) => {
|
|
119
|
+
setText(formatNumber(current));
|
|
120
|
+
onBlur?.(e);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
),
|
|
124
|
+
name ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
125
|
+
"input",
|
|
126
|
+
{
|
|
127
|
+
type: "hidden",
|
|
128
|
+
name,
|
|
129
|
+
form,
|
|
130
|
+
disabled: rest.disabled,
|
|
131
|
+
value: formatNumber(current)
|
|
132
|
+
}
|
|
133
|
+
) : null
|
|
134
|
+
] });
|
|
135
|
+
}
|
|
136
|
+
);
|
|
137
|
+
NumberField.displayName = "NumberField";
|
|
138
|
+
|
|
139
|
+
exports.NumberField = NumberField;
|
|
140
|
+
//# sourceMappingURL=chunk-XBFTO64U.cjs.map
|
|
141
|
+
//# sourceMappingURL=chunk-XBFTO64U.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/components/inputs/NumberField/NumberField.tsx"],"names":["k","forwardRef","useControllableState","useState","useRef","useEffect","jsxs","jsx","Input"],"mappings":";;;;;;;AASA,IAAM,MAAA,GAAS,2CAAA;AACf,IAAM,KAAA,GAAQ,YAAA;AAGd,SAAS,YAAY,IAAA,EAA6B;AAChD,EAAA,MAAM,OAAA,GAAU,KAAK,IAAA,EAAK;AAC1B,EAAA,IAAI,CAAC,MAAA,CAAO,IAAA,CAAK,OAAO,GAAG,OAAO,IAAA;AAElC,EAAA,MAAM,CAAA,GAAI,OAAO,OAAO,CAAA;AACxB,EAAA,IAAI,CAAC,MAAA,CAAO,QAAA,CAAS,CAAC,GAAG,OAAO,IAAA;AAEhC,EAAA,IAAI,KAAA,CAAM,KAAK,OAAO,CAAA,IAAK,CAAC,MAAA,CAAO,aAAA,CAAc,CAAC,CAAA,EAAG,OAAO,IAAA;AAE5D,EAAA,OAAO,CAAA,KAAM,IAAI,CAAA,GAAI,CAAA;AACvB;AAEA,SAAS,aAAa,KAAA,EAA8B;AAClD,EA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,CAAA;AAAA,UACzC,CAAA;AAAA,UACA,SAAA,EAAW,aAAA;AAAA,UACX,MAAA,EAAQ,CAAC,CAAA,KAAM;AACb,YAAA,OAAA,CAAQ,YAAA,CAAa,OAAO,CAAC,CAAA;AAC7B,YAAA,MAAA,GAAS,CAAC,CAAA;AAAA,UACZ;AAAA;AAAA,OACF;AAAA,MAEC,IAAA,mBACCD,cAAA;AAAA,QAAC,OAAA;AAAA,QAAA;AAAA,UACC,IAAA,EAAK,QAAA;AAAA,UACL,IAAA;AAAA,UACA,IAAA;AAAA,UACA,UAAU,IAAA,CAAK,QAAA;AAAA,UACf,KAAA,EAAO,aAAa,OAAO;AAAA;AAAA,OAC7B,GACE;AAAA,KAAA,EACN,CAAA;AAAA,EAEJ;AACF;AAEA,WAAA,CAAY,WAAA,GAAc,aAAA","file":"chunk-XBFTO64U.cjs","sourcesContent":["import { forwardRef, useEffect, useRef, useState, type KeyboardEvent } from \"react\";\nimport { useControllableState } from \"../../../hooks/use-controllable-state\";\nimport { Input } from \"../Input\";\nimport type { NumberFieldProps } from \"./NumberField.types\";\n\n/**\n * Plain decimal notation only. `Number()` alone is not safe here: it reads \"0x10\"\n * as 16 and \"Infinity\" as a number, and those are wrong numbers to emit.\n */\nconst NUMBER = /^[+-]?(\\d+(\\.\\d*)?|\\.\\d+)([eE][+-]?\\d+)?$/;\nconst WHOLE = /^[+-]?\\d+$/;\n\n/** The number the text says, or `null` if it does not say one. */\nfunction parseNumber(text: string): number | null {\n const trimmed = text.trim();\n if (!NUMBER.test(trimmed)) return null;\n\n const n = Number(trimmed);\n if (!Number.isFinite(n)) return null;\n // Past 2^53 a whole number rounds to a different one than was typed.\n if (WHOLE.test(trimmed) && !Number.isSafeInteger(n)) return null;\n\n return n === 0 ? 0 : n; // -0 is 0\n}\n\nfunction formatNumber(value: number | null): string {\n return value === null ? \"\" : String(value);\n}\n\n/** Decimal places in a number, so stepping can round away floating-point dust. */\nfunction decimals(n: number): number {\n const [mantissa, exponent] = String(n).split(\"e\");\n const places = (mantissa.split(\".\")[1] ?? \"\").length - Number(exponent ?? 0);\n return Math.min(Math.max(places, 0), 100);\n}\n\nfunction stepped(\n current: number | null,\n direction: 1 | -1,\n min: number | undefined,\n max: number | undefined,\n step: number,\n): number {\n const base = min ?? 0;\n const places = Math.max(decimals(step), decimals(base));\n const at = (k: number) => Number((base + k * step).toFixed(places));\n const position = ((current ?? 0) - base) / step;\n const nudge = 1e-9;\n\n // The next grid line in that direction, so an off-grid value lands on the grid.\n let k =\n direction === 1\n ? Math.floor(position + nudge) + 1\n : Math.ceil(position - nudge) - 1;\n\n if (max !== undefined && at(k) > max) k = Math.floor((max - base) / step + nudge);\n if (min !== undefined && at(k) < min) k = 0;\n\n return at(k);\n}\n\nexport const NumberField = forwardRef<HTMLInputElement, NumberFieldProps>(\n (\n {\n value,\n defaultValue = null,\n onValueChange,\n min,\n max,\n step,\n messages,\n name,\n form,\n inputMode,\n onKeyDown,\n onBlur,\n ...rest\n },\n ref,\n ) => {\n const [held, setValue] = useControllableState<number | null>(\n value,\n defaultValue,\n onValueChange,\n );\n // A host's NaN or Infinity has no text form, so it reads as no number.\n const current = typeof held === \"number\" && Number.isFinite(held) ? held : null;\n\n /*\n * The text is held apart from the number because \"1.\" and \"-\" have no number\n * that displays them. It only moves on its own when the number moved to\n * something the text does not say: a change from outside, or a parent refusing\n * this one.\n */\n const [text, setText] = useState(() => formatNumber(current));\n if (parseNumber(text) !== current && text !== formatNumber(current)) {\n setText(formatNumber(current));\n }\n\n const stepSize = typeof step === \"number\" && step > 0 ? step : 1;\n\n const problem = (() => {\n if (text.trim() !== \"\" && parseNumber(text) === null) {\n return messages?.invalid ?? \"Enter a number.\";\n }\n if (current === null) return \"\";\n if (min !== undefined && current < min) return messages?.min ?? `Must be at least ${min}.`;\n if (max !== undefined && current > max) return messages?.max ?? `Must be at most ${max}.`;\n if (typeof step === \"number\" && step > 0) {\n const position = (current - (min ?? 0)) / step;\n if (Math.abs(position - Math.round(position)) > 1e-9) {\n return messages?.step ?? `Must be in steps of ${step}.`;\n }\n }\n return \"\";\n })();\n\n // The text input has no min/max/step of its own, so a form learns of them here.\n // Runs every render: click-to-edit mounts a fresh input.\n const inputRef = useRef<HTMLInputElement | null>(null);\n useEffect(() => {\n inputRef.current?.setCustomValidity(problem);\n });\n\n const handleKeyDown = (e: KeyboardEvent<HTMLInputElement>) => {\n onKeyDown?.(e);\n if (e.defaultPrevented || rest.disabled || rest.readOnly) return;\n if (e.key !== \"ArrowUp\" && e.key !== \"ArrowDown\") return;\n\n e.preventDefault(); // or the caret jumps to the end of the text\n const next = stepped(current, e.key === \"ArrowUp\" ? 1 : -1, min, max, stepSize);\n setText(formatNumber(next));\n if (next !== current) setValue(next);\n };\n\n return (\n <div data-react-fancy-number-field=\"\">\n <Input\n aria-invalid={problem ? true : undefined}\n aria-valuemax={max}\n aria-valuemin={min}\n aria-valuenow={current ?? undefined}\n inputMode={\n inputMode ??\n // A numeric or decimal keypad has no minus sign on iOS, so those are\n // only offered where a negative number cannot be valid.\n (min !== undefined && min >= 0\n ? typeof step === \"number\" && Number.isInteger(step)\n ? \"numeric\"\n : \"decimal\"\n : \"text\")\n }\n role=\"spinbutton\"\n {...rest}\n ref={(el) => {\n inputRef.current = el;\n if (typeof ref === \"function\") ref(el);\n else if (ref) ref.current = el;\n }}\n // Text, not `number`: a browser reports \"-\" and \"1e\" in a number input as\n // an empty value, indistinguishable from blank, and turns the wheel into\n // a value change on a focused field. Neither applies to a text input.\n type=\"text\"\n value={text}\n onValueChange={(next) => {\n setText(next);\n const parsed = parseNumber(next);\n if (parsed !== current) setValue(parsed);\n }}\n onKeyDown={handleKeyDown}\n onBlur={(e) => {\n setText(formatNumber(current));\n onBlur?.(e);\n }}\n />\n {/* What a native submit posts: the number, never the half-typed text. */}\n {name ? (\n <input\n type=\"hidden\"\n name={name}\n form={form}\n disabled={rest.disabled}\n value={formatNumber(current)}\n />\n ) : null}\n </div>\n );\n },\n);\n\nNumberField.displayName = \"NumberField\";\n"]}
|
|
@@ -203,10 +203,14 @@ function matchesAccept(file, accept) {
|
|
|
203
203
|
return type === rule;
|
|
204
204
|
});
|
|
205
205
|
}
|
|
206
|
+
function rejection(file, reason) {
|
|
207
|
+
return { name: file.name, size: file.size, type: file.type, reason };
|
|
208
|
+
}
|
|
206
209
|
function FileUploadRoot({
|
|
207
210
|
children,
|
|
208
211
|
value,
|
|
209
212
|
onChange,
|
|
213
|
+
onReject,
|
|
210
214
|
accept,
|
|
211
215
|
multiple = true,
|
|
212
216
|
maxFiles,
|
|
@@ -219,25 +223,37 @@ function FileUploadRoot({
|
|
|
219
223
|
const addFiles = react.useCallback(
|
|
220
224
|
(newFiles) => {
|
|
221
225
|
let toAdd = Array.from(newFiles);
|
|
226
|
+
const rejections = [];
|
|
227
|
+
const keepOnly = (passes, reason) => {
|
|
228
|
+
toAdd = toAdd.filter((f) => {
|
|
229
|
+
if (passes(f)) return true;
|
|
230
|
+
rejections.push(rejection(f, reason));
|
|
231
|
+
return false;
|
|
232
|
+
});
|
|
233
|
+
};
|
|
222
234
|
if (accept) {
|
|
223
|
-
|
|
235
|
+
keepOnly((f) => matchesAccept(f, accept), "accept");
|
|
224
236
|
}
|
|
225
237
|
if (maxSize) {
|
|
226
|
-
|
|
238
|
+
keepOnly((f) => f.size <= maxSize, "maxSize");
|
|
227
239
|
}
|
|
228
240
|
if (multiple === false) {
|
|
229
241
|
const replacement = toAdd.slice(0, 1);
|
|
230
242
|
const next = replacement.length > 0 ? replacement : files;
|
|
243
|
+
for (const f of toAdd.slice(1)) rejections.push(rejection(f, "maxFiles"));
|
|
231
244
|
if (value === void 0) setInternalFiles(next);
|
|
232
245
|
onChange?.(next);
|
|
246
|
+
if (rejections.length > 0) onReject?.(rejections);
|
|
233
247
|
return;
|
|
234
248
|
}
|
|
235
249
|
const updated = [...files, ...toAdd];
|
|
236
250
|
const limited = maxFiles ? updated.slice(0, maxFiles) : updated;
|
|
251
|
+
for (const f of updated.slice(limited.length)) rejections.push(rejection(f, "maxFiles"));
|
|
237
252
|
if (value === void 0) setInternalFiles(limited);
|
|
238
253
|
onChange?.(limited);
|
|
254
|
+
if (rejections.length > 0) onReject?.(rejections);
|
|
239
255
|
},
|
|
240
|
-
[accept, files, maxFiles, maxSize, multiple, onChange, value]
|
|
256
|
+
[accept, files, maxFiles, maxSize, multiple, onChange, onReject, value]
|
|
241
257
|
);
|
|
242
258
|
const removeFile = react.useCallback(
|
|
243
259
|
(index) => {
|
|
@@ -260,5 +276,5 @@ var FileUpload = Object.assign(FileUploadRoot, {
|
|
|
260
276
|
|
|
261
277
|
exports.FileUpload = FileUpload;
|
|
262
278
|
exports.useFileUpload = useFileUpload;
|
|
263
|
-
//# sourceMappingURL=chunk-
|
|
264
|
-
//# sourceMappingURL=chunk-
|
|
279
|
+
//# sourceMappingURL=chunk-XHUV3VSM.cjs.map
|
|
280
|
+
//# sourceMappingURL=chunk-XHUV3VSM.cjs.map
|