@canva/design 2.7.3-beta.0 → 2.7.4-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/beta.d.ts CHANGED
@@ -1026,6 +1026,14 @@ export declare type ContentType = "richtext" | "fill";
1026
1026
  */
1027
1027
  declare type ContentType_2 = "richtext";
1028
1028
 
1029
+ /**
1030
+ * @beta
1031
+ */
1032
+ export declare type ContentTypeMap = {
1033
+ richtext: RichtextContentSession;
1034
+ fill: FillContentSession;
1035
+ };
1036
+
1029
1037
  /**
1030
1038
  * @public
1031
1039
  * Options for configuring where content in a design should be queried from.
@@ -1587,9 +1595,9 @@ export declare namespace DesignEditing {
1587
1595
  };
1588
1596
  /**
1589
1597
  * @public
1590
- * The result of reading part of a design when the context is the current page.
1598
+ * Session received by the `openDesign` callback when opening the current page.
1591
1599
  */
1592
- export type CurrentPageResult<
1600
+ export type CurrentPageSession<
1593
1601
  Page = DesignEditing.Page,
1594
1602
  Helpers = DesignEditing.PageHelpers,
1595
1603
  > = Readonly<{
@@ -1602,7 +1610,7 @@ export declare namespace DesignEditing {
1602
1610
  */
1603
1611
  helpers: Helpers;
1604
1612
  /**
1605
- * Saves any changes made during the session while keeping the transaction open.
1613
+ * Saves any changes made during the session while keeping the session open.
1606
1614
  *
1607
1615
  * @remarks
1608
1616
  * - Any changes in the session are only reflected in the design after this method is called.
@@ -1610,13 +1618,107 @@ export declare namespace DesignEditing {
1610
1618
  */
1611
1619
  sync(): Promise<void>;
1612
1620
  }>;
1621
+ /**
1622
+ * @deprecated The type has been superseded by `CurrentPageSession`.
1623
+ * @public
1624
+ * Session received by the `openDesign` callback when opening the current page.
1625
+ */
1626
+ export type CurrentPageResult = CurrentPageSession;
1627
+ /**
1628
+ * @beta
1629
+ * The response from `openPage` indicating whether the callback was executed.
1630
+ */
1631
+ export type OpenPageResponse =
1632
+ | OpenPageCallbackExecuted
1633
+ | OpenPageCallbackSkipped;
1634
+ /**
1635
+ * @beta
1636
+ * The response from `openPage` if the callback was executed.
1637
+ */
1638
+ export type OpenPageCallbackExecuted = {
1639
+ status: "executed";
1640
+ };
1641
+ /**
1642
+ * @beta
1643
+ * The response from `openPage` if the callback was not executed.
1644
+ */
1645
+ export type OpenPageCallbackSkipped = {
1646
+ status: "skipped";
1647
+ /**
1648
+ * Reason that the callback was not executed.
1649
+ */
1650
+ reason: string;
1651
+ };
1652
+ /**
1653
+ * @beta
1654
+ * Helpers for use when reading all pages of the design.
1655
+ *
1656
+ * @preventInline
1657
+ */
1658
+ export type AllPagesHelpers = {
1659
+ /**
1660
+ * Reads (and optionally updates) a page of the user's design.
1661
+ * @param pageRef - Reference to the page to be read.
1662
+ * @param callback - A callback for operating on the page of the design.
1663
+ * @returns A response indicating whether the callback was executed.
1664
+ */
1665
+ openPage(
1666
+ pageRef: AbsolutePageRef,
1667
+ callback: DesignOpenPageCallback<AbsolutePage>,
1668
+ ): Promise<OpenPageResponse>;
1669
+ openPage(
1670
+ pageRef: Unsupported,
1671
+ callback: DesignOpenPageCallback<Unsupported>,
1672
+ ): Promise<OpenPageResponse>;
1673
+ openPage(
1674
+ pageRef: PageRef,
1675
+ callback: DesignOpenPageCallback,
1676
+ ): Promise<OpenPageResponse>;
1677
+ };
1678
+ /**
1679
+ * @beta
1680
+ * Session received by the `openDesign` callback when opening all pages.
1681
+ */
1682
+ export type AllPagesSession = Readonly<{
1683
+ /**
1684
+ * References to all pages of the design.
1685
+ */
1686
+ pageRefs: DesignEditing.PageRefList;
1687
+ /**
1688
+ * These are various utilities that allow apps to do more complex operations on the page.
1689
+ */
1690
+ helpers: DesignEditing.AllPagesHelpers;
1691
+ /**
1692
+ * Saves any changes made during the session while keeping the session open.
1693
+ *
1694
+ * @remarks
1695
+ * - Any changes in the session are only reflected in the design after this method is called.
1696
+ * - Once this method is called, further changes in the session can still be made.
1697
+ */
1698
+ sync(): Promise<void>;
1699
+ }>;
1700
+ /**
1701
+ * @beta
1702
+ * Result received by the `openPage` callback.
1703
+ */
1704
+ export type OpenPageResult<
1705
+ Page extends DesignEditing.Page = DesignEditing.Page,
1706
+ > = Readonly<{
1707
+ /**
1708
+ * The page of the design.
1709
+ */
1710
+ page: Page;
1711
+ /**
1712
+ * These are various utilities that allow apps to do more complex operations on the page.
1713
+ */
1714
+ helpers: PageHelpers;
1715
+ }>;
1613
1716
  /**
1614
1717
  * A function called for each item in the list.
1615
1718
  *
1616
1719
  * @param item - The current item in the list.
1617
- * @param index - The index of the current item.
1618
1720
  */
1619
- export type ForEachCallback<M> = (item: M, index: number) => void;
1721
+ export type ForEachCallback<M> = (item: M) => void;
1620
1722
  /**
1621
1723
  * A function that determines if an item should be included in the result.
1622
1724
  *
@@ -1736,6 +1838,7 @@ export declare namespace DesignEditing {
1736
1838
  ): U[];
1737
1839
  readonly length: number;
1738
1840
  readonly [n: number]: T;
1841
+ at(index: number): T | undefined;
1739
1842
  }
1740
1843
  /**
1741
1844
  * @public
@@ -2637,6 +2740,32 @@ export declare namespace DesignEditing {
2637
2740
  */
2638
2741
  export type Page = AbsolutePage | Unsupported;
2639
2742
 
2743
+ /**
2744
+ * @beta
2745
+ * A reference to an `absolute` type page.
2746
+ */
2747
+ export type AbsolutePageRef = {
2748
+ /**
2749
+ * The type of page.
2750
+ */
2751
+ readonly type: "absolute";
2752
+ /**
2753
+ * If `true`, the page is locked and cannot be modified.
2754
+ */
2755
+ readonly locked: boolean;
2756
+ };
2757
+
2758
+ /**
2759
+ * @beta
2760
+ * A reference to a page.
2761
+ */
2762
+ export type PageRef = AbsolutePageRef | Unsupported;
2763
+
2764
+ /**
2765
+ * @beta
2766
+ * A list containing the references to pages in the design.
2767
+ */
2768
+ export type PageRefList = ReadableList<PageRef>;
2640
2769
  {
2641
2770
  }
2642
2771
  }
