@canva/platform 2.2.0-beta.1 → 2.2.1-beta.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 ADDED
@@ -0,0 +1,5 @@
1
+ # CHANGELOG
2
+
3
+ ## 2.2.1-beta.0 - 2025-12-18
4
+
5
+ - Initial changelog for the Preview Platform SDK.
package/beta.d.ts CHANGED
@@ -3,181 +3,175 @@
3
3
  * Provides methods for interacting with an app process.
4
4
  */
5
5
  export declare interface AppProcess {
6
- /**
7
- * The current app process.
8
- */
9
- readonly current: CurrentAppProcess;
10
- /**
11
- * @public
12
- * Requests the termination of the specified app process.
13
- *
14
- * @param target - The ID of an app process.
15
- * @param params - Parameters to pass to the `setOnDispose` callback. Any kind of structured data can be passed via this property.
16
- *
17
- * @remarks
18
- * Once called, this method:
19
- *
20
- * 1. Transitions the state of the process to `"closing"`.
21
- * 2. Invokes all registered `setOnDispose` callbacks.
22
- * 3. Waits for the process to finish closing.
23
- * 4. Transitions the state of the process to `"closed"`.
24
- *
25
- * Each time the state changes, all of the `registerOnStateChange` callbacks are called.
26
- *
27
- * @example Close a process
28
- * ```typescript
29
- * import { appProcess, type AppProcessId } from '@canva/platform';
30
- *
31
- * const placeholderProcessId = "PLACEHOLDER_PROCESS_ID" as AppProcessId;
32
- *
33
- * await appProcess.requestClose(placeholderProcessId, { reason: 'completed' });
34
- * ```
35
- *
36
- * @example Pass structured data to a process as it closes
37
- * ```typescript
38
- * import { appProcess, type AppProcessId, type CloseParams } from '@canva/platform';
39
- *
40
- * type DetailedCloseParams = CloseParams & {
41
- * savePoint: string;
42
- * timestamp: number;
43
- * userInitiated: boolean;
44
- * };
45
- *
46
- * const placeholderProcessId = "PLACEHOLDER_PROCESS_ID" as AppProcessId;
47
- *
48
- * await appProcess.requestClose<DetailedCloseParams>(placeholderProcessId, {
49
- * reason: 'completed',
50
- * savePoint: 'auto_backup_1',
51
- * timestamp: Date.now(),
52
- * userInitiated: true
53
- * });
54
- * ```
55
- */
56
- requestClose<T extends CloseParams>(
57
- target: AppProcessId,
58
- params: T,
59
- ): Promise<void>;
60
- /**
61
- * @public
62
- * Registers a callback that runs when the state of the specified app process changes.
63
- *
64
- * @param target - The ID of an app process.
65
- * @param callback - The callback to run when the state of the process changes.
66
- *
67
- * @returns
68
- * A disposer function that cleans up the registered callback.
69
- *
70
- * @example Listen for process state changes
71
- * ```typescript
72
- * import { appProcess } from '@canva/platform';
73
- *
74
- * const stateDisposer = appProcess.registerOnStateChange(
75
- * processId,
76
- * ({ state }) => {
77
- * switch (state) {
78
- * case 'opening':
79
- * // Process is starting up
80
- * break;
81
- * case 'open':
82
- * // Process is active and visible
83
- * break;
84
- * case 'closing':
85
- * // Process is about to close
86
- * // Save state, cleanup resources
87
- * break;
88
- * case 'closed':
89
- * // Process has been terminated
90
- * // Final cleanup if needed
91
- * break;
92
- * }
93
- * }
94
- * );
95
- *
96
- * // Later: cleanup the listener
97
- * await stateDisposer();
98
- * ```
99
- */
100
- registerOnStateChange(
101
- target: AppProcessId,
102
- callback: OnStateChangeCallback,
103
- ): () => Promise<void>;
104
- /**
105
- * @public
106
- * Registers a callback that listens for broadcasted messages.
107
- *
108
- * @param callback - The callback that listens for broadcasted messages.
109
- *
110
- * @returns
111
- * A disposer function that cleans up the registered callback.
112
- *
113
- * @example Listen for inter-process messages
114
- * ```typescript
115
- * import { appProcess } from '@canva/platform';
116
- *
117
- * const messageDisposer = appProcess.registerOnMessage(async (sender, message) => {
118
- * const { appProcessId, surface } = sender;
119
- * // Handle message from other process
120
- * });
121
- *
122
- * // Later: cleanup the listener
123
- * await messageDisposer();
124
- * ```
125
- */
126
- registerOnMessage(callback: OnMessageCallback): () => Promise<void>;
127
- /**
128
- * @public
129
- * Broadcasts a message to all of the app's active processes, not including the current process.
130
- *
131
- * @param message - The message to be broadcasted. This can be any kind of structured data.
132
- *
133
- * @example Broadcast primitive values
134
- * ```typescript
135
- * import { appProcess } from '@canva/platform';
136
- *
137
- * // Broadcasting a string
138
- * appProcess.broadcastMessage('REFRESH_REQUESTED');
139
- *
140
- * // Broadcasting a number
141
- * appProcess.broadcastMessage(42);
142
- *
143
- * // Broadcasting a boolean
144
- * appProcess.broadcastMessage(true);
145
- * ```
146
- *
147
- * @example Broadcast simple objects
148
- * ```typescript
149
- * import { appProcess } from '@canva/platform';
150
- *
151
- * appProcess.broadcastMessage({
152
- * id: 'user-123',
153
- * name: 'John Doe',
154
- * active: true
155
- * });
156
- * ```
157
- *
158
- * @example Broadcast complex objects
159
- * ```typescript
160
- * import { appProcess } from '@canva/platform';
161
- *
162
- * appProcess.broadcastMessage({
163
- * type: 'DOCUMENT_UPDATE',
164
- * timestamp: Date.now(),
165
- * payload: {
166
- * documentId: 'doc-123',
167
- * version: 2,
168
- * metadata: {
169
- * title: 'Project Alpha',
170
- * tags: ['draft', 'review-needed'],
171
- * collaborators: [
172
- * { id: 'user-1', role: 'editor' },
173
- * { id: 'user-2', role: 'viewer' }
174
- * ]
175
- * }
176
- * }
177
- * });
178
- * ```
179
- */
180
- broadcastMessage(message: any): void;
6
+ /**
7
+ * The current app process.
8
+ */
9
+ readonly current: CurrentAppProcess;
10
+ /**
11
+ * @public
12
+ * Requests the termination of the specified app process.
13
+ *
14
+ * @param target - The ID of an app process.
15
+ * @param params - Parameters to pass to the `setOnDispose` callback. Any kind of structured data can be passed via this property.
16
+ *
17
+ * @remarks
18
+ * Once called, this method:
19
+ *
20
+ * 1. Transitions the state of the process to `"closing"`.
21
+ * 2. Invokes all registered `setOnDispose` callbacks.
22
+ * 3. Waits for the process to finish closing.
23
+ * 4. Transitions the state of the process to `"closed"`.
24
+ *
25
+ * Each time the state changes, all of the `registerOnStateChange` callbacks are called.
26
+ *
27
+ * @example Close a process
28
+ * ```typescript
29
+ * import { appProcess, type AppProcessId } from '@canva/platform';
30
+ *
31
+ * const placeholderProcessId = "PLACEHOLDER_PROCESS_ID" as AppProcessId;
32
+ *
33
+ * await appProcess.requestClose(placeholderProcessId, { reason: 'completed' });
34
+ * ```
35
+ *
36
+ * @example Pass structured data to a process as it closes
37
+ * ```typescript
38
+ * import { appProcess, type AppProcessId, type CloseParams } from '@canva/platform';
39
+ *
40
+ * type DetailedCloseParams = CloseParams & {
41
+ * savePoint: string;
42
+ * timestamp: number;
43
+ * userInitiated: boolean;
44
+ * };
45
+ *
46
+ * const placeholderProcessId = "PLACEHOLDER_PROCESS_ID" as AppProcessId;
47
+ *
48
+ * await appProcess.requestClose<DetailedCloseParams>(placeholderProcessId, {
49
+ * reason: 'completed',
50
+ * savePoint: 'auto_backup_1',
51
+ * timestamp: Date.now(),
52
+ * userInitiated: true
53
+ * });
54
+ * ```
55
+ */
56
+ requestClose<T extends CloseParams>(target: AppProcessId, params: T): Promise<void>;
57
+ /**
58
+ * @public
59
+ * Registers a callback that runs when the state of the specified app process changes.
60
+ *
61
+ * @param target - The ID of an app process.
62
+ * @param callback - The callback to run when the state of the process changes.
63
+ *
64
+ * @returns
65
+ * A disposer function that cleans up the registered callback.
66
+ *
67
+ * @example Listen for process state changes
68
+ * ```typescript
69
+ * import { appProcess } from '@canva/platform';
70
+ *
71
+ * const stateDisposer = appProcess.registerOnStateChange(
72
+ * processId,
73
+ * ({ state }) => {
74
+ * switch (state) {
75
+ * case 'opening':
76
+ * // Process is starting up
77
+ * break;
78
+ * case 'open':
79
+ * // Process is active and visible
80
+ * break;
81
+ * case 'closing':
82
+ * // Process is about to close
83
+ * // Save state, cleanup resources
84
+ * break;
85
+ * case 'closed':
86
+ * // Process has been terminated
87
+ * // Final cleanup if needed
88
+ * break;
89
+ * }
90
+ * }
91
+ * );
92
+ *
93
+ * // Later: cleanup the listener
94
+ * await stateDisposer();
95
+ * ```
96
+ */
97
+ registerOnStateChange(target: AppProcessId, callback: OnStateChangeCallback): () => Promise<void>;
98
+ /**
99
+ * @public
100
+ * Registers a callback that listens for broadcasted messages.
101
+ *
102
+ * @param callback - The callback that listens for broadcasted messages.
103
+ *
104
+ * @returns
105
+ * A disposer function that cleans up the registered callback.
106
+ *
107
+ * @example Listen for inter-process messages
108
+ * ```typescript
109
+ * import { appProcess } from '@canva/platform';
110
+ *
111
+ * const messageDisposer = appProcess.registerOnMessage(async (sender, message) => {
112
+ * const { appProcessId, surface } = sender;
113
+ * // Handle message from other process
114
+ * });
115
+ *
116
+ * // Later: cleanup the listener
117
+ * await messageDisposer();
118
+ * ```
119
+ */
120
+ registerOnMessage(callback: OnMessageCallback): () => Promise<void>;
121
+ /**
122
+ * @public
123
+ * Broadcasts a message to all of the app's active processes, not including the current process.
124
+ *
125
+ * @param message - The message to be broadcasted. This can be any kind of structured data.
126
+ *
127
+ * @example Broadcast primitive values
128
+ * ```typescript
129
+ * import { appProcess } from '@canva/platform';
130
+ *
131
+ * // Broadcasting a string
132
+ * appProcess.broadcastMessage('REFRESH_REQUESTED');
133
+ *
134
+ * // Broadcasting a number
135
+ * appProcess.broadcastMessage(42);
136
+ *
137
+ * // Broadcasting a boolean
138
+ * appProcess.broadcastMessage(true);
139
+ * ```
140
+ *
141
+ * @example Broadcast simple objects
142
+ * ```typescript
143
+ * import { appProcess } from '@canva/platform';
144
+ *
145
+ * appProcess.broadcastMessage({
146
+ * id: 'user-123',
147
+ * name: 'John Doe',
148
+ * active: true
149
+ * });
150
+ * ```
151
+ *
152
+ * @example Broadcast complex objects
153
+ * ```typescript
154
+ * import { appProcess } from '@canva/platform';
155
+ *
156
+ * appProcess.broadcastMessage({
157
+ * type: 'DOCUMENT_UPDATE',
158
+ * timestamp: Date.now(),
159
+ * payload: {
160
+ * documentId: 'doc-123',
161
+ * version: 2,
162
+ * metadata: {
163
+ * title: 'Project Alpha',
164
+ * tags: ['draft', 'review-needed'],
165
+ * collaborators: [
166
+ * { id: 'user-1', role: 'editor' },
167
+ * { id: 'user-2', role: 'viewer' }
168
+ * ]
169
+ * }
170
+ * }
171
+ * });
172
+ * ```
173
+ */
174
+ broadcastMessage(message: any): void;
181
175
  }
