@agnos-ui/core 0.2.0 → 0.3.1

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 (143) 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 +38 -49
  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 +68 -139
  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 +15 -33
  31. package/components/slider/index.cjs +5 -0
  32. package/components/slider/index.js +5 -1
  33. package/components/slider/slider.d.ts +29 -35
  34. package/components/toast/index.cjs +5 -0
  35. package/components/toast/index.js +5 -1
  36. package/components/toast/toast.d.ts +11 -8
  37. package/config.cjs +38 -0
  38. package/config.d.ts +1 -1
  39. package/config.js +35 -50
  40. package/directive-BTSEYLF3.cjs +404 -0
  41. package/directive-DCYlDznf.js +405 -0
  42. package/func-DR0n-ShK.js +7 -0
  43. package/func-Qd3cD9a3.cjs +6 -0
  44. package/index.cjs +119 -0
  45. package/index.d.ts +1 -1
  46. package/index.js +119 -33
  47. package/modal-BI2qUu1M.js +251 -0
  48. package/modal-rzMpATf5.cjs +250 -0
  49. package/package.json +29 -19
  50. package/pagination--GkwduJn.js +263 -0
  51. package/pagination-EWSWQT1I.cjs +262 -0
  52. package/progressbar-DH7DHYMp.cjs +83 -0
  53. package/progressbar-DuRX7_my.js +84 -0
  54. package/promise-BMJ8qhA8.cjs +118 -0
  55. package/promise-CY2U8bTP.js +119 -0
  56. package/rating-BR5wD7y2.js +173 -0
  57. package/rating-CmuYUSxy.cjs +172 -0
  58. package/select-BCs6HQWn.js +358 -0
  59. package/select-CCIKn8WR.cjs +357 -0
  60. package/services/extendWidget.cjs +32 -0
  61. package/services/extendWidget.d.ts +2 -1
  62. package/services/extendWidget.js +31 -34
  63. package/services/floatingUI.cjs +131 -0
  64. package/services/floatingUI.d.ts +30 -14
  65. package/services/floatingUI.js +128 -102
  66. package/services/focustrack.cjs +47 -0
  67. package/services/focustrack.js +45 -44
  68. package/services/hash.cjs +15 -0
  69. package/services/hash.js +14 -12
  70. package/services/intersection.cjs +53 -0
  71. package/services/intersection.js +48 -50
  72. package/services/matchMedia.cjs +13 -0
  73. package/services/matchMedia.d.ts +7 -0
  74. package/services/matchMedia.js +13 -0
  75. package/services/navManager.cjs +196 -0
  76. package/services/navManager.d.ts +9 -9
  77. package/services/navManager.js +186 -168
  78. package/services/portal.cjs +43 -0
  79. package/services/portal.js +41 -42
  80. package/services/resizeObserver.cjs +32 -0
  81. package/services/resizeObserver.d.ts +1 -1
  82. package/services/resizeObserver.js +31 -28
  83. package/services/siblingsInert.cjs +40 -0
  84. package/services/siblingsInert.js +31 -31
  85. package/services/transitions/baseTransitions.cjs +171 -0
  86. package/services/transitions/baseTransitions.d.ts +16 -16
  87. package/services/transitions/baseTransitions.js +159 -170
  88. package/services/transitions/collapse.cjs +44 -0
  89. package/services/transitions/collapse.js +41 -49
  90. package/services/transitions/cssTransitions.cjs +32 -0
  91. package/services/transitions/cssTransitions.d.ts +2 -1
  92. package/services/transitions/cssTransitions.js +29 -39
  93. package/services/transitions/simpleClassTransition.cjs +31 -0
  94. package/services/transitions/simpleClassTransition.js +30 -41
  95. package/slider-CA_fszn7.js +536 -0
  96. package/slider-DsLvT87U.cjs +535 -0
  97. package/toast-8tWp6x89.js +63 -0
  98. package/toast-Aw8o0Iwe.cjs +62 -0
  99. package/types.cjs +12 -0
  100. package/types.d.ts +21 -1
  101. package/types.js +11 -13
  102. package/utils/directive.cjs +26 -0
  103. package/utils/directive.d.ts +148 -5
  104. package/utils/directive.js +25 -205
  105. package/utils/internal/dom.d.ts +43 -4
  106. package/utils/internal/promise.d.ts +2 -2
  107. package/utils/internal/ssrHTMLElement.d.ts +7 -0
  108. package/utils/stores.cjs +163 -0
  109. package/utils/stores.d.ts +9 -17
  110. package/utils/stores.js +149 -284
  111. package/utils/writables.cjs +13 -0
  112. package/utils/writables.js +12 -71
  113. package/writables-D46sFgGK.cjs +85 -0
  114. package/writables-DoU_XYTX.js +86 -0
  115. package/components/accordion/accordion.js +0 -264
  116. package/components/alert/alert.js +0 -22
  117. package/components/alert/common.js +0 -69
  118. package/components/commonProps.js +0 -1
  119. package/components/modal/modal.js +0 -186
  120. package/components/pagination/bootstrap.d.ts +0 -8
  121. package/components/pagination/bootstrap.js +0 -110
  122. package/components/pagination/pagination.js +0 -195
  123. package/components/progressbar/progressbar.js +0 -78
  124. package/components/rating/rating.js +0 -137
  125. package/components/select/select.js +0 -297
  126. package/components/slider/slider.js +0 -420
  127. package/components/toast/toast.js +0 -43
  128. package/services/transitions/bootstrap/collapse.d.ts +0 -2
  129. package/services/transitions/bootstrap/collapse.js +0 -15
  130. package/services/transitions/bootstrap/fade.d.ts +0 -1
  131. package/services/transitions/bootstrap/fade.js +0 -7
  132. package/services/transitions/bootstrap.d.ts +0 -2
  133. package/services/transitions/bootstrap.js +0 -2
  134. package/utils/internal/checks.js +0 -60
  135. package/utils/internal/dom.js +0 -82
  136. package/utils/internal/func.js +0 -11
  137. package/utils/internal/isFocusable.js +0 -37
  138. package/utils/internal/math.js +0 -13
  139. package/utils/internal/promise.js +0 -169
  140. package/utils/internal/scrollbars.js +0 -33
  141. package/utils/internal/sort.js +0 -28
  142. package/utils/internal/textDirection.js +0 -7
  143. package/utils/internal/traversal.js +0 -105
