@zykj2024/much-library 1.1.7-beta.3 → 1.1.7-beta.4
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/dist/esm/McCascader/city.js +909 -0
- package/dist/esm/McCascader/index.d.ts +19 -0
- package/dist/esm/McCascader/index.js +221 -0
- package/dist/esm/McCascader/index.less +72 -0
- package/dist/esm/McContainer/index.d.ts +192 -0
- package/dist/esm/McContainer/index.js +522 -0
- package/dist/esm/McContainer/index.less +132 -0
- package/dist/esm/McDateRange/index.d.ts +28 -0
- package/dist/esm/McDateRange/index.js +167 -0
- package/dist/esm/McDateRange/index.less +33 -0
- package/dist/esm/McEllipsis/index.d.ts +40 -0
- package/dist/esm/McEllipsis/index.js +115 -0
- package/dist/esm/McEllipsis/index.less +9 -0
- package/dist/esm/McEllipsisMiddle/index.d.ts +13 -0
- package/dist/esm/McEllipsisMiddle/index.js +42 -0
- package/dist/esm/McEllipsisMiddle/index.less +9 -0
- package/dist/esm/McFonts/index.d.ts +8 -0
- package/dist/esm/McFonts/index.js +7 -0
- package/dist/esm/McGroupPanel/comps/SelectedItem/index.d.ts +4 -0
- package/dist/esm/McGroupPanel/comps/SelectedItem/index.js +75 -0
- package/dist/esm/McGroupPanel/index.d.ts +30 -0
- package/dist/esm/McGroupPanel/index.js +426 -0
- package/dist/esm/McGroupPanel/index.less +161 -0
- package/dist/esm/McIconFont/iconfont.js +1 -0
- package/dist/esm/McIconFont/index.d.ts +5 -0
- package/dist/esm/McIconFont/index.js +8 -0
- package/dist/esm/McIcons/business.json +137 -0
- package/dist/esm/McIcons/index.less +22 -0
- package/dist/esm/McInput/Input.d.ts +19 -0
- package/dist/esm/McInput/Input.js +48 -0
- package/dist/esm/McInput/Search.d.ts +39 -0
- package/dist/esm/McInput/Search.js +81 -0
- package/dist/esm/McInput/TextArea.d.ts +11 -0
- package/dist/esm/McInput/TextArea.js +37 -0
- package/dist/esm/McInput/demo/Input/addonBefore.d.ts +3 -0
- package/dist/esm/McInput/demo/Input/addonBefore.js +67 -0
- package/dist/esm/McInput/demo/Input/base.d.ts +2 -0
- package/dist/esm/McInput/demo/Input/base.js +31 -0
- package/dist/esm/McInput/demo/Input/isTrim.d.ts +2 -0
- package/dist/esm/McInput/demo/Input/isTrim.js +22 -0
- package/dist/esm/McInput/demo/Input/label.d.ts +2 -0
- package/dist/esm/McInput/demo/Input/label.js +26 -0
- package/dist/esm/McInput/demo/Input/ref.d.ts +3 -0
- package/dist/esm/McInput/demo/Input/ref.js +53 -0
- package/dist/esm/McInput/demo/Input/status.d.ts +2 -0
- package/dist/esm/McInput/demo/Input/status.js +23 -0
- package/dist/esm/McInput/demo/Search/search-base.d.ts +2 -0
- package/dist/esm/McInput/demo/Search/search-base.js +38 -0
- package/dist/esm/McInput/demo/TextArea/text-area-base.d.ts +2 -0
- package/dist/esm/McInput/demo/TextArea/text-area-base.js +38 -0
- package/dist/esm/McInput/index.d.ts +13 -0
- package/dist/esm/McInput/index.js +7 -0
- package/dist/esm/McInput/index.less +62 -0
- package/dist/esm/McInputNumber/index.d.ts +16 -0
- package/dist/esm/McInputNumber/index.js +50 -0
- package/dist/esm/McInputNumber/index.less +18 -0
- package/dist/esm/McLazyLoader/index.d.ts +39 -0
- package/dist/esm/McLazyLoader/index.js +88 -0
- package/dist/esm/McListSelect/comps/ListSelect.d.ts +67 -0
- package/dist/esm/McListSelect/comps/ListSelect.js +289 -0
- package/dist/esm/McListSelect/comps/ListSelectPanel.d.ts +138 -0
- package/dist/esm/McListSelect/comps/ListSelectPanel.js +451 -0
- package/dist/esm/McListSelect/comps/SelectedItem.d.ts +17 -0
- package/dist/esm/McListSelect/comps/SelectedItem.js +76 -0
- package/dist/esm/McListSelect/index.d.ts +10 -0
- package/dist/esm/McListSelect/index.js +5 -0
- package/dist/esm/McListSelect/index.less +257 -0
- package/dist/esm/McModalProvider/index.d.ts +174 -0
- package/dist/esm/McModalProvider/index.js +498 -0
- package/dist/esm/McPeriodSelect/index.d.ts +13 -0
- package/dist/esm/McPeriodSelect/index.js +305 -0
- package/dist/esm/McPeriodSelect/index.less +187 -0
- package/dist/esm/McPopoverButton/index.d.ts +14 -0
- package/dist/esm/McPopoverButton/index.js +52 -0
- package/dist/esm/McPopoverForm/index.d.ts +14 -0
- package/dist/esm/McPopoverForm/index.js +95 -0
- package/dist/esm/McProSelect/index.d.ts +35 -0
- package/dist/esm/McProSelect/index.js +152 -0
- package/dist/esm/McResult/default.d.ts +1 -0
- package/dist/esm/McResult/default.js +98 -0
- package/dist/esm/McResult/icon.d.ts +25 -0
- package/dist/esm/McResult/icon.js +1014 -0
- package/dist/esm/McResult/index.d.ts +31 -0
- package/dist/esm/McResult/index.js +119 -0
- package/dist/esm/McResult/index.less +18 -0
- package/dist/esm/McResult/public/403.svg +164 -0
- package/dist/esm/McResult/public/404.svg +123 -0
- package/dist/esm/McResult/public/500.svg +129 -0
- package/dist/esm/McResult/public/building.svg +127 -0
- package/dist/esm/McResult/public/code403.svg +7 -0
- package/dist/esm/McResult/public/code404.svg +5 -0
- package/dist/esm/McResult/public/code500.svg +5 -0
- package/dist/esm/McResult/public/detailEmpty.svg +1 -0
- package/dist/esm/McResult/public/empty.svg +1 -0
- package/dist/esm/McResult/public/noFunction.svg +1 -0
- package/dist/esm/McResult/public/noUser.svg +90 -0
- package/dist/esm/McSelect/components/PanelSearchInput/index.d.ts +12 -0
- package/dist/esm/McSelect/components/PanelSearchInput/index.js +45 -0
- package/dist/esm/McSelect/components/PanelSearchInput/index.less +7 -0
- package/dist/esm/McSelect/index.d.ts +47 -0
- package/dist/esm/McSelect/index.js +436 -0
- package/dist/esm/McSelect/index.less +72 -0
- package/dist/esm/McTag/index.d.ts +22 -0
- package/dist/esm/McTag/index.js +59 -0
- package/dist/esm/McThemeConfig/customToken.json +39 -0
- package/dist/esm/McThemeConfig/globalStyle.d.ts +2 -0
- package/dist/esm/McThemeConfig/globalStyle.js +198 -0
- package/dist/esm/McThemeConfig/index.d.ts +9 -0
- package/dist/esm/McThemeConfig/index.js +16 -0
- package/dist/esm/McThemeConfig/layoutStyle.d.ts +2 -0
- package/dist/esm/McThemeConfig/layoutStyle.js +1 -0
- package/dist/esm/McThemeConfig/provider.d.ts +8 -0
- package/dist/esm/McThemeConfig/provider.js +20 -0
- package/dist/esm/McThemeConfig/themeToken.json +152 -0
- package/dist/esm/McTreePanel/SelectedItem.d.ts +4 -0
- package/dist/esm/McTreePanel/SelectedItem.js +75 -0
- package/dist/esm/McTreePanel/index.d.ts +27 -0
- package/dist/esm/McTreePanel/index.js +315 -0
- package/dist/esm/McTreePanel/index.less +106 -0
- package/dist/esm/McTreeSelect/index.d.ts +13 -0
- package/dist/esm/McTreeSelect/index.js +182 -0
- package/dist/esm/McTreeSelect/index.less +72 -0
- package/dist/esm/McUpload/comps/McFormUpload/comps/UploadForVal/index.d.ts +38 -0
- package/dist/esm/McUpload/comps/McFormUpload/comps/UploadForVal/index.js +209 -0
- package/dist/esm/McUpload/comps/McFormUpload/comps/UploadForVal/index.less +6 -0
- package/dist/esm/McUpload/comps/McFormUpload/index.d.ts +7 -0
- package/dist/esm/McUpload/comps/McFormUpload/index.js +29 -0
- package/dist/esm/McUpload/comps/McUploadCmp/index.d.ts +49 -0
- package/dist/esm/McUpload/comps/McUploadCmp/index.js +396 -0
- package/dist/esm/McUpload/comps/McUploadCmp/index.less +68 -0
- package/dist/esm/McUpload/comps/McUploadDragger/index.d.ts +49 -0
- package/dist/esm/McUpload/comps/McUploadDragger/index.js +264 -0
- package/dist/esm/McUpload/comps/McUploadTrigger/index.d.ts +39 -0
- package/dist/esm/McUpload/comps/McUploadTrigger/index.js +318 -0
- package/dist/esm/McUpload/comps/McUploadTrigger/index.less +204 -0
- package/dist/esm/McUpload/index.d.ts +14 -0
- package/dist/esm/McUpload/index.js +9 -0
- package/dist/esm/McUpload/tools/calculateMD5/index.d.ts +3 -0
- package/dist/esm/McUpload/tools/calculateMD5/index.js +94 -0
- package/dist/esm/McUpload/tools/calculateMD5/md5Worker.js +44 -0
- package/dist/esm/McUpload/tools/getUid.d.ts +1 -0
- package/dist/esm/McUpload/tools/getUid.js +6 -0
- package/dist/esm/McUpload/tools/materialVerification.d.ts +50 -0
- package/dist/esm/McUpload/tools/materialVerification.js +257 -0
- package/dist/esm/McUpload/tools/uploadTools.d.ts +5 -0
- package/dist/esm/McUpload/tools/uploadTools.js +56 -0
- package/dist/esm/Utils/index.d.ts +8 -0
- package/dist/esm/Utils/index.js +9 -0
- package/dist/esm/Utils/lib/Queue/PriorityQueue.d.ts +21 -0
- package/dist/esm/Utils/lib/Queue/PriorityQueue.js +197 -0
- package/dist/esm/Utils/lib/Queue/TaskQueue.d.ts +17 -0
- package/dist/esm/Utils/lib/Queue/TaskQueue.js +199 -0
- package/dist/esm/Utils/lib/Queue/tools/BinaryHeap.d.ts +25 -0
- package/dist/esm/Utils/lib/Queue/tools/BinaryHeap.js +184 -0
- package/dist/esm/Utils/lib/Queue/tools/publicDependencyMethod.d.ts +6 -0
- package/dist/esm/Utils/lib/Queue/tools/publicDependencyMethod.js +26 -0
- package/dist/esm/Utils/lib/Queue/types/baseTaskQueue.d.ts +23 -0
- package/dist/esm/Utils/lib/Queue/types/baseTaskQueue.js +10 -0
- package/dist/esm/Utils/lib/copyToClipboard.d.ts +8 -0
- package/dist/esm/Utils/lib/copyToClipboard.js +54 -0
- package/dist/esm/index.d.ts +34 -0
- package/dist/esm/index.js +33 -0
- package/dist/esm/styles/index.less +2 -0
- package/dist/esm/styles/mixins.less +52 -0
- package/dist/esm/styles/utilities.less +51 -0
- package/dist/esm/typings.d.ts +20 -0
- package/package.json +4 -3
@@ -0,0 +1,498 @@
|
|
1
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
2
|
+
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
3
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
4
|
+
var _excluded = ["defaultVisible", "keepMounted", "id"],
|
5
|
+
_excluded2 = ["modal", "handler"];
|
6
|
+
import React, { useCallback, useContext, useEffect, useMemo, useReducer } from 'react';
|
7
|
+
|
8
|
+
/**
|
9
|
+
* The handler to manage a modal returned by {@link useModal | useModal} hook.
|
10
|
+
*/
|
11
|
+
|
12
|
+
// Omit will not work if extends Record<string, unknown>, which is not needed here
|
13
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
14
|
+
import { Fragment as _Fragment } from "react/jsx-runtime";
|
15
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
16
|
+
var symModalId = Symbol('McModalId');
|
17
|
+
var initialState = {};
|
18
|
+
export var McModalContext = /*#__PURE__*/React.createContext(initialState);
|
19
|
+
var McModalIdContext = /*#__PURE__*/React.createContext(null);
|
20
|
+
var MODAL_REGISTRY = {};
|
21
|
+
var ALREADY_MOUNTED = {};
|
22
|
+
var uidSeed = 0;
|
23
|
+
var dispatch = function dispatch() {
|
24
|
+
throw new Error('No dispatch method detected, did you embed your app with McModal.Provider?');
|
25
|
+
};
|
26
|
+
var getUid = function getUid() {
|
27
|
+
return "_mc_modal_".concat(uidSeed++);
|
28
|
+
};
|
29
|
+
|
30
|
+
// Modal reducer used in useReducer hook.
|
31
|
+
export var reducer = function reducer() {
|
32
|
+
var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : initialState;
|
33
|
+
var action = arguments.length > 1 ? arguments[1] : undefined;
|
34
|
+
switch (action.type) {
|
35
|
+
case 'McModal/show':
|
36
|
+
{
|
37
|
+
var _action$payload = action.payload,
|
38
|
+
_modalId = _action$payload.modalId,
|
39
|
+
_args = _action$payload.args;
|
40
|
+
return _objectSpread(_objectSpread({}, state), {}, _defineProperty({}, _modalId, _objectSpread(_objectSpread({}, state[_modalId]), {}, {
|
41
|
+
id: _modalId,
|
42
|
+
args: _args,
|
43
|
+
// If modal is not mounted, mount it first then make it visible.
|
44
|
+
// There is logic inside HOC wrapper to make it visible after its first mount.
|
45
|
+
// This mechanism ensures the entering transition.
|
46
|
+
visible: !!ALREADY_MOUNTED[_modalId],
|
47
|
+
delayVisible: !ALREADY_MOUNTED[_modalId]
|
48
|
+
})));
|
49
|
+
}
|
50
|
+
case 'McModal/hide':
|
51
|
+
{
|
52
|
+
var _modalId2 = action.payload.modalId;
|
53
|
+
if (!state[_modalId2]) return state;
|
54
|
+
return _objectSpread(_objectSpread({}, state), {}, _defineProperty({}, _modalId2, _objectSpread(_objectSpread({}, state[_modalId2]), {}, {
|
55
|
+
visible: false
|
56
|
+
})));
|
57
|
+
}
|
58
|
+
case 'McModal/remove':
|
59
|
+
{
|
60
|
+
var _modalId3 = action.payload.modalId;
|
61
|
+
var newState = _objectSpread({}, state);
|
62
|
+
delete newState[_modalId3];
|
63
|
+
return newState;
|
64
|
+
}
|
65
|
+
case 'McModal/setFlags':
|
66
|
+
{
|
67
|
+
var _action$payload2 = action.payload,
|
68
|
+
_modalId4 = _action$payload2.modalId,
|
69
|
+
flags = _action$payload2.flags;
|
70
|
+
return _objectSpread(_objectSpread({}, state), {}, _defineProperty({}, _modalId4, _objectSpread(_objectSpread({}, state[_modalId4]), flags)));
|
71
|
+
}
|
72
|
+
default:
|
73
|
+
return state;
|
74
|
+
}
|
75
|
+
};
|
76
|
+
|
77
|
+
// Get modal component by modal id
|
78
|
+
function getModal(modalId) {
|
79
|
+
var _MODAL_REGISTRY$modal;
|
80
|
+
return (_MODAL_REGISTRY$modal = MODAL_REGISTRY[modalId]) === null || _MODAL_REGISTRY$modal === void 0 ? void 0 : _MODAL_REGISTRY$modal.comp;
|
81
|
+
}
|
82
|
+
|
83
|
+
// action creator to show a modal
|
84
|
+
function showModal(modalId, args) {
|
85
|
+
return {
|
86
|
+
type: 'McModal/show',
|
87
|
+
payload: {
|
88
|
+
modalId: modalId,
|
89
|
+
args: args
|
90
|
+
}
|
91
|
+
};
|
92
|
+
}
|
93
|
+
|
94
|
+
// action creator to set flags of a modal
|
95
|
+
function setModalFlags(modalId, flags) {
|
96
|
+
return {
|
97
|
+
type: 'McModal/setFlags',
|
98
|
+
payload: {
|
99
|
+
modalId: modalId,
|
100
|
+
flags: flags
|
101
|
+
}
|
102
|
+
};
|
103
|
+
}
|
104
|
+
// action creator to hide a modal
|
105
|
+
function hideModal(modalId) {
|
106
|
+
return {
|
107
|
+
type: 'McModal/hide',
|
108
|
+
payload: {
|
109
|
+
modalId: modalId
|
110
|
+
}
|
111
|
+
};
|
112
|
+
}
|
113
|
+
|
114
|
+
// action creator to remove a modal
|
115
|
+
function removeModal(modalId) {
|
116
|
+
return {
|
117
|
+
type: 'McModal/remove',
|
118
|
+
payload: {
|
119
|
+
modalId: modalId
|
120
|
+
}
|
121
|
+
};
|
122
|
+
}
|
123
|
+
var modalCallbacks = {};
|
124
|
+
var hideModalCallbacks = {};
|
125
|
+
var getModalId = function getModalId(modal) {
|
126
|
+
if (typeof modal === 'string') return modal;
|
127
|
+
// @ts-ignore
|
128
|
+
if (!modal[symModalId]) {
|
129
|
+
// @ts-ignore
|
130
|
+
modal[symModalId] = getUid();
|
131
|
+
}
|
132
|
+
// @ts-ignore
|
133
|
+
return modal[symModalId];
|
134
|
+
};
|
135
|
+
|
136
|
+
// All registered modals will be rendered in modal placeholder
|
137
|
+
export var register = function register(id, comp, props) {
|
138
|
+
if (!MODAL_REGISTRY[id]) {
|
139
|
+
MODAL_REGISTRY[id] = {
|
140
|
+
comp: comp,
|
141
|
+
props: props
|
142
|
+
};
|
143
|
+
} else {
|
144
|
+
MODAL_REGISTRY[id].props = props;
|
145
|
+
}
|
146
|
+
};
|
147
|
+
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
148
|
+
export function show(modal, args) {
|
149
|
+
var modalId = getModalId(modal);
|
150
|
+
if (typeof modal !== 'string' && !MODAL_REGISTRY[modalId]) {
|
151
|
+
register(modalId, modal);
|
152
|
+
}
|
153
|
+
dispatch(showModal(modalId, args));
|
154
|
+
if (!modalCallbacks[modalId]) {
|
155
|
+
// `!` tell ts that theResolve will be written before it is used
|
156
|
+
var theResolve;
|
157
|
+
// `!` tell ts that theResolve will be written before it is used
|
158
|
+
var theReject;
|
159
|
+
var promise = new Promise(function (resolve, reject) {
|
160
|
+
theResolve = resolve;
|
161
|
+
theReject = reject;
|
162
|
+
});
|
163
|
+
modalCallbacks[modalId] = {
|
164
|
+
resolve: theResolve,
|
165
|
+
reject: theReject,
|
166
|
+
promise: promise
|
167
|
+
};
|
168
|
+
}
|
169
|
+
return modalCallbacks[modalId].promise;
|
170
|
+
}
|
171
|
+
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
172
|
+
export function hide(modal) {
|
173
|
+
var modalId = getModalId(modal);
|
174
|
+
dispatch(hideModal(modalId));
|
175
|
+
// Should also delete the callback for modal.resolve #35
|
176
|
+
delete modalCallbacks[modalId];
|
177
|
+
if (!hideModalCallbacks[modalId]) {
|
178
|
+
// `!` tell ts that theResolve will be written before it is used
|
179
|
+
var theResolve;
|
180
|
+
// `!` tell ts that theResolve will be written before it is used
|
181
|
+
var theReject;
|
182
|
+
var promise = new Promise(function (resolve, reject) {
|
183
|
+
theResolve = resolve;
|
184
|
+
theReject = reject;
|
185
|
+
});
|
186
|
+
hideModalCallbacks[modalId] = {
|
187
|
+
resolve: theResolve,
|
188
|
+
reject: theReject,
|
189
|
+
promise: promise
|
190
|
+
};
|
191
|
+
}
|
192
|
+
return hideModalCallbacks[modalId].promise;
|
193
|
+
}
|
194
|
+
export var remove = function remove(modal) {
|
195
|
+
var modalId = getModalId(modal);
|
196
|
+
dispatch(removeModal(modalId));
|
197
|
+
delete modalCallbacks[modalId];
|
198
|
+
delete hideModalCallbacks[modalId];
|
199
|
+
};
|
200
|
+
var setFlags = function setFlags(modalId, flags) {
|
201
|
+
dispatch(setModalFlags(modalId, flags));
|
202
|
+
};
|
203
|
+
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
204
|
+
export function useModal(modal, args) {
|
205
|
+
var modals = useContext(McModalContext);
|
206
|
+
var contextModalId = useContext(McModalIdContext);
|
207
|
+
var modalId = null;
|
208
|
+
var isUseComponent = modal && typeof modal !== 'string';
|
209
|
+
if (!modal) {
|
210
|
+
modalId = contextModalId;
|
211
|
+
} else {
|
212
|
+
modalId = getModalId(modal);
|
213
|
+
}
|
214
|
+
|
215
|
+
// Only if contextModalId doesn't exist
|
216
|
+
if (!modalId) throw new Error('No modal id found in McModal.useModal.');
|
217
|
+
var mid = modalId;
|
218
|
+
// If use a component directly, register it.
|
219
|
+
useEffect(function () {
|
220
|
+
if (isUseComponent && !MODAL_REGISTRY[mid]) {
|
221
|
+
register(mid, modal, args);
|
222
|
+
}
|
223
|
+
}, [isUseComponent, mid, modal, args]);
|
224
|
+
var modalInfo = modals[mid];
|
225
|
+
var showCallback = useCallback(function (args) {
|
226
|
+
return show(mid, args);
|
227
|
+
}, [mid]);
|
228
|
+
var hideCallback = useCallback(function () {
|
229
|
+
return hide(mid);
|
230
|
+
}, [mid]);
|
231
|
+
var removeCallback = useCallback(function () {
|
232
|
+
return remove(mid);
|
233
|
+
}, [mid]);
|
234
|
+
var resolveCallback = useCallback(function (args) {
|
235
|
+
var _modalCallbacks$mid;
|
236
|
+
(_modalCallbacks$mid = modalCallbacks[mid]) === null || _modalCallbacks$mid === void 0 || _modalCallbacks$mid.resolve(args);
|
237
|
+
delete modalCallbacks[mid];
|
238
|
+
}, [mid]);
|
239
|
+
var rejectCallback = useCallback(function (args) {
|
240
|
+
var _modalCallbacks$mid2;
|
241
|
+
(_modalCallbacks$mid2 = modalCallbacks[mid]) === null || _modalCallbacks$mid2 === void 0 || _modalCallbacks$mid2.reject(args);
|
242
|
+
delete modalCallbacks[mid];
|
243
|
+
}, [mid]);
|
244
|
+
var resolveHide = useCallback(function (args) {
|
245
|
+
var _hideModalCallbacks$m;
|
246
|
+
(_hideModalCallbacks$m = hideModalCallbacks[mid]) === null || _hideModalCallbacks$m === void 0 || _hideModalCallbacks$m.resolve(args);
|
247
|
+
delete hideModalCallbacks[mid];
|
248
|
+
}, [mid]);
|
249
|
+
return useMemo(function () {
|
250
|
+
return {
|
251
|
+
id: mid,
|
252
|
+
args: modalInfo === null || modalInfo === void 0 ? void 0 : modalInfo.args,
|
253
|
+
visible: !!(modalInfo !== null && modalInfo !== void 0 && modalInfo.visible),
|
254
|
+
keepMounted: !!(modalInfo !== null && modalInfo !== void 0 && modalInfo.keepMounted),
|
255
|
+
show: showCallback,
|
256
|
+
hide: hideCallback,
|
257
|
+
remove: removeCallback,
|
258
|
+
resolve: resolveCallback,
|
259
|
+
reject: rejectCallback,
|
260
|
+
resolveHide: resolveHide
|
261
|
+
};
|
262
|
+
}, [mid, modalInfo === null || modalInfo === void 0 ? void 0 : modalInfo.args, modalInfo === null || modalInfo === void 0 ? void 0 : modalInfo.visible, modalInfo === null || modalInfo === void 0 ? void 0 : modalInfo.keepMounted, showCallback, hideCallback, removeCallback, resolveCallback, rejectCallback, resolveHide]);
|
263
|
+
}
|
264
|
+
export var create = function create(Comp) {
|
265
|
+
return function (_ref) {
|
266
|
+
var _modals$id;
|
267
|
+
var defaultVisible = _ref.defaultVisible,
|
268
|
+
keepMounted = _ref.keepMounted,
|
269
|
+
id = _ref.id,
|
270
|
+
props = _objectWithoutProperties(_ref, _excluded);
|
271
|
+
var _useModal = useModal(id),
|
272
|
+
args = _useModal.args,
|
273
|
+
show = _useModal.show;
|
274
|
+
|
275
|
+
// If there's modal state, then should mount it.
|
276
|
+
var modals = useContext(McModalContext);
|
277
|
+
var shouldMount = !!modals[id];
|
278
|
+
useEffect(function () {
|
279
|
+
// If defaultVisible, show it after mounted.
|
280
|
+
if (defaultVisible) {
|
281
|
+
show();
|
282
|
+
}
|
283
|
+
ALREADY_MOUNTED[id] = true;
|
284
|
+
return function () {
|
285
|
+
delete ALREADY_MOUNTED[id];
|
286
|
+
};
|
287
|
+
}, [id, show, defaultVisible]);
|
288
|
+
useEffect(function () {
|
289
|
+
if (keepMounted) setFlags(id, {
|
290
|
+
keepMounted: true
|
291
|
+
});
|
292
|
+
}, [id, keepMounted]);
|
293
|
+
var delayVisible = (_modals$id = modals[id]) === null || _modals$id === void 0 ? void 0 : _modals$id.delayVisible;
|
294
|
+
// If modal.show is called
|
295
|
+
// 1. If modal was mounted, should make it visible directly
|
296
|
+
// 2. If modal has not been mounted, should mount it first, then make it visible
|
297
|
+
useEffect(function () {
|
298
|
+
if (delayVisible) {
|
299
|
+
// delayVisible: false => true, it means the modal.show() is called, should show it.
|
300
|
+
show(args);
|
301
|
+
}
|
302
|
+
}, [delayVisible, args, show]);
|
303
|
+
if (!shouldMount) return null;
|
304
|
+
return /*#__PURE__*/_jsx(McModalIdContext.Provider, {
|
305
|
+
value: id,
|
306
|
+
children: /*#__PURE__*/_jsx(Comp, _objectSpread(_objectSpread({}, props), args))
|
307
|
+
});
|
308
|
+
};
|
309
|
+
};
|
310
|
+
|
311
|
+
/**
|
312
|
+
* Unregister a modal.
|
313
|
+
* @param id - The id of the modal.
|
314
|
+
*/
|
315
|
+
export var unregister = function unregister(id) {
|
316
|
+
delete MODAL_REGISTRY[id];
|
317
|
+
};
|
318
|
+
|
319
|
+
// The placeholder component is used to auto render modals when call modal.show()
|
320
|
+
// When modal.show() is called, it means there've been modal info
|
321
|
+
var McModalPlaceholder = function McModalPlaceholder() {
|
322
|
+
var modals = useContext(McModalContext);
|
323
|
+
var visibleModalIds = Object.keys(modals).filter(function (id) {
|
324
|
+
return !!modals[id];
|
325
|
+
});
|
326
|
+
visibleModalIds.forEach(function (id) {
|
327
|
+
if (!MODAL_REGISTRY[id] && !ALREADY_MOUNTED[id]) {
|
328
|
+
console.warn("No modal found for id: ".concat(id, ". Please check the id or if it is registered or declared via JSX."));
|
329
|
+
return;
|
330
|
+
}
|
331
|
+
});
|
332
|
+
var toRender = visibleModalIds.filter(function (id) {
|
333
|
+
return MODAL_REGISTRY[id];
|
334
|
+
}).map(function (id) {
|
335
|
+
return _objectSpread({
|
336
|
+
id: id
|
337
|
+
}, MODAL_REGISTRY[id]);
|
338
|
+
});
|
339
|
+
return /*#__PURE__*/_jsx(_Fragment, {
|
340
|
+
children: toRender.map(function (t) {
|
341
|
+
return /*#__PURE__*/_jsx(t.comp, _objectSpread({
|
342
|
+
id: t.id
|
343
|
+
}, t.props), t.id);
|
344
|
+
})
|
345
|
+
});
|
346
|
+
};
|
347
|
+
var InnerContextProvider = function InnerContextProvider(_ref2) {
|
348
|
+
var children = _ref2.children;
|
349
|
+
var arr = useReducer(reducer, initialState);
|
350
|
+
var modals = arr[0];
|
351
|
+
dispatch = arr[1];
|
352
|
+
return /*#__PURE__*/_jsxs(McModalContext.Provider, {
|
353
|
+
value: modals,
|
354
|
+
children: [children, /*#__PURE__*/_jsx(McModalPlaceholder, {})]
|
355
|
+
});
|
356
|
+
};
|
357
|
+
export var Provider = function Provider(_ref3) {
|
358
|
+
var children = _ref3.children,
|
359
|
+
givenDispatch = _ref3.dispatch,
|
360
|
+
givenModals = _ref3.modals;
|
361
|
+
if (!givenDispatch || !givenModals) {
|
362
|
+
return /*#__PURE__*/_jsx(InnerContextProvider, {
|
363
|
+
children: children
|
364
|
+
});
|
365
|
+
}
|
366
|
+
dispatch = givenDispatch;
|
367
|
+
return /*#__PURE__*/_jsxs(McModalContext.Provider, {
|
368
|
+
value: givenModals,
|
369
|
+
children: [children, /*#__PURE__*/_jsx(McModalPlaceholder, {})]
|
370
|
+
});
|
371
|
+
};
|
372
|
+
|
373
|
+
/**
|
374
|
+
* Declarative way to register a modal.
|
375
|
+
* @param id - The id of the modal.
|
376
|
+
* @param component - The modal Component.
|
377
|
+
* @returns
|
378
|
+
*/
|
379
|
+
export var ModalDef = function ModalDef(_ref4) {
|
380
|
+
var id = _ref4.id,
|
381
|
+
component = _ref4.component;
|
382
|
+
useEffect(function () {
|
383
|
+
register(id, component);
|
384
|
+
return function () {
|
385
|
+
unregister(id);
|
386
|
+
};
|
387
|
+
}, [id, component]);
|
388
|
+
return null;
|
389
|
+
};
|
390
|
+
|
391
|
+
/**
|
392
|
+
* A place holder allows to bind props to a modal.
|
393
|
+
* It assigns show/hide methods to handler object to show/hide the modal.
|
394
|
+
*
|
395
|
+
* Comparing to use the <MyMcModal id=../> directly, this approach allows use registered modal id to find the modal component.
|
396
|
+
* Also it avoids to create unique id for MyMcModal.
|
397
|
+
*
|
398
|
+
* @param modal - The modal id registered or a modal component.
|
399
|
+
* @param handler - The handler object to control the modal.
|
400
|
+
* @returns
|
401
|
+
*/
|
402
|
+
export var ModalHolder = function ModalHolder(_ref5) {
|
403
|
+
var _MODAL_REGISTRY$modal2;
|
404
|
+
var modal = _ref5.modal,
|
405
|
+
_ref5$handler = _ref5.handler,
|
406
|
+
handler = _ref5$handler === void 0 ? {} : _ref5$handler,
|
407
|
+
restProps = _objectWithoutProperties(_ref5, _excluded2);
|
408
|
+
var mid = useMemo(function () {
|
409
|
+
return getUid();
|
410
|
+
}, []);
|
411
|
+
var ModalComp = typeof modal === 'string' ? (_MODAL_REGISTRY$modal2 = MODAL_REGISTRY[modal]) === null || _MODAL_REGISTRY$modal2 === void 0 ? void 0 : _MODAL_REGISTRY$modal2.comp : modal;
|
412
|
+
if (!handler) {
|
413
|
+
throw new Error('No handler found in McModal.ModalHolder.');
|
414
|
+
}
|
415
|
+
if (!ModalComp) {
|
416
|
+
throw new Error("No modal found for id: ".concat(modal, " in McModal.ModalHolder."));
|
417
|
+
}
|
418
|
+
handler.show = useCallback(function (args) {
|
419
|
+
return show(mid, args);
|
420
|
+
}, [mid]);
|
421
|
+
handler.hide = useCallback(function () {
|
422
|
+
return hide(mid);
|
423
|
+
}, [mid]);
|
424
|
+
return /*#__PURE__*/_jsx(ModalComp, _objectSpread({
|
425
|
+
id: mid
|
426
|
+
}, restProps));
|
427
|
+
};
|
428
|
+
export var antdModalV4 = function antdModalV4(modal) {
|
429
|
+
return {
|
430
|
+
visible: modal.visible,
|
431
|
+
onOk: function onOk() {
|
432
|
+
return modal.hide();
|
433
|
+
},
|
434
|
+
onCancel: function onCancel() {
|
435
|
+
return modal.hide();
|
436
|
+
},
|
437
|
+
afterClose: function afterClose() {
|
438
|
+
// Need to resolve before remove
|
439
|
+
modal.resolveHide();
|
440
|
+
if (!modal.keepMounted) modal.remove();
|
441
|
+
}
|
442
|
+
};
|
443
|
+
};
|
444
|
+
export var antdModal = function antdModal(modal) {
|
445
|
+
var _antdModalV = antdModalV4(modal),
|
446
|
+
onOk = _antdModalV.onOk,
|
447
|
+
onCancel = _antdModalV.onCancel,
|
448
|
+
afterClose = _antdModalV.afterClose;
|
449
|
+
return {
|
450
|
+
open: modal.visible,
|
451
|
+
onOk: onOk,
|
452
|
+
onCancel: onCancel,
|
453
|
+
afterClose: afterClose
|
454
|
+
};
|
455
|
+
};
|
456
|
+
export var antdDrawerV4 = function antdDrawerV4(modal) {
|
457
|
+
return {
|
458
|
+
visible: modal.visible,
|
459
|
+
onClose: function onClose() {
|
460
|
+
return modal.hide();
|
461
|
+
},
|
462
|
+
afterVisibleChange: function afterVisibleChange(v) {
|
463
|
+
if (!v) {
|
464
|
+
modal.resolveHide();
|
465
|
+
}
|
466
|
+
if (!v && !modal.keepMounted) {
|
467
|
+
modal.remove();
|
468
|
+
}
|
469
|
+
}
|
470
|
+
};
|
471
|
+
};
|
472
|
+
export var antdDrawer = function antdDrawer(modal) {
|
473
|
+
var _antdDrawerV = antdDrawerV4(modal),
|
474
|
+
onClose = _antdDrawerV.onClose,
|
475
|
+
afterOpenChange = _antdDrawerV.afterVisibleChange;
|
476
|
+
return {
|
477
|
+
open: modal.visible,
|
478
|
+
onClose: onClose,
|
479
|
+
afterOpenChange: afterOpenChange
|
480
|
+
};
|
481
|
+
};
|
482
|
+
var McModal = {
|
483
|
+
Provider: Provider,
|
484
|
+
ModalDef: ModalDef,
|
485
|
+
ModalHolder: ModalHolder,
|
486
|
+
McModalContext: McModalContext,
|
487
|
+
create: create,
|
488
|
+
register: register,
|
489
|
+
getModal: getModal,
|
490
|
+
show: show,
|
491
|
+
hide: hide,
|
492
|
+
remove: remove,
|
493
|
+
useModal: useModal,
|
494
|
+
reducer: reducer,
|
495
|
+
antdModal: antdModal,
|
496
|
+
antdDrawer: antdDrawer
|
497
|
+
};
|
498
|
+
export default McModal;
|
@@ -0,0 +1,13 @@
|
|
1
|
+
import { CSSProperties, FC } from 'react';
|
2
|
+
import './index.less';
|
3
|
+
type PropsType = {
|
4
|
+
style?: CSSProperties;
|
5
|
+
className?: string;
|
6
|
+
half?: boolean;
|
7
|
+
value?: string;
|
8
|
+
onChange?: (value?: string) => void;
|
9
|
+
disabled?: boolean;
|
10
|
+
[key: string]: any;
|
11
|
+
};
|
12
|
+
declare const McPeriodSelect: FC<PropsType>;
|
13
|
+
export default McPeriodSelect;
|