@globalbrain/sefirot 3.14.0 → 3.15.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.
@@ -2,7 +2,7 @@
2
2
  import { type IconifyIcon } from '@iconify/vue/dist/offline'
3
3
  import IconQuestion from '@iconify-icons/ph/question'
4
4
  import { type DefineComponent, computed, unref, useSlots } from 'vue'
5
- import { type Validatable } from '../composables/Validation'
5
+ import { type Validatable } from '../composables/V'
6
6
  import SIcon from './SIcon.vue'
7
7
  import STooltip from './STooltip.vue'
8
8
 
@@ -3,7 +3,7 @@ import { type IconifyIcon } from '@iconify/vue/dist/offline'
3
3
  import IconCheck from '@iconify-icons/ph/check-bold'
4
4
  import IconMinus from '@iconify-icons/ph/minus-bold'
5
5
  import { computed } from 'vue'
6
- import { type Validatable } from '../composables/Validation'
6
+ import { type Validatable } from '../composables/V'
7
7
  import SIcon from './SIcon.vue'
8
8
  import SInputBase from './SInputBase.vue'
9
9
 
@@ -1,7 +1,7 @@
1
1
  <script setup lang="ts">
2
2
  import { type IconifyIcon } from '@iconify/vue/dist/offline'
3
3
  import { computed } from 'vue'
4
- import { type Validatable } from '../composables/Validation'
4
+ import { type Validatable } from '../composables/V'
5
5
  import SInputBase from './SInputBase.vue'
6
6
  import SInputCheckbox from './SInputCheckbox.vue'
7
7
 
@@ -2,7 +2,7 @@
2
2
  import { type IconifyIcon } from '@iconify/vue/dist/offline'
3
3
  import { DatePicker } from 'v-calendar'
4
4
  import { computed } from 'vue'
5
- import { type Validatable } from '../composables/Validation'
5
+ import { type Validatable } from '../composables/V'
6
6
  import { type Day, day } from '../support/Day'
7
7
  import SInputBase from './SInputBase.vue'
8
8
 
@@ -6,7 +6,7 @@ import xor from 'lodash-es/xor'
6
6
  import { type DefineComponent, computed, ref } from 'vue'
7
7
  import { type DropdownSectionFilter, useManualDropdownPosition } from '../composables/Dropdown'
8
8
  import { useFlyout } from '../composables/Flyout'
9
- import { type Validatable } from '../composables/Validation'
9
+ import { type Validatable } from '../composables/V'
10
10
  import { isArray } from '../support/Utils'
11
11
  import SDropdown from './SDropdown.vue'
12
12
  import SIcon from './SIcon.vue'
@@ -1,7 +1,7 @@
1
1
  <script setup lang="ts">
2
2
  import { type IconifyIcon } from '@iconify/vue/dist/offline'
3
3
  import { type DefineComponent, computed, ref } from 'vue'
4
- import { type Validatable } from '../composables/Validation'
4
+ import { type Validatable } from '../composables/V'
5
5
  import SInputBase from './SInputBase.vue'
6
6
 
7
7
  export type Size = 'mini' | 'small' | 'medium'
@@ -1,7 +1,7 @@
1
1
  <script setup lang="ts">
2
2
  import { type IconifyIcon } from '@iconify/vue/dist/offline'
3
3
  import { type DefineComponent, computed, ref } from 'vue'
4
- import { type Validatable } from '../composables/Validation'
4
+ import { type Validatable } from '../composables/V'
5
5
  import SInputBase from './SInputBase.vue'
6
6
 
7
7
  export type Size = 'mini' | 'small' | 'medium'
@@ -3,7 +3,7 @@ import { type IconifyIcon } from '@iconify/vue/dist/offline'
3
3
  import IconImage from '@iconify-icons/ph/image-bold'
4
4
  import { computed, ref } from 'vue'
5
5
  import { useImageSrcFromFile } from '../composables/Image'
6
- import { type Validatable } from '../composables/Validation'
6
+ import { type Validatable } from '../composables/V'
7
7
  import SButton from './SButton.vue'
8
8
  import SIcon from './SIcon.vue'
9
9
  import SInputBase from './SInputBase.vue'
@@ -1,7 +1,7 @@
1
1
  <script setup lang="ts">
2
2
  import { type IconifyIcon } from '@iconify/vue/dist/offline'
3
3
  import { type DefineComponent, computed } from 'vue'
4
- import { type Validatable } from '../composables/Validation'
4
+ import { type Validatable } from '../composables/V'
5
5
  import { isNullish, isString } from '../support/Utils'
6
6
  import SInputText from './SInputText.vue'
7
7
 
@@ -1,7 +1,7 @@
1
1
  <script setup lang="ts">
2
2
  import { type IconifyIcon } from '@iconify/vue/dist/offline'
3
3
  import { type DefineComponent, computed } from 'vue'
