@coorax/react 0.0.0-canary.3 → 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-registry.d.ts +1 -1
- package/dist/hooks/use-renderer.d.ts +1 -1
- package/dist/index.d.ts +5 -0
- package/dist/index.js +1174 -700
- package/dist/lib/index.d.ts +4 -0
- 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/lifecycle/index.d.ts +3 -1
- 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 +2 -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,10 +606,80 @@ 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
|
|
677
|
+
function focusDomBLockById(engine, id) {
|
|
678
|
+
const disposer = engine.events.on("re-render", () => {
|
|
679
|
+
focusDomElement(id);
|
|
680
|
+
disposer();
|
|
681
|
+
});
|
|
682
|
+
}
|
|
356
683
|
function focusDomElement(id) {
|
|
357
684
|
const domElement = document.getElementById(id);
|
|
358
685
|
if (!domElement)
|
|
@@ -361,42 +688,51 @@ function focusDomElement(id) {
|
|
|
361
688
|
}
|
|
362
689
|
|
|
363
690
|
// src/components/slots/overlays/focus-overlay.tsx
|
|
364
|
-
import { jsxDEV as
|
|
365
|
-
function FocusOverlay({
|
|
366
|
-
|
|
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) ?? {};
|
|
367
697
|
const focusedId = ui.focus?.id;
|
|
368
|
-
|
|
698
|
+
useEffect2(() => {
|
|
369
699
|
if (!focusedId)
|
|
370
700
|
return;
|
|
371
701
|
focusDomElement(focusedId);
|
|
372
702
|
}, [focusedId]);
|
|
373
703
|
if (hidden || !position)
|
|
374
704
|
return null;
|
|
375
|
-
return /* @__PURE__ */
|
|
705
|
+
return /* @__PURE__ */ jsxDEV17("div", {
|
|
376
706
|
style: position,
|
|
377
707
|
className: "absolute border border-blue-700 pointer-events-none flex justify-end"
|
|
378
708
|
}, undefined, false, undefined, this);
|
|
379
709
|
}
|
|
380
710
|
|
|
381
711
|
// src/components/slots/overlays/hover-overlay.tsx
|
|
382
|
-
import { jsxDEV as
|
|
383
|
-
function HoverOverlay({
|
|
384
|
-
|
|
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) ?? {};
|
|
385
718
|
if (hidden || !position)
|
|
386
719
|
return null;
|
|
387
|
-
return /* @__PURE__ */
|
|
720
|
+
return /* @__PURE__ */ jsxDEV18("div", {
|
|
388
721
|
style: position,
|
|
389
722
|
className: "absolute border-[0.5px] border-blue-400 pointer-events-none flex justify-end"
|
|
390
723
|
}, undefined, false, undefined, this);
|
|
391
724
|
}
|
|
392
725
|
|
|
393
726
|
// src/components/slots/overlays/selection-overlay.tsx
|
|
394
|
-
import { jsxDEV as
|
|
395
|
-
function SelectionOverlay({
|
|
396
|
-
|
|
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) ?? {};
|
|
397
733
|
if (hidden || !position)
|
|
398
734
|
return null;
|
|
399
|
-
return /* @__PURE__ */
|
|
735
|
+
return /* @__PURE__ */ jsxDEV19("div", {
|
|
400
736
|
style: position,
|
|
401
737
|
className: "absolute border border-blue-500 pointer-events-none flex justify-end"
|
|
402
738
|
}, undefined, false, undefined, this);
|
|
@@ -410,6 +746,9 @@ var SlotsModule = {
|
|
|
410
746
|
install() {
|
|
411
747
|
SlotsComponentRegistry.register("BlockActionButton", BlockActionButton);
|
|
412
748
|
SlotsComponentRegistry.register("ToolBarButton", ToolbarButton);
|
|
749
|
+
SlotsComponentRegistry.register("CodeThemeButton", CodeThemeButton);
|
|
750
|
+
SlotsComponentRegistry.register("CaptionButton", CaptionButton);
|
|
751
|
+
SlotsComponentRegistry.register("DeleteButton", DeleteButton);
|
|
413
752
|
SlotsComponentRegistry.register("SelectionOverlay", SelectionOverlay);
|
|
414
753
|
SlotsComponentRegistry.register("FocusOverlay", FocusOverlay);
|
|
415
754
|
SlotsComponentRegistry.register("HoverOverlay", HoverOverlay);
|
|
@@ -440,7 +779,8 @@ class Lexer {
|
|
|
440
779
|
"INTO",
|
|
441
780
|
"VALUES",
|
|
442
781
|
"CREATE",
|
|
443
|
-
"TABLE"
|
|
782
|
+
"TABLE",
|
|
783
|
+
"DELETE"
|
|
444
784
|
];
|
|
445
785
|
cleanWord() {
|
|
446
786
|
this.word = [];
|
|
@@ -587,7 +927,7 @@ var TYPES_DEFS_MAPPING = {
|
|
|
587
927
|
|
|
588
928
|
// src/services/localdb/parser/parser.ts
|
|
589
929
|
class Parser {
|
|
590
|
-
statementTypes = ["SELECT", "INSERT", "CREATE"];
|
|
930
|
+
statementTypes = ["SELECT", "INSERT", "CREATE", "DELETE"];
|
|
591
931
|
foundTable(tokens) {
|
|
592
932
|
return tokens.find((token, idx) => {
|
|
593
933
|
return token.type === "IDENTIFIER" && ["FROM", "INTO", "TABLE"].includes(tokens[idx - 1]?.type);
|
|
@@ -852,8 +1192,72 @@ class Parser {
|
|
|
852
1192
|
}
|
|
853
1193
|
return statements;
|
|
854
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
|
+
}
|
|
855
1259
|
parse(tokens, params) {
|
|
856
|
-
if (tokens.length <
|
|
1260
|
+
if (tokens.length < 3) {
|
|
857
1261
|
throw new Error(`Invalid tokens array with missing elements!`);
|
|
858
1262
|
}
|
|
859
1263
|
const firstStatement = tokens[0];
|
|
@@ -867,6 +1271,9 @@ class Parser {
|
|
|
867
1271
|
if (firstStatement.type === "SELECT") {
|
|
868
1272
|
return [this.parseSelect(tokens)];
|
|
869
1273
|
}
|
|
1274
|
+
if (firstStatement.type === "DELETE") {
|
|
1275
|
+
return [this.parseDelete(tokens)];
|
|
1276
|
+
}
|
|
870
1277
|
if (firstStatement.type === "INSERT") {
|
|
871
1278
|
const stmtChunks = [];
|
|
872
1279
|
let currentChunk = [];
|
|
@@ -1324,21 +1731,65 @@ class LocalDB {
|
|
|
1324
1731
|
await this.insertData(objectStore, newData);
|
|
1325
1732
|
break;
|
|
1326
1733
|
}
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
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
|
+
}
|
|
1342
1793
|
async MigrateDB(query) {
|
|
1343
1794
|
const statements = this.client.NewRequest(query);
|
|
1344
1795
|
const isBadReq = statements.some((s) => s.type !== "CREATE");
|
|
@@ -1382,9 +1833,12 @@ class LocalDB {
|
|
|
1382
1833
|
}
|
|
1383
1834
|
}
|
|
1384
1835
|
|
|
1836
|
+
// src/services/index.ts
|
|
1837
|
+
var CORAX_INDEXED_DB = "coraxdb";
|
|
1838
|
+
|
|
1385
1839
|
// src/modules/autosave.module.ts
|
|
1386
|
-
async function loadCompleteDocument(
|
|
1387
|
-
const result = await
|
|
1840
|
+
async function loadCompleteDocument(db2, documentId) {
|
|
1841
|
+
const result = await db2.QueryDB(`
|
|
1388
1842
|
SELECT * FROM documents
|
|
1389
1843
|
JOIN fields ON documents.id = fields.document_id
|
|
1390
1844
|
JOIN containers ON documents.id = containers.document_id
|
|
@@ -1410,13 +1864,13 @@ var AutoSaveModule = {
|
|
|
1410
1864
|
console.error("[WARN] indexedDB not supported or SSR");
|
|
1411
1865
|
return;
|
|
1412
1866
|
}
|
|
1413
|
-
const
|
|
1414
|
-
|
|
1867
|
+
const db2 = new LocalDB(CORAX_INDEXED_DB);
|
|
1868
|
+
db2.DeleteDB().then((err) => {
|
|
1415
1869
|
if (err) {
|
|
1416
1870
|
console.error(err);
|
|
1417
1871
|
return;
|
|
1418
1872
|
}
|
|
1419
|
-
|
|
1873
|
+
db2.MigrateDB(`
|
|
1420
1874
|
CREATE TABLE documents (
|
|
1421
1875
|
id TEXT,
|
|
1422
1876
|
version TEXT,
|
|
@@ -1477,6 +1931,9 @@ var AutoSaveModule = {
|
|
|
1477
1931
|
}).catch((e) => {
|
|
1478
1932
|
console.error(e);
|
|
1479
1933
|
});
|
|
1934
|
+
ctx.commands.register("db.query", ({ query }) => {
|
|
1935
|
+
db2.QueryDB(query);
|
|
1936
|
+
});
|
|
1480
1937
|
ctx.commands.before("blocks.insert", (p) => {
|
|
1481
1938
|
const dbState = ctx.state.get("localdbState");
|
|
1482
1939
|
if (!dbState || !dbState.isDBReady)
|
|
@@ -1491,9 +1948,9 @@ var AutoSaveModule = {
|
|
|
1491
1948
|
const saveDocument = async () => {
|
|
1492
1949
|
const documentId = jsonDocument.id;
|
|
1493
1950
|
const now = Date.now();
|
|
1494
|
-
await
|
|
1951
|
+
await db2.QueryDB(`INSERT INTO documents (id, version, order, created_at) VALUES (?, ?, ?, ?);`, [documentId, jsonDocument.version, Array.from(jsonDocument.order ?? []), now]);
|
|
1495
1952
|
for (const [fieldId, field] of Object.entries(jsonDocument.fields ?? {})) {
|
|
1496
|
-
await
|
|
1953
|
+
await db2.QueryDB(`INSERT INTO fields (id, document_id, name, tag, type, variant, containerId, props) VALUES (?, ?, ?, ?, ?, ?, ?, ?);`, [
|
|
1497
1954
|
field.id || fieldId,
|
|
1498
1955
|
documentId,
|
|
1499
1956
|
field.name ?? "",
|
|
@@ -1506,7 +1963,7 @@ var AutoSaveModule = {
|
|
|
1506
1963
|
const fieldProps = field.props ?? {};
|
|
1507
1964
|
if (fieldProps.file && (fieldProps.file instanceof Blob || typeof File !== "undefined" && fieldProps.file instanceof File)) {
|
|
1508
1965
|
const file = fieldProps.file;
|
|
1509
|
-
await
|
|
1966
|
+
await db2.QueryDB(`INSERT INTO medias (id, document_id, name, type, size, data, created_at) VALUES (?, ?, ?, ?, ?, ?, ?);`, [
|
|
1510
1967
|
`media:${field.id || fieldId}`,
|
|
1511
1968
|
documentId,
|
|
1512
1969
|
file.name ?? "unnamed",
|
|
@@ -1518,7 +1975,7 @@ var AutoSaveModule = {
|
|
|
1518
1975
|
}
|
|
1519
1976
|
}
|
|
1520
1977
|
for (const [containerId, container] of Object.entries(jsonDocument.containers ?? {})) {
|
|
1521
|
-
await
|
|
1978
|
+
await db2.QueryDB(`INSERT INTO containers (id, document_id, name, tag, type, variant, order, props) VALUES (?, ?, ?, ?, ?, ?, ?, ?);`, [
|
|
1522
1979
|
container.id || containerId,
|
|
1523
1980
|
documentId,
|
|
1524
1981
|
container.name ?? "",
|
|
@@ -1530,7 +1987,7 @@ var AutoSaveModule = {
|
|
|
1530
1987
|
]);
|
|
1531
1988
|
}
|
|
1532
1989
|
for (const [componentId, component] of Object.entries(jsonDocument.components ?? {})) {
|
|
1533
|
-
await
|
|
1990
|
+
await db2.QueryDB(`INSERT INTO components (id, document_id, name, tag, type, variant, order, count, updatedAt, createdAt, props) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);`, [
|
|
1534
1991
|
component.id || componentId,
|
|
1535
1992
|
documentId,
|
|
1536
1993
|
component.name ?? "",
|
|
@@ -1550,7 +2007,7 @@ var AutoSaveModule = {
|
|
|
1550
2007
|
}
|
|
1551
2008
|
};
|
|
1552
2009
|
// src/components/slots/maps/block-actions.tsx
|
|
1553
|
-
import { useEffect as
|
|
2010
|
+
import { useEffect as useEffect3, useMemo as useMemo2, useRef } from "react";
|
|
1554
2011
|
|
|
1555
2012
|
// src/hooks/use-slots.ts
|
|
1556
2013
|
import { useSyncExternalStore as useSyncExternalStore2 } from "react";
|
|
@@ -1562,24 +2019,19 @@ function useSlots(slotName) {
|
|
|
1562
2019
|
|
|
1563
2020
|
// src/hooks/use-registry.ts
|
|
1564
2021
|
import { useSyncExternalStore as useSyncExternalStore3 } from "react";
|
|
1565
|
-
|
|
1566
|
-
// src/registry/ui.primitives.registry.tsx
|
|
1567
|
-
var UIPrimitivesRegistry = new GenericRegistry;
|
|
1568
|
-
|
|
1569
|
-
// src/hooks/use-registry.ts
|
|
1570
2022
|
function useRegistryComponent(name) {
|
|
1571
2023
|
return useSyncExternalStore3((fn) => SlotsComponentRegistry.subscribe(name, fn), () => SlotsComponentRegistry.get(name), () => SlotsComponentRegistry.get(name));
|
|
1572
2024
|
}
|
|
1573
2025
|
|
|
1574
2026
|
// src/components/slots/slot-button.tsx
|
|
1575
|
-
import
|
|
2027
|
+
import React7 from "react";
|
|
1576
2028
|
function SlotButton({ c, ui }) {
|
|
1577
2029
|
const Comp = useRegistryComponent(c.name);
|
|
1578
2030
|
if (!Comp) {
|
|
1579
2031
|
console.warn(`No component registered for slot key "${c.name}"`);
|
|
1580
2032
|
return null;
|
|
1581
2033
|
}
|
|
1582
|
-
return
|
|
2034
|
+
return React7.createElement(Comp, {
|
|
1583
2035
|
c,
|
|
1584
2036
|
ui,
|
|
1585
2037
|
...{
|
|
@@ -1617,12 +2069,12 @@ function SlotComponent({ c, ui }) {
|
|
|
1617
2069
|
}
|
|
1618
2070
|
|
|
1619
2071
|
// src/components/slots/slots.tsx
|
|
1620
|
-
import { jsxDEV as
|
|
2072
|
+
import { jsxDEV as jsxDEV20, Fragment } from "react/jsx-dev-runtime";
|
|
1621
2073
|
function Slots({ slotName }) {
|
|
1622
2074
|
const items = useSlots(slotName);
|
|
1623
2075
|
const ui = useUIContext();
|
|
1624
|
-
return /* @__PURE__ */
|
|
1625
|
-
children: items.map((c) => /* @__PURE__ */
|
|
2076
|
+
return /* @__PURE__ */ jsxDEV20(Fragment, {
|
|
2077
|
+
children: items.map((c) => /* @__PURE__ */ jsxDEV20(SlotItem, {
|
|
1626
2078
|
c,
|
|
1627
2079
|
ui
|
|
1628
2080
|
}, c.id, false, undefined, this))
|
|
@@ -1633,12 +2085,12 @@ function SlotItem({ c, ui }) {
|
|
|
1633
2085
|
return null;
|
|
1634
2086
|
switch (c.kind) {
|
|
1635
2087
|
case "button":
|
|
1636
|
-
return /* @__PURE__ */
|
|
2088
|
+
return /* @__PURE__ */ jsxDEV20(SlotButton, {
|
|
1637
2089
|
c,
|
|
1638
2090
|
ui
|
|
1639
2091
|
}, undefined, false, undefined, this);
|
|
1640
2092
|
case "component":
|
|
1641
|
-
return /* @__PURE__ */
|
|
2093
|
+
return /* @__PURE__ */ jsxDEV20(SlotComponent, {
|
|
1642
2094
|
c,
|
|
1643
2095
|
ui
|
|
1644
2096
|
}, undefined, false, undefined, this);
|
|
@@ -1646,29 +2098,38 @@ function SlotItem({ c, ui }) {
|
|
|
1646
2098
|
}
|
|
1647
2099
|
|
|
1648
2100
|
// src/components/slots/maps/block-actions.tsx
|
|
1649
|
-
import { cn as
|
|
1650
|
-
import {
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
const { order = new Set } = documentSlice ?? {};
|
|
1656
|
-
const keys = [...blocks.keys()];
|
|
1657
|
-
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) {
|
|
1658
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");
|
|
1659
2117
|
const lastPositionRef = useRef({ active: false, top: 0, left: 0 });
|
|
1660
|
-
const
|
|
2118
|
+
const block = useBlock(focus?.id ?? "");
|
|
2119
|
+
const isOpened = !!useSlice("insertion");
|
|
1661
2120
|
const position = useMemo2(() => {
|
|
1662
|
-
if (!
|
|
2121
|
+
if (!focus || !block || !isEditableField(block)) {
|
|
1663
2122
|
return { active: false, top: 0, left: 0 };
|
|
1664
2123
|
}
|
|
2124
|
+
const hasContent = !!block.props.children.text.length;
|
|
2125
|
+
if (hasContent) {
|
|
2126
|
+
return { active: false, top: 0, left: 0 };
|
|
2127
|
+
}
|
|
2128
|
+
const { id: firstSelectionId, rect: blockRect } = focus;
|
|
1665
2129
|
const container = document.getElementById("corax_flow_blocks_container");
|
|
1666
2130
|
if (!container)
|
|
1667
2131
|
return { active: false, top: 0, left: 0 };
|
|
1668
2132
|
const containerRect = container.getBoundingClientRect();
|
|
1669
|
-
const block = engine.document.getBlock(firstSelectionId);
|
|
1670
|
-
if (!block || block.variant !== "field")
|
|
1671
|
-
return { active: false, top: 0, left: 0 };
|
|
1672
2133
|
const domElement = document.getElementById(firstSelectionId);
|
|
1673
2134
|
if (!domElement)
|
|
1674
2135
|
return { active: false, top: 0, left: 0 };
|
|
@@ -1680,49 +2141,57 @@ function BlockActions({ className, children, ...rest }) {
|
|
|
1680
2141
|
top,
|
|
1681
2142
|
left: 0
|
|
1682
2143
|
};
|
|
1683
|
-
}, [
|
|
1684
|
-
|
|
2144
|
+
}, [focus, block]);
|
|
2145
|
+
useEffect3(() => {
|
|
1685
2146
|
if (position.active) {
|
|
1686
2147
|
lastPositionRef.current = position;
|
|
1687
2148
|
}
|
|
1688
2149
|
}, [position]);
|
|
1689
2150
|
const _position = position.active ? position : lastPositionRef.current;
|
|
1690
|
-
return /* @__PURE__ */
|
|
2151
|
+
return /* @__PURE__ */ jsxDEV21("div", {
|
|
1691
2152
|
style: {
|
|
1692
2153
|
top: _position.top,
|
|
1693
2154
|
left: _position.left
|
|
1694
2155
|
},
|
|
1695
|
-
className:
|
|
1696
|
-
"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
|
|
1697
2158
|
}),
|
|
1698
2159
|
...rest,
|
|
1699
2160
|
children: [
|
|
1700
|
-
/* @__PURE__ */
|
|
2161
|
+
/* @__PURE__ */ jsxDEV21(Slots, {
|
|
1701
2162
|
slotName: "block-actions"
|
|
1702
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),
|
|
1703
2172
|
children
|
|
1704
2173
|
]
|
|
1705
2174
|
}, undefined, true, undefined, this);
|
|
1706
2175
|
}
|
|
1707
2176
|
// src/components/slots/maps/overlays.tsx
|
|
1708
|
-
import { jsxDEV as
|
|
2177
|
+
import { jsxDEV as jsxDEV22, Fragment as Fragment2 } from "react/jsx-dev-runtime";
|
|
1709
2178
|
function Overlays() {
|
|
1710
|
-
return /* @__PURE__ */
|
|
1711
|
-
children: /* @__PURE__ */
|
|
2179
|
+
return /* @__PURE__ */ jsxDEV22(Fragment2, {
|
|
2180
|
+
children: /* @__PURE__ */ jsxDEV22(Slots, {
|
|
1712
2181
|
slotName: "overlay"
|
|
1713
2182
|
}, undefined, false, undefined, this)
|
|
1714
2183
|
}, undefined, false, undefined, this);
|
|
1715
2184
|
}
|
|
1716
2185
|
// src/components/slots/maps/text-inspector.tsx
|
|
1717
|
-
import { jsxDEV as
|
|
2186
|
+
import { jsxDEV as jsxDEV23 } from "react/jsx-dev-runtime";
|
|
1718
2187
|
function TextInspector({ blockId }) {
|
|
1719
|
-
return /* @__PURE__ */
|
|
2188
|
+
return /* @__PURE__ */ jsxDEV23("div", {
|
|
1720
2189
|
children: blockId
|
|
1721
2190
|
}, undefined, false, undefined, this);
|
|
1722
2191
|
}
|
|
1723
2192
|
// src/components/slots/maps/toolbar.tsx
|
|
1724
|
-
import { cn as
|
|
1725
|
-
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";
|
|
1726
2195
|
|
|
1727
2196
|
// src/lib/selection.utils.ts
|
|
1728
2197
|
function rangeToOffsets(root, range) {
|
|
@@ -1755,61 +2224,88 @@ function offsetsToRange(root, start, end) {
|
|
|
1755
2224
|
}
|
|
1756
2225
|
return null;
|
|
1757
2226
|
}
|
|
1758
|
-
|
|
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;
|
|
1759
2230
|
// src/components/slots/maps/toolbar.tsx
|
|
1760
|
-
import { jsxDEV as
|
|
1761
|
-
var TOOLBAR_OFFSET =
|
|
2231
|
+
import { jsxDEV as jsxDEV24 } from "react/jsx-dev-runtime";
|
|
2232
|
+
var TOOLBAR_OFFSET = 44;
|
|
1762
2233
|
var DEFAULT_STATE = { active: false, top: 0, left: 0 };
|
|
1763
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);
|
|
1764
2244
|
const textSel = useSlice("textSelection");
|
|
1765
2245
|
const currentBlockId = textSel?.blockId;
|
|
1766
|
-
const
|
|
1767
|
-
const { order = new Set } = documentSlice ?? {};
|
|
1768
|
-
const engine = useEngine();
|
|
2246
|
+
const selection = useSlice("selection");
|
|
1769
2247
|
const lastPositionRef = useRef2(DEFAULT_STATE);
|
|
1770
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
|
+
}, []);
|
|
1771
2261
|
const position = useMemo3(() => {
|
|
1772
2262
|
const toolbarElement = toolbarRef.current;
|
|
1773
|
-
if (!
|
|
2263
|
+
if (!toolbarElement || toolbarWidth === 0) {
|
|
1774
2264
|
return DEFAULT_STATE;
|
|
1775
2265
|
}
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
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(() => {
|
|
1796
2292
|
if (position.active) {
|
|
1797
2293
|
lastPositionRef.current = position;
|
|
1798
2294
|
}
|
|
1799
2295
|
}, [position]);
|
|
1800
2296
|
const _position = position.active ? position : lastPositionRef.current;
|
|
1801
|
-
return /* @__PURE__ */
|
|
2297
|
+
return /* @__PURE__ */ jsxDEV24("div", {
|
|
1802
2298
|
ref: toolbarRef,
|
|
1803
2299
|
style: {
|
|
1804
2300
|
top: _position.top,
|
|
1805
2301
|
left: _position.left
|
|
1806
2302
|
},
|
|
1807
|
-
className:
|
|
1808
|
-
"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
|
|
1809
2305
|
}),
|
|
1810
2306
|
...rest,
|
|
1811
2307
|
children: [
|
|
1812
|
-
/* @__PURE__ */
|
|
2308
|
+
/* @__PURE__ */ jsxDEV24(Slots, {
|
|
1813
2309
|
slotName: "toolbar"
|
|
1814
2310
|
}, undefined, false, undefined, this),
|
|
1815
2311
|
children
|
|
@@ -1820,152 +2316,42 @@ function Toolbar({ className, children, ...rest }) {
|
|
|
1820
2316
|
// src/components/slots/maps/index.ts
|
|
1821
2317
|
"use client";
|
|
1822
2318
|
// src/components/corax-flow.tsx
|
|
1823
|
-
import { useEffect as
|
|
2319
|
+
import { useEffect as useEffect10, useReducer } from "react";
|
|
1824
2320
|
|
|
1825
2321
|
// src/hooks/use-renderer.ts
|
|
1826
2322
|
import { useMemo as useMemo4 } from "react";
|
|
2323
|
+
import { ReactRenderer } from "@coorax/render-react";
|
|
2324
|
+
import { UTILS as UTILS2 } from "@coorax/core";
|
|
1827
2325
|
|
|
1828
|
-
// src/
|
|
1829
|
-
import
|
|
1830
|
-
import {
|
|
1831
|
-
UTILS as UTILS3,
|
|
1832
|
-
segments
|
|
1833
|
-
} from "@coorax/core";
|
|
1834
|
-
|
|
1835
|
-
// src/registry/primitives.registry.tsx
|
|
1836
|
-
class PrimitivesComponentsRegistry {
|
|
1837
|
-
components = new Map;
|
|
1838
|
-
get(name) {
|
|
1839
|
-
const sid = Symbol.for(name);
|
|
1840
|
-
const foundCOmp = this.components.get(sid);
|
|
1841
|
-
if (foundCOmp) {
|
|
1842
|
-
return foundCOmp;
|
|
1843
|
-
}
|
|
1844
|
-
return null;
|
|
1845
|
-
}
|
|
1846
|
-
getAll(names) {
|
|
1847
|
-
return names.map((name) => this.get(name));
|
|
1848
|
-
}
|
|
1849
|
-
post(name, comp) {
|
|
1850
|
-
if (comp.length < 1) {
|
|
1851
|
-
throw new Error("Components arguments must be greater than 1");
|
|
1852
|
-
}
|
|
1853
|
-
const sid = Symbol.for(name);
|
|
1854
|
-
this.components.set(sid, comp);
|
|
1855
|
-
}
|
|
1856
|
-
delete(name) {
|
|
1857
|
-
const sid = Symbol.for(name);
|
|
1858
|
-
this.components.delete(sid);
|
|
1859
|
-
}
|
|
1860
|
-
batch(comps) {
|
|
1861
|
-
for (const [key, value] of Object.entries(comps)) {
|
|
1862
|
-
const sid = Symbol.for(key);
|
|
1863
|
-
this.components.set(sid, value);
|
|
1864
|
-
}
|
|
1865
|
-
}
|
|
1866
|
-
}
|
|
1867
|
-
|
|
1868
|
-
// src/hooks/use-block.ts
|
|
1869
|
-
import { useSyncExternalStore as useSyncExternalStore4 } from "react";
|
|
1870
|
-
function useBlock(id) {
|
|
1871
|
-
const engine = useEngine();
|
|
1872
|
-
return useSyncExternalStore4((fn) => engine.document.subscribeBlock(id, fn), () => engine.document.getBlock(id), () => engine.document.getBlock(id));
|
|
1873
|
-
}
|
|
1874
|
-
|
|
1875
|
-
// src/primitives/fields/field.primitives.tsx
|
|
1876
|
-
import { useCallback, useEffect as useEffect5, useRef as useRef3 } from "react";
|
|
1877
|
-
|
|
1878
|
-
// src/hooks/custom/use-isomorphic-layout-effect.ts
|
|
1879
|
-
import { useEffect as useEffect4, useLayoutEffect } from "react";
|
|
1880
|
-
var useIsomorphicLayoutEffect = typeof window !== "undefined" ? useLayoutEffect : useEffect4;
|
|
1881
|
-
|
|
1882
|
-
// src/primitives/fields/field.primitives.tsx
|
|
1883
|
-
import { jsxDEV as jsxDEV15 } from "react/jsx-dev-runtime";
|
|
1884
|
-
function FieldPrimitive({ blockId }) {
|
|
1885
|
-
const blockRef = useRef3(null);
|
|
1886
|
-
const engine = useEngine();
|
|
1887
|
-
const renderer = useRenderer();
|
|
1888
|
-
const block = useBlock(blockId);
|
|
1889
|
-
const sel = useSlice("textSelection");
|
|
1890
|
-
const updateRange = useCallback(() => {
|
|
1891
|
-
if (!sel)
|
|
1892
|
-
return;
|
|
1893
|
-
const root = document.querySelector(`[id="${CSS.escape(sel.blockId)}"][data-text-path="${CSS.escape(sel.path)}"]`);
|
|
1894
|
-
if (!root || !root.contains(document.activeElement))
|
|
1895
|
-
return;
|
|
1896
|
-
const domSel = document.getSelection();
|
|
1897
|
-
if (!domSel)
|
|
1898
|
-
return;
|
|
1899
|
-
if (domSel.rangeCount) {
|
|
1900
|
-
const cur = rangeToOffsets(root, domSel.getRangeAt(0));
|
|
1901
|
-
if (cur.start === sel.start && cur.end === sel.end)
|
|
1902
|
-
return;
|
|
1903
|
-
}
|
|
1904
|
-
const range = offsetsToRange(root, sel.start, sel.end);
|
|
1905
|
-
if (!range)
|
|
1906
|
-
return;
|
|
1907
|
-
domSel.removeAllRanges();
|
|
1908
|
-
domSel.addRange(range);
|
|
1909
|
-
}, [sel]);
|
|
1910
|
-
useIsomorphicLayoutEffect(() => {
|
|
1911
|
-
updateRange();
|
|
1912
|
-
}, [updateRange, engine]);
|
|
1913
|
-
useIsomorphicLayoutEffect(() => {
|
|
1914
|
-
if (!sel)
|
|
1915
|
-
return;
|
|
1916
|
-
const root = document.querySelector(`[id="${CSS.escape(sel.blockId)}"][data-text-path="${CSS.escape(sel.path)}"]`);
|
|
1917
|
-
if (!root)
|
|
1918
|
-
return;
|
|
1919
|
-
const range = offsetsToRange(root, sel.start, sel.end);
|
|
1920
|
-
if (!range)
|
|
1921
|
-
return;
|
|
1922
|
-
root.focus({ preventScroll: true });
|
|
1923
|
-
const domSel = document.getSelection();
|
|
1924
|
-
domSel.removeAllRanges();
|
|
1925
|
-
domSel.addRange(range);
|
|
1926
|
-
});
|
|
1927
|
-
useEffect5(() => {
|
|
1928
|
-
const domEl = blockRef.current;
|
|
1929
|
-
if (!domEl)
|
|
1930
|
-
return;
|
|
1931
|
-
const observer = new ResizeObserver(() => {
|
|
1932
|
-
const rect = blockRectFromBlockId(blockId);
|
|
1933
|
-
if (!rect || !!engine.document.get().order.size)
|
|
1934
|
-
return;
|
|
1935
|
-
engine.commands.tryExecute("blocks.focus", { id: blockId, rect });
|
|
1936
|
-
});
|
|
1937
|
-
observer.observe(domEl);
|
|
1938
|
-
return () => {
|
|
1939
|
-
observer.unobserve(domEl);
|
|
1940
|
-
observer.disconnect();
|
|
1941
|
-
};
|
|
1942
|
-
}, [engine, blockId]);
|
|
1943
|
-
if (!blockId.startsWith("field") || !block)
|
|
1944
|
-
return null;
|
|
1945
|
-
return /* @__PURE__ */ jsxDEV15("div", {
|
|
1946
|
-
ref: blockRef,
|
|
1947
|
-
children: renderer.renderField(block)
|
|
1948
|
-
}, undefined, false, undefined, this);
|
|
1949
|
-
}
|
|
2326
|
+
// src/lifecycle/fields/handlers.registry.ts
|
|
2327
|
+
import { GenericRegistry as GenericRegistry4 } from "@coorax/render-react";
|
|
1950
2328
|
|
|
1951
|
-
// src/
|
|
1952
|
-
var
|
|
1953
|
-
|
|
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();
|
|
1954
2339
|
};
|
|
1955
2340
|
|
|
1956
|
-
// src/
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
UTILS
|
|
1964
|
-
} 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
|
+
};
|
|
1965
2348
|
|
|
1966
|
-
// src/lifecycle/fields/mouse.events/onclick.ts
|
|
2349
|
+
// src/lifecycle/fields/common/mouse.events/onclick.ts
|
|
1967
2350
|
var createOnClick = async (engine, block, ev) => {
|
|
1968
2351
|
ev.stopPropagation();
|
|
2352
|
+
if (block.type === "iframe") {
|
|
2353
|
+
ev.preventDefault();
|
|
2354
|
+
}
|
|
1969
2355
|
const fieldInfo = getFieldTypeAndTargetId(engine, ev, block);
|
|
1970
2356
|
if (!fieldInfo)
|
|
1971
2357
|
return;
|
|
@@ -2020,44 +2406,23 @@ var createOnClick = async (engine, block, ev) => {
|
|
|
2020
2406
|
await fieldInfo.emit();
|
|
2021
2407
|
};
|
|
2022
2408
|
|
|
2023
|
-
// src/lifecycle/fields/mouse.events/
|
|
2024
|
-
var
|
|
2025
|
-
ev.stopPropagation();
|
|
2409
|
+
// src/lifecycle/fields/common/mouse.events/onmouseenter.ts
|
|
2410
|
+
var createOnMouseEnter = async (engine, block, ev) => {
|
|
2026
2411
|
const fieldInfo = getFieldTypeAndTargetId(engine, ev, block);
|
|
2027
2412
|
if (!fieldInfo)
|
|
2028
2413
|
return;
|
|
2029
|
-
const
|
|
2030
|
-
if (
|
|
2031
|
-
return;
|
|
2032
|
-
const focus = engine.state.get("focus");
|
|
2033
|
-
if (focus?.id === block.id) {
|
|
2414
|
+
const selection = engine.state.get("selection");
|
|
2415
|
+
if (selection && selection.blocks.has(block.id)) {
|
|
2034
2416
|
return;
|
|
2035
2417
|
}
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
};
|
|
2039
|
-
|
|
2040
|
-
// src/lifecycle/fields/focus.events/onfocus.ts
|
|
2041
|
-
var createOnFocus = async (engine, block, ev) => {
|
|
2042
|
-
const fieldInfo = getFieldTypeAndTargetId(engine, ev, block);
|
|
2043
|
-
if (!fieldInfo)
|
|
2044
|
-
return;
|
|
2045
|
-
await fieldInfo.emit();
|
|
2046
|
-
};
|
|
2047
|
-
|
|
2048
|
-
// src/lifecycle/fields/focus.events/onblur.ts
|
|
2049
|
-
var createOnBlur = async (engine, block, ev) => {
|
|
2050
|
-
const fieldInfo = getFieldTypeAndTargetId(engine, ev, block);
|
|
2051
|
-
if (!fieldInfo)
|
|
2052
|
-
return;
|
|
2053
|
-
const textSel = engine.state.get("textSelection");
|
|
2054
|
-
if (textSel && textSel.start !== textSel.end)
|
|
2418
|
+
const rect = blockRectFromBlockId(block.id);
|
|
2419
|
+
if (!rect)
|
|
2055
2420
|
return;
|
|
2056
|
-
engine.commands.tryExecute("blocks.
|
|
2421
|
+
engine.commands.tryExecute("blocks.hover", { id: block.id, rect });
|
|
2057
2422
|
await fieldInfo.emit();
|
|
2058
2423
|
};
|
|
2059
2424
|
|
|
2060
|
-
// src/lifecycle/fields/mouse.events/onmouseleave.ts
|
|
2425
|
+
// src/lifecycle/fields/common/mouse.events/onmouseleave.ts
|
|
2061
2426
|
var createOnMouseLeave = async (engine, block, ev) => {
|
|
2062
2427
|
const fieldInfo = getFieldTypeAndTargetId(engine, ev, block);
|
|
2063
2428
|
if (!fieldInfo)
|
|
@@ -2071,28 +2436,86 @@ var createOnMouseLeave = async (engine, block, ev) => {
|
|
|
2071
2436
|
await fieldInfo.emit();
|
|
2072
2437
|
};
|
|
2073
2438
|
|
|
2074
|
-
// src/lifecycle/fields/
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
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) => {
|
|
2453
|
+
const fieldInfo = getFieldTypeAndTargetId(engine, ev, block);
|
|
2454
|
+
if (!fieldInfo)
|
|
2081
2455
|
return;
|
|
2082
|
-
|
|
2083
|
-
const rect = blockRectFromBlockId(block.id);
|
|
2084
|
-
if (!rect)
|
|
2456
|
+
if (ev.ctrlKey || ev.metaKey)
|
|
2085
2457
|
return;
|
|
2086
|
-
engine.
|
|
2087
|
-
|
|
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}`);
|
|
2463
|
+
return;
|
|
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
|
+
}
|
|
2088
2504
|
};
|
|
2089
2505
|
|
|
2090
|
-
// 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
|
|
2091
2515
|
import {
|
|
2092
|
-
FieldsUtils
|
|
2093
|
-
isEditableField
|
|
2516
|
+
FieldsUtils as FieldsUtils2
|
|
2094
2517
|
} from "@coorax/core";
|
|
2095
|
-
var
|
|
2518
|
+
var createOnKeyDown2 = async (engine, block, ev) => {
|
|
2096
2519
|
const fieldInfo = getFieldTypeAndTargetId(engine, ev, block);
|
|
2097
2520
|
if (!fieldInfo)
|
|
2098
2521
|
return;
|
|
@@ -2111,7 +2534,7 @@ var createOnKeyDown = async (engine, block, ev) => {
|
|
|
2111
2534
|
if (ev.key === "Enter" && !ev.shiftKey) {
|
|
2112
2535
|
ev.preventDefault();
|
|
2113
2536
|
currentTarget.blur();
|
|
2114
|
-
const newField =
|
|
2537
|
+
const newField = FieldsUtils2.NewField("text");
|
|
2115
2538
|
engine.commands.tryExecute("blocks.insert", { block: newField, pos: index });
|
|
2116
2539
|
await fieldInfo.emit();
|
|
2117
2540
|
const blockRect = blockRectFromBlockId(newField.id);
|
|
@@ -2142,44 +2565,50 @@ var createOnKeyDown = async (engine, block, ev) => {
|
|
|
2142
2565
|
if (ev.key === "Escape") {
|
|
2143
2566
|
ev.preventDefault();
|
|
2144
2567
|
currentTarget.blur();
|
|
2145
|
-
|
|
2146
|
-
engine.commands.tryExecute("blocks.select", { blocks: new Map, mode: "replace" });
|
|
2147
|
-
}
|
|
2568
|
+
engine.commands.tryExecute("blocks.focus", null);
|
|
2148
2569
|
}
|
|
2149
2570
|
if (ev.key === "Backspace") {
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
if (!blockRect) {
|
|
2159
|
-
engine.commands.tryExecute("blocks.focus", null);
|
|
2160
|
-
return;
|
|
2161
|
-
}
|
|
2162
|
-
if (isEditableField(prevSiblingBlock)) {
|
|
2163
|
-
engine.commands.tryExecute("blocks.focus", {
|
|
2164
|
-
id: prevSiblingBlock.id,
|
|
2165
|
-
rect: blockRect
|
|
2166
|
-
});
|
|
2167
|
-
} else {
|
|
2168
|
-
engine.commands.tryExecute("blocks.select", {
|
|
2169
|
-
blocks: new Map().set(prevSiblingBlock.id, blockRect),
|
|
2170
|
-
mode: "replace"
|
|
2171
|
-
});
|
|
2172
|
-
}
|
|
2173
|
-
} 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) {
|
|
2174
2579
|
engine.commands.tryExecute("blocks.focus", null);
|
|
2580
|
+
return;
|
|
2175
2581
|
}
|
|
2176
|
-
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);
|
|
2177
2588
|
}
|
|
2589
|
+
engine.commands.tryExecute("blocks.delete", { blockId: block.id });
|
|
2178
2590
|
}
|
|
2179
2591
|
}
|
|
2180
2592
|
};
|
|
2181
2593
|
|
|
2182
|
-
// 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
|
|
2183
2612
|
var createOnSelect = async (engine, block, ev) => {
|
|
2184
2613
|
const fieldInfo = getFieldTypeAndTargetId(engine, ev, block);
|
|
2185
2614
|
if (!fieldInfo)
|
|
@@ -2209,318 +2638,329 @@ var createOnSelect = async (engine, block, ev) => {
|
|
|
2209
2638
|
await fieldInfo.emit();
|
|
2210
2639
|
};
|
|
2211
2640
|
|
|
2212
|
-
// 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
|
|
2213
2652
|
var createOnLoad = async (engine, block, ev) => {
|
|
2214
2653
|
const fieldInfo = getFieldTypeAndTargetId(engine, ev, block);
|
|
2215
|
-
if (!fieldInfo)
|
|
2654
|
+
if (!fieldInfo || !block.props?.src?.trim())
|
|
2216
2655
|
return;
|
|
2217
|
-
|
|
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
|
+
});
|
|
2218
2665
|
await fieldInfo.emit();
|
|
2219
2666
|
};
|
|
2220
2667
|
|
|
2221
|
-
// src/lifecycle/fields/
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
const
|
|
2225
|
-
if (!
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
|
|
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;
|
|
2230
2682
|
}
|
|
2231
|
-
const
|
|
2232
|
-
const
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
|
|
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 });
|
|
2240
2696
|
}
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
};
|
|
2258
|
-
case "img":
|
|
2259
|
-
case "video":
|
|
2260
|
-
return {
|
|
2261
|
-
onClick: createOnClick.bind(null, engine, block),
|
|
2262
|
-
onKeyDown: createOnKeyDown.bind(null, engine, block),
|
|
2263
|
-
onFocus: createOnFocus.bind(null, engine, block),
|
|
2264
|
-
onMouseEnter: createOnMouseEnter.bind(null, engine, block),
|
|
2265
|
-
onMouseLeave: createOnMouseLeave.bind(null, engine, block),
|
|
2266
|
-
onLoad: createOnLoad.bind(null, engine, block)
|
|
2267
|
-
};
|
|
2268
|
-
case "hr":
|
|
2269
|
-
return {
|
|
2270
|
-
onClick: createOnClick.bind(null, engine, block),
|
|
2271
|
-
onMouseEnter: createOnMouseEnter.bind(null, engine, block),
|
|
2272
|
-
onMouseLeave: createOnMouseLeave.bind(null, engine, block)
|
|
2273
|
-
};
|
|
2274
|
-
default:
|
|
2275
|
-
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;
|
|
2276
2713
|
}
|
|
2714
|
+
currentTarget.blur();
|
|
2715
|
+
engine.commands.tryExecute("blocks.focus", { id: rectId, rect });
|
|
2277
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);
|
|
2278
2741
|
return {
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
|
|
2283
|
-
|
|
2742
|
+
onClick,
|
|
2743
|
+
onMouseEnter,
|
|
2744
|
+
onMouseLeave,
|
|
2745
|
+
onFocus,
|
|
2746
|
+
onKeyDown: createOnKeyDown3.bind(null, engine, block),
|
|
2747
|
+
onError: createOnError.bind(null, engine, block)
|
|
2284
2748
|
};
|
|
2285
2749
|
}
|
|
2286
|
-
function getFieldLifeCycleEvents(engine, tag, block) {
|
|
2287
|
-
return getAllLifeCycleEvents(engine, block)[tag];
|
|
2288
|
-
}
|
|
2289
|
-
var FLC = { getFieldLifeCycleEvents };
|
|
2290
2750
|
|
|
2291
|
-
// src/
|
|
2292
|
-
|
|
2293
|
-
import { css } from "@emotion/css";
|
|
2294
|
-
function getTextFieldProps(engine, block) {
|
|
2295
|
-
const ui = engine.ui;
|
|
2296
|
-
const { style, pseudoStyle, className, children: _, placeholder, ...rest } = block.props;
|
|
2297
|
-
const uiStyles = ui.getStyle(block.type);
|
|
2298
|
-
const _pseudoStyle = {
|
|
2299
|
-
...uiStyles.pseudoStyle,
|
|
2300
|
-
...pseudoStyle
|
|
2301
|
-
};
|
|
2302
|
-
const pseudoClassName = resolveCoraxPseudoStyle(_pseudoStyle);
|
|
2303
|
-
const baseProps = {
|
|
2304
|
-
id: block.id,
|
|
2305
|
-
key: block.id,
|
|
2306
|
-
"data-block-type": block.type,
|
|
2307
|
-
style: {
|
|
2308
|
-
...uiStyles.style,
|
|
2309
|
-
...style,
|
|
2310
|
-
...block.props?.contentEditable ? { cursor: "auto", userSelect: "auto" } : null
|
|
2311
|
-
},
|
|
2312
|
-
className: cn7(uiStyles.className, className, pseudoClassName)
|
|
2313
|
-
};
|
|
2314
|
-
const containerProps = block.isContainerized() ? { "data-containerId": block.containerId } : {};
|
|
2315
|
-
const editableProps = {
|
|
2316
|
-
spellCheck: false,
|
|
2317
|
-
suppressContentEditableWarning: true,
|
|
2318
|
-
"data-placeholder": placeholder || "Tell the news here",
|
|
2319
|
-
...rest,
|
|
2320
|
-
contentEditable: !!rest?.contentEditable,
|
|
2321
|
-
autoFocus: true
|
|
2322
|
-
};
|
|
2751
|
+
// src/lifecycle/fields/media/image/handlers.ts
|
|
2752
|
+
function buildImageHandlers(engine, block) {
|
|
2323
2753
|
return {
|
|
2324
|
-
...
|
|
2325
|
-
|
|
2326
|
-
...editableProps,
|
|
2327
|
-
...FLC.getFieldLifeCycleEvents(engine, block.tag, block)
|
|
2754
|
+
...buildMediaHandlers(engine, block),
|
|
2755
|
+
onLoad: createOnLoad.bind(null, engine, block)
|
|
2328
2756
|
};
|
|
2329
2757
|
}
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
const
|
|
2334
|
-
|
|
2335
|
-
|
|
2336
|
-
|
|
2337
|
-
};
|
|
2338
|
-
const pseudoClassName = resolveCoraxPseudoStyle(_pseudoStyle);
|
|
2339
|
-
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, {
|
|
2340
2765
|
id: block.id,
|
|
2341
|
-
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
|
|
2347
|
-
|
|
2348
|
-
|
|
2349
|
-
|
|
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) {
|
|
2350
2795
|
return {
|
|
2351
|
-
...
|
|
2352
|
-
|
|
2353
|
-
|
|
2354
|
-
...FLC.getFieldLifeCycleEvents(engine, block.tag, block)
|
|
2796
|
+
...buildMediaHandlers(engine, block),
|
|
2797
|
+
onCanPlayThrough: createVideoOnCanPlayThrough.bind(null, engine, block),
|
|
2798
|
+
onDoubleClick: createVideoOnDoubleClick.bind(null, engine, block)
|
|
2355
2799
|
};
|
|
2356
2800
|
}
|
|
2357
|
-
function resolveCoraxPseudoStyle(style) {
|
|
2358
|
-
if (!style || Object.keys(style).length === 0)
|
|
2359
|
-
return;
|
|
2360
|
-
return css(style);
|
|
2361
|
-
}
|
|
2362
2801
|
|
|
2363
|
-
// src/
|
|
2364
|
-
|
|
2365
|
-
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
|
|
2369
|
-
const _pseudoStyle = {
|
|
2370
|
-
...uiStyles.pseudoStyle,
|
|
2371
|
-
...pseudoStyle
|
|
2372
|
-
};
|
|
2373
|
-
const pseudoClassName = resolveCoraxPseudoStyle(_pseudoStyle);
|
|
2374
|
-
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, {
|
|
2375
2808
|
id: block.id,
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
|
|
2382
|
-
|
|
2383
|
-
|
|
2384
|
-
|
|
2385
|
-
|
|
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) {
|
|
2386
2821
|
return {
|
|
2387
|
-
...
|
|
2388
|
-
|
|
2389
|
-
...rest,
|
|
2390
|
-
...handlers
|
|
2822
|
+
...buildMediaHandlers(engine, block),
|
|
2823
|
+
onLoad: createIframeOnLoad.bind(null, engine, block)
|
|
2391
2824
|
};
|
|
2392
2825
|
}
|
|
2393
2826
|
|
|
2394
|
-
// src/
|
|
2395
|
-
|
|
2396
|
-
var defaults = {
|
|
2397
|
-
bold: "strong",
|
|
2398
|
-
italic: "em",
|
|
2399
|
-
underline: "u",
|
|
2400
|
-
code: "code",
|
|
2401
|
-
link: "span",
|
|
2402
|
-
initial: "span"
|
|
2403
|
-
};
|
|
2404
|
-
var RANK = {
|
|
2405
|
-
link: 0,
|
|
2406
|
-
bold: 1,
|
|
2407
|
-
italic: 2,
|
|
2408
|
-
underline: 3,
|
|
2409
|
-
code: 4,
|
|
2410
|
-
initial: 5
|
|
2411
|
-
};
|
|
2412
|
-
function formatText(text) {
|
|
2413
|
-
return text;
|
|
2827
|
+
// src/lifecycle/fields/handlers.registry.ts
|
|
2828
|
+
class FieldHandlersRegistry extends GenericRegistry4 {
|
|
2414
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);
|
|
2415
2841
|
|
|
2416
|
-
|
|
2417
|
-
|
|
2418
|
-
|
|
2419
|
-
|
|
2420
|
-
|
|
2421
|
-
|
|
2422
|
-
|
|
2423
|
-
|
|
2424
|
-
|
|
2425
|
-
|
|
2426
|
-
|
|
2427
|
-
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
|
|
2435
|
-
|
|
2436
|
-
return
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
|
|
2442
|
-
|
|
2443
|
-
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
|
|
2447
|
-
}, this.renderTextContent(children));
|
|
2448
|
-
}
|
|
2449
|
-
renderMediaField(field, key = null) {
|
|
2450
|
-
const isMediaReady = !!field.props.src.trim();
|
|
2451
|
-
if (!isMediaReady) {
|
|
2452
|
-
const Fallback = FallbackComponentsRegistry.get(field.type);
|
|
2453
|
-
if (Fallback)
|
|
2454
|
-
return /* @__PURE__ */ jsxDEV16(Fallback, {
|
|
2455
|
-
...field
|
|
2456
|
-
}, undefined, false, undefined, this);
|
|
2457
|
-
}
|
|
2458
|
-
return React5.createElement(field.tag, {
|
|
2459
|
-
...getMediaFieldProps(this.engine, field),
|
|
2460
|
-
key: key !== null ? key : field.id
|
|
2461
|
-
});
|
|
2462
|
-
}
|
|
2463
|
-
renderDividerField(field, key = null) {
|
|
2464
|
-
return React5.createElement(field.tag, {
|
|
2465
|
-
...getDividerFieldProps(this.engine, field),
|
|
2466
|
-
key: key !== null ? key : field.id
|
|
2467
|
-
});
|
|
2468
|
-
}
|
|
2469
|
-
renderField(_field, key = null) {
|
|
2470
|
-
const field = typeof _field === "string" ? this.engine.document.getBlock(_field) : _field;
|
|
2471
|
-
if (!field || field.variant !== "field")
|
|
2472
|
-
return /* @__PURE__ */ jsxDEV16(Fragment3, {}, undefined, false, undefined, this);
|
|
2473
|
-
switch (field.type) {
|
|
2474
|
-
case "text":
|
|
2475
|
-
case "heading":
|
|
2476
|
-
return this.renderTextField(field, key);
|
|
2477
|
-
case "video":
|
|
2478
|
-
case "image":
|
|
2479
|
-
return this.renderMediaField(field, key);
|
|
2480
|
-
case "divider":
|
|
2481
|
-
return this.renderDividerField(field);
|
|
2482
|
-
default:
|
|
2483
|
-
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;
|
|
2484
2873
|
}
|
|
2485
|
-
|
|
2486
|
-
|
|
2487
|
-
|
|
2488
|
-
|
|
2489
|
-
|
|
2490
|
-
|
|
2491
|
-
|
|
2492
|
-
|
|
2493
|
-
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
|
|
2503
|
-
|
|
2504
|
-
|
|
2505
|
-
|
|
2506
|
-
|
|
2507
|
-
|
|
2508
|
-
|
|
2509
|
-
|
|
2510
|
-
|
|
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);
|
|
2511
2934
|
}
|
|
2512
2935
|
|
|
2936
|
+
// src/primitives/index.ts
|
|
2937
|
+
var FieldsPrimitives = {
|
|
2938
|
+
field: FieldPrimitive
|
|
2939
|
+
};
|
|
2940
|
+
|
|
2513
2941
|
// src/hooks/use-renderer.ts
|
|
2514
2942
|
function useRenderer() {
|
|
2515
2943
|
const engine = useEngine();
|
|
2516
|
-
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]);
|
|
2517
2957
|
}
|
|
2518
2958
|
|
|
2519
2959
|
// src/hooks/use-flow.ts
|
|
2520
|
-
import { useEffect as
|
|
2960
|
+
import { useEffect as useEffect8 } from "react";
|
|
2521
2961
|
|
|
2522
2962
|
// src/hooks/custom/use-custom-ref.ts
|
|
2523
|
-
import { useEffect as
|
|
2963
|
+
import { useEffect as useEffect7, useRef as useRef4 } from "react";
|
|
2524
2964
|
function useCustomRef(factory) {
|
|
2525
2965
|
const isServer = typeof window === "undefined";
|
|
2526
2966
|
const getInitialValue = () => {
|
|
@@ -2533,7 +2973,7 @@ function useCustomRef(factory) {
|
|
|
2533
2973
|
}
|
|
2534
2974
|
};
|
|
2535
2975
|
const ref = useRef4(getInitialValue());
|
|
2536
|
-
|
|
2976
|
+
useEffect7(() => {
|
|
2537
2977
|
try {
|
|
2538
2978
|
ref.current = typeof factory === "function" ? factory() : factory;
|
|
2539
2979
|
} catch {}
|
|
@@ -2572,7 +3012,7 @@ function useFlow() {
|
|
|
2572
3012
|
engine.commands.tryExecute("editor.rect", { editorRect: editorRectFromDomElement(flowEditor) });
|
|
2573
3013
|
return flowEditor;
|
|
2574
3014
|
});
|
|
2575
|
-
|
|
3015
|
+
useEffect8(() => {
|
|
2576
3016
|
function handleKeyDown(ev) {
|
|
2577
3017
|
if (!ev.ctrlKey || ev.key.toLocaleLowerCase() !== "z")
|
|
2578
3018
|
return;
|
|
@@ -2598,7 +3038,7 @@ function useFlow() {
|
|
|
2598
3038
|
}
|
|
2599
3039
|
};
|
|
2600
3040
|
}, [engine, coraxFlowEditorRef]);
|
|
2601
|
-
|
|
3041
|
+
useEffect8(() => {
|
|
2602
3042
|
const element = coraxFlowEditorRef.current;
|
|
2603
3043
|
if (!element)
|
|
2604
3044
|
return;
|
|
@@ -2613,12 +3053,24 @@ function useFlow() {
|
|
|
2613
3053
|
element.removeEventListener("scroll", publishEditorRect);
|
|
2614
3054
|
};
|
|
2615
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]);
|
|
2616
3068
|
}
|
|
2617
3069
|
|
|
2618
3070
|
// src/hooks/use-text-input.ts
|
|
2619
|
-
import { useEffect as
|
|
3071
|
+
import { useEffect as useEffect9 } from "react";
|
|
2620
3072
|
function useTextInput(engine) {
|
|
2621
|
-
|
|
3073
|
+
useEffect9(() => {
|
|
2622
3074
|
let composing = false;
|
|
2623
3075
|
const rootOf = (t) => ((t instanceof Element ? t : t?.parentElement) ?? null)?.closest("[data-text-path]") ?? null;
|
|
2624
3076
|
const onBeforeInput = (e) => {
|
|
@@ -2631,7 +3083,7 @@ function useTextInput(engine) {
|
|
|
2631
3083
|
r.setStart(tr.startContainer, tr.startOffset);
|
|
2632
3084
|
r.setEnd(tr.endContainer, tr.endOffset);
|
|
2633
3085
|
engine.commands.tryExecute("text.setSelection", {
|
|
2634
|
-
blockId: root.
|
|
3086
|
+
blockId: root.id,
|
|
2635
3087
|
path: root.dataset.textPath,
|
|
2636
3088
|
...rangeToOffsets(root, r)
|
|
2637
3089
|
});
|
|
@@ -2693,8 +3145,8 @@ function useTextInput(engine) {
|
|
|
2693
3145
|
}
|
|
2694
3146
|
|
|
2695
3147
|
// src/components/corax-flow.tsx
|
|
2696
|
-
import { cn as
|
|
2697
|
-
import { jsxDEV as
|
|
3148
|
+
import { cn as cn14 } from "cn";
|
|
3149
|
+
import { jsxDEV as jsxDEV26 } from "react/jsx-dev-runtime";
|
|
2698
3150
|
"use client";
|
|
2699
3151
|
function CoraxFlow({
|
|
2700
3152
|
children,
|
|
@@ -2705,47 +3157,69 @@ function CoraxFlow({
|
|
|
2705
3157
|
const renderer = useRenderer();
|
|
2706
3158
|
useFlow();
|
|
2707
3159
|
useTextInput(engine);
|
|
2708
|
-
|
|
2709
|
-
const
|
|
2710
|
-
|
|
2711
|
-
|
|
2712
|
-
|
|
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());
|
|
2713
3169
|
}, [engine]);
|
|
2714
|
-
return /* @__PURE__ */
|
|
3170
|
+
return /* @__PURE__ */ jsxDEV26("div", {
|
|
2715
3171
|
id: "corax_flow_editor",
|
|
2716
|
-
className: "relative flex flex-col w-full
|
|
2717
|
-
children:
|
|
2718
|
-
"
|
|
2719
|
-
|
|
2720
|
-
|
|
2721
|
-
|
|
2722
|
-
children
|
|
2723
|
-
|
|
2724
|
-
|
|
2725
|
-
|
|
2726
|
-
}, undefined, true, undefined, this)
|
|
2727
|
-
]
|
|
2728
|
-
}, 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);
|
|
2729
3182
|
}
|
|
2730
3183
|
|
|
2731
3184
|
// src/components/index.ts
|
|
2732
3185
|
"use client";
|
|
2733
3186
|
// src/index.ts
|
|
2734
3187
|
export * from "@coorax/core";
|
|
3188
|
+
export * from "@coorax/render-react";
|
|
2735
3189
|
"use client";
|
|
2736
3190
|
export {
|
|
2737
3191
|
useUIContext,
|
|
2738
3192
|
useSlice,
|
|
2739
3193
|
useIsomorphicLayoutEffect,
|
|
2740
3194
|
useEngine,
|
|
3195
|
+
rangeToOffsets,
|
|
3196
|
+
offsetsToRange,
|
|
2741
3197
|
loadCompleteDocument,
|
|
3198
|
+
getFieldTypeAndTargetId,
|
|
3199
|
+
getBlockActionsProps,
|
|
3200
|
+
forField,
|
|
3201
|
+
focusDomElement,
|
|
3202
|
+
focusDomBLockById,
|
|
3203
|
+
blockRectFromBlockId,
|
|
3204
|
+
UIPrimitivesRegistry,
|
|
2742
3205
|
Toolbar,
|
|
2743
3206
|
TextInspector,
|
|
2744
3207
|
SlotsModule,
|
|
3208
|
+
SlotsComponentRegistry,
|
|
3209
|
+
PrimitivesComponentsRegistry,
|
|
2745
3210
|
Overlays,
|
|
3211
|
+
LocalDB,
|
|
3212
|
+
GenericRegistry3 as GenericRegistry,
|
|
3213
|
+
FieldHandlersRegistry,
|
|
3214
|
+
FieldHandlers,
|
|
2746
3215
|
FallbacksModule,
|
|
3216
|
+
FallbackComponentsRegistry,
|
|
3217
|
+
FLC,
|
|
3218
|
+
ErrorComponentsRegistry,
|
|
3219
|
+
CoraxIcon,
|
|
2747
3220
|
CoraxFlow,
|
|
2748
3221
|
CoraxEngineProvider,
|
|
3222
|
+
CORAX_INDEXED_DB,
|
|
2749
3223
|
BlockActions,
|
|
2750
3224
|
AutoSaveModule
|
|
2751
3225
|
};
|