@coorax/react 0.0.0-canary.5 → 0.0.0-canary.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -54,18 +54,21 @@ import {
54
54
  CaptionModule,
55
55
  CodeModule,
56
56
  DeletionModule,
57
+ DividerModule,
57
58
  EditorModule,
58
59
  Engine,
59
60
  FocusModule,
60
61
  HistoryModule,
61
62
  HoverModule,
62
63
  InsertionModule,
64
+ MediaModule,
65
+ ParagraphThemeModule,
63
66
  SelectionModule,
64
67
  TextEditingModule,
65
68
  getCollectedStyles,
66
69
  setCoraxStyleSink
67
70
  } from "@coorax/core";
68
- import { createContext, useContext, useEffect, useMemo } from "react";
71
+ import { createContext, useContext, useEffect as useEffect6, useMemo } from "react";
69
72
  // src/registry/ui.primitives.registry.tsx
70
73
  import { GenericRegistry as GenericRegistry2 } from "@coorax/render-react";
71
74
  var UIPrimitivesRegistry = new GenericRegistry2;
@@ -79,12 +82,20 @@ import {
79
82
  } from "@coorax/render-react";
80
83
 
81
84
  // src/components/fallbacks/image.fallback.tsx
82
- import { RefreshCw } from "lucide-react";
85
+ import { RefreshCw, Trash2 } from "lucide-react";
83
86
  import { cn as cn2 } from "cn";
87
+ import { useEffect, useState } from "react";
84
88
  import { jsxDEV as jsxDEV2 } from "react/jsx-dev-runtime";
85
89
  function ImageFallback({ children, ...rest }) {
90
+ const [displayRemoveButton, setDisplayRemoveButton] = useState(false);
91
+ useEffect(() => {
92
+ const timer = setTimeout(() => {
93
+ setDisplayRemoveButton(true);
94
+ }, 1e4);
95
+ return () => clearTimeout(timer);
96
+ }, []);
86
97
  return /* @__PURE__ */ jsxDEV2("div", {
87
- className: "w-full h-[360px] flex relative pointer-events-none",
98
+ className: "w-full flex relative pointer-events-none",
88
99
  children: [
89
100
  /* @__PURE__ */ jsxDEV2("div", {
90
101
  className: cn2("w-full h-full absolute inset-0 flex gap-2 items-center justify-center bg-card"),
@@ -98,16 +109,36 @@ function ImageFallback({ children, ...rest }) {
98
109
  }, undefined, false, undefined, this)
99
110
  ]
100
111
  }, undefined, true, undefined, this),
101
- children
112
+ children,
113
+ displayRemoveButton && /* @__PURE__ */ jsxDEV2(Button, {
114
+ onClick: () => {
115
+ if (confirm("Delete image field ?")) {
116
+ window.__cooraxEngine.document.apply((t) => window.__cooraxEngine.mutations.deleteField(t, rest.id), { origin: "history" });
117
+ }
118
+ },
119
+ className: "absolute bottom-2 right-2 cursor-pointer pointer-events-auto",
120
+ title: "Delete image field ?",
121
+ variant: "destructive",
122
+ size: "icon-lg",
123
+ children: /* @__PURE__ */ jsxDEV2(Trash2, {}, undefined, false, undefined, this)
124
+ }, undefined, false, undefined, this)
102
125
  ]
103
126
  }, undefined, true, undefined, this);
104
127
  }
105
128
 
106
129
  // src/components/fallbacks/video.fallback.tsx
107
- import { RefreshCw as RefreshCw2 } from "lucide-react";
130
+ import { RefreshCw as RefreshCw2, Trash2 as Trash22 } from "lucide-react";
108
131
  import { cn as cn3 } from "cn";
132
+ import { useState as useState2, useEffect as useEffect2 } from "react";
109
133
  import { jsxDEV as jsxDEV3 } from "react/jsx-dev-runtime";
110
134
  function VideoFallback({ children, ...rest }) {
135
+ const [displayRemoveButton, setDisplayRemoveButton] = useState2(false);
136
+ useEffect2(() => {
137
+ const timer = setTimeout(() => {
138
+ setDisplayRemoveButton(true);
139
+ }, 1e4);
140
+ return () => clearTimeout(timer);
141
+ }, []);
111
142
  return /* @__PURE__ */ jsxDEV3("div", {
112
143
  className: "w-full h-[360px] flex relative pointer-events-none",
113
144
  children: [
@@ -124,18 +155,38 @@ function VideoFallback({ children, ...rest }) {
124
155
  ]
125
156
  }, undefined, true, undefined, this),
126
157
  children,
158
+ displayRemoveButton && /* @__PURE__ */ jsxDEV3(Button, {
159
+ onClick: () => {
160
+ if (confirm("Delete video field ?")) {
161
+ window.__cooraxEngine.document.apply((t) => window.__cooraxEngine.mutations.deleteField(t, rest.id), { origin: "history" });
162
+ }
163
+ },
164
+ className: "absolute bottom-2 right-2 cursor-pointer pointer-events-auto",
165
+ title: "Delete video field ?",
166
+ variant: "destructive",
167
+ size: "icon-lg",
168
+ children: /* @__PURE__ */ jsxDEV3(Trash22, {}, undefined, false, undefined, this)
169
+ }, undefined, false, undefined, this),
127
170
  /* @__PURE__ */ jsxDEV3("video", {}, undefined, false, undefined, this)
128
171
  ]
129
172
  }, undefined, true, undefined, this);
130
173
  }
131
174
 
132
175
  // src/components/fallbacks/iframe.fallback.tsx
133
- import { RefreshCw as RefreshCw3 } from "lucide-react";
176
+ import { RefreshCw as RefreshCw3, Trash2 as Trash23 } from "lucide-react";
134
177
  import { cn as cn4 } from "cn";
178
+ import { useState as useState3, useEffect as useEffect3 } from "react";
135
179
  import { jsxDEV as jsxDEV4 } from "react/jsx-dev-runtime";
136
180
  function IFrameFallback({ children, ...rest }) {
181
+ const [displayRemoveButton, setDisplayRemoveButton] = useState3(false);
182
+ useEffect3(() => {
183
+ const timer = setTimeout(() => {
184
+ setDisplayRemoveButton(true);
185
+ }, 1e4);
186
+ return () => clearTimeout(timer);
187
+ }, []);
137
188
  return /* @__PURE__ */ jsxDEV4("div", {
138
- className: "w-full h-[360px] flex relative pointer-events-none",
189
+ className: "w-full flex relative pointer-events-none",
139
190
  children: [
140
191
  /* @__PURE__ */ jsxDEV4("div", {
141
192
  className: cn4("w-full h-full absolute inset-0 flex gap-2 items-center justify-center bg-card"),
@@ -149,15 +200,36 @@ function IFrameFallback({ children, ...rest }) {
149
200
  }, undefined, false, undefined, this)
150
201
  ]
151
202
  }, undefined, true, undefined, this),
152
- children
203
+ children,
204
+ displayRemoveButton && /* @__PURE__ */ jsxDEV4(Button, {
205
+ onClick: () => {
206
+ if (confirm("Delete iframe field ?")) {
207
+ window.__cooraxEngine.document.apply((t) => window.__cooraxEngine.mutations.deleteField(t, rest.id), { origin: "history" });
208
+ }
209
+ },
210
+ className: "absolute bottom-2 right-2 cursor-pointer pointer-events-auto",
211
+ title: "Delete iframe field ?",
212
+ variant: "destructive",
213
+ size: "icon-lg",
214
+ children: /* @__PURE__ */ jsxDEV4(Trash23, {}, undefined, false, undefined, this)
215
+ }, undefined, false, undefined, this)
153
216
  ]
154
217
  }, undefined, true, undefined, this);
155
218
  }
156
219
 
157
220
  // src/components/fallbacks/link.fallback.tsx
158
221
  import { cn as cn5 } from "cn";
222
+ import { Trash2 as Trash24 } from "lucide-react";
223
+ import { useState as useState4, useEffect as useEffect4 } from "react";
159
224
  import { jsxDEV as jsxDEV5 } from "react/jsx-dev-runtime";
