@wavelengthusaf/components 4.16.0 → 4.17.0

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.
@@ -7483,58 +7483,100 @@ ChildDataTable.displayName = "ChildDataTable";
7483
7483
 
7484
7484
  // src/components/DataTable/SubRowTable/ChildDataTable.tsx
7485
7485
 
7486
-
7487
7486
  var _client = require('react-dom/client');
7488
7487
 
7489
- var ChildDataTable2 = ({ columns, data, dropdownArrowLocation, sortIcon, dropdownButtonIcon, ...rest }) => {
7488
+
7489
+ var ChildDataTable2 = ({ columns, data, dropdownArrowLocation, sortIcon, dropdownButtonIcon, externalSort, sortKey, sortOrder, onAction, ...rest }) => {
7490
7490
  const tableRef = _react.useRef.call(void 0, null);
7491
- const reactDropdownRoots = _react.useRef.call(void 0, /* @__PURE__ */ new Map());
7491
+ const cellRoots = _react.useRef.call(void 0, /* @__PURE__ */ new Map());
7492
+ const dropdownRoots = _react.useRef.call(void 0, /* @__PURE__ */ new Map());
7493
+ const renderReactToDOM = (element) => {
7494
+ const container = document.createElement("div");
7495
+ container.style.display = "contents";
7496
+ const root = _client.createRoot.call(void 0, container);
7497
+ cellRoots.current.set(container, root);
7498
+ root.render(element);
7499
+ return container;
7500
+ };
7501
+ const processedColumns = _react.useMemo.call(void 0, () => {
7502
+ if (!Array.isArray(columns)) return columns;
7503
+ return columns.map((col) => {
7504
+ if (typeof col.renderCell === "function") {
7505
+ const originalRender = col.renderCell;
7506
+ return {
7507
+ ...col,
7508
+ renderCell: (item) => {
7509
+ const content = originalRender(item);
7510
+ if (content !== null && typeof content === "object" && !(content instanceof HTMLElement)) {
7511
+ return renderReactToDOM(content);
7512
+ }
7513
+ return content;
7514
+ }
7515
+ };
7516
+ }
7517
+ return col;
7518
+ });
7519
+ }, [columns]);
7492
7520
  _react.useEffect.call(void 0, () => {
7493
- const customChildDataTableElement = tableRef.current;
7494
- if (!customChildDataTableElement) return;
7495
- if (columns !== void 0) customChildDataTableElement.setColumns = columns;
7496
- if (data !== void 0) customChildDataTableElement.setData = data;
7497
- if (dropdownArrowLocation !== void 0) customChildDataTableElement.setDropdownArrowLocation = dropdownArrowLocation;
7498
- if (sortIcon !== void 0) customChildDataTableElement.setSortIcon = sortIcon;
7499
- if (dropdownButtonIcon !== void 0) customChildDataTableElement.setDropdownButtonIcon = dropdownButtonIcon;
7500
- }, [columns, data, dropdownArrowLocation, sortIcon, dropdownButtonIcon]);
7521
+ const el = tableRef.current;
7522
+ if (!el) return;
7523
+ const resolveNodeToDOM = (node) => {
7524
+ if (node !== null && typeof node === "object" && !(node instanceof HTMLElement)) {
7525
+ return renderReactToDOM(node);
7526
+ }
7527
+ return node;
7528
+ };
7529
+ if (processedColumns !== void 0) el.setColumns = processedColumns;
7530
+ if (data !== void 0) el.setData = data;
7531
+ if (dropdownArrowLocation !== void 0) el.setDropdownArrowLocation = dropdownArrowLocation;
7532
+ if (sortIcon !== void 0) el.setSortIcon = resolveNodeToDOM(sortIcon);
7533
+ if (dropdownButtonIcon !== void 0) el.setDropdownButtonIcon = resolveNodeToDOM(dropdownButtonIcon);
7534
+ if (externalSort !== void 0) el.setExternalSort = externalSort;
7535
+ if (sortKey !== void 0) el.setSortKey = sortKey;
7536
+ if (sortOrder !== void 0) el.setSortOrder = sortOrder;
7537
+ }, [processedColumns, data, dropdownArrowLocation, sortIcon, dropdownButtonIcon, externalSort, sortKey, sortOrder]);
7501
7538
  _react.useEffect.call(void 0, () => {
7502
7539
  const el = tableRef.current;
7503
7540
  if (!el) return;
7541
+ const handleAction = (event) => {
7542
+ if (onAction) onAction(event);
7543
+ };
7504
7544
  const handleReactDropdown = (event) => {
7505
7545
  const customEvent = event;
7506
7546
  event.stopPropagation();
7507
7547
  const { container, itemId } = customEvent.detail;
7508
- let root = reactDropdownRoots.current.get(container);
7548
+ let root = dropdownRoots.current.get(container);
7509
7549
  if (!root) {
7510
7550
  root = _client.createRoot.call(void 0, container);
7511
- reactDropdownRoots.current.set(container, root);
7551
+ dropdownRoots.current.set(container, root);
7512
7552
  }
7513
- const item = _optionalChain([data, 'optionalAccess', _83 => _83.find, 'call', _84 => _84((item2) => String(item2.id) === String(itemId))]);
7514
- if (item && item.dropdown && root) {
7553
+ const item = _optionalChain([data, 'optionalAccess', _83 => _83.find, 'call', _84 => _84((i) => String(i.id) === String(itemId))]);
7554
+ if (_optionalChain([item, 'optionalAccess', _85 => _85.dropdown]) && root) {
7515
7555
  root.render(item.dropdown);
7516
7556
  }
7517
- const dropdown = container.querySelector(".dropdown");
7518
- if (dropdown) {
7519
- dropdown.hidden = false;
7520
- }
7521
7557
  };
7522
7558
  const handleCleanupDropdown = (event) => {
7523
7559
  event.stopPropagation();
7524
7560
  const { container } = event.detail;
7525
- const root = reactDropdownRoots.current.get(container);
7526
- const dropdown = container.querySelector(".dropdown");
7527
- if (root && dropdown) {
7528
- dropdown.hidden = true;
7561
+ const root = dropdownRoots.current.get(container);
7562
+ if (root) {
7563
+ root.unmount();
7564
+ dropdownRoots.current.delete(container);
7529
7565
  }
7530
7566
  };
7567
+ el.addEventListener("action", handleAction);
7531
7568
  el.addEventListener("getReactDropdown", handleReactDropdown);
7532
7569
  el.addEventListener("cleanupDropdown", handleCleanupDropdown);
7533
7570
  return () => {
7571
+ el.removeEventListener("action", handleAction);
7534
7572
  el.removeEventListener("getReactDropdown", handleReactDropdown);
7535
7573
  el.removeEventListener("cleanupDropdown", handleCleanupDropdown);
7574
+ cellRoots.current.forEach((root) => root.unmount());
7575
+ cellRoots.current.clear();
7576
+ dropdownRoots.current.forEach((root) => root.unmount());
7577
+ dropdownRoots.current.clear();
7536
7578
  };
7537
- }, [data]);
7579
+ }, [data, onAction]);
7538
7580
  return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "wavelength-child-data-table", { ref: tableRef, ...rest });
