@d-mok/quasar-app-extension-quasar-axe 2.1.50 → 2.1.52

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.50",
3
+ "version": "2.1.52",
4
4
  "description": "A Quasar App Extension",
5
5
  "author": "d-mok <49301824+d-mok@users.noreply.github.com>",
6
6
  "license": "MIT",
@@ -34,7 +34,8 @@
34
34
  "core-js": "^3.30.2",
35
35
  "quasar": "^2.12.0",
36
36
  "typescript": "^5.0.4",
37
- "vite": "^4.3.9"
37
+ "vite": "^4.3.9",
38
+ "vue": "^3.3.4"
38
39
  },
39
40
  "prettier": {
40
41
  "tabWidth": 4,
@@ -67,13 +67,21 @@
67
67
  :key="$route.fullPath"
68
68
  >
69
69
  <transition
70
- enter-active-class="animated fadeIn"
71
- leave-active-class="animated fadeOut"
70
+ enterActiveClass="animated fadeIn"
71
+ leaveActiveClass="animated fadeOut"
72
72
  appear
73
73
  mode="out-in"
74
74
  :duration="200"
75
75
  >
76
- <component :is="Component" />
76
+ <q-page
77
+ padding
78
+ class="q-mx-auto q-gutter-md"
79
+ >
80
+ <component
81
+ :is="Component"
82
+ style="margin: auto"
83
+ />
84
+ </q-page>
77
85
  </transition>
78
86
  </router-view>
79
87
  </q-page-container>
@@ -1,54 +1,66 @@
1
1
  <template>
2
2
  <q-select
3
- v-model="selected"
3
+ v-model="modelValue"
4
4
  :options="options"
5
- :option-label="optionLabel"
5
+ :option-label="optionLabel ?? ($ => String($))"
6
+ :option-value="optionValue ?? ($ => $)"
7
+ emit-value
8
+ map-options
6
9
  v-bind="$attrs"
7
10
  />
8
11
  </template>
9
12
 
10
- <script lang="ts" setup>
13
+ <script lang="ts" setup generic="T,R">
11
14
  import { watch } from 'vue'
12
- import { useVModel } from '@vueuse/core'
13
15
  import _ from 'lodash'
14
16
 
15
- const props = withDefaults(
16
- defineProps<{
17
- options: any[]
18
- modelValue: any
19
- optionLabel?: string | ((_: any) => string)
20
- ticker?: number
21
- }>(),
22
- {
23
- optionLabel: ($: any) => String($),
24
- ticker: 0,
25
- }
26
- )
27
- const emits = defineEmits(['update:modelValue'])
17
+ const modelValue = defineModel<R>({ required: true })
18
+
19
+ let {
20
+ options,
21
+ optionLabel,
22
+ optionValue,
23
+ ticker = 0,
24
+ } = defineProps<{
25
+ options: T[]
26
+ optionLabel?: string | ((_: T) => string)
27
+ optionValue?: string | ((_: T) => R)
28
+ ticker?: number
29
+ }>()
28
30
 
29
- const selected = useVModel(props, 'modelValue', emits)
31
+ function getValue(opt: T): R {
32
+ if (optionValue === undefined) {
33
+ return opt as any
34
+ } else if (typeof optionValue === 'string') {
35
+ return opt[optionValue as keyof T] as any
36
+ } else {
37
+ return optionValue(opt) as any
38
+ }
39
+ }
30
40
 
31
41
  function select(i: number) {
32
- i = _.clamp(i, 0, props.options.length - 1)
33
- selected.value = props.options[i]
42
+ i = _.clamp(i, 0, options.length - 1)
43
+ modelValue.value = getValue(options[i])
34
44
  }
35
45
 
36
46
  function rePick() {
37
- if (props.options.length === 0) return
38
- if (!props.options.includes(selected.value)) select(0)
47
+ const missingSelected = !options.map(getValue).includes(modelValue.value)
48
+ if (options.length > 0 && missingSelected) select(0)
39
49
  }
40
50
 
41
51
  rePick()
42
- watch(() => props.options, rePick)
43
-
44
- function getCurrentIndex(): number {
45
- return props.options.findIndex($ => $ === selected.value)
46
- }
52
+ watch(
53
+ () => options,
54
+ (now, old) => {
55
+ if (!_.isEqual(now, old)) rePick()
56
+ }
57
+ )
47
58
 
48
59
  watch(
49
- () => props.ticker,
60
+ () => ticker,
50
61
  (now, old) => {
51
- let i = getCurrentIndex()
62
+ // i = current index
63
+ let i = options.findIndex($ => getValue($) === modelValue.value)
52
64
  if (i === -1) return
53
65
  if (now > old) select(i + 1)
54
66
  if (now < old) select(i - 1)