Skip to content

Commit b16b510

Browse files
committed
Set main editor to empty.
Sadly, this now (like the existing Playground) throws a linting error by default...
1 parent 557dbf1 commit b16b510

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

playground/next/editor.mjs

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,21 @@ function editorListener(docName) {
9090
changes.push(update.state.doc.toString());
9191
debounce((docName) => {
9292
// set the global `doc` to the latest string from the editor
93-
try {
94-
const parsed = JSON.parse(changes[changes.length-1]);
95-
this[docName] = parsed;
93+
const latestChange = changes[changes.length-1];
94+
if (latestChange === '') {
95+
this[docName] = '';
9696
this.parseError = '';
97-
} catch (err) {
98-
this.parseError = err.message;
99-
};
97+
setEditorValue(readOnlyEditor, '');
98+
return;
99+
} else {
100+
try {
101+
const parsed = JSON.parse(latestChange);
102+
this[docName] = parsed;
103+
this.parseError = '';
104+
} catch (err) {
105+
this.parseError = err.message;
106+
};
107+
}
100108
}, 1000).call(this, docName);
101109
}
102110
});
@@ -249,7 +257,7 @@ const jsonLdHighlightTheme = EditorView.baseTheme({
249257
function initEditor(id, content, varName) {
250258
return new EditorView({
251259
parent: document.getElementById(id),
252-
doc: JSON.stringify(content, null, 2),
260+
doc: (content === 'object' ? JSON.stringify(content, null, 2) : ''),
253261
extensions: [
254262
basicSetup,
255263
keymap.of([indentWithTab]),
@@ -267,7 +275,7 @@ const language = new Compartment();
267275

268276
const readOnlyEditor = new EditorView({
269277
parent: document.getElementById('read-only-editor'),
270-
doc: `{}`,
278+
doc: '',
271279
extensions: [
272280
basicSetup,
273281
language.of(json()),
@@ -302,7 +310,7 @@ function setEditorValue(_editor, doc, lang) {
302310
}
303311

304312
window.app = createApp({
305-
doc: {},
313+
doc: '',
306314
contextDoc: {},
307315
frameDoc: {},
308316
tableQuads: {},
@@ -423,6 +431,7 @@ window.app = createApp({
423431
this.setOutputTab(this.outputTab);
424432
},
425433
async setOutputTab(value) {
434+
if (!value || !this.doc) return;
426435
if (value) this.outputTab = value;
427436
let context = this.contextDoc;
428437
switch (this.outputTab) {
@@ -553,7 +562,7 @@ window.app = createApp({
553562
'frameDoc');
554563
},
555564
initMainEditor() {
556-
this.mainEditor = initEditor.call(this, 'editor', {}, 'doc');
565+
this.mainEditor = initEditor.call(this, 'editor', '', 'doc');
557566
},
558567
copyContext() {
559568
this.contextDoc = {

playground/next/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ <h2 class="ui massive header">JSON-LD Playground</h2>
294294
<div class="ui error message" v-show="parseError" v-text="parseError"></div>
295295
<!-- outputs and renderings -->
296296
<div class="ui top attached tabular menu">
297-
<div v-for="(tab, key) in tabs" :class="{ active: outputTab == key }" class="item" @click="setOutputTab(key)"><i class="icon" :class="tab.icon"></i> <span v-text="tab.label"></span></div>
297+
<div v-for="(tab, key) in tabs" :class="{ active: outputTab == key, disabled: doc === '' }" class="item" @click="setOutputTab(key)"><i class="icon" :class="tab.icon"></i> <span v-text="tab.label"></span></div>
298298
</div>
299299
<div class="ui fitted resizable active bottom attached tab segment">
300300
<div class="ui very compact divided grid">

0 commit comments

Comments
 (0)