@plasmicpkgs/plasmic-strapi 0.1.179 → 0.1.181
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.ts +0 -9
- package/dist/index.esm.js +50 -246
- package/dist/index.esm.js.map +4 -4
- package/dist/index.js +39 -245
- package/dist/index.js.map +4 -4
- package/package.json +6 -9
package/dist/index.d.ts
CHANGED
|
@@ -1,24 +1,15 @@
|
|
|
1
1
|
import { ComponentMeta } from '@plasmicapp/host';
|
|
2
|
-
import { CustomFunctionMeta } from '@plasmicapp/host/registerFunction';
|
|
3
2
|
import { GlobalContextMeta } from '@plasmicapp/host';
|
|
4
3
|
import { default as React_2 } from 'react';
|
|
5
4
|
import { ReactNode } from 'react';
|
|
6
5
|
import registerComponent from '@plasmicapp/host/registerComponent';
|
|
7
6
|
import registerGlobalContext from '@plasmicapp/host/registerGlobalContext';
|
|
8
7
|
|
|
9
|
-
export declare function queryStrapi(host: string, token: string | undefined, collection: string | undefined, filterField?: string, filterValue?: string, filterParameter?: string): Promise<any>;
|
|
10
|
-
|
|
11
|
-
export declare const queryStrapiMeta: CustomFunctionMeta<typeof queryStrapi>;
|
|
12
|
-
|
|
13
8
|
export declare function registerAll(loader?: {
|
|
14
9
|
registerComponent: typeof registerComponent;
|
|
15
10
|
registerGlobalContext: typeof registerGlobalContext;
|
|
16
11
|
}): void;
|
|
17
12
|
|
|
18
|
-
export declare function registerAllCustomFunctions(loader?: {
|
|
19
|
-
registerFunction: any;
|
|
20
|
-
}): void;
|
|
21
|
-
|
|
22
13
|
export declare function StrapiCollection({ name, filterParameter, filterValue, filterField, limit, children, className, noLayout, noAutoRepeat, setControlContextData, }: StrapiCollectionProps): React_2.JSX.Element;
|
|
23
14
|
|
|
24
15
|
export declare const strapiCollectionMeta: ComponentMeta<StrapiCollectionProps>;
|
package/dist/index.esm.js
CHANGED
|
@@ -1,35 +1,4 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __defProps = Object.defineProperties;
|
|
4
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
5
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
8
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
9
|
-
var __spreadValues = (a, b) => {
|
|
10
|
-
for (var prop in b || (b = {}))
|
|
11
|
-
if (__hasOwnProp.call(b, prop))
|
|
12
|
-
__defNormalProp(a, prop, b[prop]);
|
|
13
|
-
if (__getOwnPropSymbols)
|
|
14
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
15
|
-
if (__propIsEnum.call(b, prop))
|
|
16
|
-
__defNormalProp(a, prop, b[prop]);
|
|
17
|
-
}
|
|
18
|
-
return a;
|
|
19
|
-
};
|
|
20
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
21
|
-
var __objRest = (source, exclude) => {
|
|
22
|
-
var target = {};
|
|
23
|
-
for (var prop in source)
|
|
24
|
-
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
25
|
-
target[prop] = source[prop];
|
|
26
|
-
if (source != null && __getOwnPropSymbols)
|
|
27
|
-
for (var prop of __getOwnPropSymbols(source)) {
|
|
28
|
-
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
29
|
-
target[prop] = source[prop];
|
|
30
|
-
}
|
|
31
|
-
return target;
|
|
32
|
-
};
|
|
33
2
|
var __async = (__this, __arguments, generator) => {
|
|
34
3
|
return new Promise((resolve, reject) => {
|
|
35
4
|
var fulfilled = (value) => {
|
|
@@ -58,184 +27,22 @@ import registerGlobalContext from "@plasmicapp/host/registerGlobalContext";
|
|
|
58
27
|
// src/StrapiCollection.tsx
|
|
59
28
|
import { DataProvider, repeatedElement } from "@plasmicapp/host";
|
|
60
29
|
import { usePlasmicQueryData } from "@plasmicapp/query";
|
|
30
|
+
import {
|
|
31
|
+
_extractFilterableFields,
|
|
32
|
+
_getId,
|
|
33
|
+
_queryParameters,
|
|
34
|
+
queryStrapi
|
|
35
|
+
} from "@plasmicpkgs/strapi";
|
|
61
36
|
import { pascalCase } from "change-case";
|
|
62
|
-
import get2 from "dlv";
|
|
63
37
|
import React2 from "react";
|
|
64
38
|
|
|
65
|
-
// src/
|
|
66
|
-
import
|
|
67
|
-
import get from "dlv";
|
|
68
|
-
import qs from "qs";
|
|
39
|
+
// src/StrapiCredentialsProvider.tsx
|
|
40
|
+
import React, { useContext } from "react";
|
|
69
41
|
|
|
70
42
|
// src/utils.ts
|
|
71
43
|
var modulePath = "@plasmicpkgs/plasmic-strapi";
|
|
72
|
-
var queryParameters = [
|
|
73
|
-
{
|
|
74
|
-
value: "$eq",
|
|
75
|
-
label: "Equal"
|
|
76
|
-
},
|
|
77
|
-
{
|
|
78
|
-
value: "$ne",
|
|
79
|
-
label: "Not equal"
|
|
80
|
-
},
|
|
81
|
-
{
|
|
82
|
-
value: "$lt",
|
|
83
|
-
label: "Less than"
|
|
84
|
-
},
|
|
85
|
-
{
|
|
86
|
-
value: "$lte",
|
|
87
|
-
label: "Less than or equal to"
|
|
88
|
-
},
|
|
89
|
-
{
|
|
90
|
-
value: "$gt",
|
|
91
|
-
label: "Greater than"
|
|
92
|
-
},
|
|
93
|
-
{
|
|
94
|
-
value: "$gte",
|
|
95
|
-
label: "Greater than or equal to"
|
|
96
|
-
},
|
|
97
|
-
{
|
|
98
|
-
value: "$in",
|
|
99
|
-
label: "Included in an array"
|
|
100
|
-
},
|
|
101
|
-
{
|
|
102
|
-
value: "$notIn",
|
|
103
|
-
label: "Not included in an array"
|
|
104
|
-
},
|
|
105
|
-
{
|
|
106
|
-
value: "$contains",
|
|
107
|
-
label: "Contains"
|
|
108
|
-
},
|
|
109
|
-
{
|
|
110
|
-
value: "$notContains",
|
|
111
|
-
label: "Does not contain"
|
|
112
|
-
}
|
|
113
|
-
];
|
|
114
|
-
var uniq = (xs) => Array.from(new Set(xs));
|
|
115
|
-
var getAttributes = (item) => {
|
|
116
|
-
if (!item) {
|
|
117
|
-
return void 0;
|
|
118
|
-
}
|
|
119
|
-
if (item.attributes) {
|
|
120
|
-
return item.attributes;
|
|
121
|
-
}
|
|
122
|
-
const _a = item, { documentId: _documentId, locale: _locale } = _a, rest = __objRest(_a, ["documentId", "locale"]);
|
|
123
|
-
return rest;
|
|
124
|
-
};
|
|
125
|
-
function filterFields(collectionData) {
|
|
126
|
-
return collectionData.flatMap((item) => {
|
|
127
|
-
const attributes = getAttributes(item);
|
|
128
|
-
const displayableFields = Object.keys(attributes).filter((field) => {
|
|
129
|
-
var _a;
|
|
130
|
-
const value = attributes[field];
|
|
131
|
-
const maybeMime = (_a = getAttributes(value == null ? void 0 : value.data)) == null ? void 0 : _a.mime;
|
|
132
|
-
return typeof value !== "object" || typeof maybeMime === "string" && maybeMime.startsWith("image");
|
|
133
|
-
});
|
|
134
|
-
return displayableFields;
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
// src/custom-functions.tsx
|
|
139
|
-
var queryStrapiMeta = {
|
|
140
|
-
name: "queryStrapi",
|
|
141
|
-
displayName: "Query Strapi",
|
|
142
|
-
description: "Query a Strapi collection",
|
|
143
|
-
importPath: modulePath,
|
|
144
|
-
params: [
|
|
145
|
-
{
|
|
146
|
-
name: "strapiHost",
|
|
147
|
-
type: "string",
|
|
148
|
-
description: "The Strapi host URL (e.g., https://example.com)"
|
|
149
|
-
},
|
|
150
|
-
{
|
|
151
|
-
name: "strapiToken",
|
|
152
|
-
type: "string",
|
|
153
|
-
description: "The Strapi API token (optional, for authenticated requests)"
|
|
154
|
-
},
|
|
155
|
-
{
|
|
156
|
-
name: "collection",
|
|
157
|
-
type: "string",
|
|
158
|
-
description: "The name of the Strapi collection to query"
|
|
159
|
-
},
|
|
160
|
-
{
|
|
161
|
-
name: "filterField",
|
|
162
|
-
type: "choice",
|
|
163
|
-
options: (_, ctx) => {
|
|
164
|
-
return ctx == null ? void 0 : ctx.strapiFields;
|
|
165
|
-
}
|
|
166
|
-
},
|
|
167
|
-
{
|
|
168
|
-
name: "filterValue",
|
|
169
|
-
type: "string",
|
|
170
|
-
description: "The value to filter by (optional, if you want to filter results)"
|
|
171
|
-
},
|
|
172
|
-
{
|
|
173
|
-
name: "filterParameter",
|
|
174
|
-
type: "choice",
|
|
175
|
-
description: "The parameter for filtering (e.g., 'eq', 'contains', etc.) (optional)",
|
|
176
|
-
options: () => {
|
|
177
|
-
return queryParameters.map((item) => ({
|
|
178
|
-
label: item == null ? void 0 : item.label,
|
|
179
|
-
value: item == null ? void 0 : item.value
|
|
180
|
-
}));
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
],
|
|
184
|
-
fnContext: (host, token, collection) => {
|
|
185
|
-
return {
|
|
186
|
-
dataKey: JSON.stringify({ host, token, collection }),
|
|
187
|
-
fetcher: () => __async(void 0, null, function* () {
|
|
188
|
-
if (!host) {
|
|
189
|
-
return {};
|
|
190
|
-
}
|
|
191
|
-
const data = yield queryStrapi(host, token, collection);
|
|
192
|
-
if (!get(data.data, ["data"])) {
|
|
193
|
-
return { strapiFields: [] };
|
|
194
|
-
}
|
|
195
|
-
const collectionData = get(data.data, ["data"]);
|
|
196
|
-
const filteredFields = filterFields(collectionData);
|
|
197
|
-
return { strapiFields: uniq(filteredFields != null ? filteredFields : []) };
|
|
198
|
-
})
|
|
199
|
-
};
|
|
200
|
-
}
|
|
201
|
-
};
|
|
202
|
-
function queryStrapi(host, token, collection, filterField, filterValue, filterParameter) {
|
|
203
|
-
return __async(this, null, function* () {
|
|
204
|
-
if (!host) {
|
|
205
|
-
return null;
|
|
206
|
-
}
|
|
207
|
-
collection = collection != null ? collection : "";
|
|
208
|
-
const query = host.trim() + "/api/" + collection.trim();
|
|
209
|
-
const requestInit = { method: "GET" };
|
|
210
|
-
if (token) {
|
|
211
|
-
requestInit.headers = { Authorization: "Bearer " + token };
|
|
212
|
-
}
|
|
213
|
-
const queryParams = qs.stringify(__spreadProps(__spreadValues({}, filterField && filterParameter && filterValue ? {
|
|
214
|
-
filters: {
|
|
215
|
-
[filterField]: {
|
|
216
|
-
[filterParameter]: filterValue
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
} : {}), {
|
|
220
|
-
populate: "*"
|
|
221
|
-
}));
|
|
222
|
-
const resp = yield fetch(`${query}?${queryParams}`, requestInit);
|
|
223
|
-
return resp.json();
|
|
224
|
-
});
|
|
225
|
-
}
|
|
226
|
-
function registerAllCustomFunctions(loader) {
|
|
227
|
-
function _registerFunction(fn, meta) {
|
|
228
|
-
if (loader) {
|
|
229
|
-
loader.registerFunction(fn, meta);
|
|
230
|
-
} else {
|
|
231
|
-
registerFunction(fn, meta);
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
_registerFunction(queryStrapi, queryStrapiMeta);
|
|
235
|
-
}
|
|
236
44
|
|
|
237
45
|
// src/StrapiCredentialsProvider.tsx
|
|
238
|
-
import React, { useContext } from "react";
|
|
239
46
|
var StrapiCredentialsContext = React.createContext(void 0);
|
|
240
47
|
function useStrapiCredentials() {
|
|
241
48
|
const creds = useContext(StrapiCredentialsContext);
|
|
@@ -327,7 +134,7 @@ var strapiCollectionMeta = {
|
|
|
327
134
|
displayName: "Filter Parameter",
|
|
328
135
|
description: "Field Parameter filter by",
|
|
329
136
|
options: () => {
|
|
330
|
-
return
|
|
137
|
+
return _queryParameters.map((item) => ({
|
|
331
138
|
label: item == null ? void 0 : item.label,
|
|
332
139
|
value: item == null ? void 0 : item.value
|
|
333
140
|
}));
|
|
@@ -371,10 +178,14 @@ function StrapiCollection({
|
|
|
371
178
|
noAutoRepeat,
|
|
372
179
|
setControlContextData
|
|
373
180
|
}) {
|
|
181
|
+
var _a;
|
|
374
182
|
const { host, token } = useStrapiCredentials();
|
|
375
183
|
if (!host) {
|
|
376
184
|
return /* @__PURE__ */ React2.createElement("div", null, "Please specify a host.");
|
|
377
185
|
}
|
|
186
|
+
if (!name) {
|
|
187
|
+
return /* @__PURE__ */ React2.createElement("div", null, "Please specify a collection.");
|
|
188
|
+
}
|
|
378
189
|
const cacheKey = JSON.stringify({
|
|
379
190
|
host,
|
|
380
191
|
token,
|
|
@@ -383,22 +194,21 @@ function StrapiCollection({
|
|
|
383
194
|
filterValue,
|
|
384
195
|
filterParameter
|
|
385
196
|
});
|
|
386
|
-
const
|
|
197
|
+
const resp = usePlasmicQueryData(
|
|
387
198
|
cacheKey,
|
|
388
199
|
() => __async(this, null, function* () {
|
|
389
200
|
return queryStrapi(host, token, name, filterField, filterValue, filterParameter);
|
|
390
201
|
})
|
|
391
202
|
);
|
|
392
|
-
if (!(
|
|
203
|
+
if (!(resp == null ? void 0 : resp.data)) {
|
|
393
204
|
return /* @__PURE__ */ React2.createElement("div", null, "Please configure the Strapi provider with a valid host and token.");
|
|
394
205
|
}
|
|
395
|
-
if (!
|
|
206
|
+
if (!((_a = resp.data) == null ? void 0 : _a.data)) {
|
|
396
207
|
return /* @__PURE__ */ React2.createElement("div", null, "Please specify a valid collection.");
|
|
397
208
|
}
|
|
398
|
-
const collectionData =
|
|
399
|
-
const filteredFields = filterFields(collectionData);
|
|
209
|
+
const collectionData = resp.data.data;
|
|
400
210
|
setControlContextData == null ? void 0 : setControlContextData({
|
|
401
|
-
strapiFields:
|
|
211
|
+
strapiFields: _extractFilterableFields(collectionData != null ? collectionData : [])
|
|
402
212
|
});
|
|
403
213
|
if (filterParameter && !filterValue && !filterField) {
|
|
404
214
|
return /* @__PURE__ */ React2.createElement("div", null, "Please specify a Filter Field and a Filter Value");
|
|
@@ -422,25 +232,29 @@ function StrapiCollection({
|
|
|
422
232
|
if (collection.length === 0) {
|
|
423
233
|
return /* @__PURE__ */ React2.createElement("div", null, "No collection found ");
|
|
424
234
|
}
|
|
425
|
-
const repElements = noAutoRepeat ? children : collection.map((item, index) =>
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
/* @__PURE__ */ React2.createElement(DataProvider, { name: makeDataProviderName(name), data: item }, repeatedElement(index, children))
|
|
436
|
-
);
|
|
437
|
-
});
|
|
235
|
+
const repElements = noAutoRepeat ? children : collection.map((item, index) => /* @__PURE__ */ React2.createElement(
|
|
236
|
+
DataProvider,
|
|
237
|
+
{
|
|
238
|
+
key: _getId(item),
|
|
239
|
+
name: "strapiItem",
|
|
240
|
+
data: item,
|
|
241
|
+
hidden: true
|
|
242
|
+
},
|
|
243
|
+
/* @__PURE__ */ React2.createElement(DataProvider, { name: makeDataProviderName(name), data: item }, repeatedElement(index, children))
|
|
244
|
+
));
|
|
438
245
|
return /* @__PURE__ */ React2.createElement(DataProvider, { name: "strapiItems", data: collection }, noLayout ? /* @__PURE__ */ React2.createElement(React2.Fragment, null, " ", repElements, " ") : /* @__PURE__ */ React2.createElement("div", { className }, " ", repElements, " "));
|
|
439
246
|
}
|
|
440
247
|
|
|
441
248
|
// src/StrapiField.tsx
|
|
442
249
|
import { useSelector } from "@plasmicapp/host";
|
|
443
|
-
import
|
|
250
|
+
import {
|
|
251
|
+
_extractDisplayableFields,
|
|
252
|
+
_getFieldValue,
|
|
253
|
+
_getMediaAttributes,
|
|
254
|
+
_isImage,
|
|
255
|
+
_isStrapiItem,
|
|
256
|
+
_isStrapiPrimitive
|
|
257
|
+
} from "@plasmicpkgs/strapi";
|
|
444
258
|
import React3 from "react";
|
|
445
259
|
var strapiFieldMeta = {
|
|
446
260
|
name: "StrapiField",
|
|
@@ -464,18 +278,11 @@ function StrapiField({
|
|
|
464
278
|
path,
|
|
465
279
|
setControlContextData
|
|
466
280
|
}) {
|
|
467
|
-
var _a;
|
|
468
281
|
const item = useSelector("strapiItem");
|
|
469
282
|
if (!item) {
|
|
470
283
|
return /* @__PURE__ */ React3.createElement("div", null, "StrapiField must be used within a StrapiCollection");
|
|
471
284
|
}
|
|
472
|
-
const
|
|
473
|
-
const displayableFields = Object.keys(attributes).filter((field) => {
|
|
474
|
-
var _a2;
|
|
475
|
-
const value = attributes[field];
|
|
476
|
-
const maybeMime2 = (_a2 = getAttributes(value == null ? void 0 : value.data)) == null ? void 0 : _a2.mime;
|
|
477
|
-
return typeof value !== "object" || typeof maybeMime2 === "string" && maybeMime2.startsWith("image");
|
|
478
|
-
});
|
|
285
|
+
const displayableFields = _extractDisplayableFields(item);
|
|
479
286
|
setControlContextData == null ? void 0 : setControlContextData({
|
|
480
287
|
fields: displayableFields,
|
|
481
288
|
isImage: false
|
|
@@ -483,31 +290,31 @@ function StrapiField({
|
|
|
483
290
|
if (!path) {
|
|
484
291
|
return /* @__PURE__ */ React3.createElement("div", null, "StrapiField must specify a field name.");
|
|
485
292
|
}
|
|
486
|
-
const data =
|
|
487
|
-
const
|
|
293
|
+
const data = _getFieldValue(item, path);
|
|
294
|
+
const mediaAttributes = _isStrapiItem(data) ? _getMediaAttributes(data) : null;
|
|
488
295
|
setControlContextData == null ? void 0 : setControlContextData({
|
|
489
296
|
fields: displayableFields,
|
|
490
|
-
isImage:
|
|
297
|
+
isImage: mediaAttributes ? _isImage(mediaAttributes) : false
|
|
491
298
|
});
|
|
492
|
-
if (
|
|
299
|
+
if (data === void 0) {
|
|
493
300
|
return /* @__PURE__ */ React3.createElement("div", null, "Please specify a valid field name.");
|
|
494
|
-
} else if (
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
const img_url = attrs.url.startsWith("http") ? attrs.url : creds.host + attrs.url;
|
|
498
|
-
const img_width = attrs.width;
|
|
499
|
-
const img_height = attrs.height;
|
|
301
|
+
} else if (data === null) {
|
|
302
|
+
return /* @__PURE__ */ React3.createElement("div", { className });
|
|
303
|
+
} else if (mediaAttributes && _isImage(mediaAttributes)) {
|
|
500
304
|
return /* @__PURE__ */ React3.createElement(
|
|
501
305
|
"img",
|
|
502
306
|
{
|
|
503
307
|
className,
|
|
504
|
-
src:
|
|
308
|
+
src: mediaAttributes.absoluteUrl,
|
|
505
309
|
width: 300,
|
|
506
|
-
height: 300 *
|
|
310
|
+
height: 300 * mediaAttributes.height / mediaAttributes.width
|
|
507
311
|
}
|
|
508
312
|
);
|
|
509
|
-
} else {
|
|
313
|
+
} else if (_isStrapiPrimitive(data)) {
|
|
510
314
|
return /* @__PURE__ */ React3.createElement("div", { className }, data);
|
|
315
|
+
} else {
|
|
316
|
+
console.warn("Complex field value:", data);
|
|
317
|
+
return /* @__PURE__ */ React3.createElement("div", null, "Complex field value could not be displayed. See console for details.");
|
|
511
318
|
}
|
|
512
319
|
}
|
|
513
320
|
|
|
@@ -538,10 +345,7 @@ export {
|
|
|
538
345
|
StrapiCollection,
|
|
539
346
|
StrapiCredentialsProvider,
|
|
540
347
|
StrapiField,
|
|
541
|
-
queryStrapi,
|
|
542
|
-
queryStrapiMeta,
|
|
543
348
|
registerAll,
|
|
544
|
-
registerAllCustomFunctions,
|
|
545
349
|
strapiCollectionMeta,
|
|
546
350
|
strapiCredentialsProviderMeta,
|
|
547
351
|
strapiFieldMeta
|
package/dist/index.esm.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../src/index.tsx", "../src/StrapiCollection.tsx", "../src/
|
|
4
|
-
"sourcesContent": ["import registerComponent, {\n ComponentMeta,\n} from \"@plasmicapp/host/registerComponent\";\nimport registerGlobalContext from \"@plasmicapp/host/registerGlobalContext\";\nimport { StrapiCollection, strapiCollectionMeta } from \"./StrapiCollection\";\nimport {\n StrapiCredentialsProvider,\n strapiCredentialsProviderMeta,\n} from \"./StrapiCredentialsProvider\";\nimport { StrapiField, strapiFieldMeta } from \"./StrapiField\";\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 StrapiCredentialsProvider,\n strapiCredentialsProviderMeta\n );\n } else {\n registerGlobalContext(\n StrapiCredentialsProvider,\n strapiCredentialsProviderMeta\n );\n }\n\n _registerComponent(StrapiCollection, strapiCollectionMeta);\n _registerComponent(StrapiField, strapiFieldMeta);\n}\n\nexport * from \"./custom-functions\";\nexport { StrapiCollection, strapiCollectionMeta } from \"./StrapiCollection\";\nexport {\n StrapiCredentialsProvider,\n strapiCredentialsProviderMeta,\n} from \"./StrapiCredentialsProvider\";\nexport { StrapiField, strapiFieldMeta } from \"./StrapiField\";\n", "import { ComponentMeta, DataProvider, repeatedElement } from \"@plasmicapp/host\";\nimport { usePlasmicQueryData } from \"@plasmicapp/query\";\nimport { pascalCase } from \"change-case\";\nimport get from \"dlv\";\nimport React, { ReactNode } from \"react\";\nimport { queryStrapi } from \"./custom-functions\";\nimport { useStrapiCredentials } from \"./StrapiCredentialsProvider\";\nimport { filterFields, modulePath, queryParameters, uniq } from \"./utils\";\n\nconst makeDataProviderName = (collection: string) =>\n `currentStrapi${pascalCase(collection)}Item`;\n\ninterface StrapiCollectionProps {\n name?: string;\n children?: ReactNode;\n className?: string;\n noLayout?: boolean;\n noAutoRepeat?: boolean;\n filterField?: string;\n filterValue?: string;\n limit?: number;\n filterParameter?: string;\n setControlContextData?: (data: { strapiFields: string[] }) => void;\n}\n\nexport const strapiCollectionMeta: ComponentMeta<StrapiCollectionProps> = {\n name: \"StrapiCollection\",\n displayName: \"Strapi Collection\",\n importName: \"StrapiCollection\",\n importPath: modulePath,\n providesData: true,\n description:\n \"Fetches Strapi data of a given collection, and repeats `children` slot content for each row fetched. [See tutorial video](https://www.youtube.com/watch?v=1SLoVY3hkQ4).\",\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 children: {\n type: \"component\",\n name: \"StrapiField\",\n },\n },\n },\n name: {\n type: \"string\",\n displayName: \"Name\",\n description: \"Name of the collection to be fetched.\",\n defaultValueHint: \"restaurants\",\n },\n filterField: {\n type: \"choice\",\n displayName: \"Filter field\",\n description: \"Field (from Collection) to filter by\",\n options: (_, ctx) => ctx?.strapiFields ?? [],\n hidden: (props) => !props.name,\n },\n filterParameter: {\n type: \"choice\",\n displayName: \"Filter Parameter\",\n description: \"Field Parameter filter by\",\n options: () => {\n return queryParameters.map((item: any) => ({\n label: item?.label,\n value: item?.value,\n }));\n },\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.filterParameter,\n },\n limit: {\n type: \"number\",\n displayName: \"Limit\",\n description: \"Maximum number of collections to fetch (0 for unlimited).\",\n },\n noLayout: {\n type: \"boolean\",\n displayName: \"No layout\",\n description:\n \"When set, Strapi Collection 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 noAutoRepeat: {\n type: \"boolean\",\n displayName: \"No auto-repeat\",\n description: \"Do not automatically repeat children for every category.\",\n defaultValue: false,\n },\n },\n};\n\nexport function StrapiCollection({\n name,\n filterParameter,\n filterValue,\n filterField,\n limit,\n children,\n className,\n noLayout,\n noAutoRepeat,\n setControlContextData,\n}: StrapiCollectionProps) {\n const { host, token } = useStrapiCredentials();\n\n if (!host) {\n return <div>Please specify a host.</div>;\n }\n\n const cacheKey = JSON.stringify({\n host,\n token,\n name,\n filterField,\n filterValue,\n filterParameter,\n });\n\n const data = usePlasmicQueryData<any[] | null>(cacheKey, async () =>\n queryStrapi(host, token, name, filterField, filterValue, filterParameter)\n );\n\n if (!data?.data) {\n return (\n <div>\n Please configure the Strapi provider with a valid host and token.\n </div>\n );\n }\n\n if (!get(data.data, [\"data\"])) {\n return <div>Please specify a valid collection.</div>;\n }\n\n const collectionData = get(data.data, [\"data\"]) as any[];\n\n const filteredFields = filterFields(collectionData);\n\n setControlContextData?.({\n strapiFields: uniq(filteredFields ?? []),\n });\n if (filterParameter && !filterValue && !filterField) {\n return <div>Please specify a Filter Field and a Filter Value</div>;\n }\n if (!filterParameter && filterValue && !filterField) {\n return <div>Please specify a Filter Parameter and a Filter Field</div>;\n }\n if (!filterParameter && !filterValue && filterField) {\n return <div>Please specify a Filter Parameter and a Filter Value</div>;\n }\n\n if (filterParameter && filterValue && !filterField) {\n return <div>Please specify a Filter Field</div>;\n }\n if (!filterParameter && filterValue && filterField) {\n return <div>Please specify a Filter Parameter</div>;\n }\n if (filterParameter && !filterValue && filterField) {\n return <div>Please specify a Filter Value</div>;\n }\n\n const collection =\n limit! > 0 ? collectionData.slice(0, limit) : collectionData;\n\n if (collection.length === 0) {\n return <div>No collection found </div>;\n }\n\n const repElements = noAutoRepeat\n ? children\n : collection.map((item, index) => (\n <DataProvider\n key={item.documentId ?? item.id}\n name={\"strapiItem\"}\n data={item}\n hidden={true}\n >\n <DataProvider name={makeDataProviderName(name!)} data={item}>\n {repeatedElement(index, children)}\n </DataProvider>\n </DataProvider>\n ));\n\n return (\n <DataProvider name=\"strapiItems\" data={collection}>\n {noLayout ? (\n <> {repElements} </>\n ) : (\n <div className={className}> {repElements} </div>\n )}\n </DataProvider>\n );\n}\n", "import registerFunction, {\n CustomFunctionMeta,\n} from \"@plasmicapp/host/registerFunction\";\nimport get from \"dlv\";\nimport qs from \"qs\";\nimport { filterFields, modulePath, queryParameters, uniq } from \"./utils\";\n\nexport const queryStrapiMeta: CustomFunctionMeta<typeof queryStrapi> = {\n name: \"queryStrapi\",\n displayName: \"Query Strapi\",\n description: \"Query a Strapi collection\",\n importPath: modulePath,\n params: [\n {\n name: \"strapiHost\",\n type: \"string\",\n description: \"The Strapi host URL (e.g., https://example.com)\",\n },\n {\n name: \"strapiToken\",\n type: \"string\",\n description:\n \"The Strapi API token (optional, for authenticated requests)\",\n },\n {\n name: \"collection\",\n type: \"string\",\n description: \"The name of the Strapi collection to query\",\n },\n {\n name: \"filterField\",\n type: \"choice\",\n options: (_, ctx) => {\n return ctx?.strapiFields;\n },\n },\n {\n name: \"filterValue\",\n type: \"string\",\n description:\n \"The value to filter by (optional, if you want to filter results)\",\n },\n {\n name: \"filterParameter\",\n type: \"choice\",\n description:\n \"The parameter for filtering (e.g., 'eq', 'contains', etc.) (optional)\",\n options: () => {\n return queryParameters.map((item: any) => ({\n label: item?.label,\n value: item?.value,\n }));\n },\n },\n ],\n fnContext: (host, token, collection) => {\n return {\n dataKey: JSON.stringify({ host, token, collection }),\n fetcher: async () => {\n if (!host) {\n return {};\n }\n const data = await queryStrapi(host, token, collection);\n if (!get(data.data, [\"data\"])) {\n return { strapiFields: [] };\n }\n\n const collectionData = get(data.data, [\"data\"]) as any[];\n\n const filteredFields = filterFields(collectionData);\n return { strapiFields: uniq(filteredFields ?? []) };\n },\n };\n },\n};\n\nexport async function queryStrapi(\n host: string,\n token: string | undefined,\n collection: string | undefined,\n filterField?: string,\n filterValue?: string,\n filterParameter?: string\n) {\n if (!host) {\n return null;\n }\n\n collection = collection ?? \"\";\n\n const query = host.trim() + \"/api/\" + collection.trim();\n\n const requestInit: any = { method: \"GET\" };\n if (token) {\n requestInit.headers = { Authorization: \"Bearer \" + token };\n }\n\n const queryParams = qs.stringify({\n ...(filterField && filterParameter && filterValue\n ? {\n filters: {\n [filterField]: {\n [filterParameter]: filterValue,\n },\n },\n }\n : {}),\n populate: \"*\",\n });\n\n const resp = await fetch(`${query}?${queryParams}`, requestInit);\n return resp.json();\n}\n\nexport function registerAllCustomFunctions(loader?: { registerFunction: any }) {\n function _registerFunction<T extends (...args: any[]) => any>(\n fn: T,\n meta: CustomFunctionMeta<T>\n ) {\n if (loader) {\n loader.registerFunction(fn, meta);\n } else {\n registerFunction(fn, meta);\n }\n }\n\n _registerFunction(queryStrapi, queryStrapiMeta);\n}\n", "export const modulePath = \"@plasmicpkgs/plasmic-strapi\";\n\nexport const queryParameters = [\n {\n value: \"$eq\",\n label: \"Equal\",\n },\n {\n value: \"$ne\",\n label: \"Not equal\",\n },\n {\n value: \"$lt\",\n label: \"Less than\",\n },\n {\n value: \"$lte\",\n label: \"Less than or equal to\",\n },\n {\n value: \"$gt\",\n label: \"Greater than\",\n },\n {\n value: \"$gte\",\n label: \"Greater than or equal to\",\n },\n {\n value: \"$in\",\n label: \"Included in an array\",\n },\n {\n value: \"$notIn\",\n label: \"Not included in an array\",\n },\n {\n value: \"$contains\",\n label: \"Contains\",\n },\n {\n value: \"$notContains\",\n label: \"Does not contain\",\n },\n];\n\nexport const uniq = <T>(xs: Array<T>): T[] => Array.from(new Set(xs));\n\nexport const getAttributes = (item?: Record<string, any>) => {\n if (!item) {\n return undefined;\n }\n // Strapi v4\n if (item.attributes) {\n return item.attributes;\n }\n // Strapi v5\n const { documentId: _documentId, locale: _locale, ...rest } = item;\n return rest;\n};\n\nexport function filterFields(collectionData: any[]) {\n return collectionData.flatMap((item: any) => {\n const attributes = getAttributes(item);\n const displayableFields = Object.keys(attributes).filter((field) => {\n const value = attributes[field];\n const maybeMime = getAttributes(value?.data)?.mime;\n return (\n typeof value !== \"object\" ||\n (typeof maybeMime === \"string\" && maybeMime.startsWith(\"image\"))\n );\n });\n return displayableFields;\n });\n}\n", "import { GlobalContextMeta } from \"@plasmicapp/host\";\nimport React, { useContext } from \"react\";\nimport { modulePath } from \"./utils\";\n\ninterface StrapiCredentials {\n host?: string;\n token?: string;\n}\n\nconst StrapiCredentialsContext = React.createContext<\n StrapiCredentials | undefined\n>(undefined);\n\nexport function useStrapiCredentials() {\n const creds = useContext(StrapiCredentialsContext);\n if (!creds) {\n throw new Error(\"Missing StrapiCredentials\");\n }\n\n return creds;\n}\n\nexport const strapiCredentialsProviderMeta: GlobalContextMeta<StrapiCredentials> =\n {\n name: \"StrapiCredentialsProvider\",\n displayName: \"Strapi Credentials Provider\",\n description: `[See tutorial video](https://www.youtube.com/watch?v=1SLoVY3hkQ4).\n\nAPI token is needed only if data is not publicly readable.\n\nLearn how to [get your API token](https://docs.strapi.io/user-docs/latest/settings/managing-global-settings.html#managing-api-tokens).`,\n importName: \"StrapiCredentialsProvider\",\n importPath: modulePath,\n props: {\n host: {\n type: \"string\",\n displayName: \"Host\",\n defaultValueHint: \"https://your_project_id.strapiapp.com/\",\n defaultValue: \"https://graceful-belief-d395c347a3.strapiapp.com/\",\n description: \"Server where you application is hosted.\",\n },\n token: {\n type: \"string\",\n displayName: \"API Token\",\n description:\n \"API Token (generated in http://yourhost/admin/settings/api-tokens) (or leave blank for unauthenticated usage).\",\n },\n },\n };\n\nexport function StrapiCredentialsProvider({\n host,\n token,\n children,\n}: React.PropsWithChildren<StrapiCredentials>) {\n host = host?.replace(/\\/+$/, \"\");\n return (\n <StrapiCredentialsContext.Provider value={{ host, token }}>\n {children}\n </StrapiCredentialsContext.Provider>\n );\n}\n", "import { ComponentMeta, useSelector } from \"@plasmicapp/host\";\nimport get from \"dlv\";\nimport React from \"react\";\nimport { useStrapiCredentials } from \"./StrapiCredentialsProvider\";\nimport { getAttributes, modulePath } from \"./utils\";\n\ninterface StrapiFieldProps {\n className?: string;\n path?: string;\n setControlContextData?: (data: {\n fields: string[];\n isImage: boolean;\n }) => void;\n}\n\nexport const strapiFieldMeta: ComponentMeta<StrapiFieldProps> = {\n name: \"StrapiField\",\n displayName: \"Strapi Field\",\n importName: \"StrapiField\",\n importPath: modulePath,\n props: {\n path: {\n type: \"choice\",\n options: (_, ctx) => {\n return ctx?.fields ?? [];\n },\n displayName: \"Field\",\n description: \"Field name\",\n },\n },\n};\n\nexport function StrapiField({\n className,\n path,\n setControlContextData,\n}: StrapiFieldProps) {\n const item = useSelector(\"strapiItem\");\n if (!item) {\n return <div>StrapiField must be used within a StrapiCollection</div>;\n }\n\n // Getting only fields that aren't objects\n const attributes = getAttributes(item);\n const displayableFields = Object.keys(attributes).filter((field) => {\n const value = attributes[field];\n const maybeMime = getAttributes(value?.data)?.mime;\n return (\n typeof value !== \"object\" ||\n (typeof maybeMime === \"string\" && maybeMime.startsWith(\"image\"))\n );\n });\n\n setControlContextData?.({\n fields: displayableFields,\n isImage: false,\n });\n\n if (!path) {\n return <div>StrapiField must specify a field name.</div>;\n }\n\n const data = get(attributes, [path]);\n const maybeMime = getAttributes(data?.data)?.mime;\n\n setControlContextData?.({\n fields: displayableFields,\n isImage: typeof maybeMime === \"string\" && maybeMime.startsWith(\"image\"),\n });\n\n if (!data) {\n return <div>Please specify a valid field name.</div>;\n } else if (typeof maybeMime === \"string\" && maybeMime.startsWith(\"image\")) {\n const creds = useStrapiCredentials();\n const attrs = getAttributes(data.data);\n const img_url = attrs.url.startsWith(\"http\")\n ? attrs.url\n : creds.host + attrs.url;\n const img_width = attrs.width;\n const img_height = attrs.height;\n return (\n <img\n className={className}\n src={img_url}\n width={300}\n height={(300 * img_height) / img_width}\n />\n );\n } else {\n return <div className={className}>{data}</div>;\n }\n}\n"],
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": ["
|
|
3
|
+
"sources": ["../src/index.tsx", "../src/StrapiCollection.tsx", "../src/StrapiCredentialsProvider.tsx", "../src/utils.ts", "../src/StrapiField.tsx"],
|
|
4
|
+
"sourcesContent": ["import registerComponent, {\n ComponentMeta,\n} from \"@plasmicapp/host/registerComponent\";\nimport registerGlobalContext from \"@plasmicapp/host/registerGlobalContext\";\nimport { StrapiCollection, strapiCollectionMeta } from \"./StrapiCollection\";\nimport {\n StrapiCredentialsProvider,\n strapiCredentialsProviderMeta,\n} from \"./StrapiCredentialsProvider\";\nimport { StrapiField, strapiFieldMeta } from \"./StrapiField\";\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 StrapiCredentialsProvider,\n strapiCredentialsProviderMeta\n );\n } else {\n registerGlobalContext(\n StrapiCredentialsProvider,\n strapiCredentialsProviderMeta\n );\n }\n\n _registerComponent(StrapiCollection, strapiCollectionMeta);\n _registerComponent(StrapiField, strapiFieldMeta);\n}\n\nexport { StrapiCollection, strapiCollectionMeta } from \"./StrapiCollection\";\nexport {\n StrapiCredentialsProvider,\n strapiCredentialsProviderMeta,\n} from \"./StrapiCredentialsProvider\";\nexport { StrapiField, strapiFieldMeta } from \"./StrapiField\";\n", "import { ComponentMeta, DataProvider, repeatedElement } from \"@plasmicapp/host\";\nimport { usePlasmicQueryData } from \"@plasmicapp/query\";\nimport {\n _extractFilterableFields,\n _getId,\n _queryParameters,\n queryStrapi,\n} from \"@plasmicpkgs/strapi\";\nimport { pascalCase } from \"change-case\";\nimport React, { ReactNode } from \"react\";\nimport { useStrapiCredentials } from \"./StrapiCredentialsProvider\";\nimport { modulePath } from \"./utils\";\n\nconst makeDataProviderName = (collection: string) =>\n `currentStrapi${pascalCase(collection)}Item`;\n\ninterface StrapiCollectionProps {\n name?: string;\n children?: ReactNode;\n className?: string;\n noLayout?: boolean;\n noAutoRepeat?: boolean;\n filterField?: string;\n filterValue?: string;\n limit?: number;\n filterParameter?: string;\n setControlContextData?: (data: { strapiFields: string[] }) => void;\n}\n\nexport const strapiCollectionMeta: ComponentMeta<StrapiCollectionProps> = {\n name: \"StrapiCollection\",\n displayName: \"Strapi Collection\",\n importName: \"StrapiCollection\",\n importPath: modulePath,\n providesData: true,\n description:\n \"Fetches Strapi data of a given collection, and repeats `children` slot content for each row fetched. [See tutorial video](https://www.youtube.com/watch?v=1SLoVY3hkQ4).\",\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 children: {\n type: \"component\",\n name: \"StrapiField\",\n },\n },\n },\n name: {\n type: \"string\",\n displayName: \"Name\",\n description: \"Name of the collection to be fetched.\",\n defaultValueHint: \"restaurants\",\n },\n filterField: {\n type: \"choice\",\n displayName: \"Filter field\",\n description: \"Field (from Collection) to filter by\",\n options: (_, ctx) => ctx?.strapiFields ?? [],\n hidden: (props) => !props.name,\n },\n filterParameter: {\n type: \"choice\",\n displayName: \"Filter Parameter\",\n description: \"Field Parameter filter by\",\n options: () => {\n return _queryParameters.map((item: any) => ({\n label: item?.label,\n value: item?.value,\n }));\n },\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.filterParameter,\n },\n limit: {\n type: \"number\",\n displayName: \"Limit\",\n description: \"Maximum number of collections to fetch (0 for unlimited).\",\n },\n noLayout: {\n type: \"boolean\",\n displayName: \"No layout\",\n description:\n \"When set, Strapi Collection 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 noAutoRepeat: {\n type: \"boolean\",\n displayName: \"No auto-repeat\",\n description: \"Do not automatically repeat children for every category.\",\n defaultValue: false,\n },\n },\n};\n\nexport function StrapiCollection({\n name,\n filterParameter,\n filterValue,\n filterField,\n limit,\n children,\n className,\n noLayout,\n noAutoRepeat,\n setControlContextData,\n}: StrapiCollectionProps) {\n const { host, token } = useStrapiCredentials();\n\n if (!host) {\n return <div>Please specify a host.</div>;\n }\n\n if (!name) {\n return <div>Please specify a collection.</div>;\n }\n\n const cacheKey = JSON.stringify({\n host,\n token,\n name,\n filterField,\n filterValue,\n filterParameter,\n });\n\n const resp = usePlasmicQueryData(cacheKey, async () =>\n queryStrapi(host, token, name, filterField, filterValue, filterParameter)\n );\n\n if (!resp?.data) {\n return (\n <div>\n Please configure the Strapi provider with a valid host and token.\n </div>\n );\n }\n\n if (!resp.data?.data) {\n return <div>Please specify a valid collection.</div>;\n }\n\n const collectionData = resp.data.data;\n\n setControlContextData?.({\n strapiFields: _extractFilterableFields(collectionData ?? []),\n });\n if (filterParameter && !filterValue && !filterField) {\n return <div>Please specify a Filter Field and a Filter Value</div>;\n }\n if (!filterParameter && filterValue && !filterField) {\n return <div>Please specify a Filter Parameter and a Filter Field</div>;\n }\n if (!filterParameter && !filterValue && filterField) {\n return <div>Please specify a Filter Parameter and a Filter Value</div>;\n }\n\n if (filterParameter && filterValue && !filterField) {\n return <div>Please specify a Filter Field</div>;\n }\n if (!filterParameter && filterValue && filterField) {\n return <div>Please specify a Filter Parameter</div>;\n }\n if (filterParameter && !filterValue && filterField) {\n return <div>Please specify a Filter Value</div>;\n }\n\n const collection =\n limit! > 0 ? collectionData.slice(0, limit) : collectionData;\n\n if (collection.length === 0) {\n return <div>No collection found </div>;\n }\n\n const repElements = noAutoRepeat\n ? children\n : collection.map((item, index) => (\n <DataProvider\n key={_getId(item)}\n name={\"strapiItem\"}\n data={item}\n hidden={true}\n >\n <DataProvider name={makeDataProviderName(name!)} data={item}>\n {repeatedElement(index, children)}\n </DataProvider>\n </DataProvider>\n ));\n\n return (\n <DataProvider name=\"strapiItems\" data={collection}>\n {noLayout ? (\n <> {repElements} </>\n ) : (\n <div className={className}> {repElements} </div>\n )}\n </DataProvider>\n );\n}\n", "import { GlobalContextMeta } from \"@plasmicapp/host\";\nimport React, { useContext } from \"react\";\nimport { modulePath } from \"./utils\";\n\ninterface StrapiCredentials {\n host?: string;\n token?: string;\n}\n\nconst StrapiCredentialsContext = React.createContext<\n StrapiCredentials | undefined\n>(undefined);\n\nexport function useStrapiCredentials() {\n const creds = useContext(StrapiCredentialsContext);\n if (!creds) {\n throw new Error(\"Missing StrapiCredentials\");\n }\n\n return creds;\n}\n\nexport const strapiCredentialsProviderMeta: GlobalContextMeta<StrapiCredentials> =\n {\n name: \"StrapiCredentialsProvider\",\n displayName: \"Strapi Credentials Provider\",\n description: `[See tutorial video](https://www.youtube.com/watch?v=1SLoVY3hkQ4).\n\nAPI token is needed only if data is not publicly readable.\n\nLearn how to [get your API token](https://docs.strapi.io/user-docs/latest/settings/managing-global-settings.html#managing-api-tokens).`,\n importName: \"StrapiCredentialsProvider\",\n importPath: modulePath,\n props: {\n host: {\n type: \"string\",\n displayName: \"Host\",\n defaultValueHint: \"https://your_project_id.strapiapp.com/\",\n defaultValue: \"https://graceful-belief-d395c347a3.strapiapp.com/\",\n description: \"Server where you application is hosted.\",\n },\n token: {\n type: \"string\",\n displayName: \"API Token\",\n description:\n \"API Token (generated in http://yourhost/admin/settings/api-tokens) (or leave blank for unauthenticated usage).\",\n },\n },\n };\n\nexport function StrapiCredentialsProvider({\n host,\n token,\n children,\n}: React.PropsWithChildren<StrapiCredentials>) {\n host = host?.replace(/\\/+$/, \"\");\n return (\n <StrapiCredentialsContext.Provider value={{ host, token }}>\n {children}\n </StrapiCredentialsContext.Provider>\n );\n}\n", "export const modulePath = \"@plasmicpkgs/plasmic-strapi\";\n", "import { ComponentMeta, useSelector } from \"@plasmicapp/host\";\nimport {\n _extractDisplayableFields,\n _getFieldValue,\n _getMediaAttributes,\n _isImage,\n _isStrapiItem,\n _isStrapiPrimitive,\n} from \"@plasmicpkgs/strapi\";\nimport React from \"react\";\nimport { modulePath } from \"./utils\";\n\ninterface StrapiFieldProps {\n className?: string;\n path?: string;\n setControlContextData?: (data: {\n fields: string[];\n isImage: boolean;\n }) => void;\n}\n\nexport const strapiFieldMeta: ComponentMeta<StrapiFieldProps> = {\n name: \"StrapiField\",\n displayName: \"Strapi Field\",\n importName: \"StrapiField\",\n importPath: modulePath,\n props: {\n path: {\n type: \"choice\",\n options: (_, ctx) => {\n return ctx?.fields ?? [];\n },\n displayName: \"Field\",\n description: \"Field name\",\n },\n },\n};\n\nexport function StrapiField({\n className,\n path,\n setControlContextData,\n}: StrapiFieldProps) {\n const item = useSelector(\"strapiItem\");\n if (!item) {\n return <div>StrapiField must be used within a StrapiCollection</div>;\n }\n\n // Getting only fields that aren't objects\n const displayableFields = _extractDisplayableFields(item);\n\n setControlContextData?.({\n fields: displayableFields,\n isImage: false,\n });\n\n if (!path) {\n return <div>StrapiField must specify a field name.</div>;\n }\n\n const data = _getFieldValue(item, path);\n const mediaAttributes = _isStrapiItem(data)\n ? _getMediaAttributes(data)\n : null;\n\n setControlContextData?.({\n fields: displayableFields,\n isImage: mediaAttributes ? _isImage(mediaAttributes) : false,\n });\n\n if (data === undefined) {\n return <div>Please specify a valid field name.</div>;\n } else if (data === null) {\n return <div className={className}></div>;\n } else if (mediaAttributes && _isImage(mediaAttributes)) {\n // URL is already absolute after transformMediaUrls in queryStrapi\n return (\n <img\n className={className}\n src={mediaAttributes.absoluteUrl}\n width={300}\n height={(300 * mediaAttributes.height) / mediaAttributes.width}\n />\n );\n } else if (_isStrapiPrimitive(data)) {\n return <div className={className}>{data}</div>;\n } else {\n console.warn(\"Complex field value:\", data);\n return (\n <div>\n Complex field value could not be displayed. See console for details.\n </div>\n );\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,uBAEA;AACP,OAAO,2BAA2B;;;ACHlC,SAAwB,cAAc,uBAAuB;AAC7D,SAAS,2BAA2B;AACpC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,kBAAkB;AAC3B,OAAOA,YAA0B;;;ACRjC,OAAO,SAAS,kBAAkB;;;ACD3B,IAAM,aAAa;;;ADS1B,IAAM,2BAA2B,MAAM,cAErC,MAAS;AAEJ,SAAS,uBAAuB;AACrC,QAAM,QAAQ,WAAW,wBAAwB;AACjD,MAAI,CAAC,O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
7
|
}
|
package/dist/index.js
CHANGED
|
@@ -2,39 +2,10 @@
|
|
|
2
2
|
"use strict";
|
|
3
3
|
var __create = Object.create;
|
|
4
4
|
var __defProp = Object.defineProperty;
|
|
5
|
-
var __defProps = Object.defineProperties;
|
|
6
5
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
7
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
8
6
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
9
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
10
7
|
var __getProtoOf = Object.getPrototypeOf;
|
|
11
8
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
12
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
13
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
14
|
-
var __spreadValues = (a, b) => {
|
|
15
|
-
for (var prop in b || (b = {}))
|
|
16
|
-
if (__hasOwnProp.call(b, prop))
|
|
17
|
-
__defNormalProp(a, prop, b[prop]);
|
|
18
|
-
if (__getOwnPropSymbols)
|
|
19
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
20
|
-
if (__propIsEnum.call(b, prop))
|
|
21
|
-
__defNormalProp(a, prop, b[prop]);
|
|
22
|
-
}
|
|
23
|
-
return a;
|
|
24
|
-
};
|
|
25
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
26
|
-
var __objRest = (source, exclude) => {
|
|
27
|
-
var target = {};
|
|
28
|
-
for (var prop in source)
|
|
29
|
-
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
30
|
-
target[prop] = source[prop];
|
|
31
|
-
if (source != null && __getOwnPropSymbols)
|
|
32
|
-
for (var prop of __getOwnPropSymbols(source)) {
|
|
33
|
-
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
34
|
-
target[prop] = source[prop];
|
|
35
|
-
}
|
|
36
|
-
return target;
|
|
37
|
-
};
|
|
38
9
|
var __export = (target, all) => {
|
|
39
10
|
for (var name in all)
|
|
40
11
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -83,10 +54,7 @@ __export(src_exports, {
|
|
|
83
54
|
StrapiCollection: () => StrapiCollection,
|
|
84
55
|
StrapiCredentialsProvider: () => StrapiCredentialsProvider,
|
|
85
56
|
StrapiField: () => StrapiField,
|
|
86
|
-
queryStrapi: () => queryStrapi,
|
|
87
|
-
queryStrapiMeta: () => queryStrapiMeta,
|
|
88
57
|
registerAll: () => registerAll,
|
|
89
|
-
registerAllCustomFunctions: () => registerAllCustomFunctions,
|
|
90
58
|
strapiCollectionMeta: () => strapiCollectionMeta,
|
|
91
59
|
strapiCredentialsProviderMeta: () => strapiCredentialsProviderMeta,
|
|
92
60
|
strapiFieldMeta: () => strapiFieldMeta
|
|
@@ -98,184 +66,17 @@ var import_registerGlobalContext = __toESM(require("@plasmicapp/host/registerGlo
|
|
|
98
66
|
// src/StrapiCollection.tsx
|
|
99
67
|
var import_host = require("@plasmicapp/host");
|
|
100
68
|
var import_query = require("@plasmicapp/query");
|
|
69
|
+
var import_strapi = require("@plasmicpkgs/strapi");
|
|
101
70
|
var import_change_case = require("change-case");
|
|
102
|
-
var import_dlv2 = __toESM(require("dlv"));
|
|
103
71
|
var import_react2 = __toESM(require("react"));
|
|
104
72
|
|
|
105
|
-
// src/
|
|
106
|
-
var
|
|
107
|
-
var import_dlv = __toESM(require("dlv"));
|
|
108
|
-
var import_qs = __toESM(require("qs"));
|
|
73
|
+
// src/StrapiCredentialsProvider.tsx
|
|
74
|
+
var import_react = __toESM(require("react"));
|
|
109
75
|
|
|
110
76
|
// src/utils.ts
|
|
111
77
|
var modulePath = "@plasmicpkgs/plasmic-strapi";
|
|
112
|
-
var queryParameters = [
|
|
113
|
-
{
|
|
114
|
-
value: "$eq",
|
|
115
|
-
label: "Equal"
|
|
116
|
-
},
|
|
117
|
-
{
|
|
118
|
-
value: "$ne",
|
|
119
|
-
label: "Not equal"
|
|
120
|
-
},
|
|
121
|
-
{
|
|
122
|
-
value: "$lt",
|
|
123
|
-
label: "Less than"
|
|
124
|
-
},
|
|
125
|
-
{
|
|
126
|
-
value: "$lte",
|
|
127
|
-
label: "Less than or equal to"
|
|
128
|
-
},
|
|
129
|
-
{
|
|
130
|
-
value: "$gt",
|
|
131
|
-
label: "Greater than"
|
|
132
|
-
},
|
|
133
|
-
{
|
|
134
|
-
value: "$gte",
|
|
135
|
-
label: "Greater than or equal to"
|
|
136
|
-
},
|
|
137
|
-
{
|
|
138
|
-
value: "$in",
|
|
139
|
-
label: "Included in an array"
|
|
140
|
-
},
|
|
141
|
-
{
|
|
142
|
-
value: "$notIn",
|
|
143
|
-
label: "Not included in an array"
|
|
144
|
-
},
|
|
145
|
-
{
|
|
146
|
-
value: "$contains",
|
|
147
|
-
label: "Contains"
|
|
148
|
-
},
|
|
149
|
-
{
|
|
150
|
-
value: "$notContains",
|
|
151
|
-
label: "Does not contain"
|
|
152
|
-
}
|
|
153
|
-
];
|
|
154
|
-
var uniq = (xs) => Array.from(new Set(xs));
|
|
155
|
-
var getAttributes = (item) => {
|
|
156
|
-
if (!item) {
|
|
157
|
-
return void 0;
|
|
158
|
-
}
|
|
159
|
-
if (item.attributes) {
|
|
160
|
-
return item.attributes;
|
|
161
|
-
}
|
|
162
|
-
const _a = item, { documentId: _documentId, locale: _locale } = _a, rest = __objRest(_a, ["documentId", "locale"]);
|
|
163
|
-
return rest;
|
|
164
|
-
};
|
|
165
|
-
function filterFields(collectionData) {
|
|
166
|
-
return collectionData.flatMap((item) => {
|
|
167
|
-
const attributes = getAttributes(item);
|
|
168
|
-
const displayableFields = Object.keys(attributes).filter((field) => {
|
|
169
|
-
var _a;
|
|
170
|
-
const value = attributes[field];
|
|
171
|
-
const maybeMime = (_a = getAttributes(value == null ? void 0 : value.data)) == null ? void 0 : _a.mime;
|
|
172
|
-
return typeof value !== "object" || typeof maybeMime === "string" && maybeMime.startsWith("image");
|
|
173
|
-
});
|
|
174
|
-
return displayableFields;
|
|
175
|
-
});
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
// src/custom-functions.tsx
|
|
179
|
-
var queryStrapiMeta = {
|
|
180
|
-
name: "queryStrapi",
|
|
181
|
-
displayName: "Query Strapi",
|
|
182
|
-
description: "Query a Strapi collection",
|
|
183
|
-
importPath: modulePath,
|
|
184
|
-
params: [
|
|
185
|
-
{
|
|
186
|
-
name: "strapiHost",
|
|
187
|
-
type: "string",
|
|
188
|
-
description: "The Strapi host URL (e.g., https://example.com)"
|
|
189
|
-
},
|
|
190
|
-
{
|
|
191
|
-
name: "strapiToken",
|
|
192
|
-
type: "string",
|
|
193
|
-
description: "The Strapi API token (optional, for authenticated requests)"
|
|
194
|
-
},
|
|
195
|
-
{
|
|
196
|
-
name: "collection",
|
|
197
|
-
type: "string",
|
|
198
|
-
description: "The name of the Strapi collection to query"
|
|
199
|
-
},
|
|
200
|
-
{
|
|
201
|
-
name: "filterField",
|
|
202
|
-
type: "choice",
|
|
203
|
-
options: (_, ctx) => {
|
|
204
|
-
return ctx == null ? void 0 : ctx.strapiFields;
|
|
205
|
-
}
|
|
206
|
-
},
|
|
207
|
-
{
|
|
208
|
-
name: "filterValue",
|
|
209
|
-
type: "string",
|
|
210
|
-
description: "The value to filter by (optional, if you want to filter results)"
|
|
211
|
-
},
|
|
212
|
-
{
|
|
213
|
-
name: "filterParameter",
|
|
214
|
-
type: "choice",
|
|
215
|
-
description: "The parameter for filtering (e.g., 'eq', 'contains', etc.) (optional)",
|
|
216
|
-
options: () => {
|
|
217
|
-
return queryParameters.map((item) => ({
|
|
218
|
-
label: item == null ? void 0 : item.label,
|
|
219
|
-
value: item == null ? void 0 : item.value
|
|
220
|
-
}));
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
],
|
|
224
|
-
fnContext: (host, token, collection) => {
|
|
225
|
-
return {
|
|
226
|
-
dataKey: JSON.stringify({ host, token, collection }),
|
|
227
|
-
fetcher: () => __async(void 0, null, function* () {
|
|
228
|
-
if (!host) {
|
|
229
|
-
return {};
|
|
230
|
-
}
|
|
231
|
-
const data = yield queryStrapi(host, token, collection);
|
|
232
|
-
if (!(0, import_dlv.default)(data.data, ["data"])) {
|
|
233
|
-
return { strapiFields: [] };
|
|
234
|
-
}
|
|
235
|
-
const collectionData = (0, import_dlv.default)(data.data, ["data"]);
|
|
236
|
-
const filteredFields = filterFields(collectionData);
|
|
237
|
-
return { strapiFields: uniq(filteredFields != null ? filteredFields : []) };
|
|
238
|
-
})
|
|
239
|
-
};
|
|
240
|
-
}
|
|
241
|
-
};
|
|
242
|
-
function queryStrapi(host, token, collection, filterField, filterValue, filterParameter) {
|
|
243
|
-
return __async(this, null, function* () {
|
|
244
|
-
if (!host) {
|
|
245
|
-
return null;
|
|
246
|
-
}
|
|
247
|
-
collection = collection != null ? collection : "";
|
|
248
|
-
const query = host.trim() + "/api/" + collection.trim();
|
|
249
|
-
const requestInit = { method: "GET" };
|
|
250
|
-
if (token) {
|
|
251
|
-
requestInit.headers = { Authorization: "Bearer " + token };
|
|
252
|
-
}
|
|
253
|
-
const queryParams = import_qs.default.stringify(__spreadProps(__spreadValues({}, filterField && filterParameter && filterValue ? {
|
|
254
|
-
filters: {
|
|
255
|
-
[filterField]: {
|
|
256
|
-
[filterParameter]: filterValue
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
} : {}), {
|
|
260
|
-
populate: "*"
|
|
261
|
-
}));
|
|
262
|
-
const resp = yield fetch(`${query}?${queryParams}`, requestInit);
|
|
263
|
-
return resp.json();
|
|
264
|
-
});
|
|
265
|
-
}
|
|
266
|
-
function registerAllCustomFunctions(loader) {
|
|
267
|
-
function _registerFunction(fn, meta) {
|
|
268
|
-
if (loader) {
|
|
269
|
-
loader.registerFunction(fn, meta);
|
|
270
|
-
} else {
|
|
271
|
-
(0, import_registerFunction.default)(fn, meta);
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
_registerFunction(queryStrapi, queryStrapiMeta);
|
|
275
|
-
}
|
|
276
78
|
|
|
277
79
|
// src/StrapiCredentialsProvider.tsx
|
|
278
|
-
var import_react = __toESM(require("react"));
|
|
279
80
|
var StrapiCredentialsContext = import_react.default.createContext(void 0);
|
|
280
81
|
function useStrapiCredentials() {
|
|
281
82
|
const creds = (0, import_react.useContext)(StrapiCredentialsContext);
|
|
@@ -367,7 +168,7 @@ var strapiCollectionMeta = {
|
|
|
367
168
|
displayName: "Filter Parameter",
|
|
368
169
|
description: "Field Parameter filter by",
|
|
369
170
|
options: () => {
|
|
370
|
-
return
|
|
171
|
+
return import_strapi._queryParameters.map((item) => ({
|
|
371
172
|
label: item == null ? void 0 : item.label,
|
|
372
173
|
value: item == null ? void 0 : item.value
|
|
373
174
|
}));
|
|
@@ -411,10 +212,14 @@ function StrapiCollection({
|
|
|
411
212
|
noAutoRepeat,
|
|
412
213
|
setControlContextData
|
|
413
214
|
}) {
|
|
215
|
+
var _a;
|
|
414
216
|
const { host, token } = useStrapiCredentials();
|
|
415
217
|
if (!host) {
|
|
416
218
|
return /* @__PURE__ */ import_react2.default.createElement("div", null, "Please specify a host.");
|
|
417
219
|
}
|
|
220
|
+
if (!name) {
|
|
221
|
+
return /* @__PURE__ */ import_react2.default.createElement("div", null, "Please specify a collection.");
|
|
222
|
+
}
|
|
418
223
|
const cacheKey = JSON.stringify({
|
|
419
224
|
host,
|
|
420
225
|
token,
|
|
@@ -423,22 +228,21 @@ function StrapiCollection({
|
|
|
423
228
|
filterValue,
|
|
424
229
|
filterParameter
|
|
425
230
|
});
|
|
426
|
-
const
|
|
231
|
+
const resp = (0, import_query.usePlasmicQueryData)(
|
|
427
232
|
cacheKey,
|
|
428
233
|
() => __async(this, null, function* () {
|
|
429
|
-
return queryStrapi(host, token, name, filterField, filterValue, filterParameter);
|
|
234
|
+
return (0, import_strapi.queryStrapi)(host, token, name, filterField, filterValue, filterParameter);
|
|
430
235
|
})
|
|
431
236
|
);
|
|
432
|
-
if (!(
|
|
237
|
+
if (!(resp == null ? void 0 : resp.data)) {
|
|
433
238
|
return /* @__PURE__ */ import_react2.default.createElement("div", null, "Please configure the Strapi provider with a valid host and token.");
|
|
434
239
|
}
|
|
435
|
-
if (!(
|
|
240
|
+
if (!((_a = resp.data) == null ? void 0 : _a.data)) {
|
|
436
241
|
return /* @__PURE__ */ import_react2.default.createElement("div", null, "Please specify a valid collection.");
|
|
437
242
|
}
|
|
438
|
-
const collectionData =
|
|
439
|
-
const filteredFields = filterFields(collectionData);
|
|
243
|
+
const collectionData = resp.data.data;
|
|
440
244
|
setControlContextData == null ? void 0 : setControlContextData({
|
|
441
|
-
strapiFields:
|
|
245
|
+
strapiFields: (0, import_strapi._extractFilterableFields)(collectionData != null ? collectionData : [])
|
|
442
246
|
});
|
|
443
247
|
if (filterParameter && !filterValue && !filterField) {
|
|
444
248
|
return /* @__PURE__ */ import_react2.default.createElement("div", null, "Please specify a Filter Field and a Filter Value");
|
|
@@ -462,25 +266,22 @@ function StrapiCollection({
|
|
|
462
266
|
if (collection.length === 0) {
|
|
463
267
|
return /* @__PURE__ */ import_react2.default.createElement("div", null, "No collection found ");
|
|
464
268
|
}
|
|
465
|
-
const repElements = noAutoRepeat ? children : collection.map((item, index) =>
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
/* @__PURE__ */ import_react2.default.createElement(import_host.DataProvider, { name: makeDataProviderName(name), data: item }, (0, import_host.repeatedElement)(index, children))
|
|
476
|
-
);
|
|
477
|
-
});
|
|
269
|
+
const repElements = noAutoRepeat ? children : collection.map((item, index) => /* @__PURE__ */ import_react2.default.createElement(
|
|
270
|
+
import_host.DataProvider,
|
|
271
|
+
{
|
|
272
|
+
key: (0, import_strapi._getId)(item),
|
|
273
|
+
name: "strapiItem",
|
|
274
|
+
data: item,
|
|
275
|
+
hidden: true
|
|
276
|
+
},
|
|
277
|
+
/* @__PURE__ */ import_react2.default.createElement(import_host.DataProvider, { name: makeDataProviderName(name), data: item }, (0, import_host.repeatedElement)(index, children))
|
|
278
|
+
));
|
|
478
279
|
return /* @__PURE__ */ import_react2.default.createElement(import_host.DataProvider, { name: "strapiItems", data: collection }, noLayout ? /* @__PURE__ */ import_react2.default.createElement(import_react2.default.Fragment, null, " ", repElements, " ") : /* @__PURE__ */ import_react2.default.createElement("div", { className }, " ", repElements, " "));
|
|
479
280
|
}
|
|
480
281
|
|
|
481
282
|
// src/StrapiField.tsx
|
|
482
283
|
var import_host2 = require("@plasmicapp/host");
|
|
483
|
-
var
|
|
284
|
+
var import_strapi2 = require("@plasmicpkgs/strapi");
|
|
484
285
|
var import_react3 = __toESM(require("react"));
|
|
485
286
|
var strapiFieldMeta = {
|
|
486
287
|
name: "StrapiField",
|
|
@@ -504,18 +305,11 @@ function StrapiField({
|
|
|
504
305
|
path,
|
|
505
306
|
setControlContextData
|
|
506
307
|
}) {
|
|
507
|
-
var _a;
|
|
508
308
|
const item = (0, import_host2.useSelector)("strapiItem");
|
|
509
309
|
if (!item) {
|
|
510
310
|
return /* @__PURE__ */ import_react3.default.createElement("div", null, "StrapiField must be used within a StrapiCollection");
|
|
511
311
|
}
|
|
512
|
-
const
|
|
513
|
-
const displayableFields = Object.keys(attributes).filter((field) => {
|
|
514
|
-
var _a2;
|
|
515
|
-
const value = attributes[field];
|
|
516
|
-
const maybeMime2 = (_a2 = getAttributes(value == null ? void 0 : value.data)) == null ? void 0 : _a2.mime;
|
|
517
|
-
return typeof value !== "object" || typeof maybeMime2 === "string" && maybeMime2.startsWith("image");
|
|
518
|
-
});
|
|
312
|
+
const displayableFields = (0, import_strapi2._extractDisplayableFields)(item);
|
|
519
313
|
setControlContextData == null ? void 0 : setControlContextData({
|
|
520
314
|
fields: displayableFields,
|
|
521
315
|
isImage: false
|
|
@@ -523,31 +317,31 @@ function StrapiField({
|
|
|
523
317
|
if (!path) {
|
|
524
318
|
return /* @__PURE__ */ import_react3.default.createElement("div", null, "StrapiField must specify a field name.");
|
|
525
319
|
}
|
|
526
|
-
const data = (0,
|
|
527
|
-
const
|
|
320
|
+
const data = (0, import_strapi2._getFieldValue)(item, path);
|
|
321
|
+
const mediaAttributes = (0, import_strapi2._isStrapiItem)(data) ? (0, import_strapi2._getMediaAttributes)(data) : null;
|
|
528
322
|
setControlContextData == null ? void 0 : setControlContextData({
|
|
529
323
|
fields: displayableFields,
|
|
530
|
-
isImage:
|
|
324
|
+
isImage: mediaAttributes ? (0, import_strapi2._isImage)(mediaAttributes) : false
|
|
531
325
|
});
|
|
532
|
-
if (
|
|
326
|
+
if (data === void 0) {
|
|
533
327
|
return /* @__PURE__ */ import_react3.default.createElement("div", null, "Please specify a valid field name.");
|
|
534
|
-
} else if (
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
const img_url = attrs.url.startsWith("http") ? attrs.url : creds.host + attrs.url;
|
|
538
|
-
const img_width = attrs.width;
|
|
539
|
-
const img_height = attrs.height;
|
|
328
|
+
} else if (data === null) {
|
|
329
|
+
return /* @__PURE__ */ import_react3.default.createElement("div", { className });
|
|
330
|
+
} else if (mediaAttributes && (0, import_strapi2._isImage)(mediaAttributes)) {
|
|
540
331
|
return /* @__PURE__ */ import_react3.default.createElement(
|
|
541
332
|
"img",
|
|
542
333
|
{
|
|
543
334
|
className,
|
|
544
|
-
src:
|
|
335
|
+
src: mediaAttributes.absoluteUrl,
|
|
545
336
|
width: 300,
|
|
546
|
-
height: 300 *
|
|
337
|
+
height: 300 * mediaAttributes.height / mediaAttributes.width
|
|
547
338
|
}
|
|
548
339
|
);
|
|
549
|
-
} else {
|
|
340
|
+
} else if ((0, import_strapi2._isStrapiPrimitive)(data)) {
|
|
550
341
|
return /* @__PURE__ */ import_react3.default.createElement("div", { className }, data);
|
|
342
|
+
} else {
|
|
343
|
+
console.warn("Complex field value:", data);
|
|
344
|
+
return /* @__PURE__ */ import_react3.default.createElement("div", null, "Complex field value could not be displayed. See console for details.");
|
|
551
345
|
}
|
|
552
346
|
}
|
|
553
347
|
|
package/dist/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../src/index.tsx", "../src/StrapiCollection.tsx", "../src/
|
|
4
|
-
"sourcesContent": ["import registerComponent, {\n ComponentMeta,\n} from \"@plasmicapp/host/registerComponent\";\nimport registerGlobalContext from \"@plasmicapp/host/registerGlobalContext\";\nimport { StrapiCollection, strapiCollectionMeta } from \"./StrapiCollection\";\nimport {\n StrapiCredentialsProvider,\n strapiCredentialsProviderMeta,\n} from \"./StrapiCredentialsProvider\";\nimport { StrapiField, strapiFieldMeta } from \"./StrapiField\";\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 StrapiCredentialsProvider,\n strapiCredentialsProviderMeta\n );\n } else {\n registerGlobalContext(\n StrapiCredentialsProvider,\n strapiCredentialsProviderMeta\n );\n }\n\n _registerComponent(StrapiCollection, strapiCollectionMeta);\n _registerComponent(StrapiField, strapiFieldMeta);\n}\n\nexport * from \"./custom-functions\";\nexport { StrapiCollection, strapiCollectionMeta } from \"./StrapiCollection\";\nexport {\n StrapiCredentialsProvider,\n strapiCredentialsProviderMeta,\n} from \"./StrapiCredentialsProvider\";\nexport { StrapiField, strapiFieldMeta } from \"./StrapiField\";\n", "import { ComponentMeta, DataProvider, repeatedElement } from \"@plasmicapp/host\";\nimport { usePlasmicQueryData } from \"@plasmicapp/query\";\nimport { pascalCase } from \"change-case\";\nimport get from \"dlv\";\nimport React, { ReactNode } from \"react\";\nimport { queryStrapi } from \"./custom-functions\";\nimport { useStrapiCredentials } from \"./StrapiCredentialsProvider\";\nimport { filterFields, modulePath, queryParameters, uniq } from \"./utils\";\n\nconst makeDataProviderName = (collection: string) =>\n `currentStrapi${pascalCase(collection)}Item`;\n\ninterface StrapiCollectionProps {\n name?: string;\n children?: ReactNode;\n className?: string;\n noLayout?: boolean;\n noAutoRepeat?: boolean;\n filterField?: string;\n filterValue?: string;\n limit?: number;\n filterParameter?: string;\n setControlContextData?: (data: { strapiFields: string[] }) => void;\n}\n\nexport const strapiCollectionMeta: ComponentMeta<StrapiCollectionProps> = {\n name: \"StrapiCollection\",\n displayName: \"Strapi Collection\",\n importName: \"StrapiCollection\",\n importPath: modulePath,\n providesData: true,\n description:\n \"Fetches Strapi data of a given collection, and repeats `children` slot content for each row fetched. [See tutorial video](https://www.youtube.com/watch?v=1SLoVY3hkQ4).\",\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 children: {\n type: \"component\",\n name: \"StrapiField\",\n },\n },\n },\n name: {\n type: \"string\",\n displayName: \"Name\",\n description: \"Name of the collection to be fetched.\",\n defaultValueHint: \"restaurants\",\n },\n filterField: {\n type: \"choice\",\n displayName: \"Filter field\",\n description: \"Field (from Collection) to filter by\",\n options: (_, ctx) => ctx?.strapiFields ?? [],\n hidden: (props) => !props.name,\n },\n filterParameter: {\n type: \"choice\",\n displayName: \"Filter Parameter\",\n description: \"Field Parameter filter by\",\n options: () => {\n return queryParameters.map((item: any) => ({\n label: item?.label,\n value: item?.value,\n }));\n },\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.filterParameter,\n },\n limit: {\n type: \"number\",\n displayName: \"Limit\",\n description: \"Maximum number of collections to fetch (0 for unlimited).\",\n },\n noLayout: {\n type: \"boolean\",\n displayName: \"No layout\",\n description:\n \"When set, Strapi Collection 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 noAutoRepeat: {\n type: \"boolean\",\n displayName: \"No auto-repeat\",\n description: \"Do not automatically repeat children for every category.\",\n defaultValue: false,\n },\n },\n};\n\nexport function StrapiCollection({\n name,\n filterParameter,\n filterValue,\n filterField,\n limit,\n children,\n className,\n noLayout,\n noAutoRepeat,\n setControlContextData,\n}: StrapiCollectionProps) {\n const { host, token } = useStrapiCredentials();\n\n if (!host) {\n return <div>Please specify a host.</div>;\n }\n\n const cacheKey = JSON.stringify({\n host,\n token,\n name,\n filterField,\n filterValue,\n filterParameter,\n });\n\n const data = usePlasmicQueryData<any[] | null>(cacheKey, async () =>\n queryStrapi(host, token, name, filterField, filterValue, filterParameter)\n );\n\n if (!data?.data) {\n return (\n <div>\n Please configure the Strapi provider with a valid host and token.\n </div>\n );\n }\n\n if (!get(data.data, [\"data\"])) {\n return <div>Please specify a valid collection.</div>;\n }\n\n const collectionData = get(data.data, [\"data\"]) as any[];\n\n const filteredFields = filterFields(collectionData);\n\n setControlContextData?.({\n strapiFields: uniq(filteredFields ?? []),\n });\n if (filterParameter && !filterValue && !filterField) {\n return <div>Please specify a Filter Field and a Filter Value</div>;\n }\n if (!filterParameter && filterValue && !filterField) {\n return <div>Please specify a Filter Parameter and a Filter Field</div>;\n }\n if (!filterParameter && !filterValue && filterField) {\n return <div>Please specify a Filter Parameter and a Filter Value</div>;\n }\n\n if (filterParameter && filterValue && !filterField) {\n return <div>Please specify a Filter Field</div>;\n }\n if (!filterParameter && filterValue && filterField) {\n return <div>Please specify a Filter Parameter</div>;\n }\n if (filterParameter && !filterValue && filterField) {\n return <div>Please specify a Filter Value</div>;\n }\n\n const collection =\n limit! > 0 ? collectionData.slice(0, limit) : collectionData;\n\n if (collection.length === 0) {\n return <div>No collection found </div>;\n }\n\n const repElements = noAutoRepeat\n ? children\n : collection.map((item, index) => (\n <DataProvider\n key={item.documentId ?? item.id}\n name={\"strapiItem\"}\n data={item}\n hidden={true}\n >\n <DataProvider name={makeDataProviderName(name!)} data={item}>\n {repeatedElement(index, children)}\n </DataProvider>\n </DataProvider>\n ));\n\n return (\n <DataProvider name=\"strapiItems\" data={collection}>\n {noLayout ? (\n <> {repElements} </>\n ) : (\n <div className={className}> {repElements} </div>\n )}\n </DataProvider>\n );\n}\n", "import registerFunction, {\n CustomFunctionMeta,\n} from \"@plasmicapp/host/registerFunction\";\nimport get from \"dlv\";\nimport qs from \"qs\";\nimport { filterFields, modulePath, queryParameters, uniq } from \"./utils\";\n\nexport const queryStrapiMeta: CustomFunctionMeta<typeof queryStrapi> = {\n name: \"queryStrapi\",\n displayName: \"Query Strapi\",\n description: \"Query a Strapi collection\",\n importPath: modulePath,\n params: [\n {\n name: \"strapiHost\",\n type: \"string\",\n description: \"The Strapi host URL (e.g., https://example.com)\",\n },\n {\n name: \"strapiToken\",\n type: \"string\",\n description:\n \"The Strapi API token (optional, for authenticated requests)\",\n },\n {\n name: \"collection\",\n type: \"string\",\n description: \"The name of the Strapi collection to query\",\n },\n {\n name: \"filterField\",\n type: \"choice\",\n options: (_, ctx) => {\n return ctx?.strapiFields;\n },\n },\n {\n name: \"filterValue\",\n type: \"string\",\n description:\n \"The value to filter by (optional, if you want to filter results)\",\n },\n {\n name: \"filterParameter\",\n type: \"choice\",\n description:\n \"The parameter for filtering (e.g., 'eq', 'contains', etc.) (optional)\",\n options: () => {\n return queryParameters.map((item: any) => ({\n label: item?.label,\n value: item?.value,\n }));\n },\n },\n ],\n fnContext: (host, token, collection) => {\n return {\n dataKey: JSON.stringify({ host, token, collection }),\n fetcher: async () => {\n if (!host) {\n return {};\n }\n const data = await queryStrapi(host, token, collection);\n if (!get(data.data, [\"data\"])) {\n return { strapiFields: [] };\n }\n\n const collectionData = get(data.data, [\"data\"]) as any[];\n\n const filteredFields = filterFields(collectionData);\n return { strapiFields: uniq(filteredFields ?? []) };\n },\n };\n },\n};\n\nexport async function queryStrapi(\n host: string,\n token: string | undefined,\n collection: string | undefined,\n filterField?: string,\n filterValue?: string,\n filterParameter?: string\n) {\n if (!host) {\n return null;\n }\n\n collection = collection ?? \"\";\n\n const query = host.trim() + \"/api/\" + collection.trim();\n\n const requestInit: any = { method: \"GET\" };\n if (token) {\n requestInit.headers = { Authorization: \"Bearer \" + token };\n }\n\n const queryParams = qs.stringify({\n ...(filterField && filterParameter && filterValue\n ? {\n filters: {\n [filterField]: {\n [filterParameter]: filterValue,\n },\n },\n }\n : {}),\n populate: \"*\",\n });\n\n const resp = await fetch(`${query}?${queryParams}`, requestInit);\n return resp.json();\n}\n\nexport function registerAllCustomFunctions(loader?: { registerFunction: any }) {\n function _registerFunction<T extends (...args: any[]) => any>(\n fn: T,\n meta: CustomFunctionMeta<T>\n ) {\n if (loader) {\n loader.registerFunction(fn, meta);\n } else {\n registerFunction(fn, meta);\n }\n }\n\n _registerFunction(queryStrapi, queryStrapiMeta);\n}\n", "export const modulePath = \"@plasmicpkgs/plasmic-strapi\";\n\nexport const queryParameters = [\n {\n value: \"$eq\",\n label: \"Equal\",\n },\n {\n value: \"$ne\",\n label: \"Not equal\",\n },\n {\n value: \"$lt\",\n label: \"Less than\",\n },\n {\n value: \"$lte\",\n label: \"Less than or equal to\",\n },\n {\n value: \"$gt\",\n label: \"Greater than\",\n },\n {\n value: \"$gte\",\n label: \"Greater than or equal to\",\n },\n {\n value: \"$in\",\n label: \"Included in an array\",\n },\n {\n value: \"$notIn\",\n label: \"Not included in an array\",\n },\n {\n value: \"$contains\",\n label: \"Contains\",\n },\n {\n value: \"$notContains\",\n label: \"Does not contain\",\n },\n];\n\nexport const uniq = <T>(xs: Array<T>): T[] => Array.from(new Set(xs));\n\nexport const getAttributes = (item?: Record<string, any>) => {\n if (!item) {\n return undefined;\n }\n // Strapi v4\n if (item.attributes) {\n return item.attributes;\n }\n // Strapi v5\n const { documentId: _documentId, locale: _locale, ...rest } = item;\n return rest;\n};\n\nexport function filterFields(collectionData: any[]) {\n return collectionData.flatMap((item: any) => {\n const attributes = getAttributes(item);\n const displayableFields = Object.keys(attributes).filter((field) => {\n const value = attributes[field];\n const maybeMime = getAttributes(value?.data)?.mime;\n return (\n typeof value !== \"object\" ||\n (typeof maybeMime === \"string\" && maybeMime.startsWith(\"image\"))\n );\n });\n return displayableFields;\n });\n}\n", "import { GlobalContextMeta } from \"@plasmicapp/host\";\nimport React, { useContext } from \"react\";\nimport { modulePath } from \"./utils\";\n\ninterface StrapiCredentials {\n host?: string;\n token?: string;\n}\n\nconst StrapiCredentialsContext = React.createContext<\n StrapiCredentials | undefined\n>(undefined);\n\nexport function useStrapiCredentials() {\n const creds = useContext(StrapiCredentialsContext);\n if (!creds) {\n throw new Error(\"Missing StrapiCredentials\");\n }\n\n return creds;\n}\n\nexport const strapiCredentialsProviderMeta: GlobalContextMeta<StrapiCredentials> =\n {\n name: \"StrapiCredentialsProvider\",\n displayName: \"Strapi Credentials Provider\",\n description: `[See tutorial video](https://www.youtube.com/watch?v=1SLoVY3hkQ4).\n\nAPI token is needed only if data is not publicly readable.\n\nLearn how to [get your API token](https://docs.strapi.io/user-docs/latest/settings/managing-global-settings.html#managing-api-tokens).`,\n importName: \"StrapiCredentialsProvider\",\n importPath: modulePath,\n props: {\n host: {\n type: \"string\",\n displayName: \"Host\",\n defaultValueHint: \"https://your_project_id.strapiapp.com/\",\n defaultValue: \"https://graceful-belief-d395c347a3.strapiapp.com/\",\n description: \"Server where you application is hosted.\",\n },\n token: {\n type: \"string\",\n displayName: \"API Token\",\n description:\n \"API Token (generated in http://yourhost/admin/settings/api-tokens) (or leave blank for unauthenticated usage).\",\n },\n },\n };\n\nexport function StrapiCredentialsProvider({\n host,\n token,\n children,\n}: React.PropsWithChildren<StrapiCredentials>) {\n host = host?.replace(/\\/+$/, \"\");\n return (\n <StrapiCredentialsContext.Provider value={{ host, token }}>\n {children}\n </StrapiCredentialsContext.Provider>\n );\n}\n", "import { ComponentMeta, useSelector } from \"@plasmicapp/host\";\nimport get from \"dlv\";\nimport React from \"react\";\nimport { useStrapiCredentials } from \"./StrapiCredentialsProvider\";\nimport { getAttributes, modulePath } from \"./utils\";\n\ninterface StrapiFieldProps {\n className?: string;\n path?: string;\n setControlContextData?: (data: {\n fields: string[];\n isImage: boolean;\n }) => void;\n}\n\nexport const strapiFieldMeta: ComponentMeta<StrapiFieldProps> = {\n name: \"StrapiField\",\n displayName: \"Strapi Field\",\n importName: \"StrapiField\",\n importPath: modulePath,\n props: {\n path: {\n type: \"choice\",\n options: (_, ctx) => {\n return ctx?.fields ?? [];\n },\n displayName: \"Field\",\n description: \"Field name\",\n },\n },\n};\n\nexport function StrapiField({\n className,\n path,\n setControlContextData,\n}: StrapiFieldProps) {\n const item = useSelector(\"strapiItem\");\n if (!item) {\n return <div>StrapiField must be used within a StrapiCollection</div>;\n }\n\n // Getting only fields that aren't objects\n const attributes = getAttributes(item);\n const displayableFields = Object.keys(attributes).filter((field) => {\n const value = attributes[field];\n const maybeMime = getAttributes(value?.data)?.mime;\n return (\n typeof value !== \"object\" ||\n (typeof maybeMime === \"string\" && maybeMime.startsWith(\"image\"))\n );\n });\n\n setControlContextData?.({\n fields: displayableFields,\n isImage: false,\n });\n\n if (!path) {\n return <div>StrapiField must specify a field name.</div>;\n }\n\n const data = get(attributes, [path]);\n const maybeMime = getAttributes(data?.data)?.mime;\n\n setControlContextData?.({\n fields: displayableFields,\n isImage: typeof maybeMime === \"string\" && maybeMime.startsWith(\"image\"),\n });\n\n if (!data) {\n return <div>Please specify a valid field name.</div>;\n } else if (typeof maybeMime === \"string\" && maybeMime.startsWith(\"image\")) {\n const creds = useStrapiCredentials();\n const attrs = getAttributes(data.data);\n const img_url = attrs.url.startsWith(\"http\")\n ? attrs.url\n : creds.host + attrs.url;\n const img_width = attrs.width;\n const img_height = attrs.height;\n return (\n <img\n className={className}\n src={img_url}\n width={300}\n height={(300 * img_height) / img_width}\n />\n );\n } else {\n return <div className={className}>{data}</div>;\n }\n}\n"],
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": ["
|
|
3
|
+
"sources": ["../src/index.tsx", "../src/StrapiCollection.tsx", "../src/StrapiCredentialsProvider.tsx", "../src/utils.ts", "../src/StrapiField.tsx"],
|
|
4
|
+
"sourcesContent": ["import registerComponent, {\n ComponentMeta,\n} from \"@plasmicapp/host/registerComponent\";\nimport registerGlobalContext from \"@plasmicapp/host/registerGlobalContext\";\nimport { StrapiCollection, strapiCollectionMeta } from \"./StrapiCollection\";\nimport {\n StrapiCredentialsProvider,\n strapiCredentialsProviderMeta,\n} from \"./StrapiCredentialsProvider\";\nimport { StrapiField, strapiFieldMeta } from \"./StrapiField\";\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 StrapiCredentialsProvider,\n strapiCredentialsProviderMeta\n );\n } else {\n registerGlobalContext(\n StrapiCredentialsProvider,\n strapiCredentialsProviderMeta\n );\n }\n\n _registerComponent(StrapiCollection, strapiCollectionMeta);\n _registerComponent(StrapiField, strapiFieldMeta);\n}\n\nexport { StrapiCollection, strapiCollectionMeta } from \"./StrapiCollection\";\nexport {\n StrapiCredentialsProvider,\n strapiCredentialsProviderMeta,\n} from \"./StrapiCredentialsProvider\";\nexport { StrapiField, strapiFieldMeta } from \"./StrapiField\";\n", "import { ComponentMeta, DataProvider, repeatedElement } from \"@plasmicapp/host\";\nimport { usePlasmicQueryData } from \"@plasmicapp/query\";\nimport {\n _extractFilterableFields,\n _getId,\n _queryParameters,\n queryStrapi,\n} from \"@plasmicpkgs/strapi\";\nimport { pascalCase } from \"change-case\";\nimport React, { ReactNode } from \"react\";\nimport { useStrapiCredentials } from \"./StrapiCredentialsProvider\";\nimport { modulePath } from \"./utils\";\n\nconst makeDataProviderName = (collection: string) =>\n `currentStrapi${pascalCase(collection)}Item`;\n\ninterface StrapiCollectionProps {\n name?: string;\n children?: ReactNode;\n className?: string;\n noLayout?: boolean;\n noAutoRepeat?: boolean;\n filterField?: string;\n filterValue?: string;\n limit?: number;\n filterParameter?: string;\n setControlContextData?: (data: { strapiFields: string[] }) => void;\n}\n\nexport const strapiCollectionMeta: ComponentMeta<StrapiCollectionProps> = {\n name: \"StrapiCollection\",\n displayName: \"Strapi Collection\",\n importName: \"StrapiCollection\",\n importPath: modulePath,\n providesData: true,\n description:\n \"Fetches Strapi data of a given collection, and repeats `children` slot content for each row fetched. [See tutorial video](https://www.youtube.com/watch?v=1SLoVY3hkQ4).\",\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 children: {\n type: \"component\",\n name: \"StrapiField\",\n },\n },\n },\n name: {\n type: \"string\",\n displayName: \"Name\",\n description: \"Name of the collection to be fetched.\",\n defaultValueHint: \"restaurants\",\n },\n filterField: {\n type: \"choice\",\n displayName: \"Filter field\",\n description: \"Field (from Collection) to filter by\",\n options: (_, ctx) => ctx?.strapiFields ?? [],\n hidden: (props) => !props.name,\n },\n filterParameter: {\n type: \"choice\",\n displayName: \"Filter Parameter\",\n description: \"Field Parameter filter by\",\n options: () => {\n return _queryParameters.map((item: any) => ({\n label: item?.label,\n value: item?.value,\n }));\n },\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.filterParameter,\n },\n limit: {\n type: \"number\",\n displayName: \"Limit\",\n description: \"Maximum number of collections to fetch (0 for unlimited).\",\n },\n noLayout: {\n type: \"boolean\",\n displayName: \"No layout\",\n description:\n \"When set, Strapi Collection 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 noAutoRepeat: {\n type: \"boolean\",\n displayName: \"No auto-repeat\",\n description: \"Do not automatically repeat children for every category.\",\n defaultValue: false,\n },\n },\n};\n\nexport function StrapiCollection({\n name,\n filterParameter,\n filterValue,\n filterField,\n limit,\n children,\n className,\n noLayout,\n noAutoRepeat,\n setControlContextData,\n}: StrapiCollectionProps) {\n const { host, token } = useStrapiCredentials();\n\n if (!host) {\n return <div>Please specify a host.</div>;\n }\n\n if (!name) {\n return <div>Please specify a collection.</div>;\n }\n\n const cacheKey = JSON.stringify({\n host,\n token,\n name,\n filterField,\n filterValue,\n filterParameter,\n });\n\n const resp = usePlasmicQueryData(cacheKey, async () =>\n queryStrapi(host, token, name, filterField, filterValue, filterParameter)\n );\n\n if (!resp?.data) {\n return (\n <div>\n Please configure the Strapi provider with a valid host and token.\n </div>\n );\n }\n\n if (!resp.data?.data) {\n return <div>Please specify a valid collection.</div>;\n }\n\n const collectionData = resp.data.data;\n\n setControlContextData?.({\n strapiFields: _extractFilterableFields(collectionData ?? []),\n });\n if (filterParameter && !filterValue && !filterField) {\n return <div>Please specify a Filter Field and a Filter Value</div>;\n }\n if (!filterParameter && filterValue && !filterField) {\n return <div>Please specify a Filter Parameter and a Filter Field</div>;\n }\n if (!filterParameter && !filterValue && filterField) {\n return <div>Please specify a Filter Parameter and a Filter Value</div>;\n }\n\n if (filterParameter && filterValue && !filterField) {\n return <div>Please specify a Filter Field</div>;\n }\n if (!filterParameter && filterValue && filterField) {\n return <div>Please specify a Filter Parameter</div>;\n }\n if (filterParameter && !filterValue && filterField) {\n return <div>Please specify a Filter Value</div>;\n }\n\n const collection =\n limit! > 0 ? collectionData.slice(0, limit) : collectionData;\n\n if (collection.length === 0) {\n return <div>No collection found </div>;\n }\n\n const repElements = noAutoRepeat\n ? children\n : collection.map((item, index) => (\n <DataProvider\n key={_getId(item)}\n name={\"strapiItem\"}\n data={item}\n hidden={true}\n >\n <DataProvider name={makeDataProviderName(name!)} data={item}>\n {repeatedElement(index, children)}\n </DataProvider>\n </DataProvider>\n ));\n\n return (\n <DataProvider name=\"strapiItems\" data={collection}>\n {noLayout ? (\n <> {repElements} </>\n ) : (\n <div className={className}> {repElements} </div>\n )}\n </DataProvider>\n );\n}\n", "import { GlobalContextMeta } from \"@plasmicapp/host\";\nimport React, { useContext } from \"react\";\nimport { modulePath } from \"./utils\";\n\ninterface StrapiCredentials {\n host?: string;\n token?: string;\n}\n\nconst StrapiCredentialsContext = React.createContext<\n StrapiCredentials | undefined\n>(undefined);\n\nexport function useStrapiCredentials() {\n const creds = useContext(StrapiCredentialsContext);\n if (!creds) {\n throw new Error(\"Missing StrapiCredentials\");\n }\n\n return creds;\n}\n\nexport const strapiCredentialsProviderMeta: GlobalContextMeta<StrapiCredentials> =\n {\n name: \"StrapiCredentialsProvider\",\n displayName: \"Strapi Credentials Provider\",\n description: `[See tutorial video](https://www.youtube.com/watch?v=1SLoVY3hkQ4).\n\nAPI token is needed only if data is not publicly readable.\n\nLearn how to [get your API token](https://docs.strapi.io/user-docs/latest/settings/managing-global-settings.html#managing-api-tokens).`,\n importName: \"StrapiCredentialsProvider\",\n importPath: modulePath,\n props: {\n host: {\n type: \"string\",\n displayName: \"Host\",\n defaultValueHint: \"https://your_project_id.strapiapp.com/\",\n defaultValue: \"https://graceful-belief-d395c347a3.strapiapp.com/\",\n description: \"Server where you application is hosted.\",\n },\n token: {\n type: \"string\",\n displayName: \"API Token\",\n description:\n \"API Token (generated in http://yourhost/admin/settings/api-tokens) (or leave blank for unauthenticated usage).\",\n },\n },\n };\n\nexport function StrapiCredentialsProvider({\n host,\n token,\n children,\n}: React.PropsWithChildren<StrapiCredentials>) {\n host = host?.replace(/\\/+$/, \"\");\n return (\n <StrapiCredentialsContext.Provider value={{ host, token }}>\n {children}\n </StrapiCredentialsContext.Provider>\n );\n}\n", "export const modulePath = \"@plasmicpkgs/plasmic-strapi\";\n", "import { ComponentMeta, useSelector } from \"@plasmicapp/host\";\nimport {\n _extractDisplayableFields,\n _getFieldValue,\n _getMediaAttributes,\n _isImage,\n _isStrapiItem,\n _isStrapiPrimitive,\n} from \"@plasmicpkgs/strapi\";\nimport React from \"react\";\nimport { modulePath } from \"./utils\";\n\ninterface StrapiFieldProps {\n className?: string;\n path?: string;\n setControlContextData?: (data: {\n fields: string[];\n isImage: boolean;\n }) => void;\n}\n\nexport const strapiFieldMeta: ComponentMeta<StrapiFieldProps> = {\n name: \"StrapiField\",\n displayName: \"Strapi Field\",\n importName: \"StrapiField\",\n importPath: modulePath,\n props: {\n path: {\n type: \"choice\",\n options: (_, ctx) => {\n return ctx?.fields ?? [];\n },\n displayName: \"Field\",\n description: \"Field name\",\n },\n },\n};\n\nexport function StrapiField({\n className,\n path,\n setControlContextData,\n}: StrapiFieldProps) {\n const item = useSelector(\"strapiItem\");\n if (!item) {\n return <div>StrapiField must be used within a StrapiCollection</div>;\n }\n\n // Getting only fields that aren't objects\n const displayableFields = _extractDisplayableFields(item);\n\n setControlContextData?.({\n fields: displayableFields,\n isImage: false,\n });\n\n if (!path) {\n return <div>StrapiField must specify a field name.</div>;\n }\n\n const data = _getFieldValue(item, path);\n const mediaAttributes = _isStrapiItem(data)\n ? _getMediaAttributes(data)\n : null;\n\n setControlContextData?.({\n fields: displayableFields,\n isImage: mediaAttributes ? _isImage(mediaAttributes) : false,\n });\n\n if (data === undefined) {\n return <div>Please specify a valid field name.</div>;\n } else if (data === null) {\n return <div className={className}></div>;\n } else if (mediaAttributes && _isImage(mediaAttributes)) {\n // URL is already absolute after transformMediaUrls in queryStrapi\n return (\n <img\n className={className}\n src={mediaAttributes.absoluteUrl}\n width={300}\n height={(300 * mediaAttributes.height) / mediaAttributes.width}\n />\n );\n } else if (_isStrapiPrimitive(data)) {\n return <div className={className}>{data}</div>;\n } else {\n console.warn(\"Complex field value:\", data);\n return (\n <div>\n Complex field value could not be displayed. See console for details.\n </div>\n );\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,+BAEO;AACP,mCAAkC;;;ACHlC,kBAA6D;AAC7D,mBAAoC;AACpC,oBAKO;AACP,yBAA2B;AAC3B,IAAAA,gBAAiC;;;ACRjC,mBAAkC;;;ACD3B,IAAM,aAAa;;;ADS1B,IAAM,2BAA2B,aAAAC,QAAM,cAErC,MAAS;AAEJ,SAAS,uBAAuB;AACrC,QAAM,YAAQ,yBAAW,wBAAwB;AACjD,MAAI,CAAC,OAAO;AACV,UAAM,IAAI,MAAM,2BAA2B;AAAA,EAC7C;AAEA,SAAO;AACT;AAEO,IAAM,gCACX;AAAA,EACE,MAAM;AAAA,EACN,aAAa;AAAA,EACb,aAAa;AAAA;AAAA;AAAA;AAAA;AAAA,EAKb,YAAY;AAAA,EACZ,YAAY;AAAA,EACZ,OAAO;AAAA,IACL,MAAM;AAAA,MACJ,MAAM;AAAA,MACN,aAAa;AAAA,MACb,kBAAkB;AAAA,MAClB,cAAc;AAAA,MACd,aAAa;AAAA,IACf;AAAA,IACA,OAAO;AAAA,MACL,MAAM;AAAA,MACN,aAAa;AAAA,MACb,aACE;AAAA,IACJ;AAAA,EACF;AACF;AAEK,SAAS,0BAA0B;AAAA,EACxC;AAAA,EACA;AAAA,EACA;AACF,GAA+C;AAC7C,SAAO,6BAAM,QAAQ,QAAQ;AAC7B,SACE,6BAAAA,QAAA,cAAC,yBAAyB,UAAzB,EAAkC,OAAO,EAAE,MAAM,MAAM,KACrD,QACH;AAEJ;;;ADhDA,IAAM,uBAAuB,CAAC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I,aAAuB,IAAK;AAAA,EAC1C,OAAO;AACL,YAAQ,KAAK,wBAAwB,IAAI;AACzC,WACE,8BAAAA,QAAA,cAAC,aAAI,sEAEL;AAAA,EAEJ;AACF;;;AJnFO,SAAS,YAAY,QAGzB;AACD,QAAM,qBAAqB,CACzB,WACA,gBACG;AACH,QAAI,QAAQ;AACV,aAAO,kBAAkB,WAAW,WAAW;AAAA,IACjD,OAAO;AACL,mCAAAC,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;AAEA,qBAAmB,kBAAkB,oBAAoB;AACzD,qBAAmB,aAAa,eAAe;AACjD;",
|
|
6
|
+
"names": ["import_react", "React", "React", "import_host", "import_strapi", "import_react", "React", "registerComponent", "registerGlobalContext"]
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plasmicpkgs/plasmic-strapi",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.181",
|
|
4
4
|
"description": "Plasmic Strapi components.",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -41,21 +41,18 @@
|
|
|
41
41
|
}
|
|
42
42
|
],
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@
|
|
45
|
-
"change-case": "^4.1.2"
|
|
46
|
-
"dlv": "^1.1.3",
|
|
47
|
-
"qs": "^6.11.0"
|
|
44
|
+
"@plasmicpkgs/strapi": "0.0.2",
|
|
45
|
+
"change-case": "^4.1.2"
|
|
48
46
|
},
|
|
49
47
|
"devDependencies": {
|
|
50
|
-
"@plasmicapp/host": "1.0.
|
|
51
|
-
"@plasmicapp/query": "0.1.
|
|
48
|
+
"@plasmicapp/host": "1.0.227",
|
|
49
|
+
"@plasmicapp/query": "0.1.81",
|
|
52
50
|
"@types/dlv": "^1.1.2",
|
|
53
|
-
"@types/qs": "^6.9.7",
|
|
54
51
|
"@types/react": "^18.0.27",
|
|
55
52
|
"@types/react-dom": "^18.0.10",
|
|
56
53
|
"react": "^18.2.0",
|
|
57
54
|
"react-dom": "^18.2.0",
|
|
58
55
|
"typescript": "^5.2.2"
|
|
59
56
|
},
|
|
60
|
-
"gitHead": "
|
|
57
|
+
"gitHead": "30d923e96aaebe2ea8d8385fea60efee467a5c11"
|
|
61
58
|
}
|