@lerx/promise-modal 0.2.5 → 0.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +5 -12
- package/dist/index.mjs +4 -11
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -6,12 +6,11 @@ const convert = require('@winglet/common-utils/convert');
|
|
|
6
6
|
const hook = require('@winglet/react-utils/hook');
|
|
7
7
|
const hash = require('@winglet/common-utils/hash');
|
|
8
8
|
const lib = require('@winglet/common-utils/lib');
|
|
9
|
-
const
|
|
10
|
-
const
|
|
9
|
+
const styleManager = require('@winglet/style-utils/style-manager');
|
|
10
|
+
const util = require('@winglet/style-utils/util');
|
|
11
11
|
const reactDom = require('react-dom');
|
|
12
12
|
const array = require('@winglet/common-utils/array');
|
|
13
13
|
const hoc = require('@winglet/react-utils/hoc');
|
|
14
|
-
const classNames = require('@winglet/style-utils/classNames');
|
|
15
14
|
const filter = require('@winglet/common-utils/filter');
|
|
16
15
|
const render = require('@winglet/react-utils/render');
|
|
17
16
|
const console = require('@winglet/common-utils/console');
|
|
@@ -52,7 +51,7 @@ class ModalManager {
|
|
|
52
51
|
static #styleManager = styleManager.styleManagerFactory(ModalManager.#scope);
|
|
53
52
|
static #styleSheetDefinition = new Map();
|
|
54
53
|
static defineStyleSheet(styleId, css) {
|
|
55
|
-
ModalManager.#styleSheetDefinition.set(styleId,
|
|
54
|
+
ModalManager.#styleSheetDefinition.set(styleId, util.compressCss(css));
|
|
56
55
|
}
|
|
57
56
|
static applyStyleSheet() {
|
|
58
57
|
for (const [styleId, css] of ModalManager.#styleSheetDefinition)
|
|
@@ -678,10 +677,7 @@ const BackgroundFrame = ({ modalId, onChangeOrder, }) => {
|
|
|
678
677
|
const Background = react.useMemo(() => modal?.BackgroundComponent || BackgroundComponent, [BackgroundComponent, modal]);
|
|
679
678
|
if (!modal)
|
|
680
679
|
return null;
|
|
681
|
-
return (jsxRuntime.jsx("div", { className:
|
|
682
|
-
[active$1]: modal.closeOnBackdropClick && modal.visible,
|
|
683
|
-
[visible$1]: modal.manualDestroy ? modal.alive : modal.visible,
|
|
684
|
-
}), onClick: handleClose, children: Background && (jsxRuntime.jsx(Background, { id: modal.id, type: modal.type, alive: modal.alive, visible: modal.visible, initiator: modal.initiator, manualDestroy: modal.manualDestroy, closeOnBackdropClick: modal.closeOnBackdropClick, background: modal.background, onChange: onChange, onConfirm: onConfirm, onClose: onClose, onDestroy: onDestroy, onChangeOrder: onChangeOrder, context: userDefinedContext })) }));
|
|
680
|
+
return (jsxRuntime.jsx("div", { className: util.cxLite(background, modal.closeOnBackdropClick && modal.visible && active$1, (modal.manualDestroy ? modal.alive : modal.visible) && visible$1), onClick: handleClose, children: Background && (jsxRuntime.jsx(Background, { id: modal.id, type: modal.type, alive: modal.alive, visible: modal.visible, initiator: modal.initiator, manualDestroy: modal.manualDestroy, closeOnBackdropClick: modal.closeOnBackdropClick, background: modal.background, onChange: onChange, onConfirm: onConfirm, onClose: onClose, onDestroy: onDestroy, onChangeOrder: onChangeOrder, context: userDefinedContext })) }));
|
|
685
681
|
};
|
|
686
682
|
|
|
687
683
|
const AlertInner = react.memo(({ modal, handlers }) => {
|
|
@@ -792,10 +788,7 @@ const ForegroundFrame = ({ modalId, onChangeOrder, }) => {
|
|
|
792
788
|
const Foreground = react.useMemo(() => modal?.ForegroundComponent || ForegroundComponent, [ForegroundComponent, modal]);
|
|
793
789
|
if (!modal)
|
|
794
790
|
return null;
|
|
795
|
-
return (jsxRuntime.jsx("div", { className:
|
|
796
|
-
[active]: modal.visible,
|
|
797
|
-
[visible]: modal.manualDestroy ? modal.alive : modal.visible,
|
|
798
|
-
}), children: jsxRuntime.jsxs(Foreground, { id: modal.id, type: modal.type, alive: modal.alive, visible: modal.visible, initiator: modal.initiator, manualDestroy: modal.manualDestroy, closeOnBackdropClick: modal.closeOnBackdropClick, background: modal.background, onChange: onChange, onConfirm: onConfirm, onClose: onClose, onDestroy: onDestroy, onChangeOrder: onChangeOrder, context: userDefinedContext, children: [modal.type === 'alert' && (jsxRuntime.jsx(AlertInner, { modal: modal, handlers: { onConfirm } })), modal.type === 'confirm' && (jsxRuntime.jsx(ConfirmInner, { modal: modal, handlers: { onConfirm, onClose } })), modal.type === 'prompt' && (jsxRuntime.jsx(PromptInner, { modal: modal, handlers: { onChange, onConfirm, onClose } }))] }) }));
|
|
791
|
+
return (jsxRuntime.jsx("div", { className: util.cxLite(foreground, modal.visible && active, (modal.manualDestroy ? modal.alive : modal.visible) && visible), children: jsxRuntime.jsxs(Foreground, { id: modal.id, type: modal.type, alive: modal.alive, visible: modal.visible, initiator: modal.initiator, manualDestroy: modal.manualDestroy, closeOnBackdropClick: modal.closeOnBackdropClick, background: modal.background, onChange: onChange, onConfirm: onConfirm, onClose: onClose, onDestroy: onDestroy, onChangeOrder: onChangeOrder, context: userDefinedContext, children: [modal.type === 'alert' && (jsxRuntime.jsx(AlertInner, { modal: modal, handlers: { onConfirm } })), modal.type === 'confirm' && (jsxRuntime.jsx(ConfirmInner, { modal: modal, handlers: { onConfirm, onClose } })), modal.type === 'prompt' && (jsxRuntime.jsx(PromptInner, { modal: modal, handlers: { onChange, onConfirm, onClose } }))] }) }));
|
|
799
792
|
};
|
|
800
793
|
|
|
801
794
|
const useSubscribeModal = (modal) => {
|
package/dist/index.mjs
CHANGED
|
@@ -4,12 +4,11 @@ import { convertMsFromDuration } from '@winglet/common-utils/convert';
|
|
|
4
4
|
import { useReference, useOnMountLayout, useHandle, useVersion, useOnMount } from '@winglet/react-utils/hook';
|
|
5
5
|
import { polynomialHash } from '@winglet/common-utils/hash';
|
|
6
6
|
import { getRandomString, counterFactory } from '@winglet/common-utils/lib';
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
7
|
+
import { styleManagerFactory, destroyScope } from '@winglet/style-utils/style-manager';
|
|
8
|
+
import { compressCss, cxLite } from '@winglet/style-utils/util';
|
|
9
9
|
import { createPortal } from 'react-dom';
|
|
10
10
|
import { map } from '@winglet/common-utils/array';
|
|
11
11
|
import { withErrorBoundary } from '@winglet/react-utils/hoc';
|
|
12
|
-
import { cx } from '@winglet/style-utils/classNames';
|
|
13
12
|
import { isString, isFunction } from '@winglet/common-utils/filter';
|
|
14
13
|
import { renderComponent } from '@winglet/react-utils/render';
|
|
15
14
|
import { printError } from '@winglet/common-utils/console';
|
|
@@ -676,10 +675,7 @@ const BackgroundFrame = ({ modalId, onChangeOrder, }) => {
|
|
|
676
675
|
const Background = useMemo(() => modal?.BackgroundComponent || BackgroundComponent, [BackgroundComponent, modal]);
|
|
677
676
|
if (!modal)
|
|
678
677
|
return null;
|
|
679
|
-
return (jsx("div", { className:
|
|
680
|
-
[active$1]: modal.closeOnBackdropClick && modal.visible,
|
|
681
|
-
[visible$1]: modal.manualDestroy ? modal.alive : modal.visible,
|
|
682
|
-
}), onClick: handleClose, children: Background && (jsx(Background, { id: modal.id, type: modal.type, alive: modal.alive, visible: modal.visible, initiator: modal.initiator, manualDestroy: modal.manualDestroy, closeOnBackdropClick: modal.closeOnBackdropClick, background: modal.background, onChange: onChange, onConfirm: onConfirm, onClose: onClose, onDestroy: onDestroy, onChangeOrder: onChangeOrder, context: userDefinedContext })) }));
|
|
678
|
+
return (jsx("div", { className: cxLite(background, modal.closeOnBackdropClick && modal.visible && active$1, (modal.manualDestroy ? modal.alive : modal.visible) && visible$1), onClick: handleClose, children: Background && (jsx(Background, { id: modal.id, type: modal.type, alive: modal.alive, visible: modal.visible, initiator: modal.initiator, manualDestroy: modal.manualDestroy, closeOnBackdropClick: modal.closeOnBackdropClick, background: modal.background, onChange: onChange, onConfirm: onConfirm, onClose: onClose, onDestroy: onDestroy, onChangeOrder: onChangeOrder, context: userDefinedContext })) }));
|
|
683
679
|
};
|
|
684
680
|
|
|
685
681
|
const AlertInner = memo(({ modal, handlers }) => {
|
|
@@ -790,10 +786,7 @@ const ForegroundFrame = ({ modalId, onChangeOrder, }) => {
|
|
|
790
786
|
const Foreground = useMemo(() => modal?.ForegroundComponent || ForegroundComponent, [ForegroundComponent, modal]);
|
|
791
787
|
if (!modal)
|
|
792
788
|
return null;
|
|
793
|
-
return (jsx("div", { className:
|
|
794
|
-
[active]: modal.visible,
|
|
795
|
-
[visible]: modal.manualDestroy ? modal.alive : modal.visible,
|
|
796
|
-
}), children: jsxs(Foreground, { id: modal.id, type: modal.type, alive: modal.alive, visible: modal.visible, initiator: modal.initiator, manualDestroy: modal.manualDestroy, closeOnBackdropClick: modal.closeOnBackdropClick, background: modal.background, onChange: onChange, onConfirm: onConfirm, onClose: onClose, onDestroy: onDestroy, onChangeOrder: onChangeOrder, context: userDefinedContext, children: [modal.type === 'alert' && (jsx(AlertInner, { modal: modal, handlers: { onConfirm } })), modal.type === 'confirm' && (jsx(ConfirmInner, { modal: modal, handlers: { onConfirm, onClose } })), modal.type === 'prompt' && (jsx(PromptInner, { modal: modal, handlers: { onChange, onConfirm, onClose } }))] }) }));
|
|
789
|
+
return (jsx("div", { className: cxLite(foreground, modal.visible && active, (modal.manualDestroy ? modal.alive : modal.visible) && visible), children: jsxs(Foreground, { id: modal.id, type: modal.type, alive: modal.alive, visible: modal.visible, initiator: modal.initiator, manualDestroy: modal.manualDestroy, closeOnBackdropClick: modal.closeOnBackdropClick, background: modal.background, onChange: onChange, onConfirm: onConfirm, onClose: onClose, onDestroy: onDestroy, onChangeOrder: onChangeOrder, context: userDefinedContext, children: [modal.type === 'alert' && (jsx(AlertInner, { modal: modal, handlers: { onConfirm } })), modal.type === 'confirm' && (jsx(ConfirmInner, { modal: modal, handlers: { onConfirm, onClose } })), modal.type === 'prompt' && (jsx(PromptInner, { modal: modal, handlers: { onChange, onConfirm, onClose } }))] }) }));
|
|
797
790
|
};
|
|
798
791
|
|
|
799
792
|
const useSubscribeModal = (modal) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lerx/promise-modal",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.6",
|
|
4
4
|
"description": "Universal React modal utility that can be used outside React components with promise-based results for alert, confirm, and prompt modals",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -67,7 +67,7 @@
|
|
|
67
67
|
"dependencies": {
|
|
68
68
|
"@winglet/common-utils": "^0.2.2",
|
|
69
69
|
"@winglet/react-utils": "^0.2.4",
|
|
70
|
-
"@winglet/style-utils": "^0.2.
|
|
70
|
+
"@winglet/style-utils": "^0.2.2"
|
|
71
71
|
},
|
|
72
72
|
"devDependencies": {
|
|
73
73
|
"@chromatic-com/storybook": "^3.2.6",
|