@react-typed-forms/schemas 11.5.2 → 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";
@@ -697,6 +698,24 @@ function intField(displayName, options) {
697
698
  displayName: displayName
698
699
  }, options));
699
700
  }
701
+ function dateField(displayName, options) {
702
+ return makeScalarField(_extends({
703
+ type: exports.FieldType.Date,
704
+ displayName: displayName
705
+ }, options));
706
+ }
707
+ function timeField(displayName, options) {
708
+ return makeScalarField(_extends({
709
+ type: exports.FieldType.Time,
710
+ displayName: displayName
711
+ }, options));
712
+ }
713
+ function dateTimeField(displayName, options) {
714
+ return makeScalarField(_extends({
715
+ type: exports.FieldType.DateTime,
716
+ displayName: displayName
717
+ }, options));
718
+ }
700
719
  function boolField(displayName, options) {
701
720
  return makeScalarField(_extends({
702
721
  type: exports.FieldType.Bool,
@@ -2113,6 +2132,9 @@ var _excluded = ["control", "convert"],
2113
2132
  function ControlInput(_ref) {
2114
2133
  var _effect = core.useComponentTracking();
2115
2134
  try {
2135
+ var toText = function toText(value) {
2136
+ return value == null ? "" : convert[2](value);
2137
+ };
2116
2138
  var control = _ref.control,
2117
2139
  convert = _ref.convert,
2118
2140
  props = _objectWithoutPropertiesLoose(_ref, _excluded);
@@ -2121,11 +2143,21 @@ function ControlInput(_ref) {
2121
2143
  value = _formControlProps.value,
2122
2144
  onChange = _formControlProps.onChange,
2123
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
+ });
2124
2154
  return /*#__PURE__*/React__default["default"].createElement("input", _extends({}, inputProps, {
2125
2155
  type: convert[0],
2126
- value: value == null ? "" : convert[2](value),
2156
+ value: textValue.value,
2127
2157
  onChange: function onChange(e) {
2128
- 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;
2129
2161
  }
2130
2162
  }, props));
2131
2163
  } finally {
@@ -2142,7 +2174,7 @@ function createInputConversion(ft) {
2142
2174
  }];
2143
2175
  case exports.FieldType.Bool:
2144
2176
  return ["text", function (a) {
2145
- return a === "true";
2177
+ return a === "true" ? true : a === "false" ? false : undefined;
2146
2178
  }, function (a) {
2147
2179
  var _a$toString;
2148
2180
  return (_a$toString = a == null ? void 0 : a.toString()) != null ? _a$toString : "";
@@ -2159,6 +2191,15 @@ function createInputConversion(ft) {
2159
2191
  }, function (a) {
2160
2192
  return a;
2161
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
+ }];
2162
2203
  case exports.FieldType.Double:
2163
2204
  return ["number", function (a) {
2164
2205
  return parseFloat(a);
@@ -2807,6 +2848,8 @@ exports.createSelectConversion = createSelectConversion;
2807
2848
  exports.createSelectRenderer = createSelectRenderer;
2808
2849
  exports.createVisibilityRenderer = createVisibilityRenderer;
2809
2850
  exports.dataControl = dataControl;
2851
+ exports.dateField = dateField;
2852
+ exports.dateTimeField = dateTimeField;
2810
2853
  exports.defaultArrayProps = defaultArrayProps;
2811
2854
  exports.defaultCompoundField = defaultCompoundField;
2812
2855
  exports.defaultControlForField = defaultControlForField;
@@ -2883,6 +2926,7 @@ exports.setIncluded = setIncluded;
2883
2926
  exports.stringField = stringField;
2884
2927
  exports.stringOptionsField = stringOptionsField;
2885
2928
  exports.textDisplayControl = textDisplayControl;
2929
+ exports.timeField = timeField;
2886
2930
  exports.toDepString = toDepString;
2887
2931
  exports.useControlDefinitionForSchema = useControlDefinitionForSchema;
2888
2932
  exports.useControlRenderer = useControlRenderer;