1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-05 09:36:18 +00:00

Cleanup and clarify

This commit is contained in:
jeremy@jermolene.com 2023-06-23 16:58:46 +01:00
parent 831fb3996d
commit 8690936805
6 changed files with 55 additions and 42 deletions

View File

@ -1,17 +1,20 @@
/*\
title: $:/plugins/tiddlywiki/sqlite3store/rawmarkup-bottombody.js
type: text/plain
title: $:/plugins/tiddlywiki/sqlite3store/init-sqlite3.js
type: application/javascript
Startup code injected as raw markup at the bottom of the body section
Initialise sqlite3 and then boot TiddlyWiki
This file is spliced into the HTML file to be executed after the boot kernel has been loaded.
\*/
(function() {
// Get the main tiddler store
var storeEl = document.querySelector("script.tiddlywiki-tiddler-store");
var tiddlerStore = JSON.parse(storeEl.textContent);
// Get the main tiddler store out of the HTML file
var storeEl = document.querySelector("script.tiddlywiki-tiddler-store"),
tiddlerStore = JSON.parse(storeEl.textContent);
// Helper to get a tiddler from the store by title
function getTiddler(title) {
for(var t=0; t<tiddlerStore.length; t++) {
var tiddler = tiddlerStore[t];
@ -21,21 +24,16 @@ function getTiddler(title) {
}
return undefined;
}
var thisPlugin = getTiddler("$:/plugins/tiddlywiki/sqlite3store");
var thisPluginTiddlers = JSON.parse(thisPlugin.text).tiddlers;
// Get the shadow tiddlers of this plugin
var thisPlugin = getTiddler("$:/plugins/tiddlywiki/sqlite3store"),
thisPluginTiddlers = JSON.parse(thisPlugin.text).tiddlers;
// Execute the sqlite3 module
var sqlite3js = thisPluginTiddlers["$:/plugins/tiddlywiki/sqlite3store/sqlite3.js"].text;
var context = {
exports: {}
};
var sqlite3js = thisPluginTiddlers["$:/plugins/tiddlywiki/sqlite3store/sqlite3.js"].text,
context = {
exports: {}
};
$tw.utils.evalSandboxed(sqlite3js,context,"$:/plugins/tiddlywiki/sqlite3store/sqlite3.js",true);
// Create a Blob URL for our wasm data
// Create a Blob URL for the wasm data
var sqlite3wasm = thisPluginTiddlers["$:/plugins/tiddlywiki/sqlite3store/sqlite3.wasm"].text;
var decodedData = window.atob(sqlite3wasm),
uInt8Array = new Uint8Array(decodedData.length);
@ -43,11 +41,9 @@ for (var i = 0; i < decodedData.length; ++i) {
uInt8Array[i] = decodedData.charCodeAt(i);
}
var blobUrl = URL.createObjectURL(new Blob([uInt8Array],{type: "application/wasm"}));
// Pass sqlite an URLSearchParams object containing the Blob URL of our wasm data
self.sqlite3InitModuleState.urlParams = new URLSearchParams();
self.sqlite3InitModuleState.urlParams.set("sqlite3.wasm",blobUrl);
// Initialise sqlite
self.sqlite3InitModule().then((sqlite3)=>{
// Save a reference to the sqlite3 object
@ -61,4 +57,4 @@ self.sqlite3InitModule().then((sqlite3)=>{
});
})();
//# sourceURL=$:/plugins/tiddlywiki/sqlite3store/rawmarkup-bottombody.js
//# sourceURL=$:/plugins/tiddlywiki/sqlite3store/init-sqlite3.js

View File

@ -2,5 +2,5 @@ title: $:/plugins/tiddlywiki/sqlite3store/rawmarkup/bottombody
tags: $:/tags/RawMarkupWikified/BottomBody
`<script>`
{{$:/plugins/tiddlywiki/sqlite3store/rawmarkup-bottombody.js}}
{{$:/plugins/tiddlywiki/sqlite3store/init-sqlite3.js}}
`</script>`

View File

@ -0,0 +1,7 @@
title: $:/plugins/tiddlywiki/sqlite3store/rawmarkup-bottomhead
tags: $:/tags/RawMarkupWikified
`<script>`
{{$:/plugins/tiddlywiki/sqlite3store/suppress-boot.js}}
{{$:/plugins/tiddlywiki/sqlite3store/sql-wiki-store.js}}
`</script>`

View File

@ -1,6 +0,0 @@
title: $:/plugins/tiddlywiki/sqlite3store/rawmarkup
tags: $:/tags/RawMarkupWikified
`<script>`
{{$:/plugins/tiddlywiki/sqlite3store/rawmarkup.js}}
`</script>`

View File

@ -1,22 +1,15 @@
/*\
title: $:/plugins/tiddlywiki/sqlite3store/rawmarkup.js
type: text/plain
title: $:/plugins/tiddlywiki/sqlite3store/sql-wiki-store.js
type: application/javascript
Startup code injected as raw markup
A sqlite3 implementation of a wiki store object
This file is spliced into the HTML file to be executed before the boot kernel has been loaded.
\*/
(function() {
// Initialse skeleton TiddlyWiki global because we run before bootprefix.js and boot.js
window.$tw = window.$tw || Object.create(null);
$tw.hooks = $tw.hooks || { names: {}};
$tw.boot = $tw.boot || {};
$tw.boot.preloadDirty = $tw.boot.preloadDirty || [];
// Tell TiddlyWiki not to boot itself
$tw.boot.suppressBoot = true;
$tw.Wiki = function(options) {
// Create a test database and store and retrieve some data
var db = new $tw.sqlite3.oo1.DB("/tiddlywiki.sqlite3","ct");
@ -480,4 +473,4 @@ $tw.Wiki = function(options) {
};
})();
//# sourceURL=$:/plugins/tiddlywiki/sqlite3store/rawmarkup.js
//# sourceURL=$:/plugins/tiddlywiki/sqlite3store/sql-wiki-store.js

View File

@ -0,0 +1,23 @@
/*\
title: $:/plugins/tiddlywiki/sqlite3store/suppress-boot.js
type: application/javascript
Suppress the usual synchronous startup process so that it can instead be done within the callback from sqlite3 initialisation.
This file is spliced into the HTML file to be executed before the boot kernel has been loaded.
\*/
(function() {
// Initialse skeleton TiddlyWiki global because we run before bootprefix.js and boot.js
window.$tw = window.$tw || Object.create(null);
$tw.hooks = $tw.hooks || { names: {}};
$tw.boot = $tw.boot || {};
$tw.boot.preloadDirty = $tw.boot.preloadDirty || [];
// Tell TiddlyWiki not to boot itself
$tw.boot.suppressBoot = true;
})();
//# sourceURL=$:/plugins/tiddlywiki/sqlite3store/suppress-boot.js