nish-ui 3.0.0 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -5
- package/dist/chart.d.ts +8 -3
- package/dist/chart.js +2 -417
- package/dist/elements-all.js +71 -70
- package/dist/elements-charts.d.ts +7 -1
- package/dist/elements-charts.js +16 -16
- package/dist/elements-data.d.ts +7 -1
- package/dist/elements-data.js +5 -5
- package/dist/elements-forms.d.ts +7 -1
- package/dist/elements-forms.js +18 -17
- package/dist/elements.d.ts +7 -1
- package/dist/elements.js +4 -4
- package/dist/esm/components/avatar.js +2 -2
- package/dist/esm/components/canvas/legend.js +4 -4
- package/dist/esm/components/canvas/system-canvas.js +24 -1
- package/dist/esm/components/carousel.js +21 -3
- package/dist/esm/components/charts.js +21 -13
- package/dist/esm/components/combobox.js +1 -1
- package/dist/esm/components/data-classes.js +5 -4
- package/dist/esm/components/data.js +1 -5
- package/dist/esm/components/date-picker.js +1 -0
- package/dist/esm/components/date-range-picker.js +1 -0
- package/dist/esm/components/display.js +3 -3
- package/dist/esm/components/file-dropzone.js +21 -1
- package/dist/esm/components/filters.js +3 -1
- package/dist/esm/components/flow.js +12 -11
- package/dist/esm/components/forms.js +24 -2
- package/dist/esm/components/hooks.js +20 -17
- package/dist/esm/components/inbox.js +9 -7
- package/dist/esm/components/layout-vars.js +10 -7
- package/dist/esm/components/menu.js +7 -4
- package/dist/esm/components/multi-select.js +7 -4
- package/dist/esm/components/overlay-core.js +31 -10
- package/dist/esm/components/overlay-dialog.js +17 -2
- package/dist/esm/components/pagination.js +4 -1
- package/dist/esm/components/popover.js +15 -9
- package/dist/esm/components/primitives.js +1 -1
- package/dist/esm/components/progress.js +2 -0
- package/dist/esm/components/resource-classes.js +34 -16
- package/dist/esm/components/resource.js +5 -4
- package/dist/esm/components/settings.js +4 -2
- package/dist/esm/components/slider.js +1 -0
- package/dist/esm/components/strings.js +9 -1
- package/dist/esm/components/tag-input.js +15 -7
- package/dist/esm/components/time-field-classes.js +5 -2
- package/dist/esm/components/time-field.js +15 -7
- package/dist/esm/components/tooltip.js +1 -1
- package/dist/esm/components/url-state.js +1 -0
- package/dist/esm/components/virtual-table.js +8 -2
- package/dist/esm/components/virtual.js +16 -2
- package/dist/esm/format.js +17 -14
- package/dist/esm/runtime.js +1 -1
- package/dist/esm/server/inbox/client.js +1 -1
- package/dist/esm/theme.js +66 -6
- package/dist/format.js +18 -15
- package/dist/inbox-client.js +1 -1
- package/dist/index.d.ts +32 -7
- package/dist/nish-components.css +41 -1
- package/dist/nish-components.min.css +1 -1
- package/dist/node/th-check.js +12 -3
- package/dist/server/hono.d.ts +1 -1
- package/dist/server/hono.js +20 -1
- package/dist/server/index.d.ts +2 -2
- package/dist/server/index.js +19 -5
- package/dist/{spa-BLlMc0eI.d.ts → spa-7myD4xvA.d.ts} +3 -2
- package/dist/system-canvas.d.ts +0 -4
- package/dist/theme.d.ts +20 -2
- package/dist/theme.global.js +67 -7
- package/dist/theme.js +67 -7
- package/package.json +1 -1
|
@@ -212,7 +212,7 @@ function Input({ invalid, size = "md", leading, trailing, wrapperClassName, clas
|
|
|
212
212
|
{
|
|
213
213
|
ref,
|
|
214
214
|
"aria-invalid": invalid || void 0,
|
|
215
|
-
className: fieldClass({ size, className: cn(leading != null && "ps-8", trailing != null && "pe-8", className) }),
|
|
215
|
+
className: fieldClass({ size, className: cn(leading != null && "ps-8", trailing != null && "pe-8 pointer-coarse:pe-12", className) }),
|
|
216
216
|
...rest
|
|
217
217
|
}
|
|
218
218
|
);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// src/components/resource-classes.ts
|
|
2
|
+
import { shared } from "../runtime.js";
|
|
2
3
|
var ApiError = class extends Error {
|
|
3
4
|
/** HTTP status; 0 = network failure or abort-by-timeout. */
|
|
4
5
|
status;
|
|
@@ -17,9 +18,9 @@ var ApiError = class extends Error {
|
|
|
17
18
|
return this.status === 0 || this.status >= 500;
|
|
18
19
|
}
|
|
19
20
|
};
|
|
20
|
-
var
|
|
21
|
+
var store = shared("api", () => ({ config: {} }));
|
|
21
22
|
function configureApi(c) {
|
|
22
|
-
config = { ...config, ...c };
|
|
23
|
+
store.config = { ...store.config, ...c };
|
|
23
24
|
}
|
|
24
25
|
function isRawBody(b) {
|
|
25
26
|
return typeof b === "string" || typeof FormData !== "undefined" && b instanceof FormData || typeof Blob !== "undefined" && b instanceof Blob || typeof URLSearchParams !== "undefined" && b instanceof URLSearchParams || b instanceof ArrayBuffer || ArrayBuffer.isView(b);
|
|
@@ -44,24 +45,41 @@ function excerpt(text, max = 120) {
|
|
|
44
45
|
}
|
|
45
46
|
var SCHEME = /^[a-z][a-z0-9+.-]*:/i;
|
|
46
47
|
function isTrustedOrigin(url) {
|
|
47
|
-
const
|
|
48
|
-
if (
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
48
|
+
const bases = [];
|
|
49
|
+
if (typeof document !== "undefined" && document.baseURI) bases.push(document.baseURI);
|
|
50
|
+
if (typeof location !== "undefined" && location.href) bases.push(location.href);
|
|
51
|
+
for (const here of bases) {
|
|
52
|
+
try {
|
|
53
|
+
const target = new URL(url, here);
|
|
54
|
+
if (target.origin !== "null" && target.origin === new URL(here).origin) return true;
|
|
55
|
+
if (store.config.baseUrl && SCHEME.test(store.config.baseUrl) && target.origin === new URL(store.config.baseUrl).origin) return true;
|
|
56
|
+
return false;
|
|
57
|
+
} catch {
|
|
58
|
+
}
|
|
56
59
|
}
|
|
57
|
-
return
|
|
60
|
+
return isRelativePath(url);
|
|
61
|
+
}
|
|
62
|
+
function isRelativePath(url) {
|
|
63
|
+
let i = 0;
|
|
64
|
+
while (i < url.length && (url[i] === " " || url[i] === " ")) i++;
|
|
65
|
+
const rest = url.slice(i);
|
|
66
|
+
if (SCHEME.test(rest)) return false;
|
|
67
|
+
const a = rest[0];
|
|
68
|
+
const b = rest[1];
|
|
69
|
+
const isSlash = (c) => c === "/" || c === "\\";
|
|
70
|
+
if (a === "\\") return false;
|
|
71
|
+
if (a === "/" && isSlash(b)) return false;
|
|
72
|
+
const squeezed = rest.replace(/[\t\n\r]/g, "");
|
|
73
|
+
if (isSlash(squeezed[0]) && isSlash(squeezed[1])) return false;
|
|
74
|
+
if (SCHEME.test(squeezed)) return false;
|
|
75
|
+
return true;
|
|
58
76
|
}
|
|
59
77
|
async function apiFetch(path, o = {}) {
|
|
60
78
|
const { body, timeoutMs = 15e3, nullOn404, signal: callerSignal, headers: extraHeaders, ...init } = o;
|
|
61
|
-
const url = path.startsWith("/") && config.baseUrl ? config.baseUrl + path : path;
|
|
79
|
+
const url = path.startsWith("/") && store.config.baseUrl ? store.config.baseUrl + path : path;
|
|
62
80
|
const headers = new Headers({ accept: "application/json" });
|
|
63
|
-
if (config.headers && (isTrustedOrigin(url) || config.headersFor?.(url) === true)) {
|
|
64
|
-
for (const [k, v] of Object.entries(config.headers())) headers.set(k, v);
|
|
81
|
+
if (store.config.headers && (isTrustedOrigin(url) || store.config.headersFor?.(url) === true)) {
|
|
82
|
+
for (const [k, v] of Object.entries(store.config.headers())) headers.set(k, v);
|
|
65
83
|
}
|
|
66
84
|
if (extraHeaders) new Headers(extraHeaders).forEach((v, k) => headers.set(k, v));
|
|
67
85
|
let payload;
|
|
@@ -108,7 +126,7 @@ async function apiFetch(path, o = {}) {
|
|
|
108
126
|
if (!res.ok) {
|
|
109
127
|
if (res.status === 404 && nullOn404) return null;
|
|
110
128
|
const err = new ApiError(errorMessage(parsed, res.status), { status: res.status, body: parsed, url });
|
|
111
|
-
if (res.status === 401) config.onUnauthorized?.(err);
|
|
129
|
+
if (res.status === 401) store.config.onUnauthorized?.(err);
|
|
112
130
|
throw err;
|
|
113
131
|
}
|
|
114
132
|
if (res.status === 204 || text === "") return void 0;
|
|
@@ -95,7 +95,8 @@ function useResource(key, fetcher, o = {}) {
|
|
|
95
95
|
error: void 0,
|
|
96
96
|
updatedAt: keepPrevRef.current ? s.updatedAt : void 0,
|
|
97
97
|
fetching: true,
|
|
98
|
-
settled: s.settled
|
|
98
|
+
settled: s.settled,
|
|
99
|
+
loaded: false
|
|
99
100
|
}
|
|
100
101
|
);
|
|
101
102
|
try {
|
|
@@ -104,10 +105,10 @@ function useResource(key, fetcher, o = {}) {
|
|
|
104
105
|
if (run !== runRef.current || ctl.signal.aborted) return;
|
|
105
106
|
failuresRef.current = 0;
|
|
106
107
|
if (mutatedRef.current !== mutatedAtStart) {
|
|
107
|
-
setState((s) => ({ ...s, key: k, error: void 0, fetching: false, settled: s.settled + 1 }));
|
|
108
|
+
setState((s) => ({ ...s, key: k, error: void 0, fetching: false, settled: s.settled + 1, loaded: true }));
|
|
108
109
|
return;
|
|
109
110
|
}
|
|
110
|
-
setState((s) => ({ key: k, data: data2, error: void 0, updatedAt: Date.now(), fetching: false, settled: s.settled + 1 }));
|
|
111
|
+
setState((s) => ({ key: k, data: data2, error: void 0, updatedAt: Date.now(), fetching: false, settled: s.settled + 1, loaded: true }));
|
|
111
112
|
} catch (e) {
|
|
112
113
|
if (run !== runRef.current || ctl.signal.aborted) return;
|
|
113
114
|
failuresRef.current++;
|
|
@@ -193,7 +194,7 @@ function useResource(key, fetcher, o = {}) {
|
|
|
193
194
|
return {
|
|
194
195
|
data,
|
|
195
196
|
error,
|
|
196
|
-
loading: active && data === void 0 && error === void 0,
|
|
197
|
+
loading: active && data === void 0 && error === void 0 && !(sameKey && state.loaded),
|
|
197
198
|
refreshing: state.fetching || active && !sameKey,
|
|
198
199
|
updatedAt,
|
|
199
200
|
stale,
|
|
@@ -153,6 +153,7 @@ function NumberField({
|
|
|
153
153
|
const [pending, setPending] = useState(false);
|
|
154
154
|
const draftRef = useRef(draft);
|
|
155
155
|
const lastSent = useRef(null);
|
|
156
|
+
const seq = useRef(0);
|
|
156
157
|
const mounted = useRef(true);
|
|
157
158
|
const skipCommit = useRef(false);
|
|
158
159
|
const setDraft = (next) => {
|
|
@@ -205,6 +206,7 @@ function NumberField({
|
|
|
205
206
|
if (lastSent.current && lastSent.current.v === next) return;
|
|
206
207
|
setError(null);
|
|
207
208
|
lastSent.current = { v: next };
|
|
209
|
+
const mine = ++seq.current;
|
|
208
210
|
let result;
|
|
209
211
|
try {
|
|
210
212
|
result = onCommit(next);
|
|
@@ -216,10 +218,10 @@ function NumberField({
|
|
|
216
218
|
setPending(true);
|
|
217
219
|
result.then(
|
|
218
220
|
() => {
|
|
219
|
-
if (mounted.current) setPending(false);
|
|
221
|
+
if (mounted.current && mine === seq.current) setPending(false);
|
|
220
222
|
},
|
|
221
223
|
(e) => {
|
|
222
|
-
if (!mounted.current) return;
|
|
224
|
+
if (!mounted.current || mine !== seq.current) return;
|
|
223
225
|
setPending(false);
|
|
224
226
|
fail(e);
|
|
225
227
|
}
|
|
@@ -63,7 +63,8 @@ var FIELD_STRINGS = {
|
|
|
63
63
|
clear: "Clear",
|
|
64
64
|
noMatches: "No matches",
|
|
65
65
|
searching: "Searching\u2026",
|
|
66
|
-
removeTag: (tag) => `Remove ${tag}
|
|
66
|
+
removeTag: (tag) => `Remove ${tag}`,
|
|
67
|
+
maxTags: (max) => `You can add up to ${max}`
|
|
67
68
|
};
|
|
68
69
|
var FILTER_STRINGS = {
|
|
69
70
|
filters: "Filters",
|
|
@@ -113,6 +114,7 @@ var COMMAND_STRINGS = {
|
|
|
113
114
|
var TABLE_STRINGS = {
|
|
114
115
|
sortAnnounce: (header, dir) => dir ? `Sorted by ${header}, ${dir === "asc" ? "ascending" : "descending"}` : "Sorting cleared",
|
|
115
116
|
sortBy: "Sort by",
|
|
117
|
+
sortToggle: (dir) => dir === "desc" ? "Sorted descending, switch to ascending" : "Sorted ascending, switch to descending",
|
|
116
118
|
sortDefault: "Default"
|
|
117
119
|
};
|
|
118
120
|
var SETTINGS_STRINGS = {
|
|
@@ -135,6 +137,12 @@ var PROGRESS_STRINGS = {
|
|
|
135
137
|
progressIndeterminate: "Loading"
|
|
136
138
|
};
|
|
137
139
|
var FLOW_STRINGS = {
|
|
140
|
+
agentQueued: "Queued",
|
|
141
|
+
agentRunning: "Running",
|
|
142
|
+
agentDone: "Done",
|
|
143
|
+
agentFailed: "Failed",
|
|
144
|
+
stepDone: ", done",
|
|
145
|
+
stepFailed: ", failed",
|
|
138
146
|
workflow: "Workflow",
|
|
139
147
|
activity: "Activity",
|
|
140
148
|
other: "Other",
|
|
@@ -69,23 +69,29 @@ function TagInput({
|
|
|
69
69
|
const add = (raw) => {
|
|
70
70
|
let next = tags;
|
|
71
71
|
let err = null;
|
|
72
|
+
const refused = [];
|
|
72
73
|
for (const r of raw) {
|
|
73
74
|
const t = r.trim();
|
|
74
75
|
if (!t || next.includes(t)) continue;
|
|
75
|
-
if (maxTags !== void 0 && next.length >= maxTags)
|
|
76
|
+
if (maxTags !== void 0 && next.length >= maxTags) {
|
|
77
|
+
err ??= strings.maxTags(maxTags);
|
|
78
|
+
refused.push(t);
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
76
81
|
const message = validate?.(t) ?? null;
|
|
77
82
|
if (message) {
|
|
78
83
|
err ??= message;
|
|
84
|
+
refused.push(t);
|
|
79
85
|
continue;
|
|
80
86
|
}
|
|
81
87
|
next = [...next, t];
|
|
82
88
|
}
|
|
83
89
|
if (next !== tags) setTags(next);
|
|
84
90
|
setError(err);
|
|
85
|
-
return err;
|
|
91
|
+
return { error: err, refused };
|
|
86
92
|
};
|
|
87
93
|
const commitText = (raw) => {
|
|
88
|
-
if (!add([raw])) {
|
|
94
|
+
if (!add([raw]).error) {
|
|
89
95
|
setText("");
|
|
90
96
|
setActive(-1);
|
|
91
97
|
}
|
|
@@ -98,9 +104,10 @@ function TagInput({
|
|
|
98
104
|
const handleKeyDown = (e) => {
|
|
99
105
|
if (e.nativeEvent.isComposing) return;
|
|
100
106
|
if (e.key === "Enter") {
|
|
101
|
-
|
|
107
|
+
const pick = listOpen && active >= 0 ? filtered[active] : void 0;
|
|
108
|
+
if (pick !== void 0) {
|
|
102
109
|
e.preventDefault();
|
|
103
|
-
commitText(
|
|
110
|
+
commitText(pick);
|
|
104
111
|
} else if (text.trim()) {
|
|
105
112
|
e.preventDefault();
|
|
106
113
|
commitText(text);
|
|
@@ -137,7 +144,8 @@ function TagInput({
|
|
|
137
144
|
e.preventDefault();
|
|
138
145
|
const parts = pasted.split(SPLIT);
|
|
139
146
|
parts[0] = text + parts[0];
|
|
140
|
-
|
|
147
|
+
const { error: err, refused } = add(parts);
|
|
148
|
+
setText(err ? refused.join(", ") : "");
|
|
141
149
|
};
|
|
142
150
|
const handleBlur = (e) => {
|
|
143
151
|
onBlur?.(e);
|
|
@@ -201,7 +209,7 @@ function TagInput({
|
|
|
201
209
|
"aria-expanded": hasSuggestions ? listOpen : void 0,
|
|
202
210
|
"aria-controls": listOpen ? listId : void 0,
|
|
203
211
|
"aria-autocomplete": hasSuggestions ? "list" : void 0,
|
|
204
|
-
"aria-activedescendant": listOpen && active >= 0 ? `${auto}-opt-${active}` : void 0,
|
|
212
|
+
"aria-activedescendant": listOpen && active >= 0 && active < filtered.length ? `${auto}-opt-${active}` : void 0,
|
|
205
213
|
"aria-label": ariaLabel,
|
|
206
214
|
"aria-labelledby": ariaLabelledBy,
|
|
207
215
|
"aria-describedby": [ariaDescribedBy, error ? errorId : null].filter(Boolean).join(" ") || void 0,
|
|
@@ -11,8 +11,11 @@ function toTime(h, m) {
|
|
|
11
11
|
return `${pad2(h)}:${pad2(m)}`;
|
|
12
12
|
}
|
|
13
13
|
function inTimeRange(t, min, max) {
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
const lo = parseTime(min) ? min : null;
|
|
15
|
+
const hi = parseTime(max) ? max : null;
|
|
16
|
+
if (lo !== null && hi !== null && lo > hi) return t >= lo || t <= hi;
|
|
17
|
+
if (lo !== null && t < lo) return false;
|
|
18
|
+
if (hi !== null && t > hi) return false;
|
|
16
19
|
return true;
|
|
17
20
|
}
|
|
18
21
|
var cycles = /* @__PURE__ */ new Map();
|
|
@@ -108,15 +108,17 @@ function TimeField({
|
|
|
108
108
|
};
|
|
109
109
|
const [own, setOwn] = useState(() => okProp("defaultValue", defaultValue));
|
|
110
110
|
const value = controlled ? okProp("value", valueProp) : own;
|
|
111
|
+
const hourRef = useRef(null);
|
|
112
|
+
const minuteRef = useRef(null);
|
|
111
113
|
const [draftState, setDraft] = useState(null);
|
|
112
114
|
const [bad, setBad] = useState(false);
|
|
113
|
-
|
|
115
|
+
const [focusInside, setFocusInside] = useState(false);
|
|
116
|
+
const draftKept = draftState !== null && (draftState.base === value || focusInside && draftState.prev === value);
|
|
117
|
+
if (draftState !== null && !draftKept) {
|
|
114
118
|
setDraft(null);
|
|
115
119
|
setBad(false);
|
|
116
120
|
}
|
|
117
|
-
const draft = draftState !== null &&
|
|
118
|
-
const hourRef = useRef(null);
|
|
119
|
-
const minuteRef = useRef(null);
|
|
121
|
+
const draft = draftState !== null && draftKept ? draftState.d : null;
|
|
120
122
|
const shown = draft ?? draftFromTime(value, cycle);
|
|
121
123
|
const draftBad = () => {
|
|
122
124
|
if (draft === null) return false;
|
|
@@ -147,14 +149,14 @@ function TimeField({
|
|
|
147
149
|
const t = draftTime(next, cycle);
|
|
148
150
|
if (t === null) {
|
|
149
151
|
if (value !== null) commit(null);
|
|
150
|
-
setDraft({ d: next, base: null });
|
|
152
|
+
setDraft({ d: next, base: null, prev: value });
|
|
151
153
|
setBad(false);
|
|
152
154
|
} else if (typeof t === "string" && inTimeRange(t, minT, maxT)) {
|
|
153
155
|
if (t !== value) commit(t);
|
|
154
|
-
setDraft({ d: next, base: t });
|
|
156
|
+
setDraft({ d: next, base: t, prev: value });
|
|
155
157
|
setBad(false);
|
|
156
158
|
} else {
|
|
157
|
-
setDraft({ d: next, base: value });
|
|
159
|
+
setDraft({ d: next, base: value, prev: value });
|
|
158
160
|
}
|
|
159
161
|
};
|
|
160
162
|
const focusMinute = () => {
|
|
@@ -164,6 +166,7 @@ function TimeField({
|
|
|
164
166
|
const onKey = (which) => (e) => {
|
|
165
167
|
if (disabled) return;
|
|
166
168
|
const key = e.key;
|
|
169
|
+
if (e.ctrlKey || e.metaKey || e.altKey) return;
|
|
167
170
|
if (key === "Enter") {
|
|
168
171
|
if (draftBad()) {
|
|
169
172
|
e.preventDefault();
|
|
@@ -233,9 +236,14 @@ function TimeField({
|
|
|
233
236
|
"aria-labelledby": src,
|
|
234
237
|
"data-disabled": disabled ? "" : void 0,
|
|
235
238
|
className: cn("inline-flex items-center gap-2", className),
|
|
239
|
+
onFocus: (e) => {
|
|
240
|
+
rest.onFocus?.(e);
|
|
241
|
+
setFocusInside(true);
|
|
242
|
+
},
|
|
236
243
|
onBlur: (e) => {
|
|
237
244
|
rest.onBlur?.(e);
|
|
238
245
|
if (e.relatedTarget instanceof Node && e.currentTarget.contains(e.relatedTarget)) return;
|
|
246
|
+
setFocusInside(false);
|
|
239
247
|
const isBad = draftBad();
|
|
240
248
|
setBad(isBad);
|
|
241
249
|
if (!isBad) setDraft(null);
|
|
@@ -25,7 +25,7 @@ function Tooltip({ tip, children, className, side = "top", as = "span", focusabl
|
|
|
25
25
|
const [measuredInner, setMeasuredInner] = useState(false);
|
|
26
26
|
useIsoLayoutEffect(() => {
|
|
27
27
|
const el = triggerRef.current;
|
|
28
|
-
const found = only !== null && !!el && el.
|
|
28
|
+
const found = only !== null && !!el && !!el.firstElementChild?.matches(FOCUSABLE);
|
|
29
29
|
setMeasuredInner(found);
|
|
30
30
|
});
|
|
31
31
|
const inner = only !== null && (staticInner || measuredInner);
|
|
@@ -84,6 +84,7 @@ function useUrlState(defaults, o = {}) {
|
|
|
84
84
|
const name = prefix + key;
|
|
85
85
|
const value = next[key];
|
|
86
86
|
params.delete(name);
|
|
87
|
+
if (value === void 0 || value === null) continue;
|
|
87
88
|
if (same(value, d[key])) continue;
|
|
88
89
|
if (Array.isArray(value)) {
|
|
89
90
|
if (value.length === 0) params.append(name, "");
|
|
@@ -20,7 +20,7 @@ import { useVirtualRows } from "./virtual.js";
|
|
|
20
20
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
21
21
|
var HIDE_BELOW = { sm: "hidden sm:table-cell", md: "hidden md:table-cell", lg: "hidden lg:table-cell" };
|
|
22
22
|
var ROW_FOCUS = "focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-th-accent";
|
|
23
|
-
var INTERACTIVE_CHILD =
|
|
23
|
+
var INTERACTIVE_CHILD = 'a,button,input,select,textarea,label,summary,[role="button"],[role="link"]';
|
|
24
24
|
function VirtualTable({
|
|
25
25
|
rows,
|
|
26
26
|
columns,
|
|
@@ -100,10 +100,15 @@ function VirtualTable({
|
|
|
100
100
|
const topSpace = indices.length > 0 ? offsetOf(first) : 0;
|
|
101
101
|
const bottomSpace = Math.max(0, total - (last >= 0 ? offsetOf(last) + sizeOf(last) : 0));
|
|
102
102
|
const interactive = !!onRowClick;
|
|
103
|
-
const
|
|
103
|
+
const firstInView = virtual.range.start === 0 ? first : indices.find((i) => i >= virtual.range.start + overscan) ?? first;
|
|
104
|
+
const tabbable = indices.includes(focusIndex) ? focusIndex : firstInView;
|
|
104
105
|
useEffect(() => {
|
|
105
106
|
if (count > 0 && focusIndex > count - 1) setFocusIndex(count - 1);
|
|
106
107
|
}, [count, focusIndex]);
|
|
108
|
+
useIsoLayoutEffect(() => {
|
|
109
|
+
const h = headRef.current?.offsetHeight ?? 0;
|
|
110
|
+
if (scrollRef.current) scrollRef.current.style.scrollPaddingTop = h ? `${h}px` : "";
|
|
111
|
+
});
|
|
107
112
|
useIsoLayoutEffect(() => {
|
|
108
113
|
const body = bodyRef.current;
|
|
109
114
|
if (pendingFocus.current !== null) {
|
|
@@ -127,6 +132,7 @@ function VirtualTable({
|
|
|
127
132
|
};
|
|
128
133
|
const onBodyBlur = (e) => {
|
|
129
134
|
const next = e.relatedTarget;
|
|
135
|
+
if (!next && (!document.hasFocus() || document.activeElement === e.target)) return;
|
|
130
136
|
if (next ? !bodyRef.current?.contains(next) : e.target.isConnected) {
|
|
131
137
|
hadFocus.current = false;
|
|
132
138
|
pin(null);
|
|
@@ -24,6 +24,18 @@ import { mergeRefs, warnOnce } from "./data-classes.js";
|
|
|
24
24
|
import { useLatest } from "./latest.js";
|
|
25
25
|
import { jsx } from "react/jsx-runtime";
|
|
26
26
|
var PIN_REACH = 100;
|
|
27
|
+
function rootPx(style, name) {
|
|
28
|
+
const n = parseFloat(style.getPropertyValue(name));
|
|
29
|
+
return Number.isFinite(n) ? n : 0;
|
|
30
|
+
}
|
|
31
|
+
function windowInsets() {
|
|
32
|
+
if (typeof document === "undefined" || typeof getComputedStyle === "undefined") return { top: 0, bottom: 0 };
|
|
33
|
+
const style = getComputedStyle(document.documentElement);
|
|
34
|
+
const top = rootPx(style, "--nish-header-h") + rootPx(style, "--nish-sticky-extra");
|
|
35
|
+
const raw = style.getPropertyValue("--nish-bottom-inset");
|
|
36
|
+
const bottom = Number.isFinite(parseFloat(raw)) ? parseFloat(raw) : rootPx(style, "--nish-bottom-nav-h") + rootPx(style, "--nish-bottom-bar-h");
|
|
37
|
+
return { top, bottom };
|
|
38
|
+
}
|
|
27
39
|
var byIndex = (i) => i;
|
|
28
40
|
function useVirtualRows(options) {
|
|
29
41
|
const { count, itemSize, getKey, measure, gap, overscan, initialCount, scrollRef, listRef, coverTop, pinMode, onRangeChange } = options;
|
|
@@ -59,8 +71,9 @@ function useVirtualRows(options) {
|
|
|
59
71
|
viewTop = top + cover;
|
|
60
72
|
viewBottom = top + scroller.clientHeight;
|
|
61
73
|
} else {
|
|
62
|
-
|
|
63
|
-
|
|
74
|
+
const inset = windowInsets();
|
|
75
|
+
viewTop = latest.current.coverTop ? cover : inset.top;
|
|
76
|
+
viewBottom = window.innerHeight - inset.bottom;
|
|
64
77
|
}
|
|
65
78
|
return { top: viewTop - listTop, bottom: viewBottom - listTop, listTop, viewTop, viewBottom };
|
|
66
79
|
}, [listRef, scrollRef, latest]);
|
|
@@ -238,6 +251,7 @@ function VirtualList({
|
|
|
238
251
|
};
|
|
239
252
|
const onBlur = (e) => {
|
|
240
253
|
const next = e.relatedTarget;
|
|
254
|
+
if (!next && (!document.hasFocus() || document.activeElement === e.target)) return;
|
|
241
255
|
if (!next || !listRef.current?.contains(next)) pin(null);
|
|
242
256
|
};
|
|
243
257
|
const rootStyle = self ? { ...style, height, overflowY: "auto", overflowAnchor: "none", overscrollBehavior: "contain" } : style;
|
package/dist/esm/format.js
CHANGED
|
@@ -80,32 +80,35 @@ function compactAbs(abs, digits, locale) {
|
|
|
80
80
|
function isZeroAfterRounding(v, digits) {
|
|
81
81
|
return Number(Math.abs(v).toFixed(digits)) === 0;
|
|
82
82
|
}
|
|
83
|
-
var
|
|
84
|
-
function
|
|
83
|
+
var currencies = /* @__PURE__ */ new Map();
|
|
84
|
+
function currencyInfo(currency, locale) {
|
|
85
85
|
const key = `${locale}|${currency}`;
|
|
86
|
-
let
|
|
87
|
-
if (
|
|
86
|
+
let info = currencies.get(key);
|
|
87
|
+
if (info === void 0) {
|
|
88
88
|
try {
|
|
89
|
-
const
|
|
89
|
+
const nf2 = new Intl.NumberFormat(locale, {
|
|
90
90
|
style: "currency",
|
|
91
91
|
currency,
|
|
92
92
|
currencyDisplay: "narrowSymbol"
|
|
93
|
-
})
|
|
94
|
-
s =
|
|
93
|
+
});
|
|
94
|
+
let s = nf2.formatToParts(0).find((p) => p.type === "currency")?.value ?? currency;
|
|
95
|
+
if (/\p{L}$/u.test(s)) s += "\xA0";
|
|
96
|
+
info = { symbol: s, digits: nf2.resolvedOptions().maximumFractionDigits ?? 2 };
|
|
95
97
|
} catch {
|
|
96
|
-
|
|
98
|
+
info = { symbol: currency + " ", digits: 2 };
|
|
97
99
|
}
|
|
98
|
-
|
|
100
|
+
currencies.set(key, info);
|
|
99
101
|
}
|
|
100
|
-
return
|
|
102
|
+
return info;
|
|
101
103
|
}
|
|
102
104
|
function moneyAbs(abs, o, locale) {
|
|
103
|
-
const symbol =
|
|
105
|
+
const { symbol, digits } = currencyInfo(o.currency ?? "USD", locale);
|
|
104
106
|
if (o.compact && abs >= 1e3) return symbol + compactAbs(abs, 1, locale);
|
|
105
107
|
const cents = o.cents ?? "auto";
|
|
106
|
-
const
|
|
107
|
-
const
|
|
108
|
-
|
|
108
|
+
const unit = 10 ** digits;
|
|
109
|
+
const hasCents = Math.round(abs * unit) % unit !== 0;
|
|
110
|
+
const showCents = digits > 0 && (cents === "always" || cents === "auto" && (abs < 1e3 || hasCents));
|
|
111
|
+
return symbol + (showCents ? fixed(abs, digits, digits, locale) : fixed(abs, 0, 0, locale));
|
|
109
112
|
}
|
|
110
113
|
function money(v, o = {}) {
|
|
111
114
|
if (!finite(v)) return DASH;
|
package/dist/esm/runtime.js
CHANGED
|
@@ -265,7 +265,7 @@ function createInboxClient(options) {
|
|
|
265
265
|
if (disabled) return { ok: false, error: "disabled", queued: false };
|
|
266
266
|
if (queue.length > 0) {
|
|
267
267
|
enqueue(parsed.value);
|
|
268
|
-
void flush();
|
|
268
|
+
if (timer === null) void flush();
|
|
269
269
|
return { ok: false, error: "queued behind earlier events", queued: true };
|
|
270
270
|
}
|
|
271
271
|
const result = await attempt(parsed.value);
|
package/dist/esm/theme.js
CHANGED
|
@@ -648,7 +648,8 @@ function mountStuck(el, onChange) {
|
|
|
648
648
|
};
|
|
649
649
|
}
|
|
650
650
|
function mountScrollspy(nav, o = {}) {
|
|
651
|
-
|
|
651
|
+
const noop = Object.assign(() => void 0, { lock: (_id) => void 0 });
|
|
652
|
+
if (typeof document === "undefined") return noop;
|
|
652
653
|
const links = Array.from(nav.querySelectorAll('a[href^="#"]')).filter((a) => a.hash.length > 1);
|
|
653
654
|
const target = (a) => {
|
|
654
655
|
try {
|
|
@@ -659,13 +660,16 @@ function mountScrollspy(nav, o = {}) {
|
|
|
659
660
|
};
|
|
660
661
|
const unheight = o.height === false ? () => void 0 : mountHeightVar(nav, "--nish-sticky-extra");
|
|
661
662
|
let current = null;
|
|
663
|
+
let locked = null;
|
|
664
|
+
let unlockListeners = null;
|
|
662
665
|
const edges = () => {
|
|
663
666
|
const max = nav.scrollWidth - nav.clientWidth;
|
|
664
|
-
|
|
665
|
-
nav.dataset.
|
|
667
|
+
const left = getComputedStyle(nav).direction === "rtl" ? nav.scrollLeft + max : nav.scrollLeft;
|
|
668
|
+
nav.dataset.atStart = String(left <= 1);
|
|
669
|
+
nav.dataset.atEnd = String(max <= 1 || left >= max - 1);
|
|
666
670
|
};
|
|
667
671
|
const reveal = (a) => {
|
|
668
|
-
const left = a.
|
|
672
|
+
const left = a.getBoundingClientRect().left - nav.getBoundingClientRect().left + nav.scrollLeft - nav.clientLeft;
|
|
669
673
|
const view = nav.clientWidth;
|
|
670
674
|
if (left < nav.scrollLeft + 24) nav.scrollLeft = Math.max(0, left - 24);
|
|
671
675
|
else if (left + a.offsetWidth > nav.scrollLeft + view - 24) nav.scrollLeft = left + a.offsetWidth - view + 24;
|
|
@@ -691,7 +695,61 @@ function mountScrollspy(nav, o = {}) {
|
|
|
691
695
|
if (window.innerHeight + window.scrollY >= de.scrollHeight - 2) {
|
|
692
696
|
for (const a of links) if (target(a)) found = a;
|
|
693
697
|
}
|
|
694
|
-
activate(found);
|
|
698
|
+
activate(locked ?? found);
|
|
699
|
+
};
|
|
700
|
+
const unlock = () => {
|
|
701
|
+
unlockListeners?.();
|
|
702
|
+
unlockListeners = null;
|
|
703
|
+
locked = null;
|
|
704
|
+
};
|
|
705
|
+
const lock = (id) => {
|
|
706
|
+
const a = links.find((l) => {
|
|
707
|
+
try {
|
|
708
|
+
return decodeURIComponent(l.hash.slice(1)) === id;
|
|
709
|
+
} catch {
|
|
710
|
+
return false;
|
|
711
|
+
}
|
|
712
|
+
});
|
|
713
|
+
if (!a) return;
|
|
714
|
+
unlock();
|
|
715
|
+
locked = a;
|
|
716
|
+
activate(a);
|
|
717
|
+
const release = () => {
|
|
718
|
+
unlock();
|
|
719
|
+
schedule();
|
|
720
|
+
};
|
|
721
|
+
const onKey = (e) => {
|
|
722
|
+
if (["ArrowUp", "ArrowDown", "PageUp", "PageDown", "Home", "End", " "].includes(e.key)) release();
|
|
723
|
+
};
|
|
724
|
+
let settled = false;
|
|
725
|
+
const settle = () => {
|
|
726
|
+
settled = true;
|
|
727
|
+
};
|
|
728
|
+
let t = setTimeout(settle, 400);
|
|
729
|
+
const onScroll = () => {
|
|
730
|
+
if (settled) release();
|
|
731
|
+
else {
|
|
732
|
+
clearTimeout(t);
|
|
733
|
+
t = setTimeout(settle, 200);
|
|
734
|
+
}
|
|
735
|
+
};
|
|
736
|
+
const onScrollEnd = () => {
|
|
737
|
+
clearTimeout(t);
|
|
738
|
+
t = setTimeout(settle, 50);
|
|
739
|
+
};
|
|
740
|
+
window.addEventListener("wheel", release, { passive: true });
|
|
741
|
+
window.addEventListener("touchstart", release, { passive: true });
|
|
742
|
+
window.addEventListener("keydown", onKey);
|
|
743
|
+
window.addEventListener("scroll", onScroll, { passive: true });
|
|
744
|
+
window.addEventListener("scrollend", onScrollEnd);
|
|
745
|
+
unlockListeners = () => {
|
|
746
|
+
clearTimeout(t);
|
|
747
|
+
window.removeEventListener("wheel", release);
|
|
748
|
+
window.removeEventListener("touchstart", release);
|
|
749
|
+
window.removeEventListener("keydown", onKey);
|
|
750
|
+
window.removeEventListener("scroll", onScroll);
|
|
751
|
+
window.removeEventListener("scrollend", onScrollEnd);
|
|
752
|
+
};
|
|
695
753
|
};
|
|
696
754
|
let frame = 0;
|
|
697
755
|
const schedule = () => {
|
|
@@ -719,7 +777,8 @@ function mountScrollspy(nav, o = {}) {
|
|
|
719
777
|
});
|
|
720
778
|
ro.observe(nav);
|
|
721
779
|
}
|
|
722
|
-
|
|
780
|
+
const stop = () => {
|
|
781
|
+
unlock();
|
|
723
782
|
if (frame) cancelAnimationFrame(frame);
|
|
724
783
|
window.removeEventListener("scroll", schedule);
|
|
725
784
|
window.removeEventListener("resize", schedule);
|
|
@@ -731,6 +790,7 @@ function mountScrollspy(nav, o = {}) {
|
|
|
731
790
|
delete nav.dataset.atStart;
|
|
732
791
|
delete nav.dataset.atEnd;
|
|
733
792
|
};
|
|
793
|
+
return Object.assign(stop, { lock });
|
|
734
794
|
}
|
|
735
795
|
function mountChecklist(list) {
|
|
736
796
|
if (typeof document === "undefined") return () => void 0;
|