@pooder/core 0.1.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/dist/index.d.mts +243 -134
- package/dist/index.d.ts +243 -134
- package/dist/index.js +442 -370
- package/dist/index.mjs +434 -367
- package/package.json +2 -4
- package/src/command.ts +9 -60
- package/src/context.ts +17 -0
- package/src/contribution/index.ts +12 -0
- package/src/contribution/points.ts +63 -0
- package/src/contribution/registry.ts +118 -0
- package/src/disposable.ts +3 -0
- package/src/event.ts +9 -4
- package/src/extension.ts +108 -171
- package/src/index.ts +140 -31
- package/src/run-test-full.ts +98 -0
- package/src/service.ts +25 -0
- package/src/services/CommandService.ts +79 -0
- package/src/services/ConfigurationService.ts +107 -0
- package/src/services/index.ts +4 -0
- package/src/test-extension-full.ts +79 -0
- package/tsconfig.test.json +7 -0
- package/src/canvas.ts +0 -3
- package/src/editor.ts +0 -226
- package/src/layer.ts +0 -13
- package/src/obj.ts +0 -7
- package/src/types.ts +0 -105
package/CHANGELOG.md
CHANGED
package/dist/index.d.mts
CHANGED
|
@@ -1,158 +1,267 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
declare module "fabric" {
|
|
5
|
-
interface FabricObject {
|
|
6
|
-
data?: any;
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
declare module "fabric" {
|
|
11
|
-
interface Group {
|
|
12
|
-
data?: any;
|
|
13
|
-
}
|
|
14
|
-
interface GroupProps {
|
|
15
|
-
data?: any;
|
|
16
|
-
}
|
|
17
|
-
interface SerializedGroupProps {
|
|
18
|
-
data?: any;
|
|
19
|
-
}
|
|
1
|
+
interface Service {
|
|
2
|
+
init?(): void;
|
|
3
|
+
dispose?(): void;
|
|
20
4
|
}
|
|
21
|
-
|
|
22
|
-
|
|
5
|
+
declare class ServiceRegistry {
|
|
6
|
+
private services;
|
|
7
|
+
register<T extends Service>(name: string, service: T): T;
|
|
8
|
+
get<T extends Service>(serviceName: string): T | undefined;
|
|
9
|
+
has(serviceName: string): boolean;
|
|
10
|
+
delete(serviceName: string): void;
|
|
23
11
|
}
|
|
24
12
|
|
|
25
|
-
|
|
13
|
+
type EventHandler = (...args: any[]) => void | boolean;
|
|
14
|
+
declare class EventBus {
|
|
15
|
+
private events;
|
|
16
|
+
on(event: string, handler: EventHandler, priority?: number): void;
|
|
17
|
+
off(event: string, handler: EventHandler): void;
|
|
18
|
+
emit(event: string, ...args: any[]): void;
|
|
19
|
+
clear(): void;
|
|
20
|
+
count(event: string): number;
|
|
26
21
|
}
|
|
27
22
|
|
|
28
|
-
interface
|
|
29
|
-
|
|
30
|
-
label?: string;
|
|
23
|
+
interface ContributionPoint<T = any> {
|
|
24
|
+
id: string;
|
|
31
25
|
description?: string;
|
|
32
|
-
|
|
26
|
+
validate?: (data: T) => boolean;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Command Contribution Data Definition
|
|
30
|
+
*/
|
|
31
|
+
interface CommandContribution {
|
|
32
|
+
id: string;
|
|
33
|
+
command: string;
|
|
34
|
+
title: string;
|
|
35
|
+
handler?: (...args: any[]) => any;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Tool Contribution Data Definition
|
|
39
|
+
*/
|
|
40
|
+
interface ToolContribution {
|
|
41
|
+
id: string;
|
|
42
|
+
name: string;
|
|
43
|
+
description: string;
|
|
44
|
+
parameters?: Record<string, any>;
|
|
45
|
+
execute: (...args: any[]) => Promise<any>;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* View Contribution Data Definition
|
|
49
|
+
*/
|
|
50
|
+
interface ViewContribution {
|
|
51
|
+
id: string;
|
|
52
|
+
name: string;
|
|
53
|
+
type: "sidebar" | "panel" | "editor" | "dialog" | "status-bar";
|
|
54
|
+
component: any;
|
|
55
|
+
location?: string;
|
|
56
|
+
icon?: string;
|
|
57
|
+
priority?: number;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Configuration Contribution Data Definition
|
|
61
|
+
*/
|
|
62
|
+
interface ConfigurationContribution {
|
|
63
|
+
id: string;
|
|
64
|
+
type: "string" | "number" | "boolean" | "color" | "select" | "json";
|
|
65
|
+
label: string;
|
|
33
66
|
default?: any;
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
value: any;
|
|
37
|
-
}[];
|
|
67
|
+
description?: string;
|
|
68
|
+
options?: string[];
|
|
38
69
|
min?: number;
|
|
39
70
|
max?: number;
|
|
71
|
+
step?: number;
|
|
40
72
|
}
|
|
41
|
-
|
|
42
|
-
|
|
73
|
+
declare const ContributionPointIds: {
|
|
74
|
+
CONTRIBUTIONS: string;
|
|
75
|
+
COMMANDS: string;
|
|
76
|
+
TOOLS: string;
|
|
77
|
+
VIEWS: string;
|
|
78
|
+
CONFIGURATIONS: string;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
interface Disposable {
|
|
82
|
+
dispose(): void;
|
|
43
83
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
84
|
+
|
|
85
|
+
declare class ContributionRegistry {
|
|
86
|
+
private points;
|
|
87
|
+
private contributions;
|
|
88
|
+
/**
|
|
89
|
+
* Register a new contribution point
|
|
90
|
+
*/
|
|
91
|
+
registerPoint<T>(point: ContributionPoint<T>): void;
|
|
92
|
+
/**
|
|
93
|
+
* Register a contribution to a specific point
|
|
94
|
+
* @returns Disposable to unregister the contribution
|
|
95
|
+
*/
|
|
96
|
+
register<T>(pointId: string, contribution: Contribution<T>): Disposable;
|
|
97
|
+
/**
|
|
98
|
+
* Get all contributions for a given point
|
|
99
|
+
*/
|
|
100
|
+
get<T>(pointId: string): Contribution<T>[];
|
|
101
|
+
/**
|
|
102
|
+
* Get a specific contribution by ID
|
|
103
|
+
*/
|
|
104
|
+
getById<T>(id: string): Contribution<T> | undefined;
|
|
105
|
+
/**
|
|
106
|
+
* Get the contribution point definition
|
|
107
|
+
*/
|
|
108
|
+
getPoint(pointId: string): ContributionPoint | undefined;
|
|
109
|
+
/**
|
|
110
|
+
* Unregister a contribution
|
|
111
|
+
*/
|
|
112
|
+
private unregister;
|
|
47
113
|
}
|
|
48
|
-
|
|
114
|
+
|
|
115
|
+
interface ContributionMetadata {
|
|
49
116
|
name: string;
|
|
50
|
-
|
|
117
|
+
extensionId: string;
|
|
51
118
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
119
|
+
interface Contribution<T = any> {
|
|
120
|
+
id: string;
|
|
121
|
+
data: T;
|
|
122
|
+
metadata?: Partial<ContributionMetadata>;
|
|
55
123
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
124
|
+
|
|
125
|
+
interface ExtensionContext {
|
|
126
|
+
readonly eventBus: EventBus;
|
|
127
|
+
readonly services: {
|
|
128
|
+
get<T extends Service>(serviceName: string): T | undefined;
|
|
129
|
+
};
|
|
130
|
+
readonly contributions: {
|
|
131
|
+
get<T>(pointId: string): Contribution<T>[];
|
|
132
|
+
register<T>(pointId: string, contribution: Contribution<T>): Disposable;
|
|
133
|
+
};
|
|
66
134
|
}
|
|
67
|
-
|
|
135
|
+
|
|
136
|
+
interface ExtensionMetadata {
|
|
68
137
|
name: string;
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
extensions: ExtensionMap;
|
|
91
|
-
commands: CommandMap;
|
|
92
|
-
use(extension: Extension): void;
|
|
93
|
-
unuse(name: string): void;
|
|
94
|
-
getExtension(name: string): Extension | undefined;
|
|
95
|
-
getExtensions(): Extension[];
|
|
96
|
-
enableExtension(name: string): void;
|
|
97
|
-
disableExtension(name: string): void;
|
|
98
|
-
registerCommand(name: string, command: Command): void;
|
|
99
|
-
unregisterCommand(name: string): void;
|
|
100
|
-
executeCommand(name: string, ...args: any[]): void;
|
|
101
|
-
on(event: string, handler: EventHandler, priority?: number): void;
|
|
102
|
-
off(event: string, handler: EventHandler): void;
|
|
103
|
-
emit(event: string, ...args: any[]): void;
|
|
104
|
-
getObjects(): FabricObject[];
|
|
105
|
-
getObject(id: string, layerId?: string): FabricObject | undefined;
|
|
106
|
-
getLayers(): Group[];
|
|
107
|
-
getLayer(id: string): Group | undefined;
|
|
108
|
-
updateState(updater: (state: EditorState) => EditorState): void;
|
|
109
|
-
getState(): EditorState;
|
|
110
|
-
toJSON(): any;
|
|
111
|
-
loadFromJSON(json: any): Promise<void>;
|
|
138
|
+
}
|
|
139
|
+
interface Extension {
|
|
140
|
+
id: string;
|
|
141
|
+
metadata?: Partial<ExtensionMetadata>;
|
|
142
|
+
activate(context: ExtensionContext): void;
|
|
143
|
+
deactivate(context: ExtensionContext): void;
|
|
144
|
+
contribute?(): Record<string, any[]>;
|
|
145
|
+
}
|
|
146
|
+
declare class ExtensionRegistry extends Map<string, Extension> {
|
|
147
|
+
}
|
|
148
|
+
declare class ExtensionManager {
|
|
149
|
+
private readonly context;
|
|
150
|
+
private extensionRegistry;
|
|
151
|
+
private extensionDisposables;
|
|
152
|
+
constructor(context: ExtensionContext);
|
|
153
|
+
register(extension: Extension): void;
|
|
154
|
+
collectContribution(pointId: string, item: any): Disposable | undefined;
|
|
155
|
+
unregister(name: string): true | undefined;
|
|
156
|
+
enable(name: string): void;
|
|
157
|
+
disable(name: string): void;
|
|
158
|
+
update(): void;
|
|
112
159
|
destroy(): void;
|
|
113
160
|
}
|
|
114
161
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
162
|
+
interface CommandArgSchema {
|
|
163
|
+
}
|
|
164
|
+
interface Command {
|
|
165
|
+
id: string;
|
|
166
|
+
handler: (...args: any[]) => any;
|
|
167
|
+
title?: string;
|
|
168
|
+
category?: string;
|
|
169
|
+
description?: string;
|
|
170
|
+
schema?: Record<string, CommandArgSchema>;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
declare class CommandService implements Service {
|
|
174
|
+
private commands;
|
|
175
|
+
/**
|
|
176
|
+
* Register a command
|
|
177
|
+
* @param commandId Command Name (ID)
|
|
178
|
+
* @param handler Command handler function
|
|
179
|
+
* @param thisArg The `this` context for the handler
|
|
180
|
+
* @returns Disposable to unregister the command
|
|
181
|
+
*/
|
|
182
|
+
registerCommand(commandId: string, handler: (...args: any[]) => any, thisArg?: any): Disposable;
|
|
183
|
+
/**
|
|
184
|
+
* Execute a command
|
|
185
|
+
* @param commandId Command Name (ID)
|
|
186
|
+
* @param args Arguments to pass to the handler
|
|
187
|
+
* @returns The result of the command handler
|
|
188
|
+
*/
|
|
189
|
+
executeCommand<T = any>(commandId: string, ...args: any[]): Promise<T>;
|
|
190
|
+
/**
|
|
191
|
+
* Get all registered commands
|
|
192
|
+
*/
|
|
193
|
+
getCommands(): Map<string, Command>;
|
|
194
|
+
/**
|
|
195
|
+
* Get a specific command
|
|
196
|
+
*/
|
|
197
|
+
getCommand(commandId: string): Command | undefined;
|
|
198
|
+
dispose(): void;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
declare class ConfigurationService implements Service {
|
|
202
|
+
private configValues;
|
|
120
203
|
private eventBus;
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
off(event: string, handler: EventHandler): void;
|
|
140
|
-
emit(event: string, ...args: any[]): void;
|
|
141
|
-
getObjects(): FabricObject[];
|
|
142
|
-
getObject(id: string, layerId?: string): FabricObject | undefined;
|
|
143
|
-
getLayers(): Group[];
|
|
144
|
-
getLayer(id: string): Group | undefined;
|
|
145
|
-
updateState(updater: (state: EditorState) => EditorState): void;
|
|
146
|
-
toJSON(): {
|
|
147
|
-
width: number;
|
|
148
|
-
height: number;
|
|
149
|
-
metadata: Record<string, any> | undefined;
|
|
150
|
-
extensions: Record<string, any>;
|
|
204
|
+
/**
|
|
205
|
+
* Get a configuration value.
|
|
206
|
+
*/
|
|
207
|
+
get<T = any>(key: string, defaultValue?: T): T;
|
|
208
|
+
/**
|
|
209
|
+
* Update a configuration value.
|
|
210
|
+
* Emits 'change' event.
|
|
211
|
+
*/
|
|
212
|
+
update(key: string, value: any): void;
|
|
213
|
+
/**
|
|
214
|
+
* Listen for changes to a specific configuration key.
|
|
215
|
+
*/
|
|
216
|
+
onDidChange(key: string, callback: (event: {
|
|
217
|
+
key: string;
|
|
218
|
+
value: any;
|
|
219
|
+
oldValue: any;
|
|
220
|
+
}) => void): {
|
|
221
|
+
dispose: () => void;
|
|
151
222
|
};
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
223
|
+
/**
|
|
224
|
+
* Listen for any configuration change.
|
|
225
|
+
*/
|
|
226
|
+
onAnyChange(callback: (event: {
|
|
227
|
+
key: string;
|
|
228
|
+
value: any;
|
|
229
|
+
oldValue: any;
|
|
230
|
+
}) => void): {
|
|
231
|
+
dispose: () => void;
|
|
232
|
+
};
|
|
233
|
+
/**
|
|
234
|
+
* Export current configuration state as a JSON-serializable object.
|
|
235
|
+
* Useful for saving configuration templates.
|
|
236
|
+
*/
|
|
237
|
+
export(): Record<string, any>;
|
|
238
|
+
/**
|
|
239
|
+
* Import configuration from a JSON object.
|
|
240
|
+
* This will merge the provided configuration with the current state,
|
|
241
|
+
* overwriting existing keys and triggering change events.
|
|
242
|
+
*/
|
|
243
|
+
import(data: Record<string, any>): void;
|
|
244
|
+
/**
|
|
245
|
+
* Initialize configuration with defaults from contributions.
|
|
246
|
+
* This should be called when a contribution is registered.
|
|
247
|
+
*/
|
|
248
|
+
initializeDefaults(contributions: ConfigurationContribution[]): void;
|
|
249
|
+
dispose(): void;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
declare class Pooder {
|
|
253
|
+
readonly eventBus: EventBus;
|
|
254
|
+
private readonly services;
|
|
255
|
+
private readonly contributions;
|
|
256
|
+
readonly extensionManager: ExtensionManager;
|
|
257
|
+
constructor();
|
|
258
|
+
private initDefaultContributionPoints;
|
|
259
|
+
registerService(service: Service, id?: string): boolean;
|
|
260
|
+
unregisterService(service: Service, id?: string): boolean;
|
|
261
|
+
getService<T extends Service>(id: string): T | undefined;
|
|
262
|
+
registerContributionPoint<T>(point: ContributionPoint<T>): void;
|
|
263
|
+
registerContribution<T>(pointId: string, contribution: Contribution<T>): Disposable;
|
|
264
|
+
getContributions<T>(pointId: string): Contribution<T>[];
|
|
156
265
|
}
|
|
157
266
|
|
|
158
|
-
export { type
|
|
267
|
+
export { type CommandContribution, CommandService, type ConfigurationContribution, ConfigurationService, type Contribution, type ContributionMetadata, type ContributionPoint, ContributionPointIds, ContributionRegistry, type Extension, type ExtensionContext, ExtensionManager, type ExtensionMetadata, ExtensionRegistry, Pooder, type Service, ServiceRegistry, type ToolContribution, type ViewContribution };
|