@4i/modal-manager 1.1.33 → 1.1.40
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/package.json
CHANGED
@@ -70,6 +70,17 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
70
70
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
71
71
|
}
|
72
72
|
};
|
73
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
74
|
+
var t = {};
|
75
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
76
|
+
t[p] = s[p];
|
77
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
78
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
79
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
80
|
+
t[p[i]] = s[p[i]];
|
81
|
+
}
|
82
|
+
return t;
|
83
|
+
};
|
73
84
|
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
74
85
|
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
75
86
|
if (ar || !(i in from)) {
|
@@ -127,7 +138,6 @@ var ModalProvider = function (_a) {
|
|
127
138
|
return __generator(this, function (_a) {
|
128
139
|
switch (_a.label) {
|
129
140
|
case 0:
|
130
|
-
console.log("handleClose", position);
|
131
141
|
if (!(position === "all")) return [3 /*break*/, 5];
|
132
142
|
i = modals.length - 1;
|
133
143
|
_a.label = 1;
|
@@ -188,14 +198,19 @@ var ModalProvider = function (_a) {
|
|
188
198
|
e.stopPropagation();
|
189
199
|
};
|
190
200
|
return (react_1.default.createElement(react_1.default.Fragment, null, modals.map(function (modalItem, index) {
|
191
|
-
var name = modalItem.name, payload = modalItem.payload, options = modalItem.options, id = modalItem.id;
|
201
|
+
var name = modalItem.name, payload = modalItem.payload, options = modalItem.options, id = modalItem.id, props = __rest(modalItem, ["name", "payload", "options", "id"]);
|
192
202
|
var Modal = modalList[name] || (function () { return react_1.default.createElement("div", null,
|
193
203
|
"Modal not found: ",
|
194
204
|
name); });
|
195
205
|
var hideBackdrop = (options === null || options === void 0 ? void 0 : options.hideBackdrop) || false;
|
196
206
|
var extraClass = (options === null || options === void 0 ? void 0 : options.extraClass) || "";
|
197
207
|
return (react_1.default.createElement("div", { key: id, "data-modal-id": id, "data-modal-index": index, className: "modal_container ".concat(extraClass) },
|
198
|
-
!hideBackdrop && (react_1.default.createElement("div", { onClick: function () {
|
208
|
+
!hideBackdrop && (react_1.default.createElement("div", { onClick: function () {
|
209
|
+
var _a;
|
210
|
+
(options === null || options === void 0 ? void 0 : options.onClickBackdrop)
|
211
|
+
? (_a = options === null || options === void 0 ? void 0 : options.onClickBackdrop) === null || _a === void 0 ? void 0 : _a.call(options, function () { return handleCloseModal(index); })
|
212
|
+
: handleCloseModal(index);
|
213
|
+
}, className: "modal_backdrop" })),
|
199
214
|
react_1.default.createElement("div", { className: "".concat(className, " modal_paper"), onClick: stopPropagation, ref: function (ref) { return saveModalRef(id, ref); } },
|
200
215
|
react_1.default.createElement(Modal, __assign({}, (payload.data || {}), { modalIndex: index })))));
|
201
216
|
})));
|
@@ -10,6 +10,7 @@ interface ModalProviderProps {
|
|
10
10
|
isOverflow?: boolean;
|
11
11
|
className?: string;
|
12
12
|
backdropClassName?: string;
|
13
|
+
onClickBackdrop?: (cb: any) => void;
|
13
14
|
onModalStateChange?: (
|
14
15
|
modalState: boolean,
|
15
16
|
data: ModalData[],
|
@@ -81,7 +82,6 @@ const ModalProvider: React.FC<ModalProviderProps> = ({
|
|
81
82
|
};
|
82
83
|
|
83
84
|
const handleClose = async (position: number | string) => {
|
84
|
-
console.log("handleClose", position);
|
85
85
|
if (position === "all") {
|
86
86
|
// Закрыть все модальные окна с анимацией
|
87
87
|
for (let i = modals.length - 1; i >= 0; i--) {
|
@@ -143,7 +143,7 @@ const ModalProvider: React.FC<ModalProviderProps> = ({
|
|
143
143
|
return (
|
144
144
|
<>
|
145
145
|
{modals.map((modalItem, index) => {
|
146
|
-
const { name, payload, options, id } = modalItem;
|
146
|
+
const { name, payload, options, id, ...props } = modalItem;
|
147
147
|
const Modal =
|
148
148
|
modalList[name] || (() => <div>Modal not found: {name}</div>);
|
149
149
|
const hideBackdrop = options?.hideBackdrop || false;
|
@@ -158,7 +158,11 @@ const ModalProvider: React.FC<ModalProviderProps> = ({
|
|
158
158
|
>
|
159
159
|
{!hideBackdrop && (
|
160
160
|
<div
|
161
|
-
onClick={() =>
|
161
|
+
onClick={() => {
|
162
|
+
options?.onClickBackdrop
|
163
|
+
? options?.onClickBackdrop?.(() => handleCloseModal(index))
|
164
|
+
: handleCloseModal(index);
|
165
|
+
}}
|
162
166
|
className="modal_backdrop"
|
163
167
|
/>
|
164
168
|
)}
|
@@ -32,7 +32,7 @@ var ModalManager = /** @class */ (function (_super) {
|
|
32
32
|
function ModalManager() {
|
33
33
|
var _this = _super.call(this) || this;
|
34
34
|
_this.queue = [];
|
35
|
-
_this.modalData = new Map();
|
35
|
+
_this.modalData = new Map();
|
36
36
|
_this.call = function (name, data, options) {
|
37
37
|
var modalId = uniqueID();
|
38
38
|
var id = _this.create(name, { modalId: modalId, data: data }, options);
|
@@ -26,11 +26,12 @@ export interface Options {
|
|
26
26
|
hideBackdrop?: boolean;
|
27
27
|
extraClass?: string;
|
28
28
|
openMinimized?: boolean;
|
29
|
+
onClickBackdrop?: (cb: () => void) => void;
|
29
30
|
}
|
30
31
|
|
31
32
|
export class ModalManager extends Manager {
|
32
33
|
queue: string[] = [];
|
33
|
-
modalData: Map<string, any> = new Map();
|
34
|
+
modalData: Map<string, any> = new Map();
|
34
35
|
_openModalStateCallback: null | ((props: ModalState) => void);
|
35
36
|
|
36
37
|
constructor() {
|