npm package diff
Package: @forge/react
Versions: 10.10.0 - 10.10.1-next.0
File: package/out/components/dynamic-table.js
Index: package/out/components/dynamic-table.js
===================================================================
--- package/out/components/dynamic-table.js
+++ package/out/components/dynamic-table.js
@@ -0,0 +1,40 @@
+"use strict";
+Object.defineProperty(exports, "__esModule", { value: true });
+exports.DynamicTable = void 0;
+const jsx_runtime_1 = require("react/jsx-runtime");
+const react_1 = require("react");
+const content_wrapper_1 = require("./utils/content-wrapper");
+/**
+ * These are internal components that the table head and rows are converted into.
+ * This is to ensure that they are correctly reconciled into ForgeDoc before being sent over
+ * the bridge. On the product frontend, the ForgeDoc is transformed back into the props the
+ * ADS DynamicTable expects.
+ * */
+const DynamicTablePrimitive = 'DynamicTable';
+const Cell = 'Cell';
+const Row = 'Row';
+const DynamicTable = ({ head, rows, ...tableProps }) => {
+ const transformedHead = head?.cells.map((cell) => {
+ const { content, key: cellKey, ...cellProps } = cell;
+ const reconciledContent =
+ // @ts-ignore Not all constituents of type JSXElementConstructor are callable.
+ (0, react_1.isValidElement)(content) && typeof content.type === 'function' ? content.type(content.props) : content;
+ return (
+ // The 'key' prop needs to be renamed as it is a reserved keyword in React, and won't
+ // get included in the props object otherwise.
+ (0, jsx_runtime_1.jsx)(Cell, { cellKey: cellKey, ...cellProps, children: reconciledContent }, cellKey));
+ });
+ const transformedRows = rows?.map((row) => {
+ const { cells, key: rowKey, ...rowProps } = row;
+ const transformedCells = cells.map((cell) => {
+ const { content, key: cellKey, ...cellProps } = cell;
+ const reconciledContent =
+ // @ts-ignore Not all constituents of type JSXElementConstructor are callable.
+ (0, react_1.isValidElement)(content) && typeof content.type === 'function' ? content.type(content.props) : content;
+ return ((0, jsx_runtime_1.jsx)(Cell, { cellKey: cellKey, ...cellProps, children: reconciledContent }, cellKey));
+ });
+ return ((0, jsx_runtime_1.jsx)(Row, { rowKey: rowKey, ...rowProps, children: transformedCells }, rowKey));
+ });
+ return ((0, jsx_runtime_1.jsxs)(DynamicTablePrimitive, { ...tableProps, children: [(0, jsx_runtime_1.jsx)(content_wrapper_1.ContentWrapper, { name: "head", children: transformedHead }), (0, jsx_runtime_1.jsx)(content_wrapper_1.ContentWrapper, { name: "rows", children: transformedRows })] }));
+};
+exports.DynamicTable = DynamicTable;