@coorax/react 0.0.0-canary.2 → 0.0.0-canary.4
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/button.d.ts +8 -0
- package/dist/components/corax-context-provider.d.ts +6 -0
- package/dist/components/corax-flow.d.ts +4 -0
- package/dist/components/fallbacks/image.fallback.d.ts +3 -0
- package/dist/components/slots/buttons/block-actions-button.d.ts +3 -0
- package/dist/components/slots/buttons/toolbar-button.d.ts +3 -0
- package/dist/components/slots/maps/block-actions.d.ts +1 -0
- package/dist/components/slots/maps/overlays.d.ts +1 -0
- package/dist/components/slots/maps/text-inspector.d.ts +2 -0
- package/dist/components/slots/maps/toolbar.d.ts +1 -0
- package/dist/components/slots/overlays/focus-overlay.d.ts +3 -0
- package/dist/components/slots/overlays/hover-overlay.d.ts +3 -0
- package/dist/components/slots/overlays/selection-overlay.d.ts +3 -0
- package/dist/components/slots/slot-button.d.ts +6 -0
- package/dist/components/slots/slot-component.d.ts +5 -0
- package/dist/components/slots/slots.d.ts +4 -0
- package/dist/constants/field.constants.d.ts +2 -0
- package/dist/hooks/custom/use-custom-ref.d.ts +1 -0
- package/dist/hooks/custom/use-isomorphic-layout-effect.d.ts +2 -0
- package/{src/hooks/index.ts → dist/hooks/index.d.ts} +1 -0
- package/dist/hooks/use-block-entry.d.ts +2 -0
- package/dist/hooks/use-block.d.ts +2 -0
- package/dist/hooks/use-flow.d.ts +17 -0
- package/dist/hooks/use-keyboard.d.ts +10 -0
- package/dist/hooks/use-registry.d.ts +3 -0
- package/dist/hooks/use-renderer.d.ts +2 -0
- package/dist/hooks/use-slice.d.ts +2 -0
- package/dist/hooks/use-slots.d.ts +2 -0
- package/dist/hooks/use-tasks.d.ts +7 -0
- package/dist/hooks/use-text-input.d.ts +2 -0
- package/dist/hooks/use-ui-context.d.ts +2 -0
- package/dist/hooks/useSelection.d.ts +2 -0
- package/{src/index.ts → dist/index.d.ts} +7 -4
- package/dist/index.js +2774 -0
- package/dist/lib/comp.utils.d.ts +4 -0
- package/dist/lib/func.utils.d.ts +3 -0
- package/dist/lib/index.d.ts +4 -0
- package/dist/lib/selection.utils.d.ts +5 -0
- package/dist/lib/slots.utils.d.ts +4 -0
- package/dist/lifecycle/fields/focus.events/onbeforeinput.d.ts +3 -0
- package/dist/lifecycle/fields/focus.events/onblur.d.ts +3 -0
- package/dist/lifecycle/fields/focus.events/onfocus.d.ts +3 -0
- package/dist/lifecycle/fields/keyboard.events/onkeydown.d.ts +3 -0
- package/dist/lifecycle/fields/lifecycle.fields.d.ts +12 -0
- package/dist/lifecycle/fields/lifecycle.fields.types.d.ts +15 -0
- package/dist/lifecycle/fields/lifecycle.utils.d.ts +2 -0
- package/dist/lifecycle/fields/mouse.events/onclick.d.ts +3 -0
- package/dist/lifecycle/fields/mouse.events/ondoubleclick.d.ts +4 -0
- package/dist/lifecycle/fields/mouse.events/onmouseenter.d.ts +3 -0
- package/dist/lifecycle/fields/mouse.events/onmouseleave.d.ts +3 -0
- package/dist/lifecycle/fields/synthetic.events/onload.d.ts +3 -0
- package/dist/lifecycle/fields/synthetic.events/onselect.d.ts +3 -0
- package/dist/lifecycle/index.d.ts +3 -0
- package/dist/modules/autosave.module.d.ts +31 -0
- package/dist/modules/fallbacks.module.d.ts +7 -0
- package/dist/modules/slots.module.d.ts +7 -0
- package/dist/modules/ui-primitives.module.d.ts +7 -0
- package/dist/primitives/fields/field.primitives.d.ts +2 -0
- package/dist/primitives/index.d.ts +3 -0
- package/{src/registry/fallbacks.registry.tsx → dist/registry/fallbacks.registry.d.ts} +3 -4
- package/dist/registry/primitives.registry.d.ts +22 -0
- package/dist/registry/registry.d.ts +15 -0
- package/dist/registry/slots.registry.d.ts +4 -0
- package/{src/registry/ui.primitives.registry.tsx → dist/registry/ui.primitives.registry.d.ts} +3 -4
- package/dist/renderer/renderer.d.ts +23 -0
- package/dist/renderer/renderer.test.d.ts +1 -0
- package/{src/renderer/renderer.types.ts → dist/renderer/renderer.types.d.ts} +0 -1
- package/dist/renderer/renderer.utils.d.ts +14 -0
- package/dist/renderer/utils/divider.renderer.utils.d.ts +6 -0
- package/dist/services/index.d.ts +1 -0
- package/dist/services/localdb/db/db.d.ts +74 -0
- package/dist/services/localdb/db/db.test.d.ts +1 -0
- package/dist/services/localdb/lexer/lexer.d.ts +14 -0
- package/dist/services/localdb/lexer/lexer.test.d.ts +1 -0
- package/dist/services/localdb/lexer/lexer.types.d.ts +5 -0
- package/dist/services/localdb/operator/operator.d.ts +10 -0
- package/dist/services/localdb/parser/parser.constants.d.ts +3 -0
- package/dist/services/localdb/parser/parser.d.ts +14 -0
- package/dist/services/localdb/parser/parser.test.d.ts +1 -0
- package/dist/services/localdb/parser/parser.types.d.ts +43 -0
- package/dist/services/localdb/sheet/sheet.constants.d.ts +3 -0
- package/dist/services/localdb/sheet/sheet.d.ts +14 -0
- package/dist/services/localdb/sheet/sheet.types.d.ts +13 -0
- package/dist/styles.css +1094 -0
- package/package.json +29 -12
- package/.oxlintrc.json +0 -8
- package/src/components/commons/button.tsx +0 -59
- package/src/components/corax-context-provider.tsx +0 -47
- package/src/components/corax-flow.tsx +0 -44
- package/src/components/fallbacks/image.fallback.tsx +0 -23
- package/src/components/slots/buttons/block-actions-button.tsx +0 -85
- package/src/components/slots/buttons/toolbar-button.tsx +0 -40
- package/src/components/slots/maps/block-actions.tsx +0 -84
- package/src/components/slots/maps/overlays.tsx +0 -9
- package/src/components/slots/maps/text-inspector.tsx +0 -5
- package/src/components/slots/maps/toolbar.tsx +0 -79
- package/src/components/slots/overlays/focus-overlay.tsx +0 -30
- package/src/components/slots/overlays/hover-overlay.tsx +0 -18
- package/src/components/slots/overlays/selection-overlay.tsx +0 -20
- package/src/components/slots/slot-button.tsx +0 -20
- package/src/components/slots/slot-component.tsx +0 -17
- package/src/components/slots/slots.tsx +0 -29
- package/src/constants/field.constants.ts +0 -3
- package/src/hooks/custom/use-custom-ref.ts +0 -11
- package/src/hooks/use-block-entry.ts +0 -44
- package/src/hooks/use-block.ts +0 -11
- package/src/hooks/use-flow.ts +0 -83
- package/src/hooks/use-keyboard.ts +0 -66
- package/src/hooks/use-registry.ts +0 -18
- package/src/hooks/use-renderer.ts +0 -8
- package/src/hooks/use-slice.ts +0 -13
- package/src/hooks/use-slots.ts +0 -13
- package/src/hooks/use-tasks.ts +0 -33
- package/src/hooks/use-text-input.ts +0 -83
- package/src/hooks/use-ui-context.ts +0 -16
- package/src/hooks/useSelection.ts +0 -27
- package/src/lib/comp.utils.tsx +0 -44
- package/src/lib/func.utils.ts +0 -15
- package/src/lib/selection.utils.ts +0 -33
- package/src/lib/slots.utils.tsx +0 -23
- package/src/lifecycle/fields/focus.events/onbeforeinput.ts +0 -21
- package/src/lifecycle/fields/focus.events/onblur.ts +0 -19
- package/src/lifecycle/fields/focus.events/onfocus.ts +0 -16
- package/src/lifecycle/fields/keyboard.events/onkeydown.ts +0 -128
- package/src/lifecycle/fields/lifecycle.fields.ts +0 -116
- package/src/lifecycle/fields/lifecycle.fields.types.ts +0 -33
- package/src/lifecycle/fields/lifecycle.utils.ts +0 -26
- package/src/lifecycle/fields/mouse.events/onclick.ts +0 -79
- package/src/lifecycle/fields/mouse.events/ondoubleclick.ts +0 -27
- package/src/lifecycle/fields/mouse.events/onmouseenter.ts +0 -27
- package/src/lifecycle/fields/mouse.events/onmouseleave.ts +0 -21
- package/src/lifecycle/fields/synthetic.events/onload.ts +0 -16
- package/src/lifecycle/fields/synthetic.events/onselect.ts +0 -57
- package/src/lifecycle/index.ts +0 -1
- package/src/modules/autosave.module.ts +0 -238
- package/src/modules/fallbacks.module.tsx +0 -19
- package/src/modules/slots.module.tsx +0 -28
- package/src/modules/ui-primitives.module.tsx +0 -20
- package/src/primitives/fields/field.primitives.tsx +0 -86
- package/src/primitives/index.ts +0 -8
- package/src/registry/primitives.registry.tsx +0 -57
- package/src/registry/registry.ts +0 -44
- package/src/registry/slots.registry.tsx +0 -6
- package/src/renderer/renderer.test.ts +0 -34
- package/src/renderer/renderer.tsx +0 -164
- package/src/renderer/renderer.utils.tsx +0 -139
- package/src/renderer/utils/divider.renderer.utils.tsx +0 -53
- package/src/services/localdb/db/db.test.ts +0 -351
- package/src/services/localdb/db/db.ts +0 -628
- package/src/services/localdb/lexer/lexer.test.ts +0 -123
- package/src/services/localdb/lexer/lexer.ts +0 -173
- package/src/services/localdb/lexer/lexer.types.ts +0 -34
- package/src/services/localdb/operator/operator.ts +0 -16
- package/src/services/localdb/parser/parser.constants.ts +0 -23
- package/src/services/localdb/parser/parser.test.ts +0 -172
- package/src/services/localdb/parser/parser.ts +0 -427
- package/src/services/localdb/parser/parser.types.ts +0 -56
- package/src/services/localdb/sheet/sheet.constants.ts +0 -32
- package/src/services/localdb/sheet/sheet.ts +0 -47
- package/src/services/localdb/sheet/sheet.types.ts +0 -38
- package/tsconfig.app.json +0 -26
- package/tsconfig.json +0 -9
- package/tsconfig.node.json +0 -9
- package/tsconfig.tsbuildinfo +0 -1
- package/vite.config.ts +0 -9
- /package/{src/components/index.ts → dist/components/index.d.ts} +0 -0
- /package/{src/components/slots/index.ts → dist/components/slots/index.d.ts} +0 -0
- /package/{src/components/slots/maps/index.ts → dist/components/slots/maps/index.d.ts} +0 -0
- /package/{src/modules/index.ts → dist/modules/index.d.ts} +0 -0
- /package/{src/registry/index.ts → dist/registry/index.d.ts} +0 -0
package/package.json
CHANGED
|
@@ -1,10 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coorax/react",
|
|
3
|
-
"version": "0.0.0-canary.
|
|
3
|
+
"version": "0.0.0-canary.4",
|
|
4
4
|
"private": false,
|
|
5
|
+
"files": [
|
|
6
|
+
"dist",
|
|
7
|
+
"styles.css"
|
|
8
|
+
],
|
|
5
9
|
"type": "module",
|
|
10
|
+
"main": "./dist/index.js",
|
|
11
|
+
"module": "./dist/index.js",
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
6
13
|
"exports": {
|
|
7
|
-
".":
|
|
14
|
+
".": {
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"import": "./dist/index.js",
|
|
17
|
+
"default": "./dist/index.js"
|
|
18
|
+
},
|
|
8
19
|
"./styles.css": "./styles.css"
|
|
9
20
|
},
|
|
10
21
|
"publishConfig": {
|
|
@@ -17,36 +28,42 @@
|
|
|
17
28
|
"fmt:check": "oxfmt --check",
|
|
18
29
|
"typecheck": "tsc --noEmit",
|
|
19
30
|
"vitest": "vitest",
|
|
20
|
-
"build": "tsc
|
|
31
|
+
"build:types": "tsc -p tsconfig.app.json --emitDeclarationOnly",
|
|
32
|
+
"build:js": "bun build ./src/index.ts --outdir ./dist --target browser --banner '\"use client\";' --external react --external react-dom --external @coorax/core --external lucide-react --external @emotion/css --external cn --external class-variance-authority --external zod",
|
|
33
|
+
"build": "bun run build:types && bun run build:js",
|
|
21
34
|
"prepublishOnly": "bun run build"
|
|
22
35
|
},
|
|
23
36
|
"dependencies": {
|
|
24
|
-
"@coorax/core": "0.0.0-canary.
|
|
37
|
+
"@coorax/core": "0.0.0-canary.1",
|
|
25
38
|
"@emotion/css": "^11.13.5",
|
|
26
|
-
"@emotion/react": "^11.14.0",
|
|
27
|
-
"@tailwindcss/vite": "4.3.3",
|
|
28
39
|
"class-variance-authority": "^0.7.1",
|
|
29
40
|
"cn": "^0.4.0",
|
|
30
|
-
"lucide-react": "^1.55.0",
|
|
31
|
-
"react": "^19.2.8",
|
|
32
|
-
"react-dom": "^19.2.8",
|
|
33
|
-
"tailwindcss": "4.3.3",
|
|
34
|
-
"vitest": "^5.0.3",
|
|
35
41
|
"zod": "^4.6.7"
|
|
36
42
|
},
|
|
37
43
|
"devDependencies": {
|
|
38
44
|
"@babel/core": "^7.29.7",
|
|
39
45
|
"@rolldown/plugin-babel": "^0.2.3",
|
|
46
|
+
"@tailwindcss/vite": "4.3.3",
|
|
40
47
|
"@types/babel__core": "^7.20.5",
|
|
41
48
|
"@types/node": "^24.13.3",
|
|
42
49
|
"@types/react": "^19.2.18",
|
|
43
50
|
"@types/react-dom": "^19.2.7",
|
|
44
51
|
"@vitejs/plugin-react": "^6.1.1",
|
|
45
52
|
"babel-plugin-react-compiler": "^1.0.0",
|
|
53
|
+
"lucide-react": "^1.55.0",
|
|
46
54
|
"oxfmt": "^0.71.0",
|
|
47
55
|
"oxlint": "^1.81.0",
|
|
56
|
+
"react": "^19.2.8",
|
|
57
|
+
"react-dom": "^19.2.8",
|
|
58
|
+
"tailwindcss": "4.3.3",
|
|
48
59
|
"typescript": "~6.0.2",
|
|
49
|
-
"vite": "^8.3.0"
|
|
60
|
+
"vite": "^8.3.0",
|
|
61
|
+
"vitest": "^5.0.3"
|
|
62
|
+
},
|
|
63
|
+
"peerDependencies": {
|
|
64
|
+
"lucide-react": ">=1.55.0",
|
|
65
|
+
"react": ">=18.0.0",
|
|
66
|
+
"react-dom": ">=18.0.0"
|
|
50
67
|
},
|
|
51
68
|
"packageManager": "bun@1.3.9"
|
|
52
69
|
}
|
package/.oxlintrc.json
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
import { cva, type VariantProps } from "class-variance-authority";
|
|
3
|
-
import { cn } from "cn";
|
|
4
|
-
|
|
5
|
-
const buttonVariants = cva(
|
|
6
|
-
"group/button inline-flex shrink-0 items-center justify-center rounded-lg border border-transparent bg-clip-padding text-sm font-medium whitespace-nowrap transition-all outline-none select-none focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 active:not-aria-[haspopup]:translate-y-px disabled:pointer-events-none disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
|
7
|
-
{
|
|
8
|
-
variants: {
|
|
9
|
-
variant: {
|
|
10
|
-
default: "bg-primary text-primary-foreground hover:bg-primary/80",
|
|
11
|
-
outline:
|
|
12
|
-
"border-border bg-background hover:bg-muted hover:text-foreground aria-expanded:bg-muted aria-expanded:text-foreground dark:border-input dark:bg-input/30 dark:hover:bg-input/50",
|
|
13
|
-
secondary:
|
|
14
|
-
"bg-secondary text-secondary-foreground hover:bg-[color-mix(in_oklch,var(--secondary),var(--foreground)_5%)] aria-expanded:bg-secondary aria-expanded:text-secondary-foreground",
|
|
15
|
-
ghost:
|
|
16
|
-
"hover:bg-muted hover:text-foreground aria-expanded:bg-muted aria-expanded:text-foreground dark:hover:bg-muted/50",
|
|
17
|
-
destructive:
|
|
18
|
-
"bg-destructive/10 text-destructive hover:bg-destructive/20 focus-visible:border-destructive/40 focus-visible:ring-destructive/20 dark:bg-destructive/20 dark:hover:bg-destructive/30 dark:focus-visible:ring-destructive/40",
|
|
19
|
-
link: "text-primary underline-offset-4 hover:underline",
|
|
20
|
-
},
|
|
21
|
-
size: {
|
|
22
|
-
default:
|
|
23
|
-
"h-8 gap-1.5 px-2.5 has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2",
|
|
24
|
-
xs: "h-6 gap-1 rounded-[min(var(--radius-md),10px)] px-2 text-xs in-data-[slot=button-group]:rounded-lg has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 [&_svg:not([class*='size-'])]:size-3",
|
|
25
|
-
sm: "h-7 gap-1 rounded-[min(var(--radius-md),12px)] px-2.5 text-[0.8rem] in-data-[slot=button-group]:rounded-lg has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 [&_svg:not([class*='size-'])]:size-3.5",
|
|
26
|
-
lg: "h-9 gap-1.5 px-2.5 has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2",
|
|
27
|
-
icon: "size-8",
|
|
28
|
-
"icon-xs":
|
|
29
|
-
"size-6 rounded-[min(var(--radius-md),10px)] in-data-[slot=button-group]:rounded-lg [&_svg:not([class*='size-'])]:size-3",
|
|
30
|
-
"icon-sm":
|
|
31
|
-
"size-7 rounded-[min(var(--radius-md),12px)] in-data-[slot=button-group]:rounded-lg",
|
|
32
|
-
"icon-lg": "size-9",
|
|
33
|
-
},
|
|
34
|
-
},
|
|
35
|
-
defaultVariants: {
|
|
36
|
-
variant: "default",
|
|
37
|
-
size: "default",
|
|
38
|
-
},
|
|
39
|
-
},
|
|
40
|
-
);
|
|
41
|
-
|
|
42
|
-
function Button({
|
|
43
|
-
className,
|
|
44
|
-
variant = "default",
|
|
45
|
-
size = "default",
|
|
46
|
-
...props
|
|
47
|
-
}: React.ComponentProps<"button"> & VariantProps<typeof buttonVariants>) {
|
|
48
|
-
return (
|
|
49
|
-
<button
|
|
50
|
-
data-slot="button"
|
|
51
|
-
data-variant={variant}
|
|
52
|
-
data-size={size}
|
|
53
|
-
className={cn(buttonVariants({ variant, size, className }))}
|
|
54
|
-
{...props}
|
|
55
|
-
/>
|
|
56
|
-
);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export { Button };
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
EditorModule,
|
|
3
|
-
Engine,
|
|
4
|
-
FocusModule,
|
|
5
|
-
HistoryModule,
|
|
6
|
-
HoverModule,
|
|
7
|
-
InsertionModule,
|
|
8
|
-
SelectionModule,
|
|
9
|
-
TextEditingModule,
|
|
10
|
-
} from "@coorax/core";
|
|
11
|
-
import React, { createContext, useContext, useMemo } from "react";
|
|
12
|
-
import { AutoSaveModule, SlotsModule } from "../modules";
|
|
13
|
-
import { FallbacksModule } from "../modules/fallbacks.module";
|
|
14
|
-
const CoraxEngineContext = createContext<Engine | null>(null);
|
|
15
|
-
|
|
16
|
-
export function CoraxEngineProvider({ children }: { children: React.ReactNode }) {
|
|
17
|
-
const engine = useMemo(() => {
|
|
18
|
-
const engine = new Engine();
|
|
19
|
-
|
|
20
|
-
engine.modules.register([
|
|
21
|
-
HistoryModule,
|
|
22
|
-
AutoSaveModule,
|
|
23
|
-
EditorModule,
|
|
24
|
-
HoverModule,
|
|
25
|
-
InsertionModule,
|
|
26
|
-
FocusModule,
|
|
27
|
-
SelectionModule,
|
|
28
|
-
TextEditingModule,
|
|
29
|
-
SlotsModule,
|
|
30
|
-
FallbacksModule,
|
|
31
|
-
]);
|
|
32
|
-
engine.modules.enableAll();
|
|
33
|
-
|
|
34
|
-
return engine;
|
|
35
|
-
}, []);
|
|
36
|
-
|
|
37
|
-
return <CoraxEngineContext.Provider value={engine}>{children}</CoraxEngineContext.Provider>;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// oxlint-disable-next-line react/only-export-components
|
|
41
|
-
export function useEngine() {
|
|
42
|
-
const engine = useContext(CoraxEngineContext);
|
|
43
|
-
if (!engine) {
|
|
44
|
-
throw new Error("useBlogEngine must be used within BlogEngineProvider");
|
|
45
|
-
}
|
|
46
|
-
return engine;
|
|
47
|
-
}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { useEngine } from "./corax-context-provider";
|
|
2
|
-
import React, { useEffect, useReducer } from "react";
|
|
3
|
-
import { useRenderer } from "../hooks/use-renderer";
|
|
4
|
-
import { useFlow } from "../hooks/use-flow";
|
|
5
|
-
import { useTextInput } from "../hooks/use-text-input";
|
|
6
|
-
import { cn } from "cn";
|
|
7
|
-
|
|
8
|
-
export function CoraxFlow({
|
|
9
|
-
children,
|
|
10
|
-
className,
|
|
11
|
-
}: React.PropsWithChildren & { className?: string }) {
|
|
12
|
-
const [count, forceUpdate] = useReducer((x) => x + 1, 0);
|
|
13
|
-
|
|
14
|
-
const engine = useEngine();
|
|
15
|
-
const renderer = useRenderer();
|
|
16
|
-
useFlow();
|
|
17
|
-
useTextInput(engine);
|
|
18
|
-
// useTextSelection(engine);
|
|
19
|
-
|
|
20
|
-
useEffect(() => {
|
|
21
|
-
const disposer = engine.events.on("blocks:insert", () => {
|
|
22
|
-
// console.log(payload)
|
|
23
|
-
forceUpdate();
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
return () => disposer();
|
|
27
|
-
}, [engine]);
|
|
28
|
-
|
|
29
|
-
return (
|
|
30
|
-
<div id="corax_flow_editor" className="relative flex flex-col w-full max-w-200 h-full">
|
|
31
|
-
CoraxFlow
|
|
32
|
-
<div
|
|
33
|
-
id="corax_flow_blocks_container"
|
|
34
|
-
className={cn(
|
|
35
|
-
"relative w-full h-full flex flex-col overflow-auto scrollbar-none pl-10 gap-1",
|
|
36
|
-
className,
|
|
37
|
-
)}
|
|
38
|
-
>
|
|
39
|
-
{renderer.renderTree(count)}
|
|
40
|
-
{children}
|
|
41
|
-
</div>
|
|
42
|
-
</div>
|
|
43
|
-
);
|
|
44
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import type { MediaField, NodeCommonProps } from "@coorax/core";
|
|
2
|
-
import { RefreshCw } from "lucide-react";
|
|
3
|
-
import { cn } from "cn";
|
|
4
|
-
import type { CSSProperties } from "react";
|
|
5
|
-
|
|
6
|
-
export function ImageFallback({
|
|
7
|
-
className,
|
|
8
|
-
style,
|
|
9
|
-
...props
|
|
10
|
-
}: MediaField & NodeCommonProps<CSSProperties>) {
|
|
11
|
-
return (
|
|
12
|
-
<div
|
|
13
|
-
className={cn(
|
|
14
|
-
"w-full h-[360px] flex gap-2 items-center justify-center bg-amber-500/10",
|
|
15
|
-
className,
|
|
16
|
-
)}
|
|
17
|
-
style={style}
|
|
18
|
-
>
|
|
19
|
-
<RefreshCw className="animate-spin size-5" />
|
|
20
|
-
<span className="font-semibold">{props.name}</span>
|
|
21
|
-
</div>
|
|
22
|
-
);
|
|
23
|
-
}
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import { Button } from "../../commons/button";
|
|
2
|
-
import { useEngine } from "../../corax-context-provider";
|
|
3
|
-
import { useSlice } from "../../../hooks/use-slice";
|
|
4
|
-
import { getBlockActionsProps } from "../../../lib/slots.utils";
|
|
5
|
-
import { cn } from "cn";
|
|
6
|
-
import { CoraxIcon } from "../../../lib/comp.utils";
|
|
7
|
-
import type { BlockId, Contribution, SlotBaseProps } from "@coorax/core";
|
|
8
|
-
import { blockRectFromBlockId } from "../../../lifecycle/fields/lifecycle.utils";
|
|
9
|
-
import React from "react";
|
|
10
|
-
|
|
11
|
-
export const BlockActionButton = React.memo(
|
|
12
|
-
function BlockActionButton({
|
|
13
|
-
c,
|
|
14
|
-
ui,
|
|
15
|
-
...rest
|
|
16
|
-
}: SlotBaseProps<"block-actions", "blocks.insert" | "actions.toggle", "button">) {
|
|
17
|
-
const engine = useEngine();
|
|
18
|
-
const isOpen = useSlice("insertion");
|
|
19
|
-
|
|
20
|
-
const focusMemory = useSlice("focus_memory");
|
|
21
|
-
const selection = useSlice("selection");
|
|
22
|
-
|
|
23
|
-
const { blocks = [] } = focusMemory ?? {};
|
|
24
|
-
const { blocks: _selectionBLocks = new Map() } = selection ?? {};
|
|
25
|
-
|
|
26
|
-
const selectedBlocksIds = Array.from(_selectionBLocks?.keys() ?? []) as BlockId[];
|
|
27
|
-
const focusedId = selectedBlocksIds[0] ?? blocks?.[blocks.length - 1]?.id;
|
|
28
|
-
|
|
29
|
-
if (c.name !== "BlockActionButton") return null;
|
|
30
|
-
if (!c.when?.(ui) || c.kind !== "button") return null;
|
|
31
|
-
|
|
32
|
-
const { variant, size, isBaseButton = false } = c.getProps(ui)!;
|
|
33
|
-
const enabled = engine.commands.has(c.command);
|
|
34
|
-
|
|
35
|
-
return (
|
|
36
|
-
<Button
|
|
37
|
-
{...rest}
|
|
38
|
-
variant={variant}
|
|
39
|
-
size={size}
|
|
40
|
-
disabled={!enabled}
|
|
41
|
-
{...(!isBaseButton
|
|
42
|
-
? getBlockActionsProps(!isOpen, c.order ? c.order - 1 : 0)
|
|
43
|
-
: {
|
|
44
|
-
className: cn("z-99 cursor-pointer transition-all", {
|
|
45
|
-
"rotate-45": isOpen,
|
|
46
|
-
}),
|
|
47
|
-
})}
|
|
48
|
-
|
|
49
|
-
onClick={() => {
|
|
50
|
-
if (c.command === "blocks.insert") {
|
|
51
|
-
const payload = (
|
|
52
|
-
c as Contribution<"block-actions", "blocks.insert", "button">
|
|
53
|
-
).getPayload(ui);
|
|
54
|
-
const pos = [...engine.document.get().order].indexOf(focusedId);
|
|
55
|
-
|
|
56
|
-
engine.commands.tryExecute(c.command, {
|
|
57
|
-
...payload,
|
|
58
|
-
pos: pos === -1 ? undefined : pos + 1,
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
setTimeout(() => {
|
|
62
|
-
const rect = blockRectFromBlockId(payload.block.id);
|
|
63
|
-
if (!rect) return;
|
|
64
|
-
|
|
65
|
-
engine.commands.tryExecute("blocks.focus", {
|
|
66
|
-
id: payload.block.id,
|
|
67
|
-
rect,
|
|
68
|
-
});
|
|
69
|
-
}, 0);
|
|
70
|
-
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
|
-
const payload = (
|
|
74
|
-
c as Contribution<"block-actions", "actions.toggle", "button">
|
|
75
|
-
).getPayload(ui);
|
|
76
|
-
engine.commands.tryExecute(c.command, payload);
|
|
77
|
-
}}
|
|
78
|
-
>
|
|
79
|
-
<CoraxIcon icon={c.icon} />
|
|
80
|
-
{c.label}
|
|
81
|
-
</Button>
|
|
82
|
-
);
|
|
83
|
-
},
|
|
84
|
-
() => true,
|
|
85
|
-
);
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { Button } from "../../commons/button";
|
|
2
|
-
import type { SlotBaseProps } from "@coorax/core";
|
|
3
|
-
import { CoraxIcon } from "../../../lib/comp.utils";
|
|
4
|
-
import { useEngine } from "../../corax-context-provider";
|
|
5
|
-
import React from "react";
|
|
6
|
-
import { useSlice } from "../../../hooks/use-slice";
|
|
7
|
-
|
|
8
|
-
export const ToolbarButton = React.memo(
|
|
9
|
-
function ToolbarButton({
|
|
10
|
-
c,
|
|
11
|
-
ui,
|
|
12
|
-
}: SlotBaseProps<"toolbar", "ToolBarButton", "text.format", "button">) {
|
|
13
|
-
const engine = useEngine();
|
|
14
|
-
const marks = useSlice("currentMarks");
|
|
15
|
-
|
|
16
|
-
const isActive =
|
|
17
|
-
!!c.getProps(ui)?.isActive || marks?.find((mark) => mark.type === c.getPayload(ui).format);
|
|
18
|
-
|
|
19
|
-
return (
|
|
20
|
-
<Button
|
|
21
|
-
key={c.id}
|
|
22
|
-
onClick={() => {
|
|
23
|
-
engine.commands.tryExecute(c.command, c.getPayload(ui));
|
|
24
|
-
}}
|
|
25
|
-
title={c.label}
|
|
26
|
-
size={"icon-xs"}
|
|
27
|
-
className="rounded-[8px] cursor-pointer"
|
|
28
|
-
variant={isActive ? "default" : "outline"}
|
|
29
|
-
>
|
|
30
|
-
<CoraxIcon icon={c.icon} />
|
|
31
|
-
</Button>
|
|
32
|
-
);
|
|
33
|
-
},
|
|
34
|
-
(prev, next) => {
|
|
35
|
-
const prevActive = prev.c.getProps(prev.ui);
|
|
36
|
-
const nextActive = next.c.getProps(next.ui);
|
|
37
|
-
|
|
38
|
-
return prevActive === nextActive;
|
|
39
|
-
},
|
|
40
|
-
);
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import { useEffect, useMemo, useRef } from "react";
|
|
2
|
-
import { useSlice } from "../../../hooks/use-slice";
|
|
3
|
-
import { Slots } from "../slots";
|
|
4
|
-
import { useEngine } from "../../corax-context-provider";
|
|
5
|
-
import { cn } from "cn";
|
|
6
|
-
import type { BlockId } from "@coorax/core";
|
|
7
|
-
|
|
8
|
-
export function BlockActions({ className, children, ...rest }: React.ComponentProps<"div">) {
|
|
9
|
-
const selection = useSlice("selection");
|
|
10
|
-
const documentSlice = useSlice("document");
|
|
11
|
-
|
|
12
|
-
const { blocks = new Map() } = selection ?? {};
|
|
13
|
-
const { order = new Set() } = documentSlice ?? {};
|
|
14
|
-
|
|
15
|
-
const keys = [...blocks.keys()];
|
|
16
|
-
|
|
17
|
-
const firstSelectionId = keys[0] as BlockId;
|
|
18
|
-
|
|
19
|
-
const engine = useEngine();
|
|
20
|
-
const lastPositionRef = useRef({ active: false, top: 0, left: 0 });
|
|
21
|
-
|
|
22
|
-
const blockRect = blocks.get(firstSelectionId);
|
|
23
|
-
const position = useMemo(() => {
|
|
24
|
-
if (!firstSelectionId || !blockRect) {
|
|
25
|
-
return { active: false, top: 0, left: 0 };
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const container = document.getElementById("corax_flow_blocks_container");
|
|
29
|
-
if (!container) return { active: false, top: 0, left: 0 };
|
|
30
|
-
|
|
31
|
-
const containerRect = container.getBoundingClientRect();
|
|
32
|
-
|
|
33
|
-
const block = engine.document.getBlock(firstSelectionId);
|
|
34
|
-
if (!block || block.variant !== "field") return { active: false, top: 0, left: 0 };
|
|
35
|
-
|
|
36
|
-
const domElement = document.getElementById(firstSelectionId);
|
|
37
|
-
if (!domElement) return { active: false, top: 0, left: 0 };
|
|
38
|
-
|
|
39
|
-
const heightDiff = 36 - blockRect.height;
|
|
40
|
-
const toSubstract = heightDiff / 2;
|
|
41
|
-
|
|
42
|
-
const top =
|
|
43
|
-
blockRect.top -
|
|
44
|
-
(-toSubstract > 32 ? -8 : toSubstract) -
|
|
45
|
-
containerRect.top -
|
|
46
|
-
container.clientTop +
|
|
47
|
-
blockRect.parentScrollTop;
|
|
48
|
-
|
|
49
|
-
return {
|
|
50
|
-
active: true,
|
|
51
|
-
top,
|
|
52
|
-
left: 0,
|
|
53
|
-
};
|
|
54
|
-
}, [firstSelectionId, engine, blockRect]);
|
|
55
|
-
|
|
56
|
-
useEffect(() => {
|
|
57
|
-
if (position.active) {
|
|
58
|
-
lastPositionRef.current = position;
|
|
59
|
-
}
|
|
60
|
-
}, [position]);
|
|
61
|
-
|
|
62
|
-
// oxlint-disable-next-line react/refs
|
|
63
|
-
const _position = position.active ? position : lastPositionRef.current;
|
|
64
|
-
|
|
65
|
-
return (
|
|
66
|
-
<div
|
|
67
|
-
style={{
|
|
68
|
-
top: _position.top,
|
|
69
|
-
left: _position.left,
|
|
70
|
-
}}
|
|
71
|
-
className={cn("absolute top-0 left-0 gap-1 flex items-center transition-opacity", className, {
|
|
72
|
-
"opacity-0 pointer-events-none":
|
|
73
|
-
// oxlint-disable-next-line react/refs
|
|
74
|
-
!_position.active ||
|
|
75
|
-
keys.length > 1 ||
|
|
76
|
-
(firstSelectionId && !order?.has(firstSelectionId)),
|
|
77
|
-
})}
|
|
78
|
-
{...rest}
|
|
79
|
-
>
|
|
80
|
-
<Slots slotName="block-actions" />
|
|
81
|
-
{children}
|
|
82
|
-
</div>
|
|
83
|
-
);
|
|
84
|
-
}
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
// oxlint-disable react/refs
|
|
2
|
-
import { Slots } from "../slots";
|
|
3
|
-
import { useSlice } from "../../../hooks/use-slice";
|
|
4
|
-
import { cn } from "cn";
|
|
5
|
-
import { useRef, useMemo, useEffect } from "react";
|
|
6
|
-
import { useEngine } from "../../corax-context-provider";
|
|
7
|
-
import { blockRectFromBlockId } from "../../../lifecycle/fields/lifecycle.utils";
|
|
8
|
-
import { offsetsToRange } from "../../../lib/selection.utils";
|
|
9
|
-
|
|
10
|
-
const TOOLBAR_OFFSET = 8;
|
|
11
|
-
|
|
12
|
-
const DEFAULT_STATE = { active: false, top: 0, left: 0 };
|
|
13
|
-
|
|
14
|
-
export function Toolbar({ className, children, ...rest }: React.ComponentProps<"div">) {
|
|
15
|
-
const textSel = useSlice("textSelection");
|
|
16
|
-
const currentBlockId = textSel?.blockId;
|
|
17
|
-
|
|
18
|
-
const documentSlice = useSlice("document");
|
|
19
|
-
const { order = new Set() } = documentSlice ?? {};
|
|
20
|
-
const engine = useEngine();
|
|
21
|
-
|
|
22
|
-
const lastPositionRef = useRef(DEFAULT_STATE);
|
|
23
|
-
const toolbarRef = useRef<HTMLDivElement | null>(null);
|
|
24
|
-
|
|
25
|
-
const position = useMemo(() => {
|
|
26
|
-
const toolbarElement = toolbarRef.current;
|
|
27
|
-
// oxlint-disable-next-line react/refs
|
|
28
|
-
if (!currentBlockId || !toolbarElement) {
|
|
29
|
-
return DEFAULT_STATE;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const el = document.getElementById(textSel.blockId);
|
|
33
|
-
if (!el) return DEFAULT_STATE;
|
|
34
|
-
|
|
35
|
-
const range = offsetsToRange(el, textSel.start, textSel.end);
|
|
36
|
-
if (!range) return DEFAULT_STATE;
|
|
37
|
-
|
|
38
|
-
const selRect = range.getBoundingClientRect();
|
|
39
|
-
|
|
40
|
-
const block = engine.document.getBlock(currentBlockId);
|
|
41
|
-
if (!block) return { active: false, top: 0, left: 0 };
|
|
42
|
-
|
|
43
|
-
const blockRect = blockRectFromBlockId(currentBlockId);
|
|
44
|
-
if (!blockRect) return { active: false, top: 0, left: 0 };
|
|
45
|
-
|
|
46
|
-
return {
|
|
47
|
-
active: true,
|
|
48
|
-
top: blockRect.top - toolbarElement.offsetHeight - TOOLBAR_OFFSET,
|
|
49
|
-
left: selRect.left - (toolbarElement.offsetWidth - selRect.width) / 2,
|
|
50
|
-
};
|
|
51
|
-
}, [currentBlockId, engine, textSel]);
|
|
52
|
-
|
|
53
|
-
useEffect(() => {
|
|
54
|
-
if (position.active) {
|
|
55
|
-
lastPositionRef.current = position;
|
|
56
|
-
}
|
|
57
|
-
}, [position]);
|
|
58
|
-
|
|
59
|
-
const _position = position.active ? position : lastPositionRef.current;
|
|
60
|
-
|
|
61
|
-
return (
|
|
62
|
-
<div
|
|
63
|
-
ref={toolbarRef}
|
|
64
|
-
style={{
|
|
65
|
-
top: _position.top,
|
|
66
|
-
left: _position.left,
|
|
67
|
-
}}
|
|
68
|
-
className={cn("fixed top-0 left-0 gap-1 flex items-center transition-all", className, {
|
|
69
|
-
"opacity-0 pointer-events-none":
|
|
70
|
-
!_position.active || (currentBlockId && !order?.has(currentBlockId)),
|
|
71
|
-
// || textSel?.start === textSel?.end,
|
|
72
|
-
})}
|
|
73
|
-
{...rest}
|
|
74
|
-
>
|
|
75
|
-
<Slots slotName="toolbar" />
|
|
76
|
-
{children}
|
|
77
|
-
</div>
|
|
78
|
-
);
|
|
79
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import type { CommandType, SlotBaseProps, SlotComponentMap } from "@coorax/core";
|
|
2
|
-
import { useEffect } from "react";
|
|
3
|
-
import { focusDomElement } from "../../../lib/func.utils";
|
|
4
|
-
|
|
5
|
-
declare module "@coorax/core" {}
|
|
6
|
-
|
|
7
|
-
export function FocusOverlay({ c, ui }: SlotBaseProps<"overlay", CommandType, "component">) {
|
|
8
|
-
const { position, hidden } = c.getProps(ui) as SlotComponentMap["FocusOverlay"];
|
|
9
|
-
const focusedId = ui.focus?.id;
|
|
10
|
-
|
|
11
|
-
// autoFocus isn't working so,
|
|
12
|
-
// we handle native focus with this effect
|
|
13
|
-
useEffect(() => {
|
|
14
|
-
if (!focusedId) return;
|
|
15
|
-
focusDomElement(focusedId);
|
|
16
|
-
}, [focusedId]);
|
|
17
|
-
|
|
18
|
-
if (hidden || !position) return null;
|
|
19
|
-
|
|
20
|
-
return (
|
|
21
|
-
<div
|
|
22
|
-
style={position}
|
|
23
|
-
className="absolute border border-blue-700 pointer-events-none flex justify-end"
|
|
24
|
-
>
|
|
25
|
-
{/* <div className="absolute right-0 top-[calc(100%+4px)] px-2.5 py-1 rounded-xs text-xs dark:bg-pink-800 bg-pink-300 text-foreground">
|
|
26
|
-
width: {position.width} | height: {position.height}
|
|
27
|
-
</div> */}
|
|
28
|
-
</div>
|
|
29
|
-
);
|
|
30
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { CommandType, SlotBaseProps, SlotComponentMap } from "@coorax/core";
|
|
2
|
-
|
|
3
|
-
declare module "@coorax/core" {}
|
|
4
|
-
|
|
5
|
-
export function HoverOverlay({ c, ui }: SlotBaseProps<"overlay", CommandType, "component">) {
|
|
6
|
-
const { position, hidden } = c.getProps(ui) as SlotComponentMap["HoverOverlay"];
|
|
7
|
-
|
|
8
|
-
if (hidden || !position) return null;
|
|
9
|
-
|
|
10
|
-
return (
|
|
11
|
-
<div
|
|
12
|
-
style={position}
|
|
13
|
-
className="absolute border-[0.5px] border-blue-400 pointer-events-none flex justify-end"
|
|
14
|
-
>
|
|
15
|
-
{/* Hover Overlay */}
|
|
16
|
-
</div>
|
|
17
|
-
);
|
|
18
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import type { CommandType, SlotBaseProps, SlotComponentMap } from "@coorax/core";
|
|
2
|
-
|
|
3
|
-
declare module "@coorax/core" {}
|
|
4
|
-
|
|
5
|
-
export function SelectionOverlay({ c, ui }: SlotBaseProps<"overlay", CommandType, "component">) {
|
|
6
|
-
const { position, hidden } = c.getProps(ui) as SlotComponentMap["SelectionOverlay"];
|
|
7
|
-
|
|
8
|
-
if (hidden || !position) return null;
|
|
9
|
-
|
|
10
|
-
return (
|
|
11
|
-
<div
|
|
12
|
-
style={position}
|
|
13
|
-
className="absolute border border-blue-500 pointer-events-none flex justify-end"
|
|
14
|
-
>
|
|
15
|
-
{/* <div className="absolute right-0 top-[calc(100%+4px)] px-2.5 py-1 rounded-xs text-xs dark:bg-green-800 bg-green-300 text-foreground">
|
|
16
|
-
width: {position.width} | height: {position.height}
|
|
17
|
-
</div> */}
|
|
18
|
-
</div>
|
|
19
|
-
);
|
|
20
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import type { ButtonContribution, UIContext } from "@coorax/core";
|
|
2
|
-
import { useRegistryComponent } from "../../hooks/use-registry";
|
|
3
|
-
import React from "react";
|
|
4
|
-
|
|
5
|
-
export function SlotButton({ c, ui }: { c: ButtonContribution; ui: UIContext }) {
|
|
6
|
-
const Comp = useRegistryComponent(c.name);
|
|
7
|
-
|
|
8
|
-
if (!Comp) {
|
|
9
|
-
console.warn(`No component registered for slot key "${c.name}"`);
|
|
10
|
-
return null;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
return React.createElement(Comp, {
|
|
14
|
-
c,
|
|
15
|
-
ui,
|
|
16
|
-
...{
|
|
17
|
-
"data-slot-type": "slot-button",
|
|
18
|
-
},
|
|
19
|
-
});
|
|
20
|
-
}
|