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

cerebral-module-ui-driver

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cerebral-module-ui-driver - npm Package Compare versions

Comparing version 0.5.1 to 0.6.0

actions/reset.js

19

lib/actions/reset.js

@@ -6,16 +6,9 @@ 'use strict';

});
exports.default = resetFormDriver;
exports.default = resetDriver;
function resetDriver(_ref) {
var module = _ref.module;
var modules = _ref.modules;
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
function resetFormDriver(statePath) {
var formPath = Array.isArray(statePath) ? statePath : [statePath];
var driverPath = ['drivers'].concat(_toConsumableArray(formPath));
var validationPath = [].concat(_toConsumableArray(formPath), ['validation']);
return function resetForm(_ref) {
var state = _ref.state;
state.set(driverPath, {});
state.unset(validationPath);
};
var driverModule = modules['cerebral-module-ui-driver'];
driverModule.state.set(module.name, {});
}

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

function setStateValue(_ref) {
var input = _ref.input;
var _ref$input = _ref.input;
var statePath = _ref$input.statePath;
var value = _ref$input.value;
var state = _ref.state;
state.set(input.statePath, input.value);
state.set(statePath, value);
}

@@ -7,243 +7,22 @@ 'use strict';

var _moment = require('moment');
exports.default = function (_ref) {
var moduleName = _ref.moduleName;
var modules = _ref.modules;
var state = _ref.state;
var props = _ref.props;
var _moment2 = _interopRequireDefault(_moment);
var _sideEffects = require('./sideEffects');
var _sideEffects2 = _interopRequireDefault(_sideEffects);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
exports.default = {
registerSideEffect: _sideEffects2.default.register,
createForm: function createForm(formStatePath) {
var formPath = Array.isArray(formStatePath) ? formStatePath : [formStatePath];
var formName = formPath.join('.');
var validationFields = [];
return {
state: function state() {
return {
driverForm: formPath,
driverMeta: ['drivers'].concat(_toConsumableArray(formPath))
};
},
getValidationData: function getValidationData() {
return {
fields: validationFields
};
},
getBindings: function getBindings(_ref) {
var state = _ref.state;
var signals = _ref.signals;
var _ref$t = _ref.t;
var t = _ref$t === undefined ? null : _ref$t;
var _ref$props = _ref.props;
var props = _ref$props === undefined ? {} : _ref$props;
validationFields = [];
var inputProps = function inputProps(name) {
var _ref2 = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
var _ref2$label = _ref2.label;
var label = _ref2$label === undefined ? null : _ref2$label;
var _ref2$value = _ref2.value;
var value = _ref2$value === undefined ? state.driverMeta && state.driverMeta[name] && state.driverMeta[name].inputValue : _ref2$value;
var _ref2$inputType = _ref2.inputType;
var inputType = _ref2$inputType === undefined ? 'text' : _ref2$inputType;
var _ref2$format = _ref2.format;
var format = _ref2$format === undefined ? function (val) {
return val === null ? '' : val;
} : _ref2$format;
var _ref2$messages = _ref2.messages;
var messages = _ref2$messages === undefined ? {} : _ref2$messages;
var _ref2$validationType = _ref2.validationType;
var validationType = _ref2$validationType === undefined ? 'string' : _ref2$validationType;
var _ref2$required = _ref2.required;
var required = _ref2$required === undefined ? false : _ref2$required;
var _ref2$signalData = _ref2.signalData;
var signalData = _ref2$signalData === undefined ? {} : _ref2$signalData;
var useInputValue = typeof value !== 'undefined' && value !== null;
var validationKey = state.driverForm && state.driverForm.validation && state.driverForm.validation[name];
var isError = !!validationKey;
var formattedValue = state.driverForm && format(state.driverForm[name]);
var displayValue = useInputValue ? value : formattedValue;
var statePath = [].concat(_toConsumableArray(formPath), [name]);
var signalInput = Object.assign({
formName: formName,
name: name,
displayValue: displayValue,
inputValueStatePath: ['drivers'].concat(_toConsumableArray(statePath), ['inputValue']),
validationKeyStatePath: [].concat(_toConsumableArray(formPath), ['validation', name]),
statePath: statePath,
validationType: validationType,
validationKeyPrefix: t ? name : '',
required: required
}, signalData);
validationFields.push(signalInput);
var message = '';
if (isError) {
if (t) {
message = t[validationKey] ? t[validationKey]() : validationKey;
} else {
var key = validationKey.toLowerCase();
message = messages[key] ? messages[key] : key;
}
} else if (useInputValue && formattedValue !== value) {
message = formattedValue;
}
return Object.assign({
label: label !== null ? label : (t || {})[name + 'Label'] ? (t || {})[name + 'Label']() : name,
value: displayValue,
type: inputType,
isError: isError,
message: message,
onChange: function onChange(e) {
signals.driver.valuesChanged({
fields: [Object.assign({
inputValue: e.target.value
}, signalInput)]
});
}
}, props);
};
var inputTimeProps = function inputTimeProps(name) {
var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
var timeFormat = options.timeFormat ? options.timeFormat : 'H:mm';
return inputProps(name, Object.assign({
format: function format(value) {
return value === null ? '' : (0, _moment2.default)(value * 1000 * 60).utcOffset(0).format(timeFormat);
},
validationType: 'time',
signalData: { timeFormat: timeFormat }
}, options));
};
var inputDateProps = function inputDateProps(name) {
var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
var dateFormat = options.dateFormat ? options.dateFormat : 'L';
return inputProps(name, Object.assign({
format: function format(value) {
return value === null ? '' : (0, _moment2.default)(value).format(dateFormat);
},
validationType: 'date',
signalData: { dateFormat: dateFormat }
}, options));
};
var inputIntProps = function inputIntProps(name) {
var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
return inputProps(name, Object.assign({
format: function format(value) {
return value === null ? '' : '' + value;
},
validationType: 'int',
inputType: 'number'
}, options));
};
var inputEmailProps = function inputEmailProps(name) {
var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
return inputProps(name, Object.assign({
validationType: 'email'
}, options));
};
var inputPasswordProps = function inputPasswordProps(name) {
var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
return inputProps(name, Object.assign({
validationType: options.checkStrength ? 'password' : 'string',
inputType: 'password'
}, options));
};
var inputEqualsProps = function inputEqualsProps(name, compare) {
var options = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2];
return inputProps(name, Object.assign({
validationType: 'equal',
signalData: { compare: compare }
}, options));
};
var menuOpenProps = function menuOpenProps(name) {
var _ref3 = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
var _ref3$eventType = _ref3.eventType;
var eventType = _ref3$eventType === undefined ? 'onTouchTap' : _ref3$eventType;
var statePath = [].concat(_toConsumableArray(formPath), [name]);
var driverPath = ['drivers'].concat(_toConsumableArray(statePath));
var isOpenPath = [].concat(_toConsumableArray(driverPath), ['isOpen']);
var p = {};
p[eventType] = function () {
return signals.driver.isOpenChanged({
statePath: isOpenPath,
value: true
});
};
return Object.assign(p, props);
};
var menuProps = function menuProps(name) {
var statePath = [].concat(_toConsumableArray(formPath), [name]);
var driverPath = ['drivers'].concat(_toConsumableArray(statePath));
var isOpenPath = [].concat(_toConsumableArray(driverPath), ['isOpen']);
return Object.assign({
isOpen: !!(state.driverMeta && state.driverMeta[name] && state.driverMeta[name].isOpen),
onClose: function onClose() {
signals.driver.isOpenChanged({
statePath: isOpenPath,
value: false
});
}
}, props);
};
var selectProps = function selectProps(name, selectOptions) {
var options = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2];
return Object.assign({ options: selectOptions }, inputProps(name, Object.assign({
value: null,
validationType: 'none'
}, options)), menuOpenProps(name, { eventType: 'onOpen' }), menuProps(name));
};
var checkboxProps = function checkboxProps(name) {
var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
return inputProps(name, Object.assign({
value: null,
validationType: 'none'
}, options));
};
return {
checkboxProps: checkboxProps,
inputDateProps: inputDateProps,
inputEmailProps: inputEmailProps,
inputEqualsProps: inputEqualsProps,
inputIntProps: inputIntProps,
inputPasswordProps: inputPasswordProps,
inputProps: inputProps,
inputTimeProps: inputTimeProps,
menuOpenProps: menuOpenProps,
menuProps: menuProps,
selectProps: selectProps
};
}
};
}
var driverModule = modules['cerebral-module-ui-driver'];
var formModule = modules[moduleName];
var driverOptions = driverModule.meta.options;
var propsMaps = driverModule.meta.propsMaps;
return driverOptions.bindingTypes.reduce(function (bindings, binding) {
bindings[binding] = driverOptions.bindings[binding]({
driverModule: driverModule,
formModule: formModule,
state: state,
props: props,
propsMap: propsMaps[binding]
});
return bindings;
}, {});
};

