@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.
Files changed (124) hide show
  1. package/README.md +2011 -0
  2. package/dist/anchor/getAnchorElement.d.mts +30 -0
  3. package/dist/anchor/getAnchorElement.mjs +30 -0
  4. package/dist/anchor/getAnchorMeasurement.d.mts +39 -1
  5. package/dist/anchor/getAnchorMeasurement.mjs +37 -0
  6. package/dist/anchor/setAnchorElement.d.mts +26 -0
  7. package/dist/anchor/setAnchorElement.mjs +26 -0
  8. package/dist/anchor/withAnchorElement.d.mts +31 -0
  9. package/dist/anchor/withAnchorElement.mjs +31 -1
  10. package/dist/anchor/withAnchorMeasurement.d.mts +44 -1
  11. package/dist/anchor/withAnchorMeasurement.mjs +45 -3
  12. package/dist/anchor/withMouseAnchor.d.mts +35 -1
  13. package/dist/anchor/withMouseAnchor.mjs +36 -3
  14. package/dist/createModal.d.mts +29 -0
  15. package/dist/createModal.mjs +29 -0
  16. package/dist/floating/getFloatingElement.d.mts +30 -0
  17. package/dist/floating/getFloatingElement.mjs +30 -0
  18. package/dist/floating/getFloatingMeasurement.d.mts +39 -1
  19. package/dist/floating/getFloatingMeasurement.mjs +37 -0
  20. package/dist/floating/setFloatingElement.d.mts +26 -0
  21. package/dist/floating/setFloatingElement.mjs +26 -0
  22. package/dist/floating/withFloatingElement.d.mts +31 -0
  23. package/dist/floating/withFloatingElement.mjs +31 -1
  24. package/dist/floating/withFloatingMeasurement.d.mts +42 -1
  25. package/dist/floating/withFloatingMeasurement.mjs +43 -3
  26. package/dist/groups/getDialogs.d.mts +29 -0
  27. package/dist/groups/getDialogs.mjs +29 -0
  28. package/dist/groups/getGroupsForModal.d.mts +29 -0
  29. package/dist/groups/getGroupsForModal.mjs +29 -0
  30. package/dist/groups/getModalsForGroup.d.mts +29 -0
  31. package/dist/groups/getModalsForGroup.mjs +29 -0
  32. package/dist/groups/getPopovers.d.mts +29 -0
  33. package/dist/groups/getPopovers.mjs +29 -0
  34. package/dist/groups/getTooltips.d.mts +29 -0
  35. package/dist/groups/getTooltips.mjs +29 -0
  36. package/dist/groups/isDialog.d.mts +29 -0
  37. package/dist/groups/isDialog.mjs +29 -0
  38. package/dist/groups/isModalInGroup.d.mts +29 -0
  39. package/dist/groups/isModalInGroup.mjs +29 -0
  40. package/dist/groups/isPopover.d.mts +29 -0
  41. package/dist/groups/isPopover.mjs +29 -0
  42. package/dist/groups/isTooltip.d.mts +29 -0
  43. package/dist/groups/isTooltip.mjs +29 -0
  44. package/dist/groups/modalGroups.mjs +42 -0
  45. package/dist/groups/withModalGroups.d.mts +30 -0
  46. package/dist/groups/withModalGroups.mjs +30 -1
  47. package/dist/position/getModalPlacement.d.mts +50 -0
  48. package/dist/position/getModalPlacement.mjs +49 -0
  49. package/dist/position/getModalPosition.d.mts +59 -0
  50. package/dist/position/getModalPosition.mjs +58 -0
  51. package/dist/position/withBoundary.d.mts +32 -1
  52. package/dist/position/withBoundary.mjs +33 -3
  53. package/dist/position/withPlacement.d.mts +78 -1
  54. package/dist/position/withPlacement.mjs +78 -1
  55. package/dist/position/withPosition.d.mts +67 -1
  56. package/dist/position/withPosition.mjs +68 -2
  57. package/dist/scroll/withCloseOnScroll.d.mts +37 -0
  58. package/dist/scroll/withCloseOnScroll.mjs +37 -1
  59. package/dist/status/closeAllModals.d.mts +33 -0
  60. package/dist/status/closeAllModals.mjs +33 -0
  61. package/dist/status/closeLastModal.d.mts +18 -0
  62. package/dist/status/closeLastModal.mjs +18 -0
  63. package/dist/status/closeModal.d.mts +28 -0
  64. package/dist/status/closeModal.mjs +28 -0
  65. package/dist/status/getClosedModals.d.mts +32 -0
  66. package/dist/status/getClosedModals.mjs +32 -0
  67. package/dist/status/getClosingModals.d.mts +36 -0
  68. package/dist/status/getClosingModals.mjs +36 -0
  69. package/dist/status/getModalStatus.d.mts +31 -0
  70. package/dist/status/getModalStatus.mjs +30 -0
  71. package/dist/status/getOpenModals.d.mts +36 -0
  72. package/dist/status/getOpenModals.mjs +36 -0
  73. package/dist/status/getOpenedModals.d.mts +32 -0
  74. package/dist/status/getOpenedModals.mjs +32 -0
  75. package/dist/status/getOpeningModals.d.mts +36 -0
  76. package/dist/status/getOpeningModals.mjs +36 -0
  77. package/dist/status/getVisibleModals.d.mts +36 -0
  78. package/dist/status/getVisibleModals.mjs +36 -0
  79. package/dist/status/internals.mjs +15 -6
  80. package/dist/status/isAnyModalClosed.d.mts +32 -0
  81. package/dist/status/isAnyModalClosed.mjs +32 -0
  82. package/dist/status/isAnyModalClosing.d.mts +35 -0
  83. package/dist/status/isAnyModalClosing.mjs +35 -0
  84. package/dist/status/isAnyModalOpen.d.mts +32 -0
  85. package/dist/status/isAnyModalOpen.mjs +32 -0
  86. package/dist/status/isAnyModalOpened.d.mts +32 -0
  87. package/dist/status/isAnyModalOpened.mjs +32 -0
  88. package/dist/status/isAnyModalOpening.d.mts +35 -0
  89. package/dist/status/isAnyModalOpening.mjs +35 -0
  90. package/dist/status/isAnyModalVisible.d.mts +32 -0
  91. package/dist/status/isAnyModalVisible.mjs +32 -0
  92. package/dist/status/isModalClosed.d.mts +28 -0
  93. package/dist/status/isModalClosed.mjs +28 -0
  94. package/dist/status/isModalClosing.d.mts +32 -0
  95. package/dist/status/isModalClosing.mjs +32 -0
  96. package/dist/status/isModalOpen.d.mts +28 -0
  97. package/dist/status/isModalOpen.mjs +28 -0
  98. package/dist/status/isModalOpened.d.mts +30 -0
  99. package/dist/status/isModalOpened.mjs +30 -0
  100. package/dist/status/isModalOpening.d.mts +30 -0
  101. package/dist/status/isModalOpening.mjs +30 -0
  102. package/dist/status/isModalVisible.d.mts +30 -0
  103. package/dist/status/isModalVisible.mjs +30 -0
  104. package/dist/status/onModalClosed.d.mts +33 -2
  105. package/dist/status/onModalClosed.mjs +31 -1
  106. package/dist/status/onModalClosing.d.mts +33 -2
  107. package/dist/status/onModalClosing.mjs +31 -1
  108. package/dist/status/onModalOpened.d.mts +31 -0
  109. package/dist/status/onModalOpened.mjs +31 -1
  110. package/dist/status/onModalOpening.d.mts +31 -0
  111. package/dist/status/onModalOpening.mjs +31 -1
  112. package/dist/status/openModal.d.mts +26 -0
  113. package/dist/status/openModal.mjs +26 -0
  114. package/dist/status/setModalStatus.d.mts +29 -0
  115. package/dist/status/setModalStatus.mjs +28 -0
  116. package/dist/status/withModalStatus.d.mts +41 -0
  117. package/dist/status/withModalStatus.mjs +43 -3
  118. package/dist/utils/closeLastModalOnClickOutside.d.mts +18 -0
  119. package/dist/utils/closeLastModalOnClickOutside.mjs +18 -0
  120. package/dist/utils/closeLastModalOnEsc.d.mts +18 -0
  121. package/dist/utils/closeLastModalOnEsc.mjs +18 -0
  122. package/dist/utils/syncModalGroupsToBody.d.mts +37 -0
  123. package/dist/utils/syncModalGroupsToBody.mjs +38 -1
  124. package/package.json +6 -5
