@krak-stack/registry 0.10.12 → 0.10.13
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
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# @krak-stack/registry
|
|
2
2
|
|
|
3
|
+
## 0.10.13
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Add a reusable support dialog with a message, optional screenshot attachments, and a host-owned delivery callback.
|
|
8
|
+
|
|
9
|
+
Share support schemas, multipart limits, and screenshot handling with host APIs.
|
|
10
|
+
|
|
3
11
|
## 0.10.12
|
|
4
12
|
|
|
5
13
|
### Patch Changes
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { Effect, FileSystem, Schema } from "effect";
|
|
2
|
+
import { Multipart } from "effect/http";
|
|
3
|
+
import { HttpApiSchema } from "effect/http-api";
|
|
4
|
+
import { type ReactElement } from "react";
|
|
5
|
+
export declare const SupportReplyEmail: Schema.Trim;
|
|
6
|
+
export declare const SupportRequestSchema: Schema.Struct<{
|
|
7
|
+
readonly message: Schema.Trim;
|
|
8
|
+
readonly replyEmail: Schema.optionalKey<Schema.Trim>;
|
|
9
|
+
readonly attachments: Schema.$Array<Schema.File>;
|
|
10
|
+
}>;
|
|
11
|
+
export type SupportRequest = typeof SupportRequestSchema.Type;
|
|
12
|
+
export declare const SupportMultipartPayload: HttpApiSchema.asMultipart<Schema.Struct<{
|
|
13
|
+
readonly message: Schema.Trim;
|
|
14
|
+
readonly replyEmail: Schema.optionalKey<Schema.Trim>;
|
|
15
|
+
readonly attachments: Schema.optionalKey<Schema.$Array<Multipart.PersistedFileSchema>>;
|
|
16
|
+
}>>;
|
|
17
|
+
declare const InvalidSupportScreenshot_base: Schema.Class<InvalidSupportScreenshot, Schema.TaggedStruct<"InvalidSupportScreenshot", {}>, import("effect/Cause").YieldableError>;
|
|
18
|
+
export declare class InvalidSupportScreenshot extends InvalidSupportScreenshot_base {
|
|
19
|
+
}
|
|
20
|
+
/** Read bounded temporary files from SupportMultipartPayload and check their signatures. */
|
|
21
|
+
export declare const readSupportScreenshots: (files: readonly Multipart.PersistedFile[]) => Effect.Effect<{
|
|
22
|
+
content: Uint8Array<ArrayBufferLike>;
|
|
23
|
+
contentType: string;
|
|
24
|
+
filename: string;
|
|
25
|
+
}[], InvalidSupportScreenshot | import("effect/PlatformError").PlatformError, FileSystem.FileSystem>;
|
|
26
|
+
export type SupportDialogMessages = {
|
|
27
|
+
title: string;
|
|
28
|
+
description?: string;
|
|
29
|
+
placeholder?: string;
|
|
30
|
+
replyEmail: string;
|
|
31
|
+
attach: string;
|
|
32
|
+
invalidAttachments: string;
|
|
33
|
+
removeAttachment: string;
|
|
34
|
+
submit: string;
|
|
35
|
+
pending: string;
|
|
36
|
+
success: string;
|
|
37
|
+
close: string;
|
|
38
|
+
invalid: string;
|
|
39
|
+
failed: string;
|
|
40
|
+
};
|
|
41
|
+
export type SupportDialogProps = {
|
|
42
|
+
locale?: string;
|
|
43
|
+
messages?: Partial<Record<string, Partial<SupportDialogMessages>>>;
|
|
44
|
+
trigger?: ReactElement;
|
|
45
|
+
askForReplyEmail?: boolean;
|
|
46
|
+
onSubmit: (request: SupportRequest) => void | Promise<void>;
|
|
47
|
+
};
|
|
48
|
+
export declare const SupportDialog: ({ locale: localeOverride, messages, trigger, askForReplyEmail, onSubmit, }: SupportDialogProps) => import("react").JSX.Element;
|
|
49
|
+
export {};
|
|
@@ -0,0 +1,651 @@
|
|
|
1
|
+
// ../../src/components/support-dialog.tsx
|
|
2
|
+
import { Dialog as DialogPrimitive2 } from "@base-ui/react/dialog";
|
|
3
|
+
import { Effect, FileSystem, Result, Schema } from "effect";
|
|
4
|
+
import { Multipart } from "effect/http";
|
|
5
|
+
import { HttpApiSchema } from "effect/http-api";
|
|
6
|
+
import { ImageIcon, Paperclip, XIcon as XIcon2 } from "lucide-react";
|
|
7
|
+
import {
|
|
8
|
+
useId,
|
|
9
|
+
useRef,
|
|
10
|
+
useState
|
|
11
|
+
} from "react";
|
|
12
|
+
|
|
13
|
+
// ../../src/components/ui/attachment.tsx
|
|
14
|
+
import { mergeProps } from "@base-ui/react/merge-props";
|
|
15
|
+
import { useRender } from "@base-ui/react/use-render";
|
|
16
|
+
import { cva as cva2 } from "class-variance-authority";
|
|
17
|
+
|
|
18
|
+
// ../../src/lib/utils.ts
|
|
19
|
+
import { cn } from "cn";
|
|
20
|
+
|
|
21
|
+
// ../../src/components/ui/button.tsx
|
|
22
|
+
import { Button as ButtonPrimitive } from "@base-ui/react/button";
|
|
23
|
+
import { cva } from "class-variance-authority";
|
|
24
|
+
import { jsx } from "react/jsx-runtime";
|
|
25
|
+
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", {
|
|
26
|
+
variants: {
|
|
27
|
+
variant: {
|
|
28
|
+
default: "bg-primary text-primary-foreground hover:bg-primary/80",
|
|
29
|
+
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",
|
|
30
|
+
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",
|
|
31
|
+
ghost: "hover:bg-muted hover:text-foreground aria-expanded:bg-muted aria-expanded:text-foreground dark:hover:bg-muted/50",
|
|
32
|
+
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",
|
|
33
|
+
link: "text-primary underline-offset-4 hover:underline"
|
|
34
|
+
},
|
|
35
|
+
size: {
|
|
36
|
+
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",
|
|
37
|
+
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",
|
|
38
|
+
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",
|
|
39
|
+
lg: "h-10 gap-1.5 px-2.5 has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2",
|
|
40
|
+
icon: "size-9",
|
|
41
|
+
"icon-xs": "size-6 rounded-[min(var(--radius-md),8px)] in-data-[slot=button-group]:rounded-md [&_svg:not([class*='size-'])]:size-3",
|
|
42
|
+
"icon-sm": "size-8 rounded-[min(var(--radius-md),10px)] in-data-[slot=button-group]:rounded-md",
|
|
43
|
+
"icon-lg": "size-10"
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
defaultVariants: {
|
|
47
|
+
variant: "default",
|
|
48
|
+
size: "default"
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
function Button({
|
|
52
|
+
className,
|
|
53
|
+
variant = "default",
|
|
54
|
+
size = "default",
|
|
55
|
+
...props
|
|
56
|
+
}) {
|
|
57
|
+
return /* @__PURE__ */ jsx(ButtonPrimitive, {
|
|
58
|
+
"data-slot": "button",
|
|
59
|
+
className: cn(buttonVariants({ variant, size, className })),
|
|
60
|
+
...props
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// ../../src/components/ui/attachment.tsx
|
|
65
|
+
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
66
|
+
var attachmentVariants = cva2("group/attachment relative flex w-fit max-w-full min-w-0 shrink-0 flex-wrap rounded-xl border bg-card text-card-foreground transition-colors focus-within:ring-1 focus-within:ring-ring/50 has-[>a,>button]:hover:bg-muted/50 data-[state=error]:border-destructive/30 data-[state=idle]:border-dashed", {
|
|
67
|
+
variants: {
|
|
68
|
+
size: {
|
|
69
|
+
default: "gap-2 text-sm has-data-[slot=attachment-content]:px-2.5 has-data-[slot=attachment-content]:py-2 has-data-[slot=attachment-media]:p-2",
|
|
70
|
+
sm: "gap-2.5 text-xs has-data-[slot=attachment-content]:px-2 has-data-[slot=attachment-content]:py-1.5 has-data-[slot=attachment-media]:p-1.5",
|
|
71
|
+
xs: "gap-1.5 rounded-lg text-xs has-data-[slot=attachment-content]:px-1.5 has-data-[slot=attachment-content]:py-1 has-data-[slot=attachment-media]:p-1"
|
|
72
|
+
},
|
|
73
|
+
orientation: {
|
|
74
|
+
horizontal: "min-w-40 items-center",
|
|
75
|
+
vertical: "w-24 flex-col has-data-[slot=attachment-content]:w-30"
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
function Attachment({
|
|
80
|
+
className,
|
|
81
|
+
state = "done",
|
|
82
|
+
size = "default",
|
|
83
|
+
orientation = "horizontal",
|
|
84
|
+
...props
|
|
85
|
+
}) {
|
|
86
|
+
return /* @__PURE__ */ jsx2("div", {
|
|
87
|
+
"data-slot": "attachment",
|
|
88
|
+
"data-state": state,
|
|
89
|
+
"data-size": size,
|
|
90
|
+
"data-orientation": orientation,
|
|
91
|
+
className: cn(attachmentVariants({ size, orientation }), className),
|
|
92
|
+
...props
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
var attachmentMediaVariants = cva2("relative flex aspect-square w-10 shrink-0 items-center justify-center overflow-hidden rounded-lg bg-muted text-foreground group-data-[orientation=vertical]/attachment:w-full group-data-[size=sm]/attachment:w-8 group-data-[size=xs]/attachment:w-7 group-data-[size=xs]/attachment:rounded-md group-data-[state=error]/attachment:bg-destructive/10 group-data-[state=error]/attachment:text-destructive group-data-[orientation=vertical]/attachment:*:data-[slot=spinner]:size-6! [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 group-data-[orientation=vertical]/attachment:[&_svg:not([class*='size-'])]:size-6 group-data-[size=xs]/attachment:[&_svg:not([class*='size-'])]:size-3.5", {
|
|
96
|
+
variants: {
|
|
97
|
+
variant: {
|
|
98
|
+
icon: "",
|
|
99
|
+
image: "opacity-60 group-data-[state=done]/attachment:opacity-100 group-data-[state=idle]/attachment:opacity-100 *:[img]:aspect-square *:[img]:w-full *:[img]:object-cover"
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
defaultVariants: {
|
|
103
|
+
variant: "icon"
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
function AttachmentMedia({
|
|
107
|
+
className,
|
|
108
|
+
variant = "icon",
|
|
109
|
+
...props
|
|
110
|
+
}) {
|
|
111
|
+
return /* @__PURE__ */ jsx2("div", {
|
|
112
|
+
"data-slot": "attachment-media",
|
|
113
|
+
"data-variant": variant,
|
|
114
|
+
className: cn(attachmentMediaVariants({ variant }), className),
|
|
115
|
+
...props
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
function AttachmentContent({
|
|
119
|
+
className,
|
|
120
|
+
...props
|
|
121
|
+
}) {
|
|
122
|
+
return /* @__PURE__ */ jsx2("div", {
|
|
123
|
+
"data-slot": "attachment-content",
|
|
124
|
+
className: cn("max-w-full min-w-0 flex-1 leading-tight group-data-[orientation=vertical]/attachment:px-1", className),
|
|
125
|
+
...props
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
function AttachmentTitle({
|
|
129
|
+
className,
|
|
130
|
+
...props
|
|
131
|
+
}) {
|
|
132
|
+
return /* @__PURE__ */ jsx2("span", {
|
|
133
|
+
"data-slot": "attachment-title",
|
|
134
|
+
className: cn("block max-w-full min-w-0 truncate font-medium group-data-[state=processing]/attachment:shimmer group-data-[state=uploading]/attachment:shimmer", className),
|
|
135
|
+
...props
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
function AttachmentActions({
|
|
139
|
+
className,
|
|
140
|
+
...props
|
|
141
|
+
}) {
|
|
142
|
+
return /* @__PURE__ */ jsx2("div", {
|
|
143
|
+
"data-slot": "attachment-actions",
|
|
144
|
+
className: cn("relative z-20 flex shrink-0 items-center group-data-[orientation=vertical]/attachment:absolute group-data-[orientation=vertical]/attachment:top-3 group-data-[orientation=vertical]/attachment:right-3 group-data-[orientation=vertical]/attachment:gap-1", className),
|
|
145
|
+
...props
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
function AttachmentAction({
|
|
149
|
+
className,
|
|
150
|
+
variant,
|
|
151
|
+
size = "icon-xs",
|
|
152
|
+
...props
|
|
153
|
+
}) {
|
|
154
|
+
return /* @__PURE__ */ jsx2(Button, {
|
|
155
|
+
"data-slot": "attachment-action",
|
|
156
|
+
variant: variant ?? "ghost",
|
|
157
|
+
size,
|
|
158
|
+
className: cn(className),
|
|
159
|
+
...props
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// ../../src/components/ui/dialog.tsx
|
|
164
|
+
import { Dialog as DialogPrimitive } from "@base-ui/react/dialog";
|
|
165
|
+
import { XIcon } from "lucide-react";
|
|
166
|
+
import { jsx as jsx3, jsxs } from "react/jsx-runtime";
|
|
167
|
+
function Dialog({ ...props }) {
|
|
168
|
+
return /* @__PURE__ */ jsx3(DialogPrimitive.Root, {
|
|
169
|
+
"data-slot": "dialog",
|
|
170
|
+
...props
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
function DialogTrigger({ ...props }) {
|
|
174
|
+
return /* @__PURE__ */ jsx3(DialogPrimitive.Trigger, {
|
|
175
|
+
"data-slot": "dialog-trigger",
|
|
176
|
+
...props
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
function DialogPortal({ ...props }) {
|
|
180
|
+
return /* @__PURE__ */ jsx3(DialogPrimitive.Portal, {
|
|
181
|
+
"data-slot": "dialog-portal",
|
|
182
|
+
...props
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
function DialogClose({ ...props }) {
|
|
186
|
+
return /* @__PURE__ */ jsx3(DialogPrimitive.Close, {
|
|
187
|
+
"data-slot": "dialog-close",
|
|
188
|
+
...props
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
function DialogOverlay({
|
|
192
|
+
className,
|
|
193
|
+
...props
|
|
194
|
+
}) {
|
|
195
|
+
return /* @__PURE__ */ jsx3(DialogPrimitive.Backdrop, {
|
|
196
|
+
"data-slot": "dialog-overlay",
|
|
197
|
+
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),
|
|
198
|
+
...props
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
function DialogHeader({ className, ...props }) {
|
|
202
|
+
return /* @__PURE__ */ jsx3("div", {
|
|
203
|
+
"data-slot": "dialog-header",
|
|
204
|
+
className: cn("grid gap-1.5", className),
|
|
205
|
+
...props
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
function DialogFooter({ className, ...props }) {
|
|
209
|
+
return /* @__PURE__ */ jsx3("div", {
|
|
210
|
+
"data-slot": "dialog-footer",
|
|
211
|
+
className: cn("flex flex-col-reverse gap-2 sm:flex-row sm:justify-end", className),
|
|
212
|
+
...props
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
function DialogTitle({
|
|
216
|
+
className,
|
|
217
|
+
...props
|
|
218
|
+
}) {
|
|
219
|
+
return /* @__PURE__ */ jsx3(DialogPrimitive.Title, {
|
|
220
|
+
"data-slot": "dialog-title",
|
|
221
|
+
className: cn("text-lg font-medium", className),
|
|
222
|
+
...props
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
function DialogDescription({
|
|
226
|
+
className,
|
|
227
|
+
...props
|
|
228
|
+
}) {
|
|
229
|
+
return /* @__PURE__ */ jsx3(DialogPrimitive.Description, {
|
|
230
|
+
"data-slot": "dialog-description",
|
|
231
|
+
className: cn("text-sm text-muted-foreground", className),
|
|
232
|
+
...props
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
// ../../src/components/ui/input.tsx
|
|
237
|
+
import { Input as InputPrimitive } from "@base-ui/react/input";
|
|
238
|
+
import { jsx as jsx4 } from "react/jsx-runtime";
|
|
239
|
+
function Input({ className, type, ...props }) {
|
|
240
|
+
return /* @__PURE__ */ jsx4(InputPrimitive, {
|
|
241
|
+
type,
|
|
242
|
+
"data-slot": "input",
|
|
243
|
+
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),
|
|
244
|
+
...props
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
// ../../src/components/support-dialog.tsx
|
|
249
|
+
import { useKrakstackLocale } from "@krak-stack/registry/krakstack-provider";
|
|
250
|
+
|
|
251
|
+
// ../../src/components/ui/label.tsx
|
|
252
|
+
import { jsx as jsx5 } from "react/jsx-runtime";
|
|
253
|
+
"use client";
|
|
254
|
+
function Label({ className, ...props }) {
|
|
255
|
+
return /* @__PURE__ */ jsx5("label", {
|
|
256
|
+
"data-slot": "label",
|
|
257
|
+
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),
|
|
258
|
+
...props
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
// ../../src/components/ui/textarea.tsx
|
|
263
|
+
import { jsx as jsx6 } from "react/jsx-runtime";
|
|
264
|
+
function Textarea({ className, ...props }) {
|
|
265
|
+
return /* @__PURE__ */ jsx6("textarea", {
|
|
266
|
+
"data-slot": "textarea",
|
|
267
|
+
className: cn("flex field-sizing-content min-h-16 w-full rounded-md border border-input bg-transparent px-2.5 py-2 text-base shadow-xs transition-[color,box-shadow] outline-none placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 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),
|
|
268
|
+
...props
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
// ../../src/components/support-dialog.tsx
|
|
273
|
+
import { jsx as jsx7, jsxs as jsxs2, Fragment } from "react/jsx-runtime";
|
|
274
|
+
var supportMessageLimit = 5000;
|
|
275
|
+
var supportReplyEmailLimit = 254;
|
|
276
|
+
var supportScreenshotLimit = 3;
|
|
277
|
+
var supportScreenshotMaxBytes = 5 * 1024 * 1024;
|
|
278
|
+
var screenshotFormats = new Map([
|
|
279
|
+
[
|
|
280
|
+
"image/png",
|
|
281
|
+
{ extension: "png", signatures: [[0, [137, 80, 78, 71, 13, 10, 26, 10]]] }
|
|
282
|
+
],
|
|
283
|
+
["image/jpeg", { extension: "jpg", signatures: [[0, [255, 216, 255]]] }],
|
|
284
|
+
[
|
|
285
|
+
"image/webp",
|
|
286
|
+
{
|
|
287
|
+
extension: "webp",
|
|
288
|
+
signatures: [
|
|
289
|
+
[0, [82, 73, 70, 70]],
|
|
290
|
+
[8, [87, 69, 66, 80]]
|
|
291
|
+
]
|
|
292
|
+
}
|
|
293
|
+
]
|
|
294
|
+
]);
|
|
295
|
+
var screenshotAccept = Array.from(screenshotFormats.keys()).join(",");
|
|
296
|
+
var SupportMessage = Schema.Trim.check(Schema.isNonEmpty(), Schema.isMaxLength(supportMessageLimit)).annotate({ identifier: "SupportMessage" });
|
|
297
|
+
var SupportReplyEmail = Schema.Trim.check(Schema.isMaxLength(supportReplyEmailLimit), Schema.isPattern(/^[^\s@,<>]+@[^\s@,<>]+$/)).annotate({ identifier: "SupportReplyEmail" });
|
|
298
|
+
var SupportScreenshots = Schema.Array(Schema.File.check(Schema.makeFilter((file) => screenshotFormats.has(file.type) && file.size > 0 && file.size <= supportScreenshotMaxBytes))).check(Schema.isMaxLength(supportScreenshotLimit)).annotate({ identifier: "SupportScreenshots" });
|
|
299
|
+
var SupportRequestSchema = Schema.Struct({
|
|
300
|
+
message: SupportMessage,
|
|
301
|
+
replyEmail: Schema.optionalKey(SupportReplyEmail),
|
|
302
|
+
attachments: SupportScreenshots
|
|
303
|
+
}).annotate({ identifier: "SupportRequest" });
|
|
304
|
+
var SupportMultipartPayload = Schema.Struct({
|
|
305
|
+
message: SupportMessage,
|
|
306
|
+
replyEmail: Schema.optionalKey(SupportReplyEmail),
|
|
307
|
+
attachments: Schema.optionalKey(Multipart.FilesSchema.check(Schema.isMaxLength(supportScreenshotLimit)))
|
|
308
|
+
}).annotate({ identifier: "SupportMultipartPayload" }).pipe(HttpApiSchema.asMultipart({
|
|
309
|
+
maxParts: supportScreenshotLimit + 2,
|
|
310
|
+
maxFieldSize: 32 * 1024,
|
|
311
|
+
maxFileSize: supportScreenshotMaxBytes,
|
|
312
|
+
maxTotalSize: supportScreenshotLimit * supportScreenshotMaxBytes + 1024 * 1024
|
|
313
|
+
}));
|
|
314
|
+
|
|
315
|
+
class InvalidSupportScreenshot extends Schema.TaggedError()("InvalidSupportScreenshot", {}) {
|
|
316
|
+
}
|
|
317
|
+
var readSupportScreenshots = Effect.fn("Support.readScreenshots")(function* (files) {
|
|
318
|
+
const fs = yield* FileSystem.FileSystem;
|
|
319
|
+
return yield* Effect.forEach(files, (file, index) => Effect.gen(function* () {
|
|
320
|
+
const format = screenshotFormats.get(file.contentType);
|
|
321
|
+
if (!format)
|
|
322
|
+
return yield* new InvalidSupportScreenshot;
|
|
323
|
+
const content = yield* fs.readFile(file.path);
|
|
324
|
+
if (!format.signatures.every(([offset, signature]) => signature.every((byte, index) => content[offset + index] === byte))) {
|
|
325
|
+
return yield* new InvalidSupportScreenshot;
|
|
326
|
+
}
|
|
327
|
+
return {
|
|
328
|
+
content,
|
|
329
|
+
contentType: file.contentType,
|
|
330
|
+
filename: `screenshot-${index + 1}.${format.extension}`
|
|
331
|
+
};
|
|
332
|
+
}));
|
|
333
|
+
});
|
|
334
|
+
var labels = {
|
|
335
|
+
en: {
|
|
336
|
+
title: "Tell us how we can help",
|
|
337
|
+
description: "Share any details that will help us answer your question or understand what went wrong.",
|
|
338
|
+
placeholder: "I need help with…",
|
|
339
|
+
replyEmail: "Reply email",
|
|
340
|
+
attach: "Attach screenshots",
|
|
341
|
+
invalidAttachments: "Screenshots weren’t added. Choose up to 3 PNG, JPEG or WebP images, 5 MB each.",
|
|
342
|
+
removeAttachment: "Remove screenshot",
|
|
343
|
+
submit: "Send message",
|
|
344
|
+
pending: "Sending…",
|
|
345
|
+
success: "Your message was sent.",
|
|
346
|
+
close: "Close",
|
|
347
|
+
invalid: "Check your message and reply email if requested.",
|
|
348
|
+
failed: "Could not send your message. Try again."
|
|
349
|
+
},
|
|
350
|
+
fr: {
|
|
351
|
+
title: "Dites-nous comment nous pouvons vous aider",
|
|
352
|
+
description: "Donnez-nous les détails qui nous aideront à répondre à votre question ou à comprendre le problème.",
|
|
353
|
+
placeholder: "J’ai besoin d’aide pour…",
|
|
354
|
+
replyEmail: "Adresse courriel pour la réponse",
|
|
355
|
+
attach: "Joindre des captures d’écran",
|
|
356
|
+
invalidAttachments: "Les captures d’écran n’ont pas été ajoutées. Choisissez jusqu’à 3 images PNG, JPEG ou WebP de 5 Mo chacune.",
|
|
357
|
+
removeAttachment: "Retirer la capture d’écran",
|
|
358
|
+
submit: "Envoyer le message",
|
|
359
|
+
pending: "Envoi en cours…",
|
|
360
|
+
success: "Votre message a été envoyé.",
|
|
361
|
+
close: "Fermer",
|
|
362
|
+
invalid: "Vérifiez le message et, si elle est demandée, l’adresse courriel.",
|
|
363
|
+
failed: "Impossible d’envoyer votre message. Réessayez."
|
|
364
|
+
}
|
|
365
|
+
};
|
|
366
|
+
var SupportDialog = ({
|
|
367
|
+
locale: localeOverride,
|
|
368
|
+
messages,
|
|
369
|
+
trigger,
|
|
370
|
+
askForReplyEmail = false,
|
|
371
|
+
onSubmit
|
|
372
|
+
}) => {
|
|
373
|
+
const locale = useKrakstackLocale(localeOverride);
|
|
374
|
+
const language = locale.split("-")[0] ?? locale;
|
|
375
|
+
const copy = {
|
|
376
|
+
...language === "fr" ? labels.fr : labels.en,
|
|
377
|
+
...messages?.[language],
|
|
378
|
+
...messages?.[locale]
|
|
379
|
+
};
|
|
380
|
+
const id = useId();
|
|
381
|
+
const [open, setOpen] = useState(false);
|
|
382
|
+
const [attachments, setAttachments] = useState([]);
|
|
383
|
+
const [invalidAttachments, setInvalidAttachments] = useState(false);
|
|
384
|
+
const fileInput = useRef(null);
|
|
385
|
+
const [status, setStatus] = useState("idle");
|
|
386
|
+
const submitting = useRef(false);
|
|
387
|
+
const pending = status === "pending";
|
|
388
|
+
const handleOpenChange = (next, details) => {
|
|
389
|
+
if (submitting.current) {
|
|
390
|
+
details.cancel();
|
|
391
|
+
return;
|
|
392
|
+
}
|
|
393
|
+
if (next) {
|
|
394
|
+
setAttachments([]);
|
|
395
|
+
setInvalidAttachments(false);
|
|
396
|
+
setStatus("idle");
|
|
397
|
+
}
|
|
398
|
+
setOpen(next);
|
|
399
|
+
};
|
|
400
|
+
const addAttachments = (files) => {
|
|
401
|
+
if (submitting.current || !files.length)
|
|
402
|
+
return;
|
|
403
|
+
const result = Schema.decodeUnknownResult(SupportScreenshots)([
|
|
404
|
+
...attachments,
|
|
405
|
+
...files
|
|
406
|
+
]);
|
|
407
|
+
setInvalidAttachments(Result.isFailure(result));
|
|
408
|
+
if (Result.isSuccess(result))
|
|
409
|
+
setAttachments(result.success);
|
|
410
|
+
};
|
|
411
|
+
const pasteScreenshot = (event) => {
|
|
412
|
+
const files = Array.from(event.clipboardData.files).filter((file) => file.type.startsWith("image/"));
|
|
413
|
+
if (!files.length)
|
|
414
|
+
return;
|
|
415
|
+
event.preventDefault();
|
|
416
|
+
addAttachments(files);
|
|
417
|
+
};
|
|
418
|
+
const submit = async (event) => {
|
|
419
|
+
event.preventDefault();
|
|
420
|
+
if (submitting.current)
|
|
421
|
+
return;
|
|
422
|
+
const form = new FormData(event.currentTarget);
|
|
423
|
+
const request = Schema.decodeUnknownResult(SupportRequestSchema)({
|
|
424
|
+
message: form.get("message"),
|
|
425
|
+
...askForReplyEmail ? { replyEmail: form.get("replyEmail") } : {},
|
|
426
|
+
attachments
|
|
427
|
+
});
|
|
428
|
+
if (Result.isFailure(request)) {
|
|
429
|
+
setStatus("invalid");
|
|
430
|
+
return;
|
|
431
|
+
}
|
|
432
|
+
submitting.current = true;
|
|
433
|
+
setStatus("pending");
|
|
434
|
+
try {
|
|
435
|
+
await onSubmit(request.success);
|
|
436
|
+
setAttachments([]);
|
|
437
|
+
setInvalidAttachments(false);
|
|
438
|
+
setStatus("success");
|
|
439
|
+
} catch {
|
|
440
|
+
setStatus("failed");
|
|
441
|
+
} finally {
|
|
442
|
+
submitting.current = false;
|
|
443
|
+
}
|
|
444
|
+
};
|
|
445
|
+
return /* @__PURE__ */ jsxs2(Dialog, {
|
|
446
|
+
open,
|
|
447
|
+
onOpenChange: handleOpenChange,
|
|
448
|
+
children: [
|
|
449
|
+
/* @__PURE__ */ jsx7(DialogTrigger, {
|
|
450
|
+
render: trigger ?? /* @__PURE__ */ jsx7(Button, {
|
|
451
|
+
variant: "outline",
|
|
452
|
+
children: copy.title
|
|
453
|
+
})
|
|
454
|
+
}),
|
|
455
|
+
/* @__PURE__ */ jsxs2(DialogPortal, {
|
|
456
|
+
children: [
|
|
457
|
+
/* @__PURE__ */ jsx7(DialogOverlay, {}),
|
|
458
|
+
/* @__PURE__ */ jsxs2(DialogPrimitive2.Popup, {
|
|
459
|
+
className: "bg-popover text-popover-foreground ring-foreground/10 fixed top-1/2 left-1/2 z-50 grid max-h-[calc(100dvh-2rem)] w-[calc(100%-2rem)] max-w-lg -translate-x-1/2 -translate-y-1/2 gap-4 overflow-auto rounded-xl p-6 ring-1 outline-none",
|
|
460
|
+
children: [
|
|
461
|
+
/* @__PURE__ */ jsxs2(DialogHeader, {
|
|
462
|
+
className: status === "success" ? undefined : "pe-8",
|
|
463
|
+
children: [
|
|
464
|
+
/* @__PURE__ */ jsx7(DialogTitle, {
|
|
465
|
+
children: /* @__PURE__ */ jsx7("span", {
|
|
466
|
+
id: `${id}-title`,
|
|
467
|
+
children: copy.title
|
|
468
|
+
})
|
|
469
|
+
}),
|
|
470
|
+
copy.description && /* @__PURE__ */ jsx7(DialogDescription, {
|
|
471
|
+
children: copy.description
|
|
472
|
+
})
|
|
473
|
+
]
|
|
474
|
+
}),
|
|
475
|
+
status !== "success" && /* @__PURE__ */ jsx7(DialogClose, {
|
|
476
|
+
render: /* @__PURE__ */ jsx7(Button, {
|
|
477
|
+
className: "absolute end-4 top-4",
|
|
478
|
+
variant: "ghost",
|
|
479
|
+
size: "icon-sm",
|
|
480
|
+
"aria-label": copy.close,
|
|
481
|
+
disabled: pending
|
|
482
|
+
}),
|
|
483
|
+
children: /* @__PURE__ */ jsx7(XIcon2, {
|
|
484
|
+
"aria-hidden": "true"
|
|
485
|
+
})
|
|
486
|
+
}),
|
|
487
|
+
status === "success" ? /* @__PURE__ */ jsxs2(Fragment, {
|
|
488
|
+
children: [
|
|
489
|
+
/* @__PURE__ */ jsx7("p", {
|
|
490
|
+
role: "status",
|
|
491
|
+
className: "text-sm",
|
|
492
|
+
children: copy.success
|
|
493
|
+
}),
|
|
494
|
+
/* @__PURE__ */ jsx7(DialogFooter, {
|
|
495
|
+
children: /* @__PURE__ */ jsx7(DialogClose, {
|
|
496
|
+
render: /* @__PURE__ */ jsx7(Button, {
|
|
497
|
+
autoFocus: true
|
|
498
|
+
}),
|
|
499
|
+
children: copy.close
|
|
500
|
+
})
|
|
501
|
+
})
|
|
502
|
+
]
|
|
503
|
+
}) : /* @__PURE__ */ jsxs2("form", {
|
|
504
|
+
className: "grid gap-4",
|
|
505
|
+
onSubmit: submit,
|
|
506
|
+
"aria-busy": pending,
|
|
507
|
+
children: [
|
|
508
|
+
/* @__PURE__ */ jsxs2("fieldset", {
|
|
509
|
+
disabled: pending,
|
|
510
|
+
className: "grid min-w-0 gap-4",
|
|
511
|
+
children: [
|
|
512
|
+
askForReplyEmail && /* @__PURE__ */ jsxs2("div", {
|
|
513
|
+
className: "grid gap-2",
|
|
514
|
+
children: [
|
|
515
|
+
/* @__PURE__ */ jsx7(Label, {
|
|
516
|
+
htmlFor: `${id}-email`,
|
|
517
|
+
children: copy.replyEmail
|
|
518
|
+
}),
|
|
519
|
+
/* @__PURE__ */ jsx7(Input, {
|
|
520
|
+
id: `${id}-email`,
|
|
521
|
+
name: "replyEmail",
|
|
522
|
+
type: "email",
|
|
523
|
+
autoComplete: "email",
|
|
524
|
+
maxLength: supportReplyEmailLimit,
|
|
525
|
+
required: true
|
|
526
|
+
})
|
|
527
|
+
]
|
|
528
|
+
}),
|
|
529
|
+
/* @__PURE__ */ jsxs2("div", {
|
|
530
|
+
className: "grid gap-2",
|
|
531
|
+
children: [
|
|
532
|
+
/* @__PURE__ */ jsx7(Textarea, {
|
|
533
|
+
id: `${id}-message`,
|
|
534
|
+
"aria-labelledby": `${id}-title`,
|
|
535
|
+
name: "message",
|
|
536
|
+
rows: 8,
|
|
537
|
+
className: "min-h-44",
|
|
538
|
+
placeholder: copy.placeholder,
|
|
539
|
+
required: true,
|
|
540
|
+
maxLength: supportMessageLimit,
|
|
541
|
+
onPaste: pasteScreenshot
|
|
542
|
+
}),
|
|
543
|
+
/* @__PURE__ */ jsx7("input", {
|
|
544
|
+
ref: fileInput,
|
|
545
|
+
type: "file",
|
|
546
|
+
"aria-label": copy.attach,
|
|
547
|
+
accept: screenshotAccept,
|
|
548
|
+
multiple: true,
|
|
549
|
+
hidden: true,
|
|
550
|
+
onChange: (event) => {
|
|
551
|
+
addAttachments(Array.from(event.currentTarget.files ?? []));
|
|
552
|
+
event.currentTarget.value = "";
|
|
553
|
+
}
|
|
554
|
+
}),
|
|
555
|
+
attachments.length > 0 && /* @__PURE__ */ jsx7("ul", {
|
|
556
|
+
className: "flex min-w-0 flex-wrap gap-2",
|
|
557
|
+
children: attachments.map((file, index) => /* @__PURE__ */ jsx7("li", {
|
|
558
|
+
className: "max-w-full min-w-0",
|
|
559
|
+
children: /* @__PURE__ */ jsxs2(Attachment, {
|
|
560
|
+
size: "xs",
|
|
561
|
+
className: "min-w-0 flex-nowrap",
|
|
562
|
+
children: [
|
|
563
|
+
/* @__PURE__ */ jsxs2(AttachmentContent, {
|
|
564
|
+
className: "flex items-center gap-1.5",
|
|
565
|
+
children: [
|
|
566
|
+
/* @__PURE__ */ jsx7(AttachmentMedia, {
|
|
567
|
+
className: "shrink-0",
|
|
568
|
+
children: /* @__PURE__ */ jsx7(ImageIcon, {
|
|
569
|
+
"aria-hidden": "true"
|
|
570
|
+
})
|
|
571
|
+
}),
|
|
572
|
+
/* @__PURE__ */ jsx7(AttachmentTitle, {
|
|
573
|
+
title: file.name,
|
|
574
|
+
children: file.name
|
|
575
|
+
})
|
|
576
|
+
]
|
|
577
|
+
}),
|
|
578
|
+
/* @__PURE__ */ jsx7(AttachmentActions, {
|
|
579
|
+
className: "pe-1",
|
|
580
|
+
children: /* @__PURE__ */ jsx7(AttachmentAction, {
|
|
581
|
+
type: "button",
|
|
582
|
+
"aria-label": `${copy.removeAttachment}: ${file.name}`,
|
|
583
|
+
onClick: () => {
|
|
584
|
+
setAttachments(attachments.filter((_, position) => position !== index));
|
|
585
|
+
setInvalidAttachments(false);
|
|
586
|
+
},
|
|
587
|
+
children: /* @__PURE__ */ jsx7(XIcon2, {
|
|
588
|
+
"aria-hidden": "true"
|
|
589
|
+
})
|
|
590
|
+
})
|
|
591
|
+
})
|
|
592
|
+
]
|
|
593
|
+
})
|
|
594
|
+
}, index))
|
|
595
|
+
}),
|
|
596
|
+
invalidAttachments && /* @__PURE__ */ jsx7("p", {
|
|
597
|
+
role: "alert",
|
|
598
|
+
className: "text-destructive text-sm",
|
|
599
|
+
children: copy.invalidAttachments
|
|
600
|
+
})
|
|
601
|
+
]
|
|
602
|
+
})
|
|
603
|
+
]
|
|
604
|
+
}),
|
|
605
|
+
(status === "failed" || status === "invalid") && /* @__PURE__ */ jsx7("p", {
|
|
606
|
+
role: "alert",
|
|
607
|
+
className: "text-destructive text-sm",
|
|
608
|
+
children: status === "invalid" ? copy.invalid : copy.failed
|
|
609
|
+
}),
|
|
610
|
+
/* @__PURE__ */ jsxs2("div", {
|
|
611
|
+
className: "flex flex-wrap items-center justify-between gap-2",
|
|
612
|
+
children: [
|
|
613
|
+
/* @__PURE__ */ jsxs2(Button, {
|
|
614
|
+
type: "button",
|
|
615
|
+
variant: "ghost",
|
|
616
|
+
size: "sm",
|
|
617
|
+
disabled: pending,
|
|
618
|
+
onClick: () => fileInput.current?.click(),
|
|
619
|
+
children: [
|
|
620
|
+
/* @__PURE__ */ jsx7(Paperclip, {
|
|
621
|
+
"aria-hidden": "true"
|
|
622
|
+
}),
|
|
623
|
+
copy.attach
|
|
624
|
+
]
|
|
625
|
+
}),
|
|
626
|
+
/* @__PURE__ */ jsx7(Button, {
|
|
627
|
+
type: "submit",
|
|
628
|
+
size: "sm",
|
|
629
|
+
className: "ms-auto",
|
|
630
|
+
disabled: pending,
|
|
631
|
+
children: pending ? copy.pending : copy.submit
|
|
632
|
+
})
|
|
633
|
+
]
|
|
634
|
+
})
|
|
635
|
+
]
|
|
636
|
+
})
|
|
637
|
+
]
|
|
638
|
+
})
|
|
639
|
+
]
|
|
640
|
+
})
|
|
641
|
+
]
|
|
642
|
+
});
|
|
643
|
+
};
|
|
644
|
+
export {
|
|
645
|
+
InvalidSupportScreenshot,
|
|
646
|
+
SupportDialog,
|
|
647
|
+
SupportMultipartPayload,
|
|
648
|
+
SupportReplyEmail,
|
|
649
|
+
SupportRequestSchema,
|
|
650
|
+
readSupportScreenshots
|
|
651
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@krak-stack/registry",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.13",
|
|
4
4
|
"description": "Tree-shakable KrakStack components and Effect services.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -17,6 +17,10 @@
|
|
|
17
17
|
"type": "module",
|
|
18
18
|
"sideEffects": false,
|
|
19
19
|
"exports": {
|
|
20
|
+
"./support-dialog": {
|
|
21
|
+
"types": "./dist/components/support-dialog.d.ts",
|
|
22
|
+
"import": "./dist/components/support-dialog.js"
|
|
23
|
+
},
|
|
20
24
|
"./rich-text-editor": {
|
|
21
25
|
"types": "./dist/components/ui/rich-text-editor.d.ts",
|
|
22
26
|
"import": "./dist/components/ui/rich-text-editor.js"
|