@plasmicpkgs/plasmic-cms 0.0.7

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.
@@ -0,0 +1,1773 @@
1
+ import { repeatedElement, registerComponent } from '@plasmicapp/host';
2
+ import { usePlasmicQueryData } from '@plasmicapp/query';
3
+ import React from 'react';
4
+ import { useSelector, DataProvider, useDataEnv } from '@plasmicpkgs/plasmic-basic-components';
5
+
6
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
7
+ try {
8
+ var info = gen[key](arg);
9
+ var value = info.value;
10
+ } catch (error) {
11
+ reject(error);
12
+ return;
13
+ }
14
+
15
+ if (info.done) {
16
+ resolve(value);
17
+ } else {
18
+ Promise.resolve(value).then(_next, _throw);
19
+ }
20
+ }
21
+
22
+ function _asyncToGenerator(fn) {
23
+ return function () {
24
+ var self = this,
25
+ args = arguments;
26
+ return new Promise(function (resolve, reject) {
27
+ var gen = fn.apply(self, args);
28
+
29
+ function _next(value) {
30
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
31
+ }
32
+
33
+ function _throw(err) {
34
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
35
+ }
36
+
37
+ _next(undefined);
38
+ });
39
+ };
40
+ }
41
+
42
+ function _objectWithoutPropertiesLoose(source, excluded) {
43
+ if (source == null) return {};
44
+ var target = {};
45
+ var sourceKeys = Object.keys(source);
46
+ var key, i;
47
+
48
+ for (i = 0; i < sourceKeys.length; i++) {
49
+ key = sourceKeys[i];
50
+ if (excluded.indexOf(key) >= 0) continue;
51
+ target[key] = source[key];
52
+ }
53
+
54
+ return target;
55
+ }
56
+
57
+ function _unsupportedIterableToArray(o, minLen) {
58
+ if (!o) return;
59
+ if (typeof o === "string") return _arrayLikeToArray(o, minLen);
60
+ var n = Object.prototype.toString.call(o).slice(8, -1);
61
+ if (n === "Object" && o.constructor) n = o.constructor.name;
62
+ if (n === "Map" || n === "Set") return Array.from(o);
63
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
64
+ }
65
+
66
+ function _arrayLikeToArray(arr, len) {
67
+ if (len == null || len > arr.length) len = arr.length;
68
+
69
+ for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
70
+
71
+ return arr2;
72
+ }
73
+
74
+ function _createForOfIteratorHelperLoose(o, allowArrayLike) {
75
+ var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
76
+ if (it) return (it = it.call(o)).next.bind(it);
77
+
78
+ if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
79
+ if (it) o = it;
80
+ var i = 0;
81
+ return function () {
82
+ if (i >= o.length) return {
83
+ done: true
84
+ };
85
+ return {
86
+ done: false,
87
+ value: o[i++]
88
+ };
89
+ };
90
+ }
91
+
92
+ throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
93
+ }
94
+
95
+ function createCommonjsModule(fn, module) {
96
+ return module = { exports: {} }, fn(module, module.exports), module.exports;
97
+ }
98
+
99
+ var runtime_1 = createCommonjsModule(function (module) {
100
+ /**
101
+ * Copyright (c) 2014-present, Facebook, Inc.
102
+ *
103
+ * This source code is licensed under the MIT license found in the
104
+ * LICENSE file in the root directory of this source tree.
105
+ */
106
+
107
+ var runtime = (function (exports) {
108
+
109
+ var Op = Object.prototype;
110
+ var hasOwn = Op.hasOwnProperty;
111
+ var undefined$1; // More compressible than void 0.
112
+ var $Symbol = typeof Symbol === "function" ? Symbol : {};
113
+ var iteratorSymbol = $Symbol.iterator || "@@iterator";
114
+ var asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator";
115
+ var toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
116
+
117
+ function define(obj, key, value) {
118
+ Object.defineProperty(obj, key, {
119
+ value: value,
120
+ enumerable: true,
121
+ configurable: true,
122
+ writable: true
123
+ });
124
+ return obj[key];
125
+ }
126
+ try {
127
+ // IE 8 has a broken Object.defineProperty that only works on DOM objects.
128
+ define({}, "");
129
+ } catch (err) {
130
+ define = function(obj, key, value) {
131
+ return obj[key] = value;
132
+ };
133
+ }
134
+
135
+ function wrap(innerFn, outerFn, self, tryLocsList) {
136
+ // If outerFn provided and outerFn.prototype is a Generator, then outerFn.prototype instanceof Generator.
137
+ var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator;
138
+ var generator = Object.create(protoGenerator.prototype);
139
+ var context = new Context(tryLocsList || []);
140
+
141
+ // The ._invoke method unifies the implementations of the .next,
142
+ // .throw, and .return methods.
143
+ generator._invoke = makeInvokeMethod(innerFn, self, context);
144
+
145
+ return generator;
146
+ }
147
+ exports.wrap = wrap;
148
+
149
+ // Try/catch helper to minimize deoptimizations. Returns a completion
150
+ // record like context.tryEntries[i].completion. This interface could
151
+ // have been (and was previously) designed to take a closure to be
152
+ // invoked without arguments, but in all the cases we care about we
153
+ // already have an existing method we want to call, so there's no need
154
+ // to create a new function object. We can even get away with assuming
155
+ // the method takes exactly one argument, since that happens to be true
156
+ // in every case, so we don't have to touch the arguments object. The
157
+ // only additional allocation required is the completion record, which
158
+ // has a stable shape and so hopefully should be cheap to allocate.
159
+ function tryCatch(fn, obj, arg) {
160
+ try {
161
+ return { type: "normal", arg: fn.call(obj, arg) };
162
+ } catch (err) {
163
+ return { type: "throw", arg: err };
164
+ }
165
+ }
166
+
167
+ var GenStateSuspendedStart = "suspendedStart";
168
+ var GenStateSuspendedYield = "suspendedYield";
169
+ var GenStateExecuting = "executing";
170
+ var GenStateCompleted = "completed";
171
+
172
+ // Returning this object from the innerFn has the same effect as
173
+ // breaking out of the dispatch switch statement.
174
+ var ContinueSentinel = {};
175
+
176
+ // Dummy constructor functions that we use as the .constructor and
177
+ // .constructor.prototype properties for functions that return Generator
178
+ // objects. For full spec compliance, you may wish to configure your
179
+ // minifier not to mangle the names of these two functions.
180
+ function Generator() {}
181
+ function GeneratorFunction() {}
182
+ function GeneratorFunctionPrototype() {}
183
+
184
+ // This is a polyfill for %IteratorPrototype% for environments that
185
+ // don't natively support it.
186
+ var IteratorPrototype = {};
187
+ define(IteratorPrototype, iteratorSymbol, function () {
188
+ return this;
189
+ });
190
+
191
+ var getProto = Object.getPrototypeOf;
192
+ var NativeIteratorPrototype = getProto && getProto(getProto(values([])));
193
+ if (NativeIteratorPrototype &&
194
+ NativeIteratorPrototype !== Op &&
195
+ hasOwn.call(NativeIteratorPrototype, iteratorSymbol)) {
196
+ // This environment has a native %IteratorPrototype%; use it instead
197
+ // of the polyfill.
198
+ IteratorPrototype = NativeIteratorPrototype;
199
+ }
200
+
201
+ var Gp = GeneratorFunctionPrototype.prototype =
202
+ Generator.prototype = Object.create(IteratorPrototype);
203
+ GeneratorFunction.prototype = GeneratorFunctionPrototype;
204
+ define(Gp, "constructor", GeneratorFunctionPrototype);
205
+ define(GeneratorFunctionPrototype, "constructor", GeneratorFunction);
206
+ GeneratorFunction.displayName = define(
207
+ GeneratorFunctionPrototype,
208
+ toStringTagSymbol,
209
+ "GeneratorFunction"
210
+ );
211
+
212
+ // Helper for defining the .next, .throw, and .return methods of the
213
+ // Iterator interface in terms of a single ._invoke method.
214
+ function defineIteratorMethods(prototype) {
215
+ ["next", "throw", "return"].forEach(function(method) {
216
+ define(prototype, method, function(arg) {
217
+ return this._invoke(method, arg);
218
+ });
219
+ });
220
+ }
221
+
222
+ exports.isGeneratorFunction = function(genFun) {
223
+ var ctor = typeof genFun === "function" && genFun.constructor;
224
+ return ctor
225
+ ? ctor === GeneratorFunction ||
226
+ // For the native GeneratorFunction constructor, the best we can
227
+ // do is to check its .name property.
228
+ (ctor.displayName || ctor.name) === "GeneratorFunction"
229
+ : false;
230
+ };
231
+
232
+ exports.mark = function(genFun) {
233
+ if (Object.setPrototypeOf) {
234
+ Object.setPrototypeOf(genFun, GeneratorFunctionPrototype);
235
+ } else {
236
+ genFun.__proto__ = GeneratorFunctionPrototype;
237
+ define(genFun, toStringTagSymbol, "GeneratorFunction");
238
+ }
239
+ genFun.prototype = Object.create(Gp);
240
+ return genFun;
241
+ };
242
+
243
+ // Within the body of any async function, `await x` is transformed to
244
+ // `yield regeneratorRuntime.awrap(x)`, so that the runtime can test
245
+ // `hasOwn.call(value, "__await")` to determine if the yielded value is
246
+ // meant to be awaited.
247
+ exports.awrap = function(arg) {
248
+ return { __await: arg };
249
+ };
250
+
251
+ function AsyncIterator(generator, PromiseImpl) {
252
+ function invoke(method, arg, resolve, reject) {
253
+ var record = tryCatch(generator[method], generator, arg);
254
+ if (record.type === "throw") {
255
+ reject(record.arg);
256
+ } else {
257
+ var result = record.arg;
258
+ var value = result.value;
259
+ if (value &&
260
+ typeof value === "object" &&
261
+ hasOwn.call(value, "__await")) {
262
+ return PromiseImpl.resolve(value.__await).then(function(value) {
263
+ invoke("next", value, resolve, reject);
264
+ }, function(err) {
265
+ invoke("throw", err, resolve, reject);
266
+ });
267
+ }
268
+
269
+ return PromiseImpl.resolve(value).then(function(unwrapped) {
270
+ // When a yielded Promise is resolved, its final value becomes
271
+ // the .value of the Promise<{value,done}> result for the
272
+ // current iteration.
273
+ result.value = unwrapped;
274
+ resolve(result);
275
+ }, function(error) {
276
+ // If a rejected Promise was yielded, throw the rejection back
277
+ // into the async generator function so it can be handled there.
278
+ return invoke("throw", error, resolve, reject);
279
+ });
280
+ }
281
+ }
282
+
283
+ var previousPromise;
284
+
285
+ function enqueue(method, arg) {
286
+ function callInvokeWithMethodAndArg() {
287
+ return new PromiseImpl(function(resolve, reject) {
288
+ invoke(method, arg, resolve, reject);
289
+ });
290
+ }
291
+
292
+ return previousPromise =
293
+ // If enqueue has been called before, then we want to wait until
294
+ // all previous Promises have been resolved before calling invoke,
295
+ // so that results are always delivered in the correct order. If
296
+ // enqueue has not been called before, then it is important to
297
+ // call invoke immediately, without waiting on a callback to fire,
298
+ // so that the async generator function has the opportunity to do
299
+ // any necessary setup in a predictable way. This predictability
300
+ // is why the Promise constructor synchronously invokes its
301
+ // executor callback, and why async functions synchronously
302
+ // execute code before the first await. Since we implement simple
303
+ // async functions in terms of async generators, it is especially
304
+ // important to get this right, even though it requires care.
305
+ previousPromise ? previousPromise.then(
306
+ callInvokeWithMethodAndArg,
307
+ // Avoid propagating failures to Promises returned by later
308
+ // invocations of the iterator.
309
+ callInvokeWithMethodAndArg
310
+ ) : callInvokeWithMethodAndArg();
311
+ }
312
+
313
+ // Define the unified helper method that is used to implement .next,
314
+ // .throw, and .return (see defineIteratorMethods).
315
+ this._invoke = enqueue;
316
+ }
317
+
318
+ defineIteratorMethods(AsyncIterator.prototype);
319
+ define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
320
+ return this;
321
+ });
322
+ exports.AsyncIterator = AsyncIterator;
323
+
324
+ // Note that simple async functions are implemented on top of
325
+ // AsyncIterator objects; they just return a Promise for the value of
326
+ // the final result produced by the iterator.
327
+ exports.async = function(innerFn, outerFn, self, tryLocsList, PromiseImpl) {
328
+ if (PromiseImpl === void 0) PromiseImpl = Promise;
329
+
330
+ var iter = new AsyncIterator(
331
+ wrap(innerFn, outerFn, self, tryLocsList),
332
+ PromiseImpl
333
+ );
334
+
335
+ return exports.isGeneratorFunction(outerFn)
336
+ ? iter // If outerFn is a generator, return the full iterator.
337
+ : iter.next().then(function(result) {
338
+ return result.done ? result.value : iter.next();
339
+ });
340
+ };
341
+
342
+ function makeInvokeMethod(innerFn, self, context) {
343
+ var state = GenStateSuspendedStart;
344
+
345
+ return function invoke(method, arg) {
346
+ if (state === GenStateExecuting) {
347
+ throw new Error("Generator is already running");
348
+ }
349
+
350
+ if (state === GenStateCompleted) {
351
+ if (method === "throw") {
352
+ throw arg;
353
+ }
354
+
355
+ // Be forgiving, per 25.3.3.3.3 of the spec:
356
+ // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-generatorresume
357
+ return doneResult();
358
+ }
359
+
360
+ context.method = method;
361
+ context.arg = arg;
362
+
363
+ while (true) {
364
+ var delegate = context.delegate;
365
+ if (delegate) {
366
+ var delegateResult = maybeInvokeDelegate(delegate, context);
367
+ if (delegateResult) {
368
+ if (delegateResult === ContinueSentinel) continue;
369
+ return delegateResult;
370
+ }
371
+ }
372
+
373
+ if (context.method === "next") {
374
+ // Setting context._sent for legacy support of Babel's
375
+ // function.sent implementation.
376
+ context.sent = context._sent = context.arg;
377
+
378
+ } else if (context.method === "throw") {
379
+ if (state === GenStateSuspendedStart) {
380
+ state = GenStateCompleted;
381
+ throw context.arg;
382
+ }
383
+
384
+ context.dispatchException(context.arg);
385
+
386
+ } else if (context.method === "return") {
387
+ context.abrupt("return", context.arg);
388
+ }
389
+
390
+ state = GenStateExecuting;
391
+
392
+ var record = tryCatch(innerFn, self, context);
393
+ if (record.type === "normal") {
394
+ // If an exception is thrown from innerFn, we leave state ===
395
+ // GenStateExecuting and loop back for another invocation.
396
+ state = context.done
397
+ ? GenStateCompleted
398
+ : GenStateSuspendedYield;
399
+
400
+ if (record.arg === ContinueSentinel) {
401
+ continue;
402
+ }
403
+
404
+ return {
405
+ value: record.arg,
406
+ done: context.done
407
+ };
408
+
409
+ } else if (record.type === "throw") {
410
+ state = GenStateCompleted;
411
+ // Dispatch the exception by looping back around to the
412
+ // context.dispatchException(context.arg) call above.
413
+ context.method = "throw";
414
+ context.arg = record.arg;
415
+ }
416
+ }
417
+ };
418
+ }
419
+
420
+ // Call delegate.iterator[context.method](context.arg) and handle the
421
+ // result, either by returning a { value, done } result from the
422
+ // delegate iterator, or by modifying context.method and context.arg,
423
+ // setting context.delegate to null, and returning the ContinueSentinel.
424
+ function maybeInvokeDelegate(delegate, context) {
425
+ var method = delegate.iterator[context.method];
426
+ if (method === undefined$1) {
427
+ // A .throw or .return when the delegate iterator has no .throw
428
+ // method always terminates the yield* loop.
429
+ context.delegate = null;
430
+
431
+ if (context.method === "throw") {
432
+ // Note: ["return"] must be used for ES3 parsing compatibility.
433
+ if (delegate.iterator["return"]) {
434
+ // If the delegate iterator has a return method, give it a
435
+ // chance to clean up.
436
+ context.method = "return";
437
+ context.arg = undefined$1;
438
+ maybeInvokeDelegate(delegate, context);
439
+
440
+ if (context.method === "throw") {
441
+ // If maybeInvokeDelegate(context) changed context.method from
442
+ // "return" to "throw", let that override the TypeError below.
443
+ return ContinueSentinel;
444
+ }
445
+ }
446
+
447
+ context.method = "throw";
448
+ context.arg = new TypeError(
449
+ "The iterator does not provide a 'throw' method");
450
+ }
451
+
452
+ return ContinueSentinel;
453
+ }
454
+
455
+ var record = tryCatch(method, delegate.iterator, context.arg);
456
+
457
+ if (record.type === "throw") {
458
+ context.method = "throw";
459
+ context.arg = record.arg;
460
+ context.delegate = null;
461
+ return ContinueSentinel;
462
+ }
463
+
464
+ var info = record.arg;
465
+
466
+ if (! info) {
467
+ context.method = "throw";
468
+ context.arg = new TypeError("iterator result is not an object");
469
+ context.delegate = null;
470
+ return ContinueSentinel;
471
+ }
472
+
473
+ if (info.done) {
474
+ // Assign the result of the finished delegate to the temporary
475
+ // variable specified by delegate.resultName (see delegateYield).
476
+ context[delegate.resultName] = info.value;
477
+
478
+ // Resume execution at the desired location (see delegateYield).
479
+ context.next = delegate.nextLoc;
480
+
481
+ // If context.method was "throw" but the delegate handled the
482
+ // exception, let the outer generator proceed normally. If
483
+ // context.method was "next", forget context.arg since it has been
484
+ // "consumed" by the delegate iterator. If context.method was
485
+ // "return", allow the original .return call to continue in the
486
+ // outer generator.
487
+ if (context.method !== "return") {
488
+ context.method = "next";
489
+ context.arg = undefined$1;
490
+ }
491
+
492
+ } else {
493
+ // Re-yield the result returned by the delegate method.
494
+ return info;
495
+ }
496
+
497
+ // The delegate iterator is finished, so forget it and continue with
498
+ // the outer generator.
499
+ context.delegate = null;
500
+ return ContinueSentinel;
501
+ }
502
+
503
+ // Define Generator.prototype.{next,throw,return} in terms of the
504
+ // unified ._invoke helper method.
505
+ defineIteratorMethods(Gp);
506
+
507
+ define(Gp, toStringTagSymbol, "Generator");
508
+
509
+ // A Generator should always return itself as the iterator object when the
510
+ // @@iterator function is called on it. Some browsers' implementations of the
511
+ // iterator prototype chain incorrectly implement this, causing the Generator
512
+ // object to not be returned from this call. This ensures that doesn't happen.
513
+ // See https://github.com/facebook/regenerator/issues/274 for more details.
514
+ define(Gp, iteratorSymbol, function() {
515
+ return this;
516
+ });
517
+
518
+ define(Gp, "toString", function() {
519
+ return "[object Generator]";
520
+ });
521
+
522
+ function pushTryEntry(locs) {
523
+ var entry = { tryLoc: locs[0] };
524
+
525
+ if (1 in locs) {
526
+ entry.catchLoc = locs[1];
527
+ }
528
+
529
+ if (2 in locs) {
530
+ entry.finallyLoc = locs[2];
531
+ entry.afterLoc = locs[3];
532
+ }
533
+
534
+ this.tryEntries.push(entry);
535
+ }
536
+
537
+ function resetTryEntry(entry) {
538
+ var record = entry.completion || {};
539
+ record.type = "normal";
540
+ delete record.arg;
541
+ entry.completion = record;
542
+ }
543
+
544
+ function Context(tryLocsList) {
545
+ // The root entry object (effectively a try statement without a catch
546
+ // or a finally block) gives us a place to store values thrown from
547
+ // locations where there is no enclosing try statement.
548
+ this.tryEntries = [{ tryLoc: "root" }];
549
+ tryLocsList.forEach(pushTryEntry, this);
550
+ this.reset(true);
551
+ }
552
+
553
+ exports.keys = function(object) {
554
+ var keys = [];
555
+ for (var key in object) {
556
+ keys.push(key);
557
+ }
558
+ keys.reverse();
559
+
560
+ // Rather than returning an object with a next method, we keep
561
+ // things simple and return the next function itself.
562
+ return function next() {
563
+ while (keys.length) {
564
+ var key = keys.pop();
565
+ if (key in object) {
566
+ next.value = key;
567
+ next.done = false;
568
+ return next;
569
+ }
570
+ }
571
+
572
+ // To avoid creating an additional object, we just hang the .value
573
+ // and .done properties off the next function object itself. This
574
+ // also ensures that the minifier will not anonymize the function.
575
+ next.done = true;
576
+ return next;
577
+ };
578
+ };
579
+
580
+ function values(iterable) {
581
+ if (iterable) {
582
+ var iteratorMethod = iterable[iteratorSymbol];
583
+ if (iteratorMethod) {
584
+ return iteratorMethod.call(iterable);
585
+ }
586
+
587
+ if (typeof iterable.next === "function") {
588
+ return iterable;
589
+ }
590
+
591
+ if (!isNaN(iterable.length)) {
592
+ var i = -1, next = function next() {
593
+ while (++i < iterable.length) {
594
+ if (hasOwn.call(iterable, i)) {
595
+ next.value = iterable[i];
596
+ next.done = false;
597
+ return next;
598
+ }
599
+ }
600
+
601
+ next.value = undefined$1;
602
+ next.done = true;
603
+
604
+ return next;
605
+ };
606
+
607
+ return next.next = next;
608
+ }
609
+ }
610
+
611
+ // Return an iterator with no values.
612
+ return { next: doneResult };
613
+ }
614
+ exports.values = values;
615
+
616
+ function doneResult() {
617
+ return { value: undefined$1, done: true };
618
+ }
619
+
620
+ Context.prototype = {
621
+ constructor: Context,
622
+
623
+ reset: function(skipTempReset) {
624
+ this.prev = 0;
625
+ this.next = 0;
626
+ // Resetting context._sent for legacy support of Babel's
627
+ // function.sent implementation.
628
+ this.sent = this._sent = undefined$1;
629
+ this.done = false;
630
+ this.delegate = null;
631
+
632
+ this.method = "next";
633
+ this.arg = undefined$1;
634
+
635
+ this.tryEntries.forEach(resetTryEntry);
636
+
637
+ if (!skipTempReset) {
638
+ for (var name in this) {
639
+ // Not sure about the optimal order of these conditions:
640
+ if (name.charAt(0) === "t" &&
641
+ hasOwn.call(this, name) &&
642
+ !isNaN(+name.slice(1))) {
643
+ this[name] = undefined$1;
644
+ }
645
+ }
646
+ }
647
+ },
648
+
649
+ stop: function() {
650
+ this.done = true;
651
+
652
+ var rootEntry = this.tryEntries[0];
653
+ var rootRecord = rootEntry.completion;
654
+ if (rootRecord.type === "throw") {
655
+ throw rootRecord.arg;
656
+ }
657
+
658
+ return this.rval;
659
+ },
660
+
661
+ dispatchException: function(exception) {
662
+ if (this.done) {
663
+ throw exception;
664
+ }
665
+
666
+ var context = this;
667
+ function handle(loc, caught) {
668
+ record.type = "throw";
669
+ record.arg = exception;
670
+ context.next = loc;
671
+
672
+ if (caught) {
673
+ // If the dispatched exception was caught by a catch block,
674
+ // then let that catch block handle the exception normally.
675
+ context.method = "next";
676
+ context.arg = undefined$1;
677
+ }
678
+
679
+ return !! caught;
680
+ }
681
+
682
+ for (var i = this.tryEntries.length - 1; i >= 0; --i) {
683
+ var entry = this.tryEntries[i];
684
+ var record = entry.completion;
685
+
686
+ if (entry.tryLoc === "root") {
687
+ // Exception thrown outside of any try block that could handle
688
+ // it, so set the completion value of the entire function to
689
+ // throw the exception.
690
+ return handle("end");
691
+ }
692
+
693
+ if (entry.tryLoc <= this.prev) {
694
+ var hasCatch = hasOwn.call(entry, "catchLoc");
695
+ var hasFinally = hasOwn.call(entry, "finallyLoc");
696
+
697
+ if (hasCatch && hasFinally) {
698
+ if (this.prev < entry.catchLoc) {
699
+ return handle(entry.catchLoc, true);
700
+ } else if (this.prev < entry.finallyLoc) {
701
+ return handle(entry.finallyLoc);
702
+ }
703
+
704
+ } else if (hasCatch) {
705
+ if (this.prev < entry.catchLoc) {
706
+ return handle(entry.catchLoc, true);
707
+ }
708
+
709
+ } else if (hasFinally) {
710
+ if (this.prev < entry.finallyLoc) {
711
+ return handle(entry.finallyLoc);
712
+ }
713
+
714
+ } else {
715
+ throw new Error("try statement without catch or finally");
716
+ }
717
+ }
718
+ }
719
+ },
720
+
721
+ abrupt: function(type, arg) {
722
+ for (var i = this.tryEntries.length - 1; i >= 0; --i) {
723
+ var entry = this.tryEntries[i];
724
+ if (entry.tryLoc <= this.prev &&
725
+ hasOwn.call(entry, "finallyLoc") &&
726
+ this.prev < entry.finallyLoc) {
727
+ var finallyEntry = entry;
728
+ break;
729
+ }
730
+ }
731
+
732
+ if (finallyEntry &&
733
+ (type === "break" ||
734
+ type === "continue") &&
735
+ finallyEntry.tryLoc <= arg &&
736
+ arg <= finallyEntry.finallyLoc) {
737
+ // Ignore the finally entry if control is not jumping to a
738
+ // location outside the try/catch block.
739
+ finallyEntry = null;
740
+ }
741
+
742
+ var record = finallyEntry ? finallyEntry.completion : {};
743
+ record.type = type;
744
+ record.arg = arg;
745
+
746
+ if (finallyEntry) {
747
+ this.method = "next";
748
+ this.next = finallyEntry.finallyLoc;
749
+ return ContinueSentinel;
750
+ }
751
+
752
+ return this.complete(record);
753
+ },
754
+
755
+ complete: function(record, afterLoc) {
756
+ if (record.type === "throw") {
757
+ throw record.arg;
758
+ }
759
+
760
+ if (record.type === "break" ||
761
+ record.type === "continue") {
762
+ this.next = record.arg;
763
+ } else if (record.type === "return") {
764
+ this.rval = this.arg = record.arg;
765
+ this.method = "return";
766
+ this.next = "end";
767
+ } else if (record.type === "normal" && afterLoc) {
768
+ this.next = afterLoc;
769
+ }
770
+
771
+ return ContinueSentinel;
772
+ },
773
+
774
+ finish: function(finallyLoc) {
775
+ for (var i = this.tryEntries.length - 1; i >= 0; --i) {
776
+ var entry = this.tryEntries[i];
777
+ if (entry.finallyLoc === finallyLoc) {
778
+ this.complete(entry.completion, entry.afterLoc);
779
+ resetTryEntry(entry);
780
+ return ContinueSentinel;
781
+ }
782
+ }
783
+ },
784
+
785
+ "catch": function(tryLoc) {
786
+ for (var i = this.tryEntries.length - 1; i >= 0; --i) {
787
+ var entry = this.tryEntries[i];
788
+ if (entry.tryLoc === tryLoc) {
789
+ var record = entry.completion;
790
+ if (record.type === "throw") {
791
+ var thrown = record.arg;
792
+ resetTryEntry(entry);
793
+ }
794
+ return thrown;
795
+ }
796
+ }
797
+
798
+ // The context.catch method must only be called with a location
799
+ // argument that corresponds to a known catch block.
800
+ throw new Error("illegal catch attempt");
801
+ },
802
+
803
+ delegateYield: function(iterable, resultName, nextLoc) {
804
+ this.delegate = {
805
+ iterator: values(iterable),
806
+ resultName: resultName,
807
+ nextLoc: nextLoc
808
+ };
809
+
810
+ if (this.method === "next") {
811
+ // Deliberately forget the last sent value so that we don't
812
+ // accidentally pass it on to the delegate.
813
+ this.arg = undefined$1;
814
+ }
815
+
816
+ return ContinueSentinel;
817
+ }
818
+ };
819
+
820
+ // Regardless of whether this script is executing as a CommonJS module
821
+ // or not, return the runtime object so that we can declare the variable
822
+ // regeneratorRuntime in the outer scope, which allows this module to be
823
+ // injected easily by `bin/regenerator --include-runtime script.js`.
824
+ return exports;
825
+
826
+ }(
827
+ // If this script is executing as a CommonJS module, use module.exports
828
+ // as the regeneratorRuntime namespace. Otherwise create a new empty
829
+ // object. Either way, the resulting object will be used to initialize
830
+ // the regeneratorRuntime variable at the top of this file.
831
+ module.exports
832
+ ));
833
+
834
+ try {
835
+ regeneratorRuntime = runtime;
836
+ } catch (accidentalStrictMode) {
837
+ // This module should not be running in strict mode, so the above
838
+ // assignment should always work unless something is misconfigured. Just
839
+ // in case runtime.js accidentally runs in strict mode, in modern engines
840
+ // we can explicitly access globalThis. In older engines we can escape
841
+ // strict mode using a global Function call. This could conceivably fail
842
+ // if a Content Security Policy forbids using Function, but in that case
843
+ // the proper solution is to fix the accidental strict mode problem. If
844
+ // you've misconfigured your bundler to force strict mode and applied a
845
+ // CSP to forbid Function, and you're not willing to fix either of those
846
+ // problems, please detail your unique predicament in a GitHub issue.
847
+ if (typeof globalThis === "object") {
848
+ globalThis.regeneratorRuntime = runtime;
849
+ } else {
850
+ Function("r", "regeneratorRuntime = r")(runtime);
851
+ }
852
+ }
853
+ });
854
+
855
+ function queryParamsToApi(params) {
856
+ return {
857
+ where: params.where,
858
+ limit: params.limit,
859
+ order: [{
860
+ field: params.orderBy,
861
+ dir: params.desc ? "desc" : "asc"
862
+ }]
863
+ };
864
+ }
865
+
866
+ var API = /*#__PURE__*/function () {
867
+ function API(config) {
868
+ this.config = config;
869
+ }
870
+
871
+ var _proto = API.prototype;
872
+
873
+ _proto.get = /*#__PURE__*/function () {
874
+ var _get = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(endpoint, params) {
875
+ var url, response;
876
+ return runtime_1.wrap(function _callee$(_context) {
877
+ while (1) {
878
+ switch (_context.prev = _context.next) {
879
+ case 0:
880
+ if (params === void 0) {
881
+ params = {};
882
+ }
883
+
884
+ url = new URL(this.config.host + "/api/v1/cms/databases/" + this.config.databaseId + endpoint);
885
+ url.search = new URLSearchParams(params).toString();
886
+ _context.next = 5;
887
+ return fetch(url.toString(), {
888
+ method: "GET",
889
+ headers: {
890
+ accept: "*/*",
891
+ "x-plasmic-api-project-tokens": this.config.projectId + ":" + this.config.projectApiToken
892
+ },
893
+ mode: "cors"
894
+ });
895
+
896
+ case 5:
897
+ response = _context.sent;
898
+ _context.next = 8;
899
+ return response.json();
900
+
901
+ case 8:
902
+ return _context.abrupt("return", _context.sent);
903
+
904
+ case 9:
905
+ case "end":
906
+ return _context.stop();
907
+ }
908
+ }
909
+ }, _callee, this);
910
+ }));
911
+
912
+ function get(_x, _x2) {
913
+ return _get.apply(this, arguments);
914
+ }
915
+
916
+ return get;
917
+ }();
918
+
919
+ _proto.fetchTables = /*#__PURE__*/function () {
920
+ var _fetchTables = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2() {
921
+ var response;
922
+ return runtime_1.wrap(function _callee2$(_context2) {
923
+ while (1) {
924
+ switch (_context2.prev = _context2.next) {
925
+ case 0:
926
+ _context2.prev = 0;
927
+ _context2.next = 3;
928
+ return this.get("");
929
+
930
+ case 3:
931
+ response = _context2.sent;
932
+ return _context2.abrupt("return", response.tables);
933
+
934
+ case 7:
935
+ _context2.prev = 7;
936
+ _context2.t0 = _context2["catch"](0);
937
+ console.error(_context2.t0);
938
+ throw new Error("Cannot fetch CMS models.");
939
+
940
+ case 11:
941
+ case "end":
942
+ return _context2.stop();
943
+ }
944
+ }
945
+ }, _callee2, this, [[0, 7]]);
946
+ }));
947
+
948
+ function fetchTables() {
949
+ return _fetchTables.apply(this, arguments);
950
+ }
951
+
952
+ return fetchTables;
953
+ }();
954
+
955
+ _proto.query = /*#__PURE__*/function () {
956
+ var _query = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3(table, params) {
957
+ var response;
958
+ return runtime_1.wrap(function _callee3$(_context3) {
959
+ while (1) {
960
+ switch (_context3.prev = _context3.next) {
961
+ case 0:
962
+ _context3.prev = 0;
963
+ _context3.next = 3;
964
+ return this.get("/tables/" + table + "/query", {
965
+ q: JSON.stringify(queryParamsToApi(params)),
966
+ useDraft: Number(params.useDraft)
967
+ });
968
+
969
+ case 3:
970
+ response = _context3.sent;
971
+ return _context3.abrupt("return", response.rows);
972
+
973
+ case 7:
974
+ _context3.prev = 7;
975
+ _context3.t0 = _context3["catch"](0);
976
+ console.error(_context3.t0);
977
+ throw new Error("Query returned invalid response.");
978
+
979
+ case 11:
980
+ case "end":
981
+ return _context3.stop();
982
+ }
983
+ }
984
+ }, _callee3, this, [[0, 7]]);
985
+ }));
986
+
987
+ function query(_x3, _x4) {
988
+ return _query.apply(this, arguments);
989
+ }
990
+
991
+ return query;
992
+ }();
993
+
994
+ _proto.fetchRow = /*#__PURE__*/function () {
995
+ var _fetchRow = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee4(table, row, useDraft) {
996
+ var maybeUseDraft, response;
997
+ return runtime_1.wrap(function _callee4$(_context4) {
998
+ while (1) {
999
+ switch (_context4.prev = _context4.next) {
1000
+ case 0:
1001
+ _context4.prev = 0;
1002
+ maybeUseDraft = useDraft ? "?useDraft=1" : "";
1003
+ _context4.next = 4;
1004
+ return this.get("/tables/" + table + "/rows/" + row + maybeUseDraft);
1005
+
1006
+ case 4:
1007
+ response = _context4.sent;
1008
+ return _context4.abrupt("return", response);
1009
+
1010
+ case 8:
1011
+ _context4.prev = 8;
1012
+ _context4.t0 = _context4["catch"](0);
1013
+ console.error(_context4.t0);
1014
+ throw new Error("Query returned invalid response.");
1015
+
1016
+ case 12:
1017
+ case "end":
1018
+ return _context4.stop();
1019
+ }
1020
+ }
1021
+ }, _callee4, this, [[0, 8]]);
1022
+ }));
1023
+
1024
+ function fetchRow(_x5, _x6, _x7) {
1025
+ return _fetchRow.apply(this, arguments);
1026
+ }
1027
+
1028
+ return fetchRow;
1029
+ }();
1030
+
1031
+ return API;
1032
+ }();
1033
+
1034
+ function mkApi(config) {
1035
+ if (!config) {
1036
+ throw new Error("Component must be wrapped in 'CMS Data Provider'.");
1037
+ }
1038
+
1039
+ return new API(config);
1040
+ }
1041
+
1042
+ var contextPrefix = "__plasmic_cms";
1043
+ var databaseContextKey = contextPrefix + "_database";
1044
+ var tablesContextKey = contextPrefix + "_tables";
1045
+ var queryResultPrefix = contextPrefix + "_query_";
1046
+
1047
+ var mkQueryContextKey = function mkQueryContextKey(table) {
1048
+ return "" + queryResultPrefix + table;
1049
+ };
1050
+
1051
+ var rowContextPrefix = contextPrefix + "_row_";
1052
+
1053
+ var mkRowContextKey = function mkRowContextKey(table) {
1054
+ return "" + rowContextPrefix + table;
1055
+ };
1056
+
1057
+ function useDatabase() {
1058
+ return useSelector(databaseContextKey);
1059
+ }
1060
+ function DatabaseProvider(_ref) {
1061
+ var config = _ref.config,
1062
+ children = _ref.children;
1063
+ return React.createElement(DataProvider, {
1064
+ name: databaseContextKey,
1065
+ data: config
1066
+ }, children);
1067
+ }
1068
+ function useTables() {
1069
+ return useSelector(tablesContextKey);
1070
+ }
1071
+ function TablesProvider(_ref2) {
1072
+ var children = _ref2.children,
1073
+ tables = _ref2.tables;
1074
+ return React.createElement(DataProvider, {
1075
+ name: tablesContextKey,
1076
+ data: tables
1077
+ }, children);
1078
+ }
1079
+ function useQueryResults(table) {
1080
+ var env = useDataEnv();
1081
+ var tables = useTables();
1082
+
1083
+ if (!env) {
1084
+ return undefined;
1085
+ }
1086
+
1087
+ if (table) {
1088
+ var _env$mkQueryContextKe;
1089
+
1090
+ return {
1091
+ table: table,
1092
+ rows: (_env$mkQueryContextKe = env[mkQueryContextKey(table)]) != null ? _env$mkQueryContextKe : []
1093
+ };
1094
+ }
1095
+
1096
+ if (!tables) {
1097
+ return undefined;
1098
+ }
1099
+
1100
+ var matchingKeys = getClosestMatchingKeys(env, queryResultPrefix);
1101
+
1102
+ var _loop = function _loop() {
1103
+ var key = _step.value;
1104
+ var inferredTable = tables.find(function (t) {
1105
+ return mkQueryContextKey(t.identifier) === key;
1106
+ });
1107
+
1108
+ if (inferredTable) {
1109
+ var _env$key;
1110
+
1111
+ return {
1112
+ v: {
1113
+ table: inferredTable.identifier,
1114
+ rows: (_env$key = env[key]) != null ? _env$key : []
1115
+ }
1116
+ };
1117
+ }
1118
+ };
1119
+
1120
+ for (var _iterator = _createForOfIteratorHelperLoose(matchingKeys), _step; !(_step = _iterator()).done;) {
1121
+ var _ret = _loop();
1122
+
1123
+ if (typeof _ret === "object") return _ret.v;
1124
+ }
1125
+
1126
+ return undefined;
1127
+ }
1128
+
1129
+ function getClosestMatchingKeys(env, prefix) {
1130
+ return [].concat(Object.keys(env).reverse()).filter(function (k) {
1131
+ return k.startsWith(prefix);
1132
+ });
1133
+ }
1134
+
1135
+ function QueryResultProvider(_ref3) {
1136
+ var children = _ref3.children,
1137
+ table = _ref3.table,
1138
+ rows = _ref3.rows;
1139
+ return React.createElement(DataProvider, {
1140
+ name: mkQueryContextKey(table),
1141
+ data: rows
1142
+ }, children);
1143
+ }
1144
+ function useRow(table) {
1145
+ var env = useDataEnv();
1146
+ var tables = useTables();
1147
+
1148
+ if (!env) {
1149
+ return undefined;
1150
+ }
1151
+
1152
+ if (table) {
1153
+ return {
1154
+ table: table,
1155
+ row: env[mkRowContextKey(table)]
1156
+ };
1157
+ }
1158
+
1159
+ if (!tables) {
1160
+ return undefined;
1161
+ }
1162
+
1163
+ var matchingKeys = getClosestMatchingKeys(env, rowContextPrefix);
1164
+
1165
+ var _loop2 = function _loop2() {
1166
+ var key = _step2.value;
1167
+ var inferredTable = tables.find(function (t) {
1168
+ return mkRowContextKey(t.identifier) === key;
1169
+ });
1170
+
1171
+ if (inferredTable) {
1172
+ return {
1173
+ v: {
1174
+ table: inferredTable.identifier,
1175
+ row: env[key]
1176
+ }
1177
+ };
1178
+ }
1179
+ };
1180
+
1181
+ for (var _iterator2 = _createForOfIteratorHelperLoose(matchingKeys), _step2; !(_step2 = _iterator2()).done;) {
1182
+ var _ret2 = _loop2();
1183
+
1184
+ if (typeof _ret2 === "object") return _ret2.v;
1185
+ }
1186
+
1187
+ return undefined;
1188
+ }
1189
+ function RowProvider(_ref4) {
1190
+ var children = _ref4.children,
1191
+ table = _ref4.table,
1192
+ row = _ref4.row;
1193
+ return React.createElement(DataProvider, {
1194
+ name: mkRowContextKey(table),
1195
+ data: row
1196
+ }, children);
1197
+ }
1198
+
1199
+ function mkTableOptions(tables) {
1200
+ if (!tables) {
1201
+ return [];
1202
+ }
1203
+
1204
+ return tables.map(function (table) {
1205
+ return {
1206
+ value: table.identifier,
1207
+ label: table.name
1208
+ };
1209
+ });
1210
+ }
1211
+ function mkFieldOptions(tables, tableId) {
1212
+ if (!tables) {
1213
+ return [];
1214
+ }
1215
+
1216
+ var table = tables.find(function (t) {
1217
+ return t.identifier === tableId;
1218
+ });
1219
+
1220
+ if (!table) {
1221
+ return [];
1222
+ }
1223
+
1224
+ return table.schema.fields.map(function (f) {
1225
+ return {
1226
+ value: f.identifier,
1227
+ label: f.name
1228
+ };
1229
+ });
1230
+ }
1231
+
1232
+ var _excluded = ["children"],
1233
+ _excluded2 = ["table", "children", "setControlContextData"];
1234
+ var modulePath = "@plasmicpkgs/plasmic-cms";
1235
+ var componentPrefix = "hostless-plasmic-cms";
1236
+
1237
+ function renderMaybeData(maybeData, renderFn) {
1238
+ if ("error" in maybeData) {
1239
+ var _maybeData$error;
1240
+
1241
+ return React.createElement("div", null, "Error: ", (_maybeData$error = maybeData.error) == null ? void 0 : _maybeData$error.message);
1242
+ }
1243
+
1244
+ if (!("data" in maybeData)) {
1245
+ return React.createElement("div", null, "Loading...");
1246
+ }
1247
+
1248
+ return renderFn(maybeData.data);
1249
+ }
1250
+
1251
+ var defaultHost = "https://studio.plasmic.app"; // TODO: Remove `children` from props and make cmsDataProviderMeta a
1252
+ // ContextMeta.
1253
+
1254
+ var cmsDataProviderMeta = {
1255
+ name: componentPrefix + "-data-provider",
1256
+ displayName: "CMS Data Provider",
1257
+ importName: "CmsDataProvider",
1258
+ importPath: modulePath,
1259
+ props: {
1260
+ host: {
1261
+ type: "string",
1262
+ displayName: "Studio URL",
1263
+ description: "The default host for use in production is " + defaultHost + ".",
1264
+ defaultValue: defaultHost,
1265
+ defaultValueHint: defaultHost
1266
+ },
1267
+ databaseId: {
1268
+ type: "string",
1269
+ displayName: "CMS ID",
1270
+ description: "The ID of the CMS (database) to use."
1271
+ },
1272
+ projectId: {
1273
+ type: "string",
1274
+ displayName: "Project ID",
1275
+ description: "This project's ID."
1276
+ },
1277
+ projectApiToken: {
1278
+ type: "string",
1279
+ displayName: "Project API token",
1280
+ description: "This project's API token."
1281
+ },
1282
+ children: {
1283
+ type: "slot",
1284
+ defaultValue: {
1285
+ type: "vbox",
1286
+ children: []
1287
+ }
1288
+ }
1289
+ }
1290
+ };
1291
+ function CmsDataProvider(_ref) {
1292
+ var children = _ref.children,
1293
+ config = _objectWithoutPropertiesLoose(_ref, _excluded);
1294
+
1295
+ config.host = config.host || defaultHost;
1296
+ return React.createElement(DatabaseProvider, {
1297
+ config: config
1298
+ }, React.createElement(TablesFetcher, null, children));
1299
+ }
1300
+
1301
+ function TablesFetcher(_ref2) {
1302
+ var children = _ref2.children;
1303
+ var databaseConfig = useDatabase();
1304
+ var cacheKey = JSON.stringify({
1305
+ component: "TablesFetcher",
1306
+ databaseConfig: databaseConfig
1307
+ });
1308
+ var maybeData = usePlasmicQueryData(cacheKey, /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee() {
1309
+ return runtime_1.wrap(function _callee$(_context) {
1310
+ while (1) {
1311
+ switch (_context.prev = _context.next) {
1312
+ case 0:
1313
+ return _context.abrupt("return", mkApi(databaseConfig).fetchTables());
1314
+
1315
+ case 1:
1316
+ case "end":
1317
+ return _context.stop();
1318
+ }
1319
+ }
1320
+ }, _callee);
1321
+ })));
1322
+ return renderMaybeData(maybeData, function (tables) {
1323
+ return React.createElement(TablesProvider, {
1324
+ tables: tables
1325
+ }, children);
1326
+ });
1327
+ }
1328
+
1329
+ var cmsQueryLoaderMeta = {
1330
+ name: componentPrefix + "-query-loader",
1331
+ displayName: "CMS Query Loader",
1332
+ importName: "CmsQueryLoader",
1333
+ importPath: modulePath,
1334
+ props: {
1335
+ children: {
1336
+ type: "slot",
1337
+ defaultValue: {
1338
+ type: "component",
1339
+ name: componentPrefix + "-row-repeater"
1340
+ }
1341
+ },
1342
+ table: {
1343
+ type: "choice",
1344
+ displayName: "Model",
1345
+ description: "CMS model (table) to query.",
1346
+ options: function options(_, ctx) {
1347
+ return mkTableOptions(ctx == null ? void 0 : ctx.tables);
1348
+ }
1349
+ },
1350
+ useDraft: {
1351
+ type: "boolean",
1352
+ displayName: "Use drafts?",
1353
+ description: "If set, also query unpublished content.",
1354
+ defaultValue: false
1355
+ },
1356
+ where: {
1357
+ type: "object",
1358
+ displayName: "Filter",
1359
+ description: "Filter clause, in JSON format."
1360
+ },
1361
+ orderBy: {
1362
+ type: "choice",
1363
+ displayName: "Order by",
1364
+ description: "Field to order by.",
1365
+ options: function options(_ref4, ctx) {
1366
+ var table = _ref4.table;
1367
+ return mkFieldOptions(ctx == null ? void 0 : ctx.tables, table);
1368
+ }
1369
+ },
1370
+ desc: {
1371
+ type: "boolean",
1372
+ displayName: "Sort descending?",
1373
+ description: 'Sort descending by "Order by" field.',
1374
+ defaultValue: false
1375
+ },
1376
+ limit: {
1377
+ type: "number",
1378
+ displayName: "Limit",
1379
+ description: "Maximum number of entries to fetch (0 for unlimited).",
1380
+ defaultValue: 0
1381
+ }
1382
+ }
1383
+ };
1384
+ function CmsQueryLoader(_ref5) {
1385
+ var table = _ref5.table,
1386
+ children = _ref5.children,
1387
+ setControlContextData = _ref5.setControlContextData,
1388
+ params = _objectWithoutPropertiesLoose(_ref5, _excluded2);
1389
+
1390
+ var databaseConfig = useDatabase();
1391
+ var tables = useTables();
1392
+
1393
+ if (tables) {
1394
+ // TODO: Only include table if __plasmic_cms_row_{table} exists.
1395
+ setControlContextData == null ? void 0 : setControlContextData({
1396
+ tables: tables
1397
+ });
1398
+ }
1399
+
1400
+ var cacheKey = JSON.stringify({
1401
+ component: "CmsQueryLoader",
1402
+ table: table,
1403
+ databaseConfig: databaseConfig,
1404
+ params: params
1405
+ });
1406
+ var maybeData = usePlasmicQueryData(cacheKey, /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2() {
1407
+ return runtime_1.wrap(function _callee2$(_context2) {
1408
+ while (1) {
1409
+ switch (_context2.prev = _context2.next) {
1410
+ case 0:
1411
+ if (table) {
1412
+ _context2.next = 4;
1413
+ break;
1414
+ }
1415
+
1416
+ throw new Error("You must select a table to query");
1417
+
1418
+ case 4:
1419
+ if (!(tables && !tables.find(function (t) {
1420
+ return t.identifier === table;
1421
+ }))) {
1422
+ _context2.next = 6;
1423
+ break;
1424
+ }
1425
+
1426
+ throw new Error("There is no table called \"" + table + "\"");
1427
+
1428
+ case 6:
1429
+ return _context2.abrupt("return", mkApi(databaseConfig).query(table, params));
1430
+
1431
+ case 7:
1432
+ case "end":
1433
+ return _context2.stop();
1434
+ }
1435
+ }
1436
+ }, _callee2);
1437
+ })));
1438
+ return renderMaybeData(maybeData, function (rows) {
1439
+ return React.createElement(QueryResultProvider, {
1440
+ table: table,
1441
+ rows: rows
1442
+ }, children);
1443
+ });
1444
+ }
1445
+ var cmsRowRepeaterMeta = {
1446
+ name: componentPrefix + "-row-repeater",
1447
+ displayName: "CMS Row Repeater",
1448
+ importName: "CmsRowRepeater",
1449
+ importPath: modulePath,
1450
+ props: {
1451
+ children: {
1452
+ type: "slot",
1453
+ defaultValue: {
1454
+ type: "component",
1455
+ name: componentPrefix + "-row-field"
1456
+ }
1457
+ },
1458
+ table: {
1459
+ type: "choice",
1460
+ displayName: "Model",
1461
+ description: "CMS model (table) to use.",
1462
+ options: function options(_, ctx) {
1463
+ return mkTableOptions(ctx == null ? void 0 : ctx.tables);
1464
+ }
1465
+ }
1466
+ }
1467
+ };
1468
+ function CmsRowRepeater(_ref7) {
1469
+ var table = _ref7.table,
1470
+ children = _ref7.children,
1471
+ setControlContextData = _ref7.setControlContextData;
1472
+ var tables = useTables();
1473
+
1474
+ if (tables) {
1475
+ setControlContextData == null ? void 0 : setControlContextData({
1476
+ tables: tables
1477
+ });
1478
+ }
1479
+
1480
+ var res = useQueryResults(table);
1481
+
1482
+ if (!res) {
1483
+ return React.createElement("div", null, "Error: No CMS query result to repeat.");
1484
+ }
1485
+
1486
+ return React.createElement(React.Fragment, null, res.rows.map(function (row, index) {
1487
+ return React.createElement(RowProvider, {
1488
+ table: res.table,
1489
+ row: row
1490
+ }, repeatedElement(index === 0, children));
1491
+ }));
1492
+ }
1493
+ var cmsRowFieldMeta = {
1494
+ name: componentPrefix + "-row-field",
1495
+ displayName: "CMS Row Field",
1496
+ importName: "CmsRowField",
1497
+ importPath: modulePath,
1498
+ props: {
1499
+ table: {
1500
+ type: "choice",
1501
+ displayName: "Model",
1502
+ description: "CMS model (table) to use.",
1503
+ options: function options(_, ctx) {
1504
+ return mkTableOptions(ctx == null ? void 0 : ctx.tables);
1505
+ }
1506
+ },
1507
+ field: {
1508
+ type: "choice",
1509
+ displayName: "Field",
1510
+ description: "Field (from model schema) to use.",
1511
+ options: function options(_ref8, ctx) {
1512
+ var _ctx$table;
1513
+
1514
+ var table = _ref8.table;
1515
+ return mkFieldOptions(ctx == null ? void 0 : ctx.tables, (_ctx$table = ctx == null ? void 0 : ctx.table) != null ? _ctx$table : table);
1516
+ }
1517
+ }
1518
+ }
1519
+ };
1520
+ function CmsRowField(_ref9) {
1521
+ var _tables$find, _res$row$data;
1522
+
1523
+ var className = _ref9.className,
1524
+ table = _ref9.table,
1525
+ field = _ref9.field,
1526
+ setControlContextData = _ref9.setControlContextData;
1527
+ var tables = useTables();
1528
+ var res = useRow(table);
1529
+
1530
+ if (!res || !res.row) {
1531
+ return React.createElement("div", null, "Error: No CMS Row found");
1532
+ }
1533
+
1534
+ if (tables) {
1535
+ // TODO: Only include table if __plasmic_cms_row_{table} exists.
1536
+ setControlContextData == null ? void 0 : setControlContextData({
1537
+ tables: tables,
1538
+ table: res.table
1539
+ });
1540
+ }
1541
+
1542
+ var schema = tables == null ? void 0 : (_tables$find = tables.find(function (t) {
1543
+ return t.identifier === res.table;
1544
+ })) == null ? void 0 : _tables$find.schema;
1545
+ var fieldMeta = field ? schema == null ? void 0 : schema.fields.find(function (f) {
1546
+ return f.identifier === field;
1547
+ }) : schema == null ? void 0 : schema.fields[0];
1548
+
1549
+ if (!fieldMeta) {
1550
+ return React.createElement("div", null, "Error: No field to display");
1551
+ }
1552
+
1553
+ var data = (_res$row$data = res.row.data) == null ? void 0 : _res$row$data[fieldMeta.identifier];
1554
+ return data ? renderValue(data, fieldMeta.type, {
1555
+ className: className
1556
+ }) : React.createElement("div", null, "(no data returned)");
1557
+ }
1558
+
1559
+ function assertNever(_) {
1560
+ throw new Error("unexpected branch taken");
1561
+ }
1562
+
1563
+ function renderValue(value, type, props) {
1564
+ switch (type) {
1565
+ case "number":
1566
+ case "boolean":
1567
+ case "text":
1568
+ case "long-text":
1569
+ case "date-time":
1570
+ return React.createElement("div", {
1571
+ className: props.className
1572
+ }, value);
1573
+
1574
+ case "image":
1575
+ if (value && typeof value === "object" && value.url && value.imageMeta) {
1576
+ return React.createElement("img", {
1577
+ src: value.url,
1578
+ width: value.imageMeta.height,
1579
+ height: value.imageMeta.height,
1580
+ className: props.className
1581
+ });
1582
+ }
1583
+
1584
+ return null;
1585
+
1586
+ default:
1587
+ assertNever();
1588
+ }
1589
+ }
1590
+
1591
+ var cmsRowLinkMeta = {
1592
+ name: componentPrefix + "-row-link",
1593
+ displayName: "CMS Row Link",
1594
+ importName: "CmsRowLink",
1595
+ importPath: modulePath,
1596
+ props: {
1597
+ children: {
1598
+ type: "slot",
1599
+ defaultValue: {
1600
+ type: "vbox",
1601
+ tag: "a",
1602
+ value: "Link"
1603
+ }
1604
+ },
1605
+ table: {
1606
+ type: "choice",
1607
+ displayName: "Model",
1608
+ description: "CMS model (table) to use.",
1609
+ options: function options(_, ctx) {
1610
+ return mkTableOptions(ctx == null ? void 0 : ctx.tables);
1611
+ }
1612
+ },
1613
+ field: {
1614
+ type: "choice",
1615
+ displayName: "Field",
1616
+ description: "Field (from model schema) to use.",
1617
+ options: function options(_ref10, ctx) {
1618
+ var _ctx$table2;
1619
+
1620
+ var table = _ref10.table;
1621
+ return mkFieldOptions(ctx == null ? void 0 : ctx.tables, (_ctx$table2 = ctx == null ? void 0 : ctx.table) != null ? _ctx$table2 : table);
1622
+ }
1623
+ },
1624
+ hrefProp: {
1625
+ type: "string",
1626
+ displayName: '"href" prop',
1627
+ description: "Prop to inject into children",
1628
+ defaultValue: "href"
1629
+ }
1630
+ }
1631
+ };
1632
+ function CmsRowLink(_ref11) {
1633
+ var _tables$find2, _res$row$data2;
1634
+
1635
+ var table = _ref11.table,
1636
+ field = _ref11.field,
1637
+ hrefProp = _ref11.hrefProp,
1638
+ children = _ref11.children,
1639
+ setControlContextData = _ref11.setControlContextData;
1640
+ var tables = useTables();
1641
+ var res = useRow(table);
1642
+
1643
+ if (!res || !res.row) {
1644
+ return React.createElement("div", null, "Error: No CMS row found");
1645
+ }
1646
+
1647
+ if (tables) {
1648
+ // TODO: Only include table if __plasmic_cms_row_{table} exists.
1649
+ setControlContextData == null ? void 0 : setControlContextData({
1650
+ tables: tables,
1651
+ table: res.table
1652
+ });
1653
+ }
1654
+
1655
+ var schema = tables == null ? void 0 : (_tables$find2 = tables.find(function (t) {
1656
+ return t.identifier === res.table;
1657
+ })) == null ? void 0 : _tables$find2.schema;
1658
+ var fieldMeta = field ? schema == null ? void 0 : schema.fields.find(function (f) {
1659
+ return f.identifier === field;
1660
+ }) : schema == null ? void 0 : schema.fields.find(function (f) {
1661
+ return f.type === "text";
1662
+ });
1663
+
1664
+ if (!fieldMeta) {
1665
+ return React.createElement("div", null, "Error: No field to display");
1666
+ }
1667
+
1668
+ var value = ((_res$row$data2 = res.row.data) == null ? void 0 : _res$row$data2[fieldMeta.identifier]) || "";
1669
+ var childrenWithProps = React.Children.map(children, function (child) {
1670
+ if (React.isValidElement(child)) {
1671
+ var _React$cloneElement;
1672
+
1673
+ return React.cloneElement(child, (_React$cloneElement = {}, _React$cloneElement[hrefProp] = value, _React$cloneElement));
1674
+ }
1675
+
1676
+ return child;
1677
+ });
1678
+ return React.createElement(React.Fragment, null, childrenWithProps);
1679
+ }
1680
+ var cmsRowLoaderMeta = {
1681
+ name: componentPrefix + "-row-loader",
1682
+ displayName: "CMS Row Loader",
1683
+ importName: "CmsRowLoader",
1684
+ importPath: modulePath,
1685
+ props: {
1686
+ children: {
1687
+ type: "slot",
1688
+ defaultValue: {
1689
+ type: "component",
1690
+ name: componentPrefix + "-row-field"
1691
+ }
1692
+ },
1693
+ row: {
1694
+ type: "string",
1695
+ displayName: "Entry ID",
1696
+ description: "Row identifier to query."
1697
+ },
1698
+ table: {
1699
+ type: "choice",
1700
+ displayName: "Model",
1701
+ description: "CMS model (table) to query.",
1702
+ options: function options(_, ctx) {
1703
+ return mkTableOptions(ctx == null ? void 0 : ctx.tables);
1704
+ }
1705
+ },
1706
+ useDraft: {
1707
+ type: "boolean",
1708
+ displayName: "Use drafts?",
1709
+ description: "If set, also query unpublished content.",
1710
+ defaultValue: false
1711
+ }
1712
+ }
1713
+ };
1714
+ function CmsRowLoader(_ref12) {
1715
+ var table = _ref12.table,
1716
+ row = _ref12.row,
1717
+ children = _ref12.children,
1718
+ useDraft = _ref12.useDraft,
1719
+ setControlContextData = _ref12.setControlContextData;
1720
+ var databaseConfig = useDatabase();
1721
+ var tables = useTables();
1722
+
1723
+ if (tables) {
1724
+ setControlContextData == null ? void 0 : setControlContextData({
1725
+ tables: tables
1726
+ });
1727
+ }
1728
+
1729
+ var cacheKey = JSON.stringify({
1730
+ component: "CmsRowLoader",
1731
+ table: table,
1732
+ row: row,
1733
+ databaseConfig: databaseConfig,
1734
+ useDraft: useDraft
1735
+ });
1736
+ var maybeData = usePlasmicQueryData(cacheKey, /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3() {
1737
+ return runtime_1.wrap(function _callee3$(_context3) {
1738
+ while (1) {
1739
+ switch (_context3.prev = _context3.next) {
1740
+ case 0:
1741
+ return _context3.abrupt("return", mkApi(databaseConfig).fetchRow(table, row, useDraft));
1742
+
1743
+ case 1:
1744
+ case "end":
1745
+ return _context3.stop();
1746
+ }
1747
+ }
1748
+ }, _callee3);
1749
+ })));
1750
+ return renderMaybeData(maybeData, function (row) {
1751
+ return React.createElement(RowProvider, {
1752
+ table: table,
1753
+ row: row
1754
+ }, children);
1755
+ });
1756
+ }
1757
+
1758
+ function registerAll(loader) {
1759
+ var _loader$registerCompo;
1760
+
1761
+ //const registerContext = loader?.registerContext ?? hostRegisterContext;
1762
+ //registerContext(CmsDataProvider, cmsDataProviderMeta);
1763
+ var registerComponent$1 = (_loader$registerCompo = loader == null ? void 0 : loader.registerComponent.bind(loader)) != null ? _loader$registerCompo : registerComponent;
1764
+ registerComponent$1(CmsDataProvider, cmsDataProviderMeta);
1765
+ registerComponent$1(CmsQueryLoader, cmsQueryLoaderMeta);
1766
+ registerComponent$1(CmsRowRepeater, cmsRowRepeaterMeta);
1767
+ registerComponent$1(CmsRowField, cmsRowFieldMeta);
1768
+ registerComponent$1(CmsRowLink, cmsRowLinkMeta);
1769
+ registerComponent$1(CmsRowLoader, cmsRowLoaderMeta);
1770
+ }
1771
+
1772
+ export { registerAll };
1773
+ //# sourceMappingURL=plasmic-cms.esm.js.map