@d-mok/quasar-app-extension-quasar-axe 2.1.45 → 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.45",
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
- isValid: Predicate<T> = $ => 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
- isValid,
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>
@@ -27,6 +27,13 @@
27
27
  v-if="exist"
28
28
  ></handson>
29
29
  </q-card>
30
+ <div
31
+ v-show="errorMsg()"
32
+ class="text-red"
33
+ style="text-align: right"
34
+ >
35
+ {{ errorMsg() }}
36
+ </div>
30
37
  </q-card-section>
31
38
 
32
39
  <q-card-actions align="right">
@@ -59,6 +66,7 @@ import { ref } from 'vue'
59
66
  import { toSchema, isMatchSchema, isPrimitive, clone } from './schema'
60
67
  import { unparseCSV } from '../../csv'
61
68
  import { copyToClipboard } from 'quasar'
69
+ import { validate } from 'json-schema'
62
70
 
63
71
  defineEmits([...useDialogPluginComponent.emits])
64
72
 
@@ -72,7 +80,7 @@ const props = defineProps<{
72
80
  message: string
73
81
  content: row[]
74
82
  sample: row
75
- isValid: (_: row) => boolean
83
+ validators: [(_: row) => boolean, string][]
76
84
  cancel: boolean
77
85
  }>()
78
86
 
@@ -93,10 +101,23 @@ setTimeout(() => {
93
101
  function allValid() {
94
102
  if (!props.cancel) return true
95
103
  return dummy.value.every(
96
- $ => props.isValid($) && isPrimitive($) && isMatchSchema($, schema)
104
+ $ =>
105
+ props.validators.every(v => v[0]($)) &&
106
+ isPrimitive($) &&
107
+ isMatchSchema($, schema)
97
108
  )
98
109
  }
99
110
 
111
+ function errorMsg(): string | undefined {
112
+ for (let i = 0; i < dummy.value.length; i++) {
113
+ for (let [f, e] of props.validators) {
114
+ let ok = f(dummy.value[i])
115
+ if (!ok) return `row ${i + 1}: ${e}`
116
+ }
117
+ }
118
+ return undefined
119
+ }
120
+
100
121
  // filter blank
101
122
 
102
123
  function isEmptyVal(x: any): boolean {