-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
152 lines (143 loc) · 5.06 KB
/
index.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<!DOCTYPE html>
<html dir="ltr" lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=5.0" />
<title>INCLDE Demo</title>
<script type="module" src="build/inclde.esm.js"></script>
<script nomodule src="build/inclde.js"></script>
<link rel="stylesheet" href="https://unpkg.com/chota@latest">
<style>
.fit-width {
margin-left: 0;
margin-right: 0;
}
.card {
height: 100%;
}
#preview pre {
max-height: 90vh;
margin: 0;
}
</style>
</head>
<body>
<div class="container">
<h1>INCLDE Demonstrator</h1>
<p>
INCLDE (pronounced "/ɪnˈkluːd/", as "include") stands for <strong>Inc</strong>ludable <strong>L</strong>inked <strong>D</strong>ata <strong>E</strong>ditor.
This page demonstrates the integration of the editor into another page.
Imagine this is some research environment. It could be a digital lab notebook, a research data repository, or a research data management system.
You are at a point where you would like to input some research metadata or data. The following component shall offer an easy environment to do so.
You can try the editor right here. (Note: Clicking the green "save" button will trigger a download of the data as a JSON-LD file.)
[<a href="https://github.com/kit-data-manager/INCLDE">Code & Documentation</a>]
[<a href="https://www.npmjs.com/package/@kit-data-manager/inclde">NPM Package</a>]
</p>
<div id="slider-form">
<input type="range" id="column-slider" min="0" max="6" value="6" step="1" class="hide" />
<label for="column-slider">Show JSON-LD preview (not part of the editor)</label>
<style>
#slider-form {
/* hiding slider until the preview event works properly */
/*display: flex;*/
display: none;
flex-direction: row;
align-items: center;
justify-content: center;
}
#column-slider {
width: 20rem;
vertical-align: middle;
margin: 0;
padding: 0;
}
</style>
<script>
var columnClass = "col-0";
let slider = document.getElementById("column-slider");
slider.addEventListener("input", function() {
let preview = document.getElementById("preview");
let columnWidth = (this.attributes.max.value - this.value);
let newColumnClass = "col-" + columnWidth;
if (columnWidth === 0) {
preview.style.display = "none";
preview.classList.remove(columnClass);
} else {
preview.style.display = "block";
preview.classList.remove(columnClass);
preview.classList.add(newColumnClass);
}
columnClass = newColumnClass;
});
</script>
</div>
</div>
<hr />
<div class="row fit-width">
<div id="editor" class="col card"></div>
<div id="preview" class="card" style="display: none;">
<p>Data preview</p>
<pre id="output">JSON preview will appear here after changes!</pre>
</div>
</div>
<script>
const config = {
"title": "INCLDE Demo Instance",
"hideAttributesByDefault": false,
"allowNewAttributes": true,
"attributConfig": [
{
"onType": "*",
"attributes": [
{
"name": "@id",
"readOnly": true,
"hidden": false
}
]
},
{
"onId": "https://adhesivewombat.bandcamp.com/track/8-bit-adventure",
"attributes": [
{
"name": "http://schema.org/duration",
"hidden": true
}
]
}
]
}
function downloadStringAsFile(data, filename, mimeType) {
const blob = new Blob([data], { type: mimeType });
const url = window.URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = filename;
document.body.appendChild(a);
a.click();
window.URL.revokeObjectURL(url);
}
fetch("samples/bandcamp.jsonld")
.then((response) => response.json())
.then((data) => {
console.log("Successfully fetched data", data);
const editor = document.createElement("inclde-editor");
editor.data = data;
editor.config = config;
document.getElementById("editor").appendChild(editor);
let result = JSON.stringify(data, null, 2);
document.getElementById("output").textContent = result
editor.addEventListener('editorClosed', event => {
console.log('event', event.detail);
const result = JSON.stringify(event.detail, null, 2);
downloadStringAsFile(result, "output.jsonld", "application/ld+json");
})
editor.addEventListener('dataUpdated', event => {
console.log('event', event.detail);
let result = JSON.stringify(event.detail, null, 2);
document.getElementById("output").textContent = result
})
});
</script>
</body>
</html>