@monstermann/signals-modal 0.3.0 → 0.3.2
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.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/scroll/withCloseOnScroll.d.ts +10 -0
- package/dist/scroll/withCloseOnScroll.js +41 -0
- package/dist/status/onModalClosed.d.ts +2 -2
- package/dist/status/onModalClosing.d.ts +2 -2
- package/dist/status/onModalOpened.d.ts +2 -2
- package/dist/utils/syncModalGroupsToBody.js +1 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -27,6 +27,7 @@ import { getModalPlacement } from "./position/getModalPlacement.js";
|
|
|
27
27
|
import { ModalPosition, withPosition } from "./position/withPosition.js";
|
|
28
28
|
import { getModalPosition } from "./position/getModalPosition.js";
|
|
29
29
|
import { withBoundary } from "./position/withBoundary.js";
|
|
30
|
+
import { withCloseOnScroll } from "./scroll/withCloseOnScroll.js";
|
|
30
31
|
import { closeAllModals } from "./status/closeAllModals.js";
|
|
31
32
|
import { closeLastModal } from "./status/closeLastModal.js";
|
|
32
33
|
import { closeModal } from "./status/closeModal.js";
|
|
@@ -59,4 +60,4 @@ import { withModalStatus } from "./status/withModalStatus.js";
|
|
|
59
60
|
import { closeLastModalOnClickOutside } from "./utils/closeLastModalOnClickOutside.js";
|
|
60
61
|
import { closeLastModalOnEsc } from "./utils/closeLastModalOnEsc.js";
|
|
61
62
|
import { syncModalGroupsToBody } from "./utils/syncModalGroupsToBody.js";
|
|
62
|
-
export { ModalContext, ModalPlacement, ModalPlacementOption, ModalPosition, ModalStatus, closeAllModals, closeLastModal, closeLastModalOnClickOutside, closeLastModalOnEsc, closeModal, createModal, currentModal, getAnchorElement, getAnchorMeasurement, getClosedModals, getClosingModals, getDialogs, getFloatingElement, getFloatingMeasurement, getGroupsForModal, getModalPlacement, getModalPosition, getModalStatus, getModalsForGroup, getOpenModals, getOpenedModals, getOpeningModals, getPopovers, getTooltips, getVisibleModals, isAnyModalClosed, isAnyModalClosing, isAnyModalOpen, isAnyModalOpened, isAnyModalOpening, isAnyModalVisible, isDialog, isModalClosed, isModalClosing, isModalInGroup, isModalOpen, isModalOpened, isModalOpening, isModalVisible, isPopover, isTooltip, modalGroups, onModalClosed, onModalClosing, onModalDisposed, onModalOpened, onModalOpening, openModal, setAnchorElement, setFloatingElement, setModalStatus, syncModalGroupsToBody, withAnchorElement, withAnchorMeasurement, withBoundary, withFloatingElement, withFloatingMeasurement, withModalGroups, withModalStatus, withMouseAnchor, withPlacement, withPosition };
|
|
63
|
+
export { ModalContext, ModalPlacement, ModalPlacementOption, ModalPosition, ModalStatus, closeAllModals, closeLastModal, closeLastModalOnClickOutside, closeLastModalOnEsc, closeModal, createModal, currentModal, getAnchorElement, getAnchorMeasurement, getClosedModals, getClosingModals, getDialogs, getFloatingElement, getFloatingMeasurement, getGroupsForModal, getModalPlacement, getModalPosition, getModalStatus, getModalsForGroup, getOpenModals, getOpenedModals, getOpeningModals, getPopovers, getTooltips, getVisibleModals, isAnyModalClosed, isAnyModalClosing, isAnyModalOpen, isAnyModalOpened, isAnyModalOpening, isAnyModalVisible, isDialog, isModalClosed, isModalClosing, isModalInGroup, isModalOpen, isModalOpened, isModalOpening, isModalVisible, isPopover, isTooltip, modalGroups, onModalClosed, onModalClosing, onModalDisposed, onModalOpened, onModalOpening, openModal, setAnchorElement, setFloatingElement, setModalStatus, syncModalGroupsToBody, withAnchorElement, withAnchorMeasurement, withBoundary, withCloseOnScroll, withFloatingElement, withFloatingMeasurement, withModalGroups, withModalStatus, withMouseAnchor, withPlacement, withPosition };
|
package/dist/index.js
CHANGED
|
@@ -31,6 +31,7 @@ import { getModalPosition } from "./position/getModalPosition.js";
|
|
|
31
31
|
import { withBoundary } from "./position/withBoundary.js";
|
|
32
32
|
import { withPlacement } from "./position/withPlacement.js";
|
|
33
33
|
import { withPosition } from "./position/withPosition.js";
|
|
34
|
+
import { withCloseOnScroll } from "./scroll/withCloseOnScroll.js";
|
|
34
35
|
import { closeAllModals } from "./status/closeAllModals.js";
|
|
35
36
|
import { closeLastModal } from "./status/closeLastModal.js";
|
|
36
37
|
import { getClosedModals } from "./status/getClosedModals.js";
|
|
@@ -59,4 +60,4 @@ import { closeLastModalOnClickOutside } from "./utils/closeLastModalOnClickOutsi
|
|
|
59
60
|
import { closeLastModalOnEsc } from "./utils/closeLastModalOnEsc.js";
|
|
60
61
|
import { syncModalGroupsToBody } from "./utils/syncModalGroupsToBody.js";
|
|
61
62
|
|
|
62
|
-
export { closeAllModals, closeLastModal, closeLastModalOnClickOutside, closeLastModalOnEsc, closeModal, createModal, currentModal, getAnchorElement, getAnchorMeasurement, getClosedModals, getClosingModals, getDialogs, getFloatingElement, getFloatingMeasurement, getGroupsForModal, getModalPlacement, getModalPosition, getModalStatus, getModalsForGroup, getOpenModals, getOpenedModals, getOpeningModals, getPopovers, getTooltips, getVisibleModals, isAnyModalClosed, isAnyModalClosing, isAnyModalOpen, isAnyModalOpened, isAnyModalOpening, isAnyModalVisible, isDialog, isModalClosed, isModalClosing, isModalInGroup, isModalOpen, isModalOpened, isModalOpening, isModalVisible, isPopover, isTooltip, modalGroups, onModalClosed, onModalClosing, onModalDisposed, onModalOpened, onModalOpening, openModal, setAnchorElement, setFloatingElement, setModalStatus, syncModalGroupsToBody, withAnchorElement, withAnchorMeasurement, withBoundary, withFloatingElement, withFloatingMeasurement, withModalGroups, withModalStatus, withMouseAnchor, withPlacement, withPosition };
|
|
63
|
+
export { closeAllModals, closeLastModal, closeLastModalOnClickOutside, closeLastModalOnEsc, closeModal, createModal, currentModal, getAnchorElement, getAnchorMeasurement, getClosedModals, getClosingModals, getDialogs, getFloatingElement, getFloatingMeasurement, getGroupsForModal, getModalPlacement, getModalPosition, getModalStatus, getModalsForGroup, getOpenModals, getOpenedModals, getOpeningModals, getPopovers, getTooltips, getVisibleModals, isAnyModalClosed, isAnyModalClosing, isAnyModalOpen, isAnyModalOpened, isAnyModalOpening, isAnyModalVisible, isDialog, isModalClosed, isModalClosing, isModalInGroup, isModalOpen, isModalOpened, isModalOpening, isModalVisible, isPopover, isTooltip, modalGroups, onModalClosed, onModalClosing, onModalDisposed, onModalOpened, onModalOpening, openModal, setAnchorElement, setFloatingElement, setModalStatus, syncModalGroupsToBody, withAnchorElement, withAnchorMeasurement, withBoundary, withCloseOnScroll, withFloatingElement, withFloatingMeasurement, withModalGroups, withModalStatus, withMouseAnchor, withPlacement, withPosition };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ModalStatus } from "../status/types.js";
|
|
2
|
+
import { Reactive } from "@monstermann/signals";
|
|
3
|
+
|
|
4
|
+
//#region src/scroll/withCloseOnScroll.d.ts
|
|
5
|
+
declare function withCloseOnScroll(options: {
|
|
6
|
+
$anchorElement: Reactive<HTMLElement | null>;
|
|
7
|
+
$status: Reactive<ModalStatus>;
|
|
8
|
+
}): void;
|
|
9
|
+
//#endregion
|
|
10
|
+
export { withCloseOnScroll };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { closeModal } from "../status/closeModal.js";
|
|
2
|
+
import { currentModal } from "../createModal.js";
|
|
3
|
+
import { INTERNAL, effect } from "@monstermann/signals";
|
|
4
|
+
|
|
5
|
+
//#region src/scroll/withCloseOnScroll.ts
|
|
6
|
+
const meta = {
|
|
7
|
+
path: "@signals-modal/scroll/withCloseOnScroll.ts",
|
|
8
|
+
line: 13,
|
|
9
|
+
name: "withCloseOnScroll"
|
|
10
|
+
};
|
|
11
|
+
function withCloseOnScroll(options) {
|
|
12
|
+
const modal = currentModal();
|
|
13
|
+
const onScroll = () => closeModal(modal.key);
|
|
14
|
+
modal.onDispose(effect(() => {
|
|
15
|
+
const element = options.$anchorElement();
|
|
16
|
+
const status = options.$status();
|
|
17
|
+
if (!element) return;
|
|
18
|
+
if (status === "closing" || status === "closed") return;
|
|
19
|
+
const overflowElements = getScrollableAncestors(element);
|
|
20
|
+
for (const element$1 of overflowElements) element$1.addEventListener("scroll", onScroll, { passive: true });
|
|
21
|
+
return () => {
|
|
22
|
+
for (const element$1 of overflowElements) element$1.removeEventListener("scroll", onScroll);
|
|
23
|
+
};
|
|
24
|
+
}, INTERNAL, meta));
|
|
25
|
+
}
|
|
26
|
+
function isOverflowElement(element) {
|
|
27
|
+
const { display, overflow, overflowX, overflowY } = getComputedStyle(element);
|
|
28
|
+
return /auto|scroll|overlay|hidden|clip/.test(overflow + overflowY + overflowX) && !["inline", "contents"].includes(display);
|
|
29
|
+
}
|
|
30
|
+
function getScrollableAncestors(element) {
|
|
31
|
+
const scrollableAncestors = [];
|
|
32
|
+
let pivot = element.parentElement;
|
|
33
|
+
while (pivot) {
|
|
34
|
+
if (isOverflowElement(pivot)) scrollableAncestors.push(pivot);
|
|
35
|
+
pivot = pivot.parentElement;
|
|
36
|
+
}
|
|
37
|
+
return scrollableAncestors;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
//#endregion
|
|
41
|
+
export { withCloseOnScroll };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as _monstermann_signals1 from "@monstermann/signals";
|
|
2
2
|
|
|
3
3
|
//#region src/status/onModalClosed.d.ts
|
|
4
|
-
declare const onModalClosed:
|
|
4
|
+
declare const onModalClosed: _monstermann_signals1.Emitter<string>;
|
|
5
5
|
//#endregion
|
|
6
6
|
export { onModalClosed };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as _monstermann_signals0 from "@monstermann/signals";
|
|
2
2
|
|
|
3
3
|
//#region src/status/onModalClosing.d.ts
|
|
4
|
-
declare const onModalClosing:
|
|
4
|
+
declare const onModalClosing: _monstermann_signals0.Emitter<string>;
|
|
5
5
|
//#endregion
|
|
6
6
|
export { onModalClosing };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as _monstermann_signals2 from "@monstermann/signals";
|
|
2
2
|
|
|
3
3
|
//#region src/status/onModalOpened.d.ts
|
|
4
|
-
declare const onModalOpened:
|
|
4
|
+
declare const onModalOpened: _monstermann_signals2.Emitter<string>;
|
|
5
5
|
//#endregion
|
|
6
6
|
export { onModalOpened };
|