@daouypkgs/daouy-contentful 0.0.182
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/LICENSE +21 -0
- package/README.md +1 -0
- package/dist/index.d.ts +64 -0
- package/dist/index.esm.js +493 -0
- package/dist/index.esm.js.map +7 -0
- package/dist/index.js +515 -0
- package/dist/index.js.map +7 -0
- package/package.json +65 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 Latipov Abdukhamid
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Daouy components and registration calls for Contentful
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { ComponentMeta } from '@daouy/host';
|
|
2
|
+
import { GlobalContextMeta } from '@daouy/host';
|
|
3
|
+
import { default as React_2 } from 'react';
|
|
4
|
+
import { ReactNode } from 'react';
|
|
5
|
+
import registerComponent from '@daouy/host/registerComponent';
|
|
6
|
+
import registerGlobalContext from '@daouy/host/registerGlobalContext';
|
|
7
|
+
|
|
8
|
+
declare interface ContentfulControlContextData {
|
|
9
|
+
types?: {
|
|
10
|
+
name: string;
|
|
11
|
+
id: string;
|
|
12
|
+
}[];
|
|
13
|
+
fields?: string[];
|
|
14
|
+
queryOptions?: [];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export declare function ContentfulCredentialsProvider({ accessToken, space, environment, children, }: React_2.PropsWithChildren<ContentfulCredentialsProviderProps>): React_2.JSX.Element;
|
|
18
|
+
|
|
19
|
+
export declare const ContentfulCredentialsProviderMeta: GlobalContextMeta<ContentfulCredentialsProviderProps>;
|
|
20
|
+
|
|
21
|
+
declare interface ContentfulCredentialsProviderProps {
|
|
22
|
+
space: string;
|
|
23
|
+
accessToken: string;
|
|
24
|
+
environment?: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export declare function ContentfulFetcher({ filterField, filterValue, searchParameter, noAutoRepeat, contentType, children, className, order, reverseOrder, limit, include, noLayout, setControlContextData, }: ContentfulFetcherProps): React_2.JSX.Element;
|
|
28
|
+
|
|
29
|
+
export declare const ContentfulFetcherMeta: ComponentMeta<ContentfulFetcherProps>;
|
|
30
|
+
|
|
31
|
+
declare interface ContentfulFetcherProps {
|
|
32
|
+
contentType: string;
|
|
33
|
+
children?: ReactNode;
|
|
34
|
+
className?: string;
|
|
35
|
+
limit?: number;
|
|
36
|
+
include?: number;
|
|
37
|
+
order?: string;
|
|
38
|
+
reverseOrder?: boolean;
|
|
39
|
+
filterField?: string;
|
|
40
|
+
searchParameter?: string;
|
|
41
|
+
filterValue?: string | number;
|
|
42
|
+
noAutoRepeat?: boolean;
|
|
43
|
+
noLayout?: boolean;
|
|
44
|
+
setControlContextData?: (data: ContentfulControlContextData) => void;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export declare function ContentfulField({ className, objectPath, setControlContextData, }: ContentfulFieldProps): React_2.JSX.Element;
|
|
48
|
+
|
|
49
|
+
export declare const ContentfulFieldMeta: ComponentMeta<ContentfulFieldProps>;
|
|
50
|
+
|
|
51
|
+
declare interface ContentfulFieldProps {
|
|
52
|
+
className?: string;
|
|
53
|
+
objectPath?: (string | number)[];
|
|
54
|
+
setControlContextData?: (data: {
|
|
55
|
+
data: object;
|
|
56
|
+
}) => void;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export declare function registerAll(loader?: {
|
|
60
|
+
registerComponent: typeof registerComponent;
|
|
61
|
+
registerGlobalContext: typeof registerGlobalContext;
|
|
62
|
+
}): void;
|
|
63
|
+
|
|
64
|
+
export { }
|
|
@@ -0,0 +1,493 @@
|
|
|
1
|
+
var __async = (__this, __arguments, generator) => {
|
|
2
|
+
return new Promise((resolve, reject) => {
|
|
3
|
+
var fulfilled = (value) => {
|
|
4
|
+
try {
|
|
5
|
+
step(generator.next(value));
|
|
6
|
+
} catch (e) {
|
|
7
|
+
reject(e);
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
var rejected = (value) => {
|
|
11
|
+
try {
|
|
12
|
+
step(generator.throw(value));
|
|
13
|
+
} catch (e) {
|
|
14
|
+
reject(e);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
18
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
// src/index.tsx
|
|
23
|
+
import registerComponent from "@daouy/host/registerComponent";
|
|
24
|
+
import registerGlobalContext from "@daouy/host/registerGlobalContext";
|
|
25
|
+
|
|
26
|
+
// src/contentful.tsx
|
|
27
|
+
import { documentToHtmlString } from "@contentful/rich-text-html-renderer";
|
|
28
|
+
import {
|
|
29
|
+
DataProvider,
|
|
30
|
+
repeatedElement,
|
|
31
|
+
useSelector
|
|
32
|
+
} from "@daouy/host";
|
|
33
|
+
import { useDaouyQueryData } from "@daouy/query";
|
|
34
|
+
import {
|
|
35
|
+
_denormalizeData as denormalizeData,
|
|
36
|
+
_ensure as ensure,
|
|
37
|
+
_uniq as uniq
|
|
38
|
+
} from "@daouypkgs/contentful";
|
|
39
|
+
import { pascalCase } from "change-case";
|
|
40
|
+
import get from "dlv";
|
|
41
|
+
import React, { useContext } from "react";
|
|
42
|
+
|
|
43
|
+
// src/utils.ts
|
|
44
|
+
var searchParameters = [
|
|
45
|
+
{
|
|
46
|
+
value: "[lt]",
|
|
47
|
+
label: "Less than"
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
value: "[lte]",
|
|
51
|
+
label: "Less than or equal"
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
value: "[gt]",
|
|
55
|
+
label: "Greater than"
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
value: "[gte]",
|
|
59
|
+
label: "Greater than or equal "
|
|
60
|
+
}
|
|
61
|
+
];
|
|
62
|
+
|
|
63
|
+
// src/contentful.tsx
|
|
64
|
+
var modulePath = "@daouypkgs/daouy-contentful";
|
|
65
|
+
var makeDataProviderName = (contentType) => `currentContentful${pascalCase(contentType)}Item`;
|
|
66
|
+
var CredentialsContext = React.createContext(void 0);
|
|
67
|
+
var ContentfulCredentialsProviderMeta = {
|
|
68
|
+
name: "Contentful CredentialsProvider",
|
|
69
|
+
displayName: "Contentful Credentials Provider",
|
|
70
|
+
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/).",
|
|
71
|
+
importName: "ContentfulCredentialsProvider",
|
|
72
|
+
importPath: modulePath,
|
|
73
|
+
props: {
|
|
74
|
+
space: {
|
|
75
|
+
type: "string",
|
|
76
|
+
displayName: "Space",
|
|
77
|
+
description: "Name of your space",
|
|
78
|
+
defaultValue: "lmfbwqzbh93n"
|
|
79
|
+
},
|
|
80
|
+
accessToken: {
|
|
81
|
+
type: "string",
|
|
82
|
+
displayName: "Access Token ",
|
|
83
|
+
description: "Access Token",
|
|
84
|
+
defaultValue: "aWvf6oSLTuqxKCxSUpokajdQr84hGQFE6zoJG7DVVLg"
|
|
85
|
+
},
|
|
86
|
+
environment: {
|
|
87
|
+
type: "string",
|
|
88
|
+
displayName: "Environment",
|
|
89
|
+
defaultValue: "master"
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
function ContentfulCredentialsProvider({
|
|
94
|
+
accessToken,
|
|
95
|
+
space,
|
|
96
|
+
environment,
|
|
97
|
+
children
|
|
98
|
+
}) {
|
|
99
|
+
return /* @__PURE__ */ React.createElement(CredentialsContext.Provider, { value: { space, accessToken, environment } }, children);
|
|
100
|
+
}
|
|
101
|
+
var ContentfulFetcherMeta = {
|
|
102
|
+
name: "ContentfulFetcher",
|
|
103
|
+
displayName: "Contentful Fetcher",
|
|
104
|
+
importName: "ContentfulFetcher",
|
|
105
|
+
importPath: modulePath,
|
|
106
|
+
providesData: true,
|
|
107
|
+
description: "Fetches Contentful data and repeats content of children once for every row fetched. ",
|
|
108
|
+
defaultStyles: {
|
|
109
|
+
display: "grid",
|
|
110
|
+
gridTemplateColumns: "1fr 1fr 1fr 1fr",
|
|
111
|
+
gridRowGap: "8px",
|
|
112
|
+
gridColumnGap: "8px",
|
|
113
|
+
padding: "8px",
|
|
114
|
+
maxWidth: "100%"
|
|
115
|
+
},
|
|
116
|
+
props: {
|
|
117
|
+
children: {
|
|
118
|
+
type: "slot",
|
|
119
|
+
defaultValue: {
|
|
120
|
+
type: "vbox",
|
|
121
|
+
styles: {
|
|
122
|
+
padding: "8px"
|
|
123
|
+
},
|
|
124
|
+
children: {
|
|
125
|
+
type: "component",
|
|
126
|
+
name: "ContentfulField"
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
},
|
|
130
|
+
contentType: {
|
|
131
|
+
type: "choice",
|
|
132
|
+
options: (_props, ctx) => {
|
|
133
|
+
var _a, _b;
|
|
134
|
+
return (_b = (_a = ctx == null ? void 0 : ctx.types) == null ? void 0 : _a.map((type) => {
|
|
135
|
+
var _a2;
|
|
136
|
+
return {
|
|
137
|
+
label: type == null ? void 0 : type.name,
|
|
138
|
+
value: (_a2 = type == null ? void 0 : type.sys) == null ? void 0 : _a2.id
|
|
139
|
+
};
|
|
140
|
+
})) != null ? _b : [];
|
|
141
|
+
},
|
|
142
|
+
displayName: "Content type",
|
|
143
|
+
description: "Content type to be queried."
|
|
144
|
+
},
|
|
145
|
+
filterField: {
|
|
146
|
+
type: "choice",
|
|
147
|
+
displayName: "Filter field",
|
|
148
|
+
description: "Field (from Collection) to filter by.",
|
|
149
|
+
options: (_props, ctx) => {
|
|
150
|
+
var _a;
|
|
151
|
+
return (_a = ctx == null ? void 0 : ctx.fields) != null ? _a : [];
|
|
152
|
+
},
|
|
153
|
+
hidden: (props) => !props.contentType
|
|
154
|
+
},
|
|
155
|
+
searchParameter: {
|
|
156
|
+
type: "choice",
|
|
157
|
+
displayName: "Search Parameter",
|
|
158
|
+
description: "Search Parameter to filter by (see Contentful Content Delivery API documentation for details).",
|
|
159
|
+
options: (_props, ctx) => {
|
|
160
|
+
var _a;
|
|
161
|
+
return (_a = ctx == null ? void 0 : ctx.queryOptions) != null ? _a : [];
|
|
162
|
+
},
|
|
163
|
+
hidden: (props) => !props.filterField
|
|
164
|
+
},
|
|
165
|
+
filterValue: {
|
|
166
|
+
type: "string",
|
|
167
|
+
displayName: "Filter value",
|
|
168
|
+
description: "Value to filter by, should be of filter field type.",
|
|
169
|
+
hidden: (props) => !props.searchParameter
|
|
170
|
+
},
|
|
171
|
+
order: {
|
|
172
|
+
type: "choice",
|
|
173
|
+
displayName: "Order",
|
|
174
|
+
description: "Field that the entries should be ordered by.",
|
|
175
|
+
options: (_props, ctx) => {
|
|
176
|
+
var _a;
|
|
177
|
+
return [
|
|
178
|
+
...(_a = ctx == null ? void 0 : ctx.fields) != null ? _a : [],
|
|
179
|
+
"sys.createdAt",
|
|
180
|
+
"sys.updatedAt"
|
|
181
|
+
];
|
|
182
|
+
},
|
|
183
|
+
hidden: (props) => !props.contentType
|
|
184
|
+
},
|
|
185
|
+
reverseOrder: {
|
|
186
|
+
type: "boolean",
|
|
187
|
+
displayName: "Reverse order",
|
|
188
|
+
description: "Reverse the order of the entries.",
|
|
189
|
+
defaultValue: false,
|
|
190
|
+
hidden: (props) => !props.order
|
|
191
|
+
},
|
|
192
|
+
limit: {
|
|
193
|
+
type: "number",
|
|
194
|
+
displayName: "Limit",
|
|
195
|
+
description: "Limit the number of entries that are returned."
|
|
196
|
+
},
|
|
197
|
+
include: {
|
|
198
|
+
type: "number",
|
|
199
|
+
displayName: "Linked items depth",
|
|
200
|
+
defaultValueHint: 1,
|
|
201
|
+
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.",
|
|
202
|
+
max: 10,
|
|
203
|
+
min: 0
|
|
204
|
+
},
|
|
205
|
+
noAutoRepeat: {
|
|
206
|
+
type: "boolean",
|
|
207
|
+
displayName: "No auto-repeat",
|
|
208
|
+
description: "Do not automatically repeat children for every entry.",
|
|
209
|
+
defaultValue: false
|
|
210
|
+
},
|
|
211
|
+
noLayout: {
|
|
212
|
+
type: "boolean",
|
|
213
|
+
displayName: "No layout",
|
|
214
|
+
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.",
|
|
215
|
+
defaultValue: false
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
};
|
|
219
|
+
function ContentfulFetcher({
|
|
220
|
+
filterField,
|
|
221
|
+
filterValue,
|
|
222
|
+
searchParameter,
|
|
223
|
+
noAutoRepeat,
|
|
224
|
+
contentType,
|
|
225
|
+
children,
|
|
226
|
+
className,
|
|
227
|
+
order,
|
|
228
|
+
reverseOrder,
|
|
229
|
+
limit,
|
|
230
|
+
include,
|
|
231
|
+
noLayout,
|
|
232
|
+
setControlContextData
|
|
233
|
+
}) {
|
|
234
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
235
|
+
const creds = ensure(
|
|
236
|
+
useContext(CredentialsContext),
|
|
237
|
+
"Could not find context with current credentials"
|
|
238
|
+
);
|
|
239
|
+
const cacheKey = JSON.stringify({
|
|
240
|
+
include,
|
|
241
|
+
order,
|
|
242
|
+
reverseOrder,
|
|
243
|
+
limit,
|
|
244
|
+
filterField,
|
|
245
|
+
filterValue,
|
|
246
|
+
searchParameter,
|
|
247
|
+
creds
|
|
248
|
+
});
|
|
249
|
+
const baseUrl = "https://cdn.contentful.com";
|
|
250
|
+
const { data: contentTypes } = useDaouyQueryData(
|
|
251
|
+
`${cacheKey}/contentTypes`,
|
|
252
|
+
() => __async(this, null, function* () {
|
|
253
|
+
const resp = yield fetch(
|
|
254
|
+
`${baseUrl}/spaces/${creds.space}/environments/${creds.environment}/content_types?access_token=${creds.accessToken}`
|
|
255
|
+
);
|
|
256
|
+
return resp.json();
|
|
257
|
+
})
|
|
258
|
+
);
|
|
259
|
+
setControlContextData == null ? void 0 : setControlContextData({
|
|
260
|
+
types: (_a = contentTypes == null ? void 0 : contentTypes.items) != null ? _a : []
|
|
261
|
+
});
|
|
262
|
+
function setOrderField(searchParams) {
|
|
263
|
+
if (order) {
|
|
264
|
+
searchParams.set(
|
|
265
|
+
"order",
|
|
266
|
+
`${reverseOrder ? "-" : ""}${order.startsWith("sys.") ? order : `fields.${order}`}`
|
|
267
|
+
);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
const { data: entriesData } = useDaouyQueryData(
|
|
271
|
+
contentType ? `${cacheKey}/${contentType}/entriesData` : null,
|
|
272
|
+
() => __async(this, null, function* () {
|
|
273
|
+
const path = `/spaces/${creds.space}/environments/${creds.environment}/entries`;
|
|
274
|
+
const searchParams = new URLSearchParams();
|
|
275
|
+
searchParams.set("access_token", creds.accessToken);
|
|
276
|
+
searchParams.set("content_type", contentType);
|
|
277
|
+
if (limit) {
|
|
278
|
+
searchParams.set("limit", limit.toString());
|
|
279
|
+
}
|
|
280
|
+
setOrderField(searchParams);
|
|
281
|
+
if (include) {
|
|
282
|
+
searchParams.set("include", include.toString());
|
|
283
|
+
}
|
|
284
|
+
const resp = yield fetch(`${baseUrl}${path}?${searchParams.toString()}`);
|
|
285
|
+
return resp.json();
|
|
286
|
+
})
|
|
287
|
+
);
|
|
288
|
+
const { data: filteredData } = useDaouyQueryData(
|
|
289
|
+
contentType && filterField && filterValue ? `${cacheKey}/${contentType}/filteredData` : null,
|
|
290
|
+
() => __async(this, null, function* () {
|
|
291
|
+
const path = `/spaces/${creds.space}/environments/${creds.environment}/entries`;
|
|
292
|
+
const searchParams = new URLSearchParams();
|
|
293
|
+
searchParams.set("access_token", creds.accessToken);
|
|
294
|
+
searchParams.set("content_type", contentType);
|
|
295
|
+
if (limit) {
|
|
296
|
+
searchParams.set("limit", limit.toString());
|
|
297
|
+
}
|
|
298
|
+
setOrderField(searchParams);
|
|
299
|
+
if (include) {
|
|
300
|
+
searchParams.set("include", include.toString());
|
|
301
|
+
}
|
|
302
|
+
if (filterField && searchParameter && filterValue) {
|
|
303
|
+
searchParams.set(
|
|
304
|
+
`fields.${filterField}${searchParameter}`,
|
|
305
|
+
filterValue.toString()
|
|
306
|
+
);
|
|
307
|
+
}
|
|
308
|
+
const resp = yield fetch(`${baseUrl}${path}?${searchParams.toString()}`);
|
|
309
|
+
return resp.json();
|
|
310
|
+
})
|
|
311
|
+
);
|
|
312
|
+
if (!creds.space || !creds.accessToken) {
|
|
313
|
+
return /* @__PURE__ */ React.createElement("div", null, "Please specify a valid API Credentials: Space, Access Token and Environment");
|
|
314
|
+
}
|
|
315
|
+
if (!contentTypes) {
|
|
316
|
+
return /* @__PURE__ */ React.createElement("div", null, "Please configure the Contentful credentials");
|
|
317
|
+
}
|
|
318
|
+
if (!entriesData) {
|
|
319
|
+
return /* @__PURE__ */ React.createElement("div", null, "Please select a content type");
|
|
320
|
+
}
|
|
321
|
+
const filterFields = entriesData == null ? void 0 : entriesData.items.flatMap((item) => {
|
|
322
|
+
const fields = Object.keys(item.fields).filter((field) => {
|
|
323
|
+
const value = get(item, field);
|
|
324
|
+
return typeof value !== "object" && field !== "photos";
|
|
325
|
+
});
|
|
326
|
+
return fields;
|
|
327
|
+
});
|
|
328
|
+
let operators;
|
|
329
|
+
const matchedFields = Object.values(entriesData.items).map((item) => {
|
|
330
|
+
const fields = Object.entries(item.fields).find(
|
|
331
|
+
(el) => el[0] === filterField
|
|
332
|
+
);
|
|
333
|
+
return fields;
|
|
334
|
+
});
|
|
335
|
+
Object.values(matchedFields).map((model) => Array.isArray(model) ? model : [model]).map((item) => {
|
|
336
|
+
if (typeof item[1] === "number" && typeof item[1] !== "object") {
|
|
337
|
+
operators = searchParameters;
|
|
338
|
+
} else if (typeof item[1] !== "number" && typeof item[1] !== "object" && typeof item[1] === "string") {
|
|
339
|
+
operators = [
|
|
340
|
+
{
|
|
341
|
+
value: "[match]",
|
|
342
|
+
label: "Full text search"
|
|
343
|
+
}
|
|
344
|
+
];
|
|
345
|
+
}
|
|
346
|
+
});
|
|
347
|
+
setControlContextData == null ? void 0 : setControlContextData({
|
|
348
|
+
queryOptions: operators != null ? operators : [],
|
|
349
|
+
types: (_b = contentTypes == null ? void 0 : contentTypes.items) != null ? _b : [],
|
|
350
|
+
fields: uniq(filterFields != null ? filterFields : [])
|
|
351
|
+
});
|
|
352
|
+
if (filterField) {
|
|
353
|
+
if (!searchParameter) {
|
|
354
|
+
return /* @__PURE__ */ React.createElement("div", null, "Please specify a Search Parameter");
|
|
355
|
+
}
|
|
356
|
+
if (!filterValue) {
|
|
357
|
+
return /* @__PURE__ */ React.createElement("div", null, "Please specify a Filter value");
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
let renderedData;
|
|
361
|
+
const fixedData = entriesData ? denormalizeData(entriesData) : void 0;
|
|
362
|
+
if (filteredData) {
|
|
363
|
+
if (((_c = filteredData == null ? void 0 : filteredData.items) == null ? void 0 : _c.length) === 0) {
|
|
364
|
+
return /* @__PURE__ */ React.createElement("div", { className }, "No published entry found");
|
|
365
|
+
}
|
|
366
|
+
renderedData = noAutoRepeat ? children : (_e = (_d = denormalizeData(filteredData)) == null ? void 0 : _d.items) == null ? void 0 : _e.map(
|
|
367
|
+
(item, index) => {
|
|
368
|
+
var _a2;
|
|
369
|
+
return /* @__PURE__ */ React.createElement(
|
|
370
|
+
DataProvider,
|
|
371
|
+
{
|
|
372
|
+
key: (_a2 = item == null ? void 0 : item.sys) == null ? void 0 : _a2.id,
|
|
373
|
+
name: "contentfulItem",
|
|
374
|
+
data: item,
|
|
375
|
+
hidden: true
|
|
376
|
+
},
|
|
377
|
+
/* @__PURE__ */ React.createElement(
|
|
378
|
+
DataProvider,
|
|
379
|
+
{
|
|
380
|
+
name: makeDataProviderName(contentType),
|
|
381
|
+
data: item
|
|
382
|
+
},
|
|
383
|
+
repeatedElement(index, children)
|
|
384
|
+
)
|
|
385
|
+
);
|
|
386
|
+
}
|
|
387
|
+
);
|
|
388
|
+
} else {
|
|
389
|
+
if (((_f = fixedData == null ? void 0 : fixedData.items) == null ? void 0 : _f.length) === 0) {
|
|
390
|
+
return /* @__PURE__ */ React.createElement("div", { className }, contentType, " is empty");
|
|
391
|
+
}
|
|
392
|
+
renderedData = noAutoRepeat ? children : (_g = fixedData == null ? void 0 : fixedData.items) == null ? void 0 : _g.map((item, index) => {
|
|
393
|
+
var _a2;
|
|
394
|
+
return /* @__PURE__ */ React.createElement(
|
|
395
|
+
DataProvider,
|
|
396
|
+
{
|
|
397
|
+
key: (_a2 = item == null ? void 0 : item.sys) == null ? void 0 : _a2.id,
|
|
398
|
+
name: "contentfulItem",
|
|
399
|
+
data: item,
|
|
400
|
+
hidden: true
|
|
401
|
+
},
|
|
402
|
+
/* @__PURE__ */ React.createElement(DataProvider, { name: makeDataProviderName(contentType), data: item }, repeatedElement(index, children))
|
|
403
|
+
);
|
|
404
|
+
});
|
|
405
|
+
}
|
|
406
|
+
return /* @__PURE__ */ React.createElement(DataProvider, { name: "contentfulItems", data: fixedData == null ? void 0 : fixedData.items }, noLayout ? /* @__PURE__ */ React.createElement(React.Fragment, null, " ", renderedData, " ") : /* @__PURE__ */ React.createElement("div", { className }, " ", renderedData, " "));
|
|
407
|
+
}
|
|
408
|
+
var ContentfulFieldMeta = {
|
|
409
|
+
name: "ContentfulField",
|
|
410
|
+
displayName: "Contentful Field",
|
|
411
|
+
importName: "ContentfulField",
|
|
412
|
+
importPath: modulePath,
|
|
413
|
+
props: {
|
|
414
|
+
objectPath: {
|
|
415
|
+
type: "dataSelector",
|
|
416
|
+
data: (_props, ctx) => {
|
|
417
|
+
var _a;
|
|
418
|
+
return (_a = ctx == null ? void 0 : ctx.data) != null ? _a : {};
|
|
419
|
+
},
|
|
420
|
+
displayName: "Field",
|
|
421
|
+
description: "Field to be displayed."
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
};
|
|
425
|
+
function ContentfulField({
|
|
426
|
+
className,
|
|
427
|
+
objectPath,
|
|
428
|
+
setControlContextData
|
|
429
|
+
}) {
|
|
430
|
+
var _a, _b;
|
|
431
|
+
const item = (_a = useSelector("contentfulItem")) == null ? void 0 : _a.fields;
|
|
432
|
+
if (!item) {
|
|
433
|
+
return /* @__PURE__ */ React.createElement("div", null, "ContentfulField must be used within a ContentfulFetcher ");
|
|
434
|
+
}
|
|
435
|
+
setControlContextData == null ? void 0 : setControlContextData({
|
|
436
|
+
data: item
|
|
437
|
+
});
|
|
438
|
+
if (!objectPath) {
|
|
439
|
+
return /* @__PURE__ */ React.createElement("div", null, "Please specify a valid path or select a field.");
|
|
440
|
+
}
|
|
441
|
+
const data = get(item, objectPath);
|
|
442
|
+
if (typeof data === "object" && "nodeType" in data && data.nodeType === "document") {
|
|
443
|
+
return /* @__PURE__ */ React.createElement(
|
|
444
|
+
"div",
|
|
445
|
+
{
|
|
446
|
+
className,
|
|
447
|
+
dangerouslySetInnerHTML: { __html: documentToHtmlString(data) }
|
|
448
|
+
}
|
|
449
|
+
);
|
|
450
|
+
} else if (typeof data === "object" && ((_b = data.sys) == null ? void 0 : _b.linkType) === "Asset" && data.url) {
|
|
451
|
+
return /* @__PURE__ */ React.createElement("img", { className, src: data.url });
|
|
452
|
+
} else if (!data) {
|
|
453
|
+
return /* @__PURE__ */ React.createElement("div", null, "Please specify a valid field.");
|
|
454
|
+
} else if (typeof data !== "object") {
|
|
455
|
+
return /* @__PURE__ */ React.createElement("div", { className }, data);
|
|
456
|
+
} else {
|
|
457
|
+
return /* @__PURE__ */ React.createElement("div", { className }, data.toString());
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
// src/index.tsx
|
|
462
|
+
function registerAll(loader) {
|
|
463
|
+
const _registerComponent = (Component, defaultMeta) => {
|
|
464
|
+
if (loader) {
|
|
465
|
+
loader.registerComponent(Component, defaultMeta);
|
|
466
|
+
} else {
|
|
467
|
+
registerComponent(Component, defaultMeta);
|
|
468
|
+
}
|
|
469
|
+
};
|
|
470
|
+
if (loader) {
|
|
471
|
+
loader.registerGlobalContext(
|
|
472
|
+
ContentfulCredentialsProvider,
|
|
473
|
+
ContentfulCredentialsProviderMeta
|
|
474
|
+
);
|
|
475
|
+
} else {
|
|
476
|
+
registerGlobalContext(
|
|
477
|
+
ContentfulCredentialsProvider,
|
|
478
|
+
ContentfulCredentialsProviderMeta
|
|
479
|
+
);
|
|
480
|
+
}
|
|
481
|
+
_registerComponent(ContentfulFetcher, ContentfulFetcherMeta);
|
|
482
|
+
_registerComponent(ContentfulField, ContentfulFieldMeta);
|
|
483
|
+
}
|
|
484
|
+
export {
|
|
485
|
+
ContentfulCredentialsProvider,
|
|
486
|
+
ContentfulCredentialsProviderMeta,
|
|
487
|
+
ContentfulFetcher,
|
|
488
|
+
ContentfulFetcherMeta,
|
|
489
|
+
ContentfulField,
|
|
490
|
+
ContentfulFieldMeta,
|
|
491
|
+
registerAll
|
|
492
|
+
};
|
|
493
|
+
//# sourceMappingURL=index.esm.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/index.tsx", "../src/contentful.tsx", "../src/utils.ts"],
|
|
4
|
+
"sourcesContent": ["import registerComponent, {\n ComponentMeta,\n} from \"@daouy/host/registerComponent\";\nimport registerGlobalContext from \"@daouy/host/registerGlobalContext\";\nimport {\n ContentfulCredentialsProvider,\n ContentfulCredentialsProviderMeta,\n ContentfulFetcher,\n ContentfulFetcherMeta,\n ContentfulField,\n ContentfulFieldMeta,\n} from \"./contentful\";\n\nexport function registerAll(loader?: {\n registerComponent: typeof registerComponent;\n registerGlobalContext: typeof registerGlobalContext;\n}) {\n const _registerComponent = <T extends React.ComponentType<any>>(\n Component: T,\n defaultMeta: ComponentMeta<React.ComponentProps<T>>\n ) => {\n if (loader) {\n loader.registerComponent(Component, defaultMeta);\n } else {\n registerComponent(Component, defaultMeta);\n }\n };\n\n if (loader) {\n loader.registerGlobalContext(\n ContentfulCredentialsProvider,\n ContentfulCredentialsProviderMeta\n );\n } else {\n registerGlobalContext(\n ContentfulCredentialsProvider,\n ContentfulCredentialsProviderMeta\n );\n }\n _registerComponent(ContentfulFetcher, ContentfulFetcherMeta);\n _registerComponent(ContentfulField, ContentfulFieldMeta);\n}\n\nexport * from \"./contentful\";\n", "import { documentToHtmlString } from \"@contentful/rich-text-html-renderer\";\nimport {\n ComponentMeta,\n DataProvider,\n GlobalContextMeta,\n repeatedElement,\n useSelector,\n} from \"@daouy/host\";\nimport { useDaouyQueryData } from \"@daouy/query\";\nimport {\n _denormalizeData as denormalizeData,\n _ensure as ensure,\n _uniq as uniq,\n} from \"@daouypkgs/contentful\";\nimport { pascalCase } from \"change-case\";\nimport get from \"dlv\";\nimport React, { ReactNode, useContext } from \"react\";\nimport { searchParameters } from \"./utils\";\n\nconst modulePath = \"@daouypkgs/daouy-contentful\";\n\nconst makeDataProviderName = (contentType: string) =>\n `currentContentful${pascalCase(contentType)}Item`;\n\ninterface ContentfulCredentialsProviderProps {\n space: string;\n accessToken: string;\n environment?: string;\n}\n\nconst CredentialsContext = React.createContext<\n ContentfulCredentialsProviderProps | undefined\n>(undefined);\n\nexport const ContentfulCredentialsProviderMeta: GlobalContextMeta<ContentfulCredentialsProviderProps> =\n {\n name: \"Contentful CredentialsProvider\",\n displayName: \"Contentful Credentials Provider\",\n description:\n \"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/).\",\n importName: \"ContentfulCredentialsProvider\",\n importPath: modulePath,\n props: {\n space: {\n type: \"string\",\n displayName: \"Space\",\n description: \"Name of your space\",\n defaultValue: \"lmfbwqzbh93n\",\n },\n accessToken: {\n type: \"string\",\n displayName: \"Access Token \",\n description: \"Access Token\",\n defaultValue: \"aWvf6oSLTuqxKCxSUpokajdQr84hGQFE6zoJG7DVVLg\",\n },\n environment: {\n type: \"string\",\n displayName: \"Environment\",\n defaultValue: \"master\",\n },\n },\n };\n\nexport function ContentfulCredentialsProvider({\n accessToken,\n space,\n environment,\n children,\n}: React.PropsWithChildren<ContentfulCredentialsProviderProps>) {\n return (\n <CredentialsContext.Provider value={{ space, accessToken, environment }}>\n {children}\n </CredentialsContext.Provider>\n );\n}\n\ninterface ContentfulControlContextData {\n types?: { name: string; id: string }[];\n fields?: string[];\n queryOptions?: [];\n}\n\ninterface ContentfulFetcherProps {\n contentType: string;\n children?: ReactNode;\n className?: string;\n limit?: number;\n include?: number;\n order?: string;\n reverseOrder?: boolean;\n filterField?: string;\n searchParameter?: string;\n filterValue?: string | number;\n noAutoRepeat?: boolean;\n noLayout?: boolean;\n setControlContextData?: (data: ContentfulControlContextData) => void;\n}\n\nexport const ContentfulFetcherMeta: ComponentMeta<ContentfulFetcherProps> = {\n name: \"ContentfulFetcher\",\n displayName: \"Contentful Fetcher\",\n importName: \"ContentfulFetcher\",\n importPath: modulePath,\n providesData: true,\n description:\n \"Fetches Contentful data and repeats content of children once for every row fetched. \",\n defaultStyles: {\n display: \"grid\",\n gridTemplateColumns: \"1fr 1fr 1fr 1fr\",\n gridRowGap: \"8px\",\n gridColumnGap: \"8px\",\n padding: \"8px\",\n maxWidth: \"100%\",\n },\n props: {\n children: {\n type: \"slot\",\n defaultValue: {\n type: \"vbox\",\n styles: {\n padding: \"8px\",\n },\n children: {\n type: \"component\",\n name: \"ContentfulField\",\n },\n },\n },\n contentType: {\n type: \"choice\",\n options: (_props, ctx) =>\n ctx?.types?.map((type: any) => ({\n label: type?.name,\n value: type?.sys?.id,\n })) ?? [],\n displayName: \"Content type\",\n description: \"Content type to be queried.\",\n },\n\n filterField: {\n type: \"choice\",\n displayName: \"Filter field\",\n description: \"Field (from Collection) to filter by.\",\n options: (_props, ctx) => ctx?.fields ?? [],\n hidden: (props) => !props.contentType,\n },\n searchParameter: {\n type: \"choice\",\n displayName: \"Search Parameter\",\n description:\n \"Search Parameter to filter by (see Contentful Content Delivery API documentation for details).\",\n options: (_props, ctx) => ctx?.queryOptions ?? [],\n hidden: (props) => !props.filterField,\n },\n filterValue: {\n type: \"string\",\n displayName: \"Filter value\",\n description: \"Value to filter by, should be of filter field type.\",\n hidden: (props) => !props.searchParameter,\n },\n order: {\n type: \"choice\",\n displayName: \"Order\",\n description: \"Field that the entries should be ordered by.\",\n options: (_props, ctx) => [\n ...(ctx?.fields ?? []),\n \"sys.createdAt\",\n \"sys.updatedAt\",\n ],\n hidden: (props) => !props.contentType,\n },\n reverseOrder: {\n type: \"boolean\",\n displayName: \"Reverse order\",\n description: \"Reverse the order of the entries.\",\n defaultValue: false,\n hidden: (props) => !props.order,\n },\n limit: {\n type: \"number\",\n displayName: \"Limit\",\n description: \"Limit the number of entries that are returned.\",\n },\n include: {\n type: \"number\",\n displayName: \"Linked items depth\",\n defaultValueHint: 1,\n description:\n \"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.\",\n max: 10,\n min: 0,\n },\n noAutoRepeat: {\n type: \"boolean\",\n displayName: \"No auto-repeat\",\n description: \"Do not automatically repeat children for every entry.\",\n defaultValue: false,\n },\n noLayout: {\n type: \"boolean\",\n displayName: \"No layout\",\n description:\n \"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.\",\n defaultValue: false,\n },\n },\n};\n\nexport function ContentfulFetcher({\n filterField,\n filterValue,\n searchParameter,\n noAutoRepeat,\n contentType,\n children,\n className,\n order,\n reverseOrder,\n limit,\n include,\n noLayout,\n setControlContextData,\n}: ContentfulFetcherProps) {\n const creds = ensure(\n useContext(CredentialsContext),\n \"Could not find context with current credentials\"\n );\n const cacheKey = JSON.stringify({\n include,\n order,\n reverseOrder,\n limit,\n filterField,\n filterValue,\n searchParameter,\n creds,\n });\n\n const baseUrl = \"https://cdn.contentful.com\";\n\n const { data: contentTypes } = useDaouyQueryData<any | null>(\n `${cacheKey}/contentTypes`,\n async () => {\n const resp = await fetch(\n `${baseUrl}/spaces/${creds.space}/environments/${creds.environment}/content_types?access_token=${creds.accessToken}`\n );\n return resp.json();\n }\n );\n setControlContextData?.({\n types: contentTypes?.items ?? [],\n });\n\n function setOrderField(searchParams: URLSearchParams) {\n if (order) {\n searchParams.set(\n \"order\",\n `${reverseOrder ? \"-\" : \"\"}${\n order.startsWith(\"sys.\") ? order : `fields.${order}`\n }`\n );\n }\n }\n\n const { data: entriesData } = useDaouyQueryData<any | null>(\n contentType ? `${cacheKey}/${contentType}/entriesData` : null,\n async () => {\n const path = `/spaces/${creds.space}/environments/${creds.environment}/entries`;\n\n const searchParams = new URLSearchParams();\n searchParams.set(\"access_token\", creds.accessToken);\n searchParams.set(\"content_type\", contentType);\n if (limit) {\n searchParams.set(\"limit\", limit.toString());\n }\n setOrderField(searchParams);\n if (include) {\n searchParams.set(\"include\", include.toString());\n }\n\n const resp = await fetch(`${baseUrl}${path}?${searchParams.toString()}`);\n return resp.json();\n }\n );\n\n const { data: filteredData } = useDaouyQueryData<any | null>(\n contentType && filterField && filterValue\n ? `${cacheKey}/${contentType}/filteredData`\n : null,\n async () => {\n const path = `/spaces/${creds.space}/environments/${creds.environment}/entries`;\n\n const searchParams = new URLSearchParams();\n searchParams.set(\"access_token\", creds.accessToken);\n searchParams.set(\"content_type\", contentType);\n if (limit) {\n searchParams.set(\"limit\", limit.toString());\n }\n setOrderField(searchParams);\n\n if (include) {\n searchParams.set(\"include\", include.toString());\n }\n\n if (filterField && searchParameter && filterValue) {\n searchParams.set(\n `fields.${filterField}${searchParameter}`,\n filterValue.toString()\n );\n }\n\n const resp = await fetch(`${baseUrl}${path}?${searchParams.toString()}`);\n return resp.json();\n }\n );\n\n if (!creds.space || !creds.accessToken) {\n return (\n <div>\n Please specify a valid API Credentials: Space, Access Token and\n Environment\n </div>\n );\n }\n\n if (!contentTypes) {\n return <div>Please configure the Contentful credentials</div>;\n }\n\n if (!entriesData) {\n return <div>Please select a content type</div>;\n }\n\n const filterFields: string[] = entriesData?.items.flatMap((item: any) => {\n const fields = Object.keys(item.fields).filter((field) => {\n const value = get(item, field);\n return typeof value !== \"object\" && field !== \"photos\";\n });\n return fields;\n });\n\n let operators;\n const matchedFields = Object.values(entriesData.items).map((item: any) => {\n const fields = Object.entries(item.fields).find(\n (el) => el[0] === filterField\n );\n return fields;\n });\n\n Object.values(matchedFields)\n .map((model: any) => (Array.isArray(model) ? model : [model]))\n .map((item: any) => {\n if (typeof item[1] === \"number\" && typeof item[1] !== \"object\") {\n operators = searchParameters;\n } else if (\n typeof item[1] !== \"number\" &&\n typeof item[1] !== \"object\" &&\n typeof item[1] === \"string\"\n ) {\n operators = [\n {\n value: \"[match]\",\n label: \"Full text search\",\n },\n ];\n }\n });\n\n setControlContextData?.({\n queryOptions: operators ?? [],\n types: contentTypes?.items ?? [],\n fields: uniq(filterFields ?? []),\n });\n\n if (filterField) {\n if (!searchParameter) {\n return <div>Please specify a Search Parameter</div>;\n }\n if (!filterValue) {\n return <div>Please specify a Filter value</div>;\n }\n }\n\n let renderedData;\n\n const fixedData = entriesData ? denormalizeData(entriesData) : undefined;\n\n if (filteredData) {\n if (filteredData?.items?.length === 0) {\n return <div className={className}>No published entry found</div>;\n }\n\n renderedData = noAutoRepeat\n ? children\n : denormalizeData(filteredData)?.items?.map(\n (item: any, index: number) => (\n <DataProvider\n key={item?.sys?.id}\n name={\"contentfulItem\"}\n data={item}\n hidden={true}\n >\n <DataProvider\n name={makeDataProviderName(contentType)}\n data={item}\n >\n {repeatedElement(index, children)}\n </DataProvider>\n </DataProvider>\n )\n );\n } else {\n if (fixedData?.items?.length === 0) {\n return <div className={className}>{contentType} is empty</div>;\n }\n\n renderedData = noAutoRepeat\n ? children\n : fixedData?.items?.map((item: any, index: number) => (\n <DataProvider\n key={item?.sys?.id}\n name={\"contentfulItem\"}\n data={item}\n hidden={true}\n >\n <DataProvider name={makeDataProviderName(contentType)} data={item}>\n {repeatedElement(index, children)}\n </DataProvider>\n </DataProvider>\n ));\n }\n return (\n <DataProvider name=\"contentfulItems\" data={fixedData?.items}>\n {noLayout ? (\n <> {renderedData} </>\n ) : (\n <div className={className}> {renderedData} </div>\n )}\n </DataProvider>\n );\n}\ninterface ContentfulFieldProps {\n className?: string;\n objectPath?: (string | number)[];\n setControlContextData?: (data: { data: object }) => void;\n}\n\nexport const ContentfulFieldMeta: ComponentMeta<ContentfulFieldProps> = {\n name: \"ContentfulField\",\n displayName: \"Contentful Field\",\n importName: \"ContentfulField\",\n importPath: modulePath,\n props: {\n objectPath: {\n type: \"dataSelector\",\n data: (_props, ctx) => ctx?.data ?? {},\n displayName: \"Field\",\n description: \"Field to be displayed.\",\n },\n },\n};\n\nexport function ContentfulField({\n className,\n objectPath,\n setControlContextData,\n}: ContentfulFieldProps) {\n const item = useSelector(\"contentfulItem\")?.fields;\n if (!item) {\n return <div>ContentfulField must be used within a ContentfulFetcher </div>;\n }\n setControlContextData?.({\n data: item,\n });\n if (!objectPath) {\n return <div>Please specify a valid path or select a field.</div>;\n }\n\n const data = get(item, objectPath);\n if (\n typeof data === \"object\" &&\n \"nodeType\" in data &&\n data.nodeType === \"document\"\n ) {\n return (\n <div\n className={className}\n dangerouslySetInnerHTML={{ __html: documentToHtmlString(data) }}\n />\n );\n } else if (\n typeof data === \"object\" &&\n data.sys?.linkType === \"Asset\" &&\n data.url\n ) {\n return <img className={className} src={data.url} />;\n } else if (!data) {\n return <div>Please specify a valid field.</div>;\n } else if (typeof data !== \"object\") {\n return <div className={className}>{data}</div>;\n } else {\n return <div className={className}>{data.toString()}</div>;\n }\n}\n", "export const searchParameters = [\n {\n value: \"[lt]\",\n label: \"Less than\",\n },\n {\n value: \"[lte]\",\n label: \"Less than or equal\",\n },\n {\n value: \"[gt]\",\n label: \"Greater than\",\n },\n {\n value: \"[gte]\",\n label: \"Greater than or equal \",\n },\n];\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,uBAEA;AACP,OAAO,2BAA2B;;;ACHlC,SAAS,4BAA4B;AACrC;AAAA,EAEE;AAAA,EAEA;AAAA,EACA;AAAA,OACK;AACP,SAAS,yBAAyB;AAClC;AAAA,EACE,oBAAoB;AAAA,EACpB,WAAW;AAAA,EACX,SAAS;AAAA,OACJ;AACP,SAAS,kBAAkB;AAC3B,OAAO,SAAS;AAChB,OAAO,SAAoB,kBAAkB;;;AChBtC,IAAM,mBAAmB;AAAA,EAC9B;AAAA,IACE,OAAO;AAAA,IACP,OAAO;AAAA,EACT;AAAA,EACA;AAAA,IACE,OAAO;AAAA,IACP,OAAO;AAAA,EACT;AAAA,EACA;AAAA,IACE,OAAO;AAAA,IACP,OAAO;AAAA,EACT;AAA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AC1C,OAAO;AACL,WAAO,oCAAC,SAAI,aAAuB,KAAK,SAAS,CAAE;AAAA,EACrD;AACF;;;AD1eO,SAAS,YAAY,QAGzB;AACD,QAAM,qBAAqB,CACzB,WACA,gBACG;AACH,QAAI,QAAQ;AACV,aAAO,kBAAkB,WAAW,WAAW;AAAA,IACjD,OAAO;AACL,wBAAkB,WAAW,WAAW;AAAA,IAC1C;AAAA,EACF;AAEA,MAAI,QAAQ;AACV,WAAO;AAAA,MACL;AAAA,MACA;AAAA,IACF;AAAA,EACF,OAAO;AACL;AAAA,MACE;AAAA,MACA;AAAA,IACF;AAAA,EACF;AACA,qBAAmB,mBAAmB,qBAAqB;AAC3D,qBAAmB,iBAAiB,mBAAmB;AACzD;",
|
|
6
|
+
"names": ["_a"]
|
|
7
|
+
}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,515 @@
|
|
|
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);
|
|
29
|
+
var __async = (__this, __arguments, generator) => {
|
|
30
|
+
return new Promise((resolve, reject) => {
|
|
31
|
+
var fulfilled = (value) => {
|
|
32
|
+
try {
|
|
33
|
+
step(generator.next(value));
|
|
34
|
+
} catch (e) {
|
|
35
|
+
reject(e);
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
var rejected = (value) => {
|
|
39
|
+
try {
|
|
40
|
+
step(generator.throw(value));
|
|
41
|
+
} catch (e) {
|
|
42
|
+
reject(e);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
46
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
// src/index.tsx
|
|
51
|
+
var src_exports = {};
|
|
52
|
+
__export(src_exports, {
|
|
53
|
+
ContentfulCredentialsProvider: () => ContentfulCredentialsProvider,
|
|
54
|
+
ContentfulCredentialsProviderMeta: () => ContentfulCredentialsProviderMeta,
|
|
55
|
+
ContentfulFetcher: () => ContentfulFetcher,
|
|
56
|
+
ContentfulFetcherMeta: () => ContentfulFetcherMeta,
|
|
57
|
+
ContentfulField: () => ContentfulField,
|
|
58
|
+
ContentfulFieldMeta: () => ContentfulFieldMeta,
|
|
59
|
+
registerAll: () => registerAll
|
|
60
|
+
});
|
|
61
|
+
module.exports = __toCommonJS(src_exports);
|
|
62
|
+
var import_registerComponent = __toESM(require("@daouy/host/registerComponent"));
|
|
63
|
+
var import_registerGlobalContext = __toESM(require("@daouy/host/registerGlobalContext"));
|
|
64
|
+
|
|
65
|
+
// src/contentful.tsx
|
|
66
|
+
var import_rich_text_html_renderer = require("@contentful/rich-text-html-renderer");
|
|
67
|
+
var import_host = require("@daouy/host");
|
|
68
|
+
var import_query = require("@daouy/query");
|
|
69
|
+
var import_contentful = require("@daouypkgs/contentful");
|
|
70
|
+
var import_change_case = require("change-case");
|
|
71
|
+
var import_dlv = __toESM(require("dlv"));
|
|
72
|
+
var import_react = __toESM(require("react"));
|
|
73
|
+
|
|
74
|
+
// src/utils.ts
|
|
75
|
+
var searchParameters = [
|
|
76
|
+
{
|
|
77
|
+
value: "[lt]",
|
|
78
|
+
label: "Less than"
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
value: "[lte]",
|
|
82
|
+
label: "Less than or equal"
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
value: "[gt]",
|
|
86
|
+
label: "Greater than"
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
value: "[gte]",
|
|
90
|
+
label: "Greater than or equal "
|
|
91
|
+
}
|
|
92
|
+
];
|
|
93
|
+
|
|
94
|
+
// src/contentful.tsx
|
|
95
|
+
var modulePath = "@daouypkgs/daouy-contentful";
|
|
96
|
+
var makeDataProviderName = (contentType) => `currentContentful${(0, import_change_case.pascalCase)(contentType)}Item`;
|
|
97
|
+
var CredentialsContext = import_react.default.createContext(void 0);
|
|
98
|
+
var ContentfulCredentialsProviderMeta = {
|
|
99
|
+
name: "Contentful CredentialsProvider",
|
|
100
|
+
displayName: "Contentful Credentials Provider",
|
|
101
|
+
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/).",
|
|
102
|
+
importName: "ContentfulCredentialsProvider",
|
|
103
|
+
importPath: modulePath,
|
|
104
|
+
props: {
|
|
105
|
+
space: {
|
|
106
|
+
type: "string",
|
|
107
|
+
displayName: "Space",
|
|
108
|
+
description: "Name of your space",
|
|
109
|
+
defaultValue: "lmfbwqzbh93n"
|
|
110
|
+
},
|
|
111
|
+
accessToken: {
|
|
112
|
+
type: "string",
|
|
113
|
+
displayName: "Access Token ",
|
|
114
|
+
description: "Access Token",
|
|
115
|
+
defaultValue: "aWvf6oSLTuqxKCxSUpokajdQr84hGQFE6zoJG7DVVLg"
|
|
116
|
+
},
|
|
117
|
+
environment: {
|
|
118
|
+
type: "string",
|
|
119
|
+
displayName: "Environment",
|
|
120
|
+
defaultValue: "master"
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
function ContentfulCredentialsProvider({
|
|
125
|
+
accessToken,
|
|
126
|
+
space,
|
|
127
|
+
environment,
|
|
128
|
+
children
|
|
129
|
+
}) {
|
|
130
|
+
return /* @__PURE__ */ import_react.default.createElement(CredentialsContext.Provider, { value: { space, accessToken, environment } }, children);
|
|
131
|
+
}
|
|
132
|
+
var ContentfulFetcherMeta = {
|
|
133
|
+
name: "ContentfulFetcher",
|
|
134
|
+
displayName: "Contentful Fetcher",
|
|
135
|
+
importName: "ContentfulFetcher",
|
|
136
|
+
importPath: modulePath,
|
|
137
|
+
providesData: true,
|
|
138
|
+
description: "Fetches Contentful data and repeats content of children once for every row fetched. ",
|
|
139
|
+
defaultStyles: {
|
|
140
|
+
display: "grid",
|
|
141
|
+
gridTemplateColumns: "1fr 1fr 1fr 1fr",
|
|
142
|
+
gridRowGap: "8px",
|
|
143
|
+
gridColumnGap: "8px",
|
|
144
|
+
padding: "8px",
|
|
145
|
+
maxWidth: "100%"
|
|
146
|
+
},
|
|
147
|
+
props: {
|
|
148
|
+
children: {
|
|
149
|
+
type: "slot",
|
|
150
|
+
defaultValue: {
|
|
151
|
+
type: "vbox",
|
|
152
|
+
styles: {
|
|
153
|
+
padding: "8px"
|
|
154
|
+
},
|
|
155
|
+
children: {
|
|
156
|
+
type: "component",
|
|
157
|
+
name: "ContentfulField"
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
},
|
|
161
|
+
contentType: {
|
|
162
|
+
type: "choice",
|
|
163
|
+
options: (_props, ctx) => {
|
|
164
|
+
var _a, _b;
|
|
165
|
+
return (_b = (_a = ctx == null ? void 0 : ctx.types) == null ? void 0 : _a.map((type) => {
|
|
166
|
+
var _a2;
|
|
167
|
+
return {
|
|
168
|
+
label: type == null ? void 0 : type.name,
|
|
169
|
+
value: (_a2 = type == null ? void 0 : type.sys) == null ? void 0 : _a2.id
|
|
170
|
+
};
|
|
171
|
+
})) != null ? _b : [];
|
|
172
|
+
},
|
|
173
|
+
displayName: "Content type",
|
|
174
|
+
description: "Content type to be queried."
|
|
175
|
+
},
|
|
176
|
+
filterField: {
|
|
177
|
+
type: "choice",
|
|
178
|
+
displayName: "Filter field",
|
|
179
|
+
description: "Field (from Collection) to filter by.",
|
|
180
|
+
options: (_props, ctx) => {
|
|
181
|
+
var _a;
|
|
182
|
+
return (_a = ctx == null ? void 0 : ctx.fields) != null ? _a : [];
|
|
183
|
+
},
|
|
184
|
+
hidden: (props) => !props.contentType
|
|
185
|
+
},
|
|
186
|
+
searchParameter: {
|
|
187
|
+
type: "choice",
|
|
188
|
+
displayName: "Search Parameter",
|
|
189
|
+
description: "Search Parameter to filter by (see Contentful Content Delivery API documentation for details).",
|
|
190
|
+
options: (_props, ctx) => {
|
|
191
|
+
var _a;
|
|
192
|
+
return (_a = ctx == null ? void 0 : ctx.queryOptions) != null ? _a : [];
|
|
193
|
+
},
|
|
194
|
+
hidden: (props) => !props.filterField
|
|
195
|
+
},
|
|
196
|
+
filterValue: {
|
|
197
|
+
type: "string",
|
|
198
|
+
displayName: "Filter value",
|
|
199
|
+
description: "Value to filter by, should be of filter field type.",
|
|
200
|
+
hidden: (props) => !props.searchParameter
|
|
201
|
+
},
|
|
202
|
+
order: {
|
|
203
|
+
type: "choice",
|
|
204
|
+
displayName: "Order",
|
|
205
|
+
description: "Field that the entries should be ordered by.",
|
|
206
|
+
options: (_props, ctx) => {
|
|
207
|
+
var _a;
|
|
208
|
+
return [
|
|
209
|
+
...(_a = ctx == null ? void 0 : ctx.fields) != null ? _a : [],
|
|
210
|
+
"sys.createdAt",
|
|
211
|
+
"sys.updatedAt"
|
|
212
|
+
];
|
|
213
|
+
},
|
|
214
|
+
hidden: (props) => !props.contentType
|
|
215
|
+
},
|
|
216
|
+
reverseOrder: {
|
|
217
|
+
type: "boolean",
|
|
218
|
+
displayName: "Reverse order",
|
|
219
|
+
description: "Reverse the order of the entries.",
|
|
220
|
+
defaultValue: false,
|
|
221
|
+
hidden: (props) => !props.order
|
|
222
|
+
},
|
|
223
|
+
limit: {
|
|
224
|
+
type: "number",
|
|
225
|
+
displayName: "Limit",
|
|
226
|
+
description: "Limit the number of entries that are returned."
|
|
227
|
+
},
|
|
228
|
+
include: {
|
|
229
|
+
type: "number",
|
|
230
|
+
displayName: "Linked items depth",
|
|
231
|
+
defaultValueHint: 1,
|
|
232
|
+
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.",
|
|
233
|
+
max: 10,
|
|
234
|
+
min: 0
|
|
235
|
+
},
|
|
236
|
+
noAutoRepeat: {
|
|
237
|
+
type: "boolean",
|
|
238
|
+
displayName: "No auto-repeat",
|
|
239
|
+
description: "Do not automatically repeat children for every entry.",
|
|
240
|
+
defaultValue: false
|
|
241
|
+
},
|
|
242
|
+
noLayout: {
|
|
243
|
+
type: "boolean",
|
|
244
|
+
displayName: "No layout",
|
|
245
|
+
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.",
|
|
246
|
+
defaultValue: false
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
};
|
|
250
|
+
function ContentfulFetcher({
|
|
251
|
+
filterField,
|
|
252
|
+
filterValue,
|
|
253
|
+
searchParameter,
|
|
254
|
+
noAutoRepeat,
|
|
255
|
+
contentType,
|
|
256
|
+
children,
|
|
257
|
+
className,
|
|
258
|
+
order,
|
|
259
|
+
reverseOrder,
|
|
260
|
+
limit,
|
|
261
|
+
include,
|
|
262
|
+
noLayout,
|
|
263
|
+
setControlContextData
|
|
264
|
+
}) {
|
|
265
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
266
|
+
const creds = (0, import_contentful._ensure)(
|
|
267
|
+
(0, import_react.useContext)(CredentialsContext),
|
|
268
|
+
"Could not find context with current credentials"
|
|
269
|
+
);
|
|
270
|
+
const cacheKey = JSON.stringify({
|
|
271
|
+
include,
|
|
272
|
+
order,
|
|
273
|
+
reverseOrder,
|
|
274
|
+
limit,
|
|
275
|
+
filterField,
|
|
276
|
+
filterValue,
|
|
277
|
+
searchParameter,
|
|
278
|
+
creds
|
|
279
|
+
});
|
|
280
|
+
const baseUrl = "https://cdn.contentful.com";
|
|
281
|
+
const { data: contentTypes } = (0, import_query.useDaouyQueryData)(
|
|
282
|
+
`${cacheKey}/contentTypes`,
|
|
283
|
+
() => __async(this, null, function* () {
|
|
284
|
+
const resp = yield fetch(
|
|
285
|
+
`${baseUrl}/spaces/${creds.space}/environments/${creds.environment}/content_types?access_token=${creds.accessToken}`
|
|
286
|
+
);
|
|
287
|
+
return resp.json();
|
|
288
|
+
})
|
|
289
|
+
);
|
|
290
|
+
setControlContextData == null ? void 0 : setControlContextData({
|
|
291
|
+
types: (_a = contentTypes == null ? void 0 : contentTypes.items) != null ? _a : []
|
|
292
|
+
});
|
|
293
|
+
function setOrderField(searchParams) {
|
|
294
|
+
if (order) {
|
|
295
|
+
searchParams.set(
|
|
296
|
+
"order",
|
|
297
|
+
`${reverseOrder ? "-" : ""}${order.startsWith("sys.") ? order : `fields.${order}`}`
|
|
298
|
+
);
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
const { data: entriesData } = (0, import_query.useDaouyQueryData)(
|
|
302
|
+
contentType ? `${cacheKey}/${contentType}/entriesData` : null,
|
|
303
|
+
() => __async(this, null, function* () {
|
|
304
|
+
const path = `/spaces/${creds.space}/environments/${creds.environment}/entries`;
|
|
305
|
+
const searchParams = new URLSearchParams();
|
|
306
|
+
searchParams.set("access_token", creds.accessToken);
|
|
307
|
+
searchParams.set("content_type", contentType);
|
|
308
|
+
if (limit) {
|
|
309
|
+
searchParams.set("limit", limit.toString());
|
|
310
|
+
}
|
|
311
|
+
setOrderField(searchParams);
|
|
312
|
+
if (include) {
|
|
313
|
+
searchParams.set("include", include.toString());
|
|
314
|
+
}
|
|
315
|
+
const resp = yield fetch(`${baseUrl}${path}?${searchParams.toString()}`);
|
|
316
|
+
return resp.json();
|
|
317
|
+
})
|
|
318
|
+
);
|
|
319
|
+
const { data: filteredData } = (0, import_query.useDaouyQueryData)(
|
|
320
|
+
contentType && filterField && filterValue ? `${cacheKey}/${contentType}/filteredData` : null,
|
|
321
|
+
() => __async(this, null, function* () {
|
|
322
|
+
const path = `/spaces/${creds.space}/environments/${creds.environment}/entries`;
|
|
323
|
+
const searchParams = new URLSearchParams();
|
|
324
|
+
searchParams.set("access_token", creds.accessToken);
|
|
325
|
+
searchParams.set("content_type", contentType);
|
|
326
|
+
if (limit) {
|
|
327
|
+
searchParams.set("limit", limit.toString());
|
|
328
|
+
}
|
|
329
|
+
setOrderField(searchParams);
|
|
330
|
+
if (include) {
|
|
331
|
+
searchParams.set("include", include.toString());
|
|
332
|
+
}
|
|
333
|
+
if (filterField && searchParameter && filterValue) {
|
|
334
|
+
searchParams.set(
|
|
335
|
+
`fields.${filterField}${searchParameter}`,
|
|
336
|
+
filterValue.toString()
|
|
337
|
+
);
|
|
338
|
+
}
|
|
339
|
+
const resp = yield fetch(`${baseUrl}${path}?${searchParams.toString()}`);
|
|
340
|
+
return resp.json();
|
|
341
|
+
})
|
|
342
|
+
);
|
|
343
|
+
if (!creds.space || !creds.accessToken) {
|
|
344
|
+
return /* @__PURE__ */ import_react.default.createElement("div", null, "Please specify a valid API Credentials: Space, Access Token and Environment");
|
|
345
|
+
}
|
|
346
|
+
if (!contentTypes) {
|
|
347
|
+
return /* @__PURE__ */ import_react.default.createElement("div", null, "Please configure the Contentful credentials");
|
|
348
|
+
}
|
|
349
|
+
if (!entriesData) {
|
|
350
|
+
return /* @__PURE__ */ import_react.default.createElement("div", null, "Please select a content type");
|
|
351
|
+
}
|
|
352
|
+
const filterFields = entriesData == null ? void 0 : entriesData.items.flatMap((item) => {
|
|
353
|
+
const fields = Object.keys(item.fields).filter((field) => {
|
|
354
|
+
const value = (0, import_dlv.default)(item, field);
|
|
355
|
+
return typeof value !== "object" && field !== "photos";
|
|
356
|
+
});
|
|
357
|
+
return fields;
|
|
358
|
+
});
|
|
359
|
+
let operators;
|
|
360
|
+
const matchedFields = Object.values(entriesData.items).map((item) => {
|
|
361
|
+
const fields = Object.entries(item.fields).find(
|
|
362
|
+
(el) => el[0] === filterField
|
|
363
|
+
);
|
|
364
|
+
return fields;
|
|
365
|
+
});
|
|
366
|
+
Object.values(matchedFields).map((model) => Array.isArray(model) ? model : [model]).map((item) => {
|
|
367
|
+
if (typeof item[1] === "number" && typeof item[1] !== "object") {
|
|
368
|
+
operators = searchParameters;
|
|
369
|
+
} else if (typeof item[1] !== "number" && typeof item[1] !== "object" && typeof item[1] === "string") {
|
|
370
|
+
operators = [
|
|
371
|
+
{
|
|
372
|
+
value: "[match]",
|
|
373
|
+
label: "Full text search"
|
|
374
|
+
}
|
|
375
|
+
];
|
|
376
|
+
}
|
|
377
|
+
});
|
|
378
|
+
setControlContextData == null ? void 0 : setControlContextData({
|
|
379
|
+
queryOptions: operators != null ? operators : [],
|
|
380
|
+
types: (_b = contentTypes == null ? void 0 : contentTypes.items) != null ? _b : [],
|
|
381
|
+
fields: (0, import_contentful._uniq)(filterFields != null ? filterFields : [])
|
|
382
|
+
});
|
|
383
|
+
if (filterField) {
|
|
384
|
+
if (!searchParameter) {
|
|
385
|
+
return /* @__PURE__ */ import_react.default.createElement("div", null, "Please specify a Search Parameter");
|
|
386
|
+
}
|
|
387
|
+
if (!filterValue) {
|
|
388
|
+
return /* @__PURE__ */ import_react.default.createElement("div", null, "Please specify a Filter value");
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
let renderedData;
|
|
392
|
+
const fixedData = entriesData ? (0, import_contentful._denormalizeData)(entriesData) : void 0;
|
|
393
|
+
if (filteredData) {
|
|
394
|
+
if (((_c = filteredData == null ? void 0 : filteredData.items) == null ? void 0 : _c.length) === 0) {
|
|
395
|
+
return /* @__PURE__ */ import_react.default.createElement("div", { className }, "No published entry found");
|
|
396
|
+
}
|
|
397
|
+
renderedData = noAutoRepeat ? children : (_e = (_d = (0, import_contentful._denormalizeData)(filteredData)) == null ? void 0 : _d.items) == null ? void 0 : _e.map(
|
|
398
|
+
(item, index) => {
|
|
399
|
+
var _a2;
|
|
400
|
+
return /* @__PURE__ */ import_react.default.createElement(
|
|
401
|
+
import_host.DataProvider,
|
|
402
|
+
{
|
|
403
|
+
key: (_a2 = item == null ? void 0 : item.sys) == null ? void 0 : _a2.id,
|
|
404
|
+
name: "contentfulItem",
|
|
405
|
+
data: item,
|
|
406
|
+
hidden: true
|
|
407
|
+
},
|
|
408
|
+
/* @__PURE__ */ import_react.default.createElement(
|
|
409
|
+
import_host.DataProvider,
|
|
410
|
+
{
|
|
411
|
+
name: makeDataProviderName(contentType),
|
|
412
|
+
data: item
|
|
413
|
+
},
|
|
414
|
+
(0, import_host.repeatedElement)(index, children)
|
|
415
|
+
)
|
|
416
|
+
);
|
|
417
|
+
}
|
|
418
|
+
);
|
|
419
|
+
} else {
|
|
420
|
+
if (((_f = fixedData == null ? void 0 : fixedData.items) == null ? void 0 : _f.length) === 0) {
|
|
421
|
+
return /* @__PURE__ */ import_react.default.createElement("div", { className }, contentType, " is empty");
|
|
422
|
+
}
|
|
423
|
+
renderedData = noAutoRepeat ? children : (_g = fixedData == null ? void 0 : fixedData.items) == null ? void 0 : _g.map((item, index) => {
|
|
424
|
+
var _a2;
|
|
425
|
+
return /* @__PURE__ */ import_react.default.createElement(
|
|
426
|
+
import_host.DataProvider,
|
|
427
|
+
{
|
|
428
|
+
key: (_a2 = item == null ? void 0 : item.sys) == null ? void 0 : _a2.id,
|
|
429
|
+
name: "contentfulItem",
|
|
430
|
+
data: item,
|
|
431
|
+
hidden: true
|
|
432
|
+
},
|
|
433
|
+
/* @__PURE__ */ import_react.default.createElement(import_host.DataProvider, { name: makeDataProviderName(contentType), data: item }, (0, import_host.repeatedElement)(index, children))
|
|
434
|
+
);
|
|
435
|
+
});
|
|
436
|
+
}
|
|
437
|
+
return /* @__PURE__ */ import_react.default.createElement(import_host.DataProvider, { name: "contentfulItems", data: fixedData == null ? void 0 : fixedData.items }, noLayout ? /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, " ", renderedData, " ") : /* @__PURE__ */ import_react.default.createElement("div", { className }, " ", renderedData, " "));
|
|
438
|
+
}
|
|
439
|
+
var ContentfulFieldMeta = {
|
|
440
|
+
name: "ContentfulField",
|
|
441
|
+
displayName: "Contentful Field",
|
|
442
|
+
importName: "ContentfulField",
|
|
443
|
+
importPath: modulePath,
|
|
444
|
+
props: {
|
|
445
|
+
objectPath: {
|
|
446
|
+
type: "dataSelector",
|
|
447
|
+
data: (_props, ctx) => {
|
|
448
|
+
var _a;
|
|
449
|
+
return (_a = ctx == null ? void 0 : ctx.data) != null ? _a : {};
|
|
450
|
+
},
|
|
451
|
+
displayName: "Field",
|
|
452
|
+
description: "Field to be displayed."
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
};
|
|
456
|
+
function ContentfulField({
|
|
457
|
+
className,
|
|
458
|
+
objectPath,
|
|
459
|
+
setControlContextData
|
|
460
|
+
}) {
|
|
461
|
+
var _a, _b;
|
|
462
|
+
const item = (_a = (0, import_host.useSelector)("contentfulItem")) == null ? void 0 : _a.fields;
|
|
463
|
+
if (!item) {
|
|
464
|
+
return /* @__PURE__ */ import_react.default.createElement("div", null, "ContentfulField must be used within a ContentfulFetcher ");
|
|
465
|
+
}
|
|
466
|
+
setControlContextData == null ? void 0 : setControlContextData({
|
|
467
|
+
data: item
|
|
468
|
+
});
|
|
469
|
+
if (!objectPath) {
|
|
470
|
+
return /* @__PURE__ */ import_react.default.createElement("div", null, "Please specify a valid path or select a field.");
|
|
471
|
+
}
|
|
472
|
+
const data = (0, import_dlv.default)(item, objectPath);
|
|
473
|
+
if (typeof data === "object" && "nodeType" in data && data.nodeType === "document") {
|
|
474
|
+
return /* @__PURE__ */ import_react.default.createElement(
|
|
475
|
+
"div",
|
|
476
|
+
{
|
|
477
|
+
className,
|
|
478
|
+
dangerouslySetInnerHTML: { __html: (0, import_rich_text_html_renderer.documentToHtmlString)(data) }
|
|
479
|
+
}
|
|
480
|
+
);
|
|
481
|
+
} else if (typeof data === "object" && ((_b = data.sys) == null ? void 0 : _b.linkType) === "Asset" && data.url) {
|
|
482
|
+
return /* @__PURE__ */ import_react.default.createElement("img", { className, src: data.url });
|
|
483
|
+
} else if (!data) {
|
|
484
|
+
return /* @__PURE__ */ import_react.default.createElement("div", null, "Please specify a valid field.");
|
|
485
|
+
} else if (typeof data !== "object") {
|
|
486
|
+
return /* @__PURE__ */ import_react.default.createElement("div", { className }, data);
|
|
487
|
+
} else {
|
|
488
|
+
return /* @__PURE__ */ import_react.default.createElement("div", { className }, data.toString());
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
// src/index.tsx
|
|
493
|
+
function registerAll(loader) {
|
|
494
|
+
const _registerComponent = (Component, defaultMeta) => {
|
|
495
|
+
if (loader) {
|
|
496
|
+
loader.registerComponent(Component, defaultMeta);
|
|
497
|
+
} else {
|
|
498
|
+
(0, import_registerComponent.default)(Component, defaultMeta);
|
|
499
|
+
}
|
|
500
|
+
};
|
|
501
|
+
if (loader) {
|
|
502
|
+
loader.registerGlobalContext(
|
|
503
|
+
ContentfulCredentialsProvider,
|
|
504
|
+
ContentfulCredentialsProviderMeta
|
|
505
|
+
);
|
|
506
|
+
} else {
|
|
507
|
+
(0, import_registerGlobalContext.default)(
|
|
508
|
+
ContentfulCredentialsProvider,
|
|
509
|
+
ContentfulCredentialsProviderMeta
|
|
510
|
+
);
|
|
511
|
+
}
|
|
512
|
+
_registerComponent(ContentfulFetcher, ContentfulFetcherMeta);
|
|
513
|
+
_registerComponent(ContentfulField, ContentfulFieldMeta);
|
|
514
|
+
}
|
|
515
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/index.tsx", "../src/contentful.tsx", "../src/utils.ts"],
|
|
4
|
+
"sourcesContent": ["import registerComponent, {\n ComponentMeta,\n} from \"@daouy/host/registerComponent\";\nimport registerGlobalContext from \"@daouy/host/registerGlobalContext\";\nimport {\n ContentfulCredentialsProvider,\n ContentfulCredentialsProviderMeta,\n ContentfulFetcher,\n ContentfulFetcherMeta,\n ContentfulField,\n ContentfulFieldMeta,\n} from \"./contentful\";\n\nexport function registerAll(loader?: {\n registerComponent: typeof registerComponent;\n registerGlobalContext: typeof registerGlobalContext;\n}) {\n const _registerComponent = <T extends React.ComponentType<any>>(\n Component: T,\n defaultMeta: ComponentMeta<React.ComponentProps<T>>\n ) => {\n if (loader) {\n loader.registerComponent(Component, defaultMeta);\n } else {\n registerComponent(Component, defaultMeta);\n }\n };\n\n if (loader) {\n loader.registerGlobalContext(\n ContentfulCredentialsProvider,\n ContentfulCredentialsProviderMeta\n );\n } else {\n registerGlobalContext(\n ContentfulCredentialsProvider,\n ContentfulCredentialsProviderMeta\n );\n }\n _registerComponent(ContentfulFetcher, ContentfulFetcherMeta);\n _registerComponent(ContentfulField, ContentfulFieldMeta);\n}\n\nexport * from \"./contentful\";\n", "import { documentToHtmlString } from \"@contentful/rich-text-html-renderer\";\nimport {\n ComponentMeta,\n DataProvider,\n GlobalContextMeta,\n repeatedElement,\n useSelector,\n} from \"@daouy/host\";\nimport { useDaouyQueryData } from \"@daouy/query\";\nimport {\n _denormalizeData as denormalizeData,\n _ensure as ensure,\n _uniq as uniq,\n} from \"@daouypkgs/contentful\";\nimport { pascalCase } from \"change-case\";\nimport get from \"dlv\";\nimport React, { ReactNode, useContext } from \"react\";\nimport { searchParameters } from \"./utils\";\n\nconst modulePath = \"@daouypkgs/daouy-contentful\";\n\nconst makeDataProviderName = (contentType: string) =>\n `currentContentful${pascalCase(contentType)}Item`;\n\ninterface ContentfulCredentialsProviderProps {\n space: string;\n accessToken: string;\n environment?: string;\n}\n\nconst CredentialsContext = React.createContext<\n ContentfulCredentialsProviderProps | undefined\n>(undefined);\n\nexport const ContentfulCredentialsProviderMeta: GlobalContextMeta<ContentfulCredentialsProviderProps> =\n {\n name: \"Contentful CredentialsProvider\",\n displayName: \"Contentful Credentials Provider\",\n description:\n \"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/).\",\n importName: \"ContentfulCredentialsProvider\",\n importPath: modulePath,\n props: {\n space: {\n type: \"string\",\n displayName: \"Space\",\n description: \"Name of your space\",\n defaultValue: \"lmfbwqzbh93n\",\n },\n accessToken: {\n type: \"string\",\n displayName: \"Access Token \",\n description: \"Access Token\",\n defaultValue: \"aWvf6oSLTuqxKCxSUpokajdQr84hGQFE6zoJG7DVVLg\",\n },\n environment: {\n type: \"string\",\n displayName: \"Environment\",\n defaultValue: \"master\",\n },\n },\n };\n\nexport function ContentfulCredentialsProvider({\n accessToken,\n space,\n environment,\n children,\n}: React.PropsWithChildren<ContentfulCredentialsProviderProps>) {\n return (\n <CredentialsContext.Provider value={{ space, accessToken, environment }}>\n {children}\n </CredentialsContext.Provider>\n );\n}\n\ninterface ContentfulControlContextData {\n types?: { name: string; id: string }[];\n fields?: string[];\n queryOptions?: [];\n}\n\ninterface ContentfulFetcherProps {\n contentType: string;\n children?: ReactNode;\n className?: string;\n limit?: number;\n include?: number;\n order?: string;\n reverseOrder?: boolean;\n filterField?: string;\n searchParameter?: string;\n filterValue?: string | number;\n noAutoRepeat?: boolean;\n noLayout?: boolean;\n setControlContextData?: (data: ContentfulControlContextData) => void;\n}\n\nexport const ContentfulFetcherMeta: ComponentMeta<ContentfulFetcherProps> = {\n name: \"ContentfulFetcher\",\n displayName: \"Contentful Fetcher\",\n importName: \"ContentfulFetcher\",\n importPath: modulePath,\n providesData: true,\n description:\n \"Fetches Contentful data and repeats content of children once for every row fetched. \",\n defaultStyles: {\n display: \"grid\",\n gridTemplateColumns: \"1fr 1fr 1fr 1fr\",\n gridRowGap: \"8px\",\n gridColumnGap: \"8px\",\n padding: \"8px\",\n maxWidth: \"100%\",\n },\n props: {\n children: {\n type: \"slot\",\n defaultValue: {\n type: \"vbox\",\n styles: {\n padding: \"8px\",\n },\n children: {\n type: \"component\",\n name: \"ContentfulField\",\n },\n },\n },\n contentType: {\n type: \"choice\",\n options: (_props, ctx) =>\n ctx?.types?.map((type: any) => ({\n label: type?.name,\n value: type?.sys?.id,\n })) ?? [],\n displayName: \"Content type\",\n description: \"Content type to be queried.\",\n },\n\n filterField: {\n type: \"choice\",\n displayName: \"Filter field\",\n description: \"Field (from Collection) to filter by.\",\n options: (_props, ctx) => ctx?.fields ?? [],\n hidden: (props) => !props.contentType,\n },\n searchParameter: {\n type: \"choice\",\n displayName: \"Search Parameter\",\n description:\n \"Search Parameter to filter by (see Contentful Content Delivery API documentation for details).\",\n options: (_props, ctx) => ctx?.queryOptions ?? [],\n hidden: (props) => !props.filterField,\n },\n filterValue: {\n type: \"string\",\n displayName: \"Filter value\",\n description: \"Value to filter by, should be of filter field type.\",\n hidden: (props) => !props.searchParameter,\n },\n order: {\n type: \"choice\",\n displayName: \"Order\",\n description: \"Field that the entries should be ordered by.\",\n options: (_props, ctx) => [\n ...(ctx?.fields ?? []),\n \"sys.createdAt\",\n \"sys.updatedAt\",\n ],\n hidden: (props) => !props.contentType,\n },\n reverseOrder: {\n type: \"boolean\",\n displayName: \"Reverse order\",\n description: \"Reverse the order of the entries.\",\n defaultValue: false,\n hidden: (props) => !props.order,\n },\n limit: {\n type: \"number\",\n displayName: \"Limit\",\n description: \"Limit the number of entries that are returned.\",\n },\n include: {\n type: \"number\",\n displayName: \"Linked items depth\",\n defaultValueHint: 1,\n description:\n \"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.\",\n max: 10,\n min: 0,\n },\n noAutoRepeat: {\n type: \"boolean\",\n displayName: \"No auto-repeat\",\n description: \"Do not automatically repeat children for every entry.\",\n defaultValue: false,\n },\n noLayout: {\n type: \"boolean\",\n displayName: \"No layout\",\n description:\n \"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.\",\n defaultValue: false,\n },\n },\n};\n\nexport function ContentfulFetcher({\n filterField,\n filterValue,\n searchParameter,\n noAutoRepeat,\n contentType,\n children,\n className,\n order,\n reverseOrder,\n limit,\n include,\n noLayout,\n setControlContextData,\n}: ContentfulFetcherProps) {\n const creds = ensure(\n useContext(CredentialsContext),\n \"Could not find context with current credentials\"\n );\n const cacheKey = JSON.stringify({\n include,\n order,\n reverseOrder,\n limit,\n filterField,\n filterValue,\n searchParameter,\n creds,\n });\n\n const baseUrl = \"https://cdn.contentful.com\";\n\n const { data: contentTypes } = useDaouyQueryData<any | null>(\n `${cacheKey}/contentTypes`,\n async () => {\n const resp = await fetch(\n `${baseUrl}/spaces/${creds.space}/environments/${creds.environment}/content_types?access_token=${creds.accessToken}`\n );\n return resp.json();\n }\n );\n setControlContextData?.({\n types: contentTypes?.items ?? [],\n });\n\n function setOrderField(searchParams: URLSearchParams) {\n if (order) {\n searchParams.set(\n \"order\",\n `${reverseOrder ? \"-\" : \"\"}${\n order.startsWith(\"sys.\") ? order : `fields.${order}`\n }`\n );\n }\n }\n\n const { data: entriesData } = useDaouyQueryData<any | null>(\n contentType ? `${cacheKey}/${contentType}/entriesData` : null,\n async () => {\n const path = `/spaces/${creds.space}/environments/${creds.environment}/entries`;\n\n const searchParams = new URLSearchParams();\n searchParams.set(\"access_token\", creds.accessToken);\n searchParams.set(\"content_type\", contentType);\n if (limit) {\n searchParams.set(\"limit\", limit.toString());\n }\n setOrderField(searchParams);\n if (include) {\n searchParams.set(\"include\", include.toString());\n }\n\n const resp = await fetch(`${baseUrl}${path}?${searchParams.toString()}`);\n return resp.json();\n }\n );\n\n const { data: filteredData } = useDaouyQueryData<any | null>(\n contentType && filterField && filterValue\n ? `${cacheKey}/${contentType}/filteredData`\n : null,\n async () => {\n const path = `/spaces/${creds.space}/environments/${creds.environment}/entries`;\n\n const searchParams = new URLSearchParams();\n searchParams.set(\"access_token\", creds.accessToken);\n searchParams.set(\"content_type\", contentType);\n if (limit) {\n searchParams.set(\"limit\", limit.toString());\n }\n setOrderField(searchParams);\n\n if (include) {\n searchParams.set(\"include\", include.toString());\n }\n\n if (filterField && searchParameter && filterValue) {\n searchParams.set(\n `fields.${filterField}${searchParameter}`,\n filterValue.toString()\n );\n }\n\n const resp = await fetch(`${baseUrl}${path}?${searchParams.toString()}`);\n return resp.json();\n }\n );\n\n if (!creds.space || !creds.accessToken) {\n return (\n <div>\n Please specify a valid API Credentials: Space, Access Token and\n Environment\n </div>\n );\n }\n\n if (!contentTypes) {\n return <div>Please configure the Contentful credentials</div>;\n }\n\n if (!entriesData) {\n return <div>Please select a content type</div>;\n }\n\n const filterFields: string[] = entriesData?.items.flatMap((item: any) => {\n const fields = Object.keys(item.fields).filter((field) => {\n const value = get(item, field);\n return typeof value !== \"object\" && field !== \"photos\";\n });\n return fields;\n });\n\n let operators;\n const matchedFields = Object.values(entriesData.items).map((item: any) => {\n const fields = Object.entries(item.fields).find(\n (el) => el[0] === filterField\n );\n return fields;\n });\n\n Object.values(matchedFields)\n .map((model: any) => (Array.isArray(model) ? model : [model]))\n .map((item: any) => {\n if (typeof item[1] === \"number\" && typeof item[1] !== \"object\") {\n operators = searchParameters;\n } else if (\n typeof item[1] !== \"number\" &&\n typeof item[1] !== \"object\" &&\n typeof item[1] === \"string\"\n ) {\n operators = [\n {\n value: \"[match]\",\n label: \"Full text search\",\n },\n ];\n }\n });\n\n setControlContextData?.({\n queryOptions: operators ?? [],\n types: contentTypes?.items ?? [],\n fields: uniq(filterFields ?? []),\n });\n\n if (filterField) {\n if (!searchParameter) {\n return <div>Please specify a Search Parameter</div>;\n }\n if (!filterValue) {\n return <div>Please specify a Filter value</div>;\n }\n }\n\n let renderedData;\n\n const fixedData = entriesData ? denormalizeData(entriesData) : undefined;\n\n if (filteredData) {\n if (filteredData?.items?.length === 0) {\n return <div className={className}>No published entry found</div>;\n }\n\n renderedData = noAutoRepeat\n ? children\n : denormalizeData(filteredData)?.items?.map(\n (item: any, index: number) => (\n <DataProvider\n key={item?.sys?.id}\n name={\"contentfulItem\"}\n data={item}\n hidden={true}\n >\n <DataProvider\n name={makeDataProviderName(contentType)}\n data={item}\n >\n {repeatedElement(index, children)}\n </DataProvider>\n </DataProvider>\n )\n );\n } else {\n if (fixedData?.items?.length === 0) {\n return <div className={className}>{contentType} is empty</div>;\n }\n\n renderedData = noAutoRepeat\n ? children\n : fixedData?.items?.map((item: any, index: number) => (\n <DataProvider\n key={item?.sys?.id}\n name={\"contentfulItem\"}\n data={item}\n hidden={true}\n >\n <DataProvider name={makeDataProviderName(contentType)} data={item}>\n {repeatedElement(index, children)}\n </DataProvider>\n </DataProvider>\n ));\n }\n return (\n <DataProvider name=\"contentfulItems\" data={fixedData?.items}>\n {noLayout ? (\n <> {renderedData} </>\n ) : (\n <div className={className}> {renderedData} </div>\n )}\n </DataProvider>\n );\n}\ninterface ContentfulFieldProps {\n className?: string;\n objectPath?: (string | number)[];\n setControlContextData?: (data: { data: object }) => void;\n}\n\nexport const ContentfulFieldMeta: ComponentMeta<ContentfulFieldProps> = {\n name: \"ContentfulField\",\n displayName: \"Contentful Field\",\n importName: \"ContentfulField\",\n importPath: modulePath,\n props: {\n objectPath: {\n type: \"dataSelector\",\n data: (_props, ctx) => ctx?.data ?? {},\n displayName: \"Field\",\n description: \"Field to be displayed.\",\n },\n },\n};\n\nexport function ContentfulField({\n className,\n objectPath,\n setControlContextData,\n}: ContentfulFieldProps) {\n const item = useSelector(\"contentfulItem\")?.fields;\n if (!item) {\n return <div>ContentfulField must be used within a ContentfulFetcher </div>;\n }\n setControlContextData?.({\n data: item,\n });\n if (!objectPath) {\n return <div>Please specify a valid path or select a field.</div>;\n }\n\n const data = get(item, objectPath);\n if (\n typeof data === \"object\" &&\n \"nodeType\" in data &&\n data.nodeType === \"document\"\n ) {\n return (\n <div\n className={className}\n dangerouslySetInnerHTML={{ __html: documentToHtmlString(data) }}\n />\n );\n } else if (\n typeof data === \"object\" &&\n data.sys?.linkType === \"Asset\" &&\n data.url\n ) {\n return <img className={className} src={data.url} />;\n } else if (!data) {\n return <div>Please specify a valid field.</div>;\n } else if (typeof data !== \"object\") {\n return <div className={className}>{data}</div>;\n } else {\n return <div className={className}>{data.toString()}</div>;\n }\n}\n", "export const searchParameters = [\n {\n value: \"[lt]\",\n label: \"Less than\",\n },\n {\n value: \"[lte]\",\n label: \"Less than or equal\",\n },\n {\n value: \"[gt]\",\n label: \"Greater than\",\n },\n {\n value: \"[gte]\",\n label: \"Greater than or equal \",\n },\n];\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,+BAEO;AACP,mCAAkC;;;ACHlC,qCAAqC;AACrC,kBAMO;AACP,mBAAkC;AAClC,wBAIO;AACP,yBAA2B;AAC3B,iBAAgB;AAChB,mBAA6C;;;AChBtC,IAAM,mBAAmB;AAAA,EAC9B;AAAA,IACE,OAAO;AAAA,IACP,OAAO;AAAA,EACT;AAAA,EACA;AAAA,IACE,OAAO;AAAA,IACP,OAAO;AAAA,EACT;AAAA,EACA;AAAA,IACE,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A;AAAA,QACC;AAAA,QACA,yBAAyB,EAAE,YAAQ,qDAAqB,IAAI,EAAE;AAAA;AAAA,IAChE;AAAA,EAEJ,WACE,OAAO,SAAS,cAChB,UAAK,QAAL,mBAAU,cAAa,WACvB,KAAK,KACL;AACA,WAAO,6BAAAA,QAAA,cAAC,SAAI,WAAsB,KAAK,KAAK,KAAK;AAAA,EACnD,WAAW,CAAC,MAAM;AAChB,WAAO,6BAAAA,QAAA,cAAC,aAAI,+BAA6B;AAAA,EAC3C,WAAW,OAAO,SAAS,UAAU;AACnC,WAAO,6BAAAA,QAAA,cAAC,SAAI,aAAuB,IAAK;AAAA,EAC1C,OAAO;AACL,WAAO,6BAAAA,QAAA,cAAC,SAAI,aAAuB,KAAK,SAAS,CAAE;AAAA,EACrD;AACF;;;AD1eO,SAAS,YAAY,QAGzB;AACD,QAAM,qBAAqB,CACzB,WACA,gBACG;AACH,QAAI,QAAQ;AACV,aAAO,kBAAkB,WAAW,WAAW;AAAA,IACjD,OAAO;AACL,mCAAAM,SAAkB,WAAW,WAAW;AAAA,IAC1C;AAAA,EACF;AAEA,MAAI,QAAQ;AACV,WAAO;AAAA,MACL;AAAA,MACA;AAAA,IACF;AAAA,EACF,OAAO;AACL,qCAAAC;AAAA,MACE;AAAA,MACA;AAAA,IACF;AAAA,EACF;AACA,qBAAmB,mBAAmB,qBAAqB;AAC3D,qBAAmB,iBAAiB,mBAAmB;AACzD;",
|
|
6
|
+
"names": ["React", "_a", "ensure", "get", "uniq", "denormalizeData", "registerComponent", "registerGlobalContext"]
|
|
7
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@daouypkgs/daouy-contentful",
|
|
3
|
+
"version": "0.0.182",
|
|
4
|
+
"description": "Daouy Contentful components.",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/daouyapp/daouy.git",
|
|
8
|
+
"directory": "daouypkgs/daouy-contentful"
|
|
9
|
+
},
|
|
10
|
+
"publishConfig": {
|
|
11
|
+
"access": "public"
|
|
12
|
+
},
|
|
13
|
+
"main": "./dist/index.js",
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"module": "./dist/index.esm.js",
|
|
16
|
+
"exports": {
|
|
17
|
+
".": {
|
|
18
|
+
"types": "./dist/index.d.ts",
|
|
19
|
+
"import": "./dist/index.esm.js",
|
|
20
|
+
"require": "./dist/index.js"
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"files": [
|
|
24
|
+
"dist"
|
|
25
|
+
],
|
|
26
|
+
"scripts": {
|
|
27
|
+
"build": "yarn build:types && yarn build:index",
|
|
28
|
+
"build:types": "yarn tsc",
|
|
29
|
+
"build:index": "node ../../build.mjs ./src/index.tsx",
|
|
30
|
+
"test": "TEST_CWD=`pwd` yarn --cwd=../.. test --passWithNoTests",
|
|
31
|
+
"prepublishOnly": "npm run build",
|
|
32
|
+
"postpublish": "bash ../../scripts/publish-api-doc-model.sh"
|
|
33
|
+
},
|
|
34
|
+
"size-limit": [
|
|
35
|
+
{
|
|
36
|
+
"path": "dist/index.js",
|
|
37
|
+
"limit": "10 KB"
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
"path": "dist/index.mjs",
|
|
41
|
+
"limit": "10 KB"
|
|
42
|
+
}
|
|
43
|
+
],
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"@daouy/host": "^1.0.234",
|
|
46
|
+
"@daouy/query": "^0.1.82",
|
|
47
|
+
"@daouypkgs/contentful": "^0.0.7",
|
|
48
|
+
"@types/dlv": "^1.1.2",
|
|
49
|
+
"@types/react": "^18.0.27",
|
|
50
|
+
"@types/react-dom": "^18.0.10",
|
|
51
|
+
"react": "^18.2.0",
|
|
52
|
+
"react-dom": "^18.2.0",
|
|
53
|
+
"typescript": "^5.7.3"
|
|
54
|
+
},
|
|
55
|
+
"dependencies": {
|
|
56
|
+
"@contentful/rich-text-html-renderer": "^15.13.1",
|
|
57
|
+
"@contentful/rich-text-react-renderer": "^15.12.1",
|
|
58
|
+
"change-case": "^4.1.2",
|
|
59
|
+
"dlv": "^1.1.3"
|
|
60
|
+
},
|
|
61
|
+
"peerDependencies": {
|
|
62
|
+
"@daouy/host": "^1.0.234",
|
|
63
|
+
"react": ">=16.8.0"
|
|
64
|
+
}
|
|
65
|
+
}
|