1 | "use strict";
|
2 |
|
3 | var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
4 | Object.defineProperty(exports, "__esModule", {
|
5 | value: true
|
6 | });
|
7 | exports.default = pickAttrs;
|
8 | var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
9 | 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";
|
10 | 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";
|
11 | var propList = "".concat(attributes, " ").concat(eventsName).split(/[\s\n]+/);
|
12 |
|
13 |
|
14 | var ariaPrefix = 'aria-';
|
15 | var dataPrefix = 'data-';
|
16 | function match(key, prefix) {
|
17 | return key.indexOf(prefix) === 0;
|
18 | }
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 | function pickAttrs(props) {
|
25 | var ariaOnly = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
26 | var mergedConfig;
|
27 | if (ariaOnly === false) {
|
28 | mergedConfig = {
|
29 | aria: true,
|
30 | data: true,
|
31 | attr: true
|
32 | };
|
33 | } else if (ariaOnly === true) {
|
34 | mergedConfig = {
|
35 | aria: true
|
36 | };
|
37 | } else {
|
38 | mergedConfig = (0, _objectSpread2.default)({}, ariaOnly);
|
39 | }
|
40 | var attrs = {};
|
41 | Object.keys(props).forEach(function (key) {
|
42 | if (
|
43 |
|
44 | mergedConfig.aria && (key === 'role' || match(key, ariaPrefix)) ||
|
45 |
|
46 | mergedConfig.data && match(key, dataPrefix) ||
|
47 |
|
48 | mergedConfig.attr && propList.includes(key)) {
|
49 | attrs[key] = props[key];
|
50 | }
|
51 | });
|
52 | return attrs;
|
53 | } |
\ | No newline at end of file |