From 45beb4bbde293644dccc547cdc5414c640d1db03 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Thu, 11 Aug 2022 10:39:55 +0300 Subject: [PATCH] better hash handling + tweaking and notes... Signed-off-by: Alex A. Naanou --- pwiki/page.js | 30 +++++++++++++++++++++++++++--- pwiki/store/base.js | 15 +++++++++++---- pwiki2.html | 10 ++++------ pwiki2.js | 8 +++++++- 4 files changed, 49 insertions(+), 14 deletions(-) diff --git a/pwiki/page.js b/pwiki/page.js index e2edfe7..168e68b 100755 --- a/pwiki/page.js +++ b/pwiki/page.js @@ -329,7 +329,6 @@ object.Constructor('BasePage', { // XXX should this be an iterator??? each: async function*(path){ - var that = this // NOTE: we are trying to avoid resolving non-pattern paths unless // we really have to... path = path ? @@ -345,7 +344,7 @@ object.Constructor('BasePage', { : [paths] for(var path of paths){ - yield that.get('/'+ path) } }, + yield this.get('/'+ path) } }, map: async function(func){ return this.each().map(func) }, @@ -1132,17 +1131,41 @@ object.Constructor('pWikiPageElement', Page, { dom: undefined, + domFilters: { // XXX see Page.filters.wikiword for notes... wikiword: wikiword.wikiWordText, }, + // NOTE: setting location will reset .hash set it directly via either + // one of: + // .location = [path, hash] + // .location = 'path#hash' + hash: undefined, + // NOTE: getting .location will not return the hash, so as not to force + // the user to parse it out each time. + get location(){ + return object.parentProperty(pWikiPageElement.prototype, 'location') + .get.call(this) }, + set location(value){ + var [value, hash] = + // .location = [path, hash] + value instanceof Array ? + value + // .location = '#' + : value.includes('#') ? + value.split('#') + // no hash is given... + : [value, undefined] + this.hash = hash + object.parentProperty(pWikiPageElement.prototype, 'location') + .set.call(this, value) }, + // XXX this is not persistent, is this what we want??? get title(){ return this.dom.getAttribute('title') || (this.dom.querySelector('h1') || {}).innerText || this.path }, - // XXX this is not persistent, is this what we want??? set title(value){ this.dom.setAttribute('title', value) }, @@ -1172,6 +1195,7 @@ object.Constructor('pWikiPageElement', Page, { && (page.__proto__ = this.__page_constructor__.prototype) return page }, + // handle dom as first argument... __init__: function(dom, ...args){ if(dom instanceof Element){ this.dom = dom diff --git a/pwiki/store/base.js b/pwiki/store/base.js index 5c59dbb..c8d4ffc 100755 --- a/pwiki/store/base.js +++ b/pwiki/store/base.js @@ -343,19 +343,26 @@ module.BaseStore = { for(var [path, value] of Object.entries(input)){ this.update(path, value) } } return this }, + // NOTE: this will not serialize functions... //__batch_json__: function(){ // // ... // return json}, - json: async function(asstring=false){ + json: async function(options={}){ + if(options === true){ + options = {stringify: true} } + var {stringify, keep_funcs} = options // batch... if(this.__batch_json__){ - var res = this.__batch_json__(asstring) + var res = this.__batch_json__(stringify) // generic... } else { var res = {} for(var path of await this.paths()){ - res[path] = await this.get(path) } } - return (asstring + var page = await this.get(path) + if(keep_funcs + || typeof(page) != 'function'){ + res[path] = page } } } + return (stringify && typeof(res) != 'string') ? JSON.stringify(res) : res }, diff --git a/pwiki2.html b/pwiki2.html index 0071d90..8d81c79 100755 --- a/pwiki2.html +++ b/pwiki2.html @@ -101,14 +101,11 @@ require(['./browser'], function(pwiki){ pwiki.path //'/' : path - // XXX treat links as absolute unless explicitly relative... + // treat links as absolute unless explicitly relative... path = /^\.\.?([\\\/].*)?$/.test(path) ? path : '/'+path - // NOTE: .hash needs to be set before .path, otherwise the path - // handlers will not see it.. - pwiki.hash = hash - pwiki.path = path }) + pwiki.path = [path, hash] }) pwiki .onNavigate(function(){ // NOTE: we do not need to directly update location.hash here as @@ -140,7 +137,8 @@ require(['./browser'], function(pwiki){ -
+ +
Loading...
diff --git a/pwiki2.js b/pwiki2.js index 190a35d..b2c235c 100755 --- a/pwiki2.js +++ b/pwiki2.js @@ -1,6 +1,12 @@ /********************************************************************** * * +* XXX BUG: +* pwiki.get(..) -> Page object +* pwiki.get(..).get(..) -> pWikiPageElement object +* pwiki.get(..).get(..).get(..) -> Page object +* ... +* * XXX BUG: .get('/*').raw hangs... * XXX add action to reset overloaded (bootstrap) pages... * - per page @@ -20,7 +26,7 @@ * - editor and interactivity * - migrate bootstrap * - store topology -* - markdown -- DONE?? +* - markdown -- DONE * - WikiWord -- DONE * - dom filter mechanics -- DONE * - filters / dom filters: