From 9348afd5c82243fa3c65894f6afafe42b406047a Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Tue, 26 Dec 2023 04:30:09 +0300 Subject: [PATCH] made system attrs safe from being overwritten from code directly... Signed-off-by: Alex A. Naanou --- experiments/outline-editor/editor.js | 17 +++++++++++++++-- experiments/outline-editor/index.html | 1 + 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/experiments/outline-editor/editor.js b/experiments/outline-editor/editor.js index c241b3e..0739ddb 100755 --- a/experiments/outline-editor/editor.js +++ b/experiments/outline-editor/editor.js @@ -203,13 +203,14 @@ var plugin = { var attributes = { __proto__: plugin, + // XXX should attr settings be set here or in the Outline??? + // ...this includes .__block_attrs__ and .__system_attrs__ + // // Parse attrs... // .parseBlockAttrs([, ]) // -> [, , ] // - // XXX where should we get .__block_attrs__??? - // ...editor (current), plugin, ...??? parseBlockAttrs: function(editor, text, elem={}){ var system = editor.__block_attrs__ var attrs = '' @@ -227,6 +228,9 @@ var attributes = { .split(/(?:[\t ]*::[\t ]*|[\t ]*\n[\t ]*)/g) while(match.length > 0){ var [name, val] = match.splice(0, 2) + // ignore non-settable attrs... + if(editor.__system_attrs__.includes(name)){ + continue } elem[name] = val == 'true' ? true @@ -234,10 +238,14 @@ var attributes = { false : val } return ws }) + // build the attr strings... // NOTE: we are not doing this in the loop above to include all // the attributes that are in the elem but not explicitly // given in code... for(var name in elem){ + // ignore non-settable attrs... + if(editor.__system_attrs__.includes(name)){ + continue } var val = elem[name] if(!(name in system)){ attrs += `\n${name}::${val}` @@ -925,12 +933,17 @@ var JSONOutline = { __code_attrs__: false, __view_attrs__: false, + __system_attrs__: [ + 'text', + 'children', + ], __block_attrs__: { id: 'attr', collapsed: 'attr', focused: 'cls', }, + // Plugins... // // The order of plugins can be significant in the following cases: diff --git a/experiments/outline-editor/index.html b/experiments/outline-editor/index.html index 41d4e01..1495a22 100755 --- a/experiments/outline-editor/index.html +++ b/experiments/outline-editor/index.html @@ -275,6 +275,7 @@ var setup = function(){ - `` -- field marker - each child node will copy the template and allow editing of only fields - not clear how to handle template changes... + - DONE attributes: might be a good idea to prevent setting `.text` and `.children` attrs... - DONE TOC: Q: should we have both manual and auto headings??? collapsed:: true - IMHO: no...