@longline/aqua-ui 1.0.248 → 1.0.249

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.
@@ -34,13 +34,36 @@ import { Column } from './Column';
34
34
  import { Table } from './elements/Table';
35
35
  import { sortItems } from './elements/sortItems';
36
36
  import { Ghost } from './elements/Ghost';
37
+ function getChildrenOfTypeDeep(children, componentType) {
38
+ var result = [];
39
+ React.Children.forEach(children, function (child) {
40
+ if (!React.isValidElement(child))
41
+ return;
42
+ // Match component type (handle styled-components, memo, forwardRef)
43
+ var childType = child.type.type || child.type;
44
+ if (childType === componentType) {
45
+ result.push(child);
46
+ }
47
+ // Recurse into nested children
48
+ if (child.props && child.props.children) {
49
+ result.push.apply(result, getChildrenOfTypeDeep(child.props.children, componentType));
50
+ }
51
+ });
52
+ return result;
53
+ }
54
+ /**
55
+ * Find ListView's columns. This is done by looking through the ListView's
56
+ * children (at any depth) and retaining only the children of type
57
+ * ListView.Column. For each child, the props are returned.
58
+ */
59
+ var getColumns = function (children) {
60
+ return getChildrenOfTypeDeep(children, ListView.Column).map(function (c) { return c.props; });
61
+ };
37
62
  var ListViewBase = function (props) {
38
63
  var _a, _b;
39
64
  var children = props.children, otherProps = __rest(props, ["children"]);
40
65
  var _c = React.useState(false), columnsMode = _c[0], setColumnsMode = _c[1];
41
- var originalColumns = React.Children.toArray(children).map(function (c) {
42
- return c.props;
43
- });
66
+ var originalColumns = getColumns(props.children);
44
67
  var _d = React.useState(originalColumns), columns = _d[0], setColumns = _d[1];
45
68
  // Find default sort column:
46
69
  var sortColumn = (_a = columns.find(function (c) { return c.defaultSort; })) !== null && _a !== void 0 ? _a : columns[0];
@@ -53,9 +76,7 @@ var ListViewBase = function (props) {
53
76
  }, [props.data, sort, reverse]);
54
77
  // If children change, then update columns state.
55
78
  React.useEffect(function () {
56
- setColumns(React.Children.toArray(children).map(function (c) {
57
- return c.props;
58
- }));
79
+ setColumns(getColumns(props.children));
59
80
  }, [props.children]);
60
81
  // Change sort:
61
82
  var handleSort = function (column) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@longline/aqua-ui",
3
- "version": "1.0.248",
3
+ "version": "1.0.249",
4
4
  "description": "AquaUI",
5
5
  "author": "Alexander van Oostenrijk / Longline Environment",
6
6
  "license": "Commercial",