@coorax/core 0.0.0-canary.1 → 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/types/field/field.blockquote.types.d.ts +4 -0
- package/dist/base/types/field/field.d.ts +14 -3
- package/dist/base/types/field/field.image.types.d.ts +3 -0
- 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/dist/base/types/global.types.d.ts +2 -0
- package/dist/base/types/tree/tree.d.ts +2 -1
- package/dist/constants/field.constants.d.ts +1 -0
- package/dist/constants/index.d.ts +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1174 -388
- 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/focus/focus.module.d.ts +1 -1
- package/dist/modules/history/history.module.d.ts +14 -0
- package/dist/modules/hover/hover.module.d.ts +1 -1
- package/dist/modules/index.d.ts +3 -1
- package/dist/modules/insertion/insertion.module.d.ts +18 -1
- package/dist/modules/modules-manager.d.ts +2 -0
- package/dist/modules/selection/selection.module.d.ts +1 -1
- package/dist/modules/text-editing/text-editing.constants.d.ts +1 -1
- package/dist/modules/text-editing/text-editing.module.d.ts +1 -2
- package/dist/modules/text-editing/text-editing.utils.d.ts +1 -1
- package/dist/services/document/document.d.ts +1 -2
- package/dist/services/eventbus/eventbus.d.ts +4 -4
- package/dist/services/eventbus/eventbus.test.d.ts +1 -1
- package/dist/services/eventbus/subscriber.d.ts +4 -4
- package/dist/services/mutations/mutations.d.ts +10 -5
- package/dist/services/tasks/tasks.service.d.ts +1 -1
- package/dist/services/text-marks/index.d.ts +0 -1
- package/dist/services/text-marks/text-marks.d.ts +1 -1
- package/dist/services/ui/contributions.types.d.ts +79 -0
- package/dist/services/ui/default-styles.d.ts +1 -1
- package/dist/services/ui/index.d.ts +0 -1
- package/dist/services/ui/ui.d.ts +7 -6
- package/dist/services/ui/ui.types.d.ts +7 -95
- package/dist/styles.css +1 -536
- package/dist/utils/fields.utils.d.ts +10 -2
- package/dist/utils/index.d.ts +0 -6
- package/package.json +6 -2
- package/styles.css +4 -2
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { type FieldId } from "@coorax/schema";
|
|
2
|
+
import type { CommandMap } from "../../services/commandsbus/commandsbus";
|
|
3
|
+
import type { TModule } from "../modules.types";
|
|
4
|
+
declare module "../modules-manager" {
|
|
5
|
+
interface ModuleMap {
|
|
6
|
+
caption: {};
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
declare module "../../services/commandsbus/commandsbus" {
|
|
10
|
+
interface CommandMap {
|
|
11
|
+
"caption.add": {
|
|
12
|
+
payload: {
|
|
13
|
+
mediaId: FieldId;
|
|
14
|
+
};
|
|
15
|
+
result: void;
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
declare module "../../services/eventbus/eventbus" {
|
|
20
|
+
interface TEventMap {
|
|
21
|
+
"caption:add": CommandMap["caption.add"]["payload"];
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
declare module "../../services/ui/ui" {
|
|
25
|
+
interface ButtonContributionIdentityMap {
|
|
26
|
+
"insert-caption": {};
|
|
27
|
+
}
|
|
28
|
+
interface IconMap {
|
|
29
|
+
CaptionsIcon: {};
|
|
30
|
+
}
|
|
31
|
+
interface SlotButtonPropsMap {
|
|
32
|
+
CaptionButton: {};
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
export declare const CaptionModule: TModule;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { type FieldId } from "@coorax/schema";
|
|
2
|
+
import type { CommandMap } from "../../services/commandsbus/commandsbus";
|
|
3
|
+
import type { TModule } from "../modules.types";
|
|
4
|
+
declare module "../modules-manager" {
|
|
5
|
+
interface ModuleMap {
|
|
6
|
+
code: {};
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
declare module "../../services/commandsbus/commandsbus" {
|
|
10
|
+
interface CommandMap {
|
|
11
|
+
"code.toggleTheme": {
|
|
12
|
+
payload: {
|
|
13
|
+
fieldId: FieldId;
|
|
14
|
+
};
|
|
15
|
+
result: void;
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
declare module "../../services/eventbus/eventbus" {
|
|
20
|
+
interface TEventMap {
|
|
21
|
+
"code:toggleTheme": CommandMap["code.toggleTheme"]["payload"];
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
declare module "../../services/ui/ui" {
|
|
25
|
+
interface ButtonContributionIdentityMap {
|
|
26
|
+
"format-code-theme": {};
|
|
27
|
+
}
|
|
28
|
+
interface IconMap {
|
|
29
|
+
PaletteIcon: {};
|
|
30
|
+
}
|
|
31
|
+
interface SlotButtonPropsMap {
|
|
32
|
+
CodeThemeButton: {
|
|
33
|
+
isActive: boolean;
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
export declare const CodeModule: TModule;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { TModule } from "../modules.types";
|
|
2
|
+
declare module "../modules-manager" {
|
|
3
|
+
interface ModuleMap {
|
|
4
|
+
deletion: {};
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
declare module "../../services/commandsbus/commandsbus" {
|
|
8
|
+
interface CommandMap {
|
|
9
|
+
"blocks.deleteSelection": {
|
|
10
|
+
payload: void;
|
|
11
|
+
result: void;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
declare module "../../services/ui/ui" {
|
|
16
|
+
interface ButtonContributionIdentityMap {
|
|
17
|
+
"delete-blocks": {};
|
|
18
|
+
}
|
|
19
|
+
interface IconMap {
|
|
20
|
+
TrashIcon: {};
|
|
21
|
+
}
|
|
22
|
+
interface SlotButtonPropsMap {
|
|
23
|
+
DeleteButton: {};
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
export declare const DeletionModule: TModule;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type BlockId } from "@coorax/schema";
|
|
2
2
|
import type { CommandMap } from "../../services/commandsbus";
|
|
3
3
|
import type { StateMap } from "../../services/state";
|
|
4
4
|
import type { BlockRect, TModule } from "../modules.types";
|
|
@@ -10,6 +10,10 @@ declare module "../../services/state/state" {
|
|
|
10
10
|
canUndo: boolean;
|
|
11
11
|
canRedo: boolean;
|
|
12
12
|
};
|
|
13
|
+
"history:stack": {
|
|
14
|
+
size: number;
|
|
15
|
+
cursor: number;
|
|
16
|
+
};
|
|
13
17
|
}
|
|
14
18
|
}
|
|
15
19
|
declare module "../../services/commandsbus/commandsbus" {
|
|
@@ -22,6 +26,16 @@ declare module "../../services/commandsbus/commandsbus" {
|
|
|
22
26
|
payload: {};
|
|
23
27
|
result: void;
|
|
24
28
|
};
|
|
29
|
+
"history.cleanup": {
|
|
30
|
+
payload: {};
|
|
31
|
+
result: void;
|
|
32
|
+
};
|
|
33
|
+
"history.move": {
|
|
34
|
+
payload: {
|
|
35
|
+
cursor: number;
|
|
36
|
+
};
|
|
37
|
+
result: void;
|
|
38
|
+
};
|
|
25
39
|
}
|
|
26
40
|
}
|
|
27
41
|
export declare const HistoryModule: TModule;
|
package/dist/modules/index.d.ts
CHANGED
|
@@ -6,5 +6,7 @@ export * from "./modules-manager";
|
|
|
6
6
|
export * from "./hover/hover.module";
|
|
7
7
|
export * from "./history/history.module";
|
|
8
8
|
export * from "./text-editing/text-editing.module";
|
|
9
|
-
export * from "./text-editing/text-editing.utils";
|
|
10
9
|
export * from "./editor/editor.module";
|
|
10
|
+
export * from "./code/code.module";
|
|
11
|
+
export * from "./caption/caption.module";
|
|
12
|
+
export * from "./deletion/deletion.module";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type Block, type BlockId, type FieldId, type FieldType } from "@coorax/schema";
|
|
2
2
|
import type { CommandMap } from "../../services/commandsbus/commandsbus";
|
|
3
3
|
import type { TModule } from "../modules.types";
|
|
4
4
|
declare module "../../services/commandsbus/commandsbus" {
|
|
@@ -10,6 +10,13 @@ declare module "../../services/commandsbus/commandsbus" {
|
|
|
10
10
|
};
|
|
11
11
|
result: void;
|
|
12
12
|
};
|
|
13
|
+
"fields.change": {
|
|
14
|
+
payload: {
|
|
15
|
+
fieldId: FieldId;
|
|
16
|
+
type: FieldType;
|
|
17
|
+
};
|
|
18
|
+
result: void;
|
|
19
|
+
};
|
|
13
20
|
"blocks.delete": {
|
|
14
21
|
payload: {
|
|
15
22
|
blockId: BlockId;
|
|
@@ -25,6 +32,7 @@ declare module "../../services/commandsbus/commandsbus" {
|
|
|
25
32
|
declare module "../../services/eventbus/eventbus" {
|
|
26
33
|
interface TEventMap {
|
|
27
34
|
"blocks:insert": CommandMap["blocks.insert"]["payload"];
|
|
35
|
+
"fields:change": CommandMap["fields.change"]["payload"];
|
|
28
36
|
"blocks:delete": CommandMap["blocks.delete"]["payload"];
|
|
29
37
|
"actions:toggle": CommandMap["actions.toggle"]["payload"];
|
|
30
38
|
}
|
|
@@ -45,10 +53,19 @@ declare module "../../services/ui/ui" {
|
|
|
45
53
|
"insert-heading": {};
|
|
46
54
|
"insert-text": {};
|
|
47
55
|
"insert-image": {};
|
|
56
|
+
"insert-video": {};
|
|
48
57
|
"insert-divider": {};
|
|
58
|
+
"insert-iframe": {};
|
|
59
|
+
"insert-doc": {};
|
|
60
|
+
"insert-blockquote": {};
|
|
61
|
+
"insert-code": {};
|
|
49
62
|
}
|
|
50
63
|
interface IconMap {
|
|
51
64
|
DividerIcon: {};
|
|
65
|
+
YoutubeIcon: {};
|
|
66
|
+
FileTextIcon: {};
|
|
67
|
+
QuoteIcon: {};
|
|
68
|
+
CodeIcon: {};
|
|
52
69
|
}
|
|
53
70
|
}
|
|
54
71
|
export declare const InsertionModule: TModule;
|
|
@@ -6,6 +6,7 @@ export type ModuleName = keyof ModuleMap;
|
|
|
6
6
|
export interface ModuleManagerInterface {
|
|
7
7
|
register(modules: TModule[]): void;
|
|
8
8
|
isEnabled(name: ModuleName): boolean;
|
|
9
|
+
isRegistered(name: ModuleName): boolean;
|
|
9
10
|
enable(name: ModuleName): void;
|
|
10
11
|
enableAll(): void;
|
|
11
12
|
disable(name: ModuleName, opts?: {
|
|
@@ -21,6 +22,7 @@ export declare class ModuleManager implements ModuleManagerInterface {
|
|
|
21
22
|
constructor(engine: Engine);
|
|
22
23
|
register(modules: TModule[]): void;
|
|
23
24
|
isEnabled(name: ModuleName): boolean;
|
|
25
|
+
isRegistered(name: ModuleName): boolean;
|
|
24
26
|
enable(name: ModuleName): void;
|
|
25
27
|
enableAll(): void;
|
|
26
28
|
disabledAll(): void;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { BlockId } from "
|
|
1
|
+
import type { BlockId } from "@coorax/schema";
|
|
2
2
|
import type { CommandMap } from "../../services/commandsbus/commandsbus";
|
|
3
3
|
import type { StateMap } from "../../services/state";
|
|
4
4
|
import type { BlockRect, TModule } from "../modules.types";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { MarkAttrs, MarkType } from "
|
|
1
|
+
import type { MarkAttrs, MarkType } from "@coorax/schema";
|
|
2
2
|
export declare const MARK_DEFAULT_ATTRS: Partial<Record<MarkType, MarkAttrs>>;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type FieldId, type FieldTextContentPath, type Mark, type MarkAttrs, type MarkSpec, type MarkType } from "@coorax/schema";
|
|
2
2
|
import type { CommandMap } from "../../services/commandsbus";
|
|
3
|
-
import type { FieldTextContentPath, Mark, MarkAttrs, MarkSpec, MarkType } from "../../services/text-marks/marks.types";
|
|
4
3
|
import type { TModule } from "../modules.types";
|
|
5
4
|
export type TextSelection = {
|
|
6
5
|
blockId: FieldId;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import { type TreeDiff } from "../../utils/tree.utils";
|
|
1
|
+
import { type Block, type BlockId, type CoraxTree, type TreeDiff } from "@coorax/schema";
|
|
3
2
|
import type { EventBusInterface } from "../eventbus/eventbus";
|
|
4
3
|
import type { StateInterface } from "../state/state";
|
|
5
4
|
declare module "../state/state" {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type FieldId } from "@coorax/schema";
|
|
2
2
|
import { type SubscriberProps } from "./subscriber";
|
|
3
3
|
export type CustomProps<T extends any = any> = T extends object ? Omit<T, "event"> : T;
|
|
4
4
|
export interface TEventMap {
|
|
@@ -14,10 +14,10 @@ export interface TEventMap {
|
|
|
14
14
|
}
|
|
15
15
|
export type TEvent = keyof TEventMap;
|
|
16
16
|
export type EventPropsValue<E extends TEvent = TEvent> = TEventMap[E];
|
|
17
|
-
type EventCallback<E extends TEvent = TEvent, T extends CustomProps =
|
|
17
|
+
type EventCallback<E extends TEvent = TEvent, T extends CustomProps = {}> = (scb: SubscriberProps<E, NoInfer<T>>) => void | Promise<void>;
|
|
18
18
|
type EventDisposer = () => void;
|
|
19
19
|
export interface EventBusInterface {
|
|
20
|
-
on<E extends TEvent = TEvent, T extends CustomProps =
|
|
20
|
+
on<E extends TEvent = TEvent, T extends CustomProps = {}>(ev: E, handler: EventCallback<E, T>): EventDisposer;
|
|
21
21
|
emit<E extends TEvent = TEvent, T extends EventPropsValue<E> = EventPropsValue<E>>(ev: E, props: T, toAwaited?: boolean): Promise<void>;
|
|
22
22
|
batch(evs: ReadonlyArray<readonly [TEvent, any]>): Promise<void>[];
|
|
23
23
|
}
|
|
@@ -25,7 +25,7 @@ export declare class EventBusService implements EventBusInterface {
|
|
|
25
25
|
private handlers;
|
|
26
26
|
isRerenderEventActive: boolean;
|
|
27
27
|
private cleanUpCallback;
|
|
28
|
-
on<E extends TEvent = TEvent, T extends CustomProps =
|
|
28
|
+
on<E extends TEvent = TEvent, T extends CustomProps = {}>(ev: E, callback: EventCallback<E, T>): EventDisposer;
|
|
29
29
|
/**
|
|
30
30
|
* If passed, props will overwrite all custom properties
|
|
31
31
|
* on each event handler
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import type { TEvent, CustomProps, EventPropsValue } from "./eventbus";
|
|
2
2
|
export interface SCB<E extends TEvent = TEvent> extends EventProps<E> {
|
|
3
3
|
readonly target: string;
|
|
4
|
-
readonly event: Omit<
|
|
4
|
+
readonly event: Omit<E, "changes">;
|
|
5
5
|
}
|
|
6
6
|
export type EventProps<E extends TEvent = TEvent> = {
|
|
7
7
|
value: EventPropsValue<E>;
|
|
8
8
|
};
|
|
9
|
-
export type SubscriberProps<E extends TEvent = TEvent, T extends CustomProps =
|
|
10
|
-
value: Partial<T>;
|
|
11
|
-
}
|
|
9
|
+
export type SubscriberProps<E extends TEvent = TEvent, T extends CustomProps = {}> = SCB<E> & {
|
|
10
|
+
value: EventPropsValue<E> & Partial<T>;
|
|
11
|
+
};
|
|
12
12
|
export declare class Subscriber<E extends TEvent = TEvent> implements SCB<E> {
|
|
13
13
|
readonly target: string;
|
|
14
14
|
readonly event: E;
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
import type
|
|
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";
|
|
1
|
+
import { type Container, type CoraxTree, type Field, type FieldId, type FieldType, type OmitContainersMethods, type OmitFieldsMethods } from "@coorax/schema";
|
|
5
2
|
type MaxDepth = [1, 2, 3];
|
|
6
3
|
type DataKeys<T> = {
|
|
7
4
|
[K in keyof T]: T[K] extends (...args: any[]) => any ? never : K;
|
|
@@ -12,7 +9,7 @@ type DeepKey<T, Depth extends any[] = MaxDepth> = Depth["length"] extends 0 ? ne
|
|
|
12
9
|
}[DataKeys<T>];
|
|
13
10
|
type Tail<T extends any[]> = ((...args: T) => any) extends (_: any, ...tail: infer TT) => any ? TT : [];
|
|
14
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;
|
|
15
|
-
type MutationOptions<T extends object, K extends DeepKey<T> = DeepKey<T>> = {
|
|
12
|
+
export type MutationOptions<T extends object, K extends DeepKey<T> = DeepKey<T>> = {
|
|
16
13
|
id: "id" extends keyof T ? T["id"] : never;
|
|
17
14
|
keyValuePairs: Omit<{
|
|
18
15
|
[Key in K]?: DeepValue<T, Key>;
|
|
@@ -22,12 +19,20 @@ type MutationOptions<T extends object, K extends DeepKey<T> = DeepKey<T>> = {
|
|
|
22
19
|
export interface MutationsInterface {
|
|
23
20
|
insertField(tree: CoraxTree, field: Field, index?: number): CoraxTree;
|
|
24
21
|
deleteField(tree: CoraxTree, fieldId: FieldId): CoraxTree;
|
|
22
|
+
changeField(tree: CoraxTree, options: {
|
|
23
|
+
fieldId: FieldId;
|
|
24
|
+
type: FieldType;
|
|
25
|
+
}): CoraxTree;
|
|
25
26
|
mutateField<T extends Field = Field>(tree: CoraxTree, options: MutationOptions<OmitFieldsMethods<T>>): CoraxTree;
|
|
26
27
|
mutateContainer(tree: CoraxTree, options: MutationOptions<OmitContainersMethods<Container>>): CoraxTree;
|
|
27
28
|
}
|
|
28
29
|
export declare class MutationsService implements MutationsInterface {
|
|
29
30
|
insertField(tree: CoraxTree, _field: Field, index?: number): CoraxTree;
|
|
30
31
|
deleteField(tree: CoraxTree, fieldId: FieldId): CoraxTree;
|
|
32
|
+
changeField(tree: CoraxTree, { fieldId, type }: {
|
|
33
|
+
fieldId: FieldId;
|
|
34
|
+
type: FieldType;
|
|
35
|
+
}): CoraxTree;
|
|
31
36
|
mutateField<T extends Field = Field>(tree: CoraxTree, { id, keyValuePairs, autoMerge }: MutationOptions<OmitFieldsMethods<T>>): CoraxTree;
|
|
32
37
|
private canMerge;
|
|
33
38
|
private mergeValues;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { MarkBehavior, MarkSpec, MarkType, TextContent } from "
|
|
1
|
+
import type { MarkBehavior, MarkSpec, MarkType, TextContent } from "@coorax/schema";
|
|
2
2
|
export type TextMarksDisposer = () => void;
|
|
3
3
|
export interface TextMarksInterface {
|
|
4
4
|
replaceRange(content: TextContent, start: number, end: number, text: string, opts?: {
|
|
@@ -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 {};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { NodeCommonProps } from "../../base/types/global.types";
|
|
2
2
|
import type { StyleName } from "./ui.types";
|
|
3
|
-
export declare const
|
|
3
|
+
export declare const DEFAULT_STYLES: Partial<Record<StyleName, NodeCommonProps>>;
|
package/dist/services/ui/ui.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type NodeCommonProps } from "@coorax/schema";
|
|
2
2
|
import type { CommandsInterface, CommandType } from "../commandsbus/commandsbus";
|
|
3
|
-
import type { UiInterface, StyleName,
|
|
3
|
+
import type { UiInterface, StyleName, StylesMap, ContributionDisposer, PayloadInterceptor, UIContext } from "./ui.types";
|
|
4
|
+
import type { ButtonId, Contribution, SlotName } from "./contributions.types";
|
|
4
5
|
export declare class UiService implements UiInterface {
|
|
5
6
|
private commands;
|
|
6
7
|
private styles;
|
|
@@ -9,10 +10,10 @@ export declare class UiService implements UiInterface {
|
|
|
9
10
|
private listeners;
|
|
10
11
|
private interceptors;
|
|
11
12
|
constructor(commands: CommandsInterface);
|
|
12
|
-
interceptPayload<C extends CommandType>(contributionId:
|
|
13
|
-
runContribution
|
|
14
|
-
contribute
|
|
15
|
-
getSlots(slot: SlotName): readonly
|
|
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[];
|
|
16
17
|
subscribe(slot: SlotName, fn: () => void): ContributionDisposer;
|
|
17
18
|
private notify;
|
|
18
19
|
registerStyle(styleName: StyleName, style: NodeCommonProps): ContributionDisposer;
|
|
@@ -1,113 +1,25 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { NodeCommonProps } from "../../base/types/global.types";
|
|
1
|
+
import type { NodeCommonProps, StyleName, StylesMap } from "@coorax/schema";
|
|
3
2
|
import type { CommandPayload, CommandType } from "../commandsbus";
|
|
4
3
|
import type { StateMap } from "../state";
|
|
4
|
+
import type { ButtonIdMap, Contribution, SlotName } from "./contributions.types";
|
|
5
5
|
export type MaybePromise<T> = T | Promise<T>;
|
|
6
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
7
|
export interface UIContext {
|
|
85
8
|
selection: StateMap["selection"];
|
|
86
9
|
focus: StateMap["focus"];
|
|
87
10
|
hover: StateMap["hover"];
|
|
88
11
|
textSelection: StateMap["textSelection"];
|
|
89
12
|
}
|
|
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
13
|
export type ContributionDisposer = () => void;
|
|
96
|
-
type
|
|
97
|
-
[K in Block["type"]]: NodeCommonProps;
|
|
98
|
-
};
|
|
99
|
-
export interface StylesMap extends BlockStyles {
|
|
100
|
-
}
|
|
101
|
-
export type StyleName = keyof StylesMap;
|
|
14
|
+
export type { StylesMap, StyleName };
|
|
102
15
|
export interface UiInterface {
|
|
103
|
-
contribute
|
|
16
|
+
contribute(c: Contribution): ContributionDisposer;
|
|
104
17
|
getSlots(name: SlotName): readonly Contribution[];
|
|
105
18
|
subscribe(name: SlotName, fn: () => void): ContributionDisposer;
|
|
19
|
+
interceptPayload<I extends keyof ButtonIdMap>(id: I, fn: PayloadInterceptor<ButtonIdMap[I] & CommandType>): ContributionDisposer;
|
|
20
|
+
runContribution(c: Contribution<"button">, ui: UIContext): Promise<void>;
|
|
106
21
|
getStyle: <T extends StyleName = StyleName>(styleName: T) => NodeCommonProps;
|
|
107
22
|
registerStyle: (styleName: StyleName, style: NodeCommonProps) => ContributionDisposer;
|
|
108
23
|
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
24
|
}
|
|
112
|
-
export
|
|
113
|
-
export {};
|
|
25
|
+
export * from "./contributions.types";
|