@plasmicpkgs/plasmic-rich-components 1.0.67 → 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
@@ -206,7 +206,10 @@ var richLayoutMeta = {
206
206
  name: "hostless-rich-layout",
207
207
  displayName: "Rich Page Layout",
208
208
  props: {
209
- children: "slot",
209
+ children: {
210
+ type: "slot",
211
+ unstable__isMainContentSlot: true,
212
+ },
210
213
  actionsChildren: {
211
214
  type: "slot",
212
215
  hidePlaceholder: true,
@@ -479,25 +482,24 @@ function RichTable(props) {
479
482
  // children,
480
483
  _b = props.pagination,
481
484
  // children,
482
- 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;
483
486
  var data = normalizeData(rawData);
484
- var _d = useColumnDefinitions(data, props), columnDefinitions = _d.columnDefinitions, normalized = _d.normalized;
487
+ var _f = useColumnDefinitions(data, props), columnDefinitions = _f.columnDefinitions, normalized = _f.normalized;
485
488
  var actionRef = React.useRef();
486
- var _e = useSortedFilteredData(data, normalized), finalData = _e.finalData, search = _e.search, setSearch = _e.setSearch, setSortState = _e.setSortState;
487
- var rowSelection = useRowSelection(data, props);
488
- // 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);
489
491
  var isClient = useIsClient();
490
492
  if (!isClient) {
491
493
  return null;
492
494
  }
493
- return (React__default.default.createElement("div", { className: className },
494
- 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) {
495
497
  setSortState({ sorter: sorter });
496
498
  }, style: {
497
499
  width: "100%",
498
500
  }, cardProps: {
499
501
  ghost: true,
500
- }, 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: {
501
503
  setting: hideColumnPicker
502
504
  ? false
503
505
  : {
@@ -511,10 +513,7 @@ function RichTable(props) {
511
513
  onChange: function (page) { return console.log(page); },
512
514
  showSizeChanger: false,
513
515
  }
514
- : false, dateFormatter: "string", headerTitle: title,
515
- // TODO in the future, figure out how to make this responsive to the CSS height
516
- // scroll={{ x: scrollX || undefined, y: scrollHeight }}
517
- toolbar: {
516
+ : false, dateFormatter: "string", headerTitle: title, toolbar: {
518
517
  search: !hideSearch
519
518
  ? {
520
519
  value: search,
@@ -525,12 +524,16 @@ function RichTable(props) {
525
524
  placeholder: "Search",
526
525
  }
527
526
  : undefined,
528
- }, toolBarRender: function () { 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
- ]; } }),
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
+ } })),
532
533
  React__default.default.createElement("style", { dangerouslySetInnerHTML: {
533
- __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 "),
534
537
  } })));
535
538
  }
536
539
  function deriveRowKey(data, rowKey) {
@@ -544,8 +547,19 @@ function deriveRowKey(data, rowKey) {
544
547
  }
545
548
  return undefined;
546
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
+ }
547
561
  function useColumnDefinitions(data, props) {
548
- var fields = props.fields, setControlContextData = props.setControlContextData, actions = props.actions, customActionChildren = props.customActionChildren;
562
+ var fields = props.fields, setControlContextData = props.setControlContextData, rowActions = props.rowActions;
549
563
  return React__default.default.useMemo(function () {
550
564
  var schema = tryGetSchema(data);
551
565
  if (!data || !schema) {
@@ -596,35 +610,40 @@ function useColumnDefinitions(data, props) {
596
610
  };
597
611
  return columnDefinition;
598
612
  });
599
- if (actions && actions.length > 0) {
613
+ if (rowActions && rowActions.length > 0) {
600
614
  columnDefinitions.push({
601
615
  title: "Actions",
602
616
  valueType: "option",
603
617
  key: "__plasmicActions",
604
- render: function (_text, record, _, action) { return __spreadArray(__spreadArray([], actions
605
- .filter(function (_action) { return !_action.moreMenu; })
606
- .map(function (_action, aindex) {
607
- return _action.type === "edit" ? (React__default.default.createElement("a", { key: aindex, onClick: function () {
608
- var _a;
609
- (_a = action === null || action === void 0 ? void 0 : action.startEditable) === null || _a === void 0 ? void 0 : _a.call(action, record.id);
610
- } }, "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 () {
611
- // TODO delete
612
- } }, "Delete")) : (customActionChildren);
613
- }), true), [
614
- React__default.default.createElement(proComponents.TableDropdown, { key: "actionGroup", onSelect: function () { return action === null || action === void 0 ? void 0 : action.reload(); }, menus: actions
615
- .filter(function (_action) { return !!_action.moreMenu; })
616
- .map(function (_action, aindex) {
617
- var _a;
618
- return ({
619
- key: "" + aindex,
620
- name: (_a = _action.label) !== null && _a !== void 0 ? _a : _action.type,
621
- });
622
- }) }),
623
- ], 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); },
624
643
  });
625
644
  }
626
645
  return { normalized: normalized, columnDefinitions: columnDefinitions };
627
- }, [fields, data, setControlContextData, actions, customActionChildren]);
646
+ }, [fields, data, setControlContextData, rowActions]);
628
647
  }
