@krak-stack/registry 0.11.7 → 0.11.9

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 (109) hide show
  1. package/CHANGELOG.md +54 -0
  2. package/README.md +39 -0
  3. package/dist/components/app-switcher/html.d.ts +2 -2
  4. package/dist/components/asset-input/html.d.ts +70 -0
  5. package/dist/components/asset-input/html.js +1549 -0
  6. package/dist/components/asset-input/index.d.ts +280 -0
  7. package/dist/components/asset-input/react.d.ts +32 -0
  8. package/dist/components/asset-input/react.js +2269 -0
  9. package/dist/components/asset-input/schema.d.ts +93 -0
  10. package/dist/components/asset-input/upload.d.ts +15 -0
  11. package/dist/components/asset-table/html.d.ts +110 -0
  12. package/dist/components/asset-table/html.js +4934 -0
  13. package/dist/components/asset-table/index.d.ts +225 -0
  14. package/dist/components/asset-table/react.d.ts +21 -0
  15. package/dist/components/asset-table/react.js +8241 -0
  16. package/dist/components/asset-table/schema.d.ts +73 -0
  17. package/dist/components/audit-log-table/html.js +47 -13
  18. package/dist/components/audit-log-table/react.js +36 -12
  19. package/dist/components/copy-button/html.d.ts +2 -2
  20. package/dist/components/danger-confirmation/html.d.ts +2 -2
  21. package/dist/components/data-table/classes.d.ts +2 -0
  22. package/dist/components/data-table/html.d.ts +58 -0
  23. package/dist/components/data-table/html.js +47 -13
  24. package/dist/components/data-table/index.d.ts +51 -1
  25. package/dist/components/data-table/react.d.ts +1 -0
  26. package/dist/components/data-table/react.js +36 -12
  27. package/dist/components/data-table/schema.d.ts +93 -3
  28. package/dist/components/date-input/html.d.ts +2 -2
  29. package/dist/components/docs/html.js +22 -4
  30. package/dist/components/docs/react.js +33 -2
  31. package/dist/components/editable-text/html.d.ts +2 -2
  32. package/dist/components/editing-locale-switcher/html.d.ts +2 -2
  33. package/dist/components/effect-form/react.js +343 -138
  34. package/dist/components/file-input/classes.d.ts +1 -1
  35. package/dist/components/file-input/file-type.d.ts +1 -0
  36. package/dist/components/file-input/html.d.ts +8 -1
  37. package/dist/components/file-input/html.js +170 -12
  38. package/dist/components/file-input/index.d.ts +1 -0
  39. package/dist/components/file-input/react.d.ts +9 -1
  40. package/dist/components/file-input/react.js +277 -127
  41. package/dist/components/file-input/schema.d.ts +1 -0
  42. package/dist/components/form/react.d.ts +5 -5
  43. package/dist/components/form/react.js +343 -138
  44. package/dist/components/icon-input/html.js +19 -5
  45. package/dist/components/icon-input/react.js +70 -13
  46. package/dist/components/locale-switcher/html.d.ts +2 -2
  47. package/dist/components/map-menu/html.d.ts +10 -4
  48. package/dist/components/map-menu/html.js +13 -8
  49. package/dist/components/map-menu/index.d.ts +5 -4
  50. package/dist/components/map-menu/react.d.ts +28 -17
  51. package/dist/components/map-menu/react.js +84 -178
  52. package/dist/components/map-menu/schema.d.ts +6 -0
  53. package/dist/components/map-menu/shared.d.ts +4 -0
  54. package/dist/components/permissions-input/classes.d.ts +8 -0
  55. package/dist/components/permissions-input/html.d.ts +41 -0
  56. package/dist/components/permissions-input/html.js +130 -0
  57. package/dist/components/permissions-input/index.d.ts +80 -0
  58. package/dist/components/permissions-input/react.d.ts +7 -0
  59. package/dist/components/permissions-input/react.js +201 -0
  60. package/dist/components/permissions-input/schema.d.ts +33 -0
  61. package/dist/components/phone-number-input/html.js +48 -14
  62. package/dist/components/phone-number-input/react.js +67 -10
  63. package/dist/components/presence-transition/index.d.ts +2 -2
  64. package/dist/components/search-menu/html.d.ts +2 -2
  65. package/dist/components/sidebar-layout/html.d.ts +3 -2
  66. package/dist/components/sidebar-layout/html.js +20 -2
  67. package/dist/components/sidebar-layout/index.d.ts +1 -0
  68. package/dist/components/sidebar-layout/react.js +33 -2
  69. package/dist/components/time-input/html.d.ts +2 -2
  70. package/dist/components/timezone-input/html.js +48 -14
  71. package/dist/components/timezone-input/react.js +67 -10
  72. package/dist/components/tracking-notice/html.d.ts +4 -4
  73. package/dist/components/tracking-notice/index.d.ts +2 -2
  74. package/dist/components/upload-attachment/classes.d.ts +3 -2
  75. package/dist/components/upload-attachment/html.d.ts +1 -1
  76. package/dist/components/upload-attachment/html.js +7 -5
  77. package/dist/components/upload-attachment/react.d.ts +3 -1
  78. package/dist/components/upload-attachment/react.js +25 -17
  79. package/dist/components/virtualized-combobox/classes.d.ts +12 -0
  80. package/dist/components/virtualized-combobox/html.d.ts +45 -3
  81. package/dist/components/virtualized-combobox/html.js +48 -14
  82. package/dist/components/virtualized-combobox/index.d.ts +55 -4
  83. package/dist/components/virtualized-combobox/react.d.ts +6 -2
  84. package/dist/components/virtualized-combobox/react.js +67 -10
  85. package/dist/components/virtualized-combobox/schema.d.ts +60 -4
  86. package/dist/components/webhook-delivery-table/html.js +47 -13
  87. package/dist/components/webhook-delivery-table/react.js +36 -12
  88. package/dist/lib/access/index.d.ts +61 -0
  89. package/dist/lib/access/index.js +92 -0
  90. package/dist/lib/access/table/classes.d.ts +13 -0
  91. package/dist/lib/access/table/html.d.ts +39 -0
  92. package/dist/lib/access/table/html.js +157 -0
  93. package/dist/lib/access/table/index.d.ts +32 -0
  94. package/dist/lib/access/table/react.d.ts +3 -0
  95. package/dist/lib/access/table/react.js +195 -0
  96. package/dist/lib/access/table/schema.d.ts +43 -0
  97. package/dist/lib/docs.integrations.server.js +23 -1
  98. package/dist/lib/docs.js +33 -2
  99. package/dist/lib/docs.server.js +29 -2
  100. package/dist/lib/documentation-toolkit.js +23 -1
  101. package/dist/lib/effect-ui-adapter/use-model.d.ts +1 -1
  102. package/dist/lib/effect-ui-adapter/use-model.js +19 -11
  103. package/dist/lib/lucide-effect.d.ts +19 -19
  104. package/dist/lib/lucide-effect.js +38 -38
  105. package/dist/services/assets/library.d.ts +221 -0
  106. package/dist/services/assets/schema.d.ts +3 -0
  107. package/dist/services/assets/url.d.ts +12 -0
  108. package/dist/services/assets/use-library.d.ts +20 -0
  109. package/package.json +13 -1
