@d-mok/quasar-app-extension-quasar-axe 2.0.25 → 2.1.1

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.0.25",
3
+ "version": "2.1.1",
4
4
  "description": "A Quasar App Extension",
5
5
  "author": "d-mok <49301824+d-mok@users.noreply.github.com>",
6
6
  "license": "MIT",
@@ -24,6 +24,7 @@
24
24
  "jszip": "^3.9.0",
25
25
  "lodash": "^4.17.21",
26
26
  "papaparse": "^5.3.2",
27
+ "sapphire-js": "^2.0.3",
27
28
  "vuedraggable": "^4.1.0"
28
29
  },
29
30
  "devDependencies": {
@@ -1,11 +1,8 @@
1
+ import 'sapphire-js'
2
+
1
3
  export { qDialog } from './dialog'
2
4
  export * as qNotify from './notify'
3
5
 
4
- export { Sheet, List } from './sapphire'
5
-
6
- import * as lo from 'lodash'
7
- export const _ = lo
8
-
9
6
  export { HANDLE_ERROR, supabase } from './supabase'
10
7
 
11
8
  export { localSettings } from './settings'
@@ -1,41 +1,27 @@
1
-
2
1
  import { Core } from '../core'
3
2
  import { Filter } from '../type'
4
3
  import { ui } from './ui'
5
4
 
6
-
7
-
8
5
  type Promisable<T> = T | PromiseLike<T>
9
6
 
7
+ type onfulfilled<T, U> = ((value: T) => Promisable<U>) | undefined | null
10
8
 
11
-
12
- type onfulfilled<T, U> =
13
- | ((value: T) => Promisable<U>)
14
- | undefined
15
- | null
16
-
17
- type onrejected<U> =
18
- | ((reason: any) => Promisable<U>)
19
- | undefined
20
- | null
21
-
22
-
9
+ type onrejected<U> = ((reason: any) => Promisable<U>) | undefined | null
23
10
 
24
11
  abstract class BuilderUI {
25
-
26
12
  private isSlience: boolean = false
27
13
  private isConfirm: boolean = false
28
- private confirmContent: { title: string, msg: string } = { title: '', msg: '' }
14
+ private confirmContent: { title: string; msg: string } = {
15
+ title: '',
16
+ msg: '',
17
+ }
29
18
  private isNotify: boolean = false
30
19
  private notifyContent: string = ''
31
20
 
32
-
33
21
  protected abstract dataLogic(): Promise<void>
34
22
 
35
-
36
23
  protected async run() {
37
- if (this.isSlience)
38
- ui.loadingOff()
24
+ if (this.isSlience) ui.loadingOff()
39
25
 
40
26
  if (this.isConfirm) {
41
27
  let { title, msg } = this.confirmContent
@@ -44,21 +30,17 @@ abstract class BuilderUI {
44
30
 
45
31
  await this.dataLogic()
46
32
 
47
- if (this.isNotify)
48
- ui.onNotify(this.notifyContent)
33
+ if (this.isNotify) ui.onNotify(this.notifyContent)
49
34
 
50
- if (this.isSlience)
51
- ui.loadingOn()
35
+ if (this.isSlience) ui.loadingOn()
52
36
  }
53
37
 
54
-
55
38
  confirm(title: string, ...msgs: string[]): this {
56
39
  this.isConfirm = true
57
40
  this.confirmContent = { title, msg: msgs.join('<br/>') }
58
41
  return this
59
42
  }
60
43
 
61
-
62
44
  notify(msg: string): this {
63
45
  this.isNotify = true
64
46
  this.notifyContent = msg
@@ -75,22 +57,20 @@ abstract class BuilderUI {
75
57
  this.isNotify = false
76
58
  return this
77
59
  }
78
-
79
60
  }
80
61
 
81
-
82
62
  abstract class Builder<T, R> extends BuilderUI implements PromiseLike<void> {
83
-
84
63
  constructor(
85
64
  protected core: Core<T, R>,
86
- private callback: (objs: T[]) => void,
87
- ) { super() }
65
+ private callback: (objs: T[]) => void
66
+ ) {
67
+ super()
68
+ }
88
69
 
89
70
  protected abstract logType: string
90
71
 
91
72
  protected abstract fetch(): Promise<R[]>
92
73
 
93
-
94
74
  protected override async dataLogic(): Promise<void> {
95
75
  let data = await this.fetch()
96
76
  let entities = data.map($ => this.core.convertor($))
@@ -98,18 +78,15 @@ abstract class Builder<T, R> extends BuilderUI implements PromiseLike<void> {
98
78
  ui.log(this.core.tableName, this.logType, entities)
99
79
  }
100
80
 
101
-
102
- async then<Y, N>(onfulfilled?: onfulfilled<void, Y>, onrejected?: onrejected<N>): Promise<Y | N> {
81
+ async then<Y, N>(
82
+ onfulfilled?: onfulfilled<void, Y>,
83
+ onrejected?: onrejected<N>
84
+ ): Promise<Y | N> {
103
85
  return this.run().then(onfulfilled, onrejected)
104
86
  }
105
-
106
87
  }
107
88
 
108
-
109
-
110
-
111
- abstract class FilterBuilder<T, R> extends Builder<T, R>{
112
-
89
+ abstract class FilterBuilder<T, R> extends Builder<T, R> {
113
90
  protected filters: Filter<R>[] = []
114
91
 
115
92
  eq<K extends keyof R>(key: K, val: R[K]): this {
@@ -127,43 +104,36 @@ abstract class FilterBuilder<T, R> extends Builder<T, R>{
127
104
  return this
128
105
  }
129
106
 
130
-
131
107
  limit(count: number): this {
132
108
  this.filters.push({ type: 'limit', payload: count })
133
109
  return this
134
110
  }
135
111
 
136
-
137
112
  order<K extends keyof R>(key: K, ascending: boolean = true): this {
138
113
  this.filters.push({ type: 'order', payload: { key, asc: ascending } })
139
114
  return this
140
115
  }
141
-
142
-
143
116
  }
144
117
 
145
-
146
- export class SelectBuilder<T, R> extends FilterBuilder<T, R>{
147
-
118
+ export class SelectBuilder<T, R> extends FilterBuilder<T, R> {
148
119
  protected logType = 'select'
149
120
 
150
121
  protected override async fetch() {
151
122
  return this.core.fetchSelect(this.filters)
152
123
  }
153
-
154
124
  }
155
125
 
156
-
157
-
158
- export class SelectInBuilder<T, R, K extends keyof R> extends FilterBuilder<T, R>{
159
-
126
+ export class SelectInBuilder<T, R, K extends keyof R> extends FilterBuilder<
127
+ T,
128
+ R
129
+ > {
160
130
  protected logType = 'selectIn'
161
131
 
162
132
  constructor(
163
133
  private key: K,
164
134
  private vals: R[K][],
165
135
  core: Core<T, R>,
166
- callback: (objs: T[]) => void,
136
+ callback: (objs: T[]) => void
167
137
  ) {
168
138
  super(core, callback)
169
139
  }
@@ -171,18 +141,15 @@ export class SelectInBuilder<T, R, K extends keyof R> extends FilterBuilder<T, R
171
141
  protected override async fetch() {
172
142
  return this.core.fetchSelectIn(this.key, this.vals, this.filters)
173
143
  }
174
-
175
144
  }
176
145
 
177
-
178
- export class SelectRPCBuilder<T, R> extends FilterBuilder<T, R>{
179
-
146
+ export class SelectRPCBuilder<T, R> extends FilterBuilder<T, R> {
180
147
  protected logType = 'rpc'
181
148
 
182
149
  constructor(
183
150
  private param: object,
184
151
  core: Core<T, R>,
185
- callback: (objs: T[]) => void,
152
+ callback: (objs: T[]) => void
186
153
  ) {
187
154
  super(core, callback)
188
155
  }
@@ -190,20 +157,15 @@ export class SelectRPCBuilder<T, R> extends FilterBuilder<T, R>{
190
157
  protected override async fetch() {
191
158
  return this.core.fetchRPC(this.param, this.filters)
192
159
  }
193
-
194
160
  }
195
161
 
196
-
197
-
198
-
199
- export class InsertBuilder<T, R> extends Builder<T, R>{
200
-
162
+ export class InsertBuilder<T, R> extends Builder<T, R> {
201
163
  protected logType = 'insert'
202
164
 
203
165
  constructor(
204
166
  private rows: Partial<R>[],
205
167
  core: Core<T, R>,
206
- callback: (objs: T[]) => void,
168
+ callback: (objs: T[]) => void
207
169
  ) {
208
170
  super(core, callback)
209
171
  }
@@ -211,20 +173,16 @@ export class InsertBuilder<T, R> extends Builder<T, R>{
211
173
  protected override async fetch() {
212
174
  return this.core.fetchInsert(this.rows)
213
175
  }
214
-
215
176
  }
216
177
 
217
-
218
-
219
- export class UpdateBuilder<T, R> extends Builder<T, R>{
220
-
178
+ export class UpdateBuilder<T, R> extends Builder<T, R> {
221
179
  protected logType = 'update'
222
180
 
223
181
  constructor(
224
182
  private idVal: R[keyof R],
225
183
  private row: Partial<R>,
226
184
  core: Core<T, R>,
227
- callback: (objs: T[]) => void,
185
+ callback: (objs: T[]) => void
228
186
  ) {
229
187
  super(core, callback)
230
188
  }
@@ -232,19 +190,15 @@ export class UpdateBuilder<T, R> extends Builder<T, R>{
232
190
  protected override async fetch() {
233
191
  return this.core.fetchUpdate(this.idVal, this.row)
234
192
  }
235
-
236
193
  }
237
194
 
238
-
239
-
240
- export class DeleteBuilder<T, R> extends Builder<T, R>{
241
-
195
+ export class DeleteBuilder<T, R> extends Builder<T, R> {
242
196
  protected logType = 'delete'
243
197
 
244
198
  constructor(
245
199
  private idVal: R[keyof R],
246
200
  core: Core<T, R>,
247
- callback: (objs: T[]) => void,
201
+ callback: (objs: T[]) => void
248
202
  ) {
249
203
  super(core, callback)
250
204
  }
@@ -252,23 +206,16 @@ export class DeleteBuilder<T, R> extends Builder<T, R>{
252
206
  protected override async fetch() {
253
207
  return this.core.fetchDelete(this.idVal)
254
208
  }
255
-
256
209
  }
257
210
 
258
-
259
-
260
-
261
-
262
-
263
- export class UpsertBuilder<T, R> extends Builder<T, R>{
264
-
211
+ export class UpsertBuilder<T, R> extends Builder<T, R> {
265
212
  protected logType = 'upsert'
266
213
 
267
214
  constructor(
268
215
  private row: Partial<R>,
269
216
  private conflictKeys: (keyof R)[],
270
217
  core: Core<T, R>,
271
- callback: (objs: T[]) => void,
218
+ callback: (objs: T[]) => void
272
219
  ) {
273
220
  super(core, callback)
274
221
  }
@@ -276,6 +223,4 @@ export class UpsertBuilder<T, R> extends Builder<T, R>{
276
223
  protected override async fetch() {
277
224
  return this.core.fetchUpsert(this.row, this.conflictKeys)
278
225
  }
279
-
280
226
  }
281
-
@@ -2,20 +2,17 @@ import { qDialog } from '../..'
2
2
  import { qNotify } from '../..'
3
3
  import { LoadingBar } from 'quasar'
4
4
 
5
-
6
5
  /**
7
6
  * I am responsible for providing UI interaction functions using Quasar.
8
7
  * Purely functional.
9
8
  */
10
9
  class UI {
11
-
12
-
13
10
  loadingOff(): void {
14
- LoadingBar.setDefaults({ size: "0px" })
11
+ LoadingBar.setDefaults({ size: '0px' })
15
12
  }
16
13
 
17
14
  loadingOn(): void {
18
- setTimeout(() => LoadingBar.setDefaults({ size: "5px" }), 3000)
15
+ setTimeout(() => LoadingBar.setDefaults({ size: '5px' }), 3000)
19
16
  }
20
17
 
21
18
  onConfirm(title: string, msg: string): Promise<void> {
@@ -27,11 +24,8 @@ class UI {
27
24
  }
28
25
 
29
26
  log(table: string, type: string, data: any[]): void {
30
- if (process.env.DEBUGGING)
31
- console.log(`[${table}] ${type}`, data)
27
+ if (process.env.DEBUGGING) console.log(`[${table}] ${type}`, data)
32
28
  }
33
-
34
-
35
29
  }
36
30
 
37
31
  export const ui = new UI()
@@ -1,23 +1,24 @@
1
1
  import { Filter } from '../type'
2
2
  import { db } from './db'
3
3
 
4
-
5
-
6
4
  /** I am responsible for transfering the state from Table to Builders.*/
7
5
  export class Core<T, R> {
8
-
9
6
  constructor(
10
7
  public tableName: string,
11
8
  public idKey: keyof R,
12
9
  public fields: (keyof R)[],
13
10
  public convertor: ($: R) => T
14
- ) { }
11
+ ) {}
15
12
 
16
13
  async fetchSelect(filters: Filter<R>[]): Promise<R[]> {
17
14
  return db.select(this.tableName, this.fields, filters)
18
15
  }
19
16
 
20
- async fetchSelectIn<K extends keyof R>(key: K, vals: R[K][], filters: Filter<R>[]): Promise<R[]> {
17
+ async fetchSelectIn<K extends keyof R>(
18
+ key: K,
19
+ vals: R[K][],
20
+ filters: Filter<R>[]
21
+ ): Promise<R[]> {
21
22
  return db.selectIn(this.tableName, this.fields, key, vals, filters)
22
23
  }
23
24
 
@@ -37,11 +38,10 @@ export class Core<T, R> {
37
38
  return db.delete(this.tableName, this.idKey, idVal)
38
39
  }
39
40
 
40
- async fetchUpsert(row: Partial<R>, conflictKeys: (keyof R)[]): Promise<R[]> {
41
+ async fetchUpsert(
42
+ row: Partial<R>,
43
+ conflictKeys: (keyof R)[]
44
+ ): Promise<R[]> {
41
45
  return db.upsert(this.tableName, this.idKey, row, conflictKeys)
42
46
  }
43
-
44
-
45
47
  }
46
-
47
-
@@ -1,19 +1,12 @@
1
1
  import { DeleteBuilder, UpdateBuilder } from './builder'
2
2
  import { Constructor, BooleanKeys } from './type'
3
3
 
4
-
5
4
  export function ENTITY<
6
5
  TBase extends Constructor,
7
6
  K extends string & keyof R,
8
7
  R extends InstanceType<TBase> = InstanceType<TBase>
9
- >(
10
- RowClass: TBase,
11
- tableName: string,
12
- idKey: K
13
- ) {
14
-
8
+ >(RowClass: TBase, tableName: string, idKey: K) {
15
9
  class VIEW extends RowClass {
16
-
17
10
  constructor(...args: any[]) {
18
11
  super(...args)
19
12
  let template = args[0] ?? {}
@@ -27,13 +20,9 @@ export function ENTITY<
27
20
  static _idKey: K = idKey
28
21
 
29
22
  static _fields: any[] = Object.keys(new RowClass())
30
-
31
23
  }
32
24
 
33
-
34
-
35
25
  class EDIT extends VIEW {
36
-
37
26
  update(row: Partial<R>): UpdateBuilder<any, R> {
38
27
  // @ts-ignore
39
28
  return this._hostTable.updateRow(this, row)
@@ -48,13 +37,9 @@ export function ENTITY<
48
37
  // @ts-ignore
49
38
  return this._hostTable.updateRow(this, { [key]: !this[key] })
50
39
  }
51
-
52
-
53
40
  }
54
41
  return {
55
42
  EDIT,
56
- VIEW
43
+ VIEW,
57
44
  }
58
45
  }
59
-
60
-
@@ -1,3 +1,2 @@
1
1
  export { ENTITY } from './entity'
2
2
  export { TABLE } from './table'
3
-
@@ -1,4 +1,3 @@
1
- import { Criteria, Ordering, Sheet } from '../sapphire'
2
1
  import {
3
2
  DeleteBuilder,
4
3
  InsertBuilder,
@@ -12,6 +11,7 @@ import { Constructor } from './type'
12
11
  import { Core } from './core'
13
12
  import { ENTITY } from './entity'
14
13
  import { reactive } from 'vue'
14
+ import _ from 'lodash'
15
15
 
16
16
  type imprinted<R extends object> = {
17
17
  _RowClass: Constructor
@@ -38,7 +38,7 @@ export function TABLE<
38
38
  ClassT extends EntityClass<T, R>,
39
39
  R extends RowOf<ClassT> = RowOf<ClassT>,
40
40
  T extends R = InstanceType<ClassT>
41
- >(EntityClass: ClassT, ordering: Ordering<InstanceType<ClassT>> = []) {
41
+ >(EntityClass: ClassT) {
42
42
  const tableName: string = EntityClass._tableName
43
43
  const idKey: ClassT['_idKey'] = EntityClass._idKey
44
44
  const fields: any[] = EntityClass._fields
@@ -58,24 +58,7 @@ export function TABLE<
58
58
  return new Core<T, R>(tableName, idKey, fields, convertor(host))
59
59
  }
60
60
 
61
- class Base extends Sheet<T> {
62
- protected reorder() {
63
- this.order(...ordering)
64
- }
65
-
66
- /** Get an item by `criteria`. If not found, throw error. */
67
- got(criteria: Criteria<T>): T {
68
- let obj = this.get(criteria)
69
- if (obj === undefined) {
70
- throw (
71
- EntityClass.name +
72
- ' has no element matching ' +
73
- JSON.stringify(criteria)
74
- )
75
- }
76
- return obj
77
- }
78
-
61
+ class Base extends Array<T> {
79
62
  /** make reactive */
80
63
  reactive(): this {
81
64
  const rec = reactive(this) as this
@@ -91,16 +74,9 @@ export function TABLE<
91
74
  }
92
75
 
93
76
  class TableView extends Base {
94
- private orderByList<K extends keyof R>(key: K, vals: R[K][]) {
95
- ordering.length > 0
96
- ? this.reorder()
97
- : this.order({ [key]: vals } as any)
98
- }
99
-
100
77
  select() {
101
78
  let callback = ($: T[]) => {
102
79
  this.set($)
103
- this.reorder()
104
80
  this.onChange()
105
81
  }
106
82
  return new SelectBuilder(core(this), callback)
@@ -109,7 +85,6 @@ export function TABLE<
109
85
  patch() {
110
86
  let callback = ($: T[]) => {
111
87
  this.absorb($, idKey)
112
- this.reorder()
113
88
  this.onChange()
114
89
  }
115
90
  return new SelectBuilder(core(this), callback)
@@ -118,7 +93,7 @@ export function TABLE<
118
93
  selectIn<K extends keyof R>(key: K, vals: R[K][]) {
119
94
  let callback = ($: T[]) => {
120
95
  this.set($)
121
- this.orderByList(key, vals)
96
+ this.sortBy($ => vals.indexOf($[key]))
122
97
  this.onChange()
123
98
  }
124
99
  return new SelectInBuilder(key, vals, core(this), callback)
@@ -127,7 +102,7 @@ export function TABLE<
127
102
  patchIn<K extends keyof R>(key: K, vals: R[K][]) {
128
103
  let callback = ($: T[]) => {
129
104
  this.absorb($, idKey)
130
- this.orderByList(key, vals)
105
+ this.sortBy($ => vals.indexOf($[key]))
131
106
  this.onChange()
132
107
  }
133
108
  return new SelectInBuilder(key, vals, core(this), callback)
@@ -138,7 +113,6 @@ export function TABLE<
138
113
  selectRPC(param: object = {}) {
139
114
  let callback = ($: T[]) => {
140
115
  this.set($)
141
- this.reorder()
142
116
  this.onChange()
143
117
  }
144
118
  return new SelectRPCBuilder(param, core(this), callback)
@@ -147,7 +121,6 @@ export function TABLE<
147
121
  patchRPC(param: object = {}) {
148
122
  let callback = ($: T[]) => {
149
123
  this.absorb($, idKey)
150
- this.reorder()
151
124
  this.onChange()
152
125
  }
153
126
  return new SelectRPCBuilder(param, core(this), callback)
@@ -158,7 +131,6 @@ export function TABLE<
158
131
  insert(row: Partial<R>) {
159
132
  let callback = ($: T[]) => {
160
133
  this.push(...$)
161
- this.reorder()
162
134
  this.onChange()
163
135
  this.onEdit()
164
136
  }
@@ -170,7 +142,6 @@ export function TABLE<
170
142
  update(idVal: R[ClassT['_idKey']], row: Partial<R>) {
171
143
  let callback = ($: T[]) => {
172
144
  this.merge($, idKey)
173
- this.reorder()
174
145
  this.onChange()
175
146
  this.onEdit()
176
147
  }
@@ -186,8 +157,7 @@ export function TABLE<
186
157
 
187
158
  delete(idVal: R[ClassT['_idKey']]) {
188
159
  let callback = ($: T[]) => {
189
- this.discard({ [idKey]: idVal } as any)
190
- this.reorder()
160
+ _.remove(this, $ => $[idKey] === idVal)
191
161
  this.onChange()
192
162
  this.onEdit()
193
163
  }
@@ -204,7 +174,6 @@ export function TABLE<
204
174
  upsert(row: Partial<R>, conflictKeys: (keyof R)[]) {
205
175
  let callback = ($: T[]) => {
206
176
  this.absorb($, idKey)
207
- this.reorder()
208
177
  this.onChange()
209
178
  this.onEdit()
210
179
  }
@@ -1,17 +1,13 @@
1
-
2
1
  export type Filter<R> =
3
- | { type: 'eq', payload: { key: keyof R, val: any } }
4
- | { type: 'in', payload: { key: keyof R, vals: any[] } }
5
- | { type: 'like', payload: { key: keyof R, pattern: string } }
6
- | { type: 'limit', payload: number }
7
- | { type: 'order', payload: { key: keyof R, asc: boolean } }
8
-
9
-
10
-
11
-
2
+ | { type: 'eq'; payload: { key: keyof R; val: any } }
3
+ | { type: 'in'; payload: { key: keyof R; vals: any[] } }
4
+ | { type: 'like'; payload: { key: keyof R; pattern: string } }
5
+ | { type: 'limit'; payload: number }
6
+ | { type: 'order'; payload: { key: keyof R; asc: boolean } }
12
7
 
13
8
  export type Constructor<T extends object = {}> = new (...args: any[]) => T
14
9
 
15
-
16
- export type BooleanKeys<T> = { [k in keyof T]: T[k] extends boolean ? k : never }[keyof T]
10
+ export type BooleanKeys<T> = {
11
+ [k in keyof T]: T[k] extends boolean ? k : never
12
+ }[keyof T]
17
13
  // type OnlyBoolean<T> = { [k in BooleanKeys<T>]: boolean }