@canva/design 2.2.1-beta.2 → 2.3.0-beta.1
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 +35 -8
- package/lib/cjs/sdk/design/beta.js +1 -5
- package/lib/cjs/sdk/design/fake/create.js +27 -0
- package/lib/cjs/sdk/design/fake/fake_design_interaction_client.js +217 -0
- package/lib/cjs/sdk/design/fake/fake_drag_and_drop_client.js +24 -0
- package/lib/cjs/sdk/design/fake/fake_export_client.js +34 -0
- package/lib/cjs/sdk/design/public.js +4 -0
- package/lib/cjs/sdk/design/test/beta.js +18 -0
- package/lib/cjs/sdk/design/test/index.js +16 -0
- package/lib/cjs/sdk/utils/canva_sdk.js +41 -0
- package/lib/cjs/sdk/utils/synthetic_delay.js +13 -0
- package/lib/esm/sdk/design/beta.js +1 -2
- package/lib/esm/sdk/design/fake/create.js +17 -0
- package/lib/esm/sdk/design/fake/fake_design_interaction_client.js +207 -0
- package/lib/esm/sdk/design/fake/fake_drag_and_drop_client.js +14 -0
- package/lib/esm/sdk/design/fake/fake_export_client.js +24 -0
- package/lib/esm/sdk/design/public.js +1 -0
- package/lib/esm/sdk/design/test/beta.js +1 -0
- package/lib/esm/sdk/design/test/index.js +6 -0
- package/lib/esm/sdk/utils/canva_sdk.js +20 -0
- package/lib/esm/sdk/utils/synthetic_delay.js +3 -0
- package/package.json +6 -1
- package/test/beta.d.ts +11 -0
package/beta.d.ts
CHANGED
|
@@ -87,6 +87,11 @@ export declare type AppElementChangeHandler<A extends AppElementData> = (
|
|
|
87
87
|
* The version number of the app.
|
|
88
88
|
*/
|
|
89
89
|
version: number;
|
|
90
|
+
/**
|
|
91
|
+
* @beta
|
|
92
|
+
* Function to update the app element data.
|
|
93
|
+
*/
|
|
94
|
+
update: (opts: AppElementOptions<A>) => Promise<void>;
|
|
90
95
|
}
|
|
91
96
|
| undefined,
|
|
92
97
|
) => void;
|
|
@@ -103,6 +108,12 @@ export declare interface AppElementClient<A extends AppElementData> {
|
|
|
103
108
|
* @param placement - The position, dimensions, and rotation of the app element.
|
|
104
109
|
*/
|
|
105
110
|
addOrUpdateElement(appElementData: A, placement?: Placement): Promise<void>;
|
|
111
|
+
/**
|
|
112
|
+
* @beta
|
|
113
|
+
* Adds a new app element to the design.
|
|
114
|
+
* @param opts - The data and placement of the app element.
|
|
115
|
+
*/
|
|
116
|
+
addElement(opts: AppElementOptions<A>): Promise<void>;
|
|
106
117
|
/**
|
|
107
118
|
* A callback that runs when:
|
|
108
119
|
*
|
|
@@ -132,6 +143,22 @@ export declare type AppElementClientConfiguration<A extends AppElementData> = {
|
|
|
132
143
|
*/
|
|
133
144
|
export declare type AppElementData = Record<string, Value>;
|
|
134
145
|
|
|
146
|
+
/**
|
|
147
|
+
* @beta
|
|
148
|
+
* Used to add or update an app element to the design.
|
|
149
|
+
* The update function is provided in the AppElementChangeHandler callback (registerOnElementChange).
|
|
150
|
+
*/
|
|
151
|
+
export declare type AppElementOptions<A extends AppElementData> = {
|
|
152
|
+
/**
|
|
153
|
+
* The data to attach to the app element.
|
|
154
|
+
*/
|
|
155
|
+
data: A;
|
|
156
|
+
/**
|
|
157
|
+
* The position, dimensions, and rotation of the app element.
|
|
158
|
+
*/
|
|
159
|
+
placement?: Placement;
|
|
160
|
+
};
|
|
161
|
+
|
|
135
162
|
/**
|
|
136
163
|
* @public
|
|
137
164
|
* A callback function that renders an app element based on the data it receives.
|
|
@@ -329,7 +356,7 @@ export declare interface ContentDraft<T> {
|
|
|
329
356
|
export declare type ContentType = "richtext";
|
|
330
357
|
|
|
331
358
|
/**
|
|
332
|
-
* @
|
|
359
|
+
* @public
|
|
333
360
|
* Options for configuring where content in a design should be queried from.
|
|
334
361
|
*/
|
|
335
362
|
declare type ContextOptions = {
|
|
@@ -1204,10 +1231,10 @@ export declare type DragStartEvent<E extends Element> = Pick<
|
|
|
1204
1231
|
};
|
|
1205
1232
|
|
|
1206
1233
|
/**
|
|
1207
|
-
* @
|
|
1234
|
+
* @public
|
|
1208
1235
|
* Reads and edits content of the specified type from the user's design.
|
|
1209
|
-
* @param options - Options for configuring how
|
|
1210
|
-
* @param callback - A callback for operating on the
|
|
1236
|
+
* @param options - Options for configuring how a design is read.
|
|
1237
|
+
* @param callback - A callback for operating on the read content.
|
|
1211
1238
|
*/
|
|
1212
1239
|
export declare const editContent: (
|
|
1213
1240
|
options: EditContentOptions,
|
|
@@ -1215,7 +1242,7 @@ export declare const editContent: (
|
|
|
1215
1242
|
) => Promise<void>;
|
|
1216
1243
|
|
|
1217
1244
|
/**
|
|
1218
|
-
* @
|
|
1245
|
+
* @public
|
|
1219
1246
|
* A callback for reading and updating the requested design content.
|
|
1220
1247
|
* @param session - The result of reading the content in the design.
|
|
1221
1248
|
*/
|
|
@@ -1234,7 +1261,7 @@ export declare type EditContentCallback = (session: {
|
|
|
1234
1261
|
}) => Promise<void> | void;
|
|
1235
1262
|
|
|
1236
1263
|
/**
|
|
1237
|
-
* @
|
|
1264
|
+
* @public
|
|
1238
1265
|
* Options for configuring how the design content is read.
|
|
1239
1266
|
*/
|
|
1240
1267
|
export declare type EditContentOptions = {
|
|
@@ -1671,7 +1698,7 @@ export declare type ImageRef = string & {
|
|
|
1671
1698
|
};
|
|
1672
1699
|
|
|
1673
1700
|
/**
|
|
1674
|
-
* @
|
|
1701
|
+
* @beta
|
|
1675
1702
|
* @param appElementConfig - Configuration for an AppElementClient
|
|
1676
1703
|
*/
|
|
1677
1704
|
export declare const initAppElement: <A extends AppElementData>(
|
|
@@ -2052,7 +2079,7 @@ export declare const requestExport: (
|
|
|
2052
2079
|
) => Promise<ExportResponse>;
|
|
2053
2080
|
|
|
2054
2081
|
/**
|
|
2055
|
-
* @
|
|
2082
|
+
* @public
|
|
2056
2083
|
* Provides methods for interacting with a range of formatted text.
|
|
2057
2084
|
*/
|
|
2058
2085
|
export declare interface RichtextContentRange extends RichtextRange {
|
|
@@ -12,9 +12,6 @@ _export(exports, {
|
|
|
12
12
|
initAppElement: function() {
|
|
13
13
|
return initAppElement;
|
|
14
14
|
},
|
|
15
|
-
editContent: function() {
|
|
16
|
-
return editContent;
|
|
17
|
-
},
|
|
18
15
|
openDesign: function() {
|
|
19
16
|
return openDesign;
|
|
20
17
|
}
|
|
@@ -36,6 +33,5 @@ function _export_star(from, to) {
|
|
|
36
33
|
var _window___canva___sdkRegistration, _window___canva__;
|
|
37
34
|
const { canva_sdk } = window;
|
|
38
35
|
const initAppElement = canva_sdk.design.v2.designInteraction.initAppElement;
|
|
39
|
-
const editContent = canva_sdk.design.v2.designInteraction.editContent;
|
|
40
36
|
const openDesign = canva_sdk.design.v2.designInteraction.openDesign;
|
|
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.
|
|
37
|
+
(_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.3.0', 'beta');
|
|
@@ -0,0 +1,27 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
"use strict"
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "FakeDesignInteractionClient", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return FakeDesignInteractionClient;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
class FakeDesignInteractionClient {
|
|
12
|
+
async getDesignToken() {
|
|
13
|
+
await this.delay();
|
|
14
|
+
return {
|
|
15
|
+
token: 'token'
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
async addNativeElement(element) {
|
|
19
|
+
await this.delay();
|
|
20
|
+
}
|
|
21
|
+
async addElementAtPoint(element) {
|
|
22
|
+
await this.delay();
|
|
23
|
+
}
|
|
24
|
+
async addElementAtCursor(element) {
|
|
25
|
+
await this.delay();
|
|
26
|
+
}
|
|
27
|
+
async addAudioTrack(audioTrack) {
|
|
28
|
+
await this.delay();
|
|
29
|
+
}
|
|
30
|
+
async addPage(opts) {
|
|
31
|
+
await this.delay();
|
|
32
|
+
}
|
|
33
|
+
async setCurrentPageBackground(opts) {
|
|
34
|
+
await this.delay();
|
|
35
|
+
}
|
|
36
|
+
async setAppElementData(appElementData, placement) {
|
|
37
|
+
await this.delay();
|
|
38
|
+
}
|
|
39
|
+
onAppElementChange(handler) {}
|
|
40
|
+
async addAppElement(opts) {
|
|
41
|
+
await this.delay();
|
|
42
|
+
}
|
|
43
|
+
async updateAppElement(opts) {
|
|
44
|
+
await this.delay();
|
|
45
|
+
}
|
|
46
|
+
onAppElementDrop(handler) {}
|
|
47
|
+
onAppElementCreateFromPreset(handler) {}
|
|
48
|
+
registerRenderAppElement(renderAppElement) {}
|
|
49
|
+
async getCurrentPageContext() {
|
|
50
|
+
await this.delay();
|
|
51
|
+
return {
|
|
52
|
+
dimensions: fakePageDimensions
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
async getDefaultPageDimensions() {
|
|
56
|
+
await this.delay();
|
|
57
|
+
return fakePageDimensions;
|
|
58
|
+
}
|
|
59
|
+
initAppElement(appElementConfig) {
|
|
60
|
+
return {
|
|
61
|
+
addOrUpdateElement: async ()=>{
|
|
62
|
+
await this.delay();
|
|
63
|
+
},
|
|
64
|
+
registerOnElementChange: (handler)=>{},
|
|
65
|
+
addElement: async (opts)=>{
|
|
66
|
+
await this.delay();
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
createRichtextRange() {
|
|
71
|
+
return fakeRichtextRange;
|
|
72
|
+
}
|
|
73
|
+
async editContent(options, callback) {
|
|
74
|
+
await this.delay();
|
|
75
|
+
await callback({
|
|
76
|
+
contents: [],
|
|
77
|
+
sync: async ()=>{
|
|
78
|
+
await this.delay();
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
async openDesign(options, callback) {
|
|
83
|
+
await this.delay();
|
|
84
|
+
await callback({
|
|
85
|
+
page: fakePage,
|
|
86
|
+
save: async ()=>{
|
|
87
|
+
await this.delay();
|
|
88
|
+
}
|
|
89
|
+
}, {
|
|
90
|
+
elementBuilder: fakeElementBuilder
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
constructor(delay){
|
|
94
|
+
this.delay = delay;
|
|
95
|
+
this.selection = {
|
|
96
|
+
registerOnChange: (e)=>{
|
|
97
|
+
return ()=>{};
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
this.overlay = {
|
|
101
|
+
registerOnCanOpen: (e)=>{
|
|
102
|
+
return ()=>{};
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
const fakeBounds = {
|
|
108
|
+
index: 0,
|
|
109
|
+
length: 12
|
|
110
|
+
};
|
|
111
|
+
const fakeTextRegion = {
|
|
112
|
+
text: 'Hello World!',
|
|
113
|
+
formatting: {
|
|
114
|
+
fontWeight: 'bold'
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
const fakeRichtextRange = {
|
|
118
|
+
formatParagraph: ()=>{},
|
|
119
|
+
formatText: ()=>{},
|
|
120
|
+
appendText: ()=>{
|
|
121
|
+
return {
|
|
122
|
+
bounds: fakeBounds
|
|
123
|
+
};
|
|
124
|
+
},
|
|
125
|
+
replaceText: ()=>{
|
|
126
|
+
return {
|
|
127
|
+
bounds: fakeBounds
|
|
128
|
+
};
|
|
129
|
+
},
|
|
130
|
+
readPlaintext: ()=>'',
|
|
131
|
+
readTextRegions: ()=>[
|
|
132
|
+
fakeTextRegion
|
|
133
|
+
]
|
|
134
|
+
};
|
|
135
|
+
const fakePageDimensions = {
|
|
136
|
+
width: 800,
|
|
137
|
+
height: 600
|
|
138
|
+
};
|
|
139
|
+
const fakeFill = {
|
|
140
|
+
media: undefined,
|
|
141
|
+
color: {
|
|
142
|
+
type: 'solid',
|
|
143
|
+
color: '#FFFFFF'
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
const fakePage = {
|
|
147
|
+
type: 'fixed',
|
|
148
|
+
locked: false,
|
|
149
|
+
dimensions: fakePageDimensions,
|
|
150
|
+
background: fakeFill,
|
|
151
|
+
elements: {
|
|
152
|
+
count: ()=>0,
|
|
153
|
+
toArray: ()=>[],
|
|
154
|
+
insertBefore: (ref)=>ref,
|
|
155
|
+
insertAfter: (ref)=>ref,
|
|
156
|
+
forEach: (callback)=>{},
|
|
157
|
+
filter: (filter)=>[],
|
|
158
|
+
moveBefore: (item)=>{},
|
|
159
|
+
moveAfter: (item)=>{},
|
|
160
|
+
delete: (item)=>{}
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
const fakeElement = {
|
|
164
|
+
top: 0,
|
|
165
|
+
left: 0,
|
|
166
|
+
rotation: 0,
|
|
167
|
+
transparency: 0,
|
|
168
|
+
locked: true,
|
|
169
|
+
width: 100,
|
|
170
|
+
height: 100
|
|
171
|
+
};
|
|
172
|
+
const fakeRectElement = {
|
|
173
|
+
...fakeElement,
|
|
174
|
+
type: 'rect',
|
|
175
|
+
fill: fakeFill,
|
|
176
|
+
stroke: {
|
|
177
|
+
weight: 10,
|
|
178
|
+
color: fakeFill.color
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
const fakeShapeElement = {
|
|
182
|
+
...fakeElement,
|
|
183
|
+
type: 'shape',
|
|
184
|
+
viewBox: {
|
|
185
|
+
top: 0,
|
|
186
|
+
left: 0,
|
|
187
|
+
width: 100,
|
|
188
|
+
height: 100
|
|
189
|
+
},
|
|
190
|
+
paths: {
|
|
191
|
+
count: ()=>0,
|
|
192
|
+
toArray: ()=>[],
|
|
193
|
+
forEach: (callback)=>{},
|
|
194
|
+
filter: (filter)=>[]
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
|
+
const fakeEmbedElement = {
|
|
198
|
+
...fakeElement,
|
|
199
|
+
type: 'embed',
|
|
200
|
+
url: 'https://canva.dev/docs/apps/testing/'
|
|
201
|
+
};
|
|
202
|
+
const fakeTextElement = {
|
|
203
|
+
...fakeElement,
|
|
204
|
+
type: 'text',
|
|
205
|
+
text: fakeRichtextRange
|
|
206
|
+
};
|
|
207
|
+
function cloneElement(element) {
|
|
208
|
+
return fakeRectElement;
|
|
209
|
+
}
|
|
210
|
+
const fakeElementBuilder = {
|
|
211
|
+
createRectElement: (opts)=>fakeRectElement,
|
|
212
|
+
createShapeElement: (opts)=>fakeShapeElement,
|
|
213
|
+
createEmbedElement: (opts)=>fakeEmbedElement,
|
|
214
|
+
createTextElement: (opts)=>fakeTextElement,
|
|
215
|
+
createRichtextRange: ()=>fakeRichtextRange,
|
|
216
|
+
cloneElement
|
|
217
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict"
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "FakeDragAndDropClient", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return FakeDragAndDropClient;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
class FakeDragAndDropClient {
|
|
12
|
+
async startDrag(event, dragData) {
|
|
13
|
+
await this.delay();
|
|
14
|
+
}
|
|
15
|
+
async startDragToPoint(event, dragData) {
|
|
16
|
+
await this.delay();
|
|
17
|
+
}
|
|
18
|
+
async startDragToCursor(event, dragData) {
|
|
19
|
+
await this.delay();
|
|
20
|
+
}
|
|
21
|
+
constructor(delay){
|
|
22
|
+
this.delay = delay;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict"
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "FakeExportClient", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return FakeExportClient;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
class FakeExportClient {
|
|
12
|
+
async queueDocument(request) {
|
|
13
|
+
await this.delay();
|
|
14
|
+
return {
|
|
15
|
+
status: 'completed',
|
|
16
|
+
exportBlobs: fakeExportBlobs
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
async requestExport(request) {
|
|
20
|
+
await this.delay();
|
|
21
|
+
return {
|
|
22
|
+
status: 'completed',
|
|
23
|
+
exportBlobs: fakeExportBlobs
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
constructor(delay){
|
|
27
|
+
this.delay = delay;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
const fakeExportBlobs = [
|
|
31
|
+
{
|
|
32
|
+
url: 'https://canva.dev/docs/apps/testing/'
|
|
33
|
+
}
|
|
34
|
+
];
|
|
@@ -53,6 +53,9 @@ _export(exports, {
|
|
|
53
53
|
},
|
|
54
54
|
createRichtextRange: function() {
|
|
55
55
|
return createRichtextRange;
|
|
56
|
+
},
|
|
57
|
+
editContent: function() {
|
|
58
|
+
return editContent;
|
|
56
59
|
}
|
|
57
60
|
});
|
|
58
61
|
const { canva_sdk } = window;
|
|
@@ -71,3 +74,4 @@ const getCurrentPageContext = canva_sdk.design.v2.designInteraction.getCurrentPa
|
|
|
71
74
|
const initAppElement = canva_sdk.design.v2.designInteraction.initAppElement;
|
|
72
75
|
const getDesignToken = canva_sdk.design.v2.designInteraction.getDesignToken;
|
|
73
76
|
const createRichtextRange = canva_sdk.design.v2.designInteraction.createRichtextRange;
|
|
77
|
+
const editContent = canva_sdk.design.v2.designInteraction.editContent;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict"
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
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;
|
|
18
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict"
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
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)());
|
|
16
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict"
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: all[name]
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
getCanvaSdk: function() {
|
|
13
|
+
return getCanvaSdk;
|
|
14
|
+
},
|
|
15
|
+
assertIsTestCanvaSdk: function() {
|
|
16
|
+
return assertIsTestCanvaSdk;
|
|
17
|
+
},
|
|
18
|
+
injectFakeAPIClients: function() {
|
|
19
|
+
return injectFakeAPIClients;
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
function getCanvaSdk() {
|
|
23
|
+
return window.canva_sdk;
|
|
24
|
+
}
|
|
25
|
+
function assertIsTestCanvaSdk() {
|
|
26
|
+
var _window___canva__;
|
|
27
|
+
if ((_window___canva__ = window.__canva__) === null || _window___canva__ === void 0 ? void 0 : _window___canva__.uiKit) {
|
|
28
|
+
var _getCanvaSdk_error, _getCanvaSdk;
|
|
29
|
+
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;
|
|
30
|
+
throw new CanvaError({
|
|
31
|
+
code: 'failed_precondition',
|
|
32
|
+
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/"
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
function injectFakeAPIClients(clients) {
|
|
37
|
+
window.canva_sdk = {
|
|
38
|
+
...getCanvaSdk(),
|
|
39
|
+
...clients
|
|
40
|
+
};
|
|
41
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict"
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "createSyntheticDelay", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return createSyntheticDelay;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
function createSyntheticDelay(timeout) {
|
|
12
|
+
return ()=>new Promise((res)=>setTimeout(res, timeout));
|
|
13
|
+
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
var _window___canva___sdkRegistration, _window___canva__;
|
|
2
2
|
const { canva_sdk } = window;
|
|
3
3
|
export const initAppElement = canva_sdk.design.v2.designInteraction.initAppElement;
|
|
4
|
-
export const editContent = canva_sdk.design.v2.designInteraction.editContent;
|
|
5
4
|
export const openDesign = canva_sdk.design.v2.designInteraction.openDesign;
|
|
6
5
|
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.
|
|
6
|
+
(_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.3.0', 'beta');
|
|
@@ -0,0 +1,17 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
export class FakeDesignInteractionClient {
|
|
2
|
+
async getDesignToken() {
|
|
3
|
+
await this.delay();
|
|
4
|
+
return {
|
|
5
|
+
token: 'token'
|
|
6
|
+
};
|
|
7
|
+
}
|
|
8
|
+
async addNativeElement(element) {
|
|
9
|
+
await this.delay();
|
|
10
|
+
}
|
|
11
|
+
async addElementAtPoint(element) {
|
|
12
|
+
await this.delay();
|
|
13
|
+
}
|
|
14
|
+
async addElementAtCursor(element) {
|
|
15
|
+
await this.delay();
|
|
16
|
+
}
|
|
17
|
+
async addAudioTrack(audioTrack) {
|
|
18
|
+
await this.delay();
|
|
19
|
+
}
|
|
20
|
+
async addPage(opts) {
|
|
21
|
+
await this.delay();
|
|
22
|
+
}
|
|
23
|
+
async setCurrentPageBackground(opts) {
|
|
24
|
+
await this.delay();
|
|
25
|
+
}
|
|
26
|
+
async setAppElementData(appElementData, placement) {
|
|
27
|
+
await this.delay();
|
|
28
|
+
}
|
|
29
|
+
onAppElementChange(handler) {}
|
|
30
|
+
async addAppElement(opts) {
|
|
31
|
+
await this.delay();
|
|
32
|
+
}
|
|
33
|
+
async updateAppElement(opts) {
|
|
34
|
+
await this.delay();
|
|
35
|
+
}
|
|
36
|
+
onAppElementDrop(handler) {}
|
|
37
|
+
onAppElementCreateFromPreset(handler) {}
|
|
38
|
+
registerRenderAppElement(renderAppElement) {}
|
|
39
|
+
async getCurrentPageContext() {
|
|
40
|
+
await this.delay();
|
|
41
|
+
return {
|
|
42
|
+
dimensions: fakePageDimensions
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
async getDefaultPageDimensions() {
|
|
46
|
+
await this.delay();
|
|
47
|
+
return fakePageDimensions;
|
|
48
|
+
}
|
|
49
|
+
initAppElement(appElementConfig) {
|
|
50
|
+
return {
|
|
51
|
+
addOrUpdateElement: async ()=>{
|
|
52
|
+
await this.delay();
|
|
53
|
+
},
|
|
54
|
+
registerOnElementChange: (handler)=>{},
|
|
55
|
+
addElement: async (opts)=>{
|
|
56
|
+
await this.delay();
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
createRichtextRange() {
|
|
61
|
+
return fakeRichtextRange;
|
|
62
|
+
}
|
|
63
|
+
async editContent(options, callback) {
|
|
64
|
+
await this.delay();
|
|
65
|
+
await callback({
|
|
66
|
+
contents: [],
|
|
67
|
+
sync: async ()=>{
|
|
68
|
+
await this.delay();
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
async openDesign(options, callback) {
|
|
73
|
+
await this.delay();
|
|
74
|
+
await callback({
|
|
75
|
+
page: fakePage,
|
|
76
|
+
save: async ()=>{
|
|
77
|
+
await this.delay();
|
|
78
|
+
}
|
|
79
|
+
}, {
|
|
80
|
+
elementBuilder: fakeElementBuilder
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
constructor(delay){
|
|
84
|
+
this.delay = delay;
|
|
85
|
+
this.selection = {
|
|
86
|
+
registerOnChange: (e)=>{
|
|
87
|
+
return ()=>{};
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
this.overlay = {
|
|
91
|
+
registerOnCanOpen: (e)=>{
|
|
92
|
+
return ()=>{};
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
const fakeBounds = {
|
|
98
|
+
index: 0,
|
|
99
|
+
length: 12
|
|
100
|
+
};
|
|
101
|
+
const fakeTextRegion = {
|
|
102
|
+
text: 'Hello World!',
|
|
103
|
+
formatting: {
|
|
104
|
+
fontWeight: 'bold'
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
const fakeRichtextRange = {
|
|
108
|
+
formatParagraph: ()=>{},
|
|
109
|
+
formatText: ()=>{},
|
|
110
|
+
appendText: ()=>{
|
|
111
|
+
return {
|
|
112
|
+
bounds: fakeBounds
|
|
113
|
+
};
|
|
114
|
+
},
|
|
115
|
+
replaceText: ()=>{
|
|
116
|
+
return {
|
|
117
|
+
bounds: fakeBounds
|
|
118
|
+
};
|
|
119
|
+
},
|
|
120
|
+
readPlaintext: ()=>'',
|
|
121
|
+
readTextRegions: ()=>[
|
|
122
|
+
fakeTextRegion
|
|
123
|
+
]
|
|
124
|
+
};
|
|
125
|
+
const fakePageDimensions = {
|
|
126
|
+
width: 800,
|
|
127
|
+
height: 600
|
|
128
|
+
};
|
|
129
|
+
const fakeFill = {
|
|
130
|
+
media: undefined,
|
|
131
|
+
color: {
|
|
132
|
+
type: 'solid',
|
|
133
|
+
color: '#FFFFFF'
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
const fakePage = {
|
|
137
|
+
type: 'fixed',
|
|
138
|
+
locked: false,
|
|
139
|
+
dimensions: fakePageDimensions,
|
|
140
|
+
background: fakeFill,
|
|
141
|
+
elements: {
|
|
142
|
+
count: ()=>0,
|
|
143
|
+
toArray: ()=>[],
|
|
144
|
+
insertBefore: (ref)=>ref,
|
|
145
|
+
insertAfter: (ref)=>ref,
|
|
146
|
+
forEach: (callback)=>{},
|
|
147
|
+
filter: (filter)=>[],
|
|
148
|
+
moveBefore: (item)=>{},
|
|
149
|
+
moveAfter: (item)=>{},
|
|
150
|
+
delete: (item)=>{}
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
const fakeElement = {
|
|
154
|
+
top: 0,
|
|
155
|
+
left: 0,
|
|
156
|
+
rotation: 0,
|
|
157
|
+
transparency: 0,
|
|
158
|
+
locked: true,
|
|
159
|
+
width: 100,
|
|
160
|
+
height: 100
|
|
161
|
+
};
|
|
162
|
+
const fakeRectElement = {
|
|
163
|
+
...fakeElement,
|
|
164
|
+
type: 'rect',
|
|
165
|
+
fill: fakeFill,
|
|
166
|
+
stroke: {
|
|
167
|
+
weight: 10,
|
|
168
|
+
color: fakeFill.color
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
const fakeShapeElement = {
|
|
172
|
+
...fakeElement,
|
|
173
|
+
type: 'shape',
|
|
174
|
+
viewBox: {
|
|
175
|
+
top: 0,
|
|
176
|
+
left: 0,
|
|
177
|
+
width: 100,
|
|
178
|
+
height: 100
|
|
179
|
+
},
|
|
180
|
+
paths: {
|
|
181
|
+
count: ()=>0,
|
|
182
|
+
toArray: ()=>[],
|
|
183
|
+
forEach: (callback)=>{},
|
|
184
|
+
filter: (filter)=>[]
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
const fakeEmbedElement = {
|
|
188
|
+
...fakeElement,
|
|
189
|
+
type: 'embed',
|
|
190
|
+
url: 'https://canva.dev/docs/apps/testing/'
|
|
191
|
+
};
|
|
192
|
+
const fakeTextElement = {
|
|
193
|
+
...fakeElement,
|
|
194
|
+
type: 'text',
|
|
195
|
+
text: fakeRichtextRange
|
|
196
|
+
};
|
|
197
|
+
function cloneElement(element) {
|
|
198
|
+
return fakeRectElement;
|
|
199
|
+
}
|
|
200
|
+
const fakeElementBuilder = {
|
|
201
|
+
createRectElement: (opts)=>fakeRectElement,
|
|
202
|
+
createShapeElement: (opts)=>fakeShapeElement,
|
|
203
|
+
createEmbedElement: (opts)=>fakeEmbedElement,
|
|
204
|
+
createTextElement: (opts)=>fakeTextElement,
|
|
205
|
+
createRichtextRange: ()=>fakeRichtextRange,
|
|
206
|
+
cloneElement
|
|
207
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export class FakeDragAndDropClient {
|
|
2
|
+
async startDrag(event, dragData) {
|
|
3
|
+
await this.delay();
|
|
4
|
+
}
|
|
5
|
+
async startDragToPoint(event, dragData) {
|
|
6
|
+
await this.delay();
|
|
7
|
+
}
|
|
8
|
+
async startDragToCursor(event, dragData) {
|
|
9
|
+
await this.delay();
|
|
10
|
+
}
|
|
11
|
+
constructor(delay){
|
|
12
|
+
this.delay = delay;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export class FakeExportClient {
|
|
2
|
+
async queueDocument(request) {
|
|
3
|
+
await this.delay();
|
|
4
|
+
return {
|
|
5
|
+
status: 'completed',
|
|
6
|
+
exportBlobs: fakeExportBlobs
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
async requestExport(request) {
|
|
10
|
+
await this.delay();
|
|
11
|
+
return {
|
|
12
|
+
status: 'completed',
|
|
13
|
+
exportBlobs: fakeExportBlobs
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
constructor(delay){
|
|
17
|
+
this.delay = delay;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
const fakeExportBlobs = [
|
|
21
|
+
{
|
|
22
|
+
url: 'https://canva.dev/docs/apps/testing/'
|
|
23
|
+
}
|
|
24
|
+
];
|
|
@@ -14,3 +14,4 @@ export const getCurrentPageContext = canva_sdk.design.v2.designInteraction.getCu
|
|
|
14
14
|
export const initAppElement = canva_sdk.design.v2.designInteraction.initAppElement;
|
|
15
15
|
export const getDesignToken = canva_sdk.design.v2.designInteraction.getDesignToken;
|
|
16
16
|
export const createRichtextRange = canva_sdk.design.v2.designInteraction.createRichtextRange;
|
|
17
|
+
export const editContent = canva_sdk.design.v2.designInteraction.editContent;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './index';
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export function getCanvaSdk() {
|
|
2
|
+
return window.canva_sdk;
|
|
3
|
+
}
|
|
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;
|
|
9
|
+
throw new CanvaError({
|
|
10
|
+
code: 'failed_precondition',
|
|
11
|
+
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/"
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
export function injectFakeAPIClients(clients) {
|
|
16
|
+
window.canva_sdk = {
|
|
17
|
+
...getCanvaSdk(),
|
|
18
|
+
...clients
|
|
19
|
+
};
|
|
20
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@canva/design",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.0-beta.1",
|
|
4
4
|
"description": "The Canva Apps SDK design library",
|
|
5
5
|
"author": "Canva Pty Ltd.",
|
|
6
6
|
"license": "SEE LICENSE IN LICENSE.md FILE",
|
|
@@ -14,6 +14,11 @@
|
|
|
14
14
|
"types": "./beta.d.ts",
|
|
15
15
|
"require": "./lib/cjs/sdk/design/beta.js",
|
|
16
16
|
"import": "./lib/esm/sdk/design/beta.js"
|
|
17
|
+
},
|
|
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"
|
|
17
22
|
}
|
|
18
23
|
},
|
|
19
24
|
"typings": "./beta.d.ts"
|
package/test/beta.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @public
|
|
3
|
+
* Initializes a test environment for the `@canva/design` package, enabling unit tests to mock Canva's APIs.
|
|
4
|
+
* @remarks
|
|
5
|
+
* This method should only be called once in a test environment, such as in a Jest setup file.
|
|
6
|
+
* @see
|
|
7
|
+
* https://www.canva.dev/docs/apps/testing/
|
|
8
|
+
*/
|
|
9
|
+
export declare function initTestEnvironment(): void;
|
|
10
|
+
|
|
11
|
+
export {};
|