@nuxtjs/prismic 3.0.0-rc.1 → 3.0.0-rc.3
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.d.ts +7 -2
- package/dist/module.json +3 -3
- package/dist/module.mjs +24 -40
- package/dist/runtime/plugin.client.mjs +2 -3
- package/dist/runtime/plugin.mjs +20 -6
- package/dist/types.d.ts +2 -6
- package/package.json +16 -14
- package/src/module.ts +31 -43
- package/src/runtime/plugin.client.ts +2 -9
- package/src/runtime/plugin.ts +26 -12
package/dist/module.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as _nuxt_schema from '@nuxt/schema';
|
|
2
2
|
import { PrismicPluginOptions } from '@prismicio/vue';
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
type PrismicModuleOptions = Omit<PrismicPluginOptions, 'endpoint' | 'client' | 'linkResolver' | 'htmlSerializer'> & {
|
|
5
5
|
endpoint: string;
|
|
6
6
|
client?: string;
|
|
7
7
|
linkResolver?: string;
|
|
@@ -10,6 +10,11 @@ declare type PrismicModuleOptions = Omit<PrismicPluginOptions, 'endpoint' | 'cli
|
|
|
10
10
|
toolbar?: boolean;
|
|
11
11
|
};
|
|
12
12
|
|
|
13
|
+
declare module '@nuxt/schema' {
|
|
14
|
+
interface PublicRuntimeConfig {
|
|
15
|
+
prismic: PrismicModuleOptions;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
13
18
|
declare const _default: _nuxt_schema.NuxtModule<PrismicModuleOptions>;
|
|
14
19
|
|
|
15
|
-
export { PrismicModuleOptions
|
|
20
|
+
export { PrismicModuleOptions, _default as default };
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
import { join } from 'node:path';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { isRepositoryEndpoint, getRepositoryName } from '@prismicio/client';
|
|
2
|
+
import { defu } from 'defu';
|
|
3
|
+
import { defineNuxtModule, createResolver, addPlugin, addComponent, addImports, extendPages, addTemplate } from '@nuxt/kit';
|
|
5
4
|
import * as prismicVue from '@prismicio/vue';
|
|
6
5
|
import consola from 'consola';
|
|
7
6
|
import { existsSync } from 'node:fs';
|
|
8
7
|
|
|
9
|
-
const name = "@nuxtjs/prismic";
|
|
10
|
-
const version = "3.0.0-rc.1";
|
|
11
|
-
|
|
12
8
|
const logger = consola.withScope("nuxt:prismic");
|
|
13
9
|
|
|
14
10
|
const fileExists = (path, extensions = ["js", "ts"]) => {
|
|
@@ -23,26 +19,25 @@ const fileExists = (path, extensions = ["js", "ts"]) => {
|
|
|
23
19
|
|
|
24
20
|
const module = defineNuxtModule({
|
|
25
21
|
meta: {
|
|
26
|
-
name:
|
|
27
|
-
version: version,
|
|
22
|
+
name: "@nuxtjs/prismic",
|
|
28
23
|
configKey: "prismic",
|
|
29
|
-
compatibility: { nuxt: "^3.0.0
|
|
24
|
+
compatibility: { nuxt: "^3.0.0" }
|
|
30
25
|
},
|
|
31
26
|
defaults: (nuxt) => ({
|
|
32
27
|
endpoint: "",
|
|
33
28
|
clientConfig: {},
|
|
34
|
-
client:
|
|
35
|
-
linkResolver:
|
|
36
|
-
htmlSerializer:
|
|
29
|
+
client: "~/app/prismic/client",
|
|
30
|
+
linkResolver: "~/app/prismic/linkResolver",
|
|
31
|
+
htmlSerializer: "~/app/prismic/htmlSerializer",
|
|
37
32
|
injectComponents: true,
|
|
38
33
|
components: {},
|
|
39
34
|
preview: "/preview",
|
|
40
35
|
toolbar: true
|
|
41
36
|
}),
|
|
42
37
|
hooks: {},
|
|
43
|
-
setup(
|
|
44
|
-
var _a
|
|
45
|
-
if (!
|
|
38
|
+
setup(options, nuxt) {
|
|
39
|
+
var _a;
|
|
40
|
+
if (!options.endpoint) {
|
|
46
41
|
logger.warn("Options `endpoint` is required, disabling module...");
|
|
47
42
|
return;
|
|
48
43
|
}
|
|
@@ -65,14 +60,14 @@ const module = defineNuxtModule({
|
|
|
65
60
|
});
|
|
66
61
|
}
|
|
67
62
|
};
|
|
68
|
-
proxyUserFileWithUndefinedFallback("client",
|
|
69
|
-
proxyUserFileWithUndefinedFallback("linkResolver",
|
|
70
|
-
proxyUserFileWithUndefinedFallback("htmlSerializer",
|
|
63
|
+
proxyUserFileWithUndefinedFallback("client", options.client);
|
|
64
|
+
proxyUserFileWithUndefinedFallback("linkResolver", options.linkResolver);
|
|
65
|
+
proxyUserFileWithUndefinedFallback("htmlSerializer", options.htmlSerializer);
|
|
71
66
|
(_a = nuxt.options.runtimeConfig).public || (_a.public = {});
|
|
72
|
-
nuxt.options.runtimeConfig.public
|
|
67
|
+
nuxt.options.runtimeConfig.public.prismic = defu(nuxt.options.runtimeConfig.public.prismic, options);
|
|
73
68
|
addPlugin(resolver.resolve("runtime/plugin"));
|
|
74
69
|
addPlugin(resolver.resolve("runtime/plugin.client"));
|
|
75
|
-
if (
|
|
70
|
+
if (options.injectComponents) {
|
|
76
71
|
[
|
|
77
72
|
"PrismicEmbed",
|
|
78
73
|
"PrismicImage",
|
|
@@ -88,48 +83,37 @@ const module = defineNuxtModule({
|
|
|
88
83
|
});
|
|
89
84
|
});
|
|
90
85
|
}
|
|
91
|
-
const
|
|
86
|
+
const prismicVueAutoImports = Object.keys(prismicVue).filter((key) => key.startsWith("use")).concat("getSliceComponentProps", "defineSliceZoneComponents").map((key) => {
|
|
92
87
|
return {
|
|
93
88
|
name: key,
|
|
94
89
|
as: key,
|
|
95
90
|
from: "@prismicio/vue"
|
|
96
91
|
};
|
|
97
92
|
});
|
|
98
|
-
|
|
99
|
-
|
|
93
|
+
addImports(prismicVueAutoImports);
|
|
94
|
+
addImports({
|
|
100
95
|
name: "usePrismicPreview",
|
|
101
96
|
as: "usePrismicPreview",
|
|
102
97
|
from: resolver.resolve("runtime/usePrismicPreview")
|
|
103
98
|
});
|
|
104
|
-
if (
|
|
105
|
-
const maybeUserPreviewPage = fileExists(join(nuxt.options.srcDir, nuxt.options.dir.pages,
|
|
99
|
+
if (options.preview) {
|
|
100
|
+
const maybeUserPreviewPage = fileExists(join(nuxt.options.srcDir, nuxt.options.dir.pages, options.preview), ["js", "ts", "vue"]);
|
|
106
101
|
if (maybeUserPreviewPage) {
|
|
107
|
-
logger.info(`Using user-defined preview page at \`${maybeUserPreviewPage.replace(join(nuxt.options.srcDir), "~").replace(nuxt.options.rootDir, "~~").replace(/\\/g, "/")}\`, available at \`${
|
|
102
|
+
logger.info(`Using user-defined preview page at \`${maybeUserPreviewPage.replace(join(nuxt.options.srcDir), "~").replace(nuxt.options.rootDir, "~~").replace(/\\/g, "/")}\`, available at \`${options.preview}\``);
|
|
108
103
|
} else {
|
|
109
|
-
logger.info(`Using default preview page, available at \`${
|
|
104
|
+
logger.info(`Using default preview page, available at \`${options.preview}\``);
|
|
110
105
|
extendPages((pages) => {
|
|
111
106
|
pages.unshift({
|
|
112
107
|
name: "prismic-preview",
|
|
113
|
-
path:
|
|
108
|
+
path: options.preview,
|
|
114
109
|
file: resolver.resolve("runtime/preview.vue")
|
|
115
110
|
});
|
|
116
111
|
});
|
|
117
112
|
}
|
|
118
|
-
if (!
|
|
113
|
+
if (!options.toolbar) {
|
|
119
114
|
logger.warn("`toolbar` option is disabled but `preview` is enabled. Previews won't work unless you manually load the toolbar.");
|
|
120
115
|
}
|
|
121
116
|
}
|
|
122
|
-
if (mergedOptions.toolbar) {
|
|
123
|
-
const repositoryName = isRepositoryEndpoint(mergedOptions.endpoint) ? getRepositoryName(mergedOptions.endpoint) : mergedOptions.endpoint;
|
|
124
|
-
(_b = nuxt.options.app).head || (_b.head = {});
|
|
125
|
-
(_c = nuxt.options.app.head).script || (_c.script = []);
|
|
126
|
-
nuxt.options.app.head.script.push({
|
|
127
|
-
hid: "prismic-preview",
|
|
128
|
-
src: `https://static.cdn.prismic.io/prismic.min.js?repo=${repositoryName}&new=true`,
|
|
129
|
-
async: true,
|
|
130
|
-
defer: true
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
117
|
}
|
|
134
118
|
});
|
|
135
119
|
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { defineNuxtPlugin, refreshNuxtData } from "#app";
|
|
2
|
-
const pkgName = "@nuxtjs/prismic";
|
|
3
2
|
export default defineNuxtPlugin((nuxtApp) => {
|
|
4
|
-
const
|
|
5
|
-
if (
|
|
3
|
+
const options = useRuntimeConfig().public.prismic;
|
|
4
|
+
if (options.preview) {
|
|
6
5
|
window.addEventListener("prismicPreviewUpdate", (event) => {
|
|
7
6
|
event.preventDefault();
|
|
8
7
|
refreshNuxtData();
|
package/dist/runtime/plugin.mjs
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { defineNuxtPlugin, useCookie, useRequestEvent, refreshNuxtData } from "#app";
|
|
2
1
|
import NuxtLink from "#app/components/nuxt-link";
|
|
2
|
+
import { isRepositoryEndpoint, getRepositoryName } from "@prismicio/client";
|
|
3
3
|
import { createPrismic } from "@prismicio/vue";
|
|
4
|
+
import { defineNuxtPlugin, useCookie, useRequestEvent, refreshNuxtData, useHead } from "#imports";
|
|
4
5
|
import client from "#build/prismic/proxy/client";
|
|
5
6
|
import linkResolver from "#build/prismic/proxy/linkResolver";
|
|
6
7
|
import htmlSerializer from "#build/prismic/proxy/htmlSerializer";
|
|
7
|
-
const pkgName = "@nuxtjs/prismic";
|
|
8
8
|
export default defineNuxtPlugin((nuxtApp) => {
|
|
9
|
-
const
|
|
9
|
+
const options = useRuntimeConfig().public.prismic;
|
|
10
10
|
const prismicPlugin = createPrismic({
|
|
11
|
-
...
|
|
11
|
+
...options,
|
|
12
12
|
client,
|
|
13
13
|
linkResolver,
|
|
14
14
|
htmlSerializer,
|
|
@@ -16,11 +16,11 @@ export default defineNuxtPlugin((nuxtApp) => {
|
|
|
16
16
|
components: {
|
|
17
17
|
linkInternalComponent: NuxtLink,
|
|
18
18
|
linkExternalComponent: NuxtLink,
|
|
19
|
-
...
|
|
19
|
+
...options.components
|
|
20
20
|
}
|
|
21
21
|
});
|
|
22
22
|
nuxtApp.vueApp.use(prismicPlugin);
|
|
23
|
-
if (
|
|
23
|
+
if (options.preview) {
|
|
24
24
|
const previewCookie = useCookie("io.prismic.preview").value;
|
|
25
25
|
if (process.server) {
|
|
26
26
|
prismicPlugin.client.enableAutoPreviewsFromReq(useRequestEvent()?.req);
|
|
@@ -36,4 +36,18 @@ export default defineNuxtPlugin((nuxtApp) => {
|
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
|
+
if (options.toolbar) {
|
|
40
|
+
const repositoryName = isRepositoryEndpoint(options.endpoint) ? getRepositoryName(options.endpoint) : options.endpoint;
|
|
41
|
+
useHead({
|
|
42
|
+
script: [{
|
|
43
|
+
key: "prismic-preview",
|
|
44
|
+
src: `https://static.cdn.prismic.io/prismic.min.js?repo=${repositoryName}&new=true`,
|
|
45
|
+
async: true,
|
|
46
|
+
defer: true
|
|
47
|
+
}]
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
provide: { prismic: prismicPlugin }
|
|
52
|
+
};
|
|
39
53
|
});
|
package/dist/types.d.ts
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
|
|
2
|
-
import {
|
|
2
|
+
import { } from './module'
|
|
3
3
|
|
|
4
|
-
declare module '@nuxt/schema' {
|
|
5
|
-
interface NuxtConfig { ['prismic']?: Partial<ModuleOptions> }
|
|
6
|
-
interface NuxtOptions { ['prismic']?: ModuleOptions }
|
|
7
|
-
}
|
|
8
4
|
|
|
9
5
|
|
|
10
|
-
export { default } from './module'
|
|
6
|
+
export { PrismicModuleOptions, default } from './module'
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nuxtjs/prismic",
|
|
3
|
-
"version": "3.0.0-rc.
|
|
3
|
+
"version": "3.0.0-rc.3",
|
|
4
4
|
"description": "Easily connect your Nuxt 3 application to your content hosted on Prismic",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"nuxt",
|
|
@@ -36,6 +36,8 @@
|
|
|
36
36
|
"build": "nuxt-module-build",
|
|
37
37
|
"dev": "nuxi dev playground",
|
|
38
38
|
"dev:build": "nuxi build playground",
|
|
39
|
+
"dev:preview": "nuxi preview playground",
|
|
40
|
+
"dev:generate": "nuxi generate playground",
|
|
39
41
|
"lint": "eslint --ext .js,.ts .",
|
|
40
42
|
"prepare": "nuxi prepare playground && npm run build",
|
|
41
43
|
"release": "npm run test && standard-version && git push --follow-tags && npm run build && npm publish",
|
|
@@ -43,27 +45,27 @@
|
|
|
43
45
|
"release:rc:dry": "standard-version --release-as major --prerelease rc --dry-run",
|
|
44
46
|
"release:dry": "standard-version --dry-run",
|
|
45
47
|
"test": "npm run lint && npm run unit && npm run build",
|
|
48
|
+
"types": "tsc --noEmit",
|
|
46
49
|
"unit": "vitest run --coverage",
|
|
47
50
|
"unit:watch": "vitest watch"
|
|
48
51
|
},
|
|
49
52
|
"dependencies": {
|
|
50
|
-
"@nuxt/kit": "^3.
|
|
51
|
-
"@prismicio/client": "^6.
|
|
52
|
-
"@prismicio/vue": "^3.
|
|
53
|
+
"@nuxt/kit": "^3.3.2",
|
|
54
|
+
"@prismicio/client": "^6.7.3",
|
|
55
|
+
"@prismicio/vue": "^3.1.3",
|
|
53
56
|
"consola": "^2.15.3",
|
|
54
|
-
"
|
|
57
|
+
"defu": "^6.1.2"
|
|
55
58
|
},
|
|
56
59
|
"devDependencies": {
|
|
57
|
-
"@nuxt/module-builder": "
|
|
58
|
-
"@
|
|
59
|
-
"@
|
|
60
|
-
"
|
|
61
|
-
"
|
|
62
|
-
"
|
|
63
|
-
"nuxt": "^3.0.0-rc",
|
|
60
|
+
"@nuxt/module-builder": "^0.2.1",
|
|
61
|
+
"@nuxtjs/eslint-config-typescript": "^12.0.0",
|
|
62
|
+
"@vitest/coverage-c8": "^0.29.7",
|
|
63
|
+
"eslint": "^8.36.0",
|
|
64
|
+
"mock-fs": "^5.2.0",
|
|
65
|
+
"nuxt": "^3.3.2",
|
|
64
66
|
"standard-version": "^9.5.0",
|
|
65
|
-
"typescript": "^4.
|
|
66
|
-
"vitest": "^0.
|
|
67
|
+
"typescript": "^4.9.5",
|
|
68
|
+
"vitest": "^0.29.7"
|
|
67
69
|
},
|
|
68
70
|
"engines": {
|
|
69
71
|
"node": ">=14.15.0"
|
package/src/module.ts
CHANGED
|
@@ -1,49 +1,51 @@
|
|
|
1
1
|
import { join } from 'node:path'
|
|
2
2
|
|
|
3
|
+
import { defu } from 'defu'
|
|
3
4
|
import {
|
|
4
5
|
defineNuxtModule,
|
|
5
6
|
createResolver,
|
|
6
7
|
addTemplate,
|
|
7
8
|
addPlugin,
|
|
8
|
-
|
|
9
|
+
addImports,
|
|
9
10
|
addComponent,
|
|
10
11
|
extendPages
|
|
11
12
|
} from '@nuxt/kit'
|
|
12
|
-
import { cleanDoubleSlashes } from 'ufo'
|
|
13
13
|
|
|
14
|
-
import { isRepositoryEndpoint, getRepositoryName } from '@prismicio/client'
|
|
15
14
|
import * as prismicVue from '@prismicio/vue'
|
|
16
15
|
|
|
17
|
-
import { name as pkgName, version as pkgVersion } from '../package.json'
|
|
18
16
|
import { logger, fileExists } from './lib'
|
|
19
17
|
import type { PrismicModuleOptions } from './types'
|
|
20
18
|
|
|
21
19
|
// Options export
|
|
22
20
|
export type { PrismicModuleOptions } from './types'
|
|
23
|
-
|
|
21
|
+
|
|
22
|
+
declare module '@nuxt/schema' {
|
|
23
|
+
interface PublicRuntimeConfig {
|
|
24
|
+
prismic: PrismicModuleOptions
|
|
25
|
+
}
|
|
26
|
+
}
|
|
24
27
|
|
|
25
28
|
// Module export
|
|
26
29
|
export default defineNuxtModule<PrismicModuleOptions>({
|
|
27
30
|
meta: {
|
|
28
|
-
name:
|
|
29
|
-
version: pkgVersion,
|
|
31
|
+
name: '@nuxtjs/prismic',
|
|
30
32
|
configKey: 'prismic',
|
|
31
|
-
compatibility: { nuxt: '^3.0.0
|
|
33
|
+
compatibility: { nuxt: '^3.0.0' }
|
|
32
34
|
},
|
|
33
35
|
defaults: nuxt => ({
|
|
34
36
|
endpoint: '',
|
|
35
37
|
clientConfig: {},
|
|
36
|
-
client:
|
|
37
|
-
linkResolver:
|
|
38
|
-
htmlSerializer:
|
|
38
|
+
client: '~/app/prismic/client',
|
|
39
|
+
linkResolver: '~/app/prismic/linkResolver',
|
|
40
|
+
htmlSerializer: '~/app/prismic/htmlSerializer',
|
|
39
41
|
injectComponents: true,
|
|
40
42
|
components: {},
|
|
41
43
|
preview: '/preview',
|
|
42
44
|
toolbar: true
|
|
43
45
|
}),
|
|
44
46
|
hooks: {},
|
|
45
|
-
setup (
|
|
46
|
-
if (!
|
|
47
|
+
setup (options, nuxt) {
|
|
48
|
+
if (!options.endpoint) {
|
|
47
49
|
logger.warn('Options `endpoint` is required, disabling module...')
|
|
48
50
|
return
|
|
49
51
|
}
|
|
@@ -74,20 +76,20 @@ export default defineNuxtModule<PrismicModuleOptions>({
|
|
|
74
76
|
})
|
|
75
77
|
}
|
|
76
78
|
}
|
|
77
|
-
proxyUserFileWithUndefinedFallback('client',
|
|
78
|
-
proxyUserFileWithUndefinedFallback('linkResolver',
|
|
79
|
-
proxyUserFileWithUndefinedFallback('htmlSerializer',
|
|
79
|
+
proxyUserFileWithUndefinedFallback('client', options.client!)
|
|
80
|
+
proxyUserFileWithUndefinedFallback('linkResolver', options.linkResolver!)
|
|
81
|
+
proxyUserFileWithUndefinedFallback('htmlSerializer', options.htmlSerializer!)
|
|
80
82
|
|
|
81
83
|
// Expose options through public runtime config
|
|
82
84
|
nuxt.options.runtimeConfig.public ||= {} as typeof nuxt.options.runtimeConfig.public
|
|
83
|
-
nuxt.options.runtimeConfig.public
|
|
85
|
+
nuxt.options.runtimeConfig.public.prismic = defu(nuxt.options.runtimeConfig.public.prismic, options)
|
|
84
86
|
|
|
85
87
|
// Add plugin
|
|
86
88
|
addPlugin(resolver.resolve('runtime/plugin'))
|
|
87
89
|
addPlugin(resolver.resolve('runtime/plugin.client'))
|
|
88
90
|
|
|
89
91
|
// Add components auto import
|
|
90
|
-
if (
|
|
92
|
+
if (options.injectComponents) {
|
|
91
93
|
[
|
|
92
94
|
'PrismicEmbed',
|
|
93
95
|
'PrismicImage',
|
|
@@ -104,10 +106,11 @@ export default defineNuxtModule<PrismicModuleOptions>({
|
|
|
104
106
|
})
|
|
105
107
|
}
|
|
106
108
|
|
|
107
|
-
// Add
|
|
108
|
-
const
|
|
109
|
+
// Add auto imports
|
|
110
|
+
const prismicVueAutoImports = Object
|
|
109
111
|
.keys(prismicVue)
|
|
110
112
|
.filter(key => key.startsWith('use'))
|
|
113
|
+
.concat('getSliceComponentProps', 'defineSliceZoneComponents')
|
|
111
114
|
.map((key) => {
|
|
112
115
|
return {
|
|
113
116
|
name: key,
|
|
@@ -115,50 +118,35 @@ export default defineNuxtModule<PrismicModuleOptions>({
|
|
|
115
118
|
from: '@prismicio/vue'
|
|
116
119
|
}
|
|
117
120
|
})
|
|
118
|
-
|
|
119
|
-
|
|
121
|
+
addImports(prismicVueAutoImports)
|
|
122
|
+
addImports({
|
|
120
123
|
name: 'usePrismicPreview',
|
|
121
124
|
as: 'usePrismicPreview',
|
|
122
125
|
from: resolver.resolve('runtime/usePrismicPreview')
|
|
123
126
|
})
|
|
124
127
|
|
|
125
128
|
// Add preview route
|
|
126
|
-
if (
|
|
127
|
-
const maybeUserPreviewPage = fileExists(join(nuxt.options.srcDir, nuxt.options.dir.pages,
|
|
129
|
+
if (options.preview) {
|
|
130
|
+
const maybeUserPreviewPage = fileExists(join(nuxt.options.srcDir, nuxt.options.dir.pages, options.preview), ['js', 'ts', 'vue'])
|
|
128
131
|
|
|
129
132
|
if (maybeUserPreviewPage) {
|
|
130
133
|
logger.info(`Using user-defined preview page at \`${maybeUserPreviewPage.replace(join(nuxt.options.srcDir), '~').replace(nuxt.options.rootDir, '~~').replace(/\\/g, '/')
|
|
131
|
-
}\`, available at \`${
|
|
134
|
+
}\`, available at \`${options.preview}\``)
|
|
132
135
|
} else {
|
|
133
|
-
logger.info(`Using default preview page, available at \`${
|
|
136
|
+
logger.info(`Using default preview page, available at \`${options.preview}\``)
|
|
134
137
|
|
|
135
138
|
extendPages((pages) => {
|
|
136
139
|
pages.unshift({
|
|
137
140
|
name: 'prismic-preview',
|
|
138
|
-
path:
|
|
141
|
+
path: options.preview as string, // Checked before
|
|
139
142
|
file: resolver.resolve('runtime/preview.vue')
|
|
140
143
|
})
|
|
141
144
|
})
|
|
142
145
|
}
|
|
143
146
|
|
|
144
|
-
if (!
|
|
147
|
+
if (!options.toolbar) {
|
|
145
148
|
logger.warn('`toolbar` option is disabled but `preview` is enabled. Previews won\'t work unless you manually load the toolbar.')
|
|
146
149
|
}
|
|
147
150
|
}
|
|
148
|
-
|
|
149
|
-
if (mergedOptions.toolbar) {
|
|
150
|
-
// Add toolbar
|
|
151
|
-
const repositoryName = isRepositoryEndpoint(mergedOptions.endpoint)
|
|
152
|
-
? getRepositoryName(mergedOptions.endpoint)
|
|
153
|
-
: mergedOptions.endpoint
|
|
154
|
-
nuxt.options.app.head ||= {}
|
|
155
|
-
nuxt.options.app.head.script ||= []
|
|
156
|
-
nuxt.options.app.head.script.push({
|
|
157
|
-
hid: 'prismic-preview',
|
|
158
|
-
src: `https://static.cdn.prismic.io/prismic.min.js?repo=${repositoryName}&new=true`,
|
|
159
|
-
async: true,
|
|
160
|
-
defer: true
|
|
161
|
-
})
|
|
162
|
-
}
|
|
163
151
|
}
|
|
164
152
|
})
|
|
@@ -1,19 +1,12 @@
|
|
|
1
1
|
import { defineNuxtPlugin, refreshNuxtData } from '#app'
|
|
2
2
|
|
|
3
|
-
// import { name as pkgName } from '../../package.json'
|
|
4
3
|
import { PrismicModuleOptions } from '../types'
|
|
5
4
|
|
|
6
|
-
// TODO: Revert when fixed
|
|
7
|
-
const pkgName = '@nuxtjs/prismic'
|
|
8
|
-
|
|
9
5
|
export default defineNuxtPlugin((nuxtApp) => {
|
|
10
|
-
const
|
|
11
|
-
nuxtApp.payload.config[pkgName] ??
|
|
12
|
-
nuxtApp.payload.config.public[pkgName] ??
|
|
13
|
-
{}
|
|
6
|
+
const options: PrismicModuleOptions = useRuntimeConfig().public.prismic
|
|
14
7
|
|
|
15
8
|
// Hot reload preview updates
|
|
16
|
-
if (
|
|
9
|
+
if (options.preview) {
|
|
17
10
|
window.addEventListener('prismicPreviewUpdate', (event) => {
|
|
18
11
|
event.preventDefault()
|
|
19
12
|
refreshNuxtData()
|
package/src/runtime/plugin.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { defineNuxtPlugin, useCookie, useRequestEvent, refreshNuxtData } from '#app'
|
|
2
1
|
import NuxtLink from '#app/components/nuxt-link'
|
|
3
2
|
|
|
3
|
+
import { isRepositoryEndpoint, getRepositoryName } from '@prismicio/client'
|
|
4
4
|
import { createPrismic } from '@prismicio/vue'
|
|
5
5
|
|
|
6
|
-
// import { name as pkgName } from '../../package.json'
|
|
7
6
|
import { PrismicModuleOptions } from '../types'
|
|
7
|
+
import { defineNuxtPlugin, useCookie, useRequestEvent, refreshNuxtData, useHead } from '#imports'
|
|
8
8
|
|
|
9
9
|
// @ts-expect-error vfs cannot be resolved here
|
|
10
10
|
import client from '#build/prismic/proxy/client'
|
|
@@ -13,17 +13,11 @@ import linkResolver from '#build/prismic/proxy/linkResolver'
|
|
|
13
13
|
// @ts-expect-error vfs cannot be resolved here
|
|
14
14
|
import htmlSerializer from '#build/prismic/proxy/htmlSerializer'
|
|
15
15
|
|
|
16
|
-
// TODO: Revert when fixed
|
|
17
|
-
const pkgName = '@nuxtjs/prismic'
|
|
18
|
-
|
|
19
16
|
export default defineNuxtPlugin((nuxtApp) => {
|
|
20
|
-
const
|
|
21
|
-
nuxtApp.payload.config[pkgName] ??
|
|
22
|
-
nuxtApp.payload.config.public[pkgName] ??
|
|
23
|
-
{}
|
|
17
|
+
const options: PrismicModuleOptions = useRuntimeConfig().public.prismic
|
|
24
18
|
|
|
25
19
|
const prismicPlugin = createPrismic({
|
|
26
|
-
...
|
|
20
|
+
...options,
|
|
27
21
|
client,
|
|
28
22
|
linkResolver,
|
|
29
23
|
htmlSerializer,
|
|
@@ -31,13 +25,13 @@ export default defineNuxtPlugin((nuxtApp) => {
|
|
|
31
25
|
components: {
|
|
32
26
|
linkInternalComponent: NuxtLink,
|
|
33
27
|
linkExternalComponent: NuxtLink,
|
|
34
|
-
...
|
|
28
|
+
...options.components
|
|
35
29
|
}
|
|
36
30
|
})
|
|
37
31
|
|
|
38
32
|
nuxtApp.vueApp.use(prismicPlugin)
|
|
39
33
|
|
|
40
|
-
if (
|
|
34
|
+
if (options.preview) {
|
|
41
35
|
const previewCookie = useCookie('io.prismic.preview').value
|
|
42
36
|
|
|
43
37
|
// Update client with req when running server side
|
|
@@ -64,4 +58,24 @@ export default defineNuxtPlugin((nuxtApp) => {
|
|
|
64
58
|
}
|
|
65
59
|
}
|
|
66
60
|
}
|
|
61
|
+
|
|
62
|
+
if (options.toolbar) {
|
|
63
|
+
// Add toolbar
|
|
64
|
+
const repositoryName = isRepositoryEndpoint(options.endpoint)
|
|
65
|
+
? getRepositoryName(options.endpoint)
|
|
66
|
+
: options.endpoint
|
|
67
|
+
|
|
68
|
+
useHead({
|
|
69
|
+
script: [{
|
|
70
|
+
key: 'prismic-preview',
|
|
71
|
+
src: `https://static.cdn.prismic.io/prismic.min.js?repo=${repositoryName}&new=true`,
|
|
72
|
+
async: true,
|
|
73
|
+
defer: true
|
|
74
|
+
}]
|
|
75
|
+
})
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return {
|
|
79
|
+
provide: { prismic: prismicPlugin }
|
|
80
|
+
}
|
|
67
81
|
})
|