@plasmicpkgs/plasmic-rich-components 1.0.168 → 1.0.170

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.
Files changed (64) hide show
  1. package/dist/.tsbuildinfo +1 -1
  2. package/dist/index.js +7 -7
  3. package/dist/index.js.map +1 -1
  4. package/dist/plasmic-rich-components.esm.js +7 -7
  5. package/dist/plasmic-rich-components.esm.js.map +1 -1
  6. package/dist/rich-calendar/index.d.ts +1 -1
  7. package/package.json +20 -6
  8. package/skinny/common-8cca2977.esm.js +22 -0
  9. package/skinny/common-8cca2977.esm.js.map +1 -0
  10. package/skinny/common-e1d76791.cjs.js +30 -0
  11. package/skinny/common-e1d76791.cjs.js.map +1 -0
  12. package/skinny/common-prop-types-5f1fd4b0.cjs.js +139 -0
  13. package/skinny/common-prop-types-5f1fd4b0.cjs.js.map +1 -0
  14. package/skinny/common-prop-types-686c49fe.esm.js +133 -0
  15. package/skinny/common-prop-types-686c49fe.esm.js.map +1 -0
  16. package/skinny/common-prop-types.d.ts +12 -0
  17. package/skinny/common.d.ts +5 -0
  18. package/skinny/field-mappings.d.ts +100 -0
  19. package/skinny/field-react-utils-26fba31e.esm.js +142 -0
  20. package/skinny/field-react-utils-26fba31e.esm.js.map +1 -0
  21. package/skinny/field-react-utils-c717ec94.cjs.js +153 -0
  22. package/skinny/field-react-utils-c717ec94.cjs.js.map +1 -0
  23. package/skinny/field-react-utils.d.ts +34 -0
  24. package/skinny/formatting-327e0658.cjs.js +645 -0
  25. package/skinny/formatting-327e0658.cjs.js.map +1 -0
  26. package/skinny/formatting-aff39488.esm.js +633 -0
  27. package/skinny/formatting-aff39488.esm.js.map +1 -0
  28. package/skinny/formatting.d.ts +7 -0
  29. package/skinny/rich-calendar/RichCalendar.d.ts +31 -0
  30. package/skinny/rich-calendar/index.cjs.js +501 -0
  31. package/skinny/rich-calendar/index.cjs.js.map +1 -0
  32. package/skinny/rich-calendar/index.d.ts +15 -0
  33. package/skinny/rich-calendar/index.esm.js +488 -0
  34. package/skinny/rich-calendar/index.esm.js.map +1 -0
  35. package/skinny/rich-details/RichDetails.d.ts +12 -0
  36. package/skinny/rich-details/index.cjs.js +169 -0
  37. package/skinny/rich-details/index.cjs.js.map +1 -0
  38. package/skinny/rich-details/index.d.ts +3 -0
  39. package/skinny/rich-details/index.esm.js +162 -0
  40. package/skinny/rich-details/index.esm.js.map +1 -0
  41. package/skinny/rich-layout/RichLayout.d.ts +22 -0
  42. package/skinny/rich-layout/index.cjs.js +486 -0
  43. package/skinny/rich-layout/index.cjs.js.map +1 -0
  44. package/skinny/rich-layout/index.d.ts +5 -0
  45. package/skinny/rich-layout/index.esm.js +476 -0
  46. package/skinny/rich-layout/index.esm.js.map +1 -0
  47. package/skinny/rich-list/RichList.d.ts +59 -0
  48. package/skinny/rich-list/index.cjs.js +583 -0
  49. package/skinny/rich-list/index.cjs.js.map +1 -0
  50. package/skinny/rich-list/index.d.ts +5 -0
  51. package/skinny/rich-list/index.esm.js +571 -0
  52. package/skinny/rich-list/index.esm.js.map +1 -0
  53. package/skinny/rich-table/RichTable.d.ts +46 -0
  54. package/skinny/rich-table/index.cjs.js +598 -0
  55. package/skinny/rich-table/index.cjs.js.map +1 -0
  56. package/skinny/rich-table/index.d.ts +21 -0
  57. package/skinny/rich-table/index.esm.js +586 -0
  58. package/skinny/rich-table/index.esm.js.map +1 -0
  59. package/skinny/utils-65c486f0.cjs.js +139 -0
  60. package/skinny/utils-65c486f0.cjs.js.map +1 -0
  61. package/skinny/utils-c32bd7ed.esm.js +118 -0
  62. package/skinny/utils-c32bd7ed.esm.js.map +1 -0
  63. package/skinny/utils.d.ts +72 -0
  64. package/skinny/widgets.d.ts +2 -0
