wcz-layout 10.2.2 → 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.
Files changed (115) hide show
  1. package/dist/{ChatLayout-CkS9oyPp.mjs → ChatLayout-B0MBrI-Y.mjs} +839 -371
  2. package/dist/ChatLayout-B0MBrI-Y.mjs.map +1 -0
  3. package/dist/{ExtractFile-ClTc-e1H.d.mts → ExtractFile-BQUXpuBS.d.mts} +27 -3
  4. package/dist/FileMeta-B5VU-eCi.d.mts +55 -0
  5. package/dist/FileMeta-BexXC_45.mjs +35 -0
  6. package/dist/FileMeta-BexXC_45.mjs.map +1 -0
  7. package/dist/QueryClientParam-BG9Q_9XU.d.mts +6 -0
  8. package/dist/{Translate-BiCjnlyx.mjs → Translate-C43AmXYW.mjs} +25 -37
  9. package/dist/Translate-C43AmXYW.mjs.map +1 -0
  10. package/dist/User-CvLutatT.d.mts +10 -0
  11. package/dist/ai.d.mts +1 -1
  12. package/dist/ai.mjs +2 -2
  13. package/dist/ai.mjs.map +1 -1
  14. package/dist/auth.d.mts +6 -14
  15. package/dist/auth.mjs +15 -38
  16. package/dist/auth.mjs.map +1 -1
  17. package/dist/{authMiddleware-D4GSt7m9.mjs → authMiddleware-ANa9Tlmp.mjs} +10 -15
  18. package/dist/authMiddleware-ANa9Tlmp.mjs.map +1 -0
  19. package/dist/{ChatLayout-BmLySLXy.d.mts → components-2HKj8GpC.d.mts} +219 -255
  20. package/dist/components.d.mts +2 -126
  21. package/dist/components.mjs +871 -919
  22. package/dist/components.mjs.map +1 -1
  23. package/dist/data/client.d.mts +299 -57
  24. package/dist/data/client.mjs +5 -6
  25. package/dist/data/client.mjs.map +1 -1
  26. package/dist/data/server.d.mts +6 -5
  27. package/dist/data/server.mjs +3 -5
  28. package/dist/data/server.mjs.map +1 -1
  29. package/dist/env-C4WLVJMm.mjs +32 -0
  30. package/dist/env-C4WLVJMm.mjs.map +1 -0
  31. package/dist/file-DBqTibcr.mjs +176 -0
  32. package/dist/file-DBqTibcr.mjs.map +1 -0
  33. package/dist/file-hecCQszp.mjs +114 -0
  34. package/dist/file-hecCQszp.mjs.map +1 -0
  35. package/dist/hooks.d.mts +11 -91
  36. package/dist/hooks.mjs +152 -960
  37. package/dist/hooks.mjs.map +1 -1
  38. package/dist/i18n-ZRiIIdpb.mjs +563 -0
  39. package/dist/i18n-ZRiIIdpb.mjs.map +1 -0
  40. package/dist/index.d.mts +3 -35
  41. package/dist/index.mjs +409 -510
  42. package/dist/index.mjs.map +1 -1
  43. package/dist/layout-DeTB6Ai1.mjs +224 -0
  44. package/dist/layout-DeTB6Ai1.mjs.map +1 -0
  45. package/dist/middleware.d.mts +1 -1
  46. package/dist/middleware.mjs +2 -2
  47. package/dist/models.d.mts +34 -42
  48. package/dist/models.mjs +4 -6
  49. package/dist/models.mjs.map +1 -1
  50. package/dist/oidc--D2ox365.mjs +97 -0
  51. package/dist/oidc--D2ox365.mjs.map +1 -0
  52. package/dist/peoplesoft-DhwB8jrM.d.mts +204 -0
  53. package/dist/tokens-C4djIAhl.mjs +97 -0
  54. package/dist/tokens-C4djIAhl.mjs.map +1 -0
  55. package/dist/useDialogs-QER-2rVG.mjs +297 -0
  56. package/dist/useDialogs-QER-2rVG.mjs.map +1 -0
  57. package/dist/{user-Bc2nLjAG.mjs → user-DQx1BanQ.mjs} +4 -20
  58. package/dist/user-DQx1BanQ.mjs.map +1 -0
  59. package/dist/{utils-CNYCSgip.d.mts → utils-BnyAEKW7.d.mts} +7 -9
  60. package/dist/{utils-CgabUlDD.mjs → utils-H4BskGF8.mjs} +21 -20
  61. package/dist/utils-H4BskGF8.mjs.map +1 -0
  62. package/dist/utils.d.mts +21 -4
  63. package/dist/utils.mjs +5 -4
  64. package/dist/vite.mjs +98 -32
  65. package/dist/vite.mjs.map +1 -1
  66. package/package.json +16 -43
  67. package/skills/ai/SKILL.md +1 -4
  68. package/skills/general/SKILL.md +15 -8
  69. package/skills/general/references/auth.md +10 -16
  70. package/skills/general/references/languages.md +56 -0
  71. package/skills/migrations/versions/migrate-v10-to-v11.md +98 -22
  72. package/skills/migrations/versions/migrate-v9-to-v10.md +22 -22
  73. package/skills/services/SKILL.md +1 -1
  74. package/skills/services/docs/email.md +2 -2
  75. package/skills/services/docs/file.md +100 -85
  76. package/skills/services/docs/layout.md +2 -3
  77. package/skills/start/steps/02-project-name-setup.md +1 -1
  78. package/skills/start/steps/06-entra-setup.md +1 -1
  79. package/skills/start/steps/08-generate-favicon.md +1 -1
  80. package/skills/table/SKILL.md +18 -5
  81. package/src/lib/locales/cs.json +120 -0
  82. package/src/lib/locales/en.json +119 -0
  83. package/src/lib/locales/uk.json +121 -0
  84. package/src/lib/locales/zh-TW.json +118 -0
  85. package/dist/ChatLayout-CkS9oyPp.mjs.map +0 -1
  86. package/dist/DialogsContext-D23fJjYR.mjs +0 -6
  87. package/dist/DialogsContext-D23fJjYR.mjs.map +0 -1
  88. package/dist/FileMeta-B39e2FLC.d.mts +0 -17
  89. package/dist/FileMeta-CPBWI_jA.mjs +0 -18
  90. package/dist/FileMeta-CPBWI_jA.mjs.map +0 -1
  91. package/dist/QueryClientParam-CTV1vj76.d.mts +0 -8
  92. package/dist/RouterListItemButton-CF-8w-08.mjs +0 -62
  93. package/dist/RouterListItemButton-CF-8w-08.mjs.map +0 -1
  94. package/dist/Translate-BiCjnlyx.mjs.map +0 -1
  95. package/dist/User-aJksXItw.d.mts +0 -12
  96. package/dist/authMiddleware-D4GSt7m9.mjs.map +0 -1
  97. package/dist/createApi-CF4ZL82B.mjs +0 -24
  98. package/dist/createApi-CF4ZL82B.mjs.map +0 -1
  99. package/dist/env-Cddts_dn.mjs +0 -49
  100. package/dist/env-Cddts_dn.mjs.map +0 -1
  101. package/dist/file-D4kSR_lC.mjs +0 -149
  102. package/dist/file-D4kSR_lC.mjs.map +0 -1
  103. package/dist/file-DcwYjofa.mjs +0 -150
  104. package/dist/file-DcwYjofa.mjs.map +0 -1
  105. package/dist/layout-6We_KFgN.mjs +0 -107
  106. package/dist/layout-6We_KFgN.mjs.map +0 -1
  107. package/dist/peoplesoft-DH31FCMC.mjs +0 -125
  108. package/dist/peoplesoft-DH31FCMC.mjs.map +0 -1
  109. package/dist/peoplesoft-DXukeeFr.d.mts +0 -161
  110. package/dist/providers-DOFje2P6.mjs +0 -56
  111. package/dist/providers-DOFje2P6.mjs.map +0 -1
  112. package/dist/tokens-DNe_Qifk.mjs +0 -204
  113. package/dist/tokens-DNe_Qifk.mjs.map +0 -1
  114. package/dist/user-Bc2nLjAG.mjs.map +0 -1
  115. package/dist/utils-CgabUlDD.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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E;CACjF,MAAM,EAAE,MAAM,GAAG,UAAU,iBAAiB,MAAM,IAAI;CACtD,MAAM,EAAE,WAAW,cAAc,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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,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"}
package/dist/hooks.d.mts CHANGED
@@ -1,94 +1,9 @@
1
- import { t as FormOmittedProps } from "./utils-CNYCSgip.mjs";
2
- import { a as useLayoutTable, c as LayoutTableFeatures, d as useHeaderContext, f as useTableContext, i as createLayoutColumnHelper, l as layoutTableFeatures, t as ChatLayout, u as useCellContext } from "./ChatLayout-BmLySLXy.mjs";
3
- import { AutocompleteProps, ButtonProps, CheckboxProps, RadioGroupProps, SliderProps, SwitchProps, TextFieldProps } from "@mui/material";
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 { InputAttributes, NumericFormatProps } from "react-number-format/types/types";
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 if this node is focused.*/
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;
@@ -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, useTranslation };
96
+ export { type DialogProps, type LayoutTableFeatures, createLayoutColumnHelper, layoutTableFeatures, useCellContext, useFieldContext, useFormContext, useHeaderContext, useInView, useLayoutForm, useLayoutTable, useTableContext, withLayoutForm };
177
97
  //# sourceMappingURL=hooks.d.mts.map