@brett_lamy/ui 4.0.0 → 5.0.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 +1 -1
- package/dist/components/animated-height.d.ts +3 -1
- package/dist/components/animated-height.d.ts.map +1 -1
- package/dist/components/animated-height.js +11 -11
- package/dist/components/artifact-chat-container.d.ts.map +1 -1
- package/dist/components/artifact-chat-container.js +81 -82
- package/dist/components/button.d.ts +4 -3
- package/dist/components/button.d.ts.map +1 -1
- package/dist/components/button.js +22 -9
- package/dist/components/canvas.d.ts +91 -0
- package/dist/components/canvas.d.ts.map +1 -0
- package/dist/components/canvas.js +296 -0
- package/dist/components/composer/composer-cards.d.ts +55 -0
- package/dist/components/composer/composer-cards.d.ts.map +1 -0
- package/dist/components/composer/composer-cards.js +351 -0
- package/dist/components/composer/composer.d.ts +9 -1
- package/dist/components/composer/composer.d.ts.map +1 -1
- package/dist/components/composer/composer.js +179 -154
- package/dist/components/context-menu.d.ts +25 -0
- package/dist/components/context-menu.d.ts.map +1 -0
- package/dist/components/context-menu.js +127 -0
- package/dist/components/credenza.d.ts.map +1 -1
- package/dist/components/credenza.js +52 -92
- package/dist/components/cron-editor.d.ts +47 -0
- package/dist/components/cron-editor.d.ts.map +1 -0
- package/dist/components/cron-editor.js +297 -0
- package/dist/components/dropdown-menu.d.ts +3 -1
- package/dist/components/dropdown-menu.d.ts.map +1 -1
- package/dist/components/dropdown-menu.js +5 -5
- package/dist/components/edge-drawer.d.ts.map +1 -1
- package/dist/components/edge-drawer.js +1 -0
- package/dist/components/file-upload.d.ts +121 -0
- package/dist/components/file-upload.d.ts.map +1 -0
- package/dist/components/file-upload.js +405 -0
- package/dist/components/filter-input.d.ts +22 -0
- package/dist/components/filter-input.d.ts.map +1 -0
- package/dist/components/filter-input.js +126 -0
- package/dist/components/filter.d.ts +154 -0
- package/dist/components/filter.d.ts.map +1 -0
- package/dist/components/filter.js +815 -0
- package/dist/components/floating-chat.d.ts.map +1 -1
- package/dist/components/floating-chat.js +71 -88
- package/dist/components/floating-sheet.d.ts.map +1 -1
- package/dist/components/floating-sheet.js +93 -104
- package/dist/components/markdown-editor.d.ts +2 -0
- package/dist/components/markdown-editor.d.ts.map +1 -1
- package/dist/components/markdown-editor.js +46 -45
- package/dist/components/markdown-view.d.ts +6 -1
- package/dist/components/markdown-view.d.ts.map +1 -1
- package/dist/components/markdown-view.js +13 -11
- package/dist/components/navigation-stack.d.ts +3 -5
- package/dist/components/navigation-stack.d.ts.map +1 -1
- package/dist/components/navigation-stack.js +212 -382
- package/dist/components/passkey-enroll-dialog.d.ts +36 -0
- package/dist/components/passkey-enroll-dialog.d.ts.map +1 -0
- package/dist/components/passkey-enroll-dialog.js +234 -0
- package/dist/components/result-table.d.ts +38 -0
- package/dist/components/result-table.d.ts.map +1 -0
- package/dist/components/result-table.js +161 -0
- package/dist/components/schema-tree.d.ts +19 -0
- package/dist/components/schema-tree.d.ts.map +1 -0
- package/dist/components/schema-tree.js +172 -0
- package/dist/components/side-drawer.d.ts.map +1 -1
- package/dist/components/side-drawer.js +117 -143
- package/dist/components/slider.d.ts.map +1 -1
- package/dist/components/slider.js +4 -1
- package/dist/components/spinner-shapes.d.ts +263 -0
- package/dist/components/spinner-shapes.d.ts.map +1 -0
- package/dist/components/spinner-shapes.js +771 -0
- package/dist/components/spinner.d.ts +133 -3
- package/dist/components/spinner.d.ts.map +1 -1
- package/dist/components/spinner.js +445 -29
- package/dist/components/sql-console.d.ts +28 -0
- package/dist/components/sql-console.d.ts.map +1 -0
- package/dist/components/sql-console.js +348 -0
- package/dist/components/sql-editor.d.ts +47 -0
- package/dist/components/sql-editor.d.ts.map +1 -0
- package/dist/components/sql-editor.js +170 -0
- package/dist/components/tab-view.d.ts +2 -2
- package/dist/components/tab-view.d.ts.map +1 -1
- package/dist/components/tab-view.js +63 -49
- package/dist/components/tailscale-login-button.d.ts +53 -0
- package/dist/components/tailscale-login-button.d.ts.map +1 -0
- package/dist/components/tailscale-login-button.js +197 -0
- package/dist/components/time-input.d.ts +46 -0
- package/dist/components/time-input.d.ts.map +1 -0
- package/dist/components/time-input.js +258 -0
- package/dist/components/toast.d.ts +5 -2
- package/dist/components/toast.d.ts.map +1 -1
- package/dist/components/toast.js +249 -125
- package/dist/components/vault-gate.d.ts +60 -0
- package/dist/components/vault-gate.d.ts.map +1 -0
- package/dist/components/vault-gate.js +382 -0
- package/dist/index.css +1 -1
- package/dist/index.d.ts +85 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +129 -83
- package/dist/lib/back-history.d.ts +5 -0
- package/dist/lib/back-history.d.ts.map +1 -0
- package/dist/lib/back-history.js +44 -0
- package/dist/lib/canvas-math.d.ts +82 -0
- package/dist/lib/canvas-math.d.ts.map +1 -0
- package/dist/lib/canvas-math.js +226 -0
- package/dist/lib/controllable-state.d.ts +4 -0
- package/dist/lib/controllable-state.d.ts.map +1 -0
- package/dist/lib/controllable-state.js +11 -0
- package/dist/lib/cron.d.ts +55 -0
- package/dist/lib/cron.d.ts.map +1 -0
- package/dist/lib/cron.js +269 -0
- package/dist/lib/edge-swipe.d.ts +36 -0
- package/dist/lib/edge-swipe.d.ts.map +1 -0
- package/dist/lib/edge-swipe.js +73 -0
- package/dist/lib/file-upload.d.ts +187 -0
- package/dist/lib/file-upload.d.ts.map +1 -0
- package/dist/lib/file-upload.js +349 -0
- package/dist/lib/filter-query.d.ts +90 -0
- package/dist/lib/filter-query.d.ts.map +1 -0
- package/dist/lib/filter-query.js +459 -0
- package/dist/lib/filter.d.ts +120 -0
- package/dist/lib/filter.d.ts.map +1 -0
- package/dist/lib/filter.js +399 -0
- package/dist/lib/format-bytes.d.ts +3 -0
- package/dist/lib/format-bytes.d.ts.map +1 -0
- package/dist/lib/format-bytes.js +16 -0
- package/dist/lib/gpu-cron.d.ts +51 -0
- package/dist/lib/gpu-cron.d.ts.map +1 -0
- package/dist/lib/gpu-cron.js +81 -0
- package/dist/lib/gpu-query/featurize.d.ts +19 -0
- package/dist/lib/gpu-query/featurize.d.ts.map +1 -0
- package/dist/lib/gpu-query/featurize.js +88 -0
- package/dist/lib/gpu-query/index.d.ts +73 -0
- package/dist/lib/gpu-query/index.d.ts.map +1 -0
- package/dist/lib/gpu-query/index.js +117 -0
- package/dist/lib/gpu-query/kernel.wgsl.d.ts +30 -0
- package/dist/lib/gpu-query/kernel.wgsl.d.ts.map +1 -0
- package/dist/lib/gpu-query/model.d.ts +8 -0
- package/dist/lib/gpu-query/model.d.ts.map +1 -0
- package/dist/lib/gpu-query/model.js +91 -0
- package/dist/lib/gpu-query/schema.d.ts +40 -0
- package/dist/lib/gpu-query/schema.d.ts.map +1 -0
- package/dist/lib/gpu-query/schema.js +0 -0
- package/dist/lib/gpu-query/webgpu.d.ts +12 -0
- package/dist/lib/gpu-query/webgpu.d.ts.map +1 -0
- package/dist/lib/gpu-query/weights.d.ts +17 -0
- package/dist/lib/gpu-query/weights.d.ts.map +1 -0
- package/dist/lib/gpu-query/weights.js +40 -0
- package/dist/lib/gpu-query/weights.json.d.ts +3 -0
- package/dist/lib/gpu-query/weights2.js +25 -0
- package/dist/lib/gpu-time.d.ts +77 -0
- package/dist/lib/gpu-time.d.ts.map +1 -0
- package/dist/lib/gpu-time.js +260 -0
- package/dist/lib/morph-path.d.ts +22 -0
- package/dist/lib/morph-path.d.ts.map +1 -0
- package/dist/lib/morph-path.js +42 -0
- package/dist/lib/passkey.d.ts +120 -0
- package/dist/lib/passkey.d.ts.map +1 -0
- package/dist/lib/passkey.js +186 -0
- package/dist/lib/persistent-state.d.ts +9 -0
- package/dist/lib/persistent-state.d.ts.map +1 -0
- package/dist/lib/persistent-state.js +37 -0
- package/dist/lib/pglite-core.d.ts +219 -0
- package/dist/lib/pglite-core.d.ts.map +1 -0
- package/dist/lib/pglite-core.js +273 -0
- package/dist/lib/pglite-files.d.ts +7 -0
- package/dist/lib/pglite-files.d.ts.map +1 -0
- package/dist/lib/pglite-files.js +17 -0
- package/dist/lib/pglite-schema.d.ts +58 -0
- package/dist/lib/pglite-schema.d.ts.map +1 -0
- package/dist/lib/pglite-schema.js +105 -0
- package/dist/lib/pglite-storage.d.ts +33 -0
- package/dist/lib/pglite-storage.d.ts.map +1 -0
- package/dist/lib/pglite-storage.js +55 -0
- package/dist/lib/pglite-transfer.d.ts +53 -0
- package/dist/lib/pglite-transfer.d.ts.map +1 -0
- package/dist/lib/pglite-transfer.js +126 -0
- package/dist/lib/pglite.d.ts +106 -0
- package/dist/lib/pglite.d.ts.map +1 -0
- package/dist/lib/pglite.js +298 -0
- package/dist/lib/pull-to-refresh.d.ts +24 -0
- package/dist/lib/pull-to-refresh.d.ts.map +1 -0
- package/dist/lib/pull-to-refresh.js +74 -0
- package/dist/lib/scroll-hidden.d.ts +6 -0
- package/dist/lib/scroll-hidden.d.ts.map +1 -0
- package/dist/lib/scroll-hidden.js +21 -0
- package/dist/lib/sql-format.d.ts +62 -0
- package/dist/lib/sql-format.d.ts.map +1 -0
- package/dist/lib/sql-format.js +175 -0
- package/dist/lib/sql-lex.d.ts +25 -0
- package/dist/lib/sql-lex.d.ts.map +1 -0
- package/dist/lib/sql-lex.js +135 -0
- package/dist/lib/tab-lock.d.ts +28 -0
- package/dist/lib/tab-lock.d.ts.map +1 -0
- package/dist/lib/tab-lock.js +80 -0
- package/dist/lib/tailscale-connect.d.ts +56 -0
- package/dist/lib/tailscale-connect.d.ts.map +1 -0
- package/dist/lib/tailscale-connect.js +99 -0
- package/dist/lib/tailscale-fake.d.ts +33 -0
- package/dist/lib/tailscale-fake.d.ts.map +1 -0
- package/dist/lib/tailscale-fake.js +80 -0
- package/dist/lib/tailscale-policy.d.ts +71 -0
- package/dist/lib/tailscale-policy.d.ts.map +1 -0
- package/dist/lib/tailscale-policy.js +244 -0
- package/dist/lib/tailscale-react.d.ts +20 -0
- package/dist/lib/tailscale-react.d.ts.map +1 -0
- package/dist/lib/tailscale-react.js +37 -0
- package/dist/lib/tailscale-router/bridge.d.ts +60 -0
- package/dist/lib/tailscale-router/bridge.d.ts.map +1 -0
- package/dist/lib/tailscale-router/bridge.js +198 -0
- package/dist/lib/tailscale-router/react.d.ts +19 -0
- package/dist/lib/tailscale-router/react.d.ts.map +1 -0
- package/dist/lib/tailscale-router/react.js +52 -0
- package/dist/lib/tailscale.d.ts +204 -0
- package/dist/lib/tailscale.d.ts.map +1 -0
- package/dist/lib/tailscale.js +443 -0
- package/dist/lib/title-flight.d.ts +34 -0
- package/dist/lib/title-flight.d.ts.map +1 -0
- package/dist/lib/title-flight.js +123 -0
- package/dist/lib/vault-react.d.ts +49 -0
- package/dist/lib/vault-react.d.ts.map +1 -0
- package/dist/lib/vault-react.js +196 -0
- package/dist/lib/vault-storage.d.ts +30 -0
- package/dist/lib/vault-storage.d.ts.map +1 -0
- package/dist/lib/vault-storage.js +105 -0
- package/dist/lib/vault.d.ts +200 -0
- package/dist/lib/vault.d.ts.map +1 -0
- package/dist/lib/vault.js +641 -0
- package/dist/tailscale-sw.js +332 -0
- package/package.json +35 -5
- package/dist/components/icon-button.d.ts +0 -19
- package/dist/components/icon-button.d.ts.map +0 -1
- package/dist/components/icon-button.js +0 -31
- package/dist/components/measure-h.d.ts +0 -7
- package/dist/components/measure-h.d.ts.map +0 -1
- package/dist/components/measure-h.js +0 -20
|
@@ -0,0 +1,349 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { formatBytes as e } from "./format-bytes.js";
|
|
3
|
+
import { useCallback as t, useEffect as n, useMemo as r, useRef as i, useState as a } from "react";
|
|
4
|
+
import { isDirectoryDropItem as o, isFileDropItem as s } from "react-aria-components";
|
|
5
|
+
//#region src/lib/file-upload.ts
|
|
6
|
+
function c(e) {
|
|
7
|
+
return e ? (typeof e == "string" ? e.split(",") : e).map((e) => e.trim().toLowerCase()).filter(Boolean) : [];
|
|
8
|
+
}
|
|
9
|
+
function l(e, t) {
|
|
10
|
+
let n = c(t);
|
|
11
|
+
if (!n.length) return !0;
|
|
12
|
+
let r = (e.type ?? "").toLowerCase().split(";")[0].trim(), i = e.name.toLowerCase();
|
|
13
|
+
return n.some((e) => e === "*" || e === "*/*" ? !0 : e.startsWith(".") ? i.endsWith(e) : e.endsWith("/*") ? r.startsWith(e.slice(0, -1)) : r === e);
|
|
14
|
+
}
|
|
15
|
+
function u(e) {
|
|
16
|
+
let t = c(e);
|
|
17
|
+
if (!t.length || t.includes("*") || t.includes("*/*")) return "Any file";
|
|
18
|
+
let n = t.map((e) => {
|
|
19
|
+
if (e.startsWith(".")) return `${e} files`;
|
|
20
|
+
if (e === "application/pdf") return "PDFs";
|
|
21
|
+
let [t, n] = e.split("/");
|
|
22
|
+
return n === "*" ? {
|
|
23
|
+
image: "Images",
|
|
24
|
+
video: "Videos",
|
|
25
|
+
audio: "Audio",
|
|
26
|
+
text: "Text files"
|
|
27
|
+
}[t] ?? `${t} files` : n ? `${n.replace(/^x-/, "").toUpperCase()} files` : e;
|
|
28
|
+
}), r = [...new Set(n)];
|
|
29
|
+
return r.length > 1 ? `${r.slice(0, -1).join(", ")} and ${r[r.length - 1]}` : r[0];
|
|
30
|
+
}
|
|
31
|
+
function d(t) {
|
|
32
|
+
let n = [], r = u(t.accept);
|
|
33
|
+
return r !== "Any file" && n.push(r), t.maxSize != null && n.push(`up to ${e(t.maxSize)}${t.maxFiles === 1 ? "" : " each"}`), t.minSize != null && n.push(`at least ${e(t.minSize)}`), t.maxFiles != null && t.maxFiles > 1 && n.push(`up to ${t.maxFiles} files`), n.join(" · ");
|
|
34
|
+
}
|
|
35
|
+
var f = /\.(png|jpe?g|gif|webp|avif|heic|heif|bmp|svg|ico)$/i, p = /\.(mp4|mov|m4v|webm|mkv|avi)$/i, m = /\.(mp3|m4a|aac|wav|flac|ogg|opus|aiff?)$/i, h = /\.(zip|tar|gz|tgz|bz2|xz|7z|rar|zst|dmg)$/i, g = /\.(txt|md|mdx|csv|tsv|json|ya?ml|toml|xml|html?|css|[mc]?[jt]sx?|py|rb|go|rs|java|sh|sql|log)$/i;
|
|
36
|
+
function _(e) {
|
|
37
|
+
let t = (e.type ?? "").toLowerCase();
|
|
38
|
+
return t.startsWith("image/") || !t && f.test(e.name) ? "image" : t.startsWith("video/") || !t && p.test(e.name) ? "video" : t.startsWith("audio/") || !t && m.test(e.name) ? "audio" : t === "application/pdf" || /\.pdf$/i.test(e.name) ? "pdf" : /zip|tar|gzip|rar|7z/.test(t) || h.test(e.name) ? "archive" : t.startsWith("text/") || /json|xml|javascript|yaml/.test(t) || g.test(e.name) ? "text" : "other";
|
|
39
|
+
}
|
|
40
|
+
var v = 0;
|
|
41
|
+
function y() {
|
|
42
|
+
return `f${(++v).toString(36)}${Math.random().toString(36).slice(2, 7)}`;
|
|
43
|
+
}
|
|
44
|
+
var b = (e, t) => `${e}|${t.size}|${t.lastModified}`;
|
|
45
|
+
function x(t, n, r) {
|
|
46
|
+
let i = r?.[t];
|
|
47
|
+
if (typeof i == "string") return i;
|
|
48
|
+
if (i) return i(n);
|
|
49
|
+
switch (t) {
|
|
50
|
+
case "type": return `Unsupported file type. Accepted: ${u(n.accept)}.`;
|
|
51
|
+
case "too-large": return `Larger than the ${e(n.maxSize ?? 0)} limit.`;
|
|
52
|
+
case "too-small": return `Smaller than the ${e(n.minSize ?? 0)} minimum.`;
|
|
53
|
+
case "too-many": return n.maxFiles === 1 ? "Only one file is allowed." : `Only ${n.maxFiles} files are allowed.`;
|
|
54
|
+
case "duplicate": return "Already added.";
|
|
55
|
+
default: return "This file isn’t allowed.";
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
function S(e) {
|
|
59
|
+
return Array.from(e, (e) => e instanceof File ? {
|
|
60
|
+
file: e,
|
|
61
|
+
path: e.webkitRelativePath || e.name
|
|
62
|
+
} : e);
|
|
63
|
+
}
|
|
64
|
+
function C(e, t, n = {}) {
|
|
65
|
+
let r = n.accept, i = new Set(t.filter((e) => e.status !== "rejected").map((e) => b(e.path, e.file))), a = t.filter((e) => e.status !== "rejected").length;
|
|
66
|
+
return e.map(({ file: e, path: o }) => {
|
|
67
|
+
let s = {
|
|
68
|
+
file: e,
|
|
69
|
+
path: o,
|
|
70
|
+
accept: r,
|
|
71
|
+
maxSize: n.maxSize,
|
|
72
|
+
minSize: n.minSize,
|
|
73
|
+
maxFiles: n.maxFiles
|
|
74
|
+
}, c = (t, r) => ({
|
|
75
|
+
id: y(),
|
|
76
|
+
file: e,
|
|
77
|
+
path: o,
|
|
78
|
+
status: "rejected",
|
|
79
|
+
progress: 0,
|
|
80
|
+
reason: t,
|
|
81
|
+
error: r ?? x(t, s, n.messages)
|
|
82
|
+
});
|
|
83
|
+
if (r?.length && !l(e, r)) return c("type");
|
|
84
|
+
if (n.maxSize != null && e.size > n.maxSize) return c("too-large");
|
|
85
|
+
if (n.minSize != null && e.size < n.minSize) return c("too-small");
|
|
86
|
+
let u = b(o, e);
|
|
87
|
+
if (!n.allowDuplicates && i.has(u)) return c("duplicate");
|
|
88
|
+
if (n.validate) {
|
|
89
|
+
let r = n.validate(e, {
|
|
90
|
+
path: o,
|
|
91
|
+
files: t
|
|
92
|
+
});
|
|
93
|
+
if (typeof r == "string") return c("invalid", r);
|
|
94
|
+
if (r === !1) return c("invalid");
|
|
95
|
+
}
|
|
96
|
+
return n.maxFiles != null && a >= n.maxFiles ? c("too-many") : (i.add(u), a++, {
|
|
97
|
+
id: y(),
|
|
98
|
+
file: e,
|
|
99
|
+
path: o,
|
|
100
|
+
status: "queued",
|
|
101
|
+
progress: 0
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
var w = (e) => e.includes("/") && e.split("/").slice(1).some((e) => e.startsWith("."));
|
|
106
|
+
function T(e, { skipHidden: t = !0 } = {}) {
|
|
107
|
+
let n = e ? S(Array.from(e)) : [];
|
|
108
|
+
return t ? n.filter((e) => !w(e.path)) : n;
|
|
109
|
+
}
|
|
110
|
+
async function E(e, { limit: t = 1e3, skipHidden: n = !0, directories: r = !0 } = {}) {
|
|
111
|
+
let i = [], a = !1, c = 0, l = async (e, u) => {
|
|
112
|
+
if (i.length >= t) {
|
|
113
|
+
a = !0;
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
let d = u !== "";
|
|
117
|
+
if (s(e)) {
|
|
118
|
+
if (d && n && e.name.startsWith(".")) return;
|
|
119
|
+
i.push({
|
|
120
|
+
file: await e.getFile(),
|
|
121
|
+
path: u + e.name
|
|
122
|
+
});
|
|
123
|
+
} else if (o(e)) {
|
|
124
|
+
if (!r) {
|
|
125
|
+
c++;
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
if (d && n && e.name.startsWith(".")) return;
|
|
129
|
+
try {
|
|
130
|
+
for await (let n of e.getEntries()) {
|
|
131
|
+
if (i.length >= t) {
|
|
132
|
+
a = !0;
|
|
133
|
+
break;
|
|
134
|
+
}
|
|
135
|
+
await l(n, `${u}${e.name}/`);
|
|
136
|
+
}
|
|
137
|
+
} catch {}
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
for (let t of e) await l(t, "");
|
|
141
|
+
return {
|
|
142
|
+
entries: i,
|
|
143
|
+
truncated: a,
|
|
144
|
+
skippedFolders: c
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
function D(e) {
|
|
148
|
+
try {
|
|
149
|
+
let t = JSON.parse(e.responseText), n = t.url ?? t.location;
|
|
150
|
+
if (typeof n == "string") return { url: n };
|
|
151
|
+
} catch {}
|
|
152
|
+
let t = e.getResponseHeader("Location");
|
|
153
|
+
return t ? { url: t } : void 0;
|
|
154
|
+
}
|
|
155
|
+
function O(e, t = {}) {
|
|
156
|
+
let { method: n = "POST", headers: r, fieldName: i = "file", extraFields: a, body: o = "form-data", withCredentials: s, timeout: c, parseResponse: l = D } = t;
|
|
157
|
+
return (t, { signal: u, onProgress: d }) => new Promise((f, p) => {
|
|
158
|
+
let m = () => new DOMException("Upload aborted", "AbortError");
|
|
159
|
+
if (u.aborted) return p(m());
|
|
160
|
+
let h = new XMLHttpRequest();
|
|
161
|
+
h.open(n, typeof e == "function" ? e(t) : e), s && (h.withCredentials = !0), c && (h.timeout = c);
|
|
162
|
+
for (let [e, t] of Object.entries(r ?? {})) h.setRequestHeader(e, t);
|
|
163
|
+
let g = () => h.abort(), _ = () => u.removeEventListener("abort", g);
|
|
164
|
+
if (u.addEventListener("abort", g), h.upload.onprogress = (e) => {
|
|
165
|
+
e.lengthComputable && e.total > 0 && d(e.loaded / e.total);
|
|
166
|
+
}, h.onload = () => {
|
|
167
|
+
if (_(), h.status >= 200 && h.status < 300) try {
|
|
168
|
+
f(l(h));
|
|
169
|
+
} catch (e) {
|
|
170
|
+
p(e instanceof Error ? e : /* @__PURE__ */ Error("Unreadable response"));
|
|
171
|
+
}
|
|
172
|
+
else p(/* @__PURE__ */ Error(`Upload failed (${h.status}${h.statusText ? ` ${h.statusText}` : ""})`));
|
|
173
|
+
}, h.onerror = () => {
|
|
174
|
+
_(), p(/* @__PURE__ */ Error("Network error"));
|
|
175
|
+
}, h.ontimeout = () => {
|
|
176
|
+
_(), p(/* @__PURE__ */ Error("The upload timed out"));
|
|
177
|
+
}, h.onabort = () => {
|
|
178
|
+
_(), p(m());
|
|
179
|
+
}, o === "raw") h.send(t);
|
|
180
|
+
else {
|
|
181
|
+
let e = new FormData();
|
|
182
|
+
for (let [n, r] of Object.entries(typeof a == "function" ? a(t) : a ?? {})) e.append(n, r);
|
|
183
|
+
e.append(i, t, t.name), h.send(e);
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
var k = (e) => Number.isFinite(e) ? Math.min(1, Math.max(0, e)) : 0;
|
|
188
|
+
function A(e = {}) {
|
|
189
|
+
let [o, s] = a(e.defaultFiles ?? []), c = e.files ?? o, l = i({
|
|
190
|
+
options: e,
|
|
191
|
+
files: c
|
|
192
|
+
});
|
|
193
|
+
n(() => {
|
|
194
|
+
l.current = {
|
|
195
|
+
options: e,
|
|
196
|
+
files: c
|
|
197
|
+
};
|
|
198
|
+
});
|
|
199
|
+
let u = i(c);
|
|
200
|
+
u.current = c;
|
|
201
|
+
let d = i(/* @__PURE__ */ new Map()), f = i(/* @__PURE__ */ new Set()), p = i(!1), m = t((e) => {
|
|
202
|
+
let t = u.current, n = e(t);
|
|
203
|
+
if (n === t) return;
|
|
204
|
+
u.current = n;
|
|
205
|
+
let r = l.current.options;
|
|
206
|
+
r.files === void 0 && s(n), r.onFilesChange?.(n);
|
|
207
|
+
}, []), h = t((e, t) => {
|
|
208
|
+
m((n) => {
|
|
209
|
+
let r = n.findIndex((t) => t.id === e);
|
|
210
|
+
if (r < 0 || Object.keys(t).every((e) => n[r][e] === t[e])) return n;
|
|
211
|
+
let i = n.slice();
|
|
212
|
+
return i[r] = {
|
|
213
|
+
...n[r],
|
|
214
|
+
...t
|
|
215
|
+
}, i;
|
|
216
|
+
});
|
|
217
|
+
}, [m]), g = t((e) => {
|
|
218
|
+
let t = l.current.options.upload;
|
|
219
|
+
if (!t) return;
|
|
220
|
+
let n = new AbortController();
|
|
221
|
+
d.current.set(e.id, n), f.current.delete(e.id), h(e.id, {
|
|
222
|
+
status: "uploading",
|
|
223
|
+
progress: 0,
|
|
224
|
+
error: void 0,
|
|
225
|
+
reason: void 0
|
|
226
|
+
});
|
|
227
|
+
let r = () => u.current.find((t) => t.id === e.id) ?? e, i;
|
|
228
|
+
try {
|
|
229
|
+
i = Promise.resolve(t(e.file, {
|
|
230
|
+
id: e.id,
|
|
231
|
+
path: e.path,
|
|
232
|
+
signal: n.signal,
|
|
233
|
+
onProgress: (t) => {
|
|
234
|
+
d.current.get(e.id) === n && h(e.id, { progress: k(t) });
|
|
235
|
+
}
|
|
236
|
+
}));
|
|
237
|
+
} catch (e) {
|
|
238
|
+
i = Promise.reject(e);
|
|
239
|
+
}
|
|
240
|
+
i.then((t) => {
|
|
241
|
+
d.current.get(e.id) === n && (d.current.delete(e.id), h(e.id, {
|
|
242
|
+
status: "done",
|
|
243
|
+
progress: 1,
|
|
244
|
+
error: void 0,
|
|
245
|
+
url: t?.url
|
|
246
|
+
}), l.current.options.onUploaded?.(r()));
|
|
247
|
+
}, (t) => {
|
|
248
|
+
if (d.current.get(e.id) !== n) return;
|
|
249
|
+
d.current.delete(e.id);
|
|
250
|
+
let i = t instanceof Error && t.message ? t.message : typeof t == "string" && t ? t : "Upload failed";
|
|
251
|
+
h(e.id, {
|
|
252
|
+
status: "error",
|
|
253
|
+
error: i
|
|
254
|
+
}), l.current.options.onUploadError?.(r(), t);
|
|
255
|
+
});
|
|
256
|
+
}, [h]), _ = t(() => {
|
|
257
|
+
let { upload: e, autoUpload: t = !0, concurrency: n = 3 } = l.current.options;
|
|
258
|
+
if (!e) return;
|
|
259
|
+
let r = Math.max(1, Math.floor(n)) - d.current.size;
|
|
260
|
+
for (let e of u.current) {
|
|
261
|
+
if (r <= 0) break;
|
|
262
|
+
!(e.status === "queued" || e.status === "uploading" && !d.current.has(e.id)) || d.current.has(e.id) || (t || p.current || f.current.has(e.id)) && (g(e), r--);
|
|
263
|
+
}
|
|
264
|
+
d.current.size === 0 && !u.current.some((e) => e.status === "queued") && (p.current = !1);
|
|
265
|
+
}, [g]);
|
|
266
|
+
n(() => {
|
|
267
|
+
_();
|
|
268
|
+
}, [
|
|
269
|
+
c,
|
|
270
|
+
e.autoUpload,
|
|
271
|
+
e.concurrency,
|
|
272
|
+
e.upload,
|
|
273
|
+
_
|
|
274
|
+
]), n(() => () => {
|
|
275
|
+
for (let e of d.current.values()) e.abort();
|
|
276
|
+
d.current.clear();
|
|
277
|
+
}, []);
|
|
278
|
+
let v = t((e) => {
|
|
279
|
+
let t = l.current.options, n = C(S(e), u.current, t);
|
|
280
|
+
if (!n.length) return {
|
|
281
|
+
added: [],
|
|
282
|
+
rejected: []
|
|
283
|
+
};
|
|
284
|
+
m((e) => [...e, ...n]);
|
|
285
|
+
let r = n.filter((e) => e.status !== "rejected"), i = n.filter((e) => e.status === "rejected");
|
|
286
|
+
return t.onAdd?.(r, i), {
|
|
287
|
+
added: r,
|
|
288
|
+
rejected: i
|
|
289
|
+
};
|
|
290
|
+
}, [m]), y = t((e) => {
|
|
291
|
+
let t = u.current.find((t) => t.id === e);
|
|
292
|
+
if (!t) return;
|
|
293
|
+
let n = d.current.get(e);
|
|
294
|
+
d.current.delete(e), f.current.delete(e), n?.abort(), m((t) => t.filter((t) => t.id !== e)), l.current.options.onRemove?.(t);
|
|
295
|
+
}, [m]), b = t((e) => {
|
|
296
|
+
let t = u.current.find((t) => t.id === e);
|
|
297
|
+
!t || t.status !== "error" || (f.current.add(e), h(e, {
|
|
298
|
+
status: "queued",
|
|
299
|
+
progress: 0,
|
|
300
|
+
error: void 0
|
|
301
|
+
}));
|
|
302
|
+
}, [h]), x = t(() => {
|
|
303
|
+
for (let e of d.current.values()) e.abort();
|
|
304
|
+
d.current.clear(), f.current.clear(), p.current = !1, m((e) => e.length ? [] : e);
|
|
305
|
+
}, [m]), w = t(() => {
|
|
306
|
+
p.current = !0, _();
|
|
307
|
+
}, [_]), T = r(() => {
|
|
308
|
+
let e = {
|
|
309
|
+
queued: 0,
|
|
310
|
+
uploading: 0,
|
|
311
|
+
done: 0,
|
|
312
|
+
error: 0,
|
|
313
|
+
rejected: 0
|
|
314
|
+
};
|
|
315
|
+
for (let t of c) e[t.status]++;
|
|
316
|
+
return e;
|
|
317
|
+
}, [c]);
|
|
318
|
+
return {
|
|
319
|
+
files: c,
|
|
320
|
+
add: v,
|
|
321
|
+
remove: y,
|
|
322
|
+
retry: b,
|
|
323
|
+
clear: x,
|
|
324
|
+
uploadAll: w,
|
|
325
|
+
isBusy: T.queued + T.uploading > 0,
|
|
326
|
+
counts: T,
|
|
327
|
+
rules: {
|
|
328
|
+
accept: e.accept,
|
|
329
|
+
maxSize: e.maxSize,
|
|
330
|
+
minSize: e.minSize,
|
|
331
|
+
maxFiles: e.maxFiles
|
|
332
|
+
}
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
function j(e, t = !0) {
|
|
336
|
+
let [r, i] = a();
|
|
337
|
+
return n(() => {
|
|
338
|
+
if (!e || !t || typeof URL > "u" || typeof URL.createObjectURL != "function") {
|
|
339
|
+
i(void 0);
|
|
340
|
+
return;
|
|
341
|
+
}
|
|
342
|
+
let n = URL.createObjectURL(e);
|
|
343
|
+
return i(n), () => {
|
|
344
|
+
URL.revokeObjectURL(n);
|
|
345
|
+
};
|
|
346
|
+
}, [e, t]), r;
|
|
347
|
+
}
|
|
348
|
+
//#endregion
|
|
349
|
+
export { u as describeAccept, d as describeRules, T as entriesFromFileList, _ as fileKind, l as matchesAccept, y as newFileId, c as parseAccept, E as readDropItems, x as rejectionMessage, S as toEntries, j as useFilePreview, A as useFileUpload, C as validateFiles, O as xhrUpload };
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { DateValue, Filter, FilterField, FilterOption } from './filter';
|
|
2
|
+
import { Clause, Schema, Weights } from './gpu-query';
|
|
3
|
+
/** The gpu-query schema for a set of fields, and the way back from a schema name to the field. */
|
|
4
|
+
export interface QuerySchema {
|
|
5
|
+
schema: Schema;
|
|
6
|
+
byName: Map<string, FilterField>;
|
|
7
|
+
}
|
|
8
|
+
/** Derives the schema the model is asked about: aliases from each field's label, id and `aliases`; enum values from its options. */
|
|
9
|
+
export declare function buildQuerySchema(fields: readonly FilterField[]): QuerySchema;
|
|
10
|
+
/** The option a typed value names: its label or value exactly, else the one option every typed word fuzzily matches. */
|
|
11
|
+
export declare function matchOption(raw: string, options: readonly FilterOption[]): {
|
|
12
|
+
option?: FilterOption;
|
|
13
|
+
ambiguous?: boolean;
|
|
14
|
+
};
|
|
15
|
+
/** A typed date: "today", "last week", "last 3 days", "3 weeks ago", "2026-01-05", "jan 5", "5 January 2026". */
|
|
16
|
+
export declare function parseDateText(raw: string, now?: number | Date): DateValue | null;
|
|
17
|
+
/** A fragment the phrase contained that did not become a filter, and why. */
|
|
18
|
+
export interface Unresolved {
|
|
19
|
+
text: string;
|
|
20
|
+
reason: string;
|
|
21
|
+
}
|
|
22
|
+
export interface Interpretation {
|
|
23
|
+
filters: Filter[];
|
|
24
|
+
unresolved: Unresolved[];
|
|
25
|
+
/** Things the mapping assumed that the user should know ("read as any of"). */
|
|
26
|
+
notes: string[];
|
|
27
|
+
/** The raw gpu-query clauses, for diagnostics. */
|
|
28
|
+
clauses: Clause[];
|
|
29
|
+
}
|
|
30
|
+
/** The model's view of the phrase, so the mapping can look at the words around a clause (`ParseResult` has all of it). */
|
|
31
|
+
export interface Trace {
|
|
32
|
+
tokens: string[];
|
|
33
|
+
roles: string[];
|
|
34
|
+
/** Token range `[start, end)` of each clause, parallel to the clauses. */
|
|
35
|
+
spans: Array<[number, number]>;
|
|
36
|
+
resolved: Array<{
|
|
37
|
+
field: string;
|
|
38
|
+
} | null>;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Maps gpu-query clauses onto fields: raw option text → option values (exact, then fuzzy), `cmp` + `neg` → operator,
|
|
42
|
+
* dates and numbers parsed. Clauses on one single-valued field with the same polarity merge into "any of".
|
|
43
|
+
*
|
|
44
|
+
* Given the `trace`, it also repairs what the model is known to get wrong, deterministically and visibly:
|
|
45
|
+
* - a negation word ("not", "without") inside a clause makes it negative, whatever role the model gave it;
|
|
46
|
+
* - a comparison on a select field means nothing, so it is ignored (the model often tags "to" and "not" as `<`);
|
|
47
|
+
* - one clause that holds several values ("urgent bob") is split, each word placed on the field that has it;
|
|
48
|
+
* - a date is parsed from the whole clause ("in the last 3 days"), not only the words the model called values.
|
|
49
|
+
*/
|
|
50
|
+
export declare function clausesToFilters(clauses: readonly Clause[], byName: ReadonlyMap<string, FilterField>, { now, trace }?: {
|
|
51
|
+
now?: number | Date;
|
|
52
|
+
trace?: Trace;
|
|
53
|
+
}): Interpretation;
|
|
54
|
+
/** Run one phrase against the fields with weights from `loadModel()`: the synchronous core of `useFilterQuery`. */
|
|
55
|
+
export declare function interpretQuery(model: Weights, text: string, fields: readonly FilterField[], options?: {
|
|
56
|
+
now?: number | Date;
|
|
57
|
+
query?: QuerySchema;
|
|
58
|
+
}): Interpretation;
|
|
59
|
+
interface FilterQueryState extends Omit<Interpretation, 'clauses'> {
|
|
60
|
+
/** `idle` no text · `loading` the model is still downloading · `ready` · `error` it could not load. */
|
|
61
|
+
status: 'idle' | 'loading' | 'ready' | 'error';
|
|
62
|
+
/** The (trimmed) phrase these results are for. */
|
|
63
|
+
text: string;
|
|
64
|
+
/** Typing has moved on and the results are for an earlier phrase (or are about to be computed). */
|
|
65
|
+
pending: boolean;
|
|
66
|
+
error?: Error;
|
|
67
|
+
}
|
|
68
|
+
export interface FilterQueryResult extends FilterQueryState {
|
|
69
|
+
/** Skip the debounce: interpret the current phrase now (the results arrive on the next render). */
|
|
70
|
+
refresh: () => void;
|
|
71
|
+
}
|
|
72
|
+
export interface UseFilterQueryOptions {
|
|
73
|
+
/** Wait this long (ms) after the last keystroke (default 160). */
|
|
74
|
+
debounce?: number;
|
|
75
|
+
/** `false` keeps the hook idle and never loads the model. */
|
|
76
|
+
enabled?: boolean;
|
|
77
|
+
/** Longest phrase parsed, in characters (default 240). */
|
|
78
|
+
maxLength?: number;
|
|
79
|
+
/** "Now" for relative dates (default: the current time). */
|
|
80
|
+
now?: number | Date;
|
|
81
|
+
}
|
|
82
|
+
/** Fetches the model ahead of the first phrase (call it on focus). Resolves either way; errors surface in the hook. */
|
|
83
|
+
export declare function warmFilterQuery(): Promise<void>;
|
|
84
|
+
/**
|
|
85
|
+
* A typed phrase as `Filter[]`: debounced, stale-guarded (an old phrase never overwrites a newer one's result), the
|
|
86
|
+
* weights fetched on first use. Check `unresolved` and `notes` before applying anything.
|
|
87
|
+
*/
|
|
88
|
+
export declare function useFilterQuery(text: string, fields: readonly FilterField[], options?: UseFilterQueryOptions): FilterQueryResult;
|
|
89
|
+
export {};
|
|
90
|
+
//# sourceMappingURL=filter-query.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filter-query.d.ts","sourceRoot":"","sources":["../../src/lib/filter-query.ts"],"names":[],"mappings":"AAEA,OAAO,EAAgB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