@react-typed-forms/schemas 11.1.0 → 11.2.0

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.
@@ -143,6 +143,7 @@ export interface DataControlProps {
143
143
  elementIndex?: number;
144
144
  allowedOptions?: Control<any[] | undefined>;
145
145
  useChildVisibility: ChildVisibilityFunc;
146
+ schemaInterface?: SchemaInterface;
146
147
  }
147
148
  export type CreateDataProps = (controlProps: DataControlProps) => DataRendererProps;
148
149
  export interface ControlRenderOptions extends FormContextOptions {
@@ -164,7 +165,7 @@ export declare function ControlRenderer({ definition, fields, renderer, options,
164
165
  control: Control<any>;
165
166
  parentPath?: JsonPath[];
166
167
  }): React.JSX.Element;
167
- export declare function defaultDataProps({ definition, field, control, formOptions, style, allowedOptions, ...props }: DataControlProps): DataRendererProps;
168
+ export declare function defaultDataProps({ definition, field, control, formOptions, style, allowedOptions, schemaInterface, ...props }: DataControlProps): DataRendererProps;
168
169
  export declare function defaultArrayProps(arrayControl: Control<any[] | undefined | null>, field: SchemaField, required: boolean, style: CSSProperties | undefined, className: string | undefined, renderElement: (elemIndex: number) => ReactNode, min: number | undefined | null, max: number | undefined | null): ArrayRendererProps;
169
170
  export interface ChildRendererOptions {
170
171
  elementIndex?: number;
@@ -189,6 +190,7 @@ export interface RenderControlProps {
189
190
  actionDataControl?: Control<any | undefined | null>;
190
191
  useChildVisibility: ChildVisibilityFunc;
191
192
  actionOnClick?: (actionId: string, actionData: any) => () => void;
193
+ schemaInterface?: SchemaInterface;
192
194
  }
193
195
  export declare function renderControlLayout(props: RenderControlProps): ControlLayoutProps;
194
196
  export declare function appendMarkup(k: keyof Omit<RenderedLayout, "errorControl" | "style" | "className">, markup: ReactNode): (layout: RenderedLayout) => void;
package/lib/index.js CHANGED
@@ -1250,6 +1250,10 @@ function cc(n) {
1250
1250
  var DefaultSchemaInterface = /*#__PURE__*/function () {
1251
1251
  function DefaultSchemaInterface() {}
1252
1252
  var _proto = DefaultSchemaInterface.prototype;
1253
+ _proto.getOptions = function getOptions(_ref) {
1254
+ var options = _ref.options;
1255
+ return options && options.length > 0 ? options : null;
1256
+ };
1253
1257
  _proto.isEmptyValue = function isEmptyValue(f, value) {
1254
1258
  if (f.collection) return Array.isArray(value) ? value.length === 0 : value == null;
1255
1259
  switch (f.type) {
@@ -1274,14 +1278,14 @@ var DefaultSchemaInterface = /*#__PURE__*/function () {
1274
1278
  return f.collection ? (_control$elements$len = (_control$elements = control.elements) == null ? void 0 : _control$elements.length) != null ? _control$elements$len : 0 : this.valueLength(f, control.value);
1275
1279
  };
1276
1280
  _proto.valueLength = function valueLength(field, value) {
1277
- var _ref;
1278
- return (_ref = value && (value == null ? void 0 : value.length)) != null ? _ref : 0;
1281
+ var _ref2;
1282
+ return (_ref2 = value && (value == null ? void 0 : value.length)) != null ? _ref2 : 0;
1279
1283
  };
1280
1284
  return DefaultSchemaInterface;
1281
1285
  }();
1282
1286
  var defaultSchemaInterface = new DefaultSchemaInterface();
1283
1287
 
1284
- var _excluded$3 = ["definition", "field", "control", "formOptions", "style", "allowedOptions"];
1288
+ var _excluded$3 = ["definition", "field", "control", "formOptions", "style", "allowedOptions", "schemaInterface"];
1285
1289
  var AppendAdornmentPriority = 0;
1286
1290
  var WrapAdornmentPriority = 1000;
1287
1291
  exports.LabelType = void 0;
@@ -1441,6 +1445,7 @@ function useControlRenderer(definition, fields, renderer, options) {
1441
1445
  parentContext: parentDataContext,
1442
1446
  control: displayControl != null ? displayControl : control,
1443
1447
  elementIndex: _elementIndex,
1448
+ schemaInterface: schemaInterface,
1444
1449
  labelText: labelText,
1445
1450
  field: _schemaField,
1446
1451
  displayControl: displayControl,
@@ -1529,20 +1534,22 @@ function ControlRenderer(_ref3) {
1529
1534
  }
1530
1535
  }
1531
1536
  function defaultDataProps(_ref4) {
1532
- var _definition$validator, _field$options$length, _field$options, _allowedOptions$value, _definition$children, _definition$renderOpt;
1537
+ var _definition$validator, _allowedOptions$value, _definition$children, _definition$renderOpt;
1533
1538
  var definition = _ref4.definition,
1534
1539
  field = _ref4.field,
1535
1540
  control = _ref4.control,
1536
1541
  formOptions = _ref4.formOptions,
1537
1542
  style = _ref4.style,
1538
1543
  allowedOptions = _ref4.allowedOptions,
1544
+ _ref4$schemaInterface = _ref4.schemaInterface,
1545
+ schemaInterface = _ref4$schemaInterface === void 0 ? defaultSchemaInterface : _ref4$schemaInterface,
1539
1546
  props = _objectWithoutPropertiesLoose(_ref4, _excluded$3);
1540
1547
  var lengthVal = (_definition$validator = definition.validators) == null ? void 0 : _definition$validator.find(function (x) {
1541
1548
  return x.type === exports.ValidatorType.Length;
1542
1549
  });
1543
1550
  var className = cc(definition.styleClass);
1544
1551
  var required = !!definition.required;
1545
- var fieldOptions = ((_field$options$length = (_field$options = field.options) == null ? void 0 : _field$options.length) != null ? _field$options$length : 0) === 0 ? null : field.options;
1552
+ var fieldOptions = schemaInterface.getOptions(field);
1546
1553
  var allowed = (_allowedOptions$value = allowedOptions == null ? void 0 : allowedOptions.value) != null ? _allowedOptions$value : [];
1547
1554
  return _extends({
1548
1555
  definition: definition,
@@ -1977,12 +1984,13 @@ function createSelectRenderer(options) {
1977
1984
  options = {};
1978
1985
  }
1979
1986
  return createDataRenderer(function (props, asArray) {
1987
+ var _props$options;
1980
1988
  return /*#__PURE__*/React__default["default"].createElement(SelectDataRenderer, {
1981
1989
  className: rendererClass(props.className, options.className),
1982
1990
  state: props.control,
1983
1991
  id: props.id,
1984
1992
  readonly: props.readonly,
1985
- options: props.options,
1993
+ options: (_props$options = props.options) != null ? _props$options : [],
1986
1994
  required: props.required,
1987
1995
  emptyText: options.emptyText,
1988
1996
  requiredText: options.requiredText,