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

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.
Files changed (30) hide show
  1. package/dist/components/corax-context-provider.d.ts +5 -0
  2. package/dist/components/corax-flow.d.ts +2 -0
  3. package/dist/components/slots/buttons/divider-style-button.d.ts +3 -0
  4. package/dist/components/slots/buttons/divider-width-button.d.ts +3 -0
  5. package/dist/components/slots/buttons/iframe-playback-button.d.ts +3 -0
  6. package/dist/components/slots/buttons/image-width-button.d.ts +3 -0
  7. package/dist/components/slots/buttons/paragraph-theme-button.d.ts +3 -0
  8. package/dist/index.js +784 -482
  9. package/dist/lib/comp.utils.d.ts +5 -1
  10. package/dist/lifecycle/fields/editable/handlers.d.ts +1 -1
  11. package/dist/styles.css +1 -1
  12. package/package.json +6 -5
  13. package/dist/components/fallbacks/iframe,fallback.d.ts +0 -2
  14. package/dist/lifecycle/fields/focus.events/onbeforeinput.d.ts +0 -3
  15. package/dist/lifecycle/fields/focus.events/onblur.d.ts +0 -3
  16. package/dist/lifecycle/fields/focus.events/onfocus.d.ts +0 -3
  17. package/dist/lifecycle/fields/keyboard.events/onkeydown.d.ts +0 -3
  18. package/dist/lifecycle/fields/media/handlers.d.ts +0 -7
  19. package/dist/lifecycle/fields/media/keyboard.events/onkeydown.d.ts +0 -3
  20. package/dist/lifecycle/fields/media/synthetic.events/onload.d.ts +0 -3
  21. package/dist/lifecycle/fields/mouse.events/onclick.d.ts +0 -3
  22. package/dist/lifecycle/fields/mouse.events/ondoubleclick.d.ts +0 -4
  23. package/dist/lifecycle/fields/mouse.events/onmouseenter.d.ts +0 -3
  24. package/dist/lifecycle/fields/mouse.events/onmouseleave.d.ts +0 -3
  25. package/dist/lifecycle/fields/synthetic.events/onload.d.ts +0 -3
  26. package/dist/lifecycle/fields/synthetic.events/onselect.d.ts +0 -3
  27. package/dist/registry/errors.registry.d.ts +0 -8
  28. package/dist/registry/fallbacks.registry.d.ts +0 -9
  29. package/dist/registry/primitives.registry.d.ts +0 -22
  30. package/dist/registry/registry.d.ts +0 -15
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,101 +480,22 @@ 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";
379
-
380
- // src/lib/comp.utils.tsx
381
- 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
401
- } from "lucide-react";
402
-
403
- // src/components/commons/youtube.tsx
404
483
  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
484
 
424
485
  // src/lib/comp.utils.tsx
425
- import { jsxDEV as jsxDEV11 } from "react/jsx-dev-runtime";
486
+ import { GenericRegistry as GenericRegistry4 } from "@coorax/render-react";
487
+ import { createElement } from "react";
488
+ import { Pointer } from "lucide-react";
489
+ var CoraxIconsRegistry = new GenericRegistry4;
426
490
  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
- }
491
+ const Icon = CoraxIconsRegistry.get(icon) ?? Pointer;
492
+ return createElement(Icon);
469
493
  }
470
494
 
471
495
  // src/lifecycle/fields/lifecycle.utils.ts
