@rbxts/uiblox 0.1.36 → 0.1.37
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.
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { WriteableStyle } from "./WriteableStyle";
|
|
2
|
-
export type ConditionalStylesMap<T extends Instance> = Map<WriteableStyle<T
|
|
2
|
+
export type ConditionalStylesMap<T extends Instance> = Map<WriteableStyle<T> | undefined, boolean>;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { WriteableStyle, ConditionalStylesMap } from "../types/index";
|
|
2
|
-
declare function classNames<T extends Instance>(...args: [...Array<WriteableStyle<T
|
|
2
|
+
declare function classNames<T extends Instance>(...args: [...Array<WriteableStyle<T> | undefined>, ConditionalStylesMap<T>] | [...Array<WriteableStyle<T> | undefined>]): WriteableStyle<T>;
|
|
3
3
|
export default classNames;
|
|
@@ -3,6 +3,23 @@ local TS = _G[script]
|
|
|
3
3
|
local classNamesInternal = function(conditionalStyles, ...)
|
|
4
4
|
local styles = { ... }
|
|
5
5
|
local style = {}
|
|
6
|
+
-- ▼ ReadonlyArray.filterUndefined ▼
|
|
7
|
+
local _length = 0
|
|
8
|
+
for _i in styles do
|
|
9
|
+
if _i > _length then
|
|
10
|
+
_length = _i
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
local _result = {}
|
|
14
|
+
local _resultLength = 0
|
|
15
|
+
for _i = 1, _length do
|
|
16
|
+
local _v = styles[_i]
|
|
17
|
+
if _v ~= nil then
|
|
18
|
+
_resultLength += 1
|
|
19
|
+
_result[_resultLength] = _v
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
-- ▲ ReadonlyArray.filterUndefined ▲
|
|
6
23
|
-- ▼ ReadonlyArray.forEach ▼
|
|
7
24
|
local _callback = function(value)
|
|
8
25
|
if value ~= 0 and value == value and value ~= "" and value then
|
|
@@ -14,25 +31,27 @@ local classNamesInternal = function(conditionalStyles, ...)
|
|
|
14
31
|
style = _object
|
|
15
32
|
end
|
|
16
33
|
end
|
|
17
|
-
for _k, _v in
|
|
18
|
-
_callback(_v, _k - 1,
|
|
34
|
+
for _k, _v in _result do
|
|
35
|
+
_callback(_v, _k - 1, _result)
|
|
19
36
|
end
|
|
20
37
|
-- ▲ ReadonlyArray.forEach ▲
|
|
21
|
-
local
|
|
22
|
-
if
|
|
38
|
+
local _result_1 = conditionalStyles
|
|
39
|
+
if _result_1 ~= nil then
|
|
23
40
|
-- ▼ ReadonlyMap.forEach ▼
|
|
24
41
|
local _callback_1 = function(value, key)
|
|
25
42
|
if value then
|
|
26
43
|
local _object = table.clone(style)
|
|
27
44
|
setmetatable(_object, nil)
|
|
28
|
-
|
|
29
|
-
|
|
45
|
+
if key ~= 0 and key == key and key ~= "" and key then
|
|
46
|
+
for _k, _v in key do
|
|
47
|
+
_object[_k] = _v
|
|
48
|
+
end
|
|
30
49
|
end
|
|
31
50
|
style = _object
|
|
32
51
|
end
|
|
33
52
|
end
|
|
34
|
-
for _k, _v in
|
|
35
|
-
_callback_1(_v, _k,
|
|
53
|
+
for _k, _v in _result_1 do
|
|
54
|
+
_callback_1(_v, _k, _result_1)
|
|
36
55
|
end
|
|
37
56
|
-- ▲ ReadonlyMap.forEach ▲
|
|
38
57
|
end
|
|
@@ -96,12 +115,46 @@ local function classNames(...)
|
|
|
96
115
|
local conditionalStyles = _result
|
|
97
116
|
local styles = args
|
|
98
117
|
-- ConditionalStyles<T> is the last argument
|
|
99
|
-
|
|
118
|
+
-- ▼ ReadonlyArray.filterUndefined ▼
|
|
119
|
+
local _length_1 = 0
|
|
120
|
+
for _i in styles do
|
|
121
|
+
if _i > _length_1 then
|
|
122
|
+
_length_1 = _i
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
local _result_1 = {}
|
|
126
|
+
local _resultLength = 0
|
|
127
|
+
for _i = 1, _length_1 do
|
|
128
|
+
local _v = styles[_i]
|
|
129
|
+
if _v ~= nil then
|
|
130
|
+
_resultLength += 1
|
|
131
|
+
_result_1[_resultLength] = _v
|
|
132
|
+
end
|
|
133
|
+
end
|
|
134
|
+
-- ▲ ReadonlyArray.filterUndefined ▲
|
|
135
|
+
return TS.TRY_RETURN, { classNamesInternal(conditionalStyles, unpack(_result_1)) }
|
|
100
136
|
end
|
|
101
137
|
end, function()
|
|
102
138
|
-- If we catch an error, like attempt to iterate over a string value, it means that the last argument is not a ConditionalStyles<T>
|
|
103
139
|
local styles = args
|
|
104
|
-
|
|
140
|
+
-- ▼ ReadonlyArray.filterUndefined ▼
|
|
141
|
+
local _length = 0
|
|
142
|
+
for _i in styles do
|
|
143
|
+
if _i > _length then
|
|
144
|
+
_length = _i
|
|
145
|
+
end
|
|
146
|
+
end
|
|
147
|
+
local _result = {}
|
|
148
|
+
local _resultLength = 0
|
|
149
|
+
for _i = 1, _length do
|
|
150
|
+
local _v = styles[_i]
|
|
151
|
+
if _v ~= nil then
|
|
152
|
+
_resultLength += 1
|
|
153
|
+
_result[_resultLength] = _v
|
|
154
|
+
end
|
|
155
|
+
end
|
|
156
|
+
-- ▲ ReadonlyArray.filterUndefined ▲
|
|
157
|
+
return TS.TRY_RETURN, { classNamesInternal(nil, unpack(_result)) }
|
|
105
158
|
end)
|
|
106
159
|
if _exitType then
|
|
107
160
|
return unpack(_returns)
|
|
@@ -109,7 +162,24 @@ local function classNames(...)
|
|
|
109
162
|
-- Handle case without ConditionalStyles
|
|
110
163
|
-- All args are WriteableStyle<T>
|
|
111
164
|
local styles = args
|
|
112
|
-
|
|
165
|
+
-- ▼ ReadonlyArray.filterUndefined ▼
|
|
166
|
+
local _length = 0
|
|
167
|
+
for _i in styles do
|
|
168
|
+
if _i > _length then
|
|
169
|
+
_length = _i
|
|
170
|
+
end
|
|
171
|
+
end
|
|
172
|
+
local _result = {}
|
|
173
|
+
local _resultLength = 0
|
|
174
|
+
for _i = 1, _length do
|
|
175
|
+
local _v = styles[_i]
|
|
176
|
+
if _v ~= nil then
|
|
177
|
+
_resultLength += 1
|
|
178
|
+
_result[_resultLength] = _v
|
|
179
|
+
end
|
|
180
|
+
end
|
|
181
|
+
-- ▲ ReadonlyArray.filterUndefined ▲
|
|
182
|
+
return classNamesInternal(nil, unpack(_result))
|
|
113
183
|
end
|
|
114
184
|
local default = classNames
|
|
115
185
|
return {
|