@plasmicpkgs/plasmic-rich-components 1.0.50 → 1.0.52

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.
@@ -43,9 +43,7 @@ export declare type ColumnConfig = {
43
43
  isHidden: boolean;
44
44
  formatting: StyleConfig;
45
45
  } & (AutoSettings | NumberSettings | StringSettings | BooleanSettings);
46
- export declare type PartialColumnConfig = Omit<Partial<ColumnConfig>, "key"> & {
47
- key: string;
48
- };
46
+ export declare type PartialColumnConfig = Partial<ColumnConfig>;
49
47
  export declare function deriveFieldConfigs(specifiedFieldsPartial: PartialColumnConfig[], schema: TableSchema | undefined): {
50
48
  mergedFields: ColumnConfig[];
51
49
  minimalFullLengthFields: PartialColumnConfig[];
@@ -71,37 +71,6 @@ function _objectWithoutPropertiesLoose(source, excluded) {
71
71
  }
72
72
  return target;
73
73
  }
74
- function _unsupportedIterableToArray(o, minLen) {
75
- if (!o) return;
76
- if (typeof o === "string") return _arrayLikeToArray(o, minLen);
77
- var n = Object.prototype.toString.call(o).slice(8, -1);
78
- if (n === "Object" && o.constructor) n = o.constructor.name;
79
- if (n === "Map" || n === "Set") return Array.from(o);
80
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
81
- }
82
- function _arrayLikeToArray(arr, len) {
83
- if (len == null || len > arr.length) len = arr.length;
84
- for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
85
- return arr2;
86
- }
87
- function _createForOfIteratorHelperLoose(o, allowArrayLike) {
88
- var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
89
- if (it) return (it = it.call(o)).next.bind(it);
90
- if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
91
- if (it) o = it;
92
- var i = 0;
93
- return function () {
94
- if (i >= o.length) return {
95
- done: true
96
- };
97
- return {
98
- done: false,
99
- value: o[i++]
100
- };
101
- };
102
- }
103
- throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
104
- }
105
74
 
106
75
  function useIsClient() {
107
76
  var _useState = React.useState(false),
@@ -1097,14 +1066,6 @@ var defaultColumnConfig = function defaultColumnConfig() {
1097
1066
  };
1098
1067
  function deriveFieldConfigs(specifiedFieldsPartial, schema) {
1099
1068
  var _schema$fields;
1100
- // Ugly: when adding a new item to an array from Plasmic Studio UI, no way to specify default values for the new item,
1101
- // so we have to do it here. The only one we need is the random key.
1102
- for (var _iterator = _createForOfIteratorHelperLoose(specifiedFieldsPartial), _step; !(_step = _iterator()).done;) {
1103
- var field = _step.value;
1104
- if (!field.key) {
1105
- field.key = mkShortId();
1106
- }
1107
- }
1108
1069
  var schemaFields = (_schema$fields = schema == null ? void 0 : schema.fields) != null ? _schema$fields : [];
1109
1070
  var fieldById = mkIdMap(schemaFields);
1110
1071
  var specifiedFieldIds = new Set(withoutNils(specifiedFieldsPartial.map(function (f) {
@@ -1112,6 +1073,7 @@ function deriveFieldConfigs(specifiedFieldsPartial, schema) {
1112
1073
  })));
1113
1074
  function defaultColumnConfigForField(field) {
1114
1075
  return _extends({}, defaultColumnConfig(), {
1076
+ key: field.id,
1115
1077
  fieldId: field.id,
1116
1078
  title: field.label || field.id,
1117
1079
  expr: function expr(currentItem) {
@@ -1119,10 +1081,12 @@ function deriveFieldConfigs(specifiedFieldsPartial, schema) {
1119
1081
  }
1120
1082
  });
1121
1083
  }
1122
- var keptSpecifiedFields = specifiedFieldsPartial.flatMap(function (f) {
1084
+ var keptSpecifiedFields = specifiedFieldsPartial.flatMap(function (f, index) {
1123
1085
  var fieldId = f.fieldId;
1124
1086
  if (!fieldId) {
1125
- return [_extends({}, defaultColumnConfig(), f)];
1087
+ return [_extends({}, defaultColumnConfig(), {
1088
+ key: index
1089
+ }, f)];
1126
1090
  }
1127
1091
  var field = fieldById.get(fieldId);
1128
1092
  // Drop configs with fieldIds no longer in the data.
@@ -1216,8 +1180,13 @@ function normalizeData(rawData) {
1216
1180
  schema: schema
1217
1181
  });
1218
1182
  }
1183
+ /**
1184
+ * Render booleans, objects, arrays, etc. as JSON repr.
1185
+ */
1186
+ function safeRender(x) {
1187
+ return x === undefined || x === null ? "" : typeof x === "string" ? x : typeof x === "number" ? x.toString() : JSON.stringify(x);
1188
+ }
1219
1189
  function RichTable(props) {
1220
- var _data$data;
1221
1190
  var className = props.className,
1222
1191
  _props$data = props.data,
1223
1192
  rawData = _props$data === void 0 ? {
@@ -1231,6 +1200,8 @@ function RichTable(props) {
1231
1200
  }]
1232
1201
  }
1233
1202
  } : _props$data,
1203
+ _props$pagination = props.pagination,
1204
+ pagination = _props$pagination === void 0 ? true : _props$pagination,
1234
1205
  defaultSize = props.defaultSize,
1235
1206
  fields = props.fields,
1236
1207
  setControlContextData = props.setControlContextData,
@@ -1238,10 +1209,12 @@ function RichTable(props) {
1238
1209
  addHref = props.addHref,
1239
1210
  actions = props.actions,
1240
1211
  customActionChildren = props.customActionChildren,
1241
- _props$showSearch = props.showSearch,
1242
- showSearch = _props$showSearch === void 0 ? true : _props$showSearch,
1243
1212
  _props$pageSize = props.pageSize,
1244
- pageSize = _props$pageSize === void 0 ? 20 : _props$pageSize;
1213
+ pageSize = _props$pageSize === void 0 ? 20 : _props$pageSize,
1214
+ hideSearch = props.hideSearch,
1215
+ hideDensity = props.hideDensity,
1216
+ hideColumnPicker = props.hideColumnPicker,
1217
+ hideExports = props.hideExports;
1245
1218
  var data = normalizeData(rawData);
1246
1219
  var _useState = React.useState(""),
1247
1220
  search = _useState[0],
@@ -1298,7 +1271,7 @@ function RichTable(props) {
1298
1271
  }, React__default.createElement(host.DataProvider, {
1299
1272
  name: "currentColumn",
1300
1273
  data: value
1301
- }, cconfig.expr ? cconfig.expr(record) : record)));
1274
+ }, safeRender(cconfig.expr ? cconfig.expr(record) : value))));
1302
1275
  }