182
176
 
183
177
  /**
@@ -191,7 +185,7 @@ export declare const appProcess: AppProcess;
191
185
  * The unique identifier of an app process.
192
186
  */
193
187
  export declare type AppProcessId = string & {
194
- __appProcessId: never;
188
+ __appProcessId: never;
195
189
  };
196
190
 
197
191
  /**
@@ -199,18 +193,18 @@ export declare type AppProcessId = string & {
199
193
  * Information about an app process.
200
194
  */
201
195
  export declare type AppProcessInfo<T> = {
202
- /**
203
- * The surface on which the app process is running.
204
- */
205
- surface: AppSurface;
206
- /**
207
- * The unique identifier of the app process.
208
- */
209
- processId: AppProcessId;
210
- /**
211
- * Parameters passed to the app process when it was opened.
212
- */
213
- launchParams?: T;
196
+ /**
197
+ * The surface on which the app process is running.
198
+ */
199
+ surface: AppSurface;
200
+ /**
201
+ * The unique identifier of the app process.
202
+ */
203
+ processId: AppProcessId;
204
+ /**
205
+ * Parameters passed to the app process when it was opened.
206
+ */
207
+ launchParams?: T;
214
208
  };
215
209
 
216
210
  /**
@@ -224,20 +218,17 @@ export declare type AppProcessInfo<T> = {
224
218
  * - `"object_panel"` - A surface that renders a user interface in the side panel of the Canva editor.
225
219
  * - `"selected_image_overlay"` - A surface that can be opened on top of a selected image.
226
220
  */
