@rbxts/centurion-ui 1.0.0-dev-ac608c1 → 1.0.0-dev-ba19f7f

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,3 +1,3 @@
1
- import { ClientAPI } from "@rbxts/centurion";
1
+ import { CenturionClient } from "@rbxts/centurion";
2
2
  import Vide from "@rbxts/vide";
3
- export declare function CenturionApp(api: ClientAPI): Vide.Node;
3
+ export declare function CenturionApp(client: CenturionClient): Vide.Node;
@@ -1,8 +1,6 @@
1
1
  -- Compiled with roblox-ts v2.3.0-dev-26ec859
2
2
  local TS = _G[script]
3
- local _services = TS.import(script, TS.getModule(script, "@rbxts", "services"))
4
- local GuiService = _services.GuiService
5
- local UserInputService = _services.UserInputService
3
+ local UserInputService = TS.import(script, TS.getModule(script, "@rbxts", "services")).UserInputService
6
4
  local _vide = TS.import(script, TS.getModule(script, "@rbxts", "vide").src)
7
5
  local Vide = _vide
8
6
  local derive = _vide.derive
@@ -11,8 +9,8 @@ local Suggestions = _components.Suggestions
11
9
  local Terminal = _components.Terminal
12
10
  local Group = TS.import(script, script.Parent.Parent, "components", "ui", "group").Group
13
11
  local Layer = TS.import(script, script.Parent.Parent, "components", "ui", "layer").Layer
14
- local useAPI = TS.import(script, script.Parent.Parent, "hooks", "use-api").useAPI
15
12
  local useAtom = TS.import(script, script.Parent.Parent, "hooks", "use-atom").useAtom
13
+ local useClient = TS.import(script, script.Parent.Parent, "hooks", "use-client").useClient
16
14
  local useEvent = TS.import(script, script.Parent.Parent, "hooks", "use-event").useEvent
17
15
  local _use_px = TS.import(script, script.Parent.Parent, "hooks", "use-px")
18
16
  local px = _use_px.px
@@ -26,8 +24,8 @@ local MOUSE_INPUT_TYPES = {
26
24
  [Enum.UserInputType.MouseButton2] = true,
27
25
  [Enum.UserInputType.Touch] = true,
28
26
  }
29
- local function CenturionApp(api)
30
- useAPI(api)
27
+ local function CenturionApp(client)
28
+ useClient(client)
31
29
  usePx()
32
30
  local options = useAtom(interfaceOptions)
33
31
  local visible = useAtom(interfaceVisible)
@@ -63,22 +61,20 @@ local function CenturionApp(api)
63
61
  end)
