From 658df14a785a847687e7480b6db2b2de4af14796 Mon Sep 17 00:00:00 2001 From: kazuya kawaguchi Date: Sun, 2 Oct 2022 01:40:45 +0900 Subject: [PATCH] feat: support `defaultDirection` option (#1541) --- TODO.md | 2 +- docs/content/40.options/2.routing.md | 8 +- docs/content/50.API/2.vue-i18n.md | 5 - package.json | 2 +- specs/fixtures/basic/pages/index.vue | 9 +- specs/fixtures/head/app.vue | 4 +- specs/helper.ts | 29 +- specs/seo/baseUrl.spec.ts | 37 ++ specs/seo/metaComponent.spec.ts | 3 + specs/seo/useHead.spec.ts | 6 +- src/runtime/vue-i18n-bridge.d.ts | 6 +- yarn.lock | 546 +++++++++++++++++---------- 12 files changed, 431 insertions(+), 226 deletions(-) create mode 100644 specs/seo/baseUrl.spec.ts diff --git a/TODO.md b/TODO.md index 5de4e7080..ece7e89c1 100644 --- a/TODO.md +++ b/TODO.md @@ -55,7 +55,7 @@ This todo is based on [nuxt/i18n](https://i18n.nuxtjs.org/) docs. - [x] getBrowserLocale - [x] finalizePendingLocaleChange - [x] waitForPendingLocaleChange -- [ ] defaultDirection +- [x] defaultDirection - [x] defaultLocale - [x] localeCodes - [x] locales diff --git a/docs/content/40.options/2.routing.md b/docs/content/40.options/2.routing.md index 7dd5cdfbd..2d2828245 100644 --- a/docs/content/40.options/2.routing.md +++ b/docs/content/40.options/2.routing.md @@ -64,10 +64,10 @@ export default { ## `defaultDirection` -::alert{type="warning"} -// TODO: -🚧 This feature is not implemented yet. -:: +- type: `string` +- default: `ltr` + +The app's default direction. Will only be used when `dir` is not specified. ## `defaultLocale` diff --git a/docs/content/50.API/2.vue-i18n.md b/docs/content/50.API/2.vue-i18n.md index 47d32a38b..e4f0863c5 100644 --- a/docs/content/50.API/2.vue-i18n.md +++ b/docs/content/50.API/2.vue-i18n.md @@ -63,11 +63,6 @@ Routing strategy as specified in options. ### defaultDirection -::alert{type="warning"} -// TODO: -🚧 This feature is not implemented yet. -:: - - **Type**: `Directions` Default direction as specified in options. diff --git a/package.json b/package.json index a3fc4d456..38c5f9fb4 100644 --- a/package.json +++ b/package.json @@ -99,8 +99,8 @@ "eslint-config-prettier": "^8.5.0", "eslint-plugin-prettier": "^4.0.0", "gh-changelogen": "^0.2.6", - "happy-dom": "^6.0.4", "jiti": "^1.14.0", + "jsdom": "^20.0.0", "lint-staged": "^12.1.2", "npm-run-all": "^4.1.5", "nuxt": "^3.0.0-rc.9", diff --git a/specs/fixtures/basic/pages/index.vue b/specs/fixtures/basic/pages/index.vue index 032db2ec9..ddc201a28 100644 --- a/specs/fixtures/basic/pages/index.vue +++ b/specs/fixtures/basic/pages/index.vue @@ -7,7 +7,11 @@ import LangSwitcher from '../components/LangSwitcher.vue' const { t } = useI18n() const localePath = useLocalePath() -const i18nHead = useLocaleHead({ addSeoAttributes: { canonicalQueries: ['page'] }, router: useRouter() }) +const i18nHead = useLocaleHead({ + addDirAttribute: true, + addSeoAttributes: { canonicalQueries: ['page'] }, + router: useRouter() +}) const { data, refresh } = useAsyncData('home', () => Promise.resolve({ aboutPath: localePath('about'), @@ -22,7 +26,8 @@ watchEffect(() => { useHead({ title: t('home'), htmlAttrs: { - lang: i18nHead.value.htmlAttrs!.lang + lang: i18nHead.value.htmlAttrs!.lang, + dir: i18nHead.value.htmlAttrs!.dir }, link: [...(i18nHead.value.link || [])], meta: [...(i18nHead.value.meta || [])] diff --git a/specs/fixtures/head/app.vue b/specs/fixtures/head/app.vue index 21d745afb..67e9d60b9 100644 --- a/specs/fixtures/head/app.vue +++ b/specs/fixtures/head/app.vue @@ -5,12 +5,12 @@ import { useI18n, useLocaleHead } from '#i18n' const route = useRoute() const { t } = useI18n() -const head = useLocaleHead({ addSeoAttributes: { canonicalQueries: ['page'] } }) +const head = useLocaleHead({ addDirAttribute: true, addSeoAttributes: { canonicalQueries: ['page'] } }) const title = computed(() => `Page - ${t(route.meta.title as string)}`)