This commit is contained in:
140
node_modules/react-aria-menubutton/dist/Button.js
generated
vendored
Normal file
140
node_modules/react-aria-menubutton/dist/Button.js
generated
vendored
Normal file
@@ -0,0 +1,140 @@
|
||||
'use strict';
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
||||
|
||||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
||||
|
||||
var React = require('react');
|
||||
var PropTypes = require('prop-types');
|
||||
var ManagerContext = require('./ManagerContext');
|
||||
|
||||
var _require = require("./propTypes"),
|
||||
refType = _require.refType;
|
||||
|
||||
var specialAssign = require('./specialAssign');
|
||||
|
||||
var checkedProps = {
|
||||
ambManager: PropTypes.object.isRequired,
|
||||
children: PropTypes.node.isRequired,
|
||||
disabled: PropTypes.bool,
|
||||
forwardedRef: refType,
|
||||
tag: PropTypes.string
|
||||
};
|
||||
|
||||
// List retrieved from https://www.w3schools.com/tags/att_disabled.asp
|
||||
var disabledSupportedTags = function disabledSupportedTags() {
|
||||
return ['button', 'fieldset', 'input', 'optgroup', 'option', 'select', 'textarea'];
|
||||
};
|
||||
|
||||
var AriaMenuButtonButton = function (_React$Component) {
|
||||
_inherits(AriaMenuButtonButton, _React$Component);
|
||||
|
||||
function AriaMenuButtonButton() {
|
||||
var _temp, _this, _ret;
|
||||
|
||||
_classCallCheck(this, AriaMenuButtonButton);
|
||||
|
||||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
||||
args[_key] = arguments[_key];
|
||||
}
|
||||
|
||||
return _ret = (_temp = (_this = _possibleConstructorReturn(this, _React$Component.call.apply(_React$Component, [this].concat(args))), _this), _this.ref = React.createRef(), _this.handleKeyDown = function (event) {
|
||||
if (_this.props.disabled) return;
|
||||
|
||||
var ambManager = _this.props.ambManager;
|
||||
|
||||
switch (event.key) {
|
||||
case 'ArrowDown':
|
||||
event.preventDefault();
|
||||
if (!ambManager.isOpen) {
|
||||
ambManager.openMenu();
|
||||
} else {
|
||||
ambManager.focusItem(0);
|
||||
}
|
||||
break;
|
||||
case 'Enter':
|
||||
case ' ':
|
||||
event.preventDefault();
|
||||
ambManager.toggleMenu();
|
||||
break;
|
||||
case 'Escape':
|
||||
ambManager.handleMenuKey(event);
|
||||
break;
|
||||
default:
|
||||
// (Potential) letter keys
|
||||
ambManager.handleButtonNonArrowKey(event);
|
||||
}
|
||||
}, _this.handleClick = function () {
|
||||
if (_this.props.disabled) return;
|
||||
_this.props.ambManager.toggleMenu({}, { focusMenu: false });
|
||||
}, _this.setRef = function (instance) {
|
||||
_this.ref.current = instance;
|
||||
if (typeof _this.props.forwardedRef === "function") {
|
||||
_this.props.forwardedRef(instance);
|
||||
} else if (_this.props.forwardedRef) {
|
||||
_this.props.forwardedRef.current = instance;
|
||||
}
|
||||
}, _temp), _possibleConstructorReturn(_this, _ret);
|
||||
}
|
||||
|
||||
AriaMenuButtonButton.prototype.componentDidMount = function componentDidMount() {
|
||||
this.props.ambManager.button = this;
|
||||
};
|
||||
|
||||
AriaMenuButtonButton.prototype.componentWillUnmount = function componentWillUnmount() {
|
||||
this.props.ambManager.destroy();
|
||||
};
|
||||
|
||||
AriaMenuButtonButton.prototype.render = function render() {
|
||||
var props = this.props;
|
||||
var ambManager = this.props.ambManager;
|
||||
|
||||
var buttonProps = {
|
||||
// "The menu button itself has a role of button."
|
||||
role: 'button',
|
||||
tabIndex: props.disabled ? '' : '0',
|
||||
// "The menu button has an aria-haspopup property, set to true."
|
||||
'aria-haspopup': true,
|
||||
'aria-expanded': ambManager.isOpen,
|
||||
'aria-disabled': props.disabled,
|
||||
onKeyDown: this.handleKeyDown,
|
||||
onClick: this.handleClick
|
||||
};
|
||||
|
||||
var reserved = {};
|
||||
specialAssign(reserved, checkedProps);
|
||||
// The disabled property should be passed down to the Button element
|
||||
// if the tag has support for disabled attribute. So it needs to be removed
|
||||
// from the reserved property object
|
||||
if (disabledSupportedTags().indexOf(props.tag) >= 0) {
|
||||
delete reserved.disabled;
|
||||
}
|
||||
if (ambManager.options.closeOnBlur) {
|
||||
buttonProps.onBlur = ambManager.handleBlur;
|
||||
}
|
||||
specialAssign(buttonProps, props, reserved);
|
||||
specialAssign(buttonProps, { ref: this.setRef });
|
||||
|
||||
return React.createElement(props.tag, buttonProps, props.children);
|
||||
};
|
||||
|
||||
return AriaMenuButtonButton;
|
||||
}(React.Component);
|
||||
|
||||
AriaMenuButtonButton.propTypes = checkedProps;
|
||||
AriaMenuButtonButton.defaultProps = { tag: 'span' };
|
||||
|
||||
|
||||
module.exports = React.forwardRef(function (props, ref) {
|
||||
return React.createElement(ManagerContext.Consumer, null, function (ambManager) {
|
||||
var buttonProps = { ambManager: ambManager, forwardedRef: ref };
|
||||
specialAssign(buttonProps, props, {
|
||||
ambManager: checkedProps.ambManager,
|
||||
children: checkedProps.children,
|
||||
forwardedRef: checkedProps.forwardedRef
|
||||
});
|
||||
return React.createElement(AriaMenuButtonButton, buttonProps, props.children);
|
||||
});
|
||||
});
|
||||
7
node_modules/react-aria-menubutton/dist/ManagerContext.js
generated
vendored
Normal file
7
node_modules/react-aria-menubutton/dist/ManagerContext.js
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
var React = require('react');
|
||||
|
||||
var AriaMenuButtonManagerContext = React.createContext();
|
||||
|
||||
module.exports = AriaMenuButtonManagerContext;
|
||||
131
node_modules/react-aria-menubutton/dist/Menu.js
generated
vendored
Normal file
131
node_modules/react-aria-menubutton/dist/Menu.js
generated
vendored
Normal file
@@ -0,0 +1,131 @@
|
||||
'use strict';
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
||||
|
||||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
||||
|
||||
var React = require('react');
|
||||
var PropTypes = require('prop-types');
|
||||
var createTapListener = require('teeny-tap');
|
||||
var ManagerContext = require('./ManagerContext');
|
||||
|
||||
var _require = require("./propTypes"),
|
||||
refType = _require.refType;
|
||||
|
||||
var specialAssign = require('./specialAssign');
|
||||
|
||||
var checkedProps = {
|
||||
ambManager: PropTypes.object.isRequired,
|
||||
children: PropTypes.oneOfType([PropTypes.func, PropTypes.node]).isRequired,
|
||||
forwardedRef: refType,
|
||||
tag: PropTypes.string
|
||||
};
|
||||
|
||||
var AriaMenuButtonMenu = function (_React$Component) {
|
||||
_inherits(AriaMenuButtonMenu, _React$Component);
|
||||
|
||||
function AriaMenuButtonMenu() {
|
||||
var _temp, _this, _ret;
|
||||
|
||||
_classCallCheck(this, AriaMenuButtonMenu);
|
||||
|
||||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
||||
args[_key] = arguments[_key];
|
||||
}
|
||||
|
||||
return _ret = (_temp = (_this = _possibleConstructorReturn(this, _React$Component.call.apply(_React$Component, [this].concat(args))), _this), _this.ref = React.createRef(), _this.addTapListener = function () {
|
||||
var el = _this.ref.current;
|
||||
if (!el) return;
|
||||
var doc = el.ownerDocument;
|
||||
if (!doc) return;
|
||||
_this.tapListener = createTapListener(doc.documentElement, _this.handleTap);
|
||||
}, _this.handleTap = function (event) {
|
||||
if (_this.ref.current.contains(event.target)) return;
|
||||
if (_this.props.ambManager.button.ref.current.contains(event.target)) return;
|
||||
_this.props.ambManager.closeMenu();
|
||||
}, _this.setRef = function (instance) {
|
||||
_this.ref.current = instance;
|
||||
if (typeof _this.props.forwardedRef === "function") {
|
||||
_this.props.forwardedRef(instance);
|
||||
} else if (_this.props.forwardedRef) {
|
||||
_this.props.forwardedRef.current = instance;
|
||||
}
|
||||
}, _temp), _possibleConstructorReturn(_this, _ret);
|
||||
}
|
||||
|
||||
AriaMenuButtonMenu.prototype.componentDidMount = function componentDidMount() {
|
||||
this.props.ambManager.menu = this;
|
||||
};
|
||||
|
||||
AriaMenuButtonMenu.prototype.componentDidUpdate = function componentDidUpdate() {
|
||||
var ambManager = this.props.ambManager;
|
||||
if (!ambManager.options.closeOnBlur) return;
|
||||
if (ambManager.isOpen && !this.tapListener) {
|
||||
this.addTapListener();
|
||||
} else if (!ambManager.isOpen && this.tapListener) {
|
||||
this.tapListener.remove();
|
||||
delete this.tapListener;
|
||||
}
|
||||
|
||||
if (!ambManager.isOpen) {
|
||||
// Clear the ambManager's items, so they
|
||||
// can be reloaded next time this menu opens
|
||||
ambManager.clearItems();
|
||||
}
|
||||
};
|
||||
|
||||
AriaMenuButtonMenu.prototype.componentWillUnmount = function componentWillUnmount() {
|
||||
if (this.tapListener) this.tapListener.remove();
|
||||
this.props.ambManager.destroy();
|
||||
};
|
||||
|
||||
AriaMenuButtonMenu.prototype.render = function render() {
|
||||
var props = this.props;
|
||||
var ambManager = this.props.ambManager;
|
||||
|
||||
var childrenToRender = function () {
|
||||
if (typeof props.children === 'function') {
|
||||
return props.children({ isOpen: ambManager.isOpen });
|
||||
}
|
||||
if (ambManager.isOpen) return props.children;
|
||||
return false;
|
||||
}();
|
||||
|
||||
if (!childrenToRender) return false;
|
||||
|
||||
var menuProps = {
|
||||
onKeyDown: ambManager.handleMenuKey,
|
||||
role: 'menu',
|
||||
tabIndex: -1
|
||||
};
|
||||
|
||||
if (ambManager.options.closeOnBlur) {
|
||||
menuProps.onBlur = ambManager.handleBlur;
|
||||
}
|
||||
|
||||
specialAssign(menuProps, props, checkedProps);
|
||||
specialAssign(menuProps, { ref: this.setRef });
|
||||
|
||||
return React.createElement(props.tag, menuProps, childrenToRender);
|
||||
};
|
||||
|
||||
return AriaMenuButtonMenu;
|
||||
}(React.Component);
|
||||
|
||||
AriaMenuButtonMenu.propTypes = checkedProps;
|
||||
AriaMenuButtonMenu.defaultProps = { tag: 'div' };
|
||||
|
||||
|
||||
module.exports = React.forwardRef(function (props, ref) {
|
||||
return React.createElement(ManagerContext.Consumer, null, function (ambManager) {
|
||||
var buttonProps = { ambManager: ambManager, forwardedRef: ref };
|
||||
specialAssign(buttonProps, props, {
|
||||
ambManager: checkedProps.ambManager,
|
||||
children: checkedProps.children,
|
||||
forwardedRef: checkedProps.forwardedRef
|
||||
});
|
||||
return React.createElement(AriaMenuButtonMenu, buttonProps, props.children);
|
||||
});
|
||||
});
|
||||
96
node_modules/react-aria-menubutton/dist/MenuItem.js
generated
vendored
Normal file
96
node_modules/react-aria-menubutton/dist/MenuItem.js
generated
vendored
Normal file
@@ -0,0 +1,96 @@
|
||||
'use strict';
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
||||
|
||||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
||||
|
||||
var React = require('react');
|
||||
var PropTypes = require('prop-types');
|
||||
var ManagerContext = require('./ManagerContext');
|
||||
|
||||
var _require = require("./propTypes"),
|
||||
refType = _require.refType;
|
||||
|
||||
var specialAssign = require('./specialAssign');
|
||||
|
||||
var checkedProps = {
|
||||
ambManager: PropTypes.object.isRequired,
|
||||
children: PropTypes.node.isRequired,
|
||||
forwardedRef: refType,
|
||||
tag: PropTypes.string,
|
||||
text: PropTypes.string,
|
||||
value: PropTypes.any
|
||||
};
|
||||
|
||||
var AriaMenuButtonMenuItem = function (_React$Component) {
|
||||
_inherits(AriaMenuButtonMenuItem, _React$Component);
|
||||
|
||||
function AriaMenuButtonMenuItem() {
|
||||
var _temp, _this, _ret;
|
||||
|
||||
_classCallCheck(this, AriaMenuButtonMenuItem);
|
||||
|
||||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
||||
args[_key] = arguments[_key];
|
||||
}
|
||||
|
||||
return _ret = (_temp = (_this = _possibleConstructorReturn(this, _React$Component.call.apply(_React$Component, [this].concat(args))), _this), _this.ref = React.createRef(), _this.handleKeyDown = function (event) {
|
||||
if (event.key !== 'Enter' && event.key !== ' ') return;
|
||||
if (_this.props.tag === 'a' && _this.props.href) return;
|
||||
event.preventDefault();
|
||||
_this.selectItem(event);
|
||||
}, _this.selectItem = function (event) {
|
||||
// If there's no value, we'll send the child
|
||||
var value = typeof _this.props.value !== 'undefined' ? _this.props.value : _this.props.children;
|
||||
_this.props.ambManager.handleSelection(value, event);
|
||||
}, _this.setRef = function (instance) {
|
||||
_this.ref.current = instance;
|
||||
if (typeof _this.props.forwardedRef === "function") {
|
||||
_this.props.forwardedRef(instance);
|
||||
} else if (_this.props.forwardedRef) {
|
||||
_this.props.forwardedRef.current = instance;
|
||||
}
|
||||
}, _temp), _possibleConstructorReturn(_this, _ret);
|
||||
}
|
||||
|
||||
AriaMenuButtonMenuItem.prototype.componentDidMount = function componentDidMount() {
|
||||
this.props.ambManager.addItem({
|
||||
node: this.ref.current,
|
||||
text: this.props.text
|
||||
});
|
||||
};
|
||||
|
||||
AriaMenuButtonMenuItem.prototype.render = function render() {
|
||||
var menuItemProps = {
|
||||
onClick: this.selectItem,
|
||||
onKeyDown: this.handleKeyDown,
|
||||
role: 'menuitem',
|
||||
tabIndex: '-1',
|
||||
ref: this.setRef
|
||||
};
|
||||
|
||||
specialAssign(menuItemProps, this.props, checkedProps);
|
||||
|
||||
return React.createElement(this.props.tag, menuItemProps, this.props.children);
|
||||
};
|
||||
|
||||
return AriaMenuButtonMenuItem;
|
||||
}(React.Component);
|
||||
|
||||
AriaMenuButtonMenuItem.propTypes = checkedProps;
|
||||
AriaMenuButtonMenuItem.defaultProps = { tag: 'div' };
|
||||
|
||||
|
||||
module.exports = React.forwardRef(function (props, ref) {
|
||||
return React.createElement(ManagerContext.Consumer, null, function (ambManager) {
|
||||
var buttonProps = { ambManager: ambManager, forwardedRef: ref };
|
||||
specialAssign(buttonProps, props, {
|
||||
ambManager: checkedProps.ambManager,
|
||||
children: checkedProps.children,
|
||||
forwardedRef: checkedProps.forwardedRef
|
||||
});
|
||||
return React.createElement(AriaMenuButtonMenuItem, buttonProps, props.children);
|
||||
});
|
||||
});
|
||||
74
node_modules/react-aria-menubutton/dist/Wrapper.js
generated
vendored
Normal file
74
node_modules/react-aria-menubutton/dist/Wrapper.js
generated
vendored
Normal file
@@ -0,0 +1,74 @@
|
||||
'use strict';
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
||||
|
||||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
||||
|
||||
var React = require('react');
|
||||
var PropTypes = require('prop-types');
|
||||
var createManager = require('./createManager');
|
||||
var ManagerContext = require('./ManagerContext');
|
||||
|
||||
var _require = require("./propTypes"),
|
||||
refType = _require.refType;
|
||||
|
||||
var specialAssign = require('./specialAssign');
|
||||
|
||||
var checkedProps = {
|
||||
children: PropTypes.node.isRequired,
|
||||
forwardedRef: refType,
|
||||
onMenuToggle: PropTypes.func,
|
||||
onSelection: PropTypes.func,
|
||||
closeOnSelection: PropTypes.bool,
|
||||
closeOnBlur: PropTypes.bool,
|
||||
tag: PropTypes.string
|
||||
};
|
||||
|
||||
var managerOptionsFromProps = function managerOptionsFromProps(props) {
|
||||
return {
|
||||
onMenuToggle: props.onMenuToggle,
|
||||
onSelection: props.onSelection,
|
||||
closeOnSelection: props.closeOnSelection,
|
||||
closeOnBlur: props.closeOnBlur,
|
||||
id: props.id
|
||||
};
|
||||
};
|
||||
|
||||
var AriaMenuButtonWrapper = function (_React$Component) {
|
||||
_inherits(AriaMenuButtonWrapper, _React$Component);
|
||||
|
||||
function AriaMenuButtonWrapper(props) {
|
||||
_classCallCheck(this, AriaMenuButtonWrapper);
|
||||
|
||||
var _this = _possibleConstructorReturn(this, _React$Component.call(this, props));
|
||||
|
||||
_this.manager = createManager(managerOptionsFromProps(props));
|
||||
return _this;
|
||||
}
|
||||
|
||||
AriaMenuButtonWrapper.prototype.componentDidUpdate = function componentDidUpdate() {
|
||||
this.manager.updateOptions(managerOptionsFromProps(this.props));
|
||||
};
|
||||
|
||||
AriaMenuButtonWrapper.prototype.render = function render() {
|
||||
var wrapperProps = {};
|
||||
specialAssign(wrapperProps, this.props, checkedProps);
|
||||
|
||||
return React.createElement(ManagerContext.Provider, { value: this.manager }, React.createElement(this.props.tag, wrapperProps, this.props.children));
|
||||
};
|
||||
|
||||
return AriaMenuButtonWrapper;
|
||||
}(React.Component);
|
||||
|
||||
AriaMenuButtonWrapper.propTypes = checkedProps;
|
||||
AriaMenuButtonWrapper.defaultProps = { tag: 'div' };
|
||||
|
||||
|
||||
module.exports = React.forwardRef(function (props, ref) {
|
||||
var wrapperProps = { forwardedRef: ref };
|
||||
specialAssign(wrapperProps, props, { children: checkedProps.children, forwardedRef: checkedProps.forwardedRef });
|
||||
specialAssign(wrapperProps, { forwardedRef: ref });
|
||||
return React.createElement(AriaMenuButtonWrapper, wrapperProps, props.children);
|
||||
});
|
||||
163
node_modules/react-aria-menubutton/dist/createManager.js
generated
vendored
Normal file
163
node_modules/react-aria-menubutton/dist/createManager.js
generated
vendored
Normal file
@@ -0,0 +1,163 @@
|
||||
'use strict';
|
||||
|
||||
var createFocusGroup = require('focus-group');
|
||||
var externalStateControl = require('./externalStateControl');
|
||||
|
||||
var focusGroupOptions = {
|
||||
wrap: true,
|
||||
stringSearch: true
|
||||
};
|
||||
|
||||
var protoManager = {
|
||||
init: function init(options) {
|
||||
this.updateOptions(options);
|
||||
|
||||
this.handleBlur = handleBlur.bind(this);
|
||||
this.handleSelection = handleSelection.bind(this);
|
||||
this.handleMenuKey = handleMenuKey.bind(this);
|
||||
|
||||
// "With focus on the drop-down menu, the Up and Down Arrow
|
||||
// keys move focus within the menu items, "wrapping" at the top and bottom."
|
||||
// "Typing a letter (printable character) key moves focus to the next
|
||||
// instance of a visible node whose title begins with that printable letter."
|
||||
//
|
||||
// All of the above is handled by focus-group.
|
||||
this.focusGroup = createFocusGroup(focusGroupOptions);
|
||||
|
||||
// These component references are added when the relevant components mount
|
||||
this.button = null;
|
||||
this.menu = null;
|
||||
|
||||
// State trackers
|
||||
this.isOpen = false;
|
||||
},
|
||||
updateOptions: function updateOptions(options) {
|
||||
var oldOptions = this.options;
|
||||
|
||||
this.options = options || this.options || {};
|
||||
|
||||
if (typeof this.options.closeOnSelection === 'undefined') {
|
||||
this.options.closeOnSelection = true;
|
||||
}
|
||||
|
||||
if (typeof this.options.closeOnBlur === 'undefined') {
|
||||
this.options.closeOnBlur = true;
|
||||
}
|
||||
|
||||
if (this.options.id) {
|
||||
externalStateControl.registerManager(this.options.id, this);
|
||||
}
|
||||
|
||||
if (oldOptions && oldOptions.id && oldOptions.id !== this.options.id) {
|
||||
externalStateControl.unregisterManager(this.options.id, this);
|
||||
}
|
||||
},
|
||||
focusItem: function focusItem(index) {
|
||||
this.focusGroup.focusNodeAtIndex(index);
|
||||
},
|
||||
addItem: function addItem(item) {
|
||||
this.focusGroup.addMember(item);
|
||||
},
|
||||
clearItems: function clearItems() {
|
||||
this.focusGroup.clearMembers();
|
||||
},
|
||||
handleButtonNonArrowKey: function handleButtonNonArrowKey(event) {
|
||||
this.focusGroup._handleUnboundKey(event);
|
||||
},
|
||||
destroy: function destroy() {
|
||||
this.button = null;
|
||||
this.menu = null;
|
||||
this.focusGroup.deactivate();
|
||||
clearTimeout(this.blurTimer);
|
||||
clearTimeout(this.moveFocusTimer);
|
||||
},
|
||||
update: function update() {
|
||||
this.menu.setState({ isOpen: this.isOpen });
|
||||
this.button.setState({ menuOpen: this.isOpen });
|
||||
this.options.onMenuToggle && this.options.onMenuToggle({ isOpen: this.isOpen });
|
||||
},
|
||||
openMenu: function openMenu(openOptions) {
|
||||
if (this.isOpen) return;
|
||||
openOptions = openOptions || {};
|
||||
if (openOptions.focusMenu === undefined) {
|
||||
openOptions.focusMenu = true;
|
||||
}
|
||||
this.isOpen = true;
|
||||
this.update();
|
||||
this.focusGroup.activate();
|
||||
if (openOptions.focusMenu) {
|
||||
var self = this;
|
||||
this.moveFocusTimer = setTimeout(function () {
|
||||
self.focusItem(0);
|
||||
}, 0);
|
||||
}
|
||||
},
|
||||
closeMenu: function closeMenu(closeOptions) {
|
||||
if (!this.isOpen) return;
|
||||
closeOptions = closeOptions || {};
|
||||
this.isOpen = false;
|
||||
this.update();
|
||||
if (closeOptions.focusButton) {
|
||||
this.button.ref.current.focus();
|
||||
}
|
||||
},
|
||||
toggleMenu: function toggleMenu(closeOptions, openOptions) {
|
||||
closeOptions = closeOptions || {};
|
||||
openOptions = openOptions || {};
|
||||
if (this.isOpen) {
|
||||
this.closeMenu(closeOptions);
|
||||
} else {
|
||||
this.openMenu(openOptions);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
function handleBlur() {
|
||||
var self = this;
|
||||
self.blurTimer = setTimeout(function () {
|
||||
if (!self.button) return;
|
||||
var buttonNode = self.button.ref.current;
|
||||
if (!buttonNode) return;
|
||||
var activeEl = buttonNode.ownerDocument.activeElement;
|
||||
if (buttonNode && activeEl === buttonNode) return;
|
||||
var menuNode = self.menu.ref.current;
|
||||
if (menuNode === activeEl) {
|
||||
self.focusItem(0);
|
||||
return;
|
||||
}
|
||||
if (menuNode && menuNode.contains(activeEl)) return;
|
||||
if (self.isOpen) self.closeMenu({ focusButton: false });
|
||||
}, 0);
|
||||
}
|
||||
|
||||
function handleSelection(value, event) {
|
||||
if (this.options.closeOnSelection) this.closeMenu({ focusButton: true });
|
||||
if (this.options.onSelection) this.options.onSelection(value, event);
|
||||
}
|
||||
|
||||
function handleMenuKey(event) {
|
||||
if (this.isOpen) {
|
||||
switch (event.key) {
|
||||
// With focus on the drop-down menu, pressing Escape closes
|
||||
// the menu and returns focus to the button.
|
||||
case 'Escape':
|
||||
event.preventDefault();
|
||||
this.closeMenu({ focusButton: true });
|
||||
break;
|
||||
case 'Home':
|
||||
event.preventDefault();
|
||||
this.focusGroup.moveFocusToFirst();
|
||||
break;
|
||||
case 'End':
|
||||
event.preventDefault();
|
||||
this.focusGroup.moveFocusToLast();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = function (options) {
|
||||
var newManager = Object.create(protoManager);
|
||||
newManager.init(options);
|
||||
return newManager;
|
||||
};
|
||||
32
node_modules/react-aria-menubutton/dist/externalStateControl.js
generated
vendored
Normal file
32
node_modules/react-aria-menubutton/dist/externalStateControl.js
generated
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
'use strict';
|
||||
|
||||
var registeredManagers = {};
|
||||
|
||||
var errorCommon = 'a menu outside a mounted Wrapper with an id, or a menu that does not exist';
|
||||
|
||||
function registerManager(menuId, manager) {
|
||||
registeredManagers[menuId] = manager;
|
||||
}
|
||||
|
||||
function unregisterManager(menuId) {
|
||||
delete registeredManagers[menuId];
|
||||
}
|
||||
|
||||
function openMenu(menuId, openOptions) {
|
||||
var manager = registeredManagers[menuId];
|
||||
if (!manager) throw new Error('Cannot open ' + errorCommon);
|
||||
manager.openMenu(openOptions);
|
||||
}
|
||||
|
||||
function closeMenu(menuId, closeOptions) {
|
||||
var manager = registeredManagers[menuId];
|
||||
if (!manager) throw new Error('Cannot close ' + errorCommon);
|
||||
manager.closeMenu(closeOptions);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
registerManager: registerManager,
|
||||
unregisterManager: unregisterManager,
|
||||
openMenu: openMenu,
|
||||
closeMenu: closeMenu
|
||||
};
|
||||
12
node_modules/react-aria-menubutton/dist/index.js
generated
vendored
Normal file
12
node_modules/react-aria-menubutton/dist/index.js
generated
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
'use strict';
|
||||
|
||||
var externalStateControl = require('./externalStateControl');
|
||||
|
||||
module.exports = {
|
||||
Wrapper: require('./Wrapper'),
|
||||
Button: require('./Button'),
|
||||
Menu: require('./Menu'),
|
||||
MenuItem: require('./MenuItem'),
|
||||
openMenu: externalStateControl.openMenu,
|
||||
closeMenu: externalStateControl.closeMenu
|
||||
};
|
||||
7
node_modules/react-aria-menubutton/dist/propTypes.js
generated
vendored
Normal file
7
node_modules/react-aria-menubutton/dist/propTypes.js
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
"use strict";
|
||||
|
||||
var PropTypes = require("prop-types");
|
||||
|
||||
module.exports = {
|
||||
refType: PropTypes.oneOfType([PropTypes.func, PropTypes.shape({ current: PropTypes.elementType })])
|
||||
};
|
||||
11
node_modules/react-aria-menubutton/dist/specialAssign.js
generated
vendored
Normal file
11
node_modules/react-aria-menubutton/dist/specialAssign.js
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
"use strict";
|
||||
|
||||
module.exports = function (a, b, reserved) {
|
||||
reserved = reserved || {};
|
||||
// This will get id, className, style, etc.
|
||||
for (var x in b) {
|
||||
if (!b.hasOwnProperty(x)) continue;
|
||||
if (reserved[x]) continue;
|
||||
a[x] = b[x];
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user