@plasmicpkgs/plasmic-rich-components 1.0.84 → 1.0.86

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
@@ -2,6 +2,7 @@
2
2
 
3
3
  var registerComponent = require('@plasmicapp/host/registerComponent');
4
4
  require('@plasmicapp/host/registerGlobalContext');
5
+ var lodash = require('lodash');
5
6
  var proComponents = require('@ant-design/pro-components');
6
7
  var React = require('react');
7
8
  var antd = require('antd');
@@ -9,12 +10,14 @@ var tinycolor = require('@ctrl/tinycolor');
9
10
  var icons = require('@ant-design/icons');
10
11
  var csvWriterBrowser = require('csv-writer-browser');
11
12
  var fastStringify = require('fast-stringify');
13
+ var classNames = require('classnames');
12
14
 
13
15
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
14
16
 
15
17
  var registerComponent__default = /*#__PURE__*/_interopDefault(registerComponent);
16
18
  var React__default = /*#__PURE__*/_interopDefault(React);
17
19
  var fastStringify__default = /*#__PURE__*/_interopDefault(fastStringify);
20
+ var classNames__default = /*#__PURE__*/_interopDefault(classNames);
18
21
 
19
22
  /*! *****************************************************************************
20
23
  Copyright (c) Microsoft Corporation.
@@ -110,10 +113,41 @@ function registerComponentHelper(loader, component, meta) {
110
113
  registerComponent__default.default(component, meta);
111
114
  }
112
115
  }
116
+ function ensure(x) {
117
+ if (x === null || x === undefined) {
118
+ throw new Error("Expected non-null or non-undefined value");
119
+ }
120
+ return x;
121
+ }
113
122
  function isOneOf(elem, arr) {
114
123
  return arr.includes(elem);
115
124
  }
116
-
125
+ function maybe(x, f) {
126
+ if (x === undefined || x === null)
127
+ return undefined;
128
+ return f(x);
129
+ }
130
+ function isLikeImage(value) {
131
+ return typeof value === "string"
132
+ ? value.match(/\.(png|jpg|jpeg|gif|svg|webp|avif|ico|bmp|tiff)$/i)
133
+ : false;
134
+ }
135
+ // Some heuristics to avoid selecting a row when
136
+ // the object clicked is interactable -- like button, anchor,
137
+ // input, etc. This won't be bulletproof, so just some
138
+ // heuristics!
139
+ function isInteractable(target) {
140
+ if (["A", "BUTTON", "INPUT", "TEXTAREA", "SELECT"].includes(target.tagName)) {
141
+ return true;
142
+ }
143
+ if (target.contentEditable === "true") {
144
+ return true;
145
+ }
146
+ return false;
147
+ }
148
+ function ensureArray(xs) {
149
+ return Array.isArray(xs) ? xs : [xs];
150
+ }
117
151
  var tuple = function () {
118
152
  var args = [];
119
153
  for (var _i = 0; _i < arguments.length; _i++) {
@@ -128,6 +162,10 @@ var mkShortId = function () { return "".concat(Math.random()); };
128
162
  function withoutNils(xs) {
129
163
  return xs.filter(function (x) { return x != null; });
130
164
  }
165
+ function withoutFalsey(xs) {
166
+ return xs.filter(function (x) { return !!x; });
167
+ }
168
+
131
169
  var DEFAULT_CURRENCY_SETTINGS = {
132
170
  dataType: "currency",
133
171
  currency: "USD",
@@ -192,41 +230,369 @@ function deriveValueType(cconfig) {
192
230
  ? "switch"
193
231
  : undefined;
194
232
  }
195
- function buildFieldsPropType(opts) {
196
- function getDefaultValueHint(field) {
197
- return function (_props, contextData, _a) {
198
- var item = _a.item;
199
- if (item.fieldId) {
200
- var fieldSetting = contextData === null || contextData === void 0 ? void 0 : contextData.mergedFields.find(function (f) { return f.fieldId === item.fieldId; });
201
- return fieldSetting === null || fieldSetting === void 0 ? void 0 : fieldSetting[field];
202
- }
203
- return undefined;
204
- };
205
- }
206
- var rowDataType = function (displayName, control) {
207
- return ({
208
- type: "function",
209
- displayName: displayName,
210
- control: control,
211
- argNames: ["currentItem", "currentValue"],
212
- argValues: function (_props, ctx, _a) {
213
- var _b;
214
- var item = _a.item;
215
- var row = (_b = ctx === null || ctx === void 0 ? void 0 : ctx.data) === null || _b === void 0 ? void 0 : _b[0];
216
- var cell = item.fieldId ? row === null || row === void 0 ? void 0 : row[item.fieldId] : undefined;
217
- return [row, cell];
233
+ // Hacky "unique" string values
234
+ var NoneField = "||NoneField||";
235
+ var CustomField = "";
236
+ function getFieldSubprops(opts) {
237
+ return __assign(__assign({ key: {
238
+ type: "string",
239
+ hidden: function () { return true; },
240
+ }, fieldId: {
241
+ type: "choice",
242
+ displayName: "Field name",
243
+ readOnly: !opts.canChangeField,
244
+ options: function (_props, ctx) {
245
+ var _a, _b;
246
+ return withoutFalsey(__spreadArray(__spreadArray([
247
+ opts.canPickNoneField && { value: NoneField, label: "None" }
248
+ ], ((_b = (_a = ctx === null || ctx === void 0 ? void 0 : ctx.schema) === null || _a === void 0 ? void 0 : _a.fields) !== null && _b !== void 0 ? _b : []).map(function (f) {
249
+ var _a;
250
+ return ({
251
+ value: f.id,
252
+ label: (_a = f.label) !== null && _a !== void 0 ? _a : f.id,
253
+ });
254
+ }), true), [
255
+ { value: CustomField, label: "Custom value" },
256
+ ], false));
218
257
  },
219
- });
258
+ hidden: function (ps, ctx, _a) {
259
+ _a.path;
260
+ // If this is change-able.
261
+ if (opts.canChangeField) {
262
+ return false;
263
+ }
264
+ return true;
265
+ },
266
+ }, title: {
267
+ type: "string",
268
+ displayName: "Title",
269
+ defaultValueHint: getDefaultValueHint("title"),
270
+ hidden: function () { return !!opts.noTitle; },
271
+ }, expr: __assign(__assign({}, rowDataType("Custom value")), { hidden: function (ps, ctx, _a) {
272
+ _a.item; _a.path;
273
+ return false;
274
+ } }), isHidden: {
275
+ type: "boolean",
276
+ displayName: "Is hidden",
277
+ defaultValueHint: getDefaultValueHint("isHidden"),
278
+ } }, (opts.noDataType
279
+ ? {
280
+ dataType: {
281
+ type: "choice",
282
+ displayName: "Data type",
283
+ options: [
284
+ {
285
+ value: "auto",
286
+ label: "Auto",
287
+ },
288
+ {
289
+ value: "number",
290
+ label: "Number",
291
+ },
292
+ {
293
+ value: "percent",
294
+ label: "Percentage",
295
+ },
296
+ {
297
+ value: "currency",
298
+ label: "Currency",
299
+ },
300
+ {
301
+ value: "string",
302
+ label: "String",
303
+ },
304
+ {
305
+ value: "boolean",
306
+ label: "Boolean",
307
+ },
308
+ {
309
+ value: "datetime",
310
+ label: "Date / Time",
311
+ },
312
+ {
313
+ value: "relative-datetime",
314
+ label: "Date / Time relative to now",
315
+ },
316
+ ],
317
+ defaultValueHint: getDefaultValueHint("dataType"),
318
+ },
319
+ currency: {
320
+ displayName: "Currency",
321
+ description: "Must be a valid currency code",
322
+ type: "string",
323
+ defaultValueHint: "USD",
324
+ hidden: function (ps, ctx, _a) {
325
+ var item = _a.item;
326
+ return item.dataType !== "currency";
327
+ },
328
+ },
329
+ locale: {
330
+ displayName: "Locale",
331
+ description: "Must be a valid locale code",
332
+ type: "string",
333
+ defaultValueHint: "en-US",
334
+ hidden: function (ps, ctx, _a) {
335
+ var item = _a.item;
336
+ return !isOneOf(item.dataType, NUMBER_TYPES) &&
337
+ !isOneOf(item.dataType, DATETIME_TYPES);
338
+ },
339
+ },
340
+ notation: {
341
+ displayName: "Notation",
342
+ type: "choice",
343
+ options: [
344
+ {
345
+ value: "standard",
346
+ label: "Standard",
347
+ },
348
+ {
349
+ value: "scientific",
350
+ label: "Scientific notation (like 1E3)",
351
+ },
352
+ {
353
+ value: "compact",
354
+ label: "Compact (like 10K)",
355
+ },
356
+ ],
357
+ defaultValueHint: "standard",
358
+ hidden: function (ps, ctx, _a) {
359
+ var item = _a.item;
360
+ return !isOneOf(item.dataType, NUMBER_TYPES);
361
+ },
362
+ },
363
+ signDisplay: {
364
+ type: "choice",
365
+ displayName: "Number sign",
366
+ options: [
367
+ {
368
+ value: "auto",
369
+ label: "Only for negative numbers (10, -10)",
370
+ },
371
+ {
372
+ value: "exceptZero",
373
+ label: "Positive or negative (+10, -10)",
374
+ },
375
+ ],
376
+ defaultValueHint: "auto",
377
+ hidden: function (ps, ctx, _a) {
378
+ var item = _a.item;
379
+ return !isOneOf(item.dataType, NUMBER_TYPES);
380
+ },
381
+ },
382
+ maximumFractionDigits: {
383
+ type: "number",
384
+ displayName: "Max decimal places",
385
+ defaultValueHint: 3,
386
+ min: 0,
387
+ max: 20,
388
+ hidden: function (ps, ctx, _a) {
389
+ var item = _a.item;
390
+ return !isOneOf(item.dataType, NUMBER_TYPES);
391
+ },
392
+ },
393
+ minimumFractionDigits: {
394
+ type: "number",
395
+ displayName: "Min decimal places",
396
+ defaultValueHint: 0,
397
+ min: 0,
398
+ max: 20,
399
+ hidden: function (ps, ctx, _a) {
400
+ var item = _a.item;
401
+ return !isOneOf(item.dataType, NUMBER_TYPES);
402
+ },
403
+ },
404
+ showAs: {
405
+ type: "choice",
406
+ options: [
407
+ {
408
+ value: "checkbox",
409
+ label: "Checkboxes",
410
+ },
411
+ {
412
+ value: "switch",
413
+ label: "Toggle switches",
414
+ },
415
+ {
416
+ value: "text",
417
+ label: "Text",
418
+ },
419
+ ],
420
+ displayName: "Show as",
421
+ defaultValueHint: "checkbox",
422
+ hidden: function (ps, ctx, _a) {
423
+ var item = _a.item;
424
+ return item.dataType !== "boolean";
425
+ },
426
+ },
427
+ dateStyle: {
428
+ displayName: "Date style",
429
+ type: "choice",
430
+ options: [
431
+ {
432
+ value: "none",
433
+ label: "None (don't display date)",
434
+ },
435
+ {
436
+ value: "short",
437
+ label: "Short (like 12/25/2023)",
438
+ },
439
+ {
440
+ value: "medium",
441
+ label: "Medium (like Dec 25, 2023)",
442
+ },
443
+ {
444
+ value: "long",
445
+ label: "Long (like December 25, 2023)",
446
+ },
447
+ {
448
+ value: "full",
449
+ label: "Full (like Monday, December 25, 2023)",
450
+ },
451
+ ],
452
+ defaultValueHint: DEFAULT_DATETIME_SETTINGS.dateStyle,
453
+ hidden: function (ps, ctx, _a) {
454
+ var item = _a.item;
455
+ return item.dataType !== "datetime";
456
+ },
457
+ },
458
+ timeStyle: {
459
+ displayName: "Time style",
460
+ type: "choice",
461
+ options: [
462
+ {
463
+ value: "none",
464
+ label: "None (don't display time)",
465
+ },
466
+ {
467
+ value: "short",
468
+ label: "Short (like 4:00 PM)",
469
+ },
470
+ {
471
+ value: "medium",
472
+ label: "Medium (like 4:00:00 PM)",
473
+ },
474
+ {
475
+ value: "long",
476
+ label: "Long (like 4:00:00 PM PST)",
477
+ },
478
+ {
479
+ value: "full",
480
+ label: "Full (like 4:00:00 PM Pacific Standard Time)",
481
+ },
482
+ ],
483
+ defaultValueHint: DEFAULT_DATETIME_SETTINGS.timeStyle,
484
+ hidden: function (ps, ctx, _a) {
485
+ var item = _a.item;
486
+ return item.dataType !== "datetime";
487
+ },
488
+ },
489
+ hour12: {
490
+ displayName: "Use AM/PM?",
491
+ description: "Whether to use AM/PM or 24-hour clock",
492
+ type: "boolean",
493
+ defaultValueHint: DEFAULT_DATETIME_SETTINGS.hour12,
494
+ hidden: function (ps, ctx, _a) {
495
+ var item = _a.item;
496
+ return item.dataType !== "datetime";
497
+ },
498
+ },
499
+ numeric: {
500
+ type: "choice",
501
+ displayName: "Use numbers?",
502
+ options: [
503
+ { value: "always", label: "Always use numbers" },
504
+ {
505
+ value: "auto",
506
+ label: "Use words like 'Yesterday' or 'Tomorrow'",
507
+ },
508
+ ],
509
+ defaultValueHint: DEFAULT_RELATIVE_DATETIME_SETTINGS.numeric,
510
+ hidden: function (ps, ctx, _a) {
511
+ var item = _a.item;
512
+ return item.dataType !== "relative-datetime";
513
+ },
514
+ },
515
+ unit: {
516
+ type: "choice",
517
+ displayName: "Time unit",
518
+ options: [
519
+ {
520
+ value: "second",
521
+ label: "Seconds",
522
+ },
523
+ {
524
+ value: "minute",
525
+ label: "Minutes",
526
+ },
527
+ {
528
+ value: "hour",
529
+ label: "Hours",
530
+ },
531
+ {
532
+ value: "day",
533
+ label: "Days",
534
+ },
535
+ {
536
+ value: "week",
537
+ label: "Weeks",
538
+ },
539
+ {
540
+ value: "month",
541
+ label: "Months",
542
+ },
543
+ {
544
+ value: "year",
545
+ label: "Years",
546
+ },
547
+ ],
548
+ defaultValueHint: DEFAULT_RELATIVE_DATETIME_SETTINGS.unit,
549
+ hidden: function (ps, ctx, _a) {
550
+ var item = _a.item;
551
+ return item.dataType !== "relative-datetime";
552
+ },
553
+ },
554
+ }
555
+ : {})), opts.fieldTypes);
556
+ }
557
+ function getDefaultValueHint(field) {
558
+ return function (_props, contextData, _a) {
559
+ var item = _a.item;
560
+ if (item === null || item === void 0 ? void 0 : item.fieldId) {
561
+ var fieldSetting = contextData === null || contextData === void 0 ? void 0 : contextData.mergedFields.find(function (f) { return f.fieldId === item.fieldId; });
562
+ return fieldSetting === null || fieldSetting === void 0 ? void 0 : fieldSetting[field];
563
+ }
564
+ return undefined;
220
565
  };
566
+ }
567
+ var rowDataType = function (displayName, control) {
568
+ return ({
569
+ type: "function",
570
+ displayName: displayName,
571
+ control: control,
572
+ argNames: ["currentItem", "currentValue"],
573
+ argValues: function (_props, ctx, _a) {
574
+ var _b;
575
+ var item = _a.item;
576
+ var row = (_b = ctx === null || ctx === void 0 ? void 0 : ctx.data) === null || _b === void 0 ? void 0 : _b[0];
577
+ var cell = item.fieldId ? row === null || row === void 0 ? void 0 : row[item.fieldId] : undefined;
578
+ return [row, cell];
579
+ },
580
+ });
581
+ };
582
+ function buildFieldsPropType(_a) {
583
+ var advanced = _a.advanced, displayName = _a.displayName, _b = _a.minimalValue, minimalValue = _b === void 0 ? function (_props, contextData) { return contextData === null || contextData === void 0 ? void 0 : contextData.minimalFullLengthFields; } : _b, opts = __rest(_a, ["advanced", "displayName", "minimalValue"]);
221
584
  return {
222
585
  type: "array",
586
+ advanced: advanced,
587
+ displayName: displayName,
223
588
  hidden: function (ps) { return !ps.data; },
224
589
  unstable__keyFunc: function (x) { return x.key; },
225
- unstable__minimalValue: function (_props, contextData) {
226
- return contextData === null || contextData === void 0 ? void 0 : contextData.minimalFullLengthFields;
227
- },
590
+ unstable__minimalValue: minimalValue,
228
591
  unstable__canDelete: function (ps, _props, ctx, _a) {
229
592
  var item = _a.item;
593
+ if (opts.canChangeField) {
594
+ return true;
595
+ }
230
596
  if (!(ctx === null || ctx === void 0 ? void 0 : ctx.schema)) {
231
597
  // still loading...
232
598
  return false;
@@ -240,292 +606,10 @@ function buildFieldsPropType(opts) {
240
606
  itemType: {
241
607
  type: "object",
242
608
  nameFunc: function (_item) {
243
- var _a;
244
- return (_a = _item.title) !== null && _a !== void 0 ? _a : _item.fieldId;
609
+ // Prefer to show the field ID when available, since there's no other indication what field you're edtiing if you relabeled it.
610
+ return _item.fieldId || _item.title || "Custom value";
245
611
  },
246
- fields: __assign({ key: {
247
- type: "string",
248
- hidden: function () { return true; },
249
- }, fieldId: {
250
- type: "choice",
251
- displayName: "Field name",
252
- readOnly: true,
253
- options: function (_props, ctx) { var _a, _b; return ((_b = (_a = ctx === null || ctx === void 0 ? void 0 : ctx.schema) === null || _a === void 0 ? void 0 : _a.fields) !== null && _b !== void 0 ? _b : []).map(function (f) { return f.id; }); },
254
- hidden: function (_props, ctx, _a) {
255
- var _b, _c;
256
- var _controlPath = _a.path;
257
- return !(_controlPath.slice(-1)[0] in ((_c = (_b = ctx === null || ctx === void 0 ? void 0 : ctx.schema) === null || _b === void 0 ? void 0 : _b.fields) !== null && _c !== void 0 ? _c : {}));
258
- },
259
- }, title: {
260
- type: "string",
261
- displayName: "Title",
262
- defaultValueHint: getDefaultValueHint("title"),
263
- }, expr: rowDataType("Customize cell data"), isHidden: {
264
- type: "boolean",
265
- displayName: "Is hidden",
266
- defaultValueHint: getDefaultValueHint("isHidden"),
267
- }, dataType: {
268
- type: "choice",
269
- displayName: "Data type",
270
- options: [
271
- {
272
- value: "auto",
273
- label: "Auto",
274
- },
275
- {
276
- value: "number",
277
- label: "Number",
278
- },
279
- {
280
- value: "percent",
281
- label: "Percentage",
282
- },
283
- {
284
- value: "currency",
285
- label: "Currency",
286
- },
287
- {
288
- value: "string",
289
- label: "String",
290
- },
291
- {
292
- value: "boolean",
293
- label: "Boolean",
294
- },
295
- {
296
- value: "datetime",
297
- label: "Date / Time",
298
- },
299
- {
300
- value: "relative-datetime",
301
- label: "Date / Time relative to now",
302
- },
303
- ],
304
- defaultValueHint: getDefaultValueHint("dataType"),
305
- }, currency: {
306
- displayName: "Currency",
307
- description: "Must be a valid currency code",
308
- type: "string",
309
- defaultValueHint: "USD",
310
- hidden: function (ps, ctx, _a) {
311
- var item = _a.item;
312
- return item.dataType !== "currency";
313
- },
314
- }, locale: {
315
- displayName: "Locale",
316
- description: "Must be a valid locale code",
317
- type: "string",
318
- defaultValueHint: "en-US",
319
- hidden: function (ps, ctx, _a) {
320
- var item = _a.item;
321
- return !isOneOf(item.dataType, NUMBER_TYPES) &&
322
- !isOneOf(item.dataType, DATETIME_TYPES);
323
- },
324
- }, notation: {
325
- displayName: "Notation",
326
- type: "choice",
327
- options: [
328
- {
329
- value: "standard",
330
- label: "Standard",
331
- },
332
- {
333
- value: "scientific",
334
- label: "Scientific notation (like 1E3)",
335
- },
336
- {
337
- value: "compact",
338
- label: "Compact (like 10K)",
339
- },
340
- ],
341
- defaultValueHint: "standard",
342
- hidden: function (ps, ctx, _a) {
343
- var item = _a.item;
344
- return !isOneOf(item.dataType, NUMBER_TYPES);
345
- },
346
- }, signDisplay: {
347
- type: "choice",
348
- displayName: "Number sign",
349
- options: [
350
- {
351
- value: "auto",
352
- label: "Only for negative numbers (10, -10)",
353
- },
354
- {
355
- value: "exceptZero",
356
- label: "Positive or negative (+10, -10)",
357
- },
358
- ],
359
- defaultValueHint: "auto",
360
- hidden: function (ps, ctx, _a) {
361
- var item = _a.item;
362
- return !isOneOf(item.dataType, NUMBER_TYPES);
363
- },
364
- }, maximumFractionDigits: {
365
- type: "number",
366
- displayName: "Max decimal places",
367
- defaultValueHint: 3,
368
- min: 0,
369
- max: 20,
370
- hidden: function (ps, ctx, _a) {
371
- var item = _a.item;
372
- return !isOneOf(item.dataType, NUMBER_TYPES);
373
- },
374
- }, minimumFractionDigits: {
375
- type: "number",
376
- displayName: "Min decimal places",
377
- defaultValueHint: 0,
378
- min: 0,
379
- max: 20,
380
- hidden: function (ps, ctx, _a) {
381
- var item = _a.item;
382
- return !isOneOf(item.dataType, NUMBER_TYPES);
383
- },
384
- }, showAs: {
385
- type: "choice",
386
- options: [
387
- {
388
- value: "checkbox",
389
- label: "Checkboxes",
390
- },
391
- {
392
- value: "switch",
393
- label: "Toggle switches",
394
- },
395
- {
396
- value: "text",
397
- label: "Text",
398
- },
399
- ],
400
- displayName: "Show as",
401
- defaultValueHint: "checkbox",
402
- hidden: function (ps, ctx, _a) {
403
- var item = _a.item;
404
- return item.dataType !== "boolean";
405
- },
406
- }, dateStyle: {
407
- displayName: "Date style",
408
- type: "choice",
409
- options: [
410
- {
411
- value: "none",
412
- label: "None (don't display date)",
413
- },
414
- {
415
- value: "short",
416
- label: "Short (like 12/25/2023)",
417
- },
418
- {
419
- value: "medium",
420
- label: "Medium (like Dec 25, 2023)",
421
- },
422
- {
423
- value: "long",
424
- label: "Long (like December 25, 2023)",
425
- },
426
- {
427
- value: "full",
428
- label: "Full (like Monday, December 25, 2023)",
429
- },
430
- ],
431
- defaultValueHint: DEFAULT_DATETIME_SETTINGS.dateStyle,
432
- hidden: function (ps, ctx, _a) {
433
- var item = _a.item;
434
- return item.dataType !== "datetime";
435
- },
436
- }, timeStyle: {
437
- displayName: "Time style",
438
- type: "choice",
439
- options: [
440
- {
441
- value: "none",
442
- label: "None (don't display time)",
443
- },
444
- {
445
- value: "short",
446
- label: "Short (like 4:00 PM)",
447
- },
448
- {
449
- value: "medium",
450
- label: "Medium (like 4:00:00 PM)",
451
- },
452
- {
453
- value: "long",
454
- label: "Long (like 4:00:00 PM PST)",
455
- },
456
- {
457
- value: "full",
458
- label: "Full (like 4:00:00 PM Pacific Standard Time)",
459
- },
460
- ],
461
- defaultValueHint: DEFAULT_DATETIME_SETTINGS.timeStyle,
462
- hidden: function (ps, ctx, _a) {
463
- var item = _a.item;
464
- return item.dataType !== "datetime";
465
- },
466
- }, hour12: {
467
- displayName: "Use AM/PM?",
468
- description: "Whether to use AM/PM or 24-hour clock",
469
- type: "boolean",
470
- defaultValueHint: DEFAULT_DATETIME_SETTINGS.hour12,
471
- hidden: function (ps, ctx, _a) {
472
- var item = _a.item;
473
- return item.dataType !== "datetime";
474
- },
475
- }, numeric: {
476
- type: "choice",
477
- displayName: "Use numbers?",
478
- options: [
479
- { value: "always", label: "Always use numbers" },
480
- {
481
- value: "auto",
482
- label: "Use words like 'Yesterday' or 'Tomorrow'",
483
- },
484
- ],
485
- defaultValueHint: DEFAULT_RELATIVE_DATETIME_SETTINGS.numeric,
486
- hidden: function (ps, ctx, _a) {
487
- var item = _a.item;
488
- return item.dataType !== "relative-datetime";
489
- },
490
- }, unit: {
491
- type: "choice",
492
- displayName: "Time unit",
493
- options: [
494
- {
495
- value: "second",
496
- label: "Seconds",
497
- },
498
- {
499
- value: "minute",
500
- label: "Minutes",
501
- },
502
- {
503
- value: "hour",
504
- label: "Hours",
505
- },
506
- {
507
- value: "day",
508
- label: "Days",
509
- },
510
- {
511
- value: "week",
512
- label: "Weeks",
513
- },
514
- {
515
- value: "month",
516
- label: "Months",
517
- },
518
- {
519
- value: "year",
520
- label: "Years",
521
- },
522
- ],
523
- defaultValueHint: DEFAULT_RELATIVE_DATETIME_SETTINGS.unit,
524
- hidden: function (ps, ctx, _a) {
525
- var item = _a.item;
526
- return item.dataType !== "relative-datetime";
527
- },
528
- } }, opts.fieldTypes),
612
+ fields: getFieldSubprops(opts),
529
613
  },
530
614
  };
531
615
  }
@@ -610,10 +694,25 @@ function tryGetSchema(data) {
610
694
  };
611
695
  }
612
696
 
613
- function renderValue(value, record, cconfig) {
697
+ function multiRenderValue(record, cconfigs) {
698
+ return cconfigs === null || cconfigs === void 0 ? void 0 : cconfigs.flatMap(function (cc) {
699
+ return cc.isHidden ? [] : [" \u2022 ", React__default.default.createElement(React__default.default.Fragment, null, renderValue(record, cc))];
700
+ }).slice(1);
701
+ }
702
+ function maybeRenderString(record, cconfig) {
703
+ return cconfig && !cconfig.isHidden
704
+ ? maybe(getFieldValue(record, cconfig), asString)
705
+ : undefined;
706
+ }
707
+ function getFieldValue(record, cconfig) {
708
+ var value = cconfig.fieldId ? record[cconfig.fieldId] : undefined;
614
709
  if (cconfig.expr) {
615
710
  value = cconfig.expr(record, value);
616
711
  }
712
+ return value;
713
+ }
714
+ function renderValue(record, cconfig) {
715
+ var value = getFieldValue(record, cconfig);
617
716
  if (value == null) {
618
717
  return "";
619
718
  }
@@ -874,10 +973,7 @@ function useColumnDefinitions$1(data, props) {
874
973
  return defaultRender(_);
875
974
  },
876
975
  render: function (value, record, rowIndex) {
877
- var cellValue = cconfig.fieldId
878
- ? record[cconfig.fieldId]
879
- : undefined;
880
- return renderValue(cellValue, record, cconfig);
976
+ return renderValue(record, cconfig);
881
977
  },
882
978
  };
883
979
  return columnDefinition;
@@ -965,7 +1061,8 @@ function omitUndefined(x) {
965
1061
  return v !== undefined;
966
1062
  }));
967
1063
  }
968
- var baseStyles = "\n.ant-pro-layout-bg-list {\n display: none;\n}\n.ant-pro-layout {\n display: flex;\n}\n";
1064
+ // width: 100% needed because parent is display: flex, which is needed for the min-height behavior.
1065
+ var baseStyles = "\n.ant-pro-layout-bg-list {\n display: none;\n}\n.ant-pro-layout {\n display: flex;\n width: 100%;\n}\n";
969
1066
  function RichLayout(_a) {
970
1067
  var _b, _c, _d;
971
1068
  var children = _a.children, navMenuItems = _a.navMenuItems, _e = _a.rootUrl, rootUrl = _e === void 0 ? "/" : _e, actionsChildren = _a.actionsChildren, footerChildren = _a.footerChildren, avatarLabel = _a.avatarLabel, avatarImage = _a.avatarImage, showAvatarMenu = _a.showAvatarMenu, className = _a.className, simpleNavTheme = _a.simpleNavTheme, layoutProps = __rest(_a, ["children", "navMenuItems", "rootUrl", "actionsChildren", "footerChildren", "avatarLabel", "avatarImage", "showAvatarMenu", "className", "simpleNavTheme"]);
@@ -1258,44 +1355,132 @@ function registerRichLayout(loader) {
1258
1355
  registerComponentHelper(loader, RichLayout, richLayoutMeta);
1259
1356
  }
1260
1357
 
1261
- function RichTable(props) {
1262
- var className = props.className, _a = props.data, rawData = _a === void 0 ? {
1263
- data: [],
1264
- schema: {
1265
- id: "inferred",
1266
- fields: [
1267
- {
1268
- id: "id",
1269
- type: "string",
1270
- readOnly: false,
1271
- },
1272
- ],
1273
- },
1274
- } : _a,
1275
- // children,
1276
- _b = props.pagination,
1277
- // children,
1278
- 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;
1279
- var data = normalizeData(rawData);
1280
- var _f = useColumnDefinitions(data, props), columnDefinitions = _f.columnDefinitions, normalized = _f.normalized;
1281
- var actionRef = React.useRef();
1282
- var _g = useSortedFilteredData(data, normalized), finalData = _g.finalData, search = _g.search, setSearch = _g.setSearch, setSortState = _g.setSortState;
1283
- var rowSelectionProps = useRowSelectionProps(data, props);
1284
- var isClient = useIsClient();
1285
- if (!isClient) {
1286
- return null;
1287
- }
1288
- return (React__default.default.createElement("div", { className: "".concat(className, " ").concat(scopeClassName !== null && scopeClassName !== void 0 ? scopeClassName : "") },
1289
- React__default.default.createElement(proComponents.ProTable, __assign({ rowClassName: props.onRowClick || props.canSelectRows === "click"
1290
- ? "plasmic-table-row-clickable"
1291
- : undefined, actionRef: actionRef, columns: columnDefinitions, onChange: function (_pagination, _filters, sorter, _extra) {
1292
- setSortState({ sorter: sorter });
1293
- }, style: {
1294
- width: "100%",
1295
- }, cardProps: {
1296
- ghost: true,
1297
- } }, rowSelectionProps, { dataSource: finalData, rowKey: deriveRowKey(data, rowKey), defaultSize: defaultSize, editable: { type: "multiple" }, search: false, options: {
1298
- setting: hideColumnPicker
1358
+ function useSortedFilteredData(data, columns) {
1359
+ var _a = React.useState(""), search = _a[0], setSearch = _a[1];
1360
+ var _b = React.useState(undefined), sortState = _b[0], setSortState = _b[1];
1361
+ var finalData = React__default.default.useMemo(function () {
1362
+ var _a;
1363
+ var filtered = (_a = data === null || data === void 0 ? void 0 : data.data) === null || _a === void 0 ? void 0 : _a.filter(function (row) {
1364
+ return fastStringify__default.default(Object.values(row)).toLowerCase().includes(search);
1365
+ });
1366
+ var sorted = (sortState === null || sortState === void 0 ? void 0 : sortState.sorter.column)
1367
+ ? // We use .sort() rather than sortBy to use localeCompare
1368
+ (function () {
1369
+ var _a;
1370
+ var cconfig = columns.find(function (cc) { var _a; return cc.key === ((_a = sortState === null || sortState === void 0 ? void 0 : sortState.sorter.column) === null || _a === void 0 ? void 0 : _a.key); });
1371
+ var expr = (_a = cconfig.expr) !== null && _a !== void 0 ? _a : (function (x) { return x; });
1372
+ return (filtered !== null && filtered !== void 0 ? filtered : []).sort(function (aa, bb) {
1373
+ var _a, _b;
1374
+ var a = (_a = expr(aa, cconfig.fieldId ? aa === null || aa === void 0 ? void 0 : aa[cconfig.fieldId] : null)) !== null && _a !== void 0 ? _a : null, b = (_b = expr(bb, cconfig.fieldId ? bb === null || bb === void 0 ? void 0 : bb[cconfig.fieldId] : null)) !== null && _b !== void 0 ? _b : null;
1375
+ // Default nil to '' here because A < null < z which is weird.
1376
+ return typeof a === "string"
1377
+ ? a.localeCompare(b !== null && b !== void 0 ? b : "")
1378
+ : typeof b === "string"
1379
+ ? -b.localeCompare(a !== null && a !== void 0 ? a : "")
1380
+ : a - b;
1381
+ });
1382
+ })()
1383
+ : filtered;
1384
+ var reversed = (sortState === null || sortState === void 0 ? void 0 : sortState.sorter.order) === "descend" ? sorted === null || sorted === void 0 ? void 0 : sorted.reverse() : sorted;
1385
+ return reversed;
1386
+ }, [data, columns, sortState, search]);
1387
+ return {
1388
+ finalData: finalData,
1389
+ search: search,
1390
+ setSearch: setSearch,
1391
+ setSortState: setSortState,
1392
+ };
1393
+ }
1394
+ function deriveRowKey(data, rowKey) {
1395
+ var _a;
1396
+ if (rowKey) {
1397
+ return rowKey;
1398
+ }
1399
+ var schema = data === null || data === void 0 ? void 0 : data.schema;
1400
+ if (schema) {
1401
+ return (_a = schema.fields[0]) === null || _a === void 0 ? void 0 : _a.id;
1402
+ }
1403
+ return undefined;
1404
+ }
1405
+ function deriveKeyOfRow(row, rowKey) {
1406
+ if (typeof rowKey === "function") {
1407
+ return rowKey(row);
1408
+ }
1409
+ else if (typeof rowKey === "string") {
1410
+ return row[rowKey];
1411
+ }
1412
+ else {
1413
+ return undefined;
1414
+ }
1415
+ }
1416
+ function renderActions(rowActions, row, data, rowKey) {
1417
+ return rowActions.map(function (_action) {
1418
+ var _a;
1419
+ if (_action.type === "item") {
1420
+ return (React__default.default.createElement("a", { key: _action.label, style: {
1421
+ whiteSpace: "nowrap",
1422
+ }, onClick: function () {
1423
+ var _a;
1424
+ return (_a = _action.onClick) === null || _a === void 0 ? void 0 : _a.call(_action, deriveKeyOfRow(row, deriveRowKey(data, rowKey)), row);
1425
+ } }, _action.label));
1426
+ }
1427
+ else {
1428
+ return (React__default.default.createElement(antd.Dropdown, { key: _action.label, menu: {
1429
+ items: ((_a = _action.children) !== null && _a !== void 0 ? _a : []).map(function (child) { return ({
1430
+ key: child.label,
1431
+ label: child.label,
1432
+ onClick: function () {
1433
+ var _a;
1434
+ return (_a = child.onClick) === null || _a === void 0 ? void 0 : _a.call(child, deriveKeyOfRow(row, deriveRowKey(data, rowKey)), row);
1435
+ },
1436
+ }); }),
1437
+ } },
1438
+ React__default.default.createElement("a", { href: "javascript: void 0", style: {
1439
+ whiteSpace: "nowrap",
1440
+ } }, _action.label)));
1441
+ }
1442
+ });
1443
+ }
1444
+
1445
+ // In this code, ColumnConfigs are Plasmic, while ColumnDefinitions are Ant.
1446
+ function RichTable(props) {
1447
+ var className = props.className, _a = props.data, rawData = _a === void 0 ? {
1448
+ data: [],
1449
+ schema: {
1450
+ id: "inferred",
1451
+ fields: [
1452
+ {
1453
+ id: "id",
1454
+ type: "string",
1455
+ readOnly: false,
1456
+ },
1457
+ ],
1458
+ },
1459
+ } : _a,
1460
+ // children,
1461
+ _b = props.pagination,
1462
+ // children,
1463
+ 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;
1464
+ var data = normalizeData(rawData);
1465
+ var _f = useColumnDefinitions(data, props), columnDefinitions = _f.columnDefinitions, normalized = _f.normalized;
1466
+ var actionRef = React.useRef();
1467
+ var _g = useSortedFilteredData(data, normalized), finalData = _g.finalData, search = _g.search, setSearch = _g.setSearch, setSortState = _g.setSortState;
1468
+ var rowSelectionProps = useRowSelectionProps(data, props);
1469
+ var isClient = useIsClient();
1470
+ if (!isClient) {
1471
+ return null;
1472
+ }
1473
+ return (React__default.default.createElement("div", { className: "".concat(className, " ").concat(scopeClassName !== null && scopeClassName !== void 0 ? scopeClassName : "") },
1474
+ React__default.default.createElement(proComponents.ProTable, __assign({ rowClassName: props.onRowClick || props.canSelectRows === "click"
1475
+ ? "plasmic-table-row-clickable"
1476
+ : undefined, actionRef: actionRef, columns: columnDefinitions, onChange: function (_pagination, _filters, sorter, _extra) {
1477
+ setSortState({ sorter: sorter });
1478
+ }, style: {
1479
+ width: "100%",
1480
+ }, cardProps: {
1481
+ ghost: true,
1482
+ } }, rowSelectionProps, { dataSource: finalData, rowKey: deriveRowKey(data, rowKey), defaultSize: defaultSize, editable: { type: "multiple" }, search: false, options: {
1483
+ setting: hideColumnPicker
1299
1484
  ? false
1300
1485
  : {
1301
1486
  listsHeight: 400,
@@ -1326,34 +1511,12 @@ function RichTable(props) {
1326
1511
  ].filter(function (x) { return !!x; });
1327
1512
  } })),
1328
1513
  React__default.default.createElement("style", { dangerouslySetInnerHTML: {
1329
- __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 :where(.plasmic-table-row-clickable) {\n cursor: pointer;\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
1514
+ __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 .plasmic-table-row-clickable {\n cursor: pointer;\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
1330
1515
  ? "\n .".concat(scopeClassName, " .ant-pro-table-alert {\n display: none;\n }\n ")
1331
1516
  : "", "\n "),
1332
1517
  } })));
1333
1518
  }
1334
- function deriveRowKey(data, rowKey) {
1335
- var _a;
1336
- if (rowKey) {
1337
- return rowKey;
1338
- }
1339
- var schema = data === null || data === void 0 ? void 0 : data.schema;
1340
- if (schema) {
1341
- return (_a = schema.fields[0]) === null || _a === void 0 ? void 0 : _a.id;
1342
- }
1343
- return undefined;
1344
- }
1345
- function deriveKeyOfRow(row, rowKey) {
1346
- if (typeof rowKey === "function") {
1347
- return rowKey(row);
1348
- }
1349
- else if (typeof rowKey === "string") {
1350
- return row[rowKey];
1351
- }
1352
- else {
1353
- return undefined;
1354
- }
1355
- }
1356
- var defaultColumnConfig = function () {
1519
+ var defaultColumnConfig$1 = function () {
1357
1520
  return ({
1358
1521
  key: mkShortId(),
1359
1522
  isEditableExpr: function () { return false; },
@@ -1375,7 +1538,7 @@ function useColumnDefinitions(data, props) {
1375
1538
  if (!data || !schema) {
1376
1539
  return { normalized: [], columnDefinitions: [] };
1377
1540
  }
1378
- var _a = deriveFieldConfigs(fields !== null && fields !== void 0 ? fields : [], schema, function (field) { return (__assign(__assign({}, defaultColumnConfig()), (field && {
1541
+ var _a = deriveFieldConfigs(fields !== null && fields !== void 0 ? fields : [], schema, function (field) { return (__assign(__assign({}, defaultColumnConfig$1()), (field && {
1379
1542
  key: field.id,
1380
1543
  fieldId: field.id,
1381
1544
  title: field.label || field.id,
@@ -1410,14 +1573,12 @@ function useColumnDefinitions(data, props) {
1410
1573
  return defaultRender(_);
1411
1574
  },
1412
1575
  render: function (value, record, rowIndex) {
1413
- var cellValue = cconfig.fieldId
1414
- ? record[cconfig.fieldId]
1415
- : undefined;
1416
- return renderValue(cellValue, record, cconfig);
1576
+ return renderValue(record, cconfig);
1417
1577
  },
1418
1578
  };
1419
1579
  return columnDefinition;
1420
1580
  });
1581
+ var rowKey = props.rowKey;
1421
1582
  if (rowActions && rowActions.length > 0) {
1422
1583
  columnDefinitions.push({
1423
1584
  title: "Actions",
@@ -1425,70 +1586,12 @@ function useColumnDefinitions(data, props) {
1425
1586
  key: "__plasmicActions",
1426
1587
  fixed: "right",
1427
1588
  className: props.themeResetClassName,
1428
- render: function (_text, row) { return __spreadArray([], rowActions.map(function (_action) {
1429
- var _a;
1430
- if (_action.type === "item") {
1431
- return (React__default.default.createElement("a", { key: _action.label, style: {
1432
- whiteSpace: "nowrap",
1433
- }, onClick: function () {
1434
- var _a;
1435
- return (_a = _action.onClick) === null || _a === void 0 ? void 0 : _a.call(_action, deriveKeyOfRow(row, deriveRowKey(data, props.rowKey)), row);
1436
- } }, _action.label));
1437
- }
1438
- else {
1439
- return (React__default.default.createElement(proComponents.TableDropdown, { key: _action.label, style: {
1440
- whiteSpace: "nowrap",
1441
- }, menus: ((_a = _action.children) !== null && _a !== void 0 ? _a : []).map(function (child) { return ({
1442
- key: child.label,
1443
- name: child.label,
1444
- onClick: function () {
1445
- var _a;
1446
- return (_a = child.onClick) === null || _a === void 0 ? void 0 : _a.call(child, deriveKeyOfRow(row, deriveRowKey(data, props.rowKey)), row);
1447
- },
1448
- }); }) }, _action.label));
1449
- }
1450
- }), true); },
1589
+ render: function (_text, row) { return __spreadArray([], renderActions(rowActions, row, data, rowKey), true); },
1451
1590
  });
1452
1591
  }
1453
1592
  return { normalized: normalized, columnDefinitions: columnDefinitions };
1454
1593
  }, [fields, data, setControlContextData, rowActions]);
1455
1594
  }
1456
- function useSortedFilteredData(data, columns) {
1457
- var _a = React.useState(""), search = _a[0], setSearch = _a[1];
1458
- var _b = React.useState(undefined), sortState = _b[0], setSortState = _b[1];
1459
- var finalData = React__default.default.useMemo(function () {
1460
- var _a;
1461
- var filtered = (_a = data === null || data === void 0 ? void 0 : data.data) === null || _a === void 0 ? void 0 : _a.filter(function (row) {
1462
- return fastStringify__default.default(Object.values(row)).toLowerCase().includes(search);
1463
- });
1464
- var sorted = (sortState === null || sortState === void 0 ? void 0 : sortState.sorter.column)
1465
- ? // We use .sort() rather than sortBy to use localeCompare
1466
- (function () {
1467
- var _a;
1468
- var cconfig = columns.find(function (cc) { var _a; return cc.key === ((_a = sortState === null || sortState === void 0 ? void 0 : sortState.sorter.column) === null || _a === void 0 ? void 0 : _a.key); });
1469
- var expr = (_a = cconfig.expr) !== null && _a !== void 0 ? _a : (function (x) { return x; });
1470
- return (filtered !== null && filtered !== void 0 ? filtered : []).sort(function (aa, bb) {
1471
- var _a, _b;
1472
- var a = (_a = expr(aa, cconfig.fieldId ? aa === null || aa === void 0 ? void 0 : aa[cconfig.fieldId] : null)) !== null && _a !== void 0 ? _a : null, b = (_b = expr(bb, cconfig.fieldId ? bb === null || bb === void 0 ? void 0 : bb[cconfig.fieldId] : null)) !== null && _b !== void 0 ? _b : null;
1473
- // Default nil to '' here because A < null < z which is weird.
1474
- return typeof a === "string"
1475
- ? a.localeCompare(b !== null && b !== void 0 ? b : "")
1476
- : typeof b === "string"
1477
- ? -b.localeCompare(a !== null && a !== void 0 ? a : "")
1478
- : a - b;
1479
- });
1480
- })()
1481
- : filtered;
1482
- var reversed = (sortState === null || sortState === void 0 ? void 0 : sortState.sorter.order) === "descend" ? sorted === null || sorted === void 0 ? void 0 : sorted.reverse() : sorted;
1483
- return reversed;
1484
- }, [data, columns, sortState, search]);
1485
- return {
1486
- finalData: finalData,
1487
- search: search,
1488
- setSearch: setSearch,
1489
- setSortState: setSortState,
1490
- };
1491
- }
1492
1595
  function useRowSelectionProps(data, props) {
1493
1596
  var canSelectRows = props.canSelectRows, selectedRowKey = props.selectedRowKey, onRowSelectionChanged = props.onRowSelectionChanged, rowKey = props.rowKey, onRowClick = props.onRowClick;
1494
1597
  var deriveSelectedRowKeys = function () {
@@ -1528,16 +1631,9 @@ function useRowSelectionProps(data, props) {
1528
1631
  onRow: function (row) { return ({
1529
1632
  onClick: function (event) {
1530
1633
  var key = deriveKeyOfRow(row, deriveRowKey(data, rowKey));
1531
- if (key != null) {
1634
+ if (key != null && !isInteractable(event.target)) {
1532
1635
  if (canSelectRows === "click") {
1533
- // Some heuristics to avoid selecting a row when
1534
- // the object clicked is interactable -- like button, anchor,
1535
- // input, etc. This won't be bulletproof, so just some
1536
- // heuristics!
1537
- var target = event.target;
1538
- if (!isInteractable(target)) {
1539
- onRowSelectionChanged === null || onRowSelectionChanged === void 0 ? void 0 : onRowSelectionChanged([key], [row]);
1540
- }
1636
+ onRowSelectionChanged === null || onRowSelectionChanged === void 0 ? void 0 : onRowSelectionChanged([key], [row]);
1541
1637
  }
1542
1638
  onRowClick === null || onRowClick === void 0 ? void 0 : onRowClick(key, row, event);
1543
1639
  }
@@ -1545,15 +1641,6 @@ function useRowSelectionProps(data, props) {
1545
1641
  }); },
1546
1642
  };
1547
1643
  }
1548
- function isInteractable(target) {
1549
- if (["A", "BUTTON", "INPUT", "TEXTAREA", "SELECT"].includes(target.tagName)) {
1550
- return true;
1551
- }
1552
- if (target.contentEditable === "true") {
1553
- return true;
1554
- }
1555
- return false;
1556
- }
1557
1644
  function ExportMenu(props) {
1558
1645
  var _this = this;
1559
1646
  var data = props.data;
@@ -1617,6 +1704,101 @@ function ExportMenu(props) {
1617
1704
  React__default.default.createElement(icons.EllipsisOutlined, null))));
1618
1705
  }
1619
1706
 
1707
+ function dataProp() {
1708
+ return {
1709
+ type: "dataSourceOpData",
1710
+ description: "The data to display",
1711
+ };
1712
+ }
1713
+ function commonProps() {
1714
+ return {
1715
+ pagination: {
1716
+ type: "boolean",
1717
+ advanced: true,
1718
+ defaultValueHint: true,
1719
+ },
1720
+ pageSize: {
1721
+ type: "number",
1722
+ defaultValueHint: 10,
1723
+ advanced: true,
1724
+ },
1725
+ hideSearch: {
1726
+ type: "boolean",
1727
+ description: "Hides the search toolbar",
1728
+ advanced: true,
1729
+ },
1730
+ };
1731
+ }
1732
+ function rowActionsProp() {
1733
+ return {
1734
+ type: "array",
1735
+ displayName: "Row actions",
1736
+ advanced: true,
1737
+ itemType: {
1738
+ type: "object",
1739
+ nameFunc: function (item) { return item.label; },
1740
+ fields: {
1741
+ type: {
1742
+ type: "choice",
1743
+ options: ["item", "menu"],
1744
+ defaultValue: "item",
1745
+ },
1746
+ label: {
1747
+ type: "string",
1748
+ displayName: "Action label",
1749
+ },
1750
+ children: {
1751
+ type: "array",
1752
+ displayName: "Menu items",
1753
+ itemType: {
1754
+ type: "object",
1755
+ fields: {
1756
+ label: {
1757
+ type: "string",
1758
+ displayName: "Action label",
1759
+ },
1760
+ onClick: {
1761
+ type: "eventHandler",
1762
+ argTypes: [
1763
+ { name: "rowKey", type: "string" },
1764
+ { name: "row", type: "object" },
1765
+ ],
1766
+ },
1767
+ },
1768
+ },
1769
+ hidden: function (_ps, _ctx, _a) {
1770
+ var item = _a.item;
1771
+ return item.type !== "menu";
1772
+ },
1773
+ },
1774
+ onClick: {
1775
+ type: "eventHandler",
1776
+ displayName: "Action",
1777
+ argTypes: [
1778
+ { name: "rowKey", type: "string" },
1779
+ { name: "row", type: "object" },
1780
+ ],
1781
+ hidden: function (_ps, _ctx, _a) {
1782
+ var item = _a.item;
1783
+ return item.type !== "item";
1784
+ },
1785
+ },
1786
+ },
1787
+ },
1788
+ };
1789
+ }
1790
+ function onRowClickProp() {
1791
+ return {
1792
+ type: "eventHandler",
1793
+ displayName: "On row clicked",
1794
+ argTypes: [
1795
+ { name: "rowKey", type: "string" },
1796
+ { name: "row", type: "object" },
1797
+ { name: "event", type: "object" },
1798
+ ],
1799
+ };
1800
+ }
1801
+
1620
1802
  var tableHelpers = {
1621
1803
  states: {
1622
1804
  selectedRow: {
@@ -1644,13 +1826,7 @@ var dataTableMeta = {
1644
1826
  padding: "16px",
1645
1827
  maxHeight: "100%",
1646
1828
  },
1647
- props: {
1648
- data: {
1649
- type: "dataSourceOpData",
1650
- description: "The data to display in the table",
1651
- },
1652
- fields: buildFieldsPropType({}),
1653
- canSelectRows: {
1829
+ props: __assign(__assign({ data: dataProp(), fields: buildFieldsPropType({}), canSelectRows: {
1654
1830
  type: "choice",
1655
1831
  displayName: "Select rows?",
1656
1832
  options: [
@@ -1661,8 +1837,7 @@ var dataTableMeta = {
1661
1837
  ],
1662
1838
  defaultValueHint: "none",
1663
1839
  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.",
1664
- },
1665
- rowKey: {
1840
+ }, rowKey: {
1666
1841
  type: "string",
1667
1842
  displayName: "Row key",
1668
1843
  helpText: "Column key to use as row key; can also be a function that takes in a row and returns a key value",
@@ -1671,93 +1846,24 @@ var dataTableMeta = {
1671
1846
  var derivedRowKey = deriveRowKey(ps.data, ps.rowKey);
1672
1847
  return derivedRowKey !== undefined ? "".concat(derivedRowKey) : undefined;
1673
1848
  },
1674
- },
1675
- selectedRowKey: {
1849
+ }, selectedRowKey: {
1676
1850
  type: "string",
1677
1851
  displayName: "Selected Row Key",
1678
1852
  hidden: function (ps) { return ps.canSelectRows !== "single"; },
1679
1853
  advanced: true,
1680
- },
1681
- selectedRowKeys: {
1854
+ }, selectedRowKeys: {
1682
1855
  type: "array",
1683
1856
  displayName: "Selected Row Keys",
1684
1857
  hidden: function (ps) { return ps.canSelectRows !== "multiple"; },
1685
1858
  advanced: true,
1686
- },
1687
- onRowSelectionChanged: {
1859
+ }, onRowSelectionChanged: {
1688
1860
  type: "eventHandler",
1689
1861
  displayName: "On row selection changed",
1690
1862
  argTypes: [
1691
1863
  { name: "rowKeys", type: "object" },
1692
1864
  { name: "rows", type: "object" },
1693
1865
  ],
1694
- },
1695
- onRowClick: {
1696
- type: "eventHandler",
1697
- displayName: "On row clicked",
1698
- argTypes: [
1699
- { name: "rowKey", type: "string" },
1700
- { name: "row", type: "object" },
1701
- { name: "event", type: "object" },
1702
- ],
1703
- },
1704
- rowActions: {
1705
- type: "array",
1706
- displayName: "Row actions",
1707
- advanced: true,
1708
- itemType: {
1709
- type: "object",
1710
- nameFunc: function (item) { return item.label; },
1711
- fields: {
1712
- type: {
1713
- type: "choice",
1714
- options: ["item", "menu"],
1715
- defaultValue: "item",
1716
- },
1717
- label: {
1718
- type: "string",
1719
- displayName: "Action label",
1720
- },
1721
- children: {
1722
- type: "array",
1723
- displayName: "Menu items",
1724
- itemType: {
1725
- type: "object",
1726
- fields: {
1727
- label: {
1728
- type: "string",
1729
- displayName: "Action label",
1730
- },
1731
- onClick: {
1732
- type: "eventHandler",
1733
- argTypes: [
1734
- { name: "rowKey", type: "string" },
1735
- { name: "row", type: "object" },
1736
- ],
1737
- },
1738
- },
1739
- },
1740
- hidden: function (ps, ctx, _a) {
1741
- var item = _a.item;
1742
- return item.type !== "menu";
1743
- },
1744
- },
1745
- onClick: {
1746
- type: "eventHandler",
1747
- displayName: "Action",
1748
- argTypes: [
1749
- { name: "rowKey", type: "string" },
1750
- { name: "row", type: "object" },
1751
- ],
1752
- hidden: function (ps, ctx, _a) {
1753
- var item = _a.item;
1754
- return item.type !== "item";
1755
- },
1756
- },
1757
- },
1758
- },
1759
- },
1760
- defaultSize: {
1866
+ }, onRowClick: onRowClickProp(), rowActions: rowActionsProp(), defaultSize: {
1761
1867
  displayName: "Density",
1762
1868
  type: "choice",
1763
1869
  options: [
@@ -1776,54 +1882,32 @@ var dataTableMeta = {
1776
1882
  ],
1777
1883
  defaultValueHint: "large",
1778
1884
  advanced: true,
1779
- },
1780
- pageSize: {
1781
- type: "number",
1782
- defaultValueHint: 10,
1783
- advanced: true,
1784
- },
1785
- pagination: {
1786
- type: "boolean",
1787
- advanced: true,
1788
- defaultValueHint: true,
1789
- },
1790
- hideSearch: {
1791
- type: "boolean",
1792
- description: "Hides the search toolbar",
1793
- advanced: true,
1794
- },
1795
- hideExports: {
1885
+ } }, commonProps()), { hideExports: {
1796
1886
  type: "boolean",
1797
1887
  description: "Hides the button for exporting table data to CSV",
1798
1888
  advanced: true,
1799
- },
1800
- hideDensity: {
1889
+ }, hideDensity: {
1801
1890
  type: "boolean",
1802
1891
  description: "Hides the control for changing the density of the table",
1803
1892
  advanced: true,
1804
1893
  defaultValueHint: true,
1805
- },
1806
- hideColumnPicker: {
1894
+ }, hideColumnPicker: {
1807
1895
  type: "boolean",
1808
1896
  description: "Hides the control for reordering and pinning columns",
1809
1897
  advanced: true,
1810
- },
1811
- hideSelectionBar: {
1898
+ }, hideSelectionBar: {
1812
1899
  type: "boolean",
1813
1900
  description: "Hides the toolbar that allows the user to clear selection",
1814
1901
  advanced: true,
1815
1902
  hidden: function (ps) { return !ps.canSelectRows || ps.canSelectRows === "none"; },
1816
1903
  defaultValueHint: true,
1817
- },
1818
- scopeClassName: {
1904
+ }, scopeClassName: {
1819
1905
  type: "styleScopeClass",
1820
1906
  scopeName: "instance",
1821
- },
1822
- themeResetClassName: {
1907
+ }, themeResetClassName: {
1823
1908
  type: "themeResetClass",
1824
1909
  targetAllTags: true,
1825
- },
1826
- },
1910
+ } }),
1827
1911
  states: {
1828
1912
  selectedRowKey: __assign({ type: "writable", valueProp: "selectedRowKey", onChangeProp: "onRowSelectionChanged", variableType: "text" }, tableHelpers.states.selectedRowKey),
1829
1913
  selectedRow: __assign({ type: "readonly", onChangeProp: "onRowSelectionChanged", variableType: "object" }, tableHelpers.states.selectedRow),
@@ -1841,15 +1925,327 @@ function registerRichTable(loader) {
1841
1925
  registerComponentHelper(loader, RichTable, dataTableMeta);
1842
1926
  }
1843
1927
 
1928
+ // Should really be using token colorFillTertiary instead of #8881.
1929
+ var listCss = "\n.plasmic-list--grid .ant-list-items {\n display: grid;\n grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));\n gap: 16px;\n}\n\n.plasmic-list-search {\n /* Matches RichTable search. */\n max-width: 200px;\n margin-bottom: 8px;\n}\n\n.plasmic-list-item-content--unbordered {\n padding-left: 8px;\n padding-right: 8px;\n}\n\n.plasmic-list-item--clickable:hover {\n background-color: #8881;\n}\n\n.plasmic-list-item-image {\n max-width: 80px;\n max-height: 80px;\n aspect-ratio: 1/1;\n object-fit: cover;\n border-radius: 8px;\n}\n\n/* Unsure why needed, but cards otherwise can be much narrower. */\n.plasmic-list-item-card {\n width: 100%;\n}\n\n.plasmic-list-item-card-cover {\n max-height: 300px;\n aspect-ratio: 1/1;\n object-fit: cover;\n}\n";
1930
+ function RichList(props) {
1931
+ var _a = props.data, rawData = _a === void 0 ? {
1932
+ data: [],
1933
+ schema: {
1934
+ id: "inferred",
1935
+ fields: [
1936
+ {
1937
+ id: "id",
1938
+ type: "string",
1939
+ readOnly: false,
1940
+ },
1941
+ ],
1942
+ },
1943
+ } : _a, _b = props.type, type = _b === void 0 ? "list" : _b, _c = props.bordered, bordered = _c === void 0 ? true : _c, className = props.className, size = props.size, header = props.header, footer = props.footer, _d = props.rowActions, rowActions = _d === void 0 ? [] : _d; props.title; var _e = props.pageSize, pageSize = _e === void 0 ? 10 : _e, hideSearch = props.hideSearch, rowKey = props.rowKey, pagination = props.pagination, onRowClick = props.onRowClick; __rest(props, ["data", "type", "bordered", "className", "size", "header", "footer", "rowActions", "title", "pageSize", "hideSearch", "rowKey", "pagination", "onRowClick"]);
1944
+ var data = normalizeData(rawData);
1945
+ var _f = useRoleDefinitions(data, props), normalized = _f.normalized, roleConfigs = _f.finalRoles;
1946
+ React.useRef();
1947
+ var _g = useSortedFilteredData(data, normalized), finalData = _g.finalData, search = _g.search, setSearch = _g.setSearch; _g.setSortState;
1948
+ var actuallyBordered = type === "list" ? bordered : false;
1949
+ return (React__default.default.createElement("div", { className: className },
1950
+ React__default.default.createElement("style", null, listCss),
1951
+ !hideSearch && (React__default.default.createElement(antd.Input.Search, { className: "plasmic-list-search", onChange: function (e) { return setSearch(e.target.value); }, value: search, placeholder: "Search" })),
1952
+ React__default.default.createElement(antd.List, { className: classNames__default.default({
1953
+ // We use CSS grid instead of the built-in Ant grid which can only define fixed # columns, and only at screen (and not container) breakpoints.
1954
+ "plasmic-list--grid": type === "grid",
1955
+ }), size: size, header: header, footer: footer, dataSource: finalData, itemLayout: "horizontal", bordered: actuallyBordered, pagination: pagination
1956
+ ? {
1957
+ pageSize: pageSize,
1958
+ showSizeChanger: false,
1959
+ }
1960
+ : false, renderItem: function (record, index) {
1961
+ var _a;
1962
+ // Currently, actions are nested inside the list item / card, so can't have both linkTo and actions or else hydration error.
1963
+ // Eventually can fork the Ant components to make the main linkTo area and actions not nest.
1964
+ var actions = renderActions(rowActions, record, data, rowKey);
1965
+ // actions={[
1966
+ // <SettingOutlined key="setting" />,
1967
+ // <EditOutlined key="edit" />,
1968
+ // <EllipsisOutlined key="ellipsis" />,
1969
+ // ]}
1970
+ var image = maybe(maybeRenderString(record, (_a = roleConfigs.image) === null || _a === void 0 ? void 0 : _a[0]), function (src) { return (React__default.default.createElement("img", { src: src, className: type === "list"
1971
+ ? "plasmic-list-item-image"
1972
+ : "plasmic-list-item-card-cover" })); });
1973
+ var content = (React__default.default.createElement(ListItemContent, { bordered: actuallyBordered, image: type === "list" ? image : undefined, title: multiRenderValue(record, roleConfigs.title), subtitle: multiRenderValue(record, roleConfigs.subtitle), beforeTitle: multiRenderValue(record, roleConfigs.beforeTitle), afterTitle: multiRenderValue(record, roleConfigs.afterTitle), content: multiRenderValue(record, roleConfigs.content) }));
1974
+ function makeLinkWrapper() {
1975
+ var _a;
1976
+ if ((actions !== null && actions !== void 0 ? actions : []).length > 0)
1977
+ return undefined;
1978
+ var href = maybeRenderString(record, (_a = roleConfigs.linkTo) === null || _a === void 0 ? void 0 : _a[0]);
1979
+ if (!href && !onRowClick)
1980
+ return undefined;
1981
+ var _linkWrapper = function (x) { return (React__default.default.createElement("a", { href: href, onClick: function (event) {
1982
+ var key = deriveKeyOfRow(record, deriveRowKey(data, rowKey));
1983
+ if (key != null &&
1984
+ !isInteractable(event.target)) {
1985
+ onRowClick === null || onRowClick === void 0 ? void 0 : onRowClick(key, record, event);
1986
+ }
1987
+ } }, x)); };
1988
+ return _linkWrapper;
1989
+ }
1990
+ var linkWrapper = makeLinkWrapper();
1991
+ var hasLink = !!linkWrapper;
1992
+ function maybeLink(x) {
1993
+ var _a;
1994
+ return (_a = linkWrapper === null || linkWrapper === void 0 ? void 0 : linkWrapper(x)) !== null && _a !== void 0 ? _a : x;
1995
+ }
1996
+ return type === "grid" ? (React__default.default.createElement(antd.List.Item, null, maybeLink(React__default.default.createElement(antd.Card, { className: "plasmic-list-item-card", size: "small", cover: image, hoverable: hasLink, actions: actions }, content)))) : (maybeLink(React__default.default.createElement(antd.List.Item, { actions: actions, className: classNames__default.default({
1997
+ "plasmic-list-item--clickable": hasLink,
1998
+ }) }, content)));
1999
+ } })));
2000
+ }
2001
+ function ListItemContent(_a) {
2002
+ var className = _a.className, title = _a.title, subtitle = _a.subtitle, image = _a.image, beforeTitle = _a.beforeTitle, afterTitle = _a.afterTitle, content = _a.content, bordered = _a.bordered, others = __rest(_a, ["className", "title", "subtitle", "image", "beforeTitle", "afterTitle", "content", "bordered"]);
2003
+ var prefixCls = "ant-list";
2004
+ var classString = classNames__default.default("".concat(prefixCls, "-item-meta"), className);
2005
+ return (React__default.default.createElement("div", __assign({}, others, { className: classNames__default.default({
2006
+ "plasmic-list-item-content--unbordered": !bordered,
2007
+ }, classString) }),
2008
+ image && React__default.default.createElement("div", { className: "".concat(prefixCls, "-item-meta-avatar") }, image),
2009
+ React__default.default.createElement("div", { className: "".concat(prefixCls, "-item-meta-content"), style: { display: "flex", flexDirection: "column", gap: 4 } },
2010
+ beforeTitle && (React__default.default.createElement("div", null,
2011
+ React__default.default.createElement(antd.Tag, null, beforeTitle))),
2012
+ React__default.default.createElement("div", { style: { display: "flex", gap: 8 } },
2013
+ title && (React__default.default.createElement("h4", { className: "".concat(prefixCls, "-item-meta-title"), style: { margin: 0 } }, title)),
2014
+ afterTitle && (React__default.default.createElement("div", { className: "".concat(prefixCls, "-item-meta-description") }, afterTitle))),
2015
+ subtitle && (React__default.default.createElement("div", { className: "".concat(prefixCls, "-item-meta-description") }, subtitle)),
2016
+ content && React__default.default.createElement("div", null, content))));
2017
+ }
2018
+ var defaultColumnConfig = function () {
2019
+ return ({
2020
+ key: mkShortId(),
2021
+ isEditableExpr: function () { return false; },
2022
+ disableSorting: false,
2023
+ sortByExpr: undefined,
2024
+ isHidden: false,
2025
+ formatting: {
2026
+ styles: {},
2027
+ align: "left",
2028
+ freeze: "off",
2029
+ },
2030
+ dataType: "auto",
2031
+ role: undefined,
2032
+ });
2033
+ };
2034
+ var roles = [
2035
+ "linkTo",
2036
+ "content",
2037
+ "title",
2038
+ "subtitle",
2039
+ "beforeTitle",
2040
+ "afterTitle",
2041
+ "image",
2042
+ "unset",
2043
+ ];
2044
+ // This component is different from Table/Details since it has various different roles, so the UX is one of setting the choices for each role rather than a single list of fields.
2045
+ //
2046
+ // We first infer the defaults for each role.
2047
+ // This we always need to do because we want the choices to be 'stable'.
2048
+ // If the user sets one of the roles, without setting the others, we don't want to shift things around on the other roles as a result.
2049
+ // So the defaults need to always be there (they would only be irrelevant if all roles that would have had defaults were set/overridden by the user).
2050
+ //
2051
+ // Then, we layer on the user role choices.
2052
+ //
2053
+ // One UX wart is that unsetting a role will restore the default selection instead of clearing it.
2054
+ // User must know to actually set fieldId to none or (for arrays) remove the item.
2055
+ // Just another reason to fill in few roles by default.
2056
+ function useRoleDefinitions(data, props) {
2057
+ var fields = props.fields, setControlContextData = props.setControlContextData, rowActions = props.rowActions;
2058
+ return React__default.default.useMemo(function () {
2059
+ var _a, _b, _c, _d;
2060
+ var schema = data === null || data === void 0 ? void 0 : data.schema;
2061
+ var schemaMap = new Map((_a = data === null || data === void 0 ? void 0 : data.schema) === null || _a === void 0 ? void 0 : _a.fields.map(function (f) { return [f.id, f]; }));
2062
+ if (!data || !schema) {
2063
+ return { normalized: [], roleConfigs: {}, finalRoles: {} };
2064
+ }
2065
+ function tagFieldConfigs(role) {
2066
+ var _a;
2067
+ if (role !== "unset") {
2068
+ return ensureArray((_a = props[role]) !== null && _a !== void 0 ? _a : []).map(function (field) {
2069
+ return __assign(__assign({}, field), { role: role });
2070
+ });
2071
+ }
2072
+ else {
2073
+ return [];
2074
+ }
2075
+ }
2076
+ // This is only being computed to get the default role choices.
2077
+ var _e = deriveFieldConfigs(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], tagFieldConfigs("image"), true), tagFieldConfigs("content"), true), tagFieldConfigs("title"), true), tagFieldConfigs("beforeTitle"), true), tagFieldConfigs("afterTitle"), true), tagFieldConfigs("subtitle"), true), tagFieldConfigs("linkTo"), true), schema, function (field) { return (__assign(__assign({}, defaultColumnConfig()), (field && {
2078
+ key: field.id,
2079
+ fieldId: field.id,
2080
+ title: field.label || field.id,
2081
+ // undefined means not yet determined in this routine, not 'unset'
2082
+ role: undefined,
2083
+ expr: function (currentItem) { return currentItem[field.id]; },
2084
+ }))); }), mergedFields = _e.mergedFields, minimalFullLengthFields = _e.minimalFullLengthFields;
2085
+ var normalized = mergedFields;
2086
+ // Find a good default image field.
2087
+ // Filter mergedFields where there are mostly values (in the sampleRows) that are a string that looks like a URL or path to an image file.
2088
+ // Of these, prefer the one with a name like image, picture, pic, img, avatar, profile, photo, icon.
2089
+ // Otherwise, prefer the one with a title with that substring.
2090
+ // Otherwise, pick any remaining one.
2091
+ if (data.data.length > 0 &&
2092
+ !mergedFields.some(function (field) { return field.role === "image"; })) {
2093
+ var sampleRows_1 = Array.from(new Set([0, 1, 2, 3, 4, 5, 6, 7, 8, 9].map(function (i) {
2094
+ return Math.round((i / 9) * (data.data.length - 1));
2095
+ }))).map(function (i) { return data.data[i]; });
2096
+ var imageFieldCandidates = mergedFields.filter(function (field) {
2097
+ return !field.role &&
2098
+ sampleRows_1.filter(function (row) { return field.fieldId && isLikeImage(row[field.fieldId]); }).length >=
2099
+ sampleRows_1.length / 2;
2100
+ });
2101
+ var imageField = (_c = (_b = imageFieldCandidates.find(function (f) {
2102
+ var _a;
2103
+ return (_a = f.fieldId) === null || _a === void 0 ? void 0 : _a.match(/^(image|picture|pic|img|avatar|profile|photo|icon)$/i);
2104
+ })) !== null && _b !== void 0 ? _b : imageFieldCandidates.find(function (f) {
2105
+ var _a;
2106
+ return (_a = f.fieldId) === null || _a === void 0 ? void 0 : _a.match(/.*(image|picture|pic|img|avatar|profile|photo|icon).*/i);
2107
+ })) !== null && _c !== void 0 ? _c : imageFieldCandidates[0];
2108
+ if (imageField) {
2109
+ imageField.role = "image";
2110
+ }
2111
+ }
2112
+ // Find a good default title field, just based on the field name.
2113
+ if (!mergedFields.some(function (field) { return field.role === "title"; })) {
2114
+ var titleField = mergedFields.find(function (field) {
2115
+ var _a;
2116
+ return !field.role &&
2117
+ ((_a = field.fieldId) === null || _a === void 0 ? void 0 : _a.toLowerCase().match(/^(title|name|first[ _-]?name|full[ _-]?name)$/));
2118
+ });
2119
+ if (titleField) {
2120
+ titleField.role = "title";
2121
+ }
2122
+ }
2123
+ // Find a good default content field - just any remaining text field.
2124
+ if (!mergedFields.some(function (field) { return field.role === "content"; })) {
2125
+ var contentField = mergedFields.find(function (field) {
2126
+ var _a;
2127
+ return !field.role &&
2128
+ field.fieldId &&
2129
+ ((_a = schemaMap.get(field.fieldId)) === null || _a === void 0 ? void 0 : _a.type) === "string";
2130
+ });
2131
+ if (contentField) {
2132
+ contentField.role = "content";
2133
+ }
2134
+ }
2135
+ var roleConfigs = ensure(lodash.groupBy(mergedFields, function (f) { return f.role; }));
2136
+ var finalRoles = {};
2137
+ for (var _i = 0, roles_1 = roles; _i < roles_1.length; _i++) {
2138
+ var role = roles_1[_i];
2139
+ if (role !== "unset") {
2140
+ finalRoles[role] = (_d = maybe(props[role], ensureArray)) !== null && _d !== void 0 ? _d : roleConfigs[role];
2141
+ }
2142
+ }
2143
+ var fieldIdToRole = new Map(mergedFields.map(function (f) { return [f.fieldId, f.role]; }));
2144
+ for (var _f = 0, minimalFullLengthFields_1 = minimalFullLengthFields; _f < minimalFullLengthFields_1.length; _f++) {
2145
+ var f = minimalFullLengthFields_1[_f];
2146
+ f.role = fieldIdToRole.get(f.fieldId);
2147
+ }
2148
+ setControlContextData === null || setControlContextData === void 0 ? void 0 : setControlContextData(__assign(__assign({}, data), { mergedFields: mergedFields, minimalFullLengthFields: minimalFullLengthFields }));
2149
+ return { normalized: normalized, roleConfigs: roleConfigs, finalRoles: finalRoles };
2150
+ }, [fields, data, setControlContextData, rowActions]);
2151
+ }
2152
+
2153
+ function roleProp(_a) {
2154
+ var role = _a.role, _b = _a.singular, singular = _b === void 0 ? false : _b, _c = _a.advanced, advanced = _c === void 0 ? false : _c, displayName = _a.displayName;
2155
+ return singular
2156
+ ? {
2157
+ type: "object",
2158
+ displayName: displayName,
2159
+ advanced: advanced,
2160
+ hidden: function (ps) { return !ps.data; },
2161
+ nameFunc: function (item) {
2162
+ return maybe(item, function (i) {
2163
+ return i.isHidden ? "Hidden" : i.fieldId || "Custom value";
2164
+ });
2165
+ },
2166
+ fields: getFieldSubprops({
2167
+ canChangeField: true,
2168
+ noTitle: true,
2169
+ }),
2170
+ defaultValueHint: function (_props, contextData) {
2171
+ var _a;
2172
+ return ((_a = contextData === null || contextData === void 0 ? void 0 : contextData.minimalFullLengthFields) !== null && _a !== void 0 ? _a : []).find(function (f) { return f.role === role; });
2173
+ },
2174
+ }
2175
+ : buildFieldsPropType({
2176
+ displayName: displayName,
2177
+ advanced: advanced,
2178
+ noTitle: true,
2179
+ canChangeField: true,
2180
+ minimalValue: function (_props, contextData) {
2181
+ var _a;
2182
+ return ((_a = contextData === null || contextData === void 0 ? void 0 : contextData.minimalFullLengthFields) !== null && _a !== void 0 ? _a : []).filter(function (f) { return f.role === role; });
2183
+ },
2184
+ });
2185
+ }
2186
+ var richListMeta = {
2187
+ name: "hostless-rich-list",
2188
+ displayName: "Data List",
2189
+ defaultStyles: {
2190
+ width: "stretch",
2191
+ padding: "16px",
2192
+ maxHeight: "100%",
2193
+ },
2194
+ props: __assign({ data: dataProp(), type: {
2195
+ type: "choice",
2196
+ options: [
2197
+ { value: "list", label: "List" },
2198
+ { value: "grid", label: "Grid" },
2199
+ ],
2200
+ defaultValueHint: "list",
2201
+ }, header: {
2202
+ type: "slot",
2203
+ hidePlaceholder: true,
2204
+ }, footer: {
2205
+ type: "slot",
2206
+ hidePlaceholder: true,
2207
+ }, title: roleProp({ role: "title" }), content: roleProp({ role: "content" }), image: roleProp({ role: "image", singular: true }), linkTo: roleProp({ role: "linkTo", singular: true }), subtitle: roleProp({
2208
+ role: "subtitle",
2209
+ displayName: "Subtitle",
2210
+ advanced: true,
2211
+ }),
2212
+ // Haven't styled these yet!
2213
+ // beforeTitle: roleProp({ role: "beforeTitle", advanced: true }),
2214
+ // afterTitle: roleProp({ role: "afterTitle", advanced: true }),
2215
+ onRowClick: onRowClickProp(), rowActions: rowActionsProp(), bordered: {
2216
+ type: "boolean",
2217
+ defaultValue: true,
2218
+ hidden: function (ps) { var _a; return ((_a = ps.type) !== null && _a !== void 0 ? _a : "list") !== "list"; },
2219
+ } }, commonProps()),
2220
+ importName: "RichList",
2221
+ importPath: "@plasmicpkgs/plasmic-rich-components",
2222
+ };
2223
+ function registerRichList(loader) {
2224
+ registerComponentHelper(loader, RichList, richListMeta);
2225
+ }
2226
+
1844
2227
  function registerAll(loader) {
1845
2228
  registerRichLayout(loader);
2229
+ registerRichList(loader);
1846
2230
  registerRichTable(loader);
1847
2231
  registerRichDetails(loader);
1848
2232
  }
1849
2233
 
1850
2234
  exports.RichDetails = RichDetails;
1851
2235
  exports.RichLayout = RichLayout;
2236
+ exports.RichList = RichList;
1852
2237
  exports.RichTable = RichTable;
2238
+ exports.commonProps = commonProps;
2239
+ exports.dataProp = dataProp;
2240
+ exports.deriveKeyOfRow = deriveKeyOfRow;
2241
+ exports.deriveRowKey = deriveRowKey;
2242
+ exports.ensureArray = ensureArray;
2243
+ exports.isInteractable = isInteractable;
2244
+ exports.isLikeImage = isLikeImage;
2245
+ exports.onRowClickProp = onRowClickProp;
1853
2246
  exports.registerAll = registerAll;
2247
+ exports.renderActions = renderActions;
2248
+ exports.rowActionsProp = rowActionsProp;
1854
2249
  exports.tableHelpers = tableHelpers;
2250
+ exports.useSortedFilteredData = useSortedFilteredData;
1855
2251
  //# sourceMappingURL=index.js.map