mirror of
https://github.com/flynx/pWiki.git
synced 2025-10-29 10:00:08 +00:00
fixed focus handling by toolbar + playing/testing markdown handling...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
a7d9d9e40f
commit
ccd9cd2750
@ -1,6 +1,6 @@
|
|||||||
|
|
||||||
:root {
|
:root {
|
||||||
--button-size: 5em;
|
--button-size: 2em;
|
||||||
|
|
||||||
font-family: sans-serif;
|
font-family: sans-serif;
|
||||||
font-size: 5mm;
|
font-size: 5mm;
|
||||||
@ -93,8 +93,11 @@
|
|||||||
}
|
}
|
||||||
.editor .toolbar button {
|
.editor .toolbar button {
|
||||||
display: block;
|
display: block;
|
||||||
|
|
||||||
width: var(--button-size);
|
width: var(--button-size);
|
||||||
height: var(--button-size);
|
height: var(--button-size);
|
||||||
|
|
||||||
|
font-size: var(--button-size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -23,6 +23,16 @@ var atLine = function(elem, index){
|
|||||||
return false }
|
return false }
|
||||||
|
|
||||||
|
|
||||||
|
// handle return of focus when clicking toolbar...
|
||||||
|
var FOCUS_TEXTAREA
|
||||||
|
var keepFocus = function(){
|
||||||
|
FOCUS_TEXTAREA = document.activeElement.nodeName == 'TEXTAREA' }
|
||||||
|
var refocus = function(){
|
||||||
|
FOCUS_TEXTAREA ?
|
||||||
|
editor.get().querySelector('textarea').focus()
|
||||||
|
: editor.get().focus()
|
||||||
|
FOCUS_TEXTAREA = undefined }
|
||||||
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------
|
//---------------------------------------------------------------------
|
||||||
|
|
||||||
@ -75,6 +85,10 @@ var Outline = {
|
|||||||
right_key_expands: true,
|
right_key_expands: true,
|
||||||
|
|
||||||
|
|
||||||
|
get outline(){
|
||||||
|
return this.dom.querySelector('.outline') },
|
||||||
|
|
||||||
|
|
||||||
// XXX revise name...
|
// XXX revise name...
|
||||||
Block: function(place=none){
|
Block: function(place=none){
|
||||||
var block = document.createElement('div')
|
var block = document.createElement('div')
|
||||||
@ -130,21 +144,23 @@ var Outline = {
|
|||||||
if(node == 'prev' || node == 'previous'){
|
if(node == 'prev' || node == 'previous'){
|
||||||
return this.get('focused', -1) }
|
return this.get('focused', -1) }
|
||||||
|
|
||||||
|
var outline = this.outline
|
||||||
|
|
||||||
// node lists...
|
// node lists...
|
||||||
var NO_NODES = {}
|
var NO_NODES = {}
|
||||||
var nodes =
|
var nodes =
|
||||||
node == 'all' ?
|
node == 'all' ?
|
||||||
[...this.dom.querySelectorAll('[tabindex]')]
|
[...outline.querySelectorAll('[tabindex]')]
|
||||||
: node == 'visible' ?
|
: node == 'visible' ?
|
||||||
[...this.dom.querySelectorAll('[tabindex]')]
|
[...outline.querySelectorAll('[tabindex]')]
|
||||||
.filter(function(e){
|
.filter(function(e){
|
||||||
return e.offsetParent != null })
|
return e.offsetParent != null })
|
||||||
: node == 'editable' ?
|
: node == 'editable' ?
|
||||||
[...this.dom.querySelectorAll('[tabindex]>textarea')]
|
[...outline.querySelectorAll('[tabindex]>textarea')]
|
||||||
: node == 'selected' ?
|
: node == 'selected' ?
|
||||||
[...this.dom.querySelectorAll('[tabindex][selected]')]
|
[...outline.querySelectorAll('[tabindex][selected]')]
|
||||||
: node == 'top' ?
|
: node == 'top' ?
|
||||||
[...this.dom.children]
|
[...outline.children]
|
||||||
.filter(function(elem){
|
.filter(function(elem){
|
||||||
return elem.getAttribute('tabindex') != null })
|
return elem.getAttribute('tabindex') != null })
|
||||||
: ['siblings', 'children'].includes(node) ?
|
: ['siblings', 'children'].includes(node) ?
|
||||||
@ -166,15 +182,15 @@ var Outline = {
|
|||||||
typeof(node) == 'number' ?
|
typeof(node) == 'number' ?
|
||||||
this.at(node)
|
this.at(node)
|
||||||
: node == 'focused' ?
|
: node == 'focused' ?
|
||||||
(this.dom.querySelector(`[tabindex]:focus`)
|
(outline.querySelector(`[tabindex]:focus`)
|
||||||
|| this.dom.querySelector(`textarea:focus`)?.parentElement
|
|| outline.querySelector(`textarea:focus`)?.parentElement
|
||||||
|| this.dom.querySelector('[tabindex].focused'))
|
|| outline.querySelector('[tabindex].focused'))
|
||||||
: node == 'parent' ?
|
: node == 'parent' ?
|
||||||
this.get('focused')?.parentElement
|
this.get('focused')?.parentElement
|
||||||
: node
|
: node
|
||||||
var edited
|
var edited
|
||||||
if(node == 'edited'){
|
if(node == 'edited'){
|
||||||
edited = this.dom.querySelector(`textarea:focus`)
|
edited = outline.querySelector(`textarea:focus`)
|
||||||
node = edited?.parentElement }
|
node = edited?.parentElement }
|
||||||
|
|
||||||
if(!node || typeof(node) == 'string'){
|
if(!node || typeof(node) == 'string'){
|
||||||
@ -279,14 +295,22 @@ var Outline = {
|
|||||||
|
|
||||||
// block serialization...
|
// block serialization...
|
||||||
__code2html__: function(code){
|
__code2html__: function(code){
|
||||||
return code },
|
return code
|
||||||
|
// XXX STUB...
|
||||||
|
.replace(/\*(.*)\*/g, '<b>$1</b>')
|
||||||
|
.replace(/~([^~]*)~/g, '<s>$1</s>')
|
||||||
|
.replace(/_([^_]*)_/g, '<i>$1</i>') },
|
||||||
__html2code__: function(html){
|
__html2code__: function(html){
|
||||||
return html },
|
return html
|
||||||
|
// XXX STUB...
|
||||||
|
.replace(/<b>(.*)<\/b>/g, '*$1*')
|
||||||
|
.replace(/<s>(.*)<\/s>/g, '~$1~')
|
||||||
|
.replace(/<i>(.*)<\/i>/g, '_$1_') },
|
||||||
|
|
||||||
// serialization...
|
// serialization...
|
||||||
json: function(node){
|
json: function(node){
|
||||||
var that = this
|
var that = this
|
||||||
node ??= this.dom
|
node ??= this.outline
|
||||||
return [...node.children]
|
return [...node.children]
|
||||||
.map(function(elem){
|
.map(function(elem){
|
||||||
return elem.nodeName != 'DIV' ?
|
return elem.nodeName != 'DIV' ?
|
||||||
@ -318,7 +342,14 @@ var Outline = {
|
|||||||
return text },
|
return text },
|
||||||
|
|
||||||
// XXX use .__code2html__(..)
|
// XXX use .__code2html__(..)
|
||||||
load: function(){},
|
load: function(data){
|
||||||
|
// text...
|
||||||
|
if(typeof(data) == 'string'){
|
||||||
|
// XXX
|
||||||
|
}
|
||||||
|
// json...
|
||||||
|
// XXX
|
||||||
|
},
|
||||||
|
|
||||||
// XXX add scrollIntoView(..) to nav...
|
// XXX add scrollIntoView(..) to nav...
|
||||||
keyboard: {
|
keyboard: {
|
||||||
@ -346,7 +377,7 @@ var Outline = {
|
|||||||
// horizontal navigation / collapse...
|
// horizontal navigation / collapse...
|
||||||
// XXX if at start/end of element move to prev/next...
|
// XXX if at start/end of element move to prev/next...
|
||||||
ArrowLeft: function(evt){
|
ArrowLeft: function(evt){
|
||||||
if(this.dom.querySelector('.outline textarea:focus')){
|
if(this.outline.querySelector('textarea:focus')){
|
||||||
// XXX if at end of element move to next...
|
// XXX if at end of element move to next...
|
||||||
return }
|
return }
|
||||||
;((this.left_key_collapses
|
;((this.left_key_collapses
|
||||||
@ -356,7 +387,7 @@ var Outline = {
|
|||||||
this.toggleCollapse(true)
|
this.toggleCollapse(true)
|
||||||
: this.get('parent')?.focus() },
|
: this.get('parent')?.focus() },
|
||||||
ArrowRight: function(evt){
|
ArrowRight: function(evt){
|
||||||
if(this.dom.querySelector('.outline textarea:focus')){
|
if(this.outline.querySelector('textarea:focus')){
|
||||||
// XXX if at end of element move to next...
|
// XXX if at end of element move to next...
|
||||||
return }
|
return }
|
||||||
if(this.right_key_expands){
|
if(this.right_key_expands){
|
||||||
@ -401,7 +432,7 @@ var Outline = {
|
|||||||
this.Block('after')?.querySelector('textarea')?.focus()
|
this.Block('after')?.querySelector('textarea')?.focus()
|
||||||
: this.get()?.querySelector('textarea')?.focus() },
|
: this.get()?.querySelector('textarea')?.focus() },
|
||||||
Escape: function(evt){
|
Escape: function(evt){
|
||||||
this.dom.querySelector('textarea:focus')?.parentElement?.focus() },
|
this.outline.querySelector('textarea:focus')?.parentElement?.focus() },
|
||||||
Delete: function(evt){
|
Delete: function(evt){
|
||||||
if(evt.target.isContentEditable){
|
if(evt.target.isContentEditable){
|
||||||
return }
|
return }
|
||||||
@ -424,7 +455,7 @@ var Outline = {
|
|||||||
setup: function(dom){
|
setup: function(dom){
|
||||||
var that = this
|
var that = this
|
||||||
this.dom = dom
|
this.dom = dom
|
||||||
var outline = dom.querySelector('.outline')
|
var outline = this.outline
|
||||||
// update stuff already in DOM...
|
// update stuff already in DOM...
|
||||||
for(var elem of [...outline.querySelectorAll('textarea')]){
|
for(var elem of [...outline.querySelectorAll('textarea')]){
|
||||||
elem.autoUpdateSize() }
|
elem.autoUpdateSize() }
|
||||||
|
|||||||
@ -43,18 +43,17 @@ var setup = function(){
|
|||||||
<div tabindex=0><span>This is a line of text</span><textarea></textarea>
|
<div tabindex=0><span>This is a line of text</span><textarea></textarea>
|
||||||
</div>
|
</div>
|
||||||
<div tabindex=0><span>This is a set
|
<div tabindex=0><span>This is a set
|
||||||
text lines</span><textarea></textarea>
|
text lines</span><textarea></textarea>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="toolbar">
|
<div class="toolbar" onmousedown="keepFocus()" onclick="refocus()">
|
||||||
<!-- XXX these all should focus the node back so as not to hide the keyboard on mobine -->
|
<button onclick="editor.deindent().focus()"><</button>
|
||||||
<button onclick="editor.deindent()"><</button>
|
<button onclick="editor.indent().focus()">></button>
|
||||||
<button onclick="editor.indent()">></button>
|
<button onclick="editor.Block('before').focus()">-<sup>+</sup>-</button>
|
||||||
<button onclick="editor.Block('before').focus()" style="text-decoration:underline">+</button>
|
<button onclick="editor.Block('after').focus()">-<sub>+</sub>-</button>
|
||||||
<button onclick="editor.Block('after').focus()" style="text-decoration:overline">+</button>
|
<button onclick="editor.toggleCollapse()?.focus()">˅˄</button>
|
||||||
<button onclick="editor.toggleCollapse()">+/-</button>
|
|
||||||
<button onclick="editor.remove()">×</button>
|
<button onclick="editor.remove()">×</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -63,8 +62,9 @@ var setup = function(){
|
|||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
TODO:
|
TODO:
|
||||||
- mouse controls
|
- Firefox compatibility -- remove ':has(..)'
|
||||||
- touch controls
|
- <s>focus management</s>
|
||||||
|
- <s>mouse/touch controls</s>
|
||||||
- <s>navigation</s>
|
- <s>navigation</s>
|
||||||
- <s>expand/collapse subtree</s>
|
- <s>expand/collapse subtree</s>
|
||||||
- <s>shift subtree up/down</s>
|
- <s>shift subtree up/down</s>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user