@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.
@@ -198,7 +198,10 @@ var richLayoutMeta = {
198
198
  name: "hostless-rich-layout",
199
199
  displayName: "Rich Page Layout",
200
200
  props: {
201
- children: "slot",
201
+ children: {
202
+ type: "slot",
203
+ unstable__isMainContentSlot: true,
204
+ },
202
205
  actionsChildren: {
203
206
  type: "slot",
204
207
  hidePlaceholder: true,
@@ -471,25 +474,24 @@ function RichTable(props) {
471
474
  // children,
472
475
  _b = props.pagination,
473
476
  // children,
474
- 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;
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;
475
478
  var data = normalizeData(rawData);
476
- var _d = useColumnDefinitions(data, props), columnDefinitions = _d.columnDefinitions, normalized = _d.normalized;
479
+ var _f = useColumnDefinitions(data, props), columnDefinitions = _f.columnDefinitions, normalized = _f.normalized;
477
480
  var actionRef = useRef();
478
- var _e = useSortedFilteredData(data, normalized), finalData = _e.finalData, search = _e.search, setSearch = _e.setSearch, setSortState = _e.setSortState;
479
- var rowSelection = useRowSelection(data, props);
480
- // 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);
481
483
  var isClient = useIsClient();
482
484
  if (!isClient) {
483
485
  return null;
484
486
  }
485
- return (React.createElement("div", { className: className },
486
- 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) {
487
489
  setSortState({ sorter: sorter });
488
490
  }, style: {
489
491
  width: "100%",
490
492
  }, cardProps: {
491
493
  ghost: true,
492
- }, rowSelection: rowSelection, dataSource: finalData, rowKey: deriveRowKey(data, rowKey), defaultSize: defaultSize, editable: { type: "multiple" }, search: false, options: {
494
+ } }, rowSelectionProps, { dataSource: finalData, rowKey: deriveRowKey(data, rowKey), defaultSize: defaultSize, editable: { type: "multiple" }, search: false, options: {
493
495
  setting: hideColumnPicker
494
496
  ? false
495
497
  : {
@@ -503,10 +505,7 @@ function RichTable(props) {
503
505
  onChange: function (page) { return console.log(page); },
504
506
  showSizeChanger: false,
505
507
  }
506
- : false, dateFormatter: "string", headerTitle: title,
507
- // TODO in the future, figure out how to make this responsive to the CSS height
508
- // scroll={{ x: scrollX || undefined, y: scrollHeight }}
509
- toolbar: {
508
+ : false, dateFormatter: "string", headerTitle: title, toolbar: {
510
509
  search: !hideSearch
511
510
  ? {
512
511
  value: search,
@@ -517,12 +516,16 @@ function RichTable(props) {
517
516
  placeholder: "Search",
518
517
  }
519
518
  : undefined,
520
- }, toolBarRender: function () { 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
- ]; } }),
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
+ } })),
524
525
  React.createElement("style", { dangerouslySetInnerHTML: {
525
- __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 "),
526
529
  } })));
527
530
  }
528
531
  function deriveRowKey(data, rowKey) {
@@ -536,8 +539,19 @@ function deriveRowKey(data, rowKey) {
536
539
  }
537
540
  return undefined;
538
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
+ }
539
553
  function useColumnDefinitions(data, props) {
540
- var fields = props.fields, setControlContextData = props.setControlContextData, actions = props.actions, customActionChildren = props.customActionChildren;
554
+ var fields = props.fields, setControlContextData = props.setControlContextData, rowActions = props.rowActions;
541
555
  return React.useMemo(function () {
542
556
  var schema = tryGetSchema(data);
543
557
  if (!data || !schema) {
@@ -588,35 +602,40 @@ function useColumnDefinitions(data, props) {
588
602
  };
589
603
  return columnDefinition;
590
604
  });
591
- if (actions && actions.length > 0) {
605
+ if (rowActions && rowActions.length > 0) {
592
606
  columnDefinitions.push({
593
607
  title: "Actions",
594
608
  valueType: "option",
595
609
  key: "__plasmicActions",
596
- render: function (_text, record, _, action) { return __spreadArray(__spreadArray([], actions
597
- .filter(function (_action) { return !_action.moreMenu; })
598
- .map(function (_action, aindex) {
599
- return _action.type === "edit" ? (React.createElement("a", { key: aindex, onClick: function () {
600
- var _a;
601
- (_a = action === null || action === void 0 ? void 0 : action.startEditable) === null || _a === void 0 ? void 0 : _a.call(action, record.id);
602
- } }, "Edit")) : _action.type === "view" ? (React.createElement("a", { key: aindex, href: record.url }, "View")) : _action.type === "delete" ? (React.createElement("a", { key: aindex, onClick: function () {
603
- // TODO delete
604
- } }, "Delete")) : (customActionChildren);
605
- }), true), [
606
- React.createElement(TableDropdown, { key: "actionGroup", onSelect: function () { return action === null || action === void 0 ? void 0 : action.reload(); }, menus: actions
607
- .filter(function (_action) { return !!_action.moreMenu; })
608
- .map(function (_action, aindex) {
609
- var _a;
610
- return ({
611
- key: "" + aindex,
612
- name: (_a = _action.label) !== null && _a !== void 0 ? _a : _action.type,
613
- });
614
- }) }),
615
- ], false); },
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); },
616
635
  });
617
636
  }
618
637
  return { normalized: normalized, columnDefinitions: columnDefinitions };
619
- }, [fields, data, setControlContextData, actions, customActionChildren]);
638
+ }, [fields, data, setControlContextData, rowActions]);
620
639
  }