227
- export declare type AppSurface =
228
- | "object_panel"
229
- | "selected_image_overlay"
230
- | "headless";
221
+ export declare type AppSurface = 'object_panel' | 'selected_image_overlay' | 'headless';
231
222
 
232
223
  /**
233
224
  * @public
234
225
  * Parameters passed to the `setOnDispose` callback when a process is about to close.
235
226
  */
236
227
  export declare type CloseParams = {
237
- /**
238
- * The reason the app process is closing.
239
- */
240
- reason: CloseReason;
228
+ /**
229
+ * The reason the app process is closing.
230
+ */
231
+ reason: CloseReason;
241
232
  };
242
233
 
243
234
  /**
@@ -250,134 +241,132 @@ export declare type CloseParams = {
250
241
  * - `"completed"` - Indicates that a workflow has been completed and unsaved changes should be saved.
251
242
  * - `"aborted"` - Indicates that a workflow has been abandoned and unsaved changes should be discarded.
252
243
  */
253
- export declare type CloseReason = "completed" | "aborted";
244
+ export declare type CloseReason = 'completed' | 'aborted';
254
245
 
255
246
  /**
256
247
  * @public
257
248
  * Provides methods for interacting with the current app process.
258
249
  */
259
250
  export declare type CurrentAppProcess = {
260
- /**
261
- * @public
262
- * Returns information about the current app process.
263
- *
264
- * @example Get current process information
265
- * ```typescript
266
- * import { appProcess } from '@canva/platform';
267
- *
268
- * const currentProcess = appProcess.current;
269
- * const processInfo = currentProcess.getInfo();
270
- * ```
271
- *
272
- * @example Check current process surface type
273
- * ```typescript
274
- * import { appProcess } from '@canva/platform';
275
- *
276
- * const currentProcess = appProcess.current;
277
- * const { surface } = currentProcess.getInfo();
278
- *
279
- * if (surface === 'object_panel') {
280
- * // This app is running in the object panel
281
- * }
282
- * ```
283
- *
284
- * @example Read current process launch parameters
285
- * ```typescript
286
- * import { appProcess } from '@canva/platform';
287
- *
288
- * type MyLaunchParams ={
289
- * mode: 'edit' | 'view';
290
- * id: string;
291
- * }
292
- *
293
- * const currentProcess = appProcess.current;
294
- * const { launchParams } = currentProcess.getInfo<MyLaunchParams>();
295
- *
296
- * if (launchParams) {
297
- * const { mode, id } = launchParams;
298
- * // Use launch parameters
299
- * }
300
- * ```
301
- */
302
- getInfo<T>(): AppProcessInfo<T>;
303
- /**
304
- * @public
305
- * Requests the termination of the current process.
306
- *
307
- * @param params - Parameters to pass to the `setOnDispose` callback. Any structured data can be passed via this property.
308
- *
309
- * @remarks
310
- * Once called, this method:
311
- *
312
- * 1. Transitions the state of the process to `"closing"`.
313
- * 2. Invokes all registered `setOnDispose` callbacks.
314
- * 3. Waits for the process to finish closing.
315
- * 4. Transitions the state of the process to `"closed"`.
316
- *
317
- * Each time the state changes, all of the `registerOnStateChange` callbacks are called.
318
- *
319
- * @example Close current process
320
- * ```typescript
321
- * import { appProcess } from '@canva/platform';
322
- *
323
- * await appProcess.current.requestClose({ reason: 'completed' });
324
- * ```
325
- *
326
- * @example Pass structured data to current process as it closes
327
- * ```typescript
328
- * import { appProcess, type CloseParams } from '@canva/platform';
329
- *
330
- * type DetailedCloseParams = CloseParams & {
331
- * metadata: {
332
- * savePoint: string;
333
- * timestamp: number;
334
- * userInitiated: boolean;
335
- * }
336
- * };
337
- *
338
- * await appProcess.current.requestClose<DetailedCloseParams>({
339
- * reason: 'completed',
340
- * metadata: {
341
- * savePoint: 'auto_backup_1',
342
- * timestamp: Date.now(),
343
- * userInitiated: true
344
- * }
345
- * });
346
- * ```
347
- */
348
- requestClose<T extends CloseParams>(params: T): Promise<void>;
349
- /**
350
- * @public
351
- * Registers a callback that runs when the current app process is about to close.
352
- *
353
- * @param callback - The callback to run when the current app process is about to close.
354
- *
355
- * @returns
356
- * A disposer function that cleans up the registered callback.
357
- *
358
- * @remarks
359
- * - Apps can't register multiple callbacks.
360
- * - If an app attempts to register multiple callbacks, only the last callback will be registered.
361
- * - The app process will remain open until the callback resolves or a timeout error occurs.
362
- * - The complete execution of the callback is not guaranteed as some user actions (e.g. closing tabs) may close the process prematurely.
363
- *
364
- * @example Handle process cleanup
365
- * ```typescript
366
- * import { appProcess } from '@canva/platform';
367
- *
368
- * const cleanupDisposer = appProcess.current.setOnDispose(async (params) => {
369
- * if (params.reason === 'completed') {
370
- * await saveChanges();
371
- * }
372
- * });
373
- *
374
- * // Later: cleanup the listener
375
- * await cleanupDisposer();
376
- * ```
377
- */
378
- setOnDispose<T extends CloseParams>(
379
- callback: OnDisposeCallback<T>,
380
- ): () => Promise<void>;
251
+ /**
252
+ * @public
253
+ * Returns information about the current app process.
254
+ *
255
+ * @example Get current process information
256
+ * ```typescript
257
+ * import { appProcess } from '@canva/platform';
258
+ *
259
+ * const currentProcess = appProcess.current;
260
+ * const processInfo = currentProcess.getInfo();
261
+ * ```
262
+ *
263
+ * @example Check current process surface type
264
+ * ```typescript
265
+ * import { appProcess } from '@canva/platform';
266
+ *
267
+ * const currentProcess = appProcess.current;
268
+ * const { surface } = currentProcess.getInfo();
269
+ *
270
+ * if (surface === 'object_panel') {
271
+ * // This app is running in the object panel
272
+ * }
273
+ * ```
274
+ *
275
+ * @example Read current process launch parameters
276
+ * ```typescript
277
+ * import { appProcess } from '@canva/platform';
278
+ *
279
+ * type MyLaunchParams ={
280
+ * mode: 'edit' | 'view';
281
+ * id: string;
282
+ * }
283
+ *
284
+ * const currentProcess = appProcess.current;
285
+ * const { launchParams } = currentProcess.getInfo<MyLaunchParams>();
286
+ *
287
+ * if (launchParams) {
288
+ * const { mode, id } = launchParams;
289
+ * // Use launch parameters
290
+ * }
291
+ * ```
292
+ */
293
+ getInfo<T>(): AppProcessInfo<T>;
294
+ /**
295
+ * @public
296
+ * Requests the termination of the current process.
297
+ *
298
+ * @param params - Parameters to pass to the `setOnDispose` callback. Any structured data can be passed via this property.
299
+ *
300
+ * @remarks
301
+ * Once called, this method:
302
+ *
303
+ * 1. Transitions the state of the process to `"closing"`.
304
+ * 2. Invokes all registered `setOnDispose` callbacks.
305
+ * 3. Waits for the process to finish closing.
306
+ * 4. Transitions the state of the process to `"closed"`.
307
+ *
308
+ * Each time the state changes, all of the `registerOnStateChange` callbacks are called.
309
+ *
310
+ * @example Close current process
311
+ * ```typescript
312
+ * import { appProcess } from '@canva/platform';
313
+ *
314
+ * await appProcess.current.requestClose({ reason: 'completed' });
315
+ * ```
316
+ *
317
+ * @example Pass structured data to current process as it closes
318
+ * ```typescript
319
+ * import { appProcess, type CloseParams } from '@canva/platform';
320
+ *
321
+ * type DetailedCloseParams = CloseParams & {
322
+ * metadata: {
323
+ * savePoint: string;
324
+ * timestamp: number;
325
+ * userInitiated: boolean;
326
+ * }
327
+ * };
328
+ *
329
+ * await appProcess.current.requestClose<DetailedCloseParams>({
330
+ * reason: 'completed',
331
+ * metadata: {
332
+ * savePoint: 'auto_backup_1',
333
+ * timestamp: Date.now(),
334
+ * userInitiated: true
335
+ * }
336
+ * });
337
+ * ```
338
+ */
339
+ requestClose<T extends CloseParams>(params: T): Promise<void>;
340
+ /**
341
+ * @public
342
+ * Registers a callback that runs when the current app process is about to close.
343
+ *
344
+ * @param callback - The callback to run when the current app process is about to close.
345
+ *
346
+ * @returns
347
+ * A disposer function that cleans up the registered callback.
348
+ *
349
+ * @remarks
350
+ * - Apps can't register multiple callbacks.
351
+ * - If an app attempts to register multiple callbacks, only the last callback will be registered.
352
+ * - The app process will remain open until the callback resolves or a timeout error occurs.
353
+ * - The complete execution of the callback is not guaranteed as some user actions (e.g. closing tabs) may close the process prematurely.
354
+ *
355
+ * @example Handle process cleanup
356
+ * ```typescript
357
+ * import { appProcess } from '@canva/platform';
358
+ *
359
+ * const cleanupDisposer = appProcess.current.setOnDispose(async (params) => {
360
+ * if (params.reason === 'completed') {
361
+ * await saveChanges();
362
+ * }
363
+ * });
364
+ *
365
+ * // Later: cleanup the listener
366
+ * await cleanupDisposer();
367
+ * ```
368
+ */
369
+ setOnDispose<T extends CloseParams>(callback: OnDisposeCallback<T>): () => Promise<void>;
381
370
  };
