@react-typed-forms/schemas 11.16.0 → 11.17.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.
@@ -214,6 +214,11 @@ export declare function appendMarkupAt(pos: AdornmentPlacement, markup: ReactNod
214
214
  export declare function wrapMarkupAt(pos: AdornmentPlacement, wrap: (ex: ReactNode) => ReactNode): (layout: RenderedLayout) => void;
215
215
  export declare function renderLayoutParts(props: ControlLayoutProps, renderer: FormRenderer): RenderedLayout;
216
216
  export declare function controlTitle(title: string | undefined | null, field: SchemaField): string;
217
+ export declare function getLengthRestrictions(definition: DataControlDefinition): {
218
+ min: number | null | undefined;
219
+ max: number | null | undefined;
220
+ };
221
+ export declare function createArrayActions(control: Control<any[]>, field: SchemaField, addText?: string | null, removeText?: string | null, noAdd?: boolean | null, noRemove?: boolean | null): Pick<ArrayRendererProps, "addAction" | "removeAction" | "arrayControl">;
217
222
  export declare function applyArrayLengthRestrictions({ arrayControl, min, max, addAction: aa, removeAction: ra, required, }: Pick<ArrayRendererProps, "addAction" | "removeAction" | "arrayControl" | "min" | "max" | "required">, disable?: boolean): Pick<ArrayRendererProps, "addAction" | "removeAction"> & {
218
223
  addDisabled: boolean;
219
224
  removeDisabled: boolean;
package/lib/index.js CHANGED
@@ -1911,6 +1911,39 @@ function renderLayoutParts(props, renderer) {
1911
1911
  function controlTitle(title, field) {
1912
1912
  return title ? title : fieldDisplayName(field);
1913
1913
  }
1914
+ function getLengthRestrictions(definition) {
1915
+ var _definition$validator;
1916
+ var lengthVal = (_definition$validator = definition.validators) == null ? void 0 : _definition$validator.find(function (x) {
1917
+ return x.type === exports.ValidatorType.Length;
1918
+ });
1919
+ return {
1920
+ min: lengthVal == null ? void 0 : lengthVal.min,
1921
+ max: lengthVal == null ? void 0 : lengthVal.max
1922
+ };
1923
+ }
1924
+ function createArrayActions(control, field, addText, removeText, noAdd, noRemove) {
1925
+ var _field$displayName;
1926
+ var noun = (_field$displayName = field.displayName) != null ? _field$displayName : field.field;
1927
+ return {
1928
+ arrayControl: control,
1929
+ addAction: !noAdd ? {
1930
+ actionId: "add",
1931
+ actionText: addText ? addText : "Add " + noun,
1932
+ onClick: function onClick() {
1933
+ return core.addElement(control, elementValueForField(field));
1934
+ }
1935
+ } : undefined,
1936
+ removeAction: !noRemove ? function (i) {
1937
+ return {
1938
+ actionId: "remove",
1939
+ actionText: removeText ? removeText : "Remove",
1940
+ onClick: function onClick() {
1941
+ return core.removeElement(control, i);
1942
+ }
1943
+ };
1944
+ } : undefined
1945
+ };
1946
+ }
1914
1947
  function applyArrayLengthRestrictions(_ref7, disable) {
1915
1948
  var _arrayControl$element, _arrayControl$element2;
1916
1949
  var arrayControl = _ref7.arrayControl,
@@ -2341,7 +2374,6 @@ function createInputConversion(ft) {
2341
2374
 
2342
2375
  function createDefaultArrayDataRenderer() {
2343
2376
  return createDataRenderer(function (_ref, renderers) {
2344
- var _definition$validator, _field$displayName;
2345
2377
  var definition = _ref.definition,
2346
2378
  control = _ref.control,
2347
2379
  required = _ref.required,
@@ -2351,35 +2383,14 @@ function createDefaultArrayDataRenderer() {
2351
2383
  className = _ref.className,
2352
2384
  style = _ref.style,
2353
2385
  renderOptions = _ref.renderOptions;
2354
- var lengthVal = (_definition$validator = definition.validators) == null ? void 0 : _definition$validator.find(function (x) {
2355
- return x.type === exports.ValidatorType.Length;
2356
- });
2357
2386
  var _ref2 = isArrayRenderer(renderOptions) ? renderOptions : {},
2358
2387
  addText = _ref2.addText,
2359
2388
  noAdd = _ref2.noAdd,
2360
2389
  noRemove = _ref2.noRemove,
2361
2390
  removeText = _ref2.removeText;
2362
2391
  var childOptions = isArrayRenderer(renderOptions) ? renderOptions.childOptions : undefined;
2363
- var noun = (_field$displayName = field.displayName) != null ? _field$displayName : field.field;
2364
- var arrayProps = {
2365
- arrayControl: control,
2392
+ var arrayProps = _extends({}, createArrayActions(control, field, addText, removeText, noAdd, noRemove), {
2366
2393
  required: required,
2367
- addAction: !noAdd ? {
2368
- actionId: "add",
2369
- actionText: addText ? addText : "Add " + noun,
2370
- onClick: function onClick() {
2371
- return core.addElement(control, elementValueForField(field));
2372
- }
2373
- } : undefined,
2374
- removeAction: !noRemove ? function (i) {
2375
- return {
2376
- actionId: "",
2377
- actionText: removeText ? removeText : "Remove",
2378
- onClick: function onClick() {
2379
- return core.removeElement(control, i);
2380
- }
2381
- };
2382
- } : undefined,
2383
2394
  renderElement: function renderElement(i) {
2384
2395
  var _control$elements$i$u, _control$elements;
2385
2396
  return renderChild((_control$elements$i$u = (_control$elements = control.elements) == null ? void 0 : _control$elements[i].uniqueId) != null ? _control$elements$i$u : i, {
@@ -2396,10 +2407,8 @@ function createDefaultArrayDataRenderer() {
2396
2407
  });
2397
2408
  },
2398
2409
  className: cc(className),
2399
- style: style,
2400
- min: lengthVal == null ? void 0 : lengthVal.min,
2401
- max: lengthVal == null ? void 0 : lengthVal.max
2402
- };
2410
+ style: style
2411
+ }, getLengthRestrictions(definition));
2403
2412
  return renderers.renderArray(arrayProps);
2404
2413
  });
2405
2414
  }
@@ -3254,6 +3263,7 @@ exports.controlTitle = controlTitle;
3254
3263
  exports.createAction = createAction;
3255
3264
  exports.createActionRenderer = createActionRenderer;
3256
3265
  exports.createAdornmentRenderer = createAdornmentRenderer;
3266
+ exports.createArrayActions = createArrayActions;
3257
3267
  exports.createArrayRenderer = createArrayRenderer;
3258
3268
  exports.createButtonActionRenderer = createButtonActionRenderer;
3259
3269
  exports.createCheckListRenderer = createCheckListRenderer;
@@ -3313,6 +3323,7 @@ exports.findScalarField = findScalarField;
3313
3323
  exports.getAllReferencedClasses = getAllReferencedClasses;
3314
3324
  exports.getControlData = getControlData;
3315
3325
  exports.getDisplayOnlyOptions = getDisplayOnlyOptions;
3326
+ exports.getLengthRestrictions = getLengthRestrictions;
3316
3327
  exports.getOverrideClass = getOverrideClass;
3317
3328
  exports.getTypeField = getTypeField;
3318
3329
  exports.groupedControl = groupedControl;