@coorax/core 0.0.0-canary.0 → 0.0.0-canary.2
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/base/classes/component.class.d.ts +23 -0
- package/dist/base/classes/container.class.d.ts +17 -0
- package/dist/base/classes/field.class.d.ts +15 -0
- package/dist/base/classes/tnode.class.d.ts +14 -0
- package/{src/base/index.ts → dist/base/index.d.ts} +0 -4
- package/dist/base/types/components/components.d.ts +13 -0
- package/dist/base/types/container/container.d.ts +27 -0
- package/dist/base/types/container/division.types.d.ts +3 -0
- package/{src/base/types/container/section.types.ts → dist/base/types/container/section.types.d.ts} +2 -2
- package/{src/base/types/container/ul-list.types.ts → dist/base/types/container/ul-list.types.d.ts} +2 -2
- package/dist/base/types/css.types.d.ts +23 -0
- package/dist/base/types/field/divider.types.d.ts +3 -0
- package/dist/base/types/field/field.blockquote.types.d.ts +4 -0
- package/dist/base/types/field/field.d.ts +50 -0
- package/dist/base/types/field/field.image.types.d.ts +3 -0
- package/{src/base/types/field/field.media.types.ts → dist/base/types/field/field.media.types.d.ts} +2 -3
- package/{src/base/types/field/field.text.types.ts → dist/base/types/field/field.text.types.d.ts} +4 -5
- package/dist/base/types/field/field.video.types.d.ts +8 -0
- package/dist/base/types/field/fields.iframe.types.d.ts +7 -0
- package/{src/base/types/field/heading.types.ts → dist/base/types/field/heading.types.d.ts} +2 -2
- package/{src/base/types/field/paragraph.types.ts → dist/base/types/field/paragraph.types.d.ts} +2 -2
- package/dist/base/types/global.types.d.ts +26 -0
- package/{src/base/types/node/span.types.ts → dist/base/types/node/link.types.d.ts} +2 -2
- package/{src/base/types/node/node.ts → dist/base/types/node/node.d.ts} +13 -17
- package/{src/base/types/node/link.types.ts → dist/base/types/node/span.types.d.ts} +2 -2
- package/dist/base/types/tree/tree.d.ts +24 -0
- package/dist/constants/field.constants.d.ts +1 -0
- package/dist/constants/index.d.ts +1 -0
- package/{src/engine/engine.ts → dist/engine/engine.d.ts} +20 -24
- package/dist/engine/engine.test.d.ts +1 -0
- package/{src/index.ts → dist/index.d.ts} +1 -2
- package/dist/index.js +3252 -0
- package/dist/modules/caption/caption.module.d.ts +35 -0
- package/dist/modules/caption/caption.test.d.ts +1 -0
- package/dist/modules/code/code.module.d.ts +37 -0
- package/dist/modules/deletion/deletion.module.d.ts +26 -0
- package/dist/modules/editor/editor.module.d.ts +44 -0
- package/dist/modules/focus/focus.module.d.ts +54 -0
- package/dist/modules/history/history.module.d.ts +41 -0
- package/dist/modules/hover/hover.module.d.ts +53 -0
- package/{src/modules/index.ts → dist/modules/index.d.ts} +3 -1
- package/dist/modules/insertion/insertion.module.d.ts +71 -0
- package/dist/modules/modules-manager.d.ts +43 -0
- package/{src/modules/modules.types.ts → dist/modules/modules.types.d.ts} +25 -30
- package/dist/modules/selection/selection.module.d.ts +60 -0
- package/dist/modules/selection/selection.test.d.ts +1 -0
- package/dist/modules/text-editing/text-editing.constants.d.ts +2 -0
- package/dist/modules/text-editing/text-editing.module.d.ts +82 -0
- package/dist/modules/text-editing/text-editing.utils.d.ts +6 -0
- package/dist/services/commandsbus/commandsbus.d.ts +53 -0
- package/dist/services/commandsbus/commandsbus.test.d.ts +17 -0
- package/dist/services/document/document.d.ts +44 -0
- package/dist/services/eventbus/eventbus.d.ts +86 -0
- package/dist/services/eventbus/eventbus.test.d.ts +8 -0
- package/dist/services/eventbus/subscriber.d.ts +18 -0
- package/dist/services/mutations/mutations.d.ts +43 -0
- package/dist/services/mutations/mutations.errors.d.ts +6 -0
- package/dist/services/mutations/mutations.test.d.ts +1 -0
- package/dist/services/shortcuts/shortcuts.d.ts +4 -0
- package/dist/services/state/state.d.ts +20 -0
- package/dist/services/state/state.errors.d.ts +6 -0
- package/dist/services/tasks/tasks.service.d.ts +106 -0
- package/dist/services/tasks/tasks.service.test.d.ts +7 -0
- package/dist/services/text-marks/index.d.ts +1 -0
- package/{src/services/text-marks/marks.types.ts → dist/services/text-marks/marks.types.d.ts} +20 -23
- package/dist/services/text-marks/text-marks.d.ts +45 -0
- package/dist/services/ui/contributions.types.d.ts +79 -0
- package/dist/services/ui/default-styles.d.ts +3 -0
- package/{src/services/ui/index.ts → dist/services/ui/index.d.ts} +0 -1
- package/dist/services/ui/ui.d.ts +23 -0
- package/dist/services/ui/ui.errors.d.ts +3 -0
- package/dist/services/ui/ui.types.d.ts +25 -0
- package/dist/styles.css +2 -0
- package/dist/utils/components.utils.d.ts +10 -0
- package/dist/utils/container.utils.d.ts +13 -0
- package/dist/utils/fields.utils.d.ts +27 -0
- package/dist/utils/global.utils.d.ts +47 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/modules.utils.d.ts +11 -0
- package/dist/utils/tnode.utils.d.ts +9 -0
- package/dist/utils/tree.utils.d.ts +11 -0
- package/package.json +23 -6
- package/styles.css +4 -4
- package/src/base/classes/component.class.ts +0 -68
- package/src/base/classes/container.class.ts +0 -57
- package/src/base/classes/field.class.ts +0 -42
- package/src/base/classes/tnode.class.ts +0 -38
- package/src/base/types/components/components.ts +0 -21
- package/src/base/types/container/container.ts +0 -37
- package/src/base/types/container/division.types.ts +0 -3
- package/src/base/types/css.types.ts +0 -33
- package/src/base/types/field/divider.types.ts +0 -3
- package/src/base/types/field/field.ts +0 -46
- package/src/base/types/global.types.ts +0 -45
- package/src/base/types/tree/tree.ts +0 -33
- package/src/engine/engine.test.ts +0 -27
- package/src/modules/editor/editor.module.ts +0 -119
- package/src/modules/focus/focus.module.ts +0 -185
- package/src/modules/history/history.module.ts +0 -60
- package/src/modules/hover/hover.module.ts +0 -121
- package/src/modules/insertion/insertion.module.ts +0 -140
- package/src/modules/modules-manager.ts +0 -132
- package/src/modules/selection/selection.module.ts +0 -174
- package/src/modules/selection/selection.test.ts +0 -1
- package/src/modules/text-editing/text-editing.constants.ts +0 -6
- package/src/modules/text-editing/text-editing.module.ts +0 -377
- package/src/modules/text-editing/text-editing.utils.ts +0 -27
- package/src/services/commandsbus/commandsbus.test.ts +0 -312
- package/src/services/commandsbus/commandsbus.ts +0 -360
- package/src/services/document/document.ts +0 -139
- package/src/services/eventbus/eventbus.test.ts +0 -144
- package/src/services/eventbus/eventbus.ts +0 -162
- package/src/services/eventbus/subscriber.ts +0 -46
- package/src/services/mutations/mutations.errors.ts +0 -12
- package/src/services/mutations/mutations.test.ts +0 -177
- package/src/services/mutations/mutations.ts +0 -457
- package/src/services/shortcuts/shortcuts.ts +0 -3
- package/src/services/state/state.errors.ts +0 -12
- package/src/services/state/state.ts +0 -64
- package/src/services/tasks/tasks.service.test.ts +0 -193
- package/src/services/tasks/tasks.service.ts +0 -288
- package/src/services/text-marks/index.ts +0 -2
- package/src/services/text-marks/text-marks.ts +0 -244
- package/src/services/ui/default-styles.ts +0 -93
- package/src/services/ui/ui.errors.ts +0 -6
- package/src/services/ui/ui.ts +0 -148
- package/src/services/ui/ui.types.ts +0 -197
- package/src/utils/components.utils.ts +0 -26
- package/src/utils/container.utils.ts +0 -59
- package/src/utils/fields.utils.ts +0 -118
- package/src/utils/global.utils.ts +0 -128
- package/src/utils/index.ts +0 -7
- package/src/utils/modules.utils.ts +0 -110
- package/src/utils/tnode.utils.ts +0 -48
- package/src/utils/tree.utils.ts +0 -120
- package/tsconfig.json +0 -9
- /package/{src/engine/index.ts → dist/engine/index.d.ts} +0 -0
- /package/{src/services/commandsbus/index.ts → dist/services/commandsbus/index.d.ts} +0 -0
- /package/{src/services/document/index.ts → dist/services/document/index.d.ts} +0 -0
- /package/{src/services/eventbus/index.ts → dist/services/eventbus/index.d.ts} +0 -0
- /package/{src/services/mutations/index.ts → dist/services/mutations/index.d.ts} +0 -0
- /package/{src/services/state/index.ts → dist/services/state/index.d.ts} +0 -0
- /package/{src/services/tasks/index.ts → dist/services/tasks/index.d.ts} +0 -0
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import type * as CSS from "csstype";
|
|
2
|
-
import type { Container } from "./container/container";
|
|
3
|
-
import type { Field } from "./field/field";
|
|
4
|
-
import type { Component } from "./components/components";
|
|
5
|
-
import type { TNode } from "./node/node.ts";
|
|
6
|
-
import type { CoraxCSSProperties, CoraxCSSPseudos } from "./css.types";
|
|
7
|
-
|
|
8
|
-
export type PseudoSelectors = { [P in CSS.Pseudos]?: CSS.Properties };
|
|
9
|
-
|
|
10
|
-
export type NodeCommonProps<T extends CoraxCSSProperties = CoraxCSSProperties> = {
|
|
11
|
-
title?: string;
|
|
12
|
-
style?: T;
|
|
13
|
-
pseudoStyle?: CoraxCSSPseudos;
|
|
14
|
-
className?: string;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
// #Here to omit methods
|
|
18
|
-
export type OmitContainersMethods<T extends Container> = Omit<
|
|
19
|
-
T,
|
|
20
|
-
"getChildren" | "appendChild" | "removeChild" | "getCurrentContainerObject"
|
|
21
|
-
>;
|
|
22
|
-
|
|
23
|
-
export type OmitComponentsMethods<T extends Component> = Omit<
|
|
24
|
-
T,
|
|
25
|
-
"getChildren" | "appendChild" | "removeChild" | "getCurrentComponentObject" | "isInstance"
|
|
26
|
-
>;
|
|
27
|
-
|
|
28
|
-
export type OmitFieldsMethods<T extends Field> = Omit<
|
|
29
|
-
T,
|
|
30
|
-
"isContainerized" | "getCurrentFieldObject"
|
|
31
|
-
>;
|
|
32
|
-
|
|
33
|
-
export type OmitTNodesMethods<T extends TNode> = Omit<T, "getCurrentNodeObject">;
|
|
34
|
-
|
|
35
|
-
export type UnionSide<T, K extends any> = K extends T ? K : never;
|
|
36
|
-
|
|
37
|
-
export type PathToProp<T, F, Prev extends string = ""> = {
|
|
38
|
-
[K in keyof T]: T[K] extends F
|
|
39
|
-
? `${Prev}${Extract<K, string>}`
|
|
40
|
-
: T[K] extends object
|
|
41
|
-
? PathToProp<T[K], F, `${Prev}${Extract<K, string>}.`>
|
|
42
|
-
: never;
|
|
43
|
-
}[keyof T];
|
|
44
|
-
|
|
45
|
-
export type RMUndfined<T> = T extends undefined ? never : T;
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import type { Field, FieldId } from "../field/field.ts";
|
|
2
|
-
import type { Container, ContainerId } from "../container/container.ts";
|
|
3
|
-
import type { Component, ComponentId } from "../components/components.ts";
|
|
4
|
-
import type {
|
|
5
|
-
OmitComponentsMethods,
|
|
6
|
-
OmitContainersMethods,
|
|
7
|
-
OmitFieldsMethods,
|
|
8
|
-
} from "../global.types.ts";
|
|
9
|
-
|
|
10
|
-
export type OmittedMethodsBlock =
|
|
11
|
-
| OmitFieldsMethods<Field>
|
|
12
|
-
| OmitComponentsMethods<Component>
|
|
13
|
-
| OmitContainersMethods<Container>;
|
|
14
|
-
export type Block = Field | Component | Container;
|
|
15
|
-
export type BlockId = Block["id"];
|
|
16
|
-
export type BlockTag = Block["tag"];
|
|
17
|
-
export type BlockType = Block["type"];
|
|
18
|
-
export type BlockVariant = Block["variant"];
|
|
19
|
-
|
|
20
|
-
export type CoraxTree = {
|
|
21
|
-
id: string;
|
|
22
|
-
version: `${number}.${number}.${number}`;
|
|
23
|
-
fields: Map<FieldId, Field>;
|
|
24
|
-
containers: Map<ContainerId, Container>;
|
|
25
|
-
components: Map<ComponentId, Component>;
|
|
26
|
-
order: Set<BlockId>;
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
export type JSONTree = Pick<CoraxTree, "id" | "order" | "version"> & {
|
|
30
|
-
fields: Record<FieldId, OmitFieldsMethods<Field>>;
|
|
31
|
-
containers: Record<ContainerId, OmitContainersMethods<Container>>;
|
|
32
|
-
components: Record<ComponentId, OmitComponentsMethods<Component>>;
|
|
33
|
-
};
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
// import { describe, expect, it } from "vitest";
|
|
2
|
-
// import { Engine } from "./engine";
|
|
3
|
-
|
|
4
|
-
console.log("Engine test");
|
|
5
|
-
|
|
6
|
-
// describe("Engine", () => {
|
|
7
|
-
|
|
8
|
-
// describe("Module Manager", () => {
|
|
9
|
-
|
|
10
|
-
// it("désactive un module et retire ses commandes", () => {
|
|
11
|
-
// const engine = new Engine()
|
|
12
|
-
// engine.modules.register([{
|
|
13
|
-
// name: "a",
|
|
14
|
-
// version: "1",
|
|
15
|
-
// requires: [],
|
|
16
|
-
// install: ctx => { ctx.commands.register("blocks.move", () => ({ })) },
|
|
17
|
-
// }])
|
|
18
|
-
|
|
19
|
-
// engine.modules.enable("a")
|
|
20
|
-
// expect(engine.commands.has("blocks.move")).toBe(true)
|
|
21
|
-
|
|
22
|
-
// engine.modules.disable("a")
|
|
23
|
-
// expect(engine.commands.has("blocks.move")).toBe(false)
|
|
24
|
-
// })
|
|
25
|
-
// })
|
|
26
|
-
|
|
27
|
-
// })
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
import type { BlockRect, TModule } from "..";
|
|
2
|
-
import type { CommandMap } from "../../services/commandsbus/commandsbus";
|
|
3
|
-
import { areObjectsTheSame } from "../../utils";
|
|
4
|
-
|
|
5
|
-
export type EditorRect = Omit<BlockRect, "parentScrollTop" | "parentScrollLeft"> & {
|
|
6
|
-
clientTop: number;
|
|
7
|
-
clientLeft: number;
|
|
8
|
-
scrollTop: number;
|
|
9
|
-
scrollLeft: number;
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
export type OverlayPosition = {
|
|
13
|
-
top: number;
|
|
14
|
-
left: number;
|
|
15
|
-
width: number;
|
|
16
|
-
height: number;
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
const MIN_SIZE = 16;
|
|
20
|
-
|
|
21
|
-
/** Viewport block rects → `position: absolute` inside the scroll container. */
|
|
22
|
-
export function overlayPositionFromBlockRects(
|
|
23
|
-
rects: readonly BlockRect[],
|
|
24
|
-
editorRect: EditorRect | null,
|
|
25
|
-
): OverlayPosition | null {
|
|
26
|
-
if (!editorRect || rects.length === 0) return null;
|
|
27
|
-
|
|
28
|
-
const top = Math.min(...rects.map((rect) => rect.top));
|
|
29
|
-
const left = Math.min(...rects.map((rect) => rect.left));
|
|
30
|
-
const bottom = Math.max(...rects.map((rect) => rect.bottom));
|
|
31
|
-
const right = Math.max(...rects.map((rect) => rect.right));
|
|
32
|
-
|
|
33
|
-
const scrollTop = rects[0]!.parentScrollTop;
|
|
34
|
-
const scrollLeft = rects[0]!.parentScrollLeft;
|
|
35
|
-
|
|
36
|
-
const width = right - left;
|
|
37
|
-
const height = bottom - top;
|
|
38
|
-
|
|
39
|
-
return {
|
|
40
|
-
top:
|
|
41
|
-
top -
|
|
42
|
-
editorRect.top -
|
|
43
|
-
editorRect.clientTop +
|
|
44
|
-
scrollTop -
|
|
45
|
-
(height < MIN_SIZE ? MIN_SIZE / 2 : 0),
|
|
46
|
-
left:
|
|
47
|
-
left -
|
|
48
|
-
editorRect.left -
|
|
49
|
-
editorRect.clientLeft +
|
|
50
|
-
scrollLeft -
|
|
51
|
-
(width < MIN_SIZE ? MIN_SIZE / 2 : 0),
|
|
52
|
-
width: width < MIN_SIZE ? MIN_SIZE : width,
|
|
53
|
-
height: height < MIN_SIZE ? MIN_SIZE : height,
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
declare module "../modules-manager" {
|
|
58
|
-
interface ModuleMap {
|
|
59
|
-
editor: {};
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
declare module "../../services/state/state" {
|
|
64
|
-
interface StateMap {
|
|
65
|
-
editor: { editorRect: EditorRect | null };
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
declare module "../../services/commandsbus/commandsbus" {
|
|
70
|
-
interface CommandMap {
|
|
71
|
-
"editor.rect": {
|
|
72
|
-
payload: { editorRect: EditorRect };
|
|
73
|
-
result: void;
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
declare module "../../services/eventbus/eventbus" {
|
|
79
|
-
interface TEventMap {
|
|
80
|
-
"editor:rect": CommandMap["editor.rect"]["payload"];
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
export const EditorModule: TModule = {
|
|
85
|
-
name: "editor",
|
|
86
|
-
version: "1.0.0",
|
|
87
|
-
requires: [],
|
|
88
|
-
install(ctx) {
|
|
89
|
-
ctx.state.defineSlice("editor", { editorRect: null });
|
|
90
|
-
|
|
91
|
-
ctx.commands.register("editor.rect", ({ editorRect }) => {
|
|
92
|
-
const prevState = ctx.state.get("editor");
|
|
93
|
-
|
|
94
|
-
if (editorRect === null) {
|
|
95
|
-
if (prevState?.editorRect === null) return;
|
|
96
|
-
|
|
97
|
-
ctx.state.set("editor", { editorRect });
|
|
98
|
-
ctx.events.emit("editor:rect", { editorRect });
|
|
99
|
-
return;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
if (!prevState) {
|
|
103
|
-
return;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
if (prevState.editorRect === null) {
|
|
107
|
-
ctx.state.set("editor", { editorRect });
|
|
108
|
-
ctx.events.emit("editor:rect", { editorRect });
|
|
109
|
-
return;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
const areSame = areObjectsTheSame(prevState.editorRect, editorRect);
|
|
113
|
-
if (!areSame) {
|
|
114
|
-
ctx.state.set("editor", { editorRect });
|
|
115
|
-
ctx.events.emit("editor:rect", { editorRect });
|
|
116
|
-
}
|
|
117
|
-
});
|
|
118
|
-
},
|
|
119
|
-
};
|
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
import type { BlockId, FieldId, TextField } from "../../base";
|
|
2
|
-
import type { CommandMap } from "../../services/commandsbus";
|
|
3
|
-
import type { StateMap } from "../../services/state";
|
|
4
|
-
import type { BlockRect, TModule } from "../modules.types";
|
|
5
|
-
import type { UIContext } from "../../services/ui";
|
|
6
|
-
import type { SlotComponentMap } from "../../services/ui";
|
|
7
|
-
import { overlayPositionFromBlockRects, type EditorRect } from "../editor/editor.module";
|
|
8
|
-
import _ from "lodash";
|
|
9
|
-
import { isEditableField } from "../../utils";
|
|
10
|
-
|
|
11
|
-
declare module "../modules-manager" {
|
|
12
|
-
interface ModuleMap {
|
|
13
|
-
focus: {};
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
declare module "../../services/state/state" {
|
|
18
|
-
interface StateMap {
|
|
19
|
-
focus: { id: BlockId; rect: BlockRect } | null;
|
|
20
|
-
focus_memory: {
|
|
21
|
-
blocks: { id: BlockId; rect: BlockRect }[];
|
|
22
|
-
count: number;
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
declare module "../../services/commandsbus/commandsbus" {
|
|
28
|
-
interface CommandMap {
|
|
29
|
-
"blocks.focus": { payload: StateMap["focus"]; result: void };
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
declare module "../../services/eventbus/eventbus" {
|
|
34
|
-
interface TEventMap {
|
|
35
|
-
"blocks:focus": CommandMap["blocks.focus"]["payload"];
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
declare module "../../services/ui/ui" {
|
|
40
|
-
interface SlotComponentMap {
|
|
41
|
-
FocusOverlay: {
|
|
42
|
-
position: {
|
|
43
|
-
top: number;
|
|
44
|
-
left: number;
|
|
45
|
-
width: number;
|
|
46
|
-
height: number;
|
|
47
|
-
} | null;
|
|
48
|
-
hidden: boolean;
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
interface ComponentContributionIdentityMap {
|
|
53
|
-
"focus-overlay": {};
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
function focusOverlayPropsFromUICtx(
|
|
58
|
-
ui: UIContext,
|
|
59
|
-
editorRect: EditorRect | null,
|
|
60
|
-
): SlotComponentMap["FocusOverlay"]["position"] | null {
|
|
61
|
-
const rect = ui.focus?.rect;
|
|
62
|
-
if (!rect) return null;
|
|
63
|
-
|
|
64
|
-
return overlayPositionFromBlockRects([rect], editorRect);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
export const FocusModule: TModule = {
|
|
68
|
-
name: "focus",
|
|
69
|
-
version: "1.0.0",
|
|
70
|
-
requires: ["selection"],
|
|
71
|
-
install(ctx) {
|
|
72
|
-
ctx.state.defineSlice("focus", null);
|
|
73
|
-
ctx.state.defineSlice("focus_memory", { blocks: [], count: 3 });
|
|
74
|
-
|
|
75
|
-
ctx.ui.contribute("overlay", {
|
|
76
|
-
id: "focus-overlay",
|
|
77
|
-
slot: "overlay",
|
|
78
|
-
order: 1001,
|
|
79
|
-
kind: "component",
|
|
80
|
-
name: "FocusOverlay",
|
|
81
|
-
when: (ui) => !!ui.focus?.id,
|
|
82
|
-
getProps: (ui) => {
|
|
83
|
-
const editorState = ctx.state.get("editor") ?? { editorRect: null };
|
|
84
|
-
const position = focusOverlayPropsFromUICtx(ui, editorState?.editorRect);
|
|
85
|
-
const document = ctx.state.get("document");
|
|
86
|
-
|
|
87
|
-
return {
|
|
88
|
-
position,
|
|
89
|
-
hidden: !ui.focus?.id || !position || !document?.order.has(ui?.focus?.id),
|
|
90
|
-
};
|
|
91
|
-
},
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
ctx.commands.register("blocks.focus", (payload) => {
|
|
95
|
-
// if (!payload) {
|
|
96
|
-
// void ctx.state.set("focus", null);
|
|
97
|
-
// void ctx.commands.execute("blocks.select", { blocks: new Map(), mode: "replace" });
|
|
98
|
-
// return;
|
|
99
|
-
// }
|
|
100
|
-
|
|
101
|
-
if (payload && !isEditableField(ctx.document.getBlock(payload.id as BlockId)!)) {
|
|
102
|
-
void ctx.commands.execute("blocks.select", {
|
|
103
|
-
blocks: new Map().set(payload.id, payload.rect),
|
|
104
|
-
mode: "replace",
|
|
105
|
-
});
|
|
106
|
-
return;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
const { id: focusedId = null, rect = null } = payload ?? {};
|
|
110
|
-
const prev = ctx.state.get("focus");
|
|
111
|
-
|
|
112
|
-
if (focusedId !== null && !ctx.document.has(focusedId)) return;
|
|
113
|
-
if (focusedId === prev?.id && _.isEqual(rect, prev.rect)) return;
|
|
114
|
-
|
|
115
|
-
const prevFocusedId = prev?.id;
|
|
116
|
-
const shouldUnfocusPrev = Boolean(
|
|
117
|
-
prevFocusedId &&
|
|
118
|
-
prevFocusedId !== focusedId &&
|
|
119
|
-
(() => {
|
|
120
|
-
const b = ctx.document.getBlock(prevFocusedId);
|
|
121
|
-
return b && isEditableField(b);
|
|
122
|
-
})(),
|
|
123
|
-
);
|
|
124
|
-
|
|
125
|
-
const shouldFocusCurrent = Boolean(
|
|
126
|
-
focusedId &&
|
|
127
|
-
(() => {
|
|
128
|
-
const b = ctx.document.getBlock(focusedId);
|
|
129
|
-
return b && isEditableField(b);
|
|
130
|
-
})(),
|
|
131
|
-
);
|
|
132
|
-
|
|
133
|
-
if (shouldUnfocusPrev || shouldFocusCurrent) {
|
|
134
|
-
ctx.document.apply(
|
|
135
|
-
(tree) => {
|
|
136
|
-
let nextTree = tree;
|
|
137
|
-
if (shouldUnfocusPrev && prevFocusedId) {
|
|
138
|
-
nextTree = ctx.mutations.mutateField<TextField>(nextTree, {
|
|
139
|
-
keyValuePairs: {
|
|
140
|
-
"props.contentEditable": false,
|
|
141
|
-
},
|
|
142
|
-
id: prevFocusedId as FieldId,
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
if (shouldFocusCurrent && focusedId) {
|
|
146
|
-
nextTree = ctx.mutations.mutateField<TextField>(nextTree, {
|
|
147
|
-
keyValuePairs: {
|
|
148
|
-
"props.contentEditable": true,
|
|
149
|
-
},
|
|
150
|
-
id: focusedId as FieldId,
|
|
151
|
-
});
|
|
152
|
-
}
|
|
153
|
-
return nextTree;
|
|
154
|
-
},
|
|
155
|
-
{ shouldEmitEvent: false },
|
|
156
|
-
);
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
void ctx.state.set("focus", payload);
|
|
160
|
-
const selectedBlocks = ctx.state.get("selection");
|
|
161
|
-
|
|
162
|
-
if (payload && !selectedBlocks?.blocks?.has(payload.id)) {
|
|
163
|
-
void ctx.commands.execute("blocks.select", {
|
|
164
|
-
blocks: new Map().set(payload.id, payload.rect),
|
|
165
|
-
mode: "replace",
|
|
166
|
-
});
|
|
167
|
-
} else if (!payload) {
|
|
168
|
-
void ctx.commands.execute("blocks.select", {
|
|
169
|
-
blocks: new Map(),
|
|
170
|
-
mode: "replace",
|
|
171
|
-
});
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
const { blocks: _memoBlocks, count } = ctx.state.get("focus_memory")!;
|
|
175
|
-
if (focusedId && rect) {
|
|
176
|
-
void ctx.state.set("focus_memory", {
|
|
177
|
-
blocks: [..._memoBlocks, { id: focusedId, rect }].slice(-count),
|
|
178
|
-
count,
|
|
179
|
-
});
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
void ctx.events.emit("blocks:focus", payload);
|
|
183
|
-
});
|
|
184
|
-
},
|
|
185
|
-
};
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import type { CoraxTree } from "../../base";
|
|
2
|
-
import type { TModule } from "../modules.types";
|
|
3
|
-
|
|
4
|
-
declare module "../modules-manager" {
|
|
5
|
-
interface ModuleMap {
|
|
6
|
-
history: {};
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
declare module "../../services/state/state" {
|
|
11
|
-
interface StateMap {
|
|
12
|
-
history: { canUndo: boolean; canRedo: boolean };
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
declare module "../../services/commandsbus/commandsbus" {
|
|
17
|
-
interface CommandMap {
|
|
18
|
-
"history.undo": { payload: {}; result: void };
|
|
19
|
-
"history.redo": { payload: {}; result: void };
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export const HistoryModule: TModule = {
|
|
24
|
-
name: "history",
|
|
25
|
-
version: "1.0.0",
|
|
26
|
-
requires: ["focus"],
|
|
27
|
-
install(ctx) {
|
|
28
|
-
const MAX = 100;
|
|
29
|
-
//#Use Set to store the stack
|
|
30
|
-
let stack: CoraxTree[] = [ctx.document.get()];
|
|
31
|
-
let cursor = 0;
|
|
32
|
-
|
|
33
|
-
ctx.state.defineSlice("history", { canUndo: false, canRedo: false });
|
|
34
|
-
const sync = () =>
|
|
35
|
-
ctx.state.set("history", {
|
|
36
|
-
canUndo: cursor > 0,
|
|
37
|
-
canRedo: cursor < stack.length - 1,
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
ctx.events.on("document:changed", ({ value }) => {
|
|
41
|
-
if (value.origin === "history") return;
|
|
42
|
-
stack = [...stack.slice(0, cursor + 1), value.next].slice(-MAX); // coupe la branche redo
|
|
43
|
-
cursor = stack.length - 1;
|
|
44
|
-
sync();
|
|
45
|
-
// console.log("Snapshot: ", value.next.version);
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
const go = (to: number) => {
|
|
49
|
-
if (to < 0 || to >= stack.length) return;
|
|
50
|
-
cursor = to;
|
|
51
|
-
ctx.document.apply(() => stack[cursor], { origin: "history" });
|
|
52
|
-
sync();
|
|
53
|
-
|
|
54
|
-
if (!ctx.state.get("focus")) void ctx.commands.tryExecute("blocks.focus", null);
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
ctx.commands.register("history.undo", () => go(cursor - 1));
|
|
58
|
-
ctx.commands.register("history.redo", () => go(cursor + 1));
|
|
59
|
-
},
|
|
60
|
-
};
|
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
import type { BlockId } from "../../base";
|
|
2
|
-
import type { SliceValue, StateMap } from "../../services/state";
|
|
3
|
-
import type { BlockRect, TModule } from "../modules.types";
|
|
4
|
-
import type { UIContext } from "../../services/ui";
|
|
5
|
-
import type { SlotComponentMap } from "../../services/ui";
|
|
6
|
-
import { overlayPositionFromBlockRects, type EditorRect } from "../editor/editor.module";
|
|
7
|
-
|
|
8
|
-
declare module "../modules-manager" {
|
|
9
|
-
interface ModuleMap {
|
|
10
|
-
hover: {};
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
declare module "../../services/state/state" {
|
|
15
|
-
interface StateMap {
|
|
16
|
-
hover: { id: BlockId; rect: BlockRect } | null;
|
|
17
|
-
hover_memory: { blocks: { id: BlockId; rect: BlockRect }[]; count: number };
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
declare module "../../services/commandsbus/commandsbus" {
|
|
22
|
-
interface CommandMap {
|
|
23
|
-
"blocks.hover": { payload: StateMap["hover"]; result: void };
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
declare module "../../services/eventbus/eventbus" {
|
|
28
|
-
interface TEventMap {
|
|
29
|
-
"blocks:hover": StateMap["hover"];
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
declare module "../../services/ui/ui" {
|
|
34
|
-
interface SlotComponentMap {
|
|
35
|
-
HoverOverlay: {
|
|
36
|
-
position: {
|
|
37
|
-
top: number;
|
|
38
|
-
left: number;
|
|
39
|
-
width: number;
|
|
40
|
-
height: number;
|
|
41
|
-
} | null;
|
|
42
|
-
hidden: boolean;
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
interface ComponentContributionIdentityMap {
|
|
47
|
-
"hover-overlay": {};
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function hoverOverlayPropsFromUICtx(
|
|
52
|
-
ui: UIContext,
|
|
53
|
-
editorRect: EditorRect | null,
|
|
54
|
-
): SlotComponentMap["HoverOverlay"]["position"] | null {
|
|
55
|
-
const rect = ui.hover?.rect;
|
|
56
|
-
if (!rect) return null;
|
|
57
|
-
|
|
58
|
-
return overlayPositionFromBlockRects([rect], editorRect);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
export const HoverModule: TModule = {
|
|
62
|
-
name: "hover",
|
|
63
|
-
version: "1.0.0",
|
|
64
|
-
requires: [],
|
|
65
|
-
install(ctx) {
|
|
66
|
-
ctx.state.defineSlice("hover", null);
|
|
67
|
-
ctx.state.defineSlice("hover_memory", { blocks: [], count: 3 });
|
|
68
|
-
|
|
69
|
-
ctx.ui.contribute("overlay", {
|
|
70
|
-
id: "hover-overlay",
|
|
71
|
-
slot: "overlay",
|
|
72
|
-
order: 999,
|
|
73
|
-
kind: "component",
|
|
74
|
-
name: "HoverOverlay",
|
|
75
|
-
when: (ui) => !!ui.hover?.id,
|
|
76
|
-
getProps: (ui) => {
|
|
77
|
-
const editorState = ctx.state.get("editor") ?? { editorRect: null };
|
|
78
|
-
const selection = ctx.state.get("selection");
|
|
79
|
-
const document = ctx.state.get("document");
|
|
80
|
-
|
|
81
|
-
const position = hoverOverlayPropsFromUICtx(ui, editorState?.editorRect);
|
|
82
|
-
|
|
83
|
-
return {
|
|
84
|
-
position,
|
|
85
|
-
hidden:
|
|
86
|
-
!ui.hover?.id ||
|
|
87
|
-
!position ||
|
|
88
|
-
(!!selection && selection.blocks.has(ui.hover?.id)) ||
|
|
89
|
-
!document?.order.has(ui.hover?.id),
|
|
90
|
-
};
|
|
91
|
-
},
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
ctx.commands.register("blocks.hover", (payload) => {
|
|
95
|
-
if (!payload) {
|
|
96
|
-
void ctx.state.set("hover", null);
|
|
97
|
-
void ctx.events.emit("blocks:hover", null);
|
|
98
|
-
return;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
const { id, rect } = payload;
|
|
102
|
-
const prev = ctx.state.get("hover");
|
|
103
|
-
|
|
104
|
-
if (id !== null && !ctx.document.has(id)) return;
|
|
105
|
-
if (id === prev?.id) return;
|
|
106
|
-
|
|
107
|
-
void ctx.state.set("hover", payload);
|
|
108
|
-
const { blocks: _memoBlocks, count } = ctx.state.get(
|
|
109
|
-
"hover_memory",
|
|
110
|
-
) as SliceValue<"hover_memory">;
|
|
111
|
-
if (id && rect) {
|
|
112
|
-
void ctx.state.set("hover_memory", {
|
|
113
|
-
blocks: [..._memoBlocks, { id, rect }].slice(-count),
|
|
114
|
-
count,
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
void ctx.events.emit("blocks:hover", payload);
|
|
119
|
-
});
|
|
120
|
-
},
|
|
121
|
-
};
|