first commit
This commit is contained in:
35
frontend/node_modules/rc-notification/lib/hooks/useNotification.d.ts
generated
vendored
Normal file
35
frontend/node_modules/rc-notification/lib/hooks/useNotification.d.ts
generated
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
import type { CSSMotionProps } from 'rc-motion';
|
||||
import * as React from 'react';
|
||||
import type { NotificationsProps } from '../Notifications';
|
||||
import type { OpenConfig, Placement, StackConfig } from '../interface';
|
||||
type OptionalConfig = Partial<OpenConfig>;
|
||||
export interface NotificationConfig {
|
||||
prefixCls?: string;
|
||||
/** Customize container. It will repeat call which means you should return same container element. */
|
||||
getContainer?: () => HTMLElement | ShadowRoot;
|
||||
motion?: CSSMotionProps | ((placement: Placement) => CSSMotionProps);
|
||||
closeIcon?: React.ReactNode;
|
||||
closable?: boolean | ({
|
||||
closeIcon?: React.ReactNode;
|
||||
} & React.AriaAttributes);
|
||||
maxCount?: number;
|
||||
duration?: number;
|
||||
showProgress?: boolean;
|
||||
pauseOnHover?: boolean;
|
||||
/** @private. Config for notification holder style. Safe to remove if refactor */
|
||||
className?: (placement: Placement) => string;
|
||||
/** @private. Config for notification holder style. Safe to remove if refactor */
|
||||
style?: (placement: Placement) => React.CSSProperties;
|
||||
/** @private Trigger when all the notification closed. */
|
||||
onAllRemoved?: VoidFunction;
|
||||
stack?: StackConfig;
|
||||
/** @private Slot for style in Notifications */
|
||||
renderNotifications?: NotificationsProps['renderNotifications'];
|
||||
}
|
||||
export interface NotificationAPI {
|
||||
open: (config: OptionalConfig) => void;
|
||||
close: (key: React.Key) => void;
|
||||
destroy: () => void;
|
||||
}
|
||||
export default function useNotification(rootConfig?: NotificationConfig): [NotificationAPI, React.ReactElement];
|
||||
export {};
|
||||
160
frontend/node_modules/rc-notification/lib/hooks/useNotification.js
generated
vendored
Normal file
160
frontend/node_modules/rc-notification/lib/hooks/useNotification.js
generated
vendored
Normal file
@@ -0,0 +1,160 @@
|
||||
"use strict";
|
||||
|
||||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
||||
var _typeof = require("@babel/runtime/helpers/typeof");
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = useNotification;
|
||||
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
||||
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
||||
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
||||
var React = _interopRequireWildcard(require("react"));
|
||||
var _Notifications = _interopRequireDefault(require("../Notifications"));
|
||||
var _rcUtil = require("rc-util");
|
||||
var _excluded = ["getContainer", "motion", "prefixCls", "maxCount", "className", "style", "onAllRemoved", "stack", "renderNotifications"];
|
||||
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
||||
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
||||
var defaultGetContainer = function defaultGetContainer() {
|
||||
return document.body;
|
||||
};
|
||||
var uniqueKey = 0;
|
||||
function mergeConfig() {
|
||||
var clone = {};
|
||||
for (var _len = arguments.length, objList = new Array(_len), _key = 0; _key < _len; _key++) {
|
||||
objList[_key] = arguments[_key];
|
||||
}
|
||||
objList.forEach(function (obj) {
|
||||
if (obj) {
|
||||
Object.keys(obj).forEach(function (key) {
|
||||
var val = obj[key];
|
||||
if (val !== undefined) {
|
||||
clone[key] = val;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
return clone;
|
||||
}
|
||||
function useNotification() {
|
||||
var rootConfig = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
||||
var _rootConfig$getContai = rootConfig.getContainer,
|
||||
getContainer = _rootConfig$getContai === void 0 ? defaultGetContainer : _rootConfig$getContai,
|
||||
motion = rootConfig.motion,
|
||||
prefixCls = rootConfig.prefixCls,
|
||||
maxCount = rootConfig.maxCount,
|
||||
className = rootConfig.className,
|
||||
style = rootConfig.style,
|
||||
onAllRemoved = rootConfig.onAllRemoved,
|
||||
stack = rootConfig.stack,
|
||||
renderNotifications = rootConfig.renderNotifications,
|
||||
shareConfig = (0, _objectWithoutProperties2.default)(rootConfig, _excluded);
|
||||
var _React$useState = React.useState(),
|
||||
_React$useState2 = (0, _slicedToArray2.default)(_React$useState, 2),
|
||||
container = _React$useState2[0],
|
||||
setContainer = _React$useState2[1];
|
||||
var notificationsRef = React.useRef();
|
||||
var contextHolder = /*#__PURE__*/React.createElement(_Notifications.default, {
|
||||
container: container,
|
||||
ref: notificationsRef,
|
||||
prefixCls: prefixCls,
|
||||
motion: motion,
|
||||
maxCount: maxCount,
|
||||
className: className,
|
||||
style: style,
|
||||
onAllRemoved: onAllRemoved,
|
||||
stack: stack,
|
||||
renderNotifications: renderNotifications
|
||||
});
|
||||
var _React$useState3 = React.useState([]),
|
||||
_React$useState4 = (0, _slicedToArray2.default)(_React$useState3, 2),
|
||||
taskQueue = _React$useState4[0],
|
||||
setTaskQueue = _React$useState4[1];
|
||||
var open = (0, _rcUtil.useEvent)(function (config) {
|
||||
var mergedConfig = mergeConfig(shareConfig, config);
|
||||
if (mergedConfig.key === null || mergedConfig.key === undefined) {
|
||||
mergedConfig.key = "rc-notification-".concat(uniqueKey);
|
||||
uniqueKey += 1;
|
||||
}
|
||||
setTaskQueue(function (queue) {
|
||||
return [].concat((0, _toConsumableArray2.default)(queue), [{
|
||||
type: 'open',
|
||||
config: mergedConfig
|
||||
}]);
|
||||
});
|
||||
});
|
||||
|
||||
// ========================= Refs =========================
|
||||
var api = React.useMemo(function () {
|
||||
return {
|
||||
open: open,
|
||||
close: function close(key) {
|
||||
setTaskQueue(function (queue) {
|
||||
return [].concat((0, _toConsumableArray2.default)(queue), [{
|
||||
type: 'close',
|
||||
key: key
|
||||
}]);
|
||||
});
|
||||
},
|
||||
destroy: function destroy() {
|
||||
setTaskQueue(function (queue) {
|
||||
return [].concat((0, _toConsumableArray2.default)(queue), [{
|
||||
type: 'destroy'
|
||||
}]);
|
||||
});
|
||||
}
|
||||
};
|
||||
}, []);
|
||||
|
||||
// ======================= Container ======================
|
||||
// React 18 should all in effect that we will check container in each render
|
||||
// Which means getContainer should be stable.
|
||||
React.useEffect(function () {
|
||||
setContainer(getContainer());
|
||||
});
|
||||
|
||||
// ======================== Effect ========================
|
||||
React.useEffect(function () {
|
||||
// Flush task when node ready
|
||||
if (notificationsRef.current && taskQueue.length) {
|
||||
taskQueue.forEach(function (task) {
|
||||
switch (task.type) {
|
||||
case 'open':
|
||||
notificationsRef.current.open(task.config);
|
||||
break;
|
||||
case 'close':
|
||||
notificationsRef.current.close(task.key);
|
||||
break;
|
||||
case 'destroy':
|
||||
notificationsRef.current.destroy();
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
// https://github.com/ant-design/ant-design/issues/52590
|
||||
// React `startTransition` will run once `useEffect` but many times `setState`,
|
||||
// So `setTaskQueue` with filtered array will cause infinite loop.
|
||||
// We cache the first match queue instead.
|
||||
var oriTaskQueue;
|
||||
var tgtTaskQueue;
|
||||
|
||||
// React 17 will mix order of effect & setState in async
|
||||
// - open: setState[0]
|
||||
// - effect[0]
|
||||
// - open: setState[1]
|
||||
// - effect setState([]) * here will clean up [0, 1] in React 17
|
||||
setTaskQueue(function (oriQueue) {
|
||||
if (oriTaskQueue !== oriQueue || !tgtTaskQueue) {
|
||||
oriTaskQueue = oriQueue;
|
||||
tgtTaskQueue = oriQueue.filter(function (task) {
|
||||
return !taskQueue.includes(task);
|
||||
});
|
||||
}
|
||||
return tgtTaskQueue;
|
||||
});
|
||||
}
|
||||
}, [taskQueue]);
|
||||
|
||||
// ======================== Return ========================
|
||||
return [api, contextHolder];
|
||||
}
|
||||
5
frontend/node_modules/rc-notification/lib/hooks/useStack.d.ts
generated
vendored
Normal file
5
frontend/node_modules/rc-notification/lib/hooks/useStack.d.ts
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
import type { StackConfig } from '../interface';
|
||||
type StackParams = Exclude<StackConfig, boolean>;
|
||||
type UseStack = (config?: StackConfig) => [boolean, StackParams];
|
||||
declare const useStack: UseStack;
|
||||
export default useStack;
|
||||
26
frontend/node_modules/rc-notification/lib/hooks/useStack.js
generated
vendored
Normal file
26
frontend/node_modules/rc-notification/lib/hooks/useStack.js
generated
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
"use strict";
|
||||
|
||||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
||||
var DEFAULT_OFFSET = 8;
|
||||
var DEFAULT_THRESHOLD = 3;
|
||||
var DEFAULT_GAP = 16;
|
||||
var useStack = function useStack(config) {
|
||||
var result = {
|
||||
offset: DEFAULT_OFFSET,
|
||||
threshold: DEFAULT_THRESHOLD,
|
||||
gap: DEFAULT_GAP
|
||||
};
|
||||
if (config && (0, _typeof2.default)(config) === 'object') {
|
||||
var _config$offset, _config$threshold, _config$gap;
|
||||
result.offset = (_config$offset = config.offset) !== null && _config$offset !== void 0 ? _config$offset : DEFAULT_OFFSET;
|
||||
result.threshold = (_config$threshold = config.threshold) !== null && _config$threshold !== void 0 ? _config$threshold : DEFAULT_THRESHOLD;
|
||||
result.gap = (_config$gap = config.gap) !== null && _config$gap !== void 0 ? _config$gap : DEFAULT_GAP;
|
||||
}
|
||||
return [!!config, result];
|
||||
};
|
||||
var _default = exports.default = useStack;
|
||||
Reference in New Issue
Block a user