@coorax/react 0.0.0-canary.0 → 0.0.0-canary.10

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 (198) hide show
  1. package/dist/components/commons/button.d.ts +8 -0
  2. package/dist/components/commons/youtube.d.ts +2 -0
  3. package/dist/components/corax-context-provider.d.ts +11 -0
  4. package/dist/components/corax-flow.d.ts +6 -0
  5. package/dist/components/errors/iframe.error.d.ts +2 -0
  6. package/dist/components/errors/image.error.d.ts +2 -0
  7. package/dist/components/errors/video.errors.d.ts +2 -0
  8. package/dist/components/fallbacks/iframe.fallback.d.ts +2 -0
  9. package/dist/components/fallbacks/image.fallback.d.ts +2 -0
  10. package/dist/components/fallbacks/link.fallback.d.ts +2 -0
  11. package/dist/components/fallbacks/video.fallback.d.ts +2 -0
  12. package/dist/components/slots/buttons/block-actions-button.d.ts +3 -0
  13. package/dist/components/slots/buttons/caption-button.d.ts +3 -0
  14. package/dist/components/slots/buttons/code-theme-button.d.ts +3 -0
  15. package/dist/components/slots/buttons/delete-button.d.ts +3 -0
  16. package/dist/components/slots/buttons/divider-style-button.d.ts +3 -0
  17. package/dist/components/slots/buttons/divider-width-button.d.ts +3 -0
  18. package/dist/components/slots/buttons/iframe-playback-button.d.ts +3 -0
  19. package/dist/components/slots/buttons/image-width-button.d.ts +3 -0
  20. package/dist/components/slots/buttons/paragraph-theme-button.d.ts +3 -0
  21. package/dist/components/slots/buttons/toolbar-button.d.ts +3 -0
  22. package/dist/components/slots/maps/block-actions.d.ts +1 -0
  23. package/dist/components/slots/maps/overlays.d.ts +1 -0
  24. package/dist/components/slots/maps/text-inspector.d.ts +2 -0
  25. package/dist/components/slots/maps/toolbar.d.ts +1 -0
  26. package/dist/components/slots/overlays/focus-overlay.d.ts +3 -0
  27. package/dist/components/slots/overlays/hover-overlay.d.ts +3 -0
  28. package/dist/components/slots/overlays/selection-overlay.d.ts +3 -0
  29. package/dist/components/slots/slot-button.d.ts +6 -0
  30. package/dist/components/slots/slot-component.d.ts +5 -0
  31. package/dist/components/slots/slots.d.ts +4 -0
  32. package/dist/constants/field.constants.d.ts +2 -0
  33. package/dist/hooks/custom/use-custom-ref.d.ts +1 -0
  34. package/dist/hooks/custom/use-isomorphic-layout-effect.d.ts +2 -0
  35. package/{src/hooks/index.ts → dist/hooks/index.d.ts} +1 -0
  36. package/dist/hooks/use-block-entry.d.ts +2 -0
  37. package/dist/hooks/use-block.d.ts +2 -0
  38. package/dist/hooks/use-flow.d.ts +17 -0
  39. package/dist/hooks/use-is-selected.d.ts +2 -0
  40. package/dist/hooks/use-keyboard.d.ts +10 -0
  41. package/dist/hooks/use-registry.d.ts +3 -0
  42. package/dist/hooks/use-renderer.d.ts +2 -0
  43. package/dist/hooks/use-slice.d.ts +2 -0
  44. package/dist/hooks/use-slots.d.ts +2 -0
  45. package/dist/hooks/use-tasks.d.ts +7 -0
  46. package/dist/hooks/use-text-input.d.ts +2 -0
  47. package/dist/hooks/use-ui-context.d.ts +2 -0
  48. package/dist/hooks/useSelection.d.ts +2 -0
  49. package/{src/index.ts → dist/index.d.ts} +8 -4
  50. package/dist/index.js +3575 -0
  51. package/dist/lib/comp.utils.d.ts +8 -0
  52. package/dist/lib/func.utils.d.ts +3 -0
  53. package/dist/lib/index.d.ts +4 -0
  54. package/dist/lib/selection.utils.d.ts +5 -0
  55. package/dist/lib/slots.utils.d.ts +4 -0
  56. package/dist/lifecycle/fields/common/focus.events/onblur.d.ts +3 -0
  57. package/dist/lifecycle/fields/common/focus.events/onfocus.d.ts +3 -0
  58. package/dist/lifecycle/fields/common/handlers.d.ts +13 -0
  59. package/dist/lifecycle/fields/common/mouse.events/onclick.d.ts +3 -0
  60. package/dist/lifecycle/fields/common/mouse.events/onmouseenter.d.ts +3 -0
  61. package/dist/lifecycle/fields/common/mouse.events/onmouseleave.d.ts +3 -0
  62. package/dist/lifecycle/fields/divider/handlers.d.ts +7 -0
  63. package/dist/lifecycle/fields/divider/keyboard.events/onkeydown.d.ts +3 -0
  64. package/dist/lifecycle/fields/editable/focus.events/onbeforeinput.d.ts +3 -0
  65. package/dist/lifecycle/fields/editable/handlers.d.ts +7 -0
  66. package/dist/lifecycle/fields/editable/keyboard.events/onkeydown.d.ts +3 -0
  67. package/dist/lifecycle/fields/editable/mouse.events/ondoubleclick.d.ts +4 -0
  68. package/dist/lifecycle/fields/editable/synthetic.events/onselect.d.ts +3 -0
  69. package/dist/lifecycle/fields/handlers.registry.d.ts +12 -0
  70. package/dist/lifecycle/fields/lifecycle.fields.d.ts +10 -0
  71. package/dist/lifecycle/fields/lifecycle.fields.types.d.ts +4 -0
  72. package/dist/lifecycle/fields/lifecycle.utils.d.ts +8 -0
  73. package/dist/lifecycle/fields/media/common/handlers.d.ts +7 -0
  74. package/dist/lifecycle/fields/media/common/keyboard.events/onkeydown.d.ts +3 -0
  75. package/dist/lifecycle/fields/media/common/synthetic.events/onerror.d.ts +3 -0
  76. package/dist/lifecycle/fields/media/iframe/handlers.d.ts +7 -0
  77. package/dist/lifecycle/fields/media/iframe/synthetic.events/onload.d.ts +3 -0
  78. package/dist/lifecycle/fields/media/image/handlers.d.ts +7 -0
  79. package/dist/lifecycle/fields/media/image/synthetic.events/onload.d.ts +3 -0
  80. package/dist/lifecycle/fields/media/video/handlers.d.ts +7 -0
  81. package/dist/lifecycle/fields/media/video/mouse.events/ondoubleclick.d.ts +4 -0
  82. package/dist/lifecycle/fields/media/video/synthetic.events/oncanplaythrough.d.ts +3 -0
  83. package/dist/lifecycle/index.d.ts +3 -0
  84. package/dist/modules/autosave.module.d.ts +41 -0
  85. package/dist/modules/errors.module.d.ts +7 -0
  86. package/dist/modules/fallbacks.module.d.ts +7 -0
  87. package/dist/modules/slots.module.d.ts +7 -0
  88. package/dist/modules/ui-primitives.module.d.ts +7 -0
  89. package/dist/primitives/fields/field.primitives.d.ts +2 -0
  90. package/dist/primitives/index.d.ts +3 -0
  91. package/dist/registry/index.d.ts +4 -0
  92. package/dist/registry/slots.registry.d.ts +4 -0
  93. package/{src/registry/ui.primitives.registry.tsx → dist/registry/ui.primitives.registry.d.ts} +4 -5
  94. package/dist/services/index.d.ts +2 -0
  95. package/dist/services/localdb/db/db.d.ts +78 -0
  96. package/dist/services/localdb/db/db.test.d.ts +1 -0
  97. package/dist/services/localdb/dbtest.d.ts +1 -0
  98. package/dist/services/localdb/lexer/lexer.d.ts +14 -0
  99. package/dist/services/localdb/lexer/lexer.test.d.ts +1 -0
  100. package/dist/services/localdb/lexer/lexer.types.d.ts +5 -0
  101. package/dist/services/localdb/operator/operator.d.ts +10 -0
  102. package/dist/services/localdb/parser/parser.constants.d.ts +3 -0
  103. package/dist/services/localdb/parser/parser.d.ts +15 -0
  104. package/dist/services/localdb/parser/parser.test.d.ts +1 -0
  105. package/dist/services/localdb/parser/parser.types.d.ts +49 -0
  106. package/dist/services/localdb/sheet/sheet.constants.d.ts +3 -0
  107. package/dist/services/localdb/sheet/sheet.d.ts +14 -0
  108. package/dist/services/localdb/sheet/sheet.types.d.ts +13 -0
  109. package/dist/styles.css +2 -0
  110. package/package.json +38 -15
  111. package/styles.css +2 -1
  112. package/.oxlintrc.json +0 -8
  113. package/src/components/commons/button.tsx +0 -59
  114. package/src/components/corax-context-provider.tsx +0 -47
  115. package/src/components/corax-flow.tsx +0 -44
  116. package/src/components/fallbacks/image.fallback.tsx +0 -23
  117. package/src/components/slots/buttons/block-actions-button.tsx +0 -85
  118. package/src/components/slots/buttons/toolbar-button.tsx +0 -40
  119. package/src/components/slots/maps/block-actions.tsx +0 -84
  120. package/src/components/slots/maps/overlays.tsx +0 -9
  121. package/src/components/slots/maps/text-inspector.tsx +0 -5
  122. package/src/components/slots/maps/toolbar.tsx +0 -79
  123. package/src/components/slots/overlays/focus-overlay.tsx +0 -30
  124. package/src/components/slots/overlays/hover-overlay.tsx +0 -18
  125. package/src/components/slots/overlays/selection-overlay.tsx +0 -20
  126. package/src/components/slots/slot-button.tsx +0 -20
  127. package/src/components/slots/slot-component.tsx +0 -17
  128. package/src/components/slots/slots.tsx +0 -29
  129. package/src/constants/field.constants.ts +0 -3
  130. package/src/hooks/custom/use-custom-ref.ts +0 -11
  131. package/src/hooks/use-block-entry.ts +0 -44
  132. package/src/hooks/use-block.ts +0 -11
  133. package/src/hooks/use-flow.ts +0 -83
  134. package/src/hooks/use-keyboard.ts +0 -66
  135. package/src/hooks/use-registry.ts +0 -18
  136. package/src/hooks/use-renderer.ts +0 -8
  137. package/src/hooks/use-slice.ts +0 -13
  138. package/src/hooks/use-slots.ts +0 -13
  139. package/src/hooks/use-tasks.ts +0 -33
  140. package/src/hooks/use-text-input.ts +0 -83
  141. package/src/hooks/use-ui-context.ts +0 -16
  142. package/src/hooks/useSelection.ts +0 -27
  143. package/src/lib/comp.utils.tsx +0 -44
  144. package/src/lib/func.utils.ts +0 -15
  145. package/src/lib/selection.utils.ts +0 -33
  146. package/src/lib/slots.utils.tsx +0 -23
  147. package/src/lifecycle/fields/focus.events/onbeforeinput.ts +0 -21
  148. package/src/lifecycle/fields/focus.events/onblur.ts +0 -19
  149. package/src/lifecycle/fields/focus.events/onfocus.ts +0 -16
  150. package/src/lifecycle/fields/keyboard.events/onkeydown.ts +0 -128
  151. package/src/lifecycle/fields/lifecycle.fields.ts +0 -116
  152. package/src/lifecycle/fields/lifecycle.fields.types.ts +0 -33
  153. package/src/lifecycle/fields/lifecycle.utils.ts +0 -26
  154. package/src/lifecycle/fields/mouse.events/onclick.ts +0 -79
  155. package/src/lifecycle/fields/mouse.events/ondoubleclick.ts +0 -27
  156. package/src/lifecycle/fields/mouse.events/onmouseenter.ts +0 -27
  157. package/src/lifecycle/fields/mouse.events/onmouseleave.ts +0 -21
  158. package/src/lifecycle/fields/synthetic.events/onload.ts +0 -16
  159. package/src/lifecycle/fields/synthetic.events/onselect.ts +0 -57
  160. package/src/lifecycle/index.ts +0 -1
  161. package/src/modules/autosave.module.ts +0 -238
  162. package/src/modules/fallbacks.module.tsx +0 -19
  163. package/src/modules/slots.module.tsx +0 -28
  164. package/src/modules/ui-primitives.module.tsx +0 -20
  165. package/src/primitives/fields/field.primitives.tsx +0 -86
  166. package/src/primitives/index.ts +0 -8
  167. package/src/registry/fallbacks.registry.tsx +0 -9
  168. package/src/registry/index.ts +0 -5
  169. package/src/registry/primitives.registry.tsx +0 -57
  170. package/src/registry/registry.ts +0 -44
  171. package/src/registry/slots.registry.tsx +0 -6
  172. package/src/renderer/renderer.test.ts +0 -34
  173. package/src/renderer/renderer.tsx +0 -164
  174. package/src/renderer/renderer.types.ts +0 -3
  175. package/src/renderer/renderer.utils.tsx +0 -139
  176. package/src/renderer/utils/divider.renderer.utils.tsx +0 -53
  177. package/src/services/localdb/db/db.test.ts +0 -351
  178. package/src/services/localdb/db/db.ts +0 -628
  179. package/src/services/localdb/lexer/lexer.test.ts +0 -123
  180. package/src/services/localdb/lexer/lexer.ts +0 -173
  181. package/src/services/localdb/lexer/lexer.types.ts +0 -34
  182. package/src/services/localdb/operator/operator.ts +0 -16
  183. package/src/services/localdb/parser/parser.constants.ts +0 -23
  184. package/src/services/localdb/parser/parser.test.ts +0 -172
  185. package/src/services/localdb/parser/parser.ts +0 -427
  186. package/src/services/localdb/parser/parser.types.ts +0 -56
  187. package/src/services/localdb/sheet/sheet.constants.ts +0 -32
  188. package/src/services/localdb/sheet/sheet.ts +0 -47
  189. package/src/services/localdb/sheet/sheet.types.ts +0 -38
  190. package/tsconfig.app.json +0 -26
  191. package/tsconfig.json +0 -9
  192. package/tsconfig.node.json +0 -9
  193. package/tsconfig.tsbuildinfo +0 -1
  194. package/vite.config.ts +0 -9
  195. /package/{src/components/index.ts → dist/components/index.d.ts} +0 -0
  196. /package/{src/components/slots/index.ts → dist/components/slots/index.d.ts} +0 -0
  197. /package/{src/components/slots/maps/index.ts → dist/components/slots/maps/index.d.ts} +0 -0
  198. /package/{src/modules/index.ts → dist/modules/index.d.ts} +0 -0
