Compare commits

..

No commits in common. "475078b55c0317c3b7c1e18cc80d0029abda3dbb" and "6d25e096cee29e8a7e3a39d06526cb51190aac45" have entirely different histories.

3 changed files with 49 additions and 140 deletions

View File

@ -8,6 +8,7 @@
--item-indent: 2rem; --item-indent: 2rem;
--item-padding-ratio: 0.2; --item-padding-ratio: 0.2;
--item-padding: calc(1em * var(--item-padding-ratio));
--checkbox-size: 1.5rem; --checkbox-size: 1.5rem;
@ -28,14 +29,6 @@
/*scroll-behavior: smooth;*/ /*scroll-behavior: smooth;*/
} }
.editor {
--item-padding: calc(1em * var(--item-padding-ratio));
}
/*********************************************************************/
.editor { .editor {
display: block; display: block;
position: relative; position: relative;
@ -112,11 +105,6 @@
overflow: hidden; overflow: hidden;
resize: none; resize: none;
} }
/* clickable things in view */
.editor .outline [tabindex]>span a,
.editor .outline [tabindex]>span input {
pointer-events: auto;
}
/* focus... */ /* focus... */
@ -130,7 +118,7 @@ editor .outline [tabindex]:focus {
} }
.editor .outline [tabindex].focused:not(:focus)>span, .editor .outline [tabindex].focused:not(:focus)>span,
.editor .outline [tabindex].focused:not(:focus)>textarea { .editor .outline [tabindex].focused:not(:focus)>textarea {
background: rgba(0,0,0,0.01); background: rgba(0,0,0,0.05);
} }
.editor .outline div[collapsed] { .editor .outline div[collapsed] {
@ -271,28 +259,9 @@ editor .outline [tabindex]:focus {
} }
/* Quote... */
.editor .outline .quote>span,
.editor .outline .quote>textarea {
--item-padding-ratio: 0.7;
--indent: 1rem;
/* XXX for some reason if this is not set here it will not see the new --item-padding-ratio */
--item-padding: calc(1rem * var(--item-padding-ratio));
padding: var(--item-padding) 1.5rem;
color: rgba(0,0,0,0.8);
/* XXX border messes up bullet alignment... */
/*border-left: solid 0.2em silver;*/
box-shadow: inset 0.2em 0 0 0 silver;
background: rgba(0,0,0,0.05);
}
/* Lists... */ /* Lists... */
/* XXX needs to be in the middle of the first span but with universal size... */ /* XXX needs to be in the middle of the first span but with universal size... */
.editor .outline .list-item>span:before, .editor .outline .list-item:before,
.editor .outline .list>[tabindex]>span:not(:empty):before { .editor .outline .list>[tabindex]>span:not(:empty):before {
content: "◼"; content: "◼";
color: gray; color: gray;
@ -336,6 +305,9 @@ editor .outline [tabindex]:focus {
* element -- can's seem to figure out a way to avoid this */ * element -- can's seem to figure out a way to avoid this */
--checkbox-margin: 0em; --checkbox-margin: 0em;
} }
.editor .outline input {
pointer-events: auto;
}
.editor .outline [tabindex].todo>span { .editor .outline [tabindex].todo>span {
width: calc(100% - var(--checkbox-size)); width: calc(100% - var(--checkbox-size));
/* align todo checkboxes to indnt (otherwise they are on the indent) */ /* align todo checkboxes to indnt (otherwise they are on the indent) */
@ -376,13 +348,6 @@ editor .outline [tabindex]:focus {
/*margin-left: 0;*/ /*margin-left: 0;*/
} }
/* code... */
.editor .outline [tabindex]>span code {
padding: 0.1em 0.3em;
font-family: monospace;
background: rgba(0,0,0,0.07);
border-radius: 0.2em;
}
/*********************************************************************/ /*********************************************************************/
@ -390,7 +355,6 @@ editor .outline [tabindex]:focus {
.editor.show-click-zones .outline [tabindex]>span:before, .editor.show-click-zones .outline [tabindex]>span:before,
.editor.show-click-zones .outline [tabindex]>span:after { .editor.show-click-zones .outline [tabindex]>span:after {
background: rgba(0,0,0,0.03); background: rgba(0,0,0,0.03);
border: solid 1px silver;
} }
.editor.show-click-zones .outline [tabindex]:hover>span:before, .editor.show-click-zones .outline [tabindex]:hover>span:before,
.editor.show-click-zones .outline [tabindex]:hover>span:after { .editor.show-click-zones .outline [tabindex]:hover>span:after {

View File

@ -178,9 +178,9 @@ var Outline = {
focus: function(node='focused', offset){}, focus: function(node='focused', offset){},
edit: function(node='focused', offset){}, edit: function(node='focused', offset){},
// XXX should this handle children???
update: function(node='focused', data){ update: function(node='focused', data){
var node = this.get(node) var node = this.get(node)
data ??= this.data(node, false)
typeof(data.collapsed) == 'boolean' typeof(data.collapsed) == 'boolean'
&& (data.collapsed ? && (data.collapsed ?
node.setAttribute('collapsed', '') node.setAttribute('collapsed', '')
@ -193,9 +193,9 @@ var Outline = {
var parsed = this.__code2html__(data.text) var parsed = this.__code2html__(data.text)
html.innerHTML = parsed.text html.innerHTML = parsed.text
// heading... // heading...
node.classList.remove(...this.__styles) parsed.style ?
parsed.style node.classList.add(...parsed.style)
&& node.classList.add(...parsed.style) : node.classList.remove(...this.__styles)
} else { } else {
html.innerHTML = data.text } html.innerHTML = data.text }
text.value = data.text text.value = data.text
@ -312,66 +312,36 @@ var Outline = {
return '' }) return '' })
// markdown... // markdown...
// style: headings... // style: headings...
.replace(/^(?<!\\)######\s+(.*)$/m, style('heading-6')) .replace(/^######\s*(.*)$/m, style('heading-6'))
.replace(/^(?<!\\)#####\s+(.*)$/m, style('heading-5')) .replace(/^#####\s*(.*)$/m, style('heading-5'))
.replace(/^(?<!\\)####\s+(.*)$/m, style('heading-4')) .replace(/^####\s*(.*)$/m, style('heading-4'))
.replace(/^(?<!\\)###\s+(.*)$/m, style('heading-3')) .replace(/^###\s*(.*)$/m, style('heading-3'))
.replace(/^(?<!\\)##\s+(.*)$/m, style('heading-2')) .replace(/^##\s*(.*)$/m, style('heading-2'))
.replace(/^(?<!\\)#\s+(.*)$/m, style('heading-1')) .replace(/^#\s*(.*)$/m, style('heading-1'))
// style: list... // style: list...
//.replace(/^(?<!\\)[-\*]\s+(.*)$/m, style('list-item')) .replace(/^[-\*]\s+(.*)$/m, style('list-item'))
.replace(/^\s*(.*)(?<!\\):\s*$/m, style('list')) .replace(/^\s*(.*):\s*$/m, style('list'))
// style: misc... // style: misc...
.replace(/^(?<!\\)>\s+(.*)$/m, style('quote')) .replace(/^((\/\/|;)\s+.*)$/m, style('comment'))
.replace(/^(?<!\\)((\/\/|;)\s+.*)$/m, style('comment')) .replace(/^XXX\s+(.*)$/m, style('XXX'))
.replace(/^(?<!\\)XXX\s+(.*)$/m, style('XXX')) .replace(/^(.*)\s*XXX$/m, style('XXX'))
.replace(/^(.*)\s*(?<!\\)XXX$/m, style('XXX')) .replace(/(\s*)ASAP(\s*)/m, '$1<span class="ASAP">ASAP</span>$2')
.replace(/(\s*)(?<!\\)ASAP(\s*)/m, '$1<span class="ASAP">ASAP</span>$2')
// elements... // elements...
.replace(/(\n|^)(?<!\\)---*\h*(\n|$)/m, '$1<hr>') .replace(/(\n|^)---*\h*(\n|$)/m, '$1<hr>')
// ToDo... // ToDo...
.replace(/^(?<!\\)TODO\s+/m, .replace(/^TODO\s*/m, style('todo', '<input type="checkbox">'))
style('todo', '<input type="checkbox">')) .replace(/^DONE\s*/m, style('todo', '<input type="checkbox" checked>'))
.replace(/^(?<!\\)DONE\s+/m,
style('todo', '<input type="checkbox" checked>'))
// checkboxes... // checkboxes...
.replace(/(?<!\\)\[_\]/gm, .replace(/\[_\]/gm, style('check', '<input class="check" type="checkbox">'))
style('check', '<input class="check" type="checkbox">')) .replace(/\[[X]\]/gm, style('check', '<input class="check" type="checkbox" checked>'))
.replace(/(?<!\\)\[[X]\]/gm,
style('check', '<input class="check" type="checkbox" checked>'))
// basic styling... // basic styling...
.replace(/(?<!\\)\*(?=[^\s*])(([^*]|\\\*)*[^\s*])(?<!\\)\*/gm, '<b>$1</b>') // XXX these are quite naive...
.replace(/(?<!\\)~(?=[^\s~])(([^~]|\\~)*[^\s~])(?<!\\)~/gm, '<s>$1</s>') .replace(/\*(.*)\*/gm, '<b>$1</b>')
.replace(/(?<!\\)_(?=[^\s_])(([^_]|\\_)*[^\s_])(?<!\\)_/gm, '<i>$1</i>') .replace(/~([^~]*)~/gm, '<s>$1</s>')
.replace(/(?<!\\)`(?=[^\s_])(([^`]|\\`)*[^\s_])(?<!\\)`/gm, '<code>$1</code>') .replace(/_([^_]*)_/gm, '<i>$1</i>')
// quoting...
.replace(/(?<!\\)\\(.)/gm, '$1')
return elem }, return elem },
// XXX essentially here we need to remove service stuff like some
// attributes (collapsed, id, ...)...
// XXX also need to quote leading '- ' in block text here...
// e.g.
// - block
// some text
// - text in the above block ('-' needs to be quoted)
// - next block
__code2text__: function(code){
// XXX
},
__text2code__: function(text){
// XXX
},
// serialization... // serialization...
data: function(elem, deep=true){
elem = this.get(elem)
return {
text: elem.querySelector('textarea').value,
collapsed: elem.getAttribute('collapsed') != null,
...(deep ?
{children: this.json(elem)}
: {}),
} },
json: function(node){ json: function(node){
var that = this var that = this
node ??= this.outline node ??= this.outline
@ -379,7 +349,11 @@ var Outline = {
.map(function(elem){ .map(function(elem){
return elem.nodeName != 'DIV' ? return elem.nodeName != 'DIV' ?
[] []
: [that.data(elem)] }) : [{
text: elem.querySelector('textarea').value,
collapsed: elem.getAttribute('collapsed') != null,
children: that.json(elem)
}] })
.flat() }, .flat() },
// XXX add option to customize indent size... // XXX add option to customize indent size...
text: function(node, indent, level){ text: function(node, indent, level){
@ -649,6 +623,7 @@ var Outline = {
// click: left of elem (outside) // click: left of elem (outside)
if(evt.offsetX < 0){ if(evt.offsetX < 0){
// XXX item menu? // XXX item menu?
console.log('---', elem)
// click: right of elem (outside) // click: right of elem (outside)
} else if(elem.offsetWidth < evt.offsetX){ } else if(elem.offsetWidth < evt.offsetX){
@ -686,13 +661,6 @@ var Outline = {
// heboard handling... // heboard handling...
outline.addEventListener('keydown', outline.addEventListener('keydown',
function(evt){ function(evt){
var elem = evt.target
// update element state...
if(elem.nodeName == 'TEXTAREA'){
setTimeout(function(){
that.update(elem.parentElement)
elem.updateSize() }, 0) }
// handle keyboard...
evt.key in that.keyboard evt.key in that.keyboard
&& that.keyboard[evt.key].call(that, evt) }) && that.keyboard[evt.key].call(that, evt) })
// toggle view/code of nodes... // toggle view/code of nodes...
@ -758,9 +726,7 @@ var Outline = {
// code... // code...
var code = this.code var code = this.code
if(code){ if(code){
this.load(code.innerHTML this.load(code.innerHTML) }
.replace(/&lt;/g, '<')
.replace(/&gt;/g, '>')) }
return this }, return this },
} }

View File

@ -27,7 +27,7 @@ var setup = function(){
<body onload="setup()"> <body onload="setup()">
<div class="editor"> <div class="editor">
<!-- code --> <!-- code -->
<pre class="code"> <div class="code">
- # Outline editor prototype - # Outline editor prototype
- An outline-based markdown editor experiment - An outline-based markdown editor experiment
- ### Infuences:: - ### Infuences::
@ -36,30 +36,18 @@ var setup = function(){
- Bonsai - Bonsai
- -
- ## ToDo - ## ToDo
- ASAP: editor: bksapce/del at start/end of a block should join it with prev/next - shifting nodes up/down
- ASAP: editor: pressing enter in text edit mode should split text into two blocks - editor: bksapce/del at start/end of a block should join it with prev/next
- ASAP: editor: shifting nodes up/down - editor: pressing enter in text edit mode should split text into two blocks
- ASAP: editor: `-` at start of line is interpreted as block marker...
- editor: caret - editor: caret
- ~go to next/prev element's start/end when moving off last/first char~ - ~go to next/prev element's start/end when moving off last/first char~
- handle up/down on wrapped blocks - handle up/down on wrapped blocks
_...can't seem to get caret line in a non-hacky way_ _...can't seem to get caret line in a non-hacky way_
- ~editor: semi-live update styles~
- need to reach checkboxes via keyboard
- persistent empty first/last node (a button to create a new node) - persistent empty first/last node (a button to create a new node)
- add completion percentage to blocks with todo's nested: - add completion percentage to blocks with todo's nested
- `[%]`, `%%`, or something similar... either by default oron '%%' or '[%]' placeholder
...ratio between all nested open checkboxes to checked (???)
- read-only mode - read-only mode
- should bulets be on the same level as nodes or offset??
- A) justified to bulet:
* list item
* list item
block text
- B) justified to text _(current)_:
* list item
* list item
block text
- NOTE: this is only a problem if making list-items manually -- disable???
- ~do a better expand/collapse icons~ - ~do a better expand/collapse icons~
- ~loading from DOM -- fill textarea~ - ~loading from DOM -- fill textarea~
- ~focus management~ - ~focus management~
@ -77,8 +65,7 @@ var setup = function(){
- edit node - edit node
- markdown: tables - markdown: tables
- empty item height is a bit off... - empty item height is a bit off...
- handle links gracefully - ~serialize~/deserialize
- ~serialize/deserialize~
- ~add optional text styling to nodes~ - ~add optional text styling to nodes~
- -
- ## TEST - ## TEST
@ -95,7 +82,6 @@ var setup = function(){
- a - a
- b - b
- c - c
- &gt; quoted text
- // C-style comment - // C-style comment
- ; ASM-style comment - ; ASM-style comment
- XXX Highlight - XXX Highlight
@ -110,13 +96,6 @@ var setup = function(){
- DONE done item - DONE done item
- [_] a different way to draw a checkbox - [_] a different way to draw a checkbox
- Inline [X] checkboxes [_] - Inline [X] checkboxes [_]
- link <a href="about:blank">example</a>
- markdown:
- code blocks
- numbered lists
- alerts
- tables
- footnotes??
- -
- ### Playground for testing - ### Playground for testing
- A - A
@ -131,11 +110,11 @@ var setup = function(){
- This is a line of text - This is a line of text
- This is a set - This is a set
text lines 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 </pre> - 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 </div>
<!-- outline --> <!-- outline -->
<div class="outline"></div> <div class="outline"></div>
<!-- toolbar (optional) --> <!-- toolbar (optional) -->
<!--div class="toolbar"> <div class="toolbar">
<button onclick="editor.deindent().focus()">&lt;</button> <button onclick="editor.deindent().focus()">&lt;</button>
<button onclick="editor.indent().focus()">&gt;</button> <button onclick="editor.indent().focus()">&gt;</button>
<button onclick="editor.Block('before').focus()" class="add-row">+</button> <button onclick="editor.Block('before').focus()" class="add-row">+</button>
@ -143,7 +122,7 @@ var setup = function(){
<button onclick="editor.Block('after').focus()" class="add-row">+</button> <button onclick="editor.Block('after').focus()" class="add-row">+</button>
<button onclick="editor.toggleCollapse()?.focus()">&#709;&#708;</button> <button onclick="editor.toggleCollapse()?.focus()">&#709;&#708;</button>
<button onclick="editor.remove()">&times;</button> <button onclick="editor.remove()">&times;</button>
</div--> </div>
</div> </div>
<hr> <hr>