629
648
  function useSortedFilteredData(data, columns) {
630
649
  var _a = React.useState(""), search = _a[0], setSearch = _a[1];
@@ -661,8 +680,8 @@ function useSortedFilteredData(data, columns) {
661
680
  setSortState: setSortState,
662
681
  };
663
682
  }
664
- function useRowSelection(data, props) {
665
- 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;
666
685
  var deriveSelectedRowKeys = function () {
667
686
  if (!canSelectRows ||
668
687
  canSelectRows === "none" ||
@@ -673,7 +692,7 @@ function useRowSelection(data, props) {
673
692
  return [selectedRowKey];
674
693
  }
675
694
  else if (Array.isArray(selectedRowKey)) {
676
- if (canSelectRows === "single") {
695
+ if (canSelectRows === "single" || canSelectRows === "click") {
677
696
  return selectedRowKey.slice(0, 1);
678
697
  }
679
698
  else {
@@ -685,16 +704,46 @@ function useRowSelection(data, props) {
685
704
  }
686
705
  };
687
706
  var rowSelection = canSelectRows && canSelectRows !== "none"
688
- ? {
689
- type: canSelectRows === "single" ? "radio" : "checkbox",
690
- selectedRowKeys: deriveSelectedRowKeys(),
691
- onChange: function (rowKeys, rows) {
707
+ ? __assign({ type: canSelectRows === "single" || canSelectRows === "click"
708
+ ? "radio"
709
+ : "checkbox", selectedRowKeys: deriveSelectedRowKeys(), onChange: function (rowKeys, rows) {
692
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
+ }
693
735
  },
694
- alwaysShowAlert: true,
695
- }
696
- : undefined;
697
- 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;
698
747
  }
699
748
  function ExportMenu(props) {
700
749
  var _this = this;
@@ -901,10 +950,12 @@ var dataTableMeta = {
901
950
  displayName: "Select rows?",
902
951
  options: [
903
952
  { label: "No", value: "none" },
904
- { label: "Single", value: "single" },
905
- { 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" },
906
956
  ],
907
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.",
908
959
  },
909
960
  rowKey: {
910
961
  type: "string",
@@ -933,6 +984,65 @@ var dataTableMeta = {
933
984
  { name: "rows", type: "object" },
934
985
  ],
935
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
+ },
936
1046
  pagination: {
937
1047
  type: "boolean",
938
1048
  advanced: true,
@@ -940,19 +1050,39 @@ var dataTableMeta = {
940
1050
  },
941
1051
  hideSearch: {
942
1052
  type: "boolean",
1053
+ description: "Hides the search toolbar",
943
1054
  advanced: true,
944
1055
  },
945
1056
  hideExports: {
946
1057
  type: "boolean",
1058
+ description: "Hides the button for exporting table data to CSV",
947
1059
  advanced: true,
948
1060
  },
949
1061
  hideDensity: {
950
1062
  type: "boolean",
1063
+ description: "Hides the control for changing the density of the table",
951
1064
  advanced: true,
1065
+ defaultValueHint: true,
952
1066
  },
953
1067
  hideColumnPicker: {
954
1068
  type: "boolean",
1069
+ description: "Hides the control for reordering and pinning columns",
1070
+ advanced: true,
1071
+ },
1072
+ hideSelectionBar: {
1073
+ type: "boolean",
1074
+ description: "Hides the toolbar that allows the user to clear selection",
955
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,
956
1086
  },
957
1087
  },
958
1088
  states: {