@nuxtjs/prismic 3.0.0-alpha.7 → 3.0.0-alpha.8
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/module.json +1 -1
- package/dist/module.mjs +2 -1
- package/dist/runtime/plugin.client.d.ts +2 -0
- package/dist/runtime/plugin.client.mjs +13 -0
- package/dist/runtime/plugin.mjs +18 -2
- package/package.json +1 -1
- package/src/module.ts +1 -0
- package/src/runtime/plugin.client.ts +24 -0
- package/src/runtime/plugin.ts +31 -2
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -7,7 +7,7 @@ import { existsSync } from 'fs';
|
|
|
7
7
|
import consola from 'consola';
|
|
8
8
|
|
|
9
9
|
const name = "@nuxtjs/prismic";
|
|
10
|
-
const version = "3.0.0-alpha.
|
|
10
|
+
const version = "3.0.0-alpha.8";
|
|
11
11
|
|
|
12
12
|
const fileExists = (path, extensions = ["js", "ts"]) => {
|
|
13
13
|
if (!path) {
|
|
@@ -70,6 +70,7 @@ const module = defineNuxtModule({
|
|
|
70
70
|
(_a = nuxt.options.runtimeConfig).public || (_a.public = {});
|
|
71
71
|
nuxt.options.runtimeConfig.public[name] = mergedOptions;
|
|
72
72
|
addPlugin(resolver.resolve("runtime/plugin"));
|
|
73
|
+
addPlugin(resolver.resolve("runtime/plugin.client"));
|
|
73
74
|
if (mergedOptions.injectComponents) {
|
|
74
75
|
[
|
|
75
76
|
"PrismicEmbed",
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { defineNuxtPlugin } from "#app";
|
|
2
|
+
const pkgName = "@nuxtjs/prismic";
|
|
3
|
+
export default defineNuxtPlugin((nuxtApp) => {
|
|
4
|
+
const mergedOptions = nuxtApp.payload.config[pkgName] ?? nuxtApp.payload.config.public[pkgName] ?? {};
|
|
5
|
+
if (mergedOptions.preview) {
|
|
6
|
+
window.addEventListener("prismicPreviewUpdate", (event) => {
|
|
7
|
+
if (refreshNuxtData) {
|
|
8
|
+
event.preventDefault();
|
|
9
|
+
refreshNuxtData();
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
});
|
package/dist/runtime/plugin.mjs
CHANGED
|
@@ -7,7 +7,7 @@ import htmlSerializer from "#build/prismic/proxy/htmlSerializer";
|
|
|
7
7
|
const pkgName = "@nuxtjs/prismic";
|
|
8
8
|
export default defineNuxtPlugin((nuxtApp) => {
|
|
9
9
|
const mergedOptions = nuxtApp.payload.config[pkgName] ?? nuxtApp.payload.config.public[pkgName] ?? {};
|
|
10
|
-
|
|
10
|
+
const prismicPlugin = createPrismic({
|
|
11
11
|
...mergedOptions,
|
|
12
12
|
client,
|
|
13
13
|
linkResolver,
|
|
@@ -18,5 +18,21 @@ export default defineNuxtPlugin((nuxtApp) => {
|
|
|
18
18
|
linkExternalComponent: NuxtLink,
|
|
19
19
|
...mergedOptions.components
|
|
20
20
|
}
|
|
21
|
-
})
|
|
21
|
+
});
|
|
22
|
+
nuxtApp.vueApp.use(prismicPlugin);
|
|
23
|
+
if (mergedOptions.preview) {
|
|
24
|
+
const previewCookie = useCookie("io.prismic.preview").value;
|
|
25
|
+
if (process.server) {
|
|
26
|
+
prismicPlugin.client.enableAutoPreviewsFromReq(useRequestEvent()?.req);
|
|
27
|
+
}
|
|
28
|
+
if (previewCookie) {
|
|
29
|
+
try {
|
|
30
|
+
const session = typeof previewCookie === "string" ? JSON.parse(decodeURIComponent(previewCookie)) : previewCookie;
|
|
31
|
+
if (Object.keys(session).some((key) => key in session && typeof session[key] === "object" && session[key] !== null && "preview" in session[key] && session[key].preview)) {
|
|
32
|
+
refreshNuxtData();
|
|
33
|
+
}
|
|
34
|
+
} catch (error) {
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
22
38
|
});
|
package/package.json
CHANGED
package/src/module.ts
CHANGED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { defineNuxtPlugin } from '#app'
|
|
2
|
+
|
|
3
|
+
// import { name as pkgName } from '../../package.json'
|
|
4
|
+
import { PrismicModuleOptions } from '../types'
|
|
5
|
+
|
|
6
|
+
// TODO: Revert when fixed
|
|
7
|
+
const pkgName = '@nuxtjs/prismic'
|
|
8
|
+
|
|
9
|
+
export default defineNuxtPlugin((nuxtApp) => {
|
|
10
|
+
const mergedOptions: PrismicModuleOptions =
|
|
11
|
+
nuxtApp.payload.config[pkgName] ??
|
|
12
|
+
nuxtApp.payload.config.public[pkgName] ??
|
|
13
|
+
{}
|
|
14
|
+
|
|
15
|
+
// Hot reload preview updates
|
|
16
|
+
if (mergedOptions.preview) {
|
|
17
|
+
window.addEventListener('prismicPreviewUpdate', (event) => {
|
|
18
|
+
if (refreshNuxtData) {
|
|
19
|
+
event.preventDefault()
|
|
20
|
+
refreshNuxtData()
|
|
21
|
+
}
|
|
22
|
+
})
|
|
23
|
+
}
|
|
24
|
+
})
|
package/src/runtime/plugin.ts
CHANGED
|
@@ -22,7 +22,7 @@ export default defineNuxtPlugin((nuxtApp) => {
|
|
|
22
22
|
nuxtApp.payload.config.public[pkgName] ??
|
|
23
23
|
{}
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
const prismicPlugin = createPrismic({
|
|
26
26
|
...mergedOptions,
|
|
27
27
|
client,
|
|
28
28
|
linkResolver,
|
|
@@ -33,5 +33,34 @@ export default defineNuxtPlugin((nuxtApp) => {
|
|
|
33
33
|
linkExternalComponent: NuxtLink,
|
|
34
34
|
...mergedOptions.components
|
|
35
35
|
}
|
|
36
|
-
})
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
nuxtApp.vueApp.use(prismicPlugin)
|
|
39
|
+
|
|
40
|
+
if (mergedOptions.preview) {
|
|
41
|
+
const previewCookie = useCookie('io.prismic.preview').value
|
|
42
|
+
|
|
43
|
+
// Update client with req when running server side
|
|
44
|
+
if (process.server) {
|
|
45
|
+
prismicPlugin.client.enableAutoPreviewsFromReq(useRequestEvent()?.req)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (previewCookie) {
|
|
49
|
+
try {
|
|
50
|
+
const session = typeof previewCookie === 'string' ? JSON.parse(decodeURIComponent(previewCookie)) : previewCookie
|
|
51
|
+
|
|
52
|
+
if (Object.keys(session).some(key =>
|
|
53
|
+
key in session &&
|
|
54
|
+
typeof session[key] === 'object' &&
|
|
55
|
+
session[key] !== null &&
|
|
56
|
+
'preview' in session[key] &&
|
|
57
|
+
session[key].preview)
|
|
58
|
+
) {
|
|
59
|
+
refreshNuxtData()
|
|
60
|
+
}
|
|
61
|
+
} catch (error) {
|
|
62
|
+
// noop
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
37
66
|
})
|