@react-typed-forms/schemas 11.0.3 → 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.
- package/lib/controlRender.d.ts +3 -1
- package/lib/index.js +27 -13
- package/lib/index.js.map +1 -1
- package/lib/schemaInterface.d.ts +2 -1
- package/lib/types.d.ts +2 -0
- package/lib/util.d.ts +2 -1
- package/package.json +1 -1
package/lib/controlRender.d.ts
CHANGED
|
@@ -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
|
@@ -417,6 +417,9 @@ function useUpdatedRef(a) {
|
|
|
417
417
|
function isControlReadonly(c) {
|
|
418
418
|
return isDataControl(c) && !!c.readonly;
|
|
419
419
|
}
|
|
420
|
+
function isControlDisabled(c) {
|
|
421
|
+
return isDataControl(c) && !!c.disabled;
|
|
422
|
+
}
|
|
420
423
|
function getDisplayOnlyOptions(d) {
|
|
421
424
|
return isDataControlDefinition(d) && d.renderOptions && isDisplayOnlyRenderer(d.renderOptions) ? d.renderOptions : undefined;
|
|
422
425
|
}
|
|
@@ -490,17 +493,17 @@ function lookupChildControlPath(data, jsonPath) {
|
|
|
490
493
|
var childPath = [].concat(data.path, jsonPath);
|
|
491
494
|
return watchControlLookup(data.data, childPath);
|
|
492
495
|
}
|
|
493
|
-
function cleanDataForSchema(v, fields) {
|
|
496
|
+
function cleanDataForSchema(v, fields, removeIfDefault) {
|
|
494
497
|
if (!v) return v;
|
|
495
498
|
var typeField = fields.find(function (x) {
|
|
496
499
|
return x.isTypeField;
|
|
497
500
|
});
|
|
498
501
|
if (!typeField) return v;
|
|
499
502
|
var typeValue = v[typeField.field];
|
|
500
|
-
var cleanableFields = fields.filter(function (x) {
|
|
503
|
+
var cleanableFields = !removeIfDefault ? fields.filter(function (x) {
|
|
501
504
|
var _x$onlyForTypes$lengt, _x$onlyForTypes;
|
|
502
505
|
return isCompoundField(x) || ((_x$onlyForTypes$lengt = (_x$onlyForTypes = x.onlyForTypes) == null ? void 0 : _x$onlyForTypes.length) != null ? _x$onlyForTypes$lengt : 0) > 0;
|
|
503
|
-
});
|
|
506
|
+
}) : fields;
|
|
504
507
|
if (!cleanableFields.length) return v;
|
|
505
508
|
var out = _extends({}, v);
|
|
506
509
|
cleanableFields.forEach(function (x) {
|
|
@@ -515,15 +518,15 @@ function cleanDataForSchema(v, fields) {
|
|
|
515
518
|
if (x.collection) {
|
|
516
519
|
if (Array.isArray(childValue)) {
|
|
517
520
|
out[x.field] = childValue.map(function (cv) {
|
|
518
|
-
return cleanDataForSchema(cv, childFields);
|
|
521
|
+
return cleanDataForSchema(cv, childFields, removeIfDefault);
|
|
519
522
|
});
|
|
520
523
|
}
|
|
521
524
|
} else {
|
|
522
|
-
out[x.field] = cleanDataForSchema(childValue, childFields);
|
|
525
|
+
out[x.field] = cleanDataForSchema(childValue, childFields, removeIfDefault);
|
|
523
526
|
}
|
|
524
527
|
}
|
|
525
528
|
function canBeNull() {
|
|
526
|
-
return x.collection && Array.isArray(childValue) && !childValue.length
|
|
529
|
+
return removeIfDefault && x.defaultValue === childValue || x.collection && Array.isArray(childValue) && !childValue.length
|
|
527
530
|
//|| (x.type === FieldType.Bool && childValue === false)
|
|
528
531
|
;
|
|
529
532
|
}
|
|
@@ -957,7 +960,9 @@ function useEvalAllowedOptionsHook(useEvalExpressionHook, definition) {
|
|
|
957
960
|
function useEvalDisabledHook(useEvalExpressionHook, definition) {
|
|
958
961
|
var dynamicDisabled = useEvalDynamicBoolHook(definition, exports.DynamicPropertyType.Disabled, useEvalExpressionHook);
|
|
959
962
|
return makeDynamicPropertyHook(dynamicDisabled, function () {
|
|
960
|
-
return core.
|
|
963
|
+
return core.useComputed(function () {
|
|
964
|
+
return isControlDisabled(definition);
|
|
965
|
+
});
|
|
961
966
|
}, undefined);
|
|
962
967
|
}
|
|
963
968
|
function useEvalDisplayHook(useEvalExpressionHook, definition) {
|
|
@@ -1245,6 +1250,10 @@ function cc(n) {
|
|
|
1245
1250
|
var DefaultSchemaInterface = /*#__PURE__*/function () {
|
|
1246
1251
|
function DefaultSchemaInterface() {}
|
|
1247
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
|
+
};
|
|
1248
1257
|
_proto.isEmptyValue = function isEmptyValue(f, value) {
|
|
1249
1258
|
if (f.collection) return Array.isArray(value) ? value.length === 0 : value == null;
|
|
1250
1259
|
switch (f.type) {
|
|
@@ -1269,14 +1278,14 @@ var DefaultSchemaInterface = /*#__PURE__*/function () {
|
|
|
1269
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);
|
|
1270
1279
|
};
|
|
1271
1280
|
_proto.valueLength = function valueLength(field, value) {
|
|
1272
|
-
var
|
|
1273
|
-
return (
|
|
1281
|
+
var _ref2;
|
|
1282
|
+
return (_ref2 = value && (value == null ? void 0 : value.length)) != null ? _ref2 : 0;
|
|
1274
1283
|
};
|
|
1275
1284
|
return DefaultSchemaInterface;
|
|
1276
1285
|
}();
|
|
1277
1286
|
var defaultSchemaInterface = new DefaultSchemaInterface();
|
|
1278
1287
|
|
|
1279
|
-
var _excluded$3 = ["definition", "field", "control", "formOptions", "style", "allowedOptions"];
|
|
1288
|
+
var _excluded$3 = ["definition", "field", "control", "formOptions", "style", "allowedOptions", "schemaInterface"];
|
|
1280
1289
|
var AppendAdornmentPriority = 0;
|
|
1281
1290
|
var WrapAdornmentPriority = 1000;
|
|
1282
1291
|
exports.LabelType = void 0;
|
|
@@ -1436,6 +1445,7 @@ function useControlRenderer(definition, fields, renderer, options) {
|
|
|
1436
1445
|
parentContext: parentDataContext,
|
|
1437
1446
|
control: displayControl != null ? displayControl : control,
|
|
1438
1447
|
elementIndex: _elementIndex,
|
|
1448
|
+
schemaInterface: schemaInterface,
|
|
1439
1449
|
labelText: labelText,
|
|
1440
1450
|
field: _schemaField,
|
|
1441
1451
|
displayControl: displayControl,
|
|
@@ -1524,20 +1534,22 @@ function ControlRenderer(_ref3) {
|
|
|
1524
1534
|
}
|
|
1525
1535
|
}
|
|
1526
1536
|
function defaultDataProps(_ref4) {
|
|
1527
|
-
var _definition$validator,
|
|
1537
|
+
var _definition$validator, _allowedOptions$value, _definition$children, _definition$renderOpt;
|
|
1528
1538
|
var definition = _ref4.definition,
|
|
1529
1539
|
field = _ref4.field,
|
|
1530
1540
|
control = _ref4.control,
|
|
1531
1541
|
formOptions = _ref4.formOptions,
|
|
1532
1542
|
style = _ref4.style,
|
|
1533
1543
|
allowedOptions = _ref4.allowedOptions,
|
|
1544
|
+
_ref4$schemaInterface = _ref4.schemaInterface,
|
|
1545
|
+
schemaInterface = _ref4$schemaInterface === void 0 ? defaultSchemaInterface : _ref4$schemaInterface,
|
|
1534
1546
|
props = _objectWithoutPropertiesLoose(_ref4, _excluded$3);
|
|
1535
1547
|
var lengthVal = (_definition$validator = definition.validators) == null ? void 0 : _definition$validator.find(function (x) {
|
|
1536
1548
|
return x.type === exports.ValidatorType.Length;
|
|
1537
1549
|
});
|
|
1538
1550
|
var className = cc(definition.styleClass);
|
|
1539
1551
|
var required = !!definition.required;
|
|
1540
|
-
var fieldOptions = (
|
|
1552
|
+
var fieldOptions = schemaInterface.getOptions(field);
|
|
1541
1553
|
var allowed = (_allowedOptions$value = allowedOptions == null ? void 0 : allowedOptions.value) != null ? _allowedOptions$value : [];
|
|
1542
1554
|
return _extends({
|
|
1543
1555
|
definition: definition,
|
|
@@ -1972,12 +1984,13 @@ function createSelectRenderer(options) {
|
|
|
1972
1984
|
options = {};
|
|
1973
1985
|
}
|
|
1974
1986
|
return createDataRenderer(function (props, asArray) {
|
|
1987
|
+
var _props$options;
|
|
1975
1988
|
return /*#__PURE__*/React__default["default"].createElement(SelectDataRenderer, {
|
|
1976
1989
|
className: rendererClass(props.className, options.className),
|
|
1977
1990
|
state: props.control,
|
|
1978
1991
|
id: props.id,
|
|
1979
1992
|
readonly: props.readonly,
|
|
1980
|
-
options: props.options,
|
|
1993
|
+
options: (_props$options = props.options) != null ? _props$options : [],
|
|
1981
1994
|
required: props.required,
|
|
1982
1995
|
emptyText: options.emptyText,
|
|
1983
1996
|
requiredText: options.requiredText,
|
|
@@ -2806,6 +2819,7 @@ exports.htmlDisplayControl = htmlDisplayControl;
|
|
|
2806
2819
|
exports.intField = intField;
|
|
2807
2820
|
exports.isActionControlsDefinition = isActionControlsDefinition;
|
|
2808
2821
|
exports.isCompoundField = isCompoundField;
|
|
2822
|
+
exports.isControlDisabled = isControlDisabled;
|
|
2809
2823
|
exports.isControlReadonly = isControlReadonly;
|
|
2810
2824
|
exports.isDataControl = isDataControl;
|
|
2811
2825
|
exports.isDataControlDefinition = isDataControlDefinition;
|