@canva/platform 2.0.0 → 2.1.1-beta.1

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/index.d.ts DELETED
@@ -1,362 +0,0 @@
1
- /**
2
- * @public
3
- * Provides methods for interacting with an app process.
4
- */
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
- requestClose<T extends CloseParams>(
28
- target: AppProcessId,
29
- params: T
30
- ): Promise<void>;
31
- /**
32
- * @public
33
- * Registers a callback that runs when the state of the specified app process changes.
34
- *
35
- * @param target - The ID of an app process.
36
- * @param callback - The callback to run when the state of the process changes.
37
- *
38
- * @returns
39
- * A disposer function that cleans up the registered callback.
40
- */
41
- registerOnStateChange(
42
- target: AppProcessId,
43
- callback: OnStateChangeCallback
44
- ): () => Promise<void>;
45
- /**
46
- * @public
47
- * Registers a callback that listens for broadcasted messages.
48
- *
49
- * @param callback - The callback that listens for broadcasted messages.
50
- *
51
- * @returns
52
- * A disposer function that cleans up the registered callback.
53
- */
54
- registerOnMessage(callback: OnMessageCallback): () => Promise<void>;
55
- /**
56
- * @public
57
- * Broadcasts a message to all of the app's active processes, not including the current process.
58
- *
59
- * @param message - The message to be broadcasted. This can be any kind of structured data.
60
- */
61
- broadcastMessage(message: any): void;
62
- }
63
-
64
- /**
65
- * An alias for the AppProcess interface for interacting with the App Process.
66
- * @public
67
- */
68
- export declare const appProcess: AppProcess;
69
-
70
- /**
71
- * @public
72
- * The unique identifier of an app process.
73
- */
74
- export declare type AppProcessId = string & {
75
- __appProcessId: never;
76
- };
77
-
78
- /**
79
- * @public
80
- * Information about an app process.
81
- */
82
- export declare type AppProcessInfo<T> = {
83
- /**
84
- * The surface on which the app process is running.
85
- */
86
- surface: AppSurface;
87
- /**
88
- * The unique identifier of the app process.
89
- */
90
- processId: AppProcessId;
91
- /**
92
- * Parameters passed to the app process when it was opened.
93
- */
94
- launchParams?: T;
95
- };
96
-
97
- /**
98
- * @public
99
- * The type of surface on which an app process can run.
100
- *
101
- * @remarks
102
- * The possible surfaces include:
103
- *
104
- * - `"headless"` - A surface for when there is no visible user interface.
105
- * - `"object_panel"` - A surface that renders a user interface in the side panel of the Canva editor.
106
- * - `"selected_image_overlay"` - A surface that can be opened on top of a selected image.
107
- */
108
- export declare type AppSurface =
109
- | "object_panel"
110
- | "selected_image_overlay"
111
- | "headless";
112
-
113
- /**
114
- * @public
115
- * Parameters passed to the `setOnDispose` callback when a process is about to close.
116
- */
117
- export declare type CloseParams = {
118
- /**
119
- * The reason the app process is closing.
120
- */
121
- reason: CloseReason;
122
- };
123
-
124
- /**
125
- * @public
126
- * The reason why an app process is closing.
127
- *
128
- * @remarks
129
- * The possible reasons include:
130
- *
131
- * - `"completed"` - Indicates that a workflow has been completed and unsaved changes should be saved.
132
- * - `"aborted"` - Indicates that a workflow has been abandoned and unsaved changes should be discarded.
133
- */
134
- export declare type CloseReason = "completed" | "aborted";
135
-
136
- /**
137
- * @public
138
- * Provides methods for interacting with the current app process.
139
- */
140
- export declare type CurrentAppProcess = {
141
- /**
142
- * @public
143
- * Returns information about the current app process.
144
- */
145
- getInfo<T extends any>(): AppProcessInfo<T>;
146
- /**
147
- * @public
148
- * Requests the termination of the current process.
149
- *
150
- * @param params - Parameters to pass to the `setOnDispose` callback. Any structured data can be passed via this property.
151
- *
152
- * @remarks
153
- * Once called, this method:
154
- *
155
- * 1. Transitions the state of the process to `"closing"`.
156
- * 2. Invokes all registered `setOnDispose` callbacks.
157
- * 3. Waits for the process to finish closing.
158
- * 4. Transitions the state of the process to `"closed"`.
159
- *
160
- * Each time the state changes, all of the `registerOnStateChange` callbacks are called.
161
- */
162
- requestClose<T extends CloseParams>(params: T): Promise<void>;
163
- /**
164
- * @public
165
- * Registers a callback that runs when the current app process is about to close.
166
- *
167
- * @param callback - The callback to run when the current app process is about to close.
168
- *
169
- * @returns
170
- * A disposer function that cleans up the registered callback.
171
- *
172
- * @remarks
173
- * - Apps can't register multiple callbacks.
174
- * - If an app attempts to register multiple callbacks, only the last callback will be registered.
175
- * - The app process will remain open until the callback resolves or a timeout error occurs.
176
- * - The complete execution of the callback is not guaranteed as some user actions (e.g. closing tabs) may close the process prematurely.
177
- */
178
- setOnDispose<T extends CloseParams>(
179
- callback: OnDisposeCallback<T>
180
- ): () => Promise<void>;
181
- };
182
-
183
- /**
184
- * @public
185
- * Disposes an event listener.
186
- */
187
- declare type Disposer = () => void;
188
-
189
- /**
190
- * @public
191
- * An SDK method that can be inspected for feature support.
192
- */
193
- export declare type Feature = (...args: any[]) => unknown;
194
-
195
- /**
196
- * An alias for the FeatureSupport interface for interacting with feature controls.
197
- * @public
198
- */
199
- export declare const features: FeatureSupport;
200
-
201
- /**
202
- * @public
203
- * Client interface for checking if a given SDK method is supported the currently presented context.
204
- */
205
- export declare interface FeatureSupport {
206
- /**
207
- * @public
208
- * Checks whether a given SDK method is supported under the current context.
209
- * @param features - Canva SDK methods to be checked for support.
210
- */
211
- isSupported(...features: Feature[]): boolean;
212
- /**
213
- * @public
214
- * Registers an event listener for changes in what SDK methods are currently supported.
215
- * @param onSupportChange - A callback that gets fired upon any change to the feature support context.
216
- */
217
- registerOnSupportChange(onSupportChange: () => void): Disposer;
218
- }
219
-
220
- /**
221
- * @public
222
- * Returns information about the platform on which the app is running.
223
- */
224
- export declare function getPlatformInfo(): PlatformInfo;
225
-
226
- /**
227
- * @public
228
- * A callback that runs when an app process is about to close.
229
- * @param opts - Parameters passed to the `setOnDispose` callback when a process is about to close.
230
- */
231
- export declare type OnDisposeCallback<T extends CloseParams> = (
232
- opts: T
233
- ) => Promise<void>;
234
-
235
- /**
236
- * @public
237
- * A callback that runs when an app process receives a broadcasted message.
238
- *
239
- * @param sender - Information about the process that sent the message.
240
- * - sender.appProcessId - The ID of the process that sent the message.
241
- * - sender.surface - The surface of the process that sent the message.
242
- * @param message - The broadcasted message.
243
- */
244
- export declare type OnMessageCallback = (
245
- sender: {
246
- appProcessId: AppProcessId;
247
- surface: AppSurface;
248
- },
249
- message: any
250
- ) => Promise<void>;
251
-
252
- /**
253
- * @public
254
- * A callback that runs when the state of a process changes.
255
- *
256
- * @param opts - Information about the state change.
257
- * - opts.state - The state of the process.
258
- */
259
- export declare type OnStateChangeCallback = (opts: {
260
- state: ProcessState;
261
- }) => void;
262
-
263
- /**
264
- * @public
265
- * The result when a user doesn't agree to navigate to an external URL.
266
- */
267
- export declare type OpenExternalUrlAborted = {
268
- /**
269
- * The status of the request.
270
- */
271
- status: "aborted";
272
- };
273
-
274
- /**
275
- * @public
276
- * The result when a user agrees to navigate to an external URL.
277
- */
278
- export declare type OpenExternalUrlCompleted = {
279
- /**
280
- * The status of the request.
281
- */
282
- status: "completed";
283
- };
284
-
285
- /**
286
- * @public
287
- * Options for prompting the user to open an external URL.
288
- */
289
- export declare type OpenExternalUrlRequest = {
290
- /**
291
- * The URL to open.
292
- */
293
- url: string;
294
- };
295
-
296
- /**
297
- * @public
298
- * The result of prompting the user to open an external URL.
299
- */
300
- export declare type OpenExternalUrlResponse =
301
- | OpenExternalUrlCompleted
302
- | OpenExternalUrlAborted;
303
-
304
- /**
305
- * @public
306
- * Information about the platform on which the app is running.
307
- */
308
- export declare type PlatformInfo = {
309
- /**
310
- * If `true`, the app is allowed to directly link to payment and upgrade flows.
311
- *
312
- * @remarks
313
- * This property is always `true` when the app is running in a web browser, but may otherwise be `false` in
314
- * order to comply with the policies of the platforms on which Canva is available. For example, some platforms
315
- * only allow payment-related actions that use their own payment mechanisms and apps are therefore not allowed
316
- * to render payment-related call-to-actions while running on those platforms.
317
- *
318
- * @example
319
- * ```ts
320
- * const info = getPlatformInfo();
321
- *
322
- * if (info.canAcceptPayments) {
323
- * // Display payment links and upgrade flows
324
- * } else {
325
- * // Hide payment links and upgrade flows
326
- * // Optionally, show an appropriate message
327
- * }
328
- * ```
329
- */
330
- canAcceptPayments: boolean;
331
- };
332
-
333
- /**
334
- * @public
335
- * The state of an app process.
336
- *
337
- * @remarks
338
- * The possible states include:
339
- *
340
- * - `"opening"` - The app process is opening.
341
- * - `"open"` - The app process is open, active, and visible on the designated surface.
342
- * - `"closing"` - The app process is closing.
343
- * - `"closed"` - The app process has been closed and is no longer active.
344
- *
345
- * While a process is closing, it won't receive any events or messages from other processes.
346
- */
347
- export declare type ProcessState = "opening" | "open" | "closing" | "closed";
348
-
349
- /**
350
- * @public
351
- * Opens an external URL.
352
- *
353
- * @remarks
354
- * The URL is opened natively, such as in a new browser tab on desktop or in a browser sheet on mobile.
355
- *
356
- * In some browsers, the user must enable popup permissions before any URL can be opened.
357
- */
358
- export declare function requestOpenExternalUrl(
359
- request: OpenExternalUrlRequest
360
- ): Promise<OpenExternalUrlResponse>;
361
-
362
- export {};
@@ -1,4 +0,0 @@
1
- var _window___canva___sdkRegistration, _window___canva__;
2
- export * from './public';
3
- (_window___canva__ =
4
- 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.0.0', 'ga');