@operato/data-grist 2.0.0-alpha.20 → 2.0.0-alpha.22
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/CHANGELOG.md +9 -0
- package/dist/src/editors/ox-grist-editor.js +1 -1
- package/dist/src/editors/ox-grist-editor.js.map +1 -1
- package/dist/src/filters/filter-range-date.js +12 -1
- package/dist/src/filters/filter-range-date.js.map +1 -1
- package/dist/src/filters/filters-form.d.ts +1 -0
- package/dist/src/filters/filters-form.js +21 -3
- package/dist/src/filters/filters-form.js.map +1 -1
- package/dist/src/index.d.ts +0 -1
- package/dist/src/index.js +0 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/types.d.ts +0 -8
- package/dist/src/types.js.map +1 -1
- package/dist/stories/grist-modes.stories.js +23 -2
- package/dist/stories/grist-modes.stories.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -2
- package/src/editors/ox-grist-editor.ts +1 -1
- package/src/filters/filter-range-date.ts +16 -1
- package/src/filters/filters-form.ts +25 -2
- package/src/index.ts +0 -1
- package/src/types.ts +0 -9
- package/stories/grist-modes.stories.ts +23 -2
- package/src/value-generator/date-generator.ts +0 -35
- package/src/value-generator/hour-time-generator.ts +0 -43
- package/src/value-generator/index.ts +0 -1
- package/src/value-generator/minute-time-generator.ts +0 -43
- package/src/value-generator/month-date-generator.ts +0 -38
- package/src/value-generator/now-generator.ts +0 -10
- package/src/value-generator/registry.ts +0 -58
- package/src/value-generator/time-generator.ts +0 -33
- package/src/value-generator/today-generator.ts +0 -10
- package/src/value-generator/week-date-generator.ts +0 -40
- package/src/value-generator/year-date-generator.ts +0 -36
@@ -6,6 +6,8 @@ import '@operato/input/ox-input-search.js'
|
|
6
6
|
import { css, html, LitElement, PropertyValues, TemplateResult, nothing } from 'lit'
|
7
7
|
import { customElement, property, queryAsync, state } from 'lit/decorators.js'
|
8
8
|
|
9
|
+
import { getDefaultValue } from '@operato/time-calculator'
|
10
|
+
|
9
11
|
import { FilterConfigObject } from '..'
|
10
12
|
import { DataGrist } from '../data-grist'
|
11
13
|
import { ColumnConfig, FilterOperator, FilterValue, GristConfig } from '../types'
|
@@ -72,7 +74,6 @@ export class FiltersForm extends LitElement {
|
|
72
74
|
|
73
75
|
if (grist) {
|
74
76
|
this.config = grist.compiledConfig
|
75
|
-
this.value = grist.filters || []
|
76
77
|
|
77
78
|
grist.addEventListener('config-change', (e: Event) => {
|
78
79
|
this.config = (e as CustomEvent).detail
|
@@ -102,6 +103,17 @@ export class FiltersForm extends LitElement {
|
|
102
103
|
}
|
103
104
|
}
|
104
105
|
|
106
|
+
buildDefaultValue(operator: string, defaultValue: any) {
|
107
|
+
if (defaultValue === undefined) {
|
108
|
+
return
|
109
|
+
}
|
110
|
+
if (operator == 'between') {
|
111
|
+
return (defaultValue as Array<any>).map(v => getDefaultValue(v, this))
|
112
|
+
} else {
|
113
|
+
return getDefaultValue(defaultValue, this)
|
114
|
+
}
|
115
|
+
}
|
116
|
+
|
105
117
|
updated(changes: PropertyValues<this>) {
|
106
118
|
if (changes.has('config')) {
|
107
119
|
const filters = this.config.columns.filter(columnConfig => !!columnConfig.filter)
|
@@ -114,6 +126,15 @@ export class FiltersForm extends LitElement {
|
|
114
126
|
return filter!.operator === 'search'
|
115
127
|
})
|
116
128
|
|
129
|
+
const grist = this.closest('ox-grist') as DataGrist
|
130
|
+
|
131
|
+
this.value = (grist.filters || []).map(filter => {
|
132
|
+
return {
|
133
|
+
...filter,
|
134
|
+
value: this.buildDefaultValue(filter!.operator, filter!.value)
|
135
|
+
}
|
136
|
+
})
|
137
|
+
|
117
138
|
this.empty = (this.searchColumns.length === 0 || this.withoutSearch) && this.filterColumns.length === 0
|
118
139
|
}
|
119
140
|
}
|
@@ -160,7 +181,9 @@ export class FiltersForm extends LitElement {
|
|
160
181
|
? 'text'
|
161
182
|
: type
|
162
183
|
)[idx]
|
163
|
-
const value =
|
184
|
+
const value =
|
185
|
+
this.value?.find(filter => filter.name == name)?.value ??
|
186
|
+
this.buildDefaultValue(operator!, (filter as FilterConfigObject)?.value)
|
164
187
|
|
165
188
|
if (!renderer) {
|
166
189
|
return html``
|
package/src/index.ts
CHANGED
package/src/types.ts
CHANGED
@@ -427,15 +427,6 @@ export type HeaderConfig = {
|
|
427
427
|
*/
|
428
428
|
export type HeaderRenderer = (column: ColumnConfig) => any
|
429
429
|
|
430
|
-
/**
|
431
|
-
* Function type for generating values.
|
432
|
-
*
|
433
|
-
* @callback ValueGeneratorFn
|
434
|
-
* @param {...any} args - The arguments used for generating a value.
|
435
|
-
* @returns {*} - The generated value.
|
436
|
-
*/
|
437
|
-
export type ValueGeneratorFn = (...args: any[]) => any
|
438
|
-
|
439
430
|
/**
|
440
431
|
* Configuration for specifying default values for fields in a record.
|
441
432
|
* Default values can be set using predefined value generator functions or custom user-defined functions.
|
@@ -237,7 +237,10 @@ const config = {
|
|
237
237
|
editable: true,
|
238
238
|
defaultValue: 10000.1
|
239
239
|
},
|
240
|
-
filter:
|
240
|
+
filter: {
|
241
|
+
operator: 'between',
|
242
|
+
value: [1, 100]
|
243
|
+
},
|
241
244
|
sortable: true,
|
242
245
|
width: 50
|
243
246
|
},
|
@@ -266,7 +269,25 @@ const config = {
|
|
266
269
|
name: 'now'
|
267
270
|
}
|
268
271
|
},
|
269
|
-
filter:
|
272
|
+
filter: {
|
273
|
+
operator: 'between',
|
274
|
+
type: 'datetime',
|
275
|
+
value: [
|
276
|
+
{
|
277
|
+
name: 'today',
|
278
|
+
params: {
|
279
|
+
type: 'datetime'
|
280
|
+
}
|
281
|
+
},
|
282
|
+
{
|
283
|
+
name: 'now',
|
284
|
+
params: {
|
285
|
+
type: 'datetime',
|
286
|
+
relativeDate: 1
|
287
|
+
}
|
288
|
+
}
|
289
|
+
]
|
290
|
+
},
|
270
291
|
sortable: true,
|
271
292
|
width: 180
|
272
293
|
},
|
@@ -1,35 +0,0 @@
|
|
1
|
-
export type RelativeDateParams = {
|
2
|
-
relativeDate?: number
|
3
|
-
timeZone?: string
|
4
|
-
format?: 'timestamp' | 'date' | Intl.DateTimeFormatOptions
|
5
|
-
}
|
6
|
-
|
7
|
-
export const getRelativeDate = (params: RelativeDateParams = {}): Date | number | string => {
|
8
|
-
const { relativeDate = 0, timeZone, format } = params
|
9
|
-
const relativeSeconds = relativeDate * 24 * 60 * 60
|
10
|
-
|
11
|
-
const now = new Date()
|
12
|
-
let currentDate: Date
|
13
|
-
|
14
|
-
if (timeZone) {
|
15
|
-
const options: Intl.DateTimeFormatOptions = { timeZone }
|
16
|
-
const currentDateISOString = now.toLocaleString('en-US', options).split(',')[0]
|
17
|
-
currentDate = new Date(currentDateISOString)
|
18
|
-
} else {
|
19
|
-
currentDate = now
|
20
|
-
}
|
21
|
-
|
22
|
-
const startOfDay = new Date(currentDate.getFullYear(), currentDate.getMonth(), currentDate.getDate())
|
23
|
-
const targetTime = startOfDay.getTime() + relativeSeconds * 1000
|
24
|
-
|
25
|
-
if (format === 'date') {
|
26
|
-
return new Date(targetTime)
|
27
|
-
} else if (format === 'timestamp') {
|
28
|
-
return targetTime
|
29
|
-
} else if (format) {
|
30
|
-
const formatter = new Intl.DateTimeFormat(undefined, format)
|
31
|
-
return formatter.format(new Date(targetTime))
|
32
|
-
} else {
|
33
|
-
return new Date(targetTime)
|
34
|
-
}
|
35
|
-
}
|
@@ -1,43 +0,0 @@
|
|
1
|
-
export type RelativeHourTimeParams = {
|
2
|
-
timeZone?: string
|
3
|
-
format?: 'timestamp' | 'date' | Intl.DateTimeFormatOptions
|
4
|
-
relativeHour?: number
|
5
|
-
relativeSeconds?: number
|
6
|
-
}
|
7
|
-
|
8
|
-
export const getRelativeHourTime = (params: RelativeHourTimeParams = {}): Date | number | string => {
|
9
|
-
const { relativeHour = 0, relativeSeconds = 0, timeZone, format } = params
|
10
|
-
|
11
|
-
const now = new Date()
|
12
|
-
let currentDate: Date
|
13
|
-
|
14
|
-
if (timeZone) {
|
15
|
-
const options: Intl.DateTimeFormatOptions = { timeZone }
|
16
|
-
const currentDateISOString = now.toLocaleString('en-US', options).split(',')[0]
|
17
|
-
currentDate = new Date(currentDateISOString)
|
18
|
-
} else {
|
19
|
-
currentDate = now
|
20
|
-
}
|
21
|
-
|
22
|
-
const startOfHour = new Date(
|
23
|
-
currentDate.getFullYear(),
|
24
|
-
currentDate.getMonth(),
|
25
|
-
currentDate.getDate(),
|
26
|
-
currentDate.getHours(),
|
27
|
-
0,
|
28
|
-
0,
|
29
|
-
0
|
30
|
-
)
|
31
|
-
const targetTime = startOfHour.getTime() + relativeHour * 60 * 60 * 1000 + relativeSeconds * 1000
|
32
|
-
|
33
|
-
if (format === 'date') {
|
34
|
-
return new Date(targetTime)
|
35
|
-
} else if (format === 'timestamp') {
|
36
|
-
return targetTime
|
37
|
-
} else if (format) {
|
38
|
-
const formatter = new Intl.DateTimeFormat(undefined, format)
|
39
|
-
return formatter.format(new Date(targetTime))
|
40
|
-
} else {
|
41
|
-
return new Date(targetTime)
|
42
|
-
}
|
43
|
-
}
|
@@ -1 +0,0 @@
|
|
1
|
-
export * from './registry'
|
@@ -1,43 +0,0 @@
|
|
1
|
-
export type RelativeMinuteTimeParams = {
|
2
|
-
timeZone?: string
|
3
|
-
format?: 'timestamp' | 'date' | Intl.DateTimeFormatOptions
|
4
|
-
relativeMinutes?: number
|
5
|
-
relativeSeconds?: number
|
6
|
-
}
|
7
|
-
|
8
|
-
export const getRelativeMinuteTime = (params: RelativeMinuteTimeParams = {}): Date | number | string => {
|
9
|
-
const { relativeMinutes = 0, relativeSeconds = 0, timeZone, format } = params
|
10
|
-
|
11
|
-
const now = new Date()
|
12
|
-
let currentDate: Date
|
13
|
-
|
14
|
-
if (timeZone) {
|
15
|
-
const options: Intl.DateTimeFormatOptions = { timeZone }
|
16
|
-
const currentDateISOString = now.toLocaleString('en-US', options).split(',')[0]
|
17
|
-
currentDate = new Date(currentDateISOString)
|
18
|
-
} else {
|
19
|
-
currentDate = now
|
20
|
-
}
|
21
|
-
|
22
|
-
const startOfMinute = new Date(
|
23
|
-
currentDate.getFullYear(),
|
24
|
-
currentDate.getMonth(),
|
25
|
-
currentDate.getDate(),
|
26
|
-
currentDate.getHours(),
|
27
|
-
currentDate.getMinutes(),
|
28
|
-
0,
|
29
|
-
0
|
30
|
-
)
|
31
|
-
const targetTime = startOfMinute.getTime() + relativeMinutes * 60 * 1000 + relativeSeconds * 1000
|
32
|
-
|
33
|
-
if (format === 'date') {
|
34
|
-
return new Date(targetTime)
|
35
|
-
} else if (format === 'timestamp') {
|
36
|
-
return targetTime
|
37
|
-
} else if (format) {
|
38
|
-
const formatter = new Intl.DateTimeFormat(undefined, format)
|
39
|
-
return formatter.format(new Date(targetTime))
|
40
|
-
} else {
|
41
|
-
return new Date(targetTime)
|
42
|
-
}
|
43
|
-
}
|
@@ -1,38 +0,0 @@
|
|
1
|
-
export type RelativeMonthDateParams = {
|
2
|
-
timeZone?: string
|
3
|
-
format?: 'timestamp' | 'date' | Intl.DateTimeFormatOptions
|
4
|
-
relativeMonths?: number
|
5
|
-
relativeDates?: number
|
6
|
-
}
|
7
|
-
|
8
|
-
export const getRelativeMonthDate = (params: RelativeMonthDateParams = {}): Date | number | string => {
|
9
|
-
const { relativeMonths = 0, relativeDates = 0, timeZone, format } = params
|
10
|
-
|
11
|
-
const now = new Date()
|
12
|
-
let currentDate: Date
|
13
|
-
|
14
|
-
if (timeZone) {
|
15
|
-
const options: Intl.DateTimeFormatOptions = { timeZone }
|
16
|
-
const currentDateISOString = now.toLocaleString('en-US', options).split(',')[0]
|
17
|
-
currentDate = new Date(currentDateISOString)
|
18
|
-
} else {
|
19
|
-
currentDate = now
|
20
|
-
}
|
21
|
-
|
22
|
-
const targetMonth = currentDate.getMonth() + relativeMonths
|
23
|
-
const targetYear = currentDate.getFullYear() + Math.floor(targetMonth / 12)
|
24
|
-
const targetMonthRemainder = targetMonth % 12
|
25
|
-
|
26
|
-
const targetDate = new Date(targetYear, targetMonthRemainder, currentDate.getDate() + relativeDates)
|
27
|
-
|
28
|
-
if (format === 'date') {
|
29
|
-
return targetDate
|
30
|
-
} else if (format === 'timestamp') {
|
31
|
-
return targetDate.getTime()
|
32
|
-
} else if (format) {
|
33
|
-
const formatter = new Intl.DateTimeFormat(undefined, format)
|
34
|
-
return formatter.format(targetDate)
|
35
|
-
} else {
|
36
|
-
return targetDate
|
37
|
-
}
|
38
|
-
}
|
@@ -1,10 +0,0 @@
|
|
1
|
-
import { getRelativeTime } from './time-generator'
|
2
|
-
|
3
|
-
export const getCurrentTime = (
|
4
|
-
params: { timeZone?: string; format?: 'timestamp' | 'date' | Intl.DateTimeFormatOptions } = {}
|
5
|
-
): Date | number | string => {
|
6
|
-
return getRelativeTime({
|
7
|
-
...params,
|
8
|
-
relativeSeconds: 0
|
9
|
-
})
|
10
|
-
}
|
@@ -1,58 +0,0 @@
|
|
1
|
-
import { NOOP } from '../const'
|
2
|
-
import { ValueGeneratorFn } from '../types'
|
3
|
-
|
4
|
-
import { getCurrentTime } from './now-generator'
|
5
|
-
import { getToday } from './today-generator'
|
6
|
-
import { getRelativeDate } from './date-generator'
|
7
|
-
import { getRelativeWeekDate } from './week-date-generator'
|
8
|
-
import { getRelativeMonthDate } from './month-date-generator'
|
9
|
-
import { getRelativeYearDate } from './year-date-generator'
|
10
|
-
import { getRelativeTime } from './time-generator'
|
11
|
-
import { getRelativeMinuteTime } from './minute-time-generator'
|
12
|
-
import { getRelativeHourTime } from './hour-time-generator'
|
13
|
-
|
14
|
-
var VALUE_GENERATORS: { [name: string]: ValueGeneratorFn } = {
|
15
|
-
now: getCurrentTime,
|
16
|
-
today: getToday,
|
17
|
-
date: getRelativeDate,
|
18
|
-
time: getRelativeTime,
|
19
|
-
getCurrentTime,
|
20
|
-
getToday,
|
21
|
-
getRelativeDate,
|
22
|
-
getRelativeWeekDate,
|
23
|
-
getRelativeMonthDate,
|
24
|
-
getRelativeYearDate,
|
25
|
-
getRelativeMinuteTime,
|
26
|
-
getRelativeHourTime
|
27
|
-
}
|
28
|
-
|
29
|
-
export function registerValueGenerator(name: string, generator: ValueGeneratorFn) {
|
30
|
-
VALUE_GENERATORS[name] = generator
|
31
|
-
}
|
32
|
-
|
33
|
-
export function unregisterValueGenerator(name: string) {
|
34
|
-
delete VALUE_GENERATORS[name]
|
35
|
-
}
|
36
|
-
|
37
|
-
export function getValueGenerators() {
|
38
|
-
return { ...VALUE_GENERATORS }
|
39
|
-
}
|
40
|
-
|
41
|
-
export function getValueGenerator(name: string) {
|
42
|
-
return VALUE_GENERATORS[name] || NOOP
|
43
|
-
}
|
44
|
-
|
45
|
-
export function getDefaultValue(parameter: { name: string; params?: any[] } | Function | any, binder?: any) {
|
46
|
-
if (typeof parameter == 'function') {
|
47
|
-
return parameter.call(binder || null)
|
48
|
-
} else if (typeof parameter == 'object') {
|
49
|
-
const { name, params } = parameter
|
50
|
-
const generator = getValueGenerator(name)
|
51
|
-
|
52
|
-
if (generator !== NOOP) {
|
53
|
-
return generator.call(binder || null, params)
|
54
|
-
}
|
55
|
-
}
|
56
|
-
|
57
|
-
return parameter
|
58
|
-
}
|
@@ -1,33 +0,0 @@
|
|
1
|
-
export type RelativeTimeParams = {
|
2
|
-
relativeSeconds?: number
|
3
|
-
timeZone?: string
|
4
|
-
format?: 'timestamp' | 'date' | Intl.DateTimeFormatOptions
|
5
|
-
}
|
6
|
-
|
7
|
-
export const getRelativeTime = (params: RelativeTimeParams = {}): string | number | Date => {
|
8
|
-
const { relativeSeconds = 0, timeZone, format } = params
|
9
|
-
|
10
|
-
const now = new Date()
|
11
|
-
|
12
|
-
let currentDate: Date
|
13
|
-
if (timeZone) {
|
14
|
-
const options = { timeZone }
|
15
|
-
const currentDateISOString = now.toLocaleString('en-US', options).split(',')[0]
|
16
|
-
currentDate = new Date(currentDateISOString)
|
17
|
-
} else {
|
18
|
-
currentDate = now
|
19
|
-
}
|
20
|
-
|
21
|
-
const targetTime = currentDate.getTime() + relativeSeconds * 1000
|
22
|
-
|
23
|
-
if (format === 'date') {
|
24
|
-
return new Date(targetTime)
|
25
|
-
} else if (format === 'timestamp') {
|
26
|
-
return targetTime
|
27
|
-
} else if (format) {
|
28
|
-
const formatter = new Intl.DateTimeFormat(undefined, format)
|
29
|
-
return formatter.format(new Date(targetTime))
|
30
|
-
} else {
|
31
|
-
return targetTime
|
32
|
-
}
|
33
|
-
}
|
@@ -1,10 +0,0 @@
|
|
1
|
-
import { getRelativeDate } from './date-generator'
|
2
|
-
|
3
|
-
export const getToday = (
|
4
|
-
params: { timeZone?: string; format?: 'timestamp' | 'date' | Intl.DateTimeFormatOptions } = {}
|
5
|
-
): Date | number | string => {
|
6
|
-
return getRelativeDate({
|
7
|
-
...params,
|
8
|
-
relativeDate: 0
|
9
|
-
})
|
10
|
-
}
|
@@ -1,40 +0,0 @@
|
|
1
|
-
export type RelativeWeekDateParams = {
|
2
|
-
timeZone?: string
|
3
|
-
format?: 'timestamp' | 'date' | Intl.DateTimeFormatOptions
|
4
|
-
relativeWeeks?: number
|
5
|
-
relativeDates?: number
|
6
|
-
}
|
7
|
-
|
8
|
-
export const getRelativeWeekDate = (params: RelativeWeekDateParams = {}): Date | number | string => {
|
9
|
-
const { relativeWeeks = 0, relativeDates = 0, timeZone, format } = params
|
10
|
-
|
11
|
-
const now = new Date()
|
12
|
-
let currentDate: Date
|
13
|
-
|
14
|
-
if (timeZone) {
|
15
|
-
const options: Intl.DateTimeFormatOptions = { timeZone }
|
16
|
-
const currentDateISOString = now.toLocaleString('en-US', options).split(',')[0]
|
17
|
-
currentDate = new Date(currentDateISOString)
|
18
|
-
} else {
|
19
|
-
currentDate = now
|
20
|
-
}
|
21
|
-
|
22
|
-
const startOfWeek = new Date(
|
23
|
-
currentDate.getFullYear(),
|
24
|
-
currentDate.getMonth(),
|
25
|
-
currentDate.getDate() - currentDate.getDay() + 1
|
26
|
-
)
|
27
|
-
const targetDate =
|
28
|
-
startOfWeek.getTime() + relativeWeeks * 7 * 24 * 60 * 60 * 1000 + relativeDates * 24 * 60 * 60 * 1000
|
29
|
-
|
30
|
-
if (format === 'date') {
|
31
|
-
return new Date(targetDate)
|
32
|
-
} else if (format === 'timestamp') {
|
33
|
-
return targetDate
|
34
|
-
} else if (format) {
|
35
|
-
const formatter = new Intl.DateTimeFormat(undefined, format)
|
36
|
-
return formatter.format(new Date(targetDate))
|
37
|
-
} else {
|
38
|
-
return targetDate
|
39
|
-
}
|
40
|
-
}
|
@@ -1,36 +0,0 @@
|
|
1
|
-
export type RelativeYearDateParams = {
|
2
|
-
timeZone?: string
|
3
|
-
format?: 'timestamp' | 'date' | Intl.DateTimeFormatOptions
|
4
|
-
relativeYears?: number
|
5
|
-
relativeDates?: number
|
6
|
-
}
|
7
|
-
|
8
|
-
export const getRelativeYearDate = (params: RelativeYearDateParams = {}): Date | number | string => {
|
9
|
-
const { relativeYears = 0, relativeDates = 0, timeZone, format } = params
|
10
|
-
|
11
|
-
const now = new Date()
|
12
|
-
let currentDate: Date
|
13
|
-
|
14
|
-
if (timeZone) {
|
15
|
-
const options: Intl.DateTimeFormatOptions = { timeZone }
|
16
|
-
const currentDateISOString = now.toLocaleString('en-US', options).split(',')[0]
|
17
|
-
currentDate = new Date(currentDateISOString)
|
18
|
-
} else {
|
19
|
-
currentDate = now
|
20
|
-
}
|
21
|
-
|
22
|
-
const targetYear = currentDate.getFullYear() + relativeYears
|
23
|
-
|
24
|
-
const targetDate = new Date(targetYear, currentDate.getMonth(), currentDate.getDate() + relativeDates)
|
25
|
-
|
26
|
-
if (format === 'date') {
|
27
|
-
return targetDate
|
28
|
-
} else if (format === 'timestamp') {
|
29
|
-
return targetDate.getTime()
|
30
|
-
} else if (format) {
|
31
|
-
const formatter = new Intl.DateTimeFormat(undefined, format)
|
32
|
-
return formatter.format(targetDate)
|
33
|
-
} else {
|
34
|
-
return targetDate
|
35
|
-
}
|
36
|
-
}
|