1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-12-04 07:19:56 +00:00

Fix up handling of slot/fill for custom widgets

Previously we were wrapping the body in an implicit `<$fill $name="ts-body">` widget
This commit is contained in:
jeremy@jermolene.com 2022-06-09 18:02:47 +01:00
parent defe3e42e6
commit 79b20bdaa8
8 changed files with 34 additions and 13 deletions

View File

@ -509,16 +509,10 @@ Widget.prototype.makeChildWidget = function(parseTreeNode,options) {
if(!parseTreeNode.isNotRemappable && isOverrideable() && variableInfo && variableInfo.srcVariable && variableInfo.srcVariable.value && variableInfo.srcVariable.isWidgetDefinition) { if(!parseTreeNode.isNotRemappable && isOverrideable() && variableInfo && variableInfo.srcVariable && variableInfo.srcVariable.value && variableInfo.srcVariable.isWidgetDefinition) {
var newParseTreeNode = { var newParseTreeNode = {
type: "transclude", type: "transclude",
children: [ children: parseTreeNode.children,
{
type: "fill",
children: parseTreeNode.children
}
],
isBlock: parseTreeNode.isBlock isBlock: parseTreeNode.isBlock
}; };
$tw.utils.addAttributeToParseTreeNode(newParseTreeNode,"$variable",variableDefinitionName); $tw.utils.addAttributeToParseTreeNode(newParseTreeNode,"$variable",variableDefinitionName);
$tw.utils.addAttributeToParseTreeNode(newParseTreeNode.children[0],"$name","ts-body");
$tw.utils.each(parseTreeNode.attributes,function(attr,name) { $tw.utils.each(parseTreeNode.attributes,function(attr,name) {
// If the attribute starts with a dollar then add an extra dollar so that it doesn't clash with the $xxx attributes of transclude // If the attribute starts with a dollar then add an extra dollar so that it doesn't clash with the $xxx attributes of transclude
name = name.charAt(0) === "$" ? "$" + name : name; name = name.charAt(0) === "$" ? "$" + name : name;

View File

@ -10,7 +10,7 @@ title: Output
\whitespace trim \whitespace trim
<$parameters $params="@params"> <$parameters $params="@params">
<$setmultiplevariables $names="[<@params>jsonindexes[]]" $values="[<@params>jsonindexes[]] :map[<@params>jsonget<currentTiddler>addprefix[--]addsuffix[--]]"> <$setmultiplevariables $names="[<@params>jsonindexes[]]" $values="[<@params>jsonindexes[]] :map[<@params>jsonget<currentTiddler>addprefix[--]addsuffix[--]]">
<$slot $name="ts-body"/> <$slot $name="ts-raw"/>
</$setmultiplevariables> </$setmultiplevariables>
</$parameters> </$parameters>
\end \end

View File

@ -15,7 +15,7 @@ title: $:/global/$$mywidget
_is_widget: yes _is_widget: yes
_parameters: (foo:"bar") _parameters: (foo:"bar")
Koala! <$text text=<<foo>>/>, <$slot $name="ts-body"/> Koala! <$text text=<<foo>>/>, <$slot $name="ts-raw"/>
+ +
title: ExpectedResult title: ExpectedResult

View File

@ -10,7 +10,7 @@ title: Output
\widget $non-existent-widget(one:'Jaguar') \widget $non-existent-widget(one:'Jaguar')
\whitespace trim \whitespace trim
<$text text=<<one>>/> <$text text=<<one>>/>
<$slot $name="ts-body"> <$slot $name="ts-raw">
Whale Whale
</$slot> </$slot>
\end \end

View File

@ -16,7 +16,7 @@ title: TiddlerOne
\widget $$mywidget(one:'Jaguar') \widget $$mywidget(one:'Jaguar')
\whitespace trim \whitespace trim
<$text text=<<one>>/> <$text text=<<one>>/>
<$slot $name="ts-body"> <$slot $name="ts-raw">
Whale Whale
</$slot> </$slot>
\end \end

View File

@ -0,0 +1,27 @@
title: Transclude/CustomWidget/Slotted
description: Custom widget definition
type: text/vnd.tiddlywiki-multiple
tags: [[$:/tags/wiki-test-spec]]
title: Output
\whitespace trim
\widget $$mywidget(one:'Jaguar')
\whitespace trim
<$text text=<<one>>/>
<$slot $name="ts-stuff">
Whale
</$slot>
\end
<$$mywidget one="Dingo">
<$fill $name="ts-stuff">
Crocodile
</$fill>
</$$mywidget>
<$$mywidget one="BumbleBee">
Squirrel
</$$mywidget>
+
title: ExpectedResult
<p>DingoCrocodileBumbleBeeWhale</p>

View File

@ -17,7 +17,7 @@ title: TiddlerOne
\whitespace trim \whitespace trim
<$genesis $type="text" $remappable="no" text=<<text>>/> <$genesis $type="text" $remappable="no" text=<<text>>/>
<$set name="$text" value=""> <$set name="$text" value="">
<$slot $name="ts-body"> <$slot $name="ts-raw">
Whale Whale
</$slot> </$slot>
</$set> </$set>

View File

@ -16,7 +16,7 @@ title: TiddlerOne
\widget $$mywidget($variable:'Jaguar') \widget $$mywidget($variable:'Jaguar')
\whitespace trim \whitespace trim
<$text text=<<$variable>>/> <$text text=<<$variable>>/>
<$slot $name="ts-body"> <$slot $name="ts-raw">
Whale Whale
</$slot> </$slot>
\end \end