@monstermann/signals-modal 0.0.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.
Files changed (125) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +9 -0
  3. package/dist/anchor/getAnchorElement.d.ts +4 -0
  4. package/dist/anchor/getAnchorElement.js +9 -0
  5. package/dist/anchor/getAnchorMeasurement.d.ts +6 -0
  6. package/dist/anchor/getAnchorMeasurement.js +10 -0
  7. package/dist/anchor/internals.js +19 -0
  8. package/dist/anchor/setAnchorElement.d.ts +4 -0
  9. package/dist/anchor/setAnchorElement.js +9 -0
  10. package/dist/anchor/withAnchorElement.d.ts +6 -0
  11. package/dist/anchor/withAnchorElement.js +32 -0
  12. package/dist/anchor/withAnchorMeasurement.d.ts +12 -0
  13. package/dist/anchor/withAnchorMeasurement.js +56 -0
  14. package/dist/anchor/withMouseAnchor.d.ts +11 -0
  15. package/dist/anchor/withMouseAnchor.js +57 -0
  16. package/dist/createModal.d.ts +14 -0
  17. package/dist/createModal.js +47 -0
  18. package/dist/floating/getFloatingElement.d.ts +4 -0
  19. package/dist/floating/getFloatingElement.js +9 -0
  20. package/dist/floating/getFloatingMeasurement.d.ts +6 -0
  21. package/dist/floating/getFloatingMeasurement.js +10 -0
  22. package/dist/floating/internals.js +19 -0
  23. package/dist/floating/setFloatingElement.d.ts +4 -0
  24. package/dist/floating/setFloatingElement.js +9 -0
  25. package/dist/floating/withFloatingElement.d.ts +6 -0
  26. package/dist/floating/withFloatingElement.js +32 -0
  27. package/dist/floating/withFloatingMeasurement.d.ts +12 -0
  28. package/dist/floating/withFloatingMeasurement.js +67 -0
  29. package/dist/groups/getDialogs.d.ts +4 -0
  30. package/dist/groups/getDialogs.js +10 -0
  31. package/dist/groups/getGroupsForModal.d.ts +4 -0
  32. package/dist/groups/getGroupsForModal.js +10 -0
  33. package/dist/groups/getModalsForGroup.d.ts +4 -0
  34. package/dist/groups/getModalsForGroup.js +10 -0
  35. package/dist/groups/getPopovers.d.ts +4 -0
  36. package/dist/groups/getPopovers.js +10 -0
  37. package/dist/groups/getTooltips.d.ts +4 -0
  38. package/dist/groups/getTooltips.js +10 -0
  39. package/dist/groups/internals.js +26 -0
  40. package/dist/groups/isDialog.d.ts +4 -0
  41. package/dist/groups/isDialog.js +10 -0
  42. package/dist/groups/isModalInGroup.d.ts +4 -0
  43. package/dist/groups/isModalInGroup.js +9 -0
  44. package/dist/groups/isPopover.d.ts +4 -0
  45. package/dist/groups/isPopover.js +10 -0
  46. package/dist/groups/isTooltip.d.ts +4 -0
  47. package/dist/groups/isTooltip.js +10 -0
  48. package/dist/groups/modalGroups.d.ts +8 -0
  49. package/dist/groups/modalGroups.js +9 -0
  50. package/dist/groups/withModalGroups.d.ts +6 -0
  51. package/dist/groups/withModalGroups.js +29 -0
  52. package/dist/index.d.ts +57 -0
  53. package/dist/index.js +57 -0
  54. package/dist/internals/findParentElement.js +9 -0
  55. package/dist/internals/observeDimensions.js +23 -0
  56. package/dist/internals/observePosition.js +44 -0
  57. package/dist/internals/roundByDPR.js +8 -0
  58. package/dist/position/getModalPosition.d.ts +6 -0
  59. package/dist/position/getModalPosition.js +9 -0
  60. package/dist/position/internals.js +32 -0
  61. package/dist/position/withBoundary.d.ts +11 -0
  62. package/dist/position/withBoundary.js +45 -0
  63. package/dist/position/withPlacement.d.ts +14 -0
  64. package/dist/position/withPlacement.js +75 -0
  65. package/dist/position/withPosition.d.ts +22 -0
  66. package/dist/position/withPosition.js +207 -0
  67. package/dist/status/closeAllModals.d.ts +4 -0
  68. package/dist/status/closeAllModals.js +16 -0
  69. package/dist/status/closeModal.d.ts +4 -0
  70. package/dist/status/closeModal.js +16 -0
  71. package/dist/status/getClosedModals.d.ts +4 -0
  72. package/dist/status/getClosedModals.js +12 -0
  73. package/dist/status/getClosingModals.d.ts +4 -0
  74. package/dist/status/getClosingModals.js +12 -0
  75. package/dist/status/getModalStatus.d.ts +6 -0
  76. package/dist/status/getModalStatus.js +9 -0
  77. package/dist/status/getOpenedModals.d.ts +4 -0
  78. package/dist/status/getOpenedModals.js +12 -0
  79. package/dist/status/getOpeningModals.d.ts +4 -0
  80. package/dist/status/getOpeningModals.js +12 -0
  81. package/dist/status/getVisibleModals.d.ts +4 -0
  82. package/dist/status/getVisibleModals.js +12 -0
  83. package/dist/status/internals.js +30 -0
  84. package/dist/status/isAnyModalClosed.d.ts +4 -0
  85. package/dist/status/isAnyModalClosed.js +9 -0
  86. package/dist/status/isAnyModalClosing.d.ts +4 -0
  87. package/dist/status/isAnyModalClosing.js +9 -0
  88. package/dist/status/isAnyModalOpened.d.ts +4 -0
  89. package/dist/status/isAnyModalOpened.js +9 -0
  90. package/dist/status/isAnyModalOpening.d.ts +4 -0
  91. package/dist/status/isAnyModalOpening.js +9 -0
  92. package/dist/status/isAnyModalVisible.d.ts +4 -0
  93. package/dist/status/isAnyModalVisible.js +9 -0
  94. package/dist/status/isModalClosed.d.ts +4 -0
  95. package/dist/status/isModalClosed.js +10 -0
  96. package/dist/status/isModalClosing.d.ts +4 -0
  97. package/dist/status/isModalClosing.js +9 -0
  98. package/dist/status/isModalOpened.d.ts +4 -0
  99. package/dist/status/isModalOpened.js +9 -0
  100. package/dist/status/isModalOpening.d.ts +4 -0
  101. package/dist/status/isModalOpening.js +9 -0
  102. package/dist/status/isModalVisible.d.ts +4 -0
  103. package/dist/status/isModalVisible.js +9 -0
  104. package/dist/status/onModalClosed.d.ts +6 -0
  105. package/dist/status/onModalClosed.js +12 -0
  106. package/dist/status/onModalClosing.d.ts +6 -0
  107. package/dist/status/onModalClosing.js +12 -0
  108. package/dist/status/onModalOpened.d.ts +6 -0
  109. package/dist/status/onModalOpened.js +12 -0
  110. package/dist/status/onModalOpening.d.ts +6 -0
  111. package/dist/status/onModalOpening.js +12 -0
  112. package/dist/status/openModal.d.ts +4 -0
  113. package/dist/status/openModal.js +16 -0
  114. package/dist/status/setModalStatus.d.ts +6 -0
  115. package/dist/status/setModalStatus.js +9 -0
  116. package/dist/status/types.d.ts +4 -0
  117. package/dist/status/withModalStatus.d.ts +7 -0
  118. package/dist/status/withModalStatus.js +38 -0
  119. package/dist/utils/closeLastModalOnClickOutside.d.ts +4 -0
  120. package/dist/utils/closeLastModalOnClickOutside.js +19 -0
  121. package/dist/utils/closeLastModalOnEsc.d.ts +4 -0
  122. package/dist/utils/closeLastModalOnEsc.js +17 -0
  123. package/dist/utils/syncModalGroupsToBody.d.ts +4 -0
  124. package/dist/utils/syncModalGroupsToBody.js +24 -0
  125. package/package.json +43 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) Michael Ostermann
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,9 @@
1
+ <div align="center">
2
+
3
+ <h1>signals-modal</h1>
4
+
5
+ **Composable modal management.**
6
+
7
+ [Documentation](https://MichaelOstermann.github.io/signals-modal)
8
+
9
+ </div>
@@ -0,0 +1,4 @@
1
+ //#region src/anchor/getAnchorElement.d.ts
2
+ declare function getAnchorElement(key: string): HTMLElement | undefined;
3
+ //#endregion
4
+ export { getAnchorElement };
@@ -0,0 +1,9 @@
1
+ import { $anchorElements } from "./internals.js";
2
+
3
+ //#region src/anchor/getAnchorElement.ts
4
+ function getAnchorElement(key) {
5
+ return $anchorElements().get(key)?.() ?? void 0;
6
+ }
7
+
8
+ //#endregion
9
+ export { getAnchorElement };
@@ -0,0 +1,6 @@
1
+ import { Rect } from "@monstermann/fn";
2
+
3
+ //#region src/anchor/getAnchorMeasurement.d.ts
4
+ declare function getAnchorMeasurement(key: string): Rect;
5
+ //#endregion
6
+ export { getAnchorMeasurement };
@@ -0,0 +1,10 @@
1
+ import { $anchorMeasurements } from "./internals.js";
2
+ import { Rect } from "@monstermann/fn";
3
+
4
+ //#region src/anchor/getAnchorMeasurement.ts
5
+ function getAnchorMeasurement(key) {
6
+ return $anchorMeasurements().get(key) ?? Rect.origin;
7
+ }
8
+
9
+ //#endregion
10
+ export { getAnchorMeasurement };
@@ -0,0 +1,19 @@
1
+ import { SILENT, signal } from "@monstermann/signals";
2
+
3
+ //#region src/anchor/internals.ts
4
+ const path = "@signals-modal/anchor/internals.ts";
5
+ const meta = {
6
+ path,
7
+ line: 5,
8
+ name: "$anchorElements"
9
+ };
10
+ const meta1 = {
11
+ path,
12
+ line: 6,
13
+ name: "$anchorMeasurements"
14
+ };
15
+ const $anchorElements = signal(/* @__PURE__ */ new Map(), SILENT, meta);
16
+ const $anchorMeasurements = signal(/* @__PURE__ */ new Map(), SILENT, meta1);
17
+
18
+ //#endregion
19
+ export { $anchorElements, $anchorMeasurements };
@@ -0,0 +1,4 @@
1
+ //#region src/anchor/setAnchorElement.d.ts
2
+ declare function setAnchorElement(key: string, element: HTMLElement | null): void;
3
+ //#endregion
4
+ export { setAnchorElement };
@@ -0,0 +1,9 @@
1
+ import { $anchorElements } from "./internals.js";
2
+
3
+ //#region src/anchor/setAnchorElement.ts
4
+ function setAnchorElement(key, element) {
5
+ $anchorElements().get(key)?.(element);
6
+ }
7
+
8
+ //#endregion
9
+ export { setAnchorElement };
@@ -0,0 +1,6 @@
1
+ import { Signal } from "@monstermann/signals";
2
+
3
+ //#region src/anchor/withAnchorElement.d.ts
4
+ declare function withAnchorElement(anchorElement?: HTMLElement): Signal<HTMLElement | null>;
5
+ //#endregion
6
+ export { withAnchorElement };
@@ -0,0 +1,32 @@
1
+ import { $anchorElements } from "./internals.js";
2
+ import { set } from "../node_modules/@monstermann/map/dist/Map/set.js";
3
+ import { remove } from "../node_modules/@monstermann/map/dist/Map/remove.js";
4
+ import { currentModal } from "../createModal.js";
5
+ import { INTERNAL, effect, signal } from "@monstermann/signals";
6
+
7
+ //#region src/anchor/withAnchorElement.ts
8
+ const path = "@signals-modal/anchor/withAnchorElement.ts";
9
+ const meta = {
10
+ path,
11
+ line: 10,
12
+ name: "withAnchorElement.$anchorElement"
13
+ };
14
+ const meta1 = {
15
+ path,
16
+ line: 12,
17
+ name: "withAnchorElement"
18
+ };
19
+ function withAnchorElement(anchorElement) {
20
+ const modal = currentModal();
21
+ const $anchorElement = signal(anchorElement ?? null, INTERNAL, meta);
22
+ modal.onDispose(effect(() => {
23
+ $anchorElements((map) => set(map, modal.key, $anchorElement));
24
+ }, INTERNAL, meta1));
25
+ modal.onDispose(() => {
26
+ $anchorElements((map) => remove(map, modal.key));
27
+ });
28
+ return $anchorElement;
29
+ }
30
+
31
+ //#endregion
32
+ export { withAnchorElement };
@@ -0,0 +1,12 @@
1
+ import { ModalStatus } from "../status/types.js";
2
+ import { Memo, Reactive } from "@monstermann/signals";
3
+ import { Rect } from "@monstermann/fn";
4
+
5
+ //#region src/anchor/withAnchorMeasurement.d.ts
6
+ declare function withAnchorMeasurement(options: {
7
+ $anchorElement: Reactive<HTMLElement | null>;
8
+ $status: Reactive<ModalStatus>;
9
+ transform?: (rect: Rect) => Rect;
10
+ }): Memo<Rect>;
11
+ //#endregion
12
+ export { withAnchorMeasurement };
@@ -0,0 +1,56 @@
1
+ import { $anchorMeasurements } from "./internals.js";
2
+ import { set } from "../node_modules/@monstermann/map/dist/Map/set.js";
3
+ import { remove } from "../node_modules/@monstermann/map/dist/Map/remove.js";
4
+ import { currentModal } from "../createModal.js";
5
+ import { observePosition } from "../internals/observePosition.js";
6
+ import { INTERNAL, effect, memo, signal } from "@monstermann/signals";
7
+ import { Rect } from "@monstermann/fn";
8
+
9
+ //#region src/anchor/withAnchorMeasurement.ts
10
+ const path = "@signals-modal/anchor/withAnchorMeasurement.ts";
11
+ const meta = {
12
+ path,
13
+ line: 19,
14
+ name: "withAnchorMeasurement.$rect"
15
+ };
16
+ const meta1 = {
17
+ path,
18
+ line: 24,
19
+ name: "withAnchorMeasurement.$measurement"
20
+ };
21
+ const meta2 = {
22
+ path,
23
+ line: 28,
24
+ name: "withAnchorMeasurement"
25
+ };
26
+ const meta3 = {
27
+ path,
28
+ line: 37,
29
+ name: "withAnchorMeasurement"
30
+ };
31
+ function withAnchorMeasurement(options) {
32
+ const modal = currentModal();
33
+ const $rect = signal(Rect.origin, {
34
+ equals: Rect.isEqual,
35
+ internal: true
36
+ }, meta);
37
+ const $measurement = memo(() => options.transform ? options.transform($rect()) : $rect(), INTERNAL, meta1);
38
+ modal.onDispose(effect(() => {
39
+ const element = options.$anchorElement();
40
+ const status = options.$status();
41
+ if (!element) return;
42
+ if (status === "closed") return;
43
+ $rect(Rect.fromElement(element));
44
+ return observePosition(element, (bounds) => $rect(Rect.fromDOMRect(bounds)));
45
+ }, INTERNAL, meta2));
46
+ modal.onDispose(effect(() => {
47
+ $anchorMeasurements((map) => set(map, modal.key, $rect()));
48
+ }, INTERNAL, meta3));
49
+ modal.onDispose(() => {
50
+ $anchorMeasurements((map) => remove(map, modal.key));
51
+ });
52
+ return $measurement;
53
+ }
54
+
55
+ //#endregion
56
+ export { withAnchorMeasurement };
@@ -0,0 +1,11 @@
1
+ import { ModalStatus } from "../status/types.js";
2
+ import { Memo, Reactive } from "@monstermann/signals";
3
+ import { Rect } from "@monstermann/fn";
4
+
5
+ //#region src/anchor/withMouseAnchor.d.ts
6
+ declare function withMouseAnchor(options: {
7
+ $status: Reactive<ModalStatus>;
8
+ transform?: (rect: Rect) => Rect;
9
+ }): Memo<Rect>;
10
+ //#endregion
11
+ export { withMouseAnchor };
@@ -0,0 +1,57 @@
1
+ import { $anchorMeasurements } from "./internals.js";
2
+ import { set } from "../node_modules/@monstermann/map/dist/Map/set.js";
3
+ import { remove } from "../node_modules/@monstermann/map/dist/Map/remove.js";
4
+ import { currentModal } from "../createModal.js";
5
+ import { INTERNAL, effect, memo, peek, signal } from "@monstermann/signals";
6
+ import { Rect } from "@monstermann/fn";
7
+ import { $mouseX, $mouseY } from "@monstermann/signals-web";
8
+
9
+ //#region src/anchor/withMouseAnchor.ts
10
+ const path = "@signals-modal/anchor/withMouseAnchor.ts";
11
+ const meta = {
12
+ path,
13
+ line: 18,
14
+ name: "withMouseAnchor.$rect"
15
+ };
16
+ const meta1 = {
17
+ path,
18
+ line: 23,
19
+ name: "withMouseAnchor.$measurement"
20
+ };
21
+ const meta2 = {
22
+ path,
23
+ line: 27,
24
+ name: "withMouseAnchor"
25
+ };
26
+ const meta3 = {
27
+ path,
28
+ line: 41,
29
+ name: "withMouseAnchor"
30
+ };
31
+ function withMouseAnchor(options) {
32
+ const modal = currentModal();
33
+ const $rect = signal(Rect.origin, {
34
+ equals: Rect.isEqual,
35
+ internal: true
36
+ }, meta);
37
+ const $measurement = memo(() => options.transform ? options.transform($rect()) : $rect(), INTERNAL, meta1);
38
+ modal.onDispose(effect(() => {
39
+ if (options.$status() === "closed") $rect(Rect.origin);
40
+ else if (Rect.isOrigin($rect())) $rect({
41
+ height: 0,
42
+ left: peek($mouseX()),
43
+ top: peek($mouseY()),
44
+ width: 0
45
+ });
46
+ }, INTERNAL, meta2));
47
+ modal.onDispose(effect(() => {
48
+ $anchorMeasurements((map) => set(map, modal.key, $rect()));
49
+ }, INTERNAL, meta3));
50
+ modal.onDispose(() => {
51
+ $anchorMeasurements((map) => remove(map, modal.key));
52
+ });
53
+ return $measurement;
54
+ }
55
+
56
+ //#endregion
57
+ export { withMouseAnchor };
@@ -0,0 +1,14 @@
1
+ import * as _monstermann_signals0 from "@monstermann/signals";
2
+ import { MaybeDispose } from "@monstermann/signals";
3
+
4
+ //#region src/createModal.d.ts
5
+ interface ModalContext {
6
+ key: string;
7
+ dispose: () => void;
8
+ onDispose: (dispose: MaybeDispose) => void;
9
+ }
10
+ declare const onModalDisposed: _monstermann_signals0.Emitter<string>;
11
+ declare function currentModal(): ModalContext;
12
+ declare function createModal<T extends object>(key: string, setup: () => T): ModalContext & T;
13
+ //#endregion
14
+ export { ModalContext, createModal, currentModal, onModalDisposed };
@@ -0,0 +1,47 @@
1
+ import { onModalClosed } from "./status/onModalClosed.js";
2
+ import { closeModal } from "./status/closeModal.js";
3
+ import { isModalClosed } from "./status/isModalClosed.js";
4
+ import { SILENT, context, disposer, emitter } from "@monstermann/signals";
5
+
6
+ //#region src/createModal.ts
7
+ const meta = {
8
+ path: "@signals-modal/createModal.ts",
9
+ line: 15,
10
+ name: "onModalDisposed"
11
+ };
12
+ const modalCtx = context();
13
+ const onModalDisposed = emitter(SILENT, meta);
14
+ function currentModal() {
15
+ const ctx = modalCtx();
16
+ if (!ctx) throw new Error("`currentModal` called outside of `createModal` context.");
17
+ return ctx;
18
+ }
19
+ function createModal(key, setup) {
20
+ const dispose = disposer();
21
+ const nextCtx = {
22
+ key,
23
+ onDispose: dispose,
24
+ dispose() {
25
+ if (isModalClosed(key)) {
26
+ dispose();
27
+ onModalDisposed(key);
28
+ } else {
29
+ onModalClosed((k) => k === key && this.dispose());
30
+ closeModal(key);
31
+ }
32
+ }
33
+ };
34
+ const prevCtx = modalCtx(nextCtx);
35
+ try {
36
+ const result = setup();
37
+ return {
38
+ ...nextCtx,
39
+ ...result
40
+ };
41
+ } finally {
42
+ modalCtx(prevCtx);
43
+ }
44
+ }
45
+
46
+ //#endregion
47
+ export { createModal, currentModal, onModalDisposed };
@@ -0,0 +1,4 @@
1
+ //#region src/floating/getFloatingElement.d.ts
2
+ declare function getFloatingElement(key: string): HTMLElement | undefined;
3
+ //#endregion
4
+ export { getFloatingElement };
@@ -0,0 +1,9 @@
1
+ import { $floatingElements } from "./internals.js";
2
+
3
+ //#region src/floating/getFloatingElement.ts
4
+ function getFloatingElement(key) {
5
+ return $floatingElements().get(key)?.() ?? void 0;
6
+ }
7
+
8
+ //#endregion
9
+ export { getFloatingElement };
@@ -0,0 +1,6 @@
1
+ import { Rect } from "@monstermann/fn";
2
+
3
+ //#region src/floating/getFloatingMeasurement.d.ts
4
+ declare function getFloatingMeasurement(key: string): Rect;
5
+ //#endregion
6
+ export { getFloatingMeasurement };
@@ -0,0 +1,10 @@
1
+ import { $floatingMeasurements } from "./internals.js";
2
+ import { Rect } from "@monstermann/fn";
3
+
4
+ //#region src/floating/getFloatingMeasurement.ts
5
+ function getFloatingMeasurement(key) {
6
+ return $floatingMeasurements().get(key) ?? Rect.origin;
7
+ }
8
+
9
+ //#endregion
10
+ export { getFloatingMeasurement };
@@ -0,0 +1,19 @@
1
+ import { SILENT, 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: 6,
13
+ name: "$floatingMeasurements"
14
+ };
15
+ const $floatingElements = signal(/* @__PURE__ */ new Map(), SILENT, meta);
16
+ const $floatingMeasurements = signal(/* @__PURE__ */ new Map(), SILENT, meta1);
17
+
18
+ //#endregion
19
+ export { $floatingElements, $floatingMeasurements };
@@ -0,0 +1,4 @@
1
+ //#region src/floating/setFloatingElement.d.ts
2
+ declare function setFloatingElement(key: string, element: HTMLElement | null): void;
3
+ //#endregion
4
+ export { setFloatingElement };
@@ -0,0 +1,9 @@
1
+ import { $floatingElements } from "./internals.js";
2
+
3
+ //#region src/floating/setFloatingElement.ts
4
+ function setFloatingElement(key, element) {
5
+ $floatingElements().get(key)?.(element);
6
+ }
7
+
8
+ //#endregion
9
+ export { setFloatingElement };
@@ -0,0 +1,6 @@
1
+ import { Signal } from "@monstermann/signals";
2
+
3
+ //#region src/floating/withFloatingElement.d.ts
4
+ declare function withFloatingElement(anchorElement?: HTMLElement): Signal<HTMLElement | null>;
5
+ //#endregion
6
+ export { withFloatingElement };
@@ -0,0 +1,32 @@
1
+ import { set } from "../node_modules/@monstermann/map/dist/Map/set.js";
2
+ import { remove } from "../node_modules/@monstermann/map/dist/Map/remove.js";
3
+ import { currentModal } from "../createModal.js";
4
+ import { $floatingElements } from "./internals.js";
5
+ import { INTERNAL, effect, signal } from "@monstermann/signals";
6
+
7
+ //#region src/floating/withFloatingElement.ts
8
+ const path = "@signals-modal/floating/withFloatingElement.ts";
9
+ const meta = {
10
+ path,
11
+ line: 10,
12
+ name: "withFloatingElement.$anchorElement"
13
+ };
14
+ const meta1 = {
15
+ path,
16
+ line: 12,
17
+ name: "withFloatingElement"
18
+ };
19
+ function withFloatingElement(anchorElement) {
20
+ const modal = currentModal();
21
+ const $anchorElement = signal(anchorElement ?? null, INTERNAL, meta);
22
+ modal.onDispose(effect(() => {
23
+ $floatingElements((map) => set(map, modal.key, $anchorElement));
24
+ }, INTERNAL, meta1));
25
+ modal.onDispose(() => {
26
+ $floatingElements((map) => remove(map, modal.key));
27
+ });
28
+ return $anchorElement;
29
+ }
30
+
31
+ //#endregion
32
+ export { withFloatingElement };
@@ -0,0 +1,12 @@
1
+ import { ModalStatus } from "../status/types.js";
2
+ import { Memo, Reactive } from "@monstermann/signals";
3
+ import { Rect } from "@monstermann/fn";
4
+
5
+ //#region src/floating/withFloatingMeasurement.d.ts
6
+ declare function withFloatingMeasurement(options: {
7
+ $floatingElement: Reactive<HTMLElement | null>;
8
+ $status: Reactive<ModalStatus>;
9
+ transform?: (rect: Rect) => Rect;
10
+ }): Memo<Rect>;
11
+ //#endregion
12
+ export { withFloatingMeasurement };
@@ -0,0 +1,67 @@
1
+ import { set } from "../node_modules/@monstermann/map/dist/Map/set.js";
2
+ import { remove } from "../node_modules/@monstermann/map/dist/Map/remove.js";
3
+ import { currentModal } from "../createModal.js";
4
+ import { $floatingMeasurements } from "./internals.js";
5
+ import { observeDimensions } from "../internals/observeDimensions.js";
6
+ import { INTERNAL, effect, memo, signal } from "@monstermann/signals";
7
+ import { Rect } from "@monstermann/fn";
8
+
9
+ //#region src/floating/withFloatingMeasurement.ts
10
+ const path = "@signals-modal/floating/withFloatingMeasurement.ts";
11
+ const meta = {
12
+ path,
13
+ line: 19,
14
+ name: "withFloatingMeasurement.$rect"
15
+ };
16
+ const meta1 = {
17
+ path,
18
+ line: 24,
19
+ name: "withFloatingMeasurement.$measurement"
20
+ };
21
+ const meta2 = {
22
+ path,
23
+ line: 28,
24
+ name: "withFloatingMeasurement"
25
+ };
26
+ const meta3 = {
27
+ path,
28
+ line: 48,
29
+ name: "withFloatingMeasurement"
30
+ };
31
+ function withFloatingMeasurement(options) {
32
+ const modal = currentModal();
33
+ const $rect = signal(Rect.origin, {
34
+ equals: Rect.isEqual,
35
+ internal: true
36
+ }, meta);
37
+ const $measurement = memo(() => options.transform ? options.transform($rect()) : $rect(), INTERNAL, meta1);
38
+ modal.onDispose(effect(() => {
39
+ const element = options.$floatingElement();
40
+ const status = options.$status();
41
+ if (!element) return;
42
+ if (status === "closed") return;
43
+ const bounds = Rect.fromElement(element);
44
+ $rect({
45
+ height: bounds.height,
46
+ left: 0,
47
+ top: 0,
48
+ width: bounds.width
49
+ });
50
+ return observeDimensions(element, (bounds$1) => $rect({
51
+ height: bounds$1.height,
52
+ left: 0,
53
+ top: 0,
54
+ width: bounds$1.width
55
+ }));
56
+ }, INTERNAL, meta2));
57
+ modal.onDispose(effect(() => {
58
+ $floatingMeasurements((map) => set(map, modal.key, $rect()));
59
+ }, INTERNAL, meta3));
60
+ modal.onDispose(() => {
61
+ $floatingMeasurements((map) => remove(map, modal.key));
62
+ });
63
+ return $measurement;
64
+ }
65
+
66
+ //#endregion
67
+ export { withFloatingMeasurement };
@@ -0,0 +1,4 @@
1
+ //#region src/groups/getDialogs.d.ts
2
+ declare function getDialogs(): ReadonlySet<string>;
3
+ //#endregion
4
+ export { getDialogs };
@@ -0,0 +1,10 @@
1
+ import { getModalsForGroup } from "./getModalsForGroup.js";
2
+ import { modalGroups } from "./modalGroups.js";
3
+
4
+ //#region src/groups/getDialogs.ts
5
+ function getDialogs() {
6
+ return getModalsForGroup(modalGroups.dialog);
7
+ }
8
+
9
+ //#endregion
10
+ export { getDialogs };
@@ -0,0 +1,4 @@
1
+ //#region src/groups/getGroupsForModal.d.ts
2
+ declare function getGroupsForModal(key: string): ReadonlySet<string>;
3
+ //#endregion
4
+ export { getGroupsForModal };
@@ -0,0 +1,10 @@
1
+ import { $keysToGroups } from "./internals.js";
2
+
3
+ //#region src/groups/getGroupsForModal.ts
4
+ const empty = /* @__PURE__ */ new Set();
5
+ function getGroupsForModal(key) {
6
+ return $keysToGroups().get(key) ?? empty;
7
+ }
8
+
9
+ //#endregion
10
+ export { getGroupsForModal };
@@ -0,0 +1,4 @@
1
+ //#region src/groups/getModalsForGroup.d.ts
2
+ declare function getModalsForGroup(group: string): ReadonlySet<string>;
3
+ //#endregion
4
+ export { getModalsForGroup };
@@ -0,0 +1,10 @@
1
+ import { $groupsToKeys } from "./internals.js";
2
+
3
+ //#region src/groups/getModalsForGroup.ts
4
+ const empty = /* @__PURE__ */ new Set();
5
+ function getModalsForGroup(group) {
6
+ return $groupsToKeys().get(group) ?? empty;
7
+ }
8
+
9
+ //#endregion
10
+ export { getModalsForGroup };
@@ -0,0 +1,4 @@
1
+ //#region src/groups/getPopovers.d.ts
2
+ declare function getPopovers(): ReadonlySet<string>;
3
+ //#endregion
4
+ export { getPopovers };
@@ -0,0 +1,10 @@
1
+ import { getModalsForGroup } from "./getModalsForGroup.js";
2
+ import { modalGroups } from "./modalGroups.js";
3
+
4
+ //#region src/groups/getPopovers.ts
5
+ function getPopovers() {
6
+ return getModalsForGroup(modalGroups.popover);
7
+ }
8
+
9
+ //#endregion
10
+ export { getPopovers };
@@ -0,0 +1,4 @@
1
+ //#region src/groups/getTooltips.d.ts
2
+ declare function getTooltips(): ReadonlySet<string>;
3
+ //#endregion
4
+ export { getTooltips };
@@ -0,0 +1,10 @@
1
+ import { getModalsForGroup } from "./getModalsForGroup.js";
2
+ import { modalGroups } from "./modalGroups.js";
3
+
4
+ //#region src/groups/getTooltips.ts
5
+ function getTooltips() {
6
+ return getModalsForGroup(modalGroups.tooltip);
7
+ }
8
+
9
+ //#endregion
10
+ export { getTooltips };
@@ -0,0 +1,26 @@
1
+ import { INTERNAL, SILENT, memo, signal } from "@monstermann/signals";
2
+
3
+ //#region src/groups/internals.ts
4
+ const path = "@signals-modal/groups/internals.ts";
5
+ const meta = {
6
+ path,
7
+ line: 3,
8
+ name: "$keysToGroups"
9
+ };
10
+ const meta1 = {
11
+ path,
12
+ line: 5,
13
+ name: "$groupsToKeys"
14
+ };
15
+ const $keysToGroups = signal(/* @__PURE__ */ new Map(), SILENT, meta);
16
+ const $groupsToKeys = memo(() => {
17
+ const map = /* @__PURE__ */ new Map();
18
+ for (const [key, groups] of $keysToGroups()) for (const group of groups) {
19
+ if (!map.has(group)) map.set(group, /* @__PURE__ */ new Set());
20
+ map.get(group).add(key);
21
+ }
22
+ return map;
23
+ }, INTERNAL, meta1);
24
+
25
+ //#endregion
26
+ export { $groupsToKeys, $keysToGroups };