@krak-stack/registry 0.11.6 → 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 (123) hide show
  1. package/CHANGELOG.md +80 -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/classes.d.ts +1 -0
  18. package/dist/components/audit-log-table/html.d.ts +158 -0
  19. package/dist/components/audit-log-table/html.js +3294 -0
  20. package/dist/components/audit-log-table/index.d.ts +37 -0
  21. package/dist/components/audit-log-table/react.d.ts +3 -51
  22. package/dist/components/audit-log-table/react.js +130 -89
  23. package/dist/components/audit-log-table/schema.d.ts +122 -0
  24. package/dist/components/danger-confirmation/html.d.ts +2 -2
  25. package/dist/components/danger-confirmation/index.d.ts +2 -2
  26. package/dist/components/data-table/classes.d.ts +3 -0
  27. package/dist/components/data-table/html.d.ts +70 -12
  28. package/dist/components/data-table/html.js +56 -19
  29. package/dist/components/data-table/index.d.ts +51 -1
  30. package/dist/components/data-table/react.d.ts +1 -0
  31. package/dist/components/data-table/react.js +46 -16
  32. package/dist/components/data-table/schema.d.ts +93 -3
  33. package/dist/components/docs/html.js +22 -4
  34. package/dist/components/docs/react.js +33 -2
  35. package/dist/components/editable-text/html.d.ts +2 -2
  36. package/dist/components/editable-text/index.d.ts +4 -4
  37. package/dist/components/effect-form/react.js +343 -138
  38. package/dist/components/email-editor/legacy-editor.html.d.ts +6 -6
  39. package/dist/components/file-input/classes.d.ts +1 -1
  40. package/dist/components/file-input/file-type.d.ts +1 -0
  41. package/dist/components/file-input/html.d.ts +8 -1
  42. package/dist/components/file-input/html.js +170 -12
  43. package/dist/components/file-input/index.d.ts +1 -0
  44. package/dist/components/file-input/react.d.ts +9 -1
  45. package/dist/components/file-input/react.js +277 -127
  46. package/dist/components/file-input/schema.d.ts +1 -0
  47. package/dist/components/form/react.js +343 -138
  48. package/dist/components/icon-input/html.js +19 -5
  49. package/dist/components/icon-input/react.js +70 -13
  50. package/dist/components/map-menu/html.d.ts +6 -0
  51. package/dist/components/map-menu/html.js +13 -8
  52. package/dist/components/map-menu/index.d.ts +5 -4
  53. package/dist/components/map-menu/react.d.ts +28 -17
  54. package/dist/components/map-menu/react.js +84 -178
  55. package/dist/components/map-menu/schema.d.ts +6 -0
  56. package/dist/components/map-menu/shared.d.ts +4 -0
  57. package/dist/components/permissions-input/classes.d.ts +8 -0
  58. package/dist/components/permissions-input/html.d.ts +41 -0
  59. package/dist/components/permissions-input/html.js +130 -0
  60. package/dist/components/permissions-input/index.d.ts +80 -0
  61. package/dist/components/permissions-input/react.d.ts +7 -0
  62. package/dist/components/permissions-input/react.js +201 -0
  63. package/dist/components/permissions-input/schema.d.ts +33 -0
  64. package/dist/components/phone-number-input/html.js +48 -14
  65. package/dist/components/phone-number-input/react.js +67 -10
  66. package/dist/components/search-menu/html.d.ts +2 -2
  67. package/dist/components/select-with-custom-input/html.d.ts +2 -2
  68. package/dist/components/sidebar-layout/html.d.ts +3 -2
  69. package/dist/components/sidebar-layout/html.js +20 -2
  70. package/dist/components/sidebar-layout/index.d.ts +1 -0
  71. package/dist/components/sidebar-layout/react.js +33 -2
  72. package/dist/components/switch/react.d.ts +14 -0
  73. package/dist/components/switch/react.js +55 -0
  74. package/dist/components/theme-switcher/html.d.ts +2 -2
  75. package/dist/components/time-input/html.d.ts +2 -2
  76. package/dist/components/timezone-input/html.js +48 -14
  77. package/dist/components/timezone-input/react.js +67 -10
  78. package/dist/components/tracking-notice/classes.d.ts +6 -0
  79. package/dist/components/tracking-notice/html.d.ts +85 -0
  80. package/dist/components/tracking-notice/html.js +354 -0
  81. package/dist/components/tracking-notice/index.d.ts +95 -0
  82. package/dist/components/tracking-notice/react.d.ts +5 -27
  83. package/dist/components/tracking-notice/react.js +189 -59
  84. package/dist/components/tracking-notice/schema.d.ts +45 -0
  85. package/dist/components/upload-attachment/classes.d.ts +3 -2
  86. package/dist/components/upload-attachment/html.d.ts +5 -5
  87. package/dist/components/upload-attachment/html.js +7 -5
  88. package/dist/components/upload-attachment/react.d.ts +3 -1
  89. package/dist/components/upload-attachment/react.js +25 -17
  90. package/dist/components/virtualized-combobox/classes.d.ts +12 -0
  91. package/dist/components/virtualized-combobox/html.d.ts +42 -0
  92. package/dist/components/virtualized-combobox/html.js +48 -14
  93. package/dist/components/virtualized-combobox/index.d.ts +55 -4
  94. package/dist/components/virtualized-combobox/react.d.ts +6 -2
  95. package/dist/components/virtualized-combobox/react.js +67 -10
  96. package/dist/components/virtualized-combobox/schema.d.ts +60 -4
  97. package/dist/components/webhook-delivery-table/html.js +56 -19
  98. package/dist/components/webhook-delivery-table/react.js +46 -16
  99. package/dist/lib/access/index.d.ts +61 -0
  100. package/dist/lib/access/index.js +92 -0
  101. package/dist/lib/access/table/classes.d.ts +13 -0
  102. package/dist/lib/access/table/html.d.ts +39 -0
  103. package/dist/lib/access/table/html.js +157 -0
  104. package/dist/lib/access/table/index.d.ts +32 -0
  105. package/dist/lib/access/table/react.d.ts +3 -0
  106. package/dist/lib/access/table/react.js +195 -0
  107. package/dist/lib/access/table/schema.d.ts +43 -0
  108. package/dist/lib/docs.integrations.server.js +23 -1
  109. package/dist/lib/docs.js +33 -2
  110. package/dist/lib/docs.server.js +29 -2
  111. package/dist/lib/documentation-toolkit.js +23 -1
  112. package/dist/lib/effect-ui-adapter/use-model.d.ts +1 -1
  113. package/dist/lib/effect-ui-adapter/use-model.js +19 -11
  114. package/dist/lib/lucide-effect.d.ts +19 -19
  115. package/dist/lib/lucide-effect.js +38 -38
  116. package/dist/services/assets/library.d.ts +221 -0
  117. package/dist/services/assets/schema.d.ts +3 -0
  118. package/dist/services/assets/url.d.ts +12 -0
  119. package/dist/services/assets/use-library.d.ts +20 -0
  120. package/dist/services/events/browser.js +39 -26
  121. package/dist/services/events/index.js +23 -19
  122. package/dist/services/opentelemetry/web-vitals.js +27 -23
  123. package/package.json +21 -1
