@vuu-ui/vuu-data-react 4.0.0-alpha.17 → 4.0.0-alpha.19

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/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "4.0.0-alpha.17",
2
+ "version": "4.0.0-alpha.19",
3
3
  "main": "./src/index.js",
4
4
  "author": "heswell",
5
5
  "type": "module",
@@ -11,25 +11,25 @@
11
11
  "type-defs": "node ../../scripts/build-type-defs.mjs"
12
12
  },
13
13
  "devDependencies": {
14
- "@vuu-ui/vuu-data-types": "4.0.0-alpha.17",
15
- "@vuu-ui/vuu-filter-types": "4.0.0-alpha.17",
16
- "@vuu-ui/vuu-protocol-types": "4.0.0-alpha.17",
17
- "@vuu-ui/vuu-table-types": "4.0.0-alpha.17"
14
+ "@vuu-ui/vuu-data-types": "4.0.0-alpha.19",
15
+ "@vuu-ui/vuu-filter-types": "4.0.0-alpha.19",
16
+ "@vuu-ui/vuu-protocol-types": "4.0.0-alpha.19",
17
+ "@vuu-ui/vuu-table-types": "4.0.0-alpha.19"
18
18
  },
19
19
  "dependencies": {
20
- "@vuu-ui/vuu-context-menu": "4.0.0-alpha.17",
21
- "@vuu-ui/vuu-data-remote": "4.0.0-alpha.17",
22
- "@vuu-ui/vuu-filter-parser": "4.0.0-alpha.17",
23
- "@vuu-ui/vuu-filters": "4.0.0-alpha.17",
24
- "@vuu-ui/vuu-layout": "4.0.0-alpha.17",
25
- "@vuu-ui/vuu-notifications": "4.0.0-alpha.17",
26
- "@vuu-ui/vuu-ui-controls": "4.0.0-alpha.17",
27
- "@vuu-ui/vuu-utils": "4.0.0-alpha.17",
28
- "@vuu-ui/vuu-table": "4.0.0-alpha.17",
20
+ "@vuu-ui/vuu-context-menu": "4.0.0-alpha.19",
21
+ "@vuu-ui/vuu-data-remote": "4.0.0-alpha.19",
22
+ "@vuu-ui/vuu-filter-parser": "4.0.0-alpha.19",
23
+ "@vuu-ui/vuu-filters": "4.0.0-alpha.19",
24
+ "@vuu-ui/vuu-layout": "4.0.0-alpha.19",
25
+ "@vuu-ui/vuu-notifications": "4.0.0-alpha.19",
26
+ "@vuu-ui/vuu-ui-controls": "4.0.0-alpha.19",
27
+ "@vuu-ui/vuu-utils": "4.0.0-alpha.19",
28
+ "@vuu-ui/vuu-table": "4.0.0-alpha.19",
29
29
  "@salt-ds/core": "1.67.0",
30
30
  "@salt-ds/styles": "0.2.1",
31
31
  "@salt-ds/window": "0.1.1",
32
- "@vuu-ui/core": "4.0.0-alpha.17"
32
+ "@vuu-ui/core": "4.0.0-alpha.19"
33
33
  },
