@canva/design 2.2.1-beta.1 → 2.2.1-beta.2

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
@@ -10,7 +10,7 @@ export declare const addAudioTrack: (audioTrack: AudioTrack) => Promise<void>;
10
10
  * Add element to responsive documents, which slot things into a text stream
11
11
  */
12
12
  export declare const addElementAtCursor: (
13
- element: ElementAtCursor
13
+ element: ElementAtCursor,
14
14
  ) => Promise<void>;
15
15
 
16
16
  /**
@@ -18,7 +18,7 @@ export declare const addElementAtCursor: (
18
18
  * Add element to fixed designs, which use a coordinate-based positioning system.
19
19
  */
20
20
  export declare const addElementAtPoint: (
21
- element: DesignElement | ElementAtPoint
21
+ element: DesignElement | ElementAtPoint,
22
22
  ) => Promise<void>;
23
23
 
24
24
  /**
@@ -28,7 +28,7 @@ export declare const addElementAtPoint: (
28
28
  * @param element - The element to add to the user's design.
29
29
  */
30
30
  export declare const addNativeElement: (
31
- element: NativeElement | NativeElementWithBox
31
+ element: NativeElement | NativeElementWithBox,
32
32
  ) => Promise<void>;
33
33
 
34
34
  /**
@@ -88,7 +88,7 @@ export declare type AppElementChangeHandler<A extends AppElementData> = (
88
88
  */
89
89
  version: number;
90
90
  }
91
- | undefined
91
+ | undefined,
92
92
  ) => void;
93
93
 
94
94
  /**
@@ -138,7 +138,7 @@ export declare type AppElementData = Record<string, Value>;
138
138
  * @param appElementData - The data the callback must use to render the app element.
139
139
  */
140
140
  export declare type AppElementRenderer<A extends AppElementData> = (
141
- appElementData: A
141
+ appElementData: A,
142
142
  ) => AppElementRendererOutput;
143
143
 
144
144
  /**
@@ -333,7 +333,7 @@ export declare type ContentType = "richtext";
333
333
  * Options for configuring where content in a design should be queried from.
334
334
  */
335
335
  declare type ContextOptions = {
336
- context: "current_page";
336
+ target: "current_page";
337
337
  };
338
338
 
339
339
  /**
@@ -438,7 +438,7 @@ export declare namespace DesignEditing {
438
438
  * @beta
439
439
  * Options for creating a shape path in the element builder
440
440
  */
