@d-mok/quasar-app-extension-quasar-axe 2.0.3 → 2.0.6

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.3",
3
+ "version": "2.0.6",
4
4
  "description": "A Quasar App Extension",
5
5
  "author": "d-mok <49301824+d-mok@users.noreply.github.com>",
6
6
  "license": "MIT",
@@ -16,11 +16,13 @@
16
16
  "dependencies": {
17
17
  "@handsontable/vue3": "^12.1.0",
18
18
  "@supabase/supabase-js": "^1.35.4",
19
+ "@types/lodash": "^4.14.182",
19
20
  "@types/papaparse": "^5.3.2",
20
21
  "@types/webpack-env": "^1.17.0",
21
22
  "@vueuse/core": "^9.1.0",
22
23
  "handsontable": "^12.1.0",
23
24
  "jszip": "^3.9.0",
25
+ "lodash": "^4.17.21",
24
26
  "papaparse": "^5.3.2",
25
27
  "sapphire-js": "^1.0.67",
26
28
  "vuedraggable": "^4.1.0"
@@ -0,0 +1,60 @@
1
+ <template>
2
+ <q-select
3
+ v-model="selected"
4
+ :options="options"
5
+ :option-label="optionLabel"
6
+ v-bind="$attrs"
7
+ />
8
+ </template>
9
+
10
+ <script
11
+ lang="ts"
12
+ setup
13
+ >
14
+ import { watch } from 'vue'
15
+ import { useVModel } from '@vueuse/core'
16
+ import _ from 'lodash'
17
+
18
+ const props = withDefaults(
19
+ defineProps<{
20
+ options: any[]
21
+ modelValue: any
22
+ optionLabel?: string | ((_: any) => string)
23
+ ticker?: number
24
+ }>(),
25
+ {
26
+ optionLabel: $ => String($),
27
+ ticker: 0,
28
+ }
29
+ )
30
+ const emits = defineEmits(['update:modelValue'])
31
+
32
+ const selected = useVModel(props, 'modelValue', emits)
33
+
34
+ function select(i: number) {
35
+ i = _.clamp(i, 0, props.options.length - 1)
36
+ selected.value = props.options[i]
37
+ }
38
+
39
+ function rePick() {
40
+ if (props.options.length === 0) return
41
+ if (!props.options.includes(selected.value)) select(0)
42
+ }
43
+
44
+ rePick()
45
+ watch(() => props.options, rePick)
46
+
47
+ function getCurrentIndex(): number {
48
+ return props.options.findIndex($ => $ === selected.value)
49
+ }
50
+
51
+ watch(
52
+ () => props.ticker,
53
+ (now, old) => {
54
+ let i = getCurrentIndex()
55
+ if (i === -1) return
56
+ if (now > old) select(i + 1)
57
+ if (now < old) select(i - 1)
58
+ }
59
+ )
60
+ </script>
@@ -1,19 +1,11 @@
1
- import { supabase, HANDLE_ERROR, PostgrestFilterBuilder, PostgrestSingleResponse } from '../../supabase'
1
+ import {
2
+ supabase,
3
+ HANDLE_ERROR,
4
+ PostgrestFilterBuilder,
5
+ PostgrestSingleResponse,
6
+ } from '../../supabase'
2
7
  import { Filter } from '../type'
3
-
4
-
5
-
6
-
7
- function chunk<T>(arr: T[], size: number): T[][] {
8
- if (size <= 0) return []
9
- let newArr = []
10
- for (let i = 0; i < arr.length; i += size) {
11
- newArr.push(arr.slice(i, i + size))
12
- }
13
- return newArr
14
- }
15
-
16
-
8
+ import _ from 'lodash'
17
9
 
18
10
  async function send<R>(q: PostgrestFilterBuilder<R>): Promise<R[]> {
19
11
  let { data, error } = await q
@@ -21,73 +13,67 @@ async function send<R>(q: PostgrestFilterBuilder<R>): Promise<R[]> {
21
13
  return data
22
14
  }
23
15
 
24
-
25
- async function sendSingle<R>(q: PromiseLike<PostgrestSingleResponse<R>>): Promise<R[]> {
16
+ async function sendSingle<R>(
17
+ q: PromiseLike<PostgrestSingleResponse<R>>
18
+ ): Promise<R[]> {
26
19
  let { data, error } = await q
27
20
  HANDLE_ERROR(data, error)
28
21
  return [data]
29
22
  }
30
23
 
31
-
32
-
33
-
34
- function parseFilter<R>(q: PostgrestFilterBuilder<R>, filter: Filter<R>): PostgrestFilterBuilder<R> {
24
+ function parseFilter<R>(
25
+ q: PostgrestFilterBuilder<R>,
26
+ filter: Filter<R>
27
+ ): PostgrestFilterBuilder<R> {
35
28
  if (filter.type === 'eq') q = q.eq(filter.payload.key, filter.payload.val)
36
29
  if (filter.type === 'in') q = q.in(filter.payload.key, filter.payload.vals)
37
- if (filter.type === 'like') q = q.like(filter.payload.key, filter.payload.pattern)
30
+ if (filter.type === 'like')
31
+ q = q.like(filter.payload.key, filter.payload.pattern)
38
32
  return q
39
33
  }
40
34
 
41
-
42
- function parseLimit<R>(q: PostgrestFilterBuilder<R>, filter: Filter<R>): PostgrestFilterBuilder<R> {
43
- if (filter.type === 'limit')
44
- q = q.limit(filter.payload)
35
+ function parseLimit<R>(
36
+ q: PostgrestFilterBuilder<R>,
37
+ filter: Filter<R>
38
+ ): PostgrestFilterBuilder<R> {
39
+ if (filter.type === 'limit') q = q.limit(filter.payload)
45
40
  return q
46
41
  }
47
42
 
48
-
49
- function parseOrder<R>(q: PostgrestFilterBuilder<R>, filter: Filter<R>): PostgrestFilterBuilder<R> {
43
+ function parseOrder<R>(
44
+ q: PostgrestFilterBuilder<R>,
45
+ filter: Filter<R>
46
+ ): PostgrestFilterBuilder<R> {
50
47
  if (filter.type === 'order')
51
48
  q = q.order(filter.payload.key, { ascending: filter.payload.asc })
52
49
  return q
53
50
  }
54
51
 
55
-
56
52
  function parseFilters<R>(
57
53
  q: PostgrestFilterBuilder<R>,
58
54
  filters: Filter<R>[]
59
55
  ): PostgrestFilterBuilder<R> {
60
- for (const filter of filters)
61
- q = parseFilter(q, filter)
62
- for (const filter of filters)
63
- q = parseOrder(q, filter)
64
- for (const filter of filters)
65
- q = parseLimit(q, filter)
56
+ for (const filter of filters) q = parseFilter(q, filter)
57
+ for (const filter of filters) q = parseOrder(q, filter)
58
+ for (const filter of filters) q = parseLimit(q, filter)
66
59
  return q
67
60
  }
68
61
 
69
-
70
-
71
-
72
62
  /**
73
63
  * I am responsible for providing database operation.
74
64
  * Purely functional.
75
65
  */
76
66
  class DB {
77
-
78
67
  async select<R>(
79
68
  table: string,
80
69
  fields: (keyof R)[],
81
70
  filters: Filter<R>[]
82
71
  ): Promise<R[]> {
83
- let q = supabase
84
- .from<R>(table)
85
- .select(fields.join(','))
72
+ let q = supabase.from<R>(table).select(fields.join(','))
86
73
  q = parseFilters(q, filters)
87
74
  return send(q)
88
75
  }
89
76
 
90
-
91
77
  async selectIn<R, K extends keyof R>(
92
78
  table: string,
93
79
  fields: (keyof R)[],
@@ -103,78 +89,57 @@ class DB {
103
89
  q = parseFilters(q, filters)
104
90
  return send(q)
105
91
  }
106
- let promises = chunk(vals, 100).map(getRows)
92
+ let promises = _.chunk(vals, 100).map(getRows)
107
93
  let result = await Promise.all(promises)
108
94
  return result.flat()
109
95
  }
110
96
 
111
-
112
97
  async rpc<R>(
113
98
  fn: string,
114
99
  param: object,
115
100
  filters: Filter<R>[]
116
101
  ): Promise<R[]> {
117
- let q = supabase
118
- .rpc<R>(fn, param)
102
+ let q = supabase.rpc<R>(fn, param)
119
103
  q = parseFilters(q, filters)
120
104
  return send(q)
121
105
  }
122
106
 
123
-
124
-
125
- async insert<R>(
126
- table: string,
127
- rows: Partial<R>[]
128
- ): Promise<R[]> {
129
- let q = supabase
130
- .from<R>(table)
131
- .insert(rows)
107
+ async insert<R>(table: string, rows: Partial<R>[]): Promise<R[]> {
108
+ let q = supabase.from<R>(table).insert(rows)
132
109
  return send(q)
133
110
  }
134
111
 
135
-
136
112
  async update<R, K extends keyof R>(
137
113
  table: string,
138
114
  idKey: K,
139
115
  idVal: R[K],
140
116
  row: Partial<R>
141
117
  ): Promise<R[]> {
142
- let q = supabase
143
- .from<R>(table)
144
- .update(row)
145
- .eq(idKey, idVal)
146
- .single()
118
+ let q = supabase.from<R>(table).update(row).eq(idKey, idVal).single()
147
119
  return sendSingle(q)
148
120
  }
149
121
 
150
-
151
122
  async delete<R, K extends keyof R>(
152
123
  table: string,
153
124
  idKey: K,
154
125
  idVal: R[K]
155
126
  ): Promise<R[]> {
156
- let q = supabase
157
- .from<R>(table)
158
- .delete()
159
- .eq(idKey, idVal)
160
- .single()
127
+ let q = supabase.from<R>(table).delete().eq(idKey, idVal).single()
161
128
  return sendSingle(q)
162
129
  }
163
130
 
164
-
165
131
  async upsert<R, K extends keyof R>(
166
132
  table: string,
167
133
  idKey: K,
168
134
  row: Partial<R>,
169
135
  conflictKeys: (keyof R)[]
170
136
  ): Promise<R[]> {
171
-
172
137
  let conflict: any = {}
173
138
  for (let f of conflictKeys) {
174
139
  conflict[f] = row[f]
175
140
  }
176
141
 
177
- let q = supabase.from<R>(table).select("*").match(conflict)
142
+ let q = supabase.from<R>(table).select('*').match(conflict)
178
143
  let data = await send(q)
179
144
 
180
145
  if (data.length > 1)
@@ -186,11 +151,7 @@ class DB {
186
151
  } else {
187
152
  return await this.insert(table, [row])
188
153
  }
189
-
190
154
  }
191
-
192
-
193
155
  }
194
156
 
195
-
196
- export const db = new DB()
157
+ export const db = new DB()
@@ -1,63 +0,0 @@
1
- <template>
2
- <q-select
3
- :model-value="modelValue"
4
- @update:model-value="e => emits('update:modelValue', e)"
5
- :options="options"
6
- :option-label="optionLabel"
7
- v-bind="$attrs"
8
- >
9
- </q-select>
10
- </template>
11
-
12
- <script
13
- lang="ts"
14
- setup
15
- >
16
- import { watch } from 'vue'
17
-
18
- type Props = {
19
- options: any[]
20
- modelValue: any
21
- optionLabel: string
22
- ticker?: number
23
- }
24
-
25
- const props = withDefaults(defineProps<Props>(), { ticker: 0 })
26
-
27
- const emits = defineEmits(['update:modelValue'])
28
-
29
- function rePick() {
30
- if (props.options.length === 0) return
31
-
32
- if (!props.options.includes(props.modelValue))
33
- emits('update:modelValue', props.options[0])
34
- }
35
-
36
- rePick()
37
- watch(
38
- () => props.options,
39
- () => {
40
- rePick()
41
- }
42
- )
43
-
44
- function getCurrentIndex(): number {
45
- return props.options.findIndex($ => $ === props.modelValue)
46
- }
47
-
48
- watch(
49
- () => props.ticker,
50
- (now, old) => {
51
- let i = getCurrentIndex()
52
- if (i === -1) return
53
- if (now > old) {
54
- let j = Math.min(i + 1, props.options.length - 1)
55
- emits('update:modelValue', props.options[j])
56
- }
57
- if (now < old) {
58
- let j = Math.max(i - 1, 0)
59
- emits('update:modelValue', props.options[j])
60
- }
61
- }
62
- )
63
- </script>
@@ -1,35 +0,0 @@
1
- <template>
2
- <q-select
3
- v-model="selected"
4
- :options="options"
5
- v-bind="$attrs"
6
- >
7
- </q-select>
8
- </template>
9
-
10
- <script
11
- lang="ts"
12
- setup
13
- >
14
- import { watch } from 'vue'
15
- import { useVModel } from '@vueuse/core'
16
-
17
- const props = defineProps<{
18
- options: string[]
19
- modelValue: string
20
- }>()
21
-
22
- const emits = defineEmits(['update:modelValue'])
23
-
24
- const selected = useVModel(props, 'modelValue', emits)
25
-
26
- function rePick() {
27
- if (props.options.length === 0) return
28
-
29
- if (!props.options.includes(selected.value))
30
- selected.value = props.options[0]
31
- }
32
-
33
- rePick()
34
- watch(() => props.options, rePick)
35
- </script>