@d-mok/quasar-app-extension-quasar-axe 1.0.39 → 1.0.42

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": "1.0.39",
3
+ "version": "1.0.42",
4
4
  "description": "A Quasar App Extension",
5
5
  "author": "d-mok <49301824+d-mok@users.noreply.github.com>",
6
6
  "license": "MIT",
@@ -1,11 +1,16 @@
1
1
  import { DeleteBuilder, UpdateBuilder } from './builder'
2
- import { Constructor } from './type'
2
+ import { Constructor, BooleanKeys } from './type'
3
3
 
4
4
 
5
5
  export function Entity<
6
6
  TBase extends Constructor,
7
+ K extends string & keyof R,
7
8
  R extends InstanceType<TBase> = InstanceType<TBase>
8
- >(RowClass: TBase) {
9
+ >(
10
+ RowClass: TBase,
11
+ tableName: string,
12
+ idKey: K
13
+ ) {
9
14
 
10
15
  class VIEW extends RowClass {
11
16
 
@@ -17,11 +22,15 @@ export function Entity<
17
22
 
18
23
  static _RowClass = RowClass
19
24
 
20
- static _fields: (string & keyof InstanceType<TBase>)[]
21
- = Object.keys(new RowClass()) as any
25
+ static _tableName = tableName
26
+
27
+ static _idKey: K = idKey
28
+
29
+ static _fields: any[] = Object.keys(new RowClass())
22
30
 
23
31
  }
24
32
 
33
+
25
34
 
26
35
  class EDIT extends VIEW {
27
36
 
@@ -35,6 +44,11 @@ export function Entity<
35
44
  return this._hostTable.deleteRow!(this)
36
45
  }
37
46
 
47
+ toggle(key: BooleanKeys<R>): UpdateBuilder<any, R> {
48
+ // @ts-ignore
49
+ return this._hostTable.updateRow(this, { [key]: !this[key] })
50
+ }
51
+
38
52
 
39
53
  }
40
54
  return {
@@ -5,7 +5,12 @@ import { Core } from './core'
5
5
  import { Entity } from './entity'
6
6
 
7
7
 
8
- type imprinted<R extends object> = { _RowClass: Constructor, _fields: (string & keyof R)[] }
8
+ type imprinted<R extends object> = {
9
+ _RowClass: Constructor
10
+ _tableName: string
11
+ _idKey: string & keyof R
12
+ _fields: any[]
13
+ }
9
14
  type EntityClass<T extends R, R extends object> = Constructor<T> & imprinted<R>
10
15
  type RowOf<E extends EntityClass<any, any>> = InstanceType<E['_RowClass']>
11
16
 
@@ -18,16 +23,18 @@ function logCreate(tableName: string, idKey: string, entityName: string) {
18
23
 
19
24
 
20
25
  export function Table<
21
- K extends string & keyof R,
22
26
  ClassT extends EntityClass<T, R>,
23
27
  R extends RowOf<ClassT> = RowOf<ClassT>,
24
28
  T extends R = InstanceType<ClassT>
25
29
  >(
26
30
  EntityClass: ClassT,
27
- idKey: K,
28
- tableName: string = EntityClass.name.toLowerCase(),
31
+ ordering: Ordering<InstanceType<ClassT>> = []
29
32
  ) {
30
33
 
34
+ const tableName: string = EntityClass._tableName
35
+ const idKey: ClassT['_idKey'] = EntityClass._idKey
36
+ const fields: any[] = EntityClass._fields
37
+
31
38
  logCreate(tableName, idKey, EntityClass.name)
32
39
 
33
40
  function convertor(host: any) {
@@ -43,7 +50,7 @@ export function Table<
43
50
  return new Core<T, R>(
44
51
  tableName,
45
52
  idKey,
46
- EntityClass._fields,
53
+ fields,
47
54
  convertor(host)
48
55
  )
49
56
  }
@@ -51,11 +58,9 @@ export function Table<
51
58
 
52
59
  class Base extends Sheet<T> {
53
60
 
54
- /** The default ordering instruction object. */
55
- protected readonly ordering: Readonly<Ordering<T>> = []
56
61
 
57
62
  protected reorder() {
58
- this.order(...this.ordering)
63
+ this.order(...ordering)
59
64
  }
60
65
 
61
66
 
@@ -78,7 +83,7 @@ export function Table<
78
83
  class TableView extends Base {
79
84
 
80
85
  private orderByList<K extends keyof R>(key: K, vals: R[K][]) {
81
- this.ordering.length === 0
86
+ ordering.length === 0
82
87
  ? this.reorder()
83
88
  : this.order({ [key]: vals } as any)
84
89
  }
@@ -153,7 +158,7 @@ export function Table<
153
158
  }
154
159
 
155
160
 
156
- update(idVal: R[K], row: Partial<R>) {
161
+ update(idVal: R[ClassT['_idKey']], row: Partial<R>) {
157
162
  let callback = ($: T[]) => {
158
163
  this.merge($, idKey)
159
164
  this.reorder()
@@ -170,7 +175,7 @@ export function Table<
170
175
  }
171
176
 
172
177
 
173
- delete(idVal: R[K]) {
178
+ delete(idVal: R[ClassT['_idKey']]) {
174
179
  let callback = ($: T[]) => {
175
180
  this.discard({ [idKey]: idVal } as any)
176
181
  this.reorder()
@@ -214,7 +219,8 @@ export function Table<
214
219
  // public name: string = ""
215
220
  // public class: string = ""
216
221
  // public num: number = 0
217
-
222
+ // public pass: boolean = false
223
+ // public pasds: boolean = false
218
224
 
219
225
  // }
220
226
 
@@ -222,7 +228,7 @@ export function Table<
222
228
 
223
229
 
224
230
 
225
- // class Student extends Entity(StudentRow).EDIT {
231
+ // class Student extends Entity(StudentRow, 'student', 'num').EDIT {
226
232
 
227
233
  // public full = this.class + this.name
228
234
 
@@ -231,14 +237,14 @@ export function Table<
231
237
 
232
238
  // let s = new Student()
233
239
  // // s.ful
234
- // s.update({ num: 1 })
240
+ // s.toggle('pass')
241
+
235
242
 
236
243
 
237
244
 
238
245
 
239
- // class StudentsCollection extends Table(Student, 'num').EDIT {
246
+ // class StudentsCollection extends Table(Student, ['full']).EDIT {
240
247
 
241
- // protected ordering = ['name'] as const
242
248
 
243
249
  // protected override onChange() {
244
250
  // return 1
@@ -248,8 +254,8 @@ export function Table<
248
254
 
249
255
 
250
256
  // let ss = new StudentsCollection()
251
- // ss.select().eq('num', 1)
252
- // ss.insert({ nae }).confirm('a')
253
- // ss.delete('f')
257
+ // ss.select().eq('num',)
258
+ // ss.insert()
259
+ // ss.delete(1)
254
260
 
255
261
 
@@ -10,3 +10,5 @@ export type Filter<R> =
10
10
  export type Constructor<T extends object = {}> = new (...args: any[]) => T
11
11
 
12
12
 
13
+ export type BooleanKeys<T> = { [k in keyof T]: T[k] extends boolean ? k : never }[keyof T]
14
+ // type OnlyBoolean<T> = { [k in BooleanKeys<T>]: boolean }
@@ -94,7 +94,7 @@ class QDialog {
94
94
 
95
95
  /**
96
96
  * Ask for a string by a simple text field.
97
- * Not accept empty input.
97
+ * Allow empty input.
98
98
  * @param title - the title
99
99
  * @param message - the message
100
100
  * @param prefill - default text
@@ -102,6 +102,30 @@ class QDialog {
102
102
  * @returns the user input string
103
103
  */
104
104
  async askText(title: string, message: string = "", prefill: string = "", isValid: Predicate<string> = $ => true): Promise<string> {
105
+ return this.baseDialog({
106
+ title,
107
+ message,
108
+ prompt: {
109
+ model: prefill,
110
+ type: 'text',
111
+ outlined: true,
112
+ isValid: ($: string) => isValid($)
113
+ },
114
+ })
115
+ }
116
+
117
+
118
+
119
+ /**
120
+ * Ask for a string by a simple text field.
121
+ * Not accept empty input.
122
+ * @param title - the title
123
+ * @param message - the message
124
+ * @param prefill - default text
125
+ * @param isValid - validation function on input
126
+ * @returns the user input string
127
+ */
128
+ async askTextRequired(title: string, message: string = "", prefill: string = "", isValid: Predicate<string> = $ => true): Promise<string> {
105
129
  return this.baseDialog({
106
130
  title,
107
131
  message,