@@ -0,0 +1,2269 @@
1
+ // ../assets/src/components/asset-input/react.tsx
2
+ import { FolderOpen, X as X4 } from "lucide-react";
3
+ import {
4
+ useId as useId3,
5
+ useLayoutEffect as useLayoutEffect2,
6
+ useRef as useRef3,
7
+ useState as useState4
8
+ } from "react";
9
+ import {
10
+ Attachment as Attachment3,
11
+ AttachmentAction as AttachmentAction2,
12
+ AttachmentActions as AttachmentActions3,
13
+ AttachmentContent as AttachmentContent3,
14
+ AttachmentDescription as AttachmentDescription3,
15
+ AttachmentGroup as AttachmentGroup2,
16
+ AttachmentMedia as AttachmentMedia3,
17
+ AttachmentTitle as AttachmentTitle3
18
+ } from "@/components/ui/attachment";
19
+ import { Button as Button5 } from "@/components/ui/button";
20
+ import { Field, FieldTitle } from "@/components/ui/field";
21
+ import { useKrakstackLocale as useKrakstackLocale4 } from "@krak-stack/registry/krakstack-provider/react";
22
+
23
+ // ../../src/components/virtualized-combobox/react.tsx
24
+ import { Combobox as ComboboxPrimitive } from "@base-ui/react";
25
+ import { useVirtualizer } from "@tanstack/react-virtual";
26
+ import { Check, ChevronsUpDown, X } from "lucide-react";
27
+ import {
28
+ useCallback,
29
+ useEffect,
30
+ useImperativeHandle,
31
+ useRef,
32
+ useState
33
+ } from "react";
34
+ import { Button } from "@/components/ui/button";
35
+ import { InputGroup, InputGroupInput } from "@/components/ui/input-group";
36
+
37
+ // ../../src/lib/utils.ts
38
+ import { cn } from "cn";
39
+
40
+ // ../../src/components/virtualized-combobox/react.tsx
41
+ import { useKrakstackLocale } from "@krak-stack/registry/krakstack-provider/react";
42
+
43
+ // ../../src/components/virtualized-combobox/classes.ts
44
+ var virtualizedComboboxClasses = {
45
+ itemLabel: "min-w-0 truncate",
46
+ groupLabel: "text-muted-foreground px-2 pt-3 pb-1 text-start text-xs",
47
+ itemContent: "flex min-w-0 flex-1 items-center gap-2 text-start",
48
+ itemMedia: "bg-muted grid size-8 shrink-0 place-items-center overflow-hidden rounded-md [&_svg]:size-4",
49
+ itemImage: "size-full object-cover",
50
+ itemDescription: "text-muted-foreground block truncate text-xs"
51
+ };
52
+ var virtualizedComboboxGroupHeight = 36;
53
+ var virtualizedComboboxDetailHeight = 52;
54
+ var resolveVirtualizedComboboxClasses = (overrides) => ({
55
+ ...virtualizedComboboxClasses,
56
+ ...overrides
57
+ });
58
+
59
+ // ../../src/components/virtualized-combobox/index.ts
60
+ import { Schema as Schema2 } from "effect";
61
+ import { Component, UiSchema } from "effect/ui";
62
+
63
+ // ../../src/components/virtualized-combobox/schema.ts
64
+ import { Predicate, Schema, Struct } from "effect";
65
+ var Icon = Schema.declare((value) => Predicate.isFunction(value)).annotate({ identifier: "VirtualizedComboboxIcon" });
66
+ var VirtualizedComboboxOptionSchema = Schema.Struct({
67
+ value: Schema.String.pipe(Schema.mutableKey),
68
+ label: Schema.String.pipe(Schema.mutableKey),
69
+ description: Schema.optionalKey(Schema.String),
70
+ imageSrc: Schema.optionalKey(Schema.String),
71
+ icon: Schema.optionalKey(Icon)
72
+ }).annotate({ identifier: "VirtualizedComboboxOption" });
73
+ var VirtualizedComboboxLabelsSchema = Schema.Struct({
74
+ clear: Schema.optionalKey(Schema.String),
75
+ search: Schema.optionalKey(Schema.String),
76
+ selectMore: Schema.optionalKey(Schema.String)
77
+ }).annotate({ identifier: "VirtualizedComboboxLabels" });
78
+ var VirtualizedComboboxClassesOverridesSchema = Schema.Record(Schema.Literals(Struct.keys(virtualizedComboboxClasses)), Schema.optionalKey(Schema.String)).annotate({ identifier: "VirtualizedComboboxClassesOverrides" });
79
+ var VirtualizedComboboxSharedPropsSchema = Schema.Struct({
80
+ classes: Schema.optional(VirtualizedComboboxClassesOverridesSchema),
81
+ ariaLabel: Schema.String,
82
+ ariaInvalid: Schema.optionalKey(Schema.Boolean),
83
+ contentClassName: Schema.optionalKey(Schema.String),
84
+ disabled: Schema.optionalKey(Schema.Boolean),
85
+ items: Schema.Array(VirtualizedComboboxOptionSchema),
86
+ locale: Schema.optionalKey(Schema.String),
87
+ open: Schema.optionalKey(Schema.Boolean),
88
+ searchValue: Schema.optionalKey(Schema.String),
89
+ triggerId: Schema.optionalKey(Schema.String)
90
+ }).annotate({ identifier: "VirtualizedComboboxSharedProps" });
91
+ var htmlFields = {
92
+ ...VirtualizedComboboxSharedPropsSchema.fields,
93
+ emptyLabel: Schema.String,
94
+ placeholder: Schema.String,
95
+ triggerLabel: Schema.optionalKey(Schema.String),
96
+ triggerIcon: Schema.optionalKey(Icon),
97
+ itemHeight: Schema.optionalKey(Schema.Int.check(Schema.isGreaterThan(0))),
98
+ filter: Schema.optionalKey(Schema.Literals(["contains", "none"])),
99
+ messages: Schema.optionalKey(Schema.Record(Schema.String, Schema.Struct({
100
+ ...VirtualizedComboboxLabelsSchema.fields,
101
+ selected: Schema.optionalKey(Schema.String)
102
+ })))
103
+ };
104
+ var VirtualizedComboboxPropsSchema = Schema.Union([
105
+ Schema.Struct({
106
+ ...htmlFields,
107
+ multiple: Schema.optionalKey(Schema.Literal(false)),
108
+ value: Schema.NullOr(VirtualizedComboboxOptionSchema)
109
+ }),
110
+ Schema.Struct({
111
+ ...htmlFields,
112
+ multiple: Schema.Literal(true),
113
+ value: Schema.Array(VirtualizedComboboxOptionSchema)
114
+ })
115
+ ]).annotate({ identifier: "VirtualizedComboboxProps" });
116
+
117
+ // ../../src/components/virtualized-combobox/index.ts
118
+ var isText = Schema2.is(Schema2.String);
119
+ var defaultMessages = {
120
+ en: {
121
+ clear: "Clear selection",
122
+ search: "Search...",
123
+ selected: (count) => `${count} selected`,
124
+ selectMore: "Select more"
125
+ },
126
+ fr: {
127
+ clear: "Effacer la sélection",
128
+ search: "Rechercher...",
129
+ selected: (count) => `${count} sélectionnés`,
130
+ selectMore: "Sélectionner davantage"
131
+ }
132
+ };
133
+ var virtualizedComboboxMessages = (locale, translations) => {
134
+ const language = locale.split("-")[0];
135
+ const labels = {
136
+ ...defaultMessages[language === "fr" ? "fr" : "en"],
137
+ ...translations?.[language ?? locale],
138
+ ...translations?.[locale]
139
+ };
140
+ const selected = labels.selected;
141
+ return {
142
+ ...labels,
143
+ selected: isText(selected) ? (count) => selected.replaceAll("{count}", String(count)) : selected
144
+ };
145
+ };
146
+ var selectedLabel = (value, placeholder) => {
147
+ if (!value)
148
+ return placeholder;
149
+ if ("label" in value)
150
+ return value.label;
151
+ return value.length ? value.map(({ label }) => label).join(", ") : placeholder;
152
+ };
153
+ var selectionEntries = (items, selected, groupSelections, labels) => {
154
+ const entries = items.map((item, index) => ({
155
+ kind: "item",
156
+ item,
157
+ index
158
+ }));
159
+ if (!groupSelections || entries.length === 0)
160
+ return entries;
161
+ const chosen = entries.filter(({ item }) => selected.has(item.value));
162
+ return [
163
+ ...chosen.length ? [
164
+ {
165
+ kind: "group",
166
+ key: "selected",
167
+ label: labels.selected(selected.size)
168
+ },
169
+ ...chosen
170
+ ] : [],
171
+ { kind: "group", key: "available", label: labels.selectMore },
172
+ ...entries.filter(({ item }) => !selected.has(item.value))
173
+ ];
174
+ };
175
+ var events = {
176
+ OpenChanged: { open: Schema2.Boolean },
177
+ SearchChanged: { searchValue: Schema2.String },
178
+ ValueChanged: {
179
+ value: Schema2.NullOr(Schema2.Union([Schema2.String, Schema2.Array(Schema2.String)]))
180
+ }
181
+ };
182
+ var VirtualizedComboboxEvents = UiSchema.TaggedEnum(events).annotate({
183
+ identifier: "VirtualizedComboboxEvents"
184
+ });
185
+ var VirtualizedComboboxMessage = UiSchema.TaggedEnum({
186
+ ...events,
187
+ Highlighted: { value: Schema2.String },
188
+ ImageFailed: { src: Schema2.String }
189
+ }).annotate({ identifier: "VirtualizedComboboxMessage" });
190
+ var virtualizedComboboxOptions = {
191
+ name: "VirtualizedCombobox",
192
+ props: VirtualizedComboboxPropsSchema,
193
+ model: Schema2.Struct({
194
+ open: Schema2.Boolean,
195
+ searchValue: Schema2.String,
196
+ failedImages: Schema2.Array(Schema2.String),
197
+ highlight: Schema2.NullOr(Schema2.Struct({ value: Schema2.String, id: Schema2.Int }))
198
+ }).annotate({ identifier: "VirtualizedComboboxModel" }),
199
+ message: VirtualizedComboboxMessage,
200
+ events: VirtualizedComboboxEvents,
201
+ restore: false
202
+ };
203
+ var update = Component.define(virtualizedComboboxOptions).update({
204
+ OpenChanged: ($, { open }) => $.set({
205
+ ...$.model,
206
+ open: $.props.open === undefined ? open : $.model.open,
207
+ highlight: open ? $.model.highlight : null
208
+ }).emit(VirtualizedComboboxEvents.OpenChanged({ open })),
209
+ SearchChanged: ($, { searchValue }) => $.evolve({
210
+ searchValue: $.props.searchValue === undefined ? searchValue : $.model.searchValue,
211
+ highlight: null
212
+ }).emit(VirtualizedComboboxEvents.SearchChanged({ searchValue })),
213
+ ValueChanged: ($, { value }) => $.set($.model).emit(VirtualizedComboboxEvents.ValueChanged({ value })),
214
+ Highlighted: ($, { value }) => $.evolve({
215
+ highlight: { value, id: ($.model.highlight?.id ?? 0) + 1 }
216
+ }),
217
+ ImageFailed: ($, { src }) => $.model.failedImages.includes(src) ? $.model : $.evolve({ failedImages: [...$.model.failedImages, src] })
218
+ });
219
+
220
+ // ../../src/components/virtualized-combobox/react.tsx
221
+ import { jsx, jsxs, Fragment } from "react/jsx-runtime";
222
+ "use client";
223
+ var optionEquals = (item, selected) => item.value === selected.value;
224
+ var hasOptionDetails = ({
225
+ description,
226
+ imageSrc,
227
+ icon
228
+ }) => Boolean(description || imageSrc || icon);
229
+ var VirtualizedComboboxList = ({
230
+ classes,
231
+ emptyLabel,
232
+ groupSelections,
233
+ itemHeight,
234
+ itemIndexRef,
235
+ locale = "en",
236
+ messages: messageOverrides,
237
+ renderItem,
238
+ selectedValues,
239
+ virtualizerRef
240
+ }) => {
241
+ const virtualizedComboboxClasses = resolveVirtualizedComboboxClasses(classes);
242
+ const filteredItems = ComboboxPrimitive.useFilteredItems();
243
+ const labels = virtualizedComboboxMessages(locale, messageOverrides);
244
+ const entries = selectionEntries(filteredItems, selectedValues, groupSelections, labels);
245
+ const scrollRef = useRef(null);
246
+ const [failedImages, setFailedImages] = useState(() => new Set);
247
+ const rowHeight = itemHeight ?? (filteredItems.some(hasOptionDetails) ? virtualizedComboboxDetailHeight : 36);
248
+ const virtualizer = useVirtualizer({
249
+ count: entries.length,
250
+ getScrollElement: () => scrollRef.current,
251
+ getItemKey: (index) => {
252
+ const entry = entries[index];
253
+ return entry?.kind === "group" ? `group-${entry.key}` : entry?.item.value ?? index;
254
+ },
255
+ estimateSize: (index) => entries[index]?.kind === "group" ? virtualizedComboboxGroupHeight : rowHeight,
256
+ overscan: 8
257
+ });
258
+ useEffect(() => {
259
+ itemIndexRef.current = new Map(entries.flatMap((entry, index) => entry.kind === "item" ? [[entry.index, index]] : []));
260
+ });
261
+ useImperativeHandle(virtualizerRef, () => virtualizer, [virtualizer]);
262
+ const handleScrollElementRef = useCallback((element) => {
263
+ scrollRef.current = element;
264
+ if (element)
265
+ virtualizer.measure();
266
+ }, [virtualizer]);
267
+ return /* @__PURE__ */ jsxs(Fragment, {
268
+ children: [
269
+ filteredItems.length === 0 && /* @__PURE__ */ jsx("div", {
270
+ className: "text-muted-foreground flex min-h-0 flex-1 flex-col items-center justify-center overflow-auto py-6 text-center text-sm",
271
+ children: emptyLabel
272
+ }),
273
+ /* @__PURE__ */ jsx(ComboboxPrimitive.List, {
274
+ className: "min-h-0 flex-1 scroll-py-1 overflow-auto overscroll-contain p-1",
275
+ hidden: filteredItems.length === 0,
276
+ ref: handleScrollElementRef,
277
+ style: {
278
+ height: Math.min(virtualizer.getTotalSize() + 8, 288),
279
+ maxHeight: "var(--available-height)"
280
+ },
281
+ children: /* @__PURE__ */ jsx("div", {
282
+ className: "relative w-full",
283
+ role: "presentation",
284
+ style: { height: virtualizer.getTotalSize() },
285
+ children: virtualizer.getVirtualItems().map((virtualItem) => {
286
+ const entry = entries[virtualItem.index];
287
+ if (!entry)
288
+ return null;
289
+ const style = {
290
+ height: virtualItem.size,
291
+ transform: `translateY(${virtualItem.start}px)`
292
+ };
293
+ if (entry.kind === "group") {
294
+ return /* @__PURE__ */ jsx(ComboboxPrimitive.Group, {
295
+ className: "contents",
296
+ children: /* @__PURE__ */ jsx(ComboboxPrimitive.GroupLabel, {
297
+ className: `absolute top-0 left-0 w-full ${virtualizedComboboxClasses.groupLabel}`,
298
+ "data-index": virtualItem.index,
299
+ ref: virtualizer.measureElement,
300
+ style,
301
+ children: entry.label
302
+ })
303
+ }, entry.key);
304
+ }
305
+ const details = entry.item;
306
+ const image = details.imageSrc && !failedImages.has(details.imageSrc) ? details.imageSrc : undefined;
307
+ return /* @__PURE__ */ jsxs(ComboboxPrimitive.Item, {
308
+ "aria-posinset": entry.index + 1,
309
+ "aria-setsize": filteredItems.length,
310
+ className: "data-highlighted:bg-accent data-highlighted:text-accent-foreground absolute top-0 left-0 flex w-full cursor-default items-center gap-2 rounded-sm py-1.5 pr-8 pl-2 text-sm outline-hidden select-none data-disabled:pointer-events-none data-disabled:opacity-50",
311
+ "data-index": virtualItem.index,
312
+ index: entry.index,
313
+ ref: virtualizer.measureElement,
314
+ style,
315
+ value: entry.item,
316
+ children: [
317
+ renderItem?.(entry.item) ?? (hasOptionDetails(details) ? /* @__PURE__ */ jsxs("span", {
318
+ className: virtualizedComboboxClasses.itemContent,
319
+ children: [
320
+ (image || details.icon) && /* @__PURE__ */ jsx("span", {
321
+ "aria-hidden": "true",
322
+ className: virtualizedComboboxClasses.itemMedia,
323
+ children: image ? /* @__PURE__ */ jsx("img", {
324
+ src: image,
325
+ alt: "",
326
+ loading: "lazy",
327
+ onError: () => setFailedImages((failed) => new Set(failed).add(image)),
328
+ className: virtualizedComboboxClasses.itemImage
329
+ }) : details.icon
330
+ }),
331
+ /* @__PURE__ */ jsxs("span", {
332
+ className: "min-w-0 flex-1",
333
+ children: [
334
+ /* @__PURE__ */ jsx("span", {
335
+ className: cn("block", virtualizedComboboxClasses.itemLabel),
336
+ children: entry.item.label
337
+ }),
338
+ details.description && /* @__PURE__ */ jsx("span", {
339
+ className: virtualizedComboboxClasses.itemDescription,
340
+ children: details.description
341
+ })
342
+ ]
343
+ })
344
+ ]
345
+ }) : /* @__PURE__ */ jsx("span", {
346
+ className: virtualizedComboboxClasses.itemLabel,
347
+ children: entry.item.label
348
+ })),
349
+ /* @__PURE__ */ jsx(ComboboxPrimitive.ItemIndicator, {
350
+ className: "absolute right-2 flex size-4 items-center justify-center",
351
+ children: /* @__PURE__ */ jsx(Check, {})
352
+ })
353
+ ]
354
+ }, entry.item.value);
355
+ })
356
+ })
357
+ })
358
+ ]
359
+ });
360
+ };
361
+ var VirtualizedComboboxContent = ({
362
+ classes,
363
+ contentClassName,
364
+ emptyLabel,
365
+ groupSelections,
366
+ itemHeight,
367
+ itemIndexRef,
368
+ locale = "en",
369
+ messages: messageOverrides,
370
+ renderItem,
371
+ selectedValues,
372
+ virtualizerRef
373
+ }) => {
374
+ const labels = virtualizedComboboxMessages(locale, messageOverrides);
375
+ return /* @__PURE__ */ jsx(ComboboxPrimitive.Portal, {
376
+ children: /* @__PURE__ */ jsx(ComboboxPrimitive.Positioner, {
377
+ align: "start",
378
+ className: "isolate z-50",
379
+ side: "bottom",
380
+ sideOffset: 6,
381
+ children: /* @__PURE__ */ jsxs(ComboboxPrimitive.Popup, {
382
+ className: cn("bg-popover text-popover-foreground ring-foreground/10 data-[side=bottom]:slide-in-from-top-2 data-[side=top]:slide-in-from-bottom-2 data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-in-95 relative flex max-h-(--available-height) w-(--anchor-width) max-w-(--available-width) min-w-0 origin-(--transform-origin) flex-col overflow-hidden rounded-md shadow-md ring-1 duration-100", contentClassName),
383
+ children: [
384
+ /* @__PURE__ */ jsx("div", {
385
+ className: "min-w-0 shrink-0 p-1 pb-0",
386
+ children: /* @__PURE__ */ jsx(InputGroup, {
387
+ className: "border-input/30 bg-input/30 h-8 w-full min-w-0 shadow-none",
388
+ children: /* @__PURE__ */ jsx(ComboboxPrimitive.Input, {
389
+ placeholder: labels.search,
390
+ render: /* @__PURE__ */ jsx(InputGroupInput, {})
391
+ })
392
+ })
393
+ }),
394
+ /* @__PURE__ */ jsx(VirtualizedComboboxList, {
395
+ classes,
396
+ emptyLabel,
397
+ groupSelections,
398
+ itemHeight,
399
+ itemIndexRef,
400
+ locale,
401
+ messages: messageOverrides,
402
+ renderItem,
403
+ selectedValues,
404
+ virtualizerRef
405
+ })
406
+ ]
407
+ })
408
+ })
409
+ });
410
+ };
411
+ var defaultTrigger = (ariaLabel, ariaInvalid, disabled, label, triggerId) => /* @__PURE__ */ jsxs(Button, {
412
+ "aria-label": ariaLabel,
413
+ "aria-invalid": ariaInvalid,
414
+ className: "w-full max-w-full min-w-0 justify-between overflow-hidden",
415
+ disabled,
416
+ id: triggerId,
417
+ type: "button",
418
+ variant: "outline",
419
+ children: [
420
+ /* @__PURE__ */ jsx("span", {
421
+ className: "min-w-0 flex-1 truncate pr-7 text-left",
422
+ children: label
423
+ }),
424
+ /* @__PURE__ */ jsx(ChevronsUpDown, {
425
+ className: "text-muted-foreground shrink-0 opacity-70"
426
+ })
427
+ ]
428
+ });
429
+ var defaultClear = (label) => /* @__PURE__ */ jsx(ComboboxPrimitive.Clear, {
430
+ "aria-label": label,
431
+ className: "text-muted-foreground hover:bg-muted hover:text-foreground focus-visible:border-ring focus-visible:ring-ring/50 absolute top-1/2 right-7 z-10 flex size-6 -translate-y-1/2 items-center justify-center rounded-sm outline-none focus-visible:border focus-visible:ring-3",
432
+ type: "button",
433
+ children: /* @__PURE__ */ jsx(X, {
434
+ className: "size-3.5"
435
+ })
436
+ });
437
+ var useComboboxVirtualizerRef = (providedRef) => {
438
+ const localRef = useRef(null);
439
+ return providedRef ?? localRef;
440
+ };
441
+ var VirtualizedComboboxSingle = (props) => {
442
+ const virtualizerRef = useComboboxVirtualizerRef(props.virtualizerRef);
443
+ const itemIndexRef = useRef(new Map);
444
+ const labels = virtualizedComboboxMessages(props.locale ?? "en", props.messages);
445
+ return /* @__PURE__ */ jsxs(ComboboxPrimitive.Root, {
446
+ disabled: props.disabled,
447
+ inputValue: props.searchValue,
448
+ items: [...props.items],
449
+ itemToStringLabel: (item) => item.label,
450
+ isItemEqualToValue: optionEquals,
451
+ onInputValueChange: (value) => props.onSearchValueChange?.(value),
452
+ onItemHighlighted: (_, { index, reason }) => {
453
+ if (reason === "keyboard" && index >= 0) {
454
+ virtualizerRef.current?.scrollToIndex(itemIndexRef.current.get(index) ?? index, { align: "auto" });
455
+ }
456
+ },
457
+ onOpenChange: (open) => props.onOpenChange?.(open),
458
+ onValueChange: (value) => props.onValueChange(value),
459
+ open: props.open,
460
+ value: props.value,
461
+ virtualized: true,
462
+ children: [
463
+ /* @__PURE__ */ jsxs("div", {
464
+ className: "relative",
465
+ children: [
466
+ /* @__PURE__ */ jsx(ComboboxPrimitive.Trigger, {
467
+ render: props.trigger ?? defaultTrigger(props.ariaLabel, props.ariaInvalid, props.disabled, selectedLabel(props.value, props.placeholder), props.triggerId)
468
+ }),
469
+ props.trigger ? null : defaultClear(labels.clear)
470
+ ]
471
+ }),
472
+ /* @__PURE__ */ jsx(VirtualizedComboboxContent, {
473
+ ...props,
474
+ groupSelections: false,
475
+ itemIndexRef,
476
+ selectedValues: new Set(props.value ? [props.value.value] : []),
477
+ virtualizerRef
478
+ })
479
+ ]
480
+ });
481
+ };
482
+ var VirtualizedComboboxMultiple = (props) => {
483
+ const virtualizerRef = useComboboxVirtualizerRef(props.virtualizerRef);
484
+ const itemIndexRef = useRef(new Map);
485
+ const labels = virtualizedComboboxMessages(props.locale ?? "en", props.messages);
486
+ return /* @__PURE__ */ jsxs(ComboboxPrimitive.Root, {
487
+ disabled: props.disabled,
488
+ inputValue: props.searchValue,
489
+ items: [...props.items],
490
+ itemToStringLabel: (item) => item.label,
491
+ isItemEqualToValue: optionEquals,
492
+ multiple: true,
493
+ onInputValueChange: (value) => props.onSearchValueChange?.(value),
494
+ onItemHighlighted: (_, { index, reason }) => {
495
+ if (reason === "keyboard" && index >= 0) {
496
+ virtualizerRef.current?.scrollToIndex(itemIndexRef.current.get(index) ?? index, { align: "auto" });
497
+ }
498
+ },
499
+ onOpenChange: (open) => props.onOpenChange?.(open),
500
+ onValueChange: (value) => props.onValueChange(value),
501
+ open: props.open,
502
+ value: [...props.value],
503
+ virtualized: true,
504
+ children: [
505
+ /* @__PURE__ */ jsxs("div", {
506
+ className: "relative",
507
+ children: [
508
+ /* @__PURE__ */ jsx(ComboboxPrimitive.Trigger, {
509
+ render: props.trigger ?? defaultTrigger(props.ariaLabel, props.ariaInvalid, props.disabled, selectedLabel(props.value, props.placeholder), props.triggerId)
510
+ }),
511
+ props.trigger ? null : defaultClear(labels.clear)
512
+ ]
513
+ }),
514
+ /* @__PURE__ */ jsx(VirtualizedComboboxContent, {
515
+ ...props,
516
+ groupSelections: true,
517
+ itemIndexRef,
518
+ selectedValues: new Set(props.value.map(({ value }) => value)),
519
+ virtualizerRef
520
+ })
521
+ ]
522
+ });
523
+ };
524
+ function VirtualizedCombobox(props) {
525
+ const locale = useKrakstackLocale(props.locale);
526
+ return props.multiple ? /* @__PURE__ */ jsx(VirtualizedComboboxMultiple, {
527
+ ...props,
528
+ locale
529
+ }) : /* @__PURE__ */ jsx(VirtualizedComboboxSingle, {
530
+ ...props,
531
+ locale
532
+ });
533
+ }
534
+
535
+ // ../assets/src/components/asset-input/upload.tsx
536
+ import { Redacted as Redacted3 } from "effect";
537
+ import { Component as Component6, View as View2 } from "effect/ui";
538
+ import {
539
+ useEffect as useEffect3,
540
+ useId as useId2,
541
+ useLayoutEffect,
542
+ useState as useState3
543
+ } from "react";
544
+
545
+ // ../../src/components/file-input/react.tsx
546
+ import {
547
+ useEffect as useEffect2,
548
+ useMemo,
549
+ useRef as useRef2,
550
+ useState as useState2
551
+ } from "react";
552
+ import {
553
+ Binary,
554
+ BookOpen,
555
+ Box,
556
+ CalendarDays,
557
+ Captions,
558
+ CloudUpload,
559
+ FileArchive,
560
+ Contact,
561
+ Database,
562
+ Disc3,
563
+ FileCode,
564
+ FileJson,
565
+ FileTerminal,
566
+ FileType,
567
+ Globe,
568
+ Mail,
569
+ Package,
570
+ Presentation,
571
+ FileIcon,
572
+ FileAudio,
573
+ FileImage,
574
+ FileSpreadsheet,
575
+ FileText,
576
+ FileUp,
577
+ FileVideo,
578
+ X as X2
579
+ } from "lucide-react";
580
+ import { Schema as Schema5 } from "effect";
581
+ import {
582
+ Attachment,
583
+ AttachmentAction,
584
+ AttachmentActions,
585
+ AttachmentContent,
586
+ AttachmentDescription,
587
+ AttachmentGroup,
588
+ AttachmentMedia,
589
+ AttachmentTitle
590
+ } from "@/components/ui/attachment";
591
+ import { Button as Button2 } from "@/components/ui/button";
592
+ import { Input } from "@/components/ui/input";
593
+ import { useKrakstackLocale as useKrakstackLocale2 } from "@krak-stack/registry/krakstack-provider/react";
594
+
595
+ // ../../src/components/file-input/classes.ts
596
+ var fileInputClasses = {
597
+ root: "grid min-w-0 grid-cols-1 gap-3"
598
+ };
599
+ var resolveFileInputClasses = (overrides) => ({
600
+ ...fileInputClasses,
601
+ ...overrides
602
+ });
603
+
604
+ // ../../src/components/file-input/file-type.ts
605
+ var fileType = (mimeType) => {
606
+ const type = mimeType.split(";", 1)[0]?.trim().toLowerCase() ?? "";
607
+ if (!type || type === "application/octet-stream")
608
+ return "file";
609
+ if (type.startsWith("image/"))
610
+ return "image";
611
+ if (type.startsWith("video/"))
612
+ return "video";
613
+ if (type.startsWith("audio/"))
614
+ return "audio";
615
+ if (type.startsWith("font/"))
616
+ return "font";
617
+ if (type.startsWith("model/"))
618
+ return "model";
619
+ if (type.startsWith("message/"))
620
+ return "mail";
621
+ if (type.endsWith("+json") || type === "application/json")
622
+ return "json";
623
+ if (type.includes("spreadsheet") || type.includes("ms-excel"))
624
+ return "spreadsheet";
625
+ if (type.includes("presentation") || type.includes("ms-powerpoint"))
626
+ return "presentation";
627
+ switch (type) {
628
+ case "text/vtt":
629
+ case "application/x-subrip":
630
+ case "application/ttml+xml":
631
+ return "caption";
632
+ case "application/zip":
633
+ case "application/x-zip-compressed":
634
+ case "application/x-7z-compressed":
635
+ case "application/vnd.rar":
636
+ case "application/x-rar-compressed":
637
+ case "application/x-tar":
638
+ case "application/gzip":
639
+ case "application/x-gzip":
640
+ case "application/x-bzip2":
641
+ case "application/x-xz":
642
+ case "application/zstd":
643
+ return "archive";
644
+ case "text/csv":
645
+ case "text/tab-separated-values":
646
+ return "spreadsheet";
647
+ case "text/html":
648
+ case "application/xhtml+xml":
649
+ return "web";
650
+ case "text/css":
651
+ case "text/javascript":
652
+ case "application/javascript":
653
+ case "text/typescript":
654
+ case "application/typescript":
655
+ case "application/yaml":
656
+ case "text/yaml":
657
+ case "application/toml":
658
+ return "code";
659
+ case "application/x-sh":
660
+ case "text/x-shellscript":
661
+ case "application/x-bat":
662
+ return "script";
663
+ case "application/sql":
664
+ case "application/vnd.sqlite3":
665
+ case "application/x-sqlite3":
666
+ return "database";
667
+ case "application/epub+zip":
668
+ case "application/x-mobipocket-ebook":
669
+ case "application/vnd.amazon.ebook":
670
+ return "book";
671
+ case "application/x-iso9660-image":
672
+ case "application/x-apple-diskimage":
673
+ return "disc";
674
+ case "application/vnd.android.package-archive":
675
+ case "application/x-debian-package":
676
+ case "application/x-rpm":
677
+ case "application/x-msi":
678
+ return "package";
679
+ case "application/wasm":
680
+ case "application/x-msdownload":
681
+ case "application/x-executable":
682
+ return "binary";
683
+ case "application/vnd.ms-fontobject":
684
+ case "application/font-woff":
685
+ case "application/x-font-ttf":
686
+ return "font";
687
+ case "application/vnd.ms-outlook":
688
+ return "mail";
689
+ case "text/calendar":
690
+ return "calendar";
691
+ case "text/vcard":
692
+ case "text/x-vcard":
693
+ return "contact";
694
+ case "application/xml":
695
+ case "text/xml":
696
+ return "code";
697
+ default:
698
+ if (type.endsWith("+xml") || type.startsWith("text/x-"))
699
+ return "code";
700
+ if (type.startsWith("text/") || type.includes("word") || type === "application/pdf" || type === "application/rtf")
701
+ return "document";
702
+ return "file";
703
+ }
704
+ };
705
+
706
+ // ../../src/components/file-input/index.ts
707
+ import { Redacted, Schema as Schema4 } from "effect";
708
+ import { Component as Component2, UiSchema as UiSchema2 } from "effect/ui";
709
+
710
+ // ../../src/components/file-input/schema.ts
711
+ import { Schema as Schema3, Struct as Struct2 } from "effect";
712
+ var AcceptLabel = Schema3.declare((value) => typeof value === "function").annotate({ identifier: "FilePickerAcceptLabel" });
713
+ var FilePickerFilesSchema = Schema3.Redacted(Schema3.Array(Schema3.File)).annotate({ identifier: "FilePickerFiles" });
714
+ var FileInputClassesOverridesSchema = Schema3.Record(Schema3.Literals(Struct2.keys(fileInputClasses)), Schema3.optionalKey(Schema3.String)).annotate({ identifier: "FileInputClassesOverrides" });
715
+ var FilePickerPropsSchema = Schema3.Struct({
716
+ classes: Schema3.optional(FileInputClassesOverridesSchema),
717
+ accept: Schema3.optional(Schema3.String),
718
+ canClear: Schema3.optional(Schema3.Boolean),
719
+ file: Schema3.optional(Schema3.File),
720
+ files: Schema3.optional(Schema3.Array(Schema3.File)),
721
+ id: Schema3.String,
722
+ image: Schema3.optional(Schema3.Struct({
723
+ alt: Schema3.String,
724
+ height: Schema3.Number,
725
+ src: Schema3.optional(Schema3.String),
726
+ width: Schema3.Number
727
+ }).annotate({ identifier: "FilePickerImage" })),
728
+ invalid: Schema3.optional(Schema3.Boolean),
729
+ locale: Schema3.optional(Schema3.String),
730
+ messages: Schema3.optional(Schema3.Record(Schema3.String, Schema3.Struct({
731
+ accepts: Schema3.optional(AcceptLabel),
732
+ chooseFile: Schema3.optional(Schema3.String),
733
+ chooseFiles: Schema3.optional(Schema3.String),
734
+ deleteFile: Schema3.optional(Schema3.String),
735
+ dropFile: Schema3.optional(Schema3.String),
736
+ dropFiles: Schema3.optional(Schema3.String),
737
+ replaceFile: Schema3.optional(Schema3.String)
738
+ }).annotate({ identifier: "FilePickerMessageOverrides" }))),
739
+ multiple: Schema3.optional(Schema3.Boolean),
740
+ name: Schema3.String,
741
+ required: Schema3.optional(Schema3.Boolean),
742
+ showImageThumbnails: Schema3.optionalKey(Schema3.Boolean)
743
+ }).annotate({ identifier: "FilePickerProps" });
744
+
745
+ // ../../src/components/file-input/index.ts
746
+ var defaultMessages2 = {
747
+ en: {
748
+ accepts: (accepts) => `Accepts: ${accepts}`,
749
+ chooseFile: "Choose file",
750
+ chooseFiles: "Choose files",
751
+ deleteFile: "Delete",
752
+ dropFile: "Drag and drop a file here",
753
+ dropFiles: "Drag and drop files here",
754
+ replaceFile: "Replace file"
755
+ },
756
+ fr: {
757
+ accepts: (accepts) => `Accepte : ${accepts}`,
758
+ chooseFile: "Choisir un fichier",
759
+ chooseFiles: "Choisir des fichiers",
760
+ deleteFile: "Supprimer",
761
+ dropFile: "Glissez-déposez un fichier ici",
762
+ dropFiles: "Glissez-déposez des fichiers ici",
763
+ replaceFile: "Remplacer le fichier"
764
+ }
765
+ };
766
+ var filePickerMessages = (locale = "en", translations) => ({
767
+ ...locale.startsWith("fr") ? defaultMessages2.fr : defaultMessages2.en,
768
+ ...translations?.[locale.split("-")[0] ?? locale],
769
+ ...translations?.[locale]
770
+ });
771
+ var formatBytes = (bytes, locale) => {
772
+ const units = [
773
+ "byte",
774
+ "kilobyte",
775
+ "megabyte",
776
+ "gigabyte",
777
+ "terabyte"
778
+ ];
779
+ const index = Math.min(bytes === 0 ? 0 : Math.floor(Math.log(bytes) / Math.log(1024)), units.length - 1);
780
+ const value = index === 0 ? bytes : Number((bytes / 1024 ** index).toFixed(1));
781
+ return new Intl.NumberFormat(locale, {
782
+ style: "unit",
783
+ unit: units[index],
784
+ unitDisplay: "short"
785
+ }).format(value);
786
+ };
787
+ var fileDescription = (file, locale) => [
788
+ (file.name.includes(".") ? file.name.split(".").pop()?.toUpperCase() : "") || file.type.split("/").pop()?.toUpperCase(),
789
+ formatBytes(file.size, locale)
790
+ ].filter(Boolean).join(" · ");
791
+ var filePickerKey = ({ name, size, lastModified }) => `${name}:${size}:${lastModified}`;
792
+ var mergePickedFiles = (files, added) => Array.from(new Map([...files, ...added].map((file) => [filePickerKey(file), file])).values());
793
+ var FilePickerMessage = UiSchema2.TaggedEnum({
794
+ Selected: { files: FilePickerFilesSchema },
795
+ Dropped: { files: FilePickerFilesSchema },
796
+ Removed: { index: Schema4.Int },
797
+ Cleared: {},
798
+ Blurred: {},
799
+ DragEntered: {},
800
+ DragLeft: {}
801
+ }).annotate({ identifier: "FilePickerMessage" });
802
+ var FilePickerEvents = UiSchema2.TaggedEnum({
803
+ Change: { file: Schema4.Redacted(Schema4.File) },
804
+ FilesChange: { files: FilePickerFilesSchema },
805
+ Clear: {},
806
+ Blur: {}
807
+ }).annotate({ identifier: "FilePickerEvents" });
808
+ var filePickerOptions = {
809
+ name: "FilePicker",
810
+ props: FilePickerPropsSchema,
811
+ model: Schema4.Int,
812
+ message: FilePickerMessage,
813
+ events: FilePickerEvents,
814
+ restore: false
815
+ };
816
+ var selectFiles = ($, files, dropped) => {
817
+ const events = [];
818
+ if (files.length > 0) {
819
+ if ($.props.multiple) {
820
+ events.push(FilePickerEvents.FilesChange({
821
+ files: Redacted.make(mergePickedFiles($.props.files ?? [], files))
822
+ }));
823
+ } else if (files[0]) {
824
+ events.push(FilePickerEvents.Change({ file: Redacted.make(files[0]) }));
825
+ }
826
+ }
827
+ if (dropped)
828
+ events.push(FilePickerEvents.Blur());
829
+ return $.set(dropped ? 0 : $.model).emit(...events);
830
+ };
831
+ var filePickerBehaviours = {
832
+ init: () => 0,
833
+ update: Component2.define(filePickerOptions).update({
834
+ Selected: ($, { files }) => selectFiles($, Redacted.value(files), false),
835
+ Dropped: ($, { files }) => selectFiles($, Redacted.value(files), true),
836
+ Removed: ($, { index }) => $.set($.model).emit(FilePickerEvents.FilesChange({
837
+ files: Redacted.make(($.props.files ?? []).filter((_, position) => position !== index))
838
+ })),
839
+ Cleared: ($) => $.set($.model).emit(FilePickerEvents.Clear()),
840
+ Blurred: ($) => $.set($.model).emit(FilePickerEvents.Blur()),
841
+ DragEntered: ($) => $.model + 1,
842
+ DragLeft: ($) => Math.max(0, $.model - 1)
843
+ })
844
+ };
845
+
846
+ // ../../src/components/file-input/react.tsx
847
+ import { jsx as jsx2, jsxs as jsxs2, Fragment as Fragment2 } from "react/jsx-runtime";
848
+ "use client";
849
+ var fileIcons = {
850
+ file: FileIcon,
851
+ archive: FileArchive,
852
+ binary: Binary,
853
+ book: BookOpen,
854
+ calendar: CalendarDays,
855
+ code: FileCode,
856
+ contact: Contact,
857
+ database: Database,
858
+ disc: Disc3,
859
+ font: FileType,
860
+ json: FileJson,
861
+ mail: Mail,
862
+ model: Box,
863
+ package: Package,
864
+ presentation: Presentation,
865
+ script: FileTerminal,
866
+ web: Globe,
867
+ image: FileImage,
868
+ video: FileVideo,
869
+ audio: FileAudio,
870
+ caption: Captions,
871
+ spreadsheet: FileSpreadsheet,
872
+ document: FileText
873
+ };
874
+ var FileTypeIcon = ({ mimeType }) => {
875
+ const Icon = fileIcons[fileType(mimeType)];
876
+ return /* @__PURE__ */ jsx2(Icon, {
877
+ "aria-hidden": "true"
878
+ });
879
+ };
880
+ var FileThumbnail = ({ file }) => {
881
+ const image = useRef2(null);
882
+ const isImage = fileType(file.type) === "image";
883
+ useEffect2(() => {
884
+ const element = image.current;
885
+ if (!element || typeof URL.createObjectURL !== "function")
886
+ return;
887
+ const url = URL.createObjectURL(file);
888
+ element.src = url;
889
+ return () => {
890
+ element.removeAttribute("src");
891
+ URL.revokeObjectURL(url);
892
+ };
893
+ }, [file, isImage]);
894
+ return isImage ? /* @__PURE__ */ jsx2("img", {
895
+ ref: image,
896
+ alt: "",
897
+ className: "size-9 shrink-0 rounded-md object-cover"
898
+ }) : /* @__PURE__ */ jsx2(FileTypeIcon, {
899
+ mimeType: file.type
900
+ });
901
+ };
902
+ var FileInput = ({
903
+ actions,
904
+ classes: classOverrides,
905
+ accept = "",
906
+ canClear = true,
907
+ file,
908
+ files = [],
909
+ id,
910
+ image,
911
+ invalid = false,
912
+ locale: localeOverride,
913
+ messages,
914
+ multiple = false,
915
+ name,
916
+ onBlur,
917
+ onChange,
918
+ onClear,
919
+ onFilesChange,
920
+ required,
921
+ showAcceptHint = true,
922
+ showImageThumbnails,
923
+ title
924
+ }) => {
925
+ const fileInputClasses = resolveFileInputClasses(classOverrides);
926
+ const locale = useKrakstackLocale2(localeOverride);
927
+ const labels = filePickerMessages(locale, messages);
928
+ const inputRef = useRef2(null);
929
+ const dragDepthRef = useRef2(0);
930
+ const [dragging, setDragging] = useState2(false);
931
+ const imageEnabled = image !== undefined;
932
+ const objectUrl = useMemo(() => file && imageEnabled ? URL.createObjectURL(file) : undefined, [file, imageEnabled]);
933
+ useEffect2(() => () => {
934
+ if (objectUrl)
935
+ URL.revokeObjectURL(objectUrl);
936
+ }, [objectUrl]);
937
+ const imageUrl = objectUrl ?? image?.src;
938
+ const selected = Boolean(file || imageUrl);
939
+ const selectFiles = (nextFiles) => {
940
+ const selectedFiles = Array.from(nextFiles);
941
+ if (multiple) {
942
+ onFilesChange?.(mergePickedFiles(files, selectedFiles));
943
+ } else if (selectedFiles[0]) {
944
+ onChange?.(selectedFiles[0]);
945
+ }
946
+ };
947
+ const handleDrop = (event) => {
948
+ event.preventDefault();
949
+ dragDepthRef.current = 0;
950
+ setDragging(false);
951
+ selectFiles(event.dataTransfer.files);
952
+ onBlur?.();
953
+ };
954
+ const clear = () => {
955
+ onClear();
956
+ if (inputRef.current)
957
+ inputRef.current.value = "";
958
+ };
959
+ const input = /* @__PURE__ */ jsx2(Input, {
960
+ ref: inputRef,
961
+ className: "sr-only",
962
+ hidden: !multiple && selected,
963
+ id,
964
+ name,
965
+ type: "file",
966
+ accept,
967
+ multiple,
968
+ required: required && (multiple ? files.length === 0 : !selected),
969
+ onBlur,
970
+ onChange: (event) => {
971
+ if (event.target.files)
972
+ selectFiles(event.target.files);
973
+ if (multiple || !name)
974
+ event.target.value = "";
975
+ },
976
+ "aria-invalid": invalid
977
+ });
978
+ const dropzone = /* @__PURE__ */ jsxs2("div", {
979
+ className: "bg-muted/30 data-[dragging=true]:bg-muted flex min-h-32 min-w-0 flex-col items-center justify-center gap-3 rounded-xl border border-dashed p-6 text-center transition-colors",
980
+ "data-dragging": dragging,
981
+ onDragEnter: (event) => {
982
+ event.preventDefault();
983
+ dragDepthRef.current += 1;
984
+ setDragging(true);
985
+ },
986
+ onDragLeave: (event) => {
987
+ event.preventDefault();
988
+ dragDepthRef.current = Math.max(0, dragDepthRef.current - 1);
989
+ if (dragDepthRef.current === 0)
990
+ setDragging(false);
991
+ },
992
+ onDragOver: (event) => event.preventDefault(),
993
+ onDrop: handleDrop,
994
+ children: [
995
+ /* @__PURE__ */ jsx2(CloudUpload, {
996
+ className: "text-muted-foreground size-6"
997
+ }),
998
+ /* @__PURE__ */ jsxs2("div", {
999
+ className: "max-w-full min-w-0",
1000
+ children: [
1001
+ /* @__PURE__ */ jsx2("p", {
1002
+ className: "text-sm font-medium",
1003
+ children: multiple ? labels.dropFiles : labels.dropFile
1004
+ }),
1005
+ showAcceptHint && accept && /* @__PURE__ */ jsx2("p", {
1006
+ className: "text-muted-foreground text-xs [overflow-wrap:anywhere]",
1007
+ children: labels.accepts(accept)
1008
+ })
1009
+ ]
1010
+ }),
1011
+ /* @__PURE__ */ jsxs2("div", {
1012
+ className: "flex flex-wrap items-center justify-center gap-2",
1013
+ children: [
1014
+ /* @__PURE__ */ jsxs2(Button2, {
1015
+ type: "button",
1016
+ variant: "outline",
1017
+ onClick: () => inputRef.current?.click(),
1018
+ children: [
1019
+ /* @__PURE__ */ jsx2(FileUp, {
1020
+ "data-icon": "inline-start"
1021
+ }),
1022
+ multiple ? labels.chooseFiles : labels.chooseFile
1023
+ ]
1024
+ }),
1025
+ actions
1026
+ ]
1027
+ })
1028
+ ]
1029
+ });
1030
+ if (multiple) {
1031
+ return /* @__PURE__ */ jsxs2("div", {
1032
+ className: fileInputClasses.root,
1033
+ children: [
1034
+ dropzone,
1035
+ input,
1036
+ files.length > 0 ? /* @__PURE__ */ jsx2(AttachmentGroup, {
1037
+ className: "w-full px-1 focus-within:mask-none",
1038
+ children: files.map((selectedFile) => /* @__PURE__ */ jsxs2(Attachment, {
1039
+ className: "focus-within:ring-0",
1040
+ state: invalid ? "error" : "idle",
1041
+ children: [
1042
+ /* @__PURE__ */ jsx2(AttachmentMedia, {
1043
+ children: showImageThumbnails ? /* @__PURE__ */ jsx2(FileThumbnail, {
1044
+ file: selectedFile
1045
+ }) : /* @__PURE__ */ jsx2(FileTypeIcon, {
1046
+ mimeType: selectedFile.type
1047
+ })
1048
+ }),
1049
+ /* @__PURE__ */ jsxs2(AttachmentContent, {
1050
+ children: [
1051
+ /* @__PURE__ */ jsx2(AttachmentTitle, {
1052
+ children: selectedFile.name
1053
+ }),
1054
+ /* @__PURE__ */ jsx2(AttachmentDescription, {
1055
+ children: fileDescription(selectedFile, locale)
1056
+ })
1057
+ ]
1058
+ }),
1059
+ /* @__PURE__ */ jsx2(AttachmentActions, {
1060
+ children: /* @__PURE__ */ jsx2(AttachmentAction, {
1061
+ type: "button",
1062
+ "aria-label": `${labels.deleteFile} ${selectedFile.name}`,
1063
+ onClick: () => onFilesChange?.(files.filter((candidate) => candidate !== selectedFile)),
1064
+ children: /* @__PURE__ */ jsx2(X2, {
1065
+ "aria-hidden": "true"
1066
+ })
1067
+ })
1068
+ })
1069
+ ]
1070
+ }, filePickerKey(selectedFile)))
1071
+ }) : null
1072
+ ]
1073
+ });
1074
+ }
1075
+ return /* @__PURE__ */ jsxs2(Fragment2, {
1076
+ children: [
1077
+ !selected ? dropzone : /* @__PURE__ */ jsxs2(Attachment, {
1078
+ className: "w-full focus-within:ring-0",
1079
+ orientation: "horizontal",
1080
+ state: invalid ? "error" : "done",
1081
+ children: [
1082
+ /* @__PURE__ */ jsx2(AttachmentMedia, {
1083
+ variant: image ? "image" : "icon",
1084
+ className: image ? "aspect-auto max-w-full border [&_img]:aspect-auto! [&_img]:object-contain!" : undefined,
1085
+ style: image ? {
1086
+ width: image.width,
1087
+ aspectRatio: `${image.width} / ${image.height}`
1088
+ } : undefined,
1089
+ children: image && imageUrl ? /* @__PURE__ */ jsx2("img", {
1090
+ src: imageUrl,
1091
+ alt: image.alt,
1092
+ width: image.width,
1093
+ height: image.height,
1094
+ className: "size-full object-contain"
1095
+ }) : file && showImageThumbnails ? /* @__PURE__ */ jsx2(FileThumbnail, {
1096
+ file
1097
+ }) : /* @__PURE__ */ jsx2(FileTypeIcon, {
1098
+ mimeType: file?.type ?? ""
1099
+ })
1100
+ }),
1101
+ /* @__PURE__ */ jsxs2(AttachmentContent, {
1102
+ children: [
1103
+ /* @__PURE__ */ jsx2(AttachmentTitle, {
1104
+ children: file?.name ?? title
1105
+ }),
1106
+ file ? /* @__PURE__ */ jsx2(AttachmentDescription, {
1107
+ className: "break-words",
1108
+ children: fileDescription(file, locale)
1109
+ }) : null
1110
+ ]
1111
+ }),
1112
+ canClear && /* @__PURE__ */ jsx2(AttachmentActions, {
1113
+ className: "ml-auto",
1114
+ children: /* @__PURE__ */ jsx2(AttachmentAction, {
1115
+ type: "button",
1116
+ "aria-label": `${labels.deleteFile} ${Schema5.is(Schema5.String)(title) ? title : ""}`,
1117
+ onClick: clear,
1118
+ children: /* @__PURE__ */ jsx2(X2, {
1119
+ "aria-hidden": "true"
1120
+ })
1121
+ })
1122
+ })
1123
+ ]
1124
+ }),
1125
+ input
1126
+ ]
1127
+ });
1128
+ };
1129
+
1130
+ // ../../src/components/upload-attachment/react.tsx
1131
+ import {
1132
+ Check as Check2,
1133
+ File,
1134
+ LoaderCircle,
1135
+ RotateCcw,
1136
+ TriangleAlert,
1137
+ X as X3
1138
+ } from "lucide-react";
1139
+ import { useId } from "react";
1140
+ import {
1141
+ Attachment as Attachment2,
1142
+ AttachmentActions as AttachmentActions2,
1143
+ AttachmentContent as AttachmentContent2,
1144
+ AttachmentDescription as AttachmentDescription2,
1145
+ AttachmentMedia as AttachmentMedia2,
1146
+ AttachmentTitle as AttachmentTitle2
1147
+ } from "@/components/ui/attachment";
1148
+ import { Button as Button3 } from "@/components/ui/button";
1149
+ import { useKrakstackLocale as useKrakstackLocale3 } from "@krak-stack/registry/krakstack-provider/react";
1150
+
1151
+ // ../../src/components/upload-attachment/classes.ts
1152
+ var uploadAttachmentStatusRowClass = "mt-1 flex items-center gap-2";
1153
+ var uploadAttachmentClasses = {
1154
+ pendingIcon: "motion-safe:animate-spin",
1155
+ status: "text-muted-foreground text-xs",
1156
+ 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"
1157
+ };
1158
+ var resolveUploadAttachmentClasses = (overrides) => ({
1159
+ ...uploadAttachmentClasses,
1160
+ ...overrides
1161
+ });
1162
+
1163
+ // ../../src/components/upload-attachment/index.ts
1164
+ import { Schema as Schema7 } from "effect";
1165
+ import { Component as Component3, UiSchema as UiSchema3 } from "effect/ui";
1166
+
1167
+ // ../../src/components/upload-attachment/schema.ts
1168
+ import { Schema as Schema6, Struct as Struct3 } from "effect";
1169
+ var UploadAttachmentStateSchema = Schema6.Union([
1170
+ Schema6.Struct({
1171
+ status: Schema6.Literals(["idle", "processing", "done", "cancelled"])
1172
+ }),
1173
+ Schema6.Struct({
1174
+ status: Schema6.Literal("uploading"),
1175
+ progress: Schema6.optional(Schema6.Number)
1176
+ }),
1177
+ Schema6.Struct({ status: Schema6.Literal("error"), message: Schema6.String })
1178
+ ]).annotate({ identifier: "UploadAttachmentState" });
1179
+ var Messages = Schema6.Struct({
1180
+ idle: Schema6.String,
1181
+ uploading: Schema6.String,
1182
+ processing: Schema6.String,
1183
+ done: Schema6.String,
1184
+ cancelled: Schema6.String,
1185
+ cancel: Schema6.String,
1186
+ retry: Schema6.String,
1187
+ remove: Schema6.String
1188
+ }).annotate({ identifier: "UploadAttachmentMessages" });
1189
+ var UploadAttachmentClassesOverridesSchema = Schema6.Record(Schema6.Literals(Struct3.keys(uploadAttachmentClasses)), Schema6.optionalKey(Schema6.String)).annotate({ identifier: "UploadAttachmentClassesOverrides" });
1190
+ var UploadAttachmentPropsSchema = Schema6.Struct({
1191
+ classes: Schema6.optional(UploadAttachmentClassesOverridesSchema),
1192
+ name: Schema6.String,
1193
+ description: Schema6.optional(Schema6.String),
1194
+ state: UploadAttachmentStateSchema,
1195
+ disabled: Schema6.optional(Schema6.Boolean),
1196
+ className: Schema6.optional(Schema6.String),
1197
+ locale: Schema6.optional(Schema6.String),
1198
+ messages: Schema6.optional(Schema6.Record(Schema6.String, Messages.mapFields((fields) => ({
1199
+ idle: Schema6.optional(fields.idle),
1200
+ uploading: Schema6.optional(fields.uploading),
1201
+ processing: Schema6.optional(fields.processing),
1202
+ done: Schema6.optional(fields.done),
1203
+ cancelled: Schema6.optional(fields.cancelled),
1204
+ cancel: Schema6.optional(fields.cancel),
1205
+ retry: Schema6.optional(fields.retry),
1206
+ remove: Schema6.optional(fields.remove)
1207
+ }))))
1208
+ }).annotate({ identifier: "UploadAttachmentProps" });
1209
+
1210
+ // ../../src/components/upload-attachment/index.ts
1211
+ var defaultMessages3 = {
1212
+ en: {
1213
+ idle: "Ready to upload",
1214
+ uploading: "Uploading",
1215
+ processing: "Processing",
1216
+ done: "Upload complete",
1217
+ cancelled: "Upload cancelled",
1218
+ cancel: "Cancel upload",
1219
+ retry: "Retry upload",
1220
+ remove: "Remove attachment"
1221
+ },
1222
+ fr: {
1223
+ idle: "Prêt à téléverser",
1224
+ uploading: "Téléversement",
1225
+ processing: "Traitement",
1226
+ done: "Téléversement terminé",
1227
+ cancelled: "Téléversement annulé",
1228
+ cancel: "Annuler le téléversement",
1229
+ retry: "Réessayer le téléversement",
1230
+ remove: "Retirer la pièce jointe"
1231
+ }
1232
+ };
1233
+ var getUploadAttachmentPresentation = (state, locale = "en", messages) => {
1234
+ const copy = {
1235
+ ...locale.startsWith("fr") ? defaultMessages3.fr : defaultMessages3.en,
1236
+ ...messages?.[locale.split("-")[0] ?? locale],
1237
+ ...messages?.[locale]
1238
+ };
1239
+ return {
1240
+ copy,
1241
+ busy: state.status === "uploading" || state.status === "processing",
1242
+ retry: state.status === "error" || state.status === "cancelled",
1243
+ progress: state.status === "uploading" && state.progress !== undefined && Number.isFinite(state.progress) ? Math.min(100, Math.max(0, state.progress)) : undefined,
1244
+ status: state.status === "error" ? state.message : copy[state.status]
1245
+ };
1246
+ };
1247
+ var UploadAttachmentAction = UiSchema3.TaggedEnum({
1248
+ Cancel: {},
1249
+ Retry: {},
1250
+ Remove: {}
1251
+ }).annotate({ identifier: "UploadAttachmentAction" });
1252
+ var uploadAttachmentOptions = {
1253
+ name: "UploadAttachment",
1254
+ props: UploadAttachmentPropsSchema,
1255
+ model: Schema7.Null,
1256
+ message: UploadAttachmentAction,
1257
+ events: UploadAttachmentAction,
1258
+ restore: false
1259
+ };
1260
+ var update2 = ($, action) => {
1261
+ const { busy, retry } = getUploadAttachmentPresentation($.props.state);
1262
+ const available = action._tag === "Cancel" ? busy : action._tag === "Retry" ? retry : !busy;
1263
+ return !$.props.disabled && available ? $.set(null).emit(action) : null;
1264
+ };
1265
+ var uploadAttachmentBehaviours = {
1266
+ init: () => null,
1267
+ update: Component3.define(uploadAttachmentOptions).update({
1268
+ Cancel: update2,
1269
+ Retry: update2,
1270
+ Remove: update2
1271
+ })
1272
+ };
1273
+
1274
+ // ../../src/components/upload-attachment/react.tsx
1275
+ import { jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
1276
+ var UploadAttachment = ({
1277
+ classes: classOverrides,
1278
+ name,
1279
+ description,
1280
+ fileIcon,
1281
+ state,
1282
+ disabled,
1283
+ onCancel,
1284
+ onRetry,
1285
+ onRemove,
1286
+ className,
1287
+ locale: override,
1288
+ messages
1289
+ }) => {
1290
+ const uploadAttachmentClasses = resolveUploadAttachmentClasses(classOverrides);
1291
+ const locale = useKrakstackLocale3(override);
1292
+ const id = useId();
1293
+ const { copy, busy, progress, status, retry } = getUploadAttachmentPresentation(state, locale, messages);
1294
+ return /* @__PURE__ */ jsxs3(Attachment2, {
1295
+ "data-component": "upload-attachment",
1296
+ state: state.status === "cancelled" ? "idle" : state.status,
1297
+ className,
1298
+ "aria-labelledby": `${id}-name`,
1299
+ children: [
1300
+ /* @__PURE__ */ jsx3(AttachmentMedia2, {
1301
+ children: fileIcon ?? (state.status === "done" ? /* @__PURE__ */ jsx3(Check2, {
1302
+ "aria-hidden": "true"
1303
+ }) : state.status === "error" ? /* @__PURE__ */ jsx3(TriangleAlert, {
1304
+ "aria-hidden": "true"
1305
+ }) : busy ? /* @__PURE__ */ jsx3(LoaderCircle, {
1306
+ "aria-hidden": "true",
1307
+ className: uploadAttachmentClasses.pendingIcon
1308
+ }) : /* @__PURE__ */ jsx3(File, {
1309
+ "aria-hidden": "true"
1310
+ }))
1311
+ }),
1312
+ /* @__PURE__ */ jsxs3(AttachmentContent2, {
1313
+ children: [
1314
+ /* @__PURE__ */ jsx3(AttachmentTitle2, {
1315
+ id: `${id}-name`,
1316
+ title: name,
1317
+ children: name
1318
+ }),
1319
+ description ? /* @__PURE__ */ jsx3(AttachmentDescription2, {
1320
+ children: description
1321
+ }) : null,
1322
+ /* @__PURE__ */ jsxs3("div", {
1323
+ className: uploadAttachmentStatusRowClass,
1324
+ children: [
1325
+ /* @__PURE__ */ jsx3("p", {
1326
+ "data-slot": "upload-attachment-status",
1327
+ role: state.status === "error" ? "alert" : "status",
1328
+ className: uploadAttachmentClasses.status,
1329
+ children: status
1330
+ }),
1331
+ state.status === "uploading" ? /* @__PURE__ */ jsx3("progress", {
1332
+ "data-slot": "upload-attachment-progress",
1333
+ className: uploadAttachmentClasses.progress,
1334
+ "aria-label": `${copy.uploading}: ${name}`,
1335
+ max: 100,
1336
+ value: progress
1337
+ }) : null
1338
+ ]
1339
+ })
1340
+ ]
1341
+ }),
1342
+ /* @__PURE__ */ jsxs3(AttachmentActions2, {
1343
+ children: [
1344
+ busy && onCancel ? /* @__PURE__ */ jsx3(Button3, {
1345
+ type: "button",
1346
+ variant: "ghost",
1347
+ size: "icon-sm",
1348
+ disabled,
1349
+ "aria-label": `${copy.cancel}: ${name}`,
1350
+ onClick: onCancel,
1351
+ children: /* @__PURE__ */ jsx3(X3, {
1352
+ "aria-hidden": "true"
1353
+ })
1354
+ }) : null,
1355
+ retry && onRetry ? /* @__PURE__ */ jsx3(Button3, {
1356
+ type: "button",
1357
+ variant: "ghost",
1358
+ size: "icon-sm",
1359
+ disabled,
1360
+ "aria-label": `${copy.retry}: ${name}`,
1361
+ onClick: onRetry,
1362
+ children: /* @__PURE__ */ jsx3(RotateCcw, {
1363
+ "aria-hidden": "true"
1364
+ })
1365
+ }) : null,
1366
+ !busy && onRemove ? /* @__PURE__ */ jsx3(Button3, {
1367
+ type: "button",
1368
+ variant: "ghost",
1369
+ size: "icon-sm",
1370
+ disabled,
1371
+ "aria-label": `${copy.remove}: ${name}`,
1372
+ onClick: onRemove,
1373
+ children: /* @__PURE__ */ jsx3(X3, {
1374
+ "aria-hidden": "true"
1375
+ })
1376
+ }) : null
1377
+ ]
1378
+ })
1379
+ ]
1380
+ });
1381
+ };
1382
+
1383
+ // ../assets/src/components/asset-input/upload.tsx
1384
+ import { Button as Button4 } from "@/components/ui/button";
1385
+ import {
1386
+ Dialog,
1387
+ DialogClose,
1388
+ DialogContent,
1389
+ DialogDescription,
1390
+ DialogFooter,
1391
+ DialogHeader,
1392
+ DialogTitle,
1393
+ DialogTrigger
1394
+ } from "@/components/ui/dialog";
1395
+ import { useModel } from "@krak-stack/registry/effect-ui-adapter/react";
1396
+
1397
+ // ../assets/src/components/asset-input/index.ts
1398
+ import { Effect as Effect2, Queue, Redacted as Redacted2, Schema as Schema10, Stream } from "effect";
1399
+ import { Command, Component as Component5, UiSchema as UiSchema5 } from "effect/ui";
1400
+
1401
+ // ../assets/src/services/assets/library.ts
1402
+ import {
1403
+ Context,
1404
+ Schema as Schema8
1405
+ } from "effect";
1406
+ import { AsyncResult } from "effect/reactivity";
1407
+ import { Component as Component4, Query, UiSchema as UiSchema4, View } from "effect/ui";
1408
+ var AssetLibraryAccessSchema = Schema8.Struct({
1409
+ scopeKey: Schema8.NonEmptyString,
1410
+ permissions: Schema8.Array(Schema8.Literals(["list", "read", "create", "update", "delete"]))
1411
+ }).annotate({ identifier: "AssetLibraryAccess" });
1412
+ var AssetListQuerySchema = Schema8.Struct({
1413
+ search: Schema8.optionalKey(Schema8.String.check(Schema8.isMaxLength(200))),
1414
+ kind: Schema8.optionalKey(Schema8.Literals(["image", "video", "caption", "document"]))
1415
+ }).annotate({ identifier: "AssetListQuery" });
1416
+ var AssetListItemSchema = Schema8.Struct({
1417
+ id: Schema8.String.check(Schema8.isUUID()),
1418
+ name: Schema8.NonEmptyString,
1419
+ mimeType: Schema8.NonEmptyString,
1420
+ byteSize: Schema8.Int,
1421
+ createdAt: Schema8.Date,
1422
+ updatedAt: Schema8.Date,
1423
+ url: Schema8.optionalKey(Schema8.String)
1424
+ }).annotate({ identifier: "AssetListItem" });
1425
+ var AssetStatsSchema = Schema8.Struct({
1426
+ assetCount: Schema8.Int,
1427
+ storageUsedBytes: Schema8.Int
1428
+ }).annotate({ identifier: "AssetStats" });
1429
+ var AssetListSchema = Schema8.Struct({
1430
+ items: Schema8.Array(AssetListItemSchema),
1431
+ stats: AssetStatsSchema
1432
+ }).annotate({ identifier: "AssetList" });
1433
+ var AssetListArgsSchema = Schema8.Struct({
1434
+ ...AssetListQuerySchema.fields,
1435
+ scopeKey: Schema8.NonEmptyString,
1436
+ showFiles: Schema8.Boolean
1437
+ }).annotate({ identifier: "AssetListArgs" });
1438
+ var AssetListError = Schema8.Literals([
1439
+ "unauthorized",
1440
+ "forbidden",
1441
+ "unavailable"
1442
+ ]).annotate({ identifier: "AssetListError" });
1443
+
1444
+ class AssetList extends Query.Service()("@krak-stack/assets/AssetList", {
1445
+ args: AssetListArgsSchema,
1446
+ success: AssetListSchema,
1447
+ error: AssetListError,
1448
+ staleTime: "30 seconds"
1449
+ }) {
1450
+ }
1451
+ var assetListArgs = (scopeKey, permissions, query = {}) => permissions.includes("list") ? { ...query, scopeKey, showFiles: permissions.includes("read") } : undefined;
1452
+ var AssetLibrarySnapshot = Schema8.Struct({
1453
+ data: Schema8.NullOr(AssetListSchema),
1454
+ status: Schema8.Literals(["idle", "loading", "ready", "failed"])
1455
+ }).annotate({ identifier: "AssetLibrarySnapshot" });
1456
+ var AssetLibraryMessage = UiSchema4.TaggedEnum({
1457
+ LibraryChanged: { library: AssetLibrarySnapshot }
1458
+ }).annotate({ identifier: "AssetLibraryMessage" });
1459
+ var emptyAssetLibrary = { data: null, status: "idle" };
1460
+ var libraryQuery = (result) => AssetLibraryMessage.LibraryChanged({
1461
+ library: AsyncResult.isSuccess(result) ? { data: result.value, status: "ready" } : {
1462
+ data: null,
1463
+ status: AsyncResult.isFailure(result) ? "failed" : "loading"
1464
+ }
1465
+ });
1466
+ var options = {
1467
+ name: "AssetLibraryModel",
1468
+ props: Schema8.Struct({ access: AssetLibraryAccessSchema }).annotate({
1469
+ identifier: "AssetLibraryModelProps"
1470
+ }),
1471
+ model: AssetLibrarySnapshot,
1472
+ message: AssetLibraryMessage,
1473
+ restore: false,
1474
+ queries: {
1475
+ library: {
1476
+ query: AssetList,
1477
+ dropPrevious: true,
1478
+ args: ({ props }) => assetListArgs(props.access.scopeKey, props.access.permissions),
1479
+ onChange: libraryQuery
1480
+ }
1481
+ }
1482
+ };
1483
+ var definition = Component4.define(options);
1484
+ var AssetLibraryModel = definition.make({
1485
+ init: () => emptyAssetLibrary,
1486
+ update: definition.update({ LibraryChanged: (_, { library }) => library }),
1487
+ view: () => View.text("")
1488
+ });
1489
+ var AssetUploadTransportMessages = {
1490
+ en: {
1491
+ rejected: "The file did not pass the security scan.",
1492
+ failed: "The file could not be published."
1493
+ },
1494
+ fr: {
1495
+ rejected: "Le fichier n’a pas passé l’analyse de sécurité.",
1496
+ failed: "Impossible de publier le fichier."
1497
+ }
1498
+ };
1499
+
1500
+ class AssetLibraryActions extends Context.Service()("@krak-stack/assets/AssetLibraryActions") {
1501
+ }
1502
+
1503
+ // ../assets/src/components/asset-input/schema.ts
1504
+ import { Schema as Schema9 } from "effect";
1505
+ var AssetInputItemSchema = Schema9.Struct({
1506
+ id: Schema9.String,
1507
+ name: Schema9.String,
1508
+ mimeType: Schema9.String,
1509
+ url: Schema9.optionalKey(Schema9.String),
1510
+ updatedAt: Schema9.optionalKey(Schema9.Date)
1511
+ }).annotate({ identifier: "AssetInputItem" });
1512
+ var text = Schema9.optionalKey(Schema9.String);
1513
+ var flag = Schema9.optionalKey(Schema9.Boolean);
1514
+ var AssetKindSchema = Schema9.Literals([
1515
+ "document",
1516
+ "image",
1517
+ "video",
1518
+ "caption"
1519
+ ]);
1520
+ var AssetUploadMessagesSchema = Schema9.Record(Schema9.String, Schema9.Struct({
1521
+ upload: text,
1522
+ close: text,
1523
+ cancel: text,
1524
+ dialogTitle: text,
1525
+ dialogDescription: text,
1526
+ libraryDialogTitle: text,
1527
+ libraryDialogDescription: text,
1528
+ uploadError: text,
1529
+ kindError: text,
1530
+ publishError: text
1531
+ })).annotate({ identifier: "AssetUploadMessages" });
1532
+ var AssetUploadPropsSchema = Schema9.Struct({
1533
+ accept: text,
1534
+ processingLabel: text,
1535
+ messages: Schema9.optionalKey(AssetUploadMessagesSchema)
1536
+ }).annotate({ identifier: "AssetUploadProps" });
1537
+ var AssetInputPropsSchema = Schema9.Struct({
1538
+ label: Schema9.String,
1539
+ access: Schema9.optionalKey(AssetLibraryAccessSchema),
1540
+ replaceId: text,
1541
+ uploadTrigger: Schema9.optionalKey(Schema9.Literal("button")),
1542
+ assets: Schema9.optionalKey(Schema9.Array(AssetInputItemSchema)),
1543
+ kind: Schema9.optionalKey(AssetKindSchema),
1544
+ value: Schema9.optionalKey(Schema9.Union([Schema9.String, Schema9.Array(Schema9.String)])),
1545
+ multiple: flag,
1546
+ disabled: flag,
1547
+ locale: text,
1548
+ messages: Schema9.optionalKey(Schema9.Record(Schema9.String, Schema9.Struct({
1549
+ placeholder: text,
1550
+ multiplePlaceholder: text,
1551
+ empty: text,
1552
+ selected: text,
1553
+ remove: text
1554
+ }))),
1555
+ uploader: Schema9.optionalKey(AssetUploadPropsSchema)
1556
+ }).annotate({ identifier: "AssetInputProps" });
1557
+ var AssetUploadJobSchema = Schema9.Struct({
1558
+ id: Schema9.Int,
1559
+ file: Schema9.Redacted(Schema9.File),
1560
+ phase: Schema9.Literals([
1561
+ "uploading",
1562
+ "processing",
1563
+ "done",
1564
+ "error",
1565
+ "rejected"
1566
+ ]),
1567
+ progress: Schema9.optionalKey(Schema9.Finite),
1568
+ retryPublication: flag,
1569
+ error: text
1570
+ }).annotate({ identifier: "AssetUploadJob" });
1571
+
1572
+ // ../assets/src/components/asset-input/index.ts
1573
+ var inputCopy = {
1574
+ en: {
1575
+ placeholder: "Choose asset",
1576
+ multiplePlaceholder: "Choose assets",
1577
+ empty: "No assets found.",
1578
+ selected: "Selected asset",
1579
+ remove: "Remove asset"
1580
+ },
1581
+ fr: {
1582
+ placeholder: "Choisir un fichier existant",
1583
+ multiplePlaceholder: "Choisir des fichiers existants",
1584
+ empty: "Aucun fichier trouvé.",
1585
+ selected: "Fichier sélectionné",
1586
+ remove: "Retirer le fichier"
1587
+ }
1588
+ };
1589
+ var uploadCopy = {
1590
+ en: {
1591
+ upload: "Upload",
1592
+ dialogTitle: "Upload asset",
1593
+ dialogDescription: "This uploads and selects the file. Save the form separately to keep your changes.",
1594
+ libraryDialogTitle: "Upload files",
1595
+ libraryDialogDescription: "Review your files before uploading them to the library.",
1596
+ cancel: "Cancel",
1597
+ close: "Close",
1598
+ uploadError: "Could not upload the file.",
1599
+ kindError: "Choose a file of the required type.",
1600
+ publishError: "Could not confirm publication."
1601
+ },
1602
+ fr: {
1603
+ upload: "Téléverser",
1604
+ dialogTitle: "Téléverser un fichier",
1605
+ dialogDescription: "Le fichier sera téléversé et sélectionné. Enregistrez ensuite le formulaire pour conserver vos modifications.",
1606
+ libraryDialogTitle: "Téléverser des fichiers",
1607
+ libraryDialogDescription: "Vérifiez vos fichiers avant de les téléverser dans la bibliothèque.",
1608
+ cancel: "Annuler",
1609
+ close: "Fermer",
1610
+ uploadError: "Impossible de téléverser le fichier.",
1611
+ kindError: "Choisissez un fichier du type requis.",
1612
+ publishError: "Impossible de confirmer la publication."
1613
+ }
1614
+ };
1615
+ var language = (locale) => locale.split("-")[0] ?? locale;
1616
+ var assetInputMessages = (locale, messages) => ({
1617
+ ...language(locale) === "fr" ? inputCopy.fr : inputCopy.en,
1618
+ ...messages?.[language(locale)],
1619
+ ...messages?.[locale]
1620
+ });
1621
+ var assetUploadMessages = (locale, messages) => ({
1622
+ ...language(locale) === "fr" ? uploadCopy.fr : uploadCopy.en,
1623
+ ...messages?.[language(locale)],
1624
+ ...messages?.[locale]
1625
+ });
1626
+ var matchesAssetKind = (mimeType, kind) => {
1627
+ const type = mimeType.split(";", 1)[0]?.trim().toLowerCase() ?? "";
1628
+ const category = type.startsWith("image/") ? "image" : type.startsWith("video/") ? "video" : type === "text/vtt" ? "caption" : "document";
1629
+ return kind === undefined || category === kind;
1630
+ };
1631
+ var assetUploadAccept = (kind) => kind === "image" ? "image/*" : kind === "video" ? "video/*" : kind === "caption" ? ".vtt,text/vtt" : undefined;
1632
+ var hasInvalidAssetFiles = (files, kind) => files.some((staged) => {
1633
+ const file = Redacted2.value(staged);
1634
+ const mimeType = file.name.toLowerCase().endsWith(".vtt") ? "text/vtt" : file.type;
1635
+ return !matchesAssetKind(mimeType, kind);
1636
+ });
1637
+ var assetSelection = (value) => Schema10.is(Schema10.String)(value) ? value ? [value] : [] : value ?? [];
1638
+ var redactedFile = Schema10.Redacted(Schema10.File);
1639
+ var files = Schema10.Array(redactedFile);
1640
+ var result = {
1641
+ Progress: { id: Schema10.Int, progress: Schema10.Finite },
1642
+ Processing: { id: Schema10.Int },
1643
+ Completed: { id: Schema10.Int, assetId: Schema10.String },
1644
+ Failed: { id: Schema10.Int, retryPublication: Schema10.Boolean },
1645
+ Rejected: { id: Schema10.Int, error: Schema10.String }
1646
+ };
1647
+ var AssetUploadResult = UiSchema5.TaggedEnum(result).annotate({
1648
+ identifier: "AssetUploadResult"
1649
+ });
1650
+
1651
+ class RunAssetUpload extends Command.Service()("asset-input/RunAssetUpload", {
1652
+ args: {
1653
+ id: Schema10.Int,
1654
+ file: redactedFile,
1655
+ retryPublication: Schema10.Boolean
1656
+ },
1657
+ success: AssetUploadResult,
1658
+ stream: true,
1659
+ group: ["id"],
1660
+ mode: "switch"
1661
+ }) {
1662
+ }
1663
+ var assetUploadLayer = (transport) => {
1664
+ const staged = new WeakMap;
1665
+ return RunAssetUpload.toLayer(({ id, file, retryPublication }) => Stream.callback((queue) => Effect2.tryPromise(async (signal) => {
1666
+ const source = Redacted2.value(file);
1667
+ let transferred = retryPublication;
1668
+ try {
1669
+ let prepared = retryPublication ? staged.get(file) : undefined;
1670
+ if (!prepared) {
1671
+ transferred = false;
1672
+ const context = await transport.upload(source, {
1673
+ signal,
1674
+ onProgress: (progress) => {
1675
+ if (!signal.aborted && !transferred && Number.isFinite(progress))
1676
+ Queue.offerUnsafe(queue, AssetUploadResult.Progress({ id, progress }));
1677
+ }
1678
+ });
1679
+ if (signal.aborted)
1680
+ return;
1681
+ prepared = { context };
1682
+ staged.set(file, prepared);
1683
+ }
1684
+ transferred = true;
1685
+ Queue.offerUnsafe(queue, AssetUploadResult.Processing({ id }));
1686
+ const publication = await transport.publish(prepared.context, signal);
1687
+ if (signal.aborted)
1688
+ return;
1689
+ staged.delete(file);
1690
+ Queue.offerUnsafe(queue, publication.status === "published" ? AssetUploadResult.Completed({
1691
+ id,
1692
+ assetId: publication.assetId
1693
+ }) : AssetUploadResult.Rejected({ id, error: publication.message }));
1694
+ } catch {
1695
+ if (!signal.aborted)
1696
+ Queue.offerUnsafe(queue, AssetUploadResult.Failed({ id, retryPublication: transferred }));
1697
+ } finally {
1698
+ Queue.endUnsafe(queue);
1699
+ }
1700
+ }).pipe(Effect2.ignore)));
1701
+ };
1702
+ var libraryUpload = (run, locale, replaceId) => {
1703
+ const copy = AssetUploadTransportMessages[locale.startsWith("fr") ? "fr" : "en"];
1704
+ return {
1705
+ upload: (file, { signal, onProgress }) => run(AssetLibraryActions.use((transport) => transport.upload(file, onProgress, replaceId)), { signal }),
1706
+ publish: (upload, signal) => run(AssetLibraryActions.use((transport) => transport.publish(upload)).pipe(Effect2.map((result) => result.status === "published" ? result : { status: "rejected", message: copy[result.reason] })), { signal })
1707
+ };
1708
+ };
1709
+ var AssetInputEvents = UiSchema5.TaggedEnum({
1710
+ Changed: { ids: Schema10.Array(Schema10.String) },
1711
+ Published: { assetId: Schema10.String, file: redactedFile }
1712
+ }).annotate({ identifier: "AssetInputEvents" });
1713
+ var AssetInputMessage = UiSchema5.TaggedEnum({
1714
+ Open: {},
1715
+ Stage: { files },
1716
+ SetFiles: { files },
1717
+ Upload: {},
1718
+ Dismiss: {},
1719
+ Closed: {},
1720
+ RemoveJob: { id: Schema10.Int },
1721
+ Retry: { id: Schema10.Int },
1722
+ Changed: { ids: Schema10.Array(Schema10.String) },
1723
+ ...result
1724
+ }).annotate({ identifier: "AssetInputMessage" });
1725
+ var assetInputOptions = {
1726
+ name: "AssetInput",
1727
+ props: AssetInputPropsSchema,
1728
+ model: Schema10.Struct({
1729
+ open: Schema10.Boolean,
1730
+ files,
1731
+ jobs: Schema10.Array(AssetUploadJobSchema),
1732
+ nextId: Schema10.Int
1733
+ }).annotate({ identifier: "AssetInputModel" }),
1734
+ message: AssetInputMessage,
1735
+ events: AssetInputEvents,
1736
+ restore: false
1737
+ };
1738
+ var active = (job) => job.phase === "uploading" || job.phase === "processing";
1739
+ var canCloseAssetUpload = (jobs) => jobs.some(({ phase }) => phase === "done") && !jobs.some(active);
1740
+ var withJob = (model, id, change) => model.open ? {
1741
+ ...model,
1742
+ jobs: model.jobs.map((job) => job.id === id && active(job) ? change(job) : job)
1743
+ } : model;
1744
+ var issue = (job) => RunAssetUpload.make({
1745
+ id: job.id,
1746
+ file: job.file,
1747
+ retryPublication: job.retryPublication ?? false
1748
+ });
1749
+ var definition2 = Component5.define(assetInputOptions);
1750
+ var update3 = definition2.update({
1751
+ Open: ($) => $.props.uploader && !$.props.disabled && !$.model.open ? { ...$.model, open: true, files: [], jobs: [] } : $.model,
1752
+ Stage: ($, { files }) => $.props.uploader && !$.props.disabled && files.length ? {
1753
+ ...$.model,
1754
+ open: true,
1755
+ jobs: $.model.open ? $.model.jobs : [],
1756
+ files: $.props.multiple ? files : files.slice(0, 1)
1757
+ } : $.model,
1758
+ SetFiles: ($, { files }) => $.model.open ? { ...$.model, files: $.props.multiple ? files : files.slice(0, 1) } : $.model,
1759
+ Dismiss: ($) => $.set({ ...$.model, open: false }).run(Command.interrupt(RunAssetUpload)),
1760
+ Closed: ($) => $.model.open ? $.model : { ...$.model, files: [], jobs: [] },
1761
+ Upload: ($) => {
1762
+ if (!$.model.open || !$.props.uploader || $.props.disabled || $.model.jobs.length || !$.model.files.length || hasInvalidAssetFiles($.model.files, $.props.kind))
1763
+ return $.model;
1764
+ const jobs = $.model.files.map((file, offset) => ({
1765
+ id: $.model.nextId + offset,
1766
+ file: Redacted2.make(Redacted2.value(file)),
1767
+ phase: "uploading"
1768
+ }));
1769
+ return $.set({
1770
+ ...$.model,
1771
+ files: [],
1772
+ jobs,
1773
+ nextId: $.model.nextId + jobs.length
1774
+ }).run(...jobs.map(issue));
1775
+ },
1776
+ RemoveJob: ($, { id }) => $.model.open ? $.set({
1777
+ ...$.model,
1778
+ jobs: $.model.jobs.filter((job) => job.id !== id)
1779
+ }).run(Command.interrupt(RunAssetUpload, { id })) : $.model,
1780
+ Retry: ($, { id }) => {
1781
+ const job = $.model.jobs.find((job) => job.id === id && job.phase === "error");
1782
+ if (!$.model.open || !job || !$.props.uploader || $.props.disabled)
1783
+ return $.model;
1784
+ const next = {
1785
+ ...job,
1786
+ phase: job.retryPublication ? "processing" : "uploading",
1787
+ progress: undefined
1788
+ };
1789
+ return $.set({
1790
+ ...$.model,
1791
+ jobs: $.model.jobs.map((job) => job.id === id ? next : job)
1792
+ }).run(issue(next));
1793
+ },
1794
+ Changed: ($, { ids }) => $.props.disabled ? $.model : $.emit(AssetInputEvents.Changed({
1795
+ ids: $.props.multiple ? ids : ids.slice(0, 1)
1796
+ })),
1797
+ Progress: ($, { id, progress }) => withJob($.model, id, (job) => job.phase === "uploading" ? { ...job, progress } : job),
1798
+ Processing: ($, { id }) => withJob($.model, id, (job) => ({ ...job, phase: "processing" })),
1799
+ Failed: ($, { id, retryPublication }) => withJob($.model, id, (job) => ({
1800
+ ...job,
1801
+ phase: "error",
1802
+ retryPublication
1803
+ })),
1804
+ Rejected: ($, { id, error }) => withJob($.model, id, (job) => ({ ...job, phase: "rejected", error })),
1805
+ Completed: ($, { id, assetId }) => {
1806
+ if (!$.model.open)
1807
+ return $.model;
1808
+ const job = $.model.jobs.find((job) => job.id === id && active(job));
1809
+ return job ? $.set(withJob($.model, id, (job) => ({ ...job, phase: "done" }))).emit(AssetInputEvents.Published({ assetId, file: job.file })) : $.model;
1810
+ }
1811
+ });
1812
+ var assetInputBehaviours = {
1813
+ init: () => ({ open: false, files: [], jobs: [], nextId: 0 }),
1814
+ update: update3
1815
+ };
1816
+ var assetUploadState = (job, copy) => {
1817
+ switch (job.phase) {
1818
+ case "uploading":
1819
+ return { status: "uploading", progress: job.progress };
1820
+ case "processing":
1821
+ return { status: "processing" };
1822
+ case "done":
1823
+ return { status: "done" };
1824
+ case "rejected":
1825
+ return {
1826
+ status: "error",
1827
+ message: job.error ?? copy.publishError
1828
+ };
1829
+ case "error":
1830
+ return {
1831
+ status: "error",
1832
+ message: job.retryPublication ? copy.publishError : copy.uploadError
1833
+ };
1834
+ }
1835
+ };
1836
+
1837
+ // ../assets/src/components/asset-input/upload.tsx
1838
+ import { jsx as jsx4, jsxs as jsxs4, Fragment as Fragment3 } from "react/jsx-runtime";
1839
+ "use client";
1840
+ var model = Component6.define(assetInputOptions).make({
1841
+ ...assetInputBehaviours,
1842
+ view: () => View2.text("")
1843
+ });
1844
+ var bindTransport = (transport) => {
1845
+ let current = transport;
1846
+ const component = model.pipe(Component6.provide(assetUploadLayer({
1847
+ upload: (file, options) => {
1848
+ const { upload, publish } = current;
1849
+ return upload(file, options).then((context) => ({
1850
+ context,
1851
+ publish
1852
+ }));
1853
+ },
1854
+ publish: ({ context, publish }, signal) => publish(context, signal)
1855
+ })));
1856
+ return {
1857
+ component,
1858
+ update: (transport) => {
1859
+ current = transport;
1860
+ }
1861
+ };
1862
+ };
1863
+ var UploadSession = ({
1864
+ accept,
1865
+ kind,
1866
+ multiple,
1867
+ upload,
1868
+ publish,
1869
+ onPublished,
1870
+ processingLabel,
1871
+ messages,
1872
+ locale,
1873
+ title,
1874
+ actions,
1875
+ selectsAsset,
1876
+ showPicker,
1877
+ uploadTrigger,
1878
+ onReplacementClose
1879
+ }) => {
1880
+ const id = useId2();
1881
+ const [binding] = useState3(() => bindTransport({ upload, publish }));
1882
+ useLayoutEffect(() => {
1883
+ binding.update({ upload, publish });
1884
+ }, [binding, upload, publish]);
1885
+ const {
1886
+ model: { files, jobs, open },
1887
+ send
1888
+ } = useModel(binding.component, {
1889
+ label: title,
1890
+ multiple,
1891
+ ...kind === undefined ? {} : { kind },
1892
+ uploader: { accept, messages, processingLabel }
1893
+ }, {
1894
+ onEmit: (event) => {
1895
+ if (event._tag === "Published")
1896
+ onPublished?.(event.assetId, Redacted3.value(event.file));
1897
+ }
1898
+ });
1899
+ const isReplacement = onReplacementClose !== undefined;
1900
+ useEffect3(() => {
1901
+ if (isReplacement)
1902
+ send(AssetInputMessage.Open());
1903
+ }, [isReplacement, send]);
1904
+ const labels = assetUploadMessages(locale, messages);
1905
+ const stage = (files) => send(AssetInputMessage.Stage({ files: files.map((file) => Redacted3.make(file)) }));
1906
+ const setFiles = (files) => send(AssetInputMessage.SetFiles({ files: files.map((file) => Redacted3.make(file)) }));
1907
+ const staged = files.map(Redacted3.value);
1908
+ const invalid = hasInvalidAssetFiles(files, kind);
1909
+ return /* @__PURE__ */ jsxs4(Fragment3, {
1910
+ children: [
1911
+ showPicker && !uploadTrigger && /* @__PURE__ */ jsx4(FileInput, {
1912
+ id,
1913
+ name: "",
1914
+ title,
1915
+ accept,
1916
+ actions,
1917
+ showAcceptHint: false,
1918
+ multiple,
1919
+ onChange: (file) => stage([file]),
1920
+ onFilesChange: stage,
1921
+ onClear: () => setFiles([]),
1922
+ locale
1923
+ }),
1924
+ /* @__PURE__ */ jsxs4(Dialog, {
1925
+ open,
1926
+ onOpenChange: (open) => {
1927
+ send(open ? AssetInputMessage.Open() : AssetInputMessage.Dismiss());
1928
+ },
1929
+ onOpenChangeComplete: (open) => {
1930
+ if (!open) {
1931
+ send(AssetInputMessage.Closed());
1932
+ onReplacementClose?.();
1933
+ }
1934
+ },
1935
+ children: [
1936
+ showPicker && uploadTrigger === "button" && /* @__PURE__ */ jsxs4("div", {
1937
+ className: "flex flex-wrap items-center gap-2",
1938
+ children: [
1939
+ /* @__PURE__ */ jsx4(DialogTrigger, {
1940
+ render: /* @__PURE__ */ jsx4(Button4, {
1941
+ type: "button"
1942
+ }),
1943
+ children: labels.upload
1944
+ }),
1945
+ actions
1946
+ ]
1947
+ }),
1948
+ /* @__PURE__ */ jsxs4(DialogContent, {
1949
+ showCloseButton: false,
1950
+ className: "max-h-[85dvh] min-w-0 grid-cols-1 overflow-x-hidden overflow-y-auto [overflow-wrap:anywhere]",
1951
+ children: [
1952
+ /* @__PURE__ */ jsxs4(DialogHeader, {
1953
+ children: [
1954
+ /* @__PURE__ */ jsx4(DialogTitle, {
1955
+ children: isReplacement ? title : selectsAsset ? labels.dialogTitle : labels.libraryDialogTitle
1956
+ }),
1957
+ /* @__PURE__ */ jsx4(DialogDescription, {
1958
+ children: selectsAsset ? labels.dialogDescription : labels.libraryDialogDescription
1959
+ })
1960
+ ]
1961
+ }),
1962
+ jobs.length ? /* @__PURE__ */ jsx4("div", {
1963
+ className: "grid min-w-0 grid-cols-1 gap-2",
1964
+ children: jobs.map((job) => {
1965
+ const file = Redacted3.value(job.file);
1966
+ const remove = () => send(AssetInputMessage.RemoveJob({ id: job.id }));
1967
+ return /* @__PURE__ */ jsx4(UploadAttachment, {
1968
+ className: "w-full min-w-0 flex-nowrap focus-within:ring-0",
1969
+ name: file.name,
1970
+ fileIcon: /* @__PURE__ */ jsx4(FileThumbnail, {
1971
+ file
1972
+ }),
1973
+ state: assetUploadState(job, labels),
1974
+ locale,
1975
+ messages: processingLabel ? { [locale]: { processing: processingLabel } } : undefined,
1976
+ onCancel: remove,
1977
+ onRetry: job.phase === "error" ? () => send(AssetInputMessage.Retry({ id: job.id })) : undefined,
1978
+ onRemove: job.phase === "done" ? undefined : remove
1979
+ }, job.id);
1980
+ })
1981
+ }) : /* @__PURE__ */ jsx4(FileInput, {
1982
+ id: `${id}-staged`,
1983
+ showImageThumbnails: true,
1984
+ name: "",
1985
+ title,
1986
+ multiple,
1987
+ file: multiple ? undefined : staged[0],
1988
+ files: multiple ? staged : undefined,
1989
+ accept,
1990
+ showAcceptHint: false,
1991
+ canClear: true,
1992
+ onChange: (file) => setFiles([file]),
1993
+ onFilesChange: setFiles,
1994
+ onClear: () => setFiles([]),
1995
+ locale
1996
+ }),
1997
+ invalid && /* @__PURE__ */ jsx4("p", {
1998
+ role: "alert",
1999
+ className: "text-destructive text-sm",
2000
+ children: labels.kindError
2001
+ }),
2002
+ /* @__PURE__ */ jsxs4(DialogFooter, {
2003
+ children: [
2004
+ /* @__PURE__ */ jsx4(DialogClose, {
2005
+ render: /* @__PURE__ */ jsx4(Button4, {
2006
+ type: "button",
2007
+ variant: "outline"
2008
+ }),
2009
+ children: canCloseAssetUpload(jobs) ? labels.close : labels.cancel
2010
+ }),
2011
+ !jobs.length && staged.length > 0 && /* @__PURE__ */ jsx4(Button4, {
2012
+ type: "button",
2013
+ disabled: invalid,
2014
+ onClick: () => send(AssetInputMessage.Upload()),
2015
+ children: labels.upload
2016
+ })
2017
+ ]
2018
+ })
2019
+ ]
2020
+ })
2021
+ ]
2022
+ })
2023
+ ]
2024
+ });
2025
+ };
2026
+
2027
+ // ../assets/src/services/assets/url.ts
2028
+ import { Schema as Schema12 } from "effect";
2029
+
2030
+ // ../assets/src/services/assets/schema.ts
2031
+ import { Schema as Schema11 } from "effect";
2032
+ var AssetHttpUrl = Schema11.String.check(Schema11.makeFilter((value) => {
2033
+ if (!/^https?:\/\/[^/]/i.test(value) || /[\s\\]/u.test(value))
2034
+ return false;
2035
+ try {
2036
+ const url = new URL(value);
2037
+ return !url.username && !url.password;
2038
+ } catch {
2039
+ return false;
2040
+ }
2041
+ })).annotate({ identifier: "AssetHttpUrl" });
2042
+ var AssetRelativeUrl = Schema11.String.check(Schema11.isPattern(/^\/(?!\/)[^\s\\]*$/u)).annotate({ identifier: "AssetRelativeUrl" });
2043
+
2044
+ // ../assets/src/services/assets/url.ts
2045
+ var isAssetHttpUrl = Schema12.is(AssetHttpUrl);
2046
+ var isAssetRelativeUrl = Schema12.is(AssetRelativeUrl);
2047
+ var assetUrl = ({ url }) => isAssetHttpUrl(url) || isAssetRelativeUrl(url) ? url : undefined;
2048
+ var assetImage = (asset) => {
2049
+ const url = asset.mimeType.trim().toLowerCase().startsWith("image/") ? assetUrl(asset) : undefined;
2050
+ if (!url)
2051
+ return {};
2052
+ const version = asset.updatedAt?.getTime();
2053
+ const imageSrc = version !== undefined && Number.isFinite(version) && /^\/api\/assets\/[^/?#]+\/file$/.test(url) ? `${url}?v=${version}` : url;
2054
+ return { imageSrc };
2055
+ };
2056
+
2057
+ // ../assets/src/services/assets/use-library.ts
2058
+ import { useMemo as useMemo2 } from "react";
2059
+ import { Effect as Effect3 } from "effect";
2060
+ import { Component as Component7 } from "effect/ui";
2061
+ import { useModel as useModel2 } from "@krak-stack/registry/effect-ui-adapter/react";
2062
+ var disabled = AssetLibraryModel.pipe(Component7.provide(AssetList.toLayer(() => Effect3.fail("unavailable"))));
2063
+ var noAccess = { scopeKey: "disabled", permissions: [] };
2064
+ var useAssetLibrary = (runtime, access) => {
2065
+ const scopeKey = access?.permissions.includes("list") ? access.scopeKey : undefined;
2066
+ const showFiles = access?.permissions.includes("read") ?? false;
2067
+ const model = useMemo2(() => runtime && scopeKey ? AssetLibraryModel.pipe(Component7.provide(runtime.layer)) : disabled, [runtime, scopeKey, showFiles]);
2068
+ const { model: snapshot } = useModel2(model, {
2069
+ access: runtime && scopeKey && access ? access : noAccess
2070
+ });
2071
+ return runtime && scopeKey ? snapshot : emptyAssetLibrary;
2072
+ };
2073
+
2074
+ // ../assets/src/components/asset-input/react.tsx
2075
+ import { jsx as jsx5, jsxs as jsxs5 } from "react/jsx-runtime";
2076
+ "use client";
2077
+ var AssetInput = (props) => /* @__PURE__ */ jsx5(AssetInputView, {
2078
+ ...props
2079
+ }, props.access?.scopeKey);
2080
+ var AssetInputView = (props) => {
2081
+ const {
2082
+ assets: suppliedAssets,
2083
+ kind,
2084
+ label,
2085
+ onChange,
2086
+ uploader: suppliedUploader,
2087
+ uploadAction,
2088
+ disabled,
2089
+ locale: localeOverride,
2090
+ messages,
2091
+ multiple,
2092
+ uploadTrigger
2093
+ } = props;
2094
+ const { runtime, access, replaceId } = props;
2095
+ const libraryResult = useAssetLibrary(runtime, suppliedAssets === undefined && onChange ? access : undefined);
2096
+ const assets = suppliedAssets ?? (runtime && onChange && access?.permissions.includes("list") ? libraryResult.data?.items ?? [] : undefined);
2097
+ const id = useId3();
2098
+ const [published, setPublished] = useState4([]);
2099
+ const pendingIds = useRef3([]);
2100
+ useLayoutEffect2(() => {
2101
+ pendingIds.current = props.multiple ? props.value ?? [] : [];
2102
+ }, [props.multiple, props.value]);
2103
+ const changeMultiple = (ids) => {
2104
+ if (props.multiple && props.onChange) {
2105
+ pendingIds.current = ids;
2106
+ props.onChange(ids);
2107
+ }
2108
+ };
2109
+ const locale = useKrakstackLocale4(localeOverride);
2110
+ const connectedUploader = runtime && access?.permissions.includes(replaceId ? "update" : "create") ? libraryUpload(runtime.runPromise, locale, replaceId) : undefined;
2111
+ const labels = assetInputMessages(locale, messages);
2112
+ const library = new Map(assets?.map((asset) => [asset.id, asset]));
2113
+ const assetDetails = (id) => library.get(id) ?? published.find((asset) => asset.id === id);
2114
+ const matchingAssets = (assets ?? []).filter((asset) => matchesAssetKind(asset.mimeType, kind));
2115
+ const items = matchingAssets.map((asset) => ({
2116
+ value: asset.id,
2117
+ label: asset.name,
2118
+ description: asset.mimeType,
2119
+ ...assetImage(asset),
2120
+ icon: /* @__PURE__ */ jsx5(FileTypeIcon, {
2121
+ mimeType: asset.mimeType
2122
+ })
2123
+ }));
2124
+ const selectedIds = assetSelection(props.value);
2125
+ const option = (value) => ({
2126
+ value,
2127
+ label: assetDetails(value)?.name ?? labels.selected
2128
+ });
2129
+ const placeholder = multiple ? labels.multiplePlaceholder : labels.placeholder;
2130
+ const pickerProps = {
2131
+ ariaLabel: placeholder,
2132
+ contentClassName: "w-80",
2133
+ disabled,
2134
+ emptyLabel: labels.empty,
2135
+ items,
2136
+ locale,
2137
+ placeholder,
2138
+ trigger: /* @__PURE__ */ jsxs5(Button5, {
2139
+ type: "button",
2140
+ variant: "outline",
2141
+ disabled,
2142
+ "aria-label": placeholder,
2143
+ children: [
2144
+ /* @__PURE__ */ jsx5(FolderOpen, {
2145
+ "data-icon": "inline-start",
2146
+ "aria-hidden": "true"
2147
+ }),
2148
+ placeholder
2149
+ ]
2150
+ })
2151
+ };
2152
+ const picker = !assets ? null : props.multiple ? /* @__PURE__ */ jsx5(VirtualizedCombobox, {
2153
+ ...pickerProps,
2154
+ multiple: true,
2155
+ value: selectedIds.map(option),
2156
+ onValueChange: (items) => changeMultiple(items.map((item) => item.value))
2157
+ }) : /* @__PURE__ */ jsx5(VirtualizedCombobox, {
2158
+ ...pickerProps,
2159
+ value: props.value ? option(props.value) : null,
2160
+ onValueChange: (item) => props.onChange?.(item?.value ?? "")
2161
+ });
2162
+ const showPicker = multiple || selectedIds.length === 0;
2163
+ const attachments = selectedIds.map((assetId) => {
2164
+ const selected = assetDetails(assetId);
2165
+ const imageSrc = selected && assetImage(selected).imageSrc;
2166
+ return /* @__PURE__ */ jsxs5(Attachment3, {
2167
+ className: multiple ? "focus-within:ring-0" : "w-full focus-within:ring-0",
2168
+ children: [
2169
+ /* @__PURE__ */ jsx5(AttachmentMedia3, {
2170
+ variant: imageSrc ? "image" : "icon",
2171
+ children: imageSrc ? /* @__PURE__ */ jsx5("img", {
2172
+ src: imageSrc,
2173
+ alt: "",
2174
+ className: "size-full object-cover"
2175
+ }) : /* @__PURE__ */ jsx5(FileTypeIcon, {
2176
+ mimeType: selected?.mimeType ?? ""
2177
+ })
2178
+ }),
2179
+ /* @__PURE__ */ jsxs5(AttachmentContent3, {
2180
+ children: [
2181
+ /* @__PURE__ */ jsx5(AttachmentTitle3, {
2182
+ children: selected?.name ?? labels.selected
2183
+ }),
2184
+ selected?.mimeType && /* @__PURE__ */ jsx5(AttachmentDescription3, {
2185
+ children: selected.mimeType
2186
+ })
2187
+ ]
2188
+ }),
2189
+ /* @__PURE__ */ jsx5(AttachmentActions3, {
2190
+ children: /* @__PURE__ */ jsx5(AttachmentAction2, {
2191
+ type: "button",
2192
+ "aria-label": selected ? `${labels.remove}: ${selected.name}` : labels.remove,
2193
+ disabled,
2194
+ onClick: () => props.multiple ? changeMultiple(pendingIds.current.filter((id) => id !== assetId)) : props.onChange?.(""),
2195
+ children: /* @__PURE__ */ jsx5(X4, {
2196
+ "aria-hidden": "true"
2197
+ })
2198
+ })
2199
+ })
2200
+ ]
2201
+ }, assetId);
2202
+ });
2203
+ return /* @__PURE__ */ jsxs5(Field, {
2204
+ className: "min-w-0",
2205
+ "aria-labelledby": `${id}-label`,
2206
+ children: [
2207
+ /* @__PURE__ */ jsx5(FieldTitle, {
2208
+ id: `${id}-label`,
2209
+ className: uploadTrigger === "button" && !onChange && !disabled && (suppliedUploader || connectedUploader) ? "sr-only" : undefined,
2210
+ children: label
2211
+ }),
2212
+ multiple && attachments.length > 0 ? /* @__PURE__ */ jsx5(AttachmentGroup2, {
2213
+ className: "px-1 focus-within:mask-none",
2214
+ children: attachments
2215
+ }) : attachments,
2216
+ suppliedUploader && !disabled ? /* @__PURE__ */ jsx5(UploadSession, {
2217
+ ...suppliedUploader,
2218
+ actions: picker,
2219
+ selectsAsset: assets !== undefined,
2220
+ showPicker,
2221
+ uploadTrigger,
2222
+ locale,
2223
+ title: label,
2224
+ multiple,
2225
+ onPublished: (assetId, uploaded) => {
2226
+ if (onChange) {
2227
+ const asset = {
2228
+ id: assetId,
2229
+ name: uploaded.name,
2230
+ mimeType: uploaded.type
2231
+ };
2232
+ setPublished((current) => [
2233
+ ...current.filter(({ id }) => id !== assetId),
2234
+ asset
2235
+ ]);
2236
+ if (props.multiple) {
2237
+ if (!pendingIds.current.includes(assetId))
2238
+ changeMultiple([...pendingIds.current, assetId]);
2239
+ } else
2240
+ props.onChange?.(assetId);
2241
+ }
2242
+ suppliedUploader.onPublished?.(assetId, uploaded);
2243
+ }
2244
+ }) : connectedUploader && !disabled ? /* @__PURE__ */ jsx5(UploadSession, {
2245
+ ...connectedUploader,
2246
+ accept: assetUploadAccept(kind),
2247
+ kind,
2248
+ actions: picker,
2249
+ selectsAsset: onChange !== undefined,
2250
+ showPicker,
2251
+ uploadTrigger,
2252
+ locale,
2253
+ title: label,
2254
+ multiple,
2255
+ onPublished: (id) => {
2256
+ if (props.multiple)
2257
+ changeMultiple([...new Set([...pendingIds.current, id])]);
2258
+ else
2259
+ props.onChange?.(id);
2260
+ props.onPublished?.(id);
2261
+ }
2262
+ }) : showPicker && picker,
2263
+ showPicker && !suppliedUploader && !connectedUploader && !disabled && uploadAction
2264
+ ]
2265
+ });
2266
+ };
2267
+ export {
2268
+ AssetInput
2269
+ };