472
- import { UTILS } from "@coorax/core";
496
+ import {
497
+ UTILS
498
+ } from "@coorax/core";
473
499
  function blockRectFromBlockId(id) {
474
500
  const domElement = document.getElementById(id);
475
501
  if (!domElement)
@@ -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,130 @@ 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 {
886
+ TextCursor,
887
+ PointerIcon,
888
+ HeadingIcon,
889
+ Heading2,
890
+ PlusIcon,
891
+ BoldIcon,
892
+ ItalicIcon,
893
+ UnderlineIcon,
894
+ LinkIcon,
895
+ ImagePlus,
896
+ TextInitialIcon,
897
+ Minus,
898
+ TvMinimalPlayIcon,
899
+ FileTextIcon,
900
+ QuoteIcon,
901
+ BracesIcon,
902
+ PaletteIcon,
903
+ Captions,
904
+ Trash2 as Trash25,
905
+ Play,
906
+ Pause,
907
+ MoveHorizontal,
908
+ Expand,
909
+ LineStyle,
910
+ OctagonExclamationPoint,
911
+ OctagonX,
912
+ InfoIcon,
913
+ CircleLetterI
914
+ } from "lucide-react";
915
+
916
+ // src/components/commons/youtube.tsx
917
+ import { cn as cn11 } from "cn";
918
+ import { jsxDEV as jsxDEV22 } from "react/jsx-dev-runtime";
919
+ function YoutubeIcon({ className, ...props }) {
920
+ return /* @__PURE__ */ jsxDEV22("svg", {
921
+ xmlns: "http://www.w3.org/2000/svg",
922
+ viewBox: "0 0 24 24",
923
+ fill: "none",
924
+ className: cn11("text-foreground", className),
925
+ ...props,
926
+ children: /* @__PURE__ */ jsxDEV22("path", {
927
+ fillRule: "evenodd",
928
+ clipRule: "evenodd",
929
+ 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",
930
+ stroke: "currentColor",
931
+ strokeLinejoin: "round",
932
+ strokeWidth: 2
933
+ }, undefined, false, undefined, this)
934
+ }, undefined, false, undefined, this);
935
+ }
936
+ // src/lib/selection.utils.ts
937
+ function rangeToOffsets(root, range) {
938
+ const measure = (node, offset) => {
939
+ const r = document.createRange();
940
+ r.selectNodeContents(root);
941
+ r.setEnd(node, offset);
942
+ return r.toString().length;
943
+ };
944
+ return {
945
+ start: measure(range.startContainer, range.startOffset),
946
+ end: measure(range.endContainer, range.endOffset)
947
+ };
948
+ }
949
+ function offsetsToRange(root, start, end) {
950
+ const range = document.createRange();
951
+ const walker = document.createTreeWalker(root, NodeFilter.SHOW_TEXT);
952
+ let pos = 0, startSet = false;
953
+ for (let n = walker.nextNode();n; n = walker.nextNode()) {
954
+ const next = pos + n.length;
955
+ if (!startSet && start <= next) {
956
+ range.setStart(n, start - pos);
957
+ startSet = true;
958
+ }
959
+ if (startSet && end <= next) {
960
+ range.setEnd(n, end - pos);
961
+ return range;
962
+ }
963
+ pos = next;
964
+ }
965
+ return null;
966
+ }
967
+ // src/components/slots/buttons/paragraph-theme-button.tsx
968
+ import {
969
+ getParagraphTheme
970
+ } from "@coorax/core";
971
+ import React11 from "react";
972
+ import { cn as cn12 } from "cn";
973
+ import { jsxDEV as jsxDEV23 } from "react/jsx-dev-runtime";
974
+ var ParagraphThemeButton = React11.memo(function ParagraphThemeButton2({
975
+ c,
976
+ ui,
977
+ ...rest
978
+ }) {
979
+ const engine = useEngine();
980
+ const { fieldId, theme } = c.getPayload(ui);
981
+ const block = useBlock(fieldId);
982
+ const isActive = !!block && getParagraphTheme(block.props.children) === theme;
983
+ const props = c.getProps(ui);
984
+ return /* @__PURE__ */ jsxDEV23(Button, {
985
+ ...rest,
986
+ onMouseDown: (ev) => ev.preventDefault(),
987
+ onClick: () => engine.commands.tryExecute(c.command, c.getPayload(ui)),
988
+ title: c.label ?? "Paragraph theme",
989
+ size: "icon-xs",
990
+ className: cn12("rounded-[8px] cursor-pointer", {
991
+ "bg-[#FF4D4F]/30": props.theme === "error" && !isActive,
992
+ "bg-[#FF9900]/30": props.theme === "warning" && !isActive,
993
+ "bg-[#007AFF]/30": props.theme === "info" && !isActive
994
+ }),
995
+ variant: isActive ? "default" : "secondary",
996
+ children: /* @__PURE__ */ jsxDEV23(CoraxIcon, {
997
+ icon: c.icon
998
+ }, undefined, false, undefined, this)
999
+ }, c.id, false, undefined, this);
1000
+ });
1001
+
741
1002
  // src/modules/slots.module.tsx
742
1003
  var SlotsModule = {
743
1004
  name: "slots",
@@ -749,9 +1010,43 @@ var SlotsModule = {
749
1010
  SlotsComponentRegistry.register("CodeThemeButton", CodeThemeButton);
750
1011
  SlotsComponentRegistry.register("CaptionButton", CaptionButton);
751
1012
  SlotsComponentRegistry.register("DeleteButton", DeleteButton);
1013
+ SlotsComponentRegistry.register("IframePlaybackButton", IframePlaybackButton);
1014
+ SlotsComponentRegistry.register("ImageWidthButton", ImageWidthButton);
1015
+ SlotsComponentRegistry.register("DividerWidthButton", DividerWidthButton);
1016
+ SlotsComponentRegistry.register("DividerStyleButton", DividerStyleButton);
1017
+ SlotsComponentRegistry.register("ParagraphThemeButton", ParagraphThemeButton);
752
1018
  SlotsComponentRegistry.register("SelectionOverlay", SelectionOverlay);
753
1019
  SlotsComponentRegistry.register("FocusOverlay", FocusOverlay);
754
1020
  SlotsComponentRegistry.register("HoverOverlay", HoverOverlay);
1021
+ CoraxIconsRegistry.register("TextIcon", TextCursor);
1022
+ CoraxIconsRegistry.register("CursorIcon", PointerIcon);
1023
+ CoraxIconsRegistry.register("HeadingIcon", HeadingIcon);
1024
+ CoraxIconsRegistry.register("Heading2Icon", Heading2);
1025
+ CoraxIconsRegistry.register("PlusIcon", PlusIcon);
1026
+ CoraxIconsRegistry.register("BoldIcon", BoldIcon);
1027
+ CoraxIconsRegistry.register("ItalicIcon", ItalicIcon);
1028
+ CoraxIconsRegistry.register("UnderlineIcon", UnderlineIcon);
1029
+ CoraxIconsRegistry.register("LinkIcon", LinkIcon);
1030
+ CoraxIconsRegistry.register("ImagePlus", ImagePlus);
1031
+ CoraxIconsRegistry.register("TextInitial", TextInitialIcon);
1032
+ CoraxIconsRegistry.register("DividerIcon", Minus);
1033
+ CoraxIconsRegistry.register("TvMinimalPlayIcon", TvMinimalPlayIcon);
1034
+ CoraxIconsRegistry.register("YoutubeIcon", YoutubeIcon);
1035
+ CoraxIconsRegistry.register("FileTextIcon", FileTextIcon);
1036
+ CoraxIconsRegistry.register("QuoteIcon", QuoteIcon);
1037
+ CoraxIconsRegistry.register("CodeIcon", BracesIcon);
1038
+ CoraxIconsRegistry.register("PaletteIcon", PaletteIcon);
1039
+ CoraxIconsRegistry.register("CaptionsIcon", Captions);
1040
+ CoraxIconsRegistry.register("TrashIcon", Trash25);
1041
+ CoraxIconsRegistry.register("PlayIcon", Play);
1042
+ CoraxIconsRegistry.register("PauseIcon", Pause);
1043
+ CoraxIconsRegistry.register("MoveHorizontalIcon", MoveHorizontal);
1044
+ CoraxIconsRegistry.register("ExpandIcon", Expand);
1045
+ CoraxIconsRegistry.register("LineStyleIcon", LineStyle);
1046
+ CoraxIconsRegistry.register("ThemeWarningIcon", OctagonExclamationPoint);
1047
+ CoraxIconsRegistry.register("ThemeErrorIcon", OctagonX);
1048
+ CoraxIconsRegistry.register("ThemeInfoIcon", InfoIcon);
1049
+ CoraxIconsRegistry.register("ThemeNeutralIcon", CircleLetterI);
755
1050
  }
756
1051
  };
757
1052
  // src/modules/autosave.module.ts
@@ -2007,324 +2302,96 @@ var AutoSaveModule = {
2007
2302
  }
2008
2303
  };
