@rc-component/util 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +22 -0
- package/README.md +303 -0
- package/es/Children/toArray.d.ts +5 -0
- package/es/Children/toArray.js +19 -0
- package/es/Dom/canUseDom.d.ts +1 -0
- package/es/Dom/canUseDom.js +3 -0
- package/es/Dom/contains.d.ts +1 -0
- package/es/Dom/contains.js +20 -0
- package/es/Dom/dynamicCSS.d.ts +25 -0
- package/es/Dom/dynamicCSS.js +153 -0
- package/es/Dom/findDOMNode.d.ts +12 -0
- package/es/Dom/findDOMNode.js +36 -0
- package/es/Dom/focus.d.ts +8 -0
- package/es/Dom/focus.js +87 -0
- package/es/Dom/isVisible.d.ts +2 -0
- package/es/Dom/isVisible.js +27 -0
- package/es/Dom/scrollLocker.d.ts +12 -0
- package/es/Dom/scrollLocker.js +135 -0
- package/es/Dom/shadow.d.ts +8 -0
- package/es/Dom/shadow.js +18 -0
- package/es/Dom/styleChecker.d.ts +2 -0
- package/es/Dom/styleChecker.js +26 -0
- package/es/KeyCode.d.ts +436 -0
- package/es/KeyCode.js +538 -0
- package/es/Portal.d.ts +9 -0
- package/es/Portal.js +44 -0
- package/es/PortalWrapper.d.ts +51 -0
- package/es/PortalWrapper.js +217 -0
- package/es/React/isFragment.d.ts +4 -0
- package/es/React/isFragment.js +18 -0
- package/es/React/render.d.ts +13 -0
- package/es/React/render.js +114 -0
- package/es/composeProps.d.ts +2 -0
- package/es/composeProps.js +24 -0
- package/es/getScrollBarSize.d.ts +7 -0
- package/es/getScrollBarSize.js +76 -0
- package/es/hooks/useEffect.d.ts +2 -0
- package/es/hooks/useEffect.js +14 -0
- package/es/hooks/useEvent.d.ts +2 -0
- package/es/hooks/useEvent.js +16 -0
- package/es/hooks/useId.d.ts +4 -0
- package/es/hooks/useId.js +69 -0
- package/es/hooks/useLayoutEffect.d.ts +4 -0
- package/es/hooks/useLayoutEffect.js +30 -0
- package/es/hooks/useMemo.d.ts +1 -0
- package/es/hooks/useMemo.js +9 -0
- package/es/hooks/useMergedState.d.ts +12 -0
- package/es/hooks/useMergedState.js +68 -0
- package/es/hooks/useMobile.d.ts +6 -0
- package/es/hooks/useMobile.js +25 -0
- package/es/hooks/useState.d.ts +14 -0
- package/es/hooks/useState.js +32 -0
- package/es/hooks/useSyncState.d.ts +9 -0
- package/es/hooks/useSyncState.js +29 -0
- package/es/index.d.ts +6 -0
- package/es/index.js +6 -0
- package/es/isEqual.d.ts +9 -0
- package/es/isEqual.js +55 -0
- package/es/isMobile.d.ts +2 -0
- package/es/isMobile.js +7 -0
- package/es/omit.d.ts +1 -0
- package/es/omit.js +9 -0
- package/es/pickAttrs.d.ts +11 -0
- package/es/pickAttrs.js +51 -0
- package/es/proxyObject.d.ts +4 -0
- package/es/proxyObject.js +19 -0
- package/es/raf.d.ts +6 -0
- package/es/raf.js +54 -0
- package/es/ref.d.ts +19 -0
- package/es/ref.js +89 -0
- package/es/setStyle.d.ts +12 -0
- package/es/setStyle.js +26 -0
- package/es/test/domHook.d.ts +8 -0
- package/es/test/domHook.js +64 -0
- package/es/utils/get.d.ts +1 -0
- package/es/utils/get.js +10 -0
- package/es/utils/set.d.ts +6 -0
- package/es/utils/set.js +93 -0
- package/es/warning.d.ts +32 -0
- package/es/warning.js +68 -0
- package/lib/Children/toArray.d.ts +5 -0
- package/lib/Children/toArray.js +26 -0
- package/lib/Dom/canUseDom.d.ts +1 -0
- package/lib/Dom/canUseDom.js +9 -0
- package/lib/Dom/contains.d.ts +1 -0
- package/lib/Dom/contains.js +26 -0
- package/lib/Dom/dynamicCSS.d.ts +25 -0
- package/lib/Dom/dynamicCSS.js +163 -0
- package/lib/Dom/findDOMNode.d.ts +12 -0
- package/lib/Dom/findDOMNode.js +45 -0
- package/lib/Dom/focus.d.ts +8 -0
- package/lib/Dom/focus.js +98 -0
- package/lib/Dom/isVisible.d.ts +2 -0
- package/lib/Dom/isVisible.js +33 -0
- package/lib/Dom/scrollLocker.d.ts +12 -0
- package/lib/Dom/scrollLocker.js +141 -0
- package/lib/Dom/shadow.d.ts +8 -0
- package/lib/Dom/shadow.js +25 -0
- package/lib/Dom/styleChecker.d.ts +2 -0
- package/lib/Dom/styleChecker.js +33 -0
- package/lib/KeyCode.d.ts +436 -0
- package/lib/KeyCode.js +544 -0
- package/lib/Portal.d.ts +9 -0
- package/lib/Portal.js +51 -0
- package/lib/PortalWrapper.d.ts +51 -0
- package/lib/PortalWrapper.js +226 -0
- package/lib/React/isFragment.d.ts +4 -0
- package/lib/React/isFragment.js +24 -0
- package/lib/React/render.d.ts +13 -0
- package/lib/React/render.js +125 -0
- package/lib/composeProps.d.ts +2 -0
- package/lib/composeProps.js +30 -0
- package/lib/getScrollBarSize.d.ts +7 -0
- package/lib/getScrollBarSize.js +84 -0
- package/lib/hooks/useEffect.d.ts +2 -0
- package/lib/hooks/useEffect.js +22 -0
- package/lib/hooks/useEvent.d.ts +2 -0
- package/lib/hooks/useEvent.js +26 -0
- package/lib/hooks/useId.d.ts +4 -0
- package/lib/hooks/useId.js +78 -0
- package/lib/hooks/useLayoutEffect.d.ts +4 -0
- package/lib/hooks/useLayoutEffect.js +39 -0
- package/lib/hooks/useMemo.d.ts +1 -0
- package/lib/hooks/useMemo.js +18 -0
- package/lib/hooks/useMergedState.d.ts +12 -0
- package/lib/hooks/useMergedState.js +75 -0
- package/lib/hooks/useMobile.d.ts +6 -0
- package/lib/hooks/useMobile.js +31 -0
- package/lib/hooks/useState.d.ts +14 -0
- package/lib/hooks/useState.js +41 -0
- package/lib/hooks/useSyncState.d.ts +9 -0
- package/lib/hooks/useSyncState.js +39 -0
- package/lib/index.d.ts +6 -0
- package/lib/index.js +60 -0
- package/lib/isEqual.d.ts +9 -0
- package/lib/isEqual.js +61 -0
- package/lib/isMobile.d.ts +2 -0
- package/lib/isMobile.js +13 -0
- package/lib/omit.d.ts +1 -0
- package/lib/omit.js +15 -0
- package/lib/pickAttrs.d.ts +11 -0
- package/lib/pickAttrs.js +57 -0
- package/lib/proxyObject.d.ts +4 -0
- package/lib/proxyObject.js +25 -0
- package/lib/raf.d.ts +6 -0
- package/lib/raf.js +60 -0
- package/lib/ref.d.ts +19 -0
- package/lib/ref.js +96 -0
- package/lib/setStyle.d.ts +12 -0
- package/lib/setStyle.js +32 -0
- package/lib/test/domHook.d.ts +8 -0
- package/lib/test/domHook.js +71 -0
- package/lib/utils/get.d.ts +1 -0
- package/lib/utils/get.js +16 -0
- package/lib/utils/set.d.ts +6 -0
- package/lib/utils/set.js +101 -0
- package/lib/warning.d.ts +32 -0
- package/lib/warning.js +81 -0
- package/package.json +76 -0
package/lib/pickAttrs.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = pickAttrs;
|
|
7
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
8
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
9
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
10
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
11
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
12
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
13
|
+
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";
|
|
14
|
+
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";
|
|
15
|
+
var propList = "".concat(attributes, " ").concat(eventsName).split(/[\s\n]+/);
|
|
16
|
+
|
|
17
|
+
/* eslint-enable max-len */
|
|
18
|
+
var ariaPrefix = 'aria-';
|
|
19
|
+
var dataPrefix = 'data-';
|
|
20
|
+
function match(key, prefix) {
|
|
21
|
+
return key.indexOf(prefix) === 0;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Picker props from exist props with filter
|
|
25
|
+
* @param props Passed props
|
|
26
|
+
* @param ariaOnly boolean | { aria?: boolean; data?: boolean; attr?: boolean; } filter config
|
|
27
|
+
*/
|
|
28
|
+
function pickAttrs(props) {
|
|
29
|
+
var ariaOnly = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
30
|
+
var mergedConfig;
|
|
31
|
+
if (ariaOnly === false) {
|
|
32
|
+
mergedConfig = {
|
|
33
|
+
aria: true,
|
|
34
|
+
data: true,
|
|
35
|
+
attr: true
|
|
36
|
+
};
|
|
37
|
+
} else if (ariaOnly === true) {
|
|
38
|
+
mergedConfig = {
|
|
39
|
+
aria: true
|
|
40
|
+
};
|
|
41
|
+
} else {
|
|
42
|
+
mergedConfig = _objectSpread({}, ariaOnly);
|
|
43
|
+
}
|
|
44
|
+
var attrs = {};
|
|
45
|
+
Object.keys(props).forEach(function (key) {
|
|
46
|
+
if (
|
|
47
|
+
// Aria
|
|
48
|
+
mergedConfig.aria && (key === 'role' || match(key, ariaPrefix)) ||
|
|
49
|
+
// Data
|
|
50
|
+
mergedConfig.data && match(key, dataPrefix) ||
|
|
51
|
+
// Attr
|
|
52
|
+
mergedConfig.attr && propList.includes(key)) {
|
|
53
|
+
attrs[key] = props[key];
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
return attrs;
|
|
57
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = proxyObject;
|
|
7
|
+
/**
|
|
8
|
+
* Proxy object if environment supported
|
|
9
|
+
*/
|
|
10
|
+
function proxyObject(obj, extendProps) {
|
|
11
|
+
if (typeof Proxy !== 'undefined' && obj) {
|
|
12
|
+
return new Proxy(obj, {
|
|
13
|
+
get: function get(target, prop) {
|
|
14
|
+
if (extendProps[prop]) {
|
|
15
|
+
return extendProps[prop];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// Proxy origin property
|
|
19
|
+
var originProp = target[prop];
|
|
20
|
+
return typeof originProp === 'function' ? originProp.bind(target) : originProp;
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
return obj;
|
|
25
|
+
}
|
package/lib/raf.d.ts
ADDED
package/lib/raf.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var raf = function raf(callback) {
|
|
8
|
+
return +setTimeout(callback, 16);
|
|
9
|
+
};
|
|
10
|
+
var caf = function caf(num) {
|
|
11
|
+
return clearTimeout(num);
|
|
12
|
+
};
|
|
13
|
+
if (typeof window !== 'undefined' && 'requestAnimationFrame' in window) {
|
|
14
|
+
raf = function raf(callback) {
|
|
15
|
+
return window.requestAnimationFrame(callback);
|
|
16
|
+
};
|
|
17
|
+
caf = function caf(handle) {
|
|
18
|
+
return window.cancelAnimationFrame(handle);
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
var rafUUID = 0;
|
|
22
|
+
var rafIds = new Map();
|
|
23
|
+
function cleanup(id) {
|
|
24
|
+
rafIds.delete(id);
|
|
25
|
+
}
|
|
26
|
+
var wrapperRaf = function wrapperRaf(callback) {
|
|
27
|
+
var times = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
|
|
28
|
+
rafUUID += 1;
|
|
29
|
+
var id = rafUUID;
|
|
30
|
+
function callRef(leftTimes) {
|
|
31
|
+
if (leftTimes === 0) {
|
|
32
|
+
// Clean up
|
|
33
|
+
cleanup(id);
|
|
34
|
+
|
|
35
|
+
// Trigger
|
|
36
|
+
callback();
|
|
37
|
+
} else {
|
|
38
|
+
// Next raf
|
|
39
|
+
var realId = raf(function () {
|
|
40
|
+
callRef(leftTimes - 1);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
// Bind real raf id
|
|
44
|
+
rafIds.set(id, realId);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
callRef(times);
|
|
48
|
+
return id;
|
|
49
|
+
};
|
|
50
|
+
wrapperRaf.cancel = function (id) {
|
|
51
|
+
var realId = rafIds.get(id);
|
|
52
|
+
cleanup(id);
|
|
53
|
+
return caf(realId);
|
|
54
|
+
};
|
|
55
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
56
|
+
wrapperRaf.ids = function () {
|
|
57
|
+
return rafIds;
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
var _default = exports.default = wrapperRaf;
|
package/lib/ref.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type * as React from 'react';
|
|
2
|
+
export declare const fillRef: <T>(ref: React.Ref<T>, node: T) => void;
|
|
3
|
+
/**
|
|
4
|
+
* Merge refs into one ref function to support ref passing.
|
|
5
|
+
*/
|
|
6
|
+
export declare const composeRef: <T>(...refs: React.Ref<T>[]) => React.Ref<T>;
|
|
7
|
+
export declare const useComposeRef: <T>(...refs: React.Ref<T>[]) => React.Ref<T>;
|
|
8
|
+
export declare const supportRef: (nodeOrComponent: any) => boolean;
|
|
9
|
+
interface RefAttributes<T> extends React.Attributes {
|
|
10
|
+
ref: React.Ref<T>;
|
|
11
|
+
}
|
|
12
|
+
export declare const supportNodeRef: <T = any>(node: React.ReactNode) => node is React.ReactElement<any, string | React.JSXElementConstructor<any>> & RefAttributes<T>;
|
|
13
|
+
/**
|
|
14
|
+
* In React 19. `ref` is not a property from node.
|
|
15
|
+
* But a property from `props.ref`.
|
|
16
|
+
* To check if `props.ref` exist or fallback to `ref`.
|
|
17
|
+
*/
|
|
18
|
+
export declare const getNodeRef: <T = any>(node: React.ReactNode) => React.Ref<T> | null;
|
|
19
|
+
export {};
|
package/lib/ref.js
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useComposeRef = exports.supportRef = exports.supportNodeRef = exports.getNodeRef = exports.fillRef = exports.composeRef = void 0;
|
|
7
|
+
var _react = require("react");
|
|
8
|
+
var _reactIs = require("react-is");
|
|
9
|
+
var _useMemo = _interopRequireDefault(require("./hooks/useMemo"));
|
|
10
|
+
var _isFragment = _interopRequireDefault(require("./React/isFragment"));
|
|
11
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
13
|
+
var fillRef = exports.fillRef = function fillRef(ref, node) {
|
|
14
|
+
if (typeof ref === 'function') {
|
|
15
|
+
ref(node);
|
|
16
|
+
} else if (_typeof(ref) === 'object' && ref && 'current' in ref) {
|
|
17
|
+
ref.current = node;
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Merge refs into one ref function to support ref passing.
|
|
23
|
+
*/
|
|
24
|
+
var composeRef = exports.composeRef = function composeRef() {
|
|
25
|
+
for (var _len = arguments.length, refs = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
26
|
+
refs[_key] = arguments[_key];
|
|
27
|
+
}
|
|
28
|
+
var refList = refs.filter(Boolean);
|
|
29
|
+
if (refList.length <= 1) {
|
|
30
|
+
return refList[0];
|
|
31
|
+
}
|
|
32
|
+
return function (node) {
|
|
33
|
+
refs.forEach(function (ref) {
|
|
34
|
+
fillRef(ref, node);
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
var useComposeRef = exports.useComposeRef = function useComposeRef() {
|
|
39
|
+
for (var _len2 = arguments.length, refs = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
40
|
+
refs[_key2] = arguments[_key2];
|
|
41
|
+
}
|
|
42
|
+
return (0, _useMemo.default)(function () {
|
|
43
|
+
return composeRef.apply(void 0, refs);
|
|
44
|
+
},
|
|
45
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
46
|
+
refs, function (prev, next) {
|
|
47
|
+
return prev.length !== next.length || prev.every(function (ref, i) {
|
|
48
|
+
return ref !== next[i];
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
};
|
|
52
|
+
var supportRef = exports.supportRef = function supportRef(nodeOrComponent) {
|
|
53
|
+
var _type$prototype, _nodeOrComponent$prot;
|
|
54
|
+
if (!nodeOrComponent) {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// React 19 no need `forwardRef` anymore. So just pass if is a React element.
|
|
59
|
+
if (isReactElement(nodeOrComponent) && nodeOrComponent.props.propertyIsEnumerable('ref')) {
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
var type = (0, _reactIs.isMemo)(nodeOrComponent) ? nodeOrComponent.type.type : nodeOrComponent.type;
|
|
63
|
+
|
|
64
|
+
// Function component node
|
|
65
|
+
if (typeof type === 'function' && !((_type$prototype = type.prototype) !== null && _type$prototype !== void 0 && _type$prototype.render) && type.$$typeof !== _reactIs.ForwardRef) {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Class component
|
|
70
|
+
if (typeof nodeOrComponent === 'function' && !((_nodeOrComponent$prot = nodeOrComponent.prototype) !== null && _nodeOrComponent$prot !== void 0 && _nodeOrComponent$prot.render) && nodeOrComponent.$$typeof !== _reactIs.ForwardRef) {
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
return true;
|
|
74
|
+
};
|
|
75
|
+
function isReactElement(node) {
|
|
76
|
+
return /*#__PURE__*/(0, _react.isValidElement)(node) && !(0, _isFragment.default)(node);
|
|
77
|
+
}
|
|
78
|
+
var supportNodeRef = exports.supportNodeRef = function supportNodeRef(node) {
|
|
79
|
+
return isReactElement(node) && supportRef(node);
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* In React 19. `ref` is not a property from node.
|
|
84
|
+
* But a property from `props.ref`.
|
|
85
|
+
* To check if `props.ref` exist or fallback to `ref`.
|
|
86
|
+
*/
|
|
87
|
+
var getNodeRef = exports.getNodeRef = function getNodeRef(node) {
|
|
88
|
+
if (node && isReactElement(node)) {
|
|
89
|
+
var ele = node;
|
|
90
|
+
|
|
91
|
+
// Source from:
|
|
92
|
+
// https://github.com/mui/material-ui/blob/master/packages/mui-utils/src/getReactNodeRef/getReactNodeRef.ts
|
|
93
|
+
return ele.props.propertyIsEnumerable('ref') ? ele.props.ref : ele.ref;
|
|
94
|
+
}
|
|
95
|
+
return null;
|
|
96
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type React from 'react';
|
|
2
|
+
export interface SetStyleOptions {
|
|
3
|
+
element?: HTMLElement;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Easy to set element style, return previous style
|
|
7
|
+
* IE browser compatible(IE browser doesn't merge overflow style, need to set it separately)
|
|
8
|
+
* https://github.com/ant-design/ant-design/issues/19393
|
|
9
|
+
*
|
|
10
|
+
*/
|
|
11
|
+
declare function setStyle(style: React.CSSProperties, options?: SetStyleOptions): React.CSSProperties;
|
|
12
|
+
export default setStyle;
|
package/lib/setStyle.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* Easy to set element style, return previous style
|
|
9
|
+
* IE browser compatible(IE browser doesn't merge overflow style, need to set it separately)
|
|
10
|
+
* https://github.com/ant-design/ant-design/issues/19393
|
|
11
|
+
*
|
|
12
|
+
*/
|
|
13
|
+
function setStyle(style) {
|
|
14
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
15
|
+
if (!style) {
|
|
16
|
+
return {};
|
|
17
|
+
}
|
|
18
|
+
var _options$element = options.element,
|
|
19
|
+
element = _options$element === void 0 ? document.body : _options$element;
|
|
20
|
+
var oldStyle = {};
|
|
21
|
+
var styleKeys = Object.keys(style);
|
|
22
|
+
|
|
23
|
+
// IE browser compatible
|
|
24
|
+
styleKeys.forEach(function (key) {
|
|
25
|
+
oldStyle[key] = element.style[key];
|
|
26
|
+
});
|
|
27
|
+
styleKeys.forEach(function (key) {
|
|
28
|
+
element.style[key] = style[key];
|
|
29
|
+
});
|
|
30
|
+
return oldStyle;
|
|
31
|
+
}
|
|
32
|
+
var _default = exports.default = setStyle;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export type ElementClass = Function;
|
|
2
|
+
export type Property = PropertyDescriptor | Function;
|
|
3
|
+
export declare function spyElementPrototypes<T extends ElementClass>(elementClass: T, properties: Record<string, Property>): {
|
|
4
|
+
mockRestore(): void;
|
|
5
|
+
};
|
|
6
|
+
export declare function spyElementPrototype(Element: ElementClass, propName: string, property: Property): {
|
|
7
|
+
mockRestore(): void;
|
|
8
|
+
};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.spyElementPrototype = spyElementPrototype;
|
|
7
|
+
exports.spyElementPrototypes = spyElementPrototypes;
|
|
8
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
9
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
10
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
11
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
12
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
13
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
14
|
+
/* eslint-disable @typescript-eslint/ban-types */
|
|
15
|
+
/* eslint-disable no-param-reassign */
|
|
16
|
+
var NO_EXIST = {
|
|
17
|
+
__NOT_EXIST: true
|
|
18
|
+
};
|
|
19
|
+
function spyElementPrototypes(elementClass, properties) {
|
|
20
|
+
var propNames = Object.keys(properties);
|
|
21
|
+
var originDescriptors = {};
|
|
22
|
+
propNames.forEach(function (propName) {
|
|
23
|
+
var originDescriptor = Object.getOwnPropertyDescriptor(elementClass.prototype, propName);
|
|
24
|
+
originDescriptors[propName] = originDescriptor || NO_EXIST;
|
|
25
|
+
var spyProp = properties[propName];
|
|
26
|
+
if (typeof spyProp === 'function') {
|
|
27
|
+
// If is a function
|
|
28
|
+
elementClass.prototype[propName] = function spyFunc() {
|
|
29
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
30
|
+
args[_key] = arguments[_key];
|
|
31
|
+
}
|
|
32
|
+
return spyProp.call.apply(spyProp, [this, originDescriptor].concat(args));
|
|
33
|
+
};
|
|
34
|
+
} else {
|
|
35
|
+
// Otherwise tread as a property
|
|
36
|
+
Object.defineProperty(elementClass.prototype, propName, _objectSpread(_objectSpread({}, spyProp), {}, {
|
|
37
|
+
set: function set(value) {
|
|
38
|
+
if (spyProp.set) {
|
|
39
|
+
return spyProp.set.call(this, originDescriptor, value);
|
|
40
|
+
}
|
|
41
|
+
return originDescriptor.set(value);
|
|
42
|
+
},
|
|
43
|
+
get: function get() {
|
|
44
|
+
if (spyProp.get) {
|
|
45
|
+
return spyProp.get.call(this, originDescriptor);
|
|
46
|
+
}
|
|
47
|
+
return originDescriptor.get();
|
|
48
|
+
},
|
|
49
|
+
configurable: true
|
|
50
|
+
}));
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
return {
|
|
54
|
+
mockRestore: function mockRestore() {
|
|
55
|
+
propNames.forEach(function (propName) {
|
|
56
|
+
var originDescriptor = originDescriptors[propName];
|
|
57
|
+
if (originDescriptor === NO_EXIST) {
|
|
58
|
+
delete elementClass.prototype[propName];
|
|
59
|
+
} else if (typeof originDescriptor === 'function') {
|
|
60
|
+
elementClass.prototype[propName] = originDescriptor;
|
|
61
|
+
} else {
|
|
62
|
+
Object.defineProperty(elementClass.prototype, propName, originDescriptor);
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
function spyElementPrototype(Element, propName, property) {
|
|
69
|
+
return spyElementPrototypes(Element, _defineProperty({}, propName, property));
|
|
70
|
+
}
|
|
71
|
+
/* eslint-enable */
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function get(entity: any, path: (string | number | symbol)[] | readonly (string | number | symbol)[]): any;
|
package/lib/utils/get.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = get;
|
|
7
|
+
function get(entity, path) {
|
|
8
|
+
var current = entity;
|
|
9
|
+
for (var i = 0; i < path.length; i += 1) {
|
|
10
|
+
if (current === null || current === undefined) {
|
|
11
|
+
return undefined;
|
|
12
|
+
}
|
|
13
|
+
current = current[path[i]];
|
|
14
|
+
}
|
|
15
|
+
return current;
|
|
16
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export type Path = (string | number | symbol)[];
|
|
2
|
+
export default function set<Entity = any, Output = Entity, Value = any>(entity: Entity, paths: Path, value: Value, removeIfUndefined?: boolean): Output;
|
|
3
|
+
/**
|
|
4
|
+
* Merge objects which will create
|
|
5
|
+
*/
|
|
6
|
+
export declare function merge<T extends object>(...sources: T[]): T;
|
package/lib/utils/set.js
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = set;
|
|
7
|
+
exports.merge = merge;
|
|
8
|
+
var _get = _interopRequireDefault(require("./get"));
|
|
9
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
11
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
12
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
13
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
14
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
15
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
16
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
17
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
18
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
19
|
+
function _toArray(arr) { return _arrayWithHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableRest(); }
|
|
20
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
21
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
22
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
23
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
24
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
25
|
+
function internalSet(entity, paths, value, removeIfUndefined) {
|
|
26
|
+
if (!paths.length) {
|
|
27
|
+
return value;
|
|
28
|
+
}
|
|
29
|
+
var _paths = _toArray(paths),
|
|
30
|
+
path = _paths[0],
|
|
31
|
+
restPath = _paths.slice(1);
|
|
32
|
+
var clone;
|
|
33
|
+
if (!entity && typeof path === 'number') {
|
|
34
|
+
clone = [];
|
|
35
|
+
} else if (Array.isArray(entity)) {
|
|
36
|
+
clone = _toConsumableArray(entity);
|
|
37
|
+
} else {
|
|
38
|
+
clone = _objectSpread({}, entity);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Delete prop if `removeIfUndefined` and value is undefined
|
|
42
|
+
if (removeIfUndefined && value === undefined && restPath.length === 1) {
|
|
43
|
+
delete clone[path][restPath[0]];
|
|
44
|
+
} else {
|
|
45
|
+
clone[path] = internalSet(clone[path], restPath, value, removeIfUndefined);
|
|
46
|
+
}
|
|
47
|
+
return clone;
|
|
48
|
+
}
|
|
49
|
+
function set(entity, paths, value) {
|
|
50
|
+
var removeIfUndefined = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
51
|
+
// Do nothing if `removeIfUndefined` and parent object not exist
|
|
52
|
+
if (paths.length && removeIfUndefined && value === undefined && !(0, _get.default)(entity, paths.slice(0, -1))) {
|
|
53
|
+
return entity;
|
|
54
|
+
}
|
|
55
|
+
return internalSet(entity, paths, value, removeIfUndefined);
|
|
56
|
+
}
|
|
57
|
+
function isObject(obj) {
|
|
58
|
+
return _typeof(obj) === 'object' && obj !== null && Object.getPrototypeOf(obj) === Object.prototype;
|
|
59
|
+
}
|
|
60
|
+
function createEmpty(source) {
|
|
61
|
+
return Array.isArray(source) ? [] : {};
|
|
62
|
+
}
|
|
63
|
+
var keys = typeof Reflect === 'undefined' ? Object.keys : Reflect.ownKeys;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Merge objects which will create
|
|
67
|
+
*/
|
|
68
|
+
function merge() {
|
|
69
|
+
for (var _len = arguments.length, sources = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
70
|
+
sources[_key] = arguments[_key];
|
|
71
|
+
}
|
|
72
|
+
var clone = createEmpty(sources[0]);
|
|
73
|
+
sources.forEach(function (src) {
|
|
74
|
+
function internalMerge(path, parentLoopSet) {
|
|
75
|
+
var loopSet = new Set(parentLoopSet);
|
|
76
|
+
var value = (0, _get.default)(src, path);
|
|
77
|
+
var isArr = Array.isArray(value);
|
|
78
|
+
if (isArr || isObject(value)) {
|
|
79
|
+
// Only add not loop obj
|
|
80
|
+
if (!loopSet.has(value)) {
|
|
81
|
+
loopSet.add(value);
|
|
82
|
+
var originValue = (0, _get.default)(clone, path);
|
|
83
|
+
if (isArr) {
|
|
84
|
+
// Array will always be override
|
|
85
|
+
clone = set(clone, path, []);
|
|
86
|
+
} else if (!originValue || _typeof(originValue) !== 'object') {
|
|
87
|
+
// Init container if not exist
|
|
88
|
+
clone = set(clone, path, createEmpty(value));
|
|
89
|
+
}
|
|
90
|
+
keys(value).forEach(function (key) {
|
|
91
|
+
internalMerge([].concat(_toConsumableArray(path), [key]), loopSet);
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
} else {
|
|
95
|
+
clone = set(clone, path, value);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
internalMerge([]);
|
|
99
|
+
});
|
|
100
|
+
return clone;
|
|
101
|
+
}
|
package/lib/warning.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export type preMessageFn = (message: string, type: 'warning' | 'note') => string | null | undefined | number;
|
|
2
|
+
/**
|
|
3
|
+
* Pre warning enable you to parse content before console.error.
|
|
4
|
+
* Modify to null will prevent warning.
|
|
5
|
+
*/
|
|
6
|
+
export declare const preMessage: (fn: preMessageFn) => void;
|
|
7
|
+
/**
|
|
8
|
+
* Warning if condition not match.
|
|
9
|
+
* @param valid Condition
|
|
10
|
+
* @param message Warning message
|
|
11
|
+
* @example
|
|
12
|
+
* ```js
|
|
13
|
+
* warning(false, 'some error'); // print some error
|
|
14
|
+
* warning(true, 'some error'); // print nothing
|
|
15
|
+
* warning(1 === 2, 'some error'); // print some error
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export declare function warning(valid: boolean, message: string): void;
|
|
19
|
+
/** @see Similar to {@link warning} */
|
|
20
|
+
export declare function note(valid: boolean, message: string): void;
|
|
21
|
+
export declare function resetWarned(): void;
|
|
22
|
+
export declare function call(method: (valid: boolean, message: string) => void, valid: boolean, message: string): void;
|
|
23
|
+
/** @see Same as {@link warning}, but only warn once for the same message */
|
|
24
|
+
export declare function warningOnce(valid: boolean, message: string): void;
|
|
25
|
+
export declare namespace warningOnce {
|
|
26
|
+
var preMessage: (fn: preMessageFn) => void;
|
|
27
|
+
var resetWarned: typeof import("./warning").resetWarned;
|
|
28
|
+
var noteOnce: typeof import("./warning").noteOnce;
|
|
29
|
+
}
|
|
30
|
+
/** @see Same as {@link warning}, but only warn once for the same message */
|
|
31
|
+
export declare function noteOnce(valid: boolean, message: string): void;
|
|
32
|
+
export default warningOnce;
|
package/lib/warning.js
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.call = call;
|
|
7
|
+
exports.default = void 0;
|
|
8
|
+
exports.note = note;
|
|
9
|
+
exports.noteOnce = noteOnce;
|
|
10
|
+
exports.preMessage = void 0;
|
|
11
|
+
exports.resetWarned = resetWarned;
|
|
12
|
+
exports.warning = warning;
|
|
13
|
+
exports.warningOnce = warningOnce;
|
|
14
|
+
/* eslint-disable no-console */
|
|
15
|
+
var warned = {};
|
|
16
|
+
var preWarningFns = [];
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Pre warning enable you to parse content before console.error.
|
|
20
|
+
* Modify to null will prevent warning.
|
|
21
|
+
*/
|
|
22
|
+
var preMessage = exports.preMessage = function preMessage(fn) {
|
|
23
|
+
preWarningFns.push(fn);
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Warning if condition not match.
|
|
28
|
+
* @param valid Condition
|
|
29
|
+
* @param message Warning message
|
|
30
|
+
* @example
|
|
31
|
+
* ```js
|
|
32
|
+
* warning(false, 'some error'); // print some error
|
|
33
|
+
* warning(true, 'some error'); // print nothing
|
|
34
|
+
* warning(1 === 2, 'some error'); // print some error
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
function warning(valid, message) {
|
|
38
|
+
if (process.env.NODE_ENV !== 'production' && !valid && console !== undefined) {
|
|
39
|
+
var finalMessage = preWarningFns.reduce(function (msg, preMessageFn) {
|
|
40
|
+
return preMessageFn(msg !== null && msg !== void 0 ? msg : '', 'warning');
|
|
41
|
+
}, message);
|
|
42
|
+
if (finalMessage) {
|
|
43
|
+
console.error("Warning: ".concat(finalMessage));
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** @see Similar to {@link warning} */
|
|
49
|
+
function note(valid, message) {
|
|
50
|
+
if (process.env.NODE_ENV !== 'production' && !valid && console !== undefined) {
|
|
51
|
+
var finalMessage = preWarningFns.reduce(function (msg, preMessageFn) {
|
|
52
|
+
return preMessageFn(msg !== null && msg !== void 0 ? msg : '', 'note');
|
|
53
|
+
}, message);
|
|
54
|
+
if (finalMessage) {
|
|
55
|
+
console.warn("Note: ".concat(finalMessage));
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
function resetWarned() {
|
|
60
|
+
warned = {};
|
|
61
|
+
}
|
|
62
|
+
function call(method, valid, message) {
|
|
63
|
+
if (!valid && !warned[message]) {
|
|
64
|
+
method(false, message);
|
|
65
|
+
warned[message] = true;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** @see Same as {@link warning}, but only warn once for the same message */
|
|
70
|
+
function warningOnce(valid, message) {
|
|
71
|
+
call(warning, valid, message);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** @see Same as {@link warning}, but only warn once for the same message */
|
|
75
|
+
function noteOnce(valid, message) {
|
|
76
|
+
call(note, valid, message);
|
|
77
|
+
}
|
|
78
|
+
warningOnce.preMessage = preMessage;
|
|
79
|
+
warningOnce.resetWarned = resetWarned;
|
|
80
|
+
warningOnce.noteOnce = noteOnce;
|
|
81
|
+
var _default = exports.default = warningOnce;
|