1303
1276
  };
1304
1277
  return columnDefinition;
@@ -1348,50 +1321,76 @@ function RichTable(props) {
1348
1321
  normalized: normalized,
1349
1322
  columnDefinitions: columnDefinitions
1350
1323
  };
1351
- }, [fields, data, setControlContextData, Math.random()]),
1352
- columnDefinitions = _React$useMemo.columnDefinitions;
1324
+ }, [fields, data, setControlContextData]),
1325
+ columnDefinitions = _React$useMemo.columnDefinitions,
1326
+ normalized = _React$useMemo.normalized;
1353
1327
  var actionRef = React.useRef();
1328
+ var _useState2 = React.useState(undefined),
1329
+ state = _useState2[0],
1330
+ setState = _useState2[1];
1331
+ var finalData = React.useMemo(function () {
1332
+ var _data$data;
1333
+ var filtered = data == null ? void 0 : (_data$data = data.data) == null ? void 0 : _data$data.filter(function (row) {
1334
+ return fastStringify(Object.values(row)).toLowerCase().includes(search);
1335
+ });
1336
+ var sorted = state != null && state.sorter.column ?
1337
+ // We use .sort() rather than sortBy to use localeCompare
1338
+ function () {
1339
+ var _normalized$find$expr;
1340
+ var expr = (_normalized$find$expr = normalized.find(function (cconfig) {
1341
+ var _state$sorter$column;
1342
+ return cconfig.key === (state == null ? void 0 : (_state$sorter$column = state.sorter.column) == null ? void 0 : _state$sorter$column.key);
1343
+ }).expr) != null ? _normalized$find$expr : function (x) {
1344
+ return x;
1345
+ };
1346
+ return (filtered != null ? filtered : []).sort(function (aa, bb) {
1347
+ var _expr, _expr2;
1348
+ var a = (_expr = expr(aa)) != null ? _expr : null,
1349
+ b = (_expr2 = expr(bb)) != null ? _expr2 : null;
1350
+ // Default nil to '' here because A < null < z which is weird.
1351
+ return typeof a === "string" ? a.localeCompare(b != null ? b : "") : typeof b === "string" ? -b.localeCompare(a != null ? a : "") : a - b;
1352
+ });
1353
+ }() : filtered;
1354
+ var reversed = (state == null ? void 0 : state.sorter.order) === "descend" ? sorted == null ? void 0 : sorted.reverse() : sorted;
1355
+ return reversed;
1356
+ }, [data, normalized, state, search]);
1354
1357
  var isClient = useIsClient();
