@monstermann/signals-modal 0.4.3 → 0.4.5
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/README.md +2011 -0
- package/dist/anchor/getAnchorElement.d.mts +30 -0
- package/dist/anchor/getAnchorElement.mjs +30 -0
- package/dist/anchor/getAnchorMeasurement.d.mts +39 -1
- package/dist/anchor/getAnchorMeasurement.mjs +37 -0
- package/dist/anchor/setAnchorElement.d.mts +26 -0
- package/dist/anchor/setAnchorElement.mjs +26 -0
- package/dist/anchor/withAnchorElement.d.mts +31 -0
- package/dist/anchor/withAnchorElement.mjs +31 -1
- package/dist/anchor/withAnchorMeasurement.d.mts +44 -1
- package/dist/anchor/withAnchorMeasurement.mjs +45 -3
- package/dist/anchor/withMouseAnchor.d.mts +35 -1
- package/dist/anchor/withMouseAnchor.mjs +36 -3
- package/dist/createModal.d.mts +29 -0
- package/dist/createModal.mjs +29 -0
- package/dist/floating/getFloatingElement.d.mts +30 -0
- package/dist/floating/getFloatingElement.mjs +30 -0
- package/dist/floating/getFloatingMeasurement.d.mts +39 -1
- package/dist/floating/getFloatingMeasurement.mjs +37 -0
- package/dist/floating/setFloatingElement.d.mts +26 -0
- package/dist/floating/setFloatingElement.mjs +26 -0
- package/dist/floating/withFloatingElement.d.mts +31 -0
- package/dist/floating/withFloatingElement.mjs +31 -1
- package/dist/floating/withFloatingMeasurement.d.mts +42 -1
- package/dist/floating/withFloatingMeasurement.mjs +43 -3
- package/dist/groups/getDialogs.d.mts +29 -0
- package/dist/groups/getDialogs.mjs +29 -0
- package/dist/groups/getGroupsForModal.d.mts +29 -0
- package/dist/groups/getGroupsForModal.mjs +29 -0
- package/dist/groups/getModalsForGroup.d.mts +29 -0
- package/dist/groups/getModalsForGroup.mjs +29 -0
- package/dist/groups/getPopovers.d.mts +29 -0
- package/dist/groups/getPopovers.mjs +29 -0
- package/dist/groups/getTooltips.d.mts +29 -0
- package/dist/groups/getTooltips.mjs +29 -0
- package/dist/groups/isDialog.d.mts +29 -0
- package/dist/groups/isDialog.mjs +29 -0
- package/dist/groups/isModalInGroup.d.mts +29 -0
- package/dist/groups/isModalInGroup.mjs +29 -0
- package/dist/groups/isPopover.d.mts +29 -0
- package/dist/groups/isPopover.mjs +29 -0
- package/dist/groups/isTooltip.d.mts +29 -0
- package/dist/groups/isTooltip.mjs +29 -0
- package/dist/groups/modalGroups.mjs +42 -0
- package/dist/groups/withModalGroups.d.mts +30 -0
- package/dist/groups/withModalGroups.mjs +30 -1
- package/dist/position/getModalPlacement.d.mts +50 -0
- package/dist/position/getModalPlacement.mjs +49 -0
- package/dist/position/getModalPosition.d.mts +59 -0
- package/dist/position/getModalPosition.mjs +58 -0
- package/dist/position/withBoundary.d.mts +32 -1
- package/dist/position/withBoundary.mjs +33 -3
- package/dist/position/withPlacement.d.mts +78 -1
- package/dist/position/withPlacement.mjs +78 -1
- package/dist/position/withPosition.d.mts +67 -1
- package/dist/position/withPosition.mjs +68 -2
- package/dist/scroll/withCloseOnScroll.d.mts +37 -0
- package/dist/scroll/withCloseOnScroll.mjs +37 -1
- package/dist/status/closeAllModals.d.mts +33 -0
- package/dist/status/closeAllModals.mjs +33 -0
- package/dist/status/closeLastModal.d.mts +18 -0
- package/dist/status/closeLastModal.mjs +18 -0
- package/dist/status/closeModal.d.mts +28 -0
- package/dist/status/closeModal.mjs +28 -0
- package/dist/status/getClosedModals.d.mts +32 -0
- package/dist/status/getClosedModals.mjs +32 -0
- package/dist/status/getClosingModals.d.mts +36 -0
- package/dist/status/getClosingModals.mjs +36 -0
- package/dist/status/getModalStatus.d.mts +31 -0
- package/dist/status/getModalStatus.mjs +30 -0
- package/dist/status/getOpenModals.d.mts +36 -0
- package/dist/status/getOpenModals.mjs +36 -0
- package/dist/status/getOpenedModals.d.mts +32 -0
- package/dist/status/getOpenedModals.mjs +32 -0
- package/dist/status/getOpeningModals.d.mts +36 -0
- package/dist/status/getOpeningModals.mjs +36 -0
- package/dist/status/getVisibleModals.d.mts +36 -0
- package/dist/status/getVisibleModals.mjs +36 -0
- package/dist/status/internals.mjs +15 -6
- package/dist/status/isAnyModalClosed.d.mts +32 -0
- package/dist/status/isAnyModalClosed.mjs +32 -0
- package/dist/status/isAnyModalClosing.d.mts +35 -0
- package/dist/status/isAnyModalClosing.mjs +35 -0
- package/dist/status/isAnyModalOpen.d.mts +32 -0
- package/dist/status/isAnyModalOpen.mjs +32 -0
- package/dist/status/isAnyModalOpened.d.mts +32 -0
- package/dist/status/isAnyModalOpened.mjs +32 -0
- package/dist/status/isAnyModalOpening.d.mts +35 -0
- package/dist/status/isAnyModalOpening.mjs +35 -0
- package/dist/status/isAnyModalVisible.d.mts +32 -0
- package/dist/status/isAnyModalVisible.mjs +32 -0
- package/dist/status/isModalClosed.d.mts +28 -0
- package/dist/status/isModalClosed.mjs +28 -0
- package/dist/status/isModalClosing.d.mts +32 -0
- package/dist/status/isModalClosing.mjs +32 -0
- package/dist/status/isModalOpen.d.mts +28 -0
- package/dist/status/isModalOpen.mjs +28 -0
- package/dist/status/isModalOpened.d.mts +30 -0
- package/dist/status/isModalOpened.mjs +30 -0
- package/dist/status/isModalOpening.d.mts +30 -0
- package/dist/status/isModalOpening.mjs +30 -0
- package/dist/status/isModalVisible.d.mts +30 -0
- package/dist/status/isModalVisible.mjs +30 -0
- package/dist/status/onModalClosed.d.mts +33 -2
- package/dist/status/onModalClosed.mjs +31 -1
- package/dist/status/onModalClosing.d.mts +33 -2
- package/dist/status/onModalClosing.mjs +31 -1
- package/dist/status/onModalOpened.d.mts +31 -0
- package/dist/status/onModalOpened.mjs +31 -1
- package/dist/status/onModalOpening.d.mts +31 -0
- package/dist/status/onModalOpening.mjs +31 -1
- package/dist/status/openModal.d.mts +26 -0
- package/dist/status/openModal.mjs +26 -0
- package/dist/status/setModalStatus.d.mts +29 -0
- package/dist/status/setModalStatus.mjs +28 -0
- package/dist/status/withModalStatus.d.mts +41 -0
- package/dist/status/withModalStatus.mjs +43 -3
- package/dist/utils/closeLastModalOnClickOutside.d.mts +18 -0
- package/dist/utils/closeLastModalOnClickOutside.mjs +18 -0
- package/dist/utils/closeLastModalOnEsc.d.mts +18 -0
- package/dist/utils/closeLastModalOnEsc.mjs +18 -0
- package/dist/utils/syncModalGroupsToBody.d.mts +37 -0
- package/dist/utils/syncModalGroupsToBody.mjs +38 -1
- package/package.json +6 -5
|
@@ -1,4 +1,34 @@
|
|
|
1
1
|
//#region src/anchor/getAnchorElement.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* # getAnchorElement
|
|
4
|
+
*
|
|
5
|
+
* <Badge type="tip">Reactive</Badge>
|
|
6
|
+
*
|
|
7
|
+
* ```ts
|
|
8
|
+
* function getAnchorElement(key: string): HTMLElement | undefined;
|
|
9
|
+
* ```
|
|
10
|
+
*
|
|
11
|
+
* Retrieves the current anchor element for the given `key`.
|
|
12
|
+
*
|
|
13
|
+
* ## Example
|
|
14
|
+
*
|
|
15
|
+
* ```ts
|
|
16
|
+
* import {
|
|
17
|
+
* createModal,
|
|
18
|
+
* withAnchorElement,
|
|
19
|
+
* setAnchorElement,
|
|
20
|
+
* getAnchorElement,
|
|
21
|
+
* } from "@monstermann/signals-modal";
|
|
22
|
+
*
|
|
23
|
+
* createModal("key", () => {
|
|
24
|
+
* withAnchorElement();
|
|
25
|
+
* });
|
|
26
|
+
*
|
|
27
|
+
* setAnchorElement("key", document.querySelector(".anchor"));
|
|
28
|
+
* getAnchorElement("key"); // HTMLElement
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
*/
|
|
2
32
|
declare function getAnchorElement(key: string): HTMLElement | undefined;
|
|
3
33
|
//#endregion
|
|
4
34
|
export { getAnchorElement };
|
|
@@ -1,6 +1,36 @@
|
|
|
1
1
|
import { $anchorElements } from "./internals.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/anchor/getAnchorElement.ts
|
|
4
|
+
/**
|
|
5
|
+
* # getAnchorElement
|
|
6
|
+
*
|
|
7
|
+
* <Badge type="tip">Reactive</Badge>
|
|
8
|
+
*
|
|
9
|
+
* ```ts
|
|
10
|
+
* function getAnchorElement(key: string): HTMLElement | undefined;
|
|
11
|
+
* ```
|
|
12
|
+
*
|
|
13
|
+
* Retrieves the current anchor element for the given `key`.
|
|
14
|
+
*
|
|
15
|
+
* ## Example
|
|
16
|
+
*
|
|
17
|
+
* ```ts
|
|
18
|
+
* import {
|
|
19
|
+
* createModal,
|
|
20
|
+
* withAnchorElement,
|
|
21
|
+
* setAnchorElement,
|
|
22
|
+
* getAnchorElement,
|
|
23
|
+
* } from "@monstermann/signals-modal";
|
|
24
|
+
*
|
|
25
|
+
* createModal("key", () => {
|
|
26
|
+
* withAnchorElement();
|
|
27
|
+
* });
|
|
28
|
+
*
|
|
29
|
+
* setAnchorElement("key", document.querySelector(".anchor"));
|
|
30
|
+
* getAnchorElement("key"); // HTMLElement
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
*/
|
|
4
34
|
function getAnchorElement(key) {
|
|
5
35
|
return $anchorElements().get(key)?.() ?? void 0;
|
|
6
36
|
}
|
|
@@ -1,6 +1,44 @@
|
|
|
1
|
-
import { Rect } from "@monstermann/
|
|
1
|
+
import { Rect } from "@monstermann/geometry";
|
|
2
2
|
|
|
3
3
|
//#region src/anchor/getAnchorMeasurement.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* # getAnchorMeasurement
|
|
7
|
+
*
|
|
8
|
+
* <Badge type="tip">Reactive</Badge>
|
|
9
|
+
*
|
|
10
|
+
* ```ts
|
|
11
|
+
* function getAnchorMeasurement(key: string): Rect;
|
|
12
|
+
* ```
|
|
13
|
+
*
|
|
14
|
+
* Retrieves the current result of `withAnchorMeasurement` or `withMouseAnchor`, falling back to an empty `Rect`.
|
|
15
|
+
*
|
|
16
|
+
* ## Example
|
|
17
|
+
*
|
|
18
|
+
* ```ts
|
|
19
|
+
* import {
|
|
20
|
+
* createModal,
|
|
21
|
+
* withAnchorElement,
|
|
22
|
+
* withModalStatus,
|
|
23
|
+
* withAnchorMeasurement,
|
|
24
|
+
* getAnchorMeasurement,
|
|
25
|
+
* } from "@monstermann/signals-modal";
|
|
26
|
+
*
|
|
27
|
+
* createModal("key", () => {
|
|
28
|
+
* const { $status } = withModalStatus();
|
|
29
|
+
* const $anchorElement = withAnchorElement();
|
|
30
|
+
* // Memo({ top: number, left: number, width: number, height: number })
|
|
31
|
+
* const $anchorMeasurement = withAnchorMeasurement({
|
|
32
|
+
* $status,
|
|
33
|
+
* $anchorElement,
|
|
34
|
+
* });
|
|
35
|
+
* });
|
|
36
|
+
*
|
|
37
|
+
* // { top: number, left: number, width: number, height: number }
|
|
38
|
+
* getAnchorMeasurement("key");
|
|
39
|
+
* ```
|
|
40
|
+
*
|
|
41
|
+
*/
|
|
4
42
|
declare function getAnchorMeasurement(key: string): Rect;
|
|
5
43
|
//#endregion
|
|
6
44
|
export { getAnchorMeasurement };
|
|
@@ -2,6 +2,43 @@ import { $anchorMeasurements } from "./internals.mjs";
|
|
|
2
2
|
import { origin } from "@monstermann/geometry/Rect/origin.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/anchor/getAnchorMeasurement.ts
|
|
5
|
+
/**
|
|
6
|
+
* # getAnchorMeasurement
|
|
7
|
+
*
|
|
8
|
+
* <Badge type="tip">Reactive</Badge>
|
|
9
|
+
*
|
|
10
|
+
* ```ts
|
|
11
|
+
* function getAnchorMeasurement(key: string): Rect;
|
|
12
|
+
* ```
|
|
13
|
+
*
|
|
14
|
+
* Retrieves the current result of `withAnchorMeasurement` or `withMouseAnchor`, falling back to an empty `Rect`.
|
|
15
|
+
*
|
|
16
|
+
* ## Example
|
|
17
|
+
*
|
|
18
|
+
* ```ts
|
|
19
|
+
* import {
|
|
20
|
+
* createModal,
|
|
21
|
+
* withAnchorElement,
|
|
22
|
+
* withModalStatus,
|
|
23
|
+
* withAnchorMeasurement,
|
|
24
|
+
* getAnchorMeasurement,
|
|
25
|
+
* } from "@monstermann/signals-modal";
|
|
26
|
+
*
|
|
27
|
+
* createModal("key", () => {
|
|
28
|
+
* const { $status } = withModalStatus();
|
|
29
|
+
* const $anchorElement = withAnchorElement();
|
|
30
|
+
* // Memo({ top: number, left: number, width: number, height: number })
|
|
31
|
+
* const $anchorMeasurement = withAnchorMeasurement({
|
|
32
|
+
* $status,
|
|
33
|
+
* $anchorElement,
|
|
34
|
+
* });
|
|
35
|
+
* });
|
|
36
|
+
*
|
|
37
|
+
* // { top: number, left: number, width: number, height: number }
|
|
38
|
+
* getAnchorMeasurement("key");
|
|
39
|
+
* ```
|
|
40
|
+
*
|
|
41
|
+
*/
|
|
5
42
|
function getAnchorMeasurement(key) {
|
|
6
43
|
return $anchorMeasurements().get(key)?.() ?? origin;
|
|
7
44
|
}
|
|
@@ -1,4 +1,30 @@
|
|
|
1
1
|
//#region src/anchor/setAnchorElement.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* # setAnchorElement
|
|
4
|
+
*
|
|
5
|
+
* ```ts
|
|
6
|
+
* function setAnchorElement(key: string, element: HTMLElement | null): void;
|
|
7
|
+
* ```
|
|
8
|
+
*
|
|
9
|
+
* Sets the current anchor element for the given `key`.
|
|
10
|
+
*
|
|
11
|
+
* ## Example
|
|
12
|
+
*
|
|
13
|
+
* ```ts
|
|
14
|
+
* import {
|
|
15
|
+
* createModal,
|
|
16
|
+
* withAnchorElement,
|
|
17
|
+
* getAnchorElement,
|
|
18
|
+
* } from "@monstermann/signals-modal";
|
|
19
|
+
*
|
|
20
|
+
* createModal("key", () => {
|
|
21
|
+
* withAnchorElement();
|
|
22
|
+
* });
|
|
23
|
+
*
|
|
24
|
+
* setAnchorElement("key", document.querySelector(".anchor"));
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
*/
|
|
2
28
|
declare function setAnchorElement(key: string, element: HTMLElement | null): void;
|
|
3
29
|
//#endregion
|
|
4
30
|
export { setAnchorElement };
|
|
@@ -1,6 +1,32 @@
|
|
|
1
1
|
import { $anchorElements } from "./internals.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/anchor/setAnchorElement.ts
|
|
4
|
+
/**
|
|
5
|
+
* # setAnchorElement
|
|
6
|
+
*
|
|
7
|
+
* ```ts
|
|
8
|
+
* function setAnchorElement(key: string, element: HTMLElement | null): void;
|
|
9
|
+
* ```
|
|
10
|
+
*
|
|
11
|
+
* Sets the current anchor element for the given `key`.
|
|
12
|
+
*
|
|
13
|
+
* ## Example
|
|
14
|
+
*
|
|
15
|
+
* ```ts
|
|
16
|
+
* import {
|
|
17
|
+
* createModal,
|
|
18
|
+
* withAnchorElement,
|
|
19
|
+
* getAnchorElement,
|
|
20
|
+
* } from "@monstermann/signals-modal";
|
|
21
|
+
*
|
|
22
|
+
* createModal("key", () => {
|
|
23
|
+
* withAnchorElement();
|
|
24
|
+
* });
|
|
25
|
+
*
|
|
26
|
+
* setAnchorElement("key", document.querySelector(".anchor"));
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
*/
|
|
4
30
|
function setAnchorElement(key, element) {
|
|
5
31
|
$anchorElements().get(key)?.(element);
|
|
6
32
|
}
|
|
@@ -1,6 +1,37 @@
|
|
|
1
1
|
import { Signal } from "@monstermann/signals";
|
|
2
2
|
|
|
3
3
|
//#region src/anchor/withAnchorElement.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* # withAnchorElement
|
|
7
|
+
*
|
|
8
|
+
* ```ts
|
|
9
|
+
* function withAnchorElement(
|
|
10
|
+
* anchorElement?: HTMLElement,
|
|
11
|
+
* ): Signal<HTMLElement | null>;
|
|
12
|
+
* ```
|
|
13
|
+
*
|
|
14
|
+
* Assigns an anchor element to the current modal. This function must be called inside a `createModal` callback.
|
|
15
|
+
*
|
|
16
|
+
* ## Example
|
|
17
|
+
*
|
|
18
|
+
* ```ts
|
|
19
|
+
* import {
|
|
20
|
+
* createModal,
|
|
21
|
+
* withAnchorElement,
|
|
22
|
+
* setAnchorElement,
|
|
23
|
+
* getAnchorElement,
|
|
24
|
+
* } from "@monstermann/signals-modal";
|
|
25
|
+
*
|
|
26
|
+
* createModal("key", () => {
|
|
27
|
+
* withAnchorElement();
|
|
28
|
+
* });
|
|
29
|
+
*
|
|
30
|
+
* setAnchorElement("key", document.querySelector(".anchor"));
|
|
31
|
+
* getAnchorElement("key"); // HTMLElement
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
*/
|
|
4
35
|
declare function withAnchorElement(anchorElement?: HTMLElement | null): Signal<HTMLElement | null>;
|
|
5
36
|
//#endregion
|
|
6
37
|
export { withAnchorElement };
|
|
@@ -5,9 +5,39 @@ import { INTERNAL, signal } from "@monstermann/signals";
|
|
|
5
5
|
//#region src/anchor/withAnchorElement.ts
|
|
6
6
|
const meta = {
|
|
7
7
|
path: "@signals-modal/anchor/withAnchorElement.ts",
|
|
8
|
-
line:
|
|
8
|
+
line: 38,
|
|
9
9
|
name: "withAnchorElement.$anchorElement"
|
|
10
10
|
};
|
|
11
|
+
/**
|
|
12
|
+
* # withAnchorElement
|
|
13
|
+
*
|
|
14
|
+
* ```ts
|
|
15
|
+
* function withAnchorElement(
|
|
16
|
+
* anchorElement?: HTMLElement,
|
|
17
|
+
* ): Signal<HTMLElement | null>;
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* Assigns an anchor element to the current modal. This function must be called inside a `createModal` callback.
|
|
21
|
+
*
|
|
22
|
+
* ## Example
|
|
23
|
+
*
|
|
24
|
+
* ```ts
|
|
25
|
+
* import {
|
|
26
|
+
* createModal,
|
|
27
|
+
* withAnchorElement,
|
|
28
|
+
* setAnchorElement,
|
|
29
|
+
* getAnchorElement,
|
|
30
|
+
* } from "@monstermann/signals-modal";
|
|
31
|
+
*
|
|
32
|
+
* createModal("key", () => {
|
|
33
|
+
* withAnchorElement();
|
|
34
|
+
* });
|
|
35
|
+
*
|
|
36
|
+
* setAnchorElement("key", document.querySelector(".anchor"));
|
|
37
|
+
* getAnchorElement("key"); // HTMLElement
|
|
38
|
+
* ```
|
|
39
|
+
*
|
|
40
|
+
*/
|
|
11
41
|
function withAnchorElement(anchorElement) {
|
|
12
42
|
const modal = currentModal();
|
|
13
43
|
const $anchorElement = signal(anchorElement ?? null, INTERNAL, meta);
|
|
@@ -1,8 +1,51 @@
|
|
|
1
1
|
import { ModalStatus } from "../status/types.mjs";
|
|
2
2
|
import { Memo, Reactive } from "@monstermann/signals";
|
|
3
|
-
import { Rect } from "@monstermann/
|
|
3
|
+
import { Rect } from "@monstermann/geometry";
|
|
4
4
|
|
|
5
5
|
//#region src/anchor/withAnchorMeasurement.d.ts
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* # withAnchorMeasurement
|
|
9
|
+
*
|
|
10
|
+
* ```ts
|
|
11
|
+
* function withAnchorMeasurement(options: {
|
|
12
|
+
* $anchorElement: Reactive<HTMLElement | null>;
|
|
13
|
+
* $status: Reactive<ModalStatus>;
|
|
14
|
+
* transform?: (rect: Rect) => Rect;
|
|
15
|
+
* }): Memo<Rect>;
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* Takes an anchor element and continuously measures its position while the modal is visible, to be used to position eg. a popover next to an element. This function must be called inside a `createModal` callback.
|
|
19
|
+
*
|
|
20
|
+
* The optional `transform` option can be used to eg. make the anchor bigger, resulting with a margin between the anchor and floating popover.
|
|
21
|
+
*
|
|
22
|
+
* ## Example
|
|
23
|
+
*
|
|
24
|
+
* ```ts
|
|
25
|
+
* import {
|
|
26
|
+
* createModal,
|
|
27
|
+
* withAnchorElement,
|
|
28
|
+
* withModalStatus,
|
|
29
|
+
* withAnchorMeasurement,
|
|
30
|
+
* setAnchorElement,
|
|
31
|
+
* setModalStatus,
|
|
32
|
+
* } from "@monstermann/signals-modal";
|
|
33
|
+
*
|
|
34
|
+
* createModal("key", () => {
|
|
35
|
+
* const { $status } = withModalStatus();
|
|
36
|
+
* const $anchorElement = withAnchorElement();
|
|
37
|
+
* // Memo({ top: number, left: number, width: number, height: number })
|
|
38
|
+
* const $anchorMeasurement = withAnchorMeasurement({
|
|
39
|
+
* $status,
|
|
40
|
+
* $anchorElement,
|
|
41
|
+
* });
|
|
42
|
+
* });
|
|
43
|
+
*
|
|
44
|
+
* setAnchorElement("key", document.querySelector(".anchor"));
|
|
45
|
+
* setModalStatus("key", "opened");
|
|
46
|
+
* ```
|
|
47
|
+
*
|
|
48
|
+
*/
|
|
6
49
|
declare function withAnchorMeasurement(options: {
|
|
7
50
|
$anchorElement: Reactive<HTMLElement | null>;
|
|
8
51
|
$status: Reactive<ModalStatus>;
|
|
@@ -11,19 +11,61 @@ import { fromDOMRect } from "@monstermann/geometry/Rect/fromDOMRect.mjs";
|
|
|
11
11
|
const path = "@signals-modal/anchor/withAnchorMeasurement.ts";
|
|
12
12
|
const meta = {
|
|
13
13
|
path,
|
|
14
|
-
line:
|
|
14
|
+
line: 61,
|
|
15
15
|
name: "withAnchorMeasurement.$rect"
|
|
16
16
|
};
|
|
17
17
|
const meta1 = {
|
|
18
18
|
path,
|
|
19
|
-
line:
|
|
19
|
+
line: 66,
|
|
20
20
|
name: "withAnchorMeasurement.$measurement"
|
|
21
21
|
};
|
|
22
22
|
const meta2 = {
|
|
23
23
|
path,
|
|
24
|
-
line:
|
|
24
|
+
line: 70,
|
|
25
25
|
name: "withAnchorMeasurement"
|
|
26
26
|
};
|
|
27
|
+
/**
|
|
28
|
+
* # withAnchorMeasurement
|
|
29
|
+
*
|
|
30
|
+
* ```ts
|
|
31
|
+
* function withAnchorMeasurement(options: {
|
|
32
|
+
* $anchorElement: Reactive<HTMLElement | null>;
|
|
33
|
+
* $status: Reactive<ModalStatus>;
|
|
34
|
+
* transform?: (rect: Rect) => Rect;
|
|
35
|
+
* }): Memo<Rect>;
|
|
36
|
+
* ```
|
|
37
|
+
*
|
|
38
|
+
* Takes an anchor element and continuously measures its position while the modal is visible, to be used to position eg. a popover next to an element. This function must be called inside a `createModal` callback.
|
|
39
|
+
*
|
|
40
|
+
* The optional `transform` option can be used to eg. make the anchor bigger, resulting with a margin between the anchor and floating popover.
|
|
41
|
+
*
|
|
42
|
+
* ## Example
|
|
43
|
+
*
|
|
44
|
+
* ```ts
|
|
45
|
+
* import {
|
|
46
|
+
* createModal,
|
|
47
|
+
* withAnchorElement,
|
|
48
|
+
* withModalStatus,
|
|
49
|
+
* withAnchorMeasurement,
|
|
50
|
+
* setAnchorElement,
|
|
51
|
+
* setModalStatus,
|
|
52
|
+
* } from "@monstermann/signals-modal";
|
|
53
|
+
*
|
|
54
|
+
* createModal("key", () => {
|
|
55
|
+
* const { $status } = withModalStatus();
|
|
56
|
+
* const $anchorElement = withAnchorElement();
|
|
57
|
+
* // Memo({ top: number, left: number, width: number, height: number })
|
|
58
|
+
* const $anchorMeasurement = withAnchorMeasurement({
|
|
59
|
+
* $status,
|
|
60
|
+
* $anchorElement,
|
|
61
|
+
* });
|
|
62
|
+
* });
|
|
63
|
+
*
|
|
64
|
+
* setAnchorElement("key", document.querySelector(".anchor"));
|
|
65
|
+
* setModalStatus("key", "opened");
|
|
66
|
+
* ```
|
|
67
|
+
*
|
|
68
|
+
*/
|
|
27
69
|
function withAnchorMeasurement(options) {
|
|
28
70
|
const modal = currentModal();
|
|
29
71
|
const $rect = signal(origin, {
|
|
@@ -1,8 +1,42 @@
|
|
|
1
1
|
import { ModalStatus } from "../status/types.mjs";
|
|
2
2
|
import { Memo, Reactive } from "@monstermann/signals";
|
|
3
|
-
import { Rect } from "@monstermann/
|
|
3
|
+
import { Rect } from "@monstermann/geometry";
|
|
4
4
|
|
|
5
5
|
//#region src/anchor/withMouseAnchor.d.ts
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* # withMouseAnchor
|
|
9
|
+
*
|
|
10
|
+
* ```ts
|
|
11
|
+
* function withMouseAnchor(options: {
|
|
12
|
+
* $status: Reactive<ModalStatus>;
|
|
13
|
+
* transform?: (rect: Rect) => Rect;
|
|
14
|
+
* }): Memo<Rect>;
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* This can be used to make the mouse cursor the anchor, instead of an element. This function must be called inside a `createModal` callback.
|
|
18
|
+
*
|
|
19
|
+
* ## Example
|
|
20
|
+
*
|
|
21
|
+
* ```ts
|
|
22
|
+
* import {
|
|
23
|
+
* createModal,
|
|
24
|
+
* withModalStatus,
|
|
25
|
+
* withMouseAnchor,
|
|
26
|
+
* setModalStatus,
|
|
27
|
+
* } from "@monstermann/signals-modal";
|
|
28
|
+
*
|
|
29
|
+
* createModal("key", () => {
|
|
30
|
+
* const { $status } = withModalStatus();
|
|
31
|
+
* // Memo({ top: number, left: number, width: number, height: number })
|
|
32
|
+
* const $anchorMeasurement = withMouseAnchor({ $status });
|
|
33
|
+
* });
|
|
34
|
+
*
|
|
35
|
+
* // Updates $anchorMeasurement to the current mouse coordinates (once).
|
|
36
|
+
* setModalStatus("key", "opened");
|
|
37
|
+
* ```
|
|
38
|
+
*
|
|
39
|
+
*/
|
|
6
40
|
declare function withMouseAnchor(options: {
|
|
7
41
|
$status: Reactive<ModalStatus>;
|
|
8
42
|
transform?: (rect: Rect) => Rect;
|
|
@@ -10,19 +10,52 @@ import { $mouseX, $mouseY } from "@monstermann/signals-web";
|
|
|
10
10
|
const path = "@signals-modal/anchor/withMouseAnchor.ts";
|
|
11
11
|
const meta = {
|
|
12
12
|
path,
|
|
13
|
-
line:
|
|
13
|
+
line: 50,
|
|
14
14
|
name: "withMouseAnchor.$rect"
|
|
15
15
|
};
|
|
16
16
|
const meta1 = {
|
|
17
17
|
path,
|
|
18
|
-
line:
|
|
18
|
+
line: 55,
|
|
19
19
|
name: "withMouseAnchor.$measurement"
|
|
20
20
|
};
|
|
21
21
|
const meta2 = {
|
|
22
22
|
path,
|
|
23
|
-
line:
|
|
23
|
+
line: 59,
|
|
24
24
|
name: "withMouseAnchor"
|
|
25
25
|
};
|
|
26
|
+
/**
|
|
27
|
+
* # withMouseAnchor
|
|
28
|
+
*
|
|
29
|
+
* ```ts
|
|
30
|
+
* function withMouseAnchor(options: {
|
|
31
|
+
* $status: Reactive<ModalStatus>;
|
|
32
|
+
* transform?: (rect: Rect) => Rect;
|
|
33
|
+
* }): Memo<Rect>;
|
|
34
|
+
* ```
|
|
35
|
+
*
|
|
36
|
+
* This can be used to make the mouse cursor the anchor, instead of an element. This function must be called inside a `createModal` callback.
|
|
37
|
+
*
|
|
38
|
+
* ## Example
|
|
39
|
+
*
|
|
40
|
+
* ```ts
|
|
41
|
+
* import {
|
|
42
|
+
* createModal,
|
|
43
|
+
* withModalStatus,
|
|
44
|
+
* withMouseAnchor,
|
|
45
|
+
* setModalStatus,
|
|
46
|
+
* } from "@monstermann/signals-modal";
|
|
47
|
+
*
|
|
48
|
+
* createModal("key", () => {
|
|
49
|
+
* const { $status } = withModalStatus();
|
|
50
|
+
* // Memo({ top: number, left: number, width: number, height: number })
|
|
51
|
+
* const $anchorMeasurement = withMouseAnchor({ $status });
|
|
52
|
+
* });
|
|
53
|
+
*
|
|
54
|
+
* // Updates $anchorMeasurement to the current mouse coordinates (once).
|
|
55
|
+
* setModalStatus("key", "opened");
|
|
56
|
+
* ```
|
|
57
|
+
*
|
|
58
|
+
*/
|
|
26
59
|
function withMouseAnchor(options) {
|
|
27
60
|
const modal = currentModal();
|
|
28
61
|
const $rect = signal(origin, {
|
package/dist/createModal.d.mts
CHANGED
|
@@ -10,6 +10,35 @@ interface ModalContext {
|
|
|
10
10
|
}
|
|
11
11
|
declare const onModalDisposed: _monstermann_signals0.Emitter<string>;
|
|
12
12
|
declare function currentModal(): ModalContext;
|
|
13
|
+
/**
|
|
14
|
+
* # createModal
|
|
15
|
+
*
|
|
16
|
+
* ```ts
|
|
17
|
+
* function createModal(
|
|
18
|
+
* key: string,
|
|
19
|
+
* setup: () => T,
|
|
20
|
+
* ): T & {
|
|
21
|
+
* key: string;
|
|
22
|
+
* dispose: () => void;
|
|
23
|
+
* isDisposed: () => boolean;
|
|
24
|
+
* onDispose: (dispose: MaybeDispose) => void;
|
|
25
|
+
* };
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* Creates a new modal.
|
|
29
|
+
*
|
|
30
|
+
* ## Example
|
|
31
|
+
*
|
|
32
|
+
* ```ts
|
|
33
|
+
* import { createModal } from "@monstermann/signals-modal";
|
|
34
|
+
*
|
|
35
|
+
* const modal = createModal("key", () => ({}));
|
|
36
|
+
* modal.key;
|
|
37
|
+
* modal.dispose();
|
|
38
|
+
* modal.onDispose(callback);
|
|
39
|
+
* ```
|
|
40
|
+
*
|
|
41
|
+
*/
|
|
13
42
|
declare function createModal<T extends object>(key: string, setup: () => T): ModalContext & T;
|
|
14
43
|
//#endregion
|
|
15
44
|
export { ModalContext, createModal, currentModal, onModalDisposed };
|
package/dist/createModal.mjs
CHANGED
|
@@ -16,6 +16,35 @@ function currentModal() {
|
|
|
16
16
|
if (!ctx) throw new Error("`currentModal` called outside of `createModal` context.");
|
|
17
17
|
return ctx;
|
|
18
18
|
}
|
|
19
|
+
/**
|
|
20
|
+
* # createModal
|
|
21
|
+
*
|
|
22
|
+
* ```ts
|
|
23
|
+
* function createModal(
|
|
24
|
+
* key: string,
|
|
25
|
+
* setup: () => T,
|
|
26
|
+
* ): T & {
|
|
27
|
+
* key: string;
|
|
28
|
+
* dispose: () => void;
|
|
29
|
+
* isDisposed: () => boolean;
|
|
30
|
+
* onDispose: (dispose: MaybeDispose) => void;
|
|
31
|
+
* };
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* Creates a new modal.
|
|
35
|
+
*
|
|
36
|
+
* ## Example
|
|
37
|
+
*
|
|
38
|
+
* ```ts
|
|
39
|
+
* import { createModal } from "@monstermann/signals-modal";
|
|
40
|
+
*
|
|
41
|
+
* const modal = createModal("key", () => ({}));
|
|
42
|
+
* modal.key;
|
|
43
|
+
* modal.dispose();
|
|
44
|
+
* modal.onDispose(callback);
|
|
45
|
+
* ```
|
|
46
|
+
*
|
|
47
|
+
*/
|
|
19
48
|
function createModal(key, setup) {
|
|
20
49
|
const dispose = disposer();
|
|
21
50
|
const nextCtx = {
|
|
@@ -1,4 +1,34 @@
|
|
|
1
1
|
//#region src/floating/getFloatingElement.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* # getFloatingElement
|
|
4
|
+
*
|
|
5
|
+
* <Badge type="tip">Reactive</Badge>
|
|
6
|
+
*
|
|
7
|
+
* ```ts
|
|
8
|
+
* function getFloatingElement(key: string): HTMLElement | undefined;
|
|
9
|
+
* ```
|
|
10
|
+
*
|
|
11
|
+
* Retrieves the current floating element for the given `key`.
|
|
12
|
+
*
|
|
13
|
+
* ## Example
|
|
14
|
+
*
|
|
15
|
+
* ```ts
|
|
16
|
+
* import {
|
|
17
|
+
* createModal,
|
|
18
|
+
* withFloatingElement,
|
|
19
|
+
* setFloatingElement,
|
|
20
|
+
* getFloatingElement,
|
|
21
|
+
* } from "@monstermann/signals-modal";
|
|
22
|
+
*
|
|
23
|
+
* createModal("key", () => {
|
|
24
|
+
* withFloatingElement();
|
|
25
|
+
* });
|
|
26
|
+
*
|
|
27
|
+
* setFloatingElement("key", document.querySelector(".floating"));
|
|
28
|
+
* getFloatingElement("key"); // HTMLElement
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
*/
|
|
2
32
|
declare function getFloatingElement(key: string): HTMLElement | undefined;
|
|
3
33
|
//#endregion
|
|
4
34
|
export { getFloatingElement };
|
|
@@ -1,6 +1,36 @@
|
|
|
1
1
|
import { $floatingElements } from "./internals.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/floating/getFloatingElement.ts
|
|
4
|
+
/**
|
|
5
|
+
* # getFloatingElement
|
|
6
|
+
*
|
|
7
|
+
* <Badge type="tip">Reactive</Badge>
|
|
8
|
+
*
|
|
9
|
+
* ```ts
|
|
10
|
+
* function getFloatingElement(key: string): HTMLElement | undefined;
|
|
11
|
+
* ```
|
|
12
|
+
*
|
|
13
|
+
* Retrieves the current floating element for the given `key`.
|
|
14
|
+
*
|
|
15
|
+
* ## Example
|
|
16
|
+
*
|
|
17
|
+
* ```ts
|
|
18
|
+
* import {
|
|
19
|
+
* createModal,
|
|
20
|
+
* withFloatingElement,
|
|
21
|
+
* setFloatingElement,
|
|
22
|
+
* getFloatingElement,
|
|
23
|
+
* } from "@monstermann/signals-modal";
|
|
24
|
+
*
|
|
25
|
+
* createModal("key", () => {
|
|
26
|
+
* withFloatingElement();
|
|
27
|
+
* });
|
|
28
|
+
*
|
|
29
|
+
* setFloatingElement("key", document.querySelector(".floating"));
|
|
30
|
+
* getFloatingElement("key"); // HTMLElement
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
*/
|
|
4
34
|
function getFloatingElement(key) {
|
|
5
35
|
return $floatingElements().get(key)?.() ?? void 0;
|
|
6
36
|
}
|