@vuu-ui/vuu-utils 4.0.0-alpha.2 → 4.0.0-alpha.20

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.
Files changed (41) hide show
  1. package/package.json +8 -7
  2. package/src/array-utils.js +17 -5
  3. package/src/column-utils.js +21 -6
  4. package/src/component-registry.js +2 -1
  5. package/src/data-utils.js +1 -0
  6. package/src/datasource/BaseDataSource.js +5 -3
  7. package/src/date/EpochTimestamp.js +85 -0
  8. package/src/date/date-utils.js +50 -18
  9. package/src/date/dateTimePattern.js +33 -5
  10. package/src/date/formatter.js +54 -16
  11. package/src/date/index.js +5 -2
  12. package/src/date/temporal.js +131 -0
  13. package/src/date/time-zone.js +56 -0
  14. package/src/filters/filter-utils.js +12 -6
  15. package/src/filters/filterAsQuery.js +107 -45
  16. package/src/filters/index.js +1 -0
  17. package/src/filters/temporal-cell-filter.js +63 -0
  18. package/src/form-utils.js +44 -6
  19. package/src/formatting-utils.js +46 -25
  20. package/src/html-utils.js +35 -1
  21. package/src/keyset.js +15 -9
  22. package/src/useResizeObserver.js +3 -3
  23. package/types/array-utils.d.ts +7 -4
  24. package/types/column-utils.d.ts +43 -40
  25. package/types/component-registry.d.ts +4 -4
  26. package/types/datasource/BaseDataSource.d.ts +2 -2
  27. package/types/date/EpochTimestamp.d.ts +66 -0
  28. package/types/date/date-utils.d.ts +34 -9
  29. package/types/date/dateTimePattern.d.ts +20 -2
  30. package/types/date/formatter.d.ts +26 -1
  31. package/types/date/index.d.ts +6 -2
  32. package/types/date/temporal.d.ts +68 -0
  33. package/types/date/time-zone.d.ts +52 -0
  34. package/types/filters/filter-utils.d.ts +6 -1
  35. package/types/filters/filterAsQuery.d.ts +41 -0
  36. package/types/filters/index.d.ts +1 -0
  37. package/types/filters/temporal-cell-filter.d.ts +27 -0
  38. package/types/form-utils.d.ts +19 -0
  39. package/types/formatting-utils.d.ts +23 -1
  40. package/types/html-utils.d.ts +16 -0
  41. package/types/keyset.d.ts +11 -1
package/src/html-utils.js CHANGED
@@ -81,6 +81,40 @@ function getScrollbarSize() {
81
81
  }
82
82
  return size;
83
83
  }
