@globalbrain/sefirot 2.1.4 → 2.2.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.
@@ -14,7 +14,7 @@ export interface Form<T extends Record<string, any>> {
14
14
 
15
15
  export interface UseFormOptions<T extends Record<string, any>> {
16
16
  data: T,
17
- rules?: Record<string, any>
17
+ rules?: Record<string, any> | ((state: T) => Record<string, any>)
18
18
  }
19
19
 
20
20
  export function useForm<
@@ -26,7 +26,9 @@ export function useForm<
26
26
 
27
27
  const data = reactive(options.data)
28
28
 
29
- const rules = options.rules ?? {}
29
+ const rules = options.rules
30
+ ? typeof options.rules === 'function' ? options.rules(data) : options.rules
31
+ : {}
30
32
 
31
33
  const validation = useValidation(data, rules)
32
34
 
@@ -1,12 +1,18 @@
1
+ export { or, and, not } from '@vuelidate/validators'
2
+
1
3
  export * from './checked'
2
4
  export * from './email'
3
5
  export * from './fileExtension'
4
6
  export * from './hms'
5
7
  export * from './maxLength'
6
8
  export * from './minLength'
9
+ export * from './maxValue'
10
+ export * from './minValue'
7
11
  export * from './required'
8
12
  export * from './requiredHms'
9
13
  export * from './requiredIf'
10
14
  export * from './requiredYmd'
11
15
  export * from './url'
16
+ export * from './month'
12
17
  export * from './ymd'
18
+ export * from './rule'
@@ -0,0 +1,10 @@
1
+ import { helpers, maxValue as baseMaxValue } from '@vuelidate/validators'
2
+
3
+ export function maxValue(value: number, msg?: string) {
4
+ return helpers.withMessage(
5
+ ({ $params }) => {
6
+ return msg ?? `The value must be less or equal to ${($params as any).max}.`
7
+ },
8
+ baseMaxValue(value)
9
+ )
10
+ }
@@ -0,0 +1,10 @@
1
+ import { helpers, minValue as baseMinValue } from '@vuelidate/validators'
2
+
3
+ export function minValue(value: number, msg?: string) {
4
+ return helpers.withMessage(
5
+ ({ $params }) => {
6
+ return msg ?? `The value must be greater or equal to ${($params as any).min}.`
7
+ },
8
+ baseMinValue(value)
9
+ )
10
+ }
@@ -0,0 +1,11 @@
1
+ import { helpers } from '@vuelidate/validators'
2
+ import { month as baseMonth } from '../validators/month'
3
+
4
+ export function month(msg?: string) {
5
+ return helpers.withMessage(
6
+ () => msg ?? 'The month is invalid.',
7
+ (value: number) => {
8
+ return !helpers.req(value) || baseMonth(value)
9
+ }
10
+ )
11
+ }
@@ -0,0 +1,8 @@
1
+ import { helpers } from '@vuelidate/validators'
2
+
3
+ export function rule(validation: (value: any) => boolean, msg?: string) {
4
+ return helpers.withMessage(
5
+ () => msg ?? 'The value is invalid.',
6
+ (value: any) => !helpers.req(value) || validation(value)
7
+ )
8
+ }
@@ -0,0 +1,3 @@
1
+ export function month(value: number): boolean {
2
+ return value > 0 && value < 13
3
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@globalbrain/sefirot",
3
- "version": "2.1.4",
3
+ "version": "2.2.0",
4
4
  "description": "Vue Components for Global Brain Design System.",
5
5
  "files": [
6
6
  "lib"
@@ -84,7 +84,7 @@
84
84
  "vitest": "^0.23.4",
85
85
  "vue": "^3.2.40",
86
86
  "vue-router": "^4.1.5",
87
- "vue-tsc": "^0.40.13"
87
+ "vue-tsc": "^1.0.8"
88
88
  },
89
89
  "scripts": {
90
90
  "docs": "vitepress dev docs --port 3000",