382
371
 
383
372
  /**
@@ -403,50 +392,50 @@ export declare const features: FeatureSupport;
403
392
  * Provides methods for checking if an SDK method is supported in the current context.
404
393
  */
405
394
  export declare interface FeatureSupport {
406
- /**
407
- * @public
408
- * Checks if the specified SDK methods are supported in the current context.
409
- *
410
- * @param features - The SDK methods to be checked for support.
411
- *
412
- * @example Checking a single feature
413
- * ```typescript
414
- * import { features } from '@canva/platform';
415
- * import { addElementAtPoint } from '@canva/design';
416
- *
417
- * const isSupported = features.isSupported(addElementAtPoint);
418
- * ```
419
- *
420
- * @example Checking multiple features
421
- * ```typescript
422
- * import { features } from '@canva/platform';
423
- * import { addElementAtPoint, addElementAtCursor } from '@canva/design';
424
- *
425
- * const areSupported = features.isSupported(addElementAtPoint, addElementAtCursor);
426
- * ```
427
- */
428
- isSupported(...features: Feature[]): boolean;
429
- /**
430
- * @public
431
- * Registers a callback that runs when the context changes and an SDK method becomes supported or unsupported.
432
- *
433
- * @param onSupportChange - The callback that runs when the support status of an SDK method changes.
434
- *
435
- * @example Monitoring feature support changes
436
- * ```typescript
437
- * import { features } from '@canva/platform';
438
- * import { addElementAtPoint } from '@canva/design';
439
- *
440
- * const supportDisposer = features.registerOnSupportChange(() => {
441
- * const isNowSupported = features.isSupported(addElementAtPoint);
442
- * // Update UI based on new support status
443
- * });
444
- *
445
- * // Later: cleanup the listener
446
- * await supportDisposer();
447
- * ```
448
- */
449
- registerOnSupportChange(onSupportChange: () => void): Disposer;
395
+ /**
396
+ * @public
397
+ * Checks if the specified SDK methods are supported in the current context.
398
+ *
399
+ * @param features - The SDK methods to be checked for support.
400
+ *
401
+ * @example Checking a single feature
402
+ * ```typescript
403
+ * import { features } from '@canva/platform';
404
+ * import { addElementAtPoint } from '@canva/design';
405
+ *
406
+ * const isSupported = features.isSupported(addElementAtPoint);
407
+ * ```
408
+ *
409
+ * @example Checking multiple features
410
+ * ```typescript
411
+ * import { features } from '@canva/platform';
412
+ * import { addElementAtPoint, addElementAtCursor } from '@canva/design';
413
+ *
414
+ * const areSupported = features.isSupported(addElementAtPoint, addElementAtCursor);
415
+ * ```
416
+ */
417
+ isSupported(...features: Feature[]): boolean;
418
+ /**
419
+ * @public
420
+ * Registers a callback that runs when the context changes and an SDK method becomes supported or unsupported.
421
+ *
422
+ * @param onSupportChange - The callback that runs when the support status of an SDK method changes.
423
+ *
424
+ * @example Monitoring feature support changes
425
+ * ```typescript
426
+ * import { features } from '@canva/platform';
427
+ * import { addElementAtPoint } from '@canva/design';
428
+ *
429
+ * const supportDisposer = features.registerOnSupportChange(() => {
430
+ * const isNowSupported = features.isSupported(addElementAtPoint);
431
+ * // Update UI based on new support status
432
+ * });
433
+ *
434
+ * // Later: cleanup the listener
435
+ * await supportDisposer();
436
+ * ```
437
+ */
438
+ registerOnSupportChange(onSupportChange: () => void): Disposer;
450
439
  }
