@ecsplico/editor 3.5.0 → 3.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/CHANGELOG.md +13 -2
  2. package/dist/code/CodeSurface.vue.d.ts +2 -2
  3. package/dist/document/DocumentSurface.vue.d.ts +2 -2
  4. package/dist/features/ai/protocol/generate.d.ts +1 -1
  5. package/dist/features/composites/kinds.d.ts +6 -0
  6. package/dist/features/composites/kinds.js.map +1 -1
  7. package/dist/features/composites/merge.d.ts +4 -3
  8. package/dist/features/composites/merge.js +29 -3
  9. package/dist/features/composites/merge.js.map +1 -1
  10. package/dist/features/image-studio/node-core.d.ts +46 -0
  11. package/dist/features/image-studio/node-core.js +79 -0
  12. package/dist/features/image-studio/node-core.js.map +1 -0
  13. package/dist/features/image-studio/node-store.d.ts +3 -11
  14. package/dist/features/image-studio/node-store.js +15 -44
  15. package/dist/features/image-studio/node-store.js.map +1 -1
  16. package/dist/features/image-studio/react/ImageStudioChat.js +101 -0
  17. package/dist/features/image-studio/react/ImageStudioChat.js.map +1 -0
  18. package/dist/features/image-studio/react/ImageStudioDialog.d.ts +19 -0
  19. package/dist/features/image-studio/react/ImageStudioDialog.js +357 -0
  20. package/dist/features/image-studio/react/ImageStudioDialog.js.map +1 -0
  21. package/dist/features/image-studio/react/ImageStudioTile.js +51 -0
  22. package/dist/features/image-studio/react/ImageStudioTile.js.map +1 -0
  23. package/dist/features/image-studio/react/ImageStudioView.js +126 -0
  24. package/dist/features/image-studio/react/ImageStudioView.js.map +1 -0
  25. package/dist/features/image-studio/react/store.d.ts +37 -0
  26. package/dist/features/image-studio/react/store.js +46 -0
  27. package/dist/features/image-studio/react/store.js.map +1 -0
  28. package/dist/features/image-studio/react.d.ts +18 -0
  29. package/dist/features/image-studio/react.js +21 -0
  30. package/dist/features/image-studio/react.js.map +1 -0
  31. package/dist/markdown/MarkdownSurface.vue.d.ts +6 -6
  32. package/dist/server/handlers/ai.d.ts +2 -2
  33. package/dist/vue/AdvancedEditor.vue.d.ts +5 -5
  34. package/dist/vue/SimpleEditor.vue.d.ts +4 -4
  35. package/dist/vue/components/EditorSurface.vue.d.ts +4 -4
  36. package/package.json +6 -1