34
34
  "peerDependencies": {
35
35
  "clsx": "^2.0.0",
@@ -1,12 +1,29 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
2
  import { VuuDatePicker, VuuInput, VuuTimePicker, VuuTypeaheadInput } from "@vuu-ui/vuu-ui-controls";
3
- import { asTimeString, isDataValueEditable, isDateTimeDataValue, isTimeDataValue } from "@vuu-ui/vuu-utils";
3
+ import { EpochTimestamp, getTemporalInfo, isDataValueEditable, isTimeDataValueWithMilliseconds, isValidTimeString, isValidTimeStringMillis, parseTemporalInput } from "@vuu-ui/vuu-utils";
4
4
  import { ToggleFilter } from "@vuu-ui/vuu-filters";
5
- const getDataItemEditControl = ({ InputProps, TypeaheadProps, className, commitOnBlur, commitWhenCleared, dataDescriptor, editOperation = "update", errorMessage, onCommit, table, values, variant })=>{
6
- const handleCommitNumber = (evt, value)=>{
7
- onCommit(evt, value.toString());
8
- };
5
+ const timeOfDayPattern = /^\d{2}:\d{2}(:\d{2}(\.\d{1,9})?)?$/;
6
+ const toEpochTimestamp = (value, { encoding })=>{
7
+ if (("string" == typeof value || "number" == typeof value) && !timeOfDayPattern.test(`${value}`)) return EpochTimestamp.fromWire(value, encoding);
8
+ };
9
+ const pad = (n)=>`${n}`.padStart(2, "0");
10
+ function toTimeString(value, timestamp, { timeZone }, milliseconds = false) {
11
+ if (timestamp) {
12
+ const { hour, minute, second, millisecond } = timestamp.getFields(timeZone);
13
+ const timeString = `${pad(hour)}:${pad(minute)}:${pad(second)}`;
14
+ return milliseconds ? `${timeString}.${`${millisecond}`.padStart(3, "0")}` : timeString;
15
+ }
16
+ if ("string" == typeof value) if (milliseconds) {
17
+ const timeString = 8 === value.length ? `${value}.000` : value.slice(0, 12);
18
+ if (isValidTimeStringMillis(timeString)) return timeString;
19
+ } else {
20
+ const timeString = value.slice(0, 8);
21
+ if (isValidTimeString(timeString)) return timeString;
22
+ }
23
+ }
24
+ const getDataItemEditControl = ({ InputProps, TypeaheadProps, className, commitOnBlur, commitWhenCleared, dataDescriptor, editOperation = "update", errorMessage, labels, onCommit, table, values, variant })=>{
9
25
  const dataVariant = variant && "toggle" !== variant ? variant : void 0;
26
+ const temporalInfo = getTemporalInfo(dataDescriptor);
10
27
  if (!isDataValueEditable(dataDescriptor, editOperation, true)) return /*#__PURE__*/ jsx(VuuInput, {
11
28
  variant: "secondary",
12
29
  ...InputProps,
@@ -14,26 +31,62 @@ const getDataItemEditControl = ({ InputProps, TypeaheadProps, className, commitO
14
31
  readOnly: true,
15
32
  "data-edit-control": true
16
33
  });
17
- if (isTimeDataValue(dataDescriptor)) {
18
- if (InputProps?.inputProps) {
19
- const { value, onChange } = InputProps.inputProps;
20
- return /*#__PURE__*/ jsx(VuuTimePicker, {
21
- className: className,
22
- value: asTimeString(value, true),
23
- onChange: onChange,
24
- onCommit: onCommit,
25
- "data-edit-control": true
26
- });
27
- }
28
- } else if (isDateTimeDataValue(dataDescriptor)) return /*#__PURE__*/ jsx(VuuDatePicker, {
29
- className: className,
30
- onCommit: handleCommitNumber,
31
- "data-edit-control": true
32
- });
33
- else if ("string" === dataDescriptor.serverDataType && table) if ("toggle" === variant && values?.length) return /*#__PURE__*/ jsx(ToggleFilter, {
34
+ if (temporalInfo?.kind === "time") {
35
+ const { value, onChange } = InputProps?.inputProps ?? {};
36
+ const baseValue = toEpochTimestamp(value, temporalInfo);
37
+ const handleCommitTime = (evt, timeString)=>{
38
+ if (baseValue) {
39
+ const timestamp = parseTemporalInput(timeString, temporalInfo, baseValue);
40
+ onCommit(evt, timestamp ? `${timestamp.toWire(temporalInfo.encoding)}` : "");
41
+ } else onCommit(evt, timeString);
42
+ };
43
+ return isTimeDataValueWithMilliseconds(dataDescriptor) ? /*#__PURE__*/ jsx(VuuTimePicker, {
44
+ className: className,
45
+ milliseconds: true,
46
+ value: "" === value ? "" : toTimeString(value, baseValue, temporalInfo, true),
47
+ onChange: onChange,
48
+ onCommit: handleCommitTime,
49
+ "data-edit-control": true
50
+ }) : /*#__PURE__*/ jsx(VuuTimePicker, {
51
+ className: className,
52
+ value: "" === value ? "" : toTimeString(value, baseValue, temporalInfo),
53
+ onChange: onChange,
54
+ onCommit: handleCommitTime,
55
+ "data-edit-control": true
56
+ });
57
+ }
58
+ if (temporalInfo) {
59
+ const baseValue = toEpochTimestamp(InputProps?.inputProps?.value, temporalInfo);
60
+ const handleCommitDate = (evt, startOfDayMillis)=>{
61
+ let timestamp = EpochTimestamp.fromMillis(startOfDayMillis);
62
+ if (baseValue && "datetime" === temporalInfo.kind) {
63
+ const { year, month, day } = timestamp.getFields(temporalInfo.timeZone);
64
+ const { hour, minute, second, millisecond } = baseValue.getFields(temporalInfo.timeZone);
65
+ timestamp = EpochTimestamp.fromFields({
66
+ year,
67
+ month,
68
+ day,
69
+ hour,
70
+ minute,
71
+ second,
72
+ millisecond
73
+ }, temporalInfo.timeZone, baseValue.subMilliNanos);
74
+ }
75
+ onCommit(evt, `${timestamp.toWire(temporalInfo.encoding)}`);
76
+ };
77
+ return /*#__PURE__*/ jsx(VuuDatePicker, {
78
+ className: className,
79
+ onCommit: handleCommitDate,
80
+ timeZone: temporalInfo.timeZone,
81
+ value: baseValue,
82
+ "data-edit-control": true
83
+ });
84
+ }
85
+ if ("string" === dataDescriptor.serverDataType && table) if ("toggle" === variant && values?.length) return /*#__PURE__*/ jsx(ToggleFilter, {
34
86
  className: className,
35
87
  column: dataDescriptor.name,
36
88
  "data-edit-control": true,
89
+ labels: labels,
37
90
  onCommit: onCommit,
38
91
  table: table,
39
92
  values: values,
@@ -21,6 +21,11 @@ export interface DataItemEditControlProps {
21
21
  dataDescriptor: DataValueDescriptor;
22
22
  editOperation?: "insert" | "update";
23
23
  errorMessage?: string;
24
+ /**
25
+ * Optional labels, only used with 'toggle' variant. If provided, must
26
+ * have same number of items as values. Defaults to values.
27
+ */
28
+ labels?: string[];
24
29
  onCommit: CommitHandler<HTMLElement>;
25
30
  table?: TableSchemaTable;
26
31
  /**
@@ -34,4 +39,4 @@ export interface DataItemEditControlProps {
34
39
  variant?: FilterControlVariant;
35
40
  }
36
41
  export type ValidationStatus = "initial" | true | string;
37
- export declare const getDataItemEditControl: ({ InputProps, TypeaheadProps, className, commitOnBlur, commitWhenCleared, dataDescriptor, editOperation, errorMessage, onCommit, table, values, variant, }: DataItemEditControlProps) => import("react").JSX.Element;
42
+ export declare const getDataItemEditControl: ({ InputProps, TypeaheadProps, className, commitOnBlur, commitWhenCleared, dataDescriptor, editOperation, errorMessage, labels, onCommit, table, values, variant, }: DataItemEditControlProps) => import("react").JSX.Element;