@pooder/core 0.0.2 → 1.0.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,7 +1,19 @@
1
- # @pooder/core
2
-
3
- ## 0.0.2
4
-
5
- ### Patch Changes
6
-
7
- - changeset release
1
+ # @pooder/core
2
+
3
+ ## 1.0.0
4
+
5
+ ### Major Changes
6
+
7
+ - Architecture upgrade
8
+
9
+ ## 0.1.0
10
+
11
+ ### Minor Changes
12
+
13
+ - update
14
+
15
+ ## 0.0.2
16
+
17
+ ### Patch Changes
18
+
19
+ - changeset release
package/dist/index.d.mts CHANGED
@@ -1,155 +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 } 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[]): boolean;
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
- commands?: Record<string, Command>;
79
- }
80
- interface EditorState {
81
- width: number;
82
- height: number;
83
- metadata?: Record<string, any>;
84
- }
85
- interface Editor {
86
- state: EditorState;
87
- canvas: Canvas;
88
- extensions: ExtensionMap;
89
- commands: CommandMap;
90
- use(extension: Extension): void;
91
- unuse(name: string): void;
92
- getExtension(name: string): Extension | undefined;
93
- getExtensions(): Extension[];
94
- enableExtension(name: string): void;
95
- disableExtension(name: string): void;
96
- registerCommand(name: string, command: Command): void;
97
- unregisterCommand(name: string): void;
98
- executeCommand(name: string, ...args: any[]): void;
99
- on(event: string, handler: EventHandler, priority?: number): void;
100
- off(event: string, handler: EventHandler): void;
101
- emit(event: string, ...args: any[]): void;
102
- getObjects(): FabricObject[];
103
- getObject(id: string, layerId?: string): FabricObject | undefined;
104
- getLayers(): Group[];
105
- getLayer(id: string): Group | undefined;
106
- updateState(updater: (state: EditorState) => EditorState): void;
107
- getState(): EditorState;
108
- toJSON(): any;
109
- 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;
110
159
  destroy(): void;
111
160
  }
112
161
 
113
- declare class PooderEditor implements Editor {
114
- state: EditorState;
115
- canvas: Canvas;
116
- extensions: ExtensionMap;
117
- 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;
118
203
  private eventBus;
119
- private commandManager;
120
- private extensionManager;
121
- private destroyed;
122
- constructor(el: HTMLCanvasElement, options?: {
123
- width?: number;
124
- height?: number;
125
- extensions?: Extension[];
126
- });
127
- use(extension: Extension): void;
128
- unuse(name: string): void;
129
- getExtension(name: string): Extension | undefined;
130
- getExtensions(): Extension[];
131
- enableExtension(name: string): void;
132
- disableExtension(name: string): void;
133
- registerCommand(name: string, command: Command): void;
134
- unregisterCommand(name: string): void;
135
- executeCommand(name: string, ...args: any[]): boolean;
136
- on(event: string, handler: EventHandler, priority?: number): void;
137
- off(event: string, handler: EventHandler): void;
138
- emit(event: string, ...args: any[]): void;
139
- getObjects(): FabricObject[];
140
- getObject(id: string, layerId?: string): FabricObject | undefined;
141
- getLayers(): Group[];
142
- getLayer(id: string): Group | undefined;
143
- updateState(updater: (state: EditorState) => EditorState): void;
144
- toJSON(): {
145
- width: number;
146
- height: number;
147
- metadata: Record<string, any> | undefined;
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;
148
222
  };
149
- loadFromJSON(json: any): Promise<void>;
150
- getState(): EditorState;
151
- destroy(): void;
152
- 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): boolean;
260
+ unregisterService(service: Service): 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>[];
153
265
  }
154
266
 
155
- 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 };