621
640
  function useSortedFilteredData(data, columns) {
622
641
  var _a = useState(""), search = _a[0], setSearch = _a[1];
@@ -653,8 +672,8 @@ function useSortedFilteredData(data, columns) {
653
672
  setSortState: setSortState,
654
673
  };
655
674
  }
656
- function useRowSelection(data, props) {
657
- 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;
658
677
  var deriveSelectedRowKeys = function () {
659
678
  if (!canSelectRows ||
660
679
  canSelectRows === "none" ||
@@ -665,7 +684,7 @@ function useRowSelection(data, props) {
665
684
  return [selectedRowKey];
666
685
  }
667
686
  else if (Array.isArray(selectedRowKey)) {
668
- if (canSelectRows === "single") {
687
+ if (canSelectRows === "single" || canSelectRows === "click") {
669
688
  return selectedRowKey.slice(0, 1);
670
689
  }
671
690
  else {
@@ -677,16 +696,46 @@ function useRowSelection(data, props) {
677
696
  }
678
697
  };
679
698
  var rowSelection = canSelectRows && canSelectRows !== "none"
680
- ? {
681
- type: canSelectRows === "single" ? "radio" : "checkbox",
682
- selectedRowKeys: deriveSelectedRowKeys(),
683
- onChange: function (rowKeys, rows) {
699
+ ? __assign({ type: canSelectRows === "single" || canSelectRows === "click"
700
+ ? "radio"
701
+ : "checkbox", selectedRowKeys: deriveSelectedRowKeys(), onChange: function (rowKeys, rows) {
684
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
+ }
685
727
  },
686
- alwaysShowAlert: true,
687
- }
688
- : undefined;
689
- return rowSelection;
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;
690
739
  }
691
740
  function ExportMenu(props) {
692
741
  var _this = this;
@@ -893,10 +942,12 @@ var dataTableMeta = {
893
942
  displayName: "Select rows?",
894
943
  options: [
895
944
  { label: "No", value: "none" },
896
- { label: "Single", value: "single" },
897
- { label: "Multiple", value: "multiple" },
945
+ { label: "By clicking a row", value: "click" },
946
+ { label: "Using radio buttons", value: "single" },
947
+ { label: "Using checkboxes", value: "multiple" },
898
948
  ],
899
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.",
900
951
  },
901
952
  rowKey: {
902
953
  type: "string",
@@ -925,6 +976,65 @@ var dataTableMeta = {
925
976
  { name: "rows", type: "object" },
926
977
  ],
927
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
+ },
928
1038
  pagination: {
929
1039
  type: "boolean",
930
1040
  advanced: true,
@@ -932,19 +1042,39 @@ var dataTableMeta = {
932
1042
  },
933
1043
  hideSearch: {
934
1044
  type: "boolean",
1045
+ description: "Hides the search toolbar",
935
1046
  advanced: true,
936
1047
  },
937
1048
  hideExports: {
938
1049
  type: "boolean",
1050
+ description: "Hides the button for exporting table data to CSV",
939
1051
  advanced: true,
940
1052
  },
941
1053
  hideDensity: {
942
1054
  type: "boolean",
1055
+ description: "Hides the control for changing the density of the table",
943
1056
  advanced: true,
1057
+ defaultValueHint: true,
944
1058
  },
945
1059
  hideColumnPicker: {
946
1060
  type: "boolean",
1061
+ description: "Hides the control for reordering and pinning columns",
1062
+ advanced: true,
1063
+ },
1064
+ hideSelectionBar: {
1065
+ type: "boolean",
1066
+ description: "Hides the toolbar that allows the user to clear selection",
947
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,
948
1078
  },
949
1079
  },
950
1080
  states: {