@plasmicpkgs/plasmic-rich-components 1.0.68 → 1.0.70
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.
|
@@ -474,25 +474,24 @@ function RichTable(props) {
|
|
|
474
474
|
// children,
|
|
475
475
|
_b = props.pagination,
|
|
476
476
|
// children,
|
|
477
|
-
pagination = _b === void 0 ? true : _b, defaultSize = props.defaultSize, title = props.title, addHref = props.addHref, _c = props.pageSize, pageSize = _c === void 0 ? 10 : _c, hideSearch = props.hideSearch,
|
|
477
|
+
pagination = _b === void 0 ? true : _b, defaultSize = props.defaultSize, title = props.title, addHref = props.addHref, _c = props.pageSize, pageSize = _c === void 0 ? 10 : _c, hideSearch = props.hideSearch, _d = props.hideDensity, hideDensity = _d === void 0 ? true : _d, hideColumnPicker = props.hideColumnPicker, hideExports = props.hideExports, _e = props.hideSelectionBar, hideSelectionBar = _e === void 0 ? true : _e, rowKey = props.rowKey, scopeClassName = props.scopeClassName; props.themeResetClassName;
|
|
478
478
|
var data = normalizeData(rawData);
|
|
479
|
-
var
|
|
479
|
+
var _f = useColumnDefinitions(data, props), columnDefinitions = _f.columnDefinitions, normalized = _f.normalized;
|
|
480
480
|
var actionRef = useRef();
|
|
481
|
-
var
|
|
482
|
-
var
|
|
483
|
-
// const { containerRef, tableHeight } = useScrollHeight(data, props);
|
|
481
|
+
var _g = useSortedFilteredData(data, normalized), finalData = _g.finalData, search = _g.search, setSearch = _g.setSearch, setSortState = _g.setSortState;
|
|
482
|
+
var rowSelectionProps = useRowSelectionProps(data, props);
|
|
484
483
|
var isClient = useIsClient();
|
|
485
484
|
if (!isClient) {
|
|
486
485
|
return null;
|
|
487
486
|
}
|
|
488
|
-
return (React.createElement("div", { className: className },
|
|
489
|
-
React.createElement(ProTable, { actionRef: actionRef, columns: columnDefinitions, onChange: function (_pagination, _filters, sorter, _extra) {
|
|
487
|
+
return (React.createElement("div", { className: "".concat(className, " ").concat(scopeClassName !== null && scopeClassName !== void 0 ? scopeClassName : "") },
|
|
488
|
+
React.createElement(ProTable, __assign({ actionRef: actionRef, columns: columnDefinitions, onChange: function (_pagination, _filters, sorter, _extra) {
|
|
490
489
|
setSortState({ sorter: sorter });
|
|
491
490
|
}, style: {
|
|
492
491
|
width: "100%",
|
|
493
492
|
}, cardProps: {
|
|
494
493
|
ghost: true,
|
|
495
|
-
},
|
|
494
|
+
} }, rowSelectionProps, { dataSource: finalData, rowKey: deriveRowKey(data, rowKey), defaultSize: defaultSize, editable: { type: "multiple" }, search: false, options: {
|
|
496
495
|
setting: hideColumnPicker
|
|
497
496
|
? false
|
|
498
497
|
: {
|
|
@@ -506,10 +505,7 @@ function RichTable(props) {
|
|
|
506
505
|
onChange: function (page) { return console.log(page); },
|
|
507
506
|
showSizeChanger: false,
|
|
508
507
|
}
|
|
509
|
-
: false, dateFormatter: "string", headerTitle: title,
|
|
510
|
-
// TODO in the future, figure out how to make this responsive to the CSS height
|
|
511
|
-
// scroll={{ x: scrollX || undefined, y: scrollHeight }}
|
|
512
|
-
toolbar: {
|
|
508
|
+
: false, dateFormatter: "string", headerTitle: title, toolbar: {
|
|
513
509
|
search: !hideSearch
|
|
514
510
|
? {
|
|
515
511
|
value: search,
|
|
@@ -520,12 +516,16 @@ function RichTable(props) {
|
|
|
520
516
|
placeholder: "Search",
|
|
521
517
|
}
|
|
522
518
|
: undefined,
|
|
523
|
-
}, toolBarRender: function () {
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
519
|
+
}, toolBarRender: function () {
|
|
520
|
+
return [
|
|
521
|
+
addHref && (React.createElement(Button, { key: "button", icon: React.createElement(PlusOutlined, null), type: "primary", href: addHref }, "Add")),
|
|
522
|
+
!hideExports && React.createElement(ExportMenu, { data: data }),
|
|
523
|
+
].filter(function (x) { return !!x; });
|
|
524
|
+
} })),
|
|
527
525
|
React.createElement("style", { dangerouslySetInnerHTML: {
|
|
528
|
-
__html: "\n :where(.css-dev-only-do-not-override-1p704s4).ant-pro-table-column-setting-overlay .ant-tree-treenode:hover .ant-pro-table-column-setting-list-item-option {\n display: none;\n }\n .ant-pro-table-list-toolbar-right {\n flex-wrap: initial;\n flex-shrink: 0;\n }\n .ant-pro-table, .ant-pro-table > .ant-pro-card, .ant-pro-table .ant-table-wrapper, .ant-pro-table .ant-spin-nested-loading, .ant-pro-table .ant-table-container {\n height: 100%;\n }\n .ant-pro-table .ant-spin-container {\n height: 100%;\n display: flex;\n flex-direction: column;\n }\n .ant-pro-table .ant-table {\n flex-grow: 1;\n min-height: 0;\n }\n .ant-pro-table .ant-pagination {\n flex-shrink: 0;\n }\n .ant-pro-table .ant-table-content {\n overflow: auto !important;\n height: 100%;\n }\n .ant-pro-table > .ant-pro-card > .ant-pro-card-body {\n display: flex;\n flex-direction: column;\n }\n .ant-pro-table .ant-table-wrapper {\n flex-grow: 1;\n min-height: 0;\n }\n .ant-pro-table .ant-table-thead > tr > th {\n position: sticky;\n top: 0;\n z-index: 2;\n }\n .ant-pro-table .ant-table-thead > tr > th.ant-table-cell-fix-left, .ant-pro-table .ant-table-thead > tr > th.ant-table-cell-fix-right {\n z-index: 3;\n }\n .ant-pro-table .ant-table-tbody > tr > td {\n z-index: 0;\n }\n .ant-pro-table .ant-table-tbody > tr > td.ant-table-cell-fix-left,.ant-pro-table .ant-table-tbody > tr > td.ant-table-cell-fix-right {\n z-index: 1;\n }\n
|
|
526
|
+
__html: "\n :where(.css-dev-only-do-not-override-1p704s4).ant-pro-table-column-setting-overlay .ant-tree-treenode:hover .ant-pro-table-column-setting-list-item-option {\n display: none;\n }\n .ant-pro-table-list-toolbar-right {\n flex-wrap: initial;\n flex-shrink: 0;\n }\n .ant-pro-table, .ant-pro-table > .ant-pro-card, .ant-pro-table .ant-table-wrapper, .ant-pro-table .ant-spin-nested-loading, .ant-pro-table .ant-table-container {\n height: 100%;\n }\n .ant-pro-table .ant-spin-container {\n height: 100%;\n display: flex;\n flex-direction: column;\n }\n .ant-pro-table .ant-table {\n flex-grow: 1;\n min-height: 0;\n }\n .ant-pro-table .ant-pagination {\n flex-shrink: 0;\n }\n .ant-pro-table .ant-table-content {\n overflow: auto !important;\n height: 100%;\n }\n .ant-pro-table > .ant-pro-card > .ant-pro-card-body {\n display: flex;\n flex-direction: column;\n }\n .ant-pro-table .ant-table-wrapper {\n flex-grow: 1;\n min-height: 0;\n }\n .ant-pro-table .ant-table-thead > tr > th, .ant-pro-table .ant-table-thead > tr > td.ant-table-selection-column {\n position: sticky;\n top: 0;\n z-index: 2;\n }\n .ant-pro-table .ant-table-thead > tr > th.ant-table-cell-fix-left, .ant-pro-table .ant-table-thead > tr > th.ant-table-cell-fix-right {\n z-index: 3;\n }\n .ant-pro-table .ant-table-tbody > tr > td {\n z-index: 0;\n }\n .ant-pro-table .ant-table-tbody > tr > td.ant-table-cell-fix-left,.ant-pro-table .ant-table-tbody > tr > td.ant-table-cell-fix-right {\n z-index: 1;\n }\n ".concat(scopeClassName && hideSelectionBar
|
|
527
|
+
? "\n .".concat(scopeClassName, " .ant-pro-table-alert {\n display: none;\n }\n ")
|
|
528
|
+
: "", "\n "),
|
|
529
529
|
} })));
|
|
530
530
|
}
|
|
531
531
|
function deriveRowKey(data, rowKey) {
|
|
@@ -539,8 +539,19 @@ function deriveRowKey(data, rowKey) {
|
|
|
539
539
|
}
|
|
540
540
|
return undefined;
|
|
541
541
|
}
|
|
542
|
+
function deriveKeyOfRow(row, rowKey) {
|
|
543
|
+
if (typeof rowKey === "function") {
|
|
544
|
+
return rowKey(row);
|
|
545
|
+
}
|
|
546
|
+
else if (typeof rowKey === "string") {
|
|
547
|
+
return row[rowKey];
|
|
548
|
+
}
|
|
549
|
+
else {
|
|
550
|
+
return undefined;
|
|
551
|
+
}
|
|
552
|
+
}
|
|
542
553
|
function useColumnDefinitions(data, props) {
|
|
543
|
-
var fields = props.fields, setControlContextData = props.setControlContextData,
|
|
554
|
+
var fields = props.fields, setControlContextData = props.setControlContextData, rowActions = props.rowActions;
|
|
544
555
|
return React.useMemo(function () {
|
|
545
556
|
var schema = tryGetSchema(data);
|
|
546
557
|
if (!data || !schema) {
|
|
@@ -591,35 +602,40 @@ function useColumnDefinitions(data, props) {
|
|
|
591
602
|
};
|
|
592
603
|
return columnDefinition;
|
|
593
604
|
});
|
|
594
|
-
if (
|
|
605
|
+
if (rowActions && rowActions.length > 0) {
|
|
595
606
|
columnDefinitions.push({
|
|
596
607
|
title: "Actions",
|
|
597
608
|
valueType: "option",
|
|
598
609
|
key: "__plasmicActions",
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
610
|
+
fixed: "right",
|
|
611
|
+
className: props.themeResetClassName,
|
|
612
|
+
render: function (_text, row) { return __spreadArray([], rowActions.map(function (_action) {
|
|
613
|
+
var _a;
|
|
614
|
+
if (_action.type === "item") {
|
|
615
|
+
return (React.createElement("a", { key: _action.label, style: {
|
|
616
|
+
whiteSpace: "nowrap",
|
|
617
|
+
}, onClick: function () {
|
|
618
|
+
var _a;
|
|
619
|
+
return (_a = _action.onClick) === null || _a === void 0 ? void 0 : _a.call(_action, deriveKeyOfRow(row, deriveRowKey(data, props.rowKey)), row);
|
|
620
|
+
} }, _action.label));
|
|
621
|
+
}
|
|
622
|
+
else {
|
|
623
|
+
return (React.createElement(TableDropdown, { key: _action.label, style: {
|
|
624
|
+
whiteSpace: "nowrap",
|
|
625
|
+
}, menus: ((_a = _action.children) !== null && _a !== void 0 ? _a : []).map(function (child) { return ({
|
|
626
|
+
key: child.label,
|
|
627
|
+
name: child.label,
|
|
628
|
+
onClick: function () {
|
|
629
|
+
var _a;
|
|
630
|
+
return (_a = child.onClick) === null || _a === void 0 ? void 0 : _a.call(child, deriveKeyOfRow(row, deriveRowKey(data, props.rowKey)), row);
|
|
631
|
+
},
|
|
632
|
+
}); }) }, _action.label));
|
|
633
|
+
}
|
|
634
|
+
}), true); },
|
|
619
635
|
});
|
|
620
636
|
}
|
|
621
637
|
return { normalized: normalized, columnDefinitions: columnDefinitions };
|
|
622
|
-
}, [fields, data, setControlContextData,
|
|
638
|
+
}, [fields, data, setControlContextData, rowActions]);
|
|
623
639
|
}
|
|
624
640
|
function useSortedFilteredData(data, columns) {
|
|
625
641
|
var _a = useState(""), search = _a[0], setSearch = _a[1];
|
|
@@ -656,8 +672,8 @@ function useSortedFilteredData(data, columns) {
|
|
|
656
672
|
setSortState: setSortState,
|
|
657
673
|
};
|
|
658
674
|
}
|
|
659
|
-
function
|
|
660
|
-
var canSelectRows = props.canSelectRows, selectedRowKey = props.selectedRowKey, onRowSelectionChanged = props.onRowSelectionChanged, rowKey = props.rowKey;
|
|
675
|
+
function useRowSelectionProps(data, props) {
|
|
676
|
+
var canSelectRows = props.canSelectRows, selectedRowKey = props.selectedRowKey, onRowSelectionChanged = props.onRowSelectionChanged, rowKey = props.rowKey, onRowClick = props.onRowClick;
|
|
661
677
|
var deriveSelectedRowKeys = function () {
|
|
662
678
|
if (!canSelectRows ||
|
|
663
679
|
canSelectRows === "none" ||
|
|
@@ -668,7 +684,7 @@ function useRowSelection(data, props) {
|
|
|
668
684
|
return [selectedRowKey];
|
|
669
685
|
}
|
|
670
686
|
else if (Array.isArray(selectedRowKey)) {
|
|
671
|
-
if (canSelectRows === "single") {
|
|
687
|
+
if (canSelectRows === "single" || canSelectRows === "click") {
|
|
672
688
|
return selectedRowKey.slice(0, 1);
|
|
673
689
|
}
|
|
674
690
|
else {
|
|
@@ -680,16 +696,46 @@ function useRowSelection(data, props) {
|
|
|
680
696
|
}
|
|
681
697
|
};
|
|
682
698
|
var rowSelection = canSelectRows && canSelectRows !== "none"
|
|
683
|
-
? {
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
onChange: function (rowKeys, rows) {
|
|
699
|
+
? __assign({ type: canSelectRows === "single" || canSelectRows === "click"
|
|
700
|
+
? "radio"
|
|
701
|
+
: "checkbox", selectedRowKeys: deriveSelectedRowKeys(), onChange: function (rowKeys, rows) {
|
|
687
702
|
onRowSelectionChanged === null || onRowSelectionChanged === void 0 ? void 0 : onRowSelectionChanged(rowKeys, rows);
|
|
703
|
+
}, alwaysShowAlert: true }, (canSelectRows === "click" && {
|
|
704
|
+
renderCell: function () { return null; },
|
|
705
|
+
columnWidth: 0,
|
|
706
|
+
columnTitle: null,
|
|
707
|
+
hideSelectAll: true,
|
|
708
|
+
})) : undefined;
|
|
709
|
+
return {
|
|
710
|
+
rowSelection: rowSelection,
|
|
711
|
+
onRow: function (row) { return ({
|
|
712
|
+
onClick: function (event) {
|
|
713
|
+
var key = deriveKeyOfRow(row, deriveRowKey(data, rowKey));
|
|
714
|
+
if (key) {
|
|
715
|
+
if (canSelectRows === "click") {
|
|
716
|
+
// Some heuristics to avoid selecting a row when
|
|
717
|
+
// the object clicked is interactable -- like button, anchor,
|
|
718
|
+
// input, etc. This won't be bulletproof, so just some
|
|
719
|
+
// heuristics!
|
|
720
|
+
var target = event.target;
|
|
721
|
+
if (!isInteractable(target)) {
|
|
722
|
+
onRowSelectionChanged === null || onRowSelectionChanged === void 0 ? void 0 : onRowSelectionChanged([key], [row]);
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
onRowClick === null || onRowClick === void 0 ? void 0 : onRowClick(key, row, event);
|
|
726
|
+
}
|
|
688
727
|
},
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
728
|
+
}); },
|
|
729
|
+
};
|
|
730
|
+
}
|
|
731
|
+
function isInteractable(target) {
|
|
732
|
+
if (["A", "BUTTON", "INPUT", "TEXTAREA", "SELECT"].includes(target.tagName)) {
|
|
733
|
+
return true;
|
|
734
|
+
}
|
|
735
|
+
if (target.contentEditable === "true") {
|
|
736
|
+
return true;
|
|
737
|
+
}
|
|
738
|
+
return false;
|
|
693
739
|
}
|
|
694
740
|
function ExportMenu(props) {
|
|
695
741
|
var _this = this;
|
|
@@ -896,10 +942,12 @@ var dataTableMeta = {
|
|
|
896
942
|
displayName: "Select rows?",
|
|
897
943
|
options: [
|
|
898
944
|
{ label: "No", value: "none" },
|
|
899
|
-
{ label: "
|
|
900
|
-
{ label: "
|
|
945
|
+
{ label: "By clicking a row", value: "click" },
|
|
946
|
+
{ label: "Using radio buttons", value: "single" },
|
|
947
|
+
{ label: "Using checkboxes", value: "multiple" },
|
|
901
948
|
],
|
|
902
949
|
defaultValueHint: "none",
|
|
950
|
+
description: "Lets user select table rows by clicking on a row, or using radio buttons, or checkboxes if multiple rows can be selected together. If you have interactive elements in your row and you don't want clicking on them to select the row, you may use radio buttons instead.",
|
|
903
951
|
},
|
|
904
952
|
rowKey: {
|
|
905
953
|
type: "string",
|
|
@@ -928,6 +976,65 @@ var dataTableMeta = {
|
|
|
928
976
|
{ name: "rows", type: "object" },
|
|
929
977
|
],
|
|
930
978
|
},
|
|
979
|
+
onRowClick: {
|
|
980
|
+
type: "eventHandler",
|
|
981
|
+
displayName: "On row clicked",
|
|
982
|
+
argTypes: [
|
|
983
|
+
{ name: "rowKey", type: "string" },
|
|
984
|
+
{ name: "row", type: "object" },
|
|
985
|
+
{ name: "event", type: "object" },
|
|
986
|
+
],
|
|
987
|
+
},
|
|
988
|
+
rowActions: {
|
|
989
|
+
type: "array",
|
|
990
|
+
displayName: "Row actions",
|
|
991
|
+
advanced: true,
|
|
992
|
+
itemType: {
|
|
993
|
+
type: "object",
|
|
994
|
+
nameFunc: function (ps) { return ps.label; },
|
|
995
|
+
fields: {
|
|
996
|
+
type: {
|
|
997
|
+
type: "choice",
|
|
998
|
+
options: ["item", "menu"],
|
|
999
|
+
defaultValue: "item",
|
|
1000
|
+
},
|
|
1001
|
+
label: {
|
|
1002
|
+
type: "string",
|
|
1003
|
+
displayName: "Action label",
|
|
1004
|
+
},
|
|
1005
|
+
children: {
|
|
1006
|
+
type: "array",
|
|
1007
|
+
displayName: "Menu items",
|
|
1008
|
+
itemType: {
|
|
1009
|
+
type: "object",
|
|
1010
|
+
fields: {
|
|
1011
|
+
label: {
|
|
1012
|
+
type: "string",
|
|
1013
|
+
displayName: "Action label",
|
|
1014
|
+
},
|
|
1015
|
+
onClick: {
|
|
1016
|
+
type: "eventHandler",
|
|
1017
|
+
argTypes: [
|
|
1018
|
+
{ name: "rowKey", type: "string" },
|
|
1019
|
+
{ name: "row", type: "object" },
|
|
1020
|
+
],
|
|
1021
|
+
},
|
|
1022
|
+
},
|
|
1023
|
+
},
|
|
1024
|
+
hidden: function (ps) { return ps.type !== "menu"; },
|
|
1025
|
+
},
|
|
1026
|
+
onClick: {
|
|
1027
|
+
type: "eventHandler",
|
|
1028
|
+
displayName: "Action",
|
|
1029
|
+
argTypes: [
|
|
1030
|
+
{ name: "rowKey", type: "string" },
|
|
1031
|
+
{ name: "row", type: "object" },
|
|
1032
|
+
],
|
|
1033
|
+
hidden: function (ps) { return ps.type !== "item"; },
|
|
1034
|
+
},
|
|
1035
|
+
},
|
|
1036
|
+
},
|
|
1037
|
+
},
|
|
931
1038
|
pagination: {
|
|
932
1039
|
type: "boolean",
|
|
933
1040
|
advanced: true,
|
|
@@ -935,20 +1042,40 @@ var dataTableMeta = {
|
|
|
935
1042
|
},
|
|
936
1043
|
hideSearch: {
|
|
937
1044
|
type: "boolean",
|
|
1045
|
+
description: "Hides the search toolbar",
|
|
938
1046
|
advanced: true,
|
|
939
1047
|
},
|
|
940
1048
|
hideExports: {
|
|
941
1049
|
type: "boolean",
|
|
1050
|
+
description: "Hides the button for exporting table data to CSV",
|
|
942
1051
|
advanced: true,
|
|
943
1052
|
},
|
|
944
1053
|
hideDensity: {
|
|
945
1054
|
type: "boolean",
|
|
1055
|
+
description: "Hides the control for changing the density of the table",
|
|
946
1056
|
advanced: true,
|
|
1057
|
+
defaultValueHint: true,
|
|
947
1058
|
},
|
|
948
1059
|
hideColumnPicker: {
|
|
949
1060
|
type: "boolean",
|
|
1061
|
+
description: "Hides the control for reordering and pinning columns",
|
|
950
1062
|
advanced: true,
|
|
951
1063
|
},
|
|
1064
|
+
hideSelectionBar: {
|
|
1065
|
+
type: "boolean",
|
|
1066
|
+
description: "Hides the toolbar that allows the user to clear selection",
|
|
1067
|
+
advanced: true,
|
|
1068
|
+
hidden: function (ps) { return !ps.canSelectRows || ps.canSelectRows === "none"; },
|
|
1069
|
+
defaultValueHint: true,
|
|
1070
|
+
},
|
|
1071
|
+
scopeClassName: {
|
|
1072
|
+
type: "styleScopeClass",
|
|
1073
|
+
scopeName: "instance",
|
|
1074
|
+
},
|
|
1075
|
+
themeResetClassName: {
|
|
1076
|
+
type: "themeResetClass",
|
|
1077
|
+
targetAllTags: true,
|
|
1078
|
+
},
|
|
952
1079
|
},
|
|
953
1080
|
states: {
|
|
954
1081
|
selectedRowKey: __assign({ type: "writable", valueProp: "selectedRowKey", onChangeProp: "onRowSelectionChanged", variableType: "text" }, tableHelpers.states.selectedRowKey),
|