@canva/design 1.6.0 → 1.8.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 CHANGED
@@ -97,10 +97,15 @@ export declare type AppElementRenderer<A extends AppElementData> = (
97
97
  * A return value of {@link AppElementRenderer} function.
98
98
  * It is an array of elements to render within an app element.
99
99
  */
100
- export declare type AppElementRendererOutput = Exclude<
101
- NativeSimpleElementWithBox,
102
- NativeVideoElementWithBox
103
- >[];
100
+ export declare type AppElementRendererOutput = NativeSimpleElementWithBox[];
101
+
102
+ /**
103
+ * @public
104
+ * A unique identifier that references an app runtime process
105
+ */
106
+ export declare type AppProcessId = string & {
107
+ __appProcessId: never;
108
+ };
104
109
 
105
110
  /**
106
111
  * @public
@@ -208,6 +213,23 @@ export declare type Coordinates = {
208
213
  y: number;
209
214
  };
210
215
 
216
+ /**
217
+ * @public
218
+ * Provides methods for interacting with design overlay
219
+ */
220
+ export declare type DesignOverlay = {
221
+ /**
222
+ * Registers a callback that runs when an overlay canOpen status changed on a particular target.
223
+ *
224
+ * @remarks
225
+ * The callback fires immediately
226
+ */
227
+ registerOnCanOpen<Target extends OverlayTarget>(opts: {
228
+ target: Target;
229
+ onCanOpen(event: OverlayOpenableEvent<Target>): void;
230
+ }): () => void;
231
+ };
232
+
211
233
  /**
212
234
  * @public
213
235
  * Provides methods for interacting with the user's selected content, such as images or text.
@@ -231,6 +253,14 @@ export declare type DesignSelection = {
231
253
  }): () => void;
232
254
  };
233
255
 
256
+ /**
257
+ * @public
258
+ * JWT that contains the Design ID and App ID.
259
+ */
260
+ export declare type DesignToken = {
261
+ token: string;
262
+ };
263
+
234
264
  /**
235
265
  * @public
236
266
  * Represents a width and a height.
@@ -537,6 +567,12 @@ export declare function getDefaultPageDimensions(): Promise<
537
567
  Dimensions | undefined
538
568
  >;
539
569
 
570
+ /**
571
+ * @public
572
+ * Retrieves a signed JWT that contains the Design ID, App ID and User ID.
573
+ */
574
+ export declare function getDesignToken(): Promise<DesignToken>;
575
+
540
576
  declare type Height = {
541
577
  width: "auto";
542
578
  height: number;
@@ -927,6 +963,51 @@ export declare type NativeVideoElementWithBox = NativeVideoElement & Box;
927
963
  */
928
964
  declare type ObjectPrimitive = Boolean | String;
929
965
 
966
+ /**
967
+ * @public
968
+ * An alias for the DesignOverlay interface, providing access to design overlay related functionality
969
+ */
970
+ export declare const overlay: DesignOverlay;
971
+
972
+ /**
973
+ * @public
974
+ * Information about whether the overlay can be opened or not on a particular {@link OverlayTarget}
975
+ */
976
+ export declare type OverlayOpenableEvent<Target extends OverlayTarget> = {
977
+ /**
978
+ * An event indicating whether the overlay can be opened or not when {@link OverlayTarget} is `"image_selection"`
979
+ */
980
+ ["image_selection"]:
981
+ | OverlayUnopenableEvent
982
+ | {
983
+ canOpen: true;
984
+ /**
985
+ * Launch a new app process on an overlay on top of the current selected image fill
986
+ *
987
+ * @remarks
988
+ * `launchParameters` specifies the type of data that are provided to an app process at its launch
989
+ */
990
+ readonly open: (options: {
991
+ launchParameters?: any;
992
+ }) => Promise<AppProcessId>;
993
+ };
994
+ }[Target];
995
+
996
+ /**
997
+ * @public
998
+ * The target to check if an overlay can be opened for
999
+ */
1000
+ export declare type OverlayTarget = "image_selection";
1001
+
1002
+ /**
1003
+ * @public
1004
+ * Information about the overlay when it can not be opened on a particular {@link OverlayTarget}
1005
+ */
1006
+ declare type OverlayUnopenableEvent = {
1007
+ canOpen: false;
1008
+ reason: string;
1009
+ };
1010
+
930
1011
  /**
931
1012
  * @public
932
1013
  * The appearance of a page's background.
@@ -1185,7 +1266,7 @@ export declare type TextAttributes = {
1185
1266
  * The alignment of the text.
1186
1267
  * @defaultValue 'start'
1187
1268
  */
1188
- textAlign?: "start" | "center" | "end";
1269
+ textAlign?: "start" | "center" | "end" | "justify";
1189
1270
  /**
1190
1271
  * The color of the text as a hex code.
1191
1272
  *
@@ -1233,7 +1314,7 @@ export declare type TextDragConfig = {
1233
1314
  * The alignment of the text.
1234
1315
  * @defaultValue 'start'
1235
1316
  */
1236
- textAlign?: "start" | "center" | "end";
1317
+ textAlign?: "start" | "center" | "end" | "justify";
1237
1318
  /**
1238
1319
  * The weight of the font.
1239
1320
  * @defaultValue 'normal'
@@ -1,17 +1,19 @@
1
+ // Copyright 2023 Canva Inc. All Rights Reserved.
1
2
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./public"), exports);
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,89 +1,80 @@
1
+ // Copyright 2023 Canva Inc. All Rights Reserved.
1
2
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.initAppElement = exports.getCurrentPageContext = exports.addAudioTrack = exports.addNativeElement = exports.ui = exports.requestExport = exports.getDefaultPageDimensions = exports.setCurrentPageBackground = exports.addPage = exports.selection = void 0;
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
+ selection: function() {
14
+ return selection;
15
+ },
16
+ overlay: function() {
17
+ return overlay;
18
+ },
19
+ addPage: function() {
20
+ return addPage;
21
+ },
22
+ setCurrentPageBackground: function() {
23
+ return setCurrentPageBackground;
24
+ },
25
+ getDefaultPageDimensions: function() {
26
+ return getDefaultPageDimensions;
27
+ },
28
+ requestExport: function() {
29
+ return requestExport;
30
+ },
31
+ ui: function() {
32
+ return ui;
33
+ },
34
+ addNativeElement: function() {
35
+ return addNativeElement;
36
+ },
37
+ addAudioTrack: function() {
38
+ return addAudioTrack;
39
+ },
40
+ getCurrentPageContext: function() {
41
+ return getCurrentPageContext;
42
+ },
43
+ initAppElement: function() {
44
+ return initAppElement;
45
+ },
46
+ getDesignToken: function() {
47
+ return getDesignToken;
48
+ }
49
+ });
4
50
  const { canva } = window;
5
- /**
6
- * @public
7
- * An alias for the DesignSelection interface, providing access to design selection related functionality
8
- */
9
- exports.selection = canva.designInteraction.selection;
10
- /**
11
- * @public
12
- * Adds a new page immediately after the currently selected page.
13
- * @param opts - Configuration for the new page to be added.
14
- */
51
+ const selection = canva.designInteraction.selection;
52
+ const overlay = canva.designInteraction.overlay;
15
53
  function addPage(opts) {
16
54
  return canva.designInteraction.addPage(opts);
17
55
  }
18
- exports.addPage = addPage;
19
- /**
20
- * @public
21
- * Updates the background of the user's current page. The background can be a solid color,
22
- * an image or a video.
23
- */
24
56
  function setCurrentPageBackground(opts) {
25
57
  return canva.designInteraction.setCurrentPageBackground(opts);
26
58
  }
27
- exports.setCurrentPageBackground = setCurrentPageBackground;
28
- /**
29
- * @public
30
- * Gets the default dimensions that a new page will have when it is added to a design.
31
- * It is possible for a user to resize a page without resizing the entire design, e.g. by clicking
32
- * "Expand to Whiteboard". However, there will always be a single set of default dimensions for a
33
- * design that is applied whenever a new page is created.
34
- *
35
- * Returns `undefined` if the design is unbounded (e.g. Whiteboard or Doc).
36
- */
37
59
  function getDefaultPageDimensions() {
38
60
  return canva.designInteraction.getDefaultPageDimensions();
39
61
  }
40
- exports.getDefaultPageDimensions = getDefaultPageDimensions;
41
- /**
42
- * @public
43
- * Exports the user's design as one or more static files.
44
- * @param request - The request object containing configurations of the design export.
45
- */
46
62
  function requestExport(request) {
47
63
  return canva.export.requestExport(request);
48
64
  }
49
- exports.requestExport = requestExport;
50
- /**
51
- * An alias for the UI interface, providing access to ui related functionality
52
- * @public
53
- */
54
- exports.ui = canva.dragAndDrop;
55
- /**
56
- * @public
57
- * Adds a native element to the user's design.
58
- * @param element - The element to add to the user's design.
59
- */
65
+ const ui = canva.dragAndDrop;
60
66
  function addNativeElement(element) {
61
67
  return canva.designInteraction.addNativeElement(element);
62
68
  }
63
- exports.addNativeElement = addNativeElement;
64
- /**
65
- * Adds an audio track to the user's design.
66
- * @public
67
- * @param audioTrack - The audio track to add to the user's design.
68
- */
69
69
  function addAudioTrack(audioTrack) {
70
70
  return canva.designInteraction.addAudioTrack(audioTrack);
71
71
  }
72
- exports.addAudioTrack = addAudioTrack;
73
- /**
74
- * Allows to get the context of currently selected page.
75
- * @public
76
- * @returns Page context of currently selected page
77
- */
78
72
  function getCurrentPageContext() {
79
73
  return canva.designInteraction.getCurrentPageContext();
80
74
  }
81
- exports.getCurrentPageContext = getCurrentPageContext;
82
- /**
83
- * @public
84
- * @param appElementConfig - Configuration for an AppElementClient
85
- */
86
75
  function initAppElement(appElementConfig) {
87
76
  return canva.designInteraction.initAppElement(appElementConfig);
88
77
  }
89
- exports.initAppElement = initAppElement;
78
+ function getDesignToken() {
79
+ return canva.designInteraction.getDesignToken();
80
+ }
@@ -1 +1,2 @@
1
+ // Copyright 2023 Canva Inc. All Rights Reserved.
1
2
  export * from './public';
@@ -1,23 +1,25 @@
1
+ // Copyright 2023 Canva Inc. All Rights Reserved.
1
2
  const { canva } = window;
2
3
  /**
3
4
  * @public
4
5
  * An alias for the DesignSelection interface, providing access to design selection related functionality
5
- */
6
- export const selection = canva.designInteraction.selection;
6
+ */ export const selection = canva.designInteraction.selection;
7
+ /**
8
+ * @public
9
+ * An alias for the DesignOverlay interface, providing access to design overlay related functionality
10
+ */ export const overlay = canva.designInteraction.overlay;
7
11
  /**
8
12
  * @public
9
13
  * Adds a new page immediately after the currently selected page.
10
14
  * @param opts - Configuration for the new page to be added.
11
- */
12
- export function addPage(opts) {
15
+ */ export function addPage(opts) {
13
16
  return canva.designInteraction.addPage(opts);
14
17
  }
15
18
  /**
16
19
  * @public
17
20
  * Updates the background of the user's current page. The background can be a solid color,
18
21
  * an image or a video.
19
- */
20
- export function setCurrentPageBackground(opts) {
22
+ */ export function setCurrentPageBackground(opts) {
21
23
  return canva.designInteraction.setCurrentPageBackground(opts);
22
24
  }
23
25
  /**
@@ -28,51 +30,50 @@ export function setCurrentPageBackground(opts) {
28
30
  * design that is applied whenever a new page is created.
29
31
  *
30
32
  * Returns `undefined` if the design is unbounded (e.g. Whiteboard or Doc).
31
- */
32
- export function getDefaultPageDimensions() {
33
+ */ export function getDefaultPageDimensions() {
33
34
  return canva.designInteraction.getDefaultPageDimensions();
34
35
  }
35
36
  /**
36
37
  * @public
37
38
  * Exports the user's design as one or more static files.
38
39
  * @param request - The request object containing configurations of the design export.
39
- */
40
- export function requestExport(request) {
40
+ */ export function requestExport(request) {
41
41
  return canva.export.requestExport(request);
42
42
  }
43
43
  /**
44
44
  * An alias for the UI interface, providing access to ui related functionality
45
45
  * @public
46
- */
47
- export const ui = canva.dragAndDrop;
46
+ */ export const ui = canva.dragAndDrop;
48
47
  /**
49
48
  * @public
50
49
  * Adds a native element to the user's design.
51
50
  * @param element - The element to add to the user's design.
52
- */
53
- export function addNativeElement(element) {
51
+ */ export function addNativeElement(element) {
54
52
  return canva.designInteraction.addNativeElement(element);
55
53
  }
56
54
  /**
57
55
  * Adds an audio track to the user's design.
58
56
  * @public
59
57
  * @param audioTrack - The audio track to add to the user's design.
60
- */
61
- export function addAudioTrack(audioTrack) {
58
+ */ export function addAudioTrack(audioTrack) {
62
59
  return canva.designInteraction.addAudioTrack(audioTrack);
63
60
  }
64
61
  /**
65
62
  * Allows to get the context of currently selected page.
66
63
  * @public
67
64
  * @returns Page context of currently selected page
68
- */
69
- export function getCurrentPageContext() {
65
+ */ export function getCurrentPageContext() {
70
66
  return canva.designInteraction.getCurrentPageContext();
71
67
  }
72
68
  /**
73
69
  * @public
74
70
  * @param appElementConfig - Configuration for an AppElementClient
75
- */
76
- export function initAppElement(appElementConfig) {
71
+ */ export function initAppElement(appElementConfig) {
77
72
  return canva.designInteraction.initAppElement(appElementConfig);
78
73
  }
74
+ /**
75
+ * @public
76
+ * Retrieves a signed JWT that contains the Design ID, App ID and User ID.
77
+ */ export function getDesignToken() {
78
+ return canva.designInteraction.getDesignToken();
79
+ }
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "@canva/design",
3
- "version": "1.6.0",
3
+ "version": "1.8.0",
4
4
  "description": "The Canva Apps SDK design library",
5
5
  "author": "Canva Pty Ltd.",
6
6
  "license": "SEE LICENSE IN LICENSE.md FILE",
7
7
  "peerDependencies": {
8
8
  "@canva/error": "^1.0.0"
9
9
  },
10
+ "packageManager": "yarn@1.13.0",
10
11
  "main": "lib/cjs/sdk/design/index.js",
11
12
  "module": "lib/esm/sdk/design/index.js",
12
13
  "exports": {
@@ -16,4 +17,4 @@
16
17
  }
17
18
  },
18
19
  "typings": "./index.d.ts"
19
- }
20
+ }