4
- import { type Validatable } from '../composables/Validation'
4
+ import { type Validatable } from '../composables/V'
5
5
  import SInputBase from './SInputBase.vue'
6
6
 
7
7
  export type Size = 'mini' | 'small' | 'medium'
@@ -1,7 +1,7 @@
1
1
  <script setup lang="ts">
2
2
  import { type IconifyIcon } from '@iconify/vue/dist/offline'
3
3
  import { type DefineComponent, computed } from 'vue'
4
- import { type Validatable } from '../composables/Validation'
4
+ import { type Validatable } from '../composables/V'
5
5
  import SInputBase from './SInputBase.vue'
6
6
  import SInputRadio from './SInputRadio.vue'
7
7
 
@@ -1,7 +1,7 @@
1
1
  <script setup lang="ts" generic="T extends string | number | boolean">
2
2
  import { type IconifyIcon } from '@iconify/vue/dist/offline'
3
3
  import { computed } from 'vue'
4
- import { type Validatable } from '../composables/Validation'
4
+ import { type Validatable } from '../composables/V'
5
5
  import SInputBase from './SInputBase.vue'
6
6
  import SInputSegmentsOption, { type Mode } from './SInputSegmentsOption.vue'
7
7
 
@@ -3,7 +3,7 @@ import { type IconifyIcon } from '@iconify/vue/dist/offline'
3
3
  import IconCaretDown from '@iconify-icons/ph/caret-down-bold'
4
4
  import IconCaretUp from '@iconify-icons/ph/caret-up-bold'
5
5
  import { type DefineComponent, computed, ref } from 'vue'
6
- import { type Validatable } from '../composables/Validation'
6
+ import { type Validatable } from '../composables/V'
7
7
  import SIcon from './SIcon.vue'
8
8
  import SInputBase from './SInputBase.vue'
9
9
 
@@ -1,7 +1,7 @@
1
1
  <script setup lang="ts">
2
2
  import { type IconifyIcon } from '@iconify/vue/dist/offline'
3
3
  import { type DefineComponent, computed } from 'vue'
4
- import { type Validatable } from '../composables/Validation'
4
+ import { type Validatable } from '../composables/V'
5
5
  import SInputBase from './SInputBase.vue'
6
6
 
7
7
  export type Size = 'mini' | 'small' | 'medium'
@@ -1,7 +1,7 @@
1
1
  <script setup lang="ts">
2
2
  import { type IconifyIcon } from '@iconify/vue/dist/offline'
3
3
  import { type DefineComponent, computed } from 'vue'
4
- import { type Validatable } from '../composables/Validation'
4
+ import { type Validatable } from '../composables/V'
5
5
  import SInputBase from './SInputBase.vue'
6
6
  import SInputSwitch from './SInputSwitch.vue'
7
7
 
@@ -1,7 +1,7 @@
1
1
  <script setup lang="ts">
2
2
  import { type IconifyIcon } from '@iconify/vue/dist/offline'
3
3
  import { type DefineComponent, computed, ref } from 'vue'
4
- import { type Validatable } from '../composables/Validation'
4
+ import { type Validatable } from '../composables/V'
5
5
  import { isString } from '../support/Utils'
6
6
  import SIcon from './SIcon.vue'
7
7
  import SInputBase from './SInputBase.vue'
@@ -1,7 +1,7 @@
1
1
  <script setup lang="ts">
2
2
  import { type IconifyIcon } from '@iconify/vue/dist/offline'
3
3
  import { computed } from 'vue'
4
- import { type Validatable } from '../composables/Validation'
4
+ import { type Validatable } from '../composables/V'
5
5
  import SInputBase from './SInputBase.vue'
6
6
 
7
7
  export type Size = 'mini' | 'small' | 'medium'
@@ -1,7 +1,7 @@
1
1
  <script setup lang="ts">
2
2
  import { type IconifyIcon } from '@iconify/vue/dist/offline'
3
3
  import { type DefineComponent, computed, ref } from 'vue'
4
- import { type Validatable } from '../composables/Validation'
4
+ import { type Validatable } from '../composables/V'
5
5
  import SInputBase from './SInputBase.vue'
6
6
 
7
7
  export type Size = 'mini' | 'small' | 'medium'
@@ -1,4 +1,4 @@
1
- import { type InjectionKey, type Ref, inject, provide, ref } from 'vue'
1
+ import { type Ref, inject, provide, ref } from 'vue'
2
2
 
