@simple-builder/react 1.2.4 → 1.2.5

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.
@@ -1,2248 +0,0 @@
1
- 'use client';
2
- 'use client';
3
- 'use client';
4
- import './chunk-MV72DQML.mjs';
5
- import { buttonVariants, Button, useBuilder } from './chunk-Q42UV6O3.mjs';
6
- import { cn, tv, DesignWrapper, builder, Image } from './chunk-F7EVAQN7.mjs';
7
- import * as React25 from 'react';
8
- import { useCallback } from 'react';
9
- import { ChevronRight, Check, Circle, X, ChevronDown, ChevronUp, PlusIcon, ArrowUp, ArrowDown, Edit2Icon, Trash2Icon, ImageIcon, XIcon, PlusCircleIcon, CalendarIcon, MonitorIcon, SmartphoneIcon, ChevronLeftIcon, ChevronRightIcon, PaintbrushIcon, Loader2Icon, AlignHorizontalSpaceAroundIcon, AlignHorizontalJustifyStartIcon, ScanIcon } from 'lucide-react';
10
- import * as AlertDialogPrimitive from '@radix-ui/react-alert-dialog';
11
- import * as PopoverPrimitive from '@radix-ui/react-popover';
12
- import { mergeAttributes, getMarkRange, EditorContent, useEditor } from '@tiptap/react';
13
- import { Color } from '@tiptap/extension-color';
14
- import { TextStyle } from '@tiptap/extension-text-style';
15
- import { Underline } from '@tiptap/extension-underline';
16
- import { StarterKit } from '@tiptap/starter-kit';
17
- import TiptapLink from '@tiptap/extension-link';
18
- import { Plugin, TextSelection } from '@tiptap/pm/state';
19
- import * as DropdownMenuPrimitive from '@radix-ui/react-dropdown-menu';
20
- import * as SeparatorPrimitive from '@radix-ui/react-separator';
21
- import * as TogglePrimitive from '@radix-ui/react-toggle';
22
- import { cva } from 'class-variance-authority';
23
- import { LuChevronDown, LuCheck, LuHeading, LuLink2, LuEllipsis, LuBold, LuItalic, LuUnderline, LuStrikethrough, LuCode, LuRemoveFormatting, LuQuote, LuMinus, LuListOrdered, LuList } from 'react-icons/lu';
24
- import * as ToggleGroupPrimitive from '@radix-ui/react-toggle-group';
25
- import * as DialogPrimitive from '@radix-ui/react-dialog';
26
- import { Slot } from '@radix-ui/react-slot';
27
- import { useFormContext, useForm, useFieldArray, FormProvider, Controller } from 'react-hook-form';
28
- import * as LabelPrimitive from '@radix-ui/react-label';
29
- import * as SwitchPrimitives from '@radix-ui/react-switch';
30
- import { zodResolver } from '@hookform/resolvers/zod';
31
- import { z } from 'zod';
32
- import { format } from 'date-fns';
33
- import { DayPicker } from 'react-day-picker';
34
- import * as SelectPrimitive from '@radix-ui/react-select';
35
- import * as TabsPrimitive from '@radix-ui/react-tabs';
36
- import * as ScrollAreaPrimitive from '@radix-ui/react-scroll-area';
37
-
38
- var AlertDialog = AlertDialogPrimitive.Root;
39
- var AlertDialogTrigger = AlertDialogPrimitive.Trigger;
40
- var AlertDialogPortal = AlertDialogPrimitive.Portal;
41
- var AlertDialogOverlay = React25.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ React25.createElement(
42
- AlertDialogPrimitive.Overlay,
43
- {
44
- className: cn(
45
- "sb-fixed sb-inset-0 sb-z-50 sb-bg-background/80 sb-backdrop-blur-sm data-[state=open]:sb-animate-in data-[state=closed]:sb-animate-out data-[state=closed]:sb-fade-out-0 data-[state=open]:sb-fade-in-0",
46
- className
47
- ),
48
- ...props,
49
- ref
50
- }
51
- ));
52
- AlertDialogOverlay.displayName = AlertDialogPrimitive.Overlay.displayName;
53
- var AlertDialogContent = React25.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ React25.createElement(AlertDialogPortal, null, /* @__PURE__ */ React25.createElement(AlertDialogOverlay, null), /* @__PURE__ */ React25.createElement(
54
- AlertDialogPrimitive.Content,
55
- {
56
- ref,
57
- className: cn(
58
- "sb-fixed sb-font-roboto sb-left-[50%] sb-top-[50%] sb-z-50 sb-grid sb-w-full sb-max-w-lg sb-translate-x-[-50%] sb-translate-y-[-50%] sb-gap-4 sb-border sb-bg-background sb-p-6 sb-shadow-lg sb-duration-200 data-[state=open]:sb-animate-in data-[state=closed]:sb-animate-out data-[state=closed]:sb-fade-out-0 data-[state=open]:sb-fade-in-0 data-[state=closed]:sb-zoom-out-95 data-[state=open]:sb-zoom-in-95 data-[state=closed]:sb-slide-out-to-left-1/2 data-[state=closed]:sb-slide-out-to-top-[48%] data-[state=open]:sb-slide-in-from-left-1/2 data-[state=open]:sb-slide-in-from-top-[48%] sm:sb-rounded-lg",
59
- className
60
- ),
61
- ...props
62
- }
63
- )));
64
- AlertDialogContent.displayName = AlertDialogPrimitive.Content.displayName;
65
- var AlertDialogFooter = ({
66
- className,
67
- ...props
68
- }) => /* @__PURE__ */ React25.createElement(
69
- "div",
70
- {
71
- className: cn(
72
- "sb-flex sb-flex-col-reverse sm:sb-flex-row sm:sb-justify-end sm:sb-space-x-2",
73
- className
74
- ),
75
- ...props
76
- }
77
- );
78
- AlertDialogFooter.displayName = "AlertDialogFooter";
79
- var AlertDialogTitle = React25.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ React25.createElement(
80
- AlertDialogPrimitive.Title,
81
- {
82
- ref,
83
- className: cn("sb-text-lg sb-font-semibold", className),
84
- ...props
85
- }
86
- ));
87
- AlertDialogTitle.displayName = AlertDialogPrimitive.Title.displayName;
88
- var AlertDialogDescription = React25.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ React25.createElement(
89
- AlertDialogPrimitive.Description,
90
- {
91
- ref,
92
- className: cn("sb-text-sm sb-text-muted-foreground", className),
93
- ...props
94
- }
95
- ));
96
- AlertDialogDescription.displayName = AlertDialogPrimitive.Description.displayName;
97
- var AlertDialogAction = React25.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ React25.createElement(
98
- AlertDialogPrimitive.Action,
99
- {
100
- ref,
101
- className: cn(buttonVariants(), className),
102
- ...props
103
- }
104
- ));
105
- AlertDialogAction.displayName = AlertDialogPrimitive.Action.displayName;
106
- var AlertDialogCancel = React25.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ React25.createElement(
107
- AlertDialogPrimitive.Cancel,
108
- {
109
- ref,
110
- className: cn(
111
- buttonVariants({ variant: "outline" }),
112
- "sb-mt-2 sm:sb-mt-0",
113
- className
114
- ),
115
- ...props
116
- }
117
- ));
118
- AlertDialogCancel.displayName = AlertDialogPrimitive.Cancel.displayName;
119
- var Popover = PopoverPrimitive.Root;
120
- var PopoverTrigger = PopoverPrimitive.Trigger;
121
- var PopoverClose = PopoverPrimitive.Close;
122
- var PopoverContent = React25.forwardRef(({ className, align = "center", sideOffset = 4, ...props }, ref) => /* @__PURE__ */ React25.createElement(PopoverPrimitive.Portal, null, /* @__PURE__ */ React25.createElement(
123
- PopoverPrimitive.Content,
124
- {
125
- ref,
126
- align,
127
- sideOffset,
128
- className: cn(
129
- "sb-z-50 sb-w-72 sb-rounded-md sb-border sb-bg-popover sb-p-4 sb-text-popover-foreground sb-shadow-md sb-outline-none data-[state=open]:sb-animate-in data-[state=closed]:sb-animate-out data-[state=closed]:sb-fade-out-0 data-[state=open]:sb-fade-in-0 data-[state=closed]:sb-zoom-out-95 data-[state=open]:sb-zoom-in-95 data-[side=bottom]:sb-slide-in-from-top-2 data-[side=left]:sb-slide-in-from-right-2 data-[side=right]:sb-slide-in-from-left-2 data-[side=top]:sb-slide-in-from-bottom-2 sb-origin-[--radix-popover-content-transform-origin]",
130
- className
131
- ),
132
- ...props
133
- }
134
- )));
135
- PopoverContent.displayName = PopoverPrimitive.Content.displayName;
136
- var Link = TiptapLink.extend({
137
- inclusive: false,
138
- parseHTML() {
139
- return [{ tag: 'a[href]:not([data-type="button"]):not([href *= "javascript:" i])' }];
140
- },
141
- renderHTML({ HTMLAttributes }) {
142
- return ["a", mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0];
143
- },
144
- addOptions() {
145
- return {
146
- ...this.parent?.(),
147
- openOnClick: false
148
- };
149
- },
150
- addProseMirrorPlugins() {
151
- return [
152
- ...this.parent?.() || [],
153
- new Plugin({
154
- props: {
155
- handleClick(view, pos) {
156
- const { schema: schema2, doc, tr } = view.state;
157
- const range = getMarkRange(doc.resolve(pos), schema2.marks.link);
158
- if (!range) {
159
- return;
160
- }
161
- const { from, to } = range;
162
- const start = Math.min(from, to);
163
- const end = Math.max(from, to);
164
- if (pos < start || pos > end) {
165
- return;
166
- }
167
- const $start = doc.resolve(start);
168
- const $end = doc.resolve(end);
169
- const transaction = tr.setSelection(new TextSelection($start, $end));
170
- view.dispatch(transaction);
171
- }
172
- }
173
- })
174
- ];
175
- }
176
- });
177
-
178
- // src/features/rich-text-editor/utils/get-output.ts
179
- var getOutput = (editor, format2) => {
180
- switch (format2) {
181
- case "json":
182
- return editor.getJSON();
183
- case "html":
184
- return editor.isEmpty ? "" : editor.getHTML();
185
- default:
186
- return editor.getText();
187
- }
188
- };
189
-
190
- // src/features/rich-text-editor/hooks/useRichTextEditor.ts
191
- var useRichTextEditor = ({
192
- value,
193
- output = "html",
194
- editorClassName,
195
- onUpdate,
196
- onBlur,
197
- ...options
198
- }) => {
199
- const handleCreate = useCallback(
200
- (editor2) => {
201
- if (value && editor2.isEmpty) {
202
- editor2.commands.setContent(value);
203
- }
204
- },
205
- [value]
206
- );
207
- const handleUpdate = useCallback(
208
- (editor2) => {
209
- onUpdate?.(getOutput(editor2, output));
210
- },
211
- [output]
212
- );
213
- const handleBlur = useCallback(
214
- (editor2) => {
215
- onBlur?.(getOutput(editor2, output));
216
- },
217
- [output, onBlur]
218
- );
219
- const editor = useEditor({
220
- extensions: [StarterKit, Underline, Color, TextStyle, Link],
221
- editorProps: {
222
- attributes: {
223
- autocomplete: "off",
224
- autocorrect: "off",
225
- autocapitalize: "off",
226
- class: cn("sb-focus:outline-none", editorClassName)
227
- }
228
- },
229
- onCreate: ({ editor: editor2 }) => handleCreate(editor2),
230
- onUpdate: ({ editor: editor2 }) => handleUpdate(editor2),
231
- onBlur: ({ editor: editor2 }) => handleBlur(editor2),
232
- ...options
233
- });
234
- return editor;
235
- };
236
- var DropdownMenu = DropdownMenuPrimitive.Root;
237
- var DropdownMenuTrigger = DropdownMenuPrimitive.Trigger;
238
- var DropdownMenuSubTrigger = React25.forwardRef(({ className, inset, children, ...props }, ref) => /* @__PURE__ */ React25.createElement(
239
- DropdownMenuPrimitive.SubTrigger,
240
- {
241
- ref,
242
- className: cn(
243
- "sb-flex sb-cursor-default sb-select-none sb-items-center sb-gap-2 sb-rounded-sm sb-px-2 sb-py-1.5 sb-text-sm sb-outline-none focus:sb-bg-accent data-[state=open]:sb-bg-accent [&_svg]:sb-pointer-events-none [&_svg]:sb-size-4 [&_svg]:sb-shrink-0",
244
- inset && "sb-pl-8",
245
- className
246
- ),
247
- ...props
248
- },
249
- children,
250
- /* @__PURE__ */ React25.createElement(ChevronRight, { className: "sb-ml-auto" })
251
- ));
252
- DropdownMenuSubTrigger.displayName = DropdownMenuPrimitive.SubTrigger.displayName;
253
- var DropdownMenuSubContent = React25.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ React25.createElement(
254
- DropdownMenuPrimitive.SubContent,
255
- {
256
- ref,
257
- className: cn(
258
- "sb-z-50 sb-min-w-[8rem] sb-overflow-hidden sb-rounded-md sb-border sb-bg-popover sb-p-1 sb-text-popover-foreground sb-shadow-lg data-[state=open]:sb-animate-in data-[state=closed]:sb-animate-out data-[state=closed]:sb-fade-out-0 data-[state=open]:sb-fade-in-0 data-[state=closed]:sb-zoom-out-95 data-[state=open]:sb-zoom-in-95 data-[side=bottom]:sb-slide-in-from-top-2 data-[side=left]:sb-slide-in-from-right-2 data-[side=right]:sb-slide-in-from-left-2 data-[side=top]:sb-slide-in-from-bottom-2 sb-origin-[--radix-dropdown-menu-content-transform-origin]",
259
- className
260
- ),
261
- ...props
262
- }
263
- ));
264
- DropdownMenuSubContent.displayName = DropdownMenuPrimitive.SubContent.displayName;
265
- var DropdownMenuContent = React25.forwardRef(({ className, sideOffset = 4, ...props }, ref) => /* @__PURE__ */ React25.createElement(DropdownMenuPrimitive.Portal, null, /* @__PURE__ */ React25.createElement(
266
- DropdownMenuPrimitive.Content,
267
- {
268
- ref,
269
- sideOffset,
270
- className: cn(
271
- "sb-z-50 sb-max-h-[var(--radix-dropdown-menu-content-available-height)] sb-min-w-[8rem] sb-overflow-y-auto sb-overflow-x-hidden sb-rounded-md sb-border sb-bg-popover sb-p-1 sb-text-popover-foreground sb-shadow-md",
272
- "data-[state=open]:sb-animate-in data-[state=closed]:sb-animate-out data-[state=closed]:sb-fade-out-0 data-[state=open]:sb-fade-in-0 data-[state=closed]:sb-zoom-out-95 data-[state=open]:sb-zoom-in-95 data-[side=bottom]:sb-slide-in-from-top-2 data-[side=left]:sb-slide-in-from-right-2 data-[side=right]:sb-slide-in-from-left-2 data-[side=top]:sb-slide-in-from-bottom-2 sb-origin-[--radix-dropdown-menu-content-transform-origin]",
273
- className
274
- ),
275
- ...props
276
- }
277
- )));
278
- DropdownMenuContent.displayName = DropdownMenuPrimitive.Content.displayName;
279
- var DropdownMenuItem = React25.forwardRef(({ className, inset, ...props }, ref) => /* @__PURE__ */ React25.createElement(
280
- DropdownMenuPrimitive.Item,
281
- {
282
- ref,
283
- className: cn(
284
- "sb-relative sb-flex sb-cursor-default sb-select-none sb-items-center sb-gap-2 sb-rounded-sm sb-px-2 sb-py-1.5 sb-text-sm sb-outline-none sb-transition-colors focus:sb-bg-accent focus:sb-text-accent-foreground data-[disabled]:sb-pointer-events-none data-[disabled]:sb-opacity-50 [&>svg]:sb-size-4 [&>svg]:sb-shrink-0",
285
- inset && "sb-pl-8",
286
- className
287
- ),
288
- ...props
289
- }
290
- ));
291
- DropdownMenuItem.displayName = DropdownMenuPrimitive.Item.displayName;
292
- var DropdownMenuCheckboxItem = React25.forwardRef(({ className, children, checked, ...props }, ref) => /* @__PURE__ */ React25.createElement(
293
- DropdownMenuPrimitive.CheckboxItem,
294
- {
295
- ref,
296
- className: cn(
297
- "sb-relative sb-flex sb-cursor-default sb-select-none sb-items-center sb-rounded-sm sb-py-1.5 sb-pl-8 sb-pr-2 sb-text-sm sb-outline-none sb-transition-colors focus:sb-bg-accent focus:sb-text-accent-foreground data-[disabled]:sb-pointer-events-none data-[disabled]:sb-opacity-50",
298
- className
299
- ),
300
- checked,
301
- ...props
302
- },
303
- /* @__PURE__ */ React25.createElement("span", { className: "sb-absolute sb-left-2 sb-flex sb-h-3.5 sb-w-3.5 sb-items-center sb-justify-center" }, /* @__PURE__ */ React25.createElement(DropdownMenuPrimitive.ItemIndicator, null, /* @__PURE__ */ React25.createElement(Check, { className: "sb-h-4 sb-w-4" }))),
304
- children
305
- ));
306
- DropdownMenuCheckboxItem.displayName = DropdownMenuPrimitive.CheckboxItem.displayName;
307
- var DropdownMenuRadioItem = React25.forwardRef(({ className, children, ...props }, ref) => /* @__PURE__ */ React25.createElement(
308
- DropdownMenuPrimitive.RadioItem,
309
- {
310
- ref,
311
- className: cn(
312
- "sb-relative sb-flex sb-cursor-default sb-select-none sb-items-center sb-rounded-sm sb-py-1.5 sb-pl-8 sb-pr-2 sb-text-sm sb-outline-none sb-transition-colors focus:sb-bg-accent focus:sb-text-accent-foreground data-[disabled]:sb-pointer-events-none data-[disabled]:sb-opacity-50",
313
- className
314
- ),
315
- ...props
316
- },
317
- /* @__PURE__ */ React25.createElement("span", { className: "sb-absolute sb-left-2 sb-flex sb-h-3.5 sb-w-3.5 sb-items-center sb-justify-center" }, /* @__PURE__ */ React25.createElement(DropdownMenuPrimitive.ItemIndicator, null, /* @__PURE__ */ React25.createElement(Circle, { className: "sb-h-2 sb-w-2 sb-fill-current" }))),
318
- children
319
- ));
320
- DropdownMenuRadioItem.displayName = DropdownMenuPrimitive.RadioItem.displayName;
321
- var DropdownMenuLabel = React25.forwardRef(({ className, inset, ...props }, ref) => /* @__PURE__ */ React25.createElement(
322
- DropdownMenuPrimitive.Label,
323
- {
324
- ref,
325
- className: cn(
326
- "sb-px-2 sb-py-1.5 sb-text-sm sb-font-semibold",
327
- inset && "sb-pl-8",
328
- className
329
- ),
330
- ...props
331
- }
332
- ));
333
- DropdownMenuLabel.displayName = DropdownMenuPrimitive.Label.displayName;
334
- var DropdownMenuSeparator = React25.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ React25.createElement(
335
- DropdownMenuPrimitive.Separator,
336
- {
337
- ref,
338
- className: cn("sb--mx-1 sb-my-1 sb-h-px sb-bg-muted", className),
339
- ...props
340
- }
341
- ));
342
- DropdownMenuSeparator.displayName = DropdownMenuPrimitive.Separator.displayName;
343
- var Separator2 = React25.forwardRef(
344
- ({ className, orientation = "horizontal", decorative = true, ...props }, ref) => /* @__PURE__ */ React25.createElement(
345
- SeparatorPrimitive.Root,
346
- {
347
- ref,
348
- decorative,
349
- orientation,
350
- className: cn(
351
- "sb-shrink-0 sb-bg-border",
352
- orientation === "horizontal" ? "sb-h-[1px] sb-w-full" : "sb-h-full sb-w-[1px]",
353
- className
354
- ),
355
- ...props
356
- }
357
- )
358
- );
359
- Separator2.displayName = SeparatorPrimitive.Root.displayName;
360
- var toggleVariants = cva(
361
- "sb-inline-flex sb-items-center sb-justify-center sb-gap-2 sb-rounded-md sb-text-sm sb-font-medium sb-transition-colors hover:sb-bg-muted hover:sb-text-muted-foreground focus-visible:sb-outline-none focus-visible:sb-ring-1 focus-visible:sb-ring-ring disabled:sb-pointer-events-none disabled:sb-opacity-50 data-[state=on]:sb-bg-accent data-[state=on]:sb-text-accent-foreground [&_svg]:sb-pointer-events-none [&_svg]:sb-size-4 [&_svg]:sb-shrink-0",
362
- {
363
- variants: {
364
- variant: {
365
- default: "sb-bg-transparent",
366
- outline: "sb-border sb-border-input sb-bg-transparent sb-shadow-sm hover:sb-bg-accent hover:sb-text-accent-foreground"
367
- },
368
- size: {
369
- default: "sb-h-9 sb-px-2 sb-min-w-9",
370
- sm: "sb-h-8 sb-px-1.5 sb-min-w-8",
371
- lg: "sb-h-10 sb-px-2.5 sb-min-w-10"
372
- }
373
- },
374
- defaultVariants: {
375
- variant: "default",
376
- size: "default"
377
- }
378
- }
379
- );
380
- var Toggle = React25.forwardRef(({ className, variant, size, ...props }, ref) => /* @__PURE__ */ React25.createElement(
381
- TogglePrimitive.Root,
382
- {
383
- ref,
384
- className: cn(toggleVariants({ variant, size, className })),
385
- ...props
386
- }
387
- ));
388
- Toggle.displayName = TogglePrimitive.Root.displayName;
389
- var ToggleGroupContext = React25.createContext({
390
- size: "default",
391
- variant: "default"
392
- });
393
- var ToggleGroup = React25.forwardRef(({ className, variant, size, children, ...props }, ref) => /* @__PURE__ */ React25.createElement(
394
- ToggleGroupPrimitive.Root,
395
- {
396
- ref,
397
- className: cn("sb-flex sb-items-center sb-justify-center sb-gap-1", className),
398
- ...props
399
- },
400
- /* @__PURE__ */ React25.createElement(ToggleGroupContext.Provider, { value: { variant, size } }, children)
401
- ));
402
- ToggleGroup.displayName = ToggleGroupPrimitive.Root.displayName;
403
- var ToggleGroupItem = React25.forwardRef(({ className, children, variant, size, ...props }, ref) => {
404
- const context = React25.useContext(ToggleGroupContext);
405
- return /* @__PURE__ */ React25.createElement(
406
- ToggleGroupPrimitive.Item,
407
- {
408
- ref,
409
- className: cn(
410
- toggleVariants({
411
- variant: context.variant || variant,
412
- size: context.size || size
413
- }),
414
- className
415
- ),
416
- ...props
417
- },
418
- children
419
- );
420
- });
421
- ToggleGroupItem.displayName = ToggleGroupPrimitive.Item.displayName;
422
- var PALETTES = [
423
- {
424
- inverse: "hsl(var(--background))",
425
- colors: [
426
- { cssVar: "hsl(var(--foreground))" },
427
- { cssVar: "hsl(var(--secondary-foreground))" },
428
- { cssVar: "hsl(var(--muted-foreground))" },
429
- { cssVar: "hsl(var(--accent-foreground))" },
430
- { cssVar: "hsl(var(--destructive-foreground))" }
431
- ]
432
- },
433
- {
434
- inverse: "hsl(var(--foreground))",
435
- colors: [
436
- { cssVar: "hsl(var(--background))" },
437
- { cssVar: "hsl(var(--secondary))" },
438
- { cssVar: "hsl(var(--muted))" },
439
- { cssVar: "hsl(var(--accent))" },
440
- { cssVar: "hsl(var(--destructive))" }
441
- ]
442
- }
443
- ];
444
- var ColorTool = ({ editor }) => {
445
- const color = editor.getAttributes("textStyle")?.color || "hsl(var(--foreground))";
446
- const [selectedColor, setSelectedColor] = React25.useState(color);
447
- React25.useEffect(() => {
448
- setSelectedColor(color);
449
- }, [color]);
450
- const handleColorChange = React25.useCallback(
451
- (value) => {
452
- setSelectedColor(value);
453
- editor.chain().focus().setColor(value).run();
454
- },
455
- [editor]
456
- );
457
- return /* @__PURE__ */ React25.createElement(Popover, { modal: true }, /* @__PURE__ */ React25.createElement(PopoverTrigger, { asChild: true }, /* @__PURE__ */ React25.createElement(ToolbarButton, { className: "sb-w-12" }, /* @__PURE__ */ React25.createElement(
458
- "svg",
459
- {
460
- xmlns: "http://www.w3.org/2000/svg",
461
- width: "24",
462
- height: "24",
463
- viewBox: "0 0 24 24",
464
- fill: "none",
465
- stroke: "currentColor",
466
- strokeWidth: "2",
467
- strokeLinecap: "round",
468
- strokeLinejoin: "round",
469
- className: "sb-size-5",
470
- style: { color: selectedColor }
471
- },
472
- /* @__PURE__ */ React25.createElement("path", { d: "M4 20h16" }),
473
- /* @__PURE__ */ React25.createElement("path", { d: "m6 16 6-12 6 12" }),
474
- /* @__PURE__ */ React25.createElement("path", { d: "M8 12h8" })
475
- ), /* @__PURE__ */ React25.createElement(LuChevronDown, { className: "sb-size-5" }))), /* @__PURE__ */ React25.createElement(PopoverContent, { align: "start", className: "sb-w-full" }, /* @__PURE__ */ React25.createElement(
476
- ToggleGroup,
477
- {
478
- type: "single",
479
- value: selectedColor,
480
- onValueChange: handleColorChange,
481
- className: "sb-flex-col sb-gap-1.5"
482
- },
483
- PALETTES.map((pallete, i) => /* @__PURE__ */ React25.createElement("div", { key: i, className: "sb-flex sb-gap-1.5" }, pallete.colors.map((color2, j) => /* @__PURE__ */ React25.createElement(
484
- ToggleGroupItem,
485
- {
486
- tabIndex: 0,
487
- key: j,
488
- className: "sb-relative sb-size-7 sb-rounded-md sb-border sb-p-0",
489
- value: color2.cssVar,
490
- style: { backgroundColor: color2.cssVar }
491
- },
492
- selectedColor === color2.cssVar && /* @__PURE__ */ React25.createElement(
493
- LuCheck,
494
- {
495
- className: "sb-absolute sb-inset-0 sb-m-auto sb-size-6",
496
- style: { color: pallete.inverse }
497
- }
498
- )
499
- ))))
500
- )));
501
- };
502
- var formatActions = [
503
- {
504
- label: "Normal Text",
505
- element: "span",
506
- className: "sb-grow"
507
- },
508
- {
509
- label: "Heading 1",
510
- element: "h1",
511
- level: 1,
512
- className: "sb-m-0 sb-grow sb-text-3xl sb-font-extrabold"
513
- },
514
- {
515
- label: "Heading 2",
516
- element: "h2",
517
- level: 2,
518
- className: "sb-m-0 sb-grow sb-text-xl sb-font-bold"
519
- },
520
- {
521
- label: "Heading 3",
522
- element: "h3",
523
- level: 3,
524
- className: "sb-m-0 sb-grow sb-text-lg sb-font-semibold"
525
- },
526
- {
527
- label: "Heading 4",
528
- element: "h4",
529
- level: 4,
530
- className: "sb-m-0 sb-grow sb-text-base sb-font-semibold"
531
- }
532
- ];
533
- var ElementTool = ({ editor }) => {
534
- const isActive = editor.isActive("heading");
535
- const handleFormatChange = React25.useCallback(
536
- (level) => {
537
- if (level) {
538
- editor.chain().focus().toggleHeading({ level }).run();
539
- } else {
540
- editor.chain().focus().setParagraph().run();
541
- }
542
- },
543
- [editor]
544
- );
545
- return /* @__PURE__ */ React25.createElement(DropdownMenu, null, /* @__PURE__ */ React25.createElement(DropdownMenuTrigger, { asChild: true }, /* @__PURE__ */ React25.createElement(
546
- ToolbarButton,
547
- {
548
- className: "sb-w-12 data-[state=open]:sb-bg-accent",
549
- pressed: isActive
550
- },
551
- /* @__PURE__ */ React25.createElement(LuHeading, { className: "sb-size-5" }),
552
- /* @__PURE__ */ React25.createElement(LuChevronDown, { className: "sb-size-5" })
553
- )), /* @__PURE__ */ React25.createElement(DropdownMenuContent, { align: "start" }, formatActions.map(({ element: Element, ...action }) => /* @__PURE__ */ React25.createElement(
554
- DropdownMenuItem,
555
- {
556
- key: action.label,
557
- className: cn({
558
- "sb-bg-accent": action.level ? editor.isActive("heading", { level: action.level }) : editor.isActive("paragraph")
559
- }),
560
- onClick: () => handleFormatChange(action.level)
561
- },
562
- /* @__PURE__ */ React25.createElement(Element, { className: action.className }, action.label)
563
- ))));
564
- };
565
- var actions = [
566
- {
567
- value: "bold",
568
- label: "Bold",
569
- icon: LuBold,
570
- action: (editor) => editor.chain().focus().toggleBold().run(),
571
- isActive: (editor) => editor.isActive("bold"),
572
- canExecute: (editor) => editor.can().chain().focus().toggleBold().run() && !editor.isActive("codeBlock")
573
- },
574
- {
575
- value: "italic",
576
- label: "Italic",
577
- icon: LuItalic,
578
- action: (editor) => editor.chain().focus().toggleItalic().run(),
579
- isActive: (editor) => editor.isActive("italic"),
580
- canExecute: (editor) => editor.can().chain().focus().toggleItalic().run() && !editor.isActive("codeBlock")
581
- },
582
- {
583
- value: "underline",
584
- label: "Underline",
585
- icon: LuUnderline,
586
- action: (editor) => editor.chain().focus().toggleUnderline().run(),
587
- isActive: (editor) => editor.isActive("underline"),
588
- canExecute: (editor) => editor.can().chain().focus().toggleUnderline().run() && !editor.isActive("codeBlock")
589
- },
590
- {
591
- value: "strikethrough",
592
- label: "Strikethrough",
593
- icon: LuStrikethrough,
594
- action: (editor) => editor.chain().focus().toggleStrike().run(),
595
- isActive: (editor) => editor.isActive("strike"),
596
- canExecute: (editor) => editor.can().chain().focus().toggleStrike().run() && !editor.isActive("codeBlock")
597
- },
598
- {
599
- value: "code",
600
- label: "Code",
601
- icon: LuCode,
602
- action: (editor) => editor.chain().focus().toggleCode().run(),
603
- isActive: (editor) => editor.isActive("code"),
604
- canExecute: (editor) => editor.can().chain().focus().toggleCode().run() && !editor.isActive("codeBlock")
605
- },
606
- {
607
- value: "clearFormatting",
608
- label: "Clear formatting",
609
- icon: LuRemoveFormatting,
610
- action: (editor) => editor.chain().focus().unsetAllMarks().run(),
611
- isActive: () => false,
612
- canExecute: (editor) => editor.can().chain().focus().unsetAllMarks().run() && !editor.isActive("codeBlock")
613
- }
614
- ];
615
- var FormatTool = ({ editor }) => {
616
- return /* @__PURE__ */ React25.createElement(ToolbarSection, { editor, actions, mainActionCount: 1 });
617
- };
618
- var actions2 = [
619
- {
620
- value: "codeBlock",
621
- label: "Code block",
622
- icon: LuCode,
623
- action: (editor) => editor.chain().focus().toggleCodeBlock().run(),
624
- isActive: (editor) => editor.isActive("codeBlock"),
625
- canExecute: (editor) => editor.can().chain().focus().toggleCodeBlock().run()
626
- },
627
- {
628
- value: "blockquote",
629
- label: "Blockquote",
630
- icon: LuQuote,
631
- action: (editor) => editor.chain().focus().toggleBlockquote().run(),
632
- isActive: (editor) => editor.isActive("blockquote"),
633
- canExecute: (editor) => editor.can().chain().focus().toggleBlockquote().run()
634
- },
635
- {
636
- value: "horizontalRule",
637
- label: "Divider",
638
- icon: LuMinus,
639
- action: (editor) => editor.chain().focus().setHorizontalRule().run(),
640
- isActive: () => false,
641
- canExecute: (editor) => editor.can().chain().focus().setHorizontalRule().run()
642
- }
643
- ];
644
- var InsertTool = ({ editor }) => {
645
- return /* @__PURE__ */ React25.createElement(ToolbarSection, { editor, actions: actions2, mainActionCount: 0 });
646
- };
647
- var Dialog = DialogPrimitive.Root;
648
- var DialogTrigger = DialogPrimitive.Trigger;
649
- var DialogPortal = DialogPrimitive.Portal;
650
- var DialogOverlay = React25.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ React25.createElement(
651
- DialogPrimitive.Overlay,
652
- {
653
- ref,
654
- className: cn(
655
- "sb-fixed sb-inset-0 sb-z-50 sb-bg-black/80 sb- data-[state=open]:sb-animate-in data-[state=closed]:sb-animate-out data-[state=closed]:sb-fade-out-0 data-[state=open]:sb-fade-in-0",
656
- className
657
- ),
658
- ...props
659
- }
660
- ));
661
- DialogOverlay.displayName = DialogPrimitive.Overlay.displayName;
662
- var DialogContent = React25.forwardRef(({ className, children, ...props }, ref) => /* @__PURE__ */ React25.createElement(DialogPortal, null, /* @__PURE__ */ React25.createElement(DialogOverlay, null), /* @__PURE__ */ React25.createElement(
663
- DialogPrimitive.Content,
664
- {
665
- ref,
666
- className: cn(
667
- "sb-fixed sb-left-[50%] sb-top-[50%] sb-z-50 sb-grid sb-w-full sb-max-w-lg sb-translate-x-[-50%] sb-translate-y-[-50%] sb-gap-4 sb-border sb-bg-background sb-p-6 sb-shadow-lg sb-duration-200 data-[state=open]:sb-animate-in data-[state=closed]:sb-animate-out data-[state=closed]:sb-fade-out-0 data-[state=open]:sb-fade-in-0 data-[state=closed]:sb-zoom-out-95 data-[state=open]:sb-zoom-in-95 data-[state=closed]:sb-slide-out-to-left-1/2 data-[state=closed]:sb-slide-out-to-top-[48%] data-[state=open]:sb-slide-in-from-left-1/2 data-[state=open]:sb-slide-in-from-top-[48%] sm:sb-rounded-lg",
668
- className
669
- ),
670
- ...props
671
- },
672
- children,
673
- /* @__PURE__ */ React25.createElement(DialogPrimitive.Close, { className: "sb-absolute sb-right-4 sb-top-4 sb-rounded-sm sb-opacity-70 sb-ring-offset-background sb-transition-opacity hover:sb-opacity-100 focus:sb-outline-none focus:sb-ring-2 focus:sb-ring-ring focus:sb-ring-offset-2 disabled:sb-pointer-events-none data-[state=open]:sb-bg-accent data-[state=open]:sb-text-muted-foreground" }, /* @__PURE__ */ React25.createElement(X, { className: "sb-h-4 sb-w-4" }), /* @__PURE__ */ React25.createElement("span", { className: "sb-sr-only" }, "Close"))
674
- )));
675
- DialogContent.displayName = DialogPrimitive.Content.displayName;
676
- var DialogHeader = ({
677
- className,
678
- ...props
679
- }) => /* @__PURE__ */ React25.createElement(
680
- "div",
681
- {
682
- className: cn(
683
- "sb-flex sb-flex-col sb-space-y-1.5 sb-text-center sm:sb-text-left",
684
- className
685
- ),
686
- ...props
687
- }
688
- );
689
- DialogHeader.displayName = "DialogHeader";
690
- var DialogTitle = React25.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ React25.createElement(
691
- DialogPrimitive.Title,
692
- {
693
- ref,
694
- className: cn(
695
- "sb-text-lg sb-font-semibold sb-leading-none sb-tracking-tight",
696
- className
697
- ),
698
- ...props
699
- }
700
- ));
701
- DialogTitle.displayName = DialogPrimitive.Title.displayName;
702
- var DialogDescription = React25.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ React25.createElement(
703
- DialogPrimitive.Description,
704
- {
705
- ref,
706
- className: cn("sb-text-sm sb-text-muted-foreground", className),
707
- ...props
708
- }
709
- ));
710
- DialogDescription.displayName = DialogPrimitive.Description.displayName;
711
- var labelVariants = cva(
712
- "sb-text-sm sb-font-medium sb-leading-none peer-disabled:sb-cursor-not-allowed peer-disabled:sb-opacity-70"
713
- );
714
- var Label2 = React25.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ React25.createElement(
715
- LabelPrimitive.Root,
716
- {
717
- ref,
718
- className: cn(labelVariants(), className),
719
- ...props
720
- }
721
- ));
722
- Label2.displayName = LabelPrimitive.Root.displayName;
723
-
724
- // src/components/ui/form.tsx
725
- var Form = FormProvider;
726
- var FormFieldContext = React25.createContext(
727
- {}
728
- );
729
- var FormField = ({
730
- ...props
731
- }) => {
732
- return /* @__PURE__ */ React25.createElement(FormFieldContext.Provider, { value: { name: props.name } }, /* @__PURE__ */ React25.createElement(Controller, { ...props }));
733
- };
734
- var useFormField = () => {
735
- const fieldContext = React25.useContext(FormFieldContext);
736
- const itemContext = React25.useContext(FormItemContext);
737
- const { getFieldState, formState } = useFormContext();
738
- const fieldState = getFieldState(fieldContext.name, formState);
739
- if (!fieldContext) {
740
- throw new Error("useFormField should be used within <FormField>");
741
- }
742
- const { id } = itemContext;
743
- return {
744
- id,
745
- name: fieldContext.name,
746
- formItemId: `${id}-form-item`,
747
- formDescriptionId: `${id}-form-item-description`,
748
- formMessageId: `${id}-form-item-message`,
749
- ...fieldState
750
- };
751
- };
752
- var FormItemContext = React25.createContext(
753
- {}
754
- );
755
- var FormItem = React25.forwardRef(({ className, ...props }, ref) => {
756
- const id = React25.useId();
757
- return /* @__PURE__ */ React25.createElement(FormItemContext.Provider, { value: { id } }, /* @__PURE__ */ React25.createElement("div", { ref, className: cn("sb-space-y-2", className), ...props }));
758
- });
759
- FormItem.displayName = "FormItem";
760
- var FormLabel = React25.forwardRef(({ className, ...props }, ref) => {
761
- const { error, formItemId } = useFormField();
762
- return /* @__PURE__ */ React25.createElement(
763
- Label2,
764
- {
765
- ref,
766
- className: cn(error && "sb-text-destructive", className),
767
- htmlFor: formItemId,
768
- ...props
769
- }
770
- );
771
- });
772
- FormLabel.displayName = "FormLabel";
773
- var FormControl = React25.forwardRef(({ ...props }, ref) => {
774
- const { error, formItemId, formDescriptionId, formMessageId } = useFormField();
775
- return /* @__PURE__ */ React25.createElement(
776
- Slot,
777
- {
778
- ref,
779
- id: formItemId,
780
- "aria-describedby": !error ? `${formDescriptionId}` : `${formDescriptionId} ${formMessageId}`,
781
- "aria-invalid": !!error,
782
- ...props
783
- }
784
- );
785
- });
786
- FormControl.displayName = "FormControl";
787
- var FormDescription = React25.forwardRef(({ className, ...props }, ref) => {
788
- const { formDescriptionId } = useFormField();
789
- return /* @__PURE__ */ React25.createElement(
790
- "p",
791
- {
792
- ref,
793
- id: formDescriptionId,
794
- className: cn("sb-text-[0.8rem] sb-text-muted-foreground", className),
795
- ...props
796
- }
797
- );
798
- });
799
- FormDescription.displayName = "FormDescription";
800
- var FormMessage = React25.forwardRef(({ className, children, ...props }, ref) => {
801
- const { error, formMessageId } = useFormField();
802
- const body = error ? String(error?.message ?? "") : children;
803
- if (!body) {
804
- return null;
805
- }
806
- return /* @__PURE__ */ React25.createElement(
807
- "p",
808
- {
809
- ref,
810
- id: formMessageId,
811
- className: cn("sb-text-[0.8rem] sb-font-medium sb-text-destructive", className),
812
- ...props
813
- },
814
- body
815
- );
816
- });
817
- FormMessage.displayName = "FormMessage";
818
- var Input = React25.forwardRef(
819
- ({ className, type, ...props }, ref) => {
820
- return /* @__PURE__ */ React25.createElement(
821
- "input",
822
- {
823
- type,
824
- className: cn(
825
- "sb-flex sb-h-9 sb-w-full sb-rounded-md sb-border sb-border-input sb-bg-transparent sb-px-3 sb-py-1 sb-text-base sb-shadow-sm sb-transition-colors file:sb-border-0 file:sb-bg-transparent file:sb-text-sm file:sb-font-medium file:sb-text-foreground placeholder:sb-text-muted-foreground focus-visible:sb-outline-none focus-visible:sb-ring-1 focus-visible:sb-ring-ring disabled:sb-cursor-not-allowed disabled:sb-opacity-50 md:sb-text-sm",
826
- className
827
- ),
828
- ref,
829
- ...props
830
- }
831
- );
832
- }
833
- );
834
- Input.displayName = "Input";
835
- var AdvancedInput = React25.forwardRef(
836
- ({ prepend, append, ...props }, ref) => {
837
- return /* @__PURE__ */ React25.createElement("div", { className: "sb-relative" }, /* @__PURE__ */ React25.createElement(Input, { ref, className: "sb-pl-9 sb-pr-7 sb-text-right", ...props }), prepend && /* @__PURE__ */ React25.createElement("div", { className: "sb-absolute sb-font-roboto sb-top-1/2 sb-left-3 sb--translate-y-1/2" }, prepend), append && /* @__PURE__ */ React25.createElement("div", { className: "sb-absolute sb-font-roboto sb-top-1/2 sb-right-3 sb--translate-y-1/2" }, append));
838
- }
839
- );
840
- AdvancedInput.displayName = "AdvancedInput";
841
- var Switch = React25.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ React25.createElement(
842
- SwitchPrimitives.Root,
843
- {
844
- className: cn(
845
- "sb-peer sb-inline-flex sb-h-5 sb-w-9 sb-shrink-0 sb-cursor-pointer sb-items-center sb-rounded-full sb-border-2 sb-border-transparent sb-shadow-sm sb-transition-colors focus-visible:sb-outline-none focus-visible:sb-ring-2 focus-visible:sb-ring-ring focus-visible:sb-ring-offset-2 focus-visible:sb-ring-offset-background disabled:sb-cursor-not-allowed disabled:sb-opacity-50 data-[state=checked]:sb-bg-primary data-[state=unchecked]:sb-bg-input",
846
- className
847
- ),
848
- ...props,
849
- ref
850
- },
851
- /* @__PURE__ */ React25.createElement(
852
- SwitchPrimitives.Thumb,
853
- {
854
- className: cn(
855
- "sb-pointer-events-none sb-block sb-h-4 sb-w-4 sb-rounded-full sb-bg-background sb-shadow-lg sb-ring-0 sb-transition-transform data-[state=checked]:sb-translate-x-4 data-[state=unchecked]:sb-translate-x-0"
856
- )
857
- }
858
- )
859
- ));
860
- Switch.displayName = SwitchPrimitives.Root.displayName;
861
- var LinkTool = ({ editor }) => {
862
- const [open, setOpen] = React25.useState(false);
863
- const { from, to } = editor.state.selection;
864
- const text = editor.state.doc.textBetween(from, to, " ");
865
- const handleSetLink = React25.useCallback(
866
- (url, text2, openInNewTab) => {
867
- editor.chain().focus().extendMarkRange("link").insertContent({
868
- type: "text",
869
- text: text2 || url,
870
- marks: [
871
- {
872
- type: "link",
873
- attrs: {
874
- href: url,
875
- target: openInNewTab ? "_blank" : ""
876
- }
877
- }
878
- ]
879
- }).setLink({ href: url }).run();
880
- editor.commands.enter();
881
- setOpen(false);
882
- },
883
- [editor]
884
- );
885
- return /* @__PURE__ */ React25.createElement(Dialog, { open, onOpenChange: setOpen }, /* @__PURE__ */ React25.createElement(DialogTrigger, { asChild: true }, /* @__PURE__ */ React25.createElement(
886
- ToolbarButton,
887
- {
888
- pressed: editor.isActive("link"),
889
- disabled: editor.isActive("codeBlock")
890
- },
891
- /* @__PURE__ */ React25.createElement(LuLink2, { className: "sb-size-5" })
892
- )), /* @__PURE__ */ React25.createElement(DialogContent, { className: "sb-w-full sb-min-w-80" }, /* @__PURE__ */ React25.createElement(LinkForm, { onSave: handleSetLink, defaultText: text })));
893
- };
894
- var schema = z.object({
895
- url: z.string().min(0),
896
- text: z.string().optional(),
897
- isNewTab: z.boolean().optional()
898
- });
899
- var LinkForm = ({
900
- onSave,
901
- defaultIsNewTab,
902
- defaultUrl,
903
- defaultText
904
- }) => {
905
- const form = useForm({
906
- resolver: zodResolver(schema),
907
- defaultValues: {
908
- url: defaultUrl || "",
909
- text: defaultText || "",
910
- isNewTab: defaultIsNewTab || false
911
- }
912
- });
913
- const handleSubmit = (values) => {
914
- onSave(values.url, values.text, values.isNewTab);
915
- };
916
- return /* @__PURE__ */ React25.createElement(Form, { ...form }, /* @__PURE__ */ React25.createElement("div", { className: "sb-space-y-6" }, /* @__PURE__ */ React25.createElement(
917
- FormField,
918
- {
919
- control: form.control,
920
- name: "url",
921
- render: ({ field }) => /* @__PURE__ */ React25.createElement(FormItem, null, /* @__PURE__ */ React25.createElement(FormLabel, null, "URL"), /* @__PURE__ */ React25.createElement(FormControl, null, /* @__PURE__ */ React25.createElement(Input, { type: "url", ...field, autoFocus: true })), /* @__PURE__ */ React25.createElement(FormMessage, null))
922
- }
923
- ), /* @__PURE__ */ React25.createElement(
924
- FormField,
925
- {
926
- control: form.control,
927
- name: "text",
928
- render: ({ field }) => /* @__PURE__ */ React25.createElement(FormItem, null, /* @__PURE__ */ React25.createElement(FormLabel, null, "Text"), /* @__PURE__ */ React25.createElement(FormControl, null, /* @__PURE__ */ React25.createElement(Input, { ...field })), /* @__PURE__ */ React25.createElement(FormMessage, null))
929
- }
930
- ), /* @__PURE__ */ React25.createElement(
931
- FormField,
932
- {
933
- control: form.control,
934
- name: "isNewTab",
935
- render: ({ field }) => /* @__PURE__ */ React25.createElement(FormItem, null, /* @__PURE__ */ React25.createElement("div", { className: "sb-flex sb-items-center sb-space-x-2" }, /* @__PURE__ */ React25.createElement(FormControl, null, /* @__PURE__ */ React25.createElement(
936
- Switch,
937
- {
938
- checked: field.value,
939
- onCheckedChange: field.onChange
940
- }
941
- )), /* @__PURE__ */ React25.createElement(FormLabel, null, "Open in new tab")), /* @__PURE__ */ React25.createElement(FormMessage, null))
942
- }
943
- ), /* @__PURE__ */ React25.createElement(Button, { type: "button", onClick: form.handleSubmit(handleSubmit) }, "Save")));
944
- };
945
- var actions3 = [
946
- {
947
- value: "orderedList",
948
- label: "Numbered list",
949
- icon: LuListOrdered,
950
- action: (editor) => editor.chain().focus().toggleOrderedList().run(),
951
- isActive: (editor) => editor.isActive("orderedList"),
952
- canExecute: (editor) => editor.can().chain().focus().toggleOrderedList().run()
953
- },
954
- {
955
- value: "bulletList",
956
- label: "Bullet list",
957
- icon: LuList,
958
- action: (editor) => editor.chain().focus().toggleBulletList().run(),
959
- isActive: (editor) => editor.isActive("bulletList"),
960
- canExecute: (editor) => editor.can().chain().focus().toggleBulletList().run()
961
- }
962
- ];
963
- var ListTool = ({ editor }) => {
964
- return /* @__PURE__ */ React25.createElement(ToolbarSection, { editor, actions: actions3, mainActionCount: 2 });
965
- };
966
-
967
- // src/features/rich-text-editor/components/toolbar.tsx
968
- var Toolbar = ({ editor }) => {
969
- return /* @__PURE__ */ React25.createElement("div", { className: "sb-shrink-0 sb-overflow-x-auto sb-border-b sb-border-border sb-p-2" }, /* @__PURE__ */ React25.createElement("div", { className: "sb-flex sb-w-max sb-items-center sb-gap-px" }, /* @__PURE__ */ React25.createElement(ElementTool, { editor }), /* @__PURE__ */ React25.createElement(Separator2, { orientation: "vertical", className: "sb-mx-2 sb-h-7" }), /* @__PURE__ */ React25.createElement(FormatTool, { editor }), /* @__PURE__ */ React25.createElement(Separator2, { orientation: "vertical", className: "sb-mx-2 sb-h-7" }), /* @__PURE__ */ React25.createElement(ColorTool, { editor }), /* @__PURE__ */ React25.createElement(Separator2, { orientation: "vertical", className: "sb-mx-2 sb-h-7" }), /* @__PURE__ */ React25.createElement(ListTool, { editor }), /* @__PURE__ */ React25.createElement(Separator2, { orientation: "vertical", className: "sb-mx-2 sb-h-7" }), /* @__PURE__ */ React25.createElement(LinkTool, { editor }), /* @__PURE__ */ React25.createElement(InsertTool, { editor })));
970
- };
971
- var ToolbarSection = ({
972
- editor,
973
- actions: actions4,
974
- mainActionCount = 0
975
- }) => {
976
- const { mainActions, dropdownActions } = React25.useMemo(() => {
977
- return {
978
- mainActions: actions4.slice(0, mainActionCount),
979
- dropdownActions: actions4.slice(mainActionCount)
980
- };
981
- }, [actions4, mainActionCount]);
982
- const isDropdownActive = React25.useMemo(() => {
983
- return dropdownActions.some((action) => action.isActive(editor));
984
- }, [dropdownActions, editor]);
985
- return /* @__PURE__ */ React25.createElement(React25.Fragment, null, mainActions.map((action) => /* @__PURE__ */ React25.createElement(
986
- ToolbarButton,
987
- {
988
- key: action.label,
989
- onClick: () => action.action(editor),
990
- disabled: !action.canExecute(editor),
991
- pressed: action.isActive(editor)
992
- },
993
- /* @__PURE__ */ React25.createElement(action.icon, { className: "sb-size-5" })
994
- )), dropdownActions.length > 0 && /* @__PURE__ */ React25.createElement(DropdownMenu, null, /* @__PURE__ */ React25.createElement(DropdownMenuTrigger, { asChild: true }, /* @__PURE__ */ React25.createElement(ToolbarButton, { pressed: isDropdownActive }, /* @__PURE__ */ React25.createElement(LuEllipsis, { className: "sb-size-5" }))), /* @__PURE__ */ React25.createElement(DropdownMenuContent, { align: "start" }, dropdownActions.map((action) => /* @__PURE__ */ React25.createElement(
995
- DropdownMenuItem,
996
- {
997
- key: action.label,
998
- className: cn("sb-flex sb-flex-row sb-items-center sb-gap-2", {
999
- "sb-bg-accent": action.isActive(editor)
1000
- }),
1001
- onClick: () => action.action(editor),
1002
- disabled: !action.canExecute(editor)
1003
- },
1004
- /* @__PURE__ */ React25.createElement(action.icon, { className: "sb-size-4" }),
1005
- /* @__PURE__ */ React25.createElement("span", null, action.label)
1006
- )))));
1007
- };
1008
- var ToolbarButton = React25.forwardRef(({ className, ...props }, ref) => {
1009
- return /* @__PURE__ */ React25.createElement(
1010
- Toggle,
1011
- {
1012
- size: "sm",
1013
- className: cn(
1014
- "sb-size-8 sb-p-0 data-[state=on]:sb-bg-accent",
1015
- { "sb-bg-accent": props.pressed },
1016
- className
1017
- ),
1018
- ref,
1019
- ...props
1020
- }
1021
- );
1022
- });
1023
- ToolbarButton.displayName = "ToolbarButton";
1024
-
1025
- // src/features/rich-text-editor/components/rich-text-editor.tsx
1026
- var RichTextEditor = ({
1027
- value,
1028
- onChange,
1029
- className,
1030
- editorClassName,
1031
- editorContentClassName,
1032
- ...props
1033
- }) => {
1034
- const editor = useRichTextEditor({
1035
- value,
1036
- onUpdate: onChange,
1037
- editorClassName: cn("sb-flex-1 sb-px-3 sb-py-1", editorClassName),
1038
- ...props
1039
- });
1040
- if (!editor) {
1041
- return null;
1042
- }
1043
- return /* @__PURE__ */ React25.createElement(
1044
- "div",
1045
- {
1046
- className: cn(
1047
- "sb-flex sb-h-auto sb-min-h-72 sb-w-full sb-flex-col sb-rounded-md sb-border sb-border-input sb-shadow-sm focus-within:sb-border-primary",
1048
- className
1049
- )
1050
- },
1051
- /* @__PURE__ */ React25.createElement(Toolbar, { editor }),
1052
- /* @__PURE__ */ React25.createElement(
1053
- EditorContent,
1054
- {
1055
- editor,
1056
- className: cn(
1057
- "sb-editflow sb-prose sb-flex sb-flex-1",
1058
- editorContentClassName
1059
- )
1060
- }
1061
- )
1062
- );
1063
- };
1064
- function Calendar({
1065
- className,
1066
- classNames,
1067
- showOutsideDays = true,
1068
- ...props
1069
- }) {
1070
- return /* @__PURE__ */ React25.createElement(
1071
- DayPicker,
1072
- {
1073
- showOutsideDays,
1074
- className: cn("sb-p-3 sb-font-roboto", className),
1075
- classNames: {
1076
- months: "sb-flex sb-flex-col sm:sb-flex-row sb-space-y-4 sm:sb-space-x-4 sm:sb-space-y-0",
1077
- month: "sb-space-y-4",
1078
- caption: "sb-flex sb-justify-center sb-pt-1 sb-relative sb-items-center",
1079
- caption_label: "sb-text-sm sb-font-medium",
1080
- nav: "sb-space-x-1 sb-flex sb-items-center",
1081
- nav_button: cn(
1082
- buttonVariants({ variant: "outline" }),
1083
- "sb-h-7 sb-w-7 sb-bg-transparent sb-p-0 sb-opacity-50 hover:sb-opacity-100"
1084
- ),
1085
- nav_button_previous: "sb-absolute sb-left-1",
1086
- nav_button_next: "sb-absolute sb-right-1",
1087
- table: "sb-w-full sb-border-collapse sb-space-y-1",
1088
- head_row: "sb-flex",
1089
- head_cell: "sb-text-muted-foreground sb-rounded-md sb-w-8 sb-font-normal sb-text-[0.8rem]",
1090
- row: "sb-flex sb-w-full sb-mt-2",
1091
- cell: cn(
1092
- "sb-relative sb-p-0 sb-text-center sb-text-sm focus-within:sb-relative focus-within:sb-z-20 [&:has([aria-selected])]:sb-bg-accent [&:has([aria-selected].day-outside)]:sb-bg-accent/50 [&:has([aria-selected].day-range-end)]:sb-rounded-r-md",
1093
- props.mode === "range" ? "[&:has(>.day-range-end)]:sb-rounded-r-md [&:has(>.day-range-start)]:sb-rounded-l-md first:[&:has([aria-selected])]:sb-rounded-l-md last:[&:has([aria-selected])]:sb-rounded-r-md" : "[&:has([aria-selected])]:sb-rounded-md"
1094
- ),
1095
- day: cn(
1096
- buttonVariants({ variant: "ghost" }),
1097
- "sb-h-8 sb-w-8 sb-p-0 sb-font-normal aria-selected:sb-opacity-100"
1098
- ),
1099
- day_range_start: "day-range-start",
1100
- day_range_end: "day-range-end",
1101
- day_selected: "sb-bg-primary sb-text-primary-foreground hover:sb-bg-primary hover:sb-text-primary-foreground focus:sb-bg-primary focus:sb-text-primary-foreground",
1102
- day_today: "sb-bg-accent sb-text-accent-foreground",
1103
- day_outside: "day-outside sb-text-muted-foreground sb-opacity-50 aria-selected:sb-bg-accent/50 aria-selected:sb-text-muted-foreground aria-selected:sb-opacity-30",
1104
- day_disabled: "sb-text-muted-foreground sb-opacity-50",
1105
- day_range_middle: "aria-selected:sb-bg-accent aria-selected:sb-text-accent-foreground",
1106
- day_hidden: "invisible",
1107
- ...classNames
1108
- },
1109
- components: {
1110
- IconLeft: () => /* @__PURE__ */ React25.createElement(ChevronLeftIcon, { className: "sb-h-4 sb-w-4" }),
1111
- IconRight: () => /* @__PURE__ */ React25.createElement(ChevronRightIcon, { className: "sb-h-4 sb-w-4" })
1112
- },
1113
- ...props
1114
- }
1115
- );
1116
- }
1117
- Calendar.displayName = "Calendar";
1118
- var ColorPicker = (props) => {
1119
- const { color, onColorChange, className } = props;
1120
- const colors = props.colors ?? [
1121
- "#000000",
1122
- "#ffffff",
1123
- "#0f172a",
1124
- "#F1F5F9",
1125
- "#64748B",
1126
- "#E6007E",
1127
- "#F8FAFC",
1128
- "#009DD1",
1129
- "#FF0000"
1130
- ];
1131
- return /* @__PURE__ */ React25.createElement(Popover, null, /* @__PURE__ */ React25.createElement(PopoverTrigger, { asChild: true }, /* @__PURE__ */ React25.createElement(
1132
- Button,
1133
- {
1134
- variant: "outline",
1135
- size: "sm",
1136
- className: cn(
1137
- "sb-justify-start sb-text-left sb-font-normal sb-normal-case sb-w-full",
1138
- !color && "sb-text-muted-foreground",
1139
- className
1140
- )
1141
- },
1142
- /* @__PURE__ */ React25.createElement("div", { className: "sb-w-full sb-flex sb-items-center sb-gap-2" }, color ? /* @__PURE__ */ React25.createElement(
1143
- "div",
1144
- {
1145
- className: "sb-h-4 sb-w-4 sb-rounded !sb-bg-center !sb-bg-cover sb-transition-all sb-border",
1146
- style: { background: color }
1147
- }
1148
- ) : /* @__PURE__ */ React25.createElement(PaintbrushIcon, { className: "sb-h-4 sb-w-4" }), /* @__PURE__ */ React25.createElement("div", { className: "sb-truncate sb-flex-1" }, color ? color : "Kies een kleur"))
1149
- )), /* @__PURE__ */ React25.createElement(PopoverContent, { className: "sb-w-64 sb-p-4 sb-flex sb-flex-wrap sb-gap-1" }, colors.map((s) => /* @__PURE__ */ React25.createElement(
1150
- "div",
1151
- {
1152
- key: s,
1153
- style: { background: s },
1154
- className: "sb-rounded-md sb-h-6 sb-w-6 sb-cursor-pointer active:sb-scale-105 sb-border",
1155
- onClick: () => onColorChange(s)
1156
- }
1157
- ))));
1158
- };
1159
- var MediaInput = (props) => {
1160
- const { onFilesChange, limit = 32, multiple = false, onError } = props;
1161
- const id = React25.useId();
1162
- const [queue, setQueue] = React25.useState([]);
1163
- const [sources, setSources] = React25.useState(props.files ?? []);
1164
- const maxConcurrentUploads = 3;
1165
- const uploadingCountRef = React25.useRef(0);
1166
- const handleFilesAdd = async (e) => {
1167
- const files = e.target.files;
1168
- if (!files || files.length === 0) {
1169
- return;
1170
- }
1171
- if (files.length + sources.length > (multiple ? limit : 1)) {
1172
- onError?.(
1173
- new MediaInputError(
1174
- `Maximaal ${limit} bestanden.`,
1175
- `Je probeerde nu ${files.length + sources.length} bestanden toe te voegen, maar je mag er maximaal ${limit} toevoegen.`
1176
- )
1177
- );
1178
- return;
1179
- }
1180
- const queue2 = Array.from(files);
1181
- setQueue(queue2);
1182
- for (const file of queue2) {
1183
- try {
1184
- while (uploadingCountRef.current >= maxConcurrentUploads && uploadingCountRef.current > 0) {
1185
- await new Promise((resolve) => setTimeout(resolve, 300));
1186
- }
1187
- uploadingCountRef.current++;
1188
- const formData = new FormData();
1189
- formData.append("file", file);
1190
- const res = await fetch("/api/simple-builder/file/upload", {
1191
- method: "POST",
1192
- body: formData
1193
- });
1194
- if (res === void 0 || !res.ok) {
1195
- onError?.(
1196
- new MediaInputError(
1197
- "Bestand uploaden misulukt",
1198
- `Bestand ${file.name} kon niet worden ge\xFCpload.`
1199
- )
1200
- );
1201
- continue;
1202
- }
1203
- const { data: url } = await res.json();
1204
- if (!url) {
1205
- onError?.(
1206
- new MediaInputError(
1207
- "Bestand uploaden misulukt",
1208
- `De URL van bestand ${file.name} kon niet worden opgehaald.`
1209
- )
1210
- );
1211
- continue;
1212
- }
1213
- setSources((prev) => [...prev, url]);
1214
- onFilesChange?.([...sources, url]);
1215
- } catch (e2) {
1216
- onError?.(
1217
- new MediaInputError(
1218
- "Bestand uploaden misulukt",
1219
- `Bestand ${file.name} kon niet worden ge\xFCpload.`
1220
- )
1221
- );
1222
- } finally {
1223
- setQueue((prev) => prev.filter((f) => f !== file));
1224
- uploadingCountRef.current--;
1225
- }
1226
- }
1227
- };
1228
- const handleSourceDelete = async (src) => {
1229
- setSources((prev) => prev.filter((s) => s !== src));
1230
- onFilesChange?.(sources.filter((s) => s !== src));
1231
- await fetch("/api/uploadthing/delete", {
1232
- method: "POST",
1233
- body: JSON.stringify({ src })
1234
- });
1235
- };
1236
- return /* @__PURE__ */ React25.createElement("div", { className: cn("flex flex-wrap gap-4", props.className) }, sources.map((src) => /* @__PURE__ */ React25.createElement(MediaInputItem, { key: src, className: cn("group", props.itemClassName) }, /* @__PURE__ */ React25.createElement(
1237
- Image,
1238
- {
1239
- src,
1240
- alt: "",
1241
- fill: true,
1242
- className: "sb-absolute sb-inset-0 sb-object-cover sb-pointer-events-none"
1243
- }
1244
- ), /* @__PURE__ */ React25.createElement("div", { className: "sb-absolute sb-right-1 sb-top-1 sb-z-30 sb-flex sb-items-center sb-justify-end sb-gap-3 sb-opacity-0 sb-transition-opacity group-hover:sb-opacity-100" }, /* @__PURE__ */ React25.createElement(
1245
- "button",
1246
- {
1247
- className: "sb-flex sb-h-8 sb-w-8 sb-items-center sb-justify-center sb-rounded-full sb-border sb-bg-secondary sb-text-secondary-foreground sb-opacity-90 sb-shadow sb-transition-opacity hover:sb-opacity-100",
1248
- onClick: () => handleSourceDelete(src)
1249
- },
1250
- /* @__PURE__ */ React25.createElement(Trash2Icon, { className: "sb-h-4 sb-w-4" })
1251
- )))), queue.map((_, i) => /* @__PURE__ */ React25.createElement(
1252
- MediaInputItem,
1253
- {
1254
- key: i,
1255
- className: cn(
1256
- "sb-flex sb-h-28 sb-w-28 sb-items-center sb-justify-center",
1257
- props.itemClassName
1258
- )
1259
- },
1260
- /* @__PURE__ */ React25.createElement(Loader2Icon, { className: "sb-h-6 sb-w-6 sb-animate-spin" })
1261
- )), multiple || !multiple && !sources.length && !queue.length ? /* @__PURE__ */ React25.createElement(
1262
- "label",
1263
- {
1264
- htmlFor: id,
1265
- className: cn(
1266
- "sb-flex sb-h-28 sb-w-28 sb-cursor-pointer sb-items-center sb-justify-center sb-rounded-lg sb-border",
1267
- props.itemClassName
1268
- )
1269
- },
1270
- /* @__PURE__ */ React25.createElement(PlusIcon, { className: "sb-h-6 sb-w-6" }),
1271
- /* @__PURE__ */ React25.createElement(
1272
- "input",
1273
- {
1274
- id,
1275
- type: "file",
1276
- onChange: handleFilesAdd,
1277
- multiple,
1278
- accept: ".png,.jpg,.jpeg,.webp,.gif,.svg",
1279
- className: "sb-hidden"
1280
- }
1281
- )
1282
- ) : null);
1283
- };
1284
- var MediaInputItem = (props) => {
1285
- return /* @__PURE__ */ React25.createElement(
1286
- "div",
1287
- {
1288
- className: cn(
1289
- "sb-relative sb-h-28 sb-w-28 sb-overflow-hidden sb-rounded-lg sb-border",
1290
- props.className
1291
- )
1292
- },
1293
- props.children
1294
- );
1295
- };
1296
- var MediaInputError = class extends Error {
1297
- title;
1298
- description;
1299
- constructor(message, description) {
1300
- super(message);
1301
- this.title = message;
1302
- this.description = description;
1303
- }
1304
- };
1305
- var Select = SelectPrimitive.Root;
1306
- var SelectValue = SelectPrimitive.Value;
1307
- var SelectTrigger = React25.forwardRef(({ className, children, ...props }, ref) => /* @__PURE__ */ React25.createElement(
1308
- SelectPrimitive.Trigger,
1309
- {
1310
- ref,
1311
- className: cn(
1312
- "sb-flex sb-h-10 sb-w-full sb-items-center sb-justify-between sb-rounded-md sb-border sb-border-input sb-bg-background sb-px-3 sb-py-2 sb-text-sm sb-ring-offset-background placeholder:sb-text-muted-foreground focus:sb-outline-none focus:sb-ring-2 focus:sb-ring-ring focus:sb-ring-offset-2 disabled:sb-cursor-not-allowed disabled:sb-opacity-50 [&>span]:sb-line-clamp-1",
1313
- className
1314
- ),
1315
- ...props
1316
- },
1317
- children,
1318
- /* @__PURE__ */ React25.createElement(SelectPrimitive.Icon, { asChild: true }, /* @__PURE__ */ React25.createElement(ChevronDown, { className: "sb-h-4 sb-w-4 sb-opacity-50" }))
1319
- ));
1320
- SelectTrigger.displayName = SelectPrimitive.Trigger.displayName;
1321
- var SelectScrollUpButton = React25.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ React25.createElement(
1322
- SelectPrimitive.ScrollUpButton,
1323
- {
1324
- ref,
1325
- className: cn(
1326
- "sb-flex sb-cursor-default sb-items-center sb-justify-center sb-py-1",
1327
- className
1328
- ),
1329
- ...props
1330
- },
1331
- /* @__PURE__ */ React25.createElement(ChevronUp, { className: "sb-h-4 sb-w-4" })
1332
- ));
1333
- SelectScrollUpButton.displayName = SelectPrimitive.ScrollUpButton.displayName;
1334
- var SelectScrollDownButton = React25.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ React25.createElement(
1335
- SelectPrimitive.ScrollDownButton,
1336
- {
1337
- ref,
1338
- className: cn(
1339
- "sb-flex sb-cursor-default sb-items-center sb-justify-center sb-py-1",
1340
- className
1341
- ),
1342
- ...props
1343
- },
1344
- /* @__PURE__ */ React25.createElement(ChevronDown, { className: "sb-h-4 sb-w-4" })
1345
- ));
1346
- SelectScrollDownButton.displayName = SelectPrimitive.ScrollDownButton.displayName;
1347
- var SelectContent = React25.forwardRef(({ className, children, position = "popper", ...props }, ref) => /* @__PURE__ */ React25.createElement(SelectPrimitive.Portal, null, /* @__PURE__ */ React25.createElement(
1348
- SelectPrimitive.Content,
1349
- {
1350
- ref,
1351
- className: cn(
1352
- "sb-relative sb-z-50 sb-max-h-96 sb-min-w-[8rem] sb-overflow-hidden sb-rounded-md sb-border sb-bg-popover sb-text-popover-foreground sb-shadow-md data-[state=open]:sb-animate-in data-[state=closed]:sb-animate-out data-[state=closed]:sb-fade-out-0 data-[state=open]:sb-fade-in-0 data-[state=closed]:sb-zoom-out-95 data-[state=open]:sb-zoom-in-95 data-[side=bottom]:sb-slide-in-from-top-2 data-[side=left]:sb-slide-in-from-right-2 data-[side=right]:sb-slide-in-from-left-2 data-[side=top]:sb-slide-in-from-bottom-2",
1353
- position === "popper" && "data-[side=bottom]:sb-translate-y-1 data-[side=left]:sb--translate-x-1 data-[side=right]:sb-translate-x-1 data-[side=top]:sb--translate-y-1",
1354
- className
1355
- ),
1356
- position,
1357
- ...props
1358
- },
1359
- /* @__PURE__ */ React25.createElement(SelectScrollUpButton, null),
1360
- /* @__PURE__ */ React25.createElement(
1361
- SelectPrimitive.Viewport,
1362
- {
1363
- className: cn(
1364
- "sb-p-1",
1365
- position === "popper" && "sb-h-[var(--radix-select-trigger-height)] sb-w-full sb-min-w-[var(--radix-select-trigger-width)]"
1366
- )
1367
- },
1368
- children
1369
- ),
1370
- /* @__PURE__ */ React25.createElement(SelectScrollDownButton, null)
1371
- )));
1372
- SelectContent.displayName = SelectPrimitive.Content.displayName;
1373
- var SelectLabel = React25.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ React25.createElement(
1374
- SelectPrimitive.Label,
1375
- {
1376
- ref,
1377
- className: cn(
1378
- "sb-py-1.5 sb-pl-8 sb-pr-2 sb-text-sm sb-font-semibold",
1379
- className
1380
- ),
1381
- ...props
1382
- }
1383
- ));
1384
- SelectLabel.displayName = SelectPrimitive.Label.displayName;
1385
- var SelectItem = React25.forwardRef(({ className, children, ...props }, ref) => /* @__PURE__ */ React25.createElement(
1386
- SelectPrimitive.Item,
1387
- {
1388
- ref,
1389
- className: cn(
1390
- "sb-relative sb-flex sb-w-full sb-cursor-default sb-select-none sb-items-center sb-rounded-sm sb-py-1.5 sb-pl-8 sb-pr-2 sb-text-sm sb-outline-none focus:sb-bg-accent focus:sb-text-accent-foreground data-[disabled]:sb-pointer-events-none data-[disabled]:sb-opacity-50",
1391
- className
1392
- ),
1393
- ...props
1394
- },
1395
- /* @__PURE__ */ React25.createElement("span", { className: "sb-absolute sb-left-2 sb-flex sb-h-3.5 sb-w-3.5 sb-items-center sb-justify-center" }, /* @__PURE__ */ React25.createElement(SelectPrimitive.ItemIndicator, null, /* @__PURE__ */ React25.createElement(Check, { className: "sb-h-4 sb-w-4" }))),
1396
- /* @__PURE__ */ React25.createElement(SelectPrimitive.ItemText, null, children)
1397
- ));
1398
- SelectItem.displayName = SelectPrimitive.Item.displayName;
1399
- var SelectSeparator = React25.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ React25.createElement(
1400
- SelectPrimitive.Separator,
1401
- {
1402
- ref,
1403
- className: cn("sb--mx-1 sb-my-1 sb-h-px sb-bg-muted", className),
1404
- ...props
1405
- }
1406
- ));
1407
- SelectSeparator.displayName = SelectPrimitive.Separator.displayName;
1408
- var Textarea = React25.forwardRef(
1409
- ({ className, ...props }, ref) => {
1410
- return /* @__PURE__ */ React25.createElement(
1411
- "textarea",
1412
- {
1413
- className: cn(
1414
- "sb-flex sb-min-h-[60px] sb-font-roboto sb-w-full sb-rounded-md sb-border sb-border-input sb-bg-transparent sb-px-3 sb-py-2 sb-text-sm sb-shadow-sm placeholder:sb-text-muted-foreground focus-visible:sb-outline-none focus-visible:sb-ring-1 focus-visible:sb-ring-ring disabled:sb-cursor-not-allowed disabled:sb-opacity-50",
1415
- className
1416
- ),
1417
- ref,
1418
- ...props
1419
- }
1420
- );
1421
- }
1422
- );
1423
- Textarea.displayName = "Textarea";
1424
-
1425
- // src/components/container-item-form.tsx
1426
- var ContainerItemForm = (props) => {
1427
- const { item } = props;
1428
- const { patchItem } = useBuilder();
1429
- const component = builder.getComponent(item.component);
1430
- if (!component) {
1431
- throw new Error(
1432
- `[simple-builder]: Component with id ${item.component} not found in container item form component`
1433
- );
1434
- }
1435
- const form = useForm({
1436
- defaultValues: (component.inputs || []).reduce(
1437
- (acc, input) => ({
1438
- ...acc,
1439
- [input.name]: item?.props?.[input.name] ?? input.defaultValue
1440
- }),
1441
- {}
1442
- )
1443
- });
1444
- const onSubmit = (values) => {
1445
- patchItem(item.id, {
1446
- props: values
1447
- });
1448
- };
1449
- React25.useEffect(() => {
1450
- const subscription = form.watch(() => form.handleSubmit(onSubmit)());
1451
- return () => subscription.unsubscribe();
1452
- }, [form.watch, form.handleSubmit]);
1453
- return /* @__PURE__ */ React25.createElement(Form, { ...form }, /* @__PURE__ */ React25.createElement("form", { onSubmit: form.handleSubmit(onSubmit) }, /* @__PURE__ */ React25.createElement("div", { className: "sb-space-y-4 sb-p-4" }, (component.inputs || []).map((input) => /* @__PURE__ */ React25.createElement(
1454
- RenderFormField,
1455
- {
1456
- key: input.name,
1457
- type: input.type,
1458
- input,
1459
- form
1460
- }
1461
- )))));
1462
- };
1463
- var RenderFormField = (props) => {
1464
- const { type, input, form } = props;
1465
- const fieldArray = useFieldArray({
1466
- control: form.control,
1467
- name: input.name
1468
- });
1469
- if (input.multiple) {
1470
- return /* @__PURE__ */ React25.createElement("fieldset", { className: "sb-space-y-2" }, /* @__PURE__ */ React25.createElement(FormLabel, null, input.friendlyName || input.name), /* @__PURE__ */ React25.createElement("div", { className: "sb-space-y-4" }, fieldArray.fields.map(
1471
- (field, i) => type !== "grouped" ? /* @__PURE__ */ React25.createElement(
1472
- FormField,
1473
- {
1474
- key: field.id,
1475
- control: form.control,
1476
- name: `${input.name}.${i}`,
1477
- render: ({ field: field2 }) => /* @__PURE__ */ React25.createElement("div", { className: "sb-flex sb-items-center sb-gap-3" }, /* @__PURE__ */ React25.createElement(RenderInput, { field: field2, type: input.type }), /* @__PURE__ */ React25.createElement("button", { type: "button", onClick: () => fieldArray.remove(i) }, /* @__PURE__ */ React25.createElement(XIcon, { className: "sb-h-4 sb-w-4" })))
1478
- }
1479
- ) : /* @__PURE__ */ React25.createElement("div", { className: "sb-flex sb-items-center sb-relative" }, /* @__PURE__ */ React25.createElement(
1480
- RenderFormField,
1481
- {
1482
- key: field.id,
1483
- form,
1484
- type,
1485
- input: {
1486
- ...input,
1487
- name: `${input.name}.${i}`,
1488
- multiple: false,
1489
- friendlyName: ""
1490
- }
1491
- }
1492
- ), /* @__PURE__ */ React25.createElement(
1493
- "button",
1494
- {
1495
- type: "button",
1496
- onClick: () => fieldArray.remove(i),
1497
- className: "sb-absolute sb-top-2 sb-right-2 sb-text-foreground/70 hover:sb-text-foreground"
1498
- },
1499
- /* @__PURE__ */ React25.createElement(XIcon, { className: "sb-h-4 sb-w-4" })
1500
- ))
1501
- ), /* @__PURE__ */ React25.createElement(
1502
- Button,
1503
- {
1504
- type: "button",
1505
- variant: "outline",
1506
- size: "sm",
1507
- className: cn(
1508
- "sb-w-[89%] sb-border-2 sb-border-dashed sb-text-muted-foreground",
1509
- type === "grouped" && "sb-w-full"
1510
- ),
1511
- onClick: () => fieldArray.append(void 0)
1512
- },
1513
- /* @__PURE__ */ React25.createElement(PlusCircleIcon, { className: "sb-h-4 sb-w-4" })
1514
- )));
1515
- }
1516
- switch (type) {
1517
- case "string":
1518
- case "number":
1519
- case "longText":
1520
- case "color":
1521
- case "date":
1522
- case "file":
1523
- return /* @__PURE__ */ React25.createElement(
1524
- FormField,
1525
- {
1526
- key: input.name,
1527
- control: form.control,
1528
- name: input.name,
1529
- render: ({ field }) => /* @__PURE__ */ React25.createElement(FormItem, null, /* @__PURE__ */ React25.createElement(FormLabel, null, input.friendlyName || input.name), /* @__PURE__ */ React25.createElement(FormControl, null, /* @__PURE__ */ React25.createElement(RenderInput, { type, field, options: input?.enum })), input.helperText && /* @__PURE__ */ React25.createElement(FormDescription, null, input.helperText), /* @__PURE__ */ React25.createElement(FormMessage, null))
1530
- }
1531
- );
1532
- case "richText":
1533
- return /* @__PURE__ */ React25.createElement(Dialog, null, /* @__PURE__ */ React25.createElement("div", { className: "sb-space-y-2" }, /* @__PURE__ */ React25.createElement(FormLabel, null, input.friendlyName || input.name), /* @__PURE__ */ React25.createElement(DialogTrigger, { asChild: true }, /* @__PURE__ */ React25.createElement(Button, { variant: "outline", className: "sb-w-full" }, input.friendlyName || input.name, " bewerken"))), /* @__PURE__ */ React25.createElement(DialogContent, { className: "sb-max-w-3xl sb-p-0" }, /* @__PURE__ */ React25.createElement("div", { className: "sb-flex sb-h-full sb-max-h-svh sb-w-full sb-flex-col sm:sb-max-h-[90svh]" }, /* @__PURE__ */ React25.createElement(DialogHeader, { className: "sb-flex-none sb-border-b sb-p-6" }, /* @__PURE__ */ React25.createElement(DialogTitle, null, input.friendlyName || input.name, " editor")), /* @__PURE__ */ React25.createElement("div", { className: "sb-flex-1 sb-overflow-y-auto" }, /* @__PURE__ */ React25.createElement(
1534
- FormField,
1535
- {
1536
- key: input.name,
1537
- control: form.control,
1538
- name: input.name,
1539
- render: ({ field }) => /* @__PURE__ */ React25.createElement(FormItem, null, /* @__PURE__ */ React25.createElement(FormControl, null, /* @__PURE__ */ React25.createElement(RenderInput, { type, field })), input.helperText && /* @__PURE__ */ React25.createElement(FormDescription, null, input.helperText), /* @__PURE__ */ React25.createElement(FormMessage, null))
1540
- }
1541
- )))));
1542
- case "boolean":
1543
- return /* @__PURE__ */ React25.createElement(
1544
- FormField,
1545
- {
1546
- key: input.name,
1547
- control: form.control,
1548
- name: input.name,
1549
- render: ({ field }) => /* @__PURE__ */ React25.createElement(FormItem, { className: "sb-flex sb-flex-row sb-items-center sb-justify-between sb-space-y-0" }, /* @__PURE__ */ React25.createElement(FormLabel, null, input.friendlyName || input.name), /* @__PURE__ */ React25.createElement(FormControl, null, /* @__PURE__ */ React25.createElement(RenderInput, { type, field })), input.helperText && /* @__PURE__ */ React25.createElement(FormDescription, null, input.helperText), /* @__PURE__ */ React25.createElement(FormMessage, null))
1550
- }
1551
- );
1552
- case "grouped":
1553
- return /* @__PURE__ */ React25.createElement("div", { className: "sb-space-y-2 sb-w-full" }, input.friendlyName !== "" && /* @__PURE__ */ React25.createElement(FormLabel, null, input.friendlyName || input.name), /* @__PURE__ */ React25.createElement("div", { className: "sb-space-y-2 sb-p-3 sb-w-full sb-border sb-rounded-lg" }, input.inputs.map((sub) => /* @__PURE__ */ React25.createElement(
1554
- RenderFormField,
1555
- {
1556
- key: `${input.name}.${sub.name}`,
1557
- type: sub.type,
1558
- input: {
1559
- ...sub,
1560
- name: `${input.name}.${sub.name}`
1561
- },
1562
- form
1563
- }
1564
- ))));
1565
- default:
1566
- throw new Error(
1567
- `[simple-builder]: Input type "${props.type}" not supported in render form field.`
1568
- );
1569
- }
1570
- };
1571
- var RenderInput = (props) => {
1572
- const { type, options, field } = props;
1573
- switch (type) {
1574
- case "string":
1575
- if (!options)
1576
- return /* @__PURE__ */ React25.createElement(Input, { ...field });
1577
- return /* @__PURE__ */ React25.createElement(Select, { onValueChange: field.onChange, defaultValue: field.value }, /* @__PURE__ */ React25.createElement(SelectTrigger, null, /* @__PURE__ */ React25.createElement(SelectValue, null)), /* @__PURE__ */ React25.createElement(SelectContent, null, options.map((option) => /* @__PURE__ */ React25.createElement(SelectItem, { key: option, value: option }, option))));
1578
- case "longText":
1579
- return /* @__PURE__ */ React25.createElement(Textarea, { ...field });
1580
- case "richText":
1581
- return /* @__PURE__ */ React25.createElement(RichTextEditor, { ...field });
1582
- case "number":
1583
- return /* @__PURE__ */ React25.createElement(Input, { type: "number", ...field });
1584
- case "color":
1585
- return /* @__PURE__ */ React25.createElement(ColorPicker, { color: field.value, onColorChange: field.onChange });
1586
- case "date":
1587
- return /* @__PURE__ */ React25.createElement(Popover, null, /* @__PURE__ */ React25.createElement(PopoverTrigger, { asChild: true }, /* @__PURE__ */ React25.createElement(
1588
- Button,
1589
- {
1590
- variant: "outline",
1591
- size: "sm",
1592
- className: cn(
1593
- "sb-w-full sb-flex sb-justify-start sb-text-left sb-font-normal",
1594
- !field.value && "sb-text-muted-foreground"
1595
- )
1596
- },
1597
- /* @__PURE__ */ React25.createElement(CalendarIcon, { className: "sb-mr-2 sb-h-4 sb-w-4" }),
1598
- field.value && !Array.isArray(field.value) ? format(field.value, "PPP") : /* @__PURE__ */ React25.createElement("span", null, "Pick a date")
1599
- )), /* @__PURE__ */ React25.createElement(PopoverContent, { className: "sb-w-auto sb-p-0", align: "start" }, /* @__PURE__ */ React25.createElement(
1600
- Calendar,
1601
- {
1602
- mode: "single",
1603
- selected: field.value,
1604
- onSelect: field.onChange,
1605
- initialFocus: true
1606
- }
1607
- )));
1608
- case "boolean":
1609
- return /* @__PURE__ */ React25.createElement(Switch, { checked: field.value, onCheckedChange: field.onChange });
1610
- case "file":
1611
- return /* @__PURE__ */ React25.createElement(
1612
- MediaInput,
1613
- {
1614
- className: "sb-grid sb-grid-cols-2 sb-gap-1",
1615
- itemClassName: "sb-aspect-video sb-h-auto sb-w-full",
1616
- multiple: false,
1617
- files: field.value ? [field.value] : [],
1618
- onFilesChange: (files) => field.onChange(files[0]),
1619
- onError: (e) => console.error(
1620
- "[media-input]: Title: " + e?.title,
1621
- "media-input: Error: " + e?.description
1622
- )
1623
- }
1624
- );
1625
- default:
1626
- throw new Error(
1627
- `[simple-builder]: Input type "${props.type}" not supported in render input.`
1628
- );
1629
- }
1630
- };
1631
- var Tabs = TabsPrimitive.Root;
1632
- var tabsListVariants = tv({
1633
- variants: {
1634
- variant: {
1635
- contained: "sb-inline-flex sb-h-10 sb-items-center sb-justify-center sb-rounded-md sb-bg-muted sb-p-1 sb-text-muted-foreground",
1636
- text: "sb-flex sb-items-center sb-border-b sb-px-4 sb-space-x-6"
1637
- }
1638
- },
1639
- defaultVariants: {
1640
- variant: "contained"
1641
- }
1642
- });
1643
- var TabsList = React25.forwardRef(({ variant, className, ...props }, ref) => /* @__PURE__ */ React25.createElement(
1644
- TabsPrimitive.List,
1645
- {
1646
- ref,
1647
- className: tabsListVariants({ variant, className }),
1648
- ...props
1649
- }
1650
- ));
1651
- TabsList.displayName = TabsPrimitive.List.displayName;
1652
- var tabsTriggerVariants = tv({
1653
- variants: {
1654
- variant: {
1655
- contained: "sb-inline-flex sb-items-center sb-justify-center sb-whitespace-nowrap sb-rounded-sm sb-px-3 sb-py-1.5 sb-text-sm sb-font-medium sb-ring-offset-background sb-transition-all focus-visible:sb-outline-none focus-visible:sb-ring-2 focus-visible:sb-ring-ring focus-visible:sb-ring-offset-2 disabled:sb-pointer-events-none disabled:sb-opacity-50 data-[state=active]:sb-bg-background data-[state=active]:sb-text-foreground data-[state=active]:sb-shadow-sm",
1656
- text: "sb-inline-flex sb-font-roboto sb-items-center sb-justify-center sb-whitespace-nowrap sb-py-3 sb-text-sm sb-font-medium sb-transition-all focus-visible:sb-outline-none disabled:sb-pointer-events-none disabled:sb-opacity-50 data-[state=active]:sb-border-black sb-border-b-2 sb-border-transparent data-[state=active]:sb-text-foreground sb-text-muted-foreground"
1657
- }
1658
- },
1659
- defaultVariants: {
1660
- variant: "contained"
1661
- }
1662
- });
1663
- var TabsTrigger = React25.forwardRef(({ variant, className, ...props }, ref) => /* @__PURE__ */ React25.createElement(
1664
- TabsPrimitive.Trigger,
1665
- {
1666
- ref,
1667
- className: tabsTriggerVariants({ variant, className }),
1668
- ...props
1669
- }
1670
- ));
1671
- TabsTrigger.displayName = TabsPrimitive.Trigger.displayName;
1672
- var TabsContent = React25.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ React25.createElement(
1673
- TabsPrimitive.Content,
1674
- {
1675
- ref,
1676
- className: cn(
1677
- "sb-ring-offset-background sb-font-roboto focus-visible:sb-outline-none focus-visible:sb-ring-2 focus-visible:sb-ring-ring focus-visible:sb-ring-offset-2",
1678
- className
1679
- ),
1680
- ...props
1681
- }
1682
- ));
1683
- TabsContent.displayName = TabsPrimitive.Content.displayName;
1684
-
1685
- // src/components/ui/background-picker.tsx
1686
- var BackgroundPicker = (props) => {
1687
- const { background, onBackgroundChange, className } = props;
1688
- const solids = props.solids ?? [
1689
- "#000000",
1690
- "#ffffff",
1691
- "#0f172a",
1692
- "#F1F5F9",
1693
- "#64748B",
1694
- "#E6007E",
1695
- "#F8FAFC",
1696
- "#009DD1",
1697
- "#FF0000"
1698
- ];
1699
- const gradients = props.gradients ?? [
1700
- "linear-gradient(to top left,#accbee,#e7f0fd)",
1701
- "linear-gradient(to top left,#d5d4d0,#d5d4d0,#eeeeec)"
1702
- ];
1703
- const images = props.images ?? [
1704
- "url(https://images.unsplash.com/photo-1688822863426-8c5f9b257090?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=2532&q=90)",
1705
- "url(https://images.unsplash.com/photo-1691225850735-6e4e51834cad?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=2532&q=90)"
1706
- ];
1707
- const defaultTab = React25.useMemo(() => {
1708
- if (background.includes("url"))
1709
- return "image";
1710
- if (background.includes("gradient"))
1711
- return "gradient";
1712
- return "solid";
1713
- }, [background]);
1714
- return /* @__PURE__ */ React25.createElement(Popover, null, /* @__PURE__ */ React25.createElement(PopoverTrigger, { asChild: true }, /* @__PURE__ */ React25.createElement(
1715
- Button,
1716
- {
1717
- variant: "outline",
1718
- size: "sm",
1719
- className: cn(
1720
- "sb-justify-start sb-text-left sb-font-normal sb-normal-case sb-w-full",
1721
- !background && "sb-text-muted-foreground",
1722
- className
1723
- )
1724
- },
1725
- /* @__PURE__ */ React25.createElement("div", { className: "sb-w-full sb-flex sb-items-center sb-gap-2" }, background ? /* @__PURE__ */ React25.createElement(
1726
- "div",
1727
- {
1728
- className: "sb-h-4 sb-w-4 sb-rounded !sb-bg-center !sb-bg-cover sb-transition-all sb-border",
1729
- style: { background }
1730
- }
1731
- ) : /* @__PURE__ */ React25.createElement(PaintbrushIcon, { className: "sb-h-4 sb-w-4" }), /* @__PURE__ */ React25.createElement("div", { className: "sb-truncate sb-flex-1" }, background ? background : "Kies een achtergrond"))
1732
- )), /* @__PURE__ */ React25.createElement(PopoverContent, { className: "sb-w-64 sb-p-0" }, /* @__PURE__ */ React25.createElement(Tabs, { defaultValue: defaultTab }, /* @__PURE__ */ React25.createElement(TabsList, { className: "sb-w-full" }, /* @__PURE__ */ React25.createElement(TabsTrigger, { className: "sb-flex-1", value: "solid" }, "Solid"), /* @__PURE__ */ React25.createElement(TabsTrigger, { className: "sb-flex-1", value: "gradient" }, "Gradient"), /* @__PURE__ */ React25.createElement(TabsTrigger, { className: "sb-flex-1", value: "image" }, "Image")), /* @__PURE__ */ React25.createElement(
1733
- TabsContent,
1734
- {
1735
- value: "solid",
1736
- className: "data-[state=active]:sb-flex sb-flex-wrap sb-gap-1 sb-p-4"
1737
- },
1738
- solids.map((s) => /* @__PURE__ */ React25.createElement(
1739
- "div",
1740
- {
1741
- key: s,
1742
- style: { background: s },
1743
- className: "sb-rounded-md sb-h-6 sb-w-6 sb-cursor-pointer active:sb-scale-105 sb-border",
1744
- onClick: () => onBackgroundChange(s)
1745
- }
1746
- ))
1747
- ), /* @__PURE__ */ React25.createElement(
1748
- TabsContent,
1749
- {
1750
- value: "gradient",
1751
- className: "data-[state=active]:sb-flex sb-flex-wrap sb-gap-1 sb-p-4"
1752
- },
1753
- gradients.map((s) => /* @__PURE__ */ React25.createElement(
1754
- "div",
1755
- {
1756
- key: s,
1757
- style: { background: s },
1758
- className: "rounded-md h-6 w-6 cursor-pointer active:scale-105 border",
1759
- onClick: () => onBackgroundChange(s)
1760
- }
1761
- ))
1762
- ), /* @__PURE__ */ React25.createElement(TabsContent, { value: "image" }, /* @__PURE__ */ React25.createElement("div", { className: "sb-p-4 sb-border-b" }, /* @__PURE__ */ React25.createElement(
1763
- MediaInput,
1764
- {
1765
- className: "sb-grid sb-grid-cols-2 sb-gap-1",
1766
- itemClassName: "sb-aspect-video sb-h-auto sb-w-full",
1767
- multiple: false,
1768
- onFilesChange: (files) => {
1769
- if (!files.length)
1770
- return;
1771
- onBackgroundChange(`url(${files[0]})`);
1772
- },
1773
- onError: (e) => console.error(
1774
- "[media-input]: Title: " + e?.title,
1775
- "media-input: Error: " + e?.description
1776
- )
1777
- }
1778
- )), /* @__PURE__ */ React25.createElement("div", { className: "sb-grid sb-grid-cols-2 sb-gap-1 sb-p-4" }, images.map((s) => /* @__PURE__ */ React25.createElement(
1779
- "div",
1780
- {
1781
- key: s,
1782
- style: { backgroundImage: s },
1783
- className: "sb-rounded-md sb-bg-cover sb-bg-center sb-aspect-video sb-w-full sb-cursor-pointer sb-border active:sb-scale-105",
1784
- onClick: () => onBackgroundChange(s)
1785
- }
1786
- )))))));
1787
- };
1788
- var SpacingInput = (props) => {
1789
- const [value, setValue] = React25.useState(parse(props.value || "0px"));
1790
- const [indipendent, setIndipendent] = React25.useState(
1791
- isIndipendent(parse(props.value || "0px"))
1792
- );
1793
- React25.useEffect(() => {
1794
- if (!props.onChange)
1795
- return;
1796
- props.onChange(stringify(value));
1797
- }, [value, props.onChange]);
1798
- return /* @__PURE__ */ React25.createElement("div", { className: "sb-grid sb-grid-cols-[1fr,auto] sb-gap-3" }, /* @__PURE__ */ React25.createElement("div", { className: "sb-grid sb-grid-cols-2 sb-items-center sb-gap-3" }, !indipendent ? /* @__PURE__ */ React25.createElement(React25.Fragment, null, /* @__PURE__ */ React25.createElement(
1799
- AdvancedInput,
1800
- {
1801
- value: value.left,
1802
- pattern: "\\d+",
1803
- onChange: ({ target: { value: value2 } }) => setValue((prev) => ({ ...prev, left: +value2, right: +value2 })),
1804
- prepend: /* @__PURE__ */ React25.createElement(AlignHorizontalSpaceAroundIcon, { className: "sb-h-4 sb-w-4" }),
1805
- append: /* @__PURE__ */ React25.createElement("span", { className: "sb-text-muted-foreground" }, "px")
1806
- }
1807
- ), /* @__PURE__ */ React25.createElement(
1808
- AdvancedInput,
1809
- {
1810
- value: value.top,
1811
- pattern: "\\d+",
1812
- onChange: ({ target: { value: value2 } }) => setValue((prev) => ({ ...prev, top: +value2, bottom: +value2 })),
1813
- prepend: /* @__PURE__ */ React25.createElement(AlignHorizontalSpaceAroundIcon, { className: "sb-h-4 sb-w-4 sb-rotate-90" }),
1814
- append: /* @__PURE__ */ React25.createElement("span", { className: "sb-text-muted-foreground" }, "px")
1815
- }
1816
- )) : /* @__PURE__ */ React25.createElement(React25.Fragment, null, /* @__PURE__ */ React25.createElement(
1817
- AdvancedInput,
1818
- {
1819
- value: value.left,
1820
- pattern: "\\d+",
1821
- onChange: ({ target: { value: value2 } }) => setValue((prev) => ({ ...prev, left: +value2 })),
1822
- prepend: /* @__PURE__ */ React25.createElement(AlignHorizontalJustifyStartIcon, { className: "sb-h-4 sb-w-4" }),
1823
- append: /* @__PURE__ */ React25.createElement("span", { className: "sb-text-muted-foreground" }, "px")
1824
- }
1825
- ), /* @__PURE__ */ React25.createElement(
1826
- AdvancedInput,
1827
- {
1828
- value: value.top,
1829
- pattern: "\\d+",
1830
- onChange: ({ target: { value: value2 } }) => setValue((prev) => ({ ...prev, top: +value2 })),
1831
- prepend: /* @__PURE__ */ React25.createElement(AlignHorizontalJustifyStartIcon, { className: "sb-h-4 sb-w-4 sb-rotate-90" }),
1832
- append: /* @__PURE__ */ React25.createElement("span", { className: "sb-text-muted-foreground" }, "px")
1833
- }
1834
- ), /* @__PURE__ */ React25.createElement(
1835
- AdvancedInput,
1836
- {
1837
- value: value.right,
1838
- pattern: "\\d+",
1839
- onChange: ({ target: { value: value2 } }) => setValue((prev) => ({ ...prev, right: +value2 })),
1840
- prepend: /* @__PURE__ */ React25.createElement(AlignHorizontalJustifyStartIcon, { className: "sb-h-4 sb-w-4 sb-rotate-180" }),
1841
- append: /* @__PURE__ */ React25.createElement("span", { className: "sb-text-muted-foreground" }, "px")
1842
- }
1843
- ), /* @__PURE__ */ React25.createElement(
1844
- AdvancedInput,
1845
- {
1846
- value: value.bottom,
1847
- pattern: "\\d+",
1848
- onChange: ({ target: { value: value2 } }) => setValue((prev) => ({ ...prev, bottom: +value2 })),
1849
- prepend: /* @__PURE__ */ React25.createElement(AlignHorizontalJustifyStartIcon, { className: "sb-h-4 sb-w-4 sb--rotate-90" }),
1850
- append: /* @__PURE__ */ React25.createElement("span", { className: "sb-text-muted-foreground" }, "px")
1851
- }
1852
- ))), /* @__PURE__ */ React25.createElement("div", { className: "sb-shrink-0" }, /* @__PURE__ */ React25.createElement(
1853
- Toggle,
1854
- {
1855
- className: "sb-shrink-0 sb-flex sb-w-8 sb-h-8 sb-p-0",
1856
- variant: "outline",
1857
- size: "sm",
1858
- pressed: indipendent,
1859
- onPressedChange: setIndipendent
1860
- },
1861
- /* @__PURE__ */ React25.createElement(ScanIcon, { className: "sb-h-4 sb-w-4" })
1862
- )));
1863
- };
1864
- var isIndipendent = (value) => {
1865
- const { top, right, bottom, left } = value;
1866
- return top !== bottom || right !== left;
1867
- };
1868
- var parse = (value) => {
1869
- const matches = value.match(/(\d+)/gm);
1870
- const [top = 0, right = 0, bottom = 0, left = 0] = matches?.map((match) => +match) || [];
1871
- switch (matches?.length) {
1872
- case 1:
1873
- return { top, right: top, bottom: top, left: top };
1874
- case 2:
1875
- return { top, bottom: top, left: right, right };
1876
- case 3:
1877
- return { top, right, left: right, bottom };
1878
- default:
1879
- return { top, right, bottom, left };
1880
- }
1881
- };
1882
- var stringify = (value) => {
1883
- const { top, right, bottom, left } = value;
1884
- if (top === right && top === bottom && top === left) {
1885
- return `${top}px`;
1886
- }
1887
- if (top === bottom && right === left) {
1888
- return `${top}px ${right}px`;
1889
- }
1890
- if (right === left) {
1891
- return `${top}px ${right}px ${bottom}px`;
1892
- }
1893
- return `${top}px ${right}px ${bottom}px ${left}px`;
1894
- };
1895
-
1896
- // src/components/item-design-form.tsx
1897
- var designSchema = z.object({
1898
- container: z.coerce.boolean(),
1899
- hidden: z.enum(["always", "mobile", "desktop", "never"]),
1900
- desktop: z.object({
1901
- background: z.string(),
1902
- color: z.string(),
1903
- padding: z.string(),
1904
- margin: z.string()
1905
- }),
1906
- mobile: z.object({
1907
- background: z.string(),
1908
- color: z.string(),
1909
- padding: z.string(),
1910
- margin: z.string()
1911
- })
1912
- });
1913
- var ItemDesignForm = (props) => {
1914
- const { item } = props;
1915
- const component = builder.getComponent(item.component);
1916
- if (!component) {
1917
- throw new Error(
1918
- `[simple-builder]: Component "${item.component}" not found`
1919
- );
1920
- }
1921
- const getDefaultDeviceValue = (params) => {
1922
- const { device: device2 = "desktop", key, fallback = "" } = params;
1923
- if (item.styles?.[device2]?.[key] !== void 0) {
1924
- return item.styles[device2][key];
1925
- }
1926
- if (component.defaultStyles?.[device2]?.[key] !== void 0) {
1927
- return component.defaultStyles[device2][key];
1928
- }
1929
- if (device2 === "mobile") {
1930
- const desktopValue = getDefaultDeviceValue({
1931
- ...params,
1932
- device: "desktop"
1933
- });
1934
- if (desktopValue !== void 0) {
1935
- return desktopValue;
1936
- }
1937
- }
1938
- return fallback;
1939
- };
1940
- const getDefaultDeviceValues = (device2) => {
1941
- return {
1942
- background: getDefaultDeviceValue({ device: device2, key: "background" }),
1943
- color: getDefaultDeviceValue({ device: device2, key: "color" }),
1944
- padding: getDefaultDeviceValue({ device: device2, key: "padding" }),
1945
- margin: getDefaultDeviceValue({ device: device2, key: "margin" })
1946
- };
1947
- };
1948
- const form = useForm({
1949
- resolver: zodResolver(designSchema),
1950
- values: {
1951
- container: item.styles?.container ?? true,
1952
- hidden: item.styles?.hidden ?? "never",
1953
- desktop: getDefaultDeviceValues("desktop"),
1954
- mobile: getDefaultDeviceValues("mobile")
1955
- }
1956
- });
1957
- const { patchItem } = useBuilder();
1958
- const onSubmit = (values) => {
1959
- const { container, hidden, desktop, mobile } = values;
1960
- const dirtyFields = form.formState.dirtyFields;
1961
- const desktopPatch = Object.entries(desktop).reduce(
1962
- (acc, [key, value]) => ({
1963
- ...acc,
1964
- ...value && { [key]: value }
1965
- }),
1966
- { ...item.styles?.desktop }
1967
- );
1968
- const mobilePatch = Object.entries(mobile).reduce(
1969
- (acc, [key, value]) => {
1970
- const desktopValue = desktop[key];
1971
- const isDirty = dirtyFields.desktop?.[key];
1972
- if (value === desktopValue || isDirty) {
1973
- return acc;
1974
- }
1975
- if (["padding", "margin"].includes(key)) {
1976
- if (value === "0px" && desktopValue === "0px") {
1977
- return acc;
1978
- }
1979
- }
1980
- return {
1981
- ...acc,
1982
- ...value && { [key]: value }
1983
- };
1984
- },
1985
- { ...item.styles?.mobile }
1986
- );
1987
- patchItem(item.id, {
1988
- styles: {
1989
- ...container === false && { container },
1990
- ...hidden !== "never" && { hidden },
1991
- ...Object.keys(desktopPatch).length && { desktop: desktopPatch },
1992
- ...Object.keys(mobilePatch).length && { mobile: mobilePatch }
1993
- }
1994
- });
1995
- };
1996
- const [device, setDevice] = React25.useState("desktop");
1997
- React25.useEffect(() => {
1998
- const subscription = form.watch(() => form.handleSubmit(onSubmit)());
1999
- return () => subscription.unsubscribe();
2000
- }, [form.watch, form.handleSubmit]);
2001
- return /* @__PURE__ */ React25.createElement(Form, { ...form }, /* @__PURE__ */ React25.createElement("form", { onSubmit: form.handleSubmit(onSubmit) }, /* @__PURE__ */ React25.createElement("div", { className: "sb-space-y-4 sb-p-4" }, /* @__PURE__ */ React25.createElement(
2002
- Tabs,
2003
- {
2004
- defaultValue: device,
2005
- onValueChange: (device2) => setDevice(device2)
2006
- },
2007
- /* @__PURE__ */ React25.createElement(TabsList, { className: "sb-h-9 sb-grid sb-w-full sb-grid-cols-2" }, /* @__PURE__ */ React25.createElement(TabsTrigger, { value: "desktop", className: "sb-text-xs" }, /* @__PURE__ */ React25.createElement(MonitorIcon, { className: "sb-h-4 sb-w-4 sb-mr-2" }), /* @__PURE__ */ React25.createElement("span", null, "Desktop")), /* @__PURE__ */ React25.createElement(TabsTrigger, { value: "mobile", className: "sb-text-xs" }, /* @__PURE__ */ React25.createElement(SmartphoneIcon, { className: "sb-h-4 sb-w-4 sb-mr-2" }), /* @__PURE__ */ React25.createElement("span", null, "Mobiel")))
2008
- ), /* @__PURE__ */ React25.createElement("div", { className: "sb-space-y-4" }, /* @__PURE__ */ React25.createElement(
2009
- FormField,
2010
- {
2011
- control: form.control,
2012
- key: `${device}.background`,
2013
- name: `${device}.background`,
2014
- render: ({ field }) => /* @__PURE__ */ React25.createElement(FormItem, null, /* @__PURE__ */ React25.createElement(FormLabel, null, "Achtergrond"), /* @__PURE__ */ React25.createElement(FormControl, null, /* @__PURE__ */ React25.createElement(
2015
- BackgroundPicker,
2016
- {
2017
- background: field.value,
2018
- onBackgroundChange: field.onChange
2019
- }
2020
- )), /* @__PURE__ */ React25.createElement(FormMessage, null))
2021
- }
2022
- ), /* @__PURE__ */ React25.createElement(
2023
- FormField,
2024
- {
2025
- control: form.control,
2026
- key: `${device}.color`,
2027
- name: `${device}.color`,
2028
- render: ({ field }) => /* @__PURE__ */ React25.createElement(FormItem, null, /* @__PURE__ */ React25.createElement(FormLabel, null, "Inhoud kleur"), /* @__PURE__ */ React25.createElement(FormControl, null, /* @__PURE__ */ React25.createElement(
2029
- ColorPicker,
2030
- {
2031
- color: field.value,
2032
- onColorChange: field.onChange
2033
- }
2034
- )), /* @__PURE__ */ React25.createElement(FormMessage, null))
2035
- }
2036
- ), /* @__PURE__ */ React25.createElement("hr", null), /* @__PURE__ */ React25.createElement(
2037
- FormField,
2038
- {
2039
- control: form.control,
2040
- name: "hidden",
2041
- render: ({ field }) => /* @__PURE__ */ React25.createElement(FormItem, null, /* @__PURE__ */ React25.createElement(FormLabel, null, "Verbergen"), /* @__PURE__ */ React25.createElement(FormControl, null, /* @__PURE__ */ React25.createElement(Select, { value: field.value, onValueChange: field.onChange }, /* @__PURE__ */ React25.createElement(SelectTrigger, null, /* @__PURE__ */ React25.createElement(SelectValue, null)), /* @__PURE__ */ React25.createElement(SelectContent, null, /* @__PURE__ */ React25.createElement(SelectItem, { value: "never" }, "Nooit"), /* @__PURE__ */ React25.createElement(SelectItem, { value: "desktop" }, "Op desktop"), /* @__PURE__ */ React25.createElement(SelectItem, { value: "mobile" }, "Op mobiel"), /* @__PURE__ */ React25.createElement(SelectItem, { value: "always" }, "Altijd")))), /* @__PURE__ */ React25.createElement(FormMessage, null))
2042
- }
2043
- ), /* @__PURE__ */ React25.createElement("hr", null), /* @__PURE__ */ React25.createElement(
2044
- FormField,
2045
- {
2046
- control: form.control,
2047
- name: "container",
2048
- render: ({ field }) => /* @__PURE__ */ React25.createElement(FormItem, { className: "sb-flex sb-flex-row sb-items-center sb-justify-between sb-space-y-0" }, /* @__PURE__ */ React25.createElement(FormLabel, null, "Volledige breedte"), /* @__PURE__ */ React25.createElement(FormControl, null, /* @__PURE__ */ React25.createElement(
2049
- Switch,
2050
- {
2051
- checked: !field.value,
2052
- onCheckedChange: (v) => field.onChange(!v)
2053
- }
2054
- )), /* @__PURE__ */ React25.createElement(FormMessage, null))
2055
- }
2056
- ), /* @__PURE__ */ React25.createElement("hr", null), /* @__PURE__ */ React25.createElement(
2057
- FormField,
2058
- {
2059
- control: form.control,
2060
- key: `${device}.padding`,
2061
- name: `${device}.padding`,
2062
- render: ({ field }) => /* @__PURE__ */ React25.createElement(FormItem, null, /* @__PURE__ */ React25.createElement(FormLabel, null, "Padding"), /* @__PURE__ */ React25.createElement(FormControl, null, /* @__PURE__ */ React25.createElement(
2063
- SpacingInput,
2064
- {
2065
- value: field.value,
2066
- onChange: field.onChange
2067
- }
2068
- )), /* @__PURE__ */ React25.createElement(FormMessage, null))
2069
- }
2070
- ), /* @__PURE__ */ React25.createElement(
2071
- FormField,
2072
- {
2073
- control: form.control,
2074
- key: `${device}.margin`,
2075
- name: `${device}.margin`,
2076
- render: ({ field }) => /* @__PURE__ */ React25.createElement(FormItem, null, /* @__PURE__ */ React25.createElement(FormLabel, null, "Margin"), /* @__PURE__ */ React25.createElement(FormControl, null, /* @__PURE__ */ React25.createElement(
2077
- SpacingInput,
2078
- {
2079
- value: field.value,
2080
- onChange: field.onChange
2081
- }
2082
- )), /* @__PURE__ */ React25.createElement(FormMessage, null))
2083
- }
2084
- )))));
2085
- };
2086
- var ScrollArea = React25.forwardRef(({ className, children, ...props }, ref) => /* @__PURE__ */ React25.createElement(
2087
- ScrollAreaPrimitive.Root,
2088
- {
2089
- ref,
2090
- className: cn("sb-relative sb-overflow-hidden", className),
2091
- ...props
2092
- },
2093
- /* @__PURE__ */ React25.createElement(ScrollAreaPrimitive.Viewport, { className: "sb-h-full sb-max-h-[80vh] sb-w-full sb-rounded-[inherit]" }, children),
2094
- /* @__PURE__ */ React25.createElement(ScrollBar, null),
2095
- /* @__PURE__ */ React25.createElement(ScrollAreaPrimitive.Corner, null)
2096
- ));
2097
- ScrollArea.displayName = ScrollAreaPrimitive.Root.displayName;
2098
- var ScrollBar = React25.forwardRef(({ className, orientation = "vertical", ...props }, ref) => /* @__PURE__ */ React25.createElement(
2099
- ScrollAreaPrimitive.ScrollAreaScrollbar,
2100
- {
2101
- ref,
2102
- orientation,
2103
- className: cn(
2104
- "sb-flex sb-touch-none sb-select-none sb-transition-colors",
2105
- orientation === "vertical" && "sb-h-full sb-w-2.5 sb-border-l sb-border-l-transparent sb-p-[1px]",
2106
- orientation === "horizontal" && "sb-h-2.5 sb-flex-col sb-border-t sb-border-t-transparent sb-p-[1px]",
2107
- className
2108
- ),
2109
- ...props
2110
- },
2111
- /* @__PURE__ */ React25.createElement(ScrollAreaPrimitive.ScrollAreaThumb, { className: "sb-relative sb-flex-1 sb-rounded-full sb-bg-border" })
2112
- ));
2113
- ScrollBar.displayName = ScrollAreaPrimitive.ScrollAreaScrollbar.displayName;
2114
-
2115
- // src/components/container-item-toolbar.tsx
2116
- var ContainerItemToolbar = (props) => {
2117
- const { contentId, canBringUp = false, canBringDown = false } = props;
2118
- const { bringUp, bringDown } = useBuilder();
2119
- return /* @__PURE__ */ React25.createElement("div", { className: "sb-absolute sb-z-20 sb-top-1 sb-right-1 sb-rounded-md sb-shadow sb-flex sb-flex-col sb-gap-1 sb-p-1 sb-bg-card sb-text-card-foreground sb-item-toolbar sb-opacity-0 sb-transition-opacity" }, /* @__PURE__ */ React25.createElement("div", { className: "sb-h-10 sb-p-1 sb-border sb-border-input sb-bg-background sb-rounded-md sb-text-sm sb-font-medium sb-flex sb-gap-1 sb-items-center sb-justify-start" }, /* @__PURE__ */ React25.createElement(EditButton, { id: contentId }), /* @__PURE__ */ React25.createElement(
2120
- Button,
2121
- {
2122
- variant: "ghost",
2123
- className: "sb-w-8 sb-h-8 sb-p-0",
2124
- onClick: () => bringUp(contentId),
2125
- disabled: !canBringUp
2126
- },
2127
- /* @__PURE__ */ React25.createElement(ArrowUp, { className: "sb-h-5 sb-w-5" })
2128
- ), /* @__PURE__ */ React25.createElement(
2129
- Button,
2130
- {
2131
- variant: "ghost",
2132
- className: "sb-w-8 sb-h-8 sb-p-0",
2133
- onClick: () => bringDown(contentId),
2134
- disabled: !canBringDown
2135
- },
2136
- /* @__PURE__ */ React25.createElement(ArrowDown, { className: "sb-h-5 sb-w-5" })
2137
- ), /* @__PURE__ */ React25.createElement(DeleteButton, { contentId })));
2138
- };
2139
- var EditButton = ({ id }) => {
2140
- return /* @__PURE__ */ React25.createElement(Popover, { modal: true }, /* @__PURE__ */ React25.createElement(PopoverTrigger, { asChild: true }, /* @__PURE__ */ React25.createElement(Button, { variant: "ghost", className: "sb-w-8 sb-h-8 sb-p-0" }, /* @__PURE__ */ React25.createElement(Edit2Icon, { className: "sb-h-5 sb-w-5" }))), /* @__PURE__ */ React25.createElement(
2141
- PopoverContent,
2142
- {
2143
- side: "left",
2144
- align: "start",
2145
- sideOffset: 16,
2146
- alignOffset: -8,
2147
- className: "sb-p-0 sb-relative",
2148
- collisionPadding: 16
2149
- },
2150
- /* @__PURE__ */ React25.createElement(EditPopoverInner, { id })
2151
- ));
2152
- };
2153
- var EditPopoverInner = (props) => {
2154
- const { id } = props;
2155
- const { getItem } = useBuilder();
2156
- const item = getItem(id);
2157
- if (!item) {
2158
- throw new Error(
2159
- `[simple-builder]: Item with id ${id} not found in container item form component`
2160
- );
2161
- }
2162
- return /* @__PURE__ */ React25.createElement(Tabs, null, /* @__PURE__ */ React25.createElement(TabsList, { variant: "text", defaultValue: "content" }, /* @__PURE__ */ React25.createElement(TabsTrigger, { variant: "text", value: "content" }, "Inhoud"), /* @__PURE__ */ React25.createElement(TabsTrigger, { variant: "text", value: "design" }, "Design")), /* @__PURE__ */ React25.createElement(TabsContent, { value: "content" }, /* @__PURE__ */ React25.createElement(ScrollArea, null, /* @__PURE__ */ React25.createElement(ContainerItemForm, { item }))), /* @__PURE__ */ React25.createElement(TabsContent, { value: "design" }, /* @__PURE__ */ React25.createElement(ItemDesignForm, { item })));
2163
- };
2164
- var DeleteButton = ({ contentId }) => {
2165
- const { deleteContent } = useBuilder();
2166
- return /* @__PURE__ */ React25.createElement(AlertDialog, null, /* @__PURE__ */ React25.createElement(AlertDialogTrigger, { asChild: true }, /* @__PURE__ */ React25.createElement(
2167
- Button,
2168
- {
2169
- variant: "ghost",
2170
- className: "sb-w-8 sb-h-8 sb-p-0 sb-text-destructive"
2171
- },
2172
- /* @__PURE__ */ React25.createElement(Trash2Icon, { className: "sb-h-5 sb-w-5" })
2173
- )), /* @__PURE__ */ React25.createElement(AlertDialogContent, null, /* @__PURE__ */ React25.createElement(AlertDialogDescription, null, "Weet je zeker dat je dit blok wilt verwijderen?"), /* @__PURE__ */ React25.createElement(AlertDialogFooter, null, /* @__PURE__ */ React25.createElement(AlertDialogCancel, null, "Annuleren"), /* @__PURE__ */ React25.createElement(
2174
- AlertDialogAction,
2175
- {
2176
- className: buttonVariants({ variant: "destructive" }),
2177
- onClick: () => deleteContent(contentId)
2178
- },
2179
- "Verwijderen"
2180
- ))));
2181
- };
2182
-
2183
- // src/components/build-container-client.tsx
2184
- var BuildContainerInner = (props) => {
2185
- const { id, name, content, multiple = false } = props;
2186
- const items = Array.isArray(content) ? content : content?.[name] || [];
2187
- if (!multiple && items.length > 1) {
2188
- console.error(
2189
- "[simple-builder]: Multiple content blocks detected when using property multiple false."
2190
- );
2191
- }
2192
- return /* @__PURE__ */ React25.createElement("div", null, items.length <= 0 ? /* @__PURE__ */ React25.createElement(AddContentPlaceholder, { parent: id, container: name, index: 0 }) : multiple && /* @__PURE__ */ React25.createElement(AddContentDividerButton, { parent: id, container: name, index: 0 }), items.map((item, i) => /* @__PURE__ */ React25.createElement(React25.Fragment, { key: item.id }, /* @__PURE__ */ React25.createElement("div", { className: "sb-relative sb-container-item" }, /* @__PURE__ */ React25.createElement(DesignWrapper, { building: true, styles: item.styles }, builder.bindComponent(item, true)), /* @__PURE__ */ React25.createElement(
2193
- ContainerItemToolbar,
2194
- {
2195
- contentId: item.id,
2196
- canBringUp: i > 0,
2197
- canBringDown: i < items.length - 1
2198
- }
2199
- )), multiple && /* @__PURE__ */ React25.createElement(
2200
- AddContentDividerButton,
2201
- {
2202
- parent: id,
2203
- container: name,
2204
- index: i + 1
2205
- }
2206
- ))));
2207
- };
2208
- var build_container_client_default = BuildContainerInner;
2209
- var AddContentButton = (props) => {
2210
- const components = builder.getComponents();
2211
- const { addContent } = useBuilder();
2212
- return /* @__PURE__ */ React25.createElement(Popover, null, /* @__PURE__ */ React25.createElement(PopoverTrigger, { asChild: true }, props.children), /* @__PURE__ */ React25.createElement(PopoverContent, { className: "sb-p-1" }, /* @__PURE__ */ React25.createElement("div", { className: "sb-grid sb-grid-cols-2 sb-gap-2" }, components.map((component) => {
2213
- const Icon2 = component.icon ?? ImageIcon;
2214
- return /* @__PURE__ */ React25.createElement(PopoverClose, { key: component.name, asChild: true }, /* @__PURE__ */ React25.createElement(
2215
- Button,
2216
- {
2217
- variant: "ghost",
2218
- className: "sb-justify-start",
2219
- onClick: () => {
2220
- addContent(
2221
- component.name,
2222
- props.container,
2223
- props.parent,
2224
- props.index
2225
- );
2226
- }
2227
- },
2228
- /* @__PURE__ */ React25.createElement(Icon2, { className: "sb-mr-2 sb-h-4 sb-w-4 sb-shrink-0" }),
2229
- component.friendlyName ?? component.name
2230
- ));
2231
- }))));
2232
- };
2233
- var AddContentPlaceholder = (props) => {
2234
- return /* @__PURE__ */ React25.createElement(AddContentButton, { ...props }, /* @__PURE__ */ React25.createElement("div", { className: "sb-flex sb-justify-center sb-bg-primary/50 p-4" }, /* @__PURE__ */ React25.createElement(Button, { size: "sm" }, /* @__PURE__ */ React25.createElement(PlusIcon, { className: "sb-mr-2 sb-h-4 sb-w-4" }), "Blok Toevoegen")));
2235
- };
2236
- var AddContentDividerButton = (props) => {
2237
- return /* @__PURE__ */ React25.createElement(AddContentButton, { ...props }, /* @__PURE__ */ React25.createElement("div", { className: "sb-w-full sb-h-1 sb--my-[2px] sb-bg-primary sb-relative sb-z-20 sb-opacity-0 add-content-divider-button sb-transition-opacity" }, /* @__PURE__ */ React25.createElement(
2238
- Button,
2239
- {
2240
- size: "sm",
2241
- className: "sb-absolute sb-left-1/2 sb-top-1/2 sb--translate-y-1/2 sb--translate-x-1/2 sb-shadow"
2242
- },
2243
- /* @__PURE__ */ React25.createElement(PlusIcon, { className: "sb-mr-2 sb-h-4 sb-w-4" }),
2244
- "Blok Toevoegen"
2245
- )));
2246
- };
2247
-
2248
- export { build_container_client_default as default };