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