wuira 0.1.7 → 0.1.9

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,5 +1,290 @@
1
1
  --[[ Generated with https://github.com/TypeScriptToLua/TypeScriptToLua ]]
2
2
  -- Lua Library inline imports
3
+ local function __TS__Class(self)
4
+ local c = {prototype = {}}
5
+ c.prototype.__index = c.prototype
6
+ c.prototype.constructor = c
7
+ return c
8
+ end
9
+
10
+ local __TS__Symbol, Symbol
11
+ do
12
+ local symbolMetatable = {__tostring = function(self)
13
+ return ("Symbol(" .. (self.description or "")) .. ")"
14
+ end}
15
+ function __TS__Symbol(description)
16
+ return setmetatable({description = description}, symbolMetatable)
17
+ end
18
+ Symbol = {
19
+ asyncDispose = __TS__Symbol("Symbol.asyncDispose"),
20
+ dispose = __TS__Symbol("Symbol.dispose"),
21
+ iterator = __TS__Symbol("Symbol.iterator"),
22
+ hasInstance = __TS__Symbol("Symbol.hasInstance"),
23
+ species = __TS__Symbol("Symbol.species"),
24
+ toStringTag = __TS__Symbol("Symbol.toStringTag")
25
+ }
26
+ end
27
+
28
+ local __TS__Iterator
29
+ do
30
+ local function iteratorGeneratorStep(self)
31
+ local co = self.____coroutine
32
+ local status, value = coroutine.resume(co)
33
+ if not status then
34
+ error(value, 0)
35
+ end
36
+ if coroutine.status(co) == "dead" then
37
+ return
38
+ end
39
+ return true, value
40
+ end
41
+ local function iteratorIteratorStep(self)
42
+ local result = self:next()
43
+ if result.done then
44
+ return
45
+ end
46
+ return true, result.value
47
+ end
48
+ local function iteratorStringStep(self, index)
49
+ index = index + 1
50
+ if index > #self then
51
+ return
52
+ end
53
+ return index, string.sub(self, index, index)
54
+ end
55
+ function __TS__Iterator(iterable)
56
+ if type(iterable) == "string" then
57
+ return iteratorStringStep, iterable, 0
58
+ elseif iterable.____coroutine ~= nil then
59
+ return iteratorGeneratorStep, iterable
60
+ elseif iterable[Symbol.iterator] then
61
+ local iterator = iterable[Symbol.iterator](iterable)
62
+ return iteratorIteratorStep, iterator
63
+ else
64
+ return ipairs(iterable)
65
+ end
66
+ end
67
+ end
68
+
69
+ local function __TS__New(target, ...)
70
+ local instance = setmetatable({}, target.prototype)
71
+ instance:____constructor(...)
72
+ return instance
73
+ end
74
+
75
+ local Set
76
+ do
77
+ Set = __TS__Class()
78
+ Set.name = "Set"
79
+ function Set.prototype.____constructor(self, values)
80
+ self[Symbol.toStringTag] = "Set"
81
+ self.size = 0
82
+ self.nextKey = {}
83
+ self.previousKey = {}
84
+ if values == nil then
85
+ return
86
+ end
87
+ local iterable = values
88
+ if iterable[Symbol.iterator] then
89
+ local iterator = iterable[Symbol.iterator](iterable)
90
+ while true do
91
+ local result = iterator:next()
92
+ if result.done then
93
+ break
94
+ end
95
+ self:add(result.value)
96
+ end
97
+ else
98
+ local array = values
99
+ for ____, value in ipairs(array) do
100
+ self:add(value)
101
+ end
102
+ end
103
+ end
104
+ function Set.prototype.add(self, value)
105
+ local isNewValue = not self:has(value)
106
+ if isNewValue then
107
+ self.size = self.size + 1
108
+ end
109
+ if self.firstKey == nil then
110
+ self.firstKey = value
111
+ self.lastKey = value
112
+ elseif isNewValue then
113
+ self.nextKey[self.lastKey] = value
114
+ self.previousKey[value] = self.lastKey
115
+ self.lastKey = value
116
+ end
117
+ return self
118
+ end
119
+ function Set.prototype.clear(self)
120
+ self.nextKey = {}
121
+ self.previousKey = {}
122
+ self.firstKey = nil
123
+ self.lastKey = nil
124
+ self.size = 0
125
+ end
126
+ function Set.prototype.delete(self, value)
127
+ local contains = self:has(value)
128
+ if contains then
129
+ self.size = self.size - 1
130
+ local next = self.nextKey[value]
131
+ local previous = self.previousKey[value]
132
+ if next ~= nil and previous ~= nil then
133
+ self.nextKey[previous] = next
134
+ self.previousKey[next] = previous
135
+ elseif next ~= nil then
136
+ self.firstKey = next
137
+ self.previousKey[next] = nil
138
+ elseif previous ~= nil then
139
+ self.lastKey = previous
140
+ self.nextKey[previous] = nil
141
+ else
142
+ self.firstKey = nil
143
+ self.lastKey = nil
144
+ end
145
+ self.nextKey[value] = nil
146
+ self.previousKey[value] = nil
147
+ end
148
+ return contains
149
+ end
150
+ function Set.prototype.forEach(self, callback)
151
+ for ____, key in __TS__Iterator(self:keys()) do
152
+ callback(nil, key, key, self)
153
+ end
154
+ end
155
+ function Set.prototype.has(self, value)
156
+ return self.nextKey[value] ~= nil or self.lastKey == value
157
+ end
158
+ Set.prototype[Symbol.iterator] = function(self)
159
+ return self:values()
160
+ end
161
+ function Set.prototype.entries(self)
162
+ local function getFirstKey()
163
+ return self.firstKey
164
+ end
165
+ local nextKey = self.nextKey
166
+ local key
167
+ local started = false
168
+ return {
169
+ [Symbol.iterator] = function(self)
170
+ return self
171
+ end,
172
+ next = function(self)
173
+ if not started then
174
+ started = true
175
+ key = getFirstKey(nil)
176
+ else
177
+ key = nextKey[key]
178
+ end
179
+ return {done = not key, value = {key, key}}
180
+ end
181
+ }
182
+ end
183
+ function Set.prototype.keys(self)
184
+ local function getFirstKey()
185
+ return self.firstKey
186
+ end
187
+ local nextKey = self.nextKey
188
+ local key
189
+ local started = false
190
+ return {
191
+ [Symbol.iterator] = function(self)
192
+ return self
193
+ end,
194
+ next = function(self)
195
+ if not started then
196
+ started = true
197
+ key = getFirstKey(nil)
198
+ else
199
+ key = nextKey[key]
200
+ end
201
+ return {done = not key, value = key}
202
+ end
203
+ }
204
+ end
205
+ function Set.prototype.values(self)
206
+ local function getFirstKey()
207
+ return self.firstKey
208
+ end
209
+ local nextKey = self.nextKey
210
+ local key
211
+ local started = false
212
+ return {
213
+ [Symbol.iterator] = function(self)
214
+ return self
215
+ end,
216
+ next = function(self)
217
+ if not started then
218
+ started = true
219
+ key = getFirstKey(nil)
220
+ else
221
+ key = nextKey[key]
222
+ end
223
+ return {done = not key, value = key}
224
+ end
225
+ }
226
+ end
227
+ function Set.prototype.union(self, other)
228
+ local result = __TS__New(Set, self)
229
+ for ____, item in __TS__Iterator(other) do
230
+ result:add(item)
231
+ end
232
+ return result
233
+ end
234
+ function Set.prototype.intersection(self, other)
235
+ local result = __TS__New(Set)
236
+ for ____, item in __TS__Iterator(self) do
237
+ if other:has(item) then
238
+ result:add(item)
239
+ end
240
+ end
241
+ return result
242
+ end
243
+ function Set.prototype.difference(self, other)
244
+ local result = __TS__New(Set, self)
245
+ for ____, item in __TS__Iterator(other) do
246
+ result:delete(item)
247
+ end
248
+ return result
249
+ end
250
+ function Set.prototype.symmetricDifference(self, other)
251
+ local result = __TS__New(Set, self)
252
+ for ____, item in __TS__Iterator(other) do
253
+ if self:has(item) then
254
+ result:delete(item)
255
+ else
256
+ result:add(item)
257
+ end
258
+ end
259
+ return result
260
+ end
261
+ function Set.prototype.isSubsetOf(self, other)
262
+ for ____, item in __TS__Iterator(self) do
263
+ if not other:has(item) then
264
+ return false
265
+ end
266
+ end
267
+ return true
268
+ end
269
+ function Set.prototype.isSupersetOf(self, other)
270
+ for ____, item in __TS__Iterator(other) do
271
+ if not self:has(item) then
272
+ return false
273
+ end
274
+ end
275
+ return true
276
+ end
277
+ function Set.prototype.isDisjointFrom(self, other)
278
+ for ____, item in __TS__Iterator(self) do
279
+ if other:has(item) then
280
+ return false
281
+ end
282
+ end
283
+ return true
284
+ end
285
+ Set[Symbol.species] = Set
286
+ end
287
+
3
288
  local function __TS__ArrayIsArray(value)
4
289
  return type(value) == "table" and (value[1] ~= nil or next(value) == nil)
5
290
  end
@@ -27,17 +312,52 @@ do
27
312
  function UI.createElement(self, component, props, ...)
28
313
  local children = {...}
29
314
  local elements = {}
30
- for ____, child in ipairs(children) do
315
+ local groups = __TS__New(Set)
316
+ local append
317
+ append = function(____, child)
31
318
  if __TS__ArrayIsArray(child) then
32
- for ____, element in ipairs(child) do
33
- elements[#elements + 1] = element
319
+ if groups:has(child) then
320
+ error("UI children contain a cycle")
34
321
  end
35
- else
322
+ groups:add(child)
323
+ for ____, nested in ipairs(child) do
324
+ append(nil, nested)
325
+ end
326
+ groups:delete(child)
327
+ return
328
+ end
329
+ if type(child) == "function" then
36
330
  elements[#elements + 1] = child
331
+ return
332
+ end
333
+ local element = child
334
+ if element.kind == "empty" then
335
+ return
336
+ end
337
+ if element.kind == "group" then
338
+ if groups:has(element) then
339
+ error("UI groups contain a cycle")
340
+ end
341
+ groups:add(element)
342
+ for ____, nested in ipairs(element.children or ({})) do
343
+ append(nil, nested)
344
+ end
345
+ groups:delete(element)
346
+ else
347
+ elements[#elements + 1] = element
37
348
  end
38
349
  end
350
+ for ____, child in ipairs(children) do
351
+ append(nil, child)
352
+ end
39
353
  local properties = props or ({})
40
354
  if type(component) == "string" then
355
+ for ____, child in ipairs(elements) do
356
+ if type(child) == "function" then
357
+ error("Render functions must be children of a component such as ForEach")
358
+ end
359
+ end
360
+ local visualChildren = elements
41
361
  local input = properties
42
362
  local resolved = __TS__ObjectAssign(
43
363
  {},
@@ -48,18 +368,25 @@ do
48
368
  component == "grid" and ({columns = input.columns or 1}) or ({})
49
369
  )
50
370
  if component == "flow" or component == "grid" then
51
- return {kind = component, props = resolved, children = elements}
371
+ return {kind = component, props = resolved, children = visualChildren}
52
372
  end
53
373
  if #elements > 1 then
54
374
  error("Cell accepts at most one child; use FlowLayout for multiple children", 0)
55
375
  end
56
- return {kind = component, props = resolved, child = elements[1], source = properties.source}
376
+ return {kind = component, props = resolved, child = visualChildren[1], source = properties.source}
57
377
  end
58
378
  local componentProps = #children == 0 and properties or __TS__ObjectAssign({}, properties, {child = #elements == 1 and elements[1] or elements})
59
379
  if component == UI.Fragment and #elements ~= 0 then
60
380
  error("Only empty fragments are supported for now", 0)
61
381
  end
62
- return component(nil, componentProps, elements[1])
382
+ local ____component_1 = component
383
+ local ____temp_0
384
+ if type(elements[1]) == "function" then
385
+ ____temp_0 = nil
386
+ else
387
+ ____temp_0 = elements[1]
388
+ end
389
+ return ____component_1(nil, componentProps, ____temp_0)
63
390
  end
64
391
  UI.JSX = {}
65
392
  end
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wuira",
3
- "version": "0.1.7",
3
+ "version": "0.1.9",
4
4
  "author": {
5
5
  "name": "Kerim Cetinbas",
6
6
  "email": "a.cetinbas@icloud.com"