@@ -2689,21 +2818,86 @@ export declare type DesignMetadata = {
2689
2818
  durationInSeconds: number;
2690
2819
  };
2691
2820
 
2821
+ /**
2822
+ * @beta
2823
+ * A callback for operating on all pages of the design.
2824
+ * @param session - Session received by the `openDesign` callback when opening all pages.
2825
+ */
2826
+ export declare type DesignOpenAllPagesCallback = (
2827
+ session: DesignEditing.AllPagesSession,
2828
+ ) => Promise<void>;
2829
+
2830
+ /**
2831
+ * @beta
2832
+ * Options for configuring how all pages of the design are read.
2833
+ */
2834
+ export declare type DesignOpenAllPagesOptions = {
2835
+ /**
2836
+ * The type of context.
2837
+ */
2838
+ type: "all_pages";
2839
+ };
2840
+
2692
2841
  /**
2693
2842
  * @public
2694
2843
  * A callback for reading and updating part of a design.
2695
- * @param session - The result of reading part of a design.
2844
+ * @param session - Session received by the `openDesign` callback.
2696
2845
  */
2697
2846
  export declare type DesignOpenCallback = (
2698
- session: DesignEditing.CurrentPageResult,
2847
+ session: DesignEditing.CurrentPageSession,
2848
+ ) => Promise<void>;
2849
+
2850
+ /**
2851
+ * @beta
2852
+ * A callback for operating on the design.
2853
+ */
2854
+ declare type DesignOpenCallback_2 =
2855
+ | DesignOpenCurrentPageCallback
2856
+ | DesignOpenAllPagesCallback;
2857
+
2858
+ /**
2859
+ * @beta
2860
+ * A callback for operating on the current page of the design.
2861
+ * @param session - Session received by the `openDesign` callback when opening the current page.
2862
+ */
2863
+ export declare type DesignOpenCurrentPageCallback = (
2864
+ session: DesignEditing.CurrentPageSession,
2699
2865
  ) => Promise<void>;
