@krak-stack/registry 0.5.0 → 0.7.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.
@@ -0,0 +1,334 @@
1
+ // ../../src/components/ui/editable-text.tsx
2
+ import { Pencil } from "lucide-react";
3
+ import { useEffect as useEffect2, useId, useRef as useRef2, useState as useState2 } from "react";
4
+
5
+ // ../../src/components/ui/async-action-button.tsx
6
+ import { Check, LoaderCircle, RotateCcw } from "lucide-react";
7
+ import { useEffect, useRef, useState } from "react";
8
+
9
+ // ../../src/components/ui/button.tsx
10
+ import { Button as ButtonPrimitive } from "@base-ui/react/button";
11
+ import { cva } from "class-variance-authority";
12
+
13
+ // ../../src/lib/utils.ts
14
+ import { cn } from "cn";
15
+
16
+ // ../../src/components/ui/button.tsx
17
+ import { jsx } from "react/jsx-runtime";
18
+ var buttonVariants = cva("group/button inline-flex shrink-0 items-center justify-center rounded-md border border-transparent bg-clip-padding text-sm font-medium whitespace-nowrap transition-all outline-none select-none focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 active:not-aria-[haspopup]:translate-y-px disabled:pointer-events-none disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4", {
19
+ variants: {
20
+ variant: {
21
+ default: "bg-primary text-primary-foreground hover:bg-primary/80",
22
+ outline: "border-border bg-background shadow-xs hover:bg-muted hover:text-foreground aria-expanded:bg-muted aria-expanded:text-foreground dark:border-input dark:bg-input/30 dark:hover:bg-input/50",
23
+ secondary: "bg-secondary text-secondary-foreground hover:bg-[color-mix(in_oklch,var(--secondary),var(--foreground)_5%)] aria-expanded:bg-secondary aria-expanded:text-secondary-foreground",
24
+ ghost: "hover:bg-muted hover:text-foreground aria-expanded:bg-muted aria-expanded:text-foreground dark:hover:bg-muted/50",
25
+ destructive: "bg-destructive/10 text-destructive hover:bg-destructive/20 focus-visible:border-destructive/40 focus-visible:ring-destructive/20 dark:bg-destructive/20 dark:hover:bg-destructive/30 dark:focus-visible:ring-destructive/40",
26
+ link: "text-primary underline-offset-4 hover:underline"
27
+ },
28
+ size: {
29
+ default: "h-9 gap-1.5 px-2.5 in-data-[slot=button-group]:rounded-md has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2",
30
+ xs: "h-6 gap-1 rounded-[min(var(--radius-md),8px)] px-2 text-xs in-data-[slot=button-group]:rounded-md has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 [&_svg:not([class*='size-'])]:size-3",
31
+ sm: "h-8 gap-1 rounded-[min(var(--radius-md),10px)] px-2.5 in-data-[slot=button-group]:rounded-md has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5",
32
+ lg: "h-10 gap-1.5 px-2.5 has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2",
33
+ icon: "size-9",
34
+ "icon-xs": "size-6 rounded-[min(var(--radius-md),8px)] in-data-[slot=button-group]:rounded-md [&_svg:not([class*='size-'])]:size-3",
35
+ "icon-sm": "size-8 rounded-[min(var(--radius-md),10px)] in-data-[slot=button-group]:rounded-md",
36
+ "icon-lg": "size-10"
37
+ }
38
+ },
39
+ defaultVariants: {
40
+ variant: "default",
41
+ size: "default"
42
+ }
43
+ });
44
+ function Button({
45
+ className,
46
+ variant = "default",
47
+ size = "default",
48
+ ...props
49
+ }) {
50
+ return /* @__PURE__ */ jsx(ButtonPrimitive, {
51
+ "data-slot": "button",
52
+ className: cn(buttonVariants({ variant, size, className })),
53
+ ...props
54
+ });
55
+ }
56
+
57
+ // ../../src/components/ui/async-action-button.tsx
58
+ import { useKrakstackLocale } from "@krak-stack/registry/krakstack-provider";
59
+ import { jsx as jsx2, jsxs } from "react/jsx-runtime";
60
+ var labels = {
61
+ en: {
62
+ pending: "Working…",
63
+ success: "Completed",
64
+ retry: "Try again",
65
+ error: "The action failed. Please try again."
66
+ },
67
+ fr: {
68
+ pending: "En cours…",
69
+ success: "Terminé",
70
+ retry: "Réessayer",
71
+ error: "L’action a échoué. Veuillez réessayer."
72
+ }
73
+ };
74
+ var AsyncActionButton = ({
75
+ onAction,
76
+ onPendingChange,
77
+ children,
78
+ disabled,
79
+ locale: override,
80
+ messages,
81
+ ...props
82
+ }) => {
83
+ const locale = useKrakstackLocale(override);
84
+ const copy = {
85
+ ...locale.startsWith("fr") ? labels.fr : labels.en,
86
+ ...messages?.[locale.split("-")[0] ?? locale],
87
+ ...messages?.[locale]
88
+ };
89
+ const [status, setStatus] = useState("idle");
90
+ const locked = useRef(false);
91
+ const mounted = useRef(false);
92
+ useEffect(() => {
93
+ mounted.current = true;
94
+ return () => {
95
+ mounted.current = false;
96
+ };
97
+ }, []);
98
+ const run = async () => {
99
+ if (locked.current || disabled)
100
+ return;
101
+ locked.current = true;
102
+ setStatus("pending");
103
+ onPendingChange?.(true);
104
+ try {
105
+ await onAction();
106
+ if (mounted.current)
107
+ setStatus("success");
108
+ } catch {
109
+ if (mounted.current)
110
+ setStatus("error");
111
+ } finally {
112
+ locked.current = false;
113
+ onPendingChange?.(false);
114
+ }
115
+ };
116
+ return /* @__PURE__ */ jsxs("span", {
117
+ "data-slot": "async-action-button",
118
+ className: "inline-flex min-w-0 flex-col items-start gap-2",
119
+ children: [
120
+ /* @__PURE__ */ jsxs(Button, {
121
+ ...props,
122
+ type: "button",
123
+ disabled: disabled || status === "pending",
124
+ "aria-busy": status === "pending",
125
+ onClick: () => {
126
+ run();
127
+ },
128
+ children: [
129
+ status === "pending" ? /* @__PURE__ */ jsx2(LoaderCircle, {
130
+ "aria-hidden": "true",
131
+ className: "motion-safe:animate-spin"
132
+ }) : status === "success" ? /* @__PURE__ */ jsx2(Check, {
133
+ "aria-hidden": "true"
134
+ }) : status === "error" ? /* @__PURE__ */ jsx2(RotateCcw, {
135
+ "aria-hidden": "true"
136
+ }) : null,
137
+ status === "pending" ? copy.pending : status === "success" ? copy.success : status === "error" ? copy.retry : children
138
+ ]
139
+ }),
140
+ /* @__PURE__ */ jsx2("span", {
141
+ "data-slot": "async-action-feedback",
142
+ role: "status",
143
+ className: status === "error" ? "text-destructive text-sm" : "sr-only",
144
+ children: status === "error" ? copy.error : status === "success" ? copy.success : status === "pending" ? copy.pending : ""
145
+ })
146
+ ]
147
+ });
148
+ };
149
+
150
+ // ../../src/components/ui/input.tsx
151
+ import { Input as InputPrimitive } from "@base-ui/react/input";
152
+ import { jsx as jsx3 } from "react/jsx-runtime";
153
+ function Input({ className, type, ...props }) {
154
+ return /* @__PURE__ */ jsx3(InputPrimitive, {
155
+ type,
156
+ "data-slot": "input",
157
+ className: cn("h-9 w-full min-w-0 rounded-md border border-input bg-transparent px-2.5 py-1 text-base shadow-xs transition-[color,box-shadow] outline-none file:inline-flex file:h-7 file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 md:text-sm dark:bg-input/30 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40", className),
158
+ ...props
159
+ });
160
+ }
161
+
162
+ // ../../src/components/ui/label.tsx
163
+ import { jsx as jsx4 } from "react/jsx-runtime";
164
+ "use client";
165
+ function Label({ className, ...props }) {
166
+ return /* @__PURE__ */ jsx4("label", {
167
+ "data-slot": "label",
168
+ className: cn("flex items-center gap-2 text-sm leading-none font-medium select-none group-data-[disabled=true]:pointer-events-none group-data-[disabled=true]:opacity-50 peer-disabled:cursor-not-allowed peer-disabled:opacity-50", className),
169
+ ...props
170
+ });
171
+ }
172
+
173
+ // ../../src/components/ui/editable-text.tsx
174
+ import { useKrakstackLocale as useKrakstackLocale2 } from "@krak-stack/registry/krakstack-provider";
175
+ import { jsx as jsx5, jsxs as jsxs2 } from "react/jsx-runtime";
176
+ var labels2 = {
177
+ en: {
178
+ edit: "Edit",
179
+ save: "Save",
180
+ cancel: "Cancel",
181
+ empty: "Not set",
182
+ pending: "Saving…",
183
+ error: "Could not save. Check the value and try again."
184
+ },
185
+ fr: {
186
+ edit: "Modifier",
187
+ save: "Enregistrer",
188
+ cancel: "Annuler",
189
+ empty: "Non défini",
190
+ pending: "Enregistrement…",
191
+ error: "Impossible d’enregistrer. Vérifiez la valeur et réessayez."
192
+ }
193
+ };
194
+ var EditableText = ({
195
+ value,
196
+ label,
197
+ onSave,
198
+ disabled,
199
+ maxLength,
200
+ className,
201
+ locale: override,
202
+ messages
203
+ }) => {
204
+ const locale = useKrakstackLocale2(override);
205
+ const copy = {
206
+ ...locale.startsWith("fr") ? labels2.fr : labels2.en,
207
+ ...messages?.[locale.split("-")[0] ?? locale],
208
+ ...messages?.[locale]
209
+ };
210
+ const [editing, setEditing] = useState2(false);
211
+ const trigger = useRef2(null);
212
+ const wasEditing = useRef2(false);
213
+ useEffect2(() => {
214
+ if (wasEditing.current && !editing)
215
+ trigger.current?.focus();
216
+ wasEditing.current = editing;
217
+ }, [editing]);
218
+ return /* @__PURE__ */ jsx5("div", {
219
+ className,
220
+ children: editing ? /* @__PURE__ */ jsx5(EditableTextEditor, {
221
+ value,
222
+ label,
223
+ onSave,
224
+ disabled,
225
+ maxLength,
226
+ locale,
227
+ copy,
228
+ onClose: () => setEditing(false)
229
+ }) : /* @__PURE__ */ jsxs2(Button, {
230
+ ref: trigger,
231
+ type: "button",
232
+ variant: "ghost",
233
+ disabled,
234
+ "aria-label": `${copy.edit} ${label}`,
235
+ className: "h-auto max-w-full text-left whitespace-normal",
236
+ onClick: () => setEditing(true),
237
+ children: [
238
+ /* @__PURE__ */ jsx5("span", {
239
+ className: "break-all",
240
+ children: value || copy.empty
241
+ }),
242
+ /* @__PURE__ */ jsx5(Pencil, {
243
+ "aria-hidden": "true"
244
+ })
245
+ ]
246
+ })
247
+ });
248
+ };
249
+ var EditableTextEditor = ({
250
+ value,
251
+ label,
252
+ onSave,
253
+ disabled,
254
+ maxLength,
255
+ locale,
256
+ copy,
257
+ onClose
258
+ }) => {
259
+ const [draft, setDraft] = useState2(value);
260
+ const [pending, setPending] = useState2(false);
261
+ const input = useRef2(null);
262
+ const save = useRef2(null);
263
+ const id = useId();
264
+ useEffect2(() => {
265
+ input.current?.focus();
266
+ input.current?.select();
267
+ }, []);
268
+ return /* @__PURE__ */ jsxs2("div", {
269
+ className: "grid gap-3",
270
+ onKeyDown: (event) => {
271
+ if (event.nativeEvent.isComposing)
272
+ return;
273
+ if (event.key === "Escape" && !pending) {
274
+ event.preventDefault();
275
+ event.stopPropagation();
276
+ onClose();
277
+ }
278
+ },
279
+ children: [
280
+ /* @__PURE__ */ jsx5(Label, {
281
+ htmlFor: id,
282
+ children: label
283
+ }),
284
+ /* @__PURE__ */ jsx5(Input, {
285
+ ref: input,
286
+ id,
287
+ value: draft,
288
+ maxLength,
289
+ disabled: disabled || pending,
290
+ onChange: (event) => setDraft(event.target.value),
291
+ onKeyDown: (event) => {
292
+ if (event.key === "Enter" && !event.nativeEvent.isComposing) {
293
+ event.preventDefault();
294
+ save.current?.click();
295
+ }
296
+ }
297
+ }),
298
+ /* @__PURE__ */ jsxs2("div", {
299
+ className: "grid grid-cols-[auto_1fr] items-start gap-2 [&_[data-slot=async-action-feedback]]:col-span-full [&_[data-slot=async-action-feedback]]:row-start-2 [&>[data-slot=async-action-button]]:contents",
300
+ children: [
301
+ /* @__PURE__ */ jsx5(AsyncActionButton, {
302
+ ref: save,
303
+ disabled: disabled || draft === value,
304
+ locale,
305
+ messages: {
306
+ [locale ?? "en"]: {
307
+ pending: copy.pending,
308
+ retry: copy.save,
309
+ error: copy.error
310
+ }
311
+ },
312
+ onPendingChange: setPending,
313
+ onAction: async () => {
314
+ await onSave(draft);
315
+ onClose();
316
+ },
317
+ children: copy.save
318
+ }),
319
+ /* @__PURE__ */ jsx5(Button, {
320
+ className: "justify-self-start",
321
+ type: "button",
322
+ variant: "outline",
323
+ disabled: pending,
324
+ onClick: onClose,
325
+ children: copy.cancel
326
+ })
327
+ ]
328
+ })
329
+ ]
330
+ });
331
+ };
332
+ export {
333
+ EditableText
334
+ };
@@ -0,0 +1,41 @@
1
+ export type ImageCropState = {
2
+ x: number;
3
+ y: number;
4
+ zoom: number;
5
+ rotation: 0 | 90 | 180 | 270;
6
+ };
7
+ export type ImageCropEditorMessages = {
8
+ zoom: string;
9
+ horizontal: string;
10
+ vertical: string;
11
+ rotate: string;
12
+ reset: string;
13
+ export: string;
14
+ loading: string;
15
+ loadError: string;
16
+ help: string;
17
+ exportError: string;
18
+ };
19
+ export type ImageCropEditorProps = {
20
+ src: string;
21
+ label: string;
22
+ value: ImageCropState;
23
+ onValueChange: (value: ImageCropState) => void;
24
+ onExport: (blob: Blob) => void | Promise<void>;
25
+ aspectRatio?: number;
26
+ maxOutputSize?: number;
27
+ disabled?: boolean;
28
+ className?: string;
29
+ locale?: string;
30
+ messages?: Partial<Record<string, Partial<ImageCropEditorMessages>>>;
31
+ };
32
+ /** Coordinates are in rotated source pixels; x/y state is a percentage of available travel. */
33
+ export declare const getImageCropGeometry: (width: number, height: number, value: ImageCropState, aspectRatio?: number) => {
34
+ x: number;
35
+ y: number;
36
+ width: number;
37
+ height: number;
38
+ sourceWidth: number;
39
+ sourceHeight: number;
40
+ };
41
+ export declare const ImageCropEditor: (props: ImageCropEditorProps) => import("react").JSX.Element;