@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
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
export interface CommandMap {
|
|
2
|
+
}
|
|
3
|
+
export type CommandType = keyof CommandMap;
|
|
4
|
+
export type CommandPayload<T extends CommandType> = CommandMap[T]["payload"];
|
|
5
|
+
export type CommandResult<T extends CommandType> = CommandMap[T]["result"];
|
|
6
|
+
export type CommandHandler<T extends CommandType> = (payload: CommandPayload<T>) => CommandResult<T>;
|
|
7
|
+
export type CommandDisposer = () => void;
|
|
8
|
+
export type HookNextFunction<T extends CommandType = CommandType, P extends CommandPayload<T> = CommandPayload<T>> = (payload: P) => P | null;
|
|
9
|
+
export type AsyncHookNextFunction<T extends CommandType = CommandType, P extends CommandPayload<T> = CommandPayload<T>> = (payload: P) => Promise<P | null> | P | null;
|
|
10
|
+
export type AfterHook<T extends CommandType = CommandType> = (payload: CommandPayload<T>, result: CommandResult<T>) => void;
|
|
11
|
+
export type AsyncCommandHandler<T extends CommandType = CommandType> = (payload: CommandPayload<T>) => Promise<CommandResult<T>> | CommandResult<T>;
|
|
12
|
+
export type AsyncAfterHook<T extends CommandType = CommandType> = (payload: CommandPayload<T>, result: CommandResult<T>) => Promise<void> | void;
|
|
13
|
+
export interface CommandsInterface {
|
|
14
|
+
/**
|
|
15
|
+
* Return null if a **CmdNotFoundError** error is catched
|
|
16
|
+
* else throw the error
|
|
17
|
+
* @param cmd CommandType
|
|
18
|
+
* @param payload CommandPayload<T>
|
|
19
|
+
*/
|
|
20
|
+
tryExecute<T extends CommandType = CommandType>(cmd: T, payload: CommandPayload<T>): CommandResult<T> | null;
|
|
21
|
+
tryExecuteAsync<T extends CommandType = CommandType>(cmd: T, payload: CommandPayload<T>): Promise<CommandResult<T> | null>;
|
|
22
|
+
execute<T extends CommandType = CommandType>(cmd: T, payload: CommandPayload<T>): CommandResult<T> | null;
|
|
23
|
+
executeAsync<T extends CommandType = CommandType>(cmd: T, payload: CommandPayload<T>): Promise<CommandResult<T> | null>;
|
|
24
|
+
register<T extends CommandType = CommandType>(cmd: T, callback: CommandHandler<T>): CommandDisposer;
|
|
25
|
+
registerAsync<T extends CommandType = CommandType>(cmd: T, callback: AsyncCommandHandler<T>): CommandDisposer;
|
|
26
|
+
before<T extends CommandType = CommandType>(cmd: T, next: HookNextFunction<T, CommandPayload<T>>): CommandDisposer;
|
|
27
|
+
beforeAsync<T extends CommandType = CommandType>(cmd: T, next: AsyncHookNextFunction<T, CommandPayload<T>>): CommandDisposer;
|
|
28
|
+
after<T extends CommandType = CommandType>(cmd: T, callback: AfterHook<T>): CommandDisposer;
|
|
29
|
+
afterAsync<T extends CommandType = CommandType>(cmd: T, callback: AsyncAfterHook<T>): CommandDisposer;
|
|
30
|
+
has<T extends CommandType = CommandType>(cmd: T): boolean;
|
|
31
|
+
}
|
|
32
|
+
export declare class CmdNotFoundError extends Error {
|
|
33
|
+
constructor(cmd: CommandType);
|
|
34
|
+
}
|
|
35
|
+
export declare class CommandsBusService implements CommandsInterface {
|
|
36
|
+
private handlers;
|
|
37
|
+
private asyncHandlers;
|
|
38
|
+
private afterHooks;
|
|
39
|
+
private asyncAfterHooks;
|
|
40
|
+
private nextFunctions;
|
|
41
|
+
private asyncNextFunctions;
|
|
42
|
+
tryExecute<T extends CommandType = CommandType>(cmd: T, payload: CommandPayload<T>): CommandResult<T> | null;
|
|
43
|
+
tryExecuteAsync<T extends CommandType = CommandType>(cmd: T, payload: CommandPayload<T>): Promise<CommandResult<T> | null>;
|
|
44
|
+
execute<T extends CommandType = CommandType>(cmd: T, payload: CommandPayload<T>): CommandResult<T> | null;
|
|
45
|
+
executeAsync<T extends CommandType = CommandType>(cmd: T, payload: CommandPayload<T>): Promise<CommandResult<T> | null>;
|
|
46
|
+
register<T extends CommandType = CommandType>(cmd: T, handler: CommandHandler<T>): CommandDisposer;
|
|
47
|
+
registerAsync<T extends CommandType = CommandType>(cmd: T, handler: AsyncCommandHandler<T>): CommandDisposer;
|
|
48
|
+
before<T extends CommandType = CommandType>(cmd: T, next: HookNextFunction<T, CommandPayload<T>>): CommandDisposer;
|
|
49
|
+
beforeAsync<T extends CommandType = CommandType>(cmd: T, next: AsyncHookNextFunction<T, CommandPayload<T>>): CommandDisposer;
|
|
50
|
+
after<T extends CommandType = CommandType>(cmd: T, callback: AfterHook<T>): CommandDisposer;
|
|
51
|
+
afterAsync<T extends CommandType = CommandType>(cmd: T, callback: AsyncAfterHook<T>): CommandDisposer;
|
|
52
|
+
has<T extends CommandType = CommandType>(cmd: T): boolean;
|
|
53
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { type Block, type BlockId, type CoraxTree, type TreeDiff } from "@coorax/schema";
|
|
2
|
+
import type { EventBusInterface } from "../eventbus/eventbus";
|
|
3
|
+
import type { StateInterface } from "../state/state";
|
|
4
|
+
declare module "../state/state" {
|
|
5
|
+
interface StateMap {
|
|
6
|
+
document: CoraxTree;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
declare module "../eventbus/eventbus" {
|
|
10
|
+
interface TEventMap {
|
|
11
|
+
"document:changed": {
|
|
12
|
+
prev: CoraxTree;
|
|
13
|
+
next: CoraxTree;
|
|
14
|
+
diff: TreeDiff;
|
|
15
|
+
origin: "user" | "history";
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
export type DocumentDisposer = () => void;
|
|
20
|
+
export interface DocumentInterface {
|
|
21
|
+
get(): CoraxTree;
|
|
22
|
+
subscribeBlock(id: BlockId, fn: () => void): DocumentDisposer;
|
|
23
|
+
apply(fn: (tree: CoraxTree) => CoraxTree, options?: {
|
|
24
|
+
shouldEmitEvent?: boolean;
|
|
25
|
+
origin?: "user" | "history";
|
|
26
|
+
}): void;
|
|
27
|
+
getBlock(id: BlockId): Block | undefined;
|
|
28
|
+
has(id: BlockId): boolean;
|
|
29
|
+
}
|
|
30
|
+
export declare class DocumentService implements DocumentInterface {
|
|
31
|
+
private state;
|
|
32
|
+
private events;
|
|
33
|
+
private blockListeners;
|
|
34
|
+
constructor(state: StateInterface, events: EventBusInterface);
|
|
35
|
+
subscribeBlock(id: BlockId, fn: () => void): DocumentDisposer;
|
|
36
|
+
private bumpDocumentVersion;
|
|
37
|
+
get(): CoraxTree;
|
|
38
|
+
apply(predicate: (tree: CoraxTree) => CoraxTree, { shouldEmitEvent, origin }?: {
|
|
39
|
+
shouldEmitEvent?: boolean;
|
|
40
|
+
origin?: "user" | "history";
|
|
41
|
+
}): void;
|
|
42
|
+
getBlock(id: BlockId): Block | undefined;
|
|
43
|
+
has(id: BlockId): boolean;
|
|
44
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { type FieldId } from "@coorax/schema";
|
|
2
|
+
import { type SubscriberProps } from "./subscriber";
|
|
3
|
+
export type CustomProps<T extends any = any> = T extends object ? Omit<T, "event"> : T;
|
|
4
|
+
export interface TEventMap {
|
|
5
|
+
changes: CustomProps & {
|
|
6
|
+
event: Omit<TEvent, "changes">;
|
|
7
|
+
};
|
|
8
|
+
"re-render": {
|
|
9
|
+
args: any[];
|
|
10
|
+
};
|
|
11
|
+
"field:update": {
|
|
12
|
+
id: FieldId;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
export type TEvent = keyof TEventMap;
|
|
16
|
+
export type EventPropsValue<E extends TEvent = TEvent> = TEventMap[E];
|
|
17
|
+
type EventCallback<E extends TEvent = TEvent, T extends CustomProps = {}> = (scb: SubscriberProps<E, NoInfer<T>>) => void | Promise<void>;
|
|
18
|
+
type EventDisposer = () => void;
|
|
19
|
+
export interface EventBusInterface {
|
|
20
|
+
on<E extends TEvent = TEvent, T extends CustomProps = {}>(ev: E, handler: EventCallback<E, T>): EventDisposer;
|
|
21
|
+
emit<E extends TEvent = TEvent, T extends EventPropsValue<E> = EventPropsValue<E>>(ev: E, props: T, toAwaited?: boolean): Promise<void>;
|
|
22
|
+
batch(evs: ReadonlyArray<readonly [TEvent, any]>): Promise<void>[];
|
|
23
|
+
}
|
|
24
|
+
export declare class EventBusService implements EventBusInterface {
|
|
25
|
+
private handlers;
|
|
26
|
+
isRerenderEventActive: boolean;
|
|
27
|
+
private cleanUpCallback;
|
|
28
|
+
on<E extends TEvent = TEvent, T extends CustomProps = {}>(ev: E, callback: EventCallback<E, T>): EventDisposer;
|
|
29
|
+
/**
|
|
30
|
+
* If passed, props will overwrite all custom properties
|
|
31
|
+
* on each event handler
|
|
32
|
+
*/
|
|
33
|
+
emit<E extends TEvent = TEvent, T extends any = CustomProps>(ev: E, props: T & EventPropsValue<E>, toAwaited?: boolean): Promise<void>;
|
|
34
|
+
/**
|
|
35
|
+
* Emit multiple events in batch with type-safe event/props pairing
|
|
36
|
+
* @example
|
|
37
|
+
* eventBus.batch([
|
|
38
|
+
* ["field:insert", { fieldOrNode: myField, index: 0 }],
|
|
39
|
+
* ["plugin:mount", { name: "myPlugin" }]
|
|
40
|
+
* ])
|
|
41
|
+
*/
|
|
42
|
+
batch<E1 extends TEvent>(evs: [[E1, EventPropsValue<E1>]]): Promise<void>[];
|
|
43
|
+
batch<E1 extends TEvent, E2 extends TEvent>(evs: [[E1, EventPropsValue<E1>], [E2, EventPropsValue<E2>]]): Promise<void>[];
|
|
44
|
+
batch<E1 extends TEvent, E2 extends TEvent, E3 extends TEvent>(evs: [[E1, EventPropsValue<E1>], [E2, EventPropsValue<E2>], [E3, EventPropsValue<E3>]]): Promise<void>[];
|
|
45
|
+
batch<E1 extends TEvent, E2 extends TEvent, E3 extends TEvent, E4 extends TEvent>(evs: [
|
|
46
|
+
[
|
|
47
|
+
E1,
|
|
48
|
+
EventPropsValue<E1>
|
|
49
|
+
],
|
|
50
|
+
[
|
|
51
|
+
E2,
|
|
52
|
+
EventPropsValue<E2>
|
|
53
|
+
],
|
|
54
|
+
[
|
|
55
|
+
E3,
|
|
56
|
+
EventPropsValue<E3>
|
|
57
|
+
],
|
|
58
|
+
[
|
|
59
|
+
E4,
|
|
60
|
+
EventPropsValue<E4>
|
|
61
|
+
]
|
|
62
|
+
]): Promise<void>[];
|
|
63
|
+
batch<E1 extends TEvent, E2 extends TEvent, E3 extends TEvent, E4 extends TEvent, E5 extends TEvent>(evs: [
|
|
64
|
+
[
|
|
65
|
+
E1,
|
|
66
|
+
EventPropsValue<E1>
|
|
67
|
+
],
|
|
68
|
+
[
|
|
69
|
+
E2,
|
|
70
|
+
EventPropsValue<E2>
|
|
71
|
+
],
|
|
72
|
+
[
|
|
73
|
+
E3,
|
|
74
|
+
EventPropsValue<E3>
|
|
75
|
+
],
|
|
76
|
+
[
|
|
77
|
+
E4,
|
|
78
|
+
EventPropsValue<E4>
|
|
79
|
+
],
|
|
80
|
+
[
|
|
81
|
+
E5,
|
|
82
|
+
EventPropsValue<E5>
|
|
83
|
+
]
|
|
84
|
+
]): Promise<void>[];
|
|
85
|
+
}
|
|
86
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { TEvent, CustomProps, EventPropsValue } from "./eventbus";
|
|
2
|
+
export interface SCB<E extends TEvent = TEvent> extends EventProps<E> {
|
|
3
|
+
readonly target: string;
|
|
4
|
+
readonly event: Omit<E, "changes">;
|
|
5
|
+
}
|
|
6
|
+
export type EventProps<E extends TEvent = TEvent> = {
|
|
7
|
+
value: EventPropsValue<E>;
|
|
8
|
+
};
|
|
9
|
+
export type SubscriberProps<E extends TEvent = TEvent, T extends CustomProps = {}> = SCB<E> & {
|
|
10
|
+
value: EventPropsValue<E> & Partial<T>;
|
|
11
|
+
};
|
|
12
|
+
export declare class Subscriber<E extends TEvent = TEvent> implements SCB<E> {
|
|
13
|
+
readonly target: string;
|
|
14
|
+
readonly event: E;
|
|
15
|
+
value: EventPropsValue<E>;
|
|
16
|
+
constructor(target: string, event: E);
|
|
17
|
+
with<T extends CustomProps = CustomProps>(props: T): SubscriberProps<E, T>;
|
|
18
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { type Container, type CoraxTree, type Field, type FieldId, type FieldType, type OmitContainersMethods, type OmitFieldsMethods } from "@coorax/schema";
|
|
2
|
+
type MaxDepth = [1, 2, 3];
|
|
3
|
+
type DataKeys<T> = {
|
|
4
|
+
[K in keyof T]: T[K] extends (...args: any[]) => any ? never : K;
|
|
5
|
+
}[keyof T] & string;
|
|
6
|
+
type IsPlainObject<T> = T extends object ? T extends (...args: any[]) => any ? false : T extends any[] ? false : T extends Set<any> ? false : T extends Map<any, any> ? false : T extends Date ? false : T extends RegExp ? false : true : false;
|
|
7
|
+
type DeepKey<T, Depth extends any[] = MaxDepth> = Depth["length"] extends 0 ? never : {
|
|
8
|
+
[K in DataKeys<T>]: IsPlainObject<T[K]> extends true ? K | `${K}.${DeepKey<T[K], Tail<Depth>>}` : K;
|
|
9
|
+
}[DataKeys<T>];
|
|
10
|
+
type Tail<T extends any[]> = ((...args: T) => any) extends (_: any, ...tail: infer TT) => any ? TT : [];
|
|
11
|
+
type DeepValue<T, K extends string> = K extends keyof T ? T[K] : K extends `${infer First}.${infer Rest}` ? First extends keyof T ? DeepValue<T[First], Rest> : any : any;
|
|
12
|
+
export type MutationOptions<T extends object, K extends DeepKey<T> = DeepKey<T>> = {
|
|
13
|
+
id: "id" extends keyof T ? T["id"] : never;
|
|
14
|
+
keyValuePairs: Omit<{
|
|
15
|
+
[Key in K]?: DeepValue<T, Key>;
|
|
16
|
+
}, "id" | "variant">;
|
|
17
|
+
autoMerge?: boolean;
|
|
18
|
+
};
|
|
19
|
+
export interface MutationsInterface {
|
|
20
|
+
insertField(tree: CoraxTree, field: Field, index?: number): CoraxTree;
|
|
21
|
+
deleteField(tree: CoraxTree, fieldId: FieldId): CoraxTree;
|
|
22
|
+
changeField(tree: CoraxTree, options: {
|
|
23
|
+
fieldId: FieldId;
|
|
24
|
+
type: FieldType;
|
|
25
|
+
}): CoraxTree;
|
|
26
|
+
mutateField<T extends Field = Field>(tree: CoraxTree, options: MutationOptions<OmitFieldsMethods<T>>): CoraxTree;
|
|
27
|
+
mutateContainer(tree: CoraxTree, options: MutationOptions<OmitContainersMethods<Container>>): CoraxTree;
|
|
28
|
+
}
|
|
29
|
+
export declare class MutationsService implements MutationsInterface {
|
|
30
|
+
insertField(tree: CoraxTree, _field: Field, index?: number): CoraxTree;
|
|
31
|
+
deleteField(tree: CoraxTree, fieldId: FieldId): CoraxTree;
|
|
32
|
+
changeField(tree: CoraxTree, { fieldId, type }: {
|
|
33
|
+
fieldId: FieldId;
|
|
34
|
+
type: FieldType;
|
|
35
|
+
}): CoraxTree;
|
|
36
|
+
mutateField<T extends Field = Field>(tree: CoraxTree, { id, keyValuePairs, autoMerge }: MutationOptions<OmitFieldsMethods<T>>): CoraxTree;
|
|
37
|
+
private canMerge;
|
|
38
|
+
private mergeValues;
|
|
39
|
+
private setIn;
|
|
40
|
+
private deepObjectUpdate;
|
|
41
|
+
mutateContainer(tree: CoraxTree, { keyValuePairs, id, autoMerge }: MutationOptions<OmitContainersMethods<Container>>): CoraxTree;
|
|
42
|
+
}
|
|
43
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export interface StateMap {
|
|
2
|
+
}
|
|
3
|
+
export type SliceName = keyof StateMap;
|
|
4
|
+
export type SliceValue<T extends SliceName = SliceName> = StateMap[T];
|
|
5
|
+
type StateDisposer = () => void;
|
|
6
|
+
export interface StateInterface {
|
|
7
|
+
defineSlice<T extends SliceName = SliceName>(name: T, initialValue: SliceValue<T>): StateDisposer;
|
|
8
|
+
get<T extends SliceName = SliceName>(name: T): SliceValue<T> | undefined;
|
|
9
|
+
set<T extends SliceName = SliceName>(name: T, value: SliceValue<T>): void;
|
|
10
|
+
subscribe<T extends SliceName = SliceName>(name: T, fn: (value: SliceValue<T>) => void): StateDisposer;
|
|
11
|
+
}
|
|
12
|
+
export declare class StateService implements StateInterface {
|
|
13
|
+
private slices;
|
|
14
|
+
private listeners;
|
|
15
|
+
defineSlice<T extends SliceName = SliceName>(name: T, initialValue: SliceValue<T>): StateDisposer;
|
|
16
|
+
get<T extends SliceName = SliceName>(name: T): SliceValue<T> | undefined;
|
|
17
|
+
set<T extends SliceName = SliceName>(name: T, value: SliceValue<T>): void;
|
|
18
|
+
subscribe<T extends SliceName = SliceName>(name: T, fn: (value: SliceValue<T>) => void): StateDisposer;
|
|
19
|
+
}
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { type CustomID } from "@coorax/schema";
|
|
2
|
+
/**
|
|
3
|
+
* Extensible interface mapping task names.
|
|
4
|
+
* Modules or files can extend this interface via declaration merging:
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* declare module "@coorax/core" {
|
|
9
|
+
* interface TaskMap {
|
|
10
|
+
* "autosave:persist": true;
|
|
11
|
+
* }
|
|
12
|
+
* }
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export interface TaskMap {
|
|
16
|
+
}
|
|
17
|
+
export type TaskName = keyof TaskMap extends never ? string : keyof TaskMap | (string & {});
|
|
18
|
+
export type TaskFunction = () => void | Promise<void>;
|
|
19
|
+
export type TaskDisposer = () => void;
|
|
20
|
+
export type TaskStatus = "idle" | "pending" | "running";
|
|
21
|
+
export interface TaskState {
|
|
22
|
+
readonly status: TaskStatus;
|
|
23
|
+
readonly isPending: boolean;
|
|
24
|
+
readonly isRunning: boolean;
|
|
25
|
+
readonly isIdle: boolean;
|
|
26
|
+
readonly lastExecutedAt?: number;
|
|
27
|
+
readonly error?: Error | null;
|
|
28
|
+
readonly taskId: TaskID;
|
|
29
|
+
}
|
|
30
|
+
export type TaskSubscriber = (state: TaskState) => void;
|
|
31
|
+
export interface TaskIdentityMap {
|
|
32
|
+
default: {};
|
|
33
|
+
[k: CustomID<"task">]: {};
|
|
34
|
+
}
|
|
35
|
+
export type TaskID = keyof TaskIdentityMap;
|
|
36
|
+
export interface TaskRecord {
|
|
37
|
+
taskId: TaskID;
|
|
38
|
+
name: TaskName;
|
|
39
|
+
fn: TaskFunction;
|
|
40
|
+
delay: number;
|
|
41
|
+
timerId: ReturnType<typeof setTimeout>;
|
|
42
|
+
}
|
|
43
|
+
export interface TasksInterface {
|
|
44
|
+
/**
|
|
45
|
+
* Schedules a task by name with a delay and an execution function.
|
|
46
|
+
* If a task with the same name is already pending, it cancels the previous one
|
|
47
|
+
* and reschedules with the new function and delay.
|
|
48
|
+
*/
|
|
49
|
+
schedule(name: TaskName, delay: number, fn: TaskFunction, taskId?: TaskID): TaskDisposer;
|
|
50
|
+
/**
|
|
51
|
+
* Cancels a pending task by name.
|
|
52
|
+
* @returns true if a task was found and cancelled, false otherwise.
|
|
53
|
+
*/
|
|
54
|
+
cancel(name: TaskName): boolean;
|
|
55
|
+
/**
|
|
56
|
+
* Checks if a task is currently scheduled and waiting to be executed.
|
|
57
|
+
*/
|
|
58
|
+
isPending(name: TaskName): boolean;
|
|
59
|
+
/**
|
|
60
|
+
* Checks if a task is currently running (its function is actively executing).
|
|
61
|
+
*/
|
|
62
|
+
isRunning(name: TaskName): boolean;
|
|
63
|
+
/**
|
|
64
|
+
* Gets the current status of a task ("idle" | "pending" | "running").
|
|
65
|
+
*/
|
|
66
|
+
getStatus(name: TaskName): TaskStatus;
|
|
67
|
+
/**
|
|
68
|
+
* Gets the current immutable state snapshot of a task.
|
|
69
|
+
*/
|
|
70
|
+
getState(name: TaskName): TaskState;
|
|
71
|
+
/**
|
|
72
|
+
* Immediately executes a pending task and clears its timer.
|
|
73
|
+
*/
|
|
74
|
+
flush(name: TaskName): Promise<void>;
|
|
75
|
+
/**
|
|
76
|
+
* Cancels all currently pending tasks.
|
|
77
|
+
*/
|
|
78
|
+
cancelAll(): void;
|
|
79
|
+
/**
|
|
80
|
+
* Cleans up all pending tasks and subscribers.
|
|
81
|
+
*/
|
|
82
|
+
dispose(): void;
|
|
83
|
+
/**
|
|
84
|
+
* Subscribes to state changes of a specific task (pending, running, idle).
|
|
85
|
+
* @returns A disposer to unsubscribe.
|
|
86
|
+
*/
|
|
87
|
+
subscribe(name: TaskName, fn: TaskSubscriber): TaskDisposer;
|
|
88
|
+
}
|
|
89
|
+
export declare class TasksService implements TasksInterface {
|
|
90
|
+
private pendingTasks;
|
|
91
|
+
private states;
|
|
92
|
+
private listeners;
|
|
93
|
+
private setState;
|
|
94
|
+
private notify;
|
|
95
|
+
getState(name: TaskName): TaskState;
|
|
96
|
+
getStatus(name: TaskName): TaskStatus;
|
|
97
|
+
isPending(name: TaskName): boolean;
|
|
98
|
+
isRunning(name: TaskName): boolean;
|
|
99
|
+
subscribe(name: TaskName, fn: TaskSubscriber): TaskDisposer;
|
|
100
|
+
schedule(name: TaskName, delay: number, fn: TaskFunction, taskId?: TaskID): TaskDisposer;
|
|
101
|
+
private executeTask;
|
|
102
|
+
cancel(name: TaskName): boolean;
|
|
103
|
+
flush(name: TaskName): Promise<void>;
|
|
104
|
+
cancelAll(): void;
|
|
105
|
+
dispose(): void;
|
|
106
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./text-marks";
|
package/{src/services/text-marks/marks.types.ts → dist/services/text-marks/marks.types.d.ts}
RENAMED
|
@@ -1,38 +1,35 @@
|
|
|
1
1
|
import type { TextField } from "../../base";
|
|
2
2
|
import type { NodeCommonProps, PathToProp } from "../../base/types/global.types";
|
|
3
|
-
|
|
4
3
|
export interface MarkMap {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
4
|
+
bold: {};
|
|
5
|
+
italic: {};
|
|
6
|
+
underline: {};
|
|
7
|
+
link: {
|
|
8
|
+
href: string;
|
|
9
|
+
};
|
|
10
|
+
code: {};
|
|
11
|
+
initial: {
|
|
12
|
+
style: NodeCommonProps["style"];
|
|
13
|
+
};
|
|
11
14
|
}
|
|
12
|
-
|
|
13
15
|
export type MarkType = keyof MarkMap;
|
|
14
16
|
export type MarkAttrs<T extends MarkType = MarkType> = MarkMap[T];
|
|
15
|
-
|
|
16
17
|
export interface Mark<T extends MarkType = MarkType> {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
type: T;
|
|
19
|
+
start: number;
|
|
20
|
+
end: number;
|
|
21
|
+
attrs?: MarkAttrs<T>;
|
|
21
22
|
}
|
|
22
|
-
|
|
23
23
|
export interface MarkSpec<T extends MarkType = MarkType> {
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
type: T;
|
|
25
|
+
attrs?: MarkAttrs<T>;
|
|
26
26
|
}
|
|
27
|
-
|
|
28
27
|
export interface MarkBehavior {
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
/** Un caractère tapé juste après la fin du mark l'étend-il ? */
|
|
29
|
+
inclusive: boolean;
|
|
31
30
|
}
|
|
32
|
-
|
|
33
31
|
export interface TextContent {
|
|
34
|
-
|
|
35
|
-
|
|
32
|
+
text: string;
|
|
33
|
+
marks: readonly Mark[];
|
|
36
34
|
}
|
|
37
|
-
|
|
38
35
|
export type FieldTextContentPath = PathToProp<TextField, TextContent>;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { MarkBehavior, MarkSpec, MarkType, TextContent } from "@coorax/schema";
|
|
2
|
+
export type TextMarksDisposer = () => void;
|
|
3
|
+
export interface TextMarksInterface {
|
|
4
|
+
replaceRange(content: TextContent, start: number, end: number, text: string, opts?: {
|
|
5
|
+
marks?: readonly MarkSpec[];
|
|
6
|
+
}): TextContent;
|
|
7
|
+
toggleMark(content: TextContent, { start, end, spec }: {
|
|
8
|
+
start: number;
|
|
9
|
+
end: number;
|
|
10
|
+
spec: MarkSpec;
|
|
11
|
+
}): TextContent;
|
|
12
|
+
deleteRange(content: TextContent, start: number, end: number): TextContent;
|
|
13
|
+
insertText(content: TextContent, at: number, text: string, opts?: {
|
|
14
|
+
marks?: readonly MarkSpec[];
|
|
15
|
+
}): TextContent;
|
|
16
|
+
registerMark(type: MarkType, behavior?: MarkBehavior): TextMarksDisposer;
|
|
17
|
+
isInclusive(type: MarkType): boolean;
|
|
18
|
+
insertText(content: TextContent, at: number, text: string, opts?: {
|
|
19
|
+
marks?: readonly MarkSpec[];
|
|
20
|
+
}): TextContent;
|
|
21
|
+
}
|
|
22
|
+
export declare class TextMarksService implements TextMarksInterface {
|
|
23
|
+
private behaviors;
|
|
24
|
+
registerMark(type: MarkType, behavior?: MarkBehavior): TextMarksDisposer;
|
|
25
|
+
isInclusive(type: MarkType): boolean;
|
|
26
|
+
private attrsKey;
|
|
27
|
+
private sameMarks;
|
|
28
|
+
private normalizeMarks;
|
|
29
|
+
/** Vrai si [start, end) est entièrement couvert par des marks de ce type. */
|
|
30
|
+
private isFullyMarked;
|
|
31
|
+
/** Retire le type de mark sur [start, end) en coupant les marks qui débordent. */
|
|
32
|
+
private removeMark;
|
|
33
|
+
toggleMark(content: TextContent, { start, end, spec }: {
|
|
34
|
+
start: number;
|
|
35
|
+
end: number;
|
|
36
|
+
spec: MarkSpec;
|
|
37
|
+
}): TextContent;
|
|
38
|
+
deleteRange(content: TextContent, start: number, end: number): TextContent;
|
|
39
|
+
insertText(content: TextContent, at: number, text: string, opts?: {
|
|
40
|
+
marks?: readonly MarkSpec[];
|
|
41
|
+
}): TextContent;
|
|
42
|
+
replaceRange(content: TextContent, start: number, end: number, text: string, opts?: {
|
|
43
|
+
marks?: readonly MarkSpec[];
|
|
44
|
+
}): TextContent;
|
|
45
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import type { BlockId } from "@coorax/schema";
|
|
2
|
+
import type { CommandPayload, CommandType } from "../commandsbus";
|
|
3
|
+
import type { UIContext } from "./ui.types";
|
|
4
|
+
export interface IconMap {
|
|
5
|
+
TextIcon: {};
|
|
6
|
+
CursorIcon: {};
|
|
7
|
+
HeadingIcon: {};
|
|
8
|
+
CameraIcon: {};
|
|
9
|
+
ImagePlus: {};
|
|
10
|
+
TvMinimalPlayIcon: {};
|
|
11
|
+
BracesIcon: {};
|
|
12
|
+
MinusIcon: {};
|
|
13
|
+
PlusIcon: {};
|
|
14
|
+
BoldIcon: {};
|
|
15
|
+
}
|
|
16
|
+
export type SlotIcon = keyof IconMap;
|
|
17
|
+
export interface SlotMap {
|
|
18
|
+
toolbar: {};
|
|
19
|
+
"block-actions": {};
|
|
20
|
+
sidebar: {};
|
|
21
|
+
inspector: {};
|
|
22
|
+
overlay: {};
|
|
23
|
+
}
|
|
24
|
+
export type SlotName = keyof SlotMap;
|
|
25
|
+
export interface SlotButtonPropsMap {
|
|
26
|
+
BlockActionButton: {
|
|
27
|
+
variant: "default" | "outline" | "secondary";
|
|
28
|
+
size: "icon" | "default" | "icon-lg" | "icon-sm";
|
|
29
|
+
isBaseButton?: boolean;
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
export type SlotButtonKey = keyof SlotButtonPropsMap;
|
|
33
|
+
export interface SlotComponentMap {
|
|
34
|
+
TextInspector: {
|
|
35
|
+
blockId: BlockId;
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
export type SlotComponentKey = keyof SlotComponentMap;
|
|
39
|
+
export type SlotKey = SlotButtonKey | SlotComponentKey;
|
|
40
|
+
export type SlotBaseProps<C extends Contribution = Contribution> = {
|
|
41
|
+
c: C;
|
|
42
|
+
ui: UIContext;
|
|
43
|
+
};
|
|
44
|
+
export interface ButtonIdMap {
|
|
45
|
+
}
|
|
46
|
+
export type ButtonId = keyof ButtonIdMap extends never ? string : keyof ButtonIdMap;
|
|
47
|
+
interface BaseContribution<S extends SlotName> {
|
|
48
|
+
id: string;
|
|
49
|
+
slot: S;
|
|
50
|
+
order?: number;
|
|
51
|
+
when?: (ui: UIContext) => boolean;
|
|
52
|
+
}
|
|
53
|
+
export type ButtonContribution<S extends SlotName = SlotName, C extends CommandType = CommandType, K extends SlotButtonKey = SlotButtonKey> = BaseContribution<S> & {
|
|
54
|
+
kind: "button";
|
|
55
|
+
name: K;
|
|
56
|
+
command: C;
|
|
57
|
+
icon: SlotIcon;
|
|
58
|
+
label?: string;
|
|
59
|
+
getPayload: (ui: UIContext) => CommandPayload<C>;
|
|
60
|
+
getProps: (ui: UIContext) => SlotButtonPropsMap[K] | null;
|
|
61
|
+
};
|
|
62
|
+
export type ComponentContribution<S extends SlotName = SlotName, K extends SlotComponentKey = SlotComponentKey> = BaseContribution<S> & {
|
|
63
|
+
kind: "component";
|
|
64
|
+
name: K;
|
|
65
|
+
getProps: (ui: UIContext) => SlotComponentMap[K] | null;
|
|
66
|
+
};
|
|
67
|
+
export interface ContributionKindMap {
|
|
68
|
+
button: {
|
|
69
|
+
[K in SlotButtonKey]: ButtonContribution<SlotName, any, K>;
|
|
70
|
+
}[SlotButtonKey];
|
|
71
|
+
component: {
|
|
72
|
+
[K in SlotComponentKey]: ComponentContribution<SlotName, K>;
|
|
73
|
+
}[SlotComponentKey];
|
|
74
|
+
}
|
|
75
|
+
export type ContributionKind = keyof ContributionKindMap;
|
|
76
|
+
export type Contribution<K extends ContributionKind = ContributionKind> = ContributionKindMap[K];
|
|
77
|
+
export declare const defineButton: <S extends SlotName, C extends CommandType, K extends SlotButtonKey>(c: ButtonContribution<S, C, K>) => ButtonContribution<S, C, K>;
|
|
78
|
+
export declare const defineComponent: <S extends SlotName, K extends SlotComponentKey>(c: ComponentContribution<S, K>) => ComponentContribution<S, K>;
|
|
79
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type NodeCommonProps } from "@coorax/schema";
|
|
2
|
+
import type { CommandsInterface, CommandType } from "../commandsbus/commandsbus";
|
|
3
|
+
import type { UiInterface, StyleName, StylesMap, ContributionDisposer, PayloadInterceptor, UIContext } from "./ui.types";
|
|
4
|
+
import type { ButtonId, Contribution, SlotName } from "./contributions.types";
|
|
5
|
+
export declare class UiService implements UiInterface {
|
|
6
|
+
private commands;
|
|
7
|
+
private styles;
|
|
8
|
+
private outdatedStyles;
|
|
9
|
+
private bySlot;
|
|
10
|
+
private listeners;
|
|
11
|
+
private interceptors;
|
|
12
|
+
constructor(commands: CommandsInterface);
|
|
13
|
+
interceptPayload<C extends CommandType>(contributionId: ButtonId, fn: PayloadInterceptor<C>): () => Map<string, PayloadInterceptor<any>[]>;
|
|
14
|
+
runContribution(c: Contribution<"button">, ui: UIContext): Promise<void>;
|
|
15
|
+
contribute(c: Contribution): ContributionDisposer;
|
|
16
|
+
getSlots(slot: SlotName): readonly Contribution[];
|
|
17
|
+
subscribe(slot: SlotName, fn: () => void): ContributionDisposer;
|
|
18
|
+
private notify;
|
|
19
|
+
registerStyle(styleName: StyleName, style: NodeCommonProps): ContributionDisposer;
|
|
20
|
+
patchStyle(styleName: StyleName, style: NodeCommonProps): ContributionDisposer;
|
|
21
|
+
getStyle<T extends StyleName = keyof StylesMap>(styleName: T): NodeCommonProps;
|
|
22
|
+
}
|
|
23
|
+
export * from "./ui.types";
|