@canva/design 2.4.0 → 2.4.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 +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 +2 -2
package/index.d.ts
CHANGED
|
@@ -1169,7 +1169,7 @@ export declare type OverlayOpenableEvent<Target extends OverlayTarget> = {
|
|
|
1169
1169
|
* @remarks
|
|
1170
1170
|
* This can be any type of structured data.
|
|
1171
1171
|
*/
|
|
1172
|
-
launchParameters?:
|
|
1172
|
+
launchParameters?: unknown;
|
|
1173
1173
|
}) => Promise<AppProcessId>;
|
|
1174
1174
|
};
|
|
1175
1175
|
}[Target];
|
|
@@ -1851,7 +1851,7 @@ export declare interface UI {
|
|
|
1851
1851
|
* @param event - A drag start event.
|
|
1852
1852
|
* @param dragData - Element or content to be added to the design at the end of the drag event.
|
|
1853
1853
|
*/
|
|
1854
|
-
startDrag<E extends
|
|
1854
|
+
startDrag<E extends Element>(
|
|
1855
1855
|
event: DragStartEvent<E>,
|
|
1856
1856
|
dragData:
|
|
1857
1857
|
| TextDragConfig
|
|
@@ -1867,7 +1867,7 @@ export declare interface UI {
|
|
|
1867
1867
|
* @param event - A drag start event.
|
|
1868
1868
|
* @param dragData - Element or content to be added to the design at the end of the drag event.
|
|
1869
1869
|
*/
|
|
1870
|
-
startDragToPoint<E extends
|
|
1870
|
+
startDragToPoint<E extends Element>(
|
|
1871
1871
|
event: DragStartEvent<E>,
|
|
1872
1872
|
dragData:
|
|
1873
1873
|
| TextDragConfig
|
|
@@ -1883,7 +1883,7 @@ export declare interface UI {
|
|
|
1883
1883
|
* @param event - A drag start event.
|
|
1884
1884
|
* @param dragData - Element or content to be added to the design at the end of the drag event.
|
|
1885
1885
|
*/
|
|
1886
|
-
startDragToCursor<E extends
|
|
1886
|
+
startDragToCursor<E extends Element>(
|
|
1887
1887
|
event: DragStartEvent<E>,
|
|
1888
1888
|
dragData:
|
|
1889
1889
|
| 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
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@canva/design",
|
|
3
|
-
"version": "2.4.
|
|
3
|
+
"version": "2.4.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",
|
|
@@ -22,4 +22,4 @@
|
|
|
22
22
|
}
|
|
23
23
|
},
|
|
24
24
|
"typings": "./index.d.ts"
|
|
25
|
-
}
|
|
25
|
+
}
|