@plasmicpkgs/plasmic-rich-components 1.0.61 → 1.0.62
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/common.d.ts +2 -2
- package/dist/field-mappings.d.ts +51 -51
- package/dist/index.d.ts +4 -4
- package/dist/index.js +971 -5
- package/dist/index.js.map +1 -0
- package/dist/plasmic-rich-components.esm.js +877 -1519
- package/dist/plasmic-rich-components.esm.js.map +1 -1
- package/dist/rich-layout/RichLayout.d.ts +16 -16
- package/dist/rich-layout/index.d.ts +5 -5
- package/dist/rich-table/RichTable.d.ts +45 -40
- package/dist/rich-table/index.d.ts +18 -5
- package/dist/utils.d.ts +24 -24
- package/package.json +3 -3
- package/dist/plasmic-rich-components.cjs.development.js +0 -1614
- package/dist/plasmic-rich-components.cjs.development.js.map +0 -1
- package/dist/plasmic-rich-components.cjs.production.min.js +0 -2
- package/dist/plasmic-rich-components.cjs.production.min.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,8 +1,974 @@
|
|
|
1
|
+
'use strict';
|
|
1
2
|
|
|
2
|
-
|
|
3
|
+
var React = require('react');
|
|
4
|
+
var registerComponent = require('@plasmicapp/host/registerComponent');
|
|
5
|
+
require('@plasmicapp/host/registerGlobalContext');
|
|
6
|
+
var icons = require('@ant-design/icons');
|
|
7
|
+
var proComponents = require('@ant-design/pro-components');
|
|
8
|
+
var antd = require('antd');
|
|
9
|
+
var host = require('@plasmicapp/host');
|
|
10
|
+
var csvWriterBrowser = require('csv-writer-browser');
|
|
11
|
+
var fastStringify = require('fast-stringify');
|
|
3
12
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
13
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
14
|
+
|
|
15
|
+
var React__default = /*#__PURE__*/_interopDefault(React);
|
|
16
|
+
var registerComponent__default = /*#__PURE__*/_interopDefault(registerComponent);
|
|
17
|
+
var fastStringify__default = /*#__PURE__*/_interopDefault(fastStringify);
|
|
18
|
+
|
|
19
|
+
/*! *****************************************************************************
|
|
20
|
+
Copyright (c) Microsoft Corporation.
|
|
21
|
+
|
|
22
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
23
|
+
purpose with or without fee is hereby granted.
|
|
24
|
+
|
|
25
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
26
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
27
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
28
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
29
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
30
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
31
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
32
|
+
***************************************************************************** */
|
|
33
|
+
|
|
34
|
+
var __assign = function() {
|
|
35
|
+
__assign = Object.assign || function __assign(t) {
|
|
36
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
37
|
+
s = arguments[i];
|
|
38
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
39
|
+
}
|
|
40
|
+
return t;
|
|
41
|
+
};
|
|
42
|
+
return __assign.apply(this, arguments);
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
function __rest(s, e) {
|
|
46
|
+
var t = {};
|
|
47
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
48
|
+
t[p] = s[p];
|
|
49
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
50
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
51
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
52
|
+
t[p[i]] = s[p[i]];
|
|
53
|
+
}
|
|
54
|
+
return t;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
58
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
59
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
60
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
61
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
62
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
63
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function __generator(thisArg, body) {
|
|
68
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
69
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
70
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
71
|
+
function step(op) {
|
|
72
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
73
|
+
while (_) try {
|
|
74
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
75
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
76
|
+
switch (op[0]) {
|
|
77
|
+
case 0: case 1: t = op; break;
|
|
78
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
79
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
80
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
81
|
+
default:
|
|
82
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
83
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
84
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
85
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
86
|
+
if (t[2]) _.ops.pop();
|
|
87
|
+
_.trys.pop(); continue;
|
|
88
|
+
}
|
|
89
|
+
op = body.call(thisArg, _);
|
|
90
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
91
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function __spreadArray(to, from, pack) {
|
|
96
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
97
|
+
if (ar || !(i in from)) {
|
|
98
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
99
|
+
ar[i] = from[i];
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function useIsClient() {
|
|
106
|
+
var _a = React.useState(false), loaded = _a[0], setLoaded = _a[1];
|
|
107
|
+
React.useEffect(function () {
|
|
108
|
+
setLoaded(true);
|
|
109
|
+
});
|
|
110
|
+
return loaded;
|
|
111
|
+
}
|
|
112
|
+
function capitalize(text) {
|
|
113
|
+
return text.slice(0, 1).toUpperCase() + text.slice(1);
|
|
114
|
+
}
|
|
115
|
+
|
|
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
|
+
function RichLayout(_a) {
|
|
126
|
+
var _b, _c, _d;
|
|
127
|
+
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"]);
|
|
128
|
+
var isClient = useIsClient();
|
|
129
|
+
var _f = React.useState(undefined), pathname = _f[0], setPathname = _f[1];
|
|
130
|
+
React.useEffect(function () {
|
|
131
|
+
if (typeof location !== "undefined") {
|
|
132
|
+
setPathname(location.pathname);
|
|
133
|
+
}
|
|
134
|
+
}, []);
|
|
135
|
+
if (!isClient) {
|
|
136
|
+
return null;
|
|
137
|
+
}
|
|
138
|
+
return (React__default.default.createElement("div", { className: className },
|
|
139
|
+
React__default.default.createElement("style", null, ".ant-pro-layout-bg-list {\n display: none;\n }"),
|
|
140
|
+
React__default.default.createElement(proComponents.ProLayout, __assign({}, layoutProps, {
|
|
141
|
+
// Tweak defaults. ProLayout is janky and has terrible docs!
|
|
142
|
+
layout: (_b = layoutProps.layout) !== null && _b !== void 0 ? _b : "top", fixedHeader: (_c = layoutProps.fixedHeader) !== null && _c !== void 0 ? _c : false, fixSiderbar:
|
|
143
|
+
// Doesn't stretch full height if you set this to false and you're in mix mode.
|
|
144
|
+
layoutProps.layout === "mix"
|
|
145
|
+
? undefined
|
|
146
|
+
: (_d = layoutProps.fixSiderbar) !== null && _d !== void 0 ? _d : false,
|
|
147
|
+
// This is always needed if you want layout mix to have effect and look any different from layout side - not clear why this should ever be false.
|
|
148
|
+
splitMenus: layoutProps.layout === "mix", route: {
|
|
149
|
+
path: rootUrl,
|
|
150
|
+
routes: navMenuItems,
|
|
151
|
+
}, location: {
|
|
152
|
+
pathname: pathname,
|
|
153
|
+
}, menu: {
|
|
154
|
+
// collapsedShowGroupTitle: true,
|
|
155
|
+
defaultOpenAll: true,
|
|
156
|
+
// hideMenuWhenCollapsed: true,
|
|
157
|
+
}, avatarProps: showAvatarMenu && false
|
|
158
|
+
? {
|
|
159
|
+
src: avatarImage,
|
|
160
|
+
size: "small",
|
|
161
|
+
title: avatarLabel,
|
|
162
|
+
render: function (_props, dom) {
|
|
163
|
+
return (React__default.default.createElement(antd.Dropdown, { menu: {
|
|
164
|
+
items: [
|
|
165
|
+
{
|
|
166
|
+
key: "logout",
|
|
167
|
+
icon: React__default.default.createElement(icons.LogoutOutlined, null),
|
|
168
|
+
label: "Sign out",
|
|
169
|
+
},
|
|
170
|
+
],
|
|
171
|
+
} }, dom));
|
|
172
|
+
},
|
|
173
|
+
}
|
|
174
|
+
: undefined, actionsRender: function (_props) {
|
|
175
|
+
return [actionsChildren];
|
|
176
|
+
}, menuFooterRender: function (props) {
|
|
177
|
+
if (props === null || props === void 0 ? void 0 : props.collapsed)
|
|
178
|
+
return undefined;
|
|
179
|
+
return footerChildren;
|
|
180
|
+
}, onMenuHeaderClick: function (e) { return console.log(e); }, menuItemRender: function (item, dom) { return React__default.default.createElement("a", { href: item.path }, dom); }, headerTitleRender: function (logo, title, _) {
|
|
181
|
+
return (React__default.default.createElement("a", { href: rootUrl },
|
|
182
|
+
logo,
|
|
183
|
+
title));
|
|
184
|
+
} }), children)));
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
function generateNavMenuType(remainingDepth, displayName, defaultValue) {
|
|
188
|
+
return {
|
|
189
|
+
displayName: displayName ? displayName : "Nested items",
|
|
190
|
+
type: "array",
|
|
191
|
+
defaultValue: defaultValue,
|
|
192
|
+
itemType: {
|
|
193
|
+
type: "object",
|
|
194
|
+
nameFunc: function (item) {
|
|
195
|
+
return item.name || (!displayName ? "Unnamed nested item" : "Unnamed item");
|
|
196
|
+
},
|
|
197
|
+
fields: __assign({ path: "string", name: "string" }, (remainingDepth === 0
|
|
198
|
+
? {}
|
|
199
|
+
: {
|
|
200
|
+
routes: generateNavMenuType(remainingDepth - 1),
|
|
201
|
+
})),
|
|
202
|
+
},
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
var richLayoutMeta = {
|
|
206
|
+
name: "hostless-rich-layout",
|
|
207
|
+
displayName: "Rich Page Layout",
|
|
208
|
+
props: {
|
|
209
|
+
children: "slot",
|
|
210
|
+
actionsChildren: {
|
|
211
|
+
type: "slot",
|
|
212
|
+
hidePlaceholder: true,
|
|
213
|
+
},
|
|
214
|
+
title: {
|
|
215
|
+
displayName: "Title",
|
|
216
|
+
type: "string",
|
|
217
|
+
defaultValue: "App title",
|
|
218
|
+
},
|
|
219
|
+
logo: {
|
|
220
|
+
displayName: "Logo",
|
|
221
|
+
type: "imageUrl",
|
|
222
|
+
defaultValue: "https://www.plasmic.app/favicon.ico",
|
|
223
|
+
},
|
|
224
|
+
navMenuItems: generateNavMenuType(2, "Nav menu items", [
|
|
225
|
+
{
|
|
226
|
+
path: "/",
|
|
227
|
+
name: "Link 1",
|
|
228
|
+
},
|
|
229
|
+
{
|
|
230
|
+
path: "/",
|
|
231
|
+
name: "Link 2",
|
|
232
|
+
},
|
|
233
|
+
]),
|
|
234
|
+
layout: {
|
|
235
|
+
displayName: "Layout",
|
|
236
|
+
type: "choice",
|
|
237
|
+
options: ["side", "top", "mix"].map(function (value) { return ({
|
|
238
|
+
value: value,
|
|
239
|
+
label: capitalize(value),
|
|
240
|
+
}); }),
|
|
241
|
+
defaultValueHint: "top",
|
|
242
|
+
},
|
|
243
|
+
// Advanced, show later
|
|
244
|
+
/*
|
|
245
|
+
siderMenuType: {
|
|
246
|
+
displayName: "Sidebar mode",
|
|
247
|
+
type: "choice",
|
|
248
|
+
options: ["sub", "group"].map((value) => ({
|
|
249
|
+
value,
|
|
250
|
+
label: capitalize(value),
|
|
251
|
+
})),
|
|
252
|
+
defaultValue: "sub",
|
|
253
|
+
},
|
|
254
|
+
contentWidth: {
|
|
255
|
+
displayName: "Content width",
|
|
256
|
+
type: "choice",
|
|
257
|
+
options: ["Fluid", "Fixed"],
|
|
258
|
+
defaultValueHint: "Fluid",
|
|
259
|
+
},
|
|
260
|
+
navTheme: {
|
|
261
|
+
displayName: "Theme",
|
|
262
|
+
type: "choice",
|
|
263
|
+
options: [
|
|
264
|
+
{ value: "realDark", label: "Dark" },
|
|
265
|
+
{ value: "light", label: "Light" },
|
|
266
|
+
],
|
|
267
|
+
},
|
|
268
|
+
colorPrimary: {
|
|
269
|
+
displayName: "Primary color",
|
|
270
|
+
type: "color",
|
|
271
|
+
},
|
|
272
|
+
*/
|
|
273
|
+
fixedHeader: {
|
|
274
|
+
displayName: "Sticky header",
|
|
275
|
+
type: "boolean",
|
|
276
|
+
hidden: function (ps) { var _a; return ((_a = ps.layout) !== null && _a !== void 0 ? _a : "top") !== "top"; },
|
|
277
|
+
defaultValueHint: false,
|
|
278
|
+
},
|
|
279
|
+
fixSiderbar: {
|
|
280
|
+
displayName: "Sticky sidebar",
|
|
281
|
+
type: "boolean",
|
|
282
|
+
hidden: function (ps) { var _a; return ((_a = ps.layout) !== null && _a !== void 0 ? _a : "top") !== "side"; },
|
|
283
|
+
defaultValueHint: false,
|
|
284
|
+
},
|
|
285
|
+
/*
|
|
286
|
+
showAvatarMenu: {
|
|
287
|
+
displayName: "Show avatar",
|
|
288
|
+
type: "boolean",
|
|
289
|
+
defaultValue: true,
|
|
290
|
+
},
|
|
291
|
+
avatarLabel: {
|
|
292
|
+
displayName: "Avatar label",
|
|
293
|
+
type: "string",
|
|
294
|
+
defaultValue: "User Name",
|
|
295
|
+
},
|
|
296
|
+
avatarImage: {
|
|
297
|
+
displayName: "Avatar image",
|
|
298
|
+
type: "imageUrl",
|
|
299
|
+
defaultValue:
|
|
300
|
+
"https://gw.alipayobjects.com/zos/antfincdn/efFD%24IOql2/weixintupian_20170331104822.jpg",
|
|
301
|
+
},
|
|
302
|
+
*/
|
|
303
|
+
menu: {
|
|
304
|
+
displayName: "Menu",
|
|
305
|
+
type: "object",
|
|
306
|
+
fields: {
|
|
307
|
+
defaultOpenAll: {
|
|
308
|
+
displayName: "Default open all",
|
|
309
|
+
type: "boolean",
|
|
310
|
+
},
|
|
311
|
+
hideMenuWhenCollapsed: {
|
|
312
|
+
// displayName: "",
|
|
313
|
+
type: "boolean",
|
|
314
|
+
},
|
|
315
|
+
},
|
|
316
|
+
},
|
|
317
|
+
},
|
|
318
|
+
defaultStyles: {
|
|
319
|
+
width: "stretch",
|
|
320
|
+
height: "stretch",
|
|
321
|
+
},
|
|
322
|
+
importName: "RichLayout",
|
|
323
|
+
importPath: "@plasmicpkgs/plasmic-rich-components",
|
|
324
|
+
};
|
|
325
|
+
function registerRichLayout(loader) {
|
|
326
|
+
registerComponentHelper(loader, RichLayout, richLayoutMeta);
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
var tuple = function () {
|
|
330
|
+
var args = [];
|
|
331
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
332
|
+
args[_i] = arguments[_i];
|
|
333
|
+
}
|
|
334
|
+
return args;
|
|
335
|
+
};
|
|
336
|
+
function mkIdMap(xs) {
|
|
337
|
+
return new Map(xs.map(function (x) { return tuple(x.id, x); }));
|
|
338
|
+
}
|
|
339
|
+
var mkShortId = function () { return "".concat(Math.random()); };
|
|
340
|
+
var withoutNils = function (xs) {
|
|
341
|
+
return xs.filter(function (x) { return x != null; });
|
|
342
|
+
};
|
|
343
|
+
var defaultColumnConfig = function () {
|
|
344
|
+
return ({
|
|
345
|
+
key: mkShortId(),
|
|
346
|
+
isEditableExpr: function () { return false; },
|
|
347
|
+
disableSorting: false,
|
|
348
|
+
sortByExpr: undefined,
|
|
349
|
+
isHidden: false,
|
|
350
|
+
formatting: {
|
|
351
|
+
styles: {},
|
|
352
|
+
align: "left",
|
|
353
|
+
freeze: "off",
|
|
354
|
+
},
|
|
355
|
+
dataType: "auto",
|
|
356
|
+
});
|
|
357
|
+
};
|
|
358
|
+
function deriveFieldConfigs(specifiedFieldsPartial, schema) {
|
|
359
|
+
var _a;
|
|
360
|
+
var schemaFields = (_a = schema === null || schema === void 0 ? void 0 : schema.fields) !== null && _a !== void 0 ? _a : [];
|
|
361
|
+
var fieldById = mkIdMap(schemaFields);
|
|
362
|
+
var specifiedFieldIds = new Set(withoutNils(specifiedFieldsPartial.map(function (f) { return f.fieldId; })));
|
|
363
|
+
function defaultColumnConfigForField(field) {
|
|
364
|
+
return __assign(__assign({}, defaultColumnConfig()), { key: field.id, fieldId: field.id, title: field.label || field.id, expr: function (currentItem) { return currentItem[field.id]; } });
|
|
365
|
+
}
|
|
366
|
+
var keptSpecifiedFields = specifiedFieldsPartial.flatMap(function (f, index) {
|
|
367
|
+
var fieldId = f.fieldId;
|
|
368
|
+
if (!fieldId) {
|
|
369
|
+
return [
|
|
370
|
+
__assign(__assign(__assign({}, defaultColumnConfig()), { key: index }), f),
|
|
371
|
+
];
|
|
372
|
+
}
|
|
373
|
+
var field = fieldById.get(fieldId);
|
|
374
|
+
// Drop configs with fieldIds no longer in the data.
|
|
375
|
+
if (!field) {
|
|
376
|
+
return [];
|
|
377
|
+
}
|
|
378
|
+
return [
|
|
379
|
+
__assign(__assign({}, defaultColumnConfigForField(field)), f),
|
|
380
|
+
];
|
|
381
|
+
});
|
|
382
|
+
var newVirtualFields = schemaFields
|
|
383
|
+
.filter(function (f) { return !specifiedFieldIds.has(f.id); })
|
|
384
|
+
.map(function (f) { return (__assign({}, defaultColumnConfigForField(f))); });
|
|
385
|
+
var mergedFields = __spreadArray(__spreadArray([], keptSpecifiedFields, true), newVirtualFields, true);
|
|
386
|
+
var minimalFullLengthFields = __spreadArray(__spreadArray([], specifiedFieldsPartial, true), newVirtualFields.map(function (f) { return ({ key: f.key, fieldId: f.fieldId }); }), true);
|
|
387
|
+
return { mergedFields: mergedFields, minimalFullLengthFields: minimalFullLengthFields };
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
function tryGetSchema(data) {
|
|
391
|
+
if (data === null || data === void 0 ? void 0 : data.schema) {
|
|
392
|
+
return data.schema;
|
|
393
|
+
}
|
|
394
|
+
if (Array.isArray(data)) {
|
|
395
|
+
data = { data: data };
|
|
396
|
+
}
|
|
397
|
+
if (!(data === null || data === void 0 ? void 0 : data.data) || !Array.isArray(data.data) || data.data.length === 0) {
|
|
398
|
+
return undefined;
|
|
399
|
+
}
|
|
400
|
+
var fieldMap = {};
|
|
401
|
+
data.data.forEach(function (entry) {
|
|
402
|
+
if (entry && typeof entry === "object") {
|
|
403
|
+
Array.from(Object.entries(entry)).forEach(function (_a) {
|
|
404
|
+
var k = _a[0], v = _a[1];
|
|
405
|
+
var inferredType = typeof v === "string"
|
|
406
|
+
? "string"
|
|
407
|
+
: typeof v === "boolean"
|
|
408
|
+
? "boolean"
|
|
409
|
+
: typeof v === "number"
|
|
410
|
+
? "number"
|
|
411
|
+
: "unknown";
|
|
412
|
+
if (fieldMap[k] && fieldMap[k] !== inferredType) {
|
|
413
|
+
fieldMap[k] = "unknown";
|
|
414
|
+
}
|
|
415
|
+
else {
|
|
416
|
+
fieldMap[k] = inferredType;
|
|
417
|
+
}
|
|
418
|
+
});
|
|
419
|
+
}
|
|
420
|
+
});
|
|
421
|
+
return {
|
|
422
|
+
id: "inferred",
|
|
423
|
+
fields: Object.entries(fieldMap).map(function (_a) {
|
|
424
|
+
var f = _a[0], t = _a[1];
|
|
425
|
+
return ({
|
|
426
|
+
id: f,
|
|
427
|
+
type: t,
|
|
428
|
+
readOnly: false,
|
|
429
|
+
});
|
|
430
|
+
}),
|
|
431
|
+
};
|
|
432
|
+
}
|
|
433
|
+
function normalizeData(rawData) {
|
|
434
|
+
if (!rawData || typeof rawData !== "object") {
|
|
435
|
+
return undefined;
|
|
436
|
+
}
|
|
437
|
+
var obj = Array.isArray(rawData) ? { data: rawData } : rawData;
|
|
438
|
+
if (!("data" in obj)) {
|
|
439
|
+
return undefined;
|
|
440
|
+
}
|
|
441
|
+
var objWithData = obj;
|
|
442
|
+
if (!Array.isArray(objWithData.data) || objWithData.data.length === 0) {
|
|
443
|
+
return undefined;
|
|
444
|
+
}
|
|
445
|
+
// Make TS happy.
|
|
446
|
+
var normed = __assign(__assign({}, objWithData), { data: objWithData.data });
|
|
447
|
+
var schema = tryGetSchema(rawData);
|
|
448
|
+
if (!schema) {
|
|
449
|
+
return undefined;
|
|
450
|
+
}
|
|
451
|
+
return __assign(__assign({}, normed), { schema: schema });
|
|
452
|
+
}
|
|
453
|
+
/**
|
|
454
|
+
* Render booleans, objects, arrays, etc. as JSON repr.
|
|
455
|
+
*/
|
|
456
|
+
function safeRender(x) {
|
|
457
|
+
return x === undefined || x === null
|
|
458
|
+
? ""
|
|
459
|
+
: typeof x === "string"
|
|
460
|
+
? x
|
|
461
|
+
: typeof x === "number"
|
|
462
|
+
? x.toString()
|
|
463
|
+
: JSON.stringify(x);
|
|
464
|
+
}
|
|
465
|
+
function RichTable(props) {
|
|
466
|
+
var className = props.className, _a = props.data, rawData = _a === void 0 ? {
|
|
467
|
+
data: [],
|
|
468
|
+
schema: {
|
|
469
|
+
id: "inferred",
|
|
470
|
+
fields: [
|
|
471
|
+
{
|
|
472
|
+
id: "id",
|
|
473
|
+
type: "string",
|
|
474
|
+
readOnly: false,
|
|
475
|
+
},
|
|
476
|
+
],
|
|
477
|
+
},
|
|
478
|
+
} : _a,
|
|
479
|
+
// children,
|
|
480
|
+
_b = props.pagination,
|
|
481
|
+
// children,
|
|
482
|
+
pagination = _b === void 0 ? true : _b, defaultSize = props.defaultSize, title = props.title, addHref = props.addHref, _c = props.pageSize, pageSize = _c === void 0 ? 10 : _c, _d = props.scrollX, scrollX = _d === void 0 ? true : _d, scrollHeight = props.scrollHeight, hideSearch = props.hideSearch, hideDensity = props.hideDensity, hideColumnPicker = props.hideColumnPicker, hideExports = props.hideExports, rowKey = props.rowKey;
|
|
483
|
+
var data = normalizeData(rawData);
|
|
484
|
+
var _e = useColumnDefinitions(data, props), columnDefinitions = _e.columnDefinitions, normalized = _e.normalized;
|
|
485
|
+
var actionRef = React.useRef();
|
|
486
|
+
var _f = useSortedFilteredData(data, normalized), finalData = _f.finalData, search = _f.search, setSearch = _f.setSearch, setSortState = _f.setSortState;
|
|
487
|
+
var rowSelection = useRowSelection(data, props);
|
|
488
|
+
// const { containerRef, tableHeight } = useScrollHeight(data, props);
|
|
489
|
+
var isClient = useIsClient();
|
|
490
|
+
if (!isClient) {
|
|
491
|
+
return null;
|
|
492
|
+
}
|
|
493
|
+
return (React__default.default.createElement("div", { className: className },
|
|
494
|
+
React__default.default.createElement(proComponents.ProTable, { actionRef: actionRef, columns: columnDefinitions, onChange: function (_pagination, _filters, sorter, _extra) {
|
|
495
|
+
setSortState({ sorter: sorter });
|
|
496
|
+
}, style: {
|
|
497
|
+
width: "100%",
|
|
498
|
+
height: "100%",
|
|
499
|
+
}, cardProps: {
|
|
500
|
+
ghost: true,
|
|
501
|
+
}, rowSelection: rowSelection, dataSource: finalData, rowKey: deriveRowKey(data, rowKey), defaultSize: defaultSize, editable: { type: "multiple" }, search: false, options: {
|
|
502
|
+
setting: hideColumnPicker
|
|
503
|
+
? false
|
|
504
|
+
: {
|
|
505
|
+
listsHeight: 400,
|
|
506
|
+
},
|
|
507
|
+
reload: false,
|
|
508
|
+
density: !hideDensity,
|
|
509
|
+
}, pagination: pagination
|
|
510
|
+
? {
|
|
511
|
+
pageSize: pageSize,
|
|
512
|
+
onChange: function (page) { return console.log(page); },
|
|
513
|
+
}
|
|
514
|
+
: false, dateFormatter: "string", headerTitle: title,
|
|
515
|
+
// TODO in the future, figure out how to make this responsive to the CSS height
|
|
516
|
+
scroll: { x: scrollX || undefined, y: scrollHeight }, toolbar: {
|
|
517
|
+
search: !hideSearch
|
|
518
|
+
? {
|
|
519
|
+
value: search,
|
|
520
|
+
onChange: function (e) { return setSearch(e.target.value); },
|
|
521
|
+
onSearch: function () {
|
|
522
|
+
return;
|
|
523
|
+
},
|
|
524
|
+
placeholder: "Search",
|
|
525
|
+
}
|
|
526
|
+
: undefined,
|
|
527
|
+
}, toolBarRender: function () { return [
|
|
528
|
+
addHref && (React__default.default.createElement(antd.Button, { key: "button", icon: React__default.default.createElement(icons.PlusOutlined, null), type: "primary", href: addHref }, "Add")),
|
|
529
|
+
!hideExports && React__default.default.createElement(ExportMenu, { data: data }),
|
|
530
|
+
]; } }),
|
|
531
|
+
React__default.default.createElement("style", null, "\n :where(.css-dev-only-do-not-override-1p704s4).ant-pro-table-column-setting-overlay .ant-tree-treenode:hover .ant-pro-table-column-setting-list-item-option {\n display: none;\n }\n .ant-pro-table-list-toolbar-right {\n flex-wrap: initial;\n flex-shrink: 0;\n }\n ")));
|
|
532
|
+
}
|
|
533
|
+
function deriveRowKey(data, rowKey) {
|
|
534
|
+
var _a;
|
|
535
|
+
if (rowKey) {
|
|
536
|
+
return rowKey;
|
|
537
|
+
}
|
|
538
|
+
var schema = tryGetSchema(data);
|
|
539
|
+
if (schema) {
|
|
540
|
+
return (_a = schema.fields[0]) === null || _a === void 0 ? void 0 : _a.id;
|
|
541
|
+
}
|
|
542
|
+
return undefined;
|
|
543
|
+
}
|
|
544
|
+
function useColumnDefinitions(data, props) {
|
|
545
|
+
var fields = props.fields, setControlContextData = props.setControlContextData, actions = props.actions, customActionChildren = props.customActionChildren;
|
|
546
|
+
return React__default.default.useMemo(function () {
|
|
547
|
+
var schema = tryGetSchema(data);
|
|
548
|
+
if (!data || !schema) {
|
|
549
|
+
return { normalized: [], columnDefinitions: [] };
|
|
550
|
+
}
|
|
551
|
+
var _a = deriveFieldConfigs(fields !== null && fields !== void 0 ? fields : [], schema), mergedFields = _a.mergedFields, minimalFullLengthFields = _a.minimalFullLengthFields;
|
|
552
|
+
setControlContextData === null || setControlContextData === void 0 ? void 0 : setControlContextData(__assign(__assign({}, data), { mergedFields: mergedFields, minimalFullLengthFields: minimalFullLengthFields }));
|
|
553
|
+
var normalized = mergedFields;
|
|
554
|
+
var columnDefinitions = normalized
|
|
555
|
+
.filter(function (cconfig) { return !cconfig.isHidden; })
|
|
556
|
+
.map(function (cconfig, _columnIndex, _columnsArray) {
|
|
557
|
+
var columnDefinition = {
|
|
558
|
+
dataIndex: cconfig.fieldId,
|
|
559
|
+
title: cconfig.title,
|
|
560
|
+
// dataIndex: cconfig,
|
|
561
|
+
key: cconfig.key,
|
|
562
|
+
valueType: cconfig.dataType === "auto"
|
|
563
|
+
? undefined
|
|
564
|
+
: cconfig.dataType === "string"
|
|
565
|
+
? "text"
|
|
566
|
+
: cconfig.dataType === "number"
|
|
567
|
+
? "digit"
|
|
568
|
+
: cconfig.dataType === "boolean"
|
|
569
|
+
? "switch"
|
|
570
|
+
: undefined,
|
|
571
|
+
// To come later
|
|
572
|
+
readonly: false,
|
|
573
|
+
sorter: true,
|
|
574
|
+
copyable: false,
|
|
575
|
+
ellipsis: false,
|
|
576
|
+
tip: undefined,
|
|
577
|
+
formItemProps: {
|
|
578
|
+
rules: [],
|
|
579
|
+
},
|
|
580
|
+
disable: false,
|
|
581
|
+
valueEnum: undefined,
|
|
582
|
+
search: undefined,
|
|
583
|
+
hideInSearch: false,
|
|
584
|
+
renderFormItem: function (_, _a) {
|
|
585
|
+
var defaultRender = _a.defaultRender;
|
|
586
|
+
return defaultRender(_);
|
|
587
|
+
},
|
|
588
|
+
render: function (value, record, rowIndex) {
|
|
589
|
+
return (React__default.default.createElement(host.DataProvider, { name: "currentRow", data: record },
|
|
590
|
+
React__default.default.createElement(host.DataProvider, { name: "currentRowIndex", data: rowIndex },
|
|
591
|
+
React__default.default.createElement(host.DataProvider, { name: "currentColumn", data: value }, safeRender(cconfig.expr ? cconfig.expr(record) : value)))));
|
|
592
|
+
},
|
|
593
|
+
};
|
|
594
|
+
return columnDefinition;
|
|
595
|
+
});
|
|
596
|
+
if (actions && actions.length > 0) {
|
|
597
|
+
columnDefinitions.push({
|
|
598
|
+
title: "Actions",
|
|
599
|
+
valueType: "option",
|
|
600
|
+
key: "__plasmicActions",
|
|
601
|
+
render: function (_text, record, _, action) { return __spreadArray(__spreadArray([], actions
|
|
602
|
+
.filter(function (_action) { return !_action.moreMenu; })
|
|
603
|
+
.map(function (_action, aindex) {
|
|
604
|
+
return _action.type === "edit" ? (React__default.default.createElement("a", { key: aindex, onClick: function () {
|
|
605
|
+
var _a;
|
|
606
|
+
(_a = action === null || action === void 0 ? void 0 : action.startEditable) === null || _a === void 0 ? void 0 : _a.call(action, record.id);
|
|
607
|
+
} }, "Edit")) : _action.type === "view" ? (React__default.default.createElement("a", { key: aindex, href: record.url }, "View")) : _action.type === "delete" ? (React__default.default.createElement("a", { key: aindex, onClick: function () {
|
|
608
|
+
// TODO delete
|
|
609
|
+
} }, "Delete")) : (customActionChildren);
|
|
610
|
+
}), true), [
|
|
611
|
+
React__default.default.createElement(proComponents.TableDropdown, { key: "actionGroup", onSelect: function () { return action === null || action === void 0 ? void 0 : action.reload(); }, menus: actions
|
|
612
|
+
.filter(function (_action) { return !!_action.moreMenu; })
|
|
613
|
+
.map(function (_action, aindex) {
|
|
614
|
+
var _a;
|
|
615
|
+
return ({
|
|
616
|
+
key: "" + aindex,
|
|
617
|
+
name: (_a = _action.label) !== null && _a !== void 0 ? _a : _action.type,
|
|
618
|
+
});
|
|
619
|
+
}) }),
|
|
620
|
+
], false); },
|
|
621
|
+
});
|
|
622
|
+
}
|
|
623
|
+
return { normalized: normalized, columnDefinitions: columnDefinitions };
|
|
624
|
+
}, [fields, data, setControlContextData, actions, customActionChildren]);
|
|
625
|
+
}
|
|
626
|
+
function useSortedFilteredData(data, columns) {
|
|
627
|
+
var _a = React.useState(""), search = _a[0], setSearch = _a[1];
|
|
628
|
+
var _b = React.useState(undefined), sortState = _b[0], setSortState = _b[1];
|
|
629
|
+
var finalData = React__default.default.useMemo(function () {
|
|
630
|
+
var _a;
|
|
631
|
+
var filtered = (_a = data === null || data === void 0 ? void 0 : data.data) === null || _a === void 0 ? void 0 : _a.filter(function (row) {
|
|
632
|
+
return fastStringify__default.default(Object.values(row)).toLowerCase().includes(search);
|
|
633
|
+
});
|
|
634
|
+
var sorted = (sortState === null || sortState === void 0 ? void 0 : sortState.sorter.column)
|
|
635
|
+
? // We use .sort() rather than sortBy to use localeCompare
|
|
636
|
+
(function () {
|
|
637
|
+
var _a;
|
|
638
|
+
var expr = (_a = columns.find(function (cconfig) { var _a; return cconfig.key === ((_a = sortState === null || sortState === void 0 ? void 0 : sortState.sorter.column) === null || _a === void 0 ? void 0 : _a.key); }).expr) !== null && _a !== void 0 ? _a : (function (x) { return x; });
|
|
639
|
+
return (filtered !== null && filtered !== void 0 ? filtered : []).sort(function (aa, bb) {
|
|
640
|
+
var _a, _b;
|
|
641
|
+
var a = (_a = expr(aa)) !== null && _a !== void 0 ? _a : null, b = (_b = expr(bb)) !== null && _b !== void 0 ? _b : null;
|
|
642
|
+
// Default nil to '' here because A < null < z which is weird.
|
|
643
|
+
return typeof a === "string"
|
|
644
|
+
? a.localeCompare(b !== null && b !== void 0 ? b : "")
|
|
645
|
+
: typeof b === "string"
|
|
646
|
+
? -b.localeCompare(a !== null && a !== void 0 ? a : "")
|
|
647
|
+
: a - b;
|
|
648
|
+
});
|
|
649
|
+
})()
|
|
650
|
+
: filtered;
|
|
651
|
+
var reversed = (sortState === null || sortState === void 0 ? void 0 : sortState.sorter.order) === "descend" ? sorted === null || sorted === void 0 ? void 0 : sorted.reverse() : sorted;
|
|
652
|
+
return reversed;
|
|
653
|
+
}, [data, columns, sortState, search]);
|
|
654
|
+
return {
|
|
655
|
+
finalData: finalData,
|
|
656
|
+
search: search,
|
|
657
|
+
setSearch: setSearch,
|
|
658
|
+
setSortState: setSortState,
|
|
659
|
+
};
|
|
660
|
+
}
|
|
661
|
+
function useRowSelection(data, props) {
|
|
662
|
+
var canSelectRows = props.canSelectRows, selectedRowKey = props.selectedRowKey, onRowSelectionChanged = props.onRowSelectionChanged, rowKey = props.rowKey;
|
|
663
|
+
var deriveSelectedRowKeys = function () {
|
|
664
|
+
if (!canSelectRows ||
|
|
665
|
+
canSelectRows === "none" ||
|
|
666
|
+
!deriveRowKey(data, rowKey)) {
|
|
667
|
+
return [];
|
|
668
|
+
}
|
|
669
|
+
if (typeof selectedRowKey === "string") {
|
|
670
|
+
return [selectedRowKey];
|
|
671
|
+
}
|
|
672
|
+
else if (Array.isArray(selectedRowKey)) {
|
|
673
|
+
if (canSelectRows === "single") {
|
|
674
|
+
return selectedRowKey.slice(0, 1);
|
|
675
|
+
}
|
|
676
|
+
else {
|
|
677
|
+
return selectedRowKey;
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
else {
|
|
681
|
+
return [];
|
|
682
|
+
}
|
|
683
|
+
};
|
|
684
|
+
var rowSelection = canSelectRows && canSelectRows !== "none"
|
|
685
|
+
? {
|
|
686
|
+
type: canSelectRows === "single" ? "radio" : "checkbox",
|
|
687
|
+
selectedRowKeys: deriveSelectedRowKeys(),
|
|
688
|
+
onChange: function (rowKeys, rows) {
|
|
689
|
+
onRowSelectionChanged === null || onRowSelectionChanged === void 0 ? void 0 : onRowSelectionChanged(rowKeys, rows);
|
|
690
|
+
},
|
|
691
|
+
alwaysShowAlert: true,
|
|
692
|
+
}
|
|
693
|
+
: undefined;
|
|
694
|
+
return rowSelection;
|
|
8
695
|
}
|
|
696
|
+
function ExportMenu(props) {
|
|
697
|
+
var _this = this;
|
|
698
|
+
var data = props.data;
|
|
699
|
+
return (React__default.default.createElement(antd.Dropdown, { key: "menu", menu: {
|
|
700
|
+
items: [
|
|
701
|
+
{
|
|
702
|
+
label: "Download as CSV",
|
|
703
|
+
key: "csv",
|
|
704
|
+
onClick: function () { return __awaiter(_this, void 0, void 0, function () {
|
|
705
|
+
var writer, dataStr, filename, blob, link, url;
|
|
706
|
+
var _a, _b;
|
|
707
|
+
return __generator(this, function (_c) {
|
|
708
|
+
writer = csvWriterBrowser.createObjectCsvStringifier({
|
|
709
|
+
header: (_b = (_a = tryGetSchema(data)) === null || _a === void 0 ? void 0 : _a.fields.map(function (f) { return ({
|
|
710
|
+
id: f.id,
|
|
711
|
+
title: f.id,
|
|
712
|
+
}); })) !== null && _b !== void 0 ? _b : [],
|
|
713
|
+
});
|
|
714
|
+
dataStr = writer.getHeaderString() +
|
|
715
|
+
writer.stringifyRecords(data === null || data === void 0 ? void 0 : data.data);
|
|
716
|
+
filename = "data.csv";
|
|
717
|
+
blob = new Blob([dataStr], {
|
|
718
|
+
type: "text/csv;charset=utf-8;",
|
|
719
|
+
});
|
|
720
|
+
if (navigator.msSaveBlob) {
|
|
721
|
+
// In case of IE 10+
|
|
722
|
+
navigator.msSaveBlob(blob, filename);
|
|
723
|
+
}
|
|
724
|
+
else {
|
|
725
|
+
link = document.createElement("a");
|
|
726
|
+
if (link.download !== undefined) {
|
|
727
|
+
url = URL.createObjectURL(blob);
|
|
728
|
+
link.setAttribute("href", url);
|
|
729
|
+
link.setAttribute("download", filename);
|
|
730
|
+
link.style.visibility = "hidden";
|
|
731
|
+
document.body.appendChild(link);
|
|
732
|
+
link.click();
|
|
733
|
+
document.body.removeChild(link);
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
return [2 /*return*/];
|
|
737
|
+
});
|
|
738
|
+
}); },
|
|
739
|
+
},
|
|
740
|
+
{
|
|
741
|
+
label: "Download as JSON",
|
|
742
|
+
key: "json",
|
|
743
|
+
onClick: function () {
|
|
744
|
+
var dataStr = fastStringify__default.default(data === null || data === void 0 ? void 0 : data.data);
|
|
745
|
+
var dataUri = "data:application/json;charset=utf-8, ".concat(encodeURIComponent(dataStr));
|
|
746
|
+
var exportFileDefaultName = "data.json";
|
|
747
|
+
var linkElement = document.createElement("a");
|
|
748
|
+
linkElement.setAttribute("href", dataUri);
|
|
749
|
+
linkElement.setAttribute("download", exportFileDefaultName);
|
|
750
|
+
linkElement.click();
|
|
751
|
+
},
|
|
752
|
+
},
|
|
753
|
+
],
|
|
754
|
+
} },
|
|
755
|
+
React__default.default.createElement(antd.Button, null,
|
|
756
|
+
React__default.default.createElement(icons.EllipsisOutlined, null))));
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
function ensureNumber(x) {
|
|
760
|
+
return x;
|
|
761
|
+
}
|
|
762
|
+
var tableHelpers = {
|
|
763
|
+
states: {
|
|
764
|
+
selectedRow: {
|
|
765
|
+
onChangeArgsToValue: function (rowKeys, rows) {
|
|
766
|
+
return rows[0];
|
|
767
|
+
},
|
|
768
|
+
},
|
|
769
|
+
selectedRows: {
|
|
770
|
+
onChangeArgsToValue: function (rowKeys, rows) {
|
|
771
|
+
return rows;
|
|
772
|
+
},
|
|
773
|
+
},
|
|
774
|
+
selectedRowKey: {
|
|
775
|
+
onChangeArgsToValue: function (rowKeys, rows) {
|
|
776
|
+
return rowKeys;
|
|
777
|
+
},
|
|
778
|
+
},
|
|
779
|
+
},
|
|
780
|
+
};
|
|
781
|
+
var rowDataType = function (displayName, control) {
|
|
782
|
+
return ({
|
|
783
|
+
type: "function",
|
|
784
|
+
displayName: displayName,
|
|
785
|
+
control: control,
|
|
786
|
+
argNames: ["currentItem"],
|
|
787
|
+
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]]; },
|
|
788
|
+
});
|
|
789
|
+
};
|
|
790
|
+
function getDefaultValueHint(field) {
|
|
791
|
+
return function (_props, contextData, _a) {
|
|
792
|
+
var path = _a.path;
|
|
793
|
+
return contextData === null || contextData === void 0 ? void 0 : contextData.mergedFields[ensureNumber(path.slice(-2)[0])][field];
|
|
794
|
+
};
|
|
795
|
+
}
|
|
796
|
+
var dataTableMeta = {
|
|
797
|
+
name: "hostless-rich-table",
|
|
798
|
+
displayName: "Table",
|
|
799
|
+
defaultStyles: {
|
|
800
|
+
width: "stretch",
|
|
801
|
+
},
|
|
802
|
+
props: {
|
|
803
|
+
data: {
|
|
804
|
+
type: "dataSourceOpData",
|
|
805
|
+
description: "The data to display in the table",
|
|
806
|
+
},
|
|
807
|
+
defaultSize: {
|
|
808
|
+
type: "choice",
|
|
809
|
+
options: ["large", "middle", "small"],
|
|
810
|
+
defaultValueHint: "large",
|
|
811
|
+
},
|
|
812
|
+
pageSize: {
|
|
813
|
+
type: "number",
|
|
814
|
+
defaultValueHint: 10,
|
|
815
|
+
},
|
|
816
|
+
fields: {
|
|
817
|
+
type: "array",
|
|
818
|
+
hidden: function (ps) { return !ps.data; },
|
|
819
|
+
unstable__keyFunc: function (x) { return x.key; },
|
|
820
|
+
unstable__minimalValue: function (_props, contextData) {
|
|
821
|
+
return contextData === null || contextData === void 0 ? void 0 : contextData.minimalFullLengthFields;
|
|
822
|
+
},
|
|
823
|
+
unstable__canDelete: function (_item, _props, ctx, _a) {
|
|
824
|
+
var path = _a.path;
|
|
825
|
+
return !(ctx === null || ctx === void 0 ? void 0 : ctx.mergedFields[ensureNumber(path.slice(-1)[0])].fieldId);
|
|
826
|
+
},
|
|
827
|
+
itemType: {
|
|
828
|
+
type: "object",
|
|
829
|
+
nameFunc: function (_item, _props, ctx, _a) {
|
|
830
|
+
var path = _a.path;
|
|
831
|
+
return ctx === null || ctx === void 0 ? void 0 : ctx.mergedFields[ensureNumber(path.slice(-1)[0])].title;
|
|
832
|
+
},
|
|
833
|
+
fields: {
|
|
834
|
+
key: {
|
|
835
|
+
type: "string",
|
|
836
|
+
hidden: function () { return true; },
|
|
837
|
+
},
|
|
838
|
+
fieldId: {
|
|
839
|
+
type: "choice",
|
|
840
|
+
displayName: "Field name",
|
|
841
|
+
readOnly: true,
|
|
842
|
+
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; }); },
|
|
843
|
+
hidden: function (_props, ctx, _a) {
|
|
844
|
+
var _b, _c;
|
|
845
|
+
var _controlPath = _a.path;
|
|
846
|
+
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 : {}));
|
|
847
|
+
},
|
|
848
|
+
},
|
|
849
|
+
title: {
|
|
850
|
+
type: "string",
|
|
851
|
+
displayName: "Title",
|
|
852
|
+
defaultValueHint: getDefaultValueHint("title"),
|
|
853
|
+
},
|
|
854
|
+
dataType: {
|
|
855
|
+
type: "choice",
|
|
856
|
+
displayName: "Data type",
|
|
857
|
+
options: ["auto", "number", "string", "boolean"],
|
|
858
|
+
defaultValueHint: getDefaultValueHint("dataType"),
|
|
859
|
+
},
|
|
860
|
+
expr: rowDataType("Customize data"),
|
|
861
|
+
// TODO
|
|
862
|
+
// isEditableExpr: rowDataType("Is editable", {
|
|
863
|
+
// type: "boolean",
|
|
864
|
+
// defaultValueHint: false,
|
|
865
|
+
// }),
|
|
866
|
+
// disableSorting: {
|
|
867
|
+
// type: "boolean",
|
|
868
|
+
// displayName: "Disable sorting",
|
|
869
|
+
// defaultValueHint: getDefaultValueHint("disableSorting"),
|
|
870
|
+
// },
|
|
871
|
+
// sortByExpr: rowDataType("Sort by"),
|
|
872
|
+
isHidden: {
|
|
873
|
+
type: "boolean",
|
|
874
|
+
displayName: "Is hidden",
|
|
875
|
+
defaultValueHint: getDefaultValueHint("isHidden"),
|
|
876
|
+
},
|
|
877
|
+
},
|
|
878
|
+
},
|
|
879
|
+
},
|
|
880
|
+
canSelectRows: {
|
|
881
|
+
type: "choice",
|
|
882
|
+
displayName: "Select rows?",
|
|
883
|
+
options: [
|
|
884
|
+
{ label: "No", value: "none" },
|
|
885
|
+
{ label: "Single", value: "single" },
|
|
886
|
+
{ label: "Multiple", value: "multiple" },
|
|
887
|
+
],
|
|
888
|
+
defaultValueHint: "none",
|
|
889
|
+
},
|
|
890
|
+
rowKey: {
|
|
891
|
+
type: "string",
|
|
892
|
+
displayName: "Row key",
|
|
893
|
+
helpText: "Column key to use as row key; can also be a function that takes in a row and returns a key value",
|
|
894
|
+
hidden: function (ps) { return !ps.canSelectRows || ps.canSelectRows === "none"; },
|
|
895
|
+
defaultValueHint: function (ps) { return deriveRowKey(ps.data, ps.rowKey); },
|
|
896
|
+
},
|
|
897
|
+
selectedRowKey: {
|
|
898
|
+
type: "string",
|
|
899
|
+
displayName: "Selected Row Key",
|
|
900
|
+
hidden: function (ps) { return ps.canSelectRows !== "single"; },
|
|
901
|
+
advanced: true,
|
|
902
|
+
},
|
|
903
|
+
selectedRowKeys: {
|
|
904
|
+
type: "array",
|
|
905
|
+
displayName: "Selected Row Keys",
|
|
906
|
+
hidden: function (ps) { return ps.canSelectRows !== "multiple"; },
|
|
907
|
+
advanced: true,
|
|
908
|
+
},
|
|
909
|
+
onRowSelectionChanged: {
|
|
910
|
+
type: "eventHandler",
|
|
911
|
+
displayName: "On row selection changed",
|
|
912
|
+
argTypes: [
|
|
913
|
+
{ name: "rowKeys", type: "object" },
|
|
914
|
+
{ name: "rows", type: "object" },
|
|
915
|
+
],
|
|
916
|
+
},
|
|
917
|
+
pagination: {
|
|
918
|
+
type: "boolean",
|
|
919
|
+
advanced: true,
|
|
920
|
+
defaultValueHint: true,
|
|
921
|
+
},
|
|
922
|
+
scrollX: {
|
|
923
|
+
type: "boolean",
|
|
924
|
+
advanced: true,
|
|
925
|
+
defaultValueHint: true,
|
|
926
|
+
},
|
|
927
|
+
scrollHeight: {
|
|
928
|
+
type: "number",
|
|
929
|
+
advanced: true,
|
|
930
|
+
},
|
|
931
|
+
hideSearch: {
|
|
932
|
+
type: "boolean",
|
|
933
|
+
advanced: true,
|
|
934
|
+
},
|
|
935
|
+
hideExports: {
|
|
936
|
+
type: "boolean",
|
|
937
|
+
advanced: true,
|
|
938
|
+
},
|
|
939
|
+
hideDensity: {
|
|
940
|
+
type: "boolean",
|
|
941
|
+
advanced: true,
|
|
942
|
+
},
|
|
943
|
+
hideColumnPicker: {
|
|
944
|
+
type: "boolean",
|
|
945
|
+
advanced: true,
|
|
946
|
+
},
|
|
947
|
+
},
|
|
948
|
+
states: {
|
|
949
|
+
selectedRowKey: __assign({ type: "writable", valueProp: "selectedRowKey", onChangeProp: "onRowSelectionChanged", variableType: "text" }, tableHelpers.states.selectedRowKey),
|
|
950
|
+
selectedRow: __assign({ type: "readonly", onChangeProp: "onRowSelectionChanged", variableType: "object" }, tableHelpers.states.selectedRow),
|
|
951
|
+
selectedRows: __assign({ type: "readonly", onChangeProp: "onRowSelectionChanged", variableType: "array" }, tableHelpers.states.selectedRows),
|
|
952
|
+
},
|
|
953
|
+
componentHelpers: {
|
|
954
|
+
helpers: tableHelpers,
|
|
955
|
+
importName: "tableHelpers",
|
|
956
|
+
importPath: "@plasmicpkgs/plasmic-rich-components",
|
|
957
|
+
},
|
|
958
|
+
importName: "RichTable",
|
|
959
|
+
importPath: "@plasmicpkgs/plasmic-rich-components",
|
|
960
|
+
};
|
|
961
|
+
function registerRichTable(loader) {
|
|
962
|
+
registerComponentHelper(loader, RichTable, dataTableMeta);
|
|
963
|
+
}
|
|
964
|
+
|
|
965
|
+
function registerAll(loader) {
|
|
966
|
+
registerRichLayout(loader);
|
|
967
|
+
registerRichTable(loader);
|
|
968
|
+
}
|
|
969
|
+
|
|
970
|
+
exports.RichLayout = RichLayout;
|
|
971
|
+
exports.RichTable = RichTable;
|
|
972
|
+
exports.registerAll = registerAll;
|
|
973
|
+
exports.tableHelpers = tableHelpers;
|
|
974
|
+
//# sourceMappingURL=index.js.map
|