@plasmicpkgs/plasmic-rich-components 1.0.99 → 1.0.101

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.
@@ -3,7 +3,7 @@ import '@plasmicapp/host/registerGlobalContext';
3
3
  import 'lodash/get';
4
4
  import React, { useState, useEffect, useRef } from 'react';
5
5
  import { normalizeData, deriveFieldConfigs } from '@plasmicapp/data-sources';
6
- import { Checkbox, Switch, Empty, Descriptions, theme, ConfigProvider, Dropdown, Button, Input, List, Card, Tag } from 'antd';
6
+ import { Checkbox, Switch, Empty, Descriptions, theme, ConfigProvider, Dropdown, Button, Input, List, Tag, Card } from 'antd';
7
7
  import { tinycolor } from '@ctrl/tinycolor';
8
8
  import { LogoutOutlined, PlusOutlined, EllipsisOutlined } from '@ant-design/icons';
9
9
  import { ProLayout, ProConfigProvider, ProTable } from '@ant-design/pro-components';
@@ -13,2122 +13,2572 @@ import fastStringify from 'fast-stringify';
13
13
  import classNames from 'classnames';
14
14
  import groupBy from 'lodash/groupBy';
15
15
 
16
- /*! *****************************************************************************
17
- Copyright (c) Microsoft Corporation.
18
-
19
- Permission to use, copy, modify, and/or distribute this software for any
20
- purpose with or without fee is hereby granted.
21
-
22
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
23
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
24
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
25
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
26
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
27
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
28
- PERFORMANCE OF THIS SOFTWARE.
29
- ***************************************************************************** */
30
-
31
- var __assign = function() {
32
- __assign = Object.assign || function __assign(t) {
33
- for (var s, i = 1, n = arguments.length; i < n; i++) {
34
- s = arguments[i];
35
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
36
- }
37
- return t;
38
- };
39
- return __assign.apply(this, arguments);
40
- };
41
-
42
- function __rest(s, e) {
43
- var t = {};
44
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
45
- t[p] = s[p];
46
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
47
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
48
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
49
- t[p[i]] = s[p[i]];
50
- }
51
- return t;
52
- }
53
-
54
- function __awaiter(thisArg, _arguments, P, generator) {
55
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
56
- return new (P || (P = Promise))(function (resolve, reject) {
57
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
58
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
59
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
60
- step((generator = generator.apply(thisArg, _arguments || [])).next());
61
- });
62
- }
63
-
64
- function __generator(thisArg, body) {
65
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
66
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
67
- function verb(n) { return function (v) { return step([n, v]); }; }
68
- function step(op) {
69
- if (f) throw new TypeError("Generator is already executing.");
70
- while (_) try {
71
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
72
- if (y = 0, t) op = [op[0] & 2, t.value];
73
- switch (op[0]) {
74
- case 0: case 1: t = op; break;
75
- case 4: _.label++; return { value: op[1], done: false };
76
- case 5: _.label++; y = op[1]; op = [0]; continue;
77
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
78
- default:
79
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
80
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
81
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
82
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
83
- if (t[2]) _.ops.pop();
84
- _.trys.pop(); continue;
85
- }
86
- op = body.call(thisArg, _);
87
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
88
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
89
- }
90
- }
91
-
92
- function __spreadArray(to, from, pack) {
93
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
94
- if (ar || !(i in from)) {
95
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
96
- ar[i] = from[i];
97
- }
98
- }
99
- return to.concat(ar || Array.prototype.slice.call(from));
100
- }
101
-
102
16
  function registerComponentHelper(loader, component, meta) {
103
- if (loader) {
104
- loader.registerComponent(component, meta);
105
- }
106
- else {
107
- registerComponent(component, meta);
108
- }
17
+ if (loader) {
18
+ loader.registerComponent(component, meta);
19
+ } else {
20
+ registerComponent(component, meta);
21
+ }
109
22
  }
110
23
  function ensure(x) {
111
- if (x === null || x === undefined) {
112
- throw new Error("Expected non-null or non-undefined value");
113
- }
114
- return x;
24
+ if (x === null || x === void 0) {
25
+ throw new Error("Expected non-null or non-undefined value");
26
+ }
27
+ return x;
115
28
  }
116
29
  function isOneOf(elem, arr) {
117
- return arr.includes(elem);
30
+ return arr.includes(elem);
118
31
  }
119
32
  function maybe(x, f) {
120
- if (x === undefined || x === null)
121
- return undefined;
122
- return f(x);
33
+ if (x === void 0 || x === null)
34
+ return void 0;
35
+ return f(x);
123
36
  }
124
37
  function isLikeImage(value) {
125
- return typeof value === "string"
126
- ? value.match(/\.(png|jpg|jpeg|gif|svg|webp|avif|ico|bmp|tiff)$/i)
127
- : false;
128
- }
129
- // Some heuristics to avoid selecting a row when
130
- // the object clicked is interactable -- like button, anchor,
131
- // input, etc. This won't be bulletproof, so just some
132
- // heuristics!
38
+ return typeof value === "string" ? value.match(/\.(png|jpg|jpeg|gif|svg|webp|avif|ico|bmp|tiff)$/i) : false;
39
+ }
133
40
  function isInteractable(target) {
134
- if (["A", "BUTTON", "INPUT", "TEXTAREA", "SELECT"].includes(target.tagName)) {
135
- return true;
136
- }
137
- if (target.contentEditable === "true") {
138
- return true;
139
- }
140
- return false;
41
+ if (["A", "BUTTON", "INPUT", "TEXTAREA", "SELECT"].includes(target.tagName)) {
42
+ return true;
43
+ }
44
+ if (target.contentEditable === "true") {
45
+ return true;
46
+ }
47
+ return false;
141
48
  }
142
49
  function ensureArray(xs) {
143
- return Array.isArray(xs) ? xs : [xs];
50
+ return Array.isArray(xs) ? xs : [xs];
144
51
  }
145
- var mkShortId = function () { return "".concat(Math.random()); };
52
+ const mkShortId = () => `${Math.random()}`;
146
53
  function withoutFalsey(xs) {
147
- return xs.filter(function (x) { return !!x; });
54
+ return xs.filter((x) => !!x);
148
55
  }
149
56
 
