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