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