mirror of
				https://github.com/flynx/pWiki.git
				synced 2025-10-31 02:50:08 +00:00 
			
		
		
		
	templating mostly working -- need docs...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
		
							parent
							
								
									debb98faa1
								
							
						
					
					
						commit
						cf1beec0da
					
				| @ -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,17 +327,33 @@ var templates = { | |||||||
| 		text = text | 		text = text | ||||||
| 			.replace(/^TEMPLATE/, '') | 			.replace(/^TEMPLATE/, '') | ||||||
| 		var [header, ...lines] = text.split(/\n/g) | 		var [header, ...lines] = text.split(/\n/g) | ||||||
|  | 
 | ||||||
|  | 		// set direction...
 | ||||||
|  | 		if(header[0] == '^'){ | ||||||
|  | 			header = header.slice(1)  | ||||||
|  | 			elem.create_new = 'above'  | ||||||
|  | 		} 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 =  | 			header =  | ||||||
| 				`<button>${ | 				`<button>${ | ||||||
| 					header.trim() == '' ? | 					header.trim() == '' ? | ||||||
| 					'new' | 						this.__default_button_text__ | ||||||
| 						: header.trim() | 						: header.trim() | ||||||
| 			}</button>` | 				}</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 }, | ||||||
| @ -345,15 +362,22 @@ var templates = { | |||||||
| 		//var node = editor.get(elem)
 | 		//var node = editor.get(elem)
 | ||||||
| 		//node.querySelector('button').focus() 
 | 		//node.querySelector('button').focus() 
 | ||||||
| 	}, | 	}, | ||||||
| 	// XXX restrict this to the button???
 |  | ||||||
| 	__click__: function(evt, editor, elem){ | 	__click__: function(evt, editor, elem){ | ||||||
| 		if(evt.target.tagName == 'BUTTON'){ | 		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...
 | 			// get template data...
 | ||||||
| 			var data = editor.data(elem) | 			var data = editor.data(elem) | ||||||
| 			// subtree...
 | 			// subtree...
 | ||||||
| 			if(data.children.length > 0){ | 			if(data.children.length > 0){ | ||||||
| 				data = data.children[0] | 				// get the corresponding template...
 | ||||||
| 			// text...
 | 				var i = [...editor.get(elem).querySelectorAll('button')] | ||||||
|  | 					.indexOf(e) | ||||||
|  | 				data = data.children[i] | ||||||
|  | 			// text -> trim off the TEMPLATE header...
 | ||||||
| 			} else { | 			} else { | ||||||
| 				data.text = data.text | 				data.text = data.text | ||||||
| 					.split(/\n/) | 					.split(/\n/) | ||||||
| @ -363,8 +387,10 @@ var templates = { | |||||||
| 			// XXX handle cursor placement / selection...
 | 			// XXX handle cursor placement / selection...
 | ||||||
| 			// XXX
 | 			// XXX
 | ||||||
| 
 | 
 | ||||||
| 			// XXX how do we get this???
 | 			var direction =  | ||||||
| 			var direction = 'next' | 				editor.data(elem).create_new == 'above' ?  | ||||||
|  | 					'prev'  | ||||||
|  | 					: 'next' | ||||||
| 
 | 
 | ||||||
| 			editor.focus(elem) | 			editor.focus(elem) | ||||||
| 			editor.edit( | 			editor.edit( | ||||||
|  | |||||||
| @ -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> | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user