-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
95 lines (89 loc) · 3.46 KB
/
index.html
File metadata and controls
95 lines (89 loc) · 3.46 KB
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
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="utf-8">
<!-- We use lodash.throttle to avoid spamming the API with changes -->
<script src="https://cdn.jsdelivr.net/npm/lodash@4.17.4/lodash.min.js"></script>
<!-- load a custom version of Ace editor -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.2.6/ace.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jsoneditor/9.5.5/jsoneditor.min.js"
integrity="sha512-j54mlrSyC7F9BRZhRiEjFTq6ESmJYXdznKy8lJeqIVlQOxkVNkn8lCveNphcX7MMXnyNU774ZeiDDahKl3YyYg=="
crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jsoneditor/9.5.5/jsoneditor.css"
integrity="sha512-Sbn0ZCJ/Sq+RcpmI2np6vYlQBolmDPIrx95V3kOQU7RfEOWRCgEmDvj5lD4oNnx55KVIUfadYs8rk3OudD+dFA=="
crossorigin="anonymous" referrerpolicy="no-referrer" />
<script src="https://unpkg.com/@contentstack/ui-extensions-sdk@2.2.0/dist/ui-extension-sdk.js"></script>
<title>json-editor</title>
<script type="module" crossorigin>(function polyfill() {
const relList = document.createElement("link").relList;
if (relList && relList.supports && relList.supports("modulepreload")) return;
for (const link of document.querySelectorAll('link[rel="modulepreload"]')) processPreload(link);
new MutationObserver((mutations) => {
for (const mutation of mutations) {
if (mutation.type !== "childList") continue;
for (const node of mutation.addedNodes) if (node.tagName === "LINK" && node.rel === "modulepreload") processPreload(node);
}
}).observe(document, {
childList: true,
subtree: true
});
function getFetchOpts(link) {
const fetchOpts = {};
if (link.integrity) fetchOpts.integrity = link.integrity;
if (link.referrerPolicy) fetchOpts.referrerPolicy = link.referrerPolicy;
if (link.crossOrigin === "use-credentials") fetchOpts.credentials = "include";
else if (link.crossOrigin === "anonymous") fetchOpts.credentials = "omit";
else fetchOpts.credentials = "same-origin";
return fetchOpts;
}
function processPreload(link) {
if (link.ep) return;
link.ep = true;
const fetchOpts = getFetchOpts(link);
fetch(link.href, fetchOpts);
}
})();
let extensionField = {};
let typingTimer = 0;
var jsoneditorElement = document.getElementById("jsoneditor");
var jsonEditor = {};
ContentstackUIExtension.init().then(function(extension) {
extensionField = extension;
extensionField.window.updateHeight(400);
var value = extensionField.field.getData() || {};
var options = {
modes: ["text", "code", "tree", "form", "view"],
mode: "code",
ace,
onChange: function() {
clearTimeout(typingTimer);
typingTimer = setTimeout(updateFieldValue, 600);
}
};
jsonEditor = new JSONEditor(jsoneditorElement, options);
jsonEditor.set(value);
});
document.getElementById("jsoneditor");
var NewTag = document.createElement("span");
NewTag.className = "invalid";
var text = document.createTextNode("Invalid JSON format !!");
NewTag.appendChild(text);
function updateFieldValue() {
var value = jsonEditor.get();
extensionField.field.setData(value).then(function() {
console.log("data set on child");
}).catch(function(error) {
console.log("error in setting data", error);
});
}</script>
<style rel="stylesheet" crossorigin>body {
margin: 0;
}
#jsoneditor {
height: 380px;
}</style>
</head>
<body>
<div id="jsoneditor"></div>
</body>
</html>