@canva/design 2.2.1 → 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/{index.d.ts → beta.d.ts} +888 -58
- package/lib/cjs/sdk/design/{index.js → beta.js} +19 -2
- 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/{index.js → beta.js} +4 -1
- 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 +12 -12
- package/test/beta.d.ts +11 -0
|
@@ -1,7 +1,21 @@
|
|
|
1
|
-
"use strict"
|
|
1
|
+
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
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
|
+
initAppElement: function() {
|
|
13
|
+
return initAppElement;
|
|
14
|
+
},
|
|
15
|
+
openDesign: function() {
|
|
16
|
+
return openDesign;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
5
19
|
_export_star(require("./public"), exports);
|
|
6
20
|
function _export_star(from, to) {
|
|
7
21
|
Object.keys(from).forEach(function(k) {
|
|
@@ -17,4 +31,7 @@ function _export_star(from, to) {
|
|
|
17
31
|
return from;
|
|
18
32
|
}
|
|
19
33
|
var _window___canva___sdkRegistration, _window___canva__;
|
|
20
|
-
|
|
34
|
+
const { canva_sdk } = window;
|
|
35
|
+
const initAppElement = canva_sdk.design.v2.designInteraction.initAppElement;
|
|
36
|
+
const openDesign = canva_sdk.design.v2.designInteraction.openDesign;
|
|
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,3 +1,6 @@
|
|
|
1
1
|
var _window___canva___sdkRegistration, _window___canva__;
|
|
2
|
+
const { canva_sdk } = window;
|
|
3
|
+
export const initAppElement = canva_sdk.design.v2.designInteraction.initAppElement;
|
|
4
|
+
export const openDesign = canva_sdk.design.v2.designInteraction.openDesign;
|
|
2
5
|
export * from './public';
|
|
3
|
-
(_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
|
+
}
|