@agnos-ui/core 0.1.1 → 0.3.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 (145) hide show
  1. package/README.md +3 -3
  2. package/accordion-BaWN0_n-.js +330 -0
  3. package/accordion-BuIgxZ0S.cjs +329 -0
  4. package/alert-C4jCg9Pl.cjs +8 -0
  5. package/alert-Dlf-BV98.js +9 -0
  6. package/common-DRdsw5m8.js +76 -0
  7. package/common-nJRMXbwj.cjs +75 -0
  8. package/components/accordion/accordion.d.ts +57 -64
  9. package/components/accordion/index.cjs +7 -0
  10. package/components/accordion/index.js +7 -1
  11. package/components/alert/alert.d.ts +3 -12
  12. package/components/alert/common.d.ts +4 -13
  13. package/components/alert/index.cjs +10 -0
  14. package/components/alert/index.js +10 -2
  15. package/components/modal/index.cjs +7 -0
  16. package/components/modal/index.js +7 -1
  17. package/components/modal/modal.d.ts +7 -49
  18. package/components/pagination/index.cjs +5 -0
  19. package/components/pagination/index.d.ts +0 -1
  20. package/components/pagination/index.js +5 -2
  21. package/components/pagination/pagination.d.ts +107 -128
  22. package/components/progressbar/index.cjs +5 -0
  23. package/components/progressbar/index.js +5 -1
  24. package/components/progressbar/progressbar.d.ts +6 -22
  25. package/components/rating/index.cjs +5 -0
  26. package/components/rating/index.js +5 -1
  27. package/components/rating/rating.d.ts +16 -11
  28. package/components/select/index.cjs +6 -0
  29. package/components/select/index.js +6 -1
  30. package/components/select/select.d.ts +45 -57
  31. package/components/slider/index.cjs +5 -0
  32. package/components/slider/index.js +5 -1
  33. package/components/slider/slider.d.ts +63 -5
  34. package/components/toast/index.cjs +5 -0
  35. package/components/toast/index.d.ts +1 -0
  36. package/components/toast/index.js +5 -0
  37. package/components/toast/toast.d.ts +47 -0
  38. package/config.cjs +38 -0
  39. package/config.d.ts +6 -1
  40. package/config.js +35 -50
  41. package/directive-BTSEYLF3.cjs +404 -0
  42. package/directive-DCYlDznf.js +405 -0
  43. package/func-DR0n-ShK.js +7 -0
  44. package/func-Qd3cD9a3.cjs +6 -0
  45. package/index.cjs +119 -0
  46. package/index.d.ts +3 -1
  47. package/index.js +119 -31
  48. package/modal-BI2qUu1M.js +251 -0
  49. package/modal-rzMpATf5.cjs +250 -0
  50. package/package.json +30 -22
  51. package/pagination--GkwduJn.js +263 -0
  52. package/pagination-EWSWQT1I.cjs +262 -0
  53. package/progressbar-DH7DHYMp.cjs +83 -0
  54. package/progressbar-DuRX7_my.js +84 -0
  55. package/promise-BMJ8qhA8.cjs +118 -0
  56. package/promise-CY2U8bTP.js +119 -0
  57. package/rating-BR5wD7y2.js +173 -0
  58. package/rating-CmuYUSxy.cjs +172 -0
  59. package/select-BCs6HQWn.js +358 -0
  60. package/select-CCIKn8WR.cjs +357 -0
  61. package/services/extendWidget.cjs +32 -0
  62. package/services/extendWidget.d.ts +10 -5
  63. package/services/extendWidget.js +31 -34
  64. package/services/floatingUI.cjs +131 -0
  65. package/services/floatingUI.d.ts +30 -14
  66. package/services/floatingUI.js +128 -102
  67. package/services/focustrack.cjs +47 -0
  68. package/services/focustrack.js +45 -44
  69. package/services/hash.cjs +15 -0
  70. package/services/hash.d.ts +2 -0
  71. package/services/hash.js +15 -0
  72. package/services/intersection.cjs +53 -0
  73. package/services/intersection.js +48 -50
  74. package/services/matchMedia.cjs +13 -0
  75. package/services/matchMedia.d.ts +7 -0
  76. package/services/matchMedia.js +13 -0
  77. package/services/navManager.cjs +196 -0
  78. package/services/navManager.d.ts +24 -17
  79. package/services/navManager.js +186 -162
  80. package/services/portal.cjs +43 -0
  81. package/services/portal.js +41 -42
  82. package/services/resizeObserver.cjs +32 -0
  83. package/services/resizeObserver.d.ts +14 -0
  84. package/services/resizeObserver.js +32 -0
  85. package/services/siblingsInert.cjs +40 -0
  86. package/services/siblingsInert.js +31 -31
  87. package/services/transitions/baseTransitions.cjs +171 -0
  88. package/services/transitions/baseTransitions.d.ts +16 -16
  89. package/services/transitions/baseTransitions.js +159 -170
  90. package/services/transitions/collapse.cjs +44 -0
  91. package/services/transitions/collapse.js +41 -49
  92. package/services/transitions/cssTransitions.cjs +32 -0
  93. package/services/transitions/cssTransitions.d.ts +2 -1
  94. package/services/transitions/cssTransitions.js +29 -39
  95. package/services/transitions/simpleClassTransition.cjs +31 -0
  96. package/services/transitions/simpleClassTransition.js +30 -41
  97. package/slider-CA_fszn7.js +536 -0
  98. package/slider-DsLvT87U.cjs +535 -0
  99. package/toast-8tWp6x89.js +63 -0
  100. package/toast-Aw8o0Iwe.cjs +62 -0
  101. package/types.cjs +12 -0
  102. package/types.d.ts +21 -1
  103. package/types.js +11 -13
  104. package/utils/directive.cjs +26 -0
  105. package/utils/directive.d.ts +155 -4
  106. package/utils/directive.js +25 -189
  107. package/utils/internal/dom.d.ts +57 -3
  108. package/utils/internal/promise.d.ts +2 -2
  109. package/utils/internal/ssrHTMLElement.d.ts +7 -0
  110. package/utils/internal/textDirection.d.ts +1 -1
  111. package/utils/stores.cjs +163 -0
  112. package/utils/stores.d.ts +23 -20
  113. package/utils/stores.js +151 -269
  114. package/utils/writables.cjs +13 -0
  115. package/utils/writables.js +12 -71
  116. package/writables-D46sFgGK.cjs +85 -0
  117. package/writables-DoU_XYTX.js +86 -0
  118. package/components/accordion/accordion.js +0 -267
  119. package/components/alert/alert.js +0 -22
  120. package/components/alert/common.js +0 -69
  121. package/components/commonProps.js +0 -1
  122. package/components/modal/modal.js +0 -186
  123. package/components/pagination/bootstrap.d.ts +0 -8
  124. package/components/pagination/bootstrap.js +0 -110
  125. package/components/pagination/pagination.js +0 -149
  126. package/components/progressbar/progressbar.js +0 -78
  127. package/components/rating/rating.js +0 -138
  128. package/components/select/select.js +0 -266
  129. package/components/slider/slider.js +0 -415
  130. package/services/transitions/bootstrap/collapse.d.ts +0 -2
  131. package/services/transitions/bootstrap/collapse.js +0 -15
  132. package/services/transitions/bootstrap/fade.d.ts +0 -1
  133. package/services/transitions/bootstrap/fade.js +0 -7
  134. package/services/transitions/bootstrap.d.ts +0 -2
  135. package/services/transitions/bootstrap.js +0 -2
  136. package/utils/internal/checks.js +0 -60
  137. package/utils/internal/dom.js +0 -61
  138. package/utils/internal/func.js +0 -11
  139. package/utils/internal/isFocusable.js +0 -35
  140. package/utils/internal/math.js +0 -13
  141. package/utils/internal/promise.js +0 -169
  142. package/utils/internal/scrollbars.js +0 -33
  143. package/utils/internal/sort.js +0 -28
  144. package/utils/internal/textDirection.js +0 -7
  145. package/utils/internal/traversal.js +0 -105
