diff --git a/pwiki/page.js b/pwiki/page.js
index 9f40b92..c88ae2a 100755
--- a/pwiki/page.js
+++ b/pwiki/page.js
@@ -211,10 +211,19 @@ object.Constructor('BasePage', {
// XXX should these be writable???
get name(){
return pwpath.basename(this.path) },
- //set name(value){ },
+ set name(value){
+ this.move(
+ /^[\\\/]/.test(value) ?
+ value
+ : '../'+value) },
get dir(){
return pwpath.dirname(this.path) },
- //set dir(value){ },
+ set dir(value){
+ var to = pwpath.join(value, this.name)
+ this.move(
+ /^[\\\/]/.test(to) ?
+ to
+ : '../'+to) },
/*/ XXX TITLE...
// NOTE: .__title is intentionally not persistent...
@@ -315,7 +324,25 @@ object.Constructor('BasePage', {
res.bind(this)
: res }).call(this) },
set data(value){
- this.__update__(value) },
+ if(this.actions
+ && this.actions[this.name]){
+ var name =
+ this.actions[this.name] === true ?
+ this.name
+ : this.actions[this.name]
+ var page = this.get('..')
+ // NOTE: this can return a promise, as we'll need to assign
+ // we do not care about it as long as it's not a function...
+ // XXX not sure if this is a good idea...
+ var res = page[name]
+ // set...
+ typeof(res) == 'function' ?
+ page[name](value.text ?? value)
+ : (page[name] = value.text ?? value)
+
+ // normal update...
+ } else {
+ this.__update__(value) } },
// metadata...
//
@@ -1413,7 +1440,7 @@ object.Constructor('Page', BasePage, {
.flat())
: data.text )}).call(this) },
set raw(value){
- this.__update__({text: value}) },
+ this.data = {text: value} },
//this.onTextUpdate(value) },
// iterate matches or content list as pages...
@@ -1510,7 +1537,7 @@ object.Constructor('Page', BasePage, {
renderer: this,
}) }).call(this) },
set text(value){
- this.__update__({text: value}) },
+ this.data = {text: value} },
//this.onTextUpdate(value) },
// pass on .renderer to clones...
@@ -1788,12 +1815,12 @@ module.System = {
// XXX all of these should support pattern pages...
_text: {
text: '@include(.:$ARGS isolated join="@source(file-separator)")' },
- // XXX /rootpath here is not relative -- makes reuse harder...
_view: {
text: object.doc`
☰
@source(./location/!)
+ ⟳
✎
@@ -1825,7 +1852,7 @@ module.System = {
+''
+ +'oninput="saveLiveContent(\'@source(./path)\', this.innerText)">'
+'
'
+'
'
+''
@@ -1839,13 +1866,13 @@ module.System = {
+''
+ +'oninput="saveLiveContent(\'@source(./path)/name\')">'
+'@source(./name)'
+'
'
+''
+ +'oninput="saveLiveContent(\'@source(./path)\', this.innerText)">'
+'
'
+'
'
+''},
@@ -1858,13 +1885,13 @@ module.System = {
+ oninput="saveContent(\'@source(./path)/name\', this.innerText)">
@source(./name)
`},
@@ -1967,20 +1994,16 @@ module.System = {
// page actions...
//
- // XXX broken...
// XXX this does not work as energetic...
time: async function(){
var t = Date.now()
var text = await this.get('../_text').text
var time = Date.now() - t
-
console.log('RENDER TIME:', time)
-
return object.doc`
- Time to render: ${time}ms
-
- ${text}`},
- //*/
+ Time to render: ${time}ms
+
+ ${text}`},
// XXX EXPERIMENTAL -- page types...
isAction: async function(){
@@ -2040,9 +2063,9 @@ module.System = {
&& this.renderer.refresh()
// XXX returning undefined will stop the redirect...
return '' },
- // XXX copy/move/...
- // XXX do we need this as a page action???
- move: function(){
+ // NOTE: this moves relative to the basedir and not relative to the
+ // page...
+ move: async function(){
var from = this.get('..')
// XXX this is ugly...
// ...need to standardize how we get arguments when rendering....
@@ -2050,19 +2073,25 @@ module.System = {
|| (this.renderer || {args:{}}).args.to
console.log('MOVE:', from.path, to)
- // XXX
- if(to){
- // XXX move...
- }
+
+ to
+ && await from.move(
+ /^[\\\/]/.test(to[0]) ?
+ to
+ : pwpath.join('..', to))
+
// redirect...
this.renderer
- && (this.renderer.location = this.referrer)
+ && to
+ //&& (this.renderer.location = this.referrer)
+ && (this.renderer.location = from.path)
// XXX this should not be needed...
&& this.renderer.refresh()
// XXX if we return undefined here this will not fully redirect,
// keeping the move page open but setting the url to the
// redirected page...
return '' },
+ // XXX copy/...
// XXX System/back
// XXX System/forward
diff --git a/pwiki2.html b/pwiki2.html
index 633c7fe..71fcf9c 100755
--- a/pwiki2.html
+++ b/pwiki2.html
@@ -173,22 +173,41 @@ require.config({
// Editor -- save changes...
// XXX versioning??
-var SAVE_TIMEOUT = 5000
+var SAVE_LIVE_TIMEOUT = 5000
+var SAVE_LIVE_QUEUE = {}
+
+var saveLiveContent =
+function(path, text){
+ SAVE_LIVE_QUEUE[path] = text
+ // clear editor page cache...
+ pwiki.cache = null }
+
var SAVE_QUEUE = {}
-var saveContent =
- function(path, text){
- SAVE_QUEUE[path] = text
- // clear editor page cache...
- pwiki.cache = null }
+var saveContent =
+function(path, text){
+ SAVE_QUEUE[path] = text
+}
+
+var saveAll =
+function(){
+ saveNow()
+ var queue = Object.entries(SAVE_QUEUE)
+ SAVE_QUEUE = {}
+ queue
+ .forEach(function([path, text]){
+ console.log('saving changes to:', path)
+ pwiki.get(path).raw = text }) }
+
var saveNow =
- function(){
- var queue = Object.entries(SAVE_QUEUE)
- SAVE_QUEUE = {}
- queue
- .forEach(function([path, text]){
- console.log('saving changes to:', path)
- pwiki.get(path).raw = text }) }
-setInterval(saveNow, 5000)
+function(){
+ var queue = Object.entries(SAVE_LIVE_QUEUE)
+ SAVE_LIVE_QUEUE = {}
+ NEW_TITLE = undefined
+ queue
+ .forEach(function([path, text]){
+ console.log('saving changes to:', path)
+ pwiki.get(path).raw = text }) }
+setInterval(saveNow, SAVE_LIVE_TIMEOUT)
@@ -206,8 +225,6 @@ window.stopSpinner = function(){
//---------------------------------------------------------------------
// General setup...
-REFRESH_DELAY = 20
-
document.pwikiloaded = new Event('pwikiloaded')
var logTime = async function(promise, msg=''){
@@ -223,6 +240,16 @@ var logTime = async function(promise, msg=''){
return res }
+REFRESH_DELAY = 20
+
+var refresh = async function(){
+ startSpinner()
+ setTimeout(function(){
+ logTime(
+ pwiki.refresh(),
+ pwiki.location) }, REFRESH_DELAY) }
+
+
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// start loading pWiki...
require(['./browser'], function(browser){
@@ -248,7 +275,7 @@ require(['./browser'], function(browser){
pwiki.location = [path, hash] }, REFRESH_DELAY) })
pwiki
.onBeforeNavigate(function(){
- saveNow() })
+ saveAll() })
.onNavigate(async function(){
// NOTE: we do not need to directly update location.hash here as
// that will push an extra history item...
@@ -279,12 +306,7 @@ require(['./browser'], function(browser){
// NOTE: we need to do this as hashchange is only triggered
// when the hash is actually changed...
for(var lnk of this.dom.querySelectorAll(`a[href="${location.hash}"]`)){
- lnk.addEventListener('click', function(evt){
- startSpinner()
- setTimeout(function(){
- logTime(
- that.refresh(),
- that.location) }, REFRESH_DELAY) }) } })
+ lnk.addEventListener('click', refresh) } })
// wait for stuff to finish...
browser.setup.then(function(){
diff --git a/pwiki2.js b/pwiki2.js
index 4407852..dd1f99e 100755
--- a/pwiki2.js
+++ b/pwiki2.js
@@ -55,6 +55,8 @@
* i.e. a way to pass tags through path...
* /some/path:tags=a,b,c
* XXX FEATURE images...
+* XXX generalize html/dom api...
+* ...see refresh() in pwiki2.html
* XXX async/live render...
* might be fun to push the async parts of the render to the dom...
* ...i.e. return a partially rendered DOM with handlers to fill