mirror of
				https://github.com/flynx/pWiki.git
				synced 2025-10-31 02:50:08 +00:00 
			
		
		
		
	events and other tweaks...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
		
							parent
							
								
									dd22f1faba
								
							
						
					
					
						commit
						539028a918
					
				| @ -10,6 +10,8 @@ | |||||||
|     "ig-object": "*", |     "ig-object": "*", | ||||||
|     "ig-types": "^6.9.4", |     "ig-types": "^6.9.4", | ||||||
|     "jszip": "*", |     "jszip": "*", | ||||||
|  |     "pouchdb": "^7.3.0", | ||||||
|  |     "pouchdb-browser": "^7.3.0", | ||||||
|     "requirejs": "*" |     "requirejs": "*" | ||||||
|   }, |   }, | ||||||
|   "disabled-dependencies": { |   "disabled-dependencies": { | ||||||
|  | |||||||
							
								
								
									
										78
									
								
								pwiki2.js
									
									
									
									
									
								
							
							
						
						
									
										78
									
								
								pwiki2.js
									
									
									
									
									
								
							| @ -31,11 +31,6 @@ | |||||||
| * XXX might need to get all the links (macro-level) from a page... | * XXX might need to get all the links (macro-level) from a page... | ||||||
| * 		...would be useful for caching... | * 		...would be useful for caching... | ||||||
| * | * | ||||||
| * XXX add page events: |  | ||||||
| * 		locationChange |  | ||||||
| * 		renderDone |  | ||||||
| * 		... |  | ||||||
| * |  | ||||||
| * | * | ||||||
| * | * | ||||||
| **********************************************************************/ | **********************************************************************/ | ||||||
| @ -700,11 +695,13 @@ function(name){ | |||||||
| 			module.path.relative(this.location, path),  | 			module.path.relative(this.location, path),  | ||||||
| 			strict) } } | 			strict) } } | ||||||
| 
 | 
 | ||||||
|  | var __HANDLE_NAVIGATE = | ||||||
|  | module.__HANDLE_NAVIGATE =  | ||||||
|  | 	types.event.EventCommand('HANDLE_NAVIGATE') | ||||||
|  | 
 | ||||||
| // XXX PATH_VARS
 | // XXX PATH_VARS
 | ||||||
| // XXX HISTORY do we need history management??? 
 | // XXX HISTORY do we need history management??? 
 | ||||||
| // XXX FUNC need to handle functions in store...
 | // XXX FUNC need to handle functions in store...
 | ||||||
| // XXX EVENT add event triggers/handlers...
 |  | ||||||
| // 		...event handlers must be local and not propogate to the root page.
 |  | ||||||
