@coorax/react 0.0.0-canary.4 → 0.0.0-canary.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/commons/youtube.d.ts +2 -0
- package/dist/components/corax-context-provider.d.ts +5 -0
- package/dist/components/corax-flow.d.ts +2 -0
- package/dist/components/errors/iframe.error.d.ts +2 -0
- package/dist/components/errors/image.error.d.ts +2 -0
- package/dist/components/errors/video.errors.d.ts +2 -0
- package/dist/components/fallbacks/iframe,fallback.d.ts +2 -0
- package/dist/components/fallbacks/iframe.fallback.d.ts +2 -0
- package/dist/components/fallbacks/image.fallback.d.ts +2 -3
- package/dist/components/fallbacks/link.fallback.d.ts +2 -0
- package/dist/components/fallbacks/video.fallback.d.ts +2 -0
- package/dist/components/slots/buttons/block-actions-button.d.ts +2 -2
- package/dist/components/slots/buttons/caption-button.d.ts +3 -0
- package/dist/components/slots/buttons/code-theme-button.d.ts +3 -0
- package/dist/components/slots/buttons/delete-button.d.ts +3 -0
- package/dist/components/slots/buttons/divider-style-button.d.ts +3 -0
- package/dist/components/slots/buttons/divider-width-button.d.ts +3 -0
- package/dist/components/slots/buttons/iframe-playback-button.d.ts +3 -0
- package/dist/components/slots/buttons/image-width-button.d.ts +3 -0
- package/dist/components/slots/buttons/paragraph-theme-button.d.ts +3 -0
- package/dist/components/slots/buttons/toolbar-button.d.ts +2 -2
- package/dist/components/slots/overlays/focus-overlay.d.ts +2 -2
- package/dist/components/slots/overlays/hover-overlay.d.ts +2 -2
- package/dist/components/slots/overlays/selection-overlay.d.ts +2 -2
- package/dist/hooks/use-is-selected.d.ts +2 -0
- package/dist/hooks/use-renderer.d.ts +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1611 -885
- package/dist/lib/comp.utils.d.ts +5 -1
- package/dist/lifecycle/fields/common/focus.events/onblur.d.ts +3 -0
- package/dist/lifecycle/fields/common/focus.events/onfocus.d.ts +3 -0
- package/dist/lifecycle/fields/common/handlers.d.ts +13 -0
- package/dist/lifecycle/fields/common/mouse.events/onclick.d.ts +3 -0
- package/dist/lifecycle/fields/common/mouse.events/onmouseenter.d.ts +3 -0
- package/dist/lifecycle/fields/common/mouse.events/onmouseleave.d.ts +3 -0
- package/dist/lifecycle/fields/divider/handlers.d.ts +7 -0
- package/dist/lifecycle/fields/divider/keyboard.events/onkeydown.d.ts +3 -0
- package/dist/lifecycle/fields/editable/focus.events/onbeforeinput.d.ts +3 -0
- package/dist/lifecycle/fields/editable/handlers.d.ts +7 -0
- package/dist/lifecycle/fields/editable/keyboard.events/onkeydown.d.ts +3 -0
- package/dist/lifecycle/fields/editable/mouse.events/ondoubleclick.d.ts +4 -0
- package/dist/lifecycle/fields/editable/synthetic.events/onselect.d.ts +3 -0
- package/dist/lifecycle/fields/handlers.registry.d.ts +12 -0
- package/dist/lifecycle/fields/lifecycle.fields.d.ts +8 -10
- package/dist/lifecycle/fields/lifecycle.fields.types.d.ts +3 -14
- package/dist/lifecycle/fields/lifecycle.utils.d.ts +7 -1
- package/dist/lifecycle/fields/media/common/handlers.d.ts +7 -0
- package/dist/lifecycle/fields/media/common/keyboard.events/onkeydown.d.ts +3 -0
- package/dist/lifecycle/fields/media/common/synthetic.events/onerror.d.ts +3 -0
- package/dist/lifecycle/fields/media/handlers.d.ts +7 -0
- package/dist/lifecycle/fields/media/iframe/handlers.d.ts +7 -0
- package/dist/lifecycle/fields/media/iframe/synthetic.events/onload.d.ts +3 -0
- package/dist/lifecycle/fields/media/image/handlers.d.ts +7 -0
- package/dist/lifecycle/fields/media/image/synthetic.events/onload.d.ts +3 -0
- package/dist/lifecycle/fields/media/keyboard.events/onkeydown.d.ts +3 -0
- package/dist/lifecycle/fields/media/synthetic.events/onload.d.ts +3 -0
- package/dist/lifecycle/fields/media/video/handlers.d.ts +7 -0
- package/dist/lifecycle/fields/media/video/mouse.events/ondoubleclick.d.ts +4 -0
- package/dist/lifecycle/fields/media/video/synthetic.events/oncanplaythrough.d.ts +3 -0
- package/dist/modules/autosave.module.d.ts +10 -0
- package/dist/modules/errors.module.d.ts +7 -0
- package/dist/primitives/fields/field.primitives.d.ts +1 -1
- package/dist/primitives/index.d.ts +1 -1
- package/dist/registry/errors.registry.d.ts +8 -0
- package/dist/registry/fallbacks.registry.d.ts +3 -2
- package/dist/registry/index.d.ts +2 -3
- package/dist/registry/slots.registry.d.ts +1 -1
- package/dist/registry/ui.primitives.registry.d.ts +1 -1
- package/dist/services/index.d.ts +1 -0
- package/dist/services/localdb/db/db.d.ts +6 -2
- package/dist/services/localdb/lexer/lexer.types.d.ts +1 -1
- package/dist/services/localdb/parser/parser.d.ts +1 -0
- package/dist/services/localdb/parser/parser.types.d.ts +8 -2
- package/dist/styles.css +1 -1093
- package/package.json +11 -9
- package/styles.css +1 -0
- package/dist/renderer/renderer.d.ts +0 -23
- package/dist/renderer/renderer.types.d.ts +0 -2
- package/dist/renderer/renderer.utils.d.ts +0 -14
- package/dist/renderer/utils/divider.renderer.utils.d.ts +0 -6
- /package/dist/{renderer/renderer.test.d.ts → services/localdb/dbtest.d.ts} +0 -0
package/dist/index.js
CHANGED
|
@@ -1,37 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
|
-
// src/registry/registry.ts
|
|
4
|
-
class GenericRegistry {
|
|
5
|
-
items = new Map;
|
|
6
|
-
listeners = new Map;
|
|
7
|
-
notify(key) {
|
|
8
|
-
this.listeners.get(key)?.forEach((l) => l());
|
|
9
|
-
}
|
|
10
|
-
get(key) {
|
|
11
|
-
return this.items.get(key);
|
|
12
|
-
}
|
|
13
|
-
register(key, value) {
|
|
14
|
-
this.items.set(key, value);
|
|
15
|
-
this.notify(key);
|
|
16
|
-
return () => {
|
|
17
|
-
this.items.delete(key);
|
|
18
|
-
this.notify(key);
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
subscribe(key, fn) {
|
|
22
|
-
const set = this.listeners.get(key) ?? new Set;
|
|
23
|
-
set.add(fn);
|
|
24
|
-
this.listeners.set(key, set);
|
|
25
|
-
return () => {
|
|
26
|
-
set.delete(fn);
|
|
27
|
-
if (set.size === 0) {
|
|
28
|
-
this.listeners.delete(key);
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
3
|
// src/registry/slots.registry.tsx
|
|
4
|
+
import { GenericRegistry } from "@coorax/render-react";
|
|
35
5
|
var SlotsComponentRegistry = new GenericRegistry;
|
|
36
6
|
|
|
37
7
|
// src/components/commons/button.tsx
|
|
@@ -81,39 +51,234 @@ function Button({
|
|
|
81
51
|
|
|
82
52
|
// src/components/corax-context-provider.tsx
|
|
83
53
|
import {
|
|
54
|
+
CaptionModule,
|
|
55
|
+
CodeModule,
|
|
56
|
+
DeletionModule,
|
|
57
|
+
DividerModule,
|
|
84
58
|
EditorModule,
|
|
85
59
|
Engine,
|
|
86
60
|
FocusModule,
|
|
87
61
|
HistoryModule,
|
|
88
62
|
HoverModule,
|
|
89
63
|
InsertionModule,
|
|
64
|
+
MediaModule,
|
|
65
|
+
ParagraphThemeModule,
|
|
90
66
|
SelectionModule,
|
|
91
|
-
TextEditingModule
|
|
67
|
+
TextEditingModule,
|
|
68
|
+
getCollectedStyles,
|
|
69
|
+
setCoraxStyleSink
|
|
92
70
|
} from "@coorax/core";
|
|
93
|
-
import { createContext, useContext, useMemo } from "react";
|
|
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;
|
|
94
75
|
|
|
95
|
-
// src/registry/
|
|
96
|
-
|
|
76
|
+
// src/registry/index.ts
|
|
77
|
+
import {
|
|
78
|
+
GenericRegistry as GenericRegistry3,
|
|
79
|
+
PrimitivesComponentsRegistry,
|
|
80
|
+
ErrorComponentsRegistry,
|
|
81
|
+
FallbackComponentsRegistry
|
|
82
|
+
} from "@coorax/render-react";
|
|
97
83
|
|
|
98
84
|
// src/components/fallbacks/image.fallback.tsx
|
|
99
|
-
import { RefreshCw } from "lucide-react";
|
|
85
|
+
import { RefreshCw, Trash2 } from "lucide-react";
|
|
100
86
|
import { cn as cn2 } from "cn";
|
|
87
|
+
import { useEffect, useState } from "react";
|
|
101
88
|
import { jsxDEV as jsxDEV2 } from "react/jsx-dev-runtime";
|
|
102
|
-
function ImageFallback({
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
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
|
+
}, []);
|
|
107
97
|
return /* @__PURE__ */ jsxDEV2("div", {
|
|
108
|
-
className:
|
|
109
|
-
|
|
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-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",
|
|
110
144
|
children: [
|
|
111
|
-
/* @__PURE__ */
|
|
112
|
-
className: "
|
|
145
|
+
/* @__PURE__ */ jsxDEV3("div", {
|
|
146
|
+
className: cn3("w-full h-full absolute inset-0 flex gap-2 items-center justify-center bg-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
|
+
/* @__PURE__ */ jsxDEV3("video", {}, undefined, false, undefined, this)
|
|
171
|
+
]
|
|
172
|
+
}, undefined, true, undefined, this);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// src/components/fallbacks/iframe.fallback.tsx
|
|
176
|
+
import { RefreshCw as RefreshCw3, Trash2 as Trash23 } from "lucide-react";
|
|
177
|
+
import { cn as cn4 } from "cn";
|
|
178
|
+
import { useState as useState3, useEffect as useEffect3 } from "react";
|
|
179
|
+
import { jsxDEV as jsxDEV4 } from "react/jsx-dev-runtime";
|
|
180
|
+
function IFrameFallback({ children, ...rest }) {
|
|
181
|
+
const [displayRemoveButton, setDisplayRemoveButton] = useState3(false);
|
|
182
|
+
useEffect3(() => {
|
|
183
|
+
const timer = setTimeout(() => {
|
|
184
|
+
setDisplayRemoveButton(true);
|
|
185
|
+
}, 1e4);
|
|
186
|
+
return () => clearTimeout(timer);
|
|
187
|
+
}, []);
|
|
188
|
+
return /* @__PURE__ */ jsxDEV4("div", {
|
|
189
|
+
className: "w-full flex relative pointer-events-none",
|
|
190
|
+
children: [
|
|
191
|
+
/* @__PURE__ */ jsxDEV4("div", {
|
|
192
|
+
className: cn4("w-full h-full absolute inset-0 flex gap-2 items-center justify-center bg-card"),
|
|
193
|
+
children: [
|
|
194
|
+
/* @__PURE__ */ jsxDEV4(RefreshCw3, {
|
|
195
|
+
className: "animate-spin size-5"
|
|
196
|
+
}, undefined, false, undefined, this),
|
|
197
|
+
/* @__PURE__ */ jsxDEV4("span", {
|
|
198
|
+
className: "font-semibold",
|
|
199
|
+
children: rest.name
|
|
200
|
+
}, undefined, false, undefined, this)
|
|
201
|
+
]
|
|
202
|
+
}, undefined, true, undefined, this),
|
|
203
|
+
children,
|
|
204
|
+
displayRemoveButton && /* @__PURE__ */ jsxDEV4(Button, {
|
|
205
|
+
onClick: () => {
|
|
206
|
+
if (confirm("Delete iframe field ?")) {
|
|
207
|
+
window.__cooraxEngine.document.apply((t) => window.__cooraxEngine.mutations.deleteField(t, rest.id), { origin: "history" });
|
|
208
|
+
}
|
|
209
|
+
},
|
|
210
|
+
className: "absolute bottom-2 right-2 cursor-pointer pointer-events-auto",
|
|
211
|
+
title: "Delete iframe field ?",
|
|
212
|
+
variant: "destructive",
|
|
213
|
+
size: "icon-lg",
|
|
214
|
+
children: /* @__PURE__ */ jsxDEV4(Trash23, {}, undefined, false, undefined, this)
|
|
215
|
+
}, undefined, false, undefined, this)
|
|
216
|
+
]
|
|
217
|
+
}, undefined, true, undefined, this);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// src/components/fallbacks/link.fallback.tsx
|
|
221
|
+
import { cn as cn5 } from "cn";
|
|
222
|
+
import { Trash2 as Trash24 } from "lucide-react";
|
|
223
|
+
import { useState as useState4, useEffect as useEffect4 } from "react";
|
|
224
|
+
import { jsxDEV as jsxDEV5 } from "react/jsx-dev-runtime";
|
|
225
|
+
function LinkFallback({ ...rest }) {
|
|
226
|
+
const [displayRemoveButton, setDisplayRemoveButton] = useState4(false);
|
|
227
|
+
useEffect4(() => {
|
|
228
|
+
const timer = setTimeout(() => {
|
|
229
|
+
setDisplayRemoveButton(true);
|
|
230
|
+
}, 1e4);
|
|
231
|
+
return () => clearTimeout(timer);
|
|
232
|
+
}, []);
|
|
233
|
+
return /* @__PURE__ */ jsxDEV5("div", {
|
|
234
|
+
className: "w-full h-[18px] rounded-[6px] overflow-hidden flex relative pointer-events-none bg-card",
|
|
235
|
+
children: [
|
|
236
|
+
/* @__PURE__ */ jsxDEV5("div", {
|
|
237
|
+
className: cn5("h-full absolute inset-0 bg-primary overflow-hidden"),
|
|
238
|
+
style: {
|
|
239
|
+
animation: "loading-skeleton 100s ease-in-out forwards"
|
|
240
|
+
},
|
|
241
|
+
children: /* @__PURE__ */ jsxDEV5("div", {
|
|
242
|
+
className: "w-full h-full bg-gradient-to-r from-transparent via-white/30 to-transparent",
|
|
243
|
+
style: {
|
|
244
|
+
animation: "loading-shimmer 1.55s ease-in-out infinite"
|
|
245
|
+
}
|
|
246
|
+
}, undefined, false, undefined, this)
|
|
247
|
+
}, undefined, false, undefined, this),
|
|
248
|
+
/* @__PURE__ */ jsxDEV5("span", {
|
|
249
|
+
className: "min-w-max absolute -translate-x-1/2 left-1/2 top-1/2 -translate-y-1/2 text-xs",
|
|
250
|
+
children: [
|
|
251
|
+
"Loading ",
|
|
252
|
+
rest.props.children.text,
|
|
253
|
+
"..."
|
|
254
|
+
]
|
|
255
|
+
}, undefined, true, undefined, this),
|
|
256
|
+
/* @__PURE__ */ jsxDEV5("style", {
|
|
257
|
+
children: `
|
|
258
|
+
@keyframes loading-skeleton {
|
|
259
|
+
0% { width: 0%; opacity: 0.7; }
|
|
260
|
+
1% { width: 60%; opacity: 1; }
|
|
261
|
+
4% { width: 90%; opacity: 0.7; }
|
|
262
|
+
90% { width: 100%; opacity: 0.7; }
|
|
263
|
+
100% { width: 100%; opacity: 0.7; }
|
|
264
|
+
}
|
|
265
|
+
@keyframes loading-shimmer {
|
|
266
|
+
0% { transform: translateX(-100%); }
|
|
267
|
+
100% { transform: translateX(100%); }
|
|
268
|
+
}
|
|
269
|
+
`
|
|
113
270
|
}, undefined, false, undefined, this),
|
|
114
|
-
/* @__PURE__ */
|
|
115
|
-
|
|
116
|
-
|
|
271
|
+
displayRemoveButton && /* @__PURE__ */ jsxDEV5(Button, {
|
|
272
|
+
onClick: () => {
|
|
273
|
+
if (confirm("Delete image field ?")) {
|
|
274
|
+
window.__cooraxEngine.document.apply((t) => window.__cooraxEngine.mutations.deleteField(t, rest.id), { origin: "history" });
|
|
275
|
+
}
|
|
276
|
+
},
|
|
277
|
+
className: "absolute -bottom-0.5 right-0 cursor-pointer pointer-events-auto",
|
|
278
|
+
title: "Delete link field ?",
|
|
279
|
+
variant: "destructive",
|
|
280
|
+
size: "icon-xs",
|
|
281
|
+
children: /* @__PURE__ */ jsxDEV5(Trash24, {}, undefined, false, undefined, this)
|
|
117
282
|
}, undefined, false, undefined, this)
|
|
118
283
|
]
|
|
119
284
|
}, undefined, true, undefined, this);
|
|
@@ -126,11 +291,127 @@ var FallbacksModule = {
|
|
|
126
291
|
requires: [],
|
|
127
292
|
install() {
|
|
128
293
|
FallbackComponentsRegistry.register("image", ImageFallback);
|
|
294
|
+
FallbackComponentsRegistry.register("video", VideoFallback);
|
|
295
|
+
FallbackComponentsRegistry.register("iframe", IFrameFallback);
|
|
296
|
+
FallbackComponentsRegistry.register("link", LinkFallback);
|
|
129
297
|
}
|
|
130
298
|
};
|
|
131
299
|
|
|
300
|
+
// src/components/errors/video.errors.tsx
|
|
301
|
+
import { AlertTriangle } from "lucide-react";
|
|
302
|
+
import { cn as cn6 } from "cn";
|
|
303
|
+
import { jsxDEV as jsxDEV6 } from "react/jsx-dev-runtime";
|
|
304
|
+
function VideoErrorComponent({ children, ...rest }) {
|
|
305
|
+
return /* @__PURE__ */ jsxDEV6("div", {
|
|
306
|
+
className: "w-full h-[360px] flex relative pointer-events-none",
|
|
307
|
+
children: [
|
|
308
|
+
/* @__PURE__ */ jsxDEV6("div", {
|
|
309
|
+
className: cn6("w-full h-full absolute inset-0 flex gap-2 items-center justify-center bg-destructive/5 border-3 border-dashed border-destructive"),
|
|
310
|
+
children: [
|
|
311
|
+
/* @__PURE__ */ jsxDEV6(AlertTriangle, {
|
|
312
|
+
className: "size-5 text-destructive"
|
|
313
|
+
}, undefined, false, undefined, this),
|
|
314
|
+
"Failed to load ",
|
|
315
|
+
/* @__PURE__ */ jsxDEV6("span", {
|
|
316
|
+
className: "font-semibold",
|
|
317
|
+
children: rest.name
|
|
318
|
+
}, undefined, false, undefined, this)
|
|
319
|
+
]
|
|
320
|
+
}, undefined, true, undefined, this),
|
|
321
|
+
children
|
|
322
|
+
]
|
|
323
|
+
}, undefined, true, undefined, this);
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
// src/components/errors/image.error.tsx
|
|
327
|
+
import { AlertTriangle as AlertTriangle2 } from "lucide-react";
|
|
328
|
+
import { cn as cn7 } from "cn";
|
|
329
|
+
import { jsxDEV as jsxDEV7 } from "react/jsx-dev-runtime";
|
|
330
|
+
function ImageErrorComponent({ children, ...rest }) {
|
|
331
|
+
return /* @__PURE__ */ jsxDEV7("div", {
|
|
332
|
+
className: "w-full h-[360px] flex relative pointer-events-none",
|
|
333
|
+
children: [
|
|
334
|
+
/* @__PURE__ */ jsxDEV7("div", {
|
|
335
|
+
className: cn7("w-full h-full absolute inset-0 flex gap-2 items-center justify-center bg-destructive/5 border-3 border-dashed border-destructive"),
|
|
336
|
+
children: [
|
|
337
|
+
/* @__PURE__ */ jsxDEV7(AlertTriangle2, {
|
|
338
|
+
className: "size-5 text-destructive"
|
|
339
|
+
}, undefined, false, undefined, this),
|
|
340
|
+
"Failed to load ",
|
|
341
|
+
/* @__PURE__ */ jsxDEV7("span", {
|
|
342
|
+
className: "font-semibold",
|
|
343
|
+
children: rest.name
|
|
344
|
+
}, undefined, false, undefined, this)
|
|
345
|
+
]
|
|
346
|
+
}, undefined, true, undefined, this),
|
|
347
|
+
children
|
|
348
|
+
]
|
|
349
|
+
}, undefined, true, undefined, this);
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
// src/components/errors/iframe.error.tsx
|
|
353
|
+
import { AlertTriangle as AlertTriangle3 } from "lucide-react";
|
|
354
|
+
import { cn as cn8 } from "cn";
|
|
355
|
+
import { jsxDEV as jsxDEV8 } from "react/jsx-dev-runtime";
|
|
356
|
+
function IFrameErrorComponent({ children, ...rest }) {
|
|
357
|
+
return /* @__PURE__ */ jsxDEV8("div", {
|
|
358
|
+
className: "w-full h-[360px] flex relative pointer-events-none",
|
|
359
|
+
children: [
|
|
360
|
+
/* @__PURE__ */ jsxDEV8("div", {
|
|
361
|
+
className: cn8("w-full h-full absolute inset-0 flex gap-2 items-center justify-center bg-destructive/5 border-3 border-dashed border-destructive"),
|
|
362
|
+
children: [
|
|
363
|
+
/* @__PURE__ */ jsxDEV8(AlertTriangle3, {
|
|
364
|
+
className: "size-5 text-destructive"
|
|
365
|
+
}, undefined, false, undefined, this),
|
|
366
|
+
"Failed to load ",
|
|
367
|
+
/* @__PURE__ */ jsxDEV8("span", {
|
|
368
|
+
className: "font-semibold",
|
|
369
|
+
children: rest.name
|
|
370
|
+
}, undefined, false, undefined, this)
|
|
371
|
+
]
|
|
372
|
+
}, undefined, true, undefined, this),
|
|
373
|
+
children
|
|
374
|
+
]
|
|
375
|
+
}, undefined, true, undefined, this);
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
// src/modules/errors.module.tsx
|
|
379
|
+
var ErrorsModule = {
|
|
380
|
+
name: "errors",
|
|
381
|
+
version: "1.0.0",
|
|
382
|
+
requires: [],
|
|
383
|
+
install() {
|
|
384
|
+
ErrorComponentsRegistry.register("image", ImageErrorComponent);
|
|
385
|
+
ErrorComponentsRegistry.register("video", VideoErrorComponent);
|
|
386
|
+
ErrorComponentsRegistry.register("iframe", IFrameErrorComponent);
|
|
387
|
+
}
|
|
388
|
+
};
|
|
389
|
+
|
|
390
|
+
// src/hooks/use-slice.ts
|
|
391
|
+
import { useSyncExternalStore } from "react";
|
|
392
|
+
function useSlice(sliceName) {
|
|
393
|
+
const engine = useEngine();
|
|
394
|
+
const slice = useSyncExternalStore((fn) => engine.state.subscribe(sliceName, fn), () => engine.state.get(sliceName), () => engine.state.get(sliceName));
|
|
395
|
+
return slice;
|
|
396
|
+
}
|
|
397
|
+
// src/hooks/use-ui-context.ts
|
|
398
|
+
function useUIContext() {
|
|
399
|
+
const selection = useSlice("selection") ?? { blocks: new Map };
|
|
400
|
+
const focus = useSlice("focus") ?? null;
|
|
401
|
+
const hover = useSlice("hover") ?? null;
|
|
402
|
+
const textSelection = useSlice("textSelection") ?? null;
|
|
403
|
+
return {
|
|
404
|
+
selection,
|
|
405
|
+
focus,
|
|
406
|
+
hover,
|
|
407
|
+
textSelection
|
|
408
|
+
};
|
|
409
|
+
}
|
|
410
|
+
// src/hooks/custom/use-isomorphic-layout-effect.ts
|
|
411
|
+
import { useEffect as useEffect5, useLayoutEffect } from "react";
|
|
412
|
+
var useIsomorphicLayoutEffect = typeof window !== "undefined" ? useLayoutEffect : useEffect5;
|
|
132
413
|
// src/components/corax-context-provider.tsx
|
|
133
|
-
import { jsxDEV as
|
|
414
|
+
import { jsxDEV as jsxDEV9 } from "react/jsx-dev-runtime";
|
|
134
415
|
"use client";
|
|
135
416
|
var CoraxEngineContext = createContext(null);
|
|
136
417
|
function CoraxEngineProvider({ children }) {
|
|
@@ -138,20 +419,41 @@ function CoraxEngineProvider({ children }) {
|
|
|
138
419
|
const engine2 = new Engine;
|
|
139
420
|
engine2.modules.register([
|
|
140
421
|
HistoryModule,
|
|
141
|
-
AutoSaveModule,
|
|
142
422
|
EditorModule,
|
|
143
423
|
HoverModule,
|
|
144
424
|
InsertionModule,
|
|
145
425
|
FocusModule,
|
|
146
426
|
SelectionModule,
|
|
147
427
|
TextEditingModule,
|
|
428
|
+
CodeModule,
|
|
429
|
+
CaptionModule,
|
|
430
|
+
MediaModule,
|
|
431
|
+
DividerModule,
|
|
432
|
+
ParagraphThemeModule,
|
|
433
|
+
DeletionModule,
|
|
148
434
|
SlotsModule,
|
|
149
|
-
FallbacksModule
|
|
435
|
+
FallbacksModule,
|
|
436
|
+
ErrorsModule
|
|
150
437
|
]);
|
|
151
438
|
engine2.modules.enableAll();
|
|
152
439
|
return engine2;
|
|
153
440
|
}, []);
|
|
154
|
-
|
|
441
|
+
useEffect6(() => {
|
|
442
|
+
const styleEl = document.createElement("style");
|
|
443
|
+
styleEl.setAttribute("data-corax", "pseudo-styles");
|
|
444
|
+
document.head.appendChild(styleEl);
|
|
445
|
+
const dispose = setCoraxStyleSink(() => {
|
|
446
|
+
styleEl.textContent = getCollectedStyles();
|
|
447
|
+
});
|
|
448
|
+
return () => {
|
|
449
|
+
dispose();
|
|
450
|
+
styleEl.remove();
|
|
451
|
+
};
|
|
452
|
+
}, []);
|
|
453
|
+
useIsomorphicLayoutEffect(() => {
|
|
454
|
+
window.__cooraxEngine = engine;
|
|
455
|
+
}, [engine]);
|
|
456
|
+
return /* @__PURE__ */ jsxDEV9(CoraxEngineContext.Provider, {
|
|
155
457
|
value: engine,
|
|
156
458
|
children
|
|
157
459
|
}, undefined, false, undefined, this);
|
|
@@ -164,76 +466,36 @@ function useEngine() {
|
|
|
164
466
|
return engine;
|
|
165
467
|
}
|
|
166
468
|
|
|
167
|
-
// src/hooks/use-slice.ts
|
|
168
|
-
import { useSyncExternalStore } from "react";
|
|
169
|
-
function useSlice(sliceName) {
|
|
170
|
-
const engine = useEngine();
|
|
171
|
-
const slice = useSyncExternalStore((fn) => engine.state.subscribe(sliceName, fn), () => engine.state.get(sliceName), () => engine.state.get(sliceName));
|
|
172
|
-
return slice;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
469
|
// src/lib/slots.utils.tsx
|
|
176
|
-
import { cn as
|
|
470
|
+
import { cn as cn9 } from "cn";
|
|
177
471
|
function getBlockActionsProps(isOpen, index) {
|
|
178
472
|
return {
|
|
179
|
-
className:
|
|
473
|
+
className: cn9("absolute cursor-pointer transition-all disabled:pointer-events-none disabled:opacity-50"),
|
|
180
474
|
style: {
|
|
181
475
|
"--index": isOpen ? 0 : index,
|
|
182
|
-
"--step": isOpen ? "0px" : "
|
|
183
|
-
transform: "translateX(calc((
|
|
476
|
+
"--step": isOpen ? "0px" : "42px",
|
|
477
|
+
transform: "translateX(calc((32px*var(--index)) + var(--step))"
|
|
184
478
|
}
|
|
185
479
|
};
|
|
186
480
|
}
|
|
187
481
|
|
|
188
482
|
// src/components/slots/buttons/block-actions-button.tsx
|
|
189
|
-
import { cn as
|
|
483
|
+
import { cn as cn10 } from "cn";
|
|
190
484
|
|
|
191
485
|
// src/lib/comp.utils.tsx
|
|
486
|
+
import { GenericRegistry as GenericRegistry4 } from "@coorax/render-react";
|
|
487
|
+
import { createElement } from "react";
|
|
192
488
|
import {
|
|
193
|
-
|
|
194
|
-
HeadingIcon,
|
|
195
|
-
ImagePlus,
|
|
196
|
-
ItalicIcon,
|
|
197
|
-
LinkIcon,
|
|
198
|
-
Minus,
|
|
199
|
-
PlusIcon,
|
|
200
|
-
Pointer,
|
|
201
|
-
PointerIcon,
|
|
202
|
-
TextCursor,
|
|
203
|
-
TextInitialIcon,
|
|
204
|
-
UnderlineIcon
|
|
489
|
+
Pointer
|
|
205
490
|
} from "lucide-react";
|
|
206
|
-
|
|
491
|
+
var CoraxIconsRegistry = new GenericRegistry4;
|
|
207
492
|
function CoraxIcon({ icon }) {
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
return /* @__PURE__ */ jsxDEV4(TextCursor, {}, undefined, false, undefined, this);
|
|
211
|
-
case "CursorIcon":
|
|
212
|
-
return /* @__PURE__ */ jsxDEV4(PointerIcon, {}, undefined, false, undefined, this);
|
|
213
|
-
case "HeadingIcon":
|
|
214
|
-
return /* @__PURE__ */ jsxDEV4(HeadingIcon, {}, undefined, false, undefined, this);
|
|
215
|
-
case "PlusIcon":
|
|
216
|
-
return /* @__PURE__ */ jsxDEV4(PlusIcon, {}, undefined, false, undefined, this);
|
|
217
|
-
case "BoldIcon":
|
|
218
|
-
return /* @__PURE__ */ jsxDEV4(BoldIcon, {}, undefined, false, undefined, this);
|
|
219
|
-
case "ItalicIcon":
|
|
220
|
-
return /* @__PURE__ */ jsxDEV4(ItalicIcon, {}, undefined, false, undefined, this);
|
|
221
|
-
case "UnderlineIcon":
|
|
222
|
-
return /* @__PURE__ */ jsxDEV4(UnderlineIcon, {}, undefined, false, undefined, this);
|
|
223
|
-
case "LinkIcon":
|
|
224
|
-
return /* @__PURE__ */ jsxDEV4(LinkIcon, {}, undefined, false, undefined, this);
|
|
225
|
-
case "ImagePlus":
|
|
226
|
-
return /* @__PURE__ */ jsxDEV4(ImagePlus, {}, undefined, false, undefined, this);
|
|
227
|
-
case "TextInitial":
|
|
228
|
-
return /* @__PURE__ */ jsxDEV4(TextInitialIcon, {}, undefined, false, undefined, this);
|
|
229
|
-
case "DividerIcon":
|
|
230
|
-
return /* @__PURE__ */ jsxDEV4(Minus, {}, undefined, false, undefined, this);
|
|
231
|
-
default:
|
|
232
|
-
return /* @__PURE__ */ jsxDEV4(Pointer, {}, undefined, false, undefined, this);
|
|
233
|
-
}
|
|
493
|
+
const Icon = CoraxIconsRegistry.get(icon) ?? Pointer;
|
|
494
|
+
return createElement(Icon);
|
|
234
495
|
}
|
|
235
496
|
|
|
236
497
|
// src/lifecycle/fields/lifecycle.utils.ts
|
|
498
|
+
import { UTILS } from "@coorax/core";
|
|
237
499
|
function blockRectFromBlockId(id) {
|
|
238
500
|
const domElement = document.getElementById(id);
|
|
239
501
|
if (!domElement)
|
|
@@ -257,10 +519,31 @@ function blockRectFromBlockId(id) {
|
|
|
257
519
|
parentScrollTop: parentElement.scrollTop
|
|
258
520
|
};
|
|
259
521
|
}
|
|
522
|
+
function getFieldTypeAndTargetId(engine, ev, block) {
|
|
523
|
+
const target = block?.id ?? ev.currentTarget?.getAttribute("id") ?? null;
|
|
524
|
+
const fieldType = block?.type ?? ev.currentTarget?.getAttribute("data-block-type") ?? null;
|
|
525
|
+
if (!fieldType || !target) {
|
|
526
|
+
console.warn(`Failed to continue event at ${ev.type}`);
|
|
527
|
+
ev.preventDefault();
|
|
528
|
+
ev.stopPropagation();
|
|
529
|
+
return null;
|
|
530
|
+
}
|
|
531
|
+
const safeTarget = target;
|
|
532
|
+
const safeFieldType = fieldType;
|
|
533
|
+
function emit() {
|
|
534
|
+
return engine.events.emit("field:lifecycle", {
|
|
535
|
+
type: ev?._reactName || `on${UTILS.Capitalize(ev.type)}`,
|
|
536
|
+
target: safeTarget,
|
|
537
|
+
fieldType: safeFieldType,
|
|
538
|
+
cycleEvent: ev
|
|
539
|
+
});
|
|
540
|
+
}
|
|
541
|
+
return { fieldType: safeFieldType, target: safeTarget, emit };
|
|
542
|
+
}
|
|
260
543
|
|
|
261
544
|
// src/components/slots/buttons/block-actions-button.tsx
|
|
262
545
|
import React2 from "react";
|
|
263
|
-
import { jsxDEV as
|
|
546
|
+
import { jsxDEV as jsxDEV10 } from "react/jsx-dev-runtime";
|
|
264
547
|
var BlockActionButton = React2.memo(function BlockActionButton2({
|
|
265
548
|
c,
|
|
266
549
|
ui,
|
|
@@ -280,13 +563,13 @@ var BlockActionButton = React2.memo(function BlockActionButton2({
|
|
|
280
563
|
return null;
|
|
281
564
|
const { variant, size, isBaseButton = false } = c.getProps(ui);
|
|
282
565
|
const enabled = engine.commands.has(c.command);
|
|
283
|
-
return /* @__PURE__ */
|
|
566
|
+
return /* @__PURE__ */ jsxDEV10(Button, {
|
|
284
567
|
...rest,
|
|
285
568
|
variant,
|
|
286
569
|
size,
|
|
287
570
|
disabled: !enabled,
|
|
288
571
|
...!isBaseButton ? getBlockActionsProps(!isOpen, c.order ? c.order - 1 : 0) : {
|
|
289
|
-
className:
|
|
572
|
+
className: cn10("z-99 cursor-pointer transition-all", {
|
|
290
573
|
"rotate-45": isOpen
|
|
291
574
|
})
|
|
292
575
|
},
|
|
@@ -313,7 +596,7 @@ var BlockActionButton = React2.memo(function BlockActionButton2({
|
|
|
313
596
|
engine.commands.tryExecute(c.command, payload);
|
|
314
597
|
},
|
|
315
598
|
children: [
|
|
316
|
-
/* @__PURE__ */
|
|
599
|
+
/* @__PURE__ */ jsxDEV10(CoraxIcon, {
|
|
317
600
|
icon: c.icon
|
|
318
601
|
}, undefined, false, undefined, this),
|
|
319
602
|
c.label
|
|
@@ -323,7 +606,7 @@ var BlockActionButton = React2.memo(function BlockActionButton2({
|
|
|
323
606
|
|
|
324
607
|
// src/components/slots/buttons/toolbar-button.tsx
|
|
325
608
|
import React3 from "react";
|
|
326
|
-
import { jsxDEV as
|
|
609
|
+
import { jsxDEV as jsxDEV11 } from "react/jsx-dev-runtime";
|
|
327
610
|
var ToolbarButton = React3.memo(function ToolbarButton2({
|
|
328
611
|
c,
|
|
329
612
|
ui
|
|
@@ -331,15 +614,15 @@ var ToolbarButton = React3.memo(function ToolbarButton2({
|
|
|
331
614
|
const engine = useEngine();
|
|
332
615
|
const marks = useSlice("currentMarks");
|
|
333
616
|
const isActive = !!c.getProps(ui)?.isActive || marks?.find((mark) => mark.type === c.getPayload(ui).format);
|
|
334
|
-
return /* @__PURE__ */
|
|
617
|
+
return /* @__PURE__ */ jsxDEV11(Button, {
|
|
335
618
|
onClick: () => {
|
|
336
619
|
engine.commands.tryExecute(c.command, c.getPayload(ui));
|
|
337
620
|
},
|
|
338
621
|
title: c.label,
|
|
339
622
|
size: "icon-xs",
|
|
340
623
|
className: "rounded-[8px] cursor-pointer",
|
|
341
|
-
variant: isActive ? "default" : "
|
|
342
|
-
children: /* @__PURE__ */
|
|
624
|
+
variant: isActive ? "default" : "secondary",
|
|
625
|
+
children: /* @__PURE__ */ jsxDEV11(CoraxIcon, {
|
|
343
626
|
icon: c.icon
|
|
344
627
|
}, undefined, false, undefined, this)
|
|
345
628
|
}, c.id, false, undefined, this);
|
|
@@ -349,65 +632,344 @@ var ToolbarButton = React3.memo(function ToolbarButton2({
|
|
|
349
632
|
return prevActive === nextActive;
|
|
350
633
|
});
|
|
351
634
|
|
|
352
|
-
// src/components/slots/
|
|
353
|
-
import
|
|
635
|
+
// src/components/slots/buttons/code-theme-button.tsx
|
|
636
|
+
import React4 from "react";
|
|
637
|
+
import { jsxDEV as jsxDEV12 } from "react/jsx-dev-runtime";
|
|
638
|
+
var CodeThemeButton = React4.memo(function CodeThemeButton2({
|
|
639
|
+
c,
|
|
640
|
+
ui
|
|
641
|
+
}) {
|
|
642
|
+
const engine = useEngine();
|
|
643
|
+
return /* @__PURE__ */ jsxDEV12(Button, {
|
|
644
|
+
onClick: () => engine.commands.tryExecute(c.command, c.getPayload(ui)),
|
|
645
|
+
title: c.label ?? "Toggle code theme",
|
|
646
|
+
size: "icon-xs",
|
|
647
|
+
className: "rounded-[8px] cursor-pointer",
|
|
648
|
+
variant: "secondary",
|
|
649
|
+
children: /* @__PURE__ */ jsxDEV12(CoraxIcon, {
|
|
650
|
+
icon: c.icon
|
|
651
|
+
}, undefined, false, undefined, this)
|
|
652
|
+
}, c.id, false, undefined, this);
|
|
653
|
+
});
|
|
354
654
|
|
|
355
|
-
// src/
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
const
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
655
|
+
// src/components/slots/buttons/caption-button.tsx
|
|
656
|
+
import React5 from "react";
|
|
657
|
+
import { jsxDEV as jsxDEV13 } from "react/jsx-dev-runtime";
|
|
658
|
+
var CaptionButton = React5.memo(function CaptionButton2({
|
|
659
|
+
c,
|
|
660
|
+
ui,
|
|
661
|
+
...rest
|
|
662
|
+
}) {
|
|
663
|
+
const engine = useEngine();
|
|
664
|
+
return /* @__PURE__ */ jsxDEV13(Button, {
|
|
665
|
+
...rest,
|
|
666
|
+
onClick: () => engine.commands.tryExecute(c.command, c.getPayload(ui)),
|
|
667
|
+
title: c.label ?? "Add caption",
|
|
668
|
+
size: "icon-xs",
|
|
669
|
+
className: "rounded-[8px] cursor-pointer",
|
|
670
|
+
variant: "secondary",
|
|
671
|
+
children: /* @__PURE__ */ jsxDEV13(CoraxIcon, {
|
|
672
|
+
icon: c.icon
|
|
673
|
+
}, undefined, false, undefined, this)
|
|
674
|
+
}, c.id, false, undefined, this);
|
|
675
|
+
});
|
|
368
676
|
|
|
369
|
-
// src/components/slots/
|
|
370
|
-
import
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
className: "
|
|
384
|
-
|
|
677
|
+
// src/components/slots/buttons/delete-button.tsx
|
|
678
|
+
import React6 from "react";
|
|
679
|
+
import { jsxDEV as jsxDEV14 } from "react/jsx-dev-runtime";
|
|
680
|
+
var DeleteButton = React6.memo(function DeleteButton2({
|
|
681
|
+
c,
|
|
682
|
+
ui,
|
|
683
|
+
...rest
|
|
684
|
+
}) {
|
|
685
|
+
const engine = useEngine();
|
|
686
|
+
return /* @__PURE__ */ jsxDEV14(Button, {
|
|
687
|
+
...rest,
|
|
688
|
+
onClick: () => engine.commands.tryExecute(c.command, c.getPayload(ui)),
|
|
689
|
+
title: c.label ?? "Delete",
|
|
690
|
+
size: "icon-xs",
|
|
691
|
+
className: "rounded-[8px] cursor-pointer text-destructive",
|
|
692
|
+
variant: "secondary",
|
|
693
|
+
children: /* @__PURE__ */ jsxDEV14(CoraxIcon, {
|
|
694
|
+
icon: c.icon
|
|
695
|
+
}, undefined, false, undefined, this)
|
|
696
|
+
}, c.id, false, undefined, this);
|
|
697
|
+
});
|
|
698
|
+
|
|
699
|
+
// src/components/slots/buttons/iframe-playback-button.tsx
|
|
700
|
+
import React7 from "react";
|
|
701
|
+
import { jsxDEV as jsxDEV15 } from "react/jsx-dev-runtime";
|
|
702
|
+
var IframePlaybackButton = React7.memo(function IframePlaybackButton2({
|
|
703
|
+
c,
|
|
704
|
+
ui,
|
|
705
|
+
...rest
|
|
706
|
+
}) {
|
|
707
|
+
const engine = useEngine();
|
|
708
|
+
const [isPlaying, setIsPlaying] = React7.useState(false);
|
|
709
|
+
return /* @__PURE__ */ jsxDEV15(Button, {
|
|
710
|
+
...rest,
|
|
711
|
+
onClick: () => {
|
|
712
|
+
const { fieldId } = c.getPayload(ui);
|
|
713
|
+
engine.commands.tryExecute(c.command, { fieldId, action: isPlaying ? "pause" : "play" });
|
|
714
|
+
setIsPlaying(!isPlaying);
|
|
715
|
+
},
|
|
716
|
+
title: c.label ?? "Play/Pause",
|
|
717
|
+
size: "icon-xs",
|
|
718
|
+
className: "rounded-[8px] cursor-pointer",
|
|
719
|
+
variant: "secondary",
|
|
720
|
+
children: /* @__PURE__ */ jsxDEV15(CoraxIcon, {
|
|
721
|
+
icon: isPlaying ? "PauseIcon" : "PlayIcon"
|
|
722
|
+
}, undefined, false, undefined, this)
|
|
723
|
+
}, c.id, false, undefined, this);
|
|
724
|
+
});
|
|
725
|
+
|
|
726
|
+
// src/hooks/use-block.ts
|
|
727
|
+
import { useSyncExternalStore as useSyncExternalStore2 } from "react";
|
|
728
|
+
function useBlock(id) {
|
|
729
|
+
const engine = useEngine();
|
|
730
|
+
return useSyncExternalStore2((fn) => engine.document.subscribeBlock(id, fn), () => engine.document.getBlock(id), () => engine.document.getBlock(id));
|
|
385
731
|
}
|
|
386
732
|
|
|
387
|
-
// src/components/slots/
|
|
388
|
-
import
|
|
389
|
-
|
|
390
|
-
|
|
733
|
+
// src/components/slots/buttons/image-width-button.tsx
|
|
734
|
+
import React8 from "react";
|
|
735
|
+
import { jsxDEV as jsxDEV16 } from "react/jsx-dev-runtime";
|
|
736
|
+
var ImageWidthButton = React8.memo(function ImageWidthButton2({
|
|
737
|
+
c,
|
|
738
|
+
ui,
|
|
739
|
+
...rest
|
|
740
|
+
}) {
|
|
741
|
+
const engine = useEngine();
|
|
742
|
+
const { fieldId, width } = c.getPayload(ui);
|
|
743
|
+
const block = useBlock(fieldId);
|
|
744
|
+
return /* @__PURE__ */ jsxDEV16(Button, {
|
|
745
|
+
...rest,
|
|
746
|
+
onClick: () => engine.commands.tryExecute(c.command, c.getPayload(ui)),
|
|
747
|
+
title: c.label ?? "Image width",
|
|
748
|
+
size: "icon-xs",
|
|
749
|
+
className: "rounded-[8px] cursor-pointer",
|
|
750
|
+
variant: block?.props.style?.width === width ? "default" : "secondary",
|
|
751
|
+
children: /* @__PURE__ */ jsxDEV16(CoraxIcon, {
|
|
752
|
+
icon: c.icon
|
|
753
|
+
}, undefined, false, undefined, this)
|
|
754
|
+
}, c.id, false, undefined, this);
|
|
755
|
+
});
|
|
756
|
+
|
|
757
|
+
// src/components/slots/buttons/divider-width-button.tsx
|
|
758
|
+
import React9 from "react";
|
|
759
|
+
import { jsxDEV as jsxDEV17 } from "react/jsx-dev-runtime";
|
|
760
|
+
var DividerWidthButton = React9.memo(function DividerWidthButton2({
|
|
761
|
+
c,
|
|
762
|
+
ui,
|
|
763
|
+
...rest
|
|
764
|
+
}) {
|
|
765
|
+
const engine = useEngine();
|
|
766
|
+
const { fieldId, width } = c.getPayload(ui);
|
|
767
|
+
const block = useBlock(fieldId);
|
|
768
|
+
return /* @__PURE__ */ jsxDEV17(Button, {
|
|
769
|
+
...rest,
|
|
770
|
+
onMouseDown: (ev) => ev.preventDefault(),
|
|
771
|
+
onClick: () => engine.commands.tryExecute(c.command, c.getPayload(ui)),
|
|
772
|
+
title: c.label ?? "Divider width",
|
|
773
|
+
size: "icon-xs",
|
|
774
|
+
className: "rounded-[8px] cursor-pointer",
|
|
775
|
+
variant: block?.props.style?.width === width ? "default" : "secondary",
|
|
776
|
+
children: /* @__PURE__ */ jsxDEV17(CoraxIcon, {
|
|
777
|
+
icon: c.icon
|
|
778
|
+
}, undefined, false, undefined, this)
|
|
779
|
+
}, c.id, false, undefined, this);
|
|
780
|
+
});
|
|
781
|
+
|
|
782
|
+
// src/components/slots/buttons/divider-style-button.tsx
|
|
783
|
+
import React10 from "react";
|
|
784
|
+
import { jsxDEV as jsxDEV18 } from "react/jsx-dev-runtime";
|
|
785
|
+
var DividerStyleButton = React10.memo(function DividerStyleButton2({
|
|
786
|
+
c,
|
|
787
|
+
ui,
|
|
788
|
+
...rest
|
|
789
|
+
}) {
|
|
790
|
+
const engine = useEngine();
|
|
791
|
+
const { fieldId } = c.getPayload(ui);
|
|
792
|
+
const block = useBlock(fieldId);
|
|
793
|
+
const targetStyle = c.getProps(ui)?.borderStyle ?? "solid";
|
|
794
|
+
const isActive = (block?.props.style?.borderTopStyle ?? "solid") === targetStyle;
|
|
795
|
+
return /* @__PURE__ */ jsxDEV18(Button, {
|
|
796
|
+
...rest,
|
|
797
|
+
onMouseDown: (ev) => ev.preventDefault(),
|
|
798
|
+
onClick: () => engine.commands.tryExecute(c.command, c.getPayload(ui)),
|
|
799
|
+
title: c.label ?? "Divider style",
|
|
800
|
+
size: "icon-xs",
|
|
801
|
+
className: "rounded-[8px] cursor-pointer",
|
|
802
|
+
variant: isActive ? "default" : "secondary",
|
|
803
|
+
children: /* @__PURE__ */ jsxDEV18("span", {
|
|
804
|
+
"aria-hidden": true,
|
|
805
|
+
style: {
|
|
806
|
+
display: "block",
|
|
807
|
+
width: 14,
|
|
808
|
+
borderTopWidth: 2,
|
|
809
|
+
borderTopStyle: targetStyle,
|
|
810
|
+
borderTopColor: "currentColor"
|
|
811
|
+
}
|
|
812
|
+
}, undefined, false, undefined, this)
|
|
813
|
+
}, c.id, false, undefined, this);
|
|
814
|
+
});
|
|
815
|
+
|
|
816
|
+
// src/components/slots/overlays/focus-overlay.tsx
|
|
817
|
+
import { useEffect as useEffect7 } from "react";
|
|
818
|
+
|
|
819
|
+
// src/lib/func.utils.ts
|
|
820
|
+
function focusDomBLockById(engine, id) {
|
|
821
|
+
const disposer = engine.events.on("re-render", () => {
|
|
822
|
+
focusDomElement(id);
|
|
823
|
+
disposer();
|
|
824
|
+
});
|
|
825
|
+
}
|
|
826
|
+
function focusDomElement(id) {
|
|
827
|
+
const domElement = document.getElementById(id);
|
|
828
|
+
if (!domElement)
|
|
829
|
+
return;
|
|
830
|
+
domElement.focus();
|
|
831
|
+
}
|
|
832
|
+
|
|
833
|
+
// src/components/slots/overlays/focus-overlay.tsx
|
|
834
|
+
import { jsxDEV as jsxDEV19 } from "react/jsx-dev-runtime";
|
|
835
|
+
function FocusOverlay({
|
|
836
|
+
c,
|
|
837
|
+
ui
|
|
838
|
+
}) {
|
|
839
|
+
const { position = null, hidden = null } = c.getProps(ui) ?? {};
|
|
840
|
+
const focusedId = ui.focus?.id;
|
|
841
|
+
useEffect7(() => {
|
|
842
|
+
if (!focusedId)
|
|
843
|
+
return;
|
|
844
|
+
focusDomElement(focusedId);
|
|
845
|
+
}, [focusedId]);
|
|
391
846
|
if (hidden || !position)
|
|
392
847
|
return null;
|
|
393
|
-
return /* @__PURE__ */
|
|
848
|
+
return /* @__PURE__ */ jsxDEV19("div", {
|
|
849
|
+
style: position,
|
|
850
|
+
className: "absolute border border-blue-700 pointer-events-none flex justify-end"
|
|
851
|
+
}, undefined, false, undefined, this);
|
|
852
|
+
}
|
|
853
|
+
|
|
854
|
+
// src/components/slots/overlays/hover-overlay.tsx
|
|
855
|
+
import { jsxDEV as jsxDEV20 } from "react/jsx-dev-runtime";
|
|
856
|
+
function HoverOverlay({
|
|
857
|
+
c,
|
|
858
|
+
ui
|
|
859
|
+
}) {
|
|
860
|
+
const { position = null, hidden = null } = c.getProps(ui) ?? {};
|
|
861
|
+
if (hidden || !position)
|
|
862
|
+
return null;
|
|
863
|
+
return /* @__PURE__ */ jsxDEV20("div", {
|
|
394
864
|
style: position,
|
|
395
865
|
className: "absolute border-[0.5px] border-blue-400 pointer-events-none flex justify-end"
|
|
396
866
|
}, undefined, false, undefined, this);
|
|
397
867
|
}
|
|
398
868
|
|
|
399
869
|
// src/components/slots/overlays/selection-overlay.tsx
|
|
400
|
-
import { jsxDEV as
|
|
401
|
-
function SelectionOverlay({
|
|
402
|
-
|
|
870
|
+
import { jsxDEV as jsxDEV21 } from "react/jsx-dev-runtime";
|
|
871
|
+
function SelectionOverlay({
|
|
872
|
+
c,
|
|
873
|
+
ui
|
|
874
|
+
}) {
|
|
875
|
+
const { position = null, hidden = null } = c.getProps(ui) ?? {};
|
|
403
876
|
if (hidden || !position)
|
|
404
877
|
return null;
|
|
405
|
-
return /* @__PURE__ */
|
|
878
|
+
return /* @__PURE__ */ jsxDEV21("div", {
|
|
406
879
|
style: position,
|
|
407
880
|
className: "absolute border border-blue-500 pointer-events-none flex justify-end"
|
|
408
881
|
}, undefined, false, undefined, this);
|
|
409
882
|
}
|
|
410
883
|
|
|
884
|
+
// src/modules/slots.module.tsx
|
|
885
|
+
import { TextCursor, PointerIcon, HeadingIcon, Heading2, PlusIcon, BoldIcon, ItalicIcon, UnderlineIcon, LinkIcon, ImagePlus, TextInitialIcon, Minus, TvMinimalPlayIcon, FileTextIcon, QuoteIcon, BracesIcon, PaletteIcon, Captions, Trash2 as Trash25, Play, Pause, MoveHorizontal, Expand, LineStyle, OctagonExclamationPoint, OctagonX, InfoIcon, CircleLetterI } from "lucide-react";
|
|
886
|
+
|
|
887
|
+
// src/components/commons/youtube.tsx
|
|
888
|
+
import { cn as cn11 } from "cn";
|
|
889
|
+
import { jsxDEV as jsxDEV22 } from "react/jsx-dev-runtime";
|
|
890
|
+
function YoutubeIcon({ className, ...props }) {
|
|
891
|
+
return /* @__PURE__ */ jsxDEV22("svg", {
|
|
892
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
893
|
+
viewBox: "0 0 24 24",
|
|
894
|
+
fill: "none",
|
|
895
|
+
className: cn11("text-foreground", className),
|
|
896
|
+
...props,
|
|
897
|
+
children: /* @__PURE__ */ jsxDEV22("path", {
|
|
898
|
+
fillRule: "evenodd",
|
|
899
|
+
clipRule: "evenodd",
|
|
900
|
+
d: "M20.5949 4.45999C21.5421 4.71353 22.2865 5.45785 22.54 6.40501C22.9982 8.12001 23 11.7004 23 11.7004C23 11.7004 23 15.2807 22.54 16.9957C22.2865 17.9429 21.5421 18.6872 20.5949 18.9407C18.88 19.4007 12 19.4007 12 19.4007C12 19.4007 5.12001 19.4007 3.405 18.9407C2.45785 18.6872 1.71353 17.9429 1.45999 16.9957C1 15.2807 1 11.7004 1 11.7004C1 11.7004 1 8.12001 1.45999 6.40501C1.71353 5.45785 2.45785 4.71353 3.405 4.45999C5.12001 4 12 4 12 4C12 4 18.88 4 20.5949 4.45999ZM15.5134 11.7007L9.79788 15.0003V8.40101L15.5134 11.7007Z",
|
|
901
|
+
stroke: "currentColor",
|
|
902
|
+
strokeLinejoin: "round",
|
|
903
|
+
strokeWidth: 2
|
|
904
|
+
}, undefined, false, undefined, this)
|
|
905
|
+
}, undefined, false, undefined, this);
|
|
906
|
+
}
|
|
907
|
+
// src/lib/selection.utils.ts
|
|
908
|
+
function rangeToOffsets(root, range) {
|
|
909
|
+
const measure = (node, offset) => {
|
|
910
|
+
const r = document.createRange();
|
|
911
|
+
r.selectNodeContents(root);
|
|
912
|
+
r.setEnd(node, offset);
|
|
913
|
+
return r.toString().length;
|
|
914
|
+
};
|
|
915
|
+
return {
|
|
916
|
+
start: measure(range.startContainer, range.startOffset),
|
|
917
|
+
end: measure(range.endContainer, range.endOffset)
|
|
918
|
+
};
|
|
919
|
+
}
|
|
920
|
+
function offsetsToRange(root, start, end) {
|
|
921
|
+
const range = document.createRange();
|
|
922
|
+
const walker = document.createTreeWalker(root, NodeFilter.SHOW_TEXT);
|
|
923
|
+
let pos = 0, startSet = false;
|
|
924
|
+
for (let n = walker.nextNode();n; n = walker.nextNode()) {
|
|
925
|
+
const next = pos + n.length;
|
|
926
|
+
if (!startSet && start <= next) {
|
|
927
|
+
range.setStart(n, start - pos);
|
|
928
|
+
startSet = true;
|
|
929
|
+
}
|
|
930
|
+
if (startSet && end <= next) {
|
|
931
|
+
range.setEnd(n, end - pos);
|
|
932
|
+
return range;
|
|
933
|
+
}
|
|
934
|
+
pos = next;
|
|
935
|
+
}
|
|
936
|
+
return null;
|
|
937
|
+
}
|
|
938
|
+
// src/components/slots/buttons/paragraph-theme-button.tsx
|
|
939
|
+
import {
|
|
940
|
+
getParagraphTheme
|
|
941
|
+
} from "@coorax/core";
|
|
942
|
+
import React11 from "react";
|
|
943
|
+
import { cn as cn12 } from "cn";
|
|
944
|
+
import { jsxDEV as jsxDEV23 } from "react/jsx-dev-runtime";
|
|
945
|
+
var ParagraphThemeButton = React11.memo(function ParagraphThemeButton2({
|
|
946
|
+
c,
|
|
947
|
+
ui,
|
|
948
|
+
...rest
|
|
949
|
+
}) {
|
|
950
|
+
const engine = useEngine();
|
|
951
|
+
const { fieldId, theme } = c.getPayload(ui);
|
|
952
|
+
const block = useBlock(fieldId);
|
|
953
|
+
const isActive = !!block && getParagraphTheme(block.props.children) === theme;
|
|
954
|
+
const props = c.getProps(ui);
|
|
955
|
+
return /* @__PURE__ */ jsxDEV23(Button, {
|
|
956
|
+
...rest,
|
|
957
|
+
onMouseDown: (ev) => ev.preventDefault(),
|
|
958
|
+
onClick: () => engine.commands.tryExecute(c.command, c.getPayload(ui)),
|
|
959
|
+
title: c.label ?? "Paragraph theme",
|
|
960
|
+
size: "icon-xs",
|
|
961
|
+
className: cn12("rounded-[8px] cursor-pointer", {
|
|
962
|
+
"bg-[#FF4D4F]/30": props.theme === "error" && !isActive,
|
|
963
|
+
"bg-[#FF9900]/30": props.theme === "warning" && !isActive,
|
|
964
|
+
"bg-[#007AFF]/30": props.theme === "info" && !isActive
|
|
965
|
+
}),
|
|
966
|
+
variant: isActive ? "default" : "secondary",
|
|
967
|
+
children: /* @__PURE__ */ jsxDEV23(CoraxIcon, {
|
|
968
|
+
icon: c.icon
|
|
969
|
+
}, undefined, false, undefined, this)
|
|
970
|
+
}, c.id, false, undefined, this);
|
|
971
|
+
});
|
|
972
|
+
|
|
411
973
|
// src/modules/slots.module.tsx
|
|
412
974
|
var SlotsModule = {
|
|
413
975
|
name: "slots",
|
|
@@ -416,9 +978,46 @@ var SlotsModule = {
|
|
|
416
978
|
install() {
|
|
417
979
|
SlotsComponentRegistry.register("BlockActionButton", BlockActionButton);
|
|
418
980
|
SlotsComponentRegistry.register("ToolBarButton", ToolbarButton);
|
|
981
|
+
SlotsComponentRegistry.register("CodeThemeButton", CodeThemeButton);
|
|
982
|
+
SlotsComponentRegistry.register("CaptionButton", CaptionButton);
|
|
983
|
+
SlotsComponentRegistry.register("DeleteButton", DeleteButton);
|
|
984
|
+
SlotsComponentRegistry.register("IframePlaybackButton", IframePlaybackButton);
|
|
985
|
+
SlotsComponentRegistry.register("ImageWidthButton", ImageWidthButton);
|
|
986
|
+
SlotsComponentRegistry.register("DividerWidthButton", DividerWidthButton);
|
|
987
|
+
SlotsComponentRegistry.register("DividerStyleButton", DividerStyleButton);
|
|
988
|
+
SlotsComponentRegistry.register("ParagraphThemeButton", ParagraphThemeButton);
|
|
419
989
|
SlotsComponentRegistry.register("SelectionOverlay", SelectionOverlay);
|
|
420
990
|
SlotsComponentRegistry.register("FocusOverlay", FocusOverlay);
|
|
421
991
|
SlotsComponentRegistry.register("HoverOverlay", HoverOverlay);
|
|
992
|
+
CoraxIconsRegistry.register("TextIcon", TextCursor);
|
|
993
|
+
CoraxIconsRegistry.register("CursorIcon", PointerIcon);
|
|
994
|
+
CoraxIconsRegistry.register("HeadingIcon", HeadingIcon);
|
|
995
|
+
CoraxIconsRegistry.register("Heading2Icon", Heading2);
|
|
996
|
+
CoraxIconsRegistry.register("PlusIcon", PlusIcon);
|
|
997
|
+
CoraxIconsRegistry.register("BoldIcon", BoldIcon);
|
|
998
|
+
CoraxIconsRegistry.register("ItalicIcon", ItalicIcon);
|
|
999
|
+
CoraxIconsRegistry.register("UnderlineIcon", UnderlineIcon);
|
|
1000
|
+
CoraxIconsRegistry.register("LinkIcon", LinkIcon);
|
|
1001
|
+
CoraxIconsRegistry.register("ImagePlus", ImagePlus);
|
|
1002
|
+
CoraxIconsRegistry.register("TextInitial", TextInitialIcon);
|
|
1003
|
+
CoraxIconsRegistry.register("DividerIcon", Minus);
|
|
1004
|
+
CoraxIconsRegistry.register("TvMinimalPlayIcon", TvMinimalPlayIcon);
|
|
1005
|
+
CoraxIconsRegistry.register("YoutubeIcon", YoutubeIcon);
|
|
1006
|
+
CoraxIconsRegistry.register("FileTextIcon", FileTextIcon);
|
|
1007
|
+
CoraxIconsRegistry.register("QuoteIcon", QuoteIcon);
|
|
1008
|
+
CoraxIconsRegistry.register("CodeIcon", BracesIcon);
|
|
1009
|
+
CoraxIconsRegistry.register("PaletteIcon", PaletteIcon);
|
|
1010
|
+
CoraxIconsRegistry.register("CaptionsIcon", Captions);
|
|
1011
|
+
CoraxIconsRegistry.register("TrashIcon", Trash25);
|
|
1012
|
+
CoraxIconsRegistry.register("PlayIcon", Play);
|
|
1013
|
+
CoraxIconsRegistry.register("PauseIcon", Pause);
|
|
1014
|
+
CoraxIconsRegistry.register("MoveHorizontalIcon", MoveHorizontal);
|
|
1015
|
+
CoraxIconsRegistry.register("ExpandIcon", Expand);
|
|
1016
|
+
CoraxIconsRegistry.register("LineStyleIcon", LineStyle);
|
|
1017
|
+
CoraxIconsRegistry.register("ThemeWarningIcon", OctagonExclamationPoint);
|
|
1018
|
+
CoraxIconsRegistry.register("ThemeErrorIcon", OctagonX);
|
|
1019
|
+
CoraxIconsRegistry.register("ThemeInfoIcon", InfoIcon);
|
|
1020
|
+
CoraxIconsRegistry.register("ThemeNeutralIcon", CircleLetterI);
|
|
422
1021
|
}
|
|
423
1022
|
};
|
|
424
1023
|
// src/modules/autosave.module.ts
|
|
@@ -446,7 +1045,8 @@ class Lexer {
|
|
|
446
1045
|
"INTO",
|
|
447
1046
|
"VALUES",
|
|
448
1047
|
"CREATE",
|
|
449
|
-
"TABLE"
|
|
1048
|
+
"TABLE",
|
|
1049
|
+
"DELETE"
|
|
450
1050
|
];
|
|
451
1051
|
cleanWord() {
|
|
452
1052
|
this.word = [];
|
|
@@ -593,7 +1193,7 @@ var TYPES_DEFS_MAPPING = {
|
|
|
593
1193
|
|
|
594
1194
|
// src/services/localdb/parser/parser.ts
|
|
595
1195
|
class Parser {
|
|
596
|
-
statementTypes = ["SELECT", "INSERT", "CREATE"];
|
|
1196
|
+
statementTypes = ["SELECT", "INSERT", "CREATE", "DELETE"];
|
|
597
1197
|
foundTable(tokens) {
|
|
598
1198
|
return tokens.find((token, idx) => {
|
|
599
1199
|
return token.type === "IDENTIFIER" && ["FROM", "INTO", "TABLE"].includes(tokens[idx - 1]?.type);
|
|
@@ -858,8 +1458,72 @@ class Parser {
|
|
|
858
1458
|
}
|
|
859
1459
|
return statements;
|
|
860
1460
|
}
|
|
1461
|
+
parseDelete(tokens) {
|
|
1462
|
+
const fromIndex = tokens.findIndex((t) => t.type === "FROM");
|
|
1463
|
+
if (fromIndex === -1) {
|
|
1464
|
+
throw new Error("Invalid DELETE statement: missing FROM clause");
|
|
1465
|
+
}
|
|
1466
|
+
if (tokens[2].type !== "IDENTIFIER") {
|
|
1467
|
+
throw new Error(`Invalid IDENTIFIER at: ${tokens[0].value}`);
|
|
1468
|
+
}
|
|
1469
|
+
const table = tokens[2].value;
|
|
1470
|
+
if (tokens[3].type === "SEMICOLON") {
|
|
1471
|
+
return {
|
|
1472
|
+
table,
|
|
1473
|
+
type: "DELETE",
|
|
1474
|
+
where: []
|
|
1475
|
+
};
|
|
1476
|
+
}
|
|
1477
|
+
let cursor = fromIndex + 2;
|
|
1478
|
+
let mainAlias;
|
|
1479
|
+
if (cursor < tokens.length) {
|
|
1480
|
+
if (tokens[cursor]?.type === "AS" && tokens[cursor + 1]?.type === "IDENTIFIER") {
|
|
1481
|
+
mainAlias = tokens[cursor + 1].value;
|
|
1482
|
+
cursor += 2;
|
|
1483
|
+
} else if (tokens[cursor]?.type === "IDENTIFIER" && !["JOIN", "INNER", "LEFT", "RIGHT", "FULL", "CROSS", "WHERE", "SEMICOLON"].includes(tokens[cursor].type)) {
|
|
1484
|
+
mainAlias = tokens[cursor].value;
|
|
1485
|
+
cursor++;
|
|
1486
|
+
}
|
|
1487
|
+
}
|
|
1488
|
+
const where = [];
|
|
1489
|
+
if (tokens[cursor]?.type === "WHERE") {
|
|
1490
|
+
cursor++;
|
|
1491
|
+
while (cursor < tokens.length) {
|
|
1492
|
+
const colToken = tokens[cursor];
|
|
1493
|
+
if (!colToken || colToken.type === "SEMICOLON")
|
|
1494
|
+
break;
|
|
1495
|
+
cursor++;
|
|
1496
|
+
const opToken = tokens[cursor];
|
|
1497
|
+
cursor++;
|
|
1498
|
+
const valToken = tokens[cursor];
|
|
1499
|
+
cursor++;
|
|
1500
|
+
if (colToken && opToken && valToken) {
|
|
1501
|
+
const colParts = colToken.value.split(".");
|
|
1502
|
+
const table2 = colParts.length > 1 ? colParts[0] : undefined;
|
|
1503
|
+
const column = colParts.length > 1 ? colParts[1] : colParts[0];
|
|
1504
|
+
where.push({
|
|
1505
|
+
table: table2,
|
|
1506
|
+
column,
|
|
1507
|
+
operator: opToken.value || "=",
|
|
1508
|
+
value: valToken.value
|
|
1509
|
+
});
|
|
1510
|
+
}
|
|
1511
|
+
if (tokens[cursor]?.type === "AND" || tokens[cursor]?.type === "OR") {
|
|
1512
|
+
cursor++;
|
|
1513
|
+
} else {
|
|
1514
|
+
break;
|
|
1515
|
+
}
|
|
1516
|
+
}
|
|
1517
|
+
}
|
|
1518
|
+
return {
|
|
1519
|
+
table,
|
|
1520
|
+
type: "DELETE",
|
|
1521
|
+
alias: mainAlias,
|
|
1522
|
+
where
|
|
1523
|
+
};
|
|
1524
|
+
}
|
|
861
1525
|
parse(tokens, params) {
|
|
862
|
-
if (tokens.length <
|
|
1526
|
+
if (tokens.length < 3) {
|
|
863
1527
|
throw new Error(`Invalid tokens array with missing elements!`);
|
|
864
1528
|
}
|
|
865
1529
|
const firstStatement = tokens[0];
|
|
@@ -873,6 +1537,9 @@ class Parser {
|
|
|
873
1537
|
if (firstStatement.type === "SELECT") {
|
|
874
1538
|
return [this.parseSelect(tokens)];
|
|
875
1539
|
}
|
|
1540
|
+
if (firstStatement.type === "DELETE") {
|
|
1541
|
+
return [this.parseDelete(tokens)];
|
|
1542
|
+
}
|
|
876
1543
|
if (firstStatement.type === "INSERT") {
|
|
877
1544
|
const stmtChunks = [];
|
|
878
1545
|
let currentChunk = [];
|
|
@@ -1330,6 +1997,34 @@ class LocalDB {
|
|
|
1330
1997
|
await this.insertData(objectStore, newData);
|
|
1331
1998
|
break;
|
|
1332
1999
|
}
|
|
2000
|
+
case "DELETE": {
|
|
2001
|
+
const deleteReq = requests[0];
|
|
2002
|
+
const [_, primaryStore] = this.openTx(deleteReq.table, (err) => {
|
|
2003
|
+
this.isError = err;
|
|
2004
|
+
}, "readwrite");
|
|
2005
|
+
let mainRows = await this.retrieveData(primaryStore, ["*"]);
|
|
2006
|
+
if (deleteReq.where && deleteReq.where.length > 0) {
|
|
2007
|
+
mainRows = mainRows.filter((row) => {
|
|
2008
|
+
return deleteReq.where.every((cond) => {
|
|
2009
|
+
if (cond.table && cond.table !== deleteReq.table && cond.table !== deleteReq.alias) {
|
|
2010
|
+
return true;
|
|
2011
|
+
}
|
|
2012
|
+
const val = row[cond.column];
|
|
2013
|
+
if (cond.operator === "=") {
|
|
2014
|
+
return String(val) === String(cond.value);
|
|
2015
|
+
}
|
|
2016
|
+
if (cond.operator === "!=") {
|
|
2017
|
+
return String(val) !== String(cond.value);
|
|
2018
|
+
}
|
|
2019
|
+
return true;
|
|
2020
|
+
});
|
|
2021
|
+
});
|
|
2022
|
+
}
|
|
2023
|
+
for (const row of mainRows) {
|
|
2024
|
+
await this.deleteData(primaryStore, deleteReq.table, row.id);
|
|
2025
|
+
}
|
|
2026
|
+
break;
|
|
2027
|
+
}
|
|
1333
2028
|
default:
|
|
1334
2029
|
break;
|
|
1335
2030
|
}
|
|
@@ -1339,6 +2034,22 @@ class LocalDB {
|
|
|
1339
2034
|
}
|
|
1340
2035
|
return lastResult;
|
|
1341
2036
|
}
|
|
2037
|
+
async deleteData(objectStore, table, id) {
|
|
2038
|
+
return new Promise((resolve) => {
|
|
2039
|
+
try {
|
|
2040
|
+
const request = objectStore.delete(id);
|
|
2041
|
+
request.onsuccess = () => {
|
|
2042
|
+
resolve(null);
|
|
2043
|
+
};
|
|
2044
|
+
request.onerror = (event) => {
|
|
2045
|
+
const error = event.target.error || new Error(`Erreur lors de la suppression de l'élément avec l'id ${id} dans la table ${table}`);
|
|
2046
|
+
resolve(error);
|
|
2047
|
+
};
|
|
2048
|
+
} catch (error) {
|
|
2049
|
+
resolve(error instanceof Error ? error : new Error(String(error)));
|
|
2050
|
+
}
|
|
2051
|
+
});
|
|
2052
|
+
}
|
|
1342
2053
|
async QueryDB(query, params) {
|
|
1343
2054
|
if (!this.db)
|
|
1344
2055
|
await this.init();
|
|
@@ -1388,9 +2099,12 @@ class LocalDB {
|
|
|
1388
2099
|
}
|
|
1389
2100
|
}
|
|
1390
2101
|
|
|
2102
|
+
// src/services/index.ts
|
|
2103
|
+
var CORAX_INDEXED_DB = "coraxdb";
|
|
2104
|
+
|
|
1391
2105
|
// src/modules/autosave.module.ts
|
|
1392
|
-
async function loadCompleteDocument(
|
|
1393
|
-
const result = await
|
|
2106
|
+
async function loadCompleteDocument(db2, documentId) {
|
|
2107
|
+
const result = await db2.QueryDB(`
|
|
1394
2108
|
SELECT * FROM documents
|
|
1395
2109
|
JOIN fields ON documents.id = fields.document_id
|
|
1396
2110
|
JOIN containers ON documents.id = containers.document_id
|
|
@@ -1416,13 +2130,13 @@ var AutoSaveModule = {
|
|
|
1416
2130
|
console.error("[WARN] indexedDB not supported or SSR");
|
|
1417
2131
|
return;
|
|
1418
2132
|
}
|
|
1419
|
-
const
|
|
1420
|
-
|
|
2133
|
+
const db2 = new LocalDB(CORAX_INDEXED_DB);
|
|
2134
|
+
db2.DeleteDB().then((err) => {
|
|
1421
2135
|
if (err) {
|
|
1422
2136
|
console.error(err);
|
|
1423
2137
|
return;
|
|
1424
2138
|
}
|
|
1425
|
-
|
|
2139
|
+
db2.MigrateDB(`
|
|
1426
2140
|
CREATE TABLE documents (
|
|
1427
2141
|
id TEXT,
|
|
1428
2142
|
version TEXT,
|
|
@@ -1483,6 +2197,9 @@ var AutoSaveModule = {
|
|
|
1483
2197
|
}).catch((e) => {
|
|
1484
2198
|
console.error(e);
|
|
1485
2199
|
});
|
|
2200
|
+
ctx.commands.register("db.query", ({ query }) => {
|
|
2201
|
+
db2.QueryDB(query);
|
|
2202
|
+
});
|
|
1486
2203
|
ctx.commands.before("blocks.insert", (p) => {
|
|
1487
2204
|
const dbState = ctx.state.get("localdbState");
|
|
1488
2205
|
if (!dbState || !dbState.isDBReady)
|
|
@@ -1497,9 +2214,9 @@ var AutoSaveModule = {
|
|
|
1497
2214
|
const saveDocument = async () => {
|
|
1498
2215
|
const documentId = jsonDocument.id;
|
|
1499
2216
|
const now = Date.now();
|
|
1500
|
-
await
|
|
2217
|
+
await db2.QueryDB(`INSERT INTO documents (id, version, order, created_at) VALUES (?, ?, ?, ?);`, [documentId, jsonDocument.version, Array.from(jsonDocument.order ?? []), now]);
|
|
1501
2218
|
for (const [fieldId, field] of Object.entries(jsonDocument.fields ?? {})) {
|
|
1502
|
-
await
|
|
2219
|
+
await db2.QueryDB(`INSERT INTO fields (id, document_id, name, tag, type, variant, containerId, props) VALUES (?, ?, ?, ?, ?, ?, ?, ?);`, [
|
|
1503
2220
|
field.id || fieldId,
|
|
1504
2221
|
documentId,
|
|
1505
2222
|
field.name ?? "",
|
|
@@ -1512,7 +2229,7 @@ var AutoSaveModule = {
|
|
|
1512
2229
|
const fieldProps = field.props ?? {};
|
|
1513
2230
|
if (fieldProps.file && (fieldProps.file instanceof Blob || typeof File !== "undefined" && fieldProps.file instanceof File)) {
|
|
1514
2231
|
const file = fieldProps.file;
|
|
1515
|
-
await
|
|
2232
|
+
await db2.QueryDB(`INSERT INTO medias (id, document_id, name, type, size, data, created_at) VALUES (?, ?, ?, ?, ?, ?, ?);`, [
|
|
1516
2233
|
`media:${field.id || fieldId}`,
|
|
1517
2234
|
documentId,
|
|
1518
2235
|
file.name ?? "unnamed",
|
|
@@ -1524,7 +2241,7 @@ var AutoSaveModule = {
|
|
|
1524
2241
|
}
|
|
1525
2242
|
}
|
|
1526
2243
|
for (const [containerId, container] of Object.entries(jsonDocument.containers ?? {})) {
|
|
1527
|
-
await
|
|
2244
|
+
await db2.QueryDB(`INSERT INTO containers (id, document_id, name, tag, type, variant, order, props) VALUES (?, ?, ?, ?, ?, ?, ?, ?);`, [
|
|
1528
2245
|
container.id || containerId,
|
|
1529
2246
|
documentId,
|
|
1530
2247
|
container.name ?? "",
|
|
@@ -1536,7 +2253,7 @@ var AutoSaveModule = {
|
|
|
1536
2253
|
]);
|
|
1537
2254
|
}
|
|
1538
2255
|
for (const [componentId, component] of Object.entries(jsonDocument.components ?? {})) {
|
|
1539
|
-
await
|
|
2256
|
+
await db2.QueryDB(`INSERT INTO components (id, document_id, name, tag, type, variant, order, count, updatedAt, createdAt, props) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);`, [
|
|
1540
2257
|
component.id || componentId,
|
|
1541
2258
|
documentId,
|
|
1542
2259
|
component.name ?? "",
|
|
@@ -1556,36 +2273,31 @@ var AutoSaveModule = {
|
|
|
1556
2273
|
}
|
|
1557
2274
|
};
|
|
1558
2275
|
// src/components/slots/maps/block-actions.tsx
|
|
1559
|
-
import { useEffect as
|
|
2276
|
+
import { useEffect as useEffect12, useMemo as useMemo3, useRef as useRef3 } from "react";
|
|
1560
2277
|
|
|
1561
2278
|
// src/hooks/use-slots.ts
|
|
1562
|
-
import { useSyncExternalStore as
|
|
2279
|
+
import { useSyncExternalStore as useSyncExternalStore3 } from "react";
|
|
1563
2280
|
function useSlots(slotName) {
|
|
1564
2281
|
const engine = useEngine();
|
|
1565
|
-
const items =
|
|
2282
|
+
const items = useSyncExternalStore3((fn) => engine.ui.subscribe(slotName, fn), () => engine.ui.getSlots(slotName), () => engine.ui.getSlots(slotName));
|
|
1566
2283
|
return items;
|
|
1567
2284
|
}
|
|
1568
2285
|
|
|
1569
2286
|
// src/hooks/use-registry.ts
|
|
1570
|
-
import { useSyncExternalStore as
|
|
1571
|
-
|
|
1572
|
-
// src/registry/ui.primitives.registry.tsx
|
|
1573
|
-
var UIPrimitivesRegistry = new GenericRegistry;
|
|
1574
|
-
|
|
1575
|
-
// src/hooks/use-registry.ts
|
|
2287
|
+
import { useSyncExternalStore as useSyncExternalStore4 } from "react";
|
|
1576
2288
|
function useRegistryComponent(name) {
|
|
1577
|
-
return
|
|
2289
|
+
return useSyncExternalStore4((fn) => SlotsComponentRegistry.subscribe(name, fn), () => SlotsComponentRegistry.get(name), () => SlotsComponentRegistry.get(name));
|
|
1578
2290
|
}
|
|
1579
2291
|
|
|
1580
2292
|
// src/components/slots/slot-button.tsx
|
|
1581
|
-
import
|
|
2293
|
+
import React12 from "react";
|
|
1582
2294
|
function SlotButton({ c, ui }) {
|
|
1583
2295
|
const Comp = useRegistryComponent(c.name);
|
|
1584
2296
|
if (!Comp) {
|
|
1585
2297
|
console.warn(`No component registered for slot key "${c.name}"`);
|
|
1586
2298
|
return null;
|
|
1587
2299
|
}
|
|
1588
|
-
return
|
|
2300
|
+
return React12.createElement(Comp, {
|
|
1589
2301
|
c,
|
|
1590
2302
|
ui,
|
|
1591
2303
|
...{
|
|
@@ -1594,22 +2306,8 @@ function SlotButton({ c, ui }) {
|
|
|
1594
2306
|
});
|
|
1595
2307
|
}
|
|
1596
2308
|
|
|
1597
|
-
// src/hooks/use-ui-context.ts
|
|
1598
|
-
function useUIContext() {
|
|
1599
|
-
const selection = useSlice("selection") ?? { blocks: new Map };
|
|
1600
|
-
const focus = useSlice("focus") ?? null;
|
|
1601
|
-
const hover = useSlice("hover") ?? null;
|
|
1602
|
-
const textSelection = useSlice("textSelection") ?? null;
|
|
1603
|
-
return {
|
|
1604
|
-
selection,
|
|
1605
|
-
focus,
|
|
1606
|
-
hover,
|
|
1607
|
-
textSelection
|
|
1608
|
-
};
|
|
1609
|
-
}
|
|
1610
|
-
|
|
1611
2309
|
// src/components/slots/slot-component.tsx
|
|
1612
|
-
import { createElement } from "react";
|
|
2310
|
+
import { createElement as createElement2 } from "react";
|
|
1613
2311
|
function SlotComponent({ c, ui }) {
|
|
1614
2312
|
const Comp = useRegistryComponent(c.name);
|
|
1615
2313
|
if (!Comp) {
|
|
@@ -1619,16 +2317,16 @@ function SlotComponent({ c, ui }) {
|
|
|
1619
2317
|
const props = c.getProps(ui);
|
|
1620
2318
|
if (!props)
|
|
1621
2319
|
return null;
|
|
1622
|
-
return
|
|
2320
|
+
return createElement2(Comp, { ui, c });
|
|
1623
2321
|
}
|
|
1624
2322
|
|
|
1625
2323
|
// src/components/slots/slots.tsx
|
|
1626
|
-
import { jsxDEV as
|
|
2324
|
+
import { jsxDEV as jsxDEV24, Fragment } from "react/jsx-dev-runtime";
|
|
1627
2325
|
function Slots({ slotName }) {
|
|
1628
2326
|
const items = useSlots(slotName);
|
|
1629
2327
|
const ui = useUIContext();
|
|
1630
|
-
return /* @__PURE__ */
|
|
1631
|
-
children: items.map((c) => /* @__PURE__ */
|
|
2328
|
+
return /* @__PURE__ */ jsxDEV24(Fragment, {
|
|
2329
|
+
children: items.map((c) => /* @__PURE__ */ jsxDEV24(SlotItem, {
|
|
1632
2330
|
c,
|
|
1633
2331
|
ui
|
|
1634
2332
|
}, c.id, false, undefined, this))
|
|
@@ -1639,12 +2337,12 @@ function SlotItem({ c, ui }) {
|
|
|
1639
2337
|
return null;
|
|
1640
2338
|
switch (c.kind) {
|
|
1641
2339
|
case "button":
|
|
1642
|
-
return /* @__PURE__ */
|
|
2340
|
+
return /* @__PURE__ */ jsxDEV24(SlotButton, {
|
|
1643
2341
|
c,
|
|
1644
2342
|
ui
|
|
1645
2343
|
}, undefined, false, undefined, this);
|
|
1646
2344
|
case "component":
|
|
1647
|
-
return /* @__PURE__ */
|
|
2345
|
+
return /* @__PURE__ */ jsxDEV24(SlotComponent, {
|
|
1648
2346
|
c,
|
|
1649
2347
|
ui
|
|
1650
2348
|
}, undefined, false, undefined, this);
|
|
@@ -1652,334 +2350,54 @@ function SlotItem({ c, ui }) {
|
|
|
1652
2350
|
}
|
|
1653
2351
|
|
|
1654
2352
|
// src/components/slots/maps/block-actions.tsx
|
|
1655
|
-
import { cn as
|
|
1656
|
-
import {
|
|
1657
|
-
function BlockActions({ className, children, ...rest }) {
|
|
1658
|
-
const selection = useSlice("selection");
|
|
1659
|
-
const documentSlice = useSlice("document");
|
|
1660
|
-
const { blocks = new Map } = selection ?? {};
|
|
1661
|
-
const { order = new Set } = documentSlice ?? {};
|
|
1662
|
-
const keys = [...blocks.keys()];
|
|
1663
|
-
const firstSelectionId = keys[0];
|
|
1664
|
-
const engine = useEngine();
|
|
1665
|
-
const lastPositionRef = useRef({ active: false, top: 0, left: 0 });
|
|
1666
|
-
const blockRect = blocks.get(firstSelectionId);
|
|
1667
|
-
const position = useMemo2(() => {
|
|
1668
|
-
if (!firstSelectionId || !blockRect) {
|
|
1669
|
-
return { active: false, top: 0, left: 0 };
|
|
1670
|
-
}
|
|
1671
|
-
const container = document.getElementById("corax_flow_blocks_container");
|
|
1672
|
-
if (!container)
|
|
1673
|
-
return { active: false, top: 0, left: 0 };
|
|
1674
|
-
const containerRect = container.getBoundingClientRect();
|
|
1675
|
-
const block = engine.document.getBlock(firstSelectionId);
|
|
1676
|
-
if (!block || block.variant !== "field")
|
|
1677
|
-
return { active: false, top: 0, left: 0 };
|
|
1678
|
-
const domElement = document.getElementById(firstSelectionId);
|
|
1679
|
-
if (!domElement)
|
|
1680
|
-
return { active: false, top: 0, left: 0 };
|
|
1681
|
-
const heightDiff = 36 - blockRect.height;
|
|
1682
|
-
const toSubstract = heightDiff / 2;
|
|
1683
|
-
const top = blockRect.top - (-toSubstract > 32 ? -8 : toSubstract) - containerRect.top - container.clientTop + blockRect.parentScrollTop;
|
|
1684
|
-
return {
|
|
1685
|
-
active: true,
|
|
1686
|
-
top,
|
|
1687
|
-
left: 0
|
|
1688
|
-
};
|
|
1689
|
-
}, [firstSelectionId, engine, blockRect]);
|
|
1690
|
-
useEffect2(() => {
|
|
1691
|
-
if (position.active) {
|
|
1692
|
-
lastPositionRef.current = position;
|
|
1693
|
-
}
|
|
1694
|
-
}, [position]);
|
|
1695
|
-
const _position = position.active ? position : lastPositionRef.current;
|
|
1696
|
-
return /* @__PURE__ */ jsxDEV11("div", {
|
|
1697
|
-
style: {
|
|
1698
|
-
top: _position.top,
|
|
1699
|
-
left: _position.left
|
|
1700
|
-
},
|
|
1701
|
-
className: cn5("absolute top-0 left-0 gap-1 flex items-center transition-opacity", className, {
|
|
1702
|
-
"opacity-0 pointer-events-none": !_position.active || keys.length > 1 || firstSelectionId && !order?.has(firstSelectionId)
|
|
1703
|
-
}),
|
|
1704
|
-
...rest,
|
|
1705
|
-
children: [
|
|
1706
|
-
/* @__PURE__ */ jsxDEV11(Slots, {
|
|
1707
|
-
slotName: "block-actions"
|
|
1708
|
-
}, undefined, false, undefined, this),
|
|
1709
|
-
children
|
|
1710
|
-
]
|
|
1711
|
-
}, undefined, true, undefined, this);
|
|
1712
|
-
}
|
|
1713
|
-
// src/components/slots/maps/overlays.tsx
|
|
1714
|
-
import { jsxDEV as jsxDEV12, Fragment as Fragment2 } from "react/jsx-dev-runtime";
|
|
1715
|
-
function Overlays() {
|
|
1716
|
-
return /* @__PURE__ */ jsxDEV12(Fragment2, {
|
|
1717
|
-
children: /* @__PURE__ */ jsxDEV12(Slots, {
|
|
1718
|
-
slotName: "overlay"
|
|
1719
|
-
}, undefined, false, undefined, this)
|
|
1720
|
-
}, undefined, false, undefined, this);
|
|
1721
|
-
}
|
|
1722
|
-
// src/components/slots/maps/text-inspector.tsx
|
|
1723
|
-
import { jsxDEV as jsxDEV13 } from "react/jsx-dev-runtime";
|
|
1724
|
-
function TextInspector({ blockId }) {
|
|
1725
|
-
return /* @__PURE__ */ jsxDEV13("div", {
|
|
1726
|
-
children: blockId
|
|
1727
|
-
}, undefined, false, undefined, this);
|
|
1728
|
-
}
|
|
1729
|
-
// src/components/slots/maps/toolbar.tsx
|
|
1730
|
-
import { cn as cn6 } from "cn";
|
|
1731
|
-
import { useRef as useRef2, useMemo as useMemo3, useEffect as useEffect3 } from "react";
|
|
1732
|
-
|
|
1733
|
-
// src/lib/selection.utils.ts
|
|
1734
|
-
function rangeToOffsets(root, range) {
|
|
1735
|
-
const measure = (node, offset) => {
|
|
1736
|
-
const r = document.createRange();
|
|
1737
|
-
r.selectNodeContents(root);
|
|
1738
|
-
r.setEnd(node, offset);
|
|
1739
|
-
return r.toString().length;
|
|
1740
|
-
};
|
|
1741
|
-
return {
|
|
1742
|
-
start: measure(range.startContainer, range.startOffset),
|
|
1743
|
-
end: measure(range.endContainer, range.endOffset)
|
|
1744
|
-
};
|
|
1745
|
-
}
|
|
1746
|
-
function offsetsToRange(root, start, end) {
|
|
1747
|
-
const range = document.createRange();
|
|
1748
|
-
const walker = document.createTreeWalker(root, NodeFilter.SHOW_TEXT);
|
|
1749
|
-
let pos = 0, startSet = false;
|
|
1750
|
-
for (let n = walker.nextNode();n; n = walker.nextNode()) {
|
|
1751
|
-
const next = pos + n.length;
|
|
1752
|
-
if (!startSet && start <= next) {
|
|
1753
|
-
range.setStart(n, start - pos);
|
|
1754
|
-
startSet = true;
|
|
1755
|
-
}
|
|
1756
|
-
if (startSet && end <= next) {
|
|
1757
|
-
range.setEnd(n, end - pos);
|
|
1758
|
-
return range;
|
|
1759
|
-
}
|
|
1760
|
-
pos = next;
|
|
1761
|
-
}
|
|
1762
|
-
return null;
|
|
1763
|
-
}
|
|
1764
|
-
|
|
1765
|
-
// src/components/slots/maps/toolbar.tsx
|
|
1766
|
-
import { jsxDEV as jsxDEV14 } from "react/jsx-dev-runtime";
|
|
1767
|
-
var TOOLBAR_OFFSET = 8;
|
|
1768
|
-
var DEFAULT_STATE = { active: false, top: 0, left: 0 };
|
|
1769
|
-
function Toolbar({ className, children, ...rest }) {
|
|
1770
|
-
const textSel = useSlice("textSelection");
|
|
1771
|
-
const currentBlockId = textSel?.blockId;
|
|
1772
|
-
const documentSlice = useSlice("document");
|
|
1773
|
-
const { order = new Set } = documentSlice ?? {};
|
|
1774
|
-
const engine = useEngine();
|
|
1775
|
-
const lastPositionRef = useRef2(DEFAULT_STATE);
|
|
1776
|
-
const toolbarRef = useRef2(null);
|
|
1777
|
-
const position = useMemo3(() => {
|
|
1778
|
-
const toolbarElement = toolbarRef.current;
|
|
1779
|
-
if (!currentBlockId || !toolbarElement) {
|
|
1780
|
-
return DEFAULT_STATE;
|
|
1781
|
-
}
|
|
1782
|
-
const el = document.getElementById(textSel.blockId);
|
|
1783
|
-
if (!el)
|
|
1784
|
-
return DEFAULT_STATE;
|
|
1785
|
-
const range = offsetsToRange(el, textSel.start, textSel.end);
|
|
1786
|
-
if (!range)
|
|
1787
|
-
return DEFAULT_STATE;
|
|
1788
|
-
const selRect = range.getBoundingClientRect();
|
|
1789
|
-
const block = engine.document.getBlock(currentBlockId);
|
|
1790
|
-
if (!block)
|
|
1791
|
-
return { active: false, top: 0, left: 0 };
|
|
1792
|
-
const blockRect = blockRectFromBlockId(currentBlockId);
|
|
1793
|
-
if (!blockRect)
|
|
1794
|
-
return { active: false, top: 0, left: 0 };
|
|
1795
|
-
return {
|
|
1796
|
-
active: true,
|
|
1797
|
-
top: blockRect.top - toolbarElement.offsetHeight - TOOLBAR_OFFSET,
|
|
1798
|
-
left: selRect.left - (toolbarElement.offsetWidth - selRect.width) / 2
|
|
1799
|
-
};
|
|
1800
|
-
}, [currentBlockId, engine, textSel]);
|
|
1801
|
-
useEffect3(() => {
|
|
1802
|
-
if (position.active) {
|
|
1803
|
-
lastPositionRef.current = position;
|
|
1804
|
-
}
|
|
1805
|
-
}, [position]);
|
|
1806
|
-
const _position = position.active ? position : lastPositionRef.current;
|
|
1807
|
-
return /* @__PURE__ */ jsxDEV14("div", {
|
|
1808
|
-
ref: toolbarRef,
|
|
1809
|
-
style: {
|
|
1810
|
-
top: _position.top,
|
|
1811
|
-
left: _position.left
|
|
1812
|
-
},
|
|
1813
|
-
className: cn6("fixed top-0 left-0 gap-1 flex items-center transition-all", className, {
|
|
1814
|
-
"opacity-0 pointer-events-none": !_position.active || currentBlockId && !order?.has(currentBlockId)
|
|
1815
|
-
}),
|
|
1816
|
-
...rest,
|
|
1817
|
-
children: [
|
|
1818
|
-
/* @__PURE__ */ jsxDEV14(Slots, {
|
|
1819
|
-
slotName: "toolbar"
|
|
1820
|
-
}, undefined, false, undefined, this),
|
|
1821
|
-
children
|
|
1822
|
-
]
|
|
1823
|
-
}, undefined, true, undefined, this);
|
|
1824
|
-
}
|
|
2353
|
+
import { cn as cn14 } from "cn";
|
|
2354
|
+
import { isEditableField } from "@coorax/core";
|
|
1825
2355
|
|
|
1826
|
-
// src/components/slots/maps/index.ts
|
|
1827
|
-
"use client";
|
|
1828
2356
|
// src/components/corax-flow.tsx
|
|
1829
|
-
import {
|
|
2357
|
+
import { useSyncExternalStore as useSyncExternalStore5 } from "react";
|
|
1830
2358
|
|
|
1831
2359
|
// src/hooks/use-renderer.ts
|
|
1832
|
-
import { useMemo as
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
import React5 from "react";
|
|
1836
|
-
import {
|
|
1837
|
-
UTILS as UTILS3,
|
|
1838
|
-
segments
|
|
1839
|
-
} from "@coorax/core";
|
|
2360
|
+
import { useMemo as useMemo2 } from "react";
|
|
2361
|
+
import { ReactRenderer } from "@coorax/render-react";
|
|
2362
|
+
import { UTILS as UTILS2 } from "@coorax/core";
|
|
1840
2363
|
|
|
1841
|
-
// src/
|
|
1842
|
-
|
|
1843
|
-
components = new Map;
|
|
1844
|
-
get(name) {
|
|
1845
|
-
const sid = Symbol.for(name);
|
|
1846
|
-
const foundCOmp = this.components.get(sid);
|
|
1847
|
-
if (foundCOmp) {
|
|
1848
|
-
return foundCOmp;
|
|
1849
|
-
}
|
|
1850
|
-
return null;
|
|
1851
|
-
}
|
|
1852
|
-
getAll(names) {
|
|
1853
|
-
return names.map((name) => this.get(name));
|
|
1854
|
-
}
|
|
1855
|
-
post(name, comp) {
|
|
1856
|
-
if (comp.length < 1) {
|
|
1857
|
-
throw new Error("Components arguments must be greater than 1");
|
|
1858
|
-
}
|
|
1859
|
-
const sid = Symbol.for(name);
|
|
1860
|
-
this.components.set(sid, comp);
|
|
1861
|
-
}
|
|
1862
|
-
delete(name) {
|
|
1863
|
-
const sid = Symbol.for(name);
|
|
1864
|
-
this.components.delete(sid);
|
|
1865
|
-
}
|
|
1866
|
-
batch(comps) {
|
|
1867
|
-
for (const [key, value] of Object.entries(comps)) {
|
|
1868
|
-
const sid = Symbol.for(key);
|
|
1869
|
-
this.components.set(sid, value);
|
|
1870
|
-
}
|
|
1871
|
-
}
|
|
1872
|
-
}
|
|
1873
|
-
|
|
1874
|
-
// src/hooks/use-block.ts
|
|
1875
|
-
import { useSyncExternalStore as useSyncExternalStore4 } from "react";
|
|
1876
|
-
function useBlock(id) {
|
|
1877
|
-
const engine = useEngine();
|
|
1878
|
-
return useSyncExternalStore4((fn) => engine.document.subscribeBlock(id, fn), () => engine.document.getBlock(id), () => engine.document.getBlock(id));
|
|
1879
|
-
}
|
|
1880
|
-
|
|
1881
|
-
// src/primitives/fields/field.primitives.tsx
|
|
1882
|
-
import { useCallback, useEffect as useEffect5, useRef as useRef3 } from "react";
|
|
1883
|
-
|
|
1884
|
-
// src/hooks/custom/use-isomorphic-layout-effect.ts
|
|
1885
|
-
import { useEffect as useEffect4, useLayoutEffect } from "react";
|
|
1886
|
-
var useIsomorphicLayoutEffect = typeof window !== "undefined" ? useLayoutEffect : useEffect4;
|
|
1887
|
-
|
|
1888
|
-
// src/primitives/fields/field.primitives.tsx
|
|
1889
|
-
import { jsxDEV as jsxDEV15 } from "react/jsx-dev-runtime";
|
|
1890
|
-
function FieldPrimitive({ blockId }) {
|
|
1891
|
-
const blockRef = useRef3(null);
|
|
1892
|
-
const engine = useEngine();
|
|
1893
|
-
const renderer = useRenderer();
|
|
1894
|
-
const block = useBlock(blockId);
|
|
1895
|
-
const sel = useSlice("textSelection");
|
|
1896
|
-
const updateRange = useCallback(() => {
|
|
1897
|
-
if (!sel)
|
|
1898
|
-
return;
|
|
1899
|
-
const root = document.querySelector(`[id="${CSS.escape(sel.blockId)}"][data-text-path="${CSS.escape(sel.path)}"]`);
|
|
1900
|
-
if (!root || !root.contains(document.activeElement))
|
|
1901
|
-
return;
|
|
1902
|
-
const domSel = document.getSelection();
|
|
1903
|
-
if (!domSel)
|
|
1904
|
-
return;
|
|
1905
|
-
if (domSel.rangeCount) {
|
|
1906
|
-
const cur = rangeToOffsets(root, domSel.getRangeAt(0));
|
|
1907
|
-
if (cur.start === sel.start && cur.end === sel.end)
|
|
1908
|
-
return;
|
|
1909
|
-
}
|
|
1910
|
-
const range = offsetsToRange(root, sel.start, sel.end);
|
|
1911
|
-
if (!range)
|
|
1912
|
-
return;
|
|
1913
|
-
domSel.removeAllRanges();
|
|
1914
|
-
domSel.addRange(range);
|
|
1915
|
-
}, [sel]);
|
|
1916
|
-
useIsomorphicLayoutEffect(() => {
|
|
1917
|
-
updateRange();
|
|
1918
|
-
}, [updateRange, engine]);
|
|
1919
|
-
useIsomorphicLayoutEffect(() => {
|
|
1920
|
-
if (!sel)
|
|
1921
|
-
return;
|
|
1922
|
-
const root = document.querySelector(`[id="${CSS.escape(sel.blockId)}"][data-text-path="${CSS.escape(sel.path)}"]`);
|
|
1923
|
-
if (!root)
|
|
1924
|
-
return;
|
|
1925
|
-
const range = offsetsToRange(root, sel.start, sel.end);
|
|
1926
|
-
if (!range)
|
|
1927
|
-
return;
|
|
1928
|
-
root.focus({ preventScroll: true });
|
|
1929
|
-
const domSel = document.getSelection();
|
|
1930
|
-
domSel.removeAllRanges();
|
|
1931
|
-
domSel.addRange(range);
|
|
1932
|
-
});
|
|
1933
|
-
useEffect5(() => {
|
|
1934
|
-
const domEl = blockRef.current;
|
|
1935
|
-
if (!domEl)
|
|
1936
|
-
return;
|
|
1937
|
-
const observer = new ResizeObserver(() => {
|
|
1938
|
-
const rect = blockRectFromBlockId(blockId);
|
|
1939
|
-
if (!rect || !!engine.document.get().order.size)
|
|
1940
|
-
return;
|
|
1941
|
-
engine.commands.tryExecute("blocks.focus", { id: blockId, rect });
|
|
1942
|
-
});
|
|
1943
|
-
observer.observe(domEl);
|
|
1944
|
-
return () => {
|
|
1945
|
-
observer.unobserve(domEl);
|
|
1946
|
-
observer.disconnect();
|
|
1947
|
-
};
|
|
1948
|
-
}, [engine, blockId]);
|
|
1949
|
-
if (!blockId.startsWith("field") || !block)
|
|
1950
|
-
return null;
|
|
1951
|
-
return /* @__PURE__ */ jsxDEV15("div", {
|
|
1952
|
-
ref: blockRef,
|
|
1953
|
-
children: renderer.renderField(block)
|
|
1954
|
-
}, undefined, false, undefined, this);
|
|
1955
|
-
}
|
|
2364
|
+
// src/lifecycle/fields/handlers.registry.ts
|
|
2365
|
+
import { GenericRegistry as GenericRegistry5 } from "@coorax/render-react";
|
|
1956
2366
|
|
|
1957
|
-
// src/
|
|
1958
|
-
var
|
|
1959
|
-
|
|
2367
|
+
// src/lifecycle/fields/common/focus.events/onblur.ts
|
|
2368
|
+
var createOnBlur = async (engine, block, ev) => {
|
|
2369
|
+
const fieldInfo = getFieldTypeAndTargetId(engine, ev, block);
|
|
2370
|
+
if (!fieldInfo)
|
|
2371
|
+
return;
|
|
2372
|
+
const textSel = engine.state.get("textSelection");
|
|
2373
|
+
if (textSel && textSel.start !== textSel.end)
|
|
2374
|
+
return;
|
|
2375
|
+
engine.commands.tryExecute("blocks.focus", null);
|
|
2376
|
+
await fieldInfo.emit();
|
|
1960
2377
|
};
|
|
1961
2378
|
|
|
1962
|
-
// src/
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
UTILS
|
|
1970
|
-
} from "@coorax/core";
|
|
2379
|
+
// src/lifecycle/fields/common/focus.events/onfocus.ts
|
|
2380
|
+
var createOnFocus = async (engine, block, ev) => {
|
|
2381
|
+
const fieldInfo = getFieldTypeAndTargetId(engine, ev, block);
|
|
2382
|
+
if (!fieldInfo)
|
|
2383
|
+
return;
|
|
2384
|
+
await fieldInfo.emit();
|
|
2385
|
+
};
|
|
1971
2386
|
|
|
1972
|
-
// src/lifecycle/fields/mouse.events/onclick.ts
|
|
2387
|
+
// src/lifecycle/fields/common/mouse.events/onclick.ts
|
|
1973
2388
|
var createOnClick = async (engine, block, ev) => {
|
|
1974
2389
|
ev.stopPropagation();
|
|
2390
|
+
if (block.type === "iframe") {
|
|
2391
|
+
ev.preventDefault();
|
|
2392
|
+
}
|
|
1975
2393
|
const fieldInfo = getFieldTypeAndTargetId(engine, ev, block);
|
|
1976
2394
|
if (!fieldInfo)
|
|
1977
2395
|
return;
|
|
1978
2396
|
const isOnControl = ev.ctrlKey || ev.metaKey;
|
|
1979
|
-
const
|
|
1980
|
-
if (!
|
|
2397
|
+
const selection2 = engine.state.get("selection");
|
|
2398
|
+
if (!selection2)
|
|
1981
2399
|
return;
|
|
1982
|
-
const keys = Array.from(
|
|
2400
|
+
const keys = Array.from(selection2.blocks.keys());
|
|
1983
2401
|
const blockRect = blockRectFromBlockId(block.id);
|
|
1984
2402
|
if (!blockRect)
|
|
1985
2403
|
return;
|
|
@@ -2026,44 +2444,23 @@ var createOnClick = async (engine, block, ev) => {
|
|
|
2026
2444
|
await fieldInfo.emit();
|
|
2027
2445
|
};
|
|
2028
2446
|
|
|
2029
|
-
// src/lifecycle/fields/mouse.events/
|
|
2030
|
-
var
|
|
2031
|
-
ev.stopPropagation();
|
|
2447
|
+
// src/lifecycle/fields/common/mouse.events/onmouseenter.ts
|
|
2448
|
+
var createOnMouseEnter = async (engine, block, ev) => {
|
|
2032
2449
|
const fieldInfo = getFieldTypeAndTargetId(engine, ev, block);
|
|
2033
2450
|
if (!fieldInfo)
|
|
2034
2451
|
return;
|
|
2035
|
-
const
|
|
2036
|
-
if (
|
|
2037
|
-
return;
|
|
2038
|
-
const focus = engine.state.get("focus");
|
|
2039
|
-
if (focus?.id === block.id) {
|
|
2452
|
+
const selection2 = engine.state.get("selection");
|
|
2453
|
+
if (selection2 && selection2.blocks.has(block.id)) {
|
|
2040
2454
|
return;
|
|
2041
2455
|
}
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
};
|
|
2045
|
-
|
|
2046
|
-
// src/lifecycle/fields/focus.events/onfocus.ts
|
|
2047
|
-
var createOnFocus = async (engine, block, ev) => {
|
|
2048
|
-
const fieldInfo = getFieldTypeAndTargetId(engine, ev, block);
|
|
2049
|
-
if (!fieldInfo)
|
|
2050
|
-
return;
|
|
2051
|
-
await fieldInfo.emit();
|
|
2052
|
-
};
|
|
2053
|
-
|
|
2054
|
-
// src/lifecycle/fields/focus.events/onblur.ts
|
|
2055
|
-
var createOnBlur = async (engine, block, ev) => {
|
|
2056
|
-
const fieldInfo = getFieldTypeAndTargetId(engine, ev, block);
|
|
2057
|
-
if (!fieldInfo)
|
|
2058
|
-
return;
|
|
2059
|
-
const textSel = engine.state.get("textSelection");
|
|
2060
|
-
if (textSel && textSel.start !== textSel.end)
|
|
2456
|
+
const rect = blockRectFromBlockId(block.id);
|
|
2457
|
+
if (!rect)
|
|
2061
2458
|
return;
|
|
2062
|
-
engine.commands.tryExecute("blocks.
|
|
2459
|
+
engine.commands.tryExecute("blocks.hover", { id: block.id, rect });
|
|
2063
2460
|
await fieldInfo.emit();
|
|
2064
2461
|
};
|
|
2065
2462
|
|
|
2066
|
-
// src/lifecycle/fields/mouse.events/onmouseleave.ts
|
|
2463
|
+
// src/lifecycle/fields/common/mouse.events/onmouseleave.ts
|
|
2067
2464
|
var createOnMouseLeave = async (engine, block, ev) => {
|
|
2068
2465
|
const fieldInfo = getFieldTypeAndTargetId(engine, ev, block);
|
|
2069
2466
|
if (!fieldInfo)
|
|
@@ -2077,28 +2474,86 @@ var createOnMouseLeave = async (engine, block, ev) => {
|
|
|
2077
2474
|
await fieldInfo.emit();
|
|
2078
2475
|
};
|
|
2079
2476
|
|
|
2080
|
-
// src/lifecycle/fields/
|
|
2081
|
-
|
|
2477
|
+
// src/lifecycle/fields/common/handlers.ts
|
|
2478
|
+
function buildCommonHandlers(engine, block) {
|
|
2479
|
+
return {
|
|
2480
|
+
onClick: createOnClick.bind(null, engine, block),
|
|
2481
|
+
onMouseEnter: createOnMouseEnter.bind(null, engine, block),
|
|
2482
|
+
onMouseLeave: createOnMouseLeave.bind(null, engine, block),
|
|
2483
|
+
onFocus: createOnFocus.bind(null, engine, block),
|
|
2484
|
+
onBlur: createOnBlur.bind(null, engine, block)
|
|
2485
|
+
};
|
|
2486
|
+
}
|
|
2487
|
+
|
|
2488
|
+
// src/lifecycle/fields/divider/keyboard.events/onkeydown.ts
|
|
2489
|
+
import { FieldsUtils } from "@coorax/core";
|
|
2490
|
+
var createOnKeyDown = async (engine, block, ev) => {
|
|
2082
2491
|
const fieldInfo = getFieldTypeAndTargetId(engine, ev, block);
|
|
2083
2492
|
if (!fieldInfo)
|
|
2084
2493
|
return;
|
|
2085
|
-
|
|
2086
|
-
if (selection && selection.blocks.has(block.id)) {
|
|
2494
|
+
if (ev.ctrlKey || ev.metaKey)
|
|
2087
2495
|
return;
|
|
2088
|
-
|
|
2089
|
-
const
|
|
2090
|
-
|
|
2496
|
+
const tree = engine.document.get();
|
|
2497
|
+
const normalizedTarget = fieldInfo.target;
|
|
2498
|
+
const hasCurrentElement = engine.document.has(normalizedTarget);
|
|
2499
|
+
if (!hasCurrentElement) {
|
|
2500
|
+
console.warn(`Ignoring stale field target: ${normalizedTarget}`);
|
|
2091
2501
|
return;
|
|
2092
|
-
|
|
2093
|
-
|
|
2502
|
+
}
|
|
2503
|
+
const targetIndex = [...tree.order].indexOf(normalizedTarget);
|
|
2504
|
+
const index = targetIndex + 1;
|
|
2505
|
+
const currentTarget = ev.currentTarget;
|
|
2506
|
+
if (ev.key === "Enter" && !ev.shiftKey) {
|
|
2507
|
+
ev.preventDefault();
|
|
2508
|
+
currentTarget.blur();
|
|
2509
|
+
const newField = FieldsUtils.NewField("text");
|
|
2510
|
+
engine.commands.tryExecute("blocks.insert", { block: newField, pos: index });
|
|
2511
|
+
await fieldInfo.emit();
|
|
2512
|
+
const blockRect = blockRectFromBlockId(newField.id);
|
|
2513
|
+
if (!blockRect)
|
|
2514
|
+
return;
|
|
2515
|
+
engine.commands.tryExecute("blocks.focus", { id: newField.id, rect: blockRect });
|
|
2516
|
+
}
|
|
2517
|
+
if (ev.key === "ArrowUp" || ev.key === "ArrowDown" || ev.key === "Tab") {
|
|
2518
|
+
ev.preventDefault();
|
|
2519
|
+
const mustBeNegativeDelta = ev.key === "ArrowUp" || ev.key === "Tab" && ev.shiftKey;
|
|
2520
|
+
const delta = mustBeNegativeDelta ? -1 : 1;
|
|
2521
|
+
const currentTree = engine.document.get();
|
|
2522
|
+
const blockIndex = Array.from(currentTree.order).indexOf(block.id);
|
|
2523
|
+
if (blockIndex === -1)
|
|
2524
|
+
return;
|
|
2525
|
+
if (blockIndex === 0 && delta < 0)
|
|
2526
|
+
return;
|
|
2527
|
+
if (blockIndex === currentTree.order.size - 1 && delta > 0)
|
|
2528
|
+
return;
|
|
2529
|
+
const rectId = [...currentTree.order][blockIndex + delta];
|
|
2530
|
+
const rect = blockRectFromBlockId(rectId);
|
|
2531
|
+
if (!rect) {
|
|
2532
|
+
return;
|
|
2533
|
+
}
|
|
2534
|
+
currentTarget.blur();
|
|
2535
|
+
engine.commands.tryExecute("blocks.focus", { id: rectId, rect });
|
|
2536
|
+
}
|
|
2537
|
+
if (ev.key === "Escape") {
|
|
2538
|
+
ev.preventDefault();
|
|
2539
|
+
currentTarget.blur();
|
|
2540
|
+
engine.commands.tryExecute("blocks.select", { blocks: new Map, mode: "replace" });
|
|
2541
|
+
}
|
|
2094
2542
|
};
|
|
2095
2543
|
|
|
2096
|
-
// src/lifecycle/fields/
|
|
2544
|
+
// src/lifecycle/fields/divider/handlers.ts
|
|
2545
|
+
function buildDividerHandlers(engine, block) {
|
|
2546
|
+
return {
|
|
2547
|
+
...buildCommonHandlers(engine, block),
|
|
2548
|
+
onKeyDown: createOnKeyDown.bind(null, engine, block)
|
|
2549
|
+
};
|
|
2550
|
+
}
|
|
2551
|
+
|
|
2552
|
+
// src/lifecycle/fields/editable/keyboard.events/onkeydown.ts
|
|
2097
2553
|
import {
|
|
2098
|
-
FieldsUtils
|
|
2099
|
-
isEditableField
|
|
2554
|
+
FieldsUtils as FieldsUtils2
|
|
2100
2555
|
} from "@coorax/core";
|
|
2101
|
-
var
|
|
2556
|
+
var createOnKeyDown2 = async (engine, block, ev) => {
|
|
2102
2557
|
const fieldInfo = getFieldTypeAndTargetId(engine, ev, block);
|
|
2103
2558
|
if (!fieldInfo)
|
|
2104
2559
|
return;
|
|
@@ -2117,7 +2572,7 @@ var createOnKeyDown = async (engine, block, ev) => {
|
|
|
2117
2572
|
if (ev.key === "Enter" && !ev.shiftKey) {
|
|
2118
2573
|
ev.preventDefault();
|
|
2119
2574
|
currentTarget.blur();
|
|
2120
|
-
const newField =
|
|
2575
|
+
const newField = FieldsUtils2.NewField("text");
|
|
2121
2576
|
engine.commands.tryExecute("blocks.insert", { block: newField, pos: index });
|
|
2122
2577
|
await fieldInfo.emit();
|
|
2123
2578
|
const blockRect = blockRectFromBlockId(newField.id);
|
|
@@ -2148,44 +2603,50 @@ var createOnKeyDown = async (engine, block, ev) => {
|
|
|
2148
2603
|
if (ev.key === "Escape") {
|
|
2149
2604
|
ev.preventDefault();
|
|
2150
2605
|
currentTarget.blur();
|
|
2151
|
-
|
|
2152
|
-
engine.commands.tryExecute("blocks.select", { blocks: new Map, mode: "replace" });
|
|
2153
|
-
}
|
|
2606
|
+
engine.commands.tryExecute("blocks.focus", null);
|
|
2154
2607
|
}
|
|
2155
2608
|
if (ev.key === "Backspace") {
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
if (!blockRect) {
|
|
2165
|
-
engine.commands.tryExecute("blocks.focus", null);
|
|
2166
|
-
return;
|
|
2167
|
-
}
|
|
2168
|
-
if (isEditableField(prevSiblingBlock)) {
|
|
2169
|
-
engine.commands.tryExecute("blocks.focus", {
|
|
2170
|
-
id: prevSiblingBlock.id,
|
|
2171
|
-
rect: blockRect
|
|
2172
|
-
});
|
|
2173
|
-
} else {
|
|
2174
|
-
engine.commands.tryExecute("blocks.select", {
|
|
2175
|
-
blocks: new Map().set(prevSiblingBlock.id, blockRect),
|
|
2176
|
-
mode: "replace"
|
|
2177
|
-
});
|
|
2178
|
-
}
|
|
2179
|
-
} else {
|
|
2609
|
+
const textContent = block.props.children.text;
|
|
2610
|
+
if (textContent.length === 0) {
|
|
2611
|
+
const order = [...engine.document.get().order];
|
|
2612
|
+
const curBlockIndex = order.findIndex((id) => id === block.id);
|
|
2613
|
+
const prevSiblingBlock = engine.document.getBlock(order[curBlockIndex - 1]);
|
|
2614
|
+
if (prevSiblingBlock) {
|
|
2615
|
+
const blockRect = blockRectFromBlockId(prevSiblingBlock.id);
|
|
2616
|
+
if (!blockRect) {
|
|
2180
2617
|
engine.commands.tryExecute("blocks.focus", null);
|
|
2618
|
+
return;
|
|
2181
2619
|
}
|
|
2182
|
-
engine.commands.tryExecute("blocks.
|
|
2620
|
+
engine.commands.tryExecute("blocks.focus", {
|
|
2621
|
+
id: prevSiblingBlock.id,
|
|
2622
|
+
rect: blockRect
|
|
2623
|
+
});
|
|
2624
|
+
} else {
|
|
2625
|
+
engine.commands.tryExecute("blocks.focus", null);
|
|
2183
2626
|
}
|
|
2627
|
+
engine.commands.tryExecute("blocks.delete", { blockId: block.id });
|
|
2184
2628
|
}
|
|
2185
2629
|
}
|
|
2186
2630
|
};
|
|
2187
2631
|
|
|
2188
|
-
// src/lifecycle/fields/
|
|
2632
|
+
// src/lifecycle/fields/editable/mouse.events/ondoubleclick.ts
|
|
2633
|
+
var createOnDoubleClick = async (engine, block, ev) => {
|
|
2634
|
+
ev.stopPropagation();
|
|
2635
|
+
const fieldInfo = getFieldTypeAndTargetId(engine, ev, block);
|
|
2636
|
+
if (!fieldInfo)
|
|
2637
|
+
return;
|
|
2638
|
+
const rect = blockRectFromBlockId(block.id);
|
|
2639
|
+
if (!rect)
|
|
2640
|
+
return;
|
|
2641
|
+
const focus = engine.state.get("focus");
|
|
2642
|
+
if (focus?.id === block.id) {
|
|
2643
|
+
return;
|
|
2644
|
+
}
|
|
2645
|
+
engine.commands.tryExecute("blocks.focus", { id: block.id, rect });
|
|
2646
|
+
await fieldInfo.emit();
|
|
2647
|
+
};
|
|
2648
|
+
|
|
2649
|
+
// src/lifecycle/fields/editable/synthetic.events/onselect.ts
|
|
2189
2650
|
var createOnSelect = async (engine, block, ev) => {
|
|
2190
2651
|
const fieldInfo = getFieldTypeAndTargetId(engine, ev, block);
|
|
2191
2652
|
if (!fieldInfo)
|
|
@@ -2215,318 +2676,343 @@ var createOnSelect = async (engine, block, ev) => {
|
|
|
2215
2676
|
await fieldInfo.emit();
|
|
2216
2677
|
};
|
|
2217
2678
|
|
|
2218
|
-
// src/lifecycle/fields/
|
|
2679
|
+
// src/lifecycle/fields/editable/handlers.ts
|
|
2680
|
+
function buildEditableHandlers(engine, block) {
|
|
2681
|
+
return {
|
|
2682
|
+
...buildCommonHandlers(engine, block),
|
|
2683
|
+
onKeyDown: createOnKeyDown2.bind(null, engine, block),
|
|
2684
|
+
onDoubleClick: createOnDoubleClick.bind(null, engine, block),
|
|
2685
|
+
onSelect: createOnSelect.bind(null, engine, block)
|
|
2686
|
+
};
|
|
2687
|
+
}
|
|
2688
|
+
|
|
2689
|
+
// src/lifecycle/fields/media/image/synthetic.events/onload.ts
|
|
2219
2690
|
var createOnLoad = async (engine, block, ev) => {
|
|
2220
2691
|
const fieldInfo = getFieldTypeAndTargetId(engine, ev, block);
|
|
2221
|
-
if (!fieldInfo)
|
|
2692
|
+
if (!fieldInfo || !block.props?.src?.trim())
|
|
2222
2693
|
return;
|
|
2223
|
-
|
|
2694
|
+
const img = ev?.target;
|
|
2695
|
+
const intrinsic = img?.naturalWidth && img?.naturalHeight ? {
|
|
2696
|
+
"props.intrinsicWidth": img.naturalWidth,
|
|
2697
|
+
"props.intrinsicHeight": img.naturalHeight
|
|
2698
|
+
} : {};
|
|
2699
|
+
engine.document.apply((tree) => engine.mutations.mutateField(tree, {
|
|
2700
|
+
id: block.id,
|
|
2701
|
+
keyValuePairs: {
|
|
2702
|
+
"props.isLoaded": true,
|
|
2703
|
+
...intrinsic
|
|
2704
|
+
}
|
|
2705
|
+
}), { origin: "history" });
|
|
2706
|
+
engine.commands.tryExecute("blocks.select", {
|
|
2707
|
+
blocks: new Map().set(block.id, blockRectFromBlockId(block.id))
|
|
2708
|
+
});
|
|
2224
2709
|
await fieldInfo.emit();
|
|
2225
2710
|
};
|
|
2226
2711
|
|
|
2227
|
-
// src/lifecycle/fields/
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
const
|
|
2231
|
-
if (!
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2712
|
+
// src/lifecycle/fields/media/common/keyboard.events/onkeydown.ts
|
|
2713
|
+
import { FieldsUtils as FieldsUtils3 } from "@coorax/core";
|
|
2714
|
+
var createOnKeyDown3 = async (engine, block, ev) => {
|
|
2715
|
+
const fieldInfo = getFieldTypeAndTargetId(engine, ev, block);
|
|
2716
|
+
if (!fieldInfo)
|
|
2717
|
+
return;
|
|
2718
|
+
if (ev.ctrlKey || ev.metaKey)
|
|
2719
|
+
return;
|
|
2720
|
+
const tree = engine.document.get();
|
|
2721
|
+
const normalizedTarget = fieldInfo.target;
|
|
2722
|
+
const hasCurrentElement = engine.document.has(normalizedTarget);
|
|
2723
|
+
if (!hasCurrentElement) {
|
|
2724
|
+
console.warn(`Ignoring stale field target: ${normalizedTarget}`);
|
|
2725
|
+
return;
|
|
2236
2726
|
}
|
|
2237
|
-
const
|
|
2238
|
-
const
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2727
|
+
const targetIndex = [...tree.order].indexOf(normalizedTarget);
|
|
2728
|
+
const index = targetIndex + 1;
|
|
2729
|
+
const currentTarget = ev.currentTarget;
|
|
2730
|
+
if (ev.key === "Enter" && !ev.shiftKey) {
|
|
2731
|
+
ev.preventDefault();
|
|
2732
|
+
currentTarget.blur();
|
|
2733
|
+
const newField = FieldsUtils3.NewField("text");
|
|
2734
|
+
engine.commands.tryExecute("blocks.insert", { block: newField, pos: index });
|
|
2735
|
+
await fieldInfo.emit();
|
|
2736
|
+
const blockRect = blockRectFromBlockId(newField.id);
|
|
2737
|
+
if (!blockRect)
|
|
2738
|
+
return;
|
|
2739
|
+
engine.commands.tryExecute("blocks.focus", { id: newField.id, rect: blockRect });
|
|
2246
2740
|
}
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
|
|
2261
|
-
|
|
2262
|
-
|
|
2263
|
-
};
|
|
2264
|
-
case "img":
|
|
2265
|
-
case "video":
|
|
2266
|
-
return {
|
|
2267
|
-
onClick: createOnClick.bind(null, engine, block),
|
|
2268
|
-
onKeyDown: createOnKeyDown.bind(null, engine, block),
|
|
2269
|
-
onFocus: createOnFocus.bind(null, engine, block),
|
|
2270
|
-
onMouseEnter: createOnMouseEnter.bind(null, engine, block),
|
|
2271
|
-
onMouseLeave: createOnMouseLeave.bind(null, engine, block),
|
|
2272
|
-
onLoad: createOnLoad.bind(null, engine, block)
|
|
2273
|
-
};
|
|
2274
|
-
case "hr":
|
|
2275
|
-
return {
|
|
2276
|
-
onClick: createOnClick.bind(null, engine, block),
|
|
2277
|
-
onMouseEnter: createOnMouseEnter.bind(null, engine, block),
|
|
2278
|
-
onMouseLeave: createOnMouseLeave.bind(null, engine, block)
|
|
2279
|
-
};
|
|
2280
|
-
default:
|
|
2281
|
-
return {};
|
|
2741
|
+
if (ev.key === "ArrowUp" || ev.key === "ArrowDown" || ev.key === "Tab") {
|
|
2742
|
+
ev.preventDefault();
|
|
2743
|
+
const mustBeNegativeDelta = ev.key === "ArrowUp" || ev.key === "Tab" && ev.shiftKey;
|
|
2744
|
+
const delta = mustBeNegativeDelta ? -1 : 1;
|
|
2745
|
+
const currentTree = engine.document.get();
|
|
2746
|
+
const blockIndex = Array.from(currentTree.order).indexOf(block.id);
|
|
2747
|
+
if (blockIndex === -1)
|
|
2748
|
+
return;
|
|
2749
|
+
if (blockIndex === 0 && delta < 0)
|
|
2750
|
+
return;
|
|
2751
|
+
if (blockIndex === currentTree.order.size - 1 && delta > 0)
|
|
2752
|
+
return;
|
|
2753
|
+
const rectId = [...currentTree.order][blockIndex + delta];
|
|
2754
|
+
const rect = blockRectFromBlockId(rectId);
|
|
2755
|
+
if (!rect) {
|
|
2756
|
+
return;
|
|
2282
2757
|
}
|
|
2758
|
+
currentTarget.blur();
|
|
2759
|
+
engine.commands.tryExecute("blocks.focus", { id: rectId, rect });
|
|
2283
2760
|
}
|
|
2761
|
+
if (ev.key === "Escape") {
|
|
2762
|
+
ev.preventDefault();
|
|
2763
|
+
currentTarget.blur();
|
|
2764
|
+
engine.commands.tryExecute("blocks.select", { blocks: new Map, mode: "replace" });
|
|
2765
|
+
}
|
|
2766
|
+
};
|
|
2767
|
+
|
|
2768
|
+
// src/lifecycle/fields/media/common/synthetic.events/onerror.ts
|
|
2769
|
+
var createOnError = async (engine, block, ev) => {
|
|
2770
|
+
const fieldInfo = getFieldTypeAndTargetId(engine, ev, block);
|
|
2771
|
+
if (!fieldInfo || !block.props?.src?.trim())
|
|
2772
|
+
return;
|
|
2773
|
+
engine.document.apply((tree) => engine.mutations.mutateField(tree, {
|
|
2774
|
+
id: block.id,
|
|
2775
|
+
keyValuePairs: {
|
|
2776
|
+
"props.isError": true
|
|
2777
|
+
}
|
|
2778
|
+
}), { origin: "history" });
|
|
2779
|
+
await fieldInfo.emit();
|
|
2780
|
+
};
|
|
2781
|
+
|
|
2782
|
+
// src/lifecycle/fields/media/common/handlers.ts
|
|
2783
|
+
function buildMediaHandlers(engine, block) {
|
|
2784
|
+
const { onClick, onMouseEnter, onMouseLeave, onFocus } = buildCommonHandlers(engine, block);
|
|
2284
2785
|
return {
|
|
2285
|
-
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
|
|
2786
|
+
onClick,
|
|
2787
|
+
onMouseEnter,
|
|
2788
|
+
onMouseLeave,
|
|
2789
|
+
onFocus,
|
|
2790
|
+
onKeyDown: createOnKeyDown3.bind(null, engine, block),
|
|
2791
|
+
onError: createOnError.bind(null, engine, block)
|
|
2290
2792
|
};
|
|
2291
2793
|
}
|
|
2292
|
-
function getFieldLifeCycleEvents(engine, tag, block) {
|
|
2293
|
-
return getAllLifeCycleEvents(engine, block)[tag];
|
|
2294
|
-
}
|
|
2295
|
-
var FLC = { getFieldLifeCycleEvents };
|
|
2296
2794
|
|
|
2297
|
-
// src/
|
|
2298
|
-
|
|
2299
|
-
import { css } from "@emotion/css";
|
|
2300
|
-
function getTextFieldProps(engine, block) {
|
|
2301
|
-
const ui = engine.ui;
|
|
2302
|
-
const { style, pseudoStyle, className, children: _, placeholder, ...rest } = block.props;
|
|
2303
|
-
const uiStyles = ui.getStyle(block.type);
|
|
2304
|
-
const _pseudoStyle = {
|
|
2305
|
-
...uiStyles.pseudoStyle,
|
|
2306
|
-
...pseudoStyle
|
|
2307
|
-
};
|
|
2308
|
-
const pseudoClassName = resolveCoraxPseudoStyle(_pseudoStyle);
|
|
2309
|
-
const baseProps = {
|
|
2310
|
-
id: block.id,
|
|
2311
|
-
key: block.id,
|
|
2312
|
-
"data-block-type": block.type,
|
|
2313
|
-
style: {
|
|
2314
|
-
...uiStyles.style,
|
|
2315
|
-
...style,
|
|
2316
|
-
...block.props?.contentEditable ? { cursor: "auto", userSelect: "auto" } : null
|
|
2317
|
-
},
|
|
2318
|
-
className: cn7(uiStyles.className, className, pseudoClassName)
|
|
2319
|
-
};
|
|
2320
|
-
const containerProps = block.isContainerized() ? { "data-containerId": block.containerId } : {};
|
|
2321
|
-
const editableProps = {
|
|
2322
|
-
spellCheck: false,
|
|
2323
|
-
suppressContentEditableWarning: true,
|
|
2324
|
-
"data-placeholder": placeholder || "Tell the news here",
|
|
2325
|
-
...rest,
|
|
2326
|
-
contentEditable: !!rest?.contentEditable,
|
|
2327
|
-
autoFocus: true
|
|
2328
|
-
};
|
|
2795
|
+
// src/lifecycle/fields/media/image/handlers.ts
|
|
2796
|
+
function buildImageHandlers(engine, block) {
|
|
2329
2797
|
return {
|
|
2330
|
-
...
|
|
2331
|
-
|
|
2332
|
-
...editableProps,
|
|
2333
|
-
...FLC.getFieldLifeCycleEvents(engine, block.tag, block)
|
|
2798
|
+
...buildMediaHandlers(engine, block),
|
|
2799
|
+
onLoad: createOnLoad.bind(null, engine, block)
|
|
2334
2800
|
};
|
|
2335
2801
|
}
|
|
2336
|
-
|
|
2337
|
-
|
|
2338
|
-
|
|
2339
|
-
const
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
|
|
2802
|
+
|
|
2803
|
+
// src/lifecycle/fields/media/video/synthetic.events/oncanplaythrough.ts
|
|
2804
|
+
var createVideoOnCanPlayThrough = async (engine, block, ev) => {
|
|
2805
|
+
const fieldInfo = getFieldTypeAndTargetId(engine, ev, block);
|
|
2806
|
+
if (!fieldInfo || !block.props?.src?.trim())
|
|
2807
|
+
return;
|
|
2808
|
+
const video = ev?.target;
|
|
2809
|
+
const intrinsic = video?.videoWidth && video?.videoHeight ? {
|
|
2810
|
+
"props.intrinsicWidth": video.videoWidth,
|
|
2811
|
+
"props.intrinsicHeight": video.videoHeight
|
|
2812
|
+
} : {};
|
|
2813
|
+
engine.document.apply((tree) => engine.mutations.mutateField(tree, {
|
|
2346
2814
|
id: block.id,
|
|
2347
|
-
|
|
2348
|
-
|
|
2349
|
-
|
|
2350
|
-
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
|
|
2354
|
-
};
|
|
2355
|
-
|
|
2815
|
+
keyValuePairs: {
|
|
2816
|
+
"props.isLoaded": true,
|
|
2817
|
+
...intrinsic
|
|
2818
|
+
}
|
|
2819
|
+
}), { origin: "history" });
|
|
2820
|
+
engine.commands.tryExecute("blocks.select", {
|
|
2821
|
+
blocks: new Map().set(block.id, blockRectFromBlockId(block.id))
|
|
2822
|
+
});
|
|
2823
|
+
await fieldInfo.emit();
|
|
2824
|
+
};
|
|
2825
|
+
|
|
2826
|
+
// src/lifecycle/fields/media/video/mouse.events/ondoubleclick.ts
|
|
2827
|
+
var createVideoOnDoubleClick = async (engine, block, ev) => {
|
|
2828
|
+
ev.stopPropagation();
|
|
2829
|
+
ev.preventDefault();
|
|
2830
|
+
const fieldInfo = getFieldTypeAndTargetId(engine, ev, block);
|
|
2831
|
+
if (!fieldInfo)
|
|
2832
|
+
return;
|
|
2833
|
+
const field = block;
|
|
2834
|
+
engine.document.apply((t) => engine.mutations.mutateField(t, {
|
|
2835
|
+
id: field.id,
|
|
2836
|
+
keyValuePairs: {
|
|
2837
|
+
"props.controls": !field.props.controls
|
|
2838
|
+
}
|
|
2839
|
+
}), { shouldEmitEvent: false });
|
|
2840
|
+
await fieldInfo.emit();
|
|
2841
|
+
};
|
|
2842
|
+
|
|
2843
|
+
// src/lifecycle/fields/media/video/handlers.ts
|
|
2844
|
+
function buildVideoHandlers(engine, block) {
|
|
2356
2845
|
return {
|
|
2357
|
-
...
|
|
2358
|
-
|
|
2359
|
-
|
|
2360
|
-
...FLC.getFieldLifeCycleEvents(engine, block.tag, block)
|
|
2846
|
+
...buildMediaHandlers(engine, block),
|
|
2847
|
+
onCanPlayThrough: createVideoOnCanPlayThrough.bind(null, engine, block),
|
|
2848
|
+
onDoubleClick: createVideoOnDoubleClick.bind(null, engine, block)
|
|
2361
2849
|
};
|
|
2362
2850
|
}
|
|
2363
|
-
function resolveCoraxPseudoStyle(style) {
|
|
2364
|
-
if (!style || Object.keys(style).length === 0)
|
|
2365
|
-
return;
|
|
2366
|
-
return css(style);
|
|
2367
|
-
}
|
|
2368
2851
|
|
|
2369
|
-
// src/
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
const _pseudoStyle = {
|
|
2376
|
-
...uiStyles.pseudoStyle,
|
|
2377
|
-
...pseudoStyle
|
|
2378
|
-
};
|
|
2379
|
-
const pseudoClassName = resolveCoraxPseudoStyle(_pseudoStyle);
|
|
2380
|
-
const baseProps = {
|
|
2852
|
+
// src/lifecycle/fields/media/iframe/synthetic.events/onload.ts
|
|
2853
|
+
var createIframeOnLoad = async (engine, block, ev) => {
|
|
2854
|
+
const fieldInfo = getFieldTypeAndTargetId(engine, ev, block);
|
|
2855
|
+
if (!fieldInfo || !block.props?.src?.trim())
|
|
2856
|
+
return;
|
|
2857
|
+
engine.document.apply((tree) => engine.mutations.mutateField(tree, {
|
|
2381
2858
|
id: block.id,
|
|
2382
|
-
|
|
2383
|
-
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
|
|
2859
|
+
keyValuePairs: {
|
|
2860
|
+
"props.isLoaded": true
|
|
2861
|
+
}
|
|
2862
|
+
}), { origin: "history" });
|
|
2863
|
+
engine.commands.tryExecute("blocks.select", {
|
|
2864
|
+
blocks: new Map().set(block.id, blockRectFromBlockId(block.id))
|
|
2865
|
+
});
|
|
2866
|
+
await fieldInfo.emit();
|
|
2867
|
+
};
|
|
2868
|
+
|
|
2869
|
+
// src/lifecycle/fields/media/iframe/handlers.ts
|
|
2870
|
+
function buildIFrameHandlers(engine, block) {
|
|
2392
2871
|
return {
|
|
2393
|
-
...
|
|
2394
|
-
|
|
2395
|
-
...rest,
|
|
2396
|
-
...handlers
|
|
2872
|
+
...buildMediaHandlers(engine, block),
|
|
2873
|
+
onLoad: createIframeOnLoad.bind(null, engine, block)
|
|
2397
2874
|
};
|
|
2398
2875
|
}
|
|
2399
2876
|
|
|
2400
|
-
// src/
|
|
2401
|
-
|
|
2402
|
-
var defaults = {
|
|
2403
|
-
bold: "strong",
|
|
2404
|
-
italic: "em",
|
|
2405
|
-
underline: "u",
|
|
2406
|
-
code: "code",
|
|
2407
|
-
link: "span",
|
|
2408
|
-
initial: "span"
|
|
2409
|
-
};
|
|
2410
|
-
var RANK = {
|
|
2411
|
-
link: 0,
|
|
2412
|
-
bold: 1,
|
|
2413
|
-
italic: 2,
|
|
2414
|
-
underline: 3,
|
|
2415
|
-
code: 4,
|
|
2416
|
-
initial: 5
|
|
2417
|
-
};
|
|
2418
|
-
function formatText(text) {
|
|
2419
|
-
return text;
|
|
2877
|
+
// src/lifecycle/fields/handlers.registry.ts
|
|
2878
|
+
class FieldHandlersRegistry extends GenericRegistry5 {
|
|
2420
2879
|
}
|
|
2880
|
+
var FieldHandlers = new FieldHandlersRegistry;
|
|
2881
|
+
FieldHandlers.register("h1", buildEditableHandlers);
|
|
2882
|
+
FieldHandlers.register("h2", buildEditableHandlers);
|
|
2883
|
+
FieldHandlers.register("p", buildEditableHandlers);
|
|
2884
|
+
FieldHandlers.register("blockquote", buildEditableHandlers);
|
|
2885
|
+
FieldHandlers.register("figcaption", buildEditableHandlers);
|
|
2886
|
+
FieldHandlers.register("pre", buildEditableHandlers);
|
|
2887
|
+
FieldHandlers.register("a", buildEditableHandlers);
|
|
2888
|
+
FieldHandlers.register("img", buildImageHandlers);
|
|
2889
|
+
FieldHandlers.register("video", buildVideoHandlers);
|
|
2890
|
+
FieldHandlers.register("hr", buildDividerHandlers);
|
|
2891
|
+
FieldHandlers.register("iframe", buildIFrameHandlers);
|
|
2421
2892
|
|
|
2422
|
-
|
|
2423
|
-
|
|
2424
|
-
|
|
2425
|
-
|
|
2426
|
-
|
|
2427
|
-
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
|
|
2435
|
-
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
|
|
2442
|
-
return
|
|
2443
|
-
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
|
|
2447
|
-
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
|
-
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
}, this.renderTextContent(children));
|
|
2454
|
-
}
|
|
2455
|
-
renderMediaField(field, key = null) {
|
|
2456
|
-
const isMediaReady = !!field.props.src.trim();
|
|
2457
|
-
if (!isMediaReady) {
|
|
2458
|
-
const Fallback = FallbackComponentsRegistry.get(field.type);
|
|
2459
|
-
if (Fallback)
|
|
2460
|
-
return /* @__PURE__ */ jsxDEV16(Fallback, {
|
|
2461
|
-
...field
|
|
2462
|
-
}, undefined, false, undefined, this);
|
|
2463
|
-
}
|
|
2464
|
-
return React5.createElement(field.tag, {
|
|
2465
|
-
...getMediaFieldProps(this.engine, field),
|
|
2466
|
-
key: key !== null ? key : field.id
|
|
2467
|
-
});
|
|
2468
|
-
}
|
|
2469
|
-
renderDividerField(field, key = null) {
|
|
2470
|
-
return React5.createElement(field.tag, {
|
|
2471
|
-
...getDividerFieldProps(this.engine, field),
|
|
2472
|
-
key: key !== null ? key : field.id
|
|
2473
|
-
});
|
|
2474
|
-
}
|
|
2475
|
-
renderField(_field, key = null) {
|
|
2476
|
-
const field = typeof _field === "string" ? this.engine.document.getBlock(_field) : _field;
|
|
2477
|
-
if (!field || field.variant !== "field")
|
|
2478
|
-
return /* @__PURE__ */ jsxDEV16(Fragment3, {}, undefined, false, undefined, this);
|
|
2479
|
-
switch (field.type) {
|
|
2480
|
-
case "text":
|
|
2481
|
-
case "heading":
|
|
2482
|
-
return this.renderTextField(field, key);
|
|
2483
|
-
case "video":
|
|
2484
|
-
case "image":
|
|
2485
|
-
return this.renderMediaField(field, key);
|
|
2486
|
-
case "divider":
|
|
2487
|
-
return this.renderDividerField(field);
|
|
2488
|
-
default:
|
|
2489
|
-
return /* @__PURE__ */ jsxDEV16(Fragment3, {}, undefined, false, undefined, this);
|
|
2893
|
+
// src/lifecycle/fields/lifecycle.fields.ts
|
|
2894
|
+
function getFieldLifeCycleEvents(engine, tag, block) {
|
|
2895
|
+
const build = FieldHandlers.get(tag);
|
|
2896
|
+
return build ? build(engine, block) : {};
|
|
2897
|
+
}
|
|
2898
|
+
function forField(engine, block) {
|
|
2899
|
+
return getFieldLifeCycleEvents(engine, block.tag, block);
|
|
2900
|
+
}
|
|
2901
|
+
var FLC = { forField };
|
|
2902
|
+
// src/primitives/fields/field.primitives.tsx
|
|
2903
|
+
import { useCallback, useEffect as useEffect8, useRef } from "react";
|
|
2904
|
+
import { jsxDEV as jsxDEV25 } from "react/jsx-dev-runtime";
|
|
2905
|
+
function FieldPrimitive({ blockId }) {
|
|
2906
|
+
const blockRef = useRef(null);
|
|
2907
|
+
const engine = useEngine();
|
|
2908
|
+
const renderer = useRenderer();
|
|
2909
|
+
const block = useBlock(blockId);
|
|
2910
|
+
const sel = useSlice("textSelection");
|
|
2911
|
+
const updateRange = useCallback(() => {
|
|
2912
|
+
if (!sel)
|
|
2913
|
+
return;
|
|
2914
|
+
const root = document.querySelector(`[id="${CSS.escape(sel.blockId)}"][data-text-path="${CSS.escape(sel.path)}"]`);
|
|
2915
|
+
if (!root || !root.contains(document.activeElement))
|
|
2916
|
+
return;
|
|
2917
|
+
const domSel = document.getSelection();
|
|
2918
|
+
if (!domSel)
|
|
2919
|
+
return;
|
|
2920
|
+
if (domSel.rangeCount) {
|
|
2921
|
+
const cur = rangeToOffsets(root, domSel.getRangeAt(0));
|
|
2922
|
+
if (cur.start === sel.start && cur.end === sel.end)
|
|
2923
|
+
return;
|
|
2490
2924
|
}
|
|
2491
|
-
|
|
2492
|
-
|
|
2493
|
-
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
|
|
2503
|
-
|
|
2504
|
-
|
|
2505
|
-
|
|
2506
|
-
|
|
2507
|
-
|
|
2508
|
-
|
|
2509
|
-
|
|
2510
|
-
|
|
2511
|
-
|
|
2512
|
-
|
|
2513
|
-
|
|
2514
|
-
|
|
2515
|
-
|
|
2516
|
-
|
|
2925
|
+
const range = offsetsToRange(root, sel.start, sel.end);
|
|
2926
|
+
if (!range)
|
|
2927
|
+
return;
|
|
2928
|
+
domSel.removeAllRanges();
|
|
2929
|
+
domSel.addRange(range);
|
|
2930
|
+
}, [sel]);
|
|
2931
|
+
useIsomorphicLayoutEffect(() => {
|
|
2932
|
+
updateRange();
|
|
2933
|
+
}, [updateRange, engine]);
|
|
2934
|
+
useIsomorphicLayoutEffect(() => {
|
|
2935
|
+
if (!sel)
|
|
2936
|
+
return;
|
|
2937
|
+
const root = document.querySelector(`[id="${CSS.escape(sel.blockId)}"][data-text-path="${CSS.escape(sel.path)}"]`);
|
|
2938
|
+
if (!root || !root.contains(document.activeElement))
|
|
2939
|
+
return;
|
|
2940
|
+
const range = offsetsToRange(root, sel.start, sel.end);
|
|
2941
|
+
if (!range)
|
|
2942
|
+
return;
|
|
2943
|
+
root.focus({ preventScroll: true });
|
|
2944
|
+
const domSel = document.getSelection();
|
|
2945
|
+
domSel.removeAllRanges();
|
|
2946
|
+
domSel.addRange(range);
|
|
2947
|
+
});
|
|
2948
|
+
useEffect8(() => {
|
|
2949
|
+
const domEl = blockRef.current;
|
|
2950
|
+
if (!domEl)
|
|
2951
|
+
return;
|
|
2952
|
+
const publishBlockRect = () => {
|
|
2953
|
+
const hover = engine.state.get("hover");
|
|
2954
|
+
const focus = engine.state.get("focus");
|
|
2955
|
+
const selection2 = engine.state.get("selection")?.blocks;
|
|
2956
|
+
const rect = blockRectFromBlockId(blockId);
|
|
2957
|
+
if (!rect || !engine.document.get().order.size)
|
|
2958
|
+
return;
|
|
2959
|
+
if (focus?.id === blockId) {
|
|
2960
|
+
engine.commands.tryExecute("blocks.focus", { id: blockId, rect });
|
|
2961
|
+
}
|
|
2962
|
+
if (hover?.id === blockId) {
|
|
2963
|
+
engine.commands.tryExecute("blocks.hover", { id: blockId, rect });
|
|
2964
|
+
}
|
|
2965
|
+
if (selection2?.has(blockId)) {
|
|
2966
|
+
engine.commands.tryExecute("blocks.select", {
|
|
2967
|
+
blocks: new Map(selection2.entries()).set(blockId, rect),
|
|
2968
|
+
mode: "replace"
|
|
2969
|
+
});
|
|
2970
|
+
}
|
|
2971
|
+
};
|
|
2972
|
+
const observer = new ResizeObserver(publishBlockRect);
|
|
2973
|
+
observer.observe(domEl);
|
|
2974
|
+
return () => {
|
|
2975
|
+
observer.unobserve(domEl);
|
|
2976
|
+
observer.disconnect();
|
|
2977
|
+
};
|
|
2978
|
+
}, [engine, blockId]);
|
|
2979
|
+
if (!blockId.startsWith("field") || !block)
|
|
2980
|
+
return null;
|
|
2981
|
+
return /* @__PURE__ */ jsxDEV25("div", {
|
|
2982
|
+
ref: blockRef,
|
|
2983
|
+
className: "w-full flex max-w-full items-center justify-center",
|
|
2984
|
+
children: renderer.renderField(block)
|
|
2985
|
+
}, undefined, false, undefined, this);
|
|
2517
2986
|
}
|
|
2518
2987
|
|
|
2988
|
+
// src/primitives/index.ts
|
|
2989
|
+
var FieldsPrimitives = {
|
|
2990
|
+
field: FieldPrimitive
|
|
2991
|
+
};
|
|
2992
|
+
|
|
2519
2993
|
// src/hooks/use-renderer.ts
|
|
2520
2994
|
function useRenderer() {
|
|
2521
2995
|
const engine = useEngine();
|
|
2522
|
-
return
|
|
2996
|
+
return useMemo2(() => {
|
|
2997
|
+
const ctx = {
|
|
2998
|
+
mode: "edit",
|
|
2999
|
+
styles: (type) => engine.ui.getStyle(type),
|
|
3000
|
+
events: (block) => FLC.forField(engine, block)
|
|
3001
|
+
};
|
|
3002
|
+
const renderer = new ReactRenderer(ctx, engine.document);
|
|
3003
|
+
for (const [variant, comp2] of UTILS2.ObjectEntries(FieldsPrimitives)) {
|
|
3004
|
+
if (comp2)
|
|
3005
|
+
renderer.primitives.post(variant, comp2);
|
|
3006
|
+
}
|
|
3007
|
+
return renderer;
|
|
3008
|
+
}, [engine]);
|
|
2523
3009
|
}
|
|
2524
3010
|
|
|
2525
3011
|
// src/hooks/use-flow.ts
|
|
2526
|
-
import { useEffect as
|
|
3012
|
+
import { useEffect as useEffect10 } from "react";
|
|
2527
3013
|
|
|
2528
3014
|
// src/hooks/custom/use-custom-ref.ts
|
|
2529
|
-
import { useEffect as
|
|
3015
|
+
import { useEffect as useEffect9, useRef as useRef2 } from "react";
|
|
2530
3016
|
function useCustomRef(factory) {
|
|
2531
3017
|
const isServer = typeof window === "undefined";
|
|
2532
3018
|
const getInitialValue = () => {
|
|
@@ -2538,8 +3024,8 @@ function useCustomRef(factory) {
|
|
|
2538
3024
|
return null;
|
|
2539
3025
|
}
|
|
2540
3026
|
};
|
|
2541
|
-
const ref =
|
|
2542
|
-
|
|
3027
|
+
const ref = useRef2(getInitialValue());
|
|
3028
|
+
useEffect9(() => {
|
|
2543
3029
|
try {
|
|
2544
3030
|
ref.current = typeof factory === "function" ? factory() : factory;
|
|
2545
3031
|
} catch {}
|
|
@@ -2578,7 +3064,7 @@ function useFlow() {
|
|
|
2578
3064
|
engine.commands.tryExecute("editor.rect", { editorRect: editorRectFromDomElement(flowEditor) });
|
|
2579
3065
|
return flowEditor;
|
|
2580
3066
|
});
|
|
2581
|
-
|
|
3067
|
+
useEffect10(() => {
|
|
2582
3068
|
function handleKeyDown(ev) {
|
|
2583
3069
|
if (!ev.ctrlKey || ev.key.toLocaleLowerCase() !== "z")
|
|
2584
3070
|
return;
|
|
@@ -2604,7 +3090,7 @@ function useFlow() {
|
|
|
2604
3090
|
}
|
|
2605
3091
|
};
|
|
2606
3092
|
}, [engine, coraxFlowEditorRef]);
|
|
2607
|
-
|
|
3093
|
+
useEffect10(() => {
|
|
2608
3094
|
const element = coraxFlowEditorRef.current;
|
|
2609
3095
|
if (!element)
|
|
2610
3096
|
return;
|
|
@@ -2619,12 +3105,24 @@ function useFlow() {
|
|
|
2619
3105
|
element.removeEventListener("scroll", publishEditorRect);
|
|
2620
3106
|
};
|
|
2621
3107
|
}, [engine, coraxFlowEditorRef]);
|
|
3108
|
+
useEffect10(() => {
|
|
3109
|
+
const element = coraxFlowEditorRef.current;
|
|
3110
|
+
if (!element)
|
|
3111
|
+
return;
|
|
3112
|
+
const publishEditorRect = () => {
|
|
3113
|
+
engine.commands.tryExecute("editor.rect", { editorRect: editorRectFromDomElement(element) });
|
|
3114
|
+
};
|
|
3115
|
+
window.addEventListener("resize", publishEditorRect, { passive: true });
|
|
3116
|
+
return () => {
|
|
3117
|
+
window.removeEventListener("resize", publishEditorRect);
|
|
3118
|
+
};
|
|
3119
|
+
}, [engine, coraxFlowEditorRef]);
|
|
2622
3120
|
}
|
|
2623
3121
|
|
|
2624
3122
|
// src/hooks/use-text-input.ts
|
|
2625
|
-
import { useEffect as
|
|
3123
|
+
import { useEffect as useEffect11 } from "react";
|
|
2626
3124
|
function useTextInput(engine) {
|
|
2627
|
-
|
|
3125
|
+
useEffect11(() => {
|
|
2628
3126
|
let composing = false;
|
|
2629
3127
|
const rootOf = (t) => ((t instanceof Element ? t : t?.parentElement) ?? null)?.closest("[data-text-path]") ?? null;
|
|
2630
3128
|
const onBeforeInput = (e) => {
|
|
@@ -2637,7 +3135,7 @@ function useTextInput(engine) {
|
|
|
2637
3135
|
r.setStart(tr.startContainer, tr.startOffset);
|
|
2638
3136
|
r.setEnd(tr.endContainer, tr.endOffset);
|
|
2639
3137
|
engine.commands.tryExecute("text.setSelection", {
|
|
2640
|
-
blockId: root.
|
|
3138
|
+
blockId: root.id,
|
|
2641
3139
|
path: root.dataset.textPath,
|
|
2642
3140
|
...rangeToOffsets(root, r)
|
|
2643
3141
|
});
|
|
@@ -2699,47 +3197,268 @@ function useTextInput(engine) {
|
|
|
2699
3197
|
}
|
|
2700
3198
|
|
|
2701
3199
|
// src/components/corax-flow.tsx
|
|
2702
|
-
import { cn as
|
|
2703
|
-
import { jsxDEV as
|
|
3200
|
+
import { cn as cn13 } from "cn";
|
|
3201
|
+
import { jsxDEV as jsxDEV26, Fragment as Fragment2 } from "react/jsx-dev-runtime";
|
|
2704
3202
|
"use client";
|
|
3203
|
+
var IMAGE_BREAKOUT_GUTTER = 150;
|
|
3204
|
+
function CoraxBlocks() {
|
|
3205
|
+
const engine = useEngine();
|
|
3206
|
+
const renderer = useRenderer();
|
|
3207
|
+
const order = useSyncExternalStore5((onStoreChange) => engine.state.subscribe("document", onStoreChange), () => engine.document.get().order, () => engine.document.get().order);
|
|
3208
|
+
return /* @__PURE__ */ jsxDEV26(Fragment2, {
|
|
3209
|
+
children: [...order].map((id) => {
|
|
3210
|
+
const block = engine.document.getBlock(id);
|
|
3211
|
+
if (!block)
|
|
3212
|
+
return null;
|
|
3213
|
+
const Comp = renderer.primitives.get(block.variant);
|
|
3214
|
+
if (!Comp)
|
|
3215
|
+
return null;
|
|
3216
|
+
return /* @__PURE__ */ jsxDEV26(Comp, {
|
|
3217
|
+
blockId: id
|
|
3218
|
+
}, id, false, undefined, this);
|
|
3219
|
+
})
|
|
3220
|
+
}, undefined, false, undefined, this);
|
|
3221
|
+
}
|
|
2705
3222
|
function CoraxFlow({
|
|
2706
3223
|
children,
|
|
2707
3224
|
className
|
|
2708
3225
|
}) {
|
|
2709
|
-
const [count, forceUpdate] = useReducer((x) => x + 1, 0);
|
|
2710
3226
|
const engine = useEngine();
|
|
2711
|
-
const renderer = useRenderer();
|
|
2712
3227
|
useFlow();
|
|
2713
3228
|
useTextInput(engine);
|
|
2714
|
-
|
|
2715
|
-
const disposer = engine.events.on("blocks:insert", () => {
|
|
2716
|
-
forceUpdate();
|
|
2717
|
-
});
|
|
2718
|
-
return () => disposer();
|
|
2719
|
-
}, [engine]);
|
|
2720
|
-
return /* @__PURE__ */ jsxDEV17("div", {
|
|
3229
|
+
return /* @__PURE__ */ jsxDEV26("div", {
|
|
2721
3230
|
id: "corax_flow_editor",
|
|
2722
|
-
className: "relative flex flex-col w-full
|
|
3231
|
+
className: "relative flex flex-col max-w-full w-275 h-full",
|
|
3232
|
+
children: /* @__PURE__ */ jsxDEV26("div", {
|
|
3233
|
+
id: "corax_flow_blocks_container",
|
|
3234
|
+
className: cn13("relative w-full h-full flex flex-col items-center scrollbar-none gap-1", className),
|
|
3235
|
+
style: {
|
|
3236
|
+
overflowX: "hidden",
|
|
3237
|
+
overflowY: "auto",
|
|
3238
|
+
paddingInline: IMAGE_BREAKOUT_GUTTER
|
|
3239
|
+
},
|
|
3240
|
+
children: [
|
|
3241
|
+
/* @__PURE__ */ jsxDEV26(CoraxBlocks, {}, undefined, false, undefined, this),
|
|
3242
|
+
children
|
|
3243
|
+
]
|
|
3244
|
+
}, undefined, true, undefined, this)
|
|
3245
|
+
}, undefined, false, undefined, this);
|
|
3246
|
+
}
|
|
3247
|
+
|
|
3248
|
+
// src/components/slots/maps/block-actions.tsx
|
|
3249
|
+
import { jsxDEV as jsxDEV27 } from "react/jsx-dev-runtime";
|
|
3250
|
+
function BlockActions({ className, children, ...rest }) {
|
|
3251
|
+
const focusMemo = useSlice("focus_memory");
|
|
3252
|
+
const focus = focusMemo?.blocks?.[0];
|
|
3253
|
+
const items = useSlots("block-actions");
|
|
3254
|
+
const lastPositionRef = useRef3({ active: false, top: 0, left: 0 });
|
|
3255
|
+
const block = useBlock(focus?.id ?? "");
|
|
3256
|
+
const isOpened = !!useSlice("insertion");
|
|
3257
|
+
const position = useMemo3(() => {
|
|
3258
|
+
if (!focus || !block || !isEditableField(block) || block.type === "caption") {
|
|
3259
|
+
return { active: false, top: 0, left: 0 };
|
|
3260
|
+
}
|
|
3261
|
+
const hasContent = !!block.props.children.text.length;
|
|
3262
|
+
if (hasContent) {
|
|
3263
|
+
return { active: false, top: 0, left: 0 };
|
|
3264
|
+
}
|
|
3265
|
+
const { id: firstSelectionId, rect: blockRect } = focus;
|
|
3266
|
+
const container = document.getElementById("corax_flow_blocks_container");
|
|
3267
|
+
if (!container)
|
|
3268
|
+
return { active: false, top: 0, left: 0 };
|
|
3269
|
+
const containerRect = container.getBoundingClientRect();
|
|
3270
|
+
const domElement = document.getElementById(firstSelectionId);
|
|
3271
|
+
if (!domElement)
|
|
3272
|
+
return { active: false, top: 0, left: 0 };
|
|
3273
|
+
const heightDiff = 36 - blockRect.height;
|
|
3274
|
+
const toSubstract = heightDiff / 2;
|
|
3275
|
+
const top = blockRect.top - (-toSubstract > 32 ? -8 : toSubstract) - containerRect.top - container.clientTop + blockRect.parentScrollTop;
|
|
3276
|
+
return {
|
|
3277
|
+
active: true,
|
|
3278
|
+
top,
|
|
3279
|
+
left: IMAGE_BREAKOUT_GUTTER - 44
|
|
3280
|
+
};
|
|
3281
|
+
}, [focus, block]);
|
|
3282
|
+
useEffect12(() => {
|
|
3283
|
+
if (position.active) {
|
|
3284
|
+
lastPositionRef.current = position;
|
|
3285
|
+
}
|
|
3286
|
+
}, [position]);
|
|
3287
|
+
const _position = position.active ? position : lastPositionRef.current;
|
|
3288
|
+
return /* @__PURE__ */ jsxDEV27("div", {
|
|
3289
|
+
style: {
|
|
3290
|
+
top: _position.top,
|
|
3291
|
+
left: _position.left
|
|
3292
|
+
},
|
|
3293
|
+
className: cn14("absolute top-0 left-0 gap-1 z-10 flex items-center transition-opacity", className, {
|
|
3294
|
+
"opacity-0 pointer-events-none": !position.active || !focus
|
|
3295
|
+
}),
|
|
3296
|
+
...rest,
|
|
2723
3297
|
children: [
|
|
2724
|
-
|
|
2725
|
-
|
|
2726
|
-
|
|
2727
|
-
|
|
2728
|
-
|
|
2729
|
-
|
|
2730
|
-
|
|
2731
|
-
|
|
2732
|
-
|
|
3298
|
+
/* @__PURE__ */ jsxDEV27(Slots, {
|
|
3299
|
+
slotName: "block-actions"
|
|
3300
|
+
}, undefined, false, undefined, this),
|
|
3301
|
+
/* @__PURE__ */ jsxDEV27("div", {
|
|
3302
|
+
style: {
|
|
3303
|
+
width: isOpened ? (items.length - 1) * 32 + 8 : 0
|
|
3304
|
+
},
|
|
3305
|
+
className: cn14("absolute h-9.5 -z-1 left-9 bg-popover border rounded-full transition-all duration-300 ease-damping", {
|
|
3306
|
+
"opacity-0 pointer-events-none": !isOpened
|
|
3307
|
+
})
|
|
3308
|
+
}, undefined, false, undefined, this),
|
|
3309
|
+
children
|
|
3310
|
+
]
|
|
3311
|
+
}, undefined, true, undefined, this);
|
|
3312
|
+
}
|
|
3313
|
+
// src/components/slots/maps/overlays.tsx
|
|
3314
|
+
import { jsxDEV as jsxDEV28, Fragment as Fragment3 } from "react/jsx-dev-runtime";
|
|
3315
|
+
function Overlays() {
|
|
3316
|
+
return /* @__PURE__ */ jsxDEV28(Fragment3, {
|
|
3317
|
+
children: /* @__PURE__ */ jsxDEV28(Slots, {
|
|
3318
|
+
slotName: "overlay"
|
|
3319
|
+
}, undefined, false, undefined, this)
|
|
3320
|
+
}, undefined, false, undefined, this);
|
|
3321
|
+
}
|
|
3322
|
+
// src/components/slots/maps/text-inspector.tsx
|
|
3323
|
+
import { jsxDEV as jsxDEV29 } from "react/jsx-dev-runtime";
|
|
3324
|
+
function TextInspector({ blockId }) {
|
|
3325
|
+
return /* @__PURE__ */ jsxDEV29("div", {
|
|
3326
|
+
children: blockId
|
|
3327
|
+
}, undefined, false, undefined, this);
|
|
3328
|
+
}
|
|
3329
|
+
// src/components/slots/maps/toolbar.tsx
|
|
3330
|
+
import { cn as cn15 } from "cn";
|
|
3331
|
+
import { useEffect as useEffect13, useReducer, useRef as useRef4, useState as useState5 } from "react";
|
|
3332
|
+
import { jsxDEV as jsxDEV30 } from "react/jsx-dev-runtime";
|
|
3333
|
+
var TOOLBAR_OFFSET = 44;
|
|
3334
|
+
var TOOLBAR_MARGIN = -44;
|
|
3335
|
+
var DEFAULT_STATE = { active: false, top: 0, left: 0 };
|
|
3336
|
+
function Toolbar({ className, children, ...rest }) {
|
|
3337
|
+
const items = useSlots("toolbar");
|
|
3338
|
+
const ui = useUIContext();
|
|
3339
|
+
const [toolbarWidth, setToolbarWidth] = useState5(0);
|
|
3340
|
+
const [toolbarHeight, setToolbarHeight] = useState5(0);
|
|
3341
|
+
const [, bumpViewport] = useReducer((x) => x + 1, 0);
|
|
3342
|
+
const length = items.reduce((prev, c) => {
|
|
3343
|
+
if (c.when?.(ui)) {
|
|
3344
|
+
return prev + 1;
|
|
3345
|
+
}
|
|
3346
|
+
return prev;
|
|
3347
|
+
}, 0);
|
|
3348
|
+
const textSel = useSlice("textSelection");
|
|
3349
|
+
const currentBlockId = textSel?.blockId;
|
|
3350
|
+
const selection2 = useSlice("selection");
|
|
3351
|
+
const lastPositionRef = useRef4(DEFAULT_STATE);
|
|
3352
|
+
const toolbarRef = useRef4(null);
|
|
3353
|
+
const frameRef = useRef4(0);
|
|
3354
|
+
useIsomorphicLayoutEffect(() => {
|
|
3355
|
+
const toolbarElement = toolbarRef.current;
|
|
3356
|
+
if (!toolbarElement)
|
|
3357
|
+
return;
|
|
3358
|
+
const updateToolbarSize = () => {
|
|
3359
|
+
const rect = toolbarElement.getBoundingClientRect();
|
|
3360
|
+
setToolbarWidth(rect.width);
|
|
3361
|
+
setToolbarHeight(rect.height);
|
|
3362
|
+
};
|
|
3363
|
+
updateToolbarSize();
|
|
3364
|
+
const resizeObserver = new ResizeObserver(updateToolbarSize);
|
|
3365
|
+
resizeObserver.observe(toolbarElement);
|
|
3366
|
+
return () => resizeObserver.disconnect();
|
|
3367
|
+
}, []);
|
|
3368
|
+
useEffect13(() => {
|
|
3369
|
+
const container = document.getElementById("corax_flow_blocks_container");
|
|
3370
|
+
const onViewportChange = () => {
|
|
3371
|
+
if (frameRef.current)
|
|
3372
|
+
return;
|
|
3373
|
+
frameRef.current = requestAnimationFrame(() => {
|
|
3374
|
+
frameRef.current = 0;
|
|
3375
|
+
bumpViewport();
|
|
3376
|
+
});
|
|
3377
|
+
};
|
|
3378
|
+
container?.addEventListener("scroll", onViewportChange, { passive: true });
|
|
3379
|
+
window.addEventListener("scroll", onViewportChange, { passive: true });
|
|
3380
|
+
window.addEventListener("resize", onViewportChange);
|
|
3381
|
+
return () => {
|
|
3382
|
+
if (frameRef.current)
|
|
3383
|
+
cancelAnimationFrame(frameRef.current);
|
|
3384
|
+
container?.removeEventListener("scroll", onViewportChange);
|
|
3385
|
+
window.removeEventListener("scroll", onViewportChange);
|
|
3386
|
+
window.removeEventListener("resize", onViewportChange);
|
|
3387
|
+
};
|
|
3388
|
+
}, []);
|
|
3389
|
+
const computePosition = () => {
|
|
3390
|
+
const toolbarElement = toolbarRef.current;
|
|
3391
|
+
if (!toolbarElement || toolbarWidth === 0) {
|
|
3392
|
+
return DEFAULT_STATE;
|
|
3393
|
+
}
|
|
3394
|
+
const container = document.getElementById("corax_flow_blocks_container");
|
|
3395
|
+
const containerRect = container?.getBoundingClientRect();
|
|
3396
|
+
const clampTop = (top) => {
|
|
3397
|
+
if (!containerRect)
|
|
3398
|
+
return top;
|
|
3399
|
+
const min = containerRect.top + TOOLBAR_MARGIN;
|
|
3400
|
+
const max = containerRect.bottom - TOOLBAR_MARGIN - toolbarHeight;
|
|
3401
|
+
return Math.min(Math.max(top, min), Math.max(min, max));
|
|
3402
|
+
};
|
|
3403
|
+
if (textSel && currentBlockId && textSel.start !== textSel.end) {
|
|
3404
|
+
const el = document.getElementById(textSel.blockId);
|
|
3405
|
+
const range = el ? offsetsToRange(el, textSel.start, textSel.end) : null;
|
|
3406
|
+
if (range) {
|
|
3407
|
+
const selRect = range.getBoundingClientRect();
|
|
3408
|
+
return {
|
|
3409
|
+
active: true,
|
|
3410
|
+
top: clampTop(selRect.top - TOOLBAR_OFFSET),
|
|
3411
|
+
left: selRect.left + (selRect.width - toolbarWidth) / 2
|
|
3412
|
+
};
|
|
3413
|
+
}
|
|
3414
|
+
}
|
|
3415
|
+
const rects = Array.from(selection2?.blocks?.keys() ?? []).map((id) => blockRectFromBlockId(id)).filter((rect) => !!rect);
|
|
3416
|
+
if (rects.length > 0) {
|
|
3417
|
+
const top = Math.min(...rects.map((rect) => rect.top));
|
|
3418
|
+
const left = Math.min(...rects.map((rect) => rect.left));
|
|
3419
|
+
const right = Math.max(...rects.map((rect) => rect.right));
|
|
3420
|
+
return {
|
|
3421
|
+
active: true,
|
|
3422
|
+
top: clampTop(top - TOOLBAR_OFFSET),
|
|
3423
|
+
left: (left + right) / 2 - toolbarWidth / 2
|
|
3424
|
+
};
|
|
3425
|
+
}
|
|
3426
|
+
return DEFAULT_STATE;
|
|
3427
|
+
};
|
|
3428
|
+
const position = computePosition();
|
|
3429
|
+
useEffect13(() => {
|
|
3430
|
+
if (position.active) {
|
|
3431
|
+
lastPositionRef.current = position;
|
|
3432
|
+
}
|
|
3433
|
+
}, [position]);
|
|
3434
|
+
const _position = position.active ? position : lastPositionRef.current;
|
|
3435
|
+
return /* @__PURE__ */ jsxDEV30("div", {
|
|
3436
|
+
ref: toolbarRef,
|
|
3437
|
+
style: {
|
|
3438
|
+
top: _position.top,
|
|
3439
|
+
left: _position.left
|
|
3440
|
+
},
|
|
3441
|
+
className: cn15("fixed top-0 left-0 gap-1 flex items-center transition-opacity bg-popover p-1 rounded-[12px] border", className, {
|
|
3442
|
+
"opacity-0 pointer-events-none": !position.active || !length
|
|
3443
|
+
}),
|
|
3444
|
+
...rest,
|
|
3445
|
+
children: [
|
|
3446
|
+
/* @__PURE__ */ jsxDEV30(Slots, {
|
|
3447
|
+
slotName: "toolbar"
|
|
3448
|
+
}, undefined, false, undefined, this),
|
|
3449
|
+
children
|
|
2733
3450
|
]
|
|
2734
3451
|
}, undefined, true, undefined, this);
|
|
2735
3452
|
}
|
|
2736
3453
|
|
|
3454
|
+
// src/components/slots/maps/index.ts
|
|
3455
|
+
"use client";
|
|
2737
3456
|
// src/components/index.ts
|
|
2738
3457
|
"use client";
|
|
2739
|
-
|
|
2740
|
-
var CORAX_INDEXED_DB = "coraxdb";
|
|
3458
|
+
|
|
2741
3459
|
// src/index.ts
|
|
2742
3460
|
export * from "@coorax/core";
|
|
3461
|
+
export * from "@coorax/render-react";
|
|
2743
3462
|
"use client";
|
|
2744
3463
|
export {
|
|
2745
3464
|
useUIContext,
|
|
@@ -2751,6 +3470,7 @@ export {
|
|
|
2751
3470
|
loadCompleteDocument,
|
|
2752
3471
|
getFieldTypeAndTargetId,
|
|
2753
3472
|
getBlockActionsProps,
|
|
3473
|
+
forField,
|
|
2754
3474
|
focusDomElement,
|
|
2755
3475
|
focusDomBLockById,
|
|
2756
3476
|
blockRectFromBlockId,
|
|
@@ -2761,10 +3481,16 @@ export {
|
|
|
2761
3481
|
SlotsComponentRegistry,
|
|
2762
3482
|
PrimitivesComponentsRegistry,
|
|
2763
3483
|
Overlays,
|
|
2764
|
-
|
|
3484
|
+
LocalDB,
|
|
3485
|
+
IMAGE_BREAKOUT_GUTTER,
|
|
3486
|
+
GenericRegistry3 as GenericRegistry,
|
|
3487
|
+
FieldHandlersRegistry,
|
|
3488
|
+
FieldHandlers,
|
|
2765
3489
|
FallbacksModule,
|
|
2766
3490
|
FallbackComponentsRegistry,
|
|
2767
3491
|
FLC,
|
|
3492
|
+
ErrorComponentsRegistry,
|
|
3493
|
+
CoraxIconsRegistry,
|
|
2768
3494
|
CoraxIcon,
|
|
2769
3495
|
CoraxFlow,
|
|
2770
3496
|
CoraxEngineProvider,
|