- # Outline editor prototype - An outline-based markdown editor experiment - ### Infuences:: - Logseq - Conboy (Nokia N900's Tomboy clone) - Bonsai (on PalmOS) - Google Keep (editor) - - // Seems that I unintentionally implemented quite a chunk of the markdown spec ;) - - ## Bugs: focused:: true - BUG: caret positioning broken - Example: - text text text <div> block element </div> this line, and above placement of completely broken - _this seems to be an issue with: `.getMarkdownOffset(..)`_ - ``` m = `text text text <div> block element </div> this line, and above placement of completely broken` t = 'text text text\n\n\nblock element\n\n\nthis line, and above placement of completely broken ' getMarkdownOffset(m, t, 26) ``` this returns `69` while it should return `5` _...replacing `\n\n\n` with `\n\n` seems to fix the issue (also works with spaces)_ (BUG also the above line is not italic -- can't reproduce) - clicking right of the last line places cursor wrong - DONE M M can't place cursor before first char M - DONE text text text ``` text text text ``` text text text - DONE text text text _text text text_ text text text - DONE _text text text_ text text text - DONE ``` text text text ``` text text text - BUG: parser: code blocks do not ignore single back-quotes... - ``` x = `moo` ``` - _this also leads to double quoting of html..._ ``` x = `<i>moo</i>` ``` - BUG: mobile browsers behave quite chaotically ignoring parts of the styling... - FF: - zooming on edited field - normal textarea is not sized correctly - General: - side margins are a bit too large (account for toolbat to the right) - - ## ToDo: - Q: can we place a cursor in a table correctly??? - custom element / web component - BUG: select via double/triple clicks does not work... - _looks like something is refocusing the element..._ - BUG/race: the non-value versions of custom elem seem to sometimes get loaded as empty... - DONE data interface: collapsed:: true - the "natural" way to pass data is to use the same mechanism as `<textarea>` the problem is that we can't extend `HTMLTextAreaElement` as it can not have shadow dom (reject?) - adding an explicit textarea element is an odd requirement (reject?) - seems that the least bad way to go is to use the `value` attribute - DONE API: directly mixin Outline? - DONE `.value` / `.code` should be both updated internally and also load new content when updated externally -- not yet sure how... - events - test nesting... - Q: can we get rid of the editor block??: - CSS breaks if we do... - need to figure out a way to handle autofocus for host/editor uniformly - - selection - DONE multiple node selection (via shift+motion) - fixed state -- while `shift` pressed select or deselect only depending on first action (a-la FAR) - DONE double/triple click working... - delete - copy/cut/past (???) - touch/mouse (???) - Q: should we select text (mouse/touch) without first focusing?? - _...logseq does not do this either_ - now this is possible by dragging from a click zone... - copy/paste nodes/trees - numbered lists: add counters to a depth of 6-7... - _or find a way to make them repeat..._ - FEATURE: read-only mode - FEATURE: auto-shift done blocks to the end of siblings... (option?) - ...or should this be `sort:: done` -- i.e. sort children by done status?? - codeblock as a block _...if only whitespace before/after clear it and style whole block..._ _...might be a good idea to do this with codeblock at start/end of block..._ - Code blocks and bullets: - ``` code ``` - _bullet should be either in the middle of the block or at the first line of code (preferred)..._ - export html - embed css - cleanup html - generate ideomatic html (???) - style attrs (see: [attrs](#attributes)) - FF: figure out a way to draw expand/collapse bullets without the use of CSS' `:has(..)` - table inline editing a-la code editing -- click cell and edit directly... - smooth scrolling - _...this is more complicated than adding `behavior: "smooth"` to `.scrollIntoView(..)` as scrolling animation will get interrupted by next user input..._ - need to cancel animation if things are moving too fast... - make this generic (???) - JSON API - cli - Q: do we use \\t for indent? (option???) - Q: persistent empty first/last node (a button to create a new node)? - Q: search? - _seems that search should be external to the editor_ - empty item height is a bit off... - Nerd fonts (option???) - FEATURE: `collapse-children:: true` block option -- when loading collapse all immediate children - FEATURE? block templates... collapsed:: true - something like: `TPL: [_] <editable/> -- <editable/>` - `TPL:` -- template marker - `<editable/>` -- field marker - each child node will copy the template and allow editing of only fields - not clear how to handle template changes... - DONE selecting expanded code by _click-n-drag_ collapsed:: true - # this is a test string with some extra words - DONE `backspace`/`delete` in block contract the field with a delay... collapsed:: true - _...looks like we are updating size on keyup..._ - DONE Q: should list bullets be on the same level as nodes or offset?? collapsed:: true - A) justified to bullet: ``` * list item * list item block text ``` _This is impossible to create in the current implementation_ - B) justified to text _(current)_: ``` * list item * list item block text ``` - DONE add horizontal scroll to code blocks... collapsed:: true - ```html <outline-editor session-storage="outline-text" value="initial text"></outline-editor> ``` - DONE trailing whitespace is ignored in `.view`... collapsed:: true - demos: - leading whitespace... - trailing whitespace... - empty block\: - - _it seams that HTML ignores the last newline if it is not followed by anything_ - there are four ways to deal with this:# - trim whitespace on refocus (option) - show whitespace in both modes (option) - REJECT remove trailing whitespace completely on refocus (a-la logseq) - REJECT keep current behavior - I do not believe in keeping whitespace in edit and hiding it in view (POLS) - DONE add options to save to `.sessionStorage` / `.localStorage` - DONE might be a good idea to focus the prev (empty) node if pressing `Enter` at 0 position collapsed:: true - <- place cursor here and press enter - DONE make `---` block not show list bullets... - DONE: undo: checkboxes and DONE?? collapsed:: true _...this should be triggered by text change -- move current implementation to .__editedcode__()??..._ - DONE undo - DONE crop: make path clickable - DONE Q: crop: should we control crop via "crop-in"/"crop-out" instead of crop/uncrop?? collapsed:: true - _crop-in/crop-out seems more natural..._ - DONE crop: show crop path (and depth) - DONE over-travel pause -- when going fast over start/end stop... - DONE focus: collapsed:: true - DONE `<editor>.autofocus` - DONE `focused:: true` attr (`.text(..)`/`.json(..)`/`.load(..)`) - DONE focusing editor -> focus focused block - DONE identify a block: collapsed:: true - DONE index (flat) - DONE path (index) - DONE id - _the id attr is done, but we still need to get the node via id_ - DONE pgup/pgdown/home/end buttons - DONE FEATURE: "crop" -- view block tree separately... - DONE unify attr parsing collapsed:: true - _now duplicated in `.parse(..)` and `.__code2html__(..)`_ - might be a good idea to add a special text parse stage and use in on both branches... - DONE attrs in editor are not parsed correctly (see: [attrs](#attributes)) - DONE multiple attrs are not handled correctly (see: [attrs](#attributes)) - DONE call `.sync()` on all changes... - DONE show list bullet if node is empty but edited... collapsed:: true - _...not sure which is best, so both options are available, see: `editor.css`_ - DONE Q: can we get the caret line in a textarea??? collapsed:: true - _...this will fix a lot of issues with moving between blocks in edit mode..._ - DONE Q: can we place the cursor on item click where it was clicked before before the code expanded? collapsed:: true - for example - #### Click in this line and see where the cursor goes - _not sure how..._ - DONE click to select/edit node must retain click position in text... - DONE checkbox navigation via `alt-<arrow>` collapsed:: true - _might be a good idea to include also TODO/DONE navigation -- not yet sure how to mark undone blocks (i.e. the ones marked with TODO in Logseg)..._ - toggle with `space` - navigation auto-selects first checkbox - DONE editor: backsapce/del at start/end of a block should join it with prev/next - DONE editor: pressing enter in text edit mode should split text into two blocks - DONE editor: shifting nodes up/down - DONE Q: can we edit code in a code block directly? (a-la Logseq) - DONE "percentage complete" in parent blocks with todo's nested - DONE `.editor .outline:empty` view and behavior... - DONE editor: semi-live update styles - DONE do a better expand/collapse icons - DONE loading from DOM -- fill textarea - DONE focus management - DONE mouse/touch controls - DONE navigation - DONE expand/collapse subtree - DONE shift subtree up/down - DONE create node - DONE edit node - DONE serialize/deserialize - DONE add optional text styling to nodes - - ## Refactoring: - Q: Implementation: JSON-based, DOM-based (current) or both? - implement JSON-based - compare and decide... - Plugin architecture - DONE basic structure - plugin handler sequencing (see: `<editor>.setup(..)`) - DONE plugin handler canceling (see: `<editor>.runPlugins(..)`) - DONE Item parser (`.__code2html__(..)`) collapsed:: true - DONE split out - DONE define a way to extend/stack parsers - DONE Format parser/generator collapsed:: true - DONE split out - DONE define api (see: `<editor>.__code2text__(..) / <editor>.__text2code__(..)`) - CSS - DONE nested rules (experiment) - separate out settings - separate out theming - Actions -- move user actions (code in `.keyboard`) into methods - Move to `keyboard.js` - Q: do we need a concatenative API?? - `<block>.get() -> <block>` - Docs - - ## Docs - ### Use - Minimal ```html <outline-editor></outline-editor> ``` - Session-stored ```html <outline-editor session-storage="outline-text" value="initial text"></outline-editor> ``` - #### Attributes: - `value` - `session-storage` - `local-storage` - ### Controls - ASAP: these need updating... - | Key | Action | | up | focus node above | | down | focus node below | | left | focus parent node | | right | focus first child node | | tab | indent node | | s-tab | deindent node | | s-pgup | shift node up | | s-pgdown | shift node down | | s-left | collapse node | | s-right | expand node | | c-left | prev checkbox | | c-right | next checkbox | | space | toggle checkbox | | a-s | toggle status | | a-x | toggle status DONE | | a-r | toggle status REJECT | | c-z | normal: undo | | c-s-z | normal: redo | | c | normal: crop current node | | enter | normal: edit node | | | edit: create node below | | esc | crop: exit crop | | | edit: exit edit mode | - ### Formatting - The formatting mostly adheres to the markdown spec with a few minor differences - - Styles: - # Heading 1 - ## Heading 2 - ### Heading 3 - #### Heading 4 - ##### Heading 5 - ###### Heading 6 - Text - Lists:: - bullet: - a: collapsed:: true - bullets: - in: - very: - deep: - list: - of: - items: - b - c - numbered# - a - b# - x# collapsed:: true - bullets# - in# - very# - deep# - list# - of# - items# - y - z - c - > quote - Notes - NOTE: a note text - NOTE: - a root note can also be empty - click on the outer border to edit root - // C-style comment - ; ASM-style comment - XXX Highlight - Status (toggle all via: `alt-s`) - DONE Done (toggled via: `alt-x`) - REJECT Reject (toggled via: `alt-r`) - Basic inline *bold*, _italic_ and ~striked~ - Marking ==text== - Code: - Inline quoting `html <b>code</b>` - code blocks ```javascript var text = 'Hello, world!' console.log(text) ``` - Line - --- - Markers: ASAP, BUG, FIX, HACK, STUB, WARNING, and CAUTION - Basic task management - [%] Completion status - Inline [X] checkboxes [_] - To do items/blocks - [_] undone item _(clicking the checkbox updates the item)_ - [X] done item - [_] we can also add inline [x] checkboxes and states: [%] - navigating checkboxes in view mode can be done via `ctrl-left` / `ctrl-right` and toggling is done via `space` - links - [link](about:blank) - [local links](#attributes) - https://example.com - ./path/to/file /path/to -- _not supported yet_ - Tables - | a | b | c | | 1 | 2 | 3 | | 11 | 22 | 33 | - Symbols -- _should these be ligatures?_ - (i), (c), /!\, ... - -- and --- - Attributes: id:: attributes - collapsed collapsed:: true - a - b - c - id id:: node-with-id - combined id:: combined-several-ids collapsed:: true - a - b - c - - --- - ### Playground for testing - A collapsed:: true - a - b - c - B - d - e - C - This is a line of text - This is a set text lines - Lots of text Lots of text Lots of text Lots of text Lots of text Lots of text Lots of text Lots of text Lots of text Lots of text Lots of text Lots of text Lots of text Lots of text Lots of text Lots of text Lots of text Lots of text Lots of text Lots of text Lots of text Lots of text Lots of text Lots of text Lots of text -

# Outline editor as web component

- ## code enclosed in `<textarea>` element - code is treated as-is - the only exception is the closing textarea tag

- ## raw outline editor `<element>` - the children are not protected - any html are going to be parsed by the browser