7539
7581
  };
7540
7582
  ChildDataTable2.displayName = "ChildDataTable";
@@ -7637,9 +7679,9 @@ var NestedDataTable = ({ data, columns, id }) => {
7637
7679
  const SubDataHeaders = SubDataColumns.map((column, index) => {
7638
7680
  return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "th", { children: column.title }, `SubHeadCell-${index}`);
7639
7681
  });
7640
- const subDataRows = !_optionalChain([data, 'optionalAccess', _85 => _85.length]) ? /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "tr", { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "td", { title: "NoSubDataRows", colSpan: columns.length, children: "No data" }) }) : data.map((item, index) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _jsxruntime.Fragment, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, SubDataTr, { children: SubDataColumns.map((column, colIndex) => {
7682
+ const subDataRows = !_optionalChain([data, 'optionalAccess', _86 => _86.length]) ? /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "tr", { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "td", { title: "NoSubDataRows", colSpan: columns.length, children: "No data" }) }) : data.map((item, index) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _jsxruntime.Fragment, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, SubDataTr, { children: SubDataColumns.map((column, colIndex) => {
7641
7683
  const columnKey = trimBeforePeriod(column.key);
7642
- const value = _optionalChain([item, 'access', _86 => _86.Details, 'optionalAccess', _87 => _87[columnKey]]);
7684
+ const value = _optionalChain([item, 'access', _87 => _87.Details, 'optionalAccess', _88 => _88[columnKey]]);
7643
7685
  console.log("value: ", value);
7644
7686
  if (value !== void 0) {
7645
7687
  return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "td", { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { children: value }) }, `Span-${item.id}-${colIndex}`);
@@ -7649,7 +7691,7 @@ var NestedDataTable = ({ data, columns, id }) => {
7649
7691
  /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "thead", { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "tr", { children: SubDataHeaders }) }),
7650
7692
  /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "tbody", { children: subDataRows })
7651
7693
  ] });