1355
1358
  if (!isClient) {
1356
1359
  return null;
1357
1360
  }
1358
- // return <NestedTest {...{ fields }} />;
1359
1361
  return React__default.createElement(React__default.Fragment, null, React__default.createElement(proComponents.ProTable, {
1360
1362
  actionRef: actionRef,
1361
1363
  className: className,
1362
1364
  columns: columnDefinitions,
1363
- dataSource: data == null ? void 0 : (_data$data = data.data) == null ? void 0 : _data$data.filter(function (row) {
1364
- return fastStringify(Object.values(row)).toLowerCase().includes(search);
1365
- }),
1365
+ onChange: function onChange(_pagination, _filters, sorter, _extra) {
1366
+ setState({
1367
+ sorter: sorter
1368
+ });
1369
+ },
1370
+ dataSource: finalData,
1366
1371
  rowKey: "id",
1367
1372
  defaultSize: defaultSize,
1368
- // request={() =>
1369
- // Promise.resolve({
1370
- // data: data?.data?.filter((row) =>
1371
- // fastStringify(row).toLowerCase().includes(search)
1372
- // ),
1373
- // success: true,
1374
- // })
1375
- // }
1376
1373
  editable: {
1377
1374
  type: "multiple"
1378
1375
  },
1379
1376
  search: false,
1380
1377
  options: {
1381
- setting: {
1378
+ setting: hideColumnPicker ? false : {
1382
1379
  listsHeight: 400
1383
- }
1380
+ },
1381
+ reload: false,
1382
+ density: !hideDensity
1384
1383
  },
1385
- pagination: {
1384
+ pagination: pagination ? {
1386
1385
  pageSize: pageSize,
1387
1386
  onChange: function onChange(page) {
1388
1387
  return console.log(page);
1389
1388
  }
1390
- },
1389
+ } : false,
1391
1390
  dateFormatter: "string",
1392
1391
  headerTitle: title,
1393
1392
  toolbar: {
1394
- search: showSearch ? {
1393
+ search: !hideSearch ? {
1395
1394
  value: search,
1396
1395
  onChange: function onChange(e) {
1397
1396
  return setSearch(e.target.value);
@@ -1406,7 +1405,7 @@ function RichTable(props) {
1406
1405
  icon: React__default.createElement(icons.PlusOutlined, null),
1407
1406
  type: "primary",
1408
1407
  href: addHref
1409
- }, "Add"), React__default.createElement(antd.Dropdown, {
1408
+ }, "Add"), !hideExports && React__default.createElement(antd.Dropdown, {
1410
1409
  key: "menu",
1411
1410
  menu: {
1412
1411
  items: [{
@@ -1521,17 +1520,15 @@ var dataTableMeta = {
1521
1520
  options: ["large", "middle", "small"],
1522
1521
  defaultValueHint: "large"
1523
1522
  },
1524
- // TODO
1525
- // pagination: {
1526
- // type: "boolean",
1527
- // defaultValueHint: true,
1528
- // },
1529
1523
  pageSize: {
1530
1524
  type: "number",
1531
1525
  defaultValueHint: 20
1532
1526
  },
1533
1527
  fields: {
1534
1528
  type: "array",
1529
+ hidden: function hidden(ps) {
1530
+ return !ps.data;
1531
+ },
1535
1532
  unstable__keyFunc: function unstable__keyFunc(x) {
1536
1533
  return x.key;
1537
1534
  },
@@ -1601,6 +1598,27 @@ var dataTableMeta = {
1601
1598
  }
1602
1599
  }
1603
1600
  }
1601
+ },
1602
+ pagination: {
1603
+ type: "boolean",
1604
+ advanced: true,
1605
+ defaultValueHint: true
1606
+ },
1607
+ hideSearch: {
1608
+ type: "boolean",
1609
+ advanced: true
1610
+ },
1611
+ hideExports: {
1612
+ type: "boolean",
1613
+ advanced: true
1614
+ },
1615
+ hideDensity: {
1616
+ type: "boolean",
1617
+ advanced: true
1618
+ },
1619
+ hideColumnPicker: {
1620
+ type: "boolean",
1621
+ advanced: true
1604
1622
  }
1605
1623
  },
1606
1624
  importName: "RichTable",