451
440
 
452
441
  /**
@@ -487,27 +476,27 @@ export declare const notification: NotificationClient;
487
476
  * Provides methods for interacting with notifications.
488
477
  */
489
478
  export declare interface NotificationClient {
490
- /**
491
- * @public
492
- *
493
- * A method that shows a toast notification to the user.
494
- *
495
- * @example
496
- * ```tsx
497
- * import { notification } from '@canva/platform';
498
- * import type { ToastRequest } from '@canva/platform';
499
- *
500
- * const showToast = () => {
501
- * const request: ToastRequest = {
502
- * messageText: "Hello world!",
503
- * };
504
- * notification.addToast(request);
505
- * };
506
- *
507
- * <Button onClick={() => showToast()}>Show Toast</Button>
508
- * ```
509
- */
510
- addToast: (request: ToastRequest) => Promise<ToastResponse>;
479
+ /**
480
+ * @public
481
+ *
482
+ * A method that shows a toast notification to the user.
483
+ *
484
+ * @example
485
+ * ```tsx
486
+ * import { notification } from '@canva/platform';
487
+ * import type { ToastRequest } from '@canva/platform';
488
+ *
489
+ * const showToast = () => {
490
+ * const request: ToastRequest = {
491
+ * messageText: "Hello world!",
492
+ * };
493
+ * notification.addToast(request);
494
+ * };
495
+ *
496
+ * <Button onClick={() => showToast()}>Show Toast</Button>
497
+ * ```
498
+ */
499
+ addToast: (request: ToastRequest) => Promise<ToastResponse>;
511
500
  }
