@agnos-ui/core 0.0.1-alpha.0 → 0.0.1-alpha.10

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 (126) hide show
  1. package/README.md +4 -4
  2. package/{dist/lib → components/accordion}/accordion.d.ts +29 -25
  3. package/{dist/lib → components/accordion}/accordion.js +81 -77
  4. package/components/accordion/index.d.ts +1 -0
  5. package/components/accordion/index.js +1 -0
  6. package/components/alert/alert.d.ts +31 -0
  7. package/components/alert/alert.js +22 -0
  8. package/{dist/lib/alert.d.ts → components/alert/common.d.ts} +17 -20
  9. package/{dist/lib/alert.js → components/alert/common.js} +22 -19
  10. package/components/alert/index.d.ts +2 -0
  11. package/components/alert/index.js +2 -0
  12. package/components/commonProps.d.ts +6 -0
  13. package/components/commonProps.js +1 -0
  14. package/components/modal/index.d.ts +1 -0
  15. package/components/modal/index.js +1 -0
  16. package/{dist/lib → components}/modal/modal.d.ts +30 -29
  17. package/{dist/lib → components}/modal/modal.js +59 -29
  18. package/components/pagination/index.d.ts +2 -0
  19. package/components/pagination/index.js +2 -0
  20. package/{dist/lib → components/pagination}/pagination.d.ts +5 -14
  21. package/{dist/lib → components/pagination}/pagination.js +6 -5
  22. package/components/progressbar/index.d.ts +1 -0
  23. package/components/progressbar/index.js +1 -0
  24. package/components/progressbar/progressbar.d.ts +86 -0
  25. package/components/progressbar/progressbar.js +78 -0
  26. package/components/rating/index.d.ts +1 -0
  27. package/components/rating/index.js +1 -0
  28. package/{dist/lib → components/rating}/rating.d.ts +6 -13
  29. package/{dist/lib → components/rating}/rating.js +6 -9
  30. package/components/select/index.d.ts +1 -0
  31. package/components/select/index.js +1 -0
  32. package/components/select/select.d.ts +337 -0
  33. package/components/select/select.js +266 -0
  34. package/components/slider/index.d.ts +1 -0
  35. package/components/slider/index.js +1 -0
  36. package/components/slider/slider.d.ts +245 -0
  37. package/components/slider/slider.js +413 -0
  38. package/{dist/lib/config.d.ts → config.d.ts} +17 -7
  39. package/{dist/lib/config.js → config.js} +3 -3
  40. package/index.d.ts +25 -0
  41. package/index.js +31 -0
  42. package/package.json +42 -28
  43. package/services/extendWidget.d.ts +23 -0
  44. package/services/extendWidget.js +35 -0
  45. package/services/floatingUI.d.ts +56 -0
  46. package/services/floatingUI.js +105 -0
  47. package/{dist/lib/services → services}/focustrack.js +5 -5
  48. package/services/intersection.d.ts +34 -0
  49. package/services/intersection.js +55 -0
  50. package/services/navManager.d.ts +93 -0
  51. package/services/navManager.js +172 -0
  52. package/{dist/lib/services → services}/portal.d.ts +7 -0
  53. package/services/portal.js +44 -0
  54. package/{dist/lib/services → services}/siblingsInert.d.ts +2 -1
  55. package/{dist/lib/services → services}/siblingsInert.js +2 -2
  56. package/{dist/lib → services}/transitions/baseTransitions.d.ts +15 -2
  57. package/{dist/lib → services}/transitions/baseTransitions.js +21 -10
  58. package/services/transitions/bootstrap/collapse.d.ts +2 -0
  59. package/services/transitions/bootstrap/fade.d.ts +1 -0
  60. package/services/transitions/bootstrap.d.ts +2 -0
  61. package/services/transitions/bootstrap.js +2 -0
  62. package/services/transitions/collapse.d.ts +43 -0
  63. package/{dist/lib → services}/transitions/collapse.js +15 -2
  64. package/{dist/lib → services}/transitions/cssTransitions.d.ts +6 -0
  65. package/{dist/lib → services}/transitions/cssTransitions.js +8 -4
  66. package/{dist/lib → services}/transitions/simpleClassTransition.d.ts +12 -1
  67. package/services/transitions/simpleClassTransition.js +42 -0
  68. package/{dist/lib/types.d.ts → types.d.ts} +43 -4
  69. package/types.js +14 -0
  70. package/{dist/lib/services/directiveUtils.js → utils/directive.js} +1 -1
  71. package/utils/internal/checks.d.ts +49 -0
  72. package/utils/internal/checks.js +60 -0
  73. package/utils/internal/dom.d.ts +25 -0
  74. package/utils/internal/dom.js +61 -0
  75. package/utils/internal/func.d.ts +11 -0
  76. package/utils/internal/func.js +11 -0
  77. package/utils/internal/isFocusable.d.ts +9 -0
  78. package/utils/internal/isFocusable.js +35 -0
  79. package/utils/internal/math.d.ts +5 -0
  80. package/utils/internal/math.js +13 -0
  81. package/utils/internal/promise.d.ts +87 -0
  82. package/utils/internal/promise.js +169 -0
  83. package/utils/internal/scrollbars.d.ts +8 -0
  84. package/{dist/lib/modal → utils/internal}/scrollbars.js +7 -1
  85. package/utils/internal/sort.d.ts +16 -0
  86. package/utils/internal/sort.js +28 -0
  87. package/utils/internal/textDirection.d.ts +7 -0
  88. package/utils/internal/textDirection.js +7 -0
  89. package/utils/internal/traversal.d.ts +54 -0
  90. package/utils/internal/traversal.js +105 -0
  91. package/{dist/lib/services → utils}/stores.d.ts +67 -33
  92. package/{dist/lib/services → utils}/stores.js +121 -59
  93. package/utils/writables.d.ts +32 -0
  94. package/utils/writables.js +72 -0
  95. package/dist/lib/index.d.ts +0 -11
  96. package/dist/lib/index.js +0 -11
  97. package/dist/lib/modal/scrollbars.d.ts +0 -2
  98. package/dist/lib/select.d.ts +0 -199
  99. package/dist/lib/select.js +0 -240
  100. package/dist/lib/services/checks.d.ts +0 -32
  101. package/dist/lib/services/checks.js +0 -43
  102. package/dist/lib/services/index.d.ts +0 -6
  103. package/dist/lib/services/index.js +0 -6
  104. package/dist/lib/services/portal.js +0 -33
  105. package/dist/lib/services/writables.d.ts +0 -7
  106. package/dist/lib/services/writables.js +0 -16
  107. package/dist/lib/transitions/bootstrap/collapse.d.ts +0 -2
  108. package/dist/lib/transitions/bootstrap/fade.d.ts +0 -1
  109. package/dist/lib/transitions/bootstrap/index.d.ts +0 -2
  110. package/dist/lib/transitions/bootstrap/index.js +0 -2
  111. package/dist/lib/transitions/collapse.d.ts +0 -29
  112. package/dist/lib/transitions/index.d.ts +0 -5
  113. package/dist/lib/transitions/index.js +0 -5
  114. package/dist/lib/transitions/simpleClassTransition.js +0 -28
  115. package/dist/lib/transitions/utils.d.ts +0 -20
  116. package/dist/lib/transitions/utils.js +0 -83
  117. package/dist/lib/tsdoc-metadata.json +0 -11
  118. package/dist/lib/types.js +0 -7
  119. package/dist/lib/utils.d.ts +0 -2
  120. package/dist/lib/utils.js +0 -2
  121. /package/{dist/lib/pagination.utils.d.ts → components/pagination/bootstrap.d.ts} +0 -0
  122. /package/{dist/lib/pagination.utils.js → components/pagination/bootstrap.js} +0 -0
  123. /package/{dist/lib/services → services}/focustrack.d.ts +0 -0
  124. /package/{dist/lib → services}/transitions/bootstrap/collapse.js +0 -0
  125. /package/{dist/lib → services}/transitions/bootstrap/fade.js +0 -0
  126. /package/{dist/lib/services/directiveUtils.d.ts → utils/directive.d.ts} +0 -0