@@ -8,19 +8,49 @@ import { fromWindow } from "@monstermann/geometry/Rect/fromWindow.mjs";
8
8
  const path = "@signals-modal/position/withBoundary.ts";
9
9
  const meta = {
10
10
  path,
11
- line: 15,
11
+ line: 45,
12
12
  name: "withBoundary.$rect"
13
13
  };
14
14
  const meta1 = {
15
15
  path,
16
- line: 20,
16
+ line: 50,
17
17
  name: "withBoundary.$boundary"
18
18
  };
19
19
  const meta2 = {
20
20
  path,
21
- line: 24,
21
+ line: 54,
22
22
  name: "withBoundary"
23
23
  };
24
+ /**
25
+ * # withBoundary
26
+ *
27
+ * ```ts
28
+ * function withBoundary(options: {
29
+ * $status: Reactive<ModalStatus>;
30
+ * transform?: (rect: Rect) => Rect;
31
+ * }): Memo<Rect>;
32
+ * ```
33
+ *
34
+ * Constructs a `Rect` resembling the window dimensions, to be fed into `withPlacement` and `withPosition`, used to constrain the floating element to be within the window boundary. This function must be called inside a `createModal` callback.
35
+ *
36
+ * The optional `transform` option can be used to eg. make the `Rect` smaller, increasing the distance between the floating element and the edges of the window.
37
+ *
38
+ * ## Example
39
+ *
40
+ * ```ts
41
+ * import {
42
+ * createModal,
43
+ * withModalStatus,
44
+ * withBoundary,
45
+ * } from "@monstermann/signals-modal";
46
+ *
47
+ * createModal("key", () => {
48
+ * const { $status } = withModalStatus();
49
+ * const $boundary = withBoundary({ $status });
50
+ * });
51
+ * ```
52
+ *
53
+ */
24
54
  function withBoundary(options) {
25
55
  const modal = currentModal();
26
56
  const $rect = signal(origin, {
@@ -1,9 +1,86 @@
1
1
  import { Memo } from "@monstermann/signals";
2
- import { Rect } from "@monstermann/fn";
2
+ import { Rect } from "@monstermann/geometry";
3
3
 
4
4
  //#region src/position/withPlacement.d.ts
5
5
  type ModalPlacementOption = "vertical-center" | "vertical-left" | "vertical-right" | "horizontal-center" | "horizontal-up" | "horizontal-down" | "up-center" | "down-center" | "left-down" | "right-down";
6
6
  type ModalPlacement = "down-center" | "down-left" | "down-right" | "left-center" | "left-down" | "left-up" | "right-center" | "right-down" | "right-up" | "up-center" | "up-left" | "up-right";
7
+ /**
8
+ * # withPlacement
9
+ *
10
+ * ```ts
11
+ * function withPlacement(options: {
12
+ * placement: ModalPlacementOption;
13
+ * $boundary: () => Rect;
14
+ * $anchorMeasurement: () => Rect;
15
+ * $floatingMeasurement: () => Rect;
16
+ * }): Memo<ModalPlacement>;
17
+ *
18
+ * type ModalPlacementOption =
19
+ * | "vertical-center"
20
+ * | "vertical-left"
21
+ * | "vertical-right"
22
+ * | "horizontal-center"
23
+ * | "horizontal-up"
24
+ * | "horizontal-down"
25
+ * | "up-center"
26
+ * | "down-center"
27
+ * | "left-down"
28
+ * | "right-down";
29
+ *
30
+ * type ModalPlacement =
31
+ * | "down-center"
32
+ * | "down-left"
33
+ * | "down-right"
34
+ * | "left-center"
35
+ * | "left-down"
36
+ * | "left-up"
37
+ * | "right-center"
38
+ * | "right-down"
39
+ * | "right-up"
40
+ * | "up-center"
41
+ * | "up-left"
42
+ * | "up-right";
43
+ * ```
44
+ *
45
+ * Takes a `ModalPlacementOption` and resolves it to `ModalPlacement`, picking whichever side has more space. This function must be called inside a `createModal` callback.
46
+ *
47
+ * ## Example
48
+ *
49
+ * ```ts
50
+ * import {
51
+ * createModal,
52
+ * withModalStatus,
53
+ * withAnchorElement,
54
+ * withAnchorMeasurement,
55
+ * withFloatingElement,
56
+ * withFloatingMeasurement,
57
+ * withBoundary,
58
+ * withPlacement,
59
+ * } from "@monstermann/signals-modal";
60
+ *
61
+ * createModal("key", () => {
62
+ * const { $status } = withModalStatus();
63
+ * const $anchorElement = withAnchorElement();
64
+ * const $floatingElement = withFloatingElement();
65
+ * const $anchorMeasurement = withAnchorMeasurement({
66
+ * $status,
67
+ * $anchorElement,
68
+ * });
69
+ * const $floatingMeasurement = withFloatingMeasurement({
70
+ * $status,
71
+ * $floatingElement,
72
+ * });
73
+ * const $boundary = withBoundary({ $status });
74
+ * const $placement = withPlacement({
75
+ * placement: "vertical-center",
76
+ * $boundary,
77
+ * $anchorMeasurement,
78
+ * $floatingMeasurement,
79
+ * });
80
+ * });
81
+ * ```
82
+ *
83
+ */
7
84
  declare function withPlacement(options: {
8
85
  placement: ModalPlacementOption;
9
86
  $anchorMeasurement: () => Rect;
@@ -7,7 +7,7 @@ import { height } from "@monstermann/geometry/Rect/height.mjs";
7
7
  //#region src/position/withPlacement.ts
8
8
  const meta = {
9
9
  path: "@signals-modal/position/withPlacement.ts",
10
- line: 97,
10
+ line: 174,
11
11
  name: "withPlacement.$placement"
12
12
  };
13
13
  const placementResolvers = {
@@ -40,6 +40,83 @@ const placementResolvers = {
40
40
  return height(getBoundaryDown(o.boundary, o.anchor)) >= height(up) ? "down-right" : "up-right";
41
41
  }
42
42
  };
43
+ /**
44
+ * # withPlacement
45
+ *
46
+ * ```ts
47
+ * function withPlacement(options: {
48
+ * placement: ModalPlacementOption;
49
+ * $boundary: () => Rect;
50
+ * $anchorMeasurement: () => Rect;
51
+ * $floatingMeasurement: () => Rect;
52
+ * }): Memo<ModalPlacement>;
53
+ *
54
+ * type ModalPlacementOption =
55
+ * | "vertical-center"
56
+ * | "vertical-left"
57
+ * | "vertical-right"
58
+ * | "horizontal-center"
59
+ * | "horizontal-up"
60
+ * | "horizontal-down"
61
+ * | "up-center"
62
+ * | "down-center"
63
+ * | "left-down"
64
+ * | "right-down";
65
+ *
66
+ * type ModalPlacement =
67
+ * | "down-center"
68
+ * | "down-left"
69
+ * | "down-right"
70
+ * | "left-center"
71
+ * | "left-down"
72
+ * | "left-up"
73
+ * | "right-center"
74
+ * | "right-down"
75
+ * | "right-up"
76
+ * | "up-center"
77
+ * | "up-left"
78
+ * | "up-right";
79
+ * ```
80
+ *
81
+ * Takes a `ModalPlacementOption` and resolves it to `ModalPlacement`, picking whichever side has more space. This function must be called inside a `createModal` callback.
82
+ *
83
+ * ## Example
84
+ *
85
+ * ```ts
86
+ * import {
87
+ * createModal,
88
+ * withModalStatus,
89
+ * withAnchorElement,
90
+ * withAnchorMeasurement,
91
+ * withFloatingElement,
92
+ * withFloatingMeasurement,
93
+ * withBoundary,
94
+ * withPlacement,
95
+ * } from "@monstermann/signals-modal";
96
+ *
97
+ * createModal("key", () => {
98
+ * const { $status } = withModalStatus();
99
+ * const $anchorElement = withAnchorElement();
100
+ * const $floatingElement = withFloatingElement();
101
+ * const $anchorMeasurement = withAnchorMeasurement({
102
+ * $status,
103
+ * $anchorElement,
104
+ * });
105
+ * const $floatingMeasurement = withFloatingMeasurement({
106
+ * $status,
107
+ * $floatingElement,
108
+ * });
109
+ * const $boundary = withBoundary({ $status });
110
+ * const $placement = withPlacement({
111
+ * placement: "vertical-center",
112
+ * $boundary,
113
+ * $anchorMeasurement,
114
+ * $floatingMeasurement,
115
+ * });
116
+ * });
117
+ * ```
118
+ *
119
+ */
43
120
  function withPlacement(options) {
44
121
  const modal = currentModal();
45
122
  const $placement = memo(() => {
@@ -1,6 +1,6 @@
1
1
  import { ModalPlacement } from "./withPlacement.mjs";
2
2
  import { Memo } from "@monstermann/signals";
3
- import { Rect } from "@monstermann/fn";
3
+ import { Rect } from "@monstermann/geometry";
4
4
 
5
5
  //#region src/position/withPosition.d.ts
6
6
  interface ModalPosition {
@@ -11,6 +11,72 @@ interface ModalPosition {
11
11
  originX: number;
12
12
  originY: number;
13
13
  }
14
+ /**
15
+ * # withPosition
16
+ *
17
+ * ```ts
18
+ * function withPosition(options: {
19
+ * $boundary: () => Rect;
20
+ * $placement: () => ModalPlacement;
21
+ * $anchorMeasurement: () => Rect;
22
+ * $floatingMeasurement: () => Rect;
23
+ * transform?: (rect: Rect) => Rect;
24
+ * }): Memo<{
25
+ * floatingX: number;
26
+ * floatingY: number;
27
+ * maxHeight: number;
28
+ * maxWidth: number;
29
+ * originX: number;
30
+ * originY: number;
31
+ * }>;
32
+ * ```
33
+ *
34
+ * Consumes a range of measurements and calculates the final position for the floating element. This function must be called inside a `createModal` callback.
35
+ *
36
+ * ## Example
37
+ *
38
+ * ```ts
39
+ * import {
40
+ * createModal,
41
+ * withModalStatus,
42
+ * withAnchorElement,
43
+ * withAnchorMeasurement,
44
+ * withFloatingElement,
45
+ * withFloatingMeasurement,
46
+ * withBoundary,
47
+ * withPlacement,
48
+ * withPosition,
49
+ * } from "@monstermann/signals-modal";
50
+ *
51
+ * createModal("key", () => {
52
+ * const { $status } = withModalStatus();
53
+ * const $anchorElement = withAnchorElement();
54
+ * const $floatingElement = withFloatingElement();
55
+ * const $anchorMeasurement = withAnchorMeasurement({
56
+ * $status,
57
+ * $anchorElement,
58
+ * });
59
+ * const $floatingMeasurement = withFloatingMeasurement({
60
+ * $status,
61
+ * $floatingElement,
62
+ * });
63
+ * const $boundary = withBoundary({ $status });
64
+ * const $placement = withPlacement({
65
+ * placement: "vertical-center",
66
+ * $boundary,
67
+ * $anchorMeasurement,
68
+ * $floatingMeasurement,
69
+ * });
70
+ * const $position = withPosition({
71
+ * $boundary,
72
+ * $placement,
73
+ * $anchorMeasurement,
74
+ * $floatingMeasurement,
75
+ * });
76
+ * });
77
+ * ```
78
+ *
79
+ */
14
80
  declare function withPosition(options: {
15
81
  $anchorMeasurement: () => Rect;
16
82
  $boundary: () => Rect;
@@ -7,7 +7,7 @@ import { left } from "@monstermann/geometry/Rect/left.mjs";
7
7
  import { right } from "@monstermann/geometry/Rect/right.mjs";
8
8
  import { width } from "@monstermann/geometry/Rect/width.mjs";
9
9
  import { height } from "@monstermann/geometry/Rect/height.mjs";
10
- import { pipe } from "@monstermann/fn";
10
+ import { pipe } from "@monstermann/dfdl";
11
11
  import { alignCenterX } from "@monstermann/geometry/Rect/alignCenterX.mjs";
12
12
  import { snapBelow } from "@monstermann/geometry/Rect/snapBelow.mjs";
13
13
  import { clamp } from "@monstermann/geometry/Rect/clamp.mjs";
@@ -26,7 +26,7 @@ import { snapAbove } from "@monstermann/geometry/Rect/snapAbove.mjs";
26
26
  //#region src/position/withPosition.ts
27
27
  const meta = {
28
28
  path: "@signals-modal/position/withPosition.ts",
29
- line: 313,
29
+ line: 378,
30
30
  name: "withPosition.$position"
31
31
  };
32
32
  const positionResolvers = {
@@ -195,6 +195,72 @@ const positionResolvers = {
195
195
  };
196
196
  }
197
197
  };
198
+ /**
199
+ * # withPosition
200
+ *
201
+ * ```ts
202
+ * function withPosition(options: {
203
+ * $boundary: () => Rect;
204
+ * $placement: () => ModalPlacement;
205
+ * $anchorMeasurement: () => Rect;
206
+ * $floatingMeasurement: () => Rect;
207
+ * transform?: (rect: Rect) => Rect;
208
+ * }): Memo<{
209
+ * floatingX: number;
210
+ * floatingY: number;
211
+ * maxHeight: number;
212
+ * maxWidth: number;
213
+ * originX: number;
214
+ * originY: number;
215
+ * }>;
216
+ * ```
217
+ *
218
+ * Consumes a range of measurements and calculates the final position for the floating element. This function must be called inside a `createModal` callback.
219
+ *
220
+ * ## Example
221
+ *
222
+ * ```ts
223
+ * import {
224
+ * createModal,
225
+ * withModalStatus,
226
+ * withAnchorElement,
227
+ * withAnchorMeasurement,
228
+ * withFloatingElement,
229
+ * withFloatingMeasurement,
230
+ * withBoundary,
231
+ * withPlacement,
232
+ * withPosition,
233
+ * } from "@monstermann/signals-modal";
234
+ *
235
+ * createModal("key", () => {
236
+ * const { $status } = withModalStatus();
237
+ * const $anchorElement = withAnchorElement();
238
+ * const $floatingElement = withFloatingElement();
239
+ * const $anchorMeasurement = withAnchorMeasurement({
240
+ * $status,
241
+ * $anchorElement,
242
+ * });
243
+ * const $floatingMeasurement = withFloatingMeasurement({
244
+ * $status,
245
+ * $floatingElement,
246
+ * });
247
+ * const $boundary = withBoundary({ $status });
248
+ * const $placement = withPlacement({
249
+ * placement: "vertical-center",
250
+ * $boundary,
251
+ * $anchorMeasurement,
252
+ * $floatingMeasurement,
253
+ * });
254
+ * const $position = withPosition({
255
+ * $boundary,
256
+ * $placement,
257
+ * $anchorMeasurement,
258
+ * $floatingMeasurement,
259
+ * });
260
+ * });
261
+ * ```
262
+ *
263
+ */
198
264
  function withPosition(options) {
199
265
  const modal = currentModal();
200
266
  const $position = memo(() => {
@@ -2,6 +2,43 @@ import { ModalStatus } from "../status/types.mjs";
2
2
  import { Reactive } from "@monstermann/signals";
3
3
 
4
4
  //#region src/scroll/withCloseOnScroll.d.ts
5
+
6
+ /**
7
+ * # withCloseOnScroll
8
+ *
9
+ * ```ts
10
+ * function withCloseOnScroll(options: {
11
+ * $anchorElement: Reactive<HTMLElement | null>;
12
+ * $status: Reactive<ModalStatus>;
13
+ * }): void;
14
+ * ```
15
+ *
16
+ * Automatically closes the modal when any scrollable ancestor of the anchor element is scrolled. This function must be called inside a `createModal` callback.
17
+ *
18
+ * The function listens for scroll events on all scrollable parent elements of the anchor element and triggers a close when scrolling occurs. Scroll listeners are only active when the modal is opening or opened (not when closing or closed).
19
+ *
20
+ * ## Example
21
+ *
22
+ * ```ts
23
+ * import {
24
+ * createModal,
25
+ * withModalStatus,
26
+ * withAnchorElement,
27
+ * withCloseOnScroll,
28
+ * } from "@monstermann/signals-modal";
29
+ *
30
+ * createModal("key", () => {
31
+ * const { $status } = withModalStatus();
32
+ * const $anchorElement = withAnchorElement();
33
+ *
34
+ * withCloseOnScroll({
35
+ * $status,
36
+ * $anchorElement,
37
+ * });
38
+ * });
39
+ * ```
40
+ *
41
+ */
5
42
  declare function withCloseOnScroll(options: {
6
43
  $anchorElement: Reactive<HTMLElement | null>;
7
44
  $status: Reactive<ModalStatus>;
@@ -5,9 +5,45 @@ import { INTERNAL, effect } from "@monstermann/signals";
5
5
  //#region src/scroll/withCloseOnScroll.ts
6
6
  const meta = {
7
7
  path: "@signals-modal/scroll/withCloseOnScroll.ts",
8
- line: 13,
8
+ line: 49,
9
9
  name: "withCloseOnScroll"
10
10
  };
11
+ /**
12
+ * # withCloseOnScroll
13
+ *
14
+ * ```ts
15
+ * function withCloseOnScroll(options: {
16
+ * $anchorElement: Reactive<HTMLElement | null>;
17
+ * $status: Reactive<ModalStatus>;
18
+ * }): void;
19
+ * ```
20
+ *
21
+ * Automatically closes the modal when any scrollable ancestor of the anchor element is scrolled. This function must be called inside a `createModal` callback.
22
+ *
23
+ * The function listens for scroll events on all scrollable parent elements of the anchor element and triggers a close when scrolling occurs. Scroll listeners are only active when the modal is opening or opened (not when closing or closed).
24
+ *
25
+ * ## Example
26
+ *
27
+ * ```ts
28
+ * import {
29
+ * createModal,
30
+ * withModalStatus,
31
+ * withAnchorElement,
32
+ * withCloseOnScroll,
33
+ * } from "@monstermann/signals-modal";
34
+ *
35
+ * createModal("key", () => {
36
+ * const { $status } = withModalStatus();
37
+ * const $anchorElement = withAnchorElement();
38
+ *
39
+ * withCloseOnScroll({
40
+ * $status,
41
+ * $anchorElement,
42
+ * });
43
+ * });
44
+ * ```
45
+ *
46
+ */
11
47
  function withCloseOnScroll(options) {
12
48
  const modal = currentModal();
13
49
  const onScroll = () => closeModal(modal.key);
@@ -1,4 +1,37 @@
1
1
  //#region src/status/closeAllModals.d.ts
2
+ /**
3
+ * # closeAllModals
4
+ *
5
+ * ```ts
6
+ * function closeAllModals(): void;
7
+ * ```
8
+ *
9
+ * Closes all modals by setting their status to `"closing"`. Skips modals that are already `"closing"` or `"closed"`.
10
+ *
11
+ * ## Example
12
+ *
13
+ * ```ts
14
+ * import {
15
+ * createModal,
16
+ * withModalStatus,
17
+ * openModal,
18
+ * closeAllModals,
19
+ * } from "@monstermann/signals-modal";
20
+ *
21
+ * createModal("modal1", () => {
22
+ * withModalStatus();
23
+ * });
24
+ *
25
+ * createModal("modal2", () => {
26
+ * withModalStatus();
27
+ * });
28
+ *
29
+ * openModal("modal1");
30
+ * openModal("modal2");
31
+ * closeAllModals();
32
+ * ```
33
+ *
34
+ */
2
35
  declare function closeAllModals(): void;
3
36
  //#endregion
4
37
  export { closeAllModals };
@@ -2,6 +2,39 @@ import { $keysToStatus } from "./internals.mjs";
2
2
  import { untrack } from "@monstermann/signals";
3
3
 
4
4
  //#region src/status/closeAllModals.ts
5
+ /**
6
+ * # closeAllModals
7
+ *
8
+ * ```ts
9
+ * function closeAllModals(): void;
10
+ * ```
11
+ *
12
+ * Closes all modals by setting their status to `"closing"`. Skips modals that are already `"closing"` or `"closed"`.
13
+ *
14
+ * ## Example
15
+ *
16
+ * ```ts
17
+ * import {
18
+ * createModal,
19
+ * withModalStatus,
20
+ * openModal,
21
+ * closeAllModals,
22
+ * } from "@monstermann/signals-modal";
23
+ *
24
+ * createModal("modal1", () => {
25
+ * withModalStatus();
26
+ * });
27
+ *
28
+ * createModal("modal2", () => {
29
+ * withModalStatus();
30
+ * });
31
+ *
32
+ * openModal("modal1");
33
+ * openModal("modal2");
34
+ * closeAllModals();
35
+ * ```
36
+ *
37
+ */
5
38
  function closeAllModals() {
6
39
  untrack(() => {
7
40
  for (const $status of $keysToStatus().values()) {
@@ -1,4 +1,22 @@
1
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
+ */
2
20
  declare function closeLastModal(): void;
3
21
  //#endregion
4
22
  export { closeLastModal };
@@ -2,6 +2,24 @@ import { $openedModals } from "./internals.mjs";
2
2
  import { closeModal } from "./closeModal.mjs";
3
3
 
4
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
+ */
5
23
  function closeLastModal() {
6
24
  const key = Array.from($openedModals()).at(-1);
7
25
  if (key) closeModal(key);
@@ -1,4 +1,32 @@
1
1
  //#region src/status/closeModal.d.ts
2
+ /**
3
+ * # closeModal
4
+ *
5
+ * ```ts
6
+ * function closeModal(key: string): void;
7
+ * ```
8
+ *
9
+ * Closes a modal by setting its status to `"closing"`. Does nothing if the modal is already `"closing"` or `"closed"`, or if the modal doesn't exist.
10
+ *
11
+ * ## Example
12
+ *
13
+ * ```ts
14
+ * import {
15
+ * createModal,
16
+ * withModalStatus,
17
+ * openModal,
18
+ * closeModal,
19
+ * } from "@monstermann/signals-modal";
20
+ *
21
+ * createModal("key", () => {
22
+ * withModalStatus();
23
+ * });
24
+ *
25
+ * openModal("key");
26
+ * closeModal("key");
27
+ * ```
28
+ *
29
+ */
2
30
  declare function closeModal(key: string): void;
3
31
  //#endregion
4
32
  export { closeModal };
@@ -2,6 +2,34 @@ import { $keysToStatus } from "./internals.mjs";
2
2
  import { untrack } from "@monstermann/signals";
3
3
 
4
4
  //#region src/status/closeModal.ts
5
+ /**
6
+ * # closeModal
7
+ *
8
+ * ```ts
9
+ * function closeModal(key: string): void;
10
+ * ```
11
+ *
12
+ * Closes a modal by setting its status to `"closing"`. Does nothing if the modal is already `"closing"` or `"closed"`, or if the modal doesn't exist.
13
+ *
14
+ * ## Example
15
+ *
16
+ * ```ts
17
+ * import {
18
+ * createModal,
19
+ * withModalStatus,
20
+ * openModal,
21
+ * closeModal,
22
+ * } from "@monstermann/signals-modal";
23
+ *
24
+ * createModal("key", () => {
25
+ * withModalStatus();
26
+ * });
27
+ *
28
+ * openModal("key");
29
+ * closeModal("key");
30
+ * ```
31
+ *
32
+ */
5
33
  function closeModal(key) {
6
34
  untrack(() => {
7
35
  const $status = $keysToStatus().get(key);