1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-08 02:49:56 +00:00

Merge branch 'master' into confetti-plugin

This commit is contained in:
Jeremy Ruston 2023-09-27 14:09:00 +01:00
commit 455a51f671
16 changed files with 123 additions and 77 deletions

View File

@ -2674,6 +2674,18 @@ $tw.hooks.addHook = function(hookName,definition) {
}
};
/*
Delete hooks from the hashmap
*/
$tw.hooks.removeHook = function(hookName,definition) {
if($tw.utils.hop($tw.hooks.names,hookName)) {
var p = $tw.hooks.names[hookName].indexOf(definition);
if(p !== -1) {
$tw.hooks.names[hookName].splice(p, 1);
}
}
};
/*
Invoke the hook by key
*/

View File

@ -28,12 +28,8 @@ function getAllFilterOperators() {
Export our filter function
*/
exports.all = function(source,operator,options) {
// Get our suboperators
var allFilterOperators = getAllFilterOperators();
// Cycle through the suboperators accumulating their results
var results = new $tw.utils.LinkedList(),
subops = operator.operand.split("+");
// Check for common optimisations
var subops = operator.operand.split("+");
if(subops.length === 1 && subops[0] === "") {
return source;
} else if(subops.length === 1 && subops[0] === "tiddlers") {
@ -46,6 +42,10 @@ exports.all = function(source,operator,options) {
return options.wiki.eachShadowPlusTiddlers;
}
// Do it the hard way
// Get our suboperators
var allFilterOperators = getAllFilterOperators();
// Cycle through the suboperators accumulating their results
var results = new $tw.utils.LinkedList();
for(var t=0; t<subops.length; t++) {
var subop = allFilterOperators[subops[t]];
if(subop) {

View File

@ -225,6 +225,8 @@ ListWidget.prototype.handleListChanges = function(changedTiddlers) {
// If we are providing an counter variable then we must refresh the items, otherwise we can rearrange them
var hasRefreshed = false,t;
if(this.counterName) {
var mustRefreshOldLast = false;
var oldLength = this.children.length;
// Cycle through the list and remove and re-insert the first item that has changed, and all the remaining items
for(t=0; t<this.list.length; t++) {
if(hasRefreshed || !this.children[t] || this.children[t].parseTreeNode.itemTitle !== this.list[t]) {
@ -232,6 +234,9 @@ ListWidget.prototype.handleListChanges = function(changedTiddlers) {
this.removeListItem(t);
}
this.insertListItem(t,this.list[t]);
if(!hasRefreshed && t === oldLength) {
mustRefreshOldLast = true;
}
hasRefreshed = true;
} else {
// Refresh the item we're reusing
@ -239,6 +244,12 @@ ListWidget.prototype.handleListChanges = function(changedTiddlers) {
hasRefreshed = hasRefreshed || refreshed;
}
}
// If items were inserted then we must recreate the item that used to be at the last position as it is no longer last
if(mustRefreshOldLast && oldLength > 0) {
var oldLastIdx = oldLength-1;
this.removeListItem(oldLastIdx);
this.insertListItem(oldLastIdx,this.list[oldLastIdx]);
}
// If there are items to remove and we have not refreshed then recreate the item that will now be at the last position
if(!hasRefreshed && this.children.length > this.list.length) {
this.removeListItem(this.list.length-1);

View File

@ -10,7 +10,7 @@ first-search-filter: [all[shadows+tiddlers]prefix[$:/language/Docs/Types/]sort[d
<em class="tc-edit tc-small-gap-right"><<lingo Type/Prompt>></em>
<div class="tc-type-selector-dropdown-wrapper">
<div class="tc-type-selector"><$fieldmangler>
<$macrocall $name="keyboard-driven-input" tiddler=<<currentTiddler>> storeTitle=<<typeInputTiddler>> refreshTitle=<<refreshTitle>> selectionStateTitle=<<typeSelectionTiddler>> field="type" tag="input" default="" placeholder={{$:/language/EditTemplate/Type/Placeholder}} focusPopup=<<qualify "$:/state/popup/type-dropdown">> class="tc-edit-typeeditor tc-edit-texteditor tc-popup-handle" tabindex={{$:/config/EditTabIndex}} focus={{{ [{$:/config/AutoFocus}match[type]then[true]] ~[[false]] }}} cancelPopups="yes" configTiddlerFilter="[[$:/core/ui/EditTemplate/type]]" inputCancelActions=<<input-cancel-actions>>/><$button popup=<<qualify "$:/state/popup/type-dropdown">> class="tc-btn-invisible tc-btn-dropdown tc-small-gap" tooltip={{$:/language/EditTemplate/Type/Dropdown/Hint}} aria-label={{$:/language/EditTemplate/Type/Dropdown/Caption}}>{{$:/core/images/down-arrow}}</$button><$button message="tm-remove-field" param="type" class="tc-btn-invisible tc-btn-icon" tooltip={{$:/language/EditTemplate/Type/Delete/Hint}} aria-label={{$:/language/EditTemplate/Type/Delete/Caption}}>{{$:/core/images/delete-button}}<$action-deletetiddler $filter="[<storeTitle>] [<refreshTitle>] [<selectionStateTitle>]"/></$button>
<$macrocall $name="keyboard-driven-input" tiddler=<<currentTiddler>> storeTitle=<<typeInputTiddler>> refreshTitle=<<refreshTitle>> selectionStateTitle=<<typeSelectionTiddler>> field="type" tag="input" default="" placeholder={{$:/language/EditTemplate/Type/Placeholder}} focusPopup=<<qualify "$:/state/popup/type-dropdown">> class="tc-edit-typeeditor tc-edit-texteditor tc-popup-handle" tabindex={{$:/config/EditTabIndex}} focus={{{ [{$:/config/AutoFocus}match[type]then[true]] ~[[false]] }}} cancelPopups="yes" configTiddlerFilter="[[$:/core/ui/EditTemplate/type]]" inputCancelActions=<<input-cancel-actions>>/><$button popup=<<qualify "$:/state/popup/type-dropdown">> class="tc-btn-invisible tc-btn-dropdown tc-small-gap" tooltip={{$:/language/EditTemplate/Type/Dropdown/Hint}} aria-label={{$:/language/EditTemplate/Type/Dropdown/Caption}}>{{$:/core/images/down-arrow}}</$button><$button message="tm-remove-field" param="type" class="tc-btn-invisible tc-btn-icon" tooltip={{$:/language/EditTemplate/Type/Delete/Hint}} aria-label={{$:/language/EditTemplate/Type/Delete/Caption}}>{{$:/core/images/delete-button}}<$action-deletetiddler $filter="[<typeInputTiddler>] [<storeTitle>] [<refreshTitle>] [<selectionStateTitle>]"/></$button>
</$fieldmangler></div>
<div class="tc-block-dropdown-wrapper">

View File

@ -1,9 +1,14 @@
created: 20141122200310516
modified: 20201213161842776
modified: 20230923031318421
tags: Mechanisms
title: HookMechanism
type: text/vnd.tiddlywiki
The hook mechanism provides a way for plugins to intercept and modify default functionality. Hooks are added as follows:
The hook mechanism provides a way for plugins to intercept and modify default functionality.
!! Add a hook
Hooks are added as follows:
```js
/*
@ -13,6 +18,8 @@ handler: function to be called when hook is invoked
$tw.hooks.addHook(name,handler);
```
!!! Params and return
The handler function will be called with parameters that depend on the specific hook in question, but they always follow the pattern `handler(value,params...)`
* ''value'': an optional value that is to be transformed by the hook function
@ -20,11 +27,29 @@ The handler function will be called with parameters that depend on the specific
If required by the hook in question, the handler function must return the modified ''value''.
!!! Multiple handlers
Multiple handlers can be assigned to the same name using repeated calls. When a hook is invoked by name all registered functions will be called sequentially in their order of addition.
Note that the ''value'' passed to the subsequent hook function will be the return value of the previous hook function.
Though not essential care should be taken to ensure that hooks are added before they are invoked. For example: [[Hook: th-opening-default-tiddlers-list]] should ideally be added before the story startup module is invoked otherwise any hook specified additions to the default tiddlers will not be seen on the initial loading of the page, though will be visible if the user clicks the home button.
Be careful not to `addHook` in widget's `render` method, which will be call several times. You could `addHook` in methods that only called once, e.g. the constructor of widget class. Otherwise you should `removeHook` then add it again.
!!! Timing of registration
Though not essential care should be taken to ensure that hooks are added before they are invoked.
For example: [[Hook: th-opening-default-tiddlers-list]] should ideally be added before the story startup module is invoked. Otherwise any hook specified additions to the default tiddlers will not be seen on the initial loading of the page, though will be visible if the user clicks the home button.
!! Remove a hook
You should clean up the callback when your widget is going to unmount.
```js
$tw.hooks.removeHook(handler)
```
The `handler` should be the same function instance you used in `addHook` (check by `===`). You can save it to `this.xxxHookHandler` on your widget, and call `removeHook` in [[destroy method|Widget `destroy` method examples]].
!! Example

View File

@ -527,6 +527,29 @@ describe("Widget module", function() {
expect(wrapper.children[0].children[15].sequenceNumber).toBe(53);
});
var testCounterLast = function(oldList, newList) {
return function() {
var wiki = new $tw.Wiki();
// Add some tiddlers
wiki.addTiddler({title: "Numbers", text: "", list: oldList});
var text = "<$list filter='[list[Numbers]]' variable='item' counter='c'><<item>><$text text={{{ [<c-last>match[no]then[, ]] }}} /></$list>";
var widgetNode = createWidgetNode(parseText(text,wiki),wiki);
// Render the widget node to the DOM
var wrapper = renderWidgetNode(widgetNode);
// Test the rendering
expect(wrapper.innerHTML).toBe("<p>" + oldList.split(' ').join(', ') + "</p>");
// Append a number
wiki.addTiddler({title: "Numbers", text: "", list: newList});
refreshWidgetNode(widgetNode,wrapper,["Numbers"]);
expect(wrapper.innerHTML).toBe("<p>" + newList.split(' ').join(', ') + "</p>");
}
}
it("the list widget with counter-last should update correctly when list is appended", testCounterLast("1 2 3 4", "1 2 3 4 5"));
it("the list widget with counter-last should update correctly when last item is removed", testCounterLast("1 2 3 4", "1 2 3"));
it("the list widget with counter-last should update correctly when first item is inserted", testCounterLast("1 2 3 4", "0 1 2 3 4"));
it("the list widget with counter-last should update correctly when first item is removed", testCounterLast("1 2 3 4", "2 3 4"));
it("should deal with the list widget followed by other widgets", function() {
var wiki = new $tw.Wiki();
// Add some tiddlers

View File

@ -1,9 +0,0 @@
created: 20171029155046637
modified: 20171029155227382
tags: [[Operator Examples]] [[stringify Operator]]
title: jsonstringify Operator (Examples)
type: text/vnd.tiddlywiki
<<.operator-example 1 """[[Title with "double quotes" and single ' and \backslash]] +[jsonstringify[]]""">>
<<.operator-example 2 """[[Accents and emojis -> äñøßπ ⌛🎄🍪🍓 without suffix]] +[jsonstringify[]]""">>
<<.operator-example 3 """[[Accents and emojis -> äñøßπ ⌛🎄🍪🍓 with rawunicode suffix]] +[jsonstringify:rawunicode[]]""">>

View File

@ -1,9 +1,9 @@
created: 20161017154944352
modified: 20171029155233487
modified: 20230919124059118
tags: [[Operator Examples]] [[stringify Operator]]
title: stringify Operator (Examples)
type: text/vnd.tiddlywiki
<<.operator-example 1 """[[Title with "double quotes" and single ' and \backslash]] +[stringify[]]""">>
<<.operator-example 2 """[[Accents and emojis -> äñøßπ ⌛🎄🍪🍓 without suffix]] +[stringify[]]""">>
<<.operator-example 3 """[[Accents and emojis -> äñøßπ ⌛🎄🍪🍓 with rawunicode suffix]] +[stringify:rawunicode[]]""">>
<<.operator-example 3 """[[Accents and emojis -> äñøßπ ⌛🎄🍪🍓 with rawunicode suffix]] +[stringify:rawunicode[]]""">>

View File

@ -1,36 +1,12 @@
caption: jsonstringify
created: 20171029155051467
from-version: 5.1.14
modified: 20171029155143797
op-input: a [[selection of titles|Title Selection]]
op-output: the input with JSON string encodings applied
modified: 20230919124826880
op-parameter:
op-parameter-name:
op-purpose: apply JSON string encoding to a string
op-suffix: <<.from-version "5.1.23">> optionally, the keyword `rawunicode`
op-purpose: deprecated, use <<.olink stringify>> instead
op-suffix-name: R
tags: [[Filter Operators]] [[String Operators]]
title: jsonstringify Operator
type: text/vnd.tiddlywiki
The following substitutions are made:
|!Character |!Replacement |!Condition |
|`\` |`\\` |Always |
|`"` |`\"` |Always |
|Carriage return (0x0d) |`\\r` |Always |
|Line feed (0x0a) |`\\n` |Always |
|Backspace (0x08) |`\\b` |Always |
|Form field (0x0c) |`\\f` |Always |
|Tab (0x09) |`\\t` |Always |
|Characters from 0x00 to 0x1f |`\\u####` where #### is four hex digits |Always |
|Characters from 0x80 to 0xffff|`\\u####` where #### is four hex digits |If `rawunicode` suffix is not present (default) |
|Characters from 0x80 to 0xffff|Unchanged |If `rawunicode` suffix is present <<.from-version "5.1.23">> |
<<.from-version "5.1.23">> If the suffix `rawunicode` is present, Unicode characters above 0x80 (such as ß, ä, ñ or 🎄) will be passed through unchanged. Without the suffix, they will be substituted with `\\u` codes, which was the default behavior before 5.1.23.
<<.note """Technical note: Characters outside the Basic Multilingual Plane, such as 🎄 and other emojis, will be encoded as a UTF-16 surrogate pair, i.e. with two `\u` sequences.""">>
Also see the [[stringify Operator]].
<<.operator-examples "jsonstringify">>

View File

@ -1,6 +1,7 @@
caption: stringify
created: 20161017153038029
modified: 20171029155143797
from-version: 5.1.14
modified: 20230919130847809
op-input: a [[selection of titles|Title Selection]]
op-output: the input with ~JavaScript string encodings applied
op-parameter:
@ -11,26 +12,25 @@ op-suffix-name: R
tags: [[Filter Operators]] [[String Operators]]
title: stringify Operator
type: text/vnd.tiddlywiki
from-version: 5.1.14
The following substitutions are made:
|!Character |!Replacement |!Condition |
|`\` |`\\` |Always |
|`"` |`\"` |Always |
|Carriage return (0x0d) |`\\r` |Always |
|Line feed (0x0a) |`\\n` |Always |
|Backspace (0x08) |`\\b` |Always |
|Form field (0x0c) |`\\f` |Always |
|Tab (0x09) |`\\t` |Always |
|Characters from 0x00 to 0x1f |`\\x##` where ## is two hex digits |Always |
|Characters from 0x80 to 0xffff|`\\u####` where #### is four hex digits |If `rawunicode` suffix is not present (default) |
|Carriage return (0x0d) |`\r` |Always |
|Line feed (0x0a) |`\n` |Always |
|Backspace (0x08) |`\b` |Always |
|Form field (0x0c) |`\f` |Always |
|Tab (0x09) |`\t` |Always |
|Characters from 0x00 to 0x1f |`\x##` where ## is two hex digits |Always |
|Characters from 0x80 to 0xffff|`\u####` where #### is four hex digits |If `rawunicode` suffix is not present (default) |
|Characters from 0x80 to 0xffff|<<.from-version "5.1.23">> Unchanged |If `rawunicode` suffix is present |
<<.from-version "5.1.23">> If the suffix `rawunicode` is present, Unicode characters above 0x80 (such as ß, ä, ñ or 🎄) will be passed through unchanged. Without the suffix, they will be substituted with `\\u` codes, which was the default behavior before 5.1.23.
<<.from-version "5.1.23">> If the suffix `rawunicode` is present, Unicode characters above 0x80 (such as ß, ä, ñ or 🎄) will be passed through unchanged. Without the suffix, they will be substituted with `\u` codes, which was the default behavior before 5.1.23.
<<.note """Technical note: Characters outside the Basic Multilingual Plane, such as 🎄 and other emojis, will be encoded as a UTF-16 surrogate pair, i.e. with two `\u` sequences.""">>
<<.note """Characters outside the Basic Multilingual Plane, such as 🎄 and other emojis, will be encoded as a UTF-16 surrogate pair, i.e. with two `\u` sequences.""">>
Also see the [[jsonstringify Operator]].
<<.olink jsonstringify>> is considered deprecated, as it duplicates the functionality of <<.op stringify>>.
<<.operator-examples "stringify">>
<<.operator-examples "stringify">>

View File

@ -1,7 +1,7 @@
title: Constructing JSON tiddlers
tags: [[JSON in TiddlyWiki]] [[Learning]]
created: 20220427174702859
modified: 20220427174702859
modified: 20230809113620964
tags: [[JSON in TiddlyWiki]] Learning
title: Constructing JSON tiddlers
See [[JSON in TiddlyWiki]] for an overview of using JSON in TiddlyWiki.
@ -13,4 +13,4 @@ At a high level, we have several ways to generate JSON data in TiddlyWiki's own
* [[jsontiddler Macro]]
* [[jsontiddlers Macro]]
When constructing JSON data manually, the [[jsonstringify Operator]] is needed to ensure that any special characters are properly escaped.
When constructing JSON data manually, the [[stringify Operator]] is needed to ensure that any special characters are properly escaped.

View File

@ -1,13 +1,17 @@
created: 20220917113002350
modified: 20230419103154329
modified: 20230921180332436
tags: Pragmas
title: Pragma: \whitespace
type: text/vnd.tiddlywiki
<<.from-version "5.1.15">> The ''\whitespace'' [[pragma|Pragmas]] determines how spaces and newlines are treated within wikitext. Note that this only applies to the printable text, and not to other text, such as the values of attributes.
<<.from-version "5.1.15">> The ''\whitespace'' [[pragma|Pragmas]] determines how spaces and newlines are treated within wikitext.
* ''notrim'' -- whitespace text is not subject to special processing (the default)
* ''trim'' -- whitespace text is removed
* ''trim'' -- whitespace text is ignored
Note that the processing only applies to the printable text, and not to other text, such as the values of attributes.
The whitespace setting only applies to the parsed content in which it appears. The setting is inherited by embedded [[Procedure Definitions]] and [[Custom Widgets]] definitions, but is not inherited by [[Macro definitions]].
```
\whitespace trim|notrim

View File

@ -1,5 +1,5 @@
created: 20221007125701001
modified: 20230419103154329
modified: 20230921180332436
tags: WikiText Procedures
title: Procedure Definitions
type: text/vnd.tiddlywiki
@ -18,6 +18,8 @@ This is the procedure text (param=<<param>>)
\end
```
Note that the [[Pragma: \whitespace]] setting is inherited from the parsing context in which the procedure definition occurs. That means that a tiddler containing multiple procedure definitions only needs a single whitespace pragma at the top of the tiddler, and the setting will be automatically inherited by the procedure definitions without needing the pragma to be repeated.
!! Procedure Definition with Set Widget
Procedures are implemented as a special kind of [[variable|Variables]] and so internally are actually defined with a <<.wlink SetWidget>> widget.

View File

@ -1,5 +1,5 @@
created: 20221007144237585
modified: 20230419103154328
modified: 20230921180332436
tags: Concepts Reference
title: Custom Widgets
type: text/vnd.tiddlywiki
@ -22,6 +22,8 @@ This is the widget, and the attribute is <<attribute>>.
The name of the widget must start with a dollar sign. If it is a user defined widget that does not override an existing widget then it must include at least one period (dot) within the name (for example `$my.widget` or `$acme.logger`).
Note that the [[Pragma: \whitespace]] setting is inherited from the parsing context in which the procedure definition occurs. That means that a tiddler containing multiple procedure definitions only needs a single whitespace pragma at the top of the tiddler, and the setting will be automatically inherited by the procedure definitions without needing the pragma to be repeated.
!! Using Custom Widgets
Custom widgets are called in the same way as ordinary built-in widgets:

View File

@ -1,5 +1,5 @@
title: $:/language/Help/server
description: Tworzy serwer HTTP wystawiający TiddlyWiki (zalecamy użycie komendy "--listen" zamiast tej)
description: (nieaktualne: patrz komenda 'listen') Tworzy serwer HTTP wystawiający TiddlyWiki (zalecamy użycie komendy "--listen" zamiast tej)
Dawna komenda do stawiania serwera wystawiającego wiki.

View File

@ -5,13 +5,13 @@ tags: [[$:/tags/Stylesheet]]
.tc-is-comment-header {
padding: 0.25em;
border: 2px solid #c1e1ea;
border: 2px solid <<colour message-foreground>>;
border-radius: 4px;
background: #f1fcff;
background: <<colour message-background>>;
}
.tc-comments-segment {
border-top: 2px solid #d7eef4;
border-top: 2px solid <<colour message-border>>;
}
.tc-comment-button button {
@ -25,7 +25,7 @@ tags: [[$:/tags/Stylesheet]]
}
.tc-comment-button button svg {
fill: #26cb56;
fill: <<colour download-background>>;
height: 2em;
width: 2em;
}
@ -44,18 +44,18 @@ tags: [[$:/tags/Stylesheet]]
.tc-comment-entry {
position: relative;
border: 2px solid #c1e1ea;
border: 2px solid <<colour message-border>>;
border-radius: 4px;
margin: 0.5em 0 0 0;
background: #f1fcff;
background: <<colour message-background>>;
}
.tc-comment-entry-heading {
font-size: 0.7em;
font-weight: bold;
text-transform: uppercase;
background: #d7eef4;
color: #5B6D80;
background: <<colour message-background>>;
color: <<colour message-foreground>>;
padding: 0 0.5em;
}