@prismicio/react 2.5.0 → 2.5.1
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/PrismicImage.cjs +67 -0
- package/dist/PrismicImage.cjs.map +1 -0
- package/dist/PrismicImage.d.ts +163 -0
- package/dist/PrismicImage.js +49 -0
- package/dist/PrismicImage.js.map +1 -0
- package/dist/PrismicLink.cjs +91 -0
- package/dist/PrismicLink.cjs.map +1 -0
- package/dist/PrismicLink.d.ts +105 -0
- package/dist/PrismicLink.js +73 -0
- package/dist/PrismicLink.js.map +1 -0
- package/dist/PrismicProvider.cjs +41 -0
- package/dist/PrismicProvider.cjs.map +1 -0
- package/dist/PrismicProvider.d.ts +84 -0
- package/dist/PrismicProvider.js +24 -0
- package/dist/PrismicProvider.js.map +1 -0
- package/dist/PrismicRichText.cjs +97 -0
- package/dist/PrismicRichText.cjs.map +1 -0
- package/dist/PrismicRichText.d.ts +116 -0
- package/dist/PrismicRichText.js +78 -0
- package/dist/PrismicRichText.js.map +1 -0
- package/dist/PrismicText.cjs +42 -0
- package/dist/PrismicText.cjs.map +1 -0
- package/dist/PrismicText.d.ts +39 -0
- package/dist/PrismicText.js +24 -0
- package/dist/PrismicText.js.map +1 -0
- package/dist/PrismicToolbar.cjs +41 -0
- package/dist/PrismicToolbar.cjs.map +1 -0
- package/dist/PrismicToolbar.d.ts +21 -0
- package/dist/PrismicToolbar.js +24 -0
- package/dist/PrismicToolbar.js.map +1 -0
- package/dist/SliceZone.cjs +58 -0
- package/dist/SliceZone.cjs.map +1 -0
- package/dist/SliceZone.d.ts +188 -0
- package/dist/SliceZone.js +41 -0
- package/dist/SliceZone.js.map +1 -0
- package/dist/clientHooks.cjs +40 -0
- package/dist/clientHooks.cjs.map +1 -0
- package/dist/clientHooks.d.ts +357 -0
- package/dist/clientHooks.js +40 -0
- package/dist/clientHooks.js.map +1 -0
- package/dist/index.cjs +46 -574
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +46 -1290
- package/dist/index.js +46 -519
- package/dist/index.js.map +1 -1
- package/dist/lib/__PRODUCTION__.cjs +8 -0
- package/dist/lib/__PRODUCTION__.cjs.map +1 -0
- package/dist/lib/__PRODUCTION__.d.ts +7 -0
- package/dist/lib/__PRODUCTION__.js +8 -0
- package/dist/lib/__PRODUCTION__.js.map +1 -0
- package/dist/lib/devMsg.cjs +8 -0
- package/dist/lib/devMsg.cjs.map +1 -0
- package/dist/lib/devMsg.d.ts +16 -0
- package/dist/lib/devMsg.js +8 -0
- package/dist/lib/devMsg.js.map +1 -0
- package/dist/lib/invariant.cjs +15 -0
- package/dist/lib/invariant.cjs.map +1 -0
- package/dist/lib/invariant.d.ts +24 -0
- package/dist/lib/invariant.js +15 -0
- package/dist/lib/invariant.js.map +1 -0
- package/dist/lib/isInternalURL.cjs +9 -0
- package/dist/lib/isInternalURL.cjs.map +1 -0
- package/dist/lib/isInternalURL.d.ts +8 -0
- package/dist/lib/isInternalURL.js +9 -0
- package/dist/lib/isInternalURL.js.map +1 -0
- package/dist/lib/pascalCase.cjs +10 -0
- package/dist/lib/pascalCase.cjs.map +1 -0
- package/dist/lib/pascalCase.d.ts +26 -0
- package/dist/lib/pascalCase.js +10 -0
- package/dist/lib/pascalCase.js.map +1 -0
- package/dist/package.json.cjs +5 -0
- package/dist/package.json.cjs.map +1 -0
- package/dist/package.json.js +5 -0
- package/dist/package.json.js.map +1 -0
- package/dist/types.d.ts +19 -0
- package/dist/usePrismicClient.cjs +12 -0
- package/dist/usePrismicClient.cjs.map +1 -0
- package/dist/usePrismicClient.d.ts +11 -0
- package/dist/usePrismicClient.js +12 -0
- package/dist/usePrismicClient.js.map +1 -0
- package/dist/usePrismicContext.cjs +26 -0
- package/dist/usePrismicContext.cjs.map +1 -0
- package/dist/usePrismicContext.d.ts +8 -0
- package/dist/usePrismicContext.js +9 -0
- package/dist/usePrismicContext.js.map +1 -0
- package/dist/usePrismicPreviewResolver.cjs +44 -0
- package/dist/usePrismicPreviewResolver.cjs.map +1 -0
- package/dist/usePrismicPreviewResolver.d.ts +45 -0
- package/dist/usePrismicPreviewResolver.js +27 -0
- package/dist/usePrismicPreviewResolver.js.map +1 -0
- package/dist/useStatefulPrismicClientMethod.cjs +89 -0
- package/dist/useStatefulPrismicClientMethod.cjs.map +1 -0
- package/dist/useStatefulPrismicClientMethod.d.ts +44 -0
- package/dist/useStatefulPrismicClientMethod.js +72 -0
- package/dist/useStatefulPrismicClientMethod.js.map +1 -0
- package/package.json +43 -41
- package/src/PrismicImage.tsx +2 -1
- package/src/PrismicProvider.tsx +6 -3
- package/src/PrismicText.tsx +2 -1
- package/src/SliceZone.tsx +8 -4
- package/src/clientHooks.ts +52 -44
- package/src/useStatefulPrismicClientMethod.ts +2 -1
package/dist/index.cjs
CHANGED
|
@@ -1,578 +1,50 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const d = Object.getOwnPropertyDescriptor(e, k);
|
|
16
|
-
Object.defineProperty(n, k, d.get ? d : {
|
|
17
|
-
enumerable: true,
|
|
18
|
-
get: function () { return e[k]; }
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
n["default"] = e;
|
|
24
|
-
return Object.freeze(n);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
28
|
-
const prismicH__namespace = /*#__PURE__*/_interopNamespace(prismicH);
|
|
29
|
-
const prismicR__namespace = /*#__PURE__*/_interopNamespace(prismicR);
|
|
30
|
-
|
|
31
|
-
const PrismicContext = React__namespace.createContext({});
|
|
32
|
-
const PrismicProvider = ({
|
|
33
|
-
client,
|
|
34
|
-
linkResolver,
|
|
35
|
-
richTextComponents,
|
|
36
|
-
internalLinkComponent,
|
|
37
|
-
externalLinkComponent,
|
|
38
|
-
children
|
|
39
|
-
}) => {
|
|
40
|
-
const value = React__namespace.useMemo(() => ({
|
|
41
|
-
client,
|
|
42
|
-
linkResolver,
|
|
43
|
-
richTextComponents,
|
|
44
|
-
internalLinkComponent,
|
|
45
|
-
externalLinkComponent
|
|
46
|
-
}), [
|
|
47
|
-
client,
|
|
48
|
-
linkResolver,
|
|
49
|
-
richTextComponents,
|
|
50
|
-
internalLinkComponent,
|
|
51
|
-
externalLinkComponent
|
|
52
|
-
]);
|
|
53
|
-
return /* @__PURE__ */ React__namespace.createElement(PrismicContext.Provider, {
|
|
54
|
-
value
|
|
55
|
-
}, children);
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
const usePrismicContext = () => {
|
|
59
|
-
return React__namespace.useContext(PrismicContext) || {};
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
if (typeof process === "undefined") {
|
|
63
|
-
globalThis.process = { env: {} };
|
|
64
|
-
}
|
|
65
|
-
const __PRODUCTION__ = process.env.NODE_ENV === "production";
|
|
66
|
-
|
|
67
|
-
const prefix = "Invariant failed";
|
|
68
|
-
function invariant(condition, message) {
|
|
69
|
-
if (condition) {
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
72
|
-
if (__PRODUCTION__) {
|
|
73
|
-
throw new Error(prefix);
|
|
74
|
-
}
|
|
75
|
-
throw new Error(`${prefix}: ${message || ""}`);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
const usePrismicClient = (explicitClient) => {
|
|
79
|
-
const context = usePrismicContext();
|
|
80
|
-
const client = explicitClient || (context == null ? void 0 : context.client);
|
|
81
|
-
invariant(client, "A @prismicio/client is required to query documents. Provide a client to the hook or to a <PrismicProvider> higher in your component tree.");
|
|
82
|
-
return client;
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
var version = "2.5.0";
|
|
86
|
-
|
|
87
|
-
const devMsg = (slug) => {
|
|
88
|
-
return `https://prismic.dev/msg/react/v${version}/${slug}`;
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
const isInternalURL = (url) => {
|
|
92
|
-
const isInternal = /^(\/(?!\/)|#)/.test(url);
|
|
93
|
-
const isSpecialLink = !isInternal && !/^https?:\/\//.test(url);
|
|
94
|
-
return isInternal && !isSpecialLink;
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
const defaultInternalComponent = "a";
|
|
98
|
-
const defaultExternalComponent = "a";
|
|
99
|
-
const _PrismicLink = (props, ref) => {
|
|
100
|
-
const context = usePrismicContext();
|
|
101
|
-
if (!__PRODUCTION__) {
|
|
102
|
-
if ("field" in props && props.field) {
|
|
103
|
-
if (!props.field.link_type) {
|
|
104
|
-
console.error(`[PrismicLink] This "field" prop value caused an error to be thrown.
|
|
105
|
-
`, props.field);
|
|
106
|
-
throw new Error(`[PrismicLink] The provided field is missing required properties to properly render a link. The link will not render. For more details, see ${devMsg("missing-link-properties")}`);
|
|
107
|
-
} else if (Object.keys(props.field).length > 1 && !("url" in props.field || "uid" in props.field || "id" in props.field)) {
|
|
108
|
-
console.warn(`[PrismicLink] The provided field is missing required properties to properly render a link. The link may not render correctly. For more details, see ${devMsg("missing-link-properties")}`, props.field);
|
|
109
|
-
}
|
|
110
|
-
} else if ("document" in props && props.document) {
|
|
111
|
-
if (!("url" in props.document || "id" in props.document)) {
|
|
112
|
-
console.warn(`[PrismicLink] The provided document is missing required properties to properly render a link. The link may not render correctly. For more details, see ${devMsg("missing-link-properties")}`, props.document);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
const linkResolver = props.linkResolver || context.linkResolver;
|
|
117
|
-
let href;
|
|
118
|
-
if ("href" in props) {
|
|
119
|
-
href = props.href;
|
|
120
|
-
} else if ("document" in props && props.document) {
|
|
121
|
-
href = prismicH__namespace.asLink(props.document, linkResolver);
|
|
122
|
-
} else if ("field" in props && props.field) {
|
|
123
|
-
href = prismicH__namespace.asLink(props.field, linkResolver);
|
|
124
|
-
}
|
|
125
|
-
const isInternal = href && isInternalURL(href);
|
|
126
|
-
const target = props.target || "field" in props && props.field && "target" in props.field && props.field.target || !isInternal && "_blank" || void 0;
|
|
127
|
-
const rel = props.rel || (target === "_blank" ? "noopener noreferrer" : void 0);
|
|
128
|
-
const InternalComponent = props.internalComponent || context.internalLinkComponent || defaultInternalComponent;
|
|
129
|
-
const ExternalComponent = props.externalComponent || context.externalLinkComponent || defaultExternalComponent;
|
|
130
|
-
const Component = isInternal ? InternalComponent : ExternalComponent;
|
|
131
|
-
const passthroughProps = Object.assign({}, props);
|
|
132
|
-
delete passthroughProps.linkResolver;
|
|
133
|
-
delete passthroughProps.internalComponent;
|
|
134
|
-
delete passthroughProps.externalComponent;
|
|
135
|
-
delete passthroughProps.rel;
|
|
136
|
-
delete passthroughProps.target;
|
|
137
|
-
if ("field" in passthroughProps) {
|
|
138
|
-
delete passthroughProps.field;
|
|
139
|
-
} else if ("document" in passthroughProps) {
|
|
140
|
-
delete passthroughProps.document;
|
|
141
|
-
} else if ("href" in passthroughProps) {
|
|
142
|
-
delete passthroughProps.href;
|
|
143
|
-
}
|
|
144
|
-
return href ? /* @__PURE__ */ React__namespace.createElement(Component, {
|
|
145
|
-
...passthroughProps,
|
|
146
|
-
ref,
|
|
147
|
-
href,
|
|
148
|
-
target,
|
|
149
|
-
rel
|
|
150
|
-
}) : null;
|
|
151
|
-
};
|
|
152
|
-
if (!__PRODUCTION__) {
|
|
153
|
-
_PrismicLink.displayName = "PrismicLink";
|
|
154
|
-
}
|
|
155
|
-
const PrismicLink = React__namespace.forwardRef(_PrismicLink);
|
|
156
|
-
|
|
157
|
-
const PrismicText = (props) => {
|
|
158
|
-
if (!__PRODUCTION__) {
|
|
159
|
-
if (typeof props.field === "string") {
|
|
160
|
-
throw new Error(`[PrismicText] The "field" prop only accepts a Rich Text or Title field's value but was provided a different type of field instead (e.g. a Key Text or Select field). You can resolve this error by rendering the field value inline without <PrismicText>. For more details, see ${devMsg("prismictext-works-only-with-rich-text-and-title-fields")}`);
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
return React__namespace.useMemo(() => {
|
|
164
|
-
if (prismicH__namespace.isFilled.richText(props.field)) {
|
|
165
|
-
const text = prismicH__namespace.asText(props.field, props.separator);
|
|
166
|
-
return /* @__PURE__ */ React__namespace.createElement(React__namespace.Fragment, null, text);
|
|
167
|
-
} else {
|
|
168
|
-
return props.fallback != null ? /* @__PURE__ */ React__namespace.createElement(React__namespace.Fragment, null, props.fallback) : null;
|
|
169
|
-
}
|
|
170
|
-
}, [props.field, props.fallback, props.separator]);
|
|
171
|
-
};
|
|
172
|
-
|
|
173
|
-
const createDefaultSerializer = (args) => prismicR__namespace.wrapMapSerializer({
|
|
174
|
-
heading1: ({ children, key }) => /* @__PURE__ */ React__namespace.createElement("h1", {
|
|
175
|
-
key
|
|
176
|
-
}, children),
|
|
177
|
-
heading2: ({ children, key }) => /* @__PURE__ */ React__namespace.createElement("h2", {
|
|
178
|
-
key
|
|
179
|
-
}, children),
|
|
180
|
-
heading3: ({ children, key }) => /* @__PURE__ */ React__namespace.createElement("h3", {
|
|
181
|
-
key
|
|
182
|
-
}, children),
|
|
183
|
-
heading4: ({ children, key }) => /* @__PURE__ */ React__namespace.createElement("h4", {
|
|
184
|
-
key
|
|
185
|
-
}, children),
|
|
186
|
-
heading5: ({ children, key }) => /* @__PURE__ */ React__namespace.createElement("h5", {
|
|
187
|
-
key
|
|
188
|
-
}, children),
|
|
189
|
-
heading6: ({ children, key }) => /* @__PURE__ */ React__namespace.createElement("h6", {
|
|
190
|
-
key
|
|
191
|
-
}, children),
|
|
192
|
-
paragraph: ({ children, key }) => /* @__PURE__ */ React__namespace.createElement("p", {
|
|
193
|
-
key
|
|
194
|
-
}, children),
|
|
195
|
-
preformatted: ({ node, key }) => /* @__PURE__ */ React__namespace.createElement("pre", {
|
|
196
|
-
key
|
|
197
|
-
}, node.text),
|
|
198
|
-
strong: ({ children, key }) => /* @__PURE__ */ React__namespace.createElement("strong", {
|
|
199
|
-
key
|
|
200
|
-
}, children),
|
|
201
|
-
em: ({ children, key }) => /* @__PURE__ */ React__namespace.createElement("em", {
|
|
202
|
-
key
|
|
203
|
-
}, children),
|
|
204
|
-
listItem: ({ children, key }) => /* @__PURE__ */ React__namespace.createElement("li", {
|
|
205
|
-
key
|
|
206
|
-
}, children),
|
|
207
|
-
oListItem: ({ children, key }) => /* @__PURE__ */ React__namespace.createElement("li", {
|
|
208
|
-
key
|
|
209
|
-
}, children),
|
|
210
|
-
list: ({ children, key }) => /* @__PURE__ */ React__namespace.createElement("ul", {
|
|
211
|
-
key
|
|
212
|
-
}, children),
|
|
213
|
-
oList: ({ children, key }) => /* @__PURE__ */ React__namespace.createElement("ol", {
|
|
214
|
-
key
|
|
215
|
-
}, children),
|
|
216
|
-
image: ({ node, key }) => {
|
|
217
|
-
var _a;
|
|
218
|
-
const img = /* @__PURE__ */ React__namespace.createElement("img", {
|
|
219
|
-
src: node.url,
|
|
220
|
-
alt: (_a = node.alt) != null ? _a : void 0,
|
|
221
|
-
"data-copyright": node.copyright ? node.copyright : void 0
|
|
222
|
-
});
|
|
223
|
-
return /* @__PURE__ */ React__namespace.createElement("p", {
|
|
224
|
-
key,
|
|
225
|
-
className: "block-img"
|
|
226
|
-
}, node.linkTo ? /* @__PURE__ */ React__namespace.createElement(PrismicLink, {
|
|
227
|
-
linkResolver: args.linkResolver,
|
|
228
|
-
internalComponent: args.internalLinkComponent,
|
|
229
|
-
externalComponent: args.externalLinkComponent,
|
|
230
|
-
field: node.linkTo
|
|
231
|
-
}, img) : img);
|
|
232
|
-
},
|
|
233
|
-
embed: ({ node, key }) => {
|
|
234
|
-
var _a;
|
|
235
|
-
return /* @__PURE__ */ React__namespace.createElement("div", {
|
|
236
|
-
key,
|
|
237
|
-
"data-oembed": node.oembed.embed_url,
|
|
238
|
-
"data-oembed-type": node.oembed.type,
|
|
239
|
-
"data-oembed-provider": node.oembed.provider_name,
|
|
240
|
-
dangerouslySetInnerHTML: { __html: (_a = node.oembed.html) != null ? _a : "" }
|
|
241
|
-
});
|
|
242
|
-
},
|
|
243
|
-
hyperlink: ({ node, children, key }) => /* @__PURE__ */ React__namespace.createElement(PrismicLink, {
|
|
244
|
-
key,
|
|
245
|
-
field: node.data,
|
|
246
|
-
linkResolver: args.linkResolver,
|
|
247
|
-
internalComponent: args.internalLinkComponent,
|
|
248
|
-
externalComponent: args.externalLinkComponent
|
|
249
|
-
}, children),
|
|
250
|
-
label: ({ node, children, key }) => /* @__PURE__ */ React__namespace.createElement("span", {
|
|
251
|
-
key,
|
|
252
|
-
className: node.data.label
|
|
253
|
-
}, children),
|
|
254
|
-
span: ({ text, key }) => {
|
|
255
|
-
const result = [];
|
|
256
|
-
let i = 0;
|
|
257
|
-
for (const line of text.split("\n")) {
|
|
258
|
-
if (i > 0) {
|
|
259
|
-
result.push(/* @__PURE__ */ React__namespace.createElement("br", {
|
|
260
|
-
key: `${i}__break`
|
|
261
|
-
}));
|
|
262
|
-
}
|
|
263
|
-
result.push(/* @__PURE__ */ React__namespace.createElement(React__namespace.Fragment, {
|
|
264
|
-
key: `${i}__line`
|
|
265
|
-
}, line));
|
|
266
|
-
i++;
|
|
267
|
-
}
|
|
268
|
-
return /* @__PURE__ */ React__namespace.createElement(React__namespace.Fragment, {
|
|
269
|
-
key
|
|
270
|
-
}, result);
|
|
271
|
-
}
|
|
272
|
-
});
|
|
273
|
-
const PrismicRichText = (props) => {
|
|
274
|
-
const context = usePrismicContext();
|
|
275
|
-
return React__namespace.useMemo(() => {
|
|
276
|
-
if (prismicH__namespace.isFilled.richText(props.field)) {
|
|
277
|
-
const linkResolver = props.linkResolver || context.linkResolver;
|
|
278
|
-
const serializer = prismicR__namespace.composeSerializers(typeof props.components === "object" ? prismicR__namespace.wrapMapSerializer(props.components) : props.components, typeof context.richTextComponents === "object" ? prismicR__namespace.wrapMapSerializer(context.richTextComponents) : context.richTextComponents, createDefaultSerializer({
|
|
279
|
-
linkResolver,
|
|
280
|
-
internalLinkComponent: props.internalLinkComponent,
|
|
281
|
-
externalLinkComponent: props.externalLinkComponent
|
|
282
|
-
}));
|
|
283
|
-
const serialized = prismicR__namespace.serialize(props.field, (type, node, text, children, key) => {
|
|
284
|
-
const result = serializer(type, node, text, children, key);
|
|
285
|
-
if (React__namespace.isValidElement(result) && result.key == null) {
|
|
286
|
-
return React__namespace.cloneElement(result, { key });
|
|
287
|
-
} else {
|
|
288
|
-
return result;
|
|
289
|
-
}
|
|
290
|
-
});
|
|
291
|
-
return /* @__PURE__ */ React__namespace.createElement(React__namespace.Fragment, null, serialized);
|
|
292
|
-
} else {
|
|
293
|
-
return props.fallback != null ? /* @__PURE__ */ React__namespace.createElement(React__namespace.Fragment, null, props.fallback) : null;
|
|
294
|
-
}
|
|
295
|
-
}, [
|
|
296
|
-
props.field,
|
|
297
|
-
props.internalLinkComponent,
|
|
298
|
-
props.externalLinkComponent,
|
|
299
|
-
props.components,
|
|
300
|
-
props.linkResolver,
|
|
301
|
-
props.fallback,
|
|
302
|
-
context.linkResolver,
|
|
303
|
-
context.richTextComponents
|
|
304
|
-
]);
|
|
305
|
-
};
|
|
306
|
-
|
|
307
|
-
const _PrismicImage = (props, ref) => {
|
|
308
|
-
const {
|
|
309
|
-
field,
|
|
310
|
-
alt,
|
|
311
|
-
fallbackAlt,
|
|
312
|
-
imgixParams,
|
|
313
|
-
widths,
|
|
314
|
-
pixelDensities,
|
|
315
|
-
...restProps
|
|
316
|
-
} = props;
|
|
317
|
-
if (!__PRODUCTION__) {
|
|
318
|
-
if (typeof alt === "string" && props.alt !== "") {
|
|
319
|
-
console.warn(`[PrismicImage] The "alt" prop can only be used to declare an image as decorative by passing an empty string (alt="") but was provided a non-empty string. You can resolve this warning by removing the "alt" prop or changing it to alt="". For more details, see ${devMsg("alt-must-be-an-empty-string")}`);
|
|
320
|
-
}
|
|
321
|
-
if (typeof fallbackAlt === "string" && fallbackAlt !== "") {
|
|
322
|
-
console.warn(`[PrismicImage] The "fallbackAlt" prop can only be used to declare an image as decorative by passing an empty string (fallbackAlt="") but was provided a non-empty string. You can resolve this warning by removing the "fallbackAlt" prop or changing it to fallbackAlt="". For more details, see ${devMsg("alt-must-be-an-empty-string")}`);
|
|
323
|
-
}
|
|
324
|
-
if (widths && pixelDensities) {
|
|
325
|
-
console.warn(`[PrismicImage] Only one of "widths" or "pixelDensities" props can be provided. You can resolve this warning by removing either the "widths" or "pixelDensities" prop. "widths" will be used in this case.`);
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
if (prismicH__namespace.isFilled.imageThumbnail(field)) {
|
|
329
|
-
let src;
|
|
330
|
-
let srcSet;
|
|
331
|
-
if (widths || !pixelDensities) {
|
|
332
|
-
const res = prismicH__namespace.asImageWidthSrcSet(field, {
|
|
333
|
-
...imgixParams,
|
|
334
|
-
widths: widths === "defaults" ? void 0 : widths
|
|
335
|
-
});
|
|
336
|
-
src = res.src;
|
|
337
|
-
srcSet = res.srcset;
|
|
338
|
-
} else if (pixelDensities) {
|
|
339
|
-
const res = prismicH__namespace.asImagePixelDensitySrcSet(field, {
|
|
340
|
-
...imgixParams,
|
|
341
|
-
pixelDensities: pixelDensities === "defaults" ? void 0 : pixelDensities
|
|
342
|
-
});
|
|
343
|
-
src = res.src;
|
|
344
|
-
srcSet = res.srcset;
|
|
345
|
-
}
|
|
346
|
-
return /* @__PURE__ */ React__namespace.createElement("img", {
|
|
347
|
-
ref,
|
|
348
|
-
src,
|
|
349
|
-
srcSet,
|
|
350
|
-
alt: alt != null ? alt : field.alt || fallbackAlt,
|
|
351
|
-
...restProps
|
|
352
|
-
});
|
|
353
|
-
} else {
|
|
354
|
-
return null;
|
|
355
|
-
}
|
|
356
|
-
};
|
|
357
|
-
if (!__PRODUCTION__) {
|
|
358
|
-
_PrismicImage.displayName = "PrismicImage";
|
|
359
|
-
}
|
|
360
|
-
const PrismicImage = React__namespace.forwardRef(_PrismicImage);
|
|
361
|
-
|
|
362
|
-
const pascalCase = (input) => {
|
|
363
|
-
const camelCased = input.replace(/(?:-|_)(\w)/g, (_, c) => {
|
|
364
|
-
return c ? c.toUpperCase() : "";
|
|
365
|
-
});
|
|
366
|
-
return camelCased[0].toUpperCase() + camelCased.slice(1);
|
|
367
|
-
};
|
|
368
|
-
|
|
369
|
-
const TODOSliceComponent = __PRODUCTION__ ? () => null : ({
|
|
370
|
-
slice
|
|
371
|
-
}) => {
|
|
372
|
-
const type = "slice_type" in slice ? slice.slice_type : slice.type;
|
|
373
|
-
React__namespace.useEffect(() => {
|
|
374
|
-
console.warn(`[SliceZone] Could not find a component for Slice type "${type}"`, slice);
|
|
375
|
-
}, [slice, type]);
|
|
376
|
-
return /* @__PURE__ */ React__namespace.createElement("section", {
|
|
377
|
-
"data-slice-zone-todo-component": "",
|
|
378
|
-
"data-slice-type": type
|
|
379
|
-
}, "Could not find a component for Slice type \u201C", type, "\u201D");
|
|
380
|
-
};
|
|
381
|
-
const SliceZone = ({
|
|
382
|
-
slices = [],
|
|
383
|
-
components = {},
|
|
384
|
-
resolver,
|
|
385
|
-
defaultComponent = TODOSliceComponent,
|
|
386
|
-
context = {}
|
|
387
|
-
}) => {
|
|
388
|
-
const renderedSlices = React__namespace.useMemo(() => {
|
|
389
|
-
return slices.map((slice, index) => {
|
|
390
|
-
const type = "slice_type" in slice ? slice.slice_type : slice.type;
|
|
391
|
-
let Comp = components[type] || defaultComponent;
|
|
392
|
-
if (resolver) {
|
|
393
|
-
const resolvedComp = resolver({
|
|
394
|
-
slice,
|
|
395
|
-
sliceName: pascalCase(type),
|
|
396
|
-
i: index
|
|
397
|
-
});
|
|
398
|
-
if (resolvedComp) {
|
|
399
|
-
Comp = resolvedComp;
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
const key = "id" in slice && slice.id ? slice.id : `${index}-${JSON.stringify(slice)}`;
|
|
403
|
-
return /* @__PURE__ */ React__namespace.createElement(Comp, {
|
|
404
|
-
key,
|
|
405
|
-
slice,
|
|
406
|
-
index,
|
|
407
|
-
slices,
|
|
408
|
-
context
|
|
409
|
-
});
|
|
410
|
-
});
|
|
411
|
-
}, [components, context, defaultComponent, slices, resolver]);
|
|
412
|
-
return /* @__PURE__ */ React__namespace.createElement(React__namespace.Fragment, null, renderedSlices);
|
|
413
|
-
};
|
|
414
|
-
|
|
415
|
-
const PrismicToolbar = ({
|
|
416
|
-
repositoryName,
|
|
417
|
-
type = "new"
|
|
418
|
-
}) => {
|
|
419
|
-
const src = `https://static.cdn.prismic.io/prismic.js?repo=${repositoryName}${type === "new" ? "&new=true" : ""}`;
|
|
420
|
-
React__namespace.useEffect(() => {
|
|
421
|
-
const existingScript = document.querySelector(`script[src="${src}"]`);
|
|
422
|
-
if (!existingScript) {
|
|
423
|
-
const script = document.createElement("script");
|
|
424
|
-
script.src = src;
|
|
425
|
-
script.defer = true;
|
|
426
|
-
script.dataset.prismicToolbar = "";
|
|
427
|
-
script.dataset.repositoryName = repositoryName;
|
|
428
|
-
script.dataset.type = type;
|
|
429
|
-
if (process.env.NODE_ENV === "test") {
|
|
430
|
-
script._evaluateScript = false;
|
|
431
|
-
}
|
|
432
|
-
document.body.appendChild(script);
|
|
433
|
-
}
|
|
434
|
-
}, [repositoryName, type, src]);
|
|
435
|
-
return null;
|
|
436
|
-
};
|
|
437
|
-
|
|
438
|
-
const reducer = (state, action) => {
|
|
439
|
-
switch (action[0]) {
|
|
440
|
-
case "start": {
|
|
441
|
-
return { state: "loading" };
|
|
442
|
-
}
|
|
443
|
-
case "succeed": {
|
|
444
|
-
return { state: "loaded", data: action[1] };
|
|
445
|
-
}
|
|
446
|
-
case "fail": {
|
|
447
|
-
return {
|
|
448
|
-
...state,
|
|
449
|
-
state: "failed",
|
|
450
|
-
error: action[1]
|
|
451
|
-
};
|
|
452
|
-
}
|
|
453
|
-
}
|
|
454
|
-
};
|
|
455
|
-
const initialState = {
|
|
456
|
-
state: "idle"
|
|
457
|
-
};
|
|
458
|
-
const isParams = (value) => {
|
|
459
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
460
|
-
};
|
|
461
|
-
const useStatefulPrismicClientMethod = (methodName, args, explicitClient) => {
|
|
462
|
-
const lastArg = args[args.length - 1];
|
|
463
|
-
const {
|
|
464
|
-
client: lastArgExplicitClient,
|
|
465
|
-
skip,
|
|
466
|
-
...params
|
|
467
|
-
} = isParams(lastArg) ? lastArg : {};
|
|
468
|
-
const argsWithoutParams = isParams(lastArg) ? args.slice(0, -1) : args;
|
|
469
|
-
const client = usePrismicClient(explicitClient || lastArgExplicitClient);
|
|
470
|
-
const [state, dispatch] = React__namespace.useReducer(reducer, initialState);
|
|
471
|
-
React__namespace.useEffect(() => {
|
|
472
|
-
if (!skip) {
|
|
473
|
-
{
|
|
474
|
-
dispatch(["start"]);
|
|
475
|
-
}
|
|
476
|
-
client[methodName].call(client, ...argsWithoutParams, params).then((result) => {
|
|
477
|
-
{
|
|
478
|
-
dispatch(["succeed", result]);
|
|
479
|
-
}
|
|
480
|
-
}).catch((error) => {
|
|
481
|
-
{
|
|
482
|
-
dispatch(["fail", error]);
|
|
483
|
-
}
|
|
484
|
-
});
|
|
485
|
-
}
|
|
486
|
-
}, [
|
|
487
|
-
client,
|
|
488
|
-
methodName,
|
|
489
|
-
skip,
|
|
490
|
-
JSON.stringify(argsWithoutParams),
|
|
491
|
-
JSON.stringify(params)
|
|
492
|
-
]);
|
|
493
|
-
return React__namespace.useMemo(() => [
|
|
494
|
-
state.data,
|
|
495
|
-
{
|
|
496
|
-
state: state.state,
|
|
497
|
-
error: state.error
|
|
498
|
-
}
|
|
499
|
-
], [state]);
|
|
500
|
-
};
|
|
501
|
-
|
|
502
|
-
const usePrismicPreviewResolver = (args = {}) => {
|
|
503
|
-
const context = usePrismicContext();
|
|
504
|
-
const linkResolver = args.linkResolver || context.linkResolver;
|
|
505
|
-
const result = useStatefulPrismicClientMethod("resolvePreviewURL", [
|
|
506
|
-
{
|
|
507
|
-
linkResolver,
|
|
508
|
-
defaultURL: args.defaultURL || "/",
|
|
509
|
-
previewToken: args.previewToken,
|
|
510
|
-
documentID: args.documentID
|
|
511
|
-
}
|
|
512
|
-
], args.client);
|
|
513
|
-
const [resolvedURL] = result;
|
|
514
|
-
const { navigate } = args;
|
|
515
|
-
React__namespace.useEffect(() => {
|
|
516
|
-
if (resolvedURL && navigate) {
|
|
517
|
-
navigate(resolvedURL);
|
|
518
|
-
}
|
|
519
|
-
}, [resolvedURL, navigate]);
|
|
520
|
-
return result;
|
|
521
|
-
};
|
|
522
|
-
|
|
523
|
-
const usePrismicDocuments = (...args) => useStatefulPrismicClientMethod("get", args);
|
|
524
|
-
const useFirstPrismicDocument = (...args) => useStatefulPrismicClientMethod("getFirst", args);
|
|
525
|
-
const useAllPrismicDocumentsDangerously = (...args) => useStatefulPrismicClientMethod("dangerouslyGetAll", args);
|
|
526
|
-
const usePrismicDocumentByID = (...args) => useStatefulPrismicClientMethod("getByID", args);
|
|
527
|
-
const usePrismicDocumentsByIDs = (...args) => useStatefulPrismicClientMethod("getByIDs", args);
|
|
528
|
-
const useAllPrismicDocumentsByIDs = (...args) => useStatefulPrismicClientMethod("getAllByIDs", args);
|
|
529
|
-
const usePrismicDocumentByUID = (...args) => useStatefulPrismicClientMethod("getByUID", args);
|
|
530
|
-
const usePrismicDocumentsByUIDs = (...args) => useStatefulPrismicClientMethod("getByUIDs", args);
|
|
531
|
-
const useAllPrismicDocumentsByUIDs = (...args) => useStatefulPrismicClientMethod("getAllByUIDs", args);
|
|
532
|
-
const useSinglePrismicDocument = (...args) => useStatefulPrismicClientMethod("getSingle", args);
|
|
533
|
-
const usePrismicDocumentsByType = (...args) => useStatefulPrismicClientMethod("getByType", args);
|
|
534
|
-
const useAllPrismicDocumentsByType = (...args) => useStatefulPrismicClientMethod("getAllByType", args);
|
|
535
|
-
const usePrismicDocumentsByTag = (...args) => useStatefulPrismicClientMethod("getByTag", args);
|
|
536
|
-
const useAllPrismicDocumentsByTag = (...args) => useStatefulPrismicClientMethod("getAllByTag", args);
|
|
537
|
-
const usePrismicDocumentsBySomeTags = (...args) => useStatefulPrismicClientMethod("getBySomeTags", args);
|
|
538
|
-
const useAllPrismicDocumentsBySomeTags = (...args) => useStatefulPrismicClientMethod("getAllBySomeTags", args);
|
|
539
|
-
const usePrismicDocumentsByEveryTag = (...args) => useStatefulPrismicClientMethod("getByEveryTag", args);
|
|
540
|
-
const useAllPrismicDocumentsByEveryTag = (...args) => useStatefulPrismicClientMethod("getAllByEveryTag", args);
|
|
541
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const PrismicProvider = require("./PrismicProvider.cjs");
|
|
4
|
+
const usePrismicContext = require("./usePrismicContext.cjs");
|
|
5
|
+
const usePrismicClient = require("./usePrismicClient.cjs");
|
|
6
|
+
const PrismicLink = require("./PrismicLink.cjs");
|
|
7
|
+
const PrismicText = require("./PrismicText.cjs");
|
|
8
|
+
const PrismicRichText = require("./PrismicRichText.cjs");
|
|
9
|
+
const prismicR = require("@prismicio/richtext");
|
|
10
|
+
const PrismicImage = require("./PrismicImage.cjs");
|
|
11
|
+
const SliceZone = require("./SliceZone.cjs");
|
|
12
|
+
const PrismicToolbar = require("./PrismicToolbar.cjs");
|
|
13
|
+
const usePrismicPreviewResolver = require("./usePrismicPreviewResolver.cjs");
|
|
14
|
+
const clientHooks = require("./clientHooks.cjs");
|
|
542
15
|
const Elements = prismicR.Element;
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
16
|
+
exports.PrismicProvider = PrismicProvider.PrismicProvider;
|
|
17
|
+
exports.usePrismicContext = usePrismicContext.usePrismicContext;
|
|
18
|
+
exports.usePrismicClient = usePrismicClient.usePrismicClient;
|
|
19
|
+
exports.PrismicLink = PrismicLink.PrismicLink;
|
|
20
|
+
exports.PrismicText = PrismicText.PrismicText;
|
|
21
|
+
exports.PrismicRichText = PrismicRichText.PrismicRichText;
|
|
22
|
+
Object.defineProperty(exports, "Element", {
|
|
23
|
+
enumerable: true,
|
|
24
|
+
get: () => prismicR.Element
|
|
547
25
|
});
|
|
26
|
+
exports.PrismicImage = PrismicImage.PrismicImage;
|
|
27
|
+
exports.SliceZone = SliceZone.SliceZone;
|
|
28
|
+
exports.TODOSliceComponent = SliceZone.TODOSliceComponent;
|
|
29
|
+
exports.PrismicToolbar = PrismicToolbar.PrismicToolbar;
|
|
30
|
+
exports.usePrismicPreviewResolver = usePrismicPreviewResolver.usePrismicPreviewResolver;
|
|
31
|
+
exports.useAllPrismicDocumentsByEveryTag = clientHooks.useAllPrismicDocumentsByEveryTag;
|
|
32
|
+
exports.useAllPrismicDocumentsByIDs = clientHooks.useAllPrismicDocumentsByIDs;
|
|
33
|
+
exports.useAllPrismicDocumentsBySomeTags = clientHooks.useAllPrismicDocumentsBySomeTags;
|
|
34
|
+
exports.useAllPrismicDocumentsByTag = clientHooks.useAllPrismicDocumentsByTag;
|
|
35
|
+
exports.useAllPrismicDocumentsByType = clientHooks.useAllPrismicDocumentsByType;
|
|
36
|
+
exports.useAllPrismicDocumentsByUIDs = clientHooks.useAllPrismicDocumentsByUIDs;
|
|
37
|
+
exports.useAllPrismicDocumentsDangerously = clientHooks.useAllPrismicDocumentsDangerously;
|
|
38
|
+
exports.useFirstPrismicDocument = clientHooks.useFirstPrismicDocument;
|
|
39
|
+
exports.usePrismicDocumentByID = clientHooks.usePrismicDocumentByID;
|
|
40
|
+
exports.usePrismicDocumentByUID = clientHooks.usePrismicDocumentByUID;
|
|
41
|
+
exports.usePrismicDocuments = clientHooks.usePrismicDocuments;
|
|
42
|
+
exports.usePrismicDocumentsByEveryTag = clientHooks.usePrismicDocumentsByEveryTag;
|
|
43
|
+
exports.usePrismicDocumentsByIDs = clientHooks.usePrismicDocumentsByIDs;
|
|
44
|
+
exports.usePrismicDocumentsBySomeTags = clientHooks.usePrismicDocumentsBySomeTags;
|
|
45
|
+
exports.usePrismicDocumentsByTag = clientHooks.usePrismicDocumentsByTag;
|
|
46
|
+
exports.usePrismicDocumentsByType = clientHooks.usePrismicDocumentsByType;
|
|
47
|
+
exports.usePrismicDocumentsByUIDs = clientHooks.usePrismicDocumentsByUIDs;
|
|
48
|
+
exports.useSinglePrismicDocument = clientHooks.useSinglePrismicDocument;
|
|
548
49
|
exports.Elements = Elements;
|
|
549
|
-
exports.PrismicImage = PrismicImage;
|
|
550
|
-
exports.PrismicLink = PrismicLink;
|
|
551
|
-
exports.PrismicProvider = PrismicProvider;
|
|
552
|
-
exports.PrismicRichText = PrismicRichText;
|
|
553
|
-
exports.PrismicText = PrismicText;
|
|
554
|
-
exports.PrismicToolbar = PrismicToolbar;
|
|
555
|
-
exports.SliceZone = SliceZone;
|
|
556
|
-
exports.TODOSliceComponent = TODOSliceComponent;
|
|
557
|
-
exports.useAllPrismicDocumentsByEveryTag = useAllPrismicDocumentsByEveryTag;
|
|
558
|
-
exports.useAllPrismicDocumentsByIDs = useAllPrismicDocumentsByIDs;
|
|
559
|
-
exports.useAllPrismicDocumentsBySomeTags = useAllPrismicDocumentsBySomeTags;
|
|
560
|
-
exports.useAllPrismicDocumentsByTag = useAllPrismicDocumentsByTag;
|
|
561
|
-
exports.useAllPrismicDocumentsByType = useAllPrismicDocumentsByType;
|
|
562
|
-
exports.useAllPrismicDocumentsByUIDs = useAllPrismicDocumentsByUIDs;
|
|
563
|
-
exports.useAllPrismicDocumentsDangerously = useAllPrismicDocumentsDangerously;
|
|
564
|
-
exports.useFirstPrismicDocument = useFirstPrismicDocument;
|
|
565
|
-
exports.usePrismicClient = usePrismicClient;
|
|
566
|
-
exports.usePrismicContext = usePrismicContext;
|
|
567
|
-
exports.usePrismicDocumentByID = usePrismicDocumentByID;
|
|
568
|
-
exports.usePrismicDocumentByUID = usePrismicDocumentByUID;
|
|
569
|
-
exports.usePrismicDocuments = usePrismicDocuments;
|
|
570
|
-
exports.usePrismicDocumentsByEveryTag = usePrismicDocumentsByEveryTag;
|
|
571
|
-
exports.usePrismicDocumentsByIDs = usePrismicDocumentsByIDs;
|
|
572
|
-
exports.usePrismicDocumentsBySomeTags = usePrismicDocumentsBySomeTags;
|
|
573
|
-
exports.usePrismicDocumentsByTag = usePrismicDocumentsByTag;
|
|
574
|
-
exports.usePrismicDocumentsByType = usePrismicDocumentsByType;
|
|
575
|
-
exports.usePrismicDocumentsByUIDs = usePrismicDocumentsByUIDs;
|
|
576
|
-
exports.usePrismicPreviewResolver = usePrismicPreviewResolver;
|
|
577
|
-
exports.useSinglePrismicDocument = useSinglePrismicDocument;
|
|
578
50
|
//# sourceMappingURL=index.cjs.map
|