diff --git a/examples/showcase/components/MyI18n.stories.ts b/examples/showcase/components/MyI18n.stories.ts index 360ff135..14ea49fc 100644 --- a/examples/showcase/components/MyI18n.stories.ts +++ b/examples/showcase/components/MyI18n.stories.ts @@ -8,14 +8,11 @@ const meta = { title: 'Modules/I18n', component: MyComponent, argTypes: { - lang: { control: 'select', options: ['en', 'fr', 'ar'] }, - }, // This component will have an automatically generated docsPage entry: https://storybook.js.org/docs/vue/writing-docs/autodocs tags: ['autodocs'], - } satisfies Meta export default meta @@ -36,4 +33,4 @@ export const EnglishStory: Story = { export const ArabicStory: Story = { args: { lang: 'ar' }, -} \ No newline at end of file +} diff --git a/examples/showcase/components/MyI18n.vue b/examples/showcase/components/MyI18n.vue index c1755ca9..d87ae7cf 100644 --- a/examples/showcase/components/MyI18n.vue +++ b/examples/showcase/components/MyI18n.vue @@ -8,28 +8,40 @@ const props = defineProps<{ const { t, locale } = useI18n() const rtl = computed(() => props.lang === 'ar') locale.value = props.lang -watch(() => props.lang, (lang: unknown) => { - locale.value = lang -}) +watch( + () => props.lang, + (lang: unknown) => { + locale.value = lang + }, +) \ No newline at end of file +

language : {{ lang }}

+ diff --git a/examples/showcase/i18n.config.ts b/examples/showcase/i18n.config.ts index 429db21b..28ea84a5 100644 --- a/examples/showcase/i18n.config.ts +++ b/examples/showcase/i18n.config.ts @@ -1,16 +1,16 @@ export default defineI18nConfig(() => ({ - legacy: false, - locale: 'en', - defaultLocale: 'en', - messages: { - en: { - welcome: 'Welcome to Storybook ❤️ {name} ', - }, - fr: { - welcome: 'Bienvenue a Storybook ❤️ {name} ', - }, - ar: { - welcome: ' ناكست ❤️ {name} ❤️ مرحبا بكم في ستوري بوك ', - }, + legacy: false, + locale: 'en', + defaultLocale: 'en', + messages: { + en: { + welcome: 'Welcome to Storybook ❤️ {name} ', }, - })) \ No newline at end of file + fr: { + welcome: 'Bienvenue a Storybook ❤️ {name} ', + }, + ar: { + welcome: ' ناكست ❤️ {name} ❤️ مرحبا بكم في ستوري بوك ', + }, + }, +})) diff --git a/package.json b/package.json index bf792bda..cc3e1a51 100755 --- a/package.json +++ b/package.json @@ -1,92 +1,92 @@ { - "name": "nuxt-storybook", - "version": "", - "license": "MIT", - "repository": "nuxt-modules/storybook", - "author": { - "name": "ChakAs3", - "email": "javachakir@gmail.com" - }, - "type": "module", - "scripts": { - "dev": "pnpm run --filter=./playground/** dev", - "dev:prepare": "pnpm run --recursive --filter=./packages/* --parallel dev:prepare && pnpm run prepare", - "dev:build": "pnpm run --filter=./playground/** build", - "playground:storybook:dev": "pnpm run --filter=./playground/** storybook", - "playground:storybook:build": "cd playground && pnpm run build-storybook", - "playground:storybook:publish": "chromatic --exit-zero-on-changes --build-script-name playground:storybook:build --project-token=chpt_d7cf5e98426e11e", - "example:starter:dev": "pnpm run --filter=./examples/starter/** dev", - "example:starter:build": "pnpm run --filter=./examples/starter/** build", - "example:starter:storybook:build": "pnpm run --filter=./examples/starter/** build-storybook", - "example:starter:storybook:publish": "chromatic --exit-zero-on-changes --build-script-name example:starter:storybook:build --project-token=chpt_dc04103f8a32bfa", - "example:tailwind:dev": "pnpm run --filter=./examples/tailwind/** dev", - "example:tailwind:build": "pnpm run --filter=./examples/tailwind/** build", - "example:tailwind:storybook:build": "pnpm run --filter=./examples/tailwind/** build-storybook", - "example:tailwind:storybook:publish": "chromatic --exit-zero-on-changes --build-script-name example:tailwind:storybook:build --project-token=chpt_fbfe47dc27d4064", - "example:showcase:dev": "pnpm run --filter=./examples/showcase/** dev", - "example:showcase:build": "pnpm run --filter=./examples/showcase/** build", - "example:showcase:storybook:build": "pnpm run --filter=./examples/showcase/** build-storybook", - "example:showcase:storybook:publish": "chromatic --exit-zero-on-changes --build-script-name example:showcase:storybook:build --project-token=chpt_a53adf402cb628c", - "build": "pnpm run --recursive --filter=./packages/* build", - "package": "cd ./packages/storybook-addon && pnpm pack && cd ../nuxt-module && pnpm pack", - "lint": "pnpm lint:eslint && pnpm lint:prettier", - "lint:eslint": "eslint --max-warnings=0 --report-unused-disable-directives .", - "lint:prettier": "prettier --check .", - "lint:fix": "pnpm lint:eslint --fix && pnpm lint:prettier --write", - "release": "pnpm jiti prepare-release.ts && pnpm publish --recursive && git push --follow-tags", - "nightly-release": "pnpm jiti prepare-release.ts --nightly && pnpm publish --recursive --tag nightly --access public --no-git-checks --provenance --report-summary", - "prepare": "pnpm run --filter=./playground/** prepare", - "docs:dev": "pnpm run --filter=./docs/** dev", - "docs:build": "pnpm run --filter=./docs/** build", - "docs:generate": "pnpm run --filter=./docs/** generate", - "test": "vitest run", - "test:watch": "vitest watch", - "test:coverage": "vitest --coverage", - "test:playwright": "pnpm exec playwright test" - }, - "packageManager": "pnpm@9.15.0", - "devDependencies": { - "@nuxt/eslint-config": "0.7.2", - "@nuxt/test-utils": "3.15.1", - "@vitest/coverage-v8": "2.1.8", - "@playwright/test": "1.49.0", - "@types/node": "22.10.1", - "changelogen": "0.5.7", - "chromatic": "11.20.0", - "eslint": "9.16.0", - "jiti": "2.4.1", - "nuxt": "3.14.1592", - "prettier": "3.4.2", - "release-it": "17.10.0", - "semver": "7.6.3", - "typescript": "5.7.2", - "vitest": "2.1.8" - }, - "publishConfig": { - "access": "public" - }, - "pnpm": { - "peerDependencyRules": { - "ignoreMissing": [ - "webpack", - "vue" - ] - } + "name": "nuxt-storybook", + "version": "", + "license": "MIT", + "repository": "nuxt-modules/storybook", + "author": { + "name": "ChakAs3", + "email": "javachakir@gmail.com" + }, + "type": "module", + "scripts": { + "dev": "pnpm run --filter=./playground/** dev", + "dev:prepare": "pnpm run --recursive --filter=./packages/* --parallel dev:prepare && pnpm run prepare", + "dev:build": "pnpm run --filter=./playground/** build", + "playground:storybook:dev": "pnpm run --filter=./playground/** storybook", + "playground:storybook:build": "cd playground && pnpm run build-storybook", + "playground:storybook:publish": "chromatic --exit-zero-on-changes --build-script-name playground:storybook:build --project-token=chpt_d7cf5e98426e11e", + "example:starter:dev": "pnpm run --filter=./examples/starter/** dev", + "example:starter:build": "pnpm run --filter=./examples/starter/** build", + "example:starter:storybook:build": "pnpm run --filter=./examples/starter/** build-storybook", + "example:starter:storybook:publish": "chromatic --exit-zero-on-changes --build-script-name example:starter:storybook:build --project-token=chpt_dc04103f8a32bfa", + "example:tailwind:dev": "pnpm run --filter=./examples/tailwind/** dev", + "example:tailwind:build": "pnpm run --filter=./examples/tailwind/** build", + "example:tailwind:storybook:build": "pnpm run --filter=./examples/tailwind/** build-storybook", + "example:tailwind:storybook:publish": "chromatic --exit-zero-on-changes --build-script-name example:tailwind:storybook:build --project-token=chpt_fbfe47dc27d4064", + "example:showcase:dev": "pnpm run --filter=./examples/showcase/** dev", + "example:showcase:build": "pnpm run --filter=./examples/showcase/** build", + "example:showcase:storybook:build": "pnpm run --filter=./examples/showcase/** build-storybook", + "example:showcase:storybook:publish": "chromatic --exit-zero-on-changes --build-script-name example:showcase:storybook:build --project-token=chpt_a53adf402cb628c", + "build": "pnpm run --recursive --filter=./packages/* build", + "package": "cd ./packages/storybook-addon && pnpm pack && cd ../nuxt-module && pnpm pack", + "lint": "pnpm lint:eslint && pnpm lint:prettier", + "lint:eslint": "eslint --max-warnings=0 --report-unused-disable-directives .", + "lint:prettier": "prettier --check .", + "lint:fix": "pnpm lint:eslint --fix && pnpm lint:prettier --write", + "release": "pnpm jiti prepare-release.ts && pnpm publish --recursive && git push --follow-tags", + "nightly-release": "pnpm jiti prepare-release.ts --nightly && pnpm publish --recursive --tag nightly --access public --no-git-checks --provenance --report-summary", + "prepare": "pnpm run --filter=./playground/** prepare", + "docs:dev": "pnpm run --filter=./docs/** dev", + "docs:build": "pnpm run --filter=./docs/** build", + "docs:generate": "pnpm run --filter=./docs/** generate", + "test": "vitest run", + "test:watch": "vitest watch", + "test:coverage": "vitest --coverage", + "test:playwright": "pnpm exec playwright test" + }, + "packageManager": "pnpm@9.15.0", + "devDependencies": { + "@nuxt/eslint-config": "0.7.2", + "@nuxt/test-utils": "3.15.1", + "@vitest/coverage-v8": "2.1.8", + "@playwright/test": "1.49.0", + "@types/node": "22.10.1", + "changelogen": "0.5.7", + "chromatic": "11.20.0", + "eslint": "9.16.0", + "jiti": "2.4.1", + "nuxt": "3.14.1592", + "prettier": "3.4.2", + "release-it": "17.10.0", + "semver": "7.6.3", + "typescript": "5.7.2", + "vitest": "2.1.8" + }, + "publishConfig": { + "access": "public" + }, + "pnpm": { + "peerDependencyRules": { + "ignoreMissing": [ + "webpack", + "vue" + ] + } + }, + "release-it": { + "git": { + "commitMessage": "chore(release): release v${version}" }, - "release-it": { - "git": { - "commitMessage": "chore(release): release v${version}" - }, - "github": { - "release": true, - "releaseName": "v${version}" - }, - "hooks": { - "after:bump": "npx changelogen@latest --no-commit --no-tag --output --r $(node -p \"require('./package.json').version\")" - } + "github": { + "release": true, + "releaseName": "v${version}" }, - "prettier": { - "semi": false, - "singleQuote": true + "hooks": { + "after:bump": "npx changelogen@latest --no-commit --no-tag --output --r $(node -p \"require('./package.json').version\")" } -} \ No newline at end of file + }, + "prettier": { + "semi": false, + "singleQuote": true + } +} diff --git a/packages/storybook-addon/src/preset.ts b/packages/storybook-addon/src/preset.ts index 2d2e3939..b6e88078 100644 --- a/packages/storybook-addon/src/preset.ts +++ b/packages/storybook-addon/src/preset.ts @@ -200,7 +200,7 @@ function mergeViteConfig( vue: 'vue/dist/vue.esm-bundler.js', }, }, - + plugins: [ replace({ values: { diff --git a/packages/storybook-addon/src/preview.ts b/packages/storybook-addon/src/preview.ts index a95d42f9..4acd425f 100644 --- a/packages/storybook-addon/src/preview.ts +++ b/packages/storybook-addon/src/preview.ts @@ -25,20 +25,19 @@ import plugins from '#build/plugins' // eslint-disable-next-line @typescript-eslint/no-explicit-any const pluginsTyped: Array> = plugins - setup(async (vueApp, storyContext) => { // We key the Nuxt apps to the id of the story // This is not totally correct, since the storybook vue renderer actually uses the canvas element // Also this doesn't allow to "forceRemount" // TODO: Improve this (needs PR to storybook to pass the necessary infos to this function) - + // use storyContext.canvasElement.id as key as it's unique for each rendered story // storyContext.id is same for 2 stories in Docs mode, Primary story and the first story in stories are the same story and have the same id const key = storyContext?.canvasElement.id if (!key) { throw new Error('StoryContext is not provided') } - + // Create a new nuxt app for each story const storyNuxtAppId = `nuxt-app-${key}` const storyNuxtCtx = getContext(storyNuxtAppId) diff --git a/playground/i18n.config.ts b/playground/i18n.config.ts index 429db21b..28ea84a5 100644 --- a/playground/i18n.config.ts +++ b/playground/i18n.config.ts @@ -1,16 +1,16 @@ export default defineI18nConfig(() => ({ - legacy: false, - locale: 'en', - defaultLocale: 'en', - messages: { - en: { - welcome: 'Welcome to Storybook ❤️ {name} ', - }, - fr: { - welcome: 'Bienvenue a Storybook ❤️ {name} ', - }, - ar: { - welcome: ' ناكست ❤️ {name} ❤️ مرحبا بكم في ستوري بوك ', - }, + legacy: false, + locale: 'en', + defaultLocale: 'en', + messages: { + en: { + welcome: 'Welcome to Storybook ❤️ {name} ', }, - })) \ No newline at end of file + fr: { + welcome: 'Bienvenue a Storybook ❤️ {name} ', + }, + ar: { + welcome: ' ناكست ❤️ {name} ❤️ مرحبا بكم في ستوري بوك ', + }, + }, +})) diff --git a/playground/nuxt.config.ts b/playground/nuxt.config.ts index c63afedc..a57b1987 100644 --- a/playground/nuxt.config.ts +++ b/playground/nuxt.config.ts @@ -1,13 +1,17 @@ // https://nuxt.com/docs/api/configuration/nuxt-config export default defineNuxtConfig({ devtools: { enabled: true }, - modules: ['../packages/nuxt-module/src/module', '@nuxt/test-utils/module', '@nuxtjs/i18n'], + modules: [ + '../packages/nuxt-module/src/module', + '@nuxt/test-utils/module', + '@nuxtjs/i18n', + ], storybook: { // Very verbose logs for debugging logLevel: Number.POSITIVE_INFINITY, }, - + i18n: { locales: ['en', 'fr', 'ar'], defaultLocale: 'en', diff --git a/playground/stories/MyI18n.stories.ts b/playground/stories/MyI18n.stories.ts index 8531af85..1f2ca17a 100644 --- a/playground/stories/MyI18n.stories.ts +++ b/playground/stories/MyI18n.stories.ts @@ -8,14 +8,11 @@ const meta = { title: 'Plugins/I18n', component: MyComponent, argTypes: { - lang: { control: 'select', options: ['en', 'fr', 'ar'] }, - }, // This component will have an automatically generated docsPage entry: https://storybook.js.org/docs/vue/writing-docs/autodocs tags: ['autodocs'], - } satisfies Meta export default meta @@ -36,4 +33,4 @@ export const EnglishStory: Story = { export const ArabicStory: Story = { args: { lang: 'ar' }, -} \ No newline at end of file +} diff --git a/playground/stories/MyI18n.vue b/playground/stories/MyI18n.vue index d25e601a..9f445f33 100644 --- a/playground/stories/MyI18n.vue +++ b/playground/stories/MyI18n.vue @@ -8,28 +8,40 @@ const props = defineProps<{ const { t, locale } = useI18n() const rtl = computed(() => props.lang === 'ar') locale.value = props.lang -watch(() => props.lang, (lang: unknown) => { - locale.value = lang -}) +watch( + () => props.lang, + (lang: unknown) => { + locale.value = lang + }, +) \ No newline at end of file +

language : {{ lang }}

+