@dxos/react-ui-table 0.3.7-main.e08407b → 0.3.7-main.ec7f1fc
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/lib/browser/index.mjs +123 -77
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/types/src/components/ComboboxCell.d.ts +12 -0
- package/dist/types/src/components/ComboboxCell.d.ts.map +1 -0
- package/dist/types/src/components/Table.stories.d.ts +4 -3
- package/dist/types/src/components/Table.stories.d.ts.map +1 -1
- package/dist/types/src/components/index.d.ts +1 -0
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/helpers.d.ts.map +1 -1
- package/dist/types/src/translations.d.ts +10 -0
- package/dist/types/src/translations.d.ts.map +1 -0
- package/dist/types/src/types.d.ts +1 -1
- package/dist/types/src/types.d.ts.map +1 -1
- package/package.json +10 -9
- package/src/components/ComboboxCell.tsx +97 -0
- package/src/components/Table.stories.tsx +62 -64
- package/src/components/index.ts +1 -0
- package/src/helpers.tsx +6 -49
- package/src/translations.ts +15 -0
- package/src/types.ts +1 -1
|
@@ -520,6 +520,89 @@ var TableFoot = ({ footers, expand, slots, debug, border }) => {
|
|
|
520
520
|
}))));
|
|
521
521
|
};
|
|
522
522
|
|
|
523
|
+
// packages/ui/react-ui-table/src/components/ComboboxCell.tsx
|
|
524
|
+
import { CaretDown as CaretDown2 } from "@phosphor-icons/react";
|
|
525
|
+
import React3, { useCallback, useState as useState3 } from "react";
|
|
526
|
+
import { Popover as Popover2, useTranslation } from "@dxos/react-ui";
|
|
527
|
+
import { PopoverCombobox } from "@dxos/react-ui-searchlist";
|
|
528
|
+
import { descriptionText, getSize as getSize2, mx as mx3, staticPlaceholderText } from "@dxos/react-ui-theme";
|
|
529
|
+
|
|
530
|
+
// packages/ui/react-ui-table/src/translations.ts
|
|
531
|
+
var translationKey = "table";
|
|
532
|
+
var translations_default = [
|
|
533
|
+
{
|
|
534
|
+
"en-US": {
|
|
535
|
+
[translationKey]: {
|
|
536
|
+
"no selection label": "\xA0"
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
];
|
|
541
|
+
|
|
542
|
+
// packages/ui/react-ui-table/src/components/ComboboxCell.tsx
|
|
543
|
+
var initialItems = (model, value) => value ? {
|
|
544
|
+
[model.getId(value)]: {
|
|
545
|
+
label: model.getText(value),
|
|
546
|
+
data: value
|
|
547
|
+
}
|
|
548
|
+
} : {};
|
|
549
|
+
var ComboboxCell = ({ model, value, onValueChange }) => {
|
|
550
|
+
const { t } = useTranslation(translationKey);
|
|
551
|
+
const [items, setItems] = useState3(initialItems(model, value));
|
|
552
|
+
const [loading, setLoading] = useState3(false);
|
|
553
|
+
const [searchInputValue, setSearchInputValue] = useState3("");
|
|
554
|
+
const handleSearchInputValueChange = async (text) => {
|
|
555
|
+
setSearchInputValue(text ?? "");
|
|
556
|
+
setLoading(true);
|
|
557
|
+
const items2 = await model.query(text);
|
|
558
|
+
setItems(items2.reduce((acc, item) => {
|
|
559
|
+
acc[model.getId(item)] = {
|
|
560
|
+
label: model.getText(item),
|
|
561
|
+
data: item
|
|
562
|
+
};
|
|
563
|
+
return acc;
|
|
564
|
+
}, initialItems(model, value)));
|
|
565
|
+
setLoading(false);
|
|
566
|
+
};
|
|
567
|
+
const handleValueChange = useCallback((id) => {
|
|
568
|
+
onValueChange(items[id]?.data);
|
|
569
|
+
}, [
|
|
570
|
+
items,
|
|
571
|
+
onValueChange
|
|
572
|
+
]);
|
|
573
|
+
return /* @__PURE__ */ React3.createElement(PopoverCombobox.Root, {
|
|
574
|
+
placeholder: t("no selection label")
|
|
575
|
+
}, /* @__PURE__ */ React3.createElement(PopoverCombobox.Trigger, {
|
|
576
|
+
variant: "ghost",
|
|
577
|
+
classNames: "is-full"
|
|
578
|
+
}, value ? /* @__PURE__ */ React3.createElement(React3.Fragment, null, /* @__PURE__ */ React3.createElement("span", {
|
|
579
|
+
className: mx3("font-normal text-start flex-1 min-is-0 truncate mie-2", !value && staticPlaceholderText)
|
|
580
|
+
}, model.getText(value)), /* @__PURE__ */ React3.createElement(CaretDown2, {
|
|
581
|
+
weight: "bold",
|
|
582
|
+
className: getSize2(3)
|
|
583
|
+
})) : null), /* @__PURE__ */ React3.createElement(PopoverCombobox.Content, {
|
|
584
|
+
shouldFilter: false,
|
|
585
|
+
classNames: "is-[--radix-popover-trigger-width]"
|
|
586
|
+
}, /* @__PURE__ */ React3.createElement(PopoverCombobox.Input, {
|
|
587
|
+
value: searchInputValue,
|
|
588
|
+
onValueChange: handleSearchInputValueChange
|
|
589
|
+
}), /* @__PURE__ */ React3.createElement(PopoverCombobox.List, null, searchInputValue.length < 1 ? /* @__PURE__ */ React3.createElement("p", {
|
|
590
|
+
className: mx3("text-center", descriptionText)
|
|
591
|
+
}, "Start typing to search") : loading ? /* @__PURE__ */ React3.createElement("p", {
|
|
592
|
+
className: mx3("text-center", descriptionText)
|
|
593
|
+
}, "Searching\u2026") : /* @__PURE__ */ React3.createElement(React3.Fragment, null, /* @__PURE__ */ React3.createElement(PopoverCombobox.Empty, {
|
|
594
|
+
classNames: [
|
|
595
|
+
"text-center",
|
|
596
|
+
descriptionText
|
|
597
|
+
]
|
|
598
|
+
}, "No results"), Object.entries(items).map(([id, { label }]) => /* @__PURE__ */ React3.createElement(PopoverCombobox.Item, {
|
|
599
|
+
key: id,
|
|
600
|
+
value: id,
|
|
601
|
+
onSelect: handleValueChange,
|
|
602
|
+
classNames: "truncate"
|
|
603
|
+
}, label)))), /* @__PURE__ */ React3.createElement(Popover2.Arrow, null)));
|
|
604
|
+
};
|
|
605
|
+
|
|
523
606
|
// packages/ui/react-ui-table/src/helpers.tsx
|
|
524
607
|
import { useFocusFinders } from "@fluentui/react-tabster";
|
|
525
608
|
import { Check as Check2, ClipboardText, X as X2 } from "@phosphor-icons/react";
|
|
@@ -527,9 +610,9 @@ import { createColumnHelper } from "@tanstack/react-table";
|
|
|
527
610
|
import format from "date-fns/format";
|
|
528
611
|
import formatDistanceToNow from "date-fns/formatDistanceToNow";
|
|
529
612
|
import defaultsDeep from "lodash.defaultsdeep";
|
|
530
|
-
import
|
|
531
|
-
import {
|
|
532
|
-
import { getSize as
|
|
613
|
+
import React4, { useRef as useRef3, useState as useState4 } from "react";
|
|
614
|
+
import { Input as Input2, Tooltip } from "@dxos/react-ui";
|
|
615
|
+
import { getSize as getSize3, mx as mx4 } from "@dxos/react-ui-theme";
|
|
533
616
|
import { stripUndefinedValues } from "@dxos/util";
|
|
534
617
|
var findNextFocusable = (findFirstFocusable, container) => {
|
|
535
618
|
const next = findFirstFocusable(container);
|
|
@@ -549,44 +632,6 @@ var createColumnBuilder = () => ({
|
|
|
549
632
|
var defaults = (options, ...sources) => {
|
|
550
633
|
return stripUndefinedValues(defaultsDeep({}, options, ...sources));
|
|
551
634
|
};
|
|
552
|
-
var CellSelector = ({ model, value: _value, onUpdate }) => {
|
|
553
|
-
const [edit, setEdit] = useState3(false);
|
|
554
|
-
const [value, setValue] = useState3();
|
|
555
|
-
useEffect2(() => setValue(_value ? {
|
|
556
|
-
id: model.getId(_value),
|
|
557
|
-
label: model.getText(_value)
|
|
558
|
-
} : void 0), [
|
|
559
|
-
_value
|
|
560
|
-
]);
|
|
561
|
-
const [items, setItems] = useState3([]);
|
|
562
|
-
const handleUpdate = async (text) => {
|
|
563
|
-
const items2 = await model.query(text);
|
|
564
|
-
setItems(items2.map((item) => ({
|
|
565
|
-
id: model.getId(item),
|
|
566
|
-
label: model.getText(item),
|
|
567
|
-
data: item
|
|
568
|
-
})));
|
|
569
|
-
};
|
|
570
|
-
if (!edit) {
|
|
571
|
-
const text = _value ? model.getText(_value) : void 0;
|
|
572
|
-
return (
|
|
573
|
-
// TODO(burdon): Hack to prevent div from collapsing.
|
|
574
|
-
/* @__PURE__ */ React3.createElement("div", {
|
|
575
|
-
className: mx3("w-full px-2", !text && "opacity-0"),
|
|
576
|
-
onClick: () => setEdit(true)
|
|
577
|
-
}, text ?? "-")
|
|
578
|
-
);
|
|
579
|
-
}
|
|
580
|
-
return /* @__PURE__ */ React3.createElement(ComboBox.Root, {
|
|
581
|
-
items,
|
|
582
|
-
value,
|
|
583
|
-
onChange: (value2) => onUpdate(value2?.data),
|
|
584
|
-
onInputChange: handleUpdate
|
|
585
|
-
}, /* @__PURE__ */ React3.createElement(ComboBox.Input, null), /* @__PURE__ */ React3.createElement(ComboBox.Content, null, items.map((item) => /* @__PURE__ */ React3.createElement(ComboBox.Item, {
|
|
586
|
-
key: item.id,
|
|
587
|
-
item
|
|
588
|
-
}, item.label))));
|
|
589
|
-
};
|
|
590
635
|
var ColumnBuilder = class {
|
|
591
636
|
/**
|
|
592
637
|
* Select value
|
|
@@ -595,18 +640,18 @@ var ColumnBuilder = class {
|
|
|
595
640
|
return defaults(props, {
|
|
596
641
|
minSize: 100,
|
|
597
642
|
header: (column) => {
|
|
598
|
-
return /* @__PURE__ */
|
|
643
|
+
return /* @__PURE__ */ React4.createElement("div", {
|
|
599
644
|
className: "truncate"
|
|
600
645
|
}, label ?? column.header.id);
|
|
601
646
|
},
|
|
602
|
-
cell: model && onUpdate ? (cell) => /* @__PURE__ */
|
|
647
|
+
cell: model && onUpdate ? (cell) => /* @__PURE__ */ React4.createElement(ComboboxCell, {
|
|
603
648
|
model,
|
|
604
649
|
value: cell.getValue(),
|
|
605
|
-
|
|
650
|
+
onValueChange: (value) => onUpdate?.(cell.row.original, cell.column.id, value)
|
|
606
651
|
}) : (cell) => {
|
|
607
652
|
const value = cell.getValue();
|
|
608
|
-
return /* @__PURE__ */
|
|
609
|
-
className:
|
|
653
|
+
return /* @__PURE__ */ React4.createElement("div", {
|
|
654
|
+
className: mx4("truncate", className)
|
|
610
655
|
}, value ? model.getText(value) : "");
|
|
611
656
|
}
|
|
612
657
|
});
|
|
@@ -619,13 +664,13 @@ var ColumnBuilder = class {
|
|
|
619
664
|
minSize: 100,
|
|
620
665
|
// TODO(burdon): Default.
|
|
621
666
|
header: (column) => {
|
|
622
|
-
return /* @__PURE__ */
|
|
667
|
+
return /* @__PURE__ */ React4.createElement("div", {
|
|
623
668
|
className: "truncate"
|
|
624
669
|
}, label ?? column.header.id);
|
|
625
670
|
},
|
|
626
671
|
cell: onUpdate ? (cell) => {
|
|
627
672
|
const initialValue = cell.getValue();
|
|
628
|
-
const [value, setValue] =
|
|
673
|
+
const [value, setValue] = useState4(initialValue);
|
|
629
674
|
const inputRef = useRef3(null);
|
|
630
675
|
const { findFirstFocusable } = useFocusFinders();
|
|
631
676
|
const handleSave = (focusNext = false) => {
|
|
@@ -647,7 +692,7 @@ var ColumnBuilder = class {
|
|
|
647
692
|
const rows = cell.table.getRowModel().flatRows;
|
|
648
693
|
const columns = cell.table.getVisibleFlatColumns();
|
|
649
694
|
const placeholder = cell.row.index === rows.length - 1 && columns[0].id === cell.column.id;
|
|
650
|
-
return /* @__PURE__ */
|
|
695
|
+
return /* @__PURE__ */ React4.createElement(Input2.Root, null, /* @__PURE__ */ React4.createElement(Input2.TextInput, {
|
|
651
696
|
ref: inputRef,
|
|
652
697
|
variant: "subdued",
|
|
653
698
|
placeholder: placeholder ? "Add row..." : void 0,
|
|
@@ -659,8 +704,8 @@ var ColumnBuilder = class {
|
|
|
659
704
|
}));
|
|
660
705
|
} : (cell) => {
|
|
661
706
|
const value = cell.getValue();
|
|
662
|
-
return /* @__PURE__ */
|
|
663
|
-
className:
|
|
707
|
+
return /* @__PURE__ */ React4.createElement("div", {
|
|
708
|
+
className: mx4("truncate", className)
|
|
664
709
|
}, value);
|
|
665
710
|
}
|
|
666
711
|
});
|
|
@@ -672,12 +717,12 @@ var ColumnBuilder = class {
|
|
|
672
717
|
return defaults(props, {
|
|
673
718
|
size: 100,
|
|
674
719
|
minSize: 100,
|
|
675
|
-
header: (cell) => /* @__PURE__ */
|
|
720
|
+
header: (cell) => /* @__PURE__ */ React4.createElement("div", {
|
|
676
721
|
className: "w-full truncate text-right"
|
|
677
722
|
}, label ?? cell.header.id),
|
|
678
723
|
cell: (cell) => {
|
|
679
724
|
const value = cell.getValue();
|
|
680
|
-
const [text, setText] =
|
|
725
|
+
const [text, setText] = useState4();
|
|
681
726
|
const handleEdit = () => {
|
|
682
727
|
if (onUpdate) {
|
|
683
728
|
setText(value !== void 0 ? String(value) : "");
|
|
@@ -692,9 +737,9 @@ var ColumnBuilder = class {
|
|
|
692
737
|
setText(void 0);
|
|
693
738
|
};
|
|
694
739
|
if (text !== void 0) {
|
|
695
|
-
return /* @__PURE__ */
|
|
696
|
-
className:
|
|
697
|
-
}, /* @__PURE__ */
|
|
740
|
+
return /* @__PURE__ */ React4.createElement("div", {
|
|
741
|
+
className: mx4("grow text-right font-mono", className)
|
|
742
|
+
}, /* @__PURE__ */ React4.createElement(Input2.Root, null, /* @__PURE__ */ React4.createElement(Input2.TextInput, {
|
|
698
743
|
autoFocus: true,
|
|
699
744
|
value: text,
|
|
700
745
|
classNames: "px-2",
|
|
@@ -703,8 +748,8 @@ var ColumnBuilder = class {
|
|
|
703
748
|
onKeyDown: (event) => event.key === "Escape" && handleCancel() || event.key === "Enter" && handleSave()
|
|
704
749
|
})));
|
|
705
750
|
}
|
|
706
|
-
return /* @__PURE__ */
|
|
707
|
-
className:
|
|
751
|
+
return /* @__PURE__ */ React4.createElement("div", {
|
|
752
|
+
className: mx4('grow w-full text-right font-mono empty:after:content-["\xA0"]', className),
|
|
708
753
|
onClick: handleEdit
|
|
709
754
|
}, value?.toLocaleString(void 0, {
|
|
710
755
|
minimumFractionDigits: digits ?? 0,
|
|
@@ -721,15 +766,15 @@ var ColumnBuilder = class {
|
|
|
721
766
|
return defaults(props, {
|
|
722
767
|
size: 220,
|
|
723
768
|
minSize: 100,
|
|
724
|
-
header: (cell) => /* @__PURE__ */
|
|
769
|
+
header: (cell) => /* @__PURE__ */ React4.createElement("div", null, label ?? cell.header.id),
|
|
725
770
|
cell: (cell) => {
|
|
726
771
|
const value = cell.getValue();
|
|
727
772
|
try {
|
|
728
773
|
const str = value ? formatSpec ? format(value, formatSpec) : relative ? formatDistanceToNow(value, {
|
|
729
774
|
addSuffix: true
|
|
730
775
|
}) : value.toISOString() : void 0;
|
|
731
|
-
return /* @__PURE__ */
|
|
732
|
-
className:
|
|
776
|
+
return /* @__PURE__ */ React4.createElement("div", {
|
|
777
|
+
className: mx4("font-mono", className)
|
|
733
778
|
}, str);
|
|
734
779
|
} catch (err) {
|
|
735
780
|
console.log(value);
|
|
@@ -745,25 +790,25 @@ var ColumnBuilder = class {
|
|
|
745
790
|
return defaults(props, {
|
|
746
791
|
size: 86,
|
|
747
792
|
minSize: 86,
|
|
748
|
-
header: (cell) => /* @__PURE__ */
|
|
793
|
+
header: (cell) => /* @__PURE__ */ React4.createElement("div", null, label ?? cell.header.id),
|
|
749
794
|
cell: (cell) => {
|
|
750
795
|
const value = cell.getValue();
|
|
751
796
|
if (!value) {
|
|
752
797
|
return;
|
|
753
798
|
}
|
|
754
|
-
const element = /* @__PURE__ */
|
|
799
|
+
const element = /* @__PURE__ */ React4.createElement("div", {
|
|
755
800
|
className: "font-mono font-thin text-green-500 dark:text-green-300"
|
|
756
801
|
}, value.truncate());
|
|
757
802
|
if (!tooltip) {
|
|
758
803
|
return element;
|
|
759
804
|
}
|
|
760
|
-
return /* @__PURE__ */
|
|
805
|
+
return /* @__PURE__ */ React4.createElement("div", {
|
|
761
806
|
className: "group inline-flex gap-2 items-center"
|
|
762
|
-
}, /* @__PURE__ */
|
|
807
|
+
}, /* @__PURE__ */ React4.createElement(Tooltip.Provider, null, /* @__PURE__ */ React4.createElement(Tooltip.Root, null, /* @__PURE__ */ React4.createElement(Tooltip.Trigger, {
|
|
763
808
|
asChild: true
|
|
764
|
-
}, element), /* @__PURE__ */
|
|
809
|
+
}, element), /* @__PURE__ */ React4.createElement(Tooltip.Content, {
|
|
765
810
|
side: "right"
|
|
766
|
-
}, /* @__PURE__ */
|
|
811
|
+
}, /* @__PURE__ */ React4.createElement(Tooltip.Arrow, null), /* @__PURE__ */ React4.createElement(ClipboardText, {
|
|
767
812
|
onClick: (ev) => {
|
|
768
813
|
ev.stopPropagation();
|
|
769
814
|
void navigator.clipboard.writeText(value.toHex());
|
|
@@ -779,14 +824,14 @@ var ColumnBuilder = class {
|
|
|
779
824
|
return defaults(props, {
|
|
780
825
|
size: 40,
|
|
781
826
|
minSize: 40,
|
|
782
|
-
header: (column) => /* @__PURE__ */
|
|
827
|
+
header: (column) => /* @__PURE__ */ React4.createElement("div", {
|
|
783
828
|
className: "flex grow justify-center"
|
|
784
829
|
}, label ?? column.header.id),
|
|
785
830
|
cell: (cell) => {
|
|
786
831
|
const value = cell.getValue();
|
|
787
|
-
return /* @__PURE__ */
|
|
832
|
+
return /* @__PURE__ */ React4.createElement("div", {
|
|
788
833
|
className: "flex grow justify-center"
|
|
789
|
-
}, /* @__PURE__ */
|
|
834
|
+
}, /* @__PURE__ */ React4.createElement(Input2.Root, null, /* @__PURE__ */ React4.createElement(Input2.Checkbox, {
|
|
790
835
|
onClick: (event) => event.stopPropagation(),
|
|
791
836
|
classNames: className,
|
|
792
837
|
disabled: !onUpdate,
|
|
@@ -806,22 +851,22 @@ var ColumnBuilder = class {
|
|
|
806
851
|
const IconOff = off?.Icon ?? X2;
|
|
807
852
|
return defaults(props, {
|
|
808
853
|
size: size ?? 32,
|
|
809
|
-
header: (column) => /* @__PURE__ */
|
|
854
|
+
header: (column) => /* @__PURE__ */ React4.createElement("div", {
|
|
810
855
|
className: "justify-center"
|
|
811
856
|
}, label ?? column.header.id),
|
|
812
857
|
cell: (cell) => {
|
|
813
858
|
const value = cell.getValue();
|
|
814
859
|
if (value) {
|
|
815
|
-
return /* @__PURE__ */
|
|
860
|
+
return /* @__PURE__ */ React4.createElement("div", {
|
|
816
861
|
className: "flex grow justify-center"
|
|
817
|
-
}, /* @__PURE__ */
|
|
818
|
-
className:
|
|
862
|
+
}, /* @__PURE__ */ React4.createElement(IconOn, {
|
|
863
|
+
className: mx4(getSize3(6), on?.className ?? "text-green-700")
|
|
819
864
|
}));
|
|
820
865
|
} else if (value === false) {
|
|
821
|
-
return /* @__PURE__ */
|
|
866
|
+
return /* @__PURE__ */ React4.createElement("div", {
|
|
822
867
|
className: "flex grow justify-center"
|
|
823
|
-
}, /* @__PURE__ */
|
|
824
|
-
className:
|
|
868
|
+
}, /* @__PURE__ */ React4.createElement(IconOff, {
|
|
869
|
+
className: mx4(getSize3(6), off?.className ?? "text-red-700")
|
|
825
870
|
}));
|
|
826
871
|
} else {
|
|
827
872
|
return null;
|
|
@@ -834,6 +879,7 @@ export {
|
|
|
834
879
|
ColumnBuilder,
|
|
835
880
|
ColumnMenu,
|
|
836
881
|
ColumnPanel,
|
|
882
|
+
ComboboxCell,
|
|
837
883
|
Table,
|
|
838
884
|
columnTypes,
|
|
839
885
|
createColumnBuilder,
|