@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 CHANGED
@@ -1,5 +1,17 @@
1
1
  # @pooder/core
2
2
 
3
+ ## 1.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - bugfix
8
+
9
+ ## 1.0.0
10
+
11
+ ### Major Changes
12
+
13
+ - Architecture upgrade
14
+
3
15
  ## 0.1.0
4
16
 
5
17
  ### Minor Changes
package/dist/index.d.mts CHANGED
@@ -1,158 +1,267 @@
1
- import { Canvas, FabricObject, Group } from 'fabric';
2
- export { Circle, Ellipse, Group, FabricImage as Image, Line, Path, Pattern, Point, Canvas as PooderCanvas, Group as PooderLayer, FabricObject as PooderObject, Rect, Text, filters, util } from 'fabric';
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
- declare class ExtensionMap extends Map<string, Extension> {
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
- declare class CommandMap extends Map<string, Command> {
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 CommandArgSchema {
29
- type: "string" | "number" | "boolean" | "object" | "any";
30
- label?: string;
23
+ interface ContributionPoint<T = any> {
24
+ id: string;
31
25
  description?: string;
32
- required?: boolean;
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
- options?: string[] | {
35
- label: string;
36
- value: any;
37
- }[];
67
+ description?: string;
68
+ options?: string[];
38
69
  min?: number;
39
70
  max?: number;
71
+ step?: number;
40
72
  }
41
- interface CommandSchema {
42
- [argName: string]: CommandArgSchema;
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
- interface Command {
45
- execute(...args: any[]): any;
46
- schema?: CommandSchema;
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
- interface Event {
114
+
115
+ interface ContributionMetadata {
49
116
  name: string;
50
- data: any;
117
+ extensionId: string;
51
118
  }
52
- type EventHandler = (...args: any[]) => void | boolean;
53
- interface ExtensionOptions {
54
- [key: string]: any;
119
+ interface Contribution<T = any> {
120
+ id: string;
121
+ data: T;
122
+ metadata?: Partial<ContributionMetadata>;
55
123
  }
56
- interface OptionSchema {
57
- type: "string" | "number" | "boolean" | "color" | "select";
58
- options?: string[] | {
59
- label: string;
60
- value: any;
61
- }[];
62
- min?: number;
63
- max?: number;
64
- step?: number;
65
- label?: string;
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
- interface Extension<T extends ExtensionOptions = ExtensionOptions> {
135
+
136
+ interface ExtensionMetadata {
68
137
  name: string;
69
- priority?: number;
70
- options?: T;
71
- schema?: Record<keyof T, OptionSchema>;
72
- enabled?: boolean;
73
- onCreate?(editor: Editor): void;
74
- onMount?(editor: Editor): void;
75
- onUpdate?(editor: Editor, state: EditorState): void;
76
- onUnmount?(editor: Editor): void;
77
- onDestroy?(editor: Editor): void;
78
- toJSON?(): any;
79
- loadFromJSON?(data: any): void | Promise<void>;
80
- commands?: Record<string, Command>;
81
- }
82
- interface EditorState {
83
- width: number;
84
- height: number;
85
- metadata?: Record<string, any>;
86
- }
87
- interface Editor {
88
- state: EditorState;
89
- canvas: Canvas;
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
- declare class PooderEditor implements Editor {
116
- state: EditorState;
117
- canvas: Canvas;
118
- extensions: ExtensionMap;
119
- commands: CommandMap;
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
- private commandManager;
122
- private extensionManager;
123
- private destroyed;
124
- constructor(el: HTMLCanvasElement, options?: {
125
- width?: number;
126
- height?: number;
127
- extensions?: Extension[];
128
- });
129
- use(extension: Extension): void;
130
- unuse(name: string): void;
131
- getExtension(name: string): Extension | undefined;
132
- getExtensions(): Extension[];
133
- enableExtension(name: string): void;
134
- disableExtension(name: string): void;
135
- registerCommand(name: string, command: Command): void;
136
- unregisterCommand(name: string): void;
137
- executeCommand(name: string, ...args: any[]): any;
138
- on(event: string, handler: EventHandler, priority?: number): void;
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
- loadFromJSON(json: any): Promise<void>;
153
- getState(): EditorState;
154
- destroy(): void;
155
- isDestroyed(): boolean;
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 Command, type Editor, type EditorState, type Event, type EventHandler, type Extension, type ExtensionOptions, type OptionSchema, PooderEditor };
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 };