@rbxts/centurion-ui 1.0.0-dev-e01f578 → 1.0.0-dev-47fa67f

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  <div align="center">
2
2
  <a href="https://centurion.paradoxum.dev/" target="_blank">
3
- <img src="../../docs/src/assets/logo.webp" width="150" />
3
+ <img src="https://raw.githubusercontent.com/paradoxuum/centurion/main/docs/src/assets/logo.webp" width="150" />
4
4
  </a>
5
5
 
6
6
  <h1>Centurion - UI</h1>
@@ -26,4 +26,4 @@
26
26
  <a href="https://centurion.paradoxum.dev/">📖 Documentation</a>
27
27
  </div>
28
28
 
29
- <img src="../../public/banner.png" />
29
+ <img src="https://raw.githubusercontent.com/paradoxuum/centurion/main/public/banner.png" />
@@ -1,6 +1,7 @@
1
1
  import { ClientAPI } from "@rbxts/centurion";
2
2
  import { InterfaceOptions } from "../types";
3
3
  export declare namespace CenturionUI {
4
+ function setVisible(visible: boolean): void;
4
5
  function updateOptions(options: Partial<InterfaceOptions>): void;
5
6
  function create(options?: Partial<InterfaceOptions>): (api: ClientAPI) => void;
6
7
  }
package/out/app/init.lua CHANGED
@@ -7,13 +7,19 @@ local Players = _services.Players
7
7
  local mount = TS.import(script, TS.getModule(script, "@rbxts", "vide").src).mount
8
8
  local DEFAULT_INTERFACE_OPTIONS = TS.import(script, script.Parent, "constants", "options").DEFAULT_INTERFACE_OPTIONS
9
9
  local DefaultPalette = TS.import(script, script.Parent, "palette").DefaultPalette
10
- local interfaceOptions = TS.import(script, script.Parent, "store").interfaceOptions
10
+ local _store = TS.import(script, script.Parent, "store")
11
+ local interfaceOptions = _store.interfaceOptions
12
+ local interfaceVisible = _store.interfaceVisible
11
13
  local CenturionApp = TS.import(script, script, "centurion-app").CenturionApp
12
14
  local CenturionUI = {}
13
15
  do
14
16
  local _container = CenturionUI
15
17
  local MAX_PRELOAD_ATTEMPTS = 3
16
18
  local PRELOAD_ATTEMPT_INTERVAL = 3
19
+ local function setVisible(visible)
20
+ interfaceVisible(visible)
21
+ end
22
+ _container.setVisible = setVisible
17
23
  local function updateOptions(options)
18
24
  interfaceOptions(function(prev)
19
25
  local _object = table.clone(prev)
@@ -25,33 +31,13 @@ do
25
31
  end)
26
32
  end
27
33
  _container.updateOptions = updateOptions
28
- local function registerCommands(registry)
29
- registry:registerCommand({
30
- name = "theme",
31
- description = "Change the terminal's theme",
32
- arguments = { {
33
- name = "name",
34
- description = "The name of the theme",
35
- type = CenturionType.String,
36
- suggestions = { "mocha", "macchiato", "frappe", "latte" },
37
- } },
38
- }, function(ctx, theme)
39
- if not (DefaultPalette[theme] ~= nil) then
40
- ctx:error("Invalid theme")
41
- return nil
42
- end
43
- updateOptions({
44
- palette = DefaultPalette[theme],
45
- })
46
- ctx:reply(`Set theme to '{theme}'`)
47
- end, { "centurion" })
48
- end
34
+ local registerCommands
49
35
  local function create(options)
50
36
  if options == nil then
51
37
  options = {}
52
38
  end
53
39
  return function(api)
54
- if api.options.registerBuiltInCommands then
40
+ if api.config.registerBuiltInCommands then
55
41
  registerCommands(api.registry)
56
42
  end
57
43
  updateOptions(options)
@@ -87,6 +73,27 @@ do
87
73
  end
88
74
  end
89
75
  _container.create = create
76
+ function registerCommands(registry)
77
+ registry:registerCommand({
78
+ name = "theme",
79
+ description = "Change the terminal's theme",
80
+ arguments = { {
81
+ name = "name",
82
+ description = "The name of the theme",
83
+ type = CenturionType.String,
84
+ suggestions = { "mocha", "macchiato", "frappe", "latte" },
85
+ } },
86
+ }, function(ctx, theme)
87
+ if not (DefaultPalette[theme] ~= nil) then
88
+ ctx:error("Invalid theme")
89
+ return nil
90
+ end
91
+ updateOptions({
92
+ palette = DefaultPalette[theme],
93
+ })
94
+ ctx:reply(`Set theme to '{theme}'`)
95
+ end, { "centurion" })
96
+ end
90
97
  end
