mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-12-27 02:20:28 +00:00
13c4e028b1
Previously we were using a message `tw-auto-save-wiki` to trigger an autosave. The message was generated by certain UI actions such as saving a tiddler. The trouble was that the message was being processed before the wiki change event for the accompanying change had had a chance to percolate. The end result was that the dirty indicator was staying lit when using autosave. The new approach abandons the autosave message and instead triggers the autosave in the wiki change event when a relevant change occurs. One happy side effect of these changes is that the dirty indicator now works as expected with the client server edition - ie, when typing in a draft tiddler the dirty indicator will flash briefly, and then clear when the sync mechanism has completed saving the draft.
79 lines
2.3 KiB
JavaScript
79 lines
2.3 KiB
JavaScript
/*\
|
|
title: $:/core/modules/utils/pluginmaker.js
|
|
type: application/javascript
|
|
module-type: utils
|
|
|
|
A quick and dirty way to pack up plugins within the browser.
|
|
|
|
\*/
|
|
(function(){
|
|
|
|
/*jslint node: true, browser: true */
|
|
/*global $tw: false */
|
|
"use strict";
|
|
|
|
/*
|
|
Repack a plugin, and then delete any non-shadow payload tiddlers
|
|
*/
|
|
exports.repackPlugin = function(title,additionalTiddlers,excludeTiddlers) {
|
|
additionalTiddlers = additionalTiddlers || [];
|
|
excludeTiddlers = excludeTiddlers || [];
|
|
// Get the plugin tiddler
|
|
var pluginTiddler = $tw.wiki.getTiddler(title);
|
|
if(!pluginTiddler) {
|
|
throw "No such tiddler as " + title;
|
|
}
|
|
// Extract the JSON
|
|
try {
|
|
var jsonPluginTiddler = JSON.parse(pluginTiddler.fields.text);
|
|
} catch(e) {
|
|
throw "Cannot parse plugin tiddler " + title + "\nError: " + e;
|
|
}
|
|
// Get the list of tiddlers
|
|
var tiddlers = Object.keys(jsonPluginTiddler.tiddlers);
|
|
// Add the additional tiddlers
|
|
$tw.utils.pushTop(tiddlers,additionalTiddlers)
|
|
// Remove any excluded tiddlers
|
|
for(var t=tiddlers.length-1; t>=0; t--) {
|
|
if(excludeTiddlers.indexOf(tiddlers[t]) !== -1) {
|
|
tiddlers.splice(t,1);
|
|
}
|
|
}
|
|
// Pack up the tiddlers into a block of JSON
|
|
var plugins = {};
|
|
$tw.utils.each(tiddlers,function(title) {
|
|
var tiddler = $tw.wiki.getTiddler(title),
|
|
fields = {};
|
|
$tw.utils.each(tiddler.fields,function (value,name) {
|
|
fields[name] = tiddler.getFieldString(name);
|
|
});
|
|
plugins[title] = fields;
|
|
});
|
|
// Retrieve and bump the version number
|
|
var pluginVersion = $tw.utils.parseVersion(pluginTiddler.getFieldString("version") || "0.0.0") || {
|
|
major: "0",
|
|
minor: "0",
|
|
patch: "0"
|
|
};
|
|
pluginVersion.patch++;
|
|
var version = pluginVersion.major + "." + pluginVersion.minor + "." + pluginVersion.patch;
|
|
if(pluginVersion.prerelease) {
|
|
version += "-" + pluginVersion.prerelease;
|
|
}
|
|
if(pluginVersion.build) {
|
|
version += "+" + pluginVersion.build;
|
|
}
|
|
// Save the tiddler
|
|
$tw.wiki.addTiddler(new $tw.Tiddler(pluginTiddler,{text: JSON.stringify({tiddlers: plugins},null,4), version: version}));
|
|
// Delete any non-shadow constituent tiddlers
|
|
$tw.utils.each(tiddlers,function(title) {
|
|
if($tw.wiki.tiddlerExists(title)) {
|
|
$tw.wiki.deleteTiddler(title);
|
|
}
|
|
});
|
|
// Return a heartwarming confirmation
|
|
return "Plugin " + title + " successfully saved";
|
|
}
|
|
|
|
})();
|