@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.
package/dist/index.js CHANGED
@@ -482,25 +482,24 @@ function RichTable(props) {
482
482
  // children,
483
483
  _b = props.pagination,
484
484
  // children,
485
- 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, hideDensity = props.hideDensity, hideColumnPicker = props.hideColumnPicker, hideExports = props.hideExports, rowKey = props.rowKey;
485
+ 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;
486
486
  var data = normalizeData(rawData);
487
- var _d = useColumnDefinitions(data, props), columnDefinitions = _d.columnDefinitions, normalized = _d.normalized;
487
+ var _f = useColumnDefinitions(data, props), columnDefinitions = _f.columnDefinitions, normalized = _f.normalized;
488
488
  var actionRef = React.useRef();
489
- var _e = useSortedFilteredData(data, normalized), finalData = _e.finalData, search = _e.search, setSearch = _e.setSearch, setSortState = _e.setSortState;
490
- var rowSelection = useRowSelection(data, props);
491
- // const { containerRef, tableHeight } = useScrollHeight(data, props);
489
+ var _g = useSortedFilteredData(data, normalized), finalData = _g.finalData, search = _g.search, setSearch = _g.setSearch, setSortState = _g.setSortState;
490
+ var rowSelectionProps = useRowSelectionProps(data, props);
492
491
  var isClient = useIsClient();
493
492
  if (!isClient) {
494
493
  return null;
495
494
  }
496
- return (React__default.default.createElement("div", { className: className },
497
- React__default.default.createElement(proComponents.ProTable, { actionRef: actionRef, columns: columnDefinitions, onChange: function (_pagination, _filters, sorter, _extra) {
495
+ return (React__default.default.createElement("div", { className: "".concat(className, " ").concat(scopeClassName !== null && scopeClassName !== void 0 ? scopeClassName : "") },
496
+ React__default.default.createElement(proComponents.ProTable, __assign({ actionRef: actionRef, columns: columnDefinitions, onChange: function (_pagination, _filters, sorter, _extra) {
498
497
  setSortState({ sorter: sorter });
499
498
  }, style: {
500
499
  width: "100%",
501
500
  }, cardProps: {
502
501
  ghost: true,
503
- }, rowSelection: rowSelection, dataSource: finalData, rowKey: deriveRowKey(data, rowKey), defaultSize: defaultSize, editable: { type: "multiple" }, search: false, options: {
502
+ } }, rowSelectionProps, { dataSource: finalData, rowKey: deriveRowKey(data, rowKey), defaultSize: defaultSize, editable: { type: "multiple" }, search: false, options: {
504
503
  setting: hideColumnPicker
505
504
  ? false
506
505
  : {
@@ -514,10 +513,7 @@ function RichTable(props) {
514
513
  onChange: function (page) { return console.log(page); },
515
514
  showSizeChanger: false,
516
515
  }
517
- : false, dateFormatter: "string", headerTitle: title,
518
- // TODO in the future, figure out how to make this responsive to the CSS height
519
- // scroll={{ x: scrollX || undefined, y: scrollHeight }}
520
- toolbar: {
516
+ : false, dateFormatter: "string", headerTitle: title, toolbar: {
521
517
  search: !hideSearch
522
518
  ? {
523
519
  value: search,
@@ -528,12 +524,16 @@ function RichTable(props) {
528
524
  placeholder: "Search",
529
525
  }
530
526
  : undefined,
531
- }, toolBarRender: function () { return [
532
- addHref && (React__default.default.createElement(antd.Button, { key: "button", icon: React__default.default.createElement(icons.PlusOutlined, null), type: "primary", href: addHref }, "Add")),
533
- !hideExports && React__default.default.createElement(ExportMenu, { data: data }),
534
- ]; } }),
527
+ }, toolBarRender: function () {
528
+ return [
529
+ addHref && (React__default.default.createElement(antd.Button, { key: "button", icon: React__default.default.createElement(icons.PlusOutlined, null), type: "primary", href: addHref }, "Add")),
530
+ !hideExports && React__default.default.createElement(ExportMenu, { data: data }),
531
+ ].filter(function (x) { return !!x; });
532
+ } })),
535
533
  React__default.default.createElement("style", { dangerouslySetInnerHTML: {
536
- __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 ",
534
+ __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
535
+ ? "\n .".concat(scopeClassName, " .ant-pro-table-alert {\n display: none;\n }\n ")
536
+ : "", "\n "),
537
537
  } })));
538
538
  }
539
539
  function deriveRowKey(data, rowKey) {
@@ -547,8 +547,19 @@ function deriveRowKey(data, rowKey) {
547
547
  }
548
548
  return undefined;
549
549
  }
550
+ function deriveKeyOfRow(row, rowKey) {
551
+ if (typeof rowKey === "function") {
552
+ return rowKey(row);
553
+ }
554
+ else if (typeof rowKey === "string") {
555
+ return row[rowKey];
556
+ }
557
+ else {
558
+ return undefined;
559
+ }
560
+ }
550
561
  function useColumnDefinitions(data, props) {
551
- var fields = props.fields, setControlContextData = props.setControlContextData, actions = props.actions, customActionChildren = props.customActionChildren;
562
+ var fields = props.fields, setControlContextData = props.setControlContextData, rowActions = props.rowActions;
552
563
  return React__default.default.useMemo(function () {
553
564
  var schema = tryGetSchema(data);
554
565
  if (!data || !schema) {
@@ -599,35 +610,40 @@ function useColumnDefinitions(data, props) {
599
610
  };
600
611
  return columnDefinition;
601
612
  });
602
- if (actions && actions.length > 0) {
613
+ if (rowActions && rowActions.length > 0) {
603
614
  columnDefinitions.push({
604
615
  title: "Actions",
605
616
  valueType: "option",
606
617
  key: "__plasmicActions",
607
- render: function (_text, record, _, action) { return __spreadArray(__spreadArray([], actions
608
- .filter(function (_action) { return !_action.moreMenu; })
609
- .map(function (_action, aindex) {
610
- return _action.type === "edit" ? (React__default.default.createElement("a", { key: aindex, onClick: function () {
611
- var _a;
612
- (_a = action === null || action === void 0 ? void 0 : action.startEditable) === null || _a === void 0 ? void 0 : _a.call(action, record.id);
613
- } }, "Edit")) : _action.type === "view" ? (React__default.default.createElement("a", { key: aindex, href: record.url }, "View")) : _action.type === "delete" ? (React__default.default.createElement("a", { key: aindex, onClick: function () {
614
- // TODO delete
615
- } }, "Delete")) : (customActionChildren);
616
- }), true), [
617
- React__default.default.createElement(proComponents.TableDropdown, { key: "actionGroup", onSelect: function () { return action === null || action === void 0 ? void 0 : action.reload(); }, menus: actions
618
- .filter(function (_action) { return !!_action.moreMenu; })
619
- .map(function (_action, aindex) {
620
- var _a;
621
- return ({
622
- key: "" + aindex,
623
- name: (_a = _action.label) !== null && _a !== void 0 ? _a : _action.type,
624
- });
625
- }) }),
626
- ], false); },
618
+ fixed: "right",
619
+ className: props.themeResetClassName,
620
+ render: function (_text, row) { return __spreadArray([], rowActions.map(function (_action) {
621
+ var _a;
622
+ if (_action.type === "item") {
623
+ return (React__default.default.createElement("a", { key: _action.label, style: {
624
+ whiteSpace: "nowrap",
625
+ }, onClick: function () {
626
+ var _a;
627
+ return (_a = _action.onClick) === null || _a === void 0 ? void 0 : _a.call(_action, deriveKeyOfRow(row, deriveRowKey(data, props.rowKey)), row);
628
+ } }, _action.label));
629
+ }
630
+ else {
631
+ return (React__default.default.createElement(proComponents.TableDropdown, { key: _action.label, style: {
632
+ whiteSpace: "nowrap",
633
+ }, menus: ((_a = _action.children) !== null && _a !== void 0 ? _a : []).map(function (child) { return ({
634
+ key: child.label,
635
+ name: child.label,
636
+ onClick: function () {
637
+ var _a;
638
+ return (_a = child.onClick) === null || _a === void 0 ? void 0 : _a.call(child, deriveKeyOfRow(row, deriveRowKey(data, props.rowKey)), row);
639
+ },
640
+ }); }) }, _action.label));
641
+ }
642
+ }), true); },
627
643
  });
628
644
  }
629
645
  return { normalized: normalized, columnDefinitions: columnDefinitions };
630
- }, [fields, data, setControlContextData, actions, customActionChildren]);
646
+ }, [fields, data, setControlContextData, rowActions]);
631
647
  }
632
648
  function useSortedFilteredData(data, columns) {
633
649
  var _a = React.useState(""), search = _a[0], setSearch = _a[1];
@@ -664,8 +680,8 @@ function useSortedFilteredData(data, columns) {
664
680
  setSortState: setSortState,
665
681
  };
666
682
  }
667
- function useRowSelection(data, props) {
668
- var canSelectRows = props.canSelectRows, selectedRowKey = props.selectedRowKey, onRowSelectionChanged = props.onRowSelectionChanged, rowKey = props.rowKey;
683
+ function useRowSelectionProps(data, props) {
684
+ var canSelectRows = props.canSelectRows, selectedRowKey = props.selectedRowKey, onRowSelectionChanged = props.onRowSelectionChanged, rowKey = props.rowKey, onRowClick = props.onRowClick;
669
685
  var deriveSelectedRowKeys = function () {
670
686
  if (!canSelectRows ||
671
687
  canSelectRows === "none" ||
@@ -676,7 +692,7 @@ function useRowSelection(data, props) {
676
692
  return [selectedRowKey];
677
693
  }
678
694
  else if (Array.isArray(selectedRowKey)) {
679
- if (canSelectRows === "single") {
695
+ if (canSelectRows === "single" || canSelectRows === "click") {
680
696
  return selectedRowKey.slice(0, 1);
681
697
  }
682
698
  else {
@@ -688,16 +704,46 @@ function useRowSelection(data, props) {
688
704
  }
689
705
  };
690
706
  var rowSelection = canSelectRows && canSelectRows !== "none"
691
- ? {
692
- type: canSelectRows === "single" ? "radio" : "checkbox",
693
- selectedRowKeys: deriveSelectedRowKeys(),
694
- onChange: function (rowKeys, rows) {
707
+ ? __assign({ type: canSelectRows === "single" || canSelectRows === "click"
708
+ ? "radio"
709
+ : "checkbox", selectedRowKeys: deriveSelectedRowKeys(), onChange: function (rowKeys, rows) {
695
710
  onRowSelectionChanged === null || onRowSelectionChanged === void 0 ? void 0 : onRowSelectionChanged(rowKeys, rows);
711
+ }, alwaysShowAlert: true }, (canSelectRows === "click" && {
712
+ renderCell: function () { return null; },
713
+ columnWidth: 0,
714
+ columnTitle: null,
715
+ hideSelectAll: true,
716
+ })) : undefined;
717
+ return {
718
+ rowSelection: rowSelection,
719
+ onRow: function (row) { return ({
720
+ onClick: function (event) {
721
+ var key = deriveKeyOfRow(row, deriveRowKey(data, rowKey));
722
+ if (key) {
723
+ if (canSelectRows === "click") {
724
+ // Some heuristics to avoid selecting a row when
725
+ // the object clicked is interactable -- like button, anchor,
726
+ // input, etc. This won't be bulletproof, so just some
727
+ // heuristics!
728
+ var target = event.target;
729
+ if (!isInteractable(target)) {
730
+ onRowSelectionChanged === null || onRowSelectionChanged === void 0 ? void 0 : onRowSelectionChanged([key], [row]);
731
+ }
732
+ }
733
+ onRowClick === null || onRowClick === void 0 ? void 0 : onRowClick(key, row, event);
734
+ }
696
735
  },
697
- alwaysShowAlert: true,
698
- }
699
- : undefined;
700
- return rowSelection;
736
+ }); },
737
+ };
738
+ }
739
+ function isInteractable(target) {
740
+ if (["A", "BUTTON", "INPUT", "TEXTAREA", "SELECT"].includes(target.tagName)) {
741
+ return true;
742
+ }
743
+ if (target.contentEditable === "true") {
744
+ return true;
745
+ }
746
+ return false;
701
747
  }
702
748
  function ExportMenu(props) {
703
749
  var _this = this;
@@ -904,10 +950,12 @@ var dataTableMeta = {
904
950
  displayName: "Select rows?",
905
951
  options: [
906
952
  { label: "No", value: "none" },
907
- { label: "Single", value: "single" },
908
- { label: "Multiple", value: "multiple" },
953
+ { label: "By clicking a row", value: "click" },
954
+ { label: "Using radio buttons", value: "single" },
955
+ { label: "Using checkboxes", value: "multiple" },
909
956
  ],
910
957
  defaultValueHint: "none",
958
+ 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.",
911
959
  },
912
960
  rowKey: {
913
961
  type: "string",
@@ -936,6 +984,65 @@ var dataTableMeta = {
936
984
  { name: "rows", type: "object" },
937
985
  ],
938
986
  },
987
+ onRowClick: {
988
+ type: "eventHandler",
989
+ displayName: "On row clicked",
990
+ argTypes: [
991
+ { name: "rowKey", type: "string" },
992
+ { name: "row", type: "object" },
993
+ { name: "event", type: "object" },
994
+ ],
995
+ },
996
+ rowActions: {
997
+ type: "array",
998
+ displayName: "Row actions",
999
+ advanced: true,
1000
+ itemType: {
1001
+ type: "object",
1002
+ nameFunc: function (ps) { return ps.label; },
1003
+ fields: {
1004
+ type: {
1005
+ type: "choice",
1006
+ options: ["item", "menu"],
1007
+ defaultValue: "item",
1008
+ },
1009
+ label: {
1010
+ type: "string",
1011
+ displayName: "Action label",
1012
+ },
1013
+ children: {
1014
+ type: "array",
1015
+ displayName: "Menu items",
1016
+ itemType: {
1017
+ type: "object",
1018
+ fields: {
1019
+ label: {
1020
+ type: "string",
1021
+ displayName: "Action label",
1022
+ },
1023
+ onClick: {
1024
+ type: "eventHandler",
1025
+ argTypes: [
1026
+ { name: "rowKey", type: "string" },
1027
+ { name: "row", type: "object" },
1028
+ ],
1029
+ },
1030
+ },
1031
+ },
1032
+ hidden: function (ps) { return ps.type !== "menu"; },
1033
+ },
1034
+ onClick: {
1035
+ type: "eventHandler",
1036
+ displayName: "Action",
1037
+ argTypes: [
1038
+ { name: "rowKey", type: "string" },
1039
+ { name: "row", type: "object" },
1040
+ ],
1041
+ hidden: function (ps) { return ps.type !== "item"; },
1042
+ },
1043
+ },
1044
+ },
1045
+ },
939
1046
  pagination: {
940
1047
  type: "boolean",
941
1048
  advanced: true,
@@ -943,20 +1050,40 @@ var dataTableMeta = {
943
1050
  },
944
1051
  hideSearch: {
945
1052
  type: "boolean",
1053
+ description: "Hides the search toolbar",
946
1054
  advanced: true,
947
1055
  },
948
1056
  hideExports: {
949
1057
  type: "boolean",
1058
+ description: "Hides the button for exporting table data to CSV",
950
1059
  advanced: true,
951
1060
  },
952
1061
  hideDensity: {
953
1062
  type: "boolean",
1063
+ description: "Hides the control for changing the density of the table",
954
1064
  advanced: true,
1065
+ defaultValueHint: true,
955
1066
  },
956
1067
  hideColumnPicker: {
957
1068
  type: "boolean",
1069
+ description: "Hides the control for reordering and pinning columns",
958
1070
  advanced: true,
959
1071
  },
1072
+ hideSelectionBar: {
1073
+ type: "boolean",
1074
+ description: "Hides the toolbar that allows the user to clear selection",
1075
+ advanced: true,
1076
+ hidden: function (ps) { return !ps.canSelectRows || ps.canSelectRows === "none"; },
1077
+ defaultValueHint: true,
1078
+ },
1079
+ scopeClassName: {
1080
+ type: "styleScopeClass",
1081
+ scopeName: "instance",
1082
+ },
1083
+ themeResetClassName: {
1084
+ type: "themeResetClass",
1085
+ targetAllTags: true,
1086
+ },
960
1087
  },
961
1088
  states: {
962
1089
  selectedRowKey: __assign({ type: "writable", valueProp: "selectedRowKey", onChangeProp: "onRowSelectionChanged", variableType: "text" }, tableHelpers.states.selectedRowKey),