@plasmicpkgs/plasmic-rich-components 1.0.42 → 1.0.43
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/README.md +1 -1
- package/dist/common.d.ts +2 -0
- package/dist/field-mappings.d.ts +53 -0
- package/dist/index.d.ts +2 -7
- package/dist/plasmic-rich-components.cjs.development.js +797 -112
- package/dist/plasmic-rich-components.cjs.development.js.map +1 -1
- package/dist/plasmic-rich-components.cjs.production.min.js +1 -1
- package/dist/plasmic-rich-components.cjs.production.min.js.map +1 -1
- package/dist/plasmic-rich-components.esm.js +798 -112
- package/dist/plasmic-rich-components.esm.js.map +1 -1
- package/dist/rich-layout/RichLayout.d.ts +16 -0
- package/dist/rich-layout/index.d.ts +5 -0
- package/dist/rich-table/RichTable.d.ts +35 -0
- package/dist/rich-table/index.d.ts +5 -0
- package/dist/utils.d.ts +24 -0
- package/package.json +17 -6
- package/dist/DataTable.d.ts +0 -23
|
@@ -4,10 +4,432 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
|
|
6
6
|
|
|
7
|
+
var React = require('react');
|
|
8
|
+
var React__default = _interopDefault(React);
|
|
7
9
|
var registerComponent = _interopDefault(require('@plasmicapp/host/registerComponent'));
|
|
8
|
-
|
|
10
|
+
require('@plasmicapp/host/registerGlobalContext');
|
|
11
|
+
var icons = require('@ant-design/icons');
|
|
12
|
+
var proComponents = require('@ant-design/pro-components');
|
|
9
13
|
var antd = require('antd');
|
|
10
|
-
var
|
|
14
|
+
var host = require('@plasmicapp/host');
|
|
15
|
+
var sync = require('csv-stringify/sync');
|
|
16
|
+
var fastStringify = _interopDefault(require('fast-stringify'));
|
|
17
|
+
|
|
18
|
+
function _extends() {
|
|
19
|
+
_extends = Object.assign ? Object.assign.bind() : function (target) {
|
|
20
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
21
|
+
var source = arguments[i];
|
|
22
|
+
for (var key in source) {
|
|
23
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
24
|
+
target[key] = source[key];
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return target;
|
|
29
|
+
};
|
|
30
|
+
return _extends.apply(this, arguments);
|
|
31
|
+
}
|
|
32
|
+
function _objectWithoutPropertiesLoose(source, excluded) {
|
|
33
|
+
if (source == null) return {};
|
|
34
|
+
var target = {};
|
|
35
|
+
var sourceKeys = Object.keys(source);
|
|
36
|
+
var key, i;
|
|
37
|
+
for (i = 0; i < sourceKeys.length; i++) {
|
|
38
|
+
key = sourceKeys[i];
|
|
39
|
+
if (excluded.indexOf(key) >= 0) continue;
|
|
40
|
+
target[key] = source[key];
|
|
41
|
+
}
|
|
42
|
+
return target;
|
|
43
|
+
}
|
|
44
|
+
function _unsupportedIterableToArray(o, minLen) {
|
|
45
|
+
if (!o) return;
|
|
46
|
+
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
|
47
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
48
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
49
|
+
if (n === "Map" || n === "Set") return Array.from(o);
|
|
50
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
|
51
|
+
}
|
|
52
|
+
function _arrayLikeToArray(arr, len) {
|
|
53
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
54
|
+
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
|
55
|
+
return arr2;
|
|
56
|
+
}
|
|
57
|
+
function _createForOfIteratorHelperLoose(o, allowArrayLike) {
|
|
58
|
+
var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
|
|
59
|
+
if (it) return (it = it.call(o)).next.bind(it);
|
|
60
|
+
if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
|
|
61
|
+
if (it) o = it;
|
|
62
|
+
var i = 0;
|
|
63
|
+
return function () {
|
|
64
|
+
if (i >= o.length) return {
|
|
65
|
+
done: true
|
|
66
|
+
};
|
|
67
|
+
return {
|
|
68
|
+
done: false,
|
|
69
|
+
value: o[i++]
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function useIsClient() {
|
|
77
|
+
var _useState = React.useState(false),
|
|
78
|
+
loaded = _useState[0],
|
|
79
|
+
setLoaded = _useState[1];
|
|
80
|
+
React.useEffect(function () {
|
|
81
|
+
setLoaded(true);
|
|
82
|
+
});
|
|
83
|
+
return loaded;
|
|
84
|
+
}
|
|
85
|
+
function capitalize(text) {
|
|
86
|
+
return text.slice(0, 1).toUpperCase() + text.slice(1);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function registerComponentHelper(loader, component, meta) {
|
|
90
|
+
if (loader) {
|
|
91
|
+
loader.registerComponent(component, meta);
|
|
92
|
+
} else {
|
|
93
|
+
registerComponent(component, meta);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
var _excluded = ["children", "navMenuItems", "rootUrl", "actionsChildren", "footerChildren", "avatarLabel", "avatarImage", "showAvatarMenu", "className"];
|
|
98
|
+
function RichLayout(_ref) {
|
|
99
|
+
var children = _ref.children,
|
|
100
|
+
navMenuItems = _ref.navMenuItems,
|
|
101
|
+
_ref$rootUrl = _ref.rootUrl,
|
|
102
|
+
rootUrl = _ref$rootUrl === void 0 ? "/" : _ref$rootUrl,
|
|
103
|
+
actionsChildren = _ref.actionsChildren,
|
|
104
|
+
footerChildren = _ref.footerChildren,
|
|
105
|
+
avatarLabel = _ref.avatarLabel,
|
|
106
|
+
avatarImage = _ref.avatarImage,
|
|
107
|
+
showAvatarMenu = _ref.showAvatarMenu,
|
|
108
|
+
className = _ref.className,
|
|
109
|
+
layoutProps = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
110
|
+
var _location = location,
|
|
111
|
+
pathname = _location.pathname;
|
|
112
|
+
return React__default.createElement("div", {
|
|
113
|
+
className: className
|
|
114
|
+
}, React__default.createElement(proComponents.ProLayout, Object.assign({}, layoutProps, {
|
|
115
|
+
// 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.
|
|
116
|
+
splitMenus: layoutProps.layout === "mix",
|
|
117
|
+
route: {
|
|
118
|
+
path: rootUrl,
|
|
119
|
+
routes: navMenuItems
|
|
120
|
+
},
|
|
121
|
+
location: {
|
|
122
|
+
pathname: pathname
|
|
123
|
+
},
|
|
124
|
+
menu: {
|
|
125
|
+
// collapsedShowGroupTitle: true,
|
|
126
|
+
defaultOpenAll: true
|
|
127
|
+
},
|
|
128
|
+
avatarProps: showAvatarMenu && false ? {
|
|
129
|
+
src: avatarImage,
|
|
130
|
+
size: "small",
|
|
131
|
+
title: avatarLabel,
|
|
132
|
+
render: function render(_props, dom) {
|
|
133
|
+
return React__default.createElement(antd.Dropdown, {
|
|
134
|
+
menu: {
|
|
135
|
+
items: [{
|
|
136
|
+
key: "logout",
|
|
137
|
+
icon: React__default.createElement(icons.LogoutOutlined, null),
|
|
138
|
+
label: "Sign out"
|
|
139
|
+
}]
|
|
140
|
+
}
|
|
141
|
+
}, dom);
|
|
142
|
+
}
|
|
143
|
+
} : undefined,
|
|
144
|
+
actionsRender: function actionsRender(_props) {
|
|
145
|
+
return [actionsChildren];
|
|
146
|
+
},
|
|
147
|
+
menuFooterRender: function menuFooterRender(props) {
|
|
148
|
+
if (props != null && props.collapsed) return undefined;
|
|
149
|
+
return footerChildren;
|
|
150
|
+
},
|
|
151
|
+
onMenuHeaderClick: function onMenuHeaderClick(e) {
|
|
152
|
+
return console.log(e);
|
|
153
|
+
},
|
|
154
|
+
menuItemRender: function menuItemRender(item, dom) {
|
|
155
|
+
return React__default.createElement("a", {
|
|
156
|
+
href: item.path
|
|
157
|
+
}, dom);
|
|
158
|
+
},
|
|
159
|
+
headerTitleRender: function headerTitleRender(logo, title, _) {
|
|
160
|
+
return React__default.createElement("a", {
|
|
161
|
+
href: rootUrl
|
|
162
|
+
}, logo, title);
|
|
163
|
+
}
|
|
164
|
+
}), children));
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function generateNavMenuType(remainingDepth, displayName, defaultValue) {
|
|
168
|
+
return {
|
|
169
|
+
displayName: displayName ? displayName : "Nested items",
|
|
170
|
+
type: "array",
|
|
171
|
+
defaultValue: defaultValue,
|
|
172
|
+
itemType: {
|
|
173
|
+
type: "object",
|
|
174
|
+
nameFunc: function nameFunc(item) {
|
|
175
|
+
return item.name || (!displayName ? "Unnamed nested item" : "Unnamed item");
|
|
176
|
+
},
|
|
177
|
+
fields: _extends({
|
|
178
|
+
path: "string",
|
|
179
|
+
name: "string"
|
|
180
|
+
}, remainingDepth === 0 ? {} : {
|
|
181
|
+
routes: generateNavMenuType(remainingDepth - 1)
|
|
182
|
+
})
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
var richLayoutMeta = {
|
|
187
|
+
name: "hostless-rich-layout",
|
|
188
|
+
displayName: "Rich Layout",
|
|
189
|
+
props: {
|
|
190
|
+
children: "slot",
|
|
191
|
+
actionsChildren: "slot",
|
|
192
|
+
title: {
|
|
193
|
+
displayName: "Title",
|
|
194
|
+
type: "string",
|
|
195
|
+
defaultValue: "App title"
|
|
196
|
+
},
|
|
197
|
+
logo: {
|
|
198
|
+
displayName: "Logo",
|
|
199
|
+
type: "imageUrl",
|
|
200
|
+
defaultValue: "https://www.plasmic.app/favicon.ico"
|
|
201
|
+
},
|
|
202
|
+
navMenuItems: /*#__PURE__*/generateNavMenuType(2, "Nav menu items", [{
|
|
203
|
+
path: "/welcome",
|
|
204
|
+
name: "Welcome"
|
|
205
|
+
}, {
|
|
206
|
+
path: "/admin",
|
|
207
|
+
name: "Admin",
|
|
208
|
+
// icon: <CrownFilled />,
|
|
209
|
+
// access: "canAdmin",
|
|
210
|
+
// component: "./Admin",
|
|
211
|
+
routes: [{
|
|
212
|
+
path: "/admin/sub-page1",
|
|
213
|
+
name: "Sub page 1"
|
|
214
|
+
}, {
|
|
215
|
+
path: "/admin/sub-page2",
|
|
216
|
+
name: "Sub page 2"
|
|
217
|
+
}, {
|
|
218
|
+
path: "/admin/sub-page3",
|
|
219
|
+
name: "Sub page 3"
|
|
220
|
+
}]
|
|
221
|
+
}, {
|
|
222
|
+
name: "List",
|
|
223
|
+
// icon: <TabletFilled />,
|
|
224
|
+
path: "/list",
|
|
225
|
+
// component: "./ListTableList",
|
|
226
|
+
routes: [{
|
|
227
|
+
path: "/list/sub-page",
|
|
228
|
+
name: "Page group",
|
|
229
|
+
// icon: <CrownFilled />,
|
|
230
|
+
routes: [{
|
|
231
|
+
path: "sub-sub-page1",
|
|
232
|
+
name: "Sub sub page 1"
|
|
233
|
+
}, {
|
|
234
|
+
path: "sub-sub-page2",
|
|
235
|
+
name: "Sub sub page 2"
|
|
236
|
+
}, {
|
|
237
|
+
path: "sub-sub-page3",
|
|
238
|
+
name: "Sub sub page 3"
|
|
239
|
+
}]
|
|
240
|
+
}, {
|
|
241
|
+
path: "/list/sub-page2",
|
|
242
|
+
name: "Sub page 2"
|
|
243
|
+
}, {
|
|
244
|
+
path: "/list/sub-page3",
|
|
245
|
+
name: "Sub page 3"
|
|
246
|
+
}]
|
|
247
|
+
}, {
|
|
248
|
+
path: "https://ant.design",
|
|
249
|
+
name: "Extern link"
|
|
250
|
+
}]),
|
|
251
|
+
layout: {
|
|
252
|
+
displayName: "Layout",
|
|
253
|
+
type: "choice",
|
|
254
|
+
options: /*#__PURE__*/["side", "top", "mix"].map(function (value) {
|
|
255
|
+
return {
|
|
256
|
+
value: value,
|
|
257
|
+
label: capitalize(value)
|
|
258
|
+
};
|
|
259
|
+
}),
|
|
260
|
+
defaultValue: "mix"
|
|
261
|
+
},
|
|
262
|
+
// Advanced, show later
|
|
263
|
+
/*
|
|
264
|
+
siderMenuType: {
|
|
265
|
+
displayName: "Sidebar mode",
|
|
266
|
+
type: "choice",
|
|
267
|
+
options: ["sub", "group"].map((value) => ({
|
|
268
|
+
value,
|
|
269
|
+
label: capitalize(value),
|
|
270
|
+
})),
|
|
271
|
+
defaultValue: "sub",
|
|
272
|
+
},
|
|
273
|
+
contentWidth: {
|
|
274
|
+
displayName: "Content width",
|
|
275
|
+
type: "choice",
|
|
276
|
+
options: ["Fluid", "Fixed"],
|
|
277
|
+
defaultValueHint: "Fluid",
|
|
278
|
+
},
|
|
279
|
+
navTheme: {
|
|
280
|
+
displayName: "Theme",
|
|
281
|
+
type: "choice",
|
|
282
|
+
options: [
|
|
283
|
+
{ value: "realDark", label: "Dark" },
|
|
284
|
+
{ value: "light", label: "Light" },
|
|
285
|
+
],
|
|
286
|
+
},
|
|
287
|
+
colorPrimary: {
|
|
288
|
+
displayName: "Primary color",
|
|
289
|
+
type: "color",
|
|
290
|
+
},
|
|
291
|
+
fixedHeader: {
|
|
292
|
+
displayName: "Sticky header",
|
|
293
|
+
type: "boolean",
|
|
294
|
+
defaultValue: true,
|
|
295
|
+
},
|
|
296
|
+
fixSiderbar: {
|
|
297
|
+
displayName: "Sticky sidebar",
|
|
298
|
+
type: "boolean",
|
|
299
|
+
defaultValue: true,
|
|
300
|
+
},
|
|
301
|
+
showAvatarMenu: {
|
|
302
|
+
displayName: "Show avatar",
|
|
303
|
+
type: "boolean",
|
|
304
|
+
defaultValue: true,
|
|
305
|
+
},
|
|
306
|
+
avatarLabel: {
|
|
307
|
+
displayName: "Avatar label",
|
|
308
|
+
type: "string",
|
|
309
|
+
defaultValue: "User Name",
|
|
310
|
+
},
|
|
311
|
+
avatarImage: {
|
|
312
|
+
displayName: "Avatar image",
|
|
313
|
+
type: "imageUrl",
|
|
314
|
+
defaultValue:
|
|
315
|
+
"https://gw.alipayobjects.com/zos/antfincdn/efFD%24IOql2/weixintupian_20170331104822.jpg",
|
|
316
|
+
},
|
|
317
|
+
*/
|
|
318
|
+
menu: {
|
|
319
|
+
displayName: "Menu",
|
|
320
|
+
type: "object",
|
|
321
|
+
fields: {
|
|
322
|
+
defaultOpenAll: {
|
|
323
|
+
displayName: "Default open all",
|
|
324
|
+
type: "boolean"
|
|
325
|
+
},
|
|
326
|
+
hideMenuWhenCollapsed: {
|
|
327
|
+
// displayName: "",
|
|
328
|
+
type: "boolean"
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
},
|
|
333
|
+
defaultStyles: {
|
|
334
|
+
width: "stretch",
|
|
335
|
+
height: "stretch"
|
|
336
|
+
},
|
|
337
|
+
importName: "RichLayout",
|
|
338
|
+
importPath: "@plasmicpkgs/plasmic-rich-components/dist/rich-layout/RichLayout"
|
|
339
|
+
};
|
|
340
|
+
function registerRichLayout(loader) {
|
|
341
|
+
registerComponentHelper(loader, RichLayout, richLayoutMeta);
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
var tuple = function tuple() {
|
|
345
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
346
|
+
args[_key] = arguments[_key];
|
|
347
|
+
}
|
|
348
|
+
return args;
|
|
349
|
+
};
|
|
350
|
+
function mkIdMap(xs) {
|
|
351
|
+
return new Map(xs.map(function (x) {
|
|
352
|
+
return tuple(x.id, x);
|
|
353
|
+
}));
|
|
354
|
+
}
|
|
355
|
+
var mkShortId = function mkShortId() {
|
|
356
|
+
return "" + Math.random();
|
|
357
|
+
};
|
|
358
|
+
var withoutNils = function withoutNils(xs) {
|
|
359
|
+
return xs.filter(function (x) {
|
|
360
|
+
return x != null;
|
|
361
|
+
});
|
|
362
|
+
};
|
|
363
|
+
var defaultColumnConfig = function defaultColumnConfig() {
|
|
364
|
+
return {
|
|
365
|
+
key: mkShortId(),
|
|
366
|
+
isEditableExpr: function isEditableExpr() {
|
|
367
|
+
return false;
|
|
368
|
+
},
|
|
369
|
+
disableSorting: false,
|
|
370
|
+
sortByExpr: undefined,
|
|
371
|
+
isHidden: false,
|
|
372
|
+
formatting: {
|
|
373
|
+
styles: {},
|
|
374
|
+
align: "left",
|
|
375
|
+
freeze: "off"
|
|
376
|
+
},
|
|
377
|
+
dataType: "auto"
|
|
378
|
+
};
|
|
379
|
+
};
|
|
380
|
+
function deriveFieldConfigs(specifiedFieldsPartial, schema) {
|
|
381
|
+
var _schema$fields;
|
|
382
|
+
// Ugly: when adding a new item to an array from Plasmic Studio UI, no way to specify default values for the new item,
|
|
383
|
+
// so we have to do it here. The only one we need is the random key.
|
|
384
|
+
for (var _iterator = _createForOfIteratorHelperLoose(specifiedFieldsPartial), _step; !(_step = _iterator()).done;) {
|
|
385
|
+
var field = _step.value;
|
|
386
|
+
if (!field.key) {
|
|
387
|
+
field.key = mkShortId();
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
var schemaFields = (_schema$fields = schema == null ? void 0 : schema.fields) != null ? _schema$fields : [];
|
|
391
|
+
var fieldById = mkIdMap(schemaFields);
|
|
392
|
+
var specifiedFieldIds = new Set(withoutNils(specifiedFieldsPartial.map(function (f) {
|
|
393
|
+
return f.fieldId;
|
|
394
|
+
})));
|
|
395
|
+
function defaultColumnConfigForField(field) {
|
|
396
|
+
return _extends({}, defaultColumnConfig(), {
|
|
397
|
+
fieldId: field.id,
|
|
398
|
+
title: field.label || field.id,
|
|
399
|
+
expr: function expr(currentItem) {
|
|
400
|
+
return currentItem[field.id];
|
|
401
|
+
}
|
|
402
|
+
});
|
|
403
|
+
}
|
|
404
|
+
var keptSpecifiedFields = specifiedFieldsPartial.flatMap(function (f) {
|
|
405
|
+
var fieldId = f.fieldId;
|
|
406
|
+
if (!fieldId) {
|
|
407
|
+
return [_extends({}, defaultColumnConfig(), f)];
|
|
408
|
+
}
|
|
409
|
+
var field = fieldById.get(fieldId);
|
|
410
|
+
// Drop configs with fieldIds no longer in the data.
|
|
411
|
+
if (!field) {
|
|
412
|
+
return [];
|
|
413
|
+
}
|
|
414
|
+
return [_extends({}, defaultColumnConfigForField(field), f)];
|
|
415
|
+
});
|
|
416
|
+
var newVirtualFields = schemaFields.filter(function (f) {
|
|
417
|
+
return !specifiedFieldIds.has(f.id);
|
|
418
|
+
}).map(function (f) {
|
|
419
|
+
return _extends({}, defaultColumnConfigForField(f));
|
|
420
|
+
});
|
|
421
|
+
var mergedFields = [].concat(keptSpecifiedFields, newVirtualFields);
|
|
422
|
+
var minimalFullLengthFields = [].concat(specifiedFieldsPartial, newVirtualFields.map(function (f) {
|
|
423
|
+
return {
|
|
424
|
+
key: f.key,
|
|
425
|
+
fieldId: f.fieldId
|
|
426
|
+
};
|
|
427
|
+
}));
|
|
428
|
+
return {
|
|
429
|
+
mergedFields: mergedFields,
|
|
430
|
+
minimalFullLengthFields: minimalFullLengthFields
|
|
431
|
+
};
|
|
432
|
+
}
|
|
11
433
|
|
|
12
434
|
function tryGetSchema(data) {
|
|
13
435
|
var _data, _data2;
|
|
@@ -50,141 +472,404 @@ function tryGetSchema(data) {
|
|
|
50
472
|
})
|
|
51
473
|
};
|
|
52
474
|
}
|
|
53
|
-
function
|
|
475
|
+
function normalizeData(rawData) {
|
|
476
|
+
if (!rawData || typeof rawData !== "object") {
|
|
477
|
+
return undefined;
|
|
478
|
+
}
|
|
479
|
+
var obj = Array.isArray(rawData) ? {
|
|
480
|
+
data: rawData
|
|
481
|
+
} : rawData;
|
|
482
|
+
if (!("data" in obj)) {
|
|
483
|
+
return undefined;
|
|
484
|
+
}
|
|
485
|
+
var objWithData = obj;
|
|
486
|
+
if (!Array.isArray(objWithData.data) || objWithData.data.length === 0) {
|
|
487
|
+
return undefined;
|
|
488
|
+
}
|
|
489
|
+
// Make TS happy.
|
|
490
|
+
var normed = _extends({}, objWithData, {
|
|
491
|
+
data: objWithData.data
|
|
492
|
+
});
|
|
493
|
+
var schema = tryGetSchema(rawData);
|
|
494
|
+
if (!schema) {
|
|
495
|
+
return undefined;
|
|
496
|
+
}
|
|
497
|
+
return _extends({}, normed, {
|
|
498
|
+
schema: schema
|
|
499
|
+
});
|
|
500
|
+
}
|
|
501
|
+
function RichTable(props) {
|
|
502
|
+
var _data$data;
|
|
54
503
|
var className = props.className,
|
|
55
|
-
data = props.data,
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
504
|
+
_props$data = props.data,
|
|
505
|
+
rawData = _props$data === void 0 ? {
|
|
506
|
+
data: [],
|
|
507
|
+
schema: {
|
|
508
|
+
id: "inferred",
|
|
509
|
+
fields: [{
|
|
510
|
+
id: "id",
|
|
511
|
+
type: "string",
|
|
512
|
+
readOnly: false
|
|
513
|
+
}]
|
|
514
|
+
}
|
|
515
|
+
} : _props$data,
|
|
516
|
+
defaultSize = props.defaultSize,
|
|
517
|
+
fields = props.fields,
|
|
518
|
+
setControlContextData = props.setControlContextData,
|
|
519
|
+
title = props.title,
|
|
520
|
+
addHref = props.addHref,
|
|
521
|
+
actions = props.actions,
|
|
522
|
+
customActionChildren = props.customActionChildren,
|
|
523
|
+
_props$showSearch = props.showSearch,
|
|
524
|
+
showSearch = _props$showSearch === void 0 ? true : _props$showSearch,
|
|
525
|
+
_props$pageSize = props.pageSize,
|
|
526
|
+
pageSize = _props$pageSize === void 0 ? 20 : _props$pageSize;
|
|
527
|
+
var data = normalizeData(rawData);
|
|
528
|
+
var _useState = React.useState(""),
|
|
529
|
+
search = _useState[0],
|
|
530
|
+
setSearch = _useState[1];
|
|
531
|
+
var _React$useMemo = React__default.useMemo(function () {
|
|
532
|
+
var schema = tryGetSchema(data);
|
|
533
|
+
if (!data || !schema) {
|
|
534
|
+
return {
|
|
535
|
+
normalized: [],
|
|
536
|
+
columnDefinitions: []
|
|
537
|
+
};
|
|
538
|
+
}
|
|
539
|
+
var _deriveFieldConfigs = deriveFieldConfigs(fields != null ? fields : [], schema),
|
|
540
|
+
mergedFields = _deriveFieldConfigs.mergedFields,
|
|
541
|
+
minimalFullLengthFields = _deriveFieldConfigs.minimalFullLengthFields;
|
|
542
|
+
setControlContextData == null ? void 0 : setControlContextData(_extends({}, data, {
|
|
543
|
+
mergedFields: mergedFields,
|
|
544
|
+
minimalFullLengthFields: minimalFullLengthFields
|
|
545
|
+
}));
|
|
546
|
+
var normalized = mergedFields;
|
|
547
|
+
var columnDefinitions = normalized.filter(function (cconfig) {
|
|
548
|
+
return !cconfig.isHidden;
|
|
549
|
+
}).map(function (cconfig, _columnIndex, _columnsArray) {
|
|
550
|
+
var columnDefinition = {
|
|
551
|
+
dataIndex: cconfig.fieldId,
|
|
552
|
+
title: cconfig.title,
|
|
553
|
+
// dataIndex: cconfig,
|
|
554
|
+
key: cconfig.key,
|
|
555
|
+
valueType: cconfig.dataType === "auto" ? undefined : cconfig.dataType === "string" ? "text" : cconfig.dataType === "number" ? "digit" : cconfig.dataType === "boolean" ? "switch" : undefined,
|
|
556
|
+
// To come later
|
|
557
|
+
readonly: false,
|
|
558
|
+
sorter: true,
|
|
559
|
+
copyable: false,
|
|
560
|
+
ellipsis: false,
|
|
561
|
+
tip: undefined,
|
|
562
|
+
formItemProps: {
|
|
563
|
+
rules: []
|
|
564
|
+
},
|
|
565
|
+
disable: false,
|
|
566
|
+
valueEnum: undefined,
|
|
567
|
+
search: undefined,
|
|
568
|
+
hideInSearch: false,
|
|
569
|
+
renderFormItem: function renderFormItem(_, _ref3) {
|
|
570
|
+
var defaultRender = _ref3.defaultRender;
|
|
571
|
+
return defaultRender(_);
|
|
572
|
+
},
|
|
573
|
+
render: function render(value, record, rowIndex) {
|
|
574
|
+
return React__default.createElement(host.DataProvider, {
|
|
575
|
+
name: "currentRow",
|
|
576
|
+
data: record
|
|
577
|
+
}, React__default.createElement(host.DataProvider, {
|
|
578
|
+
name: "currentRowIndex",
|
|
579
|
+
data: rowIndex
|
|
580
|
+
}, React__default.createElement(host.DataProvider, {
|
|
581
|
+
name: "currentColumn",
|
|
582
|
+
data: value
|
|
583
|
+
}, cconfig.expr ? cconfig.expr(record) : record)));
|
|
584
|
+
}
|
|
585
|
+
};
|
|
586
|
+
return columnDefinition;
|
|
587
|
+
});
|
|
588
|
+
if (actions && actions.length > 0) {
|
|
589
|
+
columnDefinitions.push({
|
|
590
|
+
title: "Actions",
|
|
591
|
+
valueType: "option",
|
|
592
|
+
key: "__plasmicActions",
|
|
593
|
+
render: function render(_text, record, _, action) {
|
|
594
|
+
return [].concat(actions.filter(function (_action) {
|
|
595
|
+
return !_action.moreMenu;
|
|
596
|
+
}).map(function (_action, aindex) {
|
|
597
|
+
return _action.type === "edit" ? React__default.createElement("a", {
|
|
598
|
+
key: aindex,
|
|
599
|
+
onClick: function onClick() {
|
|
600
|
+
action == null ? void 0 : action.startEditable == null ? void 0 : action.startEditable(record.id);
|
|
601
|
+
}
|
|
602
|
+
}, "Edit") : _action.type === "view" ? React__default.createElement("a", {
|
|
603
|
+
key: aindex,
|
|
604
|
+
href: record.url
|
|
605
|
+
}, "View") : _action.type === "delete" ? React__default.createElement("a", {
|
|
606
|
+
key: aindex,
|
|
607
|
+
onClick: function onClick() {
|
|
608
|
+
// TODO delete
|
|
609
|
+
}
|
|
610
|
+
}, "Delete") : customActionChildren;
|
|
611
|
+
}), [React__default.createElement(proComponents.TableDropdown, {
|
|
612
|
+
key: "actionGroup",
|
|
613
|
+
onSelect: function onSelect() {
|
|
614
|
+
return action == null ? void 0 : action.reload();
|
|
615
|
+
},
|
|
616
|
+
menus: actions.filter(function (_action) {
|
|
617
|
+
return !!_action.moreMenu;
|
|
618
|
+
}).map(function (_action, aindex) {
|
|
619
|
+
var _action$label;
|
|
620
|
+
return {
|
|
621
|
+
key: "" + aindex,
|
|
622
|
+
name: (_action$label = _action.label) != null ? _action$label : _action.type
|
|
623
|
+
};
|
|
624
|
+
})
|
|
625
|
+
})]);
|
|
626
|
+
}
|
|
627
|
+
});
|
|
628
|
+
}
|
|
629
|
+
return {
|
|
630
|
+
normalized: normalized,
|
|
631
|
+
columnDefinitions: columnDefinitions
|
|
94
632
|
};
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
633
|
+
}, [fields, data, setControlContextData, Math.random()]),
|
|
634
|
+
columnDefinitions = _React$useMemo.columnDefinitions;
|
|
635
|
+
var actionRef = React.useRef();
|
|
636
|
+
var isClient = useIsClient();
|
|
637
|
+
if (!isClient) {
|
|
638
|
+
return null;
|
|
639
|
+
}
|
|
640
|
+
// return <NestedTest {...{ fields }} />;
|
|
641
|
+
return React__default.createElement(React__default.Fragment, null, React__default.createElement(proComponents.ProTable, {
|
|
642
|
+
actionRef: actionRef,
|
|
99
643
|
className: className,
|
|
100
644
|
columns: columnDefinitions,
|
|
101
|
-
dataSource: data == null ? void 0 : data.data
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
645
|
+
dataSource: data == null ? void 0 : (_data$data = data.data) == null ? void 0 : _data$data.filter(function (row) {
|
|
646
|
+
return fastStringify(Object.values(row)).toLowerCase().includes(search);
|
|
647
|
+
}),
|
|
648
|
+
rowKey: "id",
|
|
649
|
+
defaultSize: defaultSize,
|
|
650
|
+
// request={() =>
|
|
651
|
+
// Promise.resolve({
|
|
652
|
+
// data: data?.data?.filter((row) =>
|
|
653
|
+
// fastStringify(row).toLowerCase().includes(search)
|
|
654
|
+
// ),
|
|
655
|
+
// success: true,
|
|
656
|
+
// })
|
|
657
|
+
// }
|
|
658
|
+
editable: {
|
|
659
|
+
type: "multiple"
|
|
109
660
|
},
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
661
|
+
search: false,
|
|
662
|
+
options: {
|
|
663
|
+
setting: {
|
|
664
|
+
listsHeight: 400
|
|
665
|
+
}
|
|
666
|
+
},
|
|
667
|
+
pagination: {
|
|
668
|
+
pageSize: pageSize,
|
|
669
|
+
onChange: function onChange(page) {
|
|
670
|
+
return console.log(page);
|
|
671
|
+
}
|
|
672
|
+
},
|
|
673
|
+
dateFormatter: "string",
|
|
674
|
+
headerTitle: title,
|
|
675
|
+
toolbar: {
|
|
676
|
+
search: showSearch ? {
|
|
677
|
+
value: search,
|
|
678
|
+
onChange: function onChange(e) {
|
|
679
|
+
return setSearch(e.target.value);
|
|
680
|
+
},
|
|
681
|
+
onSearch: function onSearch() {},
|
|
682
|
+
placeholder: "Search"
|
|
683
|
+
} : undefined
|
|
684
|
+
},
|
|
685
|
+
toolBarRender: function toolBarRender() {
|
|
686
|
+
return [addHref && React__default.createElement(antd.Button, {
|
|
687
|
+
key: "button",
|
|
688
|
+
icon: React__default.createElement(icons.PlusOutlined, null),
|
|
689
|
+
type: "primary",
|
|
690
|
+
href: addHref
|
|
691
|
+
}, "Add"), React__default.createElement(antd.Dropdown, {
|
|
692
|
+
key: "menu",
|
|
693
|
+
menu: {
|
|
694
|
+
items: [{
|
|
695
|
+
label: "Download as CSV",
|
|
696
|
+
key: "csv",
|
|
697
|
+
onClick: function onClick() {
|
|
698
|
+
var _tryGetSchema$fields$, _tryGetSchema;
|
|
699
|
+
var dataStr = sync.stringify(data == null ? void 0 : data.data, {
|
|
700
|
+
columns: (_tryGetSchema$fields$ = (_tryGetSchema = tryGetSchema(data)) == null ? void 0 : _tryGetSchema.fields.map(function (f) {
|
|
701
|
+
return f.id;
|
|
702
|
+
})) != null ? _tryGetSchema$fields$ : [],
|
|
703
|
+
header: true
|
|
704
|
+
});
|
|
705
|
+
var filename = "data.csv";
|
|
706
|
+
// Adapted from https://stackoverflow.com/a/68771795
|
|
707
|
+
var blob = new Blob([dataStr], {
|
|
708
|
+
type: "text/csv;charset=utf-8;"
|
|
709
|
+
});
|
|
710
|
+
if (navigator.msSaveBlob) {
|
|
711
|
+
// In case of IE 10+
|
|
712
|
+
navigator.msSaveBlob(blob, filename);
|
|
713
|
+
} else {
|
|
714
|
+
var link = document.createElement("a");
|
|
715
|
+
if (link.download !== undefined) {
|
|
716
|
+
// Browsers that support HTML5 download attribute
|
|
717
|
+
var url = URL.createObjectURL(blob);
|
|
718
|
+
link.setAttribute("href", url);
|
|
719
|
+
link.setAttribute("download", filename);
|
|
720
|
+
link.style.visibility = "hidden";
|
|
721
|
+
document.body.appendChild(link);
|
|
722
|
+
link.click();
|
|
723
|
+
document.body.removeChild(link);
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
}, {
|
|
728
|
+
label: "Download as JSON",
|
|
729
|
+
key: "json",
|
|
730
|
+
onClick: function onClick() {
|
|
731
|
+
var dataStr = fastStringify(data == null ? void 0 : data.data);
|
|
732
|
+
var dataUri = "data:application/json;charset=utf-8, " + encodeURIComponent(dataStr);
|
|
733
|
+
var exportFileDefaultName = "data.json";
|
|
734
|
+
var linkElement = document.createElement("a");
|
|
735
|
+
linkElement.setAttribute("href", dataUri);
|
|
736
|
+
linkElement.setAttribute("download", exportFileDefaultName);
|
|
737
|
+
linkElement.click();
|
|
738
|
+
}
|
|
739
|
+
}]
|
|
740
|
+
}
|
|
741
|
+
}, React__default.createElement(antd.Button, null, React__default.createElement(icons.EllipsisOutlined, null)))];
|
|
742
|
+
}
|
|
743
|
+
}), React__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 "));
|
|
121
744
|
}
|
|
122
745
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
746
|
+
function ensureNumber(x) {
|
|
747
|
+
return x;
|
|
748
|
+
}
|
|
749
|
+
var rowDataType = function rowDataType(displayName, control) {
|
|
750
|
+
return {
|
|
751
|
+
type: "function",
|
|
752
|
+
displayName: displayName,
|
|
753
|
+
control: control,
|
|
754
|
+
argNames: ["currentItem"],
|
|
755
|
+
argValues: function argValues(_props, ctx) {
|
|
756
|
+
var _ctx$data;
|
|
757
|
+
return [ctx == null ? void 0 : (_ctx$data = ctx.data) == null ? void 0 : _ctx$data[0]];
|
|
758
|
+
}
|
|
759
|
+
};
|
|
130
760
|
};
|
|
761
|
+
function getDefaultValueHint(field) {
|
|
762
|
+
return function (_props, contextData, _ref) {
|
|
763
|
+
var path = _ref.path;
|
|
764
|
+
return contextData == null ? void 0 : contextData.mergedFields[ensureNumber(path.slice(-2)[0])][field];
|
|
765
|
+
};
|
|
766
|
+
}
|
|
131
767
|
var dataTableMeta = {
|
|
132
|
-
name: "hostless-
|
|
133
|
-
displayName: "
|
|
768
|
+
name: "hostless-rich-table",
|
|
769
|
+
displayName: "Rich Table",
|
|
134
770
|
props: {
|
|
135
771
|
data: {
|
|
136
772
|
type: "dataSourceOpData",
|
|
137
773
|
description: "The data to display in the table"
|
|
138
774
|
},
|
|
139
|
-
|
|
140
|
-
type: "slot",
|
|
141
|
-
defaultValue: {
|
|
142
|
-
type: "component",
|
|
143
|
-
name: "hostless-plasmic-rich-components-value"
|
|
144
|
-
}
|
|
145
|
-
},
|
|
146
|
-
size: {
|
|
775
|
+
defaultSize: {
|
|
147
776
|
type: "choice",
|
|
148
777
|
options: ["large", "middle", "small"],
|
|
149
778
|
defaultValueHint: "large"
|
|
150
779
|
},
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
780
|
+
// TODO
|
|
781
|
+
// pagination: {
|
|
782
|
+
// type: "boolean",
|
|
783
|
+
// defaultValueHint: true,
|
|
784
|
+
// },
|
|
785
|
+
pageSize: {
|
|
786
|
+
type: "number",
|
|
787
|
+
defaultValueHint: 20
|
|
154
788
|
},
|
|
155
|
-
|
|
156
|
-
type: "
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
return [];
|
|
160
|
-
}
|
|
161
|
-
return schema.fields.map(function (f) {
|
|
162
|
-
return {
|
|
163
|
-
label: f.label || f.id,
|
|
164
|
-
value: f.id
|
|
165
|
-
};
|
|
166
|
-
});
|
|
789
|
+
fields: {
|
|
790
|
+
type: "array",
|
|
791
|
+
unstable__keyFunc: function unstable__keyFunc(x) {
|
|
792
|
+
return x.key;
|
|
167
793
|
},
|
|
168
|
-
|
|
794
|
+
unstable__minimalValue: function unstable__minimalValue(_props, contextData) {
|
|
795
|
+
return contextData == null ? void 0 : contextData.minimalFullLengthFields;
|
|
796
|
+
},
|
|
797
|
+
unstable__canDelete: function unstable__canDelete(_item, _props, ctx, _ref2) {
|
|
798
|
+
var path = _ref2.path;
|
|
799
|
+
return !(ctx != null && ctx.mergedFields[ensureNumber(path.slice(-1)[0])].fieldId);
|
|
800
|
+
},
|
|
801
|
+
itemType: {
|
|
802
|
+
type: "object",
|
|
803
|
+
nameFunc: function nameFunc(_item, _props, ctx, _ref3) {
|
|
804
|
+
var path = _ref3.path;
|
|
805
|
+
return ctx == null ? void 0 : ctx.mergedFields[ensureNumber(path.slice(-1)[0])].title;
|
|
806
|
+
},
|
|
807
|
+
fields: {
|
|
808
|
+
key: {
|
|
809
|
+
type: "string",
|
|
810
|
+
hidden: function hidden() {
|
|
811
|
+
return true;
|
|
812
|
+
}
|
|
813
|
+
},
|
|
814
|
+
fieldId: {
|
|
815
|
+
type: "choice",
|
|
816
|
+
displayName: "Field name",
|
|
817
|
+
readOnly: true,
|
|
818
|
+
options: function options(_props, ctx) {
|
|
819
|
+
var _ctx$schema$fields, _ctx$schema;
|
|
820
|
+
return ((_ctx$schema$fields = ctx == null ? void 0 : (_ctx$schema = ctx.schema) == null ? void 0 : _ctx$schema.fields) != null ? _ctx$schema$fields : []).map(function (f) {
|
|
821
|
+
return f.id;
|
|
822
|
+
});
|
|
823
|
+
},
|
|
824
|
+
hidden: function hidden(_props, ctx, _ref4) {
|
|
825
|
+
var _ctx$schema$fields2, _ctx$schema2;
|
|
826
|
+
var _controlPath = _ref4.path;
|
|
827
|
+
return !(_controlPath.slice(-1)[0] in ((_ctx$schema$fields2 = ctx == null ? void 0 : (_ctx$schema2 = ctx.schema) == null ? void 0 : _ctx$schema2.fields) != null ? _ctx$schema$fields2 : {}));
|
|
828
|
+
}
|
|
829
|
+
},
|
|
830
|
+
title: {
|
|
831
|
+
type: "string",
|
|
832
|
+
displayName: "Title",
|
|
833
|
+
defaultValueHint: /*#__PURE__*/getDefaultValueHint("title")
|
|
834
|
+
},
|
|
835
|
+
dataType: {
|
|
836
|
+
type: "choice",
|
|
837
|
+
displayName: "Data type",
|
|
838
|
+
options: ["auto", "number", "string", "boolean"],
|
|
839
|
+
defaultValueHint: /*#__PURE__*/getDefaultValueHint("dataType")
|
|
840
|
+
},
|
|
841
|
+
expr: /*#__PURE__*/rowDataType("Customize data"),
|
|
842
|
+
// TODO
|
|
843
|
+
// isEditableExpr: rowDataType("Is editable", {
|
|
844
|
+
// type: "boolean",
|
|
845
|
+
// defaultValueHint: false,
|
|
846
|
+
// }),
|
|
847
|
+
// disableSorting: {
|
|
848
|
+
// type: "boolean",
|
|
849
|
+
// displayName: "Disable sorting",
|
|
850
|
+
// defaultValueHint: getDefaultValueHint("disableSorting"),
|
|
851
|
+
// },
|
|
852
|
+
// sortByExpr: rowDataType("Sort by"),
|
|
853
|
+
isHidden: {
|
|
854
|
+
type: "boolean",
|
|
855
|
+
displayName: "Is hidden",
|
|
856
|
+
defaultValueHint: /*#__PURE__*/getDefaultValueHint("isHidden")
|
|
857
|
+
}
|
|
858
|
+
}
|
|
859
|
+
}
|
|
169
860
|
}
|
|
170
861
|
},
|
|
171
|
-
importName: "
|
|
172
|
-
importPath: "
|
|
862
|
+
importName: "RichTable",
|
|
863
|
+
importPath: "@plasmicpkgs/plasmic-rich-components/dist/rich-table/RichTable"
|
|
173
864
|
};
|
|
865
|
+
function registerRichTable(loader) {
|
|
866
|
+
registerComponentHelper(loader, RichTable, dataTableMeta);
|
|
867
|
+
}
|
|
868
|
+
|
|
174
869
|
function registerAll(loader) {
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
loader.registerComponent(Component, defaultMeta);
|
|
178
|
-
} else {
|
|
179
|
-
registerComponent(Component, defaultMeta);
|
|
180
|
-
}
|
|
181
|
-
};
|
|
182
|
-
_registerComponent(DataTable, dataTableMeta);
|
|
183
|
-
_registerComponent(TableValue, dataTableValueMeta);
|
|
870
|
+
registerRichLayout(loader);
|
|
871
|
+
registerRichTable(loader);
|
|
184
872
|
}
|
|
185
873
|
|
|
186
|
-
exports.DataTable = DataTable;
|
|
187
|
-
exports.TableValue = TableValue;
|
|
188
|
-
exports.default = DataTable;
|
|
189
874
|
exports.registerAll = registerAll;
|
|
190
875
|
//# sourceMappingURL=plasmic-rich-components.cjs.development.js.map
|