package/types.d.ts CHANGED
@@ -75,10 +75,27 @@ export type WidgetProps<T extends {
75
75
  patch: (arg: Partial<infer U extends object>) => void;
76
76
  } ? U : never;
77
77
  export type WidgetFactory<W extends Widget> = (props?: PropsConfig<WidgetProps<W>>) => W;
78
- export type Directive<T = void> = (node: HTMLElement, args: T) => void | {
78
+ /**
79
+ * Subset of HTMLElement that is available in a server side rendering context.
80
+ */
81
+ export interface SSRHTMLElement extends Pick<HTMLElement, 'setAttribute' | 'removeAttribute'> {
82
+ /**
83
+ * Object allowing to manipulate the classes of the element.
84
+ */
85
+ classList: Pick<HTMLElement['classList'], 'add' | 'remove' | 'toggle'>;
86
+ /**
87
+ * Object allowing to manipulate the style of the element.
88
+ */
89
+ style: Partial<Record<StyleKey, StyleValue>>;
90
+ }
91
+ export type Directive<T = void, U extends SSRHTMLElement = SSRHTMLElement> = (node: U, args: T) => void | {
79
92
  update?: (args: T) => void;
80
93
  destroy?: () => void;
81
94
  };
95
+ export type DirectiveAndParam<T, U extends SSRHTMLElement = SSRHTMLElement> = [Directive<T, U>, T];
96
+ export type DirectivesAndOptParam<T extends any[], U extends SSRHTMLElement = SSRHTMLElement> = {
97
+ [K in keyof T]: Directive<void, U> | DirectiveAndParam<T[K], U>;
98
+ };
82
99
  export type SlotContent<Props extends object = object> = undefined | null | string | ((props: Props) => string);
83
100
  export declare const INVALID_VALUE: unique symbol;
84
101
  export type NormalizeValue<T> = (value: T) => T | typeof INVALID_VALUE;
@@ -95,3 +112,6 @@ export interface WritableWithDefaultOptions<T> {
95
112
  export type ConfigValidator<T extends object> = {
96
113
  [K in keyof T]?: WritableWithDefaultOptions<T[K]>;
97
114
  };
115
+ export type AttributeValue = string | number | boolean | undefined;
116
+ export type StyleKey = Exclude<keyof CSSStyleDeclaration, 'length' | 'item' | 'parentRule' | 'getPropertyValue' | 'getPropertyPriority' | 'setProperty' | 'removeProperty' | typeof Symbol.iterator | number | 'cssText'>;
117
+ export type StyleValue = string | undefined | null;
package/types.js CHANGED
@@ -1,14 +1,12 @@
1
- /**
2
- * Extract actions, api, directives, state and stores from the widget to be passed to slots as context.
3
- *
4
- * @param w - the widget
5
- * @returns the slot context
6
- */
7
- export const toSlotContextWidget = (w) => ({
8
- actions: w.actions,
9
- api: w.api,
10
- directives: w.directives,
11
- state$: w.state$,
12
- stores: w.stores,
1
+ const toSlotContextWidget = (w) => ({
2
+ actions: w.actions,
3
+ api: w.api,
4
+ directives: w.directives,
5
+ state$: w.state$,
6
+ stores: w.stores
13
7
  });
14
- export const INVALID_VALUE = Symbol();
8
+ const INVALID_VALUE = Symbol();
9
+ export {
10
+ INVALID_VALUE,
11
+ toSlotContextWidget
12
+ };
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ require("@amadeus-it-group/tansu");
4
+ require("esm-env");
5
+ const utils_directive = require("../directive-BTSEYLF3.cjs");
6
+ require("../func-Qd3cD9a3.cjs");
7
+ require("./stores.cjs");
8
+ exports.attributesData = utils_directive.attributesData;
9
+ exports.bindDirective = utils_directive.bindDirective;
10
+ exports.bindDirectiveNoArg = utils_directive.bindDirectiveNoArg;
11
+ exports.browserDirective = utils_directive.browserDirective;
12
+ exports.classDirective = utils_directive.classDirective;
13
+ exports.createAttributesDirective = utils_directive.createAttributesDirective;
14
+ exports.createBrowserStoreArrayDirective = utils_directive.createBrowserStoreArrayDirective;
15
+ exports.createBrowserStoreDirective = utils_directive.createBrowserStoreDirective;
16
+ exports.createStoreArrayDirective = utils_directive.createStoreArrayDirective;
17
+ exports.createStoreDirective = utils_directive.createStoreDirective;
18
+ exports.directiveAttributes = utils_directive.directiveAttributes;
19
+ exports.directiveSubscribe = utils_directive.directiveSubscribe;
20
+ exports.directiveUpdate = utils_directive.directiveUpdate;
21
+ exports.isBrowserHTMLElement = utils_directive.isBrowserHTMLElement;
22
+ exports.mapDirectiveArg = utils_directive.mapDirectiveArg;
23
+ exports.mergeDirectives = utils_directive.mergeDirectives;
24
+ exports.multiDirective = utils_directive.multiDirective;
25
+ exports.registrationArray = utils_directive.registrationArray;
26
+ exports.ssrAttributes = utils_directive.ssrAttributes;
@@ -1,5 +1,18 @@
1
1
  import type { ReadableSignal } from '@amadeus-it-group/tansu';
2
- import type { Directive } from '../types';
2
+ import type { AttributeValue, Directive, DirectivesAndOptParam, SSRHTMLElement, StyleKey, StyleValue } from '../types';
3
+ /**
4
+ * On a browser environment, returns true if the given element is an HTMLElement.
5
+ * On a server environment, always returns false.
6
+ * @param element - The element to check.
7
+ * @returns true in a browser environment if the given element is an HTMLElement, otherwise false.
8
+ */
9
+ export declare const isBrowserHTMLElement: (element: SSRHTMLElement) => element is HTMLElement;
10
+ /**
11
+ * Creates a directive that wraps the provided directive to only run it in a browser environment (and not in a server-side rendering environment).
12
+ * @param directive - The directive to run only in a browser.
13
+ * @returns The wrapped directive.
14
+ */
15
+ export declare const browserDirective: <T, U extends HTMLElement>(directive: Directive<T, U>) => Directive<T, SSRHTMLElement>;
3
16
  /**
4
17
  * Binds the given directive to a store that provides its argument.
5
18
  *
@@ -13,7 +26,7 @@ import type { Directive } from '../types';
13
26
  * @param directiveArg$ - store containing the argument of the directive
14
27
  * @returns The bound directive that can be used with no argument.
15
28
  */
16
- export declare const bindDirective: <T>(directive: Directive<T>, directiveArg$: ReadableSignal<T>) => Directive;
29
+ export declare const bindDirective: <T, U extends SSRHTMLElement = SSRHTMLElement>(directive: Directive<T, U>, directiveArg$: ReadableSignal<T>) => Directive<void, U>;
17
30
  /**
18
31
  * Returns a directive that ignores any argument passed to it and calls the provided directive without any
19
32
  * argument.
@@ -21,7 +34,7 @@ export declare const bindDirective: <T>(directive: Directive<T>, directiveArg$:
21
34
  * @param directive - directive to wrap
22
35
  * @returns The resulting directive.
23
36
  */
24
- export declare const bindDirectiveNoArg: <T>(directive: Directive<void | T>) => Directive;
37
+ export declare const bindDirectiveNoArg: <T, U extends SSRHTMLElement = SSRHTMLElement>(directive: Directive<T | void, U>) => Directive<void, U>;
25
38
  /**
26
39
  * Maps the argument to another argument of a directive using a provided function.
27
40
  *
@@ -29,7 +42,7 @@ export declare const bindDirectiveNoArg: <T>(directive: Directive<void | T>) =>
29
42
  * @param fn - The function to map the argument.
30
43
  * @returns A new directive that applies the mapping function to the argument.
31
44
  */
32
- export declare const mapDirectiveArg: <T, U>(directive: Directive<U>, fn: (arg: T) => U) => Directive<T>;
45
+ export declare const mapDirectiveArg: <T, U, V extends SSRHTMLElement = SSRHTMLElement>(directive: Directive<U, V>, fn: (arg: T) => U) => Directive<T, V>;
33
46
  /**
34
47
  * Returns a directive that subscribes to the given store while it is used on a DOM element,
35
48
  * and that unsubscribes from it when it is no longer used.
@@ -60,6 +73,9 @@ export declare const registrationArray: <T>() => ReadableSignal<T[]> & {
60
73
  * currently used.
61
74
  *
62
75
  * @remarks
76
+ * It is the same as {@link createBrowserStoreArrayDirective}, but the returned directive is also executed in a server environment
77
+ * and the type of the elements is {@link SSRHTMLElement} instead of HTMLElement.
78
+ *
63
79
  * If the directive is intended to be used on a single element element, it may be more appropriate to use
64
80
  * {@link createStoreDirective} instead.
65
81
  *
@@ -69,6 +85,25 @@ export declare const registrationArray: <T>() => ReadableSignal<T[]> & {
69
85
  */
70
86
  export declare const createStoreArrayDirective: () => {
71
87
  directive: Directive;
88
+ elements$: ReadableSignal<SSRHTMLElement[]>;
89
+ };
90
+ /**
91
+ * Returns a directive and a store. The store contains at any time the array of all the DOM elements on which the directive is
92
+ * currently used.
93
+ *
94
+ * @remarks
95
+ * It is the same as {@link createStoreArrayDirective}, but the returned directive is only executed in a browser environment
96
+ * and the type of the elements is HTMLElement instead of {@link SSRHTMLElement}.
97
+ *
98
+ * If the directive is intended to be used on a single element element, it may be more appropriate to use
99
+ * {@link createBrowserStoreDirective} instead.
100
+ *
101
+ * @returns An object with two properties: the `directive` property that is the directive to use on some DOM elements,
102
+ * and the `elements$` property that is the store containing an array of all the elements on which the directive is currently
103
+ * used.
104
+ */
105
+ export declare const createBrowserStoreArrayDirective: () => {
106
+ directive: Directive<void, SSRHTMLElement>;
72
107
  elements$: ReadableSignal<HTMLElement[]>;
73
108
  };
74
109
  /**
@@ -76,6 +111,9 @@ export declare const createStoreArrayDirective: () => {
76
111
  * When the directive is not used, the store contains null.
77
112
  *
78
113
  * @remarks
114
+ * It is the same as {@link createBrowserStoreDirective}, but the returned directive is also executed in a server environment
115
+ * and the type of the element is {@link SSRHTMLElement} instead of HTMLElement.
116
+ *
79
117
  * If the directive is used on more than one element, an error is displayed in the console and the element is ignored.
80
118
  * If the directive is intended to be used on more than one element, please use {@link createStoreArrayDirective} instead.
81
119
  *
@@ -85,6 +123,25 @@ export declare const createStoreArrayDirective: () => {
85
123
  */
86
124
  export declare const createStoreDirective: () => {
87
125
  directive: Directive;
126
+ element$: ReadableSignal<SSRHTMLElement | null>;
127
+ };
128
+ /**
129
+ * Returns a directive and a store. When the directive is used on a DOM element, the store contains that DOM element.
130
+ * When the directive is not used, the store contains null.
131
+ *
132
+ * @remarks
133
+ * It is the same as {@link createStoreDirective}, but the returned directive is only executed in a browser environment
134
+ * and the type of the element is HTMLElement instead of {@link SSRHTMLElement}.
135
+ *
136
+ * If the directive is used on more than one element, an error is displayed in the console and the element is ignored.
137
+ * If the directive is intended to be used on more than one element, please use {@link createStoreArrayDirective} instead.
138
+ *
139
+ * @returns An object with two properties: the `directive` property that is the directive to use on one DOM element,
140
+ * and the `element$` property that is the store containing the element on which the directive is currently used (or null
141
+ * if the store is not currently used).
142
+ */
143
+ export declare const createBrowserStoreDirective: () => {
144
+ directive: Directive<void, SSRHTMLElement>;
88
145
  element$: ReadableSignal<HTMLElement | null>;
89
146
  };
90
147
  /**
@@ -100,4 +157,90 @@ export declare const createStoreDirective: () => {
100
157
  * @param args - directives to merge into a single directive.
101
158
  * @returns The resulting merged directive.
102
159
  */
103
- export declare const mergeDirectives: <T>(...args: (Directive | Directive<T>)[]) => Directive<T>;
160
+ export declare const mergeDirectives: <T, U extends SSRHTMLElement = SSRHTMLElement>(...args: (Directive<T, U> | Directive<void, U>)[]) => Directive<T, U>;
161
+ /**
162
+ * Directive that applies all the directives passed as arguments.
163
+ *
164
+ * @param element - the element to apply the directives to
165
+ * @param directives - the directives to apply
166
+ * @returns The directive instance.
167
+ */
168
+ export declare const multiDirective: <T extends any[], U extends SSRHTMLElement = SSRHTMLElement>(element: U, directives: DirectivesAndOptParam<T, U>) => {
169
+ update: (directives: DirectivesAndOptParam<any[], U>) => void;
170
+ destroy: () => void;
171
+ };
172
+ /**
173
+ * Properties for configuring server-side rendering directives.
174
+ */
175
+ export interface AttributesDirectiveProps {
176
+ /**
177
+ * Events to be attached to an HTML element.
178
+ * @remarks
179
+ * Key-value pairs where keys are event types and values are event handlers.
180
+ */
181
+ events?: Partial<{
182
+ [K in keyof HTMLElementEventMap]: {
183
+ handler: (this: HTMLElement, event: HTMLElementEventMap[K]) => void;
184
+ options?: boolean | AddEventListenerOptions;
185
+ } | ((this: HTMLElement, event: HTMLElementEventMap[K]) => void);
186
+ }>;
187
+ /**
188
+ * Attributes to be added to the provided node.
189
+ * @remarks
190
+ * The `style` attribute must be added separately.
191
+ */
192
+ attributes?: Record<string, AttributeValue | ReadableSignal<AttributeValue>>;
193
+ /**
194
+ * Styles to be added to an HTML element.
195
+ * @remarks
196
+ * Key-value pairs where keys are CSS style properties and values are style values.
197
+ */
198
+ styles?: Partial<Record<StyleKey, StyleValue | ReadableSignal<StyleValue>>>;
199
+ /**
200
+ * Class names to be added to an HTML element.
201
+ * @remarks
202
+ * Key-value pairs where keys are class names and values indicate whether the class should be added (true) or removed (false).
203
+ */
204
+ classNames?: Record<string, boolean | ReadableSignal<boolean>>;
205
+ }
206
+ /**
207
+ * Creates a directive for server-side rendering with bindable elements.
208
+ * This directive binds events, attributes, styles, and classNames to an HTML element.
209
+ *
210
+ * @param propsFn - A function that returns the AttributesDirectiveProps with the data to bind.
211
+ * This function can take an optional parameter that corrspond to the second parameter of the created directive.
212
+ * @returns A directive object with bound events, attributes, styles, and classNames.
213
+ */
214
+ export declare const createAttributesDirective: <T = void>(propsFn: (arg: ReadableSignal<T>) => AttributesDirectiveProps) => Directive<T>;
215
+ /**
216
+ * Returns an object with the attributes, style and class keys containing information derived from a list of directives.
217
+ *
218
+ * - The `attributes` value is a JSON representation of key/value attributes, excepted for the `class` and `style` attributes
219
+ * - The `classNames` value is an array of string representing the classes to be applied
220
+ * - The `style` value is a JSON representation of the styles to be applied
221
+ *
222
+ * @param directives - List of directives to generate attributes from. Each parameter can be the directive or an array with the directive and its parameter
223
+ * @returns JSON object with the `attributes`, `class` and `style` keys.
224
+ */
225
+ export declare const attributesData: <T extends any[]>(...directives: DirectivesAndOptParam<T>) => {
226
+ attributes: Record<string, string>;
227
+ classNames: string[];
228
+ style: Partial<Record<StyleKey, StyleValue>>;
229
+ };
230
+ /**
231
+ * Directive that takes as an argument a string containing CSS classes to be put on the HTML element.
232
+ */
233
+ export declare const classDirective: Directive<string>;
234
+ /**
235
+ * Returns JSON representation of the attributes to be applied derived from a list of directives.
236
+ *
237
+ * @param directives - List of directives to generate attributes from. Each parameter can be the directive or an array with the directive and its parameter
238
+ * @returns JSON object with name/value for the attributes
239
+ */
240
+ export declare function directiveAttributes<T extends any[]>(...directives: DirectivesAndOptParam<T>): Record<string, string>;
241
+ /**
242
+ * Same as {@link directiveAttributes}, but returns an empty object when run in a browser environement.
243
+ *
244
+ * @returns JSON object with name/value for the attributes
245
+ */
246
+ export declare const ssrAttributes: (() => {}) | typeof directiveAttributes;
@@ -1,206 +1,26 @@
1
- import { asReadable, batch, readable, writable } from '@amadeus-it-group/tansu';
2
- import { noop } from './internal/func';
3
- /**
4
- * Binds the given directive to a store that provides its argument.
5
- *
6
- * @remarks
7
- *
8
- * The returned directive can be used without argument, it will ignore any argument passed to it
9
- * and will call the provided directive with the content of the provided store as its argument,
10
- * calling its update method when the content of the store changes.
11
- *
12
- * @param directive - directive to bind
13
- * @param directiveArg$ - store containing the argument of the directive
14
- * @returns The bound directive that can be used with no argument.
15
- */
16
- export const bindDirective = (directive, directiveArg$) => {
17
- return (element) => {
18
- let firstTime = true;
19
- let instance;
20
- const unsubscribe = directiveArg$.subscribe((value) => {
21
- if (firstTime) {
22
- firstTime = false;
23
- instance = directive(element, value);
24
- }
25
- else {
26
- instance?.update?.(value);
27
- }
28
- });
29
- return {
30
- destroy() {
31
- instance?.destroy?.();
32
- unsubscribe();
33
- },
34
- };
35
- };
36
- };
37
- const noArg = readable(undefined);
38
- /**
39
- * Returns a directive that ignores any argument passed to it and calls the provided directive without any
40
- * argument.
41
- *
42
- * @param directive - directive to wrap
43
- * @returns The resulting directive.
44
- */
45
- export const bindDirectiveNoArg = (directive) => bindDirective(directive, noArg);
46
- /**
47
- * Maps the argument to another argument of a directive using a provided function.
48
- *
49
- * @param directive - The directive to be applied.
50
- * @param fn - The function to map the argument.
51
- * @returns A new directive that applies the mapping function to the argument.
52
- */
53
- export const mapDirectiveArg = (directive, fn) => (node, arg) => {
54
- const instance = directive(node, fn(arg));
55
- return {
56
- update: (arg) => {
57
- instance?.update?.(fn(arg));
58
- },
59
- destroy: () => instance?.destroy?.(),
60
- };
61
- };
62
- /**
63
- * Returns a directive that subscribes to the given store while it is used on a DOM element,
64
- * and that unsubscribes from it when it is no longer used.
65
- *
66
- * @param store - store on which there will be an active subscription while the returned directive is used.
67
- * @param asyncUnsubscribe - true if unsubscribing from the store should be done asynchronously (which is the default), and
68
- * false if it should be done synchronously when the directive is destroyed
69
- * @returns The resulting directive.
70
- */
71
- export const directiveSubscribe = (store, asyncUnsubscribe = true) => () => {
72
- const unsubscribe = store.subscribe(noop);
73
- return {
74
- destroy: async () => {
75
- if (asyncUnsubscribe) {
76
- await 0;
77
- }
78
- unsubscribe();
79
- },
80
- };
81
- };
82
- /**
83
- * Returns a directive that calls the provided function with the arguments passed to the directive
84
- * on initialization and each time they are updated.
85
- *
86
- * @param update - Function called with the directive argument when the directive is initialized and when its argument is updated.
87
- * @returns The resulting directive.
88
- */
89
- export const directiveUpdate = (update) => (element, arg) => {
90
- update(arg);
91
- return {
92
- update,
93
- };
94
- };
95
- const equalOption = { equal: Object.is };
96
- /**
97
- * Utility to create a store that contains an array of items.
98
- * @returns a store containing an array of items.
99
- */
100
- export const registrationArray = () => {
101
- const elements$ = writable([], equalOption);
102
- return asReadable(elements$, {
103
- /**
104
- * Add the given element to the array.
105
- * @param element - Element to be added to the array.
106
- * @returns A function to remove the element from the array.
107
- */
108
- register: (element) => {
109
- let removed = false;
110
- elements$.update((currentElements) => [...currentElements, element]);
111
- return () => {
112
- if (!removed) {
113
- removed = true;
114
- elements$.update((currentElements) => {
115
- const index = currentElements.indexOf(element);
116
- if (index > -1) {
117
- const copy = [...currentElements];
118
- copy.splice(index, 1);
119
- return copy;
120
- }
121
- return currentElements; // no change
122
- });
123
- }
124
- };
125
- },
126
- });
127
- };
128
- /**
129
- * Returns a directive and a store. The store contains at any time the array of all the DOM elements on which the directive is
130
- * currently used.
131
- *
132
- * @remarks
133
- * If the directive is intended to be used on a single element element, it may be more appropriate to use
134
- * {@link createStoreDirective} instead.
135
- *
136
- * @returns An object with two properties: the `directive` property that is the directive to use on some DOM elements,
137
- * and the `elements$` property that is the store containing an array of all the elements on which the directive is currently
138
- * used.
139
- */
140
- export const createStoreArrayDirective = () => {
141
- const elements$ = registrationArray();
142
- return {
143
- elements$: asReadable(elements$),
144
- directive: (element) => ({ destroy: elements$.register(element) }),
145
- };
146
- };
147
- /**
148
- * Returns a directive and a store. When the directive is used on a DOM element, the store contains that DOM element.
149
- * When the directive is not used, the store contains null.
150
- *
151
- * @remarks
152
- * If the directive is used on more than one element, an error is displayed in the console and the element is ignored.
153
- * If the directive is intended to be used on more than one element, please use {@link createStoreArrayDirective} instead.
154
- *
155
- * @returns An object with two properties: the `directive` property that is the directive to use on one DOM element,
156
- * and the `element$` property that is the store containing the element on which the directive is currently used (or null
157
- * if the store is not currently used).
158
- */
159
- export const createStoreDirective = () => {
160
- const element$ = writable(null, equalOption);
161
- return {
162
- element$: asReadable(element$),
163
- directive: (element) => {
164
- let valid = false;
165
- element$.update((currentElement) => {
166
- if (currentElement) {
167
- console.error('The directive cannot be used on multiple elements.', currentElement, element);
168
- return currentElement;
169
- }
170
- valid = true;
171
- return element;
172
- });
173
- return valid
174
- ? {
175
- destroy() {
176
- element$.update((currentElement) => (element === currentElement ? null : currentElement));
177
- },
178
- }
179
- : undefined;
180
- },
181
- };
182
- };
183
- /**
184
- * Merges multiple directives into a single directive that executes all of them when called.
185
- *
186
- * @remarks
187
- * All directives receive the same argument upon initialization and update.
188
- * Directives are created and updated in the same order as they appear in the arguments list,
189
- * they are destroyed in the reverse order.
190
- * All calls to the directives (to create, update and destroy them) are wrapped in a call to the
191
- * batch function of tansu
192
- *
193
- * @param args - directives to merge into a single directive.
194
- * @returns The resulting merged directive.
195
- */
196
- export const mergeDirectives = (...args) => (element, arg) => {
197
- const instances = batch(() => args.map((directive) => directive(element, arg)));
198
- return {
199
- update(arg) {
200
- batch(() => instances.forEach((instance) => instance?.update?.(arg)));
201
- },
202
- destroy() {
203
- batch(() => instances.reverse().forEach((instance) => instance?.destroy?.()));
204
- },
205
- };
1
+ import "@amadeus-it-group/tansu";
2
+ import "esm-env";
3
+ import { o, a, c, b, p, n, g, j, f, h, q, d, e, i, m, k, l, r, s } from "../directive-DCYlDznf.js";
4
+ import "../func-DR0n-ShK.js";
5
+ import "./stores.js";
6
+ export {
7
+ o as attributesData,
8
+ a as bindDirective,
9
+ c as bindDirectiveNoArg,
10
+ b as browserDirective,
11
+ p as classDirective,
12
+ n as createAttributesDirective,
13
+ g as createBrowserStoreArrayDirective,
14
+ j as createBrowserStoreDirective,
15
+ f as createStoreArrayDirective,
16
+ h as createStoreDirective,
17
+ q as directiveAttributes,
18
+ d as directiveSubscribe,
19
+ e as directiveUpdate,
20
+ i as isBrowserHTMLElement,
21
+ m as mapDirectiveArg,
22
+ k as mergeDirectives,
23
+ l as multiDirective,
24
+ r as registrationArray,
25
+ s as ssrAttributes
206
26
  };
@@ -1,3 +1,5 @@
1
+ import type { ReadableSignal } from '@amadeus-it-group/tansu';
2
+ import type { AttributeValue, SSRHTMLElement, StyleKey, StyleValue } from '../../types';
1
3
  /**
2
4
  * Returns the common ancestor of the provided DOM elements.
3
5
  * @param elements - array of DOM elements
@@ -8,33 +10,70 @@ export declare const computeCommonAncestor: (elements: HTMLElement[]) => HTMLEle
8
10
  * Launch a reflow using a call to the provided html element getBoudingClientRect
9
11
  * @param element - the html element
10
12
  */
11
- export declare function reflow(element?: HTMLElement): void;
13
+ export declare const reflow: (element?: SSRHTMLElement) => void;
12
14
  /**
13
15
  * Attach the given css classes to the element
14
16
  *
15
17
  * @param element - the HTML element
16
18
  * @param classes - the css lcasses
17
19
  */
18
- export declare const addClasses: (element: HTMLElement, classes?: string[]) => void;
20
+ export declare const addClasses: (element: SSRHTMLElement, classes?: string[]) => void;
19
21
  /**
20
22
  * Remove the given css classes to the element
21
23
  *
22
24
  * @param element - the HTML element
23
25
  * @param classes - the css classes
24
26
  */
25
- export declare const removeClasses: (element: HTMLElement, classes?: string[]) => void;
27
+ export declare const removeClasses: (element: SSRHTMLElement, classes?: string[]) => void;
26
28
  /**
27
29
  * Adds an event listener to the specified element.
28
30
  *
29
31
  * @param element - The HTML element to which the event listener will be added.
30
32
  * @param type - A string representing the event type to listen for.
31
33
  * @param fn - The event listener function or object.
34
+ * @param options - An options object that specifies characteristics about the event listener.
32
35
  * @returns A function that removes the event listener from the element.
33
36
  */
34
- export declare function addEvent<K extends keyof HTMLElementEventMap>(element: HTMLElement, type: K, fn: (this: HTMLElement, ev: HTMLElementEventMap[K]) => any): () => void;
37
+ export declare function addEvent<K extends keyof HTMLElementEventMap, T extends HTMLElementEventMap[K]>(element: EventTarget, type: K, fn: (this: EventTarget, ev: T) => any, options?: boolean | AddEventListenerOptions): () => void;
35
38
  /**
36
39
  * Generates a unique ID with the format 'auId-[counter]'.
37
40
  *
38
41
  * @returns The generated ID.
39
42
  */
40
43
  export declare const generateId: () => string;
44
+ /**
45
+ * Binds a value from a `ReadableSignal` to the specified attribute of an HTML element.
46
+ * When the value emitted by the signal changes, it updates the attribute accordingly.
47
+ * If the value is null, undefined or `false`, the attribute is removed from the element.
48
+ * An empty string or `true` will result in an attribute with an empty value
49
+ *
50
+ * @param node The HTML element to bind the attribute to.
51
+ * @param attributeName The name of the attribute to bind.
52
+ * @param value$ The `ReadableSignal` representing the value to bind to the attribute.
53
+ *
54
+ * @returns unsubscription method to remove the binding
55
+ */
56
+ export declare function bindAttribute(node: SSRHTMLElement, attributeName: string, value$: ReadableSignal<AttributeValue>): import("@amadeus-it-group/tansu").UnsubscribeFunction & import("@amadeus-it-group/tansu").UnsubscribeObject;
57
+ /**
58
+ * Binds a value from a `ReadableSignal` to the specified CSS style property of an HTML element.
59
+ * When the value emitted by the signal changes, it updates the style property accordingly.
60
+ * If the value is null, undefined or an empty string, the style property is cleared.
61
+ *
62
+ * @param node The HTML element to bind the style property to.
63
+ * @param styleName The name of the CSS style property to bind.
64
+ * @param value$ The `ReadableSignal` representing the value to bind to the style property.
65
+ *
66
+ * @returns unsubscription method to remove the binding
67
+ */
68
+ export declare function bindStyle(node: SSRHTMLElement, styleName: StyleKey, value$: ReadableSignal<StyleValue>): import("@amadeus-it-group/tansu").UnsubscribeFunction & import("@amadeus-it-group/tansu").UnsubscribeObject;
69
+ /**
70
+ * Binds a `ReadableSignal` of boolean to the specified className of an HTML element.
71
+ * The className is added when the value is true, removed otherwise
72
+ *
73
+ * @param node - The HTML element to bind the style property to.
74
+ * @param className - The className to bind.
75
+ * @param value$ - The `ReadableSignal` representing the value to bind to the className.
76
+ *
77
+ * @returns unsubscription method to remove the binding
78
+ */
79
+ export declare function bindClassName(node: SSRHTMLElement, className: string, value$: ReadableSignal<boolean>): () => void;
@@ -31,7 +31,7 @@ export declare const promiseStoreToPromiseStateStore: <T>(promiseStore$: Readabl
31
31
  * @param equal - an equal function to compare values
32
32
  * @returns the value store
33
33
  */
34
- export declare const promiseStateStoreToValueStore: <T>(store$: ReadableSignal<PromiseState<T>>, initialValue: T, equal?: ((a: T, b: T) => boolean) | undefined) => ReadableSignal<T>;
34
+ export declare const promiseStateStoreToValueStore: <T>(store$: ReadableSignal<PromiseState<T>>, initialValue: T, equal?: (a: T, b: T) => boolean) => ReadableSignal<T>;
35
35
  /**
36
36
  * Create a value store from a promise store
37
37
  *
@@ -42,7 +42,7 @@ export declare const promiseStateStoreToValueStore: <T>(store$: ReadableSignal<P
42
42
  * @param equal - an equal function to compare values
43
43
  * @returns the value store
44
44
  */
45
- export declare const promiseStoreToValueStore: <T>(promiseStore$: ReadableSignal<T>, initialValue: Awaited<T>, equal?: ((a: Awaited<T>, b: Awaited<T>) => boolean) | undefined) => ReadableSignal<Awaited<T>>;
45
+ export declare const promiseStoreToValueStore: <T>(promiseStore$: ReadableSignal<T>, initialValue: Awaited<T>, equal?: (a: Awaited<T>, b: Awaited<T>) => boolean) => ReadableSignal<Awaited<T>>;
46
46
  /**
47
47
  * Create a promise from a readable store and a fulfilled condition function.
48
48
  *
@@ -0,0 +1,7 @@
1
+ import type { SSRHTMLElement } from '../../types';
2
+ export declare const ssrHTMLElementAttributesAndStyle: unique symbol;
3
+ /**
4
+ * Create an SSRHTMLElement
5
+ * @returns the created SSRHTMLElement
6
+ */
7
+ export declare const ssrHTMLElement: () => SSRHTMLElement;