1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-07-01 09:43:16 +00:00

Merge branch 'master' into demo-alternate-store

This commit is contained in:
Jeremy Ruston 2023-07-18 19:33:31 +01:00
commit 83e7d32c8e
25 changed files with 210 additions and 21 deletions

View File

@ -1,6 +1,4 @@
title: $:/core/images/new-journal-button
tags: $:/tags/Image
<$parameters size="22pt" day=<<now "DD">>>
<svg width=<<size>> height=<<size>> class="tc-image-new-journal-button tc-image-button" viewBox="0 0 128 128"><g fill-rule="evenodd"><path d="M102.545 112.818v11.818c0 1.306 1.086 2.364 2.425 2.364h6.06c1.34 0 2.425-1.058 2.425-2.364v-11.818h12.12c1.34 0 2.425-1.058 2.425-2.363v-5.91c0-1.305-1.085-2.363-2.424-2.363h-12.121V90.364c0-1.306-1.086-2.364-2.425-2.364h-6.06c-1.34 0-2.425 1.058-2.425 2.364v11.818h-12.12c-1.34 0-2.425 1.058-2.425 2.363v5.91c0 1.305 1.085 2.363 2.424 2.363h12.121zM60.016 4.965c-4.781-2.76-10.897-1.118-13.656 3.66L5.553 79.305A9.993 9.993 0 009.21 92.963l51.04 29.468c4.78 2.76 10.897 1.118 13.655-3.66l40.808-70.681a9.993 9.993 0 00-3.658-13.656L60.016 4.965zm-3.567 27.963a6 6 0 106-10.393 6 6 0 00-6 10.393zm31.697 17.928a6 6 0 106-10.392 6 6 0 00-6 10.392z"/><text class="tc-fill-background" font-family="Helvetica" font-size="47.172" font-weight="bold" transform="rotate(30 25.742 95.82)"><tspan x="42" y="77.485" text-anchor="middle"><$text text=<<day>>/></tspan></text></g></svg>
</$parameters>
<$parameters size="22pt" day=<<now "DD">>><svg width=<<size>> height=<<size>> class="tc-image-new-journal-button tc-image-button" viewBox="0 0 128 128"><g fill-rule="evenodd"><path d="M102.545 112.818v11.818c0 1.306 1.086 2.364 2.425 2.364h6.06c1.34 0 2.425-1.058 2.425-2.364v-11.818h12.12c1.34 0 2.425-1.058 2.425-2.363v-5.91c0-1.305-1.085-2.363-2.424-2.363h-12.121V90.364c0-1.306-1.086-2.364-2.425-2.364h-6.06c-1.34 0-2.425 1.058-2.425 2.364v11.818h-12.12c-1.34 0-2.425 1.058-2.425 2.363v5.91c0 1.305 1.085 2.363 2.424 2.363h12.121zM60.016 4.965c-4.781-2.76-10.897-1.118-13.656 3.66L5.553 79.305A9.993 9.993 0 009.21 92.963l51.04 29.468c4.78 2.76 10.897 1.118 13.655-3.66l40.808-70.681a9.993 9.993 0 00-3.658-13.656L60.016 4.965zm-3.567 27.963a6 6 0 106-10.393 6 6 0 00-6 10.393zm31.697 17.928a6 6 0 106-10.392 6 6 0 00-6 10.392z"/><text class="tc-fill-background" font-family="Helvetica" font-size="47.172" font-weight="bold" transform="rotate(30 25.742 95.82)"><tspan x="42" y="77.485" text-anchor="middle"><$text text=<<day>>/></tspan></text></g></svg></$parameters>

View File

