@rbxts/centurion-ui 2.0.0-rc.3 → 2.0.0-rc.5
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.
- package/README.md +1 -1
- package/package.json +2 -2
- package/src/analyse/init.luau +11 -2
- package/src/analyse/leventine.luau +1 -1
- package/src/analyse/suggest.luau +46 -6
- package/src/app/header.luau +20 -10
- package/src/app/init.luau +23 -4
- package/src/app/suggestions.luau +187 -6
- package/src/init.luau +7 -2
- package/src/px.luau +2 -3
- package/src/state.luau +8 -5
- package/src/ts/index.d.ts +4 -1
- package/src/types.luau +12 -2
package/README.md
CHANGED
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
|
|
32
32
|
- 🧩 **Typed arguments.** Built-in types for players, teams, numbers, colors, durations, vectors and more, with optional, multi-value and rest arguments. Register your own types with custom suggestions.
|
|
33
33
|
|
|
34
|
-
- 🔐 **Guards and permissions.** Guard commands with reusable checks, and control access with
|
|
34
|
+
- 🔐 **Guards and permissions.** Guard commands with reusable checks, and control access with inheritable roles and permissions.
|
|
35
35
|
|
|
36
36
|
- 🔄 **Client-server sync.** Players only receive the commands they're allowed to run, and stay up to date as commands or roles change.
|
|
37
37
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rbxts/centurion-ui",
|
|
3
3
|
"description": "Terminal UI for the Centurion command framework",
|
|
4
|
-
"version": "2.0.0-rc.
|
|
4
|
+
"version": "2.0.0-rc.5",
|
|
5
5
|
"author": "paradoxuum",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"main": "src/ts/init.luau",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"access": "public"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@rbxts/centurion": "^2.0.0-rc.
|
|
36
|
+
"@rbxts/centurion": "^2.0.0-rc.3"
|
|
37
37
|
},
|
|
38
38
|
"scripts": {}
|
|
39
39
|
}
|
package/src/analyse/init.luau
CHANGED
|
@@ -166,8 +166,10 @@ local function analyse(text: string, cursor_pos: number, max_suggestions: number
|
|
|
166
166
|
end
|
|
167
167
|
|
|
168
168
|
local suggestions = {}
|
|
169
|
+
local hidden = 0
|
|
169
170
|
if #arg_suggestions > 0 then
|
|
170
|
-
local matches = suggest(input_token.text, arg_suggestions, max_suggestions)
|
|
171
|
+
local matches, total = suggest(input_token.text, arg_suggestions, max_suggestions)
|
|
172
|
+
hidden = total - #matches
|
|
171
173
|
|
|
172
174
|
for _, suggestion_text in matches do
|
|
173
175
|
local replacement = ""
|
|
@@ -202,6 +204,7 @@ local function analyse(text: string, cursor_pos: number, max_suggestions: number
|
|
|
202
204
|
kind = arg_type.kind,
|
|
203
205
|
},
|
|
204
206
|
suggestions = suggestions,
|
|
207
|
+
hidden_suggestions = hidden,
|
|
205
208
|
} :: types.AnalysisResult
|
|
206
209
|
end
|
|
207
210
|
|
|
@@ -220,7 +223,8 @@ local function analyse(text: string, cursor_pos: number, max_suggestions: number
|
|
|
220
223
|
end
|
|
221
224
|
|
|
222
225
|
local query = table.concat(token_text, " ")
|
|
223
|
-
local matches = suggest(query, to_match, max_suggestions)
|
|
226
|
+
local matches, total = suggest(query, to_match, max_suggestions)
|
|
227
|
+
local hidden = total - #matches
|
|
224
228
|
if cmd_name then
|
|
225
229
|
table.insert(matches, 1, cmd_name)
|
|
226
230
|
end
|
|
@@ -255,6 +259,7 @@ local function analyse(text: string, cursor_pos: number, max_suggestions: number
|
|
|
255
259
|
return {
|
|
256
260
|
result = result,
|
|
257
261
|
suggestions = suggestions,
|
|
262
|
+
hidden_suggestions = hidden,
|
|
258
263
|
} :: types.AnalysisResult
|
|
259
264
|
end
|
|
260
265
|
|
|
@@ -276,8 +281,10 @@ local function analyse(text: string, cursor_pos: number, max_suggestions: number
|
|
|
276
281
|
end
|
|
277
282
|
|
|
278
283
|
local final_suggestions = cmd_result.suggestions
|
|
284
|
+
local hidden_suggestions = cmd_result.hidden_suggestions
|
|
279
285
|
if at_arg and arg_result then
|
|
280
286
|
final_suggestions = arg_result.suggestions
|
|
287
|
+
hidden_suggestions = arg_result.hidden_suggestions
|
|
281
288
|
|
|
282
289
|
-- a subcommand shares the position of its parent's first argument, so
|
|
283
290
|
-- both sets are offered there instead of the argument replacing them
|
|
@@ -299,6 +306,7 @@ local function analyse(text: string, cursor_pos: number, max_suggestions: number
|
|
|
299
306
|
if max_suggestions then
|
|
300
307
|
for i = #merged, max_suggestions + 1, -1 do
|
|
301
308
|
merged[i] = nil
|
|
309
|
+
hidden_suggestions = (hidden_suggestions or 0) + 1
|
|
302
310
|
end
|
|
303
311
|
end
|
|
304
312
|
|
|
@@ -312,6 +320,7 @@ local function analyse(text: string, cursor_pos: number, max_suggestions: number
|
|
|
312
320
|
command = cmd_name,
|
|
313
321
|
argument = arg_result and arg_result.argument or nil,
|
|
314
322
|
suggestions = final_suggestions,
|
|
323
|
+
hidden_suggestions = hidden_suggestions,
|
|
315
324
|
}
|
|
316
325
|
end
|
|
317
326
|
|
|
@@ -51,7 +51,7 @@ local function myers_32(a: string, b: string, a_len: number, b_len: number): num
|
|
|
51
51
|
|
|
52
52
|
-- Set the bits for characters in string a
|
|
53
53
|
for j, a_byte in a_bytes do
|
|
54
|
-
PEQ[a_byte] = OR(PEQ[a_byte], LSHIFT(1, j))
|
|
54
|
+
PEQ[a_byte] = OR(PEQ[a_byte], LSHIFT(1, j - 1))
|
|
55
55
|
end
|
|
56
56
|
|
|
57
57
|
for _, byte in b_bytes do
|
package/src/analyse/suggest.luau
CHANGED
|
@@ -1,10 +1,52 @@
|
|
|
1
1
|
local leventine = require("./leventine")
|
|
2
2
|
|
|
3
3
|
local MIN_SCORE = -math.huge
|
|
4
|
+
local SUBSEQUENCE_BONUS = 100
|
|
4
5
|
|
|
5
|
-
local function
|
|
6
|
+
local function word_start(candidate: string, pos: number): boolean
|
|
7
|
+
return pos == 1 or string.find(string.sub(candidate, pos - 1, pos - 1), "[%s_%-]") ~= nil
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
-- rewards the query's characters appearing in order in the candidate, by how
|
|
11
|
+
-- tightly they're packed and whether they start a word. a flat bonus would
|
|
12
|
+
-- rank loose matches like "rsp" in "forcespawn" above close typos like "esp"
|
|
13
|
+
local function subsequence_bonus(query: string, candidate: string): number
|
|
14
|
+
local first = string.sub(query, 1, 1)
|
|
15
|
+
local best = 0
|
|
16
|
+
|
|
17
|
+
local start = string.find(candidate, first, 1, true)
|
|
18
|
+
while start do
|
|
19
|
+
local pos = start
|
|
20
|
+
for i = 2, #query do
|
|
21
|
+
local found = string.find(candidate, string.sub(query, i, i), pos + 1, true)
|
|
22
|
+
if not found then
|
|
23
|
+
-- later starts can't match either
|
|
24
|
+
return best
|
|
25
|
+
end
|
|
26
|
+
pos = found
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
local tightness = #query / (pos - start + 1)
|
|
30
|
+
-- abbreviations skip a lot, e.g. "tp" for "teleport", so don't punish gaps too hard
|
|
31
|
+
local bonus = SUBSEQUENCE_BONUS * tightness ^ 1.5
|
|
32
|
+
if not word_start(candidate, start) then
|
|
33
|
+
bonus /= 2
|
|
34
|
+
end
|
|
35
|
+
best = math.max(best, bonus)
|
|
36
|
+
|
|
37
|
+
start = string.find(candidate, first, start + 1, true)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
return best
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
-- returns the best matches, and how many there were before being limited
|
|
44
|
+
local function suggest(input: string, candidates: { string }, max_suggestions: number?): ({ string }, number)
|
|
6
45
|
if #input == 0 then
|
|
7
|
-
|
|
46
|
+
if max_suggestions and #candidates > max_suggestions then
|
|
47
|
+
return { unpack(candidates, 1, max_suggestions) }, #candidates
|
|
48
|
+
end
|
|
49
|
+
return candidates, #candidates
|
|
8
50
|
end
|
|
9
51
|
|
|
10
52
|
local normalized = input:lower()
|
|
@@ -17,9 +59,7 @@ local function suggest(input: string, candidates: { string }, max_suggestions: n
|
|
|
17
59
|
else
|
|
18
60
|
score = leventine.score(normalized, candidate, false)
|
|
19
61
|
score = (1 - score / math.max(#normalized, #candidate)) * 100
|
|
20
|
-
|
|
21
|
-
score += 100
|
|
22
|
-
end
|
|
62
|
+
score += subsequence_bonus(normalized, candidate:lower())
|
|
23
63
|
end
|
|
24
64
|
|
|
25
65
|
if score > MIN_SCORE then
|
|
@@ -35,7 +75,7 @@ local function suggest(input: string, candidates: { string }, max_suggestions: n
|
|
|
35
75
|
for i = 1, math.min(max_suggestions or #scored, #scored) do
|
|
36
76
|
table.insert(mapped, scored[i].text)
|
|
37
77
|
end
|
|
38
|
-
return mapped
|
|
78
|
+
return mapped, #scored
|
|
39
79
|
end
|
|
40
80
|
|
|
41
81
|
return suggest
|
package/src/app/header.luau
CHANGED
|
@@ -19,6 +19,7 @@ local source = vide.source
|
|
|
19
19
|
type Header = {
|
|
20
20
|
read order: number?,
|
|
21
21
|
read on_clear: () -> (),
|
|
22
|
+
read on_close: () -> (),
|
|
22
23
|
}
|
|
23
24
|
|
|
24
25
|
-- KeyCode names that aren't what's printed on the key
|
|
@@ -41,7 +42,7 @@ local function key_label(key: Enum.KeyCode): string
|
|
|
41
42
|
return key_labels[key.Name] or key.Name
|
|
42
43
|
end
|
|
43
44
|
|
|
44
|
-
local function
|
|
45
|
+
local function text_button(props: { order: number, label: string, on_activated: () -> () })
|
|
45
46
|
local hovered = source(false)
|
|
46
47
|
|
|
47
48
|
return create "TextButton" {
|
|
@@ -51,7 +52,7 @@ local function clear_button(props: { order: number, on_clear: () -> () })
|
|
|
51
52
|
LayoutOrder = props.order,
|
|
52
53
|
Text = "",
|
|
53
54
|
|
|
54
|
-
Activated = props.
|
|
55
|
+
Activated = props.on_activated,
|
|
55
56
|
MouseEnter = function()
|
|
56
57
|
hovered(true)
|
|
57
58
|
end,
|
|
@@ -61,7 +62,7 @@ local function clear_button(props: { order: number, on_clear: () -> () })
|
|
|
61
62
|
|
|
62
63
|
text {
|
|
63
64
|
auto = "XY",
|
|
64
|
-
text =
|
|
65
|
+
text = props.label,
|
|
65
66
|
text_size = px(state.subtext_size),
|
|
66
67
|
text_style = function()
|
|
67
68
|
return if hovered() then "highlight" else "subtext"
|
|
@@ -85,6 +86,11 @@ local function header(props: Header)
|
|
|
85
86
|
return input() == Enum.PreferredInput.KeyboardAndMouse and #state.activation_keys() > 0
|
|
86
87
|
end
|
|
87
88
|
|
|
89
|
+
-- touch devices have no key to close with, so give them a button instead
|
|
90
|
+
local function show_close()
|
|
91
|
+
return input() == Enum.PreferredInput.Touch
|
|
92
|
+
end
|
|
93
|
+
|
|
88
94
|
return container {
|
|
89
95
|
size = px(UDim2.new(1, 0, 0, 23)),
|
|
90
96
|
order = props.order,
|
|
@@ -99,7 +105,7 @@ local function header(props: Header)
|
|
|
99
105
|
flex():column():vertical("center"):gap(5),
|
|
100
106
|
|
|
101
107
|
image {
|
|
102
|
-
image = state.
|
|
108
|
+
image = state.header_icon,
|
|
103
109
|
size = px(function()
|
|
104
110
|
return UDim2.fromOffset(state.subtext_size(), state.subtext_size())
|
|
105
111
|
end),
|
|
@@ -107,7 +113,7 @@ local function header(props: Header)
|
|
|
107
113
|
return state.theme().highlight
|
|
108
114
|
end,
|
|
109
115
|
visible = function()
|
|
110
|
-
return state.
|
|
116
|
+
return state.header_icon() ~= ""
|
|
111
117
|
end,
|
|
112
118
|
order = 1,
|
|
113
119
|
},
|
|
@@ -115,7 +121,7 @@ local function header(props: Header)
|
|
|
115
121
|
text {
|
|
116
122
|
auto = "XY",
|
|
117
123
|
order = 2,
|
|
118
|
-
text = state.
|
|
124
|
+
text = state.header_title,
|
|
119
125
|
text_size = px(state.subtext_size),
|
|
120
126
|
text_style = "subtext",
|
|
121
127
|
weight = Enum.FontWeight.Bold,
|
|
@@ -130,12 +136,12 @@ local function header(props: Header)
|
|
|
130
136
|
|
|
131
137
|
-- only shown while there's something to clear
|
|
132
138
|
show(show_clear, function()
|
|
133
|
-
return
|
|
139
|
+
return text_button { order = 1, label = "Clear", on_activated = props.on_clear }
|
|
134
140
|
end),
|
|
135
141
|
|
|
136
|
-
-- vertical rule between the clear button and the close hint
|
|
142
|
+
-- vertical rule between the clear button and the close hint or button
|
|
137
143
|
show(function()
|
|
138
|
-
return show_clear() and show_hint()
|
|
144
|
+
return show_clear() and (show_hint() or show_close())
|
|
139
145
|
end, function()
|
|
140
146
|
return background {
|
|
141
147
|
order = 2,
|
|
@@ -172,7 +178,7 @@ local function header(props: Header)
|
|
|
172
178
|
if input() == Enum.PreferredInput.Gamepad then
|
|
173
179
|
return button_name(Enum.KeyCode.ButtonB)
|
|
174
180
|
end
|
|
175
|
-
return key_label(state.activation_keys()[1])
|
|
181
|
+
return #state.activation_keys() > 0 and key_label(state.activation_keys()[1]) or ""
|
|
176
182
|
end,
|
|
177
183
|
text_size = px(state.subtext_size),
|
|
178
184
|
weight = Enum.FontWeight.Bold,
|
|
@@ -188,6 +194,10 @@ local function header(props: Header)
|
|
|
188
194
|
},
|
|
189
195
|
}
|
|
190
196
|
end),
|
|
197
|
+
|
|
198
|
+
show(show_close, function()
|
|
199
|
+
return text_button { order = 4, label = "Close", on_activated = props.on_close }
|
|
200
|
+
end),
|
|
191
201
|
},
|
|
192
202
|
}
|
|
193
203
|
end
|
package/src/app/init.luau
CHANGED
|
@@ -219,6 +219,14 @@ local function app()
|
|
|
219
219
|
display_analysis(analysis())
|
|
220
220
|
end)
|
|
221
221
|
|
|
222
|
+
-- the list can shrink while a later suggestion is selected
|
|
223
|
+
effect(function()
|
|
224
|
+
local count = #analysis().suggestions
|
|
225
|
+
if untrack(selected_suggestion) > count then
|
|
226
|
+
selected_suggestion(math.max(count, 1))
|
|
227
|
+
end
|
|
228
|
+
end)
|
|
229
|
+
|
|
222
230
|
cleanup(UserInputService.InputBegan:Connect(function(input)
|
|
223
231
|
if input.UserInputState ~= Enum.UserInputState.Begin then
|
|
224
232
|
return
|
|
@@ -507,6 +515,10 @@ local function app()
|
|
|
507
515
|
end
|
|
508
516
|
|
|
509
517
|
local selected = analysis_suggestions[selected_suggestion()]
|
|
518
|
+
if selected == nil then
|
|
519
|
+
return ""
|
|
520
|
+
end
|
|
521
|
+
|
|
510
522
|
local suggested = autofill(raw_text(), selected, false)
|
|
511
523
|
if suggested:sub(1, #raw_text()) ~= raw_text() then
|
|
512
524
|
return ""
|
|
@@ -549,7 +561,7 @@ local function app()
|
|
|
549
561
|
|
|
550
562
|
local suggested = analysis().suggestions
|
|
551
563
|
if last_char == "\t" and suggested[1] then
|
|
552
|
-
local selected = suggested[selected_suggestion()]
|
|
564
|
+
local selected = suggested[selected_suggestion()] or suggested[1]
|
|
553
565
|
value = autofill(raw_text(), selected, true)
|
|
554
566
|
end
|
|
555
567
|
|
|
@@ -609,10 +621,13 @@ local function app()
|
|
|
609
621
|
local offset = px.convert((reveal() - 1) * 8)
|
|
610
622
|
return px.get(state.position) + UDim2.fromOffset(0, offset)
|
|
611
623
|
end,
|
|
612
|
-
size =
|
|
624
|
+
size = function()
|
|
613
625
|
local w = state.width()
|
|
614
|
-
|
|
615
|
-
|
|
626
|
+
local viewport = px.viewport().X
|
|
627
|
+
-- never wider than the screen, leaving a margin on either side
|
|
628
|
+
local max_offset = viewport * (1 - w.Scale) - px.convert(16) * 2
|
|
629
|
+
return UDim2.new(w.Scale, math.min(px.convert(w.Offset), max_offset), 0, 0)
|
|
630
|
+
end,
|
|
616
631
|
|
|
617
632
|
padding(px(8)),
|
|
618
633
|
flex():row():gap(1),
|
|
@@ -648,6 +663,10 @@ local function app()
|
|
|
648
663
|
state.logs({})
|
|
649
664
|
refocus()
|
|
650
665
|
end,
|
|
666
|
+
on_close = function()
|
|
667
|
+
state.opened(false)
|
|
668
|
+
state.focused(false)
|
|
669
|
+
end,
|
|
651
670
|
},
|
|
652
671
|
divider { order = 2 },
|
|
653
672
|
|
package/src/app/suggestions.luau
CHANGED
|
@@ -17,12 +17,17 @@ local theme = require("../theme")
|
|
|
17
17
|
local types = require("../types")
|
|
18
18
|
local vide = require("../../vide")
|
|
19
19
|
|
|
20
|
+
local action = vide.action
|
|
21
|
+
local changed = vide.changed
|
|
22
|
+
local cleanup = vide.cleanup
|
|
20
23
|
local create = vide.create
|
|
21
24
|
local derive = vide.derive
|
|
25
|
+
local effect = vide.effect
|
|
22
26
|
local indexes = vide.indexes
|
|
23
27
|
local show = vide.show
|
|
24
28
|
local source = vide.source
|
|
25
29
|
local spring = vide.spring
|
|
30
|
+
local untrack = vide.untrack
|
|
26
31
|
|
|
27
32
|
export type Suggestions = {
|
|
28
33
|
read analysis: () -> types.AnalysisResult,
|
|
@@ -67,12 +72,35 @@ local function pill(props: { text: () -> string, color: () -> Color3, order: num
|
|
|
67
72
|
}
|
|
68
73
|
end
|
|
69
74
|
|
|
70
|
-
local function suggestion_row(
|
|
75
|
+
local function suggestion_row(
|
|
76
|
+
value: () -> types.AnalysisSuggestion,
|
|
77
|
+
i: number,
|
|
78
|
+
props: Suggestions,
|
|
79
|
+
widths: vide.Source<{ [number]: number }>
|
|
80
|
+
)
|
|
71
81
|
local function selected()
|
|
72
82
|
return props.selected_suggestion() == i
|
|
73
83
|
end
|
|
74
84
|
local hovered = source(false)
|
|
75
85
|
|
|
86
|
+
-- the width the row needs without being stretched, so the list can fit the widest
|
|
87
|
+
local name_width = source(0)
|
|
88
|
+
local description_width = source(0)
|
|
89
|
+
|
|
90
|
+
effect(function()
|
|
91
|
+
local width = name_width() + description_width() + px.convert(10)
|
|
92
|
+
if untrack(widths)[i] ~= width then
|
|
93
|
+
local current = table.clone(untrack(widths))
|
|
94
|
+
current[i] = width
|
|
95
|
+
widths(current)
|
|
96
|
+
end
|
|
97
|
+
end)
|
|
98
|
+
cleanup(function()
|
|
99
|
+
local current = table.clone(untrack(widths))
|
|
100
|
+
current[i] = nil
|
|
101
|
+
widths(current)
|
|
102
|
+
end)
|
|
103
|
+
|
|
76
104
|
return create "TextButton" {
|
|
77
105
|
AutomaticSize = Enum.AutomaticSize.XY,
|
|
78
106
|
AutoButtonColor = false,
|
|
@@ -109,6 +137,9 @@ local function suggestion_row(value: () -> types.AnalysisSuggestion, i: number,
|
|
|
109
137
|
order = 1,
|
|
110
138
|
|
|
111
139
|
flex():column():vertical("center"),
|
|
140
|
+
changed("AbsoluteSize", function(size: Vector2)
|
|
141
|
+
name_width(size.X)
|
|
142
|
+
end),
|
|
112
143
|
|
|
113
144
|
-- marks the suggestion Tab will complete
|
|
114
145
|
text {
|
|
@@ -155,6 +186,10 @@ local function suggestion_row(value: () -> types.AnalysisSuggestion, i: number,
|
|
|
155
186
|
show(function()
|
|
156
187
|
return value().description ~= nil
|
|
157
188
|
end, function()
|
|
189
|
+
cleanup(function()
|
|
190
|
+
description_width(0)
|
|
191
|
+
end)
|
|
192
|
+
|
|
158
193
|
return text {
|
|
159
194
|
auto = "XY",
|
|
160
195
|
order = 2,
|
|
@@ -166,6 +201,9 @@ local function suggestion_row(value: () -> types.AnalysisSuggestion, i: number,
|
|
|
166
201
|
xalignment = Enum.TextXAlignment.Right,
|
|
167
202
|
|
|
168
203
|
padding { left = px(28) },
|
|
204
|
+
changed("AbsoluteSize", function(size: Vector2)
|
|
205
|
+
description_width(size.X)
|
|
206
|
+
end),
|
|
169
207
|
}
|
|
170
208
|
end),
|
|
171
209
|
}
|
|
@@ -211,6 +249,9 @@ local function suggestions(props: Suggestions)
|
|
|
211
249
|
return failed() or arg() ~= nil
|
|
212
250
|
end)
|
|
213
251
|
|
|
252
|
+
-- set by the list, which is also at the bottom when it's too short to scroll
|
|
253
|
+
local scrolled_to_bottom = source(true)
|
|
254
|
+
|
|
214
255
|
return background {
|
|
215
256
|
auto = "XY",
|
|
216
257
|
order = props.order,
|
|
@@ -353,17 +394,132 @@ local function suggestions(props: Suggestions)
|
|
|
353
394
|
},
|
|
354
395
|
|
|
355
396
|
show(has_suggestions, function()
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
397
|
+
local content_height = source(0)
|
|
398
|
+
local hovered = source(false)
|
|
399
|
+
local widths = source({} :: { [number]: number })
|
|
400
|
+
|
|
401
|
+
local canvas_y = source(0)
|
|
402
|
+
|
|
403
|
+
-- rows are all the same height, so one is the average of them
|
|
404
|
+
local function row_height()
|
|
405
|
+
return content_height() / math.max(#props.analysis().suggestions, 1)
|
|
406
|
+
end
|
|
407
|
+
|
|
408
|
+
local function visible_height()
|
|
409
|
+
return math.min(content_height(), row_height() * state.visible_suggestions())
|
|
410
|
+
end
|
|
411
|
+
|
|
412
|
+
effect(function()
|
|
413
|
+
scrolled_to_bottom(canvas_y() >= content_height() - visible_height() - 1)
|
|
414
|
+
end)
|
|
415
|
+
|
|
416
|
+
-- only the rows in view decide the width, so a long one further down
|
|
417
|
+
-- doesn't widen the list until it's scrolled to
|
|
418
|
+
local target_width = derive(function()
|
|
419
|
+
local height = row_height()
|
|
420
|
+
if height == 0 then
|
|
421
|
+
return 0
|
|
422
|
+
end
|
|
423
|
+
|
|
424
|
+
local current = widths()
|
|
425
|
+
local first = math.floor(canvas_y() / height) + 1
|
|
426
|
+
local last = math.ceil((canvas_y() + visible_height() - 0.5) / height)
|
|
427
|
+
|
|
428
|
+
local widest = 0
|
|
429
|
+
for i = first, last do
|
|
430
|
+
widest = math.max(widest, current[i] or 0)
|
|
431
|
+
end
|
|
432
|
+
return math.ceil(widest)
|
|
433
|
+
end)
|
|
434
|
+
local sprung_width = spring(target_width, 0.1, 0.8)
|
|
435
|
+
|
|
436
|
+
-- the list grows out from nothing when it first appears
|
|
437
|
+
local opening = source(true)
|
|
438
|
+
effect(function()
|
|
439
|
+
if untrack(opening) and target_width() > 0 and sprung_width() >= target_width() - 0.5 then
|
|
440
|
+
opening(false)
|
|
441
|
+
end
|
|
442
|
+
end)
|
|
443
|
+
|
|
444
|
+
-- after opening, grows instantly so rows are never clipped, and only eases when shrinking
|
|
445
|
+
local function content_width()
|
|
446
|
+
if opening() then
|
|
447
|
+
return sprung_width()
|
|
448
|
+
end
|
|
449
|
+
return math.max(target_width(), sprung_width())
|
|
450
|
+
end
|
|
451
|
+
|
|
452
|
+
return create "ScrollingFrame" {
|
|
453
|
+
AutomaticCanvasSize = Enum.AutomaticSize.Y,
|
|
454
|
+
BackgroundTransparency = 1,
|
|
455
|
+
BorderSizePixel = 0,
|
|
456
|
+
CanvasSize = UDim2.new(),
|
|
457
|
+
ScrollingDirection = Enum.ScrollingDirection.Y,
|
|
458
|
+
LayoutOrder = 4,
|
|
459
|
+
Size = function()
|
|
460
|
+
return UDim2.fromOffset(content_width() + px.convert(6), visible_height() + px.convert(6))
|
|
461
|
+
end,
|
|
462
|
+
|
|
463
|
+
-- the bar sits in the right padding rather than insetting the rows
|
|
464
|
+
ScrollBarThickness = px(3),
|
|
465
|
+
ScrollBarImageColor3 = function()
|
|
466
|
+
return state.theme().subtext
|
|
467
|
+
end,
|
|
468
|
+
ScrollBarImageTransparency = fade.fade(spring(function()
|
|
469
|
+
return if hovered() then 0 else 0.6
|
|
470
|
+
end, 0.2)),
|
|
471
|
+
VerticalScrollBarInset = Enum.ScrollBarInset.None,
|
|
472
|
+
|
|
473
|
+
MouseEnter = function()
|
|
474
|
+
hovered(true)
|
|
475
|
+
end,
|
|
476
|
+
MouseLeave = function()
|
|
477
|
+
hovered(false)
|
|
478
|
+
end,
|
|
479
|
+
|
|
480
|
+
changed("CanvasPosition", function(position: Vector2)
|
|
481
|
+
canvas_y(position.Y)
|
|
482
|
+
end),
|
|
359
483
|
|
|
360
484
|
padding(px(3)),
|
|
361
|
-
|
|
485
|
+
|
|
486
|
+
create "UIListLayout" {
|
|
487
|
+
HorizontalFlex = Enum.UIFlexAlignment.Fill,
|
|
488
|
+
SortOrder = Enum.SortOrder.LayoutOrder,
|
|
489
|
+
|
|
490
|
+
changed("AbsoluteContentSize", function(size: Vector2)
|
|
491
|
+
content_height(size.Y)
|
|
492
|
+
end),
|
|
493
|
+
},
|
|
494
|
+
|
|
495
|
+
-- keep the selected row in view when moving through the list
|
|
496
|
+
action(function(instance: ScrollingFrame)
|
|
497
|
+
effect(function()
|
|
498
|
+
local height = row_height()
|
|
499
|
+
if height == 0 then
|
|
500
|
+
return
|
|
501
|
+
end
|
|
502
|
+
|
|
503
|
+
-- AbsoluteWindowSize lags behind and is 0 when the list first appears,
|
|
504
|
+
-- which would scroll the first row out of view
|
|
505
|
+
local top = (props.selected_suggestion() - 1) * height
|
|
506
|
+
local window = visible_height()
|
|
507
|
+
local y = instance.CanvasPosition.Y
|
|
508
|
+
|
|
509
|
+
if top < y then
|
|
510
|
+
y = top
|
|
511
|
+
elseif top + height > y + window then
|
|
512
|
+
y = top + height - window
|
|
513
|
+
end
|
|
514
|
+
|
|
515
|
+
instance.CanvasPosition = Vector2.new(0, y)
|
|
516
|
+
end)
|
|
517
|
+
end),
|
|
362
518
|
|
|
363
519
|
indexes(function()
|
|
364
520
|
return props.analysis().suggestions
|
|
365
521
|
end, function(value: () -> types.AnalysisSuggestion, i)
|
|
366
|
-
return suggestion_row(value, i, props)
|
|
522
|
+
return suggestion_row(value, i, props, widths)
|
|
367
523
|
end),
|
|
368
524
|
}
|
|
369
525
|
end),
|
|
@@ -379,9 +535,11 @@ local function suggestions(props: Suggestions)
|
|
|
379
535
|
order = 6,
|
|
380
536
|
|
|
381
537
|
padding { x = px(8), y = px(4) },
|
|
538
|
+
flex():column():vertical("center"):between("horizontal"),
|
|
382
539
|
|
|
383
540
|
text {
|
|
384
541
|
auto = "XY",
|
|
542
|
+
order = 1,
|
|
385
543
|
text = function()
|
|
386
544
|
local key = rich.color("%s", state.theme().text)
|
|
387
545
|
if input() == Enum.PreferredInput.Touch then
|
|
@@ -408,6 +566,29 @@ local function suggestions(props: Suggestions)
|
|
|
408
566
|
text_style = "subtext",
|
|
409
567
|
xalignment = Enum.TextXAlignment.Left,
|
|
410
568
|
},
|
|
569
|
+
|
|
570
|
+
-- matches past the limit can't be scrolled to, so typing more is the only way to reach them.
|
|
571
|
+
-- only shown at the end of the list, where they would have been
|
|
572
|
+
show(function()
|
|
573
|
+
return (props.analysis().hidden_suggestions or 0) > 0
|
|
574
|
+
end, function()
|
|
575
|
+
return text {
|
|
576
|
+
auto = "XY",
|
|
577
|
+
order = 2,
|
|
578
|
+
text = function()
|
|
579
|
+
return `+{props.analysis().hidden_suggestions} more`
|
|
580
|
+
end,
|
|
581
|
+
text_size = px(state.subtext_size),
|
|
582
|
+
text_style = "subtext",
|
|
583
|
+
xalignment = Enum.TextXAlignment.Right,
|
|
584
|
+
-- faded rather than removed, so the footer doesn't change width while scrolling
|
|
585
|
+
transparency = spring(function()
|
|
586
|
+
return if scrolled_to_bottom() then 0 else 1
|
|
587
|
+
end, 0.1),
|
|
588
|
+
|
|
589
|
+
padding { left = px(16) },
|
|
590
|
+
}
|
|
591
|
+
end),
|
|
411
592
|
}
|
|
412
593
|
end),
|
|
413
594
|
|
package/src/init.luau
CHANGED
|
@@ -24,6 +24,7 @@ local function mount(keys: { Enum.KeyCode }?)
|
|
|
24
24
|
Name = "Centurion",
|
|
25
25
|
ResetOnSpawn = false,
|
|
26
26
|
ZIndexBehavior = Enum.ZIndexBehavior.Sibling,
|
|
27
|
+
DisplayOrder = state.display_order,
|
|
27
28
|
|
|
28
29
|
app(),
|
|
29
30
|
}
|
|
@@ -41,7 +42,6 @@ local function configure(options: types.OptionsPartial)
|
|
|
41
42
|
set_opt(state.hide_on_lost_focus, options.hide_on_lost_focus)
|
|
42
43
|
set_opt(state.activation_keys, options.activation_keys)
|
|
43
44
|
set_opt(state.theme, options.theme)
|
|
44
|
-
set_opt(state.icon, options.icon)
|
|
45
45
|
set_opt(state.font, options.font)
|
|
46
46
|
set_opt(state.transparency, options.transparency)
|
|
47
47
|
|
|
@@ -51,10 +51,15 @@ local function configure(options: types.OptionsPartial)
|
|
|
51
51
|
set_opt(state.anchor, options.anchor)
|
|
52
52
|
set_opt(state.position, options.position)
|
|
53
53
|
set_opt(state.width, options.width)
|
|
54
|
+
set_opt(state.display_order, options.display_order)
|
|
54
55
|
|
|
56
|
+
set_opt(state.visible_suggestions, options.visible_suggestions)
|
|
55
57
|
set_opt(state.max_suggestions, options.max_suggestions)
|
|
56
|
-
set_opt(state.clear_button, options.clear_button)
|
|
57
58
|
set_opt(state.format_date, options.format_date)
|
|
59
|
+
|
|
60
|
+
set_opt(state.header_title, options.header_title)
|
|
61
|
+
set_opt(state.header_icon, options.header_icon)
|
|
62
|
+
set_opt(state.clear_button, options.clear_button)
|
|
58
63
|
end
|
|
59
64
|
|
|
60
65
|
local function clear()
|
package/src/px.luau
CHANGED
|
@@ -12,6 +12,7 @@ const MIN_SCALE = 0.5
|
|
|
12
12
|
local DOMINANT_AXIS = 0.5
|
|
13
13
|
|
|
14
14
|
local scale = source(1)
|
|
15
|
+
local viewport_size = source(Vector2.new(0, 0))
|
|
15
16
|
|
|
16
17
|
local function modify_scale(scale_value: number): number
|
|
17
18
|
return math.max(scale_value, MIN_SCALE)
|
|
@@ -52,8 +53,6 @@ local function px<T>(value: T | () -> T, mode: Mode? | () -> Mode?): () -> T
|
|
|
52
53
|
end
|
|
53
54
|
|
|
54
55
|
local function mount()
|
|
55
|
-
local viewport_size = source(Vector2.new(0, 0))
|
|
56
|
-
|
|
57
56
|
effect(function()
|
|
58
57
|
local viewport = viewport_size()
|
|
59
58
|
local scaleX = math.log(viewport.X / BASE_RESOLUTION.X, 2)
|
|
@@ -69,7 +68,7 @@ local function mount()
|
|
|
69
68
|
viewport_size(workspace.CurrentCamera.ViewportSize)
|
|
70
69
|
end
|
|
71
70
|
|
|
72
|
-
return setmetatable({ mount = mount, convert = convert, get = px_raw }, {
|
|
71
|
+
return setmetatable({ mount = mount, convert = convert, get = px_raw, viewport = viewport_size }, {
|
|
73
72
|
__call = function<T>(_, value: T | () -> T, mode: Mode? | () -> Mode?): () -> T
|
|
74
73
|
return px(value, mode)
|
|
75
74
|
end,
|
package/src/state.luau
CHANGED
|
@@ -14,15 +14,17 @@ return {
|
|
|
14
14
|
hide_on_lost_focus = source(true),
|
|
15
15
|
theme = source(theme.themes.mocha),
|
|
16
16
|
font = source(Font.fromId(16658246179)),
|
|
17
|
-
|
|
18
|
-
icon = source("rbxassetid://115292290730914"),
|
|
19
|
-
transparency = source(0.2),
|
|
17
|
+
transparency = source(0.1),
|
|
20
18
|
format_date = source(function(log: types.Log): string
|
|
21
19
|
local dateTime = DateTime.fromUnixTimestamp(log.response.timestamp):FormatLocalTime("LT", "en-us")
|
|
22
20
|
local dateParts = dateTime:split(" ")
|
|
23
21
|
return `<b>{dateParts[1]}</b> {dateParts[2]}`
|
|
24
22
|
end),
|
|
25
|
-
|
|
23
|
+
visible_suggestions = source(5),
|
|
24
|
+
max_suggestions = source(50),
|
|
25
|
+
|
|
26
|
+
header_title = source("Centurion"),
|
|
27
|
+
header_icon = source("rbxassetid://115292290730914"),
|
|
26
28
|
clear_button = source(false),
|
|
27
29
|
|
|
28
30
|
text_size = source(19),
|
|
@@ -30,5 +32,6 @@ return {
|
|
|
30
32
|
|
|
31
33
|
anchor = source(Vector2.new(0.5, 0)),
|
|
32
34
|
position = source(UDim2.new(0.5, 0, 0, 0)),
|
|
33
|
-
width = source(UDim.new(0,
|
|
35
|
+
width = source(UDim.new(0, 1000)),
|
|
36
|
+
display_order = source(1000),
|
|
34
37
|
}
|
package/src/ts/index.d.ts
CHANGED
|
@@ -5,10 +5,13 @@ export interface Options {
|
|
|
5
5
|
activation_keys: Enum.KeyCode[];
|
|
6
6
|
theme: Theme;
|
|
7
7
|
font: Font;
|
|
8
|
-
icon: string;
|
|
9
8
|
transparency: number;
|
|
10
9
|
format_date: (log: Log) => string;
|
|
10
|
+
visible_suggestions: number;
|
|
11
11
|
max_suggestions: number;
|
|
12
|
+
|
|
13
|
+
header_title: string;
|
|
14
|
+
header_icon: string;
|
|
12
15
|
clear_button: boolean;
|
|
13
16
|
|
|
14
17
|
text_size: number;
|
package/src/types.luau
CHANGED
|
@@ -10,10 +10,13 @@ export type Options = {
|
|
|
10
10
|
activation_keys: { Enum.KeyCode },
|
|
11
11
|
theme: Theme,
|
|
12
12
|
font: Font,
|
|
13
|
-
icon: string,
|
|
14
13
|
transparency: number,
|
|
15
14
|
format_date: (log: Log) -> string,
|
|
15
|
+
visible_suggestions: number,
|
|
16
16
|
max_suggestions: number,
|
|
17
|
+
|
|
18
|
+
header_title: string,
|
|
19
|
+
header_icon: string,
|
|
17
20
|
clear_button: boolean,
|
|
18
21
|
|
|
19
22
|
text_size: number,
|
|
@@ -22,6 +25,7 @@ export type Options = {
|
|
|
22
25
|
anchor: Vector2,
|
|
23
26
|
width: UDim,
|
|
24
27
|
position: UDim2,
|
|
28
|
+
display_order: number,
|
|
25
29
|
}
|
|
26
30
|
|
|
27
31
|
export type OptionsPartial = {
|
|
@@ -29,10 +33,13 @@ export type OptionsPartial = {
|
|
|
29
33
|
activation_keys: { Enum.KeyCode }?,
|
|
30
34
|
theme: Theme?,
|
|
31
35
|
font: Font?,
|
|
32
|
-
icon: string?,
|
|
33
36
|
transparency: number?,
|
|
34
37
|
format_date: ((log: Log) -> string)?,
|
|
38
|
+
visible_suggestions: number?,
|
|
35
39
|
max_suggestions: number?,
|
|
40
|
+
|
|
41
|
+
header_title: string?,
|
|
42
|
+
header_icon: string?,
|
|
36
43
|
clear_button: boolean?,
|
|
37
44
|
|
|
38
45
|
text_size: number?,
|
|
@@ -41,6 +48,7 @@ export type OptionsPartial = {
|
|
|
41
48
|
anchor: Vector2?,
|
|
42
49
|
width: UDim?,
|
|
43
50
|
position: UDim2?,
|
|
51
|
+
display_order: number?,
|
|
44
52
|
}
|
|
45
53
|
|
|
46
54
|
export type Theme = {
|
|
@@ -75,6 +83,8 @@ export type AnalysisResult = {
|
|
|
75
83
|
command: string?,
|
|
76
84
|
argument: AnalysisArgument?,
|
|
77
85
|
suggestions: { AnalysisSuggestion },
|
|
86
|
+
-- matches left out by the suggestion limit
|
|
87
|
+
hidden_suggestions: number?,
|
|
78
88
|
}
|
|
79
89
|
|
|
80
90
|
export type Log = {
|