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