7652
- const rows = !_optionalChain([data, 'optionalAccess', _88 => _88.length]) ? /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "tr", { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "td", { title: "NoDataRows", colSpan: columns.length, children: "No data" }) }) : _optionalChain([data, 'optionalAccess', _89 => _89.map, 'call', _90 => _90((item, index) => /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _jsxruntime.Fragment, { children: [
7694
+ const rows = !_optionalChain([data, 'optionalAccess', _89 => _89.length]) ? /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "tr", { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "td", { title: "NoDataRows", colSpan: columns.length, children: "No data" }) }) : _optionalChain([data, 'optionalAccess', _90 => _90.map, 'call', _91 => _91((item, index) => /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _jsxruntime.Fragment, { children: [
7653
7695
  /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, PrimaryTrRows, { $index: index, children: [
7654
7696
  /* @__PURE__ */ _jsxruntime.jsx.call(void 0, DropdownButton, { onClick: () => toggleDropdown(index), children: isAscending && isOpen && primaryRowIndex === index ? /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _jsxruntime.Fragment, { children: "\u2227" }) : /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _jsxruntime.Fragment, { children: "\u2228" }) }),
7655
7697
  HeadColumns.map((column, index2) => {
@@ -975,11 +975,15 @@ declare const WavelengthDataTable: {
975
975
  };
976
976
 
977
977
  interface ChildDataTableProps extends React__default.HTMLAttributes<HTMLElement> {
978
- columns?: object;
979
- data?: object;
980
- dropdownArrowLocation?: string;
981
- sortIcon?: string | HTMLElement;
982
- dropdownButtonIcon?: string | HTMLElement;
978
+ columns?: any[];
979
+ data?: any[];
980
+ dropdownArrowLocation?: "left" | "right" | "bottom";
981
+ sortIcon?: string | HTMLElement | React__default.ReactNode;
982
+ dropdownButtonIcon?: string | HTMLElement | React__default.ReactNode;
983
+ externalSort?: boolean | string;
984
+ sortKey?: string;
985
+ sortOrder?: "asc" | "desc";
986
+ onAction?: (event: CustomEvent) => void;
983
987
  }
984
988
  declare const ChildDataTable: React__default.FC<ChildDataTableProps>;
985
989
 
@@ -975,11 +975,15 @@ declare const WavelengthDataTable: {
975
975
  };
976
976
 
977
977
  interface ChildDataTableProps extends React__default.HTMLAttributes<HTMLElement> {
978
- columns?: object;
979
- data?: object;
980
- dropdownArrowLocation?: string;
981
- sortIcon?: string | HTMLElement;
982
- dropdownButtonIcon?: string | HTMLElement;
978
+ columns?: any[];
979
+ data?: any[];
980
+ dropdownArrowLocation?: "left" | "right" | "bottom";
981
+ sortIcon?: string | HTMLElement | React__default.ReactNode;
982
+ dropdownButtonIcon?: string | HTMLElement | React__default.ReactNode;
983
+ externalSort?: boolean | string;
984
+ sortKey?: string;
985
+ sortOrder?: "asc" | "desc";
986
+ onAction?: (event: CustomEvent) => void;
983
987
  }
984
988
  declare const ChildDataTable: React__default.FC<ChildDataTableProps>;
985
989
 
package/dist/esm/index.js CHANGED
@@ -7482,59 +7482,101 @@ var ChildDataTable = ({ data, columns, downloadArrowOnClick, downloadMissionOnCl
7482
7482
  ChildDataTable.displayName = "ChildDataTable";
7483
7483
 
7484
7484
  // src/components/DataTable/SubRowTable/ChildDataTable.tsx
7485
- import { useRef as useRef25, useEffect as useEffect27 } from "react";
7486
- import "@wavelengthusaf/web-components";
7485
+ import { useRef as useRef25, useEffect as useEffect27, useMemo as useMemo4 } from "react";
7487
7486
  import { createRoot } from "react-dom/client";
7487
+ import "@wavelengthusaf/web-components";
7488
7488
  import { jsx as jsx53 } from "react/jsx-runtime";
7489
- var ChildDataTable2 = ({ columns, data, dropdownArrowLocation, sortIcon, dropdownButtonIcon, ...rest }) => {
7489
+ var ChildDataTable2 = ({ columns, data, dropdownArrowLocation, sortIcon, dropdownButtonIcon, externalSort, sortKey, sortOrder, onAction, ...rest }) => {
7490
7490
  const tableRef = useRef25(null);
7491
- const reactDropdownRoots = useRef25(/* @__PURE__ */ new Map());
7491
+ const cellRoots = useRef25(/* @__PURE__ */ new Map());
7492
+ const dropdownRoots = useRef25(/* @__PURE__ */ new Map());
7493
+ const renderReactToDOM = (element) => {
7494
+ const container = document.createElement("div");
7495
+ container.style.display = "contents";
7496
+ const root = createRoot(container);
7497
+ cellRoots.current.set(container, root);
7498
+ root.render(element);
7499
+ return container;
7500
+ };
7501
+ const processedColumns = useMemo4(() => {
7502
+ if (!Array.isArray(columns)) return columns;
7503
+ return columns.map((col) => {
7504
+ if (typeof col.renderCell === "function") {
7505
+ const originalRender = col.renderCell;
7506
+ return {
7507
+ ...col,
7508
+ renderCell: (item) => {
7509
+ const content = originalRender(item);
7510
+ if (content !== null && typeof content === "object" && !(content instanceof HTMLElement)) {
7511
+ return renderReactToDOM(content);
7512
+ }
7513
+ return content;
7514
+ }
7515
+ };
7516
+ }
7517
+ return col;
7518
+ });
7519
+ }, [columns]);
7492
7520
  useEffect27(() => {
7493
- const customChildDataTableElement = tableRef.current;
7494
- if (!customChildDataTableElement) return;
7495
- if (columns !== void 0) customChildDataTableElement.setColumns = columns;
7496
- if (data !== void 0) customChildDataTableElement.setData = data;
7497
- if (dropdownArrowLocation !== void 0) customChildDataTableElement.setDropdownArrowLocation = dropdownArrowLocation;
7498
- if (sortIcon !== void 0) customChildDataTableElement.setSortIcon = sortIcon;
7499
- if (dropdownButtonIcon !== void 0) customChildDataTableElement.setDropdownButtonIcon = dropdownButtonIcon;
7500
- }, [columns, data, dropdownArrowLocation, sortIcon, dropdownButtonIcon]);
7521
+ const el = tableRef.current;
7522
+ if (!el) return;
7523
+ const resolveNodeToDOM = (node) => {
7524
+ if (node !== null && typeof node === "object" && !(node instanceof HTMLElement)) {
7525
+ return renderReactToDOM(node);
7526
+ }
7527
+ return node;
7528
+ };
7529
+ if (processedColumns !== void 0) el.setColumns = processedColumns;
7530
+ if (data !== void 0) el.setData = data;
7531
+ if (dropdownArrowLocation !== void 0) el.setDropdownArrowLocation = dropdownArrowLocation;
7532
+ if (sortIcon !== void 0) el.setSortIcon = resolveNodeToDOM(sortIcon);
7533
+ if (dropdownButtonIcon !== void 0) el.setDropdownButtonIcon = resolveNodeToDOM(dropdownButtonIcon);
7534
+ if (externalSort !== void 0) el.setExternalSort = externalSort;
7535
+ if (sortKey !== void 0) el.setSortKey = sortKey;
7536
+ if (sortOrder !== void 0) el.setSortOrder = sortOrder;
7537
+ }, [processedColumns, data, dropdownArrowLocation, sortIcon, dropdownButtonIcon, externalSort, sortKey, sortOrder]);
7501
7538
  useEffect27(() => {
7502
7539
  const el = tableRef.current;
7503
7540
  if (!el) return;
7541
+ const handleAction = (event) => {
7542
+ if (onAction) onAction(event);
7543
+ };
7504
7544
  const handleReactDropdown = (event) => {
7505
7545
  const customEvent = event;
7506
7546
  event.stopPropagation();
7507
7547
  const { container, itemId } = customEvent.detail;
7508
- let root = reactDropdownRoots.current.get(container);
7548
+ let root = dropdownRoots.current.get(container);
7509
7549
  if (!root) {
7510
7550
  root = createRoot(container);
7511
- reactDropdownRoots.current.set(container, root);
7551
+ dropdownRoots.current.set(container, root);
7512
7552
  }
7513
- const item = data?.find((item2) => String(item2.id) === String(itemId));
7514
- if (item && item.dropdown && root) {
7553
+ const item = data?.find((i) => String(i.id) === String(itemId));
7554
+ if (item?.dropdown && root) {
7515
7555
  root.render(item.dropdown);
7516
7556
  }
7517
- const dropdown = container.querySelector(".dropdown");
7518
- if (dropdown) {
7519
- dropdown.hidden = false;
7520
- }
7521
7557
  };
7522
7558
  const handleCleanupDropdown = (event) => {
7523
7559
  event.stopPropagation();
7524
7560
  const { container } = event.detail;
7525
- const root = reactDropdownRoots.current.get(container);
7526
- const dropdown = container.querySelector(".dropdown");
7527
- if (root && dropdown) {
7528
- dropdown.hidden = true;
7561
+ const root = dropdownRoots.current.get(container);
7562
+ if (root) {
7563
+ root.unmount();
7564
+ dropdownRoots.current.delete(container);
7529
7565
  }
7530
7566
  };
7567
+ el.addEventListener("action", handleAction);
7531
7568
  el.addEventListener("getReactDropdown", handleReactDropdown);
7532
7569
  el.addEventListener("cleanupDropdown", handleCleanupDropdown);
7533
7570
  return () => {
7571
+ el.removeEventListener("action", handleAction);
7534
7572
  el.removeEventListener("getReactDropdown", handleReactDropdown);
7535
7573
  el.removeEventListener("cleanupDropdown", handleCleanupDropdown);
7574
+ cellRoots.current.forEach((root) => root.unmount());
7575
+ cellRoots.current.clear();
7576
+ dropdownRoots.current.forEach((root) => root.unmount());
7577
+ dropdownRoots.current.clear();
7536
7578
  };
7537
- }, [data]);
7579
+ }, [data, onAction]);
7538
7580
  return /* @__PURE__ */ jsx53("wavelength-child-data-table", { ref: tableRef, ...rest });
7539
7581
  };
7540
7582
  ChildDataTable2.displayName = "ChildDataTable";
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@wavelengthusaf/components",
3
3
  "author": "563 EWS - Wavelength",
4
4
  "license": "MIT",
5
- "version": "4.16.0",
5
+ "version": "4.17.0",
6
6
  "description": "Common component library used by Wavelength developers",
7
7
  "main": "/dist/cjs/index.cjs",
8
8
  "module": "/dist/esm/index.js",
@@ -71,7 +71,7 @@
71
71
  "@emotion/styled": "^11.11.0",
72
72
  "@mui/icons-material": "^5.16.5",
73
73
  "@mui/material": "^5.15.7",
74
- "@wavelengthusaf/web-components": "^1.18.0",
74
+ "@wavelengthusaf/web-components": "^1.19.0",
75
75
  "react": "^18.2.0",
76
76
  "react-router-dom": "^6.26.2",
77
77
  "styled-components": "^6.1.12",