2700
2866
 
2867
+ /**
2868
+ * @beta
2869
+ * Options for configuring how the current page of the design is read.
2870
+ */
2871
+ export declare type DesignOpenCurrentPageOptions = {
2872
+ /**
2873
+ * The type of context.
2874
+ */
2875
+ type: "current_page";
2876
+ };
2877
+
2701
2878
  /**
2702
2879
  * @public
2703
2880
  * Options for configuring which part of a design to read.
2704
2881
  */
2705
2882
  export declare type DesignOpenOptions = DesignContextOptions;
2706
2883
 
2884
+ /**
2885
+ * @beta
2886
+ * Options for configuring how the design is read.
2887
+ */
2888
+ declare type DesignOpenOptions_2 =
2889
+ | DesignOpenCurrentPageOptions
2890
+ | DesignOpenAllPagesOptions;
2891
+
2892
+ /**
2893
+ * @beta
2894
+ * A callback for operating on a page of the design.
2895
+ * @param response - Result received by the `openPage` callback.
2896
+ */
2897
+ export declare type DesignOpenPageCallback<
2898
+ Page extends DesignEditing.Page = DesignEditing.Page,
2899
+ > = (response: DesignEditing.OpenPageResult<Page>) => Promise<void>;
2900
+
2707
2901
  /**
2708
2902
  * @public
2709
2903
  * Provides methods for managing the lifecycle of overlays, such as selected image overlays.
@@ -2953,6 +3147,20 @@ export declare function editContent(
2953
3147
  callback: (session: FillContentSession) => Promise<void> | void,
2954
3148
  ): Promise<void>;
2955
3149
 
3150
+ /**
3151
+ * @beta
3152
+ * Reads and edits content from the user's design.
3153
+ * @param options - Options for configuring how a design is read. Must specify a content type.
3154
+ * @param callback - A callback that receives a session for editing.
3155
+ * @returns A promise that resolves when editing is complete.
3156
+ */
3157
+ export declare function editContent<T extends ContentType>(
3158
+ options: EditContentOptions & {
3159
+ contentType: T;
3160
+ },
3161
+ callback: (session: ContentTypeMap[T]) => Promise<void> | void,
3162
+ ): Promise<void>;
3163
+
2956
3164
  /**
2957
3165
  * @beta
2958
3166
  * A callback for reading and updating the requested design content.
@@ -3793,17 +4001,22 @@ export declare type NativeVideoElementWithBox = VideoElementAtPoint;
3793
4001
  declare type ObjectPrimitive = Boolean | String;
3794
4002
 
3795
4003
  /**
3796
- * @public
3797
- *
3798
- * Reads a specified part of the user's design and returns all elements in that part.
3799
- *
4004
+ * @beta
4005
+ * Reads (and optionally updates) a specified part of the user's design.
3800
4006
  * @param options - Options for configuring how the design is read.
3801
4007
  * @param callback - A callback for operating on the design.
3802
4008
  */