441
- export type ShapePathOpts = Pick<Path, "d"> & {
441
+ export type PathOpts = Pick<Path, "d"> & {
442
442
  fill?: FillOpts;
443
443
  stroke?: StrokeOpts;
444
444
  };
@@ -447,7 +447,7 @@ export declare namespace DesignEditing {
447
447
  * Options for creating a rect element.
448
448
  */
449
449
  export type CreateRectElementOpts = Required<
450
- Pick<Element, "top" | "left" | "width" | "height">
450
+ Pick<RectElement, "top" | "left" | "width" | "height">
451
451
  > & {
452
452
  fill?: FillOpts;
453
453
  } & {
@@ -460,12 +460,13 @@ export declare namespace DesignEditing {
460
460
  export type CreateShapeElementOpts = Required<
461
461
  Pick<ShapeElement, "top" | "left" | "width" | "height" | "viewBox">
462
462
  > & {
463
- paths: ShapePathOpts[];
463
+ paths: PathOpts[];
464
464
  } & Partial<Omit<ShapeElement, "type" | "paths">>;
465
465
  /**
466
466
  * @beta
467
467
  * Options for creating an embed element.
468
- */ export type CreateEmbedElementOpts = Required<
468
+ */
469
+ export type CreateEmbedElementOpts = Required<
469
470
  Pick<EmbedElement, "top" | "left" | "width" | "height" | "url">
470
471
  > &
471
472
  Partial<Omit<EmbedElement, "type">>;
@@ -510,6 +511,17 @@ export declare namespace DesignEditing {
510
511
  * Creates a richtext range.
511
512
  */
512
513
  createRichtextRange(): RichtextRange;
514
+ /**
515
+ * Creates a clone of an element.
516
+ * @returns a new element with the same properties as the argument.
517
+ */
518
+ cloneElement(element: RectElement): RectElement;
519
+ cloneElement(element: ShapeElement): ShapeElement;
520
+ cloneElement(element: EmbedElement): EmbedElement;
521
+ cloneElement(element: TextElement): TextElement;
522
+ cloneElement(
523
+ element: RectElement | ShapeElement | EmbedElement | TextElement,
524
+ ): RectElement | ShapeElement | EmbedElement | TextElement;
513
525
  }
514
526
  /**
515
527
  * @beta
@@ -1096,7 +1108,7 @@ export declare type DesignOpenCallback = (
1096
1108
  * Provides methods for creating elements.
1097
1109
  */
1098
1110
  elementBuilder: DesignEditing.ElementBuilder;
1099
- }
1111
+ },
1100
1112
  ) => Promise<void> | void;
1101
1113
 
1102
1114
  /**
@@ -1180,29 +1192,6 @@ export declare type Dimensions = {
1180
1192
  height: number;
1181
1193
  };
1182
1194
 
1183
- /**
1184
- * @public
1185
- * Callbacks for handling drag and drop events.
1186
- */
1187
- export declare type DragCallback = {
1188
- /**
1189
- * A callback that runs at the start of a drag event.
1190
- * @param element - The element being dragged.
1191
- */
1192
- onDragStart: (element: HTMLElement) => void;
1193
- /**
1194
- * A callback that runs at the end of a drag event.
1195
- * @param element - The element being dragged.
1196
- */
1197
- onDragEnd: (element: HTMLElement) => void;
1198
- };
1199
-
1200
- /**
1201
- * @public
1202
- * Options for adding drag and drop behavior to an `HTMLElement`.
1203
- */
1204
- export declare type DraggableElementData = ElementData | ImageElementData;
1205
-
1206
1195
  /**
1207
1196
  * @public
1208
1197
  * An event that occurs when a user starts dragging an HTML element.
@@ -1216,10 +1205,43 @@ export declare type DragStartEvent<E extends Element> = Pick<
1216
1205
 
1217
1206
  /**
1218
1207
  * @beta
1219
- * Options for configuring how a design is read.
1208
+ * Reads and edits content of the specified type from the user's design.
1209
+ * @param options - Options for configuring how the design content is read.
1210
+ * @param callback - A callback for operating on the queried content.
1211
+ */
1212
+ export declare const editContent: (
1213
+ options: EditContentOptions,
1214
+ callback: EditContentCallback,
1215
+ ) => Promise<void>;
1216
+
1217
+ /**
1218
+ * @beta
1219
+ * A callback for reading and updating the requested design content.
1220
+ * @param session - The result of reading the content in the design.
1221
+ */
1222
+ export declare type EditContentCallback = (session: {
1223
+ /**
1224
+ * The individual content items returned by a query.
1225
+ */
1226
+ readonly contents: readonly RichtextContentRange[];
1227
+ /**
1228
+ * Commits any changes made to the items in the `contents` array.
1229
+ *
1230
+ * @remarks
1231
+ * An app must call this method for any changes to be reflected in the user's design.
1232
+ */
1233
+ sync(): Promise<void>;
1234
+ }) => Promise<void> | void;
1235
+
1236
+ /**
1237
+ * @beta
1238
+ * Options for configuring how the design content is read.
1220
1239
  */
1221
- export declare type EditContentOptions<T extends ContentType> = {
1222
- contentType: T;
1240
+ export declare type EditContentOptions = {
1241
+ /**
1242
+ * The type of content to edit from the user's design
1243
+ */
1244
+ contentType: ContentType;
1223
1245
  } & ContextOptions;
1224
1246
 
1225
1247
  /**
@@ -1247,17 +1269,6 @@ export declare type ElementAtPoint =
1247
1269
  | GroupElementAtPoint
1248
1270
  | RichtextElementAtPoint;
1249
1271
 
1250
- /**
1251
- * @public
1252
- * Options for adding drag and drop behavior to an `HTMLElement`.
1253
- */
1254
- export declare type ElementData = DragCallback & {
1255
- /**
1256
- * The `HTMLElement` to be made draggable.
1257
- */
1258
- node: HTMLElement;
1259
- };
1260
-
1261
1272
  /**
1262
1273
  * @public
1263
1274
  * Embed element to be added to the design at the end of a drag event.
@@ -1593,6 +1604,9 @@ export declare type ImageElement = {
1593
1604
  type: "image";
1594
1605
  /**
1595
1606
  * A description of the image content.
1607
+ *
1608
+ * @remarks
1609
+ * Use `undefined` for content with no description.
1596
1610
  */
1597
1611
  altText: AltText | undefined;
1598
1612
  } & (
@@ -1626,17 +1640,6 @@ export declare type ImageElementAtPoint = ImageElement &
1626
1640
  Point &
1627
1641
  (WidthAndHeight | Width | Height);
1628
1642
 
1629
- /**
1630
- * @public
1631
- * Options for adding drag and drop behavior to an `HTMLImageElement`.
1632
- */
1633
- export declare type ImageElementData = DragCallback & {
1634
- /**
1635
- * The `HTMLImageElement` to be made draggable.
1636
- */
1637
- node: HTMLImageElement;
1638
- };
1639
-
1640
1643
  /**
1641
1644
  * @public
1642
1645
  * An image asset that fills a path's interior.
@@ -1650,6 +1653,13 @@ export declare type ImageFill = {
1650
1653
  * A unique identifier that points to an image asset in Canva's backend.
1651
1654
  */
1652
1655
  ref: ImageRef;
1656
+ /**
1657
+ * A description of the image content.
1658
+ *
1659
+ * @remarks
1660
+ * Use `undefined` for content with no description.
1661
+ */
1662
+ altText?: AltText;
1653
1663
  };
1654
1664
 
1655
1665
  /**
@@ -1665,7 +1675,7 @@ export declare type ImageRef = string & {
1665
1675
  * @param appElementConfig - Configuration for an AppElementClient
1666
1676
  */
1667
1677
  export declare const initAppElement: <A extends AppElementData>(
1668
- appElementConfig: AppElementClientConfiguration<A>
1678
+ appElementConfig: AppElementClientConfiguration<A>,
1669
1679
  ) => AppElementClient<A>;
1670
1680
 
1671
1681
  /**
@@ -1851,7 +1861,7 @@ declare type ObjectPrimitive = Boolean | String;
1851
1861
  * @beta
1852
1862
  * Reads a specified part of the user's design and returns all elements in that part.
1853
1863
  *
1854
- * @param options - Options for configuring how a design is read.
1864
+ * @param options - Options for configuring how the design is read.
1855
1865
  * @param callback - A callback for operating on the design.
1856
1866
  */
1857
1867
  export declare const openDesign: (
@@ -1860,8 +1870,8 @@ export declare const openDesign: (
1860
1870
  draft: DesignEditing.DesignOpenResult,
1861
1871
  helpers: {
1862
1872
  elementBuilder: DesignEditing.ElementBuilder;
1863
- }
1864
- ) => Promise<void> | void
1873
+ },
1874
+ ) => Promise<void> | void,
1865
1875
  ) => Promise<void>;
