@rbxts/uiblox 0.1.28 → 0.1.30

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.
@@ -3,10 +3,25 @@ local TS = _G[script]
3
3
  local classNamesInternal = function(conditionalStyles, ...)
4
4
  local styles = { ... }
5
5
  local style = {}
6
+ -- ▼ ReadonlyArray.forEach ▼
7
+ local _callback = function(value)
8
+ if value ~= 0 and value == value and value ~= "" and value then
9
+ local _object = table.clone(style)
10
+ setmetatable(_object, nil)
11
+ for _k, _v in value do
12
+ _object[_k] = _v
13
+ end
14
+ style = _object
15
+ end
16
+ end
17
+ for _k, _v in styles do
18
+ _callback(_v, _k - 1, styles)
19
+ end
20
+ -- ▲ ReadonlyArray.forEach ▲
6
21
  local _result = conditionalStyles
7
22
  if _result ~= nil then
8
23
  -- ▼ ReadonlyMap.forEach ▼
9
- local _callback = function(value, key)
24
+ local _callback_1 = function(value, key)
10
25
  if value then
11
26
  local _object = table.clone(style)
12
27
  setmetatable(_object, nil)
@@ -17,25 +32,10 @@ local classNamesInternal = function(conditionalStyles, ...)
17
32
  end
18
33
  end
19
34
  for _k, _v in _result do
20
- _callback(_v, _k, _result)
35
+ _callback_1(_v, _k, _result)
21
36
  end
22
37
  -- ▲ ReadonlyMap.forEach ▲
23
38
  end
24
- -- ▼ ReadonlyArray.forEach ▼
25
- local _callback = function(value)
26
- if value ~= 0 and value == value and value ~= "" and value then
27
- local _object = table.clone(style)
28
- setmetatable(_object, nil)
29
- for _k, _v in value do
30
- _object[_k] = _v
31
- end
32
- style = _object
33
- end
34
- end
35
- for _k, _v in styles do
36
- _callback(_v, _k - 1, styles)
37
- end
38
- -- ▲ ReadonlyArray.forEach ▲
39
39
  local _object = table.clone(style)
40
40
  setmetatable(_object, nil)
41
41
  return _object
@@ -47,7 +47,36 @@ local function classNames(...)
47
47
  local hasConditionalStyles = function(args)
