@krak-stack/registry 0.5.0 → 0.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.
- package/CHANGELOG.md +8 -0
- package/dist/components/ui/animated-list.d.ts +22 -0
- package/dist/components/ui/animated-list.js +219 -0
- package/dist/components/ui/animated-number.d.ts +9 -0
- package/dist/components/ui/animated-number.js +52 -0
- package/dist/components/ui/async-action-button.d.ts +16 -0
- package/dist/components/ui/async-action-button.js +147 -0
- package/dist/components/ui/auto-height.d.ts +9 -0
- package/dist/components/ui/auto-height.js +45 -0
- package/dist/components/ui/danger-confirmation.d.ts +20 -0
- package/dist/components/ui/danger-confirmation.js +394 -0
- package/dist/components/ui/editable-text.d.ts +19 -0
- package/dist/components/ui/editable-text.js +334 -0
- package/dist/components/ui/presence-transition.d.ts +9 -0
- package/dist/components/ui/presence-transition.js +41 -0
- package/dist/components/ui/unsaved-changes-guard.d.ts +15 -0
- package/dist/components/ui/unsaved-changes-guard.js +235 -0
- package/package.json +34 -1
|
@@ -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,9 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
export type PresenceTransitionProps = {
|
|
3
|
+
open: boolean;
|
|
4
|
+
children: ReactNode;
|
|
5
|
+
duration?: number;
|
|
6
|
+
className?: string;
|
|
7
|
+
};
|
|
8
|
+
/** Exit content becomes inert immediately, then unmounts after its animation. */
|
|
9
|
+
export declare const PresenceTransition: ({ open, ...props }: PresenceTransitionProps) => import("react").JSX.Element;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// ../../src/components/ui/presence-transition.tsx
|
|
2
|
+
import {
|
|
3
|
+
AnimatePresence,
|
|
4
|
+
motion,
|
|
5
|
+
useIsPresent,
|
|
6
|
+
useReducedMotion
|
|
7
|
+
} from "motion/react";
|
|
8
|
+
import { jsx } from "react/jsx-runtime";
|
|
9
|
+
var PresenceTransition = ({
|
|
10
|
+
open,
|
|
11
|
+
...props
|
|
12
|
+
}) => /* @__PURE__ */ jsx(AnimatePresence, {
|
|
13
|
+
initial: false,
|
|
14
|
+
children: open ? /* @__PURE__ */ jsx(PresenceContent, {
|
|
15
|
+
...props
|
|
16
|
+
}, "content") : null
|
|
17
|
+
});
|
|
18
|
+
var PresenceContent = ({
|
|
19
|
+
children,
|
|
20
|
+
duration = 180,
|
|
21
|
+
className
|
|
22
|
+
}) => {
|
|
23
|
+
const present = useIsPresent();
|
|
24
|
+
const reduced = useReducedMotion();
|
|
25
|
+
return /* @__PURE__ */ jsx(motion.div, {
|
|
26
|
+
"data-slot": "presence-transition",
|
|
27
|
+
className,
|
|
28
|
+
inert: !present,
|
|
29
|
+
"aria-hidden": !present ? true : undefined,
|
|
30
|
+
initial: { opacity: 0, y: reduced !== false ? 0 : 4 },
|
|
31
|
+
animate: { opacity: 1, y: 0 },
|
|
32
|
+
exit: { opacity: 0, y: reduced !== false ? 0 : 4 },
|
|
33
|
+
transition: {
|
|
34
|
+
duration: reduced !== false ? 0 : Math.max(0, duration) / 1000
|
|
35
|
+
},
|
|
36
|
+
children
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
export {
|
|
40
|
+
PresenceTransition
|
|
41
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export type UnsavedChangesGuardMessages = {
|
|
2
|
+
title: string;
|
|
3
|
+
description: string;
|
|
4
|
+
stay: string;
|
|
5
|
+
leave: string;
|
|
6
|
+
};
|
|
7
|
+
export type UnsavedChangesGuardProps = {
|
|
8
|
+
dirty: boolean;
|
|
9
|
+
enabled?: boolean;
|
|
10
|
+
protectBeforeUnload?: boolean;
|
|
11
|
+
locale?: string;
|
|
12
|
+
messages?: Partial<Record<string, Partial<UnsavedChangesGuardMessages>>>;
|
|
13
|
+
};
|
|
14
|
+
/** Mount once per editing route, inside a TanStack Router provider. */
|
|
15
|
+
export declare const UnsavedChangesGuard: ({ dirty, enabled, protectBeforeUnload, locale: override, messages, }: UnsavedChangesGuardProps) => import("react").JSX.Element;
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
// ../../src/components/ui/unsaved-changes-guard.tsx
|
|
2
|
+
import { useBlocker } from "@tanstack/react-router";
|
|
3
|
+
|
|
4
|
+
// ../../src/components/ui/alert-dialog.tsx
|
|
5
|
+
import { AlertDialog as AlertDialogPrimitive } from "@base-ui/react/alert-dialog";
|
|
6
|
+
|
|
7
|
+
// ../../src/lib/utils.ts
|
|
8
|
+
import { cn } from "cn";
|
|
9
|
+
|
|
10
|
+
// ../../src/components/ui/button.tsx
|
|
11
|
+
import { Button as ButtonPrimitive } from "@base-ui/react/button";
|
|
12
|
+
import { cva } from "class-variance-authority";
|
|
13
|
+
import { jsx } from "react/jsx-runtime";
|
|
14
|
+
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", {
|
|
15
|
+
variants: {
|
|
16
|
+
variant: {
|
|
17
|
+
default: "bg-primary text-primary-foreground hover:bg-primary/80",
|
|
18
|
+
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",
|
|
19
|
+
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",
|
|
20
|
+
ghost: "hover:bg-muted hover:text-foreground aria-expanded:bg-muted aria-expanded:text-foreground dark:hover:bg-muted/50",
|
|
21
|
+
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",
|
|
22
|
+
link: "text-primary underline-offset-4 hover:underline"
|
|
23
|
+
},
|
|
24
|
+
size: {
|
|
25
|
+
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",
|
|
26
|
+
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",
|
|
27
|
+
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",
|
|
28
|
+
lg: "h-10 gap-1.5 px-2.5 has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2",
|
|
29
|
+
icon: "size-9",
|
|
30
|
+
"icon-xs": "size-6 rounded-[min(var(--radius-md),8px)] in-data-[slot=button-group]:rounded-md [&_svg:not([class*='size-'])]:size-3",
|
|
31
|
+
"icon-sm": "size-8 rounded-[min(var(--radius-md),10px)] in-data-[slot=button-group]:rounded-md",
|
|
32
|
+
"icon-lg": "size-10"
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
defaultVariants: {
|
|
36
|
+
variant: "default",
|
|
37
|
+
size: "default"
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
function Button({
|
|
41
|
+
className,
|
|
42
|
+
variant = "default",
|
|
43
|
+
size = "default",
|
|
44
|
+
...props
|
|
45
|
+
}) {
|
|
46
|
+
return /* @__PURE__ */ jsx(ButtonPrimitive, {
|
|
47
|
+
"data-slot": "button",
|
|
48
|
+
className: cn(buttonVariants({ variant, size, className })),
|
|
49
|
+
...props
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// ../../src/components/ui/alert-dialog.tsx
|
|
54
|
+
import { jsx as jsx2, jsxs } from "react/jsx-runtime";
|
|
55
|
+
"use client";
|
|
56
|
+
function AlertDialog({ ...props }) {
|
|
57
|
+
return /* @__PURE__ */ jsx2(AlertDialogPrimitive.Root, {
|
|
58
|
+
"data-slot": "alert-dialog",
|
|
59
|
+
...props
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
function AlertDialogPortal({ ...props }) {
|
|
63
|
+
return /* @__PURE__ */ jsx2(AlertDialogPrimitive.Portal, {
|
|
64
|
+
"data-slot": "alert-dialog-portal",
|
|
65
|
+
...props
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
function AlertDialogOverlay({
|
|
69
|
+
className,
|
|
70
|
+
...props
|
|
71
|
+
}) {
|
|
72
|
+
return /* @__PURE__ */ jsx2(AlertDialogPrimitive.Backdrop, {
|
|
73
|
+
"data-slot": "alert-dialog-overlay",
|
|
74
|
+
className: cn("fixed inset-0 isolate z-50 bg-black/10 duration-100 supports-backdrop-filter:backdrop-blur-xs data-open:animate-in data-open:fade-in-0 data-closed:animate-out data-closed:fade-out-0", className),
|
|
75
|
+
...props
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
function AlertDialogContent({
|
|
79
|
+
className,
|
|
80
|
+
size = "default",
|
|
81
|
+
...props
|
|
82
|
+
}) {
|
|
83
|
+
return /* @__PURE__ */ jsxs(AlertDialogPortal, {
|
|
84
|
+
children: [
|
|
85
|
+
/* @__PURE__ */ jsx2(AlertDialogOverlay, {}),
|
|
86
|
+
/* @__PURE__ */ jsx2(AlertDialogPrimitive.Popup, {
|
|
87
|
+
"data-slot": "alert-dialog-content",
|
|
88
|
+
"data-size": size,
|
|
89
|
+
className: cn("group/alert-dialog-content fixed top-1/2 left-1/2 z-50 grid w-full -translate-x-1/2 -translate-y-1/2 gap-6 rounded-xl bg-popover p-6 text-popover-foreground ring-1 ring-foreground/10 duration-100 outline-none data-[size=default]:max-w-xs data-[size=sm]:max-w-xs data-[size=default]:sm:max-w-lg 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-out-95", className),
|
|
90
|
+
...props
|
|
91
|
+
})
|
|
92
|
+
]
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
function AlertDialogHeader({
|
|
96
|
+
className,
|
|
97
|
+
...props
|
|
98
|
+
}) {
|
|
99
|
+
return /* @__PURE__ */ jsx2("div", {
|
|
100
|
+
"data-slot": "alert-dialog-header",
|
|
101
|
+
className: cn("grid grid-rows-[auto_1fr] place-items-center gap-1.5 text-center has-data-[slot=alert-dialog-media]:grid-rows-[auto_auto_1fr] has-data-[slot=alert-dialog-media]:gap-x-6 sm:group-data-[size=default]/alert-dialog-content:place-items-start sm:group-data-[size=default]/alert-dialog-content:text-left sm:group-data-[size=default]/alert-dialog-content:has-data-[slot=alert-dialog-media]:grid-rows-[auto_1fr]", className),
|
|
102
|
+
...props
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
function AlertDialogFooter({
|
|
106
|
+
className,
|
|
107
|
+
...props
|
|
108
|
+
}) {
|
|
109
|
+
return /* @__PURE__ */ jsx2("div", {
|
|
110
|
+
"data-slot": "alert-dialog-footer",
|
|
111
|
+
className: cn("flex flex-col-reverse gap-2 group-data-[size=sm]/alert-dialog-content:grid group-data-[size=sm]/alert-dialog-content:grid-cols-2 sm:flex-row sm:justify-end", className),
|
|
112
|
+
...props
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
function AlertDialogTitle({
|
|
116
|
+
className,
|
|
117
|
+
...props
|
|
118
|
+
}) {
|
|
119
|
+
return /* @__PURE__ */ jsx2(AlertDialogPrimitive.Title, {
|
|
120
|
+
"data-slot": "alert-dialog-title",
|
|
121
|
+
className: cn("text-lg font-medium sm:group-data-[size=default]/alert-dialog-content:group-has-data-[slot=alert-dialog-media]/alert-dialog-content:col-start-2", className),
|
|
122
|
+
...props
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
function AlertDialogDescription({
|
|
126
|
+
className,
|
|
127
|
+
...props
|
|
128
|
+
}) {
|
|
129
|
+
return /* @__PURE__ */ jsx2(AlertDialogPrimitive.Description, {
|
|
130
|
+
"data-slot": "alert-dialog-description",
|
|
131
|
+
className: cn("text-sm text-balance text-muted-foreground md:text-pretty *:[a]:underline *:[a]:underline-offset-3 *:[a]:hover:text-foreground", className),
|
|
132
|
+
...props
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
function AlertDialogAction({
|
|
136
|
+
className,
|
|
137
|
+
...props
|
|
138
|
+
}) {
|
|
139
|
+
return /* @__PURE__ */ jsx2(Button, {
|
|
140
|
+
"data-slot": "alert-dialog-action",
|
|
141
|
+
className: cn(className),
|
|
142
|
+
...props
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
function AlertDialogCancel({
|
|
146
|
+
className,
|
|
147
|
+
variant = "outline",
|
|
148
|
+
size = "default",
|
|
149
|
+
...props
|
|
150
|
+
}) {
|
|
151
|
+
return /* @__PURE__ */ jsx2(AlertDialogPrimitive.Close, {
|
|
152
|
+
"data-slot": "alert-dialog-cancel",
|
|
153
|
+
className: cn(className),
|
|
154
|
+
render: /* @__PURE__ */ jsx2(Button, {
|
|
155
|
+
variant,
|
|
156
|
+
size
|
|
157
|
+
}),
|
|
158
|
+
...props
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// ../../src/components/ui/unsaved-changes-guard.tsx
|
|
163
|
+
import { useKrakstackLocale } from "@krak-stack/registry/krakstack-provider";
|
|
164
|
+
import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
165
|
+
var labels = {
|
|
166
|
+
en: {
|
|
167
|
+
title: "Leave without saving?",
|
|
168
|
+
description: "You have unsaved changes. Leaving this page will discard them.",
|
|
169
|
+
stay: "Keep editing",
|
|
170
|
+
leave: "Leave page"
|
|
171
|
+
},
|
|
172
|
+
fr: {
|
|
173
|
+
title: "Quitter sans enregistrer ?",
|
|
174
|
+
description: "Des modifications n’ont pas été enregistrées. Elles seront perdues si vous quittez cette page.",
|
|
175
|
+
stay: "Continuer la modification",
|
|
176
|
+
leave: "Quitter la page"
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
var UnsavedChangesGuard = ({
|
|
180
|
+
dirty,
|
|
181
|
+
enabled = true,
|
|
182
|
+
protectBeforeUnload = true,
|
|
183
|
+
locale: override,
|
|
184
|
+
messages
|
|
185
|
+
}) => {
|
|
186
|
+
const locale = useKrakstackLocale(override);
|
|
187
|
+
const copy = {
|
|
188
|
+
...locale.startsWith("fr") ? labels.fr : labels.en,
|
|
189
|
+
...messages?.[locale.split("-")[0] ?? locale],
|
|
190
|
+
...messages?.[locale]
|
|
191
|
+
};
|
|
192
|
+
const blocker = useBlocker({
|
|
193
|
+
shouldBlockFn: () => dirty && enabled,
|
|
194
|
+
enableBeforeUnload: dirty && enabled && protectBeforeUnload,
|
|
195
|
+
withResolver: true
|
|
196
|
+
});
|
|
197
|
+
return /* @__PURE__ */ jsx3(AlertDialog, {
|
|
198
|
+
open: blocker.status === "blocked",
|
|
199
|
+
onOpenChange: (open) => {
|
|
200
|
+
if (!open)
|
|
201
|
+
blocker.reset?.();
|
|
202
|
+
},
|
|
203
|
+
children: /* @__PURE__ */ jsxs2(AlertDialogContent, {
|
|
204
|
+
children: [
|
|
205
|
+
/* @__PURE__ */ jsxs2(AlertDialogHeader, {
|
|
206
|
+
children: [
|
|
207
|
+
/* @__PURE__ */ jsx3(AlertDialogTitle, {
|
|
208
|
+
children: copy.title
|
|
209
|
+
}),
|
|
210
|
+
/* @__PURE__ */ jsx3(AlertDialogDescription, {
|
|
211
|
+
children: copy.description
|
|
212
|
+
})
|
|
213
|
+
]
|
|
214
|
+
}),
|
|
215
|
+
/* @__PURE__ */ jsxs2(AlertDialogFooter, {
|
|
216
|
+
children: [
|
|
217
|
+
/* @__PURE__ */ jsx3(AlertDialogCancel, {
|
|
218
|
+
type: "button",
|
|
219
|
+
children: copy.stay
|
|
220
|
+
}),
|
|
221
|
+
/* @__PURE__ */ jsx3(AlertDialogAction, {
|
|
222
|
+
type: "button",
|
|
223
|
+
variant: "destructive",
|
|
224
|
+
onClick: () => blocker.proceed?.(),
|
|
225
|
+
children: copy.leave
|
|
226
|
+
})
|
|
227
|
+
]
|
|
228
|
+
})
|
|
229
|
+
]
|
|
230
|
+
})
|
|
231
|
+
});
|
|
232
|
+
};
|
|
233
|
+
export {
|
|
234
|
+
UnsavedChangesGuard
|
|
235
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@krak-stack/registry",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Tree-shakable KrakStack components and Effect services.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -17,6 +17,38 @@
|
|
|
17
17
|
"type": "module",
|
|
18
18
|
"sideEffects": false,
|
|
19
19
|
"exports": {
|
|
20
|
+
"./async-action-button": {
|
|
21
|
+
"types": "./dist/components/ui/async-action-button.d.ts",
|
|
22
|
+
"import": "./dist/components/ui/async-action-button.js"
|
|
23
|
+
},
|
|
24
|
+
"./unsaved-changes-guard": {
|
|
25
|
+
"types": "./dist/components/ui/unsaved-changes-guard.d.ts",
|
|
26
|
+
"import": "./dist/components/ui/unsaved-changes-guard.js"
|
|
27
|
+
},
|
|
28
|
+
"./danger-confirmation": {
|
|
29
|
+
"types": "./dist/components/ui/danger-confirmation.d.ts",
|
|
30
|
+
"import": "./dist/components/ui/danger-confirmation.js"
|
|
31
|
+
},
|
|
32
|
+
"./editable-text": {
|
|
33
|
+
"types": "./dist/components/ui/editable-text.d.ts",
|
|
34
|
+
"import": "./dist/components/ui/editable-text.js"
|
|
35
|
+
},
|
|
36
|
+
"./presence-transition": {
|
|
37
|
+
"types": "./dist/components/ui/presence-transition.d.ts",
|
|
38
|
+
"import": "./dist/components/ui/presence-transition.js"
|
|
39
|
+
},
|
|
40
|
+
"./auto-height": {
|
|
41
|
+
"types": "./dist/components/ui/auto-height.d.ts",
|
|
42
|
+
"import": "./dist/components/ui/auto-height.js"
|
|
43
|
+
},
|
|
44
|
+
"./animated-list": {
|
|
45
|
+
"types": "./dist/components/ui/animated-list.d.ts",
|
|
46
|
+
"import": "./dist/components/ui/animated-list.js"
|
|
47
|
+
},
|
|
48
|
+
"./animated-number": {
|
|
49
|
+
"types": "./dist/components/ui/animated-number.d.ts",
|
|
50
|
+
"import": "./dist/components/ui/animated-number.js"
|
|
51
|
+
},
|
|
20
52
|
"./app-switcher": {
|
|
21
53
|
"types": "./dist/components/ui/app-switcher.d.ts",
|
|
22
54
|
"import": "./dist/components/ui/app-switcher.js"
|
|
@@ -330,6 +362,7 @@
|
|
|
330
362
|
"dependencies": {
|
|
331
363
|
"@oxlint/plugins": "1.78.0",
|
|
332
364
|
"bowser": "^2.14.1",
|
|
365
|
+
"motion": "^14.12.0",
|
|
333
366
|
"react-colorful": "^5.8.1",
|
|
334
367
|
"web-vitals": "^5.1.0"
|
|
335
368
|
},
|