From c85531dc1253ac4d764e235deed2bb7fba9a2c84 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Tue, 26 Dec 2023 02:07:04 +0300 Subject: [PATCH] more work on attr support... still need testing... Signed-off-by: Alex A. Naanou --- experiments/outline-editor/editor.js | 57 +++++++++++++++++++-------- experiments/outline-editor/index.html | 20 ++-------- 2 files changed, 44 insertions(+), 33 deletions(-) diff --git a/experiments/outline-editor/editor.js b/experiments/outline-editor/editor.js index 287c917..0272cad 100755 --- a/experiments/outline-editor/editor.js +++ b/experiments/outline-editor/editor.js @@ -208,6 +208,7 @@ var attributes = { // .parseBlockAttrs([, ]) // -> [, , ] // + // XXX add attributes set in elem but not present in code to attrs/sysattrs... // XXX where should we get .__block_attrs__??? // ...editor (current), plugin, ...??? // XXX might be a good idea to split out the actual code handler to @@ -234,13 +235,17 @@ var attributes = { true : val == 'false' ? false - : val - // keep non-system attrs... - if(!(name in system)){ - attrs += `\n${name}::${val}` - } else { - sysattrs += `\n${name}::${val}` } } + : val } return ws }) + // 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){ + var val = elem[name] + if(!(name in system)){ + attrs += `\n${name}::${val}` + } else { + sysattrs += `\n${name}::${val}` } } return [ elem, attrs, @@ -248,26 +253,46 @@ var attributes = { ] }, // generate code... + // + // this is controlled by the value of editor.__code_attrs__: + // false / undefined - strip attrs + // true - add attrs to code if available + // 'all' - add attrs, including system attrs to + // code if available, __parse_code__: function(code, editor, elem){ var [elem, attrs, system] = this.parseBlockAttrs(editor, code, elem) return !editor.__code_attrs__ ? elem.text : editor.__code_attrs__ == 'all' ? - elem.text +'\n'+ attrs +'\n'+ system - : elem.text +'\n'+ attrs }, + elem.text + + (attrs.length > 0 ? + '\n'+ attrs + : '') + + (system.length > 0 ? + '\n'+ system + : '') + : attrs.length > 0 ? + elem.text +'\n'+ attrs + : elem.text }, + // generate view... + // + // this is controlled by the value of editor.__view_attrs__: + // false / undefined - strip attrs + // true - call the handler XXX __pre_parse__: function(text, editor, elem){ + // NOTE: we are intentionally neglecting system attrs here... var [elem, attrs, system] = this.parseBlockAttrs(editor, text, elem) - // XXX use filter handler here... - return !editor.__view_attrs__ ? - elem.text - : elem.text +'\n'+ attrs - }, + if(editor.__view_attrs__ + && attrs.length > 0){ + attrs = editor.threadPlugins('__parse_attrs__', attrs, editor, elem) + if(attrs && attrs.length > 0){ + return text +'\n'+ attrs } } + return elem.text }, // XXX - __parse_attrs__: function(){ - // XXX - } + //__parse_attrs__: function(attrs, editor, elem){ + // return attrs } } diff --git a/experiments/outline-editor/index.html b/experiments/outline-editor/index.html index 89aba68..41d4e01 100755 --- a/experiments/outline-editor/index.html +++ b/experiments/outline-editor/index.html @@ -143,25 +143,11 @@ var setup = function(){ - - ## ToDo: - ASAP: expand sub-tree on follow link... - - ASAP: attributes: finalize base mechanics: - - code filtering - ``` - .__code_attrs__(attrs, code, elem) - -> true - -> false - ``` - _system attrs are always hidden, the client can control whether the code is shown or not_ - - view filtering - ``` - .__view_attrs__(attrs, code, elem) - -> str - -> undefined - ``` - - might be a good idea to change `.parseBlockAttrs(..)` to return an array of text and attrs (str) and handle the above `.__code_attrs__(..)` and `.__view_attrs__(..)` in the respective handlers... + - ASAP TEST: attributes: finalize base mechanics... - attributes: need to show/hide the attributes -- option? attr::value - - `.__parse_code__(..)`: add data attributes to code if missing... - - do we need `.__code_attrs__` / `.__view_attrs__`??? + - DONE `.__parse_code__(..)`: add data attributes to code if missing... + - DONE do we need `.__code_attrs__` / `.__view_attrs__`??? -- YES - handle attr delete correctly -- i.e. if shown attr removed from code -> delete attr... - BUG? can't set `''` as attr value -- parser?? - TOC: tweaking: add args like depth, ... -- as attributes...