512
501
 
513
502
  /**
@@ -515,9 +504,7 @@ export declare interface NotificationClient {
515
504
  * A callback that runs when an app process is about to close.
516
505
  * @param opts - Parameters passed to the `setOnDispose` callback when a process is about to close.
517
506
  */
518
- export declare type OnDisposeCallback<T extends CloseParams> = (
519
- opts: T,
520
- ) => Promise<void>;
507
+ export declare type OnDisposeCallback<T extends CloseParams> = (opts: T) => Promise<void>;
521
508
 
522
509
  /**
523
510
  * @public
@@ -528,13 +515,10 @@ export declare type OnDisposeCallback<T extends CloseParams> = (
528
515
  * - sender.surface - The surface of the process that sent the message.
529
516
  * @param message - The broadcasted message.
530
517
  */
531
- export declare type OnMessageCallback = (
532
- sender: {
518
+ export declare type OnMessageCallback = (sender: {
533
519
  appProcessId: AppProcessId;
534
520
  surface: AppSurface;
535
- },
536
- message: any,
537
- ) => Promise<void>;
521
+ }, message: any) => Promise<void>;
538
522
 
539
523
  /**
540
524
  * @public
@@ -544,7 +528,7 @@ export declare type OnMessageCallback = (
544
528
  * - opts.state - The state of the process.
545
529
  */
546
530
  export declare type OnStateChangeCallback = (opts: {
547
- state: ProcessState;
531
+ state: ProcessState;
548
532
  }) => void;
549
533
 
550
534
  /**
@@ -552,10 +536,10 @@ export declare type OnStateChangeCallback = (opts: {
552
536
  * The result when a user doesn't agree to navigate to an external URL.
553
537
  */
554
538
  export declare type OpenExternalUrlAborted = {
555
- /**
556
- * The status of the request.
557
- */
558
- status: "aborted";
539
+ /**
540
+ * The status of the request.
541
+ */
542
+ status: 'aborted';
559
543
  };
560
544
 
561
545
  /**
@@ -563,10 +547,10 @@ export declare type OpenExternalUrlAborted = {
563
547
  * The result when a user agrees to navigate to an external URL.
564
548
  */
565
549
  export declare type OpenExternalUrlCompleted = {
566
- /**
567
- * The status of the request.
568
- */
569
- status: "completed";
550
+ /**
551
+ * The status of the request.
552
+ */
553
+ status: 'completed';
570
554
  };
571
555
 
572
556
  /**
@@ -574,47 +558,45 @@ export declare type OpenExternalUrlCompleted = {
574
558
  * Options for prompting the user to open an external URL.
575
559
  */
576
560
  export declare type OpenExternalUrlRequest = {
577
- /**
578
- * The URL to open.
579
- */
580
- url: string;
561
+ /**
562
+ * The URL to open.
563
+ */
564
+ url: string;
581
565
  };
582
566
 
583
567
  /**
584
568
  * @public
585
569
  * The result of prompting the user to open an external URL.
586
570
  */
587
- export declare type OpenExternalUrlResponse =
588
- | OpenExternalUrlCompleted
589
- | OpenExternalUrlAborted;
571
+ export declare type OpenExternalUrlResponse = OpenExternalUrlCompleted | OpenExternalUrlAborted;
590
572
 
591
573
  /**
592
574
  * @public
593
575
  * Information about the platform on which the app is running.
594
576
  */
