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