@design-factory/core 21.1.0 → 22.0.0-next.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 (130) hide show
  1. package/{accordion-D9ba0XYq.js → accordion-B5RqDwi3.js} +76 -15
  2. package/alert-Db6cG6JE.js +125 -0
  3. package/{collapse-Bn8iHKrd.js → collapse-D8Jo56k9.js} +2 -2
  4. package/{common-DFyZvkII.js → common-CP4amR0Z.js} +2 -2
  5. package/components/accordion/accordion.d.ts +73 -15
  6. package/components/accordion/index.js +1 -1
  7. package/components/alert/alert.d.ts +77 -8
  8. package/components/alert/common.d.ts +9 -9
  9. package/components/alert/index.js +2 -3
  10. package/components/carousel/index.js +2 -2
  11. package/components/collapse/index.js +1 -1
  12. package/components/drawer/drawer.d.ts +6 -0
  13. package/components/drawer/index.js +1 -1
  14. package/components/dropdown/dropdown.d.ts +110 -0
  15. package/components/dropdown/index.d.ts +1 -0
  16. package/components/dropdown/index.js +5 -0
  17. package/components/modal/index.js +1 -1
  18. package/components/pagination/index.js +1 -1
  19. package/components/progressbar/index.js +1 -1
  20. package/components/rating/index.js +1 -1
  21. package/components/slider/index.js +1 -1
  22. package/components/slider/slider.d.ts +23 -4
  23. package/components/toast/index.js +1 -1
  24. package/components/tooltip/index.d.ts +1 -0
  25. package/components/tooltip/index.js +174 -0
  26. package/components/tooltip/tooltip.d.ts +63 -0
  27. package/components/tree/index.js +1 -1
  28. package/{directive-CNNSo5Yn.js → directive-CMT2vEDg.js} +7 -4
  29. package/{drawer-CoBXUPyv.js → drawer-CpGnS2ln.js} +11 -4
  30. package/dropdown-Bjj2ql6d.js +246 -0
  31. package/index.d.ts +3 -1
  32. package/index.js +44 -37
  33. package/isFocusable-C2iRr0zh.js +72 -0
  34. package/{modal-BH9nrwVz.js → modal-CQWh2Sm5.js} +3 -3
  35. package/package.json +1 -1
  36. package/{pagination-BQWusWXN.js → pagination-DIRcpdRE.js} +2 -2
  37. package/{progressbar-S1pNn5rM.js → progressbar-Bth8r3Qu.js} +2 -2
  38. package/{promise-D-RZVPuv.js → promise-CkIc0KKt.js} +3 -3
  39. package/{rating-DWgGgwk3.js → rating-DLsgFSyB.js} +2 -2
  40. package/services/extendWidget.d.ts +1 -1
  41. package/services/focusElement.js +2 -2
  42. package/services/focustrack.js +2 -2
  43. package/services/matchMedia.js +1 -1
  44. package/services/mousetrack.d.ts +34 -0
  45. package/services/mousetrack.js +41 -0
  46. package/services/navManager.js +2 -2
  47. package/services/pointerdownPosition.js +1 -1
  48. package/services/portal.js +1 -1
  49. package/services/positioning.d.ts +101 -0
  50. package/services/positioning.js +104 -0
  51. package/services/resizeObserver.js +1 -1
  52. package/services/siblingsInert.js +1 -1
  53. package/services/transitions/baseTransitions.js +3 -3
  54. package/services/transitions/collapse.js +4 -7
  55. package/services/transitions/cssTransitions.js +2 -2
  56. package/services/transitions/simpleClassTransition.js +1 -1
  57. package/{slider-Br_Qiopx.js → slider-b9cVFNAL.js} +96 -58
  58. package/{toaster-BUBzFeJM.js → toaster-BS9qeRLF.js} +3 -3
  59. package/{tree-vD7ZkV8Z.js → tree-DW6iLxdw.js} +2 -2
  60. package/types.d.ts +8 -1
  61. package/utils/debounceSignal.d.ts +11 -0
  62. package/utils/debounceSignal.js +18 -0
  63. package/utils/directive.js +1 -1
  64. package/utils/edgeState.d.ts +23 -0
  65. package/utils/edgeState.js +43 -0
  66. package/utils/internal/isFocusable.d.ts +40 -0
  67. package/utils/stores.d.ts +1 -1
  68. package/utils/stores.js +4 -1
  69. package/utils/writables.d.ts +27 -13
  70. package/utils/writables.js +12 -11
  71. package/{writables-DYGjj5T3.js → writables-_7BriMb2.js} +37 -12
  72. package/accordion-B0vs8JWM.cjs +0 -314
  73. package/alert-AhaliJ17.cjs +0 -9
  74. package/alert-Cb9FhbFQ.js +0 -10
  75. package/collapse-BnWw4Hnc.cjs +0 -94
  76. package/common-B5jS-Ih_.cjs +0 -73
  77. package/components/accordion/index.cjs +0 -7
  78. package/components/alert/index.cjs +0 -5
  79. package/components/carousel/index.cjs +0 -292
  80. package/components/collapse/index.cjs +0 -5
  81. package/components/drawer/index.cjs +0 -5
  82. package/components/modal/index.cjs +0 -8
  83. package/components/pagination/index.cjs +0 -5
  84. package/components/progressbar/index.cjs +0 -5
  85. package/components/rating/index.cjs +0 -5
  86. package/components/slider/index.cjs +0 -5
  87. package/components/toast/index.cjs +0 -7
  88. package/components/tree/index.cjs +0 -5
  89. package/config.cjs +0 -36
  90. package/directive-DyTodNPd.cjs +0 -523
  91. package/drawer-Ca_ktkEs.cjs +0 -328
  92. package/index.cjs +0 -134
  93. package/isFocusable-Ckwus82R.js +0 -32
  94. package/isFocusable-DfzDLeAN.cjs +0 -31
  95. package/modal-Dxdw2Pkv.cjs +0 -252
  96. package/pagination-BLVa1UsZ.cjs +0 -254
  97. package/progressbar-RopgvVeA.cjs +0 -86
  98. package/promise-CxCD3NYv.cjs +0 -118
  99. package/rating-DZ3OQgtt.cjs +0 -183
  100. package/scrollbars-f651ntzz.cjs +0 -33
  101. package/services/extendWidget.cjs +0 -41
  102. package/services/floatingUI.cjs +0 -111
  103. package/services/floatingUI.d.ts +0 -76
  104. package/services/floatingUI.js +0 -111
  105. package/services/focusElement.cjs +0 -46
  106. package/services/focustrack.cjs +0 -47
  107. package/services/hash.cjs +0 -15
  108. package/services/intersection.cjs +0 -53
  109. package/services/matchMedia.cjs +0 -14
  110. package/services/navManager.cjs +0 -166
  111. package/services/pointerdownPosition.cjs +0 -60
  112. package/services/portal.cjs +0 -42
  113. package/services/resizeObserver.cjs +0 -54
  114. package/services/siblingsInert.cjs +0 -44
  115. package/services/transitions/baseTransitions.cjs +0 -186
  116. package/services/transitions/collapse.cjs +0 -40
  117. package/services/transitions/cssTransitions.cjs +0 -32
  118. package/services/transitions/simpleClassTransition.cjs +0 -37
  119. package/slider-pgDq1V5r.cjs +0 -807
  120. package/textDirection-zqcZ5-eK.cjs +0 -3
  121. package/toaster-Dlube4Ya.cjs +0 -161
  122. package/tree-Chcy4ulJ.cjs +0 -228
  123. package/types.cjs +0 -6
  124. package/utils/directive.cjs +0 -28
  125. package/utils/func.cjs +0 -7
  126. package/utils/id.cjs +0 -5
  127. package/utils/stores.cjs +0 -172
  128. package/utils/widget.cjs +0 -8
  129. package/utils/writables.cjs +0 -16
  130. package/writables-Dt68gADJ.cjs +0 -102
