@storyblok/nuxt 5.5.1 → 5.6.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/.editorconfig +12 -0
- package/.eslintignore +3 -0
- package/.eslintrc +7 -0
- package/.github/ISSUE_TEMPLATE/config.yml +1 -0
- package/.github/ISSUE_TEMPLATE/issue.bug.yml +68 -0
- package/.github/ISSUE_TEMPLATE/issue.fr.yml +40 -0
- package/.github/dependabot.yml +11 -0
- package/.github/workflows/dependabot-automerge.yml +28 -0
- package/.github/workflows/release.yml +30 -0
- package/.husky/commit-msg +6 -0
- package/.husky/pre-commit +4 -0
- package/.nuxtrc +1 -0
- package/.prettierignore +1 -0
- package/README.md +35 -17
- package/cypress/.eslintrc +3 -0
- package/cypress/e2e/index.cy.ts +34 -0
- package/cypress/fixtures/stories.json +7 -0
- package/cypress/support/commands.ts +25 -0
- package/cypress/support/e2e.ts +20 -0
- package/cypress.config.ts +11 -0
- package/package.json +74 -30
- package/playground/README.md +63 -0
- package/playground/app.vue +3 -0
- package/playground/error.vue +22 -0
- package/playground/nuxt.config.ts +18 -0
- package/playground/package-lock.json +11660 -0
- package/playground/package.json +17 -0
- package/playground/pages/[...slug].vue +17 -0
- package/playground/pages/index.vue +21 -0
- package/playground/public/favicon.ico +0 -0
- package/playground/server/tsconfig.json +3 -0
- package/playground/storyblok/sub/Feature.vue +16 -0
- package/playground/storyblok/sub/Grid.vue +19 -0
- package/playground/storyblok/sub/Page.vue +19 -0
- package/playground/storyblok/sub/Teaser.vue +19 -0
- package/playground/tsconfig.json +4 -0
- package/playground-e2e/nuxt.config.ts +24 -0
- package/playground-e2e/package.json +15 -0
- package/playground-e2e/pages/[...slug].vue +20 -0
- package/playground-e2e/pages/index.vue +19 -0
- package/playground-e2e/pages/test.vue +7 -0
- package/playground-e2e/pages/vcalong.vue +17 -0
- package/playground-e2e/plugins/storyblok.js +21 -0
- package/playground-e2e/storyblok/sub/Feature.vue +14 -0
- package/playground-e2e/storyblok/sub/Grid.vue +19 -0
- package/playground-e2e/storyblok/sub/Page.vue +19 -0
- package/playground-e2e/storyblok/sub/Teaser.vue +19 -0
- package/playground-e2e/tsconfig.json +11 -0
- package/src/module.ts +90 -0
- package/src/runtime/composables/useAsyncStoryblok.ts +33 -0
- package/{dist/runtime/plugin.mjs → src/runtime/plugin.ts} +1 -0
- package/tsconfig.json +3 -0
- package/dist/module.cjs +0 -5
- package/dist/module.d.ts +0 -13
- package/dist/module.json +0 -5
- package/dist/module.mjs +0 -58
- package/dist/runtime/composables/useAsyncStoryblok.d.ts +0 -2
- package/dist/runtime/composables/useAsyncStoryblok.mjs +0 -25
- package/dist/runtime/plugin.d.ts +0 -2
- package/dist/types.d.ts +0 -15
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@storyblok/nuxt-playground",
|
|
3
|
+
"private": true,
|
|
4
|
+
"scripts": {
|
|
5
|
+
"build": "nuxt build",
|
|
6
|
+
"dev": "nuxt dev",
|
|
7
|
+
"demo-ssl": "NODE_TLS_REJECT_UNAUTHORIZED=0 nuxt dev --https",
|
|
8
|
+
"generate": "nuxt generate",
|
|
9
|
+
"preview": "nuxt preview",
|
|
10
|
+
"postinstall": "nuxt prepare"
|
|
11
|
+
},
|
|
12
|
+
"devDependencies": {
|
|
13
|
+
"@nuxt/devtools": "^0.7.1",
|
|
14
|
+
"@types/node": "^18",
|
|
15
|
+
"nuxt": "^3.6.5"
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
<script setup>
|
|
2
|
+
const { slug } = useRoute().params;
|
|
3
|
+
const story = await useAsyncStoryblok(
|
|
4
|
+
slug && slug.length > 0 ? slug.join("/") : "home",
|
|
5
|
+
{
|
|
6
|
+
version: "draft",
|
|
7
|
+
language: "en",
|
|
8
|
+
resolve_relations: ["popular-articles.articles"]
|
|
9
|
+
}
|
|
10
|
+
);
|
|
11
|
+
</script>
|
|
12
|
+
|
|
13
|
+
<template>
|
|
14
|
+
<div>
|
|
15
|
+
<StoryblokComponent v-if="story" :blok="story.content" />
|
|
16
|
+
</div>
|
|
17
|
+
</template>
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
// const storyblokApi = useStoryblokApi();
|
|
3
|
+
// // Checking custom Flush method
|
|
4
|
+
// storyblokApi.flushCache();
|
|
5
|
+
|
|
6
|
+
const story = await useAsyncStoryblok("vue", {
|
|
7
|
+
version: "draft",
|
|
8
|
+
language: "en",
|
|
9
|
+
resolve_relations: "popular-articles.articles"
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
const richText = computed(() => renderRichText(story.value.content.richText));
|
|
13
|
+
</script>
|
|
14
|
+
|
|
15
|
+
<template>
|
|
16
|
+
<div>
|
|
17
|
+
<NuxtLink to="vue"> Vue </NuxtLink>
|
|
18
|
+
<div v-html="richText" />
|
|
19
|
+
<StoryblokComponent v-if="story" :blok="story.content" />
|
|
20
|
+
</div>
|
|
21
|
+
</template>
|
|
Binary file
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
defineProps({
|
|
3
|
+
blok: {
|
|
4
|
+
type: Object,
|
|
5
|
+
required: true
|
|
6
|
+
}
|
|
7
|
+
});
|
|
8
|
+
</script>
|
|
9
|
+
|
|
10
|
+
<template>
|
|
11
|
+
<div v-editable="blok" class="py-2" data-test="feature">
|
|
12
|
+
<h1 class="text-lg">
|
|
13
|
+
{{ blok.name }}
|
|
14
|
+
</h1>
|
|
15
|
+
</div>
|
|
16
|
+
</template>
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
defineProps({
|
|
3
|
+
blok: {
|
|
4
|
+
type: Object,
|
|
5
|
+
required: true
|
|
6
|
+
}
|
|
7
|
+
});
|
|
8
|
+
</script>
|
|
9
|
+
<template>
|
|
10
|
+
<div v-editable="blok" class="flex py-8 mb-6" data-test="grid">
|
|
11
|
+
<div
|
|
12
|
+
v-for="subBlok in blok.columns"
|
|
13
|
+
:key="subBlok._uid"
|
|
14
|
+
class="flex-auto px-6"
|
|
15
|
+
>
|
|
16
|
+
<StoryblokComponent :blok="subBlok" />
|
|
17
|
+
</div>
|
|
18
|
+
</div>
|
|
19
|
+
</template>
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
<script setup>
|
|
2
|
+
defineProps({
|
|
3
|
+
blok: {
|
|
4
|
+
type: Object,
|
|
5
|
+
required: true
|
|
6
|
+
}
|
|
7
|
+
});
|
|
8
|
+
</script>
|
|
9
|
+
|
|
10
|
+
<template>
|
|
11
|
+
<div v-editable="blok" class="px-6" data-test="page">
|
|
12
|
+
<component
|
|
13
|
+
:is="subBlok.component"
|
|
14
|
+
v-for="subBlok in blok.body"
|
|
15
|
+
:key="subBlok._uid"
|
|
16
|
+
:blok="subBlok"
|
|
17
|
+
/>
|
|
18
|
+
</div>
|
|
19
|
+
</template>
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
defineProps({
|
|
3
|
+
blok: {
|
|
4
|
+
type: Object,
|
|
5
|
+
required: true
|
|
6
|
+
}
|
|
7
|
+
});
|
|
8
|
+
</script>
|
|
9
|
+
|
|
10
|
+
<template>
|
|
11
|
+
<div
|
|
12
|
+
v-editable="blok"
|
|
13
|
+
:cat="$attrs.cat"
|
|
14
|
+
class="py-8 mb-6 text-5xl font-bold text-center"
|
|
15
|
+
data-test="teaser"
|
|
16
|
+
>
|
|
17
|
+
{{ blok.headline }}
|
|
18
|
+
</div>
|
|
19
|
+
</template>
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export default defineNuxtConfig({
|
|
2
|
+
modules: [
|
|
3
|
+
[
|
|
4
|
+
"@storyblok/nuxt",
|
|
5
|
+
{
|
|
6
|
+
accessToken: "OurklwV5XsDJTIE1NJaD2wtt",
|
|
7
|
+
apiOptions: {
|
|
8
|
+
region: ""
|
|
9
|
+
},
|
|
10
|
+
devtools: true,
|
|
11
|
+
// enableSudoMode: true /* (or legacy) usePlugin: false */
|
|
12
|
+
},
|
|
13
|
+
],
|
|
14
|
+
'@nuxt/devtools'
|
|
15
|
+
],
|
|
16
|
+
app: {
|
|
17
|
+
head: {
|
|
18
|
+
script: [{ src: "https://cdn.tailwindcss.com" }]
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
vite: {
|
|
22
|
+
optimizeDeps: { exclude: ["fsevents"] },
|
|
23
|
+
}
|
|
24
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"private": true,
|
|
3
|
+
"scripts": {
|
|
4
|
+
"demo": "nuxt dev",
|
|
5
|
+
"demo-ssl": "NODE_TLS_REJECT_UNAUTHORIZED=0 nuxt dev --https",
|
|
6
|
+
"build": "nuxt build",
|
|
7
|
+
"generate": "nuxt generate",
|
|
8
|
+
"start": "nuxt preview"
|
|
9
|
+
},
|
|
10
|
+
"devDependencies": {
|
|
11
|
+
"@nuxt/devtools": "^0.6.1",
|
|
12
|
+
"@storyblok/nuxt": "^0.0.1",
|
|
13
|
+
"nuxt": "^3.5.3"
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
<script setup>
|
|
2
|
+
const route = useRoute();
|
|
3
|
+
|
|
4
|
+
const story = ref();
|
|
5
|
+
try {
|
|
6
|
+
story.value = await useAsyncStoryblok(route.path, {
|
|
7
|
+
version: "draft",
|
|
8
|
+
language: "en",
|
|
9
|
+
resolve_relations: ["popular-articles.articles"]
|
|
10
|
+
});
|
|
11
|
+
} catch (error) {
|
|
12
|
+
console.log(error);
|
|
13
|
+
}
|
|
14
|
+
</script>
|
|
15
|
+
|
|
16
|
+
<template>
|
|
17
|
+
<div>
|
|
18
|
+
{{ story }}
|
|
19
|
+
</div>
|
|
20
|
+
</template>
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
// const storyblokApi = useStoryblokApi();
|
|
3
|
+
// // Checking custom Flush method
|
|
4
|
+
// storyblokApi.flushCache();
|
|
5
|
+
|
|
6
|
+
const story = await useAsyncStoryblok("vue", {
|
|
7
|
+
version: "draft",
|
|
8
|
+
language: "en",
|
|
9
|
+
resolve_relations: "popular-articles.articles"
|
|
10
|
+
});
|
|
11
|
+
const richText = computed(() => renderRichText(story.value.content.richText));
|
|
12
|
+
</script>
|
|
13
|
+
|
|
14
|
+
<template>
|
|
15
|
+
<div>
|
|
16
|
+
<div v-html="richText"></div>
|
|
17
|
+
<StoryblokComponent v-if="story" :blok="story.content" />
|
|
18
|
+
</div>
|
|
19
|
+
</template>
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
<script setup lant="ts">
|
|
2
|
+
const story = ref(null);
|
|
3
|
+
|
|
4
|
+
onMounted(async () => {
|
|
5
|
+
const storyblokApi = useStoryblokApi();
|
|
6
|
+
const { data } = await storyblokApi.get("cdn/stories/vue/test", {
|
|
7
|
+
version: "draft"
|
|
8
|
+
});
|
|
9
|
+
story.value = data.story;
|
|
10
|
+
|
|
11
|
+
useStoryblokBridge(story.value.id, (evStory) => (story.value = evStory));
|
|
12
|
+
});
|
|
13
|
+
</script>
|
|
14
|
+
|
|
15
|
+
<template>
|
|
16
|
+
<StoryblokComponent v-if="story" :blok="story.content" />
|
|
17
|
+
</template>
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/* import { StoryblokVue, apiPlugin } from "@storyblok/vue";
|
|
2
|
+
|
|
3
|
+
export default defineNuxtPlugin(({ vueApp }) => {
|
|
4
|
+
vueApp.use(StoryblokVue, {
|
|
5
|
+
accessToken: "OurklwV5XsDJTIE1NJaD2wtt",
|
|
6
|
+
apiOptions: {
|
|
7
|
+
cache: {
|
|
8
|
+
type: "custom",
|
|
9
|
+
custom: {
|
|
10
|
+
flush() {
|
|
11
|
+
console.log("all right");
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
use: [apiPlugin]
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
export default defineNuxtPlugin(() => {});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
defineProps({
|
|
3
|
+
blok: {
|
|
4
|
+
type: Object,
|
|
5
|
+
required: true
|
|
6
|
+
}
|
|
7
|
+
});
|
|
8
|
+
</script>
|
|
9
|
+
<template>
|
|
10
|
+
<div v-editable="blok" class="flex py-8 mb-6" data-test="grid">
|
|
11
|
+
<div
|
|
12
|
+
v-for="subBlok in blok.columns"
|
|
13
|
+
:key="subBlok._uid"
|
|
14
|
+
class="flex-auto px-6"
|
|
15
|
+
>
|
|
16
|
+
<StoryblokComponent :blok="subBlok" />
|
|
17
|
+
</div>
|
|
18
|
+
</div>
|
|
19
|
+
</template>
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
<script setup>
|
|
2
|
+
defineProps({
|
|
3
|
+
blok: {
|
|
4
|
+
type: Object,
|
|
5
|
+
required: true
|
|
6
|
+
}
|
|
7
|
+
});
|
|
8
|
+
</script>
|
|
9
|
+
|
|
10
|
+
<template>
|
|
11
|
+
<div v-editable="blok" class="px-6" data-test="page">
|
|
12
|
+
<component
|
|
13
|
+
:is="subBlok.component"
|
|
14
|
+
v-for="subBlok in blok.body"
|
|
15
|
+
:key="subBlok._uid"
|
|
16
|
+
:blok="subBlok"
|
|
17
|
+
/>
|
|
18
|
+
</div>
|
|
19
|
+
</template>
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
defineProps({
|
|
3
|
+
blok: {
|
|
4
|
+
type: Object,
|
|
5
|
+
required: true
|
|
6
|
+
}
|
|
7
|
+
});
|
|
8
|
+
</script>
|
|
9
|
+
|
|
10
|
+
<template>
|
|
11
|
+
<div
|
|
12
|
+
v-editable="blok"
|
|
13
|
+
:cat="$attrs.cat"
|
|
14
|
+
class="py-8 mb-6 text-5xl font-bold text-center"
|
|
15
|
+
data-test="teaser"
|
|
16
|
+
>
|
|
17
|
+
{{ blok.headline }}
|
|
18
|
+
</div>
|
|
19
|
+
</template>
|
package/src/module.ts
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import {
|
|
2
|
+
defineNuxtModule,
|
|
3
|
+
addPlugin,
|
|
4
|
+
addComponentsDir,
|
|
5
|
+
addImports,
|
|
6
|
+
addImportsDir,
|
|
7
|
+
createResolver
|
|
8
|
+
} from "@nuxt/kit";
|
|
9
|
+
import { NuxtHookName } from "@nuxt/schema";
|
|
10
|
+
|
|
11
|
+
export interface ModuleOptions {
|
|
12
|
+
accessToken: string,
|
|
13
|
+
enableSudoMode: boolean,
|
|
14
|
+
usePlugin: boolean, // legacy opt. for enableSudoMode
|
|
15
|
+
bridge: boolean, // storyblok bridge on/off
|
|
16
|
+
devtools: boolean, // enable nuxt/devtools integration
|
|
17
|
+
apiOptions: any, // storyblok-js-client options
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export default defineNuxtModule<ModuleOptions>({
|
|
21
|
+
meta: {
|
|
22
|
+
name: "@storyblok/nuxt",
|
|
23
|
+
configKey: "storyblok"
|
|
24
|
+
},
|
|
25
|
+
defaults: {
|
|
26
|
+
accessToken: '',
|
|
27
|
+
enableSudoMode: false,
|
|
28
|
+
usePlugin: true, // legacy opt. for enableSudoMode
|
|
29
|
+
bridge: true,
|
|
30
|
+
devtools: false,
|
|
31
|
+
apiOptions: {},
|
|
32
|
+
},
|
|
33
|
+
setup(options, nuxt) {
|
|
34
|
+
const resolver = createResolver(import.meta.url);
|
|
35
|
+
|
|
36
|
+
if(nuxt.options.vite.optimizeDeps) {
|
|
37
|
+
nuxt.options.vite.optimizeDeps.include =
|
|
38
|
+
nuxt.options.vite.optimizeDeps.include || [];
|
|
39
|
+
nuxt.options.vite.optimizeDeps.include.push("@storyblok/nuxt");
|
|
40
|
+
nuxt.options.vite.optimizeDeps.include.push("@storyblok/vue");
|
|
41
|
+
|
|
42
|
+
nuxt.options.vite.optimizeDeps.exclude =
|
|
43
|
+
nuxt.options.vite.optimizeDeps.exclude || [];
|
|
44
|
+
nuxt.options.vite.optimizeDeps.exclude.push("fsevents");
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
// Enable dirs
|
|
49
|
+
// nuxt.options.components.dirs = ["~/components/storyblok"];
|
|
50
|
+
addComponentsDir({ path: "~/storyblok", global: true, pathPrefix: false });
|
|
51
|
+
|
|
52
|
+
nuxt.options.build.transpile.push(resolver.resolve("./runtime"));
|
|
53
|
+
nuxt.options.build.transpile.push("@storyblok/nuxt");
|
|
54
|
+
nuxt.options.build.transpile.push("@storyblok/vue");
|
|
55
|
+
|
|
56
|
+
// Add plugin
|
|
57
|
+
nuxt.options.runtimeConfig.public.storyblok = options;
|
|
58
|
+
const enablePluginCondition = options.usePlugin === true && options.enableSudoMode === false;
|
|
59
|
+
if (enablePluginCondition) {
|
|
60
|
+
addPlugin(resolver.resolve("./runtime/plugin"));
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Add auto imports
|
|
64
|
+
const names = [
|
|
65
|
+
"useStoryblok",
|
|
66
|
+
"useStoryblokApi",
|
|
67
|
+
"useStoryblokBridge",
|
|
68
|
+
"renderRichText",
|
|
69
|
+
"RichTextSchema"
|
|
70
|
+
];
|
|
71
|
+
for (const name of names) {
|
|
72
|
+
addImports({ name, as: name, from: "@storyblok/vue" });
|
|
73
|
+
}
|
|
74
|
+
addImportsDir(resolver.resolve("./runtime/composables"));
|
|
75
|
+
|
|
76
|
+
if (options.devtools) {
|
|
77
|
+
nuxt.hook('devtools:customTabs' as NuxtHookName, (iframeTabs: Array<unknown>): void => {
|
|
78
|
+
iframeTabs.push({
|
|
79
|
+
name: 'storyblok',
|
|
80
|
+
title: 'Storyblok',
|
|
81
|
+
icon: 'i-logos-storyblok-icon',
|
|
82
|
+
view: {
|
|
83
|
+
type: 'iframe',
|
|
84
|
+
src: 'https://app.storyblok.com/#!/me/spaces/'
|
|
85
|
+
}
|
|
86
|
+
})
|
|
87
|
+
})
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { useStoryblokApi, useStoryblokBridge } from "@storyblok/vue";
|
|
2
|
+
import type { ISbStoriesParams, StoryblokBridgeConfigV2, ISbStoryData } from '@storyblok/vue';
|
|
3
|
+
import { useState, onMounted } from "#imports";
|
|
4
|
+
|
|
5
|
+
export const useAsyncStoryblok = async (
|
|
6
|
+
url: string,
|
|
7
|
+
apiOptions: ISbStoriesParams = {},
|
|
8
|
+
bridgeOptions: StoryblokBridgeConfigV2 = {}
|
|
9
|
+
) => {
|
|
10
|
+
const uniqueKey = `${JSON.stringify(apiOptions)}${url}`;
|
|
11
|
+
const story = useState<ISbStoryData>(`${uniqueKey}-state`);
|
|
12
|
+
const storyblokApiInstance = useStoryblokApi();
|
|
13
|
+
|
|
14
|
+
onMounted(() => {
|
|
15
|
+
if (story.value && story.value.id) {
|
|
16
|
+
useStoryblokBridge(
|
|
17
|
+
story.value.id,
|
|
18
|
+
evStory => (story.value = evStory),
|
|
19
|
+
bridgeOptions,
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
if (!story.value) {
|
|
25
|
+
const { data } = await storyblokApiInstance.get(
|
|
26
|
+
`cdn/stories/${url}`,
|
|
27
|
+
apiOptions
|
|
28
|
+
);
|
|
29
|
+
story.value = data.story;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
return story;
|
|
33
|
+
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { StoryblokVue, apiPlugin } from "@storyblok/vue";
|
|
2
2
|
import { defineNuxtPlugin, useRuntimeConfig } from "#app";
|
|
3
|
+
|
|
3
4
|
export default defineNuxtPlugin(({ vueApp }) => {
|
|
4
5
|
let { storyblok } = useRuntimeConfig().public;
|
|
5
6
|
storyblok = JSON.parse(JSON.stringify(storyblok));
|
package/tsconfig.json
ADDED
package/dist/module.cjs
DELETED
package/dist/module.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import * as _nuxt_schema from '@nuxt/schema';
|
|
2
|
-
|
|
3
|
-
interface ModuleOptions {
|
|
4
|
-
accessToken: string;
|
|
5
|
-
enableSudoMode: boolean;
|
|
6
|
-
usePlugin: boolean;
|
|
7
|
-
bridge: boolean;
|
|
8
|
-
devtools: boolean;
|
|
9
|
-
apiOptions: any;
|
|
10
|
-
}
|
|
11
|
-
declare const _default: _nuxt_schema.NuxtModule<ModuleOptions>;
|
|
12
|
-
|
|
13
|
-
export { ModuleOptions, _default as default };
|
package/dist/module.json
DELETED
package/dist/module.mjs
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { defineNuxtModule, createResolver, addComponentsDir, addPlugin, addImports, addImportsDir } from '@nuxt/kit';
|
|
2
|
-
|
|
3
|
-
const module = defineNuxtModule({
|
|
4
|
-
meta: {
|
|
5
|
-
name: "@storyblok/nuxt",
|
|
6
|
-
configKey: "storyblok"
|
|
7
|
-
},
|
|
8
|
-
defaults: {
|
|
9
|
-
accessToken: "",
|
|
10
|
-
enableSudoMode: false,
|
|
11
|
-
usePlugin: true,
|
|
12
|
-
// legacy opt. for enableSudoMode
|
|
13
|
-
bridge: true,
|
|
14
|
-
devtools: false,
|
|
15
|
-
apiOptions: {}
|
|
16
|
-
},
|
|
17
|
-
setup(options, nuxt) {
|
|
18
|
-
const resolver = createResolver(import.meta.url);
|
|
19
|
-
nuxt.options.vite.optimizeDeps.include = nuxt.options.vite.optimizeDeps.include || [];
|
|
20
|
-
nuxt.options.vite.optimizeDeps.include.push("@storyblok/nuxt");
|
|
21
|
-
nuxt.options.vite.optimizeDeps.include.push("@storyblok/vue");
|
|
22
|
-
addComponentsDir({ path: "~/storyblok", global: true, pathPrefix: false });
|
|
23
|
-
nuxt.options.build.transpile.push(resolver.resolve("./runtime"));
|
|
24
|
-
nuxt.options.build.transpile.push("@storyblok/nuxt");
|
|
25
|
-
nuxt.options.build.transpile.push("@storyblok/vue");
|
|
26
|
-
nuxt.options.runtimeConfig.public.storyblok = options;
|
|
27
|
-
const enablePluginCondition = options.usePlugin === true && options.enableSudoMode === false;
|
|
28
|
-
if (enablePluginCondition) {
|
|
29
|
-
addPlugin(resolver.resolve("./runtime/plugin"));
|
|
30
|
-
}
|
|
31
|
-
const names = [
|
|
32
|
-
"useStoryblok",
|
|
33
|
-
"useStoryblokApi",
|
|
34
|
-
"useStoryblokBridge",
|
|
35
|
-
"renderRichText",
|
|
36
|
-
"RichTextSchema"
|
|
37
|
-
];
|
|
38
|
-
for (const name of names) {
|
|
39
|
-
addImports({ name, as: name, from: "@storyblok/vue" });
|
|
40
|
-
}
|
|
41
|
-
addImportsDir(resolver.resolve("./runtime/composables"));
|
|
42
|
-
if (options.devtools) {
|
|
43
|
-
nuxt.hook("devtools:customTabs", (iframeTabs) => {
|
|
44
|
-
iframeTabs.push({
|
|
45
|
-
name: "storyblok",
|
|
46
|
-
title: "Storyblok",
|
|
47
|
-
icon: "i-logos-storyblok-icon",
|
|
48
|
-
view: {
|
|
49
|
-
type: "iframe",
|
|
50
|
-
src: "https://app.storyblok.com/#!/me/spaces/"
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
export { module as default };
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { useStoryblokApi, useStoryblokBridge } from "@storyblok/vue";
|
|
2
|
-
import { useAsyncData, useState, onMounted, createError } from "#imports";
|
|
3
|
-
export const useAsyncStoryblok = async (url, apiOptions = {}, bridgeOptions = {}) => {
|
|
4
|
-
const uniqueKey = `${JSON.stringify(apiOptions)}${url}`;
|
|
5
|
-
const story = useState(`${uniqueKey}-state`, () => ({}));
|
|
6
|
-
const storyblokApiInstance = useStoryblokApi();
|
|
7
|
-
onMounted(() => {
|
|
8
|
-
if (story.value && story.value.id) {
|
|
9
|
-
useStoryblokBridge(
|
|
10
|
-
story.value.id,
|
|
11
|
-
(evStory) => story.value = evStory,
|
|
12
|
-
bridgeOptions
|
|
13
|
-
);
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
const { data, error } = await useAsyncData(
|
|
17
|
-
`${uniqueKey}-asyncdata`,
|
|
18
|
-
() => storyblokApiInstance.get(`cdn/stories/${url}`, apiOptions)
|
|
19
|
-
);
|
|
20
|
-
if (error.value?.response && error.value?.response.status >= 400 && error.value?.response.status < 600) {
|
|
21
|
-
throw createError({ statusCode: error.value?.response.status, statusMessage: error.value?.message?.message || "Something went wrong when fetching from storyblok." });
|
|
22
|
-
}
|
|
23
|
-
story.value = data.value?.data.story;
|
|
24
|
-
return story;
|
|
25
|
-
};
|
package/dist/runtime/plugin.d.ts
DELETED
package/dist/types.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import { ModuleOptions } from './module'
|
|
3
|
-
|
|
4
|
-
declare module '@nuxt/schema' {
|
|
5
|
-
interface NuxtConfig { ['storyblok']?: Partial<ModuleOptions> }
|
|
6
|
-
interface NuxtOptions { ['storyblok']?: ModuleOptions }
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
declare module 'nuxt/schema' {
|
|
10
|
-
interface NuxtConfig { ['storyblok']?: Partial<ModuleOptions> }
|
|
11
|
-
interface NuxtOptions { ['storyblok']?: ModuleOptions }
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
export { ModuleOptions, default } from './module'
|