@lerx/promise-modal 0.2.4 → 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 -18
- package/dist/index.mjs +4 -17
- 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)
|
|
@@ -676,15 +675,9 @@ const BackgroundFrame = ({ modalId, onChangeOrder, }) => {
|
|
|
676
675
|
event.stopPropagation();
|
|
677
676
|
}, [modal, onClose]);
|
|
678
677
|
const Background = react.useMemo(() => modal?.BackgroundComponent || BackgroundComponent, [BackgroundComponent, modal]);
|
|
679
|
-
const className = react.useMemo(() => modal
|
|
680
|
-
? classNames.cx(background, {
|
|
681
|
-
[active$1]: modal.closeOnBackdropClick && modal.visible,
|
|
682
|
-
[visible$1]: modal.manualDestroy ? modal.alive : modal.visible,
|
|
683
|
-
})
|
|
684
|
-
: undefined, [modal]);
|
|
685
678
|
if (!modal)
|
|
686
679
|
return null;
|
|
687
|
-
return (jsxRuntime.jsx("div", { className:
|
|
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 })) }));
|
|
688
681
|
};
|
|
689
682
|
|
|
690
683
|
const AlertInner = react.memo(({ modal, handlers }) => {
|
|
@@ -793,15 +786,9 @@ const ForegroundFrame = ({ modalId, onChangeOrder, }) => {
|
|
|
793
786
|
const { context: userDefinedContext } = useUserDefinedContext();
|
|
794
787
|
const { modal, onChange, onConfirm, onClose, onDestroy } = useModal(modalId);
|
|
795
788
|
const Foreground = react.useMemo(() => modal?.ForegroundComponent || ForegroundComponent, [ForegroundComponent, modal]);
|
|
796
|
-
const className = react.useMemo(() => modal
|
|
797
|
-
? classNames.cx(foreground, {
|
|
798
|
-
[active]: modal.visible,
|
|
799
|
-
[visible]: modal.manualDestroy ? modal.alive : modal.visible,
|
|
800
|
-
})
|
|
801
|
-
: undefined, [modal]);
|
|
802
789
|
if (!modal)
|
|
803
790
|
return null;
|
|
804
|
-
return (jsxRuntime.jsx("div", { className:
|
|
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 } }))] }) }));
|
|
805
792
|
};
|
|
806
793
|
|
|
807
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';
|
|
@@ -674,15 +673,9 @@ const BackgroundFrame = ({ modalId, onChangeOrder, }) => {
|
|
|
674
673
|
event.stopPropagation();
|
|
675
674
|
}, [modal, onClose]);
|
|
676
675
|
const Background = useMemo(() => modal?.BackgroundComponent || BackgroundComponent, [BackgroundComponent, modal]);
|
|
677
|
-
const className = useMemo(() => modal
|
|
678
|
-
? cx(background, {
|
|
679
|
-
[active$1]: modal.closeOnBackdropClick && modal.visible,
|
|
680
|
-
[visible$1]: modal.manualDestroy ? modal.alive : modal.visible,
|
|
681
|
-
})
|
|
682
|
-
: undefined, [modal]);
|
|
683
676
|
if (!modal)
|
|
684
677
|
return null;
|
|
685
|
-
return (jsx("div", { className:
|
|
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 })) }));
|
|
686
679
|
};
|
|
687
680
|
|
|
688
681
|
const AlertInner = memo(({ modal, handlers }) => {
|
|
@@ -791,15 +784,9 @@ const ForegroundFrame = ({ modalId, onChangeOrder, }) => {
|
|
|
791
784
|
const { context: userDefinedContext } = useUserDefinedContext();
|
|
792
785
|
const { modal, onChange, onConfirm, onClose, onDestroy } = useModal(modalId);
|
|
793
786
|
const Foreground = useMemo(() => modal?.ForegroundComponent || ForegroundComponent, [ForegroundComponent, modal]);
|
|
794
|
-
const className = useMemo(() => modal
|
|
795
|
-
? cx(foreground, {
|
|
796
|
-
[active]: modal.visible,
|
|
797
|
-
[visible]: modal.manualDestroy ? modal.alive : modal.visible,
|
|
798
|
-
})
|
|
799
|
-
: undefined, [modal]);
|
|
800
787
|
if (!modal)
|
|
801
788
|
return null;
|
|
802
|
-
return (jsx("div", { className:
|
|
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 } }))] }) }));
|
|
803
790
|
};
|
|
804
791
|
|
|
805
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",
|