2009
2304
  // src/components/slots/maps/block-actions.tsx
2010
- import { useEffect as useEffect3, useMemo as useMemo2, useRef } from "react";
2305
+ import { useEffect as useEffect12, useMemo as useMemo3, useRef as useRef3 } from "react";
2011
2306
 
2012
2307
  // 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
2308
  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";
2103
-
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;
2309
+ function useSlots(slotName) {
2310
+ const engine = useEngine();
2311
+ const items = useSyncExternalStore3((fn) => engine.ui.subscribe(slotName, fn), () => engine.ui.getSlots(slotName), () => engine.ui.getSlots(slotName));
2312
+ return items;
2313
+ }
2314
+
2315
+ // src/hooks/use-registry.ts
2316
+ import { useSyncExternalStore as useSyncExternalStore4 } from "react";
2317
+ function useRegistryComponent(name) {
2318
+ return useSyncExternalStore4((fn) => SlotsComponentRegistry.subscribe(name, fn), () => SlotsComponentRegistry.get(name), () => SlotsComponentRegistry.get(name));
2319
+ }
2320
+
2321
+ // src/components/slots/slot-button.tsx
2322
+ import React12 from "react";
2323
+ function SlotButton({ c, ui }) {
2324
+ const Comp = useRegistryComponent(c.name);
2325
+ if (!Comp) {
2326
+ console.warn(`No component registered for slot key "${c.name}"`);
2327
+ return null;
2328
+ }
2329
+ return React12.createElement(Comp, {
2330
+ c,
2331
+ ui,
2332
+ ...{
2333
+ "data-slot-type": "slot-button"
2294
2334
  }
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);
2335
+ });
2314
2336
  }
2315
2337
 
2316
- // src/components/slots/maps/index.ts
2317
- "use client";
2338
+ // src/components/slots/slot-component.tsx
2339
+ import { createElement as createElement2 } from "react";
2340
+ function SlotComponent({ c, ui }) {
2341
+ const Comp = useRegistryComponent(c.name);
2342
+ if (!Comp) {
2343
+ console.warn(`No component registered for slot key "${c.name}"`);
2344
+ return null;
2345
+ }
2346
+ const props = c.getProps(ui);
2347
+ if (!props)
2348
+ return null;
2349
+ return createElement2(Comp, { ui, c });
2350
+ }
2351
+
2352
+ // src/components/slots/slots.tsx
2353
+ import { jsxDEV as jsxDEV24, Fragment } from "react/jsx-dev-runtime";
2354
+ function Slots({ slotName }) {
2355
+ const items = useSlots(slotName);
2356
+ const ui = useUIContext();
2357
+ return /* @__PURE__ */ jsxDEV24(Fragment, {
2358
+ children: items.map((c) => /* @__PURE__ */ jsxDEV24(SlotItem, {
2359
+ c,
2360
+ ui
2361
+ }, c.id, false, undefined, this))
2362
+ }, undefined, false, undefined, this);
2363
+ }
2364
+ function SlotItem({ c, ui }) {
2365
+ if (c.when && !c.when(ui))
2366
+ return null;
2367
+ switch (c.kind) {
2368
+ case "button":
2369
+ return /* @__PURE__ */ jsxDEV24(SlotButton, {
2370
+ c,
2371
+ ui
2372
+ }, undefined, false, undefined, this);
2373
+ case "component":
2374
+ return /* @__PURE__ */ jsxDEV24(SlotComponent, {
2375
+ c,
2376
+ ui
2377
+ }, undefined, false, undefined, this);
2378
+ }
2379
+ }
2380
+
2381
+ // src/components/slots/maps/block-actions.tsx
2382
+ import { cn as cn14 } from "cn";
2383
+ import { isEditableField } from "@coorax/core";
2384
+
2318
2385
  // src/components/corax-flow.tsx
