@globalbrain/sefirot 3.9.0 → 3.10.1

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,58 @@
1
+ import { type Ref, ref } from 'vue'
2
+
3
+ export interface Power {
4
+ state: Ref<boolean>
5
+ on(fn?: () => void): boolean
6
+ onAfter(fn: () => Promise<any>): Promise<boolean>
7
+ off(fn?: () => void): boolean
8
+ offAfter(fn: () => Promise<any>): Promise<boolean>
9
+ toggle(fn?: () => void): boolean
10
+ toggleAfter(fn: () => Promise<any>): Promise<boolean>
11
+ }
12
+
13
+ export function usePower(initialValue = false): Power {
14
+ const state = ref(initialValue)
15
+
16
+ function on(fn: () => void = () => {}): boolean {
17
+ typeof fn === 'function' && fn()
18
+ state.value = true
19
+ return state.value
20
+ }
21
+
22
+ async function onAfter(fn: () => Promise<any>): Promise<boolean> {
23
+ await fn()
24
+ return on()
25
+ }
26
+
27
+ function off(fn: () => void = () => {}): boolean {
28
+ typeof fn === 'function' && fn()
29
+ state.value = false
30
+ return state.value
31
+ }
32
+
33
+ async function offAfter(fn: () => Promise<any>): Promise<boolean> {
34
+ await fn()
35
+ return off()
36
+ }
37
+
38
+ function toggle(fn: () => void = () => {}): boolean {
39
+ typeof fn === 'function' && fn()
40
+ state.value = !state.value
41
+ return state.value
42
+ }
43
+
44
+ async function toggleAfter(fn: () => Promise<any>): Promise<boolean> {
45
+ await fn()
46
+ return toggle()
47
+ }
48
+
49
+ return {
50
+ state,
51
+ on,
52
+ onAfter,
53
+ off,
54
+ offAfter,
55
+ toggle,
56
+ toggleAfter
57
+ }
58
+ }
@@ -1,3 +1,4 @@
1
+ import isEqual from 'lodash-es/isEqual'
1
2
  import isPlainObject from 'lodash-es/isPlainObject'
2
3
  import { watch } from 'vue'
3
4
  import { useRoute, useRouter } from 'vue-router'
@@ -38,7 +39,7 @@ export function useUrlQuerySync(
38
39
  flattenState[key] = cast ? cast(value) : value
39
40
  })
40
41
 
41
- Object.assign(state, unflattenObject(flattenState))
42
+ deepAssign(state, unflattenObject(flattenState))
42
43
  }
43
44
 
44
45
  async function setQueryFromState() {
@@ -53,7 +54,7 @@ export function useUrlQuerySync(
53
54
  const value = flattenState[key]
54
55
  const initialValue = flattenInitialState[key]
55
56
 
56
- if (value === initialValue) {
57
+ if (isEqual(value, initialValue)) {
57
58
  delete flattenQuery[key]
58
59
  } else {
59
60
  flattenQuery[key] = value
@@ -94,3 +95,25 @@ function unflattenObject(obj: Record<string, any>) {
94
95
  return acc
95
96
  }, {} as Record<string, any>)
96
97
  }
98
+
99
+ function deepAssign(target: Record<string, any>, source: Record<string, any>) {
100
+ const dest = target
101
+ const src = source
102
+
103
+ if (isPlainObject(src)) {
104
+ Object.keys(src).forEach((key) => deepAssignBase(dest, src, key))
105
+ } else if (Array.isArray(src)) {
106
+ dest.length = src.length
107
+ src.forEach((_, key) => deepAssignBase(dest, src, key))
108
+ } else {
109
+ throw new TypeError('[deepAssign] src must be an object or array')
110
+ }
111
+ }
112
+
113
+ function deepAssignBase(dest: Record<string, any>, src: Record<string, any>, key: string | number) {
114
+ if (typeof src[key] === 'object' && src[key] !== null) {
115
+ deepAssign(dest[key], src[key])
116
+ } else {
117
+ dest[key] = src[key]
118
+ }
119
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@globalbrain/sefirot",
3
- "version": "3.9.0",
4
- "packageManager": "pnpm@8.11.0",
3
+ "version": "3.10.1",
4
+ "packageManager": "pnpm@8.12.1",
5
5
  "description": "Vue Components for Global Brain Design System.",
6
6
  "author": "Kia Ishii <ka.ishii@globalbrains.com>",
7
7
  "license": "MIT",
@@ -56,7 +56,7 @@
56
56
  "postcss": "^8.4.32",
57
57
  "postcss-nested": "^6.0.1",
58
58
  "v-calendar": "^3.1.2",
59
- "vue": "^3.3.10",
59
+ "vue": "^3.3.11",
60
60
  "vue-router": "^4.2.5"
61
61
  },
62
62
  "dependencies": {
@@ -82,7 +82,7 @@
82
82
  "@types/node": "^20.10.4",
83
83
  "@types/qs": "^6.9.10",
84
84
  "@vitejs/plugin-vue": "^4.5.2",
85
- "@vitest/coverage-v8": "^1.0.2",
85
+ "@vitest/coverage-v8": "^1.0.4",
86
86
  "@vue/test-utils": "^2.4.3",
87
87
  "@vuelidate/core": "^2.0.3",
88
88
  "@vuelidate/validators": "^2.0.4",
@@ -99,13 +99,13 @@
99
99
  "postcss": "^8.4.32",
100
100
  "postcss-nested": "^6.0.1",
101
101
  "punycode": "^2.3.1",
102
- "release-it": "^17.0.0",
102
+ "release-it": "^17.0.1",
103
103
  "typescript": "~5.3.3",
104
104
  "v-calendar": "^3.1.2",
105
- "vite": "^5.0.6",
105
+ "vite": "^5.0.9",
106
106
  "vitepress": "1.0.0-rc.31",
107
- "vitest": "^1.0.2",
108
- "vue": "^3.3.10",
107
+ "vitest": "^1.0.4",
108
+ "vue": "^3.3.11",
109
109
  "vue-router": "^4.2.5",
110
110
  "vue-tsc": "^1.8.25"
111
111
  }