@d-mok/quasar-app-extension-quasar-axe 2.1.46 → 2.1.47

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@d-mok/quasar-app-extension-quasar-axe",
3
- "version": "2.1.46",
3
+ "version": "2.1.47",
4
4
  "description": "A Quasar App Extension",
5
5
  "author": "d-mok <49301824+d-mok@users.noreply.github.com>",
6
6
  "license": "MIT",
@@ -89,7 +89,7 @@ export async function askTable<T extends object>(
89
89
  title: string,
90
90
  message: string = '',
91
91
  prefills: T[][],
92
- validator: (_: T) => true | string = $ => true
92
+ validators: [(_: T) => boolean, string][] = [[$ => true, '']]
93
93
  ): Promise<T[]> {
94
94
  if (prefills.flat().length === 0)
95
95
  throwError('Error', 'All prefills are empty array.')
@@ -98,7 +98,7 @@ export async function askTable<T extends object>(
98
98
  message,
99
99
  content: prefills.find($ => $.length > 0),
100
100
  sample: [...prefills].reverse().find($ => $.length > 0)![0],
101
- validator,
101
+ validators,
102
102
  cancel: true,
103
103
  })
104
104
  }
@@ -110,21 +110,15 @@ export async function askArray(
110
110
  title: string,
111
111
  message: string = '',
112
112
  prefill: string[] = [],
113
- isValid: Predicate<string> = $ => true
113
+ validators: [(_: string) => boolean, string][] = [[$ => true, '']]
114
114
  ): Promise<string[]> {
115
- function split(s: string): string[] {
116
- return s.split('\n').filter($ => $.trim() !== '')
117
- }
118
-
119
- let str: string = await base(dialogTextarea, {
115
+ let result = await askTable(
120
116
  title,
121
117
  message,
122
- prefill: prefill.join('\n'),
123
- isValid: (s: string) => split(s).every(isValid),
124
- cancel: true,
125
- })
126
-
127
- return split(str)
118
+ [prefill.map($ => ({ value: $ })), [{ value: '' }]],
119
+ validators.map(([fn, err]) => [$ => fn($.value), err])
120
+ )
121
+ return result.pluck('value').unmatch([''])
128
122
  }
129
123
 
130
124
  type FormPrefill = Record<
@@ -148,13 +142,13 @@ export async function askForm<T extends FormPrefill>(
148
142
  title: string,
149
143
  message: string,
150
144
  prefill: T,
151
- validator: (_: FormFlat<T>) => true | string = $ => true
145
+ validators: [(_: FormFlat<T>) => boolean, string][] = [[$ => true, '']],
152
146
  ): Promise<FormFlat<T>> {
153
147
  return await base(dialogForm, {
154
148
  title,
155
149
  message,
156
150
  prefill,
157
- validator,
151
+ validators,
158
152
  })
159
153
  }
160
154
 
@@ -41,10 +41,11 @@
41
41
  />
42
42
  </div>
43
43
  <div
44
+ v-show="errorMsg()"
44
45
  class="text-red"
45
46
  style="text-align: right"
46
47
  >
47
- {{ validator(dummy) === true ? ' ' : validator(dummy) }}
48
+ {{ errorMsg() }}
48
49
  </div>
49
50
  </q-card-section>
50
51
 
@@ -90,7 +91,7 @@ const props = defineProps<{
90
91
  title: string
91
92
  message: string
92
93
  prefill: prefill
93
- validator: (_: row) => true | string
94
+ validators: [(_: row) => boolean, string][]
94
95
  }>()
95
96
 
96
97
  function makeSample(p: prefill): row {
@@ -119,10 +120,20 @@ function getType(field: string): string {
119
120
  return 'string'
120
121
  }
121
122
 
123
+ // valid check
124
+
122
125
  function valid() {
123
126
  return (
124
- props.validator(dummy.value) === true &&
127
+ props.validators.every(v => v[0](dummy.value)) &&
125
128
  isMatchSchema(dummy.value, schema)
126
129
  )
127
130
  }
131
+
132
+ function errorMsg(): string | undefined {
133
+ for (let [f, e] of props.validators) {
134
+ let ok = f(dummy.value)
135
+ if (!ok) return e
136
+ }
137
+ return undefined
138
+ }
128
139
  </script>
@@ -28,11 +28,11 @@
28
28
  ></handson>
29
29
  </q-card>
30
30
  <div
31
- v-for="e in errorMsg()"
31
+ v-show="errorMsg()"
32
32
  class="text-red"
33
33
  style="text-align: right"
34
34
  >
35
- {{ e }}
35
+ {{ errorMsg() }}
36
36
  </div>
37
37
  </q-card-section>
38
38
 
@@ -80,7 +80,7 @@ const props = defineProps<{
80
80
  message: string
81
81
  content: row[]
82
82
  sample: row
83
- validator: (_: row) => true | string
83
+ validators: [(_: row) => boolean, string][]
84
84
  cancel: boolean
85
85
  }>()
86
86
 
@@ -102,19 +102,20 @@ function allValid() {
102
102
  if (!props.cancel) return true
103
103
  return dummy.value.every(
104
104
  $ =>
105
- props.validator($) === true &&
105
+ props.validators.every(v => v[0]($)) &&
106
106
  isPrimitive($) &&
107
107
  isMatchSchema($, schema)
108
108
  )
109
109
  }
110
110
 
111
- function errorMsg(): string[] {
112
- let msgs: string[] = []
111
+ function errorMsg(): string | undefined {
113
112
  for (let i = 0; i < dummy.value.length; i++) {
114
- let valid = props.validator(dummy.value[i])
115
- if (valid !== true) msgs.push(`row ${i + 1}: ${valid}`)
113
+ for (let [f, e] of props.validators) {
114
+ let ok = f(dummy.value[i])
115
+ if (!ok) return `row ${i + 1}: ${e}`
116
+ }
116
117
  }
117
- return msgs
118
+ return undefined
118
119
  }
119
120
 
120
121
  // filter blank