@plasmicpkgs/plasmic-rich-components 1.0.103 → 1.0.105
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/.tsbuildinfo +1 -1
- package/dist/index.js +112 -45
- package/dist/index.js.map +1 -1
- package/dist/plasmic-rich-components.esm.js +112 -45
- package/dist/plasmic-rich-components.esm.js.map +1 -1
- package/dist/utils.d.ts +22 -0
- package/package.json +4 -4
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import registerComponent from '@plasmicapp/host/registerComponent';
|
|
2
2
|
import '@plasmicapp/host/registerGlobalContext';
|
|
3
|
-
import 'lodash/get';
|
|
4
3
|
import React, { useState, useEffect, useRef } from 'react';
|
|
4
|
+
import { Result, Checkbox, Switch, Empty, Descriptions, theme, ConfigProvider, Dropdown, Button, Input, List, Tag, Card } from 'antd';
|
|
5
|
+
import 'lodash/get';
|
|
5
6
|
import { normalizeData, deriveFieldConfigs } from '@plasmicapp/data-sources';
|
|
6
|
-
import { Checkbox, Switch, Empty, Descriptions, theme, ConfigProvider, Dropdown, Button, Input, List, Tag, Card } from 'antd';
|
|
7
7
|
import { tinycolor } from '@ctrl/tinycolor';
|
|
8
8
|
import { LogoutOutlined, PlusOutlined, EllipsisOutlined } from '@ant-design/icons';
|
|
9
9
|
import { ProLayout, ProConfigProvider, ProTable } from '@ant-design/pro-components';
|
|
@@ -53,6 +53,36 @@ const mkShortId = () => `${Math.random()}`;
|
|
|
53
53
|
function withoutFalsey(xs) {
|
|
54
54
|
return xs.filter((x) => !!x);
|
|
55
55
|
}
|
|
56
|
+
class ErrorBoundary extends React.Component {
|
|
57
|
+
constructor() {
|
|
58
|
+
super(...arguments);
|
|
59
|
+
this.state = { hasError: false, errorInfo: "" };
|
|
60
|
+
}
|
|
61
|
+
static getDerivedStateFromError(error) {
|
|
62
|
+
return { hasError: true, errorInfo: error.message };
|
|
63
|
+
}
|
|
64
|
+
componentDidCatch(error, errorInfo) {
|
|
65
|
+
console.log(error, errorInfo);
|
|
66
|
+
}
|
|
67
|
+
componentDidUpdate(prevProps, prevState) {
|
|
68
|
+
if (prevProps.canvasEnvId !== this.props.canvasEnvId && prevState.hasError) {
|
|
69
|
+
this.setState({ hasError: false });
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
render() {
|
|
73
|
+
if (this.state.hasError) {
|
|
74
|
+
return /* @__PURE__ */ React.createElement(
|
|
75
|
+
Result,
|
|
76
|
+
{
|
|
77
|
+
status: "error",
|
|
78
|
+
title: "Something went wrong.",
|
|
79
|
+
extra: this.state.errorInfo
|
|
80
|
+
}
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
return this.props.children;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
56
86
|
|
|
57
87
|
var __defProp$9 = Object.defineProperty;
|
|
58
88
|
var __defProps$7 = Object.defineProperties;
|
|
@@ -1449,9 +1479,10 @@ function RichTable(props) {
|
|
|
1449
1479
|
if (!isClient) {
|
|
1450
1480
|
return null;
|
|
1451
1481
|
}
|
|
1452
|
-
return /* @__PURE__ */ React.createElement("div", { className: `${className} ${scopeClassName != null ? scopeClassName : ""}` }, /* @__PURE__ */ React.createElement(
|
|
1482
|
+
return /* @__PURE__ */ React.createElement("div", { className: `${className} ${scopeClassName != null ? scopeClassName : ""}` }, /* @__PURE__ */ React.createElement(ErrorBoundary, { canvasEnvId: props["data-plasmic-canvas-envs"] }, /* @__PURE__ */ React.createElement(
|
|
1453
1483
|
ProTable,
|
|
1454
1484
|
__spreadProps$2(__spreadValues$3({
|
|
1485
|
+
ErrorBoundary: false,
|
|
1455
1486
|
rowClassName: props.onRowClick || props.canSelectRows === "click" ? "plasmic-table-row-clickable" : void 0,
|
|
1456
1487
|
actionRef,
|
|
1457
1488
|
columns: columnDefinitions,
|
|
@@ -1508,7 +1539,7 @@ function RichTable(props) {
|
|
|
1508
1539
|
!hideExports && /* @__PURE__ */ React.createElement(ExportMenu, { data })
|
|
1509
1540
|
].filter((x) => !!x)
|
|
1510
1541
|
})
|
|
1511
|
-
), /* @__PURE__ */ React.createElement(
|
|
1542
|
+
)), /* @__PURE__ */ React.createElement(
|
|
1512
1543
|
"style",
|
|
1513
1544
|
{
|
|
1514
1545
|
dangerouslySetInnerHTML: {
|
|
@@ -2083,6 +2114,10 @@ const listCss = `
|
|
|
2083
2114
|
padding-right: 8px;
|
|
2084
2115
|
}
|
|
2085
2116
|
|
|
2117
|
+
.ant-list .plasmic-list-item {
|
|
2118
|
+
align-items: stretch;
|
|
2119
|
+
}
|
|
2120
|
+
|
|
2086
2121
|
.plasmic-list-item--clickable:hover {
|
|
2087
2122
|
background-color: #8881;
|
|
2088
2123
|
}
|
|
@@ -2132,7 +2167,7 @@ function RichList(props) {
|
|
|
2132
2167
|
pageSize = 10,
|
|
2133
2168
|
hideSearch,
|
|
2134
2169
|
rowKey,
|
|
2135
|
-
pagination,
|
|
2170
|
+
pagination = true,
|
|
2136
2171
|
onRowClick
|
|
2137
2172
|
} = _a; __objRest(_a, [
|
|
2138
2173
|
"data",
|
|
@@ -2242,7 +2277,7 @@ function RichList(props) {
|
|
|
2242
2277
|
var _a3;
|
|
2243
2278
|
return (_a3 = linkWrapper == null ? void 0 : linkWrapper(x)) != null ? _a3 : x;
|
|
2244
2279
|
}
|
|
2245
|
-
return type === "grid" ? /* @__PURE__ */ React.createElement(List.Item,
|
|
2280
|
+
return type === "grid" ? /* @__PURE__ */ React.createElement(List.Item, { className: "plasmic-list-item" }, maybeLink(
|
|
2246
2281
|
/* @__PURE__ */ React.createElement(
|
|
2247
2282
|
Card,
|
|
2248
2283
|
{
|
|
@@ -2260,6 +2295,7 @@ function RichList(props) {
|
|
|
2260
2295
|
{
|
|
2261
2296
|
actions,
|
|
2262
2297
|
className: classNames({
|
|
2298
|
+
"plasmic-list-item": true,
|
|
2263
2299
|
"plasmic-list-item--clickable": hasLink
|
|
2264
2300
|
})
|
|
2265
2301
|
},
|
|
@@ -2353,7 +2389,7 @@ function useRoleDefinitions(data, props) {
|
|
|
2353
2389
|
const schema = data == null ? void 0 : data.schema;
|
|
2354
2390
|
const schemaMap = new Map((_a = data == null ? void 0 : data.schema) == null ? void 0 : _a.fields.map((f) => [f.id, f]));
|
|
2355
2391
|
if (!data || !schema) {
|
|
2356
|
-
return { normalized: [],
|
|
2392
|
+
return { normalized: [], finalRoles: {} };
|
|
2357
2393
|
}
|
|
2358
2394
|
function tagFieldConfigs(role) {
|
|
2359
2395
|
var _a2;
|
|
@@ -2367,27 +2403,33 @@ function useRoleDefinitions(data, props) {
|
|
|
2367
2403
|
return [];
|
|
2368
2404
|
}
|
|
2369
2405
|
}
|
|
2370
|
-
const
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
|
|
2382
|
-
|
|
2383
|
-
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
|
|
2389
|
-
|
|
2390
|
-
|
|
2406
|
+
const specifiedFieldsPartial = [
|
|
2407
|
+
...tagFieldConfigs("image"),
|
|
2408
|
+
...tagFieldConfigs("content"),
|
|
2409
|
+
...tagFieldConfigs("title"),
|
|
2410
|
+
...tagFieldConfigs("beforeTitle"),
|
|
2411
|
+
...tagFieldConfigs("afterTitle"),
|
|
2412
|
+
...tagFieldConfigs("subtitle")
|
|
2413
|
+
];
|
|
2414
|
+
function doDeriveFieldConfigs(mode) {
|
|
2415
|
+
return deriveFieldConfigs(
|
|
2416
|
+
mode === "defaults" ? [] : specifiedFieldsPartial,
|
|
2417
|
+
schema,
|
|
2418
|
+
(field) => __spreadValues$1(__spreadValues$1({}, defaultColumnConfig()), field && {
|
|
2419
|
+
key: field.id,
|
|
2420
|
+
fieldId: field.id,
|
|
2421
|
+
title: field.label || field.id,
|
|
2422
|
+
// undefined means not yet determined in this routine, not 'unset'
|
|
2423
|
+
role: void 0,
|
|
2424
|
+
expr: (currentItem) => currentItem[field.id]
|
|
2425
|
+
})
|
|
2426
|
+
);
|
|
2427
|
+
}
|
|
2428
|
+
const {
|
|
2429
|
+
mergedFields: defaultMergedFields,
|
|
2430
|
+
minimalFullLengthFields: defaultMinimalFullLengthFields
|
|
2431
|
+
} = doDeriveFieldConfigs("defaults");
|
|
2432
|
+
if (data.data.length > 0 && !defaultMergedFields.some((field) => field.role === "image")) {
|
|
2391
2433
|
const sampleRows = Array.from(
|
|
2392
2434
|
new Set(
|
|
2393
2435
|
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9].map(
|
|
@@ -2395,7 +2437,7 @@ function useRoleDefinitions(data, props) {
|
|
|
2395
2437
|
)
|
|
2396
2438
|
)
|
|
2397
2439
|
).map((i) => data.data[i]);
|
|
2398
|
-
const imageFieldCandidates =
|
|
2440
|
+
const imageFieldCandidates = defaultMergedFields.filter(
|
|
2399
2441
|
(field) => !field.role && sampleRows.filter(
|
|
2400
2442
|
(row) => field.fieldId && isLikeImage(row[field.fieldId])
|
|
2401
2443
|
).length >= sampleRows.length / 2
|
|
@@ -2419,8 +2461,8 @@ function useRoleDefinitions(data, props) {
|
|
|
2419
2461
|
imageField.role = "image";
|
|
2420
2462
|
}
|
|
2421
2463
|
}
|
|
2422
|
-
if (!
|
|
2423
|
-
const titleField =
|
|
2464
|
+
if (!defaultMergedFields.some((field) => field.role === "title")) {
|
|
2465
|
+
const titleField = defaultMergedFields.find(
|
|
2424
2466
|
(field) => {
|
|
2425
2467
|
var _a2;
|
|
2426
2468
|
return !field.role && ((_a2 = field.fieldId) == null ? void 0 : _a2.toLowerCase().match(/^(title|name|first[ _-]?name|full[ _-]?name)$/));
|
|
@@ -2430,8 +2472,8 @@ function useRoleDefinitions(data, props) {
|
|
|
2430
2472
|
titleField.role = "title";
|
|
2431
2473
|
}
|
|
2432
2474
|
}
|
|
2433
|
-
if (!
|
|
2434
|
-
const contentField =
|
|
2475
|
+
if (!defaultMergedFields.some((field) => field.role === "content")) {
|
|
2476
|
+
const contentField = defaultMergedFields.find(
|
|
2435
2477
|
(field) => {
|
|
2436
2478
|
var _a2;
|
|
2437
2479
|
return !field.role && field.fieldId && ((_a2 = schemaMap.get(field.fieldId)) == null ? void 0 : _a2.type) === "string";
|
|
@@ -2441,19 +2483,49 @@ function useRoleDefinitions(data, props) {
|
|
|
2441
2483
|
contentField.role = "content";
|
|
2442
2484
|
}
|
|
2443
2485
|
}
|
|
2444
|
-
const
|
|
2486
|
+
const fieldIdToDefaultRole = new Map(
|
|
2487
|
+
defaultMergedFields.map((f) => [f.fieldId, f.role])
|
|
2488
|
+
);
|
|
2489
|
+
for (const f of defaultMinimalFullLengthFields) {
|
|
2490
|
+
f.role = fieldIdToDefaultRole.get(f.fieldId);
|
|
2491
|
+
}
|
|
2492
|
+
const { mergedFields, minimalFullLengthFields } = doDeriveFieldConfigs("existing");
|
|
2493
|
+
const minimalFullLengthFieldsWithDefaults = [
|
|
2494
|
+
...minimalFullLengthFields.filter((f) => f.role && f.role !== "unset"),
|
|
2495
|
+
...defaultMinimalFullLengthFields.filter(
|
|
2496
|
+
(f) => f.role && f.role !== "unset" && !props[f.role]
|
|
2497
|
+
)
|
|
2498
|
+
];
|
|
2499
|
+
const mergedFieldsWithDefaults = [
|
|
2500
|
+
...mergedFields.filter((f) => f.role && f.role !== "unset"),
|
|
2501
|
+
...defaultMergedFields.filter(
|
|
2502
|
+
(f) => f.role && f.role !== "unset" && !props[f.role]
|
|
2503
|
+
)
|
|
2504
|
+
];
|
|
2505
|
+
console.log("!!derived", {
|
|
2506
|
+
minimalFullLengthFieldsWithDefaults,
|
|
2507
|
+
minimalFullLengthFields,
|
|
2508
|
+
defaultMinimalFullLengthFields,
|
|
2509
|
+
mergedFieldsWithDefaults,
|
|
2510
|
+
mergedFields,
|
|
2511
|
+
defaultMergedFields,
|
|
2512
|
+
props
|
|
2513
|
+
});
|
|
2514
|
+
const roleConfigs = ensure(
|
|
2515
|
+
groupBy(mergedFieldsWithDefaults, (f) => f.role)
|
|
2516
|
+
);
|
|
2445
2517
|
const finalRoles = {};
|
|
2446
2518
|
for (const role of roles) {
|
|
2447
2519
|
if (role !== "unset") {
|
|
2448
2520
|
finalRoles[role] = (_d = maybe(props[role], ensureArray)) != null ? _d : roleConfigs[role];
|
|
2449
2521
|
}
|
|
2450
2522
|
}
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
}
|
|
2455
|
-
|
|
2456
|
-
return { normalized,
|
|
2523
|
+
setControlContextData == null ? void 0 : setControlContextData(__spreadProps(__spreadValues$1({}, data), {
|
|
2524
|
+
mergedFields: mergedFieldsWithDefaults,
|
|
2525
|
+
minimalFullLengthFields: minimalFullLengthFieldsWithDefaults
|
|
2526
|
+
}));
|
|
2527
|
+
const normalized = mergedFieldsWithDefaults;
|
|
2528
|
+
return { normalized, finalRoles };
|
|
2457
2529
|
}, [fields, data, setControlContextData, rowActions]);
|
|
2458
2530
|
}
|
|
2459
2531
|
|
|
@@ -2519,11 +2591,6 @@ const richListMeta = {
|
|
|
2519
2591
|
padding: "16px",
|
|
2520
2592
|
maxHeight: "100%"
|
|
2521
2593
|
},
|
|
2522
|
-
templates: {
|
|
2523
|
-
grid: {
|
|
2524
|
-
props: {}
|
|
2525
|
-
}
|
|
2526
|
-
},
|
|
2527
2594
|
props: __spreadValues({
|
|
2528
2595
|
data: dataProp(),
|
|
2529
2596
|
type: {
|