53 lines
3.2 KiB
JavaScript
53 lines
3.2 KiB
JavaScript
|
"use strict";
|
||
|
|
||
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
||
|
Object.defineProperty(exports, "__esModule", {
|
||
|
value: true
|
||
|
});
|
||
|
exports.default = pickAttrs;
|
||
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
||
|
var attributes = "accept acceptCharset accessKey action allowFullScreen allowTransparency\n alt async autoComplete autoFocus autoPlay capture cellPadding cellSpacing challenge\n charSet checked classID className colSpan cols content contentEditable contextMenu\n controls coords crossOrigin data dateTime default defer dir disabled download draggable\n encType form formAction formEncType formMethod formNoValidate formTarget frameBorder\n headers height hidden high href hrefLang htmlFor httpEquiv icon id inputMode integrity\n is keyParams keyType kind label lang list loop low manifest marginHeight marginWidth max maxLength media\n mediaGroup method min minLength multiple muted name noValidate nonce open\n optimum pattern placeholder poster preload radioGroup readOnly rel required\n reversed role rowSpan rows sandbox scope scoped scrolling seamless selected\n shape size sizes span spellCheck src srcDoc srcLang srcSet start step style\n summary tabIndex target title type useMap value width wmode wrap";
|
||
|
var eventsName = "onCopy onCut onPaste onCompositionEnd onCompositionStart onCompositionUpdate onKeyDown\n onKeyPress onKeyUp onFocus onBlur onChange onInput onSubmit onClick onContextMenu onDoubleClick\n onDrag onDragEnd onDragEnter onDragExit onDragLeave onDragOver onDragStart onDrop onMouseDown\n onMouseEnter onMouseLeave onMouseMove onMouseOut onMouseOver onMouseUp onSelect onTouchCancel\n onTouchEnd onTouchMove onTouchStart onScroll onWheel onAbort onCanPlay onCanPlayThrough\n onDurationChange onEmptied onEncrypted onEnded onError onLoadedData onLoadedMetadata\n onLoadStart onPause onPlay onPlaying onProgress onRateChange onSeeked onSeeking onStalled onSuspend onTimeUpdate onVolumeChange onWaiting onLoad onError";
|
||
|
var propList = "".concat(attributes, " ").concat(eventsName).split(/[\s\n]+/);
|
||
|
|
||
|
/* eslint-enable max-len */
|
||
|
var ariaPrefix = 'aria-';
|
||
|
var dataPrefix = 'data-';
|
||
|
function match(key, prefix) {
|
||
|
return key.indexOf(prefix) === 0;
|
||
|
}
|
||
|
/**
|
||
|
* Picker props from exist props with filter
|
||
|
* @param props Passed props
|
||
|
* @param ariaOnly boolean | { aria?: boolean; data?: boolean; attr?: boolean; } filter config
|
||
|
*/
|
||
|
function pickAttrs(props) {
|
||
|
var ariaOnly = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
||
|
var mergedConfig;
|
||
|
if (ariaOnly === false) {
|
||
|
mergedConfig = {
|
||
|
aria: true,
|
||
|
data: true,
|
||
|
attr: true
|
||
|
};
|
||
|
} else if (ariaOnly === true) {
|
||
|
mergedConfig = {
|
||
|
aria: true
|
||
|
};
|
||
|
} else {
|
||
|
mergedConfig = (0, _objectSpread2.default)({}, ariaOnly);
|
||
|
}
|
||
|
var attrs = {};
|
||
|
Object.keys(props).forEach(function (key) {
|
||
|
if (
|
||
|
// Aria
|
||
|
mergedConfig.aria && (key === 'role' || match(key, ariaPrefix)) ||
|
||
|
// Data
|
||
|
mergedConfig.data && match(key, dataPrefix) ||
|
||
|
// Attr
|
||
|
mergedConfig.attr && propList.includes(key)) {
|
||
|
attrs[key] = props[key];
|
||
|
}
|
||
|
});
|
||
|
return attrs;
|
||
|
}
|