48
48
  local _exitType, _returns = TS.try(function()
49
49
  local lastArg = args[#args]
50
- return TS.TRY_RETURN, { lastArg ~= nil and type(lastArg) == "table" }
50
+ -- If the last argument is undefined or not a table then its not a ConditionalStyles<T>
51
+ -- Map<K, V> compiles to a table literal (ref: https://roblox-ts.com/docs/api/constructors)
52
+ if lastArg == nil or not (type(lastArg) == "table") then
53
+ return TS.TRY_RETURN, { false }
54
+ end
55
+ local lastArgAsConditionalStylesMap = lastArg
56
+ local matchesMapFormat = true
57
+ local _result = lastArgAsConditionalStylesMap
58
+ if _result ~= nil then
59
+ -- ▼ ReadonlyMap.forEach ▼
60
+ local _callback = function(value, key)
61
+ -- Assume that the last argument is a ConditionalStyles<T> with correct format (Map<WriteableStyle<T>, boolean>)
62
+ -- If the key is not a WriteableStyle<T> then it does not match the format
63
+ -- If the value is not a boolean then it does not match the format
64
+ local _value = value
65
+ local _condition = not (type(_value) == "boolean")
66
+ if not _condition then
67
+ local _key = key
68
+ _condition = not (type(_key) == "table")
69
+ end
70
+ if _condition then
71
+ matchesMapFormat = false
72
+ end
73
+ end
74
+ for _k, _v in _result do
75
+ _callback(_v, _k, _result)
76
+ end
77
+ -- ▲ ReadonlyMap.forEach ▲
78
+ end
79
+ return TS.TRY_RETURN, { matchesMapFormat }
51
80
  end, function()
52
81
  -- If we catch an error, it means that the last argument is not a ConditionalStyles<T>
53
82
  return TS.TRY_RETURN, { false }
package/out/ui/index.d.ts CHANGED
@@ -2,6 +2,9 @@ export * from "./constants/index";
2
2
  export * from "./enums/index";
3
3
  export { Divider } from "./packages/index";
4
4
  export { DividerProps } from "./packages/index";
5
+ export { ErrorBoundary } from "./packages/index";
6
+ export { ErrorBoundaryProps } from "./packages/index";
7
+ export { ErrorBoundaryState } from "./packages/index";
5
8
  export { Icon } from "./packages/index";
6
9
  export { IconProps } from "./packages/index";
7
10
  export { IconButton } from "./packages/index";
package/out/ui/init.luau CHANGED
@@ -8,6 +8,7 @@ for _k, _v in TS.import(script, script, "enums") or {} do
8
8
  exports[_k] = _v
9
9
  end
10
10
  exports.Divider = TS.import(script, script, "packages").Divider
11
+ exports.ErrorBoundary = TS.import(script, script, "packages").ErrorBoundary
11
12
  exports.Icon = TS.import(script, script, "packages").Icon
12
13
  exports.IconButton = TS.import(script, script, "packages").IconButton
13
14
  exports.Input = TS.import(script, script, "packages").Input
@@ -0,0 +1,17 @@
1
+ import React, { Component, ErrorInfo } from "@rbxts/react";
2
+ export interface ErrorBoundaryProps {
3
+ fallback?: (error: unknown) => React.Element;
4
+ }
5
+ export interface ErrorBoundaryState {
6
+ hasError: boolean;
7
+ message?: unknown;
8
+ }
9
+ export declare class ErrorBoundary extends Component<ErrorBoundaryProps, ErrorBoundaryState> {
10
+ state: ErrorBoundaryState;
11
+ componentDidCatch(message: unknown, info: ErrorInfo): void;
12
+ render(): boolean | ReadonlyMap<React.Key, React.ReactNode> | {
13
+ readonly [key: string]: React.ReactNode;
14
+ readonly [key: number]: React.ReactNode;
15
+ } | readonly React.ReactNode[] | JSX.Element | undefined;
16
+ }
17
+ export default ErrorBoundary;
@@ -0,0 +1,46 @@
1
+ -- Compiled with roblox-ts v3.0.0
2
+ local TS = _G[script]
3
+ local _react = TS.import(script, TS.getModule(script, "@rbxts", "react"))
4
+ local React = _react
5
+ local Component = _react.Component
6
+ local ReactComponent = _react.ReactComponent
7
+ local ErrorBoundary
8
+ do
9
+ local super = Component
10
+ ErrorBoundary = setmetatable({}, {
11
+ __tostring = function()
12
+ return "ErrorBoundary"
13
+ end,
14
+ __index = super,
15
+ })
16
+ ErrorBoundary.__index = ErrorBoundary
17
+ function ErrorBoundary.new(...)
18
+ local self = setmetatable({}, ErrorBoundary)
19
+ return self:constructor(...) or self
20
+ end
21
+ function ErrorBoundary:constructor(...)
22
+ super.constructor(self, ...)
23
+ self.state = {
24
+ hasError = false,
25
+ }
26
+ end
27
+ function ErrorBoundary:componentDidCatch(message, info)
28
+ warn(message, info.componentStack)
29
+ self:setState({
30
+ hasError = true,
31
+ message = `{message} {info.componentStack}`,
32
+ })
33
+ end
34
+ function ErrorBoundary:render()
35
+ if self.state.hasError then
36
+ return if self.props.fallback ~= nil then self.props.fallback(self.state.message) else React.createElement(React.Fragment)
37
+ end
38
+ return self.props.children
39
+ end
40
+ ErrorBoundary = ReactComponent(ErrorBoundary) or ErrorBoundary
41
+ end
42
+ local default = ErrorBoundary
43
+ return {
44
+ ErrorBoundary = ErrorBoundary,
45
+ default = default,
46
+ }
@@ -0,0 +1,4 @@
1
+ export { default as ErrorBoundary } from "./components/ErrorBoundary";
2
+ export { ErrorBoundaryProps } from "./components/ErrorBoundary";
3
+ export { ErrorBoundaryState } from "./components/ErrorBoundary";
4
+ export * from "./components/ErrorBoundary";
@@ -0,0 +1,8 @@
1
+ -- Compiled with roblox-ts v3.0.0
2
+ local TS = _G[script]
3
+ local exports = {}
4
+ exports.ErrorBoundary = TS.import(script, script, "components", "ErrorBoundary").default
5
+ for _k, _v in TS.import(script, script, "components", "ErrorBoundary") or {} do
6
+ exports[_k] = _v
7
+ end
8
+ return exports
@@ -1,4 +1,5 @@
1
1
  export * from "./divider/index";
2
+ export * from "./errorBoundary/index";
2
3
  export * from "./icon/index";
3
4
  export * from "./iconButton/index";
4
5
  export * from "./input/index";
@@ -4,6 +4,9 @@ local exports = {}
4
4
  for _k, _v in TS.import(script, script, "divider") or {} do
5
5
  exports[_k] = _v
6
6
  end
7
+ for _k, _v in TS.import(script, script, "errorBoundary") or {} do
8
+ exports[_k] = _v
9
+ end
7
10
  for _k, _v in TS.import(script, script, "icon") or {} do
8
11
  exports[_k] = _v
9
12
  end
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rbxts/uiblox",
3
- "version": "0.1.28",
3
+ "version": "0.1.30",
4
4
  "description": "UI Library and theming for roblox-ts projects",
5
5
  "main": "out/init.lua",
6
6
  "scripts": {