150
- var DEFAULT_CURRENCY_SETTINGS = {
151
- dataType: "currency",
152
- currency: "USD",
153
- currencyDisplay: "narrowSymbol",
57
+ var __defProp$9 = Object.defineProperty;
58
+ var __defProps$7 = Object.defineProperties;
59
+ var __getOwnPropDescs$7 = Object.getOwnPropertyDescriptors;
60
+ var __getOwnPropSymbols$9 = Object.getOwnPropertySymbols;
61
+ var __hasOwnProp$9 = Object.prototype.hasOwnProperty;
62
+ var __propIsEnum$9 = Object.prototype.propertyIsEnumerable;
63
+ var __defNormalProp$9 = (obj, key, value) => key in obj ? __defProp$9(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
64
+ var __spreadValues$9 = (a, b) => {
65
+ for (var prop in b || (b = {}))
66
+ if (__hasOwnProp$9.call(b, prop))
67
+ __defNormalProp$9(a, prop, b[prop]);
68
+ if (__getOwnPropSymbols$9)
69
+ for (var prop of __getOwnPropSymbols$9(b)) {
70
+ if (__propIsEnum$9.call(b, prop))
71
+ __defNormalProp$9(a, prop, b[prop]);
72
+ }
73
+ return a;
154
74
  };
155
- var NUMBER_TYPES = ["number", "percent", "currency"];
156
- var DEFAULT_DATETIME_SETTINGS = {
157
- dataType: "datetime",
158
- locale: "en-US",
159
- dateStyle: "short",
160
- timeStyle: "short",
161
- hour12: true,
75
+ var __spreadProps$7 = (a, b) => __defProps$7(a, __getOwnPropDescs$7(b));
76
+ var __objRest$2 = (source, exclude) => {
77
+ var target = {};
78
+ for (var prop in source)
79
+ if (__hasOwnProp$9.call(source, prop) && exclude.indexOf(prop) < 0)
80
+ target[prop] = source[prop];
81
+ if (source != null && __getOwnPropSymbols$9)
82
+ for (var prop of __getOwnPropSymbols$9(source)) {
83
+ if (exclude.indexOf(prop) < 0 && __propIsEnum$9.call(source, prop))
84
+ target[prop] = source[prop];
85
+ }
86
+ return target;
162
87
  };
163
- var DEFAULT_RELATIVE_DATETIME_SETTINGS = {
164
- dataType: "relative-datetime",
165
- locale: "en-US",
166
- numeric: "always",
167
- style: "long",
168
- unit: "day",
88
+ const DEFAULT_CURRENCY_SETTINGS = {
89
+ dataType: "currency",
90
+ currency: "USD",
91
+ currencyDisplay: "narrowSymbol"
169
92
  };
170
- var DATETIME_TYPES = ["datetime", "relative-datetime"];
171
- var DEFAULT_BOOLEAN_SETTINGS = {
172
- dataType: "boolean",
173
- showAs: "checkbox",
93
+ const NUMBER_TYPES = ["number", "percent", "currency"];
94
+ const DEFAULT_DATETIME_SETTINGS = {
95
+ dataType: "datetime",
96
+ locale: "en-US",
97
+ dateStyle: "short",
98
+ timeStyle: "short",
99
+ hour12: true
100
+ };
101
+ const DEFAULT_RELATIVE_DATETIME_SETTINGS = {
102
+ dataType: "relative-datetime",
103
+ locale: "en-US",
104
+ numeric: "always",
105
+ style: "long",
106
+ unit: "day"
107
+ };
108
+ const DATETIME_TYPES = ["datetime", "relative-datetime"];
109
+ const DEFAULT_BOOLEAN_SETTINGS = {
110
+ dataType: "boolean",
111
+ showAs: "checkbox"
174
112
  };
175
113
  function deriveValueType(cconfig) {
176
- return cconfig.dataType === "auto"
177
- ? undefined
178
- : cconfig.dataType === "string"
179
- ? "text"
180
- : cconfig.dataType === "number"
181
- ? "digit"
182
- : cconfig.dataType === "boolean"
183
- ? "switch"
184
- : undefined;
185
- }
186
- // Hacky "unique" string values
187
- var NoneField = "||NoneField||";
188
- var CustomField = "";
114
+ return cconfig.dataType === "auto" ? void 0 : cconfig.dataType === "string" ? "text" : cconfig.dataType === "number" ? "digit" : cconfig.dataType === "boolean" ? "switch" : void 0;
115
+ }
116
+ const NoneField = "||NoneField||";
117
+ const CustomField = "";
189
118
  function getFieldSubprops(opts) {
190
- return __assign(__assign({ key: {
191
- type: "string",
192
- hidden: function () { return true; },
193
- }, fieldId: {
194
- type: "choice",
195
- displayName: "Field name",
196
- readOnly: !opts.canChangeField,
197
- options: function (_props, ctx) {
198
- var _a, _b;
199
- return withoutFalsey(__spreadArray(__spreadArray([
200
- opts.canPickNoneField && { value: NoneField, label: "None" }
201
- ], ((_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) {
202
- var _a;
203
- return ({
204
- value: f.id,
205
- label: (_a = f.label) !== null && _a !== void 0 ? _a : f.id,
206
- });
207
- }), true), [
208
- { value: CustomField, label: "Custom value" },
209
- ], false));
210
- },
211
- hidden: function (ps, ctx, _a) {
212
- _a.path;
213
- // If this is change-able.
214
- if (opts.canChangeField) {
215
- return false;
216
- }
217
- return true;
218
- },
219
- }, title: {
220
- type: "string",
221
- displayName: "Title",
222
- defaultValueHint: getDefaultValueHint("title"),
223
- hidden: function () { return !!opts.noTitle; },
224
- }, expr: __assign(__assign({}, rowDataType("Custom value")), { hidden: function (ps, ctx, _a) {
225
- _a.item; _a.path;
226
- return false;
227
- } }), isHidden: {
228
- type: "boolean",
229
- displayName: "Is hidden",
230
- defaultValueHint: getDefaultValueHint("isHidden"),
231
- } }, (!opts.noDataType
232
- ? {
233
- dataType: {
234
- type: "choice",
235
- displayName: "Data type",
236
- options: [
237
- {
238
- value: "auto",
239
- label: "Auto",
240
- },
241
- {
242
- value: "number",
243
- label: "Number",
244
- },
245
- {
246
- value: "percent",
247
- label: "Percentage",
248
- },
249
- {
250
- value: "currency",
251
- label: "Currency",
252
- },
253
- {
254
- value: "string",
255
- label: "String",
256
- },
257
- {
258
- value: "boolean",
259
- label: "Boolean",
260
- },
261
- {
262
- value: "datetime",
263
- label: "Date / Time",
264
- },
265
- {
266
- value: "relative-datetime",
267
- label: "Date / Time relative to now",
268
- },
269
- ],
270
- defaultValueHint: getDefaultValueHint("dataType"),
271
- },
272
- currency: {
273
- displayName: "Currency",
274
- description: "Must be a valid currency code",
275
- type: "string",
276
- defaultValueHint: "USD",
277
- hidden: function (ps, ctx, _a) {
278
- var item = _a.item;
279
- return item.dataType !== "currency";
280
- },
281
- },
282
- locale: {
283
- displayName: "Locale",
284
- description: "Must be a valid locale code",
285
- type: "string",
286
- defaultValueHint: "en-US",
287
- hidden: function (ps, ctx, _a) {
288
- var item = _a.item;
289
- return !isOneOf(item.dataType, NUMBER_TYPES) &&
290
- !isOneOf(item.dataType, DATETIME_TYPES);
291
- },
292
- },
293
- notation: {
294
- displayName: "Notation",
295
- type: "choice",
296
- options: [
297
- {
298
- value: "standard",
299
- label: "Standard",
300
- },
301
- {
302
- value: "scientific",
303
- label: "Scientific notation (like 1E3)",
304
- },
305
- {
306
- value: "compact",
307
- label: "Compact (like 10K)",
308
- },
309
- ],
310
- defaultValueHint: "standard",
311
- hidden: function (ps, ctx, _a) {
312
- var item = _a.item;
313
- return !isOneOf(item.dataType, NUMBER_TYPES);
314
- },
315
- },
316
- signDisplay: {
317
- type: "choice",
318
- displayName: "Number sign",
319
- options: [
320
- {
321
- value: "auto",
322
- label: "Only for negative numbers (10, -10)",
323
- },
324
- {
325
- value: "exceptZero",
326
- label: "Positive or negative (+10, -10)",
327
- },
328
- ],
329
- defaultValueHint: "auto",
330
- hidden: function (ps, ctx, _a) {
331
- var item = _a.item;
332
- return !isOneOf(item.dataType, NUMBER_TYPES);
333
- },
334
- },
335
- maximumFractionDigits: {
336
- type: "number",
337
- displayName: "Max decimal places",
338
- defaultValueHint: 3,
339
- min: 0,
340
- max: 20,
341
- hidden: function (ps, ctx, _a) {
342
- var item = _a.item;
343
- return !isOneOf(item.dataType, NUMBER_TYPES);
344
- },
345
- },
346
- minimumFractionDigits: {
347
- type: "number",
348
- displayName: "Min decimal places",
349
- defaultValueHint: 0,
350
- min: 0,
351
- max: 20,
352
- hidden: function (ps, ctx, _a) {
353
- var item = _a.item;
354
- return !isOneOf(item.dataType, NUMBER_TYPES);
355
- },
356
- },
357
- showAs: {
358
- type: "choice",
359
- options: [
360
- {
361
- value: "checkbox",
362
- label: "Checkboxes",
363
- },
364
- {
365
- value: "switch",
366
- label: "Toggle switches",
367
- },
368
- {
369
- value: "text",
370
- label: "Text",
371
- },
372
- ],
373
- displayName: "Show as",
374
- defaultValueHint: "checkbox",
375
- hidden: function (ps, ctx, _a) {
376
- var item = _a.item;
377
- return item.dataType !== "boolean";
378
- },
379
- },
380
- dateStyle: {
381
- displayName: "Date style",
382
- type: "choice",
383
- options: [
384
- {
385
- value: "none",
386
- label: "None (don't display date)",
387
- },
388
- {
389
- value: "short",
390
- label: "Short (like 12/25/2023)",
391
- },
392
- {
393
- value: "medium",
394
- label: "Medium (like Dec 25, 2023)",
395
- },
396
- {
397
- value: "long",
398
- label: "Long (like December 25, 2023)",
399
- },
400
- {
401
- value: "full",
402
- label: "Full (like Monday, December 25, 2023)",
403
- },
404
- ],
405
- defaultValueHint: DEFAULT_DATETIME_SETTINGS.dateStyle,
406
- hidden: function (ps, ctx, _a) {
407
- var item = _a.item;
408
- return item.dataType !== "datetime";
409
- },
410
- },
411
- timeStyle: {
412
- displayName: "Time style",
413
- type: "choice",
414
- options: [
415
- {
416
- value: "none",
417
- label: "None (don't display time)",
418
- },
419
- {
420
- value: "short",
421
- label: "Short (like 4:00 PM)",
422
- },
423
- {
424
- value: "medium",
425
- label: "Medium (like 4:00:00 PM)",
426
- },
427
- {
428
- value: "long",
429
- label: "Long (like 4:00:00 PM PST)",
430
- },
431
- {
432
- value: "full",
433
- label: "Full (like 4:00:00 PM Pacific Standard Time)",
434
- },
435
- ],
436
- defaultValueHint: DEFAULT_DATETIME_SETTINGS.timeStyle,
437
- hidden: function (ps, ctx, _a) {
438
- var item = _a.item;
439
- return item.dataType !== "datetime";
440
- },
441
- },
442
- hour12: {
443
- displayName: "Use AM/PM?",
444
- description: "Whether to use AM/PM or 24-hour clock",
445
- type: "boolean",
446
- defaultValueHint: DEFAULT_DATETIME_SETTINGS.hour12,
447
- hidden: function (ps, ctx, _a) {
448
- var item = _a.item;
449
- return item.dataType !== "datetime";
450
- },
451
- },
452
- numeric: {
453
- type: "choice",
454
- displayName: "Use numbers?",
455
- options: [
456
- { value: "always", label: "Always use numbers" },
457
- {
458
- value: "auto",
459
- label: "Use words like 'Yesterday' or 'Tomorrow'",
460
- },
461
- ],
462
- defaultValueHint: DEFAULT_RELATIVE_DATETIME_SETTINGS.numeric,
463
- hidden: function (ps, ctx, _a) {
464
- var item = _a.item;
465
- return item.dataType !== "relative-datetime";
466
- },
467
- },
468
- unit: {
469
- type: "choice",
470
- displayName: "Time unit",
471
- options: [
472
- {
473
- value: "second",
474
- label: "Seconds",
475
- },
476
- {
477
- value: "minute",
478
- label: "Minutes",
479
- },
480
- {
481
- value: "hour",
482
- label: "Hours",
483
- },
484
- {
485
- value: "day",
486
- label: "Days",
487
- },
488
- {
489
- value: "week",
490
- label: "Weeks",
491
- },
492
- {
493
- value: "month",
494
- label: "Months",
495
- },
496
- {
497
- value: "year",
498
- label: "Years",
499
- },
500
- ],
501
- defaultValueHint: DEFAULT_RELATIVE_DATETIME_SETTINGS.unit,
502
- hidden: function (ps, ctx, _a) {
503
- var item = _a.item;
504
- return item.dataType !== "relative-datetime";
505
- },
506
- },
119
+ return __spreadValues$9(__spreadValues$9({
120
+ key: {
121
+ type: "string",
122
+ hidden: () => true
123
+ },
124
+ fieldId: {
125
+ type: "choice",
126
+ displayName: "Field name",
127
+ readOnly: !opts.canChangeField,
128
+ options: (_props, ctx) => {
129
+ var _a, _b;
130
+ return withoutFalsey([
131
+ opts.canPickNoneField && { value: NoneField, label: "None" },
132
+ ...((_b = (_a = ctx == null ? void 0 : ctx.schema) == null ? void 0 : _a.fields) != null ? _b : []).map((f) => {
133
+ var _a2;
134
+ return {
135
+ value: f.id,
136
+ label: (_a2 = f.label) != null ? _a2 : f.id
137
+ };
138
+ }),
139
+ { value: CustomField, label: "Custom value" }
140
+ ]);
141
+ },
142
+ hidden: (ps, ctx, { path: _controlPath }) => {
143
+ if (opts.canChangeField) {
144
+ return false;
507
145
  }
508
- : {})), opts.fieldTypes);
509
- }
510
- function getDefaultValueHint(field) {
511
- return function (_props, contextData, _a) {
512
- var item = _a.item;
513
- if (item === null || item === void 0 ? void 0 : item.fieldId) {
514
- var fieldSetting = contextData === null || contextData === void 0 ? void 0 : contextData.mergedFields.find(function (f) { return f.fieldId === item.fieldId; });
515
- return fieldSetting === null || fieldSetting === void 0 ? void 0 : fieldSetting[field];
146
+ return true;
147
+ }
148
+ },
149
+ title: {
150
+ type: "string",
151
+ displayName: "Title",
152
+ defaultValueHint: getDefaultValueHint("title"),
153
+ hidden: () => !!opts.noTitle
154
+ },
155
+ expr: __spreadProps$7(__spreadValues$9({}, rowDataType("Custom value")), {
156
+ hidden: (ps, ctx, { item, path: _controlPath }) => {
157
+ return false;
158
+ }
159
+ }),
160
+ isHidden: {
161
+ type: "boolean",
162
+ displayName: "Is hidden",
163
+ defaultValueHint: getDefaultValueHint("isHidden")
164
+ }
165
+ }, !opts.noDataType ? {
166
+ dataType: {
167
+ type: "choice",
168
+ displayName: "Data type",
169
+ options: [
170
+ {
171
+ value: "auto",
172
+ label: "Auto"
173
+ },
174
+ {
175
+ value: "number",
176
+ label: "Number"
177
+ },
178
+ {
179
+ value: "percent",
180
+ label: "Percentage"
181
+ },
182
+ {
183
+ value: "currency",
184
+ label: "Currency"
185
+ },
186
+ {
187
+ value: "string",
188
+ label: "String"
189
+ },
190
+ {
191
+ value: "boolean",
192
+ label: "Boolean"
193
+ },
194
+ {
195
+ value: "datetime",
196
+ label: "Date / Time"
197
+ },
198
+ {
199
+ value: "relative-datetime",
200
+ label: "Date / Time relative to now"
516
201
  }
517
- return undefined;
518
- };
519
- }
520
- var rowDataType = function (displayName, control) {
521
- return ({
522
- type: "function",
523
- displayName: displayName,
524
- control: control,
525
- argNames: ["currentItem", "currentValue"],
526
- argValues: function (_props, ctx, _a) {
527
- var _b;
528
- var item = _a.item;
529
- var row = (_b = ctx === null || ctx === void 0 ? void 0 : ctx.data) === null || _b === void 0 ? void 0 : _b[0];
530
- var cell = item.fieldId ? row === null || row === void 0 ? void 0 : row[item.fieldId] : undefined;
531
- return [row, cell];
202
+ ],
203
+ defaultValueHint: getDefaultValueHint("dataType")
204
+ },
205
+ currency: {
206
+ displayName: "Currency",
207
+ description: "Must be a valid currency code",
208
+ type: "string",
209
+ defaultValueHint: "USD",
210
+ hidden: (ps, ctx, { item }) => item.dataType !== "currency"
211
+ },
212
+ locale: {
213
+ displayName: "Locale",
214
+ description: "Must be a valid locale code",
215
+ type: "string",
216
+ defaultValueHint: "en-US",
217
+ hidden: (ps, ctx, { item }) => !isOneOf(item.dataType, NUMBER_TYPES) && !isOneOf(item.dataType, DATETIME_TYPES)
218
+ },
219
+ notation: {
220
+ displayName: "Notation",
221
+ type: "choice",
222
+ options: [
223
+ {
224
+ value: "standard",
225
+ label: "Standard"
532
226
  },
533
- });
534
- };
535
- function buildFieldsPropType(_a) {
536
- 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"]);
537
- return {
538
- type: "array",
539
- advanced: advanced,
540
- displayName: displayName,
541
- hidden: function (ps) { return !ps.data; },
542
- unstable__keyFunc: function (x) { return x.key; },
543
- unstable__minimalValue: minimalValue,
544
- unstable__canDelete: function (ps, _props, ctx, _a) {
545
- var item = _a.item;
546
- if (opts.canChangeField) {
547
- return true;
548
- }
549
- if (!(ctx === null || ctx === void 0 ? void 0 : ctx.schema)) {
550
- // still loading...
551
- return false;
552
- }
553
- if (item.fieldId &&
554
- ctx.schema.fields.some(function (f) { return f.id === item.fieldId; })) {
555
- return false;
556
- }
557
- return true;
227
+ {
228
+ value: "scientific",
229
+ label: "Scientific notation (like 1E3)"
558
230
  },
559
- itemType: {
560
- type: "object",
561
- nameFunc: function (_item) {
562
- // Prefer to show the field ID when available, since there's no other indication what field you're edtiing if you relabeled it.
563
- return _item.fieldId || _item.title || "Custom value";
564
- },
565
- fields: getFieldSubprops(opts),
231
+ {
232
+ value: "compact",
233
+ label: "Compact (like 10K)"
234
+ }
235
+ ],
236
+ defaultValueHint: "standard",
237
+ hidden: (ps, ctx, { item }) => !isOneOf(item.dataType, NUMBER_TYPES)
238
+ },
239
+ signDisplay: {
240
+ type: "choice",
241
+ displayName: "Number sign",
242
+ options: [
243
+ {
244
+ value: "auto",
245
+ label: "Only for negative numbers (10, -10)"
246
+ },
247
+ {
248
+ value: "exceptZero",
249
+ label: "Positive or negative (+10, -10)"
250
+ }
251
+ ],
252
+ defaultValueHint: "auto",
253
+ hidden: (ps, ctx, { item }) => !isOneOf(item.dataType, NUMBER_TYPES)
254
+ },
255
+ maximumFractionDigits: {
256
+ type: "number",
257
+ displayName: "Max decimal places",
258
+ defaultValueHint: 3,
259
+ min: 0,
260
+ max: 20,
261
+ hidden: (ps, ctx, { item }) => !isOneOf(item.dataType, NUMBER_TYPES)
262
+ },
263
+ minimumFractionDigits: {
264
+ type: "number",
265
+ displayName: "Min decimal places",
266
+ defaultValueHint: 0,
267
+ min: 0,
268
+ max: 20,
269
+ hidden: (ps, ctx, { item }) => !isOneOf(item.dataType, NUMBER_TYPES)
270
+ },
271
+ showAs: {
272
+ type: "choice",
273
+ options: [
274
+ {
275
+ value: "checkbox",
276
+ label: "Checkboxes"
277
+ },
278
+ {
279
+ value: "switch",
280
+ label: "Toggle switches"
281
+ },
282
+ {
283
+ value: "text",
284
+ label: "Text"
285
+ }
286
+ ],
287
+ displayName: "Show as",
288
+ defaultValueHint: "checkbox",
289
+ hidden: (ps, ctx, { item }) => item.dataType !== "boolean"
290
+ },
291
+ dateStyle: {
292
+ displayName: "Date style",
293
+ type: "choice",
294
+ options: [
295
+ {
296
+ value: "none",
297
+ label: "None (don't display date)"
566
298
  },
567
- };
299
+ {
300
+ value: "short",
301
+ label: "Short (like 12/25/2023)"
302
+ },
303
+ {
304
+ value: "medium",
305
+ label: "Medium (like Dec 25, 2023)"
306
+ },
307
+ {
308
+ value: "long",
309
+ label: "Long (like December 25, 2023)"
310
+ },
311
+ {
312
+ value: "full",
313
+ label: "Full (like Monday, December 25, 2023)"
314
+ }
315
+ ],
316
+ defaultValueHint: DEFAULT_DATETIME_SETTINGS.dateStyle,
317
+ hidden: (ps, ctx, { item }) => item.dataType !== "datetime"
318
+ },
319
+ timeStyle: {
320
+ displayName: "Time style",
321
+ type: "choice",
322
+ options: [
323
+ {
324
+ value: "none",
325
+ label: "None (don't display time)"
326
+ },
327
+ {
328
+ value: "short",
329
+ label: "Short (like 4:00 PM)"
330
+ },
331
+ {
332
+ value: "medium",
333
+ label: "Medium (like 4:00:00 PM)"
334
+ },
335
+ {
336
+ value: "long",
337
+ label: "Long (like 4:00:00 PM PST)"
338
+ },
339
+ {
340
+ value: "full",
341
+ label: "Full (like 4:00:00 PM Pacific Standard Time)"
342
+ }
343
+ ],
344
+ defaultValueHint: DEFAULT_DATETIME_SETTINGS.timeStyle,
345
+ hidden: (ps, ctx, { item }) => item.dataType !== "datetime"
346
+ },
347
+ hour12: {
348
+ displayName: "Use AM/PM?",
349
+ description: "Whether to use AM/PM or 24-hour clock",
350
+ type: "boolean",
351
+ defaultValueHint: DEFAULT_DATETIME_SETTINGS.hour12,
352
+ hidden: (ps, ctx, { item }) => item.dataType !== "datetime"
353
+ },
354
+ numeric: {
355
+ type: "choice",
356
+ displayName: "Use numbers?",
357
+ options: [
358
+ { value: "always", label: "Always use numbers" },
359
+ {
360
+ value: "auto",
361
+ label: "Use words like 'Yesterday' or 'Tomorrow'"
362
+ }
363
+ ],
364
+ defaultValueHint: DEFAULT_RELATIVE_DATETIME_SETTINGS.numeric,
365
+ hidden: (ps, ctx, { item }) => item.dataType !== "relative-datetime"
366
+ },
367
+ unit: {
368
+ type: "choice",
369
+ displayName: "Time unit",
370
+ options: [
371
+ {
372
+ value: "second",
373
+ label: "Seconds"
374
+ },
375
+ {
376
+ value: "minute",
377
+ label: "Minutes"
378
+ },
379
+ {
380
+ value: "hour",
381
+ label: "Hours"
382
+ },
383
+ {
384
+ value: "day",
385
+ label: "Days"
386
+ },
387
+ {
388
+ value: "week",
389
+ label: "Weeks"
390
+ },
391
+ {
392
+ value: "month",
393
+ label: "Months"
394
+ },
395
+ {
396
+ value: "year",
397
+ label: "Years"
398
+ }
399
+ ],
400
+ defaultValueHint: DEFAULT_RELATIVE_DATETIME_SETTINGS.unit,
401
+ hidden: (ps, ctx, { item }) => item.dataType !== "relative-datetime"
402
+ }
403
+ } : {}), opts.fieldTypes);
404
+ }
405
+ function getDefaultValueHint(field) {
406
+ return (_props, contextData, { item }) => {
407
+ if (item == null ? void 0 : item.fieldId) {
408
+ const fieldSetting = contextData == null ? void 0 : contextData.mergedFields.find(
409
+ (f) => f.fieldId === item.fieldId
410
+ );
411
+ return fieldSetting == null ? void 0 : fieldSetting[field];
412
+ }
413
+ return void 0;
414
+ };
415
+ }
416
+ const rowDataType = (displayName, control) => ({
417
+ type: "function",
418
+ displayName,
419
+ control,
420
+ argNames: ["currentItem", "currentValue"],
421
+ argValues: (_props, ctx, { item }) => {
422
+ var _a;
423
+ const row = (_a = ctx == null ? void 0 : ctx.data) == null ? void 0 : _a[0];
424
+ const cell = item.fieldId ? row == null ? void 0 : row[item.fieldId] : void 0;
425
+ return [row, cell];
426
+ }
427
+ });
428
+ function buildFieldsPropType(_a) {
429
+ var _b = _a, {
430
+ advanced,
431
+ displayName,
432
+ minimalValue = (_props, contextData) => contextData == null ? void 0 : contextData.minimalFullLengthFields
433
+ } = _b, opts = __objRest$2(_b, [
434
+ "advanced",
435
+ "displayName",
436
+ "minimalValue"
437
+ ]);
438
+ return {
439
+ type: "array",
440
+ advanced,
441
+ displayName,
442
+ hidden: (ps) => !ps.data,
443
+ unstable__keyFunc: (x) => x.key,
444
+ unstable__minimalValue: minimalValue,
445
+ unstable__canDelete: (ps, _props, ctx, { item }) => {
446
+ if (opts.canChangeField) {
447
+ return true;
448
+ }
449
+ if (!(ctx == null ? void 0 : ctx.schema)) {
450
+ return false;
451
+ }
452
+ if (item.fieldId && ctx.schema.fields.some((f) => f.id === item.fieldId)) {
453
+ return false;
454
+ }
455
+ return true;
456
+ },
457
+ itemType: {
458
+ type: "object",
459
+ nameFunc: (_item) => {
460
+ return _item.fieldId || _item.title || "Custom value";
461
+ },
462
+ fields: getFieldSubprops(opts)
463
+ }
464
+ };
568
465
  }
569
466
 
467
+ var __defProp$8 = Object.defineProperty;
468
+ var __defProps$6 = Object.defineProperties;
469
+ var __getOwnPropDescs$6 = Object.getOwnPropertyDescriptors;
470
+ var __getOwnPropSymbols$8 = Object.getOwnPropertySymbols;
471
+ var __hasOwnProp$8 = Object.prototype.hasOwnProperty;
472
+ var __propIsEnum$8 = Object.prototype.propertyIsEnumerable;
473
+ var __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$8(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
474
+ var __spreadValues$8 = (a, b) => {
475
+ for (var prop in b || (b = {}))
476
+ if (__hasOwnProp$8.call(b, prop))
477
+ __defNormalProp$8(a, prop, b[prop]);
478
+ if (__getOwnPropSymbols$8)
479
+ for (var prop of __getOwnPropSymbols$8(b)) {
480
+ if (__propIsEnum$8.call(b, prop))
481
+ __defNormalProp$8(a, prop, b[prop]);
482
+ }
483
+ return a;
484
+ };
485
+ var __spreadProps$6 = (a, b) => __defProps$6(a, __getOwnPropDescs$6(b));
570
486
  function multiRenderValue(record, cconfigs) {
571
- return cconfigs === null || cconfigs === void 0 ? void 0 : cconfigs.flatMap(function (cc) {
572
- return cc.isHidden ? [] : [" \u2022 ", React.createElement(React.Fragment, null, renderValue(record, cc))];
573
- }).slice(1);
487
+ return cconfigs == null ? void 0 : cconfigs.flatMap(
488
+ (cc) => cc.isHidden ? [] : [` \u2022 `, /* @__PURE__ */ React.createElement(React.Fragment, null, renderValue(record, cc))]
489
+ ).slice(1);
574
490
  }
575
491
  function maybeRenderString(record, cconfig) {
576
- return cconfig && !cconfig.isHidden
577
- ? maybe(getFieldValue(record, cconfig), asString)
578
- : undefined;
492
+ return cconfig && !cconfig.isHidden ? maybe(getFieldValue(record, cconfig), asString) : void 0;
579
493
  }
580
494
  function getFieldValue(record, cconfig) {
581
- var value = cconfig.fieldId ? record[cconfig.fieldId] : undefined;
582
- if (cconfig.expr) {
583
- value = cconfig.expr(record, value);
584
- }
585
- return value;
495
+ let value = cconfig.fieldId ? record[cconfig.fieldId] : void 0;
496
+ if (cconfig.expr) {
497
+ value = cconfig.expr(record, value);
498
+ }
499
+ return value;
586
500
  }
587
501
  function renderValue(record, cconfig) {
588
- var value = getFieldValue(record, cconfig);
589
- if (value == null) {
590
- return "";
591
- }
592
- if (cconfig.dataType === "auto") {
593
- return renderAuto(value);
594
- }
595
- else {
596
- var coerced = coerceValue(value, cconfig.dataType);
597
- if (isOneOf(cconfig.dataType, NUMBER_TYPES) &&
598
- typeof coerced === "number") {
599
- return renderNumber(coerced, cconfig);
600
- }
601
- else if (cconfig.dataType === "boolean" && typeof coerced === "boolean") {
602
- return renderBoolean(coerced, cconfig);
603
- }
604
- else if (cconfig.dataType === "datetime" && coerced instanceof Date) {
605
- return renderDate(coerced, cconfig);
606
- }
607
- else if (cconfig.dataType === "relative-datetime" &&
608
- coerced instanceof Date) {
609
- return renderRelativeDate(coerced, cconfig);
610
- }
611
- return asString(value);
502
+ const value = getFieldValue(record, cconfig);
503
+ if (value == null) {
504
+ return "";
505
+ }
506
+ if (cconfig.dataType === "auto") {
507
+ return renderAuto(value);
508
+ } else {
509
+ const coerced = coerceValue(value, cconfig.dataType);
510
+ if (isOneOf(cconfig.dataType, NUMBER_TYPES) && typeof coerced === "number") {
511
+ return renderNumber(coerced, cconfig);
512
+ } else if (cconfig.dataType === "boolean" && typeof coerced === "boolean") {
513
+ return renderBoolean(coerced, cconfig);
514
+ } else if (cconfig.dataType === "datetime" && coerced instanceof Date) {
515
+ return renderDate(coerced, cconfig);
516
+ } else if (cconfig.dataType === "relative-datetime" && coerced instanceof Date) {
517
+ return renderRelativeDate(coerced, cconfig);
612
518
  }
519
+ return asString(value);
520
+ }
613
521
  }
614
522
  function renderAuto(value) {
615
- if (typeof value === "number") {
616
- return renderNumber(value, { dataType: "number" });
617
- }
618
- else if (typeof value === "boolean") {
619
- return renderBoolean(value, DEFAULT_BOOLEAN_SETTINGS);
620
- }
621
- else if (value instanceof Date) {
622
- return renderDate(value, DEFAULT_DATETIME_SETTINGS);
623
- }
624
- else {
625
- var coerced = tryCoerceAuto(value);
626
- if (coerced === CANNOT_COERCE) {
627
- return asString(value);
628
- }
629
- else {
630
- return renderAuto(coerced);
631
- }
523
+ if (typeof value === "number") {
524
+ return renderNumber(value, { dataType: "number" });
525
+ } else if (typeof value === "boolean") {
526
+ return renderBoolean(value, DEFAULT_BOOLEAN_SETTINGS);
527
+ } else if (value instanceof Date) {
528
+ return renderDate(value, DEFAULT_DATETIME_SETTINGS);
529
+ } else {
530
+ const coerced = tryCoerceAuto(value);
531
+ if (coerced === CANNOT_COERCE) {
532
+ return asString(value);
533
+ } else {
534
+ return renderAuto(coerced);
632
535
  }
536
+ }
633
537
  }
634
538
  function tryCoerceAuto(value) {
635
- for (var _i = 0, _a = [
636
- "number",
637
- "datetime",
638
- ]; _i < _a.length; _i++) {
639
- var dataType = _a[_i];
640
- var coerced = coerceValue(value, dataType);
641
- if (coerced !== CANNOT_COERCE) {
642
- return coerced;
643
- }
539
+ for (const dataType of [
540
+ "number",
541
+ "datetime"
542
+ ]) {
543
+ const coerced = coerceValue(value, dataType);
544
+ if (coerced !== CANNOT_COERCE) {
545
+ return coerced;
644
546
  }
645
- return CANNOT_COERCE;
547
+ }
548
+ return CANNOT_COERCE;
646
549
  }
647
550
  function renderNumber(value, cconfig) {
648
- if (cconfig.dataType === "number") {
649
- return new Intl.NumberFormat(cconfig.locale, cconfig).format(value);
650
- }
651
- else if (cconfig.dataType === "percent") {
652
- return new Intl.NumberFormat(cconfig.locale, __assign(__assign({}, cconfig), { style: "percent" })).format(value);
653
- }
654
- else if (cconfig.dataType === "currency") {
655
- return new Intl.NumberFormat(cconfig.locale, __assign(__assign(__assign({}, DEFAULT_CURRENCY_SETTINGS), cconfig), { style: "currency" })).format(value);
656
- }
657
- else {
658
- throw new Error("Unexpected dataType ".concat(cconfig.dataType));
659
- }
551
+ if (cconfig.dataType === "number") {
552
+ return new Intl.NumberFormat(cconfig.locale, cconfig).format(value);
553
+ } else if (cconfig.dataType === "percent") {
554
+ return new Intl.NumberFormat(cconfig.locale, __spreadProps$6(__spreadValues$8({}, cconfig), {
555
+ style: "percent"
556
+ })).format(value);
557
+ } else if (cconfig.dataType === "currency") {
558
+ return new Intl.NumberFormat(cconfig.locale, __spreadProps$6(__spreadValues$8(__spreadValues$8({}, DEFAULT_CURRENCY_SETTINGS), cconfig), {
559
+ style: "currency"
560
+ })).format(value);
561
+ } else {
562
+ throw new Error(`Unexpected dataType ${cconfig.dataType}`);
563
+ }
660
564
  }
661
565
  function renderDate(value, cconfig) {
662
- var opts = __assign(__assign({}, DEFAULT_DATETIME_SETTINGS), cconfig);
663
- if (opts.dateStyle === "none") {
664
- delete opts["dateStyle"];
665
- }
666
- if (opts.timeStyle === "none") {
667
- delete opts["timeStyle"];
668
- }
669
- return new Intl.DateTimeFormat(cconfig.locale, opts).format(value);
670
- }
671
- var SECOND_MS = 1000;
672
- var MINUTE_MS = 60 * SECOND_MS;
673
- var HOUR_MS = 60 * MINUTE_MS;
674
- var DAY_MS = 24 * HOUR_MS;
675
- var WEEK_MS = 7 * DAY_MS;
676
- var UNIT_TO_MS = {
677
- second: SECOND_MS,
678
- minute: MINUTE_MS,
679
- hour: HOUR_MS,
680
- day: DAY_MS,
681
- week: WEEK_MS,
566
+ const opts = __spreadValues$8(__spreadValues$8({}, DEFAULT_DATETIME_SETTINGS), cconfig);
567
+ if (opts.dateStyle === "none") {
568
+ delete opts["dateStyle"];
569
+ }
570
+ if (opts.timeStyle === "none") {
571
+ delete opts["timeStyle"];
572
+ }
573
+ return new Intl.DateTimeFormat(cconfig.locale, opts).format(value);
574
+ }
575
+ const SECOND_MS = 1e3;
576
+ const MINUTE_MS = 60 * SECOND_MS;
577
+ const HOUR_MS = 60 * MINUTE_MS;
578
+ const DAY_MS = 24 * HOUR_MS;
579
+ const WEEK_MS = 7 * DAY_MS;
580
+ const UNIT_TO_MS = {
581
+ second: SECOND_MS,
582
+ minute: MINUTE_MS,
583
+ hour: HOUR_MS,
584
+ day: DAY_MS,
585
+ week: WEEK_MS
682
586
  };
683
- var UNITS_BY_MS = Object.keys(UNIT_TO_MS);
587
+ const UNITS_BY_MS = Object.keys(UNIT_TO_MS);
684
588
  function renderRelativeDate(value, cconfig) {
685
- var _a;
686
- var opts = __assign(__assign({}, DEFAULT_RELATIVE_DATETIME_SETTINGS), cconfig);
687
- var unit = (_a = cconfig.unit) !== null && _a !== void 0 ? _a : "day";
688
- var formatter = new Intl.RelativeTimeFormat(cconfig.locale, opts);
689
- if (isOneOf(unit, UNITS_BY_MS)) {
690
- // for "exact" units, we can do it by just calcluating the difference
691
- // by ms
692
- var diff = value.getTime() - new Date().getTime();
693
- return formatter.format(Math.round(diff / UNIT_TO_MS[unit]), unit);
694
- }
695
- else {
696
- // otherwise we need to calculate by the specific unit
697
- if (unit === "year") {
698
- var diff = value.getFullYear() - new Date().getFullYear();
699
- return formatter.format(diff, unit);
700
- }
701
- else if (unit === "month") {
702
- var months = function (d) { return d.getFullYear() * 12 + d.getMonth() + 1; };
703
- var diff = months(value) - months(new Date());
704
- return formatter.format(diff, unit);
705
- }
706
- else {
707
- throw new Error("Unexpected relative time unit ".concat(unit));
708
- }
589
+ var _a;
590
+ const opts = __spreadValues$8(__spreadValues$8({}, DEFAULT_RELATIVE_DATETIME_SETTINGS), cconfig);
591
+ const unit = (_a = cconfig.unit) != null ? _a : "day";
592
+ const formatter = new Intl.RelativeTimeFormat(cconfig.locale, opts);
593
+ if (isOneOf(unit, UNITS_BY_MS)) {
594
+ const diff = value.getTime() - (/* @__PURE__ */ new Date()).getTime();
595
+ return formatter.format(Math.round(diff / UNIT_TO_MS[unit]), unit);
596
+ } else {
597
+ if (unit === "year") {
598
+ const diff = value.getFullYear() - (/* @__PURE__ */ new Date()).getFullYear();
599
+ return formatter.format(diff, unit);
600
+ } else if (unit === "month") {
601
+ const months = (d) => d.getFullYear() * 12 + d.getMonth() + 1;
602
+ const diff = months(value) - months(/* @__PURE__ */ new Date());
603
+ return formatter.format(diff, unit);
604
+ } else {
605
+ throw new Error(`Unexpected relative time unit ${unit}`);
709
606
  }
607
+ }
710
608
  }
711
609
  function renderBoolean(value, cconfig) {
712
- var _a;
713
- var showAs = (_a = cconfig.showAs) !== null && _a !== void 0 ? _a : DEFAULT_BOOLEAN_SETTINGS.showAs;
714
- if (showAs === "checkbox") {
715
- return React.createElement(Checkbox, { checked: value });
716
- }
717
- else if (showAs === "switch") {
718
- return React.createElement(Switch, { checked: value });
719
- }
720
- else {
721
- return value ? "true" : "false";
722
- }
610
+ var _a;
611
+ const showAs = (_a = cconfig.showAs) != null ? _a : DEFAULT_BOOLEAN_SETTINGS.showAs;
612
+ if (showAs === "checkbox") {
613
+ return /* @__PURE__ */ React.createElement(Checkbox, { checked: value });
614
+ } else if (showAs === "switch") {
615
+ return /* @__PURE__ */ React.createElement(Switch, { checked: value });
616
+ } else {
617
+ return value ? "true" : "false";
618
+ }
723
619
  }
724
- var CANNOT_COERCE = Symbol("plasmic-cannot-coerce");
620
+ const CANNOT_COERCE = Symbol("plasmic-cannot-coerce");
725
621
  function coerceValue(value, dataType) {
726
- if (value == null) {
727
- return null;
728
- }
729
- try {
730
- if (isOneOf(dataType, NUMBER_TYPES)) {
731
- if (typeof value === "number") {
732
- return value;
733
- }
734
- else if (typeof value === "string") {
735
- var maybeNumber = +value;
736
- if (!isNaN(maybeNumber)) {
737
- return maybeNumber;
738
- }
739
- }
740
- }
741
- else if (isOneOf(dataType, DATETIME_TYPES)) {
742
- if (value instanceof Date) {
743
- return value;
744
- }
745
- else if (typeof value === "number") {
746
- return new Date(value);
747
- }
748
- else if (typeof value === "string") {
749
- var maybeDate = new Date(value);
750
- if (!isNaN(maybeDate.getTime())) {
751
- return maybeDate;
752
- }
753
- }
754
- }
755
- else if (dataType === "boolean") {
756
- if (value === true || value === false) {
757
- return value;
758
- }
759
- else if (typeof value === "number") {
760
- return value !== 0;
761
- }
762
- else if (typeof value === "string") {
763
- return value.toLowerCase() === "true";
764
- }
765
- }
766
- else if (dataType === "string") {
767
- return asString(value);
622
+ if (value == null) {
623
+ return null;
624
+ }
625
+ try {
626
+ if (isOneOf(dataType, NUMBER_TYPES)) {
627
+ if (typeof value === "number") {
628
+ return value;
629
+ } else if (typeof value === "string") {
630
+ const maybeNumber = +value;
631
+ if (!isNaN(maybeNumber)) {
632
+ return maybeNumber;
768
633
  }
769
- else if (dataType === "auto") {
770
- return value;
634
+ }
635
+ } else if (isOneOf(dataType, DATETIME_TYPES)) {
636
+ if (value instanceof Date) {
637
+ return value;
638
+ } else if (typeof value === "number") {
639
+ return new Date(value);
640
+ } else if (typeof value === "string") {
641
+ const maybeDate = new Date(value);
642
+ if (!isNaN(maybeDate.getTime())) {
643
+ return maybeDate;
771
644
  }
645
+ }
646
+ } else if (dataType === "boolean") {
647
+ if (value === true || value === false) {
648
+ return value;
649
+ } else if (typeof value === "number") {
650
+ return value !== 0;
651
+ } else if (typeof value === "string") {
652
+ return value.toLowerCase() === "true";
653
+ }
654
+ } else if (dataType === "string") {
655
+ return asString(value);
656
+ } else if (dataType === "auto") {
657
+ return value;
772
658
  }
773
- catch (err) {
774
- // Ignore error; just fail to coerce
775
- }
776
- return CANNOT_COERCE;
659
+ } catch (err) {
660
+ }
661
+ return CANNOT_COERCE;
777
662
  }
778
663
  function asString(value) {
779
- if (value == null) {
780
- return "";
781
- }
782
- else if (typeof value === "string") {
783
- return value;
784
- }
785
- else if (typeof value === "object") {
786
- if ("toString" in value && typeof value.toString === "function") {
787
- return value.toString();
788
- }
789
- else {
790
- return JSON.stringify(value);
791
- }
792
- }
793
- else {
794
- return "".concat(value);
664
+ if (value == null) {
665
+ return "";
666
+ } else if (typeof value === "string") {
667
+ return value;
668
+ } else if (typeof value === "object") {
669
+ if ("toString" in value && typeof value.toString === "function") {
670
+ return value.toString();
671
+ } else {
672
+ return JSON.stringify(value);
795
673
  }
674
+ } else {
675
+ return `${value}`;
676
+ }
796
677
  }
797
678
 
798
- function RichDetails(props) {
799
- var _a;
800
- var className = props.className, rawData = props.data, size = props.size, bordered = props.bordered, layout = props.layout, _b = props.column, column = _b === void 0 ? 2 : _b;
801
- var data = normalizeData(rawData);
802
- var columnDefinitions = useColumnDefinitions$1(data, props).columnDefinitions;
803
- if (!data || !((_a = data.data) === null || _a === void 0 ? void 0 : _a[0])) {
804
- return React.createElement(Empty, { className: className, image: Empty.PRESENTED_IMAGE_SIMPLE });
679
+ var __defProp$7 = Object.defineProperty;
680
+ var __defProps$5 = Object.defineProperties;
681
+ var __getOwnPropDescs$5 = Object.getOwnPropertyDescriptors;
682
+ var __getOwnPropSymbols$7 = Object.getOwnPropertySymbols;
683
+ var __hasOwnProp$7 = Object.prototype.hasOwnProperty;
684
+ var __propIsEnum$7 = Object.prototype.propertyIsEnumerable;
685
+ var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
686
+ var __spreadValues$7 = (a, b) => {
687
+ for (var prop in b || (b = {}))
688
+ if (__hasOwnProp$7.call(b, prop))
689
+ __defNormalProp$7(a, prop, b[prop]);
690
+ if (__getOwnPropSymbols$7)
691
+ for (var prop of __getOwnPropSymbols$7(b)) {
692
+ if (__propIsEnum$7.call(b, prop))
693
+ __defNormalProp$7(a, prop, b[prop]);
805
694
  }
806
- var row = data.data[0];
807
- return (React.createElement(Descriptions, { className: className, size: size, bordered: bordered, layout: layout, column: {
808
- xs: 1,
809
- sm: 1,
810
- md: column,
811
- } }, columnDefinitions.map(function (col) { return (React.createElement(Descriptions.Item, { label: col.title, key: col.key, span: col.span }, col.render(row))); })));
695
+ return a;
696
+ };
697
+ var __spreadProps$5 = (a, b) => __defProps$5(a, __getOwnPropDescs$5(b));
698
+ function RichDetails(props) {
699
+ var _a;
700
+ const {
701
+ className,
702
+ data: rawData,
703
+ size,
704
+ bordered,
705
+ layout,
706
+ column = 2
707
+ } = props;
708
+ const data = normalizeData(rawData);
709
+ const { columnDefinitions } = useColumnDefinitions$1(data, props);
710
+ if (!data || !((_a = data.data) == null ? void 0 : _a[0])) {
711
+ return /* @__PURE__ */ React.createElement(Empty, { className, image: Empty.PRESENTED_IMAGE_SIMPLE });
712
+ }
713
+ const row = data.data[0];
714
+ return /* @__PURE__ */ React.createElement(
715
+ Descriptions,
716
+ {
717
+ className,
718
+ size,
719
+ bordered,
720
+ layout,
721
+ column: {
722
+ xs: 1,
723
+ sm: 1,
724
+ md: column
725
+ }
726
+ },
727
+ columnDefinitions.map((col) => /* @__PURE__ */ React.createElement(Descriptions.Item, { label: col.title, key: col.key, span: col.span }, col.render(row)))
728
+ );
812
729
  }
813
730
  function useColumnDefinitions$1(data, props) {
814
- var fields = props.fields, setControlContextData = props.setControlContextData;
815
- return React.useMemo(function () {
816
- var schema = data === null || data === void 0 ? void 0 : data.schema;
817
- if (!data || !schema) {
818
- return { normalized: [], columnDefinitions: [] };
731
+ const { fields, setControlContextData } = props;
732
+ return React.useMemo(() => {
733
+ const schema = data == null ? void 0 : data.schema;
734
+ if (!data || !schema) {
735
+ return { normalized: [], columnDefinitions: [] };
736
+ }
737
+ const { mergedFields, minimalFullLengthFields } = deriveFieldConfigs(
738
+ fields != null ? fields : [],
739
+ schema,
740
+ (field) => __spreadValues$7({
741
+ key: mkShortId(),
742
+ isHidden: false,
743
+ dataType: "auto"
744
+ }, field && {
745
+ key: field.id,
746
+ fieldId: field.id,
747
+ title: field.label || field.id,
748
+ expr: (currentItem) => currentItem[field.id]
749
+ })
750
+ );
751
+ setControlContextData == null ? void 0 : setControlContextData(__spreadProps$5(__spreadValues$7({}, data), { mergedFields, minimalFullLengthFields }));
752
+ const normalized = mergedFields;
753
+ const columnDefinitions = normalized.filter((cconfig) => !cconfig.isHidden).map((cconfig, _columnIndex, _columnsArray) => {
754
+ const columnDefinition = {
755
+ dataIndex: cconfig.fieldId,
756
+ title: cconfig.title,
757
+ key: cconfig.key,
758
+ span: cconfig.span,
759
+ render: (record) => {
760
+ return renderValue(record, cconfig);
819
761
  }
820
- var _a = deriveFieldConfigs(fields !== null && fields !== void 0 ? fields : [], schema, function (field) { return (__assign({ key: mkShortId(), isHidden: false, dataType: "auto" }, (field && {
821
- key: field.id,
822
- fieldId: field.id,
823
- title: field.label || field.id,
824
- expr: function (currentItem) { return currentItem[field.id]; },
825
- }))); }), mergedFields = _a.mergedFields, minimalFullLengthFields = _a.minimalFullLengthFields;
826
- setControlContextData === null || setControlContextData === void 0 ? void 0 : setControlContextData(__assign(__assign({}, data), { mergedFields: mergedFields, minimalFullLengthFields: minimalFullLengthFields }));
827
- var normalized = mergedFields;
828
- var columnDefinitions = normalized
829
- .filter(function (cconfig) { return !cconfig.isHidden; })
830
- .map(function (cconfig, _columnIndex, _columnsArray) {
831
- var columnDefinition = {
832
- dataIndex: cconfig.fieldId,
833
- title: cconfig.title,
834
- key: cconfig.key,
835
- span: cconfig.span,
836
- render: function (record) {
837
- return renderValue(record, cconfig);
838
- },
839
- };
840
- return columnDefinition;
841
- });
842
- return { normalized: normalized, columnDefinitions: columnDefinitions };
843
- }, [fields, data, setControlContextData]);
762
+ };
763
+ return columnDefinition;
764
+ });
765
+ return { normalized, columnDefinitions };
766
+ }, [fields, data, setControlContextData]);
844
767
  }
845
768
 
846
769
  function registerRichDetails(loader) {
847
- registerComponentHelper(loader, RichDetails, {
848
- name: "hostless-rich-details",
849
- displayName: "Data details",
850
- defaultStyles: {
851
- width: "stretch",
852
- maxHeight: "100%",
853
- },
854
- props: {
855
- data: {
856
- type: "dataSourceOpData",
857
- description: "The data to display",
858
- },
859
- fields: buildFieldsPropType({
860
- fieldTypes: {
861
- span: {
862
- type: "number",
863
- displayName: "Number of columns to span",
864
- defaultValueHint: 1,
865
- },
866
- },
867
- }),
868
- layout: {
869
- displayName: "Layout",
870
- type: "choice",
871
- options: [
872
- { value: "horizontal", label: "Horizontal" },
873
- { value: "vertical", label: "Vertical" },
874
- ],
875
- defaultValueHint: "horizontal",
876
- },
877
- column: {
878
- displayName: "Items per row",
879
- type: "number",
880
- description: "Number of items to display per row",
881
- defaultValueHint: 2,
882
- },
883
- size: {
884
- displayName: "Spacing",
885
- type: "choice",
886
- options: [
887
- { value: "small", label: "Small" },
888
- { value: "middle", label: "Medium" },
889
- { value: "default", label: "Large" },
890
- ],
891
- defaultValueHint: "default",
892
- },
893
- bordered: {
894
- displayName: "Show borders?",
895
- type: "boolean",
896
- defaultValueHint: false,
897
- },
898
- },
899
- importPath: "@plasmicpkgs/plasmic-rich-components",
900
- importName: "RichDetails",
901
- });
770
+ registerComponentHelper(loader, RichDetails, {
771
+ name: "hostless-rich-details",
772
+ displayName: "Data details",
773
+ defaultStyles: {
774
+ width: "stretch",
775
+ maxHeight: "100%"
776
+ },
777
+ props: {
778
+ data: {
779
+ type: "dataSourceOpData",
780
+ description: "The data to display"
781
+ },
782
+ fields: buildFieldsPropType({
783
+ fieldTypes: {
784
+ span: {
785
+ type: "number",
786
+ displayName: "Number of columns to span",
787
+ defaultValueHint: 1
788
+ }
789
+ }
790
+ }),
791
+ layout: {
792
+ displayName: "Layout",
793
+ type: "choice",
794
+ options: [
795
+ { value: "horizontal", label: "Horizontal" },
796
+ { value: "vertical", label: "Vertical" }
797
+ ],
798
+ defaultValueHint: "horizontal"
799
+ },
800
+ column: {
801
+ displayName: "Items per row",
802
+ type: "number",
803
+ description: "Number of items to display per row",
804
+ defaultValueHint: 2
805
+ },
806
+ size: {
807
+ displayName: "Spacing",
808
+ type: "choice",
809
+ options: [
810
+ { value: "small", label: "Small" },
811
+ { value: "middle", label: "Medium" },
812
+ { value: "default", label: "Large" }
813
+ ],
814
+ defaultValueHint: "default"
815
+ },
816
+ bordered: {
817
+ displayName: "Show borders?",
818
+ type: "boolean",
819
+ defaultValueHint: false
820
+ }
821
+ },
822
+ importPath: "@plasmicpkgs/plasmic-rich-components",
823
+ importName: "RichDetails"
824
+ });
902
825
  }
903
826
 
904
827
  function useIsClient() {
905
- var _a = React.useState(false), loaded = _a[0], setLoaded = _a[1];
906
- useIsomorphicLayoutEffect(function () {
907
- setLoaded(true);
908
- });
909
- return loaded;
828
+ const [loaded, setLoaded] = React.useState(false);
829
+ useIsomorphicLayoutEffect(() => {
830
+ setLoaded(true);
831
+ });
832
+ return loaded;
910
833
  }
911
- var isBrowser = typeof window !== "undefined";
912
- var useIsomorphicLayoutEffect = isBrowser
913
- ? React.useLayoutEffect
914
- : React.useEffect;
834
+ const isBrowser = typeof window !== "undefined";
835
+ const useIsomorphicLayoutEffect = isBrowser ? React.useLayoutEffect : React.useEffect;
915
836
  function capitalize(text) {
916
- return text.slice(0, 1).toUpperCase() + text.slice(1);
837
+ return text.slice(0, 1).toUpperCase() + text.slice(1);
917
838
  }
918
839
  function isLight(color) {
919
- var _a = tinycolor(color).toRgb(), r = _a.r, g = _a.g, b = _a.b;
920
- return r * 0.299 + g * 0.587 + b * 0.114 > 186;
840
+ const { r, g, b } = tinycolor(color).toRgb();
841
+ return r * 0.299 + g * 0.587 + b * 0.114 > 186;
921
842
  }
922
843
 
923
- var AnchorLink = React.forwardRef(function AnchorLink(props, ref) {
924
- return React.createElement("a", __assign({}, props, { ref: ref }));
844
+ var __defProp$6 = Object.defineProperty;
845
+ var __defProps$4 = Object.defineProperties;
846
+ var __getOwnPropDescs$4 = Object.getOwnPropertyDescriptors;
847
+ var __getOwnPropSymbols$6 = Object.getOwnPropertySymbols;
848
+ var __hasOwnProp$6 = Object.prototype.hasOwnProperty;
849
+ var __propIsEnum$6 = Object.prototype.propertyIsEnumerable;
850
+ var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
851
+ var __spreadValues$6 = (a, b) => {
852
+ for (var prop in b || (b = {}))
853
+ if (__hasOwnProp$6.call(b, prop))
854
+ __defNormalProp$6(a, prop, b[prop]);
855
+ if (__getOwnPropSymbols$6)
856
+ for (var prop of __getOwnPropSymbols$6(b)) {
857
+ if (__propIsEnum$6.call(b, prop))
858
+ __defNormalProp$6(a, prop, b[prop]);
859
+ }
860
+ return a;
861
+ };
862
+ var __spreadProps$4 = (a, b) => __defProps$4(a, __getOwnPropDescs$4(b));
863
+ const AnchorLink = React.forwardRef(function AnchorLink2(props, ref) {
864
+ return /* @__PURE__ */ React.createElement("a", __spreadProps$4(__spreadValues$6({}, props), { ref }));
925
865
  });
926
866
 
867
+ var __defProp$5 = Object.defineProperty;
868
+ var __defProps$3 = Object.defineProperties;
869
+ var __getOwnPropDescs$3 = Object.getOwnPropertyDescriptors;
870
+ var __getOwnPropSymbols$5 = Object.getOwnPropertySymbols;
871
+ var __hasOwnProp$5 = Object.prototype.hasOwnProperty;
872
+ var __propIsEnum$5 = Object.prototype.propertyIsEnumerable;
873
+ var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
874
+ var __spreadValues$5 = (a, b) => {
875
+ for (var prop in b || (b = {}))
876
+ if (__hasOwnProp$5.call(b, prop))
877
+ __defNormalProp$5(a, prop, b[prop]);
878
+ if (__getOwnPropSymbols$5)
879
+ for (var prop of __getOwnPropSymbols$5(b)) {
880
+ if (__propIsEnum$5.call(b, prop))
881
+ __defNormalProp$5(a, prop, b[prop]);
882
+ }
883
+ return a;
884
+ };
885
+ var __spreadProps$3 = (a, b) => __defProps$3(a, __getOwnPropDescs$3(b));
886
+ var __objRest$1 = (source, exclude) => {
887
+ var target = {};
888
+ for (var prop in source)
889
+ if (__hasOwnProp$5.call(source, prop) && exclude.indexOf(prop) < 0)
890
+ target[prop] = source[prop];
891
+ if (source != null && __getOwnPropSymbols$5)
892
+ for (var prop of __getOwnPropSymbols$5(source)) {
893
+ if (exclude.indexOf(prop) < 0 && __propIsEnum$5.call(source, prop))
894
+ target[prop] = source[prop];
895
+ }
896
+ return target;
897
+ };
927
898
  function omitUndefined(x) {
928
- return Object.fromEntries(Object.entries(x).filter(function (_a) {
929
- _a[0]; var v = _a[1];
930
- return v !== undefined;
931
- }));
899
+ return Object.fromEntries(
900
+ Object.entries(x).filter(([k, v]) => v !== void 0)
901
+ );
932
902
  }
933
903
  function filterNavMenuItemsByConditions(navMenuItems) {
934
- return navMenuItems
935
- .filter(function (item) { return item.condition === undefined || item.condition; })
936
- .map(function (item) { return (__assign(__assign({}, item), { routes: item.routes
937
- ? filterNavMenuItemsByConditions(item.routes)
938
- : undefined })); });
939
- }
940
- // width: 100% needed because parent is display: flex, which is needed for the min-height behavior.
941
- var baseStyles = "\n.ant-pro-layout-bg-list {\n display: none;\n}\n.ant-pro-layout {\n display: flex;\n width: 100%;\n}\n.ant-pro-layout .ant-pro-layout-content {\n padding: 0;\n}\n";
904
+ return navMenuItems.filter((item) => item.condition === void 0 || item.condition).map((item) => __spreadProps$3(__spreadValues$5({}, item), {
905
+ routes: item.routes ? filterNavMenuItemsByConditions(item.routes) : void 0
906
+ }));
907
+ }
908
+ const baseStyles = `
909
+ .ant-pro-layout-bg-list {
910
+ display: none;
911
+ }
912
+ .ant-pro-layout {
913
+ display: flex;
914
+ width: 100%;
915
+ }
916
+ .ant-pro-layout .ant-pro-layout-content {
917
+ padding: 0;
918
+ }
919
+ `;
942
920
  function RichLayout(_a) {
943
- var _b, _c, _d, _e;
944
- var children = _a.children, navMenuItems = _a.navMenuItems, _f = _a.rootUrl, rootUrl = _f === void 0 ? "/" : _f, actionsChildren = _a.actionsChildren, footerChildren = _a.footerChildren, avatarLabel = _a.avatarLabel, avatarImage = _a.avatarImage, showAvatarMenu = _a.showAvatarMenu, className = _a.className, simpleNavTheme = _a.simpleNavTheme, logo = _a.logo, logoElement = _a.logoElement, layoutProps = __rest(_a, ["children", "navMenuItems", "rootUrl", "actionsChildren", "footerChildren", "avatarLabel", "avatarImage", "showAvatarMenu", "className", "simpleNavTheme", "logo", "logoElement"]);
945
- var isClient = useIsClient();
946
- var _g = useState(undefined), pathname = _g[0], setPathname = _g[1];
947
- useEffect(function () {
948
- if (typeof location !== "undefined") {
949
- setPathname(location.pathname);
950
- }
951
- }, []);
952
- // The usePlasmicLink function may be undefined, if host is not up to date
953
- var Link = (_b = usePlasmicLink === null || usePlasmicLink === void 0 ? void 0 : usePlasmicLink()) !== null && _b !== void 0 ? _b : AnchorLink;
954
- var token = theme.useToken().token;
955
- var origTextColor = token.colorTextBase;
956
- function getNavBgColor() {
957
- var _a, _b;
958
- var scheme = (_a = simpleNavTheme === null || simpleNavTheme === void 0 ? void 0 : simpleNavTheme.scheme) !== null && _a !== void 0 ? _a : "default";
959
- switch (scheme) {
960
- case "primary":
961
- return token.colorPrimary;
962
- case "dark":
963
- // Ant default dark blue Menu color.
964
- return "#011528";
965
- case "custom":
966
- return (_b = simpleNavTheme === null || simpleNavTheme === void 0 ? void 0 : simpleNavTheme.customBgColor) !== null && _b !== void 0 ? _b : token.colorBgBase;
967
- case "light":
968
- // Just use this sorta ugly gray if using 'light' scheme in 'dark' mode.
969
- // Otherwise using light scheme in light mode.
970
- return "#fff";
971
- case "default":
972
- return token.colorBgBase || "#fff";
973
- }
921
+ var _b = _a, {
922
+ children,
923
+ navMenuItems,
924
+ rootUrl = "/",
925
+ actionsChildren,
926
+ footerChildren,
927
+ avatarLabel,
928
+ avatarImage,
929
+ showAvatarMenu,
930
+ className,
931
+ simpleNavTheme,
932
+ logo,
933
+ logoElement
934
+ } = _b, layoutProps = __objRest$1(_b, [
935
+ "children",
936
+ "navMenuItems",
937
+ "rootUrl",
938
+ "actionsChildren",
939
+ "footerChildren",
940
+ "avatarLabel",
941
+ "avatarImage",
942
+ "showAvatarMenu",
943
+ "className",
944
+ "simpleNavTheme",
945
+ "logo",
946
+ "logoElement"
947
+ ]);
948
+ var _a2, _b2, _c, _d, _e;
949
+ const isClient = useIsClient();
950
+ const [pathname, setPathname] = useState(void 0);
951
+ useEffect(() => {
952
+ if (typeof location !== "undefined") {
953
+ setPathname(location.pathname);
974
954
  }
975
- var navBgColor = getNavBgColor();
976
- // Dynamically determine whether we need to change the text to black/white or not, based on background color.
977
- // We don't want light-on-light or dark-on-dark, so if both isNavBgLight and isOrigTextLight are the same, then need to change.
978
- // If no need to change, we leave text color as is.
979
- var isNavBgLight = isLight(navBgColor);
980
- var isOrigTextLight = isLight(origTextColor);
981
- // Ant will interpret "" as defaulting to "#fff" for dark mode and "#000" in light mode.
982
- var navTextColor = isNavBgLight !== isOrigTextLight ? undefined : "";
983
- if (!isClient) {
984
- return null;
955
+ }, []);
956
+ const Link = (_b2 = (_a2 = usePlasmicLink) == null ? void 0 : _a2()) != null ? _b2 : AnchorLink;
957
+ const { token } = theme.useToken();
958
+ const origTextColor = token.colorTextBase;
959
+ function getNavBgColor() {
960
+ var _a3, _b3;
961
+ const scheme = (_a3 = simpleNavTheme == null ? void 0 : simpleNavTheme.scheme) != null ? _a3 : "default";
962
+ switch (scheme) {
963
+ case "primary":
964
+ return token.colorPrimary;
965
+ case "dark":
966
+ return "#011528";
967
+ case "custom":
968
+ return (_b3 = simpleNavTheme == null ? void 0 : simpleNavTheme.customBgColor) != null ? _b3 : token.colorBgBase;
969
+ case "light":
970
+ return "#fff";
971
+ case "default":
972
+ return token.colorBgBase || "#fff";
985
973
  }
986
- var layoutColorOverrides = isNavBgLight
987
- ? undefined
988
- : {
989
- colorBgCollapsedButton: navBgColor,
990
- colorTextCollapsedButtonHover: "rgba(255,255,255,0.85)",
991
- colorTextCollapsedButton: "rgba(255,255,255,0.65)",
992
- colorMenuBackground: navBgColor,
993
- colorBgMenuItemCollapsedHover: "rgba(0,0,0,0.06)",
994
- colorBgMenuItemCollapsedSelected: "rgba(0,0,0,0.15)",
995
- colorBgMenuItemCollapsedElevated: "rgba(0,0,0,0.85)",
996
- colorMenuItemDivider: "rgba(255,255,255,0.15)",
997
- colorBgMenuItemHover: "rgba(0,0,0,0.06)",
998
- colorBgMenuItemSelected: "rgba(0,0,0,0.15)",
999
- colorTextMenuSelected: "#fff",
1000
- colorTextMenuItemHover: "rgba(255,255,255,0.75)",
1001
- colorTextMenu: "rgba(255,255,255,0.75)",
1002
- colorTextMenuSecondary: "rgba(255,255,255,0.65)",
1003
- colorTextMenuTitle: "rgba(255,255,255,0.95)",
1004
- colorTextMenuActive: "rgba(255,255,255,0.95)",
1005
- colorTextSubMenuSelected: "#fff",
1006
- };
1007
- return (React.createElement("div", { className: className, style: { display: "flex" } },
1008
- React.createElement("style", null, baseStyles),
1009
- React.createElement(ProLayout, __assign({}, layoutProps, { logo: logo !== null && logo !== void 0 ? logo : logoElement,
1010
- // Theme just the header. If you simply pass in navTheme=realDark, it affects all main content as well.
1011
- //
1012
- // What we're doing is telling Ant to use the dark mode algorithm. However, dark mode algorithm doesn't change
1013
- // the seed tokens for colorTextBase and colorBgBase - it only fills in #fff and #000 for these if they are
1014
- // unset (""). So that's why further up we may be setting the text color to "".
1015
- //
1016
- // I think it doesn't matter too much what is the colorBgBase, since we are setting (Pro-specific) `tokens`
1017
- // further down for actually setting the fill of the nav sections. What matters is the text color - if we're
1018
- // showing a dark background, then we want the text to be white.
1019
- //
1020
- // We could specify darkAlgorithm to ConfigProvider, but IIRC Pro might be setting some of its own tokens
1021
- // based on whether dark is being specified to the ProConfigProvider. So that's why we need that.
1022
- //
1023
- // ProConfigProvider does first read/inherit the theme/tokens from the surrounding ConfigProvider.
1024
- headerRender: function (_props, defaultDom) { return (React.createElement(ConfigProvider, { theme: { token: omitUndefined({ colorTextBase: navTextColor }) } },
1025
- React.createElement(ProConfigProvider, { dark: !isNavBgLight }, defaultDom))); }, token: {
1026
- header: omitUndefined(__assign({ colorBgHeader: navBgColor }, layoutColorOverrides)),
1027
- // Ideally, we'd do something similar to headerRender above, and just specify general dark mode to specify
1028
- // whether all components/text should be light.
1029
- // But for some reason it doesn't work, causing the bg color to be ignored (just the default dark Menu color),
1030
- // *and* the text is just dark as well.
1031
- // Haven't yet been able to unravel the pro components code to figure out the proper way to do this, so just
1032
- // bluntly specifying tokens here, as recommended in some GitHub issue.
1033
- sider: layoutColorOverrides,
1034
- },
1035
- // Tweak defaults. ProLayout is janky and has terrible docs!
1036
- layout: (_c = layoutProps.layout) !== null && _c !== void 0 ? _c : "top", fixedHeader: (_d = layoutProps.fixedHeader) !== null && _d !== void 0 ? _d : false, fixSiderbar:
1037
- // Doesn't stretch full height if you set this to false and you're in mix mode.
1038
- layoutProps.layout === "mix"
1039
- ? undefined
1040
- : (_e = layoutProps.fixSiderbar) !== null && _e !== void 0 ? _e : false,
1041
- // This is always needed if you want layout mix to have effect and look any different from layout side - not clear why this should ever be false.
1042
- splitMenus: layoutProps.layout === "mix", route: {
1043
- path: rootUrl,
1044
- routes: navMenuItems
1045
- ? filterNavMenuItemsByConditions(navMenuItems)
1046
- : undefined,
1047
- }, location: {
1048
- pathname: pathname,
1049
- }, menu: {
1050
- // collapsedShowGroupTitle: true,
1051
- defaultOpenAll: true,
1052
- // hideMenuWhenCollapsed: true,
1053
- }, avatarProps: showAvatarMenu
1054
- ? {
1055
- src: avatarImage,
1056
- size: "small",
1057
- title: avatarLabel,
1058
- render: function (_props, dom) {
1059
- return (React.createElement(Dropdown, { menu: {
1060
- items: [
1061
- {
1062
- key: "logout",
1063
- icon: React.createElement(LogoutOutlined, null),
1064
- label: "Sign out",
1065
- },
1066
- ],
1067
- } }, dom));
1068
- },
1069
- }
1070
- : undefined, actionsRender: function (_props) {
1071
- return [actionsChildren];
1072
- }, menuFooterRender: function (props) {
1073
- if (props === null || props === void 0 ? void 0 : props.collapsed)
1074
- return undefined;
1075
- return footerChildren;
1076
- }, onMenuHeaderClick: function (e) { return console.log(e); }, menuItemRender: function (item, dom) { return React.createElement(Link, { href: item.path }, dom); }, headerTitleRender: function (logo, title, _) {
1077
- return (React.createElement(Link, { href: rootUrl },
1078
- logo,
1079
- title));
1080
- } }), children)));
974
+ }
975
+ const navBgColor = getNavBgColor();
976
+ const isNavBgLight = isLight(navBgColor);
977
+ const isOrigTextLight = isLight(origTextColor);
978
+ const navTextColor = isNavBgLight !== isOrigTextLight ? void 0 : "";
979
+ if (!isClient) {
980
+ return null;
981
+ }
982
+ const layoutColorOverrides = isNavBgLight ? void 0 : {
983
+ colorBgCollapsedButton: navBgColor,
984
+ colorTextCollapsedButtonHover: "rgba(255,255,255,0.85)",
985
+ colorTextCollapsedButton: "rgba(255,255,255,0.65)",
986
+ colorMenuBackground: navBgColor,
987
+ colorBgMenuItemCollapsedHover: "rgba(0,0,0,0.06)",
988
+ colorBgMenuItemCollapsedSelected: "rgba(0,0,0,0.15)",
989
+ colorBgMenuItemCollapsedElevated: "rgba(0,0,0,0.85)",
990
+ colorMenuItemDivider: "rgba(255,255,255,0.15)",
991
+ colorBgMenuItemHover: "rgba(0,0,0,0.06)",
992
+ colorBgMenuItemSelected: "rgba(0,0,0,0.15)",
993
+ colorTextMenuSelected: "#fff",
994
+ colorTextMenuItemHover: "rgba(255,255,255,0.75)",
995
+ colorTextMenu: "rgba(255,255,255,0.75)",
996
+ colorTextMenuSecondary: "rgba(255,255,255,0.65)",
997
+ colorTextMenuTitle: "rgba(255,255,255,0.95)",
998
+ colorTextMenuActive: "rgba(255,255,255,0.95)",
999
+ colorTextSubMenuSelected: "#fff"
1000
+ };
1001
+ return /* @__PURE__ */ React.createElement("div", { className, style: { display: "flex" } }, /* @__PURE__ */ React.createElement("style", null, baseStyles), /* @__PURE__ */ React.createElement(
1002
+ ProLayout,
1003
+ __spreadProps$3(__spreadValues$5({}, layoutProps), {
1004
+ logo: logo != null ? logo : logoElement,
1005
+ headerRender: (_props, defaultDom) => /* @__PURE__ */ React.createElement(
1006
+ ConfigProvider,
1007
+ {
1008
+ theme: { token: omitUndefined({ colorTextBase: navTextColor }) }
1009
+ },
1010
+ /* @__PURE__ */ React.createElement(ProConfigProvider, { dark: !isNavBgLight }, defaultDom)
1011
+ ),
1012
+ token: {
1013
+ header: omitUndefined(__spreadValues$5({
1014
+ colorBgHeader: navBgColor
1015
+ }, layoutColorOverrides)),
1016
+ // Ideally, we'd do something similar to headerRender above, and just specify general dark mode to specify
1017
+ // whether all components/text should be light.
1018
+ // But for some reason it doesn't work, causing the bg color to be ignored (just the default dark Menu color),
1019
+ // *and* the text is just dark as well.
1020
+ // Haven't yet been able to unravel the pro components code to figure out the proper way to do this, so just
1021
+ // bluntly specifying tokens here, as recommended in some GitHub issue.
1022
+ sider: layoutColorOverrides
1023
+ },
1024
+ layout: (_c = layoutProps.layout) != null ? _c : "top",
1025
+ fixedHeader: (_d = layoutProps.fixedHeader) != null ? _d : false,
1026
+ fixSiderbar: (
1027
+ // Doesn't stretch full height if you set this to false and you're in mix mode.
1028
+ layoutProps.layout === "mix" ? void 0 : (_e = layoutProps.fixSiderbar) != null ? _e : false
1029
+ ),
1030
+ splitMenus: layoutProps.layout === "mix",
1031
+ route: {
1032
+ path: rootUrl,
1033
+ routes: navMenuItems ? filterNavMenuItemsByConditions(navMenuItems) : void 0
1034
+ },
1035
+ location: {
1036
+ pathname
1037
+ },
1038
+ menu: {
1039
+ // collapsedShowGroupTitle: true,
1040
+ defaultOpenAll: true
1041
+ // hideMenuWhenCollapsed: true,
1042
+ },
1043
+ avatarProps: showAvatarMenu ? {
1044
+ src: avatarImage,
1045
+ size: "small",
1046
+ title: avatarLabel,
1047
+ render: (_props, dom) => {
1048
+ return /* @__PURE__ */ React.createElement(
1049
+ Dropdown,
1050
+ {
1051
+ menu: {
1052
+ items: [
1053
+ {
1054
+ key: "logout",
1055
+ icon: /* @__PURE__ */ React.createElement(LogoutOutlined, null),
1056
+ label: "Sign out"
1057
+ }
1058
+ ]
1059
+ }
1060
+ },
1061
+ dom
1062
+ );
1063
+ }
1064
+ } : void 0,
1065
+ actionsRender: (_props) => {
1066
+ return [actionsChildren];
1067
+ },
1068
+ menuFooterRender: (props) => {
1069
+ if (props == null ? void 0 : props.collapsed)
1070
+ return void 0;
1071
+ return footerChildren;
1072
+ },
1073
+ onMenuHeaderClick: (e) => console.log(e),
1074
+ menuItemRender: (item, dom) => /* @__PURE__ */ React.createElement(Link, { href: item.path }, dom),
1075
+ headerTitleRender: (logo2, title, _) => {
1076
+ return /* @__PURE__ */ React.createElement(Link, { href: rootUrl }, logo2, title);
1077
+ }
1078
+ }),
1079
+ children
1080
+ ));
1081
1081
  }
1082
1082
 
1083
+ var __defProp$4 = Object.defineProperty;
1084
+ var __getOwnPropSymbols$4 = Object.getOwnPropertySymbols;
1085
+ var __hasOwnProp$4 = Object.prototype.hasOwnProperty;
1086
+ var __propIsEnum$4 = Object.prototype.propertyIsEnumerable;
1087
+ var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1088
+ var __spreadValues$4 = (a, b) => {
1089
+ for (var prop in b || (b = {}))
1090
+ if (__hasOwnProp$4.call(b, prop))
1091
+ __defNormalProp$4(a, prop, b[prop]);
1092
+ if (__getOwnPropSymbols$4)
1093
+ for (var prop of __getOwnPropSymbols$4(b)) {
1094
+ if (__propIsEnum$4.call(b, prop))
1095
+ __defNormalProp$4(a, prop, b[prop]);
1096
+ }
1097
+ return a;
1098
+ };
1083
1099
  function generateNavMenuType(isNested, remainingDepth, displayName, defaultValue) {
1084
- return {
1085
- displayName: displayName ? displayName : "Nested items",
1086
- type: "array",
1087
- defaultValue: defaultValue,
1088
- advanced: isNested,
1089
- itemType: {
1090
- type: "object",
1091
- nameFunc: function (item) {
1092
- return item.name || (!displayName ? "Unnamed nested item" : "Unnamed item");
1093
- },
1094
- fields: __assign({ path: "href", name: "string", condition: {
1095
- advanced: true,
1096
- displayName: "Show only if",
1097
- type: "exprEditor",
1098
- } }, (remainingDepth === 0
1099
- ? {}
1100
- : {
1101
- routes: generateNavMenuType(true, remainingDepth - 1),
1102
- })),
1103
- },
1104
- };
1100
+ return {
1101
+ displayName: displayName ? displayName : "Nested items",
1102
+ type: "array",
1103
+ defaultValue,
1104
+ advanced: isNested,
1105
+ itemType: {
1106
+ type: "object",
1107
+ nameFunc: (item) => item.name || (!displayName ? "Unnamed nested item" : "Unnamed item"),
1108
+ fields: __spreadValues$4({
1109
+ path: "href",
1110
+ name: "string",
1111
+ condition: {
1112
+ advanced: true,
1113
+ displayName: "Show only if",
1114
+ type: "exprEditor"
1115
+ }
1116
+ }, remainingDepth === 0 ? {} : {
1117
+ routes: generateNavMenuType(true, remainingDepth - 1)
1118
+ })
1119
+ }
1120
+ };
1105
1121
  }
1106
- var richLayoutMeta = {
1107
- name: "hostless-rich-layout",
1108
- displayName: "Rich App Layout",
1109
- props: {
1110
- children: {
1111
- type: "slot",
1112
- unstable__isMainContentSlot: true,
1113
- },
1114
- actionsChildren: {
1115
- type: "slot",
1116
- hidePlaceholder: true,
1117
- },
1118
- title: {
1119
- displayName: "Title",
1120
- type: "string",
1121
- defaultValue: "App title",
1122
- },
1123
- logo: {
1124
- displayName: "Logo",
1125
- type: "imageUrl",
1126
- hidden: function (ps) { return !ps.logo; },
1127
- },
1128
- logoElement: {
1129
- type: "slot",
1130
- displayName: "Logo",
1131
- defaultValue: {
1132
- type: "img",
1133
- src: "https://static1.plasmic.app/fake-logo.svg",
1134
- },
1135
- hidden: function (ps) { return !!ps.logo; },
1136
- },
1137
- navMenuItems: generateNavMenuType(false, 2, "Nav menu items", [
1138
- {
1139
- path: "/",
1140
- name: "Link 1",
1141
- },
1142
- {
1143
- path: "/",
1144
- name: "Link 2",
1145
- },
1146
- ]),
1147
- layout: {
1148
- displayName: "Layout",
1149
- type: "choice",
1150
- options: ["side", "top", "mix"].map(function (value) { return ({
1151
- value: value,
1152
- label: capitalize(value),
1153
- }); }),
1154
- defaultValueHint: "top",
1155
- },
1156
- simpleNavTheme: {
1157
- displayName: "Theme",
1158
- type: "object",
1159
- fields: {
1160
- scheme: {
1161
- type: "choice",
1162
- options: ["default", "primary", "light", "dark", "custom"].map(function (v) { return ({
1163
- label: capitalize(v),
1164
- value: v,
1165
- }); }),
1166
- defaultValueHint: "default",
1167
- },
1168
- customBgColor: {
1169
- type: "color",
1170
- displayName: "Custom color",
1171
- hidden: function (props) { var _a; return !(((_a = props.simpleNavTheme) === null || _a === void 0 ? void 0 : _a.scheme) === "custom"); },
1172
- defaultValue: "#D73B58",
1173
- },
1174
- },
1175
- },
1176
- // Advanced, show later
1177
- /*
1178
- siderMenuType: {
1179
- displayName: "Sidebar mode",
1180
- type: "choice",
1181
- options: ["sub", "group"].map((value) => ({
1182
- value,
1183
- label: capitalize(value),
1184
- })),
1185
- defaultValue: "sub",
1186
- },
1187
- contentWidth: {
1188
- displayName: "Content width",
1122
+ const richLayoutMeta = {
1123
+ name: "hostless-rich-layout",
1124
+ displayName: "Rich App Layout",
1125
+ props: {
1126
+ children: {
1127
+ type: "slot",
1128
+ unstable__isMainContentSlot: true
1129
+ },
1130
+ actionsChildren: {
1131
+ type: "slot",
1132
+ hidePlaceholder: true
1133
+ },
1134
+ title: {
1135
+ displayName: "Title",
1136
+ type: "string",
1137
+ defaultValue: "App title"
1138
+ },
1139
+ logo: {
1140
+ displayName: "Logo",
1141
+ type: "imageUrl",
1142
+ hidden: (ps) => !ps.logo
1143
+ },
1144
+ logoElement: {
1145
+ type: "slot",
1146
+ displayName: "Logo",
1147
+ defaultValue: {
1148
+ type: "img",
1149
+ src: "https://static1.plasmic.app/fake-logo.svg"
1150
+ },
1151
+ hidden: (ps) => !!ps.logo
1152
+ },
1153
+ navMenuItems: generateNavMenuType(false, 2, "Nav menu items", [
1154
+ {
1155
+ path: "/",
1156
+ name: "Link 1"
1157
+ },
1158
+ {
1159
+ path: "/",
1160
+ name: "Link 2"
1161
+ }
1162
+ ]),
1163
+ layout: {
1164
+ displayName: "Layout",
1165
+ type: "choice",
1166
+ options: ["side", "top", "mix"].map((value) => ({
1167
+ value,
1168
+ label: capitalize(value)
1169
+ })),
1170
+ defaultValueHint: "top"
1171
+ },
1172
+ simpleNavTheme: {
1173
+ displayName: "Theme",
1174
+ type: "object",
1175
+ fields: {
1176
+ scheme: {
1189
1177
  type: "choice",
1190
- options: ["Fluid", "Fixed"],
1191
- defaultValueHint: "Fluid",
1192
- },
1193
- */
1194
- fixedHeader: {
1195
- displayName: "Sticky header",
1196
- type: "boolean",
1197
- hidden: function (ps) { var _a; return ((_a = ps.layout) !== null && _a !== void 0 ? _a : "top") !== "top"; },
1198
- defaultValueHint: false,
1199
- },
1200
- fixSiderbar: {
1201
- displayName: "Sticky sidebar",
1202
- type: "boolean",
1203
- hidden: function (ps) { var _a; return ((_a = ps.layout) !== null && _a !== void 0 ? _a : "top") !== "side"; },
1204
- defaultValueHint: false,
1205
- },
1206
- /*
1207
- showAvatarMenu: {
1208
- displayName: "Show avatar",
1209
- type: "boolean",
1210
- defaultValue: true,
1211
- },
1212
- avatarLabel: {
1213
- displayName: "Avatar label",
1214
- type: "string",
1215
- defaultValue: "User Name",
1216
- },
1217
- avatarImage: {
1218
- displayName: "Avatar image",
1219
- type: "imageUrl",
1220
- defaultValue:
1221
- "https://gw.alipayobjects.com/zos/antfincdn/efFD%24IOql2/weixintupian_20170331104822.jpg",
1222
- },
1223
- */
1224
- menu: {
1225
- displayName: "Menu",
1226
- type: "object",
1227
- fields: {
1228
- defaultOpenAll: {
1229
- displayName: "Default open all",
1230
- type: "boolean",
1231
- },
1232
- hideMenuWhenCollapsed: {
1233
- // displayName: "",
1234
- type: "boolean",
1235
- },
1236
- },
1178
+ options: ["default", "primary", "light", "dark", "custom"].map(
1179
+ (v) => ({
1180
+ label: capitalize(v),
1181
+ value: v
1182
+ })
1183
+ ),
1184
+ defaultValueHint: "default"
1237
1185
  },
1186
+ customBgColor: {
1187
+ type: "color",
1188
+ displayName: "Custom color",
1189
+ hidden: (props) => {
1190
+ var _a;
1191
+ return !(((_a = props.simpleNavTheme) == null ? void 0 : _a.scheme) === "custom");
1192
+ },
1193
+ defaultValue: "#D73B58"
1194
+ }
1195
+ }
1238
1196
  },
1239
- defaultStyles: {
1240
- width: "full-bleed",
1241
- height: "stretch",
1242
- minHeight: "100vh",
1197
+ // Advanced, show later
1198
+ /*
1199
+ siderMenuType: {
1200
+ displayName: "Sidebar mode",
1201
+ type: "choice",
1202
+ options: ["sub", "group"].map((value) => ({
1203
+ value,
1204
+ label: capitalize(value),
1205
+ })),
1206
+ defaultValue: "sub",
1243
1207
  },
1244
- importName: "RichLayout",
1245
- importPath: "@plasmicpkgs/plasmic-rich-components",
1208
+ contentWidth: {
1209
+ displayName: "Content width",
1210
+ type: "choice",
1211
+ options: ["Fluid", "Fixed"],
1212
+ defaultValueHint: "Fluid",
1213
+ },
1214
+ */
1215
+ fixedHeader: {
1216
+ displayName: "Sticky header",
1217
+ type: "boolean",
1218
+ hidden: (ps) => {
1219
+ var _a;
1220
+ return ((_a = ps.layout) != null ? _a : "top") !== "top";
1221
+ },
1222
+ defaultValueHint: false
1223
+ },
1224
+ fixSiderbar: {
1225
+ displayName: "Sticky sidebar",
1226
+ type: "boolean",
1227
+ hidden: (ps) => {
1228
+ var _a;
1229
+ return ((_a = ps.layout) != null ? _a : "top") !== "side";
1230
+ },
1231
+ defaultValueHint: false
1232
+ },
1233
+ /*
1234
+ showAvatarMenu: {
1235
+ displayName: "Show avatar",
1236
+ type: "boolean",
1237
+ defaultValue: true,
1238
+ },
1239
+ avatarLabel: {
1240
+ displayName: "Avatar label",
1241
+ type: "string",
1242
+ defaultValue: "User Name",
1243
+ },
1244
+ avatarImage: {
1245
+ displayName: "Avatar image",
1246
+ type: "imageUrl",
1247
+ defaultValue:
1248
+ "https://gw.alipayobjects.com/zos/antfincdn/efFD%24IOql2/weixintupian_20170331104822.jpg",
1249
+ },
1250
+ */
1251
+ menu: {
1252
+ displayName: "Menu",
1253
+ type: "object",
1254
+ fields: {
1255
+ defaultOpenAll: {
1256
+ displayName: "Default open all",
1257
+ type: "boolean"
1258
+ },
1259
+ hideMenuWhenCollapsed: {
1260
+ // displayName: "",
1261
+ type: "boolean"
1262
+ }
1263
+ }
1264
+ }
1265
+ },
1266
+ defaultStyles: {
1267
+ width: "full-bleed",
1268
+ height: "stretch",
1269
+ minHeight: "100vh"
1270
+ },
1271
+ importName: "RichLayout",
1272
+ importPath: "@plasmicpkgs/plasmic-rich-components"
1246
1273
  };
1247
1274
  function registerRichLayout(loader) {
1248
- registerComponentHelper(loader, RichLayout, richLayoutMeta);
1275
+ registerComponentHelper(loader, RichLayout, richLayoutMeta);
1249
1276
  }
1250
1277
 
1251
1278
  function useSortedFilteredData(data, columns) {
1252
- var _a = useState(""), search = _a[0], setSearch = _a[1];
1253
- var _b = useState(undefined), sortState = _b[0], setSortState = _b[1];
1254
- var finalData = React.useMemo(function () {
1255
- var _a;
1256
- var filtered = (_a = data === null || data === void 0 ? void 0 : data.data) === null || _a === void 0 ? void 0 : _a.filter(function (row) {
1257
- return fastStringify(Object.values(row)).toLowerCase().includes(search);
1279
+ const [search, setSearch] = useState("");
1280
+ const [sortState, setSortState] = useState(void 0);
1281
+ const finalData = React.useMemo(() => {
1282
+ var _a;
1283
+ const filtered = (_a = data == null ? void 0 : data.data) == null ? void 0 : _a.filter(
1284
+ (row) => fastStringify(Object.values(row)).toLowerCase().includes(search)
1285
+ );
1286
+ const sorted = (sortState == null ? void 0 : sortState.sorter.column) ? (
1287
+ // We use .sort() rather than sortBy to use localeCompare
1288
+ (() => {
1289
+ var _a2;
1290
+ const cconfig = columns.find(
1291
+ (cc) => {
1292
+ var _a3;
1293
+ return cc.key === ((_a3 = sortState == null ? void 0 : sortState.sorter.column) == null ? void 0 : _a3.key);
1294
+ }
1295
+ );
1296
+ const expr = (_a2 = cconfig.expr) != null ? _a2 : (x) => x;
1297
+ return (filtered != null ? filtered : []).sort((aa, bb) => {
1298
+ var _a3, _b;
1299
+ const a = (_a3 = expr(aa, cconfig.fieldId ? aa == null ? void 0 : aa[cconfig.fieldId] : null)) != null ? _a3 : null, b = (_b = expr(bb, cconfig.fieldId ? bb == null ? void 0 : bb[cconfig.fieldId] : null)) != null ? _b : null;
1300
+ return typeof a === "string" ? a.localeCompare(b != null ? b : "") : typeof b === "string" ? -b.localeCompare(a != null ? a : "") : a - b;
1258
1301
  });
1259
- var sorted = (sortState === null || sortState === void 0 ? void 0 : sortState.sorter.column)
1260
- ? // We use .sort() rather than sortBy to use localeCompare
1261
- (function () {
1262
- var _a;
1263
- 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); });
1264
- var expr = (_a = cconfig.expr) !== null && _a !== void 0 ? _a : (function (x) { return x; });
1265
- return (filtered !== null && filtered !== void 0 ? filtered : []).sort(function (aa, bb) {
1266
- var _a, _b;
1267
- 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;
1268
- // Default nil to '' here because A < null < z which is weird.
1269
- return typeof a === "string"
1270
- ? a.localeCompare(b !== null && b !== void 0 ? b : "")
1271
- : typeof b === "string"
1272
- ? -b.localeCompare(a !== null && a !== void 0 ? a : "")
1273
- : a - b;
1274
- });
1275
- })()
1276
- : filtered;
1277
- var reversed = (sortState === null || sortState === void 0 ? void 0 : sortState.sorter.order) === "descend" ? sorted === null || sorted === void 0 ? void 0 : sorted.reverse() : sorted;
1278
- return reversed;
1279
- }, [data, columns, sortState, search]);
1280
- return {
1281
- finalData: finalData,
1282
- search: search,
1283
- setSearch: setSearch,
1284
- setSortState: setSortState,
1285
- };
1302
+ })()
1303
+ ) : filtered;
1304
+ const reversed = (sortState == null ? void 0 : sortState.sorter.order) === "descend" ? sorted == null ? void 0 : sorted.reverse() : sorted;
1305
+ return reversed;
1306
+ }, [data, columns, sortState, search]);
1307
+ return {
1308
+ finalData,
1309
+ search,
1310
+ setSearch,
1311
+ setSortState
1312
+ };
1286
1313
  }
1287
1314
  function deriveRowKey(data, rowKey) {
1288
- var _a;
1289
- if (rowKey) {
1290
- return rowKey;
1291
- }
1292
- var schema = data === null || data === void 0 ? void 0 : data.schema;
1293
- if (schema) {
1294
- return (_a = schema.fields[0]) === null || _a === void 0 ? void 0 : _a.id;
1295
- }
1296
- return undefined;
1315
+ var _a;
1316
+ if (rowKey) {
1317
+ return rowKey;
1318
+ }
1319
+ const schema = data == null ? void 0 : data.schema;
1320
+ if (schema) {
1321
+ return (_a = schema.fields[0]) == null ? void 0 : _a.id;
1322
+ }
1323
+ return void 0;
1297
1324
  }
1298
1325
  function deriveKeyOfRow(row, rowKey) {
1299
- if (typeof rowKey === "function") {
1300
- return rowKey(row);
1301
- }
1302
- else if (typeof rowKey === "string") {
1303
- return row[rowKey];
1304
- }
1305
- else {
1306
- return undefined;
1307
- }
1326
+ if (typeof rowKey === "function") {
1327
+ return rowKey(row);
1328
+ } else if (typeof rowKey === "string") {
1329
+ return row[rowKey];
1330
+ } else {
1331
+ return void 0;
1332
+ }
1308
1333
  }
1309
1334
  function renderActions(rowActions, row, data, rowKey) {
1310
- return rowActions.map(function (_action) {
1311
- var _a;
1312
- if (_action.type === "item") {
1313
- return (React.createElement("a", { key: _action.label, style: {
1314
- whiteSpace: "nowrap",
1315
- }, onClick: function () {
1316
- var _a;
1317
- return (_a = _action.onClick) === null || _a === void 0 ? void 0 : _a.call(_action, deriveKeyOfRow(row, deriveRowKey(data, rowKey)), row);
1318
- } }, _action.label));
1319
- }
1320
- else {
1321
- return (React.createElement(Dropdown, { key: _action.label, menu: {
1322
- items: ((_a = _action.children) !== null && _a !== void 0 ? _a : []).map(function (child) { return ({
1323
- key: child.label,
1324
- label: child.label,
1325
- onClick: function () {
1326
- var _a;
1327
- return (_a = child.onClick) === null || _a === void 0 ? void 0 : _a.call(child, deriveKeyOfRow(row, deriveRowKey(data, rowKey)), row);
1328
- },
1329
- }); }),
1330
- } },
1331
- React.createElement("a", { href: "javascript: void 0", style: {
1332
- whiteSpace: "nowrap",
1333
- } }, _action.label)));
1334
- }
1335
- });
1335
+ return rowActions.map((_action) => {
1336
+ var _a;
1337
+ if (_action.type === "item") {
1338
+ return /* @__PURE__ */ React.createElement(
1339
+ "a",
1340
+ {
1341
+ key: _action.label,
1342
+ style: {
1343
+ whiteSpace: "nowrap"
1344
+ },
1345
+ onClick: () => {
1346
+ var _a2;
1347
+ return (_a2 = _action.onClick) == null ? void 0 : _a2.call(
1348
+ _action,
1349
+ deriveKeyOfRow(row, deriveRowKey(data, rowKey)),
1350
+ row
1351
+ );
1352
+ }
1353
+ },
1354
+ _action.label
1355
+ );
1356
+ } else {
1357
+ return /* @__PURE__ */ React.createElement(
1358
+ Dropdown,
1359
+ {
1360
+ key: _action.label,
1361
+ menu: {
1362
+ items: ((_a = _action.children) != null ? _a : []).map((child) => ({
1363
+ key: child.label,
1364
+ label: child.label,
1365
+ onClick: () => {
1366
+ var _a2;
1367
+ return (_a2 = child.onClick) == null ? void 0 : _a2.call(
1368
+ child,
1369
+ deriveKeyOfRow(row, deriveRowKey(data, rowKey)),
1370
+ row
1371
+ );
1372
+ }
1373
+ }))
1374
+ }
1375
+ },
1376
+ /* @__PURE__ */ React.createElement(
1377
+ "a",
1378
+ {
1379
+ href: "javascript: void 0",
1380
+ style: {
1381
+ whiteSpace: "nowrap"
1382
+ }
1383
+ },
1384
+ _action.label
1385
+ )
1386
+ );
1387
+ }
1388
+ });
1336
1389
  }
1337
1390
 
1338
- // In this code, ColumnConfigs are Plasmic, while ColumnDefinitions are Ant.
1391
+ var __defProp$3 = Object.defineProperty;
1392
+ var __defProps$2 = Object.defineProperties;
1393
+ var __getOwnPropDescs$2 = Object.getOwnPropertyDescriptors;
1394
+ var __getOwnPropSymbols$3 = Object.getOwnPropertySymbols;
1395
+ var __hasOwnProp$3 = Object.prototype.hasOwnProperty;
1396
+ var __propIsEnum$3 = Object.prototype.propertyIsEnumerable;
1397
+ var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1398
+ var __spreadValues$3 = (a, b) => {
1399
+ for (var prop in b || (b = {}))
1400
+ if (__hasOwnProp$3.call(b, prop))
1401
+ __defNormalProp$3(a, prop, b[prop]);
1402
+ if (__getOwnPropSymbols$3)
1403
+ for (var prop of __getOwnPropSymbols$3(b)) {
1404
+ if (__propIsEnum$3.call(b, prop))
1405
+ __defNormalProp$3(a, prop, b[prop]);
1406
+ }
1407
+ return a;
1408
+ };
1409
+ var __spreadProps$2 = (a, b) => __defProps$2(a, __getOwnPropDescs$2(b));
1339
1410
  function RichTable(props) {
1340
- var className = props.className, _a = props.data, rawData = _a === void 0 ? {
1341
- data: [],
1342
- schema: {
1343
- id: "inferred",
1344
- fields: [
1345
- {
1346
- id: "id",
1347
- type: "string",
1348
- readOnly: false,
1349
- },
1350
- ],
1351
- },
1352
- } : _a,
1353
- // children,
1354
- _b = props.pagination,
1411
+ const {
1412
+ className,
1413
+ data: rawData = {
1414
+ data: [],
1415
+ schema: {
1416
+ id: "inferred",
1417
+ fields: [
1418
+ {
1419
+ id: "id",
1420
+ type: "string",
1421
+ readOnly: false
1422
+ }
1423
+ ]
1424
+ }
1425
+ },
1355
1426
  // children,
1356
- 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;
1357
- var data = normalizeData(rawData);
1358
- var _f = useColumnDefinitions(data, props), columnDefinitions = _f.columnDefinitions, normalized = _f.normalized;
1359
- var actionRef = useRef();
1360
- var _g = useSortedFilteredData(data, normalized), finalData = _g.finalData, search = _g.search, setSearch = _g.setSearch, setSortState = _g.setSortState;
1361
- var rowSelectionProps = useRowSelectionProps(data, props);
1362
- var isClient = useIsClient();
1363
- if (!isClient) {
1364
- return null;
1365
- }
1366
- return (React.createElement("div", { className: "".concat(className, " ").concat(scopeClassName !== null && scopeClassName !== void 0 ? scopeClassName : "") },
1367
- React.createElement(ProTable, __assign({ rowClassName: props.onRowClick || props.canSelectRows === "click"
1368
- ? "plasmic-table-row-clickable"
1369
- : undefined, actionRef: actionRef, columns: columnDefinitions, onChange: function (_pagination, _filters, sorter, _extra) {
1370
- setSortState({ sorter: sorter });
1371
- }, style: {
1372
- width: "100%",
1373
- }, cardProps: {
1374
- ghost: true,
1375
- } }, rowSelectionProps, { dataSource: finalData, rowKey: deriveRowKey(data, rowKey), defaultSize: defaultSize, editable: { type: "multiple" }, search: false, options: {
1376
- setting: hideColumnPicker
1377
- ? false
1378
- : {
1379
- listsHeight: 400,
1380
- },
1381
- reload: false,
1382
- density: !hideDensity,
1383
- }, pagination: pagination
1384
- ? {
1385
- pageSize: pageSize,
1386
- onChange: function (page) { return console.log(page); },
1387
- showSizeChanger: false,
1388
- }
1389
- : false, dateFormatter: "string", headerTitle: title, toolbar: {
1390
- search: !hideSearch
1391
- ? {
1392
- value: search,
1393
- onChange: function (e) { return setSearch(e.target.value); },
1394
- onSearch: function () {
1395
- return;
1396
- },
1397
- placeholder: "Search",
1398
- }
1399
- : undefined,
1400
- }, toolBarRender: function () {
1401
- return [
1402
- addHref && (React.createElement(Button, { key: "button", icon: React.createElement(PlusOutlined, null), type: "primary", href: addHref }, "Add")),
1403
- !hideExports && React.createElement(ExportMenu, { data: data }),
1404
- ].filter(function (x) { return !!x; });
1405
- } })),
1406
- React.createElement("style", { dangerouslySetInnerHTML: {
1407
- __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
1408
- ? "\n .".concat(scopeClassName, " .ant-pro-table-alert {\n display: none;\n }\n ")
1409
- : "", "\n "),
1410
- } })));
1411
- }
1412
- var defaultColumnConfig$1 = function () {
1413
- return ({
1414
- key: mkShortId(),
1415
- isEditableExpr: function () { return false; },
1416
- disableSorting: false,
1417
- sortByExpr: undefined,
1418
- isHidden: false,
1419
- formatting: {
1420
- styles: {},
1421
- align: "left",
1422
- freeze: "off",
1427
+ pagination = true,
1428
+ defaultSize,
1429
+ title,
1430
+ addHref,
1431
+ pageSize = 10,
1432
+ hideSearch,
1433
+ hideDensity = true,
1434
+ hideColumnPicker,
1435
+ hideExports,
1436
+ hideSelectionBar = true,
1437
+ rowKey,
1438
+ scopeClassName
1439
+ } = props;
1440
+ const data = normalizeData(rawData);
1441
+ const { columnDefinitions, normalized } = useColumnDefinitions(data, props);
1442
+ const actionRef = useRef();
1443
+ const { finalData, search, setSearch, setSortState } = useSortedFilteredData(
1444
+ data,
1445
+ normalized
1446
+ );
1447
+ const rowSelectionProps = useRowSelectionProps(data, props);
1448
+ const isClient = useIsClient();
1449
+ if (!isClient) {
1450
+ return null;
1451
+ }
1452
+ return /* @__PURE__ */ React.createElement("div", { className: `${className} ${scopeClassName != null ? scopeClassName : ""}` }, /* @__PURE__ */ React.createElement(
1453
+ ProTable,
1454
+ __spreadProps$2(__spreadValues$3({
1455
+ rowClassName: props.onRowClick || props.canSelectRows === "click" ? "plasmic-table-row-clickable" : void 0,
1456
+ actionRef,
1457
+ columns: columnDefinitions,
1458
+ onChange: (_pagination, _filters, sorter, _extra) => {
1459
+ setSortState({ sorter });
1460
+ },
1461
+ style: {
1462
+ width: "100%"
1463
+ },
1464
+ cardProps: {
1465
+ ghost: true
1466
+ }
1467
+ }, rowSelectionProps), {
1468
+ dataSource: finalData,
1469
+ rowKey: deriveRowKey(data, rowKey),
1470
+ defaultSize,
1471
+ editable: { type: "multiple" },
1472
+ search: false,
1473
+ options: {
1474
+ setting: hideColumnPicker ? false : {
1475
+ listsHeight: 400
1423
1476
  },
1424
- dataType: "auto",
1425
- });
1426
- };
1477
+ reload: false,
1478
+ density: !hideDensity
1479
+ },
1480
+ pagination: pagination ? {
1481
+ pageSize,
1482
+ onChange: (page) => console.log(page),
1483
+ showSizeChanger: false
1484
+ } : false,
1485
+ dateFormatter: "string",
1486
+ headerTitle: title,
1487
+ toolbar: {
1488
+ search: !hideSearch ? {
1489
+ value: search,
1490
+ onChange: (e) => setSearch(e.target.value),
1491
+ onSearch: () => {
1492
+ return;
1493
+ },
1494
+ placeholder: "Search"
1495
+ } : void 0
1496
+ },
1497
+ toolBarRender: () => [
1498
+ addHref && /* @__PURE__ */ React.createElement(
1499
+ Button,
1500
+ {
1501
+ key: "button",
1502
+ icon: /* @__PURE__ */ React.createElement(PlusOutlined, null),
1503
+ type: "primary",
1504
+ href: addHref
1505
+ },
1506
+ "Add"
1507
+ ),
1508
+ !hideExports && /* @__PURE__ */ React.createElement(ExportMenu, { data })
1509
+ ].filter((x) => !!x)
1510
+ })
1511
+ ), /* @__PURE__ */ React.createElement(
1512
+ "style",
1513
+ {
1514
+ dangerouslySetInnerHTML: {
1515
+ __html: `
1516
+ :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 {
1517
+ display: none;
1518
+ }
1519
+ .plasmic-table-row-clickable {
1520
+ cursor: pointer;
1521
+ }
1522
+ .ant-pro-table-list-toolbar-right {
1523
+ flex-wrap: initial;
1524
+ flex-shrink: 0;
1525
+ }
1526
+ .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 {
1527
+ height: 100%;
1528
+ }
1529
+ .ant-pro-table .ant-spin-container {
1530
+ height: 100%;
1531
+ display: flex;
1532
+ flex-direction: column;
1533
+ }
1534
+ .ant-pro-table .ant-table {
1535
+ flex-grow: 1;
1536
+ min-height: 0;
1537
+ }
1538
+ .ant-pro-table .ant-pagination {
1539
+ flex-shrink: 0;
1540
+ }
1541
+ .ant-pro-table .ant-table-content {
1542
+ overflow: auto !important;
1543
+ height: 100%;
1544
+ }
1545
+ .ant-pro-table > .ant-pro-card > .ant-pro-card-body {
1546
+ display: flex;
1547
+ flex-direction: column;
1548
+ }
1549
+ .ant-pro-table .ant-table-wrapper {
1550
+ flex-grow: 1;
1551
+ min-height: 0;
1552
+ }
1553
+ .ant-pro-table .ant-table-thead > tr > th, .ant-pro-table .ant-table-thead > tr > td.ant-table-selection-column {
1554
+ position: sticky;
1555
+ top: 0;
1556
+ z-index: 2;
1557
+ }
1558
+ .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 {
1559
+ z-index: 3;
1560
+ }
1561
+ .ant-pro-table .ant-table-tbody > tr > td {
1562
+ z-index: 0;
1563
+ }
1564
+ .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 {
1565
+ z-index: 1;
1566
+ }
1567
+ ${scopeClassName && hideSelectionBar ? `
1568
+ .${scopeClassName} .ant-pro-table-alert {
1569
+ display: none;
1570
+ }
1571
+ ` : ""}
1572
+ `
1573
+ }
1574
+ }
1575
+ ));
1576
+ }
1577
+ const defaultColumnConfig$1 = () => ({
1578
+ key: mkShortId(),
1579
+ isEditableExpr: () => false,
1580
+ disableSorting: false,
1581
+ sortByExpr: void 0,
1582
+ isHidden: false,
1583
+ formatting: {
1584
+ styles: {},
1585
+ align: "left",
1586
+ freeze: "off"
1587
+ },
1588
+ dataType: "auto"
1589
+ });
1427
1590
  function useColumnDefinitions(data, props) {
1428
- var fields = props.fields, setControlContextData = props.setControlContextData, rowActions = props.rowActions;
1429
- return React.useMemo(function () {
1430
- var schema = data === null || data === void 0 ? void 0 : data.schema;
1431
- if (!data || !schema) {
1432
- return { normalized: [], columnDefinitions: [] };
1433
- }
1434
- var _a = deriveFieldConfigs(fields !== null && fields !== void 0 ? fields : [], schema, function (field) { return (__assign(__assign({}, defaultColumnConfig$1()), (field && {
1435
- key: field.id,
1436
- fieldId: field.id,
1437
- title: field.label || field.id,
1438
- expr: function (currentItem) { return currentItem[field.id]; },
1439
- }))); }), mergedFields = _a.mergedFields, minimalFullLengthFields = _a.minimalFullLengthFields;
1440
- setControlContextData === null || setControlContextData === void 0 ? void 0 : setControlContextData(__assign(__assign({}, data), { mergedFields: mergedFields, minimalFullLengthFields: minimalFullLengthFields }));
1441
- var normalized = mergedFields;
1442
- var columnDefinitions = normalized
1443
- .filter(function (cconfig) { return !cconfig.isHidden; })
1444
- .map(function (cconfig, _columnIndex, _columnsArray) {
1445
- var columnDefinition = {
1446
- dataIndex: cconfig.fieldId,
1447
- title: cconfig.title,
1448
- // dataIndex: cconfig,
1449
- key: cconfig.key,
1450
- valueType: deriveValueType(cconfig),
1451
- // To come later
1452
- readonly: false,
1453
- sorter: true,
1454
- copyable: false,
1455
- ellipsis: false,
1456
- tip: undefined,
1457
- formItemProps: {
1458
- rules: [],
1459
- },
1460
- disable: false,
1461
- valueEnum: undefined,
1462
- search: undefined,
1463
- hideInSearch: false,
1464
- renderFormItem: function (_, _a) {
1465
- var defaultRender = _a.defaultRender;
1466
- return defaultRender(_);
1467
- },
1468
- render: function (value, record, rowIndex) {
1469
- return renderValue(record, cconfig);
1470
- },
1471
- };
1472
- return columnDefinition;
1473
- });
1474
- var rowKey = props.rowKey;
1475
- if (rowActions && rowActions.length > 0) {
1476
- columnDefinitions.push({
1477
- title: "Actions",
1478
- valueType: "option",
1479
- key: "__plasmicActions",
1480
- fixed: "right",
1481
- className: props.themeResetClassName,
1482
- render: function (_text, row) { return __spreadArray([], renderActions(rowActions, row, data, rowKey), true); },
1483
- });
1591
+ const { fields, setControlContextData, rowActions } = props;
1592
+ return React.useMemo(() => {
1593
+ const schema = data == null ? void 0 : data.schema;
1594
+ if (!data || !schema) {
1595
+ return { normalized: [], columnDefinitions: [] };
1596
+ }
1597
+ const { mergedFields, minimalFullLengthFields } = deriveFieldConfigs(fields != null ? fields : [], schema, (field) => __spreadValues$3(__spreadValues$3({}, defaultColumnConfig$1()), field && {
1598
+ key: field.id,
1599
+ fieldId: field.id,
1600
+ title: field.label || field.id,
1601
+ expr: (currentItem) => currentItem[field.id]
1602
+ }));
1603
+ setControlContextData == null ? void 0 : setControlContextData(__spreadProps$2(__spreadValues$3({}, data), { mergedFields, minimalFullLengthFields }));
1604
+ const normalized = mergedFields;
1605
+ const columnDefinitions = normalized.filter((cconfig) => !cconfig.isHidden).map((cconfig, _columnIndex, _columnsArray) => {
1606
+ const columnDefinition = {
1607
+ dataIndex: cconfig.fieldId,
1608
+ title: cconfig.title,
1609
+ // dataIndex: cconfig,
1610
+ key: cconfig.key,
1611
+ valueType: deriveValueType(cconfig),
1612
+ // To come later
1613
+ readonly: false,
1614
+ sorter: true,
1615
+ copyable: false,
1616
+ ellipsis: false,
1617
+ tip: void 0,
1618
+ formItemProps: {
1619
+ rules: []
1620
+ },
1621
+ disable: false,
1622
+ valueEnum: void 0,
1623
+ search: void 0,
1624
+ hideInSearch: false,
1625
+ renderFormItem: (_, { defaultRender }) => {
1626
+ return defaultRender(_);
1627
+ },
1628
+ render: (value, record, rowIndex) => {
1629
+ return renderValue(record, cconfig);
1484
1630
  }
1485
- return { normalized: normalized, columnDefinitions: columnDefinitions };
1486
- }, [fields, data, setControlContextData, rowActions]);
1631
+ };
1632
+ return columnDefinition;
1633
+ });
1634
+ const rowKey = props.rowKey;
1635
+ if (rowActions && rowActions.length > 0) {
1636
+ columnDefinitions.push({
1637
+ title: "Actions",
1638
+ valueType: "option",
1639
+ key: "__plasmicActions",
1640
+ fixed: "right",
1641
+ className: props.themeResetClassName,
1642
+ render: (_text, row) => [
1643
+ ...renderActions(rowActions, row, data, rowKey)
1644
+ ]
1645
+ });
1646
+ }
1647
+ return { normalized, columnDefinitions };
1648
+ }, [fields, data, setControlContextData, rowActions]);
1487
1649
  }
1488
1650
  function useRowSelectionProps(data, props) {
1489
- var canSelectRows = props.canSelectRows, selectedRowKey = props.selectedRowKey, onRowSelectionChanged = props.onRowSelectionChanged, rowKey = props.rowKey, onRowClick = props.onRowClick;
1490
- var deriveSelectedRowKeys = function () {
1491
- if (!canSelectRows ||
1492
- canSelectRows === "none" ||
1493
- !deriveRowKey(data, rowKey)) {
1494
- return [];
1495
- }
1496
- if (typeof selectedRowKey === "string") {
1497
- return [selectedRowKey];
1498
- }
1499
- else if (Array.isArray(selectedRowKey)) {
1500
- if (canSelectRows === "single" || canSelectRows === "click") {
1501
- return selectedRowKey.slice(0, 1);
1502
- }
1503
- else {
1504
- return selectedRowKey;
1505
- }
1506
- }
1507
- else {
1508
- return [];
1651
+ const {
1652
+ canSelectRows,
1653
+ selectedRowKey,
1654
+ onRowSelectionChanged,
1655
+ rowKey,
1656
+ onRowClick
1657
+ } = props;
1658
+ const deriveSelectedRowKeys = () => {
1659
+ if (!canSelectRows || canSelectRows === "none" || !deriveRowKey(data, rowKey)) {
1660
+ return [];
1661
+ }
1662
+ if (typeof selectedRowKey === "string") {
1663
+ return [selectedRowKey];
1664
+ } else if (Array.isArray(selectedRowKey)) {
1665
+ if (canSelectRows === "single" || canSelectRows === "click") {
1666
+ return selectedRowKey.slice(0, 1);
1667
+ } else {
1668
+ return selectedRowKey;
1669
+ }
1670
+ } else {
1671
+ return [];
1672
+ }
1673
+ };
1674
+ const rowSelection = canSelectRows && canSelectRows !== "none" ? __spreadValues$3({
1675
+ type: canSelectRows === "single" || canSelectRows === "click" ? "radio" : "checkbox",
1676
+ selectedRowKeys: deriveSelectedRowKeys(),
1677
+ onChange: (rowKeys, rows) => {
1678
+ onRowSelectionChanged == null ? void 0 : onRowSelectionChanged(rowKeys, rows);
1679
+ },
1680
+ alwaysShowAlert: true
1681
+ }, canSelectRows === "click" && {
1682
+ renderCell: () => null,
1683
+ columnWidth: 0,
1684
+ columnTitle: null,
1685
+ hideSelectAll: true
1686
+ }) : void 0;
1687
+ return {
1688
+ rowSelection,
1689
+ onRow: (row) => ({
1690
+ onClick: (event) => {
1691
+ const key = deriveKeyOfRow(row, deriveRowKey(data, rowKey));
1692
+ if (key != null && !isInteractable(event.target)) {
1693
+ if (canSelectRows === "click") {
1694
+ onRowSelectionChanged == null ? void 0 : onRowSelectionChanged([key], [row]);
1695
+ }
1696
+ onRowClick == null ? void 0 : onRowClick(key, row, event);
1509
1697
  }
1510
- };
1511
- var rowSelection = canSelectRows && canSelectRows !== "none"
1512
- ? __assign({ type: canSelectRows === "single" || canSelectRows === "click"
1513
- ? "radio"
1514
- : "checkbox", selectedRowKeys: deriveSelectedRowKeys(), onChange: function (rowKeys, rows) {
1515
- onRowSelectionChanged === null || onRowSelectionChanged === void 0 ? void 0 : onRowSelectionChanged(rowKeys, rows);
1516
- }, alwaysShowAlert: true }, (canSelectRows === "click" && {
1517
- renderCell: function () { return null; },
1518
- columnWidth: 0,
1519
- columnTitle: null,
1520
- hideSelectAll: true,
1521
- })) : undefined;
1522
- return {
1523
- rowSelection: rowSelection,
1524
- onRow: function (row) { return ({
1525
- onClick: function (event) {
1526
- var key = deriveKeyOfRow(row, deriveRowKey(data, rowKey));
1527
- if (key != null && !isInteractable(event.target)) {
1528
- if (canSelectRows === "click") {
1529
- onRowSelectionChanged === null || onRowSelectionChanged === void 0 ? void 0 : onRowSelectionChanged([key], [row]);
1530
- }
1531
- onRowClick === null || onRowClick === void 0 ? void 0 : onRowClick(key, row, event);
1532
- }
1533
- },
1534
- }); },
1535
- };
1698
+ }
1699
+ })
1700
+ };
1536
1701
  }
1537
1702
  function ExportMenu(props) {
1538
- var _this = this;
1539
- var data = props.data;
1540
- return (React.createElement(Dropdown, { key: "menu", menu: {
1541
- items: [
1542
- {
1543
- label: "Download as CSV",
1544
- key: "csv",
1545
- onClick: function () { return __awaiter(_this, void 0, void 0, function () {
1546
- var writer, dataStr, filename, blob, link, url;
1547
- var _a, _b;
1548
- return __generator(this, function (_c) {
1549
- writer = createObjectCsvStringifier({
1550
- header: (_b = (_a = data === null || data === void 0 ? void 0 : data.schema) === null || _a === void 0 ? void 0 : _a.fields.map(function (f) { return ({
1551
- id: f.id,
1552
- title: f.id,
1553
- }); })) !== null && _b !== void 0 ? _b : [],
1554
- });
1555
- dataStr = writer.getHeaderString() +
1556
- writer.stringifyRecords(data === null || data === void 0 ? void 0 : data.data);
1557
- filename = "data.csv";
1558
- blob = new Blob([dataStr], {
1559
- type: "text/csv;charset=utf-8;",
1560
- });
1561
- if (navigator.msSaveBlob) {
1562
- // In case of IE 10+
1563
- navigator.msSaveBlob(blob, filename);
1564
- }
1565
- else {
1566
- link = document.createElement("a");
1567
- if (link.download !== undefined) {
1568
- url = URL.createObjectURL(blob);
1569
- link.setAttribute("href", url);
1570
- link.setAttribute("download", filename);
1571
- link.style.visibility = "hidden";
1572
- document.body.appendChild(link);
1573
- link.click();
1574
- document.body.removeChild(link);
1575
- }
1576
- }
1577
- return [2 /*return*/];
1578
- });
1579
- }); },
1580
- },
1581
- {
1582
- label: "Download as JSON",
1583
- key: "json",
1584
- onClick: function () {
1585
- var dataStr = fastStringify(data === null || data === void 0 ? void 0 : data.data);
1586
- var dataUri = "data:application/json;charset=utf-8, ".concat(encodeURIComponent(dataStr));
1587
- var exportFileDefaultName = "data.json";
1588
- var linkElement = document.createElement("a");
1589
- linkElement.setAttribute("href", dataUri);
1590
- linkElement.setAttribute("download", exportFileDefaultName);
1591
- linkElement.click();
1592
- },
1593
- },
1594
- ],
1595
- } },
1596
- React.createElement(Button, null,
1597
- React.createElement(EllipsisOutlined, null))));
1703
+ const { data } = props;
1704
+ return /* @__PURE__ */ React.createElement(
1705
+ Dropdown,
1706
+ {
1707
+ key: "menu",
1708
+ menu: {
1709
+ items: [
1710
+ {
1711
+ label: "Download as CSV",
1712
+ key: "csv",
1713
+ onClick: async () => {
1714
+ var _a, _b;
1715
+ const writer = createObjectCsvStringifier({
1716
+ header: (_b = (_a = data == null ? void 0 : data.schema) == null ? void 0 : _a.fields.map((f) => ({
1717
+ id: f.id,
1718
+ title: f.id
1719
+ }))) != null ? _b : []
1720
+ });
1721
+ const dataStr = writer.getHeaderString() + writer.stringifyRecords(data == null ? void 0 : data.data);
1722
+ const filename = "data.csv";
1723
+ const blob = new Blob([dataStr], {
1724
+ type: "text/csv;charset=utf-8;"
1725
+ });
1726
+ if (navigator.msSaveBlob) {
1727
+ navigator.msSaveBlob(blob, filename);
1728
+ } else {
1729
+ const link = document.createElement("a");
1730
+ if (link.download !== void 0) {
1731
+ const url = URL.createObjectURL(blob);
1732
+ link.setAttribute("href", url);
1733
+ link.setAttribute("download", filename);
1734
+ link.style.visibility = "hidden";
1735
+ document.body.appendChild(link);
1736
+ link.click();
1737
+ document.body.removeChild(link);
1738
+ }
1739
+ }
1740
+ }
1741
+ },
1742
+ {
1743
+ label: "Download as JSON",
1744
+ key: "json",
1745
+ onClick: () => {
1746
+ const dataStr = fastStringify(data == null ? void 0 : data.data);
1747
+ const dataUri = `data:application/json;charset=utf-8, ${encodeURIComponent(
1748
+ dataStr
1749
+ )}`;
1750
+ const exportFileDefaultName = "data.json";
1751
+ const linkElement = document.createElement("a");
1752
+ linkElement.setAttribute("href", dataUri);
1753
+ linkElement.setAttribute("download", exportFileDefaultName);
1754
+ linkElement.click();
1755
+ }
1756
+ }
1757
+ ]
1758
+ }
1759
+ },
1760
+ /* @__PURE__ */ React.createElement(Button, null, /* @__PURE__ */ React.createElement(EllipsisOutlined, null))
1761
+ );
1598
1762
  }
1599
1763
 
1600
1764
  function dataProp() {
1601
- return {
1602
- type: "dataSourceOpData",
1603
- description: "The data to display",
1604
- };
1765
+ return {
1766
+ type: "dataSourceOpData",
1767
+ description: "The data to display"
1768
+ };
1605
1769
  }
1606
1770
  function commonProps() {
1607
- return {
1608
- pagination: {
1609
- type: "boolean",
1610
- advanced: true,
1611
- defaultValueHint: true,
1612
- },
1613
- pageSize: {
1614
- type: "number",
1615
- defaultValueHint: 10,
1616
- advanced: true,
1617
- },
1618
- hideSearch: {
1619
- type: "boolean",
1620
- description: "Hides the search toolbar",
1621
- advanced: true,
1622
- },
1623
- };
1771
+ return {
1772
+ pagination: {
1773
+ type: "boolean",
1774
+ advanced: true,
1775
+ defaultValueHint: true
1776
+ },
1777
+ pageSize: {
1778
+ type: "number",
1779
+ defaultValueHint: 10,
1780
+ advanced: true
1781
+ },
1782
+ hideSearch: {
1783
+ type: "boolean",
1784
+ description: "Hides the search toolbar",
1785
+ advanced: true
1786
+ }
1787
+ };
1624
1788
  }
1625
1789
  function rowActionsProp() {
1626
- return {
1627
- type: "array",
1628
- displayName: "Row actions",
1629
- advanced: true,
1630
- itemType: {
1790
+ return {
1791
+ type: "array",
1792
+ displayName: "Row actions",
1793
+ advanced: true,
1794
+ itemType: {
1795
+ type: "object",
1796
+ nameFunc: (item) => item.label,
1797
+ fields: {
1798
+ type: {
1799
+ type: "choice",
1800
+ options: ["item", "menu"],
1801
+ defaultValue: "item"
1802
+ },
1803
+ label: {
1804
+ type: "string",
1805
+ displayName: "Action label"
1806
+ },
1807
+ children: {
1808
+ type: "array",
1809
+ displayName: "Menu items",
1810
+ itemType: {
1631
1811
  type: "object",
1632
- nameFunc: function (item) { return item.label; },
1633
1812
  fields: {
1634
- type: {
1635
- type: "choice",
1636
- options: ["item", "menu"],
1637
- defaultValue: "item",
1638
- },
1639
- label: {
1640
- type: "string",
1641
- displayName: "Action label",
1642
- },
1643
- children: {
1644
- type: "array",
1645
- displayName: "Menu items",
1646
- itemType: {
1647
- type: "object",
1648
- fields: {
1649
- label: {
1650
- type: "string",
1651
- displayName: "Action label",
1652
- },
1653
- onClick: {
1654
- type: "eventHandler",
1655
- argTypes: [
1656
- { name: "rowKey", type: "string" },
1657
- { name: "row", type: "object" },
1658
- ],
1659
- },
1660
- },
1661
- },
1662
- hidden: function (_ps, _ctx, _a) {
1663
- var item = _a.item;
1664
- return item.type !== "menu";
1665
- },
1666
- },
1667
- onClick: {
1668
- type: "eventHandler",
1669
- displayName: "Action",
1670
- argTypes: [
1671
- { name: "rowKey", type: "string" },
1672
- { name: "row", type: "object" },
1673
- ],
1674
- hidden: function (_ps, _ctx, _a) {
1675
- var item = _a.item;
1676
- return item.type !== "item";
1677
- },
1678
- },
1679
- },
1813
+ label: {
1814
+ type: "string",
1815
+ displayName: "Action label"
1816
+ },
1817
+ onClick: {
1818
+ type: "eventHandler",
1819
+ argTypes: [
1820
+ { name: "rowKey", type: "string" },
1821
+ { name: "row", type: "object" }
1822
+ ]
1823
+ }
1824
+ }
1825
+ },
1826
+ hidden: (_ps, _ctx, { item }) => item.type !== "menu"
1680
1827
  },
1681
- };
1828
+ onClick: {
1829
+ type: "eventHandler",
1830
+ displayName: "Action",
1831
+ argTypes: [
1832
+ { name: "rowKey", type: "string" },
1833
+ { name: "row", type: "object" }
1834
+ ],
1835
+ hidden: (_ps, _ctx, { item }) => item.type !== "item"
1836
+ }
1837
+ }
1838
+ }
1839
+ };
1682
1840
  }
1683
1841
  function onRowClickProp() {
1684
- return {
1685
- type: "eventHandler",
1686
- displayName: "On row clicked",
1687
- argTypes: [
1688
- { name: "rowKey", type: "string" },
1689
- { name: "row", type: "object" },
1690
- { name: "event", type: "object" },
1691
- ],
1692
- };
1842
+ return {
1843
+ type: "eventHandler",
1844
+ displayName: "On row clicked",
1845
+ argTypes: [
1846
+ { name: "rowKey", type: "string" },
1847
+ { name: "row", type: "object" },
1848
+ { name: "event", type: "object" }
1849
+ ]
1850
+ };
1693
1851
  }
1694
1852
 
1695
- var tableHelpers = {
1696
- states: {
1697
- selectedRow: {
1698
- onChangeArgsToValue: function (rowKeys, rows) {
1699
- return rows[0];
1700
- },
1701
- },
1702
- selectedRows: {
1703
- onChangeArgsToValue: function (rowKeys, rows) {
1704
- return rows;
1705
- },
1853
+ var __defProp$2 = Object.defineProperty;
1854
+ var __defProps$1 = Object.defineProperties;
1855
+ var __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors;
1856
+ var __getOwnPropSymbols$2 = Object.getOwnPropertySymbols;
1857
+ var __hasOwnProp$2 = Object.prototype.hasOwnProperty;
1858
+ var __propIsEnum$2 = Object.prototype.propertyIsEnumerable;
1859
+ var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1860
+ var __spreadValues$2 = (a, b) => {
1861
+ for (var prop in b || (b = {}))
1862
+ if (__hasOwnProp$2.call(b, prop))
1863
+ __defNormalProp$2(a, prop, b[prop]);
1864
+ if (__getOwnPropSymbols$2)
1865
+ for (var prop of __getOwnPropSymbols$2(b)) {
1866
+ if (__propIsEnum$2.call(b, prop))
1867
+ __defNormalProp$2(a, prop, b[prop]);
1868
+ }
1869
+ return a;
1870
+ };
1871
+ var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
1872
+ const tableHelpers = {
1873
+ states: {
1874
+ selectedRow: {
1875
+ onChangeArgsToValue: (rowKeys, rows) => {
1876
+ return rows[0];
1877
+ }
1878
+ },
1879
+ selectedRows: {
1880
+ onChangeArgsToValue: (rowKeys, rows) => {
1881
+ return rows;
1882
+ }
1883
+ },
1884
+ selectedRowKey: {
1885
+ onChangeArgsToValue: (rowKeys, rows) => {
1886
+ return rowKeys;
1887
+ }
1888
+ }
1889
+ }
1890
+ };
1891
+ const dataTableMeta = {
1892
+ name: "hostless-rich-table",
1893
+ displayName: "Table",
1894
+ defaultStyles: {
1895
+ width: "stretch",
1896
+ padding: "16px",
1897
+ maxHeight: "100%"
1898
+ },
1899
+ props: __spreadProps$1(__spreadValues$2({
1900
+ data: dataProp(),
1901
+ fields: buildFieldsPropType({}),
1902
+ canSelectRows: {
1903
+ type: "choice",
1904
+ displayName: "Select rows?",
1905
+ options: [
1906
+ { label: "No", value: "none" },
1907
+ { label: "By clicking a row", value: "click" },
1908
+ { label: "Using radio buttons", value: "single" },
1909
+ { label: "Using checkboxes", value: "multiple" }
1910
+ ],
1911
+ defaultValueHint: "none",
1912
+ 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."
1913
+ },
1914
+ rowKey: {
1915
+ type: "string",
1916
+ displayName: "Row key",
1917
+ helpText: "Column key to use as row key; can also be a function that takes in a row and returns a key value",
1918
+ hidden: (ps) => !ps.canSelectRows || ps.canSelectRows === "none",
1919
+ defaultValueHint: (ps) => {
1920
+ const derivedRowKey = deriveRowKey(ps.data, ps.rowKey);
1921
+ return derivedRowKey !== void 0 ? `${derivedRowKey}` : void 0;
1922
+ }
1923
+ },
1924
+ selectedRowKey: {
1925
+ type: "string",
1926
+ displayName: "Selected Row Key",
1927
+ hidden: (ps) => ps.canSelectRows !== "single",
1928
+ advanced: true
1929
+ },
1930
+ selectedRowKeys: {
1931
+ type: "array",
1932
+ displayName: "Selected Row Keys",
1933
+ hidden: (ps) => ps.canSelectRows !== "multiple",
1934
+ advanced: true
1935
+ },
1936
+ onRowSelectionChanged: {
1937
+ type: "eventHandler",
1938
+ displayName: "On row selection changed",
1939
+ argTypes: [
1940
+ { name: "rowKeys", type: "object" },
1941
+ { name: "rows", type: "object" }
1942
+ ]
1943
+ },
1944
+ onRowClick: onRowClickProp(),
1945
+ rowActions: rowActionsProp(),
1946
+ defaultSize: {
1947
+ displayName: "Density",
1948
+ type: "choice",
1949
+ options: [
1950
+ {
1951
+ value: "large",
1952
+ label: "Larger"
1706
1953
  },
1707
- selectedRowKey: {
1708
- onChangeArgsToValue: function (rowKeys, rows) {
1709
- return rowKeys;
1710
- },
1954
+ {
1955
+ value: "middle",
1956
+ label: "Medium"
1711
1957
  },
1958
+ {
1959
+ value: "small",
1960
+ label: "Compact"
1961
+ }
1962
+ ],
1963
+ defaultValueHint: "large",
1964
+ advanced: true
1965
+ }
1966
+ }, commonProps()), {
1967
+ hideExports: {
1968
+ type: "boolean",
1969
+ description: "Hides the button for exporting table data to CSV",
1970
+ advanced: true
1712
1971
  },
1713
- };
1714
- var dataTableMeta = {
1715
- name: "hostless-rich-table",
1716
- displayName: "Table",
1717
- defaultStyles: {
1718
- width: "stretch",
1719
- padding: "16px",
1720
- maxHeight: "100%",
1972
+ hideDensity: {
1973
+ type: "boolean",
1974
+ description: "Hides the control for changing the density of the table",
1975
+ advanced: true,
1976
+ defaultValueHint: true
1721
1977
  },
1722
- props: __assign(__assign({ data: dataProp(), fields: buildFieldsPropType({}), canSelectRows: {
1723
- type: "choice",
1724
- displayName: "Select rows?",
1725
- options: [
1726
- { label: "No", value: "none" },
1727
- { label: "By clicking a row", value: "click" },
1728
- { label: "Using radio buttons", value: "single" },
1729
- { label: "Using checkboxes", value: "multiple" },
1730
- ],
1731
- defaultValueHint: "none",
1732
- 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.",
1733
- }, rowKey: {
1734
- type: "string",
1735
- displayName: "Row key",
1736
- helpText: "Column key to use as row key; can also be a function that takes in a row and returns a key value",
1737
- hidden: function (ps) { return !ps.canSelectRows || ps.canSelectRows === "none"; },
1738
- defaultValueHint: function (ps) {
1739
- var derivedRowKey = deriveRowKey(ps.data, ps.rowKey);
1740
- return derivedRowKey !== undefined ? "".concat(derivedRowKey) : undefined;
1741
- },
1742
- }, selectedRowKey: {
1743
- type: "string",
1744
- displayName: "Selected Row Key",
1745
- hidden: function (ps) { return ps.canSelectRows !== "single"; },
1746
- advanced: true,
1747
- }, selectedRowKeys: {
1748
- type: "array",
1749
- displayName: "Selected Row Keys",
1750
- hidden: function (ps) { return ps.canSelectRows !== "multiple"; },
1751
- advanced: true,
1752
- }, onRowSelectionChanged: {
1753
- type: "eventHandler",
1754
- displayName: "On row selection changed",
1755
- argTypes: [
1756
- { name: "rowKeys", type: "object" },
1757
- { name: "rows", type: "object" },
1758
- ],
1759
- }, onRowClick: onRowClickProp(), rowActions: rowActionsProp(), defaultSize: {
1760
- displayName: "Density",
1761
- type: "choice",
1762
- options: [
1763
- {
1764
- value: "large",
1765
- label: "Larger",
1766
- },
1767
- {
1768
- value: "middle",
1769
- label: "Medium",
1770
- },
1771
- {
1772
- value: "small",
1773
- label: "Compact",
1774
- },
1775
- ],
1776
- defaultValueHint: "large",
1777
- advanced: true,
1778
- } }, commonProps()), { hideExports: {
1779
- type: "boolean",
1780
- description: "Hides the button for exporting table data to CSV",
1781
- advanced: true,
1782
- }, hideDensity: {
1783
- type: "boolean",
1784
- description: "Hides the control for changing the density of the table",
1785
- advanced: true,
1786
- defaultValueHint: true,
1787
- }, hideColumnPicker: {
1788
- type: "boolean",
1789
- description: "Hides the control for reordering and pinning columns",
1790
- advanced: true,
1791
- }, hideSelectionBar: {
1792
- type: "boolean",
1793
- description: "Hides the toolbar that allows the user to clear selection",
1794
- advanced: true,
1795
- hidden: function (ps) { return !ps.canSelectRows || ps.canSelectRows === "none"; },
1796
- defaultValueHint: true,
1797
- }, scopeClassName: {
1798
- type: "styleScopeClass",
1799
- scopeName: "instance",
1800
- }, themeResetClassName: {
1801
- type: "themeResetClass",
1802
- targetAllTags: true,
1803
- } }),
1804
- states: {
1805
- selectedRowKey: __assign({ type: "writable", valueProp: "selectedRowKey", onChangeProp: "onRowSelectionChanged", variableType: "text" }, tableHelpers.states.selectedRowKey),
1806
- selectedRow: __assign({ type: "readonly", onChangeProp: "onRowSelectionChanged", variableType: "object" }, tableHelpers.states.selectedRow),
1807
- selectedRows: __assign({ type: "readonly", onChangeProp: "onRowSelectionChanged", variableType: "array" }, tableHelpers.states.selectedRows),
1978
+ hideColumnPicker: {
1979
+ type: "boolean",
1980
+ description: "Hides the control for reordering and pinning columns",
1981
+ advanced: true
1808
1982
  },
1809
- componentHelpers: {
1810
- helpers: tableHelpers,
1811
- importName: "tableHelpers",
1812
- importPath: "@plasmicpkgs/plasmic-rich-components",
1983
+ hideSelectionBar: {
1984
+ type: "boolean",
1985
+ description: "Hides the toolbar that allows the user to clear selection",
1986
+ advanced: true,
1987
+ hidden: (ps) => !ps.canSelectRows || ps.canSelectRows === "none",
1988
+ defaultValueHint: true
1813
1989
  },
1814
- importName: "RichTable",
1815
- importPath: "@plasmicpkgs/plasmic-rich-components",
1990
+ scopeClassName: {
1991
+ type: "styleScopeClass",
1992
+ scopeName: "instance"
1993
+ },
1994
+ themeResetClassName: {
1995
+ type: "themeResetClass",
1996
+ targetAllTags: true
1997
+ }
1998
+ }),
1999
+ states: {
2000
+ selectedRowKey: __spreadValues$2({
2001
+ type: "writable",
2002
+ valueProp: "selectedRowKey",
2003
+ onChangeProp: "onRowSelectionChanged",
2004
+ variableType: "text"
2005
+ }, tableHelpers.states.selectedRowKey),
2006
+ selectedRow: __spreadValues$2({
2007
+ type: "readonly",
2008
+ onChangeProp: "onRowSelectionChanged",
2009
+ variableType: "object"
2010
+ }, tableHelpers.states.selectedRow),
2011
+ selectedRows: __spreadValues$2({
2012
+ type: "readonly",
2013
+ onChangeProp: "onRowSelectionChanged",
2014
+ variableType: "array"
2015
+ }, tableHelpers.states.selectedRows)
2016
+ },
2017
+ componentHelpers: {
2018
+ helpers: tableHelpers,
2019
+ importName: "tableHelpers",
2020
+ importPath: "@plasmicpkgs/plasmic-rich-components"
2021
+ },
2022
+ importName: "RichTable",
2023
+ importPath: "@plasmicpkgs/plasmic-rich-components"
1816
2024
  };
1817
2025
  function registerRichTable(loader) {
1818
- registerComponentHelper(loader, RichTable, dataTableMeta);
2026
+ registerComponentHelper(loader, RichTable, dataTableMeta);
1819
2027
  }
1820
2028
 
1821
- // Should really be using token colorFillTertiary instead of #8881.
1822
- 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";
2029
+ var __defProp$1 = Object.defineProperty;
2030
+ var __defProps = Object.defineProperties;
2031
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
2032
+ var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
2033
+ var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
2034
+ var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
2035
+ var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2036
+ var __spreadValues$1 = (a, b) => {
2037
+ for (var prop in b || (b = {}))
2038
+ if (__hasOwnProp$1.call(b, prop))
2039
+ __defNormalProp$1(a, prop, b[prop]);
2040
+ if (__getOwnPropSymbols$1)
2041
+ for (var prop of __getOwnPropSymbols$1(b)) {
2042
+ if (__propIsEnum$1.call(b, prop))
2043
+ __defNormalProp$1(a, prop, b[prop]);
2044
+ }
2045
+ return a;
2046
+ };
2047
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
2048
+ var __objRest = (source, exclude) => {
2049
+ var target = {};
2050
+ for (var prop in source)
2051
+ if (__hasOwnProp$1.call(source, prop) && exclude.indexOf(prop) < 0)
2052
+ target[prop] = source[prop];
2053
+ if (source != null && __getOwnPropSymbols$1)
2054
+ for (var prop of __getOwnPropSymbols$1(source)) {
2055
+ if (exclude.indexOf(prop) < 0 && __propIsEnum$1.call(source, prop))
2056
+ target[prop] = source[prop];
2057
+ }
2058
+ return target;
2059
+ };
2060
+ const listCss = `
2061
+ .plasmic-list--grid .ant-list-items {
2062
+ display: grid;
2063
+ grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
2064
+ gap: 16px;
2065
+ }
2066
+
2067
+ .plasmic-list-search {
2068
+ /* Matches RichTable search. */
2069
+ max-width: 200px;
2070
+ margin-bottom: 8px;
2071
+ }
2072
+
2073
+ .plasmic-list-item-content--unbordered {
2074
+ padding-left: 8px;
2075
+ padding-right: 8px;
2076
+ }
2077
+
2078
+ .plasmic-list-item--clickable:hover {
2079
+ background-color: #8881;
2080
+ }
2081
+
2082
+ .plasmic-list-item-image {
2083
+ max-width: 80px;
2084
+ max-height: 80px;
2085
+ aspect-ratio: 1/1;
2086
+ object-fit: cover;
2087
+ border-radius: 8px;
2088
+ }
2089
+
2090
+ /* Unsure why needed, but cards otherwise can be much narrower. */
2091
+ .plasmic-list-item-card {
2092
+ width: 100%;
2093
+ }
2094
+
2095
+ .plasmic-list-item-card-cover {
2096
+ max-height: 300px;
2097
+ aspect-ratio: 1/1;
2098
+ object-fit: cover;
2099
+ }
2100
+ `;
1823
2101
  function RichList(props) {
1824
- var _a = props.data, rawData = _a === void 0 ? {
1825
- data: [],
1826
- schema: {
1827
- id: "inferred",
1828
- fields: [
1829
- {
1830
- id: "id",
1831
- type: "string",
1832
- readOnly: false,
1833
- },
1834
- ],
1835
- },
1836
- } : _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"]);
1837
- var data = normalizeData(rawData);
1838
- var _f = useRoleDefinitions(data, props), normalized = _f.normalized, roleConfigs = _f.finalRoles;
1839
- useRef();
1840
- // Simply ignore the linkTo if it's not a function.
1841
- var linkTo = typeof props.linkTo === "function" ? props.linkTo : undefined;
1842
- var _g = useSortedFilteredData(data, normalized), finalData = _g.finalData, search = _g.search, setSearch = _g.setSearch; _g.setSortState;
1843
- var actuallyBordered = type === "list" ? bordered : false;
1844
- return (React.createElement("div", { className: className },
1845
- React.createElement("style", null, listCss),
1846
- !hideSearch && (React.createElement(Input.Search, { className: "plasmic-list-search", onChange: function (e) { return setSearch(e.target.value); }, value: search, placeholder: "Search" })),
1847
- React.createElement(List, { className: classNames({
1848
- // 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.
1849
- "plasmic-list--grid": type === "grid",
1850
- }), size: size, header: header, footer: footer, dataSource: finalData, itemLayout: "horizontal", bordered: actuallyBordered, pagination: pagination
1851
- ? {
1852
- pageSize: pageSize,
1853
- showSizeChanger: false,
1854
- }
1855
- : false, renderItem: function (record, index) {
1856
- var _a;
1857
- // Currently, actions are nested inside the list item / card, so can't have both linkTo and actions or else hydration error.
1858
- // Eventually can fork the Ant components to make the main linkTo area and actions not nest.
1859
- var actions = renderActions(rowActions, record, data, rowKey);
1860
- // actions={[
1861
- // <SettingOutlined key="setting" />,
1862
- // <EditOutlined key="edit" />,
1863
- // <EllipsisOutlined key="ellipsis" />,
1864
- // ]}
1865
- 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"
1866
- ? "plasmic-list-item-image"
1867
- : "plasmic-list-item-card-cover" })); });
1868
- 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) }));
1869
- function makeLinkWrapper() {
1870
- if ((actions !== null && actions !== void 0 ? actions : []).length > 0)
1871
- return undefined;
1872
- var href = linkTo === null || linkTo === void 0 ? void 0 : linkTo(record);
1873
- if (!href && !onRowClick)
1874
- return undefined;
1875
- var _linkWrapper = function (x) { return (React.createElement("a", { href: href, onClick: function (event) {
1876
- var key = deriveKeyOfRow(record, deriveRowKey(data, rowKey));
1877
- if (key != null &&
1878
- !isInteractable(event.target)) {
1879
- onRowClick === null || onRowClick === void 0 ? void 0 : onRowClick(key, record, event);
1880
- }
1881
- } }, x)); };
1882
- return _linkWrapper;
1883
- }
1884
- var linkWrapper = makeLinkWrapper();
1885
- var hasLink = !!linkWrapper;
1886
- function maybeLink(x) {
1887
- var _a;
1888
- return (_a = linkWrapper === null || linkWrapper === void 0 ? void 0 : linkWrapper(x)) !== null && _a !== void 0 ? _a : x;
2102
+ const _a = props, {
2103
+ data: rawData = {
2104
+ data: [],
2105
+ schema: {
2106
+ id: "inferred",
2107
+ fields: [
2108
+ {
2109
+ id: "id",
2110
+ type: "string",
2111
+ readOnly: false
2112
+ }
2113
+ ]
2114
+ }
2115
+ },
2116
+ type = "list",
2117
+ bordered = true,
2118
+ className,
2119
+ size,
2120
+ header,
2121
+ footer,
2122
+ rowActions = [],
2123
+ title,
2124
+ pageSize = 10,
2125
+ hideSearch,
2126
+ rowKey,
2127
+ pagination,
2128
+ onRowClick
2129
+ } = _a; __objRest(_a, [
2130
+ "data",
2131
+ "type",
2132
+ "bordered",
2133
+ "className",
2134
+ "size",
2135
+ "header",
2136
+ "footer",
2137
+ "rowActions",
2138
+ "title",
2139
+ "pageSize",
2140
+ "hideSearch",
2141
+ "rowKey",
2142
+ "pagination",
2143
+ "onRowClick"
2144
+ ]);
2145
+ const data = normalizeData(rawData);
2146
+ const { normalized, finalRoles: roleConfigs } = useRoleDefinitions(
2147
+ data,
2148
+ props
2149
+ );
2150
+ useRef();
2151
+ const linkTo = typeof props.linkTo === "function" ? props.linkTo : void 0;
2152
+ const { finalData, search, setSearch, setSortState } = useSortedFilteredData(
2153
+ data,
2154
+ normalized
2155
+ );
2156
+ const actuallyBordered = type === "list" ? bordered : false;
2157
+ return /* @__PURE__ */ React.createElement("div", { className }, /* @__PURE__ */ React.createElement("style", null, listCss), !hideSearch && /* @__PURE__ */ React.createElement(
2158
+ Input.Search,
2159
+ {
2160
+ className: "plasmic-list-search",
2161
+ onChange: (e) => setSearch(e.target.value),
2162
+ value: search,
2163
+ placeholder: "Search"
2164
+ }
2165
+ ), /* @__PURE__ */ React.createElement(
2166
+ List,
2167
+ {
2168
+ className: classNames({
2169
+ // 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.
2170
+ "plasmic-list--grid": type === "grid"
2171
+ }),
2172
+ size,
2173
+ header,
2174
+ footer,
2175
+ dataSource: finalData,
2176
+ itemLayout: "horizontal",
2177
+ bordered: actuallyBordered,
2178
+ pagination: pagination ? {
2179
+ pageSize,
2180
+ showSizeChanger: false
2181
+ } : false,
2182
+ renderItem: (record, index) => {
2183
+ var _a2;
2184
+ const actions = renderActions(rowActions, record, data, rowKey);
2185
+ const image = maybe(
2186
+ maybeRenderString(record, (_a2 = roleConfigs.image) == null ? void 0 : _a2[0]),
2187
+ (src) => /* @__PURE__ */ React.createElement(
2188
+ "img",
2189
+ {
2190
+ src,
2191
+ className: type === "list" ? "plasmic-list-item-image" : "plasmic-list-item-card-cover"
2192
+ }
2193
+ )
2194
+ );
2195
+ const content = /* @__PURE__ */ React.createElement(
2196
+ ListItemContent,
2197
+ {
2198
+ bordered: actuallyBordered,
2199
+ image: type === "list" ? image : void 0,
2200
+ title: multiRenderValue(record, roleConfigs.title),
2201
+ subtitle: multiRenderValue(record, roleConfigs.subtitle),
2202
+ beforeTitle: multiRenderValue(record, roleConfigs.beforeTitle),
2203
+ afterTitle: multiRenderValue(record, roleConfigs.afterTitle),
2204
+ content: multiRenderValue(record, roleConfigs.content)
2205
+ }
2206
+ );
2207
+ function makeLinkWrapper() {
2208
+ if ((actions != null ? actions : []).length > 0)
2209
+ return void 0;
2210
+ const href = linkTo == null ? void 0 : linkTo(record);
2211
+ if (!href && !onRowClick)
2212
+ return void 0;
2213
+ const _linkWrapper = (x) => /* @__PURE__ */ React.createElement(
2214
+ "a",
2215
+ {
2216
+ href,
2217
+ onClick: (event) => {
2218
+ const key = deriveKeyOfRow(
2219
+ record,
2220
+ deriveRowKey(data, rowKey)
2221
+ );
2222
+ if (key != null && !isInteractable(event.target)) {
2223
+ onRowClick == null ? void 0 : onRowClick(key, record, event);
1889
2224
  }
1890
- 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({
1891
- "plasmic-list-item--clickable": hasLink,
1892
- }) }, content)));
1893
- } })));
2225
+ }
2226
+ },
2227
+ x
2228
+ );
2229
+ return _linkWrapper;
2230
+ }
2231
+ const linkWrapper = makeLinkWrapper();
2232
+ const hasLink = !!linkWrapper;
2233
+ function maybeLink(x) {
2234
+ var _a3;
2235
+ return (_a3 = linkWrapper == null ? void 0 : linkWrapper(x)) != null ? _a3 : x;
2236
+ }
2237
+ return type === "grid" ? /* @__PURE__ */ React.createElement(List.Item, null, maybeLink(
2238
+ /* @__PURE__ */ React.createElement(
2239
+ Card,
2240
+ {
2241
+ className: "plasmic-list-item-card",
2242
+ size: "small",
2243
+ cover: image,
2244
+ hoverable: hasLink,
2245
+ actions
2246
+ },
2247
+ content
2248
+ )
2249
+ )) : maybeLink(
2250
+ /* @__PURE__ */ React.createElement(
2251
+ List.Item,
2252
+ {
2253
+ actions,
2254
+ className: classNames({
2255
+ "plasmic-list-item--clickable": hasLink
2256
+ })
2257
+ },
2258
+ content
2259
+ )
2260
+ );
2261
+ }
2262
+ }
2263
+ ));
1894
2264
  }
1895
2265
  function ListItemContent(_a) {
1896
- 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"]);
1897
- var prefixCls = "ant-list";
1898
- var classString = classNames("".concat(prefixCls, "-item-meta"), className);
1899
- return (React.createElement("div", __assign({}, others, { className: classNames({
1900
- "plasmic-list-item-content--unbordered": !bordered,
1901
- }, classString) }),
1902
- image && React.createElement("div", { className: "".concat(prefixCls, "-item-meta-avatar") }, image),
1903
- React.createElement("div", { className: "".concat(prefixCls, "-item-meta-content"), style: { display: "flex", flexDirection: "column", gap: 4 } },
1904
- beforeTitle && (React.createElement("div", null,
1905
- React.createElement(Tag, null, beforeTitle))),
1906
- React.createElement("div", { style: { display: "flex", gap: 8 } },
1907
- title && (React.createElement("h4", { className: "".concat(prefixCls, "-item-meta-title"), style: { margin: 0 } }, title)),
1908
- afterTitle && (React.createElement("div", { className: "".concat(prefixCls, "-item-meta-description") }, afterTitle))),
1909
- subtitle && (React.createElement("div", { className: "".concat(prefixCls, "-item-meta-description") }, subtitle)),
1910
- content && React.createElement("div", null, content))));
1911
- }
1912
- var defaultColumnConfig = function () {
1913
- return ({
1914
- key: mkShortId(),
1915
- isEditableExpr: function () { return false; },
1916
- disableSorting: false,
1917
- sortByExpr: undefined,
1918
- isHidden: false,
1919
- formatting: {
1920
- styles: {},
1921
- align: "left",
1922
- freeze: "off",
1923
- },
1924
- dataType: "auto",
1925
- role: undefined,
1926
- });
1927
- };
1928
- var roles = [
1929
- "content",
2266
+ var _b = _a, {
2267
+ className,
2268
+ title,
2269
+ subtitle,
2270
+ image,
2271
+ beforeTitle,
2272
+ afterTitle,
2273
+ content,
2274
+ bordered
2275
+ } = _b, others = __objRest(_b, [
2276
+ "className",
1930
2277
  "title",
1931
2278
  "subtitle",
2279
+ "image",
1932
2280
  "beforeTitle",
1933
2281
  "afterTitle",
1934
- "image",
1935
- "unset",
2282
+ "content",
2283
+ "bordered"
2284
+ ]);
2285
+ const prefixCls = "ant-list";
2286
+ const classString = classNames(`${prefixCls}-item-meta`, className);
2287
+ return /* @__PURE__ */ React.createElement(
2288
+ "div",
2289
+ __spreadProps(__spreadValues$1({}, others), {
2290
+ className: classNames(
2291
+ {
2292
+ "plasmic-list-item-content--unbordered": !bordered
2293
+ },
2294
+ classString
2295
+ )
2296
+ }),
2297
+ image && /* @__PURE__ */ React.createElement("div", { className: `${prefixCls}-item-meta-avatar` }, image),
2298
+ /* @__PURE__ */ React.createElement(
2299
+ "div",
2300
+ {
2301
+ className: `${prefixCls}-item-meta-content`,
2302
+ style: { display: "flex", flexDirection: "column", gap: 4 }
2303
+ },
2304
+ beforeTitle && /* @__PURE__ */ React.createElement("div", null, /* @__PURE__ */ React.createElement(Tag, null, beforeTitle)),
2305
+ /* @__PURE__ */ React.createElement("div", { style: { display: "flex", gap: 8 } }, title && /* @__PURE__ */ React.createElement(
2306
+ "h4",
2307
+ {
2308
+ className: `${prefixCls}-item-meta-title`,
2309
+ style: { margin: 0 }
2310
+ },
2311
+ title
2312
+ ), afterTitle && /* @__PURE__ */ React.createElement("div", { className: `${prefixCls}-item-meta-description` }, afterTitle)),
2313
+ subtitle && /* @__PURE__ */ React.createElement("div", { className: `${prefixCls}-item-meta-description` }, subtitle),
2314
+ content && /* @__PURE__ */ React.createElement("div", null, content)
2315
+ )
2316
+ );
2317
+ }
2318
+ const defaultColumnConfig = () => ({
2319
+ key: mkShortId(),
2320
+ isEditableExpr: () => false,
2321
+ disableSorting: false,
2322
+ sortByExpr: void 0,
2323
+ isHidden: false,
2324
+ formatting: {
2325
+ styles: {},
2326
+ align: "left",
2327
+ freeze: "off"
2328
+ },
2329
+ dataType: "auto",
2330
+ role: void 0
2331
+ });
2332
+ const roles = [
2333
+ "content",
2334
+ "title",
2335
+ "subtitle",
2336
+ "beforeTitle",
2337
+ "afterTitle",
2338
+ "image",
2339
+ "unset"
1936
2340
  ];
1937
- // 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.
1938
- //
1939
- // We first infer the defaults for each role.
1940
- // This we always need to do because we want the choices to be 'stable'.
1941
- // 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.
1942
- // 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).
1943
- //
1944
- // Then, we layer on the user role choices.
1945
- //
1946
- // One UX wart is that unsetting a role will restore the default selection instead of clearing it.
1947
- // User must know to actually set fieldId to none or (for arrays) remove the item.
1948
- // Just another reason to fill in few roles by default.
1949
2341
  function useRoleDefinitions(data, props) {
1950
- var fields = props.fields, setControlContextData = props.setControlContextData, rowActions = props.rowActions;
1951
- return React.useMemo(function () {
1952
- var _a, _b, _c, _d;
1953
- var schema = data === null || data === void 0 ? void 0 : data.schema;
1954
- 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]; }));
1955
- if (!data || !schema) {
1956
- return { normalized: [], roleConfigs: {}, finalRoles: {} };
1957
- }
1958
- function tagFieldConfigs(role) {
1959
- var _a;
1960
- if (role !== "unset") {
1961
- return ensureArray((_a = props[role]) !== null && _a !== void 0 ? _a : []).map(function (field) {
1962
- return __assign(__assign({}, field), { role: role });
1963
- });
1964
- }
1965
- else {
1966
- return [];
1967
- }
1968
- }
1969
- // This is only being computed to get the default role choices.
1970
- var _e = deriveFieldConfigs(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], tagFieldConfigs("image"), true), tagFieldConfigs("content"), true), tagFieldConfigs("title"), true), tagFieldConfigs("beforeTitle"), true), tagFieldConfigs("afterTitle"), true), tagFieldConfigs("subtitle"), true), schema, function (field) { return (__assign(__assign({}, defaultColumnConfig()), (field && {
1971
- key: field.id,
1972
- fieldId: field.id,
1973
- title: field.label || field.id,
1974
- // undefined means not yet determined in this routine, not 'unset'
1975
- role: undefined,
1976
- expr: function (currentItem) { return currentItem[field.id]; },
1977
- }))); }), mergedFields = _e.mergedFields, minimalFullLengthFields = _e.minimalFullLengthFields;
1978
- var normalized = mergedFields;
1979
- // Find a good default image field.
1980
- // 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.
1981
- // Of these, prefer the one with a name like image, picture, pic, img, avatar, profile, photo, icon.
1982
- // Otherwise, prefer the one with a title with that substring.
1983
- // Otherwise, pick any remaining one.
1984
- if (data.data.length > 0 &&
1985
- !mergedFields.some(function (field) { return field.role === "image"; })) {
1986
- var sampleRows_1 = Array.from(new Set([0, 1, 2, 3, 4, 5, 6, 7, 8, 9].map(function (i) {
1987
- return Math.round((i / 9) * (data.data.length - 1));
1988
- }))).map(function (i) { return data.data[i]; });
1989
- var imageFieldCandidates = mergedFields.filter(function (field) {
1990
- return !field.role &&
1991
- sampleRows_1.filter(function (row) { return field.fieldId && isLikeImage(row[field.fieldId]); }).length >=
1992
- sampleRows_1.length / 2;
1993
- });
1994
- var imageField = (_c = (_b = imageFieldCandidates.find(function (f) {
1995
- var _a;
1996
- return (_a = f.fieldId) === null || _a === void 0 ? void 0 : _a.match(/^(image|picture|pic|img|avatar|profile|photo|icon)$/i);
1997
- })) !== null && _b !== void 0 ? _b : imageFieldCandidates.find(function (f) {
1998
- var _a;
1999
- return (_a = f.fieldId) === null || _a === void 0 ? void 0 : _a.match(/.*(image|picture|pic|img|avatar|profile|photo|icon).*/i);
2000
- })) !== null && _c !== void 0 ? _c : imageFieldCandidates[0];
2001
- if (imageField) {
2002
- imageField.role = "image";
2003
- }
2004
- }
2005
- // Find a good default title field, just based on the field name.
2006
- if (!mergedFields.some(function (field) { return field.role === "title"; })) {
2007
- var titleField = mergedFields.find(function (field) {
2008
- var _a;
2009
- return !field.role &&
2010
- ((_a = field.fieldId) === null || _a === void 0 ? void 0 : _a.toLowerCase().match(/^(title|name|first[ _-]?name|full[ _-]?name)$/));
2011
- });
2012
- if (titleField) {
2013
- titleField.role = "title";
2014
- }
2342
+ const { fields, setControlContextData, rowActions } = props;
2343
+ return React.useMemo(() => {
2344
+ var _a, _b, _c, _d;
2345
+ const schema = data == null ? void 0 : data.schema;
2346
+ const schemaMap = new Map((_a = data == null ? void 0 : data.schema) == null ? void 0 : _a.fields.map((f) => [f.id, f]));
2347
+ if (!data || !schema) {
2348
+ return { normalized: [], roleConfigs: {}, finalRoles: {} };
2349
+ }
2350
+ function tagFieldConfigs(role) {
2351
+ var _a2;
2352
+ if (role !== "unset") {
2353
+ return ensureArray((_a2 = props[role]) != null ? _a2 : []).map((field) => {
2354
+ return __spreadProps(__spreadValues$1({}, field), {
2355
+ role
2356
+ });
2357
+ });
2358
+ } else {
2359
+ return [];
2360
+ }
2361
+ }
2362
+ const { mergedFields, minimalFullLengthFields } = deriveFieldConfigs(
2363
+ [
2364
+ ...tagFieldConfigs("image"),
2365
+ ...tagFieldConfigs("content"),
2366
+ ...tagFieldConfigs("title"),
2367
+ ...tagFieldConfigs("beforeTitle"),
2368
+ ...tagFieldConfigs("afterTitle"),
2369
+ ...tagFieldConfigs("subtitle")
2370
+ ],
2371
+ schema,
2372
+ (field) => __spreadValues$1(__spreadValues$1({}, defaultColumnConfig()), field && {
2373
+ key: field.id,
2374
+ fieldId: field.id,
2375
+ title: field.label || field.id,
2376
+ // undefined means not yet determined in this routine, not 'unset'
2377
+ role: void 0,
2378
+ expr: (currentItem) => currentItem[field.id]
2379
+ })
2380
+ );
2381
+ const normalized = mergedFields;
2382
+ if (data.data.length > 0 && !mergedFields.some((field) => field.role === "image")) {
2383
+ const sampleRows = Array.from(
2384
+ new Set(
2385
+ [0, 1, 2, 3, 4, 5, 6, 7, 8, 9].map(
2386
+ (i) => Math.round(i / 9 * (data.data.length - 1))
2387
+ )
2388
+ )
2389
+ ).map((i) => data.data[i]);
2390
+ const imageFieldCandidates = mergedFields.filter(
2391
+ (field) => !field.role && sampleRows.filter(
2392
+ (row) => field.fieldId && isLikeImage(row[field.fieldId])
2393
+ ).length >= sampleRows.length / 2
2394
+ );
2395
+ const imageField = (_c = (_b = imageFieldCandidates.find(
2396
+ (f) => {
2397
+ var _a2;
2398
+ return (_a2 = f.fieldId) == null ? void 0 : _a2.match(
2399
+ /^(image|picture|pic|img|avatar|profile|photo|icon)$/i
2400
+ );
2015
2401
  }
2016
- // Find a good default content field - just any remaining text field.
2017
- if (!mergedFields.some(function (field) { return field.role === "content"; })) {
2018
- var contentField = mergedFields.find(function (field) {
2019
- var _a;
2020
- return !field.role &&
2021
- field.fieldId &&
2022
- ((_a = schemaMap.get(field.fieldId)) === null || _a === void 0 ? void 0 : _a.type) === "string";
2023
- });
2024
- if (contentField) {
2025
- contentField.role = "content";
2026
- }
2402
+ )) != null ? _b : imageFieldCandidates.find(
2403
+ (f) => {
2404
+ var _a2;
2405
+ return (_a2 = f.fieldId) == null ? void 0 : _a2.match(
2406
+ /.*(image|picture|pic|img|avatar|profile|photo|icon).*/i
2407
+ );
2027
2408
  }
2028
- var roleConfigs = ensure(groupBy(mergedFields, function (f) { return f.role; }));
2029
- var finalRoles = {};
2030
- for (var _i = 0, roles_1 = roles; _i < roles_1.length; _i++) {
2031
- var role = roles_1[_i];
2032
- if (role !== "unset") {
2033
- finalRoles[role] = (_d = maybe(props[role], ensureArray)) !== null && _d !== void 0 ? _d : roleConfigs[role];
2034
- }
2409
+ )) != null ? _c : imageFieldCandidates[0];
2410
+ if (imageField) {
2411
+ imageField.role = "image";
2412
+ }
2413
+ }
2414
+ if (!mergedFields.some((field) => field.role === "title")) {
2415
+ const titleField = mergedFields.find(
2416
+ (field) => {
2417
+ var _a2;
2418
+ return !field.role && ((_a2 = field.fieldId) == null ? void 0 : _a2.toLowerCase().match(/^(title|name|first[ _-]?name|full[ _-]?name)$/));
2035
2419
  }
2036
- var fieldIdToRole = new Map(mergedFields.map(function (f) { return [f.fieldId, f.role]; }));
2037
- for (var _f = 0, minimalFullLengthFields_1 = minimalFullLengthFields; _f < minimalFullLengthFields_1.length; _f++) {
2038
- var f = minimalFullLengthFields_1[_f];
2039
- f.role = fieldIdToRole.get(f.fieldId);
2420
+ );
2421
+ if (titleField) {
2422
+ titleField.role = "title";
2423
+ }
2424
+ }
2425
+ if (!mergedFields.some((field) => field.role === "content")) {
2426
+ const contentField = mergedFields.find(
2427
+ (field) => {
2428
+ var _a2;
2429
+ return !field.role && field.fieldId && ((_a2 = schemaMap.get(field.fieldId)) == null ? void 0 : _a2.type) === "string";
2040
2430
  }
2041
- setControlContextData === null || setControlContextData === void 0 ? void 0 : setControlContextData(__assign(__assign({}, data), { mergedFields: mergedFields, minimalFullLengthFields: minimalFullLengthFields }));
2042
- return { normalized: normalized, roleConfigs: roleConfigs, finalRoles: finalRoles };
2043
- }, [fields, data, setControlContextData, rowActions]);
2431
+ );
2432
+ if (contentField) {
2433
+ contentField.role = "content";
2434
+ }
2435
+ }
2436
+ const roleConfigs = ensure(groupBy(mergedFields, (f) => f.role));
2437
+ const finalRoles = {};
2438
+ for (const role of roles) {
2439
+ if (role !== "unset") {
2440
+ finalRoles[role] = (_d = maybe(props[role], ensureArray)) != null ? _d : roleConfigs[role];
2441
+ }
2442
+ }
2443
+ const fieldIdToRole = new Map(mergedFields.map((f) => [f.fieldId, f.role]));
2444
+ for (const f of minimalFullLengthFields) {
2445
+ f.role = fieldIdToRole.get(f.fieldId);
2446
+ }
2447
+ setControlContextData == null ? void 0 : setControlContextData(__spreadProps(__spreadValues$1({}, data), { mergedFields, minimalFullLengthFields }));
2448
+ return { normalized, roleConfigs, finalRoles };
2449
+ }, [fields, data, setControlContextData, rowActions]);
2044
2450
  }
2045
2451
 
2046
- function roleProp(_a) {
2047
- 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;
2048
- return singular
2049
- ? {
2050
- type: "object",
2051
- displayName: displayName,
2052
- advanced: advanced,
2053
- hidden: function (ps) { return !ps.data; },
2054
- nameFunc: function (item) {
2055
- return maybe(item, function (i) {
2056
- return i.isHidden ? "Hidden" : i.fieldId || "Custom value";
2057
- });
2058
- },
2059
- fields: getFieldSubprops({
2060
- canChangeField: true,
2061
- noTitle: true,
2062
- }),
2063
- defaultValueHint: function (_props, contextData) {
2064
- var _a;
2065
- return ((_a = contextData === null || contextData === void 0 ? void 0 : contextData.minimalFullLengthFields) !== null && _a !== void 0 ? _a : []).find(function (f) { return f.role === role; });
2066
- },
2067
- }
2068
- : buildFieldsPropType({
2069
- displayName: displayName,
2070
- advanced: advanced,
2071
- noTitle: true,
2072
- canChangeField: true,
2073
- minimalValue: function (_props, contextData) {
2074
- var _a;
2075
- return ((_a = contextData === null || contextData === void 0 ? void 0 : contextData.minimalFullLengthFields) !== null && _a !== void 0 ? _a : []).filter(function (f) { return f.role === role; });
2076
- },
2077
- });
2452
+ var __defProp = Object.defineProperty;
2453
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
2454
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
2455
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
2456
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2457
+ var __spreadValues = (a, b) => {
2458
+ for (var prop in b || (b = {}))
2459
+ if (__hasOwnProp.call(b, prop))
2460
+ __defNormalProp(a, prop, b[prop]);
2461
+ if (__getOwnPropSymbols)
2462
+ for (var prop of __getOwnPropSymbols(b)) {
2463
+ if (__propIsEnum.call(b, prop))
2464
+ __defNormalProp(a, prop, b[prop]);
2465
+ }
2466
+ return a;
2467
+ };
2468
+ function roleProp({
2469
+ role,
2470
+ singular = false,
2471
+ advanced = false,
2472
+ displayName
2473
+ }) {
2474
+ return singular ? {
2475
+ type: "object",
2476
+ displayName,
2477
+ advanced,
2478
+ hidden: (ps) => !ps.data,
2479
+ nameFunc: (item) => maybe(
2480
+ item,
2481
+ (i) => i.isHidden ? "Hidden" : i.fieldId || "Custom value"
2482
+ ),
2483
+ fields: getFieldSubprops({
2484
+ canChangeField: true,
2485
+ noTitle: true
2486
+ }),
2487
+ defaultValueHint: (_props, contextData) => {
2488
+ var _a;
2489
+ return ((_a = contextData == null ? void 0 : contextData.minimalFullLengthFields) != null ? _a : []).find(
2490
+ (f) => f.role === role
2491
+ );
2492
+ }
2493
+ } : buildFieldsPropType({
2494
+ displayName,
2495
+ advanced,
2496
+ noTitle: true,
2497
+ canChangeField: true,
2498
+ minimalValue: (_props, contextData) => {
2499
+ var _a;
2500
+ return ((_a = contextData == null ? void 0 : contextData.minimalFullLengthFields) != null ? _a : []).filter(
2501
+ (f) => f.role === role
2502
+ );
2503
+ }
2504
+ });
2078
2505
  }
2079
- var richListMeta = {
2080
- name: "hostless-rich-list",
2081
- displayName: "Data List",
2082
- defaultStyles: {
2083
- width: "stretch",
2084
- padding: "16px",
2085
- maxHeight: "100%",
2506
+ const richListMeta = {
2507
+ name: "hostless-rich-list",
2508
+ displayName: "Data List",
2509
+ defaultStyles: {
2510
+ width: "stretch",
2511
+ padding: "16px",
2512
+ maxHeight: "100%"
2513
+ },
2514
+ templates: {
2515
+ grid: {
2516
+ props: {}
2517
+ }
2518
+ },
2519
+ props: __spreadValues({
2520
+ data: dataProp(),
2521
+ type: {
2522
+ type: "choice",
2523
+ options: [
2524
+ { value: "list", label: "List" },
2525
+ { value: "grid", label: "Grid" }
2526
+ ],
2527
+ defaultValueHint: "list"
2086
2528
  },
2087
- props: __assign({ data: dataProp(), type: {
2088
- type: "choice",
2089
- options: [
2090
- { value: "list", label: "List" },
2091
- { value: "grid", label: "Grid" },
2092
- ],
2093
- defaultValueHint: "list",
2094
- }, header: {
2095
- type: "slot",
2096
- hidePlaceholder: true,
2097
- }, footer: {
2098
- type: "slot",
2099
- hidePlaceholder: true,
2100
- }, title: roleProp({ role: "title" }), content: roleProp({ role: "content" }), image: roleProp({ role: "image", singular: true }), subtitle: roleProp({
2101
- role: "subtitle",
2102
- displayName: "Subtitle",
2103
- advanced: true,
2104
- }),
2105
- // Haven't styled these yet!
2106
- // beforeTitle: roleProp({ role: "beforeTitle", advanced: true }),
2107
- // afterTitle: roleProp({ role: "afterTitle", advanced: true }),
2108
- linkTo: {
2109
- type: "function",
2110
- control: {
2111
- type: "href",
2112
- },
2113
- argNames: ["currentItem"],
2114
- argValues: function (_props, ctx) { var _a; return [(_a = ctx === null || ctx === void 0 ? void 0 : ctx.data) === null || _a === void 0 ? void 0 : _a[0]]; },
2115
- }, onRowClick: onRowClickProp(), rowActions: rowActionsProp(), bordered: {
2116
- type: "boolean",
2117
- defaultValue: true,
2118
- hidden: function (ps) { var _a; return ((_a = ps.type) !== null && _a !== void 0 ? _a : "list") !== "list"; },
2119
- } }, commonProps()),
2120
- importName: "RichList",
2121
- importPath: "@plasmicpkgs/plasmic-rich-components",
2529
+ header: {
2530
+ type: "slot",
2531
+ hidePlaceholder: true
2532
+ },
2533
+ footer: {
2534
+ type: "slot",
2535
+ hidePlaceholder: true
2536
+ },
2537
+ title: roleProp({ role: "title" }),
2538
+ content: roleProp({ role: "content" }),
2539
+ image: roleProp({ role: "image", singular: true }),
2540
+ subtitle: roleProp({
2541
+ role: "subtitle",
2542
+ displayName: "Subtitle",
2543
+ advanced: true
2544
+ }),
2545
+ // Haven't styled these yet!
2546
+ // beforeTitle: roleProp({ role: "beforeTitle", advanced: true }),
2547
+ // afterTitle: roleProp({ role: "afterTitle", advanced: true }),
2548
+ linkTo: {
2549
+ type: "function",
2550
+ control: {
2551
+ type: "href"
2552
+ },
2553
+ argNames: ["currentItem"],
2554
+ argValues: (_props, ctx) => {
2555
+ var _a;
2556
+ return [(_a = ctx == null ? void 0 : ctx.data) == null ? void 0 : _a[0]];
2557
+ }
2558
+ },
2559
+ onRowClick: onRowClickProp(),
2560
+ rowActions: rowActionsProp(),
2561
+ bordered: {
2562
+ type: "boolean",
2563
+ defaultValue: true,
2564
+ hidden: (ps) => {
2565
+ var _a;
2566
+ return ((_a = ps.type) != null ? _a : "list") !== "list";
2567
+ }
2568
+ }
2569
+ }, commonProps()),
2570
+ importName: "RichList",
2571
+ importPath: "@plasmicpkgs/plasmic-rich-components"
2122
2572
  };
2123
2573
  function registerRichList(loader) {
2124
- registerComponentHelper(loader, RichList, richListMeta);
2574
+ registerComponentHelper(loader, RichList, richListMeta);
2125
2575
  }
2126
2576
 
2127
2577
  function registerAll(loader) {
2128
- registerRichLayout(loader);
2129
- registerRichList(loader);
2130
- registerRichTable(loader);
2131
- registerRichDetails(loader);
2578
+ registerRichLayout(loader);
2579
+ registerRichList(loader);
2580
+ registerRichTable(loader);
2581
+ registerRichDetails(loader);
2132
2582
  }
2133
2583
 
2134
2584
  export { RichDetails, RichLayout, RichList, RichTable, commonProps, dataProp, deriveKeyOfRow, deriveRowKey, ensureArray, isInteractable, isLikeImage, onRowClickProp, registerAll, renderActions, rowActionsProp, tableHelpers, useSortedFilteredData };