@coorax/react 0.0.0-canary.0 → 0.0.0-canary.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/commons/button.d.ts +8 -0
- package/dist/components/commons/youtube.d.ts +2 -0
- package/dist/components/corax-context-provider.d.ts +11 -0
- package/dist/components/corax-flow.d.ts +6 -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/image.fallback.d.ts +2 -0
- 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 +3 -0
- package/dist/components/slots/buttons/caption-button.d.ts +3 -0
- package/dist/components/slots/buttons/code-theme-button.d.ts +3 -0
- package/dist/components/slots/buttons/delete-button.d.ts +3 -0
- package/dist/components/slots/buttons/divider-style-button.d.ts +3 -0
- package/dist/components/slots/buttons/divider-width-button.d.ts +3 -0
- package/dist/components/slots/buttons/iframe-playback-button.d.ts +3 -0
- package/dist/components/slots/buttons/image-width-button.d.ts +3 -0
- package/dist/components/slots/buttons/paragraph-theme-button.d.ts +3 -0
- package/dist/components/slots/buttons/toolbar-button.d.ts +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-is-selected.d.ts +2 -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} +8 -4
- package/dist/index.js +3575 -0
- package/dist/lib/comp.utils.d.ts +8 -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/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 +10 -0
- package/dist/lifecycle/fields/lifecycle.fields.types.d.ts +4 -0
- package/dist/lifecycle/fields/lifecycle.utils.d.ts +8 -0
- 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/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/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 -0
- package/dist/modules/autosave.module.d.ts +41 -0
- package/dist/modules/errors.module.d.ts +7 -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/dist/registry/index.d.ts +4 -0
- package/dist/registry/slots.registry.d.ts +4 -0
- package/{src/registry/ui.primitives.registry.tsx → dist/registry/ui.primitives.registry.d.ts} +4 -5
- package/dist/services/index.d.ts +2 -0
- package/dist/services/localdb/db/db.d.ts +78 -0
- package/dist/services/localdb/db/db.test.d.ts +1 -0
- package/dist/services/localdb/dbtest.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 +15 -0
- package/dist/services/localdb/parser/parser.test.d.ts +1 -0
- package/dist/services/localdb/parser/parser.types.d.ts +49 -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 +2 -0
- package/package.json +38 -15
- package/styles.css +2 -1
- 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/fallbacks.registry.tsx +0 -9
- package/src/registry/index.ts +0 -5
- 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.types.ts +0 -3
- 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
|
@@ -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
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { ComponentContribution, UIContext } from "@coorax/core";
|
|
2
|
-
import { useRegistryComponent } from "../../hooks/use-registry";
|
|
3
|
-
import { createElement } from "react";
|
|
4
|
-
|
|
5
|
-
export function SlotComponent({ c, ui }: { c: ComponentContribution; 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
|
-
const props = c.getProps(ui);
|
|
14
|
-
if (!props) return null;
|
|
15
|
-
|
|
16
|
-
return createElement(Comp, { ui, c });
|
|
17
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { type SlotBaseProps, type SlotName } from "@coorax/core";
|
|
2
|
-
import { useSlots } from "../../hooks/use-slots";
|
|
3
|
-
import { SlotButton } from "./slot-button";
|
|
4
|
-
import { useUIContext } from "../../hooks/use-ui-context";
|
|
5
|
-
import { SlotComponent } from "./slot-component";
|
|
6
|
-
|
|
7
|
-
export function Slots({ slotName }: { slotName: SlotName }) {
|
|
8
|
-
const items = useSlots(slotName);
|
|
9
|
-
const ui = useUIContext();
|
|
10
|
-
|
|
11
|
-
return (
|
|
12
|
-
<>
|
|
13
|
-
{items.map((c) => (
|
|
14
|
-
<SlotItem key={c.id} c={c} ui={ui} />
|
|
15
|
-
))}
|
|
16
|
-
</>
|
|
17
|
-
);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
function SlotItem({ c, ui }: SlotBaseProps) {
|
|
21
|
-
if (c.when && !c.when(ui)) return null;
|
|
22
|
-
|
|
23
|
-
switch (c.kind) {
|
|
24
|
-
case "button":
|
|
25
|
-
return <SlotButton c={c} ui={ui} />;
|
|
26
|
-
case "component":
|
|
27
|
-
return <SlotComponent c={c} ui={ui} />;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { useEffect, useRef } from "react";
|
|
2
|
-
|
|
3
|
-
export function useCustomRef<T>(factory: T | (() => T)) {
|
|
4
|
-
const ref = useRef<T>(typeof factory === "function" ? (factory as () => T)() : factory);
|
|
5
|
-
|
|
6
|
-
useEffect(() => {
|
|
7
|
-
ref.current = typeof factory === "function" ? (factory as () => T)() : factory;
|
|
8
|
-
}, [factory]);
|
|
9
|
-
|
|
10
|
-
return ref;
|
|
11
|
-
}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import type { BlockId } from "@coorax/core";
|
|
2
|
-
import { useCustomRef } from "./custom/use-custom-ref";
|
|
3
|
-
import { useEffect } from "react";
|
|
4
|
-
import { useEngine } from "../components/corax-context-provider";
|
|
5
|
-
import { blockRectFromBlockId } from "../lifecycle/fields/lifecycle.utils";
|
|
6
|
-
import { useUIContext } from "./use-ui-context";
|
|
7
|
-
|
|
8
|
-
export function useBlockEntry(id: BlockId) {
|
|
9
|
-
const engine = useEngine();
|
|
10
|
-
const ui = useUIContext();
|
|
11
|
-
const blockRef = useCustomRef(() => {
|
|
12
|
-
const domBlock = document.getElementById(id);
|
|
13
|
-
if (!domBlock) return null;
|
|
14
|
-
return domBlock;
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
useEffect(() => {
|
|
18
|
-
const element = blockRef.current;
|
|
19
|
-
if (!element) return;
|
|
20
|
-
|
|
21
|
-
const observer = new ResizeObserver(() => {
|
|
22
|
-
const rect = blockRectFromBlockId(id);
|
|
23
|
-
if (!rect) return;
|
|
24
|
-
|
|
25
|
-
// if (ui.hoveredBlock) {
|
|
26
|
-
// engine.commands.tryExecute("blocks.hover", { hoveredId: id, blockRect: rect });
|
|
27
|
-
// }
|
|
28
|
-
// if (ui.focusedBlock) {
|
|
29
|
-
// engine.commands.tryExecute("blocks.focus", { focusedId: id, blockRect: rect });
|
|
30
|
-
// }
|
|
31
|
-
// if (ui.selectedBLocks.has(id)) {
|
|
32
|
-
// const newSelection = new Map(ui.selectedBLocks.entries()).set(id, rect);
|
|
33
|
-
// engine.commands.tryExecute("blocks.select", { blocks: newSelection, mode: "replace" });
|
|
34
|
-
// }
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
observer.observe(element);
|
|
38
|
-
|
|
39
|
-
return () => {
|
|
40
|
-
observer.disconnect();
|
|
41
|
-
observer.unobserve(element);
|
|
42
|
-
};
|
|
43
|
-
}, [blockRef, engine, id, ui]);
|
|
44
|
-
}
|
package/src/hooks/use-block.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { useSyncExternalStore } from "react";
|
|
2
|
-
import { useEngine } from "../components/corax-context-provider";
|
|
3
|
-
import type { Block, BlockId } from "@coorax/core";
|
|
4
|
-
|
|
5
|
-
export function useBlock<T extends Block = Block>(id: BlockId) {
|
|
6
|
-
const engine = useEngine();
|
|
7
|
-
return useSyncExternalStore(
|
|
8
|
-
(fn) => engine.document.subscribeBlock(id, fn),
|
|
9
|
-
() => engine.document.getBlock(id) as T,
|
|
10
|
-
);
|
|
11
|
-
}
|
package/src/hooks/use-flow.ts
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import { useEffect } from "react";
|
|
2
|
-
import { useEngine } from "../components/corax-context-provider";
|
|
3
|
-
import { useCustomRef } from "./custom/use-custom-ref";
|
|
4
|
-
|
|
5
|
-
export function editorRectFromDomElement(domElement: HTMLElement) {
|
|
6
|
-
const containerRect = domElement.getBoundingClientRect();
|
|
7
|
-
|
|
8
|
-
return {
|
|
9
|
-
scrollTop: domElement.scrollTop,
|
|
10
|
-
scrollLeft: domElement.scrollLeft,
|
|
11
|
-
clientLeft: domElement.clientLeft,
|
|
12
|
-
clientTop: domElement.clientTop,
|
|
13
|
-
top: containerRect.top,
|
|
14
|
-
left: containerRect.left,
|
|
15
|
-
bottom: containerRect.bottom,
|
|
16
|
-
right: containerRect.right,
|
|
17
|
-
width: containerRect.width,
|
|
18
|
-
height: containerRect.height,
|
|
19
|
-
offsetTop: domElement.offsetTop,
|
|
20
|
-
offsetLeft: domElement.offsetLeft,
|
|
21
|
-
offsetWidth: domElement.offsetWidth,
|
|
22
|
-
offsetHeight: domElement.offsetHeight,
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export function useFlow() {
|
|
27
|
-
const engine = useEngine();
|
|
28
|
-
const coraxFlowEditorRef = useCustomRef<HTMLDivElement | null>(() => {
|
|
29
|
-
const flowEditor = document.getElementById("corax_flow_blocks_container");
|
|
30
|
-
if (!flowEditor) return null;
|
|
31
|
-
|
|
32
|
-
engine.commands.tryExecute("editor.rect", { editorRect: editorRectFromDomElement(flowEditor) });
|
|
33
|
-
return flowEditor as HTMLDivElement;
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
useEffect(() => {
|
|
37
|
-
function handleKeyDown(ev: KeyboardEvent) {
|
|
38
|
-
if (!ev.ctrlKey || ev.key.toLocaleLowerCase() !== "z") return;
|
|
39
|
-
engine.commands.tryExecute(ev.shiftKey ? "history.redo" : "history.undo", {});
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const flowEditor = coraxFlowEditorRef.current;
|
|
43
|
-
|
|
44
|
-
function handleClick(ev: MouseEvent) {
|
|
45
|
-
const target = ev.target;
|
|
46
|
-
if (!(target instanceof Element)) return;
|
|
47
|
-
if (target.closest("[data-block-type]") || target.closest("[data-slot-type]")) return;
|
|
48
|
-
|
|
49
|
-
engine.commands.tryExecute("blocks.select", { blocks: new Map(), mode: "replace" });
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
if (flowEditor) {
|
|
53
|
-
flowEditor.addEventListener("click", handleClick);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
document.addEventListener("keydown", handleKeyDown);
|
|
57
|
-
|
|
58
|
-
return () => {
|
|
59
|
-
document.removeEventListener("keydown", handleKeyDown);
|
|
60
|
-
if (flowEditor) {
|
|
61
|
-
flowEditor.removeEventListener("click", handleClick);
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
}, [engine, coraxFlowEditorRef]);
|
|
65
|
-
|
|
66
|
-
useEffect(() => {
|
|
67
|
-
const element = coraxFlowEditorRef.current;
|
|
68
|
-
if (!element) return;
|
|
69
|
-
|
|
70
|
-
const publishEditorRect = () => {
|
|
71
|
-
engine.commands.tryExecute("editor.rect", { editorRect: editorRectFromDomElement(element) });
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
const observer = new ResizeObserver(publishEditorRect);
|
|
75
|
-
observer.observe(element);
|
|
76
|
-
element.addEventListener("scroll", publishEditorRect, { passive: true });
|
|
77
|
-
|
|
78
|
-
return () => {
|
|
79
|
-
observer.disconnect();
|
|
80
|
-
element.removeEventListener("scroll", publishEditorRect);
|
|
81
|
-
};
|
|
82
|
-
}, [engine, coraxFlowEditorRef]);
|
|
83
|
-
}
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import { useEffect, useRef, useSyncExternalStore } from "react";
|
|
2
|
-
|
|
3
|
-
type KeyboardState = {
|
|
4
|
-
eventType: string | null;
|
|
5
|
-
ctrlKey: boolean;
|
|
6
|
-
metaKey: boolean;
|
|
7
|
-
altKey: boolean;
|
|
8
|
-
currentKey: string | null;
|
|
9
|
-
shiftKey: boolean;
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
export function useKeyboard() {
|
|
13
|
-
const subscribersRef = useRef(new Set<() => void>());
|
|
14
|
-
const keyboardRef = useRef<KeyboardState>({
|
|
15
|
-
eventType: null,
|
|
16
|
-
ctrlKey: false,
|
|
17
|
-
metaKey: false,
|
|
18
|
-
altKey: false,
|
|
19
|
-
currentKey: null,
|
|
20
|
-
shiftKey: false,
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
function handleKeyDown(ev: KeyboardEvent) {
|
|
24
|
-
const newState = Object.assign(structuredClone(keyboardRef.current), {
|
|
25
|
-
eventType: ev.type,
|
|
26
|
-
ctrlKey: ev.ctrlKey,
|
|
27
|
-
metaKey: ev.metaKey,
|
|
28
|
-
altKey: ev.altKey,
|
|
29
|
-
currentKey: ev.key,
|
|
30
|
-
shiftKey: ev.shiftKey,
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
if (newState === keyboardRef.current) return;
|
|
34
|
-
|
|
35
|
-
keyboardRef.current = newState;
|
|
36
|
-
subscribersRef.current.forEach((fn) => fn());
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const boardInfo = useSyncExternalStore(
|
|
40
|
-
(callback) => {
|
|
41
|
-
subscribersRef.current.add(callback);
|
|
42
|
-
return () => {
|
|
43
|
-
subscribersRef.current.delete(callback);
|
|
44
|
-
};
|
|
45
|
-
},
|
|
46
|
-
() => keyboardRef.current,
|
|
47
|
-
);
|
|
48
|
-
|
|
49
|
-
useEffect(() => {
|
|
50
|
-
const coraxEditor = document.getElementById("corax_flow_editor");
|
|
51
|
-
if (!coraxEditor || typeof document === "undefined") {
|
|
52
|
-
console.warn("Corax editor not mounted!");
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
document.addEventListener("keyup", handleKeyDown);
|
|
57
|
-
document.addEventListener("keydown", handleKeyDown);
|
|
58
|
-
|
|
59
|
-
return () => {
|
|
60
|
-
document.removeEventListener("keyup", handleKeyDown);
|
|
61
|
-
document.removeEventListener("keydown", handleKeyDown);
|
|
62
|
-
};
|
|
63
|
-
}, []);
|
|
64
|
-
|
|
65
|
-
return boardInfo;
|
|
66
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { useSyncExternalStore } from "react";
|
|
2
|
-
import type { SlotKey } from "@coorax/core";
|
|
3
|
-
import { SlotsComponentRegistry } from "../registry/slots.registry";
|
|
4
|
-
import { UIPrimitivesRegistry } from "../registry/ui.primitives.registry";
|
|
5
|
-
|
|
6
|
-
export function useRegistryComponent(name: SlotKey) {
|
|
7
|
-
return useSyncExternalStore(
|
|
8
|
-
(fn) => SlotsComponentRegistry.subscribe(name, fn),
|
|
9
|
-
() => SlotsComponentRegistry.get(name),
|
|
10
|
-
);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export function useUIPrimitivesRegistry(name: SlotKey) {
|
|
14
|
-
return useSyncExternalStore(
|
|
15
|
-
(fn) => UIPrimitivesRegistry.subscribe(name, fn),
|
|
16
|
-
() => UIPrimitivesRegistry.get(name),
|
|
17
|
-
);
|
|
18
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { useMemo } from "react";
|
|
2
|
-
import { ReactRenderer } from "../renderer/renderer";
|
|
3
|
-
import { useEngine } from "../components/corax-context-provider";
|
|
4
|
-
|
|
5
|
-
export function useRenderer() {
|
|
6
|
-
const engine = useEngine();
|
|
7
|
-
return useMemo(() => new ReactRenderer(engine), [engine]);
|
|
8
|
-
}
|
package/src/hooks/use-slice.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { SliceName, SliceValue } from "@coorax/core";
|
|
2
|
-
import { useSyncExternalStore } from "react";
|
|
3
|
-
import { useEngine } from "../components/corax-context-provider";
|
|
4
|
-
|
|
5
|
-
export function useSlice<T extends SliceName = SliceName>(sliceName: T): SliceValue<T> | undefined {
|
|
6
|
-
const engine = useEngine();
|
|
7
|
-
const slice = useSyncExternalStore(
|
|
8
|
-
(fn) => engine.state.subscribe(sliceName, fn),
|
|
9
|
-
() => engine.state.get(sliceName),
|
|
10
|
-
);
|
|
11
|
-
|
|
12
|
-
return slice;
|
|
13
|
-
}
|
package/src/hooks/use-slots.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { Contribution, SlotName } from "@coorax/core";
|
|
2
|
-
import { useSyncExternalStore } from "react";
|
|
3
|
-
import { useEngine } from "../components/corax-context-provider";
|
|
4
|
-
|
|
5
|
-
export function useSlots(slotName: SlotName): readonly Contribution[] {
|
|
6
|
-
const engine = useEngine();
|
|
7
|
-
const items = useSyncExternalStore(
|
|
8
|
-
(fn) => engine.ui.subscribe(slotName, fn),
|
|
9
|
-
() => engine.ui.getSlots(slotName),
|
|
10
|
-
);
|
|
11
|
-
|
|
12
|
-
return items;
|
|
13
|
-
}
|
package/src/hooks/use-tasks.ts
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import type { TaskFunction, TaskID, TaskName, TaskState } from "@coorax/core";
|
|
2
|
-
import { useCallback, useSyncExternalStore } from "react";
|
|
3
|
-
import { useEngine } from "../components/corax-context-provider";
|
|
4
|
-
|
|
5
|
-
export interface UseTasksReturn extends TaskState {
|
|
6
|
-
flush: () => Promise<void>;
|
|
7
|
-
cancel: () => boolean;
|
|
8
|
-
schedule: (delay: number, fn: TaskFunction, taskId?: TaskID) => () => void;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export function useTasks<T extends TaskName = TaskName>(name: T): UseTasksReturn {
|
|
12
|
-
const engine = useEngine();
|
|
13
|
-
|
|
14
|
-
const state = useSyncExternalStore(
|
|
15
|
-
(callback) => engine.tasks.subscribe(name, callback),
|
|
16
|
-
() => engine.tasks.getState(name),
|
|
17
|
-
);
|
|
18
|
-
|
|
19
|
-
const flush = useCallback(() => engine.tasks.flush(name), [engine, name]);
|
|
20
|
-
const cancel = useCallback(() => engine.tasks.cancel(name), [engine, name]);
|
|
21
|
-
const schedule = useCallback(
|
|
22
|
-
(delay: number, fn: TaskFunction, taskId?: TaskID) =>
|
|
23
|
-
engine.tasks.schedule(name, delay, fn, taskId),
|
|
24
|
-
[engine, name],
|
|
25
|
-
);
|
|
26
|
-
|
|
27
|
-
return {
|
|
28
|
-
...state,
|
|
29
|
-
flush,
|
|
30
|
-
cancel,
|
|
31
|
-
schedule,
|
|
32
|
-
};
|
|
33
|
-
}
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import type { Engine, FieldId, FieldTextContentPath } from "@coorax/core";
|
|
2
|
-
import { useEffect } from "react";
|
|
3
|
-
import { rangeToOffsets } from "../lib/selection.utils";
|
|
4
|
-
|
|
5
|
-
export function useTextInput(engine: Engine) {
|
|
6
|
-
useEffect(() => {
|
|
7
|
-
let composing = false;
|
|
8
|
-
const rootOf = (t: EventTarget | null) =>
|
|
9
|
-
(
|
|
10
|
-
(t instanceof Element ? t : (t as Node | null)?.parentElement) ?? null
|
|
11
|
-
)?.closest<HTMLElement>("[data-text-path]") ?? null;
|
|
12
|
-
|
|
13
|
-
const onBeforeInput = (e: InputEvent) => {
|
|
14
|
-
const root = rootOf(e.target);
|
|
15
|
-
if (!root || composing || e.isComposing) return; // #IME : on laisse faire
|
|
16
|
-
|
|
17
|
-
// la plage ciblée par le navigateur est plus fiable que le slice (qui peut être en retard)
|
|
18
|
-
const tr = e.getTargetRanges()[0];
|
|
19
|
-
if (tr) {
|
|
20
|
-
const r = document.createRange();
|
|
21
|
-
r.setStart(tr.startContainer, tr.startOffset);
|
|
22
|
-
r.setEnd(tr.endContainer, tr.endOffset);
|
|
23
|
-
engine.commands.tryExecute("text.setSelection", {
|
|
24
|
-
blockId: root.dataset.blockId as FieldId,
|
|
25
|
-
path: root.dataset.textPath! as FieldTextContentPath,
|
|
26
|
-
...rangeToOffsets(root, r),
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
switch (e.inputType) {
|
|
31
|
-
case "insertText":
|
|
32
|
-
if (e.data) engine.commands.tryExecute("text.insert", { text: e.data });
|
|
33
|
-
break;
|
|
34
|
-
case "insertParagraph":
|
|
35
|
-
case "insertLineBreak":
|
|
36
|
-
engine.commands.tryExecute("text.insert", { text: "\n" });
|
|
37
|
-
break;
|
|
38
|
-
case "insertFromPaste": {
|
|
39
|
-
const text = e.dataTransfer?.getData("text/plain");
|
|
40
|
-
if (text) engine.commands.tryExecute("text.insert", { text });
|
|
41
|
-
break;
|
|
42
|
-
}
|
|
43
|
-
case "deleteContentBackward":
|
|
44
|
-
engine.commands.tryExecute("text.delete", { direction: "backward" });
|
|
45
|
-
break;
|
|
46
|
-
case "deleteWordBackward":
|
|
47
|
-
engine.commands.tryExecute("text.delete", { direction: "backward", type: "word" });
|
|
48
|
-
break;
|
|
49
|
-
case "deleteContentForward":
|
|
50
|
-
engine.commands.tryExecute("text.delete", { direction: "forward" });
|
|
51
|
-
break;
|
|
52
|
-
case "deleteWordForward":
|
|
53
|
-
engine.commands.tryExecute("text.delete", { direction: "forward", type: "word" });
|
|
54
|
-
break;
|
|
55
|
-
case "historyUndo":
|
|
56
|
-
engine.commands.tryExecute("history.undo", undefined as never);
|
|
57
|
-
break;
|
|
58
|
-
case "historyRedo":
|
|
59
|
-
engine.commands.tryExecute("history.redo", undefined as never);
|
|
60
|
-
break;
|
|
61
|
-
default:
|
|
62
|
-
break; // inputType non géré
|
|
63
|
-
}
|
|
64
|
-
e.preventDefault();
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
const start = () => {
|
|
68
|
-
composing = true;
|
|
69
|
-
};
|
|
70
|
-
const end = () => {
|
|
71
|
-
composing = false;
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
document.addEventListener("beforeinput", onBeforeInput);
|
|
75
|
-
document.addEventListener("compositionstart", start);
|
|
76
|
-
document.addEventListener("compositionend", end);
|
|
77
|
-
return () => {
|
|
78
|
-
document.removeEventListener("beforeinput", onBeforeInput);
|
|
79
|
-
document.removeEventListener("compositionstart", start);
|
|
80
|
-
document.removeEventListener("compositionend", end);
|
|
81
|
-
};
|
|
82
|
-
}, [engine]);
|
|
83
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { BlockId, BlockRect, UIContext } from "@coorax/core";
|
|
2
|
-
import { useSlice } from "./use-slice";
|
|
3
|
-
|
|
4
|
-
export function useUIContext(): UIContext {
|
|
5
|
-
const selection = useSlice("selection") ?? { blocks: new Map<BlockId, BlockRect>() };
|
|
6
|
-
const focus = useSlice("focus") ?? null;
|
|
7
|
-
const hover = useSlice("hover") ?? null;
|
|
8
|
-
const textSelection = useSlice("textSelection") ?? null;
|
|
9
|
-
|
|
10
|
-
return {
|
|
11
|
-
selection,
|
|
12
|
-
focus,
|
|
13
|
-
hover,
|
|
14
|
-
textSelection,
|
|
15
|
-
};
|
|
16
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import type { Engine, FieldId, FieldTextContentPath } from "@coorax/core";
|
|
2
|
-
import { useEffect } from "react";
|
|
3
|
-
import { rangeToOffsets } from "../lib/selection.utils";
|
|
4
|
-
|
|
5
|
-
export function useTextSelection(engine: Engine) {
|
|
6
|
-
useEffect(() => {
|
|
7
|
-
const onChange = () => {
|
|
8
|
-
const sel = document.getSelection();
|
|
9
|
-
if (!sel || sel.rangeCount === 0) return;
|
|
10
|
-
|
|
11
|
-
const range = sel.getRangeAt(0);
|
|
12
|
-
const el = range.commonAncestorContainer;
|
|
13
|
-
const root = (el instanceof Element ? el : el.parentElement)?.closest<HTMLElement>(
|
|
14
|
-
"[data-text-path]",
|
|
15
|
-
);
|
|
16
|
-
if (!root) return; // hors d'une zone de texte riche
|
|
17
|
-
|
|
18
|
-
const blockId = root.dataset.blockId as FieldId;
|
|
19
|
-
const path = root.dataset.textPath! as FieldTextContentPath; // "props.children", "props.label"...
|
|
20
|
-
const { start, end } = rangeToOffsets(root, range);
|
|
21
|
-
|
|
22
|
-
engine.commands.tryExecute("text.setSelection", { blockId, path, start, end });
|
|
23
|
-
};
|
|
24
|
-
document.addEventListener("selectionchange", onChange);
|
|
25
|
-
return () => document.removeEventListener("selectionchange", onChange);
|
|
26
|
-
}, [engine]);
|
|
27
|
-
}
|
package/src/lib/comp.utils.tsx
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import type { SlotIcon } from "@coorax/core";
|
|
2
|
-
import {
|
|
3
|
-
BoldIcon,
|
|
4
|
-
HeadingIcon,
|
|
5
|
-
ImagePlus,
|
|
6
|
-
ItalicIcon,
|
|
7
|
-
LinkIcon,
|
|
8
|
-
Minus,
|
|
9
|
-
PlusIcon,
|
|
10
|
-
Pointer,
|
|
11
|
-
PointerIcon,
|
|
12
|
-
TextCursor,
|
|
13
|
-
TextInitialIcon,
|
|
14
|
-
UnderlineIcon,
|
|
15
|
-
} from "lucide-react";
|
|
16
|
-
|
|
17
|
-
export function CoraxIcon({ icon }: { icon: SlotIcon }) {
|
|
18
|
-
switch (icon) {
|
|
19
|
-
case "TextIcon":
|
|
20
|
-
return <TextCursor />;
|
|
21
|
-
case "CursorIcon":
|
|
22
|
-
return <PointerIcon />;
|
|
23
|
-
case "HeadingIcon":
|
|
24
|
-
return <HeadingIcon />;
|
|
25
|
-
case "PlusIcon":
|
|
26
|
-
return <PlusIcon />;
|
|
27
|
-
case "BoldIcon":
|
|
28
|
-
return <BoldIcon />;
|
|
29
|
-
case "ItalicIcon":
|
|
30
|
-
return <ItalicIcon />;
|
|
31
|
-
case "UnderlineIcon":
|
|
32
|
-
return <UnderlineIcon />;
|
|
33
|
-
case "LinkIcon":
|
|
34
|
-
return <LinkIcon />;
|
|
35
|
-
case "ImagePlus":
|
|
36
|
-
return <ImagePlus />;
|
|
37
|
-
case "TextInitial":
|
|
38
|
-
return <TextInitialIcon />;
|
|
39
|
-
case "DividerIcon":
|
|
40
|
-
return <Minus />;
|
|
41
|
-
default:
|
|
42
|
-
return <Pointer />;
|
|
43
|
-
}
|
|
44
|
-
}
|
package/src/lib/func.utils.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { BlockId, Engine } from "@coorax/core";
|
|
2
|
-
|
|
3
|
-
export function focusDomBLockById(engine: Engine, id: BlockId) {
|
|
4
|
-
const disposer = engine.events.on("re-render", () => {
|
|
5
|
-
focusDomElement(id);
|
|
6
|
-
disposer();
|
|
7
|
-
});
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export function focusDomElement(id: string) {
|
|
11
|
-
const domElement = document.getElementById(id);
|
|
12
|
-
if (!domElement) return;
|
|
13
|
-
|
|
14
|
-
domElement.focus();
|
|
15
|
-
}
|