wcz-layout 10.2.1 → 11.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/dist/ChatLayout-B0MBrI-Y.mjs +2394 -0
- package/dist/ChatLayout-B0MBrI-Y.mjs.map +1 -0
- package/dist/{Employee-C8xIlBxY.d.mts → ExtractFile-BQUXpuBS.d.mts} +44 -3
- package/dist/FileMeta-B5VU-eCi.d.mts +55 -0
- package/dist/FileMeta-BexXC_45.mjs +35 -0
- package/dist/FileMeta-BexXC_45.mjs.map +1 -0
- package/dist/QueryClientParam-BG9Q_9XU.d.mts +6 -0
- package/dist/Translate-Ad784Dps.d.mts +24 -0
- package/dist/{Approval-D1TfISUL.mjs → Translate-C43AmXYW.mjs} +44 -36
- package/dist/Translate-C43AmXYW.mjs.map +1 -0
- package/dist/User-CvLutatT.d.mts +10 -0
- package/dist/ai.d.mts +31 -4
- package/dist/ai.mjs +154 -10
- package/dist/ai.mjs.map +1 -1
- package/dist/auth.d.mts +7 -14
- package/dist/auth.mjs +15 -38
- package/dist/auth.mjs.map +1 -1
- package/dist/authMiddleware-ANa9Tlmp.mjs +45 -0
- package/dist/authMiddleware-ANa9Tlmp.mjs.map +1 -0
- package/dist/{ChatLayout-BmLySLXy.d.mts → components-2HKj8GpC.d.mts} +219 -255
- package/dist/components.d.mts +2 -126
- package/dist/components.mjs +876 -916
- package/dist/components.mjs.map +1 -1
- package/dist/data/client.d.mts +313 -55
- package/dist/data/client.mjs +10 -5
- package/dist/data/client.mjs.map +1 -1
- package/dist/data/server.d.mts +19 -3
- package/dist/data/server.mjs +3 -5
- package/dist/data/server.mjs.map +1 -1
- package/dist/env-C4WLVJMm.mjs +32 -0
- package/dist/env-C4WLVJMm.mjs.map +1 -0
- package/dist/file-DBqTibcr.mjs +176 -0
- package/dist/file-DBqTibcr.mjs.map +1 -0
- package/dist/file-hecCQszp.mjs +114 -0
- package/dist/file-hecCQszp.mjs.map +1 -0
- package/dist/generatedChart-k7NEdi5Z.mjs.map +1 -1
- package/dist/hooks.d.mts +13 -93
- package/dist/hooks.mjs +353 -1059
- package/dist/hooks.mjs.map +1 -1
- package/dist/i18n-ZRiIIdpb.mjs +563 -0
- package/dist/i18n-ZRiIIdpb.mjs.map +1 -0
- package/dist/index.d.mts +3 -35
- package/dist/index.mjs +630 -680
- package/dist/index.mjs.map +1 -1
- package/dist/layout-DeTB6Ai1.mjs +224 -0
- package/dist/layout-DeTB6Ai1.mjs.map +1 -0
- package/dist/middleware.d.mts +1 -1
- package/dist/middleware.mjs +2 -46
- package/dist/middleware.mjs.map +1 -1
- package/dist/models.d.mts +35 -43
- package/dist/models.mjs +4 -6
- package/dist/models.mjs.map +1 -1
- package/dist/oidc--D2ox365.mjs +97 -0
- package/dist/oidc--D2ox365.mjs.map +1 -0
- package/dist/peoplesoft-DhwB8jrM.d.mts +204 -0
- package/dist/tokens-C4djIAhl.mjs +97 -0
- package/dist/tokens-C4djIAhl.mjs.map +1 -0
- package/dist/useDialogs-QER-2rVG.mjs +297 -0
- package/dist/useDialogs-QER-2rVG.mjs.map +1 -0
- package/dist/user-DQx1BanQ.mjs +120 -0
- package/dist/user-DQx1BanQ.mjs.map +1 -0
- package/dist/{utils-CNYCSgip.d.mts → utils-BnyAEKW7.d.mts} +7 -9
- package/dist/utils-H4BskGF8.mjs +132 -0
- package/dist/utils-H4BskGF8.mjs.map +1 -0
- package/dist/utils.d.mts +21 -4
- package/dist/utils.mjs +5 -4
- package/dist/vite.mjs +98 -32
- package/dist/vite.mjs.map +1 -1
- package/package.json +23 -29
- package/skills/ai/SKILL.md +105 -75
- package/skills/general/SKILL.md +15 -8
- package/skills/general/references/auth.md +15 -17
- package/skills/general/references/languages.md +56 -0
- package/skills/migrations/versions/migrate-v10-to-v11.md +98 -22
- package/skills/migrations/versions/migrate-v9-to-v10.md +22 -22
- package/skills/services/SKILL.md +41 -7
- package/skills/services/docs/email.md +2 -2
- package/skills/services/docs/file.md +100 -85
- package/skills/services/docs/layout.md +129 -0
- package/skills/start/steps/02-project-name-setup.md +1 -1
- package/skills/start/steps/03-apm-setup.md +8 -1
- package/skills/start/steps/06-entra-setup.md +1 -1
- package/skills/start/steps/08-generate-favicon.md +1 -1
- package/skills/table/SKILL.md +18 -5
- package/src/lib/locales/cs.json +120 -0
- package/src/lib/locales/en.json +119 -0
- package/src/lib/locales/uk.json +121 -0
- package/src/lib/locales/zh-TW.json +118 -0
- package/dist/Approval-D1TfISUL.mjs.map +0 -1
- package/dist/ChatLayout-BpRj5rlH.mjs +0 -1639
- package/dist/ChatLayout-BpRj5rlH.mjs.map +0 -1
- package/dist/DialogsContext-D23fJjYR.mjs +0 -6
- package/dist/DialogsContext-D23fJjYR.mjs.map +0 -1
- package/dist/Email-Dz5k0UWE.d.mts +0 -15
- package/dist/FileMeta-B39e2FLC.d.mts +0 -17
- package/dist/FileMeta-CPBWI_jA.mjs +0 -18
- package/dist/FileMeta-CPBWI_jA.mjs.map +0 -1
- package/dist/QueryClientParam-CTV1vj76.d.mts +0 -8
- package/dist/RouterListItemButton-CF-8w-08.mjs +0 -62
- package/dist/RouterListItemButton-CF-8w-08.mjs.map +0 -1
- package/dist/User-aJksXItw.d.mts +0 -12
- package/dist/approval-B3ZQn9aH.mjs +0 -83
- package/dist/approval-B3ZQn9aH.mjs.map +0 -1
- package/dist/createApi-BXjkj4fM.mjs +0 -25
- package/dist/createApi-BXjkj4fM.mjs.map +0 -1
- package/dist/env-BwFl7nWc.mjs +0 -48
- package/dist/env-BwFl7nWc.mjs.map +0 -1
- package/dist/file-BQ-Bu2g8.mjs +0 -150
- package/dist/file-BQ-Bu2g8.mjs.map +0 -1
- package/dist/file-DZ0KYhoB.mjs +0 -151
- package/dist/file-DZ0KYhoB.mjs.map +0 -1
- package/dist/peoplesoft-C-zPdRVj.d.mts +0 -161
- package/dist/peoplesoft-CvwdApCK.mjs +0 -125
- package/dist/peoplesoft-CvwdApCK.mjs.map +0 -1
- package/dist/providers-BfFg_3eo.mjs +0 -56
- package/dist/providers-BfFg_3eo.mjs.map +0 -1
- package/dist/session-B_jK90RC.mjs +0 -23
- package/dist/session-B_jK90RC.mjs.map +0 -1
- package/dist/tokens-CkWpu7Qp.mjs +0 -150
- package/dist/tokens-CkWpu7Qp.mjs.map +0 -1
- package/dist/utils-DJx-7b4M.mjs +0 -244
- package/dist/utils-DJx-7b4M.mjs.map +0 -1
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { r as serverEnv } from "./env-C4WLVJMm.mjs";
|
|
2
|
+
import { n as getApiToken } from "./tokens-C4djIAhl.mjs";
|
|
3
|
+
import { n as FilePermissionsSchema } from "./FileMeta-BexXC_45.mjs";
|
|
4
|
+
import { appName } from "virtual:wcz-layout";
|
|
5
|
+
import { createServerOnlyFn } from "@tanstack/react-start";
|
|
6
|
+
import { z as z$1 } from "zod";
|
|
7
|
+
import axios, { AxiosError } from "axios";
|
|
8
|
+
import { uuidv7 } from "uuidv7";
|
|
9
|
+
import https from "node:https";
|
|
10
|
+
// src/lib/createApi.ts
|
|
11
|
+
const httpsAgent = new https.Agent({ rejectUnauthorized: false });
|
|
12
|
+
const createApi = createServerOnlyFn(async ({ baseURL, scopeKey }) => {
|
|
13
|
+
const resolvedBaseURL = serverEnv[baseURL];
|
|
14
|
+
if (!resolvedBaseURL) throw new Error(`"${baseURL}" is not set: name it in src/env.ts.`);
|
|
15
|
+
const accessToken = await getApiToken(scopeKey);
|
|
16
|
+
const api = axios.create({
|
|
17
|
+
baseURL: resolvedBaseURL,
|
|
18
|
+
httpsAgent,
|
|
19
|
+
headers: { Authorization: `Bearer ${accessToken}` }
|
|
20
|
+
});
|
|
21
|
+
api.interceptors.response.use(void 0, (error) => {
|
|
22
|
+
if (error instanceof AxiosError) throw new Error(error.response?.data?.message ?? error.message);
|
|
23
|
+
throw error;
|
|
24
|
+
});
|
|
25
|
+
return api;
|
|
26
|
+
});
|
|
27
|
+
// src/data/server/file.ts
|
|
28
|
+
const SubIdSchema = z$1.string().min(1).max(255);
|
|
29
|
+
const AppNameSchema = z$1.string().trim().min(1).max(255).optional().transform((value) => value ?? appName);
|
|
30
|
+
const GetFileMetasSchema = z$1.object({
|
|
31
|
+
subId: SubIdSchema,
|
|
32
|
+
appName: AppNameSchema
|
|
33
|
+
});
|
|
34
|
+
const FileSchema = z$1.object({ id: z$1.uuid() });
|
|
35
|
+
/** Each field sent replaces its value; `permissions` as a whole. `fileName` is the base name. */
|
|
36
|
+
const UpdateFileMetaSchema = FileSchema.extend({
|
|
37
|
+
fileName: z$1.string().trim().min(1).max(255).optional(),
|
|
38
|
+
subId: SubIdSchema.optional(),
|
|
39
|
+
public: z$1.boolean().optional(),
|
|
40
|
+
permissions: FilePermissionsSchema.optional()
|
|
41
|
+
});
|
|
42
|
+
/** `public` and `permissions` decide who reads and changes the file; omitted: every employee. */
|
|
43
|
+
const CreateUploadSchema = z$1.object({
|
|
44
|
+
id: z$1.uuidv7(),
|
|
45
|
+
subId: SubIdSchema,
|
|
46
|
+
appName: AppNameSchema,
|
|
47
|
+
/** With the extension, which decides the type. */
|
|
48
|
+
fileName: z$1.string().trim().min(1).max(255),
|
|
49
|
+
size: z$1.number().int().min(0),
|
|
50
|
+
public: z$1.boolean().optional(),
|
|
51
|
+
permissions: FilePermissionsSchema.optional()
|
|
52
|
+
});
|
|
53
|
+
const UploadFileSchema = CreateUploadSchema.omit({
|
|
54
|
+
fileName: true,
|
|
55
|
+
size: true
|
|
56
|
+
}).extend({
|
|
57
|
+
id: z$1.uuidv7().default(uuidv7),
|
|
58
|
+
file: z$1.instanceof(File)
|
|
59
|
+
});
|
|
60
|
+
const RETRIES = 8;
|
|
61
|
+
const wait = (ms, signal) => new Promise((resolve, reject) => {
|
|
62
|
+
const abort = () => {
|
|
63
|
+
clearTimeout(timer);
|
|
64
|
+
reject(signal?.reason);
|
|
65
|
+
};
|
|
66
|
+
const timer = setTimeout(() => {
|
|
67
|
+
signal?.removeEventListener("abort", abort);
|
|
68
|
+
resolve();
|
|
69
|
+
}, ms);
|
|
70
|
+
signal?.addEventListener("abort", abort, { once: true });
|
|
71
|
+
});
|
|
72
|
+
/**
|
|
73
|
+
* Sends `file` to an upload session in chunks and returns the created file. A failed chunk is
|
|
74
|
+
* sent again after a back-off (about 2 minutes in total): when the service already has its
|
|
75
|
+
* bytes it answers 409 with its offset, and the upload continues from there.
|
|
76
|
+
*/
|
|
77
|
+
async function sendChunks(file, chunkSize, put, signal) {
|
|
78
|
+
let offset = 0;
|
|
79
|
+
let failures = 0;
|
|
80
|
+
for (;;) {
|
|
81
|
+
signal?.throwIfAborted();
|
|
82
|
+
const end = Math.min(offset + chunkSize, file.size);
|
|
83
|
+
const { status, body } = end > offset ? await put(`bytes ${offset}-${end - 1}/${file.size}`, file.slice(offset, end), offset) : await put(`bytes */${file.size}`, null, offset);
|
|
84
|
+
if (status === 201) return body;
|
|
85
|
+
const next = body?.offset;
|
|
86
|
+
if ((status === 200 || status === 409) && typeof next === "number" && next !== offset) {
|
|
87
|
+
offset = next;
|
|
88
|
+
failures = 0;
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
if (!(status === 0 || status === 408 || status === 429 || status >= 500) || ++failures > RETRIES) {
|
|
92
|
+
const message = body?.message;
|
|
93
|
+
throw new Error(typeof message === "string" ? message : status ? `File upload failed (HTTP ${status}).` : "File upload failed: network error.");
|
|
94
|
+
}
|
|
95
|
+
await wait(Math.min(1e3 * 2 ** (failures - 1), 3e4), signal);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
const fileApi = () => createApi({
|
|
99
|
+
baseURL: "FILE_BASE_URL",
|
|
100
|
+
scopeKey: "file"
|
|
101
|
+
});
|
|
102
|
+
const getFileMetas = createServerOnlyFn(async ({ data }) => {
|
|
103
|
+
const { subId, appName } = GetFileMetasSchema.parse(data);
|
|
104
|
+
const api = await fileApi();
|
|
105
|
+
const params = {
|
|
106
|
+
appName,
|
|
107
|
+
subId
|
|
108
|
+
};
|
|
109
|
+
const { data: fileMetas } = await api.get("/files", { params });
|
|
110
|
+
return fileMetas;
|
|
111
|
+
});
|
|
112
|
+
const getFileMeta = createServerOnlyFn(async ({ data }) => {
|
|
113
|
+
const { id } = FileSchema.parse(data);
|
|
114
|
+
const { data: fileMeta } = await (await fileApi()).get(`/files/${id}/meta`);
|
|
115
|
+
return fileMeta;
|
|
116
|
+
});
|
|
117
|
+
const updateFileMeta = createServerOnlyFn(async ({ data }) => {
|
|
118
|
+
const { id, ...changes } = UpdateFileMetaSchema.parse(data);
|
|
119
|
+
const { data: fileMeta } = await (await fileApi()).patch(`/files/${id}`, changes);
|
|
120
|
+
return fileMeta;
|
|
121
|
+
});
|
|
122
|
+
const deleteFile = createServerOnlyFn(async ({ data }) => {
|
|
123
|
+
const { id } = FileSchema.parse(data);
|
|
124
|
+
await (await fileApi()).delete(`/files/${id}`);
|
|
125
|
+
});
|
|
126
|
+
/** Deletes every file under `subId`, or none when the user can't delete one of them. */
|
|
127
|
+
const batchDeleteFiles = createServerOnlyFn(async ({ data }) => {
|
|
128
|
+
const { subId, appName } = GetFileMetasSchema.parse(data);
|
|
129
|
+
await (await fileApi()).delete("/files", { params: {
|
|
130
|
+
appName,
|
|
131
|
+
subId
|
|
132
|
+
} });
|
|
133
|
+
});
|
|
134
|
+
/** Starts an upload; the bytes go to the returned `uploadUrl` (see `sendChunks`). */
|
|
135
|
+
const createUpload = createServerOnlyFn(async ({ data }) => {
|
|
136
|
+
const { appName, ...input } = CreateUploadSchema.parse(data);
|
|
137
|
+
const { data: session } = await (await fileApi()).post("/uploads", {
|
|
138
|
+
...input,
|
|
139
|
+
appName
|
|
140
|
+
});
|
|
141
|
+
return session;
|
|
142
|
+
});
|
|
143
|
+
/** Uploads from the server, e.g. a generated report. Browsers use `uploadFileMutationOptions`. */
|
|
144
|
+
const uploadFile = createServerOnlyFn(async ({ data }) => {
|
|
145
|
+
const { file, ...input } = UploadFileSchema.parse(data);
|
|
146
|
+
const { uploadUrl, chunkSize } = await createUpload({ data: {
|
|
147
|
+
...input,
|
|
148
|
+
fileName: file.name,
|
|
149
|
+
size: file.size
|
|
150
|
+
} });
|
|
151
|
+
const api = await fileApi();
|
|
152
|
+
return sendChunks(file, chunkSize, async (range, chunk) => {
|
|
153
|
+
try {
|
|
154
|
+
const body = chunk ? Buffer.from(await chunk.arrayBuffer()) : void 0;
|
|
155
|
+
const response = await api.put(uploadUrl, body, {
|
|
156
|
+
headers: {
|
|
157
|
+
"Content-Range": range,
|
|
158
|
+
"Content-Type": "application/octet-stream"
|
|
159
|
+
},
|
|
160
|
+
validateStatus: () => true
|
|
161
|
+
});
|
|
162
|
+
return {
|
|
163
|
+
status: response.status,
|
|
164
|
+
body: response.data
|
|
165
|
+
};
|
|
166
|
+
} catch {
|
|
167
|
+
return {
|
|
168
|
+
status: 0,
|
|
169
|
+
body: null
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
});
|
|
174
|
+
export { UploadFileSchema as a, deleteFile as c, sendChunks as d, updateFileMeta as f, UpdateFileMetaSchema as i, getFileMeta as l, createApi as m, FileSchema as n, batchDeleteFiles as o, uploadFile as p, GetFileMetasSchema as r, createUpload as s, CreateUploadSchema as t, getFileMetas as u };
|
|
175
|
+
|
|
176
|
+
//# sourceMappingURL=file-DBqTibcr.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-DBqTibcr.mjs","names":["z","defaultAppName"],"sources":["../src/lib/createApi.ts","../src/data/server/file.ts"],"sourcesContent":["import { createServerOnlyFn } from \"@tanstack/react-start\";\nimport axios, { AxiosError, type AxiosInstance } from \"axios\";\nimport https from \"node:https\";\nimport type { z } from \"zod\";\nimport { serverEnv } from \"~/lib/env\";\nimport { scopes as definedScopes } from \"virtual:wcz-layout\";\nimport type { env } from \"virtual:wcz-layout\";\nimport { getApiToken } from \"~/lib/auth/tokens\";\n\ntype Server = typeof env.server;\n\nexport interface ApiOptions {\n baseURL: {\n [Key in keyof Server]: Server[Key] extends z.ZodURL | z.ZodOptional<z.ZodURL> ? Key : never;\n }[keyof Server];\n scopeKey: keyof typeof definedScopes;\n}\n\nconst httpsAgent = new https.Agent({\n rejectUnauthorized: false,\n});\n\nexport const createApi = createServerOnlyFn(\n async ({ baseURL, scopeKey }: ApiOptions): Promise<AxiosInstance> => {\n const resolvedBaseURL = serverEnv[baseURL];\n if (!resolvedBaseURL) throw new Error(`\"${baseURL}\" is not set: name it in src/env.ts.`);\n\n const accessToken = await getApiToken(scopeKey);\n\n const api = axios.create({\n baseURL: resolvedBaseURL,\n httpsAgent,\n headers: { Authorization: `Bearer ${accessToken}` },\n });\n\n api.interceptors.response.use(undefined, (error: unknown) => {\n if (error instanceof AxiosError)\n throw new Error(error.response?.data?.message ?? error.message);\n throw error;\n });\n\n return api;\n },\n);\n","import { createServerOnlyFn } from \"@tanstack/react-start\";\nimport { uuidv7 } from \"uuidv7\";\nimport { appName as defaultAppName } from \"virtual:wcz-layout\";\nimport { z } from \"zod\";\nimport { createApi } from \"~/lib/createApi\";\nimport type { FileMeta } from \"~/models/file/FileMeta\";\nimport { FilePermissionsSchema } from \"~/models/file/FileMeta\";\n\nconst SubIdSchema = z.string().min(1).max(255);\n// Another app's files; the service always needs one, by default the app's package.json name.\nconst AppNameSchema = z\n .string()\n .trim()\n .min(1)\n .max(255)\n .optional()\n .transform((value) => value ?? defaultAppName);\n\nexport const GetFileMetasSchema = z.object({ subId: SubIdSchema, appName: AppNameSchema });\n\nexport const FileSchema = z.object({ id: z.uuid() });\n\n/** Each field sent replaces its value; `permissions` as a whole. `fileName` is the base name. */\nexport const UpdateFileMetaSchema = FileSchema.extend({\n fileName: z.string().trim().min(1).max(255).optional(),\n subId: SubIdSchema.optional(),\n public: z.boolean().optional(),\n permissions: FilePermissionsSchema.optional(),\n});\n\n/** `public` and `permissions` decide who reads and changes the file; omitted: every employee. */\nexport const CreateUploadSchema = z.object({\n id: z.uuidv7(),\n subId: SubIdSchema,\n appName: AppNameSchema,\n /** With the extension, which decides the type. */\n fileName: z.string().trim().min(1).max(255),\n size: z.number().int().min(0),\n public: z.boolean().optional(),\n permissions: FilePermissionsSchema.optional(),\n});\n\nexport const UploadFileSchema = CreateUploadSchema.omit({ fileName: true, size: true }).extend({\n id: z.uuidv7().default(uuidv7),\n file: z.instanceof(File),\n});\n\n/** The browser sends the bytes to `uploadUrl` itself, signed for this one upload for 24 h. */\nexport interface UploadSession {\n uploadUrl: string;\n chunkSize: number;\n}\n\n/** What one chunk `PUT` answered; `status` 0 means no answer arrived. */\nexport interface ChunkResponse {\n status: number;\n body: unknown;\n}\n\n/** Sends one chunk: `Content-Range` header and body; `offset` is where the chunk starts. */\nexport type PutChunk = (\n range: string,\n chunk: Blob | null,\n offset: number,\n) => Promise<ChunkResponse>;\n\nconst RETRIES = 8;\n\nconst wait = (ms: number, signal?: AbortSignal) =>\n new Promise<void>((resolve, reject) => {\n const abort = () => {\n clearTimeout(timer);\n reject(signal?.reason);\n };\n const timer = setTimeout(() => {\n signal?.removeEventListener(\"abort\", abort);\n resolve();\n }, ms);\n signal?.addEventListener(\"abort\", abort, { once: true });\n });\n\n/**\n * Sends `file` to an upload session in chunks and returns the created file. A failed chunk is\n * sent again after a back-off (about 2 minutes in total): when the service already has its\n * bytes it answers 409 with its offset, and the upload continues from there.\n */\nexport async function sendChunks(\n file: Blob,\n chunkSize: number,\n put: PutChunk,\n signal?: AbortSignal,\n): Promise<FileMeta> {\n let offset = 0;\n let failures = 0;\n for (;;) {\n signal?.throwIfAborted();\n const end = Math.min(offset + chunkSize, file.size);\n // An empty `bytes */size` request finishes an upload whose bytes are all there.\n const { status, body } =\n end > offset\n ? await put(`bytes ${offset}-${end - 1}/${file.size}`, file.slice(offset, end), offset)\n : await put(`bytes */${file.size}`, null, offset);\n if (status === 201) return body as FileMeta;\n\n const next = (body as { offset?: unknown } | null)?.offset;\n if ((status === 200 || status === 409) && typeof next === \"number\" && next !== offset) {\n offset = next;\n failures = 0;\n continue;\n }\n // No answer, timeouts, throttling and server errors are worth another try.\n const transient = status === 0 || status === 408 || status === 429 || status >= 500;\n if (!transient || ++failures > RETRIES) {\n const message = (body as { message?: unknown } | null)?.message;\n throw new Error(\n typeof message === \"string\"\n ? message\n : status\n ? `File upload failed (HTTP ${status}).`\n : \"File upload failed: network error.\",\n );\n }\n await wait(Math.min(1000 * 2 ** (failures - 1), 30_000), signal);\n }\n}\n\n// The user's token, or the app's when nobody is signed in: then only files without access\n// lists are open, as for an employee without groups.\nconst fileApi = () => createApi({ baseURL: \"FILE_BASE_URL\", scopeKey: \"file\" });\n\nexport const getFileMetas = createServerOnlyFn(\n async ({ data }: { data: z.input<typeof GetFileMetasSchema> }): Promise<Array<FileMeta>> => {\n const { subId, appName } = GetFileMetasSchema.parse(data);\n const api = await fileApi();\n const params = { appName, subId };\n const { data: fileMetas } = await api.get<Array<FileMeta>>(\"/files\", { params });\n return fileMetas;\n },\n);\n\nexport const getFileMeta = createServerOnlyFn(\n async ({ data }: { data: z.input<typeof FileSchema> }): Promise<FileMeta> => {\n const { id } = FileSchema.parse(data);\n const api = await fileApi();\n const { data: fileMeta } = await api.get<FileMeta>(`/files/${id}/meta`);\n return fileMeta;\n },\n);\n\nexport const updateFileMeta = createServerOnlyFn(\n async ({ data }: { data: z.input<typeof UpdateFileMetaSchema> }): Promise<FileMeta> => {\n const { id, ...changes } = UpdateFileMetaSchema.parse(data);\n const api = await fileApi();\n const { data: fileMeta } = await api.patch<FileMeta>(`/files/${id}`, changes);\n return fileMeta;\n },\n);\n\nexport const deleteFile = createServerOnlyFn(\n async ({ data }: { data: z.input<typeof FileSchema> }): Promise<void> => {\n const { id } = FileSchema.parse(data);\n const api = await fileApi();\n await api.delete(`/files/${id}`);\n },\n);\n\n/** Deletes every file under `subId`, or none when the user can't delete one of them. */\nexport const batchDeleteFiles = createServerOnlyFn(\n async ({ data }: { data: z.input<typeof GetFileMetasSchema> }): Promise<void> => {\n const { subId, appName } = GetFileMetasSchema.parse(data);\n const api = await fileApi();\n await api.delete(\"/files\", { params: { appName, subId } });\n },\n);\n\n/** Starts an upload; the bytes go to the returned `uploadUrl` (see `sendChunks`). */\nexport const createUpload = createServerOnlyFn(\n async ({ data }: { data: z.input<typeof CreateUploadSchema> }): Promise<UploadSession> => {\n const { appName, ...input } = CreateUploadSchema.parse(data);\n const api = await fileApi();\n const { data: session } = await api.post<UploadSession>(\"/uploads\", { ...input, appName });\n return session;\n },\n);\n\n/** Uploads from the server, e.g. a generated report. Browsers use `uploadFileMutationOptions`. */\nexport const uploadFile = createServerOnlyFn(\n async ({ data }: { data: z.input<typeof UploadFileSchema> }): Promise<FileMeta> => {\n const { file, ...input } = UploadFileSchema.parse(data);\n const { uploadUrl, chunkSize } = await createUpload({\n data: { ...input, fileName: file.name, size: file.size },\n });\n const api = await fileApi();\n return sendChunks(file, chunkSize, async (range, chunk) => {\n try {\n const body = chunk ? Buffer.from(await chunk.arrayBuffer()) : undefined;\n const response = await api.put(uploadUrl, body, {\n headers: { \"Content-Range\": range, \"Content-Type\": \"application/octet-stream\" },\n validateStatus: () => true,\n });\n return { status: response.status, body: response.data };\n } catch {\n return { status: 0, body: null };\n }\n });\n },\n);\n"],"mappings":";;;;;;;;;;AAkBA,MAAM,aAAa,IAAI,MAAM,MAAM,EACjC,oBAAoB,MACtB,CAAC;AAED,MAAa,YAAY,mBACvB,OAAO,EAAE,SAAS,eAAmD;CACnE,MAAM,kBAAkB,UAAU;CAClC,IAAI,CAAC,iBAAiB,MAAM,IAAI,MAAM,IAAI,QAAQ,qCAAqC;CAEvF,MAAM,cAAc,MAAM,YAAY,QAAQ;CAE9C,MAAM,MAAM,MAAM,OAAO;EACvB,SAAS;EACT;EACA,SAAS,EAAE,eAAe,UAAU,cAAc;CACpD,CAAC;CAED,IAAI,aAAa,SAAS,IAAI,KAAA,IAAY,UAAmB;EAC3D,IAAI,iBAAiB,YACnB,MAAM,IAAI,MAAM,MAAM,UAAU,MAAM,WAAW,MAAM,OAAO;EAChE,MAAM;CACR,CAAC;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AAc,MAAM,aAAa,EAClD,MAAM;EAAE,GAAG;EAAO,UAAU,KAAK;EAAM,MAAM,KAAK;CAAK,EACzD,CAAC;CACD,MAAM,MAAM,MAAM,QAAQ;CAC1B,OAAO,WAAW,MAAM,WAAW,OAAO,OAAO,UAAU;EACzD,IAAI;GACF,MAAM,OAAO,QAAQ,OAAO,KAAK,MAAM,MAAM,YAAY,CAAC,IAAI,KAAA;GAC9D,MAAM,WAAW,MAAM,IAAI,IAAI,WAAW,MAAM;IAC9C,SAAS;KAAE,iBAAiB;KAAO,gBAAgB;IAA2B;IAC9E,sBAAsB;GACxB,CAAC;GACD,OAAO;IAAE,QAAQ,SAAS;IAAQ,MAAM,SAAS;GAAK;EACxD,QAAQ;GACN,OAAO;IAAE,QAAQ;IAAG,MAAM;GAAK;EACjC;CACF,CAAC;AACH,CACF"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { c as deleteFile, d as sendChunks, f as updateFileMeta, i as UpdateFileMetaSchema, l as getFileMeta, n as FileSchema, o as batchDeleteFiles, r as GetFileMetasSchema, s as createUpload, t as CreateUploadSchema, u as getFileMetas } from "./file-DBqTibcr.mjs";
|
|
2
|
+
import { mutationOptions, queryOptions } from "@tanstack/react-query";
|
|
3
|
+
import { createServerFn } from "@tanstack/react-start";
|
|
4
|
+
import { uuidv7 } from "uuidv7";
|
|
5
|
+
// src/data/client/file.ts
|
|
6
|
+
const QUERY_KEY = "file";
|
|
7
|
+
const HOUR = 36e5;
|
|
8
|
+
const getFileMetasRpc = createServerFn({ method: "GET" }).validator(GetFileMetasSchema).handler(({ data }) => getFileMetas({ data }));
|
|
9
|
+
const getFileMetaRpc = createServerFn({ method: "GET" }).validator(FileSchema).handler(({ data }) => getFileMeta({ data }));
|
|
10
|
+
const updateFileMetaRpc = createServerFn({ method: "POST" }).validator(UpdateFileMetaSchema).handler(({ data }) => updateFileMeta({ data }));
|
|
11
|
+
const deleteFileRpc = createServerFn({ method: "POST" }).validator(FileSchema).handler(({ data }) => deleteFile({ data }));
|
|
12
|
+
const batchDeleteFilesRpc = createServerFn({ method: "POST" }).validator(GetFileMetasSchema).handler(({ data }) => batchDeleteFiles({ data }));
|
|
13
|
+
const createUploadRpc = createServerFn({ method: "POST" }).validator(CreateUploadSchema).handler(({ data }) => createUpload({ data }));
|
|
14
|
+
const baseOptions = {
|
|
15
|
+
staleTime: HOUR,
|
|
16
|
+
gcTime: HOUR,
|
|
17
|
+
refetchInterval: HOUR
|
|
18
|
+
};
|
|
19
|
+
const fileMetasQueryOptions = (params) => queryOptions({
|
|
20
|
+
queryKey: [
|
|
21
|
+
QUERY_KEY,
|
|
22
|
+
"meta",
|
|
23
|
+
"subId",
|
|
24
|
+
params.subId,
|
|
25
|
+
params.appName
|
|
26
|
+
],
|
|
27
|
+
queryFn: () => getFileMetasRpc({ data: params }),
|
|
28
|
+
...baseOptions
|
|
29
|
+
});
|
|
30
|
+
const fileMetaQueryOptions = (params) => queryOptions({
|
|
31
|
+
queryKey: [
|
|
32
|
+
QUERY_KEY,
|
|
33
|
+
"meta",
|
|
34
|
+
params.id
|
|
35
|
+
],
|
|
36
|
+
queryFn: () => getFileMetaRpc({ data: params }),
|
|
37
|
+
enabled: !!params.id,
|
|
38
|
+
...baseOptions
|
|
39
|
+
});
|
|
40
|
+
const updateFileMetaMutationOptions = ({ queryClient }) => mutationOptions({
|
|
41
|
+
mutationFn: (data) => updateFileMetaRpc({ data }),
|
|
42
|
+
onSettled: () => queryClient.invalidateQueries({
|
|
43
|
+
queryKey: [QUERY_KEY, "meta"],
|
|
44
|
+
exact: false
|
|
45
|
+
})
|
|
46
|
+
});
|
|
47
|
+
const deleteFileMutationOptions = ({ queryClient }) => mutationOptions({
|
|
48
|
+
mutationFn: (data) => deleteFileRpc({ data }),
|
|
49
|
+
onSettled: () => queryClient.invalidateQueries({
|
|
50
|
+
queryKey: [QUERY_KEY, "meta"],
|
|
51
|
+
exact: false
|
|
52
|
+
})
|
|
53
|
+
});
|
|
54
|
+
const batchDeleteFilesMutationOptions = ({ queryClient }) => mutationOptions({
|
|
55
|
+
mutationFn: (data) => batchDeleteFilesRpc({ data }),
|
|
56
|
+
onSettled: () => queryClient.invalidateQueries({
|
|
57
|
+
queryKey: [QUERY_KEY, "meta"],
|
|
58
|
+
exact: false
|
|
59
|
+
})
|
|
60
|
+
});
|
|
61
|
+
/** One chunk with XMLHttpRequest: `fetch` reports no upload progress. */
|
|
62
|
+
function putChunk(url, range, chunk, onProgress, signal) {
|
|
63
|
+
return new Promise((resolve, reject) => {
|
|
64
|
+
const xhr = new XMLHttpRequest();
|
|
65
|
+
const abort = () => xhr.abort();
|
|
66
|
+
xhr.open("PUT", url);
|
|
67
|
+
xhr.setRequestHeader("Content-Range", range);
|
|
68
|
+
xhr.responseType = "json";
|
|
69
|
+
xhr.timeout = 12e4;
|
|
70
|
+
xhr.upload.onprogress = (event) => onProgress(event.loaded);
|
|
71
|
+
xhr.onload = () => resolve({
|
|
72
|
+
status: xhr.status,
|
|
73
|
+
body: xhr.response
|
|
74
|
+
});
|
|
75
|
+
xhr.onerror = xhr.ontimeout = () => resolve({
|
|
76
|
+
status: 0,
|
|
77
|
+
body: null
|
|
78
|
+
});
|
|
79
|
+
xhr.onabort = () => reject(signal?.reason ?? new DOMException("Upload aborted.", "AbortError"));
|
|
80
|
+
xhr.onloadend = () => signal?.removeEventListener("abort", abort);
|
|
81
|
+
signal?.addEventListener("abort", abort, { once: true });
|
|
82
|
+
xhr.send(chunk);
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* The browser sends the bytes straight to the file service, in 1 MiB chunks, through a URL
|
|
87
|
+
* signed for this one upload: no Entra token reaches the browser.
|
|
88
|
+
*/
|
|
89
|
+
const uploadFileMutationOptions = ({ queryClient }) => mutationOptions({
|
|
90
|
+
mutationFn: async ({ id = uuidv7(), file, setProgress, signal, ...input }) => {
|
|
91
|
+
const { uploadUrl, chunkSize } = await createUploadRpc({ data: {
|
|
92
|
+
...input,
|
|
93
|
+
id,
|
|
94
|
+
fileName: file.name,
|
|
95
|
+
size: file.size
|
|
96
|
+
} });
|
|
97
|
+
let sent = 0;
|
|
98
|
+
const progress = (bytes) => {
|
|
99
|
+
sent = Math.max(sent, bytes);
|
|
100
|
+
setProgress?.(file.size ? sent / file.size * 100 : 100);
|
|
101
|
+
};
|
|
102
|
+
return sendChunks(file, chunkSize, (range, chunk, offset) => putChunk(uploadUrl, range, chunk, (loaded) => progress(offset + loaded), signal), signal);
|
|
103
|
+
},
|
|
104
|
+
onSuccess: (_, { subId, appName }) => queryClient.invalidateQueries({ queryKey: [
|
|
105
|
+
QUERY_KEY,
|
|
106
|
+
"meta",
|
|
107
|
+
"subId",
|
|
108
|
+
subId,
|
|
109
|
+
appName
|
|
110
|
+
] })
|
|
111
|
+
});
|
|
112
|
+
export { updateFileMetaMutationOptions as a, fileMetasQueryOptions as i, deleteFileMutationOptions as n, uploadFileMutationOptions as o, fileMetaQueryOptions as r, batchDeleteFilesMutationOptions as t };
|
|
113
|
+
|
|
114
|
+
//# sourceMappingURL=file-hecCQszp.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-hecCQszp.mjs","names":[],"sources":["../src/data/client/file.ts"],"sourcesContent":["import { mutationOptions, queryOptions } from \"@tanstack/react-query\";\nimport { createServerFn } from \"@tanstack/react-start\";\nimport { uuidv7 } from \"uuidv7\";\nimport type { z } from \"zod\";\nimport type { ChunkResponse, UploadFileSchema } from \"~/data/server/file\";\nimport {\n CreateUploadSchema,\n FileSchema,\n GetFileMetasSchema,\n UpdateFileMetaSchema,\n batchDeleteFiles,\n createUpload,\n deleteFile,\n getFileMeta,\n getFileMetas,\n sendChunks,\n updateFileMeta,\n} from \"~/data/server/file\";\nimport type { QueryClientParam } from \"~/models/QueryClientParam\";\n\nconst QUERY_KEY = \"file\";\nconst HOUR = 1000 * 60 * 60;\n\n// Public routes use files too: without a signed-in user these run on the app token, which\n// reaches only files without access lists.\nconst getFileMetasRpc = createServerFn({ method: \"GET\" })\n .validator(GetFileMetasSchema)\n .handler(({ data }) => getFileMetas({ data }));\n\nconst getFileMetaRpc = createServerFn({ method: \"GET\" })\n .validator(FileSchema)\n .handler(({ data }) => getFileMeta({ data }));\n\nconst updateFileMetaRpc = createServerFn({ method: \"POST\" })\n .validator(UpdateFileMetaSchema)\n .handler(({ data }) => updateFileMeta({ data }));\n\nconst deleteFileRpc = createServerFn({ method: \"POST\" })\n .validator(FileSchema)\n .handler(({ data }) => deleteFile({ data }));\n\nconst batchDeleteFilesRpc = createServerFn({ method: \"POST\" })\n .validator(GetFileMetasSchema)\n .handler(({ data }) => batchDeleteFiles({ data }));\n\nconst createUploadRpc = createServerFn({ method: \"POST\" })\n .validator(CreateUploadSchema)\n .handler(({ data }) => createUpload({ data }));\n\n// Signed URLs live 2-3 h: refreshed hourly, and on returning to a tab older than that.\nconst baseOptions = {\n staleTime: HOUR,\n gcTime: HOUR,\n refetchInterval: HOUR,\n};\n\nexport const fileMetasQueryOptions = (params: z.input<typeof GetFileMetasSchema>) =>\n queryOptions({\n queryKey: [QUERY_KEY, \"meta\", \"subId\", params.subId, params.appName],\n queryFn: () => getFileMetasRpc({ data: params }),\n ...baseOptions,\n });\n\nexport const fileMetaQueryOptions = (params: z.input<typeof FileSchema>) =>\n queryOptions({\n queryKey: [QUERY_KEY, \"meta\", params.id],\n queryFn: () => getFileMetaRpc({ data: params }),\n enabled: !!params.id,\n ...baseOptions,\n });\n\nexport const updateFileMetaMutationOptions = ({ queryClient }: QueryClientParam) =>\n mutationOptions({\n mutationFn: (data: z.input<typeof UpdateFileMetaSchema>) => updateFileMetaRpc({ data }),\n onSettled: () => queryClient.invalidateQueries({ queryKey: [QUERY_KEY, \"meta\"], exact: false }),\n });\n\nexport const deleteFileMutationOptions = ({ queryClient }: QueryClientParam) =>\n mutationOptions({\n mutationFn: (data: z.input<typeof FileSchema>) => deleteFileRpc({ data }),\n onSettled: () => queryClient.invalidateQueries({ queryKey: [QUERY_KEY, \"meta\"], exact: false }),\n });\n\nexport const batchDeleteFilesMutationOptions = ({ queryClient }: QueryClientParam) =>\n mutationOptions({\n mutationFn: (data: z.input<typeof GetFileMetasSchema>) => batchDeleteFilesRpc({ data }),\n onSettled: () => queryClient.invalidateQueries({ queryKey: [QUERY_KEY, \"meta\"], exact: false }),\n });\n\n/** One chunk with XMLHttpRequest: `fetch` reports no upload progress. */\nfunction putChunk(\n url: string,\n range: string,\n chunk: Blob | null,\n onProgress: (loaded: number) => void,\n signal?: AbortSignal,\n): Promise<ChunkResponse> {\n return new Promise((resolve, reject) => {\n const xhr = new XMLHttpRequest();\n const abort = () => xhr.abort();\n xhr.open(\"PUT\", url);\n xhr.setRequestHeader(\"Content-Range\", range);\n xhr.responseType = \"json\";\n // A stalled connection counts as a failed chunk; 1 MiB in 2 minutes is ~9 KB/s.\n xhr.timeout = 120_000;\n xhr.upload.onprogress = (event) => onProgress(event.loaded);\n xhr.onload = () => resolve({ status: xhr.status, body: xhr.response });\n xhr.onerror = xhr.ontimeout = () => resolve({ status: 0, body: null });\n xhr.onabort = () => reject(signal?.reason ?? new DOMException(\"Upload aborted.\", \"AbortError\"));\n xhr.onloadend = () => signal?.removeEventListener(\"abort\", abort);\n signal?.addEventListener(\"abort\", abort, { once: true });\n xhr.send(chunk);\n });\n}\n\ntype UploadFileInput = Omit<z.input<typeof UploadFileSchema>, \"id\"> & {\n id?: string;\n /** Percent, 0-100. */\n setProgress?: (progress: number) => void;\n /** Aborting stops the upload; the unfinished upload expires on the service after 24 h. */\n signal?: AbortSignal;\n};\n\n/**\n * The browser sends the bytes straight to the file service, in 1 MiB chunks, through a URL\n * signed for this one upload: no Entra token reaches the browser.\n */\nexport const uploadFileMutationOptions = ({ queryClient }: QueryClientParam) =>\n mutationOptions({\n mutationFn: async ({ id = uuidv7(), file, setProgress, signal, ...input }: UploadFileInput) => {\n const { uploadUrl, chunkSize } = await createUploadRpc({\n data: { ...input, id, fileName: file.name, size: file.size },\n });\n // A resent chunk reports from zero again; the bar never moves back.\n let sent = 0;\n const progress = (bytes: number) => {\n sent = Math.max(sent, bytes);\n setProgress?.(file.size ? (sent / file.size) * 100 : 100);\n };\n return sendChunks(\n file,\n chunkSize,\n (range, chunk, offset) =>\n putChunk(uploadUrl, range, chunk, (loaded) => progress(offset + loaded), signal),\n signal,\n );\n },\n onSuccess: (_, { subId, appName }) =>\n queryClient.invalidateQueries({ queryKey: [QUERY_KEY, \"meta\", \"subId\", subId, appName] }),\n });\n"],"mappings":";;;;;AAoBA,MAAM,YAAY;AAClB,MAAM,OAAO;AAIb,MAAM,kBAAkB,eAAe,EAAE,QAAQ,MAAM,CAAC,CAAC,CACtD,UAAU,kBAAkB,CAAC,CAC7B,SAAS,EAAE,WAAW,aAAa,EAAE,KAAK,CAAC,CAAC;AAE/C,MAAM,iBAAiB,eAAe,EAAE,QAAQ,MAAM,CAAC,CAAC,CACrD,UAAU,UAAU,CAAC,CACrB,SAAS,EAAE,WAAW,YAAY,EAAE,KAAK,CAAC,CAAC;AAE9C,MAAM,oBAAoB,eAAe,EAAE,QAAQ,OAAO,CAAC,CAAC,CACzD,UAAU,oBAAoB,CAAC,CAC/B,SAAS,EAAE,WAAW,eAAe,EAAE,KAAK,CAAC,CAAC;AAEjD,MAAM,gBAAgB,eAAe,EAAE,QAAQ,OAAO,CAAC,CAAC,CACrD,UAAU,UAAU,CAAC,CACrB,SAAS,EAAE,WAAW,WAAW,EAAE,KAAK,CAAC,CAAC;AAE7C,MAAM,sBAAsB,eAAe,EAAE,QAAQ,OAAO,CAAC,CAAC,CAC3D,UAAU,kBAAkB,CAAC,CAC7B,SAAS,EAAE,WAAW,iBAAiB,EAAE,KAAK,CAAC,CAAC;AAEnD,MAAM,kBAAkB,eAAe,EAAE,QAAQ,OAAO,CAAC,CAAC,CACvD,UAAU,kBAAkB,CAAC,CAC7B,SAAS,EAAE,WAAW,aAAa,EAAE,KAAK,CAAC,CAAC;AAG/C,MAAM,cAAc;CAClB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;GAAE,QAAQ,IAAI;GAAQ,MAAM,IAAI;EAAS,CAAC;EACrE,IAAI,UAAU,IAAI,kBAAkB,QAAQ;GAAE,QAAQ;GAAG,MAAM;EAAK,CAAC;EACrE,IAAI,gBAAgB,OAAO,QAAQ,UAAU,IAAI,aAAa,mBAAmB,YAAY,CAAC;EAC9F,IAAI,kBAAkB,QAAQ,oBAAoB,SAAS,KAAK;EAChE,QAAQ,iBAAiB,SAAS,OAAO,EAAE,MAAM,KAAK,CAAC;EACvD,IAAI,KAAK,KAAK;CAChB,CAAC;AACH;;;;;AAcA,MAAa,6BAA6B,EAAE,kBAC1C,gBAAgB;CACd,YAAY,OAAO,EAAE,KAAK,OAAO,GAAG,MAAM,aAAa,QAAQ,GAAG,YAA6B;EAC7F,MAAM,EAAE,WAAW,cAAc,MAAM,gBAAgB,EACrD,MAAM;GAAE,GAAG;GAAO;GAAI,UAAU,KAAK;GAAM,MAAM,KAAK;EAAK,EAC7D,CAAC;EAED,IAAI,OAAO;EACX,MAAM,YAAY,UAAkB;GAClC,OAAO,KAAK,IAAI,MAAM,KAAK;GAC3B,cAAc,KAAK,OAAQ,OAAO,KAAK,OAAQ,MAAM,GAAG;EAC1D;EACA,OAAO,WACL,MACA,YACC,OAAO,OAAO,WACb,SAAS,WAAW,OAAO,QAAQ,WAAW,SAAS,SAAS,MAAM,GAAG,MAAM,GACjF,MACF;CACF;CACA,YAAY,GAAG,EAAE,OAAO,cACtB,YAAY,kBAAkB,EAAE,UAAU;EAAC;EAAW;EAAQ;EAAS;EAAO;CAAO,EAAE,CAAC;AAC5F,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generatedChart-k7NEdi5Z.mjs","names":["{ node }: Readonly<{ node: Record<string, unknown> }>","isRecord(node.props) ? node.props : {}","props","defineChart({\n ...(spec as object),\n marks: (Array.isArray(nodes) ? nodes : []).flatMap(markOf),\n scales: { x: positionScale(x), y: positionScale(y) },\n color: {\n range: SERIES,\n ...colors,\n ...(legend\n ? {\n legend: colorLegend(\n isRecord(legend) ? (legend as Parameters<typeof colorLegend>[0]) : {},\n ),\n }\n : {}),\n } as ChartColorOptions,\n tooltip,\n })","children","isRecord(scales) ? scales : {}","isRecord(color) ? color : {}","Array.isArray(nodes) ? nodes : []","typeof ariaDescription === \"string\" && { ariaDescription }","typeof aspectRatio === \"number\"\n ? { aspectRatio }\n : { height: typeof height === \"number\" ? height : 280 }","<Box sx={(theme) => ({ ...palette(LIGHT), ...theme.applyStyles(\"dark\", palette(DARK)) })}>\n <Chart\n definition={definition}\n ariaLabel={typeof ariaLabel === \"string\" ? ariaLabel : \"Chart\"}\n {...(typeof ariaDescription === \"string\" && { ariaDescription })}\n {...(typeof aspectRatio === \"number\"\n ? { aspectRatio }\n : { height: typeof height === \"number\" ? height : 280 })}\n />\n </Box>","typeof ariaLabel === \"string\" ? ariaLabel : \"Chart\"","(theme) => ({ ...palette(LIGHT), ...theme.applyStyles(\"dark\", palette(DARK)) })"
|
|
1
|
+
{"version":3,"file":"generatedChart-k7NEdi5Z.mjs","names":["{ node }: Readonly<{ node: Record<string, unknown> }>","isRecord(node.props) ? node.props : {}","props","defineChart({\n ...(spec as object),\n marks: (Array.isArray(nodes) ? nodes : []).flatMap(markOf),\n scales: { x: positionScale(x), y: positionScale(y) },\n color: {\n range: SERIES,\n ...colors,\n ...(legend\n ? {\n legend: colorLegend(\n isRecord(legend) ? (legend as Parameters<typeof colorLegend>[0]) : {},\n ),\n }\n : {}),\n } as ChartColorOptions,\n tooltip,\n })","children","isRecord(scales) ? scales : {}","isRecord(color) ? color : {}","Array.isArray(nodes) ? nodes : []","typeof ariaDescription === \"string\" && { ariaDescription }","typeof aspectRatio === \"number\"\n ? { aspectRatio }\n : { height: typeof height === \"number\" ? height : 280 }","<Box sx={(theme) => ({ ...palette(LIGHT), ...theme.applyStyles(\"dark\", palette(DARK)) })}>\n <Chart\n definition={definition}\n ariaLabel={typeof ariaLabel === \"string\" ? ariaLabel : \"Chart\"}\n {...(typeof ariaDescription === \"string\" && { ariaDescription })}\n {...(typeof aspectRatio === \"number\"\n ? { aspectRatio }\n : { height: typeof height === \"number\" ? height : 280 })}\n />\n </Box>","typeof ariaLabel === \"string\" ? ariaLabel : \"Chart\"","(theme) => ({ ...palette(LIGHT), ...theme.applyStyles(\"dark\", palette(DARK)) })"],"sources":["../src/components/chat/generatedChart.tsx"],"sourcesContent":["import { Box } from \"@mui/material\";\nimport type { ChartColorOptions, ChartMark, ChartPositionScaleOptions } from \"@tanstack/charts\";\nimport {\n areaX,\n areaY,\n arrow,\n bandX,\n bandY,\n barX,\n barY,\n boxX,\n boxY,\n cell,\n colorLegend,\n crosshair,\n defineChart,\n differenceX,\n differenceY,\n dot,\n frame,\n hexagon,\n linearRegressionX,\n linearRegressionY,\n lineX,\n lineY,\n link,\n rect,\n ridgelineX,\n ridgelineY,\n ruleX,\n ruleY,\n text,\n tickX,\n tickY,\n vector,\n violinX,\n violinY,\n waffleX,\n waffleY,\n} from \"@tanstack/charts\";\nimport { Chart } from \"@tanstack/charts/react\";\nimport { scaleBand } from \"@tanstack/charts/scales/band\";\nimport { scaleLinear } from \"@tanstack/charts/scales/linear\";\nimport { scalePoint } from \"@tanstack/charts/scales/point\";\nimport { tooltip } from \"@tanstack/charts/tooltip\";\nimport type { ChartMarkName } from \"~/lib/ai/tools/ui\";\n\nconst marks = {\n areaX,\n areaY,\n arrow,\n bandX,\n bandY,\n barX,\n barY,\n boxX,\n boxY,\n cell,\n crosshair,\n differenceX,\n differenceY,\n dot,\n frame,\n hexagon,\n lineX,\n lineY,\n linearRegressionX,\n linearRegressionY,\n link,\n rect,\n ridgelineX,\n ridgelineY,\n ruleX,\n ruleY,\n text,\n tickX,\n tickY,\n vector,\n violinX,\n violinY,\n waffleX,\n waffleY,\n} satisfies Record<ChartMarkName, unknown>;\n\n// This order is what passes the colour-blindness checks, on light and on dark paper.\nconst LIGHT = [\n \"#2a78d6\",\n \"#eb6834\",\n \"#1baf7a\",\n \"#eda100\",\n \"#e87ba4\",\n \"#008300\",\n \"#6250d6\",\n \"#e34948\",\n];\nconst DARK = [\n \"#3987e5\",\n \"#d95926\",\n \"#199e70\",\n \"#c98500\",\n \"#d55181\",\n \"#008300\",\n \"#9085e9\",\n \"#e66767\",\n];\nconst SERIES = LIGHT.map((_, index) => `var(--ts-chart-${index + 1})`);\nconst palette = (colors: Array<string>) =>\n Object.fromEntries(colors.map((color, index) => [`--ts-chart-${index + 1}`, color]));\n\nconst BARS = { maxThickness: 24, radius: { end: 4 } };\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === \"object\" && value !== null && !Array.isArray(value);\n\nfunction positionScale(spec: unknown): ChartPositionScaleOptions | null {\n if (spec === null) return null;\n const { scale, padding, domain, ...options } = isRecord(spec) ? spec : {};\n const gap = typeof padding === \"number\" ? padding : undefined;\n const make = () => {\n const made =\n scale === \"band\"\n ? scaleBand().padding(gap ?? 0.2)\n : scale === \"point\"\n ? scalePoint().padding(gap ?? 0.5)\n : scaleLinear();\n return Array.isArray(domain) ? made.domain(domain as never) : made;\n };\n return { ...options, scale: Array.isArray(domain) ? make() : make } as ChartPositionScaleOptions;\n}\n\ntype AnyMark = ChartMark<any, any, any, any, any, any, any>;\n\nfunction markOf(node: unknown): Array<AnyMark> {\n if (!isRecord(node) || typeof node.type !== \"string\" || !Object.hasOwn(marks, node.type))\n return [];\n const type = node.type as ChartMarkName;\n const { data, ...options } = isRecord(node.props) ? node.props : {};\n const make = marks[type] as (...args: Array<unknown>) => AnyMark;\n if (type === \"crosshair\" || type === \"frame\") return [make(options)];\n const rows = Array.isArray(data) ? data : [];\n return [make(rows, type === \"barX\" || type === \"barY\" ? { ...BARS, ...options } : options)];\n}\n\n/** A `Chart` node: its mark children drawn on its scales, with the default tooltip. */\nexport function GeneratedChart({ node }: Readonly<{ node: Record<string, unknown> }>) {\n const props = isRecord(node.props) ? node.props : {};\n const { scales, color, ariaLabel, ariaDescription, height, aspectRatio, children, ...spec } =\n props;\n const { x, y } = isRecord(scales) ? scales : {};\n const { legend, ...colors } = isRecord(color) ? color : {};\n const nodes = node.children ?? children;\n\n const definition = defineChart({\n ...(spec as object),\n marks: (Array.isArray(nodes) ? nodes : []).flatMap(markOf),\n scales: { x: positionScale(x), y: positionScale(y) },\n color: {\n range: SERIES,\n ...colors,\n ...(legend\n ? {\n legend: colorLegend(\n isRecord(legend) ? (legend as Parameters<typeof colorLegend>[0]) : {},\n ),\n }\n : {}),\n } as ChartColorOptions,\n tooltip,\n });\n\n return (\n <Box sx={(theme) => ({ ...palette(LIGHT), ...theme.applyStyles(\"dark\", palette(DARK)) })}>\n <Chart\n definition={definition}\n ariaLabel={typeof ariaLabel === \"string\" ? ariaLabel : \"Chart\"}\n {...(typeof ariaDescription === \"string\" && { ariaDescription })}\n {...(typeof aspectRatio === \"number\"\n ? { aspectRatio }\n : { height: typeof height === \"number\" ? height : 280 })}\n />\n </Box>\n );\n}\n"],"mappings":";;;;;;;;;;AA+CA,MAAM,QAAQ;CACZ;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AAGA,MAAM,QAAQ;CACZ;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AACA,MAAM,OAAO;CACX;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AACA,MAAM,SAAS,MAAM,KAAK,GAAG,UAAU,kBAAkB,QAAQ,EAAE,EAAE;AACrE,MAAM,WAAW,WACf,OAAO,YAAY,OAAO,KAAK,OAAO,UAAU,CAAC,cAAc,QAAQ,KAAK,KAAK,CAAC,CAAC;AAErF,MAAM,OAAO;CAAE,cAAc;CAAI,QAAQ,EAAE,KAAK,EAAE;AAAE;AAEpD,MAAM,YAAY,UAChB,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAA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AAA,QAAA,eAAA,EAAA,QAES,QAAA;EAFhB,KAAA,OAAO,gBAAgB,WACxB,EAAE,YAAY,IACd,EAAE,QAAQ,OAAO,WAAW,WAAW,SAAS,IAAI;EAF5C,EAAA,MAAA;EAES,EAAA,MAAA;;;CAPzBC,IAAAA;CAEgB,IAAA,EAAA,QAAA,cAAA,EAAA,QACDC,MAAAA,EAAAA,QACNH,MAAAA,EAAAA,QACAC,IAAAA;EALT,KAAA,oBAAC,KAAD;GAAK,IAAIG;GACP,UAAA,oBAAC,OAAD;IACc;IACZ,WAAWD;IACX,GAAKH;IACL,GAAKC;GAEqD,CAAA;EAE5D,CAAA;EAPc,EAAA,MAAA;EACDE,EAAAA,MAAAA;EACNH,EAAAA,MAAAA;EACAC,EAAAA,MAAAA;;;CANX,OACEC;AAWJ;AAXa,SAAA,MAAC,OAAA;CAAW,OAAA;EAAE,GAAG,QAAQ,KAAK;EAAG,GAAG,MAAM,YAAY,QAAQ,QAAQ,IAAI,CAAC;CAAE"}
|
package/dist/hooks.d.mts
CHANGED
|
@@ -1,94 +1,9 @@
|
|
|
1
|
-
import { t as
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { DatePickerProps, DateTimePickerProps, TimePickerProps } from "@mui/x-date-pickers";
|
|
5
|
-
import { FC, ReactNode } from "react";
|
|
6
|
-
import { useTranslation } from "react-i18next";
|
|
7
|
-
import { useInView } from "react-intersection-observer";
|
|
1
|
+
import { b as useLayoutForm, d as useCellContext, f as useHeaderContext, l as LayoutTableFeatures, o as createLayoutColumnHelper, p as useTableContext, s as useLayoutTable, t as ChatLayout, u as layoutTableFeatures, v as useFieldContext, x as withLayoutForm, y as useFormContext } from "./components-2HKj8GpC.mjs";
|
|
2
|
+
import { ReactNode } from "react";
|
|
3
|
+
import { useTranslation as useTranslation$1 } from "react-i18next";
|
|
8
4
|
import { UseChatReturn } from "@tanstack/ai-react";
|
|
9
5
|
import { AnyClientTool, RunAgentInput } from "@tanstack/ai/client";
|
|
10
|
-
import {
|
|
11
|
-
import { PickersTextFieldProps } from "@mui/x-date-pickers/PickersTextField";
|
|
12
|
-
interface FormTextFieldProps extends Omit<TextFieldProps, FormOmittedProps> {
|
|
13
|
-
type?: "color" | "email" | "password" | "search" | "tel" | "text" | "url";
|
|
14
|
-
}
|
|
15
|
-
interface FormNumberFieldProps extends Omit<TextFieldProps, FormOmittedProps> {
|
|
16
|
-
defaultValue?: number | null;
|
|
17
|
-
options?: Omit<NumericFormatProps<InputAttributes>, "customInput" | "onValueChange" | keyof InputAttributes>;
|
|
18
|
-
}
|
|
19
|
-
interface FormAutocompleteProps extends Omit<AutocompleteProps<any, boolean, boolean, boolean>, FormOmittedProps> {
|
|
20
|
-
textFieldProps?: Omit<TextFieldProps, FormOmittedProps>;
|
|
21
|
-
}
|
|
22
|
-
interface FormCheckboxProps extends Omit<CheckboxProps, FormOmittedProps> {
|
|
23
|
-
label?: string;
|
|
24
|
-
}
|
|
25
|
-
interface FormSwitchProps extends Omit<SwitchProps, FormOmittedProps> {
|
|
26
|
-
label?: string;
|
|
27
|
-
}
|
|
28
|
-
interface Option {
|
|
29
|
-
label: string;
|
|
30
|
-
value: string | number;
|
|
31
|
-
}
|
|
32
|
-
interface FormRadioGroupProps extends Omit<RadioGroupProps, FormOmittedProps> {
|
|
33
|
-
label?: string;
|
|
34
|
-
options: Array<Option>;
|
|
35
|
-
}
|
|
36
|
-
interface FormSliderProps extends Omit<SliderProps, FormOmittedProps> {
|
|
37
|
-
label?: string;
|
|
38
|
-
}
|
|
39
|
-
interface FormDatePickerProps extends Omit<DatePickerProps, FormOmittedProps> {
|
|
40
|
-
textFieldProps?: Partial<PickersTextFieldProps>;
|
|
41
|
-
}
|
|
42
|
-
interface FormTimePickerProps extends Omit<TimePickerProps, FormOmittedProps> {
|
|
43
|
-
textFieldProps?: Partial<PickersTextFieldProps>;
|
|
44
|
-
}
|
|
45
|
-
interface FormDateTimePickerProps extends Omit<DateTimePickerProps, FormOmittedProps> {
|
|
46
|
-
textFieldProps?: Partial<PickersTextFieldProps>;
|
|
47
|
-
}
|
|
48
|
-
type FormSubmitButtonProps = Omit<ButtonProps, "loading" | "disabled" | "onClick" | "type">;
|
|
49
|
-
declare const fieldContext: import("react").Context<import("@tanstack/form-core").AnyFieldApi>, useFieldContext: <TData>() => import("@tanstack/form-core").FieldApi<any, string, TData, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any>, formContext: import("react").Context<import("@tanstack/form-core").AnyFormApi>, useFormContext: () => import("@tanstack/react-form").ReactFormExtendedApi<Record<string, never>, any, any, any, any, any, any, any, any, any, any, any>;
|
|
50
|
-
export declare const useLayoutForm: <TFormData, TOnMount extends undefined | import("@tanstack/form-core").FormValidateOrFn<TFormData>, TOnChange extends undefined | import("@tanstack/form-core").FormValidateOrFn<TFormData>, TOnChangeAsync extends undefined | import("@tanstack/form-core").FormAsyncValidateOrFn<TFormData>, TOnBlur extends undefined | import("@tanstack/form-core").FormValidateOrFn<TFormData>, TOnBlurAsync extends undefined | import("@tanstack/form-core").FormAsyncValidateOrFn<TFormData>, TOnSubmit extends undefined | import("@tanstack/form-core").FormValidateOrFn<TFormData>, TOnSubmitAsync extends undefined | import("@tanstack/form-core").FormAsyncValidateOrFn<TFormData>, TOnDynamic extends undefined | import("@tanstack/form-core").FormValidateOrFn<TFormData>, TOnDynamicAsync extends undefined | import("@tanstack/form-core").FormAsyncValidateOrFn<TFormData>, TOnServer extends undefined | import("@tanstack/form-core").FormAsyncValidateOrFn<TFormData>, TSubmitMeta>(props: import("@tanstack/form-core").FormOptions<TFormData, TOnMount, TOnChange, TOnChangeAsync, TOnBlur, TOnBlurAsync, TOnSubmit, TOnSubmitAsync, TOnDynamic, TOnDynamicAsync, TOnServer, TSubmitMeta>) => import("@tanstack/react-form").AppFieldExtendedReactFormApi<TFormData, TOnMount, TOnChange, TOnChangeAsync, TOnBlur, TOnBlurAsync, TOnSubmit, TOnSubmitAsync, TOnDynamic, TOnDynamicAsync, TOnServer, TSubmitMeta, {
|
|
51
|
-
readonly TextField: import("react").FC<FormTextFieldProps>;
|
|
52
|
-
readonly NumberField: import("react").FC<FormNumberFieldProps>;
|
|
53
|
-
readonly Autocomplete: import("react").FC<FormAutocompleteProps>;
|
|
54
|
-
readonly Checkbox: import("react").FC<FormCheckboxProps>;
|
|
55
|
-
readonly Switch: import("react").FC<FormSwitchProps>;
|
|
56
|
-
readonly RadioGroup: import("react").FC<FormRadioGroupProps>;
|
|
57
|
-
readonly Slider: import("react").FC<FormSliderProps>;
|
|
58
|
-
readonly DatePicker: import("react").FC<FormDatePickerProps>;
|
|
59
|
-
readonly TimePicker: import("react").FC<FormTimePickerProps>;
|
|
60
|
-
readonly DateTimePicker: import("react").FC<FormDateTimePickerProps>;
|
|
61
|
-
}, {
|
|
62
|
-
readonly SubmitButton: import("react").FC<FormSubmitButtonProps>;
|
|
63
|
-
}>, withLayoutForm: <TFormData, TOnMount extends undefined | import("@tanstack/form-core").FormValidateOrFn<TFormData>, TOnChange extends undefined | import("@tanstack/form-core").FormValidateOrFn<TFormData>, TOnChangeAsync extends undefined | import("@tanstack/form-core").FormAsyncValidateOrFn<TFormData>, TOnBlur extends undefined | import("@tanstack/form-core").FormValidateOrFn<TFormData>, TOnBlurAsync extends undefined | import("@tanstack/form-core").FormAsyncValidateOrFn<TFormData>, TOnSubmit extends undefined | import("@tanstack/form-core").FormValidateOrFn<TFormData>, TOnSubmitAsync extends undefined | import("@tanstack/form-core").FormAsyncValidateOrFn<TFormData>, TOnDynamic extends undefined | import("@tanstack/form-core").FormValidateOrFn<TFormData>, TOnDynamicAsync extends undefined | import("@tanstack/form-core").FormAsyncValidateOrFn<TFormData>, TOnServer extends undefined | import("@tanstack/form-core").FormAsyncValidateOrFn<TFormData>, TSubmitMeta, TRenderProps extends object = {}>({ render, props }: import("@tanstack/react-form").WithFormProps<TFormData, TOnMount, TOnChange, TOnChangeAsync, TOnBlur, TOnBlurAsync, TOnSubmit, TOnSubmitAsync, TOnDynamic, TOnDynamicAsync, TOnServer, TSubmitMeta, {
|
|
64
|
-
readonly TextField: import("react").FC<FormTextFieldProps>;
|
|
65
|
-
readonly NumberField: import("react").FC<FormNumberFieldProps>;
|
|
66
|
-
readonly Autocomplete: import("react").FC<FormAutocompleteProps>;
|
|
67
|
-
readonly Checkbox: import("react").FC<FormCheckboxProps>;
|
|
68
|
-
readonly Switch: import("react").FC<FormSwitchProps>;
|
|
69
|
-
readonly RadioGroup: import("react").FC<FormRadioGroupProps>;
|
|
70
|
-
readonly Slider: import("react").FC<FormSliderProps>;
|
|
71
|
-
readonly DatePicker: import("react").FC<FormDatePickerProps>;
|
|
72
|
-
readonly TimePicker: import("react").FC<FormTimePickerProps>;
|
|
73
|
-
readonly DateTimePicker: import("react").FC<FormDateTimePickerProps>;
|
|
74
|
-
}, {
|
|
75
|
-
readonly SubmitButton: import("react").FC<FormSubmitButtonProps>;
|
|
76
|
-
}, TRenderProps>) => import("react").FunctionComponent<import("react").PropsWithChildren<NoInfer<[unknown] extends [TRenderProps] ? any : TRenderProps> & {
|
|
77
|
-
form: import("@tanstack/react-form").AppFieldExtendedReactFormApi<[unknown] extends [TFormData] ? any : TFormData, [import("@tanstack/form-core").FormValidateOrFn<TFormData> | undefined] extends [TOnMount] ? [TOnMount] extends [TOnMount & (import("@tanstack/form-core").FormValidateOrFn<TFormData> | undefined)] ? any : TOnMount : TOnMount, [import("@tanstack/form-core").FormValidateOrFn<TFormData> | undefined] extends [TOnChange] ? [TOnChange] extends [TOnChange & (import("@tanstack/form-core").FormValidateOrFn<TFormData> | undefined)] ? any : TOnChange : TOnChange, [import("@tanstack/form-core").FormValidateOrFn<TFormData> | undefined] extends [TOnChangeAsync] ? [TOnChangeAsync] extends [TOnChangeAsync & (import("@tanstack/form-core").FormValidateOrFn<TFormData> | undefined)] ? any : TOnChangeAsync : TOnChangeAsync, [import("@tanstack/form-core").FormValidateOrFn<TFormData> | undefined] extends [TOnBlur] ? [TOnBlur] extends [TOnBlur & (import("@tanstack/form-core").FormValidateOrFn<TFormData> | undefined)] ? any : TOnBlur : TOnBlur, [import("@tanstack/form-core").FormValidateOrFn<TFormData> | undefined] extends [TOnBlurAsync] ? [TOnBlurAsync] extends [TOnBlurAsync & (import("@tanstack/form-core").FormValidateOrFn<TFormData> | undefined)] ? any : TOnBlurAsync : TOnBlurAsync, [import("@tanstack/form-core").FormValidateOrFn<TFormData> | undefined] extends [TOnSubmit] ? [TOnSubmit] extends [TOnSubmit & (import("@tanstack/form-core").FormValidateOrFn<TFormData> | undefined)] ? any : TOnSubmit : TOnSubmit, [import("@tanstack/form-core").FormValidateOrFn<TFormData> | undefined] extends [TOnSubmitAsync] ? [TOnSubmitAsync] extends [TOnSubmitAsync & (import("@tanstack/form-core").FormValidateOrFn<TFormData> | undefined)] ? any : TOnSubmitAsync : TOnSubmitAsync, [import("@tanstack/form-core").FormValidateOrFn<TFormData> | undefined] extends [TOnDynamic] ? [TOnDynamic] extends [TOnDynamic & (import("@tanstack/form-core").FormValidateOrFn<TFormData> | undefined)] ? any : TOnDynamic : TOnDynamic, [import("@tanstack/form-core").FormValidateOrFn<TFormData> | undefined] extends [TOnDynamicAsync] ? [TOnDynamicAsync] extends [TOnDynamicAsync & (import("@tanstack/form-core").FormValidateOrFn<TFormData> | undefined)] ? any : TOnDynamicAsync : TOnDynamicAsync, [import("@tanstack/form-core").FormValidateOrFn<TFormData> | undefined] extends [TOnServer] ? [TOnServer] extends [TOnServer & (import("@tanstack/form-core").FormValidateOrFn<TFormData> | undefined)] ? any : TOnServer : TOnServer, [unknown] extends [TSubmitMeta] ? any : TSubmitMeta, {
|
|
78
|
-
readonly TextField: import("react").FC<FormTextFieldProps>;
|
|
79
|
-
readonly NumberField: import("react").FC<FormNumberFieldProps>;
|
|
80
|
-
readonly Autocomplete: import("react").FC<FormAutocompleteProps>;
|
|
81
|
-
readonly Checkbox: import("react").FC<FormCheckboxProps>;
|
|
82
|
-
readonly Switch: import("react").FC<FormSwitchProps>;
|
|
83
|
-
readonly RadioGroup: import("react").FC<FormRadioGroupProps>;
|
|
84
|
-
readonly Slider: import("react").FC<FormSliderProps>;
|
|
85
|
-
readonly DatePicker: import("react").FC<FormDatePickerProps>;
|
|
86
|
-
readonly TimePicker: import("react").FC<FormTimePickerProps>;
|
|
87
|
-
readonly DateTimePicker: import("react").FC<FormDateTimePickerProps>;
|
|
88
|
-
}, {
|
|
89
|
-
readonly SubmitButton: import("react").FC<FormSubmitButtonProps>;
|
|
90
|
-
}>;
|
|
91
|
-
}>>;
|
|
6
|
+
import { useInView } from "react-intersection-observer";
|
|
92
7
|
interface OpenDialogOptions<TResult> {
|
|
93
8
|
onClose?: (result: TResult) => Promise<void>;
|
|
94
9
|
}
|
|
@@ -120,6 +35,11 @@ interface DialogHook {
|
|
|
120
35
|
close: CloseDialog;
|
|
121
36
|
}
|
|
122
37
|
export declare function useDialogs(): DialogHook;
|
|
38
|
+
/**
|
|
39
|
+
* react-i18next's `useTranslation` on the request's instance during SSR, so a component
|
|
40
|
+
* above `LayoutProvider` (the root shell) renders the request's language too.
|
|
41
|
+
*/
|
|
42
|
+
export declare const useTranslation: typeof useTranslation$1;
|
|
123
43
|
interface Config {
|
|
124
44
|
/** Time to wait from last character to then trigger an evaluation of the buffer. Defaults to 100ms. */
|
|
125
45
|
timeToEvaluate?: number;
|
|
@@ -135,7 +55,7 @@ interface Config {
|
|
|
135
55
|
onError?: (error: string) => void;
|
|
136
56
|
/** Minimum length a scanned code should be. Defaults to 1.*/
|
|
137
57
|
minLength?: number;
|
|
138
|
-
/** Ignore scan input
|
|
58
|
+
/** Ignore scan input while the focus is on this node or inside it.*/
|
|
139
59
|
ignoreIfFocusOn?: Node;
|
|
140
60
|
/** Stop propagation on keydown event. Defaults to false.*/
|
|
141
61
|
stopPropagation?: boolean;
|
|
@@ -147,13 +67,13 @@ interface Config {
|
|
|
147
67
|
enabled?: boolean;
|
|
148
68
|
}
|
|
149
69
|
export declare const useScanDetection: ({ timeToEvaluate, averageWaitTime, startCharacter, endCharacter, onComplete, onError, minLength, ignoreIfFocusOn, stopPropagation, preventDefault, container, enabled }: Config) => void;
|
|
150
|
-
/** The app's chat server function: takes the AG-UI `RunAgentInput`, returns `
|
|
70
|
+
/** The app's chat server function: takes the AG-UI `RunAgentInput`, returns `layoutChat(...)`. */
|
|
151
71
|
type ChatServerFn = (options: {
|
|
152
72
|
data: RunAgentInput;
|
|
153
73
|
signal: AbortSignal;
|
|
154
74
|
}) => Promise<Response>;
|
|
155
75
|
type LayoutChatOptions = {
|
|
156
|
-
/** The conversation's name. Each signed-in user keeps their own copy
|
|
76
|
+
/** The conversation's name. Each signed-in user keeps their own copy until the tab closes. */
|
|
157
77
|
threadId: string;
|
|
158
78
|
/**
|
|
159
79
|
* Extra client tools, `toolDefinition(...).client(run)`: `run` executes in the browser, so it can
|
|
@@ -173,5 +93,5 @@ export declare function createLayoutChatHook(serverFn: ChatServerFn): {
|
|
|
173
93
|
useLayoutChat: ({ threadId, tools, forwardedProps }: LayoutChatOptions) => UseChatReturn;
|
|
174
94
|
LayoutChat: typeof ChatLayout;
|
|
175
95
|
};
|
|
176
|
-
export { type DialogProps, type LayoutTableFeatures, createLayoutColumnHelper, layoutTableFeatures, useCellContext, useFieldContext, useFormContext, useHeaderContext, useInView, useLayoutTable, useTableContext,
|
|
96
|
+
export { type DialogProps, type LayoutTableFeatures, createLayoutColumnHelper, layoutTableFeatures, useCellContext, useFieldContext, useFormContext, useHeaderContext, useInView, useLayoutForm, useLayoutTable, useTableContext, withLayoutForm };
|
|
177
97
|
//# sourceMappingURL=hooks.d.mts.map
|