@plasmicpkgs/plasmic-contentful 0.0.115 → 0.0.116

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,874 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
6
-
7
- var registerComponent = _interopDefault(require('@plasmicapp/host/registerComponent'));
8
- var registerGlobalContext = _interopDefault(require('@plasmicapp/host/registerGlobalContext'));
9
- var richTextHtmlRenderer = require('@contentful/rich-text-html-renderer');
10
- var host = require('@plasmicapp/host');
11
- var query = require('@plasmicapp/query');
12
- var changeCase = require('change-case');
13
- var get = _interopDefault(require('dlv'));
14
- var React = require('react');
15
- var React__default = _interopDefault(React);
16
-
17
- function _regeneratorRuntime() {
18
- _regeneratorRuntime = function () {
19
- return e;
20
- };
21
- var t,
22
- e = {},
23
- r = Object.prototype,
24
- n = r.hasOwnProperty,
25
- o = Object.defineProperty || function (t, e, r) {
26
- t[e] = r.value;
27
- },
28
- i = "function" == typeof Symbol ? Symbol : {},
29
- a = i.iterator || "@@iterator",
30
- c = i.asyncIterator || "@@asyncIterator",
31
- u = i.toStringTag || "@@toStringTag";
32
- function define(t, e, r) {
33
- return Object.defineProperty(t, e, {
34
- value: r,
35
- enumerable: !0,
36
- configurable: !0,
37
- writable: !0
38
- }), t[e];
39
- }
40
- try {
41
- define({}, "");
42
- } catch (t) {
43
- define = function (t, e, r) {
44
- return t[e] = r;
45
- };
46
- }
47
- function wrap(t, e, r, n) {
48
- var i = e && e.prototype instanceof Generator ? e : Generator,
49
- a = Object.create(i.prototype),
50
- c = new Context(n || []);
51
- return o(a, "_invoke", {
52
- value: makeInvokeMethod(t, r, c)
53
- }), a;
54
- }
55
- function tryCatch(t, e, r) {
56
- try {
57
- return {
58
- type: "normal",
59
- arg: t.call(e, r)
60
- };
61
- } catch (t) {
62
- return {
63
- type: "throw",
64
- arg: t
65
- };
66
- }
67
- }
68
- e.wrap = wrap;
69
- var h = "suspendedStart",
70
- l = "suspendedYield",
71
- f = "executing",
72
- s = "completed",
73
- y = {};
74
- function Generator() {}
75
- function GeneratorFunction() {}
76
- function GeneratorFunctionPrototype() {}
77
- var p = {};
78
- define(p, a, function () {
79
- return this;
80
- });
81
- var d = Object.getPrototypeOf,
82
- v = d && d(d(values([])));
83
- v && v !== r && n.call(v, a) && (p = v);
84
- var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p);
85
- function defineIteratorMethods(t) {
86
- ["next", "throw", "return"].forEach(function (e) {
87
- define(t, e, function (t) {
88
- return this._invoke(e, t);
89
- });
90
- });
91
- }
92
- function AsyncIterator(t, e) {
93
- function invoke(r, o, i, a) {
94
- var c = tryCatch(t[r], t, o);
95
- if ("throw" !== c.type) {
96
- var u = c.arg,
97
- h = u.value;
98
- return h && "object" == typeof h && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) {
99
- invoke("next", t, i, a);
100
- }, function (t) {
101
- invoke("throw", t, i, a);
102
- }) : e.resolve(h).then(function (t) {
103
- u.value = t, i(u);
104
- }, function (t) {
105
- return invoke("throw", t, i, a);
106
- });
107
- }
108
- a(c.arg);
109
- }
110
- var r;
111
- o(this, "_invoke", {
112
- value: function (t, n) {
113
- function callInvokeWithMethodAndArg() {
114
- return new e(function (e, r) {
115
- invoke(t, n, e, r);
116
- });
117
- }
118
- return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
119
- }
120
- });
121
- }
122
- function makeInvokeMethod(e, r, n) {
123
- var o = h;
124
- return function (i, a) {
125
- if (o === f) throw new Error("Generator is already running");
126
- if (o === s) {
127
- if ("throw" === i) throw a;
128
- return {
129
- value: t,
130
- done: !0
131
- };
132
- }
133
- for (n.method = i, n.arg = a;;) {
134
- var c = n.delegate;
135
- if (c) {
136
- var u = maybeInvokeDelegate(c, n);
137
- if (u) {
138
- if (u === y) continue;
139
- return u;
140
- }
141
- }
142
- if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) {
143
- if (o === h) throw o = s, n.arg;
144
- n.dispatchException(n.arg);
145
- } else "return" === n.method && n.abrupt("return", n.arg);
146
- o = f;
147
- var p = tryCatch(e, r, n);
148
- if ("normal" === p.type) {
149
- if (o = n.done ? s : l, p.arg === y) continue;
150
- return {
151
- value: p.arg,
152
- done: n.done
153
- };
154
- }
155
- "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg);
156
- }
157
- };
158
- }
159
- function maybeInvokeDelegate(e, r) {
160
- var n = r.method,
161
- o = e.iterator[n];
162
- if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y;
163
- var i = tryCatch(o, e.iterator, r.arg);
164
- if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y;
165
- var a = i.arg;
166
- return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y);
167
- }
168
- function pushTryEntry(t) {
169
- var e = {
170
- tryLoc: t[0]
171
- };
172
- 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e);
173
- }
174
- function resetTryEntry(t) {
175
- var e = t.completion || {};
176
- e.type = "normal", delete e.arg, t.completion = e;
177
- }
178
- function Context(t) {
179
- this.tryEntries = [{
180
- tryLoc: "root"
181
- }], t.forEach(pushTryEntry, this), this.reset(!0);
182
- }
183
- function values(e) {
184
- if (e || "" === e) {
185
- var r = e[a];
186
- if (r) return r.call(e);
187
- if ("function" == typeof e.next) return e;
188
- if (!isNaN(e.length)) {
189
- var o = -1,
190
- i = function next() {
191
- for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next;
192
- return next.value = t, next.done = !0, next;
193
- };
194
- return i.next = i;
195
- }
196
- }
197
- throw new TypeError(typeof e + " is not iterable");
198
- }
199
- return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", {
200
- value: GeneratorFunctionPrototype,
201
- configurable: !0
202
- }), o(GeneratorFunctionPrototype, "constructor", {
203
- value: GeneratorFunction,
204
- configurable: !0
205
- }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) {
206
- var e = "function" == typeof t && t.constructor;
207
- return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name));
208
- }, e.mark = function (t) {
209
- return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t;
210
- }, e.awrap = function (t) {
211
- return {
212
- __await: t
213
- };
214
- }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () {
215
- return this;
216
- }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) {
217
- void 0 === i && (i = Promise);
218
- var a = new AsyncIterator(wrap(t, r, n, o), i);
219
- return e.isGeneratorFunction(r) ? a : a.next().then(function (t) {
220
- return t.done ? t.value : a.next();
221
- });
222
- }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () {
223
- return this;
224
- }), define(g, "toString", function () {
225
- return "[object Generator]";
226
- }), e.keys = function (t) {
227
- var e = Object(t),
228
- r = [];
229
- for (var n in e) r.push(n);
230
- return r.reverse(), function next() {
231
- for (; r.length;) {
232
- var t = r.pop();
233
- if (t in e) return next.value = t, next.done = !1, next;
234
- }
235
- return next.done = !0, next;
236
- };
237
- }, e.values = values, Context.prototype = {
238
- constructor: Context,
239
- reset: function (e) {
240
- if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t);
241
- },
242
- stop: function () {
243
- this.done = !0;
244
- var t = this.tryEntries[0].completion;
245
- if ("throw" === t.type) throw t.arg;
246
- return this.rval;
247
- },
248
- dispatchException: function (e) {
249
- if (this.done) throw e;
250
- var r = this;
251
- function handle(n, o) {
252
- return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o;
253
- }
254
- for (var o = this.tryEntries.length - 1; o >= 0; --o) {
255
- var i = this.tryEntries[o],
256
- a = i.completion;
257
- if ("root" === i.tryLoc) return handle("end");
258
- if (i.tryLoc <= this.prev) {
259
- var c = n.call(i, "catchLoc"),
260
- u = n.call(i, "finallyLoc");
261
- if (c && u) {
262
- if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
263
- if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
264
- } else if (c) {
265
- if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
266
- } else {
267
- if (!u) throw new Error("try statement without catch or finally");
268
- if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
269
- }
270
- }
271
- }
272
- },
273
- abrupt: function (t, e) {
274
- for (var r = this.tryEntries.length - 1; r >= 0; --r) {
275
- var o = this.tryEntries[r];
276
- if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) {
277
- var i = o;
278
- break;
279
- }
280
- }
281
- i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null);
282
- var a = i ? i.completion : {};
283
- return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a);
284
- },
285
- complete: function (t, e) {
286
- if ("throw" === t.type) throw t.arg;
287
- return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y;
288
- },
289
- finish: function (t) {
290
- for (var e = this.tryEntries.length - 1; e >= 0; --e) {
291
- var r = this.tryEntries[e];
292
- if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y;
293
- }
294
- },
295
- catch: function (t) {
296
- for (var e = this.tryEntries.length - 1; e >= 0; --e) {
297
- var r = this.tryEntries[e];
298
- if (r.tryLoc === t) {
299
- var n = r.completion;
300
- if ("throw" === n.type) {
301
- var o = n.arg;
302
- resetTryEntry(r);
303
- }
304
- return o;
305
- }
306
- }
307
- throw new Error("illegal catch attempt");
308
- },
309
- delegateYield: function (e, r, n) {
310
- return this.delegate = {
311
- iterator: values(e),
312
- resultName: r,
313
- nextLoc: n
314
- }, "next" === this.method && (this.arg = t), y;
315
- }
316
- }, e;
317
- }
318
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
319
- try {
320
- var info = gen[key](arg);
321
- var value = info.value;
322
- } catch (error) {
323
- reject(error);
324
- return;
325
- }
326
- if (info.done) {
327
- resolve(value);
328
- } else {
329
- Promise.resolve(value).then(_next, _throw);
330
- }
331
- }
332
- function _asyncToGenerator(fn) {
333
- return function () {
334
- var self = this,
335
- args = arguments;
336
- return new Promise(function (resolve, reject) {
337
- var gen = fn.apply(self, args);
338
- function _next(value) {
339
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
340
- }
341
- function _throw(err) {
342
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
343
- }
344
- _next(undefined);
345
- });
346
- };
347
- }
348
- function _extends() {
349
- _extends = Object.assign ? Object.assign.bind() : function (target) {
350
- for (var i = 1; i < arguments.length; i++) {
351
- var source = arguments[i];
352
- for (var key in source) {
353
- if (Object.prototype.hasOwnProperty.call(source, key)) {
354
- target[key] = source[key];
355
- }
356
- }
357
- }
358
- return target;
359
- };
360
- return _extends.apply(this, arguments);
361
- }
362
-
363
- var searchParameters = [{
364
- value: "[lt]",
365
- label: "Less than"
366
- }, {
367
- value: "[lte]",
368
- label: "Less than or equal"
369
- }, {
370
- value: "[gt]",
371
- label: "Greater than"
372
- }, {
373
- value: "[gte]",
374
- label: "Greater than or equal "
375
- }];
376
- var uniq = function uniq(xs) {
377
- return Array.from(new Set(xs));
378
- };
379
-
380
- function ensure(x) {
381
- if (x === null || x === undefined) {
382
- throw new Error("Value must not be undefined or null");
383
- } else {
384
- return x;
385
- }
386
- }
387
- var modulePath = "@plasmicpkgs/plasmic-contentful";
388
- var makeDataProviderName = function makeDataProviderName(contentType) {
389
- return "currentContentful" + changeCase.pascalCase(contentType) + "Item";
390
- };
391
- var CredentialsContext = /*#__PURE__*/React__default.createContext(undefined);
392
- var ContentfulCredentialsProviderMeta = {
393
- name: "Contentful CredentialsProvider",
394
- displayName: "Contentful Credentials Provider",
395
- description: "Any client requesting content from the CDA needs to provide an access token that has access to the environment you're requesting content from. Learn how to [get your API key](https://www.contentful.com/developers/docs/references/authentication/).",
396
- importName: "ContentfulCredentialsProvider",
397
- importPath: modulePath,
398
- props: {
399
- space: {
400
- type: "string",
401
- displayName: "Space",
402
- description: "Name of your space",
403
- defaultValue: "lmfbwqzbh93n"
404
- },
405
- accessToken: {
406
- type: "string",
407
- displayName: "Access Token ",
408
- description: "Access Token",
409
- defaultValue: "aWvf6oSLTuqxKCxSUpokajdQr84hGQFE6zoJG7DVVLg"
410
- },
411
- environment: {
412
- type: "string",
413
- displayName: "Environment",
414
- defaultValue: "master"
415
- }
416
- }
417
- };
418
- function ContentfulCredentialsProvider(_ref) {
419
- var accessToken = _ref.accessToken,
420
- space = _ref.space,
421
- environment = _ref.environment,
422
- children = _ref.children;
423
- return React__default.createElement(CredentialsContext.Provider, {
424
- value: {
425
- space: space,
426
- accessToken: accessToken,
427
- environment: environment
428
- }
429
- }, children);
430
- }
431
- var ContentfulFetcherMeta = {
432
- name: "ContentfulFetcher",
433
- displayName: "Contentful Fetcher",
434
- importName: "ContentfulFetcher",
435
- importPath: modulePath,
436
- providesData: true,
437
- description: "Fetches Contentful data and repeats content of children once for every row fetched. ",
438
- defaultStyles: {
439
- display: "grid",
440
- gridTemplateColumns: "1fr 1fr 1fr 1fr",
441
- gridRowGap: "8px",
442
- gridColumnGap: "8px",
443
- padding: "8px",
444
- maxWidth: "100%"
445
- },
446
- props: {
447
- children: {
448
- type: "slot",
449
- defaultValue: {
450
- type: "vbox",
451
- styles: {
452
- padding: "8px"
453
- },
454
- children: {
455
- type: "component",
456
- name: "ContentfulField"
457
- }
458
- }
459
- },
460
- contentType: {
461
- type: "choice",
462
- options: function options(props, ctx) {
463
- var _ctx$types$map, _ctx$types;
464
- return (_ctx$types$map = ctx == null || (_ctx$types = ctx.types) == null ? void 0 : _ctx$types.map(function (type) {
465
- var _type$sys;
466
- return {
467
- label: type == null ? void 0 : type.name,
468
- value: type == null || (_type$sys = type.sys) == null ? void 0 : _type$sys.id
469
- };
470
- })) != null ? _ctx$types$map : [];
471
- },
472
- displayName: "Content type",
473
- description: "Content type to be queried."
474
- },
475
- filterField: {
476
- type: "choice",
477
- displayName: "Filter field",
478
- description: "Field (from Collection) to filter by.",
479
- options: function options(props, ctx) {
480
- var _ctx$fields;
481
- return (_ctx$fields = ctx == null ? void 0 : ctx.fields) != null ? _ctx$fields : [];
482
- },
483
- hidden: function hidden(props, ctx) {
484
- return !props.contentType;
485
- }
486
- },
487
- searchParameter: {
488
- type: "choice",
489
- displayName: "Search Parameter",
490
- description: "Search Parameter to filter by (see Contentful Content Delivery API documentation for details).",
491
- options: function options(props, ctx) {
492
- var _ctx$queryOptions;
493
- return (_ctx$queryOptions = ctx == null ? void 0 : ctx.queryOptions) != null ? _ctx$queryOptions : [];
494
- },
495
- hidden: function hidden(props, ctx) {
496
- return !props.filterField;
497
- }
498
- },
499
- filterValue: {
500
- type: "string",
501
- displayName: "Filter value",
502
- description: "Value to filter by, should be of filter field type.",
503
- hidden: function hidden(props, ctx) {
504
- return !props.searchParameter;
505
- }
506
- },
507
- limit: {
508
- type: "number",
509
- displayName: "Limit",
510
- description: "Limit the number of entries that are returned."
511
- },
512
- include: {
513
- type: "number",
514
- displayName: "Linked items depth",
515
- defaultValueHint: 1,
516
- description: "When you have related content (e.g. entries with links to image assets) it's possible to include both search results and related data in a single request. Using the include parameter, you can specify the number of levels to resolve.",
517
- max: 10,
518
- min: 0
519
- },
520
- noAutoRepeat: {
521
- type: "boolean",
522
- displayName: "No auto-repeat",
523
- description: "Do not automatically repeat children for every entry.",
524
- defaultValue: false
525
- },
526
- noLayout: {
527
- type: "boolean",
528
- displayName: "No layout",
529
- description: "When set, Contentful Fetcher will not layout its children; instead, the layout set on its parent element will be used. Useful if you want to set flex gap or control container tag type.",
530
- defaultValue: false
531
- }
532
- }
533
- };
534
- function ContentfulFetcher(_ref2) {
535
- var _contentTypes$items, _operators, _contentTypes$items2;
536
- var filterField = _ref2.filterField,
537
- filterValue = _ref2.filterValue,
538
- searchParameter = _ref2.searchParameter,
539
- noAutoRepeat = _ref2.noAutoRepeat,
540
- contentType = _ref2.contentType,
541
- children = _ref2.children,
542
- className = _ref2.className,
543
- limit = _ref2.limit,
544
- include = _ref2.include,
545
- noLayout = _ref2.noLayout,
546
- setControlContextData = _ref2.setControlContextData;
547
- var creds = ensure(React.useContext(CredentialsContext));
548
- var cacheKey = JSON.stringify({
549
- include: include,
550
- limit: limit,
551
- filterField: filterField,
552
- filterValue: filterValue,
553
- searchParameter: searchParameter,
554
- creds: creds
555
- });
556
- var baseUrl = "https://cdn.contentful.com";
557
- var _usePlasmicQueryData = query.usePlasmicQueryData(cacheKey + "/contentTypes", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
558
- var resp;
559
- return _regeneratorRuntime().wrap(function _callee$(_context) {
560
- while (1) switch (_context.prev = _context.next) {
561
- case 0:
562
- _context.next = 2;
563
- return fetch(baseUrl + "/spaces/" + creds.space + "/environments/" + creds.environment + "/content_types?access_token=" + creds.accessToken);
564
- case 2:
565
- resp = _context.sent;
566
- return _context.abrupt("return", resp.json());
567
- case 4:
568
- case "end":
569
- return _context.stop();
570
- }
571
- }, _callee);
572
- }))),
573
- contentTypes = _usePlasmicQueryData.data;
574
- setControlContextData == null || setControlContextData({
575
- types: (_contentTypes$items = contentTypes == null ? void 0 : contentTypes.items) != null ? _contentTypes$items : []
576
- });
577
- var _usePlasmicQueryData2 = query.usePlasmicQueryData(contentType ? cacheKey + "/" + contentType + "/entriesData" : null, /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
578
- var query, resp;
579
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
580
- while (1) switch (_context2.prev = _context2.next) {
581
- case 0:
582
- query = "/spaces/" + creds.space + "/environments/" + creds.environment + "/entries?access_token=" + creds.accessToken + "&content_type=" + contentType;
583
- if (limit) {
584
- query = query + "&limit=" + limit;
585
- }
586
- if (include) {
587
- query = query + "&include=" + include;
588
- }
589
- _context2.next = 5;
590
- return fetch("" + baseUrl + query);
591
- case 5:
592
- resp = _context2.sent;
593
- return _context2.abrupt("return", resp.json());
594
- case 7:
595
- case "end":
596
- return _context2.stop();
597
- }
598
- }, _callee2);
599
- }))),
600
- entriesData = _usePlasmicQueryData2.data;
601
- var _usePlasmicQueryData3 = query.usePlasmicQueryData(contentType && filterField && filterValue ? cacheKey + "/" + contentType + "/filteredData" : null, /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
602
- var queryPath, resp;
603
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
604
- while (1) switch (_context3.prev = _context3.next) {
605
- case 0:
606
- queryPath = "/spaces/" + creds.space + "/environments/" + creds.environment + "/entries?access_token=" + creds.accessToken + "&content_type=" + contentType + "&fields." + filterField + searchParameter + "=" + filterValue;
607
- _context3.next = 3;
608
- return fetch("" + baseUrl + queryPath);
609
- case 3:
610
- resp = _context3.sent;
611
- return _context3.abrupt("return", resp.json());
612
- case 5:
613
- case "end":
614
- return _context3.stop();
615
- }
616
- }, _callee3);
617
- }))),
618
- filteredData = _usePlasmicQueryData3.data;
619
- if (!creds.space || !creds.accessToken) {
620
- return React__default.createElement("div", null, "Please specify a valid API Credentials: Space, Access Token and Environment");
621
- }
622
- if (!contentTypes) {
623
- return React__default.createElement("div", null, "Please configure the Contentful credentials");
624
- }
625
- if (!entriesData) {
626
- return React__default.createElement("div", null, "Please select a content type");
627
- }
628
- var filterFields = entriesData == null ? void 0 : entriesData.items.flatMap(function (item) {
629
- var fields = Object.keys(item.fields).filter(function (field) {
630
- var value = get(item, field);
631
- return typeof value !== "object" && field !== "photos";
632
- });
633
- return fields;
634
- });
635
- var operators;
636
- var matchedFields = Object.values(entriesData.items).map(function (item) {
637
- var fields = Object.entries(item.fields).find(function (el) {
638
- return el[0] === filterField;
639
- });
640
- return fields;
641
- });
642
- Object.values(matchedFields).map(function (model) {
643
- return Array.isArray(model) ? model : [model];
644
- }).map(function (item) {
645
- if (typeof item[1] === "number" && typeof item[1] !== "object") {
646
- operators = searchParameters;
647
- } else if (typeof item[1] !== "number" && typeof item[1] !== "object" && typeof item[1] === "string") {
648
- operators = [{
649
- value: "[match]",
650
- label: "Full text search"
651
- }];
652
- }
653
- });
654
- setControlContextData == null || setControlContextData({
655
- queryOptions: (_operators = operators) != null ? _operators : [],
656
- types: (_contentTypes$items2 = contentTypes == null ? void 0 : contentTypes.items) != null ? _contentTypes$items2 : [],
657
- fields: uniq(filterFields != null ? filterFields : [])
658
- });
659
- if (filterField && !searchParameter) {
660
- return React__default.createElement("div", null, "Please specify a Search Parameter");
661
- }
662
- if (searchParameter && !filterValue) {
663
- return React__default.createElement("div", null, "Please specify a Filter value");
664
- }
665
- function denormalizeData(data) {
666
- if (!(data != null && data.items) || !(data != null && data.includes)) {
667
- return data;
668
- }
669
- var entryMap = {};
670
- if (data.includes.Entry) {
671
- data.includes.Entry.forEach(function (entry) {
672
- entryMap[entry.sys.id] = entry.fields;
673
- });
674
- }
675
- var itemsWithDenormalizedFields = data.items.map(function (item) {
676
- var updatedFields = {};
677
- var _loop = function _loop(fieldName) {
678
- var fieldValue = item.fields[fieldName];
679
- if (Array.isArray(fieldValue)) {
680
- var updatedArray = fieldValue.map(function (arrayItem) {
681
- if (data.includes.Asset && arrayItem && typeof arrayItem === "object" && "sys" in arrayItem && arrayItem.sys.linkType === "Asset") {
682
- var fieldId = arrayItem.sys.id;
683
- var asset = data.includes.Asset.find(function (asset) {
684
- return asset.sys.id === fieldId;
685
- });
686
- if (asset) {
687
- var _asset$fields;
688
- return _extends({}, arrayItem, {
689
- url: "https:" + ((_asset$fields = asset.fields) == null || (_asset$fields = _asset$fields.file) == null ? void 0 : _asset$fields.url)
690
- });
691
- } else {
692
- console.log("Asset URL not found for ID: " + fieldId);
693
- }
694
- } else if (data.includes.Entry && arrayItem && typeof arrayItem === "object" && "sys" in arrayItem && arrayItem.sys.linkType === "Entry") {
695
- var _fieldId = arrayItem.sys.id;
696
- if (entryMap[_fieldId]) {
697
- updatedFields[fieldName] = _extends({}, fieldValue, {
698
- fields: entryMap[_fieldId]
699
- });
700
- } else {
701
- console.log("Entry not found for ID: " + _fieldId);
702
- }
703
- }
704
- return arrayItem;
705
- });
706
- updatedFields[fieldName] = updatedArray;
707
- } else if (data.includes.Asset && fieldValue && typeof fieldValue === "object" && "sys" in fieldValue && fieldValue.sys.linkType === "Asset") {
708
- var fieldId = fieldValue.sys.id;
709
- var asset = data.includes.Asset.find(function (asset) {
710
- return asset.sys.id === fieldId;
711
- });
712
- if (asset) {
713
- var _asset$fields2;
714
- updatedFields[fieldName] = _extends({}, fieldValue, {
715
- url: "https:" + ((_asset$fields2 = asset.fields) == null || (_asset$fields2 = _asset$fields2.file) == null ? void 0 : _asset$fields2.url)
716
- });
717
- } else {
718
- console.log("Asset URL not found for ID: " + fieldId);
719
- }
720
- } else if (data.includes.Entry && fieldValue && typeof fieldValue === "object" && "sys" in fieldValue && fieldValue.sys.linkType === "Entry") {
721
- var _fieldId2 = fieldValue.sys.id;
722
- if (entryMap[_fieldId2]) {
723
- updatedFields[fieldName] = _extends({}, fieldValue, {
724
- fields: entryMap[_fieldId2]
725
- });
726
- } else {
727
- console.log("Entry not found for ID: " + _fieldId2);
728
- }
729
- } else {
730
- updatedFields[fieldName] = fieldValue;
731
- }
732
- };
733
- for (var fieldName in item.fields) {
734
- _loop(fieldName);
735
- }
736
- return _extends({}, item, {
737
- fields: updatedFields
738
- });
739
- });
740
- return _extends({}, data, {
741
- items: itemsWithDenormalizedFields
742
- });
743
- }
744
- var renderedData;
745
- if (filteredData) {
746
- var _filteredData$items, _denormalizeData;
747
- if ((filteredData == null || (_filteredData$items = filteredData.items) == null ? void 0 : _filteredData$items.length) === 0) {
748
- return React__default.createElement("div", {
749
- className: className
750
- }, "No published entry found");
751
- }
752
- renderedData = noAutoRepeat ? children : (_denormalizeData = denormalizeData(filteredData)) == null || (_denormalizeData = _denormalizeData.items) == null ? void 0 : _denormalizeData.map(function (item, index) {
753
- var _item$sys;
754
- return React__default.createElement(host.DataProvider, {
755
- key: item == null || (_item$sys = item.sys) == null ? void 0 : _item$sys.id,
756
- name: "contentfulItem",
757
- data: item,
758
- hidden: true
759
- }, React__default.createElement(host.DataProvider, {
760
- name: makeDataProviderName(contentType),
761
- data: item
762
- }, host.repeatedElement(index, children)));
763
- });
764
- } else {
765
- var _entriesData$items, _denormalizeData2;
766
- if ((entriesData == null || (_entriesData$items = entriesData.items) == null ? void 0 : _entriesData$items.length) === 0) {
767
- return React__default.createElement("div", {
768
- className: className
769
- }, contentType, " is empty");
770
- }
771
- renderedData = noAutoRepeat ? children : (_denormalizeData2 = denormalizeData(entriesData)) == null || (_denormalizeData2 = _denormalizeData2.items) == null ? void 0 : _denormalizeData2.map(function (item, index) {
772
- var _item$sys2;
773
- return React__default.createElement(host.DataProvider, {
774
- key: item == null || (_item$sys2 = item.sys) == null ? void 0 : _item$sys2.id,
775
- name: "contentfulItem",
776
- data: item,
777
- hidden: true
778
- }, React__default.createElement(host.DataProvider, {
779
- name: makeDataProviderName(contentType),
780
- data: item
781
- }, host.repeatedElement(index, children)));
782
- });
783
- }
784
- return React__default.createElement(host.DataProvider, {
785
- name: "contentfulItems",
786
- data: entriesData == null ? void 0 : entriesData.items
787
- }, noLayout ? React__default.createElement(React__default.Fragment, null, " ", renderedData, " ") : React__default.createElement("div", {
788
- className: className
789
- }, " ", renderedData, " "));
790
- }
791
- var ContentfulFieldMeta = {
792
- name: "ContentfulField",
793
- displayName: "Contentful Field",
794
- importName: "ContentfulField",
795
- importPath: modulePath,
796
- props: {
797
- objectPath: {
798
- type: "dataSelector",
799
- data: function data(props, ctx) {
800
- var _ctx$data;
801
- return (_ctx$data = ctx == null ? void 0 : ctx.data) != null ? _ctx$data : {};
802
- },
803
- displayName: "Field",
804
- description: "Field to be displayed."
805
- }
806
- }
807
- };
808
- function ContentfulField(_ref6) {
809
- var _useSelector;
810
- var className = _ref6.className,
811
- objectPath = _ref6.objectPath,
812
- setControlContextData = _ref6.setControlContextData;
813
- var item = (_useSelector = host.useSelector("contentfulItem")) == null ? void 0 : _useSelector.fields;
814
- if (!item) {
815
- return React__default.createElement("div", null, "ContentfulField must be used within a ContentfulFetcher ");
816
- }
817
- setControlContextData == null || setControlContextData({
818
- data: item
819
- });
820
- if (!objectPath) {
821
- return React__default.createElement("div", null, "Please specify a valid path or select a field.");
822
- }
823
- var data = get(item, objectPath);
824
- if (typeof data === "object" && "nodeType" in data && data.nodeType === "document") {
825
- return React__default.createElement("div", {
826
- className: className,
827
- dangerouslySetInnerHTML: {
828
- __html: richTextHtmlRenderer.documentToHtmlString(data)
829
- }
830
- });
831
- } else if (typeof data === "object" && data.sys.linkType === "Asset" && data.url) {
832
- return React__default.createElement("img", {
833
- className: className,
834
- src: data.url
835
- });
836
- } else if (!data) {
837
- return React__default.createElement("div", null, "Please specify a valid field.");
838
- } else if (typeof data !== "object") {
839
- return React__default.createElement("div", {
840
- className: className
841
- }, data);
842
- } else {
843
- return React__default.createElement("div", {
844
- className: className
845
- }, data.toString());
846
- }
847
- }
848
-
849
- function registerAll(loader) {
850
- var _registerComponent = function _registerComponent(Component, defaultMeta) {
851
- if (loader) {
852
- loader.registerComponent(Component, defaultMeta);
853
- } else {
854
- registerComponent(Component, defaultMeta);
855
- }
856
- };
857
- if (loader) {
858
- loader.registerGlobalContext(ContentfulCredentialsProvider, ContentfulCredentialsProviderMeta);
859
- } else {
860
- registerGlobalContext(ContentfulCredentialsProvider, ContentfulCredentialsProviderMeta);
861
- }
862
- _registerComponent(ContentfulFetcher, ContentfulFetcherMeta);
863
- _registerComponent(ContentfulField, ContentfulFieldMeta);
864
- }
865
-
866
- exports.ContentfulCredentialsProvider = ContentfulCredentialsProvider;
867
- exports.ContentfulCredentialsProviderMeta = ContentfulCredentialsProviderMeta;
868
- exports.ContentfulFetcher = ContentfulFetcher;
869
- exports.ContentfulFetcherMeta = ContentfulFetcherMeta;
870
- exports.ContentfulField = ContentfulField;
871
- exports.ContentfulFieldMeta = ContentfulFieldMeta;
872
- exports.ensure = ensure;
873
- exports.registerAll = registerAll;
874
- //# sourceMappingURL=plasmic-contentful.cjs.development.js.map