595
577
  export declare type PlatformInfo = {
596
- /**
597
- * If `true`, the app is allowed to directly link to payment and upgrade flows.
598
- *
599
- * @remarks
600
- * This property is always `true` when the app is running in a web browser, but may otherwise be `false` in
601
- * order to comply with the policies of the platforms on which Canva is available. For example, some platforms
602
- * only allow payment-related actions that use their own payment mechanisms and apps are therefore not allowed
603
- * to render payment-related call-to-actions while running on those platforms.
604
- *
605
- * @example
606
- * ```ts
607
- * const info = getPlatformInfo();
608
- *
609
- * if (info.canAcceptPayments) {
610
- * // Display payment links and upgrade flows
611
- * } else {
612
- * // Hide payment links and upgrade flows
613
- * // Optionally, show an appropriate message
614
- * }
615
- * ```
616
- */
617
- canAcceptPayments: boolean;
578
+ /**
579
+ * If `true`, the app is allowed to directly link to payment and upgrade flows.
580
+ *
581
+ * @remarks
582
+ * This property is always `true` when the app is running in a web browser, but may otherwise be `false` in
583
+ * order to comply with the policies of the platforms on which Canva is available. For example, some platforms
584
+ * only allow payment-related actions that use their own payment mechanisms and apps are therefore not allowed
585
+ * to render payment-related call-to-actions while running on those platforms.
586
+ *
587
+ * @example
588
+ * ```ts
589
+ * const info = getPlatformInfo();
590
+ *
591
+ * if (info.canAcceptPayments) {
592
+ * // Display payment links and upgrade flows
593
+ * } else {
594
+ * // Hide payment links and upgrade flows
595
+ * // Optionally, show an appropriate message
596
+ * }
597
+ * ```
598
+ */
599
+ canAcceptPayments: boolean;
618
600
  };
619
601
 
620
602
  /**
@@ -631,7 +613,7 @@ export declare type PlatformInfo = {
631
613
  *
632
614
  * While a process is closing, it won't receive any events or messages from other processes.
633
615
  */
634
- export declare type ProcessState = "opening" | "open" | "closing" | "closed";
616
+ export declare type ProcessState = 'opening' | 'open' | 'closing' | 'closed';
635
617
 
636
618
  /**
637
619
  * @public
@@ -677,19 +659,17 @@ export declare type ProcessState = "opening" | "open" | "closing" | "closed";
677
659
  * }
678
660
  * ```
679
661
  */
680
- export declare const requestOpenExternalUrl: (
681
- request: OpenExternalUrlRequest,
682
- ) => Promise<OpenExternalUrlResponse>;
662
+ export declare const requestOpenExternalUrl: (request: OpenExternalUrlRequest) => Promise<OpenExternalUrlResponse>;
683
663
 
684
664
  /**
685
665
  * @public
686
666
  * The result when a toast notification is successfully added.
687
667
  */
688
668
  export declare type ToastCompleted = {
689
- /**
690
- * The status of the request.
691
- */
692
- status: "completed";
669
+ /**
670
+ * The status of the request.
671
+ */
672
+ status: 'completed';
693
673
  };
694
674
 
695
675
  /**
@@ -698,20 +678,20 @@ export declare type ToastCompleted = {
698
678
  * Options for configuring a toast notification.
699
679
  */
700
680
  export declare type ToastRequest = {
701
- /**
702
- * Text to show within the toast notification.
703
- */
704
- messageText: string;
705
- /**
706
- * The duration that the notification will be visible.
707
- *
708
- * If set to `"infinite"`, the notification will be displayed until manually dismissed by the user.
709
- *
710
- * If set to a number, the notification will automatically disappear after that duration (in milliseconds).
711
- *
712
- * @defaultValue 5000
713
- */
714
- timeoutMs?: number | "infinite";
681
+ /**
682
+ * Text to show within the toast notification.
683
+ */
684
+ messageText: string;
685
+ /**
686
+ * The duration that the notification will be visible.
687
+ *
688
+ * If set to `"infinite"`, the notification will be displayed until manually dismissed by the user.
689
+ *
690
+ * If set to a number, the notification will automatically disappear after that duration (in milliseconds).
691
+ *
692
+ * @defaultValue 5000
693
+ */
694
+ timeoutMs?: number | 'infinite';
715
695
  };
716
696
 
717
697
  /**
@@ -721,4 +701,4 @@ export declare type ToastRequest = {
721
701
  */
722
702
  export declare type ToastResponse = ToastCompleted;
723
703
 
724
- export {};
704
+ export { }
package/index.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from "./beta";
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", {
3
3
  value: true
4
4
  });
5
+ const _version = require("./version");
5
6
  _export_star(require("./public"), exports);
6
7
  function _export_star(from, to) {
7
8
  Object.keys(from).forEach(function(k) {
@@ -16,5 +17,4 @@ function _export_star(from, to) {
16
17
  });
17
18
  return from;
18
19
  }
19
- var _window___canva___sdkRegistration, _window___canva__;
20
- (_window___canva__ = window.__canva__) === null || _window___canva__ === void 0 ? void 0 : (_window___canva___sdkRegistration = _window___canva__.sdkRegistration) === null || _window___canva___sdkRegistration === void 0 ? void 0 : _window___canva___sdkRegistration.registerPackageVersion('platform', '2.2.0', 'beta');
20
+ window.__canva__?.sdkRegistration?.registerPackageVersion('platform', _version.LATEST_VERSION_BETA, 'beta');
@@ -34,8 +34,7 @@ class FakeAppProcessClient {
34
34
  },
35
35
  setOnDispose: (callback)=>async ()=>{
36
36
  await Promise.resolve();
37
- },
38
- registerOnStateChangeInternal: (callback)=>()=>Promise.resolve()
37
+ }
39
38
  };
40
39
  }
