-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
150 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
'use strict'; | ||
|
||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.FORMS_TOGGLE_SELECT = exports.FORMS_UPDATE_VALUE = exports.FORMS_INITIALIZE = exports.FORMS_CANCEL_OUTSIDE_CLICK = exports.FORMS_OUTSIDE_CLICK = undefined; | ||
exports.initializeForm = initializeForm; | ||
exports.updateFormValue = updateFormValue; | ||
exports.toggleFormSelect = toggleFormSelect; | ||
exports.cancelOutsideClick = cancelOutsideClick; | ||
|
||
var _immutable = require('immutable'); | ||
|
||
var FORMS_OUTSIDE_CLICK = exports.FORMS_OUTSIDE_CLICK = 'FORMS_OUTSIDE_CLICK'; | ||
var FORMS_CANCEL_OUTSIDE_CLICK = exports.FORMS_CANCEL_OUTSIDE_CLICK = 'FORMS_CANCEL_OUTSIDE_CLICK'; | ||
|
||
var FORMS_INITIALIZE = exports.FORMS_INITIALIZE = 'FORMS_INITIALIZE'; | ||
var FORMS_UPDATE_VALUE = exports.FORMS_UPDATE_VALUE = 'FORMS_UPDATE_VALUE'; | ||
var FORMS_TOGGLE_SELECT = exports.FORMS_TOGGLE_SELECT = 'FORMS_TOGGLE_SELECT'; | ||
|
||
function initializeForm(form) { | ||
var initialValues = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : (0, _immutable.Map)(); | ||
|
||
return { | ||
type: FORMS_INITIALIZE, | ||
form: form, | ||
initialValues: initialValues | ||
}; | ||
} | ||
|
||
function updateFormValue(form, field, value) { | ||
return { | ||
type: FORMS_UPDATE_VALUE, | ||
form: form, | ||
field: field, | ||
value: value | ||
}; | ||
} | ||
|
||
function toggleFormSelect(form, field) { | ||
return { | ||
type: FORMS_TOGGLE_SELECT, | ||
form: form, | ||
field: field | ||
}; | ||
} | ||
|
||
function cancelOutsideClick() { | ||
return { | ||
type: FORMS_CANCEL_OUTSIDE_CLICK | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
'use strict'; | ||
|
||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
|
||
var _middleware = require('./middleware'); | ||
|
||
Object.keys(_middleware).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
Object.defineProperty(exports, key, { | ||
enumerable: true, | ||
get: function get() { | ||
return _middleware[key]; | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
'use strict'; | ||
|
||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.middleware = undefined; | ||
|
||
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | ||
|
||
var _actions = require('./actions'); | ||
|
||
var defaultOptions = { | ||
outsideAction: _actions.FORMS_OUTSIDE_CLICK | ||
}; | ||
|
||
var middleware = exports.middleware = function middleware(options) { | ||
return function (store) { | ||
options = _extends({}, defaultOptions, options); | ||
|
||
var _options = options, | ||
outsideAction = _options.outsideAction; | ||
|
||
var cancel = void 0; | ||
|
||
if (document) { | ||
document.body.addEventListener('click', function () { | ||
cancel = false; | ||
|
||
setTimeout(function () { | ||
return !cancel && store.dispatch({ type: outsideAction }); | ||
}, 0); | ||
}, true); | ||
} | ||
|
||
return function (next) { | ||
return function (action) { | ||
if ([_actions.FORMS_CANCEL_OUTSIDE_CLICK, _actions.FORMS_TOGGLE_SELECT].indexOf(action.type) !== -1) { | ||
cancel = true; | ||
} | ||
|
||
return next(action); | ||
}; | ||
}; | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
'use strict'; | ||
|
||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.$forms = $forms; | ||
|
||
var _immutable = require('immutable'); | ||
|
||
var _actions = require('./actions'); | ||
|
||
var NEW_FORM = (0, _immutable.Map)({}); | ||
|
||
function $forms() { | ||
var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : (0, _immutable.Map)(); | ||
var action = arguments[1]; | ||
|
||
switch (action.type) { | ||
case _actions.FORMS_OUTSIDE_CLICK: | ||
return state.map(function (form) { | ||
return form.set('$toggles', (0, _immutable.Map)()); | ||
}); | ||
case _actions.FORMS_INITIALIZE: | ||
return state.set(action.form, NEW_FORM.merge({ $values: action.initialValues })); | ||
case _actions.FORMS_UPDATE_VALUE: | ||
return state.update(action.form, (0, _immutable.Map)(), function (form) { | ||
return form.setIn(['$values', action.field], action.value); | ||
}); | ||
case _actions.FORMS_TOGGLE_SELECT: | ||
return state.updateIn([action.form, '$toggles', action.field], function (value) { | ||
return !value; | ||
}); | ||
default: | ||
return state; | ||
} | ||
} |