@@ -1,3 +0,0 @@
1
- "use strict";
2
- const getTextDirection = (element) => getComputedStyle(element).direction;
3
- exports.getTextDirection = getTextDirection;
@@ -1,161 +0,0 @@
1
- "use strict";
2
- const tansu = require("@amadeus-it-group/tansu");
3
- const services_extendWidget = require("./services/extendWidget.cjs");
4
- const utils_directive = require("./directive-DyTodNPd.cjs");
5
- const utils_stores = require("./utils/stores.cjs");
6
- const utils_writables = require("./writables-Dt68gADJ.cjs");
7
- const common = require("./common-B5jS-Ih_.cjs");
8
- const utils_widget = require("./utils/widget.cjs");
9
- const toastDefaultConfig = {
10
- autoHide: true,
11
- delay: 5e3
12
- };
13
- const toastConfigValidator = {
14
- autoHide: utils_writables.typeBoolean,
15
- delay: utils_writables.typeNumberInRangeFactory(0, Infinity, { strict: true })
16
- };
17
- function getToastDefaultConfig() {
18
- return { ...common.getCommonAlertDefaultConfig(), ...toastDefaultConfig };
19
- }
20
- const createToast = utils_widget.createWidgetFactory(
21
- "toast",
22
- (config) => {
23
- let _timeout;
24
- const extendedAlert = services_extendWidget.extendWidgetProps(
25
- common.createCommonAlert,
26
- toastDefaultConfig,
27
- toastConfigValidator
28
- )(config);
29
- const time$ = tansu.computed(() => {
30
- clearTimeout(_timeout);
31
- if (extendedAlert.stores.autoHide$()) {
32
- _timeout = setTimeout(() => void extendedAlert.api.close(), extendedAlert.stores.delay$());
33
- }
34
- });
35
- const bodyDirective = utils_directive.createAttributesDirective(() => ({
36
- attributes: {
37
- role: tansu.readable("alert"),
38
- "aria-atomic": tansu.readable("true"),
39
- class: tansu.computed(() => extendedAlert.stores.className$())
40
- },
41
- classNames: {
42
- "au-toast": utils_stores.true$,
43
- toast: utils_stores.true$
44
- }
45
- }));
46
- const closeButtonDirective = utils_directive.createAttributesDirective(() => ({
47
- attributes: {
48
- type: tansu.readable("button"),
49
- "aria-label": tansu.computed(() => extendedAlert.stores.ariaCloseButtonLabel$())
50
- },
51
- events: {
52
- click: () => void extendedAlert.api.close()
53
- }
54
- }));
55
- return {
56
- ...extendedAlert,
57
- directives: {
58
- ...extendedAlert.directives,
59
- autoHideDirective: utils_directive.directiveSubscribe(time$),
60
- bodyDirective,
61
- closeButtonDirective
62
- }
63
- };
64
- }
65
- );
66
- const defaultToasterProps = {
67
- duration: 5e3,
68
- position: "bottomRight",
69
- dismissible: false
70
- };
71
- class Toaster {
72
- constructor(props) {
73
- this.#idCount = 0;
74
- this.#toasts = tansu.writable([]);
75
- this.toasts = tansu.computed(
76
- () => this.#toasts().sort((a, b) => b.id - a.id).slice(0, this.options().limit)
77
- );
78
- this.options = tansu.writable(defaultToasterProps);
79
- this.#timers = /* @__PURE__ */ new Map();
80
- this.addTimer = (id, duration = this.options().duration) => {
81
- if (duration > 0) {
82
- this.#timers.set(id, {
83
- timeout: setTimeout(() => this.removeToast(id), duration),
84
- started: performance.now(),
85
- duration
86
- });
87
- }
88
- };
89
- this.pauseTimer = (id) => {
90
- if (this.#timers.has(id)) {
91
- const timer = this.#timers.get(id);
92
- if (timer && timer.timeout) {
93
- clearTimeout(timer.timeout);
94
- timer.timeout = null;
95
- timer.paused = performance.now();
96
- }
97
- }
98
- };
99
- this.resumeTimer = (id) => {
100
- if (this.#timers.has(id)) {
101
- const timer = this.#timers.get(id);
102
- if (timer) {
103
- const paused = timer.paused ?? timer.started;
104
- const elapsed = paused - timer.started;
105
- const remaining = (timer.duration ?? 0) - elapsed;
106
- this.addTimer(id, remaining);
107
- timer.duration = remaining;
108
- timer.paused = void 0;
109
- }
110
- }
111
- };
112
- this.eventsDirective = utils_directive.createAttributesDirective((id) => ({
113
- events: {
114
- pointerenter: () => this.options().pauseOnHover && this.pauseTimer(id()),
115
- pointerleave: () => this.options().pauseOnHover && this.resumeTimer(id())
116
- }
117
- }));
118
- this.addToast = (props2) => {
119
- const autoHide = props2.autoHide ?? this.options().duration > 0;
120
- this.#toasts.update((toasts) => [...toasts, { id: this.#idCount++, props: props2 }]);
121
- if (autoHide) {
122
- this.addTimer(this.#idCount - 1, props2.delay);
123
- }
124
- return this.#idCount - 1;
125
- };
126
- this.removeToast = (id) => {
127
- this.#timers.delete(id);
128
- this.#toasts.update((toasts) => toasts.filter((toast) => toast.id !== id));
129
- };
130
- this.updateToasts = () => {
131
- if (this.options().duration === 0) {
132
- this.options().dismissible = true;
133
- }
134
- };
135
- this.closeAll = () => {
136
- this.#toasts.set([]);
137
- this.#timers.clear();
138
- };
139
- this.options.set({
140
- ...defaultToasterProps,
141
- ...props
142
- });
143
- this.options.subscribe(() => {
144
- this.updateToasts();
145
- });
146
- }
147
- #idCount;
148
- #toasts;
149
- #timers;
150
- /**
151
- * Get the timers value from the store
152
- * @returns The map of timers.
153
- */
154
- get timers() {
155
- return new Map(this.#timers);
156
- }
157
- }
158
- exports.Toaster = Toaster;
159
- exports.createToast = createToast;
160
- exports.defaultToasterProps = defaultToasterProps;
161
- exports.getToastDefaultConfig = getToastDefaultConfig;
package/tree-Chcy4ulJ.cjs DELETED
@@ -1,228 +0,0 @@
1
- "use strict";
2
- const tansu = require("@amadeus-it-group/tansu");
3
- const services_navManager = require("./services/navManager.cjs");
4
- const utils_directive = require("./directive-DyTodNPd.cjs");
5
- const utils_func = require("./utils/func.cjs");
6
- const utils_stores = require("./utils/stores.cjs");
7
- const utils_writables = require("./writables-Dt68gADJ.cjs");
8
- const utils_widget = require("./utils/widget.cjs");
9
- function getTreeDefaultConfig() {
10
- return {
11
- ...defaultTreeConfig
12
- };
13
- }
14
- const defaultTreeConfig = {
15
- className: "",
16
- nodes: [],
17
- onExpandToggle: utils_func.noop,
18
- navSelector: (node) => node.querySelectorAll("button"),
19
- ariaLabelToggleFn: (label) => `Toggle ${label}`
20
- };
21
- const configValidator = {
22
- className: utils_writables.typeString,
23
- nodes: utils_writables.typeArray,
24
- onExpandToggle: utils_writables.typeFunction,
25
- navSelector: utils_writables.typeFunction,
26
- ariaLabelToggleFn: utils_writables.typeFunction
27
- };
28
- const createTree = utils_widget.createWidgetFactory("tree", (config) => {
29
- const [{ nodes$, onExpandToggle$, navSelector$, ariaLabelToggleFn$, ...stateProps }, patch] = utils_stores.writablesForProps(
30
- defaultTreeConfig,
31
- config,
32
- configValidator
33
- );
34
- const treeMap = /* @__PURE__ */ new Map();
35
- const _expandedMap = {
36
- get(item) {
37
- return item.isExpanded;
38
- }
39
- };
40
- const _toggleChange$ = tansu.writable({});
41
- const expandedMap$ = tansu.computed(() => {
42
- normalizedNodes$();
43
- _toggleChange$();
44
- return _expandedMap;
45
- });
46
- const {
47
- elementsInDomOrder$,
48
- directive: navDirective,
49
- refreshElements,
50
- focusIndex,
51
- focusPrevious,
52
- focusNext,
53
- focusFirst,
54
- focusLast
55
- } = services_navManager.createNavManager();
56
- const navManagerConfig$ = tansu.computed(() => ({
57
- keys: {
58
- ArrowUp: focusPrevious,
59
- ArrowDown: focusNext,
60
- Home: focusFirst,
61
- End: focusLast
62
- },
63
- selector: navSelector$()
64
- }));
65
- const traverseTree = (node, level, parent) => {
66
- const copyNode = {
67
- ...node,
68
- ariaLabel: node.ariaLabel ?? node.label,
69
- level,
70
- children: [],
71
- isExpanded: node.children?.length ? node.isExpanded ?? false : void 0
72
- };
73
- treeMap.set(copyNode, {
74
- parent
75
- });
76
- if (node.children) {
77
- copyNode.children = node.children.map((child) => traverseTree(child, level + 1, copyNode));
78
- }
79
- return copyNode;
80
- };
81
- const normalizedNodes$ = tansu.computed(() => {
82
- treeMap.clear();
83
- return nodes$().map((node) => traverseTree(node, 0, void 0));
84
- });
85
- const _lastFocusedTreeItem$ = tansu.writable(
86
- normalizedNodes$().find((node) => node.isExpanded !== void 0)
87
- );
88
- const getTreeItemInfo = (item) => {
89
- const treeItem = treeMap.get(item);
90
- if (!treeItem) {
91
- console.error(`Node ${item.label} doesn't exist in the map`);
92
- }
93
- return treeItem;
94
- };
95
- const treeItemElementDirective = utils_directive.browserDirective(
96
- (toggleItem, args) => {
97
- let treeItemInfo;
98
- const destroy = () => {
99
- if (treeItemInfo && treeItemInfo.htmlElement === toggleItem) {
100
- treeItemInfo.htmlElement = void 0;
101
- }
102
- treeItemInfo = void 0;
103
- };
104
- const update = (args2) => {
105
- destroy();
106
- treeItemInfo = getTreeItemInfo(args2.item);
107
- if (treeItemInfo) {
108
- if (treeItemInfo.htmlElement) {
109
- console.warn(`The tree item directive should be used once per element`);
110
- }
111
- treeItemInfo.htmlElement = toggleItem;
112
- }
113
- };
114
- update(args);
115
- return {
116
- update,
117
- destroy
118
- };
119
- }
120
- );
121
- const focusElementIfExists = (itemToFocus) => {
122
- if (itemToFocus) {
123
- const mapItemHtml = getTreeItemInfo(itemToFocus)?.htmlElement;
124
- if (mapItemHtml) {
125
- const index = elementsInDomOrder$().indexOf(mapItemHtml);
126
- focusIndex(index, 0);
127
- }
128
- }
129
- };
130
- const itemToggleAttributesDirective = utils_directive.createAttributesDirective(
131
- (treeItemContext$) => ({
132
- events: {
133
- focus: () => {
134
- const { item } = treeItemContext$();
135
- _lastFocusedTreeItem$.set(item);
136
- },
137
- click: () => {
138
- const { item } = treeItemContext$();
139
- toggleExpanded(item);
140
- },
141
- keydown: (event) => {
142
- const { key } = event;
143
- const { item } = treeItemContext$();
144
- const isExpanded = item.isExpanded;
145
- refreshElements();
146
- switch (key) {
147
- case "Enter":
148
- case " ":
149
- toggleExpanded(item);
150
- break;
151
- case "ArrowLeft":
152
- if (isExpanded) {
153
- toggleExpanded(item);
154
- } else {
155
- focusElementIfExists(getTreeItemInfo(item)?.parent);
156
- }
157
- break;
158
- case "ArrowRight":
159
- if (!isExpanded) {
160
- toggleExpanded(item);
161
- } else {
162
- focusElementIfExists(item.children?.[0]);
163
- }
164
- break;
165
- default:
166
- return;
167
- }
168
- event.preventDefault();
169
- event.stopPropagation();
170
- }
171
- },
172
- attributes: {
173
- "aria-label": tansu.computed(() => {
174
- const { item } = treeItemContext$();
175
- return ariaLabelToggleFn$()(item.ariaLabel);
176
- }),
177
- tabindex: tansu.computed(() => {
178
- const { item } = treeItemContext$();
179
- return item === _lastFocusedTreeItem$() ? "0" : "-1";
180
- }),
181
- type: tansu.readable("button")
182
- },
183
- classNames: {
184
- "au-tree-expand-icon": utils_stores.true$,
185
- "au-tree-expand-icon-expanded": tansu.computed(() => {
186
- _toggleChange$();
187
- const { item } = treeItemContext$();
188
- return item.isExpanded ?? false;
189
- })
190
- }
191
- })
192
- );
193
- const toggleExpanded = (node) => {
194
- const treeItemInfo = getTreeItemInfo(node);
195
- if (treeItemInfo === void 0 || node.isExpanded === void 0) {
196
- return;
197
- }
198
- node.isExpanded = !node.isExpanded;
199
- _toggleChange$.set({});
200
- onExpandToggle$()(node);
201
- };
202
- const widget = {
203
- ...utils_stores.stateStores({ normalizedNodes$, expandedMap$, ...stateProps }),
204
- patch,
205
- api: {},
206
- directives: {
207
- navigationDirective: utils_directive.bindDirective(navDirective, navManagerConfig$),
208
- itemToggleDirective: utils_directive.mergeDirectives(treeItemElementDirective, itemToggleAttributesDirective),
209
- itemAttributesDirective: utils_directive.createAttributesDirective(
210
- (treeItemContext$) => ({
211
- attributes: {
212
- role: tansu.readable("treeitem"),
213
- "aria-selected": tansu.readable("false"),
214
- // TODO: adapt aria-selected to the actual selected state
215
- "aria-expanded": tansu.computed(() => {
216
- const { item } = treeItemContext$();
217
- _toggleChange$();
218
- return item.isExpanded?.toString();
219
- })
220
- }
221
- })
222
- )
223
- }
224
- };
225
- return widget;
226
- });
227
- exports.createTree = createTree;
228
- exports.getTreeDefaultConfig = getTreeDefaultConfig;
package/types.cjs DELETED
@@ -1,6 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const FACTORY_WIDGET_NAME = /* @__PURE__ */ Symbol();
4
- const INVALID_VALUE = /* @__PURE__ */ Symbol();
5
- exports.FACTORY_WIDGET_NAME = FACTORY_WIDGET_NAME;
6
- exports.INVALID_VALUE = INVALID_VALUE;
@@ -1,28 +0,0 @@
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-DyTodNPd.cjs");
6
- require("./func.cjs");
7
- exports.attributesData = utils_directive.attributesData;
8
- exports.bindDirective = utils_directive.bindDirective;
9
- exports.bindDirectiveNoArg = utils_directive.bindDirectiveNoArg;
10
- exports.browserDirective = utils_directive.browserDirective;
11
- exports.classDirective = utils_directive.classDirective;
12
- exports.conditionalDirective = utils_directive.conditionalDirective;
13
- exports.createAttributesDirective = utils_directive.createAttributesDirective;
14
- exports.createBrowserStoreArrayDirective = utils_directive.createBrowserStoreArrayDirective;
15
- exports.createBrowserStoreDirective = utils_directive.createBrowserStoreDirective;
16
- exports.createConditionalBrowserStoreArrayDirective = utils_directive.createConditionalBrowserStoreArrayDirective;
17
- exports.createConditionalStoreArrayDirective = utils_directive.createConditionalStoreArrayDirective;
18
- exports.createStoreArrayDirective = utils_directive.createStoreArrayDirective;
19
- exports.createStoreDirective = utils_directive.createStoreDirective;
20
- exports.directiveAttributes = utils_directive.directiveAttributes;
21
- exports.directiveSubscribe = utils_directive.directiveSubscribe;
22
- exports.directiveUpdate = utils_directive.directiveUpdate;
23
- exports.isBrowserHTMLElement = utils_directive.isBrowserHTMLElement;
24
- exports.mapDirectiveArg = utils_directive.mapDirectiveArg;
25
- exports.mergeDirectives = utils_directive.mergeDirectives;
26
- exports.multiDirective = utils_directive.multiDirective;
27
- exports.registrationArray = utils_directive.registrationArray;
28
- exports.ssrAttributes = utils_directive.ssrAttributes;
package/utils/func.cjs DELETED
@@ -1,7 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const noop = () => {
4
- };
5
- const identity = (x) => x;
6
- exports.identity = identity;
7
- exports.noop = noop;
package/utils/id.cjs DELETED
@@ -1,5 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- let idCount = 0;
4
- const generateId = () => `dfId-${idCount++}`;
5
- exports.generateId = generateId;
package/utils/stores.cjs DELETED
@@ -1,172 +0,0 @@
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 utils_func = require("./func.cjs");
6
- const utils_id = require("./id.cjs");
7
- function createPatch(stores) {
8
- return function(storesValues) {
9
- tansu.batch(() => {
10
- for (const [name, value] of Object.entries(storesValues)) {
11
- stores[`${name}$`]?.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 = utils_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?.[key];
77
- const config2Store = 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?.config);
86
- const props = propsConfig?.props;
87
- for (const key of keys) {
88
- const propValue = props?.[key];
89
- res[`${key}$`] = writableWithDefault(defConfig[key], configStores[key], 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 = utils_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
- function idWithDefault(id$) {
152
- const autoId$ = tansu.computed(() => utils_id.generateId());
153
- return tansu.computed(() => id$() || autoId$());
154
- }
155
- const true$ = tansu.readable(true);
156
- const false$ = tansu.readable(false);
157
- exports.bindableDerived = bindableDerived;
158
- exports.bindableProp = bindableProp;
159
- exports.createPatch = createPatch;
160
- exports.false$ = false$;
161
- exports.findChangedProperties = findChangedProperties;
162
- exports.idWithDefault = idWithDefault;
163
- exports.isStore = isStore;
164
- exports.mergeConfigStores = mergeConfigStores;
165
- exports.normalizeConfigStores = normalizeConfigStores;
166
- exports.stateStores = stateStores;
167
- exports.toReadableStore = toReadableStore;
168
- exports.toWritableStore = toWritableStore;
169
- exports.true$ = true$;
170
- exports.writableWithDefault = writableWithDefault;
171
- exports.writablesForProps = writablesForProps;
172
- exports.writablesWithDefault = writablesWithDefault;
package/utils/widget.cjs DELETED
@@ -1,8 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const types = require("../types.cjs");
4
- function createWidgetFactory(widgetName, factory) {
5
- factory[types.FACTORY_WIDGET_NAME] = widgetName;
6
- return factory;
7
- }
8
- exports.createWidgetFactory = createWidgetFactory;
@@ -1,16 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const utils_writables = require("../writables-Dt68gADJ.cjs");
4
- require("../types.cjs");
5
- exports.createTypeEnum = utils_writables.createTypeEnum;
6
- exports.testToNormalizeValue = utils_writables.testToNormalizeValue;
7
- exports.typeArray = utils_writables.typeArray;
8
- exports.typeBoolean = utils_writables.typeBoolean;
9
- exports.typeBooleanOrNull = utils_writables.typeBooleanOrNull;
10
- exports.typeFunction = utils_writables.typeFunction;
11
- exports.typeHTMLElementOrNull = utils_writables.typeHTMLElementOrNull;
12
- exports.typeNumber = utils_writables.typeNumber;
13
- exports.typeNumberInRangeFactory = utils_writables.typeNumberInRangeFactory;
14
- exports.typeNumberOrNull = utils_writables.typeNumberOrNull;
15
- exports.typeString = utils_writables.typeString;
16
- exports.typeStringOrNull = utils_writables.typeStringOrNull;