@plasmicpkgs/plasmic-rich-components 1.0.97 → 1.0.99
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 +1 -6
- package/dist/field-react-utils.d.ts +1 -1
- package/dist/index.js +7 -127
- package/dist/index.js.map +1 -1
- package/dist/plasmic-rich-components.esm.js +1 -121
- package/dist/plasmic-rich-components.esm.js.map +1 -1
- package/package.json +4 -4
- package/dist/queries.d.ts +0 -10
|
@@ -2,6 +2,7 @@ import registerComponent from '@plasmicapp/host/registerComponent';
|
|
|
2
2
|
import '@plasmicapp/host/registerGlobalContext';
|
|
3
3
|
import 'lodash/get';
|
|
4
4
|
import React, { useState, useEffect, useRef } from 'react';
|
|
5
|
+
import { normalizeData, deriveFieldConfigs } from '@plasmicapp/data-sources';
|
|
5
6
|
import { Checkbox, Switch, Empty, Descriptions, theme, ConfigProvider, Dropdown, Button, Input, List, Card, Tag } from 'antd';
|
|
6
7
|
import { tinycolor } from '@ctrl/tinycolor';
|
|
7
8
|
import { LogoutOutlined, PlusOutlined, EllipsisOutlined } from '@ant-design/icons';
|
|
@@ -141,20 +142,7 @@ function isInteractable(target) {
|
|
|
141
142
|
function ensureArray(xs) {
|
|
142
143
|
return Array.isArray(xs) ? xs : [xs];
|
|
143
144
|
}
|
|
144
|
-
var tuple = function () {
|
|
145
|
-
var args = [];
|
|
146
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
147
|
-
args[_i] = arguments[_i];
|
|
148
|
-
}
|
|
149
|
-
return args;
|
|
150
|
-
};
|
|
151
|
-
function mkIdMap(xs) {
|
|
152
|
-
return new Map(xs.map(function (x) { return tuple(x.id, x); }));
|
|
153
|
-
}
|
|
154
145
|
var mkShortId = function () { return "".concat(Math.random()); };
|
|
155
|
-
function withoutNils(xs) {
|
|
156
|
-
return xs.filter(function (x) { return x != null; });
|
|
157
|
-
}
|
|
158
146
|
function withoutFalsey(xs) {
|
|
159
147
|
return xs.filter(function (x) { return !!x; });
|
|
160
148
|
}
|
|
@@ -184,34 +172,6 @@ var DEFAULT_BOOLEAN_SETTINGS = {
|
|
|
184
172
|
dataType: "boolean",
|
|
185
173
|
showAs: "checkbox",
|
|
186
174
|
};
|
|
187
|
-
function deriveFieldConfigs(specifiedFieldsPartial, schema, makeDefaultConfig) {
|
|
188
|
-
var _a;
|
|
189
|
-
var schemaFields = (_a = schema === null || schema === void 0 ? void 0 : schema.fields) !== null && _a !== void 0 ? _a : [];
|
|
190
|
-
var fieldById = mkIdMap(schemaFields);
|
|
191
|
-
var specifiedFieldIds = new Set(withoutNils(specifiedFieldsPartial.map(function (f) { return f.fieldId; })));
|
|
192
|
-
var keptSpecifiedFields = specifiedFieldsPartial.flatMap(function (f, index) {
|
|
193
|
-
var fieldId = f.fieldId;
|
|
194
|
-
if (!fieldId) {
|
|
195
|
-
return [
|
|
196
|
-
__assign(__assign(__assign({}, makeDefaultConfig(undefined)), { key: index }), f),
|
|
197
|
-
];
|
|
198
|
-
}
|
|
199
|
-
var field = fieldById.get(fieldId);
|
|
200
|
-
// Drop configs with fieldIds no longer in the data.
|
|
201
|
-
if (!field) {
|
|
202
|
-
return [];
|
|
203
|
-
}
|
|
204
|
-
return [
|
|
205
|
-
__assign(__assign({}, makeDefaultConfig(field)), f),
|
|
206
|
-
];
|
|
207
|
-
});
|
|
208
|
-
var newVirtualFields = schemaFields
|
|
209
|
-
.filter(function (f) { return !specifiedFieldIds.has(f.id); })
|
|
210
|
-
.map(function (f) { return (__assign({}, makeDefaultConfig(f))); });
|
|
211
|
-
var mergedFields = __spreadArray(__spreadArray([], keptSpecifiedFields, true), newVirtualFields, true);
|
|
212
|
-
var minimalFullLengthFields = __spreadArray(__spreadArray([], specifiedFieldsPartial, true), newVirtualFields.map(function (f) { return ({ key: f.key, fieldId: f.fieldId }); }), true);
|
|
213
|
-
return { mergedFields: mergedFields, minimalFullLengthFields: minimalFullLengthFields };
|
|
214
|
-
}
|
|
215
175
|
function deriveValueType(cconfig) {
|
|
216
176
|
return cconfig.dataType === "auto"
|
|
217
177
|
? undefined
|
|
@@ -607,86 +567,6 @@ function buildFieldsPropType(_a) {
|
|
|
607
567
|
};
|
|
608
568
|
}
|
|
609
569
|
|
|
610
|
-
function normalizeData(rawData) {
|
|
611
|
-
var _a;
|
|
612
|
-
if (!rawData) {
|
|
613
|
-
return undefined;
|
|
614
|
-
}
|
|
615
|
-
var dataArray = tryGetDataArray(rawData);
|
|
616
|
-
if (!dataArray) {
|
|
617
|
-
return undefined;
|
|
618
|
-
}
|
|
619
|
-
var schema = (_a = rawData.schema) !== null && _a !== void 0 ? _a : tryGetSchema(dataArray);
|
|
620
|
-
if (!schema) {
|
|
621
|
-
return undefined;
|
|
622
|
-
}
|
|
623
|
-
return { data: dataArray, schema: schema };
|
|
624
|
-
}
|
|
625
|
-
function tryGetDataArray(rawData) {
|
|
626
|
-
if (!rawData || typeof rawData !== "object") {
|
|
627
|
-
return undefined;
|
|
628
|
-
}
|
|
629
|
-
if (Array.isArray(rawData)) {
|
|
630
|
-
if (isArrayOfObjects(rawData)) {
|
|
631
|
-
return rawData;
|
|
632
|
-
}
|
|
633
|
-
else {
|
|
634
|
-
// TODO: array of primitives? Maybe we can wrap this?
|
|
635
|
-
return undefined;
|
|
636
|
-
}
|
|
637
|
-
}
|
|
638
|
-
if ("data" in rawData && Array.isArray(rawData.data)) {
|
|
639
|
-
if (isArrayOfObjects(rawData.data)) {
|
|
640
|
-
return rawData.data;
|
|
641
|
-
}
|
|
642
|
-
else {
|
|
643
|
-
return undefined;
|
|
644
|
-
}
|
|
645
|
-
}
|
|
646
|
-
if ("isLoading" in rawData || "error" in rawData) {
|
|
647
|
-
return undefined;
|
|
648
|
-
}
|
|
649
|
-
// Maybe a singleton record?
|
|
650
|
-
return [rawData];
|
|
651
|
-
}
|
|
652
|
-
function isArrayOfObjects(arr) {
|
|
653
|
-
return arr.every(function (x) { return typeof x === "object" && !Array.isArray(x); });
|
|
654
|
-
}
|
|
655
|
-
function tryGetSchema(data) {
|
|
656
|
-
var fieldMap = {};
|
|
657
|
-
data.forEach(function (entry) {
|
|
658
|
-
if (entry && typeof entry === "object") {
|
|
659
|
-
Array.from(Object.entries(entry)).forEach(function (_a) {
|
|
660
|
-
var k = _a[0], v = _a[1];
|
|
661
|
-
var inferredType = typeof v === "string"
|
|
662
|
-
? "string"
|
|
663
|
-
: typeof v === "boolean"
|
|
664
|
-
? "boolean"
|
|
665
|
-
: typeof v === "number"
|
|
666
|
-
? "number"
|
|
667
|
-
: "unknown";
|
|
668
|
-
if (fieldMap[k] && fieldMap[k] !== inferredType) {
|
|
669
|
-
fieldMap[k] = "unknown";
|
|
670
|
-
}
|
|
671
|
-
else {
|
|
672
|
-
fieldMap[k] = inferredType;
|
|
673
|
-
}
|
|
674
|
-
});
|
|
675
|
-
}
|
|
676
|
-
});
|
|
677
|
-
return {
|
|
678
|
-
id: "inferred",
|
|
679
|
-
fields: Object.entries(fieldMap).map(function (_a) {
|
|
680
|
-
var f = _a[0], t = _a[1];
|
|
681
|
-
return ({
|
|
682
|
-
id: f,
|
|
683
|
-
type: t,
|
|
684
|
-
readOnly: false,
|
|
685
|
-
});
|
|
686
|
-
}),
|
|
687
|
-
};
|
|
688
|
-
}
|
|
689
|
-
|
|
690
570
|
function multiRenderValue(record, cconfigs) {
|
|
691
571
|
return cconfigs === null || cconfigs === void 0 ? void 0 : cconfigs.flatMap(function (cc) {
|
|
692
572
|
return cc.isHidden ? [] : [" \u2022 ", React.createElement(React.Fragment, null, renderValue(record, cc))];
|