From 79b20bdaa8ea71236e778face04c72f7868bfb21 Mon Sep 17 00:00:00 2001 From: "jeremy@jermolene.com" Date: Thu, 9 Jun 2022 18:02:47 +0100 Subject: [PATCH] Fix up handling of slot/fill for custom widgets Previously we were wrapping the body in an implicit `<$fill $name="ts-body">` widget --- core/modules/widgets/widget.js | 8 +----- .../tests/data/genesis-widget/RedefineLet.tid | 2 +- .../tests/data/globals/CustomWidget.tid | 2 +- .../data/transclude/CustomWidget-Fail.tid | 2 +- .../data/transclude/CustomWidget-Simple.tid | 2 +- .../data/transclude/CustomWidget-Slotted.tid | 27 +++++++++++++++++++ .../CustomWidget-TextWidgetOverride.tid | 2 +- .../CustomWidget-VariableAttribute.tid | 2 +- 8 files changed, 34 insertions(+), 13 deletions(-) create mode 100644 editions/test/tiddlers/tests/data/transclude/CustomWidget-Slotted.tid diff --git a/core/modules/widgets/widget.js b/core/modules/widgets/widget.js index adf83a9f8..1086bd5eb 100755 --- a/core/modules/widgets/widget.js +++ b/core/modules/widgets/widget.js @@ -509,16 +509,10 @@ Widget.prototype.makeChildWidget = function(parseTreeNode,options) { if(!parseTreeNode.isNotRemappable && isOverrideable() && variableInfo && variableInfo.srcVariable && variableInfo.srcVariable.value && variableInfo.srcVariable.isWidgetDefinition) { var newParseTreeNode = { type: "transclude", - children: [ - { - type: "fill", - children: parseTreeNode.children - } - ], + children: parseTreeNode.children, isBlock: parseTreeNode.isBlock }; $tw.utils.addAttributeToParseTreeNode(newParseTreeNode,"$variable",variableDefinitionName); - $tw.utils.addAttributeToParseTreeNode(newParseTreeNode.children[0],"$name","ts-body"); $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 name = name.charAt(0) === "$" ? "$" + name : name; diff --git a/editions/test/tiddlers/tests/data/genesis-widget/RedefineLet.tid b/editions/test/tiddlers/tests/data/genesis-widget/RedefineLet.tid index 99bf18e24..184f6014f 100644 --- a/editions/test/tiddlers/tests/data/genesis-widget/RedefineLet.tid +++ b/editions/test/tiddlers/tests/data/genesis-widget/RedefineLet.tid @@ -10,7 +10,7 @@ title: Output \whitespace trim <$parameters $params="@params"> <$setmultiplevariables $names="[<@params>jsonindexes[]]" $values="[<@params>jsonindexes[]] :map[<@params>jsongetaddprefix[--]addsuffix[--]]"> -<$slot $name="ts-body"/> +<$slot $name="ts-raw"/> \end diff --git a/editions/test/tiddlers/tests/data/globals/CustomWidget.tid b/editions/test/tiddlers/tests/data/globals/CustomWidget.tid index 58d345b81..98ee4e5d7 100644 --- a/editions/test/tiddlers/tests/data/globals/CustomWidget.tid +++ b/editions/test/tiddlers/tests/data/globals/CustomWidget.tid @@ -15,7 +15,7 @@ title: $:/global/$$mywidget _is_widget: yes _parameters: (foo:"bar") -Koala! <$text text=<>/>, <$slot $name="ts-body"/> +Koala! <$text text=<>/>, <$slot $name="ts-raw"/> + title: ExpectedResult diff --git a/editions/test/tiddlers/tests/data/transclude/CustomWidget-Fail.tid b/editions/test/tiddlers/tests/data/transclude/CustomWidget-Fail.tid index 15be21b05..3d0759013 100644 --- a/editions/test/tiddlers/tests/data/transclude/CustomWidget-Fail.tid +++ b/editions/test/tiddlers/tests/data/transclude/CustomWidget-Fail.tid @@ -10,7 +10,7 @@ title: Output \widget $non-existent-widget(one:'Jaguar') \whitespace trim <$text text=<>/> -<$slot $name="ts-body"> +<$slot $name="ts-raw"> Whale \end diff --git a/editions/test/tiddlers/tests/data/transclude/CustomWidget-Simple.tid b/editions/test/tiddlers/tests/data/transclude/CustomWidget-Simple.tid index f98b2079a..70fedb61d 100644 --- a/editions/test/tiddlers/tests/data/transclude/CustomWidget-Simple.tid +++ b/editions/test/tiddlers/tests/data/transclude/CustomWidget-Simple.tid @@ -16,7 +16,7 @@ title: TiddlerOne \widget $$mywidget(one:'Jaguar') \whitespace trim <$text text=<>/> -<$slot $name="ts-body"> +<$slot $name="ts-raw"> Whale \end diff --git a/editions/test/tiddlers/tests/data/transclude/CustomWidget-Slotted.tid b/editions/test/tiddlers/tests/data/transclude/CustomWidget-Slotted.tid new file mode 100644 index 000000000..c10e84127 --- /dev/null +++ b/editions/test/tiddlers/tests/data/transclude/CustomWidget-Slotted.tid @@ -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=<>/> +<$slot $name="ts-stuff"> + Whale + +\end +<$$mywidget one="Dingo"> + <$fill $name="ts-stuff"> + Crocodile + + +<$$mywidget one="BumbleBee"> + Squirrel + ++ +title: ExpectedResult + +

DingoCrocodileBumbleBeeWhale

\ No newline at end of file diff --git a/editions/test/tiddlers/tests/data/transclude/CustomWidget-TextWidgetOverride.tid b/editions/test/tiddlers/tests/data/transclude/CustomWidget-TextWidgetOverride.tid index 0a65533f6..97313fcbd 100644 --- a/editions/test/tiddlers/tests/data/transclude/CustomWidget-TextWidgetOverride.tid +++ b/editions/test/tiddlers/tests/data/transclude/CustomWidget-TextWidgetOverride.tid @@ -17,7 +17,7 @@ title: TiddlerOne \whitespace trim <$genesis $type="text" $remappable="no" text=<>/> <$set name="$text" value=""> - <$slot $name="ts-body"> + <$slot $name="ts-raw"> Whale diff --git a/editions/test/tiddlers/tests/data/transclude/CustomWidget-VariableAttribute.tid b/editions/test/tiddlers/tests/data/transclude/CustomWidget-VariableAttribute.tid index 63fd5f87a..8ef700b41 100644 --- a/editions/test/tiddlers/tests/data/transclude/CustomWidget-VariableAttribute.tid +++ b/editions/test/tiddlers/tests/data/transclude/CustomWidget-VariableAttribute.tid @@ -16,7 +16,7 @@ title: TiddlerOne \widget $$mywidget($variable:'Jaguar') \whitespace trim <$text text=<<$variable>>/> -<$slot $name="ts-body"> +<$slot $name="ts-raw"> Whale \end