@plasmicpkgs/plasmic-rich-components 1.0.74 → 1.0.76
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/field-mappings.d.ts +69 -25
- package/dist/formatting.d.ts +3 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +907 -276
- package/dist/index.js.map +1 -1
- package/dist/plasmic-rich-components.esm.js +907 -277
- package/dist/plasmic-rich-components.esm.js.map +1 -1
- package/dist/queries.d.ts +10 -0
- package/dist/rich-details/RichDetails.d.ts +12 -0
- package/dist/rich-details/index.d.ts +3 -0
- package/dist/rich-table/RichTable.d.ts +16 -13
- package/dist/utils.d.ts +2 -0
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -1,19 +1,18 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var React = require('react');
|
|
4
3
|
var registerComponent = require('@plasmicapp/host/registerComponent');
|
|
5
4
|
require('@plasmicapp/host/registerGlobalContext');
|
|
6
|
-
var icons = require('@ant-design/icons');
|
|
7
5
|
var proComponents = require('@ant-design/pro-components');
|
|
6
|
+
var React = require('react');
|
|
8
7
|
var antd = require('antd');
|
|
9
|
-
var
|
|
8
|
+
var icons = require('@ant-design/icons');
|
|
10
9
|
var csvWriterBrowser = require('csv-writer-browser');
|
|
11
10
|
var fastStringify = require('fast-stringify');
|
|
12
11
|
|
|
13
12
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
14
13
|
|
|
15
|
-
var React__default = /*#__PURE__*/_interopDefault(React);
|
|
16
14
|
var registerComponent__default = /*#__PURE__*/_interopDefault(registerComponent);
|
|
15
|
+
var React__default = /*#__PURE__*/_interopDefault(React);
|
|
17
16
|
var fastStringify__default = /*#__PURE__*/_interopDefault(fastStringify);
|
|
18
17
|
|
|
19
18
|
/*! *****************************************************************************
|
|
@@ -102,6 +101,843 @@ function __spreadArray(to, from, pack) {
|
|
|
102
101
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
103
102
|
}
|
|
104
103
|
|
|
104
|
+
function registerComponentHelper(loader, component, meta) {
|
|
105
|
+
if (loader) {
|
|
106
|
+
loader.registerComponent(component, meta);
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
registerComponent__default.default(component, meta);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
function isOneOf(elem, arr) {
|
|
113
|
+
return arr.includes(elem);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
var tuple = function () {
|
|
117
|
+
var args = [];
|
|
118
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
119
|
+
args[_i] = arguments[_i];
|
|
120
|
+
}
|
|
121
|
+
return args;
|
|
122
|
+
};
|
|
123
|
+
function mkIdMap(xs) {
|
|
124
|
+
return new Map(xs.map(function (x) { return tuple(x.id, x); }));
|
|
125
|
+
}
|
|
126
|
+
var mkShortId = function () { return "".concat(Math.random()); };
|
|
127
|
+
function withoutNils(xs) {
|
|
128
|
+
return xs.filter(function (x) { return x != null; });
|
|
129
|
+
}
|
|
130
|
+
var DEFAULT_CURRENCY_SETTINGS = {
|
|
131
|
+
dataType: "currency",
|
|
132
|
+
currency: "USD",
|
|
133
|
+
currencyDisplay: "narrowSymbol",
|
|
134
|
+
};
|
|
135
|
+
var NUMBER_TYPES = ["number", "percent", "currency"];
|
|
136
|
+
var DEFAULT_DATETIME_SETTINGS = {
|
|
137
|
+
dataType: "datetime",
|
|
138
|
+
locale: "en-US",
|
|
139
|
+
dateStyle: "short",
|
|
140
|
+
timeStyle: "short",
|
|
141
|
+
hour12: true,
|
|
142
|
+
};
|
|
143
|
+
var DEFAULT_RELATIVE_DATETIME_SETTINGS = {
|
|
144
|
+
dataType: "relative-datetime",
|
|
145
|
+
locale: "en-US",
|
|
146
|
+
numeric: "always",
|
|
147
|
+
style: "long",
|
|
148
|
+
unit: "day",
|
|
149
|
+
};
|
|
150
|
+
var DATETIME_TYPES = ["datetime", "relative-datetime"];
|
|
151
|
+
var DEFAULT_BOOLEAN_SETTINGS = {
|
|
152
|
+
dataType: "boolean",
|
|
153
|
+
showAs: "checkbox",
|
|
154
|
+
};
|
|
155
|
+
function deriveFieldConfigs(specifiedFieldsPartial, schema, makeDefaultConfig) {
|
|
156
|
+
var _a;
|
|
157
|
+
var schemaFields = (_a = schema === null || schema === void 0 ? void 0 : schema.fields) !== null && _a !== void 0 ? _a : [];
|
|
158
|
+
var fieldById = mkIdMap(schemaFields);
|
|
159
|
+
var specifiedFieldIds = new Set(withoutNils(specifiedFieldsPartial.map(function (f) { return f.fieldId; })));
|
|
160
|
+
var keptSpecifiedFields = specifiedFieldsPartial.flatMap(function (f, index) {
|
|
161
|
+
var fieldId = f.fieldId;
|
|
162
|
+
if (!fieldId) {
|
|
163
|
+
return [
|
|
164
|
+
__assign(__assign(__assign({}, makeDefaultConfig(undefined)), { key: index }), f),
|
|
165
|
+
];
|
|
166
|
+
}
|
|
167
|
+
var field = fieldById.get(fieldId);
|
|
168
|
+
// Drop configs with fieldIds no longer in the data.
|
|
169
|
+
if (!field) {
|
|
170
|
+
return [];
|
|
171
|
+
}
|
|
172
|
+
return [
|
|
173
|
+
__assign(__assign({}, makeDefaultConfig(field)), f),
|
|
174
|
+
];
|
|
175
|
+
});
|
|
176
|
+
var newVirtualFields = schemaFields
|
|
177
|
+
.filter(function (f) { return !specifiedFieldIds.has(f.id); })
|
|
178
|
+
.map(function (f) { return (__assign({}, makeDefaultConfig(f))); });
|
|
179
|
+
var mergedFields = __spreadArray(__spreadArray([], keptSpecifiedFields, true), newVirtualFields, true);
|
|
180
|
+
var minimalFullLengthFields = __spreadArray(__spreadArray([], specifiedFieldsPartial, true), newVirtualFields.map(function (f) { return ({ key: f.key, fieldId: f.fieldId }); }), true);
|
|
181
|
+
return { mergedFields: mergedFields, minimalFullLengthFields: minimalFullLengthFields };
|
|
182
|
+
}
|
|
183
|
+
function deriveValueType(cconfig) {
|
|
184
|
+
return cconfig.dataType === "auto"
|
|
185
|
+
? undefined
|
|
186
|
+
: cconfig.dataType === "string"
|
|
187
|
+
? "text"
|
|
188
|
+
: cconfig.dataType === "number"
|
|
189
|
+
? "digit"
|
|
190
|
+
: cconfig.dataType === "boolean"
|
|
191
|
+
? "switch"
|
|
192
|
+
: undefined;
|
|
193
|
+
}
|
|
194
|
+
function buildFieldsPropType(opts) {
|
|
195
|
+
function getDefaultValueHint(field) {
|
|
196
|
+
return function (_item, contextData) {
|
|
197
|
+
if (_item.fieldId) {
|
|
198
|
+
var fieldSetting = contextData === null || contextData === void 0 ? void 0 : contextData.mergedFields.find(function (f) { return f.fieldId === _item.fieldId; });
|
|
199
|
+
return fieldSetting === null || fieldSetting === void 0 ? void 0 : fieldSetting[field];
|
|
200
|
+
}
|
|
201
|
+
return undefined;
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
var rowDataType = function (displayName, control) {
|
|
205
|
+
return ({
|
|
206
|
+
type: "function",
|
|
207
|
+
displayName: displayName,
|
|
208
|
+
control: control,
|
|
209
|
+
argNames: ["currentItem", "currentValue"],
|
|
210
|
+
argValues: function (_props, ctx) {
|
|
211
|
+
var _a;
|
|
212
|
+
var row = (_a = ctx === null || ctx === void 0 ? void 0 : ctx.data) === null || _a === void 0 ? void 0 : _a[0];
|
|
213
|
+
var cell = _props.fieldId ? row === null || row === void 0 ? void 0 : row[_props.fieldId] : undefined;
|
|
214
|
+
return [row, cell];
|
|
215
|
+
},
|
|
216
|
+
});
|
|
217
|
+
};
|
|
218
|
+
return {
|
|
219
|
+
type: "array",
|
|
220
|
+
hidden: function (ps) { return !ps.data; },
|
|
221
|
+
unstable__keyFunc: function (x) { return x.key; },
|
|
222
|
+
unstable__minimalValue: function (_props, contextData) {
|
|
223
|
+
return contextData === null || contextData === void 0 ? void 0 : contextData.minimalFullLengthFields;
|
|
224
|
+
},
|
|
225
|
+
unstable__canDelete: function (ps, _props, ctx, _a) {
|
|
226
|
+
var item = _a.item;
|
|
227
|
+
if (!(ctx === null || ctx === void 0 ? void 0 : ctx.schema)) {
|
|
228
|
+
// still loading...
|
|
229
|
+
return false;
|
|
230
|
+
}
|
|
231
|
+
if (item.fieldId &&
|
|
232
|
+
ctx.schema.fields.some(function (f) { return f.id === item.fieldId; })) {
|
|
233
|
+
return false;
|
|
234
|
+
}
|
|
235
|
+
return true;
|
|
236
|
+
},
|
|
237
|
+
itemType: {
|
|
238
|
+
type: "object",
|
|
239
|
+
nameFunc: function (_item) {
|
|
240
|
+
var _a;
|
|
241
|
+
return (_a = _item.title) !== null && _a !== void 0 ? _a : _item.fieldId;
|
|
242
|
+
},
|
|
243
|
+
fields: __assign({ key: {
|
|
244
|
+
type: "string",
|
|
245
|
+
hidden: function () { return true; },
|
|
246
|
+
}, fieldId: {
|
|
247
|
+
type: "choice",
|
|
248
|
+
displayName: "Field name",
|
|
249
|
+
readOnly: true,
|
|
250
|
+
options: function (_props, ctx) { var _a, _b; return ((_b = (_a = ctx === null || ctx === void 0 ? void 0 : ctx.schema) === null || _a === void 0 ? void 0 : _a.fields) !== null && _b !== void 0 ? _b : []).map(function (f) { return f.id; }); },
|
|
251
|
+
hidden: function (_props, ctx, _a) {
|
|
252
|
+
var _b, _c;
|
|
253
|
+
var _controlPath = _a.path;
|
|
254
|
+
return !(_controlPath.slice(-1)[0] in ((_c = (_b = ctx === null || ctx === void 0 ? void 0 : ctx.schema) === null || _b === void 0 ? void 0 : _b.fields) !== null && _c !== void 0 ? _c : {}));
|
|
255
|
+
},
|
|
256
|
+
}, title: {
|
|
257
|
+
type: "string",
|
|
258
|
+
displayName: "Title",
|
|
259
|
+
defaultValueHint: getDefaultValueHint("title"),
|
|
260
|
+
}, expr: rowDataType("Customize data"), isHidden: {
|
|
261
|
+
type: "boolean",
|
|
262
|
+
displayName: "Is hidden",
|
|
263
|
+
defaultValueHint: getDefaultValueHint("isHidden"),
|
|
264
|
+
}, dataType: {
|
|
265
|
+
type: "choice",
|
|
266
|
+
displayName: "Data type",
|
|
267
|
+
options: [
|
|
268
|
+
{
|
|
269
|
+
value: "auto",
|
|
270
|
+
label: "Auto",
|
|
271
|
+
},
|
|
272
|
+
{
|
|
273
|
+
value: "number",
|
|
274
|
+
label: "Number",
|
|
275
|
+
},
|
|
276
|
+
{
|
|
277
|
+
value: "percent",
|
|
278
|
+
label: "Percentage",
|
|
279
|
+
},
|
|
280
|
+
{
|
|
281
|
+
value: "currency",
|
|
282
|
+
label: "Currency",
|
|
283
|
+
},
|
|
284
|
+
{
|
|
285
|
+
value: "string",
|
|
286
|
+
label: "String",
|
|
287
|
+
},
|
|
288
|
+
{
|
|
289
|
+
value: "boolean",
|
|
290
|
+
label: "Boolean",
|
|
291
|
+
},
|
|
292
|
+
{
|
|
293
|
+
value: "datetime",
|
|
294
|
+
label: "Date / Time",
|
|
295
|
+
},
|
|
296
|
+
{
|
|
297
|
+
value: "relative-datetime",
|
|
298
|
+
label: "Date / Time relative to now",
|
|
299
|
+
},
|
|
300
|
+
],
|
|
301
|
+
defaultValueHint: getDefaultValueHint("dataType"),
|
|
302
|
+
}, currency: {
|
|
303
|
+
displayName: "Currency",
|
|
304
|
+
description: "Must be a valid currency code",
|
|
305
|
+
type: "string",
|
|
306
|
+
defaultValueHint: "USD",
|
|
307
|
+
hidden: function (ps, ctx, _a) {
|
|
308
|
+
var item = _a.item;
|
|
309
|
+
return item.dataType !== "currency";
|
|
310
|
+
},
|
|
311
|
+
}, locale: {
|
|
312
|
+
displayName: "Locale",
|
|
313
|
+
description: "Must be a valid locale code",
|
|
314
|
+
type: "string",
|
|
315
|
+
defaultValueHint: "en-US",
|
|
316
|
+
hidden: function (ps, ctx, _a) {
|
|
317
|
+
var item = _a.item;
|
|
318
|
+
return !isOneOf(item.dataType, NUMBER_TYPES) &&
|
|
319
|
+
!isOneOf(item.dataType, DATETIME_TYPES);
|
|
320
|
+
},
|
|
321
|
+
}, notation: {
|
|
322
|
+
displayName: "Notation",
|
|
323
|
+
type: "choice",
|
|
324
|
+
options: [
|
|
325
|
+
{
|
|
326
|
+
value: "standard",
|
|
327
|
+
label: "Standard",
|
|
328
|
+
},
|
|
329
|
+
{
|
|
330
|
+
value: "scientific",
|
|
331
|
+
label: "Scientific notation (like 1E3)",
|
|
332
|
+
},
|
|
333
|
+
{
|
|
334
|
+
value: "compact",
|
|
335
|
+
label: "Compact (like 10K)",
|
|
336
|
+
},
|
|
337
|
+
],
|
|
338
|
+
defaultValueHint: "standard",
|
|
339
|
+
hidden: function (ps, ctx, _a) {
|
|
340
|
+
var item = _a.item;
|
|
341
|
+
return !isOneOf(item.dataType, NUMBER_TYPES);
|
|
342
|
+
},
|
|
343
|
+
}, signDisplay: {
|
|
344
|
+
type: "choice",
|
|
345
|
+
displayName: "Number sign",
|
|
346
|
+
options: [
|
|
347
|
+
{
|
|
348
|
+
value: "auto",
|
|
349
|
+
label: "Only for negative numbers (10, -10)",
|
|
350
|
+
},
|
|
351
|
+
{
|
|
352
|
+
value: "exceptZero",
|
|
353
|
+
label: "Positive or negative (+10, -10)",
|
|
354
|
+
},
|
|
355
|
+
],
|
|
356
|
+
defaultValueHint: "auto",
|
|
357
|
+
hidden: function (ps, ctx, _a) {
|
|
358
|
+
var item = _a.item;
|
|
359
|
+
return !isOneOf(item.dataType, NUMBER_TYPES);
|
|
360
|
+
},
|
|
361
|
+
}, maximumFractionDigits: {
|
|
362
|
+
type: "number",
|
|
363
|
+
displayName: "Max decimal places",
|
|
364
|
+
defaultValueHint: 3,
|
|
365
|
+
min: 0,
|
|
366
|
+
max: 20,
|
|
367
|
+
hidden: function (ps, ctx, _a) {
|
|
368
|
+
var item = _a.item;
|
|
369
|
+
return !isOneOf(item.dataType, NUMBER_TYPES);
|
|
370
|
+
},
|
|
371
|
+
}, minimumFractionDigits: {
|
|
372
|
+
type: "number",
|
|
373
|
+
displayName: "Min decimal places",
|
|
374
|
+
defaultValueHint: 0,
|
|
375
|
+
min: 0,
|
|
376
|
+
max: 20,
|
|
377
|
+
hidden: function (ps, ctx, _a) {
|
|
378
|
+
var item = _a.item;
|
|
379
|
+
return !isOneOf(item.dataType, NUMBER_TYPES);
|
|
380
|
+
},
|
|
381
|
+
}, showAs: {
|
|
382
|
+
type: "choice",
|
|
383
|
+
options: [
|
|
384
|
+
{
|
|
385
|
+
value: "checkbox",
|
|
386
|
+
label: "Checkboxes",
|
|
387
|
+
},
|
|
388
|
+
{
|
|
389
|
+
value: "switch",
|
|
390
|
+
label: "Toggle switches",
|
|
391
|
+
},
|
|
392
|
+
{
|
|
393
|
+
value: "text",
|
|
394
|
+
label: "Text",
|
|
395
|
+
},
|
|
396
|
+
],
|
|
397
|
+
displayName: "Show as",
|
|
398
|
+
defaultValueHint: "checkbox",
|
|
399
|
+
hidden: function (ps, ctx, _a) {
|
|
400
|
+
var item = _a.item;
|
|
401
|
+
return item.dataType !== "boolean";
|
|
402
|
+
},
|
|
403
|
+
}, dateStyle: {
|
|
404
|
+
displayName: "Date style",
|
|
405
|
+
type: "choice",
|
|
406
|
+
options: [
|
|
407
|
+
{
|
|
408
|
+
value: "none",
|
|
409
|
+
label: "None (don't display date)",
|
|
410
|
+
},
|
|
411
|
+
{
|
|
412
|
+
value: "short",
|
|
413
|
+
label: "Short (like 12/25/2023)",
|
|
414
|
+
},
|
|
415
|
+
{
|
|
416
|
+
value: "medium",
|
|
417
|
+
label: "Medium (like Dec 25, 2023)",
|
|
418
|
+
},
|
|
419
|
+
{
|
|
420
|
+
value: "long",
|
|
421
|
+
label: "Long (like December 25, 2023)",
|
|
422
|
+
},
|
|
423
|
+
{
|
|
424
|
+
value: "full",
|
|
425
|
+
label: "Full (like Monday, December 25, 2023)",
|
|
426
|
+
},
|
|
427
|
+
],
|
|
428
|
+
defaultValueHint: DEFAULT_DATETIME_SETTINGS.dateStyle,
|
|
429
|
+
hidden: function (ps, ctx, _a) {
|
|
430
|
+
var item = _a.item;
|
|
431
|
+
return item.dataType !== "datetime";
|
|
432
|
+
},
|
|
433
|
+
}, timeStyle: {
|
|
434
|
+
displayName: "Time style",
|
|
435
|
+
type: "choice",
|
|
436
|
+
options: [
|
|
437
|
+
{
|
|
438
|
+
value: "none",
|
|
439
|
+
label: "None (don't display time)",
|
|
440
|
+
},
|
|
441
|
+
{
|
|
442
|
+
value: "short",
|
|
443
|
+
label: "Short (like 4:00 PM)",
|
|
444
|
+
},
|
|
445
|
+
{
|
|
446
|
+
value: "medium",
|
|
447
|
+
label: "Medium (like 4:00:00 PM)",
|
|
448
|
+
},
|
|
449
|
+
{
|
|
450
|
+
value: "long",
|
|
451
|
+
label: "Long (like 4:00:00 PM PST)",
|
|
452
|
+
},
|
|
453
|
+
{
|
|
454
|
+
value: "full",
|
|
455
|
+
label: "Full (like 4:00:00 PM Pacific Standard Time)",
|
|
456
|
+
},
|
|
457
|
+
],
|
|
458
|
+
defaultValueHint: DEFAULT_DATETIME_SETTINGS.timeStyle,
|
|
459
|
+
hidden: function (ps, ctx, _a) {
|
|
460
|
+
var item = _a.item;
|
|
461
|
+
return item.dataType !== "datetime";
|
|
462
|
+
},
|
|
463
|
+
}, hour12: {
|
|
464
|
+
displayName: "Use AM/PM?",
|
|
465
|
+
description: "Whether to use AM/PM or 24-hour clock",
|
|
466
|
+
type: "boolean",
|
|
467
|
+
defaultValueHint: DEFAULT_DATETIME_SETTINGS.hour12,
|
|
468
|
+
hidden: function (ps, ctx, _a) {
|
|
469
|
+
var item = _a.item;
|
|
470
|
+
return item.dataType !== "datetime";
|
|
471
|
+
},
|
|
472
|
+
}, numeric: {
|
|
473
|
+
type: "choice",
|
|
474
|
+
displayName: "Use numbers?",
|
|
475
|
+
options: [
|
|
476
|
+
{ value: "always", label: "Always use numbers" },
|
|
477
|
+
{
|
|
478
|
+
value: "auto",
|
|
479
|
+
label: "Use words like 'Yesterday' or 'Tomorrow'",
|
|
480
|
+
},
|
|
481
|
+
],
|
|
482
|
+
defaultValueHint: DEFAULT_RELATIVE_DATETIME_SETTINGS.numeric,
|
|
483
|
+
hidden: function (ps, ctx, _a) {
|
|
484
|
+
var item = _a.item;
|
|
485
|
+
return item.dataType !== "relative-datetime";
|
|
486
|
+
},
|
|
487
|
+
}, unit: {
|
|
488
|
+
type: "choice",
|
|
489
|
+
displayName: "Time unit",
|
|
490
|
+
options: [
|
|
491
|
+
{
|
|
492
|
+
value: "second",
|
|
493
|
+
label: "Seconds",
|
|
494
|
+
},
|
|
495
|
+
{
|
|
496
|
+
value: "minute",
|
|
497
|
+
label: "Minutes",
|
|
498
|
+
},
|
|
499
|
+
{
|
|
500
|
+
value: "hour",
|
|
501
|
+
label: "Hours",
|
|
502
|
+
},
|
|
503
|
+
{
|
|
504
|
+
value: "day",
|
|
505
|
+
label: "Days",
|
|
506
|
+
},
|
|
507
|
+
{
|
|
508
|
+
value: "week",
|
|
509
|
+
label: "Weeks",
|
|
510
|
+
},
|
|
511
|
+
{
|
|
512
|
+
value: "month",
|
|
513
|
+
label: "Months",
|
|
514
|
+
},
|
|
515
|
+
{
|
|
516
|
+
value: "year",
|
|
517
|
+
label: "Years",
|
|
518
|
+
},
|
|
519
|
+
],
|
|
520
|
+
defaultValueHint: DEFAULT_RELATIVE_DATETIME_SETTINGS.unit,
|
|
521
|
+
hidden: function (ps, ctx, _a) {
|
|
522
|
+
var item = _a.item;
|
|
523
|
+
return item.dataType !== "relative-datetime";
|
|
524
|
+
},
|
|
525
|
+
} }, opts.fieldTypes),
|
|
526
|
+
},
|
|
527
|
+
};
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
function normalizeData(rawData) {
|
|
531
|
+
var _a;
|
|
532
|
+
if (!rawData) {
|
|
533
|
+
return undefined;
|
|
534
|
+
}
|
|
535
|
+
var dataArray = tryGetDataArray(rawData);
|
|
536
|
+
if (!dataArray) {
|
|
537
|
+
return undefined;
|
|
538
|
+
}
|
|
539
|
+
var schema = (_a = rawData.schema) !== null && _a !== void 0 ? _a : tryGetSchema(dataArray);
|
|
540
|
+
if (!schema) {
|
|
541
|
+
return undefined;
|
|
542
|
+
}
|
|
543
|
+
return { data: dataArray, schema: schema };
|
|
544
|
+
}
|
|
545
|
+
function tryGetDataArray(rawData) {
|
|
546
|
+
if (!rawData || typeof rawData !== "object") {
|
|
547
|
+
return undefined;
|
|
548
|
+
}
|
|
549
|
+
if (Array.isArray(rawData)) {
|
|
550
|
+
if (isArrayOfObjects(rawData)) {
|
|
551
|
+
return rawData;
|
|
552
|
+
}
|
|
553
|
+
else {
|
|
554
|
+
// TODO: array of primitives? Maybe we can wrap this?
|
|
555
|
+
return undefined;
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
if ("data" in rawData && Array.isArray(rawData.data)) {
|
|
559
|
+
if (isArrayOfObjects(rawData.data)) {
|
|
560
|
+
return rawData.data;
|
|
561
|
+
}
|
|
562
|
+
else {
|
|
563
|
+
return undefined;
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
if ("isLoading" in rawData || "error" in rawData) {
|
|
567
|
+
return undefined;
|
|
568
|
+
}
|
|
569
|
+
// Maybe a singleton record?
|
|
570
|
+
return [rawData];
|
|
571
|
+
}
|
|
572
|
+
function isArrayOfObjects(arr) {
|
|
573
|
+
return arr.every(function (x) { return typeof x === "object" && !Array.isArray(x); });
|
|
574
|
+
}
|
|
575
|
+
function tryGetSchema(data) {
|
|
576
|
+
var fieldMap = {};
|
|
577
|
+
data.forEach(function (entry) {
|
|
578
|
+
if (entry && typeof entry === "object") {
|
|
579
|
+
Array.from(Object.entries(entry)).forEach(function (_a) {
|
|
580
|
+
var k = _a[0], v = _a[1];
|
|
581
|
+
var inferredType = typeof v === "string"
|
|
582
|
+
? "string"
|
|
583
|
+
: typeof v === "boolean"
|
|
584
|
+
? "boolean"
|
|
585
|
+
: typeof v === "number"
|
|
586
|
+
? "number"
|
|
587
|
+
: "unknown";
|
|
588
|
+
if (fieldMap[k] && fieldMap[k] !== inferredType) {
|
|
589
|
+
fieldMap[k] = "unknown";
|
|
590
|
+
}
|
|
591
|
+
else {
|
|
592
|
+
fieldMap[k] = inferredType;
|
|
593
|
+
}
|
|
594
|
+
});
|
|
595
|
+
}
|
|
596
|
+
});
|
|
597
|
+
return {
|
|
598
|
+
id: "inferred",
|
|
599
|
+
fields: Object.entries(fieldMap).map(function (_a) {
|
|
600
|
+
var f = _a[0], t = _a[1];
|
|
601
|
+
return ({
|
|
602
|
+
id: f,
|
|
603
|
+
type: t,
|
|
604
|
+
readOnly: false,
|
|
605
|
+
});
|
|
606
|
+
}),
|
|
607
|
+
};
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
function renderValue(value, record, cconfig) {
|
|
611
|
+
if (cconfig.expr) {
|
|
612
|
+
value = cconfig.expr(record, value);
|
|
613
|
+
}
|
|
614
|
+
if (value == null) {
|
|
615
|
+
return "";
|
|
616
|
+
}
|
|
617
|
+
if (cconfig.dataType === "auto") {
|
|
618
|
+
return renderAuto(value);
|
|
619
|
+
}
|
|
620
|
+
else {
|
|
621
|
+
var coerced = coerceValue(value, cconfig.dataType);
|
|
622
|
+
if (isOneOf(cconfig.dataType, NUMBER_TYPES) &&
|
|
623
|
+
typeof coerced === "number") {
|
|
624
|
+
return renderNumber(coerced, cconfig);
|
|
625
|
+
}
|
|
626
|
+
else if (cconfig.dataType === "boolean" && typeof coerced === "boolean") {
|
|
627
|
+
return renderBoolean(coerced, cconfig);
|
|
628
|
+
}
|
|
629
|
+
else if (cconfig.dataType === "datetime" && coerced instanceof Date) {
|
|
630
|
+
return renderDate(coerced, cconfig);
|
|
631
|
+
}
|
|
632
|
+
else if (cconfig.dataType === "relative-datetime" &&
|
|
633
|
+
coerced instanceof Date) {
|
|
634
|
+
return renderRelativeDate(coerced, cconfig);
|
|
635
|
+
}
|
|
636
|
+
return asString(value);
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
function renderAuto(value) {
|
|
640
|
+
if (typeof value === "number") {
|
|
641
|
+
return renderNumber(value, { dataType: "number" });
|
|
642
|
+
}
|
|
643
|
+
else if (typeof value === "boolean") {
|
|
644
|
+
return renderBoolean(value, DEFAULT_BOOLEAN_SETTINGS);
|
|
645
|
+
}
|
|
646
|
+
else if (value instanceof Date) {
|
|
647
|
+
return renderDate(value, DEFAULT_DATETIME_SETTINGS);
|
|
648
|
+
}
|
|
649
|
+
else {
|
|
650
|
+
var coerced = tryCoerceAuto(value);
|
|
651
|
+
if (coerced === CANNOT_COERCE) {
|
|
652
|
+
return asString(value);
|
|
653
|
+
}
|
|
654
|
+
else {
|
|
655
|
+
return renderAuto(coerced);
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
function tryCoerceAuto(value) {
|
|
660
|
+
for (var _i = 0, _a = [
|
|
661
|
+
"number",
|
|
662
|
+
"datetime",
|
|
663
|
+
]; _i < _a.length; _i++) {
|
|
664
|
+
var dataType = _a[_i];
|
|
665
|
+
var coerced = coerceValue(value, dataType);
|
|
666
|
+
if (coerced !== CANNOT_COERCE) {
|
|
667
|
+
return coerced;
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
return CANNOT_COERCE;
|
|
671
|
+
}
|
|
672
|
+
function renderNumber(value, cconfig) {
|
|
673
|
+
if (cconfig.dataType === "number") {
|
|
674
|
+
return new Intl.NumberFormat(cconfig.locale, cconfig).format(value);
|
|
675
|
+
}
|
|
676
|
+
else if (cconfig.dataType === "percent") {
|
|
677
|
+
return new Intl.NumberFormat(cconfig.locale, __assign(__assign({}, cconfig), { style: "percent" })).format(value);
|
|
678
|
+
}
|
|
679
|
+
else if (cconfig.dataType === "currency") {
|
|
680
|
+
return new Intl.NumberFormat(cconfig.locale, __assign(__assign(__assign({}, DEFAULT_CURRENCY_SETTINGS), cconfig), { style: "currency" })).format(value);
|
|
681
|
+
}
|
|
682
|
+
else {
|
|
683
|
+
throw new Error("Unexpected dataType ".concat(cconfig.dataType));
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
function renderDate(value, cconfig) {
|
|
687
|
+
var opts = __assign(__assign({}, DEFAULT_DATETIME_SETTINGS), cconfig);
|
|
688
|
+
if (opts.dateStyle === "none") {
|
|
689
|
+
delete opts["dateStyle"];
|
|
690
|
+
}
|
|
691
|
+
if (opts.timeStyle === "none") {
|
|
692
|
+
delete opts["timeStyle"];
|
|
693
|
+
}
|
|
694
|
+
return new Intl.DateTimeFormat(cconfig.locale, opts).format(value);
|
|
695
|
+
}
|
|
696
|
+
var SECOND_MS = 1000;
|
|
697
|
+
var MINUTE_MS = 60 * SECOND_MS;
|
|
698
|
+
var HOUR_MS = 60 * MINUTE_MS;
|
|
699
|
+
var DAY_MS = 24 * HOUR_MS;
|
|
700
|
+
var WEEK_MS = 7 * DAY_MS;
|
|
701
|
+
var UNIT_TO_MS = {
|
|
702
|
+
second: SECOND_MS,
|
|
703
|
+
minute: MINUTE_MS,
|
|
704
|
+
hour: HOUR_MS,
|
|
705
|
+
day: DAY_MS,
|
|
706
|
+
week: WEEK_MS,
|
|
707
|
+
};
|
|
708
|
+
var UNITS_BY_MS = Object.keys(UNIT_TO_MS);
|
|
709
|
+
function renderRelativeDate(value, cconfig) {
|
|
710
|
+
var _a;
|
|
711
|
+
var opts = __assign(__assign({}, DEFAULT_RELATIVE_DATETIME_SETTINGS), cconfig);
|
|
712
|
+
var unit = (_a = cconfig.unit) !== null && _a !== void 0 ? _a : "day";
|
|
713
|
+
var formatter = new Intl.RelativeTimeFormat(cconfig.locale, opts);
|
|
714
|
+
if (isOneOf(unit, UNITS_BY_MS)) {
|
|
715
|
+
// for "exact" units, we can do it by just calcluating the difference
|
|
716
|
+
// by ms
|
|
717
|
+
var diff = value.getTime() - new Date().getTime();
|
|
718
|
+
return formatter.format(Math.round(diff / UNIT_TO_MS[unit]), unit);
|
|
719
|
+
}
|
|
720
|
+
else {
|
|
721
|
+
// otherwise we need to calculate by the specific unit
|
|
722
|
+
if (unit === "year") {
|
|
723
|
+
var diff = value.getFullYear() - new Date().getFullYear();
|
|
724
|
+
return formatter.format(diff, unit);
|
|
725
|
+
}
|
|
726
|
+
else if (unit === "month") {
|
|
727
|
+
var months = function (d) { return d.getFullYear() * 12 + d.getMonth() + 1; };
|
|
728
|
+
var diff = months(value) - months(new Date());
|
|
729
|
+
return formatter.format(diff, unit);
|
|
730
|
+
}
|
|
731
|
+
else {
|
|
732
|
+
throw new Error("Unexpected relative time unit ".concat(unit));
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
function renderBoolean(value, cconfig) {
|
|
737
|
+
var _a;
|
|
738
|
+
var showAs = (_a = cconfig.showAs) !== null && _a !== void 0 ? _a : DEFAULT_BOOLEAN_SETTINGS.showAs;
|
|
739
|
+
if (showAs === "checkbox") {
|
|
740
|
+
return React__default.default.createElement(antd.Checkbox, { checked: value });
|
|
741
|
+
}
|
|
742
|
+
else if (showAs === "switch") {
|
|
743
|
+
return React__default.default.createElement(antd.Switch, { checked: value });
|
|
744
|
+
}
|
|
745
|
+
else {
|
|
746
|
+
return value ? "true" : "false";
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
var CANNOT_COERCE = Symbol("plasmic-cannot-coerce");
|
|
750
|
+
function coerceValue(value, dataType) {
|
|
751
|
+
if (value == null) {
|
|
752
|
+
return null;
|
|
753
|
+
}
|
|
754
|
+
try {
|
|
755
|
+
if (isOneOf(dataType, NUMBER_TYPES)) {
|
|
756
|
+
if (typeof value === "number") {
|
|
757
|
+
return value;
|
|
758
|
+
}
|
|
759
|
+
else if (typeof value === "string") {
|
|
760
|
+
var maybeNumber = +value;
|
|
761
|
+
if (!isNaN(maybeNumber)) {
|
|
762
|
+
return maybeNumber;
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
}
|
|
766
|
+
else if (isOneOf(dataType, DATETIME_TYPES)) {
|
|
767
|
+
if (value instanceof Date) {
|
|
768
|
+
return value;
|
|
769
|
+
}
|
|
770
|
+
else if (typeof value === "number") {
|
|
771
|
+
return new Date(value);
|
|
772
|
+
}
|
|
773
|
+
else if (typeof value === "string") {
|
|
774
|
+
var maybeDate = new Date(value);
|
|
775
|
+
if (!isNaN(maybeDate.getTime())) {
|
|
776
|
+
return maybeDate;
|
|
777
|
+
}
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
else if (dataType === "boolean") {
|
|
781
|
+
if (value === true || value === false) {
|
|
782
|
+
return value;
|
|
783
|
+
}
|
|
784
|
+
else if (typeof value === "number") {
|
|
785
|
+
return value !== 0;
|
|
786
|
+
}
|
|
787
|
+
else if (typeof value === "string") {
|
|
788
|
+
return value.toLowerCase() === "true";
|
|
789
|
+
}
|
|
790
|
+
}
|
|
791
|
+
else if (dataType === "string") {
|
|
792
|
+
return asString(value);
|
|
793
|
+
}
|
|
794
|
+
else if (dataType === "auto") {
|
|
795
|
+
return value;
|
|
796
|
+
}
|
|
797
|
+
}
|
|
798
|
+
catch (err) {
|
|
799
|
+
// Ignore error; just fail to coerce
|
|
800
|
+
}
|
|
801
|
+
return CANNOT_COERCE;
|
|
802
|
+
}
|
|
803
|
+
function asString(value) {
|
|
804
|
+
if (value == null) {
|
|
805
|
+
return "";
|
|
806
|
+
}
|
|
807
|
+
else if (typeof value === "string") {
|
|
808
|
+
return value;
|
|
809
|
+
}
|
|
810
|
+
else if (typeof value === "object") {
|
|
811
|
+
if ("toString" in value && typeof value.toString === "function") {
|
|
812
|
+
return value.toString();
|
|
813
|
+
}
|
|
814
|
+
else {
|
|
815
|
+
return JSON.stringify(value);
|
|
816
|
+
}
|
|
817
|
+
}
|
|
818
|
+
else {
|
|
819
|
+
return "".concat(value);
|
|
820
|
+
}
|
|
821
|
+
}
|
|
822
|
+
|
|
823
|
+
function RichDetails(props) {
|
|
824
|
+
var _a;
|
|
825
|
+
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;
|
|
826
|
+
var data = normalizeData(rawData);
|
|
827
|
+
var columnDefinitions = useColumnDefinitions$1(data, props).columnDefinitions;
|
|
828
|
+
if (!data) {
|
|
829
|
+
return React__default.default.createElement(antd.Empty, { className: className });
|
|
830
|
+
}
|
|
831
|
+
return (React__default.default.createElement(proComponents.ProDescriptions, { className: className, dataSource: (_a = data === null || data === void 0 ? void 0 : data.data) === null || _a === void 0 ? void 0 : _a[0], columns: columnDefinitions, size: size, bordered: bordered, layout: layout, column: {
|
|
832
|
+
xs: 1,
|
|
833
|
+
sm: 1,
|
|
834
|
+
md: column,
|
|
835
|
+
} }));
|
|
836
|
+
}
|
|
837
|
+
function useColumnDefinitions$1(data, props) {
|
|
838
|
+
var fields = props.fields, setControlContextData = props.setControlContextData;
|
|
839
|
+
return React__default.default.useMemo(function () {
|
|
840
|
+
var schema = data === null || data === void 0 ? void 0 : data.schema;
|
|
841
|
+
if (!data || !schema) {
|
|
842
|
+
return { normalized: [], columnDefinitions: [] };
|
|
843
|
+
}
|
|
844
|
+
var _a = deriveFieldConfigs(fields !== null && fields !== void 0 ? fields : [], schema, function (field) { return (__assign({ key: mkShortId(), isHidden: false, dataType: "auto" }, (field && {
|
|
845
|
+
key: field.id,
|
|
846
|
+
fieldId: field.id,
|
|
847
|
+
title: field.label || field.id,
|
|
848
|
+
expr: function (currentItem) { return currentItem[field.id]; },
|
|
849
|
+
}))); }), mergedFields = _a.mergedFields, minimalFullLengthFields = _a.minimalFullLengthFields;
|
|
850
|
+
setControlContextData === null || setControlContextData === void 0 ? void 0 : setControlContextData(__assign(__assign({}, data), { mergedFields: mergedFields, minimalFullLengthFields: minimalFullLengthFields }));
|
|
851
|
+
var normalized = mergedFields;
|
|
852
|
+
var columnDefinitions = normalized
|
|
853
|
+
.filter(function (cconfig) { return !cconfig.isHidden; })
|
|
854
|
+
.map(function (cconfig, _columnIndex, _columnsArray) {
|
|
855
|
+
var columnDefinition = {
|
|
856
|
+
dataIndex: cconfig.fieldId,
|
|
857
|
+
title: cconfig.title,
|
|
858
|
+
key: cconfig.key,
|
|
859
|
+
valueType: deriveValueType(cconfig),
|
|
860
|
+
span: cconfig.span,
|
|
861
|
+
// To come later
|
|
862
|
+
copyable: false,
|
|
863
|
+
ellipsis: false,
|
|
864
|
+
tip: undefined,
|
|
865
|
+
formItemProps: {
|
|
866
|
+
rules: [],
|
|
867
|
+
},
|
|
868
|
+
valueEnum: undefined,
|
|
869
|
+
renderFormItem: function (_, _a) {
|
|
870
|
+
var defaultRender = _a.defaultRender;
|
|
871
|
+
return defaultRender(_);
|
|
872
|
+
},
|
|
873
|
+
render: function (value, record, rowIndex) {
|
|
874
|
+
return renderValue(value, record, cconfig);
|
|
875
|
+
},
|
|
876
|
+
};
|
|
877
|
+
return columnDefinition;
|
|
878
|
+
});
|
|
879
|
+
return { normalized: normalized, columnDefinitions: columnDefinitions };
|
|
880
|
+
}, [fields, data, setControlContextData]);
|
|
881
|
+
}
|
|
882
|
+
|
|
883
|
+
function registerRichDetails(loader) {
|
|
884
|
+
registerComponentHelper(loader, RichDetails, {
|
|
885
|
+
name: "hostless-rich-details",
|
|
886
|
+
displayName: "Data details",
|
|
887
|
+
defaultStyles: {
|
|
888
|
+
width: "stretch",
|
|
889
|
+
maxHeight: "100%",
|
|
890
|
+
},
|
|
891
|
+
props: {
|
|
892
|
+
data: {
|
|
893
|
+
type: "dataSourceOpData",
|
|
894
|
+
description: "The data to display",
|
|
895
|
+
},
|
|
896
|
+
fields: buildFieldsPropType({
|
|
897
|
+
fieldTypes: {
|
|
898
|
+
span: {
|
|
899
|
+
type: "number",
|
|
900
|
+
displayName: "Number of columns to span",
|
|
901
|
+
defaultValueHint: 1,
|
|
902
|
+
},
|
|
903
|
+
},
|
|
904
|
+
}),
|
|
905
|
+
layout: {
|
|
906
|
+
displayName: "Layout",
|
|
907
|
+
type: "choice",
|
|
908
|
+
options: [
|
|
909
|
+
{ value: "horizontal", label: "Horizontal" },
|
|
910
|
+
{ value: "vertical", label: "Vertical" },
|
|
911
|
+
],
|
|
912
|
+
defaultValueHint: "horizontal",
|
|
913
|
+
},
|
|
914
|
+
column: {
|
|
915
|
+
displayName: "Items per row",
|
|
916
|
+
type: "number",
|
|
917
|
+
description: "Number of items to display per row",
|
|
918
|
+
defaultValueHint: 2,
|
|
919
|
+
},
|
|
920
|
+
size: {
|
|
921
|
+
displayName: "Spacing",
|
|
922
|
+
type: "choice",
|
|
923
|
+
options: [
|
|
924
|
+
{ value: "small", label: "Small" },
|
|
925
|
+
{ value: "middle", label: "Medium" },
|
|
926
|
+
{ value: "default", label: "Large" },
|
|
927
|
+
],
|
|
928
|
+
defaultValueHint: "default",
|
|
929
|
+
},
|
|
930
|
+
bordered: {
|
|
931
|
+
displayName: "Show borders?",
|
|
932
|
+
type: "boolean",
|
|
933
|
+
defaultValueHint: false,
|
|
934
|
+
},
|
|
935
|
+
},
|
|
936
|
+
importPath: "@plasmicpkgs/plasmic-rich-components",
|
|
937
|
+
importName: "RichDetails",
|
|
938
|
+
});
|
|
939
|
+
}
|
|
940
|
+
|
|
105
941
|
function useIsClient() {
|
|
106
942
|
var _a = React.useState(false), loaded = _a[0], setLoaded = _a[1];
|
|
107
943
|
React.useEffect(function () {
|
|
@@ -113,15 +949,6 @@ function capitalize(text) {
|
|
|
113
949
|
return text.slice(0, 1).toUpperCase() + text.slice(1);
|
|
114
950
|
}
|
|
115
951
|
|
|
116
|
-
function registerComponentHelper(loader, component, meta) {
|
|
117
|
-
if (loader) {
|
|
118
|
-
loader.registerComponent(component, meta);
|
|
119
|
-
}
|
|
120
|
-
else {
|
|
121
|
-
registerComponent__default.default(component, meta);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
|
|
125
952
|
function RichLayout(_a) {
|
|
126
953
|
var _b, _c, _d;
|
|
127
954
|
var children = _a.children, navMenuItems = _a.navMenuItems, _e = _a.rootUrl, rootUrl = _e === void 0 ? "/" : _e, actionsChildren = _a.actionsChildren, footerChildren = _a.footerChildren, avatarLabel = _a.avatarLabel, avatarImage = _a.avatarImage, showAvatarMenu = _a.showAvatarMenu, className = _a.className, layoutProps = __rest(_a, ["children", "navMenuItems", "rootUrl", "actionsChildren", "footerChildren", "avatarLabel", "avatarImage", "showAvatarMenu", "className"]);
|
|
@@ -329,142 +1156,6 @@ function registerRichLayout(loader) {
|
|
|
329
1156
|
registerComponentHelper(loader, RichLayout, richLayoutMeta);
|
|
330
1157
|
}
|
|
331
1158
|
|
|
332
|
-
var tuple = function () {
|
|
333
|
-
var args = [];
|
|
334
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
335
|
-
args[_i] = arguments[_i];
|
|
336
|
-
}
|
|
337
|
-
return args;
|
|
338
|
-
};
|
|
339
|
-
function mkIdMap(xs) {
|
|
340
|
-
return new Map(xs.map(function (x) { return tuple(x.id, x); }));
|
|
341
|
-
}
|
|
342
|
-
var mkShortId = function () { return "".concat(Math.random()); };
|
|
343
|
-
var withoutNils = function (xs) {
|
|
344
|
-
return xs.filter(function (x) { return x != null; });
|
|
345
|
-
};
|
|
346
|
-
var defaultColumnConfig = function () {
|
|
347
|
-
return ({
|
|
348
|
-
key: mkShortId(),
|
|
349
|
-
isEditableExpr: function () { return false; },
|
|
350
|
-
disableSorting: false,
|
|
351
|
-
sortByExpr: undefined,
|
|
352
|
-
isHidden: false,
|
|
353
|
-
formatting: {
|
|
354
|
-
styles: {},
|
|
355
|
-
align: "left",
|
|
356
|
-
freeze: "off",
|
|
357
|
-
},
|
|
358
|
-
dataType: "auto",
|
|
359
|
-
});
|
|
360
|
-
};
|
|
361
|
-
function deriveFieldConfigs(specifiedFieldsPartial, schema) {
|
|
362
|
-
var _a;
|
|
363
|
-
var schemaFields = (_a = schema === null || schema === void 0 ? void 0 : schema.fields) !== null && _a !== void 0 ? _a : [];
|
|
364
|
-
var fieldById = mkIdMap(schemaFields);
|
|
365
|
-
var specifiedFieldIds = new Set(withoutNils(specifiedFieldsPartial.map(function (f) { return f.fieldId; })));
|
|
366
|
-
function defaultColumnConfigForField(field) {
|
|
367
|
-
return __assign(__assign({}, defaultColumnConfig()), { key: field.id, fieldId: field.id, title: field.label || field.id, expr: function (currentItem) { return currentItem[field.id]; } });
|
|
368
|
-
}
|
|
369
|
-
var keptSpecifiedFields = specifiedFieldsPartial.flatMap(function (f, index) {
|
|
370
|
-
var fieldId = f.fieldId;
|
|
371
|
-
if (!fieldId) {
|
|
372
|
-
return [
|
|
373
|
-
__assign(__assign(__assign({}, defaultColumnConfig()), { key: index }), f),
|
|
374
|
-
];
|
|
375
|
-
}
|
|
376
|
-
var field = fieldById.get(fieldId);
|
|
377
|
-
// Drop configs with fieldIds no longer in the data.
|
|
378
|
-
if (!field) {
|
|
379
|
-
return [];
|
|
380
|
-
}
|
|
381
|
-
return [
|
|
382
|
-
__assign(__assign({}, defaultColumnConfigForField(field)), f),
|
|
383
|
-
];
|
|
384
|
-
});
|
|
385
|
-
var newVirtualFields = schemaFields
|
|
386
|
-
.filter(function (f) { return !specifiedFieldIds.has(f.id); })
|
|
387
|
-
.map(function (f) { return (__assign({}, defaultColumnConfigForField(f))); });
|
|
388
|
-
var mergedFields = __spreadArray(__spreadArray([], keptSpecifiedFields, true), newVirtualFields, true);
|
|
389
|
-
var minimalFullLengthFields = __spreadArray(__spreadArray([], specifiedFieldsPartial, true), newVirtualFields.map(function (f) { return ({ key: f.key, fieldId: f.fieldId }); }), true);
|
|
390
|
-
return { mergedFields: mergedFields, minimalFullLengthFields: minimalFullLengthFields };
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
function tryGetSchema(data) {
|
|
394
|
-
if (data === null || data === void 0 ? void 0 : data.schema) {
|
|
395
|
-
return data.schema;
|
|
396
|
-
}
|
|
397
|
-
if (Array.isArray(data)) {
|
|
398
|
-
data = { data: data };
|
|
399
|
-
}
|
|
400
|
-
if (!(data === null || data === void 0 ? void 0 : data.data) || !Array.isArray(data.data) || data.data.length === 0) {
|
|
401
|
-
return undefined;
|
|
402
|
-
}
|
|
403
|
-
var fieldMap = {};
|
|
404
|
-
data.data.forEach(function (entry) {
|
|
405
|
-
if (entry && typeof entry === "object") {
|
|
406
|
-
Array.from(Object.entries(entry)).forEach(function (_a) {
|
|
407
|
-
var k = _a[0], v = _a[1];
|
|
408
|
-
var inferredType = typeof v === "string"
|
|
409
|
-
? "string"
|
|
410
|
-
: typeof v === "boolean"
|
|
411
|
-
? "boolean"
|
|
412
|
-
: typeof v === "number"
|
|
413
|
-
? "number"
|
|
414
|
-
: "unknown";
|
|
415
|
-
if (fieldMap[k] && fieldMap[k] !== inferredType) {
|
|
416
|
-
fieldMap[k] = "unknown";
|
|
417
|
-
}
|
|
418
|
-
else {
|
|
419
|
-
fieldMap[k] = inferredType;
|
|
420
|
-
}
|
|
421
|
-
});
|
|
422
|
-
}
|
|
423
|
-
});
|
|
424
|
-
return {
|
|
425
|
-
id: "inferred",
|
|
426
|
-
fields: Object.entries(fieldMap).map(function (_a) {
|
|
427
|
-
var f = _a[0], t = _a[1];
|
|
428
|
-
return ({
|
|
429
|
-
id: f,
|
|
430
|
-
type: t,
|
|
431
|
-
readOnly: false,
|
|
432
|
-
});
|
|
433
|
-
}),
|
|
434
|
-
};
|
|
435
|
-
}
|
|
436
|
-
function normalizeData(rawData) {
|
|
437
|
-
if (!rawData || typeof rawData !== "object") {
|
|
438
|
-
return undefined;
|
|
439
|
-
}
|
|
440
|
-
var obj = Array.isArray(rawData) ? { data: rawData } : rawData;
|
|
441
|
-
if (!("data" in obj)) {
|
|
442
|
-
return undefined;
|
|
443
|
-
}
|
|
444
|
-
var objWithData = obj;
|
|
445
|
-
if (!Array.isArray(objWithData.data) || objWithData.data.length === 0) {
|
|
446
|
-
return undefined;
|
|
447
|
-
}
|
|
448
|
-
// Make TS happy.
|
|
449
|
-
var normed = __assign(__assign({}, objWithData), { data: objWithData.data });
|
|
450
|
-
var schema = tryGetSchema(rawData);
|
|
451
|
-
if (!schema) {
|
|
452
|
-
return undefined;
|
|
453
|
-
}
|
|
454
|
-
return __assign(__assign({}, normed), { schema: schema });
|
|
455
|
-
}
|
|
456
|
-
/**
|
|
457
|
-
* Render booleans, objects, arrays, etc. as JSON repr.
|
|
458
|
-
*/
|
|
459
|
-
function safeRender(x) {
|
|
460
|
-
return x === undefined || x === null
|
|
461
|
-
? ""
|
|
462
|
-
: typeof x === "string"
|
|
463
|
-
? x
|
|
464
|
-
: typeof x === "number"
|
|
465
|
-
? x.toString()
|
|
466
|
-
: JSON.stringify(x);
|
|
467
|
-
}
|
|
468
1159
|
function RichTable(props) {
|
|
469
1160
|
var className = props.className, _a = props.data, rawData = _a === void 0 ? {
|
|
470
1161
|
data: [],
|
|
@@ -482,7 +1173,7 @@ function RichTable(props) {
|
|
|
482
1173
|
// children,
|
|
483
1174
|
_b = props.pagination,
|
|
484
1175
|
// children,
|
|
485
|
-
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;
|
|
1176
|
+
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;
|
|
486
1177
|
var data = normalizeData(rawData);
|
|
487
1178
|
var _f = useColumnDefinitions(data, props), columnDefinitions = _f.columnDefinitions, normalized = _f.normalized;
|
|
488
1179
|
var actionRef = React.useRef();
|
|
@@ -541,7 +1232,7 @@ function deriveRowKey(data, rowKey) {
|
|
|
541
1232
|
if (rowKey) {
|
|
542
1233
|
return rowKey;
|
|
543
1234
|
}
|
|
544
|
-
var schema =
|
|
1235
|
+
var schema = data === null || data === void 0 ? void 0 : data.schema;
|
|
545
1236
|
if (schema) {
|
|
546
1237
|
return (_a = schema.fields[0]) === null || _a === void 0 ? void 0 : _a.id;
|
|
547
1238
|
}
|
|
@@ -558,14 +1249,34 @@ function deriveKeyOfRow(row, rowKey) {
|
|
|
558
1249
|
return undefined;
|
|
559
1250
|
}
|
|
560
1251
|
}
|
|
1252
|
+
var defaultColumnConfig = function () {
|
|
1253
|
+
return ({
|
|
1254
|
+
key: mkShortId(),
|
|
1255
|
+
isEditableExpr: function () { return false; },
|
|
1256
|
+
disableSorting: false,
|
|
1257
|
+
sortByExpr: undefined,
|
|
1258
|
+
isHidden: false,
|
|
1259
|
+
formatting: {
|
|
1260
|
+
styles: {},
|
|
1261
|
+
align: "left",
|
|
1262
|
+
freeze: "off",
|
|
1263
|
+
},
|
|
1264
|
+
dataType: "auto",
|
|
1265
|
+
});
|
|
1266
|
+
};
|
|
561
1267
|
function useColumnDefinitions(data, props) {
|
|
562
1268
|
var fields = props.fields, setControlContextData = props.setControlContextData, rowActions = props.rowActions;
|
|
563
1269
|
return React__default.default.useMemo(function () {
|
|
564
|
-
var schema =
|
|
1270
|
+
var schema = data === null || data === void 0 ? void 0 : data.schema;
|
|
565
1271
|
if (!data || !schema) {
|
|
566
1272
|
return { normalized: [], columnDefinitions: [] };
|
|
567
1273
|
}
|
|
568
|
-
var _a = deriveFieldConfigs(fields !== null && fields !== void 0 ? fields : [], schema
|
|
1274
|
+
var _a = deriveFieldConfigs(fields !== null && fields !== void 0 ? fields : [], schema, function (field) { return (__assign(__assign({}, defaultColumnConfig()), (field && {
|
|
1275
|
+
key: field.id,
|
|
1276
|
+
fieldId: field.id,
|
|
1277
|
+
title: field.label || field.id,
|
|
1278
|
+
expr: function (currentItem) { return currentItem[field.id]; },
|
|
1279
|
+
}))); }), mergedFields = _a.mergedFields, minimalFullLengthFields = _a.minimalFullLengthFields;
|
|
569
1280
|
setControlContextData === null || setControlContextData === void 0 ? void 0 : setControlContextData(__assign(__assign({}, data), { mergedFields: mergedFields, minimalFullLengthFields: minimalFullLengthFields }));
|
|
570
1281
|
var normalized = mergedFields;
|
|
571
1282
|
var columnDefinitions = normalized
|
|
@@ -576,15 +1287,7 @@ function useColumnDefinitions(data, props) {
|
|
|
576
1287
|
title: cconfig.title,
|
|
577
1288
|
// dataIndex: cconfig,
|
|
578
1289
|
key: cconfig.key,
|
|
579
|
-
valueType: cconfig
|
|
580
|
-
? undefined
|
|
581
|
-
: cconfig.dataType === "string"
|
|
582
|
-
? "text"
|
|
583
|
-
: cconfig.dataType === "number"
|
|
584
|
-
? "digit"
|
|
585
|
-
: cconfig.dataType === "boolean"
|
|
586
|
-
? "switch"
|
|
587
|
-
: undefined,
|
|
1290
|
+
valueType: deriveValueType(cconfig),
|
|
588
1291
|
// To come later
|
|
589
1292
|
readonly: false,
|
|
590
1293
|
sorter: true,
|
|
@@ -603,9 +1306,7 @@ function useColumnDefinitions(data, props) {
|
|
|
603
1306
|
return defaultRender(_);
|
|
604
1307
|
},
|
|
605
1308
|
render: function (value, record, rowIndex) {
|
|
606
|
-
return (
|
|
607
|
-
React__default.default.createElement(host.DataProvider, { name: "currentRowIndex", data: rowIndex },
|
|
608
|
-
React__default.default.createElement(host.DataProvider, { name: "currentColumn", data: value }, safeRender(cconfig.expr ? cconfig.expr(record) : value)))));
|
|
1309
|
+
return renderValue(value, record, cconfig);
|
|
609
1310
|
},
|
|
610
1311
|
};
|
|
611
1312
|
return columnDefinition;
|
|
@@ -657,10 +1358,11 @@ function useSortedFilteredData(data, columns) {
|
|
|
657
1358
|
? // We use .sort() rather than sortBy to use localeCompare
|
|
658
1359
|
(function () {
|
|
659
1360
|
var _a;
|
|
660
|
-
var
|
|
1361
|
+
var cconfig = columns.find(function (cc) { var _a; return cc.key === ((_a = sortState === null || sortState === void 0 ? void 0 : sortState.sorter.column) === null || _a === void 0 ? void 0 : _a.key); });
|
|
1362
|
+
var expr = (_a = cconfig.expr) !== null && _a !== void 0 ? _a : (function (x) { return x; });
|
|
661
1363
|
return (filtered !== null && filtered !== void 0 ? filtered : []).sort(function (aa, bb) {
|
|
662
1364
|
var _a, _b;
|
|
663
|
-
var a = (_a = expr(aa)) !== null && _a !== void 0 ? _a : null, b = (_b = expr(bb)) !== null && _b !== void 0 ? _b : null;
|
|
1365
|
+
var a = (_a = expr(aa, cconfig.fieldId ? aa === null || aa === void 0 ? void 0 : aa[cconfig.fieldId] : null)) !== null && _a !== void 0 ? _a : null, b = (_b = expr(bb, cconfig.fieldId ? bb === null || bb === void 0 ? void 0 : bb[cconfig.fieldId] : null)) !== null && _b !== void 0 ? _b : null;
|
|
664
1366
|
// Default nil to '' here because A < null < z which is weird.
|
|
665
1367
|
return typeof a === "string"
|
|
666
1368
|
? a.localeCompare(b !== null && b !== void 0 ? b : "")
|
|
@@ -758,7 +1460,7 @@ function ExportMenu(props) {
|
|
|
758
1460
|
var _a, _b;
|
|
759
1461
|
return __generator(this, function (_c) {
|
|
760
1462
|
writer = csvWriterBrowser.createObjectCsvStringifier({
|
|
761
|
-
header: (_b = (_a =
|
|
1463
|
+
header: (_b = (_a = data === null || data === void 0 ? void 0 : data.schema) === null || _a === void 0 ? void 0 : _a.fields.map(function (f) { return ({
|
|
762
1464
|
id: f.id,
|
|
763
1465
|
title: f.id,
|
|
764
1466
|
}); })) !== null && _b !== void 0 ? _b : [],
|
|
@@ -808,9 +1510,6 @@ function ExportMenu(props) {
|
|
|
808
1510
|
React__default.default.createElement(icons.EllipsisOutlined, null))));
|
|
809
1511
|
}
|
|
810
1512
|
|
|
811
|
-
function ensureNumber(x) {
|
|
812
|
-
return x;
|
|
813
|
-
}
|
|
814
1513
|
var tableHelpers = {
|
|
815
1514
|
states: {
|
|
816
1515
|
selectedRow: {
|
|
@@ -830,21 +1529,6 @@ var tableHelpers = {
|
|
|
830
1529
|
},
|
|
831
1530
|
},
|
|
832
1531
|
};
|
|
833
|
-
var rowDataType = function (displayName, control) {
|
|
834
|
-
return ({
|
|
835
|
-
type: "function",
|
|
836
|
-
displayName: displayName,
|
|
837
|
-
control: control,
|
|
838
|
-
argNames: ["currentItem"],
|
|
839
|
-
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]]; },
|
|
840
|
-
});
|
|
841
|
-
};
|
|
842
|
-
function getDefaultValueHint(field) {
|
|
843
|
-
return function (_props, contextData, _a) {
|
|
844
|
-
var path = _a.path;
|
|
845
|
-
return contextData === null || contextData === void 0 ? void 0 : contextData.mergedFields[ensureNumber(path.slice(-2)[0])][field];
|
|
846
|
-
};
|
|
847
|
-
}
|
|
848
1532
|
var dataTableMeta = {
|
|
849
1533
|
name: "hostless-rich-table",
|
|
850
1534
|
displayName: "Table",
|
|
@@ -858,93 +1542,7 @@ var dataTableMeta = {
|
|
|
858
1542
|
type: "dataSourceOpData",
|
|
859
1543
|
description: "The data to display in the table",
|
|
860
1544
|
},
|
|
861
|
-
|
|
862
|
-
displayName: "Density",
|
|
863
|
-
type: "choice",
|
|
864
|
-
options: [
|
|
865
|
-
{
|
|
866
|
-
value: "large",
|
|
867
|
-
label: "Larger",
|
|
868
|
-
},
|
|
869
|
-
{
|
|
870
|
-
value: "middle",
|
|
871
|
-
label: "Medium",
|
|
872
|
-
},
|
|
873
|
-
{
|
|
874
|
-
value: "small",
|
|
875
|
-
label: "Compact",
|
|
876
|
-
},
|
|
877
|
-
],
|
|
878
|
-
defaultValueHint: "large",
|
|
879
|
-
},
|
|
880
|
-
pageSize: {
|
|
881
|
-
type: "number",
|
|
882
|
-
defaultValueHint: 10,
|
|
883
|
-
},
|
|
884
|
-
fields: {
|
|
885
|
-
type: "array",
|
|
886
|
-
hidden: function (ps) { return !ps.data; },
|
|
887
|
-
unstable__keyFunc: function (x) { return x.key; },
|
|
888
|
-
unstable__minimalValue: function (_props, contextData) {
|
|
889
|
-
return contextData === null || contextData === void 0 ? void 0 : contextData.minimalFullLengthFields;
|
|
890
|
-
},
|
|
891
|
-
unstable__canDelete: function (_item, _props, ctx, _a) {
|
|
892
|
-
var path = _a.path;
|
|
893
|
-
return !(ctx === null || ctx === void 0 ? void 0 : ctx.mergedFields[ensureNumber(path.slice(-1)[0])].fieldId);
|
|
894
|
-
},
|
|
895
|
-
itemType: {
|
|
896
|
-
type: "object",
|
|
897
|
-
nameFunc: function (_item, _props, ctx, _a) {
|
|
898
|
-
var path = _a.path;
|
|
899
|
-
return ctx === null || ctx === void 0 ? void 0 : ctx.mergedFields[ensureNumber(path.slice(-1)[0])].title;
|
|
900
|
-
},
|
|
901
|
-
fields: {
|
|
902
|
-
key: {
|
|
903
|
-
type: "string",
|
|
904
|
-
hidden: function () { return true; },
|
|
905
|
-
},
|
|
906
|
-
fieldId: {
|
|
907
|
-
type: "choice",
|
|
908
|
-
displayName: "Field name",
|
|
909
|
-
readOnly: true,
|
|
910
|
-
options: function (_props, ctx) { var _a, _b; return ((_b = (_a = ctx === null || ctx === void 0 ? void 0 : ctx.schema) === null || _a === void 0 ? void 0 : _a.fields) !== null && _b !== void 0 ? _b : []).map(function (f) { return f.id; }); },
|
|
911
|
-
hidden: function (_props, ctx, _a) {
|
|
912
|
-
var _b, _c;
|
|
913
|
-
var _controlPath = _a.path;
|
|
914
|
-
return !(_controlPath.slice(-1)[0] in ((_c = (_b = ctx === null || ctx === void 0 ? void 0 : ctx.schema) === null || _b === void 0 ? void 0 : _b.fields) !== null && _c !== void 0 ? _c : {}));
|
|
915
|
-
},
|
|
916
|
-
},
|
|
917
|
-
title: {
|
|
918
|
-
type: "string",
|
|
919
|
-
displayName: "Title",
|
|
920
|
-
defaultValueHint: getDefaultValueHint("title"),
|
|
921
|
-
},
|
|
922
|
-
dataType: {
|
|
923
|
-
type: "choice",
|
|
924
|
-
displayName: "Data type",
|
|
925
|
-
options: ["auto", "number", "string", "boolean"],
|
|
926
|
-
defaultValueHint: getDefaultValueHint("dataType"),
|
|
927
|
-
},
|
|
928
|
-
expr: rowDataType("Customize data"),
|
|
929
|
-
// TODO
|
|
930
|
-
// isEditableExpr: rowDataType("Is editable", {
|
|
931
|
-
// type: "boolean",
|
|
932
|
-
// defaultValueHint: false,
|
|
933
|
-
// }),
|
|
934
|
-
// disableSorting: {
|
|
935
|
-
// type: "boolean",
|
|
936
|
-
// displayName: "Disable sorting",
|
|
937
|
-
// defaultValueHint: getDefaultValueHint("disableSorting"),
|
|
938
|
-
// },
|
|
939
|
-
// sortByExpr: rowDataType("Sort by"),
|
|
940
|
-
isHidden: {
|
|
941
|
-
type: "boolean",
|
|
942
|
-
displayName: "Is hidden",
|
|
943
|
-
defaultValueHint: getDefaultValueHint("isHidden"),
|
|
944
|
-
},
|
|
945
|
-
},
|
|
946
|
-
},
|
|
947
|
-
},
|
|
1545
|
+
fields: buildFieldsPropType({}),
|
|
948
1546
|
canSelectRows: {
|
|
949
1547
|
type: "choice",
|
|
950
1548
|
displayName: "Select rows?",
|
|
@@ -999,7 +1597,7 @@ var dataTableMeta = {
|
|
|
999
1597
|
advanced: true,
|
|
1000
1598
|
itemType: {
|
|
1001
1599
|
type: "object",
|
|
1002
|
-
nameFunc: function (
|
|
1600
|
+
nameFunc: function (item) { return item.label; },
|
|
1003
1601
|
fields: {
|
|
1004
1602
|
type: {
|
|
1005
1603
|
type: "choice",
|
|
@@ -1029,7 +1627,10 @@ var dataTableMeta = {
|
|
|
1029
1627
|
},
|
|
1030
1628
|
},
|
|
1031
1629
|
},
|
|
1032
|
-
hidden: function (ps) {
|
|
1630
|
+
hidden: function (ps, ctx, _a) {
|
|
1631
|
+
var item = _a.item;
|
|
1632
|
+
return item.type !== "menu";
|
|
1633
|
+
},
|
|
1033
1634
|
},
|
|
1034
1635
|
onClick: {
|
|
1035
1636
|
type: "eventHandler",
|
|
@@ -1038,11 +1639,39 @@ var dataTableMeta = {
|
|
|
1038
1639
|
{ name: "rowKey", type: "string" },
|
|
1039
1640
|
{ name: "row", type: "object" },
|
|
1040
1641
|
],
|
|
1041
|
-
hidden: function (ps) {
|
|
1642
|
+
hidden: function (ps, ctx, _a) {
|
|
1643
|
+
var item = _a.item;
|
|
1644
|
+
return item.type !== "item";
|
|
1645
|
+
},
|
|
1042
1646
|
},
|
|
1043
1647
|
},
|
|
1044
1648
|
},
|
|
1045
1649
|
},
|
|
1650
|
+
defaultSize: {
|
|
1651
|
+
displayName: "Density",
|
|
1652
|
+
type: "choice",
|
|
1653
|
+
options: [
|
|
1654
|
+
{
|
|
1655
|
+
value: "large",
|
|
1656
|
+
label: "Larger",
|
|
1657
|
+
},
|
|
1658
|
+
{
|
|
1659
|
+
value: "middle",
|
|
1660
|
+
label: "Medium",
|
|
1661
|
+
},
|
|
1662
|
+
{
|
|
1663
|
+
value: "small",
|
|
1664
|
+
label: "Compact",
|
|
1665
|
+
},
|
|
1666
|
+
],
|
|
1667
|
+
defaultValueHint: "large",
|
|
1668
|
+
advanced: true,
|
|
1669
|
+
},
|
|
1670
|
+
pageSize: {
|
|
1671
|
+
type: "number",
|
|
1672
|
+
defaultValueHint: 10,
|
|
1673
|
+
advanced: true,
|
|
1674
|
+
},
|
|
1046
1675
|
pagination: {
|
|
1047
1676
|
type: "boolean",
|
|
1048
1677
|
advanced: true,
|
|
@@ -1105,8 +1734,10 @@ function registerRichTable(loader) {
|
|
|
1105
1734
|
function registerAll(loader) {
|
|
1106
1735
|
registerRichLayout(loader);
|
|
1107
1736
|
registerRichTable(loader);
|
|
1737
|
+
registerRichDetails(loader);
|
|
1108
1738
|
}
|
|
1109
1739
|
|
|
1740
|
+
exports.RichDetails = RichDetails;
|
|
1110
1741
|
exports.RichLayout = RichLayout;
|
|
1111
1742
|
exports.RichTable = RichTable;
|
|
1112
1743
|
exports.registerAll = registerAll;
|