@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
@@ -0,0 +1,163 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const tansu = require("@amadeus-it-group/tansu");
4
+ const types = require("../types.cjs");
5
+ const func = require("../func-Qd3cD9a3.cjs");
6
+ function createPatch(stores) {
7
+ return function(storesValues) {
8
+ tansu.batch(() => {
9
+ var _a;
10
+ for (const [name, value] of Object.entries(storesValues ?? {})) {
11
+ (_a = stores[`${name}$`]) == null ? void 0 : _a.set(value);
12
+ }
13
+ });
14
+ };
15
+ }
16
+ function findChangedProperties(obj1, obj2) {
17
+ if (obj1 === obj2) {
18
+ return null;
19
+ }
20
+ let hasUpdate = false;
21
+ const changedValues = {};
22
+ const keys = /* @__PURE__ */ new Set([...Object.keys(obj1), ...Object.keys(obj2)]);
23
+ for (const key of keys) {
24
+ const value = obj2[key];
25
+ if (obj1[key] !== value) {
26
+ changedValues[key] = value;
27
+ hasUpdate = true;
28
+ }
29
+ }
30
+ return hasUpdate ? changedValues : null;
31
+ }
32
+ function writableWithDefault(defValue, config$ = tansu.readable(void 0), options = {}, own$ = tansu.writable(void 0)) {
33
+ const { normalizeValue = func.identity, equal = Object.is } = options;
34
+ const getDefValue = () => defValue;
35
+ const callNormalizeValue = (value, defValue2 = getDefValue) => {
36
+ const normalizedValue = value === void 0 ? void 0 : normalizeValue(value);
37
+ if (normalizedValue === types.INVALID_VALUE) {
38
+ console.error("Not using invalid value", value);
39
+ return defValue2();
40
+ }
41
+ if (normalizedValue === void 0) {
42
+ return defValue2();
43
+ }
44
+ return normalizedValue;
45
+ };
46
+ const validatedDefConfig$ = tansu.computed(() => callNormalizeValue(config$()), { equal });
47
+ const validatedOwnValue$ = tansu.computed(() => callNormalizeValue(own$(), validatedDefConfig$), { equal });
48
+ return tansu.asWritable(validatedOwnValue$, (value) => {
49
+ if (value !== void 0) {
50
+ const normalizedValue = normalizeValue(value);
51
+ if (normalizedValue === types.INVALID_VALUE) {
52
+ console.error("Not setting invalid value", value);
53
+ return;
54
+ }
55
+ value = normalizedValue;
56
+ }
57
+ own$.set(value);
58
+ });
59
+ }
60
+ const isStore = (x) => !!(x && typeof x === "function" && "subscribe" in x);
61
+ const toReadableStore = (x) => isStore(x) ? x : tansu.readable(x);
62
+ const toWritableStore = (x) => isStore(x) ? x : tansu.writable(x);
63
+ const normalizeConfigStores = (keys, config) => {
64
+ const res = {};
65
+ if (config) {
66
+ const configIsStore = isStore(config);
67
+ for (const key of keys) {
68
+ res[key] = configIsStore ? tansu.computed(() => config()[key]) : toReadableStore(config[key]);
69
+ }
70
+ }
71
+ return res;
72
+ };
73
+ const mergeConfigStores = (keys, config1, config2) => {
74
+ const res = {};
75
+ for (const key of keys) {
76
+ const config1Store = config1 == null ? void 0 : config1[key];
77
+ const config2Store = config2 == null ? void 0 : config2[key];
78
+ res[key] = config1Store && config2Store ? tansu.computed(() => config1Store() ?? config2Store()) : config1Store || config2Store;
79
+ }
80
+ return res;
81
+ };
82
+ const writablesWithDefault = (defConfig, propsConfig, options) => {
83
+ const res = {};
84
+ const keys = Object.keys(defConfig);
85
+ const configStores = normalizeConfigStores(keys, propsConfig == null ? void 0 : propsConfig.config);
86
+ const props = propsConfig == null ? void 0 : propsConfig.props;
87
+ for (const key of keys) {
88
+ const propValue = props == null ? void 0 : props[key];
89
+ res[`${key}$`] = writableWithDefault(defConfig[key], configStores[key], options == null ? void 0 : options[key], toWritableStore(propValue));
90
+ }
91
+ return res;
92
+ };
93
+ const writablesForProps = (defConfig, propsConfig, options) => {
94
+ const stores = writablesWithDefault(defConfig, propsConfig, options);
95
+ return [stores, createPatch(stores)];
96
+ };
97
+ const stateStores = (inputStores) => {
98
+ const storesNames = [];
99
+ const storesArray = [];
100
+ const stores = {};
101
+ for (const [key, store] of Object.entries(inputStores)) {
102
+ if (key.endsWith("$")) {
103
+ storesNames.push(key.substring(0, key.length - 1));
104
+ storesArray.push(store);
105
+ stores[key] = tansu.asReadable(store);
106
+ }
107
+ }
108
+ return {
109
+ stores,
110
+ state$: tansu.computed(() => {
111
+ const values = storesArray.map(tansu.get);
112
+ const res = {};
113
+ storesNames.forEach((name, index) => {
114
+ res[name] = values[index];
115
+ });
116
+ return res;
117
+ })
118
+ };
119
+ };
120
+ const bindableDerived = (onChange$, stores, adjustValue = (arg) => arg[0], equal = (currentValue, newValue) => newValue === currentValue) => {
121
+ let currentValue = stores[0]();
122
+ return tansu.asWritable(
123
+ tansu.derived(stores, {
124
+ derive(values) {
125
+ const newValue = adjustValue(values);
126
+ const rectifiedValue = !equal(values[0], newValue);
127
+ if (rectifiedValue) {
128
+ stores[0].set(newValue);
129
+ }
130
+ if (rectifiedValue || !equal(currentValue, newValue)) {
131
+ currentValue = newValue;
132
+ onChange$()(newValue);
133
+ }
134
+ return newValue;
135
+ },
136
+ equal
137
+ }),
138
+ stores[0].set.bind(stores[0])
139
+ );
140
+ };
141
+ const bindableProp = (store$, onChange$, adjustValue = func.identity, equal = tansu.equal) => tansu.asWritable(
142
+ tansu.computed(() => adjustValue(store$()), { equal }),
143
+ (newValue) => {
144
+ const adjustedValue = adjustValue(newValue);
145
+ if (!equal(store$(), adjustedValue)) {
146
+ store$.set(adjustedValue);
147
+ onChange$()(adjustedValue);
148
+ }
149
+ }
150
+ );
151
+ exports.bindableDerived = bindableDerived;
152
+ exports.bindableProp = bindableProp;
153
+ exports.createPatch = createPatch;
154
+ exports.findChangedProperties = findChangedProperties;
155
+ exports.isStore = isStore;
156
+ exports.mergeConfigStores = mergeConfigStores;
157
+ exports.normalizeConfigStores = normalizeConfigStores;
158
+ exports.stateStores = stateStores;
159
+ exports.toReadableStore = toReadableStore;
160
+ exports.toWritableStore = toWritableStore;
161
+ exports.writableWithDefault = writableWithDefault;
162
+ exports.writablesForProps = writablesForProps;
163
+ exports.writablesWithDefault = writablesWithDefault;
package/utils/stores.d.ts CHANGED
@@ -7,12 +7,6 @@ export type ReadableSignals<T extends object> = {
7
7
  [K in keyof T]?: ReadableSignal<T[K] | undefined>;
8
8
  };
