@globalbrain/sefirot 3.50.0 → 4.0.0-0
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/config/nuxt.d.ts +4 -0
- package/config/nuxt.js +31 -0
- package/config/vite.d.ts +8 -0
- package/config/vite.js +69 -0
- package/lib/components/SActionList.vue +0 -1
- package/lib/components/SActionListItem.vue +3 -11
- package/lib/components/SAlert.vue +8 -13
- package/lib/components/SButton.vue +9 -10
- package/lib/components/SCardBlock.vue +0 -6
- package/lib/components/SControlActionBarClose.vue +1 -1
- package/lib/components/SControlActionBarCollapse.vue +2 -2
- package/lib/components/SControlInputSearch.vue +2 -2
- package/lib/components/SDescAvatar.vue +1 -2
- package/lib/components/SDescFile.vue +4 -6
- package/lib/components/SDescPill.vue +1 -2
- package/lib/components/SDescText.vue +1 -1
- package/lib/components/SDropdownSectionDateRange.vue +2 -2
- package/lib/components/SDropdownSectionDateRangeDateFromTo.vue +2 -2
- package/lib/components/SDropdownSectionDateRangeYear.vue +2 -2
- package/lib/components/SDropdownSectionDateRangeYearHalf.vue +2 -2
- package/lib/components/SDropdownSectionDateRangeYearQuarter.vue +2 -2
- package/lib/components/SDropdownSectionFilter.vue +4 -6
- package/lib/components/SIndicator.vue +10 -16
- package/lib/components/SInputAddon.vue +6 -8
- package/lib/components/SInputBase.vue +6 -8
- package/lib/components/SInputCheckbox.vue +7 -11
- package/lib/components/SInputCheckboxes.vue +3 -4
- package/lib/components/SInputDate.vue +3 -4
- package/lib/components/SInputDropdown.vue +10 -13
- package/lib/components/SInputDropdownItemAvatar.vue +2 -3
- package/lib/components/SInputDropdownItemText.vue +2 -3
- package/lib/components/SInputFile.vue +3 -4
- package/lib/components/SInputHMS.vue +4 -5
- package/lib/components/SInputImage.vue +5 -7
- package/lib/components/SInputNumber.vue +10 -11
- package/lib/components/SInputRadio.vue +3 -4
- package/lib/components/SInputRadios.vue +3 -4
- package/lib/components/SInputSegments.vue +3 -4
- package/lib/components/SInputSelect.vue +7 -9
- package/lib/components/SInputSwitch.vue +3 -4
- package/lib/components/SInputSwitches.vue +3 -4
- package/lib/components/SInputText.vue +7 -9
- package/lib/components/SInputTextarea.vue +3 -4
- package/lib/components/SInputYMD.vue +4 -5
- package/lib/components/SLink.vue +1 -1
- package/lib/components/SLocalNavMenu.vue +3 -4
- package/lib/components/SLoginPage.vue +3 -3
- package/lib/components/SLoginPagePasswordDialog.vue +4 -4
- package/lib/components/SPagination.vue +2 -2
- package/lib/components/SPill.vue +1 -5
- package/lib/components/SSnackbar.vue +2 -3
- package/lib/components/SStep.vue +4 -5
- package/lib/components/STable.vue +1 -2
- package/lib/components/STableCell.vue +5 -13
- package/lib/components/STableCellAvatar.vue +10 -27
- package/lib/components/STableCellAvatars.vue +6 -19
- package/lib/components/STableCellDay.vue +4 -11
- package/lib/components/STableCellNumber.vue +8 -9
- package/lib/components/STableCellPill.vue +5 -33
- package/lib/components/STableCellPills.vue +4 -14
- package/lib/components/STableCellState.vue +3 -3
- package/lib/components/STableCellText.vue +22 -50
- package/lib/components/STableColumn.vue +4 -6
- package/lib/components/STableFooter.vue +4 -5
- package/lib/components/STableHeader.vue +2 -19
- package/lib/components/STableHeaderMenu.vue +1 -2
- package/lib/components/STableHeaderMenuItem.vue +2 -3
- package/lib/components/STableItem.vue +1 -1
- package/lib/composables/Data.ts +8 -102
- package/lib/composables/Error.ts +3 -3
- package/lib/composables/Table.ts +17 -22
- package/lib/composables/Utils.ts +2 -2
- package/lib/composables/Validation.ts +76 -14
- package/lib/http/Http.ts +27 -10
- package/lib/mixins/Card.ts +0 -27
- package/lib/mixins/Fundamental.ts +0 -3
- package/lib/support/Day.ts +5 -5
- package/lib/support/Utils.ts +35 -14
- package/lib/validation/validators/maxLength.ts +2 -2
- package/lib/validation/validators/maxValue.ts +2 -2
- package/lib/validation/validators/minLength.ts +2 -2
- package/lib/validation/validators/minValue.ts +2 -2
- package/lib/validation/validators/required.ts +4 -4
- package/package.json +40 -40
- package/lib/components/SCardFooter.vue +0 -22
- package/lib/components/SCardFooterAction.vue +0 -31
- package/lib/components/SCardFooterActions.vue +0 -18
- package/lib/components/SCardHeader.vue +0 -15
- package/lib/components/SCardHeaderAction.vue +0 -28
- package/lib/components/SCardHeaderActionClose.vue +0 -27
- package/lib/components/SCardHeaderActionCollapse.vue +0 -47
- package/lib/components/SCardHeaderActions.vue +0 -13
- package/lib/components/SCardHeaderTitle.vue +0 -29
- package/lib/components/SIcon.vue +0 -13
- package/lib/components/SSheet.vue +0 -87
- package/lib/components/SSheetFooter.vue +0 -16
- package/lib/components/SSheetFooterAction.vue +0 -34
- package/lib/components/SSheetFooterActions.vue +0 -14
- package/lib/components/SSheetForm.vue +0 -15
- package/lib/components/SSheetMedium.vue +0 -72
- package/lib/components/SSheetTitle.vue +0 -13
- package/lib/components/STableHeaderActions.vue +0 -20
- package/lib/composables/D.ts +0 -21
- package/lib/composables/Form.ts +0 -109
- package/lib/composables/V.ts +0 -97
- package/lib/mixins/Sheet.ts +0 -30
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
-
import IconCaretDown from '@iconify-icons/ph/caret-down-bold'
|
|
3
2
|
import { type DropdownSection } from '../composables/Dropdown'
|
|
4
3
|
import { useFlyout } from '../composables/Flyout'
|
|
5
4
|
import SDropdown from './SDropdown.vue'
|
|
6
|
-
import
|
|
5
|
+
import IconCaretDown from '~icons/ph/caret-down-bold'
|
|
7
6
|
|
|
8
7
|
defineProps<{
|
|
9
8
|
label: string
|
|
@@ -19,7 +18,7 @@ const { container, isOpen, toggle } = useFlyout()
|
|
|
19
18
|
<button class="button" :class="[state]" @click="toggle">
|
|
20
19
|
<span class="label">{{ label }}</span>
|
|
21
20
|
<span v-if="state !== 'indicate'" class="caret">
|
|
22
|
-
<
|
|
21
|
+
<IconCaretDown class="caret-svg" />
|
|
23
22
|
</span>
|
|
24
23
|
<span v-else class="indicator">
|
|
25
24
|
<span class="indicator-dot" />
|
package/lib/composables/Data.ts
CHANGED
|
@@ -1,115 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
* @deprecated Use `composables/D` module instead.
|
|
3
|
-
*/
|
|
1
|
+
import { type Ref, ref } from 'vue'
|
|
4
2
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
import { type WatchSource, reactive } from 'vue'
|
|
8
|
-
import { isNullish, isObject } from '../support/Utils'
|
|
9
|
-
|
|
10
|
-
export interface Data<T extends Record<string, any>> {
|
|
11
|
-
state: T
|
|
3
|
+
export interface D<T extends Record<string, any>> {
|
|
4
|
+
data: Ref<T>
|
|
12
5
|
init(): void
|
|
13
6
|
}
|
|
14
7
|
|
|
15
|
-
export
|
|
16
|
-
|
|
17
|
-
export interface Def<T = any> {
|
|
18
|
-
__isDef: true
|
|
19
|
-
value: any
|
|
20
|
-
source: WatchSource<T>
|
|
21
|
-
cb: (value: Exclude<T, undefined>) => void
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export type UseDataInput<
|
|
25
|
-
T extends Record<string, any>
|
|
26
|
-
> = T | ((utils: UseDataInputUtils) => DataWithDef)
|
|
27
|
-
|
|
28
|
-
export interface UseDataInputUtils {
|
|
29
|
-
def<T>(
|
|
30
|
-
value: any,
|
|
31
|
-
source: WatchSource<T>,
|
|
32
|
-
cb: (value: Exclude<T, null | undefined>) => void
|
|
33
|
-
): Def<T>
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export function useData<T extends Record<string, any>>(
|
|
37
|
-
data: UseDataInput<T>
|
|
38
|
-
): Data<T> {
|
|
39
|
-
const { state, defs } = createState(data)
|
|
40
|
-
|
|
41
|
-
const initialState = cloneDeep(state)
|
|
42
|
-
const reactiveState = reactive(state)
|
|
8
|
+
export function useData<T extends Record<string, any>>(data: T): D<T> {
|
|
9
|
+
const initialData = JSON.stringify(data)
|
|
43
10
|
|
|
44
|
-
|
|
11
|
+
const refData = ref(data) as Ref<T>
|
|
45
12
|
|
|
46
13
|
function init(): void {
|
|
47
|
-
|
|
14
|
+
refData.value = JSON.parse(initialData) as T
|
|
48
15
|
}
|
|
49
16
|
|
|
50
17
|
return {
|
|
51
|
-
|
|
18
|
+
data: refData,
|
|
52
19
|
init
|
|
53
20
|
}
|
|
54
21
|
}
|
|
55
|
-
|
|
56
|
-
function createState<T extends Record<string, any>>(
|
|
57
|
-
data: UseDataInput<T>
|
|
58
|
-
): { state: T; defs: [string, Def][] } {
|
|
59
|
-
if (typeof data !== 'function') {
|
|
60
|
-
return { state: data, defs: [] }
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
const dataWithDef = data({ def })
|
|
64
|
-
|
|
65
|
-
const state = {} as T
|
|
66
|
-
const defs = [] as [string, Def][]
|
|
67
|
-
|
|
68
|
-
for (const key in dataWithDef) {
|
|
69
|
-
const maybeDef = dataWithDef[key]
|
|
70
|
-
|
|
71
|
-
if (!isDef(maybeDef)) {
|
|
72
|
-
(state as any)[key] = maybeDef
|
|
73
|
-
continue
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
(state as any)[key] = maybeDef.value
|
|
77
|
-
|
|
78
|
-
defs.push([key, maybeDef])
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
return {
|
|
82
|
-
state,
|
|
83
|
-
defs
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
function handleDefs<T extends Record<string, any>>(
|
|
88
|
-
defs: [string, Def][],
|
|
89
|
-
state: T
|
|
90
|
-
): void {
|
|
91
|
-
defs.forEach(([key, def]) => {
|
|
92
|
-
watchOnce(def.source, (value: any) => {
|
|
93
|
-
if (!isNullish(value)) {
|
|
94
|
-
(state as any)[key] = def.cb(value)
|
|
95
|
-
}
|
|
96
|
-
})
|
|
97
|
-
})
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
function def<T>(
|
|
101
|
-
value: any,
|
|
102
|
-
source: WatchSource<T>,
|
|
103
|
-
cb: (value: Exclude<T, null | undefined>) => void
|
|
104
|
-
): Def {
|
|
105
|
-
return {
|
|
106
|
-
__isDef: true,
|
|
107
|
-
value,
|
|
108
|
-
source,
|
|
109
|
-
cb
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
function isDef(value: any): boolean {
|
|
114
|
-
return isObject(value) ? !!value.__isDef : false
|
|
115
|
-
}
|
package/lib/composables/Error.ts
CHANGED
|
@@ -29,7 +29,7 @@ import {
|
|
|
29
29
|
toValue
|
|
30
30
|
} from 'vue'
|
|
31
31
|
import { useError } from '../stores/Error'
|
|
32
|
-
import {
|
|
32
|
+
import { isError } from '../support/Utils'
|
|
33
33
|
|
|
34
34
|
export interface User {
|
|
35
35
|
id?: string | number
|
|
@@ -47,7 +47,7 @@ function classify(str: string): string {
|
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
function getComponentName(Component: ConcreteComponent): string | undefined {
|
|
50
|
-
return
|
|
50
|
+
return typeof Component === 'function'
|
|
51
51
|
? Component.displayName || Component.name
|
|
52
52
|
: Component.name || Component.__name
|
|
53
53
|
}
|
|
@@ -232,7 +232,7 @@ function getErrorMessage(error: unknown | undefined) {
|
|
|
232
232
|
return error
|
|
233
233
|
}
|
|
234
234
|
|
|
235
|
-
if (error
|
|
235
|
+
if (isError(error)) {
|
|
236
236
|
return error.message
|
|
237
237
|
}
|
|
238
238
|
|
package/lib/composables/Table.ts
CHANGED
|
@@ -18,11 +18,6 @@ export interface Table<
|
|
|
18
18
|
rowSize?: MaybeRef<number | undefined>
|
|
19
19
|
borderless?: MaybeRef<boolean>
|
|
20
20
|
disableSelection?: (record: R) => boolean
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* @deprecated Use `<SControl>` to add equivalent features.
|
|
24
|
-
*/
|
|
25
|
-
actions?: MaybeRef<TableHeaderAction[]>
|
|
26
21
|
menu?: MaybeRef<TableMenu[] | TableMenu[][]>
|
|
27
22
|
header?: MaybeRef<boolean | undefined>
|
|
28
23
|
footer?: MaybeRef<boolean | undefined>
|
|
@@ -61,11 +56,11 @@ export type TableCell<V = any, R = any> =
|
|
|
61
56
|
| TableCellText<V, R>
|
|
62
57
|
| TableCellNumber<V, R>
|
|
63
58
|
| TableCellDay
|
|
64
|
-
| TableCellPill
|
|
65
|
-
| TableCellPills
|
|
59
|
+
| TableCellPill
|
|
60
|
+
| TableCellPills
|
|
66
61
|
| TableCellState
|
|
67
62
|
| TableCellAvatar<V, R>
|
|
68
|
-
| TableCellAvatars
|
|
63
|
+
| TableCellAvatars
|
|
69
64
|
| TableCellCustom
|
|
70
65
|
| TableCellEmpty
|
|
71
66
|
| TableCellComponent
|
|
@@ -102,10 +97,10 @@ export interface TableCellText<V = any, R = any> extends TableCellBase {
|
|
|
102
97
|
type: 'text'
|
|
103
98
|
align?: 'left' | 'center' | 'right'
|
|
104
99
|
icon?: any
|
|
105
|
-
value?: string | null
|
|
106
|
-
link?: string | null
|
|
107
|
-
color?: TableCellValueColor
|
|
108
|
-
iconColor?: TableCellValueColor
|
|
100
|
+
value?: string | null
|
|
101
|
+
link?: string | null
|
|
102
|
+
color?: TableCellValueColor
|
|
103
|
+
iconColor?: TableCellValueColor
|
|
109
104
|
onClick?(value: V, record: R): void
|
|
110
105
|
}
|
|
111
106
|
|
|
@@ -131,17 +126,17 @@ export interface TableCellDay extends TableCellBase {
|
|
|
131
126
|
color?: 'neutral' | 'soft' | 'mute'
|
|
132
127
|
}
|
|
133
128
|
|
|
134
|
-
export interface TableCellPill
|
|
129
|
+
export interface TableCellPill extends TableCellBase {
|
|
135
130
|
type: 'pill'
|
|
136
|
-
value?: string
|
|
137
|
-
color?: TableCellPillColor
|
|
131
|
+
value?: string
|
|
132
|
+
color?: TableCellPillColor
|
|
138
133
|
}
|
|
139
134
|
|
|
140
135
|
export type TableCellPillColor = ColorModes
|
|
141
136
|
|
|
142
|
-
export interface TableCellPills
|
|
137
|
+
export interface TableCellPills extends TableCellBase {
|
|
143
138
|
type: 'pills'
|
|
144
|
-
pills: TableCellPillItem[]
|
|
139
|
+
pills: TableCellPillItem[]
|
|
145
140
|
}
|
|
146
141
|
|
|
147
142
|
export interface TableCellPillItem {
|
|
@@ -151,16 +146,16 @@ export interface TableCellPillItem {
|
|
|
151
146
|
|
|
152
147
|
export interface TableCellAvatar<V = any, R = any> extends TableCellBase {
|
|
153
148
|
type: 'avatar'
|
|
154
|
-
image?: string | null
|
|
155
|
-
name?: string | null
|
|
156
|
-
link?: string | null
|
|
149
|
+
image?: string | null
|
|
150
|
+
name?: string | null
|
|
151
|
+
link?: string | null
|
|
157
152
|
color?: 'neutral' | 'soft' | 'mute'
|
|
158
153
|
onClick?(value: V, record: R): void
|
|
159
154
|
}
|
|
160
155
|
|
|
161
|
-
export interface TableCellAvatars
|
|
156
|
+
export interface TableCellAvatars extends TableCellBase {
|
|
162
157
|
type: 'avatars'
|
|
163
|
-
avatars: TableCellAvatarsOption[]
|
|
158
|
+
avatars: TableCellAvatarsOption[]
|
|
164
159
|
color?: 'neutral' | 'soft' | 'mute'
|
|
165
160
|
avatarCount?: number
|
|
166
161
|
nameCount?: number
|
package/lib/composables/Utils.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type ComputedRef, type MaybeRefOrGetter, computed, getCurrentInstance, onMounted, toValue, useSlots } from 'vue'
|
|
2
|
-
import {
|
|
2
|
+
import { isString } from '../support/Utils'
|
|
3
3
|
|
|
4
4
|
export type WhenCondition<T> = MaybeRefOrGetter<T>
|
|
5
5
|
|
|
@@ -42,7 +42,7 @@ export function useHasSlotContent(name = 'default'): ComputedRef<boolean> {
|
|
|
42
42
|
|
|
43
43
|
return computed(() => {
|
|
44
44
|
return !!slots[name]?.().some((s) => {
|
|
45
|
-
return isArray(s.children) ? true : !!(s.children as string).trim()
|
|
45
|
+
return Array.isArray(s.children) ? true : !!(s.children as string).trim()
|
|
46
46
|
})
|
|
47
47
|
})
|
|
48
48
|
}
|
|
@@ -1,16 +1,23 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @deprecated Use `composables/V` module instead.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
1
|
import {
|
|
6
|
-
type GlobalConfig,
|
|
7
2
|
type Validation,
|
|
8
3
|
type ValidationArgs,
|
|
4
|
+
type GlobalConfig as VuelidateConfig,
|
|
9
5
|
useVuelidate
|
|
10
6
|
} from '@vuelidate/core'
|
|
11
|
-
import { type
|
|
7
|
+
import { type MaybeRefOrGetter, type Ref, computed, toValue } from 'vue'
|
|
8
|
+
import { type Snackbar, useSnackbars } from '../stores/Snackbars'
|
|
9
|
+
import { useTrans } from './Lang'
|
|
12
10
|
|
|
13
|
-
export
|
|
11
|
+
export interface V<
|
|
12
|
+
Data extends { [key in keyof Rules]: any },
|
|
13
|
+
Rules extends ValidationArgs = ValidationArgs
|
|
14
|
+
> {
|
|
15
|
+
validation: Ref<Validation<Rules, Data>>
|
|
16
|
+
validate(): Promise<boolean>
|
|
17
|
+
validateAndNotify(message?: Snackbar): Promise<boolean>
|
|
18
|
+
notify(message?: Snackbar): void
|
|
19
|
+
reset(): void
|
|
20
|
+
}
|
|
14
21
|
|
|
15
22
|
export interface Validatable {
|
|
16
23
|
readonly $dirty: boolean
|
|
@@ -23,13 +30,68 @@ export interface ValidatableError {
|
|
|
23
30
|
readonly $message: string | Ref<string>
|
|
24
31
|
}
|
|
25
32
|
|
|
33
|
+
export interface VNotification {
|
|
34
|
+
notify(message?: Snackbar): void
|
|
35
|
+
}
|
|
36
|
+
|
|
26
37
|
export function useValidation<
|
|
27
|
-
|
|
28
|
-
|
|
38
|
+
Data extends { [key in keyof Rules]: any },
|
|
39
|
+
Rules extends ValidationArgs = ValidationArgs
|
|
29
40
|
>(
|
|
30
|
-
|
|
31
|
-
rules
|
|
32
|
-
config?:
|
|
33
|
-
):
|
|
34
|
-
|
|
41
|
+
data?: MaybeRefOrGetter<Data>,
|
|
42
|
+
rules?: MaybeRefOrGetter<Rules>,
|
|
43
|
+
config?: VuelidateConfig
|
|
44
|
+
): V<Data, Rules> {
|
|
45
|
+
const { notify } = useVNotification()
|
|
46
|
+
|
|
47
|
+
const d = computed(() => toValue(data) ?? {})
|
|
48
|
+
const r = computed(() => toValue(rules) ?? {})
|
|
49
|
+
|
|
50
|
+
const validation = useVuelidate(r, d, config) as any
|
|
51
|
+
|
|
52
|
+
function reset(): void {
|
|
53
|
+
validation.value.$reset()
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function validate(): Promise<boolean> {
|
|
57
|
+
return validation.value.$validate()
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
async function validateAndNotify(message?: Snackbar): Promise<boolean> {
|
|
61
|
+
const valid = await validate()
|
|
62
|
+
|
|
63
|
+
if (!valid) {
|
|
64
|
+
notify(message)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return valid
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return {
|
|
71
|
+
validation,
|
|
72
|
+
validate,
|
|
73
|
+
validateAndNotify,
|
|
74
|
+
notify,
|
|
75
|
+
reset
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export function useVNotification(): VNotification {
|
|
80
|
+
const { t } = useTrans({
|
|
81
|
+
en: { notify: 'Form contains errors. Please correct them and try again.' },
|
|
82
|
+
ja: { notify: 'フォームにエラーがあります。内容を確認し、再度お試しください。' }
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
const snackbars = useSnackbars()
|
|
86
|
+
|
|
87
|
+
function notify(message?: Snackbar): void {
|
|
88
|
+
snackbars.push(message ?? {
|
|
89
|
+
mode: 'danger',
|
|
90
|
+
text: t.notify
|
|
91
|
+
})
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return {
|
|
95
|
+
notify
|
|
96
|
+
}
|
|
35
97
|
}
|
package/lib/http/Http.ts
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
import { parse as parseContentDisposition } from '@tinyhttp/content-disposition'
|
|
2
2
|
import { parse as parseCookie } from '@tinyhttp/cookie'
|
|
3
3
|
import FileSaver from 'file-saver'
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
FetchError,
|
|
6
|
+
type FetchOptions,
|
|
7
|
+
type FetchRequest,
|
|
8
|
+
type FetchResponse,
|
|
9
|
+
ofetch
|
|
10
|
+
} from 'ofetch'
|
|
5
11
|
import { stringify } from 'qs'
|
|
6
12
|
import { type Lang } from '../composables/Lang'
|
|
13
|
+
import { isBlob, isError, isFormData, isRequest, isResponse, isString } from '../support/Utils'
|
|
7
14
|
|
|
8
15
|
export interface HttpClient {
|
|
9
16
|
<T = any>(request: FetchRequest, options?: Omit<FetchOptions, 'method'>): Promise<T>
|
|
@@ -106,11 +113,11 @@ export class Http {
|
|
|
106
113
|
}
|
|
107
114
|
|
|
108
115
|
async post<T = any>(url: string, body?: any, options?: FetchOptions): Promise<T> {
|
|
109
|
-
if (body && !(body
|
|
116
|
+
if (body && !isFormData(body)) {
|
|
110
117
|
let hasFile = false
|
|
111
118
|
|
|
112
119
|
const payload = JSON.stringify(body, (_, value) => {
|
|
113
|
-
if (value
|
|
120
|
+
if (isBlob(value)) {
|
|
114
121
|
hasFile = true
|
|
115
122
|
return undefined
|
|
116
123
|
}
|
|
@@ -177,15 +184,11 @@ export class Http {
|
|
|
177
184
|
return
|
|
178
185
|
}
|
|
179
186
|
|
|
180
|
-
if (
|
|
181
|
-
typeof obj[property] === 'object'
|
|
182
|
-
&& !(obj[property] instanceof Blob)
|
|
183
|
-
&& obj[property] !== null
|
|
184
|
-
) {
|
|
187
|
+
if (typeof obj[property] === 'object' && !isBlob(obj[property]) && obj[property] !== null) {
|
|
185
188
|
this.objectToFormData(obj[property], fd, property, onlyFiles)
|
|
186
189
|
} else {
|
|
187
190
|
const value = obj[property] === null ? '' : obj[property]
|
|
188
|
-
if (onlyFiles && !(value
|
|
191
|
+
if (onlyFiles && !isBlob(value)) {
|
|
189
192
|
return
|
|
190
193
|
}
|
|
191
194
|
fd.append(formKey, value)
|
|
@@ -196,4 +199,18 @@ export class Http {
|
|
|
196
199
|
}
|
|
197
200
|
}
|
|
198
201
|
|
|
199
|
-
export
|
|
202
|
+
export function isFetchError(e: unknown): e is FetchError {
|
|
203
|
+
return (
|
|
204
|
+
e instanceof FetchError
|
|
205
|
+
|| (isError(e)
|
|
206
|
+
&& (isString((e as FetchError).request) || isRequest((e as FetchError).request))
|
|
207
|
+
&& ((e as FetchError).response === undefined || isResponse((e as FetchError).response))
|
|
208
|
+
&& e.message.startsWith(
|
|
209
|
+
`[${((e as FetchError).request as Request | undefined)?.method || (e as FetchError).options?.method || 'GET'}] ${
|
|
210
|
+
JSON.stringify(((e as FetchError).request as Request | undefined)?.url || String((e as FetchError).request) || '/')
|
|
211
|
+
}: `
|
|
212
|
+
))
|
|
213
|
+
)
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
export { FetchError, type FetchOptions, type FetchRequest, type FetchResponse } from 'ofetch'
|
package/lib/mixins/Card.ts
CHANGED
|
@@ -1,42 +1,15 @@
|
|
|
1
1
|
import { type App } from 'vue'
|
|
2
2
|
import SCard from '../components/SCard.vue'
|
|
3
3
|
import SCardBlock from '../components/SCardBlock.vue'
|
|
4
|
-
import SCardFooter from '../components/SCardFooter.vue'
|
|
5
|
-
import SCardFooterAction from '../components/SCardFooterAction.vue'
|
|
6
|
-
import SCardFooterActions from '../components/SCardFooterActions.vue'
|
|
7
|
-
import SCardHeader from '../components/SCardHeader.vue'
|
|
8
|
-
import SCardHeaderAction from '../components/SCardHeaderAction.vue'
|
|
9
|
-
import SCardHeaderActionClose from '../components/SCardHeaderActionClose.vue'
|
|
10
|
-
import SCardHeaderActionCollapse from '../components/SCardHeaderActionCollapse.vue'
|
|
11
|
-
import SCardHeaderActions from '../components/SCardHeaderActions.vue'
|
|
12
|
-
import SCardHeaderTitle from '../components/SCardHeaderTitle.vue'
|
|
13
4
|
|
|
14
5
|
export function mixin(app: App): void {
|
|
15
6
|
app.component('SCard', SCard)
|
|
16
7
|
app.component('SCardBlock', SCardBlock)
|
|
17
|
-
app.component('SCardFooter', SCardFooter)
|
|
18
|
-
app.component('SCardFooterAction', SCardFooterAction)
|
|
19
|
-
app.component('SCardFooterActions', SCardFooterActions)
|
|
20
|
-
app.component('SCardHeader', SCardHeader)
|
|
21
|
-
app.component('SCardHeaderAction', SCardHeaderAction)
|
|
22
|
-
app.component('SCardHeaderActionClose', SCardHeaderActionClose)
|
|
23
|
-
app.component('SCardHeaderActionCollapse', SCardHeaderActionCollapse)
|
|
24
|
-
app.component('SCardHeaderActions', SCardHeaderActions)
|
|
25
|
-
app.component('SCardHeaderTitle', SCardHeaderTitle)
|
|
26
8
|
}
|
|
27
9
|
|
|
28
10
|
declare module 'vue' {
|
|
29
11
|
export interface GlobalComponents {
|
|
30
12
|
SCard: typeof SCard
|
|
31
13
|
SCardBlock: typeof SCardBlock
|
|
32
|
-
SCardFooter: typeof SCardFooter
|
|
33
|
-
SCardFooterAction: typeof SCardFooterAction
|
|
34
|
-
SCardFooterActions: typeof SCardFooterActions
|
|
35
|
-
SCardHeader: typeof SCardHeader
|
|
36
|
-
SCardHeaderAction: typeof SCardHeaderAction
|
|
37
|
-
SCardHeaderActionClose: typeof SCardHeaderActionClose
|
|
38
|
-
SCardHeaderActionCollapse: typeof SCardHeaderActionCollapse
|
|
39
|
-
SCardHeaderActions: typeof SCardHeaderActions
|
|
40
|
-
SCardHeaderTitle: typeof SCardHeaderTitle
|
|
41
14
|
}
|
|
42
15
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { type App } from 'vue'
|
|
2
2
|
import SContent from '../components/SContent.vue'
|
|
3
3
|
import SDivider from '../components/SDivider.vue'
|
|
4
|
-
import SIcon from '../components/SIcon.vue'
|
|
5
4
|
import SLink from '../components/SLink.vue'
|
|
6
5
|
import SModal from '../components/SModal.vue'
|
|
7
6
|
import STrans from '../components/STrans.vue'
|
|
@@ -22,7 +21,6 @@ export function mixin(app: App): void {
|
|
|
22
21
|
|
|
23
22
|
app.component('SContent', SContent)
|
|
24
23
|
app.component('SDivider', SDivider)
|
|
25
|
-
app.component('SIcon', SIcon)
|
|
26
24
|
app.component('SLink', SLink)
|
|
27
25
|
app.component('SModal', SModal)
|
|
28
26
|
app.component('STrans', STrans)
|
|
@@ -32,7 +30,6 @@ declare module 'vue' {
|
|
|
32
30
|
export interface GlobalComponents {
|
|
33
31
|
SContent: typeof SContent
|
|
34
32
|
SDivider: typeof SDivider
|
|
35
|
-
SIcon: typeof SIcon
|
|
36
33
|
SLink: typeof SLink
|
|
37
34
|
SModal: typeof SModal
|
|
38
35
|
STrans: typeof STrans
|
package/lib/support/Day.ts
CHANGED
|
@@ -2,7 +2,7 @@ import dayjs, { type ConfigType, type Dayjs } from 'dayjs'
|
|
|
2
2
|
import PluginRelativeTime from 'dayjs/plugin/relativeTime'
|
|
3
3
|
import PluginTimezone from 'dayjs/plugin/timezone'
|
|
4
4
|
import PluginUtc from 'dayjs/plugin/utc'
|
|
5
|
-
import {
|
|
5
|
+
import { isNumber, isObject, isString } from './Utils'
|
|
6
6
|
|
|
7
7
|
dayjs.extend(PluginUtc)
|
|
8
8
|
dayjs.extend(PluginTimezone)
|
|
@@ -67,7 +67,7 @@ export function createYmd(
|
|
|
67
67
|
month: number | null = null,
|
|
68
68
|
date: number | null = null
|
|
69
69
|
): Ymd {
|
|
70
|
-
if (isNumber(yearOrDay) ||
|
|
70
|
+
if (isNumber(yearOrDay) || yearOrDay == null) {
|
|
71
71
|
return {
|
|
72
72
|
year: yearOrDay,
|
|
73
73
|
month,
|
|
@@ -92,7 +92,7 @@ export function createHms(
|
|
|
92
92
|
minute: string | null = null,
|
|
93
93
|
second: string | null = null
|
|
94
94
|
): Hms {
|
|
95
|
-
if (isString(hourOrDay) ||
|
|
95
|
+
if (isString(hourOrDay) || hourOrDay == null) {
|
|
96
96
|
return {
|
|
97
97
|
hour: hourOrDay,
|
|
98
98
|
minute,
|
|
@@ -108,7 +108,7 @@ export function createHms(
|
|
|
108
108
|
}
|
|
109
109
|
|
|
110
110
|
export function isYmd(value: unknown, required: YmdType[] = ['y', 'm', 'd']): value is Ymd {
|
|
111
|
-
if (
|
|
111
|
+
if (value == null || !isObject(value)) {
|
|
112
112
|
return false
|
|
113
113
|
}
|
|
114
114
|
|
|
@@ -121,7 +121,7 @@ export function isYmd(value: unknown, required: YmdType[] = ['y', 'm', 'd']): va
|
|
|
121
121
|
}
|
|
122
122
|
|
|
123
123
|
export function isHms(value: unknown, required: HmsType[] = ['h', 'm', 's']): value is Hms {
|
|
124
|
-
if (
|
|
124
|
+
if (value == null || !isObject(value)) {
|
|
125
125
|
return false
|
|
126
126
|
}
|
|
127
127
|
|
package/lib/support/Utils.ts
CHANGED
|
@@ -1,28 +1,49 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
// eslint-disable-next-line @typescript-eslint/prefer-ts-expect-error
|
|
2
|
+
// @ts-ignore internal
|
|
3
|
+
import baseGetTag from 'lodash-es/_baseGetTag'
|
|
4
|
+
|
|
5
|
+
import _isDate from 'lodash-es/isDate'
|
|
6
|
+
import _isError from 'lodash-es/isError'
|
|
7
|
+
import _isNumber from 'lodash-es/isNumber'
|
|
8
|
+
import _isPlainObject from 'lodash-es/isPlainObject'
|
|
9
|
+
import _isString from 'lodash-es/isString'
|
|
10
|
+
|
|
11
|
+
export function isBlob(value: unknown): value is Blob {
|
|
12
|
+
return value instanceof Blob || baseGetTag(value) === '[object Blob]'
|
|
3
13
|
}
|
|
4
14
|
|
|
5
|
-
export function
|
|
6
|
-
return
|
|
15
|
+
export function isDate(value: unknown): value is Date {
|
|
16
|
+
return _isDate(value)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function isError(value: unknown): value is Error {
|
|
20
|
+
return _isError(value)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function isFile(value: unknown): value is File {
|
|
24
|
+
return value instanceof File || baseGetTag(value) === '[object File]'
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function isFormData(value: unknown): value is FormData {
|
|
28
|
+
return value instanceof FormData || baseGetTag(value) === '[object FormData]'
|
|
7
29
|
}
|
|
8
30
|
|
|
9
31
|
export function isNumber(value: unknown): value is number {
|
|
10
|
-
return
|
|
32
|
+
return _isNumber(value)
|
|
11
33
|
}
|
|
12
34
|
|
|
13
|
-
export function
|
|
14
|
-
return
|
|
35
|
+
export function isObject(value: unknown): value is Record<string, unknown> {
|
|
36
|
+
return _isPlainObject(value)
|
|
15
37
|
}
|
|
16
38
|
|
|
17
|
-
export function
|
|
18
|
-
return
|
|
39
|
+
export function isRequest(value: unknown): value is Request {
|
|
40
|
+
return value instanceof Request || baseGetTag(value) === '[object Request]'
|
|
19
41
|
}
|
|
20
42
|
|
|
21
|
-
export function
|
|
22
|
-
return value instanceof
|
|
43
|
+
export function isResponse(value: unknown): value is Response {
|
|
44
|
+
return value instanceof Response || baseGetTag(value) === '[object Response]'
|
|
23
45
|
}
|
|
24
46
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
return typeof value === 'function'
|
|
47
|
+
export function isString(value: unknown): value is string {
|
|
48
|
+
return _isString(value)
|
|
28
49
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isString } from '../../support/Utils'
|
|
2
2
|
|
|
3
3
|
export function maxLength(value: unknown, length: number): boolean {
|
|
4
|
-
if (!(isString(value) || isArray(value))) {
|
|
4
|
+
if (!(isString(value) || Array.isArray(value))) {
|
|
5
5
|
return false
|
|
6
6
|
}
|
|
7
7
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { isNumber, isString } from '../../support/Utils'
|
|
1
|
+
import { isDate, isNumber, isString } from '../../support/Utils'
|
|
2
2
|
|
|
3
3
|
export function maxValue(value: unknown, max: number) {
|
|
4
|
-
if (isNumber(value) || isString(value) || value
|
|
4
|
+
if (isNumber(value) || isString(value) || isDate(value)) {
|
|
5
5
|
return +value <= max
|
|
6
6
|
}
|
|
7
7
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isString } from '../../support/Utils'
|
|
2
2
|
|
|
3
3
|
export function minLength(value: unknown, length: number): boolean {
|
|
4
|
-
if (!(isString(value) || isArray(value))) {
|
|
4
|
+
if (!(isString(value) || Array.isArray(value))) {
|
|
5
5
|
return false
|
|
6
6
|
}
|
|
7
7
|
|