@@ -1,46 +1,47 @@
1
- import { computed, readable } from '@amadeus-it-group/tansu';
2
- import { createStoreArrayDirective } from '../utils/directive';
3
- const evtFocusIn = 'focusin';
4
- const evtFocusOut = 'focusout';
5
- export const activeElement$ = readable(null, {
6
- onUse({ set }) {
7
- function setActiveElement() {
8
- set(document.activeElement);
9
- }
10
- setActiveElement();
11
- const container = document.documentElement;
12
- function onFocusOut() {
13
- setTimeout(setActiveElement);
14
- }
15
- container.addEventListener(evtFocusIn, setActiveElement, { capture: true });
16
- container.addEventListener(evtFocusOut, onFocusOut, { capture: true });
17
- return () => {
18
- container.removeEventListener(evtFocusIn, setActiveElement, { capture: true });
19
- container.removeEventListener(evtFocusOut, onFocusOut, { capture: true });
20
- };
21
- },
22
- equal: Object.is,
23
- });
24
- /**
25
- * Create a HasFocus
26
- * @returns a HasFocus
27
- */
28
- export function createHasFocus() {
29
- const { elements$, directive } = createStoreArrayDirective();
30
- const hasFocus$ = computed(() => {
31
- const activeElement = activeElement$();
32
- if (!activeElement) {
33
- return false;
34
- }
35
- for (const element of elements$()) {
36
- if (element === activeElement || element.contains(activeElement)) {
37
- return true;
38
- }
39
- }
40
- return false;
41
- });
42
- return {
43
- directive,
44
- hasFocus$,
1
+ import { readable, computed } from "@amadeus-it-group/tansu";
2
+ import { g as createBrowserStoreArrayDirective } from "../directive-DCYlDznf.js";
3
+ import { BROWSER } from "esm-env";
4
+ const evtFocusIn = "focusin";
5
+ const evtFocusOut = "focusout";
6
+ const activeElement$ = !BROWSER ? readable(null) : readable(null, {
7
+ onUse({ set }) {
8
+ function setActiveElement() {
9
+ set(document.activeElement);
10
+ }
11
+ setActiveElement();
12
+ const container = document.documentElement;
13
+ function onFocusOut() {
14
+ setTimeout(setActiveElement);
15
+ }
16
+ container.addEventListener(evtFocusIn, setActiveElement, { capture: true });
17
+ container.addEventListener(evtFocusOut, onFocusOut, { capture: true });
18
+ return () => {
19
+ container.removeEventListener(evtFocusIn, setActiveElement, { capture: true });
20
+ container.removeEventListener(evtFocusOut, onFocusOut, { capture: true });
45
21
  };
22
+ },
23
+ equal: Object.is
24
+ });
25
+ function createHasFocus() {
26
+ const { elements$, directive } = createBrowserStoreArrayDirective();
27
+ const hasFocus$ = computed(() => {
28
+ const activeElement = activeElement$();
29
+ if (!activeElement) {
30
+ return false;
31
+ }
32
+ for (const element of elements$()) {
33
+ if (element === activeElement || element.contains(activeElement)) {
34
+ return true;
35
+ }
36
+ }
37
+ return false;
38
+ });
39
+ return {
40
+ directive,
41
+ hasFocus$
42
+ };
46
43
  }
44
+ export {
45
+ activeElement$,
46
+ createHasFocus
47
+ };
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const tansu = require("@amadeus-it-group/tansu");
4
+ const hash$ = tansu.readable("", {
5
+ onUse({ set }) {
6
+ function handleHashChange() {
7
+ const hash = location.hash;
8
+ set(hash ? hash.substring(1) : "");
9
+ }
10
+ handleHashChange();
11
+ window.addEventListener("hashchange", handleHashChange);
12
+ return () => window.removeEventListener("hashchange", handleHashChange);
13
+ }
14
+ });
15
+ exports.hash$ = hash$;
@@ -0,0 +1,2 @@
1
+ /** Store exposing the location.hash string */
2
+ export declare const hash$: import("@amadeus-it-group/tansu").ReadableSignal<string>;
@@ -0,0 +1,15 @@
1
+ import { readable } from "@amadeus-it-group/tansu";
2
+ const hash$ = readable("", {
3
+ onUse({ set }) {
4
+ function handleHashChange() {
5
+ const hash = location.hash;
6
+ set(hash ? hash.substring(1) : "");
7
+ }
8
+ handleHashChange();
9
+ window.addEventListener("hashchange", handleHashChange);
10
+ return () => window.removeEventListener("hashchange", handleHashChange);
11
+ }
12
+ });
13
+ export {
14
+ hash$
15
+ };
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const tansu = require("@amadeus-it-group/tansu");
4
+ const func = require("../func-Qd3cD9a3.cjs");
5
+ const utils_stores = require("../utils/stores.cjs");
6
+ const defaultValues = {
7
+ elements: [],
8
+ options: void 0
9
+ };
10
+ const createIntersection = (config) => {
11
+ const [{ elements$, options$ }, patch] = utils_stores.writablesForProps(defaultValues, config);
12
+ const visibleElements$ = tansu.derived(
13
+ [elements$, options$],
14
+ ([elements, options], set) => {
15
+ if (elements.length) {
16
+ const visibleElements = /* @__PURE__ */ new Map();
17
+ const observer = new IntersectionObserver((entries) => {
18
+ for (const entry of entries) {
19
+ const { target, isIntersecting } = entry;
20
+ if (isIntersecting) {
21
+ visibleElements.set(target, entry);
22
+ } else {
23
+ visibleElements.delete(target);
24
+ }
25
+ }
26
+ set(visibleElements);
27
+ }, options);
28
+ for (const element of elements) {
29
+ observer.observe(element);
30
+ }
31
+ return () => {
32
+ observer.disconnect();
33
+ };
34
+ }
35
+ return func.noop;
36
+ },
37
+ /* @__PURE__ */ new Map()
38
+ );
39
+ return {
40
+ /**
41
+ * Readable of observed elements
42
+ */
43
+ elements$: tansu.asReadable(elements$),
44
+ /**
45
+ * Store of map that contains the visible elements (for the key) and the corresponding entries
46
+ *
47
+ * See the [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/API/IntersectionObserverEntry)
48
+ */
49
+ visibleElements$: tansu.asReadable(visibleElements$),
50
+ patch
51
+ };
52
+ };
53
+ exports.createIntersection = createIntersection;
@@ -1,55 +1,53 @@
1
- import { asReadable, derived } from '@amadeus-it-group/tansu';
2
- import { noop } from '../utils/internal/func';
3
- import { writablesForProps } from '../utils/stores';
1
+ import { derived, asReadable } from "@amadeus-it-group/tansu";
2
+ import { n as noop } from "../func-DR0n-ShK.js";
3
+ import { writablesForProps } from "../utils/stores.js";
4
4
  const defaultValues = {
5
- elements: [],
6
- options: undefined,
5
+ elements: [],
6
+ options: void 0
7
7
  };
8
- /**
9
- * Create an intersection service.
10
- *
11
- * The returned service includes the patch method to set the elements to observe / intersection options and the states to track the visible elements.
12
- *
13
- * @param config - the props config for the intersection service
14
- * @returns the intersection service
15
- */
16
- export const createIntersection = (config) => {
17
- const [{ elements$, options$ }, patch] = writablesForProps(defaultValues, config);
18
- const visibleElements$ = derived([elements$, options$], ([elements, options], set) => {
19
- if (elements.length) {
20
- const visibleElements = new Map();
21
- const observer = new IntersectionObserver((entries) => {
22
- for (const entry of entries) {
23
- const { target, isIntersecting } = entry;
24
- if (isIntersecting) {
25
- visibleElements.set(target, entry);
26
- }
27
- else {
28
- visibleElements.delete(target);
29
- }
30
- }
31
- set(visibleElements);
32
- }, options);
33
- for (const element of elements) {
34
- observer.observe(element);
8
+ const createIntersection = (config) => {
9
+ const [{ elements$, options$ }, patch] = writablesForProps(defaultValues, config);
10
+ const visibleElements$ = derived(
11
+ [elements$, options$],
12
+ ([elements, options], set) => {
13
+ if (elements.length) {
14
+ const visibleElements = /* @__PURE__ */ new Map();
15
+ const observer = new IntersectionObserver((entries) => {
16
+ for (const entry of entries) {
17
+ const { target, isIntersecting } = entry;
18
+ if (isIntersecting) {
19
+ visibleElements.set(target, entry);
20
+ } else {
21
+ visibleElements.delete(target);
35
22
  }
36
- return () => {
37
- observer.disconnect();
38
- };
23
+ }
24
+ set(visibleElements);
25
+ }, options);
26
+ for (const element of elements) {
27
+ observer.observe(element);
39
28
  }
40
- return noop;
41
- }, new Map());
42
- return {
43
- /**
44
- * Readable of observed elements
45
- */
46
- elements$: asReadable(elements$),
47
- /**
48
- * Store of map that contains the visible elements (for the key) and the corresponding entries
49
- *
50
- * See the [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/API/IntersectionObserverEntry)
51
- */
52
- visibleElements$: asReadable(visibleElements$),
53
- patch,
54
- };
29
+ return () => {
30
+ observer.disconnect();
31
+ };
32
+ }
33
+ return noop;
34
+ },
35
+ /* @__PURE__ */ new Map()
36
+ );
37
+ return {
38
+ /**
39
+ * Readable of observed elements
40
+ */
41
+ elements$: asReadable(elements$),
42
+ /**
43
+ * Store of map that contains the visible elements (for the key) and the corresponding entries
44
+ *
45
+ * See the [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/API/IntersectionObserverEntry)
46
+ */
47
+ visibleElements$: asReadable(visibleElements$),
48
+ patch
49
+ };
50
+ };
51
+ export {
52
+ createIntersection
55
53
  };
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const tansu = require("@amadeus-it-group/tansu");
4
+ const esmEnv = require("esm-env");
5
+ const utils_directive = require("../directive-BTSEYLF3.cjs");
6
+ const createMatchMedia = (query) => esmEnv.BROWSER ? tansu.readable(false, {
7
+ onUse({ set }) {
8
+ const mql = window.matchMedia(query.trim());
9
+ set(mql.matches);
10
+ return utils_directive.addEvent(mql, "change", (val) => set(val.matches));
11
+ }
12
+ }) : tansu.readable(false);
13
+ exports.createMatchMedia = createMatchMedia;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Create a store tracking the state of a {@link https://developer.mozilla.org/en-US/docs/Web/API/Window/matchMedia | matchMedia} query.
3
+ *
4
+ * @param query - the query to match
5
+ * @returns a readable store tracking the match media query state
6
+ */
7
+ export declare const createMatchMedia: (query: string) => import("@amadeus-it-group/tansu").ReadableSignal<boolean>;
@@ -0,0 +1,13 @@
1
+ import { readable } from "@amadeus-it-group/tansu";
2
+ import { BROWSER } from "esm-env";
3
+ import { u as addEvent } from "../directive-DCYlDznf.js";
4
+ const createMatchMedia = (query) => BROWSER ? readable(false, {
5
+ onUse({ set }) {
6
+ const mql = window.matchMedia(query.trim());
7
+ set(mql.matches);
8
+ return addEvent(mql, "change", (val) => set(val.matches));
9
+ }
10
+ }) : readable(false);
11
+ export {
12
+ createMatchMedia
13
+ };
@@ -0,0 +1,196 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const tansu = require("@amadeus-it-group/tansu");
4
+ const utils_directive = require("../directive-BTSEYLF3.cjs");
5
+ const isInertOrInvisible = (element) => {
6
+ let curElement = element;
7
+ while (curElement) {
8
+ const style = getComputedStyle(curElement);
9
+ if (curElement.inert || curElement.hidden || style.display === "none" || style.visibility === "hidden") {
10
+ return true;
11
+ }
12
+ curElement = curElement.parentElement;
13
+ }
14
+ return false;
15
+ };
16
+ const checkNotDisabled = (element) => {
17
+ var _a;
18
+ if (element.disabled) {
19
+ return false;
20
+ }
21
+ const parentFieldset = (_a = element.parentElement) == null ? void 0 : _a.closest("fieldset");
22
+ return parentFieldset ? checkNotDisabled(parentFieldset) : true;
23
+ };
24
+ const isFocusableOtherTags = (element) => element.isContentEditable || !!element.hasAttribute("tabindex");
25
+ const isFocusableByTagName = {
26
+ INPUT: (element) => element.type !== "hidden" && checkNotDisabled(element),
27
+ SELECT: checkNotDisabled,
28
+ TEXTAREA: checkNotDisabled,
29
+ BUTTON: checkNotDisabled,
30
+ A: (element) => !!element.href || isFocusableOtherTags(element)
31
+ };
32
+ const isFocusable = (element) => {
33
+ return document.contains(element) && !isInertOrInvisible(element) && (isFocusableByTagName[element.tagName] ?? isFocusableOtherTags)(element);
34
+ };
35
+ const compareDomOrder = (element1, element2) => {
36
+ if (element1 === element2) {
37
+ return 0;
38
+ }
39
+ const result = element1.compareDocumentPosition(element2);
40
+ if (result & Node.DOCUMENT_POSITION_FOLLOWING) {
41
+ return -1;
42
+ } else if (result & Node.DOCUMENT_POSITION_PRECEDING) {
43
+ return 1;
44
+ }
45
+ throw new Error("failed to compare elements");
46
+ };
47
+ const getTextDirection = (element) => getComputedStyle(element).direction;
48
+ const textInputTypes = /* @__PURE__ */ new Set(["text", "search", "url", "tel", "password"]);
49
+ const isTextInput = (element) => element instanceof HTMLInputElement && textInputTypes.has(element.type);
50
+ const getKeyName = (event) => {
51
+ let key = event.key;
52
+ if (event.shiftKey) {
53
+ key = `Shift+${key}`;
54
+ }
55
+ if (event.altKey) {
56
+ key = `Alt+${key}`;
57
+ }
58
+ if (event.ctrlKey) {
59
+ key = `Ctrl+${key}`;
60
+ }
61
+ if (event.metaKey) {
62
+ key = `Meta+${key}`;
63
+ }
64
+ return key;
65
+ };
66
+ const isInternalInputNavigation = (event) => {
67
+ const { target, key } = event;
68
+ if (isTextInput(target) && (key === "ArrowLeft" || key === "ArrowRight" || key === "Home" || key === "End")) {
69
+ let startPosition;
70
+ if (key === "ArrowLeft" || key === "ArrowRight") {
71
+ const direction = getTextDirection(target);
72
+ startPosition = key === (direction === "ltr" ? "ArrowLeft" : "ArrowRight");
73
+ } else {
74
+ startPosition = key === "Home";
75
+ }
76
+ const cursorPosition = target.selectionStart === target.selectionEnd ? target.selectionStart : null;
77
+ if (startPosition && cursorPosition !== 0 || !startPosition && cursorPosition !== target.value.length) {
78
+ return true;
79
+ }
80
+ }
81
+ return false;
82
+ };
83
+ const defaultSelector = (directiveElement) => [directiveElement];
84
+ const createNavManager = () => {
85
+ const directiveInstances$ = utils_directive.registrationArray();
86
+ const elementsRefresh$ = tansu.writable({});
87
+ const refreshElements = (now = true) => {
88
+ elementsRefresh$.set({});
89
+ if (now) {
90
+ commonAncestor$();
91
+ elementsInDomOrder$();
92
+ }
93
+ };
94
+ const elements$ = tansu.computed(() => {
95
+ elementsRefresh$();
96
+ const res = [];
97
+ for (const item of directiveInstances$()) {
98
+ res.push(...item());
99
+ }
100
+ return res;
101
+ });
102
+ const commonAncestor$ = tansu.computed(() => utils_directive.computeCommonAncestor(elements$()), { equal: Object.is });
103
+ const elementsInDomOrder$ = tansu.computed(() => [...elements$()].sort(compareDomOrder));
104
+ const ancestorDirection = () => {
105
+ const commonAncestor = commonAncestor$();
106
+ return commonAncestor ? getTextDirection(commonAncestor) : "ltr";
107
+ };
108
+ const preventDefaultIfRelevant = (value, event) => {
109
+ if (value) {
110
+ event == null ? void 0 : event.preventDefault();
111
+ }
112
+ return value;
113
+ };
114
+ const focusIndex = (index, moveDirection = 0) => {
115
+ const array = elementsInDomOrder$();
116
+ while (index >= 0 && index < array.length) {
117
+ const newItem = array[index];
118
+ if (isFocusable(newItem)) {
119
+ newItem.focus();
120
+ if (moveDirection != 0 && isTextInput(newItem)) {
121
+ const changeDirection = ancestorDirection() !== getTextDirection(newItem);
122
+ const position = moveDirection > 0 !== changeDirection ? 0 : newItem.value.length;
123
+ newItem.setSelectionRange(position, position, position === 0 ? "forward" : "backward");
124
+ }
125
+ return newItem;
126
+ }
127
+ if (moveDirection === 0) {
128
+ break;
129
+ } else {
130
+ index += moveDirection;
131
+ }
132
+ }
133
+ return null;
134
+ };
135
+ const createFocusNeighbour = (moveDirection) => ({
136
+ event,
137
+ referenceElement = (event == null ? void 0 : event.target) ?? document.activeElement
138
+ } = {}) => {
139
+ const curIndex = referenceElement ? elementsInDomOrder$().indexOf(referenceElement) : -1;
140
+ if (curIndex > -1) {
141
+ return preventDefaultIfRelevant(focusIndex(curIndex + moveDirection, moveDirection), event);
142
+ }
143
+ return null;
144
+ };
145
+ const directive = utils_directive.browserDirective((directiveElement, config) => {
146
+ const onKeyDown = (event) => {
147
+ var _a;
148
+ if (isInternalInputNavigation(event)) {
149
+ return;
150
+ }
151
+ const keyName = getKeyName(event);
152
+ const handler = (_a = config.keys) == null ? void 0 : _a[keyName];
153
+ if (handler) {
154
+ refreshElements(false);
155
+ handler({ event, directiveElement, navManager, context: config.context });
156
+ }
157
+ };
158
+ directiveElement.addEventListener("keydown", onKeyDown);
159
+ const unregister = directiveInstances$.register(() => ((config == null ? void 0 : config.selector) ?? defaultSelector)(directiveElement));
160
+ return {
161
+ update(newConfig) {
162
+ config = newConfig;
163
+ },
164
+ destroy() {
165
+ directiveElement.removeEventListener("keydown", onKeyDown);
166
+ unregister();
167
+ }
168
+ };
169
+ });
170
+ const focusPrevious = createFocusNeighbour(-1);
171
+ const focusNext = createFocusNeighbour(1);
172
+ const focusFirst = ({ event } = {}) => preventDefaultIfRelevant(focusIndex(0, 1), event);
173
+ const focusLast = ({ event } = {}) => preventDefaultIfRelevant(focusIndex(elementsInDomOrder$().length - 1, -1), event);
174
+ const focusLeft = (...args) => (ancestorDirection() === "rtl" ? focusNext : focusPrevious)(...args);
175
+ const focusRight = (...args) => (ancestorDirection() === "rtl" ? focusPrevious : focusNext)(...args);
176
+ const focusFirstLeft = (...args) => (ancestorDirection() === "rtl" ? focusLast : focusFirst)(...args);
177
+ const focusFirstRight = (...args) => (ancestorDirection() === "rtl" ? focusFirst : focusLast)(...args);
178
+ const navManager = {
179
+ elementsInDomOrder$,
180
+ directive,
181
+ focusIndex,
182
+ focusPrevious,
183
+ focusNext,
184
+ focusFirst,
185
+ focusFirstLeft,
186
+ focusFirstRight,
187
+ focusLast,
188
+ focusLeft,
189
+ focusRight,
190
+ refreshElements
191
+ };
192
+ return navManager;
193
+ };
194
+ exports.createNavManager = createNavManager;
195
+ exports.getKeyName = getKeyName;
196
+ exports.isInternalInputNavigation = isInternalInputNavigation;
@@ -1,4 +1,3 @@
1
- import type { Directive } from '../types';
2
1
  export type NavManager = ReturnType<typeof createNavManager>;
3
2
  /**
4
3
  * Returns the key name given the keyboard event. The key name is built using event.key (such as ArrowLeft, PageDown...),
@@ -23,27 +22,32 @@ export declare const isInternalInputNavigation: (event: KeyboardEvent) => boolea
23
22
  * - directiveElement: DOM element which has the navigation manager directive
24
23
  * - navManager: navigation manager instance
25
24
  */
26
- export type NavManagerKeyHandler = (info: {
25
+ export type NavManagerKeyHandler<T = any> = (info: {
27
26
  directiveElement: HTMLElement;
28
- event: KeyboardEvent;
27
+ event: Event;
29
28
  navManager: NavManager;
29
+ context?: T;
30
30
  }) => void;
31
31
  /**
32
32
  * Type of the parameter of the navigation manager directive.
33
33
  */
34
- export interface NavManagerItemConfig {
34
+ export interface NavManagerItemConfig<T = any> {
35
35
  /**
36
36
  * Map of key handlers.
37
37
  * The key in the map should match the result of calling {@link getKeyName} on the key event (for example "ArrowLeft" or "Ctrl+PageDown").
38
38
  * The value in the map is the corresponding key handler.
39
39
  */
40
- keys?: Record<string, NavManagerKeyHandler>;
40
+ keys?: Record<string, NavManagerKeyHandler<T>>;
41
41
  /**
42
42
  * Function returning DOM elements to include in the navigation manager.
43
43
  * It receives as a parameter the DOM element on which the navigation manager directive is used.
44
44
  * If not specified, the default selector function only returns the element on which the navigation manager directive is used.
45
45
  */
46
46
  selector?: (directiveElement: HTMLElement) => Iterable<HTMLElement>;
47
+ /**
48
+ *
49
+ */
50
+ context?: T;
47
51
  }
48
52
  /**
49
53
  * Returns a new instance of the navigation manager.
@@ -59,35 +63,38 @@ export interface NavManagerItemConfig {
59
63
  */
60
64
  export declare const createNavManager: () => {
61
65
  elementsInDomOrder$: import("@amadeus-it-group/tansu").ReadableSignal<HTMLElement[]>;
62
- directive: Directive<NavManagerItemConfig>;
66
+ directive: <T = any>(node: import("..").SSRHTMLElement, args: NavManagerItemConfig<T>) => void | {
67
+ update?: ((args: NavManagerItemConfig<T>) => void) | undefined;
68
+ destroy?: (() => void) | undefined;
69
+ };
63
70
  focusIndex: (index: number, moveDirection?: -1 | 0 | 1) => HTMLElement | null;
64
71
  focusPrevious: ({ event, referenceElement, }?: {
65
- event?: KeyboardEvent | undefined;
66
- referenceElement?: HTMLElement | null | undefined;
72
+ event?: Event;
73
+ referenceElement?: HTMLElement | null;
67
74
  }) => HTMLElement | null;
68
75
  focusNext: ({ event, referenceElement, }?: {
69
- event?: KeyboardEvent | undefined;
70
- referenceElement?: HTMLElement | null | undefined;
76
+ event?: Event;
77
+ referenceElement?: HTMLElement | null;
71
78
  }) => HTMLElement | null;
72
79
  focusFirst: ({ event }?: {
73
- event?: KeyboardEvent | undefined;
80
+ event?: Event;
74
81
  }) => HTMLElement | null;
75
82
  focusFirstLeft: (args_0?: {
76
- event?: KeyboardEvent | undefined;
83
+ event?: Event | undefined;
77
84
  } | undefined) => HTMLElement | null;
78
85
  focusFirstRight: (args_0?: {
79
- event?: KeyboardEvent | undefined;
86
+ event?: Event | undefined;
80
87
  } | undefined) => HTMLElement | null;
81
88
  focusLast: ({ event }?: {
82
- event?: KeyboardEvent | undefined;
89
+ event?: Event;
83
90
  }) => HTMLElement | null;
84
91
  focusLeft: (args_0?: {
85
- event?: KeyboardEvent | undefined;
92
+ event?: Event | undefined;
86
93
  referenceElement?: HTMLElement | null | undefined;
87
94
  } | undefined) => HTMLElement | null;
88
95
  focusRight: (args_0?: {
89
- event?: KeyboardEvent | undefined;
96
+ event?: Event | undefined;
90
97
  referenceElement?: HTMLElement | null | undefined;
91
98
  } | undefined) => HTMLElement | null;
92
- refreshElements: () => void;
99
+ refreshElements: (now?: boolean) => void;
93
100
  };