@@ -11,5 +11,5 @@ 'use strict';

var _valuesChanged = require('./chains/valuesChanged');
var _valueChanged = require('./chains/valueChanged');
var _valuesChanged2 = _interopRequireDefault(_valuesChanged);
var _valueChanged2 = _interopRequireDefault(_valueChanged);

@@ -20,6 +20,14 @@ var _propsMaps = require('./propsMaps');

var _bindingTypes = require('./bindingTypes');
var _bindings = require('./bindings');
var _bindingTypes2 = _interopRequireDefault(_bindingTypes);
var _bindings2 = _interopRequireDefault(_bindings);
var _casts = require('./casts');
var _casts2 = _interopRequireDefault(_casts);
var _formatters = require('./formatters');
var _formatters2 = _interopRequireDefault(_formatters);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -29,6 +37,17 @@

var options = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];
var propsMaps = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
// set undefined options
options.bindings = Object.assign({}, _bindings2.default, options.bindings);
options.bindingTypes = options.bindingTypes || Object.keys(options.bindings);
options.casts = Object.assign({}, _casts2.default, options.casts);
options.formatters = Object.assign({}, _formatters2.default, options.formatters);
options.dateFormat = options.dateFormat || 'L';
options.timeFormat = options.timeFormat || 'H:mm';
options.invalidDateMessage = options.invalidDateMessage || 'invalid date';
options.invalidNumberMessage = options.invalidNumberMessage || 'invalid number';
options.invalidTimeMessage = options.invalidTimeMessage || 'invalid time';
options.invalidMessage = options.invalidMessage || 'form has validation errors';
// configure props maps
var propsMaps = options.propsMaps || {};
_bindingTypes2.default.forEach(function (binding) {
options.bindingTypes.forEach(function (binding) {
propsMaps[binding] = Object.assign({}, _propsMaps2.default.base, propsMaps.base, _propsMaps2.default[binding], propsMaps[binding]);

@@ -39,18 +58,17 @@ });

return function (module) {
module.state({});
module.alias('cerebral-module-ui-driver');
module.signals({
isOpenChanged: _isOpenChanged2.default
});
// register signals
module.signals({ isOpenChanged: _isOpenChanged2.default });
module.signalsSync({
valuesChanged: _valuesChanged2.default
valueChanged: (0, _valueChanged2.default)(options.debounceTimeout || 200)
});
module.services({
return {
signals: module.getSignals(),
options: options,
propsMaps: propsMaps
});
return {};
propsMaps: propsMaps,
isUiDriverModule: true
};
};
};

@@ -8,5 +8,5 @@ 'use strict';

base: {
label: 'label',
value: 'value',
onChange: 'onChange',
isValidating: 'isValidating',
isError: 'isError',

@@ -19,2 +19,5 @@ message: 'message',

},
form: {
onSubmit: 'onSubmit'
},
menuOpen: {

@@ -21,0 +24,0 @@ onOpen: 'onClick'

{
"name": "cerebral-module-ui-driver",
"version": "0.5.1",
"version": "0.6.0",
"description": "A driver for connecting ui components to cerebral",

@@ -39,6 +39,6 @@ "main": "lib/index.js",

"babel-preset-es2015": "^6.3.13",
"baobab": "^2.3.0",
"cerebral": "^0.31.0",
"cerebral-addons": "^0.2.3",
"cerebral-model-baobab": "^0.4.5",
"baobab": "^2.3.1",
"cerebral": "^0.32.0",
"cerebral-addons": "^0.3.1",
"cerebral-model-baobab": "^0.4.6",
"chai": "^3.4.1",

@@ -57,6 +57,6 @@ "mocha": "^2.3.4",

"peerDependencies": {
"cerebral": "^0.31.0",
"cerebral-addons": "^0.2.3",
"cerebral": "^0.32.0",
"cerebral-addons": "^0.3.1",
"moment": "^2.11.0"
}
}

Sorry, the diff of this file is not supported yet

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