@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.
@@ -1,1614 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
6
-
7
- var React = require('react');
8
- var React__default = _interopDefault(React);
9
- var registerComponent = _interopDefault(require('@plasmicapp/host/registerComponent'));
10
- require('@plasmicapp/host/registerGlobalContext');
11
- var icons = require('@ant-design/icons');
12
- var proComponents = require('@ant-design/pro-components');
13
- var antd = require('antd');
14
- var host = require('@plasmicapp/host');
15
- var csvWriterBrowser = require('csv-writer-browser');
16
- var fastStringify = _interopDefault(require('fast-stringify'));
17
-
18
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
19
- try {
20
- var info = gen[key](arg);
21
- var value = info.value;
22
- } catch (error) {
23
- reject(error);
24
- return;
25
- }
26
- if (info.done) {
27
- resolve(value);
28
- } else {
29
- Promise.resolve(value).then(_next, _throw);
30
- }
31
- }
32
- function _asyncToGenerator(fn) {
33
- return function () {
34
- var self = this,
35
- args = arguments;
36
- return new Promise(function (resolve, reject) {
37
- var gen = fn.apply(self, args);
38
- function _next(value) {
39
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
40
- }
41
- function _throw(err) {
42
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
43
- }
44
- _next(undefined);
45
- });
46
- };
47
- }
48
- function _extends() {
49
- _extends = Object.assign ? Object.assign.bind() : function (target) {
50
- for (var i = 1; i < arguments.length; i++) {
51
- var source = arguments[i];
52
- for (var key in source) {
53
- if (Object.prototype.hasOwnProperty.call(source, key)) {
54
- target[key] = source[key];
55
- }
56
- }
57
- }
58
- return target;
59
- };
60
- return _extends.apply(this, arguments);
61
- }
62
- function _objectWithoutPropertiesLoose(source, excluded) {
63
- if (source == null) return {};
64
- var target = {};
65
- var sourceKeys = Object.keys(source);
66
- var key, i;
67
- for (i = 0; i < sourceKeys.length; i++) {
68
- key = sourceKeys[i];
69
- if (excluded.indexOf(key) >= 0) continue;
70
- target[key] = source[key];
71
- }
72
- return target;
73
- }
74
-
75
- function useIsClient() {
76
- var _useState = React.useState(false),
77
- loaded = _useState[0],
78
- setLoaded = _useState[1];
79
- React.useEffect(function () {
80
- setLoaded(true);
81
- });
82
- return loaded;
83
- }
84
- function capitalize(text) {
85
- return text.slice(0, 1).toUpperCase() + text.slice(1);
86
- }
87
-
88
- function registerComponentHelper(loader, component, meta) {
89
- if (loader) {
90
- loader.registerComponent(component, meta);
91
- } else {
92
- registerComponent(component, meta);
93
- }
94
- }
95
-
96
- var _excluded = ["children", "navMenuItems", "rootUrl", "actionsChildren", "footerChildren", "avatarLabel", "avatarImage", "showAvatarMenu", "className"];
97
- function RichLayout(_ref) {
98
- var _layoutProps$layout, _layoutProps$fixedHea, _layoutProps$fixSider;
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 isClient = useIsClient();
111
- var _useState = React.useState(undefined),
112
- pathname = _useState[0],
113
- setPathname = _useState[1];
114
- React.useEffect(function () {
115
- if (typeof location !== "undefined") {
116
- setPathname(location.pathname);
117
- }
118
- }, []);
119
- if (!isClient) {
120
- return null;
121
- }
122
- return React__default.createElement("div", {
123
- className: className
124
- }, React__default.createElement("style", null, ".ant-pro-layout-bg-list {\n display: none;\n }"), React__default.createElement(proComponents.ProLayout, Object.assign({}, layoutProps, {
125
- // Tweak defaults. ProLayout is janky and has terrible docs!
126
- layout: (_layoutProps$layout = layoutProps.layout) != null ? _layoutProps$layout : "top",
127
- fixedHeader: (_layoutProps$fixedHea = layoutProps.fixedHeader) != null ? _layoutProps$fixedHea : false,
128
- fixSiderbar:
129
- // Doesn't stretch full height if you set this to false and you're in mix mode.
130
- layoutProps.layout === "mix" ? undefined : (_layoutProps$fixSider = layoutProps.fixSiderbar) != null ? _layoutProps$fixSider : false,
131
- // 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.
132
- splitMenus: layoutProps.layout === "mix",
133
- route: {
134
- path: rootUrl,
135
- routes: navMenuItems
136
- },
137
- location: {
138
- pathname: pathname
139
- },
140
- menu: {
141
- // collapsedShowGroupTitle: true,
142
- defaultOpenAll: true
143
- },
144
- avatarProps: showAvatarMenu && false ? {
145
- src: avatarImage,
146
- size: "small",
147
- title: avatarLabel,
148
- render: function render(_props, dom) {
149
- return React__default.createElement(antd.Dropdown, {
150
- menu: {
151
- items: [{
152
- key: "logout",
153
- icon: React__default.createElement(icons.LogoutOutlined, null),
154
- label: "Sign out"
155
- }]
156
- }
157
- }, dom);
158
- }
159
- } : undefined,
160
- actionsRender: function actionsRender(_props) {
161
- return [actionsChildren];
162
- },
163
- menuFooterRender: function menuFooterRender(props) {
164
- if (props != null && props.collapsed) return undefined;
165
- return footerChildren;
166
- },
167
- onMenuHeaderClick: function onMenuHeaderClick(e) {
168
- return console.log(e);
169
- },
170
- menuItemRender: function menuItemRender(item, dom) {
171
- return React__default.createElement("a", {
172
- href: item.path
173
- }, dom);
174
- },
175
- headerTitleRender: function headerTitleRender(logo, title, _) {
176
- return React__default.createElement("a", {
177
- href: rootUrl
178
- }, logo, title);
179
- }
180
- }), children));
181
- }
182
-
183
- function generateNavMenuType(remainingDepth, displayName, defaultValue) {
184
- return {
185
- displayName: displayName ? displayName : "Nested items",
186
- type: "array",
187
- defaultValue: defaultValue,
188
- itemType: {
189
- type: "object",
190
- nameFunc: function nameFunc(item) {
191
- return item.name || (!displayName ? "Unnamed nested item" : "Unnamed item");
192
- },
193
- fields: _extends({
194
- path: "string",
195
- name: "string"
196
- }, remainingDepth === 0 ? {} : {
197
- routes: generateNavMenuType(remainingDepth - 1)
198
- })
199
- }
200
- };
201
- }
202
- var richLayoutMeta = {
203
- name: "hostless-rich-layout",
204
- displayName: "Rich Page Layout",
205
- props: {
206
- children: "slot",
207
- actionsChildren: {
208
- type: "slot",
209
- hidePlaceholder: true
210
- },
211
- title: {
212
- displayName: "Title",
213
- type: "string",
214
- defaultValue: "App title"
215
- },
216
- logo: {
217
- displayName: "Logo",
218
- type: "imageUrl",
219
- defaultValue: "https://www.plasmic.app/favicon.ico"
220
- },
221
- navMenuItems: /*#__PURE__*/generateNavMenuType(2, "Nav menu items", [{
222
- path: "/",
223
- name: "Link 1"
224
- }, {
225
- path: "/",
226
- name: "Link 2"
227
- }]),
228
- layout: {
229
- displayName: "Layout",
230
- type: "choice",
231
- options: /*#__PURE__*/["side", "top", "mix"].map(function (value) {
232
- return {
233
- value: value,
234
- label: capitalize(value)
235
- };
236
- }),
237
- defaultValueHint: "top"
238
- },
239
- // Advanced, show later
240
- /*
241
- siderMenuType: {
242
- displayName: "Sidebar mode",
243
- type: "choice",
244
- options: ["sub", "group"].map((value) => ({
245
- value,
246
- label: capitalize(value),
247
- })),
248
- defaultValue: "sub",
249
- },
250
- contentWidth: {
251
- displayName: "Content width",
252
- type: "choice",
253
- options: ["Fluid", "Fixed"],
254
- defaultValueHint: "Fluid",
255
- },
256
- navTheme: {
257
- displayName: "Theme",
258
- type: "choice",
259
- options: [
260
- { value: "realDark", label: "Dark" },
261
- { value: "light", label: "Light" },
262
- ],
263
- },
264
- colorPrimary: {
265
- displayName: "Primary color",
266
- type: "color",
267
- },
268
- */
269
- fixedHeader: {
270
- displayName: "Sticky header",
271
- type: "boolean",
272
- hidden: function hidden(ps) {
273
- var _ps$layout;
274
- return ((_ps$layout = ps.layout) != null ? _ps$layout : "top") !== "top";
275
- },
276
- defaultValueHint: false
277
- },
278
- fixSiderbar: {
279
- displayName: "Sticky sidebar",
280
- type: "boolean",
281
- hidden: function hidden(ps) {
282
- var _ps$layout2;
283
- return ((_ps$layout2 = ps.layout) != null ? _ps$layout2 : "top") !== "side";
284
- },
285
- defaultValueHint: false
286
- },
287
- /*
288
- showAvatarMenu: {
289
- displayName: "Show avatar",
290
- type: "boolean",
291
- defaultValue: true,
292
- },
293
- avatarLabel: {
294
- displayName: "Avatar label",
295
- type: "string",
296
- defaultValue: "User Name",
297
- },
298
- avatarImage: {
299
- displayName: "Avatar image",
300
- type: "imageUrl",
301
- defaultValue:
302
- "https://gw.alipayobjects.com/zos/antfincdn/efFD%24IOql2/weixintupian_20170331104822.jpg",
303
- },
304
- */
305
- menu: {
306
- displayName: "Menu",
307
- type: "object",
308
- fields: {
309
- defaultOpenAll: {
310
- displayName: "Default open all",
311
- type: "boolean"
312
- },
313
- hideMenuWhenCollapsed: {
314
- // displayName: "",
315
- type: "boolean"
316
- }
317
- }
318
- }
319
- },
320
- defaultStyles: {
321
- width: "stretch",
322
- height: "stretch"
323
- },
324
- importName: "RichLayout",
325
- importPath: "@plasmicpkgs/plasmic-rich-components"
326
- };
327
- function registerRichLayout(loader) {
328
- registerComponentHelper(loader, RichLayout, richLayoutMeta);
329
- }
330
-
331
- function createCommonjsModule(fn, module) {
332
- return module = { exports: {} }, fn(module, module.exports), module.exports;
333
- }
334
-
335
- var runtime_1 = /*#__PURE__*/createCommonjsModule(function (module) {
336
- /**
337
- * Copyright (c) 2014-present, Facebook, Inc.
338
- *
339
- * This source code is licensed under the MIT license found in the
340
- * LICENSE file in the root directory of this source tree.
341
- */
342
-
343
- var runtime = function (exports) {
344
-
345
- var Op = Object.prototype;
346
- var hasOwn = Op.hasOwnProperty;
347
- var undefined$1; // More compressible than void 0.
348
- var $Symbol = typeof Symbol === "function" ? Symbol : {};
349
- var iteratorSymbol = $Symbol.iterator || "@@iterator";
350
- var asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator";
351
- var toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
352
- function define(obj, key, value) {
353
- Object.defineProperty(obj, key, {
354
- value: value,
355
- enumerable: true,
356
- configurable: true,
357
- writable: true
358
- });
359
- return obj[key];
360
- }
361
- try {
362
- // IE 8 has a broken Object.defineProperty that only works on DOM objects.
363
- define({}, "");
364
- } catch (err) {
365
- define = function define(obj, key, value) {
366
- return obj[key] = value;
367
- };
368
- }
369
- function wrap(innerFn, outerFn, self, tryLocsList) {
370
- // If outerFn provided and outerFn.prototype is a Generator, then outerFn.prototype instanceof Generator.
371
- var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator;
372
- var generator = Object.create(protoGenerator.prototype);
373
- var context = new Context(tryLocsList || []);
374
-
375
- // The ._invoke method unifies the implementations of the .next,
376
- // .throw, and .return methods.
377
- generator._invoke = makeInvokeMethod(innerFn, self, context);
378
- return generator;
379
- }
380
- exports.wrap = wrap;
381
-
382
- // Try/catch helper to minimize deoptimizations. Returns a completion
383
- // record like context.tryEntries[i].completion. This interface could
384
- // have been (and was previously) designed to take a closure to be
385
- // invoked without arguments, but in all the cases we care about we
386
- // already have an existing method we want to call, so there's no need
387
- // to create a new function object. We can even get away with assuming
388
- // the method takes exactly one argument, since that happens to be true
389
- // in every case, so we don't have to touch the arguments object. The
390
- // only additional allocation required is the completion record, which
391
- // has a stable shape and so hopefully should be cheap to allocate.
392
- function tryCatch(fn, obj, arg) {
393
- try {
394
- return {
395
- type: "normal",
396
- arg: fn.call(obj, arg)
397
- };
398
- } catch (err) {
399
- return {
400
- type: "throw",
401
- arg: err
402
- };
403
- }
404
- }
405
- var GenStateSuspendedStart = "suspendedStart";
406
- var GenStateSuspendedYield = "suspendedYield";
407
- var GenStateExecuting = "executing";
408
- var GenStateCompleted = "completed";
409
-
410
- // Returning this object from the innerFn has the same effect as
411
- // breaking out of the dispatch switch statement.
412
- var ContinueSentinel = {};
413
-
414
- // Dummy constructor functions that we use as the .constructor and
415
- // .constructor.prototype properties for functions that return Generator
416
- // objects. For full spec compliance, you may wish to configure your
417
- // minifier not to mangle the names of these two functions.
418
- function Generator() {}
419
- function GeneratorFunction() {}
420
- function GeneratorFunctionPrototype() {}
421
-
422
- // This is a polyfill for %IteratorPrototype% for environments that
423
- // don't natively support it.
424
- var IteratorPrototype = {};
425
- define(IteratorPrototype, iteratorSymbol, function () {
426
- return this;
427
- });
428
- var getProto = Object.getPrototypeOf;
429
- var NativeIteratorPrototype = getProto && getProto(getProto(values([])));
430
- if (NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol)) {
431
- // This environment has a native %IteratorPrototype%; use it instead
432
- // of the polyfill.
433
- IteratorPrototype = NativeIteratorPrototype;
434
- }
435
- var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype);
436
- GeneratorFunction.prototype = GeneratorFunctionPrototype;
437
- define(Gp, "constructor", GeneratorFunctionPrototype);
438
- define(GeneratorFunctionPrototype, "constructor", GeneratorFunction);
439
- GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction");
440
-
441
- // Helper for defining the .next, .throw, and .return methods of the
442
- // Iterator interface in terms of a single ._invoke method.
443
- function defineIteratorMethods(prototype) {
444
- ["next", "throw", "return"].forEach(function (method) {
445
- define(prototype, method, function (arg) {
446
- return this._invoke(method, arg);
447
- });
448
- });
449
- }
450
- exports.isGeneratorFunction = function (genFun) {
451
- var ctor = typeof genFun === "function" && genFun.constructor;
452
- return ctor ? ctor === GeneratorFunction ||
453
- // For the native GeneratorFunction constructor, the best we can
454
- // do is to check its .name property.
455
- (ctor.displayName || ctor.name) === "GeneratorFunction" : false;
456
- };
457
- exports.mark = function (genFun) {
458
- if (Object.setPrototypeOf) {
459
- Object.setPrototypeOf(genFun, GeneratorFunctionPrototype);
460
- } else {
461
- genFun.__proto__ = GeneratorFunctionPrototype;
462
- define(genFun, toStringTagSymbol, "GeneratorFunction");
463
- }
464
- genFun.prototype = Object.create(Gp);
465
- return genFun;
466
- };
467
-
468
- // Within the body of any async function, `await x` is transformed to
469
- // `yield regeneratorRuntime.awrap(x)`, so that the runtime can test
470
- // `hasOwn.call(value, "__await")` to determine if the yielded value is
471
- // meant to be awaited.
472
- exports.awrap = function (arg) {
473
- return {
474
- __await: arg
475
- };
476
- };
477
- function AsyncIterator(generator, PromiseImpl) {
478
- function invoke(method, arg, resolve, reject) {
479
- var record = tryCatch(generator[method], generator, arg);
480
- if (record.type === "throw") {
481
- reject(record.arg);
482
- } else {
483
- var result = record.arg;
484
- var value = result.value;
485
- if (value && typeof value === "object" && hasOwn.call(value, "__await")) {
486
- return PromiseImpl.resolve(value.__await).then(function (value) {
487
- invoke("next", value, resolve, reject);
488
- }, function (err) {
489
- invoke("throw", err, resolve, reject);
490
- });
491
- }
492
- return PromiseImpl.resolve(value).then(function (unwrapped) {
493
- // When a yielded Promise is resolved, its final value becomes
494
- // the .value of the Promise<{value,done}> result for the
495
- // current iteration.
496
- result.value = unwrapped;
497
- resolve(result);
498
- }, function (error) {
499
- // If a rejected Promise was yielded, throw the rejection back
500
- // into the async generator function so it can be handled there.
501
- return invoke("throw", error, resolve, reject);
502
- });
503
- }
504
- }
505
- var previousPromise;
506
- function enqueue(method, arg) {
507
- function callInvokeWithMethodAndArg() {
508
- return new PromiseImpl(function (resolve, reject) {
509
- invoke(method, arg, resolve, reject);
510
- });
511
- }
512
- return previousPromise =
513
- // If enqueue has been called before, then we want to wait until
514
- // all previous Promises have been resolved before calling invoke,
515
- // so that results are always delivered in the correct order. If
516
- // enqueue has not been called before, then it is important to
517
- // call invoke immediately, without waiting on a callback to fire,
518
- // so that the async generator function has the opportunity to do
519
- // any necessary setup in a predictable way. This predictability
520
- // is why the Promise constructor synchronously invokes its
521
- // executor callback, and why async functions synchronously
522
- // execute code before the first await. Since we implement simple
523
- // async functions in terms of async generators, it is especially
524
- // important to get this right, even though it requires care.
525
- previousPromise ? previousPromise.then(callInvokeWithMethodAndArg,
526
- // Avoid propagating failures to Promises returned by later
527
- // invocations of the iterator.
528
- callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
529
- }
530
-
531
- // Define the unified helper method that is used to implement .next,
532
- // .throw, and .return (see defineIteratorMethods).
533
- this._invoke = enqueue;
534
- }
535
- defineIteratorMethods(AsyncIterator.prototype);
536
- define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
537
- return this;
538
- });
539
- exports.AsyncIterator = AsyncIterator;
540
-
541
- // Note that simple async functions are implemented on top of
542
- // AsyncIterator objects; they just return a Promise for the value of
543
- // the final result produced by the iterator.
544
- exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) {
545
- if (PromiseImpl === void 0) PromiseImpl = Promise;
546
- var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl);
547
- return exports.isGeneratorFunction(outerFn) ? iter // If outerFn is a generator, return the full iterator.
548
- : iter.next().then(function (result) {
549
- return result.done ? result.value : iter.next();
550
- });
551
- };
552
- function makeInvokeMethod(innerFn, self, context) {
553
- var state = GenStateSuspendedStart;
554
- return function invoke(method, arg) {
555
- if (state === GenStateExecuting) {
556
- throw new Error("Generator is already running");
557
- }
558
- if (state === GenStateCompleted) {
559
- if (method === "throw") {
560
- throw arg;
561
- }
562
-
563
- // Be forgiving, per 25.3.3.3.3 of the spec:
564
- // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-generatorresume
565
- return doneResult();
566
- }
567
- context.method = method;
568
- context.arg = arg;
569
- while (true) {
570
- var delegate = context.delegate;
571
- if (delegate) {
572
- var delegateResult = maybeInvokeDelegate(delegate, context);
573
- if (delegateResult) {
574
- if (delegateResult === ContinueSentinel) continue;
575
- return delegateResult;
576
- }
577
- }
578
- if (context.method === "next") {
579
- // Setting context._sent for legacy support of Babel's
580
- // function.sent implementation.
581
- context.sent = context._sent = context.arg;
582
- } else if (context.method === "throw") {
583
- if (state === GenStateSuspendedStart) {
584
- state = GenStateCompleted;
585
- throw context.arg;
586
- }
587
- context.dispatchException(context.arg);
588
- } else if (context.method === "return") {
589
- context.abrupt("return", context.arg);
590
- }
591
- state = GenStateExecuting;
592
- var record = tryCatch(innerFn, self, context);
593
- if (record.type === "normal") {
594
- // If an exception is thrown from innerFn, we leave state ===
595
- // GenStateExecuting and loop back for another invocation.
596
- state = context.done ? GenStateCompleted : GenStateSuspendedYield;
597
- if (record.arg === ContinueSentinel) {
598
- continue;
599
- }
600
- return {
601
- value: record.arg,
602
- done: context.done
603
- };
604
- } else if (record.type === "throw") {
605
- state = GenStateCompleted;
606
- // Dispatch the exception by looping back around to the
607
- // context.dispatchException(context.arg) call above.
608
- context.method = "throw";
609
- context.arg = record.arg;
610
- }
611
- }
612
- };
613
- }
614
-
615
- // Call delegate.iterator[context.method](context.arg) and handle the
616
- // result, either by returning a { value, done } result from the
617
- // delegate iterator, or by modifying context.method and context.arg,
618
- // setting context.delegate to null, and returning the ContinueSentinel.
619
- function maybeInvokeDelegate(delegate, context) {
620
- var method = delegate.iterator[context.method];
621
- if (method === undefined$1) {
622
- // A .throw or .return when the delegate iterator has no .throw
623
- // method always terminates the yield* loop.
624
- context.delegate = null;
625
- if (context.method === "throw") {
626
- // Note: ["return"] must be used for ES3 parsing compatibility.
627
- if (delegate.iterator["return"]) {
628
- // If the delegate iterator has a return method, give it a
629
- // chance to clean up.
630
- context.method = "return";
631
- context.arg = undefined$1;
632
- maybeInvokeDelegate(delegate, context);
633
- if (context.method === "throw") {
634
- // If maybeInvokeDelegate(context) changed context.method from
635
- // "return" to "throw", let that override the TypeError below.
636
- return ContinueSentinel;
637
- }
638
- }
639
- context.method = "throw";
640
- context.arg = new TypeError("The iterator does not provide a 'throw' method");
641
- }
642
- return ContinueSentinel;
643
- }
644
- var record = tryCatch(method, delegate.iterator, context.arg);
645
- if (record.type === "throw") {
646
- context.method = "throw";
647
- context.arg = record.arg;
648
- context.delegate = null;
649
- return ContinueSentinel;
650
- }
651
- var info = record.arg;
652
- if (!info) {
653
- context.method = "throw";
654
- context.arg = new TypeError("iterator result is not an object");
655
- context.delegate = null;
656
- return ContinueSentinel;
657
- }
658
- if (info.done) {
659
- // Assign the result of the finished delegate to the temporary
660
- // variable specified by delegate.resultName (see delegateYield).
661
- context[delegate.resultName] = info.value;
662
-
663
- // Resume execution at the desired location (see delegateYield).
664
- context.next = delegate.nextLoc;
665
-
666
- // If context.method was "throw" but the delegate handled the
667
- // exception, let the outer generator proceed normally. If
668
- // context.method was "next", forget context.arg since it has been
669
- // "consumed" by the delegate iterator. If context.method was
670
- // "return", allow the original .return call to continue in the
671
- // outer generator.
672
- if (context.method !== "return") {
673
- context.method = "next";
674
- context.arg = undefined$1;
675
- }
676
- } else {
677
- // Re-yield the result returned by the delegate method.
678
- return info;
679
- }
680
-
681
- // The delegate iterator is finished, so forget it and continue with
682
- // the outer generator.
683
- context.delegate = null;
684
- return ContinueSentinel;
685
- }
686
-
687
- // Define Generator.prototype.{next,throw,return} in terms of the
688
- // unified ._invoke helper method.
689
- defineIteratorMethods(Gp);
690
- define(Gp, toStringTagSymbol, "Generator");
691
-
692
- // A Generator should always return itself as the iterator object when the
693
- // @@iterator function is called on it. Some browsers' implementations of the
694
- // iterator prototype chain incorrectly implement this, causing the Generator
695
- // object to not be returned from this call. This ensures that doesn't happen.
696
- // See https://github.com/facebook/regenerator/issues/274 for more details.
697
- define(Gp, iteratorSymbol, function () {
698
- return this;
699
- });
700
- define(Gp, "toString", function () {
701
- return "[object Generator]";
702
- });
703
- function pushTryEntry(locs) {
704
- var entry = {
705
- tryLoc: locs[0]
706
- };
707
- if (1 in locs) {
708
- entry.catchLoc = locs[1];
709
- }
710
- if (2 in locs) {
711
- entry.finallyLoc = locs[2];
712
- entry.afterLoc = locs[3];
713
- }
714
- this.tryEntries.push(entry);
715
- }
716
- function resetTryEntry(entry) {
717
- var record = entry.completion || {};
718
- record.type = "normal";
719
- delete record.arg;
720
- entry.completion = record;
721
- }
722
- function Context(tryLocsList) {
723
- // The root entry object (effectively a try statement without a catch
724
- // or a finally block) gives us a place to store values thrown from
725
- // locations where there is no enclosing try statement.
726
- this.tryEntries = [{
727
- tryLoc: "root"
728
- }];
729
- tryLocsList.forEach(pushTryEntry, this);
730
- this.reset(true);
731
- }
732
- exports.keys = function (object) {
733
- var keys = [];
734
- for (var key in object) {
735
- keys.push(key);
736
- }
737
- keys.reverse();
738
-
739
- // Rather than returning an object with a next method, we keep
740
- // things simple and return the next function itself.
741
- return function next() {
742
- while (keys.length) {
743
- var key = keys.pop();
744
- if (key in object) {
745
- next.value = key;
746
- next.done = false;
747
- return next;
748
- }
749
- }
750
-
751
- // To avoid creating an additional object, we just hang the .value
752
- // and .done properties off the next function object itself. This
753
- // also ensures that the minifier will not anonymize the function.
754
- next.done = true;
755
- return next;
756
- };
757
- };
758
- function values(iterable) {
759
- if (iterable) {
760
- var iteratorMethod = iterable[iteratorSymbol];
761
- if (iteratorMethod) {
762
- return iteratorMethod.call(iterable);
763
- }
764
- if (typeof iterable.next === "function") {
765
- return iterable;
766
- }
767
- if (!isNaN(iterable.length)) {
768
- var i = -1,
769
- next = function next() {
770
- while (++i < iterable.length) {
771
- if (hasOwn.call(iterable, i)) {
772
- next.value = iterable[i];
773
- next.done = false;
774
- return next;
775
- }
776
- }
777
- next.value = undefined$1;
778
- next.done = true;
779
- return next;
780
- };
781
- return next.next = next;
782
- }
783
- }
784
-
785
- // Return an iterator with no values.
786
- return {
787
- next: doneResult
788
- };
789
- }
790
- exports.values = values;
791
- function doneResult() {
792
- return {
793
- value: undefined$1,
794
- done: true
795
- };
796
- }
797
- Context.prototype = {
798
- constructor: Context,
799
- reset: function reset(skipTempReset) {
800
- this.prev = 0;
801
- this.next = 0;
802
- // Resetting context._sent for legacy support of Babel's
803
- // function.sent implementation.
804
- this.sent = this._sent = undefined$1;
805
- this.done = false;
806
- this.delegate = null;
807
- this.method = "next";
808
- this.arg = undefined$1;
809
- this.tryEntries.forEach(resetTryEntry);
810
- if (!skipTempReset) {
811
- for (var name in this) {
812
- // Not sure about the optimal order of these conditions:
813
- if (name.charAt(0) === "t" && hasOwn.call(this, name) && !isNaN(+name.slice(1))) {
814
- this[name] = undefined$1;
815
- }
816
- }
817
- }
818
- },
819
- stop: function stop() {
820
- this.done = true;
821
- var rootEntry = this.tryEntries[0];
822
- var rootRecord = rootEntry.completion;
823
- if (rootRecord.type === "throw") {
824
- throw rootRecord.arg;
825
- }
826
- return this.rval;
827
- },
828
- dispatchException: function dispatchException(exception) {
829
- if (this.done) {
830
- throw exception;
831
- }
832
- var context = this;
833
- function handle(loc, caught) {
834
- record.type = "throw";
835
- record.arg = exception;
836
- context.next = loc;
837
- if (caught) {
838
- // If the dispatched exception was caught by a catch block,
839
- // then let that catch block handle the exception normally.
840
- context.method = "next";
841
- context.arg = undefined$1;
842
- }
843
- return !!caught;
844
- }
845
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
846
- var entry = this.tryEntries[i];
847
- var record = entry.completion;
848
- if (entry.tryLoc === "root") {
849
- // Exception thrown outside of any try block that could handle
850
- // it, so set the completion value of the entire function to
851
- // throw the exception.
852
- return handle("end");
853
- }
854
- if (entry.tryLoc <= this.prev) {
855
- var hasCatch = hasOwn.call(entry, "catchLoc");
856
- var hasFinally = hasOwn.call(entry, "finallyLoc");
857
- if (hasCatch && hasFinally) {
858
- if (this.prev < entry.catchLoc) {
859
- return handle(entry.catchLoc, true);
860
- } else if (this.prev < entry.finallyLoc) {
861
- return handle(entry.finallyLoc);
862
- }
863
- } else if (hasCatch) {
864
- if (this.prev < entry.catchLoc) {
865
- return handle(entry.catchLoc, true);
866
- }
867
- } else if (hasFinally) {
868
- if (this.prev < entry.finallyLoc) {
869
- return handle(entry.finallyLoc);
870
- }
871
- } else {
872
- throw new Error("try statement without catch or finally");
873
- }
874
- }
875
- }
876
- },
877
- abrupt: function abrupt(type, arg) {
878
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
879
- var entry = this.tryEntries[i];
880
- if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) {
881
- var finallyEntry = entry;
882
- break;
883
- }
884
- }
885
- if (finallyEntry && (type === "break" || type === "continue") && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc) {
886
- // Ignore the finally entry if control is not jumping to a
887
- // location outside the try/catch block.
888
- finallyEntry = null;
889
- }
890
- var record = finallyEntry ? finallyEntry.completion : {};
891
- record.type = type;
892
- record.arg = arg;
893
- if (finallyEntry) {
894
- this.method = "next";
895
- this.next = finallyEntry.finallyLoc;
896
- return ContinueSentinel;
897
- }
898
- return this.complete(record);
899
- },
900
- complete: function complete(record, afterLoc) {
901
- if (record.type === "throw") {
902
- throw record.arg;
903
- }
904
- if (record.type === "break" || record.type === "continue") {
905
- this.next = record.arg;
906
- } else if (record.type === "return") {
907
- this.rval = this.arg = record.arg;
908
- this.method = "return";
909
- this.next = "end";
910
- } else if (record.type === "normal" && afterLoc) {
911
- this.next = afterLoc;
912
- }
913
- return ContinueSentinel;
914
- },
915
- finish: function finish(finallyLoc) {
916
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
917
- var entry = this.tryEntries[i];
918
- if (entry.finallyLoc === finallyLoc) {
919
- this.complete(entry.completion, entry.afterLoc);
920
- resetTryEntry(entry);
921
- return ContinueSentinel;
922
- }
923
- }
924
- },
925
- "catch": function _catch(tryLoc) {
926
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
927
- var entry = this.tryEntries[i];
928
- if (entry.tryLoc === tryLoc) {
929
- var record = entry.completion;
930
- if (record.type === "throw") {
931
- var thrown = record.arg;
932
- resetTryEntry(entry);
933
- }
934
- return thrown;
935
- }
936
- }
937
-
938
- // The context.catch method must only be called with a location
939
- // argument that corresponds to a known catch block.
940
- throw new Error("illegal catch attempt");
941
- },
942
- delegateYield: function delegateYield(iterable, resultName, nextLoc) {
943
- this.delegate = {
944
- iterator: values(iterable),
945
- resultName: resultName,
946
- nextLoc: nextLoc
947
- };
948
- if (this.method === "next") {
949
- // Deliberately forget the last sent value so that we don't
950
- // accidentally pass it on to the delegate.
951
- this.arg = undefined$1;
952
- }
953
- return ContinueSentinel;
954
- }
955
- };
956
-
957
- // Regardless of whether this script is executing as a CommonJS module
958
- // or not, return the runtime object so that we can declare the variable
959
- // regeneratorRuntime in the outer scope, which allows this module to be
960
- // injected easily by `bin/regenerator --include-runtime script.js`.
961
- return exports;
962
- }(
963
- // If this script is executing as a CommonJS module, use module.exports
964
- // as the regeneratorRuntime namespace. Otherwise create a new empty
965
- // object. Either way, the resulting object will be used to initialize
966
- // the regeneratorRuntime variable at the top of this file.
967
- module.exports );
968
- try {
969
- regeneratorRuntime = runtime;
970
- } catch (accidentalStrictMode) {
971
- // This module should not be running in strict mode, so the above
972
- // assignment should always work unless something is misconfigured. Just
973
- // in case runtime.js accidentally runs in strict mode, in modern engines
974
- // we can explicitly access globalThis. In older engines we can escape
975
- // strict mode using a global Function call. This could conceivably fail
976
- // if a Content Security Policy forbids using Function, but in that case
977
- // the proper solution is to fix the accidental strict mode problem. If
978
- // you've misconfigured your bundler to force strict mode and applied a
979
- // CSP to forbid Function, and you're not willing to fix either of those
980
- // problems, please detail your unique predicament in a GitHub issue.
981
- if (typeof globalThis === "object") {
982
- globalThis.regeneratorRuntime = runtime;
983
- } else {
984
- Function("r", "regeneratorRuntime = r")(runtime);
985
- }
986
- }
987
- });
988
-
989
- var tuple = function tuple() {
990
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
991
- args[_key] = arguments[_key];
992
- }
993
- return args;
994
- };
995
- function mkIdMap(xs) {
996
- return new Map(xs.map(function (x) {
997
- return tuple(x.id, x);
998
- }));
999
- }
1000
- var mkShortId = function mkShortId() {
1001
- return "" + Math.random();
1002
- };
1003
- var withoutNils = function withoutNils(xs) {
1004
- return xs.filter(function (x) {
1005
- return x != null;
1006
- });
1007
- };
1008
- var defaultColumnConfig = function defaultColumnConfig() {
1009
- return {
1010
- key: mkShortId(),
1011
- isEditableExpr: function isEditableExpr() {
1012
- return false;
1013
- },
1014
- disableSorting: false,
1015
- sortByExpr: undefined,
1016
- isHidden: false,
1017
- formatting: {
1018
- styles: {},
1019
- align: "left",
1020
- freeze: "off"
1021
- },
1022
- dataType: "auto"
1023
- };
1024
- };
1025
- function deriveFieldConfigs(specifiedFieldsPartial, schema) {
1026
- var _schema$fields;
1027
- var schemaFields = (_schema$fields = schema == null ? void 0 : schema.fields) != null ? _schema$fields : [];
1028
- var fieldById = mkIdMap(schemaFields);
1029
- var specifiedFieldIds = new Set(withoutNils(specifiedFieldsPartial.map(function (f) {
1030
- return f.fieldId;
1031
- })));
1032
- function defaultColumnConfigForField(field) {
1033
- return _extends({}, defaultColumnConfig(), {
1034
- key: field.id,
1035
- fieldId: field.id,
1036
- title: field.label || field.id,
1037
- expr: function expr(currentItem) {
1038
- return currentItem[field.id];
1039
- }
1040
- });
1041
- }
1042
- var keptSpecifiedFields = specifiedFieldsPartial.flatMap(function (f, index) {
1043
- var fieldId = f.fieldId;
1044
- if (!fieldId) {
1045
- return [_extends({}, defaultColumnConfig(), {
1046
- key: index
1047
- }, f)];
1048
- }
1049
- var field = fieldById.get(fieldId);
1050
- // Drop configs with fieldIds no longer in the data.
1051
- if (!field) {
1052
- return [];
1053
- }
1054
- return [_extends({}, defaultColumnConfigForField(field), f)];
1055
- });
1056
- var newVirtualFields = schemaFields.filter(function (f) {
1057
- return !specifiedFieldIds.has(f.id);
1058
- }).map(function (f) {
1059
- return _extends({}, defaultColumnConfigForField(f));
1060
- });
1061
- var mergedFields = [].concat(keptSpecifiedFields, newVirtualFields);
1062
- var minimalFullLengthFields = [].concat(specifiedFieldsPartial, newVirtualFields.map(function (f) {
1063
- return {
1064
- key: f.key,
1065
- fieldId: f.fieldId
1066
- };
1067
- }));
1068
- return {
1069
- mergedFields: mergedFields,
1070
- minimalFullLengthFields: minimalFullLengthFields
1071
- };
1072
- }
1073
-
1074
- function tryGetSchema(data) {
1075
- var _data, _data2;
1076
- if ((_data = data) != null && _data.schema) {
1077
- return data.schema;
1078
- }
1079
- if (Array.isArray(data)) {
1080
- data = {
1081
- data: data
1082
- };
1083
- }
1084
- if (!((_data2 = data) != null && _data2.data) || !Array.isArray(data.data) || data.data.length === 0) {
1085
- return undefined;
1086
- }
1087
- var fieldMap = {};
1088
- data.data.forEach(function (entry) {
1089
- if (entry && typeof entry === "object") {
1090
- Array.from(Object.entries(entry)).forEach(function (_ref) {
1091
- var k = _ref[0],
1092
- v = _ref[1];
1093
- var inferredType = typeof v === "string" ? "string" : typeof v === "boolean" ? "boolean" : typeof v === "number" ? "number" : "unknown";
1094
- if (fieldMap[k] && fieldMap[k] !== inferredType) {
1095
- fieldMap[k] = "unknown";
1096
- } else {
1097
- fieldMap[k] = inferredType;
1098
- }
1099
- });
1100
- }
1101
- });
1102
- return {
1103
- id: "inferred",
1104
- fields: Object.entries(fieldMap).map(function (_ref2) {
1105
- var f = _ref2[0],
1106
- t = _ref2[1];
1107
- return {
1108
- id: f,
1109
- type: t,
1110
- readOnly: false
1111
- };
1112
- })
1113
- };
1114
- }
1115
- function normalizeData(rawData) {
1116
- if (!rawData || typeof rawData !== "object") {
1117
- return undefined;
1118
- }
1119
- var obj = Array.isArray(rawData) ? {
1120
- data: rawData
1121
- } : rawData;
1122
- if (!("data" in obj)) {
1123
- return undefined;
1124
- }
1125
- var objWithData = obj;
1126
- if (!Array.isArray(objWithData.data) || objWithData.data.length === 0) {
1127
- return undefined;
1128
- }
1129
- // Make TS happy.
1130
- var normed = _extends({}, objWithData, {
1131
- data: objWithData.data
1132
- });
1133
- var schema = tryGetSchema(rawData);
1134
- if (!schema) {
1135
- return undefined;
1136
- }
1137
- return _extends({}, normed, {
1138
- schema: schema
1139
- });
1140
- }
1141
- /**
1142
- * Render booleans, objects, arrays, etc. as JSON repr.
1143
- */
1144
- function safeRender(x) {
1145
- return x === undefined || x === null ? "" : typeof x === "string" ? x : typeof x === "number" ? x.toString() : JSON.stringify(x);
1146
- }
1147
- function RichTable(props) {
1148
- var className = props.className,
1149
- _props$data = props.data,
1150
- rawData = _props$data === void 0 ? {
1151
- data: [],
1152
- schema: {
1153
- id: "inferred",
1154
- fields: [{
1155
- id: "id",
1156
- type: "string",
1157
- readOnly: false
1158
- }]
1159
- }
1160
- } : _props$data,
1161
- _props$pagination = props.pagination,
1162
- pagination = _props$pagination === void 0 ? true : _props$pagination,
1163
- defaultSize = props.defaultSize,
1164
- fields = props.fields,
1165
- setControlContextData = props.setControlContextData,
1166
- title = props.title,
1167
- addHref = props.addHref,
1168
- actions = props.actions,
1169
- customActionChildren = props.customActionChildren,
1170
- _props$pageSize = props.pageSize,
1171
- pageSize = _props$pageSize === void 0 ? 10 : _props$pageSize,
1172
- _props$scrollX = props.scrollX,
1173
- scrollX = _props$scrollX === void 0 ? true : _props$scrollX,
1174
- scrollHeight = props.scrollHeight,
1175
- hideSearch = props.hideSearch,
1176
- hideDensity = props.hideDensity,
1177
- hideColumnPicker = props.hideColumnPicker,
1178
- hideExports = props.hideExports;
1179
- var data = normalizeData(rawData);
1180
- var _useState = React.useState(""),
1181
- search = _useState[0],
1182
- setSearch = _useState[1];
1183
- var _React$useMemo = React__default.useMemo(function () {
1184
- var schema = tryGetSchema(data);
1185
- if (!data || !schema) {
1186
- return {
1187
- normalized: [],
1188
- columnDefinitions: []
1189
- };
1190
- }
1191
- var _deriveFieldConfigs = deriveFieldConfigs(fields != null ? fields : [], schema),
1192
- mergedFields = _deriveFieldConfigs.mergedFields,
1193
- minimalFullLengthFields = _deriveFieldConfigs.minimalFullLengthFields;
1194
- setControlContextData == null ? void 0 : setControlContextData(_extends({}, data, {
1195
- mergedFields: mergedFields,
1196
- minimalFullLengthFields: minimalFullLengthFields
1197
- }));
1198
- var normalized = mergedFields;
1199
- var columnDefinitions = normalized.filter(function (cconfig) {
1200
- return !cconfig.isHidden;
1201
- }).map(function (cconfig, _columnIndex, _columnsArray) {
1202
- var columnDefinition = {
1203
- dataIndex: cconfig.fieldId,
1204
- title: cconfig.title,
1205
- // dataIndex: cconfig,
1206
- key: cconfig.key,
1207
- valueType: cconfig.dataType === "auto" ? undefined : cconfig.dataType === "string" ? "text" : cconfig.dataType === "number" ? "digit" : cconfig.dataType === "boolean" ? "switch" : undefined,
1208
- // To come later
1209
- readonly: false,
1210
- sorter: true,
1211
- copyable: false,
1212
- ellipsis: false,
1213
- tip: undefined,
1214
- formItemProps: {
1215
- rules: []
1216
- },
1217
- disable: false,
1218
- valueEnum: undefined,
1219
- search: undefined,
1220
- hideInSearch: false,
1221
- renderFormItem: function renderFormItem(_, _ref3) {
1222
- var defaultRender = _ref3.defaultRender;
1223
- return defaultRender(_);
1224
- },
1225
- render: function render(value, record, rowIndex) {
1226
- return React__default.createElement(host.DataProvider, {
1227
- name: "currentRow",
1228
- data: record
1229
- }, React__default.createElement(host.DataProvider, {
1230
- name: "currentRowIndex",
1231
- data: rowIndex
1232
- }, React__default.createElement(host.DataProvider, {
1233
- name: "currentColumn",
1234
- data: value
1235
- }, safeRender(cconfig.expr ? cconfig.expr(record) : value))));
1236
- }
1237
- };
1238
- return columnDefinition;
1239
- });
1240
- if (actions && actions.length > 0) {
1241
- columnDefinitions.push({
1242
- title: "Actions",
1243
- valueType: "option",
1244
- key: "__plasmicActions",
1245
- render: function render(_text, record, _, action) {
1246
- return [].concat(actions.filter(function (_action) {
1247
- return !_action.moreMenu;
1248
- }).map(function (_action, aindex) {
1249
- return _action.type === "edit" ? React__default.createElement("a", {
1250
- key: aindex,
1251
- onClick: function onClick() {
1252
- action == null ? void 0 : action.startEditable == null ? void 0 : action.startEditable(record.id);
1253
- }
1254
- }, "Edit") : _action.type === "view" ? React__default.createElement("a", {
1255
- key: aindex,
1256
- href: record.url
1257
- }, "View") : _action.type === "delete" ? React__default.createElement("a", {
1258
- key: aindex,
1259
- onClick: function onClick() {
1260
- // TODO delete
1261
- }
1262
- }, "Delete") : customActionChildren;
1263
- }), [React__default.createElement(proComponents.TableDropdown, {
1264
- key: "actionGroup",
1265
- onSelect: function onSelect() {
1266
- return action == null ? void 0 : action.reload();
1267
- },
1268
- menus: actions.filter(function (_action) {
1269
- return !!_action.moreMenu;
1270
- }).map(function (_action, aindex) {
1271
- var _action$label;
1272
- return {
1273
- key: "" + aindex,
1274
- name: (_action$label = _action.label) != null ? _action$label : _action.type
1275
- };
1276
- })
1277
- })]);
1278
- }
1279
- });
1280
- }
1281
- return {
1282
- normalized: normalized,
1283
- columnDefinitions: columnDefinitions
1284
- };
1285
- }, [fields, data, setControlContextData]),
1286
- columnDefinitions = _React$useMemo.columnDefinitions,
1287
- normalized = _React$useMemo.normalized;
1288
- var actionRef = React.useRef();
1289
- var _useState2 = React.useState(undefined),
1290
- state = _useState2[0],
1291
- setState = _useState2[1];
1292
- var finalData = React.useMemo(function () {
1293
- var _data$data;
1294
- var filtered = data == null ? void 0 : (_data$data = data.data) == null ? void 0 : _data$data.filter(function (row) {
1295
- return fastStringify(Object.values(row)).toLowerCase().includes(search);
1296
- });
1297
- var sorted = state != null && state.sorter.column ?
1298
- // We use .sort() rather than sortBy to use localeCompare
1299
- function () {
1300
- var _normalized$find$expr;
1301
- var expr = (_normalized$find$expr = normalized.find(function (cconfig) {
1302
- var _state$sorter$column;
1303
- return cconfig.key === (state == null ? void 0 : (_state$sorter$column = state.sorter.column) == null ? void 0 : _state$sorter$column.key);
1304
- }).expr) != null ? _normalized$find$expr : function (x) {
1305
- return x;
1306
- };
1307
- return (filtered != null ? filtered : []).sort(function (aa, bb) {
1308
- var _expr, _expr2;
1309
- var a = (_expr = expr(aa)) != null ? _expr : null,
1310
- b = (_expr2 = expr(bb)) != null ? _expr2 : null;
1311
- // Default nil to '' here because A < null < z which is weird.
1312
- return typeof a === "string" ? a.localeCompare(b != null ? b : "") : typeof b === "string" ? -b.localeCompare(a != null ? a : "") : a - b;
1313
- });
1314
- }() : filtered;
1315
- var reversed = (state == null ? void 0 : state.sorter.order) === "descend" ? sorted == null ? void 0 : sorted.reverse() : sorted;
1316
- return reversed;
1317
- }, [data, normalized, state, search]);
1318
- var isClient = useIsClient();
1319
- if (!isClient) {
1320
- return null;
1321
- }
1322
- return React__default.createElement(React__default.Fragment, null, React__default.createElement(proComponents.ProTable, {
1323
- actionRef: actionRef,
1324
- className: className,
1325
- columns: columnDefinitions,
1326
- onChange: function onChange(_pagination, _filters, sorter, _extra) {
1327
- setState({
1328
- sorter: sorter
1329
- });
1330
- },
1331
- dataSource: finalData,
1332
- rowKey: "id",
1333
- defaultSize: defaultSize,
1334
- editable: {
1335
- type: "multiple"
1336
- },
1337
- search: false,
1338
- options: {
1339
- setting: hideColumnPicker ? false : {
1340
- listsHeight: 400
1341
- },
1342
- reload: false,
1343
- density: !hideDensity
1344
- },
1345
- pagination: pagination ? {
1346
- pageSize: pageSize,
1347
- onChange: function onChange(page) {
1348
- return console.log(page);
1349
- }
1350
- } : false,
1351
- dateFormatter: "string",
1352
- headerTitle: title,
1353
- // TODO in the future, figure out how to make this responsive to the CSS height
1354
- scroll: {
1355
- x: scrollX || undefined,
1356
- y: scrollHeight
1357
- },
1358
- toolbar: {
1359
- search: !hideSearch ? {
1360
- value: search,
1361
- onChange: function onChange(e) {
1362
- return setSearch(e.target.value);
1363
- },
1364
- onSearch: function onSearch() {},
1365
- placeholder: "Search"
1366
- } : undefined
1367
- },
1368
- toolBarRender: function toolBarRender() {
1369
- return [addHref && React__default.createElement(antd.Button, {
1370
- key: "button",
1371
- icon: React__default.createElement(icons.PlusOutlined, null),
1372
- type: "primary",
1373
- href: addHref
1374
- }, "Add"), !hideExports && React__default.createElement(antd.Dropdown, {
1375
- key: "menu",
1376
- menu: {
1377
- items: [{
1378
- label: "Download as CSV",
1379
- key: "csv",
1380
- onClick: function () {
1381
- var _onClick = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee() {
1382
- var _tryGetSchema$fields$, _tryGetSchema;
1383
- var writer, dataStr, filename, blob, link, url;
1384
- return runtime_1.wrap(function _callee$(_context) {
1385
- while (1) {
1386
- switch (_context.prev = _context.next) {
1387
- case 0:
1388
- writer = csvWriterBrowser.createObjectCsvStringifier({
1389
- header: (_tryGetSchema$fields$ = (_tryGetSchema = tryGetSchema(data)) == null ? void 0 : _tryGetSchema.fields.map(function (f) {
1390
- return {
1391
- id: f.id,
1392
- title: f.id
1393
- };
1394
- })) != null ? _tryGetSchema$fields$ : []
1395
- });
1396
- dataStr = writer.getHeaderString() + writer.stringifyRecords(data == null ? void 0 : data.data); // const dataStr = stringify(data?.data as any, {
1397
- // columns:
1398
- // tryGetSchema(data)?.fields.map((f) => f.id) ?? [],
1399
- // header: true,
1400
- // });
1401
- filename = "data.csv"; // Adapted from https://stackoverflow.com/a/68771795
1402
- blob = new Blob([dataStr], {
1403
- type: "text/csv;charset=utf-8;"
1404
- });
1405
- if (navigator.msSaveBlob) {
1406
- // In case of IE 10+
1407
- navigator.msSaveBlob(blob, filename);
1408
- } else {
1409
- link = document.createElement("a");
1410
- if (link.download !== undefined) {
1411
- // Browsers that support HTML5 download attribute
1412
- url = URL.createObjectURL(blob);
1413
- link.setAttribute("href", url);
1414
- link.setAttribute("download", filename);
1415
- link.style.visibility = "hidden";
1416
- document.body.appendChild(link);
1417
- link.click();
1418
- document.body.removeChild(link);
1419
- }
1420
- }
1421
- case 5:
1422
- case "end":
1423
- return _context.stop();
1424
- }
1425
- }
1426
- }, _callee);
1427
- }));
1428
- function onClick() {
1429
- return _onClick.apply(this, arguments);
1430
- }
1431
- return onClick;
1432
- }()
1433
- }, {
1434
- label: "Download as JSON",
1435
- key: "json",
1436
- onClick: function onClick() {
1437
- var dataStr = fastStringify(data == null ? void 0 : data.data);
1438
- var dataUri = "data:application/json;charset=utf-8, " + encodeURIComponent(dataStr);
1439
- var exportFileDefaultName = "data.json";
1440
- var linkElement = document.createElement("a");
1441
- linkElement.setAttribute("href", dataUri);
1442
- linkElement.setAttribute("download", exportFileDefaultName);
1443
- linkElement.click();
1444
- }
1445
- }]
1446
- }
1447
- }, React__default.createElement(antd.Button, null, React__default.createElement(icons.EllipsisOutlined, null)))];
1448
- }
1449
- }), 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 "));
1450
- }
1451
-
1452
- function ensureNumber(x) {
1453
- return x;
1454
- }
1455
- var rowDataType = function rowDataType(displayName, control) {
1456
- return {
1457
- type: "function",
1458
- displayName: displayName,
1459
- control: control,
1460
- argNames: ["currentItem"],
1461
- argValues: function argValues(_props, ctx) {
1462
- var _ctx$data;
1463
- return [ctx == null ? void 0 : (_ctx$data = ctx.data) == null ? void 0 : _ctx$data[0]];
1464
- }
1465
- };
1466
- };
1467
- function getDefaultValueHint(field) {
1468
- return function (_props, contextData, _ref) {
1469
- var path = _ref.path;
1470
- return contextData == null ? void 0 : contextData.mergedFields[ensureNumber(path.slice(-2)[0])][field];
1471
- };
1472
- }
1473
- var dataTableMeta = {
1474
- name: "hostless-rich-table",
1475
- displayName: "Table",
1476
- defaultStyles: {
1477
- width: "stretch"
1478
- },
1479
- props: {
1480
- data: {
1481
- type: "dataSourceOpData",
1482
- description: "The data to display in the table"
1483
- },
1484
- defaultSize: {
1485
- type: "choice",
1486
- options: ["large", "middle", "small"],
1487
- defaultValueHint: "large"
1488
- },
1489
- pageSize: {
1490
- type: "number",
1491
- defaultValueHint: 10
1492
- },
1493
- fields: {
1494
- type: "array",
1495
- hidden: function hidden(ps) {
1496
- return !ps.data;
1497
- },
1498
- unstable__keyFunc: function unstable__keyFunc(x) {
1499
- return x.key;
1500
- },
1501
- unstable__minimalValue: function unstable__minimalValue(_props, contextData) {
1502
- return contextData == null ? void 0 : contextData.minimalFullLengthFields;
1503
- },
1504
- unstable__canDelete: function unstable__canDelete(_item, _props, ctx, _ref2) {
1505
- var path = _ref2.path;
1506
- return !(ctx != null && ctx.mergedFields[ensureNumber(path.slice(-1)[0])].fieldId);
1507
- },
1508
- itemType: {
1509
- type: "object",
1510
- nameFunc: function nameFunc(_item, _props, ctx, _ref3) {
1511
- var path = _ref3.path;
1512
- return ctx == null ? void 0 : ctx.mergedFields[ensureNumber(path.slice(-1)[0])].title;
1513
- },
1514
- fields: {
1515
- key: {
1516
- type: "string",
1517
- hidden: function hidden() {
1518
- return true;
1519
- }
1520
- },
1521
- fieldId: {
1522
- type: "choice",
1523
- displayName: "Field name",
1524
- readOnly: true,
1525
- options: function options(_props, ctx) {
1526
- var _ctx$schema$fields, _ctx$schema;
1527
- 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) {
1528
- return f.id;
1529
- });
1530
- },
1531
- hidden: function hidden(_props, ctx, _ref4) {
1532
- var _ctx$schema$fields2, _ctx$schema2;
1533
- var _controlPath = _ref4.path;
1534
- 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 : {}));
1535
- }
1536
- },
1537
- title: {
1538
- type: "string",
1539
- displayName: "Title",
1540
- defaultValueHint: /*#__PURE__*/getDefaultValueHint("title")
1541
- },
1542
- dataType: {
1543
- type: "choice",
1544
- displayName: "Data type",
1545
- options: ["auto", "number", "string", "boolean"],
1546
- defaultValueHint: /*#__PURE__*/getDefaultValueHint("dataType")
1547
- },
1548
- expr: /*#__PURE__*/rowDataType("Customize data"),
1549
- // TODO
1550
- // isEditableExpr: rowDataType("Is editable", {
1551
- // type: "boolean",
1552
- // defaultValueHint: false,
1553
- // }),
1554
- // disableSorting: {
1555
- // type: "boolean",
1556
- // displayName: "Disable sorting",
1557
- // defaultValueHint: getDefaultValueHint("disableSorting"),
1558
- // },
1559
- // sortByExpr: rowDataType("Sort by"),
1560
- isHidden: {
1561
- type: "boolean",
1562
- displayName: "Is hidden",
1563
- defaultValueHint: /*#__PURE__*/getDefaultValueHint("isHidden")
1564
- }
1565
- }
1566
- }
1567
- },
1568
- pagination: {
1569
- type: "boolean",
1570
- advanced: true,
1571
- defaultValueHint: true
1572
- },
1573
- scrollX: {
1574
- type: "boolean",
1575
- advanced: true,
1576
- defaultValueHint: true
1577
- },
1578
- scrollHeight: {
1579
- type: "number",
1580
- advanced: true
1581
- },
1582
- hideSearch: {
1583
- type: "boolean",
1584
- advanced: true
1585
- },
1586
- hideExports: {
1587
- type: "boolean",
1588
- advanced: true
1589
- },
1590
- hideDensity: {
1591
- type: "boolean",
1592
- advanced: true
1593
- },
1594
- hideColumnPicker: {
1595
- type: "boolean",
1596
- advanced: true
1597
- }
1598
- },
1599
- importName: "RichTable",
1600
- importPath: "@plasmicpkgs/plasmic-rich-components"
1601
- };
1602
- function registerRichTable(loader) {
1603
- registerComponentHelper(loader, RichTable, dataTableMeta);
1604
- }
1605
-
1606
- function registerAll(loader) {
1607
- registerRichLayout(loader);
1608
- registerRichTable(loader);
1609
- }
1610
-
1611
- exports.RichLayout = RichLayout;
1612
- exports.RichTable = RichTable;
1613
- exports.registerAll = registerAll;
1614
- //# sourceMappingURL=plasmic-rich-components.cjs.development.js.map