@coorax/react 0.0.0-canary.4 → 0.0.0-canary.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/commons/youtube.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/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 +1152 -701
- 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 +7 -5
- 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,6 +51,9 @@ function Button({
|
|
|
81
51
|
|
|
82
52
|
// src/components/corax-context-provider.tsx
|
|
83
53
|
import {
|
|
54
|
+
CaptionModule,
|
|
55
|
+
CodeModule,
|
|
56
|
+
DeletionModule,
|
|
84
57
|
EditorModule,
|
|
85
58
|
Engine,
|
|
86
59
|
FocusModule,
|
|
@@ -88,32 +61,140 @@ import {
|
|
|
88
61
|
HoverModule,
|
|
89
62
|
InsertionModule,
|
|
90
63
|
SelectionModule,
|
|
91
|
-
TextEditingModule
|
|
64
|
+
TextEditingModule,
|
|
65
|
+
getCollectedStyles,
|
|
66
|
+
setCoraxStyleSink
|
|
92
67
|
} from "@coorax/core";
|
|
93
|
-
import { createContext, useContext, useMemo } from "react";
|
|
68
|
+
import { createContext, useContext, useEffect, useMemo } from "react";
|
|
69
|
+
// src/registry/ui.primitives.registry.tsx
|
|
70
|
+
import { GenericRegistry as GenericRegistry2 } from "@coorax/render-react";
|
|
71
|
+
var UIPrimitivesRegistry = new GenericRegistry2;
|
|
94
72
|
|
|
95
|
-
// src/registry/
|
|
96
|
-
|
|
73
|
+
// src/registry/index.ts
|
|
74
|
+
import {
|
|
75
|
+
GenericRegistry as GenericRegistry3,
|
|
76
|
+
PrimitivesComponentsRegistry,
|
|
77
|
+
ErrorComponentsRegistry,
|
|
78
|
+
FallbackComponentsRegistry
|
|
79
|
+
} from "@coorax/render-react";
|
|
97
80
|
|
|
98
81
|
// src/components/fallbacks/image.fallback.tsx
|
|
99
82
|
import { RefreshCw } from "lucide-react";
|
|
100
83
|
import { cn as cn2 } from "cn";
|
|
101
84
|
import { jsxDEV as jsxDEV2 } from "react/jsx-dev-runtime";
|
|
102
|
-
function ImageFallback({
|
|
103
|
-
className,
|
|
104
|
-
style,
|
|
105
|
-
...props
|
|
106
|
-
}) {
|
|
85
|
+
function ImageFallback({ children, ...rest }) {
|
|
107
86
|
return /* @__PURE__ */ jsxDEV2("div", {
|
|
108
|
-
className:
|
|
109
|
-
|
|
87
|
+
className: "w-full h-[360px] flex relative pointer-events-none",
|
|
88
|
+
children: [
|
|
89
|
+
/* @__PURE__ */ jsxDEV2("div", {
|
|
90
|
+
className: cn2("w-full h-full absolute inset-0 flex gap-2 items-center justify-center bg-card"),
|
|
91
|
+
children: [
|
|
92
|
+
/* @__PURE__ */ jsxDEV2(RefreshCw, {
|
|
93
|
+
className: "animate-spin size-5"
|
|
94
|
+
}, undefined, false, undefined, this),
|
|
95
|
+
/* @__PURE__ */ jsxDEV2("span", {
|
|
96
|
+
className: "font-semibold",
|
|
97
|
+
children: rest.name
|
|
98
|
+
}, undefined, false, undefined, this)
|
|
99
|
+
]
|
|
100
|
+
}, undefined, true, undefined, this),
|
|
101
|
+
children
|
|
102
|
+
]
|
|
103
|
+
}, undefined, true, undefined, this);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// src/components/fallbacks/video.fallback.tsx
|
|
107
|
+
import { RefreshCw as RefreshCw2 } from "lucide-react";
|
|
108
|
+
import { cn as cn3 } from "cn";
|
|
109
|
+
import { jsxDEV as jsxDEV3 } from "react/jsx-dev-runtime";
|
|
110
|
+
function VideoFallback({ children, ...rest }) {
|
|
111
|
+
return /* @__PURE__ */ jsxDEV3("div", {
|
|
112
|
+
className: "w-full h-[360px] flex relative pointer-events-none",
|
|
113
|
+
children: [
|
|
114
|
+
/* @__PURE__ */ jsxDEV3("div", {
|
|
115
|
+
className: cn3("w-full h-full absolute inset-0 flex gap-2 items-center justify-center bg-card"),
|
|
116
|
+
children: [
|
|
117
|
+
/* @__PURE__ */ jsxDEV3(RefreshCw2, {
|
|
118
|
+
className: "animate-spin size-5"
|
|
119
|
+
}, undefined, false, undefined, this),
|
|
120
|
+
/* @__PURE__ */ jsxDEV3("span", {
|
|
121
|
+
className: "font-semibold",
|
|
122
|
+
children: rest.name
|
|
123
|
+
}, undefined, false, undefined, this)
|
|
124
|
+
]
|
|
125
|
+
}, undefined, true, undefined, this),
|
|
126
|
+
children,
|
|
127
|
+
/* @__PURE__ */ jsxDEV3("video", {}, undefined, false, undefined, this)
|
|
128
|
+
]
|
|
129
|
+
}, undefined, true, undefined, this);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// src/components/fallbacks/iframe.fallback.tsx
|
|
133
|
+
import { RefreshCw as RefreshCw3 } from "lucide-react";
|
|
134
|
+
import { cn as cn4 } from "cn";
|
|
135
|
+
import { jsxDEV as jsxDEV4 } from "react/jsx-dev-runtime";
|
|
136
|
+
function IFrameFallback({ children, ...rest }) {
|
|
137
|
+
return /* @__PURE__ */ jsxDEV4("div", {
|
|
138
|
+
className: "w-full h-[360px] flex relative pointer-events-none",
|
|
139
|
+
children: [
|
|
140
|
+
/* @__PURE__ */ jsxDEV4("div", {
|
|
141
|
+
className: cn4("w-full h-full absolute inset-0 flex gap-2 items-center justify-center bg-card"),
|
|
142
|
+
children: [
|
|
143
|
+
/* @__PURE__ */ jsxDEV4(RefreshCw3, {
|
|
144
|
+
className: "animate-spin size-5"
|
|
145
|
+
}, undefined, false, undefined, this),
|
|
146
|
+
/* @__PURE__ */ jsxDEV4("span", {
|
|
147
|
+
className: "font-semibold",
|
|
148
|
+
children: rest.name
|
|
149
|
+
}, undefined, false, undefined, this)
|
|
150
|
+
]
|
|
151
|
+
}, undefined, true, undefined, this),
|
|
152
|
+
children
|
|
153
|
+
]
|
|
154
|
+
}, undefined, true, undefined, this);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// src/components/fallbacks/link.fallback.tsx
|
|
158
|
+
import { cn as cn5 } from "cn";
|
|
159
|
+
import { jsxDEV as jsxDEV5 } from "react/jsx-dev-runtime";
|
|
160
|
+
function LinkFallback({ ...rest }) {
|
|
161
|
+
return /* @__PURE__ */ jsxDEV5("div", {
|
|
162
|
+
className: "w-full h-[18px] rounded-[6px] overflow-hidden flex relative pointer-events-none bg-card",
|
|
110
163
|
children: [
|
|
111
|
-
/* @__PURE__ */
|
|
112
|
-
className: "
|
|
164
|
+
/* @__PURE__ */ jsxDEV5("div", {
|
|
165
|
+
className: cn5("h-full absolute inset-0 bg-primary overflow-hidden"),
|
|
166
|
+
style: {
|
|
167
|
+
animation: "loading-skeleton 100s ease-in-out forwards"
|
|
168
|
+
},
|
|
169
|
+
children: /* @__PURE__ */ jsxDEV5("div", {
|
|
170
|
+
className: "w-full h-full bg-gradient-to-r from-transparent via-white/30 to-transparent",
|
|
171
|
+
style: {
|
|
172
|
+
animation: "loading-shimmer 1.55s ease-in-out infinite"
|
|
173
|
+
}
|
|
174
|
+
}, undefined, false, undefined, this)
|
|
113
175
|
}, undefined, false, undefined, this),
|
|
114
|
-
/* @__PURE__ */
|
|
115
|
-
className: "
|
|
116
|
-
children:
|
|
176
|
+
/* @__PURE__ */ jsxDEV5("span", {
|
|
177
|
+
className: "min-w-max absolute -translate-x-1/2 left-1/2 top-1/2 -translate-y-1/2 text-xs",
|
|
178
|
+
children: [
|
|
179
|
+
"Loading ",
|
|
180
|
+
rest.props.children.text,
|
|
181
|
+
"..."
|
|
182
|
+
]
|
|
183
|
+
}, undefined, true, undefined, this),
|
|
184
|
+
/* @__PURE__ */ jsxDEV5("style", {
|
|
185
|
+
children: `
|
|
186
|
+
@keyframes loading-skeleton {
|
|
187
|
+
0% { width: 0%; opacity: 0.7; }
|
|
188
|
+
1% { width: 60%; opacity: 1; }
|
|
189
|
+
4% { width: 90%; opacity: 0.7; }
|
|
190
|
+
90% { width: 100%; opacity: 0.7; }
|
|
191
|
+
100% { width: 100%; opacity: 0.7; }
|
|
192
|
+
}
|
|
193
|
+
@keyframes loading-shimmer {
|
|
194
|
+
0% { transform: translateX(-100%); }
|
|
195
|
+
100% { transform: translateX(100%); }
|
|
196
|
+
}
|
|
197
|
+
`
|
|
117
198
|
}, undefined, false, undefined, this)
|
|
118
199
|
]
|
|
119
200
|
}, undefined, true, undefined, this);
|
|
@@ -126,11 +207,104 @@ var FallbacksModule = {
|
|
|
126
207
|
requires: [],
|
|
127
208
|
install() {
|
|
128
209
|
FallbackComponentsRegistry.register("image", ImageFallback);
|
|
210
|
+
FallbackComponentsRegistry.register("video", VideoFallback);
|
|
211
|
+
FallbackComponentsRegistry.register("iframe", IFrameFallback);
|
|
212
|
+
FallbackComponentsRegistry.register("link", LinkFallback);
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
// src/components/errors/video.errors.tsx
|
|
217
|
+
import { AlertTriangle } from "lucide-react";
|
|
218
|
+
import { cn as cn6 } from "cn";
|
|
219
|
+
import { jsxDEV as jsxDEV6 } from "react/jsx-dev-runtime";
|
|
220
|
+
function VideoErrorComponent({ children, ...rest }) {
|
|
221
|
+
return /* @__PURE__ */ jsxDEV6("div", {
|
|
222
|
+
className: "w-full h-[360px] flex relative pointer-events-none",
|
|
223
|
+
children: [
|
|
224
|
+
/* @__PURE__ */ jsxDEV6("div", {
|
|
225
|
+
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"),
|
|
226
|
+
children: [
|
|
227
|
+
/* @__PURE__ */ jsxDEV6(AlertTriangle, {
|
|
228
|
+
className: "size-5 text-destructive"
|
|
229
|
+
}, undefined, false, undefined, this),
|
|
230
|
+
"Failed to load ",
|
|
231
|
+
/* @__PURE__ */ jsxDEV6("span", {
|
|
232
|
+
className: "font-semibold",
|
|
233
|
+
children: rest.name
|
|
234
|
+
}, undefined, false, undefined, this)
|
|
235
|
+
]
|
|
236
|
+
}, undefined, true, undefined, this),
|
|
237
|
+
children
|
|
238
|
+
]
|
|
239
|
+
}, undefined, true, undefined, this);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
// src/components/errors/image.error.tsx
|
|
243
|
+
import { AlertTriangle as AlertTriangle2 } from "lucide-react";
|
|
244
|
+
import { cn as cn7 } from "cn";
|
|
245
|
+
import { jsxDEV as jsxDEV7 } from "react/jsx-dev-runtime";
|
|
246
|
+
function ImageErrorComponent({ children, ...rest }) {
|
|
247
|
+
return /* @__PURE__ */ jsxDEV7("div", {
|
|
248
|
+
className: "w-full h-[360px] flex relative pointer-events-none",
|
|
249
|
+
children: [
|
|
250
|
+
/* @__PURE__ */ jsxDEV7("div", {
|
|
251
|
+
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"),
|
|
252
|
+
children: [
|
|
253
|
+
/* @__PURE__ */ jsxDEV7(AlertTriangle2, {
|
|
254
|
+
className: "size-5 text-destructive"
|
|
255
|
+
}, undefined, false, undefined, this),
|
|
256
|
+
"Failed to load ",
|
|
257
|
+
/* @__PURE__ */ jsxDEV7("span", {
|
|
258
|
+
className: "font-semibold",
|
|
259
|
+
children: rest.name
|
|
260
|
+
}, undefined, false, undefined, this)
|
|
261
|
+
]
|
|
262
|
+
}, undefined, true, undefined, this),
|
|
263
|
+
children
|
|
264
|
+
]
|
|
265
|
+
}, undefined, true, undefined, this);
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
// src/components/errors/iframe.error.tsx
|
|
269
|
+
import { AlertTriangle as AlertTriangle3 } from "lucide-react";
|
|
270
|
+
import { cn as cn8 } from "cn";
|
|
271
|
+
import { jsxDEV as jsxDEV8 } from "react/jsx-dev-runtime";
|
|
272
|
+
function IFrameErrorComponent({ children, ...rest }) {
|
|
273
|
+
return /* @__PURE__ */ jsxDEV8("div", {
|
|
274
|
+
className: "w-full h-[360px] flex relative pointer-events-none",
|
|
275
|
+
children: [
|
|
276
|
+
/* @__PURE__ */ jsxDEV8("div", {
|
|
277
|
+
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"),
|
|
278
|
+
children: [
|
|
279
|
+
/* @__PURE__ */ jsxDEV8(AlertTriangle3, {
|
|
280
|
+
className: "size-5 text-destructive"
|
|
281
|
+
}, undefined, false, undefined, this),
|
|
282
|
+
"Failed to load ",
|
|
283
|
+
/* @__PURE__ */ jsxDEV8("span", {
|
|
284
|
+
className: "font-semibold",
|
|
285
|
+
children: rest.name
|
|
286
|
+
}, undefined, false, undefined, this)
|
|
287
|
+
]
|
|
288
|
+
}, undefined, true, undefined, this),
|
|
289
|
+
children
|
|
290
|
+
]
|
|
291
|
+
}, undefined, true, undefined, this);
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
// src/modules/errors.module.tsx
|
|
295
|
+
var ErrorsModule = {
|
|
296
|
+
name: "errors",
|
|
297
|
+
version: "1.0.0",
|
|
298
|
+
requires: [],
|
|
299
|
+
install() {
|
|
300
|
+
ErrorComponentsRegistry.register("image", ImageErrorComponent);
|
|
301
|
+
ErrorComponentsRegistry.register("video", VideoErrorComponent);
|
|
302
|
+
ErrorComponentsRegistry.register("iframe", IFrameErrorComponent);
|
|
129
303
|
}
|
|
130
304
|
};
|
|
131
305
|
|
|
132
306
|
// src/components/corax-context-provider.tsx
|
|
133
|
-
import { jsxDEV as
|
|
307
|
+
import { jsxDEV as jsxDEV9 } from "react/jsx-dev-runtime";
|
|
134
308
|
"use client";
|
|
135
309
|
var CoraxEngineContext = createContext(null);
|
|
136
310
|
function CoraxEngineProvider({ children }) {
|
|
@@ -138,20 +312,35 @@ function CoraxEngineProvider({ children }) {
|
|
|
138
312
|
const engine2 = new Engine;
|
|
139
313
|
engine2.modules.register([
|
|
140
314
|
HistoryModule,
|
|
141
|
-
AutoSaveModule,
|
|
142
315
|
EditorModule,
|
|
143
316
|
HoverModule,
|
|
144
317
|
InsertionModule,
|
|
145
318
|
FocusModule,
|
|
146
319
|
SelectionModule,
|
|
147
320
|
TextEditingModule,
|
|
321
|
+
CodeModule,
|
|
322
|
+
CaptionModule,
|
|
323
|
+
DeletionModule,
|
|
148
324
|
SlotsModule,
|
|
149
|
-
FallbacksModule
|
|
325
|
+
FallbacksModule,
|
|
326
|
+
ErrorsModule
|
|
150
327
|
]);
|
|
151
328
|
engine2.modules.enableAll();
|
|
152
329
|
return engine2;
|
|
153
330
|
}, []);
|
|
154
|
-
|
|
331
|
+
useEffect(() => {
|
|
332
|
+
const styleEl = document.createElement("style");
|
|
333
|
+
styleEl.setAttribute("data-corax", "pseudo-styles");
|
|
334
|
+
document.head.appendChild(styleEl);
|
|
335
|
+
const dispose = setCoraxStyleSink(() => {
|
|
336
|
+
styleEl.textContent = getCollectedStyles();
|
|
337
|
+
});
|
|
338
|
+
return () => {
|
|
339
|
+
dispose();
|
|
340
|
+
styleEl.remove();
|
|
341
|
+
};
|
|
342
|
+
}, []);
|
|
343
|
+
return /* @__PURE__ */ jsxDEV9(CoraxEngineContext.Provider, {
|
|
155
344
|
value: engine,
|
|
156
345
|
children
|
|
157
346
|
}, undefined, false, undefined, this);
|
|
@@ -173,67 +362,114 @@ function useSlice(sliceName) {
|
|
|
173
362
|
}
|
|
174
363
|
|
|
175
364
|
// src/lib/slots.utils.tsx
|
|
176
|
-
import { cn as
|
|
365
|
+
import { cn as cn9 } from "cn";
|
|
177
366
|
function getBlockActionsProps(isOpen, index) {
|
|
178
367
|
return {
|
|
179
|
-
className:
|
|
368
|
+
className: cn9("absolute cursor-pointer transition-all disabled:pointer-events-none disabled:opacity-50"),
|
|
180
369
|
style: {
|
|
181
370
|
"--index": isOpen ? 0 : index,
|
|
182
|
-
"--step": isOpen ? "0px" : "
|
|
183
|
-
transform: "translateX(calc((
|
|
371
|
+
"--step": isOpen ? "0px" : "42px",
|
|
372
|
+
transform: "translateX(calc((32px*var(--index)) + var(--step))"
|
|
184
373
|
}
|
|
185
374
|
};
|
|
186
375
|
}
|
|
187
376
|
|
|
188
377
|
// src/components/slots/buttons/block-actions-button.tsx
|
|
189
|
-
import { cn as
|
|
378
|
+
import { cn as cn11 } from "cn";
|
|
190
379
|
|
|
191
380
|
// src/lib/comp.utils.tsx
|
|
192
381
|
import {
|
|
193
382
|
BoldIcon,
|
|
383
|
+
BracesIcon,
|
|
384
|
+
Captions,
|
|
385
|
+
FileTextIcon,
|
|
194
386
|
HeadingIcon,
|
|
195
387
|
ImagePlus,
|
|
196
388
|
ItalicIcon,
|
|
197
389
|
LinkIcon,
|
|
198
390
|
Minus,
|
|
391
|
+
PaletteIcon,
|
|
199
392
|
PlusIcon,
|
|
200
393
|
Pointer,
|
|
201
394
|
PointerIcon,
|
|
395
|
+
QuoteIcon,
|
|
202
396
|
TextCursor,
|
|
203
397
|
TextInitialIcon,
|
|
398
|
+
Trash2,
|
|
399
|
+
TvMinimalPlayIcon,
|
|
204
400
|
UnderlineIcon
|
|
205
401
|
} from "lucide-react";
|
|
206
|
-
|
|
402
|
+
|
|
403
|
+
// src/components/commons/youtube.tsx
|
|
404
|
+
import { cn as cn10 } from "cn";
|
|
405
|
+
import { jsxDEV as jsxDEV10 } from "react/jsx-dev-runtime";
|
|
406
|
+
function YoutubeIcon({ className, ...props }) {
|
|
407
|
+
return /* @__PURE__ */ jsxDEV10("svg", {
|
|
408
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
409
|
+
viewBox: "0 0 24 24",
|
|
410
|
+
fill: "none",
|
|
411
|
+
className: cn10("text-foreground", className),
|
|
412
|
+
...props,
|
|
413
|
+
children: /* @__PURE__ */ jsxDEV10("path", {
|
|
414
|
+
fillRule: "evenodd",
|
|
415
|
+
clipRule: "evenodd",
|
|
416
|
+
d: "M20.5949 4.45999C21.5421 4.71353 22.2865 5.45785 22.54 6.40501C22.9982 8.12001 23 11.7004 23 11.7004C23 11.7004 23 15.2807 22.54 16.9957C22.2865 17.9429 21.5421 18.6872 20.5949 18.9407C18.88 19.4007 12 19.4007 12 19.4007C12 19.4007 5.12001 19.4007 3.405 18.9407C2.45785 18.6872 1.71353 17.9429 1.45999 16.9957C1 15.2807 1 11.7004 1 11.7004C1 11.7004 1 8.12001 1.45999 6.40501C1.71353 5.45785 2.45785 4.71353 3.405 4.45999C5.12001 4 12 4 12 4C12 4 18.88 4 20.5949 4.45999ZM15.5134 11.7007L9.79788 15.0003V8.40101L15.5134 11.7007Z",
|
|
417
|
+
stroke: "currentColor",
|
|
418
|
+
strokeLinejoin: "round",
|
|
419
|
+
strokeWidth: 2
|
|
420
|
+
}, undefined, false, undefined, this)
|
|
421
|
+
}, undefined, false, undefined, this);
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
// src/lib/comp.utils.tsx
|
|
425
|
+
import { jsxDEV as jsxDEV11 } from "react/jsx-dev-runtime";
|
|
207
426
|
function CoraxIcon({ icon }) {
|
|
208
427
|
switch (icon) {
|
|
209
428
|
case "TextIcon":
|
|
210
|
-
return /* @__PURE__ */
|
|
429
|
+
return /* @__PURE__ */ jsxDEV11(TextCursor, {}, undefined, false, undefined, this);
|
|
211
430
|
case "CursorIcon":
|
|
212
|
-
return /* @__PURE__ */
|
|
431
|
+
return /* @__PURE__ */ jsxDEV11(PointerIcon, {}, undefined, false, undefined, this);
|
|
213
432
|
case "HeadingIcon":
|
|
214
|
-
return /* @__PURE__ */
|
|
433
|
+
return /* @__PURE__ */ jsxDEV11(HeadingIcon, {}, undefined, false, undefined, this);
|
|
215
434
|
case "PlusIcon":
|
|
216
|
-
return /* @__PURE__ */
|
|
435
|
+
return /* @__PURE__ */ jsxDEV11(PlusIcon, {}, undefined, false, undefined, this);
|
|
217
436
|
case "BoldIcon":
|
|
218
|
-
return /* @__PURE__ */
|
|
437
|
+
return /* @__PURE__ */ jsxDEV11(BoldIcon, {}, undefined, false, undefined, this);
|
|
219
438
|
case "ItalicIcon":
|
|
220
|
-
return /* @__PURE__ */
|
|
439
|
+
return /* @__PURE__ */ jsxDEV11(ItalicIcon, {}, undefined, false, undefined, this);
|
|
221
440
|
case "UnderlineIcon":
|
|
222
|
-
return /* @__PURE__ */
|
|
441
|
+
return /* @__PURE__ */ jsxDEV11(UnderlineIcon, {}, undefined, false, undefined, this);
|
|
223
442
|
case "LinkIcon":
|
|
224
|
-
return /* @__PURE__ */
|
|
443
|
+
return /* @__PURE__ */ jsxDEV11(LinkIcon, {}, undefined, false, undefined, this);
|
|
225
444
|
case "ImagePlus":
|
|
226
|
-
return /* @__PURE__ */
|
|
445
|
+
return /* @__PURE__ */ jsxDEV11(ImagePlus, {}, undefined, false, undefined, this);
|
|
227
446
|
case "TextInitial":
|
|
228
|
-
return /* @__PURE__ */
|
|
447
|
+
return /* @__PURE__ */ jsxDEV11(TextInitialIcon, {}, undefined, false, undefined, this);
|
|
229
448
|
case "DividerIcon":
|
|
230
|
-
return /* @__PURE__ */
|
|
449
|
+
return /* @__PURE__ */ jsxDEV11(Minus, {}, undefined, false, undefined, this);
|
|
450
|
+
case "TvMinimalPlayIcon":
|
|
451
|
+
return /* @__PURE__ */ jsxDEV11(TvMinimalPlayIcon, {}, undefined, false, undefined, this);
|
|
452
|
+
case "YoutubeIcon":
|
|
453
|
+
return /* @__PURE__ */ jsxDEV11(YoutubeIcon, {}, undefined, false, undefined, this);
|
|
454
|
+
case "FileTextIcon":
|
|
455
|
+
return /* @__PURE__ */ jsxDEV11(FileTextIcon, {}, undefined, false, undefined, this);
|
|
456
|
+
case "QuoteIcon":
|
|
457
|
+
return /* @__PURE__ */ jsxDEV11(QuoteIcon, {}, undefined, false, undefined, this);
|
|
458
|
+
case "CodeIcon":
|
|
459
|
+
return /* @__PURE__ */ jsxDEV11(BracesIcon, {}, undefined, false, undefined, this);
|
|
460
|
+
case "PaletteIcon":
|
|
461
|
+
return /* @__PURE__ */ jsxDEV11(PaletteIcon, {}, undefined, false, undefined, this);
|
|
462
|
+
case "CaptionsIcon":
|
|
463
|
+
return /* @__PURE__ */ jsxDEV11(Captions, {}, undefined, false, undefined, this);
|
|
464
|
+
case "TrashIcon":
|
|
465
|
+
return /* @__PURE__ */ jsxDEV11(Trash2, {}, undefined, false, undefined, this);
|
|
231
466
|
default:
|
|
232
|
-
return /* @__PURE__ */
|
|
467
|
+
return /* @__PURE__ */ jsxDEV11(Pointer, {}, undefined, false, undefined, this);
|
|
233
468
|
}
|
|
234
469
|
}
|
|
235
470
|
|
|
236
471
|
// src/lifecycle/fields/lifecycle.utils.ts
|
|
472
|
+
import { UTILS } from "@coorax/core";
|
|
237
473
|
function blockRectFromBlockId(id) {
|
|
238
474
|
const domElement = document.getElementById(id);
|
|
239
475
|
if (!domElement)
|
|
@@ -257,10 +493,31 @@ function blockRectFromBlockId(id) {
|
|
|
257
493
|
parentScrollTop: parentElement.scrollTop
|
|
258
494
|
};
|
|
259
495
|
}
|
|
496
|
+
function getFieldTypeAndTargetId(engine, ev, block) {
|
|
497
|
+
const target = block?.id ?? ev.currentTarget?.getAttribute("id") ?? null;
|
|
498
|
+
const fieldType = block?.type ?? ev.currentTarget?.getAttribute("data-block-type") ?? null;
|
|
499
|
+
if (!fieldType || !target) {
|
|
500
|
+
console.warn(`Failed to continue event at ${ev.type}`);
|
|
501
|
+
ev.preventDefault();
|
|
502
|
+
ev.stopPropagation();
|
|
503
|
+
return null;
|
|
504
|
+
}
|
|
505
|
+
const safeTarget = target;
|
|
506
|
+
const safeFieldType = fieldType;
|
|
507
|
+
function emit() {
|
|
508
|
+
return engine.events.emit("field:lifecycle", {
|
|
509
|
+
type: ev?._reactName || `on${UTILS.Capitalize(ev.type)}`,
|
|
510
|
+
target: safeTarget,
|
|
511
|
+
fieldType: safeFieldType,
|
|
512
|
+
cycleEvent: ev
|
|
513
|
+
});
|
|
514
|
+
}
|
|
515
|
+
return { fieldType: safeFieldType, target: safeTarget, emit };
|
|
516
|
+
}
|
|
260
517
|
|
|
261
518
|
// src/components/slots/buttons/block-actions-button.tsx
|
|
262
519
|
import React2 from "react";
|
|
263
|
-
import { jsxDEV as
|
|
520
|
+
import { jsxDEV as jsxDEV12 } from "react/jsx-dev-runtime";
|
|
264
521
|
var BlockActionButton = React2.memo(function BlockActionButton2({
|
|
265
522
|
c,
|
|
266
523
|
ui,
|
|
@@ -280,13 +537,13 @@ var BlockActionButton = React2.memo(function BlockActionButton2({
|
|
|
280
537
|
return null;
|
|
281
538
|
const { variant, size, isBaseButton = false } = c.getProps(ui);
|
|
282
539
|
const enabled = engine.commands.has(c.command);
|
|
283
|
-
return /* @__PURE__ */
|
|
540
|
+
return /* @__PURE__ */ jsxDEV12(Button, {
|
|
284
541
|
...rest,
|
|
285
542
|
variant,
|
|
286
543
|
size,
|
|
287
544
|
disabled: !enabled,
|
|
288
545
|
...!isBaseButton ? getBlockActionsProps(!isOpen, c.order ? c.order - 1 : 0) : {
|
|
289
|
-
className:
|
|
546
|
+
className: cn11("z-99 cursor-pointer transition-all", {
|
|
290
547
|
"rotate-45": isOpen
|
|
291
548
|
})
|
|
292
549
|
},
|
|
@@ -313,7 +570,7 @@ var BlockActionButton = React2.memo(function BlockActionButton2({
|
|
|
313
570
|
engine.commands.tryExecute(c.command, payload);
|
|
314
571
|
},
|
|
315
572
|
children: [
|
|
316
|
-
/* @__PURE__ */
|
|
573
|
+
/* @__PURE__ */ jsxDEV12(CoraxIcon, {
|
|
317
574
|
icon: c.icon
|
|
318
575
|
}, undefined, false, undefined, this),
|
|
319
576
|
c.label
|
|
@@ -323,7 +580,7 @@ var BlockActionButton = React2.memo(function BlockActionButton2({
|
|
|
323
580
|
|
|
324
581
|
// src/components/slots/buttons/toolbar-button.tsx
|
|
325
582
|
import React3 from "react";
|
|
326
|
-
import { jsxDEV as
|
|
583
|
+
import { jsxDEV as jsxDEV13 } from "react/jsx-dev-runtime";
|
|
327
584
|
var ToolbarButton = React3.memo(function ToolbarButton2({
|
|
328
585
|
c,
|
|
329
586
|
ui
|
|
@@ -331,15 +588,15 @@ var ToolbarButton = React3.memo(function ToolbarButton2({
|
|
|
331
588
|
const engine = useEngine();
|
|
332
589
|
const marks = useSlice("currentMarks");
|
|
333
590
|
const isActive = !!c.getProps(ui)?.isActive || marks?.find((mark) => mark.type === c.getPayload(ui).format);
|
|
334
|
-
return /* @__PURE__ */
|
|
591
|
+
return /* @__PURE__ */ jsxDEV13(Button, {
|
|
335
592
|
onClick: () => {
|
|
336
593
|
engine.commands.tryExecute(c.command, c.getPayload(ui));
|
|
337
594
|
},
|
|
338
595
|
title: c.label,
|
|
339
596
|
size: "icon-xs",
|
|
340
597
|
className: "rounded-[8px] cursor-pointer",
|
|
341
|
-
variant: isActive ? "default" : "
|
|
342
|
-
children: /* @__PURE__ */
|
|
598
|
+
variant: isActive ? "default" : "secondary",
|
|
599
|
+
children: /* @__PURE__ */ jsxDEV13(CoraxIcon, {
|
|
343
600
|
icon: c.icon
|
|
344
601
|
}, undefined, false, undefined, this)
|
|
345
602
|
}, c.id, false, undefined, this);
|
|
@@ -349,8 +606,72 @@ var ToolbarButton = React3.memo(function ToolbarButton2({
|
|
|
349
606
|
return prevActive === nextActive;
|
|
350
607
|
});
|
|
351
608
|
|
|
609
|
+
// src/components/slots/buttons/code-theme-button.tsx
|
|
610
|
+
import React4 from "react";
|
|
611
|
+
import { jsxDEV as jsxDEV14 } from "react/jsx-dev-runtime";
|
|
612
|
+
var CodeThemeButton = React4.memo(function CodeThemeButton2({
|
|
613
|
+
c,
|
|
614
|
+
ui
|
|
615
|
+
}) {
|
|
616
|
+
const engine = useEngine();
|
|
617
|
+
return /* @__PURE__ */ jsxDEV14(Button, {
|
|
618
|
+
onClick: () => engine.commands.tryExecute(c.command, c.getPayload(ui)),
|
|
619
|
+
title: c.label ?? "Toggle code theme",
|
|
620
|
+
size: "icon-xs",
|
|
621
|
+
className: "rounded-[8px] cursor-pointer",
|
|
622
|
+
variant: "secondary",
|
|
623
|
+
children: /* @__PURE__ */ jsxDEV14(CoraxIcon, {
|
|
624
|
+
icon: c.icon
|
|
625
|
+
}, undefined, false, undefined, this)
|
|
626
|
+
}, c.id, false, undefined, this);
|
|
627
|
+
});
|
|
628
|
+
|
|
629
|
+
// src/components/slots/buttons/caption-button.tsx
|
|
630
|
+
import React5 from "react";
|
|
631
|
+
import { jsxDEV as jsxDEV15 } from "react/jsx-dev-runtime";
|
|
632
|
+
var CaptionButton = React5.memo(function CaptionButton2({
|
|
633
|
+
c,
|
|
634
|
+
ui,
|
|
635
|
+
...rest
|
|
636
|
+
}) {
|
|
637
|
+
const engine = useEngine();
|
|
638
|
+
return /* @__PURE__ */ jsxDEV15(Button, {
|
|
639
|
+
...rest,
|
|
640
|
+
onClick: () => engine.commands.tryExecute(c.command, c.getPayload(ui)),
|
|
641
|
+
title: c.label ?? "Add caption",
|
|
642
|
+
size: "icon-xs",
|
|
643
|
+
className: "rounded-[8px] cursor-pointer",
|
|
644
|
+
variant: "secondary",
|
|
645
|
+
children: /* @__PURE__ */ jsxDEV15(CoraxIcon, {
|
|
646
|
+
icon: c.icon
|
|
647
|
+
}, undefined, false, undefined, this)
|
|
648
|
+
}, c.id, false, undefined, this);
|
|
649
|
+
});
|
|
650
|
+
|
|
651
|
+
// src/components/slots/buttons/delete-button.tsx
|
|
652
|
+
import React6 from "react";
|
|
653
|
+
import { jsxDEV as jsxDEV16 } from "react/jsx-dev-runtime";
|
|
654
|
+
var DeleteButton = React6.memo(function DeleteButton2({
|
|
655
|
+
c,
|
|
656
|
+
ui,
|
|
657
|
+
...rest
|
|
658
|
+
}) {
|
|
659
|
+
const engine = useEngine();
|
|
660
|
+
return /* @__PURE__ */ jsxDEV16(Button, {
|
|
661
|
+
...rest,
|
|
662
|
+
onClick: () => engine.commands.tryExecute(c.command, c.getPayload(ui)),
|
|
663
|
+
title: c.label ?? "Delete",
|
|
664
|
+
size: "icon-xs",
|
|
665
|
+
className: "rounded-[8px] cursor-pointer text-destructive",
|
|
666
|
+
variant: "secondary",
|
|
667
|
+
children: /* @__PURE__ */ jsxDEV16(CoraxIcon, {
|
|
668
|
+
icon: c.icon
|
|
669
|
+
}, undefined, false, undefined, this)
|
|
670
|
+
}, c.id, false, undefined, this);
|
|
671
|
+
});
|
|
672
|
+
|
|
352
673
|
// src/components/slots/overlays/focus-overlay.tsx
|
|
353
|
-
import { useEffect } from "react";
|
|
674
|
+
import { useEffect as useEffect2 } from "react";
|
|
354
675
|
|
|
355
676
|
// src/lib/func.utils.ts
|
|
356
677
|
function focusDomBLockById(engine, id) {
|
|
@@ -367,42 +688,51 @@ function focusDomElement(id) {
|
|
|
367
688
|
}
|
|
368
689
|
|
|
369
690
|
// src/components/slots/overlays/focus-overlay.tsx
|
|
370
|
-
import { jsxDEV as
|
|
371
|
-
function FocusOverlay({
|
|
372
|
-
|
|
691
|
+
import { jsxDEV as jsxDEV17 } from "react/jsx-dev-runtime";
|
|
692
|
+
function FocusOverlay({
|
|
693
|
+
c,
|
|
694
|
+
ui
|
|
695
|
+
}) {
|
|
696
|
+
const { position = null, hidden = null } = c.getProps(ui) ?? {};
|
|
373
697
|
const focusedId = ui.focus?.id;
|
|
374
|
-
|
|
698
|
+
useEffect2(() => {
|
|
375
699
|
if (!focusedId)
|
|
376
700
|
return;
|
|
377
701
|
focusDomElement(focusedId);
|
|
378
702
|
}, [focusedId]);
|
|
379
703
|
if (hidden || !position)
|
|
380
704
|
return null;
|
|
381
|
-
return /* @__PURE__ */
|
|
705
|
+
return /* @__PURE__ */ jsxDEV17("div", {
|
|
382
706
|
style: position,
|
|
383
707
|
className: "absolute border border-blue-700 pointer-events-none flex justify-end"
|
|
384
708
|
}, undefined, false, undefined, this);
|
|
385
709
|
}
|
|
386
710
|
|
|
387
711
|
// src/components/slots/overlays/hover-overlay.tsx
|
|
388
|
-
import { jsxDEV as
|
|
389
|
-
function HoverOverlay({
|
|
390
|
-
|
|
712
|
+
import { jsxDEV as jsxDEV18 } from "react/jsx-dev-runtime";
|
|
713
|
+
function HoverOverlay({
|
|
714
|
+
c,
|
|
715
|
+
ui
|
|
716
|
+
}) {
|
|
717
|
+
const { position = null, hidden = null } = c.getProps(ui) ?? {};
|
|
391
718
|
if (hidden || !position)
|
|
392
719
|
return null;
|
|
393
|
-
return /* @__PURE__ */
|
|
720
|
+
return /* @__PURE__ */ jsxDEV18("div", {
|
|
394
721
|
style: position,
|
|
395
722
|
className: "absolute border-[0.5px] border-blue-400 pointer-events-none flex justify-end"
|
|
396
723
|
}, undefined, false, undefined, this);
|
|
397
724
|
}
|
|
398
725
|
|
|
399
726
|
// src/components/slots/overlays/selection-overlay.tsx
|
|
400
|
-
import { jsxDEV as
|
|
401
|
-
function SelectionOverlay({
|
|
402
|
-
|
|
727
|
+
import { jsxDEV as jsxDEV19 } from "react/jsx-dev-runtime";
|
|
728
|
+
function SelectionOverlay({
|
|
729
|
+
c,
|
|
730
|
+
ui
|
|
731
|
+
}) {
|
|
732
|
+
const { position = null, hidden = null } = c.getProps(ui) ?? {};
|
|
403
733
|
if (hidden || !position)
|
|
404
734
|
return null;
|
|
405
|
-
return /* @__PURE__ */
|
|
735
|
+
return /* @__PURE__ */ jsxDEV19("div", {
|
|
406
736
|
style: position,
|
|
407
737
|
className: "absolute border border-blue-500 pointer-events-none flex justify-end"
|
|
408
738
|
}, undefined, false, undefined, this);
|
|
@@ -416,6 +746,9 @@ var SlotsModule = {
|
|
|
416
746
|
install() {
|
|
417
747
|
SlotsComponentRegistry.register("BlockActionButton", BlockActionButton);
|
|
418
748
|
SlotsComponentRegistry.register("ToolBarButton", ToolbarButton);
|
|
749
|
+
SlotsComponentRegistry.register("CodeThemeButton", CodeThemeButton);
|
|
750
|
+
SlotsComponentRegistry.register("CaptionButton", CaptionButton);
|
|
751
|
+
SlotsComponentRegistry.register("DeleteButton", DeleteButton);
|
|
419
752
|
SlotsComponentRegistry.register("SelectionOverlay", SelectionOverlay);
|
|
420
753
|
SlotsComponentRegistry.register("FocusOverlay", FocusOverlay);
|
|
421
754
|
SlotsComponentRegistry.register("HoverOverlay", HoverOverlay);
|
|
@@ -446,7 +779,8 @@ class Lexer {
|
|
|
446
779
|
"INTO",
|
|
447
780
|
"VALUES",
|
|
448
781
|
"CREATE",
|
|
449
|
-
"TABLE"
|
|
782
|
+
"TABLE",
|
|
783
|
+
"DELETE"
|
|
450
784
|
];
|
|
451
785
|
cleanWord() {
|
|
452
786
|
this.word = [];
|
|
@@ -593,7 +927,7 @@ var TYPES_DEFS_MAPPING = {
|
|
|
593
927
|
|
|
594
928
|
// src/services/localdb/parser/parser.ts
|
|
595
929
|
class Parser {
|
|
596
|
-
statementTypes = ["SELECT", "INSERT", "CREATE"];
|
|
930
|
+
statementTypes = ["SELECT", "INSERT", "CREATE", "DELETE"];
|
|
597
931
|
foundTable(tokens) {
|
|
598
932
|
return tokens.find((token, idx) => {
|
|
599
933
|
return token.type === "IDENTIFIER" && ["FROM", "INTO", "TABLE"].includes(tokens[idx - 1]?.type);
|
|
@@ -858,8 +1192,72 @@ class Parser {
|
|
|
858
1192
|
}
|
|
859
1193
|
return statements;
|
|
860
1194
|
}
|
|
1195
|
+
parseDelete(tokens) {
|
|
1196
|
+
const fromIndex = tokens.findIndex((t) => t.type === "FROM");
|
|
1197
|
+
if (fromIndex === -1) {
|
|
1198
|
+
throw new Error("Invalid DELETE statement: missing FROM clause");
|
|
1199
|
+
}
|
|
1200
|
+
if (tokens[2].type !== "IDENTIFIER") {
|
|
1201
|
+
throw new Error(`Invalid IDENTIFIER at: ${tokens[0].value}`);
|
|
1202
|
+
}
|
|
1203
|
+
const table = tokens[2].value;
|
|
1204
|
+
if (tokens[3].type === "SEMICOLON") {
|
|
1205
|
+
return {
|
|
1206
|
+
table,
|
|
1207
|
+
type: "DELETE",
|
|
1208
|
+
where: []
|
|
1209
|
+
};
|
|
1210
|
+
}
|
|
1211
|
+
let cursor = fromIndex + 2;
|
|
1212
|
+
let mainAlias;
|
|
1213
|
+
if (cursor < tokens.length) {
|
|
1214
|
+
if (tokens[cursor]?.type === "AS" && tokens[cursor + 1]?.type === "IDENTIFIER") {
|
|
1215
|
+
mainAlias = tokens[cursor + 1].value;
|
|
1216
|
+
cursor += 2;
|
|
1217
|
+
} else if (tokens[cursor]?.type === "IDENTIFIER" && !["JOIN", "INNER", "LEFT", "RIGHT", "FULL", "CROSS", "WHERE", "SEMICOLON"].includes(tokens[cursor].type)) {
|
|
1218
|
+
mainAlias = tokens[cursor].value;
|
|
1219
|
+
cursor++;
|
|
1220
|
+
}
|
|
1221
|
+
}
|
|
1222
|
+
const where = [];
|
|
1223
|
+
if (tokens[cursor]?.type === "WHERE") {
|
|
1224
|
+
cursor++;
|
|
1225
|
+
while (cursor < tokens.length) {
|
|
1226
|
+
const colToken = tokens[cursor];
|
|
1227
|
+
if (!colToken || colToken.type === "SEMICOLON")
|
|
1228
|
+
break;
|
|
1229
|
+
cursor++;
|
|
1230
|
+
const opToken = tokens[cursor];
|
|
1231
|
+
cursor++;
|
|
1232
|
+
const valToken = tokens[cursor];
|
|
1233
|
+
cursor++;
|
|
1234
|
+
if (colToken && opToken && valToken) {
|
|
1235
|
+
const colParts = colToken.value.split(".");
|
|
1236
|
+
const table2 = colParts.length > 1 ? colParts[0] : undefined;
|
|
1237
|
+
const column = colParts.length > 1 ? colParts[1] : colParts[0];
|
|
1238
|
+
where.push({
|
|
1239
|
+
table: table2,
|
|
1240
|
+
column,
|
|
1241
|
+
operator: opToken.value || "=",
|
|
1242
|
+
value: valToken.value
|
|
1243
|
+
});
|
|
1244
|
+
}
|
|
1245
|
+
if (tokens[cursor]?.type === "AND" || tokens[cursor]?.type === "OR") {
|
|
1246
|
+
cursor++;
|
|
1247
|
+
} else {
|
|
1248
|
+
break;
|
|
1249
|
+
}
|
|
1250
|
+
}
|
|
1251
|
+
}
|
|
1252
|
+
return {
|
|
1253
|
+
table,
|
|
1254
|
+
type: "DELETE",
|
|
1255
|
+
alias: mainAlias,
|
|
1256
|
+
where
|
|
1257
|
+
};
|
|
1258
|
+
}
|
|
861
1259
|
parse(tokens, params) {
|
|
862
|
-
if (tokens.length <
|
|
1260
|
+
if (tokens.length < 3) {
|
|
863
1261
|
throw new Error(`Invalid tokens array with missing elements!`);
|
|
864
1262
|
}
|
|
865
1263
|
const firstStatement = tokens[0];
|
|
@@ -873,6 +1271,9 @@ class Parser {
|
|
|
873
1271
|
if (firstStatement.type === "SELECT") {
|
|
874
1272
|
return [this.parseSelect(tokens)];
|
|
875
1273
|
}
|
|
1274
|
+
if (firstStatement.type === "DELETE") {
|
|
1275
|
+
return [this.parseDelete(tokens)];
|
|
1276
|
+
}
|
|
876
1277
|
if (firstStatement.type === "INSERT") {
|
|
877
1278
|
const stmtChunks = [];
|
|
878
1279
|
let currentChunk = [];
|
|
@@ -1330,22 +1731,66 @@ class LocalDB {
|
|
|
1330
1731
|
await this.insertData(objectStore, newData);
|
|
1331
1732
|
break;
|
|
1332
1733
|
}
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1734
|
+
case "DELETE": {
|
|
1735
|
+
const deleteReq = requests[0];
|
|
1736
|
+
const [_, primaryStore] = this.openTx(deleteReq.table, (err) => {
|
|
1737
|
+
this.isError = err;
|
|
1738
|
+
}, "readwrite");
|
|
1739
|
+
let mainRows = await this.retrieveData(primaryStore, ["*"]);
|
|
1740
|
+
if (deleteReq.where && deleteReq.where.length > 0) {
|
|
1741
|
+
mainRows = mainRows.filter((row) => {
|
|
1742
|
+
return deleteReq.where.every((cond) => {
|
|
1743
|
+
if (cond.table && cond.table !== deleteReq.table && cond.table !== deleteReq.alias) {
|
|
1744
|
+
return true;
|
|
1745
|
+
}
|
|
1746
|
+
const val = row[cond.column];
|
|
1747
|
+
if (cond.operator === "=") {
|
|
1748
|
+
return String(val) === String(cond.value);
|
|
1749
|
+
}
|
|
1750
|
+
if (cond.operator === "!=") {
|
|
1751
|
+
return String(val) !== String(cond.value);
|
|
1752
|
+
}
|
|
1753
|
+
return true;
|
|
1754
|
+
});
|
|
1755
|
+
});
|
|
1756
|
+
}
|
|
1757
|
+
for (const row of mainRows) {
|
|
1758
|
+
await this.deleteData(primaryStore, deleteReq.table, row.id);
|
|
1759
|
+
}
|
|
1760
|
+
break;
|
|
1761
|
+
}
|
|
1762
|
+
default:
|
|
1763
|
+
break;
|
|
1764
|
+
}
|
|
1765
|
+
} catch (error) {
|
|
1766
|
+
return error instanceof Error ? error : new Error(JSON.stringify(error));
|
|
1767
|
+
}
|
|
1768
|
+
}
|
|
1769
|
+
return lastResult;
|
|
1770
|
+
}
|
|
1771
|
+
async deleteData(objectStore, table, id) {
|
|
1772
|
+
return new Promise((resolve) => {
|
|
1773
|
+
try {
|
|
1774
|
+
const request = objectStore.delete(id);
|
|
1775
|
+
request.onsuccess = () => {
|
|
1776
|
+
resolve(null);
|
|
1777
|
+
};
|
|
1778
|
+
request.onerror = (event) => {
|
|
1779
|
+
const error = event.target.error || new Error(`Erreur lors de la suppression de l'élément avec l'id ${id} dans la table ${table}`);
|
|
1780
|
+
resolve(error);
|
|
1781
|
+
};
|
|
1782
|
+
} catch (error) {
|
|
1783
|
+
resolve(error instanceof Error ? error : new Error(String(error)));
|
|
1784
|
+
}
|
|
1785
|
+
});
|
|
1786
|
+
}
|
|
1787
|
+
async QueryDB(query, params) {
|
|
1788
|
+
if (!this.db)
|
|
1789
|
+
await this.init();
|
|
1790
|
+
const req = this.client.NewRequest(query, params);
|
|
1791
|
+
return this.executeQuery(req);
|
|
1792
|
+
}
|
|
1793
|
+
async MigrateDB(query) {
|
|
1349
1794
|
const statements = this.client.NewRequest(query);
|
|
1350
1795
|
const isBadReq = statements.some((s) => s.type !== "CREATE");
|
|
1351
1796
|
if (isBadReq) {
|
|
@@ -1388,9 +1833,12 @@ class LocalDB {
|
|
|
1388
1833
|
}
|
|
1389
1834
|
}
|
|
1390
1835
|
|
|
1836
|
+
// src/services/index.ts
|
|
1837
|
+
var CORAX_INDEXED_DB = "coraxdb";
|
|
1838
|
+
|
|
1391
1839
|
// src/modules/autosave.module.ts
|
|
1392
|
-
async function loadCompleteDocument(
|
|
1393
|
-
const result = await
|
|
1840
|
+
async function loadCompleteDocument(db2, documentId) {
|
|
1841
|
+
const result = await db2.QueryDB(`
|
|
1394
1842
|
SELECT * FROM documents
|
|
1395
1843
|
JOIN fields ON documents.id = fields.document_id
|
|
1396
1844
|
JOIN containers ON documents.id = containers.document_id
|
|
@@ -1416,13 +1864,13 @@ var AutoSaveModule = {
|
|
|
1416
1864
|
console.error("[WARN] indexedDB not supported or SSR");
|
|
1417
1865
|
return;
|
|
1418
1866
|
}
|
|
1419
|
-
const
|
|
1420
|
-
|
|
1867
|
+
const db2 = new LocalDB(CORAX_INDEXED_DB);
|
|
1868
|
+
db2.DeleteDB().then((err) => {
|
|
1421
1869
|
if (err) {
|
|
1422
1870
|
console.error(err);
|
|
1423
1871
|
return;
|
|
1424
1872
|
}
|
|
1425
|
-
|
|
1873
|
+
db2.MigrateDB(`
|
|
1426
1874
|
CREATE TABLE documents (
|
|
1427
1875
|
id TEXT,
|
|
1428
1876
|
version TEXT,
|
|
@@ -1483,6 +1931,9 @@ var AutoSaveModule = {
|
|
|
1483
1931
|
}).catch((e) => {
|
|
1484
1932
|
console.error(e);
|
|
1485
1933
|
});
|
|
1934
|
+
ctx.commands.register("db.query", ({ query }) => {
|
|
1935
|
+
db2.QueryDB(query);
|
|
1936
|
+
});
|
|
1486
1937
|
ctx.commands.before("blocks.insert", (p) => {
|
|
1487
1938
|
const dbState = ctx.state.get("localdbState");
|
|
1488
1939
|
if (!dbState || !dbState.isDBReady)
|
|
@@ -1497,9 +1948,9 @@ var AutoSaveModule = {
|
|
|
1497
1948
|
const saveDocument = async () => {
|
|
1498
1949
|
const documentId = jsonDocument.id;
|
|
1499
1950
|
const now = Date.now();
|
|
1500
|
-
await
|
|
1951
|
+
await db2.QueryDB(`INSERT INTO documents (id, version, order, created_at) VALUES (?, ?, ?, ?);`, [documentId, jsonDocument.version, Array.from(jsonDocument.order ?? []), now]);
|
|
1501
1952
|
for (const [fieldId, field] of Object.entries(jsonDocument.fields ?? {})) {
|
|
1502
|
-
await
|
|
1953
|
+
await db2.QueryDB(`INSERT INTO fields (id, document_id, name, tag, type, variant, containerId, props) VALUES (?, ?, ?, ?, ?, ?, ?, ?);`, [
|
|
1503
1954
|
field.id || fieldId,
|
|
1504
1955
|
documentId,
|
|
1505
1956
|
field.name ?? "",
|
|
@@ -1512,7 +1963,7 @@ var AutoSaveModule = {
|
|
|
1512
1963
|
const fieldProps = field.props ?? {};
|
|
1513
1964
|
if (fieldProps.file && (fieldProps.file instanceof Blob || typeof File !== "undefined" && fieldProps.file instanceof File)) {
|
|
1514
1965
|
const file = fieldProps.file;
|
|
1515
|
-
await
|
|
1966
|
+
await db2.QueryDB(`INSERT INTO medias (id, document_id, name, type, size, data, created_at) VALUES (?, ?, ?, ?, ?, ?, ?);`, [
|
|
1516
1967
|
`media:${field.id || fieldId}`,
|
|
1517
1968
|
documentId,
|
|
1518
1969
|
file.name ?? "unnamed",
|
|
@@ -1524,7 +1975,7 @@ var AutoSaveModule = {
|
|
|
1524
1975
|
}
|
|
1525
1976
|
}
|
|
1526
1977
|
for (const [containerId, container] of Object.entries(jsonDocument.containers ?? {})) {
|
|
1527
|
-
await
|
|
1978
|
+
await db2.QueryDB(`INSERT INTO containers (id, document_id, name, tag, type, variant, order, props) VALUES (?, ?, ?, ?, ?, ?, ?, ?);`, [
|
|
1528
1979
|
container.id || containerId,
|
|
1529
1980
|
documentId,
|
|
1530
1981
|
container.name ?? "",
|
|
@@ -1536,7 +1987,7 @@ var AutoSaveModule = {
|
|
|
1536
1987
|
]);
|
|
1537
1988
|
}
|
|
1538
1989
|
for (const [componentId, component] of Object.entries(jsonDocument.components ?? {})) {
|
|
1539
|
-
await
|
|
1990
|
+
await db2.QueryDB(`INSERT INTO components (id, document_id, name, tag, type, variant, order, count, updatedAt, createdAt, props) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);`, [
|
|
1540
1991
|
component.id || componentId,
|
|
1541
1992
|
documentId,
|
|
1542
1993
|
component.name ?? "",
|
|
@@ -1556,7 +2007,7 @@ var AutoSaveModule = {
|
|
|
1556
2007
|
}
|
|
1557
2008
|
};
|
|
1558
2009
|
// src/components/slots/maps/block-actions.tsx
|
|
1559
|
-
import { useEffect as
|
|
2010
|
+
import { useEffect as useEffect3, useMemo as useMemo2, useRef } from "react";
|
|
1560
2011
|
|
|
1561
2012
|
// src/hooks/use-slots.ts
|
|
1562
2013
|
import { useSyncExternalStore as useSyncExternalStore2 } from "react";
|
|
@@ -1568,24 +2019,19 @@ function useSlots(slotName) {
|
|
|
1568
2019
|
|
|
1569
2020
|
// src/hooks/use-registry.ts
|
|
1570
2021
|
import { useSyncExternalStore as useSyncExternalStore3 } from "react";
|
|
1571
|
-
|
|
1572
|
-
// src/registry/ui.primitives.registry.tsx
|
|
1573
|
-
var UIPrimitivesRegistry = new GenericRegistry;
|
|
1574
|
-
|
|
1575
|
-
// src/hooks/use-registry.ts
|
|
1576
2022
|
function useRegistryComponent(name) {
|
|
1577
2023
|
return useSyncExternalStore3((fn) => SlotsComponentRegistry.subscribe(name, fn), () => SlotsComponentRegistry.get(name), () => SlotsComponentRegistry.get(name));
|
|
1578
2024
|
}
|
|
1579
2025
|
|
|
1580
2026
|
// src/components/slots/slot-button.tsx
|
|
1581
|
-
import
|
|
2027
|
+
import React7 from "react";
|
|
1582
2028
|
function SlotButton({ c, ui }) {
|
|
1583
2029
|
const Comp = useRegistryComponent(c.name);
|
|
1584
2030
|
if (!Comp) {
|
|
1585
2031
|
console.warn(`No component registered for slot key "${c.name}"`);
|
|
1586
2032
|
return null;
|
|
1587
2033
|
}
|
|
1588
|
-
return
|
|
2034
|
+
return React7.createElement(Comp, {
|
|
1589
2035
|
c,
|
|
1590
2036
|
ui,
|
|
1591
2037
|
...{
|
|
@@ -1623,12 +2069,12 @@ function SlotComponent({ c, ui }) {
|
|
|
1623
2069
|
}
|
|
1624
2070
|
|
|
1625
2071
|
// src/components/slots/slots.tsx
|
|
1626
|
-
import { jsxDEV as
|
|
2072
|
+
import { jsxDEV as jsxDEV20, Fragment } from "react/jsx-dev-runtime";
|
|
1627
2073
|
function Slots({ slotName }) {
|
|
1628
2074
|
const items = useSlots(slotName);
|
|
1629
2075
|
const ui = useUIContext();
|
|
1630
|
-
return /* @__PURE__ */
|
|
1631
|
-
children: items.map((c) => /* @__PURE__ */
|
|
2076
|
+
return /* @__PURE__ */ jsxDEV20(Fragment, {
|
|
2077
|
+
children: items.map((c) => /* @__PURE__ */ jsxDEV20(SlotItem, {
|
|
1632
2078
|
c,
|
|
1633
2079
|
ui
|
|
1634
2080
|
}, c.id, false, undefined, this))
|
|
@@ -1639,12 +2085,12 @@ function SlotItem({ c, ui }) {
|
|
|
1639
2085
|
return null;
|
|
1640
2086
|
switch (c.kind) {
|
|
1641
2087
|
case "button":
|
|
1642
|
-
return /* @__PURE__ */
|
|
2088
|
+
return /* @__PURE__ */ jsxDEV20(SlotButton, {
|
|
1643
2089
|
c,
|
|
1644
2090
|
ui
|
|
1645
2091
|
}, undefined, false, undefined, this);
|
|
1646
2092
|
case "component":
|
|
1647
|
-
return /* @__PURE__ */
|
|
2093
|
+
return /* @__PURE__ */ jsxDEV20(SlotComponent, {
|
|
1648
2094
|
c,
|
|
1649
2095
|
ui
|
|
1650
2096
|
}, undefined, false, undefined, this);
|
|
@@ -1652,29 +2098,38 @@ function SlotItem({ c, ui }) {
|
|
|
1652
2098
|
}
|
|
1653
2099
|
|
|
1654
2100
|
// src/components/slots/maps/block-actions.tsx
|
|
1655
|
-
import { cn as
|
|
1656
|
-
import {
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
const { order = new Set } = documentSlice ?? {};
|
|
1662
|
-
const keys = [...blocks.keys()];
|
|
1663
|
-
const firstSelectionId = keys[0];
|
|
2101
|
+
import { cn as cn12 } from "cn";
|
|
2102
|
+
import { isEditableField } from "@coorax/core";
|
|
2103
|
+
|
|
2104
|
+
// src/hooks/use-block.ts
|
|
2105
|
+
import { useSyncExternalStore as useSyncExternalStore4 } from "react";
|
|
2106
|
+
function useBlock(id) {
|
|
1664
2107
|
const engine = useEngine();
|
|
2108
|
+
return useSyncExternalStore4((fn) => engine.document.subscribeBlock(id, fn), () => engine.document.getBlock(id), () => engine.document.getBlock(id));
|
|
2109
|
+
}
|
|
2110
|
+
|
|
2111
|
+
// src/components/slots/maps/block-actions.tsx
|
|
2112
|
+
import { jsxDEV as jsxDEV21 } from "react/jsx-dev-runtime";
|
|
2113
|
+
function BlockActions({ className, children, ...rest }) {
|
|
2114
|
+
const focusMemo = useSlice("focus_memory");
|
|
2115
|
+
const focus = focusMemo?.blocks?.[0];
|
|
2116
|
+
const items = useSlots("block-actions");
|
|
1665
2117
|
const lastPositionRef = useRef({ active: false, top: 0, left: 0 });
|
|
1666
|
-
const
|
|
2118
|
+
const block = useBlock(focus?.id ?? "");
|
|
2119
|
+
const isOpened = !!useSlice("insertion");
|
|
1667
2120
|
const position = useMemo2(() => {
|
|
1668
|
-
if (!
|
|
2121
|
+
if (!focus || !block || !isEditableField(block)) {
|
|
2122
|
+
return { active: false, top: 0, left: 0 };
|
|
2123
|
+
}
|
|
2124
|
+
const hasContent = !!block.props.children.text.length;
|
|
2125
|
+
if (hasContent) {
|
|
1669
2126
|
return { active: false, top: 0, left: 0 };
|
|
1670
2127
|
}
|
|
2128
|
+
const { id: firstSelectionId, rect: blockRect } = focus;
|
|
1671
2129
|
const container = document.getElementById("corax_flow_blocks_container");
|
|
1672
2130
|
if (!container)
|
|
1673
2131
|
return { active: false, top: 0, left: 0 };
|
|
1674
2132
|
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
2133
|
const domElement = document.getElementById(firstSelectionId);
|
|
1679
2134
|
if (!domElement)
|
|
1680
2135
|
return { active: false, top: 0, left: 0 };
|
|
@@ -1686,49 +2141,57 @@ function BlockActions({ className, children, ...rest }) {
|
|
|
1686
2141
|
top,
|
|
1687
2142
|
left: 0
|
|
1688
2143
|
};
|
|
1689
|
-
}, [
|
|
1690
|
-
|
|
2144
|
+
}, [focus, block]);
|
|
2145
|
+
useEffect3(() => {
|
|
1691
2146
|
if (position.active) {
|
|
1692
2147
|
lastPositionRef.current = position;
|
|
1693
2148
|
}
|
|
1694
2149
|
}, [position]);
|
|
1695
2150
|
const _position = position.active ? position : lastPositionRef.current;
|
|
1696
|
-
return /* @__PURE__ */
|
|
2151
|
+
return /* @__PURE__ */ jsxDEV21("div", {
|
|
1697
2152
|
style: {
|
|
1698
2153
|
top: _position.top,
|
|
1699
2154
|
left: _position.left
|
|
1700
2155
|
},
|
|
1701
|
-
className:
|
|
1702
|
-
"opacity-0 pointer-events-none": !
|
|
2156
|
+
className: cn12("absolute top-0 left-0 gap-1 z-10 flex items-center transition-opacity", className, {
|
|
2157
|
+
"opacity-0 pointer-events-none": !position.active || !focus
|
|
1703
2158
|
}),
|
|
1704
2159
|
...rest,
|
|
1705
2160
|
children: [
|
|
1706
|
-
/* @__PURE__ */
|
|
2161
|
+
/* @__PURE__ */ jsxDEV21(Slots, {
|
|
1707
2162
|
slotName: "block-actions"
|
|
1708
2163
|
}, undefined, false, undefined, this),
|
|
2164
|
+
/* @__PURE__ */ jsxDEV21("div", {
|
|
2165
|
+
style: {
|
|
2166
|
+
width: isOpened ? (items.length - 1) * 32 + 8 : 0
|
|
2167
|
+
},
|
|
2168
|
+
className: cn12("absolute h-9.5 -z-1 left-9 bg-popover border rounded-full transition-all duration-300 ease-damping", {
|
|
2169
|
+
"opacity-0 pointer-events-none": !isOpened
|
|
2170
|
+
})
|
|
2171
|
+
}, undefined, false, undefined, this),
|
|
1709
2172
|
children
|
|
1710
2173
|
]
|
|
1711
2174
|
}, undefined, true, undefined, this);
|
|
1712
2175
|
}
|
|
1713
2176
|
// src/components/slots/maps/overlays.tsx
|
|
1714
|
-
import { jsxDEV as
|
|
2177
|
+
import { jsxDEV as jsxDEV22, Fragment as Fragment2 } from "react/jsx-dev-runtime";
|
|
1715
2178
|
function Overlays() {
|
|
1716
|
-
return /* @__PURE__ */
|
|
1717
|
-
children: /* @__PURE__ */
|
|
2179
|
+
return /* @__PURE__ */ jsxDEV22(Fragment2, {
|
|
2180
|
+
children: /* @__PURE__ */ jsxDEV22(Slots, {
|
|
1718
2181
|
slotName: "overlay"
|
|
1719
2182
|
}, undefined, false, undefined, this)
|
|
1720
2183
|
}, undefined, false, undefined, this);
|
|
1721
2184
|
}
|
|
1722
2185
|
// src/components/slots/maps/text-inspector.tsx
|
|
1723
|
-
import { jsxDEV as
|
|
2186
|
+
import { jsxDEV as jsxDEV23 } from "react/jsx-dev-runtime";
|
|
1724
2187
|
function TextInspector({ blockId }) {
|
|
1725
|
-
return /* @__PURE__ */
|
|
2188
|
+
return /* @__PURE__ */ jsxDEV23("div", {
|
|
1726
2189
|
children: blockId
|
|
1727
2190
|
}, undefined, false, undefined, this);
|
|
1728
2191
|
}
|
|
1729
2192
|
// src/components/slots/maps/toolbar.tsx
|
|
1730
|
-
import { cn as
|
|
1731
|
-
import { useRef as useRef2, useMemo as useMemo3, useEffect as
|
|
2193
|
+
import { cn as cn13 } from "cn";
|
|
2194
|
+
import { useRef as useRef2, useMemo as useMemo3, useEffect as useEffect5, useState } from "react";
|
|
1732
2195
|
|
|
1733
2196
|
// src/lib/selection.utils.ts
|
|
1734
2197
|
function rangeToOffsets(root, range) {
|
|
@@ -1761,61 +2224,88 @@ function offsetsToRange(root, start, end) {
|
|
|
1761
2224
|
}
|
|
1762
2225
|
return null;
|
|
1763
2226
|
}
|
|
1764
|
-
|
|
2227
|
+
// src/hooks/custom/use-isomorphic-layout-effect.ts
|
|
2228
|
+
import { useEffect as useEffect4, useLayoutEffect } from "react";
|
|
2229
|
+
var useIsomorphicLayoutEffect = typeof window !== "undefined" ? useLayoutEffect : useEffect4;
|
|
1765
2230
|
// src/components/slots/maps/toolbar.tsx
|
|
1766
|
-
import { jsxDEV as
|
|
1767
|
-
var TOOLBAR_OFFSET =
|
|
2231
|
+
import { jsxDEV as jsxDEV24 } from "react/jsx-dev-runtime";
|
|
2232
|
+
var TOOLBAR_OFFSET = 44;
|
|
1768
2233
|
var DEFAULT_STATE = { active: false, top: 0, left: 0 };
|
|
1769
2234
|
function Toolbar({ className, children, ...rest }) {
|
|
2235
|
+
const items = useSlots("toolbar");
|
|
2236
|
+
const ui = useUIContext();
|
|
2237
|
+
const [toolbarWidth, setToolbarWidth] = useState(0);
|
|
2238
|
+
const length = items.reduce((prev, c) => {
|
|
2239
|
+
if (c.when?.(ui)) {
|
|
2240
|
+
return prev + 1;
|
|
2241
|
+
}
|
|
2242
|
+
return prev;
|
|
2243
|
+
}, 0);
|
|
1770
2244
|
const textSel = useSlice("textSelection");
|
|
1771
2245
|
const currentBlockId = textSel?.blockId;
|
|
1772
|
-
const
|
|
1773
|
-
const { order = new Set } = documentSlice ?? {};
|
|
1774
|
-
const engine = useEngine();
|
|
2246
|
+
const selection = useSlice("selection");
|
|
1775
2247
|
const lastPositionRef = useRef2(DEFAULT_STATE);
|
|
1776
2248
|
const toolbarRef = useRef2(null);
|
|
2249
|
+
useIsomorphicLayoutEffect(() => {
|
|
2250
|
+
const toolbarElement = toolbarRef.current;
|
|
2251
|
+
if (!toolbarElement)
|
|
2252
|
+
return;
|
|
2253
|
+
const updateToolbarWidth = () => {
|
|
2254
|
+
setToolbarWidth(toolbarElement.getBoundingClientRect().width);
|
|
2255
|
+
};
|
|
2256
|
+
updateToolbarWidth();
|
|
2257
|
+
const resizeObserver = new ResizeObserver(updateToolbarWidth);
|
|
2258
|
+
resizeObserver.observe(toolbarElement);
|
|
2259
|
+
return () => resizeObserver.disconnect();
|
|
2260
|
+
}, []);
|
|
1777
2261
|
const position = useMemo3(() => {
|
|
1778
2262
|
const toolbarElement = toolbarRef.current;
|
|
1779
|
-
if (!
|
|
2263
|
+
if (!toolbarElement || toolbarWidth === 0) {
|
|
1780
2264
|
return DEFAULT_STATE;
|
|
1781
2265
|
}
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
2266
|
+
if (textSel && currentBlockId && textSel.start !== textSel.end) {
|
|
2267
|
+
const el = document.getElementById(textSel.blockId);
|
|
2268
|
+
const range = el ? offsetsToRange(el, textSel.start, textSel.end) : null;
|
|
2269
|
+
if (range) {
|
|
2270
|
+
const selRect = range.getBoundingClientRect();
|
|
2271
|
+
return {
|
|
2272
|
+
active: true,
|
|
2273
|
+
top: selRect.top - TOOLBAR_OFFSET,
|
|
2274
|
+
left: selRect.left + (selRect.width - toolbarWidth) / 2
|
|
2275
|
+
};
|
|
2276
|
+
}
|
|
2277
|
+
}
|
|
2278
|
+
const rects = Array.from(selection?.blocks?.values() ?? []);
|
|
2279
|
+
if (rects.length > 0) {
|
|
2280
|
+
const top = Math.min(...rects.map((rect) => rect.top));
|
|
2281
|
+
const left = Math.min(...rects.map((rect) => rect.left));
|
|
2282
|
+
const right = Math.max(...rects.map((rect) => rect.right));
|
|
2283
|
+
return {
|
|
2284
|
+
active: true,
|
|
2285
|
+
top: top - TOOLBAR_OFFSET,
|
|
2286
|
+
left: (left + right) / 2 - toolbarWidth / 2
|
|
2287
|
+
};
|
|
2288
|
+
}
|
|
2289
|
+
return DEFAULT_STATE;
|
|
2290
|
+
}, [currentBlockId, textSel, selection, toolbarWidth]);
|
|
2291
|
+
useEffect5(() => {
|
|
1802
2292
|
if (position.active) {
|
|
1803
2293
|
lastPositionRef.current = position;
|
|
1804
2294
|
}
|
|
1805
2295
|
}, [position]);
|
|
1806
2296
|
const _position = position.active ? position : lastPositionRef.current;
|
|
1807
|
-
return /* @__PURE__ */
|
|
2297
|
+
return /* @__PURE__ */ jsxDEV24("div", {
|
|
1808
2298
|
ref: toolbarRef,
|
|
1809
2299
|
style: {
|
|
1810
2300
|
top: _position.top,
|
|
1811
2301
|
left: _position.left
|
|
1812
2302
|
},
|
|
1813
|
-
className:
|
|
1814
|
-
"opacity-0 pointer-events-none": !
|
|
2303
|
+
className: cn13("fixed top-0 left-0 gap-1 flex items-center transition-all bg-popover p-1 rounded-[12px] border", className, {
|
|
2304
|
+
"opacity-0 pointer-events-none": !position.active || !length
|
|
1815
2305
|
}),
|
|
1816
2306
|
...rest,
|
|
1817
2307
|
children: [
|
|
1818
|
-
/* @__PURE__ */
|
|
2308
|
+
/* @__PURE__ */ jsxDEV24(Slots, {
|
|
1819
2309
|
slotName: "toolbar"
|
|
1820
2310
|
}, undefined, false, undefined, this),
|
|
1821
2311
|
children
|
|
@@ -1826,152 +2316,42 @@ function Toolbar({ className, children, ...rest }) {
|
|
|
1826
2316
|
// src/components/slots/maps/index.ts
|
|
1827
2317
|
"use client";
|
|
1828
2318
|
// src/components/corax-flow.tsx
|
|
1829
|
-
import { useEffect as
|
|
2319
|
+
import { useEffect as useEffect10, useReducer } from "react";
|
|
1830
2320
|
|
|
1831
2321
|
// src/hooks/use-renderer.ts
|
|
1832
2322
|
import { useMemo as useMemo4 } from "react";
|
|
2323
|
+
import { ReactRenderer } from "@coorax/render-react";
|
|
2324
|
+
import { UTILS as UTILS2 } from "@coorax/core";
|
|
1833
2325
|
|
|
1834
|
-
// src/
|
|
1835
|
-
import
|
|
1836
|
-
import {
|
|
1837
|
-
UTILS as UTILS3,
|
|
1838
|
-
segments
|
|
1839
|
-
} from "@coorax/core";
|
|
1840
|
-
|
|
1841
|
-
// src/registry/primitives.registry.tsx
|
|
1842
|
-
class PrimitivesComponentsRegistry {
|
|
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
|
-
}
|
|
2326
|
+
// src/lifecycle/fields/handlers.registry.ts
|
|
2327
|
+
import { GenericRegistry as GenericRegistry4 } from "@coorax/render-react";
|
|
1956
2328
|
|
|
1957
|
-
// src/
|
|
1958
|
-
var
|
|
1959
|
-
|
|
2329
|
+
// src/lifecycle/fields/common/focus.events/onblur.ts
|
|
2330
|
+
var createOnBlur = async (engine, block, ev) => {
|
|
2331
|
+
const fieldInfo = getFieldTypeAndTargetId(engine, ev, block);
|
|
2332
|
+
if (!fieldInfo)
|
|
2333
|
+
return;
|
|
2334
|
+
const textSel = engine.state.get("textSelection");
|
|
2335
|
+
if (textSel && textSel.start !== textSel.end)
|
|
2336
|
+
return;
|
|
2337
|
+
engine.commands.tryExecute("blocks.focus", null);
|
|
2338
|
+
await fieldInfo.emit();
|
|
1960
2339
|
};
|
|
1961
2340
|
|
|
1962
|
-
// src/
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
UTILS
|
|
1970
|
-
} from "@coorax/core";
|
|
2341
|
+
// src/lifecycle/fields/common/focus.events/onfocus.ts
|
|
2342
|
+
var createOnFocus = async (engine, block, ev) => {
|
|
2343
|
+
const fieldInfo = getFieldTypeAndTargetId(engine, ev, block);
|
|
2344
|
+
if (!fieldInfo)
|
|
2345
|
+
return;
|
|
2346
|
+
await fieldInfo.emit();
|
|
2347
|
+
};
|
|
1971
2348
|
|
|
1972
|
-
// src/lifecycle/fields/mouse.events/onclick.ts
|
|
2349
|
+
// src/lifecycle/fields/common/mouse.events/onclick.ts
|
|
1973
2350
|
var createOnClick = async (engine, block, ev) => {
|
|
1974
2351
|
ev.stopPropagation();
|
|
2352
|
+
if (block.type === "iframe") {
|
|
2353
|
+
ev.preventDefault();
|
|
2354
|
+
}
|
|
1975
2355
|
const fieldInfo = getFieldTypeAndTargetId(engine, ev, block);
|
|
1976
2356
|
if (!fieldInfo)
|
|
1977
2357
|
return;
|
|
@@ -2026,44 +2406,23 @@ var createOnClick = async (engine, block, ev) => {
|
|
|
2026
2406
|
await fieldInfo.emit();
|
|
2027
2407
|
};
|
|
2028
2408
|
|
|
2029
|
-
// src/lifecycle/fields/mouse.events/
|
|
2030
|
-
var
|
|
2031
|
-
ev.stopPropagation();
|
|
2409
|
+
// src/lifecycle/fields/common/mouse.events/onmouseenter.ts
|
|
2410
|
+
var createOnMouseEnter = async (engine, block, ev) => {
|
|
2032
2411
|
const fieldInfo = getFieldTypeAndTargetId(engine, ev, block);
|
|
2033
2412
|
if (!fieldInfo)
|
|
2034
2413
|
return;
|
|
2035
|
-
const
|
|
2036
|
-
if (
|
|
2037
|
-
return;
|
|
2038
|
-
const focus = engine.state.get("focus");
|
|
2039
|
-
if (focus?.id === block.id) {
|
|
2414
|
+
const selection = engine.state.get("selection");
|
|
2415
|
+
if (selection && selection.blocks.has(block.id)) {
|
|
2040
2416
|
return;
|
|
2041
2417
|
}
|
|
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)
|
|
2418
|
+
const rect = blockRectFromBlockId(block.id);
|
|
2419
|
+
if (!rect)
|
|
2061
2420
|
return;
|
|
2062
|
-
engine.commands.tryExecute("blocks.
|
|
2421
|
+
engine.commands.tryExecute("blocks.hover", { id: block.id, rect });
|
|
2063
2422
|
await fieldInfo.emit();
|
|
2064
2423
|
};
|
|
2065
2424
|
|
|
2066
|
-
// src/lifecycle/fields/mouse.events/onmouseleave.ts
|
|
2425
|
+
// src/lifecycle/fields/common/mouse.events/onmouseleave.ts
|
|
2067
2426
|
var createOnMouseLeave = async (engine, block, ev) => {
|
|
2068
2427
|
const fieldInfo = getFieldTypeAndTargetId(engine, ev, block);
|
|
2069
2428
|
if (!fieldInfo)
|
|
@@ -2077,28 +2436,86 @@ var createOnMouseLeave = async (engine, block, ev) => {
|
|
|
2077
2436
|
await fieldInfo.emit();
|
|
2078
2437
|
};
|
|
2079
2438
|
|
|
2080
|
-
// src/lifecycle/fields/
|
|
2081
|
-
|
|
2439
|
+
// src/lifecycle/fields/common/handlers.ts
|
|
2440
|
+
function buildCommonHandlers(engine, block) {
|
|
2441
|
+
return {
|
|
2442
|
+
onClick: createOnClick.bind(null, engine, block),
|
|
2443
|
+
onMouseEnter: createOnMouseEnter.bind(null, engine, block),
|
|
2444
|
+
onMouseLeave: createOnMouseLeave.bind(null, engine, block),
|
|
2445
|
+
onFocus: createOnFocus.bind(null, engine, block),
|
|
2446
|
+
onBlur: createOnBlur.bind(null, engine, block)
|
|
2447
|
+
};
|
|
2448
|
+
}
|
|
2449
|
+
|
|
2450
|
+
// src/lifecycle/fields/divider/keyboard.events/onkeydown.ts
|
|
2451
|
+
import { FieldsUtils } from "@coorax/core";
|
|
2452
|
+
var createOnKeyDown = async (engine, block, ev) => {
|
|
2082
2453
|
const fieldInfo = getFieldTypeAndTargetId(engine, ev, block);
|
|
2083
2454
|
if (!fieldInfo)
|
|
2084
2455
|
return;
|
|
2085
|
-
|
|
2086
|
-
if (selection && selection.blocks.has(block.id)) {
|
|
2456
|
+
if (ev.ctrlKey || ev.metaKey)
|
|
2087
2457
|
return;
|
|
2088
|
-
|
|
2089
|
-
const
|
|
2090
|
-
|
|
2458
|
+
const tree = engine.document.get();
|
|
2459
|
+
const normalizedTarget = fieldInfo.target;
|
|
2460
|
+
const hasCurrentElement = engine.document.has(normalizedTarget);
|
|
2461
|
+
if (!hasCurrentElement) {
|
|
2462
|
+
console.warn(`Ignoring stale field target: ${normalizedTarget}`);
|
|
2091
2463
|
return;
|
|
2092
|
-
|
|
2093
|
-
|
|
2464
|
+
}
|
|
2465
|
+
const targetIndex = [...tree.order].indexOf(normalizedTarget);
|
|
2466
|
+
const index = targetIndex + 1;
|
|
2467
|
+
const currentTarget = ev.currentTarget;
|
|
2468
|
+
if (ev.key === "Enter" && !ev.shiftKey) {
|
|
2469
|
+
ev.preventDefault();
|
|
2470
|
+
currentTarget.blur();
|
|
2471
|
+
const newField = FieldsUtils.NewField("text");
|
|
2472
|
+
engine.commands.tryExecute("blocks.insert", { block: newField, pos: index });
|
|
2473
|
+
await fieldInfo.emit();
|
|
2474
|
+
const blockRect = blockRectFromBlockId(newField.id);
|
|
2475
|
+
if (!blockRect)
|
|
2476
|
+
return;
|
|
2477
|
+
engine.commands.tryExecute("blocks.focus", { id: newField.id, rect: blockRect });
|
|
2478
|
+
}
|
|
2479
|
+
if (ev.key === "ArrowUp" || ev.key === "ArrowDown" || ev.key === "Tab") {
|
|
2480
|
+
ev.preventDefault();
|
|
2481
|
+
const mustBeNegativeDelta = ev.key === "ArrowUp" || ev.key === "Tab" && ev.shiftKey;
|
|
2482
|
+
const delta = mustBeNegativeDelta ? -1 : 1;
|
|
2483
|
+
const currentTree = engine.document.get();
|
|
2484
|
+
const blockIndex = Array.from(currentTree.order).indexOf(block.id);
|
|
2485
|
+
if (blockIndex === -1)
|
|
2486
|
+
return;
|
|
2487
|
+
if (blockIndex === 0 && delta < 0)
|
|
2488
|
+
return;
|
|
2489
|
+
if (blockIndex === currentTree.order.size - 1 && delta > 0)
|
|
2490
|
+
return;
|
|
2491
|
+
const rectId = [...currentTree.order][blockIndex + delta];
|
|
2492
|
+
const rect = blockRectFromBlockId(rectId);
|
|
2493
|
+
if (!rect) {
|
|
2494
|
+
return;
|
|
2495
|
+
}
|
|
2496
|
+
currentTarget.blur();
|
|
2497
|
+
engine.commands.tryExecute("blocks.focus", { id: rectId, rect });
|
|
2498
|
+
}
|
|
2499
|
+
if (ev.key === "Escape") {
|
|
2500
|
+
ev.preventDefault();
|
|
2501
|
+
currentTarget.blur();
|
|
2502
|
+
engine.commands.tryExecute("blocks.select", { blocks: new Map, mode: "replace" });
|
|
2503
|
+
}
|
|
2094
2504
|
};
|
|
2095
2505
|
|
|
2096
|
-
// src/lifecycle/fields/
|
|
2506
|
+
// src/lifecycle/fields/divider/handlers.ts
|
|
2507
|
+
function buildDividerHandlers(engine, block) {
|
|
2508
|
+
return {
|
|
2509
|
+
...buildCommonHandlers(engine, block),
|
|
2510
|
+
onKeyDown: createOnKeyDown.bind(null, engine, block)
|
|
2511
|
+
};
|
|
2512
|
+
}
|
|
2513
|
+
|
|
2514
|
+
// src/lifecycle/fields/editable/keyboard.events/onkeydown.ts
|
|
2097
2515
|
import {
|
|
2098
|
-
FieldsUtils
|
|
2099
|
-
isEditableField
|
|
2516
|
+
FieldsUtils as FieldsUtils2
|
|
2100
2517
|
} from "@coorax/core";
|
|
2101
|
-
var
|
|
2518
|
+
var createOnKeyDown2 = async (engine, block, ev) => {
|
|
2102
2519
|
const fieldInfo = getFieldTypeAndTargetId(engine, ev, block);
|
|
2103
2520
|
if (!fieldInfo)
|
|
2104
2521
|
return;
|
|
@@ -2117,7 +2534,7 @@ var createOnKeyDown = async (engine, block, ev) => {
|
|
|
2117
2534
|
if (ev.key === "Enter" && !ev.shiftKey) {
|
|
2118
2535
|
ev.preventDefault();
|
|
2119
2536
|
currentTarget.blur();
|
|
2120
|
-
const newField =
|
|
2537
|
+
const newField = FieldsUtils2.NewField("text");
|
|
2121
2538
|
engine.commands.tryExecute("blocks.insert", { block: newField, pos: index });
|
|
2122
2539
|
await fieldInfo.emit();
|
|
2123
2540
|
const blockRect = blockRectFromBlockId(newField.id);
|
|
@@ -2148,44 +2565,50 @@ var createOnKeyDown = async (engine, block, ev) => {
|
|
|
2148
2565
|
if (ev.key === "Escape") {
|
|
2149
2566
|
ev.preventDefault();
|
|
2150
2567
|
currentTarget.blur();
|
|
2151
|
-
|
|
2152
|
-
engine.commands.tryExecute("blocks.select", { blocks: new Map, mode: "replace" });
|
|
2153
|
-
}
|
|
2568
|
+
engine.commands.tryExecute("blocks.focus", null);
|
|
2154
2569
|
}
|
|
2155
2570
|
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 {
|
|
2571
|
+
const textContent = block.props.children.text;
|
|
2572
|
+
if (textContent.length === 0) {
|
|
2573
|
+
const order = [...engine.document.get().order];
|
|
2574
|
+
const curBlockIndex = order.findIndex((id) => id === block.id);
|
|
2575
|
+
const prevSiblingBlock = engine.document.getBlock(order[curBlockIndex - 1]);
|
|
2576
|
+
if (prevSiblingBlock) {
|
|
2577
|
+
const blockRect = blockRectFromBlockId(prevSiblingBlock.id);
|
|
2578
|
+
if (!blockRect) {
|
|
2180
2579
|
engine.commands.tryExecute("blocks.focus", null);
|
|
2580
|
+
return;
|
|
2181
2581
|
}
|
|
2182
|
-
engine.commands.tryExecute("blocks.
|
|
2582
|
+
engine.commands.tryExecute("blocks.focus", {
|
|
2583
|
+
id: prevSiblingBlock.id,
|
|
2584
|
+
rect: blockRect
|
|
2585
|
+
});
|
|
2586
|
+
} else {
|
|
2587
|
+
engine.commands.tryExecute("blocks.focus", null);
|
|
2183
2588
|
}
|
|
2589
|
+
engine.commands.tryExecute("blocks.delete", { blockId: block.id });
|
|
2184
2590
|
}
|
|
2185
2591
|
}
|
|
2186
2592
|
};
|
|
2187
2593
|
|
|
2188
|
-
// src/lifecycle/fields/
|
|
2594
|
+
// src/lifecycle/fields/editable/mouse.events/ondoubleclick.ts
|
|
2595
|
+
var createOnDoubleClick = async (engine, block, ev) => {
|
|
2596
|
+
ev.stopPropagation();
|
|
2597
|
+
const fieldInfo = getFieldTypeAndTargetId(engine, ev, block);
|
|
2598
|
+
if (!fieldInfo)
|
|
2599
|
+
return;
|
|
2600
|
+
const rect = blockRectFromBlockId(block.id);
|
|
2601
|
+
if (!rect)
|
|
2602
|
+
return;
|
|
2603
|
+
const focus = engine.state.get("focus");
|
|
2604
|
+
if (focus?.id === block.id) {
|
|
2605
|
+
return;
|
|
2606
|
+
}
|
|
2607
|
+
engine.commands.tryExecute("blocks.focus", { id: block.id, rect });
|
|
2608
|
+
await fieldInfo.emit();
|
|
2609
|
+
};
|
|
2610
|
+
|
|
2611
|
+
// src/lifecycle/fields/editable/synthetic.events/onselect.ts
|
|
2189
2612
|
var createOnSelect = async (engine, block, ev) => {
|
|
2190
2613
|
const fieldInfo = getFieldTypeAndTargetId(engine, ev, block);
|
|
2191
2614
|
if (!fieldInfo)
|
|
@@ -2215,318 +2638,329 @@ var createOnSelect = async (engine, block, ev) => {
|
|
|
2215
2638
|
await fieldInfo.emit();
|
|
2216
2639
|
};
|
|
2217
2640
|
|
|
2218
|
-
// src/lifecycle/fields/
|
|
2641
|
+
// src/lifecycle/fields/editable/handlers.ts
|
|
2642
|
+
function buildEditableHandlers(engine, block) {
|
|
2643
|
+
return {
|
|
2644
|
+
...buildCommonHandlers(engine, block),
|
|
2645
|
+
onKeyDown: createOnKeyDown2.bind(null, engine, block),
|
|
2646
|
+
onDoubleClick: createOnDoubleClick.bind(null, engine, block),
|
|
2647
|
+
onSelect: createOnSelect.bind(null, engine, block)
|
|
2648
|
+
};
|
|
2649
|
+
}
|
|
2650
|
+
|
|
2651
|
+
// src/lifecycle/fields/media/image/synthetic.events/onload.ts
|
|
2219
2652
|
var createOnLoad = async (engine, block, ev) => {
|
|
2220
2653
|
const fieldInfo = getFieldTypeAndTargetId(engine, ev, block);
|
|
2221
|
-
if (!fieldInfo)
|
|
2654
|
+
if (!fieldInfo || !block.props?.src?.trim())
|
|
2222
2655
|
return;
|
|
2223
|
-
|
|
2656
|
+
engine.document.apply((tree) => engine.mutations.mutateField(tree, {
|
|
2657
|
+
id: block.id,
|
|
2658
|
+
keyValuePairs: {
|
|
2659
|
+
"props.isLoaded": true
|
|
2660
|
+
}
|
|
2661
|
+
}), { origin: "history" });
|
|
2662
|
+
engine.commands.tryExecute("blocks.select", {
|
|
2663
|
+
blocks: new Map().set(block.id, blockRectFromBlockId(block.id))
|
|
2664
|
+
});
|
|
2224
2665
|
await fieldInfo.emit();
|
|
2225
2666
|
};
|
|
2226
2667
|
|
|
2227
|
-
// src/lifecycle/fields/
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
const
|
|
2231
|
-
if (!
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2668
|
+
// src/lifecycle/fields/media/common/keyboard.events/onkeydown.ts
|
|
2669
|
+
import { FieldsUtils as FieldsUtils3 } from "@coorax/core";
|
|
2670
|
+
var createOnKeyDown3 = async (engine, block, ev) => {
|
|
2671
|
+
const fieldInfo = getFieldTypeAndTargetId(engine, ev, block);
|
|
2672
|
+
if (!fieldInfo)
|
|
2673
|
+
return;
|
|
2674
|
+
if (ev.ctrlKey || ev.metaKey)
|
|
2675
|
+
return;
|
|
2676
|
+
const tree = engine.document.get();
|
|
2677
|
+
const normalizedTarget = fieldInfo.target;
|
|
2678
|
+
const hasCurrentElement = engine.document.has(normalizedTarget);
|
|
2679
|
+
if (!hasCurrentElement) {
|
|
2680
|
+
console.warn(`Ignoring stale field target: ${normalizedTarget}`);
|
|
2681
|
+
return;
|
|
2236
2682
|
}
|
|
2237
|
-
const
|
|
2238
|
-
const
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2683
|
+
const targetIndex = [...tree.order].indexOf(normalizedTarget);
|
|
2684
|
+
const index = targetIndex + 1;
|
|
2685
|
+
const currentTarget = ev.currentTarget;
|
|
2686
|
+
if (ev.key === "Enter" && !ev.shiftKey) {
|
|
2687
|
+
ev.preventDefault();
|
|
2688
|
+
currentTarget.blur();
|
|
2689
|
+
const newField = FieldsUtils3.NewField("text");
|
|
2690
|
+
engine.commands.tryExecute("blocks.insert", { block: newField, pos: index });
|
|
2691
|
+
await fieldInfo.emit();
|
|
2692
|
+
const blockRect = blockRectFromBlockId(newField.id);
|
|
2693
|
+
if (!blockRect)
|
|
2694
|
+
return;
|
|
2695
|
+
engine.commands.tryExecute("blocks.focus", { id: newField.id, rect: blockRect });
|
|
2246
2696
|
}
|
|
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 {};
|
|
2697
|
+
if (ev.key === "ArrowUp" || ev.key === "ArrowDown" || ev.key === "Tab") {
|
|
2698
|
+
ev.preventDefault();
|
|
2699
|
+
const mustBeNegativeDelta = ev.key === "ArrowUp" || ev.key === "Tab" && ev.shiftKey;
|
|
2700
|
+
const delta = mustBeNegativeDelta ? -1 : 1;
|
|
2701
|
+
const currentTree = engine.document.get();
|
|
2702
|
+
const blockIndex = Array.from(currentTree.order).indexOf(block.id);
|
|
2703
|
+
if (blockIndex === -1)
|
|
2704
|
+
return;
|
|
2705
|
+
if (blockIndex === 0 && delta < 0)
|
|
2706
|
+
return;
|
|
2707
|
+
if (blockIndex === currentTree.order.size - 1 && delta > 0)
|
|
2708
|
+
return;
|
|
2709
|
+
const rectId = [...currentTree.order][blockIndex + delta];
|
|
2710
|
+
const rect = blockRectFromBlockId(rectId);
|
|
2711
|
+
if (!rect) {
|
|
2712
|
+
return;
|
|
2282
2713
|
}
|
|
2714
|
+
currentTarget.blur();
|
|
2715
|
+
engine.commands.tryExecute("blocks.focus", { id: rectId, rect });
|
|
2283
2716
|
}
|
|
2717
|
+
if (ev.key === "Escape") {
|
|
2718
|
+
ev.preventDefault();
|
|
2719
|
+
currentTarget.blur();
|
|
2720
|
+
engine.commands.tryExecute("blocks.select", { blocks: new Map, mode: "replace" });
|
|
2721
|
+
}
|
|
2722
|
+
};
|
|
2723
|
+
|
|
2724
|
+
// src/lifecycle/fields/media/common/synthetic.events/onerror.ts
|
|
2725
|
+
var createOnError = async (engine, block, ev) => {
|
|
2726
|
+
const fieldInfo = getFieldTypeAndTargetId(engine, ev, block);
|
|
2727
|
+
if (!fieldInfo || !block.props?.src?.trim())
|
|
2728
|
+
return;
|
|
2729
|
+
engine.document.apply((tree) => engine.mutations.mutateField(tree, {
|
|
2730
|
+
id: block.id,
|
|
2731
|
+
keyValuePairs: {
|
|
2732
|
+
"props.isError": true
|
|
2733
|
+
}
|
|
2734
|
+
}), { origin: "history" });
|
|
2735
|
+
await fieldInfo.emit();
|
|
2736
|
+
};
|
|
2737
|
+
|
|
2738
|
+
// src/lifecycle/fields/media/common/handlers.ts
|
|
2739
|
+
function buildMediaHandlers(engine, block) {
|
|
2740
|
+
const { onClick, onMouseEnter, onMouseLeave, onFocus } = buildCommonHandlers(engine, block);
|
|
2284
2741
|
return {
|
|
2285
|
-
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
|
|
2742
|
+
onClick,
|
|
2743
|
+
onMouseEnter,
|
|
2744
|
+
onMouseLeave,
|
|
2745
|
+
onFocus,
|
|
2746
|
+
onKeyDown: createOnKeyDown3.bind(null, engine, block),
|
|
2747
|
+
onError: createOnError.bind(null, engine, block)
|
|
2290
2748
|
};
|
|
2291
2749
|
}
|
|
2292
|
-
function getFieldLifeCycleEvents(engine, tag, block) {
|
|
2293
|
-
return getAllLifeCycleEvents(engine, block)[tag];
|
|
2294
|
-
}
|
|
2295
|
-
var FLC = { getFieldLifeCycleEvents };
|
|
2296
2750
|
|
|
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
|
-
};
|
|
2751
|
+
// src/lifecycle/fields/media/image/handlers.ts
|
|
2752
|
+
function buildImageHandlers(engine, block) {
|
|
2329
2753
|
return {
|
|
2330
|
-
...
|
|
2331
|
-
|
|
2332
|
-
...editableProps,
|
|
2333
|
-
...FLC.getFieldLifeCycleEvents(engine, block.tag, block)
|
|
2754
|
+
...buildMediaHandlers(engine, block),
|
|
2755
|
+
onLoad: createOnLoad.bind(null, engine, block)
|
|
2334
2756
|
};
|
|
2335
2757
|
}
|
|
2336
|
-
|
|
2337
|
-
|
|
2338
|
-
|
|
2339
|
-
const
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
|
|
2343
|
-
};
|
|
2344
|
-
const pseudoClassName = resolveCoraxPseudoStyle(_pseudoStyle);
|
|
2345
|
-
const baseProps = {
|
|
2758
|
+
|
|
2759
|
+
// src/lifecycle/fields/media/video/synthetic.events/oncanplaythrough.ts
|
|
2760
|
+
var createVideoOnCanPlayThrough = async (engine, block, ev) => {
|
|
2761
|
+
const fieldInfo = getFieldTypeAndTargetId(engine, ev, block);
|
|
2762
|
+
if (!fieldInfo || !block.props?.src?.trim())
|
|
2763
|
+
return;
|
|
2764
|
+
engine.document.apply((tree) => engine.mutations.mutateField(tree, {
|
|
2346
2765
|
id: block.id,
|
|
2347
|
-
|
|
2348
|
-
|
|
2349
|
-
|
|
2350
|
-
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
|
|
2354
|
-
|
|
2355
|
-
|
|
2766
|
+
keyValuePairs: {
|
|
2767
|
+
"props.isLoaded": true
|
|
2768
|
+
}
|
|
2769
|
+
}), { origin: "history" });
|
|
2770
|
+
engine.commands.tryExecute("blocks.select", {
|
|
2771
|
+
blocks: new Map().set(block.id, blockRectFromBlockId(block.id))
|
|
2772
|
+
});
|
|
2773
|
+
await fieldInfo.emit();
|
|
2774
|
+
};
|
|
2775
|
+
|
|
2776
|
+
// src/lifecycle/fields/media/video/mouse.events/ondoubleclick.ts
|
|
2777
|
+
var createVideoOnDoubleClick = async (engine, block, ev) => {
|
|
2778
|
+
ev.stopPropagation();
|
|
2779
|
+
ev.preventDefault();
|
|
2780
|
+
const fieldInfo = getFieldTypeAndTargetId(engine, ev, block);
|
|
2781
|
+
if (!fieldInfo)
|
|
2782
|
+
return;
|
|
2783
|
+
const field = block;
|
|
2784
|
+
engine.document.apply((t) => engine.mutations.mutateField(t, {
|
|
2785
|
+
id: field.id,
|
|
2786
|
+
keyValuePairs: {
|
|
2787
|
+
"props.controls": !field.props.controls
|
|
2788
|
+
}
|
|
2789
|
+
}));
|
|
2790
|
+
await fieldInfo.emit();
|
|
2791
|
+
};
|
|
2792
|
+
|
|
2793
|
+
// src/lifecycle/fields/media/video/handlers.ts
|
|
2794
|
+
function buildVideoHandlers(engine, block) {
|
|
2356
2795
|
return {
|
|
2357
|
-
...
|
|
2358
|
-
|
|
2359
|
-
|
|
2360
|
-
...FLC.getFieldLifeCycleEvents(engine, block.tag, block)
|
|
2796
|
+
...buildMediaHandlers(engine, block),
|
|
2797
|
+
onCanPlayThrough: createVideoOnCanPlayThrough.bind(null, engine, block),
|
|
2798
|
+
onDoubleClick: createVideoOnDoubleClick.bind(null, engine, block)
|
|
2361
2799
|
};
|
|
2362
2800
|
}
|
|
2363
|
-
function resolveCoraxPseudoStyle(style) {
|
|
2364
|
-
if (!style || Object.keys(style).length === 0)
|
|
2365
|
-
return;
|
|
2366
|
-
return css(style);
|
|
2367
|
-
}
|
|
2368
2801
|
|
|
2369
|
-
// src/
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
const _pseudoStyle = {
|
|
2376
|
-
...uiStyles.pseudoStyle,
|
|
2377
|
-
...pseudoStyle
|
|
2378
|
-
};
|
|
2379
|
-
const pseudoClassName = resolveCoraxPseudoStyle(_pseudoStyle);
|
|
2380
|
-
const baseProps = {
|
|
2802
|
+
// src/lifecycle/fields/media/iframe/synthetic.events/onload.ts
|
|
2803
|
+
var createIframeOnLoad = async (engine, block, ev) => {
|
|
2804
|
+
const fieldInfo = getFieldTypeAndTargetId(engine, ev, block);
|
|
2805
|
+
if (!fieldInfo || !block.props?.src?.trim())
|
|
2806
|
+
return;
|
|
2807
|
+
engine.document.apply((tree) => engine.mutations.mutateField(tree, {
|
|
2381
2808
|
id: block.id,
|
|
2382
|
-
|
|
2383
|
-
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
|
|
2809
|
+
keyValuePairs: {
|
|
2810
|
+
"props.isLoaded": true
|
|
2811
|
+
}
|
|
2812
|
+
}), { origin: "history" });
|
|
2813
|
+
engine.commands.tryExecute("blocks.select", {
|
|
2814
|
+
blocks: new Map().set(block.id, blockRectFromBlockId(block.id))
|
|
2815
|
+
});
|
|
2816
|
+
await fieldInfo.emit();
|
|
2817
|
+
};
|
|
2818
|
+
|
|
2819
|
+
// src/lifecycle/fields/media/iframe/handlers.ts
|
|
2820
|
+
function buildIFrameHandlers(engine, block) {
|
|
2392
2821
|
return {
|
|
2393
|
-
...
|
|
2394
|
-
|
|
2395
|
-
...rest,
|
|
2396
|
-
...handlers
|
|
2822
|
+
...buildMediaHandlers(engine, block),
|
|
2823
|
+
onLoad: createIframeOnLoad.bind(null, engine, block)
|
|
2397
2824
|
};
|
|
2398
2825
|
}
|
|
2399
2826
|
|
|
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;
|
|
2827
|
+
// src/lifecycle/fields/handlers.registry.ts
|
|
2828
|
+
class FieldHandlersRegistry extends GenericRegistry4 {
|
|
2420
2829
|
}
|
|
2830
|
+
var FieldHandlers = new FieldHandlersRegistry;
|
|
2831
|
+
FieldHandlers.register("h1", buildEditableHandlers);
|
|
2832
|
+
FieldHandlers.register("p", buildEditableHandlers);
|
|
2833
|
+
FieldHandlers.register("blockquote", buildEditableHandlers);
|
|
2834
|
+
FieldHandlers.register("figcaption", buildEditableHandlers);
|
|
2835
|
+
FieldHandlers.register("pre", buildEditableHandlers);
|
|
2836
|
+
FieldHandlers.register("a", buildEditableHandlers);
|
|
2837
|
+
FieldHandlers.register("img", buildImageHandlers);
|
|
2838
|
+
FieldHandlers.register("video", buildVideoHandlers);
|
|
2839
|
+
FieldHandlers.register("hr", buildDividerHandlers);
|
|
2840
|
+
FieldHandlers.register("iframe", buildIFrameHandlers);
|
|
2421
2841
|
|
|
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);
|
|
2842
|
+
// src/lifecycle/fields/lifecycle.fields.ts
|
|
2843
|
+
function getFieldLifeCycleEvents(engine, tag, block) {
|
|
2844
|
+
const build = FieldHandlers.get(tag);
|
|
2845
|
+
return build ? build(engine, block) : {};
|
|
2846
|
+
}
|
|
2847
|
+
function forField(engine, block) {
|
|
2848
|
+
return getFieldLifeCycleEvents(engine, block.tag, block);
|
|
2849
|
+
}
|
|
2850
|
+
var FLC = { forField };
|
|
2851
|
+
// src/primitives/fields/field.primitives.tsx
|
|
2852
|
+
import { useCallback, useEffect as useEffect6, useRef as useRef3 } from "react";
|
|
2853
|
+
import { jsxDEV as jsxDEV25 } from "react/jsx-dev-runtime";
|
|
2854
|
+
function FieldPrimitive({ blockId }) {
|
|
2855
|
+
const blockRef = useRef3(null);
|
|
2856
|
+
const engine = useEngine();
|
|
2857
|
+
const renderer = useRenderer();
|
|
2858
|
+
const block = useBlock(blockId);
|
|
2859
|
+
const sel = useSlice("textSelection");
|
|
2860
|
+
const updateRange = useCallback(() => {
|
|
2861
|
+
if (!sel)
|
|
2862
|
+
return;
|
|
2863
|
+
const root = document.querySelector(`[id="${CSS.escape(sel.blockId)}"][data-text-path="${CSS.escape(sel.path)}"]`);
|
|
2864
|
+
if (!root || !root.contains(document.activeElement))
|
|
2865
|
+
return;
|
|
2866
|
+
const domSel = document.getSelection();
|
|
2867
|
+
if (!domSel)
|
|
2868
|
+
return;
|
|
2869
|
+
if (domSel.rangeCount) {
|
|
2870
|
+
const cur = rangeToOffsets(root, domSel.getRangeAt(0));
|
|
2871
|
+
if (cur.start === sel.start && cur.end === sel.end)
|
|
2872
|
+
return;
|
|
2490
2873
|
}
|
|
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
|
-
|
|
2874
|
+
const range = offsetsToRange(root, sel.start, sel.end);
|
|
2875
|
+
if (!range)
|
|
2876
|
+
return;
|
|
2877
|
+
domSel.removeAllRanges();
|
|
2878
|
+
domSel.addRange(range);
|
|
2879
|
+
}, [sel]);
|
|
2880
|
+
useIsomorphicLayoutEffect(() => {
|
|
2881
|
+
updateRange();
|
|
2882
|
+
}, [updateRange, engine]);
|
|
2883
|
+
useIsomorphicLayoutEffect(() => {
|
|
2884
|
+
if (!sel)
|
|
2885
|
+
return;
|
|
2886
|
+
const root = document.querySelector(`[id="${CSS.escape(sel.blockId)}"][data-text-path="${CSS.escape(sel.path)}"]`);
|
|
2887
|
+
if (!root || !root.contains(document.activeElement))
|
|
2888
|
+
return;
|
|
2889
|
+
const range = offsetsToRange(root, sel.start, sel.end);
|
|
2890
|
+
if (!range)
|
|
2891
|
+
return;
|
|
2892
|
+
root.focus({ preventScroll: true });
|
|
2893
|
+
const domSel = document.getSelection();
|
|
2894
|
+
domSel.removeAllRanges();
|
|
2895
|
+
domSel.addRange(range);
|
|
2896
|
+
});
|
|
2897
|
+
useEffect6(() => {
|
|
2898
|
+
const domEl = blockRef.current;
|
|
2899
|
+
if (!domEl)
|
|
2900
|
+
return;
|
|
2901
|
+
const publishBlockRect = () => {
|
|
2902
|
+
const hover = engine.state.get("hover");
|
|
2903
|
+
const focus = engine.state.get("focus");
|
|
2904
|
+
const selection = engine.state.get("selection")?.blocks;
|
|
2905
|
+
const rect = blockRectFromBlockId(blockId);
|
|
2906
|
+
if (!rect || !engine.document.get().order.size)
|
|
2907
|
+
return;
|
|
2908
|
+
if (focus?.id === blockId) {
|
|
2909
|
+
engine.commands.tryExecute("blocks.focus", { id: blockId, rect });
|
|
2910
|
+
}
|
|
2911
|
+
if (hover?.id === blockId) {
|
|
2912
|
+
engine.commands.tryExecute("blocks.hover", { id: blockId, rect });
|
|
2913
|
+
}
|
|
2914
|
+
if (selection?.has(blockId)) {
|
|
2915
|
+
engine.commands.tryExecute("blocks.select", {
|
|
2916
|
+
blocks: new Map().set(blockId, rect),
|
|
2917
|
+
mode: "add"
|
|
2918
|
+
});
|
|
2919
|
+
}
|
|
2920
|
+
};
|
|
2921
|
+
const observer = new ResizeObserver(publishBlockRect);
|
|
2922
|
+
observer.observe(domEl);
|
|
2923
|
+
return () => {
|
|
2924
|
+
observer.unobserve(domEl);
|
|
2925
|
+
observer.disconnect();
|
|
2926
|
+
};
|
|
2927
|
+
}, [engine, blockId]);
|
|
2928
|
+
if (!blockId.startsWith("field") || !block)
|
|
2929
|
+
return null;
|
|
2930
|
+
return /* @__PURE__ */ jsxDEV25("div", {
|
|
2931
|
+
ref: blockRef,
|
|
2932
|
+
children: renderer.renderField(block)
|
|
2933
|
+
}, undefined, false, undefined, this);
|
|
2517
2934
|
}
|
|
2518
2935
|
|
|
2936
|
+
// src/primitives/index.ts
|
|
2937
|
+
var FieldsPrimitives = {
|
|
2938
|
+
field: FieldPrimitive
|
|
2939
|
+
};
|
|
2940
|
+
|
|
2519
2941
|
// src/hooks/use-renderer.ts
|
|
2520
2942
|
function useRenderer() {
|
|
2521
2943
|
const engine = useEngine();
|
|
2522
|
-
return useMemo4(() =>
|
|
2944
|
+
return useMemo4(() => {
|
|
2945
|
+
const ctx = {
|
|
2946
|
+
mode: "edit",
|
|
2947
|
+
styles: (type) => engine.ui.getStyle(type),
|
|
2948
|
+
events: (block) => FLC.forField(engine, block)
|
|
2949
|
+
};
|
|
2950
|
+
const renderer = new ReactRenderer(ctx, engine.document);
|
|
2951
|
+
for (const [variant, comp] of UTILS2.ObjectEntries(FieldsPrimitives)) {
|
|
2952
|
+
if (comp)
|
|
2953
|
+
renderer.primitives.post(variant, comp);
|
|
2954
|
+
}
|
|
2955
|
+
return renderer;
|
|
2956
|
+
}, [engine]);
|
|
2523
2957
|
}
|
|
2524
2958
|
|
|
2525
2959
|
// src/hooks/use-flow.ts
|
|
2526
|
-
import { useEffect as
|
|
2960
|
+
import { useEffect as useEffect8 } from "react";
|
|
2527
2961
|
|
|
2528
2962
|
// src/hooks/custom/use-custom-ref.ts
|
|
2529
|
-
import { useEffect as
|
|
2963
|
+
import { useEffect as useEffect7, useRef as useRef4 } from "react";
|
|
2530
2964
|
function useCustomRef(factory) {
|
|
2531
2965
|
const isServer = typeof window === "undefined";
|
|
2532
2966
|
const getInitialValue = () => {
|
|
@@ -2539,7 +2973,7 @@ function useCustomRef(factory) {
|
|
|
2539
2973
|
}
|
|
2540
2974
|
};
|
|
2541
2975
|
const ref = useRef4(getInitialValue());
|
|
2542
|
-
|
|
2976
|
+
useEffect7(() => {
|
|
2543
2977
|
try {
|
|
2544
2978
|
ref.current = typeof factory === "function" ? factory() : factory;
|
|
2545
2979
|
} catch {}
|
|
@@ -2578,7 +3012,7 @@ function useFlow() {
|
|
|
2578
3012
|
engine.commands.tryExecute("editor.rect", { editorRect: editorRectFromDomElement(flowEditor) });
|
|
2579
3013
|
return flowEditor;
|
|
2580
3014
|
});
|
|
2581
|
-
|
|
3015
|
+
useEffect8(() => {
|
|
2582
3016
|
function handleKeyDown(ev) {
|
|
2583
3017
|
if (!ev.ctrlKey || ev.key.toLocaleLowerCase() !== "z")
|
|
2584
3018
|
return;
|
|
@@ -2604,7 +3038,7 @@ function useFlow() {
|
|
|
2604
3038
|
}
|
|
2605
3039
|
};
|
|
2606
3040
|
}, [engine, coraxFlowEditorRef]);
|
|
2607
|
-
|
|
3041
|
+
useEffect8(() => {
|
|
2608
3042
|
const element = coraxFlowEditorRef.current;
|
|
2609
3043
|
if (!element)
|
|
2610
3044
|
return;
|
|
@@ -2619,12 +3053,24 @@ function useFlow() {
|
|
|
2619
3053
|
element.removeEventListener("scroll", publishEditorRect);
|
|
2620
3054
|
};
|
|
2621
3055
|
}, [engine, coraxFlowEditorRef]);
|
|
3056
|
+
useEffect8(() => {
|
|
3057
|
+
const element = coraxFlowEditorRef.current;
|
|
3058
|
+
if (!element)
|
|
3059
|
+
return;
|
|
3060
|
+
const publishEditorRect = () => {
|
|
3061
|
+
engine.commands.tryExecute("editor.rect", { editorRect: editorRectFromDomElement(element) });
|
|
3062
|
+
};
|
|
3063
|
+
window.addEventListener("resize", publishEditorRect, { passive: true });
|
|
3064
|
+
return () => {
|
|
3065
|
+
window.removeEventListener("resize", publishEditorRect);
|
|
3066
|
+
};
|
|
3067
|
+
}, [engine, coraxFlowEditorRef]);
|
|
2622
3068
|
}
|
|
2623
3069
|
|
|
2624
3070
|
// src/hooks/use-text-input.ts
|
|
2625
|
-
import { useEffect as
|
|
3071
|
+
import { useEffect as useEffect9 } from "react";
|
|
2626
3072
|
function useTextInput(engine) {
|
|
2627
|
-
|
|
3073
|
+
useEffect9(() => {
|
|
2628
3074
|
let composing = false;
|
|
2629
3075
|
const rootOf = (t) => ((t instanceof Element ? t : t?.parentElement) ?? null)?.closest("[data-text-path]") ?? null;
|
|
2630
3076
|
const onBeforeInput = (e) => {
|
|
@@ -2637,7 +3083,7 @@ function useTextInput(engine) {
|
|
|
2637
3083
|
r.setStart(tr.startContainer, tr.startOffset);
|
|
2638
3084
|
r.setEnd(tr.endContainer, tr.endOffset);
|
|
2639
3085
|
engine.commands.tryExecute("text.setSelection", {
|
|
2640
|
-
blockId: root.
|
|
3086
|
+
blockId: root.id,
|
|
2641
3087
|
path: root.dataset.textPath,
|
|
2642
3088
|
...rangeToOffsets(root, r)
|
|
2643
3089
|
});
|
|
@@ -2699,8 +3145,8 @@ function useTextInput(engine) {
|
|
|
2699
3145
|
}
|
|
2700
3146
|
|
|
2701
3147
|
// src/components/corax-flow.tsx
|
|
2702
|
-
import { cn as
|
|
2703
|
-
import { jsxDEV as
|
|
3148
|
+
import { cn as cn14 } from "cn";
|
|
3149
|
+
import { jsxDEV as jsxDEV26 } from "react/jsx-dev-runtime";
|
|
2704
3150
|
"use client";
|
|
2705
3151
|
function CoraxFlow({
|
|
2706
3152
|
children,
|
|
@@ -2711,35 +3157,35 @@ function CoraxFlow({
|
|
|
2711
3157
|
const renderer = useRenderer();
|
|
2712
3158
|
useFlow();
|
|
2713
3159
|
useTextInput(engine);
|
|
2714
|
-
|
|
2715
|
-
const
|
|
2716
|
-
|
|
2717
|
-
|
|
2718
|
-
|
|
3160
|
+
useEffect10(() => {
|
|
3161
|
+
const disposers = [
|
|
3162
|
+
engine.events.on("document:changed", ({ value }) => {
|
|
3163
|
+
const { diff } = value;
|
|
3164
|
+
if (diff.added.size || diff.removed.size || diff.orderChanged)
|
|
3165
|
+
forceUpdate();
|
|
3166
|
+
})
|
|
3167
|
+
];
|
|
3168
|
+
return () => disposers.forEach((dispose) => dispose());
|
|
2719
3169
|
}, [engine]);
|
|
2720
|
-
return /* @__PURE__ */
|
|
3170
|
+
return /* @__PURE__ */ jsxDEV26("div", {
|
|
2721
3171
|
id: "corax_flow_editor",
|
|
2722
|
-
className: "relative flex flex-col w-full
|
|
2723
|
-
children:
|
|
2724
|
-
"
|
|
2725
|
-
|
|
2726
|
-
|
|
2727
|
-
|
|
2728
|
-
children
|
|
2729
|
-
|
|
2730
|
-
|
|
2731
|
-
|
|
2732
|
-
}, undefined, true, undefined, this)
|
|
2733
|
-
]
|
|
2734
|
-
}, undefined, true, undefined, this);
|
|
3172
|
+
className: "relative flex flex-col max-w-full w-200 h-full",
|
|
3173
|
+
children: /* @__PURE__ */ jsxDEV26("div", {
|
|
3174
|
+
id: "corax_flow_blocks_container",
|
|
3175
|
+
className: cn14("relative w-full h-full flex flex-col overflow-auto scrollbar-none pl-10 gap-1", className),
|
|
3176
|
+
children: [
|
|
3177
|
+
renderer.renderTree(count),
|
|
3178
|
+
children
|
|
3179
|
+
]
|
|
3180
|
+
}, undefined, true, undefined, this)
|
|
3181
|
+
}, undefined, false, undefined, this);
|
|
2735
3182
|
}
|
|
2736
3183
|
|
|
2737
3184
|
// src/components/index.ts
|
|
2738
3185
|
"use client";
|
|
2739
|
-
// src/services/index.ts
|
|
2740
|
-
var CORAX_INDEXED_DB = "coraxdb";
|
|
2741
3186
|
// src/index.ts
|
|
2742
3187
|
export * from "@coorax/core";
|
|
3188
|
+
export * from "@coorax/render-react";
|
|
2743
3189
|
"use client";
|
|
2744
3190
|
export {
|
|
2745
3191
|
useUIContext,
|
|
@@ -2751,6 +3197,7 @@ export {
|
|
|
2751
3197
|
loadCompleteDocument,
|
|
2752
3198
|
getFieldTypeAndTargetId,
|
|
2753
3199
|
getBlockActionsProps,
|
|
3200
|
+
forField,
|
|
2754
3201
|
focusDomElement,
|
|
2755
3202
|
focusDomBLockById,
|
|
2756
3203
|
blockRectFromBlockId,
|
|
@@ -2761,10 +3208,14 @@ export {
|
|
|
2761
3208
|
SlotsComponentRegistry,
|
|
2762
3209
|
PrimitivesComponentsRegistry,
|
|
2763
3210
|
Overlays,
|
|
2764
|
-
|
|
3211
|
+
LocalDB,
|
|
3212
|
+
GenericRegistry3 as GenericRegistry,
|
|
3213
|
+
FieldHandlersRegistry,
|
|
3214
|
+
FieldHandlers,
|
|
2765
3215
|
FallbacksModule,
|
|
2766
3216
|
FallbackComponentsRegistry,
|
|
2767
3217
|
FLC,
|
|
3218
|
+
ErrorComponentsRegistry,
|
|
2768
3219
|
CoraxIcon,
|
|
2769
3220
|
CoraxFlow,
|
|
2770
3221
|
CoraxEngineProvider,
|