3
3
  export interface CardState {
4
4
  isCollapsed: Ref<boolean>
@@ -6,7 +6,7 @@ export interface CardState {
6
6
  toggleCollapse(): void
7
7
  }
8
8
 
9
- export const cardStateKey = Symbol('card-state') as InjectionKey<CardState>
9
+ export const CardStateKey = 'card-state'
10
10
 
11
11
  export function provideCardState(): CardState {
12
12
  const isCollapsed = ref(false)
@@ -25,13 +25,13 @@ export function provideCardState(): CardState {
25
25
  toggleCollapse
26
26
  }
27
27
 
28
- provide(cardStateKey, cardState)
28
+ provide(CardStateKey, cardState)
29
29
 
30
30
  return cardState
31
31
  }
32
32
 
33
33
  export function useCardState(): CardState {
34
- const cardState = inject(cardStateKey)
34
+ const cardState = inject<CardState | null>(CardStateKey, null)
35
35
 
36
36
  if (!cardState) {
37
37
  throw new Error(
@@ -0,0 +1,21 @@
1
+ import { type Ref, ref } from 'vue'
2
+
3
+ export interface D<T extends Record<string, any>> {
4
+ data: Ref<T>
5
+ init(): void
6
+ }
7
+
8
+ export function useD<T extends Record<string, any>>(data: T): D<T> {
9
+ const initialData = JSON.parse(JSON.stringify(data))
10
+
11
+ const refData = ref(data) as Ref<T>
12
+
13
+ function init(): void {
14
+ refData.value = initialData
15
+ }
16
+
17
+ return {
18
+ data: refData,
19
+ init
20
+ }
21
+ }
@@ -1,3 +1,7 @@
1
+ /**
2
+ * @deprecated Use `composables/D` module instead.
3
+ */
4
+
1
5
  import { watchOnce } from '@vueuse/core'
2
6
  import cloneDeep from 'lodash-es/cloneDeep'
3
7
  import { type WatchSource, reactive } from 'vue'
@@ -1,3 +1,7 @@
1
+ /**
2
+ * @deprecated Use `composables/D` and `composables/V` modules instead.
3
+ */
4
+
1
5
  import { type Ref, computed, reactive, toRefs } from 'vue'
2
6
  import { type Snackbar, useSnackbars } from '../stores/Snackbars'
3
7
  import { type UseDataInput, useData } from './Data'
@@ -0,0 +1,73 @@
1
+ import { type Validation, type ValidationArgs, useVuelidate } from '@vuelidate/core'
2
+ import { type MaybeRefOrGetter, type Ref, computed, toValue } from 'vue'
3
+ import { type Snackbar, useSnackbars } from '../stores/Snackbars'
4
+ import { useTrans } from './Lang'
5
+
6
+ export interface V<
7
+ Data extends { [key in keyof Rules]: any },
8
+ Rules extends ValidationArgs = ValidationArgs
9
+ > {
10
+ validation: Ref<Validation<Rules, Data>>
11
+ validate(): Promise<boolean>
12
+ validateAndNotify(message?: Snackbar): Promise<boolean>
13
+ reset(): void
14
+ }
15
+
16
+ export interface Validatable {
17
+ readonly $dirty: boolean
18
+ readonly $invalid: boolean
19
+ readonly $errors: ValidatableError[]
20
+ readonly $touch: () => void
21
+ }
22
+
23
+ export interface ValidatableError {
24
+ readonly $message: string | Ref<string>
25
+ }
26
+
27
+ export function useV<
28
+ Data extends { [key in keyof Rules]: any },
29
+ Rules extends ValidationArgs = ValidationArgs
30
+ >(
31
+ data: MaybeRefOrGetter<Data>,
32
+ rules: MaybeRefOrGetter<Rules>
33
+ ): V<Data, Rules> {
34
+ const { t } = useTrans({
35
+ en: { notify: 'Form contains errors. Please correct them and try again.' },
36
+ ja: { notify: 'フォームにエラーがあります。内容を確認し、再度お試しください。' }
37
+ })
38
+
39
+ const snackbars = useSnackbars()
40
+
41
+ const d = computed(() => toValue(data))
42
+ const r = computed(() => toValue(rules))
43
+
44
+ const validation = useVuelidate(r, d)
45
+
46
+ function reset(): void {
47
+ validation.value.$reset()
48
+ }
49
+
50
+ function validate(): Promise<boolean> {
51
+ return validation.value.$validate()
52
+ }
53
+
54
+ async function validateAndNotify(message?: Snackbar): Promise<boolean> {
55
+ const valid = await validate()
56
+
57
+ if (!valid) {
58
+ snackbars.push(message ?? {
59
+ mode: 'danger',
60
+ text: t.notify
61
+ })
62
+ }
63
+
64
+ return valid
65
+ }
66
+
67
+ return {
68
+ validation,
69
+ validate,
70
+ validateAndNotify,
71
+ reset
72
+ }
73
+ }
@@ -1,3 +1,7 @@
1
+ /**
2
+ * @deprecated Use `composables/V` module instead.
3
+ */
4
+
1
5
  import {
2
6
  type GlobalConfig,
3
7
  type Validation,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@globalbrain/sefirot",
3
- "version": "3.14.0",
3
+ "version": "3.15.0",
4
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>",