9
9
  export type WithoutDollar<S extends `${string}$`> = S extends `${infer U}$` ? U : never;
10
- export type ValueOfStore<S extends ReadableSignal<any>> = S extends ReadableSignal<infer U> ? U : never;
11
- export type ToState<S extends {
12
- [K in keyof S & `${string}$`]: ReadableSignal<any>;
13
- }> = {
14
- [K in keyof S & `${string}$` as WithoutDollar<K>]: ValueOfStore<S[K]>;
15
- };
16
10
  /**
17
11
  *
18
12
  * Utility function designed to create a `patch` function related to the provided stores.
@@ -72,13 +66,13 @@ export declare const isStore: (x: any) => x is ReadableSignal<any>;
72
66
  * @param x - either a store or a simple value
73
67
  * @returns either x if x is already a store, or readable(x) otherwise
74
68
  */
75
- export declare const toReadableStore: <T>(x: T | ReadableSignal<T>) => ReadableSignal<T>;
69
+ export declare const toReadableStore: <T>(x: ReadableSignal<T> | T) => ReadableSignal<T>;
76
70
  /**
77
71
  * If the provided argument is already a store, it is returned as is, otherwise, a writable store is created with the provided argument as its initial value.
78
72
  * @param x - either a writable store or a simple value
79
73
  * @returns either x if x is already a store, or writable(x) otherwise
80
74
  */
