aio-popup 6.0.4 → 6.2.0
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/index.css +5 -5
- package/index.d.ts +145 -144
- package/index.js +802 -802
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -1,802 +1,802 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
11
|
-
import { createRef, useEffect, useState, createContext, useContext, useRef } from 'react';
|
|
12
|
-
import * as ReactDOMServer from 'react-dom/server';
|
|
13
|
-
import ReactDOM from 'react-dom';
|
|
14
|
-
import anime from "animejs/lib/anime.es.js";
|
|
15
|
-
import $ from 'jquery';
|
|
16
|
-
import './index.css';
|
|
17
|
-
const CTX = createContext({});
|
|
18
|
-
function Align(p) {
|
|
19
|
-
let { modal, target, fitHorizontal, rtl, limitTo } = p;
|
|
20
|
-
const bodyWidth = window.innerWidth, bodyHeight = window.innerHeight;
|
|
21
|
-
let pageLimit = { left: 0, top: 0, bottom: bodyHeight, right: bodyWidth, width: bodyWidth, height: bodyHeight };
|
|
22
|
-
let targetLimit = getBound(target[0]);
|
|
23
|
-
let domLimit = getBound(modal[0]);
|
|
24
|
-
targetLimit = Object.assign({}, targetLimit);
|
|
25
|
-
domLimit = Object.assign({}, domLimit);
|
|
26
|
-
let overflowY;
|
|
27
|
-
domLimit.top = targetLimit.bottom;
|
|
28
|
-
domLimit.bottom = domLimit.top + domLimit.height;
|
|
29
|
-
if (fitHorizontal) {
|
|
30
|
-
domLimit.width = targetLimit.width;
|
|
31
|
-
domLimit.left = targetLimit.left;
|
|
32
|
-
domLimit.right = targetLimit.left + targetLimit.width;
|
|
33
|
-
}
|
|
34
|
-
else {
|
|
35
|
-
if (limitTo) {
|
|
36
|
-
let elem = modal.parents(limitTo);
|
|
37
|
-
if (elem.length) {
|
|
38
|
-
pageLimit = getBound(elem[0]);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
//اگر راست به چپ باید باشد
|
|
42
|
-
if (rtl) {
|
|
43
|
-
//راست المان را با راست هدف ست کن
|
|
44
|
-
domLimit.right = targetLimit.right;
|
|
45
|
-
//چپ المان را بروز رسانی کن
|
|
46
|
-
domLimit.left = domLimit.right - domLimit.width;
|
|
47
|
-
//اگر المان از سمت چپ از صفحه بیرون زد سمت چپ المان را با سمت چپ صفحه ست کن
|
|
48
|
-
if (domLimit.left < pageLimit.left) {
|
|
49
|
-
domLimit.left = pageLimit.left;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
else {
|
|
53
|
-
//چپ المان را با چپ هدف ست کن
|
|
54
|
-
domLimit.left = targetLimit.left;
|
|
55
|
-
//راست المان را بروز رسانی کن
|
|
56
|
-
domLimit.right = domLimit.left + domLimit.width;
|
|
57
|
-
//اگر المان از سمت راست صفحه بیرون زد سمت چپ المان را با پهنای المان ست کن
|
|
58
|
-
if (domLimit.right > pageLimit.right) {
|
|
59
|
-
domLimit.left = pageLimit.right - domLimit.width;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
//اگر المان از سمت پایین صفحه بیرون زد
|
|
64
|
-
if (domLimit.bottom > pageLimit.bottom) {
|
|
65
|
-
if (domLimit.height > targetLimit.top - pageLimit.top) {
|
|
66
|
-
domLimit.top = pageLimit.bottom - domLimit.height;
|
|
67
|
-
}
|
|
68
|
-
else {
|
|
69
|
-
domLimit.top = targetLimit.top - domLimit.height;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
else {
|
|
73
|
-
domLimit.top = targetLimit.bottom;
|
|
74
|
-
}
|
|
75
|
-
if (domLimit.height > pageLimit.height) {
|
|
76
|
-
domLimit.top = pageLimit.top;
|
|
77
|
-
domLimit.height = pageLimit.height;
|
|
78
|
-
overflowY = 'auto';
|
|
79
|
-
}
|
|
80
|
-
return { left: domLimit.left, top: domLimit.top, width: domLimit.width, overflowY, maxWidth: pageLimit.width };
|
|
81
|
-
}
|
|
82
|
-
const CloseIcon = () => {
|
|
83
|
-
return (_jsx("svg", { viewBox: "0 0 24 24", role: "presentation", style: { width: '1.2rem', height: '1.2rem' }, children: _jsx("path", { d: "M19,6.41L17.59,5L12,10.59L6.41,5L5,6.41L10.59,12L5,17.59L6.41,19L12,13.41L17.59,19L19,17.59L13.41,12L19,6.41Z", style: { fill: 'currentcolor' } }) }));
|
|
84
|
-
};
|
|
85
|
-
function AddToAttrs(attrs, p) {
|
|
86
|
-
attrs = attrs || {};
|
|
87
|
-
let { style } = p;
|
|
88
|
-
let attrClassName = attrs.className ? attrs.className.split(' ') : [];
|
|
89
|
-
let className = p.className ? (Array.isArray(p.className) ? p.className : p.className.split(' ')) : [];
|
|
90
|
-
let classNames = [...attrClassName, ...className.filter((o) => !!o)];
|
|
91
|
-
let newClassName = classNames.length ? classNames.join(' ') : undefined;
|
|
92
|
-
let newStyle = Object.assign(Object.assign({}, attrs.style), style);
|
|
93
|
-
return Object.assign(Object.assign(Object.assign({}, attrs), { className: newClassName, style: newStyle }), p.attrs);
|
|
94
|
-
}
|
|
95
|
-
const usePopup = (props) => {
|
|
96
|
-
let [modals, setModals] = useState([]);
|
|
97
|
-
const promptTexts = useRef({});
|
|
98
|
-
let modalsRef = useRef(modals);
|
|
99
|
-
modalsRef.current = modals;
|
|
100
|
-
const getModals = () => modalsRef.current;
|
|
101
|
-
const [snackebarItems, setSnackebarItems] = useState([]);
|
|
102
|
-
const snackebarItemsRef = useRef(snackebarItems);
|
|
103
|
-
snackebarItemsRef.current = snackebarItems;
|
|
104
|
-
const [highlight, setHighlight] = useState();
|
|
105
|
-
const addModal = (o) => {
|
|
106
|
-
if (o.id === undefined) {
|
|
107
|
-
o.id = 'popup' + Math.round(Math.random() * 1000000);
|
|
108
|
-
}
|
|
109
|
-
let newModal = o;
|
|
110
|
-
setModals(prevModals => {
|
|
111
|
-
let newModals = prevModals.filter(({ id }) => id !== o.id);
|
|
112
|
-
return [...newModals, newModal];
|
|
113
|
-
});
|
|
114
|
-
};
|
|
115
|
-
const removeModal = (arg) => __awaiter(void 0, void 0, void 0, function* () {
|
|
116
|
-
if (typeof arg !== 'string') {
|
|
117
|
-
arg = 'last';
|
|
118
|
-
}
|
|
119
|
-
if (arg === 'all') {
|
|
120
|
-
setModals([]);
|
|
121
|
-
return;
|
|
122
|
-
}
|
|
123
|
-
if (!modalsRef.current.length) {
|
|
124
|
-
return;
|
|
125
|
-
}
|
|
126
|
-
if (arg === 'last') {
|
|
127
|
-
arg = modalsRef.current[modalsRef.current.length - 1].id;
|
|
128
|
-
}
|
|
129
|
-
let modal = modalsRef.current.find((o) => o.id === arg);
|
|
130
|
-
if (!modal) {
|
|
131
|
-
return;
|
|
132
|
-
}
|
|
133
|
-
$(`[data-id=${arg}]`).addClass('not-mounted');
|
|
134
|
-
setTimeout(() => {
|
|
135
|
-
if (modal && typeof modal.onClose === 'function') {
|
|
136
|
-
modal.onClose();
|
|
137
|
-
}
|
|
138
|
-
setModals(prevModals => prevModals.filter((o) => o.id !== arg));
|
|
139
|
-
}, 300);
|
|
140
|
-
});
|
|
141
|
-
const addSnackebar = (item) => {
|
|
142
|
-
let items = snackebarItemsRef.current;
|
|
143
|
-
let newItems = [...items, Object.assign(Object.assign({}, item), { id: 'a' + Math.round(Math.random() * 1000000000) })];
|
|
144
|
-
setSnackebarItems(newItems);
|
|
145
|
-
};
|
|
146
|
-
const removeSnackebar = (id) => {
|
|
147
|
-
const items = snackebarItemsRef.current;
|
|
148
|
-
const item = items.find((o) => o.id === id);
|
|
149
|
-
if (!item || item.onClose === false) {
|
|
150
|
-
return;
|
|
151
|
-
}
|
|
152
|
-
let newItems = items.filter((o, i) => o.id !== id);
|
|
153
|
-
setSnackebarItems(newItems);
|
|
154
|
-
if (typeof item.onClose === 'function') {
|
|
155
|
-
item.onClose();
|
|
156
|
-
}
|
|
157
|
-
};
|
|
158
|
-
const addAlert = (obj) => Alert(Object.assign({ rtl: props === null || props === void 0 ? void 0 : props.rtl }, obj));
|
|
159
|
-
const addHighlight = (highlight) => setHighlight(highlight);
|
|
160
|
-
const removeHighlight = () => setHighlight(undefined);
|
|
161
|
-
const addConfirm = (obj) => {
|
|
162
|
-
let { title, subtitle, submitText = 'Yes', canselText = 'No', onSubmit, onCansel = () => { }, setAttrs = () => { return {}; } } = obj;
|
|
163
|
-
let config = {
|
|
164
|
-
position: 'center',
|
|
165
|
-
setAttrs: (key) => {
|
|
166
|
-
let attrs = setAttrs(key);
|
|
167
|
-
if (key === 'modal') {
|
|
168
|
-
return AddToAttrs(attrs, { className: 'aio-popup-confirm' });
|
|
169
|
-
}
|
|
170
|
-
return attrs;
|
|
171
|
-
},
|
|
172
|
-
header: { title, subtitle },
|
|
173
|
-
body: _jsx(_Fragment, { children:
|
|
174
|
-
footer: (_jsxs(_Fragment, { children: [_jsx("button", { type: 'button', onClick: () => { onCansel(); removeModal(); }, children: canselText }), _jsx("button", { type: 'button', className: 'active', onClick: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
175
|
-
if (!onSubmit) {
|
|
176
|
-
return;
|
|
177
|
-
}
|
|
178
|
-
let res = yield onSubmit();
|
|
179
|
-
if (res !== false) {
|
|
180
|
-
removeModal();
|
|
181
|
-
}
|
|
182
|
-
}), children: submitText })] }))
|
|
183
|
-
};
|
|
184
|
-
addModal(config);
|
|
185
|
-
};
|
|
186
|
-
const addPrompt = (obj) => {
|
|
187
|
-
const id = 'a' + (Math.round(Math.random() * 100000));
|
|
188
|
-
let { title, subtitle, submitText = 'Submit', canselText = 'close', onSubmit, onCansel = () => { }, setAttrs = () => { return {}; } } = obj;
|
|
189
|
-
let config = {
|
|
190
|
-
position: 'center',
|
|
191
|
-
setAttrs: (key) => {
|
|
192
|
-
let attrs = setAttrs(key);
|
|
193
|
-
if (key === 'modal') {
|
|
194
|
-
return AddToAttrs(attrs, { className: 'aio-popup-prompt' });
|
|
195
|
-
}
|
|
196
|
-
return attrs;
|
|
197
|
-
},
|
|
198
|
-
header: { title, subtitle },
|
|
199
|
-
body: _jsx(Prompt, { change: (value) => promptTexts.current = Object.assign(Object.assign({}, promptTexts.current), { [id]: value }) }),
|
|
200
|
-
footer: (_jsxs(_Fragment, { children: [_jsx("button", { type: 'button', onClick: () => { onCansel(); removeModal(); }, children: canselText }), _jsx("button", { type: 'button', className: 'active', onClick: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
201
|
-
if (!onSubmit) {
|
|
202
|
-
return;
|
|
203
|
-
}
|
|
204
|
-
const value = promptTexts.current[id];
|
|
205
|
-
let res = yield onSubmit(value);
|
|
206
|
-
if (res !== false) {
|
|
207
|
-
removeModal();
|
|
208
|
-
}
|
|
209
|
-
else {
|
|
210
|
-
const newPromptTexts = {};
|
|
211
|
-
for (let prop in promptTexts.current) {
|
|
212
|
-
if (prop !== id) {
|
|
213
|
-
newPromptTexts[prop] = promptTexts.current[prop];
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
promptTexts.current = newPromptTexts;
|
|
217
|
-
}
|
|
218
|
-
}), children: submitText })] }))
|
|
219
|
-
};
|
|
220
|
-
addModal(config);
|
|
221
|
-
};
|
|
222
|
-
const getContext = () => {
|
|
223
|
-
return {
|
|
224
|
-
rtl: !!props && !!props.rtl,
|
|
225
|
-
snackebarItems: snackebarItemsRef.current,
|
|
226
|
-
removeSnackebar, removeModal
|
|
227
|
-
};
|
|
228
|
-
};
|
|
229
|
-
const render = (caller) => {
|
|
230
|
-
return (_jsxs(CTX.Provider, { value: getContext(), children: [modalsRef.current.map((modal, i) => {
|
|
231
|
-
return (_jsx(Popup, { modal: modal, isLast: i === modalsRef.current.length - 1, renderCaller: caller }, modal.id));
|
|
232
|
-
}), snackebarItems.map((item, i) => _jsx(SnackebarItem, { item: item, index: i }, item.id)), !!highlight && _jsx(Highlight, { highlight: highlight })] }));
|
|
233
|
-
};
|
|
234
|
-
const portal = () => ReactDOM.createPortal(render(), document.body);
|
|
235
|
-
return { addAlert, addSnackebar, removeModal, addModal, getModals, addHighlight, removeHighlight, render, addConfirm, addPrompt, portal };
|
|
236
|
-
};
|
|
237
|
-
export default usePopup;
|
|
238
|
-
const Prompt = ({ change }) => {
|
|
239
|
-
const [text, setText] = useState('');
|
|
240
|
-
return (_jsx("textarea", { placeholder: text, value: text, onChange: (e) => { const value = e.target.value; setText(value); change(value); } }));
|
|
241
|
-
};
|
|
242
|
-
const POPUPCTX = createContext({});
|
|
243
|
-
const Popup = ({ modal, isLast, renderCaller }) => {
|
|
244
|
-
const mainContext = useContext(CTX);
|
|
245
|
-
let { setAttrs = () => { return {}; }, id, position = 'fullscreen', getTarget } = modal;
|
|
246
|
-
let [temp] = useState({ dom: createRef(), backdropDom: createRef(), dui: undefined });
|
|
247
|
-
let [popoverStyle, setPopoverStyle] = useState({});
|
|
248
|
-
let modalMouseDown = useRef(false);
|
|
249
|
-
//bar taraf kardane moshkele mozakhrafe click rooye backdrop ke az har ja mouse ro roosh vel mikoni modal baste mishe
|
|
250
|
-
const isModalMouseDown = () => modalMouseDown.current;
|
|
251
|
-
let [state, setState] = useState(modal.state);
|
|
252
|
-
let attrs = setAttrs('modal') || {};
|
|
253
|
-
const firstMount = useRef(false);
|
|
254
|
-
useEffect(() => () => { $(window).unbind('click', handleBackClick); });
|
|
255
|
-
useEffect(() => {
|
|
256
|
-
if (position === 'popover') {
|
|
257
|
-
setPopoverStyle(getPopoverStyle());
|
|
258
|
-
}
|
|
259
|
-
if (getTarget) {
|
|
260
|
-
temp.dui = 'a' + (Math.round(Math.random() * 10000000));
|
|
261
|
-
let target = getTarget();
|
|
262
|
-
target.attr('data-id', temp.dui);
|
|
263
|
-
}
|
|
264
|
-
setTimeout(() => {
|
|
265
|
-
let popup = $(temp.dom.current);
|
|
266
|
-
popup.removeClass('not-mounted');
|
|
267
|
-
$(temp.backdropDom.current).removeClass('not-mounted');
|
|
268
|
-
popup.focus();
|
|
269
|
-
}, 0);
|
|
270
|
-
$(window).unbind('click', handleBackClick);
|
|
271
|
-
$(window).bind('click', handleBackClick);
|
|
272
|
-
}, []);
|
|
273
|
-
function handleBackClick(e) {
|
|
274
|
-
//در مود پاپاور اگر هر جایی غیر از اینپوت و پاپاور کلیک شد پاپاپ رو ببند
|
|
275
|
-
if (!temp.dui) {
|
|
276
|
-
return;
|
|
277
|
-
}
|
|
278
|
-
let target = $(e.target);
|
|
279
|
-
if (position !== 'popover' || target.attr('data-id') === temp.dui || target.parents(`[data-id=${temp.dui}]`).length) {
|
|
280
|
-
return;
|
|
281
|
-
}
|
|
282
|
-
mainContext.removeModal();
|
|
283
|
-
}
|
|
284
|
-
function getModalProps() {
|
|
285
|
-
let style = Object.assign(Object.assign({}, popoverStyle), attrs.style);
|
|
286
|
-
let ev = "ontouchstart" in document.documentElement ? 'onTouchStart' : 'onMouseDown';
|
|
287
|
-
return Object.assign(Object.assign({}, attrs), { ref: temp.dom, "data-id": modal.id, tabIndex: 0, onKeyDown, [ev]: mouseDown, className: getClassName(), style: Object.assign({}, style), onClick: (e) => { e.stopPropagation(); } });
|
|
288
|
-
}
|
|
289
|
-
function getPopoverStyle() {
|
|
290
|
-
if (!getTarget) {
|
|
291
|
-
return {};
|
|
292
|
-
}
|
|
293
|
-
let target = getTarget();
|
|
294
|
-
if (!target || !target.length) {
|
|
295
|
-
return {};
|
|
296
|
-
}
|
|
297
|
-
let p = { modal: $(temp.dom.current), target, fitHorizontal: modal.fitHorizontal, limitTo: modal.limitTo, attrs, rtl: mainContext.rtl };
|
|
298
|
-
let style = Align(p);
|
|
299
|
-
let res = Object.assign(Object.assign({}, style), { position: 'absolute' });
|
|
300
|
-
return res;
|
|
301
|
-
}
|
|
302
|
-
function onKeyDown(e) {
|
|
303
|
-
if (!isLast) {
|
|
304
|
-
return;
|
|
305
|
-
}
|
|
306
|
-
let code = e.keyCode;
|
|
307
|
-
if (code === 27) {
|
|
308
|
-
mainContext.removeModal();
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
function mouseUp() {
|
|
312
|
-
setTimeout(() => modalMouseDown.current = false, 0);
|
|
313
|
-
}
|
|
314
|
-
function mouseDown(e) {
|
|
315
|
-
modalMouseDown.current = true;
|
|
316
|
-
$(window).unbind('mouseup', mouseUp);
|
|
317
|
-
$(window).bind('mouseup', mouseUp);
|
|
318
|
-
}
|
|
319
|
-
function getClassName() {
|
|
320
|
-
let className = 'aio-popup';
|
|
321
|
-
className += mainContext.rtl ? ' rtl' : ' ltr';
|
|
322
|
-
if (firstMount) {
|
|
323
|
-
className += ' not-mounted';
|
|
324
|
-
}
|
|
325
|
-
if (attrs.className) {
|
|
326
|
-
className += ' ' + attrs.className;
|
|
327
|
-
}
|
|
328
|
-
return className;
|
|
329
|
-
}
|
|
330
|
-
const getContext = () => ({ modal, isLast, state, setState, onKeyDown });
|
|
331
|
-
return (_jsx(POPUPCTX.Provider, { value: getContext(), children: _jsx(ModalBackdrop, { firstMount: !!firstMount, backdropDom: temp.backdropDom, isModalMouseDown: isModalMouseDown, children: _jsxs("div", Object.assign({}, getModalProps(), { children: [_jsx(ModalHeader, {}), _jsx(ModalBody, {}, modal.id), _jsx(ModalFooter, {})] }), modal.id) }, modal.id) }));
|
|
332
|
-
};
|
|
333
|
-
const ModalBackdrop = ({ children, firstMount, backdropDom, isModalMouseDown }) => {
|
|
334
|
-
const { removeModal, rtl } = useContext(CTX);
|
|
335
|
-
let { modal, onKeyDown } = useContext(POPUPCTX);
|
|
336
|
-
let { setAttrs = () => { return {}; }, id, position = 'fullscreen' } = modal;
|
|
337
|
-
const [attrs] = useState(setAttrs('backdrop') || {});
|
|
338
|
-
function backClick(e) {
|
|
339
|
-
if (isModalMouseDown()) {
|
|
340
|
-
return;
|
|
341
|
-
}
|
|
342
|
-
if (e.target !== e.currentTarget) {
|
|
343
|
-
return;
|
|
344
|
-
}
|
|
345
|
-
let target = $(e.target);
|
|
346
|
-
if (!target.hasClass('aio-popup-backdrop')) {
|
|
347
|
-
return;
|
|
348
|
-
}
|
|
349
|
-
removeModal();
|
|
350
|
-
}
|
|
351
|
-
function getProps() {
|
|
352
|
-
let className = 'aio-popup-backdrop';
|
|
353
|
-
className += ` aio-popup-position-${position}`;
|
|
354
|
-
className += rtl ? ' rtl' : ' ltr';
|
|
355
|
-
if (firstMount) {
|
|
356
|
-
className += ' not-mounted';
|
|
357
|
-
}
|
|
358
|
-
return AddToAttrs(attrs, { className, attrs: { ref: backdropDom, onKeyDown, tabIndex: 0, ['data-id']: id, onClick: attrs.onClick ? attrs.onClick : backClick } });
|
|
359
|
-
}
|
|
360
|
-
return _jsx("div", Object.assign({}, getProps(), { children: children }));
|
|
361
|
-
};
|
|
362
|
-
const ModalHeader = () => {
|
|
363
|
-
const { removeModal } = useContext(CTX);
|
|
364
|
-
let { modal, state, setState } = useContext(POPUPCTX);
|
|
365
|
-
if (!modal.header) {
|
|
366
|
-
return null;
|
|
367
|
-
}
|
|
368
|
-
let { setAttrs = () => { return {}; } } = modal;
|
|
369
|
-
let attrs = setAttrs('header') || {};
|
|
370
|
-
if (typeof modal.header === 'function') {
|
|
371
|
-
return modal.header({ removeModal: removeModal, state, setState });
|
|
372
|
-
}
|
|
373
|
-
if (typeof modal.header !== 'object') {
|
|
374
|
-
return null;
|
|
375
|
-
}
|
|
376
|
-
return (_jsxs("div", Object.assign({}, AddToAttrs(attrs, { className: 'aio-popup-header' }), { children: [_jsx(ModalHeaderElement, { type: 'before' }, 'before'), _jsx(ModalHeaderElement, { type: 'title' }, 'title'), _jsx(ModalHeaderElement, { type: 'after' }, 'after'), _jsx(ModalClose, {})] })));
|
|
377
|
-
};
|
|
378
|
-
const ModalHeaderElement = ({ type }) => {
|
|
379
|
-
let { modal } = useContext(POPUPCTX), { header } = modal;
|
|
380
|
-
if (typeof header === 'function' || !header) {
|
|
381
|
-
return null;
|
|
382
|
-
}
|
|
383
|
-
if (!header[type]) {
|
|
384
|
-
return null;
|
|
385
|
-
}
|
|
386
|
-
return _jsx("div", { className: `aio-popup-header-${type}`, "data-subtitle": type === 'title' ? header.subtitle : undefined, children: header[type] });
|
|
387
|
-
};
|
|
388
|
-
const ModalClose = () => {
|
|
389
|
-
const { removeModal } = useContext(CTX);
|
|
390
|
-
let { modal, state, setState } = useContext(POPUPCTX), { header } = modal;
|
|
391
|
-
if (typeof header === 'function' || !header) {
|
|
392
|
-
return null;
|
|
393
|
-
}
|
|
394
|
-
if (header.onClose === false) {
|
|
395
|
-
return null;
|
|
396
|
-
}
|
|
397
|
-
return _jsx("div", { className: `aio-popup-header-close`, onClick: (e) => {
|
|
398
|
-
e.stopPropagation();
|
|
399
|
-
e.preventDefault();
|
|
400
|
-
if (typeof header.onClose === 'function') {
|
|
401
|
-
header.onClose({ state, setState });
|
|
402
|
-
}
|
|
403
|
-
else {
|
|
404
|
-
removeModal(modal.id);
|
|
405
|
-
}
|
|
406
|
-
}, children: _jsx(CloseIcon, {}) });
|
|
407
|
-
};
|
|
408
|
-
const ModalBody = () => {
|
|
409
|
-
const { modal } = useContext(POPUPCTX);
|
|
410
|
-
let { body, setAttrs = () => { return {}; } } = modal;
|
|
411
|
-
let attrs = setAttrs('body') || {};
|
|
412
|
-
if (!body || body === null) {
|
|
413
|
-
return null;
|
|
414
|
-
}
|
|
415
|
-
return (_jsx("div", Object.assign({}, AddToAttrs(attrs, { className: 'aio-popup-body aio-popup-scroll' }), { children: body })));
|
|
416
|
-
};
|
|
417
|
-
const ModalFooter = () => {
|
|
418
|
-
const { modal } = useContext(POPUPCTX);
|
|
419
|
-
let { setAttrs = () => { return {}; }, footer } = modal;
|
|
420
|
-
if (!footer) {
|
|
421
|
-
return null;
|
|
422
|
-
}
|
|
423
|
-
let Attrs = setAttrs('footer') || {};
|
|
424
|
-
const attrs = AddToAttrs(Attrs, { className: 'aio-popup-footer' });
|
|
425
|
-
return _jsx("div", Object.assign({}, attrs, { children: footer }));
|
|
426
|
-
};
|
|
427
|
-
const SBCTX = createContext({});
|
|
428
|
-
const SnackebarItem = (props) => {
|
|
429
|
-
const mainContext = useContext(CTX);
|
|
430
|
-
let { item } = props;
|
|
431
|
-
let { time = 8, id, align = ['right', 'top'] } = item;
|
|
432
|
-
if (align[1] !== 'top' && align[1] !== 'bottom') {
|
|
433
|
-
align[1] = 'top';
|
|
434
|
-
}
|
|
435
|
-
if (align[0] !== 'left' && align[0] !== 'right' && align[0] !== 'center') {
|
|
436
|
-
align[0] = 'right';
|
|
437
|
-
}
|
|
438
|
-
let [mounted, setMounted] = useState(false);
|
|
439
|
-
useEffect(() => {
|
|
440
|
-
setTimeout(() => setMounted(true), 0);
|
|
441
|
-
setTimeout(() => remove(), time * 1000);
|
|
442
|
-
}, []);
|
|
443
|
-
function remove() {
|
|
444
|
-
setMounted(false);
|
|
445
|
-
setTimeout(() => mainContext.removeSnackebar(id), 200);
|
|
446
|
-
}
|
|
447
|
-
const getSvg = (type) => { return type === 'error' || type === 'warning' || type === 'info' ? _jsx(InfoSvg, {}) : _jsx(SuccessSvg, {}); };
|
|
448
|
-
const getContext = () => {
|
|
449
|
-
return { mainContext, remove, item: Object.assign(Object.assign({}, props.item), { time, align }), index: props.index, mounted, getSvg };
|
|
450
|
-
};
|
|
451
|
-
return (_jsx(SBCTX.Provider, { value: getContext(), children: _jsx(SnackebarContainer, {}) }));
|
|
452
|
-
};
|
|
453
|
-
const SnackebarContainer = () => {
|
|
454
|
-
const { mainContext, mounted, index, item, remove } = useContext(SBCTX);
|
|
455
|
-
const { rtl } = mainContext;
|
|
456
|
-
let { onClose, align = ['right', 'top'] } = item;
|
|
457
|
-
function getOffsetStyle(index) {
|
|
458
|
-
let els = $('.aio-popup-snackebar-item-container'), sum = { top: 12, bottom: 12 };
|
|
459
|
-
for (let i = 0; i < index; i++) {
|
|
460
|
-
let dom = els.eq(i);
|
|
461
|
-
let height = dom.height() + 6;
|
|
462
|
-
let va = dom.attr('data-vertical-align');
|
|
463
|
-
sum[va] += height;
|
|
464
|
-
}
|
|
465
|
-
return {
|
|
466
|
-
[align[1] === 'top' ? 'top' : 'bottom']: sum[align[1]]
|
|
467
|
-
};
|
|
468
|
-
}
|
|
469
|
-
let className = 'aio-popup-snackebar-item-container';
|
|
470
|
-
className += ` aio-popup-snackebar-item-container-horizontal-align-${align[0]}`;
|
|
471
|
-
if (mounted) {
|
|
472
|
-
className += ' mounted';
|
|
473
|
-
}
|
|
474
|
-
if (rtl) {
|
|
475
|
-
className += ' rtl';
|
|
476
|
-
}
|
|
477
|
-
let style = getOffsetStyle(index);
|
|
478
|
-
let p = { 'data-vertical-align': align[1], className, style, onClick: onClose === false ? undefined : () => remove() };
|
|
479
|
-
return _jsx("div", Object.assign({}, p, { children: _jsx(SnackebarCard, {}) }));
|
|
480
|
-
};
|
|
481
|
-
const SnackebarCard = () => {
|
|
482
|
-
const { item } = useContext(SBCTX);
|
|
483
|
-
let { type, attrs = {} } = item;
|
|
484
|
-
let className = 'aio-popup-snackebar-item';
|
|
485
|
-
className += ` aio-popup-snackebar-item-${type}`;
|
|
486
|
-
if (attrs.className) {
|
|
487
|
-
className += ` ${attrs.className}`;
|
|
488
|
-
}
|
|
489
|
-
let p = Object.assign(Object.assign({}, attrs), { className, style: attrs.style });
|
|
490
|
-
return (_jsxs("div", Object.assign({}, p, { children: [_jsx(SnackebarIcon, {}), _jsx(SnackebarText, {}), _jsx(SnackebarAction, {}), _jsx(SnackebarBar, {})] })));
|
|
491
|
-
};
|
|
492
|
-
const SnackebarIcon = () => {
|
|
493
|
-
const { getSvg, item } = useContext(SBCTX);
|
|
494
|
-
return _jsx("div", { className: `aio-popup-snackebar-item-icon`, children: !!item.icon ? item.icon : getSvg(item.type) });
|
|
495
|
-
};
|
|
496
|
-
const SnackebarText = () => {
|
|
497
|
-
const { item } = useContext(SBCTX);
|
|
498
|
-
return (_jsxs("div", { className: 'aio-popup-snackebar-item-text', children: [_jsx("div", { className: 'aio-popup-snackebar-item-uptext', children: item.text }), !!item.subtext && _jsx("div", { className: 'aio-popup-snackebar-item-subtext', children: item.subtext })] }));
|
|
499
|
-
};
|
|
500
|
-
const SnackebarAction = () => {
|
|
501
|
-
const { item, remove } = useContext(SBCTX);
|
|
502
|
-
const { action } = item;
|
|
503
|
-
if (!action || !action.text) {
|
|
504
|
-
return null;
|
|
505
|
-
}
|
|
506
|
-
let p = {
|
|
507
|
-
className: 'aio-popup-snackebar-item-action',
|
|
508
|
-
onClick: (e) => { e.stopPropagation(); if (action) {
|
|
509
|
-
action.onClick();
|
|
510
|
-
} remove(); }
|
|
511
|
-
};
|
|
512
|
-
return (_jsx("button", Object.assign({}, p, { children: action.text })));
|
|
513
|
-
};
|
|
514
|
-
const SnackebarBar = () => {
|
|
515
|
-
const { item } = useContext(SBCTX);
|
|
516
|
-
return _jsx("div", { className: 'aio-popup-snackebar-bar', style: { transition: `${item.time || 8}s linear` } });
|
|
517
|
-
};
|
|
518
|
-
export function Alert(props) {
|
|
519
|
-
let { icon, type = '', title = '', text = '', time = 10, className, closeText = 'Close', onClose, rtl } = props;
|
|
520
|
-
let $$ = {
|
|
521
|
-
id: '',
|
|
522
|
-
time: 0,
|
|
523
|
-
getId() {
|
|
524
|
-
return 'aa' + Math.round((Math.random() * 100000000));
|
|
525
|
-
},
|
|
526
|
-
getBarRender() {
|
|
527
|
-
return `<div class='aio-popup-time-bar' style="width:${$$.time}%;"></div>`;
|
|
528
|
-
},
|
|
529
|
-
updateBarRender() {
|
|
530
|
-
$(`.aio-popup-alert-container.${$$.id} .aio-popup-time`).html($$.getBarRender());
|
|
531
|
-
},
|
|
532
|
-
getRender() {
|
|
533
|
-
return (`
|
|
534
|
-
<div class='aio-popup-alert-container not-mounted ${$$.id} aio-popup-alert-container-center${!!className ? ` ${className}` : ''}'>
|
|
535
|
-
<div class='aio-popup-alert aio-popup-alert-${type}'>
|
|
536
|
-
<div class='aio-popup-alert-header'>${$$.getIcon()}</div>
|
|
537
|
-
<div class='aio-popup-alert-body aio-popup-scroll'>
|
|
538
|
-
<div class='aio-popup-alert-title'>${ReactDOMServer.renderToStaticMarkup(title)}</div>
|
|
539
|
-
<div class='aio-popup-alert-text' style="text-align:${rtl ? 'right' : 'left'}">${text}</div>
|
|
540
|
-
</div>
|
|
541
|
-
<div class='aio-popup-alert-footer'>
|
|
542
|
-
<button class='aio-popup-alert-close ${$$.id}'>${closeText}</button>
|
|
543
|
-
</div>
|
|
544
|
-
<div class='aio-popup-time'></div>
|
|
545
|
-
</div>
|
|
546
|
-
</div>
|
|
547
|
-
`);
|
|
548
|
-
},
|
|
549
|
-
close() {
|
|
550
|
-
$$.toggleClass(false);
|
|
551
|
-
setTimeout(() => {
|
|
552
|
-
if (typeof onClose === 'function') {
|
|
553
|
-
onClose();
|
|
554
|
-
}
|
|
555
|
-
if (onClose === false) {
|
|
556
|
-
return;
|
|
557
|
-
}
|
|
558
|
-
$('.' + $$.id).remove();
|
|
559
|
-
}, 200);
|
|
560
|
-
},
|
|
561
|
-
getIcon() {
|
|
562
|
-
if (icon === false) {
|
|
563
|
-
return '';
|
|
564
|
-
}
|
|
565
|
-
return icon || {
|
|
566
|
-
error: (`<svg viewBox="0 0 24 24" role="presentation" style="width: 4.5rem; height: 4.5rem;"><path d="M19,6.41L17.59,5L12,10.59L6.41,5L5,6.41L10.59,12L5,17.59L6.41,19L12,13.41L17.59,19L19,17.59L13.41,12L19,6.41Z"></path></svg>`),
|
|
567
|
-
warning: (`<svg viewBox="0 0 24 24" role="presentation" style="width: 4.5rem; height: 4.5rem;"><path d="M12,2L1,21H23M12,6L19.53,19H4.47M11,10V14H13V10M11,16V18H13V16"></path></svg>`),
|
|
568
|
-
info: (`<svg viewBox="0 0 24 24" role="presentation" style="width: 4.5rem; height: 4.5rem;"><path d="M11,9H13V7H11M12,20C7.59,20 4,16.41 4,12C4,7.59 7.59,4 12,4C16.41,4 20,7.59 20,12C20,16.41 16.41,20 12,20M12,2A10,10 0 0,0 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12A10,10 0 0,0 12,2M11,17H13V11H11V17Z"></path></svg>`),
|
|
569
|
-
success: (`<svg viewBox="0 0 24 24" role="presentation" style="width: 4.5rem; height: 4.5rem;"><path d="M12 2C6.5 2 2 6.5 2 12S6.5 22 12 22 22 17.5 22 12 17.5 2 12 2M12 20C7.59 20 4 16.41 4 12S7.59 4 12 4 20 7.59 20 12 16.41 20 12 20M16.59 7.58L10 14.17L7.41 11.59L6 13L10 17L18 9L16.59 7.58Z"></path></svg>`)
|
|
570
|
-
}[type] || '';
|
|
571
|
-
},
|
|
572
|
-
startTimer() {
|
|
573
|
-
setTimeout(() => {
|
|
574
|
-
if ($$.time >= 100) {
|
|
575
|
-
$$.time = 100;
|
|
576
|
-
$$.close();
|
|
577
|
-
return;
|
|
578
|
-
}
|
|
579
|
-
$$.time += 2;
|
|
580
|
-
$$.updateBarRender();
|
|
581
|
-
$$.startTimer();
|
|
582
|
-
}, time / 50 * 1000);
|
|
583
|
-
},
|
|
584
|
-
toggleClass(mount) {
|
|
585
|
-
let dom = $(`.${$$.id}`);
|
|
586
|
-
if (mount) {
|
|
587
|
-
setTimeout(() => dom.removeClass('not-mounted'), 0);
|
|
588
|
-
}
|
|
589
|
-
else {
|
|
590
|
-
dom.addClass('not-mounted');
|
|
591
|
-
}
|
|
592
|
-
},
|
|
593
|
-
render() {
|
|
594
|
-
$('body').append($$.getRender());
|
|
595
|
-
$('button.' + $$.id).off('click', $$.close);
|
|
596
|
-
$('button.' + $$.id).on('click', $$.close);
|
|
597
|
-
$$.toggleClass(true);
|
|
598
|
-
}
|
|
599
|
-
};
|
|
600
|
-
$$.id = $$.getId();
|
|
601
|
-
$$.render();
|
|
602
|
-
if (time) {
|
|
603
|
-
$$.startTimer();
|
|
604
|
-
}
|
|
605
|
-
}
|
|
606
|
-
const Highlight = ({ highlight }) => {
|
|
607
|
-
const [limit, setLimit] = useState({ Left: 0, Top: 0, Width: 0, Height: 0, TopSpace: 0, BottomSpace: 0 });
|
|
608
|
-
const limitRef = useRef(limit);
|
|
609
|
-
limitRef.current = limit;
|
|
610
|
-
useEffect(() => {
|
|
611
|
-
setTimeout(() => {
|
|
612
|
-
try {
|
|
613
|
-
const { dom, duration = 1200 } = highlight;
|
|
614
|
-
dom[0].scrollIntoView();
|
|
615
|
-
let newLimit = getHLLimit(highlight);
|
|
616
|
-
let easing = getEasing(highlight);
|
|
617
|
-
let obj = Object.assign(Object.assign({}, newLimit), { targets: [Object.assign({}, limitRef.current)], duration, update: (p) => {
|
|
618
|
-
const { animatables } = p;
|
|
619
|
-
setLimit(Object.assign({}, animatables[0].target));
|
|
620
|
-
} });
|
|
621
|
-
if (easing) {
|
|
622
|
-
obj.easing = easing;
|
|
623
|
-
}
|
|
624
|
-
anime(obj);
|
|
625
|
-
}
|
|
626
|
-
catch (_a) {
|
|
627
|
-
alert(`aio-highlighter error => connot find dom`);
|
|
628
|
-
}
|
|
629
|
-
}, 0);
|
|
630
|
-
});
|
|
631
|
-
function getArrowIcon(props) {
|
|
632
|
-
return (_jsx("svg", Object.assign({ version: "1.1", id: "Layer_1", xmlns: "http://www.w3.org/2000/svg", x: "0px", y: "0px", viewBox: "0 0 512 512" }, props, { children: _jsxs("g", { children: [_jsx("path", { d: "M242.1,45.2c7.7-7.7,20.2-7.7,27.8-0.1l0.1,0.1l236.3,236.3c7.7,7.7,7.7,20.2,0,27.9c-7.7,7.7-20.2,7.7-27.9,0\r\n L256,86.9L33.7,309.3c-7.7,7.7-20.2,7.7-27.9,0c-7.7-7.7-7.7-20.2,0-27.9L242.1,45.2z" }), _jsx("path", { d: "M242.1,202.7c7.7-7.7,20.2-7.7,27.8-0.1l0.1,0.1L506.2,439c7.7,7.7,7.7,20.2,0,27.9c-7.7,7.7-20.2,7.7-27.9,0\r\n L256,244.5L33.7,466.9c-7.7,7.7-20.2,7.7-27.9,0c-7.7-7.7-7.7-20.2,0-27.9L242.1,202.7z" })] }) })));
|
|
633
|
-
}
|
|
634
|
-
function getArrow(dir, left, width) {
|
|
635
|
-
let center = left + width / 2, Left = center - 12;
|
|
636
|
-
let style = { position: 'absolute', height: 24, width: 24, left: Left };
|
|
637
|
-
let props = { width: 24, height: 24, style, className: `aio-popup-highlight-arrow-${dir}` };
|
|
638
|
-
return (_jsx("div", { className: "aio-popup-highlight-arrow", children: getArrowIcon(props) }));
|
|
639
|
-
}
|
|
640
|
-
function getHtml(dir) {
|
|
641
|
-
if (!highlight.html) {
|
|
642
|
-
return '';
|
|
643
|
-
}
|
|
644
|
-
let column;
|
|
645
|
-
let html = highlight.html || '';
|
|
646
|
-
let space = _jsx("div", { className: "aio-popup-highlight-space" });
|
|
647
|
-
let content = _jsx("div", { className: "aio-popup-highlight-html", children: html });
|
|
648
|
-
let arrow = getArrow(dir, limitRef.current.Left, limitRef.current.Width);
|
|
649
|
-
if (dir === 'top') {
|
|
650
|
-
column = _jsxs(_Fragment, { children: [space, content, arrow] });
|
|
651
|
-
}
|
|
652
|
-
else {
|
|
653
|
-
column = _jsxs(_Fragment, { children: [arrow, content, space] });
|
|
654
|
-
}
|
|
655
|
-
return _jsx("div", { className: "aio-popup-highlight-html-container", children: column });
|
|
656
|
-
}
|
|
657
|
-
function click() {
|
|
658
|
-
if (highlight.mouseAccess) {
|
|
659
|
-
return;
|
|
660
|
-
}
|
|
661
|
-
if (highlight.onClick) {
|
|
662
|
-
highlight.onClick();
|
|
663
|
-
}
|
|
664
|
-
}
|
|
665
|
-
function vMask_node(type) {
|
|
666
|
-
let html = '', size = 0, className = 'aio-popup-highlight-mask';
|
|
667
|
-
let dir = type === 'top' || type === 'bottom' ? 'height' : 'width';
|
|
668
|
-
let limit = limitRef.current;
|
|
669
|
-
if (type === 'top') {
|
|
670
|
-
size = limit.Top;
|
|
671
|
-
if (limit.TopSpace > limit.BottomSpace) {
|
|
672
|
-
html = getHtml('top');
|
|
673
|
-
}
|
|
674
|
-
}
|
|
675
|
-
else if (type === 'bottom') {
|
|
676
|
-
className += ' aio-popup-highlight-mask-flex';
|
|
677
|
-
if (limit.TopSpace <= limit.BottomSpace) {
|
|
678
|
-
html = getHtml('bottom');
|
|
679
|
-
}
|
|
680
|
-
}
|
|
681
|
-
else if (type === 'left') {
|
|
682
|
-
size = limit.Left;
|
|
683
|
-
}
|
|
684
|
-
else {
|
|
685
|
-
className += ' aio-popup-highlight-mask-flex';
|
|
686
|
-
}
|
|
687
|
-
return (_jsx("div", { className: className, style: { [dir]: size }, onClick: () => click(), children: html }));
|
|
688
|
-
}
|
|
689
|
-
function focus_node() {
|
|
690
|
-
const cls1 = "aio-popup-highlight-focus-container", cls2 = 'aio-popup-highlight-focus';
|
|
691
|
-
return (_jsx("div", { style: { width: limit.Width }, className: cls1, onClick: click, children: _jsx("div", { className: cls2 }) }));
|
|
692
|
-
}
|
|
693
|
-
function main_node() {
|
|
694
|
-
return _jsxs("div", { className: "aio-popup-highlight-main", style: { height: limit.Height }, children: [vMask_node('left'), focus_node(), vMask_node('right')] });
|
|
695
|
-
}
|
|
696
|
-
function getStyle() { return { pointerEvents: highlight.mouseAccess ? 'none' : 'all' }; }
|
|
697
|
-
const attrs = AddToAttrs(highlight.attrs, { className: 'aio-popup-highlight', style: getStyle() });
|
|
698
|
-
return (_jsxs("div", Object.assign({}, attrs, { children: [vMask_node('top'), main_node(), vMask_node('bottom')] })));
|
|
699
|
-
};
|
|
700
|
-
function getHLLimit(highlight) {
|
|
701
|
-
const { padding = 6, dom } = highlight;
|
|
702
|
-
let offset = dom.offset();
|
|
703
|
-
let left = offset.left - window.pageXOffset;
|
|
704
|
-
let top = offset.top - window.pageYOffset;
|
|
705
|
-
let pageHeight = window.innerHeight;
|
|
706
|
-
let width = dom.outerWidth();
|
|
707
|
-
let height = dom.outerHeight();
|
|
708
|
-
let Top = top - 1 * padding;
|
|
709
|
-
let Left = left - 1 * padding;
|
|
710
|
-
let Width = width + 2 * padding;
|
|
711
|
-
let Height = height + 2 * padding;
|
|
712
|
-
let TopSpace = top;
|
|
713
|
-
let BottomSpace = pageHeight - (top + height);
|
|
714
|
-
let res = { Left, Top, Width, Height, TopSpace, BottomSpace };
|
|
715
|
-
return res;
|
|
716
|
-
}
|
|
717
|
-
function getEasing(highlight) {
|
|
718
|
-
const { easing } = highlight;
|
|
719
|
-
var easingNames = [
|
|
720
|
-
'linear',
|
|
721
|
-
'easeInQuad',
|
|
722
|
-
'easeInSine',
|
|
723
|
-
'easeInCirc',
|
|
724
|
-
'easeInBack',
|
|
725
|
-
'easeOutQuad',
|
|
726
|
-
'easeOutSine',
|
|
727
|
-
'easeOutCirc',
|
|
728
|
-
'easeInOutQuad',
|
|
729
|
-
'easeInOutSine',
|
|
730
|
-
'easeInOutBack',
|
|
731
|
-
'easeOutBounce', //27
|
|
732
|
-
];
|
|
733
|
-
if (typeof easing === 'number') {
|
|
734
|
-
let res = easingNames[easing];
|
|
735
|
-
return res || easingNames[0];
|
|
736
|
-
}
|
|
737
|
-
return easing;
|
|
738
|
-
}
|
|
739
|
-
const InfoSvg = () => {
|
|
740
|
-
const d = "M11,9H13V7H11M12,20C7.59,20 4,16.41 4,12C4,7.59 7.59,4 12,4C16.41,4 20,7.59 20,12C20,16.41 16.41,20 12,20M12,2A10,10 0 0,0 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12A10,10 0 0,0 12,2M11,17H13V11H11V17Z";
|
|
741
|
-
return (_jsx("svg", { viewBox: "0 0 24 24", role: "presentation", style: { width: '1.2rem', height: '1.2rem' }, children: _jsx("path", { d: d, style: { fill: 'currentcolor' } }) }));
|
|
742
|
-
};
|
|
743
|
-
const SuccessSvg = () => {
|
|
744
|
-
const d = "M12 2C6.5 2 2 6.5 2 12S6.5 22 12 22 22 17.5 22 12 17.5 2 12 2M12 20C7.59 20 4 16.41 4 12S7.59 4 12 4 20 7.59 20 12 16.41 20 12 20M16.59 7.58L10 14.17L7.41 11.59L6 13L10 17L18 9L16.59 7.58Z";
|
|
745
|
-
return (_jsx("svg", { viewBox: "0 0 24 24", role: "presentation", style: { width: '1.2rem', height: '1.2rem' }, children: _jsx("path", { d: d, style: { fill: 'currentcolor' } }) }));
|
|
746
|
-
};
|
|
747
|
-
function getBound(dom) {
|
|
748
|
-
try {
|
|
749
|
-
const res = dom.getBoundingClientRect();
|
|
750
|
-
return { width: res.width, height: res.height, left: res.left, top: res.top, bottom: res.bottom, right: res.right };
|
|
751
|
-
}
|
|
752
|
-
catch (_a) {
|
|
753
|
-
return { width: 0, height: 0, left: 0, top: 0, bottom: 0, right: 0 };
|
|
754
|
-
}
|
|
755
|
-
}
|
|
756
|
-
export class Loading {
|
|
757
|
-
constructor(loader) {
|
|
758
|
-
this.loader = '0';
|
|
759
|
-
this.getLoader_0 = () => {
|
|
760
|
-
return (`
|
|
761
|
-
<div class="aio-loading-container-0">
|
|
762
|
-
<div class="aio-loading-0">
|
|
763
|
-
${new Array(5).fill(0).map((o, i) => this.getLoaderItem_0(`0.${i}`)).join(' ')}
|
|
764
|
-
</div>
|
|
765
|
-
</div>
|
|
766
|
-
`);
|
|
767
|
-
};
|
|
768
|
-
this.getLoaderItem_0 = (ease) => {
|
|
769
|
-
return `<div class="aio-loading-item-0" style="animation: 1s ease-in-out ${ease}s infinite normal none running aioloading0;"></div>`;
|
|
770
|
-
};
|
|
771
|
-
this.getLoader = (id) => {
|
|
772
|
-
let content = '';
|
|
773
|
-
if (this.loader === '0') {
|
|
774
|
-
content = this.getLoader_0();
|
|
775
|
-
}
|
|
776
|
-
else if (typeof this.loader === 'string') {
|
|
777
|
-
content = this.loader;
|
|
778
|
-
}
|
|
779
|
-
return (`<div class="aio-loading" id="aio-loading-${id}">${content}</div>`);
|
|
780
|
-
};
|
|
781
|
-
this.show = (id, parentSelector) => {
|
|
782
|
-
parentSelector = parentSelector || 'body';
|
|
783
|
-
let loadingStr = this.getLoader(id);
|
|
784
|
-
let parent = document.querySelector(parentSelector);
|
|
785
|
-
if (parent) {
|
|
786
|
-
parent.insertAdjacentHTML('beforeend', loadingStr);
|
|
787
|
-
}
|
|
788
|
-
};
|
|
789
|
-
this.hide = (id) => {
|
|
790
|
-
let loadingDom = document.getElementById('aio-loading-' + id);
|
|
791
|
-
if (!loadingDom) {
|
|
792
|
-
loadingDom = document.querySelector('.aio-loading');
|
|
793
|
-
}
|
|
794
|
-
if (loadingDom) {
|
|
795
|
-
loadingDom.remove();
|
|
796
|
-
}
|
|
797
|
-
};
|
|
798
|
-
if (typeof loader === 'string') {
|
|
799
|
-
this.loader = loader;
|
|
800
|
-
}
|
|
801
|
-
}
|
|
802
|
-
}
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
11
|
+
import { createRef, useEffect, useState, createContext, useContext, useRef } from 'react';
|
|
12
|
+
import * as ReactDOMServer from 'react-dom/server';
|
|
13
|
+
import ReactDOM from 'react-dom';
|
|
14
|
+
import anime from "animejs/lib/anime.es.js";
|
|
15
|
+
import $ from 'jquery';
|
|
16
|
+
import './index.css';
|
|
17
|
+
const CTX = createContext({});
|
|
18
|
+
function Align(p) {
|
|
19
|
+
let { modal, target, fitHorizontal, rtl, limitTo } = p;
|
|
20
|
+
const bodyWidth = window.innerWidth, bodyHeight = window.innerHeight;
|
|
21
|
+
let pageLimit = { left: 0, top: 0, bottom: bodyHeight, right: bodyWidth, width: bodyWidth, height: bodyHeight };
|
|
22
|
+
let targetLimit = getBound(target[0]);
|
|
23
|
+
let domLimit = getBound(modal[0]);
|
|
24
|
+
targetLimit = Object.assign({}, targetLimit);
|
|
25
|
+
domLimit = Object.assign({}, domLimit);
|
|
26
|
+
let overflowY;
|
|
27
|
+
domLimit.top = targetLimit.bottom;
|
|
28
|
+
domLimit.bottom = domLimit.top + domLimit.height;
|
|
29
|
+
if (fitHorizontal) {
|
|
30
|
+
domLimit.width = targetLimit.width;
|
|
31
|
+
domLimit.left = targetLimit.left;
|
|
32
|
+
domLimit.right = targetLimit.left + targetLimit.width;
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
if (limitTo) {
|
|
36
|
+
let elem = modal.parents(limitTo);
|
|
37
|
+
if (elem.length) {
|
|
38
|
+
pageLimit = getBound(elem[0]);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
//اگر راست به چپ باید باشد
|
|
42
|
+
if (rtl) {
|
|
43
|
+
//راست المان را با راست هدف ست کن
|
|
44
|
+
domLimit.right = targetLimit.right;
|
|
45
|
+
//چپ المان را بروز رسانی کن
|
|
46
|
+
domLimit.left = domLimit.right - domLimit.width;
|
|
47
|
+
//اگر المان از سمت چپ از صفحه بیرون زد سمت چپ المان را با سمت چپ صفحه ست کن
|
|
48
|
+
if (domLimit.left < pageLimit.left) {
|
|
49
|
+
domLimit.left = pageLimit.left;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
//چپ المان را با چپ هدف ست کن
|
|
54
|
+
domLimit.left = targetLimit.left;
|
|
55
|
+
//راست المان را بروز رسانی کن
|
|
56
|
+
domLimit.right = domLimit.left + domLimit.width;
|
|
57
|
+
//اگر المان از سمت راست صفحه بیرون زد سمت چپ المان را با پهنای المان ست کن
|
|
58
|
+
if (domLimit.right > pageLimit.right) {
|
|
59
|
+
domLimit.left = pageLimit.right - domLimit.width;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
//اگر المان از سمت پایین صفحه بیرون زد
|
|
64
|
+
if (domLimit.bottom > pageLimit.bottom) {
|
|
65
|
+
if (domLimit.height > targetLimit.top - pageLimit.top) {
|
|
66
|
+
domLimit.top = pageLimit.bottom - domLimit.height;
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
domLimit.top = targetLimit.top - domLimit.height;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
domLimit.top = targetLimit.bottom;
|
|
74
|
+
}
|
|
75
|
+
if (domLimit.height > pageLimit.height) {
|
|
76
|
+
domLimit.top = pageLimit.top;
|
|
77
|
+
domLimit.height = pageLimit.height;
|
|
78
|
+
overflowY = 'auto';
|
|
79
|
+
}
|
|
80
|
+
return { left: domLimit.left, top: domLimit.top, width: domLimit.width, overflowY, maxWidth: pageLimit.width };
|
|
81
|
+
}
|
|
82
|
+
const CloseIcon = () => {
|
|
83
|
+
return (_jsx("svg", { viewBox: "0 0 24 24", role: "presentation", style: { width: '1.2rem', height: '1.2rem' }, children: _jsx("path", { d: "M19,6.41L17.59,5L12,10.59L6.41,5L5,6.41L10.59,12L5,17.59L6.41,19L12,13.41L17.59,19L19,17.59L13.41,12L19,6.41Z", style: { fill: 'currentcolor' } }) }));
|
|
84
|
+
};
|
|
85
|
+
function AddToAttrs(attrs, p) {
|
|
86
|
+
attrs = attrs || {};
|
|
87
|
+
let { style } = p;
|
|
88
|
+
let attrClassName = attrs.className ? attrs.className.split(' ') : [];
|
|
89
|
+
let className = p.className ? (Array.isArray(p.className) ? p.className : p.className.split(' ')) : [];
|
|
90
|
+
let classNames = [...attrClassName, ...className.filter((o) => !!o)];
|
|
91
|
+
let newClassName = classNames.length ? classNames.join(' ') : undefined;
|
|
92
|
+
let newStyle = Object.assign(Object.assign({}, attrs.style), style);
|
|
93
|
+
return Object.assign(Object.assign(Object.assign({}, attrs), { className: newClassName, style: newStyle }), p.attrs);
|
|
94
|
+
}
|
|
95
|
+
const usePopup = (props) => {
|
|
96
|
+
let [modals, setModals] = useState([]);
|
|
97
|
+
const promptTexts = useRef({});
|
|
98
|
+
let modalsRef = useRef(modals);
|
|
99
|
+
modalsRef.current = modals;
|
|
100
|
+
const getModals = () => modalsRef.current;
|
|
101
|
+
const [snackebarItems, setSnackebarItems] = useState([]);
|
|
102
|
+
const snackebarItemsRef = useRef(snackebarItems);
|
|
103
|
+
snackebarItemsRef.current = snackebarItems;
|
|
104
|
+
const [highlight, setHighlight] = useState();
|
|
105
|
+
const addModal = (o) => {
|
|
106
|
+
if (o.id === undefined) {
|
|
107
|
+
o.id = 'popup' + Math.round(Math.random() * 1000000);
|
|
108
|
+
}
|
|
109
|
+
let newModal = o;
|
|
110
|
+
setModals(prevModals => {
|
|
111
|
+
let newModals = prevModals.filter(({ id }) => id !== o.id);
|
|
112
|
+
return [...newModals, newModal];
|
|
113
|
+
});
|
|
114
|
+
};
|
|
115
|
+
const removeModal = (arg) => __awaiter(void 0, void 0, void 0, function* () {
|
|
116
|
+
if (typeof arg !== 'string') {
|
|
117
|
+
arg = 'last';
|
|
118
|
+
}
|
|
119
|
+
if (arg === 'all') {
|
|
120
|
+
setModals([]);
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
if (!modalsRef.current.length) {
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
if (arg === 'last') {
|
|
127
|
+
arg = modalsRef.current[modalsRef.current.length - 1].id;
|
|
128
|
+
}
|
|
129
|
+
let modal = modalsRef.current.find((o) => o.id === arg);
|
|
130
|
+
if (!modal) {
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
$(`[data-id=${arg}]`).addClass('not-mounted');
|
|
134
|
+
setTimeout(() => {
|
|
135
|
+
if (modal && typeof modal.onClose === 'function') {
|
|
136
|
+
modal.onClose();
|
|
137
|
+
}
|
|
138
|
+
setModals(prevModals => prevModals.filter((o) => o.id !== arg));
|
|
139
|
+
}, 300);
|
|
140
|
+
});
|
|
141
|
+
const addSnackebar = (item) => {
|
|
142
|
+
let items = snackebarItemsRef.current;
|
|
143
|
+
let newItems = [...items, Object.assign(Object.assign({}, item), { id: 'a' + Math.round(Math.random() * 1000000000) })];
|
|
144
|
+
setSnackebarItems(newItems);
|
|
145
|
+
};
|
|
146
|
+
const removeSnackebar = (id) => {
|
|
147
|
+
const items = snackebarItemsRef.current;
|
|
148
|
+
const item = items.find((o) => o.id === id);
|
|
149
|
+
if (!item || item.onClose === false) {
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
let newItems = items.filter((o, i) => o.id !== id);
|
|
153
|
+
setSnackebarItems(newItems);
|
|
154
|
+
if (typeof item.onClose === 'function') {
|
|
155
|
+
item.onClose();
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
const addAlert = (obj) => Alert(Object.assign({ rtl: props === null || props === void 0 ? void 0 : props.rtl }, obj));
|
|
159
|
+
const addHighlight = (highlight) => setHighlight(highlight);
|
|
160
|
+
const removeHighlight = () => setHighlight(undefined);
|
|
161
|
+
const addConfirm = (obj) => {
|
|
162
|
+
let { title, subtitle, text, submitText = 'Yes', canselText = 'No', onSubmit, onCansel = () => { }, setAttrs = () => { return {}; } } = obj;
|
|
163
|
+
let config = {
|
|
164
|
+
position: 'center',
|
|
165
|
+
setAttrs: (key) => {
|
|
166
|
+
let attrs = setAttrs(key);
|
|
167
|
+
if (key === 'modal') {
|
|
168
|
+
return AddToAttrs(attrs, { className: 'aio-popup-confirm' });
|
|
169
|
+
}
|
|
170
|
+
return attrs;
|
|
171
|
+
},
|
|
172
|
+
header: { title, subtitle },
|
|
173
|
+
body: _jsx(_Fragment, { children: text }),
|
|
174
|
+
footer: (_jsxs(_Fragment, { children: [_jsx("button", { type: 'button', onClick: () => { onCansel(); removeModal(); }, children: canselText }), _jsx("button", { type: 'button', className: 'active', onClick: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
175
|
+
if (!onSubmit) {
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
let res = yield onSubmit();
|
|
179
|
+
if (res !== false) {
|
|
180
|
+
removeModal();
|
|
181
|
+
}
|
|
182
|
+
}), children: submitText })] }))
|
|
183
|
+
};
|
|
184
|
+
addModal(config);
|
|
185
|
+
};
|
|
186
|
+
const addPrompt = (obj) => {
|
|
187
|
+
const id = 'a' + (Math.round(Math.random() * 100000));
|
|
188
|
+
let { title, subtitle, submitText = 'Submit', canselText = 'close', onSubmit, onCansel = () => { }, setAttrs = () => { return {}; } } = obj;
|
|
189
|
+
let config = {
|
|
190
|
+
position: 'center',
|
|
191
|
+
setAttrs: (key) => {
|
|
192
|
+
let attrs = setAttrs(key);
|
|
193
|
+
if (key === 'modal') {
|
|
194
|
+
return AddToAttrs(attrs, { className: 'aio-popup-prompt' });
|
|
195
|
+
}
|
|
196
|
+
return attrs;
|
|
197
|
+
},
|
|
198
|
+
header: { title, subtitle },
|
|
199
|
+
body: _jsx(Prompt, { change: (value) => promptTexts.current = Object.assign(Object.assign({}, promptTexts.current), { [id]: value }) }),
|
|
200
|
+
footer: (_jsxs(_Fragment, { children: [_jsx("button", { type: 'button', onClick: () => { onCansel(); removeModal(); }, children: canselText }), _jsx("button", { type: 'button', className: 'active', onClick: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
201
|
+
if (!onSubmit) {
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
const value = promptTexts.current[id];
|
|
205
|
+
let res = yield onSubmit(value);
|
|
206
|
+
if (res !== false) {
|
|
207
|
+
removeModal();
|
|
208
|
+
}
|
|
209
|
+
else {
|
|
210
|
+
const newPromptTexts = {};
|
|
211
|
+
for (let prop in promptTexts.current) {
|
|
212
|
+
if (prop !== id) {
|
|
213
|
+
newPromptTexts[prop] = promptTexts.current[prop];
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
promptTexts.current = newPromptTexts;
|
|
217
|
+
}
|
|
218
|
+
}), children: submitText })] }))
|
|
219
|
+
};
|
|
220
|
+
addModal(config);
|
|
221
|
+
};
|
|
222
|
+
const getContext = () => {
|
|
223
|
+
return {
|
|
224
|
+
rtl: !!props && !!props.rtl,
|
|
225
|
+
snackebarItems: snackebarItemsRef.current,
|
|
226
|
+
removeSnackebar, removeModal
|
|
227
|
+
};
|
|
228
|
+
};
|
|
229
|
+
const render = (caller) => {
|
|
230
|
+
return (_jsxs(CTX.Provider, { value: getContext(), children: [modalsRef.current.map((modal, i) => {
|
|
231
|
+
return (_jsx(Popup, { modal: modal, isLast: i === modalsRef.current.length - 1, renderCaller: caller }, modal.id));
|
|
232
|
+
}), snackebarItems.map((item, i) => _jsx(SnackebarItem, { item: item, index: i }, item.id)), !!highlight && _jsx(Highlight, { highlight: highlight })] }));
|
|
233
|
+
};
|
|
234
|
+
const portal = () => ReactDOM.createPortal(render(), document.body);
|
|
235
|
+
return { addAlert, addSnackebar, removeModal, addModal, getModals, addHighlight, removeHighlight, render, addConfirm, addPrompt, portal };
|
|
236
|
+
};
|
|
237
|
+
export default usePopup;
|
|
238
|
+
const Prompt = ({ change }) => {
|
|
239
|
+
const [text, setText] = useState('');
|
|
240
|
+
return (_jsx("textarea", { placeholder: text, value: text, onChange: (e) => { const value = e.target.value; setText(value); change(value); } }));
|
|
241
|
+
};
|
|
242
|
+
const POPUPCTX = createContext({});
|
|
243
|
+
const Popup = ({ modal, isLast, renderCaller }) => {
|
|
244
|
+
const mainContext = useContext(CTX);
|
|
245
|
+
let { setAttrs = () => { return {}; }, id, position = 'fullscreen', getTarget } = modal;
|
|
246
|
+
let [temp] = useState({ dom: createRef(), backdropDom: createRef(), dui: undefined });
|
|
247
|
+
let [popoverStyle, setPopoverStyle] = useState({});
|
|
248
|
+
let modalMouseDown = useRef(false);
|
|
249
|
+
//bar taraf kardane moshkele mozakhrafe click rooye backdrop ke az har ja mouse ro roosh vel mikoni modal baste mishe
|
|
250
|
+
const isModalMouseDown = () => modalMouseDown.current;
|
|
251
|
+
let [state, setState] = useState(modal.state);
|
|
252
|
+
let attrs = setAttrs('modal') || {};
|
|
253
|
+
const firstMount = useRef(false);
|
|
254
|
+
useEffect(() => () => { $(window).unbind('click', handleBackClick); });
|
|
255
|
+
useEffect(() => {
|
|
256
|
+
if (position === 'popover') {
|
|
257
|
+
setPopoverStyle(getPopoverStyle());
|
|
258
|
+
}
|
|
259
|
+
if (getTarget) {
|
|
260
|
+
temp.dui = 'a' + (Math.round(Math.random() * 10000000));
|
|
261
|
+
let target = getTarget();
|
|
262
|
+
target.attr('data-id', temp.dui);
|
|
263
|
+
}
|
|
264
|
+
setTimeout(() => {
|
|
265
|
+
let popup = $(temp.dom.current);
|
|
266
|
+
popup.removeClass('not-mounted');
|
|
267
|
+
$(temp.backdropDom.current).removeClass('not-mounted');
|
|
268
|
+
popup.focus();
|
|
269
|
+
}, 0);
|
|
270
|
+
$(window).unbind('click', handleBackClick);
|
|
271
|
+
$(window).bind('click', handleBackClick);
|
|
272
|
+
}, []);
|
|
273
|
+
function handleBackClick(e) {
|
|
274
|
+
//در مود پاپاور اگر هر جایی غیر از اینپوت و پاپاور کلیک شد پاپاپ رو ببند
|
|
275
|
+
if (!temp.dui) {
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
let target = $(e.target);
|
|
279
|
+
if (position !== 'popover' || target.attr('data-id') === temp.dui || target.parents(`[data-id=${temp.dui}]`).length) {
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
mainContext.removeModal();
|
|
283
|
+
}
|
|
284
|
+
function getModalProps() {
|
|
285
|
+
let style = Object.assign(Object.assign({}, popoverStyle), attrs.style);
|
|
286
|
+
let ev = "ontouchstart" in document.documentElement ? 'onTouchStart' : 'onMouseDown';
|
|
287
|
+
return Object.assign(Object.assign({}, attrs), { ref: temp.dom, "data-id": modal.id, tabIndex: 0, onKeyDown, [ev]: mouseDown, className: getClassName(), style: Object.assign({}, style), onClick: (e) => { e.stopPropagation(); } });
|
|
288
|
+
}
|
|
289
|
+
function getPopoverStyle() {
|
|
290
|
+
if (!getTarget) {
|
|
291
|
+
return {};
|
|
292
|
+
}
|
|
293
|
+
let target = getTarget();
|
|
294
|
+
if (!target || !target.length) {
|
|
295
|
+
return {};
|
|
296
|
+
}
|
|
297
|
+
let p = { modal: $(temp.dom.current), target, fitHorizontal: modal.fitHorizontal, limitTo: modal.limitTo, attrs, rtl: mainContext.rtl };
|
|
298
|
+
let style = Align(p);
|
|
299
|
+
let res = Object.assign(Object.assign({}, style), { position: 'absolute' });
|
|
300
|
+
return res;
|
|
301
|
+
}
|
|
302
|
+
function onKeyDown(e) {
|
|
303
|
+
if (!isLast) {
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
306
|
+
let code = e.keyCode;
|
|
307
|
+
if (code === 27) {
|
|
308
|
+
mainContext.removeModal();
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
function mouseUp() {
|
|
312
|
+
setTimeout(() => modalMouseDown.current = false, 0);
|
|
313
|
+
}
|
|
314
|
+
function mouseDown(e) {
|
|
315
|
+
modalMouseDown.current = true;
|
|
316
|
+
$(window).unbind('mouseup', mouseUp);
|
|
317
|
+
$(window).bind('mouseup', mouseUp);
|
|
318
|
+
}
|
|
319
|
+
function getClassName() {
|
|
320
|
+
let className = 'aio-popup';
|
|
321
|
+
className += mainContext.rtl ? ' rtl' : ' ltr';
|
|
322
|
+
if (firstMount) {
|
|
323
|
+
className += ' not-mounted';
|
|
324
|
+
}
|
|
325
|
+
if (attrs.className) {
|
|
326
|
+
className += ' ' + attrs.className;
|
|
327
|
+
}
|
|
328
|
+
return className;
|
|
329
|
+
}
|
|
330
|
+
const getContext = () => ({ modal, isLast, state, setState, onKeyDown });
|
|
331
|
+
return (_jsx(POPUPCTX.Provider, { value: getContext(), children: _jsx(ModalBackdrop, { firstMount: !!firstMount, backdropDom: temp.backdropDom, isModalMouseDown: isModalMouseDown, children: _jsxs("div", Object.assign({}, getModalProps(), { children: [_jsx(ModalHeader, {}), _jsx(ModalBody, {}, modal.id), _jsx(ModalFooter, {})] }), modal.id) }, modal.id) }));
|
|
332
|
+
};
|
|
333
|
+
const ModalBackdrop = ({ children, firstMount, backdropDom, isModalMouseDown }) => {
|
|
334
|
+
const { removeModal, rtl } = useContext(CTX);
|
|
335
|
+
let { modal, onKeyDown } = useContext(POPUPCTX);
|
|
336
|
+
let { setAttrs = () => { return {}; }, id, position = 'fullscreen' } = modal;
|
|
337
|
+
const [attrs] = useState(setAttrs('backdrop') || {});
|
|
338
|
+
function backClick(e) {
|
|
339
|
+
if (isModalMouseDown()) {
|
|
340
|
+
return;
|
|
341
|
+
}
|
|
342
|
+
if (e.target !== e.currentTarget) {
|
|
343
|
+
return;
|
|
344
|
+
}
|
|
345
|
+
let target = $(e.target);
|
|
346
|
+
if (!target.hasClass('aio-popup-backdrop')) {
|
|
347
|
+
return;
|
|
348
|
+
}
|
|
349
|
+
removeModal();
|
|
350
|
+
}
|
|
351
|
+
function getProps() {
|
|
352
|
+
let className = 'aio-popup-backdrop';
|
|
353
|
+
className += ` aio-popup-position-${position}`;
|
|
354
|
+
className += rtl ? ' rtl' : ' ltr';
|
|
355
|
+
if (firstMount) {
|
|
356
|
+
className += ' not-mounted';
|
|
357
|
+
}
|
|
358
|
+
return AddToAttrs(attrs, { className, attrs: { ref: backdropDom, onKeyDown, tabIndex: 0, ['data-id']: id, onClick: attrs.onClick ? attrs.onClick : backClick } });
|
|
359
|
+
}
|
|
360
|
+
return _jsx("div", Object.assign({}, getProps(), { children: children }));
|
|
361
|
+
};
|
|
362
|
+
const ModalHeader = () => {
|
|
363
|
+
const { removeModal } = useContext(CTX);
|
|
364
|
+
let { modal, state, setState } = useContext(POPUPCTX);
|
|
365
|
+
if (!modal.header) {
|
|
366
|
+
return null;
|
|
367
|
+
}
|
|
368
|
+
let { setAttrs = () => { return {}; } } = modal;
|
|
369
|
+
let attrs = setAttrs('header') || {};
|
|
370
|
+
if (typeof modal.header === 'function') {
|
|
371
|
+
return modal.header({ removeModal: removeModal, state, setState });
|
|
372
|
+
}
|
|
373
|
+
if (typeof modal.header !== 'object') {
|
|
374
|
+
return null;
|
|
375
|
+
}
|
|
376
|
+
return (_jsxs("div", Object.assign({}, AddToAttrs(attrs, { className: 'aio-popup-header' }), { children: [_jsx(ModalHeaderElement, { type: 'before' }, 'before'), _jsx(ModalHeaderElement, { type: 'title' }, 'title'), _jsx(ModalHeaderElement, { type: 'after' }, 'after'), _jsx(ModalClose, {})] })));
|
|
377
|
+
};
|
|
378
|
+
const ModalHeaderElement = ({ type }) => {
|
|
379
|
+
let { modal } = useContext(POPUPCTX), { header } = modal;
|
|
380
|
+
if (typeof header === 'function' || !header) {
|
|
381
|
+
return null;
|
|
382
|
+
}
|
|
383
|
+
if (!header[type]) {
|
|
384
|
+
return null;
|
|
385
|
+
}
|
|
386
|
+
return _jsx("div", { className: `aio-popup-header-${type}`, "data-subtitle": type === 'title' ? header.subtitle : undefined, children: header[type] });
|
|
387
|
+
};
|
|
388
|
+
const ModalClose = () => {
|
|
389
|
+
const { removeModal } = useContext(CTX);
|
|
390
|
+
let { modal, state, setState } = useContext(POPUPCTX), { header } = modal;
|
|
391
|
+
if (typeof header === 'function' || !header) {
|
|
392
|
+
return null;
|
|
393
|
+
}
|
|
394
|
+
if (header.onClose === false) {
|
|
395
|
+
return null;
|
|
396
|
+
}
|
|
397
|
+
return _jsx("div", { className: `aio-popup-header-close`, onClick: (e) => {
|
|
398
|
+
e.stopPropagation();
|
|
399
|
+
e.preventDefault();
|
|
400
|
+
if (typeof header.onClose === 'function') {
|
|
401
|
+
header.onClose({ state, setState });
|
|
402
|
+
}
|
|
403
|
+
else {
|
|
404
|
+
removeModal(modal.id);
|
|
405
|
+
}
|
|
406
|
+
}, children: _jsx(CloseIcon, {}) });
|
|
407
|
+
};
|
|
408
|
+
const ModalBody = () => {
|
|
409
|
+
const { modal } = useContext(POPUPCTX);
|
|
410
|
+
let { body, setAttrs = () => { return {}; } } = modal;
|
|
411
|
+
let attrs = setAttrs('body') || {};
|
|
412
|
+
if (!body || body === null) {
|
|
413
|
+
return null;
|
|
414
|
+
}
|
|
415
|
+
return (_jsx("div", Object.assign({}, AddToAttrs(attrs, { className: 'aio-popup-body aio-popup-scroll' }), { children: body })));
|
|
416
|
+
};
|
|
417
|
+
const ModalFooter = () => {
|
|
418
|
+
const { modal } = useContext(POPUPCTX);
|
|
419
|
+
let { setAttrs = () => { return {}; }, footer } = modal;
|
|
420
|
+
if (!footer) {
|
|
421
|
+
return null;
|
|
422
|
+
}
|
|
423
|
+
let Attrs = setAttrs('footer') || {};
|
|
424
|
+
const attrs = AddToAttrs(Attrs, { className: 'aio-popup-footer' });
|
|
425
|
+
return _jsx("div", Object.assign({}, attrs, { children: footer }));
|
|
426
|
+
};
|
|
427
|
+
const SBCTX = createContext({});
|
|
428
|
+
const SnackebarItem = (props) => {
|
|
429
|
+
const mainContext = useContext(CTX);
|
|
430
|
+
let { item } = props;
|
|
431
|
+
let { time = 8, id, align = ['right', 'top'] } = item;
|
|
432
|
+
if (align[1] !== 'top' && align[1] !== 'bottom') {
|
|
433
|
+
align[1] = 'top';
|
|
434
|
+
}
|
|
435
|
+
if (align[0] !== 'left' && align[0] !== 'right' && align[0] !== 'center') {
|
|
436
|
+
align[0] = 'right';
|
|
437
|
+
}
|
|
438
|
+
let [mounted, setMounted] = useState(false);
|
|
439
|
+
useEffect(() => {
|
|
440
|
+
setTimeout(() => setMounted(true), 0);
|
|
441
|
+
setTimeout(() => remove(), time * 1000);
|
|
442
|
+
}, []);
|
|
443
|
+
function remove() {
|
|
444
|
+
setMounted(false);
|
|
445
|
+
setTimeout(() => mainContext.removeSnackebar(id), 200);
|
|
446
|
+
}
|
|
447
|
+
const getSvg = (type) => { return type === 'error' || type === 'warning' || type === 'info' ? _jsx(InfoSvg, {}) : _jsx(SuccessSvg, {}); };
|
|
448
|
+
const getContext = () => {
|
|
449
|
+
return { mainContext, remove, item: Object.assign(Object.assign({}, props.item), { time, align }), index: props.index, mounted, getSvg };
|
|
450
|
+
};
|
|
451
|
+
return (_jsx(SBCTX.Provider, { value: getContext(), children: _jsx(SnackebarContainer, {}) }));
|
|
452
|
+
};
|
|
453
|
+
const SnackebarContainer = () => {
|
|
454
|
+
const { mainContext, mounted, index, item, remove } = useContext(SBCTX);
|
|
455
|
+
const { rtl } = mainContext;
|
|
456
|
+
let { onClose, align = ['right', 'top'] } = item;
|
|
457
|
+
function getOffsetStyle(index) {
|
|
458
|
+
let els = $('.aio-popup-snackebar-item-container'), sum = { top: 12, bottom: 12 };
|
|
459
|
+
for (let i = 0; i < index; i++) {
|
|
460
|
+
let dom = els.eq(i);
|
|
461
|
+
let height = dom.height() + 6;
|
|
462
|
+
let va = dom.attr('data-vertical-align');
|
|
463
|
+
sum[va] += height;
|
|
464
|
+
}
|
|
465
|
+
return {
|
|
466
|
+
[align[1] === 'top' ? 'top' : 'bottom']: sum[align[1]]
|
|
467
|
+
};
|
|
468
|
+
}
|
|
469
|
+
let className = 'aio-popup-snackebar-item-container';
|
|
470
|
+
className += ` aio-popup-snackebar-item-container-horizontal-align-${align[0]}`;
|
|
471
|
+
if (mounted) {
|
|
472
|
+
className += ' mounted';
|
|
473
|
+
}
|
|
474
|
+
if (rtl) {
|
|
475
|
+
className += ' rtl';
|
|
476
|
+
}
|
|
477
|
+
let style = getOffsetStyle(index);
|
|
478
|
+
let p = { 'data-vertical-align': align[1], className, style, onClick: onClose === false ? undefined : () => remove() };
|
|
479
|
+
return _jsx("div", Object.assign({}, p, { children: _jsx(SnackebarCard, {}) }));
|
|
480
|
+
};
|
|
481
|
+
const SnackebarCard = () => {
|
|
482
|
+
const { item } = useContext(SBCTX);
|
|
483
|
+
let { type, attrs = {} } = item;
|
|
484
|
+
let className = 'aio-popup-snackebar-item';
|
|
485
|
+
className += ` aio-popup-snackebar-item-${type}`;
|
|
486
|
+
if (attrs.className) {
|
|
487
|
+
className += ` ${attrs.className}`;
|
|
488
|
+
}
|
|
489
|
+
let p = Object.assign(Object.assign({}, attrs), { className, style: attrs.style });
|
|
490
|
+
return (_jsxs("div", Object.assign({}, p, { children: [_jsx(SnackebarIcon, {}), _jsx(SnackebarText, {}), _jsx(SnackebarAction, {}), _jsx(SnackebarBar, {})] })));
|
|
491
|
+
};
|
|
492
|
+
const SnackebarIcon = () => {
|
|
493
|
+
const { getSvg, item } = useContext(SBCTX);
|
|
494
|
+
return _jsx("div", { className: `aio-popup-snackebar-item-icon`, children: !!item.icon ? item.icon : getSvg(item.type) });
|
|
495
|
+
};
|
|
496
|
+
const SnackebarText = () => {
|
|
497
|
+
const { item } = useContext(SBCTX);
|
|
498
|
+
return (_jsxs("div", { className: 'aio-popup-snackebar-item-text', children: [_jsx("div", { className: 'aio-popup-snackebar-item-uptext', children: item.text }), !!item.subtext && _jsx("div", { className: 'aio-popup-snackebar-item-subtext', children: item.subtext })] }));
|
|
499
|
+
};
|
|
500
|
+
const SnackebarAction = () => {
|
|
501
|
+
const { item, remove } = useContext(SBCTX);
|
|
502
|
+
const { action } = item;
|
|
503
|
+
if (!action || !action.text) {
|
|
504
|
+
return null;
|
|
505
|
+
}
|
|
506
|
+
let p = {
|
|
507
|
+
className: 'aio-popup-snackebar-item-action',
|
|
508
|
+
onClick: (e) => { e.stopPropagation(); if (action) {
|
|
509
|
+
action.onClick();
|
|
510
|
+
} remove(); }
|
|
511
|
+
};
|
|
512
|
+
return (_jsx("button", Object.assign({}, p, { children: action.text })));
|
|
513
|
+
};
|
|
514
|
+
const SnackebarBar = () => {
|
|
515
|
+
const { item } = useContext(SBCTX);
|
|
516
|
+
return _jsx("div", { className: 'aio-popup-snackebar-bar', style: { transition: `${item.time || 8}s linear` } });
|
|
517
|
+
};
|
|
518
|
+
export function Alert(props) {
|
|
519
|
+
let { icon, type = '', title = '', text = '', time = 10, className, closeText = 'Close', onClose, rtl } = props;
|
|
520
|
+
let $$ = {
|
|
521
|
+
id: '',
|
|
522
|
+
time: 0,
|
|
523
|
+
getId() {
|
|
524
|
+
return 'aa' + Math.round((Math.random() * 100000000));
|
|
525
|
+
},
|
|
526
|
+
getBarRender() {
|
|
527
|
+
return `<div class='aio-popup-time-bar' style="width:${$$.time}%;"></div>`;
|
|
528
|
+
},
|
|
529
|
+
updateBarRender() {
|
|
530
|
+
$(`.aio-popup-alert-container.${$$.id} .aio-popup-time`).html($$.getBarRender());
|
|
531
|
+
},
|
|
532
|
+
getRender() {
|
|
533
|
+
return (`
|
|
534
|
+
<div class='aio-popup-alert-container not-mounted ${$$.id} aio-popup-alert-container-center${!!className ? ` ${className}` : ''}'>
|
|
535
|
+
<div class='aio-popup-alert aio-popup-alert-${type}'>
|
|
536
|
+
<div class='aio-popup-alert-header'>${$$.getIcon()}</div>
|
|
537
|
+
<div class='aio-popup-alert-body aio-popup-scroll'>
|
|
538
|
+
<div class='aio-popup-alert-title'>${ReactDOMServer.renderToStaticMarkup(title)}</div>
|
|
539
|
+
<div class='aio-popup-alert-text' style="text-align:${rtl ? 'right' : 'left'}">${text}</div>
|
|
540
|
+
</div>
|
|
541
|
+
<div class='aio-popup-alert-footer'>
|
|
542
|
+
<button class='aio-popup-alert-close ${$$.id}'>${closeText}</button>
|
|
543
|
+
</div>
|
|
544
|
+
<div class='aio-popup-time'></div>
|
|
545
|
+
</div>
|
|
546
|
+
</div>
|
|
547
|
+
`);
|
|
548
|
+
},
|
|
549
|
+
close() {
|
|
550
|
+
$$.toggleClass(false);
|
|
551
|
+
setTimeout(() => {
|
|
552
|
+
if (typeof onClose === 'function') {
|
|
553
|
+
onClose();
|
|
554
|
+
}
|
|
555
|
+
if (onClose === false) {
|
|
556
|
+
return;
|
|
557
|
+
}
|
|
558
|
+
$('.' + $$.id).remove();
|
|
559
|
+
}, 200);
|
|
560
|
+
},
|
|
561
|
+
getIcon() {
|
|
562
|
+
if (icon === false) {
|
|
563
|
+
return '';
|
|
564
|
+
}
|
|
565
|
+
return icon || {
|
|
566
|
+
error: (`<svg viewBox="0 0 24 24" role="presentation" style="width: 4.5rem; height: 4.5rem;"><path d="M19,6.41L17.59,5L12,10.59L6.41,5L5,6.41L10.59,12L5,17.59L6.41,19L12,13.41L17.59,19L19,17.59L13.41,12L19,6.41Z"></path></svg>`),
|
|
567
|
+
warning: (`<svg viewBox="0 0 24 24" role="presentation" style="width: 4.5rem; height: 4.5rem;"><path d="M12,2L1,21H23M12,6L19.53,19H4.47M11,10V14H13V10M11,16V18H13V16"></path></svg>`),
|
|
568
|
+
info: (`<svg viewBox="0 0 24 24" role="presentation" style="width: 4.5rem; height: 4.5rem;"><path d="M11,9H13V7H11M12,20C7.59,20 4,16.41 4,12C4,7.59 7.59,4 12,4C16.41,4 20,7.59 20,12C20,16.41 16.41,20 12,20M12,2A10,10 0 0,0 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12A10,10 0 0,0 12,2M11,17H13V11H11V17Z"></path></svg>`),
|
|
569
|
+
success: (`<svg viewBox="0 0 24 24" role="presentation" style="width: 4.5rem; height: 4.5rem;"><path d="M12 2C6.5 2 2 6.5 2 12S6.5 22 12 22 22 17.5 22 12 17.5 2 12 2M12 20C7.59 20 4 16.41 4 12S7.59 4 12 4 20 7.59 20 12 16.41 20 12 20M16.59 7.58L10 14.17L7.41 11.59L6 13L10 17L18 9L16.59 7.58Z"></path></svg>`)
|
|
570
|
+
}[type] || '';
|
|
571
|
+
},
|
|
572
|
+
startTimer() {
|
|
573
|
+
setTimeout(() => {
|
|
574
|
+
if ($$.time >= 100) {
|
|
575
|
+
$$.time = 100;
|
|
576
|
+
$$.close();
|
|
577
|
+
return;
|
|
578
|
+
}
|
|
579
|
+
$$.time += 2;
|
|
580
|
+
$$.updateBarRender();
|
|
581
|
+
$$.startTimer();
|
|
582
|
+
}, time / 50 * 1000);
|
|
583
|
+
},
|
|
584
|
+
toggleClass(mount) {
|
|
585
|
+
let dom = $(`.${$$.id}`);
|
|
586
|
+
if (mount) {
|
|
587
|
+
setTimeout(() => dom.removeClass('not-mounted'), 0);
|
|
588
|
+
}
|
|
589
|
+
else {
|
|
590
|
+
dom.addClass('not-mounted');
|
|
591
|
+
}
|
|
592
|
+
},
|
|
593
|
+
render() {
|
|
594
|
+
$('body').append($$.getRender());
|
|
595
|
+
$('button.' + $$.id).off('click', $$.close);
|
|
596
|
+
$('button.' + $$.id).on('click', $$.close);
|
|
597
|
+
$$.toggleClass(true);
|
|
598
|
+
}
|
|
599
|
+
};
|
|
600
|
+
$$.id = $$.getId();
|
|
601
|
+
$$.render();
|
|
602
|
+
if (time) {
|
|
603
|
+
$$.startTimer();
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
const Highlight = ({ highlight }) => {
|
|
607
|
+
const [limit, setLimit] = useState({ Left: 0, Top: 0, Width: 0, Height: 0, TopSpace: 0, BottomSpace: 0 });
|
|
608
|
+
const limitRef = useRef(limit);
|
|
609
|
+
limitRef.current = limit;
|
|
610
|
+
useEffect(() => {
|
|
611
|
+
setTimeout(() => {
|
|
612
|
+
try {
|
|
613
|
+
const { dom, duration = 1200 } = highlight;
|
|
614
|
+
dom[0].scrollIntoView();
|
|
615
|
+
let newLimit = getHLLimit(highlight);
|
|
616
|
+
let easing = getEasing(highlight);
|
|
617
|
+
let obj = Object.assign(Object.assign({}, newLimit), { targets: [Object.assign({}, limitRef.current)], duration, update: (p) => {
|
|
618
|
+
const { animatables } = p;
|
|
619
|
+
setLimit(Object.assign({}, animatables[0].target));
|
|
620
|
+
} });
|
|
621
|
+
if (easing) {
|
|
622
|
+
obj.easing = easing;
|
|
623
|
+
}
|
|
624
|
+
anime(obj);
|
|
625
|
+
}
|
|
626
|
+
catch (_a) {
|
|
627
|
+
alert(`aio-highlighter error => connot find dom`);
|
|
628
|
+
}
|
|
629
|
+
}, 0);
|
|
630
|
+
});
|
|
631
|
+
function getArrowIcon(props) {
|
|
632
|
+
return (_jsx("svg", Object.assign({ version: "1.1", id: "Layer_1", xmlns: "http://www.w3.org/2000/svg", x: "0px", y: "0px", viewBox: "0 0 512 512" }, props, { children: _jsxs("g", { children: [_jsx("path", { d: "M242.1,45.2c7.7-7.7,20.2-7.7,27.8-0.1l0.1,0.1l236.3,236.3c7.7,7.7,7.7,20.2,0,27.9c-7.7,7.7-20.2,7.7-27.9,0\r\n L256,86.9L33.7,309.3c-7.7,7.7-20.2,7.7-27.9,0c-7.7-7.7-7.7-20.2,0-27.9L242.1,45.2z" }), _jsx("path", { d: "M242.1,202.7c7.7-7.7,20.2-7.7,27.8-0.1l0.1,0.1L506.2,439c7.7,7.7,7.7,20.2,0,27.9c-7.7,7.7-20.2,7.7-27.9,0\r\n L256,244.5L33.7,466.9c-7.7,7.7-20.2,7.7-27.9,0c-7.7-7.7-7.7-20.2,0-27.9L242.1,202.7z" })] }) })));
|
|
633
|
+
}
|
|
634
|
+
function getArrow(dir, left, width) {
|
|
635
|
+
let center = left + width / 2, Left = center - 12;
|
|
636
|
+
let style = { position: 'absolute', height: 24, width: 24, left: Left };
|
|
637
|
+
let props = { width: 24, height: 24, style, className: `aio-popup-highlight-arrow-${dir}` };
|
|
638
|
+
return (_jsx("div", { className: "aio-popup-highlight-arrow", children: getArrowIcon(props) }));
|
|
639
|
+
}
|
|
640
|
+
function getHtml(dir) {
|
|
641
|
+
if (!highlight.html) {
|
|
642
|
+
return '';
|
|
643
|
+
}
|
|
644
|
+
let column;
|
|
645
|
+
let html = highlight.html || '';
|
|
646
|
+
let space = _jsx("div", { className: "aio-popup-highlight-space" });
|
|
647
|
+
let content = _jsx("div", { className: "aio-popup-highlight-html", children: html });
|
|
648
|
+
let arrow = getArrow(dir, limitRef.current.Left, limitRef.current.Width);
|
|
649
|
+
if (dir === 'top') {
|
|
650
|
+
column = _jsxs(_Fragment, { children: [space, content, arrow] });
|
|
651
|
+
}
|
|
652
|
+
else {
|
|
653
|
+
column = _jsxs(_Fragment, { children: [arrow, content, space] });
|
|
654
|
+
}
|
|
655
|
+
return _jsx("div", { className: "aio-popup-highlight-html-container", children: column });
|
|
656
|
+
}
|
|
657
|
+
function click() {
|
|
658
|
+
if (highlight.mouseAccess) {
|
|
659
|
+
return;
|
|
660
|
+
}
|
|
661
|
+
if (highlight.onClick) {
|
|
662
|
+
highlight.onClick();
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
function vMask_node(type) {
|
|
666
|
+
let html = '', size = 0, className = 'aio-popup-highlight-mask';
|
|
667
|
+
let dir = type === 'top' || type === 'bottom' ? 'height' : 'width';
|
|
668
|
+
let limit = limitRef.current;
|
|
669
|
+
if (type === 'top') {
|
|
670
|
+
size = limit.Top;
|
|
671
|
+
if (limit.TopSpace > limit.BottomSpace) {
|
|
672
|
+
html = getHtml('top');
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
else if (type === 'bottom') {
|
|
676
|
+
className += ' aio-popup-highlight-mask-flex';
|
|
677
|
+
if (limit.TopSpace <= limit.BottomSpace) {
|
|
678
|
+
html = getHtml('bottom');
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
else if (type === 'left') {
|
|
682
|
+
size = limit.Left;
|
|
683
|
+
}
|
|
684
|
+
else {
|
|
685
|
+
className += ' aio-popup-highlight-mask-flex';
|
|
686
|
+
}
|
|
687
|
+
return (_jsx("div", { className: className, style: { [dir]: size }, onClick: () => click(), children: html }));
|
|
688
|
+
}
|
|
689
|
+
function focus_node() {
|
|
690
|
+
const cls1 = "aio-popup-highlight-focus-container", cls2 = 'aio-popup-highlight-focus';
|
|
691
|
+
return (_jsx("div", { style: { width: limit.Width }, className: cls1, onClick: click, children: _jsx("div", { className: cls2 }) }));
|
|
692
|
+
}
|
|
693
|
+
function main_node() {
|
|
694
|
+
return _jsxs("div", { className: "aio-popup-highlight-main", style: { height: limit.Height }, children: [vMask_node('left'), focus_node(), vMask_node('right')] });
|
|
695
|
+
}
|
|
696
|
+
function getStyle() { return { pointerEvents: highlight.mouseAccess ? 'none' : 'all' }; }
|
|
697
|
+
const attrs = AddToAttrs(highlight.attrs, { className: 'aio-popup-highlight', style: getStyle() });
|
|
698
|
+
return (_jsxs("div", Object.assign({}, attrs, { children: [vMask_node('top'), main_node(), vMask_node('bottom')] })));
|
|
699
|
+
};
|
|
700
|
+
function getHLLimit(highlight) {
|
|
701
|
+
const { padding = 6, dom } = highlight;
|
|
702
|
+
let offset = dom.offset();
|
|
703
|
+
let left = offset.left - window.pageXOffset;
|
|
704
|
+
let top = offset.top - window.pageYOffset;
|
|
705
|
+
let pageHeight = window.innerHeight;
|
|
706
|
+
let width = dom.outerWidth();
|
|
707
|
+
let height = dom.outerHeight();
|
|
708
|
+
let Top = top - 1 * padding;
|
|
709
|
+
let Left = left - 1 * padding;
|
|
710
|
+
let Width = width + 2 * padding;
|
|
711
|
+
let Height = height + 2 * padding;
|
|
712
|
+
let TopSpace = top;
|
|
713
|
+
let BottomSpace = pageHeight - (top + height);
|
|
714
|
+
let res = { Left, Top, Width, Height, TopSpace, BottomSpace };
|
|
715
|
+
return res;
|
|
716
|
+
}
|
|
717
|
+
function getEasing(highlight) {
|
|
718
|
+
const { easing } = highlight;
|
|
719
|
+
var easingNames = [
|
|
720
|
+
'linear',
|
|
721
|
+
'easeInQuad', //1
|
|
722
|
+
'easeInSine', //5
|
|
723
|
+
'easeInCirc', //7
|
|
724
|
+
'easeInBack', //8
|
|
725
|
+
'easeOutQuad', //9
|
|
726
|
+
'easeOutSine', //13
|
|
727
|
+
'easeOutCirc', //15
|
|
728
|
+
'easeInOutQuad', //18
|
|
729
|
+
'easeInOutSine', //22
|
|
730
|
+
'easeInOutBack', //25
|
|
731
|
+
'easeOutBounce', //27
|
|
732
|
+
];
|
|
733
|
+
if (typeof easing === 'number') {
|
|
734
|
+
let res = easingNames[easing];
|
|
735
|
+
return res || easingNames[0];
|
|
736
|
+
}
|
|
737
|
+
return easing;
|
|
738
|
+
}
|
|
739
|
+
const InfoSvg = () => {
|
|
740
|
+
const d = "M11,9H13V7H11M12,20C7.59,20 4,16.41 4,12C4,7.59 7.59,4 12,4C16.41,4 20,7.59 20,12C20,16.41 16.41,20 12,20M12,2A10,10 0 0,0 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12A10,10 0 0,0 12,2M11,17H13V11H11V17Z";
|
|
741
|
+
return (_jsx("svg", { viewBox: "0 0 24 24", role: "presentation", style: { width: '1.2rem', height: '1.2rem' }, children: _jsx("path", { d: d, style: { fill: 'currentcolor' } }) }));
|
|
742
|
+
};
|
|
743
|
+
const SuccessSvg = () => {
|
|
744
|
+
const d = "M12 2C6.5 2 2 6.5 2 12S6.5 22 12 22 22 17.5 22 12 17.5 2 12 2M12 20C7.59 20 4 16.41 4 12S7.59 4 12 4 20 7.59 20 12 16.41 20 12 20M16.59 7.58L10 14.17L7.41 11.59L6 13L10 17L18 9L16.59 7.58Z";
|
|
745
|
+
return (_jsx("svg", { viewBox: "0 0 24 24", role: "presentation", style: { width: '1.2rem', height: '1.2rem' }, children: _jsx("path", { d: d, style: { fill: 'currentcolor' } }) }));
|
|
746
|
+
};
|
|
747
|
+
function getBound(dom) {
|
|
748
|
+
try {
|
|
749
|
+
const res = dom.getBoundingClientRect();
|
|
750
|
+
return { width: res.width, height: res.height, left: res.left, top: res.top, bottom: res.bottom, right: res.right };
|
|
751
|
+
}
|
|
752
|
+
catch (_a) {
|
|
753
|
+
return { width: 0, height: 0, left: 0, top: 0, bottom: 0, right: 0 };
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
export class Loading {
|
|
757
|
+
constructor(loader) {
|
|
758
|
+
this.loader = '0';
|
|
759
|
+
this.getLoader_0 = () => {
|
|
760
|
+
return (`
|
|
761
|
+
<div class="aio-loading-container-0">
|
|
762
|
+
<div class="aio-loading-0">
|
|
763
|
+
${new Array(5).fill(0).map((o, i) => this.getLoaderItem_0(`0.${i}`)).join(' ')}
|
|
764
|
+
</div>
|
|
765
|
+
</div>
|
|
766
|
+
`);
|
|
767
|
+
};
|
|
768
|
+
this.getLoaderItem_0 = (ease) => {
|
|
769
|
+
return `<div class="aio-loading-item-0" style="animation: 1s ease-in-out ${ease}s infinite normal none running aioloading0;"></div>`;
|
|
770
|
+
};
|
|
771
|
+
this.getLoader = (id) => {
|
|
772
|
+
let content = '';
|
|
773
|
+
if (this.loader === '0') {
|
|
774
|
+
content = this.getLoader_0();
|
|
775
|
+
}
|
|
776
|
+
else if (typeof this.loader === 'string') {
|
|
777
|
+
content = this.loader;
|
|
778
|
+
}
|
|
779
|
+
return (`<div class="aio-loading" id="aio-loading-${id}">${content}</div>`);
|
|
780
|
+
};
|
|
781
|
+
this.show = (id, parentSelector) => {
|
|
782
|
+
parentSelector = parentSelector || 'body';
|
|
783
|
+
let loadingStr = this.getLoader(id);
|
|
784
|
+
let parent = document.querySelector(parentSelector);
|
|
785
|
+
if (parent) {
|
|
786
|
+
parent.insertAdjacentHTML('beforeend', loadingStr);
|
|
787
|
+
}
|
|
788
|
+
};
|
|
789
|
+
this.hide = (id) => {
|
|
790
|
+
let loadingDom = document.getElementById('aio-loading-' + id);
|
|
791
|
+
if (!loadingDom) {
|
|
792
|
+
loadingDom = document.querySelector('.aio-loading');
|
|
793
|
+
}
|
|
794
|
+
if (loadingDom) {
|
|
795
|
+
loadingDom.remove();
|
|
796
|
+
}
|
|
797
|
+
};
|
|
798
|
+
if (typeof loader === 'string') {
|
|
799
|
+
this.loader = loader;
|
|
800
|
+
}
|
|
801
|
+
}
|
|
802
|
+
}
|