@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.
@@ -1,3 +1,4 @@
1
+ 'use client';
1
2
  "use strict";
2
3
  Object.defineProperty(exports, "__esModule", { value: true });
3
4
  exports.ActionList = void 0;
@@ -1,3 +1,4 @@
1
+ 'use client';
1
2
  "use strict";
2
3
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
4
  return (mod && mod.__esModule) ? mod : { "default": mod };
@@ -1,3 +1,4 @@
1
+ 'use client';
1
2
  "use strict";
2
3
  Object.defineProperty(exports, "__esModule", { value: true });
3
4
  exports.AfterInitialMount = void 0;
@@ -1,3 +1,4 @@
1
+ 'use client';
1
2
  "use strict";
2
3
  Object.defineProperty(exports, "__esModule", { value: true });
3
4
  exports.AlphaCard = void 0;
package/dist/src/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ 'use client';
1
2
  "use strict";
2
3
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
4
  if (k2 === undefined) k2 = k;
@@ -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
- return isElementOfType(element, Component) ? element : (0, jsx_runtime_1.jsx)(Component, { ...props, children: element });
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) {