mirror of
https://github.com/Jermolene/TiddlyWiki5.git
synced 2026-01-21 12:02:56 -08:00
* refactor: extract a new $tw.wiki.getParser
* feat: allow $tw.utils.getParseTreeText to render other rules' text
* feat: two example getText handler
* Revert "feat: allow $tw.utils.getParseTreeText to render other rules' text"
This reverts commit 8a12498fa9.
* refactor: keep original getParseTreeText not touched
* refactor: use serialize in rules
* refactor: $tw.utils.extend({},options) -> options || {}
* Update codeinline.js
* Create test-wikitext-serialize.js
* DEBUG: only run my tests for development, remove before PR merge
* lint: if
* feat: add rule: 'parseBlock' metadata
* feat: handle tailing \n that may be missing
* feat: allow recursive
* feat: generate more rule and tests
* feat: generate more rule and tests
* fix: remove pragma:true, otherwise following text will become children of it
* fix: condition manually
Deekseek is silly
* fix: some test
* fix: some test
* feat: $tw.utils.serializeAttribute
* fix: use "" for string param
* feat: list
* refactor: ' -> "
* fix: parsemode don't have node
* fix: render invisible comment and parsemode as data element
* feat: add void: true, in ast node to prevent render
* feat: use void widget, so methods always return a widget
* feat: ast to use new widget type void
* test: add rule: 'parseBlock' and isRuleEnd: true
* lint: quote
* Update widget.js
* fix: void node need to handle its children
* Update test-wikitext-parser.js
* lint: quote
* Update void.js
* Update test-wikitext-parser.js
* fix: macrodef with comment (void node) not working
* lint: ' -> "
* feat: add to styleblock
* feat: styleblock
* feat: styleinline
* Update table.js
* lint: useless comments
* feat: transcludeblock
* refactor: reuse block on inline when possible
* feat: use void node to carry important info for typedblock
* feat: run all tests
* lint: useless ai generated comments
* Update conditional.js to not include space
* Update test-wikitext-serialize.js
* Update conditional.js
* refactor: move tiddlers to /data
* refactor: no need for new $tw.Wiki()
* lint: double quote
* refactor: lowercase the parseblock rule name
* fix: Wiki parser initialize blockRuleClasses only when first new an instance
* feat: restore inline macro def
* fix: macro in widget param
* fix: positional attribute in macro call
* fix: table space and horizrule block new line
* feat: make sure block rule all have \n\n for visiblity
* lint: function param
* fix: empty list item
* feat: add \n\n based on isBlock, if could also be inline
* fix: conditional without elseif
* refactor: use isBlock in macrodef to know inline or block
* fix: link may not have attribute and children
* DEBUG: render result and diff below body only on browser
DEBUG: render result below body only on browser
DEBUG: render result below body
DEBUG: fix build
DEBUG: show render result as ViewTemplate
* fix: remove pad space in />
* test: remove pad space in />
* Revert DEBUG: render result and diff below body only on browser
* refactor: fold commentText variable
* refactor: fold long comment
* fix: double quotes for parameter values
* Update void.js
* refactor: move all exports.serialize = function(tree,serialize) { to plugin
* fix: expost listTypes from core, and require it in plugin
* refactor: move serializeWikitextParseTree to plugin and init it
* refactor: move serializeAttribute util also to the plugin
* fix: Delete unused file
* Update macrodef.js
* Update test-wikitext-parser.js
* lint: fix
* Update plugins/tiddlywiki/wikitext-serialize/rules/filteredtranscludeblock.js
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* Update core/modules/widgets/void.js
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* Update plugins/tiddlywiki/wikitext-serialize/rules/list.js
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* Update plugins/tiddlywiki/wikitext-serialize/rules/list.js
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* Update plugins/tiddlywiki/wikitext-serialize/rules/styleblock.js
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* Remove unused methods from VoidNodeWidget
Deleted render, execute, and refresh methods from VoidNodeWidget as they are no longer needed. The widget now only inherits from the base Widget class and exports the constructor.
* docs: about regex in styleinline.js
* Update parsetree.js
* Update core/modules/widgets/void.js
Co-authored-by: Jeremy Ruston <jeremy@jermolene.com>
* feat: Ensure at least one space after the style/class
---------
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Jeremy Ruston <jeremy@jermolene.com>
132 lines
4.4 KiB
JavaScript
132 lines
4.4 KiB
JavaScript
/*\
|
|
title: $:/core/modules/widgets/importvariables.js
|
|
type: application/javascript
|
|
module-type: widget
|
|
|
|
Import variable definitions from other tiddlers
|
|
|
|
\*/
|
|
|
|
"use strict";
|
|
|
|
var Widget = require("$:/core/modules/widgets/widget.js").widget;
|
|
|
|
var ImportVariablesWidget = function(parseTreeNode,options) {
|
|
this.initialise(parseTreeNode,options);
|
|
};
|
|
|
|
/*
|
|
Inherit from the base widget class
|
|
*/
|
|
ImportVariablesWidget.prototype = new Widget();
|
|
|
|
/*
|
|
Render this widget into the DOM
|
|
*/
|
|
ImportVariablesWidget.prototype.render = function(parent,nextSibling) {
|
|
this.parentDomNode = parent;
|
|
this.computeAttributes();
|
|
this.execute();
|
|
this.renderChildren(parent,nextSibling);
|
|
};
|
|
|
|
/*
|
|
Compute the internal state of the widget
|
|
*/
|
|
ImportVariablesWidget.prototype.execute = function(tiddlerList) {
|
|
var widgetPointer = this;
|
|
// Got to flush all the accumulated variables
|
|
this.variables = Object.create(null);
|
|
if(this.parentWidget) {
|
|
Object.setPrototypeOf(this.variables,this.parentWidget.variables);
|
|
}
|
|
// Get our parameters
|
|
this.filter = this.getAttribute("filter");
|
|
// Compute the filter
|
|
this.tiddlerList = tiddlerList || this.wiki.filterTiddlers(this.filter,this);
|
|
// Accumulate the <$set> widgets from each tiddler
|
|
$tw.utils.each(this.tiddlerList,function(title) {
|
|
var parser = widgetPointer.wiki.parseTiddler(title,{parseAsInline:true, configTrimWhiteSpace:false});
|
|
if(parser) {
|
|
var parseTreeNode = parser.tree[0];
|
|
// process AST nodes generated by pragma rules.
|
|
while(parseTreeNode && ["setvariable","set","parameters","void"].indexOf(parseTreeNode.type) !== -1) {
|
|
var node = {
|
|
type: "set",
|
|
attributes: parseTreeNode.attributes,
|
|
params: parseTreeNode.params,
|
|
isMacroDefinition: parseTreeNode.isMacroDefinition,
|
|
isFunctionDefinition: parseTreeNode.isFunctionDefinition,
|
|
isProcedureDefinition: parseTreeNode.isProcedureDefinition,
|
|
isWidgetDefinition: parseTreeNode.isWidgetDefinition,
|
|
configTrimWhiteSpace: parseTreeNode.configTrimWhiteSpace
|
|
};
|
|
if(parseTreeNode.type === "set" || parseTreeNode.type === "setvariable") {
|
|
if(parseTreeNode.isMacroDefinition || parseTreeNode.isProcedureDefinition || parseTreeNode.isWidgetDefinition || parseTreeNode.isFunctionDefinition) {
|
|
// Macro definitions can be folded into
|
|
// current widget instead of adding
|
|
// another link to the chain.
|
|
var widget = widgetPointer.makeChildWidget(node);
|
|
widget.computeAttributes();
|
|
widget.execute();
|
|
// We SHALLOW copy over all variables
|
|
// in widget. We can't use
|
|
// $tw.utils.assign, because that copies
|
|
// up the prototype chain, which we
|
|
// don't want.
|
|
$tw.utils.each(Object.keys(widget.variables), function(key) {
|
|
widgetPointer.variables[key] = widget.variables[key];
|
|
});
|
|
} else {
|
|
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];
|
|
}
|
|
}
|
|
});
|
|
|
|
if(widgetPointer != this) {
|
|
widgetPointer.parseTreeNode.children = this.parseTreeNode.children;
|
|
} else {
|
|
widgetPointer.makeChildWidgets();
|
|
}
|
|
};
|
|
|
|
/*
|
|
Selectively refreshes the widget if needed. Returns true if the widget or any of its children needed re-rendering
|
|
*/
|
|
ImportVariablesWidget.prototype.refresh = function(changedTiddlers) {
|
|
// Recompute our attributes and the filter list
|
|
var changedAttributes = this.computeAttributes(),
|
|
tiddlerList = this.wiki.filterTiddlers(this.getAttribute("filter"),this);
|
|
// Refresh if the filter has changed, or the list of tiddlers has changed, or any of the tiddlers in the list has changed
|
|
function haveListedTiddlersChanged() {
|
|
var changed = false;
|
|
tiddlerList.forEach(function(title) {
|
|
if(changedTiddlers[title]) {
|
|
changed = true;
|
|
}
|
|
});
|
|
return changed;
|
|
}
|
|
if(changedAttributes.filter || !$tw.utils.isArrayEqual(this.tiddlerList,tiddlerList) || haveListedTiddlersChanged()) {
|
|
// Compute the filter
|
|
this.removeChildDomNodes();
|
|
this.execute(tiddlerList);
|
|
this.renderChildren(this.parentDomNode,this.findNextSiblingDomNode());
|
|
return true;
|
|
} else {
|
|
return this.refreshChildren(changedTiddlers);
|
|
}
|
|
};
|
|
|
|
exports.importvariables = ImportVariablesWidget;
|