| var BasePage = | var BasePage = | ||||||
| module.BasePage =  | module.BasePage =  | ||||||
| object.Constructor('BasePage', { | object.Constructor('BasePage', { | ||||||
| @ -755,11 +752,31 @@ object.Constructor('BasePage', { | |||||||
| 	//
 | 	//
 | ||||||
| 	// NOTE: path variables are resolved relative to the page BEFORE 
 | 	// NOTE: path variables are resolved relative to the page BEFORE 
 | ||||||
| 	// 		navigation...
 | 	// 		navigation...
 | ||||||
|  | 	// NOTE: the actual work is done by the .onNavigate(..) method...
 | ||||||
| 	__location: undefined, | 	__location: undefined, | ||||||
| 	get location(){ | 	get location(){ | ||||||
| 		return this.__location ?? '/' }, | 		return this.__location ?? '/' }, | ||||||
| 	// XXX EVENT need to be able to trigger a callback/event on this...
 |  | ||||||
| 	set location(path){ | 	set location(path){ | ||||||
|  | 		// trigger the event...
 | ||||||
|  | 		this.onNavigate(path) }, | ||||||
|  | 	// referrer -- a previous page location...
 | ||||||
|  | 	referrer: undefined, | ||||||
|  | 
 | ||||||
|  | 	// events...
 | ||||||
|  | 	//
 | ||||||
|  | 	// XXX revise naming...
 | ||||||
|  | 	// XXX should this be able to prevent navigation???
 | ||||||
|  | 	onBeforeNavigate: types.event.Event('beforeNavigate'), | ||||||
|  | 	onNavigate: types.event.Event('navigate', | ||||||
|  | 		function(handle, path){ | ||||||
|  | 			// special case: we are triggering handlers only...
 | ||||||
|  | 			// NOTE: this usually means that we are setting .__location 
 | ||||||
|  | 			// 		externally...
 | ||||||
|  | 			// XXX HISTORY this is only used for history at this point...
 | ||||||
|  | 			if(path === module.__HANDLE_NAVIGATE){ | ||||||
|  | 				handle() | ||||||
|  | 				return } | ||||||
|  | 			this.onBeforeNavigate(path) | ||||||
| 			this.referrer = this.location | 			this.referrer = this.location | ||||||
| 			var cur = this.__location =  | 			var cur = this.__location =  | ||||||
| 				this.resolvePathVars( | 				this.resolvePathVars( | ||||||
| @ -772,9 +789,9 @@ object.Constructor('BasePage', { | |||||||
| 					&& this.history.splice( | 					&& this.history.splice( | ||||||
| 						this.history.indexOf(this.__location)+1,  | 						this.history.indexOf(this.__location)+1,  | ||||||
| 						this.history.length) | 						this.history.length) | ||||||
| 			this.history.push(cur) } }, | 				this.history.push(cur) }  | ||||||
| 	// referrer -- a previous page location...
 | 			// trigger handlers...
 | ||||||
| 	referrer: undefined, | 			handle() }), | ||||||
| 
 | 
 | ||||||
| 	// .path is a proxy to .location
 | 	// .path is a proxy to .location
 | ||||||
| 	// XXX do we need this???
 | 	// XXX do we need this???
 | ||||||
| @ -794,7 +811,6 @@ object.Constructor('BasePage', { | |||||||
| 	get isPattern(){ | 	get isPattern(){ | ||||||
| 		return this.location.includes('*') }, | 		return this.location.includes('*') }, | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
| 	// history...
 | 	// history...
 | ||||||
| 	//
 | 	//
 | ||||||
| 	//* XXX HISTORY...
 | 	//* XXX HISTORY...
 | ||||||
| @ -807,7 +823,6 @@ object.Constructor('BasePage', { | |||||||
| 			this.__history = [] } | 			this.__history = [] } | ||||||
| 			//this.__history = (this.__history ?? []).slice() }
 | 			//this.__history = (this.__history ?? []).slice() }
 | ||||||
| 		return this.__history }, | 		return this.__history }, | ||||||
| 	// XXX EVENT trigger location change event..,
 |  | ||||||
| 	back: function(offset=1){ | 	back: function(offset=1){ | ||||||
| 		var h = this.history | 		var h = this.history | ||||||
| 		if(h === false  | 		if(h === false  | ||||||
| @ -826,8 +841,10 @@ object.Constructor('BasePage', { | |||||||
| 					+ offset, | 					+ offset, | ||||||
| 				h.length-1),  | 				h.length-1),  | ||||||
| 			0) | 			0) | ||||||
|  | 		this.onBeforeNavigate(this.path) | ||||||
| 		this.referrer = this.location | 		this.referrer = this.location | ||||||
| 		this.__location = h[h.length-1 - p] | 		var path = this.__location = h[h.length-1 - p] | ||||||
|  | 		this.onNavigate(module.__HANDLE_NAVIGATE, path) | ||||||
| 		return this }, | 		return this }, | ||||||
| 	forward: function(offset=1){ | 	forward: function(offset=1){ | ||||||
| 		return this.back(-offset) }, | 		return this.back(-offset) }, | ||||||
| @ -861,7 +878,6 @@ object.Constructor('BasePage', { | |||||||
| 			: res }, | 			: res }, | ||||||
| 		//return this.store.get(this.location, !!this.strict) },
 | 		//return this.store.get(this.location, !!this.strict) },
 | ||||||
| 	set data(value){ | 	set data(value){ | ||||||
| 		//this.store.update(this.location, value) },
 |  | ||||||
| 		this.__update__(value) }, | 		this.__update__(value) }, | ||||||
| 
 | 
 | ||||||
| 	// metadata...
 | 	// metadata...
 | ||||||
| @ -871,7 +887,6 @@ object.Constructor('BasePage', { | |||||||
| 	get metadata(){ | 	get metadata(){ | ||||||
| 		return this.store.metadata(this.location) }, | 		return this.store.metadata(this.location) }, | ||||||
| 	set metadata(value){ | 	set metadata(value){ | ||||||
| 		//this.store.update(this.location, value) },
 |  | ||||||
| 		this.__update__(value) }, | 		this.__update__(value) }, | ||||||
| 
 | 
 | ||||||
| 	// number of matching pages...
 | 	// number of matching pages...
 | ||||||
| @ -1065,6 +1080,8 @@ object.Constructor('BasePage', { | |||||||
| 
 | 
 | ||||||
| 	// XXX should this be update or assign???
 | 	// XXX should this be update or assign???
 | ||||||
| 	// XXX how should this work on multiple pages...
 | 	// XXX how should this work on multiple pages...
 | ||||||
|  | 	// 		...right now this will write what-ever is given, even if it
 | ||||||
|  | 	// 		will never be explicitly be accessible...
 | ||||||
| 	update: function(...data){ | 	update: function(...data){ | ||||||
| 		return Object.assign(this, ...data) }, | 		return Object.assign(this, ...data) }, | ||||||
| 
 | 
 | ||||||
| @ -1076,6 +1093,9 @@ object.Constructor('BasePage', { | |||||||
| 		this.referrer = referrer }, | 		this.referrer = referrer }, | ||||||
| }) | }) | ||||||
| 
 | 
 | ||||||
|  | // pepper in event functionality...
 | ||||||
|  | types.event.EventMixin(BasePage.prototype) | ||||||
|  | 
 | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| //---------------------------------------------------------------------
 | //---------------------------------------------------------------------
 | ||||||
| @ -2053,6 +2073,20 @@ object.Constructor('Page', BasePage, { | |||||||
| 		'join': ['macro'], | 		'join': ['macro'], | ||||||
| 	}, | 	}, | ||||||
| 
 | 
 | ||||||
|  | 	// events...
 | ||||||
|  | 	//
 | ||||||
|  | 	// NOTE: textUpdate event will not get triggered if text is updated 
 | ||||||
|  | 	// 		directly via .data or .__update__(..)
 | ||||||
|  | 	/*/ XXX EVENTS do we need this??? | ||||||
|  | 	onTextUpdate: types.event.Event('textUpdate', | ||||||
|  | 		function(handle, text){ | ||||||
|  | 			this.__update__({text}) }), | ||||||
|  | 	// XXX EVENTS not sure where to trigger this???
 | ||||||
|  | 	// 		...on .parse(..) is a bit too granular, something like .text??
 | ||||||
|  | 	// XXX not triggered yet...
 | ||||||
|  | 	//onParse: types.event.Event('parse'),
 | ||||||
|  | 	//*/
 | ||||||
|  | 
 | ||||||
| 	// page parser...
 | 	// page parser...
 | ||||||
| 	//
 | 	//
 | ||||||
| 	__parser__: module.parser, | 	__parser__: module.parser, | ||||||
| @ -2065,10 +2099,10 @@ object.Constructor('Page', BasePage, { | |||||||
| 			text = null } | 			text = null } | ||||||
| 		state = state ?? {} | 		state = state ?? {} | ||||||
| 		text = text ?? this.raw | 		text = text ?? this.raw | ||||||
| 		if(text instanceof Array){ | 		return text instanceof Array ? | ||||||
| 			return text.map(function(text){ | 			text.map(function(text){ | ||||||
| 				return this.__parser__.parse(this, text, state) }.bind(this)) } | 				return this.__parser__.parse(this, text, state) }.bind(this)) | ||||||
| 		return this.__parser__.parse(this, text, state) }, | 			: this.__parser__.parse(this, text, state) }, | ||||||
| 
 | 
 | ||||||
| 	// true if page has an array value but is not a pattern page...
 | 	// true if page has an array value but is not a pattern page...
 | ||||||
| 	//
 | 	//
 | ||||||
| @ -2115,8 +2149,8 @@ object.Constructor('Page', BasePage, { | |||||||
| 					.flat() | 					.flat() | ||||||
|    			: data.text }, |    			: data.text }, | ||||||
| 	set raw(value){ | 	set raw(value){ | ||||||
| 		//this.store.update(this.location, {text: value}) },
 |  | ||||||
| 		this.__update__({text: value}) }, | 		this.__update__({text: value}) }, | ||||||
|  | 		//this.onTextUpdate(value) },
 | ||||||
| 
 | 
 | ||||||
| 	// expanded page text...
 | 	// expanded page text...
 | ||||||
| 	//
 | 	//
 | ||||||
| @ -2131,8 +2165,8 @@ object.Constructor('Page', BasePage, { | |||||||
| 			.flat() | 			.flat() | ||||||
| 			.join('\n') },  | 			.join('\n') },  | ||||||
| 	set text(value){ | 	set text(value){ | ||||||
| 		//this.store.update(this.location, {text: value}) },
 |  | ||||||
| 		this.__update__({text: value}) }, | 		this.__update__({text: value}) }, | ||||||
|  | 		//this.onTextUpdate(value) },
 | ||||||
| }) | }) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user