81
- export declare const toWritableStore: <T>(x: T | WritableSignal<T, T>) => WritableSignal<T, T>;
75
+ export declare const toWritableStore: <T>(x: WritableSignal<T> | T) => WritableSignal<T, T>;
82
76
  /**
83
77
  * Extract and normalize config stores.
84
78
  *
@@ -86,7 +80,7 @@ export declare const toWritableStore: <T>(x: T | WritableSignal<T, T>) => Writab
86
80
  * @param config - the config stores
87
81
  * @returns the normalized config stores
88
82
  */
89
- export declare const normalizeConfigStores: <T extends object>(keys: (keyof T)[], config?: ReadableSignal<Partial<T>> | ValuesOrReadableSignals<T> | undefined) => ReadableSignals<T>;
83
+ export declare const normalizeConfigStores: <T extends object>(keys: (keyof T)[], config?: ReadableSignal<Partial<T>> | ValuesOrReadableSignals<T>) => ReadableSignals<T>;
90
84
  /**
91
85
  * Merge two stores configs into one
92
86
  *
@@ -95,7 +89,7 @@ export declare const normalizeConfigStores: <T extends object>(keys: (keyof T)[]
95
89
  * @param config2 - the second config
96
90
  * @returns the merged config
97
91
  */
98
- export declare const mergeConfigStores: <T extends object>(keys: (keyof T)[], config1?: ReadableSignals<T> | undefined, config2?: ReadableSignals<T> | undefined) => ReadableSignals<T>;
92
+ export declare const mergeConfigStores: <T extends object>(keys: (keyof T)[], config1?: ReadableSignals<T>, config2?: ReadableSignals<T>) => ReadableSignals<T>;
99
93
  /**
100
94
  * Returns an object containing, for each property of `defConfig`, a corresponding writable with the normalization and default value logic
101
95
  * described in {@link writableWithDefault}. Keys in the returned object are the same as the ones present in `defConfig`,
@@ -123,7 +117,7 @@ export declare const mergeConfigStores: <T extends object>(keys: (keyof T)[], co
123
117
  * const {propA$, propB$} = writablesWithDefault(defConfig, {config}, validation);
124
118
  * ```
125
119
  */
126
- export declare const writablesWithDefault: <T extends object>(defConfig: T, propsConfig?: PropsConfig<T> | undefined, options?: ConfigValidator<T> | undefined) => ToWritableSignal<T>;
120
+ export declare const writablesWithDefault: <T extends object>(defConfig: T, propsConfig?: PropsConfig<T>, options?: ConfigValidator<T>) => ToWritableSignal<T>;
127
121
  /**
128
122
  * Shortcut for calling both {@link writablesWithDefault} and {@link createPatch} in one call.
129
123
  * @param defConfig - object containing, for each property, a default value to use in case `config` does not provide the suitable default
@@ -150,25 +144,34 @@ export declare const writablesWithDefault: <T extends object>(defConfig: T, prop
150
144
  * const [{propA$, propB$}, patch] = writablesForProps(defConfig, config, validation);
151
145
  * ```
152
146
  */
