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