@prismicio/react 2.0.3-debug.2 → 2.0.5
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.cjs +23 -17
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +429 -0
- package/dist/index.mjs +23 -18
- package/dist/index.mjs.map +1 -1
- package/package.json +14 -11
- package/src/PrismicProvider.tsx +2 -3
- package/src/PrismicRichText.tsx +23 -11
- package/src/PrismicText.tsx +1 -2
- package/src/PrismicToolbar.tsx +2 -2
- package/src/SliceZone.tsx +2 -3
- package/src/usePrismicContext.ts +2 -2
- package/src/usePrismicPreviewResolver.ts +2 -2
- package/src/useStatefulPrismicClientMethod.ts +4 -4
package/dist/index.js
ADDED
|
@@ -0,0 +1,429 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import * as prismicH from '@prismicio/helpers';
|
|
3
|
+
import * as prismicR from '@prismicio/richtext';
|
|
4
|
+
import { Element } from '@prismicio/richtext';
|
|
5
|
+
export { Element } from '@prismicio/richtext';
|
|
6
|
+
|
|
7
|
+
const PrismicContext = React.createContext({});
|
|
8
|
+
const PrismicProvider = ({
|
|
9
|
+
client,
|
|
10
|
+
linkResolver,
|
|
11
|
+
richTextComponents,
|
|
12
|
+
internalLinkComponent,
|
|
13
|
+
externalLinkComponent,
|
|
14
|
+
children
|
|
15
|
+
}) => {
|
|
16
|
+
const value = React.useMemo(() => ({
|
|
17
|
+
client,
|
|
18
|
+
linkResolver,
|
|
19
|
+
richTextComponents,
|
|
20
|
+
internalLinkComponent,
|
|
21
|
+
externalLinkComponent
|
|
22
|
+
}), [
|
|
23
|
+
client,
|
|
24
|
+
linkResolver,
|
|
25
|
+
richTextComponents,
|
|
26
|
+
internalLinkComponent,
|
|
27
|
+
externalLinkComponent
|
|
28
|
+
]);
|
|
29
|
+
return /* @__PURE__ */ React.createElement(PrismicContext.Provider, {
|
|
30
|
+
value
|
|
31
|
+
}, children);
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const usePrismicContext = () => {
|
|
35
|
+
return React.useContext(PrismicContext) || {};
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
if (typeof process === "undefined") {
|
|
39
|
+
globalThis.process = { env: {} };
|
|
40
|
+
}
|
|
41
|
+
const __PRODUCTION__ = process.env.NODE_ENV === "production";
|
|
42
|
+
|
|
43
|
+
const prefix = "Invariant failed";
|
|
44
|
+
function invariant(condition, message) {
|
|
45
|
+
if (condition) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
if (__PRODUCTION__) {
|
|
49
|
+
throw new Error(prefix);
|
|
50
|
+
}
|
|
51
|
+
throw new Error(`${prefix}: ${message || ""}`);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const usePrismicClient = (explicitClient) => {
|
|
55
|
+
const context = usePrismicContext();
|
|
56
|
+
const client = explicitClient || (context == null ? void 0 : context.client);
|
|
57
|
+
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.");
|
|
58
|
+
return client;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const isInternalURL = (url) => {
|
|
62
|
+
const isInternal = /^(\/(?!\/)|#)/.test(url);
|
|
63
|
+
const isSpecialLink = !isInternal && !/^https?:\/\//.test(url);
|
|
64
|
+
return isInternal && !isSpecialLink;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
const defaultInternalComponent = "a";
|
|
68
|
+
const defaultExternalComponent = "a";
|
|
69
|
+
const PrismicLink = (props) => {
|
|
70
|
+
const context = usePrismicContext();
|
|
71
|
+
const linkResolver = props.linkResolver || context.linkResolver;
|
|
72
|
+
let href;
|
|
73
|
+
if ("href" in props) {
|
|
74
|
+
href = props.href;
|
|
75
|
+
} else if ("document" in props && props.document) {
|
|
76
|
+
href = prismicH.asLink(props.document, linkResolver);
|
|
77
|
+
} else if ("field" in props && props.field) {
|
|
78
|
+
href = prismicH.asLink(props.field, linkResolver);
|
|
79
|
+
}
|
|
80
|
+
const target = props.target || "field" in props && props.field && "target" in props.field && props.field.target || void 0;
|
|
81
|
+
const rel = props.rel || (target === "_blank" ? "noopener noreferrer" : void 0);
|
|
82
|
+
const InternalComponent = props.internalComponent || context.internalLinkComponent || defaultInternalComponent;
|
|
83
|
+
const ExternalComponent = props.externalComponent || context.externalLinkComponent || defaultExternalComponent;
|
|
84
|
+
const isInternal = href && isInternalURL(href);
|
|
85
|
+
const Component = isInternal ? InternalComponent : ExternalComponent;
|
|
86
|
+
const passthroughProps = Object.assign({}, props);
|
|
87
|
+
delete passthroughProps.linkResolver;
|
|
88
|
+
delete passthroughProps.internalComponent;
|
|
89
|
+
delete passthroughProps.externalComponent;
|
|
90
|
+
delete passthroughProps.rel;
|
|
91
|
+
delete passthroughProps.target;
|
|
92
|
+
if ("field" in passthroughProps) {
|
|
93
|
+
delete passthroughProps.field;
|
|
94
|
+
} else if ("document" in passthroughProps) {
|
|
95
|
+
delete passthroughProps.document;
|
|
96
|
+
} else if ("href" in passthroughProps) {
|
|
97
|
+
delete passthroughProps.href;
|
|
98
|
+
}
|
|
99
|
+
return href ? /* @__PURE__ */ React.createElement(Component, {
|
|
100
|
+
...passthroughProps,
|
|
101
|
+
href,
|
|
102
|
+
target,
|
|
103
|
+
rel
|
|
104
|
+
}) : null;
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
const PrismicText = (props) => {
|
|
108
|
+
return React.useMemo(() => {
|
|
109
|
+
if (props.field) {
|
|
110
|
+
const text = prismicH.asText(props.field, props.separator);
|
|
111
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, null, text);
|
|
112
|
+
} else {
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
}, [props.field, props.separator]);
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
const createDefaultSerializer = (args) => prismicR.wrapMapSerializer({
|
|
119
|
+
heading1: ({ children, key }) => /* @__PURE__ */ React.createElement("h1", {
|
|
120
|
+
key
|
|
121
|
+
}, children),
|
|
122
|
+
heading2: ({ children, key }) => /* @__PURE__ */ React.createElement("h2", {
|
|
123
|
+
key
|
|
124
|
+
}, children),
|
|
125
|
+
heading3: ({ children, key }) => /* @__PURE__ */ React.createElement("h3", {
|
|
126
|
+
key
|
|
127
|
+
}, children),
|
|
128
|
+
heading4: ({ children, key }) => /* @__PURE__ */ React.createElement("h4", {
|
|
129
|
+
key
|
|
130
|
+
}, children),
|
|
131
|
+
heading5: ({ children, key }) => /* @__PURE__ */ React.createElement("h5", {
|
|
132
|
+
key
|
|
133
|
+
}, children),
|
|
134
|
+
heading6: ({ children, key }) => /* @__PURE__ */ React.createElement("h6", {
|
|
135
|
+
key
|
|
136
|
+
}, children),
|
|
137
|
+
paragraph: ({ children, key }) => /* @__PURE__ */ React.createElement("p", {
|
|
138
|
+
key
|
|
139
|
+
}, children),
|
|
140
|
+
preformatted: ({ node, key }) => /* @__PURE__ */ React.createElement("pre", {
|
|
141
|
+
key
|
|
142
|
+
}, node.text),
|
|
143
|
+
strong: ({ children, key }) => /* @__PURE__ */ React.createElement("strong", {
|
|
144
|
+
key
|
|
145
|
+
}, children),
|
|
146
|
+
em: ({ children, key }) => /* @__PURE__ */ React.createElement("em", {
|
|
147
|
+
key
|
|
148
|
+
}, children),
|
|
149
|
+
listItem: ({ children, key }) => /* @__PURE__ */ React.createElement("li", {
|
|
150
|
+
key
|
|
151
|
+
}, children),
|
|
152
|
+
oListItem: ({ children, key }) => /* @__PURE__ */ React.createElement("li", {
|
|
153
|
+
key
|
|
154
|
+
}, children),
|
|
155
|
+
list: ({ children, key }) => /* @__PURE__ */ React.createElement("ul", {
|
|
156
|
+
key
|
|
157
|
+
}, children),
|
|
158
|
+
oList: ({ children, key }) => /* @__PURE__ */ React.createElement("ol", {
|
|
159
|
+
key
|
|
160
|
+
}, children),
|
|
161
|
+
image: ({ node, key }) => {
|
|
162
|
+
var _a;
|
|
163
|
+
const img = /* @__PURE__ */ React.createElement("img", {
|
|
164
|
+
src: node.url,
|
|
165
|
+
alt: (_a = node.alt) != null ? _a : void 0,
|
|
166
|
+
"data-copyright": node.copyright ? node.copyright : void 0
|
|
167
|
+
});
|
|
168
|
+
return /* @__PURE__ */ React.createElement("p", {
|
|
169
|
+
key,
|
|
170
|
+
className: "block-img"
|
|
171
|
+
}, node.linkTo ? /* @__PURE__ */ React.createElement(PrismicLink, {
|
|
172
|
+
linkResolver: args.linkResolver,
|
|
173
|
+
internalComponent: args.internalLinkComponent,
|
|
174
|
+
externalComponent: args.externalLinkComponent,
|
|
175
|
+
field: node.linkTo
|
|
176
|
+
}, img) : img);
|
|
177
|
+
},
|
|
178
|
+
embed: ({ node, key }) => {
|
|
179
|
+
var _a;
|
|
180
|
+
return /* @__PURE__ */ React.createElement("div", {
|
|
181
|
+
key,
|
|
182
|
+
"data-oembed": node.oembed.embed_url,
|
|
183
|
+
"data-oembed-type": node.oembed.type,
|
|
184
|
+
"data-oembed-provider": node.oembed.provider_name,
|
|
185
|
+
dangerouslySetInnerHTML: { __html: (_a = node.oembed.html) != null ? _a : "" }
|
|
186
|
+
});
|
|
187
|
+
},
|
|
188
|
+
hyperlink: ({ node, children, key }) => /* @__PURE__ */ React.createElement(PrismicLink, {
|
|
189
|
+
key,
|
|
190
|
+
field: node.data,
|
|
191
|
+
linkResolver: args.linkResolver,
|
|
192
|
+
internalComponent: args.internalLinkComponent,
|
|
193
|
+
externalComponent: args.externalLinkComponent
|
|
194
|
+
}, children),
|
|
195
|
+
label: ({ node, children, key }) => /* @__PURE__ */ React.createElement("span", {
|
|
196
|
+
key,
|
|
197
|
+
className: node.data.label
|
|
198
|
+
}, children),
|
|
199
|
+
span: ({ text, key }) => {
|
|
200
|
+
const result = [];
|
|
201
|
+
let i = 0;
|
|
202
|
+
for (const line of text.split("\n")) {
|
|
203
|
+
if (i > 0) {
|
|
204
|
+
result.push(/* @__PURE__ */ React.createElement("br", {
|
|
205
|
+
key: `${i}__break`
|
|
206
|
+
}));
|
|
207
|
+
}
|
|
208
|
+
result.push(/* @__PURE__ */ React.createElement(React.Fragment, {
|
|
209
|
+
key: `${i}__line`
|
|
210
|
+
}, line));
|
|
211
|
+
i++;
|
|
212
|
+
}
|
|
213
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, {
|
|
214
|
+
key
|
|
215
|
+
}, result);
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
const PrismicRichText = (props) => {
|
|
219
|
+
const context = usePrismicContext();
|
|
220
|
+
return React.useMemo(() => {
|
|
221
|
+
if (!props.field) {
|
|
222
|
+
return null;
|
|
223
|
+
} else {
|
|
224
|
+
const linkResolver = props.linkResolver || context.linkResolver;
|
|
225
|
+
const serializer = prismicR.composeSerializers(typeof props.components === "object" ? prismicR.wrapMapSerializer(props.components) : props.components, typeof context.richTextComponents === "object" ? prismicR.wrapMapSerializer(context.richTextComponents) : context.richTextComponents, createDefaultSerializer({
|
|
226
|
+
linkResolver,
|
|
227
|
+
internalLinkComponent: props.internalLinkComponent,
|
|
228
|
+
externalLinkComponent: props.externalLinkComponent
|
|
229
|
+
}));
|
|
230
|
+
const serialized = prismicR.serialize(props.field, (type, node, text, children, key) => {
|
|
231
|
+
const result = serializer(type, node, text, children, key);
|
|
232
|
+
if (React.isValidElement(result) && result.key == null) {
|
|
233
|
+
return React.cloneElement(result, { key });
|
|
234
|
+
} else {
|
|
235
|
+
return result;
|
|
236
|
+
}
|
|
237
|
+
});
|
|
238
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, null, serialized);
|
|
239
|
+
}
|
|
240
|
+
}, [
|
|
241
|
+
props.field,
|
|
242
|
+
props.internalLinkComponent,
|
|
243
|
+
props.externalLinkComponent,
|
|
244
|
+
props.components,
|
|
245
|
+
props.linkResolver,
|
|
246
|
+
context.linkResolver,
|
|
247
|
+
context.richTextComponents
|
|
248
|
+
]);
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
const pascalCase = (input) => {
|
|
252
|
+
const camelCased = input.replace(/(?:-|_)(\w)/g, (_, c) => {
|
|
253
|
+
return c ? c.toUpperCase() : "";
|
|
254
|
+
});
|
|
255
|
+
return camelCased[0].toUpperCase() + camelCased.slice(1);
|
|
256
|
+
};
|
|
257
|
+
|
|
258
|
+
const TODOSliceComponent = __PRODUCTION__ ? () => null : ({
|
|
259
|
+
slice
|
|
260
|
+
}) => {
|
|
261
|
+
React.useEffect(() => {
|
|
262
|
+
console.warn(`[SliceZone] Could not find a component for Slice type "${slice.slice_type}"`, slice);
|
|
263
|
+
}, [slice]);
|
|
264
|
+
return /* @__PURE__ */ React.createElement("section", {
|
|
265
|
+
"data-slice-zone-todo-component": "",
|
|
266
|
+
"data-slice-type": slice.slice_type
|
|
267
|
+
}, "Could not find a component for Slice type \u201C", slice.slice_type, "\u201D");
|
|
268
|
+
};
|
|
269
|
+
const SliceZone = ({
|
|
270
|
+
slices = [],
|
|
271
|
+
components = {},
|
|
272
|
+
resolver,
|
|
273
|
+
defaultComponent = TODOSliceComponent,
|
|
274
|
+
context = {}
|
|
275
|
+
}) => {
|
|
276
|
+
const renderedSlices = React.useMemo(() => {
|
|
277
|
+
return slices.map((slice, index) => {
|
|
278
|
+
let Comp = components[slice.slice_type] || defaultComponent;
|
|
279
|
+
if (resolver) {
|
|
280
|
+
const resolvedComp = resolver({
|
|
281
|
+
slice,
|
|
282
|
+
sliceName: pascalCase(slice.slice_type),
|
|
283
|
+
i: index
|
|
284
|
+
});
|
|
285
|
+
if (resolvedComp) {
|
|
286
|
+
Comp = resolvedComp;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
const key = `${index}-${JSON.stringify(slice)}`;
|
|
290
|
+
return /* @__PURE__ */ React.createElement(Comp, {
|
|
291
|
+
key,
|
|
292
|
+
slice,
|
|
293
|
+
index,
|
|
294
|
+
slices,
|
|
295
|
+
context
|
|
296
|
+
});
|
|
297
|
+
});
|
|
298
|
+
}, [components, context, defaultComponent, slices, resolver]);
|
|
299
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, null, renderedSlices);
|
|
300
|
+
};
|
|
301
|
+
|
|
302
|
+
const PrismicToolbar = ({
|
|
303
|
+
repositoryName,
|
|
304
|
+
type = "new"
|
|
305
|
+
}) => {
|
|
306
|
+
const src = `https://static.cdn.prismic.io/prismic.js?repo=${repositoryName}${type === "new" ? "&new=true" : ""}`;
|
|
307
|
+
React.useEffect(() => {
|
|
308
|
+
const existingScript = document.querySelector(`script[src="${src}"]`);
|
|
309
|
+
if (!existingScript) {
|
|
310
|
+
const script = document.createElement("script");
|
|
311
|
+
script.src = src;
|
|
312
|
+
script.defer = true;
|
|
313
|
+
script.dataset.prismicToolbar = "";
|
|
314
|
+
script.dataset.repositoryName = repositoryName;
|
|
315
|
+
script.dataset.type = type;
|
|
316
|
+
document.body.appendChild(script);
|
|
317
|
+
}
|
|
318
|
+
}, [repositoryName, type, src]);
|
|
319
|
+
return null;
|
|
320
|
+
};
|
|
321
|
+
|
|
322
|
+
const reducer = (state, action) => {
|
|
323
|
+
switch (action[0]) {
|
|
324
|
+
case "start": {
|
|
325
|
+
return { state: "loading" };
|
|
326
|
+
}
|
|
327
|
+
case "succeed": {
|
|
328
|
+
return { state: "loaded", data: action[1] };
|
|
329
|
+
}
|
|
330
|
+
case "fail": {
|
|
331
|
+
return {
|
|
332
|
+
...state,
|
|
333
|
+
state: "failed",
|
|
334
|
+
error: action[1]
|
|
335
|
+
};
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
};
|
|
339
|
+
const initialState = {
|
|
340
|
+
state: "idle"
|
|
341
|
+
};
|
|
342
|
+
const isParams = (value) => {
|
|
343
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
344
|
+
};
|
|
345
|
+
const useStatefulPrismicClientMethod = (methodName, args, explicitClient) => {
|
|
346
|
+
const lastArg = args[args.length - 1];
|
|
347
|
+
const {
|
|
348
|
+
client: lastArgExplicitClient,
|
|
349
|
+
skip,
|
|
350
|
+
...params
|
|
351
|
+
} = isParams(lastArg) ? lastArg : {};
|
|
352
|
+
const argsWithoutParams = isParams(lastArg) ? args.slice(0, -1) : args;
|
|
353
|
+
const client = usePrismicClient(explicitClient || lastArgExplicitClient);
|
|
354
|
+
const [state, dispatch] = React.useReducer(reducer, initialState);
|
|
355
|
+
React.useEffect(() => {
|
|
356
|
+
if (!skip) {
|
|
357
|
+
{
|
|
358
|
+
dispatch(["start"]);
|
|
359
|
+
}
|
|
360
|
+
client[methodName].call(client, ...argsWithoutParams, params).then((result) => {
|
|
361
|
+
{
|
|
362
|
+
dispatch(["succeed", result]);
|
|
363
|
+
}
|
|
364
|
+
}).catch((error) => {
|
|
365
|
+
{
|
|
366
|
+
dispatch(["fail", error]);
|
|
367
|
+
}
|
|
368
|
+
});
|
|
369
|
+
}
|
|
370
|
+
}, [
|
|
371
|
+
client,
|
|
372
|
+
methodName,
|
|
373
|
+
skip,
|
|
374
|
+
JSON.stringify(argsWithoutParams),
|
|
375
|
+
JSON.stringify(params)
|
|
376
|
+
]);
|
|
377
|
+
return React.useMemo(() => [
|
|
378
|
+
state.data,
|
|
379
|
+
{
|
|
380
|
+
state: state.state,
|
|
381
|
+
error: state.error
|
|
382
|
+
}
|
|
383
|
+
], [state]);
|
|
384
|
+
};
|
|
385
|
+
|
|
386
|
+
const usePrismicPreviewResolver = (args = {}) => {
|
|
387
|
+
const context = usePrismicContext();
|
|
388
|
+
const linkResolver = args.linkResolver || context.linkResolver;
|
|
389
|
+
const result = useStatefulPrismicClientMethod("resolvePreviewURL", [
|
|
390
|
+
{
|
|
391
|
+
linkResolver,
|
|
392
|
+
defaultURL: args.defaultURL || "/",
|
|
393
|
+
previewToken: args.previewToken,
|
|
394
|
+
documentID: args.documentID
|
|
395
|
+
}
|
|
396
|
+
], args.client);
|
|
397
|
+
const [resolvedURL] = result;
|
|
398
|
+
const { navigate } = args;
|
|
399
|
+
React.useEffect(() => {
|
|
400
|
+
if (resolvedURL && navigate) {
|
|
401
|
+
navigate(resolvedURL);
|
|
402
|
+
}
|
|
403
|
+
}, [resolvedURL, navigate]);
|
|
404
|
+
return result;
|
|
405
|
+
};
|
|
406
|
+
|
|
407
|
+
const usePrismicDocuments = (...args) => useStatefulPrismicClientMethod("get", args);
|
|
408
|
+
const useFirstPrismicDocument = (...args) => useStatefulPrismicClientMethod("getFirst", args);
|
|
409
|
+
const useAllPrismicDocumentsDangerously = (...args) => useStatefulPrismicClientMethod("dangerouslyGetAll", args);
|
|
410
|
+
const usePrismicDocumentByID = (...args) => useStatefulPrismicClientMethod("getByID", args);
|
|
411
|
+
const usePrismicDocumentsByIDs = (...args) => useStatefulPrismicClientMethod("getByIDs", args);
|
|
412
|
+
const useAllPrismicDocumentsByIDs = (...args) => useStatefulPrismicClientMethod("getAllByIDs", args);
|
|
413
|
+
const usePrismicDocumentByUID = (...args) => useStatefulPrismicClientMethod("getByUID", args);
|
|
414
|
+
const usePrismicDocumentsByUIDs = (...args) => useStatefulPrismicClientMethod("getByUIDs", args);
|
|
415
|
+
const useAllPrismicDocumentsByUIDs = (...args) => useStatefulPrismicClientMethod("getAllByUIDs", args);
|
|
416
|
+
const useSinglePrismicDocument = (...args) => useStatefulPrismicClientMethod("getSingle", args);
|
|
417
|
+
const usePrismicDocumentsByType = (...args) => useStatefulPrismicClientMethod("getByType", args);
|
|
418
|
+
const useAllPrismicDocumentsByType = (...args) => useStatefulPrismicClientMethod("getAllByType", args);
|
|
419
|
+
const usePrismicDocumentsByTag = (...args) => useStatefulPrismicClientMethod("getByTag", args);
|
|
420
|
+
const useAllPrismicDocumentsByTag = (...args) => useStatefulPrismicClientMethod("getAllByTag", args);
|
|
421
|
+
const usePrismicDocumentsBySomeTags = (...args) => useStatefulPrismicClientMethod("getBySomeTags", args);
|
|
422
|
+
const useAllPrismicDocumentsBySomeTags = (...args) => useStatefulPrismicClientMethod("getAllBySomeTags", args);
|
|
423
|
+
const usePrismicDocumentsByEveryTag = (...args) => useStatefulPrismicClientMethod("getByEveryTag", args);
|
|
424
|
+
const useAllPrismicDocumentsByEveryTag = (...args) => useStatefulPrismicClientMethod("getAllByEveryTag", args);
|
|
425
|
+
|
|
426
|
+
const Elements = Element;
|
|
427
|
+
|
|
428
|
+
export { Elements, PrismicLink, PrismicProvider, PrismicRichText, PrismicText, PrismicToolbar, SliceZone, TODOSliceComponent, useAllPrismicDocumentsByEveryTag, useAllPrismicDocumentsByIDs, useAllPrismicDocumentsBySomeTags, useAllPrismicDocumentsByTag, useAllPrismicDocumentsByType, useAllPrismicDocumentsByUIDs, useAllPrismicDocumentsDangerously, useFirstPrismicDocument, usePrismicClient, usePrismicContext, usePrismicDocumentByID, usePrismicDocumentByUID, usePrismicDocuments, usePrismicDocumentsByEveryTag, usePrismicDocumentsByIDs, usePrismicDocumentsBySomeTags, usePrismicDocumentsByTag, usePrismicDocumentsByType, usePrismicDocumentsByUIDs, usePrismicPreviewResolver, useSinglePrismicDocument };
|
|
429
|
+
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { createContext, useMemo, useContext, Fragment, useEffect, useReducer } from 'react';
|
|
3
2
|
import * as prismicH from '@prismicio/helpers';
|
|
4
3
|
import * as prismicR from '@prismicio/richtext';
|
|
5
4
|
import { Element } from '@prismicio/richtext';
|
|
6
5
|
export { Element } from '@prismicio/richtext';
|
|
7
6
|
|
|
8
|
-
const PrismicContext = createContext({});
|
|
7
|
+
const PrismicContext = React.createContext({});
|
|
9
8
|
const PrismicProvider = ({
|
|
10
9
|
client,
|
|
11
10
|
linkResolver,
|
|
@@ -14,7 +13,7 @@ const PrismicProvider = ({
|
|
|
14
13
|
externalLinkComponent,
|
|
15
14
|
children
|
|
16
15
|
}) => {
|
|
17
|
-
const value = useMemo(() => ({
|
|
16
|
+
const value = React.useMemo(() => ({
|
|
18
17
|
client,
|
|
19
18
|
linkResolver,
|
|
20
19
|
richTextComponents,
|
|
@@ -33,7 +32,7 @@ const PrismicProvider = ({
|
|
|
33
32
|
};
|
|
34
33
|
|
|
35
34
|
const usePrismicContext = () => {
|
|
36
|
-
return useContext(PrismicContext) || {};
|
|
35
|
+
return React.useContext(PrismicContext) || {};
|
|
37
36
|
};
|
|
38
37
|
|
|
39
38
|
if (typeof process === "undefined") {
|
|
@@ -106,7 +105,7 @@ const PrismicLink = (props) => {
|
|
|
106
105
|
};
|
|
107
106
|
|
|
108
107
|
const PrismicText = (props) => {
|
|
109
|
-
return useMemo(() => {
|
|
108
|
+
return React.useMemo(() => {
|
|
110
109
|
if (props.field) {
|
|
111
110
|
const text = prismicH.asText(props.field, props.separator);
|
|
112
111
|
return /* @__PURE__ */ React.createElement(React.Fragment, null, text);
|
|
@@ -206,30 +205,36 @@ const createDefaultSerializer = (args) => prismicR.wrapMapSerializer({
|
|
|
206
205
|
key: `${i}__break`
|
|
207
206
|
}));
|
|
208
207
|
}
|
|
209
|
-
result.push(/* @__PURE__ */ React.createElement(Fragment, {
|
|
208
|
+
result.push(/* @__PURE__ */ React.createElement(React.Fragment, {
|
|
210
209
|
key: `${i}__line`
|
|
211
210
|
}, line));
|
|
212
211
|
i++;
|
|
213
212
|
}
|
|
214
|
-
return /* @__PURE__ */ React.createElement(Fragment, {
|
|
213
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, {
|
|
215
214
|
key
|
|
216
215
|
}, result);
|
|
217
216
|
}
|
|
218
217
|
});
|
|
219
218
|
const PrismicRichText = (props) => {
|
|
220
219
|
const context = usePrismicContext();
|
|
221
|
-
return useMemo(() => {
|
|
220
|
+
return React.useMemo(() => {
|
|
222
221
|
if (!props.field) {
|
|
223
222
|
return null;
|
|
224
223
|
} else {
|
|
225
224
|
const linkResolver = props.linkResolver || context.linkResolver;
|
|
226
|
-
const
|
|
225
|
+
const serializer = prismicR.composeSerializers(typeof props.components === "object" ? prismicR.wrapMapSerializer(props.components) : props.components, typeof context.richTextComponents === "object" ? prismicR.wrapMapSerializer(context.richTextComponents) : context.richTextComponents, createDefaultSerializer({
|
|
227
226
|
linkResolver,
|
|
228
227
|
internalLinkComponent: props.internalLinkComponent,
|
|
229
228
|
externalLinkComponent: props.externalLinkComponent
|
|
229
|
+
}));
|
|
230
|
+
const serialized = prismicR.serialize(props.field, (type, node, text, children, key) => {
|
|
231
|
+
const result = serializer(type, node, text, children, key);
|
|
232
|
+
if (React.isValidElement(result) && result.key == null) {
|
|
233
|
+
return React.cloneElement(result, { key });
|
|
234
|
+
} else {
|
|
235
|
+
return result;
|
|
236
|
+
}
|
|
230
237
|
});
|
|
231
|
-
const serializer = prismicR.composeSerializers(typeof props.components === "object" ? prismicR.wrapMapSerializer(props.components) : props.components, typeof context.richTextComponents === "object" ? prismicR.wrapMapSerializer(context.richTextComponents) : context.richTextComponents, defaultSerializer);
|
|
232
|
-
const serialized = prismicR.serialize(props.field, serializer);
|
|
233
238
|
return /* @__PURE__ */ React.createElement(React.Fragment, null, serialized);
|
|
234
239
|
}
|
|
235
240
|
}, [
|
|
@@ -253,7 +258,7 @@ const pascalCase = (input) => {
|
|
|
253
258
|
const TODOSliceComponent = __PRODUCTION__ ? () => null : ({
|
|
254
259
|
slice
|
|
255
260
|
}) => {
|
|
256
|
-
useEffect(() => {
|
|
261
|
+
React.useEffect(() => {
|
|
257
262
|
console.warn(`[SliceZone] Could not find a component for Slice type "${slice.slice_type}"`, slice);
|
|
258
263
|
}, [slice]);
|
|
259
264
|
return /* @__PURE__ */ React.createElement("section", {
|
|
@@ -268,7 +273,7 @@ const SliceZone = ({
|
|
|
268
273
|
defaultComponent = TODOSliceComponent,
|
|
269
274
|
context = {}
|
|
270
275
|
}) => {
|
|
271
|
-
const renderedSlices = useMemo(() => {
|
|
276
|
+
const renderedSlices = React.useMemo(() => {
|
|
272
277
|
return slices.map((slice, index) => {
|
|
273
278
|
let Comp = components[slice.slice_type] || defaultComponent;
|
|
274
279
|
if (resolver) {
|
|
@@ -299,7 +304,7 @@ const PrismicToolbar = ({
|
|
|
299
304
|
type = "new"
|
|
300
305
|
}) => {
|
|
301
306
|
const src = `https://static.cdn.prismic.io/prismic.js?repo=${repositoryName}${type === "new" ? "&new=true" : ""}`;
|
|
302
|
-
useEffect(() => {
|
|
307
|
+
React.useEffect(() => {
|
|
303
308
|
const existingScript = document.querySelector(`script[src="${src}"]`);
|
|
304
309
|
if (!existingScript) {
|
|
305
310
|
const script = document.createElement("script");
|
|
@@ -346,8 +351,8 @@ const useStatefulPrismicClientMethod = (methodName, args, explicitClient) => {
|
|
|
346
351
|
} = isParams(lastArg) ? lastArg : {};
|
|
347
352
|
const argsWithoutParams = isParams(lastArg) ? args.slice(0, -1) : args;
|
|
348
353
|
const client = usePrismicClient(explicitClient || lastArgExplicitClient);
|
|
349
|
-
const [state, dispatch] = useReducer(reducer, initialState);
|
|
350
|
-
useEffect(() => {
|
|
354
|
+
const [state, dispatch] = React.useReducer(reducer, initialState);
|
|
355
|
+
React.useEffect(() => {
|
|
351
356
|
if (!skip) {
|
|
352
357
|
{
|
|
353
358
|
dispatch(["start"]);
|
|
@@ -369,7 +374,7 @@ const useStatefulPrismicClientMethod = (methodName, args, explicitClient) => {
|
|
|
369
374
|
JSON.stringify(argsWithoutParams),
|
|
370
375
|
JSON.stringify(params)
|
|
371
376
|
]);
|
|
372
|
-
return useMemo(() => [
|
|
377
|
+
return React.useMemo(() => [
|
|
373
378
|
state.data,
|
|
374
379
|
{
|
|
375
380
|
state: state.state,
|
|
@@ -391,7 +396,7 @@ const usePrismicPreviewResolver = (args = {}) => {
|
|
|
391
396
|
], args.client);
|
|
392
397
|
const [resolvedURL] = result;
|
|
393
398
|
const { navigate } = args;
|
|
394
|
-
useEffect(() => {
|
|
399
|
+
React.useEffect(() => {
|
|
395
400
|
if (resolvedURL && navigate) {
|
|
396
401
|
navigate(resolvedURL);
|
|
397
402
|
}
|