@liiift-studio/sanity-visitor-insights 0.48.0 → 0.49.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.
- package/dist/index.d.mts +7 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +31 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +31 -5
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/studio/Figure.tsx +80 -5
- package/src/studio/panels.test.tsx +89 -1
package/dist/index.d.mts
CHANGED
|
@@ -363,6 +363,13 @@ interface SortColumn<Row> {
|
|
|
363
363
|
* currency, and a column with a fallback displays something `sortValue` returns null for.
|
|
364
364
|
*/
|
|
365
365
|
exportValue?: (row: Row) => number | string | null;
|
|
366
|
+
/**
|
|
367
|
+
* Keep this column even when every value in it is blank or zero.
|
|
368
|
+
*
|
|
369
|
+
* For the column that identifies the row — a table whose first column collapsed would be a list
|
|
370
|
+
* of numbers belonging to nothing — and for any column whose emptiness is itself the finding.
|
|
371
|
+
*/
|
|
372
|
+
alwaysShow?: boolean;
|
|
366
373
|
render: (row: Row) => React.ReactNode;
|
|
367
374
|
}
|
|
368
375
|
/** Props for SortableTable. */
|
package/dist/index.d.ts
CHANGED
|
@@ -363,6 +363,13 @@ interface SortColumn<Row> {
|
|
|
363
363
|
* currency, and a column with a fallback displays something `sortValue` returns null for.
|
|
364
364
|
*/
|
|
365
365
|
exportValue?: (row: Row) => number | string | null;
|
|
366
|
+
/**
|
|
367
|
+
* Keep this column even when every value in it is blank or zero.
|
|
368
|
+
*
|
|
369
|
+
* For the column that identifies the row — a table whose first column collapsed would be a list
|
|
370
|
+
* of numbers belonging to nothing — and for any column whose emptiness is itself the finding.
|
|
371
|
+
*/
|
|
372
|
+
alwaysShow?: boolean;
|
|
366
373
|
render: (row: Row) => React.ReactNode;
|
|
367
374
|
}
|
|
368
375
|
/** Props for SortableTable. */
|
package/dist/index.js
CHANGED
|
@@ -648,6 +648,14 @@ function NoticeList({ notices }) {
|
|
|
648
648
|
)
|
|
649
649
|
] });
|
|
650
650
|
}
|
|
651
|
+
function columnIsEmpty(column, rows) {
|
|
652
|
+
if (column.alwaysShow) return false;
|
|
653
|
+
if (rows.length === 0) return false;
|
|
654
|
+
return rows.every((row) => {
|
|
655
|
+
const value = column.sortValue(row);
|
|
656
|
+
return value === 0 || value === "";
|
|
657
|
+
});
|
|
658
|
+
}
|
|
651
659
|
function SortableTable({
|
|
652
660
|
caption,
|
|
653
661
|
columns,
|
|
@@ -666,6 +674,7 @@ function SortableTable({
|
|
|
666
674
|
const [query, setQuery] = import_react2.default.useState("");
|
|
667
675
|
const [excluded, setExcluded] = import_react2.default.useState(() => /* @__PURE__ */ new Set());
|
|
668
676
|
const [copied, setCopied] = import_react2.default.useState("idle");
|
|
677
|
+
const [showEmpty, setShowEmpty] = import_react2.default.useState(false);
|
|
669
678
|
const copyTimer = import_react2.default.useRef(null);
|
|
670
679
|
import_react2.default.useEffect(() => () => {
|
|
671
680
|
if (copyTimer.current !== null) window.clearTimeout(copyTimer.current);
|
|
@@ -679,6 +688,13 @@ function SortableTable({
|
|
|
679
688
|
return filterOn(row).toLowerCase().includes(needle);
|
|
680
689
|
});
|
|
681
690
|
}, [rows, query, excluded, filterOn, rowKey]);
|
|
691
|
+
const emptyColumns = import_react2.default.useMemo(
|
|
692
|
+
() => columns.filter(
|
|
693
|
+
(column, index) => index > 0 && column.key !== sort?.key && columnIsEmpty(column, visible)
|
|
694
|
+
),
|
|
695
|
+
[columns, visible, sort?.key]
|
|
696
|
+
);
|
|
697
|
+
const shown = showEmpty || emptyColumns.length === 0 ? columns : columns.filter((column) => !emptyColumns.includes(column));
|
|
682
698
|
const ordered = import_react2.default.useMemo(() => {
|
|
683
699
|
const rows2 = visible;
|
|
684
700
|
if (!active || !sort) return rows2;
|
|
@@ -701,8 +717,8 @@ function SortableTable({
|
|
|
701
717
|
});
|
|
702
718
|
};
|
|
703
719
|
const copyCsv = async () => {
|
|
704
|
-
const header =
|
|
705
|
-
const lines = [header, ...ordered.map((row) =>
|
|
720
|
+
const header = shown.map((column) => column.label);
|
|
721
|
+
const lines = [header, ...ordered.map((row) => shown.map((column) => {
|
|
706
722
|
const value = column.exportValue ? column.exportValue(row) : column.sortValue(row);
|
|
707
723
|
return value === null || value === void 0 ? "" : String(value);
|
|
708
724
|
}))];
|
|
@@ -722,7 +738,7 @@ function SortableTable({
|
|
|
722
738
|
const hiddenCount = rows.length - visible.length - excludedInWindow;
|
|
723
739
|
const excludedCount = excluded.size;
|
|
724
740
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_sanity_ui_compat.Stack, { space: 2, children: [
|
|
725
|
-
(filterOn || exportName) && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: tableControls, children: [
|
|
741
|
+
(filterOn || exportName || emptyColumns.length > 0) && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: tableControls, children: [
|
|
726
742
|
filterOn && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
727
743
|
"input",
|
|
728
744
|
{
|
|
@@ -750,11 +766,21 @@ function SortableTable({
|
|
|
750
766
|
] })
|
|
751
767
|
] }),
|
|
752
768
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { style: { flex: 1 } }),
|
|
769
|
+
emptyColumns.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
770
|
+
"button",
|
|
771
|
+
{
|
|
772
|
+
type: "button",
|
|
773
|
+
style: tableControlButton,
|
|
774
|
+
"aria-pressed": showEmpty,
|
|
775
|
+
onClick: () => setShowEmpty((open) => !open),
|
|
776
|
+
children: showEmpty ? `Hide ${emptyColumns.length} empty column${emptyColumns.length === 1 ? "" : "s"}` : `Show ${emptyColumns.length} empty column${emptyColumns.length === 1 ? "" : "s"}`
|
|
777
|
+
}
|
|
778
|
+
),
|
|
753
779
|
exportName && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", style: tableControlButton, onClick: () => void copyCsv(), children: copied === "done" ? "Copied" : copied === "failed" ? "Could not copy" : "Copy as CSV" })
|
|
754
780
|
] }),
|
|
755
781
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_sanity_ui_compat.Card, { radius: 2, tone: "transparent", border: true, style: tableWrapper, children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("table", { style: tableBase, children: [
|
|
756
782
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("caption", { style: visuallyHidden, children: caption }),
|
|
757
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("thead", { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("tr", { children:
|
|
783
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("thead", { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("tr", { children: shown.map((column) => {
|
|
758
784
|
const isActive = sort?.key === column.key;
|
|
759
785
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
760
786
|
"th",
|
|
@@ -773,7 +799,7 @@ function SortableTable({
|
|
|
773
799
|
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("tbody", { children: [
|
|
774
800
|
ordered.map((row) => {
|
|
775
801
|
const key = rowKey(row);
|
|
776
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("tr", { children:
|
|
802
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("tr", { children: shown.map((column, index) => {
|
|
777
803
|
const content = column.render(row);
|
|
778
804
|
return index === 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("th", { scope: "row", style: bodyCell, children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { style: firstCell, children: [
|
|
779
805
|
content,
|