@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 +5 -0
- package/beta.d.ts +432 -452
- package/index.d.ts +1 -0
- package/lib/cjs/sdk/platform/beta.js +2 -2
- package/lib/cjs/sdk/platform/fake/fake_app_process_client.js +1 -2
- package/lib/cjs/sdk/platform/index.js +18 -0
- package/lib/cjs/sdk/platform/version.js +24 -0
- package/lib/cjs/sdk/utils/canva_sdk.js +2 -4
- package/lib/esm/sdk/platform/beta.js +2 -2
- package/lib/esm/sdk/platform/fake/fake_app_process_client.js +1 -2
- package/lib/esm/sdk/platform/index.js +1 -0
- package/lib/esm/sdk/platform/version.js +3 -0
- package/lib/esm/sdk/utils/canva_sdk.js +2 -4
- package/package.json +1 -1
- package/test/beta.d.ts +1 -1
- package/test/index.d.ts +1 -0
package/CHANGELOG.md
ADDED
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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
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
|
-
|
|
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
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
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
|
-
|
|
239
|
-
|
|
240
|
-
|
|
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 =
|
|
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
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
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
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
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
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
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
|
-
|
|
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
|
-
|
|
557
|
-
|
|
558
|
-
|
|
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
|
-
|
|
568
|
-
|
|
569
|
-
|
|
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
|
-
|
|
579
|
-
|
|
580
|
-
|
|
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
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
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 =
|
|
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
|
-
|
|
691
|
-
|
|
692
|
-
|
|
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
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
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
|
-
|
|
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');
|
|
@@ -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
|
-
|
|
30
|
-
|
|
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
|
-
|
|
1
|
+
import { LATEST_VERSION_BETA } from './version';
|
|
2
2
|
export * from './public';
|
|
3
|
-
|
|
3
|
+
window.__canva__?.sdkRegistration?.registerPackageVersion('platform', LATEST_VERSION_BETA, 'beta');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './beta';
|
|
@@ -2,10 +2,8 @@ export function getCanvaSdk() {
|
|
|
2
2
|
return window.canva_sdk;
|
|
3
3
|
}
|
|
4
4
|
export function assertIsTestCanvaSdk() {
|
|
5
|
-
|
|
6
|
-
|
|
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
package/test/beta.d.ts
CHANGED
package/test/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./beta";
|