@macive/ui 0.0.7 → 0.0.9
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/dist/src/components/ActionList/ActionList.js +1 -0
- package/dist/src/components/ActionMenu/ActionMenu.js +1 -0
- package/dist/src/components/AfterInitialMount/AfterInitialMount.js +1 -0
- package/dist/src/components/AlphaCard/AlphaCard.js +1 -0
- package/dist/src/index.js +1 -0
- package/dist/src/utilities/components copy.js +57 -0
- package/dist/src/utilities/components.js +20 -3
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/src/components/ActionList/ActionList.d.ts.map +1 -1
- package/dist/types/src/components/ActionMenu/ActionMenu.d.ts.map +1 -1
- package/dist/types/src/components/AfterInitialMount/AfterInitialMount.d.ts.map +1 -1
- package/dist/types/src/components/AlphaCard/AlphaCard.d.ts.map +1 -1
- package/dist/types/src/components/Scrollable/Scrollable.d.ts +1 -1
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/utilities/components copy.d.ts +17 -0
- package/dist/types/src/utilities/components copy.d.ts.map +1 -0
- package/dist/types/src/utilities/components.d.ts +3 -1
- package/dist/types/src/utilities/components.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/src/index.js
CHANGED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ConditionalRender = exports.ConditionalWrapper = exports.elementChildren = exports.isElementOfType = exports.wrapWithComponent = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const react_1 = require("react");
|
|
6
|
+
// Wraps `element` in `Component`, if it is not already an instance of
|
|
7
|
+
// `Component`. If `props` is passed, those will be added as props on the
|
|
8
|
+
// wrapped component. If `element` is null, the component is not wrapped.
|
|
9
|
+
function wrapWithComponent(element, Component, props) {
|
|
10
|
+
if (element == null) {
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
return isElementOfType(element, Component) ? element : (0, jsx_runtime_1.jsx)(Component, { ...props, children: element });
|
|
14
|
+
}
|
|
15
|
+
exports.wrapWithComponent = wrapWithComponent;
|
|
16
|
+
// In development, we compare based on the name of the function because
|
|
17
|
+
// React Hot Loader proxies React components in order to make updates. In
|
|
18
|
+
// production we can simply compare the components for equality.
|
|
19
|
+
const isComponent = process.env.NODE_ENV === 'development'
|
|
20
|
+
? hotReloadComponentCheck
|
|
21
|
+
: (AComponent, AnotherComponent) => AComponent === AnotherComponent;
|
|
22
|
+
// Checks whether `element` is a React element of type `Component` (or one of
|
|
23
|
+
// the passed components, if `Component` is an array of React components).
|
|
24
|
+
function isElementOfType(element, Component) {
|
|
25
|
+
var _a;
|
|
26
|
+
if (element == null || !(0, react_1.isValidElement)(element) || typeof element.type === 'string') {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
const { type: defaultType } = element;
|
|
30
|
+
// Type override allows components to bypass default wrapping behavior. Ex: Stack, ResourceList...
|
|
31
|
+
// See https://github.com/Airsoko/app-extension-libs/issues/996#issuecomment-710437088
|
|
32
|
+
const overrideType = (_a = element.props) === null || _a === void 0 ? void 0 : _a.__type__;
|
|
33
|
+
const type = overrideType || defaultType;
|
|
34
|
+
const Components = Array.isArray(Component) ? Component : [Component];
|
|
35
|
+
return Components.some((AComponent) => typeof type !== 'string' && isComponent(AComponent, type));
|
|
36
|
+
}
|
|
37
|
+
exports.isElementOfType = isElementOfType;
|
|
38
|
+
// Returns all children that are valid elements as an array. Can optionally be
|
|
39
|
+
// filtered by passing `predicate`.
|
|
40
|
+
function elementChildren(children, predicate = () => true) {
|
|
41
|
+
return react_1.Children.toArray(children).filter((child) => (0, react_1.isValidElement)(child) && predicate(child));
|
|
42
|
+
}
|
|
43
|
+
exports.elementChildren = elementChildren;
|
|
44
|
+
function ConditionalWrapper({ condition, wrapper, children, }) {
|
|
45
|
+
return condition ? wrapper(children) : children;
|
|
46
|
+
}
|
|
47
|
+
exports.ConditionalWrapper = ConditionalWrapper;
|
|
48
|
+
function ConditionalRender({ condition, children }) {
|
|
49
|
+
return condition ? children : null;
|
|
50
|
+
}
|
|
51
|
+
exports.ConditionalRender = ConditionalRender;
|
|
52
|
+
function hotReloadComponentCheck(AComponent, AnotherComponent) {
|
|
53
|
+
const componentName = AComponent.name;
|
|
54
|
+
const anotherComponentName = AnotherComponent.displayName;
|
|
55
|
+
return (AComponent === AnotherComponent ||
|
|
56
|
+
(Boolean(componentName) && componentName === anotherComponentName));
|
|
57
|
+
}
|
|
@@ -10,7 +10,9 @@ function wrapWithComponent(element, Component, props) {
|
|
|
10
10
|
if (element == null) {
|
|
11
11
|
return null;
|
|
12
12
|
}
|
|
13
|
-
|
|
13
|
+
// Separate the `key` prop from other props
|
|
14
|
+
const { key, ...restProps } = props;
|
|
15
|
+
return isElementOfType(element, Component) ? (element) : ((0, jsx_runtime_1.jsx)(Component, { ...restProps, children: element }, key));
|
|
14
16
|
}
|
|
15
17
|
exports.wrapWithComponent = wrapWithComponent;
|
|
16
18
|
// In development, we compare based on the name of the function because
|
|
@@ -21,20 +23,35 @@ const isComponent = process.env.NODE_ENV === 'development'
|
|
|
21
23
|
: (AComponent, AnotherComponent) => AComponent === AnotherComponent;
|
|
22
24
|
// Checks whether `element` is a React element of type `Component` (or one of
|
|
23
25
|
// the passed components, if `Component` is an array of React components).
|
|
26
|
+
// Checks whether `element` is a React element of type `Component` (or one of
|
|
27
|
+
// the passed components, if `Component` is an array of React components).
|
|
24
28
|
function isElementOfType(element, Component) {
|
|
25
29
|
var _a;
|
|
26
30
|
if (element == null || !(0, react_1.isValidElement)(element) || typeof element.type === 'string') {
|
|
27
31
|
return false;
|
|
28
32
|
}
|
|
29
33
|
const { type: defaultType } = element;
|
|
30
|
-
// Type override allows components to bypass default wrapping behavior. Ex: Stack, ResourceList...
|
|
31
|
-
// See https://github.com/Airsoko/app-extension-libs/issues/996#issuecomment-710437088
|
|
32
34
|
const overrideType = (_a = element.props) === null || _a === void 0 ? void 0 : _a.__type__;
|
|
33
35
|
const type = overrideType || defaultType;
|
|
34
36
|
const Components = Array.isArray(Component) ? Component : [Component];
|
|
35
37
|
return Components.some((AComponent) => typeof type !== 'string' && isComponent(AComponent, type));
|
|
36
38
|
}
|
|
37
39
|
exports.isElementOfType = isElementOfType;
|
|
40
|
+
// export function isElementOfType<TProps>(
|
|
41
|
+
// element: React.ReactNode | null | undefined,
|
|
42
|
+
// Component: React.ComponentType<TProps> | React.ComponentType<TProps>[],
|
|
43
|
+
// ): boolean {
|
|
44
|
+
// if (element == null || !isValidElement(element) || typeof element.type === 'string') {
|
|
45
|
+
// return false
|
|
46
|
+
// }
|
|
47
|
+
// const { type: defaultType } = element
|
|
48
|
+
// // Type override allows components to bypass default wrapping behavior. Ex: Stack, ResourceList...
|
|
49
|
+
// // See https://github.com/Airsoko/app-extension-libs/issues/996#issuecomment-710437088
|
|
50
|
+
// const overrideType = element.props?.__type__
|
|
51
|
+
// const type = overrideType || defaultType
|
|
52
|
+
// const Components = Array.isArray(Component) ? Component : [Component]
|
|
53
|
+
// return Components.some((AComponent) => typeof type !== 'string' && isComponent(AComponent, type))
|
|
54
|
+
// }
|
|
38
55
|
// Returns all children that are valid elements as an array. Can optionally be
|
|
39
56
|
// filtered by passing `predicate`.
|
|
40
57
|
function elementChildren(children, predicate = () => true) {
|