@globalbrain/sefirot 2.12.0 → 2.14.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/LICENSE.md +1 -1
- package/lib/components/SButton.vue +4 -2
- package/lib/components/SInputBase.vue +75 -32
- package/lib/components/SInputCheckbox.vue +3 -0
- package/lib/components/SInputCheckboxes.vue +3 -0
- package/lib/components/SInputDate.vue +3 -0
- package/lib/components/SInputDropdown.vue +3 -0
- package/lib/components/SInputFile.vue +39 -34
- package/lib/components/SInputHMS.vue +4 -3
- package/lib/components/SInputNumber.vue +5 -1
- package/lib/components/SInputRadio.vue +19 -14
- package/lib/components/SInputRadios.vue +38 -12
- package/lib/components/SInputSelect.vue +15 -17
- package/lib/components/SInputSwitch.vue +3 -0
- package/lib/components/SInputSwitches.vue +3 -0
- package/lib/components/SInputText.vue +3 -0
- package/lib/components/SInputTextarea.vue +3 -0
- package/lib/components/SInputYMD.vue +3 -0
- package/lib/components/STable.vue +39 -10
- package/lib/components/STableColumn.vue +20 -5
- package/lib/components/STableFooter.vue +14 -8
- package/lib/components/STableHeader.vue +13 -7
- package/lib/components/STooltip.vue +51 -52
- package/lib/composables/Table.ts +5 -0
- package/lib/composables/Tooltip.ts +3 -3
- package/lib/composables/Utils.ts +26 -0
- package/lib/composables/Validation.ts +5 -2
- package/lib/styles/variables.css +13 -1
- package/lib/support/Day.ts +23 -0
- package/lib/support/Time.ts +2 -6
- package/lib/validation/rules/index.ts +6 -6
- package/lib/validation/rules/maxFileSize.ts +16 -0
- package/lib/validation/validators/maxFileSize.ts +10 -0
- package/package.json +10 -10
- package/lib/support/Day/Constant.ts +0 -32
- package/lib/support/Day/index.ts +0 -11
- package/lib/support/Day/plugins/RelativeTime.ts +0 -124
|
@@ -1,112 +1,111 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
-
import {
|
|
2
|
+
import { computed, ref } from 'vue'
|
|
3
3
|
import { Position, useTooltip } from '../composables/Tooltip'
|
|
4
4
|
import SMarkdown from './SMarkdown.vue'
|
|
5
5
|
|
|
6
|
-
const props = defineProps
|
|
7
|
-
tag
|
|
8
|
-
text
|
|
9
|
-
position
|
|
10
|
-
})
|
|
6
|
+
const props = defineProps<{
|
|
7
|
+
tag?: string
|
|
8
|
+
text?: string
|
|
9
|
+
position?: Position
|
|
10
|
+
}>()
|
|
11
11
|
|
|
12
12
|
const tip = ref<HTMLElement | null>(null)
|
|
13
13
|
const content = ref<HTMLElement | null>(null)
|
|
14
|
-
const classes = computed(() => [props.position])
|
|
15
|
-
|
|
14
|
+
const classes = computed(() => [props.position ?? 'top'])
|
|
15
|
+
|
|
16
|
+
const { on, show, hide } = useTooltip(
|
|
17
|
+
content,
|
|
18
|
+
tip,
|
|
19
|
+
computed(() => props.position ?? 'top')
|
|
20
|
+
)
|
|
16
21
|
</script>
|
|
17
22
|
|
|
18
23
|
<template>
|
|
19
|
-
<component :is="tag" class="STooltip" @mouseenter="show" @mouseleave="hide">
|
|
20
|
-
<
|
|
21
|
-
<
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
<
|
|
26
|
-
<span v-
|
|
27
|
-
|
|
28
|
-
</span>
|
|
29
|
-
</transition>
|
|
30
|
-
</template>
|
|
31
|
-
|
|
32
|
-
<template v-else>
|
|
33
|
-
<span class="STooltip-content">
|
|
34
|
-
<slot />
|
|
24
|
+
<component :is="tag ?? 'span'" class="STooltip" @mouseenter="show" @mouseleave="hide">
|
|
25
|
+
<span class="content" ref="content">
|
|
26
|
+
<slot />
|
|
27
|
+
</span>
|
|
28
|
+
|
|
29
|
+
<transition name="fade">
|
|
30
|
+
<span v-show="on" class="container" :class="classes" ref="tip">
|
|
31
|
+
<span v-if="$slots.text" class="tip"><slot name="text" /></span>
|
|
32
|
+
<SMarkdown v-else-if="text" tag="span" class="tip" :content="text" inline />
|
|
35
33
|
</span>
|
|
36
|
-
</
|
|
34
|
+
</transition>
|
|
37
35
|
</component>
|
|
38
36
|
</template>
|
|
39
37
|
|
|
40
|
-
<style lang="postcss"
|
|
38
|
+
<style scoped lang="postcss">
|
|
41
39
|
.STooltip {
|
|
42
40
|
position: relative;
|
|
43
41
|
}
|
|
44
42
|
|
|
45
|
-
.
|
|
43
|
+
.content {
|
|
44
|
+
white-space: nowrap;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
.container {
|
|
46
48
|
position: absolute;
|
|
47
|
-
display: block;
|
|
48
|
-
transition: opacity .25s;
|
|
49
49
|
z-index: var(--z-index-tooltip);
|
|
50
|
+
display: block;
|
|
51
|
+
transition: opacity 0.25s;
|
|
50
52
|
}
|
|
51
53
|
|
|
52
|
-
.
|
|
53
|
-
.
|
|
54
|
+
.container.fade-enter-from,
|
|
55
|
+
.container.fade-leave-to {
|
|
54
56
|
opacity: 0;
|
|
55
|
-
&.top .
|
|
56
|
-
&.right .
|
|
57
|
-
&.bottom .
|
|
58
|
-
&.left .
|
|
57
|
+
&.top .tip { transform: translateY(8px); }
|
|
58
|
+
&.right .tip { transform: translateX(-8px); }
|
|
59
|
+
&.bottom .tip { transform: translateY(-8px); }
|
|
60
|
+
&.left .tip { transform: translateX(8px); }
|
|
59
61
|
}
|
|
60
62
|
|
|
61
|
-
.
|
|
63
|
+
.container.top {
|
|
62
64
|
top: 0;
|
|
63
65
|
left: 50%;
|
|
64
66
|
padding-bottom: 8px;
|
|
65
67
|
transform: translate(-50%, -100%);
|
|
66
68
|
}
|
|
67
69
|
|
|
68
|
-
.
|
|
70
|
+
.container.right {
|
|
69
71
|
top: 50%;
|
|
70
72
|
left: 100%;
|
|
71
73
|
transform: translate(8px, -50%);
|
|
72
74
|
}
|
|
73
75
|
|
|
74
|
-
.
|
|
76
|
+
.container.bottom {
|
|
75
77
|
bottom: 0;
|
|
76
78
|
left: 50%;
|
|
77
79
|
padding-top: 8px;
|
|
78
80
|
transform: translate(-50%, 100%);
|
|
79
81
|
}
|
|
80
82
|
|
|
81
|
-
.
|
|
83
|
+
.container.left {
|
|
82
84
|
top: 50%;
|
|
83
85
|
right: 100%;
|
|
84
86
|
transform: translate(-8px, -50%);
|
|
85
87
|
}
|
|
86
88
|
|
|
87
|
-
.
|
|
89
|
+
.tip {
|
|
88
90
|
display: block;
|
|
89
|
-
border
|
|
91
|
+
border: 1px solid var(--tooltip-border-color);
|
|
92
|
+
border-radius: 6px;
|
|
90
93
|
padding: 12px;
|
|
91
94
|
width: max-content;
|
|
92
|
-
max-width:
|
|
95
|
+
max-width: var(--tooltip-max-width);
|
|
93
96
|
line-height: 18px;
|
|
94
97
|
font-size: 12px;
|
|
95
98
|
font-weight: 500;
|
|
96
|
-
color: var(--
|
|
97
|
-
background-color:
|
|
98
|
-
transition: transform .25s;
|
|
99
|
+
color: var(--tooltip-text-color);
|
|
100
|
+
background-color: var(--tooltip-bg-color);
|
|
101
|
+
transition: transform 0.25s;
|
|
99
102
|
}
|
|
100
103
|
|
|
101
|
-
.
|
|
102
|
-
color: var(--c-info);
|
|
104
|
+
.tip :deep(a) {
|
|
105
|
+
color: var(--c-info-text);
|
|
103
106
|
|
|
104
107
|
&:hover {
|
|
105
|
-
color: var(--c-info-dark);
|
|
108
|
+
color: var(--c-info-text-dark);
|
|
106
109
|
}
|
|
107
110
|
}
|
|
108
|
-
|
|
109
|
-
.STooltip-content {
|
|
110
|
-
white-space: nowrap;
|
|
111
|
-
}
|
|
112
111
|
</style>
|
package/lib/composables/Table.ts
CHANGED
|
@@ -6,6 +6,8 @@ export interface Table {
|
|
|
6
6
|
orders: string[]
|
|
7
7
|
columns: TableColumns
|
|
8
8
|
records?: Record<string, any>[] | null
|
|
9
|
+
header?: boolean
|
|
10
|
+
footer?: boolean
|
|
9
11
|
total?: number | null
|
|
10
12
|
page?: number | null
|
|
11
13
|
perPage?: number | null
|
|
@@ -25,6 +27,7 @@ export interface TableColumn {
|
|
|
25
27
|
label: string
|
|
26
28
|
className?: string
|
|
27
29
|
dropdown?: DropdownSection[]
|
|
30
|
+
resizable?: boolean
|
|
28
31
|
cell?: TableCell | ((value: any, record: any) => TableCell)
|
|
29
32
|
}
|
|
30
33
|
|
|
@@ -115,6 +118,8 @@ export interface UseTableOptions {
|
|
|
115
118
|
orders: MaybeRef<string[]>
|
|
116
119
|
columns: MaybeRef<TableColumns>
|
|
117
120
|
records?: MaybeRef<Record<string, any>[] | null | undefined>
|
|
121
|
+
header?: MaybeRef<boolean | undefined>
|
|
122
|
+
footer?: MaybeRef<boolean | undefined>
|
|
118
123
|
total?: MaybeRef<number | null | undefined>
|
|
119
124
|
page?: MaybeRef<number | null | undefined>
|
|
120
125
|
perPage?: MaybeRef<number | null | undefined>
|
|
@@ -12,7 +12,7 @@ const SCREEN_PADDING = 16
|
|
|
12
12
|
export function useTooltip(
|
|
13
13
|
content: Ref<HTMLElement | null>,
|
|
14
14
|
tip: Ref<HTMLElement | null>,
|
|
15
|
-
position: Position
|
|
15
|
+
position: Ref<Position>
|
|
16
16
|
) {
|
|
17
17
|
const on = ref(false)
|
|
18
18
|
|
|
@@ -72,7 +72,7 @@ export function useTooltip(
|
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
function setTransform(x: number): void {
|
|
75
|
-
tip.value!.style.transform = `translate(${x}px, ${position === 'top' ? -100 : 100}%)`
|
|
75
|
+
tip.value!.style.transform = `translate(${x}px, ${position.value === 'top' ? -100 : 100}%)`
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
function shouldPosition(): boolean {
|
|
@@ -80,7 +80,7 @@ export function useTooltip(
|
|
|
80
80
|
return false
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
-
return position === 'top' || position === 'bottom'
|
|
83
|
+
return position.value === 'top' || position.value === 'bottom'
|
|
84
84
|
}
|
|
85
85
|
|
|
86
86
|
return {
|
package/lib/composables/Utils.ts
CHANGED
|
@@ -1,5 +1,31 @@
|
|
|
1
|
+
import { MaybeComputedRef, resolveUnref } from '@vueuse/core'
|
|
1
2
|
import { ComputedRef, computed } from 'vue'
|
|
2
3
|
|
|
4
|
+
export type WhenCondition<T> = MaybeComputedRef<T>
|
|
5
|
+
|
|
6
|
+
export function computedWhen<T, C>(
|
|
7
|
+
condition: WhenCondition<C>,
|
|
8
|
+
fn: (item: NonNullable<C>) => T
|
|
9
|
+
): ComputedRef<T | undefined>
|
|
10
|
+
|
|
11
|
+
export function computedWhen<T, C, D>(
|
|
12
|
+
condition: WhenCondition<C>,
|
|
13
|
+
fn: (item: NonNullable<C>) => T,
|
|
14
|
+
whenFalse: D
|
|
15
|
+
): ComputedRef<T | D>
|
|
16
|
+
|
|
17
|
+
export function computedWhen<T, C, D>(
|
|
18
|
+
condition: WhenCondition<C>,
|
|
19
|
+
fn: (item: NonNullable<C>) => T,
|
|
20
|
+
whenFalse?: D
|
|
21
|
+
): ComputedRef<T | D> {
|
|
22
|
+
return computed(() => {
|
|
23
|
+
const c = resolveUnref(condition)
|
|
24
|
+
|
|
25
|
+
return c ? fn(c) : whenFalse as D
|
|
26
|
+
})
|
|
27
|
+
}
|
|
28
|
+
|
|
3
29
|
export function computedArray<T = any>(fn: (arr: T[]) => void): ComputedRef<T[]> {
|
|
4
30
|
return computed(() => {
|
|
5
31
|
const arr = [] as T[]
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import {
|
|
2
|
-
ErrorObject,
|
|
3
2
|
GlobalConfig,
|
|
4
3
|
Validation,
|
|
5
4
|
ValidationArgs,
|
|
@@ -11,11 +10,15 @@ export type { Validation, ValidationArgs, GlobalConfig }
|
|
|
11
10
|
|
|
12
11
|
export interface Validatable {
|
|
13
12
|
readonly $dirty: boolean
|
|
14
|
-
readonly $errors: ErrorObject[]
|
|
15
13
|
readonly $invalid: boolean
|
|
14
|
+
readonly $errors: ValidatableError[]
|
|
16
15
|
readonly $touch: () => void
|
|
17
16
|
}
|
|
18
17
|
|
|
18
|
+
export interface ValidatableError {
|
|
19
|
+
readonly $message: string | Ref<string>
|
|
20
|
+
}
|
|
21
|
+
|
|
19
22
|
export function useValidation<
|
|
20
23
|
T extends { [key in keyof R]: any },
|
|
21
24
|
R extends ValidationArgs = ValidationArgs
|
package/lib/styles/variables.css
CHANGED
|
@@ -287,6 +287,7 @@
|
|
|
287
287
|
* -------------------------------------------------------------------------- */
|
|
288
288
|
|
|
289
289
|
:root {
|
|
290
|
+
--z-index-tooltip: 10;
|
|
290
291
|
--z-index-dropdown: 1000;
|
|
291
292
|
--z-index-backdrop: 2000;
|
|
292
293
|
}
|
|
@@ -594,6 +595,17 @@
|
|
|
594
595
|
--pill-fill-danger-active-bg-color: var(--c-danger-bg-darker);
|
|
595
596
|
}
|
|
596
597
|
|
|
598
|
+
/**
|
|
599
|
+
* Component: Tooltip
|
|
600
|
+
* -------------------------------------------------------------------------- */
|
|
601
|
+
|
|
602
|
+
:root {
|
|
603
|
+
--tooltip-max-width: 288px;
|
|
604
|
+
--tooltip-border-color: var(--c-divider-2);
|
|
605
|
+
--tooltip-text-color: var(--c-text-1);
|
|
606
|
+
--tooltip-bg-color: var(--c-bg-elv-3);
|
|
607
|
+
}
|
|
608
|
+
|
|
597
609
|
/**
|
|
598
610
|
* Component: Dropdown
|
|
599
611
|
* -------------------------------------------------------------------------- */
|
|
@@ -611,7 +623,7 @@
|
|
|
611
623
|
* -------------------------------------------------------------------------- */
|
|
612
624
|
|
|
613
625
|
:root {
|
|
614
|
-
--table-border: 1px solid var(--c-divider-
|
|
626
|
+
--table-border: 1px solid var(--c-divider-2);
|
|
615
627
|
--table-border-top: var(--table-border);
|
|
616
628
|
--table-border-right: var(--table-border);
|
|
617
629
|
--table-border-bottom: var(--table-border);
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import dayjs, { ConfigType, Dayjs } from 'dayjs'
|
|
2
|
+
import PluginRelativeTime from 'dayjs/plugin/relativeTime'
|
|
3
|
+
import PluginTimezone from 'dayjs/plugin/timezone'
|
|
4
|
+
import PluginUtc from 'dayjs/plugin/utc'
|
|
5
|
+
|
|
6
|
+
export type Day = Dayjs
|
|
7
|
+
export type Input = ConfigType
|
|
8
|
+
|
|
9
|
+
dayjs.extend(PluginUtc)
|
|
10
|
+
dayjs.extend(PluginTimezone)
|
|
11
|
+
dayjs.extend(PluginRelativeTime)
|
|
12
|
+
|
|
13
|
+
export function day(input?: Input): Day {
|
|
14
|
+
return dayjs(input)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function utc(input?: Input): Day {
|
|
18
|
+
return dayjs.utc(input)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function tz(input?: Input, timezone?: string): Day {
|
|
22
|
+
return dayjs.tz(input, timezone)
|
|
23
|
+
}
|
package/lib/support/Time.ts
CHANGED
|
@@ -1,13 +1,9 @@
|
|
|
1
|
-
type Awaited<T> = T extends undefined
|
|
2
|
-
? T
|
|
3
|
-
: T extends PromiseLike<infer U> ? U : T
|
|
4
|
-
|
|
5
1
|
export function sleep(ms = 500): Promise<undefined> {
|
|
6
2
|
return new Promise<undefined>((resolve) => setTimeout(resolve, ms))
|
|
7
3
|
}
|
|
8
4
|
|
|
9
|
-
export function delay<T extends
|
|
10
|
-
iterable: T,
|
|
5
|
+
export function delay<T extends unknown[]>(
|
|
6
|
+
iterable: [...T],
|
|
11
7
|
ms?: number
|
|
12
8
|
): Promise<{ [P in keyof T]: Awaited<T[P]> }> {
|
|
13
9
|
return Promise.all([...iterable, sleep(ms)]) as any
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
export {
|
|
2
|
-
|
|
1
|
+
export { and, not, or } from '@vuelidate/validators'
|
|
3
2
|
export * from './checked'
|
|
3
|
+
export * from './decimal'
|
|
4
4
|
export * from './email'
|
|
5
5
|
export * from './fileExtension'
|
|
6
6
|
export * from './hms'
|
|
7
|
+
export * from './maxFileSize'
|
|
7
8
|
export * from './maxLength'
|
|
8
|
-
export * from './minLength'
|
|
9
9
|
export * from './maxValue'
|
|
10
|
+
export * from './minLength'
|
|
10
11
|
export * from './minValue'
|
|
12
|
+
export * from './month'
|
|
11
13
|
export * from './required'
|
|
12
14
|
export * from './requiredHms'
|
|
13
15
|
export * from './requiredIf'
|
|
14
16
|
export * from './requiredYmd'
|
|
17
|
+
export * from './rule'
|
|
15
18
|
export * from './url'
|
|
16
|
-
export * from './decimal'
|
|
17
|
-
export * from './month'
|
|
18
19
|
export * from './ymd'
|
|
19
|
-
export * from './rule'
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { helpers } from '@vuelidate/validators'
|
|
2
|
+
import { maxFileSize as baseMaxFileSize } from '../validators/maxFileSize'
|
|
3
|
+
|
|
4
|
+
export function maxFileSize(size: string, msg?: string) {
|
|
5
|
+
return helpers.withParams(
|
|
6
|
+
{ size },
|
|
7
|
+
helpers.withMessage(
|
|
8
|
+
({ $params }) => {
|
|
9
|
+
return msg ?? `The file must be smaller than ${$params.size}.`
|
|
10
|
+
},
|
|
11
|
+
(value: File) => {
|
|
12
|
+
return !helpers.req(value) || baseMaxFileSize(value, size)
|
|
13
|
+
}
|
|
14
|
+
)
|
|
15
|
+
)
|
|
16
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@globalbrain/sefirot",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.14.0",
|
|
4
4
|
"description": "Vue Components for Global Brain Design System.",
|
|
5
5
|
"author": "Kia Ishii <ka.ishii@globalbrains.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -52,9 +52,9 @@
|
|
|
52
52
|
"@types/body-scroll-lock": "^3.1.0",
|
|
53
53
|
"@types/lodash-es": "^4.17.6",
|
|
54
54
|
"@types/markdown-it": "^12.2.3",
|
|
55
|
-
"@types/node": "^18.11.
|
|
56
|
-
"@vitejs/plugin-vue": "^
|
|
57
|
-
"@vitest/coverage-c8": "^0.
|
|
55
|
+
"@types/node": "^18.11.18",
|
|
56
|
+
"@vitejs/plugin-vue": "^4.0.0",
|
|
57
|
+
"@vitest/coverage-c8": "^0.27.2",
|
|
58
58
|
"@vue/test-utils": "^2.2.7",
|
|
59
59
|
"@vuelidate/core": "^2.0.0",
|
|
60
60
|
"@vuelidate/validators": "^2.0.0",
|
|
@@ -63,10 +63,10 @@
|
|
|
63
63
|
"chalk": "^4.1.2",
|
|
64
64
|
"conventional-changelog-cli": "^2.2.2",
|
|
65
65
|
"enquirer": "^2.3.6",
|
|
66
|
-
"eslint": "^8.
|
|
66
|
+
"eslint": "^8.32.0",
|
|
67
67
|
"execa": "^5.1.1",
|
|
68
68
|
"fuse.js": "^6.6.2",
|
|
69
|
-
"happy-dom": "^8.1.
|
|
69
|
+
"happy-dom": "^8.1.4",
|
|
70
70
|
"histoire": "^0.12.4",
|
|
71
71
|
"lodash-es": "^4.17.21",
|
|
72
72
|
"markdown-it": "^13.0.1",
|
|
@@ -77,12 +77,12 @@
|
|
|
77
77
|
"semver": "^7.3.8",
|
|
78
78
|
"typescript": "^4.9.4",
|
|
79
79
|
"v-calendar": "3.0.0-alpha.8",
|
|
80
|
-
"vite": "^
|
|
81
|
-
"vitepress": "1.0.0-alpha.
|
|
82
|
-
"vitest": "^0.
|
|
80
|
+
"vite": "^4.0.4",
|
|
81
|
+
"vitepress": "1.0.0-alpha.38",
|
|
82
|
+
"vitest": "^0.27.2",
|
|
83
83
|
"vue": "^3.2.45",
|
|
84
84
|
"vue-router": "^4.1.6",
|
|
85
|
-
"vue-tsc": "^1.0.
|
|
85
|
+
"vue-tsc": "^1.0.24"
|
|
86
86
|
},
|
|
87
87
|
"scripts": {
|
|
88
88
|
"docs": "vitepress dev docs --port 4000",
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
// This file is copied from the source to avoid plugin resolution problem.
|
|
2
|
-
|
|
3
|
-
export const SECONDS_A_MINUTE = 60
|
|
4
|
-
export const SECONDS_A_HOUR = SECONDS_A_MINUTE * 60
|
|
5
|
-
export const SECONDS_A_DAY = SECONDS_A_HOUR * 24
|
|
6
|
-
export const SECONDS_A_WEEK = SECONDS_A_DAY * 7
|
|
7
|
-
|
|
8
|
-
export const MILLISECONDS_A_SECOND = 1e3
|
|
9
|
-
export const MILLISECONDS_A_MINUTE = SECONDS_A_MINUTE * MILLISECONDS_A_SECOND
|
|
10
|
-
export const MILLISECONDS_A_HOUR = SECONDS_A_HOUR * MILLISECONDS_A_SECOND
|
|
11
|
-
export const MILLISECONDS_A_DAY = SECONDS_A_DAY * MILLISECONDS_A_SECOND
|
|
12
|
-
export const MILLISECONDS_A_WEEK = SECONDS_A_WEEK * MILLISECONDS_A_SECOND
|
|
13
|
-
|
|
14
|
-
// English locales
|
|
15
|
-
export const MS = 'millisecond'
|
|
16
|
-
export const S = 'second'
|
|
17
|
-
export const MIN = 'minute'
|
|
18
|
-
export const H = 'hour'
|
|
19
|
-
export const D = 'day'
|
|
20
|
-
export const W = 'week'
|
|
21
|
-
export const M = 'month'
|
|
22
|
-
export const Q = 'quarter'
|
|
23
|
-
export const Y = 'year'
|
|
24
|
-
export const DATE = 'date'
|
|
25
|
-
|
|
26
|
-
export const FORMAT_DEFAULT = 'YYYY-MM-DDTHH:mm:ssZ'
|
|
27
|
-
|
|
28
|
-
export const INVALID_DATE_STRING = 'Invalid Date'
|
|
29
|
-
|
|
30
|
-
// Regex
|
|
31
|
-
export const REGEX_PARSE = /^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[Tt\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/
|
|
32
|
-
export const REGEX_FORMAT = /\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g
|
package/lib/support/Day/index.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import dayjs, { ConfigType, Dayjs } from 'dayjs'
|
|
2
|
-
import { relativeTime } from './plugins/RelativeTime'
|
|
3
|
-
|
|
4
|
-
export type Day = Dayjs
|
|
5
|
-
export type Input = ConfigType
|
|
6
|
-
|
|
7
|
-
dayjs.extend(relativeTime)
|
|
8
|
-
|
|
9
|
-
export function day(input?: Input): Day {
|
|
10
|
-
return dayjs(input)
|
|
11
|
-
}
|
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
// This file is copied from the source to avoid plugin resolution problem.
|
|
2
|
-
|
|
3
|
-
import { PluginFunc } from 'dayjs'
|
|
4
|
-
import * as C from '../Constant'
|
|
5
|
-
|
|
6
|
-
declare module 'dayjs' {
|
|
7
|
-
interface Dayjs {
|
|
8
|
-
fromNow(withoutSuffix?: boolean): string
|
|
9
|
-
from(compared: ConfigType, withoutSuffix?: boolean): string
|
|
10
|
-
toNow(withoutSuffix?: boolean): string
|
|
11
|
-
to(compared: ConfigType, withoutSuffix?: boolean): string
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export interface RelativeTimeOptions {
|
|
16
|
-
rounding?: (num: number) => number
|
|
17
|
-
thresholds?: RelativeTimeThreshold[]
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export interface RelativeTimeThreshold {
|
|
21
|
-
l: string
|
|
22
|
-
r?: number
|
|
23
|
-
d?: string
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export const relativeTime: PluginFunc<RelativeTimeOptions> = (o, c, d) => {
|
|
27
|
-
o = o || {}
|
|
28
|
-
|
|
29
|
-
const proto = c.prototype
|
|
30
|
-
|
|
31
|
-
const relObj = {
|
|
32
|
-
future: 'in %s',
|
|
33
|
-
past: '%s ago',
|
|
34
|
-
s: 'a few seconds',
|
|
35
|
-
m: 'a minute',
|
|
36
|
-
mm: '%d minutes',
|
|
37
|
-
h: 'an hour',
|
|
38
|
-
hh: '%d hours',
|
|
39
|
-
d: 'a day',
|
|
40
|
-
dd: '%d days',
|
|
41
|
-
M: 'a month',
|
|
42
|
-
MM: '%d months',
|
|
43
|
-
y: 'a year',
|
|
44
|
-
yy: '%d years'
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
;(d as any).en.relativeTime = relObj
|
|
48
|
-
|
|
49
|
-
;(proto as any).fromToBase = (input: any, withoutSuffix: any, instance: any, isFrom: any, postFormat: any) => {
|
|
50
|
-
const loc = instance.$locale().relativeTime || relObj
|
|
51
|
-
|
|
52
|
-
const T = o.thresholds || [
|
|
53
|
-
{ l: 's', r: 44, d: C.S },
|
|
54
|
-
{ l: 'm', r: 89 },
|
|
55
|
-
{ l: 'mm', r: 44, d: C.MIN },
|
|
56
|
-
{ l: 'h', r: 89 },
|
|
57
|
-
{ l: 'hh', r: 21, d: C.H },
|
|
58
|
-
{ l: 'd', r: 35 },
|
|
59
|
-
{ l: 'dd', r: 25, d: C.D },
|
|
60
|
-
{ l: 'M', r: 45 },
|
|
61
|
-
{ l: 'MM', r: 10, d: C.M },
|
|
62
|
-
{ l: 'y', r: 17 },
|
|
63
|
-
{ l: 'yy', d: C.Y }
|
|
64
|
-
]
|
|
65
|
-
|
|
66
|
-
const Tl = T.length
|
|
67
|
-
|
|
68
|
-
let result
|
|
69
|
-
let out
|
|
70
|
-
let isFuture
|
|
71
|
-
|
|
72
|
-
for (let i = 0; i < Tl; i += 1) {
|
|
73
|
-
let t = T[i]
|
|
74
|
-
if (t.d) {
|
|
75
|
-
result = isFrom
|
|
76
|
-
? d(input).diff(instance, (t as any).d, true)
|
|
77
|
-
: instance.diff(input, t.d, true)
|
|
78
|
-
}
|
|
79
|
-
let abs = (o.rounding || Math.round)(Math.abs(result))
|
|
80
|
-
isFuture = result > 0
|
|
81
|
-
if (abs <= (t as any).r || !t.r) {
|
|
82
|
-
if (abs <= 1 && i > 0) { t = T[i - 1] } // 1 minutes -> a minute, 0 seconds -> 0 second
|
|
83
|
-
const format = loc[t.l]
|
|
84
|
-
if (postFormat) {
|
|
85
|
-
abs = postFormat(`${abs}`)
|
|
86
|
-
}
|
|
87
|
-
if (typeof format === 'string') {
|
|
88
|
-
out = (format as any).replace('%d', abs)
|
|
89
|
-
} else {
|
|
90
|
-
out = format(abs, withoutSuffix, t.l, isFuture)
|
|
91
|
-
}
|
|
92
|
-
break
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
if (withoutSuffix) { return out }
|
|
96
|
-
const pastOrFuture = isFuture ? loc.future : loc.past
|
|
97
|
-
if (typeof pastOrFuture === 'function') {
|
|
98
|
-
return pastOrFuture(out)
|
|
99
|
-
}
|
|
100
|
-
return pastOrFuture.replace('%s', out)
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
function fromTo(input: any, withoutSuffix: any, instance: any, isFrom?: any) {
|
|
104
|
-
return (proto as any).fromToBase(input, withoutSuffix, instance, isFrom)
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
proto.to = function (input, withoutSuffix) {
|
|
108
|
-
return fromTo(input, withoutSuffix, this, true)
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
proto.from = function (input, withoutSuffix) {
|
|
112
|
-
return fromTo(input, withoutSuffix, this)
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
const makeNow = (thisDay: any) => (thisDay.$u ? (d as any).utc() : d())
|
|
116
|
-
|
|
117
|
-
proto.toNow = function (withoutSuffix?: boolean) {
|
|
118
|
-
return this.to(makeNow(this), withoutSuffix)
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
proto.fromNow = function (withoutSuffix) {
|
|
122
|
-
return this.from(makeNow(this), withoutSuffix)
|
|
123
|
-
}
|
|
124
|
-
}
|