2 changes: 1 addition & 1 deletion core/modules/utils/base64-utf8/base64-utf8.module.min.js
10 changes: 5 additions & 5 deletions core/modules/utils/dom/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,23 @@ exports.removeChildren = function(node) {
};

exports.hasClass = function(el,className) {
return el && el.className && el.className.toString().split(" ").indexOf(className) !== -1;
return el && el.hasAttribute && el.hasAttribute("class") && el.getAttribute("class").split(" ").indexOf(className) !== -1;
};

exports.addClass = function(el,className) {
var c = el.className.split(" ");
var c = (el.getAttribute("class") || "").split(" ");
if(c.indexOf(className) === -1) {
c.push(className);
el.className = c.join(" ");
el.setAttribute("class",c.join(" "));
}
};

exports.removeClass = function(el,className) {
var c = el.className.split(" "),
var c = (el.getAttribute("class") || "").split(" "),
p = c.indexOf(className);
if(p !== -1) {
c.splice(p,1);
el.className = c.join(" ");
el.setAttribute("class",c.join(" "));
}
};

Expand Down
16 changes: 13 additions & 3 deletions core/modules/utils/dom/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ exports.httpRequest = function(options) {
var type = options.type || "GET",
url = options.url,
headers = options.headers || {accept: "application/json"},
hasHeader = function(targetHeader) {
targetHeader = targetHeader.toLowerCase();
var result = false;
$tw.utils.each(headers,function(header,headerTitle,object) {
if(headerTitle.toLowerCase() === targetHeader) {
result = true;
}
});
return result;
},
returnProp = options.returnProp || "responseText",
request = new XMLHttpRequest(),
data = "",
Expand Down Expand Up @@ -63,10 +73,10 @@ exports.httpRequest = function(options) {
request.setRequestHeader(headerTitle,header);
});
}
if(data && !$tw.utils.hop(headers,"Content-type")) {
request.setRequestHeader("Content-type","application/x-www-form-urlencoded; charset=UTF-8");
if(data && !hasHeader("Content-Type")) {
request.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
}
if(!$tw.utils.hop(headers,"X-Requested-With")) {
if(!hasHeader("X-Requested-With")) {
request.setRequestHeader("X-Requested-With","TiddlyWiki");
}
try {
Expand Down
40 changes: 36 additions & 4 deletions core/modules/utils/dom/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Modal message mechanism
"use strict";

var widget = require("$:/core/modules/widgets/widget.js");
var navigator = require("$:/core/modules/widgets/navigator.js");

var Modal = function(wiki) {
this.wiki = wiki;
Expand Down Expand Up @@ -41,7 +42,12 @@ Modal.prototype.display = function(title,options) {
return;
}
// Create the variables
var variables = $tw.utils.extend({currentTiddler: title},options.variables);
var variables = $tw.utils.extend({
currentTiddler: title,
"tv-story-list": (options.event && options.event.widget ? options.event.widget.getVariable("tv-story-list") : ""),
"tv-history-list": (options.event && options.event.widget ? options.event.widget.getVariable("tv-history-list") : "")
},options.variables);

// Create the wrapper divs
var wrapper = this.srcDocument.createElement("div"),
modalBackdrop = this.srcDocument.createElement("div"),
Expand Down Expand Up @@ -75,6 +81,31 @@ Modal.prototype.display = function(title,options) {
modalFooter.appendChild(modalFooterHelp);
modalFooter.appendChild(modalFooterButtons);
modalWrapper.appendChild(modalFooter);
var navigatorTree = {
"type": "navigator",
"attributes": {
"story": {
"name": "story",
"type": "string",
"value": variables["tv-story-list"]
},
"history": {
"name": "history",
"type": "string",
"value": variables["tv-history-list"]
}
},
"tag": "$navigator",
"isBlock": true,
"children": []
};
var navigatorWidgetNode = new navigator.navigator(navigatorTree, {
wiki: this.wiki,
document : this.srcDocument,
parentWidget: $tw.rootWidget
});
navigatorWidgetNode.render(modalBody,null);

// Render the title of the message
var headerWidgetNode = this.wiki.makeTranscludeWidget(title,{
field: "subtitle",
Expand All @@ -86,19 +117,20 @@ Modal.prototype.display = function(title,options) {
type: "string",
value: title
}}}],
parentWidget: $tw.rootWidget,
parentWidget: navigatorWidgetNode,
document: this.srcDocument,
variables: variables,
importPageMacros: true
});
headerWidgetNode.render(headerTitle,null);
// Render the body of the message
var bodyWidgetNode = this.wiki.makeTranscludeWidget(title,{
parentWidget: $tw.rootWidget,
parentWidget: navigatorWidgetNode,
document: this.srcDocument,
variables: variables,
importPageMacros: true
});

bodyWidgetNode.render(modalBody,null);
// Setup the link if present
if(options.downloadLink) {
Expand Down Expand Up @@ -135,7 +167,7 @@ Modal.prototype.display = function(title,options) {
value: $tw.language.getString("Buttons/Close/Caption")
}}}
]}],
parentWidget: $tw.rootWidget,
parentWidget: navigatorWidgetNode,
document: this.srcDocument,
variables: variables,
importPageMacros: true
Expand Down
15 changes: 14 additions & 1 deletion core/modules/utils/dom/scroller.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,12 @@ Handle an event
*/
PageScroller.prototype.handleEvent = function(event) {
if(event.type === "tm-scroll") {
return this.scrollIntoView(event.target);
if(event.paramObject && event.paramObject.selector) {
this.scrollSelectorIntoView(null,event.paramObject.selector);
} else {
this.scrollIntoView(event.target);
}
return false; // Event was handled
}
return true;
};
Expand Down Expand Up @@ -117,6 +122,14 @@ PageScroller.prototype.scrollIntoView = function(element,callback) {
drawFrame();
};

PageScroller.prototype.scrollSelectorIntoView = function(baseElement,selector,callback) {
baseElement = baseElement || document.body;
var element = baseElement.querySelector(selector);
if(element) {
this.scrollIntoView(element,callback);
}
};

exports.PageScroller = PageScroller;

})();
24 changes: 22 additions & 2 deletions core/modules/utils/fakedom.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,32 @@ var bumpSequenceNumber = function(object) {
}
};

var TW_Node = function (){
throw TypeError("Illegal constructor");
};

Object.defineProperty(TW_Node.prototype, 'ELEMENT_NODE', {
get: function() {
return 1;
}
});

Object.defineProperty(TW_Node.prototype, 'TEXT_NODE', {
get: function() {
return 3;
}
});

var TW_TextNode = function(text) {
bumpSequenceNumber(this);
this.textContent = text + "";
};

TW_TextNode.prototype = Object.create(TW_Node.prototype);

Object.defineProperty(TW_TextNode.prototype, "nodeType", {
get: function() {
return 3;
return this.TEXT_NODE;
}
});

Expand All @@ -49,6 +67,8 @@ var TW_Element = function(tag,namespace) {
this.namespaceURI = namespace || "http://www.w3.org/1999/xhtml";
};

TW_Element.prototype = Object.create(TW_Node.prototype);