package/README.md CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  [![npm](https://img.shields.io/npm/v/@agnos-ui/core)](https://www.npmjs.com/package/@agnos-ui/core)
4
4
 
5
- [AgnosUI](https://amadeusitgroup.github.io/AgnosUI/latest/) is a framework-agnostic widget library with adapters for multiple frameworks:
5
+ [AgnosUI](https://amadeusitgroup.github.io/AgnosUI/latest/) is a framework-agnostic widget library with adapters for multiple frameworks, either [Bootstrap](https://getbootstrap.com/)-based or headless:
6
6
 
7
- - [Angular](https://www.npmjs.com/package/@agnos-ui/angular)
8
- - [React](https://www.npmjs.com/package/@agnos-ui/react)
9
- - [Svelte](https://www.npmjs.com/package/@agnos-ui/svelte)
7
+ - [Angular](https://www.npmjs.com/package/@agnos-ui/angular), [Angular headless](https://www.npmjs.com/package/@agnos-ui/angular-headless)
8
+ - [React](https://www.npmjs.com/package/@agnos-ui/react), [React headless](https://www.npmjs.com/package/@agnos-ui/react-headless)
9
+ - [Svelte](https://www.npmjs.com/package/@agnos-ui/svelte), [Svelte headless](https://www.npmjs.com/package/@agnos-ui/svelte-headless)
10
10
 
11
11
  This `@agnos-ui/core` package contains the framework-agnostic common code used by the above framework adapters.
12
12
 
@@ -1,13 +1,7 @@
1
- import type { PropsConfig } from './services';
2
- import type { TransitionFn } from './transitions';
3
- import type { Directive, SlotContent, Widget, WidgetSlotContext } from './types';
4
- export interface AccordionCommonPropsAndState {
5
- /**
6
- * Classes to add on the accordion DOM element.
7
- */
8
- accordionClass: string;
9
- }
10
- export interface AccordionProps extends AccordionCommonPropsAndState {
1
+ import type { TransitionFn } from '../../services/transitions/baseTransitions';
2
+ import type { Directive, PropsConfig, SlotContent, Widget, WidgetSlotContext } from '../../types';
3
+ import type { WidgetsCommonPropsAndState } from '../commonProps';
4
+ export interface AccordionProps extends WidgetsCommonPropsAndState {
11
5
  /**
12
6
  * If `true`, only one item at the time can stay open.
13
7
  */
@@ -44,11 +38,11 @@ export interface AccordionProps extends AccordionCommonPropsAndState {
44
38
  */
45
39
  itemDisabled: boolean;
46
40
  /**
47
- * If `true`, the accordion-item will be collapsed. Otherwise, it will be expanded.
41
+ * If `true`, the accordion-item will be visible (expanded). Otherwise, it will be hidden (collapsed).
48
42
  *
49
43
  * It is a prop of the accordion-item.
50
44
  */
51
- itemCollapsed: boolean;
45
+ itemVisible: boolean;
52
46
  /**
53
47
  * If `true`, accordion-item will be animated.
54
48
  *
@@ -74,13 +68,13 @@ export interface AccordionProps extends AccordionCommonPropsAndState {
74
68
  */
75
69
  onItemHidden: () => void;
76
70
  /**
77
- * An event fired when the `collapsed` value changes.
71
+ * An event fired when the `visible` value changes.
78
72
  *
79
- * Event payload is the new value of collapsed.
73
+ * Event payload is the new value of visible.
80
74
  *
81
75
  * It is a prop of the accordion-item.
82
76
  */
83
- onItemCollapsedChange: (collapsed: boolean) => void;
77
+ onItemVisibleChange: (visible: boolean) => void;
84
78
  /**
85
79
  * Structure of the accordion-item. The default item structure is: accordion-item
86
80
  * contains accordion header and accordion collapse; the accordion header contains the accordion button
@@ -131,8 +125,14 @@ export interface AccordionProps extends AccordionCommonPropsAndState {
131
125
  * It is a prop of the accordion-item.
132
126
  */
133
127
  itemBodyClass: string;
128
+ /**
129
+ * The html tag to use for the accordion-item-header.
130
+ *
131
+ * It is a prop of the accordion-item.
132
+ */
133
+ itemHeadingTag: string;
134
134
  }
135
- export interface AccordionState extends AccordionCommonPropsAndState {
135
+ export interface AccordionState extends WidgetsCommonPropsAndState {
136
136
  /**
137
137
  * Array containing all the accordion-items contained in the accordion.
138
138
  */
@@ -140,7 +140,7 @@ export interface AccordionState extends AccordionCommonPropsAndState {
140
140
  }
141
141
  export interface AccordionApi {
142
142
  /**
143
- * Given the itemId, it will return if such item is expanded or not.
143
+ * Given the itemId, it will return if such item is visible (expanded) or not.
144
144
  *
145
145
  * If the itemId is not a valid id it will return `false`.
146
146
  */
@@ -174,7 +174,7 @@ export interface AccordionApi {
174
174
  */
175
175
  collapseAll(): void;
176
176
  /**
177
- * Creates a new in accordionItem.
177
+ * Creates a new accordionItem.
178
178
  */
179
179
  registerItem(itemConfig?: PropsConfig<AccordionItemProps>): AccordionItemWidget;
180
180
  }
@@ -222,9 +222,9 @@ export interface AccordionItemDirectives {
222
222
  }
223
223
  export interface AccordionItemCommonPropsAndState {
224
224
  /**
225
- * If `true`, the accordion-item will be collapsed. Otherwise, it will be expanded.
225
+ * If `true`, the accordion-item will be visible (expanded). Otherwise, it will be hidden (collapsed).
226
226
  */
227
- itemCollapsed: boolean;
227
+ itemVisible: boolean;
228
228
  /**
229
229
  * If `true`, the accordion-item will be disabled.
230
230
  * It will not react to user's clicks, but still will be possible to toggle programmatically.
@@ -268,6 +268,10 @@ export interface AccordionItemCommonPropsAndState {
268
268
  * Classes to add on the accordion-item body DOM element.
269
269
  */
270
270
  itemBodyClass: string;
271
+ /**
272
+ * The html tag to use for the accordion-item-header.
273
+ */
274
+ itemHeadingTag: string;
271
275
  }
272
276
  export interface AccordionItemProps extends AccordionItemCommonPropsAndState {
273
277
  /**
@@ -291,16 +295,16 @@ export interface AccordionItemProps extends AccordionItemCommonPropsAndState {
291
295
  */
292
296
  onItemHidden: () => void;
293
297
  /**
294
- * An event fired when the `collapsed` value changes.
298
+ * An event fired when the `visible` value changes.
295
299
  *
296
- * Event payload is the new value of collapsed.
300
+ * Event payload is the new value of visible.
297
301
  */
298
- onItemCollapsedChange: (collapsed: boolean) => void;
302
+ onItemVisibleChange: (visible: boolean) => void;
299
303
  }
300
304
  export interface AccordionItemState extends AccordionItemCommonPropsAndState {
301
305
  /**
302
- * If `true` the collapse inside the accordion-item should be in DOM. Its value depends on the
303
- * value of the `itemCollapse` and `itemDestroyOnHide`.
306
+ * If `true` the content of the accordion-item collapse should be in DOM. Its value depends on the
307
+ * value of the `itemVisible` and `itemDestroyOnHide`.
304
308
  */
305
309
  shouldBeInDOM: boolean;
306
310
  }
@@ -1,28 +1,28 @@
1
- import { bindDirectiveNoArg, bindableDerived, directiveSubscribe, registrationArray, stateStores, typeBoolean, typeFunction, typeString, writablesForProps, } from './services';
2
- import { createTransition } from './transitions';
3
- import { collapseVerticalTransition } from './transitions/bootstrap';
4
- import { computed, readable, writable } from '@amadeus-it-group/tansu';
5
- import { noop } from './utils';
1
+ import { stateStores, writablesForProps, normalizeConfigStores, mergeConfigStores } from '../../utils/stores';
2
+ import { createTransition } from '../../services/transitions/baseTransitions';
3
+ import { collapseVerticalTransition } from '../../services/transitions/bootstrap/collapse';
4
+ import { computed, writable } from '@amadeus-it-group/tansu';
5
+ import { noop } from '../../utils/internal/func';
6
+ import { typeBoolean, typeFunction, typeString } from '../../utils/writables';
7
+ import { bindDirectiveNoArg, directiveSubscribe, registrationArray } from '../../utils/directive';
6
8
  let itemId = 0;
7
9
  function getItemId() {
8
10
  return `accordion-item-${itemId++}`;
9
11
  }
10
12
  function adjustItemsCloseOthers(items, openItems, oldOpen) {
13
+ let keepOpen;
11
14
  if (openItems.length == 2) {
12
15
  oldOpen = oldOpen ?? openItems[0];
13
- const keepOpen = openItems.find((id) => id !== oldOpen);
14
- items.forEach((item) => {
15
- if (item.state$().itemId !== keepOpen && !item.state$().itemCollapsed) {
16
- item.patch({ itemCollapsed: true });
17
- }
18
- });
16
+ keepOpen = openItems.find((id) => id !== oldOpen);
19
17
  }
20
18
  else if (openItems.length > 2) {
21
19
  //this case can happen when you have multiple items open and you toggle the close others
22
- const keepOpen = openItems[0];
20
+ keepOpen = openItems[0];
21
+ }
22
+ if (keepOpen) {
23
23
  items.forEach((item) => {
24
- if (item.state$().itemId !== keepOpen && !item.state$().itemCollapsed) {
25
- item.patch({ itemCollapsed: true });
24
+ if (item.state$().itemId !== keepOpen && item.state$().itemVisible) {
25
+ item.patch({ itemVisible: false });
26
26
  }
27
27
  });
28
28
  }
@@ -35,16 +35,17 @@ const defaultAccordionConfig = {
35
35
  closeOthers: false,
36
36
  onShown: noop,
37
37
  onHidden: noop,
38
- accordionClass: '',
38
+ className: '',
39
39
  itemId: '',
40
- itemDestroyOnHide: false,
40
+ itemDestroyOnHide: true,
41
41
  itemDisabled: false,
42
- itemCollapsed: true,
42
+ itemVisible: false,
43
43
  itemAnimation: true,
44
44
  itemTransition: collapseVerticalTransition,
45
+ itemHeadingTag: '',
45
46
  onItemShown: noop,
46
47
  onItemHidden: noop,
47
- onItemCollapsedChange: noop,
48
+ onItemVisibleChange: noop,
48
49
  slotItemStructure: undefined,
49
50
  slotItemBody: undefined,
50
51
  slotItemHeader: undefined,
@@ -58,12 +59,12 @@ const defaultItemConfig = {
58
59
  itemId: defaultAccordionConfig.itemId,
59
60
  itemDestroyOnHide: defaultAccordionConfig.itemDestroyOnHide,
60
61
  itemDisabled: defaultAccordionConfig.itemDisabled,
61
- itemCollapsed: defaultAccordionConfig.itemCollapsed,
62
+ itemVisible: defaultAccordionConfig.itemVisible,
62
63
  itemAnimation: defaultAccordionConfig.itemAnimation,
63
64
  itemTransition: defaultAccordionConfig.itemTransition,
64
65
  onItemShown: defaultAccordionConfig.onItemShown,
65
66
  onItemHidden: defaultAccordionConfig.onItemHidden,
66
- onItemCollapsedChange: defaultAccordionConfig.onItemCollapsedChange,
67
+ onItemVisibleChange: defaultAccordionConfig.onItemVisibleChange,
67
68
  slotItemStructure: defaultAccordionConfig.slotItemStructure,
68
69
  slotItemBody: defaultAccordionConfig.slotItemBody,
69
70
  slotItemHeader: defaultAccordionConfig.slotItemHeader,
@@ -72,7 +73,9 @@ const defaultItemConfig = {
72
73
  itemButtonClass: defaultAccordionConfig.itemButtonClass,
73
74
  itemCollapseClass: defaultAccordionConfig.itemCollapseClass,
74
75
  itemBodyClass: defaultAccordionConfig.itemBodyClass,
76
+ itemHeadingTag: defaultAccordionConfig.itemHeadingTag,
75
77
  };
78
+ const accordionItemProps = Object.keys(defaultItemConfig);
76
79
  /**
77
80
  * Retrieve a shallow copy of the default accordion config
78
81
  * @returns the default accordion config
@@ -87,63 +90,63 @@ const configAccordionValidator = {
87
90
  itemId: typeString,
88
91
  itemDestroyOnHide: typeBoolean,
89
92
  itemDisabled: typeBoolean,
90
- itemCollapsed: typeBoolean,
93
+ itemVisible: typeBoolean,
91
94
  itemAnimation: typeBoolean,
92
95
  itemTransition: typeFunction,
93
96
  onItemShown: typeFunction,
94
97
  onItemHidden: typeFunction,
95
- onItemCollapsedChange: typeFunction,
98
+ onItemVisibleChange: typeFunction,
96
99
  itemClass: typeString,
97
100
  itemHeaderClass: typeString,
98
101
  itemButtonClass: typeString,
99
102
  itemCollapseClass: typeString,
100
103
  itemBodyClass: typeString,
104
+ itemHeadingTag: typeString,
101
105
  };
102
106
  const configItemValidator = {
103
107
  itemId: typeString,
104
108
  itemDestroyOnHide: typeBoolean,
105
109
  itemDisabled: typeBoolean,
106
- itemCollapsed: typeBoolean,
110
+ itemVisible: typeBoolean,
107
111
  itemAnimation: typeBoolean,
108
112
  itemTransition: typeFunction,
109
113
  onItemShown: typeFunction,
110
114
  onItemHidden: typeFunction,
111
- onItemCollapsedChange: typeFunction,
115
+ onItemVisibleChange: typeFunction,
112
116
  itemClass: typeString,
113
117
  itemHeaderClass: typeString,
114
118
  itemButtonClass: typeString,
115
119
  itemCollapseClass: typeString,
116
120
  itemBodyClass: typeString,
121
+ itemHeadingTag: typeString,
117
122
  };
118
123
  function createAccordionItem(accordionOnShown, accordionOnHidden, config) {
119
- const [{ itemAnimation$, itemTransition$, itemDestroyOnHide$, onItemShown$, onItemHidden$, onItemCollapsedChange$, itemCollapsed$, itemId$: _dirtyItemId$, itemDisabled$, ...stateProps }, patch,] = writablesForProps(defaultItemConfig, config, configItemValidator);
124
+ const [{ itemAnimation$, itemTransition$, itemDestroyOnHide$, onItemShown$, onItemHidden$, onItemVisibleChange$, itemVisible$, itemId$: _dirtyItemId$, itemDisabled$, ...stateProps }, patch,] = writablesForProps(defaultItemConfig, config, configItemValidator);
120
125
  const initDone$ = writable(false);
121
- const itemId$ = bindableDerived(readable(noop), [_dirtyItemId$], ([dirtyItemId]) => (dirtyItemId ? dirtyItemId : getItemId()));
122
- const shouldBeInDOM$ = computed(() => {
123
- return itemDestroyOnHide$() === false || !itemTransition.state$().hidden;
124
- });
126
+ const _autoItemId$ = computed(() => getItemId());
127
+ const itemId$ = computed(() => _dirtyItemId$() || _autoItemId$());
128
+ const shouldBeInDOM$ = computed(() => itemDestroyOnHide$() === false || !itemTransition.state$().hidden);
125
129
  const itemTransition = createTransition({
126
- transition: itemTransition$,
127
- visible: computed(() => {
128
- const collapsed = itemCollapsed$();
129
- onItemCollapsedChange$()(collapsed);
130
- return !collapsed;
131
- }),
132
- animation: itemAnimation$,
133
- animationOnInit: false,
134
- initDone: initDone$,
135
- onHidden: () => {
136
- accordionOnHidden()(itemId$());
137
- onItemHidden$()();
138
- },
139
- onShown: () => {
140
- accordionOnShown()(itemId$());
141
- onItemShown$()();
130
+ props: {
131
+ transition: itemTransition$,
132
+ visible: itemVisible$,
133
+ onVisibleChange: onItemVisibleChange$,
134
+ animation: itemAnimation$,
135
+ animationOnInit: false,
136
+ initDone: initDone$,
137
+ onHidden: () => {
138
+ accordionOnHidden()(itemId$());
139
+ onItemHidden$()();
140
+ },
141
+ onShown: () => {
142
+ accordionOnShown()(itemId$());
143
+ onItemShown$()();
144
+ },
142
145
  },
143
146
  });
144
147
  return {
145
148
  ...stateStores({
146
- itemCollapsed$,
149
+ itemVisible$,
147
150
  itemId$,
148
151
  shouldBeInDOM$,
149
152
  itemDisabled$,
@@ -153,7 +156,7 @@ function createAccordionItem(accordionOnShown, accordionOnHidden, config) {
153
156
  actions: {
154
157
  click: () => {
155
158
  if (!itemDisabled$()) {
156
- itemCollapsed$.update((c) => !c);
159
+ itemVisible$.update((c) => !c);
157
160
  }
158
161
  },
159
162
  },
@@ -162,13 +165,13 @@ function createAccordionItem(accordionOnShown, accordionOnHidden, config) {
162
165
  initDone$.set(true);
163
166
  },
164
167
  collapse: () => {
165
- itemCollapsed$.set(true);
168
+ itemVisible$.set(false);
166
169
  },
167
170
  expand: () => {
168
- itemCollapsed$.set(false);
171
+ itemVisible$.set(true);
169
172
  },
170
173
  toggle: () => {
171
- itemCollapsed$.update((c) => !c);
174
+ itemVisible$.update((c) => !c);
172
175
  },
173
176
  },
174
177
  directives: { collapseDirective: bindDirectiveNoArg(itemTransition.directives.directive), accordionItemDirective: noop },
@@ -180,12 +183,32 @@ function createAccordionItem(accordionOnShown, accordionOnHidden, config) {
180
183
  * @returns a new accordion widget instance
181
184
  */
182
185
  export function createAccordion(config) {
183
- const [{ closeOthers$, onShown$, onHidden$, itemId$, itemAnimation$, itemClass$, itemDisabled$, itemCollapsed$, itemTransition$, itemDestroyOnHide$, itemBodyClass$, itemButtonClass$, itemCollapseClass$, itemHeaderClass$, onItemCollapsedChange$, onItemHidden$, onItemShown$, slotItemStructure$, slotItemBody$, slotItemHeader$, ...stateProps }, patch,] = writablesForProps(defaultAccordionConfig, config, configAccordionValidator);
186
+ const [{ closeOthers$, onShown$, onHidden$, itemId$, itemAnimation$, itemClass$, itemDisabled$, itemVisible$, itemTransition$, itemDestroyOnHide$, itemBodyClass$, itemButtonClass$, itemCollapseClass$, itemHeaderClass$, itemHeadingTag$, onItemVisibleChange$, onItemHidden$, onItemShown$, slotItemStructure$, slotItemBody$, slotItemHeader$, ...stateProps }, patch,] = writablesForProps(defaultAccordionConfig, config, configAccordionValidator);
187
+ const accordionItemConfig = {
188
+ itemId: itemId$,
189
+ itemClass: itemClass$,
190
+ itemAnimation: itemAnimation$,
191
+ itemDisabled: itemDisabled$,
192
+ itemVisible: itemVisible$,
193
+ itemTransition: itemTransition$,
194
+ itemDestroyOnHide: itemDestroyOnHide$,
195
+ itemBodyClass: itemBodyClass$,
196
+ itemButtonClass: itemButtonClass$,
197
+ itemCollapseClass: itemCollapseClass$,
198
+ itemHeaderClass: itemHeaderClass$,
199
+ itemHeadingTag: itemHeadingTag$,
200
+ onItemVisibleChange: onItemVisibleChange$,
201
+ onItemHidden: onItemHidden$,
202
+ onItemShown: onItemShown$,
203
+ slotItemStructure: slotItemStructure$,
204
+ slotItemBody: slotItemBody$,
205
+ slotItemHeader: slotItemHeader$,
206
+ };
184
207
  const itemsWidget$ = registrationArray();
185
208
  const openItems$ = computed(() => {
186
209
  const openItems = [];
187
210
  itemsWidget$().forEach((item) => {
188
- if (!item.state$().itemCollapsed) {
211
+ if (item.state$().itemVisible) {
189
212
  openItems.push(item.state$().itemId);
190
213
  }
191
214
  });
@@ -197,9 +220,6 @@ export function createAccordion(config) {
197
220
  adjustItemsCloseOthers(itemsWidget$(), openItems$(), oldOpenItem$());
198
221
  oldOpenItem$.set(openItems$()[0]);
199
222
  }
200
- else {
201
- itemsWidget$();
202
- }
203
223
  });
204
224
  const action$ = computed(() => {
205
225
  checkCloseOthersAction$();
@@ -212,7 +232,7 @@ export function createAccordion(config) {
212
232
  isExpanded: (id) => {
213
233
  const item = getItem(itemsWidget$(), id);
214
234
  if (item) {
215
- return !item.state$().itemCollapsed;
235
+ return item.state$().itemVisible;
216
236
  }
217
237
  else {
218
238
  return false;
@@ -233,27 +253,11 @@ export function createAccordion(config) {
233
253
  collapseAll: () => {
234
254
  itemsWidget$().forEach((i) => i.api.collapse());
235
255
  },
236
- registerItem: (itemConfig) => {
237
- const item = createAccordionItem(onShown$, onHidden$, computed(() => ({
238
- itemId: itemId$(),
239
- itemClass: itemClass$(),
240
- itemAnimation: itemAnimation$(),
241
- itemDisabled: itemDisabled$(),
242
- itemCollapsed: itemCollapsed$(),
243
- itemTransition: itemTransition$(),
244
- itemDestroyOnHide: itemDestroyOnHide$(),
245
- itemBodyClass: itemBodyClass$(),
246
- itemButtonClass: itemButtonClass$(),
247
- itemCollapseClass: itemCollapseClass$(),
248
- itemHeaderClass: itemHeaderClass$(),
249
- onItemCollapsedChange: onItemCollapsedChange$(),
250
- onItemHidden: onItemHidden$(),
251
- onItemShown: onItemShown$(),
252
- slotItemStructure: slotItemStructure$(),
253
- slotItemBody: slotItemBody$(),
254
- slotItemHeader: slotItemHeader$(),
255
- ...itemConfig?.(),
256
- })));
256
+ registerItem: (propsConfig) => {
257
+ const item = createAccordionItem(onShown$, onHidden$, {
258
+ config: mergeConfigStores(accordionItemProps, normalizeConfigStores(accordionItemProps, propsConfig?.config), accordionItemConfig),
259
+ props: propsConfig?.props,
260
+ });
257
261
  item.directives.accordionItemDirective = () => ({ destroy: itemsWidget$.register(item) });
258
262
  return item;
259
263
  },
@@ -0,0 +1 @@
1
+ export * from './accordion';
@@ -0,0 +1 @@
1
+ export * from './accordion';
@@ -0,0 +1,31 @@
1
+ import type { CommonAlertApi, CommonAlertDirectives, CommonAlertProps, CommonAlertState } from './common';
2
+ import type { ExtendWidgetAdaptSlotWidgetProps } from '../../services/extendWidget';
3
+ import type { Widget, WidgetFactory, WidgetSlotContext } from '../../types';
4
+ export type AlertContext = WidgetSlotContext<AlertWidget>;
5
+ export interface AlertExtraProps {
6
+ /**
7
+ * Type of the alert.
8
+ * There are the following types: 'success', 'info', 'warning', 'danger', 'primary', 'secondary', 'light' and 'dark'.
9
+ */
10
+ type: string;
11
+ }
12
+ export interface AlertState extends ExtendWidgetAdaptSlotWidgetProps<CommonAlertState, AlertExtraProps> {
13
+ }
14
+ export interface AlertProps extends ExtendWidgetAdaptSlotWidgetProps<CommonAlertProps, AlertExtraProps> {
15
+ }
16
+ export interface AlertApi extends CommonAlertApi {
17
+ }
18
+ export interface AlertDirectives extends CommonAlertDirectives {
19
+ }
20
+ export type AlertWidget = Widget<AlertProps, AlertState, AlertApi, object, AlertDirectives>;
21
+ /**
22
+ * Retrieve a shallow copy of the default alert config
23
+ * @returns the default alert config
24
+ */
25
+ export declare function getAlertDefaultConfig(): AlertProps;
26
+ /**
27
+ * Create an AlertWidget with given config props
28
+ * @param config - an optional alert config
29
+ * @returns an AlertWidget
30
+ */
31
+ export declare const createAlert: WidgetFactory<AlertWidget>;
@@ -0,0 +1,22 @@
1
+ import { createCommonAlert, getCommonAlertDefaultConfig } from './common';
2
+ import { extendWidgetProps } from '../../services/extendWidget';
3
+ import { typeString } from '../../utils/writables';
4
+ const alertDefaultConfig = {
5
+ type: 'primary',
6
+ };
7
+ const alertConfigValidator = {
8
+ type: typeString,
9
+ };
10
+ /**
11
+ * Retrieve a shallow copy of the default alert config
12
+ * @returns the default alert config
13
+ */
14
+ export function getAlertDefaultConfig() {
15
+ return { ...getCommonAlertDefaultConfig(), ...alertDefaultConfig };
16
+ }
17
+ /**
18
+ * Create an AlertWidget with given config props
19
+ * @param config - an optional alert config
20
+ * @returns an AlertWidget
21
+ */
22
+ export const createAlert = extendWidgetProps(createCommonAlert, alertDefaultConfig, alertConfigValidator);
@@ -1,26 +1,21 @@
1
- import type { PropsConfig } from './services';
2
- import type { TransitionFn } from './transitions';
3
- import type { Directive, SlotContent, Widget, WidgetSlotContext } from './types';
4
- export type AlertContext = WidgetSlotContext<AlertWidget>;
5
- export interface AlertCommonPropsAndState {
1
+ import type { TransitionFn } from '../../services/transitions/baseTransitions';
2
+ import type { WidgetsCommonPropsAndState } from '../commonProps';
3
+ import type { ConfigValidator, Directive, PropsConfig, SlotContent, Widget, WidgetSlotContext } from '../../types';
4
+ export type CommonAlertContext = WidgetSlotContext<CommonAlertWidget>;
5
+ export interface CommonAlertCommonPropsAndState extends WidgetsCommonPropsAndState {
6
6
  /**
7
7
  * If `true`, alert can be dismissed by the user.
8
8
  * The close button (×) will be displayed and you can be notified of the event with the (close) output.
9
9
  */
10
10
  dismissible: boolean;
11
- /**
12
- * Type of the alert.
13
- * There are the following types: 'success', 'info', 'warning', 'danger', 'primary', 'secondary', 'light' and 'dark'.
14
- */
15
- type: string;
16
11
  /**
17
12
  * Template for the alert content
18
13
  */
19
- slotDefault: SlotContent<AlertContext>;
14
+ slotDefault: SlotContent<CommonAlertContext>;
20
15
  /**
21
16
  * Global template for the alert component
22
17
  */
23
- slotStructure: SlotContent<AlertContext>;
18
+ slotStructure: SlotContent<CommonAlertContext>;
24
19
  /**
25
20
  * If `true` the alert is visible to the user
26
21
  */
@@ -30,13 +25,13 @@ export interface AlertCommonPropsAndState {
30
25
  */
31
26
  ariaCloseButtonLabel: string;
32
27
  }
33
- export interface AlertState extends AlertCommonPropsAndState {
28
+ export interface CommonAlertState extends CommonAlertCommonPropsAndState {
34
29
  /**
35
30
  * Is `true` when the alert is hidden. Compared to `visible`, this is updated after the transition is executed.
36
31
  */
37
32
  hidden: boolean;
38
33
  }
39
- export interface AlertProps extends AlertCommonPropsAndState {
34
+ export interface CommonAlertProps extends CommonAlertCommonPropsAndState {
40
35
  /**
41
36
  * Callback called when the alert visibility changed.
42
37
  */
@@ -52,7 +47,7 @@ export interface AlertProps extends AlertCommonPropsAndState {
52
47
  /**
53
48
  * The transition function will be executed when the alert is displayed or hidden.
54
49
  *
55
- * Depending on the value of {@link AlertProps.animationOnInit}, the animation can be optionally skipped during the showing process.
50
+ * Depending on the value of {@link CommonAlertProps.animationOnInit}, the animation can be optionally skipped during the showing process.
56
51
  */
57
52
  transition: TransitionFn;
58
53
  /**
@@ -70,7 +65,7 @@ export interface AlertProps extends AlertCommonPropsAndState {
70
65
  */
71
66
  animation: boolean;
72
67
  }
73
- export interface AlertApi {
68
+ export interface CommonAlertApi {
74
69
  /**
75
70
  * Triggers alert closing programmatically (same as clicking on the close button (×)).
76
71
  */
@@ -80,21 +75,23 @@ export interface AlertApi {
80
75
  */
81
76
  open(): void;
82
77
  }
83
- export interface AlertDirectives {
78
+ export interface CommonAlertDirectives {
84
79
  /**
85
80
  * the transition directive, piloting what is the visual effect of going from hidden to visible
86
81
  */
87
82
  transitionDirective: Directive;
88
83
  }
89
- export type AlertWidget = Widget<AlertProps, AlertState, AlertApi, object, AlertDirectives>;
84
+ export type CommonAlertWidget = Widget<CommonAlertProps, CommonAlertState, CommonAlertApi, object, CommonAlertDirectives>;
85
+ export declare const defaultCommonAlertConfig: CommonAlertProps;
90
86
  /**
91
87
  * Retrieve a shallow copy of the default alert config
92
88
  * @returns the default alert config
93
89
  */
94
- export declare function getAlertDefaultConfig(): AlertProps;
90
+ export declare function getCommonAlertDefaultConfig(): CommonAlertProps;
91
+ export declare const commonAlertConfigValidator: ConfigValidator<CommonAlertProps>;
95
92
  /**
96
93
  * Create an AlertWidget with given config props
97
94
  * @param config - an optional alert config
98
95
  * @returns an AlertWidget
99
96
  */
100
- export declare function createAlert(config?: PropsConfig<AlertProps>): AlertWidget;
97
+ export declare function createCommonAlert(config?: PropsConfig<CommonAlertProps>): CommonAlertWidget;
@@ -1,11 +1,12 @@
1
- import { bindDirectiveNoArg, stateStores, typeBoolean, typeString, writablesForProps } from './services';
2
- import { createTransition } from './transitions';
3
- import { fadeTransition } from './transitions/bootstrap';
4
- import { noop } from './utils';
5
- const defaultConfig = {
1
+ import { createTransition } from '../../services/transitions/baseTransitions';
2
+ import { noop } from '../../utils/internal/func';
3
+ import { fadeTransition } from '../../services/transitions/bootstrap/fade';
4
+ import { stateStores, writablesForProps } from '../../utils/stores';
5
+ import { bindDirectiveNoArg } from '../../utils/directive';
6
+ import { typeBoolean } from '../../utils/writables';
7
+ export const defaultCommonAlertConfig = {
6
8
  visible: true,
7
9
  dismissible: true,
8
- type: 'primary',
9
10
  ariaCloseButtonLabel: 'Close',
10
11
  onVisibleChange: noop,
11
12
  onShown: noop,
@@ -15,33 +16,35 @@ const defaultConfig = {
15
16
  animation: true,
16
17
  animationOnInit: false,
17
18
  transition: fadeTransition,
19
+ className: '',
18
20
  };
19
21
  /**
20
22
  * Retrieve a shallow copy of the default alert config
21
23
  * @returns the default alert config
22
24
  */
23
- export function getAlertDefaultConfig() {
24
- return { ...defaultConfig };
25
+ export function getCommonAlertDefaultConfig() {
26
+ return { ...defaultCommonAlertConfig };
25
27
  }
26
- const configValidator = {
28
+ export const commonAlertConfigValidator = {
27
29
  dismissible: typeBoolean,
28
- type: typeString,
29
30
  };
30
31
  /**
31
32
  * Create an AlertWidget with given config props
32
33
  * @param config - an optional alert config
33
34
  * @returns an AlertWidget
34
35
  */
35
- export function createAlert(config) {
36
- const [{ transition$, animationOnInit$, animation$, visible$: requestedVisible$, onVisibleChange$, onHidden$, onShown$, ...stateProps }, patch,] = writablesForProps(defaultConfig, config, configValidator);
36
+ export function createCommonAlert(config) {
37
+ const [{ transition$, animationOnInit$, animation$, visible$: requestedVisible$, onVisibleChange$, onHidden$, onShown$, ...stateProps }, patch,] = writablesForProps(defaultCommonAlertConfig, config, commonAlertConfigValidator);
37
38
  const transition = createTransition({
38
- transition: transition$,
39
- visible: requestedVisible$,
40
- animation: animation$,
41
- animationOnInit: animationOnInit$,
42
- onVisibleChange: onVisibleChange$,
43
- onHidden: onHidden$,
44
- onShown: onShown$,
39
+ props: {
40
+ transition: transition$,
41
+ visible: requestedVisible$,
42
+ animation: animation$,
43
+ animationOnInit: animationOnInit$,
44
+ onVisibleChange: onVisibleChange$,
45
+ onHidden: onHidden$,
46
+ onShown: onShown$,
47
+ },
45
48
  });
46
49
  const close = () => {
47
50
  patch({ visible: false });
@@ -0,0 +1,2 @@
1
+ export * from './common';
2
+ export * from './alert';