@krak-stack/registry 0.10.5 → 0.10.6
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 +14 -0
- package/dist/components/ui/animated-list.d.ts +6 -7
- package/dist/components/ui/animated-list.js +329 -139
- package/dist/components/ui/animated-number.js +47 -24
- package/dist/components/ui/auto-height.js +56 -15
- package/dist/components/ui/email-editor.d.ts +124 -0
- package/dist/components/ui/email-editor.js +2651 -0
- package/dist/components/ui/form.d.ts +5 -5
- package/dist/components/ui/presence-transition.d.ts +1 -1
- package/dist/components/ui/presence-transition.js +79 -26
- package/dist/components/ui/rich-text-editor.d.ts +70 -0
- package/dist/components/ui/rich-text-editor.js +1135 -0
- package/dist/components/ui/time-picker.d.ts +13 -4
- package/dist/components/ui/time-picker.js +141 -47
- package/dist/components/ui/time-picker.schema.d.ts +16 -2
- package/dist/lib/email-document/model.d.ts +26 -0
- package/dist/lib/email-document/model.js +253 -0
- package/dist/lib/email-document/render.d.ts +115 -0
- package/dist/lib/email-document/render.js +469 -0
- package/dist/lib/email-document/schema.d.ts +285 -0
- package/dist/lib/email-document/schema.js +139 -0
- package/dist/lib/krakmotion.d.ts +27 -0
- package/dist/lib/rich-text/dom.d.ts +40 -0
- package/dist/lib/rich-text/model.d.ts +19 -0
- package/dist/lib/rich-text/model.js +141 -0
- package/dist/lib/rich-text/schema.d.ts +64 -0
- package/dist/lib/rich-text/schema.js +53 -0
- package/package.json +29 -5
|
@@ -0,0 +1,2651 @@
|
|
|
1
|
+
// ../../src/components/ui/email-editor.tsx
|
|
2
|
+
import { Schema as Schema7 } from "effect";
|
|
3
|
+
import { Popover } from "@base-ui/react/popover";
|
|
4
|
+
import { useId as useId3, useState as useState4 } from "react";
|
|
5
|
+
import {
|
|
6
|
+
Type,
|
|
7
|
+
Image,
|
|
8
|
+
MousePointer2,
|
|
9
|
+
Minus,
|
|
10
|
+
Space,
|
|
11
|
+
KeyRound,
|
|
12
|
+
ScanLine,
|
|
13
|
+
Trash2,
|
|
14
|
+
Copy,
|
|
15
|
+
Pencil,
|
|
16
|
+
X,
|
|
17
|
+
ChevronDown as ChevronDown2,
|
|
18
|
+
Plus,
|
|
19
|
+
Palette
|
|
20
|
+
} from "lucide-react";
|
|
21
|
+
|
|
22
|
+
// ../../src/components/ui/button.tsx
|
|
23
|
+
import { Button as ButtonPrimitive } from "@base-ui/react/button";
|
|
24
|
+
import { cva } from "class-variance-authority";
|
|
25
|
+
|
|
26
|
+
// ../../src/lib/utils.ts
|
|
27
|
+
import { cn } from "cn";
|
|
28
|
+
|
|
29
|
+
// ../../src/components/ui/button.tsx
|
|
30
|
+
import { jsx } from "react/jsx-runtime";
|
|
31
|
+
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", {
|
|
32
|
+
variants: {
|
|
33
|
+
variant: {
|
|
34
|
+
default: "bg-primary text-primary-foreground hover:bg-primary/80",
|
|
35
|
+
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",
|
|
36
|
+
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",
|
|
37
|
+
ghost: "hover:bg-muted hover:text-foreground aria-expanded:bg-muted aria-expanded:text-foreground dark:hover:bg-muted/50",
|
|
38
|
+
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",
|
|
39
|
+
link: "text-primary underline-offset-4 hover:underline"
|
|
40
|
+
},
|
|
41
|
+
size: {
|
|
42
|
+
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",
|
|
43
|
+
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",
|
|
44
|
+
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",
|
|
45
|
+
lg: "h-10 gap-1.5 px-2.5 has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2",
|
|
46
|
+
icon: "size-9",
|
|
47
|
+
"icon-xs": "size-6 rounded-[min(var(--radius-md),8px)] in-data-[slot=button-group]:rounded-md [&_svg:not([class*='size-'])]:size-3",
|
|
48
|
+
"icon-sm": "size-8 rounded-[min(var(--radius-md),10px)] in-data-[slot=button-group]:rounded-md",
|
|
49
|
+
"icon-lg": "size-10"
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
defaultVariants: {
|
|
53
|
+
variant: "default",
|
|
54
|
+
size: "default"
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
function Button({
|
|
58
|
+
className,
|
|
59
|
+
variant = "default",
|
|
60
|
+
size = "default",
|
|
61
|
+
...props
|
|
62
|
+
}) {
|
|
63
|
+
return /* @__PURE__ */ jsx(ButtonPrimitive, {
|
|
64
|
+
"data-slot": "button",
|
|
65
|
+
className: cn(buttonVariants({ variant, size, className })),
|
|
66
|
+
...props
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// ../../src/components/ui/input.tsx
|
|
71
|
+
import { Input as InputPrimitive } from "@base-ui/react/input";
|
|
72
|
+
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
73
|
+
function Input({ className, type, ...props }) {
|
|
74
|
+
return /* @__PURE__ */ jsx2(InputPrimitive, {
|
|
75
|
+
type,
|
|
76
|
+
"data-slot": "input",
|
|
77
|
+
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),
|
|
78
|
+
...props
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// ../../src/components/ui/select.tsx
|
|
83
|
+
import { Select as SelectPrimitive } from "@base-ui/react/select";
|
|
84
|
+
import { ChevronDownIcon, CheckIcon, ChevronUpIcon } from "lucide-react";
|
|
85
|
+
import { jsx as jsx3, jsxs } from "react/jsx-runtime";
|
|
86
|
+
"use client";
|
|
87
|
+
var Select = SelectPrimitive.Root;
|
|
88
|
+
function SelectValue({ className, ...props }) {
|
|
89
|
+
return /* @__PURE__ */ jsx3(SelectPrimitive.Value, {
|
|
90
|
+
"data-slot": "select-value",
|
|
91
|
+
className: cn("flex flex-1 text-left", className),
|
|
92
|
+
...props
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
function SelectTrigger({
|
|
96
|
+
className,
|
|
97
|
+
size = "default",
|
|
98
|
+
children,
|
|
99
|
+
...props
|
|
100
|
+
}) {
|
|
101
|
+
return /* @__PURE__ */ jsxs(SelectPrimitive.Trigger, {
|
|
102
|
+
"data-slot": "select-trigger",
|
|
103
|
+
"data-size": size,
|
|
104
|
+
className: cn("flex w-fit items-center justify-between gap-1.5 rounded-md border border-input bg-transparent py-2 pr-2 pl-2.5 text-sm whitespace-nowrap shadow-xs transition-[color,box-shadow] outline-none 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 data-placeholder:text-muted-foreground 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 dark:bg-input/30 dark:hover:bg-input/50 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", className),
|
|
105
|
+
...props,
|
|
106
|
+
children: [
|
|
107
|
+
children,
|
|
108
|
+
/* @__PURE__ */ jsx3(SelectPrimitive.Icon, {
|
|
109
|
+
render: /* @__PURE__ */ jsx3(ChevronDownIcon, {
|
|
110
|
+
className: "text-muted-foreground pointer-events-none size-4"
|
|
111
|
+
})
|
|
112
|
+
})
|
|
113
|
+
]
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
function SelectContent({
|
|
117
|
+
className,
|
|
118
|
+
children,
|
|
119
|
+
side = "bottom",
|
|
120
|
+
sideOffset = 4,
|
|
121
|
+
align = "center",
|
|
122
|
+
alignOffset = 0,
|
|
123
|
+
alignItemWithTrigger = true,
|
|
124
|
+
...props
|
|
125
|
+
}) {
|
|
126
|
+
return /* @__PURE__ */ jsx3(SelectPrimitive.Portal, {
|
|
127
|
+
children: /* @__PURE__ */ jsx3(SelectPrimitive.Positioner, {
|
|
128
|
+
side,
|
|
129
|
+
sideOffset,
|
|
130
|
+
align,
|
|
131
|
+
alignOffset,
|
|
132
|
+
alignItemWithTrigger,
|
|
133
|
+
className: "isolate z-50",
|
|
134
|
+
children: /* @__PURE__ */ jsxs(SelectPrimitive.Popup, {
|
|
135
|
+
"data-slot": "select-content",
|
|
136
|
+
"data-align-trigger": alignItemWithTrigger,
|
|
137
|
+
className: cn("relative isolate z-50 max-h-(--available-height) w-(--anchor-width) min-w-36 origin-(--transform-origin) overflow-x-hidden overflow-y-auto rounded-md bg-popover text-popover-foreground shadow-md ring-1 ring-foreground/10 duration-100 data-[align-trigger=true]:animate-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:fade-out-0 data-closed:zoom-out-95", className),
|
|
138
|
+
...props,
|
|
139
|
+
children: [
|
|
140
|
+
/* @__PURE__ */ jsx3(SelectScrollUpButton, {}),
|
|
141
|
+
/* @__PURE__ */ jsx3(SelectPrimitive.List, {
|
|
142
|
+
children
|
|
143
|
+
}),
|
|
144
|
+
/* @__PURE__ */ jsx3(SelectScrollDownButton, {})
|
|
145
|
+
]
|
|
146
|
+
})
|
|
147
|
+
})
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
function SelectItem({
|
|
151
|
+
className,
|
|
152
|
+
children,
|
|
153
|
+
...props
|
|
154
|
+
}) {
|
|
155
|
+
return /* @__PURE__ */ jsxs(SelectPrimitive.Item, {
|
|
156
|
+
"data-slot": "select-item",
|
|
157
|
+
className: cn("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 focus:bg-accent focus:text-accent-foreground not-data-[variant=destructive]:focus:**:text-accent-foreground 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),
|
|
158
|
+
...props,
|
|
159
|
+
children: [
|
|
160
|
+
/* @__PURE__ */ jsx3(SelectPrimitive.ItemText, {
|
|
161
|
+
className: "flex flex-1 shrink-0 gap-2 whitespace-nowrap",
|
|
162
|
+
children
|
|
163
|
+
}),
|
|
164
|
+
/* @__PURE__ */ jsx3(SelectPrimitive.ItemIndicator, {
|
|
165
|
+
render: /* @__PURE__ */ jsx3("span", {
|
|
166
|
+
className: "pointer-events-none absolute right-2 flex size-4 items-center justify-center"
|
|
167
|
+
}),
|
|
168
|
+
children: /* @__PURE__ */ jsx3(CheckIcon, {
|
|
169
|
+
className: "pointer-events-none"
|
|
170
|
+
})
|
|
171
|
+
})
|
|
172
|
+
]
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
function SelectScrollUpButton({
|
|
176
|
+
className,
|
|
177
|
+
...props
|
|
178
|
+
}) {
|
|
179
|
+
return /* @__PURE__ */ jsx3(SelectPrimitive.ScrollUpArrow, {
|
|
180
|
+
"data-slot": "select-scroll-up-button",
|
|
181
|
+
className: cn("top-0 z-10 flex w-full cursor-default items-center justify-center bg-popover py-1 [&_svg:not([class*='size-'])]:size-4", className),
|
|
182
|
+
...props,
|
|
183
|
+
children: /* @__PURE__ */ jsx3(ChevronUpIcon, {})
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
function SelectScrollDownButton({
|
|
187
|
+
className,
|
|
188
|
+
...props
|
|
189
|
+
}) {
|
|
190
|
+
return /* @__PURE__ */ jsx3(SelectPrimitive.ScrollDownArrow, {
|
|
191
|
+
"data-slot": "select-scroll-down-button",
|
|
192
|
+
className: cn("bottom-0 z-10 flex w-full cursor-default items-center justify-center bg-popover py-1 [&_svg:not([class*='size-'])]:size-4", className),
|
|
193
|
+
...props,
|
|
194
|
+
children: /* @__PURE__ */ jsx3(ChevronDownIcon, {})
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// ../../src/components/ui/popover.tsx
|
|
199
|
+
import { Popover as PopoverPrimitive } from "@base-ui/react/popover";
|
|
200
|
+
import { jsx as jsx4 } from "react/jsx-runtime";
|
|
201
|
+
function PopoverTrigger({ ...props }) {
|
|
202
|
+
return /* @__PURE__ */ jsx4(PopoverPrimitive.Trigger, {
|
|
203
|
+
"data-slot": "popover-trigger",
|
|
204
|
+
...props
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
function PopoverContent({
|
|
208
|
+
className,
|
|
209
|
+
align = "center",
|
|
210
|
+
alignOffset = 0,
|
|
211
|
+
side = "bottom",
|
|
212
|
+
sideOffset = 4,
|
|
213
|
+
...props
|
|
214
|
+
}) {
|
|
215
|
+
return /* @__PURE__ */ jsx4(PopoverPrimitive.Portal, {
|
|
216
|
+
children: /* @__PURE__ */ jsx4(PopoverPrimitive.Positioner, {
|
|
217
|
+
align,
|
|
218
|
+
alignOffset,
|
|
219
|
+
side,
|
|
220
|
+
sideOffset,
|
|
221
|
+
className: "isolate z-50",
|
|
222
|
+
children: /* @__PURE__ */ jsx4(PopoverPrimitive.Popup, {
|
|
223
|
+
"data-slot": "popover-content",
|
|
224
|
+
className: cn("z-50 flex w-72 origin-(--transform-origin) flex-col gap-4 rounded-md bg-popover p-4 text-sm text-popover-foreground shadow-md ring-1 ring-foreground/10 outline-hidden duration-100 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", className),
|
|
225
|
+
...props
|
|
226
|
+
})
|
|
227
|
+
})
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
function PopoverTitle({ className, ...props }) {
|
|
231
|
+
return /* @__PURE__ */ jsx4(PopoverPrimitive.Title, {
|
|
232
|
+
"data-slot": "popover-title",
|
|
233
|
+
className: cn("font-medium", className),
|
|
234
|
+
...props
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
// ../../src/components/ui/animated-list.tsx
|
|
239
|
+
import {
|
|
240
|
+
useEffect as useEffect2,
|
|
241
|
+
useEffectEvent as useEffectEvent2,
|
|
242
|
+
useId,
|
|
243
|
+
useRef as useRef2,
|
|
244
|
+
useState as useState2
|
|
245
|
+
} from "react";
|
|
246
|
+
import { GripVertical } from "lucide-react";
|
|
247
|
+
import { cn as cn2 } from "cn";
|
|
248
|
+
import { useKrakstackLocale } from "@krak-stack/registry/krakstack-provider";
|
|
249
|
+
|
|
250
|
+
// ../../src/lib/krakmotion.ts
|
|
251
|
+
import {
|
|
252
|
+
useEffect,
|
|
253
|
+
useEffectEvent,
|
|
254
|
+
useLayoutEffect,
|
|
255
|
+
useRef,
|
|
256
|
+
useState,
|
|
257
|
+
useSyncExternalStore
|
|
258
|
+
} from "react";
|
|
259
|
+
var useBrowserLayoutEffect = globalThis.window ? useLayoutEffect : useEffect;
|
|
260
|
+
var reducedMotionQuery = "(prefers-reduced-motion: reduce)";
|
|
261
|
+
var subscribeReducedMotion = (notify) => {
|
|
262
|
+
const query = window.matchMedia?.(reducedMotionQuery);
|
|
263
|
+
query?.addEventListener("change", notify);
|
|
264
|
+
return () => query?.removeEventListener("change", notify);
|
|
265
|
+
};
|
|
266
|
+
var useReducedMotion = () => useSyncExternalStore(subscribeReducedMotion, () => window.matchMedia?.(reducedMotionQuery).matches ?? true, () => true);
|
|
267
|
+
var animateElement = (element, frames, duration, complete) => {
|
|
268
|
+
if (duration <= 0 || !element.animate) {
|
|
269
|
+
complete?.();
|
|
270
|
+
return () => {};
|
|
271
|
+
}
|
|
272
|
+
const animation = element.animate(frames, {
|
|
273
|
+
duration,
|
|
274
|
+
easing: "cubic-bezier(0.2, 0, 0, 1)"
|
|
275
|
+
});
|
|
276
|
+
animation.onfinish = () => complete?.();
|
|
277
|
+
return () => {
|
|
278
|
+
animation.onfinish = null;
|
|
279
|
+
animation.cancel();
|
|
280
|
+
};
|
|
281
|
+
};
|
|
282
|
+
var useKeyedPresence = (items, getKey) => {
|
|
283
|
+
const [previous, setPrevious] = useState(items);
|
|
284
|
+
const [retained, setRetained] = useState(items);
|
|
285
|
+
if (previous !== items) {
|
|
286
|
+
const keys = new Set(items.map(getKey));
|
|
287
|
+
const next = [...items];
|
|
288
|
+
retained.forEach((item, index) => {
|
|
289
|
+
if (!keys.has(getKey(item)))
|
|
290
|
+
next.splice(Math.min(index, next.length), 0, item);
|
|
291
|
+
});
|
|
292
|
+
setPrevious(items);
|
|
293
|
+
setRetained(next);
|
|
294
|
+
}
|
|
295
|
+
const present = new Set(items.map(getKey));
|
|
296
|
+
return {
|
|
297
|
+
items: retained,
|
|
298
|
+
present,
|
|
299
|
+
remove: (key) => setRetained((current) => current.filter((item) => getKey(item) !== key))
|
|
300
|
+
};
|
|
301
|
+
};
|
|
302
|
+
var useListLayout = (ref, duration) => {
|
|
303
|
+
const previous = useRef(new Map);
|
|
304
|
+
const animations = useRef(new Map);
|
|
305
|
+
const reduced = useReducedMotion();
|
|
306
|
+
useBrowserLayoutEffect(() => {
|
|
307
|
+
const next = new Map;
|
|
308
|
+
for (const element of ref.current?.children ?? []) {
|
|
309
|
+
if (!(element instanceof HTMLElement))
|
|
310
|
+
continue;
|
|
311
|
+
const key = element.dataset.motionKey;
|
|
312
|
+
if (!key)
|
|
313
|
+
continue;
|
|
314
|
+
const position = { top: element.offsetTop, left: element.offsetLeft };
|
|
315
|
+
next.set(key, position);
|
|
316
|
+
const old = previous.current.get(key);
|
|
317
|
+
if (old && (old.top !== position.top || old.left !== position.left)) {
|
|
318
|
+
const transform = getComputedStyle(element).transform;
|
|
319
|
+
const interrupted = transform === "none" ? null : new DOMMatrixReadOnly(transform);
|
|
320
|
+
animations.current.get(element)?.();
|
|
321
|
+
if (!element.hasAttribute("data-dragging")) {
|
|
322
|
+
animations.current.set(element, animateElement(element, [
|
|
323
|
+
{
|
|
324
|
+
transform: `translate(${old.left - position.left + (interrupted?.m41 ?? 0)}px, ${old.top - position.top + (interrupted?.m42 ?? 0)}px)`
|
|
325
|
+
},
|
|
326
|
+
{ transform: "none" }
|
|
327
|
+
], reduced ? 0 : Math.max(0, duration)));
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
for (const [element, cancel] of animations.current) {
|
|
332
|
+
if (!element.isConnected) {
|
|
333
|
+
cancel();
|
|
334
|
+
animations.current.delete(element);
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
previous.current = next;
|
|
338
|
+
});
|
|
339
|
+
useEffect(() => () => {
|
|
340
|
+
for (const cancel of animations.current.values())
|
|
341
|
+
cancel();
|
|
342
|
+
}, []);
|
|
343
|
+
};
|
|
344
|
+
var setDragStyle = (element, translate, active) => {
|
|
345
|
+
element.style.translate = translate;
|
|
346
|
+
element.style.zIndex = active ? "1" : "";
|
|
347
|
+
element.toggleAttribute("data-dragging", active);
|
|
348
|
+
};
|
|
349
|
+
var useVerticalDrag = ({
|
|
350
|
+
ref,
|
|
351
|
+
container,
|
|
352
|
+
enabled,
|
|
353
|
+
overflow,
|
|
354
|
+
onMove
|
|
355
|
+
}) => {
|
|
356
|
+
const session = useRef(null);
|
|
357
|
+
const update = () => {
|
|
358
|
+
const drag = session.current;
|
|
359
|
+
const element = drag?.element ?? ref.current;
|
|
360
|
+
const list = container.current;
|
|
361
|
+
if (!drag?.active || !element || !list)
|
|
362
|
+
return;
|
|
363
|
+
const bounds = list.getBoundingClientRect();
|
|
364
|
+
const top = bounds.top + list.clientTop - list.scrollTop;
|
|
365
|
+
const allowance = Math.max(0, overflow);
|
|
366
|
+
const desired = Math.max(bounds.top - allowance, Math.min(bounds.bottom - element.offsetHeight + allowance, drag.y - drag.grab));
|
|
367
|
+
setDragStyle(element, `0 ${desired - top - element.offsetTop}px`, true);
|
|
368
|
+
const bottom = desired + element.offsetHeight;
|
|
369
|
+
const siblings = [...list.children].filter((child) => child instanceof HTMLElement && child.getAttribute("aria-hidden") !== "true");
|
|
370
|
+
const index = siblings.indexOf(element);
|
|
371
|
+
let target = index;
|
|
372
|
+
for (let i = 0;i < siblings.length; i++) {
|
|
373
|
+
const sibling = siblings[i];
|
|
374
|
+
if (!(sibling instanceof HTMLElement) || sibling === element)
|
|
375
|
+
continue;
|
|
376
|
+
const middle = top + sibling.offsetTop + sibling.offsetHeight / 2;
|
|
377
|
+
if (i > index && bottom > middle)
|
|
378
|
+
target = i;
|
|
379
|
+
if (i < index && desired < middle) {
|
|
380
|
+
target = i;
|
|
381
|
+
break;
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
if (target !== index)
|
|
385
|
+
onMove(target);
|
|
386
|
+
};
|
|
387
|
+
const end = () => {
|
|
388
|
+
const drag = session.current;
|
|
389
|
+
session.current = null;
|
|
390
|
+
const element = drag?.element ?? ref.current;
|
|
391
|
+
if (element)
|
|
392
|
+
setDragStyle(element, "", false);
|
|
393
|
+
if (drag?.capture.hasPointerCapture?.(drag.pointer))
|
|
394
|
+
drag.capture.releasePointerCapture(drag.pointer);
|
|
395
|
+
};
|
|
396
|
+
const updateDrag = useEffectEvent(update);
|
|
397
|
+
const endDrag = useEffectEvent(end);
|
|
398
|
+
const connection = useRef({ generation: 0 });
|
|
399
|
+
useBrowserLayoutEffect(() => {
|
|
400
|
+
if (!enabled)
|
|
401
|
+
end();
|
|
402
|
+
else
|
|
403
|
+
update();
|
|
404
|
+
});
|
|
405
|
+
useEffect(() => {
|
|
406
|
+
const lifecycle = connection.current;
|
|
407
|
+
const generation = ++lifecycle.generation;
|
|
408
|
+
const scroll = () => updateDrag();
|
|
409
|
+
const move = (event) => {
|
|
410
|
+
const drag = session.current;
|
|
411
|
+
const element = ref.current;
|
|
412
|
+
if (!drag || drag.pointer !== event.pointerId || !element)
|
|
413
|
+
return;
|
|
414
|
+
drag.y = event.clientY;
|
|
415
|
+
if (!drag.active && Math.abs(drag.y - drag.start) < 4)
|
|
416
|
+
return;
|
|
417
|
+
drag.active = true;
|
|
418
|
+
element.dataset.dragging = "";
|
|
419
|
+
element.style.zIndex = "1";
|
|
420
|
+
updateDrag();
|
|
421
|
+
};
|
|
422
|
+
const stop = (event) => {
|
|
423
|
+
if (session.current?.pointer === event.pointerId)
|
|
424
|
+
endDrag();
|
|
425
|
+
};
|
|
426
|
+
document.addEventListener("scroll", scroll, true);
|
|
427
|
+
document.addEventListener("pointermove", move);
|
|
428
|
+
document.addEventListener("pointerup", stop);
|
|
429
|
+
document.addEventListener("pointercancel", stop);
|
|
430
|
+
document.addEventListener("lostpointercapture", stop);
|
|
431
|
+
window.addEventListener("resize", endDrag);
|
|
432
|
+
return () => {
|
|
433
|
+
document.removeEventListener("scroll", scroll, true);
|
|
434
|
+
document.removeEventListener("pointermove", move);
|
|
435
|
+
document.removeEventListener("pointerup", stop);
|
|
436
|
+
document.removeEventListener("pointercancel", stop);
|
|
437
|
+
document.removeEventListener("lostpointercapture", stop);
|
|
438
|
+
window.removeEventListener("resize", endDrag);
|
|
439
|
+
queueMicrotask(() => {
|
|
440
|
+
if (lifecycle.generation === generation)
|
|
441
|
+
endDrag();
|
|
442
|
+
});
|
|
443
|
+
};
|
|
444
|
+
}, [ref]);
|
|
445
|
+
return {
|
|
446
|
+
onPointerDown: (event) => {
|
|
447
|
+
if (!enabled || event.button !== 0 || session.current)
|
|
448
|
+
return;
|
|
449
|
+
const element = ref.current;
|
|
450
|
+
const list = container.current;
|
|
451
|
+
if (!element || !list)
|
|
452
|
+
return;
|
|
453
|
+
list.setPointerCapture(event.pointerId);
|
|
454
|
+
session.current = {
|
|
455
|
+
pointer: event.pointerId,
|
|
456
|
+
start: event.clientY,
|
|
457
|
+
y: event.clientY,
|
|
458
|
+
grab: event.clientY - element.getBoundingClientRect().top,
|
|
459
|
+
active: false,
|
|
460
|
+
capture: list,
|
|
461
|
+
element
|
|
462
|
+
};
|
|
463
|
+
}
|
|
464
|
+
};
|
|
465
|
+
};
|
|
466
|
+
|
|
467
|
+
// ../../src/components/ui/animated-list.tsx
|
|
468
|
+
import { jsx as jsx5, jsxs as jsxs2, Fragment } from "react/jsx-runtime";
|
|
469
|
+
var labels = {
|
|
470
|
+
en: {
|
|
471
|
+
reorder: "Reorder",
|
|
472
|
+
instructions: "Drag to reorder, or use Arrow Up, Arrow Down, Home and End on the handle.",
|
|
473
|
+
position: (label, position, total) => `${label}, position ${position} of ${total}.`
|
|
474
|
+
},
|
|
475
|
+
fr: {
|
|
476
|
+
reorder: "Réordonner",
|
|
477
|
+
instructions: "Faites glisser pour réordonner, ou utilisez les flèches haut et bas, Début et Fin sur la poignée.",
|
|
478
|
+
position: (label, position, total) => `${label}, position ${position} sur ${total}.`
|
|
479
|
+
}
|
|
480
|
+
};
|
|
481
|
+
var AnimatedList = ({
|
|
482
|
+
items,
|
|
483
|
+
getKey,
|
|
484
|
+
children,
|
|
485
|
+
duration = 180,
|
|
486
|
+
className,
|
|
487
|
+
itemClassName,
|
|
488
|
+
label,
|
|
489
|
+
onReorder,
|
|
490
|
+
dragOverflow = 12,
|
|
491
|
+
getItemLabel,
|
|
492
|
+
locale: override,
|
|
493
|
+
messages
|
|
494
|
+
}) => {
|
|
495
|
+
const locale = useKrakstackLocale(override);
|
|
496
|
+
const copy = {
|
|
497
|
+
...locale.startsWith("fr") ? labels.fr : labels.en,
|
|
498
|
+
...messages?.[locale.split("-")[0] ?? locale],
|
|
499
|
+
...messages?.[locale]
|
|
500
|
+
};
|
|
501
|
+
const instructions = useId();
|
|
502
|
+
const container = useRef2(null);
|
|
503
|
+
const [announcedKey, setAnnouncedKey] = useState2(null);
|
|
504
|
+
const retained = useKeyedPresence(items, getKey);
|
|
505
|
+
const [initial, setInitial] = useState2(true);
|
|
506
|
+
useEffect2(() => setInitial(false), []);
|
|
507
|
+
useListLayout(container, duration);
|
|
508
|
+
const announcement = items.map((item, index) => getKey(item) === announcedKey ? copy.position(getItemLabel?.(item) ?? getKey(item), index + 1, items.length) : "").join("");
|
|
509
|
+
const move = (key, target) => {
|
|
510
|
+
const index = items.findIndex((item) => getKey(item) === key);
|
|
511
|
+
if (index < 0 || index === target || !onReorder)
|
|
512
|
+
return;
|
|
513
|
+
const next = [...items];
|
|
514
|
+
const [item] = next.splice(index, 1);
|
|
515
|
+
if (item === undefined)
|
|
516
|
+
return;
|
|
517
|
+
next.splice(target, 0, item);
|
|
518
|
+
setAnnouncedKey(key);
|
|
519
|
+
onReorder(next);
|
|
520
|
+
};
|
|
521
|
+
return /* @__PURE__ */ jsxs2(Fragment, {
|
|
522
|
+
children: [
|
|
523
|
+
/* @__PURE__ */ jsx5("ul", {
|
|
524
|
+
ref: container,
|
|
525
|
+
"data-slot": "animated-list",
|
|
526
|
+
className: cn2("relative grid gap-3", className),
|
|
527
|
+
"aria-label": label,
|
|
528
|
+
children: retained.items.map((item) => {
|
|
529
|
+
const key = getKey(item);
|
|
530
|
+
const index = items.findIndex((candidate) => getKey(candidate) === key);
|
|
531
|
+
return /* @__PURE__ */ jsx5(ListItem, {
|
|
532
|
+
itemKey: key,
|
|
533
|
+
present: retained.present.has(key),
|
|
534
|
+
initial,
|
|
535
|
+
duration,
|
|
536
|
+
className: itemClassName,
|
|
537
|
+
instructions,
|
|
538
|
+
handleLabel: `${copy.reorder}: ${getItemLabel?.(item) ?? key}`,
|
|
539
|
+
reorderable: !!onReorder,
|
|
540
|
+
disabled: items.length < 2,
|
|
541
|
+
container,
|
|
542
|
+
dragOverflow,
|
|
543
|
+
onExit: () => retained.remove(key),
|
|
544
|
+
onMove: (target) => move(key, target),
|
|
545
|
+
onKeyMove: (direction) => move(key, direction === "Home" ? 0 : direction === "End" ? items.length - 1 : Math.max(0, Math.min(items.length - 1, index + (direction === "ArrowUp" ? -1 : 1)))),
|
|
546
|
+
children: children(item)
|
|
547
|
+
}, key);
|
|
548
|
+
})
|
|
549
|
+
}),
|
|
550
|
+
onReorder ? /* @__PURE__ */ jsxs2(Fragment, {
|
|
551
|
+
children: [
|
|
552
|
+
/* @__PURE__ */ jsx5("p", {
|
|
553
|
+
id: instructions,
|
|
554
|
+
className: "sr-only",
|
|
555
|
+
children: copy.instructions
|
|
556
|
+
}),
|
|
557
|
+
/* @__PURE__ */ jsx5("p", {
|
|
558
|
+
role: "status",
|
|
559
|
+
"aria-live": "polite",
|
|
560
|
+
"aria-atomic": "true",
|
|
561
|
+
className: "sr-only",
|
|
562
|
+
children: announcement
|
|
563
|
+
})
|
|
564
|
+
]
|
|
565
|
+
}) : null
|
|
566
|
+
]
|
|
567
|
+
});
|
|
568
|
+
};
|
|
569
|
+
var ListItem = ({
|
|
570
|
+
itemKey,
|
|
571
|
+
present,
|
|
572
|
+
initial,
|
|
573
|
+
duration,
|
|
574
|
+
className,
|
|
575
|
+
instructions,
|
|
576
|
+
handleLabel,
|
|
577
|
+
reorderable,
|
|
578
|
+
disabled,
|
|
579
|
+
container,
|
|
580
|
+
dragOverflow,
|
|
581
|
+
onExit,
|
|
582
|
+
onMove,
|
|
583
|
+
onKeyMove,
|
|
584
|
+
children
|
|
585
|
+
}) => {
|
|
586
|
+
const ref = useRef2(null);
|
|
587
|
+
const mounted = useRef2(false);
|
|
588
|
+
const lastPresent = useRef2(present);
|
|
589
|
+
const transitioning = useRef2(false);
|
|
590
|
+
const exit = useEffectEvent2(onExit);
|
|
591
|
+
const reduced = useReducedMotion();
|
|
592
|
+
const drag = useVerticalDrag({
|
|
593
|
+
ref,
|
|
594
|
+
container,
|
|
595
|
+
enabled: reorderable && !disabled && present,
|
|
596
|
+
overflow: dragOverflow,
|
|
597
|
+
onMove
|
|
598
|
+
});
|
|
599
|
+
useEffect2(() => {
|
|
600
|
+
const element = ref.current;
|
|
601
|
+
const first = !mounted.current;
|
|
602
|
+
mounted.current = true;
|
|
603
|
+
if (!element || first && initial && present)
|
|
604
|
+
return;
|
|
605
|
+
if (!first && lastPresent.current === present && !transitioning.current)
|
|
606
|
+
return;
|
|
607
|
+
lastPresent.current = present;
|
|
608
|
+
transitioning.current = true;
|
|
609
|
+
return animateElement(element, [{ opacity: present ? 0 : 1 }, { opacity: present ? 1 : 0 }], reduced ? 0 : Math.max(0, duration), () => {
|
|
610
|
+
transitioning.current = false;
|
|
611
|
+
if (!present)
|
|
612
|
+
exit();
|
|
613
|
+
});
|
|
614
|
+
}, [present, initial, duration, reduced]);
|
|
615
|
+
return /* @__PURE__ */ jsxs2("li", {
|
|
616
|
+
ref,
|
|
617
|
+
"data-slot": "animated-list-item",
|
|
618
|
+
"data-motion-key": itemKey,
|
|
619
|
+
className: cn2("relative", className),
|
|
620
|
+
inert: !present,
|
|
621
|
+
"aria-hidden": !present ? true : undefined,
|
|
622
|
+
children: [
|
|
623
|
+
reorderable ? /* @__PURE__ */ jsx5("button", {
|
|
624
|
+
"data-slot": "animated-list-handle",
|
|
625
|
+
type: "button",
|
|
626
|
+
disabled: disabled || !present,
|
|
627
|
+
"aria-label": handleLabel,
|
|
628
|
+
"aria-describedby": instructions,
|
|
629
|
+
className: "text-muted-foreground focus-visible:ring-ring inline-flex size-8 shrink-0 cursor-grab touch-none items-center justify-center rounded-md outline-none select-none focus-visible:ring-2 active:cursor-grabbing disabled:cursor-default disabled:opacity-50",
|
|
630
|
+
...drag,
|
|
631
|
+
onKeyDown: (event) => {
|
|
632
|
+
if (event.altKey || event.ctrlKey || event.metaKey || event.shiftKey)
|
|
633
|
+
return;
|
|
634
|
+
if (event.key === "ArrowUp" || event.key === "ArrowDown" || event.key === "Home" || event.key === "End") {
|
|
635
|
+
event.preventDefault();
|
|
636
|
+
event.stopPropagation();
|
|
637
|
+
onKeyMove(event.key);
|
|
638
|
+
}
|
|
639
|
+
},
|
|
640
|
+
children: /* @__PURE__ */ jsx5(GripVertical, {
|
|
641
|
+
className: "size-4",
|
|
642
|
+
"aria-hidden": "true"
|
|
643
|
+
})
|
|
644
|
+
}) : null,
|
|
645
|
+
children
|
|
646
|
+
]
|
|
647
|
+
});
|
|
648
|
+
};
|
|
649
|
+
|
|
650
|
+
// ../../src/components/ui/rich-text-editor.tsx
|
|
651
|
+
import { Schema as Schema4 } from "effect";
|
|
652
|
+
import {
|
|
653
|
+
useEffect as useEffect3,
|
|
654
|
+
useEffectEvent as useEffectEvent3,
|
|
655
|
+
useId as useId2,
|
|
656
|
+
useRef as useRef3,
|
|
657
|
+
useState as useState3
|
|
658
|
+
} from "react";
|
|
659
|
+
import {
|
|
660
|
+
Bold,
|
|
661
|
+
Italic,
|
|
662
|
+
Underline,
|
|
663
|
+
Undo2,
|
|
664
|
+
Redo2,
|
|
665
|
+
Link2,
|
|
666
|
+
Unlink,
|
|
667
|
+
Braces,
|
|
668
|
+
ChevronDown
|
|
669
|
+
} from "lucide-react";
|
|
670
|
+
|
|
671
|
+
// ../../src/components/ui/dropdown-menu.tsx
|
|
672
|
+
import { Menu as MenuPrimitive } from "@base-ui/react/menu";
|
|
673
|
+
import { ChevronRightIcon, CheckIcon as CheckIcon2 } from "lucide-react";
|
|
674
|
+
import { jsx as jsx6, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
675
|
+
function DropdownMenu({ ...props }) {
|
|
676
|
+
return /* @__PURE__ */ jsx6(MenuPrimitive.Root, {
|
|
677
|
+
"data-slot": "dropdown-menu",
|
|
678
|
+
...props
|
|
679
|
+
});
|
|
680
|
+
}
|
|
681
|
+
function DropdownMenuTrigger({ ...props }) {
|
|
682
|
+
return /* @__PURE__ */ jsx6(MenuPrimitive.Trigger, {
|
|
683
|
+
"data-slot": "dropdown-menu-trigger",
|
|
684
|
+
...props
|
|
685
|
+
});
|
|
686
|
+
}
|
|
687
|
+
function DropdownMenuContent({
|
|
688
|
+
align = "start",
|
|
689
|
+
alignOffset = 0,
|
|
690
|
+
side = "bottom",
|
|
691
|
+
sideOffset = 4,
|
|
692
|
+
className,
|
|
693
|
+
...props
|
|
694
|
+
}) {
|
|
695
|
+
return /* @__PURE__ */ jsx6(MenuPrimitive.Portal, {
|
|
696
|
+
children: /* @__PURE__ */ jsx6(MenuPrimitive.Positioner, {
|
|
697
|
+
className: "isolate z-50 outline-none",
|
|
698
|
+
align,
|
|
699
|
+
alignOffset,
|
|
700
|
+
side,
|
|
701
|
+
sideOffset,
|
|
702
|
+
children: /* @__PURE__ */ jsx6(MenuPrimitive.Popup, {
|
|
703
|
+
"data-slot": "dropdown-menu-content",
|
|
704
|
+
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),
|
|
705
|
+
...props
|
|
706
|
+
})
|
|
707
|
+
})
|
|
708
|
+
});
|
|
709
|
+
}
|
|
710
|
+
function DropdownMenuItem({
|
|
711
|
+
className,
|
|
712
|
+
inset,
|
|
713
|
+
variant = "default",
|
|
714
|
+
...props
|
|
715
|
+
}) {
|
|
716
|
+
return /* @__PURE__ */ jsx6(MenuPrimitive.Item, {
|
|
717
|
+
"data-slot": "dropdown-menu-item",
|
|
718
|
+
"data-inset": inset,
|
|
719
|
+
"data-variant": variant,
|
|
720
|
+
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),
|
|
721
|
+
...props
|
|
722
|
+
});
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
// ../../src/components/ui/rich-text-editor.tsx
|
|
726
|
+
import { useKrakstackLocale as useKrakstackLocale2 } from "@krak-stack/registry/krakstack-provider";
|
|
727
|
+
|
|
728
|
+
// ../../src/lib/rich-text/schema.ts
|
|
729
|
+
import { Schema } from "effect";
|
|
730
|
+
var RichTextLink = Schema.String.check(Schema.isMaxLength(2000), Schema.makeFilter((value) => {
|
|
731
|
+
if (/[\s\p{Cc}\\{}]/u.test(value))
|
|
732
|
+
return false;
|
|
733
|
+
const url = URL.parse(value);
|
|
734
|
+
return url !== null && ["https:", "mailto:"].includes(url.protocol) && !url.username && !url.password;
|
|
735
|
+
})).annotate({ identifier: "RichTextLink" });
|
|
736
|
+
var RichTextMarks = Schema.Struct({
|
|
737
|
+
bold: Schema.optional(Schema.Boolean),
|
|
738
|
+
italic: Schema.optional(Schema.Boolean),
|
|
739
|
+
underline: Schema.optional(Schema.Boolean),
|
|
740
|
+
href: Schema.optional(RichTextLink)
|
|
741
|
+
}).annotate({ identifier: "RichTextMarks" });
|
|
742
|
+
var RichTextInline = Schema.Union([
|
|
743
|
+
Schema.Struct({
|
|
744
|
+
type: Schema.Literal("text"),
|
|
745
|
+
text: Schema.String.check(Schema.isMaxLength(20000)),
|
|
746
|
+
marks: Schema.optional(RichTextMarks)
|
|
747
|
+
}),
|
|
748
|
+
Schema.Struct({
|
|
749
|
+
type: Schema.Literal("variable"),
|
|
750
|
+
key: Schema.String.check(Schema.isPattern(/^[a-zA-Z][a-zA-Z0-9_.]{0,79}$/)),
|
|
751
|
+
marks: Schema.optional(RichTextMarks)
|
|
752
|
+
})
|
|
753
|
+
]).annotate({ identifier: "RichTextInline" });
|
|
754
|
+
var RichTextBlockKind = Schema.Literals([
|
|
755
|
+
"paragraph",
|
|
756
|
+
"heading",
|
|
757
|
+
"bullet",
|
|
758
|
+
"numbered"
|
|
759
|
+
]).annotate({ identifier: "RichTextBlockKind" });
|
|
760
|
+
var RichTextDocument = Schema.Struct({
|
|
761
|
+
version: Schema.Literal(1),
|
|
762
|
+
blocks: Schema.Array(Schema.Struct({
|
|
763
|
+
type: RichTextBlockKind,
|
|
764
|
+
content: Schema.Array(RichTextInline).check(Schema.isMaxLength(2000))
|
|
765
|
+
})).check(Schema.isMinLength(1), Schema.isMaxLength(100))
|
|
766
|
+
}).check(Schema.makeFilter((value) => value.blocks.reduce((size, block) => size + block.content.reduce((count, inline) => count + (inline.type === "text" ? inline.text.length : 1), 0), 0) <= 20000)).annotate({ identifier: "RichTextDocument" });
|
|
767
|
+
var RichTextVariable = Schema.Struct({
|
|
768
|
+
key: Schema.String.check(Schema.isPattern(/^[a-zA-Z][a-zA-Z0-9_.]{0,79}$/)),
|
|
769
|
+
label: Schema.String,
|
|
770
|
+
type: Schema.Literals(["text", "url"]),
|
|
771
|
+
sample: Schema.String
|
|
772
|
+
}).annotate({ identifier: "RichTextVariable" });
|
|
773
|
+
|
|
774
|
+
// ../../src/lib/rich-text/model.ts
|
|
775
|
+
import { Schema as Schema2 } from "effect";
|
|
776
|
+
var sameMarks = Schema2.toEquivalence(RichTextMarks);
|
|
777
|
+
var emptyRichText = () => ({
|
|
778
|
+
version: 1,
|
|
779
|
+
blocks: [{ type: "paragraph", content: [] }]
|
|
780
|
+
});
|
|
781
|
+
var richTextFromString = (text) => ({
|
|
782
|
+
version: 1,
|
|
783
|
+
blocks: text.split(/\r\n?|\n/).map((line) => ({
|
|
784
|
+
type: "paragraph",
|
|
785
|
+
content: line ? [{ type: "text", text: line }] : []
|
|
786
|
+
}))
|
|
787
|
+
});
|
|
788
|
+
var richTextPlainText = (value, variables) => value.blocks.map((block) => block.content.map((inline) => inline.type === "text" ? inline.text : variables?.[inline.key] ?? `{{${inline.key}}}`).join("")).join(`
|
|
789
|
+
`);
|
|
790
|
+
var units = (value) => value.blocks.flatMap((block, index) => [
|
|
791
|
+
...index ? [{ type: "break", next: block.type }] : [],
|
|
792
|
+
...block.content.flatMap((inline) => inline.type === "text" ? inline.text.split("").map((text) => ({ ...inline, text })) : [inline])
|
|
793
|
+
]);
|
|
794
|
+
var fromUnits = (content, first) => {
|
|
795
|
+
const blocks = [{ type: first, content: [] }];
|
|
796
|
+
for (const unit of content) {
|
|
797
|
+
if (unit.type === "break") {
|
|
798
|
+
blocks.push({ type: unit.next, content: [] });
|
|
799
|
+
continue;
|
|
800
|
+
}
|
|
801
|
+
const target = blocks.at(-1);
|
|
802
|
+
if (!target)
|
|
803
|
+
continue;
|
|
804
|
+
const previous = target.content.at(-1);
|
|
805
|
+
if (unit.type === "text" && previous?.type === "text" && sameMarks(previous.marks ?? {}, unit.marks ?? {})) {
|
|
806
|
+
target.content[target.content.length - 1] = {
|
|
807
|
+
...previous,
|
|
808
|
+
text: previous.text + unit.text
|
|
809
|
+
};
|
|
810
|
+
} else
|
|
811
|
+
target.content.push(unit);
|
|
812
|
+
}
|
|
813
|
+
return { version: 1, blocks };
|
|
814
|
+
};
|
|
815
|
+
var replaceRichText = (value, selection, inserted) => {
|
|
816
|
+
const content = units(value);
|
|
817
|
+
const from = Math.max(0, Math.min(selection.from, content.length));
|
|
818
|
+
const to = Math.max(from, Math.min(selection.to, content.length));
|
|
819
|
+
const additions = inserted.type === "text" ? inserted.text.replace(/\r\n?/g, `
|
|
820
|
+
`).split("").map((text) => text === `
|
|
821
|
+
` ? { type: "break", next: "paragraph" } : { type: "text", text, marks: inserted.marks }) : [inserted];
|
|
822
|
+
const next = fromUnits([...content.slice(0, from), ...additions, ...content.slice(to)], value.blocks[0]?.type ?? "paragraph");
|
|
823
|
+
const position = from + additions.length;
|
|
824
|
+
return { value: next, selection: { from: position, to: position } };
|
|
825
|
+
};
|
|
826
|
+
var formatRichText = (value, selection, mark, setting) => fromUnits(units(value).map((unit, index) => {
|
|
827
|
+
if (unit.type === "break" || index < selection.from || index >= selection.to)
|
|
828
|
+
return unit;
|
|
829
|
+
const marks = { ...unit.marks, [mark]: setting };
|
|
830
|
+
return { ...unit, marks };
|
|
831
|
+
}), value.blocks[0]?.type ?? "paragraph");
|
|
832
|
+
var setRichTextBlock = (value, selection, type) => {
|
|
833
|
+
let offset = 0;
|
|
834
|
+
return {
|
|
835
|
+
...value,
|
|
836
|
+
blocks: value.blocks.map((block) => {
|
|
837
|
+
const start = offset;
|
|
838
|
+
offset += block.content.reduce((size, inline) => size + (inline.type === "text" ? inline.text.length : 1), 0) + 1;
|
|
839
|
+
return selection.from < offset && selection.to >= start ? { ...block, type } : block;
|
|
840
|
+
})
|
|
841
|
+
};
|
|
842
|
+
};
|
|
843
|
+
var richTextMarksAt = (value, position) => {
|
|
844
|
+
const content = units(value);
|
|
845
|
+
const unit = content[Math.max(0, position - 1)];
|
|
846
|
+
return unit && unit.type !== "break" ? unit.marks ?? {} : {};
|
|
847
|
+
};
|
|
848
|
+
|
|
849
|
+
// ../../src/lib/rich-text/dom.ts
|
|
850
|
+
import { Option, Schema as Schema3 } from "effect";
|
|
851
|
+
var blocks = new Set(["P", "DIV", "H1", "H2", "H3", "LI"]);
|
|
852
|
+
var sameMarks2 = Schema3.toEquivalence(RichTextMarks);
|
|
853
|
+
var pointAfter = (node) => ({
|
|
854
|
+
node: node.parentNode ?? node,
|
|
855
|
+
offset: Array.from(node.parentNode?.childNodes ?? []).indexOf(node) + 1
|
|
856
|
+
});
|
|
857
|
+
var readRichTextDOM = (root) => {
|
|
858
|
+
const result = [];
|
|
859
|
+
const points = [{ node: root, offset: 0 }];
|
|
860
|
+
let current;
|
|
861
|
+
const begin = (type, point) => {
|
|
862
|
+
if (current)
|
|
863
|
+
result.push(current);
|
|
864
|
+
if (result.length)
|
|
865
|
+
points.push(point);
|
|
866
|
+
else
|
|
867
|
+
points[0] = point;
|
|
868
|
+
current = { type, content: [] };
|
|
869
|
+
};
|
|
870
|
+
const append = (inline, point) => {
|
|
871
|
+
if (!current)
|
|
872
|
+
begin("paragraph", point);
|
|
873
|
+
const previous = current?.content.at(-1);
|
|
874
|
+
if (inline.type === "text" && previous?.type === "text" && sameMarks2(inline.marks ?? {}, previous.marks ?? {})) {
|
|
875
|
+
if (current)
|
|
876
|
+
current.content[current.content.length - 1] = {
|
|
877
|
+
...previous,
|
|
878
|
+
text: previous.text + inline.text
|
|
879
|
+
};
|
|
880
|
+
} else
|
|
881
|
+
current?.content.push(inline);
|
|
882
|
+
points.push(point);
|
|
883
|
+
};
|
|
884
|
+
const visit = (node, inherited = {}, kind = "paragraph") => {
|
|
885
|
+
if (node instanceof Text) {
|
|
886
|
+
if (!current)
|
|
887
|
+
begin(kind, { node, offset: 0 });
|
|
888
|
+
for (let index = 0;index < node.data.length; index++)
|
|
889
|
+
append({ type: "text", text: node.data[index] ?? "", marks: inherited }, { node, offset: index + 1 });
|
|
890
|
+
return;
|
|
891
|
+
}
|
|
892
|
+
if (!(node instanceof HTMLElement) || ["SCRIPT", "STYLE", "IFRAME"].includes(node.tagName))
|
|
893
|
+
return;
|
|
894
|
+
const key = node.dataset.richVariable;
|
|
895
|
+
if (key) {
|
|
896
|
+
const variable = { type: "variable", key, marks: inherited };
|
|
897
|
+
append(variable, pointAfter(node));
|
|
898
|
+
return;
|
|
899
|
+
}
|
|
900
|
+
const href = node.getAttribute("href");
|
|
901
|
+
const marks = {
|
|
902
|
+
bold: inherited.bold,
|
|
903
|
+
italic: inherited.italic,
|
|
904
|
+
underline: inherited.underline,
|
|
905
|
+
href: inherited.href
|
|
906
|
+
};
|
|
907
|
+
if (["B", "STRONG"].includes(node.tagName) || node.style.fontWeight === "700")
|
|
908
|
+
marks.bold = true;
|
|
909
|
+
if (["I", "EM"].includes(node.tagName) || node.style.fontStyle === "italic")
|
|
910
|
+
marks.italic = true;
|
|
911
|
+
if (node.tagName === "U" || node.style.textDecoration.includes("underline"))
|
|
912
|
+
marks.underline = true;
|
|
913
|
+
if (href && Schema3.is(RichTextLink)(href))
|
|
914
|
+
marks.href = href;
|
|
915
|
+
const type = node.dataset.richKind === "bullet" ? "bullet" : node.dataset.richKind === "numbered" ? "numbered" : /^H[123]$/.test(node.tagName) ? "heading" : node.tagName === "LI" ? node.parentElement?.tagName === "OL" ? "numbered" : "bullet" : kind;
|
|
916
|
+
const isBlock = blocks.has(node.tagName);
|
|
917
|
+
const container = isBlock && [...node.children].some((child) => blocks.has(child.tagName));
|
|
918
|
+
if (isBlock && !container)
|
|
919
|
+
begin(type, { node, offset: 0 });
|
|
920
|
+
if (node.tagName === "BR") {
|
|
921
|
+
if (node.nextSibling)
|
|
922
|
+
begin(kind, pointAfter(node));
|
|
923
|
+
return;
|
|
924
|
+
}
|
|
925
|
+
for (const child of node.childNodes)
|
|
926
|
+
visit(child, marks, type);
|
|
927
|
+
};
|
|
928
|
+
for (const child of root.childNodes)
|
|
929
|
+
visit(child);
|
|
930
|
+
if (current)
|
|
931
|
+
result.push(current);
|
|
932
|
+
const value = Option.getOrUndefined(Schema3.decodeOption(RichTextDocument)({
|
|
933
|
+
version: 1,
|
|
934
|
+
blocks: result.length ? result : emptyRichText().blocks
|
|
935
|
+
}));
|
|
936
|
+
return { value, points };
|
|
937
|
+
};
|
|
938
|
+
var readEditorSelection = (root, points) => {
|
|
939
|
+
const selection = root.ownerDocument.getSelection();
|
|
940
|
+
if (!selection?.anchorNode || !selection.focusNode || !root.contains(selection.anchorNode) || !root.contains(selection.focusNode))
|
|
941
|
+
return;
|
|
942
|
+
const position = (node, offset) => {
|
|
943
|
+
const range = root.ownerDocument.createRange();
|
|
944
|
+
range.setStart(node, offset);
|
|
945
|
+
range.collapse(true);
|
|
946
|
+
let result = 0;
|
|
947
|
+
points.forEach((point, index) => {
|
|
948
|
+
if (root.contains(point.node) && range.comparePoint(point.node, point.offset) <= 0)
|
|
949
|
+
result = index;
|
|
950
|
+
});
|
|
951
|
+
return result;
|
|
952
|
+
};
|
|
953
|
+
const anchor = position(selection.anchorNode, selection.anchorOffset);
|
|
954
|
+
const focus = position(selection.focusNode, selection.focusOffset);
|
|
955
|
+
return { from: Math.min(anchor, focus), to: Math.max(anchor, focus) };
|
|
956
|
+
};
|
|
957
|
+
var restoreRichTextSelection = (root, selection) => {
|
|
958
|
+
const { points } = readRichTextDOM(root);
|
|
959
|
+
const start = points[Math.min(selection.from, points.length - 1)];
|
|
960
|
+
const end = points[Math.min(selection.to, points.length - 1)];
|
|
961
|
+
if (!start || !end)
|
|
962
|
+
return;
|
|
963
|
+
const range = root.ownerDocument.createRange();
|
|
964
|
+
range.setStart(start.node, start.offset);
|
|
965
|
+
range.setEnd(end.node, end.offset);
|
|
966
|
+
root.ownerDocument.getSelection()?.removeAllRanges();
|
|
967
|
+
root.ownerDocument.getSelection()?.addRange(range);
|
|
968
|
+
};
|
|
969
|
+
var writeRichTextDOM = (root, value, variables) => {
|
|
970
|
+
const children = value.blocks.map((block) => {
|
|
971
|
+
const paragraph = root.ownerDocument.createElement(block.type === "heading" ? "h2" : "div");
|
|
972
|
+
if (block.type === "heading")
|
|
973
|
+
paragraph.style.cssText = "font-size:1.4em;font-weight:700";
|
|
974
|
+
if (block.type === "bullet" || block.type === "numbered") {
|
|
975
|
+
paragraph.dataset.richKind = block.type;
|
|
976
|
+
paragraph.style.cssText = `display:list-item;margin-left:1.5em;list-style-type:${block.type === "bullet" ? "disc" : "decimal"}`;
|
|
977
|
+
}
|
|
978
|
+
for (const inline of block.content) {
|
|
979
|
+
const span = root.ownerDocument.createElement(inline.marks?.href ? "a" : "span");
|
|
980
|
+
if (inline.type === "variable") {
|
|
981
|
+
span.dataset.richVariable = inline.key;
|
|
982
|
+
span.contentEditable = "false";
|
|
983
|
+
span.textContent = `{{${variables.find((item) => item.key === inline.key)?.label ?? inline.key}}}`;
|
|
984
|
+
span.className = "mx-0.5 inline-block rounded bg-indigo-50 px-1 font-mono text-[0.85em] text-indigo-800";
|
|
985
|
+
} else
|
|
986
|
+
span.textContent = inline.text;
|
|
987
|
+
if (inline.marks?.bold)
|
|
988
|
+
span.style.fontWeight = "700";
|
|
989
|
+
if (inline.marks?.italic)
|
|
990
|
+
span.style.fontStyle = "italic";
|
|
991
|
+
if (inline.marks?.underline)
|
|
992
|
+
span.style.textDecoration = "underline";
|
|
993
|
+
if (inline.marks?.href) {
|
|
994
|
+
span.setAttribute("href", inline.marks.href);
|
|
995
|
+
span.style.textDecoration = "underline";
|
|
996
|
+
}
|
|
997
|
+
paragraph.append(span);
|
|
998
|
+
}
|
|
999
|
+
if (!block.content.length)
|
|
1000
|
+
paragraph.append(root.ownerDocument.createElement("br"));
|
|
1001
|
+
return paragraph;
|
|
1002
|
+
});
|
|
1003
|
+
root.replaceChildren(...children);
|
|
1004
|
+
};
|
|
1005
|
+
|
|
1006
|
+
// ../../src/components/ui/rich-text-editor.tsx
|
|
1007
|
+
import { jsx as jsx7, jsxs as jsxs4, Fragment as Fragment2 } from "react/jsx-runtime";
|
|
1008
|
+
var labels2 = {
|
|
1009
|
+
en: {
|
|
1010
|
+
bold: "Bold",
|
|
1011
|
+
italic: "Italic",
|
|
1012
|
+
underline: "Underline",
|
|
1013
|
+
undo: "Undo",
|
|
1014
|
+
redo: "Redo",
|
|
1015
|
+
link: "Link",
|
|
1016
|
+
unlink: "Remove link",
|
|
1017
|
+
linkUrl: "Link URL",
|
|
1018
|
+
apply: "Apply link",
|
|
1019
|
+
variable: "Insert variable",
|
|
1020
|
+
paragraph: "Paragraph",
|
|
1021
|
+
heading: "Heading",
|
|
1022
|
+
bullet: "Bulleted list",
|
|
1023
|
+
numbered: "Numbered list",
|
|
1024
|
+
toolbar: "Text formatting",
|
|
1025
|
+
invalid: "The content is too long or contains an unsupported value.",
|
|
1026
|
+
invalidLink: "Enter an HTTPS or mailto link.",
|
|
1027
|
+
cancel: "Cancel"
|
|
1028
|
+
},
|
|
1029
|
+
fr: {
|
|
1030
|
+
bold: "Gras",
|
|
1031
|
+
italic: "Italique",
|
|
1032
|
+
underline: "Souligné",
|
|
1033
|
+
undo: "Annuler",
|
|
1034
|
+
redo: "Rétablir",
|
|
1035
|
+
link: "Lien",
|
|
1036
|
+
unlink: "Retirer le lien",
|
|
1037
|
+
linkUrl: "URL du lien",
|
|
1038
|
+
apply: "Appliquer le lien",
|
|
1039
|
+
variable: "Insérer une variable",
|
|
1040
|
+
paragraph: "Paragraphe",
|
|
1041
|
+
heading: "Titre",
|
|
1042
|
+
bullet: "Liste à puces",
|
|
1043
|
+
numbered: "Liste numérotée",
|
|
1044
|
+
toolbar: "Mise en forme",
|
|
1045
|
+
invalid: "Le contenu est trop long ou contient une valeur non prise en charge.",
|
|
1046
|
+
invalidLink: "Saisissez un lien HTTPS ou mailto.",
|
|
1047
|
+
cancel: "Annuler"
|
|
1048
|
+
}
|
|
1049
|
+
};
|
|
1050
|
+
var equivalent = Schema4.toEquivalence(RichTextDocument);
|
|
1051
|
+
var ToolButton = ({
|
|
1052
|
+
label,
|
|
1053
|
+
children,
|
|
1054
|
+
onClick,
|
|
1055
|
+
pressed,
|
|
1056
|
+
disabled
|
|
1057
|
+
}) => /* @__PURE__ */ jsx7(Button, {
|
|
1058
|
+
type: "button",
|
|
1059
|
+
size: "icon-sm",
|
|
1060
|
+
variant: pressed ? "secondary" : "ghost",
|
|
1061
|
+
"aria-label": label,
|
|
1062
|
+
title: label,
|
|
1063
|
+
"aria-pressed": pressed,
|
|
1064
|
+
disabled,
|
|
1065
|
+
onPointerDown: (event) => event.preventDefault(),
|
|
1066
|
+
onClick,
|
|
1067
|
+
children
|
|
1068
|
+
});
|
|
1069
|
+
var inlineContent = (inline, variables, values) => {
|
|
1070
|
+
let content = inline.type === "text" ? inline.text : values?.[inline.key] ?? /* @__PURE__ */ jsx7("span", {
|
|
1071
|
+
contentEditable: false,
|
|
1072
|
+
"data-rich-variable": inline.key,
|
|
1073
|
+
className: "inline-block rounded bg-indigo-50 px-1.5 font-mono text-[0.85em] text-indigo-800 select-all",
|
|
1074
|
+
children: `{{${variables.find((variable) => variable.key === inline.key)?.label ?? inline.key}}}`
|
|
1075
|
+
});
|
|
1076
|
+
if (inline.marks?.bold)
|
|
1077
|
+
content = /* @__PURE__ */ jsx7("strong", {
|
|
1078
|
+
children: content
|
|
1079
|
+
});
|
|
1080
|
+
if (inline.marks?.italic)
|
|
1081
|
+
content = /* @__PURE__ */ jsx7("em", {
|
|
1082
|
+
children: content
|
|
1083
|
+
});
|
|
1084
|
+
if (inline.marks?.underline)
|
|
1085
|
+
content = /* @__PURE__ */ jsx7("u", {
|
|
1086
|
+
children: content
|
|
1087
|
+
});
|
|
1088
|
+
if (inline.marks?.href)
|
|
1089
|
+
content = /* @__PURE__ */ jsx7("a", {
|
|
1090
|
+
href: inline.marks.href,
|
|
1091
|
+
className: "underline",
|
|
1092
|
+
children: content
|
|
1093
|
+
});
|
|
1094
|
+
return content;
|
|
1095
|
+
};
|
|
1096
|
+
var RichTextContent = ({
|
|
1097
|
+
value,
|
|
1098
|
+
variables = [],
|
|
1099
|
+
values
|
|
1100
|
+
}) => /* @__PURE__ */ jsx7(Fragment2, {
|
|
1101
|
+
children: value.blocks.map((block, index) => {
|
|
1102
|
+
const content = block.content.map((inline, key) => /* @__PURE__ */ jsx7("span", {
|
|
1103
|
+
children: inlineContent(inline, variables, values)
|
|
1104
|
+
}, key));
|
|
1105
|
+
if (block.type === "heading")
|
|
1106
|
+
return /* @__PURE__ */ jsx7("h2", {
|
|
1107
|
+
className: "text-xl font-semibold",
|
|
1108
|
+
children: content.length ? content : /* @__PURE__ */ jsx7("br", {})
|
|
1109
|
+
}, index);
|
|
1110
|
+
return /* @__PURE__ */ jsx7("div", {
|
|
1111
|
+
"data-rich-kind": block.type,
|
|
1112
|
+
style: block.type === "bullet" || block.type === "numbered" ? {
|
|
1113
|
+
display: "list-item",
|
|
1114
|
+
marginLeft: "1.5em",
|
|
1115
|
+
listStyleType: block.type === "bullet" ? "disc" : "decimal"
|
|
1116
|
+
} : undefined,
|
|
1117
|
+
children: content.length ? content : /* @__PURE__ */ jsx7("br", {})
|
|
1118
|
+
}, index);
|
|
1119
|
+
})
|
|
1120
|
+
});
|
|
1121
|
+
var RichTextEditor = ({
|
|
1122
|
+
value,
|
|
1123
|
+
onChange,
|
|
1124
|
+
label,
|
|
1125
|
+
variables = [],
|
|
1126
|
+
disabled,
|
|
1127
|
+
locale: override,
|
|
1128
|
+
messages,
|
|
1129
|
+
className,
|
|
1130
|
+
contentStyle,
|
|
1131
|
+
singleLine = false,
|
|
1132
|
+
maxLength
|
|
1133
|
+
}) => {
|
|
1134
|
+
const locale = useKrakstackLocale2(override);
|
|
1135
|
+
const copy = {
|
|
1136
|
+
...locale.startsWith("fr") ? labels2.fr : labels2.en,
|
|
1137
|
+
...messages?.[locale.split("-")[0] ?? locale],
|
|
1138
|
+
...messages?.[locale]
|
|
1139
|
+
};
|
|
1140
|
+
const root = useRef3(null);
|
|
1141
|
+
const model = useRef3(value);
|
|
1142
|
+
const composing = useRef3(false);
|
|
1143
|
+
const selected = useRef3({ from: 0, to: 0 });
|
|
1144
|
+
const history = useRef3([
|
|
1145
|
+
{ value, selection: { from: 0, to: 0 } }
|
|
1146
|
+
]);
|
|
1147
|
+
const cursor = useRef3(0);
|
|
1148
|
+
const [marks, setMarks] = useState3({});
|
|
1149
|
+
const pendingMarks = useRef3(null);
|
|
1150
|
+
const [error, setError] = useState3(false);
|
|
1151
|
+
const [linkOpen, setLinkOpen] = useState3(false);
|
|
1152
|
+
const [link, setLink] = useState3("");
|
|
1153
|
+
const [linkError, setLinkError] = useState3(false);
|
|
1154
|
+
const [revision, setRevision] = useState3(0);
|
|
1155
|
+
const [historyState, setHistoryState] = useState3({
|
|
1156
|
+
undo: false,
|
|
1157
|
+
redo: false
|
|
1158
|
+
});
|
|
1159
|
+
const id = useId2();
|
|
1160
|
+
const [initial] = useState3(() => /* @__PURE__ */ jsx7(RichTextContent, {
|
|
1161
|
+
value,
|
|
1162
|
+
variables
|
|
1163
|
+
}));
|
|
1164
|
+
const selection = () => {
|
|
1165
|
+
const element = root.current;
|
|
1166
|
+
if (!element)
|
|
1167
|
+
return selected.current;
|
|
1168
|
+
const next = readEditorSelection(element, readRichTextDOM(element).points);
|
|
1169
|
+
if (next)
|
|
1170
|
+
selected.current = next;
|
|
1171
|
+
return selected.current;
|
|
1172
|
+
};
|
|
1173
|
+
const focusEditor = () => {
|
|
1174
|
+
const element = root.current;
|
|
1175
|
+
if (element) {
|
|
1176
|
+
element.focus();
|
|
1177
|
+
restoreRichTextSelection(element, selected.current);
|
|
1178
|
+
}
|
|
1179
|
+
return false;
|
|
1180
|
+
};
|
|
1181
|
+
const commit = (next, range, write = true, record = true) => {
|
|
1182
|
+
const element = root.current;
|
|
1183
|
+
if (!element || disabled)
|
|
1184
|
+
return;
|
|
1185
|
+
const original = next;
|
|
1186
|
+
if (singleLine) {
|
|
1187
|
+
next = {
|
|
1188
|
+
version: 1,
|
|
1189
|
+
blocks: [
|
|
1190
|
+
{
|
|
1191
|
+
type: "paragraph",
|
|
1192
|
+
content: next.blocks.flatMap((block, index) => [
|
|
1193
|
+
...index ? [{ type: "text", text: " " }] : [],
|
|
1194
|
+
...block.content.map((inline) => inline.type === "variable" ? { type: "variable", key: inline.key } : {
|
|
1195
|
+
type: "text",
|
|
1196
|
+
text: inline.text.replace(/[\r\n]+/g, " ")
|
|
1197
|
+
})
|
|
1198
|
+
])
|
|
1199
|
+
}
|
|
1200
|
+
]
|
|
1201
|
+
};
|
|
1202
|
+
if (!equivalent(original, next))
|
|
1203
|
+
write = true;
|
|
1204
|
+
}
|
|
1205
|
+
if (!Schema4.is(RichTextDocument)(next) || maxLength !== undefined && richTextPlainText(next).length > maxLength) {
|
|
1206
|
+
setError(true);
|
|
1207
|
+
writeRichTextDOM(element, model.current, variables);
|
|
1208
|
+
element.focus();
|
|
1209
|
+
restoreRichTextSelection(element, selected.current);
|
|
1210
|
+
return;
|
|
1211
|
+
}
|
|
1212
|
+
setError(false);
|
|
1213
|
+
if (record && !equivalent(model.current, next)) {
|
|
1214
|
+
history.current[cursor.current] = {
|
|
1215
|
+
value: model.current,
|
|
1216
|
+
selection: selected.current
|
|
1217
|
+
};
|
|
1218
|
+
history.current = [
|
|
1219
|
+
...history.current.slice(0, cursor.current + 1),
|
|
1220
|
+
{ value: next, selection: range }
|
|
1221
|
+
].slice(-100);
|
|
1222
|
+
cursor.current = history.current.length - 1;
|
|
1223
|
+
}
|
|
1224
|
+
model.current = next;
|
|
1225
|
+
selected.current = range;
|
|
1226
|
+
if (write) {
|
|
1227
|
+
writeRichTextDOM(element, next, variables);
|
|
1228
|
+
element.focus();
|
|
1229
|
+
restoreRichTextSelection(element, range);
|
|
1230
|
+
}
|
|
1231
|
+
setRevision((current) => current + 1);
|
|
1232
|
+
setHistoryState({
|
|
1233
|
+
undo: cursor.current > 0,
|
|
1234
|
+
redo: cursor.current < history.current.length - 1
|
|
1235
|
+
});
|
|
1236
|
+
onChange(next);
|
|
1237
|
+
};
|
|
1238
|
+
const travel = (direction) => {
|
|
1239
|
+
const index = Math.max(0, Math.min(history.current.length - 1, cursor.current + direction));
|
|
1240
|
+
const snapshot = history.current[index];
|
|
1241
|
+
if (!snapshot || index === cursor.current)
|
|
1242
|
+
return;
|
|
1243
|
+
cursor.current = index;
|
|
1244
|
+
pendingMarks.current = null;
|
|
1245
|
+
commit(snapshot.value, snapshot.selection, true, false);
|
|
1246
|
+
};
|
|
1247
|
+
const insert = (inline) => {
|
|
1248
|
+
const result = replaceRichText(model.current, selection(), inline);
|
|
1249
|
+
commit(result.value, result.selection);
|
|
1250
|
+
};
|
|
1251
|
+
const format = (mark) => {
|
|
1252
|
+
const range = selection();
|
|
1253
|
+
const next = {
|
|
1254
|
+
...pendingMarks.current ?? richTextMarksAt(model.current, range.to),
|
|
1255
|
+
[mark]: !marks[mark]
|
|
1256
|
+
};
|
|
1257
|
+
setMarks(next);
|
|
1258
|
+
if (range.from === range.to) {
|
|
1259
|
+
pendingMarks.current = next;
|
|
1260
|
+
root.current?.focus();
|
|
1261
|
+
} else
|
|
1262
|
+
commit(formatRichText(model.current, range, mark, next[mark]), range);
|
|
1263
|
+
};
|
|
1264
|
+
const syncInput = () => {
|
|
1265
|
+
const element = root.current;
|
|
1266
|
+
if (!element || composing.current)
|
|
1267
|
+
return;
|
|
1268
|
+
const parsed = readRichTextDOM(element);
|
|
1269
|
+
const range = readEditorSelection(element, parsed.points) ?? selected.current;
|
|
1270
|
+
if (parsed.value)
|
|
1271
|
+
commit(parsed.value, range, false);
|
|
1272
|
+
else {
|
|
1273
|
+
setError(true);
|
|
1274
|
+
writeRichTextDOM(element, model.current, variables);
|
|
1275
|
+
restoreRichTextSelection(element, selected.current);
|
|
1276
|
+
}
|
|
1277
|
+
};
|
|
1278
|
+
const beforeInput = useEffectEvent3((event) => {
|
|
1279
|
+
if (disabled || composing.current || event.isComposing)
|
|
1280
|
+
return;
|
|
1281
|
+
if (event.inputType === "historyUndo" || event.inputType === "historyRedo") {
|
|
1282
|
+
event.preventDefault();
|
|
1283
|
+
travel(event.inputType === "historyUndo" ? -1 : 1);
|
|
1284
|
+
} else if (["insertText", "insertParagraph", "insertLineBreak"].includes(event.inputType)) {
|
|
1285
|
+
event.preventDefault();
|
|
1286
|
+
if (singleLine && event.inputType !== "insertText")
|
|
1287
|
+
return;
|
|
1288
|
+
const range = selection();
|
|
1289
|
+
insert({
|
|
1290
|
+
type: "text",
|
|
1291
|
+
text: event.inputType === "insertText" ? event.data ?? "" : `
|
|
1292
|
+
`,
|
|
1293
|
+
marks: pendingMarks.current ?? richTextMarksAt(model.current, range.to)
|
|
1294
|
+
});
|
|
1295
|
+
} else if (event.inputType === "formatBold" || event.inputType === "formatItalic" || event.inputType === "formatUnderline") {
|
|
1296
|
+
event.preventDefault();
|
|
1297
|
+
if (!singleLine)
|
|
1298
|
+
format(event.inputType === "formatBold" ? "bold" : event.inputType === "formatItalic" ? "italic" : "underline");
|
|
1299
|
+
}
|
|
1300
|
+
});
|
|
1301
|
+
useEffect3(() => {
|
|
1302
|
+
const element = root.current;
|
|
1303
|
+
if (!element)
|
|
1304
|
+
return;
|
|
1305
|
+
const listener = (event) => beforeInput(event);
|
|
1306
|
+
element.addEventListener("beforeinput", listener);
|
|
1307
|
+
return () => element.removeEventListener("beforeinput", listener);
|
|
1308
|
+
}, []);
|
|
1309
|
+
const remember = useEffectEvent3(() => {
|
|
1310
|
+
const element = root.current;
|
|
1311
|
+
if (!element || document.activeElement !== element || composing.current)
|
|
1312
|
+
return;
|
|
1313
|
+
const previous = selected.current;
|
|
1314
|
+
const range = selection();
|
|
1315
|
+
if (previous.from !== range.from || previous.to !== range.to)
|
|
1316
|
+
pendingMarks.current = null;
|
|
1317
|
+
setMarks(pendingMarks.current ?? richTextMarksAt(model.current, range.to));
|
|
1318
|
+
});
|
|
1319
|
+
useEffect3(() => {
|
|
1320
|
+
document.addEventListener("selectionchange", remember);
|
|
1321
|
+
return () => document.removeEventListener("selectionchange", remember);
|
|
1322
|
+
}, []);
|
|
1323
|
+
useEffect3(() => {
|
|
1324
|
+
const element = root.current;
|
|
1325
|
+
if (!element || composing.current)
|
|
1326
|
+
return;
|
|
1327
|
+
if (!equivalent(model.current, value)) {
|
|
1328
|
+
model.current = value;
|
|
1329
|
+
history.current = [{ value, selection: { from: 0, to: 0 } }];
|
|
1330
|
+
cursor.current = 0;
|
|
1331
|
+
selected.current = { from: 0, to: 0 };
|
|
1332
|
+
writeRichTextDOM(element, value, variables);
|
|
1333
|
+
setRevision((current) => current + 1);
|
|
1334
|
+
setHistoryState({ undo: false, redo: false });
|
|
1335
|
+
}
|
|
1336
|
+
}, [value, variables]);
|
|
1337
|
+
return /* @__PURE__ */ jsxs4("div", {
|
|
1338
|
+
"data-slot": "rich-text-editor",
|
|
1339
|
+
className: `bg-background text-foreground overflow-hidden rounded-xl border ${className ?? ""}`,
|
|
1340
|
+
"data-revision": revision,
|
|
1341
|
+
children: [
|
|
1342
|
+
/* @__PURE__ */ jsxs4("div", {
|
|
1343
|
+
role: "group",
|
|
1344
|
+
"aria-label": copy.toolbar,
|
|
1345
|
+
className: "bg-muted/30 flex flex-wrap items-center gap-1 border-b p-2",
|
|
1346
|
+
children: [
|
|
1347
|
+
/* @__PURE__ */ jsx7(ToolButton, {
|
|
1348
|
+
label: copy.undo,
|
|
1349
|
+
disabled: disabled || !historyState.undo,
|
|
1350
|
+
onClick: () => travel(-1),
|
|
1351
|
+
children: /* @__PURE__ */ jsx7(Undo2, {})
|
|
1352
|
+
}),
|
|
1353
|
+
/* @__PURE__ */ jsx7(ToolButton, {
|
|
1354
|
+
label: copy.redo,
|
|
1355
|
+
disabled: disabled || !historyState.redo,
|
|
1356
|
+
onClick: () => travel(1),
|
|
1357
|
+
children: /* @__PURE__ */ jsx7(Redo2, {})
|
|
1358
|
+
}),
|
|
1359
|
+
!singleLine ? /* @__PURE__ */ jsxs4(Fragment2, {
|
|
1360
|
+
children: [
|
|
1361
|
+
/* @__PURE__ */ jsx7("span", {
|
|
1362
|
+
className: "mx-1 h-5 border-l",
|
|
1363
|
+
"aria-hidden": true
|
|
1364
|
+
}),
|
|
1365
|
+
/* @__PURE__ */ jsxs4(Select, {
|
|
1366
|
+
disabled,
|
|
1367
|
+
defaultValue: "paragraph",
|
|
1368
|
+
items: [
|
|
1369
|
+
{ value: "paragraph", label: copy.paragraph },
|
|
1370
|
+
{ value: "heading", label: copy.heading },
|
|
1371
|
+
{ value: "bullet", label: copy.bullet },
|
|
1372
|
+
{ value: "numbered", label: copy.numbered }
|
|
1373
|
+
],
|
|
1374
|
+
onOpenChange: (open) => {
|
|
1375
|
+
if (open)
|
|
1376
|
+
selection();
|
|
1377
|
+
},
|
|
1378
|
+
onValueChange: (value) => {
|
|
1379
|
+
const type = Schema4.decodeUnknownSync(RichTextBlockKind)(value);
|
|
1380
|
+
const range = selection();
|
|
1381
|
+
commit(setRichTextBlock(model.current, range, type), range);
|
|
1382
|
+
},
|
|
1383
|
+
children: [
|
|
1384
|
+
/* @__PURE__ */ jsx7(SelectTrigger, {
|
|
1385
|
+
size: "sm",
|
|
1386
|
+
"aria-label": copy.paragraph,
|
|
1387
|
+
className: "max-w-40 text-xs",
|
|
1388
|
+
onPointerDown: selection,
|
|
1389
|
+
onFocus: selection,
|
|
1390
|
+
children: /* @__PURE__ */ jsx7(SelectValue, {})
|
|
1391
|
+
}),
|
|
1392
|
+
/* @__PURE__ */ jsxs4(SelectContent, {
|
|
1393
|
+
align: "start",
|
|
1394
|
+
alignItemWithTrigger: false,
|
|
1395
|
+
finalFocus: focusEditor,
|
|
1396
|
+
children: [
|
|
1397
|
+
/* @__PURE__ */ jsx7(SelectItem, {
|
|
1398
|
+
value: "paragraph",
|
|
1399
|
+
children: copy.paragraph
|
|
1400
|
+
}),
|
|
1401
|
+
/* @__PURE__ */ jsx7(SelectItem, {
|
|
1402
|
+
value: "heading",
|
|
1403
|
+
children: copy.heading
|
|
1404
|
+
}),
|
|
1405
|
+
/* @__PURE__ */ jsx7(SelectItem, {
|
|
1406
|
+
value: "bullet",
|
|
1407
|
+
children: copy.bullet
|
|
1408
|
+
}),
|
|
1409
|
+
/* @__PURE__ */ jsx7(SelectItem, {
|
|
1410
|
+
value: "numbered",
|
|
1411
|
+
children: copy.numbered
|
|
1412
|
+
})
|
|
1413
|
+
]
|
|
1414
|
+
})
|
|
1415
|
+
]
|
|
1416
|
+
}),
|
|
1417
|
+
/* @__PURE__ */ jsx7(ToolButton, {
|
|
1418
|
+
label: copy.bold,
|
|
1419
|
+
disabled,
|
|
1420
|
+
pressed: !!marks.bold,
|
|
1421
|
+
onClick: () => format("bold"),
|
|
1422
|
+
children: /* @__PURE__ */ jsx7(Bold, {})
|
|
1423
|
+
}),
|
|
1424
|
+
/* @__PURE__ */ jsx7(ToolButton, {
|
|
1425
|
+
label: copy.italic,
|
|
1426
|
+
disabled,
|
|
1427
|
+
pressed: !!marks.italic,
|
|
1428
|
+
onClick: () => format("italic"),
|
|
1429
|
+
children: /* @__PURE__ */ jsx7(Italic, {})
|
|
1430
|
+
}),
|
|
1431
|
+
/* @__PURE__ */ jsx7(ToolButton, {
|
|
1432
|
+
label: copy.underline,
|
|
1433
|
+
disabled,
|
|
1434
|
+
pressed: !!marks.underline,
|
|
1435
|
+
onClick: () => format("underline"),
|
|
1436
|
+
children: /* @__PURE__ */ jsx7(Underline, {})
|
|
1437
|
+
}),
|
|
1438
|
+
/* @__PURE__ */ jsx7(ToolButton, {
|
|
1439
|
+
label: copy.link,
|
|
1440
|
+
disabled,
|
|
1441
|
+
pressed: linkOpen || !!marks.href,
|
|
1442
|
+
onClick: () => {
|
|
1443
|
+
selection();
|
|
1444
|
+
setLink(marks.href ?? "");
|
|
1445
|
+
setLinkError(false);
|
|
1446
|
+
setLinkOpen(!linkOpen);
|
|
1447
|
+
},
|
|
1448
|
+
children: /* @__PURE__ */ jsx7(Link2, {})
|
|
1449
|
+
})
|
|
1450
|
+
]
|
|
1451
|
+
}) : null,
|
|
1452
|
+
variables.length ? /* @__PURE__ */ jsxs4(DropdownMenu, {
|
|
1453
|
+
onOpenChange: (open) => {
|
|
1454
|
+
if (open)
|
|
1455
|
+
selection();
|
|
1456
|
+
},
|
|
1457
|
+
children: [
|
|
1458
|
+
/* @__PURE__ */ jsxs4(DropdownMenuTrigger, {
|
|
1459
|
+
disabled,
|
|
1460
|
+
onPointerDown: selection,
|
|
1461
|
+
onFocus: selection,
|
|
1462
|
+
render: /* @__PURE__ */ jsx7(Button, {
|
|
1463
|
+
type: "button",
|
|
1464
|
+
variant: "outline",
|
|
1465
|
+
size: "sm",
|
|
1466
|
+
className: "ml-auto text-xs"
|
|
1467
|
+
}),
|
|
1468
|
+
children: [
|
|
1469
|
+
/* @__PURE__ */ jsx7(Braces, {
|
|
1470
|
+
className: "size-3.5",
|
|
1471
|
+
"aria-hidden": true
|
|
1472
|
+
}),
|
|
1473
|
+
copy.variable,
|
|
1474
|
+
/* @__PURE__ */ jsx7(ChevronDown, {
|
|
1475
|
+
className: "size-3.5",
|
|
1476
|
+
"aria-hidden": true
|
|
1477
|
+
})
|
|
1478
|
+
]
|
|
1479
|
+
}),
|
|
1480
|
+
/* @__PURE__ */ jsx7(DropdownMenuContent, {
|
|
1481
|
+
align: "end",
|
|
1482
|
+
finalFocus: focusEditor,
|
|
1483
|
+
children: variables.map((variable) => /* @__PURE__ */ jsx7(DropdownMenuItem, {
|
|
1484
|
+
onClick: () => insert({ type: "variable", key: variable.key }),
|
|
1485
|
+
children: variable.label
|
|
1486
|
+
}, variable.key))
|
|
1487
|
+
})
|
|
1488
|
+
]
|
|
1489
|
+
}) : null
|
|
1490
|
+
]
|
|
1491
|
+
}),
|
|
1492
|
+
linkOpen ? /* @__PURE__ */ jsxs4("div", {
|
|
1493
|
+
className: "flex flex-wrap items-end gap-2 border-b p-3",
|
|
1494
|
+
children: [
|
|
1495
|
+
/* @__PURE__ */ jsxs4("label", {
|
|
1496
|
+
className: "grid min-w-0 flex-1 gap-1 text-xs",
|
|
1497
|
+
children: [
|
|
1498
|
+
copy.linkUrl,
|
|
1499
|
+
/* @__PURE__ */ jsx7(Input, {
|
|
1500
|
+
value: link,
|
|
1501
|
+
"aria-invalid": linkError,
|
|
1502
|
+
placeholder: "https://",
|
|
1503
|
+
onChange: (event) => setLink(event.target.value)
|
|
1504
|
+
})
|
|
1505
|
+
]
|
|
1506
|
+
}),
|
|
1507
|
+
/* @__PURE__ */ jsx7(Button, {
|
|
1508
|
+
type: "button",
|
|
1509
|
+
size: "sm",
|
|
1510
|
+
disabled,
|
|
1511
|
+
onClick: () => {
|
|
1512
|
+
if (!Schema4.is(RichTextLink)(link)) {
|
|
1513
|
+
setLinkError(true);
|
|
1514
|
+
return;
|
|
1515
|
+
}
|
|
1516
|
+
commit(formatRichText(model.current, selected.current, "href", link), selected.current);
|
|
1517
|
+
setLinkOpen(false);
|
|
1518
|
+
},
|
|
1519
|
+
children: copy.apply
|
|
1520
|
+
}),
|
|
1521
|
+
marks.href ? /* @__PURE__ */ jsxs4(Button, {
|
|
1522
|
+
type: "button",
|
|
1523
|
+
size: "sm",
|
|
1524
|
+
variant: "outline",
|
|
1525
|
+
disabled,
|
|
1526
|
+
onClick: () => {
|
|
1527
|
+
commit(formatRichText(model.current, selected.current, "href", undefined), selected.current);
|
|
1528
|
+
setLinkOpen(false);
|
|
1529
|
+
setLinkError(false);
|
|
1530
|
+
},
|
|
1531
|
+
children: [
|
|
1532
|
+
/* @__PURE__ */ jsx7(Unlink, {
|
|
1533
|
+
"aria-hidden": true
|
|
1534
|
+
}),
|
|
1535
|
+
copy.unlink
|
|
1536
|
+
]
|
|
1537
|
+
}) : null,
|
|
1538
|
+
/* @__PURE__ */ jsx7(Button, {
|
|
1539
|
+
type: "button",
|
|
1540
|
+
size: "sm",
|
|
1541
|
+
variant: "ghost",
|
|
1542
|
+
onClick: () => setLinkOpen(false),
|
|
1543
|
+
children: copy.cancel
|
|
1544
|
+
}),
|
|
1545
|
+
linkError ? /* @__PURE__ */ jsx7("p", {
|
|
1546
|
+
role: "alert",
|
|
1547
|
+
className: "text-destructive w-full text-xs",
|
|
1548
|
+
children: copy.invalidLink
|
|
1549
|
+
}) : null
|
|
1550
|
+
]
|
|
1551
|
+
}) : null,
|
|
1552
|
+
/* @__PURE__ */ jsx7("div", {
|
|
1553
|
+
ref: root,
|
|
1554
|
+
style: contentStyle,
|
|
1555
|
+
role: "textbox",
|
|
1556
|
+
"aria-label": label,
|
|
1557
|
+
"aria-multiline": !singleLine,
|
|
1558
|
+
"aria-disabled": disabled,
|
|
1559
|
+
"aria-describedby": error ? `${id}-error` : undefined,
|
|
1560
|
+
contentEditable: !disabled,
|
|
1561
|
+
suppressContentEditableWarning: true,
|
|
1562
|
+
className: `focus-visible:ring-ring ${singleLine ? "min-h-10" : "min-h-32"} px-4 py-3 text-sm leading-relaxed outline-none focus-visible:ring-2 focus-visible:ring-inset [&>div]:min-h-[1.5em]`,
|
|
1563
|
+
onInput: syncInput,
|
|
1564
|
+
onKeyUp: selection,
|
|
1565
|
+
onPointerUp: selection,
|
|
1566
|
+
onBlur: selection,
|
|
1567
|
+
onCompositionStart: () => {
|
|
1568
|
+
composing.current = true;
|
|
1569
|
+
},
|
|
1570
|
+
onCompositionEnd: () => {
|
|
1571
|
+
composing.current = false;
|
|
1572
|
+
syncInput();
|
|
1573
|
+
},
|
|
1574
|
+
onPaste: (event) => {
|
|
1575
|
+
event.preventDefault();
|
|
1576
|
+
const text = event.clipboardData.getData("text/plain");
|
|
1577
|
+
insert({
|
|
1578
|
+
type: "text",
|
|
1579
|
+
text: singleLine ? text.replace(/[\r\n]+/g, " ") : text
|
|
1580
|
+
});
|
|
1581
|
+
},
|
|
1582
|
+
onDrop: (event) => event.preventDefault(),
|
|
1583
|
+
onClick: (event) => {
|
|
1584
|
+
if (event.target instanceof HTMLElement && event.target.closest("a"))
|
|
1585
|
+
event.preventDefault();
|
|
1586
|
+
},
|
|
1587
|
+
onKeyDown: (event) => {
|
|
1588
|
+
if (event.nativeEvent.isComposing)
|
|
1589
|
+
return;
|
|
1590
|
+
if ((event.ctrlKey || event.metaKey) && !event.altKey) {
|
|
1591
|
+
const key = event.key.toLowerCase();
|
|
1592
|
+
if (["b", "i", "u", "z", "y"].includes(key)) {
|
|
1593
|
+
event.preventDefault();
|
|
1594
|
+
if (key === "z" || key === "y")
|
|
1595
|
+
travel(key === "y" || event.shiftKey ? 1 : -1);
|
|
1596
|
+
else if (!singleLine)
|
|
1597
|
+
format(key === "b" ? "bold" : key === "i" ? "italic" : "underline");
|
|
1598
|
+
}
|
|
1599
|
+
}
|
|
1600
|
+
},
|
|
1601
|
+
children: initial
|
|
1602
|
+
}),
|
|
1603
|
+
error ? /* @__PURE__ */ jsx7("p", {
|
|
1604
|
+
id: `${id}-error`,
|
|
1605
|
+
role: "alert",
|
|
1606
|
+
className: "text-destructive px-4 pb-3 text-xs",
|
|
1607
|
+
children: copy.invalid
|
|
1608
|
+
}) : null
|
|
1609
|
+
]
|
|
1610
|
+
});
|
|
1611
|
+
};
|
|
1612
|
+
|
|
1613
|
+
// ../../src/components/ui/tabs.tsx
|
|
1614
|
+
import { Tabs as TabsPrimitive } from "@base-ui/react/tabs";
|
|
1615
|
+
import { cva as cva2 } from "class-variance-authority";
|
|
1616
|
+
import { jsx as jsx8 } from "react/jsx-runtime";
|
|
1617
|
+
function Tabs({
|
|
1618
|
+
className,
|
|
1619
|
+
orientation = "horizontal",
|
|
1620
|
+
...props
|
|
1621
|
+
}) {
|
|
1622
|
+
return /* @__PURE__ */ jsx8(TabsPrimitive.Root, {
|
|
1623
|
+
"data-slot": "tabs",
|
|
1624
|
+
"data-orientation": orientation,
|
|
1625
|
+
className: cn("group/tabs flex gap-2 data-horizontal:flex-col", className),
|
|
1626
|
+
...props
|
|
1627
|
+
});
|
|
1628
|
+
}
|
|
1629
|
+
var tabsListVariants = cva2("group/tabs-list inline-flex w-fit items-center justify-center rounded-lg p-[3px] text-muted-foreground group-data-horizontal/tabs:h-9 group-data-vertical/tabs:h-fit group-data-vertical/tabs:flex-col data-[variant=line]:rounded-none", {
|
|
1630
|
+
variants: {
|
|
1631
|
+
variant: {
|
|
1632
|
+
default: "bg-muted",
|
|
1633
|
+
line: "gap-1 bg-transparent"
|
|
1634
|
+
}
|
|
1635
|
+
},
|
|
1636
|
+
defaultVariants: {
|
|
1637
|
+
variant: "default"
|
|
1638
|
+
}
|
|
1639
|
+
});
|
|
1640
|
+
function TabsList({
|
|
1641
|
+
className,
|
|
1642
|
+
variant = "default",
|
|
1643
|
+
...props
|
|
1644
|
+
}) {
|
|
1645
|
+
return /* @__PURE__ */ jsx8(TabsPrimitive.List, {
|
|
1646
|
+
"data-slot": "tabs-list",
|
|
1647
|
+
"data-variant": variant,
|
|
1648
|
+
className: cn(tabsListVariants({ variant }), className),
|
|
1649
|
+
...props
|
|
1650
|
+
});
|
|
1651
|
+
}
|
|
1652
|
+
function TabsTrigger({ className, ...props }) {
|
|
1653
|
+
return /* @__PURE__ */ jsx8(TabsPrimitive.Tab, {
|
|
1654
|
+
"data-slot": "tabs-trigger",
|
|
1655
|
+
className: cn("relative inline-flex h-[calc(100%-1px)] flex-1 items-center justify-center gap-1.5 rounded-md border border-transparent px-2 py-1 text-sm font-medium whitespace-nowrap text-foreground/60 transition-all group-data-vertical/tabs:w-full group-data-vertical/tabs:justify-start hover:text-foreground focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 focus-visible:outline-1 focus-visible:outline-ring disabled:pointer-events-none disabled:opacity-50 has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 aria-disabled:pointer-events-none aria-disabled:opacity-50 dark:text-muted-foreground dark:hover:text-foreground group-data-[variant=default]/tabs-list:data-active:shadow-sm group-data-[variant=line]/tabs-list:data-active:shadow-none [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4", "group-data-[variant=line]/tabs-list:bg-transparent group-data-[variant=line]/tabs-list:data-active:bg-transparent dark:group-data-[variant=line]/tabs-list:data-active:border-transparent dark:group-data-[variant=line]/tabs-list:data-active:bg-transparent", "data-active:bg-background data-active:text-foreground dark:data-active:border-input dark:data-active:bg-input/30 dark:data-active:text-foreground", "after:absolute after:bg-foreground after:opacity-0 after:transition-opacity group-data-horizontal/tabs:after:inset-x-0 group-data-horizontal/tabs:after:bottom-[-5px] group-data-horizontal/tabs:after:h-0.5 group-data-vertical/tabs:after:inset-y-0 group-data-vertical/tabs:after:-right-1 group-data-vertical/tabs:after:w-0.5 group-data-[variant=line]/tabs-list:data-active:after:opacity-100", className),
|
|
1656
|
+
...props
|
|
1657
|
+
});
|
|
1658
|
+
}
|
|
1659
|
+
function TabsContent({ className, ...props }) {
|
|
1660
|
+
return /* @__PURE__ */ jsx8(TabsPrimitive.Panel, {
|
|
1661
|
+
"data-slot": "tabs-content",
|
|
1662
|
+
className: cn("flex-1 text-sm outline-none", className),
|
|
1663
|
+
...props
|
|
1664
|
+
});
|
|
1665
|
+
}
|
|
1666
|
+
|
|
1667
|
+
// ../../src/components/ui/email-editor.tsx
|
|
1668
|
+
import { useKrakstackLocale as useKrakstackLocale3 } from "@krak-stack/registry/krakstack-provider";
|
|
1669
|
+
|
|
1670
|
+
// ../../src/lib/email-document/schema.ts
|
|
1671
|
+
import { Schema as Schema5 } from "effect";
|
|
1672
|
+
var EmailImageUrl = RichTextLink.check(Schema5.isPattern(/^https:\/\//)).annotate({ identifier: "EmailImageUrl" });
|
|
1673
|
+
var EmailColor = Schema5.String.check(Schema5.isPattern(/^#[0-9a-fA-F]{6}$/)).annotate({ identifier: "EmailColor" });
|
|
1674
|
+
var EmailAlignment = Schema5.Literals([
|
|
1675
|
+
"left",
|
|
1676
|
+
"center",
|
|
1677
|
+
"right"
|
|
1678
|
+
]).annotate({ identifier: "EmailAlignment" });
|
|
1679
|
+
var EmailFont = Schema5.Literals(["sans", "serif", "mono"]).annotate({
|
|
1680
|
+
identifier: "EmailFont"
|
|
1681
|
+
});
|
|
1682
|
+
var spacing = Schema5.Int.check(Schema5.isBetween({ minimum: 0, maximum: 96 }));
|
|
1683
|
+
var common = {
|
|
1684
|
+
id: Schema5.NonEmptyString.check(Schema5.isMaxLength(80)),
|
|
1685
|
+
alignment: EmailAlignment,
|
|
1686
|
+
paddingTop: spacing,
|
|
1687
|
+
paddingBottom: spacing
|
|
1688
|
+
};
|
|
1689
|
+
var EmailDestination = Schema5.Union([
|
|
1690
|
+
Schema5.Struct({ type: Schema5.Literal("url"), url: RichTextLink }),
|
|
1691
|
+
Schema5.Struct({
|
|
1692
|
+
type: Schema5.Literal("variable"),
|
|
1693
|
+
key: RichTextVariable.fields.key
|
|
1694
|
+
})
|
|
1695
|
+
]).annotate({ identifier: "EmailDestination" });
|
|
1696
|
+
var EmailElement = Schema5.Union([
|
|
1697
|
+
Schema5.Struct({
|
|
1698
|
+
...common,
|
|
1699
|
+
type: Schema5.Literal("text"),
|
|
1700
|
+
content: RichTextDocument
|
|
1701
|
+
}),
|
|
1702
|
+
Schema5.Struct({
|
|
1703
|
+
...common,
|
|
1704
|
+
type: Schema5.Literal("button"),
|
|
1705
|
+
label: Schema5.String.check(Schema5.isMaxLength(200)),
|
|
1706
|
+
destination: EmailDestination
|
|
1707
|
+
}),
|
|
1708
|
+
Schema5.Struct({
|
|
1709
|
+
...common,
|
|
1710
|
+
type: Schema5.Literal("code"),
|
|
1711
|
+
variable: RichTextVariable.fields.key
|
|
1712
|
+
}),
|
|
1713
|
+
Schema5.Struct({
|
|
1714
|
+
...common,
|
|
1715
|
+
type: Schema5.Literals(["logo", "image"]),
|
|
1716
|
+
src: EmailImageUrl,
|
|
1717
|
+
alt: Schema5.String.check(Schema5.isMaxLength(200)),
|
|
1718
|
+
width: Schema5.Int.check(Schema5.isBetween({ minimum: 32, maximum: 560 }))
|
|
1719
|
+
}),
|
|
1720
|
+
Schema5.Struct({ ...common, type: Schema5.Literal("divider") }),
|
|
1721
|
+
Schema5.Struct({ ...common, type: Schema5.Literal("spacer"), height: spacing })
|
|
1722
|
+
]).annotate({ identifier: "EmailElement" });
|
|
1723
|
+
var subject = Schema5.String.check(Schema5.isMaxLength(200), Schema5.isPattern(/^[^\r\n]*$/));
|
|
1724
|
+
var EmailDocument = Schema5.Struct({
|
|
1725
|
+
version: Schema5.Literal(1),
|
|
1726
|
+
subject,
|
|
1727
|
+
preview: subject,
|
|
1728
|
+
appearance: Schema5.Struct({
|
|
1729
|
+
background: EmailColor,
|
|
1730
|
+
surface: EmailColor,
|
|
1731
|
+
text: EmailColor,
|
|
1732
|
+
primary: EmailColor,
|
|
1733
|
+
primaryText: EmailColor,
|
|
1734
|
+
font: EmailFont,
|
|
1735
|
+
radius: Schema5.Int.check(Schema5.isBetween({ minimum: 0, maximum: 32 }))
|
|
1736
|
+
}),
|
|
1737
|
+
elements: Schema5.Array(EmailElement).check(Schema5.isMaxLength(40))
|
|
1738
|
+
}).check(Schema5.makeFilter((document2) => new Set(document2.elements.map((element) => element.id)).size === document2.elements.length)).annotate({ identifier: "EmailDocument" });
|
|
1739
|
+
var EmailRenderInput = Schema5.Struct({
|
|
1740
|
+
document: EmailDocument,
|
|
1741
|
+
variables: Schema5.Array(RichTextVariable),
|
|
1742
|
+
values: Schema5.Record(Schema5.String, Schema5.String),
|
|
1743
|
+
requiredVariables: Schema5.optional(Schema5.Array(Schema5.String))
|
|
1744
|
+
}).annotate({ identifier: "EmailRenderInput" });
|
|
1745
|
+
var EmailRenderResult = Schema5.Struct({
|
|
1746
|
+
subject: Schema5.String,
|
|
1747
|
+
html: Schema5.String,
|
|
1748
|
+
text: Schema5.String
|
|
1749
|
+
}).annotate({ identifier: "EmailRenderResult" });
|
|
1750
|
+
|
|
1751
|
+
// ../../src/lib/email-document/model.ts
|
|
1752
|
+
import { Schema as Schema6 } from "effect";
|
|
1753
|
+
var emailElementTypes = [
|
|
1754
|
+
"text",
|
|
1755
|
+
"button",
|
|
1756
|
+
"code",
|
|
1757
|
+
"logo",
|
|
1758
|
+
"image",
|
|
1759
|
+
"divider",
|
|
1760
|
+
"spacer"
|
|
1761
|
+
];
|
|
1762
|
+
var newEmailElement = (type, input) => {
|
|
1763
|
+
const common = {
|
|
1764
|
+
id: input.id,
|
|
1765
|
+
alignment: "left",
|
|
1766
|
+
paddingTop: 8,
|
|
1767
|
+
paddingBottom: 8
|
|
1768
|
+
};
|
|
1769
|
+
switch (type) {
|
|
1770
|
+
case "text":
|
|
1771
|
+
return { ...common, type, content: richTextFromString(input.text) };
|
|
1772
|
+
case "button":
|
|
1773
|
+
return {
|
|
1774
|
+
...common,
|
|
1775
|
+
type,
|
|
1776
|
+
label: input.button,
|
|
1777
|
+
destination: input.urlVariable ? { type: "variable", key: input.urlVariable } : { type: "url", url: "https://example.com" }
|
|
1778
|
+
};
|
|
1779
|
+
case "code":
|
|
1780
|
+
return { ...common, type, variable: input.codeVariable ?? "code" };
|
|
1781
|
+
case "logo":
|
|
1782
|
+
case "image":
|
|
1783
|
+
return {
|
|
1784
|
+
...common,
|
|
1785
|
+
type,
|
|
1786
|
+
src: "https://krakstack.net/favicon.svg",
|
|
1787
|
+
alt: input.imageAlt,
|
|
1788
|
+
width: type === "logo" ? 48 : 160
|
|
1789
|
+
};
|
|
1790
|
+
case "divider":
|
|
1791
|
+
return { ...common, type };
|
|
1792
|
+
case "spacer":
|
|
1793
|
+
return { ...common, type, height: 24 };
|
|
1794
|
+
}
|
|
1795
|
+
};
|
|
1796
|
+
var richTextFromEmailText = (text) => ({
|
|
1797
|
+
version: 1,
|
|
1798
|
+
blocks: [
|
|
1799
|
+
{
|
|
1800
|
+
type: "paragraph",
|
|
1801
|
+
content: text.split(/(\{\{[a-zA-Z][a-zA-Z0-9_.]*\}\})/g).filter(Boolean).map((part) => /^\{\{[a-zA-Z][a-zA-Z0-9_.]*\}\}$/.test(part) ? { type: "variable", key: part.slice(2, -2) } : { type: "text", text: part })
|
|
1802
|
+
}
|
|
1803
|
+
]
|
|
1804
|
+
});
|
|
1805
|
+
var textReferences = (text) => [...text.matchAll(/\{\{([a-zA-Z][a-zA-Z0-9_.]*)\}\}/g)].map((match) => match[1] ?? "");
|
|
1806
|
+
var emailDocumentReferences = (document2) => [
|
|
1807
|
+
...new Set([
|
|
1808
|
+
...textReferences(document2.subject),
|
|
1809
|
+
...textReferences(document2.preview),
|
|
1810
|
+
...document2.elements.flatMap((element) => {
|
|
1811
|
+
switch (element.type) {
|
|
1812
|
+
case "text":
|
|
1813
|
+
return element.content.blocks.flatMap((block) => block.content.flatMap((inline) => inline.type === "variable" ? [inline.key] : []));
|
|
1814
|
+
case "code":
|
|
1815
|
+
return [element.variable];
|
|
1816
|
+
case "button":
|
|
1817
|
+
return [
|
|
1818
|
+
...textReferences(element.label),
|
|
1819
|
+
...element.destination.type === "variable" ? [element.destination.key] : []
|
|
1820
|
+
];
|
|
1821
|
+
default:
|
|
1822
|
+
return [];
|
|
1823
|
+
}
|
|
1824
|
+
})
|
|
1825
|
+
])
|
|
1826
|
+
];
|
|
1827
|
+
var validateEmailDocument = ({
|
|
1828
|
+
document: document2,
|
|
1829
|
+
variables,
|
|
1830
|
+
values,
|
|
1831
|
+
requiredVariables = []
|
|
1832
|
+
}) => {
|
|
1833
|
+
if (!Schema6.is(EmailDocument)(document2))
|
|
1834
|
+
return [{ code: "invalid-document" }];
|
|
1835
|
+
const references = emailDocumentReferences(document2);
|
|
1836
|
+
const issues = [];
|
|
1837
|
+
for (const key of references) {
|
|
1838
|
+
if (!variables.some((variable) => variable.key === key))
|
|
1839
|
+
issues.push({ code: "unknown-variable", key });
|
|
1840
|
+
if (values && !values[key])
|
|
1841
|
+
issues.push({ code: "missing-variable", key });
|
|
1842
|
+
}
|
|
1843
|
+
for (const element of document2.elements) {
|
|
1844
|
+
if (element.type === "button" && element.destination.type === "variable") {
|
|
1845
|
+
const key = element.destination.key;
|
|
1846
|
+
if (variables.find((variable) => variable.key === key)?.type !== "url" || values && !Schema6.is(RichTextLink)(values[key]))
|
|
1847
|
+
issues.push({ code: "invalid-url", key });
|
|
1848
|
+
}
|
|
1849
|
+
}
|
|
1850
|
+
for (const key of requiredVariables)
|
|
1851
|
+
if (!document2.elements.some((element) => element.type === "code" && element.variable === key || element.type === "button" && element.destination.type === "variable" && element.destination.key === key || element.type === "text" && element.content.blocks.some((block) => block.content.some((inline) => inline.type === "variable" && inline.key === key))))
|
|
1852
|
+
issues.push({ code: "missing-required-variable", key });
|
|
1853
|
+
return issues;
|
|
1854
|
+
};
|
|
1855
|
+
|
|
1856
|
+
// ../../src/components/ui/email-editor.tsx
|
|
1857
|
+
import { jsx as jsx9, jsxs as jsxs5, Fragment as Fragment3 } from "react/jsx-runtime";
|
|
1858
|
+
var EmailEditorSelect = ({
|
|
1859
|
+
label,
|
|
1860
|
+
value,
|
|
1861
|
+
options,
|
|
1862
|
+
disabled,
|
|
1863
|
+
onValueChange
|
|
1864
|
+
}) => /* @__PURE__ */ jsxs5(Select, {
|
|
1865
|
+
items: options,
|
|
1866
|
+
value,
|
|
1867
|
+
disabled,
|
|
1868
|
+
onValueChange: (value) => {
|
|
1869
|
+
if (value !== null)
|
|
1870
|
+
onValueChange(value);
|
|
1871
|
+
},
|
|
1872
|
+
children: [
|
|
1873
|
+
/* @__PURE__ */ jsx9(SelectTrigger, {
|
|
1874
|
+
"aria-label": label,
|
|
1875
|
+
className: "w-full min-w-0 text-xs",
|
|
1876
|
+
children: /* @__PURE__ */ jsx9(SelectValue, {})
|
|
1877
|
+
}),
|
|
1878
|
+
/* @__PURE__ */ jsx9(SelectContent, {
|
|
1879
|
+
align: "start",
|
|
1880
|
+
alignItemWithTrigger: false,
|
|
1881
|
+
children: options.map((option) => /* @__PURE__ */ jsx9(SelectItem, {
|
|
1882
|
+
value: option.value,
|
|
1883
|
+
children: option.label
|
|
1884
|
+
}, option.value))
|
|
1885
|
+
})
|
|
1886
|
+
]
|
|
1887
|
+
});
|
|
1888
|
+
var labels3 = {
|
|
1889
|
+
en: {
|
|
1890
|
+
edit: "Design",
|
|
1891
|
+
preview: "Preview",
|
|
1892
|
+
subject: "Subject",
|
|
1893
|
+
preheader: "Preview text",
|
|
1894
|
+
add: "Add element",
|
|
1895
|
+
text: "Text",
|
|
1896
|
+
button: "Button",
|
|
1897
|
+
code: "Verification code",
|
|
1898
|
+
logo: "Logo",
|
|
1899
|
+
image: "Image",
|
|
1900
|
+
divider: "Divider",
|
|
1901
|
+
spacer: "Spacer",
|
|
1902
|
+
content: "Email content",
|
|
1903
|
+
properties: "Element settings",
|
|
1904
|
+
select: "Select an element to edit its settings.",
|
|
1905
|
+
alignment: "Alignment",
|
|
1906
|
+
left: "Left",
|
|
1907
|
+
center: "Center",
|
|
1908
|
+
right: "Right",
|
|
1909
|
+
paddingTop: "Space above",
|
|
1910
|
+
paddingBottom: "Space below",
|
|
1911
|
+
width: "Width",
|
|
1912
|
+
height: "Height",
|
|
1913
|
+
src: "Image URL",
|
|
1914
|
+
alt: "Alternative text",
|
|
1915
|
+
label: "Button label",
|
|
1916
|
+
destination: "Destination",
|
|
1917
|
+
url: "Custom URL",
|
|
1918
|
+
variable: "Variable",
|
|
1919
|
+
insertVariable: "Insert variable",
|
|
1920
|
+
close: "Close settings",
|
|
1921
|
+
duplicate: "Duplicate element",
|
|
1922
|
+
remove: "Remove element",
|
|
1923
|
+
background: "Canvas",
|
|
1924
|
+
surface: "Paper",
|
|
1925
|
+
primary: "Accent",
|
|
1926
|
+
primaryText: "Button text",
|
|
1927
|
+
foreground: "Text color",
|
|
1928
|
+
font: "Font",
|
|
1929
|
+
sans: "Sans serif",
|
|
1930
|
+
serif: "Serif",
|
|
1931
|
+
mono: "Monospace",
|
|
1932
|
+
branding: "Branding",
|
|
1933
|
+
invalid: "Fix invalid settings or missing variables before using this email.",
|
|
1934
|
+
newText: "Write your message here.",
|
|
1935
|
+
newButton: "Continue",
|
|
1936
|
+
newImage: "Your image",
|
|
1937
|
+
empty: "Start with an element. Everything can be moved.",
|
|
1938
|
+
editElement: "Edit element",
|
|
1939
|
+
local: "Drag by the grip or use the arrow keys on it. Your changes stay in this editor."
|
|
1940
|
+
},
|
|
1941
|
+
fr: {
|
|
1942
|
+
edit: "Création",
|
|
1943
|
+
preview: "Aperçu",
|
|
1944
|
+
subject: "Objet",
|
|
1945
|
+
preheader: "Texte d’aperçu",
|
|
1946
|
+
add: "Ajouter un élément",
|
|
1947
|
+
text: "Texte",
|
|
1948
|
+
button: "Bouton",
|
|
1949
|
+
code: "Code de vérification",
|
|
1950
|
+
logo: "Logo",
|
|
1951
|
+
image: "Image",
|
|
1952
|
+
divider: "Séparateur",
|
|
1953
|
+
spacer: "Espacement",
|
|
1954
|
+
content: "Contenu du courriel",
|
|
1955
|
+
properties: "Réglages de l’élément",
|
|
1956
|
+
select: "Sélectionnez un élément pour modifier ses réglages.",
|
|
1957
|
+
alignment: "Alignement",
|
|
1958
|
+
left: "Gauche",
|
|
1959
|
+
center: "Centre",
|
|
1960
|
+
right: "Droite",
|
|
1961
|
+
paddingTop: "Espace au-dessus",
|
|
1962
|
+
paddingBottom: "Espace en dessous",
|
|
1963
|
+
width: "Largeur",
|
|
1964
|
+
height: "Hauteur",
|
|
1965
|
+
src: "URL de l’image",
|
|
1966
|
+
alt: "Texte de remplacement",
|
|
1967
|
+
label: "Libellé du bouton",
|
|
1968
|
+
destination: "Destination",
|
|
1969
|
+
url: "URL personnalisée",
|
|
1970
|
+
variable: "Variable",
|
|
1971
|
+
insertVariable: "Insérer une variable",
|
|
1972
|
+
close: "Fermer les réglages",
|
|
1973
|
+
duplicate: "Dupliquer l’élément",
|
|
1974
|
+
remove: "Retirer l’élément",
|
|
1975
|
+
background: "Fond",
|
|
1976
|
+
surface: "Papier",
|
|
1977
|
+
primary: "Accent",
|
|
1978
|
+
primaryText: "Texte du bouton",
|
|
1979
|
+
foreground: "Couleur du texte",
|
|
1980
|
+
font: "Police",
|
|
1981
|
+
sans: "Sans empattement",
|
|
1982
|
+
serif: "Avec empattement",
|
|
1983
|
+
mono: "Chasse fixe",
|
|
1984
|
+
branding: "Identité visuelle",
|
|
1985
|
+
invalid: "Corrigez les réglages invalides ou les variables manquantes avant d’utiliser ce courriel.",
|
|
1986
|
+
newText: "Rédigez votre message ici.",
|
|
1987
|
+
newButton: "Continuer",
|
|
1988
|
+
newImage: "Votre image",
|
|
1989
|
+
empty: "Commencez par un élément. Tout peut être déplacé.",
|
|
1990
|
+
editElement: "Modifier l’élément",
|
|
1991
|
+
local: "Glissez avec la poignée ou utilisez ses touches fléchées. Vos modifications restent dans cet éditeur."
|
|
1992
|
+
}
|
|
1993
|
+
};
|
|
1994
|
+
var icons = {
|
|
1995
|
+
text: Type,
|
|
1996
|
+
button: MousePointer2,
|
|
1997
|
+
code: KeyRound,
|
|
1998
|
+
logo: ScanLine,
|
|
1999
|
+
image: Image,
|
|
2000
|
+
divider: Minus,
|
|
2001
|
+
spacer: Space
|
|
2002
|
+
};
|
|
2003
|
+
var fonts = {
|
|
2004
|
+
sans: "Arial, sans-serif",
|
|
2005
|
+
serif: "Georgia, serif",
|
|
2006
|
+
mono: "'Courier New', monospace"
|
|
2007
|
+
};
|
|
2008
|
+
var EmailEditor = ({
|
|
2009
|
+
value,
|
|
2010
|
+
onChange,
|
|
2011
|
+
variables = [],
|
|
2012
|
+
requiredVariables = [],
|
|
2013
|
+
preview,
|
|
2014
|
+
disabled,
|
|
2015
|
+
locale: override,
|
|
2016
|
+
messages
|
|
2017
|
+
}) => {
|
|
2018
|
+
const locale = useKrakstackLocale3(override);
|
|
2019
|
+
const copy = {
|
|
2020
|
+
...locale.startsWith("fr") ? labels3.fr : labels3.en,
|
|
2021
|
+
...messages?.[locale.split("-")[0] ?? locale],
|
|
2022
|
+
...messages?.[locale]
|
|
2023
|
+
};
|
|
2024
|
+
const [active, setActive] = useState4(value.elements.find((element) => element.type === "text")?.id ?? null);
|
|
2025
|
+
const selected = value.elements.find((element) => element.id === active);
|
|
2026
|
+
const [view, setView] = useState4("design");
|
|
2027
|
+
const [settingsAnchor, setSettingsAnchor] = useState4(null);
|
|
2028
|
+
const [settingsOpen, setSettingsOpen] = useState4(false);
|
|
2029
|
+
const id = useId3();
|
|
2030
|
+
const [insertOpen, setInsertOpen] = useState4(false);
|
|
2031
|
+
const update = (element) => {
|
|
2032
|
+
if (!disabled)
|
|
2033
|
+
onChange({
|
|
2034
|
+
...value,
|
|
2035
|
+
elements: value.elements.map((item) => item.id === element.id ? element : item)
|
|
2036
|
+
});
|
|
2037
|
+
};
|
|
2038
|
+
const add = (type) => {
|
|
2039
|
+
const element = newEmailElement(type, {
|
|
2040
|
+
id: crypto.randomUUID(),
|
|
2041
|
+
text: copy.newText,
|
|
2042
|
+
button: copy.newButton,
|
|
2043
|
+
imageAlt: copy.newImage,
|
|
2044
|
+
codeVariable: variables.find((variable) => variable.key === "code")?.key ?? variables.find((variable) => variable.type === "text")?.key,
|
|
2045
|
+
urlVariable: variables.find((variable) => variable.type === "url")?.key
|
|
2046
|
+
});
|
|
2047
|
+
onChange({ ...value, elements: [...value.elements, element] });
|
|
2048
|
+
setActive(element.id);
|
|
2049
|
+
};
|
|
2050
|
+
const field = (label, control) => /* @__PURE__ */ jsxs5("label", {
|
|
2051
|
+
className: "grid min-w-0 gap-1.5 text-xs font-medium",
|
|
2052
|
+
children: [
|
|
2053
|
+
label,
|
|
2054
|
+
control
|
|
2055
|
+
]
|
|
2056
|
+
});
|
|
2057
|
+
const invalid = validateEmailDocument({ document: value, variables, requiredVariables }).length > 0;
|
|
2058
|
+
const canvasVariables = {
|
|
2059
|
+
"--email-paper": value.appearance.surface,
|
|
2060
|
+
"--email-hover": `color-mix(in srgb, ${value.appearance.surface} 94%, ${value.appearance.text})`
|
|
2061
|
+
};
|
|
2062
|
+
return /* @__PURE__ */ jsxs5("div", {
|
|
2063
|
+
"data-slot": "email-editor",
|
|
2064
|
+
className: "min-w-0 space-y-4",
|
|
2065
|
+
children: [
|
|
2066
|
+
/* @__PURE__ */ jsxs5(Tabs, {
|
|
2067
|
+
value: view,
|
|
2068
|
+
onValueChange: setView,
|
|
2069
|
+
children: [
|
|
2070
|
+
/* @__PURE__ */ jsxs5(TabsList, {
|
|
2071
|
+
children: [
|
|
2072
|
+
/* @__PURE__ */ jsx9(TabsTrigger, {
|
|
2073
|
+
value: "design",
|
|
2074
|
+
children: copy.edit
|
|
2075
|
+
}),
|
|
2076
|
+
/* @__PURE__ */ jsx9(TabsTrigger, {
|
|
2077
|
+
value: "preview",
|
|
2078
|
+
disabled: !preview,
|
|
2079
|
+
children: copy.preview
|
|
2080
|
+
})
|
|
2081
|
+
]
|
|
2082
|
+
}),
|
|
2083
|
+
/* @__PURE__ */ jsx9(TabsContent, {
|
|
2084
|
+
value: "preview",
|
|
2085
|
+
className: "mt-4",
|
|
2086
|
+
children: preview
|
|
2087
|
+
}),
|
|
2088
|
+
/* @__PURE__ */ jsxs5(TabsContent, {
|
|
2089
|
+
value: "design",
|
|
2090
|
+
className: "mt-4 space-y-4",
|
|
2091
|
+
children: [
|
|
2092
|
+
/* @__PURE__ */ jsx9("div", {
|
|
2093
|
+
className: "grid gap-3",
|
|
2094
|
+
children: ["subject", "preview"].map((key) => {
|
|
2095
|
+
const label = key === "subject" ? copy.subject : copy.preheader;
|
|
2096
|
+
return /* @__PURE__ */ jsxs5("div", {
|
|
2097
|
+
role: "group",
|
|
2098
|
+
"aria-label": label,
|
|
2099
|
+
className: "min-w-0 space-y-1.5",
|
|
2100
|
+
children: [
|
|
2101
|
+
/* @__PURE__ */ jsx9("p", {
|
|
2102
|
+
className: "text-xs font-medium",
|
|
2103
|
+
children: label
|
|
2104
|
+
}),
|
|
2105
|
+
/* @__PURE__ */ jsx9(RichTextEditor, {
|
|
2106
|
+
label,
|
|
2107
|
+
value: richTextFromEmailText(value[key]),
|
|
2108
|
+
onChange: (content) => onChange({ ...value, [key]: richTextPlainText(content) }),
|
|
2109
|
+
variables,
|
|
2110
|
+
locale,
|
|
2111
|
+
disabled,
|
|
2112
|
+
singleLine: true,
|
|
2113
|
+
maxLength: 200
|
|
2114
|
+
})
|
|
2115
|
+
]
|
|
2116
|
+
}, key);
|
|
2117
|
+
})
|
|
2118
|
+
}),
|
|
2119
|
+
/* @__PURE__ */ jsxs5("div", {
|
|
2120
|
+
className: "bg-muted/20 flex flex-wrap items-center justify-between gap-2 rounded-xl border p-2",
|
|
2121
|
+
children: [
|
|
2122
|
+
/* @__PURE__ */ jsxs5(Popover.Root, {
|
|
2123
|
+
open: insertOpen,
|
|
2124
|
+
onOpenChange: setInsertOpen,
|
|
2125
|
+
children: [
|
|
2126
|
+
/* @__PURE__ */ jsxs5(PopoverTrigger, {
|
|
2127
|
+
id: `${id}-add`,
|
|
2128
|
+
render: /* @__PURE__ */ jsx9(Button, {
|
|
2129
|
+
type: "button",
|
|
2130
|
+
size: "sm",
|
|
2131
|
+
disabled: disabled || value.elements.length >= 40
|
|
2132
|
+
}),
|
|
2133
|
+
children: [
|
|
2134
|
+
/* @__PURE__ */ jsx9(Plus, {
|
|
2135
|
+
className: "size-3.5",
|
|
2136
|
+
"aria-hidden": true
|
|
2137
|
+
}),
|
|
2138
|
+
copy.add,
|
|
2139
|
+
/* @__PURE__ */ jsx9(ChevronDown2, {
|
|
2140
|
+
className: "size-3.5",
|
|
2141
|
+
"aria-hidden": true
|
|
2142
|
+
})
|
|
2143
|
+
]
|
|
2144
|
+
}),
|
|
2145
|
+
/* @__PURE__ */ jsxs5(PopoverContent, {
|
|
2146
|
+
align: "start",
|
|
2147
|
+
className: "w-64",
|
|
2148
|
+
children: [
|
|
2149
|
+
/* @__PURE__ */ jsx9(PopoverTitle, {
|
|
2150
|
+
children: copy.add
|
|
2151
|
+
}),
|
|
2152
|
+
/* @__PURE__ */ jsx9("div", {
|
|
2153
|
+
className: "grid gap-1",
|
|
2154
|
+
children: emailElementTypes.map((type) => {
|
|
2155
|
+
const Icon = icons[type];
|
|
2156
|
+
return /* @__PURE__ */ jsxs5(Button, {
|
|
2157
|
+
type: "button",
|
|
2158
|
+
variant: "ghost",
|
|
2159
|
+
size: "sm",
|
|
2160
|
+
className: "h-auto min-h-8 min-w-0 justify-start text-left whitespace-normal",
|
|
2161
|
+
disabled: disabled || value.elements.length >= 40,
|
|
2162
|
+
onClick: () => {
|
|
2163
|
+
add(type);
|
|
2164
|
+
setInsertOpen(false);
|
|
2165
|
+
},
|
|
2166
|
+
children: [
|
|
2167
|
+
/* @__PURE__ */ jsx9(Icon, {
|
|
2168
|
+
className: "size-3.5",
|
|
2169
|
+
"aria-hidden": true
|
|
2170
|
+
}),
|
|
2171
|
+
copy[type]
|
|
2172
|
+
]
|
|
2173
|
+
}, type);
|
|
2174
|
+
})
|
|
2175
|
+
})
|
|
2176
|
+
]
|
|
2177
|
+
})
|
|
2178
|
+
]
|
|
2179
|
+
}),
|
|
2180
|
+
/* @__PURE__ */ jsxs5(Popover.Root, {
|
|
2181
|
+
children: [
|
|
2182
|
+
/* @__PURE__ */ jsxs5(PopoverTrigger, {
|
|
2183
|
+
render: /* @__PURE__ */ jsx9(Button, {
|
|
2184
|
+
type: "button",
|
|
2185
|
+
variant: "outline",
|
|
2186
|
+
size: "sm",
|
|
2187
|
+
disabled
|
|
2188
|
+
}),
|
|
2189
|
+
children: [
|
|
2190
|
+
/* @__PURE__ */ jsx9(Palette, {
|
|
2191
|
+
className: "size-3.5",
|
|
2192
|
+
"aria-hidden": true
|
|
2193
|
+
}),
|
|
2194
|
+
copy.branding,
|
|
2195
|
+
/* @__PURE__ */ jsx9(ChevronDown2, {
|
|
2196
|
+
className: "size-3.5",
|
|
2197
|
+
"aria-hidden": true
|
|
2198
|
+
})
|
|
2199
|
+
]
|
|
2200
|
+
}),
|
|
2201
|
+
/* @__PURE__ */ jsxs5(PopoverContent, {
|
|
2202
|
+
align: "end",
|
|
2203
|
+
className: "w-[min(380px,calc(100vw-2rem))]",
|
|
2204
|
+
children: [
|
|
2205
|
+
/* @__PURE__ */ jsx9(PopoverTitle, {
|
|
2206
|
+
children: copy.branding
|
|
2207
|
+
}),
|
|
2208
|
+
/* @__PURE__ */ jsxs5("div", {
|
|
2209
|
+
className: "grid grid-cols-2 gap-4",
|
|
2210
|
+
children: [
|
|
2211
|
+
[
|
|
2212
|
+
"background",
|
|
2213
|
+
"surface",
|
|
2214
|
+
"primary",
|
|
2215
|
+
"primaryText",
|
|
2216
|
+
"text"
|
|
2217
|
+
].map((key) => /* @__PURE__ */ jsxs5("label", {
|
|
2218
|
+
className: "flex items-center justify-between gap-2 text-xs",
|
|
2219
|
+
children: [
|
|
2220
|
+
key === "text" ? copy.foreground : copy[key],
|
|
2221
|
+
/* @__PURE__ */ jsx9("input", {
|
|
2222
|
+
type: "color",
|
|
2223
|
+
value: value.appearance[key],
|
|
2224
|
+
disabled,
|
|
2225
|
+
className: "h-8 w-9 cursor-pointer rounded border p-0.5",
|
|
2226
|
+
onChange: (event) => onChange({
|
|
2227
|
+
...value,
|
|
2228
|
+
appearance: {
|
|
2229
|
+
...value.appearance,
|
|
2230
|
+
[key]: event.target.value
|
|
2231
|
+
}
|
|
2232
|
+
})
|
|
2233
|
+
})
|
|
2234
|
+
]
|
|
2235
|
+
}, key)),
|
|
2236
|
+
field(copy.font, /* @__PURE__ */ jsx9(EmailEditorSelect, {
|
|
2237
|
+
label: copy.font,
|
|
2238
|
+
value: value.appearance.font,
|
|
2239
|
+
disabled,
|
|
2240
|
+
options: ["sans", "serif", "mono"].map((font) => ({ value: font, label: copy[font] })),
|
|
2241
|
+
onValueChange: (font) => onChange({
|
|
2242
|
+
...value,
|
|
2243
|
+
appearance: {
|
|
2244
|
+
...value.appearance,
|
|
2245
|
+
font: Schema7.decodeUnknownSync(EmailFont)(font)
|
|
2246
|
+
}
|
|
2247
|
+
})
|
|
2248
|
+
}))
|
|
2249
|
+
]
|
|
2250
|
+
})
|
|
2251
|
+
]
|
|
2252
|
+
})
|
|
2253
|
+
]
|
|
2254
|
+
})
|
|
2255
|
+
]
|
|
2256
|
+
}),
|
|
2257
|
+
/* @__PURE__ */ jsxs5("div", {
|
|
2258
|
+
className: "flex min-w-0 flex-col gap-4",
|
|
2259
|
+
children: [
|
|
2260
|
+
/* @__PURE__ */ jsx9("div", {
|
|
2261
|
+
className: "min-w-0 rounded-xl border p-3 sm:p-4",
|
|
2262
|
+
style: {
|
|
2263
|
+
backgroundColor: Schema7.is(EmailColor)(value.appearance.background) ? value.appearance.background : "#f4f4f5"
|
|
2264
|
+
},
|
|
2265
|
+
children: /* @__PURE__ */ jsxs5("div", {
|
|
2266
|
+
className: "min-w-0 rounded-lg p-2 shadow-sm sm:p-3",
|
|
2267
|
+
style: {
|
|
2268
|
+
...canvasVariables,
|
|
2269
|
+
backgroundColor: Schema7.is(EmailColor)(value.appearance.surface) ? value.appearance.surface : "#ffffff",
|
|
2270
|
+
color: Schema7.is(EmailColor)(value.appearance.text) ? value.appearance.text : "#18181b",
|
|
2271
|
+
fontFamily: fonts[value.appearance.font]
|
|
2272
|
+
},
|
|
2273
|
+
children: [
|
|
2274
|
+
!value.elements.length ? /* @__PURE__ */ jsx9("p", {
|
|
2275
|
+
className: "p-8 text-center text-sm",
|
|
2276
|
+
children: copy.empty
|
|
2277
|
+
}) : null,
|
|
2278
|
+
/* @__PURE__ */ jsx9(AnimatedList, {
|
|
2279
|
+
items: value.elements,
|
|
2280
|
+
getKey: (element) => element.id,
|
|
2281
|
+
label: copy.content,
|
|
2282
|
+
locale,
|
|
2283
|
+
getItemLabel: (element) => copy[element.type],
|
|
2284
|
+
duration: 140,
|
|
2285
|
+
onReorder: disabled ? undefined : (elements) => onChange({ ...value, elements }),
|
|
2286
|
+
itemClassName: "group flex min-w-0 items-start gap-1 rounded-lg bg-[var(--email-paper)] transition-[background-color,box-shadow] hover:bg-[var(--email-hover)] data-[dragging]:bg-[var(--email-hover)] data-[dragging]:shadow-lg [&>[data-slot=animated-list-handle]]:text-inherit",
|
|
2287
|
+
children: (element) => /* @__PURE__ */ jsxs5("div", {
|
|
2288
|
+
className: "min-w-0 flex-1 rounded-lg border border-transparent transition-colors hover:border-current",
|
|
2289
|
+
onClick: (event) => {
|
|
2290
|
+
if (!disabled) {
|
|
2291
|
+
setActive(element.id);
|
|
2292
|
+
if (element.type !== "text" || active !== element.id) {
|
|
2293
|
+
setSettingsAnchor(event.currentTarget);
|
|
2294
|
+
setSettingsOpen(true);
|
|
2295
|
+
}
|
|
2296
|
+
}
|
|
2297
|
+
},
|
|
2298
|
+
onFocusCapture: () => {
|
|
2299
|
+
if (!disabled)
|
|
2300
|
+
setActive(element.id);
|
|
2301
|
+
},
|
|
2302
|
+
style: active === element.id ? { borderColor: value.appearance.primary } : undefined,
|
|
2303
|
+
children: [
|
|
2304
|
+
/* @__PURE__ */ jsx9("div", {
|
|
2305
|
+
className: "flex items-center justify-between gap-2 px-2 py-1 text-xs",
|
|
2306
|
+
children: /* @__PURE__ */ jsxs5("button", {
|
|
2307
|
+
type: "button",
|
|
2308
|
+
disabled,
|
|
2309
|
+
"aria-label": `${copy.editElement}: ${copy[element.type]}`,
|
|
2310
|
+
onClick: (event) => {
|
|
2311
|
+
setActive(element.id);
|
|
2312
|
+
setSettingsAnchor(event.currentTarget);
|
|
2313
|
+
setSettingsOpen(true);
|
|
2314
|
+
},
|
|
2315
|
+
className: "inline-flex items-center gap-1 rounded px-1 py-0.5 hover:underline",
|
|
2316
|
+
children: [
|
|
2317
|
+
/* @__PURE__ */ jsx9(Pencil, {
|
|
2318
|
+
className: "size-3",
|
|
2319
|
+
"aria-hidden": true
|
|
2320
|
+
}),
|
|
2321
|
+
copy[element.type]
|
|
2322
|
+
]
|
|
2323
|
+
})
|
|
2324
|
+
}),
|
|
2325
|
+
/* @__PURE__ */ jsx9("div", {
|
|
2326
|
+
style: {
|
|
2327
|
+
textAlign: element.alignment,
|
|
2328
|
+
paddingTop: element.paddingTop,
|
|
2329
|
+
paddingBottom: element.paddingBottom
|
|
2330
|
+
},
|
|
2331
|
+
className: "min-w-0 px-2",
|
|
2332
|
+
children: element.type === "text" ? active === element.id ? /* @__PURE__ */ jsx9(RichTextEditor, {
|
|
2333
|
+
value: element.content,
|
|
2334
|
+
variables,
|
|
2335
|
+
locale,
|
|
2336
|
+
label: copy.text,
|
|
2337
|
+
disabled,
|
|
2338
|
+
contentStyle: {
|
|
2339
|
+
color: value.appearance.text,
|
|
2340
|
+
backgroundColor: value.appearance.surface
|
|
2341
|
+
},
|
|
2342
|
+
onChange: (content) => update({ ...element, content })
|
|
2343
|
+
}) : /* @__PURE__ */ jsx9("div", {
|
|
2344
|
+
role: "button",
|
|
2345
|
+
tabIndex: disabled ? -1 : 0,
|
|
2346
|
+
"aria-label": `${copy.editElement}: ${copy.text}`,
|
|
2347
|
+
className: "cursor-text text-sm leading-relaxed",
|
|
2348
|
+
onClick: (event) => {
|
|
2349
|
+
event.preventDefault();
|
|
2350
|
+
setActive(element.id);
|
|
2351
|
+
},
|
|
2352
|
+
onKeyDown: (event) => {
|
|
2353
|
+
if (event.key === "Enter" || event.key === " ") {
|
|
2354
|
+
event.preventDefault();
|
|
2355
|
+
setActive(element.id);
|
|
2356
|
+
}
|
|
2357
|
+
},
|
|
2358
|
+
children: /* @__PURE__ */ jsx9(RichTextContent, {
|
|
2359
|
+
value: element.content,
|
|
2360
|
+
variables
|
|
2361
|
+
})
|
|
2362
|
+
}) : element.type === "button" ? /* @__PURE__ */ jsx9("button", {
|
|
2363
|
+
type: "button",
|
|
2364
|
+
disabled,
|
|
2365
|
+
onClick: () => setActive(element.id),
|
|
2366
|
+
className: "max-w-full rounded-md px-5 py-3 text-sm font-semibold break-words",
|
|
2367
|
+
style: {
|
|
2368
|
+
backgroundColor: value.appearance.primary,
|
|
2369
|
+
color: value.appearance.primaryText
|
|
2370
|
+
},
|
|
2371
|
+
children: element.label
|
|
2372
|
+
}) : element.type === "code" ? /* @__PURE__ */ jsx9("button", {
|
|
2373
|
+
type: "button",
|
|
2374
|
+
disabled,
|
|
2375
|
+
onClick: () => setActive(element.id),
|
|
2376
|
+
className: "w-full rounded-lg border border-[#e5e7eb] p-4 font-mono text-xl tracking-[0.2em]",
|
|
2377
|
+
children: `{{${element.variable}}}`
|
|
2378
|
+
}) : element.type === "image" || element.type === "logo" ? Schema7.is(RichTextLink)(element.src) ? /* @__PURE__ */ jsx9("img", {
|
|
2379
|
+
src: element.src,
|
|
2380
|
+
alt: element.alt,
|
|
2381
|
+
width: element.width,
|
|
2382
|
+
className: "inline-block max-w-full"
|
|
2383
|
+
}) : /* @__PURE__ */ jsx9(Image, {
|
|
2384
|
+
className: "mx-auto size-8"
|
|
2385
|
+
}) : element.type === "divider" ? /* @__PURE__ */ jsx9("hr", {
|
|
2386
|
+
className: "border-[#e5e7eb]"
|
|
2387
|
+
}) : element.type === "spacer" ? /* @__PURE__ */ jsx9("div", {
|
|
2388
|
+
style: { height: element.height },
|
|
2389
|
+
className: "min-h-2 rounded border border-dashed border-[#e5e7eb]"
|
|
2390
|
+
}) : null
|
|
2391
|
+
})
|
|
2392
|
+
]
|
|
2393
|
+
})
|
|
2394
|
+
})
|
|
2395
|
+
]
|
|
2396
|
+
})
|
|
2397
|
+
}),
|
|
2398
|
+
/* @__PURE__ */ jsx9(Popover.Root, {
|
|
2399
|
+
open: settingsOpen && !!selected,
|
|
2400
|
+
onOpenChange: setSettingsOpen,
|
|
2401
|
+
children: /* @__PURE__ */ jsx9(Popover.Portal, {
|
|
2402
|
+
children: /* @__PURE__ */ jsx9(Popover.Positioner, {
|
|
2403
|
+
anchor: settingsAnchor,
|
|
2404
|
+
side: "right",
|
|
2405
|
+
align: "start",
|
|
2406
|
+
sideOffset: 8,
|
|
2407
|
+
className: "z-50",
|
|
2408
|
+
children: /* @__PURE__ */ jsxs5(Popover.Popup, {
|
|
2409
|
+
initialFocus: false,
|
|
2410
|
+
className: "bg-popover text-popover-foreground max-h-[min(480px,80dvh)] w-[min(420px,calc(100vw-2rem))] space-y-3 overflow-y-auto rounded-xl border p-4 shadow-lg outline-none",
|
|
2411
|
+
children: [
|
|
2412
|
+
/* @__PURE__ */ jsxs5("div", {
|
|
2413
|
+
className: "flex items-center justify-between gap-2",
|
|
2414
|
+
children: [
|
|
2415
|
+
/* @__PURE__ */ jsx9(Popover.Title, {
|
|
2416
|
+
className: "text-xs font-semibold",
|
|
2417
|
+
children: selected ? copy[selected.type] : copy.properties
|
|
2418
|
+
}),
|
|
2419
|
+
/* @__PURE__ */ jsx9(Popover.Close, {
|
|
2420
|
+
"aria-label": copy.close,
|
|
2421
|
+
className: "hover:bg-muted rounded p-1",
|
|
2422
|
+
children: /* @__PURE__ */ jsx9(X, {
|
|
2423
|
+
className: "size-4"
|
|
2424
|
+
})
|
|
2425
|
+
})
|
|
2426
|
+
]
|
|
2427
|
+
}),
|
|
2428
|
+
!selected ? /* @__PURE__ */ jsx9("p", {
|
|
2429
|
+
className: "text-muted-foreground text-xs",
|
|
2430
|
+
children: copy.select
|
|
2431
|
+
}) : /* @__PURE__ */ jsxs5("div", {
|
|
2432
|
+
className: "grid min-w-0 items-end gap-3 sm:grid-cols-2 [&>label]:min-w-0",
|
|
2433
|
+
children: [
|
|
2434
|
+
field(copy.alignment, /* @__PURE__ */ jsx9(EmailEditorSelect, {
|
|
2435
|
+
label: copy.alignment,
|
|
2436
|
+
value: selected.alignment,
|
|
2437
|
+
disabled,
|
|
2438
|
+
options: ["left", "center", "right"].map((alignment) => ({
|
|
2439
|
+
value: alignment,
|
|
2440
|
+
label: copy[alignment]
|
|
2441
|
+
})),
|
|
2442
|
+
onValueChange: (alignment) => update({
|
|
2443
|
+
...selected,
|
|
2444
|
+
alignment: Schema7.decodeUnknownSync(EmailAlignment)(alignment)
|
|
2445
|
+
})
|
|
2446
|
+
})),
|
|
2447
|
+
/* @__PURE__ */ jsx9("div", {
|
|
2448
|
+
className: "grid grid-cols-2 gap-2",
|
|
2449
|
+
children: ["paddingTop", "paddingBottom"].map((key) => /* @__PURE__ */ jsxs5("label", {
|
|
2450
|
+
className: "grid gap-1.5 text-[11px]",
|
|
2451
|
+
children: [
|
|
2452
|
+
copy[key],
|
|
2453
|
+
/* @__PURE__ */ jsx9(Input, {
|
|
2454
|
+
type: "number",
|
|
2455
|
+
min: 0,
|
|
2456
|
+
max: 96,
|
|
2457
|
+
value: selected[key],
|
|
2458
|
+
disabled,
|
|
2459
|
+
onChange: (event) => update({
|
|
2460
|
+
...selected,
|
|
2461
|
+
[key]: event.target.valueAsNumber
|
|
2462
|
+
})
|
|
2463
|
+
})
|
|
2464
|
+
]
|
|
2465
|
+
}, key))
|
|
2466
|
+
}),
|
|
2467
|
+
selected.type === "button" ? /* @__PURE__ */ jsxs5(Fragment3, {
|
|
2468
|
+
children: [
|
|
2469
|
+
field(copy.label, /* @__PURE__ */ jsx9(Input, {
|
|
2470
|
+
value: selected.label,
|
|
2471
|
+
disabled,
|
|
2472
|
+
onChange: (event) => update({
|
|
2473
|
+
...selected,
|
|
2474
|
+
label: event.target.value
|
|
2475
|
+
})
|
|
2476
|
+
})),
|
|
2477
|
+
field(copy.destination, /* @__PURE__ */ jsx9(EmailEditorSelect, {
|
|
2478
|
+
label: copy.destination,
|
|
2479
|
+
disabled,
|
|
2480
|
+
options: [
|
|
2481
|
+
{ value: "__url", label: copy.url },
|
|
2482
|
+
...variables.filter((variable) => variable.type === "url").map((variable) => ({
|
|
2483
|
+
value: variable.key,
|
|
2484
|
+
label: variable.label
|
|
2485
|
+
}))
|
|
2486
|
+
],
|
|
2487
|
+
value: selected.destination.type === "variable" ? selected.destination.key : "__url",
|
|
2488
|
+
onValueChange: (destination) => update({
|
|
2489
|
+
...selected,
|
|
2490
|
+
destination: destination === "__url" ? {
|
|
2491
|
+
type: "url",
|
|
2492
|
+
url: "https://example.com"
|
|
2493
|
+
} : {
|
|
2494
|
+
type: "variable",
|
|
2495
|
+
key: destination
|
|
2496
|
+
}
|
|
2497
|
+
})
|
|
2498
|
+
})),
|
|
2499
|
+
selected.destination.type === "url" ? field(copy.url, /* @__PURE__ */ jsx9(Input, {
|
|
2500
|
+
type: "url",
|
|
2501
|
+
value: selected.destination.url,
|
|
2502
|
+
disabled,
|
|
2503
|
+
onChange: (event) => update({
|
|
2504
|
+
...selected,
|
|
2505
|
+
destination: {
|
|
2506
|
+
type: "url",
|
|
2507
|
+
url: event.target.value
|
|
2508
|
+
}
|
|
2509
|
+
})
|
|
2510
|
+
})) : null
|
|
2511
|
+
]
|
|
2512
|
+
}) : null,
|
|
2513
|
+
selected.type === "code" ? field(copy.variable, /* @__PURE__ */ jsx9(EmailEditorSelect, {
|
|
2514
|
+
label: copy.variable,
|
|
2515
|
+
disabled,
|
|
2516
|
+
value: selected.variable,
|
|
2517
|
+
options: variables.filter((variable) => variable.type === "text").map((variable) => ({
|
|
2518
|
+
value: variable.key,
|
|
2519
|
+
label: variable.label
|
|
2520
|
+
})),
|
|
2521
|
+
onValueChange: (variable) => update({
|
|
2522
|
+
...selected,
|
|
2523
|
+
variable
|
|
2524
|
+
})
|
|
2525
|
+
})) : null,
|
|
2526
|
+
selected.type === "logo" || selected.type === "image" ? /* @__PURE__ */ jsxs5(Fragment3, {
|
|
2527
|
+
children: [
|
|
2528
|
+
field(copy.src, /* @__PURE__ */ jsx9(Input, {
|
|
2529
|
+
type: "url",
|
|
2530
|
+
value: selected.src,
|
|
2531
|
+
disabled,
|
|
2532
|
+
onChange: (event) => update({
|
|
2533
|
+
...selected,
|
|
2534
|
+
src: event.target.value
|
|
2535
|
+
})
|
|
2536
|
+
})),
|
|
2537
|
+
field(copy.alt, /* @__PURE__ */ jsx9(Input, {
|
|
2538
|
+
value: selected.alt,
|
|
2539
|
+
disabled,
|
|
2540
|
+
onChange: (event) => update({
|
|
2541
|
+
...selected,
|
|
2542
|
+
alt: event.target.value
|
|
2543
|
+
})
|
|
2544
|
+
})),
|
|
2545
|
+
field(copy.width, /* @__PURE__ */ jsx9(Input, {
|
|
2546
|
+
type: "number",
|
|
2547
|
+
min: 32,
|
|
2548
|
+
max: 560,
|
|
2549
|
+
value: selected.width,
|
|
2550
|
+
disabled,
|
|
2551
|
+
onChange: (event) => update({
|
|
2552
|
+
...selected,
|
|
2553
|
+
width: event.target.valueAsNumber
|
|
2554
|
+
})
|
|
2555
|
+
}))
|
|
2556
|
+
]
|
|
2557
|
+
}) : null,
|
|
2558
|
+
selected.type === "spacer" ? field(copy.height, /* @__PURE__ */ jsx9(Input, {
|
|
2559
|
+
type: "number",
|
|
2560
|
+
min: 0,
|
|
2561
|
+
max: 96,
|
|
2562
|
+
value: selected.height,
|
|
2563
|
+
disabled,
|
|
2564
|
+
onChange: (event) => update({
|
|
2565
|
+
...selected,
|
|
2566
|
+
height: event.target.valueAsNumber
|
|
2567
|
+
})
|
|
2568
|
+
})) : null,
|
|
2569
|
+
/* @__PURE__ */ jsxs5("div", {
|
|
2570
|
+
className: "flex flex-wrap items-center gap-2 sm:col-span-2",
|
|
2571
|
+
children: [
|
|
2572
|
+
/* @__PURE__ */ jsxs5(Button, {
|
|
2573
|
+
type: "button",
|
|
2574
|
+
size: "sm",
|
|
2575
|
+
variant: "outline",
|
|
2576
|
+
disabled: disabled || value.elements.length >= 40,
|
|
2577
|
+
onClick: () => {
|
|
2578
|
+
const duplicate = {
|
|
2579
|
+
...selected,
|
|
2580
|
+
id: crypto.randomUUID()
|
|
2581
|
+
};
|
|
2582
|
+
const index = value.elements.findIndex((element) => element.id === selected.id);
|
|
2583
|
+
onChange({
|
|
2584
|
+
...value,
|
|
2585
|
+
elements: [
|
|
2586
|
+
...value.elements.slice(0, index + 1),
|
|
2587
|
+
duplicate,
|
|
2588
|
+
...value.elements.slice(index + 1)
|
|
2589
|
+
]
|
|
2590
|
+
});
|
|
2591
|
+
setActive(duplicate.id);
|
|
2592
|
+
},
|
|
2593
|
+
children: [
|
|
2594
|
+
/* @__PURE__ */ jsx9(Copy, {
|
|
2595
|
+
className: "size-3.5"
|
|
2596
|
+
}),
|
|
2597
|
+
copy.duplicate
|
|
2598
|
+
]
|
|
2599
|
+
}),
|
|
2600
|
+
/* @__PURE__ */ jsxs5(Button, {
|
|
2601
|
+
type: "button",
|
|
2602
|
+
size: "sm",
|
|
2603
|
+
variant: "ghost",
|
|
2604
|
+
className: "text-destructive",
|
|
2605
|
+
disabled,
|
|
2606
|
+
onClick: () => {
|
|
2607
|
+
document.getElementById(`${id}-add`)?.focus();
|
|
2608
|
+
onChange({
|
|
2609
|
+
...value,
|
|
2610
|
+
elements: value.elements.filter((element) => element.id !== selected.id)
|
|
2611
|
+
});
|
|
2612
|
+
setActive(null);
|
|
2613
|
+
setSettingsOpen(false);
|
|
2614
|
+
},
|
|
2615
|
+
children: [
|
|
2616
|
+
/* @__PURE__ */ jsx9(Trash2, {
|
|
2617
|
+
className: "size-3.5"
|
|
2618
|
+
}),
|
|
2619
|
+
copy.remove
|
|
2620
|
+
]
|
|
2621
|
+
})
|
|
2622
|
+
]
|
|
2623
|
+
})
|
|
2624
|
+
]
|
|
2625
|
+
})
|
|
2626
|
+
]
|
|
2627
|
+
})
|
|
2628
|
+
})
|
|
2629
|
+
})
|
|
2630
|
+
})
|
|
2631
|
+
]
|
|
2632
|
+
}),
|
|
2633
|
+
/* @__PURE__ */ jsx9("p", {
|
|
2634
|
+
className: "text-muted-foreground text-xs",
|
|
2635
|
+
children: copy.local
|
|
2636
|
+
})
|
|
2637
|
+
]
|
|
2638
|
+
})
|
|
2639
|
+
]
|
|
2640
|
+
}),
|
|
2641
|
+
invalid ? /* @__PURE__ */ jsx9("p", {
|
|
2642
|
+
role: "alert",
|
|
2643
|
+
className: "text-destructive text-xs",
|
|
2644
|
+
children: copy.invalid
|
|
2645
|
+
}) : null
|
|
2646
|
+
]
|
|
2647
|
+
});
|
|
2648
|
+
};
|
|
2649
|
+
export {
|
|
2650
|
+
EmailEditor
|
|
2651
|
+
};
|