84
+ const DEFAULT_MAX_SCROLL_HEIGHT = 33000000;
85
+ const MAX_PROBE_HEIGHT = 2 ** 26;
86
+ const maxScrollHeightByDevicePixelRatio = new Map();
87
+ function getMaxScrollHeight(doc = globalThis.document) {
88
+ if (doc?.body === void 0 || null === doc.body) return DEFAULT_MAX_SCROLL_HEIGHT;
89
+ const devicePixelRatio = doc.defaultView?.devicePixelRatio ?? 1;
90
+ const cachedValue = maxScrollHeightByDevicePixelRatio.get(devicePixelRatio);
91
+ if (void 0 !== cachedValue) return cachedValue;
92
+ const outer = doc.createElement("div");
93
+ outer.style.cssText = "position:absolute;top:-200px;left:-200px;width:50px;height:50px;overflow:scroll;visibility:hidden;";
94
+ const inner = doc.createElement("div");
95
+ inner.style.width = "1px";
96
+ outer.appendChild(inner);
97
+ doc.body.appendChild(outer);
98
+ const isHonoured = (height)=>{
99
+ inner.style.height = `${height}px`;
100
+ return outer.scrollHeight >= height - 1;
101
+ };
102
+ let lo = 0;
103
+ let hi = MAX_PROBE_HEIGHT;
104
+ while(hi - lo > 1){
105
+ const mid = Math.floor((lo + hi) / 2);
106
+ if (isHonoured(mid)) lo = mid;
107
+ else hi = mid;
108
+ }
109
+ inner.style.height = `${lo}px`;
110
+ const maxScrollHeight = Math.min(lo, outer.scrollHeight);
111
+ outer.remove();
112
+ if (maxScrollHeight > 0) {
113
+ maxScrollHeightByDevicePixelRatio.set(devicePixelRatio, maxScrollHeight);
114
+ return maxScrollHeight;
115
+ }
116
+ return DEFAULT_MAX_SCROLL_HEIGHT;
117
+ }
84
118
  const dispatchMouseEvent = (el, type)=>{
85
119
  const evt = new MouseEvent(type, {
86
120
  view: window,
@@ -105,4 +139,4 @@ const dispatchCustomEvent = (el, type)=>{
105
139
  });
106
140
  el.dispatchEvent(evt);
107
141
  };
108
- export { createEl, dispatchCustomEvent, dispatchKeyboardEvent, dispatchMouseEvent, focusFirstFocusableElement, getClosest, getClosestIndexItem, getElementByDataIndex, getElementDataIndex, getFocusableElement, getScrollbarSize, hasOpenOptionList, isDateInput, isInputElement, isSelectableElement, queryClosest };
142
+ export { DEFAULT_MAX_SCROLL_HEIGHT, createEl, dispatchCustomEvent, dispatchKeyboardEvent, dispatchMouseEvent, focusFirstFocusableElement, getClosest, getClosestIndexItem, getElementByDataIndex, getElementDataIndex, getFocusableElement, getMaxScrollHeight, getScrollbarSize, hasOpenOptionList, isDateInput, isInputElement, isSelectableElement, queryClosest };
package/src/keyset.js CHANGED
@@ -1,10 +1,14 @@
1
1
  const EMPTY = [];
2
2
  class KeySet {
3
3
  keys = new Map();
4
+ freeKeys = [];
4
5
  nextKeyValue = 0;
5
6
  range;
6
7
  constructor(range){
7
- this.range = range;
8
+ this.range = {
9
+ from: range.from,
10
+ to: range.to
11
+ };
8
12
  this.init(range);
9
13
  }
10
14
  next(free = EMPTY) {
@@ -13,6 +17,7 @@ class KeySet {
13
17
  }
14
18
  init({ from, to }) {
15
19
  this.keys.clear();
20
+ this.freeKeys.length = 0;
16
21
  this.nextKeyValue = 0;
17
22
  for(let rowIndex = from; rowIndex < to; rowIndex++){
18
23
  const nextKeyValue = this.next();
@@ -20,23 +25,24 @@ class KeySet {
20
25
  }
21
26
  return true;
22
27
  }
23
- reset(range) {
24
- const { from, to } = range;
25
- const newSize = to - from;
26
- const currentSize = this.range.to - this.range.from;
27
- this.range = range;
28
- if (currentSize > newSize) return this.init(range);
29
- const freeKeys = [];
28
+ reset({ from, to }) {
29
+ this.range = {
30
+ from,
31
+ to
32
+ };
33
+ const { freeKeys } = this;
30
34
  this.keys.forEach((keyValue, rowIndex)=>{
31
35
  if (rowIndex < from || rowIndex >= to) {
32
36
  freeKeys.push(keyValue);
33
37
  this.keys.delete(rowIndex);
34
38
  }
35
39
  });
40
+ let freeKeyIndex = 0;
36
41
  for(let rowIndex = from; rowIndex < to; rowIndex++)if (!this.keys.has(rowIndex)) {
37
- const nextKeyValue = this.next(freeKeys);
42
+ const nextKeyValue = freeKeyIndex < freeKeys.length ? freeKeys[freeKeyIndex++] : this.nextKeyValue++;
38
43
  this.keys.set(rowIndex, nextKeyValue);
39
44
  }
45
+ if (freeKeyIndex > 0) freeKeys.splice(0, freeKeyIndex);
40
46
  return false;
41
47
  }
42
48
  keyFor(rowIndex) {
@@ -29,7 +29,7 @@ const getTargetSize = (element, size, dimension)=>{
29
29
  return 0;
30
30
  }
31
31
  };
32
- const resizeObserver = new ResizeObserver((entries)=>{
32
+ const resizeObserver = "u" < typeof ResizeObserver ? void 0 : new ResizeObserver((entries)=>{
33
33
  for (const entry of entries){
34
34
  const { target, borderBoxSize, contentBoxSize } = entry;
35
35
  const observedTarget = observedMap.get(target);
@@ -81,7 +81,7 @@ function useResizeObserver(ref, dimensions, onResize, reportInitialSize = false)
81
81
  if (observedTarget) {
82
82
  const measurements = measure(target);
83
83
  observedTarget.measurements = measurements;
84
- resizeObserver.observe(target);
84
+ resizeObserver?.observe(target);
85
85
  if (reportInitialSize) onResize(measurements);
86
86
  } else console.log("%cuseResizeObserver an target expected to be under observation wa snot found. This warrants investigation", "font-weight:bold; color:red;");
87
87
  }
@@ -93,7 +93,7 @@ function useResizeObserver(ref, dimensions, onResize, reportInitialSize = false)
93
93
  }
94
94
  return ()=>{
95
95
  if (target && observedMap.has(target)) {
96
- resizeObserver.unobserve(target);
96
+ resizeObserver?.unobserve(target);
97
97
  observedMap.delete(target);
98
98
  }
99
99
  };
@@ -1,11 +1,14 @@
1
1
  export type PartitionTest<T> = (value: T, index: number) => boolean;
2
+ export type ItemComparator<T> = (firstItem: T, secondItem: T) => boolean;
2
3
  export declare function partition<T>(array: T[], test: PartitionTest<T>, pass?: T[], fail?: T[]): [T[], T[]];
3
- export declare function itemsChanged<T = unknown>(currentItems: T[], newItems: T[], identityProperty?: string): boolean;
4
- export declare function itemsOrOrderChanged<T = unknown>(currentItems: T[], newItems: T[], identityProperty?: string): boolean;
4
+ export declare function itemsChanged<T = unknown>(currentItems: readonly T[], newItems: readonly T[], identityProperty?: string): boolean;
5
+ export declare function itemsOrOrderChanged<T = unknown>(currentItems: readonly T[], newItems: readonly T[], identityProperty?: string): boolean;
5
6
  export declare const moveItemDeprecated: <T = unknown>(items: T[], item: T, moveTo: number) => T[];
6
7
  export declare const moveItem: <T = unknown>(items: T[], fromIndex: number, toIndex: number) => T[];
7
- export declare const getAddedItems: <T>(values: undefined | T[], newValues: T[]) => T[];
8
- export declare const getMissingItems: <T, I>(sourceItems: T[], items: I[], identity: (s: T) => I) => I[];
8
+ export declare const getAddedItems: <T>(currentItems: undefined | readonly T[], newItems: readonly T[], compareItems?: ItemComparator<T>) => readonly T[];
9
+ export declare const getRemovedItems: <T>(currentItems: readonly T[], newItems: undefined | readonly T[], compareItems?: ItemComparator<T>) => readonly T[];
10
+ export declare const containsSubsetOfItems: <T>(allItems: readonly T[], comparedItems: readonly T[]) => boolean;
11
+ export declare const getMissingItems: <T, I>(sourceItems: readonly T[], items: readonly I[], identity: (s: T) => I) => I[];
9
12
  /**
10
13
  * Given an ordered list of item names, return items in same order
11
14
  */
@@ -1,8 +1,8 @@
1
1
  import type { DataSourceRow, DataValueDescriptor, DataValueType, DataValueTypeSimple, DateTimeDataValueDescriptor, SchemaColumn, TableSchema, TimeDataValueDescriptor } from "@vuu-ui/vuu-data-types";
2
2
  import type { VuuAggType, VuuAggregation, VuuColumnDataType, VuuDataRowDto, VuuGroupBy, VuuSort } from "@vuu-ui/vuu-protocol-types";
3
3
  import type { ColumnAlignment, ColumnDescriptor, ColumnLayout, ColumnTypeFormatting, ColumnTypeRendering, ColumnTypeWithValidationRules, DataRow, DataValueTypeDescriptor, DefaultColumnConfiguration, GroupColumnDescriptor, LookupRenderer, MappedValueTypeRenderer, PinLocation, RuntimeColumnDescriptor, TableCellRendererProps, TableConfig, TableHeadings, ValueListRenderer } from "@vuu-ui/vuu-table-types";
4
- import type { CSSProperties } from "react";
5
4
  import type { TableModel } from "@vuu-ui/vuu-table";
5
+ import type { CSSProperties } from "react";
6
6
  /**
7
7
  * ColumnMap provides a lookup of the index position of a data item within a row
8
8
  * by column name.
@@ -33,13 +33,48 @@ export type CalculatedColumn = {
33
33
  };
34
34
  export declare const isVuuColumnDataType: (value: string | undefined | null) => value is VuuColumnDataType;
35
35
  export declare const fromServerDataType: (serverDataType: VuuColumnDataType) => DataValueTypeSimple;
36
+ /**
37
+ * Returns true if serverDataType is epochtimestampnano. Note: prefer
38
+ * getTemporalInfo, which describes encoding, kind and time zone.
39
+ */
36
40
  export declare const isNanoTimestampColumn: ({ serverDataType, }: DataValueDescriptor) => boolean;
37
- export declare const isTimestampColumn: (column: ColumnDescriptor) => boolean;
38
- export declare const isNumericColumn: ({ serverDataType, type }: ColumnDescriptor) => boolean;
39
- export declare const isDateTimeDataType: (column: ColumnDescriptor) => column is DateTimeDataValueDescriptor;
40
- export declare const isTimeDataType: (column: ColumnDescriptor) => column is TimeDataValueDescriptor;
41
- export declare const isDateTimeDataValue: (column: ColumnDescriptor) => boolean;
42
- export declare const isTimeDataValue: (column?: ColumnDescriptor) => column is TimeDataValueDescriptor;
41
+ /**
42
+ * Returns true if serverDataType is epochtimestamp or epochtimestampnano.
43
+ * Note: this does not recognise legacy columns (long with a date/time type),
44
+ * use isTemporalColumn for that.
45
+ */
46
+ export declare const isTimestampColumn: (column: DataValueDescriptor) => boolean;
47
+ /**
48
+ * Returns true for any column holding a temporal value, see getTemporalInfo.
49
+ */
50
+ export declare const isTemporalColumn: (column?: DataValueDescriptor) => boolean;
51
+ /**
52
+ * Numeric columns, excluding those that hold temporal values.
53
+ */
54
+ export declare const isNumericColumn: (column: ColumnDescriptor) => boolean;
55
+ /**
56
+ * Checks the 'type' only, returns true for 'date/time' (or 'date').
57
+ * @deprecated use getTemporalInfo or isDateTimeDataValue
58
+ */
59
+ export declare const isDateTimeDataType: (column: DataValueDescriptor) => column is DateTimeDataValueDescriptor;
60
+ /**
61
+ * Checks the 'type' only, returns true for 'time'.
62
+ * @deprecated use getTemporalInfo or isTimeDataValue
63
+ */
64
+ export declare const isTimeDataType: (column: DataValueDescriptor) => column is TimeDataValueDescriptor;
65
+ /**
66
+ * Temporal value of kind 'datetime' or 'date' (i.e has a meaningful date component)
67
+ */
68
+ export declare const isDateTimeDataValue: (column?: DataValueDescriptor) => boolean;
69
+ /**
70
+ * Temporal value of kind 'time' (time of day)
71
+ */
72
+ export declare const isTimeDataValue: (column?: DataValueDescriptor) => column is TimeDataValueDescriptor;
73
+ /**
74
+ * A time column is edited/filtered with millisecond precision if its
75
+ * formatting pattern includes milliseconds.
76
+ */
77
+ export declare const isTimeDataValueWithMilliseconds: (column?: ColumnDescriptor) => column is TimeDataValueDescriptor;
43
78
  export declare const isPinned: (column: ColumnDescriptor) => boolean;
44
79
  export declare const hasHeadings: (column: ColumnDescriptor) => boolean;
45
80
  export declare const isResizing: (column: RuntimeColumnDescriptor) => boolean | undefined;
@@ -171,39 +206,7 @@ export declare const setCalculatedColumnType: (column: ColumnDescriptor, serverD
171
206
  export declare const setCalculatedColumnExpression: (column: ColumnDescriptor, expression: string) => ColumnDescriptor;
172
207
  export declare const moveColumnTo: (columns: ColumnDescriptor[], column: ColumnDescriptor, newIndex: number) => ColumnDescriptor[];
173
208
  export declare function replaceColumn<C extends ColumnDescriptor = RuntimeColumnDescriptor>(columns: readonly C[], column: C): C[];
174
- export declare const applyDefaultColumnConfig: ({ columns: columnsProp, table }: TableSchema, getDefaultColumnConfig?: DefaultColumnConfiguration, includeVuuDefaultColumns?: boolean) => (SchemaColumn | {
175
- aggregate?: VuuAggType;
176
- align?: ColumnAlignment;
177
- allowColumnHeaderMenu?: false;
178
- className?: string;
179
- colHeaderContentRenderer?: string;
180
- colHeaderLabelRenderer?: string;
181
- exportFormatter?: (value: unknown) => string;
182
- flex?: number;
183
- getIcon?: (row: DataRow) => string | undefined;
184
- groupable?: boolean;
185
- heading?: string[];
186
- hidden?: boolean;
187
- isSystemColumn?: boolean;
188
- locked?: Exclude<PinLocation, "left"> | false;
189
- maxWidth?: number;
190
- minWidth?: number;
191
- pin?: PinLocation | false;
192
- removeable?: boolean;
193
- resizeable?: boolean;
194
- selected?: boolean;
195
- sortable?: boolean;
196
- source?: "client" | "server";
197
- status?: import("@salt-ds/core").ValidationStatus;
198
- width?: number;
199
- editableBulk?: import("@vuu-ui/vuu-data-types").BulkEdit;
200
- label?: string;
201
- required?: boolean;
202
- type?: DataValueType;
203
- editable?: import("@vuu-ui/vuu-data-types").DataEditable | undefined;
204
- name: string;
205
- serverDataType: VuuColumnDataType;
206
- })[] | readonly SchemaColumn[];
209
+ export declare const applyDefaultColumnConfig: ({ columns: columnsProp, table }: TableSchema, getDefaultColumnConfig?: DefaultColumnConfiguration, includeVuuDefaultColumns?: boolean) => readonly SchemaColumn[];
207
210
  export type columnOptions = {
208
211
  availableWidth?: number;
209
212
  columnLayout?: ColumnLayout;
@@ -1,7 +1,7 @@
1
- import { EditRuleValidator } from "@vuu-ui/vuu-data-types";
2
- import { VuuColumnDataType } from "@vuu-ui/vuu-protocol-types";
3
- import { ColumnDescriptor, ColumnDescriptorCustomRenderer, ColumnTypeRendering, DataRow, HeaderCellProps, TableCellRendererProps } from "@vuu-ui/vuu-table-types";
4
- import { FunctionComponent as FC, HTMLAttributes } from "react";
1
+ import type { EditRuleValidator } from "@vuu-ui/vuu-data-types";
2
+ import type { VuuColumnDataType } from "@vuu-ui/vuu-protocol-types";
3
+ import type { ColumnDescriptor, ColumnDescriptorCustomRenderer, ColumnTypeRendering, DataRow, HeaderCellProps, TableCellRendererProps } from "@vuu-ui/vuu-table-types";
4
+ import type { FunctionComponent as FC, HTMLAttributes } from "react";
5
5
  export interface CellConfigPanelProps extends HTMLAttributes<HTMLDivElement> {
6
6
  onConfigChange: () => void;
7
7
  }
@@ -1,4 +1,4 @@
1
- import type { DataSource, DataSourceConstructorProps, DataSourceEvents, DataSourceFilter, DataSourceSubscribeCallback, DataSourceSubscribeProps, DataSourceSuspenseProps, WithBaseFilter, WithFullConfig } from "@vuu-ui/vuu-data-types";
1
+ import type { DataSource, DataSourceConstructorProps, DataSourceEvents, DataSourceFilter, DataSourceSubscribeCallback, DataSourceSubscribeProps, DataSourceSuspenseProps, SetFilterOptions, WithBaseFilter, WithFullConfig } from "@vuu-ui/vuu-data-types";
2
2
  import { LinkDescriptorWithLabel, VuuAggregation, VuuRange, VuuSort } from "@vuu-ui/vuu-protocol-types";
3
3
  import { EventEmitter } from "../event-emitter";
4
4
  import { Range } from "../range-utils";
@@ -28,7 +28,7 @@ export declare abstract class BaseDataSource extends EventEmitter<DataSourceEven
28
28
  set columns(columns: string[]);
29
29
  get filter(): DataSourceFilter;
30
30
  set filter(filter: DataSourceFilter);
31
- setFilter(filter: Filter): void;
31
+ setFilter(filter: Filter, options?: SetFilterOptions): void;
32
32
  clearFilter(): void;
33
33
  get isAwaitingConfirmationOfConfigChange(): boolean;
34
34
  protected confirmConfigChange(): void;
@@ -0,0 +1,66 @@
1
+ import { type DateTimeFields, type TimeZoneSpec } from "./time-zone";
2
+ /**
3
+ * How a temporal value is encoded on the wire (i.e in rows received from,
4
+ * and values sent to, the server).
5
+ * - epochMillis, a number (epochtimestamp, or legacy long with a date/time type)
6
+ * - epochNanos, a string of digits (epochtimestampnano). Nanosecond values
7
+ * cannot be represented safely as JavaScript numbers. A bigint is also
8
+ * accepted where values are generated locally.
9
+ */
10
+ export type TemporalEncoding = "epochMillis" | "epochNanos";
11
+ /**
12
+ * A timestamp with nanosecond precision. Internally represented as epoch
13
+ * millis (floored) plus nanos within the milli, so the common millisecond
14
+ * case requires no bigint arithmetic.
15
+ *
16
+ * Note: an empty value (null, undefined, '', 0, '0') is treated as 'no value'
17
+ * by fromWire. The Vuu server uses 0 to represent an unset timestamp, so
18
+ * the epoch itself (1970-01-01T00:00:00.000Z) cannot be represented.
19
+ */
20
+ export declare class EpochTimestamp {
21
+ readonly epochMillis: number;
22
+ /** nanoseconds within the millisecond, 0 - 999,999 */
23
+ readonly subMilliNanos: number;
24
+ private constructor();
25
+ static fromMillis(epochMillis: number, subMilliNanos?: number): EpochTimestamp;
26
+ static fromNanos(epochNanos: bigint | string | number): EpochTimestamp;
27
+ static fromDate(date: Date): EpochTimestamp;
28
+ static fromFields(fields: Partial<DateTimeFields> & Pick<DateTimeFields, "year" | "month" | "day">, timeZone?: TimeZoneSpec, subMilliNanos?: number): EpochTimestamp;
29
+ /**
30
+ * Returns true if value represents 'no value'.
31
+ */
32
+ static isEmpty(value: unknown): value is "" | "0" | 0 | 0n | null | undefined;
33
+ /**
34
+ * Decode a value as received from the server, or held in a filter,
35
+ * in the given encoding. Returns undefined for an empty or invalid value,
36
+ * including a value outside the range of a JavaScript Date (e.g. a nanos
37
+ * value decoded as millis).
38
+ */
39
+ static fromWire(value: unknown, encoding: TemporalEncoding): EpochTimestamp | undefined;
40
+ private static decode;
41
+ get epochNanos(): bigint;
42
+ toDate(): Date;
43
+ /**
44
+ * Fraction of second, truncated to the requested number of digits
45
+ */
46
+ fractionalSecond(digits: number): string;
47
+ getFields(timeZone?: TimeZoneSpec): DateTimeFields;
48
+ /**
49
+ * Encode for the wire. epochMillis => number, epochNanos => string
50
+ */
51
+ toWire(encoding: "epochMillis"): number;
52
+ toWire(encoding: "epochNanos"): string;
53
+ toWire(encoding: TemporalEncoding): number | string;
54
+ /**
55
+ * Encode as a literal in a filter query (never quoted)
56
+ */
57
+ toLiteral(encoding: TemporalEncoding): string;
58
+ /**
59
+ * Add a number of the smallest unit for the encoding, i.e 1 milli or 1 nano.
60
+ * Useful to convert inclusive to exclusive bounds.
61
+ */
62
+ addUnits(units: number, encoding: TemporalEncoding): EpochTimestamp;
63
+ compare(other: EpochTimestamp): number;
64
+ equals(other?: EpochTimestamp): boolean;
65
+ toString(): string;
66
+ }
@@ -5,35 +5,60 @@ export type zeroToFive = 0 | oneToFive;
5
5
  export type sixToNine = 6 | 7 | 8 | 9;
6
6
  export type zeroToNine = zeroToFive | sixToNine;
7
7
  export type oneToNine = oneToFive | sixToNine;
8
- export type TimeUnit = "hours" | "minutes" | "seconds";
8
+ export type TimeUnit = "hours" | "minutes" | "seconds" | "milliseconds";
9
9
  export type Hours = `${0 | 1}${zeroToNine}` | `2${0 | 1 | 2 | 3}`;
10
10
  export type Minutes = `${zeroToFive}${zeroToNine}`;
11
11
  export type Seconds = `${zeroToFive}${zeroToNine}`;
12
- export type TimeUnitValue<T extends TimeUnit> = T extends "hours" ? Hours : T extends "minutes" ? Minutes : Seconds;
12
+ export type Milliseconds = `${zeroToNine}${zeroToNine}${zeroToNine}`;
13
+ export type TimeUnitValue<T extends TimeUnit> = T extends "hours" ? Hours : T extends "minutes" ? Minutes : T extends "seconds" ? Seconds : Milliseconds;
13
14
  export type TimeString = `${number}${number}:${number}${number}:${number}${number}`;
15
+ /**
16
+ * A TimeString with millisecond precision, hh:mm:ss.SSS
17
+ */
18
+ export type TimeStringMillis = `${TimeString}.${number}${number}${number}`;
14
19
  type YYYY = `19${zeroToNine}${zeroToNine}` | `20${zeroToNine}${zeroToNine}`;
15
20
  type MM = `0${oneToNine}` | `1${0 | 1 | 2}`;
16
21
  type DD = `${0}${oneToNine}` | `${1 | 2}${zeroToNine}` | `3${0 | 1}`;
17
22
  export type DateStringISO = `${YYYY}-${MM}-${DD}`;
18
23
  export declare const zeroTime: TimeString;
24
+ export declare const zeroTimeMillis: TimeStringMillis;
19
25
  export declare const zeroTimeUnit: TimeUnitValue<TimeUnit>;
20
- export declare function incrementTimeUnitValue<T extends TimeUnit>(unit: T, value: TimeUnitValue<T>): TimeUnitValue<T> | Hours;
21
- export declare function decrementTimeUnitValue<T extends TimeUnit>(unit: T, value: TimeUnitValue<T>): TimeUnitValue<T> | Hours;
22
- export declare function updateTimeString<T extends TimeUnit>(timeString: TimeString, unit: T, value: TimeUnitValue<T>): TimeString;
26
+ export declare function incrementTimeUnitValue<T extends TimeUnit>(unit: T, value: TimeUnitValue<T>): TimeUnitValue<T>;
27
+ export declare function decrementTimeUnitValue<T extends TimeUnit>(unit: T, value: TimeUnitValue<T>): TimeUnitValue<T>;
28
+ export declare function updateTimeString<S extends TimeString | TimeStringMillis, T extends TimeUnit>(timeString: S, unit: T, value: TimeUnitValue<T>): S;
23
29
  export declare const isValidTimeString: (value: unknown) => value is TimeString;
30
+ export declare const isValidTimeStringMillis: (value: unknown) => value is TimeStringMillis;
31
+ /**
32
+ * Convert a valid TimeString or TimeStringMillis to the required precision.
33
+ * Milliseconds are added (as 000) or removed as necessary. Returns undefined
34
+ * if value is not a valid time.
35
+ */
36
+ export declare function normaliseTimeString(value: unknown, milliseconds: true): TimeStringMillis | undefined;
37
+ export declare function normaliseTimeString(value: unknown, milliseconds?: false): TimeString | undefined;
38
+ export declare function normaliseTimeString(value: unknown, milliseconds?: boolean): TimeString | TimeStringMillis | undefined;
24
39
  export declare function asTimeString(value: unknown, allowUndefined: false): TimeString;
25
40
  export declare function asTimeString(value: unknown, allowUndefined?: true): TimeString | undefined;
41
+ /**
42
+ * Millisecond precision equivalent of asTimeString. Accepts a TimeString,
43
+ * TimeStringMillis or a timestamp (millis since epoch, number or string).
44
+ */
45
+ export declare function asTimeStringMillis(value: unknown, allowUndefined: false): TimeStringMillis;
46
+ export declare function asTimeStringMillis(value: unknown, allowUndefined?: true): TimeStringMillis | undefined;
26
47
  export interface Time {
27
48
  hours: number;
28
49
  minutes: number;
29
50
  seconds: number;
51
+ milliseconds: number;
30
52
  asDate: (date?: Date | DateStringISO) => Date;
31
53
  }
32
- export declare function Time(timeString: TimeString): Time;
54
+ export declare function Time(timeString: TimeString | TimeStringMillis): Time;
33
55
  export declare namespace Time {
34
- export var millisToTimeString: (timestamp: number) => TimeString;
35
- var _a: (hours: number, minutes: number, seconds: number) => TimeString;
36
- export { _a as toString };
56
+ var millisToTimeString: (timestamp: number) => TimeString;
57
+ var millisToTimeStringMillis: (timestamp: number) => TimeStringMillis;
58
+ export { timeToString as toString };
37
59
  export var isDateInMillis: (dtInMillis: string | number) => boolean;
38
60
  }
61
+ declare function timeToString(hours: number, minutes: number, seconds: number): TimeString;
62
+ declare function timeToString(hours: number, minutes: number, seconds: number, milliseconds: number): TimeStringMillis;
63
+ declare function timeToString(hours: number, minutes: number, seconds: number, milliseconds?: number): TimeString | TimeStringMillis;
39
64
  export {};
@@ -1,8 +1,26 @@
1
- import { DateTimeDataValueDescriptor } from "@vuu-ui/vuu-data-types";
1
+ import type { DataValueDescriptor, DataValueType, DateTimeDataValueDescriptor } from "@vuu-ui/vuu-data-types";
2
+ import { type TemporalKind } from "./temporal";
2
3
  import { DateTimePattern } from "./types";
3
4
  export declare const defaultPatternsByType: {
4
5
  readonly time: "hh:mm:ss";
5
6
  readonly date: "dd.mm.yyyy";
6
7
  };
7
8
  export declare const fallbackDateTimePattern: DateTimePattern;
8
- export declare function dateTimePattern(type: DateTimeDataValueDescriptor["type"]): DateTimePattern;
9
+ export declare const defaultDateTimePatternByKind: Record<TemporalKind, DateTimePattern>;
10
+ /**
11
+ * Returns the DateTimePattern configured on the type (formatting.pattern), if
12
+ * there is one. Otherwise, the default pattern for the temporal kind. If kind
13
+ * is not provided, it is inferred from type name.
14
+ */
15
+ export declare function dateTimePattern(type?: DataValueType | DateTimeDataValueDescriptor["type"], kind?: TemporalKind | undefined): DateTimePattern;
16
+ /**
17
+ * Returns a copy of a temporal descriptor, with its type replaced so that the
18
+ * value is displayed (or edited) using the given pattern. The type name follows
19
+ * the pattern: 'date/time' if both date and time are specified, else 'date' or
20
+ * 'time'. Other formatting (e.g. timeZone, locale) is preserved. The descriptor
21
+ * is returned unchanged if no pattern is provided or the descriptor is not
22
+ * temporal.
23
+ * Use this to present a column differently in different contexts, e.g. a
24
+ * ColumnFilter using a different pattern to the Table.
25
+ */
26
+ export declare const withDateTimePattern: <T extends DataValueDescriptor>(descriptor: T, pattern?: DateTimePattern) => T;
@@ -1,9 +1,34 @@
1
1
  import { DateFormatter } from "@internationalized/date";
2
+ import type { FractionalSecondDigits } from "@vuu-ui/vuu-table-types";
3
+ import { EpochTimestamp } from "./EpochTimestamp";
4
+ import { type TimeZoneSpec } from "./time-zone";
2
5
  import { DateTimePattern } from "./types";
3
6
  type DateTimeFormatConfig = {
4
7
  locale: string;
5
8
  options: Intl.DateTimeFormatOptions;
6
9
  };
10
+ export interface DateTimeFormatOptions {
11
+ /**
12
+ * Number of sub-second digits to display, when pattern includes time. If
13
+ * not specified, 3 is used for the 'hh:mm:ss.ms' pattern, otherwise 0.
14
+ */
15
+ fractionalSecondDigits?: FractionalSecondDigits;
16
+ /**
17
+ * Override the locale implied by the pattern. Pattern then determines the
18
+ * style of each field, locale determines order and language.
19
+ */
20
+ locale?: string;
21
+ timeZone?: TimeZoneSpec;
22
+ }
23
+ type TimestampFormatter = (ts: EpochTimestamp) => string;
24
+ /**
25
+ * Create a formatter for EpochTimestamp values. This is the most general
26
+ * formatter, it supports nanosecond precision.
27
+ */
28
+ export declare function formatTimestamp({ date, time }: DateTimePattern, { fractionalSecondDigits, locale, timeZone, }?: DateTimeFormatOptions): TimestampFormatter;
29
+ /**
30
+ * Create a formatter for Date values.
31
+ */
32
+ export declare function formatDate(pattern: DateTimePattern, options?: DateTimeFormatOptions): (d: Date) => string;
7
33
  export declare function getDateFormatter({ locale, options }: DateTimeFormatConfig): DateFormatter;
8
- export declare function formatDate(pattern: DateTimePattern): (d: Date) => string;
9
34
  export {};
@@ -1,4 +1,8 @@
1
- export { asTimeString, decrementTimeUnitValue, incrementTimeUnitValue, isValidTimeString, Time, toCalendarDate, type DateStringISO, type Hours, type Minutes, type Seconds, type TimeString, type TimeUnit, type TimeUnitValue, updateTimeString, zeroTime, zeroTimeUnit, } from "./date-utils";
2
- export { dateTimePattern, defaultPatternsByType, fallbackDateTimePattern, } from "./dateTimePattern";
1
+ export { asTimeString, asTimeStringMillis, decrementTimeUnitValue, incrementTimeUnitValue, isValidTimeString, isValidTimeStringMillis, normaliseTimeString, Time, toCalendarDate, type DateStringISO, type Hours, type Milliseconds, type Minutes, type Seconds, type TimeString, type TimeStringMillis, type TimeUnit, type TimeUnitValue, updateTimeString, zeroTime, zeroTimeMillis, zeroTimeUnit, } from "./date-utils";
2
+ export { dateTimePattern, defaultPatternsByType, fallbackDateTimePattern, withDateTimePattern, } from "./dateTimePattern";
3
3
  export * from "./formatter";
4
4
  export { dateTimeLabelByType, isDatePattern, isTimePattern, supportedDateTimePatterns, type DatePattern, type DateTimePattern, type TimePattern, } from "./types";
5
+ export { defaultDateTimePatternByKind } from "./dateTimePattern";
6
+ export { EpochTimestamp, type TemporalEncoding } from "./EpochTimestamp";
7
+ export * from "./temporal";
8
+ export * from "./time-zone";
@@ -0,0 +1,68 @@
1
+ import type { DataValueDescriptor, TemporalDataValueTypeSimple } from "@vuu-ui/vuu-data-types";
2
+ import type { FractionalSecondDigits } from "@vuu-ui/vuu-table-types";
3
+ import { EpochTimestamp, type TemporalEncoding } from "./EpochTimestamp";
4
+ import { type TimeZoneSpec } from "./time-zone";
5
+ /**
6
+ * What a temporal value represents, from the user's perspective
7
+ * - datetime: a point in time, date and time of day are both meaningful
8
+ * - date: a calendar date, time of day is not meaningful
9
+ * - time: a time of day, the date is not meaningful (typically 'today')
10
+ */
11
+ export type TemporalKind = "datetime" | "date" | "time";
12
+ /**
13
+ * The finest resolution that the encoding can represent.
14
+ */
15
+ export type TemporalPrecision = "ms" | "ns";
16
+ export interface TemporalInfo {
17
+ kind: TemporalKind;
18
+ encoding: TemporalEncoding;
19
+ precision: TemporalPrecision;
20
+ timeZone: TimeZoneSpec;
21
+ }
22
+ export declare const isTemporalTypeName: (typeName?: string) => typeName is TemporalDataValueTypeSimple;
23
+ type TemporalDescriptor = Pick<DataValueDescriptor, "serverDataType" | "type">;
24
+ /**
25
+ * The single source of truth for whether (and how) a column or form field
26
+ * holds a temporal value. Rules:
27
+ *
28
+ * - encoding is determined by serverDataType
29
+ * - epochtimestamp => epochMillis
30
+ * - epochtimestampnano => epochNanos
31
+ * - long, int, double (or unspecified) => epochMillis, but only when the
32
+ * 'type' is a temporal type. This legacy usage (pre epochtimestamp) is
33
+ * DEPRECATED and supported only for backward compatibility. Timestamps
34
+ * should be described by the server as epochtimestamp or epochtimestampnano.
35
+ * - kind is determined by 'type' ('date/time', 'date', 'time'), default 'datetime'.
36
+ * An explicit type of 'number' opts an epochtimestamp column out of temporal
37
+ * treatment altogether.
38
+ * - timeZone from type.formatting.timeZone, falling back to the default time zone
39
+ *
40
+ * @returns TemporalInfo or undefined if value is not temporal
41
+ */
42
+ export declare const getTemporalInfo: (descriptor?: TemporalDescriptor) => TemporalInfo | undefined;
43
+ export declare const isTemporal: (descriptor?: TemporalDescriptor) => boolean;
44
+ export declare const defaultFractionalSecondDigits: (info: Pick<TemporalInfo, "precision">) => FractionalSecondDigits;
45
+ /**
46
+ * Format a timestamp as a canonical, locale independent, editable string:
47
+ * - date: yyyy-mm-dd
48
+ * - datetime: yyyy-mm-dd hh:mm:ss[.fffffffff]
49
+ * - time: hh:mm:ss[.fffffffff]
50
+ * Sub-second digits are included only when non zero, up to the precision of
51
+ * the encoding, so they round-trip unchanged through an edit.
52
+ */
53
+ export declare const formatTemporalInput: (value: EpochTimestamp | undefined, { kind, precision, timeZone }: Omit<TemporalInfo, "encoding">) => string;
54
+ /**
55
+ * Parse user input. Accepts the canonical formats produced by
56
+ * formatTemporalInput as well as raw epoch values (in the encoding of the
57
+ * column). Where the input does not include a component (e.g the date for a
58
+ * 'time' value), it is taken from baseValue if provided, otherwise today
59
+ * (date) or midnight (time).
60
+ *
61
+ * @returns EpochTimestamp, or undefined if input is not valid
62
+ */
63
+ export declare const parseTemporalInput: (input: string, { kind, encoding, precision, timeZone }: TemporalInfo, baseValue?: EpochTimestamp) => EpochTimestamp | undefined;
64
+ /**
65
+ * Placeholder text describing the canonical input format for a kind.
66
+ */
67
+ export declare const temporalInputPlaceholder: (kind: TemporalKind) => "hh:mm:ss" | "yyyy-mm-dd" | "yyyy-mm-dd hh:mm:ss";
68
+ export {};
@@ -0,0 +1,52 @@
1
+ import { CalendarDate } from "@internationalized/date";
2
+ import type { DateStringISO, TimeString } from "./date-utils";
3
+ /**
4
+ * 'local' (browser time zone), 'UTC' or any IANA time zone identifier.
5
+ */
6
+ export type TimeZoneSpec = "local" | "UTC" | (string & {});
7
+ /**
8
+ * Set the time zone used for temporal values where a column does not
9
+ * specify one explicitly (formatting.timeZone). Default is 'local'.
10
+ */
11
+ export declare const setDefaultTimeZone: (timeZone: TimeZoneSpec) => void;
12
+ export declare const getDefaultTimeZone: () => TimeZoneSpec;
13
+ /**
14
+ * Resolve a TimeZoneSpec to an IANA time zone identifier.
15
+ */
16
+ export declare const resolveTimeZone: (timeZone?: TimeZoneSpec) => string;
17
+ export interface DateTimeFields {
18
+ year: number;
19
+ month: number;
20
+ day: number;
21
+ hour: number;
22
+ minute: number;
23
+ second: number;
24
+ millisecond: number;
25
+ }
26
+ export declare const getDateTimeFields: (epochMillis: number, timeZone?: TimeZoneSpec) => DateTimeFields;
27
+ /**
28
+ * Convert wall clock fields in the given time zone to epoch millis. Where the
29
+ * wall clock time is ambiguous or does not exist (DST transitions), the
30
+ * 'compatible' disambiguation strategy is used (same as Temporal / JS Date).
31
+ */
32
+ export declare const fromDateTimeFields: ({ year, month, day, hour, minute, second, millisecond, }: Partial<DateTimeFields> & Pick<DateTimeFields, "year" | "month" | "day">, timeZone?: TimeZoneSpec) => number;
33
+ /**
34
+ * Epoch millis of the start of the calendar day (in timeZone) that contains epochMillis.
35
+ */
36
+ export declare const startOfDay: (epochMillis: number, timeZone?: TimeZoneSpec) => number;
37
+ /**
38
+ * Epoch millis of the start of the calendar day (in timeZone) following the day that
39
+ * contains epochMillis. This is DST safe, the day may be 23, 24 or 25 hours long.
40
+ */
41
+ export declare const startOfNextDay: (epochMillis: number, timeZone?: TimeZoneSpec) => number;
42
+ export declare const isStartOfDay: (epochMillis: number, timeZone?: TimeZoneSpec) => boolean;
43
+ /**
44
+ * A date to which a time of day can be applied. 'today' and 'yesterday' are
45
+ * resolved at the point of use, so filters that use them remain relative.
46
+ */
47
+ export type RelativeDate = "today" | "yesterday" | DateStringISO;
48
+ export declare const resolveRelativeDate: (date?: RelativeDate | Date, timeZone?: TimeZoneSpec) => CalendarDate;
49
+ /**
50
+ * Epoch millis of the given time of day on the given date, in timeZone.
51
+ */
52
+ export declare const timeOfDayToEpochMillis: (timeString: TimeString | `${TimeString}.${string}`, date?: RelativeDate | Date, timeZone?: TimeZoneSpec) => number;
@@ -26,7 +26,8 @@ export declare const stripFilterFromColumns: (columns: RuntimeColumnDescriptor[]
26
26
  allowColumnHeaderMenu?: false;
27
27
  colHeaderContentRenderer?: string;
28
28
  colHeaderLabelRenderer?: string;
29
- exportFormatter?: (value: unknown) => string;
29
+ exportable?: boolean;
30
+ exportFormatter?: (value: unknown, row: import("@vuu-ui/vuu-table-types").RowAccessor) => string;
30
31
  getIcon?: (row: import("@vuu-ui/vuu-table-types").DataRow) => string | undefined;
31
32
  groupable?: boolean;
32
33
  hidden?: boolean;
@@ -71,5 +72,9 @@ export declare const stripFilterFromColumns: (columns: RuntimeColumnDescriptor[]
71
72
  type?: import("@vuu-ui/vuu-data-types").DataValueType;
72
73
  }[];
73
74
  export declare const extractFilterForColumn: (filter: Filter | undefined, columnName: string) => Filter | undefined;
75
+ /**
76
+ * The full-day range used as default value of a time range filter.
77
+ */
78
+ export declare const getDefaultTimeRange: (column: ColumnDescriptor) => [string, string];
74
79
  export declare const getColumnValueFromFilter: (column: ColumnDescriptor, operator: ColumnFilterOp, filter?: FilterContainerFilter) => ColumnFilterValue;
75
80
  export declare const filtersAreEqual: (f1: FilterContainerFilter | null | undefined, f2: FilterContainerFilter | null | undefined) => boolean;