working on browser...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2022-08-04 14:29:25 +03:00
parent 246392f888
commit 7ce3e6f8bc
20 changed files with 69228 additions and 140 deletions

View File

@ -13,8 +13,14 @@ LOCAL_MODULES := \
node_modules/ig-actions/actions.js \
node_modules/ig-features/features.js
POUCH_DB := \
$(wildcard node_modules/pouchdb/dist/*)
ext-lib/pouchdb.js: node_modules $(POUCH_DB)
cp $(POUCH_DB) ext-lib/
bootstrap.js: scripts/bootstrap.js $(BOOTSTRAP_FILES)
node $<
@ -28,7 +34,7 @@ node_modules:
npm install
dev: node_modules $(LOCAL_MODULES) bootstrap
dev: node_modules ext-lib/pouchdb.js $(LOCAL_MODULES) bootstrap
cp $(LOCAL_MODULES) lib/

View File

@ -11,17 +11,48 @@ var object = require('ig-object')
var types = require('ig-types')
var pwpath = require('./lib/path')
var page = require('./page')
var basestore = require('./store/base')
var localstoragestore = require('./store/localstorage')
// XXX for some reason this does not run quietly in browser
//var pouchdbstore = require('./store/pouchdb')
var pouchdbstore = require('./store/pouchdb')
// XXX this fails silently in browser...
//var bootstrap = require('./bootstrap')
//---------------------------------------------------------------------
var store =
module.store =
{ __proto__: basestore.BaseStore }
.nest({ __proto__: basestore.MetaStore })
store.update('System',
Object.create(basestore.BaseStore).load(page.System))
var pwiki =
module.pwiki =
page.Page('/', '/', store)
pwiki.store.update('@local', {
__proto__: localstoragestore.localStorageStore,
data: localStorage,
})
pwiki.store.update('@session', {
__proto__: localstoragestore.localStorageStore,
data: sessionStorage,
})
pwiki.store.update('@pouch', {
__proto__: pouchdbstore.PouchDBStore,
})
/**********************************************************************
* vim:set ts=4 sw=4 : */ return module })

1
ext-lib/README Executable file
View File

@ -0,0 +1 @@
This directory contains external modules used for in-browser rendering.

6798
ext-lib/pouchdb.find.js Executable file

File diff suppressed because it is too large Load Diff

8
ext-lib/pouchdb.find.min.js vendored Executable file

File diff suppressed because one or more lines are too long

5152
ext-lib/pouchdb.indexeddb.js Executable file

File diff suppressed because it is too large Load Diff

2
ext-lib/pouchdb.indexeddb.min.js vendored Executable file

File diff suppressed because one or more lines are too long

13146
ext-lib/pouchdb.js Executable file

File diff suppressed because it is too large Load Diff

21765
ext-lib/pouchdb.localstorage.js Executable file

File diff suppressed because it is too large Load Diff

45
ext-lib/pouchdb.localstorage.min.js vendored Executable file

File diff suppressed because one or more lines are too long

22008
ext-lib/pouchdb.memory.js Executable file

File diff suppressed because it is too large Load Diff

45
ext-lib/pouchdb.memory.min.js vendored Executable file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

46
filters/base.js Executable file
View File

@ -0,0 +1,46 @@
/**********************************************************************
*
*
*
**********************************************************************/
((typeof define)[0]=='u'?function(f){module.exports=f(require)}:define)
(function(require){ var module={} // make module AMD/node compatible...
/*********************************************************************/
//---------------------------------------------------------------------
// XXX revise...
var Filter =
module.Filter =
function(...args){
var func = args.pop()
args.length > 0
&& Object.assign(func, args.pop())
return func }
//---------------------------------------------------------------------
var WIKIWORD_PATTERN =
RegExp('('+[
//'\\\\?(\\/|\\./|\\.\\./|>>|[A-Z][_a-z0-9]+[A-Z/])[_a-zA-Z0-9/]*',
'\\\\?\\/?(\\./|\\.\\./|>>|[A-Z][_a-z0-9]+[A-Z/])[_a-zA-Z0-9/]*',
'\\\\?\\[[^\\]]+\\]',
].join('|') +')', 'g')
module.wikiWord =
Filter(
{quote: 'quote-wikiword'},
function(source){
// XXX
return source })
module.quoteWikiWord =
function(source){
// XXX
return source }
/**********************************************************************
* vim:set ts=4 sw=4 : */ return module })

31
filters/markdown.js Executable file
View File

