forked from hygraph/hygraph-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdialog.html
101 lines (92 loc) · 2.95 KB
/
dialog.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>GraphCMS Bynder Extension Dialog</title>
<style>
body {
margin: 0px;
}
#bynder {
height: 800px;
width: 100%;
}
</style>
<script src="https://cdn.jsdelivr.net/npm/@graphcms/[email protected]/lib/zoid.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@graphcms/[email protected]/dist/gcuix.umd.production.min.js"></script>
<script src="https://d8ejoa1fys2rk.cloudfront.net/5.0.5/modules/compactview/bynder-compactview-2-latest.js"></script>
</head>
<body>
<div id="bynder"></div>
<script>
(() => {
const declaration = {
extensionType: 'field',
fieldType: 'JSON',
name: 'Bynder',
description: '',
features: ['FieldRenderer'],
};
function deserialize(value) {
try {
return (value && JSON.parse(value)) || [];
} catch (error) {
console.log(error);
console.log('Invalid JSON: ' + value);
return null;
}
}
function serialize(value) {
try {
return value.length ? JSON.stringify(value) : '';
} catch (error) {
console.log(error);
return '';
}
}
document.addEventListener('DOMContentLoaded', async () => {
try {
window.GCUIX.init({
declaration,
}).then((initialState) => {
const { status, props } = initialState;
if (status === 'ok') {
const {
defaultDomain,
defaultDomainEditable,
allowedAssetTypes,
isList,
selectedAssetIds,
onCloseDialog,
} = props;
BynderCompactView.open({
container: document.getElementById('bynder'),
portal: {
url: defaultDomain || '',
editable: defaultDomainEditable,
},
language: 'en_US',
mode: props.isList ? 'MultiSelect' : 'SingleSelect',
assetTypes: deserialize(allowedAssetTypes) || [
'image',
'audio',
'video',
'document',
],
selectedAssets: deserialize(selectedAssetIds) || [],
onSuccess: function (assets, additionalInfo) {
onCloseDialog(serialize(assets));
},
});
}
});
} catch (error) {
console.error('Failed to init extension:', error.message);
console.error('- error code:', error.code);
}
});
})();
</script>
</body>
</html>