@globalbrain/sefirot 4.10.0 → 4.11.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.
@@ -0,0 +1,22 @@
1
+ import { type HttpOptions } from '../http/Http'
2
+ import { useSetupHttp } from './Http'
3
+ import { type HasLang, useSetupLang } from './Lang'
4
+ import { type HasTheme, useSetupTheme } from './Theme'
5
+
6
+ export interface SetupAppUser extends HasLang, HasTheme {}
7
+
8
+ export interface SetupAppOptions {
9
+ http?: HttpOptions
10
+ }
11
+
12
+ export function useSetupApp(): (user?: SetupAppUser | null, options?: SetupAppOptions) => void {
13
+ const setupLang = useSetupLang()
14
+ const setupTheme = useSetupTheme()
15
+ const setupHttp = useSetupHttp()
16
+
17
+ return (user, options) => {
18
+ setupLang(user)
19
+ setupTheme(user)
20
+ setupHttp(user, options?.http)
21
+ }
22
+ }
@@ -0,0 +1,17 @@
1
+ import { type Lang, useBrowserLang } from 'sefirot/composables/Lang'
2
+ import { Http, type HttpOptions } from 'sefirot/http/Http'
3
+
4
+ export interface HasLang {
5
+ lang: Lang
6
+ }
7
+
8
+ export function useSetupHttp(): (user?: HasLang | null, options?: HttpOptions) => void {
9
+ const browserLang = useBrowserLang()
10
+
11
+ return (user, options = {}) => {
12
+ Http.config({
13
+ lang: user?.lang ?? browserLang,
14
+ ...options
15
+ })
16
+ }
17
+ }
@@ -11,8 +11,20 @@ export interface TransMessages<T> {
11
11
  ja: T
12
12
  }
13
13
 
14
+ export interface HasLang {
15
+ lang: Lang
16
+ }
17
+
14
18
  export const SefirotLangKey = 'sefirot-lang-key'
15
19
 
20
+ export function useSetupLang(): (user?: HasLang | null) => void {
21
+ const browserLang = useBrowserLang()
22
+
23
+ return (user) => {
24
+ provideLang(user?.lang ?? browserLang)
25
+ }
26
+ }
27
+
16
28
  export function provideLang(lang: Lang) {
17
29
  provide(SefirotLangKey, lang)
18
30
  }
@@ -23,6 +35,12 @@ export function useLang(): Lang {
23
35
  return inject(SefirotLangKey, 'en') || 'en'
24
36
  }
25
37
 
38
+ export function useBrowserLang(): Lang {
39
+ const lang = navigator.language
40
+
41
+ return lang.split('-')[0] === 'ja' ? 'ja' : 'en'
42
+ }
43
+
26
44
  export function useTrans<T>(messages: TransMessages<T>): Trans<T> {
27
45
  const lang = useLang()
28
46
 
@@ -32,9 +50,3 @@ export function useTrans<T>(messages: TransMessages<T>): Trans<T> {
32
50
  t
33
51
  }
34
52
  }
35
-
36
- export function useBrowserLang(): Lang {
37
- const lang = navigator.language
38
-
39
- return lang.split('-')[0] === 'ja' ? 'ja' : 'en'
40
- }
@@ -0,0 +1,25 @@
1
+ import { useDark } from '@vueuse/core'
2
+ import { type WritableComputedRef, computed } from 'vue'
3
+
4
+ export type Theme = 'light' | 'dark'
5
+
6
+ export interface HasTheme {
7
+ theme: Theme
8
+ }
9
+
10
+ export function useSetupTheme(): (user?: HasTheme | null) => void {
11
+ const theme = useTheme()
12
+
13
+ return (user) => {
14
+ theme.value = user?.theme ?? 'light'
15
+ }
16
+ }
17
+
18
+ export function useTheme(): WritableComputedRef<Theme> {
19
+ const _isDark = useDark()
20
+
21
+ return computed({
22
+ get: () => _isDark.value ? 'dark' : 'light',
23
+ set: (v) => { _isDark.value = v === 'dark' }
24
+ })
25
+ }
@@ -1,5 +1,5 @@
1
1
  import isEqual from 'lodash-es/isEqual'
2
- import { type MaybeRef, nextTick, unref, watch } from 'vue'
2
+ import { type MaybeRef, computed, nextTick, unref, watch } from 'vue'
3
3
  import { type LocationQuery, useRoute, useRouter } from 'vue-router'
4
4
 
5
5
  export interface UseUrlQuerySyncOptions {
@@ -21,13 +21,22 @@ export function useUrlQuerySync(
21
21
  const route = useRoute()
22
22
  const router = useRouter()
23
23
 
24
+ const routeQuery = computed(() => ({
25
+ path: route.path,
26
+ query: route.query
27
+ }))
28
+
24
29
  const flattenedDefaultState = flattenObject(unref(state))
25
30
 
26
31
  let isSyncing = false
27
32
 
28
33
  watch(
29
- () => route.query,
30
- async () => {
34
+ routeQuery,
35
+ async (to, from) => {
36
+ if (from && from.path !== to.path) {
37
+ return
38
+ }
39
+
31
40
  if (!isSyncing) {
32
41
  isSyncing = true
33
42
  await setState()
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@globalbrain/sefirot",
3
3
  "type": "module",
4
- "version": "4.10.0",
4
+ "version": "4.11.0",
5
5
  "packageManager": "pnpm@9.15.3",
6
6
  "description": "Vue Components for Global Brain Design System.",
7
7
  "author": "Kia Ishii <ka.ishii@globalbrains.com>",