@ -0,0 +1,31 @@
/**********************************************************************
*
*
*
**********************************************************************/
((typeof define)[0]=='u'?function(f){module.exports=f(require)}:define)
(function(require){ var module={} // make module AMD/node compatible...
/*********************************************************************/
var base = require('./base')
//---------------------------------------------------------------------
module.markdown =
base.Filter(
{quote: 'quote-markdown'},
function(source){
// XXX
return source })
module.quoteMarkdown =
function(source){
// XXX
return source }
/**********************************************************************
* vim:set ts=4 sw=4 : */ return module })

115
page.js
View File

@ -14,13 +14,8 @@ var types = require('ig-types')
var pwpath = require('./lib/path')
var parser = require('./parser')
var basestore = require('./store/base')
//var localstoragestore = require('./store/localstorage')
// XXX for some reason this does not run quietly in browser
//var pouchdbstore = require('./store/pouchdb')
//var filestore = require('./store/file')
var filters = require('./filters/base')
var markdown = require('./filters/markdown')
//---------------------------------------------------------------------
@ -46,6 +41,9 @@ function(name){
Object.defineProperty(func, 'name', {value: name})
return func }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
var __HANDLE_NAVIGATE =
module.__HANDLE_NAVIGATE =
types.event.EventCommand('HANDLE_NAVIGATE')
@ -459,17 +457,9 @@ types.event.EventMixin(BasePage.prototype)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// XXX should these be something more generic like Object.assign(..) ???
//---------------------------------------------------------------------
// XXX revise...
var Filter =
module.Filter =
function(...args){
var func = args.pop()
args.length > 0
&& Object.assign(func, args.pop())
return func }
// XXX should these be something more generic like Object.assign(..) ???
// XXX do we need anything else like .doc, attrs???
var Macro =
@ -531,23 +521,11 @@ object.Constructor('Page', BasePage, {
return source
.replace(/test/g, 'TEST') },
wikiword: Filter(
{quote: 'quote-wikiword'},
function(source){
// XXX
return source }),
'quote-wikiword': function(source){
// XXX
return source },
wikiword: filters.wikiWord,
'quote-wikiword': filters.quoteWikiWord,
markdown: Filter(
{quote: 'quote-markdown'},
function(source){
// XXX
return source }),
'quote-markdown': function(source){
// XXX
return source },
markdown: markdown.markdown,
'quote-markdown': markdown.quoteMarkdown,
},
//
@ -1070,14 +1048,73 @@ object.Constructor('Page', BasePage, {
//---------------------------------------------------------------------
// System pages/actions...
var WIKIWORD_PATTERN =
RegExp('('+[
//'\\\\?(\\/|\\./|\\.\\./|>>|[A-Z][_a-z0-9]+[A-Z/])[_a-zA-Z0-9/]*',
'\\\\?\\/?(\\./|\\.\\./|>>|[A-Z][_a-z0-9]+[A-Z/])[_a-zA-Z0-9/]*',
'\\\\?\\[[^\\]]+\\]',
].join('|') +')', 'g')
var System =
module.System = {
// base templates...
//
_text: {
text: '<macro src="." join="\n">@source(.)</macro>' },
NotFound: {
text: module.PAGE_NOT_FOUND
.replace('$PATH', '@source(./path)') },
// XXX tests...
test_list: function(){
return 'abcdef'.split('') },
// metadata...
//
path: function(){
return this.get('..').path },
location: function(){
return this.get('..').path },
dir: function(){
return this.get('..').dir },
name: function(){
return this.get('..').name },
ctime: function(){
return this.get('..').data.ctime },
mtime: function(){
return this.get('..').data.mtime },
// XXX this can be a list for pattern paths...
resolved: function(){
return this.get('..').resolve() },
title: function(){
var p = this.get('..')
return p.title
?? p.name },
// utils...
//
// XXX System/subpaths
// XXX
links: function(){
// XXX
return '' },
// XXX links to pages...
to: function(){
return (this.get('..').data || {}).to ?? [] },
// XXX pages linking to us...
'from': function(){
return (this.get('..').data || {})['from'] ?? [] },
// actions...
//
delete: function(){
this.location = '..'
this.delete()
return this.text },
// XXX System/back
// XXX System/forward
// XXX System/sort
// XXX System/reverse
}

View File

@ -27,6 +27,8 @@
<style>
</style>
<script src="ext-lib/pouchdb.js"></script>
<!--script data-main="pwiki2" src="ext-lib/require.js"></script-->
<script src="ext-lib/require.js"></script>
<script>
@ -46,7 +48,9 @@ require.config({
})
var setup = function(){
require(['./browser'], function(){ })
require(['./browser'], function(m){
window.pwiki = m.pwiki
})
}
</script>

121
pwiki2.js
View File

@ -1,22 +1,52 @@
/**********************************************************************
*
*
* XXX ROADMAP:
* - run in browser
* - basics, loading -- DONE
* - test localStorage / sessionStorage -- DONE
* - test pouch -- DONE
* - render page
* - navigation
* - hash/anchor
* - service worker
* - migrate bootstrap
* - test pwa
* - archive old code
* - update docs
* - refactor and cleanup
* - pack as electron app (???)
*
*
*
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*
* Architecture:
* store
* page
* renderer
*
* Modules:
* page - base pages and page APIs (XXX should this be in lib???)
* parser - pWiki macro parser (XXX should this be in lib???)
* store - stores
* base - memory store and store utils
* file - file storage
* localstorage - localStorage / sessionStorage stores
* pouchdb -
* ...
* filter - page filters
* base - base filters incl. wikiword
* markdown - markdown renderer
* ...
* pwiki2 - main cli / node entry point
* browser - browser entry point
* pwiki2-test - testing and experimenting (XXX move to test.js)
*
* XXX ROADMAP:
* - run in browser
* - test localStorage / sessionStorage
* - test pouch
* - move the bootstrap over
* - test pwa
* - archive old code
* - update docs
* - refactor and cleanup
* - pack as electron app (???)
*
* Q: can we make this a single module with +/- some plugins??
* ...this would make things quite a bit simpler but will negate the
* use of high level libs like types...
*
*
* XXX weaknesses to review:
@ -26,8 +56,6 @@
* ...need to be independent of the number of pages if at
* all possible -- otherwise this will hinder long-term use...
* -
*
*
* TODO:
* - <page>.then() -- resolve when all pending write operations done ???
* - an async REPL???
@ -114,80 +142,13 @@ module.store =
.nest({ __proto__: basestore.MetaStore })
var System =
module.System = {
// base templates...
//
_text: {
text: '<macro src="." join="\n">@source(.)</macro>' },
NotFound: {
text: page.PAGE_NOT_FOUND
.replace('$PATH', '@source(./path)') },
// XXX tests...
test_list: function(){
return 'abcdef'.split('') },
// metadata...
//
path: function(){
return this.get('..').path },
location: function(){
return this.get('..').path },
dir: function(){
return this.get('..').dir },
name: function(){
return this.get('..').name },
ctime: function(){
return this.get('..').data.ctime },
mtime: function(){
return this.get('..').data.mtime },
// XXX this can be a list for pattern paths...
resolved: function(){
return this.get('..').resolve() },
title: function(){
var p = this.get('..')
return p.title
?? p.name },
// utils...
//
// XXX System/subpaths
// XXX
links: function(){
// XXX
return '' },
// XXX links to pages...
to: function(){
return (this.get('..').data || {}).to ?? [] },
// XXX pages linking to us...
'from': function(){
return (this.get('..').data || {})['from'] ?? [] },
// actions...
//
delete: function(){
this.location = '..'
this.delete()
return this.text },
// XXX System/back
// XXX System/forward
// XXX System/sort
// XXX System/reverse
}
// XXX note sure how to organize the system actions -- there can be two
// options:
// - a root ram store with all the static stuff and nest the rest
// - a nested store (as is the case here)
// XXX nested system store...
store.update('System',
Object.create(basestore.BaseStore).load(System))
Object.create(basestore.BaseStore).load(page.System))
// NOTE: in general the root wiki api is simply a page instance.

View File

@ -50,11 +50,18 @@ module.localStorageStore = {
JSON.stringify(data) },
__delete__: function(path){
delete this.data[(this.__prefix__ ?? '')+ path] },
clear: function(){
for(var e in this.data){
if(e.startsWith(this.__prefix__)){
delete this.data[e] } }
return this },
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// XXX
var localStorageNestedStore =
module.localStorageNestedStore = {
__proto__: base.BaseStore,

View File

@ -11,15 +11,18 @@ var object = require('ig-object')
var types = require('ig-types')
var pwpath = require('../lib/path')
var base = require('../store/base')
// XXX HACK: trick requirejs to delay module loading...
var req = require
module.PouchDB =
typeof(PouchDB) != 'undefined' ?
PouchDB
: req('pouchdb')
//---------------------------------------------------------------------
// XXX
module.PouchDB = undefined
var PouchDBStore =
module.PouchDBStore = {
__proto__: base.BaseStore,
@ -31,12 +34,8 @@ module.PouchDBStore = {
__data: undefined,
get data(){
if(!this.__data){
var PouchDB =
module.PouchDB =
require('pouchdb')
return (this.__data = new PouchDB(this.__path__)) }
return this.__data },
return this.__data
?? (this.__data = new module.PouchDB(this.__path__)) },
set data(value){
this.__data = value },