@globalbrain/sefirot 2.7.2 → 2.8.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/lib/components/STable.vue +16 -2
- package/lib/components/STableCell.vue +3 -1
- package/lib/components/STableCellText.vue +18 -5
- package/lib/components/STableColumn.vue +1 -1
- package/lib/components/STableItem.vue +2 -1
- package/lib/composables/Table.ts +5 -3
- package/lib/support/Day/Constant.ts +32 -0
- package/lib/support/Day/index.ts +11 -0
- package/lib/support/Day/plugins/RelativeTime.ts +125 -0
- package/package.json +1 -1
- package/lib/support/Day.ts +0 -11
|
@@ -102,10 +102,17 @@ function updateColWidth(key: string, value: string) {
|
|
|
102
102
|
>
|
|
103
103
|
<div class="block">
|
|
104
104
|
<div class="row">
|
|
105
|
-
<STableItem
|
|
105
|
+
<STableItem
|
|
106
|
+
v-for="key in orders"
|
|
107
|
+
:key="key"
|
|
108
|
+
:name="key"
|
|
109
|
+
:class-name="columns[key].className"
|
|
110
|
+
:width="colWidths[key]"
|
|
111
|
+
>
|
|
106
112
|
<STableColumn
|
|
107
113
|
:name="key"
|
|
108
114
|
:label="columns[key].label"
|
|
115
|
+
:class-name="columns[key].className"
|
|
109
116
|
:dropdown="columns[key].dropdown"
|
|
110
117
|
@resize="(value) => updateColWidth(key, value)"
|
|
111
118
|
/>
|
|
@@ -124,9 +131,16 @@ function updateColWidth(key: string, value: string) {
|
|
|
124
131
|
>
|
|
125
132
|
<div class="block">
|
|
126
133
|
<div v-for="(record, rIndex) in records" :key="rIndex" class="row">
|
|
127
|
-
<STableItem
|
|
134
|
+
<STableItem
|
|
135
|
+
v-for="key in orders"
|
|
136
|
+
:key="key"
|
|
137
|
+
:name="key"
|
|
138
|
+
:class-name="columns[key].className"
|
|
139
|
+
:width="colWidths[key]"
|
|
140
|
+
>
|
|
128
141
|
<STableCell
|
|
129
142
|
:name="key"
|
|
143
|
+
:class-name="columns[key].className"
|
|
130
144
|
:cell="columns[key].cell"
|
|
131
145
|
:value="record[key]"
|
|
132
146
|
:record="record"
|
|
@@ -8,6 +8,7 @@ import STableCellText from './STableCellText.vue'
|
|
|
8
8
|
|
|
9
9
|
defineProps<{
|
|
10
10
|
name: string
|
|
11
|
+
className?: string
|
|
11
12
|
cell?: TableCell
|
|
12
13
|
value: any
|
|
13
14
|
record: any
|
|
@@ -16,7 +17,7 @@ defineProps<{
|
|
|
16
17
|
</script>
|
|
17
18
|
|
|
18
19
|
<template>
|
|
19
|
-
<div class="STableCell" :class="[`col-${name}`]">
|
|
20
|
+
<div class="STableCell" :class="[className, `col-${name}`]">
|
|
20
21
|
<STableCellText
|
|
21
22
|
v-if="!cell || cell.type === 'text'"
|
|
22
23
|
:value="value"
|
|
@@ -26,6 +27,7 @@ defineProps<{
|
|
|
26
27
|
:link="cell?.link"
|
|
27
28
|
:color="cell?.color"
|
|
28
29
|
:icon-color="cell?.iconColor"
|
|
30
|
+
:on-click="cell?.onClick"
|
|
29
31
|
/>
|
|
30
32
|
<STableCellDay
|
|
31
33
|
v-else-if="cell.type === 'day'"
|
|
@@ -8,6 +8,7 @@ export type Color =
|
|
|
8
8
|
| 'soft'
|
|
9
9
|
| 'mute'
|
|
10
10
|
| 'info'
|
|
11
|
+
| 'success'
|
|
11
12
|
| 'warning'
|
|
12
13
|
| 'danger'
|
|
13
14
|
|
|
@@ -15,10 +16,11 @@ const props = defineProps<{
|
|
|
15
16
|
value?: any
|
|
16
17
|
record: any
|
|
17
18
|
icon?: any
|
|
18
|
-
getter?: string | ((value: any) => string)
|
|
19
|
+
getter?: string | ((value: any, record: any) => string)
|
|
19
20
|
color?: Color | ((value: any, record: any) => Color)
|
|
20
21
|
iconColor?: Color | ((value: any, record: any) => Color)
|
|
21
22
|
link?(value: any, record: any): string
|
|
23
|
+
onClick?(value: any, record: any): void
|
|
22
24
|
}>()
|
|
23
25
|
|
|
24
26
|
const _value = computed(() => {
|
|
@@ -28,7 +30,7 @@ const _value = computed(() => {
|
|
|
28
30
|
|
|
29
31
|
return typeof props.getter === 'string'
|
|
30
32
|
? props.getter
|
|
31
|
-
: props.getter(props.value)
|
|
33
|
+
: props.getter(props.value, props.record)
|
|
32
34
|
})
|
|
33
35
|
|
|
34
36
|
const _color = computed(() => {
|
|
@@ -45,8 +47,14 @@ const _iconColor = computed(() => {
|
|
|
45
47
|
</script>
|
|
46
48
|
|
|
47
49
|
<template>
|
|
48
|
-
<div class="STableCellText" :class="[{ link }, _color]">
|
|
49
|
-
<SLink
|
|
50
|
+
<div class="STableCellText" :class="[{ link: link || onClick }, _color]">
|
|
51
|
+
<SLink
|
|
52
|
+
v-if="_value"
|
|
53
|
+
class="container"
|
|
54
|
+
:href="link?.(value, record)"
|
|
55
|
+
:role="onClick ? 'button' : null"
|
|
56
|
+
@click="() => onClick?.(value, record)"
|
|
57
|
+
>
|
|
50
58
|
<div v-if="icon" class="icon" :class="[_iconColor ?? _color]">
|
|
51
59
|
<SIcon :icon="icon" class="svg" />
|
|
52
60
|
</div>
|
|
@@ -81,6 +89,7 @@ const _iconColor = computed(() => {
|
|
|
81
89
|
&.soft { color: var(--c-text-2); }
|
|
82
90
|
&.mute { color: var(--c-text-3); }
|
|
83
91
|
&.info { color: var(--c-info); }
|
|
92
|
+
&.success { color: var(--c-success); }
|
|
84
93
|
&.warning { color: var(--c-warning); }
|
|
85
94
|
&.danger { color: var(--c-danger); }
|
|
86
95
|
|
|
@@ -92,9 +101,11 @@ const _iconColor = computed(() => {
|
|
|
92
101
|
.STableCellText.link &.soft { color: var(--c-text-2); }
|
|
93
102
|
.STableCellText.link:hover &.soft { color: var(--c-info); }
|
|
94
103
|
.STableCellText.link &.mute { color: var(--c-text-3); }
|
|
95
|
-
.STableCellText.link:hover &.mute { color: var(--c-
|
|
104
|
+
.STableCellText.link:hover &.mute { color: var(--c-text-3); }
|
|
96
105
|
.STableCellText.link &.info { color: var(--c-info); }
|
|
97
106
|
.STableCellText.link:hover &.info { color: var(--c-info-dark); }
|
|
107
|
+
.STableCellText.link &.success { color: var(--c-success); }
|
|
108
|
+
.STableCellText.link:hover &.success { color: var(--c-success-dark); }
|
|
98
109
|
.STableCellText.link &.warning { color: var(--c-warning); }
|
|
99
110
|
.STableCellText.link:hover &.warning { color: var(--c-warning-darker); }
|
|
100
111
|
.STableCellText.link &.danger { color: var(--c-danger); }
|
|
@@ -126,6 +137,8 @@ const _iconColor = computed(() => {
|
|
|
126
137
|
.STableCellText.link:hover &.mute { color: var(--c-info); }
|
|
127
138
|
.STableCellText.link &.info { color: var(--c-info); }
|
|
128
139
|
.STableCellText.link:hover &.info { color: var(--c-info-dark); }
|
|
140
|
+
.STableCellText.link &.success { color: var(--c-success); }
|
|
141
|
+
.STableCellText.link:hover &.success { color: var(--c-success-dark); }
|
|
129
142
|
.STableCellText.link &.warning { color: var(--c-warning); }
|
|
130
143
|
.STableCellText.link:hover &.warning { color: var(--c-warning-dark); }
|
|
131
144
|
.STableCellText.link &.danger { color: var(--c-danger); }
|
|
@@ -112,7 +112,7 @@ function stopDialogPositionListener() {
|
|
|
112
112
|
</script>
|
|
113
113
|
|
|
114
114
|
<template>
|
|
115
|
-
<div class="STableColumn STableCell" :class="[{ active }, className
|
|
115
|
+
<div class="STableColumn STableCell" :class="[{ active }, className, `col-${name}`]" ref="column">
|
|
116
116
|
<div class="container">
|
|
117
117
|
<p class="label">{{ label }}</p>
|
|
118
118
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
defineProps<{
|
|
3
3
|
name: string
|
|
4
|
+
className?: string
|
|
4
5
|
width?: string
|
|
5
6
|
}>()
|
|
6
7
|
</script>
|
|
@@ -8,7 +9,7 @@ defineProps<{
|
|
|
8
9
|
<template>
|
|
9
10
|
<div
|
|
10
11
|
class="STableItem"
|
|
11
|
-
:class="[`col-${name}`, { adjusted: width }]"
|
|
12
|
+
:class="[className, `col-${name}`, { adjusted: width }]"
|
|
12
13
|
>
|
|
13
14
|
<slot />
|
|
14
15
|
</div>
|
package/lib/composables/Table.ts
CHANGED
|
@@ -45,10 +45,11 @@ export interface TableCellBase {
|
|
|
45
45
|
export interface TableCellText extends TableCellBase {
|
|
46
46
|
type: 'text'
|
|
47
47
|
icon?: any
|
|
48
|
-
value?: string | ((value: any) => string)
|
|
48
|
+
value?: string | ((value: any, record: any) => string)
|
|
49
49
|
link?(value: any, record: any): string
|
|
50
50
|
color?: TableCellTextColor | ((value: any, record: any) => TableCellTextColor)
|
|
51
51
|
iconColor?: TableCellTextColor | ((value: any, record: any) => TableCellTextColor)
|
|
52
|
+
onClick?(value: any, record: any): void
|
|
52
53
|
}
|
|
53
54
|
|
|
54
55
|
export type TableCellTextColor =
|
|
@@ -56,6 +57,7 @@ export type TableCellTextColor =
|
|
|
56
57
|
| 'soft'
|
|
57
58
|
| 'mute'
|
|
58
59
|
| 'info'
|
|
60
|
+
| 'success'
|
|
59
61
|
| 'warning'
|
|
60
62
|
| 'danger'
|
|
61
63
|
|
|
@@ -99,8 +101,8 @@ export interface TableCellAvatarsOption {
|
|
|
99
101
|
}
|
|
100
102
|
|
|
101
103
|
export interface UseTableOptions {
|
|
102
|
-
orders: string[]
|
|
103
|
-
columns: TableColumns
|
|
104
|
+
orders: MaybeRef<string[]>
|
|
105
|
+
columns: MaybeRef<TableColumns>
|
|
104
106
|
records?: MaybeRef<Record<string, any>[] | null | undefined>
|
|
105
107
|
total?: MaybeRef<number | null | undefined>
|
|
106
108
|
page?: MaybeRef<number | null | undefined>
|
|
@@ -0,0 +1,32 @@
|
|
|
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
|
|
@@ -0,0 +1,11 @@
|
|
|
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): Dayjs {
|
|
10
|
+
return dayjs(input)
|
|
11
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
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
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
out = format(abs, withoutSuffix, t.l, isFuture)
|
|
92
|
+
}
|
|
93
|
+
break
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
if (withoutSuffix) { return out }
|
|
97
|
+
const pastOrFuture = isFuture ? loc.future : loc.past
|
|
98
|
+
if (typeof pastOrFuture === 'function') {
|
|
99
|
+
return pastOrFuture(out)
|
|
100
|
+
}
|
|
101
|
+
return pastOrFuture.replace('%s', out)
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function fromTo(input: any, withoutSuffix: any, instance: any, isFrom?: any) {
|
|
105
|
+
return (proto as any).fromToBase(input, withoutSuffix, instance, isFrom)
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
proto.to = function (input, withoutSuffix) {
|
|
109
|
+
return fromTo(input, withoutSuffix, this, true)
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
proto.from = function (input, withoutSuffix) {
|
|
113
|
+
return fromTo(input, withoutSuffix, this)
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const makeNow = (thisDay: any) => (thisDay.$u ? (d as any).utc() : d())
|
|
117
|
+
|
|
118
|
+
proto.toNow = function (withoutSuffix?: boolean) {
|
|
119
|
+
return this.to(makeNow(this), withoutSuffix)
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
proto.fromNow = function (withoutSuffix) {
|
|
123
|
+
return this.from(makeNow(this), withoutSuffix)
|
|
124
|
+
}
|
|
125
|
+
}
|
package/package.json
CHANGED
package/lib/support/Day.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import dayjs, { ConfigType, Dayjs } from 'dayjs/esm'
|
|
2
|
-
import RelativeTime from 'dayjs/esm/plugin/relativeTime'
|
|
3
|
-
|
|
4
|
-
export type Day = Dayjs
|
|
5
|
-
export type Input = ConfigType
|
|
6
|
-
|
|
7
|
-
dayjs.extend(RelativeTime)
|
|
8
|
-
|
|
9
|
-
export function day(input?: Input): Dayjs {
|
|
10
|
-
return dayjs(input)
|
|
11
|
-
}
|