@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
package/dist/field-mappings.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { TableSchema, QueryResult } from "@plasmicapp/data-sources";
|
|
2
2
|
import { PropType } from "@plasmicapp/host/registerComponent";
|
|
3
|
-
import { QueryResult } from "./queries";
|
|
4
3
|
import { ContextDependentConfig } from "@plasmicapp/host";
|
|
5
4
|
export interface AutoSettings {
|
|
6
5
|
dataType: "auto";
|
|
@@ -67,10 +66,6 @@ interface _BaseColumnConfig {
|
|
|
67
66
|
expr?: CellFunc<any>;
|
|
68
67
|
}
|
|
69
68
|
export type BaseColumnConfig = _BaseColumnConfig & (AutoSettings | NumberSettings | StringSettings | BooleanSettings | DateTimeSettings | RelativeDateTimeSettings);
|
|
70
|
-
export declare function deriveFieldConfigs<ColumnConfig extends BaseColumnConfig>(specifiedFieldsPartial: Partial<ColumnConfig>[], schema: TableSchema | undefined, makeDefaultConfig: (field: TableFieldSchema | undefined) => ColumnConfig): {
|
|
71
|
-
mergedFields: ColumnConfig[];
|
|
72
|
-
minimalFullLengthFields: Partial<ColumnConfig>[];
|
|
73
|
-
};
|
|
74
69
|
export declare function deriveValueType(cconfig: BaseColumnConfig): "text" | "switch" | "digit" | undefined;
|
|
75
70
|
export interface ControlContextData<ColumnConfig extends BaseColumnConfig> {
|
|
76
71
|
data: unknown[];
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { NormalizedData, QueryResult } from "
|
|
1
|
+
import { NormalizedData, QueryResult } from "@plasmicapp/data-sources";
|
|
2
2
|
import { BaseColumnConfig } from "./field-mappings";
|
|
3
3
|
import React, { Key } from "react";
|
|
4
4
|
import type { GetRowKey, SorterResult } from "antd/es/table/interface";
|
package/dist/index.js
CHANGED
|
@@ -4,6 +4,7 @@ var registerComponent = require('@plasmicapp/host/registerComponent');
|
|
|
4
4
|
require('@plasmicapp/host/registerGlobalContext');
|
|
5
5
|
require('lodash/get');
|
|
6
6
|
var React = require('react');
|
|
7
|
+
var dataSources = require('@plasmicapp/data-sources');
|
|
7
8
|
var antd = require('antd');
|
|
8
9
|
var tinycolor = require('@ctrl/tinycolor');
|
|
9
10
|
var icons = require('@ant-design/icons');
|
|
@@ -151,20 +152,7 @@ function isInteractable(target) {
|
|
|
151
152
|
function ensureArray(xs) {
|
|
152
153
|
return Array.isArray(xs) ? xs : [xs];
|
|
153
154
|
}
|
|
154
|
-
var tuple = function () {
|
|
155
|
-
var args = [];
|
|
156
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
157
|
-
args[_i] = arguments[_i];
|
|
158
|
-
}
|
|
159
|
-
return args;
|
|
160
|
-
};
|
|
161
|
-
function mkIdMap(xs) {
|
|
162
|
-
return new Map(xs.map(function (x) { return tuple(x.id, x); }));
|
|
163
|
-
}
|
|
164
155
|
var mkShortId = function () { return "".concat(Math.random()); };
|
|
165
|
-
function withoutNils(xs) {
|
|
166
|
-
return xs.filter(function (x) { return x != null; });
|
|
167
|
-
}
|
|
168
156
|
function withoutFalsey(xs) {
|
|
169
157
|
return xs.filter(function (x) { return !!x; });
|
|
170
158
|
}
|
|
@@ -194,34 +182,6 @@ var DEFAULT_BOOLEAN_SETTINGS = {
|
|
|
194
182
|
dataType: "boolean",
|
|
195
183
|
showAs: "checkbox",
|
|
196
184
|
};
|
|
197
|
-
function deriveFieldConfigs(specifiedFieldsPartial, schema, makeDefaultConfig) {
|
|
198
|
-
var _a;
|
|
199
|
-
var schemaFields = (_a = schema === null || schema === void 0 ? void 0 : schema.fields) !== null && _a !== void 0 ? _a : [];
|
|
200
|
-
var fieldById = mkIdMap(schemaFields);
|
|
201
|
-
var specifiedFieldIds = new Set(withoutNils(specifiedFieldsPartial.map(function (f) { return f.fieldId; })));
|
|
202
|
-
var keptSpecifiedFields = specifiedFieldsPartial.flatMap(function (f, index) {
|
|
203
|
-
var fieldId = f.fieldId;
|
|
204
|
-
if (!fieldId) {
|
|
205
|
-
return [
|
|
206
|
-
__assign(__assign(__assign({}, makeDefaultConfig(undefined)), { key: index }), f),
|
|
207
|
-
];
|
|
208
|
-
}
|
|
209
|
-
var field = fieldById.get(fieldId);
|
|
210
|
-
// Drop configs with fieldIds no longer in the data.
|
|
211
|
-
if (!field) {
|
|
212
|
-
return [];
|
|
213
|
-
}
|
|
214
|
-
return [
|
|
215
|
-
__assign(__assign({}, makeDefaultConfig(field)), f),
|
|
216
|
-
];
|
|
217
|
-
});
|
|
218
|
-
var newVirtualFields = schemaFields
|
|
219
|
-
.filter(function (f) { return !specifiedFieldIds.has(f.id); })
|
|
220
|
-
.map(function (f) { return (__assign({}, makeDefaultConfig(f))); });
|
|
221
|
-
var mergedFields = __spreadArray(__spreadArray([], keptSpecifiedFields, true), newVirtualFields, true);
|
|
222
|
-
var minimalFullLengthFields = __spreadArray(__spreadArray([], specifiedFieldsPartial, true), newVirtualFields.map(function (f) { return ({ key: f.key, fieldId: f.fieldId }); }), true);
|
|
223
|
-
return { mergedFields: mergedFields, minimalFullLengthFields: minimalFullLengthFields };
|
|
224
|
-
}
|
|
225
185
|
function deriveValueType(cconfig) {
|
|
226
186
|
return cconfig.dataType === "auto"
|
|
227
187
|
? undefined
|
|
@@ -617,86 +577,6 @@ function buildFieldsPropType(_a) {
|
|
|
617
577
|
};
|
|
618
578
|
}
|
|
619
579
|
|
|
620
|
-
function normalizeData(rawData) {
|
|
621
|
-
var _a;
|
|
622
|
-
if (!rawData) {
|
|
623
|
-
return undefined;
|
|
624
|
-
}
|
|
625
|
-
var dataArray = tryGetDataArray(rawData);
|
|
626
|
-
if (!dataArray) {
|
|
627
|
-
return undefined;
|
|
628
|
-
}
|
|
629
|
-
var schema = (_a = rawData.schema) !== null && _a !== void 0 ? _a : tryGetSchema(dataArray);
|
|
630
|
-
if (!schema) {
|
|
631
|
-
return undefined;
|
|
632
|
-
}
|
|
633
|
-
return { data: dataArray, schema: schema };
|
|
634
|
-
}
|
|
635
|
-
function tryGetDataArray(rawData) {
|
|
636
|
-
if (!rawData || typeof rawData !== "object") {
|
|
637
|
-
return undefined;
|
|
638
|
-
}
|
|
639
|
-
if (Array.isArray(rawData)) {
|
|
640
|
-
if (isArrayOfObjects(rawData)) {
|
|
641
|
-
return rawData;
|
|
642
|
-
}
|
|
643
|
-
else {
|
|
644
|
-
// TODO: array of primitives? Maybe we can wrap this?
|
|
645
|
-
return undefined;
|
|
646
|
-
}
|
|
647
|
-
}
|
|
648
|
-
if ("data" in rawData && Array.isArray(rawData.data)) {
|
|
649
|
-
if (isArrayOfObjects(rawData.data)) {
|
|
650
|
-
return rawData.data;
|
|
651
|
-
}
|
|
652
|
-
else {
|
|
653
|
-
return undefined;
|
|
654
|
-
}
|
|
655
|
-
}
|
|
656
|
-
if ("isLoading" in rawData || "error" in rawData) {
|
|
657
|
-
return undefined;
|
|
658
|
-
}
|
|
659
|
-
// Maybe a singleton record?
|
|
660
|
-
return [rawData];
|
|
661
|
-
}
|
|
662
|
-
function isArrayOfObjects(arr) {
|
|
663
|
-
return arr.every(function (x) { return typeof x === "object" && !Array.isArray(x); });
|
|
664
|
-
}
|
|
665
|
-
function tryGetSchema(data) {
|
|
666
|
-
var fieldMap = {};
|
|
667
|
-
data.forEach(function (entry) {
|
|
668
|
-
if (entry && typeof entry === "object") {
|
|
669
|
-
Array.from(Object.entries(entry)).forEach(function (_a) {
|
|
670
|
-
var k = _a[0], v = _a[1];
|
|
671
|
-
var inferredType = typeof v === "string"
|
|
672
|
-
? "string"
|
|
673
|
-
: typeof v === "boolean"
|
|
674
|
-
? "boolean"
|
|
675
|
-
: typeof v === "number"
|
|
676
|
-
? "number"
|
|
677
|
-
: "unknown";
|
|
678
|
-
if (fieldMap[k] && fieldMap[k] !== inferredType) {
|
|
679
|
-
fieldMap[k] = "unknown";
|
|
680
|
-
}
|
|
681
|
-
else {
|
|
682
|
-
fieldMap[k] = inferredType;
|
|
683
|
-
}
|
|
684
|
-
});
|
|
685
|
-
}
|
|
686
|
-
});
|
|
687
|
-
return {
|
|
688
|
-
id: "inferred",
|
|
689
|
-
fields: Object.entries(fieldMap).map(function (_a) {
|
|
690
|
-
var f = _a[0], t = _a[1];
|
|
691
|
-
return ({
|
|
692
|
-
id: f,
|
|
693
|
-
type: t,
|
|
694
|
-
readOnly: false,
|
|
695
|
-
});
|
|
696
|
-
}),
|
|
697
|
-
};
|
|
698
|
-
}
|
|
699
|
-
|
|
700
580
|
function multiRenderValue(record, cconfigs) {
|
|
701
581
|
return cconfigs === null || cconfigs === void 0 ? void 0 : cconfigs.flatMap(function (cc) {
|
|
702
582
|
return cc.isHidden ? [] : [" \u2022 ", React__default.default.createElement(React__default.default.Fragment, null, renderValue(record, cc))];
|
|
@@ -928,7 +808,7 @@ function asString(value) {
|
|
|
928
808
|
function RichDetails(props) {
|
|
929
809
|
var _a;
|
|
930
810
|
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;
|
|
931
|
-
var data = normalizeData(rawData);
|
|
811
|
+
var data = dataSources.normalizeData(rawData);
|
|
932
812
|
var columnDefinitions = useColumnDefinitions$1(data, props).columnDefinitions;
|
|
933
813
|
if (!data || !((_a = data.data) === null || _a === void 0 ? void 0 : _a[0])) {
|
|
934
814
|
return React__default.default.createElement(antd.Empty, { className: className, image: antd.Empty.PRESENTED_IMAGE_SIMPLE });
|
|
@@ -947,7 +827,7 @@ function useColumnDefinitions$1(data, props) {
|
|
|
947
827
|
if (!data || !schema) {
|
|
948
828
|
return { normalized: [], columnDefinitions: [] };
|
|
949
829
|
}
|
|
950
|
-
var _a = deriveFieldConfigs(fields !== null && fields !== void 0 ? fields : [], schema, function (field) { return (__assign({ key: mkShortId(), isHidden: false, dataType: "auto" }, (field && {
|
|
830
|
+
var _a = dataSources.deriveFieldConfigs(fields !== null && fields !== void 0 ? fields : [], schema, function (field) { return (__assign({ key: mkShortId(), isHidden: false, dataType: "auto" }, (field && {
|
|
951
831
|
key: field.id,
|
|
952
832
|
fieldId: field.id,
|
|
953
833
|
title: field.label || field.id,
|
|
@@ -1484,7 +1364,7 @@ function RichTable(props) {
|
|
|
1484
1364
|
_b = props.pagination,
|
|
1485
1365
|
// children,
|
|
1486
1366
|
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;
|
|
1487
|
-
var data = normalizeData(rawData);
|
|
1367
|
+
var data = dataSources.normalizeData(rawData);
|
|
1488
1368
|
var _f = useColumnDefinitions(data, props), columnDefinitions = _f.columnDefinitions, normalized = _f.normalized;
|
|
1489
1369
|
var actionRef = React.useRef();
|
|
1490
1370
|
var _g = useSortedFilteredData(data, normalized), finalData = _g.finalData, search = _g.search, setSearch = _g.setSearch, setSortState = _g.setSortState;
|
|
@@ -1561,7 +1441,7 @@ function useColumnDefinitions(data, props) {
|
|
|
1561
1441
|
if (!data || !schema) {
|
|
1562
1442
|
return { normalized: [], columnDefinitions: [] };
|
|
1563
1443
|
}
|
|
1564
|
-
var _a = deriveFieldConfigs(fields !== null && fields !== void 0 ? fields : [], schema, function (field) { return (__assign(__assign({}, defaultColumnConfig$1()), (field && {
|
|
1444
|
+
var _a = dataSources.deriveFieldConfigs(fields !== null && fields !== void 0 ? fields : [], schema, function (field) { return (__assign(__assign({}, defaultColumnConfig$1()), (field && {
|
|
1565
1445
|
key: field.id,
|
|
1566
1446
|
fieldId: field.id,
|
|
1567
1447
|
title: field.label || field.id,
|
|
@@ -1964,7 +1844,7 @@ function RichList(props) {
|
|
|
1964
1844
|
],
|
|
1965
1845
|
},
|
|
1966
1846
|
} : _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"]);
|
|
1967
|
-
var data = normalizeData(rawData);
|
|
1847
|
+
var data = dataSources.normalizeData(rawData);
|
|
1968
1848
|
var _f = useRoleDefinitions(data, props), normalized = _f.normalized, roleConfigs = _f.finalRoles;
|
|
1969
1849
|
React.useRef();
|
|
1970
1850
|
// Simply ignore the linkTo if it's not a function.
|
|
@@ -2097,7 +1977,7 @@ function useRoleDefinitions(data, props) {
|
|
|
2097
1977
|
}
|
|
2098
1978
|
}
|
|
2099
1979
|
// This is only being computed to get the default role choices.
|
|
2100
|
-
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 && {
|
|
1980
|
+
var _e = dataSources.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 && {
|
|
2101
1981
|
key: field.id,
|
|
2102
1982
|
fieldId: field.id,
|
|
2103
1983
|
title: field.label || field.id,
|