From 66c3760be9dcf8aa5aa82b1a7d9bc1f8e2db6fb7 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Wed, 18 Oct 2023 14:41:49 +0300 Subject: [PATCH] bugfix... Signed-off-by: Alex A. Naanou --- experiments/outline-editor/editor.js | 166 +++++++++++++------------- experiments/outline-editor/index.html | 4 +- 2 files changed, 86 insertions(+), 84 deletions(-) diff --git a/experiments/outline-editor/editor.js b/experiments/outline-editor/editor.js index ee04ad0..5673529 100755 --- a/experiments/outline-editor/editor.js +++ b/experiments/outline-editor/editor.js @@ -197,6 +197,84 @@ var quoted = { } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +// XXX add actions... +var tasks = { + __proto__: plugin, + + updateStatus: function(editor, node){ + node = editor.get(node) + if(node == null){ + return this } + var state = node + .querySelector('.view') + .querySelector('.completion') + if(state){ + var c = + ((node.querySelectorAll('input[type=checkbox]:checked').length + / node.querySelectorAll('input[type=checkbox]').length) + * 100) + .toFixed(0) + !isNaN(c) + && state.setAttribute('completion', c +'%') } + return this }, + updateBranch: function(editor, node){ + if(!node){ + return this } + var outline = editor.outline + var p = node + while(p !== outline){ + this.updateStatus(editor, p) + p = editor.get(p, 'parent') } + return this }, + updateAll: function(editor){ + for(var e of [...editor.outline.querySelectorAll('.block>.view .completion')]){ + this.updateStatus(editor, e) } + return this }, + + __setup__: function(editor){ + return this.updateAll(editor) }, + __parse__: function(text, editor, elem){ + return text + // block checkboxes... + // NOTE: these are separate as we need to align block text + // to leading chekbox... + .replace(/^\s*(?')) + .replace(/^\s*(?')) + // inline checkboxes... + .replace(/\s*(?')) + .replace(/\s*(?')) + // completion... + // XXX add support for being like a todo checkbox... + .replace(/(?') }, + __editedcode__: function(evt, editor, node){ + return this.updateBranch(editor, node) }, + __click__: function(evt, editor, elem){ + // toggle checkbox... + if(elem.type == 'checkbox'){ + var node = editor.get(elem) + var text = node.querySelector('.code') + // get the checkbox order... + var i = [...node.querySelectorAll('input[type=checkbox]')].indexOf(elem) + var to = elem.checked ? + '[X]' + : '[_]' + var toggle = function(m){ + return i-- == 0 ? + to + : m } + text.value = text.value.replace(/\[[Xx_]\]/g, toggle) + // update status... + this.updateBranch(editor, node) } + return this }, +} + + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // XXX Hackish... @@ -262,9 +340,9 @@ var styling = { // elements... .replace(/(\n|^)(?') // basic styling... - // XXX revise... .replace(/(?$1') .replace(/(?$1') + // XXX this can clash with '[_] .. [_]' checkboxes... .replace(/(?$1') // code/quoting... //.replace(/(?.view .completion')]){ - this.updateStatus(editor, e) } - return this }, - - - __setup__: function(editor){ - return this.updateAll(editor) }, - __parse__: function(text, editor, elem){ - return text - // block checkboxes... - // NOTE: these are separate as we need to align block text - // to leading chekbox... - .replace(/^\s*(?')) - .replace(/^\s*(?')) - // inline checkboxes... - .replace(/\s*(?')) - .replace(/\s*(?')) - // completion... - // XXX add support for being like a todo checkbox... - .replace(/(?') }, - __editedcode__: function(evt, editor, node){ - return this.updateBranch(editor, node) }, - __click__: function(evt, editor, elem){ - // toggle checkbox... - if(elem.type == 'checkbox'){ - var node = editor.get(elem) - var text = node.querySelector('.code') - // get the checkbox order... - var i = [...node.querySelectorAll('input[type=checkbox]')].indexOf(elem) - var to = elem.checked ? - '[X]' - : '[_]' - var toggle = function(m){ - return i-- == 0 ? - to - : m } - text.value = text.value.replace(/\[[Xx_]\]/g, toggle) - // update status... - this.updateBranch(editor, node) } - return this }, -} - - //--------------------------------------------------------------------- @@ -402,6 +401,8 @@ var Outline = { carot_jump_edge_then_block: false, + // Plugins... + // // The order of plugins can be significant in the following cases: // - parsing // - event dropping @@ -409,11 +410,14 @@ var Outline = { attributes, blocks, quoted, + + // NOTE: this needs to be before styling to prevent it from + // treating '[_] ... [_]' as italic... + tasks, styling, tables, symbols, syntax, - tasks, // keep this last... // XXX revise -- should this be external??? diff --git a/experiments/outline-editor/index.html b/experiments/outline-editor/index.html index 78116cf..727269d 100755 --- a/experiments/outline-editor/index.html +++ b/experiments/outline-editor/index.html @@ -44,12 +44,10 @@ var setup = function(){ - // Seems that I unintentionally implemented quite a chunk of the markdown spec ;) - - ## Bugs: - - BUG: last node seems to get trash tags added to it's end... - - BUG: checkboxes bust be parsed BEFORE styling... - - [_] two unchecked [_] checkboxes get interpreted as italic... - BUG: exiting a node via arrow keys does not update status (click works)... - [_] some [X] text [%] - _likely need to handle an extra event..._ + - BUG: last node seems to get trash tags added to it's end... - - ## ToDo: - ASAP: checkbox navigation via `alt-`