41
40
  }
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ _export_star(require("./beta"), exports);
6
+ function _export_star(from, to) {
7
+ Object.keys(from).forEach(function(k) {
8
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
9
+ Object.defineProperty(to, k, {
10
+ enumerable: true,
11
+ get: function() {
12
+ return from[k];
13
+ }
14
+ });
15
+ }
16
+ });
17
+ return from;
18
+ }
@@ -0,0 +1,24 @@
1
+ "use strict"
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ function _export(target, all) {
6
+ for(var name in all)Object.defineProperty(target, name, {
7
+ enumerable: true,
8
+ get: Object.getOwnPropertyDescriptor(all, name).get
9
+ });
10
+ }
11
+ _export(exports, {
12
+ get LATEST_VERSION () {
13
+ return LATEST_VERSION;
14
+ },
15
+ get LATEST_VERSION_ALPHA () {
16
+ return LATEST_VERSION_ALPHA;
17
+ },
18
+ get LATEST_VERSION_BETA () {
19
+ return LATEST_VERSION_BETA;
20
+ }
21
+ });
22
+ const LATEST_VERSION = '2.2.0';
23
+ const LATEST_VERSION_BETA = '2.2.1-beta.0';
24
+ const LATEST_VERSION_ALPHA = 'NONE';
@@ -26,10 +26,8 @@ function getCanvaSdk() {
26
26
  return window.canva_sdk;
27
27
  }
28
28
  function assertIsTestCanvaSdk() {
29
- var _window___canva__;
30
- if ((_window___canva__ = window.__canva__) === null || _window___canva__ === void 0 ? void 0 : _window___canva__.uiKit) {
31
- var _getCanvaSdk_error, _getCanvaSdk;
32
- const CanvaError = (_getCanvaSdk = getCanvaSdk()) === null || _getCanvaSdk === void 0 ? void 0 : (_getCanvaSdk_error = _getCanvaSdk.error) === null || _getCanvaSdk_error === void 0 ? void 0 : _getCanvaSdk_error.v2.CanvaError;
29
+ if (window.__canva__?.uiKit) {
30
+ const CanvaError = getCanvaSdk()?.error?.v2.CanvaError;
33
31
  throw new CanvaError({
34
32
  code: 'failed_precondition',
35
33
  message: "Canva App SDK: You're attempting to call `initTestEnvironment` in a non-test environment, such as in production. This method should be called in test environments, once and only once. For more info refer to https://canva.dev/docs/apps/testing/"
@@ -1,3 +1,3 @@
1
- var _window___canva___sdkRegistration, _window___canva__;
1
+ import { LATEST_VERSION_BETA } from './version';
2
2
  export * from './public';
3
- (_window___canva__ = window.__canva__) === null || _window___canva__ === void 0 ? void 0 : (_window___canva___sdkRegistration = _window___canva__.sdkRegistration) === null || _window___canva___sdkRegistration === void 0 ? void 0 : _window___canva___sdkRegistration.registerPackageVersion('platform', '2.2.0', 'beta');
3
+ window.__canva__?.sdkRegistration?.registerPackageVersion('platform', LATEST_VERSION_BETA, 'beta');
@@ -24,8 +24,7 @@ export class FakeAppProcessClient {
24
24
  },
25
25
  setOnDispose: (callback)=>async ()=>{
26
26
  await Promise.resolve();
27
- },
28
- registerOnStateChangeInternal: (callback)=>()=>Promise.resolve()
27
+ }
29
28
  };
30
29
  }
31
30
  }
@@ -0,0 +1 @@
1
+ export * from './beta';
@@ -0,0 +1,3 @@
1
+ export const LATEST_VERSION = '2.2.0';
2
+ export const LATEST_VERSION_BETA = '2.2.1-beta.0';
3
+ export const LATEST_VERSION_ALPHA = 'NONE';
@@ -2,10 +2,8 @@ export function getCanvaSdk() {
2
2
  return window.canva_sdk;
3
3
  }
4
4
  export function assertIsTestCanvaSdk() {
5
- var _window___canva__;
6
- if ((_window___canva__ = window.__canva__) === null || _window___canva__ === void 0 ? void 0 : _window___canva__.uiKit) {
7
- var _getCanvaSdk_error, _getCanvaSdk;
8
- const CanvaError = (_getCanvaSdk = getCanvaSdk()) === null || _getCanvaSdk === void 0 ? void 0 : (_getCanvaSdk_error = _getCanvaSdk.error) === null || _getCanvaSdk_error === void 0 ? void 0 : _getCanvaSdk_error.v2.CanvaError;
5
+ if (window.__canva__?.uiKit) {
6
+ const CanvaError = getCanvaSdk()?.error?.v2.CanvaError;
9
7
  throw new CanvaError({
10
8
  code: 'failed_precondition',
11
9
  message: "Canva App SDK: You're attempting to call `initTestEnvironment` in a non-test environment, such as in production. This method should be called in test environments, once and only once. For more info refer to https://canva.dev/docs/apps/testing/"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@canva/platform",
3
- "version": "2.2.0-beta.1",
3
+ "version": "2.2.1-beta.0",
4
4
  "description": "The Canva Apps SDK app platform library",
5
5
  "author": "Canva Pty Ltd.",
6
6
  "license": "SEE LICENSE IN LICENSE.md FILE",
package/test/beta.d.ts CHANGED
@@ -8,4 +8,4 @@
8
8
  */
9
9
  export declare function initTestEnvironment(): void;
10
10
 
11
- export {};
11
+ export { }
@@ -0,0 +1 @@
1
+ export * from "./beta";