@coorax/core 0.0.0-canary.0 → 0.0.0-canary.1
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/{src/base/types/field/field.ts → dist/base/types/field/field.d.ts} +19 -26
- 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/{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 +24 -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 +23 -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} +0 -1
- package/dist/index.js +2466 -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 +27 -0
- package/dist/modules/hover/hover.module.d.ts +53 -0
- package/dist/modules/insertion/insertion.module.d.ts +54 -0
- package/dist/modules/modules-manager.d.ts +41 -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 +83 -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 +45 -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 +38 -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/{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/default-styles.d.ts +3 -0
- package/dist/services/ui/ui.d.ts +22 -0
- package/dist/services/ui/ui.errors.d.ts +3 -0
- package/dist/services/ui/ui.types.d.ts +113 -0
- package/dist/styles.css +537 -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 +19 -0
- package/dist/utils/global.utils.d.ts +47 -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 +19 -6
- package/styles.css +1 -3
- 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/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/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/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/modules/index.ts → dist/modules/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
- /package/{src/services/text-marks/index.ts → dist/services/text-marks/index.d.ts} +0 -0
- /package/{src/services/ui/index.ts → dist/services/ui/index.d.ts} +0 -0
- /package/{src/utils/index.ts → dist/utils/index.d.ts} +0 -0
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import type { FieldId } from "../../base";
|
|
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 = CustomProps> = (scb: SubscriberProps<E, T>) => void | Promise<void>;
|
|
18
|
+
type EventDisposer = () => void;
|
|
19
|
+
export interface EventBusInterface {
|
|
20
|
+
on<E extends TEvent = TEvent, T extends CustomProps = 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 = 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<TEvent, "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 = CustomProps> = SCB & {
|
|
10
|
+
value: Partial<T>;
|
|
11
|
+
} & EventProps<E>;
|
|
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,38 @@
|
|
|
1
|
+
import type { Container } from "../../base/types/container/container";
|
|
2
|
+
import type { Field, FieldId } from "../../base/types/field/field";
|
|
3
|
+
import type { OmitContainersMethods, OmitFieldsMethods } from "../../base/types/global.types";
|
|
4
|
+
import type { CoraxTree } from "../../base/types/tree/tree";
|
|
5
|
+
type MaxDepth = [1, 2, 3];
|
|
6
|
+
type DataKeys<T> = {
|
|
7
|
+
[K in keyof T]: T[K] extends (...args: any[]) => any ? never : K;
|
|
8
|
+
}[keyof T] & string;
|
|
9
|
+
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;
|
|
10
|
+
type DeepKey<T, Depth extends any[] = MaxDepth> = Depth["length"] extends 0 ? never : {
|
|
11
|
+
[K in DataKeys<T>]: IsPlainObject<T[K]> extends true ? K | `${K}.${DeepKey<T[K], Tail<Depth>>}` : K;
|
|
12
|
+
}[DataKeys<T>];
|
|
13
|
+
type Tail<T extends any[]> = ((...args: T) => any) extends (_: any, ...tail: infer TT) => any ? TT : [];
|
|
14
|
+
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;
|
|
15
|
+
type MutationOptions<T extends object, K extends DeepKey<T> = DeepKey<T>> = {
|
|
16
|
+
id: "id" extends keyof T ? T["id"] : never;
|
|
17
|
+
keyValuePairs: Omit<{
|
|
18
|
+
[Key in K]?: DeepValue<T, Key>;
|
|
19
|
+
}, "id" | "variant">;
|
|
20
|
+
autoMerge?: boolean;
|
|
21
|
+
};
|
|
22
|
+
export interface MutationsInterface {
|
|
23
|
+
insertField(tree: CoraxTree, field: Field, index?: number): CoraxTree;
|
|
24
|
+
deleteField(tree: CoraxTree, fieldId: FieldId): CoraxTree;
|
|
25
|
+
mutateField<T extends Field = Field>(tree: CoraxTree, options: MutationOptions<OmitFieldsMethods<T>>): CoraxTree;
|
|
26
|
+
mutateContainer(tree: CoraxTree, options: MutationOptions<OmitContainersMethods<Container>>): CoraxTree;
|
|
27
|
+
}
|
|
28
|
+
export declare class MutationsService implements MutationsInterface {
|
|
29
|
+
insertField(tree: CoraxTree, _field: Field, index?: number): CoraxTree;
|
|
30
|
+
deleteField(tree: CoraxTree, fieldId: FieldId): CoraxTree;
|
|
31
|
+
mutateField<T extends Field = Field>(tree: CoraxTree, { id, keyValuePairs, autoMerge }: MutationOptions<OmitFieldsMethods<T>>): CoraxTree;
|
|
32
|
+
private canMerge;
|
|
33
|
+
private mergeValues;
|
|
34
|
+
private setIn;
|
|
35
|
+
private deepObjectUpdate;
|
|
36
|
+
mutateContainer(tree: CoraxTree, { keyValuePairs, id, autoMerge }: MutationOptions<OmitContainersMethods<Container>>): CoraxTree;
|
|
37
|
+
}
|
|
38
|
+
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 "../../utils";
|
|
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
|
+
}
|
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 "./marks.types";
|
|
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,22 @@
|
|
|
1
|
+
import type { NodeCommonProps } from "../../base/types/global.types";
|
|
2
|
+
import type { CommandsInterface, CommandType } from "../commandsbus/commandsbus";
|
|
3
|
+
import type { UiInterface, StyleName, SlotName, Contribution, SlotKey, ContributionKind, StylesMap, ContributionDisposer, PayloadInterceptor, UIContext, ButtonContributionId } from "./ui.types";
|
|
4
|
+
export declare class UiService implements UiInterface {
|
|
5
|
+
private commands;
|
|
6
|
+
private styles;
|
|
7
|
+
private outdatedStyles;
|
|
8
|
+
private bySlot;
|
|
9
|
+
private listeners;
|
|
10
|
+
private interceptors;
|
|
11
|
+
constructor(commands: CommandsInterface);
|
|
12
|
+
interceptPayload<C extends CommandType>(contributionId: ButtonContributionId, fn: PayloadInterceptor<C>): () => Map<keyof ButtonContributionIdentityMap, PayloadInterceptor<any>[]>;
|
|
13
|
+
runContribution<C extends CommandType>(c: Contribution<SlotName, SlotKey, C, "button">, ui: UIContext): Promise<void>;
|
|
14
|
+
contribute<S extends SlotName = SlotName, Arg2 extends SlotKey | CommandType = SlotKey, Arg3 extends CommandType | ContributionKind = Arg2 extends SlotKey ? CommandType : ContributionKind, Arg4 extends ContributionKind = ContributionKind>(slotName: S, c: Contribution<S, Arg2, Arg3, Arg4>): ContributionDisposer;
|
|
15
|
+
getSlots(slot: SlotName): readonly (import("./ui.types").ComponentContribution<keyof import("./ui.types").SlotMap, keyof SlotComponentMap> | import("./ui.types").ButtonContribution<keyof import("./ui.types").SlotMap, keyof import("../commandsbus").CommandMap, keyof SlotButtonPropsMap>)[];
|
|
16
|
+
subscribe(slot: SlotName, fn: () => void): ContributionDisposer;
|
|
17
|
+
private notify;
|
|
18
|
+
registerStyle(styleName: StyleName, style: NodeCommonProps): ContributionDisposer;
|
|
19
|
+
patchStyle(styleName: StyleName, style: NodeCommonProps): ContributionDisposer;
|
|
20
|
+
getStyle<T extends StyleName = keyof StylesMap>(styleName: T): NodeCommonProps;
|
|
21
|
+
}
|
|
22
|
+
export * from "./ui.types";
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import type { BlockId, Block } from "../../base";
|
|
2
|
+
import type { NodeCommonProps } from "../../base/types/global.types";
|
|
3
|
+
import type { CommandPayload, CommandType } from "../commandsbus";
|
|
4
|
+
import type { StateMap } from "../state";
|
|
5
|
+
export type MaybePromise<T> = T | Promise<T>;
|
|
6
|
+
export type PayloadInterceptor<C extends CommandType> = (payload: CommandPayload<C>, ui: UIContext) => MaybePromise<CommandPayload<C> | null>;
|
|
7
|
+
export interface SlotMap {
|
|
8
|
+
toolbar: {};
|
|
9
|
+
"block-actions": {};
|
|
10
|
+
sidebar: {};
|
|
11
|
+
inspector: {};
|
|
12
|
+
overlay: {};
|
|
13
|
+
}
|
|
14
|
+
export type SlotName = keyof SlotMap;
|
|
15
|
+
export interface IconMap {
|
|
16
|
+
TextIcon: {};
|
|
17
|
+
CursorIcon: {};
|
|
18
|
+
HeadingIcon: {};
|
|
19
|
+
CameraIcon: {};
|
|
20
|
+
ImagePlus: {};
|
|
21
|
+
TvMinimalPlayIcon: {};
|
|
22
|
+
QuoteIcon: {};
|
|
23
|
+
BracesIcon: {};
|
|
24
|
+
MinusIcon: {};
|
|
25
|
+
PlusIcon: {};
|
|
26
|
+
BoldIcon: {};
|
|
27
|
+
}
|
|
28
|
+
export type SlotIcon = keyof IconMap;
|
|
29
|
+
export interface SlotComponentMap {
|
|
30
|
+
TextInspector: {
|
|
31
|
+
blockId: BlockId;
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
export type SlotComponentKey = keyof SlotComponentMap;
|
|
35
|
+
export interface SlotButtonPropsMap {
|
|
36
|
+
BlockActionButton: {
|
|
37
|
+
variant: "default" | "outline" | "secondary";
|
|
38
|
+
size: "icon" | "default" | "icon-lg";
|
|
39
|
+
isBaseButton?: boolean;
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
export type SlotButtonKey = keyof SlotButtonPropsMap;
|
|
43
|
+
export type SlotKey = SlotButtonKey | SlotComponentKey;
|
|
44
|
+
export interface ButtonContributionIdentityMap {
|
|
45
|
+
}
|
|
46
|
+
export type ButtonContributionId = keyof ButtonContributionIdentityMap;
|
|
47
|
+
export interface ComponentContributionIdentityMap {
|
|
48
|
+
}
|
|
49
|
+
export type ComponentContributionId = keyof ComponentContributionIdentityMap;
|
|
50
|
+
export type ContributionId = ComponentContributionId | ButtonContributionId;
|
|
51
|
+
type BaseContribution<T extends SlotName = SlotName> = {
|
|
52
|
+
id: ContributionId;
|
|
53
|
+
slot: T;
|
|
54
|
+
order?: number;
|
|
55
|
+
when?: (ui: UIContext) => boolean;
|
|
56
|
+
};
|
|
57
|
+
export type ButtonContribution<S extends SlotName = SlotName, C extends CommandType = CommandType, K extends SlotButtonKey = SlotButtonKey> = {
|
|
58
|
+
[Key in K]: BaseContribution<S> & {
|
|
59
|
+
command: C;
|
|
60
|
+
label?: string;
|
|
61
|
+
name: Key;
|
|
62
|
+
icon: SlotIcon;
|
|
63
|
+
kind: "button";
|
|
64
|
+
getPayload: (ui: UIContext) => CommandPayload<C>;
|
|
65
|
+
getProps: (ui: UIContext) => SlotButtonPropsMap[Key] | null;
|
|
66
|
+
};
|
|
67
|
+
}[K];
|
|
68
|
+
export type ComponentContribution<T extends SlotName = SlotName, K extends SlotComponentKey = SlotComponentKey> = {
|
|
69
|
+
[Key in K]: BaseContribution<T> & {
|
|
70
|
+
kind: "component";
|
|
71
|
+
name: Key;
|
|
72
|
+
getProps: (ui: UIContext) => SlotComponentMap[Key] | null;
|
|
73
|
+
};
|
|
74
|
+
}[K];
|
|
75
|
+
export interface ContributionMap<S extends SlotName = SlotName, C extends CommandType = CommandType, B extends SlotKey = SlotKey> {
|
|
76
|
+
button: ButtonContribution<S, C, Extract<B, SlotButtonKey>>;
|
|
77
|
+
component: ComponentContribution<S, Extract<B, SlotComponentKey>>;
|
|
78
|
+
}
|
|
79
|
+
export type ContributionKind<S extends SlotName = SlotName, Arg2 = any, Arg3 = any> = [
|
|
80
|
+
S,
|
|
81
|
+
Arg2,
|
|
82
|
+
Arg3
|
|
83
|
+
] extends [any, any, any] ? "button" | "component" : never;
|
|
84
|
+
export interface UIContext {
|
|
85
|
+
selection: StateMap["selection"];
|
|
86
|
+
focus: StateMap["focus"];
|
|
87
|
+
hover: StateMap["hover"];
|
|
88
|
+
textSelection: StateMap["textSelection"];
|
|
89
|
+
}
|
|
90
|
+
export type Contribution<S extends SlotName = SlotName, Arg2 extends SlotKey | CommandType = SlotKey, Arg3 extends CommandType | ContributionKind = Arg2 extends SlotKey ? CommandType : ContributionKind, Arg4 extends ContributionKind = ContributionKind> = [Arg2] extends [SlotKey] ? ContributionMap<S, Arg3 extends CommandType ? Arg3 : CommandType, Arg2>[Arg4] : ContributionMap<S, Arg2 extends CommandType ? Arg2 : CommandType, SlotKey>[Arg3 extends ContributionKind ? Arg3 : ContributionKind];
|
|
91
|
+
export type SlotBaseProps<S extends SlotName = SlotName, Arg2 extends SlotKey | CommandType = SlotKey, Arg3 extends CommandType | ContributionKind = Arg2 extends SlotKey ? CommandType : ContributionKind, Arg4 extends ContributionKind = ContributionKind> = {
|
|
92
|
+
c: Contribution<S, Arg2, Arg3, Arg4>;
|
|
93
|
+
ui: UIContext;
|
|
94
|
+
};
|
|
95
|
+
export type ContributionDisposer = () => void;
|
|
96
|
+
type BlockStyles = {
|
|
97
|
+
[K in Block["type"]]: NodeCommonProps;
|
|
98
|
+
};
|
|
99
|
+
export interface StylesMap extends BlockStyles {
|
|
100
|
+
}
|
|
101
|
+
export type StyleName = keyof StylesMap;
|
|
102
|
+
export interface UiInterface {
|
|
103
|
+
contribute<S extends SlotName = SlotName, Arg2 extends SlotKey | CommandType = SlotKey, Arg3 extends CommandType | ContributionKind = Arg2 extends SlotKey ? CommandType : ContributionKind, Arg4 extends ContributionKind = ContributionKind>(slotName: S, contribution: Contribution<S, Arg2, Arg3, Arg4>): ContributionDisposer;
|
|
104
|
+
getSlots(name: SlotName): readonly Contribution[];
|
|
105
|
+
subscribe(name: SlotName, fn: () => void): ContributionDisposer;
|
|
106
|
+
getStyle: <T extends StyleName = StyleName>(styleName: T) => NodeCommonProps;
|
|
107
|
+
registerStyle: (styleName: StyleName, style: NodeCommonProps) => ContributionDisposer;
|
|
108
|
+
patchStyle: (styleName: StyleName, style: NodeCommonProps) => ContributionDisposer;
|
|
109
|
+
interceptPayload<C extends CommandType>(contributionId: ButtonContributionId, fn: PayloadInterceptor<C>): ContributionDisposer;
|
|
110
|
+
runContribution<C extends CommandType>(c: Contribution<SlotName, SlotKey, C, "button">, ui: UIContext): Promise<void>;
|
|
111
|
+
}
|
|
112
|
+
export declare function createContribution<S extends SlotName = SlotName, Arg2 extends SlotKey | CommandType = SlotKey, Arg3 extends CommandType | ContributionKind = Arg2 extends SlotKey ? CommandType : ContributionKind, Arg4 extends ContributionKind = ContributionKind>(contribution: Contribution<S, Arg2, Arg3, Arg4>): Contribution<S, Arg2, Arg3, Arg4>;
|
|
113
|
+
export {};
|