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.
@@ -0,0 +1,300 @@
1
+ --[[ Generated with https://github.com/TypeScriptToLua/TypeScriptToLua ]]
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 function __TS__NumberIsFinite(value)
11
+ return type(value) == "number" and value == value and value ~= math.huge and value ~= -math.huge
12
+ end
13
+
14
+ local function __TS__CloneDescriptor(____bindingPattern0)
15
+ local value
16
+ local writable
17
+ local set
18
+ local get
19
+ local configurable
20
+ local enumerable
21
+ enumerable = ____bindingPattern0.enumerable
22
+ configurable = ____bindingPattern0.configurable
23
+ get = ____bindingPattern0.get
24
+ set = ____bindingPattern0.set
25
+ writable = ____bindingPattern0.writable
26
+ value = ____bindingPattern0.value
27
+ local descriptor = {enumerable = enumerable == true, configurable = configurable == true}
28
+ local hasGetterOrSetter = get ~= nil or set ~= nil
29
+ local hasValueOrWritableAttribute = writable ~= nil or value ~= nil
30
+ if hasGetterOrSetter and hasValueOrWritableAttribute then
31
+ error("Invalid property descriptor. Cannot both specify accessors and a value or writable attribute.", 0)
32
+ end
33
+ if get or set then
34
+ descriptor.get = get
35
+ descriptor.set = set
36
+ else
37
+ descriptor.value = value
38
+ descriptor.writable = writable == true
39
+ end
40
+ return descriptor
41
+ end
42
+
43
+ local __TS__DescriptorGet
44
+ do
45
+ local getmetatable = _G.getmetatable
46
+ local ____rawget = _G.rawget
47
+ function __TS__DescriptorGet(self, metatable, key)
48
+ while metatable do
49
+ local rawResult = ____rawget(metatable, key)
50
+ if rawResult ~= nil then
51
+ return rawResult
52
+ end
53
+ local descriptors = ____rawget(metatable, "_descriptors")
54
+ if descriptors then
55
+ local descriptor = descriptors[key]
56
+ if descriptor ~= nil then
57
+ if descriptor.get then
58
+ return descriptor.get(self)
59
+ end
60
+ return descriptor.value
61
+ end
62
+ end
63
+ metatable = getmetatable(metatable)
64
+ end
65
+ end
66
+ end
67
+
68
+ local __TS__DescriptorSet
69
+ do
70
+ local getmetatable = _G.getmetatable
71
+ local ____rawget = _G.rawget
72
+ local rawset = _G.rawset
73
+ function __TS__DescriptorSet(self, metatable, key, value)
74
+ while metatable do
75
+ local descriptors = ____rawget(metatable, "_descriptors")
76
+ if descriptors then
77
+ local descriptor = descriptors[key]
78
+ if descriptor ~= nil then
79
+ if descriptor.set then
80
+ descriptor.set(self, value)
81
+ else
82
+ if descriptor.writable == false then
83
+ error(
84
+ ((("Cannot assign to read only property '" .. key) .. "' of object '") .. tostring(self)) .. "'",
85
+ 0
86
+ )
87
+ end
88
+ descriptor.value = value
89
+ end
90
+ return
91
+ end
92
+ end
93
+ metatable = getmetatable(metatable)
94
+ end
95
+ rawset(self, key, value)
96
+ end
97
+ end
98
+
99
+ local __TS__SetDescriptor
100
+ do
101
+ local getmetatable = _G.getmetatable
102
+ local function descriptorIndex(self, key)
103
+ return __TS__DescriptorGet(
104
+ self,
105
+ getmetatable(self),
106
+ key
107
+ )
108
+ end
109
+ local function descriptorNewIndex(self, key, value)
110
+ return __TS__DescriptorSet(
111
+ self,
112
+ getmetatable(self),
113
+ key,
114
+ value
115
+ )
116
+ end
117
+ function __TS__SetDescriptor(target, key, desc, isPrototype)
118
+ if isPrototype == nil then
119
+ isPrototype = false
120
+ end
121
+ local ____isPrototype_0
122
+ if isPrototype then
123
+ ____isPrototype_0 = target
124
+ else
125
+ ____isPrototype_0 = getmetatable(target)
126
+ end
127
+ local metatable = ____isPrototype_0
128
+ if not metatable then
129
+ metatable = {}
130
+ setmetatable(target, metatable)
131
+ end
132
+ if not isPrototype and not rawget(metatable, "_isOwnDescriptorMetatable") then
133
+ local instanceMetatable = {}
134
+ instanceMetatable._isOwnDescriptorMetatable = true
135
+ setmetatable(instanceMetatable, metatable)
136
+ setmetatable(target, instanceMetatable)
137
+ metatable = instanceMetatable
138
+ end
139
+ local value = rawget(target, key)
140
+ if value ~= nil then
141
+ rawset(target, key, nil)
142
+ end
143
+ if not rawget(metatable, "_descriptors") then
144
+ metatable._descriptors = {}
145
+ end
146
+ metatable._descriptors[key] = __TS__CloneDescriptor(desc)
147
+ metatable.__index = descriptorIndex
148
+ metatable.__newindex = descriptorNewIndex
149
+ end
150
+ end
151
+ -- End of Lua Library inline imports
152
+ local ____exports = {}
153
+ local ____wuira = require("wuira")
154
+ local wuira = ____wuira.wuira
155
+ --- A draggable, standalone UI host. Closing releases its mounted content.
156
+ ____exports.Window = __TS__Class()
157
+ local Window = ____exports.Window
158
+ Window.name = "Window"
159
+ function Window.prototype.____constructor(self, options)
160
+ self.pendingClose = false
161
+ self.disposed = false
162
+ self.moving = false
163
+ if not __TS__NumberIsFinite(options.width) or not __TS__NumberIsFinite(options.height) or options.width <= 0 or options.height <= 0 then
164
+ error("Window requires positive finite dimensions")
165
+ end
166
+ local frame = CreateFrame("Frame", nil, UIParent)
167
+ self.Frame = frame
168
+ frame:SetSize(options.width, options.height)
169
+ frame:SetPoint(
170
+ "CENTER",
171
+ UIParent,
172
+ "CENTER",
173
+ 0,
174
+ 0
175
+ )
176
+ frame:SetFrameStrata("DIALOG")
177
+ frame:SetMovable(true)
178
+ frame:SetClampedToScreen(true)
179
+ frame:EnableMouse(true)
180
+ frame:EnableKeyboard(false)
181
+ frame:Hide()
182
+ frame:SetScript(
183
+ "OnKeyDown",
184
+ function(_frame, key)
185
+ local ____opt_0 = frame.IsProtected
186
+ if ____opt_0 and ____opt_0(frame) and InCombatLockdown() then
187
+ if key == "ESCAPE" then
188
+ self:Close()
189
+ end
190
+ return
191
+ end
192
+ frame:SetPropagateKeyboardInput(key ~= "ESCAPE")
193
+ if key == "ESCAPE" then
194
+ self:Close()
195
+ end
196
+ end
197
+ )
198
+ frame:RegisterEvent("PLAYER_REGEN_ENABLED")
199
+ frame:SetScript(
200
+ "OnEvent",
201
+ function()
202
+ if self.pendingClose then
203
+ self:Close()
204
+ end
205
+ end
206
+ )
207
+ end
208
+ function Window.prototype.Open(self, view)
209
+ if self.disposed then
210
+ error("Window is disposed")
211
+ end
212
+ local ____this_3
213
+ ____this_3 = self.Frame
214
+ local ____opt_2 = ____this_3.IsProtected
215
+ if ____opt_2 and ____opt_2(____this_3) and InCombatLockdown() then
216
+ error("Window: update protected content outside combat")
217
+ end
218
+ self.pendingClose = false
219
+ local next = wuira:Mount(view, nil, self.Frame)
220
+ local previous = self.content
221
+ self.content = next
222
+ if previous ~= nil then
223
+ wuira:Unmount(previous)
224
+ end
225
+ self.Frame:SetPropagateKeyboardInput(true)
226
+ self.Frame:EnableKeyboard(true)
227
+ self.Frame:Show()
228
+ end
229
+ function Window.prototype.BindDragHandle(self, handle)
230
+ handle:EnableMouse(true)
231
+ handle:RegisterForDrag("LeftButton")
232
+ handle:SetScript(
233
+ "OnDragStart",
234
+ function()
235
+ if not InCombatLockdown() then
236
+ self.Frame:StartMoving()
237
+ self.moving = true
238
+ end
239
+ end
240
+ )
241
+ handle:SetScript(
242
+ "OnDragStop",
243
+ function() return self:StopMoving() end
244
+ )
245
+ return function()
246
+ self:StopMoving()
247
+ handle:RegisterForDrag()
248
+ handle:SetScript("OnDragStart", nil)
249
+ handle:SetScript("OnDragStop", nil)
250
+ end
251
+ end
252
+ function Window.prototype.Close(self)
253
+ local ____this_5
254
+ ____this_5 = self.Frame
255
+ local ____opt_4 = ____this_5.IsProtected
256
+ if ____opt_4 and ____opt_4(____this_5) and InCombatLockdown() then
257
+ self.pendingClose = true
258
+ return
259
+ end
260
+ self.pendingClose = false
261
+ self:StopMoving()
262
+ self.Frame:EnableKeyboard(false)
263
+ self.Frame:Hide()
264
+ if self.content ~= nil then
265
+ wuira:Unmount(self.content)
266
+ end
267
+ self.content = nil
268
+ end
269
+ function Window.prototype.Dispose(self)
270
+ if self.disposed then
271
+ return
272
+ end
273
+ local ____this_7
274
+ ____this_7 = self.Frame
275
+ local ____opt_6 = ____this_7.IsProtected
276
+ if ____opt_6 and ____opt_6(____this_7) and InCombatLockdown() then
277
+ error("Window: dispose protected content outside combat")
278
+ end
279
+ self:Close()
280
+ self.Frame:UnregisterAllEvents()
281
+ self.Frame:SetScript("OnEvent", nil)
282
+ self.Frame:SetScript("OnKeyDown", nil)
283
+ self.disposed = true
284
+ end
285
+ function Window.prototype.StopMoving(self)
286
+ if not self.moving then
287
+ return
288
+ end
289
+ self.Frame:StopMovingOrSizing()
290
+ self.moving = false
291
+ end
292
+ __TS__SetDescriptor(
293
+ Window.prototype,
294
+ "IsOpen",
295
+ {get = function(self)
296
+ return self.Frame:IsShown()
297
+ end},
298
+ true
299
+ )
300
+ return ____exports
package/lib/ui/index.d.ts CHANGED
@@ -5,7 +5,7 @@ export { FrameMover } from "./FrameMover";
5
5
  export type { FramePosition, FrameMoverOptions } from "./FrameMover";
6
6
  export { KeybindCapture } from "./KeybindCapture";
7
7
  export type { HoverTrackerOptions, HoverFrame } from "./HoverTracker";
8
- export type { Element, Component } from "./primitives/jsx";
8
+ export type { Element, Component, Children } from "./primitives/jsx";
9
9
  export { Cell } from "./Cell";
10
10
  export { Button } from "./Button";
11
11
  export type { ButtonProps } from "./Button";
@@ -13,6 +13,12 @@ export { SecureButton } from "./SecureButton";
13
13
  export type { SecureAction, SecureButtonProps, MouseButton } from "./SecureButton";
14
14
  export type { CellProps } from "./Cell";
15
15
  export { FlowLayout } from "./FlowLayout";
16
+ export { ForEach } from "./ForEach";
17
+ export { Window } from "./Window";
18
+ export { TextInput } from "./TextInput";
19
+ export { ScrollHost } from "./ScrollHost";
20
+ export type { WindowOptions } from "./Window";
21
+ export type { ForEachProps } from "./ForEach";
16
22
  export { GridLayout } from "./GridLayout";
17
23
  export { ProgressBar } from "./ProgressBar";
18
24
  export { Background } from "./decorations/Background";
package/lib/ui/index.lua CHANGED
@@ -32,6 +32,22 @@ do
32
32
  local ____FlowLayout = require("ui.FlowLayout")
33
33
  ____exports.FlowLayout = ____FlowLayout.FlowLayout
34
34
  end
35
+ do
36
+ local ____ForEach = require("ui.ForEach")
37
+ ____exports.ForEach = ____ForEach.ForEach
38
+ end
39
+ do
40
+ local ____Window = require("ui.Window")
41
+ ____exports.Window = ____Window.Window
42
+ end
43
+ do
44
+ local ____TextInput = require("ui.TextInput")
45
+ ____exports.TextInput = ____TextInput.TextInput
46
+ end
47
+ do
48
+ local ____ScrollHost = require("ui.ScrollHost")
49
+ ____exports.ScrollHost = ____ScrollHost.ScrollHost
50
+ end
35
51
  do
36
52
  local ____GridLayout = require("ui.GridLayout")
37
53
  ____exports.GridLayout = ____GridLayout.GridLayout
@@ -1,4 +1,9 @@
1
1
  --[[ Generated with https://github.com/TypeScriptToLua/TypeScriptToLua ]]
2
+ -- Lua Library inline imports
3
+ local function __TS__NumberIsFinite(value)
4
+ return type(value) == "number" and value == value and value ~= math.huge and value ~= -math.huge
5
+ end
6
+ -- End of Lua Library inline imports
2
7
  local ____exports = {}
3
8
  --- Pure layout calculation in top-left UI coordinates.
4
9
  function ____exports.calculateFlow(self, props, children)
@@ -15,11 +20,31 @@ function ____exports.calculateFlow(self, props, children)
15
20
  local cross = 0
16
21
  local lineSize = 0
17
22
  local count = 0
23
+ local lineStart = 0
24
+ local function alignLine()
25
+ local free = __TS__NumberIsFinite(limit) and math.max(0, limit - cursor) or 0
26
+ local offset = props.justify == "center" and free / 2 or (props.justify == "end" and free or 0)
27
+ do
28
+ local index = lineStart
29
+ while index < #result do
30
+ if horizontal then
31
+ local ____result_index_0, ____x_1 = result[index + 1], "x"
32
+ ____result_index_0[____x_1] = ____result_index_0[____x_1] + offset
33
+ else
34
+ local ____result_index_2, ____y_3 = result[index + 1], "y"
35
+ ____result_index_2[____y_3] = ____result_index_2[____y_3] + offset
36
+ end
37
+ index = index + 1
38
+ end
39
+ end
40
+ lineStart = #result
41
+ end
18
42
  for ____, child in ipairs(children) do
19
43
  local size = horizontal and child.width or child.height
20
44
  local crossSize = horizontal and child.height or child.width
21
45
  local next = count == 0 and 0 or cursor + gap
22
46
  if props.grow and count > 0 and next + size > limit then
47
+ alignLine(nil)
23
48
  cross = cross + (lineSize + lineGap)
24
49
  cursor = 0
25
50
  lineSize = 0
@@ -31,6 +56,7 @@ function ____exports.calculateFlow(self, props, children)
31
56
  lineSize = math.max(lineSize, crossSize)
32
57
  count = count + 1
33
58
  end
59
+ alignLine(nil)
34
60
  return result
35
61
  end
36
62
  return ____exports