1866
1876
 
1867
1877
  /**
@@ -2032,68 +2042,26 @@ declare type Point = {
2032
2042
  */
2033
2043
  declare type Primitive = undefined | null | number | boolean | string;
2034
2044
 
2035
- /**
2036
- * @beta
2037
- * A snapshot of content returned by a query.
2038
- *
2039
- * @remarks
2040
- * The snapshot is known as the *draft*.
2041
- */
2042
- export declare interface QueryContentDraft<T> {
2043
- /**
2044
- * The individual content items returned by a query.
2045
- */
2046
- readonly contents: readonly T[];
2047
- /**
2048
- * Commits any changes made to the items in the `contents` array.
2049
- *
2050
- * @remarks
2051
- * An app must call this method for any changes to be reflected in the user's design.
2052
- */
2053
- sync(): Promise<void>;
2054
- }
2055
-
2056
- /**
2057
- * @beta
2058
- * The result of querying content in a design.
2059
- */
2060
- export declare type QueryResult<T extends ContentType> = {
2061
- ["richtext"]: QueryContentDraft<
2062
- RichtextRange & {
2063
- readonly deleted: boolean;
2064
- }
2065
- >;
2066
- }[T];
2067
-
2068
- /**
2069
- * @beta
2070
- * Reads content of the specified type from the user's design.
2071
- * @param options - Options for configuring how a design is read.
2072
- * @param callback - A callback for operating on the queried content.
2073
- */
2074
- export declare const readContent: <T extends ContentType>(
2075
- options: EditContentOptions<T>,
2076
- callback: (draft: QueryResult<T>) => Promise<void> | void
2077
- ) => Promise<void>;
2078
-
2079
- /**
2080
- * @beta
2081
- * A callback for reading and updating part of a design.
2082
- * @param draft - The result of reading the content in a design.
2083
- */
2084
- export declare type ReadContentCallback<T extends ContentType> = (
2085
- draft: QueryResult<T>
2086
- ) => Promise<void> | void;
2087
-
2088
2045
  /**
2089
2046
  * @public
2090
2047
  * Exports the user's design as one or more static files.
2091
2048
  * @param request - The request object containing configurations of the design export.
2092
2049
  */