@@ -0,0 +1,1549 @@
1
+ // ../assets/src/components/asset-input/html.ts
2
+ import { Effect as Effect4, Layer, Redacted as Redacted4, Schema as Schema14 } from "effect";
3
+ import { AsyncResult as AsyncResult2 } from "effect/reactivity";
4
+
5
+ // ../assets/src/services/assets/library.ts
6
+ import {
7
+ Context,
8
+ Schema
9
+ } from "effect";
10
+ import { AsyncResult } from "effect/reactivity";
11
+ import { Component, Query, UiSchema, View } from "effect/ui";
12
+ var AssetLibraryAccessSchema = Schema.Struct({
13
+ scopeKey: Schema.NonEmptyString,
14
+ permissions: Schema.Array(Schema.Literals(["list", "read", "create", "update", "delete"]))
15
+ }).annotate({ identifier: "AssetLibraryAccess" });
16
+ var AssetListQuerySchema = Schema.Struct({
17
+ search: Schema.optionalKey(Schema.String.check(Schema.isMaxLength(200))),
18
+ kind: Schema.optionalKey(Schema.Literals(["image", "video", "caption", "document"]))
19
+ }).annotate({ identifier: "AssetListQuery" });
20
+ var AssetListItemSchema = Schema.Struct({
21
+ id: Schema.String.check(Schema.isUUID()),
22
+ name: Schema.NonEmptyString,
23
+ mimeType: Schema.NonEmptyString,
24
+ byteSize: Schema.Int,
25
+ createdAt: Schema.Date,
26
+ updatedAt: Schema.Date,
27
+ url: Schema.optionalKey(Schema.String)
28
+ }).annotate({ identifier: "AssetListItem" });
29
+ var AssetStatsSchema = Schema.Struct({
30
+ assetCount: Schema.Int,
31
+ storageUsedBytes: Schema.Int
32
+ }).annotate({ identifier: "AssetStats" });
33
+ var AssetListSchema = Schema.Struct({
34
+ items: Schema.Array(AssetListItemSchema),
35
+ stats: AssetStatsSchema
36
+ }).annotate({ identifier: "AssetList" });
37
+ var AssetListArgsSchema = Schema.Struct({
38
+ ...AssetListQuerySchema.fields,
39
+ scopeKey: Schema.NonEmptyString,
40
+ showFiles: Schema.Boolean
41
+ }).annotate({ identifier: "AssetListArgs" });
42
+ var AssetListError = Schema.Literals([
43
+ "unauthorized",
44
+ "forbidden",
45
+ "unavailable"
46
+ ]).annotate({ identifier: "AssetListError" });
47
+
48
+ class AssetList extends Query.Service()("@krak-stack/assets/AssetList", {
49
+ args: AssetListArgsSchema,
50
+ success: AssetListSchema,
51
+ error: AssetListError,
52
+ staleTime: "30 seconds"
53
+ }) {
54
+ }
55
+ var assetListArgs = (scopeKey, permissions, query = {}) => permissions.includes("list") ? { ...query, scopeKey, showFiles: permissions.includes("read") } : undefined;
56
+ var AssetLibrarySnapshot = Schema.Struct({
57
+ data: Schema.NullOr(AssetListSchema),
58
+ status: Schema.Literals(["idle", "loading", "ready", "failed"])
59
+ }).annotate({ identifier: "AssetLibrarySnapshot" });
60
+ var AssetLibraryMessage = UiSchema.TaggedEnum({
61
+ LibraryChanged: { library: AssetLibrarySnapshot }
62
+ }).annotate({ identifier: "AssetLibraryMessage" });
63
+ var emptyAssetLibrary = { data: null, status: "idle" };
64
+ var libraryQuery = (result) => AssetLibraryMessage.LibraryChanged({
65
+ library: AsyncResult.isSuccess(result) ? { data: result.value, status: "ready" } : {
66
+ data: null,
67
+ status: AsyncResult.isFailure(result) ? "failed" : "loading"
68
+ }
69
+ });
70
+ var options = {
71
+ name: "AssetLibraryModel",
72
+ props: Schema.Struct({ access: AssetLibraryAccessSchema }).annotate({
73
+ identifier: "AssetLibraryModelProps"
74
+ }),
75
+ model: AssetLibrarySnapshot,
76
+ message: AssetLibraryMessage,
77
+ restore: false,
78
+ queries: {
79
+ library: {
80
+ query: AssetList,
81
+ dropPrevious: true,
82
+ args: ({ props }) => assetListArgs(props.access.scopeKey, props.access.permissions),
83
+ onChange: libraryQuery
84
+ }
85
+ }
86
+ };
87
+ var definition = Component.define(options);
88
+ var AssetLibraryModel = definition.make({
89
+ init: () => emptyAssetLibrary,
90
+ update: definition.update({ LibraryChanged: (_, { library }) => library }),
91
+ view: () => View.text("")
92
+ });
93
+ var AssetUploadTransportMessages = {
94
+ en: {
95
+ rejected: "The file did not pass the security scan.",
96
+ failed: "The file could not be published."
97
+ },
98
+ fr: {
99
+ rejected: "Le fichier n’a pas passé l’analyse de sécurité.",
100
+ failed: "Impossible de publier le fichier."
101
+ }
102
+ };
103
+
104
+ class AssetLibraryActions extends Context.Service()("@krak-stack/assets/AssetLibraryActions") {
105
+ }
106
+
107
+ // ../assets/src/components/asset-input/html.ts
108
+ import { Component as Component7 } from "effect/ui";
109
+ import { Html as Html4 } from "effect/ui/html";
110
+ import { Dialog, Field } from "effect/ui/kit";
111
+ import { Button as Button3, buttonVariants as buttonVariants3 } from "@/components/effectcn/button";
112
+ import {
113
+ DialogBackdrop,
114
+ DialogDescription,
115
+ DialogHeader,
116
+ DialogPopup,
117
+ DialogTitle,
118
+ DialogViewport
119
+ } from "@/components/effectcn/dialog";
120
+ import { FieldLabel, FieldRoot } from "@/components/effectcn/field";
121
+
122
+ // ../../src/components/file-input/html.ts
123
+ import { Effect as Effect2, Redacted as Redacted2, Schema as Schema4, Stream } from "effect";
124
+ import { Component as Component3, Mount } from "effect/ui";
125
+ import { Html } from "effect/ui/html";
126
+ import { Button, buttonVariants } from "@/components/effectcn/button";
127
+ import {
128
+ FileDropHint,
129
+ FileDropIcon,
130
+ FileDropTitle,
131
+ fileDropZoneClass
132
+ } from "@/components/effectcn/file-drop";
133
+ import { krakstackLocaleRead } from "@krak-stack/registry/krakstack-provider/html";
134
+ import {
135
+ CloudUpload as UploadIcon,
136
+ File as FileIcon,
137
+ Captions,
138
+ Binary,
139
+ BookOpen,
140
+ Box,
141
+ CalendarDays,
142
+ Contact,
143
+ Database,
144
+ Disc3,
145
+ FileCode,
146
+ FileJson,
147
+ FileTerminal,
148
+ FileType,
149
+ Globe,
150
+ Mail,
151
+ Package,
152
+ Presentation,
153
+ FileArchive,
154
+ FileAudio,
155
+ FileImage,
156
+ FileSpreadsheet,
157
+ FileText,
158
+ FileVideo,
159
+ FileUp as ChooseIcon,
160
+ X as RemoveIcon
161
+ } from "@krak-stack/registry/lucide-effect";
162
+
163
+ // ../../src/lib/utils.ts
164
+ import { cn } from "cn";
165
+
166
+ // ../../src/components/file-input/classes.ts
167
+ var fileInputClasses = {
168
+ root: "grid min-w-0 grid-cols-1 gap-3"
169
+ };
170
+ var resolveFileInputClasses = (overrides) => ({
171
+ ...fileInputClasses,
172
+ ...overrides
173
+ });
174
+
175
+ // ../../src/components/file-input/file-type.ts
176
+ var fileType = (mimeType) => {
177
+ const type = mimeType.split(";", 1)[0]?.trim().toLowerCase() ?? "";
178
+ if (!type || type === "application/octet-stream")
179
+ return "file";
180
+ if (type.startsWith("image/"))
181
+ return "image";
182
+ if (type.startsWith("video/"))
183
+ return "video";
184
+ if (type.startsWith("audio/"))
185
+ return "audio";
186
+ if (type.startsWith("font/"))
187
+ return "font";
188
+ if (type.startsWith("model/"))
189
+ return "model";
190
+ if (type.startsWith("message/"))
191
+ return "mail";
192
+ if (type.endsWith("+json") || type === "application/json")
193
+ return "json";
194
+ if (type.includes("spreadsheet") || type.includes("ms-excel"))
195
+ return "spreadsheet";
196
+ if (type.includes("presentation") || type.includes("ms-powerpoint"))
197
+ return "presentation";
198
+ switch (type) {
199
+ case "text/vtt":
200
+ case "application/x-subrip":
201
+ case "application/ttml+xml":
202
+ return "caption";
203
+ case "application/zip":
204
+ case "application/x-zip-compressed":
205
+ case "application/x-7z-compressed":
206
+ case "application/vnd.rar":
207
+ case "application/x-rar-compressed":
208
+ case "application/x-tar":
209
+ case "application/gzip":
210
+ case "application/x-gzip":
211
+ case "application/x-bzip2":
212
+ case "application/x-xz":
213
+ case "application/zstd":
214
+ return "archive";
215
+ case "text/csv":
216
+ case "text/tab-separated-values":
217
+ return "spreadsheet";
218
+ case "text/html":
219
+ case "application/xhtml+xml":
220
+ return "web";
221
+ case "text/css":
222
+ case "text/javascript":
223
+ case "application/javascript":
224
+ case "text/typescript":
225
+ case "application/typescript":
226
+ case "application/yaml":
227
+ case "text/yaml":
228
+ case "application/toml":
229
+ return "code";
230
+ case "application/x-sh":
231
+ case "text/x-shellscript":
232
+ case "application/x-bat":
233
+ return "script";
234
+ case "application/sql":
235
+ case "application/vnd.sqlite3":
236
+ case "application/x-sqlite3":
237
+ return "database";
238
+ case "application/epub+zip":
239
+ case "application/x-mobipocket-ebook":
240
+ case "application/vnd.amazon.ebook":
241
+ return "book";
242
+ case "application/x-iso9660-image":
243
+ case "application/x-apple-diskimage":
244
+ return "disc";
245
+ case "application/vnd.android.package-archive":
246
+ case "application/x-debian-package":
247
+ case "application/x-rpm":
248
+ case "application/x-msi":
249
+ return "package";
250
+ case "application/wasm":
251
+ case "application/x-msdownload":
252
+ case "application/x-executable":
253
+ return "binary";
254
+ case "application/vnd.ms-fontobject":
255
+ case "application/font-woff":
256
+ case "application/x-font-ttf":
257
+ return "font";
258
+ case "application/vnd.ms-outlook":
259
+ return "mail";
260
+ case "text/calendar":
261
+ return "calendar";
262
+ case "text/vcard":
263
+ case "text/x-vcard":
264
+ return "contact";
265
+ case "application/xml":
266
+ case "text/xml":
267
+ return "code";
268
+ default:
269
+ if (type.endsWith("+xml") || type.startsWith("text/x-"))
270
+ return "code";
271
+ if (type.startsWith("text/") || type.includes("word") || type === "application/pdf" || type === "application/rtf")
272
+ return "document";
273
+ return "file";
274
+ }
275
+ };
276
+
277
+ // ../../src/components/file-input/index.ts
278
+ import { Redacted, Schema as Schema3 } from "effect";
279
+ import { Component as Component2, UiSchema as UiSchema2 } from "effect/ui";
280
+
281
+ // ../../src/components/file-input/schema.ts
282
+ import { Schema as Schema2, Struct } from "effect";
283
+ var AcceptLabel = Schema2.declare((value) => typeof value === "function").annotate({ identifier: "FilePickerAcceptLabel" });
284
+ var FilePickerFilesSchema = Schema2.Redacted(Schema2.Array(Schema2.File)).annotate({ identifier: "FilePickerFiles" });
285
+ var FileInputClassesOverridesSchema = Schema2.Record(Schema2.Literals(Struct.keys(fileInputClasses)), Schema2.optionalKey(Schema2.String)).annotate({ identifier: "FileInputClassesOverrides" });
286
+ var FilePickerPropsSchema = Schema2.Struct({
287
+ classes: Schema2.optional(FileInputClassesOverridesSchema),
288
+ accept: Schema2.optional(Schema2.String),
289
+ canClear: Schema2.optional(Schema2.Boolean),
290
+ file: Schema2.optional(Schema2.File),
291
+ files: Schema2.optional(Schema2.Array(Schema2.File)),
292
+ id: Schema2.String,
293
+ image: Schema2.optional(Schema2.Struct({
294
+ alt: Schema2.String,
295
+ height: Schema2.Number,
296
+ src: Schema2.optional(Schema2.String),
297
+ width: Schema2.Number
298
+ }).annotate({ identifier: "FilePickerImage" })),
299
+ invalid: Schema2.optional(Schema2.Boolean),
300
+ locale: Schema2.optional(Schema2.String),
301
+ messages: Schema2.optional(Schema2.Record(Schema2.String, Schema2.Struct({
302
+ accepts: Schema2.optional(AcceptLabel),
303
+ chooseFile: Schema2.optional(Schema2.String),
304
+ chooseFiles: Schema2.optional(Schema2.String),
305
+ deleteFile: Schema2.optional(Schema2.String),
306
+ dropFile: Schema2.optional(Schema2.String),
307
+ dropFiles: Schema2.optional(Schema2.String),
308
+ replaceFile: Schema2.optional(Schema2.String)
309
+ }).annotate({ identifier: "FilePickerMessageOverrides" }))),
310
+ multiple: Schema2.optional(Schema2.Boolean),
311
+ name: Schema2.String,
312
+ required: Schema2.optional(Schema2.Boolean),
313
+ showImageThumbnails: Schema2.optionalKey(Schema2.Boolean)
314
+ }).annotate({ identifier: "FilePickerProps" });
315
+
316
+ // ../../src/components/file-input/index.ts
317
+ var defaultMessages = {
318
+ en: {
319
+ accepts: (accepts) => `Accepts: ${accepts}`,
320
+ chooseFile: "Choose file",
321
+ chooseFiles: "Choose files",
322
+ deleteFile: "Delete",
323
+ dropFile: "Drag and drop a file here",
324
+ dropFiles: "Drag and drop files here",
325
+ replaceFile: "Replace file"
326
+ },
327
+ fr: {
328
+ accepts: (accepts) => `Accepte : ${accepts}`,
329
+ chooseFile: "Choisir un fichier",
330
+ chooseFiles: "Choisir des fichiers",
331
+ deleteFile: "Supprimer",
332
+ dropFile: "Glissez-déposez un fichier ici",
333
+ dropFiles: "Glissez-déposez des fichiers ici",
334
+ replaceFile: "Remplacer le fichier"
335
+ }
336
+ };
337
+ var filePickerMessages = (locale = "en", translations) => ({
338
+ ...locale.startsWith("fr") ? defaultMessages.fr : defaultMessages.en,
339
+ ...translations?.[locale.split("-")[0] ?? locale],
340
+ ...translations?.[locale]
341
+ });
342
+ var formatBytes = (bytes, locale) => {
343
+ const units = [
344
+ "byte",
345
+ "kilobyte",
346
+ "megabyte",
347
+ "gigabyte",
348
+ "terabyte"
349
+ ];
350
+ const index = Math.min(bytes === 0 ? 0 : Math.floor(Math.log(bytes) / Math.log(1024)), units.length - 1);
351
+ const value = index === 0 ? bytes : Number((bytes / 1024 ** index).toFixed(1));
352
+ return new Intl.NumberFormat(locale, {
353
+ style: "unit",
354
+ unit: units[index],
355
+ unitDisplay: "short"
356
+ }).format(value);
357
+ };
358
+ var fileDescription = (file, locale) => [
359
+ (file.name.includes(".") ? file.name.split(".").pop()?.toUpperCase() : "") || file.type.split("/").pop()?.toUpperCase(),
360
+ formatBytes(file.size, locale)
361
+ ].filter(Boolean).join(" · ");
362
+ var filePickerKey = ({ name, size, lastModified }) => `${name}:${size}:${lastModified}`;
363
+ var mergePickedFiles = (files, added) => Array.from(new Map([...files, ...added].map((file) => [filePickerKey(file), file])).values());
364
+ var FilePickerMessage = UiSchema2.TaggedEnum({
365
+ Selected: { files: FilePickerFilesSchema },
366
+ Dropped: { files: FilePickerFilesSchema },
367
+ Removed: { index: Schema3.Int },
368
+ Cleared: {},
369
+ Blurred: {},
370
+ DragEntered: {},
371
+ DragLeft: {}
372
+ }).annotate({ identifier: "FilePickerMessage" });
373
+ var FilePickerEvents = UiSchema2.TaggedEnum({
374
+ Change: { file: Schema3.Redacted(Schema3.File) },
375
+ FilesChange: { files: FilePickerFilesSchema },
376
+ Clear: {},
377
+ Blur: {}
378
+ }).annotate({ identifier: "FilePickerEvents" });
379
+ var filePickerOptions = {
380
+ name: "FilePicker",
381
+ props: FilePickerPropsSchema,
382
+ model: Schema3.Int,
383
+ message: FilePickerMessage,
384
+ events: FilePickerEvents,
385
+ restore: false
386
+ };
387
+ var selectFiles = ($, files, dropped) => {
388
+ const events = [];
389
+ if (files.length > 0) {
390
+ if ($.props.multiple) {
391
+ events.push(FilePickerEvents.FilesChange({
392
+ files: Redacted.make(mergePickedFiles($.props.files ?? [], files))
393
+ }));
394
+ } else if (files[0]) {
395
+ events.push(FilePickerEvents.Change({ file: Redacted.make(files[0]) }));
396
+ }
397
+ }
398
+ if (dropped)
399
+ events.push(FilePickerEvents.Blur());
400
+ return $.set(dropped ? 0 : $.model).emit(...events);
401
+ };
402
+ var filePickerBehaviours = {
403
+ init: () => 0,
404
+ update: Component2.define(filePickerOptions).update({
405
+ Selected: ($, { files }) => selectFiles($, Redacted.value(files), false),
406
+ Dropped: ($, { files }) => selectFiles($, Redacted.value(files), true),
407
+ Removed: ($, { index }) => $.set($.model).emit(FilePickerEvents.FilesChange({
408
+ files: Redacted.make(($.props.files ?? []).filter((_, position) => position !== index))
409
+ })),
410
+ Cleared: ($) => $.set($.model).emit(FilePickerEvents.Clear()),
411
+ Blurred: ($) => $.set($.model).emit(FilePickerEvents.Blur()),
412
+ DragEntered: ($) => $.model + 1,
413
+ DragLeft: ($) => Math.max(0, $.model - 1)
414
+ })
415
+ };
416
+
417
+ // ../../src/components/file-input/html.ts
418
+ var fileIcons = {
419
+ file: FileIcon,
420
+ archive: FileArchive,
421
+ binary: Binary,
422
+ book: BookOpen,
423
+ calendar: CalendarDays,
424
+ code: FileCode,
425
+ contact: Contact,
426
+ database: Database,
427
+ disc: Disc3,
428
+ font: FileType,
429
+ json: FileJson,
430
+ mail: Mail,
431
+ model: Box,
432
+ package: Package,
433
+ presentation: Presentation,
434
+ script: FileTerminal,
435
+ web: Globe,
436
+ image: FileImage,
437
+ video: FileVideo,
438
+ audio: FileAudio,
439
+ caption: Captions,
440
+ spreadsheet: FileSpreadsheet,
441
+ document: FileText
442
+ };
443
+ var fileTypeIconRenderer = (mimeType) => fileIcons[fileType(mimeType)];
444
+ var FileTypeIcon = (h, mimeType) => fileTypeIconRenderer(mimeType)(h, { size: 18 });
445
+ var PreviewFile = Mount.make("FilePickerPreviewFile", { args: { file: Schema4.Redacted(Schema4.File) } }, (image, _, changes) => Effect2.gen(function* () {
446
+ let url;
447
+ yield* Effect2.addFinalizer(() => Effect2.sync(() => {
448
+ if (url)
449
+ URL.revokeObjectURL(url);
450
+ }));
451
+ yield* changes.pipe(Stream.runForEach(({ file }) => Effect2.sync(() => {
452
+ if (url)
453
+ URL.revokeObjectURL(url);
454
+ url = URL.createObjectURL(Redacted2.value(file));
455
+ image.src = url;
456
+ })));
457
+ return Component3.noop;
458
+ }));
459
+ var FileThumbnail = (h, file) => fileType(file.type) === "image" ? h.img.class("size-9 shrink-0 rounded-md object-cover").attr("alt", "").onMount(PreviewFile({ file: Redacted2.make(file) })) : FileTypeIcon(h, file.type);
460
+ var props = Schema4.Struct({
461
+ ...filePickerOptions.props.fields,
462
+ title: Schema4.String,
463
+ showAcceptHint: Schema4.optionalKey(Schema4.Boolean)
464
+ }).annotate({ identifier: "FilePickerHtmlProps" });
465
+ var FileInput = Html.component({
466
+ ...filePickerOptions,
467
+ props,
468
+ slots: ["actions"],
469
+ reads: { localeConfig: krakstackLocaleRead }
470
+ }).make({
471
+ ...filePickerBehaviours,
472
+ view: (h, dragDepth) => {
473
+ const fileInputClasses = resolveFileInputClasses(h.props.classes);
474
+ const p = h.props;
475
+ const locale = p.locale ?? h.reads.localeConfig?.locale ?? "en";
476
+ const copy = filePickerMessages(locale, p.messages);
477
+ const files = p.files ?? [];
478
+ const icon = (file) => file && p.showImageThumbnails ? FileThumbnail(h, file) : FileTypeIcon(h, file?.type ?? "");
479
+ const selected = !p.multiple && Boolean(p.file ?? p.image?.src);
480
+ const inputLabel = p.multiple ? copy.chooseFiles : copy.chooseFile;
481
+ const chooser = h.label.class(cn(buttonVariants({ variant: "outline" }), "focus-within:ring-ring relative cursor-pointer overflow-hidden focus-within:ring-2")).children(ChooseIcon(h), inputLabel, h.input.id(p.id).class("absolute inset-0 z-10 size-full cursor-pointer opacity-0").attrs({
482
+ type: "file",
483
+ name: p.name,
484
+ accept: p.accept,
485
+ multiple: p.multiple ? "" : undefined,
486
+ required: p.required && !p.file && files.length === 0 && !p.image?.src ? "" : undefined,
487
+ "aria-invalid": p.invalid ? "true" : "false",
488
+ "aria-label": inputLabel
489
+ }).value("").on("blur", FilePickerMessage.Blurred()).on("change", ({ files }) => FilePickerMessage.Selected({ files: Redacted2.make(files) })));
490
+ const remove = (label, onPress) => Button(h, {
491
+ variant: "ghost",
492
+ size: "icon-sm",
493
+ props: { type: "button" },
494
+ onPress
495
+ }).attr("aria-label", label).children(RemoveIcon(h));
496
+ const attachment = (name, file) => h.div.class("min-w-0 flex-1").children(h.p.class("break-words text-sm font-medium").children(name), file && h.p.class("text-muted-foreground break-words text-xs").children(fileDescription(file, locale)));
497
+ const dropzone = h.div.class(cn(fileDropZoneClass, "min-h-32 min-w-0")).attrs({
498
+ "data-dragging": dragDepth > 0 ? "true" : "false",
499
+ "data-drag-over": dragDepth > 0 ? "" : undefined
500
+ }).dropTarget({ accepts: ["Files"], dropEffect: "copy" }).on("dragenter", FilePickerMessage.DragEntered()).on("dragleave", FilePickerMessage.DragLeft()).on("drop", ({ files }) => FilePickerMessage.Dropped({ files: Redacted2.make(files) })).children(FileDropIcon(h).children(UploadIcon(h)), h.div.class("min-w-0").children(FileDropTitle(h).children(p.multiple ? copy.dropFiles : copy.dropFile), p.showAcceptHint !== false && p.accept && FileDropHint(h, { class: "break-words" }).children(copy.accepts(p.accept ?? ""))), h.div.class("flex flex-wrap items-center justify-center gap-2").children(chooser, h.slots.actions));
501
+ const preview = p.image && (p.file || p.image.src) ? h.img.class("h-auto max-w-full rounded border object-contain").attrs({
502
+ alt: p.image.alt,
503
+ width: String(p.image.width),
504
+ height: String(p.image.height),
505
+ src: p.file ? undefined : p.image.src
506
+ }) : null;
507
+ return h.div.class(fileInputClasses.root).children(selected ? h.div.class("flex flex-wrap items-center gap-3 rounded-lg border p-3").children(preview && p.file ? preview.onMount(PreviewFile({ file: Redacted2.make(p.file) })) : preview ?? icon(p.file), attachment(p.file?.name ?? p.title, p.file), p.canClear !== false && remove(`${copy.deleteFile} ${p.title}`, FilePickerMessage.Cleared())) : dropzone, p.multiple && files.length > 0 && h.ul.class("grid gap-2").children(files.map((file, index) => h.li.key(`${filePickerKey(file)}:${index}`).class("flex items-center gap-3 rounded-lg border p-3").children(icon(file), attachment(file.name, file), remove(`${copy.deleteFile} ${file.name}`, FilePickerMessage.Removed({ index }))))));
508
+ }
509
+ });
510
+
511
+ // ../assets/src/components/asset-input/html.ts
512
+ import { krakstackLocaleRead as krakstackLocaleRead4 } from "@krak-stack/registry/krakstack-provider/html";
513
+
514
+ // ../../src/components/upload-attachment/html.ts
515
+ import { Schema as Schema7 } from "effect";
516
+ import { Html as Html2 } from "effect/ui/html";
517
+ import { Button as Button2 } from "@/components/effectcn/button";
518
+ import { krakstackLocaleRead as krakstackLocaleRead2 } from "@krak-stack/registry/krakstack-provider/html";
519
+ import {
520
+ Check,
521
+ File as FileIcon2,
522
+ LoaderCircle,
523
+ RotateCcw,
524
+ TriangleAlert,
525
+ X
526
+ } from "@krak-stack/registry/lucide-effect";
527
+
528
+ // ../../src/components/upload-attachment/classes.ts
529
+ var uploadAttachmentStatusRowClass = "mt-1 flex items-center gap-2";
530
+ var uploadAttachmentClasses = {
531
+ pendingIcon: "motion-safe:animate-spin",
532
+ status: "text-muted-foreground text-xs",
533
+ progress: "accent-primary h-1.5 min-w-0 flex-1 overflow-hidden rounded-full [&:not(:indeterminate)]:appearance-none [&:not(:indeterminate)]:bg-muted [&::-webkit-progress-bar]:bg-muted [&::-webkit-progress-value]:rounded-full [&::-webkit-progress-value]:bg-primary [&::-moz-progress-bar]:rounded-full [&::-moz-progress-bar]:bg-primary"
534
+ };
535
+ var resolveUploadAttachmentClasses = (overrides) => ({
536
+ ...uploadAttachmentClasses,
537
+ ...overrides
538
+ });
539
+
540
+ // ../../src/components/upload-attachment/index.ts
541
+ import { Schema as Schema6 } from "effect";
542
+ import { Component as Component4, UiSchema as UiSchema3 } from "effect/ui";
543
+
544
+ // ../../src/components/upload-attachment/schema.ts
545
+ import { Schema as Schema5, Struct as Struct2 } from "effect";
546
+ var UploadAttachmentStateSchema = Schema5.Union([
547
+ Schema5.Struct({
548
+ status: Schema5.Literals(["idle", "processing", "done", "cancelled"])
549
+ }),
550
+ Schema5.Struct({
551
+ status: Schema5.Literal("uploading"),
552
+ progress: Schema5.optional(Schema5.Number)
553
+ }),
554
+ Schema5.Struct({ status: Schema5.Literal("error"), message: Schema5.String })
555
+ ]).annotate({ identifier: "UploadAttachmentState" });
556
+ var Messages = Schema5.Struct({
557
+ idle: Schema5.String,
558
+ uploading: Schema5.String,
559
+ processing: Schema5.String,
560
+ done: Schema5.String,
561
+ cancelled: Schema5.String,
562
+ cancel: Schema5.String,
563
+ retry: Schema5.String,
564
+ remove: Schema5.String
565
+ }).annotate({ identifier: "UploadAttachmentMessages" });
566
+ var UploadAttachmentClassesOverridesSchema = Schema5.Record(Schema5.Literals(Struct2.keys(uploadAttachmentClasses)), Schema5.optionalKey(Schema5.String)).annotate({ identifier: "UploadAttachmentClassesOverrides" });
567
+ var UploadAttachmentPropsSchema = Schema5.Struct({
568
+ classes: Schema5.optional(UploadAttachmentClassesOverridesSchema),
569
+ name: Schema5.String,
570
+ description: Schema5.optional(Schema5.String),
571
+ state: UploadAttachmentStateSchema,
572
+ disabled: Schema5.optional(Schema5.Boolean),
573
+ className: Schema5.optional(Schema5.String),
574
+ locale: Schema5.optional(Schema5.String),
575
+ messages: Schema5.optional(Schema5.Record(Schema5.String, Messages.mapFields((fields) => ({
576
+ idle: Schema5.optional(fields.idle),
577
+ uploading: Schema5.optional(fields.uploading),
578
+ processing: Schema5.optional(fields.processing),
579
+ done: Schema5.optional(fields.done),
580
+ cancelled: Schema5.optional(fields.cancelled),
581
+ cancel: Schema5.optional(fields.cancel),
582
+ retry: Schema5.optional(fields.retry),
583
+ remove: Schema5.optional(fields.remove)
584
+ }))))
585
+ }).annotate({ identifier: "UploadAttachmentProps" });
586
+
587
+ // ../../src/components/upload-attachment/index.ts
588
+ var defaultMessages2 = {
589
+ en: {
590
+ idle: "Ready to upload",
591
+ uploading: "Uploading",
592
+ processing: "Processing",
593
+ done: "Upload complete",
594
+ cancelled: "Upload cancelled",
595
+ cancel: "Cancel upload",
596
+ retry: "Retry upload",
597
+ remove: "Remove attachment"
598
+ },
599
+ fr: {
600
+ idle: "Prêt à téléverser",
601
+ uploading: "Téléversement",
602
+ processing: "Traitement",
603
+ done: "Téléversement terminé",
604
+ cancelled: "Téléversement annulé",
605
+ cancel: "Annuler le téléversement",
606
+ retry: "Réessayer le téléversement",
607
+ remove: "Retirer la pièce jointe"
608
+ }
609
+ };
610
+ var getUploadAttachmentPresentation = (state, locale = "en", messages) => {
611
+ const copy = {
612
+ ...locale.startsWith("fr") ? defaultMessages2.fr : defaultMessages2.en,
613
+ ...messages?.[locale.split("-")[0] ?? locale],
614
+ ...messages?.[locale]
615
+ };
616
+ return {
617
+ copy,
618
+ busy: state.status === "uploading" || state.status === "processing",
619
+ retry: state.status === "error" || state.status === "cancelled",
620
+ progress: state.status === "uploading" && state.progress !== undefined && Number.isFinite(state.progress) ? Math.min(100, Math.max(0, state.progress)) : undefined,
621
+ status: state.status === "error" ? state.message : copy[state.status]
622
+ };
623
+ };
624
+ var UploadAttachmentAction = UiSchema3.TaggedEnum({
625
+ Cancel: {},
626
+ Retry: {},
627
+ Remove: {}
628
+ }).annotate({ identifier: "UploadAttachmentAction" });
629
+ var uploadAttachmentOptions = {
630
+ name: "UploadAttachment",
631
+ props: UploadAttachmentPropsSchema,
632
+ model: Schema6.Null,
633
+ message: UploadAttachmentAction,
634
+ events: UploadAttachmentAction,
635
+ restore: false
636
+ };
637
+ var update = ($, action) => {
638
+ const { busy, retry } = getUploadAttachmentPresentation($.props.state);
639
+ const available = action._tag === "Cancel" ? busy : action._tag === "Retry" ? retry : !busy;
640
+ return !$.props.disabled && available ? $.set(null).emit(action) : null;
641
+ };
642
+ var uploadAttachmentBehaviours = {
643
+ init: () => null,
644
+ update: Component4.define(uploadAttachmentOptions).update({
645
+ Cancel: update,
646
+ Retry: update,
647
+ Remove: update
648
+ })
649
+ };
650
+
651
+ // ../../src/components/upload-attachment/html.ts
652
+ var props2 = Schema7.Struct({
653
+ ...uploadAttachmentOptions.props.fields,
654
+ canCancel: Schema7.optional(Schema7.Boolean),
655
+ canRetry: Schema7.optional(Schema7.Boolean),
656
+ canRemove: Schema7.optional(Schema7.Boolean)
657
+ }).annotate({ identifier: "UploadAttachmentHtmlProps" });
658
+ var UploadAttachment = Html2.component({
659
+ ...uploadAttachmentOptions,
660
+ props: props2,
661
+ slots: ["fileIcon"],
662
+ reads: { localeConfig: krakstackLocaleRead2 }
663
+ }).make({
664
+ ...uploadAttachmentBehaviours,
665
+ view: (h) => {
666
+ const uploadAttachmentClasses = resolveUploadAttachmentClasses(h.props.classes);
667
+ const { name, description, state, disabled, className, locale, messages } = h.props;
668
+ const { busy, copy, progress, retry, status } = getUploadAttachmentPresentation(state, locale ?? h.reads.localeConfig?.locale, messages);
669
+ const id = h.id("name");
670
+ const action = (label, onPress) => Button2(h, {
671
+ variant: "ghost",
672
+ size: "icon-sm",
673
+ props: { type: "button", disabled },
674
+ onPress
675
+ }).attr("aria-label", `${label}: ${name}`).children(onPress._tag === "Retry" ? RotateCcw(h) : X(h));
676
+ return h.div.class(cn("flex min-w-0 items-start gap-3 rounded-lg border p-3", className)).attrs({
677
+ "data-component": "upload-attachment",
678
+ "data-state": state.status,
679
+ "aria-labelledby": id
680
+ }).children(h.span.class("bg-muted grid size-9 shrink-0 place-items-center rounded-md").children(h.span.class("peer empty:hidden").children(h.slots.fileIcon), h.span.class("peer-[:not(:empty)]:hidden").children(state.status === "done" ? Check(h, { size: 18 }) : state.status === "error" ? TriangleAlert(h, { size: 18 }) : busy ? LoaderCircle(h, {
681
+ size: 18,
682
+ className: uploadAttachmentClasses.pendingIcon
683
+ }) : FileIcon2(h, { size: 18 }))), h.div.class("min-w-0 flex-1").children(h.p.id(id).class("truncate text-sm font-medium").children(name), description && h.p.class("text-muted-foreground text-xs").children(description), h.div.class(uploadAttachmentStatusRowClass).children(h.p.attrs({
684
+ "data-slot": "upload-attachment-status",
685
+ role: state.status === "error" ? "alert" : "status"
686
+ }).class(uploadAttachmentClasses.status).children(status), state.status === "uploading" && h.progress.attrs({
687
+ "data-slot": "upload-attachment-progress",
688
+ "aria-label": `${copy.uploading}: ${name}`,
689
+ max: "100",
690
+ value: progress?.toString()
691
+ }).class(uploadAttachmentClasses.progress))), h.div.class("flex items-center gap-1").children(busy && h.props.canCancel && action(copy.cancel, UploadAttachmentAction.Cancel()), retry && h.props.canRetry && action(copy.retry, UploadAttachmentAction.Retry()), !busy && h.props.canRemove && action(copy.remove, UploadAttachmentAction.Remove())));
692
+ }
693
+ });
694
+
695
+ // ../../src/components/virtualized-combobox/html.ts
696
+ import { Html as Html3 } from "effect/ui/html";
697
+ import { Combobox, VirtualList } from "effect/ui/kit";
698
+ import { buttonVariants as buttonVariants2 } from "@/components/effectcn/button";
699
+ import {
700
+ ComboboxButton,
701
+ ComboboxClear,
702
+ ComboboxEmpty,
703
+ ComboboxItem,
704
+ ComboboxItemIndicator,
705
+ ComboboxPopup,
706
+ ComboboxPositioner,
707
+ ComboboxSearchInput
708
+ } from "@/components/effectcn/combobox";
709
+ import { krakstackLocaleRead as krakstackLocaleRead3 } from "@krak-stack/registry/krakstack-provider/html";
710
+
711
+ // ../../src/components/virtualized-combobox/classes.ts
712
+ var virtualizedComboboxClasses = {
713
+ itemLabel: "min-w-0 truncate",
714
+ groupLabel: "text-muted-foreground px-2 pt-3 pb-1 text-start text-xs",
715
+ itemContent: "flex min-w-0 flex-1 items-center gap-2 text-start",
716
+ itemMedia: "bg-muted grid size-8 shrink-0 place-items-center overflow-hidden rounded-md [&_svg]:size-4",
717
+ itemImage: "size-full object-cover",
718
+ itemDescription: "text-muted-foreground block truncate text-xs"
719
+ };
720
+ var virtualizedComboboxGroupHeight = 36;
721
+ var virtualizedComboboxDetailHeight = 52;
722
+ var resolveVirtualizedComboboxClasses = (overrides) => ({
723
+ ...virtualizedComboboxClasses,
724
+ ...overrides
725
+ });
726
+
727
+ // ../../src/components/virtualized-combobox/index.ts
728
+ import { Schema as Schema9 } from "effect";
729
+ import { Component as Component5, UiSchema as UiSchema4 } from "effect/ui";
730
+
731
+ // ../../src/components/virtualized-combobox/schema.ts
732
+ import { Predicate, Schema as Schema8, Struct as Struct3 } from "effect";
733
+ var Icon = Schema8.declare((value) => Predicate.isFunction(value)).annotate({ identifier: "VirtualizedComboboxIcon" });
734
+ var VirtualizedComboboxOptionSchema = Schema8.Struct({
735
+ value: Schema8.String.pipe(Schema8.mutableKey),
736
+ label: Schema8.String.pipe(Schema8.mutableKey),
737
+ description: Schema8.optionalKey(Schema8.String),
738
+ imageSrc: Schema8.optionalKey(Schema8.String),
739
+ icon: Schema8.optionalKey(Icon)
740
+ }).annotate({ identifier: "VirtualizedComboboxOption" });
741
+ var VirtualizedComboboxLabelsSchema = Schema8.Struct({
742
+ clear: Schema8.optionalKey(Schema8.String),
743
+ search: Schema8.optionalKey(Schema8.String),
744
+ selectMore: Schema8.optionalKey(Schema8.String)
745
+ }).annotate({ identifier: "VirtualizedComboboxLabels" });
746
+ var VirtualizedComboboxClassesOverridesSchema = Schema8.Record(Schema8.Literals(Struct3.keys(virtualizedComboboxClasses)), Schema8.optionalKey(Schema8.String)).annotate({ identifier: "VirtualizedComboboxClassesOverrides" });
747
+ var VirtualizedComboboxSharedPropsSchema = Schema8.Struct({
748
+ classes: Schema8.optional(VirtualizedComboboxClassesOverridesSchema),
749
+ ariaLabel: Schema8.String,
750
+ ariaInvalid: Schema8.optionalKey(Schema8.Boolean),
751
+ contentClassName: Schema8.optionalKey(Schema8.String),
752
+ disabled: Schema8.optionalKey(Schema8.Boolean),
753
+ items: Schema8.Array(VirtualizedComboboxOptionSchema),
754
+ locale: Schema8.optionalKey(Schema8.String),
755
+ open: Schema8.optionalKey(Schema8.Boolean),
756
+ searchValue: Schema8.optionalKey(Schema8.String),
757
+ triggerId: Schema8.optionalKey(Schema8.String)
758
+ }).annotate({ identifier: "VirtualizedComboboxSharedProps" });
759
+ var htmlFields = {
760
+ ...VirtualizedComboboxSharedPropsSchema.fields,
761
+ emptyLabel: Schema8.String,
762
+ placeholder: Schema8.String,
763
+ triggerLabel: Schema8.optionalKey(Schema8.String),
764
+ triggerIcon: Schema8.optionalKey(Icon),
765
+ itemHeight: Schema8.optionalKey(Schema8.Int.check(Schema8.isGreaterThan(0))),
766
+ filter: Schema8.optionalKey(Schema8.Literals(["contains", "none"])),
767
+ messages: Schema8.optionalKey(Schema8.Record(Schema8.String, Schema8.Struct({
768
+ ...VirtualizedComboboxLabelsSchema.fields,
769
+ selected: Schema8.optionalKey(Schema8.String)
770
+ })))
771
+ };
772
+ var VirtualizedComboboxPropsSchema = Schema8.Union([
773
+ Schema8.Struct({
774
+ ...htmlFields,
775
+ multiple: Schema8.optionalKey(Schema8.Literal(false)),
776
+ value: Schema8.NullOr(VirtualizedComboboxOptionSchema)
777
+ }),
778
+ Schema8.Struct({
779
+ ...htmlFields,
780
+ multiple: Schema8.Literal(true),
781
+ value: Schema8.Array(VirtualizedComboboxOptionSchema)
782
+ })
783
+ ]).annotate({ identifier: "VirtualizedComboboxProps" });
784
+
785
+ // ../../src/components/virtualized-combobox/index.ts
786
+ var isText = Schema9.is(Schema9.String);
787
+ var defaultMessages3 = {
788
+ en: {
789
+ clear: "Clear selection",
790
+ search: "Search...",
791
+ selected: (count) => `${count} selected`,
792
+ selectMore: "Select more"
793
+ },
794
+ fr: {
795
+ clear: "Effacer la sélection",
796
+ search: "Rechercher...",
797
+ selected: (count) => `${count} sélectionnés`,
798
+ selectMore: "Sélectionner davantage"
799
+ }
800
+ };
801
+ var virtualizedComboboxMessages = (locale, translations) => {
802
+ const language = locale.split("-")[0];
803
+ const labels = {
804
+ ...defaultMessages3[language === "fr" ? "fr" : "en"],
805
+ ...translations?.[language ?? locale],
806
+ ...translations?.[locale]
807
+ };
808
+ const selected = labels.selected;
809
+ return {
810
+ ...labels,
811
+ selected: isText(selected) ? (count) => selected.replaceAll("{count}", String(count)) : selected
812
+ };
813
+ };
814
+ var selectedLabel = (value, placeholder) => {
815
+ if (!value)
816
+ return placeholder;
817
+ if ("label" in value)
818
+ return value.label;
819
+ return value.length ? value.map(({ label }) => label).join(", ") : placeholder;
820
+ };
821
+ var selectionEntries = (items, selected, groupSelections, labels) => {
822
+ const entries = items.map((item, index) => ({
823
+ kind: "item",
824
+ item,
825
+ index
826
+ }));
827
+ if (!groupSelections || entries.length === 0)
828
+ return entries;
829
+ const chosen = entries.filter(({ item }) => selected.has(item.value));
830
+ return [
831
+ ...chosen.length ? [
832
+ {
833
+ kind: "group",
834
+ key: "selected",
835
+ label: labels.selected(selected.size)
836
+ },
837
+ ...chosen
838
+ ] : [],
839
+ { kind: "group", key: "available", label: labels.selectMore },
840
+ ...entries.filter(({ item }) => !selected.has(item.value))
841
+ ];
842
+ };
843
+ var events = {
844
+ OpenChanged: { open: Schema9.Boolean },
845
+ SearchChanged: { searchValue: Schema9.String },
846
+ ValueChanged: {
847
+ value: Schema9.NullOr(Schema9.Union([Schema9.String, Schema9.Array(Schema9.String)]))
848
+ }
849
+ };
850
+ var selectionId = (value) => isText(value) ? value : null;
851
+ var selectionIds = (value) => isText(value) ? [value] : value ?? [];
852
+ var VirtualizedComboboxEvents = UiSchema4.TaggedEnum(events).annotate({
853
+ identifier: "VirtualizedComboboxEvents"
854
+ });
855
+ var VirtualizedComboboxMessage = UiSchema4.TaggedEnum({
856
+ ...events,
857
+ Highlighted: { value: Schema9.String },
858
+ ImageFailed: { src: Schema9.String }
859
+ }).annotate({ identifier: "VirtualizedComboboxMessage" });
860
+ var virtualizedComboboxOptions = {
861
+ name: "VirtualizedCombobox",
862
+ props: VirtualizedComboboxPropsSchema,
863
+ model: Schema9.Struct({
864
+ open: Schema9.Boolean,
865
+ searchValue: Schema9.String,
866
+ failedImages: Schema9.Array(Schema9.String),
867
+ highlight: Schema9.NullOr(Schema9.Struct({ value: Schema9.String, id: Schema9.Int }))
868
+ }).annotate({ identifier: "VirtualizedComboboxModel" }),
869
+ message: VirtualizedComboboxMessage,
870
+ events: VirtualizedComboboxEvents,
871
+ restore: false
872
+ };
873
+ var update2 = Component5.define(virtualizedComboboxOptions).update({
874
+ OpenChanged: ($, { open }) => $.set({
875
+ ...$.model,
876
+ open: $.props.open === undefined ? open : $.model.open,
877
+ highlight: open ? $.model.highlight : null
878
+ }).emit(VirtualizedComboboxEvents.OpenChanged({ open })),
879
+ SearchChanged: ($, { searchValue }) => $.evolve({
880
+ searchValue: $.props.searchValue === undefined ? searchValue : $.model.searchValue,
881
+ highlight: null
882
+ }).emit(VirtualizedComboboxEvents.SearchChanged({ searchValue })),
883
+ ValueChanged: ($, { value }) => $.set($.model).emit(VirtualizedComboboxEvents.ValueChanged({ value })),
884
+ Highlighted: ($, { value }) => $.evolve({
885
+ highlight: { value, id: ($.model.highlight?.id ?? 0) + 1 }
886
+ }),
887
+ ImageFailed: ($, { src }) => $.model.failedImages.includes(src) ? $.model : $.evolve({ failedImages: [...$.model.failedImages, src] })
888
+ });
889
+ var virtualizedComboboxBehaviours = {
890
+ init: () => ({
891
+ open: false,
892
+ searchValue: "",
893
+ highlight: null,
894
+ failedImages: []
895
+ }),
896
+ update: update2
897
+ };
898
+
899
+ // ../../src/components/virtualized-combobox/html.ts
900
+ var visibleRows = 8;
901
+ var itemKey = (value) => `item:${value}`;
902
+ var VirtualizedCombobox = Html3.component({
903
+ ...virtualizedComboboxOptions,
904
+ reads: { localeConfig: krakstackLocaleRead3 }
905
+ }).make({
906
+ ...virtualizedComboboxBehaviours,
907
+ view: (h, model) => {
908
+ const virtualizedComboboxClasses = resolveVirtualizedComboboxClasses(h.props.classes);
909
+ const props = h.props;
910
+ const optionsByValue = new Map(props.items.map((item) => [item.value, item]));
911
+ const rowHeight = props.itemHeight ?? (props.items.some(({ description, imageSrc, icon }) => description || imageSrc || icon) ? virtualizedComboboxDetailHeight : 36);
912
+ const locale = props.locale ?? h.reads.localeConfig?.locale ?? "en";
913
+ const labels = virtualizedComboboxMessages(locale, props.messages);
914
+ const value = props.multiple ? props.value.map((item) => item.value) : props.value?.value ?? null;
915
+ const selected = new Set(selectionIds(value));
916
+ return Combobox(h, {
917
+ props: {
918
+ open: props.open ?? model.open,
919
+ inputValue: props.searchValue ?? model.searchValue,
920
+ items: props.items.map(({ value, label }) => ({ value, label })),
921
+ value,
922
+ locale,
923
+ multiple: props.multiple,
924
+ filter: props.filter,
925
+ disabled: props.disabled,
926
+ id: props.triggerId,
927
+ sideOffset: 6,
928
+ inputInPopup: true,
929
+ virtualized: true
930
+ },
931
+ onEmit: {
932
+ RequestedOpen: () => VirtualizedComboboxMessage.OpenChanged({ open: true }),
933
+ RequestedClose: () => VirtualizedComboboxMessage.OpenChanged({ open: false }),
934
+ RequestedInputValue: ({ inputValue }) => VirtualizedComboboxMessage.SearchChanged({ searchValue: inputValue }),
935
+ Picked: ({ value }) => VirtualizedComboboxMessage.ValueChanged({
936
+ value: props.multiple ? selectionIds(value) : selectionId(value)
937
+ }),
938
+ Highlighted: ({ reason, value }) => reason === "keyboard" && value !== null ? VirtualizedComboboxMessage.Highlighted({ value }) : undefined,
939
+ Settled: () => {
940
+ return;
941
+ }
942
+ },
943
+ view: (combo) => {
944
+ const entries = selectionEntries(combo.items, selected, props.multiple === true, labels);
945
+ const keys = entries.map((entry) => entry.kind === "group" ? `group:${entry.key}` : itemKey(entry.item.value));
946
+ const highlight = model.highlight && keys.includes(itemKey(model.highlight.value)) ? model.highlight : undefined;
947
+ return h.div.class("relative min-w-0").children((props.triggerIcon ? combo.trigger(h.button.class(buttonVariants2({ variant: "outline" }))).children(props.triggerIcon(h, { size: 16 }), props.triggerLabel ?? selectedLabel(props.value, props.placeholder)) : ComboboxButton(h, combo, {
948
+ class: "w-full min-w-0 aria-invalid:border-destructive",
949
+ value: props.triggerLabel ?? selectedLabel(props.value, props.placeholder),
950
+ valueClass: selected.size > 0 ? "pr-7" : undefined
951
+ })).attrs({
952
+ "aria-label": props.ariaLabel,
953
+ "aria-invalid": props.ariaInvalid ? "true" : undefined
954
+ }), !props.triggerIcon && selected.size > 0 && ComboboxClear(h, combo, {
955
+ class: "absolute right-7 top-1/2 -translate-y-1/2"
956
+ })?.attrs({ "aria-label": labels.clear, tabindex: "0" }), ComboboxPositioner(h, combo, {
957
+ class: "overflow-visible border-0 bg-transparent p-0 text-inherit"
958
+ }).children(ComboboxPopup(h, combo, { class: props.contentClassName }).attr("aria-label", props.ariaLabel).children(ComboboxSearchInput(h, combo, {
959
+ placeholder: labels.search
960
+ }), ComboboxEmpty(h, combo).children(props.emptyLabel), VirtualList(h, {
961
+ props: {
962
+ count: entries.length,
963
+ itemSize: rowHeight,
964
+ sizes: entries.some(({ kind }) => kind === "group") ? entries.map(({ kind }) => kind === "group" ? virtualizedComboboxGroupHeight : rowHeight) : undefined,
965
+ measure: false,
966
+ keys,
967
+ initialCount: visibleRows,
968
+ overscan: 8,
969
+ scrollTo: highlight && {
970
+ target: { _tag: "Key", key: itemKey(highlight.value) },
971
+ id: `${highlight.id}:${highlight.value}`,
972
+ align: "nearest"
973
+ }
974
+ },
975
+ view: (list) => list.viewport(h.div.class("min-h-0 overflow-auto overscroll-contain py-1")).attr("style", `max-height:${rowHeight * visibleRows}px`).attr("tabindex", "-1").children(list.list(combo.list(h.div)).children(...list.items.map((index) => {
976
+ const entry = entries[index];
977
+ const element = h.div.key(keys[index]);
978
+ if (entry.kind === "group") {
979
+ return list.item({
980
+ element: element.attr("role", "presentation"),
981
+ index
982
+ }).class("px-1").children(h.div.class(virtualizedComboboxClasses.groupLabel).children(entry.label));
983
+ }
984
+ const { value, label } = entry.item;
985
+ const details = optionsByValue.get(value);
986
+ const image = details?.imageSrc && !model.failedImages.includes(details.imageSrc) ? details.imageSrc : undefined;
987
+ return list.item({
988
+ element: element.attr("role", "presentation"),
989
+ index
990
+ }).children(ComboboxItem(h, combo, {
991
+ class: "mx-1 h-full",
992
+ value
993
+ }).attrs({
994
+ "aria-posinset": String(entry.index + 1),
995
+ "aria-setsize": String(combo.items.length)
996
+ }).children(h.span.class(virtualizedComboboxClasses.itemContent).children((image || details?.icon) && h.span.attr("aria-hidden", "true").class(virtualizedComboboxClasses.itemMedia).children(image ? h.img.attrs({
997
+ src: image,
998
+ alt: "",
999
+ loading: "lazy"
1000
+ }).class(virtualizedComboboxClasses.itemImage).on("error", VirtualizedComboboxMessage.ImageFailed({
1001
+ src: image
1002
+ })) : details?.icon?.(h, {
1003
+ size: 16
1004
+ })), h.span.class("min-w-0 flex-1").children(h.span.class(`block ${virtualizedComboboxClasses.itemLabel}`).children(label), details?.description && h.span.class(virtualizedComboboxClasses.itemDescription).children(details.description))), ComboboxItemIndicator(h, combo, { value })));
1005
+ })))
1006
+ }))));
1007
+ }
1008
+ });
1009
+ }
1010
+ });
1011
+
1012
+ // ../assets/src/components/asset-input/html.ts
1013
+ import { FolderOpen, X as X2 } from "@krak-stack/registry/lucide-effect";
1014
+
1015
+ // ../assets/src/services/assets/url.ts
1016
+ import { Schema as Schema11 } from "effect";
1017
+
1018
+ // ../assets/src/services/assets/schema.ts
1019
+ import { Schema as Schema10 } from "effect";
1020
+ var AssetHttpUrl = Schema10.String.check(Schema10.makeFilter((value) => {
1021
+ if (!/^https?:\/\/[^/]/i.test(value) || /[\s\\]/u.test(value))
1022
+ return false;
1023
+ try {
1024
+ const url = new URL(value);
1025
+ return !url.username && !url.password;
1026
+ } catch {
1027
+ return false;
1028
+ }
1029
+ })).annotate({ identifier: "AssetHttpUrl" });
1030
+ var AssetRelativeUrl = Schema10.String.check(Schema10.isPattern(/^\/(?!\/)[^\s\\]*$/u)).annotate({ identifier: "AssetRelativeUrl" });
1031
+
1032
+ // ../assets/src/services/assets/url.ts
1033
+ var isAssetHttpUrl = Schema11.is(AssetHttpUrl);
1034
+ var isAssetRelativeUrl = Schema11.is(AssetRelativeUrl);
1035
+ var assetUrl = ({ url }) => isAssetHttpUrl(url) || isAssetRelativeUrl(url) ? url : undefined;
1036
+ var assetImage = (asset) => {
1037
+ const url = asset.mimeType.trim().toLowerCase().startsWith("image/") ? assetUrl(asset) : undefined;
1038
+ if (!url)
1039
+ return {};
1040
+ const version = asset.updatedAt?.getTime();
1041
+ const imageSrc = version !== undefined && Number.isFinite(version) && /^\/api\/assets\/[^/?#]+\/file$/.test(url) ? `${url}?v=${version}` : url;
1042
+ return { imageSrc };
1043
+ };
1044
+
1045
+ // ../assets/src/components/asset-input/index.ts
1046
+ import { Effect as Effect3, Queue, Redacted as Redacted3, Schema as Schema13, Stream as Stream2 } from "effect";
1047
+ import { Command, Component as Component6, UiSchema as UiSchema5 } from "effect/ui";
1048
+
1049
+ // ../assets/src/components/asset-input/schema.ts
1050
+ import { Schema as Schema12 } from "effect";
1051
+ var AssetInputItemSchema = Schema12.Struct({
1052
+ id: Schema12.String,
1053
+ name: Schema12.String,
1054
+ mimeType: Schema12.String,
1055
+ url: Schema12.optionalKey(Schema12.String),
1056
+ updatedAt: Schema12.optionalKey(Schema12.Date)
1057
+ }).annotate({ identifier: "AssetInputItem" });
1058
+ var text = Schema12.optionalKey(Schema12.String);
1059
+ var flag = Schema12.optionalKey(Schema12.Boolean);
1060
+ var AssetKindSchema = Schema12.Literals([
1061
+ "document",
1062
+ "image",
1063
+ "video",
1064
+ "caption"
1065
+ ]);
1066
+ var AssetUploadMessagesSchema = Schema12.Record(Schema12.String, Schema12.Struct({
1067
+ upload: text,
1068
+ close: text,
1069
+ cancel: text,
1070
+ dialogTitle: text,
1071
+ dialogDescription: text,
1072
+ libraryDialogTitle: text,
1073
+ libraryDialogDescription: text,
1074
+ uploadError: text,
1075
+ kindError: text,
1076
+ publishError: text
1077
+ })).annotate({ identifier: "AssetUploadMessages" });
1078
+ var AssetUploadPropsSchema = Schema12.Struct({
1079
+ accept: text,
1080
+ processingLabel: text,
1081
+ messages: Schema12.optionalKey(AssetUploadMessagesSchema)
1082
+ }).annotate({ identifier: "AssetUploadProps" });
1083
+ var AssetInputPropsSchema = Schema12.Struct({
1084
+ label: Schema12.String,
1085
+ access: Schema12.optionalKey(AssetLibraryAccessSchema),
1086
+ replaceId: text,
1087
+ uploadTrigger: Schema12.optionalKey(Schema12.Literal("button")),
1088
+ assets: Schema12.optionalKey(Schema12.Array(AssetInputItemSchema)),
1089
+ kind: Schema12.optionalKey(AssetKindSchema),
1090
+ value: Schema12.optionalKey(Schema12.Union([Schema12.String, Schema12.Array(Schema12.String)])),
1091
+ multiple: flag,
1092
+ disabled: flag,
1093
+ locale: text,
1094
+ messages: Schema12.optionalKey(Schema12.Record(Schema12.String, Schema12.Struct({
1095
+ placeholder: text,
1096
+ multiplePlaceholder: text,
1097
+ empty: text,
1098
+ selected: text,
1099
+ remove: text
1100
+ }))),
1101
+ uploader: Schema12.optionalKey(AssetUploadPropsSchema)
1102
+ }).annotate({ identifier: "AssetInputProps" });
1103
+ var AssetUploadJobSchema = Schema12.Struct({
1104
+ id: Schema12.Int,
1105
+ file: Schema12.Redacted(Schema12.File),
1106
+ phase: Schema12.Literals([
1107
+ "uploading",
1108
+ "processing",
1109
+ "done",
1110
+ "error",
1111
+ "rejected"
1112
+ ]),
1113
+ progress: Schema12.optionalKey(Schema12.Finite),
1114
+ retryPublication: flag,
1115
+ error: text
1116
+ }).annotate({ identifier: "AssetUploadJob" });
1117
+
1118
+ // ../assets/src/components/asset-input/index.ts
1119
+ var inputCopy = {
1120
+ en: {
1121
+ placeholder: "Choose asset",
1122
+ multiplePlaceholder: "Choose assets",
1123
+ empty: "No assets found.",
1124
+ selected: "Selected asset",
1125
+ remove: "Remove asset"
1126
+ },
1127
+ fr: {
1128
+ placeholder: "Choisir un fichier existant",
1129
+ multiplePlaceholder: "Choisir des fichiers existants",
1130
+ empty: "Aucun fichier trouvé.",
1131
+ selected: "Fichier sélectionné",
1132
+ remove: "Retirer le fichier"
1133
+ }
1134
+ };
1135
+ var uploadCopy = {
1136
+ en: {
1137
+ upload: "Upload",
1138
+ dialogTitle: "Upload asset",
1139
+ dialogDescription: "This uploads and selects the file. Save the form separately to keep your changes.",
1140
+ libraryDialogTitle: "Upload files",
1141
+ libraryDialogDescription: "Review your files before uploading them to the library.",
1142
+ cancel: "Cancel",
1143
+ close: "Close",
1144
+ uploadError: "Could not upload the file.",
1145
+ kindError: "Choose a file of the required type.",
1146
+ publishError: "Could not confirm publication."
1147
+ },
1148
+ fr: {
1149
+ upload: "Téléverser",
1150
+ dialogTitle: "Téléverser un fichier",
1151
+ dialogDescription: "Le fichier sera téléversé et sélectionné. Enregistrez ensuite le formulaire pour conserver vos modifications.",
1152
+ libraryDialogTitle: "Téléverser des fichiers",
1153
+ libraryDialogDescription: "Vérifiez vos fichiers avant de les téléverser dans la bibliothèque.",
1154
+ cancel: "Annuler",
1155
+ close: "Fermer",
1156
+ uploadError: "Impossible de téléverser le fichier.",
1157
+ kindError: "Choisissez un fichier du type requis.",
1158
+ publishError: "Impossible de confirmer la publication."
1159
+ }
1160
+ };
1161
+ var language = (locale) => locale.split("-")[0] ?? locale;
1162
+ var assetInputMessages = (locale, messages) => ({
1163
+ ...language(locale) === "fr" ? inputCopy.fr : inputCopy.en,
1164
+ ...messages?.[language(locale)],
1165
+ ...messages?.[locale]
1166
+ });
1167
+ var assetUploadMessages = (locale, messages) => ({
1168
+ ...language(locale) === "fr" ? uploadCopy.fr : uploadCopy.en,
1169
+ ...messages?.[language(locale)],
1170
+ ...messages?.[locale]
1171
+ });
1172
+ var matchesAssetKind = (mimeType, kind) => {
1173
+ const type = mimeType.split(";", 1)[0]?.trim().toLowerCase() ?? "";
1174
+ const category = type.startsWith("image/") ? "image" : type.startsWith("video/") ? "video" : type === "text/vtt" ? "caption" : "document";
1175
+ return kind === undefined || category === kind;
1176
+ };
1177
+ var assetUploadAccept = (kind) => kind === "image" ? "image/*" : kind === "video" ? "video/*" : kind === "caption" ? ".vtt,text/vtt" : undefined;
1178
+ var hasInvalidAssetFiles = (files, kind) => files.some((staged) => {
1179
+ const file = Redacted3.value(staged);
1180
+ const mimeType = file.name.toLowerCase().endsWith(".vtt") ? "text/vtt" : file.type;
1181
+ return !matchesAssetKind(mimeType, kind);
1182
+ });
1183
+ var assetSelection = (value) => Schema13.is(Schema13.String)(value) ? value ? [value] : [] : value ?? [];
1184
+ var redactedFile = Schema13.Redacted(Schema13.File);
1185
+ var files = Schema13.Array(redactedFile);
1186
+ var result = {
1187
+ Progress: { id: Schema13.Int, progress: Schema13.Finite },
1188
+ Processing: { id: Schema13.Int },
1189
+ Completed: { id: Schema13.Int, assetId: Schema13.String },
1190
+ Failed: { id: Schema13.Int, retryPublication: Schema13.Boolean },
1191
+ Rejected: { id: Schema13.Int, error: Schema13.String }
1192
+ };
1193
+ var AssetUploadResult = UiSchema5.TaggedEnum(result).annotate({
1194
+ identifier: "AssetUploadResult"
1195
+ });
1196
+
1197
+ class RunAssetUpload extends Command.Service()("asset-input/RunAssetUpload", {
1198
+ args: {
1199
+ id: Schema13.Int,
1200
+ file: redactedFile,
1201
+ retryPublication: Schema13.Boolean
1202
+ },
1203
+ success: AssetUploadResult,
1204
+ stream: true,
1205
+ group: ["id"],
1206
+ mode: "switch"
1207
+ }) {
1208
+ }
1209
+ var assetUploadLayer = (transport) => {
1210
+ const staged = new WeakMap;
1211
+ return RunAssetUpload.toLayer(({ id, file, retryPublication }) => Stream2.callback((queue) => Effect3.tryPromise(async (signal) => {
1212
+ const source = Redacted3.value(file);
1213
+ let transferred = retryPublication;
1214
+ try {
1215
+ let prepared = retryPublication ? staged.get(file) : undefined;
1216
+ if (!prepared) {
1217
+ transferred = false;
1218
+ const context = await transport.upload(source, {
1219
+ signal,
1220
+ onProgress: (progress) => {
1221
+ if (!signal.aborted && !transferred && Number.isFinite(progress))
1222
+ Queue.offerUnsafe(queue, AssetUploadResult.Progress({ id, progress }));
1223
+ }
1224
+ });
1225
+ if (signal.aborted)
1226
+ return;
1227
+ prepared = { context };
1228
+ staged.set(file, prepared);
1229
+ }
1230
+ transferred = true;
1231
+ Queue.offerUnsafe(queue, AssetUploadResult.Processing({ id }));
1232
+ const publication = await transport.publish(prepared.context, signal);
1233
+ if (signal.aborted)
1234
+ return;
1235
+ staged.delete(file);
1236
+ Queue.offerUnsafe(queue, publication.status === "published" ? AssetUploadResult.Completed({
1237
+ id,
1238
+ assetId: publication.assetId
1239
+ }) : AssetUploadResult.Rejected({ id, error: publication.message }));
1240
+ } catch {
1241
+ if (!signal.aborted)
1242
+ Queue.offerUnsafe(queue, AssetUploadResult.Failed({ id, retryPublication: transferred }));
1243
+ } finally {
1244
+ Queue.endUnsafe(queue);
1245
+ }
1246
+ }).pipe(Effect3.ignore)));
1247
+ };
1248
+ var libraryUpload = (run, locale, replaceId) => {
1249
+ const copy = AssetUploadTransportMessages[locale.startsWith("fr") ? "fr" : "en"];
1250
+ return {
1251
+ upload: (file, { signal, onProgress }) => run(AssetLibraryActions.use((transport) => transport.upload(file, onProgress, replaceId)), { signal }),
1252
+ publish: (upload, signal) => run(AssetLibraryActions.use((transport) => transport.publish(upload)).pipe(Effect3.map((result) => result.status === "published" ? result : { status: "rejected", message: copy[result.reason] })), { signal })
1253
+ };
1254
+ };
1255
+ var AssetInputEvents = UiSchema5.TaggedEnum({
1256
+ Changed: { ids: Schema13.Array(Schema13.String) },
1257
+ Published: { assetId: Schema13.String, file: redactedFile }
1258
+ }).annotate({ identifier: "AssetInputEvents" });
1259
+ var AssetInputMessage = UiSchema5.TaggedEnum({
1260
+ Open: {},
1261
+ Stage: { files },
1262
+ SetFiles: { files },
1263
+ Upload: {},
1264
+ Dismiss: {},
1265
+ Closed: {},
1266
+ RemoveJob: { id: Schema13.Int },
1267
+ Retry: { id: Schema13.Int },
1268
+ Changed: { ids: Schema13.Array(Schema13.String) },
1269
+ ...result
1270
+ }).annotate({ identifier: "AssetInputMessage" });
1271
+ var assetInputOptions = {
1272
+ name: "AssetInput",
1273
+ props: AssetInputPropsSchema,
1274
+ model: Schema13.Struct({
1275
+ open: Schema13.Boolean,
1276
+ files,
1277
+ jobs: Schema13.Array(AssetUploadJobSchema),
1278
+ nextId: Schema13.Int
1279
+ }).annotate({ identifier: "AssetInputModel" }),
1280
+ message: AssetInputMessage,
1281
+ events: AssetInputEvents,
1282
+ restore: false
1283
+ };
1284
+ var active = (job) => job.phase === "uploading" || job.phase === "processing";
1285
+ var canCloseAssetUpload = (jobs) => jobs.some(({ phase }) => phase === "done") && !jobs.some(active);
1286
+ var withJob = (model, id, change) => model.open ? {
1287
+ ...model,
1288
+ jobs: model.jobs.map((job) => job.id === id && active(job) ? change(job) : job)
1289
+ } : model;
1290
+ var issue = (job) => RunAssetUpload.make({
1291
+ id: job.id,
1292
+ file: job.file,
1293
+ retryPublication: job.retryPublication ?? false
1294
+ });
1295
+ var definition2 = Component6.define(assetInputOptions);
1296
+ var update3 = definition2.update({
1297
+ Open: ($) => $.props.uploader && !$.props.disabled && !$.model.open ? { ...$.model, open: true, files: [], jobs: [] } : $.model,
1298
+ Stage: ($, { files }) => $.props.uploader && !$.props.disabled && files.length ? {
1299
+ ...$.model,
1300
+ open: true,
1301
+ jobs: $.model.open ? $.model.jobs : [],
1302
+ files: $.props.multiple ? files : files.slice(0, 1)
1303
+ } : $.model,
1304
+ SetFiles: ($, { files }) => $.model.open ? { ...$.model, files: $.props.multiple ? files : files.slice(0, 1) } : $.model,
1305
+ Dismiss: ($) => $.set({ ...$.model, open: false }).run(Command.interrupt(RunAssetUpload)),
1306
+ Closed: ($) => $.model.open ? $.model : { ...$.model, files: [], jobs: [] },
1307
+ Upload: ($) => {
1308
+ if (!$.model.open || !$.props.uploader || $.props.disabled || $.model.jobs.length || !$.model.files.length || hasInvalidAssetFiles($.model.files, $.props.kind))
1309
+ return $.model;
1310
+ const jobs = $.model.files.map((file, offset) => ({
1311
+ id: $.model.nextId + offset,
1312
+ file: Redacted3.make(Redacted3.value(file)),
1313
+ phase: "uploading"
1314
+ }));
1315
+ return $.set({
1316
+ ...$.model,
1317
+ files: [],
1318
+ jobs,
1319
+ nextId: $.model.nextId + jobs.length
1320
+ }).run(...jobs.map(issue));
1321
+ },
1322
+ RemoveJob: ($, { id }) => $.model.open ? $.set({
1323
+ ...$.model,
1324
+ jobs: $.model.jobs.filter((job) => job.id !== id)
1325
+ }).run(Command.interrupt(RunAssetUpload, { id })) : $.model,
1326
+ Retry: ($, { id }) => {
1327
+ const job = $.model.jobs.find((job) => job.id === id && job.phase === "error");
1328
+ if (!$.model.open || !job || !$.props.uploader || $.props.disabled)
1329
+ return $.model;
1330
+ const next = {
1331
+ ...job,
1332
+ phase: job.retryPublication ? "processing" : "uploading",
1333
+ progress: undefined
1334
+ };
1335
+ return $.set({
1336
+ ...$.model,
1337
+ jobs: $.model.jobs.map((job) => job.id === id ? next : job)
1338
+ }).run(issue(next));
1339
+ },
1340
+ Changed: ($, { ids }) => $.props.disabled ? $.model : $.emit(AssetInputEvents.Changed({
1341
+ ids: $.props.multiple ? ids : ids.slice(0, 1)
1342
+ })),
1343
+ Progress: ($, { id, progress }) => withJob($.model, id, (job) => job.phase === "uploading" ? { ...job, progress } : job),
1344
+ Processing: ($, { id }) => withJob($.model, id, (job) => ({ ...job, phase: "processing" })),
1345
+ Failed: ($, { id, retryPublication }) => withJob($.model, id, (job) => ({
1346
+ ...job,
1347
+ phase: "error",
1348
+ retryPublication
1349
+ })),
1350
+ Rejected: ($, { id, error }) => withJob($.model, id, (job) => ({ ...job, phase: "rejected", error })),
1351
+ Completed: ($, { id, assetId }) => {
1352
+ if (!$.model.open)
1353
+ return $.model;
1354
+ const job = $.model.jobs.find((job) => job.id === id && active(job));
1355
+ return job ? $.set(withJob($.model, id, (job) => ({ ...job, phase: "done" }))).emit(AssetInputEvents.Published({ assetId, file: job.file })) : $.model;
1356
+ }
1357
+ });
1358
+ var assetInputBehaviours = {
1359
+ init: () => ({ open: false, files: [], jobs: [], nextId: 0 }),
1360
+ update: update3
1361
+ };
1362
+ var assetUploadState = (job, copy) => {
1363
+ switch (job.phase) {
1364
+ case "uploading":
1365
+ return { status: "uploading", progress: job.progress };
1366
+ case "processing":
1367
+ return { status: "processing" };
1368
+ case "done":
1369
+ return { status: "done" };
1370
+ case "rejected":
1371
+ return {
1372
+ status: "error",
1373
+ message: job.error ?? copy.publishError
1374
+ };
1375
+ case "error":
1376
+ return {
1377
+ status: "error",
1378
+ message: job.retryPublication ? copy.publishError : copy.uploadError
1379
+ };
1380
+ }
1381
+ };
1382
+
1383
+ // ../assets/src/components/asset-input/html.ts
1384
+ var AssetInputView = Html4.component({
1385
+ ...assetInputOptions,
1386
+ slots: ["uploadAction"],
1387
+ reads: { localeConfig: krakstackLocaleRead4 },
1388
+ queries: {
1389
+ library: {
1390
+ query: AssetList,
1391
+ dropPrevious: true,
1392
+ args: ({ props }) => props.assets === undefined && props.value !== undefined && props.access ? assetListArgs(props.access.scopeKey, props.access.permissions) : undefined
1393
+ }
1394
+ }
1395
+ }).make({
1396
+ ...assetInputBehaviours,
1397
+ view: (h, model) => {
1398
+ const result = h.queries.library;
1399
+ const p = {
1400
+ ...h.props,
1401
+ assets: h.props.assets ?? (h.props.value !== undefined && h.props.access?.permissions.includes("list") ? AsyncResult2.isSuccess(result) ? result.value.items : [] : undefined)
1402
+ };
1403
+ const locale = p.locale ?? h.reads.localeConfig?.locale ?? "en";
1404
+ const labels = assetInputMessages(locale, p.messages);
1405
+ const upload = p.uploader;
1406
+ const copy = assetUploadMessages(locale, upload?.messages);
1407
+ const ids = assetSelection(p.value);
1408
+ const selected = new Map(p.assets?.map((asset) => [asset.id, asset]));
1409
+ const placeholder = p.multiple ? labels.multiplePlaceholder : labels.placeholder;
1410
+ const option = (value) => ({
1411
+ value,
1412
+ label: selected.get(value)?.name ?? labels.selected
1413
+ });
1414
+ const items = p.assets?.filter(({ mimeType }) => matchesAssetKind(mimeType, p.kind)).map((asset) => ({
1415
+ value: asset.id,
1416
+ label: asset.name,
1417
+ description: asset.mimeType,
1418
+ icon: fileTypeIconRenderer(asset.mimeType),
1419
+ ...assetImage(asset)
1420
+ })) ?? [];
1421
+ const picker = p.assets && VirtualizedCombobox(h, {
1422
+ props: {
1423
+ ariaLabel: placeholder,
1424
+ placeholder,
1425
+ triggerLabel: placeholder,
1426
+ triggerIcon: FolderOpen,
1427
+ emptyLabel: labels.empty,
1428
+ locale,
1429
+ disabled: p.disabled,
1430
+ items,
1431
+ contentClassName: "w-80",
1432
+ ...p.multiple ? { multiple: true, value: ids.map(option) } : { value: ids[0] ? option(ids[0]) : null }
1433
+ },
1434
+ onEmit: (event) => event._tag === "ValueChanged" ? AssetInputMessage.Changed({ ids: assetSelection(event.value ?? undefined) }) : undefined
1435
+ });
1436
+ const choose = (staged) => FileInput(h, {
1437
+ props: {
1438
+ id: h.id(staged ? "staged" : "file"),
1439
+ name: "",
1440
+ title: p.label,
1441
+ multiple: p.multiple,
1442
+ locale,
1443
+ accept: upload?.accept ?? assetUploadAccept(p.kind),
1444
+ showAcceptHint: false,
1445
+ ...staged ? { showImageThumbnails: true } : {},
1446
+ file: staged && !p.multiple && model.files[0] ? Redacted4.value(model.files[0]) : undefined,
1447
+ files: staged && p.multiple ? model.files.map(Redacted4.value) : undefined
1448
+ },
1449
+ slots: { actions: staged ? undefined : picker },
1450
+ onEmit: (event) => {
1451
+ const files = event._tag === "Change" ? [event.file] : event._tag === "FilesChange" ? Redacted4.value(event.files).map((file) => Redacted4.make(file)) : event._tag === "Clear" ? [] : undefined;
1452
+ return files && (staged ? AssetInputMessage.SetFiles({ files }) : AssetInputMessage.Stage({ files }));
1453
+ }
1454
+ });
1455
+ const showPicker = p.multiple || ids.length === 0;
1456
+ const buttonTrigger = p.uploadTrigger === "button" && upload && !p.disabled;
1457
+ return Field(h, {
1458
+ props: { disabled: p.disabled },
1459
+ view: (field) => FieldRoot(h, field).children(FieldLabel(h, field, {
1460
+ class: buttonTrigger && !p.assets ? "sr-only" : undefined
1461
+ }).children(p.label), ids.length > 0 && h.div.class(p.multiple ? "flex min-w-0 gap-2 overflow-x-auto p-1 scroll-p-1" : "min-w-0").children(ids.map((id) => {
1462
+ const item = selected.get(id);
1463
+ const imageSrc = item && assetImage(item).imageSrc;
1464
+ return h.div.key(id).class(p.multiple ? "flex min-w-40 max-w-full shrink-0 items-center gap-2 rounded-lg border p-2" : "flex min-w-0 items-center gap-2 rounded-lg border p-2").children(h.span.class("bg-muted grid size-9 shrink-0 place-items-center overflow-hidden rounded-md").children(imageSrc ? h.img.class("size-full object-cover").attrs({
1465
+ src: imageSrc,
1466
+ alt: ""
1467
+ }) : FileTypeIcon(h, item?.mimeType ?? "")), h.div.class("min-w-0 flex-1").children(h.p.class("truncate text-sm font-medium").children(item?.name ?? labels.selected), item?.mimeType && h.p.class("text-muted-foreground truncate text-xs").children(item.mimeType)), Button3(h, {
1468
+ variant: "ghost",
1469
+ size: "icon-sm",
1470
+ props: { type: "button", disabled: p.disabled },
1471
+ onPress: AssetInputMessage.Changed({
1472
+ ids: ids.filter((value) => value !== id)
1473
+ })
1474
+ }).attr("aria-label", item ? `${labels.remove}: ${item.name}` : labels.remove).children(X2(h, { size: 16 })));
1475
+ })), showPicker && (upload && !p.disabled && !buttonTrigger ? choose(false) : picker), showPicker && !p.disabled && !upload && h.slots.uploadAction, (upload || model.open) && Dialog(h, {
1476
+ props: { open: model.open },
1477
+ onEmit: (event) => event._tag === "RequestedClose" ? AssetInputMessage.Dismiss() : event._tag === "RequestedOpen" ? AssetInputMessage.Open() : event._tag === "Settled" && !event.open ? AssetInputMessage.Closed() : undefined,
1478
+ view: (dialog) => h.div.children(showPicker && buttonTrigger && dialog.trigger(h.button.class(buttonVariants3()).attr("type", "button")).children(copy.upload), dialog.portal(h.div.class("relative z-50"))?.children(DialogBackdrop(h, dialog), DialogViewport(h, dialog, {
1479
+ class: "grid-cols-1 grid-rows-1"
1480
+ }).children(DialogPopup(h, dialog, {
1481
+ class: "min-w-0 overflow-x-hidden overflow-y-auto [overflow-wrap:anywhere]"
1482
+ }).children(DialogHeader(h).children(DialogTitle(h, dialog).children(p.assets ? copy.dialogTitle : copy.libraryDialogTitle), DialogDescription(h, dialog).children(p.assets ? copy.dialogDescription : copy.libraryDialogDescription)), model.jobs.length > 0 ? h.div.class("grid min-w-0 grid-cols-1 gap-2").children(model.jobs.map((job) => {
1483
+ const file = Redacted4.value(job.file);
1484
+ return UploadAttachment(h, {
1485
+ key: String(job.id),
1486
+ props: {
1487
+ name: file.name,
1488
+ state: assetUploadState(job, copy),
1489
+ locale,
1490
+ canCancel: true,
1491
+ canRetry: Boolean(upload && !p.disabled && job.phase === "error"),
1492
+ canRemove: job.phase !== "done",
1493
+ messages: upload?.processingLabel ? {
1494
+ [locale]: {
1495
+ processing: upload.processingLabel
1496
+ }
1497
+ } : undefined
1498
+ },
1499
+ slots: {
1500
+ fileIcon: FileThumbnail(h, file)
1501
+ },
1502
+ onEmit: (event) => event._tag === "Retry" ? AssetInputMessage.Retry({ id: job.id }) : AssetInputMessage.RemoveJob({ id: job.id })
1503
+ });
1504
+ })) : upload && !p.disabled && choose(true), hasInvalidAssetFiles(model.files, p.kind) && h.p.attr("role", "alert").class("text-destructive text-sm").children(copy.kindError), h.div.class("flex flex-wrap justify-end gap-2").children(dialog.close(h.button.class(buttonVariants3({ variant: "outline" })).attr("type", "button")).children(canCloseAssetUpload(model.jobs) ? copy.close : copy.cancel), upload && !p.disabled && !model.jobs.length && model.files.length > 0 && Button3(h, {
1505
+ props: {
1506
+ type: "button",
1507
+ disabled: hasInvalidAssetFiles(model.files, p.kind)
1508
+ },
1509
+ onPress: AssetInputMessage.Upload()
1510
+ }).children(copy.upload))))))
1511
+ }))
1512
+ });
1513
+ }
1514
+ });
1515
+ var connectedUpload = (props) => Layer.unwrap(Effect4.context().pipe(Effect4.map((context) => assetUploadLayer(libraryUpload(Effect4.runPromiseWith(context), props.locale ?? "en", props.replaceId)))));
1516
+ var ConnectedAssetInput = AssetInputView.pipe(Component7.provide(connectedUpload));
1517
+ var AssetInput = Html4.component({
1518
+ name: "AssetInputConnection",
1519
+ props: assetInputOptions.props,
1520
+ model: Schema14.Null,
1521
+ message: AssetInputEvents,
1522
+ events: AssetInputEvents,
1523
+ slots: ["uploadAction"],
1524
+ reads: { localeConfig: krakstackLocaleRead4 },
1525
+ restore: false
1526
+ }).make({
1527
+ init: () => null,
1528
+ update: ($, event) => $.emit(event),
1529
+ view: (h) => {
1530
+ const { access, uploader, replaceId } = h.props;
1531
+ const connected = !uploader && access?.permissions.includes(replaceId ? "update" : "create");
1532
+ const Input = connected ? ConnectedAssetInput : AssetInputView;
1533
+ const locale = h.props.locale ?? h.reads.localeConfig?.locale ?? "en";
1534
+ return Input(h, {
1535
+ key: JSON.stringify([access?.scopeKey, connected, replaceId, locale]),
1536
+ props: { ...h.props, locale, ...connected ? { uploader: {} } : {} },
1537
+ slots: h.slots,
1538
+ onEmit: (event) => event
1539
+ });
1540
+ }
1541
+ });
1542
+ export {
1543
+ AssetInput,
1544
+ AssetInputEvents,
1545
+ AssetInputItemSchema,
1546
+ AssetUploadResult,
1547
+ RunAssetUpload,
1548
+ assetUploadLayer
1549
+ };