153
- export declare const writablesForProps: <T extends object>(defConfig: T, propsConfig?: PropsConfig<T> | undefined, options?: { [K in keyof T]?: WritableWithDefaultOptions<T[K]> | undefined; } | undefined) => [ToWritableSignal<T>, <U extends Partial<T>>(storesValues?: void | U | undefined) => void];
147
+ export declare const writablesForProps: <T extends object>(defConfig: T, propsConfig?: PropsConfig<T>, options?: { [K in keyof T]?: WritableWithDefaultOptions<T[K]> | undefined; } | undefined) => [ToWritableSignal<T>, ReturnType<typeof createPatch<T>>];
154
148
  /**
155
149
  * Using input stores, this function builds an object containing the stores as readable and a global state.
156
150
  *
157
151
  * @param inputStores - the input stores
158
152
  * @returns the object containing the stores as readable and the global state
159
153
  */
160
- export declare const stateStores: <A extends {
161
- [x: `${string}$`]: ReadableSignal<any>;
162
- }>(inputStores: A) => {
163
- state$: ReadableSignal<ToState<A>>;
164
- stores: { [key in `${string}$` & keyof A]: ReadableSignal<ValueOfStore<A[key]>>; };
154
+ export declare const stateStores: <A extends object>(inputStores: { [K in keyof A as `${K & string}$`]: ReadableSignal<any>; }) => {
155
+ state$: ReadableSignal<A>;
156
+ stores: { [K_1 in keyof A as `${K_1 & string}$`]: ReadableSignal<A[K_1]>; };
165
157
  };
166
158
  /**
167
- * Creates a computed store that binds to multiple stores and triggers a callback when the value changes.
168
- * @param onChange$ - A readable signal callback function to execute when the value changes.
159
+ * Creates a derived store that binds to multiple stores and triggers a callback when the value changes for any reason.
160
+ * @param onChange$ - A readable signal containing a callback function to execute when the value changes.
169
161
  * @param stores - An array of Svelte stores, with the main store at index 0.
170
162
  * @param adjustValue - A function to adjust the value of the main store. By default, the value of the main store is returned.
171
163
  * @param equal - A function to determine if two values are equal. Used to compare the ajusted value with the current one.
172
164
  * @returns The derived store that reflects the combined state of the input stores.
173
165
  */
174
- export declare const bindableDerived: <T, U extends [WritableSignal<T, T>, ...StoreInput<any>[]]>(onChange$: ReadableSignal<(value: T) => void>, stores: U, adjustValue?: (arg: StoresInputValues<U>) => T, equal?: (currentValue: T, newValue: T) => boolean) => ReadableSignal<T>;
166
+ export declare const bindableDerived: <T, U extends [WritableSignal<T, T>, ...StoreInput<any>[]]>(onChange$: ReadableSignal<(value: T) => void>, stores: U, adjustValue?: (arg: StoresInputValues<U>) => T, equal?: (currentValue: T, newValue: T) => boolean) => WritableSignal<T, T>;
167
+ /**
168
+ * Creates a computed store that contains the adjusted value of the given store and that triggers a callback when the value changes from the set or update
169
+ * method of the returned writable store.
170
+ * @param store$ - store to be bound
171
+ * @param onChange$ - A readable signal containing a callback function to execute when the value changes from the set or update method of the returned writable store.
172
+ * @param adjustValue - A function to adjust the value of the store, called in a reactive context each time the value changes or any called dependency changes.
173
+ * By default, the value of store$ is returned.
174
+ * @param equal - A function to determine if two values are equal.
175
+ * @returns A writable store that contains the adjusted value of the given store, with the set or update functions that trigger the onChange$ callback.
176
+ */
177
+ export declare const bindableProp: <T>(store$: WritableSignal<T, T | undefined>, onChange$: ReadableSignal<(newValue: T) => void>, adjustValue?: (value: T) => T, equal?: (a: T, b: T) => boolean) => WritableSignal<T, T>;