2093
2050
  export declare const requestExport: (
2094
- request: ExportRequest
2051
+ request: ExportRequest,
2095
2052
  ) => Promise<ExportResponse>;
2096
2053
 
2054
+ /**
2055
+ * @beta
2056
+ * Provides methods for interacting with a range of formatted text.
2057
+ */
2058
+ export declare interface RichtextContentRange extends RichtextRange {
2059
+ /**
2060
+ * Indicates whether the object containing this richtext range has been deleted.
2061
+ */
2062
+ readonly deleted: boolean;
2063
+ }
2064
+
2097
2065
  /**
2098
2066
  * @public
2099
2067
  * An element that renders richtext content.
@@ -2201,7 +2169,7 @@ export declare type RichtextRange = {
2201
2169
  */
2202
2170
  appendText(
2203
2171
  characters: string,
2204
- formatting?: InlineFormatting
2172
+ formatting?: InlineFormatting,
2205
2173
  ): {
2206
2174
  bounds: Bounds;
2207
2175
  };
@@ -2215,7 +2183,7 @@ export declare type RichtextRange = {
2215
2183
  replaceText(
2216
2184
  bounds: Bounds,
2217
2185
  characters: string,
2218
- formatting?: InlineFormatting
2186
+ formatting?: InlineFormatting,
2219
2187
  ): {
2220
2188
  /**
2221
2189
  * The bounds of the replacement characters within the updated range.
@@ -2353,7 +2321,7 @@ export declare type SelectionValue<Scope extends SelectionScope> = {
2353
2321
  * an image or a video.
2354
2322
  */
2355
2323
  export declare const setCurrentPageBackground: (
2356
- opts: PageBackgroundFill
2324
+ opts: PageBackgroundFill,
2357
2325
  ) => Promise<void>;
2358
2326
 
2359
2327
  /**
@@ -2595,7 +2563,7 @@ export declare type TextElement = {
2595
2563
  * @public
2596
2564
  * An element that renders text content and has positional properties.
2597
2565
  */
2598
- export declare type TextElementAtPoint = TextElement & TextAttributes & TextBox;
2566
+ export declare type TextElementAtPoint = TextElement & TextBox;
2599
2567
 
2600
2568
  /**
2601
2569
  * @public
@@ -2632,7 +2600,7 @@ export declare interface UI {
2632
2600
  | AudioDragConfig
2633
2601
  | EmbedDragConfig
2634
2602
  | VideoDragConfigForElement<E>
2635
- | ImageDragConfigForElement<E>
2603
+ | ImageDragConfigForElement<E>,
2636
2604
  ): Promise<void>;
2637
2605
  /**
2638
2606
  * @public
@@ -2648,7 +2616,7 @@ export declare interface UI {
2648
2616
  | AudioDragConfig
2649
2617
  | EmbedDragConfig
2650
2618
  | VideoDragConfigForElement<E>
2651
- | ImageDragConfigForElement<E>
2619
+ | ImageDragConfigForElement<E>,
2652
2620
  ): Promise<void>;
2653
2621
  /**
2654
2622
  * @public
@@ -2662,7 +2630,7 @@ export declare interface UI {
2662
2630
  dragData:
2663
2631
  | EmbedDragConfig
2664
2632
  | VideoDragConfigForElement<E>
2665
- | ImageDragConfigForElement<E>
2633
+ | ImageDragConfigForElement<E>,
2666
2634
  ): Promise<void>;
2667
2635
  }
2668
2636
 
@@ -2742,6 +2710,9 @@ export declare type VideoElement = {
2742
2710
  ref: VideoRef;
2743
2711
  /**
2744
2712
  * A description of the video content.
2713
+ *
2714
+ * @remarks
2715
+ * Use `undefined` for content with no description.
2745
2716
  */
2746
2717
  altText: AltText | undefined;
2747
2718
  };
@@ -2767,6 +2738,13 @@ export declare type VideoFill = {
2767
2738
  * A unique identifier that points to a video asset in Canva's backend.
2768
2739
  */
2769
2740
  ref: VideoRef;
2741
+ /**
2742
+ * A description of the image content.
2743
+ *
2744
+ * @remarks
2745
+ * Use `undefined` for content with no description.
2746
+ */
2747
+ altText?: AltText;
2770
2748
  };
2771
2749
 
2772
2750
  /**
@@ -9,8 +9,11 @@ function _export(target, all) {
9
9
  });
10
10
  }
11
11
  _export(exports, {
12
- readContent: function() {
13
- return readContent;
12
+ initAppElement: function() {
13
+ return initAppElement;
14
+ },
15
+ editContent: function() {
16
+ return editContent;
14
17
  },
15
18
  openDesign: function() {
16
19
  return openDesign;
@@ -32,6 +35,7 @@ function _export_star(from, to) {
32
35
  }
33
36
  var _window___canva___sdkRegistration, _window___canva__;
34
37
  const { canva_sdk } = window;
35
- const readContent = canva_sdk.design.v2.designInteraction.readContent;
38
+ const initAppElement = canva_sdk.design.v2.designInteraction.initAppElement;
39
+ const editContent = canva_sdk.design.v2.designInteraction.editContent;
36
40
  const openDesign = canva_sdk.design.v2.designInteraction.openDesign;
37
41
  (_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.2.1', 'beta');
@@ -1,6 +1,7 @@
1
1
  var _window___canva___sdkRegistration, _window___canva__;
2
2
  const { canva_sdk } = window;
3
- export const readContent = canva_sdk.design.v2.designInteraction.readContent;
3
+ export const initAppElement = canva_sdk.design.v2.designInteraction.initAppElement;
4
+ export const editContent = canva_sdk.design.v2.designInteraction.editContent;
4
5
  export const openDesign = canva_sdk.design.v2.designInteraction.openDesign;
5
6
  export * from './public';
6
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.2.1', 'beta');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@canva/design",
3
- "version": "2.2.1-beta.1",
3
+ "version": "2.2.1-beta.2",
4
4
  "description": "The Canva Apps SDK design library",
5
5
  "author": "Canva Pty Ltd.",
6
6
  "license": "SEE LICENSE IN LICENSE.md FILE",
@@ -11,14 +11,9 @@
11
11
  "module": "./lib/esm/sdk/design/beta.js",
12
12
  "exports": {
13
13
  ".": {
14
- "require": {
15
- "types": "./beta.d.ts",
16
- "default": "./lib/cjs/sdk/design/beta.js"
17
- },
18
- "import": {
19
- "types": "./beta.d.ts",
20
- "default": "./lib/esm/sdk/design/beta.js"
21
- }
14
+ "types": "./beta.d.ts",
15
+ "require": "./lib/cjs/sdk/design/beta.js",
16
+ "import": "./lib/esm/sdk/design/beta.js"
22
17
  }
23
18
  },
24
19
  "typings": "./beta.d.ts"