@plasmicpkgs/plasmic-contentful 0.0.115 → 0.0.117

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,52 @@
1
+ import registerComponent from '@plasmicapp/host/registerComponent';
2
+ import registerGlobalContext from '@plasmicapp/host/registerGlobalContext';
3
+ import { GlobalContextMeta, ComponentMeta } from '@plasmicapp/host';
4
+ import React, { ReactNode } from 'react';
5
+
6
+ declare function ensure<T>(x: T | null | undefined): T;
7
+ interface ContentfulCredentialsProviderProps {
8
+ space: string;
9
+ accessToken: string;
10
+ environment?: string;
11
+ }
12
+ declare const ContentfulCredentialsProviderMeta: GlobalContextMeta<ContentfulCredentialsProviderProps>;
13
+ declare function ContentfulCredentialsProvider({ accessToken, space, environment, children, }: React.PropsWithChildren<ContentfulCredentialsProviderProps>): React.JSX.Element;
14
+ interface ContentfulFetcherProps {
15
+ contentType: string;
16
+ children?: ReactNode;
17
+ className?: string;
18
+ limit?: number;
19
+ include?: number;
20
+ order?: string;
21
+ filterField?: string;
22
+ searchParameter?: string;
23
+ filterValue?: string | number;
24
+ noAutoRepeat?: boolean;
25
+ noLayout?: boolean;
26
+ setControlContextData?: (data: {
27
+ types?: {
28
+ name: string;
29
+ id: string;
30
+ }[];
31
+ fields?: string[];
32
+ queryOptions?: [];
33
+ }) => void;
34
+ }
35
+ declare const ContentfulFetcherMeta: ComponentMeta<ContentfulFetcherProps>;
36
+ declare function ContentfulFetcher({ filterField, filterValue, searchParameter, noAutoRepeat, contentType, children, className, limit, include, noLayout, setControlContextData, }: ContentfulFetcherProps): React.JSX.Element;
37
+ interface ContentfulFieldProps {
38
+ className?: string;
39
+ objectPath?: (string | number)[];
40
+ setControlContextData?: (data: {
41
+ data: object;
42
+ }) => void;
43
+ }
44
+ declare const ContentfulFieldMeta: ComponentMeta<ContentfulFieldProps>;
45
+ declare function ContentfulField({ className, objectPath, setControlContextData, }: ContentfulFieldProps): React.JSX.Element;
46
+
47
+ declare function registerAll(loader?: {
48
+ registerComponent: typeof registerComponent;
49
+ registerGlobalContext: typeof registerGlobalContext;
50
+ }): void;
51
+
52
+ export { ContentfulCredentialsProvider, ContentfulCredentialsProviderMeta, ContentfulFetcher, ContentfulFetcherMeta, ContentfulField, ContentfulFieldMeta, ensure, registerAll };
package/dist/index.d.ts CHANGED
@@ -1,7 +1,52 @@
1
- import registerComponent from "@plasmicapp/host/registerComponent";
2
- import registerGlobalContext from "@plasmicapp/host/registerGlobalContext";
3
- export declare function registerAll(loader?: {
4
- registerComponent: typeof registerComponent;
5
- registerGlobalContext: typeof registerGlobalContext;
6
- }): void;
7
- export * from "./contentful";
1
+ import registerComponent from '@plasmicapp/host/registerComponent';
2
+ import registerGlobalContext from '@plasmicapp/host/registerGlobalContext';
3
+ import { GlobalContextMeta, ComponentMeta } from '@plasmicapp/host';
4
+ import React, { ReactNode } from 'react';
5
+
6
+ declare function ensure<T>(x: T | null | undefined): T;
7
+ interface ContentfulCredentialsProviderProps {
8
+ space: string;
9
+ accessToken: string;
10
+ environment?: string;
11
+ }
12
+ declare const ContentfulCredentialsProviderMeta: GlobalContextMeta<ContentfulCredentialsProviderProps>;
13
+ declare function ContentfulCredentialsProvider({ accessToken, space, environment, children, }: React.PropsWithChildren<ContentfulCredentialsProviderProps>): React.JSX.Element;
14
+ interface ContentfulFetcherProps {
15
+ contentType: string;
16
+ children?: ReactNode;
17
+ className?: string;
18
+ limit?: number;
19
+ include?: number;
20
+ order?: string;
21
+ filterField?: string;
22
+ searchParameter?: string;
23
+ filterValue?: string | number;
24
+ noAutoRepeat?: boolean;
25
+ noLayout?: boolean;
26
+ setControlContextData?: (data: {
27
+ types?: {
28
+ name: string;
29
+ id: string;
30
+ }[];
31
+ fields?: string[];
32
+ queryOptions?: [];
33
+ }) => void;
34
+ }
35
+ declare const ContentfulFetcherMeta: ComponentMeta<ContentfulFetcherProps>;
36
+ declare function ContentfulFetcher({ filterField, filterValue, searchParameter, noAutoRepeat, contentType, children, className, limit, include, noLayout, setControlContextData, }: ContentfulFetcherProps): React.JSX.Element;
37
+ interface ContentfulFieldProps {
38
+ className?: string;
39
+ objectPath?: (string | number)[];
40
+ setControlContextData?: (data: {
41
+ data: object;
42
+ }) => void;
43
+ }
44
+ declare const ContentfulFieldMeta: ComponentMeta<ContentfulFieldProps>;
45
+ declare function ContentfulField({ className, objectPath, setControlContextData, }: ContentfulFieldProps): React.JSX.Element;
46
+
47
+ declare function registerAll(loader?: {
48
+ registerComponent: typeof registerComponent;
49
+ registerGlobalContext: typeof registerGlobalContext;
50
+ }): void;
51
+
52
+ export { ContentfulCredentialsProvider, ContentfulCredentialsProviderMeta, ContentfulFetcher, ContentfulFetcherMeta, ContentfulField, ContentfulFieldMeta, ensure, registerAll };
package/dist/index.js CHANGED
@@ -1,8 +1,536 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
1
29
 
