From 141641bd29004c21a211a1ef65fd51badf3f7563 Mon Sep 17 00:00:00 2001 From: jean-emmanuel Date: Wed, 4 Oct 2017 18:30:02 +0200 Subject: [PATCH] editor: parse inputs with JSON5 instead of JSON, it's more flexible and will avoid many typing errors --- CHANGELOG.md | 2 ++ package.json | 1 + resources/docs/editing-sessions.md | 3 +++ src/browser/js/app/editor/edit-objects.js | 3 ++- 4 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3bf87750..4f761919 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,8 @@ - messages received almost simultaneously are now bundled before being sent to the clients. This helps preserving their order. - widgets - sliders/pads: when receiving feedback while touched, the widget waits to be released before updating to the latest received value. +- editor + - property fields are now parsed using [JSON5](https://github.com/json5/json5), a more flexible notation. Session files are still using the standard JSON format, this is just a way to avoid typing mistakes when using the editor. ## 0.20.3 diff --git a/package.json b/package.json index a591db5a..9256e27c 100644 --- a/package.json +++ b/package.json @@ -30,6 +30,7 @@ "exorcist": "1.0.0", "file-saver": "^1.3.3", "jquery": "3.2.1", + "json5": "^0.5.1", "kiwi.js": "1.0.1", "licensify": "3.1.3", "mathjs": "3.16.4", diff --git a/resources/docs/editing-sessions.md b/resources/docs/editing-sessions.md index d9af44d9..edb43d5a 100644 --- a/resources/docs/editing-sessions.md +++ b/resources/docs/editing-sessions.md @@ -36,6 +36,9 @@ By default, widget resizing / dragging snaps to a 10 pixel wide grid. Its width Selected widget's properties are displayed and can be modified in the sidepanel. The [widgets reference](widgets/widgets) section lists the available properties for each widget type. Property fields are all multiline (press `shit + enter` for new line). +Properties are written in JSON, with some flexibility brought by the [JSON5](https://github.com/json5/json5) format. For example, doubles quotes around object keys are not mandatory. All input will be converted to standard JSON. + + ## Widget resizing / dragging Selected widget can be resized using its south, south-east and east handles. It can be dragged with its north-west handle. diff --git a/src/browser/js/app/editor/edit-objects.js b/src/browser/js/app/editor/edit-objects.js index a557822b..f0f9d443 100644 --- a/src/browser/js/app/editor/edit-objects.js +++ b/src/browser/js/app/editor/edit-objects.js @@ -1,6 +1,7 @@ var updateDom = require('./data-workers').updateDom, {widgets, categories} = require('../widgets'), {icon} = require('../utils'), + JSON5 = require('json5'), defaults = {} for (var k in widgets) { @@ -101,7 +102,7 @@ var editObject = function(container, data, refresh){ v try { - v = JSON.parse(input.val()) + v = JSON5.parse(input.val()) } catch(err) { v = input.val() }