160
225
  function LinkFallback({ ...rest }) {
226
+ const [displayRemoveButton, setDisplayRemoveButton] = useState4(false);
227
+ useEffect4(() => {
228
+ const timer = setTimeout(() => {
229
+ setDisplayRemoveButton(true);
230
+ }, 1e4);
231
+ return () => clearTimeout(timer);
232
+ }, []);
161
233
  return /* @__PURE__ */ jsxDEV5("div", {
162
234
  className: "w-full h-[18px] rounded-[6px] overflow-hidden flex relative pointer-events-none bg-card",
163
235
  children: [
@@ -195,6 +267,18 @@ function LinkFallback({ ...rest }) {
195
267
  100% { transform: translateX(100%); }
196
268
  }
197
269
  `
270
+ }, undefined, false, undefined, this),
271
+ displayRemoveButton && /* @__PURE__ */ jsxDEV5(Button, {
272
+ onClick: () => {
273
+ if (confirm("Delete image field ?")) {
274
+ window.__cooraxEngine.document.apply((t) => window.__cooraxEngine.mutations.deleteField(t, rest.id), { origin: "history" });
275
+ }
276
+ },
277
+ className: "absolute -bottom-0.5 right-0 cursor-pointer pointer-events-auto",
278
+ title: "Delete link field ?",
279
+ variant: "destructive",
280
+ size: "icon-xs",
281
+ children: /* @__PURE__ */ jsxDEV5(Trash24, {}, undefined, false, undefined, this)
198
282
  }, undefined, false, undefined, this)
199
283
  ]
200
284
  }, undefined, true, undefined, this);
@@ -303,6 +387,29 @@ var ErrorsModule = {
303
387
  }
304
388
  };
305
389
 
390
+ // src/hooks/use-slice.ts
391
+ import { useSyncExternalStore } from "react";
392
+ function useSlice(sliceName) {
393
+ const engine = useEngine();
394
+ const slice = useSyncExternalStore((fn) => engine.state.subscribe(sliceName, fn), () => engine.state.get(sliceName), () => engine.state.get(sliceName));
395
+ return slice;
396
+ }
397
+ // src/hooks/use-ui-context.ts
398
+ function useUIContext() {
399
+ const selection = useSlice("selection") ?? { blocks: new Map };
400
+ const focus = useSlice("focus") ?? null;
401
+ const hover = useSlice("hover") ?? null;
402
+ const textSelection = useSlice("textSelection") ?? null;
403
+ return {
404
+ selection,
405
+ focus,
406
+ hover,
407
+ textSelection
408
+ };
409
+ }
410
+ // src/hooks/custom/use-isomorphic-layout-effect.ts
411
+ import { useEffect as useEffect5, useLayoutEffect } from "react";
412
+ var useIsomorphicLayoutEffect = typeof window !== "undefined" ? useLayoutEffect : useEffect5;
306
413
  // src/components/corax-context-provider.tsx
307
414
  import { jsxDEV as jsxDEV9 } from "react/jsx-dev-runtime";
308
415
  "use client";
@@ -320,6 +427,9 @@ function CoraxEngineProvider({ children }) {
320
427
  TextEditingModule,
321
428
  CodeModule,
322
429
  CaptionModule,
430
+ MediaModule,
431
+ DividerModule,
432
+ ParagraphThemeModule,
323
433
  DeletionModule,
324
434
  SlotsModule,
325
435
  FallbacksModule,
@@ -328,7 +438,7 @@ function CoraxEngineProvider({ children }) {
328
438
  engine2.modules.enableAll();
329
439
  return engine2;
330
440
  }, []);
331
- useEffect(() => {
441
+ useEffect6(() => {
332
442
  const styleEl = document.createElement("style");
333
443
  styleEl.setAttribute("data-corax", "pseudo-styles");
334
444
  document.head.appendChild(styleEl);
@@ -340,6 +450,9 @@ function CoraxEngineProvider({ children }) {
340
450
  styleEl.remove();
341
451
  };
342
452
  }, []);
453
+ useIsomorphicLayoutEffect(() => {
454
+ window.__cooraxEngine = engine;
455
+ }, [engine]);
343
456
  return /* @__PURE__ */ jsxDEV9(CoraxEngineContext.Provider, {
344
457
  value: engine,
345
458
  children
@@ -353,14 +466,6 @@ function useEngine() {
353
466
  return engine;
354
467
  }
355
468
 
356
- // src/hooks/use-slice.ts
357
- import { useSyncExternalStore } from "react";
358
- function useSlice(sliceName) {
359
- const engine = useEngine();
360
- const slice = useSyncExternalStore((fn) => engine.state.subscribe(sliceName, fn), () => engine.state.get(sliceName), () => engine.state.get(sliceName));
361
- return slice;
362
- }
363
-
364
469
  // src/lib/slots.utils.tsx
365
470
  import { cn as cn9 } from "cn";
366
471
  function getBlockActionsProps(isOpen, index) {
@@ -375,97 +480,18 @@ function getBlockActionsProps(isOpen, index) {
375
480
  }
376
481
 
377
482
  // src/components/slots/buttons/block-actions-button.tsx
378
- import { cn as cn11 } from "cn";
483
+ import { cn as cn10 } from "cn";
379
484
 
380
485
  // src/lib/comp.utils.tsx
486
+ import { GenericRegistry as GenericRegistry4 } from "@coorax/render-react";
487
+ import { createElement } from "react";
381
488
  import {
382
- BoldIcon,
383
- BracesIcon,
384
- Captions,
385
- FileTextIcon,
386
- HeadingIcon,
387
- ImagePlus,
388
- ItalicIcon,
389
- LinkIcon,
390
- Minus,
391
- PaletteIcon,
392
- PlusIcon,
393
- Pointer,
394
- PointerIcon,
395
- QuoteIcon,
396
- TextCursor,
397
- TextInitialIcon,
398
- Trash2,
399
- TvMinimalPlayIcon,
400
- UnderlineIcon
489
+ Pointer
401
490
  } from "lucide-react";
402
-
403
- // src/components/commons/youtube.tsx
404
- import { cn as cn10 } from "cn";
405
- import { jsxDEV as jsxDEV10 } from "react/jsx-dev-runtime";
406
- function YoutubeIcon({ className, ...props }) {
407
- return /* @__PURE__ */ jsxDEV10("svg", {
408
- xmlns: "http://www.w3.org/2000/svg",
409
- viewBox: "0 0 24 24",
410
- fill: "none",
411
- className: cn10("text-foreground", className),
412
- ...props,
413
- children: /* @__PURE__ */ jsxDEV10("path", {
414
- fillRule: "evenodd",
415
- clipRule: "evenodd",
416
- d: "M20.5949 4.45999C21.5421 4.71353 22.2865 5.45785 22.54 6.40501C22.9982 8.12001 23 11.7004 23 11.7004C23 11.7004 23 15.2807 22.54 16.9957C22.2865 17.9429 21.5421 18.6872 20.5949 18.9407C18.88 19.4007 12 19.4007 12 19.4007C12 19.4007 5.12001 19.4007 3.405 18.9407C2.45785 18.6872 1.71353 17.9429 1.45999 16.9957C1 15.2807 1 11.7004 1 11.7004C1 11.7004 1 8.12001 1.45999 6.40501C1.71353 5.45785 2.45785 4.71353 3.405 4.45999C5.12001 4 12 4 12 4C12 4 18.88 4 20.5949 4.45999ZM15.5134 11.7007L9.79788 15.0003V8.40101L15.5134 11.7007Z",
417
- stroke: "currentColor",
418
- strokeLinejoin: "round",
419
- strokeWidth: 2
420
- }, undefined, false, undefined, this)
421
- }, undefined, false, undefined, this);
422
- }
423
-
424
- // src/lib/comp.utils.tsx
425
- import { jsxDEV as jsxDEV11 } from "react/jsx-dev-runtime";
491
+ var CoraxIconsRegistry = new GenericRegistry4;
426
492
  function CoraxIcon({ icon }) {
427
- switch (icon) {
428
- case "TextIcon":
429
- return /* @__PURE__ */ jsxDEV11(TextCursor, {}, undefined, false, undefined, this);
430
- case "CursorIcon":
431
- return /* @__PURE__ */ jsxDEV11(PointerIcon, {}, undefined, false, undefined, this);
432
- case "HeadingIcon":
433
- return /* @__PURE__ */ jsxDEV11(HeadingIcon, {}, undefined, false, undefined, this);
434
- case "PlusIcon":
435
- return /* @__PURE__ */ jsxDEV11(PlusIcon, {}, undefined, false, undefined, this);
436
- case "BoldIcon":
437
- return /* @__PURE__ */ jsxDEV11(BoldIcon, {}, undefined, false, undefined, this);
438
- case "ItalicIcon":
439
- return /* @__PURE__ */ jsxDEV11(ItalicIcon, {}, undefined, false, undefined, this);
440
- case "UnderlineIcon":
441
- return /* @__PURE__ */ jsxDEV11(UnderlineIcon, {}, undefined, false, undefined, this);
442
- case "LinkIcon":
443
- return /* @__PURE__ */ jsxDEV11(LinkIcon, {}, undefined, false, undefined, this);
444
- case "ImagePlus":
445
- return /* @__PURE__ */ jsxDEV11(ImagePlus, {}, undefined, false, undefined, this);
446
- case "TextInitial":
447
- return /* @__PURE__ */ jsxDEV11(TextInitialIcon, {}, undefined, false, undefined, this);
448
- case "DividerIcon":
449
- return /* @__PURE__ */ jsxDEV11(Minus, {}, undefined, false, undefined, this);
450
- case "TvMinimalPlayIcon":
451
- return /* @__PURE__ */ jsxDEV11(TvMinimalPlayIcon, {}, undefined, false, undefined, this);
452
- case "YoutubeIcon":
453
- return /* @__PURE__ */ jsxDEV11(YoutubeIcon, {}, undefined, false, undefined, this);
454
- case "FileTextIcon":
455
- return /* @__PURE__ */ jsxDEV11(FileTextIcon, {}, undefined, false, undefined, this);
456
- case "QuoteIcon":
457
- return /* @__PURE__ */ jsxDEV11(QuoteIcon, {}, undefined, false, undefined, this);
458
- case "CodeIcon":
459
- return /* @__PURE__ */ jsxDEV11(BracesIcon, {}, undefined, false, undefined, this);
460
- case "PaletteIcon":
461
- return /* @__PURE__ */ jsxDEV11(PaletteIcon, {}, undefined, false, undefined, this);
462
- case "CaptionsIcon":
463
- return /* @__PURE__ */ jsxDEV11(Captions, {}, undefined, false, undefined, this);
464
- case "TrashIcon":
465
- return /* @__PURE__ */ jsxDEV11(Trash2, {}, undefined, false, undefined, this);
466
- default:
467
- return /* @__PURE__ */ jsxDEV11(Pointer, {}, undefined, false, undefined, this);
468
- }
493
+ const Icon = CoraxIconsRegistry.get(icon) ?? Pointer;
494
+ return createElement(Icon);
469
495
  }
470
496
 
471
497
  // src/lifecycle/fields/lifecycle.utils.ts
@@ -517,7 +543,7 @@ function getFieldTypeAndTargetId(engine, ev, block) {
517
543
 
518
544
  // src/components/slots/buttons/block-actions-button.tsx
519
545
  import React2 from "react";
520
- import { jsxDEV as jsxDEV12 } from "react/jsx-dev-runtime";
546
+ import { jsxDEV as jsxDEV10 } from "react/jsx-dev-runtime";
521
547
  var BlockActionButton = React2.memo(function BlockActionButton2({
522
548
  c,
523
549
  ui,
@@ -537,13 +563,13 @@ var BlockActionButton = React2.memo(function BlockActionButton2({
537
563
  return null;
538
564
  const { variant, size, isBaseButton = false } = c.getProps(ui);
539
565
  const enabled = engine.commands.has(c.command);
540
- return /* @__PURE__ */ jsxDEV12(Button, {
566
+ return /* @__PURE__ */ jsxDEV10(Button, {
541
567
  ...rest,
542
568
  variant,
543
569
  size,
544
570
  disabled: !enabled,
545
571
  ...!isBaseButton ? getBlockActionsProps(!isOpen, c.order ? c.order - 1 : 0) : {
546
- className: cn11("z-99 cursor-pointer transition-all", {
572
+ className: cn10("z-99 cursor-pointer transition-all", {
547
573
  "rotate-45": isOpen
548
574
  })
549
575
  },
@@ -570,7 +596,7 @@ var BlockActionButton = React2.memo(function BlockActionButton2({
570
596
  engine.commands.tryExecute(c.command, payload);
571
597
  },
572
598
  children: [
573
- /* @__PURE__ */ jsxDEV12(CoraxIcon, {
599
+ /* @__PURE__ */ jsxDEV10(CoraxIcon, {
574
600
  icon: c.icon
575
601
  }, undefined, false, undefined, this),
576
602
  c.label
@@ -580,7 +606,7 @@ var BlockActionButton = React2.memo(function BlockActionButton2({
580
606
 
581
607
  // src/components/slots/buttons/toolbar-button.tsx
582
608
  import React3 from "react";
583
- import { jsxDEV as jsxDEV13 } from "react/jsx-dev-runtime";
609
+ import { jsxDEV as jsxDEV11 } from "react/jsx-dev-runtime";
584
610
  var ToolbarButton = React3.memo(function ToolbarButton2({
585
611
  c,
586
612
  ui
@@ -588,7 +614,7 @@ var ToolbarButton = React3.memo(function ToolbarButton2({
588
614
  const engine = useEngine();
589
615
  const marks = useSlice("currentMarks");
590
616
  const isActive = !!c.getProps(ui)?.isActive || marks?.find((mark) => mark.type === c.getPayload(ui).format);
591
- return /* @__PURE__ */ jsxDEV13(Button, {
617
+ return /* @__PURE__ */ jsxDEV11(Button, {
592
618
  onClick: () => {
593
619
  engine.commands.tryExecute(c.command, c.getPayload(ui));
594
620
  },
@@ -596,7 +622,7 @@ var ToolbarButton = React3.memo(function ToolbarButton2({
596
622
  size: "icon-xs",
597
623
  className: "rounded-[8px] cursor-pointer",
598
624
  variant: isActive ? "default" : "secondary",
599
- children: /* @__PURE__ */ jsxDEV13(CoraxIcon, {
625
+ children: /* @__PURE__ */ jsxDEV11(CoraxIcon, {
600
626
  icon: c.icon
601
627
  }, undefined, false, undefined, this)
602
628
  }, c.id, false, undefined, this);
@@ -608,19 +634,19 @@ var ToolbarButton = React3.memo(function ToolbarButton2({
608
634
 
609
635
  // src/components/slots/buttons/code-theme-button.tsx
610
636
  import React4 from "react";
611
- import { jsxDEV as jsxDEV14 } from "react/jsx-dev-runtime";
637
+ import { jsxDEV as jsxDEV12 } from "react/jsx-dev-runtime";
612
638
  var CodeThemeButton = React4.memo(function CodeThemeButton2({
613
639
  c,
614
640
  ui
615
641
  }) {
616
642
  const engine = useEngine();
617
- return /* @__PURE__ */ jsxDEV14(Button, {
643
+ return /* @__PURE__ */ jsxDEV12(Button, {
618
644
  onClick: () => engine.commands.tryExecute(c.command, c.getPayload(ui)),
619
645
  title: c.label ?? "Toggle code theme",
620
646
  size: "icon-xs",
621
647
  className: "rounded-[8px] cursor-pointer",
622
648
  variant: "secondary",
623
- children: /* @__PURE__ */ jsxDEV14(CoraxIcon, {
649
+ children: /* @__PURE__ */ jsxDEV12(CoraxIcon, {
624
650
  icon: c.icon
625
651
  }, undefined, false, undefined, this)
626
652
  }, c.id, false, undefined, this);
@@ -628,21 +654,21 @@ var CodeThemeButton = React4.memo(function CodeThemeButton2({
628
654
 
629
655
  // src/components/slots/buttons/caption-button.tsx
630
656
  import React5 from "react";
631
- import { jsxDEV as jsxDEV15 } from "react/jsx-dev-runtime";
657
+ import { jsxDEV as jsxDEV13 } from "react/jsx-dev-runtime";
632
658
  var CaptionButton = React5.memo(function CaptionButton2({
633
659
  c,
634
660
  ui,
635
661
  ...rest
636
662
  }) {
637
663
  const engine = useEngine();
638
- return /* @__PURE__ */ jsxDEV15(Button, {
664
+ return /* @__PURE__ */ jsxDEV13(Button, {
639
665
  ...rest,
640
666
  onClick: () => engine.commands.tryExecute(c.command, c.getPayload(ui)),
641
667
  title: c.label ?? "Add caption",
642
668
  size: "icon-xs",
643
669
  className: "rounded-[8px] cursor-pointer",
644
670
  variant: "secondary",
645
- children: /* @__PURE__ */ jsxDEV15(CoraxIcon, {
671
+ children: /* @__PURE__ */ jsxDEV13(CoraxIcon, {
646
672
  icon: c.icon
647
673
  }, undefined, false, undefined, this)
648
674
  }, c.id, false, undefined, this);
@@ -650,28 +676,145 @@ var CaptionButton = React5.memo(function CaptionButton2({
650
676
 
651
677
  // src/components/slots/buttons/delete-button.tsx
652
678
  import React6 from "react";
653
- import { jsxDEV as jsxDEV16 } from "react/jsx-dev-runtime";
679
+ import { jsxDEV as jsxDEV14 } from "react/jsx-dev-runtime";
654
680
  var DeleteButton = React6.memo(function DeleteButton2({
655
681
  c,
656
682
  ui,
657
683
  ...rest
658
684
  }) {
659
685
  const engine = useEngine();
660
- return /* @__PURE__ */ jsxDEV16(Button, {
686
+ return /* @__PURE__ */ jsxDEV14(Button, {
661
687
  ...rest,
662
688
  onClick: () => engine.commands.tryExecute(c.command, c.getPayload(ui)),
663
689
  title: c.label ?? "Delete",
664
690
  size: "icon-xs",
665
691
  className: "rounded-[8px] cursor-pointer text-destructive",
666
692
  variant: "secondary",
693
+ children: /* @__PURE__ */ jsxDEV14(CoraxIcon, {
694
+ icon: c.icon
695
+ }, undefined, false, undefined, this)
696
+ }, c.id, false, undefined, this);
697
+ });
698
+
699
+ // src/components/slots/buttons/iframe-playback-button.tsx
700
+ import React7 from "react";
701
+ import { jsxDEV as jsxDEV15 } from "react/jsx-dev-runtime";
702
+ var IframePlaybackButton = React7.memo(function IframePlaybackButton2({
703
+ c,
704
+ ui,
705
+ ...rest
706
+ }) {
707
+ const engine = useEngine();
708
+ const [isPlaying, setIsPlaying] = React7.useState(false);
709
+ return /* @__PURE__ */ jsxDEV15(Button, {
710
+ ...rest,
711
+ onClick: () => {
712
+ const { fieldId } = c.getPayload(ui);
713
+ engine.commands.tryExecute(c.command, { fieldId, action: isPlaying ? "pause" : "play" });
714
+ setIsPlaying(!isPlaying);
715
+ },
716
+ title: c.label ?? "Play/Pause",
717
+ size: "icon-xs",
718
+ className: "rounded-[8px] cursor-pointer",
719
+ variant: "secondary",
720
+ children: /* @__PURE__ */ jsxDEV15(CoraxIcon, {
721
+ icon: isPlaying ? "PauseIcon" : "PlayIcon"
722
+ }, undefined, false, undefined, this)
723
+ }, c.id, false, undefined, this);
724
+ });
725
+
726
+ // src/hooks/use-block.ts
727
+ import { useSyncExternalStore as useSyncExternalStore2 } from "react";
728
+ function useBlock(id) {
729
+ const engine = useEngine();
730
+ return useSyncExternalStore2((fn) => engine.document.subscribeBlock(id, fn), () => engine.document.getBlock(id), () => engine.document.getBlock(id));
731
+ }
732
+
733
+ // src/components/slots/buttons/image-width-button.tsx
734
+ import React8 from "react";
735
+ import { jsxDEV as jsxDEV16 } from "react/jsx-dev-runtime";
736
+ var ImageWidthButton = React8.memo(function ImageWidthButton2({
737
+ c,
738
+ ui,
739
+ ...rest
740
+ }) {
741
+ const engine = useEngine();
742
+ const { fieldId, width } = c.getPayload(ui);
743
+ const block = useBlock(fieldId);
744
+ return /* @__PURE__ */ jsxDEV16(Button, {
745
+ ...rest,
746
+ onClick: () => engine.commands.tryExecute(c.command, c.getPayload(ui)),
747
+ title: c.label ?? "Image width",
748
+ size: "icon-xs",
749
+ className: "rounded-[8px] cursor-pointer",
750
+ variant: block?.props.style?.width === width ? "default" : "secondary",
667
751
  children: /* @__PURE__ */ jsxDEV16(CoraxIcon, {
668
752
  icon: c.icon
669
753
  }, undefined, false, undefined, this)
670
754
  }, c.id, false, undefined, this);
671
755
  });
672
756
 
757
+ // src/components/slots/buttons/divider-width-button.tsx
758
+ import React9 from "react";
759
+ import { jsxDEV as jsxDEV17 } from "react/jsx-dev-runtime";
760
+ var DividerWidthButton = React9.memo(function DividerWidthButton2({
761
+ c,
762
+ ui,
763
+ ...rest
764
+ }) {
765
+ const engine = useEngine();
766
+ const { fieldId, width } = c.getPayload(ui);
767
+ const block = useBlock(fieldId);
768
+ return /* @__PURE__ */ jsxDEV17(Button, {
769
+ ...rest,
770
+ onMouseDown: (ev) => ev.preventDefault(),
771
+ onClick: () => engine.commands.tryExecute(c.command, c.getPayload(ui)),
772
+ title: c.label ?? "Divider width",
773
+ size: "icon-xs",
774
+ className: "rounded-[8px] cursor-pointer",
775
+ variant: block?.props.style?.width === width ? "default" : "secondary",
776
+ children: /* @__PURE__ */ jsxDEV17(CoraxIcon, {
777
+ icon: c.icon
778
+ }, undefined, false, undefined, this)
779
+ }, c.id, false, undefined, this);
780
+ });
781
+
782
+ // src/components/slots/buttons/divider-style-button.tsx
783
+ import React10 from "react";
784
+ import { jsxDEV as jsxDEV18 } from "react/jsx-dev-runtime";
785
+ var DividerStyleButton = React10.memo(function DividerStyleButton2({
786
+ c,
787
+ ui,
788
+ ...rest
789
+ }) {
790
+ const engine = useEngine();
791
+ const { fieldId } = c.getPayload(ui);
792
+ const block = useBlock(fieldId);
793
+ const targetStyle = c.getProps(ui)?.borderStyle ?? "solid";
794
+ const isActive = (block?.props.style?.borderTopStyle ?? "solid") === targetStyle;
795
+ return /* @__PURE__ */ jsxDEV18(Button, {
796
+ ...rest,
797
+ onMouseDown: (ev) => ev.preventDefault(),
798
+ onClick: () => engine.commands.tryExecute(c.command, c.getPayload(ui)),
799
+ title: c.label ?? "Divider style",
800
+ size: "icon-xs",
801
+ className: "rounded-[8px] cursor-pointer",
802
+ variant: isActive ? "default" : "secondary",
803
+ children: /* @__PURE__ */ jsxDEV18("span", {
804
+ "aria-hidden": true,
805
+ style: {
806
+ display: "block",
807
+ width: 14,
808
+ borderTopWidth: 2,
809
+ borderTopStyle: targetStyle,
810
+ borderTopColor: "currentColor"
811
+ }
812
+ }, undefined, false, undefined, this)
813
+ }, c.id, false, undefined, this);
814
+ });
815
+
673
816
  // src/components/slots/overlays/focus-overlay.tsx
674
- import { useEffect as useEffect2 } from "react";
817
+ import { useEffect as useEffect7 } from "react";
675
818
 
676
819
  // src/lib/func.utils.ts
677
820
  function focusDomBLockById(engine, id) {
@@ -688,28 +831,28 @@ function focusDomElement(id) {
688
831
  }
689
832
 
690
833
  // src/components/slots/overlays/focus-overlay.tsx
691
- import { jsxDEV as jsxDEV17 } from "react/jsx-dev-runtime";
834
+ import { jsxDEV as jsxDEV19 } from "react/jsx-dev-runtime";
692
835
  function FocusOverlay({
693
836
  c,
694
837
  ui
695
838
  }) {
696
839
  const { position = null, hidden = null } = c.getProps(ui) ?? {};
697
840
  const focusedId = ui.focus?.id;
698
- useEffect2(() => {
841
+ useEffect7(() => {
699
842
  if (!focusedId)
700
843
  return;
701
844
  focusDomElement(focusedId);
702
845
  }, [focusedId]);
703
846
  if (hidden || !position)
704
847
  return null;
705
- return /* @__PURE__ */ jsxDEV17("div", {
848
+ return /* @__PURE__ */ jsxDEV19("div", {
706
849
  style: position,
707
850
  className: "absolute border border-blue-700 pointer-events-none flex justify-end"
708
851
  }, undefined, false, undefined, this);
709
852
  }
710
853
 
711
854
  // src/components/slots/overlays/hover-overlay.tsx
712
- import { jsxDEV as jsxDEV18 } from "react/jsx-dev-runtime";
855
+ import { jsxDEV as jsxDEV20 } from "react/jsx-dev-runtime";
713
856
  function HoverOverlay({
714
857
  c,
715
858
  ui
@@ -717,14 +860,14 @@ function HoverOverlay({
717
860
  const { position = null, hidden = null } = c.getProps(ui) ?? {};
718
861
  if (hidden || !position)
719
862
  return null;
720
- return /* @__PURE__ */ jsxDEV18("div", {
863
+ return /* @__PURE__ */ jsxDEV20("div", {
721
864
  style: position,
722
865
  className: "absolute border-[0.5px] border-blue-400 pointer-events-none flex justify-end"
723
866
  }, undefined, false, undefined, this);
724
867
  }
725
868
 
726
869
  // src/components/slots/overlays/selection-overlay.tsx
727
- import { jsxDEV as jsxDEV19 } from "react/jsx-dev-runtime";
870
+ import { jsxDEV as jsxDEV21 } from "react/jsx-dev-runtime";
728
871
  function SelectionOverlay({
729
872
  c,
730
873
  ui
@@ -732,12 +875,101 @@ function SelectionOverlay({
732
875
  const { position = null, hidden = null } = c.getProps(ui) ?? {};
733
876
  if (hidden || !position)
734
877
  return null;
735
- return /* @__PURE__ */ jsxDEV19("div", {
878
+ return /* @__PURE__ */ jsxDEV21("div", {
736
879
  style: position,
737
880
  className: "absolute border border-blue-500 pointer-events-none flex justify-end"
738
881
  }, undefined, false, undefined, this);
739
882
  }
740
883
 
884
+ // src/modules/slots.module.tsx
885
+ import { TextCursor, PointerIcon, HeadingIcon, Heading2, PlusIcon, BoldIcon, ItalicIcon, UnderlineIcon, LinkIcon, ImagePlus, TextInitialIcon, Minus, TvMinimalPlayIcon, FileTextIcon, QuoteIcon, BracesIcon, PaletteIcon, Captions, Trash2 as Trash25, Play, Pause, MoveHorizontal, Expand, LineStyle, OctagonExclamationPoint, OctagonX, InfoIcon, CircleLetterI } from "lucide-react";
886
+
887
+ // src/components/commons/youtube.tsx
888
+ import { cn as cn11 } from "cn";
889
+ import { jsxDEV as jsxDEV22 } from "react/jsx-dev-runtime";
890
+ function YoutubeIcon({ className, ...props }) {
891
+ return /* @__PURE__ */ jsxDEV22("svg", {
892
+ xmlns: "http://www.w3.org/2000/svg",
893
+ viewBox: "0 0 24 24",
894
+ fill: "none",
895
+ className: cn11("text-foreground", className),
896
+ ...props,
897
+ children: /* @__PURE__ */ jsxDEV22("path", {
898
+ fillRule: "evenodd",
899
+ clipRule: "evenodd",
900
+ d: "M20.5949 4.45999C21.5421 4.71353 22.2865 5.45785 22.54 6.40501C22.9982 8.12001 23 11.7004 23 11.7004C23 11.7004 23 15.2807 22.54 16.9957C22.2865 17.9429 21.5421 18.6872 20.5949 18.9407C18.88 19.4007 12 19.4007 12 19.4007C12 19.4007 5.12001 19.4007 3.405 18.9407C2.45785 18.6872 1.71353 17.9429 1.45999 16.9957C1 15.2807 1 11.7004 1 11.7004C1 11.7004 1 8.12001 1.45999 6.40501C1.71353 5.45785 2.45785 4.71353 3.405 4.45999C5.12001 4 12 4 12 4C12 4 18.88 4 20.5949 4.45999ZM15.5134 11.7007L9.79788 15.0003V8.40101L15.5134 11.7007Z",
901
+ stroke: "currentColor",
902
+ strokeLinejoin: "round",
903
+ strokeWidth: 2
904
+ }, undefined, false, undefined, this)
905
+ }, undefined, false, undefined, this);
906
+ }
907
+ // src/lib/selection.utils.ts
908
+ function rangeToOffsets(root, range) {
909
+ const measure = (node, offset) => {
910
+ const r = document.createRange();
911
+ r.selectNodeContents(root);
912
+ r.setEnd(node, offset);
913
+ return r.toString().length;
914
+ };
915
+ return {
916
+ start: measure(range.startContainer, range.startOffset),
917
+ end: measure(range.endContainer, range.endOffset)
918
+ };
919
+ }
920
+ function offsetsToRange(root, start, end) {
921
+ const range = document.createRange();
922
+ const walker = document.createTreeWalker(root, NodeFilter.SHOW_TEXT);
923
+ let pos = 0, startSet = false;
924
+ for (let n = walker.nextNode();n; n = walker.nextNode()) {
925
+ const next = pos + n.length;
926
+ if (!startSet && start <= next) {
927
+ range.setStart(n, start - pos);
928
+ startSet = true;
929
+ }
930
+ if (startSet && end <= next) {
931
+ range.setEnd(n, end - pos);
932
+ return range;
933
+ }
934
+ pos = next;
935
+ }
936
+ return null;
937
+ }
938
+ // src/components/slots/buttons/paragraph-theme-button.tsx
939
+ import {
940
+ getParagraphTheme
941
+ } from "@coorax/core";
942
+ import React11 from "react";
943
+ import { cn as cn12 } from "cn";
944
+ import { jsxDEV as jsxDEV23 } from "react/jsx-dev-runtime";
945
+ var ParagraphThemeButton = React11.memo(function ParagraphThemeButton2({
946
+ c,
947
+ ui,
948
+ ...rest
949
+ }) {
950
+ const engine = useEngine();
951
+ const { fieldId, theme } = c.getPayload(ui);
952
+ const block = useBlock(fieldId);
953
+ const isActive = !!block && getParagraphTheme(block.props.children) === theme;
954
+ const props = c.getProps(ui);
955
+ return /* @__PURE__ */ jsxDEV23(Button, {
956
+ ...rest,
957
+ onMouseDown: (ev) => ev.preventDefault(),
958
+ onClick: () => engine.commands.tryExecute(c.command, c.getPayload(ui)),
959
+ title: c.label ?? "Paragraph theme",
960
+ size: "icon-xs",
961
+ className: cn12("rounded-[8px] cursor-pointer", {
962
+ "bg-[#FF4D4F]/30": props.theme === "error" && !isActive,
963
+ "bg-[#FF9900]/30": props.theme === "warning" && !isActive,
964
+ "bg-[#007AFF]/30": props.theme === "info" && !isActive
965
+ }),
966
+ variant: isActive ? "default" : "secondary",
967
+ children: /* @__PURE__ */ jsxDEV23(CoraxIcon, {
968
+ icon: c.icon
969
+ }, undefined, false, undefined, this)
970
+ }, c.id, false, undefined, this);
971
+ });
972
+
741
973
  // src/modules/slots.module.tsx
742
974
  var SlotsModule = {
743
975
  name: "slots",
@@ -749,9 +981,43 @@ var SlotsModule = {
749
981
  SlotsComponentRegistry.register("CodeThemeButton", CodeThemeButton);
750
982
  SlotsComponentRegistry.register("CaptionButton", CaptionButton);
751
983
  SlotsComponentRegistry.register("DeleteButton", DeleteButton);
984
+ SlotsComponentRegistry.register("IframePlaybackButton", IframePlaybackButton);
985
+ SlotsComponentRegistry.register("ImageWidthButton", ImageWidthButton);
986
+ SlotsComponentRegistry.register("DividerWidthButton", DividerWidthButton);
987
+ SlotsComponentRegistry.register("DividerStyleButton", DividerStyleButton);
988
+ SlotsComponentRegistry.register("ParagraphThemeButton", ParagraphThemeButton);
752
989
  SlotsComponentRegistry.register("SelectionOverlay", SelectionOverlay);
753
990
  SlotsComponentRegistry.register("FocusOverlay", FocusOverlay);
754
991
  SlotsComponentRegistry.register("HoverOverlay", HoverOverlay);
992
+ CoraxIconsRegistry.register("TextIcon", TextCursor);
993
+ CoraxIconsRegistry.register("CursorIcon", PointerIcon);
994
+ CoraxIconsRegistry.register("HeadingIcon", HeadingIcon);
995
+ CoraxIconsRegistry.register("Heading2Icon", Heading2);
996
+ CoraxIconsRegistry.register("PlusIcon", PlusIcon);
997
+ CoraxIconsRegistry.register("BoldIcon", BoldIcon);
998
+ CoraxIconsRegistry.register("ItalicIcon", ItalicIcon);
999
+ CoraxIconsRegistry.register("UnderlineIcon", UnderlineIcon);
1000
+ CoraxIconsRegistry.register("LinkIcon", LinkIcon);
1001
+ CoraxIconsRegistry.register("ImagePlus", ImagePlus);
1002
+ CoraxIconsRegistry.register("TextInitial", TextInitialIcon);
1003
+ CoraxIconsRegistry.register("DividerIcon", Minus);
1004
+ CoraxIconsRegistry.register("TvMinimalPlayIcon", TvMinimalPlayIcon);
1005
+ CoraxIconsRegistry.register("YoutubeIcon", YoutubeIcon);
1006
+ CoraxIconsRegistry.register("FileTextIcon", FileTextIcon);
1007
+ CoraxIconsRegistry.register("QuoteIcon", QuoteIcon);
1008
+ CoraxIconsRegistry.register("CodeIcon", BracesIcon);
1009
+ CoraxIconsRegistry.register("PaletteIcon", PaletteIcon);
1010
+ CoraxIconsRegistry.register("CaptionsIcon", Captions);
1011
+ CoraxIconsRegistry.register("TrashIcon", Trash25);
1012
+ CoraxIconsRegistry.register("PlayIcon", Play);
1013
+ CoraxIconsRegistry.register("PauseIcon", Pause);
1014
+ CoraxIconsRegistry.register("MoveHorizontalIcon", MoveHorizontal);
1015
+ CoraxIconsRegistry.register("ExpandIcon", Expand);
1016
+ CoraxIconsRegistry.register("LineStyleIcon", LineStyle);
1017
+ CoraxIconsRegistry.register("ThemeWarningIcon", OctagonExclamationPoint);
1018
+ CoraxIconsRegistry.register("ThemeErrorIcon", OctagonX);
1019
+ CoraxIconsRegistry.register("ThemeInfoIcon", InfoIcon);
1020
+ CoraxIconsRegistry.register("ThemeNeutralIcon", CircleLetterI);
755
1021
  }
756
1022
  };
757
1023
  // src/modules/autosave.module.ts
@@ -2007,324 +2273,96 @@ var AutoSaveModule = {
2007
2273
  }
2008
2274
  };
2009
2275
  // src/components/slots/maps/block-actions.tsx
2010
- import { useEffect as useEffect3, useMemo as useMemo2, useRef } from "react";
2011
-
2012
- // src/hooks/use-slots.ts
2013
- import { useSyncExternalStore as useSyncExternalStore2 } from "react";
2014
- function useSlots(slotName) {
2015
- const engine = useEngine();
2016
- const items = useSyncExternalStore2((fn) => engine.ui.subscribe(slotName, fn), () => engine.ui.getSlots(slotName), () => engine.ui.getSlots(slotName));
2017
- return items;
2018
- }
2019
-
2020
- // src/hooks/use-registry.ts
2021
- import { useSyncExternalStore as useSyncExternalStore3 } from "react";
2022
- function useRegistryComponent(name) {
2023
- return useSyncExternalStore3((fn) => SlotsComponentRegistry.subscribe(name, fn), () => SlotsComponentRegistry.get(name), () => SlotsComponentRegistry.get(name));
2024
- }
2025
-
2026
- // src/components/slots/slot-button.tsx
2027
- import React7 from "react";
2028
- function SlotButton({ c, ui }) {
2029
- const Comp = useRegistryComponent(c.name);
2030
- if (!Comp) {
2031
- console.warn(`No component registered for slot key "${c.name}"`);
2032
- return null;
2033
- }
2034
- return React7.createElement(Comp, {
2035
- c,
2036
- ui,
2037
- ...{
2038
- "data-slot-type": "slot-button"
2039
- }
2040
- });
2041
- }
2042
-
2043
- // src/hooks/use-ui-context.ts
2044
- function useUIContext() {
2045
- const selection = useSlice("selection") ?? { blocks: new Map };
2046
- const focus = useSlice("focus") ?? null;
2047
- const hover = useSlice("hover") ?? null;
2048
- const textSelection = useSlice("textSelection") ?? null;
2049
- return {
2050
- selection,
2051
- focus,
2052
- hover,
2053
- textSelection
2054
- };
2055
- }
2056
-
2057
- // src/components/slots/slot-component.tsx
2058
- import { createElement } from "react";
2059
- function SlotComponent({ c, ui }) {
2060
- const Comp = useRegistryComponent(c.name);
2061
- if (!Comp) {
2062
- console.warn(`No component registered for slot key "${c.name}"`);
2063
- return null;
2064
- }
2065
- const props = c.getProps(ui);
2066
- if (!props)
2067
- return null;
2068
- return createElement(Comp, { ui, c });
2069
- }
2070
-
2071
- // src/components/slots/slots.tsx
2072
- import { jsxDEV as jsxDEV20, Fragment } from "react/jsx-dev-runtime";
2073
- function Slots({ slotName }) {
2074
- const items = useSlots(slotName);
2075
- const ui = useUIContext();
2076
- return /* @__PURE__ */ jsxDEV20(Fragment, {
2077
- children: items.map((c) => /* @__PURE__ */ jsxDEV20(SlotItem, {
2078
- c,
2079
- ui
2080
- }, c.id, false, undefined, this))
2081
- }, undefined, false, undefined, this);
2082
- }
2083
- function SlotItem({ c, ui }) {
2084
- if (c.when && !c.when(ui))
2085
- return null;
2086
- switch (c.kind) {
2087
- case "button":
2088
- return /* @__PURE__ */ jsxDEV20(SlotButton, {
2089
- c,
2090
- ui
2091
- }, undefined, false, undefined, this);
2092
- case "component":
2093
- return /* @__PURE__ */ jsxDEV20(SlotComponent, {
2094
- c,
2095
- ui
2096
- }, undefined, false, undefined, this);
2097
- }
2098
- }
2099
-
2100
- // src/components/slots/maps/block-actions.tsx
2101
- import { cn as cn12 } from "cn";
2102
- import { isEditableField } from "@coorax/core";
2276
+ import { useEffect as useEffect12, useMemo as useMemo3, useRef as useRef3 } from "react";
2103
2277
 
2104
- // src/hooks/use-block.ts
2105
- import { useSyncExternalStore as useSyncExternalStore4 } from "react";
2106
- function useBlock(id) {
2107
- const engine = useEngine();
2108
- return useSyncExternalStore4((fn) => engine.document.subscribeBlock(id, fn), () => engine.document.getBlock(id), () => engine.document.getBlock(id));
2109
- }
2110
-
2111
- // src/components/slots/maps/block-actions.tsx
2112
- import { jsxDEV as jsxDEV21 } from "react/jsx-dev-runtime";
2113
- function BlockActions({ className, children, ...rest }) {
2114
- const focusMemo = useSlice("focus_memory");
2115
- const focus = focusMemo?.blocks?.[0];
2116
- const items = useSlots("block-actions");
2117
- const lastPositionRef = useRef({ active: false, top: 0, left: 0 });
2118
- const block = useBlock(focus?.id ?? "");
2119
- const isOpened = !!useSlice("insertion");
2120
- const position = useMemo2(() => {
2121
- if (!focus || !block || !isEditableField(block)) {
2122
- return { active: false, top: 0, left: 0 };
2123
- }
2124
- const hasContent = !!block.props.children.text.length;
2125
- if (hasContent) {
2126
- return { active: false, top: 0, left: 0 };
2127
- }
2128
- const { id: firstSelectionId, rect: blockRect } = focus;
2129
- const container = document.getElementById("corax_flow_blocks_container");
2130
- if (!container)
2131
- return { active: false, top: 0, left: 0 };
2132
- const containerRect = container.getBoundingClientRect();
2133
- const domElement = document.getElementById(firstSelectionId);
2134
- if (!domElement)
2135
- return { active: false, top: 0, left: 0 };
2136
- const heightDiff = 36 - blockRect.height;
2137
- const toSubstract = heightDiff / 2;
2138
- const top = blockRect.top - (-toSubstract > 32 ? -8 : toSubstract) - containerRect.top - container.clientTop + blockRect.parentScrollTop;
2139
- return {
2140
- active: true,
2141
- top,
2142
- left: 0
2143
- };
2144
- }, [focus, block]);
2145
- useEffect3(() => {
2146
- if (position.active) {
2147
- lastPositionRef.current = position;
2148
- }
2149
- }, [position]);
2150
- const _position = position.active ? position : lastPositionRef.current;
2151
- return /* @__PURE__ */ jsxDEV21("div", {
2152
- style: {
2153
- top: _position.top,
2154
- left: _position.left
2155
- },
2156
- className: cn12("absolute top-0 left-0 gap-1 z-10 flex items-center transition-opacity", className, {
2157
- "opacity-0 pointer-events-none": !position.active || !focus
2158
- }),
2159
- ...rest,
2160
- children: [
2161
- /* @__PURE__ */ jsxDEV21(Slots, {
2162
- slotName: "block-actions"
2163
- }, undefined, false, undefined, this),
2164
- /* @__PURE__ */ jsxDEV21("div", {
2165
- style: {
2166
- width: isOpened ? (items.length - 1) * 32 + 8 : 0
2167
- },
2168
- className: cn12("absolute h-9.5 -z-1 left-9 bg-popover border rounded-full transition-all duration-300 ease-damping", {
2169
- "opacity-0 pointer-events-none": !isOpened
2170
- })
2171
- }, undefined, false, undefined, this),
2172
- children
2173
- ]
2174
- }, undefined, true, undefined, this);
2175
- }
2176
- // src/components/slots/maps/overlays.tsx
2177
- import { jsxDEV as jsxDEV22, Fragment as Fragment2 } from "react/jsx-dev-runtime";
2178
- function Overlays() {
2179
- return /* @__PURE__ */ jsxDEV22(Fragment2, {
2180
- children: /* @__PURE__ */ jsxDEV22(Slots, {
2181
- slotName: "overlay"
2182
- }, undefined, false, undefined, this)
2183
- }, undefined, false, undefined, this);
2184
- }
2185
- // src/components/slots/maps/text-inspector.tsx
2186
- import { jsxDEV as jsxDEV23 } from "react/jsx-dev-runtime";
2187
- function TextInspector({ blockId }) {
2188
- return /* @__PURE__ */ jsxDEV23("div", {
2189
- children: blockId
2190
- }, undefined, false, undefined, this);
2191
- }
2192
- // src/components/slots/maps/toolbar.tsx
2193
- import { cn as cn13 } from "cn";
2194
- import { useRef as useRef2, useMemo as useMemo3, useEffect as useEffect5, useState } from "react";
2195
-
2196
- // src/lib/selection.utils.ts
2197
- function rangeToOffsets(root, range) {
2198
- const measure = (node, offset) => {
2199
- const r = document.createRange();
2200
- r.selectNodeContents(root);
2201
- r.setEnd(node, offset);
2202
- return r.toString().length;
2203
- };
2204
- return {
2205
- start: measure(range.startContainer, range.startOffset),
2206
- end: measure(range.endContainer, range.endOffset)
2207
- };
2208
- }
2209
- function offsetsToRange(root, start, end) {
2210
- const range = document.createRange();
2211
- const walker = document.createTreeWalker(root, NodeFilter.SHOW_TEXT);
2212
- let pos = 0, startSet = false;
2213
- for (let n = walker.nextNode();n; n = walker.nextNode()) {
2214
- const next = pos + n.length;
2215
- if (!startSet && start <= next) {
2216
- range.setStart(n, start - pos);
2217
- startSet = true;
2218
- }
2219
- if (startSet && end <= next) {
2220
- range.setEnd(n, end - pos);
2221
- return range;
2222
- }
2223
- pos = next;
2224
- }
2225
- return null;
2226
- }
2227
- // src/hooks/custom/use-isomorphic-layout-effect.ts
2228
- import { useEffect as useEffect4, useLayoutEffect } from "react";
2229
- var useIsomorphicLayoutEffect = typeof window !== "undefined" ? useLayoutEffect : useEffect4;
2230
- // src/components/slots/maps/toolbar.tsx
2231
- import { jsxDEV as jsxDEV24 } from "react/jsx-dev-runtime";
2232
- var TOOLBAR_OFFSET = 44;
2233
- var DEFAULT_STATE = { active: false, top: 0, left: 0 };
2234
- function Toolbar({ className, children, ...rest }) {
2235
- const items = useSlots("toolbar");
2236
- const ui = useUIContext();
2237
- const [toolbarWidth, setToolbarWidth] = useState(0);
2238
- const length = items.reduce((prev, c) => {
2239
- if (c.when?.(ui)) {
2240
- return prev + 1;
2241
- }
2242
- return prev;
2243
- }, 0);
2244
- const textSel = useSlice("textSelection");
2245
- const currentBlockId = textSel?.blockId;
2246
- const selection = useSlice("selection");
2247
- const lastPositionRef = useRef2(DEFAULT_STATE);
2248
- const toolbarRef = useRef2(null);
2249
- useIsomorphicLayoutEffect(() => {
2250
- const toolbarElement = toolbarRef.current;
2251
- if (!toolbarElement)
2252
- return;
2253
- const updateToolbarWidth = () => {
2254
- setToolbarWidth(toolbarElement.getBoundingClientRect().width);
2255
- };
2256
- updateToolbarWidth();
2257
- const resizeObserver = new ResizeObserver(updateToolbarWidth);
2258
- resizeObserver.observe(toolbarElement);
2259
- return () => resizeObserver.disconnect();
2260
- }, []);
2261
- const position = useMemo3(() => {
2262
- const toolbarElement = toolbarRef.current;
2263
- if (!toolbarElement || toolbarWidth === 0) {
2264
- return DEFAULT_STATE;
2265
- }
2266
- if (textSel && currentBlockId && textSel.start !== textSel.end) {
2267
- const el = document.getElementById(textSel.blockId);
2268
- const range = el ? offsetsToRange(el, textSel.start, textSel.end) : null;
2269
- if (range) {
2270
- const selRect = range.getBoundingClientRect();
2271
- return {
2272
- active: true,
2273
- top: selRect.top - TOOLBAR_OFFSET,
2274
- left: selRect.left + (selRect.width - toolbarWidth) / 2
2275
- };
2276
- }
2277
- }
2278
- const rects = Array.from(selection?.blocks?.values() ?? []);
2279
- if (rects.length > 0) {
2280
- const top = Math.min(...rects.map((rect) => rect.top));
2281
- const left = Math.min(...rects.map((rect) => rect.left));
2282
- const right = Math.max(...rects.map((rect) => rect.right));
2283
- return {
2284
- active: true,
2285
- top: top - TOOLBAR_OFFSET,
2286
- left: (left + right) / 2 - toolbarWidth / 2
2287
- };
2288
- }
2289
- return DEFAULT_STATE;
2290
- }, [currentBlockId, textSel, selection, toolbarWidth]);
2291
- useEffect5(() => {
2292
- if (position.active) {
2293
- lastPositionRef.current = position;
2278
+ // src/hooks/use-slots.ts
2279
+ import { useSyncExternalStore as useSyncExternalStore3 } from "react";
2280
+ function useSlots(slotName) {
2281
+ const engine = useEngine();
2282
+ const items = useSyncExternalStore3((fn) => engine.ui.subscribe(slotName, fn), () => engine.ui.getSlots(slotName), () => engine.ui.getSlots(slotName));
2283
+ return items;
2284
+ }
2285
+
2286
+ // src/hooks/use-registry.ts
2287
+ import { useSyncExternalStore as useSyncExternalStore4 } from "react";
2288
+ function useRegistryComponent(name) {
2289
+ return useSyncExternalStore4((fn) => SlotsComponentRegistry.subscribe(name, fn), () => SlotsComponentRegistry.get(name), () => SlotsComponentRegistry.get(name));
2290
+ }
2291
+
2292
+ // src/components/slots/slot-button.tsx
2293
+ import React12 from "react";
2294
+ function SlotButton({ c, ui }) {
2295
+ const Comp = useRegistryComponent(c.name);
2296
+ if (!Comp) {
2297
+ console.warn(`No component registered for slot key "${c.name}"`);
2298
+ return null;
2299
+ }
2300
+ return React12.createElement(Comp, {
2301
+ c,
2302
+ ui,
2303
+ ...{
2304
+ "data-slot-type": "slot-button"
2294
2305
  }
2295
- }, [position]);
2296
- const _position = position.active ? position : lastPositionRef.current;
2297
- return /* @__PURE__ */ jsxDEV24("div", {
2298
- ref: toolbarRef,
2299
- style: {
2300
- top: _position.top,
2301
- left: _position.left
2302
- },
2303
- className: cn13("fixed top-0 left-0 gap-1 flex items-center transition-all bg-popover p-1 rounded-[12px] border", className, {
2304
- "opacity-0 pointer-events-none": !position.active || !length
2305
- }),
2306
- ...rest,
2307
- children: [
2308
- /* @__PURE__ */ jsxDEV24(Slots, {
2309
- slotName: "toolbar"
2310
- }, undefined, false, undefined, this),
2311
- children
2312
- ]
2313
- }, undefined, true, undefined, this);
2306
+ });
2314
2307
  }
2315
2308
 
2316
- // src/components/slots/maps/index.ts
2317
- "use client";
2309
+ // src/components/slots/slot-component.tsx
2310
+ import { createElement as createElement2 } from "react";
2311
+ function SlotComponent({ c, ui }) {
2312
+ const Comp = useRegistryComponent(c.name);
2313
+ if (!Comp) {
2314
+ console.warn(`No component registered for slot key "${c.name}"`);
2315
+ return null;
2316
+ }
2317
+ const props = c.getProps(ui);
2318
+ if (!props)
2319
+ return null;
2320
+ return createElement2(Comp, { ui, c });
2321
+ }
2322
+
2323
+ // src/components/slots/slots.tsx
2324
+ import { jsxDEV as jsxDEV24, Fragment } from "react/jsx-dev-runtime";
2325
+ function Slots({ slotName }) {
2326
+ const items = useSlots(slotName);
2327
+ const ui = useUIContext();
2328
+ return /* @__PURE__ */ jsxDEV24(Fragment, {
2329
+ children: items.map((c) => /* @__PURE__ */ jsxDEV24(SlotItem, {
2330
+ c,
2331
+ ui
2332
+ }, c.id, false, undefined, this))
2333
+ }, undefined, false, undefined, this);
2334
+ }
2335
+ function SlotItem({ c, ui }) {
2336
+ if (c.when && !c.when(ui))
2337
+ return null;
2338
+ switch (c.kind) {
2339
+ case "button":
2340
+ return /* @__PURE__ */ jsxDEV24(SlotButton, {
2341
+ c,
2342
+ ui
2343
+ }, undefined, false, undefined, this);
2344
+ case "component":
2345
+ return /* @__PURE__ */ jsxDEV24(SlotComponent, {
2346
+ c,
2347
+ ui
2348
+ }, undefined, false, undefined, this);
2349
+ }
2350
+ }
2351
+
2352
+ // src/components/slots/maps/block-actions.tsx
2353
+ import { cn as cn14 } from "cn";
2354
+ import { isEditableField } from "@coorax/core";
2355
+
2318
2356
  // src/components/corax-flow.tsx
2319
- import { useEffect as useEffect10, useReducer } from "react";
2357
+ import { useSyncExternalStore as useSyncExternalStore5 } from "react";
2320
2358
 
2321
2359
  // src/hooks/use-renderer.ts
2322
- import { useMemo as useMemo4 } from "react";
2360
+ import { useMemo as useMemo2 } from "react";
2323
2361
  import { ReactRenderer } from "@coorax/render-react";
2324
2362
  import { UTILS as UTILS2 } from "@coorax/core";
2325
2363
 
2326
2364
  // src/lifecycle/fields/handlers.registry.ts
2327
- import { GenericRegistry as GenericRegistry4 } from "@coorax/render-react";
2365
+ import { GenericRegistry as GenericRegistry5 } from "@coorax/render-react";
2328
2366
 
2329
2367
  // src/lifecycle/fields/common/focus.events/onblur.ts
2330
2368
  var createOnBlur = async (engine, block, ev) => {
@@ -2356,10 +2394,10 @@ var createOnClick = async (engine, block, ev) => {
2356
2394
  if (!fieldInfo)
2357
2395
  return;
2358
2396
  const isOnControl = ev.ctrlKey || ev.metaKey;
2359
- const selection = engine.state.get("selection");
2360
- if (!selection)
2397
+ const selection2 = engine.state.get("selection");
2398
+ if (!selection2)
2361
2399
  return;
2362
- const keys = Array.from(selection.blocks.keys());
2400
+ const keys = Array.from(selection2.blocks.keys());
2363
2401
  const blockRect = blockRectFromBlockId(block.id);
2364
2402
  if (!blockRect)
2365
2403
  return;
@@ -2411,8 +2449,8 @@ var createOnMouseEnter = async (engine, block, ev) => {
2411
2449
  const fieldInfo = getFieldTypeAndTargetId(engine, ev, block);
2412
2450
  if (!fieldInfo)
2413
2451
  return;
2414
- const selection = engine.state.get("selection");
2415
- if (selection && selection.blocks.has(block.id)) {
2452
+ const selection2 = engine.state.get("selection");
2453
+ if (selection2 && selection2.blocks.has(block.id)) {
2416
2454
  return;
2417
2455
  }
2418
2456
  const rect = blockRectFromBlockId(block.id);
@@ -2653,10 +2691,16 @@ var createOnLoad = async (engine, block, ev) => {
2653
2691
  const fieldInfo = getFieldTypeAndTargetId(engine, ev, block);
2654
2692
  if (!fieldInfo || !block.props?.src?.trim())
2655
2693
  return;
2694
+ const img = ev?.target;
2695
+ const intrinsic = img?.naturalWidth && img?.naturalHeight ? {
2696
+ "props.intrinsicWidth": img.naturalWidth,
2697
+ "props.intrinsicHeight": img.naturalHeight
2698
+ } : {};
2656
2699
  engine.document.apply((tree) => engine.mutations.mutateField(tree, {
2657
2700
  id: block.id,
2658
2701
  keyValuePairs: {
2659
- "props.isLoaded": true
2702
+ "props.isLoaded": true,
2703
+ ...intrinsic
2660
2704
  }
2661
2705
  }), { origin: "history" });
2662
2706
  engine.commands.tryExecute("blocks.select", {
@@ -2761,10 +2805,16 @@ var createVideoOnCanPlayThrough = async (engine, block, ev) => {
2761
2805
  const fieldInfo = getFieldTypeAndTargetId(engine, ev, block);
2762
2806
  if (!fieldInfo || !block.props?.src?.trim())
2763
2807
  return;
2808
+ const video = ev?.target;
2809
+ const intrinsic = video?.videoWidth && video?.videoHeight ? {
2810
+ "props.intrinsicWidth": video.videoWidth,
2811
+ "props.intrinsicHeight": video.videoHeight
2812
+ } : {};
2764
2813
  engine.document.apply((tree) => engine.mutations.mutateField(tree, {
2765
2814
  id: block.id,
2766
2815
  keyValuePairs: {
2767
- "props.isLoaded": true
2816
+ "props.isLoaded": true,
2817
+ ...intrinsic
2768
2818
  }
2769
2819
  }), { origin: "history" });
2770
2820
  engine.commands.tryExecute("blocks.select", {
@@ -2786,7 +2836,7 @@ var createVideoOnDoubleClick = async (engine, block, ev) => {
2786
2836
  keyValuePairs: {
2787
2837
  "props.controls": !field.props.controls
2788
2838
  }
2789
- }));
2839
+ }), { shouldEmitEvent: false });
2790
2840
  await fieldInfo.emit();
2791
2841
  };
2792
2842
 
@@ -2825,10 +2875,11 @@ function buildIFrameHandlers(engine, block) {
2825
2875
  }
2826
2876
 
2827
2877
  // src/lifecycle/fields/handlers.registry.ts
2828
- class FieldHandlersRegistry extends GenericRegistry4 {
2878
+ class FieldHandlersRegistry extends GenericRegistry5 {
2829
2879
  }
2830
2880
  var FieldHandlers = new FieldHandlersRegistry;
2831
2881
  FieldHandlers.register("h1", buildEditableHandlers);
2882
+ FieldHandlers.register("h2", buildEditableHandlers);
2832
2883
  FieldHandlers.register("p", buildEditableHandlers);
2833
2884
  FieldHandlers.register("blockquote", buildEditableHandlers);
2834
2885
  FieldHandlers.register("figcaption", buildEditableHandlers);
@@ -2849,10 +2900,10 @@ function forField(engine, block) {
2849
2900
  }
2850
2901
  var FLC = { forField };
2851
2902
  // src/primitives/fields/field.primitives.tsx
2852
- import { useCallback, useEffect as useEffect6, useRef as useRef3 } from "react";
2903
+ import { useCallback, useEffect as useEffect8, useRef } from "react";
2853
2904
  import { jsxDEV as jsxDEV25 } from "react/jsx-dev-runtime";
2854
2905
  function FieldPrimitive({ blockId }) {
2855
- const blockRef = useRef3(null);
2906
+ const blockRef = useRef(null);
2856
2907
  const engine = useEngine();
2857
2908
  const renderer = useRenderer();
2858
2909
  const block = useBlock(blockId);
@@ -2894,14 +2945,14 @@ function FieldPrimitive({ blockId }) {
2894
2945
  domSel.removeAllRanges();
2895
2946
  domSel.addRange(range);
2896
2947
  });
2897
- useEffect6(() => {
2948
+ useEffect8(() => {
2898
2949
  const domEl = blockRef.current;
2899
2950
  if (!domEl)
2900
2951
  return;
2901
2952
  const publishBlockRect = () => {
2902
2953
  const hover = engine.state.get("hover");
2903
2954
  const focus = engine.state.get("focus");
2904
- const selection = engine.state.get("selection")?.blocks;
2955
+ const selection2 = engine.state.get("selection")?.blocks;
2905
2956
  const rect = blockRectFromBlockId(blockId);
2906
2957
  if (!rect || !engine.document.get().order.size)
2907
2958
  return;
@@ -2911,10 +2962,10 @@ function FieldPrimitive({ blockId }) {
2911
2962
  if (hover?.id === blockId) {
2912
2963
  engine.commands.tryExecute("blocks.hover", { id: blockId, rect });
2913
2964
  }
2914
- if (selection?.has(blockId)) {
2965
+ if (selection2?.has(blockId)) {
2915
2966
  engine.commands.tryExecute("blocks.select", {
2916
- blocks: new Map().set(blockId, rect),
2917
- mode: "add"
2967
+ blocks: new Map(selection2.entries()).set(blockId, rect),
2968
+ mode: "replace"
2918
2969
  });
2919
2970
  }
2920
2971
  };
@@ -2929,6 +2980,7 @@ function FieldPrimitive({ blockId }) {
2929
2980
  return null;
2930
2981
  return /* @__PURE__ */ jsxDEV25("div", {
2931
2982
  ref: blockRef,
2983
+ className: "w-full flex max-w-full items-center justify-center",
2932
2984
  children: renderer.renderField(block)
2933
2985
  }, undefined, false, undefined, this);
2934
2986
  }
@@ -2941,26 +2993,26 @@ var FieldsPrimitives = {
2941
2993
  // src/hooks/use-renderer.ts
2942
2994
  function useRenderer() {
2943
2995
  const engine = useEngine();
2944
- return useMemo4(() => {
2996
+ return useMemo2(() => {
2945
2997
  const ctx = {
2946
2998
  mode: "edit",
2947
2999
  styles: (type) => engine.ui.getStyle(type),
2948
3000
  events: (block) => FLC.forField(engine, block)
2949
3001
  };
2950
3002
  const renderer = new ReactRenderer(ctx, engine.document);
2951
- for (const [variant, comp] of UTILS2.ObjectEntries(FieldsPrimitives)) {
2952
- if (comp)
2953
- renderer.primitives.post(variant, comp);
3003
+ for (const [variant, comp2] of UTILS2.ObjectEntries(FieldsPrimitives)) {
3004
+ if (comp2)
3005
+ renderer.primitives.post(variant, comp2);
2954
3006
  }
2955
3007
  return renderer;
2956
3008
  }, [engine]);
2957
3009
  }
2958
3010
 
2959
3011
  // src/hooks/use-flow.ts
2960
- import { useEffect as useEffect8 } from "react";
3012
+ import { useEffect as useEffect10 } from "react";
2961
3013
 
2962
3014
  // src/hooks/custom/use-custom-ref.ts
2963
- import { useEffect as useEffect7, useRef as useRef4 } from "react";
3015
+ import { useEffect as useEffect9, useRef as useRef2 } from "react";
2964
3016
  function useCustomRef(factory) {
2965
3017
  const isServer = typeof window === "undefined";
2966
3018
  const getInitialValue = () => {
@@ -2972,8 +3024,8 @@ function useCustomRef(factory) {
2972
3024
  return null;
2973
3025
  }
2974
3026
  };
2975
- const ref = useRef4(getInitialValue());
2976
- useEffect7(() => {
3027
+ const ref = useRef2(getInitialValue());
3028
+ useEffect9(() => {
2977
3029
  try {
2978
3030
  ref.current = typeof factory === "function" ? factory() : factory;
2979
3031
  } catch {}
@@ -3012,7 +3064,7 @@ function useFlow() {
3012
3064
  engine.commands.tryExecute("editor.rect", { editorRect: editorRectFromDomElement(flowEditor) });
3013
3065
  return flowEditor;
3014
3066
  });
3015
- useEffect8(() => {
3067
+ useEffect10(() => {
3016
3068
  function handleKeyDown(ev) {
3017
3069
  if (!ev.ctrlKey || ev.key.toLocaleLowerCase() !== "z")
3018
3070
  return;
@@ -3038,7 +3090,7 @@ function useFlow() {
3038
3090
  }
3039
3091
  };
3040
3092
  }, [engine, coraxFlowEditorRef]);
3041
- useEffect8(() => {
3093
+ useEffect10(() => {
3042
3094
  const element = coraxFlowEditorRef.current;
3043
3095
  if (!element)
3044
3096
  return;
@@ -3053,7 +3105,7 @@ function useFlow() {
3053
3105
  element.removeEventListener("scroll", publishEditorRect);
3054
3106
  };
3055
3107
  }, [engine, coraxFlowEditorRef]);
3056
- useEffect8(() => {
3108
+ useEffect10(() => {
3057
3109
  const element = coraxFlowEditorRef.current;
3058
3110
  if (!element)
3059
3111
  return;
@@ -3068,9 +3120,9 @@ function useFlow() {
3068
3120
  }
3069
3121
 
3070
3122
  // src/hooks/use-text-input.ts
3071
- import { useEffect as useEffect9 } from "react";
3123
+ import { useEffect as useEffect11 } from "react";
3072
3124
  function useTextInput(engine) {
3073
- useEffect9(() => {
3125
+ useEffect11(() => {
3074
3126
  let composing = false;
3075
3127
  const rootOf = (t) => ((t instanceof Element ? t : t?.parentElement) ?? null)?.closest("[data-text-path]") ?? null;
3076
3128
  const onBeforeInput = (e) => {
@@ -3145,44 +3197,265 @@ function useTextInput(engine) {
3145
3197
  }
3146
3198
 
3147
3199
  // src/components/corax-flow.tsx
3148
- import { cn as cn14 } from "cn";
3149
- import { jsxDEV as jsxDEV26 } from "react/jsx-dev-runtime";
3200
+ import { cn as cn13 } from "cn";
3201
+ import { jsxDEV as jsxDEV26, Fragment as Fragment2 } from "react/jsx-dev-runtime";
3150
3202
  "use client";
3203
+ var IMAGE_BREAKOUT_GUTTER = 150;
3204
+ function CoraxBlocks() {
3205
+ const engine = useEngine();
3206
+ const renderer = useRenderer();
3207
+ const order = useSyncExternalStore5((onStoreChange) => engine.state.subscribe("document", onStoreChange), () => engine.document.get().order, () => engine.document.get().order);
3208
+ return /* @__PURE__ */ jsxDEV26(Fragment2, {
3209
+ children: [...order].map((id) => {
3210
+ const block = engine.document.getBlock(id);
3211
+ if (!block)
3212
+ return null;
3213
+ const Comp = renderer.primitives.get(block.variant);
3214
+ if (!Comp)
3215
+ return null;
3216
+ return /* @__PURE__ */ jsxDEV26(Comp, {
3217
+ blockId: id
3218
+ }, id, false, undefined, this);
3219
+ })
3220
+ }, undefined, false, undefined, this);
3221
+ }
3151
3222
  function CoraxFlow({
3152
3223
  children,
3153
3224
  className
3154
3225
  }) {
3155
- const [count, forceUpdate] = useReducer((x) => x + 1, 0);
3156
3226
  const engine = useEngine();
3157
- const renderer = useRenderer();
3158
3227
  useFlow();
3159
3228
  useTextInput(engine);
3160
- useEffect10(() => {
3161
- const disposers = [
3162
- engine.events.on("document:changed", ({ value }) => {
3163
- const { diff } = value;
3164
- if (diff.added.size || diff.removed.size || diff.orderChanged)
3165
- forceUpdate();
3166
- })
3167
- ];
3168
- return () => disposers.forEach((dispose) => dispose());
3169
- }, [engine]);
3170
3229
  return /* @__PURE__ */ jsxDEV26("div", {
3171
3230
  id: "corax_flow_editor",
3172
- className: "relative flex flex-col max-w-full w-200 h-full",
3231
+ className: "relative flex flex-col max-w-full w-275 h-full",
3173
3232
  children: /* @__PURE__ */ jsxDEV26("div", {
3174
3233
  id: "corax_flow_blocks_container",
3175
- className: cn14("relative w-full h-full flex flex-col overflow-auto scrollbar-none pl-10 gap-1", className),
3234
+ className: cn13("relative w-full h-full flex flex-col items-center scrollbar-none gap-1", className),
3235
+ style: {
3236
+ overflowX: "hidden",
3237
+ overflowY: "auto",
3238
+ paddingInline: IMAGE_BREAKOUT_GUTTER
3239
+ },
3176
3240
  children: [
3177
- renderer.renderTree(count),
3241
+ /* @__PURE__ */ jsxDEV26(CoraxBlocks, {}, undefined, false, undefined, this),
3178
3242
  children
3179
3243
  ]
3180
3244
  }, undefined, true, undefined, this)
3181
3245
  }, undefined, false, undefined, this);
3182
3246
  }
3183
3247
 
3248
+ // src/components/slots/maps/block-actions.tsx
3249
+ import { jsxDEV as jsxDEV27 } from "react/jsx-dev-runtime";
3250
+ function BlockActions({ className, children, ...rest }) {
3251
+ const focusMemo = useSlice("focus_memory");
3252
+ const focus = focusMemo?.blocks?.[0];
3253
+ const items = useSlots("block-actions");
3254
+ const lastPositionRef = useRef3({ active: false, top: 0, left: 0 });
3255
+ const block = useBlock(focus?.id ?? "");
3256
+ const isOpened = !!useSlice("insertion");
3257
+ const position = useMemo3(() => {
3258
+ if (!focus || !block || !isEditableField(block) || block.type === "caption") {
3259
+ return { active: false, top: 0, left: 0 };
3260
+ }
3261
+ const hasContent = !!block.props.children.text.length;
3262
+ if (hasContent) {
3263
+ return { active: false, top: 0, left: 0 };
3264
+ }
3265
+ const { id: firstSelectionId, rect: blockRect } = focus;
3266
+ const container = document.getElementById("corax_flow_blocks_container");
3267
+ if (!container)
3268
+ return { active: false, top: 0, left: 0 };
3269
+ const containerRect = container.getBoundingClientRect();
3270
+ const domElement = document.getElementById(firstSelectionId);
3271
+ if (!domElement)
3272
+ return { active: false, top: 0, left: 0 };
3273
+ const heightDiff = 36 - blockRect.height;
3274
+ const toSubstract = heightDiff / 2;
3275
+ const top = blockRect.top - (-toSubstract > 32 ? -8 : toSubstract) - containerRect.top - container.clientTop + blockRect.parentScrollTop;
3276
+ return {
3277
+ active: true,
3278
+ top,
3279
+ left: IMAGE_BREAKOUT_GUTTER - 44
3280
+ };
3281
+ }, [focus, block]);
3282
+ useEffect12(() => {
3283
+ if (position.active) {
3284
+ lastPositionRef.current = position;
3285
+ }
3286
+ }, [position]);
3287
+ const _position = position.active ? position : lastPositionRef.current;
3288
+ return /* @__PURE__ */ jsxDEV27("div", {
3289
+ style: {
3290
+ top: _position.top,
3291
+ left: _position.left
3292
+ },
3293
+ className: cn14("absolute top-0 left-0 gap-1 z-10 flex items-center transition-opacity", className, {
3294
+ "opacity-0 pointer-events-none": !position.active || !focus
3295
+ }),
3296
+ ...rest,
3297
+ children: [
3298
+ /* @__PURE__ */ jsxDEV27(Slots, {
3299
+ slotName: "block-actions"
3300
+ }, undefined, false, undefined, this),
3301
+ /* @__PURE__ */ jsxDEV27("div", {
3302
+ style: {
3303
+ width: isOpened ? (items.length - 1) * 32 + 8 : 0
3304
+ },
3305
+ className: cn14("absolute h-9.5 -z-1 left-9 bg-popover border rounded-full transition-all duration-300 ease-damping", {
3306
+ "opacity-0 pointer-events-none": !isOpened
3307
+ })
3308
+ }, undefined, false, undefined, this),
3309
+ children
3310
+ ]
3311
+ }, undefined, true, undefined, this);
3312
+ }
3313
+ // src/components/slots/maps/overlays.tsx
3314
+ import { jsxDEV as jsxDEV28, Fragment as Fragment3 } from "react/jsx-dev-runtime";
3315
+ function Overlays() {
3316
+ return /* @__PURE__ */ jsxDEV28(Fragment3, {
3317
+ children: /* @__PURE__ */ jsxDEV28(Slots, {
3318
+ slotName: "overlay"
3319
+ }, undefined, false, undefined, this)
3320
+ }, undefined, false, undefined, this);
3321
+ }
3322
+ // src/components/slots/maps/text-inspector.tsx
3323
+ import { jsxDEV as jsxDEV29 } from "react/jsx-dev-runtime";
3324
+ function TextInspector({ blockId }) {
3325
+ return /* @__PURE__ */ jsxDEV29("div", {
3326
+ children: blockId
3327
+ }, undefined, false, undefined, this);
3328
+ }
3329
+ // src/components/slots/maps/toolbar.tsx
3330
+ import { cn as cn15 } from "cn";
3331
+ import { useEffect as useEffect13, useReducer, useRef as useRef4, useState as useState5 } from "react";
3332
+ import { jsxDEV as jsxDEV30 } from "react/jsx-dev-runtime";
3333
+ var TOOLBAR_OFFSET = 44;
3334
+ var TOOLBAR_MARGIN = -44;
3335
+ var DEFAULT_STATE = { active: false, top: 0, left: 0 };
3336
+ function Toolbar({ className, children, ...rest }) {
3337
+ const items = useSlots("toolbar");
3338
+ const ui = useUIContext();
3339
+ const [toolbarWidth, setToolbarWidth] = useState5(0);
3340
+ const [toolbarHeight, setToolbarHeight] = useState5(0);
3341
+ const [, bumpViewport] = useReducer((x) => x + 1, 0);
3342
+ const length = items.reduce((prev, c) => {
3343
+ if (c.when?.(ui)) {
3344
+ return prev + 1;
3345
+ }
3346
+ return prev;
3347
+ }, 0);
3348
+ const textSel = useSlice("textSelection");
3349
+ const currentBlockId = textSel?.blockId;
3350
+ const selection2 = useSlice("selection");
3351
+ const lastPositionRef = useRef4(DEFAULT_STATE);
3352
+ const toolbarRef = useRef4(null);
3353
+ const frameRef = useRef4(0);
3354
+ useIsomorphicLayoutEffect(() => {
3355
+ const toolbarElement = toolbarRef.current;
3356
+ if (!toolbarElement)
3357
+ return;
3358
+ const updateToolbarSize = () => {
3359
+ const rect = toolbarElement.getBoundingClientRect();
3360
+ setToolbarWidth(rect.width);
3361
+ setToolbarHeight(rect.height);
3362
+ };
3363
+ updateToolbarSize();
3364
+ const resizeObserver = new ResizeObserver(updateToolbarSize);
3365
+ resizeObserver.observe(toolbarElement);
3366
+ return () => resizeObserver.disconnect();
3367
+ }, []);
3368
+ useEffect13(() => {
3369
+ const container = document.getElementById("corax_flow_blocks_container");
3370
+ const onViewportChange = () => {
3371
+ if (frameRef.current)
3372
+ return;
3373
+ frameRef.current = requestAnimationFrame(() => {
3374
+ frameRef.current = 0;
3375
+ bumpViewport();
3376
+ });
3377
+ };
3378
+ container?.addEventListener("scroll", onViewportChange, { passive: true });
3379
+ window.addEventListener("scroll", onViewportChange, { passive: true });
3380
+ window.addEventListener("resize", onViewportChange);
3381
+ return () => {
3382
+ if (frameRef.current)
3383
+ cancelAnimationFrame(frameRef.current);
3384
+ container?.removeEventListener("scroll", onViewportChange);
3385
+ window.removeEventListener("scroll", onViewportChange);
3386
+ window.removeEventListener("resize", onViewportChange);
3387
+ };
3388
+ }, []);
3389
+ const computePosition = () => {
3390
+ const toolbarElement = toolbarRef.current;
3391
+ if (!toolbarElement || toolbarWidth === 0) {
3392
+ return DEFAULT_STATE;
3393
+ }
3394
+ const container = document.getElementById("corax_flow_blocks_container");
3395
+ const containerRect = container?.getBoundingClientRect();
3396
+ const clampTop = (top) => {
3397
+ if (!containerRect)
3398
+ return top;
3399
+ const min = containerRect.top + TOOLBAR_MARGIN;
3400
+ const max = containerRect.bottom - TOOLBAR_MARGIN - toolbarHeight;
3401
+ return Math.min(Math.max(top, min), Math.max(min, max));
3402
+ };
3403
+ if (textSel && currentBlockId && textSel.start !== textSel.end) {
3404
+ const el = document.getElementById(textSel.blockId);
3405
+ const range = el ? offsetsToRange(el, textSel.start, textSel.end) : null;
3406
+ if (range) {
3407
+ const selRect = range.getBoundingClientRect();
3408
+ return {
3409
+ active: true,
3410
+ top: clampTop(selRect.top - TOOLBAR_OFFSET),
3411
+ left: selRect.left + (selRect.width - toolbarWidth) / 2
3412
+ };
3413
+ }
3414
+ }
3415
+ const rects = Array.from(selection2?.blocks?.keys() ?? []).map((id) => blockRectFromBlockId(id)).filter((rect) => !!rect);
3416
+ if (rects.length > 0) {
3417
+ const top = Math.min(...rects.map((rect) => rect.top));
3418
+ const left = Math.min(...rects.map((rect) => rect.left));
3419
+ const right = Math.max(...rects.map((rect) => rect.right));
3420
+ return {
3421
+ active: true,
3422
+ top: clampTop(top - TOOLBAR_OFFSET),
3423
+ left: (left + right) / 2 - toolbarWidth / 2
3424
+ };
3425
+ }
3426
+ return DEFAULT_STATE;
3427
+ };
3428
+ const position = computePosition();
3429
+ useEffect13(() => {
3430
+ if (position.active) {
3431
+ lastPositionRef.current = position;
3432
+ }
3433
+ }, [position]);
3434
+ const _position = position.active ? position : lastPositionRef.current;
3435
+ return /* @__PURE__ */ jsxDEV30("div", {
3436
+ ref: toolbarRef,
3437
+ style: {
3438
+ top: _position.top,
3439
+ left: _position.left
3440
+ },
3441
+ className: cn15("fixed top-0 left-0 gap-1 flex items-center transition-opacity bg-popover p-1 rounded-[12px] border", className, {
3442
+ "opacity-0 pointer-events-none": !position.active || !length
3443
+ }),
3444
+ ...rest,
3445
+ children: [
3446
+ /* @__PURE__ */ jsxDEV30(Slots, {
3447
+ slotName: "toolbar"
3448
+ }, undefined, false, undefined, this),
3449
+ children
3450
+ ]
3451
+ }, undefined, true, undefined, this);
3452
+ }
3453
+
3454
+ // src/components/slots/maps/index.ts
3455
+ "use client";
3184
3456
  // src/components/index.ts
3185
3457
  "use client";
3458
+
3186
3459
  // src/index.ts
3187
3460
  export * from "@coorax/core";
3188
3461
  export * from "@coorax/render-react";
@@ -3209,6 +3482,7 @@ export {
3209
3482
  PrimitivesComponentsRegistry,
3210
3483
  Overlays,
3211
3484
  LocalDB,
3485
+ IMAGE_BREAKOUT_GUTTER,
3212
3486
  GenericRegistry3 as GenericRegistry,
3213
3487
  FieldHandlersRegistry,
3214
3488
  FieldHandlers,
@@ -3216,6 +3490,7 @@ export {
3216
3490
  FallbackComponentsRegistry,
3217
3491
  FLC,
3218
3492
  ErrorComponentsRegistry,
3493
+ CoraxIconsRegistry,
3219
3494
  CoraxIcon,
3220
3495
  CoraxFlow,
3221
3496
  CoraxEngineProvider,