@mythpe/quasar-ui-qui 0.0.23-dev → 0.0.24-dev
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/index.d.ts +4 -0
- package/package.json +8 -5
- package/src/components/form/MAvatarViewer.vue +324 -0
- package/src/components/form/MBtn.vue +258 -91
- package/src/components/form/MCheckbox.vue +123 -0
- package/src/components/form/MColor.vue +122 -0
- package/src/components/form/MDate.vue +47 -0
- package/src/components/form/MEditor.vue +285 -0
- package/src/components/form/MEmail.vue +40 -0
- package/src/components/form/MField.vue +142 -0
- package/src/components/form/MFile.vue +209 -0
- package/src/components/form/MForm.vue +83 -0
- package/src/components/form/MHidden.vue +83 -0
- package/src/components/form/MHiddenInput.vue +55 -0
- package/src/components/form/MInput.vue +62 -65
- package/src/components/form/MInputFieldControl.vue +4 -1
- package/src/components/form/MInputLabel.vue +6 -2
- package/src/components/form/MMobile.vue +37 -0
- package/src/components/form/MPicker.vue +310 -0
- package/src/components/form/MRadio.vue +175 -0
- package/src/components/form/MSelect.vue +343 -0
- package/src/components/form/MTime.vue +45 -0
- package/src/components/form/index.ts +38 -1
- package/src/components/grid/MBlock.vue +31 -17
- package/src/components/grid/MCol.vue +2 -14
- package/src/components/grid/MContainer.vue +21 -12
- package/src/components/grid/MHelpRow.vue +4 -9
- package/src/components/grid/MRow.vue +22 -9
- package/src/components/index.ts +1 -0
- package/src/components/transition/MFadeTransition.vue +27 -0
- package/src/components/transition/MFadeXTransition.vue +26 -0
- package/src/components/transition/MTransition.vue +41 -0
- package/src/components/transition/index.ts +13 -0
- package/src/components/typography/index.ts +1 -0
- package/src/composable/index.ts +3 -1
- package/src/composable/{useHelpersMyth.ts → useBindInput.ts} +92 -62
- package/src/composable/useError.ts +11 -0
- package/src/composable/useMyth.ts +280 -3
- package/src/composable/useValue.ts +12 -0
- package/src/index.sass +7 -33
- package/src/style/m-container.sass +13 -0
- package/src/style/main.sass +42 -0
- package/src/types/api-helpers.d.ts +120 -0
- package/src/types/components.d.ts +550 -52
- package/src/types/dt.d.ts +142 -0
- package/src/types/index.d.ts +128 -47
- package/src/types/lodash.d.ts +26 -0
- package/src/types/quasar-helpers.d.ts +7 -0
- package/src/types/theme.d.ts +12 -0
- package/src/utils/Helpers.ts +321 -0
- package/src/utils/Str.ts +210 -0
- package/src/utils/index.ts +2 -0
- package/src/utils/myth.ts +75 -22
- package/src/utils/vee-rules.ts +2 -1
- package/src/utils/vue-plugin.ts +80 -3
- package/tsconfig.json +8 -11
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
- MyTh Ahmed Faiz Copyright © 2016-2024 All rights reserved.
|
|
3
|
+
- Email: mythpe@gmail.com
|
|
4
|
+
- Mobile: +966590470092
|
|
5
|
+
- Website: https://www.4myth.com
|
|
6
|
+
- Github: https://github.com/mythpe
|
|
7
|
+
-->
|
|
8
|
+
|
|
9
|
+
<script
|
|
10
|
+
lang="ts"
|
|
11
|
+
setup
|
|
12
|
+
>
|
|
13
|
+
defineOptions({
|
|
14
|
+
name: 'MFadeTransition',
|
|
15
|
+
inheritAttrs: !1
|
|
16
|
+
})
|
|
17
|
+
</script>
|
|
18
|
+
|
|
19
|
+
<template>
|
|
20
|
+
<Transition
|
|
21
|
+
appear
|
|
22
|
+
name="myth-transition__fade"
|
|
23
|
+
v-bind="$attrs"
|
|
24
|
+
>
|
|
25
|
+
<slot />
|
|
26
|
+
</Transition>
|
|
27
|
+
</template>
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
- MyTh Ahmed Faiz Copyright © 2016-2024 All rights reserved.
|
|
3
|
+
- Email: mythpe@gmail.com
|
|
4
|
+
- Mobile: +966590470092
|
|
5
|
+
- Website: https://www.4myth.com
|
|
6
|
+
- Github: https://github.com/mythpe
|
|
7
|
+
-->
|
|
8
|
+
<script
|
|
9
|
+
lang="ts"
|
|
10
|
+
setup
|
|
11
|
+
>
|
|
12
|
+
defineOptions({
|
|
13
|
+
name: 'MFadeXTransition',
|
|
14
|
+
inheritAttrs: !1
|
|
15
|
+
})
|
|
16
|
+
</script>
|
|
17
|
+
|
|
18
|
+
<template>
|
|
19
|
+
<Transition
|
|
20
|
+
appear
|
|
21
|
+
name="myth-transition__fade-x"
|
|
22
|
+
v-bind="$attrs"
|
|
23
|
+
>
|
|
24
|
+
<slot />
|
|
25
|
+
</Transition>
|
|
26
|
+
</template>
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
- MyTh Ahmed Faiz Copyright © 2016-2024 All rights reserved.
|
|
3
|
+
- Email: mythpe@gmail.com
|
|
4
|
+
- Mobile: +966590470092
|
|
5
|
+
- Website: https://www.4myth.com
|
|
6
|
+
- Github: https://github.com/mythpe
|
|
7
|
+
-->
|
|
8
|
+
|
|
9
|
+
<script lang="ts" setup>
|
|
10
|
+
import type { MTransitionProps as Props } from '../../types'
|
|
11
|
+
|
|
12
|
+
interface P {
|
|
13
|
+
enterIn?: Props['enterIn'];
|
|
14
|
+
enterOut?: Props['enterOut'];
|
|
15
|
+
slowIn?: Props['slowIn'];
|
|
16
|
+
slowOut?: Props['slowIn'];
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
withDefaults(defineProps<P>(), {
|
|
20
|
+
enterIn: () => 'fadeIn',
|
|
21
|
+
enterOut: () => 'fadeOut',
|
|
22
|
+
slowIn: () => !1,
|
|
23
|
+
slowOut: () => !1
|
|
24
|
+
})
|
|
25
|
+
defineOptions({
|
|
26
|
+
name: 'MTransition',
|
|
27
|
+
inheritAttrs: !1
|
|
28
|
+
})
|
|
29
|
+
</script>
|
|
30
|
+
|
|
31
|
+
<template>
|
|
32
|
+
<TransitionGroup
|
|
33
|
+
:enter-active-class="`animated ${enterIn} ${slowIn ? 'slow' : ''}`"
|
|
34
|
+
:leave-active-class="`animated ${enterOut} ${slowOut ? 'slow' : ''}`"
|
|
35
|
+
appear
|
|
36
|
+
name="m__transition__fade"
|
|
37
|
+
v-bind="$attrs"
|
|
38
|
+
>
|
|
39
|
+
<slot />
|
|
40
|
+
</TransitionGroup>
|
|
41
|
+
</template>
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* MyTh Ahmed Faiz Copyright © 2016-2024 All rights reserved.
|
|
3
|
+
* Email: mythpe@gmail.com
|
|
4
|
+
* Mobile: +966590470092
|
|
5
|
+
* Website: https://www.4myth.com
|
|
6
|
+
* Github: https://github.com/mythpe
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import MFadeTransition from './MFadeTransition.vue'
|
|
10
|
+
import MFadeXTransition from './MFadeXTransition.vue'
|
|
11
|
+
import MTransition from './MTransition.vue'
|
|
12
|
+
|
|
13
|
+
export { MFadeTransition, MFadeXTransition, MTransition }
|
package/src/composable/index.ts
CHANGED
|
@@ -1,51 +1,69 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
* Email: mythpe@gmail.com
|
|
4
|
-
* Mobile: +966590470092
|
|
5
|
-
* Website: https://www.4myth.com
|
|
6
|
-
* Github: https://github.com/mythpe
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import { camelCase, kebabCase, snakeCase, uniq } from 'lodash'
|
|
10
|
-
import { computed, type MaybeRefOrGetter, toValue } from 'vue'
|
|
11
|
-
import { extend, useSplitAttrs } from 'quasar'
|
|
1
|
+
import type { PropsContext as UiOpt } from '../types'
|
|
2
|
+
import { computed, MaybeRefOrGetter, ref, toValue } from 'vue'
|
|
12
3
|
import { useI18n } from 'vue-i18n'
|
|
13
|
-
import { useFieldError, useFieldValue, useSetFieldError, useSetFieldValue } from 'vee-validate'
|
|
14
|
-
import { myth } from '../utils'
|
|
15
4
|
import { useMyth } from './useMyth'
|
|
16
|
-
import
|
|
5
|
+
import { useSplitAttrs } from 'quasar'
|
|
6
|
+
import { myth } from '../utils'
|
|
7
|
+
import { camelCase, kebabCase, snakeCase, uniq } from 'lodash'
|
|
17
8
|
|
|
18
|
-
type G = { name: string;
|
|
9
|
+
type G = { name: string; [k: string]: any };
|
|
19
10
|
type OptsContext = { choose?: boolean; };
|
|
20
|
-
export const
|
|
11
|
+
export const useBindInput = <P extends G = G> (Props: MaybeRefOrGetter<P>, key: keyof UiOpt, Opts: MaybeRefOrGetter<OptsContext> = {}) => {
|
|
21
12
|
const { messages, locale } = useI18n({ useScope: 'global' })
|
|
22
13
|
const { __ } = useMyth()
|
|
23
|
-
const { attributes
|
|
14
|
+
const { attributes } = useSplitAttrs()
|
|
24
15
|
const props = toValue<P>(Props)
|
|
25
16
|
const opts = toValue<OptsContext>(Opts)
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
17
|
+
const getProp = computed(() => (k: string) => {
|
|
18
|
+
if (props[k] !== undefined) {
|
|
19
|
+
return props[k]
|
|
20
|
+
}
|
|
21
|
+
return pluginProps.value[key]?.[k]
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
const { themeBtn, themeInput, props: pluginProps } = myth
|
|
25
|
+
const theme = computed(() => (key === 'btn' ? themeBtn.value : themeInput.value) ?? {})
|
|
26
|
+
const mergedTheme = ref({})
|
|
27
|
+
for (const k in theme.value) {
|
|
28
|
+
mergedTheme.value[k] = props[k] !== undefined ? theme.value[k] : props[k]
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Top Label Style.
|
|
32
|
+
*/
|
|
33
|
+
const hasTopLabel = computed(() => {
|
|
34
|
+
if (props.topLabel !== undefined) {
|
|
35
|
+
return props.topLabel !== !1
|
|
36
|
+
}
|
|
37
|
+
if ('topLabel' in theme.value && theme.value.topLabel !== undefined) {
|
|
38
|
+
return theme.value.topLabel !== !1
|
|
39
|
+
}
|
|
40
|
+
if (pluginProps.value[key] && 'topLabel' in pluginProps.value[key]) {
|
|
41
|
+
return pluginProps.value[key]?.topLabel !== !1
|
|
42
|
+
}
|
|
43
|
+
return !1
|
|
44
|
+
})
|
|
31
45
|
|
|
32
46
|
const getLabel = computed<string | undefined>(() => {
|
|
33
47
|
const k = props.label === undefined ? props.name : props.label
|
|
34
48
|
return k ? (__(k) || undefined) : undefined
|
|
35
49
|
})
|
|
36
50
|
const getPlaceholder = computed<string | undefined>(() => {
|
|
51
|
+
const replace = computed(() => {
|
|
52
|
+
const val = props.useChoice !== undefined ? props.useChoice : (attributes.value.useChoice !== undefined ? attributes.value.useChoice : opts?.choose)
|
|
53
|
+
if (typeof val === 'string' && val?.length > 0) {
|
|
54
|
+
return val
|
|
55
|
+
}
|
|
56
|
+
return 'enter'
|
|
57
|
+
})
|
|
37
58
|
if (props.placeholder === undefined) {
|
|
38
59
|
const k = props.label !== undefined ? props.label : props.name
|
|
39
|
-
return __(`replace.${
|
|
60
|
+
return __(`replace.${replace.value}`, { name: __(k) })
|
|
40
61
|
}
|
|
41
62
|
return __(props.placeholder) || undefined
|
|
42
|
-
// if (inputProps.value.hidePlaceholder === !0) {
|
|
43
|
-
// return props.placeholder !== undefined ? (__(props.placeholder) || undefined) : undefined
|
|
44
|
-
// }
|
|
45
63
|
})
|
|
46
64
|
const getAutocompleteAttribute = computed<string | null | undefined>(() => {
|
|
47
|
-
const
|
|
48
|
-
const autocomplete = 'autocomplete' in opt && opt?.autocomplete !== undefined ? opt?.autocomplete : props.autocomplete
|
|
65
|
+
const autocomplete = props.autocomplete !== undefined ? props.autocomplete : (pluginProps.value[key] && 'autocomplete' in pluginProps.value[key] ? pluginProps.value[key]?.autocomplete : undefined)
|
|
66
|
+
// const autocomplete = 'autocomplete' in opt && opt?.autocomplete !== undefined ? opt?.autocomplete : props.autocomplete
|
|
49
67
|
if (autocomplete !== undefined) {
|
|
50
68
|
if (autocomplete === !0 || autocomplete === '') {
|
|
51
69
|
return kebabCase(props.name)
|
|
@@ -58,24 +76,51 @@ export const useInputHelper = <P extends G = G> (Props: MaybeRefOrGetter<P>, key
|
|
|
58
76
|
return undefined
|
|
59
77
|
})
|
|
60
78
|
const accepts = computed(() => {
|
|
61
|
-
const l:
|
|
79
|
+
const l: string[] = []
|
|
62
80
|
if (props.accept) {
|
|
63
|
-
|
|
81
|
+
if (typeof props.accept === 'string') {
|
|
82
|
+
l.push(props.accept)
|
|
83
|
+
} else if (Array.isArray(props.accept)) {
|
|
84
|
+
l.push(...props.accept)
|
|
85
|
+
} else if (typeof props.accept === 'object') {
|
|
86
|
+
const v = toValue(props.accept)
|
|
87
|
+
l.push(...Object.values<string>(v))
|
|
88
|
+
}
|
|
64
89
|
}
|
|
65
90
|
if (props.images) {
|
|
66
|
-
|
|
91
|
+
if (typeof props.images === 'string' && props.images?.length > 0) {
|
|
92
|
+
l.push(props.images)
|
|
93
|
+
} else {
|
|
94
|
+
l.push('image/png,image/jpg,image/jpeg')
|
|
95
|
+
}
|
|
67
96
|
}
|
|
68
97
|
if (props.svg) {
|
|
69
|
-
|
|
98
|
+
if (typeof props.svg === 'string' && props.svg?.length > 0) {
|
|
99
|
+
l.push(props.svg)
|
|
100
|
+
} else {
|
|
101
|
+
l.push('image/svg+xml')
|
|
102
|
+
}
|
|
70
103
|
}
|
|
71
104
|
if (props.video) {
|
|
72
|
-
|
|
105
|
+
if (typeof props.video === 'string' && props.video?.length > 0) {
|
|
106
|
+
l.push(props.video)
|
|
107
|
+
} else {
|
|
108
|
+
l.push('video/mp4')
|
|
109
|
+
}
|
|
73
110
|
}
|
|
74
111
|
if (props.pdf) {
|
|
75
|
-
|
|
112
|
+
if (typeof props.pdf === 'string' && props.pdf?.length > 0) {
|
|
113
|
+
l.push(props.pdf)
|
|
114
|
+
} else {
|
|
115
|
+
l.push('application/pdf')
|
|
116
|
+
}
|
|
76
117
|
}
|
|
77
118
|
if (props.excel) {
|
|
78
|
-
|
|
119
|
+
if (typeof props.excel === 'string' && props.excel?.length > 0) {
|
|
120
|
+
l.push(props.excel)
|
|
121
|
+
} else {
|
|
122
|
+
l.push('application/vnd.ms-excel')
|
|
123
|
+
}
|
|
79
124
|
}
|
|
80
125
|
return l
|
|
81
126
|
})
|
|
@@ -115,13 +160,12 @@ export const useInputHelper = <P extends G = G> (Props: MaybeRefOrGetter<P>, key
|
|
|
115
160
|
}
|
|
116
161
|
const publicRules = ['required', 'email', 'numeric', 'integer', 'float', 'color']
|
|
117
162
|
const validations = (messages.value as any)?.[locale.value]?.validation?.messages || {}
|
|
118
|
-
const
|
|
163
|
+
const inputRules = computed<Record<string, any>>(() => {
|
|
119
164
|
if (props.viewMode) {
|
|
120
165
|
return {}
|
|
121
166
|
}
|
|
122
167
|
const rules: any = { ...convertRules(toValue(props.rules)) }
|
|
123
|
-
|
|
124
|
-
const keys = uniq<string>([...publicRules, ...(myth.options.value.inputRules ?? []), ...Object.keys(validations)])
|
|
168
|
+
const keys = uniq<string>([...publicRules, ...(myth.rules.value ?? []), ...Object.keys(validations)])
|
|
125
169
|
for (const k of keys) {
|
|
126
170
|
if (['mobile', '_default', 'default'].includes(k)) {
|
|
127
171
|
continue
|
|
@@ -130,7 +174,7 @@ export const useInputHelper = <P extends G = G> (Props: MaybeRefOrGetter<P>, key
|
|
|
130
174
|
|
|
131
175
|
// eslint-disable-next-line no-labels
|
|
132
176
|
mainFor: for (const c of cases) {
|
|
133
|
-
for (const b of [
|
|
177
|
+
for (const b of [attributes.value, props]) {
|
|
134
178
|
if (c in b && (b[c] === !0 || b[c] === '')) {
|
|
135
179
|
rules[snakeCase(k)] = b[c] === !0 || b[c] === '' ? !0 : b[c]
|
|
136
180
|
// eslint-disable-next-line no-labels
|
|
@@ -140,40 +184,26 @@ export const useInputHelper = <P extends G = G> (Props: MaybeRefOrGetter<P>, key
|
|
|
140
184
|
}
|
|
141
185
|
}
|
|
142
186
|
|
|
143
|
-
const mobile =
|
|
187
|
+
const mobile = attributes.value?.mobile !== undefined ? attributes.value.mobile : props.mobile
|
|
144
188
|
if (mobile !== undefined && mobile !== false) {
|
|
145
189
|
const defLen = 10
|
|
146
190
|
rules.digits = typeof mobile === 'boolean' ? defLen : (mobile || defLen)
|
|
147
191
|
}
|
|
148
192
|
return Object.values(rules).filter(e => !!e).length > 0 ? rules : undefined
|
|
149
193
|
})
|
|
150
|
-
|
|
194
|
+
const attrs = computed(() => ({
|
|
195
|
+
...props,
|
|
196
|
+
...attributes.value,
|
|
197
|
+
...mergedTheme.value
|
|
198
|
+
}))
|
|
151
199
|
return {
|
|
152
|
-
|
|
200
|
+
inputRules,
|
|
153
201
|
accepts,
|
|
154
202
|
hasTopLabel,
|
|
155
203
|
getLabel,
|
|
156
204
|
getPlaceholder,
|
|
157
205
|
getAutocompleteAttribute,
|
|
158
|
-
|
|
159
|
-
|
|
206
|
+
getProp,
|
|
207
|
+
attrs
|
|
160
208
|
}
|
|
161
209
|
}
|
|
162
|
-
|
|
163
|
-
export const useValue = <T = any> (name: MaybeRefOrGetter<string>) => {
|
|
164
|
-
const [value, setValue] = [useFieldValue<T>(name), useSetFieldValue<T>(name)]
|
|
165
|
-
const field = computed<T>({
|
|
166
|
-
get: () => value.value,
|
|
167
|
-
set: (v: T) => setValue(v)
|
|
168
|
-
})
|
|
169
|
-
|
|
170
|
-
return { field, value, setValue }
|
|
171
|
-
}
|
|
172
|
-
export const useError = (name: MaybeRefOrGetter<string>) => {
|
|
173
|
-
const [error, setErrors] = [useFieldError(name), useSetFieldError(name)]
|
|
174
|
-
const errors = computed<string | string[] | undefined>({
|
|
175
|
-
get: () => error.value,
|
|
176
|
-
set: (v: string | string[] | undefined) => setErrors(v)
|
|
177
|
-
})
|
|
178
|
-
return { errors, error, setErrors }
|
|
179
|
-
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { computed, MaybeRefOrGetter } from 'vue'
|
|
2
|
+
import { useFieldError, useSetFieldError } from 'vee-validate'
|
|
3
|
+
|
|
4
|
+
export const useError = (name: MaybeRefOrGetter<string>) => {
|
|
5
|
+
const [error, setErrors] = [useFieldError(name), useSetFieldError(name)]
|
|
6
|
+
const errors = computed<string | string[] | undefined>({
|
|
7
|
+
get: () => error.value,
|
|
8
|
+
set: (v: string | string[] | undefined) => setErrors(v)
|
|
9
|
+
})
|
|
10
|
+
return { errors, error, setErrors }
|
|
11
|
+
}
|
|
@@ -6,12 +6,289 @@
|
|
|
6
6
|
* Github: https://github.com/mythpe
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
+
import lodash from 'lodash'
|
|
9
10
|
import { useI18n } from 'vue-i18n'
|
|
11
|
+
import type { RouteLocationNormalizedLoaded } from 'vue-router'
|
|
12
|
+
import { copyToClipboard, Dialog, extend, QDialogOptions, QNotifyCreateOptions, useQuasar } from 'quasar'
|
|
13
|
+
import { Helpers, myth, Str } from '../utils'
|
|
14
|
+
import type { MDtColumn, MDtHeadersParameter, ParseHeaderOptions, Vue3MAlertMessage, Vue3MAlertMessageOptions, Vue3MConfirmMessage } from '../types'
|
|
10
15
|
|
|
11
16
|
export const useMyth = () => {
|
|
12
17
|
const { t, te } = useI18n({ useScope: 'global' })
|
|
13
|
-
|
|
14
|
-
const
|
|
18
|
+
const { props: pluginOptions } = myth
|
|
19
|
+
const q = useQuasar()
|
|
20
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
21
|
+
// @ts-ignore
|
|
22
|
+
const __ = (key: any, ...rest: unknown[]) => !key ? '' : te(`attributes.${key}`) ? t(`attributes.${key}`, ...rest) : te(key) ? t(key, ...rest) : key
|
|
15
23
|
|
|
16
|
-
|
|
24
|
+
function quasarNotifyOptions (opts: QNotifyCreateOptions | string): QNotifyCreateOptions {
|
|
25
|
+
return {
|
|
26
|
+
badgeColor: 'primary',
|
|
27
|
+
progress: !0,
|
|
28
|
+
...pluginOptions.value.notify as any,
|
|
29
|
+
message: typeof opts === 'string' ? opts : opts.message,
|
|
30
|
+
...(typeof opts !== 'string' ? opts : {})
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function alertMessage (opts: Vue3MAlertMessageOptions): Vue3MAlertMessage {
|
|
35
|
+
return q.notify(helpers.quasarNotifyOptions(opts))
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const helpers = {
|
|
39
|
+
getPageTitle (route: RouteLocationNormalizedLoaded, number?: number | string): string {
|
|
40
|
+
number = number || 2
|
|
41
|
+
number = parseInt(number.toString())
|
|
42
|
+
const defaultValue = ''
|
|
43
|
+
// Not is route
|
|
44
|
+
// No page title
|
|
45
|
+
if (!route) {
|
|
46
|
+
return defaultValue
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const routePath = route?.path?.toString() || null
|
|
50
|
+
const routeName = route?.name?.toString() || null
|
|
51
|
+
|
|
52
|
+
// Not is route
|
|
53
|
+
// No page title
|
|
54
|
+
if (!routePath || !routeName) {
|
|
55
|
+
return defaultValue
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
let lastRouteName = routeName.split('.').pop() || ''
|
|
59
|
+
if (lastRouteName === 'index') {
|
|
60
|
+
const s = routeName.split('.')
|
|
61
|
+
lastRouteName = s[s.length - 2] ?? lastRouteName
|
|
62
|
+
}
|
|
63
|
+
const pluralize = Str.pascalCase(lodash.pluralize(lastRouteName))
|
|
64
|
+
const singular = Str.pascalCase(lodash.singularize(lastRouteName))
|
|
65
|
+
const keys = lodash.filter(lodash.uniq([
|
|
66
|
+
`${lastRouteName}Page.title`,
|
|
67
|
+
`${lodash.camelCase(lastRouteName)}Page.title`,
|
|
68
|
+
`choice.${pluralize}`,
|
|
69
|
+
`choice.${singular}`,
|
|
70
|
+
`replace.${lastRouteName}_details`,
|
|
71
|
+
`replace.${lastRouteName}`,
|
|
72
|
+
pluralize,
|
|
73
|
+
lodash.snakeCase(pluralize),
|
|
74
|
+
singular,
|
|
75
|
+
lodash.snakeCase(singular)
|
|
76
|
+
]))
|
|
77
|
+
|
|
78
|
+
let str: string | null = null
|
|
79
|
+
let k: string | any
|
|
80
|
+
|
|
81
|
+
if (te((k = `routes.${routeName}`)) && lodash.isString((str = t(k)))) {
|
|
82
|
+
return str
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (te((k = `routes.${routePath}`)) && lodash.isString((str = t(k)))) {
|
|
86
|
+
return str
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
for (const f in keys) {
|
|
90
|
+
if (!(k = keys[f])) {
|
|
91
|
+
continue
|
|
92
|
+
}
|
|
93
|
+
if (te && te(k) && lodash.isString(t(k))) {
|
|
94
|
+
if (lodash.startsWith(k, 'choice.')) {
|
|
95
|
+
const s = k.split('.')
|
|
96
|
+
const n = routeName.split('.')
|
|
97
|
+
if (s.length === 2 && n.length > 1) {
|
|
98
|
+
const model = n[n.length - 2]
|
|
99
|
+
const pluralizeModel = lodash.pluralize(lodash.pascalCase(model))
|
|
100
|
+
const _modelChoiceKey = `choice.${pluralizeModel}`
|
|
101
|
+
if (te(_modelChoiceKey)) {
|
|
102
|
+
const l = t(_modelChoiceKey, number as any)
|
|
103
|
+
const rep = lodash.singularize(n[n.length - 1]).toLocaleLowerCase()
|
|
104
|
+
const e = `replace.${rep}`
|
|
105
|
+
str = te(e) ? t(e, { name: l }) : null
|
|
106
|
+
} else {
|
|
107
|
+
const pop: string = k.split('.').pop() || ''
|
|
108
|
+
str = te(k) ? t(k, number as any, { [pop]: number }) : null
|
|
109
|
+
}
|
|
110
|
+
} else {
|
|
111
|
+
const pop: string = k.split('.').pop() || ''
|
|
112
|
+
str = te(k) ? t(k, number as any, { [pop]: number }) : null
|
|
113
|
+
}
|
|
114
|
+
} else {
|
|
115
|
+
const parents: string[] = routeName.split('.')
|
|
116
|
+
if (parents.length > 1) {
|
|
117
|
+
const e = `choice.${Str.pascalCase(lodash.pluralize(parents[parents.length - 2]))}`
|
|
118
|
+
str = te(e) ? t(k, { name: t(e, '1') }) : null
|
|
119
|
+
} else {
|
|
120
|
+
str = te(k) ? t(k, { name: '' }) : null
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return str || defaultValue
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return defaultValue
|
|
127
|
+
},
|
|
128
|
+
/**
|
|
129
|
+
* Custom transformer
|
|
130
|
+
* @param headers
|
|
131
|
+
* @param options
|
|
132
|
+
*/
|
|
133
|
+
parseHeaders (headers: MDtHeadersParameter, options: ParseHeaderOptions = {}): MDtColumn[] {
|
|
134
|
+
const defaultOptions: Partial<ParseHeaderOptions> = {
|
|
135
|
+
controlKey: 'control',
|
|
136
|
+
// controlStyle: 'max-width: 150px',
|
|
137
|
+
align: 'center'
|
|
138
|
+
// sortable: !0
|
|
139
|
+
}
|
|
140
|
+
const opts = extend<ParseHeaderOptions>(!0, defaultOptions, options)
|
|
141
|
+
let control: string | undefined = defaultOptions.controlKey
|
|
142
|
+
let controlStyle: string | undefined = defaultOptions.controlStyle
|
|
143
|
+
if (opts.controlKey) {
|
|
144
|
+
control = opts.controlKey
|
|
145
|
+
delete opts.controlKey
|
|
146
|
+
}
|
|
147
|
+
if (opts.controlStyle) {
|
|
148
|
+
controlStyle = opts.controlStyle
|
|
149
|
+
delete opts.controlStyle
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
const result: MDtColumn[] = []
|
|
153
|
+
|
|
154
|
+
headers.forEach((elm: string | MDtColumn | undefined) => {
|
|
155
|
+
if (typeof elm !== 'string' && !elm?.name) return elm
|
|
156
|
+
// Todo: will do this
|
|
157
|
+
let item: MDtColumn = typeof elm === 'string' ? {
|
|
158
|
+
name: elm as string,
|
|
159
|
+
label: elm as string,
|
|
160
|
+
field: elm as string
|
|
161
|
+
} : { ...elm }
|
|
162
|
+
item.name = item.name ?? ''
|
|
163
|
+
item.label = (item.label === undefined || item.label === null) ? item.name : item.label
|
|
164
|
+
item.field = (item.field === undefined || item.field === null) ? item.name : item.field
|
|
165
|
+
item = {
|
|
166
|
+
...item,
|
|
167
|
+
name: Str.strBefore(Str.strBefore(item.name), 'ToString'),
|
|
168
|
+
label: (item.label !== undefined && item.label !== null) ? Str.strBefore(Str.strBefore(item.label), 'ToString') : item.label
|
|
169
|
+
}
|
|
170
|
+
const name = item.name
|
|
171
|
+
let k
|
|
172
|
+
if (te) {
|
|
173
|
+
if (te((k = `attributes.${item.label}`))) {
|
|
174
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
175
|
+
// @ts-ignore
|
|
176
|
+
item.label = t(k)
|
|
177
|
+
} else if (te((k = `attributes.${lodash.snakeCase(item.label)}`))) {
|
|
178
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
179
|
+
// @ts-ignore
|
|
180
|
+
item.label = t(k)
|
|
181
|
+
} else if (te((k = `attributes.${lodash.camelCase(item.label)}`))) {
|
|
182
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
183
|
+
// @ts-ignore
|
|
184
|
+
item.label = t(k)
|
|
185
|
+
} else if (te((k = `attributes.${Str.pascalCase(item.label)}`))) {
|
|
186
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
187
|
+
// @ts-ignore
|
|
188
|
+
item.label = t(k)
|
|
189
|
+
} else if (te((k = `choice.${lodash.pluralize(Str.pascalCase(item.label))}`))) {
|
|
190
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
191
|
+
// @ts-ignore
|
|
192
|
+
item.label = t(k, 2)
|
|
193
|
+
} else if (te((k = item.label))) {
|
|
194
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
195
|
+
// @ts-ignore
|
|
196
|
+
item.label = t(k)
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
if (name === control) {
|
|
201
|
+
if (controlStyle && !item.style) {
|
|
202
|
+
item.style = controlStyle + (item.style ? ` ${item.style}` : '')
|
|
203
|
+
}
|
|
204
|
+
item.headerClasses = (item.headerClasses ? item.headerClasses : '') + ' m--control-header'
|
|
205
|
+
item.headerClasses = item.headerClasses.trim()
|
|
206
|
+
item.sortable = !1
|
|
207
|
+
if (!item.align) {
|
|
208
|
+
item.align = 'right'
|
|
209
|
+
}
|
|
210
|
+
opts.classes = opts.classes || ''
|
|
211
|
+
if (typeof opts.classes === 'function') {
|
|
212
|
+
opts.classes = opts.classes()
|
|
213
|
+
}
|
|
214
|
+
opts.classes += ' m--control-cell'
|
|
215
|
+
opts.classes = opts.classes.trim()
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
item = { ...opts, ...item }
|
|
219
|
+
|
|
220
|
+
if (item.sortable === undefined && (options.noSort ?? []).length > 0 && options.noSort?.includes(item.name)) {
|
|
221
|
+
item.sortable = !1
|
|
222
|
+
} else if (item.sortable === undefined) {
|
|
223
|
+
item.sortable = !0
|
|
224
|
+
}
|
|
225
|
+
result.push(item)
|
|
226
|
+
})
|
|
227
|
+
return lodash.uniqBy(result, (e: MDtColumn) => e.name)
|
|
228
|
+
},
|
|
229
|
+
/**
|
|
230
|
+
* Copy text
|
|
231
|
+
* @param text
|
|
232
|
+
*/
|
|
233
|
+
copyText: async (text: string | any) => copyToClipboard(text),
|
|
234
|
+
quasarNotifyOptions,
|
|
235
|
+
alertMessage,
|
|
236
|
+
alertSuccess (message: string) {
|
|
237
|
+
return alertMessage({ type: 'positive', message })
|
|
238
|
+
},
|
|
239
|
+
alertError (message: string) {
|
|
240
|
+
return alertMessage({ type: 'negative', message })
|
|
241
|
+
},
|
|
242
|
+
confirmMessage (message?: string, title?: string, opts?: QDialogOptions): Vue3MConfirmMessage {
|
|
243
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
244
|
+
// @ts-ignore
|
|
245
|
+
title = title || t('messages.are_you_sure') || ''
|
|
246
|
+
message = message || ''
|
|
247
|
+
opts = opts || {}
|
|
248
|
+
const buttonsProps = {
|
|
249
|
+
...(pluginOptions.value.btn || {})
|
|
250
|
+
// ...(options.value.confirmDialogOptions?.buttons || {})
|
|
251
|
+
}
|
|
252
|
+
// const okProps = options.value.confirmDialogOptions?.okProps || {}
|
|
253
|
+
const okProps: any = {}
|
|
254
|
+
// const cancelProps = options.value.confirmDialogOptions?.cancelProps || {}
|
|
255
|
+
const cancelProps: any = {}
|
|
256
|
+
// const dialogProps = options.value.confirmDialog || {} as any
|
|
257
|
+
const dialogProps: any = {}
|
|
258
|
+
dialogProps.transitionShow = dialogProps.transitionShow || 'jump-down'
|
|
259
|
+
dialogProps.transitionHide = dialogProps.transitionHide || 'jump-up'
|
|
260
|
+
dialogProps.class = ('m--confirm ') + (dialogProps.class || '')
|
|
261
|
+
return Dialog.create({
|
|
262
|
+
title,
|
|
263
|
+
message,
|
|
264
|
+
focus: 'none',
|
|
265
|
+
cancel: {
|
|
266
|
+
color: cancelProps.color || 'positive',
|
|
267
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
268
|
+
// @ts-ignore
|
|
269
|
+
label: t(cancelProps?.label || 'no'),
|
|
270
|
+
...buttonsProps as any,
|
|
271
|
+
flat: !0,
|
|
272
|
+
unelevated: !0,
|
|
273
|
+
...cancelProps as any
|
|
274
|
+
},
|
|
275
|
+
ok: {
|
|
276
|
+
color: okProps.color || 'negative',
|
|
277
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
278
|
+
// @ts-ignore
|
|
279
|
+
label: t(okProps?.label || 'yes'),
|
|
280
|
+
...buttonsProps as any,
|
|
281
|
+
flat: !0,
|
|
282
|
+
unelevated: !0,
|
|
283
|
+
...okProps as any
|
|
284
|
+
},
|
|
285
|
+
persistent: !0,
|
|
286
|
+
...dialogProps as any,
|
|
287
|
+
...opts as any
|
|
288
|
+
})
|
|
289
|
+
},
|
|
290
|
+
...Helpers
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
return { __, helpers }
|
|
17
294
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { computed, MaybeRefOrGetter } from 'vue'
|
|
2
|
+
import { useFieldValue, useSetFieldValue } from 'vee-validate'
|
|
3
|
+
|
|
4
|
+
export const useValue = <T = any> (name: MaybeRefOrGetter<string>) => {
|
|
5
|
+
const [value, setValue] = [useFieldValue<T>(name), useSetFieldValue<T>(name)]
|
|
6
|
+
const field = computed<T>({
|
|
7
|
+
get: () => value.value,
|
|
8
|
+
set: (v: T) => setValue(v)
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
return { field, value, setValue }
|
|
12
|
+
}
|