wuira 0.1.6 → 0.1.8

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,290 @@
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
+ if not __TS__NumberIsFinite(options.width) or not __TS__NumberIsFinite(options.height) or options.width <= 0 or options.height <= 0 then
163
+ error("Window requires positive finite dimensions")
164
+ end
165
+ local frame = CreateFrame("Frame", nil, UIParent)
166
+ self.Frame = frame
167
+ frame:SetSize(options.width, options.height)
168
+ frame:SetPoint(
169
+ "CENTER",
170
+ UIParent,
171
+ "CENTER",
172
+ 0,
173
+ 0
174
+ )
175
+ frame:SetFrameStrata("DIALOG")
176
+ frame:SetMovable(true)
177
+ frame:SetClampedToScreen(true)
178
+ frame:EnableMouse(true)
179
+ frame:EnableKeyboard(false)
180
+ frame:Hide()
181
+ frame:SetScript(
182
+ "OnKeyDown",
183
+ function(_frame, key)
184
+ local ____opt_0 = frame.IsProtected
185
+ if ____opt_0 and ____opt_0(frame) and InCombatLockdown() then
186
+ if key == "ESCAPE" then
187
+ self:Close()
188
+ end
189
+ return
190
+ end
191
+ frame:SetPropagateKeyboardInput(key ~= "ESCAPE")
192
+ if key == "ESCAPE" then
193
+ self:Close()
194
+ end
195
+ end
196
+ )
197
+ frame:RegisterEvent("PLAYER_REGEN_ENABLED")
198
+ frame:SetScript(
199
+ "OnEvent",
200
+ function()
201
+ if self.pendingClose then
202
+ self:Close()
203
+ end
204
+ end
205
+ )
206
+ end
207
+ function Window.prototype.Open(self, view)
208
+ if self.disposed then
209
+ error("Window is disposed")
210
+ end
211
+ local ____this_3
212
+ ____this_3 = self.Frame
213
+ local ____opt_2 = ____this_3.IsProtected
214
+ if ____opt_2 and ____opt_2(____this_3) and InCombatLockdown() then
215
+ error("Window: update protected content outside combat")
216
+ end
217
+ self.pendingClose = false
218
+ if self.content ~= nil then
219
+ wuira:Unmount(self.content)
220
+ end
221
+ self.content = nil
222
+ self.content = wuira:Mount(view, nil, self.Frame)
223
+ self.Frame:SetPropagateKeyboardInput(true)
224
+ self.Frame:EnableKeyboard(true)
225
+ self.Frame:Show()
226
+ end
227
+ function Window.prototype.BindDragHandle(self, handle)
228
+ handle:EnableMouse(true)
229
+ handle:RegisterForDrag("LeftButton")
230
+ handle:SetScript(
231
+ "OnDragStart",
232
+ function()
233
+ if not InCombatLockdown() then
234
+ self.Frame:StartMoving()
235
+ end
236
+ end
237
+ )
238
+ handle:SetScript(
239
+ "OnDragStop",
240
+ function() return self.Frame:StopMovingOrSizing() end
241
+ )
242
+ return function()
243
+ self.Frame:StopMovingOrSizing()
244
+ handle:RegisterForDrag()
245
+ handle:SetScript("OnDragStart", nil)
246
+ handle:SetScript("OnDragStop", nil)
247
+ end
248
+ end
249
+ function Window.prototype.Close(self)
250
+ local ____this_5
251
+ ____this_5 = self.Frame
252
+ local ____opt_4 = ____this_5.IsProtected
253
+ if ____opt_4 and ____opt_4(____this_5) and InCombatLockdown() then
254
+ self.pendingClose = true
255
+ return
256
+ end
257
+ self.pendingClose = false
258
+ self.Frame:StopMovingOrSizing()
259
+ self.Frame:EnableKeyboard(false)
260
+ self.Frame:Hide()
261
+ if self.content ~= nil then
262
+ wuira:Unmount(self.content)
263
+ end
264
+ self.content = nil
265
+ end
266
+ function Window.prototype.Dispose(self)
267
+ if self.disposed then
268
+ return
269
+ end
270
+ local ____this_7
271
+ ____this_7 = self.Frame
272
+ local ____opt_6 = ____this_7.IsProtected
273
+ if ____opt_6 and ____opt_6(____this_7) and InCombatLockdown() then
274
+ error("Window: dispose protected content outside combat")
275
+ end
276
+ self:Close()
277
+ self.Frame:UnregisterAllEvents()
278
+ self.Frame:SetScript("OnEvent", nil)
279
+ self.Frame:SetScript("OnKeyDown", nil)
280
+ self.disposed = true
281
+ end
282
+ __TS__SetDescriptor(
283
+ Window.prototype,
284
+ "IsOpen",
285
+ {get = function(self)
286
+ return self.Frame:IsShown()
287
+ end},
288
+ true
289
+ )
290
+ 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,10 @@ 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 type { WindowOptions } from "./Window";
19
+ export type { ForEachProps } from "./ForEach";
16
20
  export { GridLayout } from "./GridLayout";
17
21
  export { ProgressBar } from "./ProgressBar";
18
22
  export { Background } from "./decorations/Background";
package/lib/ui/index.lua CHANGED
@@ -32,6 +32,14 @@ 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
35
43
  do
36
44
  local ____GridLayout = require("ui.GridLayout")
37
45
  ____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