3803
- export declare const openDesign: (
3804
- options: DesignOpenOptions,
3805
- callback: DesignOpenCallback,
3806
- ) => Promise<void>;
4009
+ export declare const openDesign: {
4010
+ (
4011
+ options: DesignOpenCurrentPageOptions,
4012
+ callback: DesignOpenCurrentPageCallback,
4013
+ ): Promise<void>;
4014
+ (
4015
+ options: DesignOpenAllPagesOptions,
4016
+ callback: DesignOpenAllPagesCallback,
4017
+ ): Promise<void>;
4018
+ (options: DesignOpenOptions_2, callback: DesignOpenCallback_2): Promise<void>;
4019
+ };
3807
4020
 
3808
4021
  /**
3809
4022
  * @public
package/index.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from "./beta";
@@ -2,12 +2,21 @@
2
2
  Object.defineProperty(exports, "__esModule", {
3
3
  value: true
4
4
  });
5
- Object.defineProperty(exports, "editContent", {
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 editContent () {
8
13
  return editContent;
14
+ },
15
+ get openDesign () {
16
+ return openDesign;
9
17
  }
10
18
  });
19
+ const _version = require("./version");
11
20
  _export_star(require("./public"), exports);
12
21
  function _export_star(from, to) {
13
22
  Object.keys(from).forEach(function(k) {
@@ -22,9 +31,9 @@ function _export_star(from, to) {
22
31
  });
23
32
  return from;
24
33
  }
25
- var _window___canva___sdkRegistration, _window___canva__;
26
34
  const { canva_sdk } = window;
27
35
  function editContent(options, callback) {
28
36
  return canva_sdk.design.v2.designInteraction.editContent(options, (session)=>callback(session));
29
37
  }
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');
38
+ const openDesign = canva_sdk.design.v2.designInteraction.openDesign;
39
+ window.__canva__?.sdkRegistration?.registerPackageVersion('design', _version.LATEST_VERSION, 'beta');
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "createBetaFakeDesignClients", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return createBetaFakeDesignClients;
9
+ }
10
+ });
11
+ const _synthetic_delay = require('../../utils/synthetic_delay');
12
+ const _fake_design_interaction_client = require("./fake_design_interaction_client");
13
+ const _fake_drag_and_drop_client = require("./fake_drag_and_drop_client");
14
+ const _fake_export_client = require("./fake_export_client");
15
+ function createBetaFakeDesignClients() {
16
+ const syntheticDelay = (0, _synthetic_delay.createSyntheticDelay)(10);
17
+ const v2 = {
18
+ designInteraction: new FakeBetaDesignInteractionClient(syntheticDelay),
19
+ dragAndDrop: new _fake_drag_and_drop_client.FakeDragAndDropClient(syntheticDelay),
20
+ export: new _fake_export_client.FakeExportClient(syntheticDelay)
21
+ };
22
+ return {
23
+ design: {
24
+ v2
25
+ }
26
+ };
27
+ }
28
+ class FakeBetaDesignInteractionClient extends _fake_design_interaction_client.FakeDesignInteractionClient {
29
+ async editContent(options, callback) {
30
+ await this.delay();
31
+ await callback({
32
+ contents: [],
33
+ sync: async ()=>{
34
+ await this.delay();
35
+ }
36
+ });
37
+ }
38
+ async openDesign(options, callback) {
39
+ await this.delay();
40
+ await callback({
41
+ page: _fake_design_interaction_client.fakePage,
42
+ pageRefs: fakePageRefList,
43
+ sync: async ()=>{
44
+ await this.delay();
45
+ },
46
+ helpers: {
47
+ ..._fake_design_interaction_client.fakeOpenDesignHelpers,
48
+ openPage: async (_, callback)=>{
49
+ await callback({
50
+ page: _fake_design_interaction_client.fakePage,
51
+ helpers: _fake_design_interaction_client.fakeOpenDesignHelpers
52
+ });
53
+ return {
54
+ status: 'executed'
55
+ };
56
+ }
57
+ }
58
+ });
59
+ }
60
+ }
61
+ const fakePageRef = {
62
+ type: 'absolute',
63
+ locked: false
64
+ };
65
+ const fakePageRefList = {
66
+ forEach (callback) {},
67
+ toArray () {
68
+ return [
69
+ fakePageRef
70
+ ];
71
+ },
72
+ count () {
73
+ return 0;
74
+ },
75
+ filter (filter) {}
76
+ };
@@ -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
+ };
@@ -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
+ }
@@ -2,17 +2,15 @@
2
2
  Object.defineProperty(exports, "__esModule", {
3
3
  value: true
4
4
  });
5
- _export_star(require("./index"), 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;
5
+ Object.defineProperty(exports, "initTestEnvironment", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return initTestEnvironment;
9
+ }
10
+ });
11
+ const _create_beta = require('../fake/create_beta');
12
+ const _canva_sdk = require('../../utils/canva_sdk');
13
+ function initTestEnvironment() {
14
+ (0, _canva_sdk.assertIsTestCanvaSdk)();
15
+ (0, _canva_sdk.injectFakeAPIClients)((0, _create_beta.createBetaFakeDesignClients)());
18
16
  }
@@ -1,16 +1,18 @@
1
- "use strict"
1
+ "use strict";
2
2
  Object.defineProperty(exports, "__esModule", {
3
3
  value: true
4
4
  });
5
- Object.defineProperty(exports, "initTestEnvironment", {
6
- enumerable: true,
7
- get: function() {
8
- return initTestEnvironment;
9
- }
10
- });
11
- const _create = require('../fake/create');
12
- const _canva_sdk = require('../../utils/canva_sdk');
13
- function initTestEnvironment() {
14
- (0, _canva_sdk.assertIsTestCanvaSdk)();
15
- (0, _canva_sdk.injectFakeAPIClients)((0, _create.createFakeDesignClients)());
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;
16
18
  }
@@ -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/"
@@ -1,7 +1,8 @@
1
- var _window___canva___sdkRegistration, _window___canva__;
1
+ import { LATEST_VERSION } from './version';
2
2
  const { canva_sdk } = window;
3
3
  export function editContent(options, callback) {
4
4
  return canva_sdk.design.v2.designInteraction.editContent(options, (session)=>callback(session));
5
5
  }
6
+ export const openDesign = canva_sdk.design.v2.designInteraction.openDesign;
6
7
  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');
8
+ window.__canva__?.sdkRegistration?.registerPackageVersion('design', LATEST_VERSION, 'beta');
@@ -0,0 +1,66 @@
1
+ import { createSyntheticDelay } from '../../utils/synthetic_delay';
2
+ import { FakeDesignInteractionClient, fakeOpenDesignHelpers, fakePage } from './fake_design_interaction_client';
3
+ import { FakeDragAndDropClient } from './fake_drag_and_drop_client';
4
+ import { FakeExportClient } from './fake_export_client';
5
+ export function createBetaFakeDesignClients() {
6
+ const syntheticDelay = createSyntheticDelay(10);
7
+ const v2 = {
8
+ designInteraction: new FakeBetaDesignInteractionClient(syntheticDelay),
9
+ dragAndDrop: new FakeDragAndDropClient(syntheticDelay),
10
+ export: new FakeExportClient(syntheticDelay)
11
+ };
12
+ return {
13
+ design: {
14
+ v2
15
+ }
16
+ };
17
+ }
18
+ class FakeBetaDesignInteractionClient extends FakeDesignInteractionClient {
19
+ async editContent(options, callback) {
20
+ await this.delay();
21
+ await callback({
22
+ contents: [],
23
+ sync: async ()=>{
24
+ await this.delay();
25
+ }
26
+ });
27
+ }
28
+ async openDesign(options, callback) {
29
+ await this.delay();
30
+ await callback({
31
+ page: fakePage,
32
+ pageRefs: fakePageRefList,
33
+ sync: async ()=>{
34
+ await this.delay();
35
+ },
36
+ helpers: {
37
+ ...fakeOpenDesignHelpers,
38
+ openPage: async (_, callback)=>{
39
+ await callback({
40
+ page: fakePage,
41
+ helpers: fakeOpenDesignHelpers
42
+ });
43
+ return {
44
+ status: 'executed'
45
+ };
46
+ }
47
+ }
48
+ });
49
+ }
50
+ }
51
+ const fakePageRef = {
52
+ type: 'absolute',
53
+ locked: false
54
+ };
55
+ const fakePageRefList = {
56
+ forEach (callback) {},
57
+ toArray () {
58
+ return [
59
+ fakePageRef
60
+ ];
61
+ },
62
+ count () {
63
+ return 0;
64
+ },
65
+ filter (filter) {}
66
+ };
@@ -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 @@
1
+ export * from './beta';
@@ -1 +1,6 @@
1
- export * from './index';
1
+ import { createBetaFakeDesignClients } from '../fake/create_beta';
2
+ import { assertIsTestCanvaSdk, injectFakeAPIClients } from '../../utils/canva_sdk';
3
+ export function initTestEnvironment() {
4
+ assertIsTestCanvaSdk();
5
+ injectFakeAPIClients(createBetaFakeDesignClients());
6
+ }
@@ -1,6 +1 @@
1
- import { createFakeDesignClients } from '../fake/create';
2
- import { assertIsTestCanvaSdk, injectFakeAPIClients } from '../../utils/canva_sdk';
3
- export function initTestEnvironment() {
4
- assertIsTestCanvaSdk();
5
- injectFakeAPIClients(createFakeDesignClients());
6
- }
1
+ export * from './beta';
@@ -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,6 +1,6 @@
1
1
  {
2
2
  "name": "@canva/design",
3
- "version": "2.7.3-beta.0",
3
+ "version": "2.7.4-beta.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",
package/test/beta.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @public
2
+ * @beta
3
3
  * Initializes a test environment for the `@canva/design` package, enabling unit tests to mock Canva's APIs.
4
4
  * @remarks
5
5
  * This method should only be called once in a test environment, such as in a Jest setup file.
@@ -0,0 +1 @@
1
+ export * from "./beta";
@@ -1,27 +0,0 @@
1
- "use strict"
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "createFakeDesignClients", {
6
- enumerable: true,
7
- get: function() {
8
- return createFakeDesignClients;
9
- }
10
- });
11
- const _synthetic_delay = require('../../utils/synthetic_delay');
12
- const _fake_design_interaction_client = require("./fake_design_interaction_client");
13
- const _fake_drag_and_drop_client = require("./fake_drag_and_drop_client");
14
- const _fake_export_client = require("./fake_export_client");
15
- function createFakeDesignClients() {
16
- const syntheticDelay = (0, _synthetic_delay.createSyntheticDelay)(10);
17
- const v2 = {
18
- designInteraction: new _fake_design_interaction_client.FakeDesignInteractionClient(syntheticDelay),
19
- dragAndDrop: new _fake_drag_and_drop_client.FakeDragAndDropClient(syntheticDelay),
20
- export: new _fake_export_client.FakeExportClient(syntheticDelay)
21
- };
22
- return {
23
- design: {
24
- v2
25
- }
26
- };
27
- }
@@ -1,17 +0,0 @@
1
- import { createSyntheticDelay } from '../../utils/synthetic_delay';
2
- import { FakeDesignInteractionClient } from './fake_design_interaction_client';
3
- import { FakeDragAndDropClient } from './fake_drag_and_drop_client';
4
- import { FakeExportClient } from './fake_export_client';
5
- export function createFakeDesignClients() {
6
- const syntheticDelay = createSyntheticDelay(10);
7
- const v2 = {
8
- designInteraction: new FakeDesignInteractionClient(syntheticDelay),
9
- dragAndDrop: new FakeDragAndDropClient(syntheticDelay),
10
- export: new FakeExportClient(syntheticDelay)
11
- };
12
- return {
13
- design: {
14
- v2
15
- }
16
- };
17
- }