@d-mok/quasar-app-extension-quasar-axe 2.2.7 → 2.2.9

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.2.7",
3
+ "version": "2.2.9",
4
4
  "description": "A Quasar App Extension",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -89,7 +89,8 @@ export async function askTable<T extends object>(
89
89
  title: string,
90
90
  message: string = '',
91
91
  prefills: T[][],
92
- validators: [(_: T) => boolean, string][] = [[$ => true, '']]
92
+ validators: [(_: T) => boolean, string][] = [[$ => true, '']],
93
+ arrayValidator: [(_: T[]) => boolean, string][] = [[$ => true, '']]
93
94
  ): Promise<T[]> {
94
95
  if (prefills.flat().length === 0)
95
96
  throwError('Error', 'All prefills are empty array.')
@@ -99,6 +100,7 @@ export async function askTable<T extends object>(
99
100
  content: prefills.find($ => $.length > 0),
100
101
  sample: [...prefills].reverse().find($ => $.length > 0)![0],
101
102
  validators,
103
+ arrayValidator,
102
104
  cancel: true,
103
105
  allowAddRow: true,
104
106
  })
@@ -111,7 +113,8 @@ export async function editTable<T extends object>(
111
113
  title: string,
112
114
  message: string = '',
113
115
  prefill: T[],
114
- validators: [(_: T) => boolean, string][] = [[$ => true, '']]
116
+ validators: [(_: T) => boolean, string][] = [[$ => true, '']],
117
+ arrayValidator: [(_: T[]) => boolean, string][] = [[$ => true, '']]
115
118
  ): Promise<T[]> {
116
119
  if (prefill.length === 0) throwError('Error', 'prefill is empty array.')
117
120
  return await base(dialogTable, {
@@ -120,6 +123,7 @@ export async function editTable<T extends object>(
120
123
  content: prefill,
121
124
  sample: prefill[0],
122
125
  validators,
126
+ arrayValidator,
123
127
  cancel: true,
124
128
  allowAddRow: false,
125
129
  })
@@ -132,13 +136,15 @@ export async function askArray(
132
136
  title: string,
133
137
  message: string = '',
134
138
  prefill: string[] = [],
135
- validators: [(_: string) => boolean, string][] = [[$ => true, '']]
139
+ validators: [(_: string) => boolean, string][] = [[$ => true, '']],
140
+ arrayValidator: [(_: string[]) => boolean, string][] = [[$ => true, '']]
136
141
  ): Promise<string[]> {
137
142
  let result = await askTable(
138
143
  title,
139
144
  message,
140
145
  [prefill.map($ => ({ value: $ })), [{ value: '' }]],
141
- validators.map(([fn, err]) => [$ => fn($.value), err])
146
+ validators.map(([fn, err]) => [$ => fn($.value), err]),
147
+ arrayValidator.map(([fn, err]) => [$ => fn($.pluck('value')), err])
142
148
  )
143
149
  return result.pluck('value').unmatch([''])
144
150
  }
@@ -208,6 +214,7 @@ export async function showTable(
208
214
  content,
209
215
  sample: content[0],
210
216
  validators: [[($: any) => true, '']],
217
+ arrayValidators: [[($: any) => true, '']],
211
218
  cancel: false,
212
219
  allowAddRow: false,
213
220
  })
@@ -7,7 +7,7 @@
7
7
  <q-card
8
8
  :style="{
9
9
  'max-width': '100%',
10
- width: Object.keys(sample).length * 150 + 100 + 'px',
10
+ width: Object.keys(sample).length * 200 + 200 + 'px',
11
11
  }"
12
12
  >
13
13
  <q-card-section>
@@ -81,6 +81,7 @@ const props = defineProps<{
81
81
  content: row[]
82
82
  sample: row
83
83
  validators: [(_: row) => boolean, string][]
84
+ arrayValidators: [(_: row[]) => boolean, string][]
84
85
  cancel: boolean
85
86
  allowAddRow: boolean
86
87
  }>()
@@ -101,21 +102,29 @@ setTimeout(() => {
101
102
 
102
103
  function allValid() {
103
104
  if (!props.cancel) return true
104
- return dummy.value.every(
105
+ let rowsOK = dummy.value.every(
105
106
  $ =>
106
- props.validators.every(v => v[0]($)) &&
107
+ props.validators.every(([checker, msg]) => checker($)) &&
107
108
  isPrimitive($) &&
108
109
  isMatchSchema($, schema)
109
110
  )
111
+ let arrayOK = props.arrayValidators.every(([checker, msg]) =>
112
+ checker(dummy.value)
113
+ )
114
+ return rowsOK && arrayOK
110
115
  }
111
116
 
112
117
  function errorMsg(): string | undefined {
113
118
  for (let i = 0; i < dummy.value.length; i++) {
114
- for (let [f, e] of props.validators) {
115
- let ok = f(dummy.value[i])
116
- if (!ok) return `row ${i + 1}: ${e}`
119
+ for (let [checker, msg] of props.validators) {
120
+ let ok = checker(dummy.value[i])
121
+ if (!ok) return `row ${i + 1}: ${msg}`
117
122
  }
118
123
  }
124
+ for (let [checker, msg] of props.arrayValidators) {
125
+ let ok = checker(dummy.value)
126
+ if (!ok) return msg
127
+ }
119
128
  return undefined
120
129
  }
121
130