@@ -0,0 +1,101 @@
1
+ import { useEditorI18n } from "../../../react/use-editor-i18n.js";
2
+ import { cn } from "../../../react/ui/utils.js";
3
+ import { Icon } from "../../../react/Icon.js";
4
+ import { Button } from "../../../react/ui/button.js";
5
+ import { Textarea } from "../../../react/ui/textarea.js";
6
+ import { useEffect, useId, useRef, useState } from "react";
7
+ import { jsx, jsxs } from "react/jsx-runtime";
8
+ //#region src/features/image-studio/react/ImageStudioChat.tsx
9
+ /**
10
+ * The chat of the Bild-Studio: the turn log (instruction, the picture it produced if the block still has it, the
11
+ * problem when it failed) and the instruction input. `Enter` sends, `Shift+Enter` breaks the line; while `running` the
12
+ * input and the button are disabled. An empty instruction is sent when `emptyAllowed` (the block has a description to generate from).
13
+ */
14
+ function ImageStudioChat({ turns, images, running, emptyAllowed, onSend }) {
15
+ const { t } = useEditorI18n();
16
+ const headingId = useId();
17
+ const [instruction, setInstruction] = useState("");
18
+ const log = useRef(null);
19
+ const thumbnail = (turn) => turn.imageId === null ? void 0 : images.find((image) => image.id === turn.imageId);
20
+ const instructionOf = (turn) => turn.instruction || t("imageStudio.dialog.chat.fromDescription");
21
+ function send() {
22
+ if (running || !emptyAllowed && instruction.trim() === "") return;
23
+ const text = instruction.trim();
24
+ setInstruction("");
25
+ onSend(text);
26
+ }
27
+ function onKeyDown(event) {
28
+ if (event.key !== "Enter" || event.shiftKey || event.nativeEvent.isComposing) return;
29
+ event.preventDefault();
30
+ send();
31
+ }
32
+ useEffect(() => {
33
+ if (log.current) log.current.scrollTop = log.current.scrollHeight;
34
+ }, [turns.length]);
35
+ return /* @__PURE__ */ jsxs("section", {
36
+ className: "flex min-h-0 flex-1 flex-col gap-2",
37
+ "aria-labelledby": headingId,
38
+ children: [
39
+ /* @__PURE__ */ jsx("h3", {
40
+ id: headingId,
41
+ className: "text-sm font-medium text-foreground",
42
+ children: t("imageStudio.dialog.chat.heading")
43
+ }),
44
+ /* @__PURE__ */ jsxs("ol", {
45
+ ref: log,
46
+ className: "flex min-h-24 flex-1 flex-col gap-2 overflow-y-auto",
47
+ "data-image-studio-log": true,
48
+ children: [!turns.length && /* @__PURE__ */ jsx("li", {
49
+ className: "text-sm text-muted-foreground",
50
+ children: t("imageStudio.dialog.chat.empty")
51
+ }), turns.map((turn) => {
52
+ const picture = thumbnail(turn);
53
+ return /* @__PURE__ */ jsxs("li", {
54
+ className: "flex items-start gap-2 rounded-md border border-border p-2",
55
+ "data-problem": turn.problem !== void 0,
56
+ "data-image-studio-turn": true,
57
+ children: [picture && /* @__PURE__ */ jsx("img", {
58
+ src: picture.url,
59
+ alt: t("imageStudio.dialog.chat.turnImage", { instruction: instructionOf(turn) }),
60
+ className: "size-12 shrink-0 rounded object-cover"
61
+ }), /* @__PURE__ */ jsxs("div", {
62
+ className: "min-w-0 flex-1",
63
+ children: [/* @__PURE__ */ jsx("p", {
64
+ className: cn("whitespace-pre-wrap break-words text-sm text-foreground", !turn.instruction && "italic text-muted-foreground"),
65
+ children: instructionOf(turn)
66
+ }), turn.problem && /* @__PURE__ */ jsx("p", {
67
+ className: "mt-1 whitespace-pre-wrap break-words text-sm text-destructive",
68
+ role: "alert",
69
+ children: turn.problem
70
+ })]
71
+ })]
72
+ }, turn.id);
73
+ })]
74
+ }),
75
+ /* @__PURE__ */ jsxs("div", {
76
+ className: "flex items-end gap-2",
77
+ children: [/* @__PURE__ */ jsx(Textarea, {
78
+ value: instruction,
79
+ className: "min-w-0 flex-1",
80
+ rows: 2,
81
+ placeholder: t("imageStudio.dialog.chat.placeholder"),
82
+ "aria-label": t("imageStudio.dialog.chat.label"),
83
+ disabled: running,
84
+ onChange: (event) => setInstruction(event.target.value),
85
+ onKeyDown
86
+ }), /* @__PURE__ */ jsxs(Button, {
87
+ disabled: running || !emptyAllowed && instruction.trim() === "",
88
+ onClick: send,
89
+ children: [/* @__PURE__ */ jsx(Icon, {
90
+ name: running ? "i-lucide-loader-circle" : "i-lucide-sparkles",
91
+ className: cn(running && "animate-spin")
92
+ }), running ? t("imageStudio.dialog.chat.running") : t("imageStudio.dialog.chat.send")]
93
+ })]
94
+ })
95
+ ]
96
+ });
97
+ }
98
+ //#endregion
99
+ export { ImageStudioChat };
100
+
101
+ //# sourceMappingURL=ImageStudioChat.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ImageStudioChat.js","names":[],"sources":["../../../../src/features/image-studio/react/ImageStudioChat.tsx"],"sourcesContent":["import { type KeyboardEvent, useEffect, useId, useRef, useState } from 'react'\nimport { Icon } from '../../../react/Icon'\nimport { Button } from '../../../react/ui/button'\nimport { Textarea } from '../../../react/ui/textarea'\nimport { cn } from '../../../react/ui/utils'\nimport { useEditorI18n } from '../../../react/use-editor-i18n'\nimport type { ImageStudioImage, ImageStudioTurn } from '../state'\n\n/**\n * The chat of the Bild-Studio: the turn log (instruction, the picture it produced if the block still has it, the\n * problem when it failed) and the instruction input. `Enter` sends, `Shift+Enter` breaks the line; while `running` the\n * input and the button are disabled. An empty instruction is sent when `emptyAllowed` (the block has a description to generate from).\n */\nexport function ImageStudioChat({ turns, images, running, emptyAllowed, onSend }: {\n turns: readonly ImageStudioTurn[]\n /** The block's images, to show the thumbnail of a turn. */\n images: readonly ImageStudioImage[]\n running: boolean\n emptyAllowed: boolean\n onSend: (instruction: string) => void\n}) {\n const { t } = useEditorI18n()\n const headingId = useId()\n const [instruction, setInstruction] = useState('')\n const log = useRef<HTMLOListElement>(null)\n\n const thumbnail = (turn: ImageStudioTurn): ImageStudioImage | undefined =>\n turn.imageId === null ? undefined : images.find(image => image.id === turn.imageId)\n const instructionOf = (turn: ImageStudioTurn): string => turn.instruction || t('imageStudio.dialog.chat.fromDescription')\n\n function send() {\n if (running || (!emptyAllowed && instruction.trim() === '')) return\n const text = instruction.trim()\n setInstruction('')\n onSend(text)\n }\n\n function onKeyDown(event: KeyboardEvent<HTMLTextAreaElement>) {\n if (event.key !== 'Enter' || event.shiftKey || event.nativeEvent.isComposing) return\n event.preventDefault()\n send()\n }\n\n // The newest turn stays in view.\n useEffect(() => {\n if (log.current) log.current.scrollTop = log.current.scrollHeight\n }, [turns.length])\n\n return (\n <section className=\"flex min-h-0 flex-1 flex-col gap-2\" aria-labelledby={headingId}>\n <h3 id={headingId} className=\"text-sm font-medium text-foreground\">\n {t('imageStudio.dialog.chat.heading')}\n </h3>\n <ol ref={log} className=\"flex min-h-24 flex-1 flex-col gap-2 overflow-y-auto\" data-image-studio-log>\n {!turns.length && <li className=\"text-sm text-muted-foreground\">{t('imageStudio.dialog.chat.empty')}</li>}\n {turns.map((turn) => {\n const picture = thumbnail(turn)\n return (\n <li\n key={turn.id}\n className=\"flex items-start gap-2 rounded-md border border-border p-2\"\n data-problem={turn.problem !== undefined}\n data-image-studio-turn\n >\n {picture && (\n <img\n src={picture.url}\n alt={t('imageStudio.dialog.chat.turnImage', { instruction: instructionOf(turn) })}\n className=\"size-12 shrink-0 rounded object-cover\"\n />\n )}\n <div className=\"min-w-0 flex-1\">\n <p className={cn('whitespace-pre-wrap break-words text-sm text-foreground', !turn.instruction && 'italic text-muted-foreground')}>\n {instructionOf(turn)}\n </p>\n {turn.problem && (\n <p className=\"mt-1 whitespace-pre-wrap break-words text-sm text-destructive\" role=\"alert\">\n {turn.problem}\n </p>\n )}\n </div>\n </li>\n )\n })}\n </ol>\n <div className=\"flex items-end gap-2\">\n <Textarea\n value={instruction}\n className=\"min-w-0 flex-1\"\n rows={2}\n placeholder={t('imageStudio.dialog.chat.placeholder')}\n aria-label={t('imageStudio.dialog.chat.label')}\n disabled={running}\n onChange={event => setInstruction(event.target.value)}\n onKeyDown={onKeyDown}\n />\n <Button disabled={running || (!emptyAllowed && instruction.trim() === '')} onClick={send}>\n <Icon name={running ? 'i-lucide-loader-circle' : 'i-lucide-sparkles'} className={cn(running && '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V,gBAAc,KAAK,YAAY,KAAA;MAC/B,0BAAA;MAJF,UAAA,CAMG,WACC,oBAAC,OAAD;OACE,KAAK,QAAQ;OACb,KAAK,EAAE,qCAAqC,EAAE,aAAa,cAAc,IAAI,EAAE,CAAC;OAChF,WAAU;MACX,CAAA,GAEH,qBAAC,OAAD;OAAK,WAAU;OAAf,UAAA,CACE,oBAAC,KAAD;QAAG,WAAW,GAAG,2DAA2D,CAAC,KAAK,eAAe,8BAA8B;QAC5H,UAAA,cAAc,IAAI;OAClB,CAAA,GACF,KAAK,WACJ,oBAAC,KAAD;QAAG,WAAU;QAAgE,MAAK;QAC/E,UAAA,KAAK;OACL,CAAA,CAEF;MACH,CAAA,CAAA;KAtBG,GAAA,KAAK,EAsBR;IAER,CAAC,CACC;;GACJ,qBAAC,OAAD;IAAK,WAAU;IAAf,UAAA,CACE,oBAAC,UAAD;KACE,OAAO;KACP,WAAU;KACV,MAAM;KACN,aAAa,EAAE,qCAAqC;KACpD,cAAY,EAAE,+BAA+B;KAC7C,UAAU;KACV,WAAU,UAAS,eAAe,MAAM,OAAO,KAAK;KACzC;IACZ,CAAA,GACD,qBAAC,QAAD;KAAQ,UAAU,WAAY,CAAC,gBAAgB,YAAY,KAAK,MAAM;KAAK,SAAS;KAApF,UAAA,CACE,oBAAC,MAAD;MAAM,MAAM,UAAU,2BAA2B;MAAqB,WAAW,GAAG,WAAW,cAAc;KAAI,CAAA,GAChH,UAAU,EAAE,iCAAiC,IAAI,EAAE,8BAA8B,CAC5E;IACL,CAAA,CAAA;;EACE;;AAEb"}
@@ -0,0 +1,19 @@
1
+ import { ImageStudioReactStore } from "./store.js";
2
+ //#region src/features/image-studio/react/ImageStudioDialog.d.ts
3
+ /**
4
+ * The Bild-Studio: description and Prompt-Bausteine on the left, references and previous generations in the middle,
5
+ * the block's image and the chat on the right. The dialog applies the reducers of `../state` to `store.state` and
6
+ * hands every result to `store.update`; the store only generates, uploads and persists (see `ImageStudioReactStore`).
7
+ *
8
+ * The description is committed 500 ms after the last keystroke and at once on blur, on „Erzeugen“ and on close, so the
9
+ * host never builds a prompt from a stale text. Closing (or unmounting) aborts a running generation; an aborted
10
+ * generation adds no turn, a failed one adds a turn with the problem.
11
+ */
12
+ export declare function ImageStudioDialog({ open, onOpenChange, store, title }: {
13
+ open: boolean;
14
+ onOpenChange: (open: boolean) => void;
15
+ store: ImageStudioReactStore;
16
+ title?: string;
17
+ }): import("react").JSX.Element;
18
+ //#endregion
19
+ //# sourceMappingURL=ImageStudioDialog.d.ts.map
@@ -0,0 +1,357 @@
1
+ import { fetchErrorMessage } from "../../../core/fetch-error.js";
2
+ import { useEditorI18n } from "../../../react/use-editor-i18n.js";
3
+ import { cn } from "../../../react/ui/utils.js";
4
+ import { Icon } from "../../../react/Icon.js";
5
+ import { Button } from "../../../react/ui/button.js";
6
+ import { Dialog, DialogContent, DialogHeader, DialogTitle } from "../../../react/ui/dialog.js";
7
+ import { Textarea } from "../../../react/ui/textarea.js";
8
+ import { Alert, AlertTitle } from "../../../react/ui/alert.js";
9
+ import { Switch } from "../../../react/ui/switch.js";
10
+ import { addGeneration, addReference, removeImage, select, selectedImage, setDescription, toggleImage, togglePromptBlock } from "../state.js";
11
+ import { ImageStudioChat } from "./ImageStudioChat.js";
12
+ import { ImageStudioTile } from "./ImageStudioTile.js";
13
+ import { useEffect, useId, useRef, useState } from "react";
14
+ import { jsx, jsxs } from "react/jsx-runtime";
15
+ //#region src/features/image-studio/react/ImageStudioDialog.tsx
16
+ const COMMIT_DELAY_MS = 500;
17
+ /**
18
+ * The Bild-Studio: description and Prompt-Bausteine on the left, references and previous generations in the middle,
19
+ * the block's image and the chat on the right. The dialog applies the reducers of `../state` to `store.state` and
20
+ * hands every result to `store.update`; the store only generates, uploads and persists (see `ImageStudioReactStore`).
21
+ *
22
+ * The description is committed 500 ms after the last keystroke and at once on blur, on „Erzeugen“ and on close, so the
23
+ * host never builds a prompt from a stale text. Closing (or unmounting) aborts a running generation; an aborted
24
+ * generation adds no turn, a failed one adds a turn with the problem.
25
+ */
26
+ function ImageStudioDialog({ open, onOpenChange, store, title }) {
27
+ const { t } = useEditorI18n();
28
+ const uid = useId();
29
+ const { state, promptBlocks, problem } = store;
30
+ const images = [...state.generations, ...state.references];
31
+ const picture = selectedImage(state);
32
+ const storeRef = useRef(store);
33
+ storeRef.current = store;
34
+ const latest = useRef(state);
35
+ const seen = useRef(state);
36
+ if (seen.current !== state) {
37
+ seen.current = state;
38
+ latest.current = state;
39
+ }
40
+ const apply = (next) => {
41
+ latest.current = next;
42
+ storeRef.current.update(next);
43
+ };
44
+ const [draft, setDraft] = useState(state.description);
45
+ const draftRef = useRef(draft);
46
+ /** The description as last committed or received: the host's echo of our own commit must not overwrite a newer draft. */
47
+ const known = useRef(state.description);
48
+ const commitTimer = useRef(void 0);
49
+ function commitDescription() {
50
+ clearTimeout(commitTimer.current);
51
+ commitTimer.current = void 0;
52
+ if (draftRef.current === latest.current.description) return;
53
+ known.current = draftRef.current;
54
+ apply(setDescription(latest.current, draftRef.current));
55
+ }
56
+ function onDescriptionChange(event) {
57
+ const text = event.target.value;
58
+ draftRef.current = text;
59
+ setDraft(text);
60
+ if (text === latest.current.description) return;
61
+ clearTimeout(commitTimer.current);
62
+ commitTimer.current = setTimeout(commitDescription, COMMIT_DELAY_MS);
63
+ }
64
+ useEffect(() => {
65
+ if (state.description === known.current) return;
66
+ known.current = state.description;
67
+ if (commitTimer.current === void 0) {
68
+ draftRef.current = state.description;
69
+ setDraft(state.description);
70
+ }
71
+ }, [state.description]);
72
+ const fileInput = useRef(null);
73
+ const [uploading, setUploading] = useState(0);
74
+ const [uploadProblem, setUploadProblem] = useState();
75
+ const [dragging, setDragging] = useState(false);
76
+ async function upload(files) {
77
+ const pictures = files.filter((file) => file.type.startsWith("image/"));
78
+ if (!pictures.length) return;
79
+ setUploadProblem(void 0);
80
+ setUploading((count) => count + pictures.length);
81
+ await Promise.all(pictures.map(async (file) => {
82
+ try {
83
+ const image = await storeRef.current.upload(file);
84
+ apply(addReference(latest.current, image));
85
+ } catch (error) {
86
+ setUploadProblem(t("imageStudio.dialog.references.failed", { message: fetchErrorMessage(error) }));
87
+ } finally {
88
+ setUploading((count) => count - 1);
89
+ }
90
+ }));
91
+ }
92
+ function onFilesChosen(event) {
93
+ const input = event.target;
94
+ const files = [...input.files ?? []];
95
+ input.value = "";
96
+ upload(files);
97
+ }
98
+ function onDrop(event) {
99
+ event.preventDefault();
100
+ setDragging(false);
101
+ upload([...event.dataTransfer.files]);
102
+ }
103
+ const [running, setRunning] = useState(false);
104
+ const controller = useRef(void 0);
105
+ function abortGeneration() {
106
+ controller.current?.abort();
107
+ controller.current = void 0;
108
+ setRunning(false);
109
+ }
110
+ async function generate(instruction) {
111
+ if (controller.current) return;
112
+ commitDescription();
113
+ const own = new AbortController();
114
+ controller.current = own;
115
+ setRunning(true);
116
+ const turn = {
117
+ id: crypto.randomUUID(),
118
+ instruction,
119
+ imageId: null,
120
+ createdAt: (/* @__PURE__ */ new Date()).toISOString()
121
+ };
122
+ try {
123
+ const image = await storeRef.current.generate(instruction, own.signal);
124
+ if (own.signal.aborted) return;
125
+ apply(addGeneration(latest.current, image, turn));
126
+ } catch (error) {
127
+ if (own.signal.aborted) return;
128
+ apply({
129
+ ...latest.current,
130
+ turns: [...latest.current.turns, {
131
+ ...turn,
132
+ problem: fetchErrorMessage(error)
133
+ }]
134
+ });
135
+ } finally {
136
+ if (controller.current === own) {
137
+ controller.current = void 0;
138
+ setRunning(false);
139
+ }
140
+ }
141
+ }
142
+ function close() {
143
+ commitDescription();
144
+ abortGeneration();
145
+ onOpenChange(false);
146
+ }
147
+ useEffect(() => {
148
+ if (open) return;
149
+ commitDescription();
150
+ abortGeneration();
151
+ }, [open]);
152
+ useEffect(() => () => {
153
+ commitDescription();
154
+ abortGeneration();
155
+ }, []);
156
+ const heading = "text-sm font-medium text-foreground";
157
+ return /* @__PURE__ */ jsx(Dialog, {
158
+ open,
159
+ onOpenChange: (value) => {
160
+ if (!value) close();
161
+ },
162
+ children: /* @__PURE__ */ jsxs(DialogContent, {
163
+ className: "max-h-[calc(100vh-2rem)] overflow-y-auto sm:max-w-[min(72rem,calc(100vw-2rem))]",
164
+ "aria-describedby": void 0,
165
+ children: [/* @__PURE__ */ jsx(DialogHeader, { children: /* @__PURE__ */ jsx(DialogTitle, { children: title ?? t("imageStudio.dialog.title") }) }), /* @__PURE__ */ jsxs("div", {
166
+ className: "flex flex-col gap-3",
167
+ "data-image-studio-dialog": true,
168
+ children: [problem && /* @__PURE__ */ jsx(Alert, {
169
+ variant: "destructive",
170
+ children: /* @__PURE__ */ jsx(AlertTitle, { children: problem })
171
+ }), /* @__PURE__ */ jsxs("div", {
172
+ className: "grid gap-4 lg:h-[68vh] lg:grid-cols-[17rem_minmax(0,1fr)_minmax(0,22rem)]",
173
+ children: [
174
+ /* @__PURE__ */ jsxs("section", {
175
+ className: "flex min-h-0 flex-col gap-3 lg:overflow-y-auto",
176
+ "aria-labelledby": `${uid}-description`,
177
+ children: [
178
+ /* @__PURE__ */ jsx("h3", {
179
+ id: `${uid}-description`,
180
+ className: heading,
181
+ children: t("imageStudio.dialog.description.heading")
182
+ }),
183
+ /* @__PURE__ */ jsx(Textarea, {
184
+ value: draft,
185
+ rows: 6,
186
+ placeholder: t("imageStudio.dialog.description.placeholder"),
187
+ "aria-label": t("imageStudio.dialog.description.heading"),
188
+ onChange: onDescriptionChange,
189
+ onBlur: commitDescription
190
+ }),
191
+ /* @__PURE__ */ jsx("h3", {
192
+ id: `${uid}-blocks`,
193
+ className: cn(heading, "mt-2"),
194
+ children: t("imageStudio.dialog.blocks.heading")
195
+ }),
196
+ promptBlocks.length ? /* @__PURE__ */ jsx("ul", {
197
+ className: "flex flex-col gap-3",
198
+ "aria-labelledby": `${uid}-blocks`,
199
+ children: promptBlocks.map((block) => /* @__PURE__ */ jsxs("li", {
200
+ className: "flex items-start gap-2",
201
+ children: [/* @__PURE__ */ jsx(Switch, {
202
+ id: `${uid}-block-${block.id}`,
203
+ checked: state.promptBlockIds.includes(block.id),
204
+ "aria-labelledby": `${uid}-block-${block.id}-label`,
205
+ "aria-describedby": `${uid}-block-${block.id}-text`,
206
+ onCheckedChange: () => apply(togglePromptBlock(latest.current, block.id))
207
+ }), /* @__PURE__ */ jsxs("div", {
208
+ className: "flex min-w-0 flex-col gap-0.5",
209
+ children: [/* @__PURE__ */ jsx("label", {
210
+ id: `${uid}-block-${block.id}-label`,
211
+ htmlFor: `${uid}-block-${block.id}`,
212
+ className: "text-sm font-medium text-foreground",
213
+ children: block.label
214
+ }), /* @__PURE__ */ jsx("p", {
215
+ id: `${uid}-block-${block.id}-text`,
216
+ className: "whitespace-pre-wrap break-words text-xs text-muted-foreground",
217
+ children: block.text
218
+ })]
219
+ })]
220
+ }, block.id))
221
+ }) : /* @__PURE__ */ jsx("p", {
222
+ className: "text-sm text-muted-foreground",
223
+ children: t("imageStudio.dialog.blocks.empty")
224
+ })
225
+ ]
226
+ }),
227
+ /* @__PURE__ */ jsxs("div", {
228
+ className: "flex min-h-0 flex-col gap-4 lg:overflow-y-auto",
229
+ children: [/* @__PURE__ */ jsxs("section", {
230
+ className: "flex flex-col gap-2 rounded-md border border-dashed border-transparent p-1 data-[dragging=true]:border-primary",
231
+ "data-dragging": dragging,
232
+ "aria-labelledby": `${uid}-references`,
233
+ "data-image-studio-drop": true,
234
+ onDragEnter: (event) => {
235
+ event.preventDefault();
236
+ setDragging(true);
237
+ },
238
+ onDragOver: (event) => {
239
+ event.preventDefault();
240
+ setDragging(true);
241
+ },
242
+ onDragLeave: () => setDragging(false),
243
+ onDrop,
244
+ children: [
245
+ /* @__PURE__ */ jsxs("div", {
246
+ className: "flex items-center justify-between gap-2",
247
+ children: [
248
+ /* @__PURE__ */ jsx("h3", {
249
+ id: `${uid}-references`,
250
+ className: heading,
251
+ children: t("imageStudio.dialog.references.heading")
252
+ }),
253
+ /* @__PURE__ */ jsxs(Button, {
254
+ size: "xs",
255
+ variant: "outline",
256
+ disabled: uploading > 0,
257
+ onClick: () => fileInput.current?.click(),
258
+ children: [/* @__PURE__ */ jsx(Icon, {
259
+ name: uploading > 0 ? "i-lucide-loader-circle" : "i-lucide-upload",
260
+ className: cn(uploading > 0 && "animate-spin")
261
+ }), t("imageStudio.dialog.references.upload")]
262
+ }),
263
+ /* @__PURE__ */ jsx("input", {
264
+ ref: fileInput,
265
+ type: "file",
266
+ accept: "image/*",
267
+ multiple: true,
268
+ hidden: true,
269
+ "data-image-studio-file": true,
270
+ onChange: onFilesChosen
271
+ })
272
+ ]
273
+ }),
274
+ uploading > 0 && /* @__PURE__ */ jsx("p", {
275
+ className: "text-xs text-muted-foreground",
276
+ role: "status",
277
+ children: t("imageStudio.dialog.references.uploading")
278
+ }),
279
+ uploadProblem && /* @__PURE__ */ jsx(Alert, {
280
+ variant: "destructive",
281
+ children: /* @__PURE__ */ jsx(AlertTitle, { children: uploadProblem })
282
+ }),
283
+ state.references.length ? /* @__PURE__ */ jsx("ul", {
284
+ className: "grid grid-cols-2 gap-2 sm:grid-cols-3",
285
+ children: state.references.map((image) => /* @__PURE__ */ jsx(ImageStudioTile, {
286
+ image,
287
+ selected: state.selected === image.id,
288
+ onToggle: () => apply(toggleImage(latest.current, image.id)),
289
+ onSelect: () => apply(select(latest.current, image.id)),
290
+ onRemove: () => apply(removeImage(latest.current, image.id))
291
+ }, image.id))
292
+ }) : /* @__PURE__ */ jsx("p", {
293
+ className: "text-sm text-muted-foreground",
294
+ children: t("imageStudio.dialog.references.drop")
295
+ })
296
+ ]
297
+ }), /* @__PURE__ */ jsxs("section", {
298
+ className: "flex flex-col gap-2 p-1",
299
+ "aria-labelledby": `${uid}-generations`,
300
+ children: [/* @__PURE__ */ jsx("h3", {
301
+ id: `${uid}-generations`,
302
+ className: heading,
303
+ children: t("imageStudio.dialog.generations.heading")
304
+ }), state.generations.length ? /* @__PURE__ */ jsx("ul", {
305
+ className: "grid grid-cols-2 gap-2 sm:grid-cols-3",
306
+ children: state.generations.map((image) => /* @__PURE__ */ jsx(ImageStudioTile, {
307
+ image,
308
+ selected: state.selected === image.id,
309
+ onToggle: () => apply(toggleImage(latest.current, image.id)),
310
+ onSelect: () => apply(select(latest.current, image.id)),
311
+ onRemove: () => apply(removeImage(latest.current, image.id))
312
+ }, image.id))
313
+ }) : /* @__PURE__ */ jsx("p", {
314
+ className: "text-sm text-muted-foreground",
315
+ children: t("imageStudio.dialog.generations.empty")
316
+ })]
317
+ })]
318
+ }),
319
+ /* @__PURE__ */ jsxs("div", {
320
+ className: "flex min-h-0 flex-col gap-3",
321
+ children: [/* @__PURE__ */ jsxs("section", {
322
+ className: "flex flex-col gap-2",
323
+ "aria-labelledby": `${uid}-preview`,
324
+ children: [/* @__PURE__ */ jsx("h3", {
325
+ id: `${uid}-preview`,
326
+ className: heading,
327
+ children: t("imageStudio.dialog.preview.heading")
328
+ }), /* @__PURE__ */ jsx("div", {
329
+ className: "flex aspect-square items-center justify-center overflow-hidden rounded-md border border-border bg-muted",
330
+ children: picture ? /* @__PURE__ */ jsx("img", {
331
+ src: picture.url,
332
+ alt: picture.title || t("imageStudio.dialog.tile.untitled"),
333
+ className: "size-full object-contain",
334
+ "data-image-studio-preview": true
335
+ }) : /* @__PURE__ */ jsx("p", {
336
+ className: "text-sm text-muted-foreground",
337
+ children: t("imageStudio.dialog.preview.empty")
338
+ })
339
+ })]
340
+ }), /* @__PURE__ */ jsx(ImageStudioChat, {
341
+ turns: state.turns,
342
+ images,
343
+ running,
344
+ emptyAllowed: draft.trim() !== "",
345
+ onSend: (instruction) => void generate(instruction)
346
+ })]
347
+ })
348
+ ]
349
+ })]
350
+ })]
351
+ })
352
+ });
353
+ }
354
+ //#endregion
355
+ export { ImageStudioDialog };
356
+
357
+ //# sourceMappingURL=ImageStudioDialog.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ImageStudioDialog.js","names":[],"sources":["../../../../src/features/image-studio/react/ImageStudioDialog.tsx"],"sourcesContent":["import { type ChangeEvent, type DragEvent, useEffect, useId, useRef, useState } from 'react'\nimport { fetchErrorMessage } from '../../../core'\nimport { Icon } from '../../../react/Icon'\nimport { Alert, AlertTitle } from '../../../react/ui/alert'\nimport { Button } from '../../../react/ui/button'\nimport { Dialog, DialogContent, DialogHeader, DialogTitle } from '../../../react/ui/dialog'\nimport { Switch } from '../../../react/ui/switch'\nimport { Textarea } from '../../../react/ui/textarea'\nimport { cn } from '../../../react/ui/utils'\nimport { useEditorI18n } from '../../../react/use-editor-i18n'\nimport {\n addGeneration,\n addReference,\n type ImageStudioState,\n type ImageStudioTurn,\n removeImage,\n select,\n selectedImage,\n setDescription,\n toggleImage,\n togglePromptBlock,\n} from '../state'\nimport { ImageStudioChat } from './ImageStudioChat'\nimport { ImageStudioTile } from './ImageStudioTile'\nimport type { ImageStudioReactStore } from './store'\n\nconst COMMIT_DELAY_MS = 500\n\n/**\n * The Bild-Studio: description and Prompt-Bausteine on the left, references and previous generations in the middle,\n * the block's image and the chat on the right. The dialog applies the reducers of `../state` to `store.state` and\n * hands every result to `store.update`; the store only generates, uploads and persists (see `ImageStudioReactStore`).\n *\n * The description is committed 500 ms after the last keystroke and at once on blur, on „Erzeugen“ and on close, so the\n * host never builds a prompt from a stale text. Closing (or unmounting) aborts a running generation; an aborted\n * generation adds no turn, a failed one adds a turn with the problem.\n */\nexport function ImageStudioDialog({ open, onOpenChange, store, title }: {\n open: boolean\n onOpenChange: (open: boolean) => void\n store: ImageStudioReactStore\n title?: string\n}) {\n const { t } = useEditorI18n()\n const uid = useId()\n const { state, promptBlocks, problem } = store\n const images = [...state.generations, ...state.references]\n const picture = selectedImage(state)\n\n // The latest store and the latest state: async continuations (an upload, a generation) must build on the newest\n // state, also when a render has not caught up with the `update` just made. A new `store.state` replaces it.\n const storeRef = useRef(store)\n storeRef.current = store\n const latest = useRef(state)\n const seen = useRef(state)\n if (seen.current !== state) {\n seen.current = state\n latest.current = state\n }\n const apply = (next: ImageStudioState) => {\n latest.current = next\n storeRef.current.update(next)\n }\n\n // --- Description --------------------------------------------------------------------------------------------------\n\n const [draft, setDraft] = useState(state.description)\n const draftRef = useRef(draft)\n /** The description as last committed or received: the host's echo of our own commit must not overwrite a newer draft. */\n const known = useRef(state.description)\n const commitTimer = useRef<ReturnType<typeof setTimeout>>(undefined)\n\n function commitDescription() {\n clearTimeout(commitTimer.current)\n commitTimer.current = undefined\n if (draftRef.current === latest.current.description) return\n known.current = draftRef.current\n apply(setDescription(latest.current, draftRef.current))\n }\n\n function onDescriptionChange(event: ChangeEvent<HTMLTextAreaElement>) {\n const text = event.target.value\n draftRef.current = text\n setDraft(text)\n if (text === latest.current.description) return\n clearTimeout(commitTimer.current)\n commitTimer.current = setTimeout(commitDescription, COMMIT_DELAY_MS)\n }\n\n // A change of the host (undo, another tab) shows unless the user has typed something that is not committed yet.\n useEffect(() => {\n if (state.description === known.current) return\n known.current = state.description\n if (commitTimer.current === undefined) {\n draftRef.current = state.description\n setDraft(state.description)\n }\n }, [state.description])\n\n // --- References: upload and drop ----------------------------------------------------------------------------------\n\n const fileInput = useRef<HTMLInputElement>(null)\n const [uploading, setUploading] = useState(0)\n const [uploadProblem, setUploadProblem] = useState<string>()\n const [dragging, setDragging] = useState(false)\n\n async function upload(files: readonly File[]) {\n const pictures = files.filter(file => file.type.startsWith('image/'))\n if (!pictures.length) return\n setUploadProblem(undefined)\n setUploading(count => count + pictures.length)\n await Promise.all(pictures.map(async (file) => {\n try {\n const image = await storeRef.current.upload(file)\n apply(addReference(latest.current, image))\n }\n catch (error) {\n setUploadProblem(t('imageStudio.dialog.references.failed', { message: fetchErrorMessage(error) }))\n }\n finally {\n setUploading(count => count - 1)\n }\n }))\n }\n\n function onFilesChosen(event: ChangeEvent<HTMLInputElement>) {\n const input = event.target\n const files = [...(input.files ?? [])]\n input.value = '' // the same file can be chosen again\n void upload(files)\n }\n\n function onDrop(event: DragEvent) {\n event.preventDefault()\n setDragging(false)\n void upload([...event.dataTransfer.files])\n }\n\n // --- Generation ---------------------------------------------------------------------------------------------------\n\n const [running, setRunning] = useState(false)\n const controller = useRef<AbortController>(undefined)\n\n function abortGeneration() {\n controller.current?.abort()\n controller.current = undefined\n setRunning(false)\n }\n\n async function generate(instruction: string) {\n if (controller.current) return\n commitDescription()\n const own = new AbortController()\n controller.current = own\n setRunning(true)\n const turn: ImageStudioTurn = { id: crypto.randomUUID(), instruction, imageId: null, createdAt: new Date().toISOString() }\n try {\n const image = await storeRef.current.generate(instruction, own.signal)\n if (own.signal.aborted) return\n apply(addGeneration(latest.current, image, turn))\n }\n catch (error) {\n if (own.signal.aborted) return\n apply({ ...latest.current, turns: [...latest.current.turns, { ...turn, problem: fetchErrorMessage(error) }] })\n }\n finally {\n if (controller.current === own) {\n controller.current = undefined\n setRunning(false)\n }\n }\n }\n\n // --- Closing ------------------------------------------------------------------------------------------------------\n\n function close() {\n commitDescription()\n abortGeneration()\n onOpenChange(false)\n }\n\n // The host closes the dialog itself, or the component goes: commit what was typed, stop what runs.\n useEffect(() => {\n if (open) return\n commitDescription()\n abortGeneration()\n }, [open])\n useEffect(() => () => {\n commitDescription()\n abortGeneration()\n }, [])\n\n const heading = 'text-sm font-medium text-foreground'\n\n return (\n <Dialog open={open} onOpenChange={(value) => { if (!value) close() }}>\n <DialogContent className=\"max-h-[calc(100vh-2rem)] overflow-y-auto sm:max-w-[min(72rem,calc(100vw-2rem))]\" aria-describedby={undefined}>\n <DialogHeader>\n <DialogTitle>{title ?? t('imageStudio.dialog.title')}</DialogTitle>\n </DialogHeader>\n <div className=\"flex flex-col gap-3\" data-image-studio-dialog>\n {problem && (\n <Alert variant=\"destructive\">\n <AlertTitle>{problem}</AlertTitle>\n </Alert>\n )}\n <div className=\"grid gap-4 lg:h-[68vh] lg:grid-cols-[17rem_minmax(0,1fr)_minmax(0,22rem)]\">\n {/* Left: what the picture shows. */}\n <section className=\"flex min-h-0 flex-col gap-3 lg:overflow-y-auto\" aria-labelledby={`${uid}-description`}>\n <h3 id={`${uid}-description`} className={heading}>{t('imageStudio.dialog.description.heading')}</h3>\n <Textarea\n value={draft}\n rows={6}\n placeholder={t('imageStudio.dialog.description.placeholder')}\n aria-label={t('imageStudio.dialog.description.heading')}\n onChange={onDescriptionChange}\n onBlur={commitDescription}\n />\n <h3 id={`${uid}-blocks`} className={cn(heading, 'mt-2')}>{t('imageStudio.dialog.blocks.heading')}</h3>\n {promptBlocks.length\n ? (\n <ul className=\"flex flex-col gap-3\" aria-labelledby={`${uid}-blocks`}>\n {promptBlocks.map(block => (\n <li key={block.id} className=\"flex items-start gap-2\">\n <Switch\n id={`${uid}-block-${block.id}`}\n checked={state.promptBlockIds.includes(block.id)}\n aria-labelledby={`${uid}-block-${block.id}-label`}\n aria-describedby={`${uid}-block-${block.id}-text`}\n onCheckedChange={() => apply(togglePromptBlock(latest.current, block.id))}\n />\n <div className=\"flex min-w-0 flex-col gap-0.5\">\n <label id={`${uid}-block-${block.id}-label`} htmlFor={`${uid}-block-${block.id}`} className=\"text-sm font-medium text-foreground\">\n {block.label}\n </label>\n <p id={`${uid}-block-${block.id}-text`} className=\"whitespace-pre-wrap break-words text-xs text-muted-foreground\">\n {block.text}\n </p>\n </div>\n </li>\n ))}\n </ul>\n )\n : <p className=\"text-sm text-muted-foreground\">{t('imageStudio.dialog.blocks.empty')}</p>}\n </section>\n\n {/* Middle: references and previous generations. */}\n <div className=\"flex min-h-0 flex-col gap-4 lg:overflow-y-auto\">\n <section\n className=\"flex flex-col gap-2 rounded-md border border-dashed border-transparent p-1 data-[dragging=true]:border-primary\"\n data-dragging={dragging}\n aria-labelledby={`${uid}-references`}\n data-image-studio-drop\n onDragEnter={(event) => { event.preventDefault(); setDragging(true) }}\n onDragOver={(event) => { event.preventDefault(); setDragging(true) }}\n onDragLeave={() => setDragging(false)}\n onDrop={onDrop}\n >\n <div className=\"flex items-center justify-between gap-2\">\n <h3 id={`${uid}-references`} className={heading}>{t('imageStudio.dialog.references.heading')}</h3>\n <Button size=\"xs\" variant=\"outline\" disabled={uploading > 0} onClick={() => fileInput.current?.click()}>\n <Icon name={uploading > 0 ? 'i-lucide-loader-circle' : 'i-lucide-upload'} className={cn(uploading > 0 && 'animate-spin')} />\n {t('imageStudio.dialog.references.upload')}\n </Button>\n <input ref={fileInput} type=\"file\" accept=\"image/*\" multiple hidden data-image-studio-file onChange={onFilesChosen} />\n </div>\n {uploading > 0 && <p className=\"text-xs text-muted-foreground\" role=\"status\">{t('imageStudio.dialog.references.uploading')}</p>}\n {uploadProblem && (\n <Alert variant=\"destructive\">\n <AlertTitle>{uploadProblem}</AlertTitle>\n </Alert>\n )}\n {state.references.length\n ? (\n <ul className=\"grid grid-cols-2 gap-2 sm:grid-cols-3\">\n {state.references.map(image => (\n <ImageStudioTile\n key={image.id}\n image={image}\n selected={state.selected === image.id}\n onToggle={() => apply(toggleImage(latest.current, image.id))}\n onSelect={() => apply(select(latest.current, image.id))}\n onRemove={() => apply(removeImage(latest.current, image.id))}\n />\n ))}\n </ul>\n )\n : <p className=\"text-sm text-muted-foreground\">{t('imageStudio.dialog.references.drop')}</p>}\n </section>\n\n <section className=\"flex flex-col gap-2 p-1\" aria-labelledby={`${uid}-generations`}>\n <h3 id={`${uid}-generations`} className={heading}>{t('imageStudio.dialog.generations.heading')}</h3>\n {state.generations.length\n ? (\n <ul className=\"grid grid-cols-2 gap-2 sm:grid-cols-3\">\n {state.generations.map(image => (\n <ImageStudioTile\n key={image.id}\n image={image}\n selected={state.selected === image.id}\n onToggle={() => apply(toggleImage(latest.current, image.id))}\n onSelect={() => apply(select(latest.current, image.id))}\n onRemove={() => apply(removeImage(latest.current, image.id))}\n />\n ))}\n </ul>\n )\n : <p className=\"text-sm text-muted-foreground\">{t('imageStudio.dialog.generations.empty')}</p>}\n </section>\n </div>\n\n {/* Right: the block's image and the chat. */}\n <div className=\"flex min-h-0 flex-col gap-3\">\n <section className=\"flex flex-col gap-2\" aria-labelledby={`${uid}-preview`}>\n <h3 id={`${uid}-preview`} className={heading}>{t('imageStudio.dialog.preview.heading')}</h3>\n <div className=\"flex aspect-square items-center justify-center overflow-hidden rounded-md border border-border bg-muted\">\n {picture\n ? (\n <img\n src={picture.url}\n alt={picture.title || t('imageStudio.dialog.tile.untitled')}\n className=\"size-full object-contain\"\n data-image-studio-preview\n />\n )\n : <p className=\"text-sm text-muted-foreground\">{t('imageStudio.dialog.preview.empty')}</p>}\n </div>\n </section>\n <ImageStudioChat\n turns={state.turns}\n images={images}\n running={running}\n emptyAllowed={draft.trim() !== ''}\n onSend={instruction => void generate(instruction)}\n />\n </div>\n </div>\n </div>\n </DialogContent>\n </Dialog>\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;AA0BA,MAAM,kBAAkB;;;;;;;;;;AAWxB,SAAgB,kBAAkB,EAAE,MAAM,cAAc,OAAO,SAK5D;CACD,MAAM,EAAE,MAAM,cAAc;CAC5B,MAAM,MAAM,MAAM;CAClB,MAAM,EAAE,OAAO,cAAc,YAAY;CACzC,MAAM,SAAS,CAAC,GAAG,MAAM,aAAa,GAAG,MAAM,UAAU;CACzD,MAAM,UAAU,cAAc,KAAK;CAInC,MAAM,WAAW,OAAO,KAAK;CAC7B,SAAS,UAAU;CACnB,MAAM,SAAS,OAAO,KAAK;CAC3B,MAAM,OAAO,OAAO,KAAK;CACzB,IAAI,KAAK,YAAY,OAAO;EAC1B,KAAK,UAAU;EACf,OAAO,UAAU;CACnB;CACA,MAAM,SAAS,SAA2B;EACxC,OAAO,UAAU;EACjB,SAAS,QAAQ,OAAO,IAAI;CAC9B;CAIA,MAAM,CAAC,OAAO,YAAY,SAAS,MAAM,WAAW;CACpD,MAAM,WAAW,OAAO,KAAK;;CAE7B,MAAM,QAAQ,OAAO,MAAM,WAAW;CACtC,MAAM,cAAc,OAAsC,KAAA,CAAS;CAEnE,SAAS,oBAAoB;EAC3B,aAAa,YAAY,OAAO;EAChC,YAAY,UAAU,KAAA;EACtB,IAAI,SAAS,YAAY,OAAO,QAAQ,aAAa;EACrD,MAAM,UAAU,SAAS;EACzB,MAAM,eAAe,OAAO,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;;MAGL,qBAAC,OAAD;OAAK,WAAU;OAAf,UAAA,CACE,qBAAC,WAAD;QAAS,WAAU;QAAsB,mBAAiB,GAAG,IAAI;QAAjE,UAAA,CACE,oBAAC,MAAD;SAAI,IAAI,GAAG,IAAI;SAAW,WAAW;SAAU,UAAA,EAAE,oCAAoC;QAAM,CAAA,GAC3F,oBAAC,OAAD;SAAK,WAAU;SACZ,UAAA,UAEK,oBAAC,OAAD;UACE,KAAK,QAAQ;UACb,KAAK,QAAQ,SAAS,EAAE,kCAAkC;UAC1D,WAAU;UACV,6BAAA;SACD,CAAA,IAEH,oBAAC,KAAD;UAAG,WAAU;UAAiC,UAAA,EAAE,kCAAkC;SAAK,CAAA;QACxF,CAAA,CACE;OACT,CAAA,GAAA,oBAAC,iBAAD;QACE,OAAO,MAAM;QACL;QACC;QACT,cAAc,MAAM,KAAK,MAAM;QAC/B,SAAQ,gBAAe,KAAK,SAAS,WAAW;OACjD,CAAA,CACE;;KACF;IACF,CAAA,CAAA;GACQ,CAAA,CAAA;;CACT,CAAA;AAEZ"}
@@ -0,0 +1,51 @@
1
+ import { useEditorI18n } from "../../../react/use-editor-i18n.js";
2
+ import { Icon } from "../../../react/Icon.js";
3
+ import { Button } from "../../../react/ui/button.js";
4
+ import { jsx, jsxs } from "react/jsx-runtime";
5
+ //#region src/features/image-studio/react/ImageStudioTile.tsx
6
+ /**
7
+ * One reference or previous generation of the Bild-Studio. A click on the picture flips `active` (goes into the next
8
+ * generation, ring via `data-active`), „Als Bild verwenden“ makes it the block's image, „Entfernen“ drops it from the block.
9
+ */
10
+ function ImageStudioTile({ image, selected, onToggle, onSelect, onRemove }) {
11
+ const { t } = useEditorI18n();
12
+ const title = image.title || t("imageStudio.dialog.tile.untitled");
13
+ return /* @__PURE__ */ jsxs("li", {
14
+ className: "flex flex-col gap-1.5 rounded-md border border-border p-1.5 data-[active=true]:border-primary data-[active=true]:ring-2 data-[active=true]:ring-primary",
15
+ "data-active": image.active,
16
+ "data-selected": selected,
17
+ "data-image-studio-tile": true,
18
+ children: [/* @__PURE__ */ jsx("button", {
19
+ type: "button",
20
+ className: "block overflow-hidden rounded bg-muted focus-visible:outline-2 focus-visible:outline-primary",
21
+ "aria-pressed": image.active,
22
+ "aria-label": t("imageStudio.dialog.tile.toggle", { title }),
23
+ onClick: onToggle,
24
+ children: /* @__PURE__ */ jsx("img", {
25
+ src: image.url,
26
+ alt: title,
27
+ className: "aspect-square w-full object-cover",
28
+ draggable: false
29
+ })
30
+ }), /* @__PURE__ */ jsxs("div", {
31
+ className: "flex items-center justify-between gap-1",
32
+ children: [/* @__PURE__ */ jsxs(Button, {
33
+ size: "xs",
34
+ variant: selected ? "default" : "outline",
35
+ "aria-pressed": selected,
36
+ onClick: onSelect,
37
+ children: [selected && /* @__PURE__ */ jsx(Icon, { name: "i-lucide-check" }), t("imageStudio.dialog.tile.use")]
38
+ }), /* @__PURE__ */ jsx(Button, {
39
+ size: "icon-xs",
40
+ variant: "ghost",
41
+ "aria-label": t("imageStudio.dialog.tile.remove"),
42
+ onClick: onRemove,
43
+ children: /* @__PURE__ */ jsx(Icon, { name: "i-lucide-trash-2" })
44
+ })]
45
+ })]
46
+ });
47
+ }
48
+ //#endregion
49
+ export { ImageStudioTile };
50
+
51
+ //# sourceMappingURL=ImageStudioTile.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ImageStudioTile.js","names":[],"sources":["../../../../src/features/image-studio/react/ImageStudioTile.tsx"],"sourcesContent":["import { Icon } from '../../../react/Icon'\nimport { Button } from '../../../react/ui/button'\nimport { useEditorI18n } from '../../../react/use-editor-i18n'\nimport type { ImageStudioImage } from '../state'\n\n/**\n * One reference or previous generation of the Bild-Studio. A click on the picture flips `active` (goes into the next\n * generation, ring via `data-active`), „Als Bild verwenden“ makes it the block's image, „Entfernen“ drops it from the block.\n */\nexport function ImageStudioTile({ image, selected, onToggle, onSelect, onRemove }: {\n image: ImageStudioImage\n selected: boolean\n onToggle: () => void\n onSelect: () => void\n onRemove: () => void\n}) {\n const { t } = useEditorI18n()\n const title = image.title || t('imageStudio.dialog.tile.untitled')\n return (\n <li\n className=\"flex flex-col gap-1.5 rounded-md border border-border p-1.5 data-[active=true]:border-primary data-[active=true]:ring-2 data-[active=true]:ring-primary\"\n data-active={image.active}\n data-selected={selected}\n data-image-studio-tile\n >\n <button\n type=\"button\"\n className=\"block overflow-hidden rounded bg-muted focus-visible:outline-2 focus-visible:outline-primary\"\n aria-pressed={image.active}\n aria-label={t('imageStudio.dialog.tile.toggle', { title })}\n onClick={onToggle}\n >\n <img src={image.url} alt={title} className=\"aspect-square w-full object-cover\" draggable={false} />\n </button>\n <div className=\"flex items-center justify-between gap-1\">\n <Button size=\"xs\" variant={selected ? 'default' : 'outline'} aria-pressed={selected} onClick={onSelect}>\n {selected && <Icon name=\"i-lucide-check\" />}\n {t('imageStudio.dialog.tile.use')}\n </Button>\n <Button size=\"icon-xs\" variant=\"ghost\" aria-label={t('imageStudio.dialog.tile.remove')} onClick={onRemove}>\n <Icon name=\"i-lucide-trash-2\" />\n </Button>\n </div>\n </li>\n )\n}\n"],"mappings":";;;;;;;;;AASA,SAAgB,gBAAgB,EAAE,OAAO,UAAU,UAAU,UAAU,YAMpE;CACD,MAAM,EAAE,MAAM,cAAc;CAC5B,MAAM,QAAQ,MAAM,SAAS,EAAE,kCAAkC;CACjE,OACE,qBAAC,MAAD;EACE,WAAU;EACV,eAAa,MAAM;EACnB,iBAAe;EACf,0BAAA;EAJF,UAAA,CAME,oBAAC,UAAD;GACE,MAAK;GACL,WAAU;GACV,gBAAc,MAAM;GACpB,cAAY,EAAE,kCAAkC,EAAE,MAAM,CAAC;GACzD,SAAS;GAET,UAAA,oBAAC,OAAD;IAAK,KAAK,MAAM;IAAK,KAAK;IAAO,WAAU;IAAoC,WAAW;GAAQ,CAAA;EAC5F,CAAA,GACR,qBAAC,OAAD;GAAK,WAAU;GAAf,UAAA,CACE,qBAAC,QAAD;IAAQ,MAAK;IAAK,SAAS,WAAW,YAAY;IAAW,gBAAc;IAAU,SAAS;IAA9F,UAAA,CACG,YAAY,oBAAC,MAAD,EAAM,MAAK,iBAAkB,CAAA,GACzC,EAAE,6BAA6B,CAC1B;GACR,CAAA,GAAA,oBAAC,QAAD;IAAQ,MAAK;IAAU,SAAQ;IAAQ,cAAY,EAAE,gCAAgC;IAAG,SAAS;IAC/F,UAAA,oBAAC,MAAD,EAAM,MAAK,mBAAoB,CAAA;GACzB,CAAA,CACL;EACH,CAAA,CAAA;;AAER"}