mirror of
				https://github.com/flynx/pWiki.git
				synced 2025-10-31 11:00:08 +00:00 
			
		
		
		
	refactoring + fixes...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
		
							parent
							
								
									56bf5c7592
								
							
						
					
					
						commit
						c68095f97a
					
				| @ -161,9 +161,9 @@ object.Constructor('BasePage', { | |||||||
| 				&& this.__beforenavigate__(location) }), | 				&& this.__beforenavigate__(location) }), | ||||||
| 	onNavigate: types.event.Event('navigate', | 	onNavigate: types.event.Event('navigate', | ||||||
| 		function(handle, location){ | 		function(handle, location){ | ||||||
|  | 			var {path, args} = pwpath.splitArgs(location) | ||||||
| 			this.onBeforeNavigate(location) | 			this.onBeforeNavigate(location) | ||||||
| 			this.referrer = this.location | 			this.referrer = this.location | ||||||
| 			var {path, args} = pwpath.splitArgs(location) |  | ||||||
| 			var cur = this.__location =  | 			var cur = this.__location =  | ||||||
| 				this.resolvePathVars( | 				this.resolvePathVars( | ||||||
| 					// NOTE: this is done instead of simply assigning 
 | 					// NOTE: this is done instead of simply assigning 
 | ||||||
| @ -213,6 +213,8 @@ object.Constructor('BasePage', { | |||||||
| 	get name(){ | 	get name(){ | ||||||
| 		return pwpath.basename(this.path) }, | 		return pwpath.basename(this.path) }, | ||||||
| 	set name(value){ | 	set name(value){ | ||||||
|  | 		if(pwpath.normalize(value) == ''){ | ||||||
|  | 			return } | ||||||
| 		this.move( | 		this.move( | ||||||
| 			/^[\\\/]/.test(value) ? | 			/^[\\\/]/.test(value) ? | ||||||
| 				value | 				value | ||||||
| @ -405,6 +407,8 @@ object.Constructor('BasePage', { | |||||||
| 	// XXX should these be implemented here or proxy to .store???
 | 	// XXX should these be implemented here or proxy to .store???
 | ||||||
| 	// XXX do we sanity check to no not contain '*'???
 | 	// XXX do we sanity check to no not contain '*'???
 | ||||||
| 	copy: async function(to, base=true){ | 	copy: async function(to, base=true){ | ||||||
|  | 		if(this.get(to).path == this.path){ | ||||||
|  | 			return this } | ||||||
| 		// copy children...
 | 		// copy children...
 | ||||||
| 		if(this.isPattern){ | 		if(this.isPattern){ | ||||||
| 			var base = this.path.split('*')[0] | 			var base = this.path.split('*')[0] | ||||||
| @ -422,6 +426,8 @@ object.Constructor('BasePage', { | |||||||
| 		return this }, | 		return this }, | ||||||
| 	move: async function(to, base=true){ | 	move: async function(to, base=true){ | ||||||
| 		var from = this.path | 		var from = this.path | ||||||
|  | 		if(this.get(to).path == this.path){ | ||||||
|  | 			return this } | ||||||
| 		await this.copy(to, base) | 		await this.copy(to, base) | ||||||
| 		this.delete(from, base) | 		this.delete(from, base) | ||||||
| 		return this }, | 		return this }, | ||||||
|  | |||||||
| @ -10,6 +10,34 @@ | |||||||
| var types = require('ig-types') | var types = require('ig-types') | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | //---------------------------------------------------------------------
 | ||||||
|  | 
 | ||||||
|  | var makeEncoder = function(name, chars){ | ||||||
|  | 	var pattern_attr = '__'+name+'_pattern' | ||||||
|  | 	return function(str){ | ||||||
|  | 		var pattern = this[pattern_attr] =  | ||||||
|  | 			this[pattern_attr]  | ||||||
|  | 				?? RegExp(`[${ | ||||||
|  | 					this[chars] | ||||||
|  | 						.replace(/\\/g, '\\\\') }]`, 'g')
 | ||||||
|  | 		return str | ||||||
|  | 			.replace(pattern, | ||||||
|  | 				function(s){  | ||||||
|  | 					return ('%'+s.charCodeAt().toString(16)).toUpperCase() }) } } | ||||||
|  | var makeDecoder = function(name, encode, chars){ | ||||||
|  | 	var pattern_attr = '__'+name+'_pattern' | ||||||
|  | 	return function(str){ | ||||||
|  | 		var pattern = this[pattern_attr] =  | ||||||
|  | 			this[pattern_attr]  | ||||||
|  | 				?? RegExp(`%(${ | ||||||
|  | 					this[encode](this[chars]) | ||||||
|  | 						.slice(1) | ||||||
|  | 						.replace(/%/g, '|') })`, 'gi')
 | ||||||
|  | 		return str | ||||||
|  | 			.replace(pattern, function(_, c){ | ||||||
|  | 				return String.fromCharCode('0x'+c) }) } } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| //---------------------------------------------------------------------
 | //---------------------------------------------------------------------
 | ||||||
| // Path...
 | // Path...
 | ||||||
| 
 | 
 | ||||||
| @ -50,20 +78,20 @@ module = { | |||||||
| 	SYSTEM_PATH: '/.system', | 	SYSTEM_PATH: '/.system', | ||||||
| 
 | 
 | ||||||
| 	// XXX EXPERIMENTAL
 | 	// XXX EXPERIMENTAL
 | ||||||
| 	encode: function(str){ | 	 | ||||||
| 		return str | 	ENCODED_PATH: '#:*%', | ||||||
| 			.replace(/[#:*%]/g,  | 	encode: makeEncoder('encode', 'ENCODED_PATH'), | ||||||
| 				function(s){  | 	decode: makeDecoder('decode', 'encode', 'ENCODED_PATH'), | ||||||
| 					return '%'+s.charCodeAt().toString(16) }) }, | 
 | ||||||
| 	decode: function(str){ | 	ENCODED_ELEM: '#:*%\\/', | ||||||
| 		return decodeURIComponent(str) }, | 	encodeElem: makeEncoder('encode_elem', 'ENCODED_ELEM'), | ||||||
| 	encodeElem: function(str){ | 	decodeElem: makeDecoder('decode_elem', 'encodeElem', 'ENCODED_ELEM'), | ||||||
| 		return str | 
 | ||||||
| 			.replace(/[#:*%\\\/]/g, | 	// chars we keep in path as-is -- decode on normalize...
 | ||||||
| 				function(s){  | 	//
 | ||||||
| 					return '%'+s.charCodeAt().toString(16) }) }, | 	UNENCODED_PATH: '\'"', | ||||||
| 	decodeElem: function(str){ | 	quote: makeEncoder('quote', 'UNENCODED_PATH'), | ||||||
| 		return decodeURIComponent(str) }, | 	unquote: makeDecoder('unquote', 'quote', 'UNENCODED_PATH'), | ||||||
| 
 | 
 | ||||||
| 	/*/ XXX NORMCACHE... | 	/*/ XXX NORMCACHE... | ||||||
| 	__normalized_cache_threshold: 100, | 	__normalized_cache_threshold: 100, | ||||||
| @ -104,7 +132,8 @@ module = { | |||||||
| 			: format | 			: format | ||||||
| 		var root = path[0] == ''  | 		var root = path[0] == ''  | ||||||
| 			|| path[0] == '/' | 			|| path[0] == '/' | ||||||
| 		path = (path instanceof Array ? | 		path = this.unquote( | ||||||
|  | 				path instanceof Array ? | ||||||
| 					path.join('/') | 					path.join('/') | ||||||
| 					: path) | 					: path) | ||||||
| 			// NOTE: this will also trim the path elements...
 | 			// NOTE: this will also trim the path elements...
 | ||||||
|  | |||||||
							
								
								
									
										18
									
								
								pwiki2.html
									
									
									
									
									
								
							
							
						
						
									
										18
									
								
								pwiki2.html
									
									
									
									
									
								
							| @ -102,6 +102,15 @@ body.loading .page.spinner span { | |||||||
| 	} | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | [contenteditable] { | ||||||
|  |   outline: 0px solid transparent; | ||||||
|  | } | ||||||
|  | [contenteditable]:empty:after { | ||||||
|  | 	display: block; | ||||||
|  | 	content: 'Empty'; | ||||||
|  | 	opacity: 0.3; | ||||||
|  | } | ||||||
|  | 
 | ||||||
| 
 | 
 | ||||||
| </style> | </style> | ||||||
| 
 | 
 | ||||||
| @ -178,9 +187,6 @@ var SAVE_LIVE_QUEUE = {} | |||||||
| 
 | 
 | ||||||
| var saveLiveContent =  | var saveLiveContent =  | ||||||
| function(path, text){ | function(path, text){ | ||||||
| 	path = path |  | ||||||
| 		.replace(/%22/g, '"') |  | ||||||
| 		.replace(/%27/g, "'") |  | ||||||
| 	SAVE_LIVE_QUEUE[path] = text  | 	SAVE_LIVE_QUEUE[path] = text  | ||||||
| 	// clear editor page cache... | 	// clear editor page cache... | ||||||
| 	pwiki.cache = null } | 	pwiki.cache = null } | ||||||
| @ -188,11 +194,7 @@ function(path, text){ | |||||||
| var SAVE_QUEUE = {} | var SAVE_QUEUE = {} | ||||||
| var saveContent = | var saveContent = | ||||||
| function(path, text){ | function(path, text){ | ||||||
| 	path = path | 	SAVE_QUEUE[path] = text } | ||||||
| 		.replace(/%22/g, '"') |  | ||||||
| 		.replace(/%27/g, "'") |  | ||||||
| 	SAVE_QUEUE[path] = text |  | ||||||
| } |  | ||||||
| 
 | 
 | ||||||
| var saveAll = | var saveAll = | ||||||
| function(){ | function(){ | ||||||
|  | |||||||
| @ -15,7 +15,6 @@ | |||||||
| * 			pwiki.path = '/tree' 								// reports about ~2sec
 | * 			pwiki.path = '/tree' 								// reports about ~2sec
 | ||||||
| * 			await pwiki.get('/Test/Subtree/Page2').delete()		// fast
 | * 			await pwiki.get('/Test/Subtree/Page2').delete()		// fast
 | ||||||
| * 			pwiki.path = '/tree' 								// reports about ~2sec
 | * 			pwiki.path = '/tree' 								// reports about ~2sec
 | ||||||
| * XXX FEATURE would be nice to have a deleteAll action... |  | ||||||
| * XXX macros: should we add the pattern path to .depends instead of the | * XXX macros: should we add the pattern path to .depends instead of the | ||||||
| * 		final path... | * 		final path... | ||||||
| * 		...would also need a fast way to pattern match... | * 		...would also need a fast way to pattern match... | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user