@@ -0,0 +1,633 @@
1
+ import { parseDate } from '@plasmicpkgs/luxon-parser';
2
+ import { Checkbox, Switch } from 'antd';
3
+ import React from 'react';
4
+ import { w as withoutFalsey, h as isOneOf, m as maybe } from './utils-c32bd7ed.esm.js';
5
+ import 'lodash/get';
6
+
7
+ var __defProp$1 = Object.defineProperty;
8
+ var __defProps$1 = Object.defineProperties;
9
+ var __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors;
10
+ var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
11
+ var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
12
+ var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
13
+ var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
14
+ var __spreadValues$1 = (a, b) => {
15
+ for (var prop in b || (b = {}))
16
+ if (__hasOwnProp$1.call(b, prop))
17
+ __defNormalProp$1(a, prop, b[prop]);
18
+ if (__getOwnPropSymbols$1)
19
+ for (var prop of __getOwnPropSymbols$1(b)) {
20
+ if (__propIsEnum$1.call(b, prop))
21
+ __defNormalProp$1(a, prop, b[prop]);
22
+ }
23
+ return a;
24
+ };
25
+ var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
26
+ var __objRest = (source, exclude) => {
27
+ var target = {};
28
+ for (var prop in source)
29
+ if (__hasOwnProp$1.call(source, prop) && exclude.indexOf(prop) < 0)
30
+ target[prop] = source[prop];
31
+ if (source != null && __getOwnPropSymbols$1)
32
+ for (var prop of __getOwnPropSymbols$1(source)) {
33
+ if (exclude.indexOf(prop) < 0 && __propIsEnum$1.call(source, prop))
34
+ target[prop] = source[prop];
35
+ }
36
+ return target;
37
+ };
38
+ const DEFAULT_CURRENCY_SETTINGS = {
39
+ dataType: "currency",
40
+ currency: "USD",
41
+ currencyDisplay: "narrowSymbol"
42
+ };
43
+ const NUMBER_TYPES = ["number", "percent", "currency"];
44
+ const DEFAULT_DATETIME_SETTINGS = {
45
+ dataType: "datetime",
46
+ locale: "en-US",
47
+ dateStyle: "short",
48
+ timeStyle: "short",
49
+ hour12: true
50
+ };
51
+ const DEFAULT_RELATIVE_DATETIME_SETTINGS = {
52
+ dataType: "relative-datetime",
53
+ locale: "en-US",
54
+ numeric: "always",
55
+ style: "long",
56
+ unit: "day"
57
+ };
58
+ const DATETIME_TYPES = ["datetime", "relative-datetime"];
59
+ const DEFAULT_BOOLEAN_SETTINGS = {
60
+ dataType: "boolean",
61
+ showAs: "checkbox"
62
+ };
63
+ function deriveValueType(cconfig) {
64
+ return cconfig.dataType === "auto" ? void 0 : cconfig.dataType === "string" ? "text" : cconfig.dataType === "number" ? "digit" : cconfig.dataType === "boolean" ? "switch" : void 0;
65
+ }
66
+ const NoneField = "||NoneField||";
67
+ const CustomField = "";
68
+ function getFieldSubprops(opts) {
69
+ return __spreadValues$1(__spreadValues$1({
70
+ key: {
71
+ type: "string",
72
+ hidden: () => true
73
+ },
74
+ fieldId: {
75
+ type: "choice",
76
+ displayName: "Field name",
77
+ readOnly: !opts.canChangeField,
78
+ options: (_props, ctx) => {
79
+ var _a, _b;
80
+ return withoutFalsey([
81
+ opts.canPickNoneField && { value: NoneField, label: "None" },
82
+ ...((_b = (_a = ctx == null ? void 0 : ctx.schema) == null ? void 0 : _a.fields) != null ? _b : []).map((f) => {
83
+ var _a2;
84
+ return {
85
+ value: f.id,
86
+ label: (_a2 = f.label) != null ? _a2 : f.id
87
+ };
88
+ }),
89
+ { value: CustomField, label: "Custom value" }
90
+ ]);
91
+ },
92
+ hidden: (ps, ctx, { path: _controlPath }) => {
93
+ if (opts.canChangeField) {
94
+ return false;
95
+ }
96
+ return true;
97
+ }
98
+ },
99
+ title: {
100
+ type: "string",
101
+ displayName: "Title",
102
+ defaultValueHint: getDefaultValueHint("title"),
103
+ hidden: () => !!opts.noTitle
104
+ },
105
+ expr: __spreadProps$1(__spreadValues$1({}, rowDataType("Custom value")), {
106
+ hidden: (ps, ctx, { item, path: _controlPath }) => {
107
+ return false;
108
+ }
109
+ }),
110
+ isHidden: {
111
+ type: "boolean",
112
+ displayName: "Is hidden",
113
+ defaultValueHint: getDefaultValueHint("isHidden")
114
+ }
115
+ }, !opts.noDataType ? {
116
+ dataType: {
117
+ type: "choice",
118
+ displayName: "Data type",
119
+ options: [
120
+ {
121
+ value: "auto",
122
+ label: "Auto"
123
+ },
124
+ {
125
+ value: "number",
126
+ label: "Number"
127
+ },
128
+ {
129
+ value: "percent",
130
+ label: "Percentage"
131
+ },
132
+ {
133
+ value: "currency",
134
+ label: "Currency"
135
+ },
136
+ {
137
+ value: "string",
138
+ label: "String"
139
+ },
140
+ {
141
+ value: "boolean",
142
+ label: "Boolean"
143
+ },
144
+ {
145
+ value: "datetime",
146
+ label: "Date / Time"
147
+ },
148
+ {
149
+ value: "relative-datetime",
150
+ label: "Date / Time relative to now"
151
+ }
152
+ ],
153
+ defaultValueHint: getDefaultValueHint("dataType")
154
+ },
155
+ currency: {
156
+ displayName: "Currency",
157
+ description: "Must be a valid currency code",
158
+ type: "string",
159
+ defaultValueHint: "USD",
160
+ hidden: (ps, ctx, { item }) => item.dataType !== "currency"
161
+ },
162
+ locale: {
163
+ displayName: "Locale",
164
+ description: "Must be a valid locale code",
165
+ type: "string",
166
+ defaultValueHint: "en-US",
167
+ hidden: (ps, ctx, { item }) => !isOneOf(item.dataType, NUMBER_TYPES) && !isOneOf(item.dataType, DATETIME_TYPES)
168
+ },
169
+ notation: {
170
+ displayName: "Notation",
171
+ type: "choice",
172
+ options: [
173
+ {
174
+ value: "standard",
175
+ label: "Standard"
176
+ },
177
+ {
178
+ value: "scientific",
179
+ label: "Scientific notation (like 1E3)"
180
+ },
181
+ {
182
+ value: "compact",
183
+ label: "Compact (like 10K)"
184
+ }
185
+ ],
186
+ defaultValueHint: "standard",
187
+ hidden: (ps, ctx, { item }) => !isOneOf(item.dataType, NUMBER_TYPES)
188
+ },
189
+ signDisplay: {
190
+ type: "choice",
191
+ displayName: "Number sign",
192
+ options: [
193
+ {
194
+ value: "auto",
195
+ label: "Only for negative numbers (10, -10)"
196
+ },
197
+ {
198
+ value: "exceptZero",
199
+ label: "Positive or negative (+10, -10)"
200
+ }
201
+ ],
202
+ defaultValueHint: "auto",
203
+ hidden: (ps, ctx, { item }) => !isOneOf(item.dataType, NUMBER_TYPES)
204
+ },
205
+ maximumFractionDigits: {
206
+ type: "number",
207
+ displayName: "Max decimal places",
208
+ defaultValueHint: 3,
209
+ min: 0,
210
+ max: 20,
211
+ hidden: (ps, ctx, { item }) => !isOneOf(item.dataType, NUMBER_TYPES)
212
+ },
213
+ minimumFractionDigits: {
214
+ type: "number",
215
+ displayName: "Min decimal places",
216
+ defaultValueHint: 0,
217
+ min: 0,
218
+ max: 20,
219
+ hidden: (ps, ctx, { item }) => !isOneOf(item.dataType, NUMBER_TYPES)
220
+ },
221
+ showAs: {
222
+ type: "choice",
223
+ options: [
224
+ {
225
+ value: "checkbox",
226
+ label: "Checkboxes"
227
+ },
228
+ {
229
+ value: "switch",
230
+ label: "Toggle switches"
231
+ },
232
+ {
233
+ value: "text",
234
+ label: "Text"
235
+ }
236
+ ],
237
+ displayName: "Show as",
238
+ defaultValueHint: "checkbox",
239
+ hidden: (ps, ctx, { item }) => item.dataType !== "boolean"
240
+ },
241
+ dateStyle: {
242
+ displayName: "Date style",
243
+ type: "choice",
244
+ options: [
245
+ {
246
+ value: "none",
247
+ label: "None (don't display date)"
248
+ },
249
+ {
250
+ value: "short",
251
+ label: "Short (like 12/25/2023)"
252
+ },
253
+ {
254
+ value: "medium",
255
+ label: "Medium (like Dec 25, 2023)"
256
+ },
257
+ {
258
+ value: "long",
259
+ label: "Long (like December 25, 2023)"
260
+ },
261
+ {
262
+ value: "full",
263
+ label: "Full (like Monday, December 25, 2023)"
264
+ }
265
+ ],
266
+ defaultValueHint: DEFAULT_DATETIME_SETTINGS.dateStyle,
267
+ hidden: (ps, ctx, { item }) => item.dataType !== "datetime"
268
+ },
269
+ timeStyle: {
270
+ displayName: "Time style",
271
+ type: "choice",
272
+ options: [
273
+ {
274
+ value: "none",
275
+ label: "None (don't display time)"
276
+ },
277
+ {
278
+ value: "short",
279
+ label: "Short (like 4:00 PM)"
280
+ },
281
+ {
282
+ value: "medium",
283
+ label: "Medium (like 4:00:00 PM)"
284
+ },
285
+ {
286
+ value: "long",
287
+ label: "Long (like 4:00:00 PM PST)"
288
+ },
289
+ {
290
+ value: "full",
291
+ label: "Full (like 4:00:00 PM Pacific Standard Time)"
292
+ }
293
+ ],
294
+ defaultValueHint: DEFAULT_DATETIME_SETTINGS.timeStyle,
295
+ hidden: (ps, ctx, { item }) => item.dataType !== "datetime"
296
+ },
297
+ hour12: {
298
+ displayName: "Use AM/PM?",
299
+ description: "Whether to use AM/PM or 24-hour clock",
300
+ type: "boolean",
301
+ defaultValueHint: DEFAULT_DATETIME_SETTINGS.hour12,
302
+ hidden: (ps, ctx, { item }) => item.dataType !== "datetime"
303
+ },
304
+ numeric: {
305
+ type: "choice",
306
+ displayName: "Use numbers?",
307
+ options: [
308
+ { value: "always", label: "Always use numbers" },
309
+ {
310
+ value: "auto",
311
+ label: "Use words like 'Yesterday' or 'Tomorrow'"
312
+ }
313
+ ],
314
+ defaultValueHint: DEFAULT_RELATIVE_DATETIME_SETTINGS.numeric,
315
+ hidden: (ps, ctx, { item }) => item.dataType !== "relative-datetime"
316
+ },
317
+ unit: {
318
+ type: "choice",
319
+ displayName: "Time unit",
320
+ options: [
321
+ {
322
+ value: "second",
323
+ label: "Seconds"
324
+ },
325
+ {
326
+ value: "minute",
327
+ label: "Minutes"
328
+ },
329
+ {
330
+ value: "hour",
331
+ label: "Hours"
332
+ },
333
+ {
334
+ value: "day",
335
+ label: "Days"
336
+ },
337
+ {
338
+ value: "week",
339
+ label: "Weeks"
340
+ },
341
+ {
342
+ value: "month",
343
+ label: "Months"
344
+ },
345
+ {
346
+ value: "year",
347
+ label: "Years"
348
+ }
349
+ ],
350
+ defaultValueHint: DEFAULT_RELATIVE_DATETIME_SETTINGS.unit,
351
+ hidden: (ps, ctx, { item }) => item.dataType !== "relative-datetime"
352
+ }
353
+ } : {}), opts.fieldTypes);
354
+ }
355
+ function getDefaultValueHint(field) {
356
+ return (_props, contextData, { item }) => {
357
+ if (item == null ? void 0 : item.fieldId) {
358
+ const fieldSetting = contextData == null ? void 0 : contextData.mergedFields.find(
359
+ (f) => f.fieldId === item.fieldId
360
+ );
361
+ return fieldSetting == null ? void 0 : fieldSetting[field];
362
+ }
363
+ return void 0;
364
+ };
365
+ }
366
+ const rowDataType = (displayName, control) => ({
367
+ type: "function",
368
+ displayName,
369
+ control,
370
+ argNames: ["currentItem", "currentValue"],
371
+ argValues: (_props, ctx, { item }) => {
372
+ var _a;
373
+ const row = (_a = ctx == null ? void 0 : ctx.data) == null ? void 0 : _a[0];
374
+ const cell = item.fieldId ? row == null ? void 0 : row[item.fieldId] : void 0;
375
+ return [row, cell];
376
+ }
377
+ });
378
+ function buildFieldsPropType(_a) {
379
+ var _b = _a, {
380
+ advanced,
381
+ displayName,
382
+ minimalValue = (_props, contextData) => contextData == null ? void 0 : contextData.minimalFullLengthFields
383
+ } = _b, opts = __objRest(_b, [
384
+ "advanced",
385
+ "displayName",
386
+ "minimalValue"
387
+ ]);
388
+ return {
389
+ type: "array",
390
+ advanced,
391
+ displayName,
392
+ hidden: (ps) => !ps.data,
393
+ unstable__keyFunc: (x) => x.key,
394
+ unstable__minimalValue: minimalValue,
395
+ unstable__canDelete: (ps, _props, ctx, { item }) => {
396
+ if (opts.canChangeField) {
397
+ return true;
398
+ }
399
+ if (!(ctx == null ? void 0 : ctx.schema)) {
400
+ return false;
401
+ }
402
+ if (item.fieldId && ctx.schema.fields.some((f) => f.id === item.fieldId)) {
403
+ return false;
404
+ }
405
+ return true;
406
+ },
407
+ itemType: {
408
+ type: "object",
409
+ nameFunc: (_item) => {
410
+ return _item.fieldId || _item.title || "Custom value";
411
+ },
412
+ fields: getFieldSubprops(opts)
413
+ }
414
+ };
415
+ }
416
+
417
+ var __defProp = Object.defineProperty;
418
+ var __defProps = Object.defineProperties;
419
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
420
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
421
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
422
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
423
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
424
+ var __spreadValues = (a, b) => {
425
+ for (var prop in b || (b = {}))
426
+ if (__hasOwnProp.call(b, prop))
427
+ __defNormalProp(a, prop, b[prop]);
428
+ if (__getOwnPropSymbols)
429
+ for (var prop of __getOwnPropSymbols(b)) {
430
+ if (__propIsEnum.call(b, prop))
431
+ __defNormalProp(a, prop, b[prop]);
432
+ }
433
+ return a;
434
+ };
435
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
436
+ function multiRenderValue(record, cconfigs) {
437
+ return cconfigs == null ? void 0 : cconfigs.flatMap(
438
+ (cc) => cc.isHidden ? [] : [` \u2022 `, /* @__PURE__ */ React.createElement(React.Fragment, null, renderValue(record, cc))]
439
+ ).slice(1);
440
+ }
441
+ function maybeRenderString(record, cconfig) {
442
+ return cconfig && !cconfig.isHidden ? maybe(getFieldValue(record, cconfig), asString) : void 0;
443
+ }
444
+ function getFieldValue(record, cconfig) {
445
+ let value = cconfig.fieldId ? record[cconfig.fieldId] : void 0;
446
+ if (cconfig.expr) {
447
+ value = cconfig.expr(record, value);
448
+ }
449
+ return value;
450
+ }
451
+ function getFieldAggregateValue(record, cconfigs, separator = ", ") {
452
+ if (!(cconfigs == null ? void 0 : cconfigs.length))
453
+ return void 0;
454
+ return (cconfigs == null ? void 0 : cconfigs.length) ? cconfigs.map((item) => getFieldValue(record, item)).join(separator) : void 0;
455
+ }
456
+ function renderValue(record, cconfig) {
457
+ const value = getFieldValue(record, cconfig);
458
+ if (value == null) {
459
+ return "";
460
+ }
461
+ if (cconfig.dataType === "auto") {
462
+ return renderAuto(value);
463
+ } else {
464
+ const coerced = coerceValue(value, cconfig.dataType);
465
+ if (isOneOf(cconfig.dataType, NUMBER_TYPES) && typeof coerced === "number") {
466
+ return renderNumber(coerced, cconfig);
467
+ } else if (cconfig.dataType === "boolean" && typeof coerced === "boolean") {
468
+ return renderBoolean(coerced, cconfig);
469
+ } else if (cconfig.dataType === "datetime" && coerced instanceof Date) {
470
+ return renderDate(coerced, cconfig);
471
+ } else if (cconfig.dataType === "relative-datetime" && coerced instanceof Date) {
472
+ return renderRelativeDate(coerced, cconfig);
473
+ }
474
+ return asString(value);
475
+ }
476
+ }
477
+ function renderAuto(value) {
478
+ if (typeof value === "number") {
479
+ return renderNumber(value, { dataType: "number" });
480
+ } else if (typeof value === "boolean") {
481
+ return renderBoolean(value, DEFAULT_BOOLEAN_SETTINGS);
482
+ } else if (value instanceof Date) {
483
+ return renderDate(value, DEFAULT_DATETIME_SETTINGS);
484
+ } else {
485
+ const coerced = tryCoerceAuto(value);
486
+ if (coerced === CANNOT_COERCE) {
487
+ return asString(value);
488
+ } else {
489
+ return renderAuto(coerced);
490
+ }
491
+ }
492
+ }
493
+ function tryCoerceAuto(value) {
494
+ for (const dataType of [
495
+ "number",
496
+ "datetime"
497
+ ]) {
498
+ const coerced = coerceValue(value, dataType);
499
+ if (coerced !== CANNOT_COERCE) {
500
+ return coerced;
501
+ }
502
+ }
503
+ return CANNOT_COERCE;
504
+ }
505
+ function renderNumber(value, cconfig) {
506
+ if (cconfig.dataType === "number") {
507
+ return new Intl.NumberFormat(cconfig.locale, cconfig).format(value);
508
+ } else if (cconfig.dataType === "percent") {
509
+ return new Intl.NumberFormat(cconfig.locale, __spreadProps(__spreadValues({}, cconfig), {
510
+ style: "percent"
511
+ })).format(value);
512
+ } else if (cconfig.dataType === "currency") {
513
+ return new Intl.NumberFormat(cconfig.locale, __spreadProps(__spreadValues(__spreadValues({}, DEFAULT_CURRENCY_SETTINGS), cconfig), {
514
+ style: "currency"
515
+ })).format(value);
516
+ } else {
517
+ throw new Error(`Unexpected dataType ${cconfig.dataType}`);
518
+ }
519
+ }
520
+ function renderDate(value, cconfig) {
521
+ const opts = __spreadValues(__spreadValues({}, DEFAULT_DATETIME_SETTINGS), cconfig);
522
+ if (opts.dateStyle === "none") {
523
+ delete opts["dateStyle"];
524
+ }
525
+ if (opts.timeStyle === "none") {
526
+ delete opts["timeStyle"];
527
+ }
528
+ return new Intl.DateTimeFormat(cconfig.locale, opts).format(value);
529
+ }
530
+ const SECOND_MS = 1e3;
531
+ const MINUTE_MS = 60 * SECOND_MS;
532
+ const HOUR_MS = 60 * MINUTE_MS;
533
+ const DAY_MS = 24 * HOUR_MS;
534
+ const WEEK_MS = 7 * DAY_MS;
535
+ const UNIT_TO_MS = {
536
+ second: SECOND_MS,
537
+ minute: MINUTE_MS,
538
+ hour: HOUR_MS,
539
+ day: DAY_MS,
540
+ week: WEEK_MS
541
+ };
542
+ const UNITS_BY_MS = Object.keys(UNIT_TO_MS);
543
+ function renderRelativeDate(value, cconfig) {
544
+ var _a;
545
+ const opts = __spreadValues(__spreadValues({}, DEFAULT_RELATIVE_DATETIME_SETTINGS), cconfig);
546
+ const unit = (_a = cconfig.unit) != null ? _a : "day";
547
+ const formatter = new Intl.RelativeTimeFormat(cconfig.locale, opts);
548
+ if (isOneOf(unit, UNITS_BY_MS)) {
549
+ const diff = value.getTime() - (/* @__PURE__ */ new Date()).getTime();
550
+ return formatter.format(Math.round(diff / UNIT_TO_MS[unit]), unit);
551
+ } else {
552
+ if (unit === "year") {
553
+ const diff = value.getFullYear() - (/* @__PURE__ */ new Date()).getFullYear();
554
+ return formatter.format(diff, unit);
555
+ } else if (unit === "month") {
556
+ const months = (d) => d.getFullYear() * 12 + d.getMonth() + 1;
557
+ const diff = months(value) - months(/* @__PURE__ */ new Date());
558
+ return formatter.format(diff, unit);
559
+ } else {
560
+ throw new Error(`Unexpected relative time unit ${unit}`);
561
+ }
562
+ }
563
+ }
564
+ function renderBoolean(value, cconfig) {
565
+ var _a;
566
+ const showAs = (_a = cconfig.showAs) != null ? _a : DEFAULT_BOOLEAN_SETTINGS.showAs;
567
+ if (showAs === "checkbox") {
568
+ return /* @__PURE__ */ React.createElement(Checkbox, { checked: value });
569
+ } else if (showAs === "switch") {
570
+ return /* @__PURE__ */ React.createElement(Switch, { checked: value });
571
+ } else {
572
+ return value ? "true" : "false";
573
+ }
574
+ }
575
+ const CANNOT_COERCE = Symbol("plasmic-cannot-coerce");
576
+ function coerceValue(value, dataType) {
577
+ if (value == null) {
578
+ return null;
579
+ }
580
+ try {
581
+ if (isOneOf(dataType, NUMBER_TYPES)) {
582
+ if (typeof value === "number") {
583
+ return value;
584
+ } else if (typeof value === "string") {
585
+ const maybeNumber = +value;
586
+ if (!isNaN(maybeNumber)) {
587
+ return maybeNumber;
588
+ }
589
+ }
590
+ } else if (isOneOf(dataType, DATETIME_TYPES)) {
591
+ if (value instanceof Date) {
592
+ return value;
593
+ } else if (typeof value === "number") {
594
+ return new Date(value);
595
+ } else if (typeof value === "string") {
596
+ const parsed = parseDate(value);
597
+ return parsed ? parsed : CANNOT_COERCE;
598
+ }
599
+ } else if (dataType === "boolean") {
600
+ if (value === true || value === false) {
601
+ return value;
602
+ } else if (typeof value === "number") {
603
+ return value !== 0;
604
+ } else if (typeof value === "string") {
605
+ return value.toLowerCase() === "true";
606
+ }
607
+ } else if (dataType === "string") {
608
+ return asString(value);
609
+ } else if (dataType === "auto") {
610
+ return value;
611
+ }
612
+ } catch (err) {
613
+ }
614
+ return CANNOT_COERCE;
615
+ }
616
+ function asString(value) {
617
+ if (value == null) {
618
+ return "";
619
+ } else if (typeof value === "string") {
620
+ return value;
621
+ } else if (typeof value === "object") {
622
+ if ("toString" in value && typeof value.toString === "function") {
623
+ return value.toString();
624
+ } else {
625
+ return JSON.stringify(value);
626
+ }
627
+ } else {
628
+ return `${value}`;
629
+ }
630
+ }
631
+
632
+ export { multiRenderValue as a, buildFieldsPropType as b, getFieldSubprops as c, deriveValueType as d, getFieldAggregateValue as g, maybeRenderString as m, renderValue as r };
633
+ //# sourceMappingURL=formatting-aff39488.esm.js.map