@zykj2024/much-library 1.0.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (207) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +35 -0
  3. package/dist/McCascader/city.js +909 -0
  4. package/dist/McCascader/index.css +60 -0
  5. package/dist/McCascader/index.d.ts +19 -0
  6. package/dist/McCascader/index.js +221 -0
  7. package/dist/McContainer/demo/actionBar.d.ts +8 -0
  8. package/dist/McContainer/demo/actionBar.js +70 -0
  9. package/dist/McContainer/demo/base.d.ts +8 -0
  10. package/dist/McContainer/demo/base.js +80 -0
  11. package/dist/McContainer/demo/batch.d.ts +8 -0
  12. package/dist/McContainer/demo/batch.js +89 -0
  13. package/dist/McContainer/demo/collapse.d.ts +8 -0
  14. package/dist/McContainer/demo/collapse.js +76 -0
  15. package/dist/McContainer/demo/expand.d.ts +8 -0
  16. package/dist/McContainer/demo/expand.js +90 -0
  17. package/dist/McContainer/demo/pagination.d.ts +7 -0
  18. package/dist/McContainer/demo/pagination.js +93 -0
  19. package/dist/McContainer/demo/search.d.ts +7 -0
  20. package/dist/McContainer/demo/search.js +101 -0
  21. package/dist/McContainer/demo/standard.d.ts +7 -0
  22. package/dist/McContainer/demo/standard.js +168 -0
  23. package/dist/McContainer/index.css +123 -0
  24. package/dist/McContainer/index.d.ts +49 -0
  25. package/dist/McContainer/index.js +407 -0
  26. package/dist/McDateRange/demo/base.d.ts +6 -0
  27. package/dist/McDateRange/demo/base.js +22 -0
  28. package/dist/McDateRange/demo/cancelPresets.d.ts +6 -0
  29. package/dist/McDateRange/demo/cancelPresets.js +23 -0
  30. package/dist/McDateRange/demo/overlap.d.ts +2 -0
  31. package/dist/McDateRange/demo/overlap.js +32 -0
  32. package/dist/McDateRange/index.css +31 -0
  33. package/dist/McDateRange/index.d.ts +28 -0
  34. package/dist/McDateRange/index.js +167 -0
  35. package/dist/McFonts/index.d.ts +7 -0
  36. package/dist/McFonts/index.js +10 -0
  37. package/dist/McFonts/public/FF DIN Pro Bold.otf +0 -0
  38. package/dist/McFonts/public/SourceHanSansCN-Bold.otf +0 -0
  39. package/dist/McFonts/public/SourceHanSansCN-Light.otf +0 -0
  40. package/dist/McFonts/public/SourceHanSansCN-Medium.otf +0 -0
  41. package/dist/McFonts/public/SourceHanSansCN-Regular.otf +0 -0
  42. package/dist/McGroupPanel/comps/SelectedItem/index.d.ts +4 -0
  43. package/dist/McGroupPanel/comps/SelectedItem/index.js +76 -0
  44. package/dist/McGroupPanel/index.css +162 -0
  45. package/dist/McGroupPanel/index.d.ts +29 -0
  46. package/dist/McGroupPanel/index.js +411 -0
  47. package/dist/McIconFont/iconfont.js +1 -0
  48. package/dist/McIconFont/index.d.ts +5 -0
  49. package/dist/McIconFont/index.js +8 -0
  50. package/dist/McIcons/business.json +137 -0
  51. package/dist/McInput/Input.d.ts +19 -0
  52. package/dist/McInput/Input.js +48 -0
  53. package/dist/McInput/Search.d.ts +39 -0
  54. package/dist/McInput/Search.js +81 -0
  55. package/dist/McInput/TextArea.d.ts +11 -0
  56. package/dist/McInput/TextArea.js +37 -0
  57. package/dist/McInput/demo/Input/addonBefore.d.ts +3 -0
  58. package/dist/McInput/demo/Input/addonBefore.js +67 -0
  59. package/dist/McInput/demo/Input/base.d.ts +2 -0
  60. package/dist/McInput/demo/Input/base.js +31 -0
  61. package/dist/McInput/demo/Input/isTrim.d.ts +2 -0
  62. package/dist/McInput/demo/Input/isTrim.js +22 -0
  63. package/dist/McInput/demo/Input/label.d.ts +2 -0
  64. package/dist/McInput/demo/Input/label.js +26 -0
  65. package/dist/McInput/demo/Input/ref.d.ts +3 -0
  66. package/dist/McInput/demo/Input/ref.js +53 -0
  67. package/dist/McInput/demo/Input/status.d.ts +2 -0
  68. package/dist/McInput/demo/Input/status.js +23 -0
  69. package/dist/McInput/demo/Search/search-base.d.ts +2 -0
  70. package/dist/McInput/demo/Search/search-base.js +38 -0
  71. package/dist/McInput/demo/TextArea/text-area-base.d.ts +2 -0
  72. package/dist/McInput/demo/TextArea/text-area-base.js +38 -0
  73. package/dist/McInput/index.css +44 -0
  74. package/dist/McInput/index.d.ts +13 -0
  75. package/dist/McInput/index.js +7 -0
  76. package/dist/McInputNumber/demo/index.d.ts +2 -0
  77. package/dist/McInputNumber/demo/index.js +28 -0
  78. package/dist/McInputNumber/demo/label.d.ts +2 -0
  79. package/dist/McInputNumber/demo/label.js +26 -0
  80. package/dist/McInputNumber/demo/precision.d.ts +2 -0
  81. package/dist/McInputNumber/demo/precision.js +20 -0
  82. package/dist/McInputNumber/index.css +9 -0
  83. package/dist/McInputNumber/index.d.ts +13 -0
  84. package/dist/McInputNumber/index.js +43 -0
  85. package/dist/McModalProvider/index.d.ts +174 -0
  86. package/dist/McModalProvider/index.js +498 -0
  87. package/dist/McPeriodSelect/demo/base.d.ts +6 -0
  88. package/dist/McPeriodSelect/demo/base.js +19 -0
  89. package/dist/McPeriodSelect/demo/half.d.ts +6 -0
  90. package/dist/McPeriodSelect/demo/half.js +20 -0
  91. package/dist/McPeriodSelect/index.css +189 -0
  92. package/dist/McPeriodSelect/index.d.ts +13 -0
  93. package/dist/McPeriodSelect/index.js +305 -0
  94. package/dist/McPopoverButton/index.d.ts +14 -0
  95. package/dist/McPopoverButton/index.js +52 -0
  96. package/dist/McPopoverForm/index.d.ts +14 -0
  97. package/dist/McPopoverForm/index.js +95 -0
  98. package/dist/McResult/default.d.ts +1 -0
  99. package/dist/McResult/default.js +84 -0
  100. package/dist/McResult/demo/403.d.ts +6 -0
  101. package/dist/McResult/demo/403.js +17 -0
  102. package/dist/McResult/demo/404.d.ts +6 -0
  103. package/dist/McResult/demo/404.js +17 -0
  104. package/dist/McResult/demo/500.d.ts +6 -0
  105. package/dist/McResult/demo/500.js +17 -0
  106. package/dist/McResult/demo/building.d.ts +6 -0
  107. package/dist/McResult/demo/building.js +12 -0
  108. package/dist/McResult/demo/empty.d.ts +2 -0
  109. package/dist/McResult/demo/empty.js +11 -0
  110. package/dist/McResult/demo/noFunction.d.ts +2 -0
  111. package/dist/McResult/demo/noFunction.js +11 -0
  112. package/dist/McResult/demo/noUser.d.ts +6 -0
  113. package/dist/McResult/demo/noUser.js +12 -0
  114. package/dist/McResult/demo/preview.d.ts +2 -0
  115. package/dist/McResult/demo/preview.js +14 -0
  116. package/dist/McResult/icon.d.ts +25 -0
  117. package/dist/McResult/icon.js +946 -0
  118. package/dist/McResult/index.css +20 -0
  119. package/dist/McResult/index.d.ts +27 -0
  120. package/dist/McResult/index.js +103 -0
  121. package/dist/McResult/public/403.svg +164 -0
  122. package/dist/McResult/public/404.svg +123 -0
  123. package/dist/McResult/public/500.svg +129 -0
  124. package/dist/McResult/public/building.svg +127 -0
  125. package/dist/McResult/public/code403.svg +7 -0
  126. package/dist/McResult/public/code404.svg +5 -0
  127. package/dist/McResult/public/code500.svg +5 -0
  128. package/dist/McResult/public/empty.svg +1 -0
  129. package/dist/McResult/public/noFunction.svg +1 -0
  130. package/dist/McResult/public/noUser.svg +90 -0
  131. package/dist/McSelect/demo/base.d.ts +2 -0
  132. package/dist/McSelect/demo/base.js +63 -0
  133. package/dist/McSelect/demo/changeOnHidden.d.ts +2 -0
  134. package/dist/McSelect/demo/changeOnHidden.js +43 -0
  135. package/dist/McSelect/demo/dropdownRender.d.ts +7 -0
  136. package/dist/McSelect/demo/dropdownRender.js +78 -0
  137. package/dist/McSelect/demo/fetchOptions.d.ts +7 -0
  138. package/dist/McSelect/demo/fetchOptions.js +210 -0
  139. package/dist/McSelect/demo/inexistent.d.ts +2 -0
  140. package/dist/McSelect/demo/inexistent.js +79 -0
  141. package/dist/McSelect/demo/labelInValue.d.ts +2 -0
  142. package/dist/McSelect/demo/labelInValue.js +72 -0
  143. package/dist/McSelect/demo/maxTagCount.d.ts +3 -0
  144. package/dist/McSelect/demo/maxTagCount.js +51 -0
  145. package/dist/McSelect/demo/multiple.d.ts +2 -0
  146. package/dist/McSelect/demo/multiple.js +46 -0
  147. package/dist/McSelect/demo/optionRender.d.ts +3 -0
  148. package/dist/McSelect/demo/optionRender.js +51 -0
  149. package/dist/McSelect/demo/tagRender.d.ts +3 -0
  150. package/dist/McSelect/demo/tagRender.js +51 -0
  151. package/dist/McSelect/index.css +60 -0
  152. package/dist/McSelect/index.d.ts +40 -0
  153. package/dist/McSelect/index.js +350 -0
  154. package/dist/McThemeConfig/customToken.json +38 -0
  155. package/dist/McThemeConfig/demo/button.d.ts +2 -0
  156. package/dist/McThemeConfig/demo/button.js +226 -0
  157. package/dist/McThemeConfig/demo/drawer.d.ts +2 -0
  158. package/dist/McThemeConfig/demo/drawer.js +59 -0
  159. package/dist/McThemeConfig/demo/modal.d.ts +2 -0
  160. package/dist/McThemeConfig/demo/modal.js +78 -0
  161. package/dist/McThemeConfig/demo/radio.d.ts +2 -0
  162. package/dist/McThemeConfig/demo/radio.js +97 -0
  163. package/dist/McThemeConfig/demo/switch.d.ts +2 -0
  164. package/dist/McThemeConfig/demo/switch.js +96 -0
  165. package/dist/McThemeConfig/demo/tabs.d.ts +2 -0
  166. package/dist/McThemeConfig/demo/tabs.js +35 -0
  167. package/dist/McThemeConfig/globalStyle.d.ts +2 -0
  168. package/dist/McThemeConfig/globalStyle.js +172 -0
  169. package/dist/McThemeConfig/index.d.ts +9 -0
  170. package/dist/McThemeConfig/index.js +16 -0
  171. package/dist/McThemeConfig/layoutStyle.d.ts +2 -0
  172. package/dist/McThemeConfig/layoutStyle.js +1 -0
  173. package/dist/McThemeConfig/provider.d.ts +7 -0
  174. package/dist/McThemeConfig/provider.js +19 -0
  175. package/dist/McThemeConfig/themeToken.json +149 -0
  176. package/dist/McTreePanel/SelectedItem.d.ts +4 -0
  177. package/dist/McTreePanel/SelectedItem.js +75 -0
  178. package/dist/McTreePanel/demo/base.d.ts +6 -0
  179. package/dist/McTreePanel/demo/base.js +45 -0
  180. package/dist/McTreePanel/demo/fieldNames.d.ts +6 -0
  181. package/dist/McTreePanel/demo/fieldNames.js +37 -0
  182. package/dist/McTreePanel/demo/inexistent.d.ts +6 -0
  183. package/dist/McTreePanel/demo/inexistent.js +56 -0
  184. package/dist/McTreePanel/demo/labelInValue.d.ts +6 -0
  185. package/dist/McTreePanel/demo/labelInValue.js +56 -0
  186. package/dist/McTreePanel/demo/sortable.d.ts +6 -0
  187. package/dist/McTreePanel/demo/sortable.js +34 -0
  188. package/dist/McTreePanel/index.css +110 -0
  189. package/dist/McTreePanel/index.d.ts +27 -0
  190. package/dist/McTreePanel/index.js +315 -0
  191. package/dist/McTreeSelect/demo/base.d.ts +5 -0
  192. package/dist/McTreeSelect/demo/base.js +58 -0
  193. package/dist/McTreeSelect/demo/inexistent.d.ts +5 -0
  194. package/dist/McTreeSelect/demo/inexistent.js +63 -0
  195. package/dist/McTreeSelect/demo/label.d.ts +5 -0
  196. package/dist/McTreeSelect/demo/label.js +60 -0
  197. package/dist/McTreeSelect/demo/multiple.d.ts +5 -0
  198. package/dist/McTreeSelect/demo/multiple.js +71 -0
  199. package/dist/McTreeSelect/index.css +60 -0
  200. package/dist/McTreeSelect/index.d.ts +13 -0
  201. package/dist/McTreeSelect/index.js +182 -0
  202. package/dist/Utils/index.d.ts +4 -0
  203. package/dist/Utils/index.js +26 -0
  204. package/dist/index.d.ts +19 -0
  205. package/dist/index.js +19 -0
  206. package/dist/typings.d.ts +20 -0
  207. 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,6 @@
1
+ /**
2
+ * title: 基础用法
3
+ * description: 通过 `value` 属性设置默认值,通过 `onChange` 事件获取当前值。
4
+ */
5
+ declare const _default: () => import("react/jsx-runtime").JSX.Element;
6
+ export default _default;
@@ -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,6 @@
1
+ /**
2
+ * title: 改变单位时间长度为半小时
3
+ * description: 通过设置half属性为true,可以使选择的时间段的单位长度变为半小时。
4
+ */
5
+ declare const _default: () => import("react/jsx-runtime").JSX.Element;
6
+ export default _default;
@@ -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
+ });