91
98
  return {
92
99
  CenturionUI = CenturionUI,
@@ -7,6 +7,7 @@ local subscribe = TS.import(script, TS.getModule(script, "@rbxts", "charm").src)
7
7
  local UserInputService = TS.import(script, TS.getModule(script, "@rbxts", "services")).UserInputService
8
8
  local _vide = TS.import(script, TS.getModule(script, "@rbxts", "vide").src)
9
9
  local Vide = _vide
10
+ local cleanup = _vide.cleanup
10
11
  local effect = _vide.effect
11
12
  local source = _vide.source
12
13
  local getAPI = TS.import(script, script.Parent.Parent.Parent, "hooks", "use-api").getAPI
@@ -14,8 +15,6 @@ local useAtom = TS.import(script, script.Parent.Parent.Parent, "hooks", "use-ato
14
15
  local useEvent = TS.import(script, script.Parent.Parent.Parent, "hooks", "use-event").useEvent
15
16
  local px = TS.import(script, script.Parent.Parent.Parent, "hooks", "use-px").px
16
17
  local _store = TS.import(script, script.Parent.Parent.Parent, "store")
17
- local commandHistory = _store.commandHistory
18
- local commandHistoryIndex = _store.commandHistoryIndex
19
18
  local currentArgIndex = _store.currentArgIndex
20
19
  local currentCommandPath = _store.currentCommandPath
21
20
  local currentSuggestion = _store.currentSuggestion
@@ -42,6 +41,8 @@ local function TerminalTextField(_param)
42
41
  local visible = useAtom(interfaceVisible)
43
42
  local valid = useAtom(terminalTextValid)
44
43
  local ref = source(nil)
44
+ local commandHistory = source({})
45
+ local commandHistoryIndex = source(nil)
45
46
  local text = source("")
46
47
  local suggestionText = source("")
47
48
  -- Focus text field when terminal becomes visible
@@ -64,16 +65,22 @@ local function TerminalTextField(_param)
64
65
  return nil
65
66
  end
66
67
  local historyIndex = commandHistoryIndex()
67
- if (up and historyIndex == 0) or (not up and historyIndex == -1) then
68
+ if not up and historyIndex == nil then
68
69
  return nil
69
70
  end
70
- local newIndex
71
- if up then
72
- newIndex = if historyIndex == -1 then #history - 1 else historyIndex - 1
73
- else
74
- newIndex = if historyIndex ~= #history - 1 then historyIndex + 1 else -1
71
+ local lastIndex = #history - 1
72
+ if not up and historyIndex == lastIndex then
73
+ text("")
74
+ suggestionText("")
75
+ commandHistoryIndex(nil)
76
+ return nil
77
+ end
78
+ local _condition = historyIndex
79
+ if _condition == nil then
80
+ _condition = #history
75
81
  end
76
- local newText = if newIndex ~= -1 then history[newIndex + 1] else ""
82
+ local newIndex = math.clamp(_condition + (if up then -1 else 1), 0, lastIndex)
83
+ local newText = history[newIndex + 1]
77
84
  text(newText)
78
85
  suggestionText("")
79
86
  commandHistoryIndex(newIndex)
@@ -82,7 +89,7 @@ local function TerminalTextField(_param)
82
89
  textBox.CursorPosition = #newText + 1
83
90
  end
84
91
  end
85
- subscribe(currentSuggestion, function(suggestion)
92
+ local suggestionConnection = subscribe(currentSuggestion, function(suggestion)
86
93
  if suggestion == nil then
87
94
  suggestionText("")
88
95
  return nil
@@ -113,6 +120,7 @@ local function TerminalTextField(_param)
113
120
  end
114
121
  suggestionText(newText)
115
122
  end)
123
+ cleanup(suggestionConnection)
116
124
  useEvent(UserInputService.InputBegan, function(input)
117
125
  local textBox = ref()
118
126
  local _condition = textBox == nil
@@ -276,17 +284,15 @@ local function TerminalTextField(_param)
276
284
  local currentText = textBox.Text
277
285
  local history = commandHistory()
278
286
  if currentText ~= "" and (#history == 0 or history[#history] ~= currentText) then
279
- commandHistory(function(prev)
280
- local _array = {}
281
- local _length = #_array
282
- local _prevLength = #prev
283
- table.move(prev, 1, _prevLength, _length + 1, _array)
284
- _length += _prevLength
285
- _array[_length + 1] = textBox.Text
286
- return _array
287
- end)
287
+ local _array = {}
288
+ local _length = #_array
289
+ local _historyLength = #history
290
+ table.move(history, 1, _historyLength, _length + 1, _array)
291
+ _length += _historyLength
292
+ _array[_length + 1] = textBox.Text
293
+ commandHistory(_array)
288
294
  end
289
- commandHistoryIndex(-1)
295
+ commandHistoryIndex(nil)
290
296
  local _result = onSubmit
291
297
  if _result ~= nil then
292
298
  _result(currentText)
@@ -295,7 +301,10 @@ local function TerminalTextField(_param)
295
301
  text("")
296
302
  end,
297
303
  textChanged = function(currentText)
298
- commandHistoryIndex(-1)
304
+ local historyIndex = commandHistoryIndex()
305
+ if historyIndex ~= nil and currentText ~= commandHistory()[historyIndex + 1] then
306
+ commandHistoryIndex(nil)
307
+ end
299
308
  text(currentText)
300
309
  end,
301
310
  zIndex = 2,
@@ -45,7 +45,8 @@ local px = setmetatable({
45
45
  ]]
46
46
  local function usePx()
47
47
  local camera = Workspace.CurrentCamera
48
- assert(camera, "CurrentCamera is not set")
48
+ local _arg0 = camera ~= nil
49
+ assert(_arg0, "CurrentCamera is not set")
49
50
  local updateScale = debounce(function()
50
51
  local viewport = camera.ViewportSize
51
52
  local width = math.log(viewport.X / BASE_RESOLUTION.X, 2)
package/out/store.d.ts CHANGED
@@ -1,12 +1,10 @@
1
1
  import { ImmutableRegistryPath } from "@rbxts/centurion";
2
- import { InterfaceOptions, Suggestion } from "./types";
2
+ import { Suggestion } from "./types";
3
3
  export declare const interfaceVisible: import("@rbxts/charm").Atom<boolean>;
4
- export declare const interfaceOptions: import("@rbxts/charm").Atom<InterfaceOptions>;
4
+ export declare const interfaceOptions: import("@rbxts/charm").Atom<import("./types").InterfaceOptions>;
5
5
  export declare const mouseOverInterface: import("@rbxts/charm").Atom<boolean>;
6
6
  export declare const currentCommandPath: import("@rbxts/charm").Atom<ImmutableRegistryPath | undefined>;
7
7
  export declare const currentArgIndex: import("@rbxts/charm").Atom<number | undefined>;
8
- export declare const commandHistory: import("@rbxts/charm").Atom<string[]>;
9
- export declare const commandHistoryIndex: import("@rbxts/charm").Atom<number>;
10
8
  export declare const currentSuggestion: import("@rbxts/charm").Atom<Suggestion | undefined>;
11
9
  export declare const terminalText: import("@rbxts/charm").Atom<string>;
12
10
  export declare const terminalTextParts: import("@rbxts/charm").Molecule<string[]>;
package/out/store.lua CHANGED
@@ -10,8 +10,6 @@ local interfaceOptions = atom(DEFAULT_INTERFACE_OPTIONS)
10
10
  local mouseOverInterface = atom(false)
11
11
  local currentCommandPath = atom(nil)
12
12
  local currentArgIndex = atom(nil)
13
- local commandHistory = atom({})
14
- local commandHistoryIndex = atom(-1)
15
13
  local currentSuggestion = atom(nil)
16
14
  local terminalText = atom("")
17
15
  local terminalTextParts = computed(function()
@@ -34,8 +32,6 @@ return {
34
32
  mouseOverInterface = mouseOverInterface,
35
33
  currentCommandPath = currentCommandPath,
36
34
  currentArgIndex = currentArgIndex,
37
- commandHistory = commandHistory,
38
- commandHistoryIndex = commandHistoryIndex,
39
35
  currentSuggestion = currentSuggestion,
40
36
  terminalText = terminalText,
41
37
  terminalTextParts = terminalTextParts,
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-e01f578",
4
+ "version": "1.0.0-dev-47fa67f",
5
5
  "author": "paradoxuum",
6
6
  "license": "MIT",
7
7
  "main": "out/init.lua",
@@ -32,22 +32,22 @@
32
32
  "dev": "shx rm -rf out && rbxtsc -w"
33
33
  },
34
34
  "devDependencies": {
35
- "@rbxts/centurion": "^1.0.0-dev-e01f578",
35
+ "@rbxts/centurion": "^1.0.0-dev-47fa67f",
36
36
  "@rbxts/compiler-types": "2.3.0-types.1",
37
- "@rbxts/types": "^1.0.790",
37
+ "@rbxts/types": "^1.0.792",
38
38
  "roblox-ts": "2.3.0-dev-26ec859",
39
39
  "shx": "^0.3.4",
40
- "typescript": "~5.5.3"
40
+ "typescript": "~5.5.4"
41
41
  },
42
42
  "dependencies": {
43
43
  "@rbxts/charm": "^0.5.2",
44
44
  "@rbxts/ripple": "^0.8.2",
45
45
  "@rbxts/services": "^1.5.4",
46
46
  "@rbxts/set-timeout": "^1.1.2",
47
- "@rbxts/vide": "^0.4.1"
47
+ "@rbxts/vide": "^0.4.2"
48
48
  },
49
49
  "peerDependencies": {
50
- "@rbxts/centurion": "^1.0.0-dev-e01f578"
50
+ "@rbxts/centurion": "^1.0.0-dev"
51
51
  },
52
52
  "stableVersion": "1.0.0"
53
53
  }