@globalbrain/sefirot 4.31.0 → 4.32.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/client.d.ts +5 -0
- package/config/nuxt.d.ts +1 -0
- package/config/nuxt.js +1 -1
- package/config/vite.js +3 -2
- package/lib/components/SActionList.vue +2 -2
- package/lib/components/SActionMenu.vue +4 -4
- package/lib/components/SAvatar.vue +1 -1
- package/lib/components/SAvatarStack.vue +12 -12
- package/lib/components/SButton.vue +5 -7
- package/lib/components/SCard.vue +2 -2
- package/lib/components/SChartBar.vue +37 -12
- package/lib/components/SChartPie.vue +13 -7
- package/lib/components/SControlActionBarCollapse.vue +2 -4
- package/lib/components/SControlInputSearch.vue +7 -2
- package/lib/components/SDataListItem.vue +1 -3
- package/lib/components/SDescAvatar.vue +1 -1
- package/lib/components/SDescDay.vue +2 -2
- package/lib/components/SDescFile.vue +2 -4
- package/lib/components/SDescItem.vue +2 -1
- package/lib/components/SDescLabel.vue +1 -1
- package/lib/components/SDescLink.vue +2 -7
- package/lib/components/SDescPill.vue +2 -4
- package/lib/components/SDescText.vue +2 -2
- package/lib/components/SDropdown.vue +1 -1
- package/lib/components/SDropdownSectionFilter.vue +11 -11
- package/lib/components/SFragment.vue +1 -1
- package/lib/components/SInputAddon.vue +13 -11
- package/lib/components/SInputBase.vue +11 -11
- package/lib/components/SInputCheckbox.vue +6 -3
- package/lib/components/SInputCheckboxes.vue +7 -3
- package/lib/components/SInputDate.vue +3 -5
- package/lib/components/SInputDropdown.vue +26 -28
- package/lib/components/SInputDropdownItem.vue +21 -11
- package/lib/components/SInputFile.vue +9 -6
- package/lib/components/SInputFileUpload.vue +9 -11
- package/lib/components/SInputFileUploadItem.vue +8 -4
- package/lib/components/SInputHMS.vue +3 -1
- package/lib/components/SInputImage.vue +4 -2
- package/lib/components/SInputNumber.vue +9 -10
- package/lib/components/SInputRadio.vue +3 -2
- package/lib/components/SInputRadios.vue +6 -5
- package/lib/components/SInputSegments.vue +5 -7
- package/lib/components/SInputSegmentsOption.vue +1 -2
- package/lib/components/SInputSelect.vue +6 -4
- package/lib/components/SInputSwitch.vue +4 -1
- package/lib/components/SInputSwitches.vue +5 -3
- package/lib/components/SInputText.vue +16 -16
- package/lib/components/SInputTextarea.vue +7 -3
- package/lib/components/SInputYMD.vue +3 -1
- package/lib/components/SLink.vue +2 -2
- package/lib/components/SLocalNav.vue +1 -1
- package/lib/components/SLocalNavActions.vue +1 -1
- package/lib/components/SLocalNavMenu.vue +2 -2
- package/lib/components/SLoginPagePasswordDialog.vue +2 -2
- package/lib/components/SM.vue +1 -1
- package/lib/components/SMFade.vue +1 -1
- package/lib/components/SMarkdown.vue +3 -2
- package/lib/components/SModal.vue +2 -2
- package/lib/components/SSnackbar.vue +2 -2
- package/lib/components/SSteps.vue +6 -6
- package/lib/components/STable.vue +70 -27
- package/lib/components/STableCell.vue +14 -17
- package/lib/components/STableCellAvatars.vue +1 -1
- package/lib/components/STableCellDay.vue +12 -5
- package/lib/components/STableCellNumber.vue +2 -3
- package/lib/components/STableCellPath.vue +2 -2
- package/lib/components/STableCellText.vue +2 -3
- package/lib/components/STableColumn.vue +38 -16
- package/lib/components/STableFooter.vue +10 -2
- package/lib/components/STableHeader.vue +0 -1
- package/lib/components/STableHeaderMenu.vue +4 -4
- package/lib/components/STableHeaderMenuItem.vue +1 -1
- package/lib/components/STooltip.vue +3 -3
- package/lib/composables/Dropdown.ts +10 -1
- package/lib/composables/Error.ts +37 -37
- package/lib/composables/Grid.ts +1 -4
- package/lib/composables/Image.ts +2 -3
- package/lib/composables/Lang.ts +1 -1
- package/lib/composables/Markdown.ts +1 -1
- package/lib/composables/Table.ts +0 -2
- package/lib/composables/Theme.ts +1 -1
- package/lib/composables/Utils.ts +11 -4
- package/lib/composables/Validation.ts +1 -4
- package/lib/http/Http.ts +23 -17
- package/lib/styles/variables-deprecated.css +0 -1
- package/lib/styles/variables.css +16 -16
- package/lib/support/Chart.ts +0 -1
- package/lib/support/DateRange.ts +1 -1
- package/lib/support/Day.ts +12 -65
- package/lib/support/File.ts +7 -16
- package/lib/support/Utils.ts +7 -40
- package/lib/validation/Rule.ts +6 -21
- package/lib/validation/rules/decimal.ts +3 -3
- package/lib/validation/rules/email.ts +1 -1
- package/lib/validation/rules/index.ts +1 -1
- package/lib/validation/rules/negativeInteger.ts +1 -1
- package/lib/validation/rules/positiveInteger.ts +1 -1
- package/lib/validation/rules/requiredHms.ts +2 -2
- package/lib/validation/rules/requiredIf.ts +1 -4
- package/lib/validation/rules/requiredYmd.ts +2 -2
- package/lib/validation/rules/slackChannelName.ts +4 -1
- package/lib/validation/rules/zeroOrNegativeInteger.ts +1 -1
- package/lib/validation/rules/zeroOrPositiveInteger.ts +1 -1
- package/lib/validation/validators/after.ts +1 -5
- package/lib/validation/validators/afterOrEqual.ts +1 -5
- package/lib/validation/validators/before.ts +1 -4
- package/lib/validation/validators/beforeOrEqual.ts +1 -5
- package/lib/validation/validators/decimal.ts +7 -9
- package/lib/validation/validators/email.ts +4 -8
- package/lib/validation/validators/fileExtension.ts +7 -15
- package/lib/validation/validators/hms.ts +26 -15
- package/lib/validation/validators/index.ts +0 -2
- package/lib/validation/validators/maxFileSize.ts +3 -13
- package/lib/validation/validators/maxLength.ts +1 -7
- package/lib/validation/validators/maxTotalFileSize.ts +3 -26
- package/lib/validation/validators/maxValue.ts +2 -6
- package/lib/validation/validators/minLength.ts +1 -7
- package/lib/validation/validators/minValue.ts +2 -6
- package/lib/validation/validators/month.ts +1 -7
- package/lib/validation/validators/negativeInteger.ts +1 -7
- package/lib/validation/validators/positiveInteger.ts +1 -7
- package/lib/validation/validators/required.ts +5 -28
- package/lib/validation/validators/requiredHmsIf.ts +11 -13
- package/lib/validation/validators/requiredIf.ts +5 -11
- package/lib/validation/validators/requiredYmdIf.ts +11 -13
- package/lib/validation/validators/slackChannelName.ts +11 -11
- package/lib/validation/validators/url.ts +7 -5
- package/lib/validation/validators/ymd.ts +36 -30
- package/package.json +38 -38
- package/lib/validation/validators/requiredHms.ts +0 -9
- package/lib/validation/validators/requiredYmd.ts +0 -9
package/lib/composables/Utils.ts
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
type ComputedRef,
|
|
3
|
+
type MaybeRefOrGetter,
|
|
4
|
+
computed,
|
|
5
|
+
getCurrentInstance,
|
|
6
|
+
onMounted,
|
|
7
|
+
toValue,
|
|
8
|
+
useSlots
|
|
9
|
+
} from 'vue'
|
|
3
10
|
|
|
4
11
|
export type WhenCondition<T> = MaybeRefOrGetter<T>
|
|
5
12
|
|
|
@@ -22,7 +29,7 @@ export function computedWhen<T, C, D>(
|
|
|
22
29
|
return computed(() => {
|
|
23
30
|
const c = toValue(condition)
|
|
24
31
|
|
|
25
|
-
return c ? fn(c) : whenFalse as D
|
|
32
|
+
return c ? fn(c) : (whenFalse as D)
|
|
26
33
|
})
|
|
27
34
|
}
|
|
28
35
|
|
|
@@ -68,7 +75,7 @@ export function useSlotValue(name = 'default'): ComputedRef<string | null> {
|
|
|
68
75
|
|
|
69
76
|
return computed(() => {
|
|
70
77
|
const c = slots[name]?.()[0]?.children
|
|
71
|
-
const v =
|
|
78
|
+
const v = typeof c === 'string' ? c.trim() : null
|
|
72
79
|
return v !== '' ? v : null
|
|
73
80
|
})
|
|
74
81
|
}
|
|
@@ -85,10 +85,7 @@ export function useVNotification(): VNotification {
|
|
|
85
85
|
const snackbars = useSnackbars()
|
|
86
86
|
|
|
87
87
|
function notify(message?: Snackbar): void {
|
|
88
|
-
snackbars.push(message ?? {
|
|
89
|
-
mode: 'danger',
|
|
90
|
-
text: t.notify
|
|
91
|
-
})
|
|
88
|
+
snackbars.push(message ?? { mode: 'danger', text: t.notify })
|
|
92
89
|
}
|
|
93
90
|
|
|
94
91
|
return {
|
package/lib/http/Http.ts
CHANGED
|
@@ -3,7 +3,6 @@ import { parse as parseCookie } from '@tinyhttp/cookie'
|
|
|
3
3
|
import FileSaver from 'file-saver'
|
|
4
4
|
import { FetchError, type FetchOptions, type FetchResponse } from 'ofetch'
|
|
5
5
|
import { stringify } from 'qs'
|
|
6
|
-
import { isBlob, isError, isFormData, isRequest, isResponse, isString } from '../support/Utils'
|
|
7
6
|
|
|
8
7
|
type Config = ReturnType<typeof import('../stores/HttpConfig').useHttpConfig>
|
|
9
8
|
|
|
@@ -31,9 +30,13 @@ export class Http {
|
|
|
31
30
|
|
|
32
31
|
private async buildRequest(url: string, _options: FetchOptions = {}): Promise<[string, FetchOptions]> {
|
|
33
32
|
const { method, params, query, ...options } = _options
|
|
34
|
-
const xsrfToken = ['POST', 'PUT', 'PATCH', 'DELETE'].includes(method || '')
|
|
33
|
+
const xsrfToken = ['POST', 'PUT', 'PATCH', 'DELETE'].includes(method || '')
|
|
34
|
+
&& (await this.ensureXsrfToken())
|
|
35
35
|
|
|
36
|
-
const queryString = stringify(
|
|
36
|
+
const queryString = stringify(
|
|
37
|
+
{ ...params, ...query },
|
|
38
|
+
{ encodeValuesOnly: true, ...this.config.stringifyOptions }
|
|
39
|
+
)
|
|
37
40
|
|
|
38
41
|
return [
|
|
39
42
|
`${url}${queryString ? `?${queryString}` : ''}`,
|
|
@@ -70,11 +73,11 @@ export class Http {
|
|
|
70
73
|
}
|
|
71
74
|
|
|
72
75
|
async post<T = any>(url: string, body?: any, options?: FetchOptions): Promise<T> {
|
|
73
|
-
if (body && !
|
|
76
|
+
if (body && !(body instanceof FormData)) {
|
|
74
77
|
let hasFile = false
|
|
75
78
|
|
|
76
79
|
const payload = JSON.stringify(body, (_, value) => {
|
|
77
|
-
if (
|
|
80
|
+
if (value instanceof Blob) {
|
|
78
81
|
hasFile = true
|
|
79
82
|
return undefined
|
|
80
83
|
}
|
|
@@ -120,13 +123,18 @@ export class Http {
|
|
|
120
123
|
throw new Error('No blob')
|
|
121
124
|
}
|
|
122
125
|
|
|
123
|
-
const { filename = 'download' }
|
|
124
|
-
|
|
126
|
+
const { filename = 'download' } =
|
|
127
|
+
parseContentDisposition(headers.get('Content-Disposition') || '')?.parameters || {}
|
|
125
128
|
|
|
126
129
|
FileSaver.saveAs(blob, filename as string)
|
|
127
130
|
}
|
|
128
131
|
|
|
129
|
-
private objectToFormData(
|
|
132
|
+
private objectToFormData(
|
|
133
|
+
obj: any,
|
|
134
|
+
form?: FormData,
|
|
135
|
+
namespace?: string,
|
|
136
|
+
onlyFiles = false
|
|
137
|
+
): FormData {
|
|
130
138
|
const fd = form || new FormData()
|
|
131
139
|
let formKey: string
|
|
132
140
|
|
|
@@ -141,11 +149,15 @@ export class Http {
|
|
|
141
149
|
return
|
|
142
150
|
}
|
|
143
151
|
|
|
144
|
-
if (
|
|
152
|
+
if (
|
|
153
|
+
typeof obj[property] === 'object'
|
|
154
|
+
&& !(obj[property] instanceof Blob)
|
|
155
|
+
&& obj[property] !== null
|
|
156
|
+
) {
|
|
145
157
|
this.objectToFormData(obj[property], fd, property, onlyFiles)
|
|
146
158
|
} else {
|
|
147
159
|
const value = obj[property] === null ? '' : obj[property]
|
|
148
|
-
if (onlyFiles && !
|
|
160
|
+
if (onlyFiles && !(value instanceof Blob)) {
|
|
149
161
|
return
|
|
150
162
|
}
|
|
151
163
|
fd.append(formKey, value)
|
|
@@ -157,13 +169,7 @@ export class Http {
|
|
|
157
169
|
}
|
|
158
170
|
|
|
159
171
|
export function isFetchError(e: unknown): e is FetchError {
|
|
160
|
-
return (
|
|
161
|
-
e instanceof FetchError
|
|
162
|
-
|| (isError<FetchError>(e)
|
|
163
|
-
&& (e.response === undefined || isResponse(e.response))
|
|
164
|
-
&& ((isString(e.request) && e.message.startsWith(`[${e.options?.method || 'GET'}] ${JSON.stringify(e.request || '/')}: `))
|
|
165
|
-
|| (isRequest(e.request) && e.message.startsWith(`[${e.request.method}] ${JSON.stringify(e.request.url)}: `))))
|
|
166
|
-
)
|
|
172
|
+
return e instanceof FetchError || (e instanceof Error && e.name === 'FetchError')
|
|
167
173
|
}
|
|
168
174
|
|
|
169
175
|
export { FetchError, type FetchOptions, type FetchRequest, type FetchResponse } from 'ofetch'
|
package/lib/styles/variables.css
CHANGED
|
@@ -154,7 +154,7 @@
|
|
|
154
154
|
* Color: Divider and Gutter
|
|
155
155
|
* -------------------------------------------------------------------------- */
|
|
156
156
|
|
|
157
|
-
|
|
157
|
+
:root {
|
|
158
158
|
--c-divider: #e0e0e1;
|
|
159
159
|
--c-gutter: #e2e2e3;
|
|
160
160
|
}
|
|
@@ -290,7 +290,7 @@
|
|
|
290
290
|
* Color: Border
|
|
291
291
|
* -------------------------------------------------------------------------- */
|
|
292
292
|
|
|
293
|
-
|
|
293
|
+
:root {
|
|
294
294
|
--c-border-mute-1: var(--c-gray-6);
|
|
295
295
|
--c-border-mute-2: var(--c-gray-7);
|
|
296
296
|
--c-border-mute-3: var(--c-gray-8);
|
|
@@ -316,7 +316,7 @@
|
|
|
316
316
|
* Color: Text
|
|
317
317
|
* -------------------------------------------------------------------------- */
|
|
318
318
|
|
|
319
|
-
|
|
319
|
+
:root {
|
|
320
320
|
--c-text-1: var(--c-text-light-1);
|
|
321
321
|
--c-text-2: var(--c-text-light-2);
|
|
322
322
|
--c-text-3: var(--c-text-light-3);
|
|
@@ -367,11 +367,11 @@
|
|
|
367
367
|
* -------------------------------------------------------------------------- */
|
|
368
368
|
|
|
369
369
|
:root {
|
|
370
|
-
--shadow-depth-1: 0 1px 2px rgba(0, 0, 0, .04), 0 1px 2px rgba(0, 0, 0, .06);
|
|
371
|
-
--shadow-depth-2: 0 3px 12px rgba(0, 0, 0, .07), 0 1px 4px rgba(0, 0, 0, .07);
|
|
372
|
-
--shadow-depth-3: 0 12px 32px rgba(0, 0, 0, .1), 0 2px 6px rgba(0, 0, 0, .08);
|
|
373
|
-
--shadow-depth-4: 0 14px 44px rgba(0, 0, 0, .12), 0 3px 9px rgba(0, 0, 0, .12);
|
|
374
|
-
--shadow-depth-5: 0 18px 56px rgba(0, 0, 0, .16), 0 4px 12px rgba(0, 0, 0, .16);
|
|
370
|
+
--shadow-depth-1: 0 1px 2px rgba(0, 0, 0, 0.04), 0 1px 2px rgba(0, 0, 0, 0.06);
|
|
371
|
+
--shadow-depth-2: 0 3px 12px rgba(0, 0, 0, 0.07), 0 1px 4px rgba(0, 0, 0, 0.07);
|
|
372
|
+
--shadow-depth-3: 0 12px 32px rgba(0, 0, 0, 0.1), 0 2px 6px rgba(0, 0, 0, 0.08);
|
|
373
|
+
--shadow-depth-4: 0 14px 44px rgba(0, 0, 0, 0.12), 0 3px 9px rgba(0, 0, 0, 0.12);
|
|
374
|
+
--shadow-depth-5: 0 18px 56px rgba(0, 0, 0, 0.16), 0 4px 12px rgba(0, 0, 0, 0.16);
|
|
375
375
|
}
|
|
376
376
|
|
|
377
377
|
/**
|
|
@@ -389,15 +389,15 @@
|
|
|
389
389
|
* -------------------------------------------------------------------------- */
|
|
390
390
|
|
|
391
391
|
:root {
|
|
392
|
-
--ease-in-quint: cubic-bezier(.755, .05, .855, .06);
|
|
393
|
-
--ease-in-back: cubic-bezier(1,
|
|
392
|
+
--ease-in-quint: cubic-bezier(0.755, 0.05, 0.855, 0.06);
|
|
393
|
+
--ease-in-back: cubic-bezier(1, -0.75, 1, 1);
|
|
394
394
|
|
|
395
|
-
--ease-out-quint: cubic-bezier(.23, 1, .32, 1);
|
|
396
|
-
--ease-out-expo: cubic-bezier(.19, 1, .22, 1);
|
|
397
|
-
--ease-out-back: cubic-bezier(.175, .885, .
|
|
398
|
-
--ease-out-back-quint: cubic-bezier(.175, .885, .
|
|
395
|
+
--ease-out-quint: cubic-bezier(0.23, 1, 0.32, 1);
|
|
396
|
+
--ease-out-expo: cubic-bezier(0.19, 1, 0.22, 1);
|
|
397
|
+
--ease-out-back: cubic-bezier(0.175, 0.885, 0.32, 1.275);
|
|
398
|
+
--ease-out-back-quint: cubic-bezier(0.175, 0.885, 0.28, 1.5);
|
|
399
399
|
|
|
400
|
-
--ease-in-out-quint: cubic-bezier(.86, 0, .07, 1);
|
|
400
|
+
--ease-in-out-quint: cubic-bezier(0.86, 0, 0.07, 1);
|
|
401
401
|
--ease-in-out-expo: cubic-bezier(1, 0, 0, 1);
|
|
402
402
|
}
|
|
403
403
|
|
|
@@ -503,7 +503,7 @@
|
|
|
503
503
|
--button-fill-black-hover-text-color: var(--c-text-dark-1);
|
|
504
504
|
--button-fill-black-hover-bg-color: var(--c-neutral-light-2);
|
|
505
505
|
--button-fill-black-active-border-color: transparent;
|
|
506
|
-
--button-fill-black-active-text-color:var(--c-text-dark-1);
|
|
506
|
+
--button-fill-black-active-text-color: var(--c-text-dark-1);
|
|
507
507
|
--button-fill-black-active-bg-color: var(--c-neutral-light-3);
|
|
508
508
|
--button-fill-black-disabled-border-color: transparent;
|
|
509
509
|
--button-fill-black-disabled-text-color: var(--c-text-dark-2);
|
package/lib/support/Chart.ts
CHANGED
|
@@ -37,7 +37,6 @@ export const chartColors = {
|
|
|
37
37
|
gray: 'light-dark(#8d8d8d, #7b7b7b)'
|
|
38
38
|
} as const
|
|
39
39
|
|
|
40
|
-
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
41
40
|
export type ChartColor = keyof typeof chartColors | (string & {})
|
|
42
41
|
export type KV = { key: string; value: number; color?: ChartColor }
|
|
43
42
|
export type Margins = Partial<{ top: number; right: number; bottom: number; left: number }>
|
package/lib/support/DateRange.ts
CHANGED
|
@@ -93,7 +93,7 @@ export class DateFromTo extends DateRangePresetBase {
|
|
|
93
93
|
const f = this.getFrom()?.format('YYYY-MM-DD')
|
|
94
94
|
const t = this.getTo()?.format('YYYY-MM-DD')
|
|
95
95
|
|
|
96
|
-
return
|
|
96
|
+
return f && t ? `${f} – ${t}` : 'Error'
|
|
97
97
|
}
|
|
98
98
|
|
|
99
99
|
setFrom(from: Day | null): this {
|
package/lib/support/Day.ts
CHANGED
|
@@ -2,7 +2,6 @@ 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 { isNumber, isObject, isString } from './Utils'
|
|
6
5
|
|
|
7
6
|
dayjs.extend(PluginUtc)
|
|
8
7
|
dayjs.extend(PluginTimezone)
|
|
@@ -22,12 +21,6 @@ export interface Ymd {
|
|
|
22
21
|
|
|
23
22
|
export type YmdType = 'y' | 'm' | 'd'
|
|
24
23
|
|
|
25
|
-
export const YmdMap = {
|
|
26
|
-
y: 'year',
|
|
27
|
-
m: 'month',
|
|
28
|
-
d: 'date'
|
|
29
|
-
} as const
|
|
30
|
-
|
|
31
24
|
/**
|
|
32
25
|
* The hour, minute, and second object interface.
|
|
33
26
|
*/
|
|
@@ -39,13 +32,13 @@ export interface Hms {
|
|
|
39
32
|
|
|
40
33
|
export type HmsType = 'h' | 'm' | 's'
|
|
41
34
|
|
|
42
|
-
export const HmsMap = {
|
|
43
|
-
h: 'hour',
|
|
44
|
-
m: 'minute',
|
|
45
|
-
s: 'second'
|
|
46
|
-
} as const
|
|
47
|
-
|
|
48
35
|
export function day(input?: Input): Day {
|
|
36
|
+
// hack for histoire
|
|
37
|
+
if (input && typeof input === 'object' && !(input instanceof Date)) {
|
|
38
|
+
const { $D, $H, $M, $m, $ms, $s, $y } = input as any
|
|
39
|
+
input = new Date($y, $M, $D, $H, $m, $s, $ms)
|
|
40
|
+
}
|
|
41
|
+
|
|
49
42
|
return dayjs(input)
|
|
50
43
|
}
|
|
51
44
|
|
|
@@ -67,19 +60,9 @@ export function createYmd(
|
|
|
67
60
|
month: number | null = null,
|
|
68
61
|
date: number | null = null
|
|
69
62
|
): Ymd {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
month,
|
|
74
|
-
date
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
return {
|
|
79
|
-
year: yearOrDay.year(),
|
|
80
|
-
month: yearOrDay.month() + 1,
|
|
81
|
-
date: yearOrDay.date()
|
|
82
|
-
}
|
|
63
|
+
return isDay(yearOrDay)
|
|
64
|
+
? { year: yearOrDay.year(), month: yearOrDay.month() + 1, date: yearOrDay.date() }
|
|
65
|
+
: { year: yearOrDay, month, date }
|
|
83
66
|
}
|
|
84
67
|
|
|
85
68
|
/**
|
|
@@ -92,45 +75,9 @@ export function createHms(
|
|
|
92
75
|
minute: string | null = null,
|
|
93
76
|
second: string | null = null
|
|
94
77
|
): Hms {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
minute,
|
|
99
|
-
second
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
return {
|
|
104
|
-
hour: hourOrDay.format('HH'),
|
|
105
|
-
minute: hourOrDay.format('mm'),
|
|
106
|
-
second: hourOrDay.format('ss')
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
export function isYmd(value: unknown, required: YmdType[] = ['y', 'm', 'd']): value is Ymd {
|
|
111
|
-
if (value == null || !isObject(value)) {
|
|
112
|
-
return false
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
return required
|
|
116
|
-
.reduce<string[]>((keys, type) => {
|
|
117
|
-
keys.push(YmdMap[type])
|
|
118
|
-
return keys
|
|
119
|
-
}, [])
|
|
120
|
-
.every((key) => value[key] === null || isNumber(value[key]))
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
export function isHms(value: unknown, required: HmsType[] = ['h', 'm', 's']): value is Hms {
|
|
124
|
-
if (value == null || !isObject(value)) {
|
|
125
|
-
return false
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
return required
|
|
129
|
-
.reduce<string[]>((keys, type) => {
|
|
130
|
-
keys.push(HmsMap[type])
|
|
131
|
-
return keys
|
|
132
|
-
}, [])
|
|
133
|
-
.every((key) => value[key] === null || isString(value[key]))
|
|
78
|
+
return isDay(hourOrDay)
|
|
79
|
+
? { hour: hourOrDay.format('HH'), minute: hourOrDay.format('mm'), second: hourOrDay.format('ss') }
|
|
80
|
+
: { hour: hourOrDay, minute, second }
|
|
134
81
|
}
|
|
135
82
|
|
|
136
83
|
export function isDay(value: unknown): value is Day {
|
package/lib/support/File.ts
CHANGED
|
@@ -1,24 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
* Get extension of the given file.
|
|
3
|
-
*/
|
|
4
|
-
export function getExtension(file: File): string {
|
|
5
|
-
const name = file.name
|
|
6
|
-
|
|
7
|
-
return name.slice((name.lastIndexOf('.') - 1 >>> 0) + 2)
|
|
8
|
-
}
|
|
1
|
+
const units = ['B', 'kB', 'MB', 'GB'] as const
|
|
9
2
|
|
|
10
3
|
/**
|
|
11
4
|
* Formats the file size in bytes to a human-readable format. It also accepts
|
|
12
5
|
* array of files and returns the total size.
|
|
13
6
|
*/
|
|
14
7
|
export function formatSize(files: File | File[]): string {
|
|
15
|
-
const units = ['B', 'KB', 'MB', 'GB', 'TB', 'PB']
|
|
16
8
|
files = Array.isArray(files) ? files : [files]
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
return `${size.toFixed(2)}${units[index]}`
|
|
9
|
+
|
|
10
|
+
const size = files.reduce((sum, file) => sum + file.size, 0)
|
|
11
|
+
if (size === 0) { return `0 ${units[0]}` }
|
|
12
|
+
|
|
13
|
+
const i = Math.min(Math.floor(Math.log(size) / Math.log(1000)), units.length - 1)
|
|
14
|
+
return `${(size / 1000 ** i).toFixed(2)} ${units[i]}`
|
|
24
15
|
}
|
package/lib/support/Utils.ts
CHANGED
|
@@ -1,49 +1,16 @@
|
|
|
1
|
-
|
|
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]'
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export function isDate(value: unknown): value is Date {
|
|
16
|
-
return _isDate(value)
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export function isError<T extends Error = Error>(value: unknown): value is T {
|
|
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]'
|
|
29
|
-
}
|
|
30
|
-
|
|
1
|
+
/** @deprecated */
|
|
31
2
|
export function isNumber(value: unknown): value is number {
|
|
32
|
-
return
|
|
3
|
+
return Number.isFinite(value)
|
|
33
4
|
}
|
|
34
5
|
|
|
35
6
|
export function isObject(value: unknown): value is Record<string, unknown> {
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export function isRequest(value: unknown): value is Request {
|
|
40
|
-
return value instanceof Request || baseGetTag(value) === '[object Request]'
|
|
41
|
-
}
|
|
7
|
+
if (value == null || typeof value !== 'object') { return false }
|
|
42
8
|
|
|
43
|
-
|
|
44
|
-
return
|
|
9
|
+
const proto = Object.getPrototypeOf(value)
|
|
10
|
+
return proto === null || proto === Object.prototype
|
|
45
11
|
}
|
|
46
12
|
|
|
13
|
+
/** @deprecated */
|
|
47
14
|
export function isString(value: unknown): value is string {
|
|
48
|
-
return
|
|
15
|
+
return typeof value === 'string'
|
|
49
16
|
}
|
package/lib/validation/Rule.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type ValidationRuleWithParams } from '@vuelidate/core'
|
|
2
2
|
import { type MessageProps as VMessageProps, helpers } from '@vuelidate/validators'
|
|
3
3
|
import { type Lang } from '../composables/Lang'
|
|
4
|
-
import {
|
|
4
|
+
import { required } from './validators'
|
|
5
5
|
|
|
6
6
|
export interface RuleOptions {
|
|
7
7
|
optional?: boolean
|
|
@@ -15,34 +15,19 @@ export interface MessageProps extends VMessageProps {
|
|
|
15
15
|
lang: Lang
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
export function createRule(
|
|
19
|
-
options: RuleOptions
|
|
20
|
-
): ValidationRuleWithParams {
|
|
18
|
+
export function createRule(options: RuleOptions): ValidationRuleWithParams {
|
|
21
19
|
const lang = typeof document !== 'undefined'
|
|
22
20
|
? (document.documentElement.lang === 'ja' ? 'ja' : 'en')
|
|
23
21
|
: 'en'
|
|
24
22
|
|
|
25
23
|
const params = options.params ?? {}
|
|
26
24
|
|
|
27
|
-
const validator = helpers.withParams(
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
return options.optional && !_required(value)
|
|
31
|
-
? true
|
|
32
|
-
: options.validation(value)
|
|
33
|
-
}
|
|
34
|
-
)
|
|
25
|
+
const validator = helpers.withParams(params, (value: unknown) => {
|
|
26
|
+
return options.optional && !required(value, false) ? true : options.validation(value)
|
|
27
|
+
})
|
|
35
28
|
|
|
36
29
|
return helpers.withMessage(
|
|
37
30
|
(params) => options.message({ ...params, lang }),
|
|
38
|
-
options.async
|
|
39
|
-
? helpers.withAsync(validator, createParamsForAsyncValidator(params))
|
|
40
|
-
: validator
|
|
31
|
+
options.async ? helpers.withAsync(validator, Object.values(params)) : validator
|
|
41
32
|
)
|
|
42
33
|
}
|
|
43
|
-
|
|
44
|
-
function createParamsForAsyncValidator(params: Record<string, any>) {
|
|
45
|
-
return Object.keys(params).map((key) => {
|
|
46
|
-
return params[key]
|
|
47
|
-
})
|
|
48
|
-
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { createRule } from '../Rule'
|
|
2
|
-
import { decimal as baseDecimal
|
|
2
|
+
import { decimal as baseDecimal } from '../validators'
|
|
3
3
|
|
|
4
4
|
export const message = {
|
|
5
|
-
en: 'The value must be valid decimal
|
|
5
|
+
en: 'The value must be a valid decimal number.',
|
|
6
6
|
ja: 'この値は小数または10進数である必要があります。'
|
|
7
7
|
}
|
|
8
8
|
|
|
@@ -10,6 +10,6 @@ export function decimal(msg?: string) {
|
|
|
10
10
|
return createRule({
|
|
11
11
|
message: ({ lang }) => msg ?? message[lang],
|
|
12
12
|
optional: true,
|
|
13
|
-
validation: (value) =>
|
|
13
|
+
validation: (value) => baseDecimal(value)
|
|
14
14
|
})
|
|
15
15
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
export { and, not, or } from '@vuelidate/validators'
|
|
2
1
|
export { after } from './after'
|
|
3
2
|
export { afterOrEqual } from './afterOrEqual'
|
|
4
3
|
export { before } from './before'
|
|
@@ -30,3 +29,4 @@ export { url } from './url'
|
|
|
30
29
|
export { ymd } from './ymd'
|
|
31
30
|
export { zeroOrNegativeInteger } from './zeroOrNegativeInteger'
|
|
32
31
|
export { zeroOrPositiveInteger } from './zeroOrPositiveInteger'
|
|
32
|
+
export { and, not, or } from '@vuelidate/validators'
|
|
@@ -2,7 +2,7 @@ import { createRule } from '../Rule'
|
|
|
2
2
|
import { negativeInteger as baseNegativeInteger } from '../validators'
|
|
3
3
|
|
|
4
4
|
export const message = {
|
|
5
|
-
en: 'The value must be valid negative integer.',
|
|
5
|
+
en: 'The value must be a valid negative integer.',
|
|
6
6
|
ja: 'この値は負の整数である必要があります。'
|
|
7
7
|
}
|
|
8
8
|
|
|
@@ -2,7 +2,7 @@ import { createRule } from '../Rule'
|
|
|
2
2
|
import { positiveInteger as basePositiveInteger } from '../validators'
|
|
3
3
|
|
|
4
4
|
export const message = {
|
|
5
|
-
en: 'The value must be valid positive integer.',
|
|
5
|
+
en: 'The value must be a valid positive integer.',
|
|
6
6
|
ja: 'この値は正の整数である必要があります。'
|
|
7
7
|
}
|
|
8
8
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type HmsType } from '../../support/Day'
|
|
2
2
|
import { createRule } from '../Rule'
|
|
3
|
-
import {
|
|
3
|
+
import { hms as baseHms } from '../validators/hms'
|
|
4
4
|
|
|
5
5
|
export const message = {
|
|
6
6
|
en: 'The field is required.',
|
|
@@ -10,6 +10,6 @@ export const message = {
|
|
|
10
10
|
export function requiredHms(required?: HmsType[], msg?: string) {
|
|
11
11
|
return createRule({
|
|
12
12
|
message: ({ lang }) => msg ?? message[lang],
|
|
13
|
-
validation: (value) =>
|
|
13
|
+
validation: (value) => baseHms(value, required, true)
|
|
14
14
|
})
|
|
15
15
|
}
|
|
@@ -6,10 +6,7 @@ export const message = {
|
|
|
6
6
|
ja: 'この項目は必須です。'
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
export function requiredIf(
|
|
10
|
-
condition: RequiredIfCondition,
|
|
11
|
-
msg?: string
|
|
12
|
-
) {
|
|
9
|
+
export function requiredIf(condition: RequiredIfCondition, msg?: string) {
|
|
13
10
|
return createRule({
|
|
14
11
|
async: true,
|
|
15
12
|
params: { condition },
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type YmdType } from '../../support/Day'
|
|
2
2
|
import { createRule } from '../Rule'
|
|
3
|
-
import {
|
|
3
|
+
import { ymd as baseYmd } from '../validators/ymd'
|
|
4
4
|
|
|
5
5
|
export const message = {
|
|
6
6
|
en: 'The field is required.',
|
|
@@ -10,6 +10,6 @@ export const message = {
|
|
|
10
10
|
export function requiredYmd(required?: YmdType[], msg?: string) {
|
|
11
11
|
return createRule({
|
|
12
12
|
message: ({ lang }) => msg ?? message[lang],
|
|
13
|
-
validation: (value) =>
|
|
13
|
+
validation: (value) => baseYmd(value, required, true)
|
|
14
14
|
})
|
|
15
15
|
}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { createRule } from '../Rule'
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
type SlackChannelNameOptions,
|
|
4
|
+
slackChannelName as baseSlackChannelName
|
|
5
|
+
} from '../validators'
|
|
3
6
|
|
|
4
7
|
export const message = {
|
|
5
8
|
en: 'The slack channel name is invalid.',
|
|
@@ -2,7 +2,7 @@ import { createRule } from '../Rule'
|
|
|
2
2
|
import { negativeInteger as baseNegativeInteger, zero } from '../validators'
|
|
3
3
|
|
|
4
4
|
export const message = {
|
|
5
|
-
en: 'The value must be zero or valid negative integer.',
|
|
5
|
+
en: 'The value must be zero or a valid negative integer.',
|
|
6
6
|
ja: 'この値はゼロまたは負の整数である必要があります。'
|
|
7
7
|
}
|
|
8
8
|
|
|
@@ -2,7 +2,7 @@ import { createRule } from '../Rule'
|
|
|
2
2
|
import { positiveInteger as basePositiveInteger, zero } from '../validators'
|
|
3
3
|
|
|
4
4
|
export const message = {
|
|
5
|
-
en: 'The value must be zero or valid positive integer.',
|
|
5
|
+
en: 'The value must be zero or a valid positive integer.',
|
|
6
6
|
ja: 'この値はゼロまたは正の整数である必要があります。'
|
|
7
7
|
}
|
|
8
8
|
|
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
import { type Day, isDay } from '../../support/Day'
|
|
2
2
|
|
|
3
3
|
export function after(value: unknown, date: Day): boolean {
|
|
4
|
-
|
|
5
|
-
return false
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
return value.isAfter(date)
|
|
4
|
+
return isDay(value) && isDay(date) && value.isAfter(date, 'day')
|
|
9
5
|
}
|
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
import { type Day, isDay } from '../../support/Day'
|
|
2
2
|
|
|
3
3
|
export function afterOrEqual(value: unknown, date: Day): boolean {
|
|
4
|
-
|
|
5
|
-
return false
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
return value.isAfter(date) || value.isSame(date)
|
|
4
|
+
return isDay(value) && isDay(date) && (value.isAfter(date, 'day') || value.isSame(date, 'day'))
|
|
9
5
|
}
|
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
import { type Day, isDay } from '../../support/Day'
|
|
2
2
|
|
|
3
3
|
export function before(value: unknown, date: Day): boolean {
|
|
4
|
-
|
|
5
|
-
return false
|
|
6
|
-
}
|
|
7
|
-
return value.isBefore(date)
|
|
4
|
+
return isDay(value) && isDay(date) && value.isBefore(date, 'day')
|
|
8
5
|
}
|