mirror of
				https://github.com/flynx/pWiki.git
				synced 2025-11-04 13:00:10 +00:00 
			
		
		
		
	added basic buttons....
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
		
							parent
							
								
									0c5c5f2a5f
								
							
						
					
					
						commit
						b514f4efb4
					
				@ -1,21 +1,34 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
:root {
 | 
					:root {
 | 
				
			||||||
 | 
						--button-size: 5em;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	font-family: sans-serif;
 | 
						font-family: sans-serif;
 | 
				
			||||||
	font-size: 5mm;
 | 
						font-size: 5mm;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
.editor [tabindex] {
 | 
					.editor {
 | 
				
			||||||
 | 
						display: block;
 | 
				
			||||||
	position: relative;
 | 
						position: relative;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
.editor div [tabindex] {
 | 
					
 | 
				
			||||||
 | 
					.editor .outline {
 | 
				
			||||||
 | 
						display: block;
 | 
				
			||||||
 | 
						position: relative;
 | 
				
			||||||
 | 
						width: calc(100% - var(--button-size));
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					.editor .outline [tabindex] {
 | 
				
			||||||
 | 
						position: relative;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					.editor .outline div [tabindex] {
 | 
				
			||||||
	margin-left: 2em;
 | 
						margin-left: 2em;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
.editor [tabindex]>span,
 | 
					.editor .outline [tabindex]>span,
 | 
				
			||||||
.editor [tabindex]>textarea {
 | 
					.editor .outline [tabindex]>textarea {
 | 
				
			||||||
	--padding: 0.2em;
 | 
						--padding: 0.2em;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	display: block;
 | 
						display: block;
 | 
				
			||||||
	width: 100%;
 | 
						width: 100%
 | 
				
			||||||
	/* XXX this is a tiny bit off and using textarea's height here is off too... */
 | 
						/* XXX this is a tiny bit off and using textarea's height here is off too... */
 | 
				
			||||||
	min-height: 1em;
 | 
						min-height: 1em;
 | 
				
			||||||
	padding: var(--padding);
 | 
						padding: var(--padding);
 | 
				
			||||||
@ -28,41 +41,61 @@
 | 
				
			|||||||
	outline: none;
 | 
						outline: none;
 | 
				
			||||||
	border: none;
 | 
						border: none;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
.editor [tabindex]>textarea {
 | 
					.editor .outline [tabindex]>textarea {
 | 
				
			||||||
	height: calc(2 * var(--padding) + 1em);
 | 
						height: calc(2 * var(--padding) + 1em);
 | 
				
			||||||
	overflow: hidden;
 | 
						overflow: hidden;
 | 
				
			||||||
	resize: none;
 | 
						resize: none;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* show/hide node's view/code... */
 | 
					/* show/hide node's view/code... */
 | 
				
			||||||
.editor [tabindex]>span+textarea:not(:focus),
 | 
					.editor .outline [tabindex]>span+textarea:not(:focus),
 | 
				
			||||||
/* XXX not sure how to do this without :has(..)... */
 | 
					/* XXX not sure how to do this without :has(..)... */
 | 
				
			||||||
.editor [tabindex]:has(>span+textarea:focus)>span:has(+textarea),
 | 
					.editor .outline [tabindex]:has(>span+textarea:focus)>span:has(+textarea),
 | 
				
			||||||
.editor [tabindex]:focus>span+textarea {
 | 
					.editor .outline [tabindex]:focus>span+textarea {
 | 
				
			||||||
	position: absolute;
 | 
						position: absolute;
 | 
				
			||||||
	opacity: 0;
 | 
						opacity: 0;
 | 
				
			||||||
	top: 0;
 | 
						top: 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
.editor div[collapsed] {
 | 
					/* focus... */
 | 
				
			||||||
 | 
					.editor .outline [tabindex]:focus {
 | 
				
			||||||
 | 
						/*outline: solid 0.2em silver;*/
 | 
				
			||||||
 | 
						outline: none;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					.editor .outline [tabindex]:focus>span,
 | 
				
			||||||
 | 
					.editor .outline [tabindex]:focus>textarea {
 | 
				
			||||||
 | 
						background: rgba(0,0,0,0.1);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					.editor .outline [tabindex].focused:not(:focus)>span,
 | 
				
			||||||
 | 
					.editor .outline [tabindex].focused:not(:focus)>textarea {
 | 
				
			||||||
 | 
						background: rgba(0,0,0,0.05);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					.editor .outline div[collapsed] {
 | 
				
			||||||
	border-bottom: solid 1px silver;
 | 
						border-bottom: solid 1px silver;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
.editor div[collapsed] div {
 | 
					.editor .outline div[collapsed] div {
 | 
				
			||||||
	display: none;
 | 
						display: none;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* XXX are we selecting subtrees or blocks??? */
 | 
					/* XXX are we selecting subtrees or blocks??? */
 | 
				
			||||||
.editor [selected] {
 | 
					.editor .outline [selected] {
 | 
				
			||||||
	background: silver;
 | 
						background: silver;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
.editor div:focus {
 | 
					
 | 
				
			||||||
	/*outline: solid 0.2em silver;*/
 | 
					.editor .toolbar {
 | 
				
			||||||
	outline: none;
 | 
						display: inline-block;
 | 
				
			||||||
 | 
						position: absolute; 
 | 
				
			||||||
 | 
						top: 1em;
 | 
				
			||||||
 | 
						right: 1em;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
.editor div:focus>span,
 | 
					.editor .toolbar button {
 | 
				
			||||||
.editor div:focus>textarea {
 | 
						display: block;
 | 
				
			||||||
	background: rgba(0,0,0,0.1);
 | 
						width: var(--button-size);
 | 
				
			||||||
 | 
						height: var(--button-size);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -167,7 +167,8 @@ var Outline = {
 | 
				
			|||||||
				this.at(node)
 | 
									this.at(node)
 | 
				
			||||||
			: node == 'focused' ?
 | 
								: node == 'focused' ?
 | 
				
			||||||
				(this.dom.querySelector(`[tabindex]:focus`)
 | 
									(this.dom.querySelector(`[tabindex]:focus`)
 | 
				
			||||||
					|| this.dom.querySelector(`textarea:focus`)?.parentElement)
 | 
										|| this.dom.querySelector(`textarea:focus`)?.parentElement
 | 
				
			||||||
 | 
										|| this.dom.querySelector('[tabindex].focused'))
 | 
				
			||||||
			: node == 'parent' ?
 | 
								: node == 'parent' ?
 | 
				
			||||||
				this.get('focused')?.parentElement
 | 
									this.get('focused')?.parentElement
 | 
				
			||||||
			: node 
 | 
								: node 
 | 
				
			||||||
@ -221,7 +222,7 @@ var Outline = {
 | 
				
			|||||||
		// deindent...
 | 
							// deindent...
 | 
				
			||||||
		if(!indent){
 | 
							if(!indent){
 | 
				
			||||||
			var parent = cur.parentElement
 | 
								var parent = cur.parentElement
 | 
				
			||||||
			if(!parent.classList.contains('.editor')){
 | 
								if(!parent.classList.contains('.outline')){
 | 
				
			||||||
				var children = siblings.slice(siblings.indexOf(cur)+1)
 | 
									var children = siblings.slice(siblings.indexOf(cur)+1)
 | 
				
			||||||
				parent.after(cur)
 | 
									parent.after(cur)
 | 
				
			||||||
				children.length > 0
 | 
									children.length > 0
 | 
				
			||||||
@ -260,9 +261,10 @@ var Outline = {
 | 
				
			|||||||
				elem.updateSize() } }
 | 
									elem.updateSize() } }
 | 
				
			||||||
		return node },
 | 
							return node },
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// XXX
 | 
						// XXX should this handle focus???
 | 
				
			||||||
	remove: function(node){
 | 
						remove: function(node='focused', offset){
 | 
				
			||||||
	},
 | 
							this.get(...arguments)?.remove()
 | 
				
			||||||
 | 
							return this },
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// block serialization...
 | 
						// block serialization...
 | 
				
			||||||
	__code2html__: function(code){
 | 
						__code2html__: function(code){
 | 
				
			||||||
@ -333,7 +335,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('.editor textarea:focus')){
 | 
								if(this.dom.querySelector('.outline 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 
 | 
				
			||||||
@ -343,7 +345,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('.editor textarea:focus')){
 | 
								if(this.dom.querySelector('.outline 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){
 | 
				
			||||||
@ -394,7 +396,7 @@ var Outline = {
 | 
				
			|||||||
				return }
 | 
									return }
 | 
				
			||||||
			this.toggleCollapse(true)
 | 
								this.toggleCollapse(true)
 | 
				
			||||||
			var next = this.get('next')
 | 
								var next = this.get('next')
 | 
				
			||||||
			this.get()?.remove() 
 | 
								this.remove()
 | 
				
			||||||
			next?.focus() },
 | 
								next?.focus() },
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// select...
 | 
							// select...
 | 
				
			||||||
@ -414,20 +416,26 @@ 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')
 | 
				
			||||||
		// update stuff already in DOM...
 | 
							// update stuff already in DOM...
 | 
				
			||||||
		for(var elem of [...dom.querySelectorAll('.editor textarea')]){
 | 
							for(var elem of [...outline.querySelectorAll('textarea')]){
 | 
				
			||||||
			elem.autoUpdateSize() } 
 | 
								elem.autoUpdateSize() } 
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// heboard handling...
 | 
							// heboard handling...
 | 
				
			||||||
		dom.addEventListener('keydown', 
 | 
							outline.addEventListener('keydown', 
 | 
				
			||||||
			function(evt){
 | 
								function(evt){
 | 
				
			||||||
				evt.key in that.keyboard 
 | 
									evt.key in that.keyboard 
 | 
				
			||||||
					&& that.keyboard[evt.key].call(that, evt) })
 | 
										&& that.keyboard[evt.key].call(that, evt) })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// toggle view/code of nodes...
 | 
							// toggle view/code of nodes...
 | 
				
			||||||
		dom.addEventListener('focusin', 
 | 
							outline.addEventListener('focusin', 
 | 
				
			||||||
			function(evt){
 | 
								function(evt){
 | 
				
			||||||
				var node = evt.target
 | 
									var node = evt.target
 | 
				
			||||||
 | 
									// handle focus...
 | 
				
			||||||
 | 
									for(var e of [...that.dom.querySelectorAll('.focused')]){
 | 
				
			||||||
 | 
										e.classList.remove('focused') }
 | 
				
			||||||
 | 
									that.get('focused')?.classList?.add('focused')
 | 
				
			||||||
 | 
									// textarea...
 | 
				
			||||||
				if(node.nodeName == 'TEXTAREA' 
 | 
									if(node.nodeName == 'TEXTAREA' 
 | 
				
			||||||
						&& node?.previousElementSibling?.nodeName == 'SPAN'){
 | 
											&& node?.previousElementSibling?.nodeName == 'SPAN'){
 | 
				
			||||||
					node.value = 
 | 
										node.value = 
 | 
				
			||||||
@ -435,7 +443,7 @@ var Outline = {
 | 
				
			|||||||
							that.__html2code__(node.previousElementSibling.innerHTML)
 | 
												that.__html2code__(node.previousElementSibling.innerHTML)
 | 
				
			||||||
							: node.previousElementSibling.innerHTML 
 | 
												: node.previousElementSibling.innerHTML 
 | 
				
			||||||
					node.updateSize() } })
 | 
										node.updateSize() } })
 | 
				
			||||||
		dom.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' 
 | 
				
			||||||
 | 
				
			|||||||
@ -21,6 +21,7 @@ var setup = function(){
 | 
				
			|||||||
</head>
 | 
					</head>
 | 
				
			||||||
<body onload="setup()">
 | 
					<body onload="setup()">
 | 
				
			||||||
<div class="editor">
 | 
					<div class="editor">
 | 
				
			||||||
 | 
						<div class="outline">
 | 
				
			||||||
		<div tabindex=0>
 | 
							<div tabindex=0>
 | 
				
			||||||
			<span><i>root</i></span><textarea></textarea>
 | 
								<span><i>root</i></span><textarea></textarea>
 | 
				
			||||||
			<div tabindex=0 collapsed>
 | 
								<div tabindex=0 collapsed>
 | 
				
			||||||
@ -47,6 +48,13 @@ text lines</span><textarea></textarea>
 | 
				
			|||||||
			</div>
 | 
								</div>
 | 
				
			||||||
		</div>
 | 
							</div>
 | 
				
			||||||
	</div>
 | 
						</div>
 | 
				
			||||||
 | 
						<div class="toolbar">
 | 
				
			||||||
 | 
							<button onclick="editor.deindent()"><</button>
 | 
				
			||||||
 | 
							<button onclick="editor.indent()">></button>
 | 
				
			||||||
 | 
							<button>indent</button>
 | 
				
			||||||
 | 
							<button>indent</button>
 | 
				
			||||||
 | 
						</div>
 | 
				
			||||||
 | 
					</div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
<hr>
 | 
					<hr>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user