@ -38,6 +38,7 @@ exports.startup = function() {
url: params.url,
method: params.method,
body: params.body,
binary: params.binary,
oncompletion: params.oncompletion,
onprogress: params.onprogress,
bindStatus: params["bind-status"],

View File

@ -90,6 +90,7 @@ wiki: wiki to be used for executing action strings
url: URL for request
method: method eg GET, POST
body: text of request body
binary: set to "yes" to force binary processing of response payload
oncompletion: action string to be invoked on completion
onprogress: action string to be invoked on progress updates
bindStatus: optional title of tiddler to which status ("pending", "complete", "error") should be written
@ -110,6 +111,7 @@ function HttpClientRequest(options) {
this.bindProgress = options["bindProgress"];
this.method = options.method || "GET";
this.body = options.body || "";
this.binary = options.binary || "";
this.variables = options.variables;
var url = options.url;
$tw.utils.each(options.queryStrings,function(value,name) {
@ -156,6 +158,8 @@ HttpClientRequest.prototype.send = function(callback) {
type: this.method,
headers: this.requestHeaders,
data: this.body,
returnProp: this.binary === "" ? "responseText" : "response",
responseType: this.binary === "" ? "text" : "arraybuffer",
callback: function(err,data,xhr) {
var hasSucceeded = xhr.status >= 200 && xhr.status < 300,
completionCode = hasSucceeded ? "complete" : "error",
@ -175,6 +179,16 @@ HttpClientRequest.prototype.send = function(callback) {
data: (data || "").toString(),
headers: JSON.stringify(headers)
};
/* Convert data from binary to base64 */
if (xhr.responseType === "arraybuffer") {
var binary = "",
bytes = new Uint8Array(data),
len = bytes.byteLength;
for (var i=0; i<len; i++) {
binary += String.fromCharCode(bytes[i]);
}
resultVariables.data = window.btoa(binary);
}
self.wiki.addTiddler(new $tw.Tiddler(self.wiki.getTiddler(requestTrackerTitle),{
status: completionCode,
}));
@ -212,6 +226,7 @@ Make an HTTP request. Options are:
callback: function invoked with (err,data,xhr)
progress: optional function invoked with (lengthComputable,loaded,total)
returnProp: string name of the property to return as first argument of callback
responseType: "text" or "arraybuffer"
*/
exports.httpRequest = function(options) {
var type = options.type || "GET",
@ -264,6 +279,7 @@ exports.httpRequest = function(options) {
}
}
}
request.responseType = options.responseType || "text";
// Set up the state change handler
request.onreadystatechange = function() {
if(this.readyState === 4) {

View File

@ -49,7 +49,7 @@ ImportVariablesWidget.prototype.execute = function(tiddlerList) {
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});
var parser = widgetPointer.wiki.parseTiddler(title,{parseAsInline:true, configTrimWhiteSpace:true});
if(parser) {
var parseTreeNode = parser.tree[0];
while(parseTreeNode && ["setvariable","set","parameters"].indexOf(parseTreeNode.type) !== -1) {

View File

@ -41,16 +41,17 @@ TranscludeWidget.prototype.execute = function() {
this.collectAttributes();
this.collectStringParameters();
this.collectSlotFillParameters();
// Get the parse tree nodes that we are transcluding
// Get the target text and parse tree nodes that we are transcluding
var target = this.getTransclusionTarget(),
parseTreeNodes = target.parseTreeNodes;
parseTreeNodes;
this.sourceText = target.text;
this.parserType = target.type;
this.parseAsInline = target.parseAsInline;
// Process the transclusion according to the output type
switch(this.transcludeOutput || "text/html") {
case "text/html":
// No further processing required
// Return the parse tree nodes
parseTreeNodes = target.parseTreeNodes;
break;
case "text/raw":
// Just return the raw text
@ -158,7 +159,7 @@ TranscludeWidget.prototype.collectSlotFillParameters = function() {
};
/*
Get transcluded parse tree nodes as an object {parser:,text:,type:}
Get transcluded parse tree nodes as an object {text:,type:,parseTreeNodes:,parseAsInline:}
*/
TranscludeWidget.prototype.getTransclusionTarget = function() {
var self = this;
@ -270,7 +271,6 @@ TranscludeWidget.prototype.getTransclusionTarget = function() {
// Return the parse tree
if(parser) {
return {
parser: parser,
parseTreeNodes: parser.tree,
parseAsInline: parseAsInline,
text: parser.source,
@ -279,7 +279,6 @@ TranscludeWidget.prototype.getTransclusionTarget = function() {
} else {
// If there's no parse tree then return the missing slot value
return {
parser: null,
parseTreeNodes: (this.slotFillParseTrees["ts-missing"] || []),
parseAsInline: parseAsInline,
text: null,

View File

@ -13,7 +13,7 @@ Widget base class
"use strict";
/* Maximum permitted depth of the widget tree for recursion detection */
var MAX_WIDGET_TREE_DEPTH = 1000;
var MAX_WIDGET_TREE_DEPTH = 500;
/*
Create a widget object for a parse tree node

View File

@ -1086,7 +1086,7 @@ exports.getSubstitutedText = function(text,widget,options) {
output = $tw.utils.replaceString(output,new RegExp("\\$" + $tw.utils.escapeRegExp(substitute.name) + "\\$","mg"),substitute.value);
});
// Substitute any variable references with their values
return output.replace(/\$\((\w+)\)\$/g, function(match,varname) {
return output.replace(/\$\(([^\)\$]+)\)\$/g, function(match,varname) {
return widget.getVariable(varname,{defaultValue: ""})
});
};

View File

@ -1,3 +1,4 @@
code-body: yes
title: $:/core/ui/AlertTemplate
\whitespace trim

View File

@ -1,3 +1,4 @@
code-body: yes
title: $:/core/ui/EditTemplate
\define delete-edittemplate-state-tiddlers()

View File

@ -1,5 +1,6 @@
title: $:/core/ui/ImportPreviews/Text
tags: $:/tags/ImportPreview
caption: {{$:/language/Import/Listing/Preview/Text}}
code-body: yes
<$transclude tiddler=<<currentTiddler>> subtiddler=<<payloadTiddler>> mode="block"/>

View File

@ -1,4 +1,5 @@
title: $:/core/ui/PageStylesheet
code-body: yes
\import [subfilter{$:/core/config/GlobalImportFilter}]
\whitespace trim

View File

@ -2,6 +2,7 @@ title: $:/core/ui/PageTemplate
name: {{$:/language/PageTemplate/Name}}
description: {{$:/language/PageTemplate/Description}}
icon: $:/core/images/layout-button
code-body: yes
\whitespace trim
\import [subfilter{$:/core/config/GlobalImportFilter}]

View File

@ -1,4 +1,5 @@
title: $:/core/ui/RootTemplate
code-body: yes
<$transclude tiddler={{{ [{$:/layout}has[text]] ~[[$:/core/ui/PageTemplate]] }}} mode="inline"/>

View File

@ -1,3 +1,4 @@
title: $:/core/ui/StoryTiddlerTemplate
code-body: yes
<$transclude tiddler={{{ [<currentTiddler>] :cascade[all[shadows+tiddlers]tag[$:/tags/StoryTiddlerTemplateFilter]!is[draft]get[text]] :and[has[title]else[$:/core/ui/ViewTemplate]] }}} />

View File

@ -1,4 +1,5 @@
title: $:/core/ui/ViewTemplate
code-body: yes
\whitespace trim
\define folded-state()

View File

@ -1,4 +1,5 @@
title: $:/core/ui/ViewTemplate/body/default
code-body: yes
<$transclude>

View File

@ -2,7 +2,8 @@ title: $:/config/ViewTemplateBodyFilters/
tags: $:/tags/ViewTemplateBodyFilter
stylesheet: [tag[$:/tags/Stylesheet]then[$:/core/ui/ViewTemplate/body/rendered-plain-text]]
system: [prefix[$:/boot/]] [prefix[$:/config/]] [prefix[$:/core/macros]] [prefix[$:/core/save/]] [prefix[$:/core/templates/]] [prefix[$:/core/ui/]split[/]count[]compare:number:eq[4]] [prefix[$:/info/]] [prefix[$:/language/]] [prefix[$:/languages/]] [prefix[$:/snippets/]] [prefix[$:/state/]] [prefix[$:/status/]] [prefix[$:/info/]] [prefix[$:/temp/]] +[!is[image]limit[1]then[$:/core/ui/ViewTemplate/body/code]]
core-ui-tags: [tag[$:/tags/PageTemplate]] [tag[$:/tags/EditTemplate]] [tag[$:/tags/ViewTemplate]] [tag[$:/tags/KeyboardShortcut]] [tag[$:/tags/ImportPreview]] [tag[$:/tags/EditPreview]][tag[$:/tags/EditorToolbar]] [tag[$:/tags/Actions]] :then[[$:/core/ui/ViewTemplate/body/code]]
system: [prefix[$:/boot/]] [prefix[$:/config/]] [prefix[$:/core/macros]] [prefix[$:/core/save/]] [prefix[$:/core/templates/]] [prefix[$:/info/]] [prefix[$:/language/]] [prefix[$:/languages/]] [prefix[$:/snippets/]] [prefix[$:/state/]] [prefix[$:/status/]] [prefix[$:/info/]] [prefix[$:/temp/]] +[!is[image]limit[1]then[$:/core/ui/ViewTemplate/body/code]]
code-body: [field:code-body[yes]then[$:/core/ui/ViewTemplate/body/code]]
import: [field:plugin-type[import]then[$:/core/ui/ViewTemplate/body/import]]
plugin: [has[plugin-type]then[$:/core/ui/ViewTemplate/body/plugin]]

View File

@ -1,3 +1,2 @@
title: $:/tags/ViewTemplateBodyFilter
list: $:/config/ViewTemplateBodyFilters/hide-body $:/config/ViewTemplateBodyFilters/code-body $:/config/ViewTemplateBodyFilters/stylesheet $:/config/ViewTemplateBodyFilters/system $:/config/ViewTemplateBodyFilters/import $:/config/ViewTemplateBodyFilters/plugin $:/config/ViewTemplateBodyFilters/default
list: $:/config/ViewTemplateBodyFilters/hide-body $:/config/ViewTemplateBodyFilters/code-body $:/config/ViewTemplateBodyFilters/stylesheet $:/config/ViewTemplateBodyFilters/core-ui-advanced-search $:/config/ViewTemplateBodyFilters/core-ui-tags $:/config/ViewTemplateBodyFilters/system $:/config/ViewTemplateBodyFilters/import $:/config/ViewTemplateBodyFilters/plugin $:/config/ViewTemplateBodyFilters/default

View File

@ -0,0 +1,23 @@
title: ImportVariables/WithSetWidgets
description: Import variables defined with a set widget
type: text/vnd.tiddlywiki-multiple
tags: [[$:/tags/wiki-test-spec]]
title: Output
\whitespace trim
\import Definitions
<$text text=<<one>>/>,
<$text text=<<two>>/>
+
title: Definitions
\whitespace trim
<$set name="one" value="elephant">
<$set name="two" value="giraffe">
</$set>
</$set>
+
title: ExpectedResult
<p>elephant,giraffe</p>

View File

@ -0,0 +1,22 @@
title: ImportVariables/WithSetWidgets2
description: Import variables defined with a set widget without whitespace pragma
type: text/vnd.tiddlywiki-multiple
tags: [[$:/tags/wiki-test-spec]]
title: Output
\whitespace trim
\import Definitions
<$text text=<<one>>/>,
<$text text=<<two>>/>
+
title: Definitions
<$set name="one" value="elephant">
<$set name="two" value="giraffe">
</$set>
</$set>
+
title: ExpectedResult
<p>elephant,giraffe</p>

View File

@ -0,0 +1,29 @@
title: ImportVariables/WithSetWidgetsAndMacros
description: Import variables defined with a set widget without whitespace pragma
type: text/vnd.tiddlywiki-multiple
tags: [[$:/tags/wiki-test-spec]]
title: Output
\whitespace trim
\import Definitions
<$text text=<<name>>/>,
<$text text=<<address>>/>,
<$text text=<<one>>/>,
<$text text=<<two>>/>
+
title: Definitions
\define name() Bugs Bunny
\procedure address()
Bunny Hill
\end
<$set name="one" value="elephant">
<$set name="two" value="giraffe">
</$set>
</$set>
+
title: ExpectedResult
<p>Bugs Bunny,Bunny Hill,elephant,giraffe</p>

View File

@ -6,14 +6,16 @@ tags: [[$:/tags/wiki-test-spec]]
title: Output
\whitespace trim
<$let project="TiddlyWiki" disabled="true">
<$set name="var with spaces" value="spaces">
<$let project="TiddlyWiki" disabled="true" var-with-dashes="dashes">
<div class=`$(project)$
${ [[Hello]addsuffix[There]] }$` attrib=`myvalue` otherattrib=`$(1)$` blankattrib=`` quoted="here" disabled=```$(disabled)$```>
${ [[Hello]addsuffix[There]] }$` attrib=`myvalue` otherattrib=`$(1)$` blankattrib=`` quoted="here" disabled=```$(disabled)$``` dashes=`$(var-with-dashes)$` spaces=`$(var with spaces)$`>
</div>
</$let>
</$set>
+
title: ExpectedResult
<p><div attrib="myvalue" blankattrib="" class="TiddlyWiki
HelloThere" disabled="true" otherattrib="" quoted="here"></div></p>
HelloThere" dashes="dashes" disabled="true" otherattrib="" quoted="here" spaces="spaces"></div></p>

View File

@ -0,0 +1,88 @@
title: WidgetMessage: tm-http-request Example - Random Dog
tags: $:/tags/Global
\procedure download-dog(url)
\procedure completion-download-dog()
\import [subfilter{$:/core/config/GlobalImportFilter}]
<$action-log msg="In completion-download-dog"/>
<$action-log/>
<!-- Success -->
<$list filter="[<status>compare:number:gteq[200]compare:number:lteq[299]]" variable="ignore">
<!-- Create the dog tiddler -->
<$action-createtiddler
$basetitle=`$:/RandomDog/$(title)$`
text=<<data>>
tags="$:/tags/RandomDog"
type={{{ [<headers>jsonget[content-type]] }}}
credits="https://random.dog/"
>
<$action-log msg="Created tiddler" title=<<createTiddler-title>>/>
</$createtiddler>
</$list>
\end completion-download-dog
<$action-sendmessage
$message="tm-http-request"
url=<<url>>
method="GET"
binary="yes"
oncompletion=<<completion-download-dog>>
var-title=<<url>>
/>
\end download-dog
\procedure get-random-dog()
\procedure completion-get-json()
\import [subfilter{$:/core/config/GlobalImportFilter}]
<$action-log msg="In completion-get-json"/>
<$action-log/>
<!-- Success -->
<$list filter="[<status>compare:number:gteq[200]compare:number:lteq[299]]" variable="ignore">
<!-- Download the dog -->
<$macrocall $name="download-dog" url={{{ [<data>jsonget[url]] }}}/>
</$list>
\end completion-get-json
<$action-sendmessage
$message="tm-http-request"
url="https://random.dog/woof.json"
method="GET"
oncompletion=<<completion-get-json>>
/>
\end get-random-dog
!! Random Dogs
This demo uses the API of the website https://random.dog/ to import a random dog image or video.
<$button actions=<<get-random-dog>>>
Import a random dog image or video
</$button>
<$list filter="[tag[$:/tags/RandomDog]limit[1]]" variable="ignore">
!! Imported Tiddlers
<$button>
<$action-deletetiddler $filter="[tag[$:/tags/RandomDog]]"/>
Delete all imported random dogs
</$button>
Export all imported random dogs: <$macrocall $name="exportButton" exportFilter="[tag[$:/tags/RandomDog]]" lingoBase="$:/language/Buttons/ExportTiddlers/"/>
</$list>
<ol>
<$list filter="[tag[$:/tags/RandomDog]!sort[modified]]">
<li>
<$link>
<$text text=<<currentTiddler>>/>
</$link>
<div style="width:300px;height:300px;">
<$transclude $tiddler=<<currentTiddler>>/>
</div>
</li>
</$list>
</ol>

View File

@ -1,5 +1,5 @@
title: WidgetMessage: tm-http-request Example - Zotero
tags: $:/tags/Macro
tags: $:/tags/Global
\procedure select-zotero-group()
Specify the Zotero group ID to import
@ -34,7 +34,7 @@ Specify the Zotero group ID to import
\procedure zotero-get-items(start:"0",limit:"25")
\procedure completion()
\import [[$:/core/ui/PageMacros]] [all[shadows+tiddlers]tag[$:/tags/Macro]!has[draft.of]]
\import [subfilter{$:/core/config/GlobalImportFilter}]
<$action-log msg="In completion"/>
<$action-log/>
<!-- Success -->

View File

@ -1,6 +1,6 @@
caption: tm-http-request
created: 20230429161453032
modified: 20230429161453032
modified: 20230717104212742
tags: Messages
title: WidgetMessage: tm-http-request
type: text/vnd.tiddlywiki
@ -18,6 +18,7 @@ The following parameters are used:
|!Name |!Description |
|method |HTTP method (eg "GET", "POST") |
|body |String data to be sent with the request |
|binary |<<.from-version "5.3.1">> Set to "yes" to cause the response body to be treated as binary data and returned in base64 format |
|query-* |Query string parameters with string values |
|header-* |Headers with string values |
|password-header-* |Headers with values taken from the password store |
@ -49,3 +50,4 @@ Note that the state tiddler $:/state/http-requests contains a number representin
!! Examples
* [[Zotero's|https://www.zotero.org/]] API for retrieving reference items: [[WidgetMessage: tm-http-request Example - Zotero]]
* [[Random Dog's|https://random.dog/]] API for retrieving random pictures of dogs showing how to retrieve binary data: [[WidgetMessage: tm-http-request Example - Random Dogs]]