mirror of
https://github.com/flynx/pWiki.git
synced 2025-11-01 11:30:08 +00:00
now @quote(..) handles actions without triggering them by deafult + fixes and notes...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
b638f85732
commit
d13cdef574
117
pwiki/page.js
117
pwiki/page.js
@ -192,6 +192,13 @@ object.Constructor('BasePage', {
|
|||||||
set metadata(value){
|
set metadata(value){
|
||||||
this.__update__(value) },
|
this.__update__(value) },
|
||||||
|
|
||||||
|
get type(){ return async function(){
|
||||||
|
return this.store.isStore(this.path) ?
|
||||||
|
'store'
|
||||||
|
: typeof(await this.data) == 'function' ?
|
||||||
|
'action'
|
||||||
|
: 'page' }.bind(this)() },
|
||||||
|
|
||||||
// number of matching pages...
|
// number of matching pages...
|
||||||
// NOTE: this can be both sync and async...
|
// NOTE: this can be both sync and async...
|
||||||
get length(){
|
get length(){
|
||||||
@ -521,6 +528,8 @@ object.Constructor('Page', BasePage, {
|
|||||||
|
|
||||||
NOT_FOUND_TEMPLATE_ERROR: 'NotFoundTemplateError',
|
NOT_FOUND_TEMPLATE_ERROR: 'NotFoundTemplateError',
|
||||||
|
|
||||||
|
QUOTE_ACTION_PAGE: 'QuoteActionPage',
|
||||||
|
|
||||||
// XXX DEPENDS to be used for cache invalidation...
|
// XXX DEPENDS to be used for cache invalidation...
|
||||||
// Format:
|
// Format:
|
||||||
// {
|
// {
|
||||||
@ -793,7 +802,7 @@ object.Constructor('Page', BasePage, {
|
|||||||
//
|
//
|
||||||
// XXX need a way to escape macros -- i.e. include </quote> in a quoted text...
|
// XXX need a way to escape macros -- i.e. include </quote> in a quoted text...
|
||||||
quote: Macro(
|
quote: Macro(
|
||||||
['src', 'filter', 'text', 'join'],
|
['src', 'filter', 'text', 'join', ['expandactions']],
|
||||||
async function*(args, body, state){
|
async function*(args, body, state){
|
||||||
var src = args.src //|| args[0]
|
var src = args.src //|| args[0]
|
||||||
var base = this.get(this.path.split(/\*/).shift())
|
var base = this.get(this.path.split(/\*/).shift())
|
||||||
@ -804,6 +813,7 @@ object.Constructor('Page', BasePage, {
|
|||||||
src = src ?
|
src = src ?
|
||||||
await base.parse(src, state)
|
await base.parse(src, state)
|
||||||
: src
|
: src
|
||||||
|
var expandactions = args.expandactions
|
||||||
|
|
||||||
// XXX DEPENDS
|
// XXX DEPENDS
|
||||||
var depends = state.depends =
|
var depends = state.depends =
|
||||||
@ -811,7 +821,10 @@ object.Constructor('Page', BasePage, {
|
|||||||
?? new Set()
|
?? new Set()
|
||||||
|
|
||||||
var pages = src ?
|
var pages = src ?
|
||||||
this.get(src).asPages()
|
(!expandactions
|
||||||
|
&& await this.get(src).type == 'action' ?
|
||||||
|
base.get(this.QUOTE_ACTION_PAGE)
|
||||||
|
: this.get(src).asPages())
|
||||||
: text instanceof Array ?
|
: text instanceof Array ?
|
||||||
[text.join('')]
|
[text.join('')]
|
||||||
: typeof(text) == 'string' ?
|
: typeof(text) == 'string' ?
|
||||||
@ -830,8 +843,13 @@ object.Constructor('Page', BasePage, {
|
|||||||
first = false
|
first = false
|
||||||
|
|
||||||
text = typeof(page) == 'string' ?
|
text = typeof(page) == 'string' ?
|
||||||
page
|
page
|
||||||
|
: (!expandactions
|
||||||
|
&& await page.type == 'action') ?
|
||||||
|
base.get(this.QUOTE_ACTION_PAGE).raw
|
||||||
: await page.raw
|
: await page.raw
|
||||||
|
|
||||||
|
|
||||||
// XXX DEPENDS...
|
// XXX DEPENDS...
|
||||||
page.path
|
page.path
|
||||||
&& depends.add(page.path)
|
&& depends.add(page.path)
|
||||||
@ -1157,15 +1175,39 @@ object.Constructor('Page', BasePage, {
|
|||||||
|
|
||||||
// iterate matches or content list as pages...
|
// iterate matches or content list as pages...
|
||||||
//
|
//
|
||||||
|
// .asPages()
|
||||||
|
// .asPages(<path>[, <options>])
|
||||||
|
// .asPages(<strict>[, <options>])
|
||||||
|
// .asPages(<path>, <strict>[, <options>])
|
||||||
|
// .asPages(<options>)
|
||||||
|
// -> <iter>
|
||||||
|
//
|
||||||
|
// NOTE: this will get .raw for non-pattern pages this it can trigger
|
||||||
|
// actions...
|
||||||
|
//
|
||||||
// XXX revise name...
|
// XXX revise name...
|
||||||
asPages: async function*(path='.', strict=false){
|
asPages: async function*(path='.', strict=false, noexpandactions=false){
|
||||||
if(path === true
|
// options...
|
||||||
|| path === false){
|
var args = [...arguments]
|
||||||
strict = path
|
var opts = typeof(args.at(-1)) == 'object' ?
|
||||||
path = '.' }
|
args.pop()
|
||||||
|
: {}
|
||||||
|
var {path, strict, noexpandactions} = {
|
||||||
|
...opts,
|
||||||
|
path: typeof(args[0]) == 'string' ?
|
||||||
|
args.shift()
|
||||||
|
: '.',
|
||||||
|
strict: args.shift() ?? false,
|
||||||
|
}
|
||||||
|
|
||||||
var page = this.get(path, strict)
|
var page = this.get(path, strict)
|
||||||
// handle lists in pages (actions, ... etc.)...
|
// handle lists in pages (actions, ... etc.)...
|
||||||
if(!page.isPattern){
|
if(!page.isPattern){
|
||||||
|
if(noexpandactions
|
||||||
|
&& await page.type == 'action'){
|
||||||
|
//yield this.get(this.QUOTE_ACTION_PAGE)
|
||||||
|
yield page
|
||||||
|
return }
|
||||||
var raw = await page.raw
|
var raw = await page.raw
|
||||||
if(raw == null){
|
if(raw == null){
|
||||||
return }
|
return }
|
||||||
@ -1417,18 +1459,27 @@ module.System = {
|
|||||||
@source(../path)
|
@source(../path)
|
||||||
</slot>
|
</slot>
|
||||||
<macro src="../*" join="@source(line-separator)">
|
<macro src="../*" join="@source(line-separator)">
|
||||||
<a href="#@source(./path)/list">↳</a>
|
<a href="#@source(./path)/list">@source(./name)</a>
|
||||||
<a href="#@source(./path)">@source(./name)</a>
|
<i>
|
||||||
|
<macro src="./isAction">
|
||||||
|
a
|
||||||
|
<else>
|
||||||
|
<macro src="./isStore">s</macro>
|
||||||
|
</else>
|
||||||
|
</macro>
|
||||||
|
</i>
|
||||||
<a href="#@source(./path)/delete">×</a>
|
<a href="#@source(./path)/delete">×</a>
|
||||||
</macro>` },
|
</macro>` },
|
||||||
// XXX this is really slow...
|
// XXX this is really slow...
|
||||||
tree: {
|
tree: {
|
||||||
text: object.doc`
|
text: object.doc`
|
||||||
<macro src="../*">
|
<macro src="../*">
|
||||||
<div>
|
<div class="item">
|
||||||
<a href="#@source(./path)">@source(./name)</a>
|
<a href="#@source(./path)">@source(./name)</a>
|
||||||
<macro src="./isAction">*</macro>
|
<span class="show-on-hover">
|
||||||
<a href="#@source(./path)/delete">×</a>
|
<a href="#@source(./path)/info">🛈</a>
|
||||||
|
<a href="#@source(./path)/delete">×</a>
|
||||||
|
</span>
|
||||||
<div style="padding-left: 30px">
|
<div style="padding-left: 30px">
|
||||||
@source(./tree)
|
@source(./tree)
|
||||||
</div>
|
</div>
|
||||||
@ -1438,12 +1489,20 @@ module.System = {
|
|||||||
text: `@include(../**/path join="@source(line-separator)")`},
|
text: `@include(../**/path join="@source(line-separator)")`},
|
||||||
info: {
|
info: {
|
||||||
text: object.doc`
|
text: object.doc`
|
||||||
Path: @source(../path)<br>
|
Path: @source(../path)
|
||||||
Resolved path: @source(../resolved)<br>
|
(<a href="#@source(../path)/edit">edit</a>)<br>
|
||||||
Referrer: @source(../referrer)<br>
|
Resolved path: @source(../resolved)
|
||||||
Renderer: @source(../renderer)<br>
|
(<a href="#@source(../resolved)/edit">edit</a>)<br>
|
||||||
|
Referrer: @source(../referrer)
|
||||||
|
(<a href="#@source(../referrer)/edit">edit</a>)<br>
|
||||||
|
Renderer: @source(../renderer)
|
||||||
|
(<a href="#@source(../renderer)/edit">edit</a>)<br>
|
||||||
|
|
||||||
|
type: @source(../type)<br>
|
||||||
|
|
||||||
ctime: @source(../ctime)<br>
|
ctime: @source(../ctime)<br>
|
||||||
mtime: @source(../mtime)<br>
|
mtime: @source(../mtime)<br>
|
||||||
|
|
||||||
<hr>
|
<hr>
|
||||||
<pre wikiwords="no"><quote filter="quote-tags" src=".."/></pre> ` },
|
<pre wikiwords="no"><quote filter="quote-tags" src=".."/></pre> ` },
|
||||||
|
|
||||||
@ -1472,6 +1531,8 @@ module.System = {
|
|||||||
<slot name="content"></slot>
|
<slot name="content"></slot>
|
||||||
<hr>
|
<hr>
|
||||||
<slot name="footer"></slot> ` },
|
<slot name="footer"></slot> ` },
|
||||||
|
QuoteActionPage: {
|
||||||
|
text: '[ native code ]' },
|
||||||
|
|
||||||
|
|
||||||
// page actions...
|
// page actions...
|
||||||
@ -1498,19 +1559,20 @@ module.System = {
|
|||||||
return p.title
|
return p.title
|
||||||
?? p.name },
|
?? p.name },
|
||||||
ctime: async function(){
|
ctime: async function(){
|
||||||
return (await this.get('..').data).ctime ?? '' },
|
return (await this.get('..').data).ctime },
|
||||||
mtime: async function(){
|
mtime: async function(){
|
||||||
return (await this.get('..').data).mtime ?? '' },
|
return (await this.get('..').data).mtime },
|
||||||
|
|
||||||
// XXX EXPERIMENTAL...
|
// XXX EXPERIMENTAL...
|
||||||
type: async function(){
|
type: async function(){
|
||||||
// XXX also check if a page is a store...
|
return await this.get('..').type },
|
||||||
return typeof(await this.get('..').data) == 'function' ?
|
|
||||||
'action'
|
|
||||||
: 'page' },
|
|
||||||
isAction: async function(){
|
isAction: async function(){
|
||||||
return typeof(await this.get('..').data) == 'function' ?
|
return await this.get('..').type == 'action' ?
|
||||||
['action']
|
'action'
|
||||||
|
: undefined },
|
||||||
|
isStore: async function(){
|
||||||
|
return await this.get('..').type == 'store' ?
|
||||||
|
'store'
|
||||||
: undefined },
|
: undefined },
|
||||||
|
|
||||||
|
|
||||||
@ -1534,6 +1596,8 @@ module.System = {
|
|||||||
delete: function(){
|
delete: function(){
|
||||||
var target = this.get('..')
|
var target = this.get('..')
|
||||||
|
|
||||||
|
console.log('DELETE:', target.path)
|
||||||
|
|
||||||
target.delete()
|
target.delete()
|
||||||
|
|
||||||
// redirect...
|
// redirect...
|
||||||
@ -1542,7 +1606,7 @@ module.System = {
|
|||||||
// show info about the delete operation...
|
// show info about the delete operation...
|
||||||
return target.get('DeletingPage').text },
|
return target.get('DeletingPage').text },
|
||||||
|
|
||||||
// XXX EXPERIMENTAL
|
/*/ XXX EXPERIMENTAL
|
||||||
// move page one level up...
|
// move page one level up...
|
||||||
moveUp: function(){
|
moveUp: function(){
|
||||||
var target = this.get('..')
|
var target = this.get('..')
|
||||||
@ -1587,6 +1651,7 @@ module.System = {
|
|||||||
this.render_root
|
this.render_root
|
||||||
&& (this.render_root.location = to)
|
&& (this.render_root.location = to)
|
||||||
return '' },
|
return '' },
|
||||||
|
//*/
|
||||||
|
|
||||||
//
|
//
|
||||||
test_path: function(){
|
test_path: function(){
|
||||||
|
|||||||
@ -457,12 +457,14 @@ module.MetaStore = {
|
|||||||
return object.childOf(value, BaseStore) })
|
return object.childOf(value, BaseStore) })
|
||||||
.map(function([path, _]){
|
.map(function([path, _]){
|
||||||
return path })) },
|
return path })) },
|
||||||
|
// XXX do we need to account for trailing '/' here???
|
||||||
substore: function(path){
|
substore: function(path){
|
||||||
path = pwpath.normalize(path, 'string')
|
path = pwpath.normalize(path, 'string')
|
||||||
if(this.substores.includes(path)){
|
if(this.substores.includes(path)){
|
||||||
return path }
|
return path }
|
||||||
var root = path[0] == '/'
|
var root = path[0] == '/'
|
||||||
var store = this.substores
|
var store = this.substores
|
||||||
|
// normalize store paths to the given path...
|
||||||
.filter(function(p){
|
.filter(function(p){
|
||||||
return path.startsWith(
|
return path.startsWith(
|
||||||
root ?
|
root ?
|
||||||
@ -477,6 +479,14 @@ module.MetaStore = {
|
|||||||
: store },
|
: store },
|
||||||
getstore: function(path){
|
getstore: function(path){
|
||||||
return this.data[this.substore(path)] },
|
return this.data[this.substore(path)] },
|
||||||
|
// XXX do we need to account for trailing '/' here???
|
||||||
|
isStore: function(path){
|
||||||
|
path = pwpath.normalize(path, 'string')
|
||||||
|
path = path[0] == '/' ?
|
||||||
|
path.slice(1)
|
||||||
|
: path
|
||||||
|
return this.substores.includes(path)
|
||||||
|
|| this.substores.includes('/'+ path) },
|
||||||
|
|
||||||
// XXX this depends on .data having keys...
|
// XXX this depends on .data having keys...
|
||||||
__paths__: async function(){
|
__paths__: async function(){
|
||||||
|
|||||||
11
pwiki2.html
11
pwiki2.html
@ -25,6 +25,17 @@
|
|||||||
</head>
|
</head>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
|
||||||
|
.show-on-hover {
|
||||||
|
opacity: 0;
|
||||||
|
}
|
||||||
|
:hover>.show-on-hover {
|
||||||
|
opacity: 0.4;
|
||||||
|
}
|
||||||
|
.show-on-hover:hover {
|
||||||
|
opacity: 0.8;
|
||||||
|
}
|
||||||
|
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<!-- XXX do we need this??? -->
|
<!-- XXX do we need this??? -->
|
||||||
|
|||||||
@ -1,8 +1,8 @@
|
|||||||
/**********************************************************************
|
/**********************************************************************
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* XXX need a uniform way to track state in pwiki for things like paging
|
* XXX need a uniform way to track some state in links in pwiki for things
|
||||||
* and the like with simple user/macro access...
|
* like paging and the like with simple user/macro access (???)...
|
||||||
* ...the simplest that comes to mind is to store in in path
|
* ...the simplest that comes to mind is to store in in path
|
||||||
* somehow:
|
* somehow:
|
||||||
* - <path>?<arg>=<value>&...
|
* - <path>?<arg>=<value>&...
|
||||||
@ -10,12 +10,12 @@
|
|||||||
* - <path>/<arg>:<valu>/<arg>:<value>/.../<action>
|
* - <path>/<arg>:<valu>/<arg>:<value>/.../<action>
|
||||||
* stack-style arguments...
|
* stack-style arguments...
|
||||||
* + simple to implement
|
* + simple to implement
|
||||||
* - goes thrugh page search???
|
* - goes through page search???
|
||||||
* - <path>:<value>:<name>=<value>:...
|
* - <path>:<value>:<name>=<value>:...
|
||||||
* - ...
|
* - ...
|
||||||
* the general idea is to be:
|
* the general idea is to be:
|
||||||
* - flexible enough to allow the basics done
|
* - flexible enough to allow the basics done
|
||||||
* - restrictive enough to prevent missuse
|
* - restrictive enough to prevent misuse
|
||||||
* ...the rest of the state can simply be stored in the root pwiki
|
* ...the rest of the state can simply be stored in the root pwiki
|
||||||
* object in one of the following ways:
|
* object in one of the following ways:
|
||||||
* - directly (attrs/dict)
|
* - directly (attrs/dict)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user