@krak-stack/registry 0.10.19 → 0.10.20
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 +25 -0
- package/README.md +18 -0
- package/dist/components/ui/code-block.js +7 -7
- package/dist/components/ui/copy-button.js +7 -7
- package/dist/components/ui/copy-value.js +7 -7
- package/dist/components/ui/data-table.d.ts +3 -3
- package/dist/components/ui/data-table.js +23 -17
- package/dist/components/ui/editing-locale-switcher.js +7 -7
- package/dist/components/ui/effect-form.js +8 -8
- package/dist/components/ui/email-composer.js +871 -0
- package/dist/components/ui/email-editor.d.ts +3 -1
- package/dist/components/ui/email-editor.js +294 -471
- package/dist/components/ui/error-component.js +7 -7
- package/dist/components/ui/form.d.ts +7 -7
- package/dist/components/ui/form.js +18 -14
- package/dist/components/ui/icon-input.js +1 -1
- package/dist/components/ui/map-menu.d.ts +1 -1
- package/dist/components/ui/map-menu.js +183 -60
- package/dist/components/ui/pagination.js +7 -7
- package/dist/components/ui/phone-number-input.js +1 -1
- package/dist/components/ui/rich-text-editor.d.ts +15 -13
- package/dist/components/ui/rich-text-editor.js +280 -661
- package/dist/components/ui/select-with-custom-input.js +7 -7
- package/dist/components/ui/select.js +159 -0
- package/dist/components/ui/timezone-select.js +1 -1
- package/dist/components/ui/virtualized-combobox.js +1 -1
- package/dist/lib/docs.js +7 -7
- package/dist/lib/email-composer/index.js +110 -0
- package/dist/lib/email-composer/schema.js +13 -0
- package/dist/lib/email-document/legacy-rich-text/editor.d.ts +70 -0
- package/dist/lib/email-document/legacy-rich-text/schema.d.ts +65 -0
- package/dist/lib/email-document/legacy-rich-text/tiptap.d.ts +39 -0
- package/dist/lib/email-document/model.d.ts +1 -1
- package/dist/lib/email-document/model.js +2 -2
- package/dist/lib/email-document/render.js +2 -2
- package/dist/lib/email-document/schema.js +1 -1
- package/dist/lib/rich-text/model.js +79 -111
- package/dist/lib/rich-text/schema.d.ts +5 -55
- package/dist/lib/rich-text/schema.js +17 -36
- package/dist/lib/rich-text/tiptap.d.ts +12 -0
- package/dist/services/agent/client/index.js +7 -7
- package/dist/services/events/client/audit-log-table.js +23 -17
- package/dist/services/webhooks/client/delivery-table.js +30 -24
- package/package.json +24 -1
- package/dist/lib/rich-text/dom.d.ts +0 -40
- /package/dist/lib/{rich-text → email-document/legacy-rich-text}/model.d.ts +0 -0
|
@@ -0,0 +1,871 @@
|
|
|
1
|
+
// ../../src/components/ui/email-composer.tsx
|
|
2
|
+
import { Effect as Effect2 } from "effect";
|
|
3
|
+
import { useEffect as useEffect2, useEffectEvent as useEffectEvent2, useState as useState2 } from "react";
|
|
4
|
+
|
|
5
|
+
// ../../src/components/ui/rich-text-editor.tsx
|
|
6
|
+
import { Schema as Schema3 } from "effect";
|
|
7
|
+
import { EditorContent, useEditor } from "@tiptap/react";
|
|
8
|
+
import { EditorState } from "@tiptap/pm/state";
|
|
9
|
+
import { closeHistory } from "@tiptap/pm/history";
|
|
10
|
+
import { renderToReactElement } from "@tiptap/static-renderer/pm/react";
|
|
11
|
+
import {
|
|
12
|
+
useEffect,
|
|
13
|
+
useEffectEvent,
|
|
14
|
+
useId,
|
|
15
|
+
useState
|
|
16
|
+
} from "react";
|
|
17
|
+
import {
|
|
18
|
+
Bold,
|
|
19
|
+
Italic,
|
|
20
|
+
Underline,
|
|
21
|
+
Undo2,
|
|
22
|
+
Redo2,
|
|
23
|
+
Link2,
|
|
24
|
+
Unlink,
|
|
25
|
+
Braces
|
|
26
|
+
} from "lucide-react";
|
|
27
|
+
|
|
28
|
+
// ../../src/components/ui/button.tsx
|
|
29
|
+
import { Button as ButtonPrimitive } from "@base-ui/react/button";
|
|
30
|
+
import { cva } from "class-variance-authority";
|
|
31
|
+
|
|
32
|
+
// ../../src/lib/utils.ts
|
|
33
|
+
import { cn } from "cn";
|
|
34
|
+
|
|
35
|
+
// ../../src/components/ui/button.tsx
|
|
36
|
+
import { jsx } from "react/jsx-runtime";
|
|
37
|
+
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", {
|
|
38
|
+
variants: {
|
|
39
|
+
variant: {
|
|
40
|
+
default: "bg-primary text-primary-foreground hover:bg-primary/80",
|
|
41
|
+
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",
|
|
42
|
+
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",
|
|
43
|
+
ghost: "hover:bg-muted hover:text-foreground aria-expanded:bg-muted aria-expanded:text-foreground dark:hover:bg-muted/50",
|
|
44
|
+
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",
|
|
45
|
+
link: "text-primary underline-offset-4 hover:underline"
|
|
46
|
+
},
|
|
47
|
+
size: {
|
|
48
|
+
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",
|
|
49
|
+
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",
|
|
50
|
+
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",
|
|
51
|
+
lg: "h-10 gap-1.5 px-2.5 has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2",
|
|
52
|
+
icon: "size-9",
|
|
53
|
+
"icon-xs": "size-6 rounded-[min(var(--radius-md),8px)] in-data-[slot=button-group]:rounded-md [&_svg:not([class*='size-'])]:size-3",
|
|
54
|
+
"icon-sm": "size-8 rounded-[min(var(--radius-md),10px)] in-data-[slot=button-group]:rounded-md",
|
|
55
|
+
"icon-lg": "size-10"
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
defaultVariants: {
|
|
59
|
+
variant: "default",
|
|
60
|
+
size: "default"
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
function Button({
|
|
64
|
+
className,
|
|
65
|
+
variant = "default",
|
|
66
|
+
size = "default",
|
|
67
|
+
...props
|
|
68
|
+
}) {
|
|
69
|
+
return /* @__PURE__ */ jsx(ButtonPrimitive, {
|
|
70
|
+
"data-slot": "button",
|
|
71
|
+
className: cn(buttonVariants({ variant, size, className })),
|
|
72
|
+
...props
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// ../../src/components/ui/input.tsx
|
|
77
|
+
import { Input as InputPrimitive } from "@base-ui/react/input";
|
|
78
|
+
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
79
|
+
function Input({ className, type, ...props }) {
|
|
80
|
+
return /* @__PURE__ */ jsx2(InputPrimitive, {
|
|
81
|
+
type,
|
|
82
|
+
"data-slot": "input",
|
|
83
|
+
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),
|
|
84
|
+
...props
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// ../../src/components/ui/select.tsx
|
|
89
|
+
import { Select as SelectPrimitive } from "@base-ui/react/select";
|
|
90
|
+
import { ChevronDownIcon, CheckIcon, ChevronUpIcon } from "lucide-react";
|
|
91
|
+
import { jsx as jsx3, jsxs } from "react/jsx-runtime";
|
|
92
|
+
"use client";
|
|
93
|
+
var Select = SelectPrimitive.Root;
|
|
94
|
+
function SelectValue({ className, ...props }) {
|
|
95
|
+
return /* @__PURE__ */ jsx3(SelectPrimitive.Value, {
|
|
96
|
+
"data-slot": "select-value",
|
|
97
|
+
className: cn("flex flex-1 text-left", className),
|
|
98
|
+
...props
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
function SelectTrigger({
|
|
102
|
+
className,
|
|
103
|
+
size = "default",
|
|
104
|
+
children,
|
|
105
|
+
...props
|
|
106
|
+
}) {
|
|
107
|
+
return /* @__PURE__ */ jsxs(SelectPrimitive.Trigger, {
|
|
108
|
+
"data-slot": "select-trigger",
|
|
109
|
+
"data-size": size,
|
|
110
|
+
className: cn("border-input focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 data-placeholder:text-muted-foreground dark:bg-input/30 dark:hover:bg-input/50 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 flex w-fit items-center justify-between gap-1.5 rounded-md border bg-transparent py-2 pr-2 pl-2.5 text-sm whitespace-nowrap shadow-xs transition-[color,box-shadow] outline-none focus-visible:ring-3 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:ring-3 data-[size=default]:h-9 data-[size=sm]:h-8 *:data-[slot=select-value]:line-clamp-1 *:data-[slot=select-value]:flex *:data-[slot=select-value]:items-center *:data-[slot=select-value]:gap-1.5 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4", className),
|
|
111
|
+
...props,
|
|
112
|
+
children: [
|
|
113
|
+
children,
|
|
114
|
+
/* @__PURE__ */ jsx3(SelectPrimitive.Icon, {
|
|
115
|
+
render: /* @__PURE__ */ jsx3(ChevronDownIcon, {
|
|
116
|
+
className: "text-muted-foreground pointer-events-none size-4"
|
|
117
|
+
})
|
|
118
|
+
})
|
|
119
|
+
]
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
function SelectContent({
|
|
123
|
+
className,
|
|
124
|
+
children,
|
|
125
|
+
side = "bottom",
|
|
126
|
+
sideOffset = 4,
|
|
127
|
+
align = "start",
|
|
128
|
+
alignOffset = 0,
|
|
129
|
+
alignItemWithTrigger = false,
|
|
130
|
+
...props
|
|
131
|
+
}) {
|
|
132
|
+
return /* @__PURE__ */ jsx3(SelectPrimitive.Portal, {
|
|
133
|
+
children: /* @__PURE__ */ jsx3(SelectPrimitive.Positioner, {
|
|
134
|
+
side,
|
|
135
|
+
sideOffset,
|
|
136
|
+
align,
|
|
137
|
+
alignOffset,
|
|
138
|
+
alignItemWithTrigger,
|
|
139
|
+
className: "isolate z-50",
|
|
140
|
+
children: /* @__PURE__ */ jsxs(SelectPrimitive.Popup, {
|
|
141
|
+
"data-slot": "select-content",
|
|
142
|
+
"data-align-trigger": alignItemWithTrigger,
|
|
143
|
+
className: cn("bg-popover text-popover-foreground ring-foreground/10 data-[side=bottom]:slide-in-from-top-2 data-[side=inline-end]:slide-in-from-left-2 data-[side=inline-start]:slide-in-from-right-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95 relative isolate z-50 max-h-(--available-height) w-(--anchor-width) max-w-(--available-width) min-w-0 origin-(--transform-origin) overflow-x-hidden overflow-y-auto rounded-md shadow-md ring-1 duration-100 data-[align-trigger=true]:animate-none", className),
|
|
144
|
+
...props,
|
|
145
|
+
children: [
|
|
146
|
+
/* @__PURE__ */ jsx3(SelectScrollUpButton, {}),
|
|
147
|
+
/* @__PURE__ */ jsx3(SelectPrimitive.List, {
|
|
148
|
+
children
|
|
149
|
+
}),
|
|
150
|
+
/* @__PURE__ */ jsx3(SelectScrollDownButton, {})
|
|
151
|
+
]
|
|
152
|
+
})
|
|
153
|
+
})
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
function SelectItem({
|
|
157
|
+
className,
|
|
158
|
+
children,
|
|
159
|
+
...props
|
|
160
|
+
}) {
|
|
161
|
+
return /* @__PURE__ */ jsxs(SelectPrimitive.Item, {
|
|
162
|
+
"data-slot": "select-item",
|
|
163
|
+
className: cn("focus:bg-accent focus:text-accent-foreground not-data-[variant=destructive]:focus:**:text-accent-foreground relative flex w-full cursor-default items-center gap-2 rounded-sm py-1.5 pr-8 pl-2 text-sm outline-hidden select-none data-disabled:pointer-events-none data-disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 *:[span]:last:flex *:[span]:last:items-center *:[span]:last:gap-2", className),
|
|
164
|
+
...props,
|
|
165
|
+
children: [
|
|
166
|
+
/* @__PURE__ */ jsx3(SelectPrimitive.ItemText, {
|
|
167
|
+
className: "flex flex-1 shrink-0 gap-2 whitespace-nowrap",
|
|
168
|
+
children
|
|
169
|
+
}),
|
|
170
|
+
/* @__PURE__ */ jsx3(SelectPrimitive.ItemIndicator, {
|
|
171
|
+
render: /* @__PURE__ */ jsx3("span", {
|
|
172
|
+
className: "pointer-events-none absolute right-2 flex size-4 items-center justify-center"
|
|
173
|
+
}),
|
|
174
|
+
children: /* @__PURE__ */ jsx3(CheckIcon, {
|
|
175
|
+
className: "pointer-events-none"
|
|
176
|
+
})
|
|
177
|
+
})
|
|
178
|
+
]
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
function SelectScrollUpButton({
|
|
182
|
+
className,
|
|
183
|
+
...props
|
|
184
|
+
}) {
|
|
185
|
+
return /* @__PURE__ */ jsx3(SelectPrimitive.ScrollUpArrow, {
|
|
186
|
+
"data-slot": "select-scroll-up-button",
|
|
187
|
+
className: cn("bg-popover top-0 z-10 flex w-full cursor-default items-center justify-center py-1 [&_svg:not([class*='size-'])]:size-4", className),
|
|
188
|
+
...props,
|
|
189
|
+
children: /* @__PURE__ */ jsx3(ChevronUpIcon, {})
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
function SelectScrollDownButton({
|
|
193
|
+
className,
|
|
194
|
+
...props
|
|
195
|
+
}) {
|
|
196
|
+
return /* @__PURE__ */ jsx3(SelectPrimitive.ScrollDownArrow, {
|
|
197
|
+
"data-slot": "select-scroll-down-button",
|
|
198
|
+
className: cn("bg-popover bottom-0 z-10 flex w-full cursor-default items-center justify-center py-1 [&_svg:not([class*='size-'])]:size-4", className),
|
|
199
|
+
...props,
|
|
200
|
+
children: /* @__PURE__ */ jsx3(ChevronDownIcon, {})
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// ../../src/components/ui/dropdown-menu.tsx
|
|
205
|
+
import { Menu as MenuPrimitive } from "@base-ui/react/menu";
|
|
206
|
+
import { ChevronRightIcon, CheckIcon as CheckIcon2 } from "lucide-react";
|
|
207
|
+
import { jsx as jsx4, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
208
|
+
function DropdownMenu({ ...props }) {
|
|
209
|
+
return /* @__PURE__ */ jsx4(MenuPrimitive.Root, {
|
|
210
|
+
"data-slot": "dropdown-menu",
|
|
211
|
+
...props
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
function DropdownMenuTrigger({ ...props }) {
|
|
215
|
+
return /* @__PURE__ */ jsx4(MenuPrimitive.Trigger, {
|
|
216
|
+
"data-slot": "dropdown-menu-trigger",
|
|
217
|
+
...props
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
function DropdownMenuContent({
|
|
221
|
+
align = "start",
|
|
222
|
+
alignOffset = 0,
|
|
223
|
+
side = "bottom",
|
|
224
|
+
sideOffset = 4,
|
|
225
|
+
className,
|
|
226
|
+
...props
|
|
227
|
+
}) {
|
|
228
|
+
return /* @__PURE__ */ jsx4(MenuPrimitive.Portal, {
|
|
229
|
+
children: /* @__PURE__ */ jsx4(MenuPrimitive.Positioner, {
|
|
230
|
+
className: "isolate z-50 outline-none",
|
|
231
|
+
align,
|
|
232
|
+
alignOffset,
|
|
233
|
+
side,
|
|
234
|
+
sideOffset,
|
|
235
|
+
children: /* @__PURE__ */ jsx4(MenuPrimitive.Popup, {
|
|
236
|
+
"data-slot": "dropdown-menu-content",
|
|
237
|
+
className: cn("z-50 max-h-(--available-height) w-(--anchor-width) min-w-32 origin-(--transform-origin) overflow-x-hidden overflow-y-auto rounded-md bg-popover p-1 text-popover-foreground shadow-md ring-1 ring-foreground/10 duration-100 outline-none data-[side=bottom]:slide-in-from-top-2 data-[side=inline-end]:slide-in-from-left-2 data-[side=inline-start]:slide-in-from-right-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:overflow-hidden data-closed:fade-out-0 data-closed:zoom-out-95", className),
|
|
238
|
+
...props
|
|
239
|
+
})
|
|
240
|
+
})
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
function DropdownMenuItem({
|
|
244
|
+
className,
|
|
245
|
+
inset,
|
|
246
|
+
variant = "default",
|
|
247
|
+
...props
|
|
248
|
+
}) {
|
|
249
|
+
return /* @__PURE__ */ jsx4(MenuPrimitive.Item, {
|
|
250
|
+
"data-slot": "dropdown-menu-item",
|
|
251
|
+
"data-inset": inset,
|
|
252
|
+
"data-variant": variant,
|
|
253
|
+
className: cn("group/dropdown-menu-item relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground not-data-[variant=destructive]:focus:**:text-accent-foreground data-inset:pl-8 data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 data-[variant=destructive]:focus:text-destructive dark:data-[variant=destructive]:focus:bg-destructive/20 data-disabled:pointer-events-none data-disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 data-[variant=destructive]:*:[svg]:text-destructive", className),
|
|
254
|
+
...props
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
// ../../src/components/ui/rich-text-editor.tsx
|
|
259
|
+
import { useKrakstackLocale } from "@krak-stack/registry/krakstack-provider";
|
|
260
|
+
|
|
261
|
+
// ../../src/lib/rich-text/schema.ts
|
|
262
|
+
import { Schema } from "effect";
|
|
263
|
+
var RichTextLink = Schema.String.check(Schema.isMaxLength(2000), Schema.makeFilter((value) => {
|
|
264
|
+
if (/[\s\p{Cc}\\{}]/u.test(value))
|
|
265
|
+
return false;
|
|
266
|
+
const url = URL.parse(value);
|
|
267
|
+
return url !== null && ["https:", "mailto:"].includes(url.protocol) && !url.username && !url.password;
|
|
268
|
+
})).annotate({ identifier: "RichTextLink" });
|
|
269
|
+
var attributes = Schema.Record(Schema.String, Schema.Json);
|
|
270
|
+
var variableKey = Schema.String.check(Schema.isPattern(/^[a-zA-Z][a-zA-Z0-9_.]{0,79}$/));
|
|
271
|
+
var mark = Schema.Struct({
|
|
272
|
+
type: Schema.String,
|
|
273
|
+
attrs: Schema.optional(attributes)
|
|
274
|
+
}).check(Schema.makeFilter((value) => value.type !== "link" || Schema.is(RichTextLink)(value.attrs?.href)));
|
|
275
|
+
var TiptapNode = Schema.Struct({
|
|
276
|
+
type: Schema.String,
|
|
277
|
+
attrs: Schema.optional(attributes),
|
|
278
|
+
content: Schema.optional(Schema.mutable(Schema.Array(Schema.suspend(() => TiptapNode)))),
|
|
279
|
+
marks: Schema.optional(Schema.mutable(Schema.Array(mark))),
|
|
280
|
+
text: Schema.optional(Schema.String)
|
|
281
|
+
}).check(Schema.makeFilter((node) => node.type !== "mention" || Schema.is(variableKey)(node.attrs?.id))).annotate({ identifier: "TiptapNode" });
|
|
282
|
+
var RichTextDocument = TiptapNode.check(Schema.makeFilter((node) => node.type === "doc")).annotate({ identifier: "TiptapDocument" });
|
|
283
|
+
var RichTextVariable = Schema.Struct({
|
|
284
|
+
key: variableKey,
|
|
285
|
+
label: Schema.String,
|
|
286
|
+
type: Schema.Literals(["text", "url"]),
|
|
287
|
+
sample: Schema.String
|
|
288
|
+
}).annotate({ identifier: "RichTextVariable" });
|
|
289
|
+
|
|
290
|
+
// ../../src/lib/rich-text/tiptap.ts
|
|
291
|
+
import { Extension } from "@tiptap/core";
|
|
292
|
+
import Mention from "@tiptap/extension-mention";
|
|
293
|
+
import StarterKit from "@tiptap/starter-kit";
|
|
294
|
+
import { Plugin } from "@tiptap/pm/state";
|
|
295
|
+
import { Schema as Schema2 } from "effect";
|
|
296
|
+
var richTextMention = (variables = () => []) => Mention.configure({
|
|
297
|
+
deleteTriggerWithBackspace: true,
|
|
298
|
+
HTMLAttributes: {
|
|
299
|
+
class: "rounded bg-primary/10 px-1 font-mono text-primary",
|
|
300
|
+
contenteditable: "false"
|
|
301
|
+
},
|
|
302
|
+
renderText: ({ node }) => `{{${node.attrs.id}}}`,
|
|
303
|
+
renderHTML: ({ node }) => {
|
|
304
|
+
const id = Schema2.decodeUnknownSync(RichTextVariable.fields.key)(node.attrs.id);
|
|
305
|
+
const label = variables().find((variable) => variable.key === id)?.label ?? node.attrs.label ?? id;
|
|
306
|
+
return [
|
|
307
|
+
"span",
|
|
308
|
+
{
|
|
309
|
+
"data-type": "mention",
|
|
310
|
+
"data-id": id,
|
|
311
|
+
contenteditable: "false",
|
|
312
|
+
class: "rounded bg-primary/10 px-1 font-mono text-primary"
|
|
313
|
+
},
|
|
314
|
+
`{{${label}}}`
|
|
315
|
+
];
|
|
316
|
+
},
|
|
317
|
+
suggestion: { items: () => [] }
|
|
318
|
+
});
|
|
319
|
+
var richTextExtensions = ({
|
|
320
|
+
variables = () => []
|
|
321
|
+
} = {}) => [
|
|
322
|
+
StarterKit.configure({
|
|
323
|
+
link: {
|
|
324
|
+
openOnClick: false,
|
|
325
|
+
autolink: false,
|
|
326
|
+
linkOnPaste: false,
|
|
327
|
+
isAllowedUri: (url) => Schema2.is(RichTextLink)(url)
|
|
328
|
+
},
|
|
329
|
+
undoRedo: { depth: 100 },
|
|
330
|
+
heading: { levels: [1, 2, 3] }
|
|
331
|
+
}),
|
|
332
|
+
richTextMention(variables)
|
|
333
|
+
];
|
|
334
|
+
var richTextValidation = ({
|
|
335
|
+
maxLength,
|
|
336
|
+
onInvalid
|
|
337
|
+
}) => Extension.create({
|
|
338
|
+
name: "richTextValidation",
|
|
339
|
+
addProseMirrorPlugins: () => [
|
|
340
|
+
new Plugin({
|
|
341
|
+
filterTransaction: (transaction) => {
|
|
342
|
+
if (!transaction.docChanged)
|
|
343
|
+
return true;
|
|
344
|
+
const limit = maxLength();
|
|
345
|
+
const text = transaction.doc.textBetween(0, transaction.doc.content.size, `
|
|
346
|
+
`, (node) => node.type.name === "mention" ? `{{${node.attrs.id}}}` : "");
|
|
347
|
+
const valid = Schema2.is(RichTextDocument)(transaction.doc.toJSON()) && (limit === undefined || text.length <= limit);
|
|
348
|
+
onInvalid(!valid);
|
|
349
|
+
return valid;
|
|
350
|
+
}
|
|
351
|
+
})
|
|
352
|
+
]
|
|
353
|
+
});
|
|
354
|
+
|
|
355
|
+
// ../../src/components/ui/rich-text-editor.tsx
|
|
356
|
+
import { jsx as jsx5, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
357
|
+
var labels = {
|
|
358
|
+
en: {
|
|
359
|
+
bold: "Bold",
|
|
360
|
+
italic: "Italic",
|
|
361
|
+
underline: "Underline",
|
|
362
|
+
undo: "Undo",
|
|
363
|
+
redo: "Redo",
|
|
364
|
+
link: "Link",
|
|
365
|
+
unlink: "Remove link",
|
|
366
|
+
linkUrl: "Link URL",
|
|
367
|
+
apply: "Apply link",
|
|
368
|
+
cancel: "Cancel",
|
|
369
|
+
variable: "Insert variable",
|
|
370
|
+
paragraph: "Paragraph",
|
|
371
|
+
heading: "Heading",
|
|
372
|
+
bullet: "Bulleted list",
|
|
373
|
+
numbered: "Numbered list",
|
|
374
|
+
toolbar: "Text formatting",
|
|
375
|
+
invalid: "The content is too long or contains an unsupported value.",
|
|
376
|
+
invalidLink: "Enter an HTTPS or mailto link."
|
|
377
|
+
},
|
|
378
|
+
fr: {
|
|
379
|
+
bold: "Gras",
|
|
380
|
+
italic: "Italique",
|
|
381
|
+
underline: "Souligné",
|
|
382
|
+
undo: "Annuler",
|
|
383
|
+
redo: "Rétablir",
|
|
384
|
+
link: "Lien",
|
|
385
|
+
unlink: "Retirer le lien",
|
|
386
|
+
linkUrl: "URL du lien",
|
|
387
|
+
apply: "Appliquer le lien",
|
|
388
|
+
cancel: "Annuler",
|
|
389
|
+
variable: "Insérer une variable",
|
|
390
|
+
paragraph: "Paragraphe",
|
|
391
|
+
heading: "Titre",
|
|
392
|
+
bullet: "Liste à puces",
|
|
393
|
+
numbered: "Liste numérotée",
|
|
394
|
+
toolbar: "Mise en forme",
|
|
395
|
+
invalid: "Le contenu est trop long ou contient une valeur non prise en charge.",
|
|
396
|
+
invalidLink: "Saisissez un lien HTTPS ou mailto."
|
|
397
|
+
}
|
|
398
|
+
};
|
|
399
|
+
var replacementMeta = "krakstackExternalReplacement";
|
|
400
|
+
var ToolButton = ({
|
|
401
|
+
label,
|
|
402
|
+
children,
|
|
403
|
+
onClick,
|
|
404
|
+
pressed,
|
|
405
|
+
disabled
|
|
406
|
+
}) => /* @__PURE__ */ jsx5(Button, {
|
|
407
|
+
type: "button",
|
|
408
|
+
size: "icon-sm",
|
|
409
|
+
variant: pressed ? "secondary" : "ghost",
|
|
410
|
+
"aria-label": label,
|
|
411
|
+
title: label,
|
|
412
|
+
"aria-pressed": pressed,
|
|
413
|
+
disabled,
|
|
414
|
+
onPointerDown: (event) => event.preventDefault(),
|
|
415
|
+
onClick,
|
|
416
|
+
children
|
|
417
|
+
});
|
|
418
|
+
var RichTextEditor = ({
|
|
419
|
+
value,
|
|
420
|
+
onChange,
|
|
421
|
+
label,
|
|
422
|
+
variables = [],
|
|
423
|
+
disabled,
|
|
424
|
+
locale: override,
|
|
425
|
+
messages,
|
|
426
|
+
className,
|
|
427
|
+
contentStyle,
|
|
428
|
+
maxLength,
|
|
429
|
+
extensions,
|
|
430
|
+
onReady
|
|
431
|
+
}) => {
|
|
432
|
+
const locale = useKrakstackLocale(override);
|
|
433
|
+
const language = locale.startsWith("fr") ? "fr" : "en";
|
|
434
|
+
const copy = {
|
|
435
|
+
...labels[language],
|
|
436
|
+
...messages?.[language],
|
|
437
|
+
...messages?.[locale]
|
|
438
|
+
};
|
|
439
|
+
const [error, setError] = useState(false);
|
|
440
|
+
const [linkOpen, setLinkOpen] = useState(false);
|
|
441
|
+
const [link, setLink] = useState("");
|
|
442
|
+
const [linkError, setLinkError] = useState(false);
|
|
443
|
+
const [revision, setRevision] = useState(0);
|
|
444
|
+
const id = useId();
|
|
445
|
+
const getMaxLength = useEffectEvent(() => maxLength);
|
|
446
|
+
const getVariables = useEffectEvent(() => variables);
|
|
447
|
+
const editor = useEditor({
|
|
448
|
+
immediatelyRender: false,
|
|
449
|
+
extensions: [
|
|
450
|
+
...extensions ?? richTextExtensions({ variables: () => getVariables() }),
|
|
451
|
+
richTextValidation({
|
|
452
|
+
maxLength: () => getMaxLength(),
|
|
453
|
+
onInvalid: setError
|
|
454
|
+
})
|
|
455
|
+
],
|
|
456
|
+
content: Schema3.decodeSync(RichTextDocument)(value),
|
|
457
|
+
editable: !disabled,
|
|
458
|
+
onCreate: ({ editor }) => onReady?.(editor),
|
|
459
|
+
onUpdate: ({ editor }) => onChange(editor.getJSON()),
|
|
460
|
+
onTransaction: ({ transaction }) => {
|
|
461
|
+
const replacement = transaction.getMeta(replacementMeta) === true;
|
|
462
|
+
if (replacement) {
|
|
463
|
+
setError(false);
|
|
464
|
+
setLinkOpen(false);
|
|
465
|
+
}
|
|
466
|
+
if (replacement || transaction.docChanged || transaction.selectionSet || transaction.storedMarksSet)
|
|
467
|
+
setRevision((current) => current + 1);
|
|
468
|
+
},
|
|
469
|
+
editorProps: {
|
|
470
|
+
attributes: {
|
|
471
|
+
role: "textbox",
|
|
472
|
+
"aria-label": label,
|
|
473
|
+
"aria-multiline": "true",
|
|
474
|
+
"aria-disabled": String(!!disabled),
|
|
475
|
+
"aria-describedby": error ? `${id}-error` : "",
|
|
476
|
+
class: `min-h-40 px-4 py-3 outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset ${contentStyle?.fontSize === undefined ? "text-sm" : ""} ${contentStyle?.lineHeight === undefined ? "leading-relaxed" : ""} [&_h1]:text-2xl [&_h2]:text-xl [&_h3]:text-lg [&_h1]:font-semibold [&_h2]:font-semibold [&_h3]:font-semibold [&_ul]:list-disc [&_ol]:list-decimal [&_ul]:pl-6 [&_ol]:pl-6 [&_a]:underline [&_blockquote]:border-l-2 [&_blockquote]:pl-4 [&_pre]:rounded [&_pre]:bg-muted [&_pre]:p-3`
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
}, [extensions]);
|
|
480
|
+
const focusEditor = () => {
|
|
481
|
+
editor?.view.focus();
|
|
482
|
+
return false;
|
|
483
|
+
};
|
|
484
|
+
useEffect(() => {
|
|
485
|
+
if (!editor)
|
|
486
|
+
return;
|
|
487
|
+
const incoming = editor.schema.nodeFromJSON(Schema3.decodeSync(RichTextDocument)(value));
|
|
488
|
+
incoming.check();
|
|
489
|
+
if (!editor.state.doc.eq(incoming)) {
|
|
490
|
+
editor.view.updateState(EditorState.create({
|
|
491
|
+
schema: editor.schema,
|
|
492
|
+
doc: incoming,
|
|
493
|
+
plugins: editor.state.plugins
|
|
494
|
+
}));
|
|
495
|
+
editor.view.dispatch(editor.state.tr.setMeta(replacementMeta, true));
|
|
496
|
+
}
|
|
497
|
+
}, [editor, value]);
|
|
498
|
+
useEffect(() => {
|
|
499
|
+
editor?.setEditable(!disabled, false);
|
|
500
|
+
}, [editor, disabled]);
|
|
501
|
+
useEffect(() => {
|
|
502
|
+
if (!editor)
|
|
503
|
+
return;
|
|
504
|
+
for (const chip of editor.view.dom.querySelectorAll('[data-type="mention"]')) {
|
|
505
|
+
const key = chip.getAttribute("data-id");
|
|
506
|
+
const text = `{{${variables.find((variable) => variable.key === key)?.label ?? key}}}`;
|
|
507
|
+
if (chip.textContent !== text)
|
|
508
|
+
chip.textContent = text;
|
|
509
|
+
}
|
|
510
|
+
}, [editor, variables]);
|
|
511
|
+
const block = editor?.isActive("bulletList") ? "bullet" : editor?.isActive("orderedList") ? "numbered" : editor?.isActive("heading") ? "heading" : "paragraph";
|
|
512
|
+
return /* @__PURE__ */ jsxs3("div", {
|
|
513
|
+
"data-slot": "rich-text-editor",
|
|
514
|
+
"data-revision": revision,
|
|
515
|
+
className: `bg-background text-foreground overflow-hidden rounded-xl border ${className ?? ""}`,
|
|
516
|
+
children: [
|
|
517
|
+
/* @__PURE__ */ jsxs3("div", {
|
|
518
|
+
role: "group",
|
|
519
|
+
"aria-label": copy.toolbar,
|
|
520
|
+
className: "bg-muted/30 flex flex-wrap items-center gap-1 border-b p-2",
|
|
521
|
+
children: [
|
|
522
|
+
/* @__PURE__ */ jsx5(ToolButton, {
|
|
523
|
+
label: copy.undo,
|
|
524
|
+
disabled: disabled || !editor?.can().undo(),
|
|
525
|
+
onClick: () => {
|
|
526
|
+
editor?.chain().focus().undo().run();
|
|
527
|
+
},
|
|
528
|
+
children: /* @__PURE__ */ jsx5(Undo2, {})
|
|
529
|
+
}),
|
|
530
|
+
/* @__PURE__ */ jsx5(ToolButton, {
|
|
531
|
+
label: copy.redo,
|
|
532
|
+
disabled: disabled || !editor?.can().redo(),
|
|
533
|
+
onClick: () => {
|
|
534
|
+
editor?.chain().focus().redo().run();
|
|
535
|
+
},
|
|
536
|
+
children: /* @__PURE__ */ jsx5(Redo2, {})
|
|
537
|
+
}),
|
|
538
|
+
/* @__PURE__ */ jsxs3(Select, {
|
|
539
|
+
disabled: disabled || !editor,
|
|
540
|
+
value: block,
|
|
541
|
+
items: [
|
|
542
|
+
{ value: "paragraph", label: copy.paragraph },
|
|
543
|
+
{ value: "heading", label: copy.heading },
|
|
544
|
+
{ value: "bullet", label: copy.bullet },
|
|
545
|
+
{ value: "numbered", label: copy.numbered }
|
|
546
|
+
],
|
|
547
|
+
onValueChange: (kind) => {
|
|
548
|
+
if (disabled || !editor)
|
|
549
|
+
return;
|
|
550
|
+
if (kind === "bullet")
|
|
551
|
+
editor.chain().focus().toggleBulletList().run();
|
|
552
|
+
else if (kind === "numbered")
|
|
553
|
+
editor.chain().focus().toggleOrderedList().run();
|
|
554
|
+
else if (kind === "heading")
|
|
555
|
+
editor.chain().focus().clearNodes().setHeading({ level: 2 }).run();
|
|
556
|
+
else
|
|
557
|
+
editor.chain().focus().clearNodes().setParagraph().run();
|
|
558
|
+
},
|
|
559
|
+
children: [
|
|
560
|
+
/* @__PURE__ */ jsx5(SelectTrigger, {
|
|
561
|
+
size: "sm",
|
|
562
|
+
"aria-label": copy.paragraph,
|
|
563
|
+
className: "max-w-40 text-xs",
|
|
564
|
+
children: /* @__PURE__ */ jsx5(SelectValue, {})
|
|
565
|
+
}),
|
|
566
|
+
/* @__PURE__ */ jsxs3(SelectContent, {
|
|
567
|
+
align: "start",
|
|
568
|
+
alignItemWithTrigger: false,
|
|
569
|
+
finalFocus: focusEditor,
|
|
570
|
+
children: [
|
|
571
|
+
/* @__PURE__ */ jsx5(SelectItem, {
|
|
572
|
+
value: "paragraph",
|
|
573
|
+
children: copy.paragraph
|
|
574
|
+
}),
|
|
575
|
+
/* @__PURE__ */ jsx5(SelectItem, {
|
|
576
|
+
value: "heading",
|
|
577
|
+
children: copy.heading
|
|
578
|
+
}),
|
|
579
|
+
/* @__PURE__ */ jsx5(SelectItem, {
|
|
580
|
+
value: "bullet",
|
|
581
|
+
children: copy.bullet
|
|
582
|
+
}),
|
|
583
|
+
/* @__PURE__ */ jsx5(SelectItem, {
|
|
584
|
+
value: "numbered",
|
|
585
|
+
children: copy.numbered
|
|
586
|
+
})
|
|
587
|
+
]
|
|
588
|
+
})
|
|
589
|
+
]
|
|
590
|
+
}),
|
|
591
|
+
/* @__PURE__ */ jsx5(ToolButton, {
|
|
592
|
+
label: copy.bold,
|
|
593
|
+
disabled: disabled || !editor,
|
|
594
|
+
pressed: editor?.isActive("bold"),
|
|
595
|
+
onClick: () => {
|
|
596
|
+
editor?.chain().focus().toggleBold().run();
|
|
597
|
+
},
|
|
598
|
+
children: /* @__PURE__ */ jsx5(Bold, {})
|
|
599
|
+
}),
|
|
600
|
+
/* @__PURE__ */ jsx5(ToolButton, {
|
|
601
|
+
label: copy.italic,
|
|
602
|
+
disabled: disabled || !editor,
|
|
603
|
+
pressed: editor?.isActive("italic"),
|
|
604
|
+
onClick: () => {
|
|
605
|
+
editor?.chain().focus().toggleItalic().run();
|
|
606
|
+
},
|
|
607
|
+
children: /* @__PURE__ */ jsx5(Italic, {})
|
|
608
|
+
}),
|
|
609
|
+
/* @__PURE__ */ jsx5(ToolButton, {
|
|
610
|
+
label: copy.underline,
|
|
611
|
+
disabled: disabled || !editor,
|
|
612
|
+
pressed: editor?.isActive("underline"),
|
|
613
|
+
onClick: () => {
|
|
614
|
+
editor?.chain().focus().toggleUnderline().run();
|
|
615
|
+
},
|
|
616
|
+
children: /* @__PURE__ */ jsx5(Underline, {})
|
|
617
|
+
}),
|
|
618
|
+
/* @__PURE__ */ jsx5(ToolButton, {
|
|
619
|
+
label: copy.link,
|
|
620
|
+
disabled: disabled || !editor,
|
|
621
|
+
pressed: linkOpen || editor?.isActive("link"),
|
|
622
|
+
onClick: () => {
|
|
623
|
+
setLink(editor?.getAttributes("link").href ?? "");
|
|
624
|
+
setLinkError(false);
|
|
625
|
+
setLinkOpen(!linkOpen);
|
|
626
|
+
},
|
|
627
|
+
children: /* @__PURE__ */ jsx5(Link2, {})
|
|
628
|
+
}),
|
|
629
|
+
variables.length ? /* @__PURE__ */ jsxs3(DropdownMenu, {
|
|
630
|
+
children: [
|
|
631
|
+
/* @__PURE__ */ jsxs3(DropdownMenuTrigger, {
|
|
632
|
+
disabled: disabled || !editor,
|
|
633
|
+
render: /* @__PURE__ */ jsx5(Button, {
|
|
634
|
+
type: "button",
|
|
635
|
+
variant: "outline",
|
|
636
|
+
size: "sm",
|
|
637
|
+
className: "ml-auto text-xs"
|
|
638
|
+
}),
|
|
639
|
+
children: [
|
|
640
|
+
/* @__PURE__ */ jsx5(Braces, {
|
|
641
|
+
"aria-hidden": true
|
|
642
|
+
}),
|
|
643
|
+
copy.variable
|
|
644
|
+
]
|
|
645
|
+
}),
|
|
646
|
+
/* @__PURE__ */ jsx5(DropdownMenuContent, {
|
|
647
|
+
align: "end",
|
|
648
|
+
finalFocus: focusEditor,
|
|
649
|
+
children: variables.map((variable) => /* @__PURE__ */ jsx5(DropdownMenuItem, {
|
|
650
|
+
onClick: () => {
|
|
651
|
+
if (disabled || !editor)
|
|
652
|
+
return;
|
|
653
|
+
editor.view.dispatch(closeHistory(editor.state.tr));
|
|
654
|
+
editor.commands.insertContent({
|
|
655
|
+
type: "mention",
|
|
656
|
+
attrs: { id: variable.key, label: variable.label }
|
|
657
|
+
});
|
|
658
|
+
editor.view.dispatch(closeHistory(editor.state.tr));
|
|
659
|
+
},
|
|
660
|
+
children: variable.label
|
|
661
|
+
}, variable.key))
|
|
662
|
+
})
|
|
663
|
+
]
|
|
664
|
+
}) : null
|
|
665
|
+
]
|
|
666
|
+
}),
|
|
667
|
+
linkOpen ? /* @__PURE__ */ jsxs3("div", {
|
|
668
|
+
className: "flex flex-wrap items-end gap-2 border-b p-3",
|
|
669
|
+
children: [
|
|
670
|
+
/* @__PURE__ */ jsxs3("label", {
|
|
671
|
+
className: "grid min-w-0 flex-1 gap-1 text-xs",
|
|
672
|
+
children: [
|
|
673
|
+
copy.linkUrl,
|
|
674
|
+
/* @__PURE__ */ jsx5(Input, {
|
|
675
|
+
value: link,
|
|
676
|
+
"aria-invalid": linkError,
|
|
677
|
+
placeholder: "https://",
|
|
678
|
+
onChange: (event) => setLink(event.target.value)
|
|
679
|
+
})
|
|
680
|
+
]
|
|
681
|
+
}),
|
|
682
|
+
/* @__PURE__ */ jsx5(Button, {
|
|
683
|
+
type: "button",
|
|
684
|
+
size: "sm",
|
|
685
|
+
disabled,
|
|
686
|
+
onClick: () => {
|
|
687
|
+
if (!Schema3.is(RichTextLink)(link)) {
|
|
688
|
+
setLinkError(true);
|
|
689
|
+
return;
|
|
690
|
+
}
|
|
691
|
+
editor?.chain().focus().extendMarkRange("link").setLink({ href: link }).run();
|
|
692
|
+
setLinkOpen(false);
|
|
693
|
+
},
|
|
694
|
+
children: copy.apply
|
|
695
|
+
}),
|
|
696
|
+
editor?.isActive("link") ? /* @__PURE__ */ jsxs3(Button, {
|
|
697
|
+
type: "button",
|
|
698
|
+
size: "sm",
|
|
699
|
+
variant: "outline",
|
|
700
|
+
disabled,
|
|
701
|
+
onClick: () => {
|
|
702
|
+
editor.chain().focus().extendMarkRange("link").unsetLink().run();
|
|
703
|
+
setLinkOpen(false);
|
|
704
|
+
},
|
|
705
|
+
children: [
|
|
706
|
+
/* @__PURE__ */ jsx5(Unlink, {
|
|
707
|
+
"aria-hidden": true
|
|
708
|
+
}),
|
|
709
|
+
copy.unlink
|
|
710
|
+
]
|
|
711
|
+
}) : null,
|
|
712
|
+
/* @__PURE__ */ jsx5(Button, {
|
|
713
|
+
type: "button",
|
|
714
|
+
size: "sm",
|
|
715
|
+
variant: "ghost",
|
|
716
|
+
onClick: () => setLinkOpen(false),
|
|
717
|
+
children: copy.cancel
|
|
718
|
+
}),
|
|
719
|
+
linkError ? /* @__PURE__ */ jsx5("p", {
|
|
720
|
+
role: "alert",
|
|
721
|
+
className: "text-destructive w-full text-xs",
|
|
722
|
+
children: copy.invalidLink
|
|
723
|
+
}) : null
|
|
724
|
+
]
|
|
725
|
+
}) : null,
|
|
726
|
+
/* @__PURE__ */ jsx5(EditorContent, {
|
|
727
|
+
editor,
|
|
728
|
+
style: contentStyle
|
|
729
|
+
}),
|
|
730
|
+
error ? /* @__PURE__ */ jsx5("p", {
|
|
731
|
+
id: `${id}-error`,
|
|
732
|
+
role: "alert",
|
|
733
|
+
className: "text-destructive px-4 pb-3 text-xs",
|
|
734
|
+
children: copy.invalid
|
|
735
|
+
}) : null
|
|
736
|
+
]
|
|
737
|
+
});
|
|
738
|
+
};
|
|
739
|
+
|
|
740
|
+
// ../../src/components/ui/email-composer.tsx
|
|
741
|
+
import { useKrakstackLocale as useKrakstackLocale2 } from "@krak-stack/registry/krakstack-provider";
|
|
742
|
+
|
|
743
|
+
// ../../src/lib/email-composer/index.ts
|
|
744
|
+
import { composeReactEmail, EmailNode } from "@react-email/editor/core";
|
|
745
|
+
import { StarterKit as StarterKit2 } from "@react-email/editor/extensions";
|
|
746
|
+
import { Effect, Schema as Schema5 } from "effect";
|
|
747
|
+
|
|
748
|
+
// ../../src/lib/email-composer/schema.ts
|
|
749
|
+
import { Schema as Schema4 } from "effect";
|
|
750
|
+
var EmailExport = Schema4.Struct({
|
|
751
|
+
html: Schema4.String,
|
|
752
|
+
text: Schema4.String
|
|
753
|
+
}).annotate({ identifier: "EmailExport" });
|
|
754
|
+
|
|
755
|
+
class EmailComposerExportError extends Schema4.TaggedError()("EmailComposerExportError", { cause: Schema4.Defect() }) {
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
// ../../src/lib/email-composer/index.ts
|
|
759
|
+
var createEmailComposerExtensions = (resolveVariable = (key) => `{{${key}}}`) => [
|
|
760
|
+
StarterKit2.configure({
|
|
761
|
+
Link: {
|
|
762
|
+
openOnClick: false,
|
|
763
|
+
autolink: false,
|
|
764
|
+
linkOnPaste: false,
|
|
765
|
+
isAllowedUri: (url) => Schema5.is(RichTextLink)(url)
|
|
766
|
+
},
|
|
767
|
+
TwoColumns: false,
|
|
768
|
+
ThreeColumns: false,
|
|
769
|
+
FourColumns: false,
|
|
770
|
+
ColumnsColumn: false
|
|
771
|
+
}),
|
|
772
|
+
EmailNode.from(richTextMention(), ({ node }) => resolveVariable(Schema5.decodeUnknownSync(RichTextVariable.fields.key)(node.attrs?.id)))
|
|
773
|
+
];
|
|
774
|
+
var emailComposerExtensions = createEmailComposerExtensions();
|
|
775
|
+
var exportEmail = Effect.fn("EmailComposer.export")(function* ({
|
|
776
|
+
editor
|
|
777
|
+
}) {
|
|
778
|
+
const result = yield* Effect.tryPromise({
|
|
779
|
+
try: () => composeReactEmail({ editor, pretty: false }),
|
|
780
|
+
catch: (cause) => new EmailComposerExportError({ cause })
|
|
781
|
+
});
|
|
782
|
+
return yield* Schema5.decodeEffect(EmailExport)({
|
|
783
|
+
html: result.unformattedHtml,
|
|
784
|
+
text: result.text
|
|
785
|
+
}).pipe(Effect.mapError((cause) => new EmailComposerExportError({ cause })));
|
|
786
|
+
});
|
|
787
|
+
|
|
788
|
+
// ../../src/components/ui/email-composer.tsx
|
|
789
|
+
import { jsx as jsx6, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
790
|
+
var labels2 = {
|
|
791
|
+
en: {
|
|
792
|
+
preview: "Email preview",
|
|
793
|
+
text: "Plain-text email",
|
|
794
|
+
error: "The email preview could not be generated. Please try again."
|
|
795
|
+
},
|
|
796
|
+
fr: {
|
|
797
|
+
preview: "Aperçu du courriel",
|
|
798
|
+
text: "Courriel en texte brut",
|
|
799
|
+
error: "L’aperçu du courriel n’a pas pu être généré. Veuillez réessayer."
|
|
800
|
+
}
|
|
801
|
+
};
|
|
802
|
+
var EmailComposer = ({
|
|
803
|
+
previewMessages,
|
|
804
|
+
...props
|
|
805
|
+
}) => {
|
|
806
|
+
const locale = useKrakstackLocale2(props.locale).startsWith("fr") ? "fr" : "en";
|
|
807
|
+
const copy = { ...labels2[locale], ...previewMessages };
|
|
808
|
+
const [editor, setEditor] = useState2(null);
|
|
809
|
+
const [email, setEmail] = useState2(null);
|
|
810
|
+
const [previewError, setPreviewError] = useState2(false);
|
|
811
|
+
const resolveVariable = useEffectEvent2((key) => props.variables?.find((variable) => variable.key === key)?.sample ?? `{{${key}}}`);
|
|
812
|
+
const [extensions] = useState2(() => createEmailComposerExtensions((key) => resolveVariable(key)));
|
|
813
|
+
useEffect2(() => {
|
|
814
|
+
if (!editor || editor.isDestroyed)
|
|
815
|
+
return;
|
|
816
|
+
let current = true;
|
|
817
|
+
Effect2.runPromise(exportEmail({ editor }).pipe(Effect2.match({
|
|
818
|
+
onFailure: () => {
|
|
819
|
+
if (current) {
|
|
820
|
+
setEmail(null);
|
|
821
|
+
setPreviewError(true);
|
|
822
|
+
}
|
|
823
|
+
},
|
|
824
|
+
onSuccess: (result) => {
|
|
825
|
+
if (current) {
|
|
826
|
+
setEmail(result);
|
|
827
|
+
setPreviewError(false);
|
|
828
|
+
}
|
|
829
|
+
}
|
|
830
|
+
})));
|
|
831
|
+
return () => {
|
|
832
|
+
current = false;
|
|
833
|
+
};
|
|
834
|
+
}, [editor, props.value, props.variables]);
|
|
835
|
+
return /* @__PURE__ */ jsxs4("div", {
|
|
836
|
+
"data-slot": "email-composer",
|
|
837
|
+
className: "min-w-0 space-y-3",
|
|
838
|
+
children: [
|
|
839
|
+
/* @__PURE__ */ jsx6(RichTextEditor, {
|
|
840
|
+
...props,
|
|
841
|
+
extensions,
|
|
842
|
+
onReady: setEditor
|
|
843
|
+
}),
|
|
844
|
+
previewError ? /* @__PURE__ */ jsx6("p", {
|
|
845
|
+
role: "alert",
|
|
846
|
+
className: "text-destructive text-sm",
|
|
847
|
+
children: copy.error
|
|
848
|
+
}) : null,
|
|
849
|
+
/* @__PURE__ */ jsx6("iframe", {
|
|
850
|
+
title: copy.preview,
|
|
851
|
+
sandbox: "",
|
|
852
|
+
srcDoc: email?.html ?? "",
|
|
853
|
+
className: "h-64 w-full rounded-lg border bg-white"
|
|
854
|
+
}),
|
|
855
|
+
/* @__PURE__ */ jsxs4("label", {
|
|
856
|
+
className: "grid gap-2 text-sm",
|
|
857
|
+
children: [
|
|
858
|
+
copy.text,
|
|
859
|
+
/* @__PURE__ */ jsx6("textarea", {
|
|
860
|
+
readOnly: true,
|
|
861
|
+
value: email?.text ?? "",
|
|
862
|
+
className: "min-h-24 w-full rounded-lg border p-3"
|
|
863
|
+
})
|
|
864
|
+
]
|
|
865
|
+
})
|
|
866
|
+
]
|
|
867
|
+
});
|
|
868
|
+
};
|
|
869
|
+
export {
|
|
870
|
+
EmailComposer
|
|
871
|
+
};
|