package/dist/index.js ADDED
@@ -0,0 +1,3575 @@
1
+ "use client";
2
+
3
+ // src/registry/slots.registry.tsx
4
+ import { GenericRegistry } from "@coorax/render-react";
5
+ var SlotsComponentRegistry = new GenericRegistry;
6
+
7
+ // src/components/commons/button.tsx
8
+ import { cva } from "class-variance-authority";
9
+ import { cn } from "cn";
10
+ import { jsxDEV } from "react/jsx-dev-runtime";
11
+ var buttonVariants = cva("group/button inline-flex shrink-0 items-center justify-center rounded-corax-lg border border-transparent bg-clip-padding text-sm font-medium whitespace-nowrap transition-all outline-none select-none focus-visible:border-corax-ring focus-visible:ring-3 focus-visible:ring-corax-ring/50 active:not-aria-[haspopup]:translate-y-px disabled:pointer-events-none disabled:opacity-50 aria-invalid:border-corax-destructive aria-invalid:ring-3 aria-invalid:ring-corax-destructive/20 dark:aria-invalid:border-corax-destructive/50 dark:aria-invalid:ring-corax-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4", {
12
+ variants: {
13
+ variant: {
14
+ default: "bg-corax-primary text-corax-primary-foreground hover:bg-corax-primary/80",
15
+ outline: "border-corax-border bg-corax-background hover:bg-corax-muted hover:text-corax-foreground aria-expanded:bg-corax-muted aria-expanded:text-corax-foreground dark:border-corax-input dark:bg-corax-input/30 dark:hover:bg-corax-input/50",
16
+ secondary: "bg-corax-secondary text-corax-secondary-foreground hover:bg-[color-mix(in_oklch,var(--corax-secondary),var(--corax-foreground)_5%)] aria-expanded:bg-corax-secondary aria-expanded:text-corax-secondary-foreground",
17
+ ghost: "hover:bg-corax-muted hover:text-corax-foreground aria-expanded:bg-corax-muted aria-expanded:text-corax-foreground dark:hover:bg-corax-muted/50",
18
+ destructive: "bg-corax-destructive/10 text-corax-destructive hover:bg-corax-destructive/20 focus-visible:border-corax-destructive/40 focus-visible:ring-corax-destructive/20 dark:bg-corax-destructive/20 dark:hover:bg-corax-destructive/30 dark:focus-visible:ring-corax-destructive/40",
19
+ link: "text-corax-primary underline-offset-4 hover:underline"
20
+ },
21
+ size: {
22
+ default: "h-8 gap-1.5 px-2.5 has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2",
23
+ xs: "h-6 gap-1 rounded-[min(var(--radius-corax-md),10px)] px-2 text-xs in-data-[slot=button-group]:rounded-corax-lg has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 [&_svg:not([class*='size-'])]:size-3",
24
+ sm: "h-7 gap-1 rounded-[min(var(--radius-corax-md),12px)] px-2.5 text-[0.8rem] in-data-[slot=button-group]:rounded-corax-lg has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 [&_svg:not([class*='size-'])]:size-3.5",
25
+ lg: "h-9 gap-1.5 px-2.5 has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2",
26
+ icon: "size-8",
27
+ "icon-xs": "size-6 rounded-[min(var(--radius-corax-md),10px)] in-data-[slot=button-group]:rounded-corax-lg [&_svg:not([class*='size-'])]:size-3",
28
+ "icon-sm": "size-7 rounded-[min(var(--radius-corax-md),12px)] in-data-[slot=button-group]:rounded-corax-lg",
29
+ "icon-lg": "size-9"
30
+ }
31
+ },
32
+ defaultVariants: {
33
+ variant: "default",
34
+ size: "default"
35
+ }
36
+ });
37
+ function Button({
38
+ className,
39
+ variant = "default",
40
+ size = "default",
41
+ ...props
42
+ }) {
43
+ return /* @__PURE__ */ jsxDEV("button", {
44
+ "data-slot": "button",
45
+ "data-variant": variant,
46
+ "data-size": size,
47
+ className: cn(buttonVariants({ variant, size, className })),
48
+ ...props
49
+ }, undefined, false, undefined, this);
50
+ }
51
+
52
+ // src/components/corax-context-provider.tsx
53
+ import {
54
+ CaptionModule,
55
+ CodeModule,
56
+ DeletionModule,
57
+ DividerModule,
58
+ EditorModule,
59
+ Engine,
60
+ FocusModule,
61
+ HistoryModule,
62
+ HoverModule,
63
+ InsertionModule,
64
+ MediaModule,
65
+ ParagraphThemeModule,
66
+ SelectionModule,
67
+ TextEditingModule,
68
+ getCollectedStyles,
69
+ setCoraxStyleSink
70
+ } from "@coorax/core";
71
+ import { createContext, useContext, useEffect as useEffect6, useMemo } from "react";
72
+ // src/registry/ui.primitives.registry.tsx
73
+ import { GenericRegistry as GenericRegistry2 } from "@coorax/render-react";
74
+ var UIPrimitivesRegistry = new GenericRegistry2;
75
+
76
+ // src/registry/index.ts
77
+ import {
78
+ GenericRegistry as GenericRegistry3,
79
+ PrimitivesComponentsRegistry,
80
+ ErrorComponentsRegistry,
81
+ FallbackComponentsRegistry
82
+ } from "@coorax/render-react";
83
+
84
+ // src/components/fallbacks/image.fallback.tsx
85
+ import { RefreshCw, Trash2 } from "lucide-react";
86
+ import { cn as cn2 } from "cn";
87
+ import { useEffect, useState } from "react";
88
+ import { jsxDEV as jsxDEV2 } from "react/jsx-dev-runtime";
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
+ }, []);
97
+ return /* @__PURE__ */ jsxDEV2("div", {
98
+ className: "w-full flex relative pointer-events-none",
99
+ children: [
100
+ /* @__PURE__ */ jsxDEV2("div", {
101
+ className: cn2("w-full h-full absolute inset-0 flex gap-2 items-center justify-center bg-corax-card"),
102
+ children: [
103
+ /* @__PURE__ */ jsxDEV2(RefreshCw, {
104
+ className: "animate-spin size-5"
105
+ }, undefined, false, undefined, this),
106
+ /* @__PURE__ */ jsxDEV2("span", {
107
+ className: "font-semibold",
108
+ children: rest.name
109
+ }, undefined, false, undefined, this)
110
+ ]
111
+ }, undefined, true, undefined, this),
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)
125
+ ]
126
+ }, undefined, true, undefined, this);
127
+ }
128
+
129
+ // src/components/fallbacks/video.fallback.tsx
130
+ import { RefreshCw as RefreshCw2, Trash2 as Trash22 } from "lucide-react";
131
+ import { cn as cn3 } from "cn";
132
+ import { useState as useState2, useEffect as useEffect2 } from "react";
133
+ import { jsxDEV as jsxDEV3 } from "react/jsx-dev-runtime";
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
+ }, []);
142
+ return /* @__PURE__ */ jsxDEV3("div", {
143
+ className: "w-full h-[360px] flex relative pointer-events-none",
144
+ children: [
145
+ /* @__PURE__ */ jsxDEV3("div", {
146
+ className: cn3("w-full h-full absolute inset-0 flex gap-2 items-center justify-center bg-corax-card"),
147
+ children: [
148
+ /* @__PURE__ */ jsxDEV3(RefreshCw2, {
149
+ className: "animate-spin size-5"
150
+ }, undefined, false, undefined, this),
151
+ /* @__PURE__ */ jsxDEV3("span", {
152
+ className: "font-semibold",
153
+ children: rest.name
154
+ }, undefined, false, undefined, this)
155
+ ]
156
+ }, undefined, true, undefined, this),
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)
170
+ ]
171
+ }, undefined, true, undefined, this);
172
+ }
173
+
174
+ // src/components/fallbacks/iframe.fallback.tsx
175
+ import { RefreshCw as RefreshCw3, Trash2 as Trash23 } from "lucide-react";
176
+ import { cn as cn4 } from "cn";
177
+ import { useState as useState3, useEffect as useEffect3 } from "react";
178
+ import { jsxDEV as jsxDEV4 } from "react/jsx-dev-runtime";
179
+ function IFrameFallback({ children, ...rest }) {
180
+ const [displayRemoveButton, setDisplayRemoveButton] = useState3(false);
181
+ useEffect3(() => {
182
+ const timer = setTimeout(() => {
183
+ setDisplayRemoveButton(true);
184
+ }, 1e4);
185
+ return () => clearTimeout(timer);
186
+ }, []);
187
+ return /* @__PURE__ */ jsxDEV4("div", {
188
+ className: "w-full flex relative pointer-events-none",
189
+ children: [
190
+ /* @__PURE__ */ jsxDEV4("div", {
191
+ className: cn4("w-full h-full absolute inset-0 flex gap-2 items-center justify-center bg-corax-card"),
192
+ children: [
193
+ /* @__PURE__ */ jsxDEV4(RefreshCw3, {
194
+ className: "animate-spin size-5"
195
+ }, undefined, false, undefined, this),
196
+ /* @__PURE__ */ jsxDEV4("span", {
197
+ className: "font-semibold",
198
+ children: rest.name
199
+ }, undefined, false, undefined, this)
200
+ ]
201
+ }, undefined, true, undefined, this),
202
+ children,
203
+ displayRemoveButton && /* @__PURE__ */ jsxDEV4(Button, {
204
+ onClick: () => {
205
+ if (confirm("Delete iframe field ?")) {
206
+ window.__cooraxEngine.document.apply((t) => window.__cooraxEngine.mutations.deleteField(t, rest.id), { origin: "history" });
207
+ }
208
+ },
209
+ className: "absolute bottom-2 right-2 cursor-pointer pointer-events-auto",
210
+ title: "Delete iframe field ?",
211
+ variant: "destructive",
212
+ size: "icon-lg",
213
+ children: /* @__PURE__ */ jsxDEV4(Trash23, {}, undefined, false, undefined, this)
214
+ }, undefined, false, undefined, this)
215
+ ]
216
+ }, undefined, true, undefined, this);
217
+ }
218
+
219
+ // src/components/fallbacks/link.fallback.tsx
220
+ import { cn as cn5 } from "cn";
221
+ import { Trash2 as Trash24 } from "lucide-react";
222
+ import { useState as useState4, useEffect as useEffect4 } from "react";
223
+ import { jsxDEV as jsxDEV5 } from "react/jsx-dev-runtime";
224
+ function LinkFallback({ ...rest }) {
225
+ const [displayRemoveButton, setDisplayRemoveButton] = useState4(false);
226
+ useEffect4(() => {
227
+ const timer = setTimeout(() => {
228
+ setDisplayRemoveButton(true);
229
+ }, 1e4);
230
+ return () => clearTimeout(timer);
231
+ }, []);
232
+ return /* @__PURE__ */ jsxDEV5("div", {
233
+ className: "w-full h-[18px] rounded-[6px] overflow-hidden flex relative pointer-events-none bg-corax-card",
234
+ children: [
235
+ /* @__PURE__ */ jsxDEV5("div", {
236
+ className: cn5("h-full absolute inset-0 bg-corax-primary overflow-hidden"),
237
+ style: {
238
+ animation: "loading-skeleton 100s ease-in-out forwards"
239
+ },
240
+ children: /* @__PURE__ */ jsxDEV5("div", {
241
+ className: "w-full h-full bg-gradient-to-r from-transparent via-white/30 to-transparent",
242
+ style: {
243
+ animation: "loading-shimmer 1.55s ease-in-out infinite"
244
+ }
245
+ }, undefined, false, undefined, this)
246
+ }, undefined, false, undefined, this),
247
+ /* @__PURE__ */ jsxDEV5("span", {
248
+ className: "min-w-max absolute -translate-x-1/2 left-1/2 top-1/2 -translate-y-1/2 text-xs",
249
+ children: [
250
+ "Loading ",
251
+ rest.props.children.text,
252
+ "..."
253
+ ]
254
+ }, undefined, true, undefined, this),
255
+ /* @__PURE__ */ jsxDEV5("style", {
256
+ children: `
257
+ @keyframes loading-skeleton {
258
+ 0% { width: 0%; opacity: 0.7; }
259
+ 1% { width: 60%; opacity: 1; }
260
+ 4% { width: 90%; opacity: 0.7; }
261
+ 90% { width: 100%; opacity: 0.7; }
262
+ 100% { width: 100%; opacity: 0.7; }
263
+ }
264
+ @keyframes loading-shimmer {
265
+ 0% { transform: translateX(-100%); }
266
+ 100% { transform: translateX(100%); }
267
+ }
268
+ `
269
+ }, undefined, false, undefined, this),
270
+ displayRemoveButton && /* @__PURE__ */ jsxDEV5(Button, {
271
+ onClick: () => {
272
+ if (confirm("Delete image field ?")) {
273
+ window.__cooraxEngine.document.apply((t) => window.__cooraxEngine.mutations.deleteField(t, rest.id), { origin: "history" });
274
+ }
275
+ },
276
+ className: "absolute -bottom-0.5 right-0 cursor-pointer pointer-events-auto",
277
+ title: "Delete link field ?",
278
+ variant: "destructive",
279
+ size: "icon-xs",
280
+ children: /* @__PURE__ */ jsxDEV5(Trash24, {}, undefined, false, undefined, this)
281
+ }, undefined, false, undefined, this)
282
+ ]
283
+ }, undefined, true, undefined, this);
284
+ }
285
+
286
+ // src/modules/fallbacks.module.tsx
287
+ var FallbacksModule = {
288
+ name: "fallbacks",
289
+ version: "1.0.0",
290
+ requires: [],
291
+ install() {
292
+ FallbackComponentsRegistry.register("image", ImageFallback);
293
+ FallbackComponentsRegistry.register("video", VideoFallback);
294
+ FallbackComponentsRegistry.register("iframe", IFrameFallback);
295
+ FallbackComponentsRegistry.register("link", LinkFallback);
296
+ }
297
+ };
298
+
299
+ // src/components/errors/video.errors.tsx
300
+ import { AlertTriangle } from "lucide-react";
301
+ import { cn as cn6 } from "cn";
302
+ import { jsxDEV as jsxDEV6 } from "react/jsx-dev-runtime";
303
+ function VideoErrorComponent({ children, ...rest }) {
304
+ return /* @__PURE__ */ jsxDEV6("div", {
305
+ className: "w-full h-[360px] flex relative pointer-events-none",
306
+ children: [
307
+ /* @__PURE__ */ jsxDEV6("div", {
308
+ className: cn6("w-full h-full absolute inset-0 flex gap-2 items-center justify-center bg-corax-destructive/5 border-3 border-dashed border-corax-destructive"),
309
+ children: [
310
+ /* @__PURE__ */ jsxDEV6(AlertTriangle, {
311
+ className: "size-5 text-corax-destructive"
312
+ }, undefined, false, undefined, this),
313
+ "Failed to load ",
314
+ /* @__PURE__ */ jsxDEV6("span", {
315
+ className: "font-semibold",
316
+ children: rest.name
317
+ }, undefined, false, undefined, this)
318
+ ]
319
+ }, undefined, true, undefined, this),
320
+ children
321
+ ]
322
+ }, undefined, true, undefined, this);
323
+ }
324
+
325
+ // src/components/errors/image.error.tsx
326
+ import { AlertTriangle as AlertTriangle2 } from "lucide-react";
327
+ import { cn as cn7 } from "cn";
328
+ import { jsxDEV as jsxDEV7 } from "react/jsx-dev-runtime";
329
+ function ImageErrorComponent({ children, ...rest }) {
330
+ return /* @__PURE__ */ jsxDEV7("div", {
331
+ className: "w-full h-[360px] flex relative pointer-events-none",
332
+ children: [
333
+ /* @__PURE__ */ jsxDEV7("div", {
334
+ className: cn7("w-full h-full absolute inset-0 flex gap-2 items-center justify-center bg-corax-destructive/5 border-3 border-dashed border-corax-destructive"),
335
+ children: [
336
+ /* @__PURE__ */ jsxDEV7(AlertTriangle2, {
337
+ className: "size-5 text-corax-destructive"
338
+ }, undefined, false, undefined, this),
339
+ "Failed to load ",
340
+ /* @__PURE__ */ jsxDEV7("span", {
341
+ className: "font-semibold",
342
+ children: rest.name
343
+ }, undefined, false, undefined, this)
344
+ ]
345
+ }, undefined, true, undefined, this),
346
+ children
347
+ ]
348
+ }, undefined, true, undefined, this);
349
+ }
350
+
351
+ // src/components/errors/iframe.error.tsx
352
+ import { AlertTriangle as AlertTriangle3 } from "lucide-react";
353
+ import { cn as cn8 } from "cn";
354
+ import { jsxDEV as jsxDEV8 } from "react/jsx-dev-runtime";
355
+ function IFrameErrorComponent({ children, ...rest }) {
356
+ return /* @__PURE__ */ jsxDEV8("div", {
357
+ className: "w-full h-[360px] flex relative pointer-events-none",
358
+ children: [
359
+ /* @__PURE__ */ jsxDEV8("div", {
360
+ className: cn8("w-full h-full absolute inset-0 flex gap-2 items-center justify-center bg-corax-destructive/5 border-3 border-dashed border-corax-destructive"),
361
+ children: [
362
+ /* @__PURE__ */ jsxDEV8(AlertTriangle3, {
363
+ className: "size-5 text-corax-destructive"
364
+ }, undefined, false, undefined, this),
365
+ "Failed to load ",
366
+ /* @__PURE__ */ jsxDEV8("span", {
367
+ className: "font-semibold",
368
+ children: rest.name
369
+ }, undefined, false, undefined, this)
370
+ ]
371
+ }, undefined, true, undefined, this),
372
+ children
373
+ ]
374
+ }, undefined, true, undefined, this);
375
+ }
376
+
377
+ // src/modules/errors.module.tsx
378
+ var ErrorsModule = {
379
+ name: "errors",
380
+ version: "1.0.0",
381
+ requires: [],
382
+ install() {
383
+ ErrorComponentsRegistry.register("image", ImageErrorComponent);
384
+ ErrorComponentsRegistry.register("video", VideoErrorComponent);
385
+ ErrorComponentsRegistry.register("iframe", IFrameErrorComponent);
386
+ }
387
+ };
388
+
389
+ // src/hooks/use-slice.ts
390
+ import { useSyncExternalStore } from "react";
391
+ function useSlice(sliceName) {
392
+ const engine = useEngine();
393
+ const slice = useSyncExternalStore((fn) => engine.state.subscribe(sliceName, fn), () => engine.state.get(sliceName), () => engine.state.get(sliceName));
394
+ return slice;
395
+ }
396
+ // src/hooks/use-ui-context.ts
397
+ function useUIContext() {
398
+ const selection = useSlice("selection") ?? { blocks: new Map };
399
+ const focus = useSlice("focus") ?? null;
400
+ const hover = useSlice("hover") ?? null;
401
+ const textSelection = useSlice("textSelection") ?? null;
402
+ return {
403
+ selection,
404
+ focus,
405
+ hover,
406
+ textSelection
407
+ };
408
+ }
409
+ // src/hooks/custom/use-isomorphic-layout-effect.ts
410
+ import { useEffect as useEffect5, useLayoutEffect } from "react";
411
+ var useIsomorphicLayoutEffect = typeof window !== "undefined" ? useLayoutEffect : useEffect5;
412
+ // src/components/corax-context-provider.tsx
413
+ import { jsxDEV as jsxDEV9 } from "react/jsx-dev-runtime";
414
+ "use client";
415
+ var CoraxEngineContext = createContext(null);
416
+ function CoraxEngineProvider({ children }) {
417
+ const engine = useMemo(() => {
418
+ const engine2 = new Engine;
419
+ engine2.modules.register([
420
+ HistoryModule,
421
+ EditorModule,
422
+ HoverModule,
423
+ InsertionModule,
424
+ FocusModule,
425
+ SelectionModule,
426
+ TextEditingModule,
427
+ CodeModule,
428
+ CaptionModule,
429
+ MediaModule,
430
+ DividerModule,
431
+ ParagraphThemeModule,
432
+ DeletionModule,
433
+ SlotsModule,
434
+ FallbacksModule,
435
+ ErrorsModule
436
+ ]);
437
+ engine2.modules.enableAll();
438
+ return engine2;
439
+ }, []);
440
+ useEffect6(() => {
441
+ const styleEl = document.createElement("style");
442
+ styleEl.setAttribute("data-corax", "pseudo-styles");
443
+ document.head.appendChild(styleEl);
444
+ const dispose = setCoraxStyleSink(() => {
445
+ styleEl.textContent = getCollectedStyles();
446
+ });
447
+ return () => {
448
+ dispose();
449
+ styleEl.remove();
450
+ };
451
+ }, []);
452
+ useIsomorphicLayoutEffect(() => {
453
+ window.__cooraxEngine = engine;
454
+ }, [engine]);
455
+ return /* @__PURE__ */ jsxDEV9(CoraxEngineContext.Provider, {
456
+ value: engine,
457
+ children
458
+ }, undefined, false, undefined, this);
459
+ }
460
+ function useEngine() {
461
+ const engine = useContext(CoraxEngineContext);
462
+ if (!engine) {
463
+ throw new Error("useBlogEngine must be used within BlogEngineProvider");
464
+ }
465
+ return engine;
466
+ }
467
+
468
+ // src/lib/slots.utils.tsx
469
+ import { cn as cn9 } from "cn";
470
+ function getBlockActionsProps(isOpen, index) {
471
+ return {
472
+ className: cn9("absolute cursor-pointer transition-all disabled:pointer-events-none disabled:opacity-50"),
473
+ style: {
474
+ "--index": isOpen ? 0 : index,
475
+ "--step": isOpen ? "0px" : "42px",
476
+ transform: "translateX(calc((32px*var(--index)) + var(--step))"
477
+ }
478
+ };
479
+ }
480
+
481
+ // src/components/slots/buttons/block-actions-button.tsx
482
+ import { cn as cn10 } from "cn";
483
+
484
+ // src/lib/comp.utils.tsx
485
+ import { GenericRegistry as GenericRegistry4 } from "@coorax/render-react";
486
+ import { createElement } from "react";
487
+ import { Pointer } from "lucide-react";
488
+ var CoraxIconsRegistry = new GenericRegistry4;
489
+ function CoraxIcon({ icon }) {
490
+ const Icon = CoraxIconsRegistry.get(icon) ?? Pointer;
491
+ return createElement(Icon);
492
+ }
493
+
494
+ // src/lifecycle/fields/lifecycle.utils.ts
495
+ import {
496
+ UTILS
497
+ } from "@coorax/core";
498
+ function blockRectFromBlockId(id) {
499
+ const domElement = document.getElementById(id);
500
+ if (!domElement)
501
+ return null;
502
+ const parentElement = domElement.closest("#corax_flow_blocks_container");
503
+ if (!parentElement)
504
+ return null;
505
+ const rect = domElement.getBoundingClientRect();
506
+ return {
507
+ top: rect.top,
508
+ left: rect.left,
509
+ width: rect.width,
510
+ right: rect.right,
511
+ height: rect.height,
512
+ bottom: rect.bottom,
513
+ offsetTop: domElement.offsetTop,
514
+ offsetLeft: domElement.offsetLeft,
515
+ offsetHeight: domElement.offsetHeight,
516
+ offsetWidth: domElement.offsetWidth,
517
+ parentScrollLeft: parentElement.scrollLeft,
518
+ parentScrollTop: parentElement.scrollTop
519
+ };
520
+ }
521
+ function getFieldTypeAndTargetId(engine, ev, block) {
522
+ const target = block?.id ?? ev.currentTarget?.getAttribute("id") ?? null;
523
+ const fieldType = block?.type ?? ev.currentTarget?.getAttribute("data-block-type") ?? null;
524
+ if (!fieldType || !target) {
525
+ console.warn(`Failed to continue event at ${ev.type}`);
526
+ ev.preventDefault();
527
+ ev.stopPropagation();
528
+ return null;
529
+ }
530
+ const safeTarget = target;
531
+ const safeFieldType = fieldType;
532
+ function emit() {
533
+ return engine.events.emit("field:lifecycle", {
534
+ type: ev?._reactName || `on${UTILS.Capitalize(ev.type)}`,
535
+ target: safeTarget,
536
+ fieldType: safeFieldType,
537
+ cycleEvent: ev
538
+ });
539
+ }
540
+ return { fieldType: safeFieldType, target: safeTarget, emit };
541
+ }
542
+
543
+ // src/components/slots/buttons/block-actions-button.tsx
544
+ import React2 from "react";
545
+ import { jsxDEV as jsxDEV10 } from "react/jsx-dev-runtime";
546
+ var BlockActionButton = React2.memo(function BlockActionButton2({
547
+ c,
548
+ ui,
549
+ ...rest
550
+ }) {
551
+ const engine = useEngine();
552
+ const isOpen = useSlice("insertion");
553
+ const selection = useSlice("selection");
554
+ const { blocks: _selectionBLocks = new Map } = selection ?? {};
555
+ if (c.name !== "BlockActionButton")
556
+ return null;
557
+ if (!c.when?.(ui) || c.kind !== "button")
558
+ return null;
559
+ const { variant, size, isBaseButton = false, type } = c.getProps(ui);
560
+ const enabled = engine.commands.has(c.command);
561
+ return /* @__PURE__ */ jsxDEV10(Button, {
562
+ ...rest,
563
+ variant,
564
+ size,
565
+ disabled: !enabled,
566
+ role: `actions-${type}`,
567
+ ...!isBaseButton ? getBlockActionsProps(!isOpen, c.order ? c.order - 1 : 0) : {
568
+ className: cn10("z-99 cursor-pointer transition-all", {
569
+ "rotate-45": isOpen
570
+ })
571
+ },
572
+ onClick: () => {
573
+ if (c.command === "fields.change") {
574
+ const payload2 = c.getPayload(ui);
575
+ if (!payload2)
576
+ return;
577
+ engine.commands.tryExecute(c.command, payload2);
578
+ setTimeout(() => {
579
+ const rect = blockRectFromBlockId(payload2.fieldId);
580
+ if (!rect)
581
+ return;
582
+ engine.commands.tryExecute("blocks.focus", {
583
+ id: payload2.fieldId,
584
+ rect
585
+ });
586
+ }, 0);
587
+ return;
588
+ }
589
+ const payload = c.getPayload(ui);
590
+ if (payload !== null)
591
+ engine.commands.tryExecute(c.command, payload);
592
+ },
593
+ children: [
594
+ /* @__PURE__ */ jsxDEV10(CoraxIcon, {
595
+ icon: c.icon
596
+ }, undefined, false, undefined, this),
597
+ c.label
598
+ ]
599
+ }, undefined, true, undefined, this);
600
+ }, () => true);
601
+
602
+ // src/components/slots/buttons/toolbar-button.tsx
603
+ import React3 from "react";
604
+ import { jsxDEV as jsxDEV11 } from "react/jsx-dev-runtime";
605
+ var ToolbarButton = React3.memo(function ToolbarButton2({
606
+ c,
607
+ ui,
608
+ ...rest
609
+ }) {
610
+ const engine = useEngine();
611
+ const marks = useSlice("currentMarks");
612
+ const payload = c.getPayload(ui);
613
+ if (!payload)
614
+ return null;
615
+ const isActive = !!c.getProps(ui)?.isActive || marks?.find((mark) => mark.type === payload.format);
616
+ return /* @__PURE__ */ jsxDEV11(Button, {
617
+ ...rest,
618
+ role: `toolbar-${payload.format}`,
619
+ onClick: () => {
620
+ const payload2 = c.getPayload(ui);
621
+ if (payload2)
622
+ engine.commands.tryExecute(c.command, payload2);
623
+ },
624
+ title: c.label,
625
+ size: "icon-xs",
626
+ className: "rounded-lg cursor-pointer",
627
+ variant: isActive ? "default" : "secondary",
628
+ children: /* @__PURE__ */ jsxDEV11(CoraxIcon, {
629
+ icon: c.icon
630
+ }, undefined, false, undefined, this)
631
+ }, c.id, false, undefined, this);
632
+ }, (prev, next) => {
633
+ const prevActive = prev.c.getProps(prev.ui);
634
+ const nextActive = next.c.getProps(next.ui);
635
+ return prevActive === nextActive;
636
+ });
637
+
638
+ // src/components/slots/buttons/code-theme-button.tsx
639
+ import React4 from "react";
640
+ import { jsxDEV as jsxDEV12 } from "react/jsx-dev-runtime";
641
+ var CodeThemeButton = React4.memo(function CodeThemeButton2({
642
+ c,
643
+ ui,
644
+ ...rest
645
+ }) {
646
+ const engine = useEngine();
647
+ return /* @__PURE__ */ jsxDEV12(Button, {
648
+ ...rest,
649
+ onClick: () => {
650
+ const payload = c.getPayload(ui);
651
+ if (payload)
652
+ engine.commands.tryExecute(c.command, payload);
653
+ },
654
+ title: c.label ?? "Toggle code theme",
655
+ size: "icon-xs",
656
+ className: "rounded-lg cursor-pointer",
657
+ variant: "secondary",
658
+ children: /* @__PURE__ */ jsxDEV12(CoraxIcon, {
659
+ icon: c.icon
660
+ }, undefined, false, undefined, this)
661
+ }, c.id, false, undefined, this);
662
+ });
663
+
664
+ // src/components/slots/buttons/caption-button.tsx
665
+ import React5 from "react";
666
+ import { jsxDEV as jsxDEV13 } from "react/jsx-dev-runtime";
667
+ var CaptionButton = React5.memo(function CaptionButton2({
668
+ c,
669
+ ui,
670
+ ...rest
671
+ }) {
672
+ const engine = useEngine();
673
+ return /* @__PURE__ */ jsxDEV13(Button, {
674
+ ...rest,
675
+ onClick: () => {
676
+ const payload = c.getPayload(ui);
677
+ if (payload)
678
+ engine.commands.tryExecute(c.command, payload);
679
+ },
680
+ title: c.label ?? "Add caption",
681
+ size: "icon-xs",
682
+ className: "rounded-lg cursor-pointer",
683
+ variant: "secondary",
684
+ children: /* @__PURE__ */ jsxDEV13(CoraxIcon, {
685
+ icon: c.icon
686
+ }, undefined, false, undefined, this)
687
+ }, c.id, false, undefined, this);
688
+ });
689
+
690
+ // src/components/slots/buttons/delete-button.tsx
691
+ import React6 from "react";
692
+ import { jsxDEV as jsxDEV14 } from "react/jsx-dev-runtime";
693
+ var DeleteButton = React6.memo(function DeleteButton2({
694
+ c,
695
+ ui,
696
+ ...rest
697
+ }) {
698
+ const engine = useEngine();
699
+ return /* @__PURE__ */ jsxDEV14(Button, {
700
+ ...rest,
701
+ onClick: () => {
702
+ const payload = c.getPayload(ui);
703
+ if (payload !== null)
704
+ engine.commands.tryExecute(c.command, payload);
705
+ },
706
+ title: c.label ?? "Delete",
707
+ size: "icon-xs",
708
+ className: "rounded-lg cursor-pointer text-corax-destructive",
709
+ variant: "secondary",
710
+ children: /* @__PURE__ */ jsxDEV14(CoraxIcon, {
711
+ icon: c.icon
712
+ }, undefined, false, undefined, this)
713
+ }, c.id, false, undefined, this);
714
+ });
715
+
716
+ // src/components/slots/buttons/iframe-playback-button.tsx
717
+ import React7 from "react";
718
+ import { jsxDEV as jsxDEV15 } from "react/jsx-dev-runtime";
719
+ var IframePlaybackButton = React7.memo(function IframePlaybackButton2({
720
+ c,
721
+ ui,
722
+ ...rest
723
+ }) {
724
+ const engine = useEngine();
725
+ const [isPlaying, setIsPlaying] = React7.useState(false);
726
+ return /* @__PURE__ */ jsxDEV15(Button, {
727
+ ...rest,
728
+ onClick: () => {
729
+ const payload = c.getPayload(ui);
730
+ if (!payload)
731
+ return;
732
+ const { fieldId } = payload;
733
+ engine.commands.tryExecute(c.command, { fieldId, action: isPlaying ? "pause" : "play" });
734
+ setIsPlaying(!isPlaying);
735
+ },
736
+ title: c.label ?? "Play/Pause",
737
+ size: "icon-xs",
738
+ className: "rounded-lg cursor-pointer",
739
+ variant: "secondary",
740
+ children: /* @__PURE__ */ jsxDEV15(CoraxIcon, {
741
+ icon: isPlaying ? "PauseIcon" : "PlayIcon"
742
+ }, undefined, false, undefined, this)
743
+ }, c.id, false, undefined, this);
744
+ });
745
+
746
+ // src/hooks/use-block.ts
747
+ import { useSyncExternalStore as useSyncExternalStore2 } from "react";
748
+ function useBlock(id) {
749
+ const engine = useEngine();
750
+ return useSyncExternalStore2((fn) => engine.document.subscribeBlock(id, fn), () => engine.document.getBlock(id), () => engine.document.getBlock(id));
751
+ }
752
+
753
+ // src/components/slots/buttons/image-width-button.tsx
754
+ import React8 from "react";
755
+ import { jsxDEV as jsxDEV16 } from "react/jsx-dev-runtime";
756
+ var ImageWidthButton = React8.memo(function ImageWidthButton2({
757
+ c,
758
+ ui,
759
+ ...rest
760
+ }) {
761
+ const engine = useEngine();
762
+ const payload = c.getPayload(ui);
763
+ const { fieldId, width } = payload ?? { fieldId: "", width: "" };
764
+ const block = useBlock(fieldId);
765
+ if (!payload)
766
+ return null;
767
+ return /* @__PURE__ */ jsxDEV16(Button, {
768
+ ...rest,
769
+ onClick: () => {
770
+ const payload2 = c.getPayload(ui);
771
+ if (payload2)
772
+ engine.commands.tryExecute(c.command, payload2);
773
+ },
774
+ title: c.label ?? "Image width",
775
+ size: "icon-xs",
776
+ className: "rounded-lg cursor-pointer",
777
+ variant: block?.props.style?.width === width ? "default" : "secondary",
778
+ children: /* @__PURE__ */ jsxDEV16(CoraxIcon, {
779
+ icon: c.icon
780
+ }, undefined, false, undefined, this)
781
+ }, c.id, false, undefined, this);
782
+ });
783
+
784
+ // src/components/slots/buttons/divider-width-button.tsx
785
+ import React9 from "react";
786
+ import { jsxDEV as jsxDEV17 } from "react/jsx-dev-runtime";
787
+ var DividerWidthButton = React9.memo(function DividerWidthButton2({
788
+ c,
789
+ ui,
790
+ ...rest
791
+ }) {
792
+ const engine = useEngine();
793
+ const payload = c.getPayload(ui);
794
+ const { fieldId, width } = payload ?? { fieldId: "", width: "" };
795
+ const block = useBlock(fieldId);
796
+ if (!payload)
797
+ return null;
798
+ return /* @__PURE__ */ jsxDEV17(Button, {
799
+ ...rest,
800
+ onClick: () => {
801
+ const payload2 = c.getPayload(ui);
802
+ if (payload2)
803
+ engine.commands.tryExecute(c.command, payload2);
804
+ },
805
+ title: c.label ?? "Divider width",
806
+ size: "icon-xs",
807
+ className: "rounded-lg cursor-pointer",
808
+ variant: block?.props.style?.width === width ? "default" : "secondary",
809
+ children: /* @__PURE__ */ jsxDEV17(CoraxIcon, {
810
+ icon: c.icon
811
+ }, undefined, false, undefined, this)
812
+ }, c.id, false, undefined, this);
813
+ });
814
+
815
+ // src/components/slots/buttons/divider-style-button.tsx
816
+ import React10 from "react";
817
+ import { jsxDEV as jsxDEV18 } from "react/jsx-dev-runtime";
818
+ var DividerStyleButton = React10.memo(function DividerStyleButton2({
819
+ c,
820
+ ui,
821
+ ...rest
822
+ }) {
823
+ const engine = useEngine();
824
+ const payload = c.getPayload(ui);
825
+ const { fieldId } = payload ?? { fieldId: "" };
826
+ const block = useBlock(fieldId);
827
+ const targetStyle = c.getProps(ui)?.borderStyle ?? "solid";
828
+ const isActive = (block?.props.style?.borderTopStyle ?? "solid") === targetStyle;
829
+ if (!payload)
830
+ return null;
831
+ return /* @__PURE__ */ jsxDEV18(Button, {
832
+ ...rest,
833
+ onClick: () => {
834
+ const payload2 = c.getPayload(ui);
835
+ if (payload2)
836
+ engine.commands.tryExecute(c.command, payload2);
837
+ },
838
+ title: c.label ?? "Divider style",
839
+ size: "icon-xs",
840
+ className: "rounded-lg cursor-pointer",
841
+ variant: isActive ? "default" : "secondary",
842
+ children: /* @__PURE__ */ jsxDEV18("span", {
843
+ "aria-hidden": true,
844
+ style: {
845
+ display: "block",
846
+ width: 14,
847
+ borderTopWidth: 2,
848
+ borderTopStyle: targetStyle,
849
+ borderTopColor: "currentColor"
850
+ }
851
+ }, undefined, false, undefined, this)
852
+ }, c.id, false, undefined, this);
853
+ });
854
+
855
+ // src/components/slots/overlays/focus-overlay.tsx
856
+ import { useEffect as useEffect7 } from "react";
857
+
858
+ // src/lib/func.utils.ts
859
+ function focusDomBLockById(engine, id) {
860
+ const disposer = engine.events.on("re-render", () => {
861
+ focusDomElement(id);
862
+ disposer();
863
+ });
864
+ }
865
+ function focusDomElement(id) {
866
+ const domElement = document.getElementById(id);
867
+ if (!domElement)
868
+ return;
869
+ domElement.focus();
870
+ }
871
+
872
+ // src/components/slots/overlays/focus-overlay.tsx
873
+ import { jsxDEV as jsxDEV19 } from "react/jsx-dev-runtime";
874
+ function FocusOverlay({
875
+ c,
876
+ ui
877
+ }) {
878
+ const { position = null, hidden = null } = c.getProps(ui) ?? {};
879
+ const focusedId = ui.focus?.id;
880
+ useEffect7(() => {
881
+ if (!focusedId)
882
+ return;
883
+ focusDomElement(focusedId);
884
+ }, [focusedId]);
885
+ if (hidden || !position)
886
+ return null;
887
+ return /* @__PURE__ */ jsxDEV19("div", {
888
+ style: position,
889
+ className: "absolute border border-blue-700 pointer-events-none flex justify-end"
890
+ }, undefined, false, undefined, this);
891
+ }
892
+
893
+ // src/components/slots/overlays/hover-overlay.tsx
894
+ import { jsxDEV as jsxDEV20 } from "react/jsx-dev-runtime";
895
+ function HoverOverlay({
896
+ c,
897
+ ui
898
+ }) {
899
+ const { position = null, hidden = null } = c.getProps(ui) ?? {};
900
+ if (hidden || !position)
901
+ return null;
902
+ return /* @__PURE__ */ jsxDEV20("div", {
903
+ style: position,
904
+ className: "absolute border-[0.5px] border-blue-400 pointer-events-none flex justify-end"
905
+ }, undefined, false, undefined, this);
906
+ }
907
+
908
+ // src/components/slots/overlays/selection-overlay.tsx
909
+ import { jsxDEV as jsxDEV21 } from "react/jsx-dev-runtime";
910
+ function SelectionOverlay({
911
+ c,
912
+ ui
913
+ }) {
914
+ const { position = null, hidden = null } = c.getProps(ui) ?? {};
915
+ if (hidden || !position)
916
+ return null;
917
+ return /* @__PURE__ */ jsxDEV21("div", {
918
+ style: position,
919
+ className: "absolute border border-blue-500 pointer-events-none flex justify-end"
920
+ }, undefined, false, undefined, this);
921
+ }
922
+
923
+ // src/modules/slots.module.tsx
924
+ import {
925
+ TextCursor,
926
+ PointerIcon,
927
+ HeadingIcon,
928
+ Heading2,
929
+ PlusIcon,
930
+ BoldIcon,
931
+ ItalicIcon,
932
+ UnderlineIcon,
933
+ LinkIcon,
934
+ ImagePlus,
935
+ TextInitialIcon,
936
+ Minus,
937
+ TvMinimalPlayIcon,
938
+ FileTextIcon,
939
+ QuoteIcon,
940
+ BracesIcon,
941
+ PaletteIcon,
942
+ Captions,
943
+ Trash2 as Trash25,
944
+ Play,
945
+ Pause,
946
+ MoveHorizontal,
947
+ Expand,
948
+ LineStyle,
949
+ OctagonExclamationPoint,
950
+ OctagonX,
951
+ InfoIcon,
952
+ CircleLetterI
953
+ } from "lucide-react";
954
+
955
+ // src/components/commons/youtube.tsx
956
+ import { cn as cn11 } from "cn";
957
+ import { jsxDEV as jsxDEV22 } from "react/jsx-dev-runtime";
958
+ function YoutubeIcon({ className, ...props }) {
959
+ return /* @__PURE__ */ jsxDEV22("svg", {
960
+ xmlns: "http://www.w3.org/2000/svg",
961
+ viewBox: "0 0 24 24",
962
+ fill: "none",
963
+ className: cn11("text-corax-foreground", className),
964
+ ...props,
965
+ children: /* @__PURE__ */ jsxDEV22("path", {
966
+ fillRule: "evenodd",
967
+ clipRule: "evenodd",
968
+ 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",
969
+ stroke: "currentColor",
970
+ strokeLinejoin: "round",
971
+ strokeWidth: 2
972
+ }, undefined, false, undefined, this)
973
+ }, undefined, false, undefined, this);
974
+ }
975
+ // src/lib/selection.utils.ts
976
+ function rangeToOffsets(root, range) {
977
+ const measure = (node, offset) => {
978
+ const r = document.createRange();
979
+ r.selectNodeContents(root);
980
+ r.setEnd(node, offset);
981
+ return r.toString().length;
982
+ };
983
+ return {
984
+ start: measure(range.startContainer, range.startOffset),
985
+ end: measure(range.endContainer, range.endOffset)
986
+ };
987
+ }
988
+ function offsetsToRange(root, start, end) {
989
+ const range = document.createRange();
990
+ const walker = document.createTreeWalker(root, NodeFilter.SHOW_TEXT);
991
+ let pos = 0, startSet = false;
992
+ for (let n = walker.nextNode();n; n = walker.nextNode()) {
993
+ const next = pos + n.length;
994
+ if (!startSet && start <= next) {
995
+ range.setStart(n, start - pos);
996
+ startSet = true;
997
+ }
998
+ if (startSet && end <= next) {
999
+ range.setEnd(n, end - pos);
1000
+ return range;
1001
+ }
1002
+ pos = next;
1003
+ }
1004
+ return null;
1005
+ }
1006
+ // src/components/slots/buttons/paragraph-theme-button.tsx
1007
+ import {
1008
+ getParagraphTheme
1009
+ } from "@coorax/core";
1010
+ import React11 from "react";
1011
+ import { cn as cn12 } from "cn";
1012
+ import { jsxDEV as jsxDEV23 } from "react/jsx-dev-runtime";
1013
+ var ParagraphThemeButton = React11.memo(function ParagraphThemeButton2({
1014
+ c,
1015
+ ui,
1016
+ ...rest
1017
+ }) {
1018
+ const engine = useEngine();
1019
+ const payload = c.getPayload(ui);
1020
+ const { fieldId, theme } = payload ?? { fieldId: "", theme: "" };
1021
+ const block = useBlock(fieldId);
1022
+ const isActive = !!block && getParagraphTheme(block.props.children) === theme;
1023
+ if (!payload)
1024
+ return null;
1025
+ const props = c.getProps(ui);
1026
+ return /* @__PURE__ */ jsxDEV23(Button, {
1027
+ ...rest,
1028
+ onClick: () => {
1029
+ const payload2 = c.getPayload(ui);
1030
+ if (payload2)
1031
+ engine.commands.tryExecute(c.command, payload2);
1032
+ },
1033
+ title: c.label ?? "Paragraph theme",
1034
+ size: "icon-xs",
1035
+ className: cn12("rounded-lg cursor-pointer", {
1036
+ "bg-[#FF4D4F]/30": props.theme === "error" && !isActive,
1037
+ "bg-[#FF9900]/30": props.theme === "warning" && !isActive,
1038
+ "bg-[#007AFF]/30": props.theme === "info" && !isActive
1039
+ }),
1040
+ variant: isActive ? "default" : "secondary",
1041
+ children: /* @__PURE__ */ jsxDEV23(CoraxIcon, {
1042
+ icon: c.icon
1043
+ }, undefined, false, undefined, this)
1044
+ }, c.id, false, undefined, this);
1045
+ });
1046
+
1047
+ // src/modules/slots.module.tsx
1048
+ var SlotsModule = {
1049
+ name: "slots",
1050
+ version: "1.0.0",
1051
+ requires: [],
1052
+ install() {
1053
+ SlotsComponentRegistry.register("BlockActionButton", BlockActionButton);
1054
+ SlotsComponentRegistry.register("ToolBarButton", ToolbarButton);
1055
+ SlotsComponentRegistry.register("CodeThemeButton", CodeThemeButton);
1056
+ SlotsComponentRegistry.register("CaptionButton", CaptionButton);
1057
+ SlotsComponentRegistry.register("DeleteButton", DeleteButton);
1058
+ SlotsComponentRegistry.register("IframePlaybackButton", IframePlaybackButton);
1059
+ SlotsComponentRegistry.register("ImageWidthButton", ImageWidthButton);
1060
+ SlotsComponentRegistry.register("DividerWidthButton", DividerWidthButton);
1061
+ SlotsComponentRegistry.register("DividerStyleButton", DividerStyleButton);
1062
+ SlotsComponentRegistry.register("ParagraphThemeButton", ParagraphThemeButton);
1063
+ SlotsComponentRegistry.register("SelectionOverlay", SelectionOverlay);
1064
+ SlotsComponentRegistry.register("FocusOverlay", FocusOverlay);
1065
+ SlotsComponentRegistry.register("HoverOverlay", HoverOverlay);
1066
+ CoraxIconsRegistry.register("TextIcon", TextCursor);
1067
+ CoraxIconsRegistry.register("CursorIcon", PointerIcon);
1068
+ CoraxIconsRegistry.register("HeadingIcon", HeadingIcon);
1069
+ CoraxIconsRegistry.register("Heading2Icon", Heading2);
1070
+ CoraxIconsRegistry.register("PlusIcon", PlusIcon);
1071
+ CoraxIconsRegistry.register("BoldIcon", BoldIcon);
1072
+ CoraxIconsRegistry.register("ItalicIcon", ItalicIcon);
1073
+ CoraxIconsRegistry.register("UnderlineIcon", UnderlineIcon);
1074
+ CoraxIconsRegistry.register("LinkIcon", LinkIcon);
1075
+ CoraxIconsRegistry.register("ImagePlus", ImagePlus);
1076
+ CoraxIconsRegistry.register("TextInitial", TextInitialIcon);
1077
+ CoraxIconsRegistry.register("DividerIcon", Minus);
1078
+ CoraxIconsRegistry.register("TvMinimalPlayIcon", TvMinimalPlayIcon);
1079
+ CoraxIconsRegistry.register("YoutubeIcon", YoutubeIcon);
1080
+ CoraxIconsRegistry.register("FileTextIcon", FileTextIcon);
1081
+ CoraxIconsRegistry.register("QuoteIcon", QuoteIcon);
1082
+ CoraxIconsRegistry.register("CodeIcon", BracesIcon);
1083
+ CoraxIconsRegistry.register("PaletteIcon", PaletteIcon);
1084
+ CoraxIconsRegistry.register("CaptionsIcon", Captions);
1085
+ CoraxIconsRegistry.register("TrashIcon", Trash25);
1086
+ CoraxIconsRegistry.register("PlayIcon", Play);
1087
+ CoraxIconsRegistry.register("PauseIcon", Pause);
1088
+ CoraxIconsRegistry.register("MoveHorizontalIcon", MoveHorizontal);
1089
+ CoraxIconsRegistry.register("ExpandIcon", Expand);
1090
+ CoraxIconsRegistry.register("LineStyleIcon", LineStyle);
1091
+ CoraxIconsRegistry.register("ThemeWarningIcon", OctagonExclamationPoint);
1092
+ CoraxIconsRegistry.register("ThemeErrorIcon", OctagonX);
1093
+ CoraxIconsRegistry.register("ThemeInfoIcon", InfoIcon);
1094
+ CoraxIconsRegistry.register("ThemeNeutralIcon", CircleLetterI);
1095
+ }
1096
+ };
1097
+ // src/modules/autosave.module.ts
1098
+ import { SerializeTree } from "@coorax/core";
1099
+
1100
+ // src/services/localdb/lexer/lexer.ts
1101
+ class Lexer {
1102
+ pos = 0;
1103
+ word = [];
1104
+ tokensTypes = [
1105
+ "SELECT",
1106
+ "FROM",
1107
+ "WHERE",
1108
+ "JOIN",
1109
+ "INNER",
1110
+ "LEFT",
1111
+ "RIGHT",
1112
+ "FULL",
1113
+ "CROSS",
1114
+ "ON",
1115
+ "AND",
1116
+ "OR",
1117
+ "AS",
1118
+ "INSERT",
1119
+ "INTO",
1120
+ "VALUES",
1121
+ "CREATE",
1122
+ "TABLE",
1123
+ "DELETE"
1124
+ ];
1125
+ cleanWord() {
1126
+ this.word = [];
1127
+ }
1128
+ bumpPos() {
1129
+ this.pos++;
1130
+ }
1131
+ flushWord(tokens) {
1132
+ if (this.word.length === 0)
1133
+ return;
1134
+ const currentWord = this.word.join("");
1135
+ const upper = currentWord.toUpperCase();
1136
+ if (this.tokensTypes.includes(upper)) {
1137
+ tokens.push({
1138
+ type: upper,
1139
+ value: upper
1140
+ });
1141
+ } else {
1142
+ tokens.push({
1143
+ type: "IDENTIFIER",
1144
+ value: currentWord
1145
+ });
1146
+ }
1147
+ this.cleanWord();
1148
+ }
1149
+ lex(sql) {
1150
+ const sqlString = sql.replace(/[\r\n]+/g, " ").trim();
1151
+ const tokens = [];
1152
+ if (!sqlString.endsWith(";")) {
1153
+ throw new Error(`Failed to execute sql. ';' missing at the end`);
1154
+ }
1155
+ this.pos = 0;
1156
+ this.cleanWord();
1157
+ while (this.pos < sqlString.length) {
1158
+ const currentChar = sqlString[this.pos];
1159
+ if (currentChar === "'" || currentChar === '"') {
1160
+ this.flushWord(tokens);
1161
+ const quoteChar = currentChar;
1162
+ this.bumpPos();
1163
+ const strChars = [];
1164
+ let closed = false;
1165
+ while (this.pos < sqlString.length) {
1166
+ const char = sqlString[this.pos];
1167
+ if (char === "\\") {
1168
+ this.bumpPos();
1169
+ if (this.pos < sqlString.length) {
1170
+ strChars.push(sqlString[this.pos]);
1171
+ this.bumpPos();
1172
+ }
1173
+ continue;
1174
+ }
1175
+ if (char === quoteChar) {
1176
+ this.bumpPos();
1177
+ closed = true;
1178
+ break;
1179
+ }
1180
+ strChars.push(char);
1181
+ this.bumpPos();
1182
+ }
1183
+ if (!closed) {
1184
+ throw new Error(`Unterminated string literal at ${this.pos}`);
1185
+ }
1186
+ tokens.push({
1187
+ type: "STRING",
1188
+ value: strChars.join("")
1189
+ });
1190
+ continue;
1191
+ }
1192
+ if (currentChar === " " || currentChar === "\t") {
1193
+ this.flushWord(tokens);
1194
+ this.bumpPos();
1195
+ continue;
1196
+ }
1197
+ switch (currentChar) {
1198
+ case ",":
1199
+ this.flushWord(tokens);
1200
+ tokens.push({ type: "COMMA", value: "," });
1201
+ this.bumpPos();
1202
+ continue;
1203
+ case ";":
1204
+ this.flushWord(tokens);
1205
+ tokens.push({ type: "SEMICOLON", value: ";" });
1206
+ this.bumpPos();
1207
+ continue;
1208
+ case "(":
1209
+ this.flushWord(tokens);
1210
+ tokens.push({ type: "BRACKETS", value: "(" });
1211
+ this.bumpPos();
1212
+ continue;
1213
+ case ")":
1214
+ this.flushWord(tokens);
1215
+ tokens.push({ type: "BRACKETS", value: ")" });
1216
+ this.bumpPos();
1217
+ continue;
1218
+ case "*":
1219
+ this.flushWord(tokens);
1220
+ tokens.push({ type: "STAR", value: "*" });
1221
+ this.bumpPos();
1222
+ continue;
1223
+ case "=":
1224
+ this.flushWord(tokens);
1225
+ tokens.push({ type: "EQUALS", value: "=" });
1226
+ this.bumpPos();
1227
+ continue;
1228
+ case "?":
1229
+ this.flushWord(tokens);
1230
+ tokens.push({ type: "QUESTION_MARK", value: "?" });
1231
+ this.bumpPos();
1232
+ continue;
1233
+ default:
1234
+ this.word.push(currentChar);
1235
+ this.bumpPos();
1236
+ continue;
1237
+ }
1238
+ }
1239
+ this.flushWord(tokens);
1240
+ this.pos = 0;
1241
+ this.cleanWord();
1242
+ return tokens;
1243
+ }
1244
+ }
1245
+
1246
+ // src/services/localdb/parser/parser.constants.ts
1247
+ var TYPES_DEFS = [
1248
+ "TEXT",
1249
+ "DATETIME",
1250
+ "INTEGER",
1251
+ "UUID",
1252
+ "OBJECT",
1253
+ "ARRAY[STRING]",
1254
+ "FILE",
1255
+ "BLOB"
1256
+ ];
1257
+ var TYPES_DEFS_MAPPING = {
1258
+ TEXT: "string",
1259
+ INTEGER: "number",
1260
+ DATETIME: "number",
1261
+ UUID: "uuid",
1262
+ OBJECT: "object",
1263
+ "ARRAY[STRING]": "array.string",
1264
+ FILE: "file",
1265
+ BLOB: "blob"
1266
+ };
1267
+
1268
+ // src/services/localdb/parser/parser.ts
1269
+ class Parser {
1270
+ statementTypes = ["SELECT", "INSERT", "CREATE", "DELETE"];
1271
+ foundTable(tokens) {
1272
+ return tokens.find((token, idx) => {
1273
+ return token.type === "IDENTIFIER" && ["FROM", "INTO", "TABLE"].includes(tokens[idx - 1]?.type);
1274
+ });
1275
+ }
1276
+ parseSelect(tokens) {
1277
+ const fromIndex = tokens.findIndex((t) => t.type === "FROM");
1278
+ if (fromIndex === -1) {
1279
+ throw new Error("Invalid SELECT statement: missing FROM clause");
1280
+ }
1281
+ const isAllFieldsWanted = tokens.slice(0, fromIndex).some((t) => t.type === "STAR");
1282
+ const columns = isAllFieldsWanted ? ["*"] : tokens.slice(1, fromIndex).filter((t) => t.type === "IDENTIFIER" || t.type === "STRING").map((t) => t.value);
1283
+ const tableToken = tokens[fromIndex + 1];
1284
+ if (!tableToken || tableToken.type !== "IDENTIFIER") {
1285
+ throw new Error("Invalid SELECT statement: missing table name after FROM");
1286
+ }
1287
+ const mainTable = tableToken.value;
1288
+ let cursor = fromIndex + 2;
1289
+ let mainAlias;
1290
+ if (cursor < tokens.length) {
1291
+ if (tokens[cursor]?.type === "AS" && tokens[cursor + 1]?.type === "IDENTIFIER") {
1292
+ mainAlias = tokens[cursor + 1].value;
1293
+ cursor += 2;
1294
+ } else if (tokens[cursor]?.type === "IDENTIFIER" && !["JOIN", "INNER", "LEFT", "RIGHT", "FULL", "CROSS", "WHERE", "SEMICOLON"].includes(tokens[cursor].type)) {
1295
+ mainAlias = tokens[cursor].value;
1296
+ cursor++;
1297
+ }
1298
+ }
1299
+ const joins = [];
1300
+ while (cursor < tokens.length) {
1301
+ const currentToken = tokens[cursor];
1302
+ if (!currentToken || currentToken.type === "SEMICOLON" || currentToken.type === "WHERE") {
1303
+ break;
1304
+ }
1305
+ let joinType = "JOIN";
1306
+ let hasJoin = false;
1307
+ if (currentToken.type === "JOIN") {
1308
+ joinType = "JOIN";
1309
+ cursor++;
1310
+ hasJoin = true;
1311
+ } else if (["INNER", "LEFT", "RIGHT", "FULL", "CROSS"].includes(currentToken.type) && tokens[cursor + 1]?.type === "JOIN") {
1312
+ joinType = currentToken.type;
1313
+ cursor += 2;
1314
+ hasJoin = true;
1315
+ }
1316
+ if (!hasJoin) {
1317
+ break;
1318
+ }
1319
+ const joinTableToken = tokens[cursor];
1320
+ if (!joinTableToken || joinTableToken.type !== "IDENTIFIER") {
1321
+ throw new Error(`Expected table name after ${joinType} JOIN`);
1322
+ }
1323
+ const joinTable = joinTableToken.value;
1324
+ cursor++;
1325
+ let joinAlias;
1326
+ if (cursor < tokens.length) {
1327
+ if (tokens[cursor]?.type === "AS" && tokens[cursor + 1]?.type === "IDENTIFIER") {
1328
+ joinAlias = tokens[cursor + 1].value;
1329
+ cursor += 2;
1330
+ } else if (tokens[cursor]?.type === "IDENTIFIER" && tokens[cursor].value.toUpperCase() !== "ON" && !["JOIN", "INNER", "LEFT", "RIGHT", "FULL", "CROSS", "WHERE", "SEMICOLON"].includes(tokens[cursor].type)) {
1331
+ joinAlias = tokens[cursor].value;
1332
+ cursor++;
1333
+ }
1334
+ }
1335
+ let joinCondition;
1336
+ if (tokens[cursor]?.type === "ON") {
1337
+ cursor++;
1338
+ const leftToken = tokens[cursor];
1339
+ cursor++;
1340
+ const opToken = tokens[cursor];
1341
+ cursor++;
1342
+ const rightToken = tokens[cursor];
1343
+ cursor++;
1344
+ if (!leftToken || !opToken || !rightToken || opToken.type !== "EQUALS" && opToken.value !== "=") {
1345
+ throw new Error(`Invalid ON clause syntax in JOIN ${joinTable}`);
1346
+ }
1347
+ const leftParts = leftToken.value.split(".");
1348
+ const rightParts = rightToken.value.split(".");
1349
+ const leftTable = leftParts.length > 1 ? leftParts[0] : undefined;
1350
+ const leftColumn = leftParts.length > 1 ? leftParts[1] : leftParts[0];
1351
+ const rightTable = rightParts.length > 1 ? rightParts[0] : undefined;
1352
+ const rightColumn = rightParts.length > 1 ? rightParts[1] : rightParts[0];
1353
+ joinCondition = {
1354
+ leftTable,
1355
+ leftColumn,
1356
+ operator: "=",
1357
+ rightTable,
1358
+ rightColumn
1359
+ };
1360
+ }
1361
+ joins.push({
1362
+ type: joinType,
1363
+ table: joinTable,
1364
+ alias: joinAlias,
1365
+ on: joinCondition
1366
+ });
1367
+ }
1368
+ const where = [];
1369
+ if (tokens[cursor]?.type === "WHERE") {
1370
+ cursor++;
1371
+ while (cursor < tokens.length) {
1372
+ const colToken = tokens[cursor];
1373
+ if (!colToken || colToken.type === "SEMICOLON")
1374
+ break;
1375
+ cursor++;
1376
+ const opToken = tokens[cursor];
1377
+ cursor++;
1378
+ const valToken = tokens[cursor];
1379
+ cursor++;
1380
+ if (colToken && opToken && valToken) {
1381
+ const colParts = colToken.value.split(".");
1382
+ const table = colParts.length > 1 ? colParts[0] : undefined;
1383
+ const column = colParts.length > 1 ? colParts[1] : colParts[0];
1384
+ where.push({
1385
+ table,
1386
+ column,
1387
+ operator: opToken.value || "=",
1388
+ value: valToken.value
1389
+ });
1390
+ }
1391
+ if (tokens[cursor]?.type === "AND" || tokens[cursor]?.type === "OR") {
1392
+ cursor++;
1393
+ } else {
1394
+ break;
1395
+ }
1396
+ }
1397
+ }
1398
+ return {
1399
+ type: "SELECT",
1400
+ columns,
1401
+ table: mainTable,
1402
+ alias: mainAlias,
1403
+ joins: joins.length > 0 ? joins : undefined,
1404
+ where: where.length > 0 ? where : undefined
1405
+ };
1406
+ }
1407
+ parseInsert(tokens, params, paramState = { index: 0 }) {
1408
+ const intoIndex = tokens.findIndex((t) => t.type === "INTO");
1409
+ if (intoIndex === -1) {
1410
+ throw new Error("Invalid INSERT statement: missing INTO keyword");
1411
+ }
1412
+ const tableToken = tokens[intoIndex + 1];
1413
+ if (!tableToken || tableToken.type !== "IDENTIFIER") {
1414
+ throw new Error("Invalid INSERT statement: missing table name");
1415
+ }
1416
+ const table = tableToken.value;
1417
+ let cursor = intoIndex + 2;
1418
+ let fields;
1419
+ if (tokens[cursor]?.type === "BRACKETS" && tokens[cursor]?.value === "(") {
1420
+ cursor++;
1421
+ fields = [];
1422
+ while (cursor < tokens.length) {
1423
+ const t = tokens[cursor];
1424
+ if (t.type === "BRACKETS" && t.value === ")") {
1425
+ cursor++;
1426
+ break;
1427
+ }
1428
+ if (t.type === "IDENTIFIER") {
1429
+ fields.push(t.value);
1430
+ }
1431
+ cursor++;
1432
+ }
1433
+ }
1434
+ const valuesIndex = tokens.slice(cursor).findIndex((t) => t.type === "VALUES");
1435
+ if (valuesIndex === -1) {
1436
+ throw new Error("Invalid INSERT statement: missing VALUES keyword");
1437
+ }
1438
+ cursor += valuesIndex + 1;
1439
+ const statements = [];
1440
+ while (cursor < tokens.length) {
1441
+ if (tokens[cursor]?.type === "SEMICOLON")
1442
+ break;
1443
+ if (tokens[cursor]?.type === "BRACKETS" && tokens[cursor]?.value === "(") {
1444
+ cursor++;
1445
+ const values = [];
1446
+ while (cursor < tokens.length) {
1447
+ const t = tokens[cursor];
1448
+ if (t.type === "BRACKETS" && t.value === ")") {
1449
+ cursor++;
1450
+ break;
1451
+ }
1452
+ if (t.type === "COMMA") {
1453
+ cursor++;
1454
+ continue;
1455
+ }
1456
+ if (t.type === "QUESTION_MARK") {
1457
+ if (params && paramState.index < params.length) {
1458
+ values.push(params[paramState.index++]);
1459
+ } else {
1460
+ values.push(null);
1461
+ }
1462
+ } else if (t.type === "STRING") {
1463
+ values.push(t.value);
1464
+ } else if (t.type === "NUMBER" || /^-?\d+(\.\d+)?$/.test(t.value)) {
1465
+ values.push(Number(t.value));
1466
+ } else {
1467
+ values.push(t.value);
1468
+ }
1469
+ cursor++;
1470
+ }
1471
+ statements.push({
1472
+ type: "INSERT",
1473
+ table,
1474
+ fields,
1475
+ columns: values.map((v) => typeof v === "object" ? JSON.stringify(v) : String(v ?? "")),
1476
+ values
1477
+ });
1478
+ } else {
1479
+ cursor++;
1480
+ }
1481
+ }
1482
+ return statements;
1483
+ }
1484
+ parseCreate(tokens) {
1485
+ const statements = [];
1486
+ let cursor = 0;
1487
+ while (cursor < tokens.length) {
1488
+ const createIdx = tokens.slice(cursor).findIndex((t) => t.type === "CREATE");
1489
+ if (createIdx === -1)
1490
+ break;
1491
+ const startIdx = cursor + createIdx;
1492
+ const semiIdx = tokens.slice(startIdx).findIndex((t) => t.type === "SEMICOLON");
1493
+ if (semiIdx === -1) {
1494
+ throw new Error("Invalid CREATE statement: missing ';' at end");
1495
+ }
1496
+ const currentTokens = tokens.slice(startIdx, startIdx + semiIdx + 1);
1497
+ cursor = startIdx + semiIdx + 1;
1498
+ const nextToken = currentTokens[1];
1499
+ if (!nextToken || !["TABLE", "INDEX"].includes(nextToken.type)) {
1500
+ throw new Error(`Invalid statement at near ${nextToken?.value}. Should be TABLE or INDEX!`);
1501
+ }
1502
+ const currentTable = this.foundTable(currentTokens);
1503
+ if (!currentTable) {
1504
+ throw new Error("Cannot find table name in CREATE TABLE statement");
1505
+ }
1506
+ const openBracketIndex = currentTokens.findIndex((t) => t.type === "BRACKETS" && t.value === "(");
1507
+ const closeBracketIndex = currentTokens.findIndex((t) => t.type === "BRACKETS" && t.value === ")");
1508
+ if (openBracketIndex === -1 || closeBracketIndex === -1) {
1509
+ throw new Error("Invalid statement. '(' or ')' is missing in CREATE TABLE!");
1510
+ }
1511
+ const creationColumns = [];
1512
+ const innerTokens = currentTokens.slice(openBracketIndex + 1, closeBracketIndex);
1513
+ const isTypeDefOrDecorators = (token) => TYPES_DEFS.includes(token.value.toUpperCase()) || token.type !== "IDENTIFIER";
1514
+ for (let i = 0;i < innerTokens.length; i++) {
1515
+ const token = innerTokens[i];
1516
+ if (isTypeDefOrDecorators(token))
1517
+ continue;
1518
+ const tokenTypeDef = innerTokens[i + 1];
1519
+ if (!tokenTypeDef)
1520
+ continue;
1521
+ const mappedType = TYPES_DEFS_MAPPING[tokenTypeDef.value.toUpperCase()];
1522
+ if (!mappedType) {
1523
+ throw new Error(`Unknown type at near ${tokenTypeDef.value}`);
1524
+ }
1525
+ creationColumns.push(`${token.value}:${mappedType}`);
1526
+ }
1527
+ statements.push({
1528
+ type: "CREATE",
1529
+ table: currentTable.value,
1530
+ columns: creationColumns
1531
+ });
1532
+ }
1533
+ return statements;
1534
+ }
1535
+ parseDelete(tokens) {
1536
+ const fromIndex = tokens.findIndex((t) => t.type === "FROM");
1537
+ if (fromIndex === -1) {
1538
+ throw new Error("Invalid DELETE statement: missing FROM clause");
1539
+ }
1540
+ if (tokens[2].type !== "IDENTIFIER") {
1541
+ throw new Error(`Invalid IDENTIFIER at: ${tokens[0].value}`);
1542
+ }
1543
+ const table = tokens[2].value;
1544
+ if (tokens[3].type === "SEMICOLON") {
1545
+ return {
1546
+ table,
1547
+ type: "DELETE",
1548
+ where: []
1549
+ };
1550
+ }
1551
+ let cursor = fromIndex + 2;
1552
+ let mainAlias;
1553
+ if (cursor < tokens.length) {
1554
+ if (tokens[cursor]?.type === "AS" && tokens[cursor + 1]?.type === "IDENTIFIER") {
1555
+ mainAlias = tokens[cursor + 1].value;
1556
+ cursor += 2;
1557
+ } else if (tokens[cursor]?.type === "IDENTIFIER" && !["JOIN", "INNER", "LEFT", "RIGHT", "FULL", "CROSS", "WHERE", "SEMICOLON"].includes(tokens[cursor].type)) {
1558
+ mainAlias = tokens[cursor].value;
1559
+ cursor++;
1560
+ }
1561
+ }
1562
+ const where = [];
1563
+ if (tokens[cursor]?.type === "WHERE") {
1564
+ cursor++;
1565
+ while (cursor < tokens.length) {
1566
+ const colToken = tokens[cursor];
1567
+ if (!colToken || colToken.type === "SEMICOLON")
1568
+ break;
1569
+ cursor++;
1570
+ const opToken = tokens[cursor];
1571
+ cursor++;
1572
+ const valToken = tokens[cursor];
1573
+ cursor++;
1574
+ if (colToken && opToken && valToken) {
1575
+ const colParts = colToken.value.split(".");
1576
+ const table2 = colParts.length > 1 ? colParts[0] : undefined;
1577
+ const column = colParts.length > 1 ? colParts[1] : colParts[0];
1578
+ where.push({
1579
+ table: table2,
1580
+ column,
1581
+ operator: opToken.value || "=",
1582
+ value: valToken.value
1583
+ });
1584
+ }
1585
+ if (tokens[cursor]?.type === "AND" || tokens[cursor]?.type === "OR") {
1586
+ cursor++;
1587
+ } else {
1588
+ break;
1589
+ }
1590
+ }
1591
+ }
1592
+ return {
1593
+ table,
1594
+ type: "DELETE",
1595
+ alias: mainAlias,
1596
+ where
1597
+ };
1598
+ }
1599
+ parse(tokens, params) {
1600
+ if (tokens.length < 3) {
1601
+ throw new Error(`Invalid tokens array with missing elements!`);
1602
+ }
1603
+ const firstStatement = tokens[0];
1604
+ if (!this.statementTypes.includes(firstStatement.type)) {
1605
+ throw new Error(`Invalid statement at near ${firstStatement.value}`);
1606
+ }
1607
+ const paramState = { index: 0 };
1608
+ if (firstStatement.type === "CREATE") {
1609
+ return this.parseCreate(tokens);
1610
+ }
1611
+ if (firstStatement.type === "SELECT") {
1612
+ return [this.parseSelect(tokens)];
1613
+ }
1614
+ if (firstStatement.type === "DELETE") {
1615
+ return [this.parseDelete(tokens)];
1616
+ }
1617
+ if (firstStatement.type === "INSERT") {
1618
+ const stmtChunks = [];
1619
+ let currentChunk = [];
1620
+ for (const t of tokens) {
1621
+ currentChunk.push(t);
1622
+ if (t.type === "SEMICOLON") {
1623
+ stmtChunks.push(currentChunk);
1624
+ currentChunk = [];
1625
+ }
1626
+ }
1627
+ if (currentChunk.length > 0)
1628
+ stmtChunks.push(currentChunk);
1629
+ const results = [];
1630
+ for (const chunk of stmtChunks) {
1631
+ if (chunk.some((t) => t.type === "INSERT")) {
1632
+ results.push(...this.parseInsert(chunk, params, paramState));
1633
+ }
1634
+ }
1635
+ return results;
1636
+ }
1637
+ throw new Error(`Unsupported statement type: ${firstStatement.type}`);
1638
+ }
1639
+ }
1640
+
1641
+ // src/services/localdb/operator/operator.ts
1642
+ class DBClient {
1643
+ lexer = new Lexer;
1644
+ parser = new Parser;
1645
+ NewRequest(query, params) {
1646
+ return this.parser.parse(this.lexer.lex(query), params);
1647
+ }
1648
+ }
1649
+
1650
+ // src/services/localdb/sheet/sheet.ts
1651
+ class TablesSheet {
1652
+ tables = [];
1653
+ constructor() {}
1654
+ statementToTable(stm) {
1655
+ const fields = {};
1656
+ const order = [];
1657
+ for (const [key, value] of stm.columns.map((cl) => cl.split(":"))) {
1658
+ const fieldType = value;
1659
+ const newField = fieldType;
1660
+ fields[key] = newField;
1661
+ if (order.includes(key)) {
1662
+ throw new Error(`Duplicate field at statement near ${key}`);
1663
+ }
1664
+ order.push(key);
1665
+ }
1666
+ return {
1667
+ name: stm.table,
1668
+ fields,
1669
+ order
1670
+ };
1671
+ }
1672
+ async RegisterSheet(statements) {
1673
+ const tables = statements.map((stm) => this.statementToTable(stm));
1674
+ this.tables = tables;
1675
+ return tables;
1676
+ }
1677
+ GetTables() {
1678
+ return this.tables;
1679
+ }
1680
+ }
1681
+
1682
+ // src/services/localdb/sheet/sheet.constants.ts
1683
+ import z from "zod";
1684
+ var DEFAULT_FIELDS_SCHEMA = new Map([
1685
+ ["string", z.string()],
1686
+ ["number", z.number()],
1687
+ ["bigint", z.bigint()],
1688
+ ["symbol", z.symbol()],
1689
+ ["undefined", z.undefined()],
1690
+ ["boolean", z.boolean()],
1691
+ ["object", z.record(z.string(), z.any()).or(z.object({}))],
1692
+ ["uuid", z.string()],
1693
+ ["array.string", z.array(z.string())],
1694
+ [
1695
+ "file",
1696
+ z.custom((val) => {
1697
+ if (typeof Blob !== "undefined" && val instanceof Blob)
1698
+ return true;
1699
+ if (typeof File !== "undefined" && val instanceof File)
1700
+ return true;
1701
+ if (typeof val === "object" && val !== null)
1702
+ return true;
1703
+ return false;
1704
+ })
1705
+ ],
1706
+ [
1707
+ "blob",
1708
+ z.custom((val) => {
1709
+ if (typeof Blob !== "undefined" && val instanceof Blob)
1710
+ return true;
1711
+ if (typeof File !== "undefined" && val instanceof File)
1712
+ return true;
1713
+ if (typeof val === "object" && val !== null)
1714
+ return true;
1715
+ return false;
1716
+ })
1717
+ ]
1718
+ ]);
1719
+
1720
+ // src/services/localdb/db/db.ts
1721
+ class LocalDB {
1722
+ DBName = "MYDB";
1723
+ DBVersion = 1;
1724
+ defaultStores = [];
1725
+ DBTypesStoreName = "__db.types";
1726
+ isAvailable;
1727
+ isError = null;
1728
+ db = null;
1729
+ client = new DBClient;
1730
+ sheet = new TablesSheet;
1731
+ constructor(DbName) {
1732
+ if (DbName)
1733
+ this.DBName = DbName;
1734
+ this.isAvailable = typeof window !== "undefined" && !!window?.indexedDB;
1735
+ }
1736
+ onDBError(cb, ev) {
1737
+ console.error("[ERROR] IndexedDB error:", ev);
1738
+ this.isError = new Error(ev.target?.error?.name ?? ev.type);
1739
+ cb(new Error(ev.target?.error?.name ?? ev.type));
1740
+ }
1741
+ onDBSuccess(cb, ev) {
1742
+ this.db = ev.target.result;
1743
+ this.isError = null;
1744
+ cb(null);
1745
+ }
1746
+ closeConnection() {
1747
+ if (this.db) {
1748
+ this.db.close();
1749
+ this.db = null;
1750
+ }
1751
+ }
1752
+ ensureObjectStores(db, storeNames = this.defaultStores) {
1753
+ for (const name of storeNames) {
1754
+ if (db.objectStoreNames.contains(name))
1755
+ continue;
1756
+ db.createObjectStore(name, { keyPath: "id" });
1757
+ }
1758
+ }
1759
+ bumpVersion(value) {
1760
+ this.DBVersion = value ?? this.DBVersion + 1;
1761
+ }
1762
+ async DeleteDB() {
1763
+ if (!this.isAvailable) {
1764
+ console.warn("[WARN] IndexDB not available in this browser!");
1765
+ return new Error("[ERROR] IndexDB not available in this browser!");
1766
+ }
1767
+ this.closeConnection();
1768
+ return new Promise((resolve) => {
1769
+ const request = window.indexedDB.deleteDatabase(this.DBName);
1770
+ request.onsuccess = () => {
1771
+ this.db = null;
1772
+ resolve(null);
1773
+ };
1774
+ request.onerror = () => {
1775
+ console.error("[ERROR] Failed to delete database", request.error);
1776
+ resolve(request.error ?? new Error("Failed to delete database"));
1777
+ };
1778
+ request.onblocked = () => {
1779
+ console.warn("[WARN] Database deletion blocked. Close all open connections first.");
1780
+ resolve(new Error("[WARN] Database deletion blocked. Close all open connections first."));
1781
+ };
1782
+ });
1783
+ }
1784
+ async init() {
1785
+ return new Promise((resolve, reject) => {
1786
+ if (!this.isAvailable) {
1787
+ console.warn("[WARN] IndexDB not available in this browser!");
1788
+ return;
1789
+ }
1790
+ if (this.db)
1791
+ resolve(true);
1792
+ const request = window.indexedDB.open(this.DBName, this.DBVersion !== 1 ? this.DBVersion : undefined);
1793
+ request.onupgradeneeded = () => {
1794
+ this.ensureObjectStores(request.result, this.defaultStores);
1795
+ };
1796
+ request.onerror = this.onDBError.bind(this, reject);
1797
+ request.onsuccess = (ev) => {
1798
+ this.bumpVersion(request.result.version);
1799
+ this.onDBSuccess(() => resolve(true), ev);
1800
+ };
1801
+ });
1802
+ }
1803
+ async retrieveData(objectStore, columns) {
1804
+ return new Promise((resolve) => {
1805
+ const data = [];
1806
+ const cursorReq = objectStore.openCursor();
1807
+ cursorReq.onsuccess = (ev) => {
1808
+ const cursor = ev.target.result;
1809
+ if (cursor) {
1810
+ const value = cursor.value;
1811
+ if (typeof value !== "object" || value === null) {
1812
+ cursor.continue();
1813
+ return;
1814
+ }
1815
+ const row = { ...value };
1816
+ if (!columns.includes("*")) {
1817
+ for (const key of Object.keys(row)) {
1818
+ if (!columns.includes(key)) {
1819
+ delete row[key];
1820
+ }
1821
+ }
1822
+ }
1823
+ data.push(row);
1824
+ cursor.continue();
1825
+ } else {
1826
+ resolve(data);
1827
+ }
1828
+ };
1829
+ cursorReq.onerror = (ev) => {
1830
+ console.error(`Cursor error: ${ev.target.error?.message}`);
1831
+ resolve([]);
1832
+ };
1833
+ });
1834
+ }
1835
+ async retrieveById(objectStore, id, columns) {
1836
+ return new Promise((resolve) => {
1837
+ const request = objectStore.get(id);
1838
+ request.onsuccess = () => {
1839
+ const value = request.result;
1840
+ if (!value) {
1841
+ resolve(null);
1842
+ return;
1843
+ }
1844
+ if (typeof value !== "object") {
1845
+ console.error(`Expected an object, received ${typeof value}`);
1846
+ resolve(null);
1847
+ return;
1848
+ }
1849
+ const row = { ...value };
1850
+ if (!columns.includes("*")) {
1851
+ for (const key of Object.keys(row)) {
1852
+ if (!columns.includes(key)) {
1853
+ delete row[key];
1854
+ }
1855
+ }
1856
+ }
1857
+ resolve(row);
1858
+ };
1859
+ request.onerror = (ev) => {
1860
+ console.error(`Retrieve by ID error: ${ev.target.error?.message}`);
1861
+ resolve(null);
1862
+ };
1863
+ });
1864
+ }
1865
+ async insertData(objectStore, data) {
1866
+ return new Promise((resolve) => {
1867
+ if (Array.isArray(data)) {
1868
+ throw new Error("Oops! you provide an array...");
1869
+ }
1870
+ const request = objectStore.put(data);
1871
+ request.onsuccess = () => {
1872
+ resolve(null);
1873
+ };
1874
+ request.onerror = (ev) => {
1875
+ resolve(new Error(`Insert error: ${ev.target.error?.message}`));
1876
+ };
1877
+ });
1878
+ }
1879
+ openTx(tableNames, reject, mode = "readwrite") {
1880
+ const rawNames = Array.isArray(tableNames) ? tableNames : [tableNames];
1881
+ const uniqueNames = [...new Set(rawNames.filter(Boolean))];
1882
+ for (const name of uniqueNames) {
1883
+ if (!this.db?.objectStoreNames.contains(name)) {
1884
+ throw new Error(`Table ${name} does not exist!`);
1885
+ }
1886
+ }
1887
+ const tx = this.db.transaction([this.DBTypesStoreName, ...uniqueNames], mode);
1888
+ tx.onerror = this.onDBError.bind(this, reject);
1889
+ return [tx, tx.objectStore(uniqueNames[0])];
1890
+ }
1891
+ convertFieldValueType(value, type) {
1892
+ switch (type) {
1893
+ case "number":
1894
+ if (typeof value === "number")
1895
+ return value;
1896
+ if (!/^-?\d+$/.test(String(value).trim())) {
1897
+ throw new Error(`Invalid number expr. Got ${value}`);
1898
+ }
1899
+ return parseInt(String(value).trim(), 10);
1900
+ case "boolean":
1901
+ if (typeof value === "boolean")
1902
+ return value;
1903
+ if (!["true", "false"].includes(String(value).trim())) {
1904
+ throw new Error(`Invalid boolean expr. Got ${value}`);
1905
+ }
1906
+ return String(value).trim() === "true";
1907
+ case "bigint":
1908
+ return BigInt(value);
1909
+ case "symbol":
1910
+ return typeof value === "symbol" ? value : Symbol.for(String(value));
1911
+ case "object":
1912
+ if (typeof value === "object" && value !== null)
1913
+ return value;
1914
+ if (typeof value === "string") {
1915
+ try {
1916
+ return JSON.parse(value);
1917
+ } catch {
1918
+ return {};
1919
+ }
1920
+ }
1921
+ return {};
1922
+ case "array.string":
1923
+ if (Array.isArray(value))
1924
+ return value.map(String);
1925
+ if (value instanceof Set)
1926
+ return Array.from(value).map(String);
1927
+ if (typeof value === "string") {
1928
+ try {
1929
+ const parsed = JSON.parse(value);
1930
+ if (Array.isArray(parsed))
1931
+ return parsed.map(String);
1932
+ } catch {}
1933
+ return value.split(",").map((s) => s.trim()).filter(Boolean);
1934
+ }
1935
+ return [];
1936
+ case "file":
1937
+ case "blob":
1938
+ return value;
1939
+ default:
1940
+ return typeof value === "string" ? value.trim() : String(value ?? "");
1941
+ }
1942
+ }
1943
+ async executeQuery(requests) {
1944
+ this.isError = null;
1945
+ let lastResult = [];
1946
+ for (const request of requests) {
1947
+ try {
1948
+ switch (request.type) {
1949
+ case "SELECT": {
1950
+ const selectReq = request;
1951
+ const joinTables = (selectReq.joins ?? []).map((j) => j.table);
1952
+ const allTables = [selectReq.table, ...joinTables];
1953
+ const [tx, primaryStore] = this.openTx(allTables, (err) => {
1954
+ this.isError = err;
1955
+ }, "readonly");
1956
+ let mainRows = await this.retrieveData(primaryStore, ["*"]);
1957
+ if (selectReq.where && selectReq.where.length > 0) {
1958
+ mainRows = mainRows.filter((row) => {
1959
+ return selectReq.where.every((cond) => {
1960
+ if (cond.table && cond.table !== selectReq.table && cond.table !== selectReq.alias) {
1961
+ return true;
1962
+ }
1963
+ const val = row[cond.column];
1964
+ if (cond.operator === "=") {
1965
+ return String(val) === String(cond.value);
1966
+ }
1967
+ if (cond.operator === "!=") {
1968
+ return String(val) !== String(cond.value);
1969
+ }
1970
+ return true;
1971
+ });
1972
+ });
1973
+ }
1974
+ if (selectReq.joins && selectReq.joins.length > 0) {
1975
+ for (const join of selectReq.joins) {
1976
+ const joinStore = tx.objectStore(join.table);
1977
+ let joinRows = await this.retrieveData(joinStore, ["*"]);
1978
+ if (selectReq.where && selectReq.where.length > 0) {
1979
+ joinRows = joinRows.filter((row) => {
1980
+ return selectReq.where.every((cond) => {
1981
+ if (cond.table && cond.table !== join.table && cond.table !== join.alias) {
1982
+ return true;
1983
+ }
1984
+ const val = row[cond.column];
1985
+ if (cond.operator === "=") {
1986
+ return String(val) === String(cond.value);
1987
+ }
1988
+ if (cond.operator === "!=") {
1989
+ return String(val) !== String(cond.value);
1990
+ }
1991
+ return true;
1992
+ });
1993
+ });
1994
+ }
1995
+ let leftCol = "id";
1996
+ let rightCol = `${selectReq.table.replace(/s$/, "")}_id`;
1997
+ if (join.on) {
1998
+ leftCol = join.on.leftColumn;
1999
+ rightCol = join.on.rightColumn;
2000
+ }
2001
+ const survivingRows = [];
2002
+ for (const mainRow of mainRows) {
2003
+ const mainVal = mainRow[leftCol];
2004
+ const matched = joinRows.filter((child) => String(child[rightCol]) === String(mainVal));
2005
+ if (join.type === "INNER" && matched.length === 0) {
2006
+ continue;
2007
+ }
2008
+ const collection = {};
2009
+ let allHaveId = matched.length > 0;
2010
+ for (const child of matched) {
2011
+ if (!child.id)
2012
+ allHaveId = false;
2013
+ const cleanChild = { ...child };
2014
+ delete cleanChild[rightCol];
2015
+ collection[child.id] = cleanChild;
2016
+ }
2017
+ if (allHaveId || matched.length === 0) {
2018
+ mainRow[join.table] = collection;
2019
+ } else {
2020
+ mainRow[join.table] = matched;
2021
+ }
2022
+ survivingRows.push(mainRow);
2023
+ }
2024
+ mainRows = survivingRows;
2025
+ }
2026
+ }
2027
+ if (!selectReq.columns.includes("*")) {
2028
+ mainRows = mainRows.map((row) => {
2029
+ const filtered = {};
2030
+ for (const col of selectReq.columns) {
2031
+ if (col in row) {
2032
+ filtered[col] = row[col];
2033
+ }
2034
+ }
2035
+ return filtered;
2036
+ });
2037
+ }
2038
+ lastResult = mainRows;
2039
+ break;
2040
+ }
2041
+ case "INSERT": {
2042
+ const insertReq = request;
2043
+ const [tx, objectStore] = this.openTx(insertReq.table, (err) => {
2044
+ this.isError = err;
2045
+ }, "readwrite");
2046
+ const table = await this.retrieveById(tx.objectStore(this.DBTypesStoreName), insertReq.table, ["*"]);
2047
+ if (!table) {
2048
+ return new Error(`Table ${insertReq.table} types not found. Please try Migrate your DB`);
2049
+ }
2050
+ const newData = {};
2051
+ const fieldsToUse = insertReq.fields?.length ? insertReq.fields : table.order;
2052
+ const valuesToUse = insertReq.values?.length ? insertReq.values : insertReq.columns;
2053
+ for (let idx = 0;idx < fieldsToUse.length; idx++) {
2054
+ const fieldId = fieldsToUse[idx];
2055
+ const LocalDBDataType = table.fields[fieldId];
2056
+ const typeSchema = DEFAULT_FIELDS_SCHEMA.get(LocalDBDataType);
2057
+ if (!typeSchema) {
2058
+ return new Error(`Unknown table type ${LocalDBDataType}`);
2059
+ }
2060
+ const correspondingValue = valuesToUse[idx];
2061
+ if (correspondingValue === undefined) {
2062
+ continue;
2063
+ }
2064
+ const convertedValue = this.convertFieldValueType(correspondingValue, LocalDBDataType);
2065
+ const safeValue = typeSchema.safeParse(convertedValue);
2066
+ if (!safeValue.success) {
2067
+ return new Error(`Mismatch field type at ${fieldId}. Must be ${LocalDBDataType}. Stack: ${safeValue.error.message}`);
2068
+ }
2069
+ newData[fieldId] = convertedValue;
2070
+ }
2071
+ await this.insertData(objectStore, newData);
2072
+ break;
2073
+ }
2074
+ case "DELETE": {
2075
+ const deleteReq = requests[0];
2076
+ const [_, primaryStore] = this.openTx(deleteReq.table, (err) => {
2077
+ this.isError = err;
2078
+ }, "readwrite");
2079
+ let mainRows = await this.retrieveData(primaryStore, ["*"]);
2080
+ if (deleteReq.where && deleteReq.where.length > 0) {
2081
+ mainRows = mainRows.filter((row) => {
2082
+ return deleteReq.where.every((cond) => {
2083
+ if (cond.table && cond.table !== deleteReq.table && cond.table !== deleteReq.alias) {
2084
+ return true;
2085
+ }
2086
+ const val = row[cond.column];
2087
+ if (cond.operator === "=") {
2088
+ return String(val) === String(cond.value);
2089
+ }
2090
+ if (cond.operator === "!=") {
2091
+ return String(val) !== String(cond.value);
2092
+ }
2093
+ return true;
2094
+ });
2095
+ });
2096
+ }
2097
+ for (const row of mainRows) {
2098
+ await this.deleteData(primaryStore, deleteReq.table, row.id);
2099
+ }
2100
+ break;
2101
+ }
2102
+ default:
2103
+ break;
2104
+ }
2105
+ } catch (error) {
2106
+ return error instanceof Error ? error : new Error(JSON.stringify(error));
2107
+ }
2108
+ }
2109
+ return lastResult;
2110
+ }
2111
+ async deleteData(objectStore, table, id) {
2112
+ return new Promise((resolve) => {
2113
+ try {
2114
+ const request = objectStore.delete(id);
2115
+ request.onsuccess = () => {
2116
+ resolve(null);
2117
+ };
2118
+ request.onerror = (event) => {
2119
+ const error = event.target.error || new Error(`Erreur lors de la suppression de l'élément avec l'id ${id} dans la table ${table}`);
2120
+ resolve(error);
2121
+ };
2122
+ } catch (error) {
2123
+ resolve(error instanceof Error ? error : new Error(String(error)));
2124
+ }
2125
+ });
2126
+ }
2127
+ async QueryDB(query, params) {
2128
+ if (!this.db)
2129
+ await this.init();
2130
+ const req = this.client.NewRequest(query, params);
2131
+ return this.executeQuery(req);
2132
+ }
2133
+ async MigrateDB(query) {
2134
+ const statements = this.client.NewRequest(query);
2135
+ const isBadReq = statements.some((s) => s.type !== "CREATE");
2136
+ if (isBadReq) {
2137
+ return new Error(`Bad request at migration. All must be CREATE statement!`);
2138
+ }
2139
+ const tables = await this.sheet.RegisterSheet(statements);
2140
+ const uniqueNames = [...new Set(tables.map((table) => table.name))];
2141
+ if (uniqueNames.includes(this.DBTypesStoreName)) {
2142
+ return new Error(`Reserved store name ${this.DBTypesStoreName}!`);
2143
+ }
2144
+ if (!this.isAvailable) {
2145
+ return new Error("[WARN] IndexDB not available in this browser!");
2146
+ }
2147
+ if (!this.db)
2148
+ await this.init();
2149
+ const namesToCreate = uniqueNames.filter((name) => !this.db?.objectStoreNames.contains(name));
2150
+ if (!namesToCreate.length) {
2151
+ return null;
2152
+ }
2153
+ this.closeConnection();
2154
+ this.bumpVersion();
2155
+ return new Promise((resolve) => {
2156
+ const request = window.indexedDB.open(this.DBName, this.DBVersion);
2157
+ request.onupgradeneeded = () => {
2158
+ const db = request.result;
2159
+ this.ensureObjectStores(db, [this.DBTypesStoreName, ...namesToCreate]);
2160
+ };
2161
+ request.onsuccess = async (ev) => {
2162
+ const db = request.result;
2163
+ const objectStore = db.transaction([this.DBTypesStoreName], "readwrite").objectStore(this.DBTypesStoreName);
2164
+ await Promise.all(tables.map((table) => this.insertData(objectStore, { ...table, id: table.name })));
2165
+ this.onDBSuccess.call(this, resolve, ev);
2166
+ };
2167
+ request.onerror = this.onDBError.bind(this, resolve);
2168
+ request.onblocked = () => {
2169
+ console.warn("[WARN] Migration blocked because another IndexedDB connection is still open.");
2170
+ resolve(new Error("IndexedDB migration blocked"));
2171
+ };
2172
+ });
2173
+ }
2174
+ }
2175
+
2176
+ // src/services/index.ts
2177
+ var CORAX_INDEXED_DB = "coraxdb";
2178
+
2179
+ // src/modules/autosave.module.ts
2180
+ async function loadCompleteDocument(db2, documentId) {
2181
+ const result = await db2.QueryDB(`
2182
+ SELECT * FROM documents
2183
+ JOIN fields ON documents.id = fields.document_id
2184
+ JOIN containers ON documents.id = containers.document_id
2185
+ JOIN components ON documents.id = components.document_id
2186
+ LEFT JOIN medias ON documents.id = medias.document_id
2187
+ WHERE documents.id = '${documentId}';
2188
+ `);
2189
+ if (result instanceof Error) {
2190
+ throw result;
2191
+ }
2192
+ if (Array.isArray(result) && result.length > 0) {
2193
+ return result[0];
2194
+ }
2195
+ return null;
2196
+ }
2197
+ var AutoSaveModule = {
2198
+ name: "autosave",
2199
+ version: "1.0.0",
2200
+ requires: [],
2201
+ install(ctx) {
2202
+ ctx.state.defineSlice("localdbState", { isDBReady: false });
2203
+ if (typeof window === "undefined" || !("indexedDB" in window)) {
2204
+ console.error("[WARN] indexedDB not supported or SSR");
2205
+ return;
2206
+ }
2207
+ const db2 = new LocalDB(CORAX_INDEXED_DB);
2208
+ db2.DeleteDB().then((err) => {
2209
+ if (err) {
2210
+ console.error(err);
2211
+ return;
2212
+ }
2213
+ db2.MigrateDB(`
2214
+ CREATE TABLE documents (
2215
+ id TEXT,
2216
+ version TEXT,
2217
+ order ARRAY[STRING],
2218
+ created_at DATETIME
2219
+ );
2220
+ CREATE TABLE fields (
2221
+ id TEXT,
2222
+ document_id TEXT,
2223
+ name TEXT,
2224
+ tag TEXT,
2225
+ type TEXT,
2226
+ variant TEXT,
2227
+ containerId TEXT,
2228
+ props OBJECT
2229
+ );
2230
+ CREATE TABLE containers (
2231
+ id TEXT,
2232
+ document_id TEXT,
2233
+ name TEXT,
2234
+ tag TEXT,
2235
+ type TEXT,
2236
+ variant TEXT,
2237
+ order ARRAY[STRING],
2238
+ props OBJECT
2239
+ );
2240
+ CREATE TABLE components (
2241
+ id TEXT,
2242
+ document_id TEXT,
2243
+ name TEXT,
2244
+ tag TEXT,
2245
+ type TEXT,
2246
+ variant TEXT,
2247
+ order ARRAY[STRING],
2248
+ count INTEGER,
2249
+ updatedAt DATETIME,
2250
+ createdAt DATETIME,
2251
+ props OBJECT
2252
+ );
2253
+ CREATE TABLE medias (
2254
+ id TEXT,
2255
+ document_id TEXT,
2256
+ name TEXT,
2257
+ type TEXT,
2258
+ size INTEGER,
2259
+ data FILE,
2260
+ created_at DATETIME
2261
+ );
2262
+ `).then((error) => {
2263
+ if (error) {
2264
+ console.error("Failed to migrate database:", error);
2265
+ return;
2266
+ }
2267
+ ctx.state.set("localdbState", { isDBReady: true });
2268
+ }).catch((r) => {
2269
+ console.error(r);
2270
+ });
2271
+ }).catch((e) => {
2272
+ console.error(e);
2273
+ });
2274
+ ctx.commands.register("db.query", ({ query }) => {
2275
+ db2.QueryDB(query);
2276
+ });
2277
+ ctx.commands.before("blocks.insert", (p) => {
2278
+ const dbState = ctx.state.get("localdbState");
2279
+ if (!dbState || !dbState.isDBReady)
2280
+ return null;
2281
+ return p;
2282
+ });
2283
+ ctx.events.on("document:changed", (sbc) => {
2284
+ const dbState = ctx.state.get("localdbState");
2285
+ if (!dbState || !dbState.isDBReady)
2286
+ return;
2287
+ const jsonDocument = SerializeTree(sbc.value.next);
2288
+ const saveDocument = async () => {
2289
+ const documentId = jsonDocument.id;
2290
+ const now = Date.now();
2291
+ await db2.QueryDB(`INSERT INTO documents (id, version, order, created_at) VALUES (?, ?, ?, ?);`, [documentId, jsonDocument.version, Array.from(jsonDocument.order ?? []), now]);
2292
+ for (const [fieldId, field] of Object.entries(jsonDocument.fields ?? {})) {
2293
+ await db2.QueryDB(`INSERT INTO fields (id, document_id, name, tag, type, variant, containerId, props) VALUES (?, ?, ?, ?, ?, ?, ?, ?);`, [
2294
+ field.id || fieldId,
2295
+ documentId,
2296
+ field.name ?? "",
2297
+ field.tag ?? "p",
2298
+ field.type ?? "text",
2299
+ field.variant ?? "field",
2300
+ field.containerId ?? "",
2301
+ field.props ?? {}
2302
+ ]);
2303
+ const fieldProps = field.props ?? {};
2304
+ if (fieldProps.file && (fieldProps.file instanceof Blob || typeof File !== "undefined" && fieldProps.file instanceof File)) {
2305
+ const file = fieldProps.file;
2306
+ await db2.QueryDB(`INSERT INTO medias (id, document_id, name, type, size, data, created_at) VALUES (?, ?, ?, ?, ?, ?, ?);`, [
2307
+ `media:${field.id || fieldId}`,
2308
+ documentId,
2309
+ file.name ?? "unnamed",
2310
+ file.type ?? "application/octet-stream",
2311
+ file.size ?? 0,
2312
+ file,
2313
+ now
2314
+ ]);
2315
+ }
2316
+ }
2317
+ for (const [containerId, container] of Object.entries(jsonDocument.containers ?? {})) {
2318
+ await db2.QueryDB(`INSERT INTO containers (id, document_id, name, tag, type, variant, order, props) VALUES (?, ?, ?, ?, ?, ?, ?, ?);`, [
2319
+ container.id || containerId,
2320
+ documentId,
2321
+ container.name ?? "",
2322
+ container.tag ?? "div",
2323
+ container.type ?? "division",
2324
+ container.variant ?? "container",
2325
+ Array.from(container.order ?? []),
2326
+ container.props ?? {}
2327
+ ]);
2328
+ }
2329
+ for (const [componentId, component] of Object.entries(jsonDocument.components ?? {})) {
2330
+ await db2.QueryDB(`INSERT INTO components (id, document_id, name, tag, type, variant, order, count, updatedAt, createdAt, props) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);`, [
2331
+ component.id || componentId,
2332
+ documentId,
2333
+ component.name ?? "",
2334
+ component.tag ?? "div",
2335
+ component.type ?? "division",
2336
+ component.variant ?? "component",
2337
+ Array.from(component.order ?? []),
2338
+ component.count ?? 0,
2339
+ component.updatedAt ?? now,
2340
+ component.createdAt ?? now,
2341
+ component.props ?? {}
2342
+ ]);
2343
+ }
2344
+ };
2345
+ ctx.tasks.schedule("autosave:persist", 1000, saveDocument);
2346
+ });
2347
+ }
2348
+ };
2349
+ // src/components/slots/maps/block-actions.tsx
2350
+ import { useEffect as useEffect12, useMemo as useMemo3, useRef as useRef3 } from "react";
2351
+
2352
+ // src/hooks/use-slots.ts
2353
+ import { useSyncExternalStore as useSyncExternalStore3 } from "react";
2354
+ function useSlots(slotName) {
2355
+ const engine = useEngine();
2356
+ const items = useSyncExternalStore3((fn) => engine.ui.subscribe(slotName, fn), () => engine.ui.getSlots(slotName), () => engine.ui.getSlots(slotName));
2357
+ return items;
2358
+ }
2359
+
2360
+ // src/hooks/use-registry.ts
2361
+ import { useSyncExternalStore as useSyncExternalStore4 } from "react";
2362
+ function useRegistryComponent(name) {
2363
+ return useSyncExternalStore4((fn) => SlotsComponentRegistry.subscribe(name, fn), () => SlotsComponentRegistry.get(name), () => SlotsComponentRegistry.get(name));
2364
+ }
2365
+
2366
+ // src/components/slots/slot-button.tsx
2367
+ import React12 from "react";
2368
+ function SlotButton({ c, ui }) {
2369
+ const Comp = useRegistryComponent(c.name);
2370
+ if (!Comp) {
2371
+ console.warn(`No component registered for slot key "${c.name}"`);
2372
+ return null;
2373
+ }
2374
+ return React12.createElement(Comp, {
2375
+ c,
2376
+ ui,
2377
+ ...{
2378
+ "data-slot-type": "slot-button",
2379
+ onMouseDown: (ev) => ev.preventDefault()
2380
+ }
2381
+ });
2382
+ }
2383
+
2384
+ // src/components/slots/slot-component.tsx
2385
+ import { createElement as createElement2 } from "react";
2386
+ function SlotComponent({ c, ui }) {
2387
+ const Comp = useRegistryComponent(c.name);
2388
+ if (!Comp) {
2389
+ console.warn(`No component registered for slot key "${c.name}"`);
2390
+ return null;
2391
+ }
2392
+ const props = c.getProps(ui);
2393
+ if (!props)
2394
+ return null;
2395
+ return createElement2(Comp, { ui, c });
2396
+ }
2397
+
2398
+ // src/components/slots/slots.tsx
2399
+ import { jsxDEV as jsxDEV24, Fragment } from "react/jsx-dev-runtime";
2400
+ function Slots({ slotName }) {
2401
+ const items = useSlots(slotName);
2402
+ const ui = useUIContext();
2403
+ return /* @__PURE__ */ jsxDEV24(Fragment, {
2404
+ children: items.map((c) => /* @__PURE__ */ jsxDEV24(SlotItem, {
2405
+ c,
2406
+ ui
2407
+ }, c.id, false, undefined, this))
2408
+ }, undefined, false, undefined, this);
2409
+ }
2410
+ function SlotItem({ c, ui }) {
2411
+ if (c.when && !c.when(ui))
2412
+ return null;
2413
+ switch (c.kind) {
2414
+ case "button":
2415
+ return /* @__PURE__ */ jsxDEV24(SlotButton, {
2416
+ c,
2417
+ ui
2418
+ }, undefined, false, undefined, this);
2419
+ case "component":
2420
+ return /* @__PURE__ */ jsxDEV24(SlotComponent, {
2421
+ c,
2422
+ ui
2423
+ }, undefined, false, undefined, this);
2424
+ }
2425
+ }
2426
+
2427
+ // src/components/slots/maps/block-actions.tsx
2428
+ import { cn as cn14 } from "cn";
2429
+ import { isEditableField } from "@coorax/core";
2430
+
2431
+ // src/components/corax-flow.tsx
2432
+ import { useSyncExternalStore as useSyncExternalStore5 } from "react";
2433
+
2434
+ // src/hooks/use-renderer.ts
2435
+ import { useMemo as useMemo2 } from "react";
2436
+ import { ReactRenderer } from "@coorax/render-react";
2437
+ import { UTILS as UTILS2 } from "@coorax/core";
2438
+
2439
+ // src/lifecycle/fields/handlers.registry.ts
2440
+ import { GenericRegistry as GenericRegistry5 } from "@coorax/render-react";
2441
+
2442
+ // src/lifecycle/fields/common/focus.events/onblur.ts
2443
+ var createOnBlur = async (engine, block, ev) => {
2444
+ const fieldInfo = getFieldTypeAndTargetId(engine, ev, block);
2445
+ if (!fieldInfo)
2446
+ return;
2447
+ const textSel = engine.state.get("textSelection");
2448
+ if (textSel && textSel.start !== textSel.end)
2449
+ return;
2450
+ engine.commands.tryExecute("blocks.focus", null);
2451
+ await fieldInfo.emit();
2452
+ };
2453
+
2454
+ // src/lifecycle/fields/common/focus.events/onfocus.ts
2455
+ var createOnFocus = async (engine, block, ev) => {
2456
+ const fieldInfo = getFieldTypeAndTargetId(engine, ev, block);
2457
+ if (!fieldInfo)
2458
+ return;
2459
+ await fieldInfo.emit();
2460
+ };
2461
+
2462
+ // src/lifecycle/fields/common/mouse.events/onclick.ts
2463
+ var createOnClick = async (engine, block, ev) => {
2464
+ ev.stopPropagation();
2465
+ if (block.type === "iframe") {
2466
+ ev.preventDefault();
2467
+ }
2468
+ const fieldInfo = getFieldTypeAndTargetId(engine, ev, block);
2469
+ if (!fieldInfo)
2470
+ return;
2471
+ const isOnControl = ev.ctrlKey || ev.metaKey;
2472
+ const selection2 = engine.state.get("selection");
2473
+ if (!selection2)
2474
+ return;
2475
+ const keys = Array.from(selection2.blocks.keys());
2476
+ const blockRect = blockRectFromBlockId(block.id);
2477
+ if (!blockRect)
2478
+ return;
2479
+ if (!ev.shiftKey || keys.includes(block.id)) {
2480
+ const blocks = new Map;
2481
+ blocks.set(block.id, blockRect);
2482
+ engine.commands.tryExecute("blocks.select", {
2483
+ blocks,
2484
+ mode: isOnControl ? "toggle" : "replace"
2485
+ });
2486
+ } else {
2487
+ const treeOrder = [...engine.document.get().order];
2488
+ const currentBlockIndex = treeOrder.indexOf(block.id);
2489
+ const orderMap = new Map(treeOrder.map((id, index) => [id, index]));
2490
+ const { minIndexKey, maxIndexKey } = keys.reduce((acc, key) => {
2491
+ const currPos = orderMap.get(key) ?? Infinity;
2492
+ const minPos = orderMap.get(acc.minIndexKey) ?? Infinity;
2493
+ const maxPos = orderMap.get(acc.maxIndexKey) ?? -Infinity;
2494
+ return {
2495
+ minIndexKey: currPos < minPos ? key : acc.minIndexKey,
2496
+ maxIndexKey: currPos > maxPos ? key : acc.maxIndexKey
2497
+ };
2498
+ }, { minIndexKey: keys[0], maxIndexKey: keys[0] });
2499
+ const lowestIndex = treeOrder.indexOf(minIndexKey);
2500
+ const greatestIndex = treeOrder.indexOf(maxIndexKey);
2501
+ const toSelect = (() => {
2502
+ if (currentBlockIndex > lowestIndex) {
2503
+ return treeOrder.slice(lowestIndex, currentBlockIndex + 1);
2504
+ }
2505
+ return treeOrder.slice(currentBlockIndex, greatestIndex + 1);
2506
+ })();
2507
+ const blocks = new Map;
2508
+ for (const id of toSelect) {
2509
+ const rect = blockRectFromBlockId(id);
2510
+ if (rect) {
2511
+ blocks.set(id, rect);
2512
+ }
2513
+ }
2514
+ engine.commands.tryExecute("blocks.select", {
2515
+ blocks,
2516
+ mode: "replace"
2517
+ });
2518
+ }
2519
+ await fieldInfo.emit();
2520
+ };
2521
+
2522
+ // src/lifecycle/fields/common/mouse.events/onmouseenter.ts
2523
+ var createOnMouseEnter = async (engine, block, ev) => {
2524
+ const fieldInfo = getFieldTypeAndTargetId(engine, ev, block);
2525
+ if (!fieldInfo)
2526
+ return;
2527
+ const selection2 = engine.state.get("selection");
2528
+ if (selection2 && selection2.blocks.has(block.id)) {
2529
+ return;
2530
+ }
2531
+ const rect = blockRectFromBlockId(block.id);
2532
+ if (!rect)
2533
+ return;
2534
+ engine.commands.tryExecute("blocks.hover", { id: block.id, rect });
2535
+ await fieldInfo.emit();
2536
+ };
2537
+
2538
+ // src/lifecycle/fields/common/mouse.events/onmouseleave.ts
2539
+ var createOnMouseLeave = async (engine, block, ev) => {
2540
+ const fieldInfo = getFieldTypeAndTargetId(engine, ev, block);
2541
+ if (!fieldInfo)
2542
+ return;
2543
+ const state = engine.state.get("hover");
2544
+ if (!state)
2545
+ return;
2546
+ if (state === null)
2547
+ return;
2548
+ engine.commands.tryExecute("blocks.hover", null);
2549
+ await fieldInfo.emit();
2550
+ };
2551
+
2552
+ // src/lifecycle/fields/common/handlers.ts
2553
+ function buildCommonHandlers(engine, block) {
2554
+ return {
2555
+ onClick: createOnClick.bind(null, engine, block),
2556
+ onMouseEnter: createOnMouseEnter.bind(null, engine, block),
2557
+ onMouseLeave: createOnMouseLeave.bind(null, engine, block),
2558
+ onFocus: createOnFocus.bind(null, engine, block),
2559
+ onBlur: createOnBlur.bind(null, engine, block)
2560
+ };
2561
+ }
2562
+
2563
+ // src/lifecycle/fields/divider/keyboard.events/onkeydown.ts
2564
+ import { FieldsUtils } from "@coorax/core";
2565
+ var createOnKeyDown = async (engine, block, ev) => {
2566
+ const fieldInfo = getFieldTypeAndTargetId(engine, ev, block);
2567
+ if (!fieldInfo)
2568
+ return;
2569
+ if (ev.ctrlKey || ev.metaKey)
2570
+ return;
2571
+ const tree = engine.document.get();
2572
+ const normalizedTarget = fieldInfo.target;
2573
+ const hasCurrentElement = engine.document.has(normalizedTarget);
2574
+ if (!hasCurrentElement) {
2575
+ console.warn(`Ignoring stale field target: ${normalizedTarget}`);
2576
+ return;
2577
+ }
2578
+ const targetIndex = [...tree.order].indexOf(normalizedTarget);
2579
+ const index = targetIndex + 1;
2580
+ const currentTarget = ev.currentTarget;
2581
+ if (ev.key === "Enter" && !ev.shiftKey) {
2582
+ ev.preventDefault();
2583
+ currentTarget.blur();
2584
+ const newField = FieldsUtils.NewField("text");
2585
+ engine.commands.tryExecute("blocks.insert", { block: newField, pos: index });
2586
+ await fieldInfo.emit();
2587
+ const blockRect = blockRectFromBlockId(newField.id);
2588
+ if (!blockRect)
2589
+ return;
2590
+ engine.commands.tryExecute("blocks.focus", { id: newField.id, rect: blockRect });
2591
+ }
2592
+ if (ev.key === "ArrowUp" || ev.key === "ArrowDown" || ev.key === "Tab") {
2593
+ ev.preventDefault();
2594
+ const mustBeNegativeDelta = ev.key === "ArrowUp" || ev.key === "Tab" && ev.shiftKey;
2595
+ const delta = mustBeNegativeDelta ? -1 : 1;
2596
+ const currentTree = engine.document.get();
2597
+ const blockIndex = Array.from(currentTree.order).indexOf(block.id);
2598
+ if (blockIndex === -1)
2599
+ return;
2600
+ if (blockIndex === 0 && delta < 0)
2601
+ return;
2602
+ if (blockIndex === currentTree.order.size - 1 && delta > 0)
2603
+ return;
2604
+ const rectId = [...currentTree.order][blockIndex + delta];
2605
+ const rect = blockRectFromBlockId(rectId);
2606
+ if (!rect) {
2607
+ return;
2608
+ }
2609
+ currentTarget.blur();
2610
+ engine.commands.tryExecute("blocks.focus", { id: rectId, rect });
2611
+ }
2612
+ if (ev.key === "Escape") {
2613
+ ev.preventDefault();
2614
+ currentTarget.blur();
2615
+ engine.commands.tryExecute("blocks.select", { blocks: new Map, mode: "replace" });
2616
+ }
2617
+ };
2618
+
2619
+ // src/lifecycle/fields/divider/handlers.ts
2620
+ function buildDividerHandlers(engine, block) {
2621
+ return {
2622
+ ...buildCommonHandlers(engine, block),
2623
+ onKeyDown: createOnKeyDown.bind(null, engine, block)
2624
+ };
2625
+ }
2626
+
2627
+ // src/lifecycle/fields/editable/keyboard.events/onkeydown.ts
2628
+ import { FieldsUtils as FieldsUtils2 } from "@coorax/core";
2629
+ var createOnKeyDown2 = async (engine, block, ev) => {
2630
+ const fieldInfo = getFieldTypeAndTargetId(engine, ev, block);
2631
+ if (!fieldInfo)
2632
+ return;
2633
+ if (ev.ctrlKey || ev.metaKey)
2634
+ return;
2635
+ const tree = engine.document.get();
2636
+ const normalizedTarget = fieldInfo.target;
2637
+ const hasCurrentElement = engine.document.has(normalizedTarget);
2638
+ if (!hasCurrentElement) {
2639
+ console.warn(`Ignoring stale field target: ${normalizedTarget}`);
2640
+ return;
2641
+ }
2642
+ const targetIndex = [...tree.order].indexOf(normalizedTarget);
2643
+ const index = targetIndex + 1;
2644
+ const currentTarget = ev.currentTarget;
2645
+ if (ev.key === "Enter" && !ev.shiftKey) {
2646
+ ev.preventDefault();
2647
+ currentTarget.blur();
2648
+ const newField = FieldsUtils2.NewField("text");
2649
+ engine.commands.tryExecute("blocks.insert", { block: newField, pos: index });
2650
+ await fieldInfo.emit();
2651
+ const blockRect = blockRectFromBlockId(newField.id);
2652
+ if (!blockRect)
2653
+ return;
2654
+ engine.commands.tryExecute("blocks.focus", { id: newField.id, rect: blockRect });
2655
+ }
2656
+ if (ev.key === "ArrowUp" || ev.key === "ArrowDown" || ev.key === "Tab") {
2657
+ ev.preventDefault();
2658
+ const mustBeNegativeDelta = ev.key === "ArrowUp" || ev.key === "Tab" && ev.shiftKey;
2659
+ const delta = mustBeNegativeDelta ? -1 : 1;
2660
+ const currentTree = engine.document.get();
2661
+ const blockIndex = Array.from(currentTree.order).indexOf(block.id);
2662
+ if (blockIndex === -1)
2663
+ return;
2664
+ if (blockIndex === 0 && delta < 0)
2665
+ return;
2666
+ if (blockIndex === currentTree.order.size - 1 && delta > 0)
2667
+ return;
2668
+ const rectId = [...currentTree.order][blockIndex + delta];
2669
+ const rect = blockRectFromBlockId(rectId);
2670
+ if (!rect) {
2671
+ return;
2672
+ }
2673
+ currentTarget.blur();
2674
+ engine.commands.tryExecute("blocks.focus", { id: rectId, rect });
2675
+ }
2676
+ if (ev.key === "Escape") {
2677
+ ev.preventDefault();
2678
+ currentTarget.blur();
2679
+ engine.commands.tryExecute("blocks.focus", null);
2680
+ }
2681
+ if (ev.key === "Backspace") {
2682
+ const textContent = block.props.children.text;
2683
+ if (textContent.length === 0) {
2684
+ const order = [...engine.document.get().order];
2685
+ const curBlockIndex = order.findIndex((id) => id === block.id);
2686
+ const prevSiblingBlock = engine.document.getBlock(order[curBlockIndex - 1]);
2687
+ if (prevSiblingBlock) {
2688
+ const blockRect = blockRectFromBlockId(prevSiblingBlock.id);
2689
+ if (!blockRect) {
2690
+ engine.commands.tryExecute("blocks.focus", null);
2691
+ return;
2692
+ }
2693
+ engine.commands.tryExecute("blocks.focus", {
2694
+ id: prevSiblingBlock.id,
2695
+ rect: blockRect
2696
+ });
2697
+ } else {
2698
+ engine.commands.tryExecute("blocks.focus", null);
2699
+ }
2700
+ engine.commands.tryExecute("blocks.delete", { blockId: block.id });
2701
+ }
2702
+ }
2703
+ };
2704
+
2705
+ // src/lifecycle/fields/editable/mouse.events/ondoubleclick.ts
2706
+ var createOnDoubleClick = async (engine, block, ev) => {
2707
+ ev.stopPropagation();
2708
+ const fieldInfo = getFieldTypeAndTargetId(engine, ev, block);
2709
+ if (!fieldInfo)
2710
+ return;
2711
+ const rect = blockRectFromBlockId(block.id);
2712
+ if (!rect)
2713
+ return;
2714
+ const focus = engine.state.get("focus");
2715
+ if (focus?.id === block.id) {
2716
+ return;
2717
+ }
2718
+ engine.commands.tryExecute("blocks.focus", { id: block.id, rect });
2719
+ await fieldInfo.emit();
2720
+ };
2721
+
2722
+ // src/lifecycle/fields/editable/synthetic.events/onselect.ts
2723
+ var createOnSelect = async (engine, block, ev) => {
2724
+ const fieldInfo = getFieldTypeAndTargetId(engine, ev, block);
2725
+ if (!fieldInfo)
2726
+ return;
2727
+ const target = ev.currentTarget;
2728
+ if (!target)
2729
+ return;
2730
+ const documentSel = document.getSelection();
2731
+ if (!documentSel)
2732
+ return;
2733
+ const range = documentSel.getRangeAt(0);
2734
+ const el = range.commonAncestorContainer;
2735
+ const root = (el instanceof Element ? el : el.parentElement)?.closest("[data-text-path]");
2736
+ if (!root)
2737
+ return;
2738
+ const blockId = root.getAttribute("id");
2739
+ const path = root.dataset.textPath;
2740
+ const { start, end } = rangeToOffsets(root, range);
2741
+ engine.commands.tryExecute("text.setSelection", { blockId, path, start, end });
2742
+ const sel = {
2743
+ blockId: block.id,
2744
+ path: "props.children",
2745
+ start: Math.min(start, end),
2746
+ end: Math.max(start, end)
2747
+ };
2748
+ engine.commands.tryExecute("text.setSelection", sel);
2749
+ await fieldInfo.emit();
2750
+ };
2751
+
2752
+ // src/lifecycle/fields/editable/handlers.ts
2753
+ function buildEditableHandlers(engine, block) {
2754
+ return {
2755
+ ...buildCommonHandlers(engine, block),
2756
+ onKeyDown: createOnKeyDown2.bind(null, engine, block),
2757
+ onDoubleClick: createOnDoubleClick.bind(null, engine, block),
2758
+ onSelect: createOnSelect.bind(null, engine, block)
2759
+ };
2760
+ }
2761
+
2762
+ // src/lifecycle/fields/media/image/synthetic.events/onload.ts
2763
+ var createOnLoad = async (engine, block, ev) => {
2764
+ const fieldInfo = getFieldTypeAndTargetId(engine, ev, block);
2765
+ if (!fieldInfo || !block.props?.src?.trim())
2766
+ return;
2767
+ const img = ev?.target;
2768
+ const intrinsic = img?.naturalWidth && img?.naturalHeight ? {
2769
+ "props.intrinsicWidth": img.naturalWidth,
2770
+ "props.intrinsicHeight": img.naturalHeight
2771
+ } : {};
2772
+ engine.document.apply((tree) => engine.mutations.mutateField(tree, {
2773
+ id: block.id,
2774
+ keyValuePairs: {
2775
+ "props.isLoaded": true,
2776
+ ...intrinsic
2777
+ }
2778
+ }), { origin: "history" });
2779
+ engine.commands.tryExecute("blocks.select", {
2780
+ blocks: new Map().set(block.id, blockRectFromBlockId(block.id))
2781
+ });
2782
+ await fieldInfo.emit();
2783
+ };
2784
+
2785
+ // src/lifecycle/fields/media/common/keyboard.events/onkeydown.ts
2786
+ import { FieldsUtils as FieldsUtils3 } from "@coorax/core";
2787
+ var createOnKeyDown3 = async (engine, block, ev) => {
2788
+ const fieldInfo = getFieldTypeAndTargetId(engine, ev, block);
2789
+ if (!fieldInfo)
2790
+ return;
2791
+ if (ev.ctrlKey || ev.metaKey)
2792
+ return;
2793
+ const tree = engine.document.get();
2794
+ const normalizedTarget = fieldInfo.target;
2795
+ const hasCurrentElement = engine.document.has(normalizedTarget);
2796
+ if (!hasCurrentElement) {
2797
+ console.warn(`Ignoring stale field target: ${normalizedTarget}`);
2798
+ return;
2799
+ }
2800
+ const targetIndex = [...tree.order].indexOf(normalizedTarget);
2801
+ const index = targetIndex + 1;
2802
+ const currentTarget = ev.currentTarget;
2803
+ if (ev.key === "Enter" && !ev.shiftKey) {
2804
+ ev.preventDefault();
2805
+ currentTarget.blur();
2806
+ const newField = FieldsUtils3.NewField("text");
2807
+ engine.commands.tryExecute("blocks.insert", { block: newField, pos: index });
2808
+ await fieldInfo.emit();
2809
+ const blockRect = blockRectFromBlockId(newField.id);
2810
+ if (!blockRect)
2811
+ return;
2812
+ engine.commands.tryExecute("blocks.focus", { id: newField.id, rect: blockRect });
2813
+ }
2814
+ if (ev.key === "ArrowUp" || ev.key === "ArrowDown" || ev.key === "Tab") {
2815
+ ev.preventDefault();
2816
+ const mustBeNegativeDelta = ev.key === "ArrowUp" || ev.key === "Tab" && ev.shiftKey;
2817
+ const delta = mustBeNegativeDelta ? -1 : 1;
2818
+ const currentTree = engine.document.get();
2819
+ const blockIndex = Array.from(currentTree.order).indexOf(block.id);
2820
+ if (blockIndex === -1)
2821
+ return;
2822
+ if (blockIndex === 0 && delta < 0)
2823
+ return;
2824
+ if (blockIndex === currentTree.order.size - 1 && delta > 0)
2825
+ return;
2826
+ const rectId = [...currentTree.order][blockIndex + delta];
2827
+ const rect = blockRectFromBlockId(rectId);
2828
+ if (!rect) {
2829
+ return;
2830
+ }
2831
+ currentTarget.blur();
2832
+ engine.commands.tryExecute("blocks.focus", { id: rectId, rect });
2833
+ }
2834
+ if (ev.key === "Escape") {
2835
+ ev.preventDefault();
2836
+ currentTarget.blur();
2837
+ engine.commands.tryExecute("blocks.select", { blocks: new Map, mode: "replace" });
2838
+ }
2839
+ };
2840
+
2841
+ // src/lifecycle/fields/media/common/synthetic.events/onerror.ts
2842
+ var createOnError = async (engine, block, ev) => {
2843
+ const fieldInfo = getFieldTypeAndTargetId(engine, ev, block);
2844
+ if (!fieldInfo || !block.props?.src?.trim())
2845
+ return;
2846
+ engine.document.apply((tree) => engine.mutations.mutateField(tree, {
2847
+ id: block.id,
2848
+ keyValuePairs: {
2849
+ "props.isError": true
2850
+ }
2851
+ }), { origin: "history" });
2852
+ await fieldInfo.emit();
2853
+ };
2854
+
2855
+ // src/lifecycle/fields/media/common/handlers.ts
2856
+ function buildMediaHandlers(engine, block) {
2857
+ const { onClick, onMouseEnter, onMouseLeave, onFocus } = buildCommonHandlers(engine, block);
2858
+ return {
2859
+ onClick,
2860
+ onMouseEnter,
2861
+ onMouseLeave,
2862
+ onFocus,
2863
+ onKeyDown: createOnKeyDown3.bind(null, engine, block),
2864
+ onError: createOnError.bind(null, engine, block)
2865
+ };
2866
+ }
2867
+
2868
+ // src/lifecycle/fields/media/image/handlers.ts
2869
+ function buildImageHandlers(engine, block) {
2870
+ return {
2871
+ ...buildMediaHandlers(engine, block),
2872
+ onLoad: createOnLoad.bind(null, engine, block)
2873
+ };
2874
+ }
2875
+
2876
+ // src/lifecycle/fields/media/video/synthetic.events/oncanplaythrough.ts
2877
+ var createVideoOnCanPlayThrough = async (engine, block, ev) => {
2878
+ const fieldInfo = getFieldTypeAndTargetId(engine, ev, block);
2879
+ if (!fieldInfo || !block.props?.src?.trim())
2880
+ return;
2881
+ const video = ev?.target;
2882
+ const intrinsic = video?.videoWidth && video?.videoHeight ? {
2883
+ "props.intrinsicWidth": video.videoWidth,
2884
+ "props.intrinsicHeight": video.videoHeight
2885
+ } : {};
2886
+ engine.document.apply((tree) => engine.mutations.mutateField(tree, {
2887
+ id: block.id,
2888
+ keyValuePairs: {
2889
+ "props.isLoaded": true,
2890
+ ...intrinsic
2891
+ }
2892
+ }), { origin: "history" });
2893
+ engine.commands.tryExecute("blocks.select", {
2894
+ blocks: new Map().set(block.id, blockRectFromBlockId(block.id))
2895
+ });
2896
+ await fieldInfo.emit();
2897
+ };
2898
+
2899
+ // src/lifecycle/fields/media/video/mouse.events/ondoubleclick.ts
2900
+ var createVideoOnDoubleClick = async (engine, block, ev) => {
2901
+ ev.stopPropagation();
2902
+ ev.preventDefault();
2903
+ const fieldInfo = getFieldTypeAndTargetId(engine, ev, block);
2904
+ if (!fieldInfo)
2905
+ return;
2906
+ const field = block;
2907
+ engine.document.apply((t) => engine.mutations.mutateField(t, {
2908
+ id: field.id,
2909
+ keyValuePairs: {
2910
+ "props.controls": !field.props.controls
2911
+ }
2912
+ }), { shouldEmitEvent: false });
2913
+ await fieldInfo.emit();
2914
+ };
2915
+
2916
+ // src/lifecycle/fields/media/video/handlers.ts
2917
+ function buildVideoHandlers(engine, block) {
2918
+ return {
2919
+ ...buildMediaHandlers(engine, block),
2920
+ onCanPlayThrough: createVideoOnCanPlayThrough.bind(null, engine, block),
2921
+ onDoubleClick: createVideoOnDoubleClick.bind(null, engine, block)
2922
+ };
2923
+ }
2924
+
2925
+ // src/lifecycle/fields/media/iframe/synthetic.events/onload.ts
2926
+ var createIframeOnLoad = async (engine, block, ev) => {
2927
+ const fieldInfo = getFieldTypeAndTargetId(engine, ev, block);
2928
+ if (!fieldInfo || !block.props?.src?.trim())
2929
+ return;
2930
+ engine.document.apply((tree) => engine.mutations.mutateField(tree, {
2931
+ id: block.id,
2932
+ keyValuePairs: {
2933
+ "props.isLoaded": true
2934
+ }
2935
+ }), { origin: "history" });
2936
+ engine.commands.tryExecute("blocks.select", {
2937
+ blocks: new Map().set(block.id, blockRectFromBlockId(block.id))
2938
+ });
2939
+ await fieldInfo.emit();
2940
+ };
2941
+
2942
+ // src/lifecycle/fields/media/iframe/handlers.ts
2943
+ function buildIFrameHandlers(engine, block) {
2944
+ return {
2945
+ ...buildMediaHandlers(engine, block),
2946
+ onLoad: createIframeOnLoad.bind(null, engine, block)
2947
+ };
2948
+ }
2949
+
2950
+ // src/lifecycle/fields/handlers.registry.ts
2951
+ class FieldHandlersRegistry extends GenericRegistry5 {
2952
+ }
2953
+ var FieldHandlers = new FieldHandlersRegistry;
2954
+ FieldHandlers.register("h1", buildEditableHandlers);
2955
+ FieldHandlers.register("h2", buildEditableHandlers);
2956
+ FieldHandlers.register("p", buildEditableHandlers);
2957
+ FieldHandlers.register("blockquote", buildEditableHandlers);
2958
+ FieldHandlers.register("figcaption", buildEditableHandlers);
2959
+ FieldHandlers.register("pre", buildEditableHandlers);
2960
+ FieldHandlers.register("a", buildEditableHandlers);
2961
+ FieldHandlers.register("img", buildImageHandlers);
2962
+ FieldHandlers.register("video", buildVideoHandlers);
2963
+ FieldHandlers.register("hr", buildDividerHandlers);
2964
+ FieldHandlers.register("iframe", buildIFrameHandlers);
2965
+
2966
+ // src/lifecycle/fields/lifecycle.fields.ts
2967
+ function getFieldLifeCycleEvents(engine, tag, block) {
2968
+ const build = FieldHandlers.get(tag);
2969
+ return build ? build(engine, block) : {};
2970
+ }
2971
+ function forField(engine, block) {
2972
+ return getFieldLifeCycleEvents(engine, block.tag, block);
2973
+ }
2974
+ var FLC = { forField };
2975
+ // src/primitives/fields/field.primitives.tsx
2976
+ import { useCallback, useEffect as useEffect8, useRef } from "react";
2977
+ import { jsxDEV as jsxDEV25 } from "react/jsx-dev-runtime";
2978
+ function FieldPrimitive({ blockId }) {
2979
+ const blockRef = useRef(null);
2980
+ const engine = useEngine();
2981
+ const renderer = useRenderer();
2982
+ const block = useBlock(blockId);
2983
+ const sel = useSlice("textSelection");
2984
+ const updateRange = useCallback(() => {
2985
+ if (!sel)
2986
+ return;
2987
+ const root = document.querySelector(`[id="${CSS.escape(sel.blockId)}"][data-text-path="${CSS.escape(sel.path)}"]`);
2988
+ if (!root || !root.contains(document.activeElement))
2989
+ return;
2990
+ const domSel = document.getSelection();
2991
+ if (!domSel)
2992
+ return;
2993
+ if (domSel.rangeCount) {
2994
+ const cur = rangeToOffsets(root, domSel.getRangeAt(0));
2995
+ if (cur.start === sel.start && cur.end === sel.end)
2996
+ return;
2997
+ }
2998
+ const range = offsetsToRange(root, sel.start, sel.end);
2999
+ if (!range)
3000
+ return;
3001
+ domSel.removeAllRanges();
3002
+ domSel.addRange(range);
3003
+ }, [sel]);
3004
+ useIsomorphicLayoutEffect(() => {
3005
+ updateRange();
3006
+ }, [updateRange, engine]);
3007
+ useIsomorphicLayoutEffect(() => {
3008
+ if (!sel)
3009
+ return;
3010
+ const root = document.querySelector(`[id="${CSS.escape(sel.blockId)}"][data-text-path="${CSS.escape(sel.path)}"]`);
3011
+ if (!root || !root.contains(document.activeElement))
3012
+ return;
3013
+ const range = offsetsToRange(root, sel.start, sel.end);
3014
+ if (!range)
3015
+ return;
3016
+ root.focus({ preventScroll: true });
3017
+ const domSel = document.getSelection();
3018
+ domSel.removeAllRanges();
3019
+ domSel.addRange(range);
3020
+ });
3021
+ useEffect8(() => {
3022
+ const domEl = blockRef.current;
3023
+ if (!domEl)
3024
+ return;
3025
+ const publishBlockRect = () => {
3026
+ const hover = engine.state.get("hover");
3027
+ const focus = engine.state.get("focus");
3028
+ const selection2 = engine.state.get("selection")?.blocks;
3029
+ const rect = blockRectFromBlockId(blockId);
3030
+ if (!rect || !engine.document.get().order.size)
3031
+ return;
3032
+ if (focus?.id === blockId) {
3033
+ engine.commands.tryExecute("blocks.focus", { id: blockId, rect });
3034
+ }
3035
+ if (hover?.id === blockId) {
3036
+ engine.commands.tryExecute("blocks.hover", { id: blockId, rect });
3037
+ }
3038
+ if (selection2?.has(blockId)) {
3039
+ engine.commands.tryExecute("blocks.select", {
3040
+ blocks: new Map(selection2.entries()).set(blockId, rect),
3041
+ mode: "replace"
3042
+ });
3043
+ }
3044
+ };
3045
+ const observer = new ResizeObserver(publishBlockRect);
3046
+ observer.observe(domEl);
3047
+ return () => {
3048
+ observer.unobserve(domEl);
3049
+ observer.disconnect();
3050
+ };
3051
+ }, [engine, blockId]);
3052
+ if (!blockId.startsWith("field") || !block)
3053
+ return null;
3054
+ return /* @__PURE__ */ jsxDEV25("div", {
3055
+ ref: blockRef,
3056
+ className: "w-full flex max-w-full items-center justify-center",
3057
+ children: renderer.renderField(block)
3058
+ }, undefined, false, undefined, this);
3059
+ }
3060
+
3061
+ // src/primitives/index.ts
3062
+ var FieldsPrimitives = {
3063
+ field: FieldPrimitive
3064
+ };
3065
+
3066
+ // src/hooks/use-renderer.ts
3067
+ function useRenderer() {
3068
+ const engine = useEngine();
3069
+ return useMemo2(() => {
3070
+ const ctx = {
3071
+ mode: "edit",
3072
+ styles: (type) => engine.ui.getStyle(type),
3073
+ events: (block) => FLC.forField(engine, block)
3074
+ };
3075
+ const renderer = new ReactRenderer(ctx, engine.document);
3076
+ for (const [variant, comp2] of UTILS2.ObjectEntries(FieldsPrimitives)) {
3077
+ if (comp2)
3078
+ renderer.primitives.post(variant, comp2);
3079
+ }
3080
+ return renderer;
3081
+ }, [engine]);
3082
+ }
3083
+
3084
+ // src/hooks/use-flow.ts
3085
+ import { useEffect as useEffect10 } from "react";
3086
+
3087
+ // src/hooks/custom/use-custom-ref.ts
3088
+ import { useEffect as useEffect9, useRef as useRef2 } from "react";
3089
+ function useCustomRef(factory) {
3090
+ const isServer = typeof window === "undefined";
3091
+ const getInitialValue = () => {
3092
+ if (isServer)
3093
+ return null;
3094
+ try {
3095
+ return typeof factory === "function" ? factory() : factory;
3096
+ } catch {
3097
+ return null;
3098
+ }
3099
+ };
3100
+ const ref = useRef2(getInitialValue());
3101
+ useEffect9(() => {
3102
+ try {
3103
+ ref.current = typeof factory === "function" ? factory() : factory;
3104
+ } catch {}
3105
+ }, [factory]);
3106
+ return ref;
3107
+ }
3108
+
3109
+ // src/hooks/use-flow.ts
3110
+ function editorRectFromDomElement(domElement) {
3111
+ const containerRect = domElement.getBoundingClientRect();
3112
+ return {
3113
+ scrollTop: domElement.scrollTop,
3114
+ scrollLeft: domElement.scrollLeft,
3115
+ clientLeft: domElement.clientLeft,
3116
+ clientTop: domElement.clientTop,
3117
+ top: containerRect.top,
3118
+ left: containerRect.left,
3119
+ bottom: containerRect.bottom,
3120
+ right: containerRect.right,
3121
+ width: containerRect.width,
3122
+ height: containerRect.height,
3123
+ offsetTop: domElement.offsetTop,
3124
+ offsetLeft: domElement.offsetLeft,
3125
+ offsetWidth: domElement.offsetWidth,
3126
+ offsetHeight: domElement.offsetHeight
3127
+ };
3128
+ }
3129
+ function useFlow() {
3130
+ const engine = useEngine();
3131
+ const coraxFlowEditorRef = useCustomRef(() => {
3132
+ if (typeof document === "undefined")
3133
+ return null;
3134
+ const flowEditor = document.getElementById("corax_flow_blocks_container");
3135
+ if (!flowEditor)
3136
+ return null;
3137
+ engine.commands.tryExecute("editor.rect", { editorRect: editorRectFromDomElement(flowEditor) });
3138
+ return flowEditor;
3139
+ });
3140
+ useEffect10(() => {
3141
+ function handleKeyDown(ev) {
3142
+ if (!ev.ctrlKey || ev.key.toLocaleLowerCase() !== "z")
3143
+ return;
3144
+ engine.commands.tryExecute(ev.shiftKey ? "history.redo" : "history.undo", {});
3145
+ }
3146
+ const flowEditor = coraxFlowEditorRef.current;
3147
+ function handleClick(ev) {
3148
+ const target = ev.target;
3149
+ if (!(target instanceof Element))
3150
+ return;
3151
+ if (target.closest("[data-block-type]") || target.closest("[data-slot-type]"))
3152
+ return;
3153
+ engine.commands.tryExecute("blocks.select", { blocks: new Map, mode: "replace" });
3154
+ }
3155
+ if (flowEditor) {
3156
+ flowEditor.addEventListener("click", handleClick);
3157
+ }
3158
+ document.addEventListener("keydown", handleKeyDown);
3159
+ return () => {
3160
+ document.removeEventListener("keydown", handleKeyDown);
3161
+ if (flowEditor) {
3162
+ flowEditor.removeEventListener("click", handleClick);
3163
+ }
3164
+ };
3165
+ }, [engine, coraxFlowEditorRef]);
3166
+ useEffect10(() => {
3167
+ const element = coraxFlowEditorRef.current;
3168
+ if (!element)
3169
+ return;
3170
+ const publishEditorRect = () => {
3171
+ engine.commands.tryExecute("editor.rect", { editorRect: editorRectFromDomElement(element) });
3172
+ };
3173
+ const observer = new ResizeObserver(publishEditorRect);
3174
+ observer.observe(element);
3175
+ element.addEventListener("scroll", publishEditorRect, { passive: true });
3176
+ return () => {
3177
+ observer.disconnect();
3178
+ element.removeEventListener("scroll", publishEditorRect);
3179
+ };
3180
+ }, [engine, coraxFlowEditorRef]);
3181
+ useEffect10(() => {
3182
+ const element = coraxFlowEditorRef.current;
3183
+ if (!element)
3184
+ return;
3185
+ const publishEditorRect = () => {
3186
+ engine.commands.tryExecute("editor.rect", { editorRect: editorRectFromDomElement(element) });
3187
+ };
3188
+ window.addEventListener("resize", publishEditorRect, { passive: true });
3189
+ return () => {
3190
+ window.removeEventListener("resize", publishEditorRect);
3191
+ };
3192
+ }, [engine, coraxFlowEditorRef]);
3193
+ }
3194
+
3195
+ // src/hooks/use-text-input.ts
3196
+ import { useEffect as useEffect11 } from "react";
3197
+ function useTextInput(engine) {
3198
+ useEffect11(() => {
3199
+ let composing = false;
3200
+ const rootOf = (t) => ((t instanceof Element ? t : t?.parentElement) ?? null)?.closest("[data-text-path]") ?? null;
3201
+ const onBeforeInput = (e) => {
3202
+ const root = rootOf(e.target);
3203
+ if (!root || composing || e.isComposing)
3204
+ return;
3205
+ const tr = e.getTargetRanges()[0];
3206
+ if (tr) {
3207
+ const r = document.createRange();
3208
+ r.setStart(tr.startContainer, tr.startOffset);
3209
+ r.setEnd(tr.endContainer, tr.endOffset);
3210
+ engine.commands.tryExecute("text.setSelection", {
3211
+ blockId: root.id,
3212
+ path: root.dataset.textPath,
3213
+ ...rangeToOffsets(root, r)
3214
+ });
3215
+ }
3216
+ switch (e.inputType) {
3217
+ case "insertText":
3218
+ if (e.data)
3219
+ engine.commands.tryExecute("text.insert", { text: e.data });
3220
+ break;
3221
+ case "insertParagraph":
3222
+ case "insertLineBreak":
3223
+ engine.commands.tryExecute("text.insert", { text: `
3224
+ ` });
3225
+ break;
3226
+ case "insertFromPaste": {
3227
+ const text = e.dataTransfer?.getData("text/plain");
3228
+ if (text)
3229
+ engine.commands.tryExecute("text.insert", { text });
3230
+ break;
3231
+ }
3232
+ case "deleteContentBackward":
3233
+ engine.commands.tryExecute("text.delete", { direction: "backward" });
3234
+ break;
3235
+ case "deleteWordBackward":
3236
+ engine.commands.tryExecute("text.delete", { direction: "backward", type: "word" });
3237
+ break;
3238
+ case "deleteContentForward":
3239
+ engine.commands.tryExecute("text.delete", { direction: "forward" });
3240
+ break;
3241
+ case "deleteWordForward":
3242
+ engine.commands.tryExecute("text.delete", { direction: "forward", type: "word" });
3243
+ break;
3244
+ case "historyUndo":
3245
+ engine.commands.tryExecute("history.undo", undefined);
3246
+ break;
3247
+ case "historyRedo":
3248
+ engine.commands.tryExecute("history.redo", undefined);
3249
+ break;
3250
+ default:
3251
+ break;
3252
+ }
3253
+ e.preventDefault();
3254
+ };
3255
+ const start = () => {
3256
+ composing = true;
3257
+ };
3258
+ const end = () => {
3259
+ composing = false;
3260
+ };
3261
+ document.addEventListener("beforeinput", onBeforeInput);
3262
+ document.addEventListener("compositionstart", start);
3263
+ document.addEventListener("compositionend", end);
3264
+ return () => {
3265
+ document.removeEventListener("beforeinput", onBeforeInput);
3266
+ document.removeEventListener("compositionstart", start);
3267
+ document.removeEventListener("compositionend", end);
3268
+ };
3269
+ }, [engine]);
3270
+ }
3271
+
3272
+ // src/components/corax-flow.tsx
3273
+ import { cn as cn13 } from "cn";
3274
+ import { jsxDEV as jsxDEV26, Fragment as Fragment2 } from "react/jsx-dev-runtime";
3275
+ "use client";
3276
+ var IMAGE_BREAKOUT_GUTTER = 150;
3277
+ function CoraxBlocks() {
3278
+ const engine = useEngine();
3279
+ const renderer = useRenderer();
3280
+ const order = useSyncExternalStore5((onStoreChange) => engine.state.subscribe("document", onStoreChange), () => engine.document.get().order, () => engine.document.get().order);
3281
+ return /* @__PURE__ */ jsxDEV26(Fragment2, {
3282
+ children: [...order].map((id) => {
3283
+ const block = engine.document.getBlock(id);
3284
+ if (!block)
3285
+ return null;
3286
+ const Comp = renderer.primitives.get(block.variant);
3287
+ if (!Comp)
3288
+ return null;
3289
+ return /* @__PURE__ */ jsxDEV26(Comp, {
3290
+ blockId: id
3291
+ }, id, false, undefined, this);
3292
+ })
3293
+ }, undefined, false, undefined, this);
3294
+ }
3295
+ function CoraxFlow({
3296
+ children,
3297
+ className
3298
+ }) {
3299
+ const engine = useEngine();
3300
+ useFlow();
3301
+ useTextInput(engine);
3302
+ return /* @__PURE__ */ jsxDEV26("div", {
3303
+ id: "corax_flow_editor",
3304
+ className: "relative flex flex-col max-w-full w-275 h-full",
3305
+ children: /* @__PURE__ */ jsxDEV26("div", {
3306
+ id: "corax_flow_blocks_container",
3307
+ className: cn13("relative w-full h-full flex flex-col items-center scrollbar-none gap-1", className),
3308
+ style: {
3309
+ overflowX: "hidden",
3310
+ overflowY: "auto",
3311
+ paddingInline: IMAGE_BREAKOUT_GUTTER
3312
+ },
3313
+ children: [
3314
+ /* @__PURE__ */ jsxDEV26(CoraxBlocks, {}, undefined, false, undefined, this),
3315
+ children
3316
+ ]
3317
+ }, undefined, true, undefined, this)
3318
+ }, undefined, false, undefined, this);
3319
+ }
3320
+
3321
+ // src/components/slots/maps/block-actions.tsx
3322
+ import { jsxDEV as jsxDEV27 } from "react/jsx-dev-runtime";
3323
+ function BlockActions({ className, children, ...rest }) {
3324
+ const focusMemo = useSlice("focus_memory");
3325
+ const focus = focusMemo?.blocks?.[0];
3326
+ const items = useSlots("block-actions");
3327
+ const lastPositionRef = useRef3({ active: false, top: 0, left: 0 });
3328
+ const block = useBlock(focus?.id ?? "");
3329
+ const isOpened = !!useSlice("insertion");
3330
+ const position = useMemo3(() => {
3331
+ if (!focus || !block || !isEditableField(block) || block.type === "caption") {
3332
+ return { active: false, top: 0, left: 0 };
3333
+ }
3334
+ const hasContent = !!block.props.children.text.length;
3335
+ if (hasContent) {
3336
+ return { active: false, top: 0, left: 0 };
3337
+ }
3338
+ const { id: firstSelectionId, rect: blockRect } = focus;
3339
+ const container = document.getElementById("corax_flow_blocks_container");
3340
+ if (!container)
3341
+ return { active: false, top: 0, left: 0 };
3342
+ const containerRect = container.getBoundingClientRect();
3343
+ const domElement = document.getElementById(firstSelectionId);
3344
+ if (!domElement)
3345
+ return { active: false, top: 0, left: 0 };
3346
+ const heightDiff = 36 - blockRect.height;
3347
+ const toSubstract = heightDiff / 2;
3348
+ const top = blockRect.top - (-toSubstract > 32 ? -8 : toSubstract) - containerRect.top - container.clientTop + blockRect.parentScrollTop;
3349
+ return {
3350
+ active: true,
3351
+ top,
3352
+ left: IMAGE_BREAKOUT_GUTTER - 44
3353
+ };
3354
+ }, [focus, block]);
3355
+ useEffect12(() => {
3356
+ if (position.active) {
3357
+ lastPositionRef.current = position;
3358
+ }
3359
+ }, [position]);
3360
+ const _position = position.active ? position : lastPositionRef.current;
3361
+ return /* @__PURE__ */ jsxDEV27("div", {
3362
+ style: {
3363
+ top: _position.top,
3364
+ left: _position.left
3365
+ },
3366
+ className: cn14("absolute top-0 left-0 gap-1 z-10 flex items-center transition-opacity", className, {
3367
+ "opacity-0 pointer-events-none": !position.active || !focus
3368
+ }),
3369
+ role: "block-actions",
3370
+ ...rest,
3371
+ children: [
3372
+ /* @__PURE__ */ jsxDEV27(Slots, {
3373
+ slotName: "block-actions"
3374
+ }, undefined, false, undefined, this),
3375
+ /* @__PURE__ */ jsxDEV27("div", {
3376
+ style: {
3377
+ width: isOpened ? (items.length - 1) * 32 + 8 : 0
3378
+ },
3379
+ className: cn14("absolute h-9.5 -z-1 left-9 bg-corax-popover border border-corax-border rounded-full transition-all duration-300 ease-damping", {
3380
+ "opacity-0 pointer-events-none": !isOpened
3381
+ })
3382
+ }, undefined, false, undefined, this),
3383
+ children
3384
+ ]
3385
+ }, undefined, true, undefined, this);
3386
+ }
3387
+ // src/components/slots/maps/overlays.tsx
3388
+ import { jsxDEV as jsxDEV28, Fragment as Fragment3 } from "react/jsx-dev-runtime";
3389
+ function Overlays() {
3390
+ return /* @__PURE__ */ jsxDEV28(Fragment3, {
3391
+ children: /* @__PURE__ */ jsxDEV28(Slots, {
3392
+ slotName: "overlay"
3393
+ }, undefined, false, undefined, this)
3394
+ }, undefined, false, undefined, this);
3395
+ }
3396
+ // src/components/slots/maps/text-inspector.tsx
3397
+ import { jsxDEV as jsxDEV29 } from "react/jsx-dev-runtime";
3398
+ function TextInspector({ blockId }) {
3399
+ return /* @__PURE__ */ jsxDEV29("div", {
3400
+ children: blockId
3401
+ }, undefined, false, undefined, this);
3402
+ }
3403
+ // src/components/slots/maps/toolbar.tsx
3404
+ import { cn as cn15 } from "cn";
3405
+ import { useEffect as useEffect13, useReducer, useRef as useRef4, useState as useState5 } from "react";
3406
+ import { jsxDEV as jsxDEV30 } from "react/jsx-dev-runtime";
3407
+ var TOOLBAR_OFFSET = 44;
3408
+ var TOOLBAR_MARGIN = -44;
3409
+ var DEFAULT_STATE = { active: false, top: 0, left: 0 };
3410
+ function Toolbar({ className, children, ...rest }) {
3411
+ const items = useSlots("toolbar");
3412
+ const ui = useUIContext();
3413
+ const [toolbarWidth, setToolbarWidth] = useState5(0);
3414
+ const [toolbarHeight, setToolbarHeight] = useState5(0);
3415
+ const [, bumpViewport] = useReducer((x) => x + 1, 0);
3416
+ const length = items.reduce((prev, c) => {
3417
+ if (c.when?.(ui)) {
3418
+ return prev + 1;
3419
+ }
3420
+ return prev;
3421
+ }, 0);
3422
+ const textSel = useSlice("textSelection");
3423
+ const currentBlockId = textSel?.blockId;
3424
+ const selection2 = useSlice("selection");
3425
+ const lastPositionRef = useRef4(DEFAULT_STATE);
3426
+ const toolbarRef = useRef4(null);
3427
+ const frameRef = useRef4(0);
3428
+ useIsomorphicLayoutEffect(() => {
3429
+ const toolbarElement = toolbarRef.current;
3430
+ if (!toolbarElement)
3431
+ return;
3432
+ const updateToolbarSize = () => {
3433
+ const rect = toolbarElement.getBoundingClientRect();
3434
+ setToolbarWidth(rect.width);
3435
+ setToolbarHeight(rect.height);
3436
+ };
3437
+ updateToolbarSize();
3438
+ const resizeObserver = new ResizeObserver(updateToolbarSize);
3439
+ resizeObserver.observe(toolbarElement);
3440
+ return () => resizeObserver.disconnect();
3441
+ }, []);
3442
+ useEffect13(() => {
3443
+ const container = document.getElementById("corax_flow_blocks_container");
3444
+ const onViewportChange = () => {
3445
+ if (frameRef.current)
3446
+ return;
3447
+ frameRef.current = requestAnimationFrame(() => {
3448
+ frameRef.current = 0;
3449
+ bumpViewport();
3450
+ });
3451
+ };
3452
+ container?.addEventListener("scroll", onViewportChange, { passive: true });
3453
+ window.addEventListener("scroll", onViewportChange, { passive: true });
3454
+ window.addEventListener("resize", onViewportChange);
3455
+ return () => {
3456
+ if (frameRef.current)
3457
+ cancelAnimationFrame(frameRef.current);
3458
+ container?.removeEventListener("scroll", onViewportChange);
3459
+ window.removeEventListener("scroll", onViewportChange);
3460
+ window.removeEventListener("resize", onViewportChange);
3461
+ };
3462
+ }, []);
3463
+ const computePosition = () => {
3464
+ const toolbarElement = toolbarRef.current;
3465
+ if (!toolbarElement || toolbarWidth === 0) {
3466
+ return DEFAULT_STATE;
3467
+ }
3468
+ const container = document.getElementById("corax_flow_blocks_container");
3469
+ const containerRect = container?.getBoundingClientRect();
3470
+ const clampTop = (top) => {
3471
+ if (!containerRect)
3472
+ return top;
3473
+ const min = containerRect.top + TOOLBAR_MARGIN;
3474
+ const max = containerRect.bottom - TOOLBAR_MARGIN - toolbarHeight;
3475
+ return Math.min(Math.max(top, min), Math.max(min, max));
3476
+ };
3477
+ if (textSel && currentBlockId && textSel.start !== textSel.end) {
3478
+ const el = document.getElementById(textSel.blockId);
3479
+ const range = el ? offsetsToRange(el, textSel.start, textSel.end) : null;
3480
+ if (range) {
3481
+ const selRect = range.getBoundingClientRect();
3482
+ return {
3483
+ active: true,
3484
+ top: clampTop(selRect.top - TOOLBAR_OFFSET),
3485
+ left: selRect.left + (selRect.width - toolbarWidth) / 2
3486
+ };
3487
+ }
3488
+ }
3489
+ const rects = Array.from(selection2?.blocks?.keys() ?? []).map((id) => blockRectFromBlockId(id)).filter((rect) => !!rect);
3490
+ if (rects.length > 0) {
3491
+ const top = Math.min(...rects.map((rect) => rect.top));
3492
+ const left = Math.min(...rects.map((rect) => rect.left));
3493
+ const right = Math.max(...rects.map((rect) => rect.right));
3494
+ return {
3495
+ active: true,
3496
+ top: clampTop(top - TOOLBAR_OFFSET),
3497
+ left: (left + right) / 2 - toolbarWidth / 2
3498
+ };
3499
+ }
3500
+ return DEFAULT_STATE;
3501
+ };
3502
+ const position = computePosition();
3503
+ useEffect13(() => {
3504
+ if (position.active) {
3505
+ lastPositionRef.current = position;
3506
+ }
3507
+ }, [position]);
3508
+ const _position = position.active ? position : lastPositionRef.current;
3509
+ return /* @__PURE__ */ jsxDEV30("div", {
3510
+ ref: toolbarRef,
3511
+ style: {
3512
+ top: _position.top,
3513
+ left: _position.left
3514
+ },
3515
+ className: cn15("fixed top-0 left-0 gap-1 flex items-center transition-opacity bg-corax-popover p-1 rounded-[12px] border border-corax-border", className, {
3516
+ "opacity-0 pointer-events-none": !position.active || !length
3517
+ }),
3518
+ role: "toolbar",
3519
+ ...rest,
3520
+ children: [
3521
+ /* @__PURE__ */ jsxDEV30(Slots, {
3522
+ slotName: "toolbar"
3523
+ }, undefined, false, undefined, this),
3524
+ children
3525
+ ]
3526
+ }, undefined, true, undefined, this);
3527
+ }
3528
+
3529
+ // src/components/slots/maps/index.ts
3530
+ "use client";
3531
+ // src/components/index.ts
3532
+ "use client";
3533
+
3534
+ // src/index.ts
3535
+ export * from "@coorax/core";
3536
+ export * from "@coorax/render-react";
3537
+ "use client";
3538
+ export {
3539
+ useUIContext,
3540
+ useSlice,
3541
+ useIsomorphicLayoutEffect,
3542
+ useEngine,
3543
+ rangeToOffsets,
3544
+ offsetsToRange,
3545
+ loadCompleteDocument,
3546
+ getFieldTypeAndTargetId,
3547
+ getBlockActionsProps,
3548
+ forField,
3549
+ focusDomElement,
3550
+ focusDomBLockById,
3551
+ blockRectFromBlockId,
3552
+ UIPrimitivesRegistry,
3553
+ Toolbar,
3554
+ TextInspector,
3555
+ SlotsModule,
3556
+ SlotsComponentRegistry,
3557
+ PrimitivesComponentsRegistry,
3558
+ Overlays,
3559
+ LocalDB,
3560
+ IMAGE_BREAKOUT_GUTTER,
3561
+ GenericRegistry3 as GenericRegistry,
3562
+ FieldHandlersRegistry,
3563
+ FieldHandlers,
3564
+ FallbacksModule,
3565
+ FallbackComponentsRegistry,
3566
+ FLC,
3567
+ ErrorComponentsRegistry,
3568
+ CoraxIconsRegistry,
3569
+ CoraxIcon,
3570
+ CoraxFlow,
3571
+ CoraxEngineProvider,
3572
+ CORAX_INDEXED_DB,
3573
+ BlockActions,
3574
+ AutoSaveModule
3575
+ };