added update/delete page events and some template tweaking...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2022-10-31 02:29:21 +03:00
parent e3b104f9cc
commit bb04752e7a
5 changed files with 41 additions and 27 deletions

View File

@ -427,8 +427,9 @@ object.Constructor('BasePage', {
//*/
resolve: relMatchProxy('resolve'),
delete: async function(path='.', base=true){
delete: types.event.Event('delete',
async function(handle, path='.', base=true){
handle(false)
if(path === true || path === false){
base = path
path = '.' }
@ -440,7 +441,8 @@ object.Constructor('BasePage', {
this.__delete__(p) }
} else {
this.__delete__(path) }
return this },
handle()
return this }),
// XXX should these be implemented here or proxy to .store???
// XXX do we sanity check to no not contain '*'???
copy: async function(to, base=true){
@ -687,8 +689,9 @@ object.Constructor('BasePage', {
// ...right now this will write what-ever is given, even if it
// will never be explicitly be accessible...
// XXX sync/async???
update: function(...data){
return Object.assign(this, ...data) },
update: types.event.Event('update',
function(_, ...data){
return Object.assign(this, ...data) }),
// XXX should this take an options/dict argument????
__init__: function(path, referrer, store){
@ -1359,7 +1362,7 @@ object.Constructor('Page', BasePage, {
text = typeof(text) == 'string' ?
[...this.__parser__.group(this, text+'</macro>', 'macro')]
: text
var join
var join, itext
var iargs = {}
// stored macros...
@ -1383,7 +1386,7 @@ object.Constructor('Page', BasePage, {
// XXX is there a point in overloading text???
text = text.length > 0 ?
text
: itext
: itext ?? text
var sort = (args.sort
?? iargs.sort
?? '')
@ -1441,7 +1444,7 @@ object.Constructor('Page', BasePage, {
seen: state.seen,
depends,
renderer: state.renderer,
macros: args.inheritmacros ?
macros: inheritmacros ?
{__proto__: macros}
: {},
}
@ -2102,7 +2105,9 @@ module.System = {
<div class="item">
<a class="tree-page-title" href="#@source(s ./path)">@source(./title)</a>
<a class="show-on-hover" href="#@source(s ./path)/info">&#128712;</a>
<a class="show-on-hover" href="#@source(s ./path)/delete">&times;</a>
<a class="show-on-hover"
href="javascript:pwiki.delete('@source(s ./path)')"
>&times;</a>
</div>
<div style="padding-left: 30px">
@include("./tree:$ARGS")

View File

@ -35,7 +35,7 @@ module.BaseParser = {
//
MACRO_ARGS: ['(\\s*(',[
// arg='val' | arg="val" | arg=val
'(?<PREFIXArgName>[a-z-]+)\\s*=\\s*(?<PREFIXArgValue>'+([
'(?<PREFIXArgName>[a-z:-]+)\\s*=\\s*(?<PREFIXArgValue>'+([
// XXX CHROME/NODE BUG: this does not work yet...
//'\\s+(?<quote>[\'"])[^\\k<quote>]*\\k<quote>',
'"(?<PREFIXDoubleQuotedValue>(\\"|[^"])*?)"',

View File

@ -276,7 +276,7 @@ module.BaseStore = {
return data },
remove: async function(data, path){
var {tags, paths} = await data
for(var tag of paths[path]){
for(var tag of paths[path] ?? []){
tags[tag].delete(path) }
return data }, }),
get tags(){
@ -609,8 +609,11 @@ module.BaseStore = {
// ...this could be a sign of problems with index -- needs more
// tought...
update: types.event.Event('update',
function(handler, path, data, mode='update'){
return this.__update(...[...arguments].slice(1)) }),
async function(handler, path, data, mode='update'){
handler(false)
var res = await this.__update(...[...arguments].slice(1))
handler()
return res }),
__delete__: async function(path){
delete this.data[path] },
@ -625,8 +628,11 @@ module.BaseStore = {
this.index('remove', path) }
return this },
delete: types.event.Event('delete',
function(handler, path){
return this.__delete(path) }),
async function(handler, path){
handler(false)
var res = await this.__delete(path)
handler()
return res }),
// XXX NEXT might be a good idea to have an API to move pages from
// current store up the chain...

View File

@ -97,7 +97,7 @@ a:hover {
/* Spinner... */
.spinner {
position: absolute;
position: fixed;
display: flex;
text-align: center;
left: 50%;
@ -411,6 +411,7 @@ require(['./browser'], function(browser){
// when the hash is actually changed...
for(var lnk of this.dom.querySelectorAll(`a[href="${location.hash}"]`)){
lnk.addEventListener('click', refresh) } })
.delete(refresh)
// handle special file updates...
// NOTE: the actual updates are done .navigate(..)

View File

@ -18,6 +18,8 @@
* - CLI -
*
*
* XXX macros: add @defmacro(<name> ..) to be exactly as @macro(<name> ..)
* but defines a @<name>(..) macro...
* XXX BUG: parser:
* This will break:
* await pwiki.parse('<macro src=../tags join=", ">@source(.)</macro>')