@weave-apps/sdk 0.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.
@@ -0,0 +1,231 @@
1
+ /**
2
+ * Weave API Client
3
+ *
4
+ * Client-side API for iframe apps to interact with the Weave backend
5
+ * through a secure proxy in the sidebar.
6
+ *
7
+ * Apps can call AI services and manage their own app data.
8
+ */
9
+ /**
10
+ * AI Chat Request
11
+ */
12
+ export interface AIChatRequest {
13
+ /** User's input prompt */
14
+ prompt: string;
15
+ /** Optional context for the AI */
16
+ context?: string;
17
+ /** Optional flag to disable JSON extraction */
18
+ disableJsonExtraction?: boolean;
19
+ }
20
+ /**
21
+ * AI Chat Response
22
+ */
23
+ export interface AIChatResponse {
24
+ /** AI chat response content */
25
+ response: string;
26
+ }
27
+ /**
28
+ * App Data structure
29
+ */
30
+ export interface AppData {
31
+ _id: string;
32
+ /** Reference to the app component this data belongs to */
33
+ appId: string;
34
+ /** Company that owns this app data */
35
+ companyId: string;
36
+ /** User that owns this specific app data instance */
37
+ userId: string;
38
+ /** Key for organizing data within an app namespace */
39
+ dataKey: string;
40
+ /** Unstructured data - apps determine the content structure */
41
+ data: Record<string, any>;
42
+ createdAt: Date;
43
+ updatedAt: Date;
44
+ createdBy: string;
45
+ }
46
+ /**
47
+ * Create App Data Request
48
+ */
49
+ export interface CreateAppDataRequest {
50
+ /** Key for organizing data within an app namespace */
51
+ dataKey: string;
52
+ /** Unstructured data - apps determine the content structure */
53
+ data: Record<string, any>;
54
+ }
55
+ /**
56
+ * Update App Data Request
57
+ */
58
+ export interface UpdateAppDataRequest {
59
+ /** Key for organizing data within an app namespace */
60
+ dataKey: string;
61
+ /** Unstructured data - apps determine the content structure */
62
+ data: Record<string, any>;
63
+ }
64
+ /**
65
+ * Pagination metadata
66
+ */
67
+ export interface PaginationMeta {
68
+ /** Current offset */
69
+ offset: number;
70
+ /** Number of items per page */
71
+ limit: number;
72
+ /** Total number of items available */
73
+ totalResultCount: number;
74
+ }
75
+ /**
76
+ * Paginated response wrapper
77
+ */
78
+ export interface PaginatedResponse<T> {
79
+ /** Array of data items */
80
+ data: T[];
81
+ /** Pagination metadata */
82
+ meta: PaginationMeta;
83
+ }
84
+ /**
85
+ * Weave API Client
86
+ * Provides methods for iframe apps to interact with Weave backend
87
+ */
88
+ export declare class WeaveAPIClient {
89
+ private pendingRequests;
90
+ private messageListener;
91
+ private requestCounter;
92
+ private timeout;
93
+ private appId;
94
+ constructor();
95
+ /**
96
+ * Set the app ID for this client
97
+ * Called automatically by WeaveBaseApp
98
+ */
99
+ setAppId(appId: string): void;
100
+ /**
101
+ * Initialize the API client and start listening for responses
102
+ */
103
+ private initialize;
104
+ /**
105
+ * Cleanup
106
+ */
107
+ destroy(): void;
108
+ /**
109
+ * Handle response from sidebar
110
+ */
111
+ private handleResponse;
112
+ /**
113
+ * Send request to sidebar
114
+ */
115
+ private sendRequest;
116
+ /**
117
+ * Send a chat message to the AI service
118
+ *
119
+ * Note: App ID is automatically injected by the APIBridge.
120
+ * You only need to provide the prompt and optional context.
121
+ *
122
+ * @example
123
+ * ```javascript
124
+ * const response = await weaveAPI.ai.chat({
125
+ * prompt: 'What is the capital of France?',
126
+ * context: 'User is learning geography'
127
+ * });
128
+ * ```
129
+ */
130
+ ai: {
131
+ chat: (request: AIChatRequest) => Promise<AIChatResponse>;
132
+ };
133
+ /**
134
+ * App Data operations - CRUD for app-specific data storage
135
+ */
136
+ appData: {
137
+ /**
138
+ * Get all app data for the current company (paginated)
139
+ *
140
+ * Returns a paginated response with data and metadata.
141
+ * Default limit is 25 items. For apps with large datasets (500-5000+ rows),
142
+ * use pagination to avoid performance issues.
143
+ *
144
+ * @example
145
+ * ```javascript
146
+ * // Get first page (default: 25 items)
147
+ * const response = await weaveAPI.appData.getAll();
148
+ *
149
+ * // Access the array of items
150
+ * const items = response.data;
151
+ * items.forEach(item => {
152
+ * });
153
+ * ```
154
+ */
155
+ getAll: () => Promise<PaginatedResponse<AppData>>;
156
+ /**
157
+ * Create new app data
158
+ *
159
+ * Note: App ID is automatically injected by the APIBridge.
160
+ *
161
+ * @example
162
+ * ```javascript
163
+ * const newData = await weaveAPI.appData.create({
164
+ * dataKey: 'user-preferences',
165
+ * data: { theme: 'dark', language: 'en' }
166
+ * });
167
+ * ```
168
+ */
169
+ create: (request: CreateAppDataRequest) => Promise<AppData>;
170
+ /**
171
+ * Get specific app data by ID
172
+ *
173
+ * @example
174
+ * ```javascript
175
+ * const data = await weaveAPI.appData.get('data-id-123');
176
+ * ```
177
+ */
178
+ get: (appDataId: string) => Promise<AppData>;
179
+ /**
180
+ * Update existing app data
181
+ *
182
+ * @example
183
+ * ```javascript
184
+ * const updated = await weaveAPI.appData.update('data-id-123', {
185
+ * data: { theme: 'light' }
186
+ * });
187
+ * ```
188
+ */
189
+ update: (appDataId: string, request: UpdateAppDataRequest) => Promise<AppData>;
190
+ /**
191
+ * Delete app data
192
+ *
193
+ * @example
194
+ * ```javascript
195
+ * await weaveAPI.appData.delete('data-id-123');
196
+ * ```
197
+ */
198
+ delete: (appDataId: string) => Promise<void>;
199
+ };
200
+ /**
201
+ * Utility functions for common operations
202
+ *
203
+ * Note: These utilities are loaded from the sidebar-loader at runtime.
204
+ * They are available through the window object and don't need to be bundled with apps.
205
+ */
206
+ utils: {
207
+ /**
208
+ * Convert HTML to Markdown
209
+ *
210
+ * @example
211
+ * ```javascript
212
+ * const markdown = weaveAPI.utils.htmlToMarkdown('<h1>Hello</h1>');
213
+ * console.log(markdown); // # Hello
214
+ * ```
215
+ */
216
+ htmlToMarkdown: (html: string) => string;
217
+ /**
218
+ * Convert Markdown to HTML (sanitized)
219
+ *
220
+ * @example
221
+ * ```javascript
222
+ * const html = weaveAPI.utils.markdownToHtml('# Hello');
223
+ * console.log(html); // <h1>Hello</h1>
224
+ * ```
225
+ */
226
+ markdownToHtml: (markdown: string) => string;
227
+ };
228
+ }
229
+ declare const weaveAPI: WeaveAPIClient;
230
+ export default weaveAPI;
231
+ //# sourceMappingURL=WeaveAPIClient.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"WeaveAPIClient.d.ts","sourceRoot":"","sources":["../src/WeaveAPIClient.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,0BAA0B;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,kCAAkC;IAClC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,+CAA+C;IAC/C,qBAAqB,CAAC,EAAE,OAAO,CAAC;CACjC;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,+BAA+B;IAC/B,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,OAAO;IACtB,GAAG,EAAE,MAAM,CAAC;IACZ,0DAA0D;IAC1D,KAAK,EAAE,MAAM,CAAC;IACd,sCAAsC;IACtC,SAAS,EAAE,MAAM,CAAC;IAClB,qDAAqD;IACrD,MAAM,EAAE,MAAM,CAAC;IACf,sDAAsD;IACtD,OAAO,EAAE,MAAM,CAAC;IAChB,+DAA+D;IAC/D,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC1B,SAAS,EAAE,IAAI,CAAC;IAChB,SAAS,EAAE,IAAI,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,sDAAsD;IACtD,OAAO,EAAE,MAAM,CAAC;IAChB,+DAA+D;IAC/D,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAC3B;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,sDAAsD;IACtD,OAAO,EAAE,MAAM,CAAC;IAChB,+DAA+D;IAC/D,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAC3B;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,qBAAq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,MAAM;QAQtC;;;;;;;;WAQG;mCACwB,MAAM,KAAG,MAAM;MAO1C;CACH;AAGD,QAAA,MAAM,QAAQ,gBAAuB,CAAC;AAOtC,eAAe,QAAQ,CAAC"}
@@ -0,0 +1,274 @@
1
+ /**
2
+ * Weave API Client
3
+ *
4
+ * Client-side API for iframe apps to interact with the Weave backend
5
+ * through a secure proxy in the sidebar.
6
+ *
7
+ * Apps can call AI services and manage their own app data.
8
+ */
9
+ /**
10
+ * API operation types
11
+ */
12
+ var APIOperation;
13
+ (function (APIOperation) {
14
+ // AI Service
15
+ APIOperation["AI_CHAT"] = "AI_CHAT";
16
+ // App Data Service
17
+ APIOperation["APP_DATA_GET_ALL"] = "APP_DATA_GET_ALL";
18
+ APIOperation["APP_DATA_CREATE"] = "APP_DATA_CREATE";
19
+ APIOperation["APP_DATA_GET"] = "APP_DATA_GET";
20
+ APIOperation["APP_DATA_UPDATE"] = "APP_DATA_UPDATE";
21
+ APIOperation["APP_DATA_DELETE"] = "APP_DATA_DELETE";
22
+ })(APIOperation || (APIOperation = {}));
23
+ /**
24
+ * Weave API Client
25
+ * Provides methods for iframe apps to interact with Weave backend
26
+ */
27
+ export class WeaveAPIClient {
28
+ constructor() {
29
+ this.pendingRequests = new Map();
30
+ this.messageListener = null;
31
+ this.requestCounter = 0;
32
+ this.timeout = 180000; // 3 minute timeout for API calls (AI can take time on large forms)
33
+ this.appId = null; // App ID set by the app
34
+ // ============================================================================
35
+ // AI Service
36
+ // ============================================================================
37
+ /**
38
+ * Send a chat message to the AI service
39
+ *
40
+ * Note: App ID is automatically injected by the APIBridge.
41
+ * You only need to provide the prompt and optional context.
42
+ *
43
+ * @example
44
+ * ```javascript
45
+ * const response = await weaveAPI.ai.chat({
46
+ * prompt: 'What is the capital of France?',
47
+ * context: 'User is learning geography'
48
+ * });
49
+ * ```
50
+ */
51
+ this.ai = {
52
+ chat: async (request) => {
53
+ return this.sendRequest(APIOperation.AI_CHAT, request);
54
+ }
55
+ };
56
+ // ============================================================================
57
+ // App Data Service
58
+ // ============================================================================
59
+ /**
60
+ * App Data operations - CRUD for app-specific data storage
61
+ */
62
+ this.appData = {
63
+ /**
64
+ * Get all app data for the current company (paginated)
65
+ *
66
+ * Returns a paginated response with data and metadata.
67
+ * Default limit is 25 items. For apps with large datasets (500-5000+ rows),
68
+ * use pagination to avoid performance issues.
69
+ *
70
+ * @example
71
+ * ```javascript
72
+ * // Get first page (default: 25 items)
73
+ * const response = await weaveAPI.appData.getAll();
74
+ *
75
+ * // Access the array of items
76
+ * const items = response.data;
77
+ * items.forEach(item => {
78
+ * });
79
+ * ```
80
+ */
81
+ getAll: async () => {
82
+ return this.sendRequest(APIOperation.APP_DATA_GET_ALL, {});
83
+ },
84
+ /**
85
+ * Create new app data
86
+ *
87
+ * Note: App ID is automatically injected by the APIBridge.
88
+ *
89
+ * @example
90
+ * ```javascript
91
+ * const newData = await weaveAPI.appData.create({
92
+ * dataKey: 'user-preferences',
93
+ * data: { theme: 'dark', language: 'en' }
94
+ * });
95
+ * ```
96
+ */
97
+ create: async (request) => {
98
+ return this.sendRequest(APIOperation.APP_DATA_CREATE, request);
99
+ },
100
+ /**
101
+ * Get specific app data by ID
102
+ *
103
+ * @example
104
+ * ```javascript
105
+ * const data = await weaveAPI.appData.get('data-id-123');
106
+ * ```
107
+ */
108
+ get: async (appDataId) => {
109
+ return this.sendRequest(APIOperation.APP_DATA_GET, { appDataId });
110
+ },
111
+ /**
112
+ * Update existing app data
113
+ *
114
+ * @example
115
+ * ```javascript
116
+ * const updated = await weaveAPI.appData.update('data-id-123', {
117
+ * data: { theme: 'light' }
118
+ * });
119
+ * ```
120
+ */
121
+ update: async (appDataId, request) => {
122
+ return this.sendRequest(APIOperation.APP_DATA_UPDATE, {
123
+ appDataId,
124
+ ...request
125
+ });
126
+ },
127
+ /**
128
+ * Delete app data
129
+ *
130
+ * @example
131
+ * ```javascript
132
+ * await weaveAPI.appData.delete('data-id-123');
133
+ * ```
134
+ */
135
+ delete: async (appDataId) => {
136
+ return this.sendRequest(APIOperation.APP_DATA_DELETE, { appDataId });
137
+ }
138
+ };
139
+ /**
140
+ * Utility functions for common operations
141
+ *
142
+ * Note: These utilities are loaded from the sidebar-loader at runtime.
143
+ * They are available through the window object and don't need to be bundled with apps.
144
+ */
145
+ this.utils = {
146
+ /**
147
+ * Convert HTML to Markdown
148
+ *
149
+ * @example
150
+ * ```javascript
151
+ * const markdown = weaveAPI.utils.htmlToMarkdown('<h1>Hello</h1>');
152
+ * console.log(markdown); // # Hello
153
+ * ```
154
+ */
155
+ htmlToMarkdown: (html) => {
156
+ // Access the utility from window object (loaded by sidebar-loader)
157
+ if (typeof window !== 'undefined' && window.__weaveUtils?.htmlToMarkdown) {
158
+ return window.__weaveUtils.htmlToMarkdown(html);
159
+ }
160
+ throw new Error('htmlToMarkdown utility not available. Ensure sidebar-loader is loaded.');
161
+ },
162
+ /**
163
+ * Convert Markdown to HTML (sanitized)
164
+ *
165
+ * @example
166
+ * ```javascript
167
+ * const html = weaveAPI.utils.markdownToHtml('# Hello');
168
+ * console.log(html); // <h1>Hello</h1>
169
+ * ```
170
+ */
171
+ markdownToHtml: (markdown) => {
172
+ // Access the utility from window object (loaded by sidebar-loader)
173
+ if (typeof window !== 'undefined' && window.__weaveUtils?.markdownToHtml) {
174
+ return window.__weaveUtils.markdownToHtml(markdown);
175
+ }
176
+ throw new Error('markdownToHtml utility not available. Ensure sidebar-loader is loaded.');
177
+ }
178
+ };
179
+ this.initialize();
180
+ }
181
+ /**
182
+ * Set the app ID for this client
183
+ * Called automatically by WeaveBaseApp
184
+ */
185
+ setAppId(appId) {
186
+ this.appId = appId;
187
+ }
188
+ /**
189
+ * Initialize the API client and start listening for responses
190
+ */
191
+ initialize() {
192
+ this.messageListener = (event) => {
193
+ this.handleResponse(event);
194
+ };
195
+ window.addEventListener('message', this.messageListener);
196
+ }
197
+ /**
198
+ * Cleanup
199
+ */
200
+ destroy() {
201
+ if (this.messageListener) {
202
+ window.removeEventListener('message', this.messageListener);
203
+ this.messageListener = null;
204
+ }
205
+ this.pendingRequests.clear();
206
+ }
207
+ /**
208
+ * Handle response from sidebar
209
+ */
210
+ handleResponse(event) {
211
+ const data = event.data;
212
+ if (data?.type !== 'WEAVE_API_RESPONSE') {
213
+ return;
214
+ }
215
+ const response = data;
216
+ const pending = this.pendingRequests.get(response.id);
217
+ if (!pending) {
218
+ return;
219
+ }
220
+ this.pendingRequests.delete(response.id);
221
+ if (response.success) {
222
+ pending.resolve(response.data);
223
+ }
224
+ else {
225
+ pending.reject(new Error(response.error || 'Unknown error'));
226
+ }
227
+ }
228
+ /**
229
+ * Send request to sidebar
230
+ */
231
+ sendRequest(operation, payload) {
232
+ return new Promise((resolve, reject) => {
233
+ const id = `api-request-${++this.requestCounter}`;
234
+ const request = {
235
+ type: 'WEAVE_API_REQUEST',
236
+ id,
237
+ operation,
238
+ payload,
239
+ appId: this.appId || undefined, // Include app ID if set
240
+ };
241
+ // Store pending request
242
+ this.pendingRequests.set(id, { resolve, reject });
243
+ // Set timeout
244
+ const timeoutId = setTimeout(() => {
245
+ this.pendingRequests.delete(id);
246
+ reject(new Error(`Request timeout: ${operation}`));
247
+ }, this.timeout);
248
+ // Clear timeout on resolve/reject
249
+ const originalResolve = resolve;
250
+ const originalReject = reject;
251
+ this.pendingRequests.set(id, {
252
+ resolve: (value) => {
253
+ clearTimeout(timeoutId);
254
+ originalResolve(value);
255
+ },
256
+ reject: (error) => {
257
+ clearTimeout(timeoutId);
258
+ originalReject(error);
259
+ },
260
+ });
261
+ // Send to current window (sidebar APIBridge will intercept)
262
+ // Apps run in the sidebar's window, not in a separate iframe
263
+ window.postMessage(request, '*');
264
+ APIOperation;
265
+ });
266
+ }
267
+ }
268
+ // Create singleton instance
269
+ const weaveAPI = new WeaveAPIClient();
270
+ // Export for global usage
271
+ if (typeof window !== 'undefined') {
272
+ window.weaveAPI = weaveAPI;
273
+ }
274
+ export default weaveAPI;
@@ -0,0 +1,177 @@
1
+ /**
2
+ * Weave Base App
3
+ *
4
+ * Base class for all Weave 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 WeaveBaseApp<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 WeaveAppInfo {
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 Weave 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 WeaveBaseApp<TSettings = Record<string, any>, TState = Record<string, any>> extends HTMLElement {
83
+ /** App metadata */
84
+ protected appInfo: WeaveAppInfo;
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 weaveAPI: any;
93
+ /**
94
+ * Creates a new Weave app
95
+ * @param appInfo - App metadata configuration
96
+ */
97
+ constructor(appInfo: WeaveAppInfo);
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 Weave Platform)
149
+ */
150
+ getAppInfo(): WeaveAppInfo;
151
+ /**
152
+ * Get current app state (for Weave Platform)
153
+ */
154
+ getAppState(): Record<string, any>;
155
+ /**
156
+ * Set app configuration (for Weave 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=WeaveBaseApp.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"WeaveBaseApp.d.ts","sourceRoot":"","sources":["../src/WeaveBaseApp.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwDG;AAEH;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,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,YAAY,CAChC,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAC/B,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,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