@react-typed-forms/schemas 11.5.3 → 11.5.5

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,
@@ -1234,13 +1241,9 @@ function useValidationHook(definition, field) {
1234
1241
  }
1235
1242
  function useJsonataValidator(control, context, expr, hidden, i) {
1236
1243
  var errorMsg = useJsonataExpression(expr.expression, context);
1237
- core.useControlEffect(function () {
1238
- return [hidden, errorMsg.value];
1239
- }, function (_ref2) {
1240
- var hidden = _ref2[0],
1241
- msg = _ref2[1];
1242
- return control.setError("jsonata" + i, !hidden ? msg : null);
1243
- }, true);
1244
+ core.useValidator(control, function () {
1245
+ return !hidden ? errorMsg.value : null;
1246
+ }, "jsonata" + i);
1244
1247
  }
1245
1248
  function useDateValidator(control, dv, i) {
1246
1249
  var comparisonDate;
@@ -2125,6 +2128,9 @@ var _excluded = ["control", "convert"],
2125
2128
  function ControlInput(_ref) {
2126
2129
  var _effect = core.useComponentTracking();
2127
2130
  try {
2131
+ var toText = function toText(value) {
2132
+ return value == null ? "" : convert[2](value);
2133
+ };
2128
2134
  var control = _ref.control,
2129
2135
  convert = _ref.convert,
2130
2136
  props = _objectWithoutPropertiesLoose(_ref, _excluded);
@@ -2133,11 +2139,21 @@ function ControlInput(_ref) {
2133
2139
  value = _formControlProps.value,
2134
2140
  onChange = _formControlProps.onChange,
2135
2141
  inputProps = _objectWithoutPropertiesLoose(_formControlProps, _excluded2);
2142
+ var textValue = core.useControl(function () {
2143
+ return toText(value);
2144
+ });
2145
+ core.useControlEffect(function () {
2146
+ return control.value;
2147
+ }, function (v) {
2148
+ return textValue.value = toText(v);
2149
+ });
2136
2150
  return /*#__PURE__*/React__default["default"].createElement("input", _extends({}, inputProps, {
2137
2151
  type: convert[0],
2138
- value: value == null ? "" : convert[2](value),
2152
+ value: textValue.value,
2139
2153
  onChange: function onChange(e) {
2140
- control.value = convert[1](e.target.value);
2154
+ textValue.value = e.target.value;
2155
+ var converted = convert[1](e.target.value);
2156
+ if (converted !== undefined) control.value = converted;
2141
2157
  }
2142
2158
  }, props));
2143
2159
  } finally {
@@ -2154,7 +2170,7 @@ function createInputConversion(ft) {
2154
2170
  }];
2155
2171
  case exports.FieldType.Bool:
2156
2172
  return ["text", function (a) {
2157
- return a === "true";
2173
+ return a === "true" ? true : a === "false" ? false : undefined;
2158
2174
  }, function (a) {
2159
2175
  var _a$toString;
2160
2176
  return (_a$toString = a == null ? void 0 : a.toString()) != null ? _a$toString : "";
@@ -2171,6 +2187,15 @@ function createInputConversion(ft) {
2171
2187
  }, function (a) {
2172
2188
  return a;
2173
2189
  }];
2190
+ case exports.FieldType.Time:
2191
+ return ["time", function (a) {
2192
+ var l = a.length;
2193
+ if (l === 5) return a + ":00";
2194
+ if (l === 8) return a;
2195
+ return undefined;
2196
+ }, function (a) {
2197
+ return a ? a.substring(0, 5) : "";
2198
+ }];
2174
2199
  case exports.FieldType.Double:
2175
2200
  return ["number", function (a) {
2176
2201
  return parseFloat(a);
@@ -2897,6 +2922,7 @@ exports.setIncluded = setIncluded;
2897
2922
  exports.stringField = stringField;
2898
2923
  exports.stringOptionsField = stringOptionsField;
2899
2924
  exports.textDisplayControl = textDisplayControl;
2925
+ exports.timeField = timeField;
2900
2926
  exports.toDepString = toDepString;
2901
2927
  exports.useControlDefinitionForSchema = useControlDefinitionForSchema;
2902
2928
  exports.useControlRenderer = useControlRenderer;