@vantageos/mosaic-blocks 0.3.4-alpha → 0.3.5-alpha

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/index.cjs CHANGED
@@ -46,7 +46,7 @@ function _interopNamespace(e) {
46
46
  var React27__namespace = /*#__PURE__*/_interopNamespace(React27);
47
47
 
48
48
  // src/version.ts
49
- var version = "0.3.4-alpha";
49
+ var version = "0.3.5-alpha";
50
50
  function Placeholder({ label = "mosaic-blocks placeholder" }) {
51
51
  return /* @__PURE__ */ jsxRuntime.jsx("div", { "data-mosaic-block": "placeholder", children: label });
52
52
  }
@@ -9702,6 +9702,139 @@ function MosaicOrgProfilePage({
9702
9702
  );
9703
9703
  }
9704
9704
  MosaicOrgProfilePage.displayName = "MosaicOrgProfilePage";
9705
+ function cn66(...classes) {
9706
+ return classes.filter(Boolean).join(" ");
9707
+ }
9708
+ function defaultCompare(a, b) {
9709
+ if (typeof a === "number" && typeof b === "number") return a - b;
9710
+ return String(a ?? "").localeCompare(String(b ?? ""), void 0, { numeric: true });
9711
+ }
9712
+ function MosaicDataTable({
9713
+ columns,
9714
+ rows,
9715
+ getRowKey,
9716
+ sortable: masterSortable = true,
9717
+ emptyState,
9718
+ className,
9719
+ ref
9720
+ }) {
9721
+ const [sort, setSort] = React27.useState(null);
9722
+ function handleHeaderClick(col) {
9723
+ if (!masterSortable || !col.sortable) return;
9724
+ setSort((prev) => {
9725
+ if (prev?.key === col.key) {
9726
+ return { key: col.key, direction: prev.direction === "asc" ? "desc" : "asc" };
9727
+ }
9728
+ return { key: col.key, direction: "asc" };
9729
+ });
9730
+ }
9731
+ const sortedRows = sort ? [...rows].sort((a, b) => {
9732
+ const aVal = a[sort.key];
9733
+ const bVal = b[sort.key];
9734
+ const cmp = defaultCompare(aVal, bVal);
9735
+ return sort.direction === "asc" ? cmp : -cmp;
9736
+ }) : rows;
9737
+ function alignClass(align) {
9738
+ if (align === "right") return "text-right";
9739
+ if (align === "center") return "text-center";
9740
+ return "text-left";
9741
+ }
9742
+ function ariaSort(col) {
9743
+ if (!sort || sort.key !== col.key) return "none";
9744
+ return sort.direction === "asc" ? "ascending" : "descending";
9745
+ }
9746
+ function sortIndicator(col) {
9747
+ if (!masterSortable || !col.sortable) return null;
9748
+ if (!sort || sort.key !== col.key) {
9749
+ return /* @__PURE__ */ jsxRuntime.jsx(
9750
+ "span",
9751
+ {
9752
+ "aria-hidden": "true",
9753
+ className: "ml-1 inline-block select-none text-xs text-muted-foreground opacity-40",
9754
+ children: "\u2195"
9755
+ }
9756
+ );
9757
+ }
9758
+ return /* @__PURE__ */ jsxRuntime.jsx("span", { "aria-hidden": "true", className: "ml-1 inline-block select-none text-xs", children: sort.direction === "asc" ? "\u25B2" : "\u25BC" });
9759
+ }
9760
+ return /* @__PURE__ */ jsxRuntime.jsxs(
9761
+ "table",
9762
+ {
9763
+ ref,
9764
+ "data-slot": "data-table",
9765
+ className: cn66("w-full border-collapse text-sm", className),
9766
+ children: [
9767
+ /* @__PURE__ */ jsxRuntime.jsx("thead", { "data-slot": "data-table-header", children: /* @__PURE__ */ jsxRuntime.jsx("tr", { "data-slot": "data-table-header-row", className: "border-b border-border bg-muted", children: columns.map((col, colIndex) => {
9768
+ const isSortable = masterSortable && col.sortable;
9769
+ return /* @__PURE__ */ jsxRuntime.jsxs(
9770
+ "th",
9771
+ {
9772
+ "data-slot": "data-table-th",
9773
+ scope: "col",
9774
+ "aria-sort": ariaSort(col),
9775
+ tabIndex: isSortable ? 0 : void 0,
9776
+ onClick: isSortable ? () => handleHeaderClick(col) : void 0,
9777
+ onKeyDown: isSortable ? (e) => {
9778
+ if (e.key === "Enter" || e.key === " ") {
9779
+ e.preventDefault();
9780
+ handleHeaderClick(col);
9781
+ }
9782
+ } : void 0,
9783
+ className: cn66(
9784
+ "px-4 py-3 font-medium text-muted-foreground",
9785
+ alignClass(col.align),
9786
+ col.className,
9787
+ isSortable && "cursor-pointer select-none hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
9788
+ ),
9789
+ children: [
9790
+ col.header,
9791
+ sortIndicator(col)
9792
+ ]
9793
+ },
9794
+ colIndex
9795
+ );
9796
+ }) }) }),
9797
+ /* @__PURE__ */ jsxRuntime.jsx("tbody", { "data-slot": "data-table-body", children: sortedRows.length === 0 ? /* @__PURE__ */ jsxRuntime.jsx("tr", { "data-slot": "data-table-empty-row", children: /* @__PURE__ */ jsxRuntime.jsx(
9798
+ "td",
9799
+ {
9800
+ "data-slot": "data-table-empty-cell",
9801
+ colSpan: columns.length,
9802
+ className: "px-4 py-12 text-center text-muted-foreground",
9803
+ children: emptyState ?? "No data"
9804
+ }
9805
+ ) }) : sortedRows.map((row, index) => {
9806
+ const key = getRowKey ? getRowKey(row, index) : index;
9807
+ return /* @__PURE__ */ jsxRuntime.jsx(
9808
+ "tr",
9809
+ {
9810
+ "data-slot": "data-table-row",
9811
+ className: "border-b border-border hover:bg-muted/50 transition-colors",
9812
+ children: columns.map((col, colIndex) => {
9813
+ const rawVal = row[col.key];
9814
+ const cell = col.render ? col.render(row) : String(rawVal ?? "");
9815
+ return /* @__PURE__ */ jsxRuntime.jsx(
9816
+ "td",
9817
+ {
9818
+ "data-slot": "data-table-td",
9819
+ className: cn66(
9820
+ "px-4 py-3 text-foreground",
9821
+ alignClass(col.align),
9822
+ col.className
9823
+ ),
9824
+ children: cell
9825
+ },
9826
+ colIndex
9827
+ );
9828
+ })
9829
+ },
9830
+ key
9831
+ );
9832
+ }) })
9833
+ ]
9834
+ }
9835
+ );
9836
+ }
9837
+ MosaicDataTable.displayName = "MosaicDataTable";
9705
9838
  var WorkspaceCtx = React27__namespace.createContext({
9706
9839
  workspaceId: null,
9707
9840
  isLoading: false
@@ -9872,6 +10005,7 @@ exports.MosaicCreateOrgDialog = MosaicCreateOrgDialog;
9872
10005
  exports.MosaicDashboardContent = MosaicDashboardContent;
9873
10006
  exports.MosaicDashboardHeader = MosaicDashboardHeader;
9874
10007
  exports.MosaicDashboardLayout = MosaicDashboardLayout;
10008
+ exports.MosaicDataTable = MosaicDataTable;
9875
10009
  exports.MosaicDeleteConfirmationDialog = MosaicDeleteConfirmationDialog;
9876
10010
  exports.MosaicDeviceProvider = MosaicDeviceProvider;
9877
10011
  exports.MosaicDropdownMenu = MosaicDropdownMenu;