64
62
  return Vide.jsx(Layer, {
65
63
  displayOrder = function()
66
- local _condition = options().displayOrder
67
- if _condition == nil then
68
- _condition = 0
69
- end
70
- return _condition
64
+ return options().displayOrder
71
65
  end,
72
66
  visible = visible,
73
67
  }, Vide.jsx(Group, {
74
68
  anchorPoint = function()
75
- return options().anchorPoint or Vector2.new(0, 0)
69
+ return options().anchorPoint
76
70
  end,
77
71
  size = function()
78
- return options().size or UDim2.new(0, px(1024), 1, 0)
72
+ local size = options().size
73
+ return if typeof(size) == "UDim2" then size else size(px)
79
74
  end,
80
75
  position = function()
81
- return options().position or UDim2.fromOffset(px(16), px(8) + (GuiService:GetGuiInset()).Y)
76
+ local position = options().position
77
+ return if typeof(position) == "UDim2" then position else position(px)
82
78
  end,
83
79
  }, Vide.jsx(Terminal), Vide.jsx(Suggestions), Vide.jsx("uilistlayout", {
84
80
  Padding = function()
@@ -1,7 +1,8 @@
1
- import { ClientAPI } from "@rbxts/centurion";
1
+ import { CenturionClient } from "@rbxts/centurion";
2
2
  import { InterfaceOptions } from "../types";
3
3
  export declare namespace CenturionUI {
4
+ function isVisible(): boolean;
4
5
  function setVisible(visible: boolean): void;
5
6
  function updateOptions(options: Partial<InterfaceOptions>): void;
6
- function create(options?: Partial<InterfaceOptions>): (api: ClientAPI) => void;
7
+ function start(client: CenturionClient, options?: Partial<InterfaceOptions>): void;
7
8
  }
package/out/app/init.lua CHANGED
@@ -16,6 +16,10 @@ do
16
16
  local _container = CenturionUI
17
17
  local MAX_PRELOAD_ATTEMPTS = 3
18
18
  local PRELOAD_ATTEMPT_INTERVAL = 3
19
+ local function isVisible()
20
+ return interfaceVisible()
21
+ end
22
+ _container.isVisible = isVisible
19
23
  local function setVisible(visible)
20
24
  interfaceVisible(visible)
21
25
  end
@@ -27,52 +31,52 @@ do
27
31
  for _k, _v in options do
28
32
  _object[_k] = _v
29
33
  end
34
+ for _k, _v in DEFAULT_INTERFACE_OPTIONS do
35
+ _object[_k] = _v
36
+ end
30
37
  return _object
31
38
  end)
32
39
  end
33
40
  _container.updateOptions = updateOptions
34
41
  local registerCommands
35
- local function create(options)
42
+ local function start(client, options)
36
43
  if options == nil then
37
44
  options = {}
38
45
  end
39
- return function(api)
40
- if api.config.registerBuiltInCommands then
41
- registerCommands(api.registry)
46
+ if client.config.registerBuiltInCommands then
47
+ registerCommands(client.registry)
48
+ end
49
+ updateOptions(options)
50
+ -- Attempt to preload font
51
+ task.spawn(function()
52
+ local _result = options.font
53
+ if _result ~= nil then
54
+ _result = _result.regular
42
55
  end
43
- updateOptions(options)
44
- -- Attempt to preload font
45
- task.spawn(function()
46
- local _result = options.font
47
- if _result ~= nil then
48
- _result = _result.regular
49
- end
50
- local _condition = _result
51
- if _condition == nil then
52
- _condition = DEFAULT_INTERFACE_OPTIONS.font.regular
53
- end
54
- local fontFamily = _condition.Family
55
- local attempts = 0
56
- while attempts < MAX_PRELOAD_ATTEMPTS do
57
- ContentProvider:PreloadAsync({ fontFamily }, function(_, status)
58
- if status == Enum.AssetFetchStatus.Success then
59
- attempts = MAX_PRELOAD_ATTEMPTS
60
- end
61
- end)
62
- if attempts == MAX_PRELOAD_ATTEMPTS then
63
- break
56
+ local _condition = _result
57
+ if _condition == nil then
58
+ _condition = DEFAULT_INTERFACE_OPTIONS.font.regular
59
+ end
60
+ local fontFamily = _condition.Family
61
+ local attempts = 0
62
+ while attempts < MAX_PRELOAD_ATTEMPTS do
63
+ ContentProvider:PreloadAsync({ fontFamily }, function(_, status)
64
+ if status == Enum.AssetFetchStatus.Success then
65
+ attempts = MAX_PRELOAD_ATTEMPTS
64
66
  end
65
- task.wait(PRELOAD_ATTEMPT_INTERVAL)
66
- attempts += 1
67
+ end)
68
+ if attempts == MAX_PRELOAD_ATTEMPTS then
69
+ break
67
70
  end
68
- end)
69
- local target = Players.LocalPlayer:WaitForChild("PlayerGui")
70
- mount(function()
71
- return CenturionApp(api)
72
- end, target)
73
- end
71
+ task.wait(PRELOAD_ATTEMPT_INTERVAL)
72
+ attempts += 1
73
+ end
74
+ end)
75
+ mount(function()
76
+ return CenturionApp(client)
77
+ end, Players.LocalPlayer:WaitForChild("PlayerGui"))
74
78
  end
75
- _container.create = create
79
+ _container.start = start
76
80
  function registerCommands(registry)
77
81
  registry:registerCommand({
78
82
  name = "theme",
@@ -7,8 +7,8 @@ local Vide = _vide
7
7
  local cleanup = _vide.cleanup
8
8
  local effect = _vide.effect
9
9
  local source = _vide.source
10
- local getAPI = TS.import(script, script.Parent.Parent.Parent, "hooks", "use-api").getAPI
11
10
  local useAtom = TS.import(script, script.Parent.Parent.Parent, "hooks", "use-atom").useAtom
11
+ local useClient = TS.import(script, script.Parent.Parent.Parent, "hooks", "use-client").useClient
12
12
  local useEvent = TS.import(script, script.Parent.Parent.Parent, "hooks", "use-event").useEvent
13
13
  local px = TS.import(script, script.Parent.Parent.Parent, "hooks", "use-px").px
14
14
  local _store = TS.import(script, script.Parent.Parent.Parent, "store")
@@ -37,7 +37,7 @@ local function TerminalTextField(_param)
37
37
  local backgroundTransparency = _param.backgroundTransparency
38
38
  local onTextChange = _param.onTextChange
39
39
  local onSubmit = _param.onSubmit
40
- local api = getAPI()
40
+ local client = useClient()
41
41
  local options = useAtom(interfaceOptions)
42
42
  local visible = useAtom(interfaceVisible)
43
43
  local valid = useAtom(terminalTextValid)
@@ -128,7 +128,7 @@ local function TerminalTextField(_param)
128
128
  end
129
129
  newText ..= string.sub(_exp, _condition + 1)
130
130
  end
131
- local argNames = getArgumentNames(api.registry, command)
131
+ local argNames = getArgumentNames(client.registry, command)
132
132
  for i = argIndex + 1, #argNames - 1 do
133
133
  newText = `{newText} {argNames[i + 1]}`
134
134
  end
@@ -186,7 +186,7 @@ local function TerminalTextField(_param)
186
186
  table.remove(pathParts, _arg0 + 1)
187
187
  table.insert(pathParts, suggestionTitle)
188
188
  end
189
- local _nextCommand = api.registry:getCommandByString(formatPartsAsPath(pathParts))
189
+ local _nextCommand = client.registry:getCommandByString(formatPartsAsPath(pathParts))
190
190
  if _nextCommand ~= nil then
191
191
  _nextCommand = _nextCommand.options
192
192
  end
@@ -216,7 +216,7 @@ local function TerminalTextField(_param)
216
216
  return nil
217
217
  end
218
218
  local argIndex = terminalArgIndex()
219
- local _commandArgs = api.registry:getCommand(commandPath)
219
+ local _commandArgs = client.registry:getCommand(commandPath)
220
220
  if _commandArgs ~= nil then
221
221
  _commandArgs = _commandArgs.options.arguments
222
222
  end
@@ -226,10 +226,8 @@ local function TerminalTextField(_param)
226
226
  end
227
227
  local newText = text()
228
228
  local otherSuggestion = suggestion.others[1]
229
- if (string.match(otherSuggestion, "%s")) ~= nil then
230
- otherSuggestion = `"{otherSuggestion}"`
231
- end
232
- local _otherSuggestion = otherSuggestion
229
+ local _newText = newText
230
+ local _exp = #newText
233
231
  local _result = currentTextPart()
234
232
  if _result ~= nil then
235
233
  _result = #_result
@@ -238,7 +236,8 @@ local function TerminalTextField(_param)
238
236
  if _condition_1 == nil then
239
237
  _condition_1 = 0
240
238
  end
241
- newText ..= string.sub(_otherSuggestion, _condition_1 + 1)
239
+ newText = string.sub(_newText, 0, _exp - _condition_1)
240
+ newText ..= if #{ string.match(otherSuggestion, "%s") } == 0 then otherSuggestion else `"{otherSuggestion}"`
242
241
  if argIndex < #commandArgs - 1 then
243
242
  newText ..= " "
244
243
  end
@@ -8,8 +8,8 @@ local Vide = _vide
8
8
  local effect = _vide.effect
9
9
  local source = _vide.source
10
10
  local HISTORY_TEXT_SIZE = TS.import(script, script.Parent.Parent.Parent, "constants", "text").HISTORY_TEXT_SIZE
11
- local getAPI = TS.import(script, script.Parent.Parent.Parent, "hooks", "use-api").getAPI
12
11
  local useAtom = TS.import(script, script.Parent.Parent.Parent, "hooks", "use-atom").useAtom
12
+ local useClient = TS.import(script, script.Parent.Parent.Parent, "hooks", "use-client").useClient
13
13
  local useHistory = TS.import(script, script.Parent.Parent.Parent, "hooks", "use-history").useHistory
14
14
  local useMotion = TS.import(script, script.Parent.Parent.Parent, "hooks", "use-motion").useMotion
15
15
  local px = TS.import(script, script.Parent.Parent.Parent, "hooks", "use-px").px
@@ -37,7 +37,7 @@ local TerminalTextField = TS.import(script, script.Parent, "terminal-text-field"
37
37
  local MAX_HEIGHT = HISTORY_TEXT_SIZE * 10
38
38
  local TEXT_FIELD_HEIGHT = 40
39
39
  local function Terminal()
40
- local api = getAPI()
40
+ local client = useClient()
41
41
  local options = useAtom(interfaceOptions)
42
42
  local missingArgs = source({})
43
43
  local history = useHistory()
@@ -114,8 +114,8 @@ local function Terminal()
114
114
  -- If the text ends in a space, we want to count that as having traversed
115
115
  -- to the next "part" of the text.
116
116
  local atNextPart = string.sub(text, -1) == " "
117
- local path = getValidPath(api.registry, parts)
118
- local command = if path ~= nil then api.registry:getCommand(path) else nil
117
+ local path = getValidPath(client.registry, parts)
118
+ local command = if path ~= nil then client.registry:getCommand(path) else nil
119
119
  if command ~= nil then
120
120
  -- Check for missing arguments
121
121
  local missing = getMissingArgs(command, parts)
@@ -140,7 +140,7 @@ local function Terminal()
140
140
  if command == nil or argIndex == -1 then
141
141
  -- Get command suggestions
142
142
  local parentPath = if not (#parts == 0) then RegistryPath.new(ArrayUtil.slice(parts, 0, #parts - (if atNextPart then 0 else 1))) else nil
143
- local _exp = api.registry
143
+ local _exp = client.registry
144
144
  local _result = parentPath
145
145
  if _result ~= nil then
146
146
  _result = _result:isEmpty()
@@ -177,7 +177,7 @@ local function Terminal()
177
177
  local numArgs = _condition
178
178
  endIndex = if numArgs ~= "rest" then i + (numArgs - 1) else nil
179
179
  end
180
- local _registry = api.registry
180
+ local _registry = client.registry
181
181
  local _result = currentArg
182
182
  if _result ~= nil then
183
183
  _result = _result.type
@@ -236,9 +236,9 @@ local function Terminal()
236
236
  end,
237
237
  onSubmit = function()
238
238
  local commandPath = currentCommandPath()
239
- local command = if commandPath ~= nil then api.registry:getCommand(commandPath) else nil
239
+ local command = if commandPath ~= nil then client.registry:getCommand(commandPath) else nil
240
240
  if commandPath == nil or command == nil then
241
- api.dispatcher:addHistoryEntry({
241
+ client.dispatcher:addHistoryEntry({
242
242
  success = false,
243
243
  text = "Command not found.",
244
244
  sentAt = os.time(),
@@ -247,7 +247,7 @@ local function Terminal()
247
247
  end
248
248
  local missing = missingArgs()
249
249
  if not (#missing == 0) then
250
- api.dispatcher:addHistoryEntry({
250
+ client.dispatcher:addHistoryEntry({
251
251
  success = false,
252
252
  text = `Missing arguments: {table.concat(missing, ", ")}`,
253
253
  sentAt = os.time(),
@@ -255,7 +255,7 @@ local function Terminal()
255
255
  return nil
256
256
  end
257
257
  local args = ArrayUtil.slice(terminalTextParts(), commandPath:size())
258
- api.dispatcher:run(commandPath, args)
258
+ client.dispatcher:run(commandPath, args)
259
259
  end,
260
260
  }))
261
261
  end
@@ -1,18 +1,25 @@
1
1
  -- Compiled with roblox-ts v2.3.0-dev-26ec859
2
2
  local TS = _G[script]
3
+ local GuiService = TS.import(script, TS.getModule(script, "@rbxts", "services")).GuiService
3
4
  local DefaultPalette = TS.import(script, script.Parent.Parent, "palette").DefaultPalette
4
5
  local DEFAULT_INTERFACE_OPTIONS = {
6
+ anchorPoint = Vector2.new(),
7
+ position = function(px)
8
+ return UDim2.fromOffset(px(16), px(8) + (GuiService:GetGuiInset()).Y)
9
+ end,
10
+ size = function(px)
11
+ return UDim2.new(0, px(1024), 1, 0)
12
+ end,
5
13
  displayOrder = 1000,
6
- activationKeys = { Enum.KeyCode.F2 },
14
+ backgroundTransparency = 0.2,
7
15
  hideOnLostFocus = true,
16
+ activationKeys = { Enum.KeyCode.F2 },
8
17
  font = {
9
18
  regular = Font.new("rbxassetid://16658221428"),
10
19
  medium = Font.new("rbxassetid://16658221428", Enum.FontWeight.Medium),
11
20
  bold = Font.new("rbxassetid://16658221428", Enum.FontWeight.Bold),
12
21
  },
13
22
  palette = DefaultPalette.mocha,
14
- backgroundTransparency = 0.2,
15
- showShortcutSuggestions = true,
16
23
  }
17
24
  return {
18
25
  DEFAULT_INTERFACE_OPTIONS = DEFAULT_INTERFACE_OPTIONS,
@@ -0,0 +1,2 @@
1
+ import { CenturionClient } from "@rbxts/centurion";
2
+ export declare function useClient(client?: CenturionClient): CenturionClient;
@@ -0,0 +1,17 @@
1
+ -- Compiled with roblox-ts v2.3.0-dev-26ec859
2
+ local TS = _G[script]
3
+ local source = TS.import(script, TS.getModule(script, "@rbxts", "vide").src).source
4
+ local clientState = source()
5
+ local function useClient(client)
6
+ local value = clientState()
7
+ if value ~= nil then
8
+ return value
9
+ end
10
+ local _arg0 = client ~= nil
11
+ assert(_arg0, "No client has been set.")
12
+ clientState(client)
13
+ return client
14
+ end
15
+ return {
16
+ useClient = useClient,
17
+ }
@@ -7,15 +7,15 @@ local derive = _vide.derive
7
7
  local source = _vide.source
8
8
  local HISTORY_TEXT_SIZE = TS.import(script, script.Parent.Parent, "constants", "text").HISTORY_TEXT_SIZE
9
9
  local interfaceOptions = TS.import(script, script.Parent.Parent, "store").interfaceOptions
10
- local getAPI = TS.import(script, script.Parent, "use-api").getAPI
11
10
  local useAtom = TS.import(script, script.Parent, "use-atom").useAtom
11
+ local useClient = TS.import(script, script.Parent, "use-client").useClient
12
12
  local useEvent = TS.import(script, script.Parent, "use-event").useEvent
13
13
  local px = TS.import(script, script.Parent, "use-px").px
14
14
  local function useHistory()
15
- local api = getAPI()
15
+ local client = useClient()
16
16
  local options = useAtom(interfaceOptions)
17
- local history = source(api.dispatcher:getHistory())
18
- useEvent(api.dispatcher.historyUpdated, function(entries)
17
+ local history = source(client.dispatcher:getHistory())
18
+ useEvent(client.dispatcher.historyUpdated, function(entries)
19
19
  local _array = {}
20
20
  local _length = #_array
21
21
  table.move(entries, 1, #entries, _length + 1, _array)
@@ -1,4 +1,4 @@
1
- interface ScaleFunction {
1
+ export interface ScaleFunction {
2
2
  /**
3
3
  * Scales `pixels` based on the current viewport size and rounds the result.
4
4
  */
@@ -33,4 +33,3 @@ export declare const px: ScaleFunction;
33
33
  * called once in `Vide.mount`.
34
34
  */
35
35
  export declare function usePx(): void;
36
- export {};
package/out/types.d.ts CHANGED
@@ -1,11 +1,12 @@
1
1
  import { CommandShortcut, HistoryEntry } from "@rbxts/centurion";
2
+ import { ScaleFunction } from "./hooks/use-px";
2
3
  import { InterfacePalette } from "./palette";
3
4
  export interface InterfaceOptions {
4
- anchorPoint?: Vector2;
5
- size?: UDim2;
6
- position?: UDim2;
7
- backgroundTransparency?: number;
8
- displayOrder?: number;
5
+ anchorPoint: Vector2;
6
+ size: UDim2 | ((px: ScaleFunction) => UDim2);
7
+ position: UDim2 | ((px: ScaleFunction) => UDim2);
8
+ displayOrder: number;
9
+ backgroundTransparency: number;
9
10
  hideOnLostFocus: boolean;
10
11
  activationKeys: Enum.KeyCode[];
11
12
  font: {
@@ -14,7 +15,6 @@ export interface InterfaceOptions {
14
15
  bold: Font;
15
16
  };
16
17
  palette: InterfacePalette;
17
- showShortcutSuggestions?: boolean;
18
18
  }
19
19
  export interface HistoryLineData {
20
20
  entry: HistoryEntry;
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": "1.0.0-dev-ac608c1",
4
+ "version": "1.0.0-dev-ba19f7f",
5
5
  "author": "paradoxuum",
6
6
  "license": "MIT",
7
7
  "main": "out/init.lua",
@@ -32,7 +32,7 @@
32
32
  "dev": "shx rm -rf out && rbxtsc -w"
33
33
  },
34
34
  "devDependencies": {
35
- "@rbxts/centurion": "^1.0.0-dev-ac608c1",
35
+ "@rbxts/centurion": "^1.0.0-dev-ba19f7f",
36
36
  "@rbxts/compiler-types": "2.3.0-types.1",
37
37
  "@rbxts/types": "^1.0.794",
38
38
  "roblox-ts": "2.3.0-dev-26ec859",
@@ -1,3 +0,0 @@
1
- import { ClientAPI } from "@rbxts/centurion";
2
- export declare function getAPI(): ClientAPI;
3
- export declare function useAPI(clientAPI: ClientAPI): import("@rbxts/vide").Source<ClientAPI | undefined>;
@@ -1,18 +0,0 @@
1
- -- Compiled with roblox-ts v2.3.0-dev-26ec859
2
- local TS = _G[script]
3
- local source = TS.import(script, TS.getModule(script, "@rbxts", "vide").src).source
4
- local api = source()
5
- local function getAPI()
6
- local value = api()
7
- local _arg0 = value ~= nil
8
- assert(_arg0, "Client API has not been set")
9
- return value
10
- end
11
- local function useAPI(clientAPI)
12
- api(clientAPI)
13
- return api
14
- end
15
- return {
16
- getAPI = getAPI,
17
- useAPI = useAPI,
18
- }