@canva/platform 1.0.1 → 1.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.
- package/index.d.ts +205 -0
- package/lib/cjs/sdk/platform/index.js +18 -16
- package/lib/cjs/sdk/platform/public.js +22 -17
- package/lib/esm/sdk/platform/index.js +1 -0
- package/lib/esm/sdk/platform/public.js +7 -4
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -1,9 +1,191 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @public
|
|
3
|
+
* An API for interacting with the App Process.
|
|
4
|
+
*/
|
|
5
|
+
export declare interface AppProcess {
|
|
6
|
+
readonly current: CurrentAppProcess;
|
|
7
|
+
/**
|
|
8
|
+
* @public
|
|
9
|
+
* Request the termination of an app process.
|
|
10
|
+
* @param target - The id of the app process to close.
|
|
11
|
+
* @param params - A parameters object passed to all callback functions registered via registerOnBeforeClose API for the provided AppProcessId.
|
|
12
|
+
* In addition to the required 'reason' field, app can choose to pass any structured data via params.
|
|
13
|
+
* {@link https://html.spec.whatwg.org/multipage/structured-data.html#safe-passing-of-structured-data | safe passing of structured data}
|
|
14
|
+
* @remarks
|
|
15
|
+
* A successful invocation indicates the platform has begun shutdown following procedure for the target AppProcessId, which:
|
|
16
|
+
* 1. Transitions process state to `CLOSING`, triggering all registered state change callbacks.
|
|
17
|
+
* 2. Invokes all registered onBeforeClose callbacks.
|
|
18
|
+
* 3. Waits for the process to close.
|
|
19
|
+
* 4. Transitions process state to `CLOSED`, triggering all registered state change callbacks.
|
|
20
|
+
* @remarks
|
|
21
|
+
* Once initiated, the closing process is irreversible and the process will NOT receive any events or messages from other processes.
|
|
22
|
+
*/
|
|
23
|
+
requestClose<T extends CloseParams>(
|
|
24
|
+
target: AppProcessId,
|
|
25
|
+
params: T
|
|
26
|
+
): Promise<void>;
|
|
27
|
+
/**
|
|
28
|
+
* @public
|
|
29
|
+
* Registers a callback to be executed when the state of the specified app process changes.
|
|
30
|
+
* @param target - The id of the app process for which to register the callback.
|
|
31
|
+
* @param callback - Callback function triggered on state change
|
|
32
|
+
* @returns a disposer function to unsubscribe the callback.
|
|
33
|
+
*/
|
|
34
|
+
registerOnStateChange(
|
|
35
|
+
target: AppProcessId,
|
|
36
|
+
callback: (opts: { state: ProcessState }) => void
|
|
37
|
+
): () => Promise<void>;
|
|
38
|
+
/**
|
|
39
|
+
* Registers a handler to receive messages sent from other app processes.
|
|
40
|
+
* @param callback - Handler function to receive incoming messages.
|
|
41
|
+
* @returns a disposer function to unsubscribe the handler.
|
|
42
|
+
*/
|
|
43
|
+
registerOnMessage(
|
|
44
|
+
callback: (
|
|
45
|
+
sender: {
|
|
46
|
+
appProcessId: AppProcessId;
|
|
47
|
+
surface: AppSurface;
|
|
48
|
+
},
|
|
49
|
+
message: any
|
|
50
|
+
) => void
|
|
51
|
+
): () => Promise<void>;
|
|
52
|
+
/**
|
|
53
|
+
* Broadcasts a message to all other running app processes which share the caller's AppId.
|
|
54
|
+
* @param message - app-defined message to be broadcast. message needs to be structured data.
|
|
55
|
+
*/
|
|
56
|
+
broadcastMessage(message: any): void;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* An alias for the AppProcess interface for interacting with the App Process.
|
|
61
|
+
* @public
|
|
62
|
+
*/
|
|
63
|
+
export declare const appProcess: AppProcess;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* @public
|
|
67
|
+
* The unique identifier for an app process.
|
|
68
|
+
*/
|
|
69
|
+
export declare type AppProcessId = string & {
|
|
70
|
+
__appProcessId: never;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* @public
|
|
75
|
+
* Information about an app process.
|
|
76
|
+
*/
|
|
77
|
+
export declare type AppProcessInfo<T> = {
|
|
78
|
+
/**
|
|
79
|
+
* The surface on which the app is running.
|
|
80
|
+
*/
|
|
81
|
+
surface: AppSurface;
|
|
82
|
+
/**
|
|
83
|
+
* The unique identifier of the app process.
|
|
84
|
+
*/
|
|
85
|
+
processId: AppProcessId;
|
|
86
|
+
/**
|
|
87
|
+
* The parameters provided to the app at the time of its process launch.
|
|
88
|
+
*/
|
|
89
|
+
launchParams?: T;
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* @public
|
|
94
|
+
* The types of surfaces that can run an app process.
|
|
95
|
+
*/
|
|
96
|
+
export declare type AppSurface =
|
|
97
|
+
/**
|
|
98
|
+
* The object panel on the left side of the editing UI.
|
|
99
|
+
*/
|
|
100
|
+
| "object_panel"
|
|
101
|
+
/**
|
|
102
|
+
* The overlay surface on top of a selected image in the design.
|
|
103
|
+
*/
|
|
104
|
+
| "selected_image_overlay";
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* @public
|
|
108
|
+
* The parameters specified when closing an app process.
|
|
109
|
+
* @remarks
|
|
110
|
+
* CloseParams are passed on to the callback function registered for handling the termination of an app process,
|
|
111
|
+
* and provide additional context for ending the process.
|
|
112
|
+
* For example, Apps should persist unsaved changes when the close reason is 'completed'.
|
|
113
|
+
*/
|
|
114
|
+
export declare type CloseParams = {
|
|
115
|
+
reason: CloseReason;
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* @public
|
|
120
|
+
* The reasons why an app process is closed.
|
|
121
|
+
*/
|
|
122
|
+
export declare type CloseReason =
|
|
123
|
+
/**
|
|
124
|
+
* Indicates the workflow is completed, for example, when user clicks a 'Save and Close' in the App.
|
|
125
|
+
* Any unsaved changes should be saved before closing.
|
|
126
|
+
*/
|
|
127
|
+
| "completed"
|
|
128
|
+
/**
|
|
129
|
+
* Indicates user has aborted the workflow, for example, when user clicked the 'cancel' button in the App.
|
|
130
|
+
* App should be closed without saving any current changes.
|
|
131
|
+
*/
|
|
132
|
+
| "aborted";
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* @public
|
|
136
|
+
* Represents and exposes functionality specific to the currently running app process.
|
|
137
|
+
*/
|
|
138
|
+
export declare type CurrentAppProcess = {
|
|
139
|
+
/**
|
|
140
|
+
* @public
|
|
141
|
+
* Retrieves information about the current app process.
|
|
142
|
+
*/
|
|
143
|
+
getInfo<T extends any>(): AppProcessInfo<T>;
|
|
144
|
+
/**
|
|
145
|
+
* @public
|
|
146
|
+
* Requests the current app process be closed.
|
|
147
|
+
* @param params - A parameters object passed to all callback functions registered via registerOnBeforeClose API for the current process.
|
|
148
|
+
* In addition to the required 'reason' field, app can choose to pass any structured data via params.
|
|
149
|
+
* @remarks
|
|
150
|
+
* A successful invocation indicates the platform has begun shutdown following procedure for the current process, which:
|
|
151
|
+
* 1. Transitions process state to `CLOSING`, triggering all registered state change callbacks.
|
|
152
|
+
* 2. Invokes all registered onBeforeClose callbacks.
|
|
153
|
+
* 3. Waits for the process to close.
|
|
154
|
+
* 4. Transitions process state to `CLOSED`, triggering all registered state change callbacks.
|
|
155
|
+
* @remarks
|
|
156
|
+
* Once initiated, the closing process is irreversible and the process will NOT receive any events or messages from other processes.
|
|
157
|
+
*/
|
|
158
|
+
requestClose<T extends CloseParams>(params: T): Promise<void>;
|
|
159
|
+
/**
|
|
160
|
+
* @public
|
|
161
|
+
* Registers a callback to be executed when the current app process is about to close.
|
|
162
|
+
* @remarks Only allow registering one callback.
|
|
163
|
+
* Subsequential invokes of the API will override the existing callback.
|
|
164
|
+
* The process remains open until the callback resolve or a timeout occurs.
|
|
165
|
+
* @param callback - The callback function to be invoked before closure.
|
|
166
|
+
* @returns a disposer function to unsubscribe the callback.
|
|
167
|
+
* @remarks Complete execution of the callback is not guaranteed. Certain user actions (e.g. closing tabs, top level navigation) may terminate app processes prematurely. Consider these callbacks **best effort only.**
|
|
168
|
+
*/
|
|
169
|
+
setOnDispose<T extends CloseParams>(
|
|
170
|
+
callback: OnDisposeCallback<T>
|
|
171
|
+
): () => Promise<void>;
|
|
172
|
+
};
|
|
173
|
+
|
|
1
174
|
/**
|
|
2
175
|
* @public
|
|
3
176
|
* Returns information about the platform on which the app is running.
|
|
4
177
|
*/
|
|
5
178
|
export declare function getPlatformInfo(): PlatformInfo;
|
|
6
179
|
|
|
180
|
+
/**
|
|
181
|
+
* @public
|
|
182
|
+
* The type of a callback that is invoked when an app process is being closed.
|
|
183
|
+
* @returns a promise.
|
|
184
|
+
*/
|
|
185
|
+
export declare type OnDisposeCallback<T extends CloseParams> = (
|
|
186
|
+
opts: T
|
|
187
|
+
) => Promise<void>;
|
|
188
|
+
|
|
7
189
|
/**
|
|
8
190
|
* @public
|
|
9
191
|
* The result of opening an external URL when a user chooses to not navigate away from Canva.
|
|
@@ -72,6 +254,29 @@ export declare type PlatformInfo = {
|
|
|
72
254
|
canAcceptPayments: boolean;
|
|
73
255
|
};
|
|
74
256
|
|
|
257
|
+
/**
|
|
258
|
+
* @public
|
|
259
|
+
* The states are an app process.
|
|
260
|
+
*/
|
|
261
|
+
export declare type ProcessState =
|
|
262
|
+
/**
|
|
263
|
+
* The app process is in the process of opening.
|
|
264
|
+
*/
|
|
265
|
+
| "opening"
|
|
266
|
+
/**
|
|
267
|
+
* The app process is active and visible to the user on its designated surface.
|
|
268
|
+
*/
|
|
269
|
+
| "open"
|
|
270
|
+
/**
|
|
271
|
+
* The app process is in the process of closing.
|
|
272
|
+
* At this state, the process becomes non-interactive and won't receive any events and messages from other processes.
|
|
273
|
+
*/
|
|
274
|
+
| "closing"
|
|
275
|
+
/**
|
|
276
|
+
* The app process has been terminated and is no longer running.
|
|
277
|
+
*/
|
|
278
|
+
| "closed";
|
|
279
|
+
|
|
75
280
|
/**
|
|
76
281
|
* @public
|
|
77
282
|
* Opens an external URL.
|
|
@@ -1,17 +1,19 @@
|
|
|
1
|
+
// Copyright 2023 Canva Inc. All Rights Reserved.
|
|
1
2
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
_export_star(require("./public"), exports);
|
|
7
|
+
function _export_star(from, to) {
|
|
8
|
+
Object.keys(from).forEach(function(k) {
|
|
9
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
|
10
|
+
Object.defineProperty(to, k, {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function() {
|
|
13
|
+
return from[k];
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
return from;
|
|
19
|
+
}
|
|
@@ -1,25 +1,30 @@
|
|
|
1
|
+
// Copyright 2023 Canva Inc. All Rights Reserved.
|
|
1
2
|
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
function _export(target, all) {
|
|
7
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: all[name]
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
_export(exports, {
|
|
13
|
+
appProcess: function() {
|
|
14
|
+
return appProcess;
|
|
15
|
+
},
|
|
16
|
+
requestOpenExternalUrl: function() {
|
|
17
|
+
return requestOpenExternalUrl;
|
|
18
|
+
},
|
|
19
|
+
getPlatformInfo: function() {
|
|
20
|
+
return getPlatformInfo;
|
|
21
|
+
}
|
|
22
|
+
});
|
|
4
23
|
const { canva } = window;
|
|
5
|
-
|
|
6
|
-
* @public
|
|
7
|
-
* Opens an external URL.
|
|
8
|
-
*
|
|
9
|
-
* @remarks
|
|
10
|
-
* The URL is opened natively, such as in a new browser tab on desktop or in a browser sheet on mobile.
|
|
11
|
-
*
|
|
12
|
-
* In some browsers, the user must enable popup permissions before any URL can be opened.
|
|
13
|
-
*/
|
|
24
|
+
const appProcess = canva.appProcess;
|
|
14
25
|
function requestOpenExternalUrl(request) {
|
|
15
26
|
return canva.platform.requestOpenExternalUrl(request);
|
|
16
27
|
}
|
|
17
|
-
exports.requestOpenExternalUrl = requestOpenExternalUrl;
|
|
18
|
-
/**
|
|
19
|
-
* @public
|
|
20
|
-
* Returns information about the platform on which the app is running.
|
|
21
|
-
*/
|
|
22
28
|
function getPlatformInfo() {
|
|
23
29
|
return canva.platform.getPlatformInfo();
|
|
24
30
|
}
|
|
25
|
-
exports.getPlatformInfo = getPlatformInfo;
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
+
// Copyright 2023 Canva Inc. All Rights Reserved.
|
|
1
2
|
const { canva } = window;
|
|
3
|
+
/**
|
|
4
|
+
* An alias for the AppProcess interface for interacting with the App Process.
|
|
5
|
+
* @public
|
|
6
|
+
*/ export const appProcess = canva.appProcess;
|
|
2
7
|
/**
|
|
3
8
|
* @public
|
|
4
9
|
* Opens an external URL.
|
|
@@ -7,14 +12,12 @@ const { canva } = window;
|
|
|
7
12
|
* The URL is opened natively, such as in a new browser tab on desktop or in a browser sheet on mobile.
|
|
8
13
|
*
|
|
9
14
|
* In some browsers, the user must enable popup permissions before any URL can be opened.
|
|
10
|
-
*/
|
|
11
|
-
export function requestOpenExternalUrl(request) {
|
|
15
|
+
*/ export function requestOpenExternalUrl(request) {
|
|
12
16
|
return canva.platform.requestOpenExternalUrl(request);
|
|
13
17
|
}
|
|
14
18
|
/**
|
|
15
19
|
* @public
|
|
16
20
|
* Returns information about the platform on which the app is running.
|
|
17
|
-
*/
|
|
18
|
-
export function getPlatformInfo() {
|
|
21
|
+
*/ export function getPlatformInfo() {
|
|
19
22
|
return canva.platform.getPlatformInfo();
|
|
20
23
|
}
|