@canva/design 2.7.3-beta.0 → 2.7.3

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.
@@ -1015,16 +1015,11 @@ export declare interface ContentDraft<T> {
1015
1015
  save(): Promise<void>;
1016
1016
  }
1017
1017
 
1018
- /**
1019
- * @beta
1020
- */
1021
- export declare type ContentType = "richtext" | "fill";
1022
-
1023
1018
  /**
1024
1019
  * @public
1025
1020
  * A type of content that can be read from a user's design.
1026
1021
  */
1027
- declare type ContentType_2 = "richtext";
1022
+ export declare type ContentType = "richtext";
1028
1023
 
1029
1024
  /**
1030
1025
  * @public
@@ -1587,9 +1582,9 @@ export declare namespace DesignEditing {
1587
1582
  };
1588
1583
  /**
1589
1584
  * @public
1590
- * The result of reading part of a design when the context is the current page.
1585
+ * Session received by the `openDesign` callback when opening the current page.
1591
1586
  */
1592
- export type CurrentPageResult<
1587
+ export type CurrentPageSession<
1593
1588
  Page = DesignEditing.Page,
1594
1589
  Helpers = DesignEditing.PageHelpers,
1595
1590
  > = Readonly<{
@@ -1602,7 +1597,7 @@ export declare namespace DesignEditing {
1602
1597
  */
1603
1598
  helpers: Helpers;
1604
1599
  /**
1605
- * Saves any changes made during the session while keeping the transaction open.
1600
+ * Saves any changes made during the session while keeping the session open.
1606
1601
  *
1607
1602
  * @remarks
1608
1603
  * - Any changes in the session are only reflected in the design after this method is called.
@@ -1610,13 +1605,19 @@ export declare namespace DesignEditing {
1610
1605
  */
1611
1606
  sync(): Promise<void>;
1612
1607
  }>;
1608
+ /**
1609
+ * @deprecated The type has been superseded by `CurrentPageSession`.
1610
+ * @public
1611
+ * Session received by the `openDesign` callback when opening the current page.
1612
+ */
1613
+ export type CurrentPageResult = CurrentPageSession;
1614
+
1613
1615
  /**
1614
1616
  * A function called for each item in the list.
1615
1617
  *
1616
1618
  * @param item - The current item in the list.
1617
- * @param index - The index of the current item.
1618
1619
  */
1619
- export type ForEachCallback<M> = (item: M, index: number) => void;
1620
+ export type ForEachCallback<M> = (item: M) => void;
1620
1621
  /**
1621
1622
  * A function that determines if an item should be included in the result.
1622
1623
  *
@@ -1736,6 +1737,7 @@ export declare namespace DesignEditing {
1736
1737
  ): U[];
1737
1738
  readonly length: number;
1738
1739
  readonly [n: number]: T;
1740
+ at(index: number): T | undefined;
1739
1741
  }
1740
1742
  /**
1741
1743
  * @public
@@ -2692,10 +2694,10 @@ export declare type DesignMetadata = {
2692
2694
  /**
2693
2695
  * @public
2694
2696
  * A callback for reading and updating part of a design.
2695
- * @param session - The result of reading part of a design.
2697
+ * @param session - Session received by the `openDesign` callback.
2696
2698
  */
2697
2699
  export declare type DesignOpenCallback = (
2698
- session: DesignEditing.CurrentPageResult,
2700
+ session: DesignEditing.CurrentPageSession,
2699
2701
  ) => Promise<void>;
2700
2702
 
2701
2703
  /**
@@ -2926,53 +2928,39 @@ export declare type DragStartEvent<E extends Element> = Pick<
2926
2928
  };
2927
2929
 
2928
2930
  /**
2929
- * @beta
2930
- * Reads and edits richtext content from the user's design.
2931
- * @param options - Options for configuring how a design is read. Must specify `contentType: 'richtext'`.
2932
- * @param callback - A callback that receives a `RichtextContentSession` for editing.
2933
- * @returns A promise that resolves when editing is complete.
2934
- */
2935
- export declare function editContent(
2936
- options: EditContentOptions & {
2937
- contentType: "richtext";
2938
- },
2939
- callback: (session: RichtextContentSession) => Promise<void> | void,
2940
- ): Promise<void>;
2941
-
2942
- /**
2943
- * @beta
2944
- * Reads and edits fill content from the user's design.
2945
- * @param options - Options for configuring how a design is read. Must specify `contentType: 'fill'`.
2946
- * @param callback - A callback that receives a `FillContentSession` for editing.
2947
- * @returns A promise that resolves when editing is complete.
2948
- */
2949
- export declare function editContent(
2950
- options: EditContentOptions & {
2951
- contentType: "fill";
2952
- },
2953
- callback: (session: FillContentSession) => Promise<void> | void,
2954
- ): Promise<void>;
2955
-
2956
- /**
2957
- * @beta
2958
- * A callback for reading and updating the requested design content.
2959
- * @param session - Session for reading and updating content in the design.
2931
+ * @public
2932
+ * Reads and edits content of the specified type from the user's design.
2933
+ * @param options - Options for configuring how a design is read.
2934
+ * @param callback - A callback for operating on the read content.
2935
+ *
2936
+ * @example Read richtext content
2937
+ * ```typescript
2938
+ * import { editContent } from "@canva/design";
2939
+ *
2940
+ * await editContent(
2941
+ * { contentType: 'richtext', target: 'current_page' },
2942
+ * async (session) => {
2943
+ * // Do something with the richtext content, e.g. `session.contents`
2944
+ * }
2945
+ * );
2946
+ * ```
2960
2947
  */
2961
- export declare type EditContentCallback = (
2962
- session: RichtextContentSession | FillContentSession,
2963
- ) => Promise<void> | void;
2948
+ export declare const editContent: (
2949
+ options: EditContentOptions,
2950
+ callback: EditContentCallback,
2951
+ ) => Promise<void>;
2964
2952
 
2965
2953
  /**
2966
2954
  * @public
2967
2955
  * A callback for reading and updating the requested design content.
2968
2956
  * @param session - The result of reading the content in the design.
2969
2957
  */
2970
- declare type EditContentCallback_2 = (
2958
+ export declare type EditContentCallback = (
2971
2959
  session: RichtextContentSession,
2972
2960
  ) => Promise<void> | void;
2973
2961
 
2974
2962
  /**
2975
- * @beta
2963
+ * @public
2976
2964
  * Options for configuring how the design content is read.
2977
2965
  */
2978
2966
  export declare type EditContentOptions = {
@@ -2982,17 +2970,6 @@ export declare type EditContentOptions = {
2982
2970
  contentType: ContentType;
2983
2971
  } & ContextOptions;
2984
2972
 
2985
- /**
2986
- * @public
2987
- * Options for configuring how the design content is read.
2988
- */
2989
- declare type EditContentOptions_2 = {
2990
- /**
2991
- * The type of content to edit from the user's design
2992
- */
2993
- contentType: ContentType_2;
2994
- } & ContextOptions;
2995
-
2996
2973
  /**
2997
2974
  * @public
2998
2975
  * Elements targeting a cursor are a subset of the base Element
@@ -3223,67 +3200,6 @@ export declare type Fill = {
3223
3200
  asset?: ImageFill | VideoFill;
3224
3201
  };
3225
3202
 
3226
- /**
3227
- * @beta
3228
- * Object for interacting with fill content (images/videos).
3229
- */
3230
- export declare type FillContent =
3231
- | {
3232
- type: "image";
3233
- /**
3234
- * A unique identifier that points to an image asset in Canva's backend.
3235
- */
3236
- ref: ImageRef;
3237
- /**
3238
- * A description of the image content.
3239
- *
3240
- * @remarks
3241
- * Use `undefined` for content with no description.
3242
- */
3243
- altText?: AltText;
3244
- /**
3245
- * Indicates whether the object containing this fill has been deleted.
3246
- */
3247
- deleted: boolean;
3248
- }
3249
- | {
3250
- type: "video";
3251
- /**
3252
- * A unique identifier that points to an video asset in Canva's backend.
3253
- */
3254
- ref: VideoRef;
3255
- /**
3256
- * A description of the video content.
3257
- *
3258
- * @remarks
3259
- * Use `undefined` for content with no description.
3260
- */
3261
- altText?: AltText;
3262
- /**
3263
- * Indicates whether the object containing this fill has been deleted.
3264
- */
3265
- deleted: boolean;
3266
- };
3267
-
3268
- /**
3269
- * @beta
3270
- * Session for reading and updating fill content in a user's design.
3271
- */
3272
- export declare interface FillContentSession {
3273
- /**
3274
- * Fill content in the design.
3275
- */
3276
- readonly contents: readonly FillContent[];
3277
- /**
3278
- * Saves any changes made during the session while keeping the transaction open.
3279
- *
3280
- * @remarks
3281
- * - Any changes in the session are only reflected in the design after this method is called.
3282
- * - Once this method is called, further changes in the session can still be made.
3283
- */
3284
- sync(): Promise<void>;
3285
- }
3286
-
3287
3203
  /**
3288
3204
  * @public
3289
3205
  * A reference to a font that can be used in other parts of the SDK.
@@ -4914,11 +4830,6 @@ export declare type TextDragConfig = {
4914
4830
  * @defaultValue "none"
4915
4831
  */
4916
4832
  decoration?: "none" | "underline";
4917
- /**
4918
- * @beta
4919
- * A unique identifier that points to a font asset in Canva's backend.
4920
- */
4921
- fontRef?: FontRef;
4922
4833
  };
4923
4834
 
4924
4835
  /**
@@ -2,10 +2,21 @@
2
2
  Object.defineProperty(exports, "__esModule", {
3
3
  value: true
4
4
  });
5
- Object.defineProperty(exports, "FakeDesignInteractionClient", {
6
- enumerable: true,
7
- get: function() {
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 FakeDesignInteractionClient () {
8
13
  return FakeDesignInteractionClient;
14
+ },
15
+ get fakeOpenDesignHelpers () {
16
+ return fakeOpenDesignHelpers;
17
+ },
18
+ get fakePage () {
19
+ return fakePage;
9
20
  }
10
21
  });
11
22
  class FakeDesignInteractionClient {
@@ -114,14 +125,7 @@ class FakeDesignInteractionClient {
114
125
  sync: async ()=>{
115
126
  await this.delay();
116
127
  },
117
- helpers: {
118
- elementStateBuilder: fakeElementStateBuilder,
119
- group: fakeAsyncOperations.group,
120
- ungroup: fakeAsyncOperations.ungroup,
121
- snapshot: ()=>{
122
- return {};
123
- }
124
- }
128
+ helpers: fakeOpenDesignHelpers
125
129
  });
126
130
  }
127
131
  constructor(delay){
@@ -360,3 +364,11 @@ const fakeAsyncOperations = {
360
364
  ];
361
365
  }
362
366
  };
367
+ const fakeOpenDesignHelpers = {
368
+ elementStateBuilder: fakeElementStateBuilder,
369
+ group: fakeAsyncOperations.group,
370
+ ungroup: fakeAsyncOperations.ungroup,
371
+ snapshot: ()=>{
372
+ return {};
373
+ }
374
+ };
@@ -2,7 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", {
3
3
  value: true
4
4
  });
5
- _export_star(require("./index"), exports);
5
+ const _version = require("./version");
6
+ _export_star(require("./public"), exports);
6
7
  function _export_star(from, to) {
7
8
  Object.keys(from).forEach(function(k) {
8
9
  if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
@@ -16,3 +17,4 @@ function _export_star(from, to) {
16
17
  });
17
18
  return from;
18
19
  }
20
+ window.__canva__?.sdkRegistration?.registerPackageVersion('design', _version.LATEST_VERSION, 'ga');
@@ -0,0 +1,11 @@
1
+ "use strict"
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "LATEST_VERSION", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return LATEST_VERSION;
9
+ }
10
+ });
11
+ const LATEST_VERSION = '2.7.3';
@@ -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/"
@@ -104,14 +104,7 @@ export class FakeDesignInteractionClient {
104
104
  sync: async ()=>{
105
105
  await this.delay();
106
106
  },
107
- helpers: {
108
- elementStateBuilder: fakeElementStateBuilder,
109
- group: fakeAsyncOperations.group,
110
- ungroup: fakeAsyncOperations.ungroup,
111
- snapshot: ()=>{
112
- return {};
113
- }
114
- }
107
+ helpers: fakeOpenDesignHelpers
115
108
  });
116
109
  }
117
110
  constructor(delay){
@@ -202,7 +195,7 @@ const fakeElementList = {
202
195
  return fakeRectElement;
203
196
  }
204
197
  };
205
- const fakePage = {
198
+ export const fakePage = {
206
199
  type: 'absolute',
207
200
  locked: false,
208
201
  dimensions: fakePageDimensions,
@@ -350,3 +343,11 @@ const fakeAsyncOperations = {
350
343
  ];
351
344
  }
352
345
  };
346
+ export const fakeOpenDesignHelpers = {
347
+ elementStateBuilder: fakeElementStateBuilder,
348
+ group: fakeAsyncOperations.group,
349
+ ungroup: fakeAsyncOperations.ungroup,
350
+ snapshot: ()=>{
351
+ return {};
352
+ }
353
+ };
@@ -0,0 +1,3 @@
1
+ import { LATEST_VERSION } from './version';
2
+ export * from './public';
3
+ window.__canva__?.sdkRegistration?.registerPackageVersion('design', LATEST_VERSION, 'ga');
@@ -0,0 +1 @@
1
+ export const LATEST_VERSION = '2.7.3';
@@ -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,25 +1,25 @@
1
1
  {
2
2
  "name": "@canva/design",
3
- "version": "2.7.3-beta.0",
3
+ "version": "2.7.3",
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": "^2.0.0"
9
9
  },
10
- "main": "./lib/cjs/sdk/design/beta.js",
11
- "module": "./lib/esm/sdk/design/beta.js",
10
+ "main": "./lib/cjs/sdk/design/index.js",
11
+ "module": "./lib/esm/sdk/design/index.js",
12
12
  "exports": {
13
13
  ".": {
14
- "types": "./beta.d.ts",
15
- "require": "./lib/cjs/sdk/design/beta.js",
16
- "import": "./lib/esm/sdk/design/beta.js"
14
+ "types": "./index.d.ts",
15
+ "require": "./lib/cjs/sdk/design/index.js",
16
+ "import": "./lib/esm/sdk/design/index.js"
17
17
  },
18
18
  "./test": {
19
- "types": "./test/beta.d.ts",
20
- "require": "./lib/cjs/sdk/design/test/beta.js",
21
- "import": "./lib/esm/sdk/design/test/beta.js"
19
+ "types": "./test/index.d.ts",
20
+ "require": "./lib/cjs/sdk/design/test/index.js",
21
+ "import": "./lib/esm/sdk/design/test/index.js"
22
22
  }
23
23
  },
24
- "typings": "./beta.d.ts"
24
+ "typings": "./index.d.ts"
25
25
  }
@@ -1,30 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "editContent", {
6
- enumerable: true,
7
- get: function() {
8
- return editContent;
9
- }
10
- });
11
- _export_star(require("./public"), exports);
12
- function _export_star(from, to) {
13
- Object.keys(from).forEach(function(k) {
14
- if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
15
- Object.defineProperty(to, k, {
16
- enumerable: true,
17
- get: function() {
18
- return from[k];
19
- }
20
- });
21
- }
22
- });
23
- return from;
24
- }
25
- var _window___canva___sdkRegistration, _window___canva__;
26
- const { canva_sdk } = window;
27
- function editContent(options, callback) {
28
- return canva_sdk.design.v2.designInteraction.editContent(options, (session)=>callback(session));
29
- }
30
- (_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('design', '2.7.2', 'beta');
@@ -1,7 +0,0 @@
1
- var _window___canva___sdkRegistration, _window___canva__;
2
- const { canva_sdk } = window;
3
- export function editContent(options, callback) {
4
- return canva_sdk.design.v2.designInteraction.editContent(options, (session)=>callback(session));
5
- }
6
- export * from './public';
7
- (_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('design', '2.7.2', 'beta');
@@ -1 +0,0 @@
1
- export * from './index';
File without changes