@nuxtjs/prismic 3.0.0-alpha.7 → 3.0.0-rc.0
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/README.md +1 -1
- package/dist/module.d.ts +1 -0
- package/dist/module.json +1 -1
- package/dist/module.mjs +18 -8
- package/dist/runtime/plugin.client.d.ts +2 -0
- package/dist/runtime/plugin.client.mjs +11 -0
- package/dist/runtime/plugin.mjs +20 -3
- package/package.json +15 -10
- package/src/{utils.ts → lib/fileExists.ts} +1 -1
- package/src/lib/index.ts +2 -0
- package/src/{logger.ts → lib/logger.ts} +0 -0
- package/src/module.ts +20 -12
- package/src/runtime/plugin.client.ts +22 -0
- package/src/runtime/plugin.ts +33 -3
- package/src/types.ts +1 -0
package/README.md
CHANGED
|
@@ -26,7 +26,7 @@ Easily connect your Nuxt.js application to your content hosted on [Prismic][pris
|
|
|
26
26
|
## Install
|
|
27
27
|
|
|
28
28
|
```bash
|
|
29
|
-
npm install --save-dev @nuxtjs/prismic@
|
|
29
|
+
npm install --save-dev @nuxtjs/prismic@rc # or yarn add --dev @nuxtjs/prismic@rc
|
|
30
30
|
```
|
|
31
31
|
|
|
32
32
|
Then, add `@nuxtjs/prismic` to the `modules` section of your Nuxt config and configure your Prismic API endpoint:
|
package/dist/module.d.ts
CHANGED
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
import { join } from 'path';
|
|
1
|
+
import { join } from 'node:path';
|
|
2
2
|
import { defineNuxtModule, createResolver, addPlugin, addComponent, addAutoImport, extendPages, addTemplate } from '@nuxt/kit';
|
|
3
3
|
import { cleanDoubleSlashes } from 'ufo';
|
|
4
4
|
import { isRepositoryEndpoint, getRepositoryName } from '@prismicio/client';
|
|
5
5
|
import * as prismicVue from '@prismicio/vue';
|
|
6
|
-
import { existsSync } from 'fs';
|
|
7
6
|
import consola from 'consola';
|
|
7
|
+
import { existsSync } from 'node:fs';
|
|
8
8
|
|
|
9
9
|
const name = "@nuxtjs/prismic";
|
|
10
|
-
const version = "3.0.0-
|
|
10
|
+
const version = "3.0.0-rc.0";
|
|
11
|
+
|
|
12
|
+
const logger = consola.withScope("nuxt:prismic");
|
|
11
13
|
|
|
12
14
|
const fileExists = (path, extensions = ["js", "ts"]) => {
|
|
13
15
|
if (!path) {
|
|
@@ -19,8 +21,6 @@ const fileExists = (path, extensions = ["js", "ts"]) => {
|
|
|
19
21
|
return extension ? `${path}.${extension}` : null;
|
|
20
22
|
};
|
|
21
23
|
|
|
22
|
-
const logger = consola.withScope("nuxt:prismic");
|
|
23
|
-
|
|
24
24
|
const module = defineNuxtModule({
|
|
25
25
|
meta: {
|
|
26
26
|
name: name,
|
|
@@ -36,7 +36,8 @@ const module = defineNuxtModule({
|
|
|
36
36
|
htmlSerializer: cleanDoubleSlashes(`~/${nuxt.options.dir.app}/prismic/htmlSerializer`),
|
|
37
37
|
injectComponents: true,
|
|
38
38
|
components: {},
|
|
39
|
-
preview: "/preview"
|
|
39
|
+
preview: "/preview",
|
|
40
|
+
toolbar: true
|
|
40
41
|
}),
|
|
41
42
|
hooks: {},
|
|
42
43
|
setup(mergedOptions, nuxt) {
|
|
@@ -49,7 +50,7 @@ const module = defineNuxtModule({
|
|
|
49
50
|
nuxt.options.build.transpile.push(resolver.resolve("runtime"), "@nuxtjs/prismic", "@prismicio/vue");
|
|
50
51
|
const proxyUserFileWithUndefinedFallback = (filename, path, extensions = ["js", "mjs", "ts"]) => {
|
|
51
52
|
const resolvedFilename = `prismic/proxy/${filename}.ts`;
|
|
52
|
-
const resolvedPath = path
|
|
53
|
+
const resolvedPath = path.replace(/^(~~|@@)/, nuxt.options.rootDir).replace(/^(~|@)/, nuxt.options.srcDir);
|
|
53
54
|
const maybeUserFile = fileExists(resolvedPath, extensions);
|
|
54
55
|
if (maybeUserFile) {
|
|
55
56
|
logger.info(`Using user-defined \`${filename}\` at \`${maybeUserFile.replace(nuxt.options.srcDir, "~").replace(nuxt.options.rootDir, "~~").replace(/\\/g, "/")}\``);
|
|
@@ -70,6 +71,7 @@ const module = defineNuxtModule({
|
|
|
70
71
|
(_a = nuxt.options.runtimeConfig).public || (_a.public = {});
|
|
71
72
|
nuxt.options.runtimeConfig.public[name] = mergedOptions;
|
|
72
73
|
addPlugin(resolver.resolve("runtime/plugin"));
|
|
74
|
+
addPlugin(resolver.resolve("runtime/plugin.client"));
|
|
73
75
|
if (mergedOptions.injectComponents) {
|
|
74
76
|
[
|
|
75
77
|
"PrismicEmbed",
|
|
@@ -113,11 +115,19 @@ const module = defineNuxtModule({
|
|
|
113
115
|
});
|
|
114
116
|
});
|
|
115
117
|
}
|
|
118
|
+
if (!mergedOptions.toolbar) {
|
|
119
|
+
logger.warn("`toolbar` option is disabled but `preview` is enabled. Previews won't work unless you manually load the toolbar.");
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
if (mergedOptions.toolbar) {
|
|
116
123
|
const repositoryName = isRepositoryEndpoint(mergedOptions.endpoint) ? getRepositoryName(mergedOptions.endpoint) : mergedOptions.endpoint;
|
|
117
124
|
(_b = nuxt.options.app).head || (_b.head = {});
|
|
118
125
|
(_c = nuxt.options.app.head).script || (_c.script = []);
|
|
119
126
|
nuxt.options.app.head.script.push({
|
|
120
|
-
|
|
127
|
+
hid: "prismic-preview",
|
|
128
|
+
src: `https://static.cdn.prismic.io/prismic.min.js?repo=${repositoryName}&new=true`,
|
|
129
|
+
async: true,
|
|
130
|
+
defer: true
|
|
121
131
|
});
|
|
122
132
|
}
|
|
123
133
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { defineNuxtPlugin, refreshNuxtData } 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
|
+
event.preventDefault();
|
|
8
|
+
refreshNuxtData();
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
});
|
package/dist/runtime/plugin.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { defineNuxtPlugin } from "#app";
|
|
1
|
+
import { defineNuxtPlugin, useCookie, useRequestEvent, refreshNuxtData } from "#app";
|
|
2
2
|
import NuxtLink from "#app/components/nuxt-link";
|
|
3
3
|
import { createPrismic } from "@prismicio/vue";
|
|
4
4
|
import client from "#build/prismic/proxy/client";
|
|
@@ -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,22 @@ 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
|
+
console.warn("Failed to parse Prismic preview cookie", error);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
22
39
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nuxtjs/prismic",
|
|
3
|
-
"version": "3.0.0-
|
|
3
|
+
"version": "3.0.0-rc.0",
|
|
4
4
|
"description": "Easily connect your Nuxt 3 application to your content hosted on Prismic",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"nuxt",
|
|
@@ -38,27 +38,32 @@
|
|
|
38
38
|
"dev:build": "nuxi build playground",
|
|
39
39
|
"lint": "eslint --ext .js,.ts .",
|
|
40
40
|
"prepare": "nuxi prepare playground && npm run build",
|
|
41
|
-
"release": "npm run
|
|
42
|
-
"release:
|
|
43
|
-
"release:
|
|
41
|
+
"release": "npm run test && standard-version && git push --follow-tags && npm run build && npm publish",
|
|
42
|
+
"release:rc": "npm run test && standard-version --release-as major --prerelease rc && git push --follow-tags && npm run build && npm publish --tag rc",
|
|
43
|
+
"release:rc:dry": "standard-version --release-as major --prerelease rc --dry-run",
|
|
44
44
|
"release:dry": "standard-version --dry-run",
|
|
45
|
-
"test": "npm run lint && npm run unit",
|
|
46
|
-
"unit": "
|
|
45
|
+
"test": "npm run lint && npm run unit && npm run build",
|
|
46
|
+
"unit": "vitest run --coverage",
|
|
47
|
+
"unit:watch": "vitest watch"
|
|
47
48
|
},
|
|
48
49
|
"dependencies": {
|
|
49
50
|
"@nuxt/kit": "^3.0.0-rc",
|
|
50
51
|
"@prismicio/client": "^6.6.1",
|
|
51
|
-
"@prismicio/vue": "^3.0.0
|
|
52
|
+
"@prismicio/vue": "^3.0.0",
|
|
52
53
|
"consola": "^2.15.3",
|
|
53
|
-
"ufo": "^0.8.
|
|
54
|
+
"ufo": "^0.8.5"
|
|
54
55
|
},
|
|
55
56
|
"devDependencies": {
|
|
56
57
|
"@nuxt/module-builder": "latest",
|
|
58
|
+
"@nuxt/test-utils": "npm:@nuxt/test-utils-edge@latest",
|
|
57
59
|
"@nuxtjs/eslint-config-typescript": "latest",
|
|
58
|
-
"
|
|
60
|
+
"c8": "^7.11.3",
|
|
61
|
+
"eslint": "^8.20.0",
|
|
62
|
+
"mock-fs": "^5.1.2",
|
|
59
63
|
"nuxt": "^3.0.0-rc",
|
|
60
64
|
"standard-version": "^9.5.0",
|
|
61
|
-
"typescript": "^4.7.4"
|
|
65
|
+
"typescript": "^4.7.4",
|
|
66
|
+
"vitest": "^0.18.1"
|
|
62
67
|
},
|
|
63
68
|
"engines": {
|
|
64
69
|
"node": ">=14.15.0"
|
package/src/lib/index.ts
ADDED
|
File without changes
|
package/src/module.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { join } from 'path'
|
|
1
|
+
import { join } from 'node:path'
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
4
|
defineNuxtModule,
|
|
@@ -15,9 +15,8 @@ import { isRepositoryEndpoint, getRepositoryName } from '@prismicio/client'
|
|
|
15
15
|
import * as prismicVue from '@prismicio/vue'
|
|
16
16
|
|
|
17
17
|
import { name as pkgName, version as pkgVersion } from '../package.json'
|
|
18
|
+
import { logger, fileExists } from './lib'
|
|
18
19
|
import type { PrismicModuleOptions } from './types'
|
|
19
|
-
import { fileExists } from './utils'
|
|
20
|
-
import { logger } from './logger'
|
|
21
20
|
|
|
22
21
|
// Options export
|
|
23
22
|
export type { PrismicModuleOptions } from './types'
|
|
@@ -39,7 +38,8 @@ export default defineNuxtModule<PrismicModuleOptions>({
|
|
|
39
38
|
htmlSerializer: cleanDoubleSlashes(`~/${nuxt.options.dir.app}/prismic/htmlSerializer`),
|
|
40
39
|
injectComponents: true,
|
|
41
40
|
components: {},
|
|
42
|
-
preview: '/preview'
|
|
41
|
+
preview: '/preview',
|
|
42
|
+
toolbar: true
|
|
43
43
|
}),
|
|
44
44
|
hooks: {},
|
|
45
45
|
setup (mergedOptions, nuxt) {
|
|
@@ -53,11 +53,9 @@ export default defineNuxtModule<PrismicModuleOptions>({
|
|
|
53
53
|
nuxt.options.build.transpile.push(resolver.resolve('runtime'), '@nuxtjs/prismic', '@prismicio/vue')
|
|
54
54
|
|
|
55
55
|
// Add runtime user code
|
|
56
|
-
const proxyUserFileWithUndefinedFallback = (filename: string, path
|
|
56
|
+
const proxyUserFileWithUndefinedFallback = (filename: string, path: string, extensions = ['js', 'mjs', 'ts']) => {
|
|
57
57
|
const resolvedFilename = `prismic/proxy/${filename}.ts`
|
|
58
|
-
const resolvedPath = path
|
|
59
|
-
? path.replace(/^(~~|@@)/, nuxt.options.rootDir).replace(/^(~|@)/, nuxt.options.srcDir)
|
|
60
|
-
: undefined
|
|
58
|
+
const resolvedPath = path.replace(/^(~~|@@)/, nuxt.options.rootDir).replace(/^(~|@)/, nuxt.options.srcDir)
|
|
61
59
|
const maybeUserFile = fileExists(resolvedPath, extensions)
|
|
62
60
|
|
|
63
61
|
if (maybeUserFile) {
|
|
@@ -76,9 +74,9 @@ export default defineNuxtModule<PrismicModuleOptions>({
|
|
|
76
74
|
})
|
|
77
75
|
}
|
|
78
76
|
}
|
|
79
|
-
proxyUserFileWithUndefinedFallback('client', mergedOptions.client)
|
|
80
|
-
proxyUserFileWithUndefinedFallback('linkResolver', mergedOptions.linkResolver)
|
|
81
|
-
proxyUserFileWithUndefinedFallback('htmlSerializer', mergedOptions.htmlSerializer)
|
|
77
|
+
proxyUserFileWithUndefinedFallback('client', mergedOptions.client!)
|
|
78
|
+
proxyUserFileWithUndefinedFallback('linkResolver', mergedOptions.linkResolver!)
|
|
79
|
+
proxyUserFileWithUndefinedFallback('htmlSerializer', mergedOptions.htmlSerializer!)
|
|
82
80
|
|
|
83
81
|
// Expose options through public runtime config
|
|
84
82
|
nuxt.options.runtimeConfig.public ||= {} as typeof nuxt.options.runtimeConfig.public
|
|
@@ -86,6 +84,7 @@ export default defineNuxtModule<PrismicModuleOptions>({
|
|
|
86
84
|
|
|
87
85
|
// Add plugin
|
|
88
86
|
addPlugin(resolver.resolve('runtime/plugin'))
|
|
87
|
+
addPlugin(resolver.resolve('runtime/plugin.client'))
|
|
89
88
|
|
|
90
89
|
// Add components auto import
|
|
91
90
|
if (mergedOptions.injectComponents) {
|
|
@@ -142,6 +141,12 @@ export default defineNuxtModule<PrismicModuleOptions>({
|
|
|
142
141
|
})
|
|
143
142
|
}
|
|
144
143
|
|
|
144
|
+
if (!mergedOptions.toolbar) {
|
|
145
|
+
logger.warn('`toolbar` option is disabled but `preview` is enabled. Previews won\'t work unless you manually load the toolbar.')
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
if (mergedOptions.toolbar) {
|
|
145
150
|
// Add toolbar
|
|
146
151
|
const repositoryName = isRepositoryEndpoint(mergedOptions.endpoint)
|
|
147
152
|
? getRepositoryName(mergedOptions.endpoint)
|
|
@@ -149,7 +154,10 @@ export default defineNuxtModule<PrismicModuleOptions>({
|
|
|
149
154
|
nuxt.options.app.head ||= {}
|
|
150
155
|
nuxt.options.app.head.script ||= []
|
|
151
156
|
nuxt.options.app.head.script.push({
|
|
152
|
-
|
|
157
|
+
hid: 'prismic-preview',
|
|
158
|
+
src: `https://static.cdn.prismic.io/prismic.min.js?repo=${repositoryName}&new=true`,
|
|
159
|
+
async: true,
|
|
160
|
+
defer: true
|
|
153
161
|
})
|
|
154
162
|
}
|
|
155
163
|
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { defineNuxtPlugin, refreshNuxtData } 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
|
+
event.preventDefault()
|
|
19
|
+
refreshNuxtData()
|
|
20
|
+
})
|
|
21
|
+
}
|
|
22
|
+
})
|
package/src/runtime/plugin.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { defineNuxtPlugin } from '#app'
|
|
1
|
+
import { defineNuxtPlugin, useCookie, useRequestEvent, refreshNuxtData } from '#app'
|
|
2
2
|
import NuxtLink from '#app/components/nuxt-link'
|
|
3
3
|
|
|
4
4
|
import { createPrismic } from '@prismicio/vue'
|
|
@@ -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,35 @@ 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
|
+
// eslint-disable-next-line no-console
|
|
63
|
+
console.warn('Failed to parse Prismic preview cookie', error)
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
37
67
|
})
|