From 35893ea2c6ab796fc0e133968d3bdb2cef8d7c33 Mon Sep 17 00:00:00 2001 From: ElectricalBoy <15651807+ElectricalBoy@users.noreply.github.com> Date: Mon, 1 Jun 2026 16:40:48 +0900 Subject: [PATCH 1/3] remove widget2 context support --- lua/wikis/commons/Widget.lua | 22 -------------------- lua/wikis/commons/Widget/Context.lua | 31 ---------------------------- 2 files changed, 53 deletions(-) delete mode 100644 lua/wikis/commons/Widget/Context.lua diff --git a/lua/wikis/commons/Widget.lua b/lua/wikis/commons/Widget.lua index 5d27f81096a..7fe2eabb5aa 100644 --- a/lua/wikis/commons/Widget.lua +++ b/lua/wikis/commons/Widget.lua @@ -25,8 +25,6 @@ local Widget = Class.new(function(self, props) if not Array.isArray(self.props.children) then self.props.children = {self.props.children} end - - self.context = {} -- Populated by the parent end) Widget.defaultProps = {} @@ -55,7 +53,6 @@ function Widget:tryMake() return table.concat(Array.map(ret, function(val) if Class.instanceOf(val, Widget) then ---@cast val Widget - val.context = self:_nextContext() return val:tryMake() end if val ~= nil then @@ -72,31 +69,12 @@ function Widget:tryMake() ) end ----@param widget WidgetContext ----@param default any ----@return any -function Widget:useContext(widget, default) - local context = Array.find(self.context, function(node) - return Class.instanceOf(node, widget) - end) - if context then - ---@cast context WidgetContext - return context:getValue(default) - end - return default -end - ---@param error Error ---@return string function Widget:getDerivedStateFromError(error) return tostring(ErrorDisplay.InlineError(error)) end ----@return Widget[] -function Widget:_nextContext() - return {self, unpack(self.context)} -end - ---@param error Error ---@return Error function Widget._updateErrorHeader(error) diff --git a/lua/wikis/commons/Widget/Context.lua b/lua/wikis/commons/Widget/Context.lua deleted file mode 100644 index a4b716846bd..00000000000 --- a/lua/wikis/commons/Widget/Context.lua +++ /dev/null @@ -1,31 +0,0 @@ ---- --- @Liquipedia --- page=Module:Widget/Context --- --- Please see https://github.com/Liquipedia/Lua-Modules to contribute --- - -local Lua = require('Module:Lua') - -local Class = Lua.import('Module:Class') - -local Widget = Lua.import('Module:Widget') - ----@class WidgetContext: Widget -local WidgetContext = Class.new(Widget) - ----@param default any ----@return any -function WidgetContext:getValue(default) - if type(self.props.value) == 'function' then - return self.props.value(default) - end - return self.props.value -end - ----@return Renderable[] -function WidgetContext:render() - return self.props.children -end - -return WidgetContext From 1da5422a88aadfe7ec4206c5fcc320136baffa95 Mon Sep 17 00:00:00 2001 From: ElectricalBoy <15651807+ElectricalBoy@users.noreply.github.com> Date: Mon, 1 Jun 2026 16:45:00 +0900 Subject: [PATCH 2/3] use widget3 backend --- lua/wikis/commons/Widget.lua | 18 ++---------------- lua/wikis/commons/Widget/Renderer.lua | 5 ++++- 2 files changed, 6 insertions(+), 17 deletions(-) diff --git a/lua/wikis/commons/Widget.lua b/lua/wikis/commons/Widget.lua index 7fe2eabb5aa..3ec31c65b1c 100644 --- a/lua/wikis/commons/Widget.lua +++ b/lua/wikis/commons/Widget.lua @@ -12,6 +12,7 @@ local Class = Lua.import('Module:Class') local ErrorDisplay = Lua.import('Module:Error/Display') local FnUtil = Lua.import('Module:FnUtil') local Logic = Lua.import('Module:Logic') +local Renderer = Lua.import('Module:Widget/Renderer') local String = Lua.import('Module:StringUtils') local Table = Lua.import('Module:Table') @@ -44,22 +45,7 @@ end ---@return string function Widget:tryMake() local function renderComponent() - local ret = self:render() - if not Array.isArray(ret) then - ret = {ret} - end - ---@cast ret Renderable[] - - return table.concat(Array.map(ret, function(val) - if Class.instanceOf(val, Widget) then - ---@cast val Widget - return val:tryMake() - end - if val ~= nil then - return tostring(val) - end - return nil - end)) + return Renderer.render(self:render()) end return Logic.tryOrElseLog( diff --git a/lua/wikis/commons/Widget/Renderer.lua b/lua/wikis/commons/Widget/Renderer.lua index 592c3ef328a..88ced48541a 100644 --- a/lua/wikis/commons/Widget/Renderer.lua +++ b/lua/wikis/commons/Widget/Renderer.lua @@ -55,7 +55,10 @@ function Renderer.render(vNode, context) -- Backward Compatibility (with Widgets and mw.html) if not renderFn then - if vNode.__tostring or vNode._build then + if vNode.tryMake then + ---@cast vNode Widget + return Renderer.render(vNode:render(), context) + elseif vNode.__tostring or vNode._build then return tostring(vNode) end mw.log('ERROR! Bad renderable:' .. mw.dumpObject(vNode)) From a5206aba0d5305d4a3c40e7125a87e313c0ba85f Mon Sep 17 00:00:00 2001 From: ElectricalBoy <15651807+ElectricalBoy@users.noreply.github.com> Date: Mon, 1 Jun 2026 16:46:58 +0900 Subject: [PATCH 3/3] cleanup --- lua/wikis/commons/Widget.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/lua/wikis/commons/Widget.lua b/lua/wikis/commons/Widget.lua index 3ec31c65b1c..d72ac22c97f 100644 --- a/lua/wikis/commons/Widget.lua +++ b/lua/wikis/commons/Widget.lua @@ -18,7 +18,6 @@ local Table = Lua.import('Module:Table') ---@class Widget: BaseClass ---@operator call(table): self ----@field context Widget[] ---@field props table local Widget = Class.new(function(self, props) self.props = Table.deepMerge(Table.deepCopy(self.defaultProps), props)