2
- 'use strict'
30
+ // src/index.tsx
31
+ var src_exports = {};
32
+ __export(src_exports, {
33
+ ContentfulCredentialsProvider: () => ContentfulCredentialsProvider,
34
+ ContentfulCredentialsProviderMeta: () => ContentfulCredentialsProviderMeta,
35
+ ContentfulFetcher: () => ContentfulFetcher,
36
+ ContentfulFetcherMeta: () => ContentfulFetcherMeta,
37
+ ContentfulField: () => ContentfulField,
38
+ ContentfulFieldMeta: () => ContentfulFieldMeta,
39
+ ensure: () => ensure,
40
+ registerAll: () => registerAll
41
+ });
42
+ module.exports = __toCommonJS(src_exports);
43
+ var import_registerComponent = __toESM(require("@plasmicapp/host/registerComponent"));
44
+ var import_registerGlobalContext = __toESM(require("@plasmicapp/host/registerGlobalContext"));
3
45
 
4
- if (process.env.NODE_ENV === 'production') {
5
- module.exports = require('./plasmic-contentful.cjs.production.min.js')
6
- } else {
7
- module.exports = require('./plasmic-contentful.cjs.development.js')
46
+ // src/contentful.tsx
47
+ var import_rich_text_html_renderer = require("@contentful/rich-text-html-renderer");
48
+ var import_host = require("@plasmicapp/host");
49
+ var import_query = require("@plasmicapp/query");
50
+ var import_change_case = require("change-case");
51
+ var import_dlv = __toESM(require("dlv"));
52
+ var import_react = __toESM(require("react"));
53
+
54
+ // src/utils.ts
55
+ var searchParameters = [
56
+ {
57
+ value: "[lt]",
58
+ label: "Less than"
59
+ },
60
+ {
61
+ value: "[lte]",
62
+ label: "Less than or equal"
63
+ },
64
+ {
65
+ value: "[gt]",
66
+ label: "Greater than"
67
+ },
68
+ {
69
+ value: "[gte]",
70
+ label: "Greater than or equal "
71
+ }
72
+ ];
73
+ var uniq = (xs) => Array.from(new Set(xs));
74
+
75
+ // src/contentful.tsx
76
+ function ensure(x) {
77
+ if (x === null || x === void 0) {
78
+ throw new Error(`Value must not be undefined or null`);
79
+ } else {
80
+ return x;
81
+ }
82
+ }
83
+ var modulePath = "@plasmicpkgs/plasmic-contentful";
84
+ var makeDataProviderName = (contentType) => `currentContentful${(0, import_change_case.pascalCase)(contentType)}Item`;
85
+ var CredentialsContext = import_react.default.createContext(void 0);
86
+ var ContentfulCredentialsProviderMeta = {
87
+ name: "Contentful CredentialsProvider",
88
+ displayName: "Contentful Credentials Provider",
89
+ 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/).",
90
+ importName: "ContentfulCredentialsProvider",
91
+ importPath: modulePath,
92
+ props: {
93
+ space: {
94
+ type: "string",
95
+ displayName: "Space",
96
+ description: "Name of your space",
97
+ defaultValue: "lmfbwqzbh93n"
98
+ },
99
+ accessToken: {
100
+ type: "string",
101
+ displayName: "Access Token ",
102
+ description: "Access Token",
103
+ defaultValue: "aWvf6oSLTuqxKCxSUpokajdQr84hGQFE6zoJG7DVVLg"
104
+ },
105
+ environment: {
106
+ type: "string",
107
+ displayName: "Environment",
108
+ defaultValue: "master"
109
+ }
110
+ }
111
+ };
112
+ function ContentfulCredentialsProvider({
113
+ accessToken,
114
+ space,
115
+ environment,
116
+ children
117
+ }) {
118
+ return /* @__PURE__ */ import_react.default.createElement(CredentialsContext.Provider, { value: { space, accessToken, environment } }, children);
119
+ }
120
+ var ContentfulFetcherMeta = {
121
+ name: "ContentfulFetcher",
122
+ displayName: "Contentful Fetcher",
123
+ importName: "ContentfulFetcher",
124
+ importPath: modulePath,
125
+ providesData: true,
126
+ description: "Fetches Contentful data and repeats content of children once for every row fetched. ",
127
+ defaultStyles: {
128
+ display: "grid",
129
+ gridTemplateColumns: "1fr 1fr 1fr 1fr",
130
+ gridRowGap: "8px",
131
+ gridColumnGap: "8px",
132
+ padding: "8px",
133
+ maxWidth: "100%"
134
+ },
135
+ props: {
136
+ children: {
137
+ type: "slot",
138
+ defaultValue: {
139
+ type: "vbox",
140
+ styles: {
141
+ padding: "8px"
142
+ },
143
+ children: {
144
+ type: "component",
145
+ name: "ContentfulField"
146
+ }
147
+ }
148
+ },
149
+ contentType: {
150
+ type: "choice",
151
+ options: (props, ctx) => {
152
+ var _a, _b;
153
+ return (_b = (_a = ctx == null ? void 0 : ctx.types) == null ? void 0 : _a.map((type) => {
154
+ var _a2;
155
+ return {
156
+ label: type == null ? void 0 : type.name,
157
+ value: (_a2 = type == null ? void 0 : type.sys) == null ? void 0 : _a2.id
158
+ };
159
+ })) != null ? _b : [];
160
+ },
161
+ displayName: "Content type",
162
+ description: "Content type to be queried."
163
+ },
164
+ filterField: {
165
+ type: "choice",
166
+ displayName: "Filter field",
167
+ description: "Field (from Collection) to filter by.",
168
+ options: (props, ctx) => {
169
+ var _a;
170
+ return (_a = ctx == null ? void 0 : ctx.fields) != null ? _a : [];
171
+ },
172
+ hidden: (props, ctx) => !props.contentType
173
+ },
174
+ searchParameter: {
175
+ type: "choice",
176
+ displayName: "Search Parameter",
177
+ description: "Search Parameter to filter by (see Contentful Content Delivery API documentation for details).",
178
+ options: (props, ctx) => {
179
+ var _a;
180
+ return (_a = ctx == null ? void 0 : ctx.queryOptions) != null ? _a : [];
181
+ },
182
+ hidden: (props, ctx) => !props.filterField
183
+ },
184
+ filterValue: {
185
+ type: "string",
186
+ displayName: "Filter value",
187
+ description: "Value to filter by, should be of filter field type.",
188
+ hidden: (props, ctx) => !props.searchParameter
189
+ },
190
+ limit: {
191
+ type: "number",
192
+ displayName: "Limit",
193
+ description: "Limit the number of entries that are returned."
194
+ },
195
+ include: {
196
+ type: "number",
197
+ displayName: "Linked items depth",
198
+ defaultValueHint: 1,
199
+ 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.",
200
+ max: 10,
201
+ min: 0
202
+ },
203
+ noAutoRepeat: {
204
+ type: "boolean",
205
+ displayName: "No auto-repeat",
206
+ description: "Do not automatically repeat children for every entry.",
207
+ defaultValue: false
208
+ },
209
+ noLayout: {
210
+ type: "boolean",
211
+ displayName: "No layout",
212
+ 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.",
213
+ defaultValue: false
214
+ }
215
+ }
216
+ };
217
+ function ContentfulFetcher({
218
+ filterField,
219
+ filterValue,
220
+ searchParameter,
221
+ noAutoRepeat,
222
+ contentType,
223
+ children,
224
+ className,
225
+ limit,
226
+ include,
227
+ noLayout,
228
+ setControlContextData
229
+ }) {
230
+ var _a, _b, _c, _d, _e, _f, _g, _h;
231
+ const creds = ensure((0, import_react.useContext)(CredentialsContext));
232
+ const cacheKey = JSON.stringify({
233
+ include,
234
+ limit,
235
+ filterField,
236
+ filterValue,
237
+ searchParameter,
238
+ creds
239
+ });
240
+ const baseUrl = "https://cdn.contentful.com";
241
+ const { data: contentTypes } = (0, import_query.usePlasmicQueryData)(
242
+ `${cacheKey}/contentTypes`,
243
+ async () => {
244
+ const resp = await fetch(
245
+ `${baseUrl}/spaces/${creds.space}/environments/${creds.environment}/content_types?access_token=${creds.accessToken}`
246
+ );
247
+ return resp.json();
248
+ }
249
+ );
250
+ setControlContextData == null ? void 0 : setControlContextData({
251
+ types: (_a = contentTypes == null ? void 0 : contentTypes.items) != null ? _a : []
252
+ });
253
+ const { data: entriesData } = (0, import_query.usePlasmicQueryData)(
254
+ contentType ? `${cacheKey}/${contentType}/entriesData` : null,
255
+ async () => {
256
+ let query = `/spaces/${creds.space}/environments/${creds.environment}/entries?access_token=${creds.accessToken}&content_type=${contentType}`;
257
+ if (limit) {
258
+ query = `${query}&limit=${limit}`;
259
+ }
260
+ if (include) {
261
+ query = `${query}&include=${include}`;
262
+ }
263
+ const resp = await fetch(`${baseUrl}${query}`);
264
+ return resp.json();
265
+ }
266
+ );
267
+ const { data: filteredData } = (0, import_query.usePlasmicQueryData)(
268
+ contentType && filterField && filterValue ? `${cacheKey}/${contentType}/filteredData` : null,
269
+ async () => {
270
+ const queryPath = `/spaces/${creds.space}/environments/${creds.environment}/entries?access_token=${creds.accessToken}&content_type=${contentType}&fields.${filterField}${searchParameter}=${filterValue}`;
271
+ const resp = await fetch(`${baseUrl}${queryPath}`);
272
+ return resp.json();
273
+ }
274
+ );
275
+ if (!creds.space || !creds.accessToken) {
276
+ return /* @__PURE__ */ import_react.default.createElement("div", null, "Please specify a valid API Credentials: Space, Access Token and Environment");
277
+ }
278
+ if (!contentTypes) {
279
+ return /* @__PURE__ */ import_react.default.createElement("div", null, "Please configure the Contentful credentials");
280
+ }
281
+ if (!entriesData) {
282
+ return /* @__PURE__ */ import_react.default.createElement("div", null, "Please select a content type");
283
+ }
284
+ const filterFields = entriesData == null ? void 0 : entriesData.items.flatMap((item) => {
285
+ const fields = Object.keys(item.fields).filter((field) => {
286
+ const value = (0, import_dlv.default)(item, field);
287
+ return typeof value !== "object" && field !== "photos";
288
+ });
289
+ return fields;
290
+ });
291
+ let operators;
292
+ const matchedFields = Object.values(entriesData.items).map((item) => {
293
+ const fields = Object.entries(item.fields).find(
294
+ (el) => el[0] === filterField
295
+ );
296
+ return fields;
297
+ });
298
+ Object.values(matchedFields).map((model) => Array.isArray(model) ? model : [model]).map((item) => {
299
+ if (typeof item[1] === "number" && typeof item[1] !== "object") {
300
+ operators = searchParameters;
301
+ } else if (typeof item[1] !== "number" && typeof item[1] !== "object" && typeof item[1] === "string") {
302
+ operators = [
303
+ {
304
+ value: "[match]",
305
+ label: "Full text search"
306
+ }
307
+ ];
308
+ }
309
+ });
310
+ setControlContextData == null ? void 0 : setControlContextData({
311
+ queryOptions: operators != null ? operators : [],
312
+ types: (_b = contentTypes == null ? void 0 : contentTypes.items) != null ? _b : [],
313
+ fields: uniq(filterFields != null ? filterFields : [])
314
+ });
315
+ if (filterField && !searchParameter) {
316
+ return /* @__PURE__ */ import_react.default.createElement("div", null, "Please specify a Search Parameter");
317
+ }
318
+ if (searchParameter && !filterValue) {
319
+ return /* @__PURE__ */ import_react.default.createElement("div", null, "Please specify a Filter value");
320
+ }
321
+ function denormalizeData(data) {
322
+ if (!(data == null ? void 0 : data.items) || !(data == null ? void 0 : data.includes)) {
323
+ return data;
324
+ }
325
+ const entryMap = {};
326
+ if (data.includes.Entry) {
327
+ data.includes.Entry.forEach((entry) => {
328
+ entryMap[entry.sys.id] = entry.fields;
329
+ });
330
+ }
331
+ const itemsWithDenormalizedFields = data.items.map((item) => {
332
+ var _a2, _b2;
333
+ const updatedFields = {};
334
+ for (const fieldName in item.fields) {
335
+ const fieldValue = item.fields[fieldName];
336
+ if (Array.isArray(fieldValue)) {
337
+ const updatedArray = fieldValue.map((arrayItem) => {
338
+ var _a3, _b3;
339
+ if (data.includes.Asset && arrayItem && typeof arrayItem === "object" && "sys" in arrayItem && arrayItem.sys.linkType === "Asset") {
340
+ const fieldId = arrayItem.sys.id;
341
+ const asset = data.includes.Asset.find(
342
+ (asset2) => asset2.sys.id === fieldId
343
+ );
344
+ if (asset) {
345
+ return {
346
+ ...arrayItem,
347
+ url: "https:" + ((_b3 = (_a3 = asset.fields) == null ? void 0 : _a3.file) == null ? void 0 : _b3.url)
348
+ };
349
+ } else {
350
+ console.log(`Asset URL not found for ID: ${fieldId}`);
351
+ }
352
+ } else if (data.includes.Entry && arrayItem && typeof arrayItem === "object" && "sys" in arrayItem && arrayItem.sys.linkType === "Entry") {
353
+ const fieldId = arrayItem.sys.id;
354
+ if (entryMap[fieldId]) {
355
+ updatedFields[fieldName] = {
356
+ ...fieldValue,
357
+ fields: entryMap[fieldId]
358
+ };
359
+ } else {
360
+ console.log(`Entry not found for ID: ${fieldId}`);
361
+ }
362
+ }
363
+ return arrayItem;
364
+ });
365
+ updatedFields[fieldName] = updatedArray;
366
+ } else if (data.includes.Asset && fieldValue && typeof fieldValue === "object" && "sys" in fieldValue && fieldValue.sys.linkType === "Asset") {
367
+ const fieldId = fieldValue.sys.id;
368
+ const asset = data.includes.Asset.find(
369
+ (asset2) => asset2.sys.id === fieldId
370
+ );
371
+ if (asset) {
372
+ updatedFields[fieldName] = {
373
+ ...fieldValue,
374
+ url: "https:" + ((_b2 = (_a2 = asset.fields) == null ? void 0 : _a2.file) == null ? void 0 : _b2.url)
375
+ };
376
+ } else {
377
+ console.log(`Asset URL not found for ID: ${fieldId}`);
378
+ }
379
+ } else if (data.includes.Entry && fieldValue && typeof fieldValue === "object" && "sys" in fieldValue && fieldValue.sys.linkType === "Entry") {
380
+ const fieldId = fieldValue.sys.id;
381
+ if (entryMap[fieldId]) {
382
+ updatedFields[fieldName] = {
383
+ ...fieldValue,
384
+ fields: entryMap[fieldId]
385
+ };
386
+ } else {
387
+ console.log(`Entry not found for ID: ${fieldId}`);
388
+ }
389
+ } else {
390
+ updatedFields[fieldName] = fieldValue;
391
+ }
392
+ }
393
+ return {
394
+ ...item,
395
+ fields: updatedFields
396
+ };
397
+ });
398
+ return {
399
+ ...data,
400
+ items: itemsWithDenormalizedFields
401
+ };
402
+ }
403
+ let renderedData;
404
+ if (filteredData) {
405
+ if (((_c = filteredData == null ? void 0 : filteredData.items) == null ? void 0 : _c.length) === 0) {
406
+ return /* @__PURE__ */ import_react.default.createElement("div", { className }, "No published entry found");
407
+ }
408
+ renderedData = noAutoRepeat ? children : (_e = (_d = denormalizeData(filteredData)) == null ? void 0 : _d.items) == null ? void 0 : _e.map(
409
+ (item, index) => {
410
+ var _a2;
411
+ return /* @__PURE__ */ import_react.default.createElement(
412
+ import_host.DataProvider,
413
+ {
414
+ key: (_a2 = item == null ? void 0 : item.sys) == null ? void 0 : _a2.id,
415
+ name: "contentfulItem",
416
+ data: item,
417
+ hidden: true
418
+ },
419
+ /* @__PURE__ */ import_react.default.createElement(
420
+ import_host.DataProvider,
421
+ {
422
+ name: makeDataProviderName(contentType),
423
+ data: item
424
+ },
425
+ (0, import_host.repeatedElement)(index, children)
426
+ )
427
+ );
428
+ }
429
+ );
430
+ } else {
431
+ if (((_f = entriesData == null ? void 0 : entriesData.items) == null ? void 0 : _f.length) === 0) {
432
+ return /* @__PURE__ */ import_react.default.createElement("div", { className }, contentType, " is empty");
433
+ }
434
+ renderedData = noAutoRepeat ? children : (_h = (_g = denormalizeData(entriesData)) == null ? void 0 : _g.items) == null ? void 0 : _h.map((item, index) => {
435
+ var _a2;
436
+ return /* @__PURE__ */ import_react.default.createElement(
437
+ import_host.DataProvider,
438
+ {
439
+ key: (_a2 = item == null ? void 0 : item.sys) == null ? void 0 : _a2.id,
440
+ name: "contentfulItem",
441
+ data: item,
442
+ hidden: true
443
+ },
444
+ /* @__PURE__ */ import_react.default.createElement(import_host.DataProvider, { name: makeDataProviderName(contentType), data: item }, (0, import_host.repeatedElement)(index, children))
445
+ );
446
+ });
447
+ }
448
+ return /* @__PURE__ */ import_react.default.createElement(import_host.DataProvider, { name: "contentfulItems", data: entriesData == null ? void 0 : entriesData.items }, noLayout ? /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, " ", renderedData, " ") : /* @__PURE__ */ import_react.default.createElement("div", { className }, " ", renderedData, " "));
449
+ }
450
+ var ContentfulFieldMeta = {
451
+ name: "ContentfulField",
452
+ displayName: "Contentful Field",
453
+ importName: "ContentfulField",
454
+ importPath: modulePath,
455
+ props: {
456
+ objectPath: {
457
+ type: "dataSelector",
458
+ data: (props, ctx) => {
459
+ var _a;
460
+ return (_a = ctx == null ? void 0 : ctx.data) != null ? _a : {};
461
+ },
462
+ displayName: "Field",
463
+ description: "Field to be displayed."
464
+ }
465
+ }
466
+ };
467
+ function ContentfulField({
468
+ className,
469
+ objectPath,
470
+ setControlContextData
471
+ }) {
472
+ var _a;
473
+ const item = (_a = (0, import_host.useSelector)("contentfulItem")) == null ? void 0 : _a.fields;
474
+ if (!item) {
475
+ return /* @__PURE__ */ import_react.default.createElement("div", null, "ContentfulField must be used within a ContentfulFetcher ");
476
+ }
477
+ setControlContextData == null ? void 0 : setControlContextData({
478
+ data: item
479
+ });
480
+ if (!objectPath) {
481
+ return /* @__PURE__ */ import_react.default.createElement("div", null, "Please specify a valid path or select a field.");
482
+ }
483
+ const data = (0, import_dlv.default)(item, objectPath);
484
+ if (typeof data === "object" && "nodeType" in data && data.nodeType === "document") {
485
+ return /* @__PURE__ */ import_react.default.createElement(
486
+ "div",
487
+ {
488
+ className,
489
+ dangerouslySetInnerHTML: { __html: (0, import_rich_text_html_renderer.documentToHtmlString)(data) }
490
+ }
491
+ );
492
+ } else if (typeof data === "object" && data.sys.linkType === "Asset" && data.url) {
493
+ return /* @__PURE__ */ import_react.default.createElement("img", { className, src: data.url });
494
+ } else if (!data) {
495
+ return /* @__PURE__ */ import_react.default.createElement("div", null, "Please specify a valid field.");
496
+ } else if (typeof data !== "object") {
497
+ return /* @__PURE__ */ import_react.default.createElement("div", { className }, data);
498
+ } else {
499
+ return /* @__PURE__ */ import_react.default.createElement("div", { className }, data.toString());
500
+ }
501
+ }
502
+
503
+ // src/index.tsx
504
+ function registerAll(loader) {
505
+ const _registerComponent = (Component, defaultMeta) => {
506
+ if (loader) {
507
+ loader.registerComponent(Component, defaultMeta);
508
+ } else {
509
+ (0, import_registerComponent.default)(Component, defaultMeta);
510
+ }
511
+ };
512
+ if (loader) {
513
+ loader.registerGlobalContext(
514
+ ContentfulCredentialsProvider,
515
+ ContentfulCredentialsProviderMeta
516
+ );
517
+ } else {
518
+ (0, import_registerGlobalContext.default)(
519
+ ContentfulCredentialsProvider,
520
+ ContentfulCredentialsProviderMeta
521
+ );
522
+ }
523
+ _registerComponent(ContentfulFetcher, ContentfulFetcherMeta);
524
+ _registerComponent(ContentfulField, ContentfulFieldMeta);
8
525
  }
526
+ // Annotate the CommonJS export names for ESM import in node:
527
+ 0 && (module.exports = {
528
+ ContentfulCredentialsProvider,
529
+ ContentfulCredentialsProviderMeta,
530
+ ContentfulFetcher,
531
+ ContentfulFetcherMeta,
532
+ ContentfulField,
533
+ ContentfulFieldMeta,
534
+ ensure,
535
+ registerAll
536
+ });