From 02ebc61a59f9b07e810d8c3e6726a9d135e362de Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Sun, 14 Aug 2022 03:00:06 +0300 Subject: [PATCH] added basic editor + basic settings page... Signed-off-by: Alex A. Naanou --- browser.js | 2 ++ pwiki/page.js | 20 +++++++++++++++++++- pwiki2.html | 18 +++++++++++++++++- pwiki2.js | 10 ++++++++-- 4 files changed, 46 insertions(+), 4 deletions(-) diff --git a/browser.js b/browser.js index 2c690d4..e1366ae 100755 --- a/browser.js +++ b/browser.js @@ -31,6 +31,8 @@ module.store = store.update('System', Object.create(basestore.BaseStore).load(page.System)) +store.update('Settings', + Object.create(basestore.BaseStore).load(page.Settings)) var pwiki = module.pwiki = diff --git a/pwiki/page.js b/pwiki/page.js index 852b4f9..d2701e2 100755 --- a/pwiki/page.js +++ b/pwiki/page.js @@ -664,7 +664,7 @@ object.Constructor('Page', BasePage, { // XXX can we lose stuff from state this way??? // ...at this stage it should more or less be static -- check! var res = - await this.__parser__.filter(this, ast, { + await this.__parser__.parse(this, ast, { ...state, filters: local.includes(this.ISOLATED_FILTERS) ? local @@ -1231,6 +1231,15 @@ module.System = { // XXX not sure if this is the right way to go... _code: { text: '
' }, + //_edit: { + _ed: { + text: + '
'
+				+''
+			+'
' }, // base system pages... @@ -1302,6 +1311,15 @@ module.System = { // XXX System/reverse } +var Settings = +module.Settings = { + Export: { + text: '' }, + // XXX + Settings: { + text: '{}' }, +} + diff --git a/pwiki2.html b/pwiki2.html index b99b4a5..1a1863f 100755 --- a/pwiki2.html +++ b/pwiki2.html @@ -131,8 +131,24 @@ require(['./browser'], function(pwiki){ }) +// XXX make this a 2 stage save -- first cache and then save to store... +// XXX versioning??? +var SAVE_TIMEOUT = 5000 +var SAVE_QUEUE = {} +var saveContent = function(path, text){ + SAVE_QUEUE[path] = 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) + + // XXX -var saveData = async function(){ +var exportData = async function(){ var blob = new Blob([await pwiki.store.json(true)], {type: "text/plain;charset=utf-8"}); var a = document.createElement('a') diff --git a/pwiki2.js b/pwiki2.js index 0cc6a88..87282c0 100755 --- a/pwiki2.js +++ b/pwiki2.js @@ -1,6 +1,7 @@ /********************************************************************** * * +* XXX BUG: comments seem to be broken -- see: /Doc/About * XXX BUG: browser: .get('/*').raw hangs... * XXX add action to reset overloaded (bootstrap) pages... * - per page @@ -17,8 +18,10 @@ * - render page -- DONE * - navigation -- DONE * - hash/anchor -- DONE -* - basic editor and interactivity -* - export / zip +* - basic editor and interactivity -- DONE +* - export +* - json -- DONE +* - zip * - migrate bootstrap * - store topology * - sync and sync conf @@ -229,6 +232,9 @@ module.store = // XXX nested system store... store.update('System', Object.create(basestore.BaseStore).load(page.System)) +store.update('Settings', + Object.create(basestore.BaseStore).load(page.Settings)) + // NOTE: in general the root wiki api is simply a page instance.