@plasmicpkgs/plasmic-strapi 0.1.137 → 0.1.139
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +10 -9
- package/dist/index.d.ts +10 -9
- package/dist/index.js +56 -43
- package/dist/index.mjs +56 -46
- package/package.json +10 -10
package/dist/index.d.mts
CHANGED
|
@@ -1,15 +1,8 @@
|
|
|
1
1
|
import registerComponent from '@plasmicapp/host/registerComponent';
|
|
2
2
|
import registerGlobalContext from '@plasmicapp/host/registerGlobalContext';
|
|
3
|
-
import {
|
|
3
|
+
import { ComponentMeta, GlobalContextMeta } from '@plasmicapp/host';
|
|
4
4
|
import React, { ReactNode } from 'react';
|
|
5
5
|
|
|
6
|
-
declare function ensure<T>(x: T | null | undefined): T;
|
|
7
|
-
interface StrapiCredentialsProviderProps {
|
|
8
|
-
host?: string;
|
|
9
|
-
token?: string;
|
|
10
|
-
}
|
|
11
|
-
declare const strapiCredentialsProviderMeta: GlobalContextMeta<StrapiCredentialsProviderProps>;
|
|
12
|
-
declare function StrapiCredentialsProvider({ host, token, children, }: React.PropsWithChildren<StrapiCredentialsProviderProps>): React.JSX.Element;
|
|
13
6
|
interface StrapiCollectionProps {
|
|
14
7
|
name?: string;
|
|
15
8
|
children?: ReactNode;
|
|
@@ -26,6 +19,14 @@ interface StrapiCollectionProps {
|
|
|
26
19
|
}
|
|
27
20
|
declare const strapiCollectionMeta: ComponentMeta<StrapiCollectionProps>;
|
|
28
21
|
declare function StrapiCollection({ name, filterParameter, filterValue, filterField, limit, children, className, noLayout, noAutoRepeat, setControlContextData, }: StrapiCollectionProps): React.JSX.Element;
|
|
22
|
+
|
|
23
|
+
interface StrapiCredentials {
|
|
24
|
+
host?: string;
|
|
25
|
+
token?: string;
|
|
26
|
+
}
|
|
27
|
+
declare const strapiCredentialsProviderMeta: GlobalContextMeta<StrapiCredentials>;
|
|
28
|
+
declare function StrapiCredentialsProvider({ host, token, children, }: React.PropsWithChildren<StrapiCredentials>): React.JSX.Element;
|
|
29
|
+
|
|
29
30
|
interface StrapiFieldProps {
|
|
30
31
|
className?: string;
|
|
31
32
|
path?: string;
|
|
@@ -42,4 +43,4 @@ declare function registerAll(loader?: {
|
|
|
42
43
|
registerGlobalContext: typeof registerGlobalContext;
|
|
43
44
|
}): void;
|
|
44
45
|
|
|
45
|
-
export { StrapiCollection, StrapiCredentialsProvider, StrapiField,
|
|
46
|
+
export { StrapiCollection, StrapiCredentialsProvider, StrapiField, registerAll, strapiCollectionMeta, strapiCredentialsProviderMeta, strapiFieldMeta };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,15 +1,8 @@
|
|
|
1
1
|
import registerComponent from '@plasmicapp/host/registerComponent';
|
|
2
2
|
import registerGlobalContext from '@plasmicapp/host/registerGlobalContext';
|
|
3
|
-
import {
|
|
3
|
+
import { ComponentMeta, GlobalContextMeta } from '@plasmicapp/host';
|
|
4
4
|
import React, { ReactNode } from 'react';
|
|
5
5
|
|
|
6
|
-
declare function ensure<T>(x: T | null | undefined): T;
|
|
7
|
-
interface StrapiCredentialsProviderProps {
|
|
8
|
-
host?: string;
|
|
9
|
-
token?: string;
|
|
10
|
-
}
|
|
11
|
-
declare const strapiCredentialsProviderMeta: GlobalContextMeta<StrapiCredentialsProviderProps>;
|
|
12
|
-
declare function StrapiCredentialsProvider({ host, token, children, }: React.PropsWithChildren<StrapiCredentialsProviderProps>): React.JSX.Element;
|
|
13
6
|
interface StrapiCollectionProps {
|
|
14
7
|
name?: string;
|
|
15
8
|
children?: ReactNode;
|
|
@@ -26,6 +19,14 @@ interface StrapiCollectionProps {
|
|
|
26
19
|
}
|
|
27
20
|
declare const strapiCollectionMeta: ComponentMeta<StrapiCollectionProps>;
|
|
28
21
|
declare function StrapiCollection({ name, filterParameter, filterValue, filterField, limit, children, className, noLayout, noAutoRepeat, setControlContextData, }: StrapiCollectionProps): React.JSX.Element;
|
|
22
|
+
|
|
23
|
+
interface StrapiCredentials {
|
|
24
|
+
host?: string;
|
|
25
|
+
token?: string;
|
|
26
|
+
}
|
|
27
|
+
declare const strapiCredentialsProviderMeta: GlobalContextMeta<StrapiCredentials>;
|
|
28
|
+
declare function StrapiCredentialsProvider({ host, token, children, }: React.PropsWithChildren<StrapiCredentials>): React.JSX.Element;
|
|
29
|
+
|
|
29
30
|
interface StrapiFieldProps {
|
|
30
31
|
className?: string;
|
|
31
32
|
path?: string;
|
|
@@ -42,4 +43,4 @@ declare function registerAll(loader?: {
|
|
|
42
43
|
registerGlobalContext: typeof registerGlobalContext;
|
|
43
44
|
}): void;
|
|
44
45
|
|
|
45
|
-
export { StrapiCollection, StrapiCredentialsProvider, StrapiField,
|
|
46
|
+
export { StrapiCollection, StrapiCredentialsProvider, StrapiField, registerAll, strapiCollectionMeta, strapiCredentialsProviderMeta, strapiFieldMeta };
|
package/dist/index.js
CHANGED
|
@@ -33,7 +33,6 @@ __export(src_exports, {
|
|
|
33
33
|
StrapiCollection: () => StrapiCollection,
|
|
34
34
|
StrapiCredentialsProvider: () => StrapiCredentialsProvider,
|
|
35
35
|
StrapiField: () => StrapiField,
|
|
36
|
-
ensure: () => ensure,
|
|
37
36
|
registerAll: () => registerAll,
|
|
38
37
|
strapiCollectionMeta: () => strapiCollectionMeta,
|
|
39
38
|
strapiCredentialsProviderMeta: () => strapiCredentialsProviderMeta,
|
|
@@ -43,15 +42,19 @@ module.exports = __toCommonJS(src_exports);
|
|
|
43
42
|
var import_registerComponent = __toESM(require("@plasmicapp/host/registerComponent"));
|
|
44
43
|
var import_registerGlobalContext = __toESM(require("@plasmicapp/host/registerGlobalContext"));
|
|
45
44
|
|
|
46
|
-
// src/
|
|
45
|
+
// src/StrapiCollection.tsx
|
|
47
46
|
var import_host = require("@plasmicapp/host");
|
|
48
47
|
var import_query = require("@plasmicapp/query");
|
|
49
|
-
var qs = __toESM(require("qs"));
|
|
50
|
-
var import_dlv = __toESM(require("dlv"));
|
|
51
48
|
var import_change_case = require("change-case");
|
|
49
|
+
var import_dlv = __toESM(require("dlv"));
|
|
50
|
+
var qs = __toESM(require("qs"));
|
|
51
|
+
var import_react2 = __toESM(require("react"));
|
|
52
|
+
|
|
53
|
+
// src/StrapiCredentialsProvider.tsx
|
|
52
54
|
var import_react = __toESM(require("react"));
|
|
53
55
|
|
|
54
56
|
// src/utils.ts
|
|
57
|
+
var modulePath = "@plasmicpkgs/plasmic-strapi";
|
|
55
58
|
var queryParameters = [
|
|
56
59
|
{
|
|
57
60
|
value: "$eq",
|
|
@@ -96,17 +99,15 @@ var queryParameters = [
|
|
|
96
99
|
];
|
|
97
100
|
var uniq = (xs) => Array.from(new Set(xs));
|
|
98
101
|
|
|
99
|
-
// src/
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
102
|
+
// src/StrapiCredentialsProvider.tsx
|
|
103
|
+
var StrapiCredentialsContext = import_react.default.createContext(void 0);
|
|
104
|
+
function useStrapiCredentials() {
|
|
105
|
+
const creds = (0, import_react.useContext)(StrapiCredentialsContext);
|
|
106
|
+
if (!creds) {
|
|
107
|
+
throw new Error("Missing StrapiCredentials");
|
|
105
108
|
}
|
|
109
|
+
return creds;
|
|
106
110
|
}
|
|
107
|
-
var modulePath = "@plasmicpkgs/plasmic-strapi";
|
|
108
|
-
var makeDataProviderName = (collection) => `currentStrapi${(0, import_change_case.pascalCase)(collection)}Item`;
|
|
109
|
-
var CredentialsContext = import_react.default.createContext(void 0);
|
|
110
111
|
var strapiCredentialsProviderMeta = {
|
|
111
112
|
name: "StrapiCredentialsProvider",
|
|
112
113
|
displayName: "Strapi Credentials Provider",
|
|
@@ -137,9 +138,12 @@ function StrapiCredentialsProvider({
|
|
|
137
138
|
token,
|
|
138
139
|
children
|
|
139
140
|
}) {
|
|
140
|
-
host =
|
|
141
|
-
return /* @__PURE__ */ import_react.default.createElement(
|
|
141
|
+
host = host == null ? void 0 : host.replace(/\/+$/, "");
|
|
142
|
+
return /* @__PURE__ */ import_react.default.createElement(StrapiCredentialsContext.Provider, { value: { host, token } }, children);
|
|
142
143
|
}
|
|
144
|
+
|
|
145
|
+
// src/StrapiCollection.tsx
|
|
146
|
+
var makeDataProviderName = (collection) => `currentStrapi${(0, import_change_case.pascalCase)(collection)}Item`;
|
|
143
147
|
var strapiCollectionMeta = {
|
|
144
148
|
name: "StrapiCollection",
|
|
145
149
|
displayName: "Strapi Collection",
|
|
@@ -231,9 +235,9 @@ function StrapiCollection({
|
|
|
231
235
|
noAutoRepeat,
|
|
232
236
|
setControlContextData
|
|
233
237
|
}) {
|
|
234
|
-
const creds =
|
|
238
|
+
const creds = useStrapiCredentials();
|
|
235
239
|
if (!creds.host) {
|
|
236
|
-
return /* @__PURE__ */
|
|
240
|
+
return /* @__PURE__ */ import_react2.default.createElement("div", null, "Please specify a host.");
|
|
237
241
|
}
|
|
238
242
|
const query = creds.host + "/api/" + name;
|
|
239
243
|
const cacheKey = JSON.stringify({
|
|
@@ -265,10 +269,10 @@ function StrapiCollection({
|
|
|
265
269
|
return resp.json();
|
|
266
270
|
});
|
|
267
271
|
if (!(data == null ? void 0 : data.data)) {
|
|
268
|
-
return /* @__PURE__ */
|
|
272
|
+
return /* @__PURE__ */ import_react2.default.createElement("div", null, "Please configure the Strapi provider with a valid host and token.");
|
|
269
273
|
}
|
|
270
274
|
if (!(0, import_dlv.default)(data.data, ["data"])) {
|
|
271
|
-
return /* @__PURE__ */
|
|
275
|
+
return /* @__PURE__ */ import_react2.default.createElement("div", null, "Please specify a valid collection.");
|
|
272
276
|
}
|
|
273
277
|
const collectionData = (0, import_dlv.default)(data.data, ["data"]);
|
|
274
278
|
const filterFieds = collectionData.flatMap((item) => {
|
|
@@ -285,28 +289,28 @@ function StrapiCollection({
|
|
|
285
289
|
strapiFields: uniq(filterFieds != null ? filterFieds : [])
|
|
286
290
|
});
|
|
287
291
|
if (filterParameter && !filterValue && !filterField) {
|
|
288
|
-
return /* @__PURE__ */
|
|
292
|
+
return /* @__PURE__ */ import_react2.default.createElement("div", null, "Please specify a Filter Field and a Filter Value");
|
|
289
293
|
}
|
|
290
294
|
if (!filterParameter && filterValue && !filterField) {
|
|
291
|
-
return /* @__PURE__ */
|
|
295
|
+
return /* @__PURE__ */ import_react2.default.createElement("div", null, "Please specify a Filter Parameter and a Filter Field");
|
|
292
296
|
}
|
|
293
297
|
if (!filterParameter && !filterValue && filterField) {
|
|
294
|
-
return /* @__PURE__ */
|
|
298
|
+
return /* @__PURE__ */ import_react2.default.createElement("div", null, "Please specify a Filter Parameter and a Filter Value");
|
|
295
299
|
}
|
|
296
300
|
if (filterParameter && filterValue && !filterField) {
|
|
297
|
-
return /* @__PURE__ */
|
|
301
|
+
return /* @__PURE__ */ import_react2.default.createElement("div", null, "Please specify a Filter Field");
|
|
298
302
|
}
|
|
299
303
|
if (!filterParameter && filterValue && filterField) {
|
|
300
|
-
return /* @__PURE__ */
|
|
304
|
+
return /* @__PURE__ */ import_react2.default.createElement("div", null, "Please specify a Filter Parameter");
|
|
301
305
|
}
|
|
302
306
|
if (filterParameter && !filterValue && filterField) {
|
|
303
|
-
return /* @__PURE__ */
|
|
307
|
+
return /* @__PURE__ */ import_react2.default.createElement("div", null, "Please specify a Filter Value");
|
|
304
308
|
}
|
|
305
309
|
const collection = limit > 0 ? collectionData.slice(0, limit) : collectionData;
|
|
306
310
|
if (collection.length === 0) {
|
|
307
|
-
return /* @__PURE__ */
|
|
311
|
+
return /* @__PURE__ */ import_react2.default.createElement("div", null, "No collection found ");
|
|
308
312
|
}
|
|
309
|
-
const repElements = noAutoRepeat ? children : collection.map((item, index) => /* @__PURE__ */
|
|
313
|
+
const repElements = noAutoRepeat ? children : collection.map((item, index) => /* @__PURE__ */ import_react2.default.createElement(
|
|
310
314
|
import_host.DataProvider,
|
|
311
315
|
{
|
|
312
316
|
key: item.id,
|
|
@@ -314,10 +318,15 @@ function StrapiCollection({
|
|
|
314
318
|
data: item,
|
|
315
319
|
hidden: true
|
|
316
320
|
},
|
|
317
|
-
/* @__PURE__ */
|
|
321
|
+
/* @__PURE__ */ import_react2.default.createElement(import_host.DataProvider, { name: makeDataProviderName(name), data: item }, (0, import_host.repeatedElement)(index, children))
|
|
318
322
|
));
|
|
319
|
-
return /* @__PURE__ */
|
|
323
|
+
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, " "));
|
|
320
324
|
}
|
|
325
|
+
|
|
326
|
+
// src/StrapiField.tsx
|
|
327
|
+
var import_host2 = require("@plasmicapp/host");
|
|
328
|
+
var import_dlv2 = __toESM(require("dlv"));
|
|
329
|
+
var import_react3 = __toESM(require("react"));
|
|
321
330
|
var strapiFieldMeta = {
|
|
322
331
|
name: "StrapiField",
|
|
323
332
|
displayName: "Strapi Field",
|
|
@@ -341,15 +350,14 @@ function StrapiField({
|
|
|
341
350
|
setControlContextData
|
|
342
351
|
}) {
|
|
343
352
|
var _a, _b;
|
|
344
|
-
const item = (0,
|
|
353
|
+
const item = (0, import_host2.useSelector)("strapiItem");
|
|
345
354
|
if (!item) {
|
|
346
|
-
return /* @__PURE__ */
|
|
355
|
+
return /* @__PURE__ */ import_react3.default.createElement("div", null, "StrapiField must be used within a StrapiCollection");
|
|
347
356
|
}
|
|
348
|
-
const attributes = (0,
|
|
357
|
+
const attributes = (0, import_dlv2.default)(item, ["attributes"]);
|
|
349
358
|
const displayableFields = Object.keys(attributes).filter((field) => {
|
|
350
|
-
var _a2, _b2;
|
|
351
359
|
const value = attributes[field];
|
|
352
|
-
const maybeMime2 = (
|
|
360
|
+
const maybeMime2 = (0, import_dlv2.default)(value, "data.attributes.mime");
|
|
353
361
|
return typeof value !== "object" || typeof maybeMime2 === "string" && maybeMime2.startsWith("image");
|
|
354
362
|
});
|
|
355
363
|
setControlContextData == null ? void 0 : setControlContextData({
|
|
@@ -357,23 +365,23 @@ function StrapiField({
|
|
|
357
365
|
isImage: false
|
|
358
366
|
});
|
|
359
367
|
if (!path) {
|
|
360
|
-
return /* @__PURE__ */
|
|
368
|
+
return /* @__PURE__ */ import_react3.default.createElement("div", null, "StrapiField must specify a field name.");
|
|
361
369
|
}
|
|
362
|
-
const data = (0,
|
|
370
|
+
const data = (0, import_dlv2.default)(item, ["attributes", path]);
|
|
363
371
|
const maybeMime = (_b = (_a = data == null ? void 0 : data.data) == null ? void 0 : _a.attributes) == null ? void 0 : _b.mime;
|
|
364
372
|
setControlContextData == null ? void 0 : setControlContextData({
|
|
365
373
|
fields: displayableFields,
|
|
366
374
|
isImage: typeof maybeMime === "string" && maybeMime.startsWith("image")
|
|
367
375
|
});
|
|
368
376
|
if (!data) {
|
|
369
|
-
return /* @__PURE__ */
|
|
377
|
+
return /* @__PURE__ */ import_react3.default.createElement("div", null, "Please specify a valid field name.");
|
|
370
378
|
} else if (typeof maybeMime === "string" && maybeMime.startsWith("image")) {
|
|
371
|
-
const creds =
|
|
379
|
+
const creds = useStrapiCredentials();
|
|
372
380
|
const attrs = data.data.attributes;
|
|
373
381
|
const img_url = attrs.url.startsWith("http") ? attrs.url : creds.host + attrs.url;
|
|
374
382
|
const img_width = attrs.width;
|
|
375
383
|
const img_height = attrs.height;
|
|
376
|
-
return /* @__PURE__ */
|
|
384
|
+
return /* @__PURE__ */ import_react3.default.createElement(
|
|
377
385
|
"img",
|
|
378
386
|
{
|
|
379
387
|
className,
|
|
@@ -383,7 +391,7 @@ function StrapiField({
|
|
|
383
391
|
}
|
|
384
392
|
);
|
|
385
393
|
} else {
|
|
386
|
-
return /* @__PURE__ */
|
|
394
|
+
return /* @__PURE__ */ import_react3.default.createElement("div", { className }, data);
|
|
387
395
|
}
|
|
388
396
|
}
|
|
389
397
|
|
|
@@ -397,9 +405,15 @@ function registerAll(loader) {
|
|
|
397
405
|
}
|
|
398
406
|
};
|
|
399
407
|
if (loader) {
|
|
400
|
-
loader.registerGlobalContext(
|
|
408
|
+
loader.registerGlobalContext(
|
|
409
|
+
StrapiCredentialsProvider,
|
|
410
|
+
strapiCredentialsProviderMeta
|
|
411
|
+
);
|
|
401
412
|
} else {
|
|
402
|
-
(0, import_registerGlobalContext.default)(
|
|
413
|
+
(0, import_registerGlobalContext.default)(
|
|
414
|
+
StrapiCredentialsProvider,
|
|
415
|
+
strapiCredentialsProviderMeta
|
|
416
|
+
);
|
|
403
417
|
}
|
|
404
418
|
_registerComponent(StrapiCollection, strapiCollectionMeta);
|
|
405
419
|
_registerComponent(StrapiField, strapiFieldMeta);
|
|
@@ -409,7 +423,6 @@ function registerAll(loader) {
|
|
|
409
423
|
StrapiCollection,
|
|
410
424
|
StrapiCredentialsProvider,
|
|
411
425
|
StrapiField,
|
|
412
|
-
ensure,
|
|
413
426
|
registerAll,
|
|
414
427
|
strapiCollectionMeta,
|
|
415
428
|
strapiCredentialsProviderMeta,
|
package/dist/index.mjs
CHANGED
|
@@ -2,19 +2,19 @@
|
|
|
2
2
|
import registerComponent from "@plasmicapp/host/registerComponent";
|
|
3
3
|
import registerGlobalContext from "@plasmicapp/host/registerGlobalContext";
|
|
4
4
|
|
|
5
|
-
// src/
|
|
6
|
-
import {
|
|
7
|
-
DataProvider,
|
|
8
|
-
repeatedElement,
|
|
9
|
-
useSelector
|
|
10
|
-
} from "@plasmicapp/host";
|
|
5
|
+
// src/StrapiCollection.tsx
|
|
6
|
+
import { DataProvider, repeatedElement } from "@plasmicapp/host";
|
|
11
7
|
import { usePlasmicQueryData } from "@plasmicapp/query";
|
|
12
|
-
import * as qs from "qs";
|
|
13
|
-
import get from "dlv";
|
|
14
8
|
import { pascalCase } from "change-case";
|
|
9
|
+
import get from "dlv";
|
|
10
|
+
import * as qs from "qs";
|
|
11
|
+
import React2 from "react";
|
|
12
|
+
|
|
13
|
+
// src/StrapiCredentialsProvider.tsx
|
|
15
14
|
import React, { useContext } from "react";
|
|
16
15
|
|
|
17
16
|
// src/utils.ts
|
|
17
|
+
var modulePath = "@plasmicpkgs/plasmic-strapi";
|
|
18
18
|
var queryParameters = [
|
|
19
19
|
{
|
|
20
20
|
value: "$eq",
|
|
@@ -59,17 +59,15 @@ var queryParameters = [
|
|
|
59
59
|
];
|
|
60
60
|
var uniq = (xs) => Array.from(new Set(xs));
|
|
61
61
|
|
|
62
|
-
// src/
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
62
|
+
// src/StrapiCredentialsProvider.tsx
|
|
63
|
+
var StrapiCredentialsContext = React.createContext(void 0);
|
|
64
|
+
function useStrapiCredentials() {
|
|
65
|
+
const creds = useContext(StrapiCredentialsContext);
|
|
66
|
+
if (!creds) {
|
|
67
|
+
throw new Error("Missing StrapiCredentials");
|
|
68
68
|
}
|
|
69
|
+
return creds;
|
|
69
70
|
}
|
|
70
|
-
var modulePath = "@plasmicpkgs/plasmic-strapi";
|
|
71
|
-
var makeDataProviderName = (collection) => `currentStrapi${pascalCase(collection)}Item`;
|
|
72
|
-
var CredentialsContext = React.createContext(void 0);
|
|
73
71
|
var strapiCredentialsProviderMeta = {
|
|
74
72
|
name: "StrapiCredentialsProvider",
|
|
75
73
|
displayName: "Strapi Credentials Provider",
|
|
@@ -100,9 +98,12 @@ function StrapiCredentialsProvider({
|
|
|
100
98
|
token,
|
|
101
99
|
children
|
|
102
100
|
}) {
|
|
103
|
-
host =
|
|
104
|
-
return /* @__PURE__ */ React.createElement(
|
|
101
|
+
host = host == null ? void 0 : host.replace(/\/+$/, "");
|
|
102
|
+
return /* @__PURE__ */ React.createElement(StrapiCredentialsContext.Provider, { value: { host, token } }, children);
|
|
105
103
|
}
|
|
104
|
+
|
|
105
|
+
// src/StrapiCollection.tsx
|
|
106
|
+
var makeDataProviderName = (collection) => `currentStrapi${pascalCase(collection)}Item`;
|
|
106
107
|
var strapiCollectionMeta = {
|
|
107
108
|
name: "StrapiCollection",
|
|
108
109
|
displayName: "Strapi Collection",
|
|
@@ -194,9 +195,9 @@ function StrapiCollection({
|
|
|
194
195
|
noAutoRepeat,
|
|
195
196
|
setControlContextData
|
|
196
197
|
}) {
|
|
197
|
-
const creds =
|
|
198
|
+
const creds = useStrapiCredentials();
|
|
198
199
|
if (!creds.host) {
|
|
199
|
-
return /* @__PURE__ */
|
|
200
|
+
return /* @__PURE__ */ React2.createElement("div", null, "Please specify a host.");
|
|
200
201
|
}
|
|
201
202
|
const query = creds.host + "/api/" + name;
|
|
202
203
|
const cacheKey = JSON.stringify({
|
|
@@ -228,10 +229,10 @@ function StrapiCollection({
|
|
|
228
229
|
return resp.json();
|
|
229
230
|
});
|
|
230
231
|
if (!(data == null ? void 0 : data.data)) {
|
|
231
|
-
return /* @__PURE__ */
|
|
232
|
+
return /* @__PURE__ */ React2.createElement("div", null, "Please configure the Strapi provider with a valid host and token.");
|
|
232
233
|
}
|
|
233
234
|
if (!get(data.data, ["data"])) {
|
|
234
|
-
return /* @__PURE__ */
|
|
235
|
+
return /* @__PURE__ */ React2.createElement("div", null, "Please specify a valid collection.");
|
|
235
236
|
}
|
|
236
237
|
const collectionData = get(data.data, ["data"]);
|
|
237
238
|
const filterFieds = collectionData.flatMap((item) => {
|
|
@@ -248,28 +249,28 @@ function StrapiCollection({
|
|
|
248
249
|
strapiFields: uniq(filterFieds != null ? filterFieds : [])
|
|
249
250
|
});
|
|
250
251
|
if (filterParameter && !filterValue && !filterField) {
|
|
251
|
-
return /* @__PURE__ */
|
|
252
|
+
return /* @__PURE__ */ React2.createElement("div", null, "Please specify a Filter Field and a Filter Value");
|
|
252
253
|
}
|
|
253
254
|
if (!filterParameter && filterValue && !filterField) {
|
|
254
|
-
return /* @__PURE__ */
|
|
255
|
+
return /* @__PURE__ */ React2.createElement("div", null, "Please specify a Filter Parameter and a Filter Field");
|
|
255
256
|
}
|
|
256
257
|
if (!filterParameter && !filterValue && filterField) {
|
|
257
|
-
return /* @__PURE__ */
|
|
258
|
+
return /* @__PURE__ */ React2.createElement("div", null, "Please specify a Filter Parameter and a Filter Value");
|
|
258
259
|
}
|
|
259
260
|
if (filterParameter && filterValue && !filterField) {
|
|
260
|
-
return /* @__PURE__ */
|
|
261
|
+
return /* @__PURE__ */ React2.createElement("div", null, "Please specify a Filter Field");
|
|
261
262
|
}
|
|
262
263
|
if (!filterParameter && filterValue && filterField) {
|
|
263
|
-
return /* @__PURE__ */
|
|
264
|
+
return /* @__PURE__ */ React2.createElement("div", null, "Please specify a Filter Parameter");
|
|
264
265
|
}
|
|
265
266
|
if (filterParameter && !filterValue && filterField) {
|
|
266
|
-
return /* @__PURE__ */
|
|
267
|
+
return /* @__PURE__ */ React2.createElement("div", null, "Please specify a Filter Value");
|
|
267
268
|
}
|
|
268
269
|
const collection = limit > 0 ? collectionData.slice(0, limit) : collectionData;
|
|
269
270
|
if (collection.length === 0) {
|
|
270
|
-
return /* @__PURE__ */
|
|
271
|
+
return /* @__PURE__ */ React2.createElement("div", null, "No collection found ");
|
|
271
272
|
}
|
|
272
|
-
const repElements = noAutoRepeat ? children : collection.map((item, index) => /* @__PURE__ */
|
|
273
|
+
const repElements = noAutoRepeat ? children : collection.map((item, index) => /* @__PURE__ */ React2.createElement(
|
|
273
274
|
DataProvider,
|
|
274
275
|
{
|
|
275
276
|
key: item.id,
|
|
@@ -277,10 +278,15 @@ function StrapiCollection({
|
|
|
277
278
|
data: item,
|
|
278
279
|
hidden: true
|
|
279
280
|
},
|
|
280
|
-
/* @__PURE__ */
|
|
281
|
+
/* @__PURE__ */ React2.createElement(DataProvider, { name: makeDataProviderName(name), data: item }, repeatedElement(index, children))
|
|
281
282
|
));
|
|
282
|
-
return /* @__PURE__ */
|
|
283
|
+
return /* @__PURE__ */ React2.createElement(DataProvider, { name: "strapiItems", data: collection }, noLayout ? /* @__PURE__ */ React2.createElement(React2.Fragment, null, " ", repElements, " ") : /* @__PURE__ */ React2.createElement("div", { className }, " ", repElements, " "));
|
|
283
284
|
}
|
|
285
|
+
|
|
286
|
+
// src/StrapiField.tsx
|
|
287
|
+
import { useSelector } from "@plasmicapp/host";
|
|
288
|
+
import get2 from "dlv";
|
|
289
|
+
import React3 from "react";
|
|
284
290
|
var strapiFieldMeta = {
|
|
285
291
|
name: "StrapiField",
|
|
286
292
|
displayName: "Strapi Field",
|
|
@@ -306,13 +312,12 @@ function StrapiField({
|
|
|
306
312
|
var _a, _b;
|
|
307
313
|
const item = useSelector("strapiItem");
|
|
308
314
|
if (!item) {
|
|
309
|
-
return /* @__PURE__ */
|
|
315
|
+
return /* @__PURE__ */ React3.createElement("div", null, "StrapiField must be used within a StrapiCollection");
|
|
310
316
|
}
|
|
311
|
-
const attributes =
|
|
317
|
+
const attributes = get2(item, ["attributes"]);
|
|
312
318
|
const displayableFields = Object.keys(attributes).filter((field) => {
|
|
313
|
-
var _a2, _b2;
|
|
314
319
|
const value = attributes[field];
|
|
315
|
-
const maybeMime2 = (
|
|
320
|
+
const maybeMime2 = get2(value, "data.attributes.mime");
|
|
316
321
|
return typeof value !== "object" || typeof maybeMime2 === "string" && maybeMime2.startsWith("image");
|
|
317
322
|
});
|
|
318
323
|
setControlContextData == null ? void 0 : setControlContextData({
|
|
@@ -320,23 +325,23 @@ function StrapiField({
|
|
|
320
325
|
isImage: false
|
|
321
326
|
});
|
|
322
327
|
if (!path) {
|
|
323
|
-
return /* @__PURE__ */
|
|
328
|
+
return /* @__PURE__ */ React3.createElement("div", null, "StrapiField must specify a field name.");
|
|
324
329
|
}
|
|
325
|
-
const data =
|
|
330
|
+
const data = get2(item, ["attributes", path]);
|
|
326
331
|
const maybeMime = (_b = (_a = data == null ? void 0 : data.data) == null ? void 0 : _a.attributes) == null ? void 0 : _b.mime;
|
|
327
332
|
setControlContextData == null ? void 0 : setControlContextData({
|
|
328
333
|
fields: displayableFields,
|
|
329
334
|
isImage: typeof maybeMime === "string" && maybeMime.startsWith("image")
|
|
330
335
|
});
|
|
331
336
|
if (!data) {
|
|
332
|
-
return /* @__PURE__ */
|
|
337
|
+
return /* @__PURE__ */ React3.createElement("div", null, "Please specify a valid field name.");
|
|
333
338
|
} else if (typeof maybeMime === "string" && maybeMime.startsWith("image")) {
|
|
334
|
-
const creds =
|
|
339
|
+
const creds = useStrapiCredentials();
|
|
335
340
|
const attrs = data.data.attributes;
|
|
336
341
|
const img_url = attrs.url.startsWith("http") ? attrs.url : creds.host + attrs.url;
|
|
337
342
|
const img_width = attrs.width;
|
|
338
343
|
const img_height = attrs.height;
|
|
339
|
-
return /* @__PURE__ */
|
|
344
|
+
return /* @__PURE__ */ React3.createElement(
|
|
340
345
|
"img",
|
|
341
346
|
{
|
|
342
347
|
className,
|
|
@@ -346,7 +351,7 @@ function StrapiField({
|
|
|
346
351
|
}
|
|
347
352
|
);
|
|
348
353
|
} else {
|
|
349
|
-
return /* @__PURE__ */
|
|
354
|
+
return /* @__PURE__ */ React3.createElement("div", { className }, data);
|
|
350
355
|
}
|
|
351
356
|
}
|
|
352
357
|
|
|
@@ -360,9 +365,15 @@ function registerAll(loader) {
|
|
|
360
365
|
}
|
|
361
366
|
};
|
|
362
367
|
if (loader) {
|
|
363
|
-
loader.registerGlobalContext(
|
|
368
|
+
loader.registerGlobalContext(
|
|
369
|
+
StrapiCredentialsProvider,
|
|
370
|
+
strapiCredentialsProviderMeta
|
|
371
|
+
);
|
|
364
372
|
} else {
|
|
365
|
-
registerGlobalContext(
|
|
373
|
+
registerGlobalContext(
|
|
374
|
+
StrapiCredentialsProvider,
|
|
375
|
+
strapiCredentialsProviderMeta
|
|
376
|
+
);
|
|
366
377
|
}
|
|
367
378
|
_registerComponent(StrapiCollection, strapiCollectionMeta);
|
|
368
379
|
_registerComponent(StrapiField, strapiFieldMeta);
|
|
@@ -371,7 +382,6 @@ export {
|
|
|
371
382
|
StrapiCollection,
|
|
372
383
|
StrapiCredentialsProvider,
|
|
373
384
|
StrapiField,
|
|
374
|
-
ensure,
|
|
375
385
|
registerAll,
|
|
376
386
|
strapiCollectionMeta,
|
|
377
387
|
strapiCredentialsProviderMeta,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plasmicpkgs/plasmic-strapi",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.139",
|
|
4
4
|
"description": "Plasmic Strapi components.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"analyze": "size-limit --why"
|
|
20
20
|
},
|
|
21
21
|
"peerDependencies": {
|
|
22
|
-
"react": ">=16"
|
|
22
|
+
"react": ">=16.8.0"
|
|
23
23
|
},
|
|
24
24
|
"size-limit": [
|
|
25
25
|
{
|
|
@@ -31,8 +31,14 @@
|
|
|
31
31
|
"limit": "10 KB"
|
|
32
32
|
}
|
|
33
33
|
],
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@types/dlv": "^1.1.2",
|
|
36
|
+
"change-case": "^4.1.2",
|
|
37
|
+
"dlv": "^1.1.3",
|
|
38
|
+
"qs": "^6.11.0"
|
|
39
|
+
},
|
|
34
40
|
"devDependencies": {
|
|
35
|
-
"@plasmicapp/host": "1.0.
|
|
41
|
+
"@plasmicapp/host": "1.0.191",
|
|
36
42
|
"@plasmicapp/query": "0.1.78",
|
|
37
43
|
"@size-limit/preset-small-lib": "^7.0.8",
|
|
38
44
|
"@types/dlv": "^1.1.2",
|
|
@@ -40,7 +46,6 @@
|
|
|
40
46
|
"@types/react": "^18.0.27",
|
|
41
47
|
"@types/react-dom": "^18.0.10",
|
|
42
48
|
"husky": "^7.0.4",
|
|
43
|
-
"qs": "^6.11.0",
|
|
44
49
|
"react": "^18.2.0",
|
|
45
50
|
"react-dom": "^18.2.0",
|
|
46
51
|
"size-limit": "^7.0.8",
|
|
@@ -48,10 +53,5 @@
|
|
|
48
53
|
"tsup": "^7.2.0",
|
|
49
54
|
"typescript": "^5.2.2"
|
|
50
55
|
},
|
|
51
|
-
"
|
|
52
|
-
"@types/dlv": "^1.1.2",
|
|
53
|
-
"change-case": "^4.1.2",
|
|
54
|
-
"dlv": "^1.1.3"
|
|
55
|
-
},
|
|
56
|
-
"gitHead": "d610e0b0246d0f56d641248b95b7b10f235e68c5"
|
|
56
|
+
"gitHead": "df264a9098a27ee0323639e37204ec0dc58ba9f2"
|
|
57
57
|
}
|