@coorax/core 0.0.0-canary.0

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.
Files changed (78) hide show
  1. package/package.json +40 -0
  2. package/src/base/classes/component.class.ts +68 -0
  3. package/src/base/classes/container.class.ts +57 -0
  4. package/src/base/classes/field.class.ts +42 -0
  5. package/src/base/classes/tnode.class.ts +38 -0
  6. package/src/base/index.ts +23 -0
  7. package/src/base/types/components/components.ts +21 -0
  8. package/src/base/types/container/container.ts +37 -0
  9. package/src/base/types/container/division.types.ts +3 -0
  10. package/src/base/types/container/section.types.ts +3 -0
  11. package/src/base/types/container/ul-list.types.ts +3 -0
  12. package/src/base/types/css.types.ts +33 -0
  13. package/src/base/types/field/divider.types.ts +3 -0
  14. package/src/base/types/field/field.media.types.ts +6 -0
  15. package/src/base/types/field/field.text.types.ts +9 -0
  16. package/src/base/types/field/field.ts +46 -0
  17. package/src/base/types/field/heading.types.ts +3 -0
  18. package/src/base/types/field/paragraph.types.ts +3 -0
  19. package/src/base/types/global.types.ts +45 -0
  20. package/src/base/types/node/link.types.ts +3 -0
  21. package/src/base/types/node/node.ts +28 -0
  22. package/src/base/types/node/span.types.ts +3 -0
  23. package/src/base/types/tree/tree.ts +33 -0
  24. package/src/engine/engine.test.ts +27 -0
  25. package/src/engine/engine.ts +38 -0
  26. package/src/engine/index.ts +1 -0
  27. package/src/index.ts +13 -0
  28. package/src/modules/editor/editor.module.ts +119 -0
  29. package/src/modules/focus/focus.module.ts +185 -0
  30. package/src/modules/history/history.module.ts +60 -0
  31. package/src/modules/hover/hover.module.ts +121 -0
  32. package/src/modules/index.ts +10 -0
  33. package/src/modules/insertion/insertion.module.ts +140 -0
  34. package/src/modules/modules-manager.ts +132 -0
  35. package/src/modules/modules.types.ts +47 -0
  36. package/src/modules/selection/selection.module.ts +174 -0
  37. package/src/modules/selection/selection.test.ts +1 -0
  38. package/src/modules/text-editing/text-editing.constants.ts +6 -0
  39. package/src/modules/text-editing/text-editing.module.ts +377 -0
  40. package/src/modules/text-editing/text-editing.utils.ts +27 -0
  41. package/src/services/commandsbus/commandsbus.test.ts +312 -0
  42. package/src/services/commandsbus/commandsbus.ts +360 -0
  43. package/src/services/commandsbus/index.ts +1 -0
  44. package/src/services/document/document.ts +139 -0
  45. package/src/services/document/index.ts +1 -0
  46. package/src/services/eventbus/eventbus.test.ts +144 -0
  47. package/src/services/eventbus/eventbus.ts +162 -0
  48. package/src/services/eventbus/index.ts +2 -0
  49. package/src/services/eventbus/subscriber.ts +46 -0
  50. package/src/services/mutations/index.ts +2 -0
  51. package/src/services/mutations/mutations.errors.ts +12 -0
  52. package/src/services/mutations/mutations.test.ts +177 -0
  53. package/src/services/mutations/mutations.ts +457 -0
  54. package/src/services/shortcuts/shortcuts.ts +3 -0
  55. package/src/services/state/index.ts +2 -0
  56. package/src/services/state/state.errors.ts +12 -0
  57. package/src/services/state/state.ts +64 -0
  58. package/src/services/tasks/index.ts +1 -0
  59. package/src/services/tasks/tasks.service.test.ts +193 -0
  60. package/src/services/tasks/tasks.service.ts +288 -0
  61. package/src/services/text-marks/index.ts +2 -0
  62. package/src/services/text-marks/marks.types.ts +38 -0
  63. package/src/services/text-marks/text-marks.ts +244 -0
  64. package/src/services/ui/default-styles.ts +93 -0
  65. package/src/services/ui/index.ts +3 -0
  66. package/src/services/ui/ui.errors.ts +6 -0
  67. package/src/services/ui/ui.ts +148 -0
  68. package/src/services/ui/ui.types.ts +197 -0
  69. package/src/utils/components.utils.ts +26 -0
  70. package/src/utils/container.utils.ts +59 -0
  71. package/src/utils/fields.utils.ts +118 -0
  72. package/src/utils/global.utils.ts +128 -0
  73. package/src/utils/index.ts +7 -0
  74. package/src/utils/modules.utils.ts +110 -0
  75. package/src/utils/tnode.utils.ts +48 -0
  76. package/src/utils/tree.utils.ts +120 -0
  77. package/styles.css +178 -0
  78. package/tsconfig.json +9 -0
