Compare commits

...

4 Commits

Author SHA1 Message Date
82e003dbf4 examples...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
2025-02-10 07:57:58 +03:00
cf1beec0da templating mostly working -- need docs...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
2025-02-10 07:49:12 +03:00
debb98faa1 basic templating functional -- still needs work...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
2025-02-10 06:39:01 +03:00
7d45f89dfe working on template action...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
2025-02-10 06:18:23 +03:00
2 changed files with 86 additions and 11 deletions

View File

@ -311,11 +311,12 @@ var attributes = {
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// XXX make this collapsed...
// XXX handle cursor marker... // XXX handle cursor marker...
var templates = { var templates = {
__proto__: plugin, __proto__: plugin,
__default_button_text__: 'New',
nodeFromTemplate: function(){ nodeFromTemplate: function(){
}, },
@ -326,26 +327,76 @@ var templates = {
text = text text = text
.replace(/^TEMPLATE/, '') .replace(/^TEMPLATE/, '')
var [header, ...lines] = text.split(/\n/g) var [header, ...lines] = text.split(/\n/g)
header =
`<button>${ // set direction...
header.trim() == '' ? if(header[0] == '^'){
'new' header = header.slice(1)
: header.trim() elem.create_new = 'above'
}</button>` } else {
elem.create_new = 'below' }
// nested button...
var nested_button
header = header
.replace(/\[([^\]]*)\]/g,
function(_, text){
nested_button = true
return `<button>${ text.trim() }</button>` })
// whole text is a button...
if(!nested_button){
header =
`<button>${
header.trim() == '' ?
this.__default_button_text__
: header.trim()
}</button>` }
// body... // body...
// XXX only do this if we have nested elements... // XXX only do this if we have nested elements...
elem.collapsed = true elem.collapsed = true
// XXX
// button... // button...
return header }, return header },
// XXX focus button... // XXX focus button...
__focusin__: function(evt, editor, elem){ __focusin__: function(evt, editor, elem){
//var node = editor.get(elem)
//node.querySelector('button').focus()
}, },
// XXX handle button???
__click__: function(evt, editor, elem){ __click__: function(evt, editor, elem){
}, e = evt.target
// check if we are clicking a button...
while(e.tagName != 'BUTTON'
&& e.parentElement != null){
e = e.parentElement }
if(e.tagName == 'BUTTON'){
// get template data...
var data = editor.data(elem)
// subtree...
if(data.children.length > 0){
// get the corresponding template...
var i = [...editor.get(elem).querySelectorAll('button')]
.indexOf(e)
data = data.children[i]
// text -> trim off the TEMPLATE header...
} else {
data.text = data.text
.split(/\n/)
.slice(1)
.join('\n') }
// XXX handle cursor placement / selection...
// XXX
var direction =
editor.data(elem).create_new == 'above' ?
'prev'
: 'next'
editor.focus(elem)
editor.edit(
// XXX BUG? currently this only creates a single node,
// should be recursive...
editor.Block(data, direction)) } },
} }

View File

@ -164,10 +164,18 @@ var setup = function(){
- sub-tree - sub-tree
- TEMPLATE title - TEMPLATE title
- text [cursor] - text [cursor]
- TEMPLATE title *boo*
- text [cursor]
- TEMPLATE title [new]
- text [cursor]
- multi-template - multi-template
- TEMPLATE [A] [B] [C]
- aaa
- bbb
- ccc
- TEMPLATE title A - TEMPLATE title A
text [cursor] text [cursor]
- TEMPLATE title B - TEMPLATE^ title B
- text [cursor] - text [cursor]
- renders as: - renders as:
- <button>title</button> - <button>title</button>
@ -691,6 +699,22 @@ var setup = function(){
- @ Heading - @ Heading
- @ Heading - @ Heading
- @ Heading - @ Heading
- Templating:
- Inline
- TEMPLATE
[ ]
- [ ] example item
- Nested
- TEMPLATE creates [below]
- [ ]
- [ ] example item
- TEMPLATE^ creates [above]
- [ ]
- Multiple nested
- TEMPLATE [ToDo] [Note]
- [ ]
-
- [ ] example item
- Attributes: - Attributes:
id:: attributes id:: attributes
- collapsed - collapsed