mirror of
https://github.com/flynx/pWiki.git
synced 2025-10-28 17:40:07 +00:00
Compare commits
4 Commits
1a0e7b9d69
...
82e003dbf4
| Author | SHA1 | Date | |
|---|---|---|---|
| 82e003dbf4 | |||
| cf1beec0da | |||
| debb98faa1 | |||
| 7d45f89dfe |
@ -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)) } },
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -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
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user