package/package.json ADDED
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "@coorax/core",
3
+ "version": "0.0.0-canary.0",
4
+ "private": false,
5
+ "type": "module",
6
+ "exports": {
7
+ ".": "./src/index.ts",
8
+ "./styles.css": "./styles.css"
9
+ },
10
+ "publishConfig": {
11
+ "access": "public"
12
+ },
13
+ "scripts": {
14
+ "lint": "oxlint",
15
+ "lint:fix": "oxlint --fix --max-warnings=0",
16
+ "fmt": "oxfmt",
17
+ "fmt:check": "oxfmt --check",
18
+ "vtest": "vitest",
19
+ "typecheck": "tsc --noEmit",
20
+ "build": "tsc --emitDeclarationOnly --declaration --outDir dist && bun build ./src/index.ts --outdir ./dist --target node",
21
+ "prepublishOnly": "bun run build"
22
+ },
23
+ "dependencies": {
24
+ "@fontsource-variable/geist": "^5.3.0",
25
+ "@tailwindcss/vite": "4.3.3",
26
+ "cn": "^0.4.0",
27
+ "lodash": "^4.18.1",
28
+ "tailwindcss": "4.3.3"
29
+ },
30
+ "devDependencies": {
31
+ "@types/lodash": "^4.17.27",
32
+ "csstype": "^3.2.3",
33
+ "oxfmt": "^0.71.0",
34
+ "oxlint": "^1.86.0",
35
+ "typescript": "~6.0.2",
36
+ "vite": "^8.3.0",
37
+ "vitest": "^5.0.3"
38
+ },
39
+ "packageManager": "bun@1.3.9"
40
+ }
@@ -0,0 +1,68 @@
1
+ import type { ContainerProps, ContainerTag, ContainerType } from "../types/container/container.ts";
2
+ import type { Component, ComponentId } from "../types/components/components.ts";
3
+ import type { BlockId, CoraxTree } from "../types/tree/tree.ts";
4
+ import type { OmitComponentsMethods } from "../types/global.types.ts";
5
+
6
+ export class ComponentClass<
7
+ TType extends ContainerType = ContainerType,
8
+ TTag extends ContainerTag = ContainerTag,
9
+ > implements Component<TType, TTag> {
10
+ id: ComponentId;
11
+ name: string;
12
+ tag: TTag;
13
+ type: TType;
14
+ props: ContainerProps<TTag>;
15
+ variant = "component" as const;
16
+ order: Set<BlockId>;
17
+ instanceId?: ComponentId;
18
+ count: number;
19
+ updatedAt: number;
20
+ createdAt: number;
21
+
22
+ constructor(component: OmitComponentsMethods<Component<TType, TTag>>) {
23
+ this.id = component.id;
24
+ this.name = component.name;
25
+ this.tag = component.tag;
26
+ this.type = component.type;
27
+ this.variant = component.variant;
28
+ this.order = component.order;
29
+ this.props = component.props;
30
+ this.count = component.count;
31
+ this.updatedAt = component.updatedAt;
32
+ this.createdAt = component.createdAt;
33
+ this.instanceId = component.instanceId;
34
+ }
35
+
36
+ isInstance(): boolean {
37
+ return !!this.instanceId;
38
+ }
39
+
40
+ getChildren(_tree: CoraxTree): Set<BlockId> {
41
+ //#TODO
42
+ return new Set();
43
+ }
44
+
45
+ appendChild(tree: CoraxTree): CoraxTree {
46
+ return tree;
47
+ }
48
+
49
+ removeChild(tree: CoraxTree): CoraxTree {
50
+ return tree;
51
+ }
52
+
53
+ getCurrentComponentObject(): OmitComponentsMethods<Component<TType, TTag>> {
54
+ return {
55
+ id: this.id,
56
+ name: this.name,
57
+ tag: this.tag,
58
+ type: this.type,
59
+ variant: this.variant,
60
+ order: this.order,
61
+ props: this.props,
62
+ count: this.count,
63
+ instanceId: this.instanceId,
64
+ createdAt: this.createdAt,
65
+ updatedAt: this.updatedAt,
66
+ };
67
+ }
68
+ }
@@ -0,0 +1,57 @@
1
+ import type {
2
+ Container,
3
+ ContainerId,
4
+ ContainerProps,
5
+ ContainerTag,
6
+ ContainerType,
7
+ } from "../types/container/container.ts";
8
+ import type { OmitContainersMethods } from "../types/global.types.ts";
9
+ import type { BlockId, CoraxTree } from "../types/tree/tree.ts";
10
+
11
+ export class ContainerClass<
12
+ TType extends ContainerType = ContainerType,
13
+ TTag extends ContainerTag = ContainerTag,
14
+ > implements Container<TType, TTag> {
15
+ id: ContainerId;
16
+ name: string;
17
+ tag: TTag;
18
+ type: TType;
19
+ props: ContainerProps<TTag>;
20
+ variant = "container" as const;
21
+ order: Set<BlockId>;
22
+
23
+ constructor(container: OmitContainersMethods<Container<TType, TTag>>) {
24
+ this.id = container.id;
25
+ this.name = container.name;
26
+ this.tag = container.tag;
27
+ this.type = container.type;
28
+ this.variant = container.variant;
29
+ this.order = container.order;
30
+ this.props = container.props;
31
+ }
32
+
33
+ getChildren(_tree: CoraxTree): Set<BlockId> {
34
+ //#TODO
35
+ return new Set();
36
+ }
37
+
38
+ appendChild(tree: CoraxTree): CoraxTree {
39
+ return tree;
40
+ }
41
+
42
+ removeChild(tree: CoraxTree): CoraxTree {
43
+ return tree;
44
+ }
45
+
46
+ getCurrentContainerObject(): OmitContainersMethods<Container<TType, TTag>> {
47
+ return {
48
+ id: this.id,
49
+ name: this.name,
50
+ tag: this.tag,
51
+ type: this.type,
52
+ variant: this.variant,
53
+ order: this.order,
54
+ props: this.props,
55
+ };
56
+ }
57
+ }
@@ -0,0 +1,42 @@
1
+ import type { Field, FieldId, FieldProps, FieldTag, FieldType } from "../types/field/field.ts";
2
+ import type { ContainerId } from "../types/container/container.ts";
3
+ import type { OmitFieldsMethods } from "../types/global.types.ts";
4
+
5
+ export class FieldClass<
6
+ TType extends FieldType = FieldType,
7
+ TTag extends FieldTag = FieldTag,
8
+ > implements Field<TType, TTag> {
9
+ id: FieldId;
10
+ name: string;
11
+ tag: TTag;
12
+ type: TType;
13
+ variant = "field" as const;
14
+ containerId?: ContainerId;
15
+ props: FieldProps<TTag>;
16
+
17
+ constructor(field: OmitFieldsMethods<Field<TType, TTag>>) {
18
+ this.id = field.id;
19
+ this.name = field.name;
20
+ this.tag = field.tag;
21
+ this.containerId = field.containerId;
22
+ this.props = field.props;
23
+ this.variant = field.variant;
24
+ this.type = field.type;
25
+ }
26
+
27
+ isContainerized(): boolean {
28
+ return !!this.containerId;
29
+ }
30
+
31
+ getCurrentFieldObject(): OmitFieldsMethods<Field<TType, TTag>> {
32
+ return {
33
+ id: this.id,
34
+ name: this.name,
35
+ tag: this.tag,
36
+ containerId: this.containerId,
37
+ props: this.props,
38
+ variant: this.variant,
39
+ type: this.type,
40
+ };
41
+ }
42
+ }
@@ -0,0 +1,38 @@
1
+ import type { TNode, TNodeId, TNodeProps, TNodeTag, TNodeType } from "../types/node/node.ts";
2
+ import type { OmitTNodesMethods } from "../types/global.types.ts";
3
+ import type { FieldId } from "../types/field/field.ts";
4
+
5
+ export class TNodeClass<
6
+ T extends TNodeType = TNodeType,
7
+ A extends TNodeTag = TNodeTag,
8
+ > implements TNode<T, A> {
9
+ id: TNodeId;
10
+ tag: A;
11
+ type: T;
12
+ name: string;
13
+ variant: "tnode";
14
+ fieldId?: FieldId;
15
+ props: TNodeProps<A>;
16
+
17
+ constructor(tnode: OmitTNodesMethods<TNode<T, A>>) {
18
+ this.id = tnode.id;
19
+ this.name = tnode.name;
20
+ this.variant = tnode.variant;
21
+ this.tag = tnode.tag;
22
+ this.props = tnode.props;
23
+ this.type = tnode.type;
24
+ this.fieldId = tnode.fieldId;
25
+ }
26
+
27
+ getCurrentNodeObject(): OmitTNodesMethods<TNode<T, A>> {
28
+ return {
29
+ id: this.id,
30
+ name: this.name,
31
+ variant: this.variant,
32
+ tag: this.tag,
33
+ type: this.type,
34
+ props: this.props,
35
+ fieldId: this.fieldId,
36
+ };
37
+ }
38
+ }
@@ -0,0 +1,23 @@
1
+ export * from "./classes/component.class";
2
+ export * from "./classes/container.class";
3
+ export * from "./classes/field.class";
4
+ export * from "./classes/tnode.class";
5
+
6
+ export * from "./types/components/components";
7
+
8
+ export * from "./types/tree/tree";
9
+ export * from "./types/container/container";
10
+ export * from "./types/container/division.types";
11
+ export * from "./types/container/section.types";
12
+ export * from "./types/container/ul-list.types";
13
+
14
+ export * from "./types/field/field";
15
+ export * from "./types/field/field.text.types";
16
+ export * from "./types/field/heading.types";
17
+ export * from "./types/field/paragraph.types";
18
+
19
+ export * from "./types/node/link.types";
20
+ export * from "./types/node/node";
21
+ export * from "./types/node/span.types";
22
+ export * from "./types/global.types";
23
+ export * from "./types/css.types";
@@ -0,0 +1,21 @@
1
+ import type { Container, ContainerTag, ContainerType } from "../container/container.ts";
2
+ import type { OmitComponentsMethods } from "../global.types.ts";
3
+
4
+ export type ComponentId =
5
+ | `component:${string}-${string}-${string}-${string}-${string}`
6
+ | `component:${string}`;
7
+
8
+ export interface Component<
9
+ T extends ContainerType = ContainerType,
10
+ A extends ContainerTag = ContainerTag,
11
+ > extends Omit<Container<T, A>, "getCurrentContainerObject" | "variant" | "id"> {
12
+ id: ComponentId;
13
+ count: number;
14
+ updatedAt: number;
15
+ createdAt: number;
16
+ variant: "component";
17
+ instanceId?: ComponentId;
18
+
19
+ getCurrentComponentObject(): OmitComponentsMethods<Component<T, A>>;
20
+ isInstance(): boolean;
21
+ }
@@ -0,0 +1,37 @@
1
+ import type { UlListProps } from "./ul-list.types.ts";
2
+ import type { SectionProps } from "./section.types.ts";
3
+ import type { BlockId, CoraxTree } from "../tree/tree.ts";
4
+ import type { OmitContainersMethods } from "../global.types.ts";
5
+ import type { DivisionProps } from "./division.types.ts";
6
+
7
+ export type ContainerType = "list" | "section" | "division";
8
+ export type ContainerTag = "ul" | "section" | "div";
9
+ export type ContainerId =
10
+ | `container:${string}-${string}-${string}-${string}-${string}`
11
+ | `container:${string}`;
12
+
13
+ export type ContainerGlobalProps = {
14
+ ul: UlListProps;
15
+ section: SectionProps;
16
+ div: DivisionProps;
17
+ };
18
+
19
+ export type ContainerProps<A extends ContainerTag = ContainerTag> = ContainerGlobalProps[A];
20
+
21
+ export interface Container<
22
+ T extends ContainerType = ContainerType,
23
+ A extends ContainerTag = ContainerTag,
24
+ > {
25
+ id: ContainerId;
26
+ tag: A;
27
+ type: T;
28
+ name: string;
29
+ props: ContainerProps<A>;
30
+ variant: "container";
31
+ order: Set<BlockId>;
32
+
33
+ getChildren(tree: CoraxTree): Set<BlockId>;
34
+ removeChild(tree: CoraxTree): CoraxTree;
35
+ appendChild(tree: CoraxTree): CoraxTree;
36
+ getCurrentContainerObject(): OmitContainersMethods<Container<T, A>>;
37
+ }
@@ -0,0 +1,3 @@
1
+ import type { NodeCommonProps } from "../global.types";
2
+
3
+ export interface DivisionProps extends NodeCommonProps {}
@@ -0,0 +1,3 @@
1
+ import type { NodeCommonProps } from "../global.types.ts";
2
+
3
+ export interface SectionProps extends NodeCommonProps {}
@@ -0,0 +1,3 @@
1
+ import type { NodeCommonProps } from "../global.types.ts";
2
+
3
+ export interface UlListProps extends NodeCommonProps {}
@@ -0,0 +1,33 @@
1
+ import type * as CSS from "csstype";
2
+
3
+ export type CoraxCSSProperties = CSS.PropertiesFallback<number | string>;
4
+ export type CoraxCSSPropertiesWithMultiValues = {
5
+ [K in keyof CoraxCSSProperties]:
6
+ | CoraxCSSProperties[K]
7
+ | ReadonlyArray<Extract<CoraxCSSProperties[K], string>>;
8
+ };
9
+ export type CoraxCSSPseudos = {
10
+ [K in CSS.Pseudos]?: CoraxCSSObject;
11
+ };
12
+ export interface ArrayCSSInterpolation extends ReadonlyArray<CoraxCSSInterpolation> {}
13
+ export type CoraxInterpolationPrimitive =
14
+ | null
15
+ | undefined
16
+ | boolean
17
+ | number
18
+ | string
19
+ | CoraxKeyframes
20
+ | CoraxCSSObject;
21
+ export type CoraxCSSInterpolation = CoraxInterpolationPrimitive | ArrayCSSInterpolation;
22
+ export interface CoraxCSSOthersObject {
23
+ [propertiesName: string]: CoraxCSSInterpolation;
24
+ }
25
+ export interface CoraxCSSObject
26
+ extends CoraxCSSPropertiesWithMultiValues, CoraxCSSPseudos, CoraxCSSOthersObject {}
27
+
28
+ export type CoraxKeyframes = {
29
+ name: string;
30
+ styles: string;
31
+ anim: number;
32
+ toString: () => string;
33
+ } & string;
@@ -0,0 +1,3 @@
1
+ import type { NodeCommonProps } from "../global.types";
2
+
3
+ export interface DividerProps extends NodeCommonProps {}
@@ -0,0 +1,6 @@
1
+ import type { NodeCommonProps } from "../global.types";
2
+
3
+ export interface MediaCommonProps extends NodeCommonProps {
4
+ src: string;
5
+ alt: string;
6
+ }
@@ -0,0 +1,9 @@
1
+ import type { TextContent } from "../../../services/text-marks/marks.types";
2
+ import type { NodeCommonProps } from "../global.types.ts";
3
+
4
+ export interface TextCommonProps extends NodeCommonProps {
5
+ children: TextContent;
6
+ placeholder?: string;
7
+ contentEditable?: boolean;
8
+ "data-text-path": string;
9
+ }
@@ -0,0 +1,46 @@
1
+ import type { ParagraphProps } from "./paragraph.types.ts";
2
+ import type { HeadingProps } from "./heading.types.ts";
3
+ import type { ContainerId } from "../container/container.ts";
4
+ import type { OmitFieldsMethods } from "../global.types.ts";
5
+ import type { MediaCommonProps } from "./field.media.types";
6
+ import type { DividerProps } from "./divider.types";
7
+
8
+ export type FieldType = keyof FieldTMap;
9
+ export type FieldTag = keyof FieldMap;
10
+ export type FieldId = `field:${string}-${string}-${string}-${string}-${string}` | `field:${string}`;
11
+
12
+ export interface FieldMap {
13
+ p: ParagraphProps;
14
+ h1: HeadingProps;
15
+ img: MediaCommonProps;
16
+ video: MediaCommonProps;
17
+ hr: DividerProps;
18
+ }
19
+
20
+ export interface FieldTMap {
21
+ text: {};
22
+ heading: {};
23
+ image: {};
24
+ video: {};
25
+ divider: {};
26
+ }
27
+
28
+ export type FieldPropsByTag<T extends FieldTag = FieldTag> = FieldMap[T];
29
+ export type FieldProps<A extends FieldTag = FieldTag> = FieldPropsByTag<A>;
30
+
31
+ export interface Field<T extends FieldType = FieldType, A extends FieldTag = FieldTag> {
32
+ id: FieldId;
33
+ tag: A;
34
+ type: T;
35
+ name: string;
36
+ variant: "field";
37
+ containerId?: ContainerId;
38
+ props: FieldProps<A>;
39
+
40
+ isContainerized(): boolean;
41
+ getCurrentFieldObject(): OmitFieldsMethods<Field<T, A>>;
42
+ }
43
+
44
+ export type TextField = Field<"heading" | "text", "h1" | "p">;
45
+ export type MediaField = Field<"image" | "video", "img" | "video">;
46
+ export type DividerField = Field<"divider", "hr">;
@@ -0,0 +1,3 @@
1
+ import type { TextCommonProps } from "./field.text.types.ts";
2
+
3
+ export interface HeadingProps extends TextCommonProps {}
@@ -0,0 +1,3 @@
1
+ import type { TextCommonProps } from "./field.text.types.ts";
2
+
3
+ export interface ParagraphProps extends TextCommonProps {}
@@ -0,0 +1,45 @@
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;
@@ -0,0 +1,3 @@
1
+ import type { NodeCommonProps } from "../global.types.ts";
2
+
3
+ export interface LinkProps extends NodeCommonProps {}
@@ -0,0 +1,28 @@
1
+ import type { FieldId } from "../field/field.ts";
2
+ import type { OmitTNodesMethods } from "../global.types.ts";
3
+ import type { LinkProps } from "./link.types.ts";
4
+ import type { SpanProps } from "./span.types.ts";
5
+
6
+ export type TNodeType = "link" | "sub-field";
7
+ export type TNodeTag = "a" | "span";
8
+ export type TNodeId = `tnode:${string}-${string}-${string}-${string}-${string}` | `node:${string}`;
9
+
10
+ export type TNodeGlobalProps = {
11
+ a: LinkProps;
12
+ span: SpanProps;
13
+ };
14
+
15
+ export type TNodeProps<A extends TNodeTag = TNodeTag> = TNodeGlobalProps[A] & { text: string };
16
+
17
+ export interface TNode<T extends TNodeType = TNodeType, A extends TNodeTag = TNodeTag> {
18
+ id: TNodeId;
19
+ tag: A;
20
+ type: T;
21
+ name: string;
22
+ variant: "tnode";
23
+ fieldId?: FieldId;
24
+ props: TNodeProps<A>;
25
+
26
+ //#TODO
27
+ getCurrentNodeObject(): OmitTNodesMethods<TNode<T, A>>;
28
+ }
@@ -0,0 +1,3 @@
1
+ import type { NodeCommonProps } from "../global.types.ts";
2
+
3
+ export interface SpanProps extends NodeCommonProps {}
@@ -0,0 +1,33 @@
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
+ };
@@ -0,0 +1,27 @@
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
+ // })
@@ -0,0 +1,38 @@
1
+ import { ModuleManager } from "../modules/modules-manager";
2
+ import { CommandsBusService, type CommandsInterface } from "../services/commandsbus/commandsbus";
3
+ import { DocumentService, type DocumentInterface } from "../services/document/document";
4
+ import { EventBusService, type EventBusInterface } from "../services/eventbus/eventbus";
5
+ import { MutationsService, type MutationsInterface } from "../services/mutations/mutations";
6
+ import { ShortcutsService, type ShortcutsInterface } from "../services/shortcuts/shortcuts";
7
+ import { StateService, type StateInterface } from "../services/state/state";
8
+ import { TextMarksService, type TextMarksInterface } from "../services/text-marks/text-marks";
9
+ import { UiService, type UiInterface } from "../services/ui/ui";
10
+ import { TasksService, type TasksInterface } from "../services/tasks/tasks.service";
11
+
12
+ export interface TServices {
13
+ readonly events: EventBusInterface;
14
+ readonly commands: CommandsInterface;
15
+ readonly shortcuts: ShortcutsInterface;
16
+ readonly mutations: MutationsInterface;
17
+ readonly state: StateInterface;
18
+ readonly document: DocumentInterface;
19
+ readonly ui: UiInterface;
20
+ readonly text: TextMarksInterface;
21
+ readonly tasks: TasksInterface;
22
+ }
23
+
24
+ export type TServicesType = keyof TServices;
25
+
26
+ export class Engine implements TServices {
27
+ readonly events = new EventBusService();
28
+ readonly state = new StateService();
29
+ readonly document = new DocumentService(this.state, this.events);
30
+ readonly commands = new CommandsBusService();
31
+ readonly shortcuts = new ShortcutsService();
32
+ readonly mutations = new MutationsService();
33
+ readonly ui = new UiService(this.commands);
34
+ readonly text = new TextMarksService();
35
+ readonly tasks = new TasksService();
36
+
37
+ readonly modules = new ModuleManager(this);
38
+ }
@@ -0,0 +1 @@
1
+ export * from "./engine";
package/src/index.ts ADDED
@@ -0,0 +1,13 @@
1
+ export * from "./base";
2
+ export * from "./engine";
3
+ export * from "./modules";
4
+ export * from "./utils";
5
+
6
+ export * from "./services/commandsbus";
7
+ export * from "./services/document";
8
+ export * from "./services/eventbus";
9
+ export * from "./services/mutations";
10
+ export * from "./services/state";
11
+ export * from "./services/ui";
12
+ export * from "./services/text-marks";
13
+ export * from "./services/tasks";