@weave-apps/sdk 0.1.18 → 0.1.19

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.
@@ -1,177 +0,0 @@
1
- /**
2
- * Sidekick Base App
3
- *
4
- * Base class for all Sidekick apps. Provides common functionality and lifecycle methods.
5
- * Third-party developers should extend this class instead of HTMLElement directly.
6
- *
7
- * @example
8
- * ```typescript
9
- * // Define your settings and state types
10
- * interface MyAppSettings {
11
- * apiKey: string;
12
- * endpoint: string;
13
- * autoSave?: boolean;
14
- * }
15
- *
16
- * interface MyAppState {
17
- * count: number;
18
- * isLoading: boolean;
19
- * data: any[];
20
- * }
21
- *
22
- * class MyApp extends SidekickBaseApp<MyAppSettings, MyAppState> {
23
- * constructor() {
24
- * super({
25
- * id: 'my-app',
26
- * name: 'My App',
27
- * version: '1.0.0',
28
- * category: 'utility',
29
- * description: 'My custom app',
30
- * author: 'Your Name',
31
- * tags: ['custom']
32
- * });
33
- *
34
- * // Settings are now type-safe!
35
- * const apiKey = this.appSettings?.apiKey; // ✅ TypeScript knows this exists
36
- *
37
- * // Initialize state with proper typing
38
- * this.state = {
39
- * count: 0,
40
- * isLoading: false,
41
- * data: []
42
- * };
43
- * }
44
- *
45
- * render() {
46
- * return `<div>My App Content</div>`;
47
- * }
48
- *
49
- * setupEventListeners() {
50
- * // setState is also type-safe
51
- * this.setState({ count: this.state.count + 1 }); // ✅ Type-safe
52
- * }
53
- * }
54
- *
55
- * customElements.define('my-app', MyApp);
56
- * ```
57
- */
58
- /**
59
- * App metadata configuration
60
- */
61
- export interface SidekickAppInfo {
62
- /** Unique identifier for the app (kebab-case recommended) */
63
- id: string;
64
- /** Display name of the app */
65
- name: string;
66
- /** Semantic version (x.y.z) */
67
- version: string;
68
- /** Primary category for the app */
69
- category: string;
70
- /** Detailed description of the app */
71
- description: string;
72
- /** Author or organization name */
73
- author: string;
74
- /** Additional tags for search and categorization */
75
- tags?: string[];
76
- }
77
- /**
78
- * Base class for Sidekick apps
79
- * @template TSettings - Type for app settings, defaults to an empty object
80
- * @template TState - Type for app state, defaults to an empty object
81
- */
82
- export declare abstract class SidekickBaseApp<TSettings = Record<string, any>, TState = Record<string, any>> extends HTMLElement {
83
- /** App metadata */
84
- protected appInfo: SidekickAppInfo;
85
- /** App settings (override in subclass) **/
86
- protected appSettings?: TSettings;
87
- /** App-specific state (override in subclass) */
88
- protected state: TState;
89
- /** Shadow root for style isolation */
90
- private _shadowRoot;
91
- /** App-specific API client instance (prevents app ID conflicts) */
92
- protected sidekickAPI: any;
93
- /**
94
- * Creates a new Sidekick app
95
- * @param appInfo - App metadata configuration
96
- */
97
- constructor(appInfo: SidekickAppInfo);
98
- /**
99
- * Get shadow root (override native property)
100
- */
101
- get shadowRoot(): ShadowRoot;
102
- /**
103
- * Background service - optional override in subclass
104
- * Called immediately after app instantiation, before DOM attachment
105
- * Use this for background tasks like URL monitoring, event listening, etc.
106
- */
107
- protected onBackgroundService?(): void;
108
- /**
109
- * URL change handler - optional override in subclass
110
- * Called when the page URL changes (SPA navigation)
111
- * @param url - The new URL
112
- */
113
- protected onUrlChange?(url: string): void;
114
- /**
115
- * Render method - must be implemented by subclass
116
- * Should return HTML string or directly manipulate shadowRoot
117
- */
118
- protected render(): void;
119
- /**
120
- * Setup event listeners - optional override in subclass
121
- */
122
- protected setupEventListeners(): void;
123
- /**
124
- * Initialize background service
125
- * Called by BackgroundAppManager after instantiation
126
- */
127
- initializeBackgroundService(): void;
128
- /**
129
- * Handle URL change
130
- * Called by BackgroundAppManager when URL changes
131
- */
132
- handleUrlChange(url: string): void;
133
- /**
134
- * Lifecycle: Called when element is added to DOM
135
- * This happens when user opens the app in the drawer
136
- */
137
- connectedCallback(): void;
138
- /**
139
- * Lifecycle: Called when element is removed from DOM
140
- */
141
- disconnectedCallback(): void;
142
- /**
143
- * Cleanup method - optional override in subclass
144
- * Called when app is disconnected from DOM
145
- */
146
- protected cleanup(): void;
147
- /**
148
- * Get app configuration (for Sidekick Platform)
149
- */
150
- getAppInfo(): SidekickAppInfo;
151
- /**
152
- * Get current app state (for Sidekick Platform)
153
- */
154
- getAppState(): Record<string, any>;
155
- /**
156
- * Set app configuration (for Sidekick Platform)
157
- * Override this method to handle configuration updates
158
- */
159
- setAppConfig(_config: Record<string, any>): void;
160
- /**
161
- * Helper: Update app state
162
- */
163
- protected setState(updates: Partial<TState>): void;
164
- /**
165
- * Helper: Render HTML into shadow root
166
- */
167
- protected renderHTML(html: string): void;
168
- /**
169
- * Helper: Query element in shadow root
170
- */
171
- protected query<T extends Element = Element>(selector: string): T | null;
172
- /**
173
- * Helper: Query all elements in shadow root
174
- */
175
- protected queryAll<T extends Element = Element>(selector: string): NodeListOf<T>;
176
- }
177
- //# sourceMappingURL=SidekickBaseApp.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"SidekickBaseApp.d.ts","sourceRoot":"","sources":["../src/SidekickBaseApp.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwDG;AAEH;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,6DAA6D;IAC7D,EAAE,EAAE,MAAM,CAAC;IACX,8BAA8B;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,+BAA+B;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,mCAAmC;IACnC,QAAQ,EAAE,MAAM,CAAC;IACjB,sCAAsC;IACtC,WAAW,EAAE,MAAM,CAAC;IACpB,kCAAkC;IAClC,MAAM,EAAE,MAAM,CAAC;IACf,oDAAoD;IACpD,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;CACjB;AAED;;;;GAIG;AACH,8BAAsB,eAAe,CACnC,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAC/B,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAC5B,SAAQ,WAAW;IACnB,mBAAmB;IACnB,SAAS,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CAAC,SAAS,OAAO,GAAG,OAAO,EAAE,QAAQ,EAAE,MAAM,GAAG,CAAC,GAAG,IAAI;IAIxE;;OAEG;IACH,SAAS,CAAC,QAAQ,CAAC,CAAC,SAAS,OAAO,GAAG,OAAO,EAAE,QAAQ,EAAE,MAAM,GAAG,UAAU,CAAC,CAAC,CAAC;CAGjF"}
@@ -1,228 +0,0 @@
1
- /**
2
- * Sidekick Base App
3
- *
4
- * Base class for all Sidekick apps. Provides common functionality and lifecycle methods.
5
- * Third-party developers should extend this class instead of HTMLElement directly.
6
- *
7
- * @example
8
- * ```typescript
9
- * // Define your settings and state types
10
- * interface MyAppSettings {
11
- * apiKey: string;
12
- * endpoint: string;
13
- * autoSave?: boolean;
14
- * }
15
- *
16
- * interface MyAppState {
17
- * count: number;
18
- * isLoading: boolean;
19
- * data: any[];
20
- * }
21
- *
22
- * class MyApp extends SidekickBaseApp<MyAppSettings, MyAppState> {
23
- * constructor() {
24
- * super({
25
- * id: 'my-app',
26
- * name: 'My App',
27
- * version: '1.0.0',
28
- * category: 'utility',
29
- * description: 'My custom app',
30
- * author: 'Your Name',
31
- * tags: ['custom']
32
- * });
33
- *
34
- * // Settings are now type-safe!
35
- * const apiKey = this.appSettings?.apiKey; // ✅ TypeScript knows this exists
36
- *
37
- * // Initialize state with proper typing
38
- * this.state = {
39
- * count: 0,
40
- * isLoading: false,
41
- * data: []
42
- * };
43
- * }
44
- *
45
- * render() {
46
- * return `<div>My App Content</div>`;
47
- * }
48
- *
49
- * setupEventListeners() {
50
- * // setState is also type-safe
51
- * this.setState({ count: this.state.count + 1 }); // ✅ Type-safe
52
- * }
53
- * }
54
- *
55
- * customElements.define('my-app', MyApp);
56
- * ```
57
- */
58
- /**
59
- * Base class for Sidekick apps
60
- * @template TSettings - Type for app settings, defaults to an empty object
61
- * @template TState - Type for app state, defaults to an empty object
62
- */
63
- export class SidekickBaseApp extends HTMLElement {
64
- /**
65
- * Creates a new Sidekick app
66
- * @param appInfo - App metadata configuration
67
- */
68
- constructor(appInfo) {
69
- super();
70
- /** App-specific state (override in subclass) */
71
- this.state = {};
72
- // Validate required fields
73
- if (!appInfo.id || !appInfo.name || !appInfo.version) {
74
- throw new Error('SidekickBaseApp: id, name, and version are required');
75
- }
76
- this.appInfo = appInfo;
77
- // Create shadow DOM for style isolation and store reference
78
- this._shadowRoot = this.attachShadow({ mode: 'open' });
79
- // Read UUID and settings from global registry (set by BackgroundAppManager before element creation)
80
- // This allows the constructor to access both UUID and settings immediately
81
- const registry = window.__sidekickAppRegistry;
82
- const tagName = this.tagName.toLowerCase();
83
- const registryData = registry?.[tagName];
84
- // Set app settings if available in registry
85
- if (registryData?.settings) {
86
- this.appSettings = registryData.settings;
87
- }
88
- // Set app UUID on the global API client so it's included in all requests
89
- // This allows background services to make API calls without the app being open
90
- if (window.sidekickAPI) {
91
- const appUuid = registryData?.uuid;
92
- if (appUuid) {
93
- // Create a new API client instance for THIS app
94
- this.sidekickAPI = new window.SidekickAPIClient();
95
- this.sidekickAPI.setAppId(appUuid);
96
- }
97
- else {
98
- console.warn('⚠️ App UUID not found in registry - API calls may fail. App:', appInfo.id);
99
- // Fallback to global API client (will have wrong app ID, but better than nothing)
100
- this.sidekickAPI = window.sidekickAPI;
101
- }
102
- }
103
- }
104
- /**
105
- * Get shadow root (override native property)
106
- */
107
- get shadowRoot() {
108
- return this._shadowRoot;
109
- }
110
- /**
111
- * Render method - must be implemented by subclass
112
- * Should return HTML string or directly manipulate shadowRoot
113
- */
114
- render() {
115
- // Default implementation - subclasses should override
116
- }
117
- /**
118
- * Setup event listeners - optional override in subclass
119
- */
120
- setupEventListeners() {
121
- // Default implementation - subclasses can override
122
- }
123
- /**
124
- * Initialize background service
125
- * Called by BackgroundAppManager after instantiation
126
- */
127
- initializeBackgroundService() {
128
- if (this.onBackgroundService) {
129
- this.onBackgroundService();
130
- }
131
- }
132
- /**
133
- * Handle URL change
134
- * Called by BackgroundAppManager when URL changes
135
- */
136
- handleUrlChange(url) {
137
- if (this.onUrlChange) {
138
- this.onUrlChange(url);
139
- }
140
- }
141
- /**
142
- * Lifecycle: Called when element is added to DOM
143
- * This happens when user opens the app in the drawer
144
- */
145
- connectedCallback() {
146
- // Render the app UI
147
- this.render();
148
- // Setup event listeners for UI
149
- this.setupEventListeners();
150
- // Notify Sidekick Platform that app UI is ready
151
- this.dispatchEvent(new CustomEvent('sidekick-app-ready', {
152
- detail: {
153
- appInfo: this.appInfo,
154
- timestamp: new Date().toISOString()
155
- },
156
- bubbles: true,
157
- composed: true
158
- }));
159
- }
160
- /**
161
- * Lifecycle: Called when element is removed from DOM
162
- */
163
- disconnectedCallback() {
164
- this.cleanup();
165
- }
166
- /**
167
- * Cleanup method - optional override in subclass
168
- * Called when app is disconnected from DOM
169
- */
170
- cleanup() {
171
- // Default implementation - subclasses can override
172
- }
173
- /**
174
- * Get app configuration (for Sidekick Platform)
175
- */
176
- getAppInfo() {
177
- return this.appInfo;
178
- }
179
- /**
180
- * Get current app state (for Sidekick Platform)
181
- */
182
- getAppState() {
183
- return {
184
- ...this.state,
185
- lastUpdated: new Date().toISOString()
186
- };
187
- }
188
- /**
189
- * Set app configuration (for Sidekick Platform)
190
- * Override this method to handle configuration updates
191
- */
192
- setAppConfig(_config) {
193
- // Default implementation - subclasses can override
194
- }
195
- /**
196
- * Helper: Update app state
197
- */
198
- setState(updates) {
199
- this.state = { ...this.state, ...updates };
200
- }
201
- /**
202
- * Helper: Render HTML into shadow root
203
- */
204
- renderHTML(html) {
205
- if (this._shadowRoot) {
206
- this._shadowRoot.innerHTML = html;
207
- }
208
- else {
209
- console.error('❌ No shadow root available!');
210
- }
211
- }
212
- /**
213
- * Helper: Query element in shadow root
214
- */
215
- query(selector) {
216
- return this._shadowRoot?.querySelector(selector) || null;
217
- }
218
- /**
219
- * Helper: Query all elements in shadow root
220
- */
221
- queryAll(selector) {
222
- return this._shadowRoot?.querySelectorAll(selector) || [];
223
- }
224
- }
225
- // Export for global usage
226
- if (typeof window !== 'undefined') {
227
- window.SidekickBaseApp = SidekickBaseApp;
228
- }