Object.defineProperty(TW_Element.prototype, "style", {
get: function() {
return this._style;
Expand All @@ -69,7 +89,7 @@ Object.defineProperty(TW_Element.prototype, "style", {

Object.defineProperty(TW_Element.prototype, "nodeType", {
get: function() {
return 1;
return this.ELEMENT_NODE;
}
});

Expand Down
188 changes: 173 additions & 15 deletions core/modules/utils/filesystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,33 @@ File system utilities
var fs = require("fs"),
path = require("path");

/*
Return the subdirectories of a path
*/
exports.getSubdirectories = function(dirPath) {
if(!$tw.utils.isDirectory(dirPath)) {
return null;
}
var subdirs = [];
$tw.utils.each(fs.readdirSync(dirPath),function(item) {
if($tw.utils.isDirectory(path.resolve(dirPath,item))) {
subdirs.push(item);
}
});
return subdirs;
}

/*
Recursively (and synchronously) copy a directory and all its content
*/
exports.copyDirectory = function(srcPath,dstPath) {
// Remove any trailing path separators
srcPath = $tw.utils.removeTrailingSeparator(srcPath);
dstPath = $tw.utils.removeTrailingSeparator(dstPath);
srcPath = path.resolve($tw.utils.removeTrailingSeparator(srcPath));
dstPath = path.resolve($tw.utils.removeTrailingSeparator(dstPath));
// Check that neither director is within the other
if(srcPath.substring(0,dstPath.length) === dstPath || dstPath.substring(0,srcPath.length) === srcPath) {
return "Cannot copy nested directories";
}
// Create the destination directory
var err = $tw.utils.createDirectory(dstPath);
if(err) {
Expand Down Expand Up @@ -184,15 +204,23 @@ exports.deleteEmptyDirs = function(dirpath,callback) {
/*
Create a fileInfo object for saving a tiddler:
filepath: the absolute path to the file containing the tiddler
type: the type of the tiddler file (NOT the type of the tiddler)
type: the type of the tiddler file on disk (NOT the type of the tiddler)
hasMetaFile: true if the file also has a companion .meta file
isEditableFile: true if the tiddler was loaded via non-standard options & marked editable
Options include:
directory: absolute path of root directory to which we are saving
pathFilters: optional array of filters to be used to generate the base path
wiki: optional wiki for evaluating the pathFilters
extFilters: optional array of filters to be used to generate the base path
wiki: optional wiki for evaluating the pathFilters,
fileInfo: an existing fileInfo to check against
originalpath: a preferred filepath if no pathFilters match
*/
exports.generateTiddlerFileInfo = function(tiddler,options) {
var fileInfo = {};
var fileInfo = {}, metaExt;
// Propagate the isEditableFile flag
if(options.fileInfo) {
fileInfo.isEditableFile = options.fileInfo.isEditableFile || false;
}
// Check if the tiddler has any unsafe fields that can't be expressed in a .tid or .meta file: containing control characters, or leading/trailing whitespace
var hasUnsafeFields = false;
$tw.utils.each(tiddler.getFieldStrings(),function(value,fieldName) {
Expand All @@ -218,32 +246,84 @@ exports.generateTiddlerFileInfo = function(tiddler,options) {
fileInfo.type = tiddlerType;
fileInfo.hasMetaFile = true;
}
if(options.extFilters) {
// Check for extension override
metaExt = $tw.utils.generateTiddlerExtension(tiddler.fields.title,{
extFilters: options.extFilters,
wiki: options.wiki
});
if(metaExt){
if(metaExt === ".tid") {
// Overriding to the .tid extension needs special handling
fileInfo.type = "application/x-tiddler";
fileInfo.hasMetaFile = false;
} else if (metaExt === ".json") {
// Overriding to the .json extension needs special handling
fileInfo.type = "application/json";
fileInfo.hasMetaFile = false;
} else {
//If the new type matches a known extention, use that MIME type's encoding
var extInfo = $tw.utils.getFileExtensionInfo(metaExt);
fileInfo.type = extInfo ? extInfo.type : null;
fileInfo.encoding = $tw.utils.getTypeEncoding(metaExt);
fileInfo.hasMetaFile = true;
}
}
}
}
// Take the file extension from the tiddler content type
// Take the file extension from the tiddler content type or metaExt
var contentTypeInfo = $tw.config.contentTypeInfo[fileInfo.type] || {extension: ""};
// Generate the filepath
fileInfo.filepath = $tw.utils.generateTiddlerFilepath(tiddler.fields.title,{
extension: contentTypeInfo.extension,
extension: metaExt || contentTypeInfo.extension,
directory: options.directory,
pathFilters: options.pathFilters,
wiki: options.wiki
wiki: options.wiki,
fileInfo: options.fileInfo,
originalpath: options.originalpath
});
return fileInfo;
};

/*
Generate the file extension for saving a tiddler
Options include:
extFilters: optional array of filters to be used to generate the extention
wiki: optional wiki for evaluating the extFilters
*/
exports.generateTiddlerExtension = function(title,options) {
var self = this,
extension;
// Check if any of the extFilters applies
if(options.extFilters && options.wiki) {
$tw.utils.each(options.extFilters,function(filter) {
if(!extension) {
var source = options.wiki.makeTiddlerIterator([title]),
result = options.wiki.filterTiddlers(filter,null,source);
if(result.length > 0) {
extension = result[0];
}
}
});
}
return extension;
};

/*
Generate the filepath for saving a tiddler
Options include:
extension: file extension to be added the finished filepath
directory: absolute path of root directory to which we are saving
pathFilters: optional array of filters to be used to generate the base path
wiki: optional wiki for evaluating the pathFilters
fileInfo: an existing fileInfo object to check against
*/
exports.generateTiddlerFilepath = function(title,options) {
var self = this,
directory = options.directory || "",
extension = options.extension || "",
filepath;
originalpath = options.originalpath || "",
filepath;
// Check if any of the pathFilters applies
if(options.pathFilters && options.wiki) {
$tw.utils.each(options.pathFilters,function(filter) {
Expand All @@ -256,8 +336,11 @@ exports.generateTiddlerFilepath = function(title,options) {
}
});
}
// If not, generate a base pathname
if(!filepath) {
if(!filepath && originalpath !== "") {
//Use the originalpath without the extension
var ext = path.extname(originalpath);
filepath = originalpath.substring(0,originalpath.length - ext.length);
} else if(!filepath) {
filepath = title;
// If the filepath already ends in the extension then remove it
if(filepath.substring(filepath.length - extension.length) === extension) {
Expand All @@ -266,10 +349,13 @@ exports.generateTiddlerFilepath = function(title,options) {
// Remove any forward or backward slashes so we don't create directories
filepath = filepath.replace(/\/|\\/g,"_");
}
// Don't let the filename start with a dot because such files are invisible on *nix
filepath = filepath.replace(/^\./g,"_");
//If the path does not start with "." or ".." and a path seperator, then
if(!/^\.{1,2}[/\\]/g.test(filepath)) {
// Don't let the filename start with any dots because such files are invisible on *nix
filepath = filepath.replace(/^\.+/g,"_");
}
// Remove any characters that can't be used in cross-platform filenames
filepath = $tw.utils.transliterate(filepath.replace(/<|>|\:|\"|\||\?|\*|\^/g,"_"));
filepath = $tw.utils.transliterate(filepath.replace(/<|>|~|\:|\"|\||\?|\*|\^/g,"_"));
// Truncate the filename if it is too long
if(filepath.length > 200) {
filepath = filepath.substr(0,200);
Expand All @@ -286,12 +372,30 @@ exports.generateTiddlerFilepath = function(title,options) {
});
}
// Add a uniquifier if the file already exists
var fullPath,
var fullPath, oldPath = (options.fileInfo) ? options.fileInfo.filepath : undefined,
count = 0;
do {
fullPath = path.resolve(directory,filepath + (count ? "_" + count : "") + extension);
if(oldPath && oldPath == fullPath) {
break;
}
count++;
} while(fs.existsSync(fullPath));
// If the last write failed with an error, or if path does not start with:
// the resolved options.directory, the resolved wikiPath directory, or the wikiTiddlersPath directory,
// then encodeURIComponent() and resolve to tiddler directory
var newPath = fullPath,
encode = (options.fileInfo || {writeError: false}).writeError == true;
if(!encode){
encode = !(fullPath.indexOf(path.resolve(directory)) == 0 ||
fullPath.indexOf(path.resolve($tw.boot.wikiPath)) == 0 ||
fullPath.indexOf($tw.boot.wikiTiddlersPath) == 0);
}
if(encode){
fullPath = path.resolve(directory, encodeURIComponent(fullPath));
}
// Call hook to allow plugins to modify the final path
fullPath = $tw.hooks.invokeHook("th-make-tiddler-path", newPath, fullPath);
// Return the full path to the file
return fullPath;
};
Expand Down Expand Up @@ -346,4 +450,58 @@ exports.saveTiddlerToFileSync = function(tiddler,fileInfo) {
}
};

/*
Delete a file described by the fileInfo if it exits
*/
exports.deleteTiddlerFile = function(fileInfo, callback) {
//Only attempt to delete files that exist on disk
if(!fileInfo.filepath || !fs.existsSync(fileInfo.filepath)) {
return callback(null);
}
// Delete the file
fs.unlink(fileInfo.filepath,function(err) {
if(err) {
return callback(err);
}
// Delete the metafile if present
if(fileInfo.hasMetaFile && fs.existsSync(fileInfo.filepath + ".meta")) {
fs.unlink(fileInfo.filepath + ".meta",function(err) {
if(err) {
return callback(err);
}
return $tw.utils.deleteEmptyDirs(path.dirname(fileInfo.filepath),callback);
});
} else {
return $tw.utils.deleteEmptyDirs(path.dirname(fileInfo.filepath),callback);
}
});
};

/*
Cleanup old files on disk, by comparing the options values:
adaptorInfo from $tw.syncer.tiddlerInfo
bootInfo from $tw.boot.files
*/
exports.cleanupTiddlerFiles = function(options, callback) {
var adaptorInfo = options.adaptorInfo || {},
bootInfo = options.bootInfo || {},
title = options.title || "undefined";
if(adaptorInfo.filepath && bootInfo.filepath && adaptorInfo.filepath !== bootInfo.filepath) {
return $tw.utils.deleteTiddlerFile(adaptorInfo, function(err){
if(err) {
if ((err.code == "EPERM" || err.code == "EACCES") && err.syscall == "unlink") {
// Error deleting the previous file on disk, should fail gracefully
$tw.syncer.displayError("Server desynchronized. Error cleaning up previous file for tiddler: "+title, err);
return callback(null);
} else {
return callback(err);
}
}
return callback(null);
});
} else {
return callback(null);
}
};

})();
118 changes: 118 additions & 0 deletions core/modules/utils/linked-list.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/*\
module-type: utils
title: $:/core/modules/utils/linkedlist.js
type: application/javascript
This is a doubly-linked indexed list intended for manipulation, particularly
pushTop, which it does with significantly better performance than an array.
\*/
(function(){

function LinkedList() {
this.clear();
};

LinkedList.prototype.clear = function() {
this.index = Object.create(null);
// LinkedList performs the duty of both the head and tail node
this.next = this;
this.prev = this;
this.length = 0;
};

LinkedList.prototype.remove = function(value) {
if($tw.utils.isArray(value)) {
for(var t=0; t<value.length; t++) {
_removeOne(this,value[t]);
}
} else {
_removeOne(this,value);
}
};

LinkedList.prototype.push = function(/* values */) {
for(var i = 0; i < arguments.length; i++) {
var value = arguments[i];
var node = {value: value};
var preexistingNode = this.index[value];
_linkToEnd(this,node);
if(preexistingNode) {
// We want to keep pointing to the first instance, but we want
// to have that instance (or chain of instances) point to the
// new one.
while (preexistingNode.copy) {
preexistingNode = preexistingNode.copy;
}
preexistingNode.copy = node;
} else {
this.index[value] = node;
}
}
};

LinkedList.prototype.pushTop = function(value) {
if($tw.utils.isArray(value)) {
for(var t=0; t<value.length; t++) {
_removeOne(this,value[t]);
}
this.push.apply(this,value);
} else {
var node = _removeOne(this,value);
if(!node) {
node = {value: value};
this.index[value] = node;
} else {
// Put this node at the end of the copy chain.
var preexistingNode = node;
while(preexistingNode.copy) {
preexistingNode = preexistingNode.copy;
}
// The order of these three statements is important,
// because sometimes preexistingNode == node.
preexistingNode.copy = node;
this.index[value] = node.copy;
node.copy = undefined;
}
_linkToEnd(this,node);
}
};

LinkedList.prototype.each = function(callback) {
for(var ptr = this.next; ptr !== this; ptr = ptr.next) {
callback(ptr.value);
}
};

LinkedList.prototype.toArray = function() {
var output = [];
for(var ptr = this.next; ptr !== this; ptr = ptr.next) {
output.push(ptr.value);
}
return output;
};

function _removeOne(list,value) {
var node = list.index[value];
if(node) {
node.prev.next = node.next;
node.next.prev = node.prev;
list.length -= 1;
// Point index to the next instance of the same value, maybe nothing.
list.index[value] = node.copy;
}
return node;
};

function _linkToEnd(list,node) {
// Sticks the given node onto the end of the list.
list.prev.next = node;
node.prev = list.prev;
list.prev = node;
node.next = list;
list.length += 1;
};

exports.LinkedList = LinkedList;

})();
107 changes: 100 additions & 7 deletions core/modules/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,19 @@ exports.warning = function(text) {
exports.log(text,"brown/orange");
};

/*
Log a table of name: value pairs
*/
exports.logTable = function(data) {
if(console.table) {
console.table(data);
} else {
$tw.utils.each(data,function(value,name) {
console.log(name + ": " + value);
});
}
}

/*
Return the integer represented by the str (string).
Return the dflt (default) parameter if str is not a base-10 number.
Expand Down Expand Up @@ -94,6 +107,36 @@ exports.trim = function(str) {
}
};

exports.trimPrefix = function(str,unwanted) {
if(typeof str === "string" && typeof unwanted === "string") {
if(unwanted === "") {
return str.replace(/^\s\s*/, '');
} else {
// Safely regexp-escape the unwanted text
unwanted = unwanted.replace(/[\\^$*+?.()|[\]{}]/g, '\\$&');
var regex = new RegExp('^(' + unwanted + ')+');
return str.replace(regex, '');
}
} else {
return str;
}
};

exports.trimSuffix = function(str,unwanted) {
if(typeof str === "string" && typeof unwanted === "string") {
if(unwanted === "") {
return str.replace(/\s\s*$/, '');
} else {
// Safely regexp-escape the unwanted text
unwanted = unwanted.replace(/[\\^$*+?.()|[\]{}]/g, '\\$&');
var regex = new RegExp('(' + unwanted + ')+$');
return str.replace(regex, '');
}
} else {
return str;
}
};

/*
Convert a string to sentence case (ie capitalise first letter)
*/
Expand Down Expand Up @@ -259,7 +302,7 @@ exports.formatDateString = function(date,template) {
return $tw.utils.pad($tw.utils.getHours12(date));
}],
[/^wYYYY/, function() {
return $tw.utils.getYearForWeekNo(date);
return $tw.utils.pad($tw.utils.getYearForWeekNo(date),4);
}],
[/^hh12/, function() {
return $tw.utils.getHours12(date);
Expand All @@ -268,7 +311,14 @@ exports.formatDateString = function(date,template) {
return date.getDate() + $tw.utils.getDaySuffix(date);
}],
[/^YYYY/, function() {
return date.getFullYear();
return $tw.utils.pad(date.getFullYear(),4);
}],
[/^aYYYY/, function() {
return $tw.utils.pad(Math.abs(date.getFullYear()),4);
}],
[/^\{era:([^,\|}]*)\|([^}\|]*)\|([^}]*)\}/, function(match) {
var year = date.getFullYear();
return year === 0 ? match[2] : (year < 0 ? match[1] : match[3]);
}],
[/^0hh/, function() {
return $tw.utils.pad(date.getHours());
Expand Down Expand Up @@ -357,7 +407,7 @@ exports.formatDateString = function(date,template) {
$tw.utils.each(matches, function(m) {
var match = m[0].exec(t);
if(match) {
matchString = m[1].call();
matchString = m[1].call(null,match);
t = t.substr(match[0].length);
return false;
}
Expand Down Expand Up @@ -514,7 +564,7 @@ exports.escape = function(ch) {

// Turns a string into a legal JavaScript string
// Copied from peg.js, thanks to David Majda
exports.stringify = function(s) {
exports.stringify = function(s, rawUnicode) {
/*
* ECMA-262, 5th ed., 7.8.4: All characters may appear literally in a string
* literal except for the closing quote character, backslash, carriage return,
Expand All @@ -523,19 +573,21 @@ exports.stringify = function(s) {
*
* For portability, we also escape all non-ASCII characters.
*/
var regex = rawUnicode ? /[\x00-\x1f]/g : /[\x00-\x1f\x80-\uFFFF]/g;
return (s || "")
.replace(/\\/g, '\\\\') // backslash
.replace(/"/g, '\\"') // double quote character
.replace(/'/g, "\\'") // single quote character
.replace(/\r/g, '\\r') // carriage return
.replace(/\n/g, '\\n') // line feed
.replace(/[\x00-\x1f\x80-\uFFFF]/g, exports.escape); // non-ASCII characters
.replace(regex, exports.escape); // non-ASCII characters
};

// Turns a string into a legal JSON string
// Derived from peg.js, thanks to David Majda
exports.jsonStringify = function(s) {
exports.jsonStringify = function(s, rawUnicode) {
// See http://www.json.org/
var regex = rawUnicode ? /[\x00-\x1f]/g : /[\x00-\x1f\x80-\uFFFF]/g;
return (s || "")
.replace(/\\/g, '\\\\') // backslash
.replace(/"/g, '\\"') // double quote character
Expand All @@ -544,7 +596,7 @@ exports.jsonStringify = function(s) {
.replace(/\x08/g, '\\b') // backspace
.replace(/\x0c/g, '\\f') // formfeed
.replace(/\t/g, '\\t') // tab
.replace(/[\x00-\x1f\x80-\uFFFF]/g,function(s) {
.replace(regex,function(s) {
return '\\u' + $tw.utils.pad(s.charCodeAt(0).toString(16).toUpperCase(),4);
}); // non-ASCII characters
};
Expand Down Expand Up @@ -813,4 +865,45 @@ exports.stringifyNumber = function(num) {
return num + "";
};

exports.makeCompareFunction = function(type,options) {
options = options || {};
var gt = options.invert ? -1 : +1,
lt = options.invert ? +1 : -1,
compare = function(a,b) {
if(a > b) {
return gt ;
} else if(a < b) {
return lt;
} else {
return 0;
}
},
types = {
"number": function(a,b) {
return compare($tw.utils.parseNumber(a),$tw.utils.parseNumber(b));
},
"integer": function(a,b) {
return compare($tw.utils.parseInt(a),$tw.utils.parseInt(b));
},
"string": function(a,b) {
return compare("" + a,"" +b);
},
"date": function(a,b) {
var dateA = $tw.utils.parseDate(a),
dateB = $tw.utils.parseDate(b);
if(!isFinite(dateA)) {
dateA = new Date(0);
}
if(!isFinite(dateB)) {
dateB = new Date(0);
}
return compare(dateA,dateB);
},
"version": function(a,b) {
return $tw.utils.compareVersions(a,b);
}
};
return (types[type] || types[options.defaultType] || types.number);
};

})();
77 changes: 77 additions & 0 deletions core/modules/widgets/action-confirm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*\
title: $:/core/modules/widgets/action-confirm.js
type: application/javascript
module-type: widget
\*/
(function(){

/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";

var Widget = require("$:/core/modules/widgets/widget.js").widget;

var ConfirmWidget = function(parseTreeNode,options) {
this.initialise(parseTreeNode,options);
};

/*
Inherit from the base widget class
*/
ConfirmWidget.prototype = new Widget();

/*
Render this widget into the DOM
*/
ConfirmWidget.prototype.render = function(parent,nextSibling) {
this.computeAttributes();
this.execute();
this.parentDomNode = parent;
this.renderChildren(parent,nextSibling);
};

/*
Compute the internal state of the widget
*/
ConfirmWidget.prototype.execute = function() {
this.message = this.getAttribute("$message",$tw.language.getString("ConfirmAction"));
this.prompt = (this.getAttribute("$prompt","yes") == "no" ? false : true);
this.makeChildWidgets();
};

/*
Refresh the widget by ensuring our attributes are up to date
*/
ConfirmWidget.prototype.refresh = function(changedTiddlers) {
var changedAttributes = this.computeAttributes();
if(changedAttributes["$message"] || changedAttributes["$prompt"]) {
this.refreshSelf();
return true;
}
return this.refreshChildren(changedTiddlers);
};

/*
Invoke the action associated with this widget
*/
ConfirmWidget.prototype.invokeAction = function(triggeringWidget,event) {
var invokeActions = true,
handled = true;
if(this.prompt) {
invokeActions = confirm(this.message);
}
if(invokeActions) {
handled = this.invokeActions(triggeringWidget,event);
}
return handled;
};

ConfirmWidget.prototype.allowActionPropagation = function() {
return false;
};

exports["action-confirm"] = ConfirmWidget;

})();
93 changes: 93 additions & 0 deletions core/modules/widgets/action-log.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*\
title: $:/core/modules/widgets/action-log.js
type: application/javascript
module-type: widget
Action widget to log debug messages
\*/
(function(){

/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";

var Widget = require("$:/core/modules/widgets/widget.js").widget;

var LogWidget = function(parseTreeNode,options) {
this.initialise(parseTreeNode,options);
};

/*
Inherit from the base widget class
*/
LogWidget.prototype = new Widget();

/*
Render this widget into the DOM
*/
LogWidget.prototype.render = function(parent,nextSibling) {
this.computeAttributes();
this.execute();
};

LogWidget.prototype.execute = function(){
this.message = this.getAttribute("$$message","debug");
this.logAll = this.getAttribute("$$all","no") === "yes" ? true : false;
this.filter = this.getAttribute("$$filter");
}

/*
Refresh the widget by ensuring our attributes are up to date
*/
LogWidget.prototype.refresh = function(changedTiddlers) {
this.refreshSelf();
return true;
};

/*
Invoke the action associated with this widget
*/
LogWidget.prototype.invokeAction = function(triggeringWidget,event) {
this.log();
return true; // Action was invoked
};

LogWidget.prototype.log = function() {
var data = {},
dataCount,
allVars = {},
filteredVars;

$tw.utils.each(this.attributes,function(attribute,name) {
if(name.substring(0,2) !== "$$") {
data[name] = attribute;
}
});

for(var v in this.variables) {
allVars[v] = this.getVariable(v,{defaultValue:""});
}
if(this.filter) {
filteredVars = this.wiki.compileFilter(this.filter).call(this.wiki,this.wiki.makeTiddlerIterator(allVars));
$tw.utils.each(filteredVars,function(name) {
data[name] = allVars[name];
});
}
dataCount = $tw.utils.count(data);

console.group(this.message);
if(dataCount > 0) {
$tw.utils.logTable(data);
}
if(this.logAll || !dataCount) {
console.groupCollapsed("All variables");
$tw.utils.logTable(allVars);
console.groupEnd();
}
console.groupEnd();
}

exports["action-log"] = LogWidget;

})();
4 changes: 3 additions & 1 deletion core/modules/widgets/action-popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ Invoke the action associated with this widget
ActionPopupWidget.prototype.invokeAction = function(triggeringWidget,event) {
// Trigger the popup
var popupLocationRegExp = /^\((-?[0-9\.E]+),(-?[0-9\.E]+),(-?[0-9\.E]+),(-?[0-9\.E]+)\)$/,
match = popupLocationRegExp.exec(this.actionCoords);
match = popupLocationRegExp.exec(this.actionCoords || "");
if(match) {
$tw.popup.triggerPopup({
domNode: null,
Expand All @@ -70,6 +70,8 @@ ActionPopupWidget.prototype.invokeAction = function(triggeringWidget,event) {
title: this.actionState,
wiki: this.wiki
});
} else {
$tw.popup.cancel(0);
}
return true; // Action was invoked
};
Expand Down
4 changes: 4 additions & 0 deletions core/modules/widgets/browse.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ BrowseWidget.prototype.render = function(parent,nextSibling) {
if(this.nwsaveas) {
domNode.setAttribute("nwsaveas",this.nwsaveas);
}
if(this.accept) {
domNode.setAttribute("accept",this.accept);
}
// Nw.js supports "webkitdirectory" and "nwdirectory" to allow a directory to be selected
if(this.webkitdirectory) {
domNode.setAttribute("webkitdirectory",this.webkitdirectory);
Expand Down Expand Up @@ -83,6 +86,7 @@ BrowseWidget.prototype.execute = function() {
this.param = this.getAttribute("param");
this.tooltip = this.getAttribute("tooltip");
this.nwsaveas = this.getAttribute("nwsaveas");
this.accept = this.getAttribute("accept");
this.webkitdirectory = this.getAttribute("webkitdirectory");
this.nwdirectory = this.getAttribute("nwdirectory");
};
Expand Down
41 changes: 34 additions & 7 deletions core/modules/widgets/button.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,20 @@ ButtonWidget.prototype = new Widget();
Render this widget into the DOM
*/
ButtonWidget.prototype.render = function(parent,nextSibling) {
var self = this;
var self = this,
tag = "button",
domNode;
// Remember parent
this.parentDomNode = parent;
// Compute attributes and execute state
this.computeAttributes();
this.execute();
// Create element
var tag = "button";
if(this.buttonTag && $tw.config.htmlUnsafeElements.indexOf(this.buttonTag) === -1) {
tag = this.buttonTag;
}
var domNode = this.document.createElement(tag);
domNode = this.document.createElement(tag);
this.domNode = domNode;
// Assign classes
var classes = this["class"].split(" ") || [],
isPoppedUp = (this.popup || this.popupTitle) && this.isPoppedUp();
Expand Down Expand Up @@ -67,7 +69,10 @@ ButtonWidget.prototype.render = function(parent,nextSibling) {
// Set the tabindex
if(this.tabIndex) {
domNode.setAttribute("tabindex",this.tabIndex);
}
}
if(this.isDisabled === "yes") {
domNode.setAttribute("disabled",true);
}
// Add a click event handler
domNode.addEventListener("click",function (event) {
var handled = false;
Expand All @@ -91,7 +96,8 @@ ButtonWidget.prototype.render = function(parent,nextSibling) {
handled = true;
}
if(self.actions) {
self.invokeActionString(self.actions,self,event);
var modifierKey = $tw.keyboardManager.getEventModifierKeyDescriptor(event);
self.invokeActionString(self.actions,self,event,{modifier: modifierKey});
}
if(handled) {
event.preventDefault();
Expand Down Expand Up @@ -196,10 +202,10 @@ ButtonWidget.prototype.execute = function() {
this.setTo = this.getAttribute("setTo");
this.popup = this.getAttribute("popup");
this.hover = this.getAttribute("hover");
this["class"] = this.getAttribute("class","");
this["aria-label"] = this.getAttribute("aria-label");
this.tooltip = this.getAttribute("tooltip");
this.style = this.getAttribute("style");
this["class"] = this.getAttribute("class","");
this.selectedClass = this.getAttribute("selectedClass");
this.defaultSetValue = this.getAttribute("default","");
this.buttonTag = this.getAttribute("tag");
Expand All @@ -210,18 +216,39 @@ ButtonWidget.prototype.execute = function() {
this.setIndex = this.getAttribute("setIndex");
this.popupTitle = this.getAttribute("popupTitle");
this.tabIndex = this.getAttribute("tabindex");
this.isDisabled = this.getAttribute("disabled","no");
// Make child widgets
this.makeChildWidgets();
};

ButtonWidget.prototype.updateDomNodeClasses = function() {
var domNodeClasses = this.domNode.className.split(" "),
oldClasses = this.class.split(" "),
newClasses;
this["class"] = this.getAttribute("class","");
newClasses = this.class.split(" ");
//Remove classes assigned from the old value of class attribute
$tw.utils.each(oldClasses,function(oldClass){
var i = domNodeClasses.indexOf(oldClass);
if(i !== -1) {
domNodeClasses.splice(i,1);
}
});
//Add new classes from updated class attribute.
$tw.utils.pushTop(domNodeClasses,newClasses);
this.domNode.className = domNodeClasses.join(" ");
}

/*
Selectively refreshes the widget if needed. Returns true if the widget or any of its children needed re-rendering
*/
ButtonWidget.prototype.refresh = function(changedTiddlers) {
var changedAttributes = this.computeAttributes();
if(changedAttributes.actions || changedAttributes.to || changedAttributes.message || changedAttributes.param || changedAttributes.set || changedAttributes.setTo || changedAttributes.popup || changedAttributes.hover || changedAttributes["class"] || changedAttributes.selectedClass || changedAttributes.style || changedAttributes.dragFilter || changedAttributes.dragTiddler || (this.set && changedTiddlers[this.set]) || (this.popup && changedTiddlers[this.popup]) || (this.popupTitle && changedTiddlers[this.popupTitle]) || changedAttributes.setTitle || changedAttributes.setField || changedAttributes.setIndex || changedAttributes.popupTitle) {
if(changedAttributes.actions || changedAttributes.to || changedAttributes.message || changedAttributes.param || changedAttributes.set || changedAttributes.setTo || changedAttributes.popup || changedAttributes.hover || changedAttributes.selectedClass || changedAttributes.style || changedAttributes.dragFilter || changedAttributes.dragTiddler || (this.set && changedTiddlers[this.set]) || (this.popup && changedTiddlers[this.popup]) || (this.popupTitle && changedTiddlers[this.popupTitle]) || changedAttributes.setTitle || changedAttributes.setField || changedAttributes.setIndex || changedAttributes.popupTitle || changedAttributes.disabled) {
this.refreshSelf();
return true;
} else if(changedAttributes["class"]) {
this.updateDomNodeClasses();
}
return this.refreshChildren(changedTiddlers);
};
Expand Down
6 changes: 5 additions & 1 deletion core/modules/widgets/checkbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ CheckboxWidget.prototype.render = function(parent,nextSibling) {
if(this.getValue()) {
this.inputDomNode.setAttribute("checked","true");
}
if(this.isDisabled === "yes") {
this.inputDomNode.setAttribute("disabled",true);
}
this.labelDomNode.appendChild(this.inputDomNode);
this.spanDomNode = this.document.createElement("span");
this.labelDomNode.appendChild(this.spanDomNode);
Expand Down Expand Up @@ -181,6 +184,7 @@ CheckboxWidget.prototype.execute = function() {
this.checkboxDefault = this.getAttribute("default");
this.checkboxClass = this.getAttribute("class","");
this.checkboxInvertTag = this.getAttribute("invertTag","");
this.isDisabled = this.getAttribute("disabled","no");
// Make the child widgets
this.makeChildWidgets();
};
Expand All @@ -190,7 +194,7 @@ Selectively refreshes the widget if needed. Returns true if the widget or any of
*/
CheckboxWidget.prototype.refresh = function(changedTiddlers) {
var changedAttributes = this.computeAttributes();
if(changedAttributes.tiddler || changedAttributes.tag || changedAttributes.invertTag || changedAttributes.field || changedAttributes.index || changedAttributes.checked || changedAttributes.unchecked || changedAttributes["default"] || changedAttributes["class"]) {
if(changedAttributes.tiddler || changedAttributes.tag || changedAttributes.invertTag || changedAttributes.field || changedAttributes.index || changedAttributes.checked || changedAttributes.unchecked || changedAttributes["default"] || changedAttributes["class"] || changedAttributes.disabled) {
this.refreshSelf();
return true;
} else {
Expand Down
35 changes: 23 additions & 12 deletions core/modules/widgets/droppable.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,21 @@ DroppableWidget.prototype = new Widget();
Render this widget into the DOM
*/
DroppableWidget.prototype.render = function(parent,nextSibling) {
var self = this;
var self = this,
tag = this.parseTreeNode.isBlock ? "div" : "span",
domNode;
// Remember parent
this.parentDomNode = parent;
// Compute attributes and execute state
this.computeAttributes();
this.execute();
var tag = this.parseTreeNode.isBlock ? "div" : "span";
if(this.droppableTag && $tw.config.htmlUnsafeElements.indexOf(this.droppableTag) === -1) {
tag = this.droppableTag;
}
// Create element and assign classes
var domNode = this.document.createElement(tag),
classes = (this["class"] || "").split(" ");
classes.push("tc-droppable");
domNode.className = classes.join(" ");
domNode = this.document.createElement(tag);
this.domNode = domNode;
this.assignDomNodeClasses();
// Add event handlers
if(this.droppableEnable) {
$tw.utils.addEventListeners(domNode,[
Expand All @@ -50,6 +50,8 @@ DroppableWidget.prototype.render = function(parent,nextSibling) {
{name: "dragleave", handlerObject: this, handlerMethod: "handleDragLeaveEvent"},
{name: "drop", handlerObject: this, handlerMethod: "handleDropEvent"}
]);
} else {
$tw.utils.addClass(this.domNode,this.disabledClass);
}
// Insert element
parent.insertBefore(domNode,nextSibling);
Expand All @@ -75,7 +77,9 @@ DroppableWidget.prototype.leaveDrag = function(event) {
// Remove highlighting if we're leaving externally. The hacky second condition is to resolve a problem with Firefox whereby there is an erroneous dragenter event if the node being dragged is within the dropzone
if(this.currentlyEntered.length === 0 || (this.currentlyEntered.length === 1 && this.currentlyEntered[0] === $tw.dragInProgress)) {
this.currentlyEntered = [];
$tw.utils.removeClass(this.domNodes[0],"tc-dragover");
if(this.domNodes[0]) {
$tw.utils.removeClass(this.domNodes[0],"tc-dragover");
}
}
};

Expand Down Expand Up @@ -130,8 +134,7 @@ DroppableWidget.prototype.handleDropEvent = function(event) {

DroppableWidget.prototype.performActions = function(title,event) {
if(this.droppableActions) {
var modifierKey = event.ctrlKey && ! event.shiftKey ? "ctrl" : event.shiftKey && !event.ctrlKey ? "shift" :
event.ctrlKey && event.shiftKey ? "ctrl-shift" : "normal" ;
var modifierKey = $tw.keyboardManager.getEventModifierKeyDescriptor(event);
this.invokeActionString(this.droppableActions,this,event,{actionTiddler: title, modifier: modifierKey});
}
};
Expand All @@ -143,24 +146,32 @@ DroppableWidget.prototype.execute = function() {
this.droppableActions = this.getAttribute("actions");
this.droppableEffect = this.getAttribute("effect","copy");
this.droppableTag = this.getAttribute("tag");
this.droppableClass = this.getAttribute("class");
this.droppableEnable = (this.getAttribute("enable") || "yes") === "yes";
this.disabledClass = this.getAttribute("disabledClass","");
// Make child widgets
this.makeChildWidgets();
};

DroppableWidget.prototype.assignDomNodeClasses = function() {
var classes = this.getAttribute("class","").split(" ");
classes.push("tc-droppable");
this.domNode.className = classes.join(" ");
};

/*
Selectively refreshes the widget if needed. Returns true if the widget or any of its children needed re-rendering
*/
DroppableWidget.prototype.refresh = function(changedTiddlers) {
var changedAttributes = this.computeAttributes();
if(changedAttributes["class"] || changedAttributes.tag || changedAttributes.enable) {
if(changedAttributes.tag || changedAttributes.enable || changedAttributes.disabledClass || changedAttributes.actions || changedAttributes.effect) {
this.refreshSelf();
return true;
} else if(changedAttributes["class"]) {
this.assignDomNodeClasses();
}
return this.refreshChildren(changedTiddlers);
};

exports.droppable = DroppableWidget;

})();
})();
10 changes: 6 additions & 4 deletions core/modules/widgets/dropzone.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ DropZoneWidget.prototype.handleDragEndEvent = function(event) {
DropZoneWidget.prototype.handleDropEvent = function(event) {
var self = this,
readFileCallback = function(tiddlerFieldsArray) {
self.dispatchEvent({type: "tm-import-tiddlers", param: JSON.stringify(tiddlerFieldsArray)});
self.dispatchEvent({type: "tm-import-tiddlers", param: JSON.stringify(tiddlerFieldsArray), autoOpenOnImport: self.autoOpenOnImport, importTitle: self.importTitle});
};
this.leaveDrag(event);
// Check for being over a TEXTAREA or INPUT
Expand Down Expand Up @@ -149,7 +149,7 @@ DropZoneWidget.prototype.handleDropEvent = function(event) {
DropZoneWidget.prototype.handlePasteEvent = function(event) {
var self = this,
readFileCallback = function(tiddlerFieldsArray) {
self.dispatchEvent({type: "tm-import-tiddlers", param: JSON.stringify(tiddlerFieldsArray)});
self.dispatchEvent({type: "tm-import-tiddlers", param: JSON.stringify(tiddlerFieldsArray), autoOpenOnImport: self.autoOpenOnImport, importTitle: self.importTitle});
};
// Let the browser handle it if we're in a textarea or input box
if(["TEXTAREA","INPUT"].indexOf(event.target.tagName) == -1 && !event.target.isContentEditable) {
Expand All @@ -176,7 +176,7 @@ DropZoneWidget.prototype.handlePasteEvent = function(event) {
if($tw.log.IMPORT) {
console.log("Importing string '" + str + "', type: '" + type + "'");
}
self.dispatchEvent({type: "tm-import-tiddlers", param: JSON.stringify([tiddlerFields])});
self.dispatchEvent({type: "tm-import-tiddlers", param: JSON.stringify([tiddlerFields]), autoOpenOnImport: self.autoOpenOnImport, importTitle: self.importTitle});
});
}
}
Expand All @@ -193,6 +193,8 @@ DropZoneWidget.prototype.execute = function() {
this.dropzoneClass = this.getAttribute("class");
this.dropzoneDeserializer = this.getAttribute("deserializer");
this.dropzoneEnable = (this.getAttribute("enable") || "yes") === "yes";
this.autoOpenOnImport = this.getAttribute("autoOpenOnImport");
this.importTitle = this.getAttribute("importTitle");
// Make child widgets
this.makeChildWidgets();
};
Expand All @@ -202,7 +204,7 @@ Selectively refreshes the widget if needed. Returns true if the widget or any of
*/
DropZoneWidget.prototype.refresh = function(changedTiddlers) {
var changedAttributes = this.computeAttributes();
if(changedAttributes.enable) {
if(changedAttributes.enable || changedAttributes.autoOpenOnImport || changedAttributes.importTitle || changedAttributes.deserializer || changedAttributes.class) {
this.refreshSelf();
return true;
}
Expand Down
16 changes: 6 additions & 10 deletions core/modules/widgets/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,16 @@ EditWidget.prototype.execute = function() {
this.editPlaceholder = this.getAttribute("placeholder");
this.editTabIndex = this.getAttribute("tabindex");
this.editFocus = this.getAttribute("focus","");
this.editCancelPopups = this.getAttribute("cancelPopups","");
this.editInputActions = this.getAttribute("inputActions");
this.editRefreshTitle = this.getAttribute("refreshTitle");
this.editAutoComplete = this.getAttribute("autocomplete");
// Choose the appropriate edit widget
this.editorType = this.getEditorType();
// Make the child widgets
this.makeChildWidgets([{
type: "edit-" + this.editorType,
attributes: {
tiddler: {type: "string", value: this.editTitle},
field: {type: "string", value: this.editField},
index: {type: "string", value: this.editIndex},
"class": {type: "string", value: this.editClass},
"placeholder": {type: "string", value: this.editPlaceholder},
"tabindex": {type: "string", value: this.editTabIndex},
"focus": {type: "string", value: this.editFocus}
},
attributes: this.parseTreeNode.attributes,
children: this.parseTreeNode.children
}]);
};
Expand Down Expand Up @@ -94,7 +90,7 @@ Selectively refreshes the widget if needed. Returns true if the widget or any of
EditWidget.prototype.refresh = function(changedTiddlers) {
var changedAttributes = this.computeAttributes();
// Refresh if an attribute has changed, or the type associated with the target tiddler has changed
if(changedAttributes.tiddler || changedAttributes.field || changedAttributes.index || changedAttributes.tabindex || (changedTiddlers[this.editTitle] && this.getEditorType() !== this.editorType)) {
if(changedAttributes.tiddler || changedAttributes.field || changedAttributes.index || changedAttributes.tabindex || changedAttributes.cancelPopups || changedAttributes.inputActions || changedAttributes.refreshTitle || changedAttributes.autocomplete || (changedTiddlers[this.editTitle] && this.getEditorType() !== this.editorType)) {
this.refreshSelf();
return true;
} else {
Expand Down
49 changes: 28 additions & 21 deletions core/modules/widgets/element.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,45 +29,47 @@ Render this widget into the DOM
ElementWidget.prototype.render = function(parent,nextSibling) {
this.parentDomNode = parent;
this.computeAttributes();
this.execute();
// Neuter blacklisted elements
var tag = this.parseTreeNode.tag;
if($tw.config.htmlUnsafeElements.indexOf(tag) !== -1) {
tag = "safe-" + tag;
this.tag = this.parseTreeNode.tag;
if($tw.config.htmlUnsafeElements.indexOf(this.tag) !== -1) {
this.tag = "safe-" + this.tag;
}
// Adjust headings by the current base level
var headingLevel = ["h1","h2","h3","h4","h5","h6"].indexOf(tag);
var headingLevel = ["h1","h2","h3","h4","h5","h6"].indexOf(this.tag);
if(headingLevel !== -1) {
var baseLevel = parseInt(this.getVariable("tv-adjust-heading-level","0"),10) || 0;
headingLevel = Math.min(Math.max(headingLevel + 1 + baseLevel,1),6);
tag = "h" + headingLevel;
this.tag = "h" + headingLevel;
}
// Create the DOM node
var domNode = this.document.createElementNS(this.namespace,tag);
this.assignAttributes(domNode,{excludeEventAttributes: true});
parent.insertBefore(domNode,nextSibling);
this.renderChildren(domNode,null);
this.domNodes.push(domNode);
};

/*
Compute the internal state of the widget
*/
ElementWidget.prototype.execute = function() {
// Select the namespace for the tag
var tagNamespaces = {
svg: "http://www.w3.org/2000/svg",
math: "http://www.w3.org/1998/Math/MathML",
body: "http://www.w3.org/1999/xhtml"
};
this.namespace = tagNamespaces[this.parseTreeNode.tag];
this.namespace = tagNamespaces[this.tag];
if(this.namespace) {
this.setVariable("namespace",this.namespace);
} else {
this.namespace = this.getVariable("namespace",{defaultValue: "http://www.w3.org/1999/xhtml"});
}
// Invoke the th-rendering-element hook
var parseTreeNodes = $tw.hooks.invokeHook("th-rendering-element",null,this);
this.isReplaced = !!parseTreeNodes;
if(parseTreeNodes) {
// Use the parse tree nodes provided by the hook
this.makeChildWidgets(parseTreeNodes);
this.renderChildren(this.parentDomNode,null);
return;
}
// Make the child widgets
this.makeChildWidgets();
// Create the DOM node and render children
var domNode = this.document.createElementNS(this.namespace,this.tag);
this.assignAttributes(domNode,{excludeEventAttributes: true});
parent.insertBefore(domNode,nextSibling);
this.renderChildren(domNode,null);
this.domNodes.push(domNode);
};

/*
Expand All @@ -77,8 +79,13 @@ ElementWidget.prototype.refresh = function(changedTiddlers) {
var changedAttributes = this.computeAttributes(),
hasChangedAttributes = $tw.utils.count(changedAttributes) > 0;
if(hasChangedAttributes) {
// Update our attributes
this.assignAttributes(this.domNodes[0],{excludeEventAttributes: true});
if(!this.isReplaced) {
// Update our attributes
this.assignAttributes(this.domNodes[0],{excludeEventAttributes: true});
} else {
// If we were replaced then completely refresh ourselves
return this.refreshSelf();
}
}
return this.refreshChildren(changedTiddlers) || hasChangedAttributes;
};
Expand Down
1 change: 1 addition & 0 deletions core/modules/widgets/entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Render this widget into the DOM
*/
EntityWidget.prototype.render = function(parent,nextSibling) {
this.parentDomNode = parent;
this.computeAttributes();
this.execute();
var entityString = this.getAttribute("entity",this.parseTreeNode.entity || ""),
textNode = this.document.createTextNode($tw.utils.entityDecode(entityString));
Expand Down
156 changes: 156 additions & 0 deletions core/modules/widgets/eventcatcher.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
/*\
title: $:/core/modules/widgets/eventcatcher.js
type: application/javascript
module-type: widget
Event handler widget
\*/
(function(){

/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";

var Widget = require("$:/core/modules/widgets/widget.js").widget;

var EventWidget = function(parseTreeNode,options) {
this.initialise(parseTreeNode,options);
};

/*
Inherit from the base widget class
*/
EventWidget.prototype = new Widget();

/*
Render this widget into the DOM
*/
EventWidget.prototype.render = function(parent,nextSibling) {
var self = this;
// Remember parent
this.parentDomNode = parent;
// Compute attributes and execute state
this.computeAttributes();
this.execute();
// Create element
var tag = this.parseTreeNode.isBlock ? "div" : "span";
if(this.elementTag && $tw.config.htmlUnsafeElements.indexOf(this.elementTag) === -1) {
tag = this.elementTag;
}
var domNode = this.document.createElement(tag);
this.domNode = domNode;
// Assign classes
this.assignDomNodeClasses();
// Add our event handler
$tw.utils.each(this.types,function(type) {
domNode.addEventListener(type,function(event) {
var selector = self.getAttribute("selector"),
actions = self.getAttribute("actions-"+type),
selectedNode = event.target,
selectedNodeRect,
catcherNodeRect,
variables = {};
if(selector) {
// Search ancestors for a node that matches the selector
while(!selectedNode.matches(selector) && selectedNode !== domNode) {
selectedNode = selectedNode.parentNode;
}
// If we found one, copy the attributes as variables, otherwise exit
if(selectedNode.matches(selector)) {
$tw.utils.each(selectedNode.attributes,function(attribute) {
variables["dom-" + attribute.name] = attribute.value.toString();
});
//Add a variable with a popup coordinate string for the selected node
variables["tv-popup-coords"] = "(" + selectedNode.offsetLeft + "," + selectedNode.offsetTop +"," + selectedNode.offsetWidth + "," + selectedNode.offsetHeight + ")";

//Add variables for offset of selected node
variables["tv-selectednode-posx"] = selectedNode.offsetLeft.toString();
variables["tv-selectednode-posy"] = selectedNode.offsetTop.toString();
variables["tv-selectednode-width"] = selectedNode.offsetWidth.toString();
variables["tv-selectednode-height"] = selectedNode.offsetHeight.toString();

//Add variables for event X and Y position relative to selected node
selectedNodeRect = selectedNode.getBoundingClientRect();
variables["event-fromselected-posx"] = (event.clientX - selectedNodeRect.left).toString();
variables["event-fromselected-posy"] = (event.clientY - selectedNodeRect.top).toString();

//Add variables for event X and Y position relative to event catcher node
catcherNodeRect = self.domNode.getBoundingClientRect();
variables["event-fromcatcher-posx"] = (event.clientX - catcherNodeRect.left).toString();
variables["event-fromcatcher-posy"] = (event.clientY - catcherNodeRect.top).toString();
} else {
return false;
}
}
// Execute our actions with the variables
if(actions) {
// Add a variable for the modifier key
variables.modifier = $tw.keyboardManager.getEventModifierKeyDescriptor(event);
// Add a variable for the mouse button
if("button" in event) {
if(event.button === 0) {
variables["event-mousebutton"] = "left";
} else if(event.button === 1) {
variables["event-mousebutton"] = "middle";
} else if(event.button === 2) {
variables["event-mousebutton"] = "right";
}
}
variables["event-type"] = event.type.toString();
if(typeof event.detail === "object" && !!event.detail) {
$tw.utils.each(event.detail,function(detailValue,detail) {
variables["event-detail-" + detail] = detailValue.toString();
});
} else if(!!event.detail) {
variables["event-detail"] = event.detail.toString();
}
self.invokeActionString(actions,self,event,variables);
event.preventDefault();
event.stopPropagation();
return true;
}
return false;
},false);
});
// Insert element
parent.insertBefore(domNode,nextSibling);
this.renderChildren(domNode,null);
this.domNodes.push(domNode);
};

/*
Compute the internal state of the widget
*/
EventWidget.prototype.execute = function() {
var self = this;
// Get attributes that require a refresh on change
this.types = this.getAttribute("events","").split(" ");
this.elementTag = this.getAttribute("tag");
// Make child widgets
this.makeChildWidgets();
};

EventWidget.prototype.assignDomNodeClasses = function() {
var classes = this.getAttribute("class","").split(" ");
classes.push("tc-eventcatcher");
this.domNode.className = classes.join(" ");
};

/*
Selectively refreshes the widget if needed. Returns true if the widget or any of its children needed re-rendering
*/
EventWidget.prototype.refresh = function(changedTiddlers) {
var changedAttributes = this.computeAttributes();
if(changedAttributes["events"] || changedAttributes["tag"]) {
this.refreshSelf();
return true;
} else if(changedAttributes["class"]) {
this.assignDomNodeClasses();
}
return this.refreshChildren(changedTiddlers);
};

exports.eventcatcher = EventWidget;

})();
11 changes: 10 additions & 1 deletion core/modules/widgets/importvariables.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ Compute the internal state of the widget
*/
ImportVariablesWidget.prototype.execute = function(tiddlerList) {
var widgetPointer = this;
// Got to flush all the accumulated variables
this.variables = new this.variablesConstructor();
// Get our parameters
this.filter = this.getAttribute("filter");
// Compute the filter
Expand Down Expand Up @@ -70,7 +72,14 @@ ImportVariablesWidget.prototype.execute = function(tiddlerList) {
widgetPointer.variables[key] = widget.variables[key];
});
} else {
widgetPointer.makeChildWidgets([node]);
widgetPointer.children = [widgetPointer.makeChildWidget(node)];
// No more regenerating children for
// this widget. If it needs to refresh,
// it'll do so along with the the whole
// importvariable tree.
if (widgetPointer != this) {
widgetPointer.makeChildWidgets = function(){};
}
widgetPointer = widgetPointer.children[0];
}
parseTreeNode = parseTreeNode.children && parseTreeNode.children[0];
Expand Down
8 changes: 5 additions & 3 deletions core/modules/widgets/keyboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,15 @@ KeyboardWidget.prototype.render = function(parent,nextSibling) {
// Add a keyboard event handler
domNode.addEventListener("keydown",function (event) {
if($tw.keyboardManager.checkKeyDescriptors(event,self.keyInfoArray)) {
self.invokeActions(self,event);
var handled = self.invokeActions(self,event);
if(self.actions) {
self.invokeActionString(self.actions,self,event);
}
self.dispatchMessage(event);
event.preventDefault();
event.stopPropagation();
if(handled || self.actions || self.message) {
event.preventDefault();
event.stopPropagation();
}
return true;
}
return false;
Expand Down
9 changes: 6 additions & 3 deletions core/modules/widgets/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ LinkWidget.prototype.renderLink = function(parent,nextSibling) {
tag = "a";
}
// Create our element
var domNode = this.document.createElement(tag);
var namespace = this.getVariable("namespace",{defaultValue: "http://www.w3.org/1999/xhtml"}),
domNode = this.document.createElementNS(namespace,tag);
// Assign classes
var classes = [];
if(this.overrideClasses === undefined) {
Expand Down Expand Up @@ -102,7 +103,8 @@ LinkWidget.prototype.renderLink = function(parent,nextSibling) {
// Override with the value of tv-get-export-link if defined
wikiLinkText = this.getVariable("tv-get-export-link",{params: [{name: "to",value: this.to}],defaultValue: wikiLinkText});
if(tag === "a") {
domNode.setAttribute("href",wikiLinkText);
var namespaceHref = (namespace === "http://www.w3.org/2000/svg") ? "http://www.w3.org/1999/xlink" : undefined;
domNode.setAttributeNS(namespaceHref,"href",wikiLinkText);
}
// Set the tabindex
if(this.tabIndex) {
Expand Down Expand Up @@ -156,7 +158,8 @@ LinkWidget.prototype.handleClickEvent = function(event) {
metaKey: event.metaKey,
ctrlKey: event.ctrlKey,
altKey: event.altKey,
shiftKey: event.shiftKey
shiftKey: event.shiftKey,
event: event
});
if(this.domNodes[0].hasAttribute("href")) {
event.preventDefault();
Expand Down
3 changes: 2 additions & 1 deletion core/modules/widgets/linkcatcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ LinkCatcherWidget.prototype.handleNavigateEvent = function(event) {
}
if(this.catchActions) {
this.executingActions = true;
this.invokeActionString(this.catchActions,this,event,{navigateTo: event.navigateTo});
var modifierKey = $tw.keyboardManager.getEventModifierKeyDescriptor(event);
this.invokeActionString(this.catchActions,this,event,{navigateTo: event.navigateTo, modifier: modifierKey});
this.executingActions = false;
}
} else {
Expand Down
10 changes: 8 additions & 2 deletions core/modules/widgets/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,14 @@ ListWidget.prototype.getTiddlerList = function() {
};

ListWidget.prototype.getEmptyMessage = function() {
var emptyMessage = this.getAttribute("emptyMessage",""),
parser = this.wiki.parseText("text/vnd.tiddlywiki",emptyMessage,{parseAsInline: true});
var parser,
emptyMessage = this.getAttribute("emptyMessage","");
// this.wiki.parseText() calls
// new Parser(..), which should only be done, if needed, because it's heavy!
if (emptyMessage === "") {
return [];
}
parser = this.wiki.parseText("text/vnd.tiddlywiki",emptyMessage,{parseAsInline: true});
if(parser) {
return parser.tree;
} else {
Expand Down
30 changes: 30 additions & 0 deletions core/modules/widgets/log.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*\
title: $:/core/modules/widgets/log.js
type: application/javascript
module-type: widget-subclass
Widget to log debug messages
\*/
(function(){

/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";

exports.baseClass = "action-log";

exports.name = "log";

exports.constructor = function(parseTreeNode,options) {
this.initialise(parseTreeNode,options);
}

exports.prototype = {};

exports.prototype.render = function(event) {
Object.getPrototypeOf(Object.getPrototypeOf(this)).render.call(this,event);
Object.getPrototypeOf(Object.getPrototypeOf(this)).log.call(this);
}

})();
18 changes: 15 additions & 3 deletions core/modules/widgets/macrocall.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,19 @@ MacroCallWidget.prototype.execute = function() {
// Are we rendering to HTML?
if(this.renderOutput === "text/html") {
// If so we'll return the parsed macro
var parser = this.wiki.parseText(this.parseType,text,
{parseAsInline: !this.parseTreeNode.isBlock});
parseTreeNodes = parser ? parser.tree : [];
// Check if we've already cached parsing this macro
var mode = this.parseTreeNode.isBlock ? "blockParser" : "inlineParser",
parser;
if(variableInfo.srcVariable && variableInfo.srcVariable[mode]) {
parser = variableInfo.srcVariable[mode];
} else {
parser = this.wiki.parseText(this.parseType,text,
{parseAsInline: !this.parseTreeNode.isBlock});
if(variableInfo.isCacheable && variableInfo.srcVariable) {
variableInfo.srcVariable[mode] = parser;
}
}
var parseTreeNodes = parser ? parser.tree : [];
// Wrap the parse tree in a vars widget assigning the parameters to variables named "__paramname__"
var attributes = {};
$tw.utils.each(variableInfo.params,function(param) {
Expand All @@ -73,6 +83,8 @@ MacroCallWidget.prototype.execute = function() {
attributes: attributes,
children: parseTreeNodes
}];
} else if(this.renderOutput === "text/raw") {
parseTreeNodes = [{type: "text", text: text}];
} else {
// Otherwise, we'll render the text
var plainText = this.wiki.renderText("text/plain",this.parseType,text,{parentWidget: this});
Expand Down
48 changes: 32 additions & 16 deletions core/modules/widgets/navigator.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ NavigatorWidget.prototype.execute = function() {
this.historyTitle = this.getAttribute("history");
this.setVariable("tv-story-list",this.storyTitle);
this.setVariable("tv-history-list",this.historyTitle);
this.story = new $tw.Story({
wiki: this.wiki,
storyTitle: this.storyTitle,
historyTitle: this.historyTitle
});
// Construct the child widgets
this.makeChildWidgets();
};
Expand Down Expand Up @@ -123,7 +128,7 @@ NavigatorWidget.prototype.replaceFirstTitleInStory = function(storyList,oldTitle

NavigatorWidget.prototype.addToStory = function(title,fromTitle) {
if(this.storyTitle) {
this.wiki.addToStory(title,fromTitle,this.storyTitle,{
this.story.addToStory(title,fromTitle,{
openLinkFromInsideRiver: this.getAttribute("openLinkFromInsideRiver","top"),
openLinkFromOutsideRiver: this.getAttribute("openLinkFromOutsideRiver","top")
});
Expand All @@ -136,7 +141,7 @@ title: a title string or an array of title strings
fromPageRect: page coordinates of the origin of the navigation
*/
NavigatorWidget.prototype.addToHistory = function(title,fromPageRect) {
this.wiki.addToHistory(title,fromPageRect,this.historyTitle);
this.story.addToHistory(title,fromPageRect,this.historyTitle);
};

/*
Expand Down Expand Up @@ -273,7 +278,9 @@ NavigatorWidget.prototype.makeDraftTiddler = function(targetTitle) {
var tiddler = this.wiki.getTiddler(targetTitle);
// Save the initial value of the draft tiddler
draftTitle = this.generateDraftTitle(targetTitle);
var draftTiddler = new $tw.Tiddler(
var draftTiddler = new $tw.Tiddler({
text: "",
},
tiddler,
{
title: draftTitle,
Expand Down Expand Up @@ -320,12 +327,11 @@ NavigatorWidget.prototype.handleSaveTiddlerEvent = function(event) {
"draft.title": undefined,
"draft.of": undefined
},this.wiki.getModificationFields());
newTiddler = $tw.hooks.invokeHook("th-saving-tiddler",newTiddler);
newTiddler = $tw.hooks.invokeHook("th-saving-tiddler",newTiddler,tiddler);
this.wiki.addTiddler(newTiddler);
// If enabled, relink references to renamed tiddler
var shouldRelink = this.getAttribute("relinkOnRename","no").toLowerCase().trim() === "yes";
if(isRename && shouldRelink && this.wiki.tiddlerExists(draftOf)) {
console.log("Relinking '" + draftOf + "' to '" + draftTitle + "'");
this.wiki.relinkTiddler(draftOf,draftTitle);
}
// Remove the draft tiddler
Expand Down Expand Up @@ -494,10 +500,11 @@ NavigatorWidget.prototype.handleImportTiddlersEvent = function(event) {
} catch(e) {
}
// Get the current $:/Import tiddler
var importTiddler = this.wiki.getTiddler(IMPORT_TITLE),
importData = this.wiki.getTiddlerData(IMPORT_TITLE,{}),
var importTitle = event.importTitle ? event.importTitle : IMPORT_TITLE,
importTiddler = this.wiki.getTiddler(importTitle),
importData = this.wiki.getTiddlerData(importTitle,{}),
newFields = new Object({
title: IMPORT_TITLE,
title: importTitle,
type: "application/json",
"plugin-type": "import",
"status": "pending"
Expand All @@ -522,21 +529,23 @@ NavigatorWidget.prototype.handleImportTiddlersEvent = function(event) {
$tw.utils.each(importData.tiddlers,function(tiddler,title) {
if($tw.utils.count(tiddler) === 0) {
newFields["selection-" + title] = "unchecked";
newFields["suppressed-" + title] = "yes";
}
});
// Save the $:/Import tiddler
newFields.text = JSON.stringify(importData,null,$tw.config.preferences.jsonSpaces);
this.wiki.addTiddler(new $tw.Tiddler(importTiddler,newFields));
// Update the story and history details
if(this.getVariable("tv-auto-open-on-import") !== "no") {
var autoOpenOnImport = event.autoOpenOnImport ? event.autoOpenOnImport : this.getVariable("tv-auto-open-on-import");
if(autoOpenOnImport !== "no") {
var storyList = this.getStoryList(),
history = [];
// Add it to the story
if(storyList && storyList.indexOf(IMPORT_TITLE) === -1) {
storyList.unshift(IMPORT_TITLE);
if(storyList && storyList.indexOf(importTitle) === -1) {
storyList.unshift(importTitle);
}
// And to history
history.push(IMPORT_TITLE);
history.push(importTitle);
// Save the updated story and history
this.saveStoryList(storyList);
this.addToHistory(history);
Expand All @@ -555,10 +564,14 @@ NavigatorWidget.prototype.handlePerformImportEvent = function(event) {
$tw.utils.each(importData.tiddlers,function(tiddlerFields) {
var title = tiddlerFields.title;
if(title && importTiddler && importTiddler.fields["selection-" + title] !== "unchecked") {
var tiddler = new $tw.Tiddler(tiddlerFields);
if($tw.utils.hop(importTiddler.fields,["rename-" + title])) {
var tiddler = new $tw.Tiddler(tiddlerFields,{title : importTiddler.fields["rename-" + title]});
} else {
var tiddler = new $tw.Tiddler(tiddlerFields);
}
tiddler = $tw.hooks.invokeHook("th-importing-tiddler",tiddler);
self.wiki.addTiddler(tiddler);
importReport.push("# [[" + tiddlerFields.title + "]]");
importReport.push("# [[" + tiddler.fields.title + "]]");
}
});
// Replace the $:/Import tiddler with an import report
Expand Down Expand Up @@ -609,10 +622,13 @@ NavigatorWidget.prototype.handleUnfoldAllTiddlersEvent = function(event) {
};

NavigatorWidget.prototype.handleRenameTiddlerEvent = function(event) {
var paramObject = event.paramObject || {},
var options = {},
paramObject = event.paramObject || {},
from = paramObject.from || event.tiddlerTitle,
to = paramObject.to;
this.wiki.renameTiddler(from,to);
options.dontRenameInTags = (paramObject.renameInTags === "false" || paramObject.renameInTags === "no") ? true : false;
options.dontRenameInLists = (paramObject.renameInLists === "false" || paramObject.renameInLists === "no") ? true : false;
this.wiki.renameTiddler(from,to,options);
};

exports.navigator = NavigatorWidget;
Expand Down
23 changes: 13 additions & 10 deletions core/modules/widgets/radio.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ Set a field or index at a given tiddler via radio buttons
"use strict";

var Widget = require("$:/core/modules/widgets/widget.js").widget;

var RadioWidget = function(parseTreeNode,options) {
this.initialise(parseTreeNode,options);
};
Expand All @@ -37,13 +36,16 @@ RadioWidget.prototype.render = function(parent,nextSibling) {
// Create our elements
this.labelDomNode = this.document.createElement("label");
this.labelDomNode.setAttribute("class",
"tc-radio " + this.radioClass + (isChecked ? " tc-radio-selected" : "")
);
"tc-radio " + this.radioClass + (isChecked ? " tc-radio-selected" : "")
);
this.inputDomNode = this.document.createElement("input");
this.inputDomNode.setAttribute("type","radio");
if(isChecked) {
this.inputDomNode.setAttribute("checked","true");
}
if(this.isDisabled === "yes") {
this.inputDomNode.setAttribute("disabled",true);
}
this.labelDomNode.appendChild(this.inputDomNode);
this.spanDomNode = this.document.createElement("span");
this.labelDomNode.appendChild(this.spanDomNode);
Expand Down Expand Up @@ -83,6 +85,10 @@ RadioWidget.prototype.handleChangeEvent = function(event) {
if(this.inputDomNode.checked) {
this.setValue();
}
// Trigger actions
if(this.radioActions) {
this.invokeActionString(this.radioActions,this,event,{"actionValue": this.radioValue});
}
};

/*
Expand All @@ -95,6 +101,8 @@ RadioWidget.prototype.execute = function() {
this.radioIndex = this.getAttribute("index");
this.radioValue = this.getAttribute("value");
this.radioClass = this.getAttribute("class","");
this.isDisabled = this.getAttribute("disabled","no");
this.radioActions = this.getAttribute("actions","");
// Make the child widgets
this.makeChildWidgets();
};
Expand All @@ -104,16 +112,11 @@ Selectively refreshes the widget if needed. Returns true if the widget or any of
*/
RadioWidget.prototype.refresh = function(changedTiddlers) {
var changedAttributes = this.computeAttributes();
if(changedAttributes.tiddler || changedAttributes.field || changedAttributes.index || changedAttributes.value || changedAttributes["class"]) {
if(($tw.utils.count(changedAttributes) > 0) || changedTiddlers[this.radioTitle]) {
this.refreshSelf();
return true;
} else {
var refreshed = false;
if(changedTiddlers[this.radioTitle]) {
this.inputDomNode.checked = this.getValue() === this.radioValue;
refreshed = true;
}
return this.refreshChildren(changedTiddlers) || refreshed;
return this.refreshChildren(changedTiddlers);
}
};

Expand Down
88 changes: 78 additions & 10 deletions core/modules/widgets/range.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,16 @@ RangeWidget.prototype.render = function(parent,nextSibling) {
if(this.increment){
this.inputDomNode.setAttribute("step", this.increment);
}
if(this.isDisabled === "yes") {
this.inputDomNode.setAttribute("disabled",true);
}
this.inputDomNode.value = this.getValue();
// Add a click event handler
$tw.utils.addEventListeners(this.inputDomNode,[
{name: "input", handlerObject: this, handlerMethod: "handleInputEvent"},
{name: "change", handlerObject: this, handlerMethod: "handleInputEvent"}
{name:"mousedown", handlerObject:this, handlerMethod:"handleMouseDownEvent"},
{name:"mouseup", handlerObject:this, handlerMethod:"handleMouseUpEvent"},
{name:"change", handlerObject:this, handlerMethod:"handleChangeEvent"},
{name:"input", handlerObject:this, handlerMethod:"handleInputEvent"},
]);
// Insert the label into the DOM and render any children
parent.insertBefore(this.inputDomNode,nextSibling);
Expand All @@ -59,23 +64,77 @@ RangeWidget.prototype.render = function(parent,nextSibling) {

RangeWidget.prototype.getValue = function() {
var tiddler = this.wiki.getTiddler(this.tiddlerTitle),
fieldName = this.tiddlerField || "text",
value = this.defaultValue;
fieldName = this.tiddlerField,
value = this.defaultValue;
if(tiddler) {
if(this.tiddlerIndex) {
value = this.wiki.extractTiddlerDataItem(tiddler,this.tiddlerIndex,this.defaultValue || "");
value = this.wiki.extractTiddlerDataItem(tiddler,this.tiddlerIndex,this.defaultValue);
} else {
if($tw.utils.hop(tiddler.fields,fieldName)) {
value = tiddler.fields[fieldName] || "";
} else {
value = this.defaultValue || "";
value = this.defaultValue;
}
}
}
return value;
};

RangeWidget.prototype.getActionVariables = function(options) {
options = options || {};
var hasChanged = (this.startValue !== this.inputDomNode.value) ? "yes" : "no";
// Trigger actions. Use variables = {key:value, key:value ...}
// the "value" is needed.
return $tw.utils.extend({"actionValue": this.inputDomNode.value, "actionValueHasChanged": hasChanged}, options);
}

// actionsStart
RangeWidget.prototype.handleMouseDownEvent = function(event) {
this.mouseDown = true; // TODO remove once IE is gone.
this.startValue = this.inputDomNode.value; // TODO remove this line once IE is gone!
this.handleEvent(event);
// Trigger actions
if(this.actionsMouseDown) {
var variables = this.getActionVariables() // TODO this line will go into the function call below.
this.invokeActionString(this.actionsMouseDown,this,event,variables);
}
}

// actionsStop
RangeWidget.prototype.handleMouseUpEvent = function(event) {
this.mouseDown = false; // TODO remove once IE is gone.
this.handleEvent(event);
// Trigger actions
if(this.actionsMouseUp) {
var variables = this.getActionVariables()
this.invokeActionString(this.actionsMouseUp,this,event,variables);
}
// TODO remove the following if() once IE is gone!
if ($tw.browser.isIE) {
if (this.startValue !== this.inputDomNode.value) {
this.handleChangeEvent(event);
this.startValue = this.inputDomNode.value;
}
}
}

RangeWidget.prototype.handleChangeEvent = function(event) {
if (this.mouseDown) { // TODO refactor this function once IE is gone.
this.handleInputEvent(event);
}
};

RangeWidget.prototype.handleInputEvent = function(event) {
this.handleEvent(event);
// Trigger actions
if(this.actionsInput) {
// "tiddler" parameter may be missing. See .execute() below
var variables = this.getActionVariables({"actionValueHasChanged": "yes"}) // TODO this line will go into the function call below.
this.invokeActionString(this.actionsInput,this,event,variables);
}
};

RangeWidget.prototype.handleEvent = function(event) {
if(this.getValue() !== this.inputDomNode.value) {
if(this.tiddlerIndex) {
this.wiki.setText(this.tiddlerTitle,"",this.tiddlerIndex,this.inputDomNode.value);
Expand All @@ -89,15 +148,24 @@ RangeWidget.prototype.handleInputEvent = function(event) {
Compute the internal state of the widget
*/
RangeWidget.prototype.execute = function() {
// TODO remove the next 1 lines once IE is gone!
this.mouseUp = true; // Needed for IE10
// Get the parameters from the attributes
this.tiddlerTitle = this.getAttribute("tiddler",this.getVariable("currentTiddler"));
this.tiddlerField = this.getAttribute("field");
this.tiddlerField = this.getAttribute("field","text");
this.tiddlerIndex = this.getAttribute("index");
this.minValue = this.getAttribute("min");
this.maxValue = this.getAttribute("max");
this.increment = this.getAttribute("increment");
this.defaultValue = this.getAttribute("default");
this.defaultValue = this.getAttribute("default","");
this.elementClass = this.getAttribute("class","");
this.isDisabled = this.getAttribute("disabled","no");
// Actions since 5.1.23
// Next 2 only fire once!
this.actionsMouseDown = this.getAttribute("actionsStart","");
this.actionsMouseUp = this.getAttribute("actionsStop","");
// Input fires very often!
this.actionsInput = this.getAttribute("actions","");
// Make the child widgets
this.makeChildWidgets();
};
Expand All @@ -107,15 +175,15 @@ Selectively refreshes the widget if needed. Returns true if the widget or any of
*/
RangeWidget.prototype.refresh = function(changedTiddlers) {
var changedAttributes = this.computeAttributes();
if(changedAttributes.tiddler || changedAttributes.field || changedAttributes.index || changedAttributes['min'] || changedAttributes['max'] || changedAttributes['increment'] || changedAttributes["default"] || changedAttributes["class"]) {
if($tw.utils.count(changedAttributes) > 0) {
this.refreshSelf();
return true;
} else {
var refreshed = false;
if(changedTiddlers[this.tiddlerTitle]) {
var value = this.getValue();
if(this.inputDomNode.value !== value) {
this.inputDomNode.value = value;
this.inputDomNode.value = value;
}
refreshed = true;
}
Expand Down
30 changes: 26 additions & 4 deletions core/modules/widgets/reveal.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,8 @@ RevealWidget.prototype.render = function(parent,nextSibling) {
tag = this.revealTag;
}
var domNode = this.document.createElement(tag);
var classes = this["class"].split(" ") || [];
classes.push("tc-reveal");
domNode.className = classes.join(" ");
this.domNode = domNode;
this.assignDomNodeClasses();
if(this.style) {
domNode.setAttribute("style",this.style);
}
Expand Down Expand Up @@ -70,6 +69,10 @@ RevealWidget.prototype.positionPopup = function(domNode) {
left = this.popup.left + this.popup.width;
top = this.popup.top + this.popup.height - domNode.offsetHeight;
break;
case "belowright":
left = this.popup.left + this.popup.width;
top = this.popup.top + this.popup.height;
break;
case "right":
left = this.popup.left + this.popup.width;
top = this.popup.top;
Expand All @@ -78,6 +81,10 @@ RevealWidget.prototype.positionPopup = function(domNode) {
left = this.popup.left + this.popup.width - domNode.offsetWidth;
top = this.popup.top + this.popup.height;
break;
case "aboveleft":
left = this.popup.left - domNode.offsetWidth;
top = this.popup.top - domNode.offsetHeight;
break;
default: // Below
left = this.popup.left;
top = this.popup.top + this.popup.height;
Expand All @@ -102,13 +109,14 @@ RevealWidget.prototype.execute = function() {
this.text = this.getAttribute("text");
this.position = this.getAttribute("position");
this.positionAllowNegative = this.getAttribute("positionAllowNegative") === "yes";
this["class"] = this.getAttribute("class","");
// class attribute handled in assignDomNodeClasses()
this.style = this.getAttribute("style","");
this["default"] = this.getAttribute("default","");
this.animate = this.getAttribute("animate","no");
this.retain = this.getAttribute("retain","no");
this.openAnimation = this.animate === "no" ? undefined : "open";
this.closeAnimation = this.animate === "no" ? undefined : "close";
this.updatePopupPosition = this.getAttribute("updatePopupPosition","no") === "yes";
// Compute the title of the state tiddler and read it
this.stateTiddlerTitle = this.state;
this.stateTitle = this.getAttribute("stateTitle");
Expand Down Expand Up @@ -194,6 +202,12 @@ RevealWidget.prototype.readPopupState = function(state) {
}
};

RevealWidget.prototype.assignDomNodeClasses = function() {
var classes = this.getAttribute("class","").split(" ");
classes.push("tc-reveal");
this.domNode.className = classes.join(" ");
};

/*
Selectively refreshes the widget if needed. Returns true if the widget or any of its children needed re-rendering
*/
Expand All @@ -212,7 +226,15 @@ RevealWidget.prototype.refresh = function(changedTiddlers) {
this.refreshSelf();
return true;
}
} else if(this.type === "popup" && this.updatePopupPosition && (changedTiddlers[this.state] || changedTiddlers[this.stateTitle])) {
this.positionPopup(this.domNode);
}
if(changedAttributes.style) {
this.domNode.style = this.getAttribute("style","");
}
if(changedAttributes["class"]) {
this.assignDomNodeClasses();
}
return this.refreshChildren(changedTiddlers);
}
};
Expand Down
19 changes: 16 additions & 3 deletions core/modules/widgets/scrollable.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,20 @@ ScrollableWidget.prototype.handleScrollEvent = function(event) {
if(this.outerDomNode.scrollWidth <= this.outerDomNode.offsetWidth && this.outerDomNode.scrollHeight <= this.outerDomNode.offsetHeight && this.fallthrough === "yes") {
return true;
}
this.scrollIntoView(event.target);
if(event.paramObject && event.paramObject.selector) {
this.scrollSelectorIntoView(null,event.paramObject.selector);
} else {
this.scrollIntoView(event.target);
}
return false; // Handled event
};

/*
Scroll an element into view
*/
ScrollableWidget.prototype.scrollIntoView = function(element) {
var duration = $tw.utils.getAnimationDuration();
var duration = $tw.utils.getAnimationDuration(),
srcWindow = element ? element.ownerDocument.defaultView : window;
this.cancelScroll();
this.startTime = Date.now();
var scrollPosition = {
Expand Down Expand Up @@ -122,13 +127,21 @@ ScrollableWidget.prototype.scrollIntoView = function(element) {
self.outerDomNode.scrollLeft = scrollPosition.x + (endX - scrollPosition.x) * t;
self.outerDomNode.scrollTop = scrollPosition.y + (endY - scrollPosition.y) * t;
if(t < 1) {
self.idRequestFrame = self.requestAnimationFrame.call(window,drawFrame);
self.idRequestFrame = self.requestAnimationFrame.call(srcWindow,drawFrame);
}
};
drawFrame();
}
};

ScrollableWidget.prototype.scrollSelectorIntoView = function(baseElement,selector,callback) {
baseElement = baseElement || document.body;
var element = baseElement.querySelector(selector);
if(element) {
this.scrollIntoView(element,callback);
}
};

/*
Render this widget into the DOM
*/
Expand Down
5 changes: 4 additions & 1 deletion core/modules/widgets/transclude.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ TranscludeWidget.prototype.execute = function() {
this.transcludeField = this.getAttribute("field");
this.transcludeIndex = this.getAttribute("index");
this.transcludeMode = this.getAttribute("mode");
this.recursionMarker = this.getAttribute("recursionMarker","yes");
// Parse the text reference
var parseAsInline = !this.parseTreeNode.isBlock;
if(this.transcludeMode === "inline") {
Expand All @@ -61,7 +62,9 @@ TranscludeWidget.prototype.execute = function() {
parseTreeNodes = parser ? parser.tree : this.parseTreeNode.children;
// Set context variables for recursion detection
var recursionMarker = this.makeRecursionMarker();
this.setVariable("transclusion",recursionMarker);
if(this.recursionMarker === "yes") {
this.setVariable("transclusion",recursionMarker);
}
// Check for recursion
if(parser) {
if(this.parentWidget && this.parentWidget.hasVariable("transclusion",recursionMarker)) {
Expand Down
18 changes: 16 additions & 2 deletions core/modules/widgets/widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ Widget.prototype.getVariableInfo = function(name,options) {
// Check for the variable defined in the parent widget (or an ancestor in the prototype chain)
if(parentWidget && name in parentWidget.variables) {
var variable = parentWidget.variables[name],
value = variable.value,
originalValue = variable.value,
value = originalValue,
params = this.resolveVariableParameters(variable.params,actualParams);
// Substitute any parameters specified in the definition
$tw.utils.each(params,function(param) {
Expand All @@ -125,7 +126,9 @@ Widget.prototype.getVariableInfo = function(name,options) {
}
return {
text: value,
params: params
params: params,
srcVariable: variable,
isCacheable: originalValue === value
};
}
// If the variable doesn't exist in the parent widget then look for a macro module
Expand Down Expand Up @@ -421,6 +424,7 @@ Widget.prototype.addEventListener = function(type,handler) {
Dispatch an event to a widget. If the widget doesn't handle the event then it is also dispatched to the parent widget
*/
Widget.prototype.dispatchEvent = function(event) {
event.widget = event.widget || this;
// Dispatch the event if this widget handles it
var listener = this.eventListeners[event.type];
if(listener) {
Expand Down Expand Up @@ -570,6 +574,16 @@ Widget.prototype.invokeActionString = function(actions,triggeringWidget,event,va
return widgetNode.invokeActions(this,event);
};

/*
Execute action tiddlers by tag
*/
Widget.prototype.invokeActionsByTag = function(tag,event,variables) {
var self = this;
$tw.utils.each(self.wiki.filterTiddlers("[all[shadows+tiddlers]tag[" + tag + "]!has[draft.of]]"),function(title) {
self.invokeActionString(self.wiki.getTiddlerText(title),self,event,variables);
});
};

Widget.prototype.allowActionPropagation = function() {
return true;
};
Expand Down
49 changes: 42 additions & 7 deletions core/modules/wiki.js
Original file line number Diff line number Diff line change
Expand Up @@ -378,10 +378,10 @@ exports.sortTiddlers = function(titles,sortField,isDescending,isCaseSensitive,is
y = Number(b);
if(isNumeric && (!isNaN(x) || !isNaN(y))) {
return compareNumbers(x,y);
} else if(isAlphaNumeric) {
return isDescending ? b.localeCompare(a,undefined,{numeric: true,sensitivity: "base"}) : a.localeCompare(b,undefined,{numeric: true,sensitivity: "base"});
} else if($tw.utils.isDate(a) && $tw.utils.isDate(b)) {
return isDescending ? b - a : a - b;
} else if(isAlphaNumeric) {
return isDescending ? b.localeCompare(a,undefined,{numeric: true,sensitivity: "base"}) : a.localeCompare(b,undefined,{numeric: true,sensitivity: "base"});
} else {
a = String(a);
b = String(b);
Expand Down Expand Up @@ -1004,6 +1004,7 @@ title: target tiddler title
options: as for wiki.makeWidget() plus:
options.field: optional field to transclude (defaults to "text")
options.mode: transclusion mode "inline" or "block"
options.recursionMarker : optional flag to set a recursion marker, defaults to "yes"
options.children: optional array of children for the transclude widget
options.importVariables: optional importvariables filter string for macros to be included
options.importPageMacros: optional boolean; if true, equivalent to passing "[[$:/core/ui/PageMacros]] [all[shadows+tiddlers]tag[$:/tags/Macro]!has[draft.of]]" to options.importVariables
Expand All @@ -1027,10 +1028,17 @@ exports.makeTranscludeWidget = function(title,options) {
parseTreeTransclude = {
type: "transclude",
attributes: {
recursionMarker: {
name: "recursionMarker",
type: "string",
value: options.recursionMarker || "yes"
},
tiddler: {
name: "tiddler",
type: "string",
value: title}},
value: title
}
},
isBlock: !options.parseAsInline};
if(options.importVariables || options.importPageMacros) {
if(options.importVariables) {
Expand All @@ -1052,7 +1060,7 @@ exports.makeTranscludeWidget = function(title,options) {
if(options.children) {
parseTreeTransclude.children = options.children;
}
return $tw.wiki.makeWidget(parseTreeDiv,options);
return this.makeWidget(parseTreeDiv,options);
};

/*
Expand Down Expand Up @@ -1362,7 +1370,7 @@ exports.readFileContent = function(file,type,isBinary,deserializer,callback) {
// Onload
reader.onload = function(event) {
var text = event.target.result,
tiddlerFields = {title: file.name || "Untitled", type: type};
tiddlerFields = {title: file.name || "Untitled"};
if(isBinary) {
var commaPos = text.indexOf(",");
if(commaPos !== -1) {
Expand Down Expand Up @@ -1426,7 +1434,8 @@ historyTitle: title of history tiddler (defaults to $:/HistoryList)
*/
exports.addToHistory = function(title,fromPageRect,historyTitle) {
var story = new $tw.Story({wiki: this, historyTitle: historyTitle});
story.addToHistory(title,fromPageRect);
story.addToHistory(title,fromPageRect);
console.log("$tw.wiki.addToHistory() is deprecated since V5.1.23! Use the this.story.addToHistory() from the story-object!")
};

/*
Expand All @@ -1438,7 +1447,8 @@ options: see story.js
*/
exports.addToStory = function(title,fromTitle,storyTitle,options) {
var story = new $tw.Story({wiki: this, storyTitle: storyTitle});
story.addToStory(title,fromTitle,options);
story.addToStory(title,fromTitle,options);
console.log("$tw.wiki.addToStory() is deprecated since V5.1.23! Use the this.story.addToStory() from the story-object!")
};

/*
Expand Down Expand Up @@ -1503,5 +1513,30 @@ exports.doesPluginInfoRequireReload = function(pluginInfo) {
}
};

exports.slugify = function(title,options) {
var tiddler = this.getTiddler(title),
slug;
if(tiddler && tiddler.fields.slug) {
slug = tiddler.fields.slug;
} else {
slug = $tw.utils.transliterate(title.toString().toLowerCase()) // Replace diacritics with basic lowercase ASCII
.replace(/\s+/g,"-") // Replace spaces with -
.replace(/[^\w\-\.]+/g,"") // Remove all non-word chars except dash and dot
.replace(/\-\-+/g,"-") // Replace multiple - with single -
.replace(/^-+/,"") // Trim - from start of text
.replace(/-+$/,""); // Trim - from end of text
}
// If the resulting slug is blank (eg because the title is just punctuation characters)
if(!slug) {
// ...then just use the character codes of the title
var result = [];
$tw.utils.each(title.split(""),function(char) {
result.push(char.charCodeAt(0).toString());
});
slug = result.join("-");
}
return slug;
};

})();

129 changes: 129 additions & 0 deletions core/palettes/CupertinoDark.tid
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
title: $:/palettes/CupertinoDark
tags: $:/tags/Palette
name: Cupertino Dark
description: A macOS inspired dark palette
type: application/x-tiddler-dictionary

alert-background: #FF453A
alert-border: #FF453A
alert-highlight: #FFD60A
alert-muted-foreground: <<colour muted-foreground>>
background: #282828
blockquote-bar: <<colour page-background>>
button-foreground: <<colour background>>
code-background: <<colour pre-background>>
code-border: <<colour pre-border>>
code-foreground: rgba(255, 255, 255, 0.54)
dirty-indicator: #FF453A
download-background: <<colour primary>>
download-foreground: <<colour foreground>>
dragger-background: <<colour foreground>>
dragger-foreground: <<colour background>>
dropdown-background: <<colour tiddler-info-background>>
dropdown-border: <<colour dropdown-background>>
dropdown-tab-background-selected: #3F638B
dropdown-tab-background: #323232
dropzone-background: #30D158
external-link-background-hover: transparent
external-link-background-visited: transparent
external-link-background: transparent
external-link-foreground-hover:
external-link-foreground-visited: #BF5AF2
external-link-foreground: #32D74B
foreground: #FFFFFF
menubar-background: #464646
menubar-foreground: #ffffff
message-background: <<colour background>>
message-border: <<colour very-muted-foreground>>
message-foreground: rgba(255, 255, 255, 0.54)
modal-backdrop: <<colour page-background>>
modal-background: <<colour background>>
modal-border: <<colour very-muted-foreground>>
modal-footer-background: <<colour background>>
modal-footer-border: <<colour background>>
modal-header-border: <<colour very-muted-foreground>>
muted-foreground: #98989D
notification-background: <<colour dropdown-background>>
notification-border: <<colour dropdown-background>>
page-background: #323232
pre-background: #464646
pre-border: transparent
primary: #0A84FF
select-tag-background: <<colour background>>
select-tag-foreground: <<colour foreground>>
sidebar-button-foreground: <<colour background>>
sidebar-controls-foreground-hover: #FF9F0A
sidebar-controls-foreground: #8E8E93
sidebar-foreground-shadow: transparent
sidebar-foreground: rgba(255, 255, 255, 0.54)
sidebar-muted-foreground-hover: rgba(255, 255, 255, 0.54)
sidebar-muted-foreground: rgba(255, 255, 255, 0.38)
sidebar-tab-background-selected: #3F638B
sidebar-tab-background: <<colour background>>
sidebar-tab-border-selected: <<colour background>>
sidebar-tab-border: <<colour background>>
sidebar-tab-divider: <<colour background>>
sidebar-tab-foreground-selected: rgba(255, 255, 255, 0.87)
sidebar-tab-foreground: rgba(255, 255, 255, 0.54)
sidebar-tiddler-link-foreground-hover: rgba(255, 255, 255, 0.7)
sidebar-tiddler-link-foreground: rgba(255, 255, 255, 0.54)
site-title-foreground: #ffffff
static-alert-foreground: #B4B4B4
tab-background-selected: #3F638B
tab-background: <<colour page-background>>
tab-border-selected: <<colour page-background>>
tab-border: <<colour page-background>>
tab-divider: <<colour page-background>>
tab-foreground-selected: rgba(255, 255, 255, 0.87)
tab-foreground: rgba(255, 255, 255, 0.54)
table-border: #464646
table-footer-background: <<colour tiddler-editor-fields-odd>>
table-header-background: <<colour tiddler-editor-fields-even>>
tag-background: #48484A
tag-foreground: #323232
tiddler-background: <<colour background>>
tiddler-border: transparent
tiddler-controls-foreground-hover: <<colour sidebar-controls-foreground-hover>>
tiddler-controls-foreground-selected: <<colour sidebar-controls-foreground-hover>>
tiddler-controls-foreground: #48484A
tiddler-editor-background: transparent
tiddler-editor-border-image:
tiddler-editor-border: rgba(255, 255, 255, 0.08)
tiddler-editor-fields-even: rgba(255, 255, 255, 0.1)
tiddler-editor-fields-odd: rgba(255, 255, 255, 0.04)
tiddler-info-background: #1E1E1E
tiddler-info-border: #1E1E1E
tiddler-info-tab-background: #3F638B
tiddler-link-background: <<colour background>>
tiddler-link-foreground: <<colour primary>>
tiddler-subtitle-foreground: <<colour muted-foreground>>
tiddler-title-foreground: #FFFFFF
toolbar-new-button:
toolbar-options-button:
toolbar-save-button:
toolbar-info-button:
toolbar-edit-button:
toolbar-close-button:
toolbar-delete-button:
toolbar-cancel-button:
toolbar-done-button:
untagged-background: <<colour very-muted-foreground>>
very-muted-foreground: #464646
selection-background: #3F638B
selection-foreground: #ffffff
wikilist-background: <<colour page-background>>
wikilist-button-background: #3F638B
wikilist-button-foreground: <<colour foreground>>
wikilist-button-open: #32D74B
wikilist-button-open-hover: #32D74B
wikilist-button-reveal: #0A84FF
wikilist-button-reveal-hover: #0A84FF
wikilist-button-remove: #FF453A
wikilist-button-remove-hover: #FF453A
wikilist-droplink-dragover: #32D74B
wikilist-item: <<colour background>>
wikilist-toolbar-background: <<colour background>>
wikilist-title: <<colour foreground>>
wikilist-title-svg: <<colour foreground>>
wikilist-toolbar-foreground: <<colour foreground>>
wikilist-url: <<colour muted-foreground>>
Loading