Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@data-driven-forms/react-form-renderer

Package Overview
Dependencies
Maintainers
2
Versions
388
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@data-driven-forms/react-form-renderer - npm Package Compare versions

Comparing version 3.22.0 to 3.22.1

14

esm/form-renderer/render-form.js

@@ -105,6 +105,7 @@ import _extends from "@babel/runtime/helpers/extends";

children = _ref5.children,
field = _ref5.field;
field = _ref5.field,
conditionMapper = _ref5.conditionMapper;
if (condition) {
var triggers = getConditionTriggers(condition, field);
var triggers = getConditionTriggers(condition, field, conditionMapper);
return /*#__PURE__*/React.createElement(ConditionTriggerDetector, {

@@ -123,3 +124,4 @@ triggers: triggers,

children: PropTypes.node.isRequired,
field: PropTypes.object
field: PropTypes.object,
conditionMapper: PropTypes.object
};

@@ -133,3 +135,4 @@

actionMapper = _useContext.actionMapper,
componentMapper = _useContext.componentMapper;
componentMapper = _useContext.componentMapper,
conditionMapper = _useContext.conditionMapper;

@@ -156,3 +159,4 @@ var _prepareComponentProp = prepareComponentProps({

condition: condition,
field: restProps
field: restProps,
conditionMapper: conditionMapper
}, /*#__PURE__*/React.createElement(FormFieldHideWrapper, {

@@ -159,0 +163,0 @@ hideField: hideField

@@ -0,6 +1,13 @@

import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
import _toArray from "@babel/runtime/helpers/toArray";
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import _typeof from "@babel/runtime/helpers/typeof";
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
var _excluded = ["when"];
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
var mergeFunctionTrigger = function mergeFunctionTrigger(fn, field) {

@@ -20,2 +27,3 @@ var internalTriggers = [];

var getConditionTriggers = function getConditionTriggers(condition, field) {
var conditionMapper = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
var triggers = [];

@@ -25,4 +33,30 @@

return condition.reduce(function (acc, item) {
return [].concat(_toConsumableArray(acc), _toConsumableArray(getConditionTriggers(item, field)));
return [].concat(_toConsumableArray(acc), _toConsumableArray(getConditionTriggers(item, field, conditionMapper)));
}, []);
} // extract mapped attributes to a new static condition object
if (_typeof(condition.mappedAttributes) === 'object') {
try {
var newCondition = _objectSpread(_objectSpread({}, condition), {}, {
mappedAttributes: undefined
});
Object.entries(condition.mappedAttributes).forEach(function (_ref) {
var _ref2 = _slicedToArray(_ref, 2),
attribute = _ref2[0],
_ref2$ = _toArray(_ref2[1]),
functionName = _ref2$[0],
args = _ref2$.slice(1);
if (!conditionMapper[functionName]) {
throw new Error("Missing condition mapper function \"".concat(functionName, "\" for field ").concat(field.name, "!"));
}
newCondition[attribute] = conditionMapper[functionName].apply(conditionMapper, _toConsumableArray(args));
});
return getConditionTriggers(newCondition, field, conditionMapper);
} catch (error) {
console.error(error.toString());
}
}

@@ -58,3 +92,3 @@

rest[key].forEach(function (item) {
triggers = [].concat(_toConsumableArray(triggers), _toConsumableArray(getConditionTriggers(item, field)));
triggers = [].concat(_toConsumableArray(triggers), _toConsumableArray(getConditionTriggers(item, field, conditionMapper)));
});

@@ -65,3 +99,3 @@ }

if (_typeof(condition.not) === 'object') {
triggers = [].concat(_toConsumableArray(triggers), _toConsumableArray(getConditionTriggers(condition.not, field)));
triggers = [].concat(_toConsumableArray(triggers), _toConsumableArray(getConditionTriggers(condition.not, field, conditionMapper)));
}

@@ -68,0 +102,0 @@

@@ -9,6 +9,6 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty";

var getVisibleFields = function getVisibleFields(schema, values) {
var getVisibleFields = function getVisibleFields(schema, values, conditionMapper) {
if (Array.isArray(schema)) {
return schema.map(function (field) {
return getVisibleFields(field, values);
return getVisibleFields(field, values, undefined, conditionMapper);
}).filter(Boolean);

@@ -18,7 +18,7 @@ }

if (schema.condition) {
var result = parseCondition(schema.condition, values, schema);
var result = parseCondition(schema.condition, values, schema, conditionMapper);
if (result.visible) {
return _objectSpread(_objectSpread({}, schema), schema.fields && {
fields: getVisibleFields(schema.fields, values).filter(Boolean)
fields: getVisibleFields(schema.fields, values, undefined, conditionMapper).filter(Boolean)
});

@@ -31,3 +31,3 @@ } else {

return _objectSpread(_objectSpread({}, schema), schema.fields && {
fields: getVisibleFields(schema.fields, values).filter(Boolean)
fields: getVisibleFields(schema.fields, values, undefined, conditionMapper).filter(Boolean)
});

@@ -34,0 +34,0 @@ };

@@ -108,3 +108,3 @@ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";

return !condition.map(function (condition) {
return parseCondition(condition, values, field);
return parseCondition(condition, values, field, conditionMapper);
}).some(function (_ref3) {

@@ -120,3 +120,3 @@ var result = _ref3.result;

return !conditionInternal.and.map(function (condition) {
return parseCondition(condition, values, field);
return parseCondition(condition, values, field, conditionMapper);
}).some(function (_ref4) {

@@ -130,3 +130,3 @@ var result = _ref4.result;

return conditionInternal.sequence.reduce(function (acc, curr) {
var result = parseCondition(curr, values, field);
var result = parseCondition(curr, values, field, conditionMapper);
return {

@@ -144,3 +144,3 @@ sets: [].concat(_toConsumableArray(acc.sets), _toConsumableArray(result.set ? [result.set] : [])),

return conditionInternal.or.map(function (condition) {
return parseCondition(condition, values, field);
return parseCondition(condition, values, field, conditionMapper);
}).some(function (_ref5) {

@@ -153,3 +153,3 @@ var result = _ref5.result;

if (conditionInternal.not) {
return !parseCondition(conditionInternal.not, values, field).result ? positiveResult : negativeResult;
return !parseCondition(conditionInternal.not, values, field, conditionMapper).result ? positiveResult : negativeResult;
}

@@ -156,0 +156,0 @@

@@ -35,3 +35,3 @@ import _typeof from "@babel/runtime/helpers/typeof";

var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(schema, options) {
var values, componentMapper, validatorMapper, actionMapper, schemaValidatorMapper, omitWarnings, validatorMapperMerged, validatorTypes, actionTypes, finalComponentMapper, finalSchema, validates;
var values, componentMapper, validatorMapper, actionMapper, schemaValidatorMapper, omitWarnings, conditionMapper, validatorMapperMerged, validatorTypes, actionTypes, finalComponentMapper, finalSchema, validates;
return _regeneratorRuntime.wrap(function _callee2$(_context2) {

@@ -57,3 +57,3 @@ while (1) {

case 4:
values = options.values, componentMapper = options.componentMapper, validatorMapper = options.validatorMapper, actionMapper = options.actionMapper, schemaValidatorMapper = options.schemaValidatorMapper, omitWarnings = options.omitWarnings;
values = options.values, componentMapper = options.componentMapper, validatorMapper = options.validatorMapper, actionMapper = options.actionMapper, schemaValidatorMapper = options.schemaValidatorMapper, omitWarnings = options.omitWarnings, conditionMapper = options.conditionMapper;
validatorMapperMerged = _objectSpread(_objectSpread({}, defaultValidatorMapper), validatorMapper);

@@ -71,3 +71,3 @@ validatorTypes = Object.keys(validatorMapperMerged);

defaultSchemaValidator(finalSchema, finalComponentMapper, validatorTypes, actionTypes, schemaValidatorMapper);
finalSchema = getVisibleFields(finalSchema, values);
finalSchema = getVisibleFields(finalSchema, values, undefined, conditionMapper);
validates = getValidates(finalSchema, {

@@ -74,0 +74,0 @@ componentMapper: finalComponentMapper,

@@ -131,6 +131,7 @@ "use strict";

children = _ref5.children,
field = _ref5.field;
field = _ref5.field,
conditionMapper = _ref5.conditionMapper;
if (condition) {
var triggers = (0, _getConditionTriggers["default"])(condition, field);
var triggers = (0, _getConditionTriggers["default"])(condition, field, conditionMapper);
return /*#__PURE__*/_react["default"].createElement(ConditionTriggerDetector, {

@@ -149,3 +150,4 @@ triggers: triggers,

children: _propTypes["default"].node.isRequired,
field: _propTypes["default"].object
field: _propTypes["default"].object,
conditionMapper: _propTypes["default"].object
};

@@ -159,3 +161,4 @@

actionMapper = _useContext.actionMapper,
componentMapper = _useContext.componentMapper;
componentMapper = _useContext.componentMapper,
conditionMapper = _useContext.conditionMapper;

@@ -182,3 +185,4 @@ var _prepareComponentProp = (0, _prepareComponentProps["default"])({

condition: condition,
field: restProps
field: restProps,
conditionMapper: conditionMapper
}, /*#__PURE__*/_react["default"].createElement(FormFieldHideWrapper, {

@@ -185,0 +189,0 @@ hideField: hideField

@@ -0,5 +1,7 @@

import { Field } from "../common-types";
import { ConditionDefinition } from "../condition";
import { ConditionMapper } from "../form-renderer/condition-mapper";
declare function getConditionTriggers(params:ConditionDefinition | ConditionDefinition[]): string[];
declare function getConditionTriggers(params:ConditionDefinition | ConditionDefinition[], field: Extract<Field, 'condition' | 'hideField'>, conditionMapper: ConditionMapper): string[];
export default getConditionTriggers;

@@ -10,6 +10,12 @@ "use strict";

var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
var _toArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toArray"));
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));

@@ -19,2 +25,6 @@

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
var mergeFunctionTrigger = function mergeFunctionTrigger(fn, field) {

@@ -34,2 +44,3 @@ var internalTriggers = [];

var getConditionTriggers = function getConditionTriggers(condition, field) {
var conditionMapper = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
var triggers = [];

@@ -39,4 +50,30 @@

return condition.reduce(function (acc, item) {
return [].concat((0, _toConsumableArray2["default"])(acc), (0, _toConsumableArray2["default"])(getConditionTriggers(item, field)));
return [].concat((0, _toConsumableArray2["default"])(acc), (0, _toConsumableArray2["default"])(getConditionTriggers(item, field, conditionMapper)));
}, []);
} // extract mapped attributes to a new static condition object
if ((0, _typeof2["default"])(condition.mappedAttributes) === 'object') {
try {
var newCondition = _objectSpread(_objectSpread({}, condition), {}, {
mappedAttributes: undefined
});
Object.entries(condition.mappedAttributes).forEach(function (_ref) {
var _ref2 = (0, _slicedToArray2["default"])(_ref, 2),
attribute = _ref2[0],
_ref2$ = (0, _toArray2["default"])(_ref2[1]),
functionName = _ref2$[0],
args = _ref2$.slice(1);
if (!conditionMapper[functionName]) {
throw new Error("Missing condition mapper function \"".concat(functionName, "\" for field ").concat(field.name, "!"));
}
newCondition[attribute] = conditionMapper[functionName].apply(conditionMapper, (0, _toConsumableArray2["default"])(args));
});
return getConditionTriggers(newCondition, field, conditionMapper);
} catch (error) {
console.error(error.toString());
}
}

@@ -71,3 +108,3 @@

rest[key].forEach(function (item) {
triggers = [].concat((0, _toConsumableArray2["default"])(triggers), (0, _toConsumableArray2["default"])(getConditionTriggers(item, field)));
triggers = [].concat((0, _toConsumableArray2["default"])(triggers), (0, _toConsumableArray2["default"])(getConditionTriggers(item, field, conditionMapper)));
});

@@ -78,3 +115,3 @@ }

if ((0, _typeof2["default"])(condition.not) === 'object') {
triggers = [].concat((0, _toConsumableArray2["default"])(triggers), (0, _toConsumableArray2["default"])(getConditionTriggers(condition.not, field)));
triggers = [].concat((0, _toConsumableArray2["default"])(triggers), (0, _toConsumableArray2["default"])(getConditionTriggers(condition.not, field, conditionMapper)));
}

@@ -81,0 +118,0 @@

@@ -18,6 +18,6 @@ "use strict";

var getVisibleFields = function getVisibleFields(schema, values) {
var getVisibleFields = function getVisibleFields(schema, values, conditionMapper) {
if (Array.isArray(schema)) {
return schema.map(function (field) {
return getVisibleFields(field, values);
return getVisibleFields(field, values, undefined, conditionMapper);
}).filter(Boolean);

@@ -27,7 +27,7 @@ }

if (schema.condition) {
var result = (0, _parseCondition["default"])(schema.condition, values, schema);
var result = (0, _parseCondition["default"])(schema.condition, values, schema, conditionMapper);
if (result.visible) {
return _objectSpread(_objectSpread({}, schema), schema.fields && {
fields: getVisibleFields(schema.fields, values).filter(Boolean)
fields: getVisibleFields(schema.fields, values, undefined, conditionMapper).filter(Boolean)
});

@@ -40,3 +40,3 @@ } else {

return _objectSpread(_objectSpread({}, schema), schema.fields && {
fields: getVisibleFields(schema.fields, values).filter(Boolean)
fields: getVisibleFields(schema.fields, values, undefined, conditionMapper).filter(Boolean)
});

@@ -43,0 +43,0 @@ };

{
"name": "@data-driven-forms/react-form-renderer",
"version": "3.22.0",
"version": "3.22.1",
"description": "React Form Renderer. Data Driven Forms converts JSON form definitions into fully functional React forms.",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -126,3 +126,3 @@ "use strict";

return !condition.map(function (condition) {
return parseCondition(condition, values, field);
return parseCondition(condition, values, field, conditionMapper);
}).some(function (_ref3) {

@@ -138,3 +138,3 @@ var result = _ref3.result;

return !conditionInternal.and.map(function (condition) {
return parseCondition(condition, values, field);
return parseCondition(condition, values, field, conditionMapper);
}).some(function (_ref4) {

@@ -148,3 +148,3 @@ var result = _ref4.result;

return conditionInternal.sequence.reduce(function (acc, curr) {
var result = parseCondition(curr, values, field);
var result = parseCondition(curr, values, field, conditionMapper);
return {

@@ -162,3 +162,3 @@ sets: [].concat((0, _toConsumableArray2["default"])(acc.sets), (0, _toConsumableArray2["default"])(result.set ? [result.set] : [])),

return conditionInternal.or.map(function (condition) {
return parseCondition(condition, values, field);
return parseCondition(condition, values, field, conditionMapper);
}).some(function (_ref5) {

@@ -171,3 +171,3 @@ var result = _ref5.result;

if (conditionInternal.not) {
return !parseCondition(conditionInternal.not, values, field).result ? positiveResult : negativeResult;
return !parseCondition(conditionInternal.not, values, field, conditionMapper).result ? positiveResult : negativeResult;
}

@@ -174,0 +174,0 @@

@@ -54,3 +54,3 @@ "use strict";

var _ref = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2(schema, options) {
var values, componentMapper, validatorMapper, actionMapper, schemaValidatorMapper, omitWarnings, validatorMapperMerged, validatorTypes, actionTypes, finalComponentMapper, finalSchema, validates;
var values, componentMapper, validatorMapper, actionMapper, schemaValidatorMapper, omitWarnings, conditionMapper, validatorMapperMerged, validatorTypes, actionTypes, finalComponentMapper, finalSchema, validates;
return _regenerator["default"].wrap(function _callee2$(_context2) {

@@ -76,3 +76,3 @@ while (1) {

case 4:
values = options.values, componentMapper = options.componentMapper, validatorMapper = options.validatorMapper, actionMapper = options.actionMapper, schemaValidatorMapper = options.schemaValidatorMapper, omitWarnings = options.omitWarnings;
values = options.values, componentMapper = options.componentMapper, validatorMapper = options.validatorMapper, actionMapper = options.actionMapper, schemaValidatorMapper = options.schemaValidatorMapper, omitWarnings = options.omitWarnings, conditionMapper = options.conditionMapper;
validatorMapperMerged = _objectSpread(_objectSpread({}, _validatorMapper["default"]), validatorMapper);

@@ -90,3 +90,3 @@ validatorTypes = Object.keys(validatorMapperMerged);

(0, _defaultSchemaValidator["default"])(finalSchema, finalComponentMapper, validatorTypes, actionTypes, schemaValidatorMapper);
finalSchema = (0, _getVisibleFields["default"])(finalSchema, values);
finalSchema = (0, _getVisibleFields["default"])(finalSchema, values, undefined, conditionMapper);
validates = (0, _getValidates["default"])(finalSchema, {

@@ -93,0 +93,0 @@ componentMapper: finalComponentMapper,

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc