@canva/design 2.4.0-beta.1 → 2.4.1-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 +4 -4
- package/lib/cjs/sdk/utils/canva_sdk.js +24 -0
- package/lib/esm/sdk/utils/canva_sdk.js +21 -0
- package/package.json +1 -1
package/beta.d.ts
CHANGED
|
@@ -1932,7 +1932,7 @@ export declare type OverlayOpenableEvent<Target extends OverlayTarget> = {
|
|
|
1932
1932
|
* @remarks
|
|
1933
1933
|
* This can be any type of structured data.
|
|
1934
1934
|
*/
|
|
1935
|
-
launchParameters?:
|
|
1935
|
+
launchParameters?: unknown;
|
|
1936
1936
|
}) => Promise<AppProcessId>;
|
|
1937
1937
|
};
|
|
1938
1938
|
}[Target];
|
|
@@ -2619,7 +2619,7 @@ export declare interface UI {
|
|
|
2619
2619
|
* @param event - A drag start event.
|
|
2620
2620
|
* @param dragData - Element or content to be added to the design at the end of the drag event.
|
|
2621
2621
|
*/
|
|
2622
|
-
startDrag<E extends
|
|
2622
|
+
startDrag<E extends Element>(
|
|
2623
2623
|
event: DragStartEvent<E>,
|
|
2624
2624
|
dragData:
|
|
2625
2625
|
| TextDragConfig
|
|
@@ -2635,7 +2635,7 @@ export declare interface UI {
|
|
|
2635
2635
|
* @param event - A drag start event.
|
|
2636
2636
|
* @param dragData - Element or content to be added to the design at the end of the drag event.
|
|
2637
2637
|
*/
|
|
2638
|
-
startDragToPoint<E extends
|
|
2638
|
+
startDragToPoint<E extends Element>(
|
|
2639
2639
|
event: DragStartEvent<E>,
|
|
2640
2640
|
dragData:
|
|
2641
2641
|
| TextDragConfig
|
|
@@ -2651,7 +2651,7 @@ export declare interface UI {
|
|
|
2651
2651
|
* @param event - A drag start event.
|
|
2652
2652
|
* @param dragData - Element or content to be added to the design at the end of the drag event.
|
|
2653
2653
|
*/
|
|
2654
|
-
startDragToCursor<E extends
|
|
2654
|
+
startDragToCursor<E extends Element>(
|
|
2655
2655
|
event: DragStartEvent<E>,
|
|
2656
2656
|
dragData:
|
|
2657
2657
|
| EmbedDragConfig
|
|
@@ -12,6 +12,9 @@ _export(exports, {
|
|
|
12
12
|
assertIsTestCanvaSdk: function() {
|
|
13
13
|
return assertIsTestCanvaSdk;
|
|
14
14
|
},
|
|
15
|
+
bindMethodsToClients: function() {
|
|
16
|
+
return bindMethodsToClients;
|
|
17
|
+
},
|
|
15
18
|
getCanvaSdk: function() {
|
|
16
19
|
return getCanvaSdk;
|
|
17
20
|
},
|
|
@@ -34,8 +37,29 @@ function assertIsTestCanvaSdk() {
|
|
|
34
37
|
}
|
|
35
38
|
}
|
|
36
39
|
function injectFakeAPIClients(clients) {
|
|
40
|
+
bindMethodsToClients(clients);
|
|
37
41
|
window.canva_sdk = {
|
|
38
42
|
...getCanvaSdk(),
|
|
39
43
|
...clients
|
|
40
44
|
};
|
|
41
45
|
}
|
|
46
|
+
function bindMethodsToClients(objectToBind) {
|
|
47
|
+
if (typeof objectToBind !== 'object' || objectToBind == null)
|
|
48
|
+
return;
|
|
49
|
+
const classMethods = new Set();
|
|
50
|
+
let currentPrototype = Object.getPrototypeOf(objectToBind);
|
|
51
|
+
while(currentPrototype && currentPrototype !== Object.prototype){
|
|
52
|
+
Object.getOwnPropertyNames(currentPrototype).forEach((method)=>classMethods.add(method));
|
|
53
|
+
currentPrototype = Object.getPrototypeOf(currentPrototype);
|
|
54
|
+
}
|
|
55
|
+
classMethods.delete('constructor');
|
|
56
|
+
for (const method of classMethods) {
|
|
57
|
+
const originalFn = objectToBind[method];
|
|
58
|
+
if (typeof originalFn === 'function') Object.defineProperty(objectToBind, method, {
|
|
59
|
+
value: (...args)=>{
|
|
60
|
+
return originalFn.call(objectToBind, ...args);
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
Object.values(objectToBind).forEach(bindMethodsToClients);
|
|
65
|
+
}
|
|
@@ -13,8 +13,29 @@ export function assertIsTestCanvaSdk() {
|
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
15
|
export function injectFakeAPIClients(clients) {
|
|
16
|
+
bindMethodsToClients(clients);
|
|
16
17
|
window.canva_sdk = {
|
|
17
18
|
...getCanvaSdk(),
|
|
18
19
|
...clients
|
|
19
20
|
};
|
|
20
21
|
}
|
|
22
|
+
export function bindMethodsToClients(objectToBind) {
|
|
23
|
+
if (typeof objectToBind !== 'object' || objectToBind == null)
|
|
24
|
+
return;
|
|
25
|
+
const classMethods = new Set();
|
|
26
|
+
let currentPrototype = Object.getPrototypeOf(objectToBind);
|
|
27
|
+
while(currentPrototype && currentPrototype !== Object.prototype){
|
|
28
|
+
Object.getOwnPropertyNames(currentPrototype).forEach((method)=>classMethods.add(method));
|
|
29
|
+
currentPrototype = Object.getPrototypeOf(currentPrototype);
|
|
30
|
+
}
|
|
31
|
+
classMethods.delete('constructor');
|
|
32
|
+
for (const method of classMethods) {
|
|
33
|
+
const originalFn = objectToBind[method];
|
|
34
|
+
if (typeof originalFn === 'function') Object.defineProperty(objectToBind, method, {
|
|
35
|
+
value: (...args)=>{
|
|
36
|
+
return originalFn.call(objectToBind, ...args);
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
Object.values(objectToBind).forEach(bindMethodsToClients);
|
|
41
|
+
}
|