@rbxts/app-forge 0.6.0-alpha.63 → 0.6.0-alpha.65

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.
@@ -13,6 +13,7 @@ local function App(props)
13
13
  local _name_1 = props.name
14
14
  local _arg1 = {
15
15
  constructor = constructor,
16
+ renderGroup = props.renderGroup,
16
17
  visible = props.visible,
17
18
  rules = props.rules,
18
19
  }
@@ -2,4 +2,7 @@ import Vide from "@rbxts/vide";
2
2
  import type Types from "./types";
3
3
  import type AppForge from ".";
4
4
  export declare function createSource(name: AppNames, forge: AppForge): typeof Vide.source | undefined;
5
+ export declare function normalizeGroups(group: GroupNames | GroupNames[]): GroupNames[];
6
+ export declare function collectByGroup(groups: GroupNames[], filter?: (name: AppNames) => boolean): AppNames[];
7
+ export declare function renderNames(props: Types.Props.Main, names: AppNames[], forge: AppForge): (ScreenGui | Frame)[];
5
8
  export declare function Render(props: Types.Props.Main): Vide.Node;
@@ -28,6 +28,63 @@ local function createSource(name, forge)
28
28
  _sources_1[_exp] = _arg1
29
29
  return source
30
30
  end
31
+ local function normalizeGroups(group)
32
+ local _group = group
33
+ local _result
34
+ if type(_group) == "table" then
35
+ local _array = {}
36
+ local _length = #_array
37
+ table.move(group, 1, #group, _length + 1, _array)
38
+ _result = _array
39
+ else
40
+ _result = { group }
41
+ end
42
+ return _result
43
+ end
44
+ local function collectByGroup(groups, filter)
45
+ local result = {}
46
+ -- ▼ ReadonlyMap.forEach ▼
47
+ local _callback = function(app, name)
48
+ local appGroup = app.renderGroup
49
+ if not (appGroup ~= "" and appGroup) then
50
+ return nil
51
+ end
52
+ if not (table.find(groups, appGroup) ~= nil) then
53
+ return nil
54
+ end
55
+ if filter and not filter(name) then
56
+ return nil
57
+ end
58
+ local _name = name
59
+ table.insert(result, _name)
60
+ end
61
+ for _k, _v in AppRegistry do
62
+ _callback(_v, _k, AppRegistry)
63
+ end
64
+ -- ▲ ReadonlyMap.forEach ▲
65
+ return result
66
+ end
67
+ local function renderNames(props, names, forge)
68
+ if #names == 0 then
69
+ error("No app names provided to renderApps")
70
+ end
71
+ -- ▼ ReadonlyArray.map ▼
72
+ local _newValue = table.create(#names)
73
+ local _callback = function(name)
74
+ local _forge = forge
75
+ local _object = table.clone(props)
76
+ setmetatable(_object, nil)
77
+ _object.render = {
78
+ name = name,
79
+ }
80
+ return _forge:renderApp(_object)
81
+ end
82
+ for _k, _v in names do
83
+ _newValue[_k] = _callback(_v, _k - 1, names)
84
+ end
85
+ -- ▲ ReadonlyArray.map ▲
86
+ return _newValue
87
+ end
31
88
  local function Render(props)
32
89
  local _binding = props
33
90
  local config = _binding.config
@@ -60,15 +117,31 @@ local function Render(props)
60
117
  warn("Rendering twice making a second px")
61
118
  end
62
119
  if render then
63
- local _value = render.name
64
- if _value ~= "" and _value then
65
- return forge:renderApp(props)
66
- elseif render.names then
67
- return forge:renderApps(props)
120
+ local _condition = render.name
121
+ if _condition ~= "" and _condition then
122
+ _condition = render.group
123
+ end
124
+ if _condition ~= "" and _condition then
125
+ return forge:renderGroupByName(props)
68
126
  else
69
- local _value_1 = render.group
70
- if _value_1 ~= "" and _value_1 then
71
- return forge:renderGroup(props)
127
+ local _value = render.names and render.group
128
+ if _value ~= "" and _value then
129
+ return forge:renderGroupByNames(props)
130
+ else
131
+ local _result = render
132
+ if _result ~= nil then
133
+ _result = _result.name
134
+ end
135
+ if _result ~= "" and _result then
136
+ return forge:renderApp(props)
137
+ elseif render.names then
138
+ return forge:renderApps(props)
139
+ else
140
+ local _value_1 = render.group
141
+ if _value_1 ~= "" and _value_1 then
142
+ return forge:renderGroup(props)
143
+ end
144
+ end
72
145
  end
73
146
  end
74
147
  end
@@ -76,5 +149,8 @@ local function Render(props)
76
149
  end
77
150
  return {
78
151
  createSource = createSource,
152
+ normalizeGroups = normalizeGroups,
153
+ collectByGroup = collectByGroup,
154
+ renderNames = renderNames,
79
155
  Render = Render,
80
156
  }
@@ -13,5 +13,7 @@ export default class AppForge {
13
13
  renderApp(props: Types.Props.Main): ScreenGui | Frame;
14
14
  renderApps(props: Types.Props.Main): (ScreenGui | Frame)[];
15
15
  renderGroup(props: Types.Props.Main): (ScreenGui | Frame)[];
16
+ renderGroupByName(props: Types.Props.Main): (ScreenGui | Frame)[];
17
+ renderGroupByNames(props: Types.Props.Main): (ScreenGui | Frame)[];
16
18
  renderAll(props: Types.Props.Main): (ScreenGui | Frame)[];
17
19
  }
@@ -1,5 +1,7 @@
1
1
  -- Compiled with roblox-ts v3.0.0
2
2
  local TS = _G[script]
3
+ -- Services
4
+ local RunService = TS.import(script, TS.getModule(script, "@rbxts", "services")).RunService
3
5
  -- Packages
4
6
  local _vide = TS.import(script, TS.getModule(script, "@rbxts", "vide").src)
5
7
  local effect = _vide.effect
@@ -11,8 +13,11 @@ local AppRegistry = TS.import(script, script, "decorator").AppRegistry
11
13
  -- Classes
12
14
  local RulesManager = TS.import(script, script, "rules").default
13
15
  -- Helpers
14
- local createSource = TS.import(script, script, "helpers").createSource
15
- local RunService = TS.import(script, TS.getModule(script, "@rbxts", "services")).RunService
16
+ local _helpers = TS.import(script, script, "helpers")
17
+ local createSource = _helpers.createSource
18
+ local renderNames = _helpers.renderNames
19
+ local collectByGroup = _helpers.collectByGroup
20
+ local normalizeGroups = _helpers.normalizeGroups
16
21
  local AppForge
17
22
  do
18
23
  AppForge = setmetatable({}, {
@@ -104,86 +109,47 @@ do
104
109
  _names = _names.names
105
110
  end
106
111
  local names = _names
107
- if names then
108
- -- ReadonlyArray.map
109
- local _newValue = table.create(#names)
110
- local _callback = function(name)
111
- local render = {
112
- name = name,
113
- }
114
- local _self = self
115
- local _object = table.clone(props)
116
- setmetatable(_object, nil)
117
- _object.render = render
118
- return _self:renderApp(_object)
119
- end
120
- for _k, _v in names do
121
- _newValue[_k] = _callback(_v, _k - 1, names)
122
- end
123
- -- ▲ ReadonlyArray.map ▲
124
- return _newValue
125
- end
126
- error("No app names provided to renderApps")
112
+ if not names then
113
+ error("No app names provided to renderApps")
114
+ end
115
+ return renderNames(props, names, self)
127
116
  end
128
117
  function AppForge:renderGroup(props)
129
- local _selectedGroup = props.render
130
- if _selectedGroup ~= nil then
131
- _selectedGroup = _selectedGroup.group
132
- end
133
- local selectedGroup = _selectedGroup
134
- if selectedGroup ~= "" and selectedGroup then
135
- local names = {}
136
- -- ▼ ReadonlyMap.forEach ▼
137
- local _callback = function(app, name)
138
- local _foundGroup = app.rules
139
- if _foundGroup ~= nil then
140
- _foundGroup = _foundGroup.renderGroup
141
- end
142
- local foundGroup = _foundGroup
143
- if not (foundGroup ~= "" and foundGroup) then
144
- return nil
145
- end
146
- local _result
147
- if type(selectedGroup) == "table" then
148
- local _array = {}
149
- local _length = #_array
150
- table.move(selectedGroup, 1, #selectedGroup, _length + 1, _array)
151
- _result = _array
152
- else
153
- _result = { selectedGroup }
154
- end
155
- local allGroups = _result
156
- if table.find(allGroups, foundGroup) ~= nil then
157
- local _name = name
158
- table.insert(names, _name)
159
- return #names
160
- end
161
- end
162
- for _k, _v in AppRegistry do
163
- _callback(_v, _k, AppRegistry)
164
- end
165
- -- ▲ ReadonlyMap.forEach ▲
166
- if names then
167
- -- ▼ ReadonlyArray.map ▼
168
- local _newValue = table.create(#names)
169
- local _callback_1 = function(name)
170
- local render = {
171
- name = name,
172
- }
173
- local _self = self
174
- local _object = table.clone(props)
175
- setmetatable(_object, nil)
176
- _object.render = render
177
- return _self:renderApp(_object)
178
- end
179
- for _k, _v in names do
180
- _newValue[_k] = _callback_1(_v, _k - 1, names)
181
- end
182
- -- ▲ ReadonlyArray.map ▲
183
- return _newValue
184
- end
185
- end
186
- error("No app names provided to renderApps")
118
+ local _group = props.render
119
+ if _group ~= nil then
120
+ _group = _group.group
121
+ end
122
+ local group = _group
123
+ if not (group ~= "" and group) then
124
+ error("No app names provided to renderApps")
125
+ end
126
+ local groups = normalizeGroups(group)
127
+ return renderNames(props, collectByGroup(groups), self)
128
+ end
129
+ function AppForge:renderGroupByName(props)
130
+ local _binding = props.render or {}
131
+ local group = _binding.group
132
+ local name = _binding.name
133
+ if not (group ~= "" and group) or not (name ~= "" and name) then
134
+ error("No app names provided to renderApps")
135
+ end
136
+ local groups = normalizeGroups(group)
137
+ return renderNames(props, collectByGroup(groups, function(n)
138
+ return n == name
139
+ end), self)
140
+ end
141
+ function AppForge:renderGroupByNames(props)
142
+ local _binding = props.render or {}
143
+ local group = _binding.group
144
+ local names = _binding.names
145
+ if not (group ~= "" and group) or not names then
146
+ error("No app names provided to renderApps")
147
+ end
148
+ local groups = normalizeGroups(group)
149
+ return renderNames(props, collectByGroup(groups, function(n)
150
+ local _n = n
151
+ return table.find(names, _n) ~= nil
152
+ end), self)
187
153
  end
188
154
  function AppForge:renderAll(props)
189
155
  local names = {}
@@ -191,19 +157,13 @@ do
191
157
  local _callback = function(_, name)
192
158
  local _name = name
193
159
  table.insert(names, _name)
160
+ return #names
194
161
  end
195
162
  for _k, _v in AppRegistry do
196
163
  _callback(_v, _k, AppRegistry)
197
164
  end
198
165
  -- ▲ ReadonlyMap.forEach ▲
199
- local render = {
200
- names = names,
201
- }
202
- local _self = self
203
- local _object = table.clone(props)
204
- setmetatable(_object, nil)
205
- _object.render = render
206
- return _self:renderApps(_object)
166
+ return renderNames(props, names, self)
207
167
  end
208
168
  end
209
169
  return {
@@ -7,7 +7,9 @@ declare namespace Types {
7
7
  type Render =
8
8
  | { name?: AppNames; names?: never; group?: never }
9
9
  | { names?: AppNames[]; name?: never; group?: never }
10
- | { names?: never; name?: never; group?: GroupNames[] | GroupNames };
10
+ | { group?: GroupNames[] | GroupNames; names?: AppNames[]; name?: never }
11
+ | { group?: GroupNames[] | GroupNames; name?: AppNames; names?: never }
12
+ | { group?: GroupNames[] | GroupNames; names?: never; name?: never };
11
13
 
12
14
  type Main = {
13
15
  props: AppProps;
@@ -32,18 +34,23 @@ declare namespace Types {
32
34
  type Props<N extends AppNames> = {
33
35
  name: N;
34
36
  visible?: boolean;
37
+ renderGroup?: GroupNames;
35
38
  rules?: Rules.Generic<N>;
36
39
  };
37
40
 
38
41
  type Static = {
39
42
  constructor: new (props: Types.Props.Main, name: AppNames) => Args;
43
+
40
44
  visible?: boolean;
45
+ renderGroup?: GroupNames;
41
46
  rules?: Rules.Static;
42
47
  };
43
48
 
44
49
  type Generic<N extends AppNames = AppNames> = {
45
50
  constructor: new (props: Types.Props.Main, name: AppNames) => Args;
51
+
46
52
  visible?: boolean;
53
+ renderGroup?: GroupNames;
47
54
  rules?: Rules.Generic<N>;
48
55
  };
49
56
  }
@@ -52,13 +59,11 @@ declare namespace Types {
52
59
  type Static = {
53
60
  parent?: string;
54
61
  exclusiveGroup?: string;
55
- renderGroup?: string;
56
62
  };
57
63
 
58
64
  type Generic<N extends AppNames = AppNames> = {
59
65
  parent?: Exclude<AppNames, N>;
60
66
  exclusiveGroup?: GroupNames;
61
- renderGroup?: GroupNames;
62
67
  };
63
68
  }
64
69
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rbxts/app-forge",
3
- "version": "0.6.0-alpha.63",
3
+ "version": "0.6.0-alpha.65",
4
4
  "description": "An App Manager for Vide",
5
5
  "main": "out/init.lua",
6
6
  "types": "out/index.d.ts",