@zykj2024/much-library 1.0.9
Sign up to get free protection for your applications and to get access to all the features.
- package/LICENSE +21 -0
- package/README.md +35 -0
- package/dist/McCascader/city.js +909 -0
- package/dist/McCascader/index.css +60 -0
- package/dist/McCascader/index.d.ts +19 -0
- package/dist/McCascader/index.js +221 -0
- package/dist/McContainer/demo/actionBar.d.ts +8 -0
- package/dist/McContainer/demo/actionBar.js +70 -0
- package/dist/McContainer/demo/base.d.ts +8 -0
- package/dist/McContainer/demo/base.js +80 -0
- package/dist/McContainer/demo/batch.d.ts +8 -0
- package/dist/McContainer/demo/batch.js +89 -0
- package/dist/McContainer/demo/collapse.d.ts +8 -0
- package/dist/McContainer/demo/collapse.js +76 -0
- package/dist/McContainer/demo/expand.d.ts +8 -0
- package/dist/McContainer/demo/expand.js +90 -0
- package/dist/McContainer/demo/pagination.d.ts +7 -0
- package/dist/McContainer/demo/pagination.js +93 -0
- package/dist/McContainer/demo/search.d.ts +7 -0
- package/dist/McContainer/demo/search.js +101 -0
- package/dist/McContainer/demo/standard.d.ts +7 -0
- package/dist/McContainer/demo/standard.js +168 -0
- package/dist/McContainer/index.css +123 -0
- package/dist/McContainer/index.d.ts +49 -0
- package/dist/McContainer/index.js +407 -0
- package/dist/McDateRange/demo/base.d.ts +6 -0
- package/dist/McDateRange/demo/base.js +22 -0
- package/dist/McDateRange/demo/cancelPresets.d.ts +6 -0
- package/dist/McDateRange/demo/cancelPresets.js +23 -0
- package/dist/McDateRange/demo/overlap.d.ts +2 -0
- package/dist/McDateRange/demo/overlap.js +32 -0
- package/dist/McDateRange/index.css +31 -0
- package/dist/McDateRange/index.d.ts +28 -0
- package/dist/McDateRange/index.js +167 -0
- package/dist/McFonts/index.d.ts +7 -0
- package/dist/McFonts/index.js +10 -0
- package/dist/McFonts/public/FF DIN Pro Bold.otf +0 -0
- package/dist/McFonts/public/SourceHanSansCN-Bold.otf +0 -0
- package/dist/McFonts/public/SourceHanSansCN-Light.otf +0 -0
- package/dist/McFonts/public/SourceHanSansCN-Medium.otf +0 -0
- package/dist/McFonts/public/SourceHanSansCN-Regular.otf +0 -0
- package/dist/McGroupPanel/comps/SelectedItem/index.d.ts +4 -0
- package/dist/McGroupPanel/comps/SelectedItem/index.js +76 -0
- package/dist/McGroupPanel/index.css +162 -0
- package/dist/McGroupPanel/index.d.ts +29 -0
- package/dist/McGroupPanel/index.js +411 -0
- package/dist/McIconFont/iconfont.js +1 -0
- package/dist/McIconFont/index.d.ts +5 -0
- package/dist/McIconFont/index.js +8 -0
- package/dist/McIcons/business.json +137 -0
- package/dist/McInput/Input.d.ts +19 -0
- package/dist/McInput/Input.js +48 -0
- package/dist/McInput/Search.d.ts +39 -0
- package/dist/McInput/Search.js +81 -0
- package/dist/McInput/TextArea.d.ts +11 -0
- package/dist/McInput/TextArea.js +37 -0
- package/dist/McInput/demo/Input/addonBefore.d.ts +3 -0
- package/dist/McInput/demo/Input/addonBefore.js +67 -0
- package/dist/McInput/demo/Input/base.d.ts +2 -0
- package/dist/McInput/demo/Input/base.js +31 -0
- package/dist/McInput/demo/Input/isTrim.d.ts +2 -0
- package/dist/McInput/demo/Input/isTrim.js +22 -0
- package/dist/McInput/demo/Input/label.d.ts +2 -0
- package/dist/McInput/demo/Input/label.js +26 -0
- package/dist/McInput/demo/Input/ref.d.ts +3 -0
- package/dist/McInput/demo/Input/ref.js +53 -0
- package/dist/McInput/demo/Input/status.d.ts +2 -0
- package/dist/McInput/demo/Input/status.js +23 -0
- package/dist/McInput/demo/Search/search-base.d.ts +2 -0
- package/dist/McInput/demo/Search/search-base.js +38 -0
- package/dist/McInput/demo/TextArea/text-area-base.d.ts +2 -0
- package/dist/McInput/demo/TextArea/text-area-base.js +38 -0
- package/dist/McInput/index.css +44 -0
- package/dist/McInput/index.d.ts +13 -0
- package/dist/McInput/index.js +7 -0
- package/dist/McInputNumber/demo/index.d.ts +2 -0
- package/dist/McInputNumber/demo/index.js +28 -0
- package/dist/McInputNumber/demo/label.d.ts +2 -0
- package/dist/McInputNumber/demo/label.js +26 -0
- package/dist/McInputNumber/demo/precision.d.ts +2 -0
- package/dist/McInputNumber/demo/precision.js +20 -0
- package/dist/McInputNumber/index.css +9 -0
- package/dist/McInputNumber/index.d.ts +13 -0
- package/dist/McInputNumber/index.js +43 -0
- package/dist/McModalProvider/index.d.ts +174 -0
- package/dist/McModalProvider/index.js +498 -0
- package/dist/McPeriodSelect/demo/base.d.ts +6 -0
- package/dist/McPeriodSelect/demo/base.js +19 -0
- package/dist/McPeriodSelect/demo/half.d.ts +6 -0
- package/dist/McPeriodSelect/demo/half.js +20 -0
- package/dist/McPeriodSelect/index.css +189 -0
- package/dist/McPeriodSelect/index.d.ts +13 -0
- package/dist/McPeriodSelect/index.js +305 -0
- package/dist/McPopoverButton/index.d.ts +14 -0
- package/dist/McPopoverButton/index.js +52 -0
- package/dist/McPopoverForm/index.d.ts +14 -0
- package/dist/McPopoverForm/index.js +95 -0
- package/dist/McResult/default.d.ts +1 -0
- package/dist/McResult/default.js +84 -0
- package/dist/McResult/demo/403.d.ts +6 -0
- package/dist/McResult/demo/403.js +17 -0
- package/dist/McResult/demo/404.d.ts +6 -0
- package/dist/McResult/demo/404.js +17 -0
- package/dist/McResult/demo/500.d.ts +6 -0
- package/dist/McResult/demo/500.js +17 -0
- package/dist/McResult/demo/building.d.ts +6 -0
- package/dist/McResult/demo/building.js +12 -0
- package/dist/McResult/demo/empty.d.ts +2 -0
- package/dist/McResult/demo/empty.js +11 -0
- package/dist/McResult/demo/noFunction.d.ts +2 -0
- package/dist/McResult/demo/noFunction.js +11 -0
- package/dist/McResult/demo/noUser.d.ts +6 -0
- package/dist/McResult/demo/noUser.js +12 -0
- package/dist/McResult/demo/preview.d.ts +2 -0
- package/dist/McResult/demo/preview.js +14 -0
- package/dist/McResult/icon.d.ts +25 -0
- package/dist/McResult/icon.js +946 -0
- package/dist/McResult/index.css +20 -0
- package/dist/McResult/index.d.ts +27 -0
- package/dist/McResult/index.js +103 -0
- package/dist/McResult/public/403.svg +164 -0
- package/dist/McResult/public/404.svg +123 -0
- package/dist/McResult/public/500.svg +129 -0
- package/dist/McResult/public/building.svg +127 -0
- package/dist/McResult/public/code403.svg +7 -0
- package/dist/McResult/public/code404.svg +5 -0
- package/dist/McResult/public/code500.svg +5 -0
- package/dist/McResult/public/empty.svg +1 -0
- package/dist/McResult/public/noFunction.svg +1 -0
- package/dist/McResult/public/noUser.svg +90 -0
- package/dist/McSelect/demo/base.d.ts +2 -0
- package/dist/McSelect/demo/base.js +63 -0
- package/dist/McSelect/demo/changeOnHidden.d.ts +2 -0
- package/dist/McSelect/demo/changeOnHidden.js +43 -0
- package/dist/McSelect/demo/dropdownRender.d.ts +7 -0
- package/dist/McSelect/demo/dropdownRender.js +78 -0
- package/dist/McSelect/demo/fetchOptions.d.ts +7 -0
- package/dist/McSelect/demo/fetchOptions.js +210 -0
- package/dist/McSelect/demo/inexistent.d.ts +2 -0
- package/dist/McSelect/demo/inexistent.js +79 -0
- package/dist/McSelect/demo/labelInValue.d.ts +2 -0
- package/dist/McSelect/demo/labelInValue.js +72 -0
- package/dist/McSelect/demo/maxTagCount.d.ts +3 -0
- package/dist/McSelect/demo/maxTagCount.js +51 -0
- package/dist/McSelect/demo/multiple.d.ts +2 -0
- package/dist/McSelect/demo/multiple.js +46 -0
- package/dist/McSelect/demo/optionRender.d.ts +3 -0
- package/dist/McSelect/demo/optionRender.js +51 -0
- package/dist/McSelect/demo/tagRender.d.ts +3 -0
- package/dist/McSelect/demo/tagRender.js +51 -0
- package/dist/McSelect/index.css +60 -0
- package/dist/McSelect/index.d.ts +40 -0
- package/dist/McSelect/index.js +350 -0
- package/dist/McThemeConfig/customToken.json +38 -0
- package/dist/McThemeConfig/demo/button.d.ts +2 -0
- package/dist/McThemeConfig/demo/button.js +226 -0
- package/dist/McThemeConfig/demo/drawer.d.ts +2 -0
- package/dist/McThemeConfig/demo/drawer.js +59 -0
- package/dist/McThemeConfig/demo/modal.d.ts +2 -0
- package/dist/McThemeConfig/demo/modal.js +78 -0
- package/dist/McThemeConfig/demo/radio.d.ts +2 -0
- package/dist/McThemeConfig/demo/radio.js +97 -0
- package/dist/McThemeConfig/demo/switch.d.ts +2 -0
- package/dist/McThemeConfig/demo/switch.js +96 -0
- package/dist/McThemeConfig/demo/tabs.d.ts +2 -0
- package/dist/McThemeConfig/demo/tabs.js +35 -0
- package/dist/McThemeConfig/globalStyle.d.ts +2 -0
- package/dist/McThemeConfig/globalStyle.js +172 -0
- package/dist/McThemeConfig/index.d.ts +9 -0
- package/dist/McThemeConfig/index.js +16 -0
- package/dist/McThemeConfig/layoutStyle.d.ts +2 -0
- package/dist/McThemeConfig/layoutStyle.js +1 -0
- package/dist/McThemeConfig/provider.d.ts +7 -0
- package/dist/McThemeConfig/provider.js +19 -0
- package/dist/McThemeConfig/themeToken.json +149 -0
- package/dist/McTreePanel/SelectedItem.d.ts +4 -0
- package/dist/McTreePanel/SelectedItem.js +75 -0
- package/dist/McTreePanel/demo/base.d.ts +6 -0
- package/dist/McTreePanel/demo/base.js +45 -0
- package/dist/McTreePanel/demo/fieldNames.d.ts +6 -0
- package/dist/McTreePanel/demo/fieldNames.js +37 -0
- package/dist/McTreePanel/demo/inexistent.d.ts +6 -0
- package/dist/McTreePanel/demo/inexistent.js +56 -0
- package/dist/McTreePanel/demo/labelInValue.d.ts +6 -0
- package/dist/McTreePanel/demo/labelInValue.js +56 -0
- package/dist/McTreePanel/demo/sortable.d.ts +6 -0
- package/dist/McTreePanel/demo/sortable.js +34 -0
- package/dist/McTreePanel/index.css +110 -0
- package/dist/McTreePanel/index.d.ts +27 -0
- package/dist/McTreePanel/index.js +315 -0
- package/dist/McTreeSelect/demo/base.d.ts +5 -0
- package/dist/McTreeSelect/demo/base.js +58 -0
- package/dist/McTreeSelect/demo/inexistent.d.ts +5 -0
- package/dist/McTreeSelect/demo/inexistent.js +63 -0
- package/dist/McTreeSelect/demo/label.d.ts +5 -0
- package/dist/McTreeSelect/demo/label.js +60 -0
- package/dist/McTreeSelect/demo/multiple.d.ts +5 -0
- package/dist/McTreeSelect/demo/multiple.js +71 -0
- package/dist/McTreeSelect/index.css +60 -0
- package/dist/McTreeSelect/index.d.ts +13 -0
- package/dist/McTreeSelect/index.js +182 -0
- package/dist/Utils/index.d.ts +4 -0
- package/dist/Utils/index.js +26 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.js +19 -0
- package/dist/typings.d.ts +20 -0
- package/package.json +82 -0
@@ -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,19 @@
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
2
|
+
/**
|
3
|
+
* title: 基础用法
|
4
|
+
* description: 通过 `value` 属性设置默认值,通过 `onChange` 事件获取当前值。
|
5
|
+
*/
|
6
|
+
|
7
|
+
import { McPeriodSelect } from "../..";
|
8
|
+
import { useState } from 'react';
|
9
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
10
|
+
export default (function () {
|
11
|
+
var _useState = useState(),
|
12
|
+
_useState2 = _slicedToArray(_useState, 2),
|
13
|
+
value = _useState2[0],
|
14
|
+
setValue = _useState2[1];
|
15
|
+
return /*#__PURE__*/_jsx(McPeriodSelect, {
|
16
|
+
value: value,
|
17
|
+
onChange: setValue
|
18
|
+
});
|
19
|
+
});
|
@@ -0,0 +1,20 @@
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
2
|
+
/**
|
3
|
+
* title: 改变单位时间长度为半小时
|
4
|
+
* description: 通过设置half属性为true,可以使选择的时间段的单位长度变为半小时。
|
5
|
+
*/
|
6
|
+
|
7
|
+
import { McPeriodSelect } from "../..";
|
8
|
+
import { useState } from 'react';
|
9
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
10
|
+
export default (function () {
|
11
|
+
var _useState = useState(),
|
12
|
+
_useState2 = _slicedToArray(_useState, 2),
|
13
|
+
value = _useState2[0],
|
14
|
+
setValue = _useState2[1];
|
15
|
+
return /*#__PURE__*/_jsx(McPeriodSelect, {
|
16
|
+
value: value,
|
17
|
+
half: true,
|
18
|
+
onChange: setValue
|
19
|
+
});
|
20
|
+
});
|