reworked dom...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2023-10-06 17:53:28 +03:00
parent aaff6360a4
commit 697a9d8347
4 changed files with 47 additions and 25 deletions

View File

@ -1,9 +1,13 @@
:root { :root {
--font-size: 5mm;
--button-size: 2em; --button-size: 2em;
font-family: sans-serif; font-family: sans-serif;
font-size: 5mm; font-size: var(--font-size);
/*text-size-adjust: none;*/
text-size-adjust: 150%;
} }
.editor { .editor {
@ -36,7 +40,7 @@
margin: 0; margin: 0;
font-family: sans-serif; font-family: sans-serif;
font-size: 5mm; font-size: var(--font-size);
outline: none; outline: none;
border: none; border: none;
@ -49,9 +53,14 @@
/* show/hide node's view/code... */ /* show/hide node's view/code... */
.editor .outline [tabindex]>span+textarea:not(:focus), .editor .outline [tabindex]>span+textarea:not(:focus),
/* XXX not sure how to do this without :has(..)... */ .editor .outline [tabindex]:has(>span+textarea:focus)>span:first-child {
.editor .outline [tabindex]:has(>span+textarea:focus)>span:has(+textarea), position: absolute;
.editor .outline [tabindex]:focus>span+textarea { opacity: 0;
top: 0;
}
.editor .outline [tabindex]>textarea:focus+span,
.editor .outline [tabindex]>textarea:not(:focus) {
position: absolute; position: absolute;
opacity: 0; opacity: 0;
top: 0; top: 0;

View File

@ -87,9 +87,9 @@ var Outline = {
var block = document.createElement('div') var block = document.createElement('div')
block.setAttribute('tabindex', '0') block.setAttribute('tabindex', '0')
block.append( block.append(
document.createElement('span'),
document.createElement('textarea') document.createElement('textarea')
.autoUpdateSize()) .autoUpdateSize(),
document.createElement('span'))
var cur = this.get() var cur = this.get()
place && cur place && cur
&& cur[place](block) && cur[place](block)
@ -349,10 +349,18 @@ var Outline = {
// text... // text...
if(typeof(data) == 'string'){ if(typeof(data) == 'string'){
// XXX // XXX
data = data.split(/\n(\s*)- /g)
var level = function(lst){
while(lst.length > 0){
}
}
} }
// json... // json...
// XXX // XXX
},
// generate dom...
// XXX
return this },
// XXX add scrollIntoView(..) to nav... // XXX add scrollIntoView(..) to nav...
keyboard: { keyboard: {
@ -480,18 +488,18 @@ var Outline = {
that.get('focused')?.classList?.add('focused') that.get('focused')?.classList?.add('focused')
// textarea... // textarea...
if(node.nodeName == 'TEXTAREA' if(node.nodeName == 'TEXTAREA'
&& node?.previousElementSibling?.nodeName == 'SPAN'){ && node?.nextElementSibling?.nodeName == 'SPAN'){
node.value = node.value =
that.__html2code__ ? that.__html2code__ ?
that.__html2code__(node.previousElementSibling.innerHTML) that.__html2code__(node.nextElementSibling.innerHTML)
: node.previousElementSibling.innerHTML : node.nextElementSibling.innerHTML
node.updateSize() } }) node.updateSize() } })
outline.addEventListener('focusout', outline.addEventListener('focusout',
function(evt){ function(evt){
var node = evt.target var node = evt.target
if(node.nodeName == 'TEXTAREA' if(node.nodeName == 'TEXTAREA'
&& node?.previousElementSibling?.nodeName == 'SPAN'){ && node?.nextElementSibling?.nodeName == 'SPAN'){
node.previousElementSibling.innerHTML = node.nextElementSibling.innerHTML =
that.__code2html__ ? that.__code2html__ ?
that.__code2html__(node.value) that.__code2html__(node.value)
: node.value } }) : node.value } })

View File

@ -19,6 +19,7 @@ Object.defineProperty(HTMLTextAreaElement.prototype, 'caretLine', {
enumerable: false, enumerable: false,
get: function(){ get: function(){
var offset = this.selectionStart var offset = this.selectionStart
console.log('---', this)
return offset != null ? return offset != null ?
this.value this.value
.slice(0, offset) .slice(0, offset)

View File

@ -26,27 +26,29 @@ var setup = function(){
<div class="editor"> <div class="editor">
<div class="outline"> <div class="outline">
<div tabindex=0> <div tabindex=0>
<span><i>root</i></span><textarea></textarea> <textarea></textarea><span><i>root</i></span>
<div tabindex=0 collapsed> <div tabindex=0 collapsed>
<span>A</span><textarea></textarea> <textarea></textarea><span>A</span>
<div tabindex=0><span>a</span><textarea></textarea> <div tabindex=0><textarea></textarea><span>a</span>
</div> </div>
<div tabindex=0><span>b</span><textarea></textarea> <div tabindex=0><textarea></textarea><span>b</span>
</div> </div>
<div tabindex=0><span>c</span><textarea></textarea> <div tabindex=0><textarea></textarea><span>c</span>
</div> </div>
</div> </div>
<div tabindex=0><span>B</span><textarea></textarea> <div tabindex=0><textarea></textarea><span>B</span>
<div tabindex=0><span>d</span><textarea></textarea> <div tabindex=0><textarea></textarea><span>d</span>
</div> </div>
<div tabindex=0><span>e</span><textarea></textarea> <div tabindex=0><textarea></textarea><span>e</span>
</div> </div>
</div> </div>
<div tabindex=0><span>C</span><textarea></textarea> <div tabindex=0><textarea></textarea><span>C</span>
<div tabindex=0><span>This is a line of text</span><textarea></textarea> <div tabindex=0><textarea></textarea><span>This is a line of text</span>
</div> </div>
<div tabindex=0><span>This is a set<br> <div tabindex=0><textarea></textarea><span>This is a set<br>
text lines</span><textarea></textarea> text lines</span>
</div>
<div tabindex=0><textarea></textarea><span>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 </span>
</div> </div>
</div> </div>
</div> </div>
@ -67,6 +69,8 @@ var setup = function(){
<pre> <pre>
TODO: TODO:
- persistent empty first/last node (a button to create a new node)
- loading from DOM -- fill textarea
- Firefox compatibility -- remove ':has(..)' - Firefox compatibility -- remove ':has(..)'
- <s>focus management</s> - <s>focus management</s>
- <s>mouse/touch controls</s> - <s>mouse/touch controls</s>