@monstermann/signals-modal 0.5.0 → 0.7.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/README.md +0 -377
- package/dist/anchor/withAnchorElement.mjs +2 -13
- package/dist/anchor/withAnchorMeasurement.mjs +3 -11
- package/dist/anchor/withMouseAnchor.mjs +3 -11
- package/dist/createModal.mjs +1 -1
- package/dist/floating/withFloatingElement.mjs +2 -13
- package/dist/floating/withFloatingMeasurement.mjs +3 -11
- package/dist/index.d.mts +2 -14
- package/dist/index.mjs +5 -17
- package/dist/position/internals.mjs +1 -21
- package/dist/position/withPlacement.mjs +3 -13
- package/dist/position/withPosition.mjs +5 -15
- package/dist/status/internals.mjs +4 -31
- package/dist/status/withModalStatus.mjs +3 -3
- package/package.json +2 -2
- package/dist/anchor/getAnchorElement.d.mts +0 -34
- package/dist/anchor/getAnchorElement.mjs +0 -39
- package/dist/anchor/getAnchorMeasurement.d.mts +0 -43
- package/dist/anchor/getAnchorMeasurement.mjs +0 -47
- package/dist/anchor/internals.mjs +0 -25
- package/dist/anchor/setAnchorElement.d.mts +0 -30
- package/dist/anchor/setAnchorElement.mjs +0 -35
- package/dist/floating/getFloatingElement.d.mts +0 -34
- package/dist/floating/getFloatingElement.mjs +0 -39
- package/dist/floating/getFloatingMeasurement.d.mts +0 -43
- package/dist/floating/getFloatingMeasurement.mjs +0 -47
- package/dist/floating/internals.mjs +0 -25
- package/dist/floating/setFloatingElement.d.mts +0 -30
- package/dist/floating/setFloatingElement.mjs +0 -35
- package/dist/internals/findParentElement.mjs +0 -9
- package/dist/position/getModalPlacement.d.mts +0 -55
- package/dist/position/getModalPlacement.mjs +0 -58
- package/dist/position/getModalPosition.d.mts +0 -64
- package/dist/position/getModalPosition.mjs +0 -67
- package/dist/status/closeLastModal.d.mts +0 -22
- package/dist/status/closeLastModal.mjs +0 -29
- package/dist/utils/closeLastModalOnClickOutside.d.mts +0 -22
- package/dist/utils/closeLastModalOnClickOutside.mjs +0 -37
- package/dist/utils/closeLastModalOnEsc.d.mts +0 -22
- package/dist/utils/closeLastModalOnEsc.mjs +0 -35
- package/dist/utils/syncModalGroupsToBody.d.mts +0 -41
- package/dist/utils/syncModalGroupsToBody.mjs +0 -72
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { $floatingMeasurements } from "./internals.mjs";
|
|
2
|
-
import { origin } from "@monstermann/geometry/Rect/origin.mjs";
|
|
3
|
-
|
|
4
|
-
//#region src/floating/getFloatingMeasurement.ts
|
|
5
|
-
/**
|
|
6
|
-
* # getFloatingMeasurement
|
|
7
|
-
*
|
|
8
|
-
* <Badge type="tip">Reactive</Badge>
|
|
9
|
-
*
|
|
10
|
-
* ```ts
|
|
11
|
-
* function getFloatingMeasurement(key: string): Rect;
|
|
12
|
-
* ```
|
|
13
|
-
*
|
|
14
|
-
* Retrieves the current result of `withFloatingMeasurement`, falling back to an empty `Rect`.
|
|
15
|
-
*
|
|
16
|
-
* ## Example
|
|
17
|
-
*
|
|
18
|
-
* ```ts
|
|
19
|
-
* import {
|
|
20
|
-
* createModal,
|
|
21
|
-
* withFloatingElement,
|
|
22
|
-
* withModalStatus,
|
|
23
|
-
* withFloatingMeasurement,
|
|
24
|
-
* getFloatingMeasurement,
|
|
25
|
-
* } from "@monstermann/signals-modal";
|
|
26
|
-
*
|
|
27
|
-
* createModal("key", () => {
|
|
28
|
-
* const { $status } = withModalStatus();
|
|
29
|
-
* const $floatingElement = withFloatingElement();
|
|
30
|
-
* // Memo({ top: number, left: number, width: number, height: number })
|
|
31
|
-
* const $floatingMeasurement = withFloatingMeasurement({
|
|
32
|
-
* $status,
|
|
33
|
-
* $floatingElement,
|
|
34
|
-
* });
|
|
35
|
-
* });
|
|
36
|
-
*
|
|
37
|
-
* // { top: number, left: number, width: number, height: number }
|
|
38
|
-
* getFloatingMeasurement("key");
|
|
39
|
-
* ```
|
|
40
|
-
*
|
|
41
|
-
*/
|
|
42
|
-
function getFloatingMeasurement(key) {
|
|
43
|
-
return $floatingMeasurements().get(key)?.() ?? origin;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
//#endregion
|
|
47
|
-
export { getFloatingMeasurement };
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { signal } from "@monstermann/signals";
|
|
2
|
-
|
|
3
|
-
//#region src/floating/internals.ts
|
|
4
|
-
const path = "@signals-modal/floating/internals.ts";
|
|
5
|
-
const meta = {
|
|
6
|
-
path,
|
|
7
|
-
line: 5,
|
|
8
|
-
name: "$floatingElements"
|
|
9
|
-
};
|
|
10
|
-
const meta1 = {
|
|
11
|
-
path,
|
|
12
|
-
line: 10,
|
|
13
|
-
name: "$floatingMeasurements"
|
|
14
|
-
};
|
|
15
|
-
const $floatingElements = signal(/* @__PURE__ */ new Map(), {
|
|
16
|
-
mutable: true,
|
|
17
|
-
silent: true
|
|
18
|
-
}, meta);
|
|
19
|
-
const $floatingMeasurements = signal(/* @__PURE__ */ new Map(), {
|
|
20
|
-
mutable: true,
|
|
21
|
-
silent: true
|
|
22
|
-
}, meta1);
|
|
23
|
-
|
|
24
|
-
//#endregion
|
|
25
|
-
export { $floatingElements, $floatingMeasurements };
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
//#region src/floating/setFloatingElement.d.ts
|
|
2
|
-
/**
|
|
3
|
-
* # setFloatingElement
|
|
4
|
-
*
|
|
5
|
-
* ```ts
|
|
6
|
-
* function setFloatingElement(key: string, element: HTMLElement | null): void;
|
|
7
|
-
* ```
|
|
8
|
-
*
|
|
9
|
-
* Sets the current floating element for the given `key`.
|
|
10
|
-
*
|
|
11
|
-
* ## Example
|
|
12
|
-
*
|
|
13
|
-
* ```ts
|
|
14
|
-
* import {
|
|
15
|
-
* createModal,
|
|
16
|
-
* withFloatingElement,
|
|
17
|
-
* getFloatingElement,
|
|
18
|
-
* } from "@monstermann/signals-modal";
|
|
19
|
-
*
|
|
20
|
-
* createModal("key", () => {
|
|
21
|
-
* withFloatingElement();
|
|
22
|
-
* });
|
|
23
|
-
*
|
|
24
|
-
* setFloatingElement("key", document.querySelector(".floating"));
|
|
25
|
-
* ```
|
|
26
|
-
*
|
|
27
|
-
*/
|
|
28
|
-
declare function setFloatingElement(key: string, element: HTMLElement | null): void;
|
|
29
|
-
//#endregion
|
|
30
|
-
export { setFloatingElement };
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { $floatingElements } from "./internals.mjs";
|
|
2
|
-
|
|
3
|
-
//#region src/floating/setFloatingElement.ts
|
|
4
|
-
/**
|
|
5
|
-
* # setFloatingElement
|
|
6
|
-
*
|
|
7
|
-
* ```ts
|
|
8
|
-
* function setFloatingElement(key: string, element: HTMLElement | null): void;
|
|
9
|
-
* ```
|
|
10
|
-
*
|
|
11
|
-
* Sets the current floating element for the given `key`.
|
|
12
|
-
*
|
|
13
|
-
* ## Example
|
|
14
|
-
*
|
|
15
|
-
* ```ts
|
|
16
|
-
* import {
|
|
17
|
-
* createModal,
|
|
18
|
-
* withFloatingElement,
|
|
19
|
-
* getFloatingElement,
|
|
20
|
-
* } from "@monstermann/signals-modal";
|
|
21
|
-
*
|
|
22
|
-
* createModal("key", () => {
|
|
23
|
-
* withFloatingElement();
|
|
24
|
-
* });
|
|
25
|
-
*
|
|
26
|
-
* setFloatingElement("key", document.querySelector(".floating"));
|
|
27
|
-
* ```
|
|
28
|
-
*
|
|
29
|
-
*/
|
|
30
|
-
function setFloatingElement(key, element) {
|
|
31
|
-
$floatingElements().get(key)?.(element);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
//#endregion
|
|
35
|
-
export { setFloatingElement };
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
//#region src/internals/findParentElement.ts
|
|
2
|
-
function findParentElement(element, predicate) {
|
|
3
|
-
if (!element) return void 0;
|
|
4
|
-
if (predicate(element)) return element;
|
|
5
|
-
return findParentElement(element.parentElement, predicate);
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
//#endregion
|
|
9
|
-
export { findParentElement };
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { ModalPlacement } from "./withPlacement.mjs";
|
|
2
|
-
|
|
3
|
-
//#region src/position/getModalPlacement.d.ts
|
|
4
|
-
/**
|
|
5
|
-
* # getModalPlacement
|
|
6
|
-
*
|
|
7
|
-
* ```ts
|
|
8
|
-
* function getModalPlacement(key: string): ModalPlacement | undefined;
|
|
9
|
-
* ```
|
|
10
|
-
*
|
|
11
|
-
* Returns the current placement for the given `key`.
|
|
12
|
-
*
|
|
13
|
-
* ## Example
|
|
14
|
-
*
|
|
15
|
-
* ```ts
|
|
16
|
-
* import {
|
|
17
|
-
* createModal,
|
|
18
|
-
* withModalStatus,
|
|
19
|
-
* withAnchorElement,
|
|
20
|
-
* withAnchorMeasurement,
|
|
21
|
-
* withFloatingElement,
|
|
22
|
-
* withFloatingMeasurement,
|
|
23
|
-
* withBoundary,
|
|
24
|
-
* withPlacement,
|
|
25
|
-
* getModalPlacement,
|
|
26
|
-
* } from "@monstermann/signals-modal";
|
|
27
|
-
*
|
|
28
|
-
* createModal("key", () => {
|
|
29
|
-
* const { $status } = withModalStatus();
|
|
30
|
-
* const $anchorElement = withAnchorElement();
|
|
31
|
-
* const $floatingElement = withFloatingElement();
|
|
32
|
-
* const $anchorMeasurement = withAnchorMeasurement({
|
|
33
|
-
* $status,
|
|
34
|
-
* $anchorElement,
|
|
35
|
-
* });
|
|
36
|
-
* const $floatingMeasurement = withFloatingMeasurement({
|
|
37
|
-
* $status,
|
|
38
|
-
* $floatingElement,
|
|
39
|
-
* });
|
|
40
|
-
* const $boundary = withBoundary({ $status });
|
|
41
|
-
* const $placement = withPlacement({
|
|
42
|
-
* placement: "vertical-center",
|
|
43
|
-
* $boundary,
|
|
44
|
-
* $anchorMeasurement,
|
|
45
|
-
* $floatingMeasurement,
|
|
46
|
-
* });
|
|
47
|
-
* });
|
|
48
|
-
*
|
|
49
|
-
* getModalPlacement("key"); // up-center | down-center
|
|
50
|
-
* ```
|
|
51
|
-
*
|
|
52
|
-
*/
|
|
53
|
-
declare function getModalPlacement(key: string): ModalPlacement | undefined;
|
|
54
|
-
//#endregion
|
|
55
|
-
export { getModalPlacement };
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { $placements } from "./internals.mjs";
|
|
2
|
-
|
|
3
|
-
//#region src/position/getModalPlacement.ts
|
|
4
|
-
/**
|
|
5
|
-
* # getModalPlacement
|
|
6
|
-
*
|
|
7
|
-
* ```ts
|
|
8
|
-
* function getModalPlacement(key: string): ModalPlacement | undefined;
|
|
9
|
-
* ```
|
|
10
|
-
*
|
|
11
|
-
* Returns the current placement for the given `key`.
|
|
12
|
-
*
|
|
13
|
-
* ## Example
|
|
14
|
-
*
|
|
15
|
-
* ```ts
|
|
16
|
-
* import {
|
|
17
|
-
* createModal,
|
|
18
|
-
* withModalStatus,
|
|
19
|
-
* withAnchorElement,
|
|
20
|
-
* withAnchorMeasurement,
|
|
21
|
-
* withFloatingElement,
|
|
22
|
-
* withFloatingMeasurement,
|
|
23
|
-
* withBoundary,
|
|
24
|
-
* withPlacement,
|
|
25
|
-
* getModalPlacement,
|
|
26
|
-
* } from "@monstermann/signals-modal";
|
|
27
|
-
*
|
|
28
|
-
* createModal("key", () => {
|
|
29
|
-
* const { $status } = withModalStatus();
|
|
30
|
-
* const $anchorElement = withAnchorElement();
|
|
31
|
-
* const $floatingElement = withFloatingElement();
|
|
32
|
-
* const $anchorMeasurement = withAnchorMeasurement({
|
|
33
|
-
* $status,
|
|
34
|
-
* $anchorElement,
|
|
35
|
-
* });
|
|
36
|
-
* const $floatingMeasurement = withFloatingMeasurement({
|
|
37
|
-
* $status,
|
|
38
|
-
* $floatingElement,
|
|
39
|
-
* });
|
|
40
|
-
* const $boundary = withBoundary({ $status });
|
|
41
|
-
* const $placement = withPlacement({
|
|
42
|
-
* placement: "vertical-center",
|
|
43
|
-
* $boundary,
|
|
44
|
-
* $anchorMeasurement,
|
|
45
|
-
* $floatingMeasurement,
|
|
46
|
-
* });
|
|
47
|
-
* });
|
|
48
|
-
*
|
|
49
|
-
* getModalPlacement("key"); // up-center | down-center
|
|
50
|
-
* ```
|
|
51
|
-
*
|
|
52
|
-
*/
|
|
53
|
-
function getModalPlacement(key) {
|
|
54
|
-
return $placements().get(key)?.();
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
//#endregion
|
|
58
|
-
export { getModalPlacement };
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { ModalPosition } from "./withPosition.mjs";
|
|
2
|
-
|
|
3
|
-
//#region src/position/getModalPosition.d.ts
|
|
4
|
-
/**
|
|
5
|
-
* # getModalPosition
|
|
6
|
-
*
|
|
7
|
-
* <Badge type="tip">Reactive</Badge>
|
|
8
|
-
*
|
|
9
|
-
* ```ts
|
|
10
|
-
* function getModalPosition(key: string): ModalPosition | undefined;
|
|
11
|
-
* ```
|
|
12
|
-
*
|
|
13
|
-
* Returns the current result of `withPosition`.
|
|
14
|
-
*
|
|
15
|
-
* ## Example
|
|
16
|
-
*
|
|
17
|
-
* ```ts
|
|
18
|
-
* import {
|
|
19
|
-
* createModal,
|
|
20
|
-
* withModalStatus,
|
|
21
|
-
* withAnchorElement,
|
|
22
|
-
* withAnchorMeasurement,
|
|
23
|
-
* withFloatingElement,
|
|
24
|
-
* withFloatingMeasurement,
|
|
25
|
-
* withBoundary,
|
|
26
|
-
* withPlacement,
|
|
27
|
-
* withPosition,
|
|
28
|
-
* getModalPosition,
|
|
29
|
-
* } from "@monstermann/signals-modal";
|
|
30
|
-
*
|
|
31
|
-
* createModal("key", () => {
|
|
32
|
-
* const { $status } = withModalStatus();
|
|
33
|
-
* const $anchorElement = withAnchorElement();
|
|
34
|
-
* const $floatingElement = withFloatingElement();
|
|
35
|
-
* const $anchorMeasurement = withAnchorMeasurement({
|
|
36
|
-
* $status,
|
|
37
|
-
* $anchorElement,
|
|
38
|
-
* });
|
|
39
|
-
* const $floatingMeasurement = withFloatingMeasurement({
|
|
40
|
-
* $status,
|
|
41
|
-
* $floatingElement,
|
|
42
|
-
* });
|
|
43
|
-
* const $boundary = withBoundary({ $status });
|
|
44
|
-
* const $placement = withPlacement({
|
|
45
|
-
* placement: "vertical-center",
|
|
46
|
-
* $boundary,
|
|
47
|
-
* $anchorMeasurement,
|
|
48
|
-
* $floatingMeasurement,
|
|
49
|
-
* });
|
|
50
|
-
* const $position = withPosition({
|
|
51
|
-
* $boundary,
|
|
52
|
-
* $placement,
|
|
53
|
-
* $anchorMeasurement,
|
|
54
|
-
* $floatingMeasurement,
|
|
55
|
-
* });
|
|
56
|
-
* });
|
|
57
|
-
*
|
|
58
|
-
* getModalPosition("key"); // ModalPosition | undefined
|
|
59
|
-
* ```
|
|
60
|
-
*
|
|
61
|
-
*/
|
|
62
|
-
declare function getModalPosition(key: string): ModalPosition | undefined;
|
|
63
|
-
//#endregion
|
|
64
|
-
export { getModalPosition };
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { $positions } from "./internals.mjs";
|
|
2
|
-
|
|
3
|
-
//#region src/position/getModalPosition.ts
|
|
4
|
-
/**
|
|
5
|
-
* # getModalPosition
|
|
6
|
-
*
|
|
7
|
-
* <Badge type="tip">Reactive</Badge>
|
|
8
|
-
*
|
|
9
|
-
* ```ts
|
|
10
|
-
* function getModalPosition(key: string): ModalPosition | undefined;
|
|
11
|
-
* ```
|
|
12
|
-
*
|
|
13
|
-
* Returns the current result of `withPosition`.
|
|
14
|
-
*
|
|
15
|
-
* ## Example
|
|
16
|
-
*
|
|
17
|
-
* ```ts
|
|
18
|
-
* import {
|
|
19
|
-
* createModal,
|
|
20
|
-
* withModalStatus,
|
|
21
|
-
* withAnchorElement,
|
|
22
|
-
* withAnchorMeasurement,
|
|
23
|
-
* withFloatingElement,
|
|
24
|
-
* withFloatingMeasurement,
|
|
25
|
-
* withBoundary,
|
|
26
|
-
* withPlacement,
|
|
27
|
-
* withPosition,
|
|
28
|
-
* getModalPosition,
|
|
29
|
-
* } from "@monstermann/signals-modal";
|
|
30
|
-
*
|
|
31
|
-
* createModal("key", () => {
|
|
32
|
-
* const { $status } = withModalStatus();
|
|
33
|
-
* const $anchorElement = withAnchorElement();
|
|
34
|
-
* const $floatingElement = withFloatingElement();
|
|
35
|
-
* const $anchorMeasurement = withAnchorMeasurement({
|
|
36
|
-
* $status,
|
|
37
|
-
* $anchorElement,
|
|
38
|
-
* });
|
|
39
|
-
* const $floatingMeasurement = withFloatingMeasurement({
|
|
40
|
-
* $status,
|
|
41
|
-
* $floatingElement,
|
|
42
|
-
* });
|
|
43
|
-
* const $boundary = withBoundary({ $status });
|
|
44
|
-
* const $placement = withPlacement({
|
|
45
|
-
* placement: "vertical-center",
|
|
46
|
-
* $boundary,
|
|
47
|
-
* $anchorMeasurement,
|
|
48
|
-
* $floatingMeasurement,
|
|
49
|
-
* });
|
|
50
|
-
* const $position = withPosition({
|
|
51
|
-
* $boundary,
|
|
52
|
-
* $placement,
|
|
53
|
-
* $anchorMeasurement,
|
|
54
|
-
* $floatingMeasurement,
|
|
55
|
-
* });
|
|
56
|
-
* });
|
|
57
|
-
*
|
|
58
|
-
* getModalPosition("key"); // ModalPosition | undefined
|
|
59
|
-
* ```
|
|
60
|
-
*
|
|
61
|
-
*/
|
|
62
|
-
function getModalPosition(key) {
|
|
63
|
-
return $positions().get(key)?.();
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
//#endregion
|
|
67
|
-
export { getModalPosition };
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
//#region src/status/closeLastModal.d.ts
|
|
2
|
-
/**
|
|
3
|
-
* # closeLastModal
|
|
4
|
-
*
|
|
5
|
-
* ```ts
|
|
6
|
-
* function closeLastModal(): void;
|
|
7
|
-
* ```
|
|
8
|
-
*
|
|
9
|
-
* Closes the last opened modal by setting its status to `"closing"`.
|
|
10
|
-
*
|
|
11
|
-
* ## Example
|
|
12
|
-
*
|
|
13
|
-
* ```ts
|
|
14
|
-
* import { closeLastModal } from "@monstermann/signals-modal";
|
|
15
|
-
*
|
|
16
|
-
* closeLastModal();
|
|
17
|
-
* ```
|
|
18
|
-
*
|
|
19
|
-
*/
|
|
20
|
-
declare function closeLastModal(): void;
|
|
21
|
-
//#endregion
|
|
22
|
-
export { closeLastModal };
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { $openedModals } from "./internals.mjs";
|
|
2
|
-
import { closeModal } from "./closeModal.mjs";
|
|
3
|
-
|
|
4
|
-
//#region src/status/closeLastModal.ts
|
|
5
|
-
/**
|
|
6
|
-
* # closeLastModal
|
|
7
|
-
*
|
|
8
|
-
* ```ts
|
|
9
|
-
* function closeLastModal(): void;
|
|
10
|
-
* ```
|
|
11
|
-
*
|
|
12
|
-
* Closes the last opened modal by setting its status to `"closing"`.
|
|
13
|
-
*
|
|
14
|
-
* ## Example
|
|
15
|
-
*
|
|
16
|
-
* ```ts
|
|
17
|
-
* import { closeLastModal } from "@monstermann/signals-modal";
|
|
18
|
-
*
|
|
19
|
-
* closeLastModal();
|
|
20
|
-
* ```
|
|
21
|
-
*
|
|
22
|
-
*/
|
|
23
|
-
function closeLastModal() {
|
|
24
|
-
const key = Array.from($openedModals()).at(-1);
|
|
25
|
-
if (key) closeModal(key);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
//#endregion
|
|
29
|
-
export { closeLastModal };
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
//#region src/utils/closeLastModalOnClickOutside.d.ts
|
|
2
|
-
/**
|
|
3
|
-
* # closeLastModalOnClickOutside
|
|
4
|
-
*
|
|
5
|
-
* ```ts
|
|
6
|
-
* function closeLastModalOnClickOutside(): void;
|
|
7
|
-
* ```
|
|
8
|
-
*
|
|
9
|
-
* Sets up a global `mousedown` listener that closes the last opened modal when clicked outside the floating element.
|
|
10
|
-
*
|
|
11
|
-
* ## Example
|
|
12
|
-
*
|
|
13
|
-
* ```ts
|
|
14
|
-
* import { closeLastModalOnClickOutside } from "@monstermann/signals-modal";
|
|
15
|
-
*
|
|
16
|
-
* closeLastModalOnClickOutside();
|
|
17
|
-
* ```
|
|
18
|
-
*
|
|
19
|
-
*/
|
|
20
|
-
declare function closeLastModalOnClickOutside(): void;
|
|
21
|
-
//#endregion
|
|
22
|
-
export { closeLastModalOnClickOutside };
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { $openedModals } from "../status/internals.mjs";
|
|
2
|
-
import { closeModal } from "../status/closeModal.mjs";
|
|
3
|
-
import { getFloatingElement } from "../floating/getFloatingElement.mjs";
|
|
4
|
-
import { findParentElement } from "../internals/findParentElement.mjs";
|
|
5
|
-
|
|
6
|
-
//#region src/utils/closeLastModalOnClickOutside.ts
|
|
7
|
-
/**
|
|
8
|
-
* # closeLastModalOnClickOutside
|
|
9
|
-
*
|
|
10
|
-
* ```ts
|
|
11
|
-
* function closeLastModalOnClickOutside(): void;
|
|
12
|
-
* ```
|
|
13
|
-
*
|
|
14
|
-
* Sets up a global `mousedown` listener that closes the last opened modal when clicked outside the floating element.
|
|
15
|
-
*
|
|
16
|
-
* ## Example
|
|
17
|
-
*
|
|
18
|
-
* ```ts
|
|
19
|
-
* import { closeLastModalOnClickOutside } from "@monstermann/signals-modal";
|
|
20
|
-
*
|
|
21
|
-
* closeLastModalOnClickOutside();
|
|
22
|
-
* ```
|
|
23
|
-
*
|
|
24
|
-
*/
|
|
25
|
-
function closeLastModalOnClickOutside() {
|
|
26
|
-
document.addEventListener("mousedown", (evt) => {
|
|
27
|
-
const key = Array.from($openedModals()).at(-1);
|
|
28
|
-
if (!key) return;
|
|
29
|
-
const target = evt.target;
|
|
30
|
-
const floating = getFloatingElement(key);
|
|
31
|
-
if (!floating) return;
|
|
32
|
-
if (!findParentElement(target, (el) => el === floating)) closeModal(key);
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
//#endregion
|
|
37
|
-
export { closeLastModalOnClickOutside };
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
//#region src/utils/closeLastModalOnEsc.d.ts
|
|
2
|
-
/**
|
|
3
|
-
* # closeLastModalOnEsc
|
|
4
|
-
*
|
|
5
|
-
* ```ts
|
|
6
|
-
* function closeLastModalOnEsc(): void;
|
|
7
|
-
* ```
|
|
8
|
-
*
|
|
9
|
-
* Sets up a global `keydown` listener that closes the last opened modal when `esc` is pressed, unless the target was an editable element such as `<input>`.
|
|
10
|
-
*
|
|
11
|
-
* ## Example
|
|
12
|
-
*
|
|
13
|
-
* ```ts
|
|
14
|
-
* import { closeLastModalOnEsc } from "@monstermann/signals-modal";
|
|
15
|
-
*
|
|
16
|
-
* closeLastModalOnEsc();
|
|
17
|
-
* ```
|
|
18
|
-
*
|
|
19
|
-
*/
|
|
20
|
-
declare function closeLastModalOnEsc(): void;
|
|
21
|
-
//#endregion
|
|
22
|
-
export { closeLastModalOnEsc };
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { $openedModals } from "../status/internals.mjs";
|
|
2
|
-
import { closeModal } from "../status/closeModal.mjs";
|
|
3
|
-
import { findParentElement } from "../internals/findParentElement.mjs";
|
|
4
|
-
|
|
5
|
-
//#region src/utils/closeLastModalOnEsc.ts
|
|
6
|
-
/**
|
|
7
|
-
* # closeLastModalOnEsc
|
|
8
|
-
*
|
|
9
|
-
* ```ts
|
|
10
|
-
* function closeLastModalOnEsc(): void;
|
|
11
|
-
* ```
|
|
12
|
-
*
|
|
13
|
-
* Sets up a global `keydown` listener that closes the last opened modal when `esc` is pressed, unless the target was an editable element such as `<input>`.
|
|
14
|
-
*
|
|
15
|
-
* ## Example
|
|
16
|
-
*
|
|
17
|
-
* ```ts
|
|
18
|
-
* import { closeLastModalOnEsc } from "@monstermann/signals-modal";
|
|
19
|
-
*
|
|
20
|
-
* closeLastModalOnEsc();
|
|
21
|
-
* ```
|
|
22
|
-
*
|
|
23
|
-
*/
|
|
24
|
-
function closeLastModalOnEsc() {
|
|
25
|
-
document.addEventListener("keydown", (evt) => {
|
|
26
|
-
if (evt.key !== "Escape") return;
|
|
27
|
-
const key = Array.from($openedModals()).at(-1);
|
|
28
|
-
if (!key) return;
|
|
29
|
-
const target = evt.target;
|
|
30
|
-
if (!(target.nodeName === "INPUT" || target.nodeName === "TEXTAREA" || findParentElement(target, (el) => el.getAttribute("contenteditable") === "true"))) closeModal(key);
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
//#endregion
|
|
35
|
-
export { closeLastModalOnEsc };
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
//#region src/utils/syncModalGroupsToBody.d.ts
|
|
2
|
-
/**
|
|
3
|
-
* # syncModalGroupsToBody
|
|
4
|
-
*
|
|
5
|
-
* ```ts
|
|
6
|
-
* function syncModalGroupsToBody(): void;
|
|
7
|
-
* ```
|
|
8
|
-
*
|
|
9
|
-
* Sets up a global `Effect` that adds `has-${group}` class names to `document.body` for opened modals.
|
|
10
|
-
*
|
|
11
|
-
* ## Example
|
|
12
|
-
*
|
|
13
|
-
* ```ts
|
|
14
|
-
* import {
|
|
15
|
-
* createModal,
|
|
16
|
-
* withModalGroups,
|
|
17
|
-
* withModalStatus,
|
|
18
|
-
* syncModalGroupsToBody,
|
|
19
|
-
* openModal,
|
|
20
|
-
* closeModal,
|
|
21
|
-
* } from "@monstermann/signals-modal";
|
|
22
|
-
*
|
|
23
|
-
* syncModalGroupsToBody();
|
|
24
|
-
*
|
|
25
|
-
* const modal = createModal("key", () => {
|
|
26
|
-
* const $groups = withModalGroups(["dialog"]);
|
|
27
|
-
* const { $status } = withModalStatus();
|
|
28
|
-
* return { $groups, $status };
|
|
29
|
-
* });
|
|
30
|
-
*
|
|
31
|
-
* document.body.classList; // []
|
|
32
|
-
* openModal("key");
|
|
33
|
-
* document.body.classList; // ["has-dialog"]
|
|
34
|
-
* closeModal("key");
|
|
35
|
-
* document.body.classList; // []
|
|
36
|
-
* ```
|
|
37
|
-
*
|
|
38
|
-
*/
|
|
39
|
-
declare function syncModalGroupsToBody(): void;
|
|
40
|
-
//#endregion
|
|
41
|
-
export { syncModalGroupsToBody };
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import { getGroupsForModal } from "../groups/getGroupsForModal.mjs";
|
|
2
|
-
import { getVisibleModals } from "../status/getVisibleModals.mjs";
|
|
3
|
-
import { INTERNAL, effect, memo } from "@monstermann/signals";
|
|
4
|
-
|
|
5
|
-
//#region src/utils/syncModalGroupsToBody.ts
|
|
6
|
-
const path = "@signals-modal/utils/syncModalGroupsToBody.ts";
|
|
7
|
-
const meta = {
|
|
8
|
-
path,
|
|
9
|
-
line: 5,
|
|
10
|
-
name: "$classes"
|
|
11
|
-
};
|
|
12
|
-
const meta1 = {
|
|
13
|
-
path,
|
|
14
|
-
line: 54,
|
|
15
|
-
name: "syncModalGroupsToBody"
|
|
16
|
-
};
|
|
17
|
-
const $classes = memo(() => {
|
|
18
|
-
const modals = getVisibleModals();
|
|
19
|
-
const clx = /* @__PURE__ */ new Set();
|
|
20
|
-
for (const modal of modals) for (const group of getGroupsForModal(modal)) clx.add(`has-${group}`);
|
|
21
|
-
return Array.from(clx).sort().join(" ");
|
|
22
|
-
}, INTERNAL, meta);
|
|
23
|
-
/**
|
|
24
|
-
* # syncModalGroupsToBody
|
|
25
|
-
*
|
|
26
|
-
* ```ts
|
|
27
|
-
* function syncModalGroupsToBody(): void;
|
|
28
|
-
* ```
|
|
29
|
-
*
|
|
30
|
-
* Sets up a global `Effect` that adds `has-${group}` class names to `document.body` for opened modals.
|
|
31
|
-
*
|
|
32
|
-
* ## Example
|
|
33
|
-
*
|
|
34
|
-
* ```ts
|
|
35
|
-
* import {
|
|
36
|
-
* createModal,
|
|
37
|
-
* withModalGroups,
|
|
38
|
-
* withModalStatus,
|
|
39
|
-
* syncModalGroupsToBody,
|
|
40
|
-
* openModal,
|
|
41
|
-
* closeModal,
|
|
42
|
-
* } from "@monstermann/signals-modal";
|
|
43
|
-
*
|
|
44
|
-
* syncModalGroupsToBody();
|
|
45
|
-
*
|
|
46
|
-
* const modal = createModal("key", () => {
|
|
47
|
-
* const $groups = withModalGroups(["dialog"]);
|
|
48
|
-
* const { $status } = withModalStatus();
|
|
49
|
-
* return { $groups, $status };
|
|
50
|
-
* });
|
|
51
|
-
*
|
|
52
|
-
* document.body.classList; // []
|
|
53
|
-
* openModal("key");
|
|
54
|
-
* document.body.classList; // ["has-dialog"]
|
|
55
|
-
* closeModal("key");
|
|
56
|
-
* document.body.classList; // []
|
|
57
|
-
* ```
|
|
58
|
-
*
|
|
59
|
-
*/
|
|
60
|
-
function syncModalGroupsToBody() {
|
|
61
|
-
effect(() => {
|
|
62
|
-
if (!$classes()) return;
|
|
63
|
-
const classes = $classes().split(" ");
|
|
64
|
-
document.body.classList.add(...classes);
|
|
65
|
-
return () => {
|
|
66
|
-
document.body.classList.remove(...classes);
|
|
67
|
-
};
|
|
68
|
-
}, INTERNAL, meta1);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
//#endregion
|
|
72
|
-
export { syncModalGroupsToBody };
|