@rbxts/uiblox 0.1.28 → 0.1.29

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,10 +3,25 @@ local TS = _G[script]
3
3
  local classNamesInternal = function(conditionalStyles, ...)
4
4
  local styles = { ... }
5
5
  local style = {}
6
+ -- ▼ ReadonlyArray.forEach ▼
7
+ local _callback = function(value)
8
+ if value ~= 0 and value == value and value ~= "" and value then
9
+ local _object = table.clone(style)
10
+ setmetatable(_object, nil)
11
+ for _k, _v in value do
12
+ _object[_k] = _v
13
+ end
14
+ style = _object
15
+ end
16
+ end
17
+ for _k, _v in styles do
18
+ _callback(_v, _k - 1, styles)
19
+ end
20
+ -- ▲ ReadonlyArray.forEach ▲
6
21
  local _result = conditionalStyles
7
22
  if _result ~= nil then
8
23
  -- ▼ ReadonlyMap.forEach ▼
9
- local _callback = function(value, key)
24
+ local _callback_1 = function(value, key)
10
25
  if value then
11
26
  local _object = table.clone(style)
12
27
  setmetatable(_object, nil)
@@ -17,25 +32,10 @@ local classNamesInternal = function(conditionalStyles, ...)
17
32
  end
18
33
  end
19
34
  for _k, _v in _result do
20
- _callback(_v, _k, _result)
35
+ _callback_1(_v, _k, _result)
21
36
  end
22
37
  -- ▲ ReadonlyMap.forEach ▲
23
38
  end
24
- -- ▼ ReadonlyArray.forEach ▼
25
- local _callback = function(value)
26
- if value ~= 0 and value == value and value ~= "" and value then
27
- local _object = table.clone(style)
28
- setmetatable(_object, nil)
29
- for _k, _v in value do
30
- _object[_k] = _v
31
- end
32
- style = _object
33
- end
34
- end
35
- for _k, _v in styles do
36
- _callback(_v, _k - 1, styles)
37
- end
38
- -- ▲ ReadonlyArray.forEach ▲
39
39
  local _object = table.clone(style)
40
40
  setmetatable(_object, nil)
41
41
  return _object
@@ -47,7 +47,36 @@ local function classNames(...)
47
47
  local hasConditionalStyles = function(args)
48
48
  local _exitType, _returns = TS.try(function()
49
49
  local lastArg = args[#args]
50
- return TS.TRY_RETURN, { lastArg ~= nil and type(lastArg) == "table" }
50
+ -- If the last argument is undefined or not a table then its not a ConditionalStyles<T>
51
+ -- Map<K, V> compiles to a table literal (ref: https://roblox-ts.com/docs/api/constructors)
52
+ if lastArg == nil or not (type(lastArg) == "table") then
53
+ return TS.TRY_RETURN, { false }
54
+ end
55
+ local lastArgAsConditionalStylesMap = lastArg
56
+ local matchesMapFormat = true
57
+ local _result = lastArgAsConditionalStylesMap
58
+ if _result ~= nil then
59
+ -- ▼ ReadonlyMap.forEach ▼
60
+ local _callback = function(value, key)
61
+ -- Assume that the last argument is a ConditionalStyles<T> with correct format (Map<WriteableStyle<T>, boolean>)
62
+ -- If the key is not a WriteableStyle<T> then it does not match the format
63
+ -- If the value is not a boolean then it does not match the format
64
+ local _value = value
65
+ local _condition = not (type(_value) == "boolean")
66
+ if not _condition then
67
+ local _key = key
68
+ _condition = not (type(_key) == "table")
69
+ end
70
+ if _condition then
71
+ matchesMapFormat = false
72
+ end
73
+ end
74
+ for _k, _v in _result do
75
+ _callback(_v, _k, _result)
76
+ end
77
+ -- ▲ ReadonlyMap.forEach ▲
78
+ end
79
+ return TS.TRY_RETURN, { matchesMapFormat }
51
80
  end, function()
52
81
  -- If we catch an error, it means that the last argument is not a ConditionalStyles<T>
53
82
  return TS.TRY_RETURN, { false }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rbxts/uiblox",
3
- "version": "0.1.28",
3
+ "version": "0.1.29",
4
4
  "description": "UI Library and theming for roblox-ts projects",
5
5
  "main": "out/init.lua",
6
6
  "scripts": {