@react-typed-forms/schemas 11.5.3 → 11.5.4

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.
@@ -4,6 +4,10 @@ export declare function ControlInput({ control, convert, ...props }: React.Input
4
4
  control: Control<any>;
5
5
  convert: InputConversion;
6
6
  }): React.JSX.Element;
7
- type InputConversion = [string, (s: any) => any, (a: any) => string | number];
7
+ type InputConversion = [
8
+ string,
9
+ (s: string) => any,
10
+ (a: any) => string | number
11
+ ];
8
12
  export declare function createInputConversion(ft: string): InputConversion;
9
13
  export {};
package/lib/index.js CHANGED
@@ -16,6 +16,7 @@ exports.FieldType = void 0;
16
16
  FieldType["Int"] = "Int";
17
17
  FieldType["Date"] = "Date";
18
18
  FieldType["DateTime"] = "DateTime";
19
+ FieldType["Time"] = "Time";
19
20
  FieldType["Double"] = "Double";
20
21
  FieldType["EntityRef"] = "EntityRef";
21
22
  FieldType["Compound"] = "Compound";
@@ -703,6 +704,12 @@ function dateField(displayName, options) {
703
704
  displayName: displayName
704
705
  }, options));
705
706
  }
707
+ function timeField(displayName, options) {
708
+ return makeScalarField(_extends({
709
+ type: exports.FieldType.Time,
710
+ displayName: displayName
711
+ }, options));
712
+ }
706
713
  function dateTimeField(displayName, options) {
707
714
  return makeScalarField(_extends({
708
715
  type: exports.FieldType.DateTime,
@@ -2125,6 +2132,9 @@ var _excluded = ["control", "convert"],
2125
2132
  function ControlInput(_ref) {
2126
2133
  var _effect = core.useComponentTracking();
2127
2134
  try {
2135
+ var toText = function toText(value) {
2136
+ return value == null ? "" : convert[2](value);
2137
+ };
2128
2138
  var control = _ref.control,
2129
2139
  convert = _ref.convert,
2130
2140
  props = _objectWithoutPropertiesLoose(_ref, _excluded);
@@ -2133,11 +2143,21 @@ function ControlInput(_ref) {
2133
2143
  value = _formControlProps.value,
2134
2144
  onChange = _formControlProps.onChange,
2135
2145
  inputProps = _objectWithoutPropertiesLoose(_formControlProps, _excluded2);
2146
+ var textValue = core.useControl(function () {
2147
+ return toText(value);
2148
+ });
2149
+ core.useControlEffect(function () {
2150
+ return control.value;
2151
+ }, function (v) {
2152
+ return textValue.value = toText(v);
2153
+ });
2136
2154
  return /*#__PURE__*/React__default["default"].createElement("input", _extends({}, inputProps, {
2137
2155
  type: convert[0],
2138
- value: value == null ? "" : convert[2](value),
2156
+ value: textValue.value,
2139
2157
  onChange: function onChange(e) {
2140
- control.value = convert[1](e.target.value);
2158
+ textValue.value = e.target.value;
2159
+ var converted = convert[1](e.target.value);
2160
+ if (converted !== undefined) control.value = converted;
2141
2161
  }
2142
2162
  }, props));
2143
2163
  } finally {
@@ -2154,7 +2174,7 @@ function createInputConversion(ft) {
2154
2174
  }];
2155
2175
  case exports.FieldType.Bool:
2156
2176
  return ["text", function (a) {
2157
- return a === "true";
2177
+ return a === "true" ? true : a === "false" ? false : undefined;
2158
2178
  }, function (a) {
2159
2179
  var _a$toString;
2160
2180
  return (_a$toString = a == null ? void 0 : a.toString()) != null ? _a$toString : "";
@@ -2171,6 +2191,15 @@ function createInputConversion(ft) {
2171
2191
  }, function (a) {
2172
2192
  return a;
2173
2193
  }];
2194
+ case exports.FieldType.Time:
2195
+ return ["time", function (a) {
2196
+ var l = a.length;
2197
+ if (l === 5) return a + ":00";
2198
+ if (l === 8) return a;
2199
+ return undefined;
2200
+ }, function (a) {
2201
+ return a ? a.substring(0, 5) : "";
2202
+ }];
2174
2203
  case exports.FieldType.Double:
2175
2204
  return ["number", function (a) {
2176
2205
  return parseFloat(a);
@@ -2897,6 +2926,7 @@ exports.setIncluded = setIncluded;
2897
2926
  exports.stringField = stringField;
2898
2927
  exports.stringOptionsField = stringOptionsField;
2899
2928
  exports.textDisplayControl = textDisplayControl;
2929
+ exports.timeField = timeField;
2900
2930
  exports.toDepString = toDepString;
2901
2931
  exports.useControlDefinitionForSchema = useControlDefinitionForSchema;
2902
2932
  exports.useControlRenderer = useControlRenderer;