2319
- import { useEffect as useEffect10, useReducer } from "react";
2386
+ import { useSyncExternalStore as useSyncExternalStore5 } from "react";
2320
2387
 
2321
2388
  // src/hooks/use-renderer.ts
2322
- import { useMemo as useMemo4 } from "react";
2389
+ import { useMemo as useMemo2 } from "react";
2323
2390
  import { ReactRenderer } from "@coorax/render-react";
2324
2391
  import { UTILS as UTILS2 } from "@coorax/core";
2325
2392
 
2326
2393
  // src/lifecycle/fields/handlers.registry.ts
2327
- import { GenericRegistry as GenericRegistry4 } from "@coorax/render-react";
2394
+ import { GenericRegistry as GenericRegistry5 } from "@coorax/render-react";
2328
2395
 
2329
2396
  // src/lifecycle/fields/common/focus.events/onblur.ts
2330
2397
  var createOnBlur = async (engine, block, ev) => {
@@ -2356,10 +2423,10 @@ var createOnClick = async (engine, block, ev) => {
2356
2423
  if (!fieldInfo)
2357
2424
  return;
2358
2425
  const isOnControl = ev.ctrlKey || ev.metaKey;
2359
- const selection = engine.state.get("selection");
2360
- if (!selection)
2426
+ const selection2 = engine.state.get("selection");
2427
+ if (!selection2)
2361
2428
  return;
2362
- const keys = Array.from(selection.blocks.keys());
2429
+ const keys = Array.from(selection2.blocks.keys());
2363
2430
  const blockRect = blockRectFromBlockId(block.id);
2364
2431
  if (!blockRect)
2365
2432
  return;
@@ -2411,8 +2478,8 @@ var createOnMouseEnter = async (engine, block, ev) => {
2411
2478
  const fieldInfo = getFieldTypeAndTargetId(engine, ev, block);
2412
2479
  if (!fieldInfo)
2413
2480
  return;
2414
- const selection = engine.state.get("selection");
2415
- if (selection && selection.blocks.has(block.id)) {
2481
+ const selection2 = engine.state.get("selection");
2482
+ if (selection2 && selection2.blocks.has(block.id)) {
2416
2483
  return;
2417
2484
  }
2418
2485
  const rect = blockRectFromBlockId(block.id);
@@ -2512,9 +2579,7 @@ function buildDividerHandlers(engine, block) {
2512
2579
  }
2513
2580
 
2514
2581
  // src/lifecycle/fields/editable/keyboard.events/onkeydown.ts
2515
- import {
2516
- FieldsUtils as FieldsUtils2
2517
- } from "@coorax/core";
2582
+ import { FieldsUtils as FieldsUtils2 } from "@coorax/core";
2518
2583
  var createOnKeyDown2 = async (engine, block, ev) => {
2519
2584
  const fieldInfo = getFieldTypeAndTargetId(engine, ev, block);
2520
2585
  if (!fieldInfo)
@@ -2653,10 +2718,16 @@ var createOnLoad = async (engine, block, ev) => {
2653
2718
  const fieldInfo = getFieldTypeAndTargetId(engine, ev, block);
2654
2719
  if (!fieldInfo || !block.props?.src?.trim())
2655
2720
  return;
2721
+ const img = ev?.target;
2722
+ const intrinsic = img?.naturalWidth && img?.naturalHeight ? {
2723
+ "props.intrinsicWidth": img.naturalWidth,
2724
+ "props.intrinsicHeight": img.naturalHeight
2725
+ } : {};
2656
2726
  engine.document.apply((tree) => engine.mutations.mutateField(tree, {
2657
2727
  id: block.id,
2658
2728
  keyValuePairs: {
2659
- "props.isLoaded": true
2729
+ "props.isLoaded": true,
2730
+ ...intrinsic
2660
2731
  }
2661
2732
  }), { origin: "history" });
2662
2733
  engine.commands.tryExecute("blocks.select", {
@@ -2761,10 +2832,16 @@ var createVideoOnCanPlayThrough = async (engine, block, ev) => {
2761
2832
  const fieldInfo = getFieldTypeAndTargetId(engine, ev, block);
2762
2833
  if (!fieldInfo || !block.props?.src?.trim())
2763
2834
  return;
2835
+ const video = ev?.target;
2836
+ const intrinsic = video?.videoWidth && video?.videoHeight ? {
2837
+ "props.intrinsicWidth": video.videoWidth,
2838
+ "props.intrinsicHeight": video.videoHeight
2839
+ } : {};
2764
2840
  engine.document.apply((tree) => engine.mutations.mutateField(tree, {
2765
2841
  id: block.id,
2766
2842
  keyValuePairs: {
2767
- "props.isLoaded": true
2843
+ "props.isLoaded": true,
2844
+ ...intrinsic
2768
2845
  }
2769
2846
  }), { origin: "history" });
2770
2847
  engine.commands.tryExecute("blocks.select", {
@@ -2786,7 +2863,7 @@ var createVideoOnDoubleClick = async (engine, block, ev) => {
2786
2863
  keyValuePairs: {
2787
2864
  "props.controls": !field.props.controls
2788
2865
  }
2789
- }));
2866
+ }), { shouldEmitEvent: false });
2790
2867
  await fieldInfo.emit();
2791
2868
  };
2792
2869
 
@@ -2825,10 +2902,11 @@ function buildIFrameHandlers(engine, block) {
2825
2902
  }
2826
2903
 
2827
2904
  // src/lifecycle/fields/handlers.registry.ts
2828
- class FieldHandlersRegistry extends GenericRegistry4 {
2905
+ class FieldHandlersRegistry extends GenericRegistry5 {
2829
2906
  }
2830
2907
  var FieldHandlers = new FieldHandlersRegistry;
2831
2908
  FieldHandlers.register("h1", buildEditableHandlers);
2909
+ FieldHandlers.register("h2", buildEditableHandlers);
2832
2910
  FieldHandlers.register("p", buildEditableHandlers);
2833
2911
  FieldHandlers.register("blockquote", buildEditableHandlers);
2834
2912
  FieldHandlers.register("figcaption", buildEditableHandlers);
@@ -2849,10 +2927,10 @@ function forField(engine, block) {
2849
2927
  }
2850
2928
  var FLC = { forField };
2851
2929
  // src/primitives/fields/field.primitives.tsx
2852
- import { useCallback, useEffect as useEffect6, useRef as useRef3 } from "react";
2930
+ import { useCallback, useEffect as useEffect8, useRef } from "react";
2853
2931
  import { jsxDEV as jsxDEV25 } from "react/jsx-dev-runtime";
2854
2932
  function FieldPrimitive({ blockId }) {
2855
- const blockRef = useRef3(null);
2933
+ const blockRef = useRef(null);
2856
2934
  const engine = useEngine();
2857
2935
  const renderer = useRenderer();
2858
2936
  const block = useBlock(blockId);
@@ -2894,14 +2972,14 @@ function FieldPrimitive({ blockId }) {
2894
2972
  domSel.removeAllRanges();
2895
2973
  domSel.addRange(range);
2896
2974
  });
2897
- useEffect6(() => {
2975
+ useEffect8(() => {
2898
2976
  const domEl = blockRef.current;
2899
2977
  if (!domEl)
2900
2978
  return;
2901
2979
  const publishBlockRect = () => {
2902
2980
  const hover = engine.state.get("hover");
2903
2981
  const focus = engine.state.get("focus");
2904
- const selection = engine.state.get("selection")?.blocks;
2982
+ const selection2 = engine.state.get("selection")?.blocks;
2905
2983
  const rect = blockRectFromBlockId(blockId);
2906
2984
  if (!rect || !engine.document.get().order.size)
2907
2985
  return;
@@ -2911,10 +2989,10 @@ function FieldPrimitive({ blockId }) {
2911
2989
  if (hover?.id === blockId) {
2912
2990
  engine.commands.tryExecute("blocks.hover", { id: blockId, rect });
2913
2991
  }
2914
- if (selection?.has(blockId)) {
2992
+ if (selection2?.has(blockId)) {
2915
2993
  engine.commands.tryExecute("blocks.select", {
2916
- blocks: new Map().set(blockId, rect),
2917
- mode: "add"
2994
+ blocks: new Map(selection2.entries()).set(blockId, rect),
2995
+ mode: "replace"
2918
2996
  });
2919
2997
  }
2920
2998
  };
@@ -2929,6 +3007,7 @@ function FieldPrimitive({ blockId }) {
2929
3007
  return null;
2930
3008
  return /* @__PURE__ */ jsxDEV25("div", {
2931
3009
  ref: blockRef,
3010
+ className: "w-full flex max-w-full items-center justify-center",
2932
3011
  children: renderer.renderField(block)
2933
3012
  }, undefined, false, undefined, this);
2934
3013
  }
@@ -2941,26 +3020,26 @@ var FieldsPrimitives = {
2941
3020
  // src/hooks/use-renderer.ts
2942
3021
  function useRenderer() {
2943
3022
  const engine = useEngine();
2944
- return useMemo4(() => {
3023
+ return useMemo2(() => {
2945
3024
  const ctx = {
2946
3025
  mode: "edit",
2947
3026
  styles: (type) => engine.ui.getStyle(type),
2948
3027
  events: (block) => FLC.forField(engine, block)
2949
3028
  };
2950
3029
  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);
3030
+ for (const [variant, comp2] of UTILS2.ObjectEntries(FieldsPrimitives)) {
3031
+ if (comp2)
3032
+ renderer.primitives.post(variant, comp2);
2954
3033
  }
2955
3034
  return renderer;
2956
3035
  }, [engine]);
2957
3036
  }
2958
3037
 
2959
3038
  // src/hooks/use-flow.ts
2960
- import { useEffect as useEffect8 } from "react";
3039
+ import { useEffect as useEffect10 } from "react";
2961
3040
 
2962
3041
  // src/hooks/custom/use-custom-ref.ts
2963
- import { useEffect as useEffect7, useRef as useRef4 } from "react";
3042
+ import { useEffect as useEffect9, useRef as useRef2 } from "react";
2964
3043
  function useCustomRef(factory) {
2965
3044
  const isServer = typeof window === "undefined";
2966
3045
  const getInitialValue = () => {
@@ -2972,8 +3051,8 @@ function useCustomRef(factory) {
2972
3051
  return null;
2973
3052
  }
2974
3053
  };
2975
- const ref = useRef4(getInitialValue());
2976
- useEffect7(() => {
3054
+ const ref = useRef2(getInitialValue());
3055
+ useEffect9(() => {
2977
3056
  try {
2978
3057
  ref.current = typeof factory === "function" ? factory() : factory;
2979
3058
  } catch {}
@@ -3012,7 +3091,7 @@ function useFlow() {
3012
3091
  engine.commands.tryExecute("editor.rect", { editorRect: editorRectFromDomElement(flowEditor) });
3013
3092
  return flowEditor;
3014
3093
  });
3015
- useEffect8(() => {
3094
+ useEffect10(() => {
3016
3095
  function handleKeyDown(ev) {
3017
3096
  if (!ev.ctrlKey || ev.key.toLocaleLowerCase() !== "z")
3018
3097
  return;
@@ -3038,7 +3117,7 @@ function useFlow() {
3038
3117
  }
3039
3118
  };
3040
3119
  }, [engine, coraxFlowEditorRef]);
3041
- useEffect8(() => {
3120
+ useEffect10(() => {
3042
3121
  const element = coraxFlowEditorRef.current;
3043
3122
  if (!element)
3044
3123
  return;
@@ -3053,7 +3132,7 @@ function useFlow() {
3053
3132
  element.removeEventListener("scroll", publishEditorRect);
3054
3133
  };
3055
3134
  }, [engine, coraxFlowEditorRef]);
3056
- useEffect8(() => {
3135
+ useEffect10(() => {
3057
3136
  const element = coraxFlowEditorRef.current;
3058
3137
  if (!element)
3059
3138
  return;
@@ -3068,9 +3147,9 @@ function useFlow() {
3068
3147
  }
3069
3148
 
3070
3149
  // src/hooks/use-text-input.ts
3071
- import { useEffect as useEffect9 } from "react";
3150
+ import { useEffect as useEffect11 } from "react";
3072
3151
  function useTextInput(engine) {
3073
- useEffect9(() => {
3152
+ useEffect11(() => {
3074
3153
  let composing = false;
3075
3154
  const rootOf = (t) => ((t instanceof Element ? t : t?.parentElement) ?? null)?.closest("[data-text-path]") ?? null;
3076
3155
  const onBeforeInput = (e) => {
@@ -3145,44 +3224,265 @@ function useTextInput(engine) {
3145
3224
  }
3146
3225
 
3147
3226
  // src/components/corax-flow.tsx
3148
- import { cn as cn14 } from "cn";
3149
- import { jsxDEV as jsxDEV26 } from "react/jsx-dev-runtime";
3227
+ import { cn as cn13 } from "cn";
3228
+ import { jsxDEV as jsxDEV26, Fragment as Fragment2 } from "react/jsx-dev-runtime";
3150
3229
  "use client";
3230
+ var IMAGE_BREAKOUT_GUTTER = 150;
3231
+ function CoraxBlocks() {
3232
+ const engine = useEngine();
3233
+ const renderer = useRenderer();
3234
+ const order = useSyncExternalStore5((onStoreChange) => engine.state.subscribe("document", onStoreChange), () => engine.document.get().order, () => engine.document.get().order);
3235
+ return /* @__PURE__ */ jsxDEV26(Fragment2, {
3236
+ children: [...order].map((id) => {
3237
+ const block = engine.document.getBlock(id);
3238
+ if (!block)
3239
+ return null;
3240
+ const Comp = renderer.primitives.get(block.variant);
3241
+ if (!Comp)
3242
+ return null;
3243
+ return /* @__PURE__ */ jsxDEV26(Comp, {
3244
+ blockId: id
3245
+ }, id, false, undefined, this);
3246
+ })
3247
+ }, undefined, false, undefined, this);
3248
+ }
3151
3249
  function CoraxFlow({
3152
3250
  children,
3153
3251
  className
3154
3252
  }) {
3155
- const [count, forceUpdate] = useReducer((x) => x + 1, 0);
3156
3253
  const engine = useEngine();
3157
- const renderer = useRenderer();
3158
3254
  useFlow();
3159
3255
  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
3256
  return /* @__PURE__ */ jsxDEV26("div", {
3171
3257
  id: "corax_flow_editor",
3172
- className: "relative flex flex-col max-w-full w-200 h-full",
3258
+ className: "relative flex flex-col max-w-full w-275 h-full",
3173
3259
  children: /* @__PURE__ */ jsxDEV26("div", {
3174
3260
  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),
3261
+ className: cn13("relative w-full h-full flex flex-col items-center scrollbar-none gap-1", className),
3262
+ style: {
3263
+ overflowX: "hidden",
3264
+ overflowY: "auto",
3265
+ paddingInline: IMAGE_BREAKOUT_GUTTER
3266
+ },
3176
3267
  children: [
3177
- renderer.renderTree(count),
3268
+ /* @__PURE__ */ jsxDEV26(CoraxBlocks, {}, undefined, false, undefined, this),
3178
3269
  children
3179
3270
  ]
3180
3271
  }, undefined, true, undefined, this)
3181
3272
  }, undefined, false, undefined, this);
3182
3273
  }
3183
3274
 
3275
+ // src/components/slots/maps/block-actions.tsx
3276
+ import { jsxDEV as jsxDEV27 } from "react/jsx-dev-runtime";
3277
+ function BlockActions({ className, children, ...rest }) {
3278
+ const focusMemo = useSlice("focus_memory");
3279
+ const focus = focusMemo?.blocks?.[0];
3280
+ const items = useSlots("block-actions");
3281
+ const lastPositionRef = useRef3({ active: false, top: 0, left: 0 });
3282
+ const block = useBlock(focus?.id ?? "");
3283
+ const isOpened = !!useSlice("insertion");
3284
+ const position = useMemo3(() => {
3285
+ if (!focus || !block || !isEditableField(block) || block.type === "caption") {
3286
+ return { active: false, top: 0, left: 0 };
3287
+ }
3288
+ const hasContent = !!block.props.children.text.length;
3289
+ if (hasContent) {
3290
+ return { active: false, top: 0, left: 0 };
3291
+ }
3292
+ const { id: firstSelectionId, rect: blockRect } = focus;
3293
+ const container = document.getElementById("corax_flow_blocks_container");
3294
+ if (!container)
3295
+ return { active: false, top: 0, left: 0 };
3296
+ const containerRect = container.getBoundingClientRect();
3297
+ const domElement = document.getElementById(firstSelectionId);
3298
+ if (!domElement)
3299
+ return { active: false, top: 0, left: 0 };
3300
+ const heightDiff = 36 - blockRect.height;
3301
+ const toSubstract = heightDiff / 2;
3302
+ const top = blockRect.top - (-toSubstract > 32 ? -8 : toSubstract) - containerRect.top - container.clientTop + blockRect.parentScrollTop;
3303
+ return {
3304
+ active: true,
3305
+ top,
3306
+ left: IMAGE_BREAKOUT_GUTTER - 44
3307
+ };
3308
+ }, [focus, block]);
3309
+ useEffect12(() => {
3310
+ if (position.active) {
3311
+ lastPositionRef.current = position;
3312
+ }
3313
+ }, [position]);
3314
+ const _position = position.active ? position : lastPositionRef.current;
3315
+ return /* @__PURE__ */ jsxDEV27("div", {
3316
+ style: {
3317
+ top: _position.top,
3318
+ left: _position.left
3319
+ },
3320
+ className: cn14("absolute top-0 left-0 gap-1 z-10 flex items-center transition-opacity", className, {
3321
+ "opacity-0 pointer-events-none": !position.active || !focus
3322
+ }),
3323
+ ...rest,
3324
+ children: [
3325
+ /* @__PURE__ */ jsxDEV27(Slots, {
3326
+ slotName: "block-actions"
3327
+ }, undefined, false, undefined, this),
3328
+ /* @__PURE__ */ jsxDEV27("div", {
3329
+ style: {
3330
+ width: isOpened ? (items.length - 1) * 32 + 8 : 0
3331
+ },
3332
+ className: cn14("absolute h-9.5 -z-1 left-9 bg-popover border rounded-full transition-all duration-300 ease-damping", {
3333
+ "opacity-0 pointer-events-none": !isOpened
3334
+ })
3335
+ }, undefined, false, undefined, this),
3336
+ children
3337
+ ]
3338
+ }, undefined, true, undefined, this);
3339
+ }
3340
+ // src/components/slots/maps/overlays.tsx
3341
+ import { jsxDEV as jsxDEV28, Fragment as Fragment3 } from "react/jsx-dev-runtime";
3342
+ function Overlays() {
3343
+ return /* @__PURE__ */ jsxDEV28(Fragment3, {
3344
+ children: /* @__PURE__ */ jsxDEV28(Slots, {
3345
+ slotName: "overlay"
3346
+ }, undefined, false, undefined, this)
3347
+ }, undefined, false, undefined, this);
3348
+ }
3349
+ // src/components/slots/maps/text-inspector.tsx
3350
+ import { jsxDEV as jsxDEV29 } from "react/jsx-dev-runtime";
3351
+ function TextInspector({ blockId }) {
3352
+ return /* @__PURE__ */ jsxDEV29("div", {
3353
+ children: blockId
3354
+ }, undefined, false, undefined, this);
3355
+ }
3356
+ // src/components/slots/maps/toolbar.tsx
3357
+ import { cn as cn15 } from "cn";
3358
+ import { useEffect as useEffect13, useReducer, useRef as useRef4, useState as useState5 } from "react";
3359
+ import { jsxDEV as jsxDEV30 } from "react/jsx-dev-runtime";
3360
+ var TOOLBAR_OFFSET = 44;
3361
+ var TOOLBAR_MARGIN = -44;
3362
+ var DEFAULT_STATE = { active: false, top: 0, left: 0 };
3363
+ function Toolbar({ className, children, ...rest }) {
3364
+ const items = useSlots("toolbar");
3365
+ const ui = useUIContext();
3366
+ const [toolbarWidth, setToolbarWidth] = useState5(0);
3367
+ const [toolbarHeight, setToolbarHeight] = useState5(0);
3368
+ const [, bumpViewport] = useReducer((x) => x + 1, 0);
3369
+ const length = items.reduce((prev, c) => {
3370
+ if (c.when?.(ui)) {
3371
+ return prev + 1;
3372
+ }
3373
+ return prev;
3374
+ }, 0);
3375
+ const textSel = useSlice("textSelection");
3376
+ const currentBlockId = textSel?.blockId;
3377
+ const selection2 = useSlice("selection");
3378
+ const lastPositionRef = useRef4(DEFAULT_STATE);
3379
+ const toolbarRef = useRef4(null);
3380
+ const frameRef = useRef4(0);
3381
+ useIsomorphicLayoutEffect(() => {
3382
+ const toolbarElement = toolbarRef.current;
3383
+ if (!toolbarElement)
3384
+ return;
3385
+ const updateToolbarSize = () => {
3386
+ const rect = toolbarElement.getBoundingClientRect();
3387
+ setToolbarWidth(rect.width);
3388
+ setToolbarHeight(rect.height);
3389
+ };
3390
+ updateToolbarSize();
3391
+ const resizeObserver = new ResizeObserver(updateToolbarSize);
3392
+ resizeObserver.observe(toolbarElement);
3393
+ return () => resizeObserver.disconnect();
3394
+ }, []);
3395
+ useEffect13(() => {
3396
+ const container = document.getElementById("corax_flow_blocks_container");
3397
+ const onViewportChange = () => {
3398
+ if (frameRef.current)
3399
+ return;
3400
+ frameRef.current = requestAnimationFrame(() => {
3401
+ frameRef.current = 0;
3402
+ bumpViewport();
3403
+ });
3404
+ };
3405
+ container?.addEventListener("scroll", onViewportChange, { passive: true });
3406
+ window.addEventListener("scroll", onViewportChange, { passive: true });
3407
+ window.addEventListener("resize", onViewportChange);
3408
+ return () => {
3409
+ if (frameRef.current)
3410
+ cancelAnimationFrame(frameRef.current);
3411
+ container?.removeEventListener("scroll", onViewportChange);
3412
+ window.removeEventListener("scroll", onViewportChange);
3413
+ window.removeEventListener("resize", onViewportChange);
3414
+ };
3415
+ }, []);
3416
+ const computePosition = () => {
3417
+ const toolbarElement = toolbarRef.current;
3418
+ if (!toolbarElement || toolbarWidth === 0) {
3419
+ return DEFAULT_STATE;
3420
+ }
3421
+ const container = document.getElementById("corax_flow_blocks_container");
3422
+ const containerRect = container?.getBoundingClientRect();
3423
+ const clampTop = (top) => {
3424
+ if (!containerRect)
3425
+ return top;
3426
+ const min = containerRect.top + TOOLBAR_MARGIN;
3427
+ const max = containerRect.bottom - TOOLBAR_MARGIN - toolbarHeight;
3428
+ return Math.min(Math.max(top, min), Math.max(min, max));
3429
+ };
3430
+ if (textSel && currentBlockId && textSel.start !== textSel.end) {
3431
+ const el = document.getElementById(textSel.blockId);
3432
+ const range = el ? offsetsToRange(el, textSel.start, textSel.end) : null;
3433
+ if (range) {
3434
+ const selRect = range.getBoundingClientRect();
3435
+ return {
3436
+ active: true,
3437
+ top: clampTop(selRect.top - TOOLBAR_OFFSET),
3438
+ left: selRect.left + (selRect.width - toolbarWidth) / 2
3439
+ };
3440
+ }
3441
+ }
3442
+ const rects = Array.from(selection2?.blocks?.keys() ?? []).map((id) => blockRectFromBlockId(id)).filter((rect) => !!rect);
3443
+ if (rects.length > 0) {
3444
+ const top = Math.min(...rects.map((rect) => rect.top));
3445
+ const left = Math.min(...rects.map((rect) => rect.left));
3446
+ const right = Math.max(...rects.map((rect) => rect.right));
3447
+ return {
3448
+ active: true,
3449
+ top: clampTop(top - TOOLBAR_OFFSET),
3450
+ left: (left + right) / 2 - toolbarWidth / 2
3451
+ };
3452
+ }
3453
+ return DEFAULT_STATE;
3454
+ };
3455
+ const position = computePosition();
3456
+ useEffect13(() => {
3457
+ if (position.active) {
3458
+ lastPositionRef.current = position;
3459
+ }
3460
+ }, [position]);
3461
+ const _position = position.active ? position : lastPositionRef.current;
3462
+ return /* @__PURE__ */ jsxDEV30("div", {
3463
+ ref: toolbarRef,
3464
+ style: {
3465
+ top: _position.top,
3466
+ left: _position.left
3467
+ },
3468
+ className: cn15("fixed top-0 left-0 gap-1 flex items-center transition-opacity bg-popover p-1 rounded-[12px] border", className, {
3469
+ "opacity-0 pointer-events-none": !position.active || !length
3470
+ }),
3471
+ ...rest,
3472
+ children: [
3473
+ /* @__PURE__ */ jsxDEV30(Slots, {
3474
+ slotName: "toolbar"
3475
+ }, undefined, false, undefined, this),
3476
+ children
3477
+ ]
3478
+ }, undefined, true, undefined, this);
3479
+ }
3480
+
3481
+ // src/components/slots/maps/index.ts
3482
+ "use client";
3184
3483
  // src/components/index.ts
3185
3484
  "use client";
3485
+
3186
3486
  // src/index.ts
3187
3487
  export * from "@coorax/core";
3188
3488
  export * from "@coorax/render-react";
@@ -3209,6 +3509,7 @@ export {
3209
3509
  PrimitivesComponentsRegistry,
3210
3510
  Overlays,
3211
3511
  LocalDB,
3512
+ IMAGE_BREAKOUT_GUTTER,
3212
3513
  GenericRegistry3 as GenericRegistry,
3213
3514
  FieldHandlersRegistry,
3214
3515
  FieldHandlers,
@@ -3216,6 +3517,7 @@ export {
3216
3517
  FallbackComponentsRegistry,
3217
3518
  FLC,
3218
3519
  ErrorComponentsRegistry,
3520
+ CoraxIconsRegistry,
3219
3521
  CoraxIcon,
3220
3522
  CoraxFlow,
3221
3523
  CoraxEngineProvider,