added .title (encoded .name) + fixed @source(..) + refactoring, tweaks and fixes...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2022-09-22 02:52:14 +03:00
parent ee2a2c21b4
commit 3e39ff8228
3 changed files with 61 additions and 23 deletions

View File

@ -226,16 +226,20 @@ object.Constructor('BasePage', {
to to
: '../'+to) }, : '../'+to) },
/*/ XXX TITLE... /*/ XXX TITLE / EXPERIMENTAL...
// NOTE: .__title is intentionally not persistent... // NOTE: .__title is intentionally not persistent...
__title: undefined, __title: undefined,
get title(){ get title(){
return this.__title return this.__title
?? this.path }, ?? this.name },
set title(value){ set title(value){
this.__title = value this.__title = value
this.__update__({title: value}) }, this.__update__({title: value}) },
//*/ //*/
get title(){
return pwpath.decodeElem(this.name) },
set title(value){
this.name = pwpath.encodeElem(value) },
get isPattern(){ get isPattern(){
return this.path.includes('*') }, return this.path.includes('*') },
@ -316,10 +320,10 @@ object.Constructor('BasePage', {
// single page... // single page...
// XXX ENERGETIC... // XXX ENERGETIC...
var res = await this.store.get(this.path, !!this.strict, !!await this.energetic) var res = await this.store.get(this.path, !!this.strict, !!await this.energetic)
/*/ XXX TITLE... /*/ XXX TITLE / EXPERIMENTAL...
// load the title if set... // load the title if set...
res.title res.title
?? (this.__title = res.title) && (this.__title = res.title)
//*/ //*/
return typeof(res) == 'function' ? return typeof(res) == 'function' ?
res.bind(this) res.bind(this)
@ -979,17 +983,21 @@ object.Constructor('Page', BasePage, {
// this renders the src in the context of current page while // this renders the src in the context of current page while
// include is rendered in the context of its page but with // include is rendered in the context of its page but with
// the same state... // the same state...
// i.e. for @include(PATH) the paths within the included page
// are resolved relative to PATH while for @source(PATH)
// relative to the page containing the @source(..) statement...
source: Macro( source: Macro(
// XXX should this have the same args as include??? // XXX should this have the same args as include???
['src', 'recursive', 'join', ['src', 'recursive', 'join',
['strict', 'nonstrict', 'isolated']], ['strict', 'nonstrict', 'isolated']],
//['src'], //['src'],
async function*(args, body, state){ async function*(args, body, state){
var that = this
yield* this.macros.include.call(this, yield* this.macros.include.call(this,
'source', 'source',
args, body, state, 'sources', args, body, state, 'sources',
async function(src, state){ async function(src, state){
return this.parse(this.get(src).raw, state) }) }), return that.parse(that.get(src).raw, state) }) }),
// //
// @quote(<src>) // @quote(<src>)
// //
@ -1485,8 +1493,10 @@ object.Constructor('Page', BasePage, {
// handle lists in pages (actions, ... etc.)... // handle lists in pages (actions, ... etc.)...
} else { } else {
var data = await page.data var data = await page.data
data = typeof(data) == 'function' ? data =
data typeof(data) == 'function' ?
//data
await data()
: 'text' in data ? : 'text' in data ?
data.text data.text
: null : null
@ -1496,6 +1506,9 @@ object.Constructor('Page', BasePage, {
.map(function(p){ .map(function(p){
return page.virtual({text: p}) }) return page.virtual({text: p}) })
return } return }
// do not iterate pages/actions that are undefined...
if(data == null){
return }
yield page } }, yield page } },
@ -1826,7 +1839,8 @@ module.System = {
text: object.doc` text: object.doc`
<slot name="header"> <slot name="header">
<a href="#/list">&#9776</a> <a href="#/list">&#9776</a>
@source(./location/!) <a href="#<slot name=parent>../</slot>">&#x21D1;</a>
[<slot name="location">@source(./location/!)</slot>]
<a href="javascript:refresh()">&#10227;</a> <a href="javascript:refresh()">&#10227;</a>
<a href="#@source(./path/!)/edit">&#9998;</a> <a href="#@source(./path/!)/edit">&#9998;</a>
</slot> </slot>
@ -1837,6 +1851,7 @@ module.System = {
<!-- fill slots defaults --> <!-- fill slots defaults -->
<slot name="content" hidden> <slot name="content" hidden>
<slot name=title><h1>@source(./title)</h1></slot>
@include(.:$ARGS join="@source(file-separator)" recursive="") @include(.:$ARGS join="@source(file-separator)" recursive="")
</slot>` }, </slot>` },
// XXX add join... // XXX add join...
@ -1885,15 +1900,17 @@ module.System = {
+'</macro>'}, +'</macro>'},
//*/ //*/
edit: { edit: {
// XXX not sure if we should use .title or .name here...
text: object.doc` text: object.doc`
@include(_view) <slot name="parent">../..</slot>
<slot name="header">@source(../path)</slot> <slot name="location">@source(../location/!)</slot>
<slot name="content"> <slot name="content">
<macro src=".." join="@source(file-separator)"> <macro src=".." join="@source(file-separator)">
<h1 class="title-editor" <h1 class="title-editor"
contenteditable contenteditable
oninput="saveContent(\'@source(./path)/name\', this.innerText)"> oninput="saveContent(\'@source(./path)/title\', this.innerText)">
@source(./name) @source(./title)
</h1> </h1>
<pre class="editor" <pre class="editor"
wikiwords="no" wikiwords="no"
@ -1932,6 +1949,7 @@ module.System = {
// XXX this is really slow... // XXX this is really slow...
tree: { tree: {
text: object.doc` text: object.doc`
<slot name=title></slot>
<macro src="../*:@(all)"> <macro src="../*:@(all)">
<div> <div>
<div class="item"> <div class="item">
@ -1940,7 +1958,7 @@ module.System = {
<a class="show-on-hover" href="#@source(./path)/delete">&times;</a> <a class="show-on-hover" href="#@source(./path)/delete">&times;</a>
</div> </div>
<div style="padding-left: 30px"> <div style="padding-left: 30px">
@source("./tree:@(all)") @include("./tree:@(all)")
</div> </div>
</div> </div>
</macro>` }, </macro>` },
@ -1997,6 +2015,20 @@ module.System = {
QuoteActionPage: { QuoteActionPage: {
text: '[ native code ]' }, text: '[ native code ]' },
// XXX should this be in templates???
// XXX for some reason this does not list files...
FlatNotes: {
text: object.doc`
<slot name=title></slot>
<slot name="header"><content/><a href="#./$NOW/edit">&#128462;</a></slot>
<macro src="*:@(all)" join="<br>">
<div class="item">
<a href="#@source(./path)/edit">@source(./title)</a>
<a class="show-on-hover" href="#@source(./path)/info">&#128712;</a>
<a class="show-on-hover" href="#@source(./path)/delete">&times;</a>
</div>
</macro>` },
// page actions... // page actions...
// //

View File

@ -56,6 +56,11 @@ module = {
.replace(/[#:*%]/g, encodeURIComponent) }, .replace(/[#:*%]/g, encodeURIComponent) },
decode: function(str){ decode: function(str){
return decodeURIComponent(str) }, return decodeURIComponent(str) },
encodeElem: function(str){
return str
.replace(/[#:*%\\\/.]/g, encodeURIComponent) },
decodeElem: function(str){
return decodeURIComponent(str) },
/*/ XXX NORMCACHE... /*/ XXX NORMCACHE...
__normalized_cache_threshold: 100, __normalized_cache_threshold: 100,
@ -106,14 +111,18 @@ module = {
if(res.length == 0 if(res.length == 0
&& e == '..'){ && e == '..'){
return [e] } return [e] }
;(e == '.' // multiple leading '..'...
;(e == '..'
&& res.at(-1) == '..' ?
res.push(e)
: e == '.'
// keep explicit '/' only at start/end of path... // keep explicit '/' only at start/end of path...
|| (e == '' || (e == ''
&& i != 0 && i != 0
&& i != L.length-1)) ? && i != L.length-1)) ?
undefined undefined
: e == '..' : e == '..'
|| res[res.length-1] == '>>' ? || res.at(-1) == '>>' ?
((res.length > 1 ((res.length > 1
|| res[0] != '') || res[0] != '')
&& res.pop()) && res.pop())
@ -158,10 +167,12 @@ module = {
: 'string') : 'string')
: format : format
path = this.split(path) path = this.split(path)
;(path[0] == '' // leading: '/', '.' and '..'...
while(path[0] == ''
|| path[0] == '.' || path[0] == '.'
|| path[0] == '..') || path[0] == '..'){
&& path.shift() path.shift() }
//trailing '/'
path.at(-1) == '' path.at(-1) == ''
&& path.pop() && path.pop()
return format == 'string' ? return format == 'string' ?

View File

@ -6,11 +6,6 @@
* - fs store/export in browser or a simple way to export/import... * - fs store/export in browser or a simple way to export/import...
* *
* *
* XXX need page names to contain odd characters when created by user, for
* example: note titles...
* ...and need this to work through all the i/o...
* ....this might be an argument towards the .title attr, at least
* for notes...
* XXX macros: should we add the pattern path to .depends instead of the * XXX macros: should we add the pattern path to .depends instead of the
* final path... * final path...
* ...would also need a fast way to pattern match... * ...would also need a fast way to pattern match...