first commit
This commit is contained in:
18
frontend/node_modules/antd/es/modal/useModal/HookModal.d.ts
generated
vendored
Normal file
18
frontend/node_modules/antd/es/modal/useModal/HookModal.d.ts
generated
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
import * as React from 'react';
|
||||
import type { ConfigUpdate } from '../confirm';
|
||||
import type { ModalFuncProps } from '../interface';
|
||||
export interface HookModalProps {
|
||||
afterClose: () => void;
|
||||
config: ModalFuncProps;
|
||||
onConfirm?: (confirmed: boolean) => void;
|
||||
/**
|
||||
* Do not throw if is await mode
|
||||
*/
|
||||
isSilent?: () => boolean;
|
||||
}
|
||||
export interface HookModalRef {
|
||||
destroy: () => void;
|
||||
update: (config: ConfigUpdate) => void;
|
||||
}
|
||||
declare const _default: React.ForwardRefExoticComponent<HookModalProps & React.RefAttributes<HookModalRef>>;
|
||||
export default _default;
|
||||
69
frontend/node_modules/antd/es/modal/useModal/HookModal.js
generated
vendored
Normal file
69
frontend/node_modules/antd/es/modal/useModal/HookModal.js
generated
vendored
Normal file
@@ -0,0 +1,69 @@
|
||||
"use client";
|
||||
|
||||
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
||||
var __rest = this && this.__rest || function (s, e) {
|
||||
var t = {};
|
||||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
|
||||
if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
||||
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
|
||||
}
|
||||
return t;
|
||||
};
|
||||
import * as React from 'react';
|
||||
import { ConfigContext } from '../../config-provider';
|
||||
import defaultLocale from '../../locale/en_US';
|
||||
import useLocale from '../../locale/useLocale';
|
||||
import ConfirmDialog from '../ConfirmDialog';
|
||||
const HookModal = (_a, ref) => {
|
||||
var _b;
|
||||
var {
|
||||
afterClose: hookAfterClose,
|
||||
config
|
||||
} = _a,
|
||||
restProps = __rest(_a, ["afterClose", "config"]);
|
||||
const [open, setOpen] = React.useState(true);
|
||||
const [innerConfig, setInnerConfig] = React.useState(config);
|
||||
const {
|
||||
direction,
|
||||
getPrefixCls
|
||||
} = React.useContext(ConfigContext);
|
||||
const prefixCls = getPrefixCls('modal');
|
||||
const rootPrefixCls = getPrefixCls();
|
||||
const afterClose = () => {
|
||||
var _a;
|
||||
hookAfterClose();
|
||||
(_a = innerConfig.afterClose) === null || _a === void 0 ? void 0 : _a.call(innerConfig);
|
||||
};
|
||||
const close = (...args) => {
|
||||
var _a;
|
||||
setOpen(false);
|
||||
const triggerCancel = args.some(param => param === null || param === void 0 ? void 0 : param.triggerCancel);
|
||||
if (triggerCancel) {
|
||||
var _a2;
|
||||
(_a = innerConfig.onCancel) === null || _a === void 0 ? void 0 : (_a2 = _a).call.apply(_a2, [innerConfig, () => {}].concat(_toConsumableArray(args.slice(1))));
|
||||
}
|
||||
};
|
||||
React.useImperativeHandle(ref, () => ({
|
||||
destroy: close,
|
||||
update: newConfig => {
|
||||
setInnerConfig(originConfig => {
|
||||
const nextConfig = typeof newConfig === 'function' ? newConfig(originConfig) : newConfig;
|
||||
return Object.assign(Object.assign({}, originConfig), nextConfig);
|
||||
});
|
||||
}
|
||||
}));
|
||||
const mergedOkCancel = (_b = innerConfig.okCancel) !== null && _b !== void 0 ? _b : innerConfig.type === 'confirm';
|
||||
const [contextLocale] = useLocale('Modal', defaultLocale.Modal);
|
||||
return /*#__PURE__*/React.createElement(ConfirmDialog, Object.assign({
|
||||
prefixCls: prefixCls,
|
||||
rootPrefixCls: rootPrefixCls
|
||||
}, innerConfig, {
|
||||
close: close,
|
||||
open: open,
|
||||
afterClose: afterClose,
|
||||
okText: innerConfig.okText || (mergedOkCancel ? contextLocale === null || contextLocale === void 0 ? void 0 : contextLocale.okText : contextLocale === null || contextLocale === void 0 ? void 0 : contextLocale.justOkText),
|
||||
direction: innerConfig.direction || direction,
|
||||
cancelText: innerConfig.cancelText || (contextLocale === null || contextLocale === void 0 ? void 0 : contextLocale.cancelText)
|
||||
}, restProps));
|
||||
};
|
||||
export default /*#__PURE__*/React.forwardRef(HookModal);
|
||||
8
frontend/node_modules/antd/es/modal/useModal/index.d.ts
generated
vendored
Normal file
8
frontend/node_modules/antd/es/modal/useModal/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
import * as React from 'react';
|
||||
import type { ModalFunc, ModalStaticFunctions } from '../confirm';
|
||||
export type ModalFuncWithPromise = (...args: Parameters<ModalFunc>) => ReturnType<ModalFunc> & {
|
||||
then: <T>(resolve: (confirmed: boolean) => T, reject: VoidFunction) => Promise<T>;
|
||||
};
|
||||
export type HookAPI = Omit<Record<keyof ModalStaticFunctions, ModalFuncWithPromise>, 'warn'>;
|
||||
declare function useModal(): readonly [instance: HookAPI, contextHolder: React.ReactElement];
|
||||
export default useModal;
|
||||
100
frontend/node_modules/antd/es/modal/useModal/index.js
generated
vendored
Normal file
100
frontend/node_modules/antd/es/modal/useModal/index.js
generated
vendored
Normal file
@@ -0,0 +1,100 @@
|
||||
"use client";
|
||||
|
||||
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
||||
import * as React from 'react';
|
||||
import { usePatchElement } from '../../_util/hooks';
|
||||
import { withConfirm, withError, withInfo, withSuccess, withWarn } from '../confirm';
|
||||
import destroyFns from '../destroyFns';
|
||||
import HookModal from './HookModal';
|
||||
let uuid = 0;
|
||||
const ElementsHolder = /*#__PURE__*/React.memo(/*#__PURE__*/React.forwardRef((_props, ref) => {
|
||||
const [elements, patchElement] = usePatchElement();
|
||||
React.useImperativeHandle(ref, () => ({
|
||||
patchElement
|
||||
}), [patchElement]);
|
||||
return /*#__PURE__*/React.createElement(React.Fragment, null, elements);
|
||||
}));
|
||||
function useModal() {
|
||||
const holderRef = React.useRef(null);
|
||||
// ========================== Effect ==========================
|
||||
const [actionQueue, setActionQueue] = React.useState([]);
|
||||
React.useEffect(() => {
|
||||
if (actionQueue.length) {
|
||||
const cloneQueue = _toConsumableArray(actionQueue);
|
||||
cloneQueue.forEach(action => {
|
||||
action();
|
||||
});
|
||||
setActionQueue([]);
|
||||
}
|
||||
}, [actionQueue]);
|
||||
// =========================== Hook ===========================
|
||||
const getConfirmFunc = React.useCallback(withFunc => function hookConfirm(config) {
|
||||
var _a;
|
||||
uuid += 1;
|
||||
const modalRef = /*#__PURE__*/React.createRef();
|
||||
// Proxy to promise with `onClose`
|
||||
let resolvePromise;
|
||||
const promise = new Promise(resolve => {
|
||||
resolvePromise = resolve;
|
||||
});
|
||||
let silent = false;
|
||||
let closeFunc;
|
||||
const modal = /*#__PURE__*/React.createElement(HookModal, {
|
||||
key: `modal-${uuid}`,
|
||||
config: withFunc(config),
|
||||
ref: modalRef,
|
||||
afterClose: () => {
|
||||
closeFunc === null || closeFunc === void 0 ? void 0 : closeFunc();
|
||||
},
|
||||
isSilent: () => silent,
|
||||
onConfirm: confirmed => {
|
||||
resolvePromise(confirmed);
|
||||
}
|
||||
});
|
||||
closeFunc = (_a = holderRef.current) === null || _a === void 0 ? void 0 : _a.patchElement(modal);
|
||||
if (closeFunc) {
|
||||
destroyFns.push(closeFunc);
|
||||
}
|
||||
const instance = {
|
||||
destroy: () => {
|
||||
function destroyAction() {
|
||||
var _a;
|
||||
(_a = modalRef.current) === null || _a === void 0 ? void 0 : _a.destroy();
|
||||
}
|
||||
if (modalRef.current) {
|
||||
destroyAction();
|
||||
} else {
|
||||
setActionQueue(prev => [].concat(_toConsumableArray(prev), [destroyAction]));
|
||||
}
|
||||
},
|
||||
update: newConfig => {
|
||||
function updateAction() {
|
||||
var _a;
|
||||
(_a = modalRef.current) === null || _a === void 0 ? void 0 : _a.update(newConfig);
|
||||
}
|
||||
if (modalRef.current) {
|
||||
updateAction();
|
||||
} else {
|
||||
setActionQueue(prev => [].concat(_toConsumableArray(prev), [updateAction]));
|
||||
}
|
||||
},
|
||||
then: resolve => {
|
||||
silent = true;
|
||||
return promise.then(resolve);
|
||||
}
|
||||
};
|
||||
return instance;
|
||||
}, []);
|
||||
const fns = React.useMemo(() => ({
|
||||
info: getConfirmFunc(withInfo),
|
||||
success: getConfirmFunc(withSuccess),
|
||||
error: getConfirmFunc(withError),
|
||||
warning: getConfirmFunc(withWarn),
|
||||
confirm: getConfirmFunc(withConfirm)
|
||||
}), [getConfirmFunc]);
|
||||
return [fns, /*#__PURE__*/React.createElement(ElementsHolder, {
|
||||
key: "modal-holder",
|
||||
ref: holderRef
|
||||
})];
|
||||
}
|
||||
export default useModal;
|
||||
Reference in New Issue
Block a user