@agnos-ui/angular-headless 0.0.1-alpha.3 → 0.0.1-alpha.5

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 (96) hide show
  1. package/components/accordion/accordion.d.ts +11 -0
  2. package/components/alert/alert.d.ts +7 -0
  3. package/components/modal/modal.d.ts +7 -0
  4. package/components/pagination/pagination.d.ts +8 -0
  5. package/components/progressbar/progressbar.d.ts +7 -0
  6. package/components/rating/rating.d.ts +6 -0
  7. package/components/select/select.d.ts +8 -0
  8. package/components/slider/slider.d.ts +1 -0
  9. package/config.d.ts +53 -0
  10. package/esm2022/agnos-ui-angular-headless.mjs +2 -2
  11. package/esm2022/components/accordion/accordion.mjs +4 -0
  12. package/esm2022/components/alert/alert.mjs +4 -0
  13. package/esm2022/components/modal/modal.mjs +4 -0
  14. package/esm2022/components/pagination/pagination.mjs +4 -0
  15. package/esm2022/components/progressbar/progressbar.mjs +4 -0
  16. package/esm2022/components/rating/rating.mjs +4 -0
  17. package/esm2022/components/select/select.mjs +4 -0
  18. package/esm2022/components/slider/slider.mjs +2 -0
  19. package/esm2022/config.mjs +104 -0
  20. package/esm2022/generated/config.mjs +2 -0
  21. package/esm2022/generated/index.mjs +23 -0
  22. package/esm2022/generated/services/extendWidget.mjs +2 -0
  23. package/esm2022/generated/services/floatingUI.mjs +2 -0
  24. package/esm2022/generated/services/focustrack.mjs +2 -0
  25. package/esm2022/generated/services/intersection.mjs +2 -0
  26. package/esm2022/generated/services/navManager.mjs +2 -0
  27. package/esm2022/generated/services/portal.mjs +2 -0
  28. package/esm2022/generated/services/siblingsInert.mjs +2 -0
  29. package/esm2022/generated/services/transitions/baseTransitions.mjs +2 -0
  30. package/esm2022/generated/services/transitions/bootstrap.mjs +2 -0
  31. package/esm2022/generated/services/transitions/collapse.mjs +2 -0
  32. package/esm2022/generated/services/transitions/cssTransitions.mjs +2 -0
  33. package/esm2022/generated/services/transitions/simpleClassTransition.mjs +2 -0
  34. package/esm2022/generated/slot.directive.mjs +2 -0
  35. package/esm2022/generated/slotDefault.directive.mjs +2 -0
  36. package/esm2022/generated/types.mjs +2 -0
  37. package/esm2022/generated/utils/coercion.mjs +2 -0
  38. package/esm2022/generated/utils/directive.mjs +2 -0
  39. package/esm2022/generated/utils/stores.mjs +2 -0
  40. package/esm2022/generated/utils/widget.mjs +2 -0
  41. package/esm2022/generated/utils/writables.mjs +2 -0
  42. package/esm2022/generated/utils/zone.mjs +2 -0
  43. package/esm2022/index.mjs +13 -0
  44. package/esm2022/slot.directive.mjs +199 -0
  45. package/esm2022/slotDefault.directive.mjs +20 -0
  46. package/esm2022/types.mjs +21 -0
  47. package/esm2022/utils/coercion.mjs +34 -0
  48. package/esm2022/utils/directive.mjs +63 -0
  49. package/esm2022/utils/stores.mjs +14 -0
  50. package/esm2022/utils/widget.mjs +114 -0
  51. package/esm2022/utils/zone.mjs +67 -0
  52. package/fesm2022/agnos-ui-angular-headless.mjs +472 -241
  53. package/fesm2022/agnos-ui-angular-headless.mjs.map +1 -1
  54. package/generated/config.d.ts +1 -0
  55. package/generated/index.d.ts +22 -0
  56. package/generated/services/extendWidget.d.ts +1 -0
  57. package/generated/services/floatingUI.d.ts +1 -0
  58. package/generated/services/focustrack.d.ts +1 -0
  59. package/generated/services/intersection.d.ts +1 -0
  60. package/generated/services/navManager.d.ts +1 -0
  61. package/generated/services/portal.d.ts +1 -0
  62. package/generated/services/siblingsInert.d.ts +1 -0
  63. package/generated/services/transitions/baseTransitions.d.ts +1 -0
  64. package/generated/services/transitions/bootstrap.d.ts +1 -0
  65. package/generated/services/transitions/collapse.d.ts +1 -0
  66. package/generated/services/transitions/cssTransitions.d.ts +1 -0
  67. package/generated/services/transitions/simpleClassTransition.d.ts +1 -0
  68. package/generated/slot.directive.d.ts +1 -0
  69. package/generated/slotDefault.directive.d.ts +1 -0
  70. package/generated/types.d.ts +1 -0
  71. package/generated/utils/coercion.d.ts +1 -0
  72. package/generated/utils/directive.d.ts +1 -0
  73. package/generated/utils/stores.d.ts +1 -0
  74. package/generated/utils/widget.d.ts +1 -0
  75. package/generated/utils/writables.d.ts +1 -0
  76. package/generated/utils/zone.d.ts +1 -0
  77. package/index.d.ts +9 -5
  78. package/package.json +17 -15
  79. package/{lib/slot.directive.d.ts → slot.directive.d.ts} +1 -1
  80. package/{lib/slotDefault.directive.d.ts → slotDefault.directive.d.ts} +1 -1
  81. package/{lib/slotTypes.d.ts → types.d.ts} +19 -2
  82. package/utils/coercion.d.ts +22 -0
  83. package/{lib/use.directive.d.ts → utils/directive.d.ts} +8 -5
  84. package/utils/stores.d.ts +4 -0
  85. package/utils/widget.d.ts +27 -0
  86. package/utils/zone.d.ts +16 -0
  87. package/esm2022/lib/config.mjs +0 -102
  88. package/esm2022/lib/slot.directive.mjs +0 -199
  89. package/esm2022/lib/slotDefault.directive.mjs +0 -20
  90. package/esm2022/lib/slotTypes.mjs +0 -7
  91. package/esm2022/lib/use.directive.mjs +0 -57
  92. package/esm2022/lib/utils.mjs +0 -45
  93. package/esm2022/public-api.mjs +0 -25
  94. package/lib/config.d.ts +0 -48
  95. package/lib/utils.d.ts +0 -16
  96. package/public-api.d.ts +0 -49
@@ -1,9 +1,192 @@
1
- import { toReadableStore, createWidgetsConfig, createAccordion as createAccordion$1, createAlert as createAlert$1, createModal as createModal$1, createPagination as createPagination$1, createRating as createRating$1, createSelect as createSelect$1, createProgressbar as createProgressbar$1 } from '@agnos-ui/core';
2
- export * from '@agnos-ui/core';
3
- import { DOCUMENT } from '@angular/common';
1
+ import { createAccordion as createAccordion$1 } from '@agnos-ui/core/components/accordion';
2
+ export * from '@agnos-ui/core/components/accordion';
3
+ import { createAlert as createAlert$1 } from '@agnos-ui/core/components/alert';
4
+ export * from '@agnos-ui/core/components/alert';
5
+ import { createModal as createModal$1 } from '@agnos-ui/core/components/modal';
6
+ export * from '@agnos-ui/core/components/modal';
7
+ import { createPagination as createPagination$1 } from '@agnos-ui/core/components/pagination';
8
+ export * from '@agnos-ui/core/components/pagination';
9
+ import { createProgressbar as createProgressbar$1 } from '@agnos-ui/core/components/progressbar';
10
+ export * from '@agnos-ui/core/components/progressbar';
11
+ import { createRating as createRating$1 } from '@agnos-ui/core/components/rating';
12
+ export * from '@agnos-ui/core/components/rating';
13
+ import { createSelect as createSelect$1 } from '@agnos-ui/core/components/select';
14
+ export * from '@agnos-ui/core/components/select';
15
+ export * from '@agnos-ui/core/components/slider';
16
+ export * from '@agnos-ui/core/services/siblingsInert';
17
+ export * from '@agnos-ui/core/services/portal';
18
+ export * from '@agnos-ui/core/services/navManager';
19
+ export * from '@agnos-ui/core/services/intersection';
20
+ export * from '@agnos-ui/core/services/focustrack';
21
+ export * from '@agnos-ui/core/services/floatingUI';
22
+ export * from '@agnos-ui/core/services/extendWidget';
23
+ export * from '@agnos-ui/core/services/transitions/simpleClassTransition';
24
+ export * from '@agnos-ui/core/services/transitions/cssTransitions';
25
+ export * from '@agnos-ui/core/services/transitions/collapse';
26
+ export * from '@agnos-ui/core/services/transitions/bootstrap';
27
+ export * from '@agnos-ui/core/services/transitions/baseTransitions';
28
+ export * from '@agnos-ui/core/utils/writables';
4
29
  import * as i0 from '@angular/core';
5
- import { createComponent, EnvironmentInjector, TemplateRef, reflectComponentType, inject, ViewContainerRef, Directive, Input, ElementRef, Injector, runInInjectionContext, SkipSelf, Optional, InjectionToken } from '@angular/core';
30
+ import { NgZone, inject, Injectable, signal, DestroyRef, ElementRef, Directive, Input, Injector, runInInjectionContext, SkipSelf, Optional, InjectionToken, booleanAttribute, numberAttribute, TemplateRef, EnvironmentInjector, createComponent, reflectComponentType, ViewContainerRef } from '@angular/core';
31
+ import { toReadableStore } from '@agnos-ui/core/utils/stores';
32
+ export * from '@agnos-ui/core/utils/stores';
33
+ export * from '@agnos-ui/core/utils/directive';
34
+ import { toSlotContextWidget } from '@agnos-ui/core/types';
35
+ export * from '@agnos-ui/core/types';
36
+ import { createWidgetsConfig } from '@agnos-ui/core/config';
37
+ export * from '@agnos-ui/core/config';
6
38
  import { writable, computed } from '@amadeus-it-group/tansu';
39
+ import { DOCUMENT } from '@angular/common';
40
+
41
+ const createAccordion = createAccordion$1;
42
+
43
+ const createAlert = createAlert$1;
44
+
45
+ const createModal = createModal$1;
46
+
47
+ const createPagination = createPagination$1;
48
+
49
+ const createProgressbar = createProgressbar$1;
50
+
51
+ const createRating = createRating$1;
52
+
53
+ const createSelect = createSelect$1;
54
+
55
+ const noop = () => { };
56
+ const identity = (a) => a;
57
+ const createObjectWrapper = (wrap) => (object) => {
58
+ if (!object || typeof object !== 'object') {
59
+ return object;
60
+ }
61
+ const res = {};
62
+ for (const key of Object.keys(object)) {
63
+ res[key] = wrap(object[key]);
64
+ }
65
+ return res;
66
+ };
67
+ const createReturnValueWrapper = (wrapReturnValue, wrapResult) => (fn) => wrapResult(typeof fn === 'function' ? ((...args) => wrapReturnValue(fn(...args))) : fn);
68
+ class ZoneWrapper {
69
+ constructor() {
70
+ this.#zone = inject(NgZone);
71
+ this.#hasZone = this.#zone.run(() => NgZone.isInAngularZone()); // check if zone is enabled (can be NoopZone, cf https://angular.io/guide/zone#noopzone)
72
+ this.#runNeeded = false;
73
+ this.#runPlanned = false;
74
+ this.planNgZoneRun = this.#hasZone
75
+ ? () => {
76
+ if (this.#zone.isStable) {
77
+ this.#runNeeded = true;
78
+ if (!this.#runPlanned) {
79
+ this.#runPlanned = true;
80
+ (async () => {
81
+ await 0;
82
+ this.#runPlanned = false;
83
+ if (this.#runNeeded) {
84
+ this.ngZoneRun(noop);
85
+ }
86
+ })();
87
+ }
88
+ }
89
+ }
90
+ : noop;
91
+ this.insideNgZone = this.#hasZone
92
+ ? (fn) => (typeof fn === 'function' ? ((...args) => this.ngZoneRun(() => fn(...args))) : fn)
93
+ : identity;
94
+ this.insideNgZoneWrapFunctionsObject = createObjectWrapper(this.insideNgZone);
95
+ this.outsideNgZone = this.#hasZone
96
+ ? (fn) => (typeof fn === 'function' ? ((...args) => this.#zone.runOutsideAngular(() => fn(...args))) : fn)
97
+ : identity;
98
+ this.outsideNgZoneWrapFunctionsObject = createObjectWrapper(this.outsideNgZone);
99
+ this.outsideNgZoneWrapDirective = createReturnValueWrapper(this.outsideNgZoneWrapFunctionsObject, this.outsideNgZone);
100
+ this.outsideNgZoneWrapDirectivesObject = createObjectWrapper(this.outsideNgZoneWrapDirective);
101
+ }
102
+ #zone;
103
+ #hasZone; // check if zone is enabled (can be NoopZone, cf https://angular.io/guide/zone#noopzone)
104
+ #runNeeded;
105
+ #runPlanned;
106
+ ngZoneRun(fn) {
107
+ this.#runNeeded = false;
108
+ return this.#zone.run(fn);
109
+ }
110
+ static { this.ɵfac = function ZoneWrapper_Factory(t) { return new (t || ZoneWrapper)(); }; }
111
+ static { this.ɵprov = /*@__PURE__*/ i0.ɵɵdefineInjectable({ token: ZoneWrapper, factory: ZoneWrapper.ɵfac, providedIn: 'root' }); }
112
+ }
113
+ (() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(ZoneWrapper, [{
114
+ type: Injectable,
115
+ args: [{
116
+ providedIn: 'root',
117
+ }]
118
+ }], null, null); })();
119
+
120
+ const toAngularSignal = (tansuSignal) => {
121
+ const zoneWrapper = inject(ZoneWrapper);
122
+ const res = signal(undefined);
123
+ const subscription = zoneWrapper.outsideNgZone(tansuSignal.subscribe)((value) => {
124
+ res.set(value);
125
+ zoneWrapper.planNgZoneRun();
126
+ });
127
+ inject(DestroyRef).onDestroy(zoneWrapper.outsideNgZone(subscription));
128
+ return res;
129
+ };
130
+
131
+ // All calls of the directive in this class are done asynchronously (with await 0)
132
+ // in order to avoid ExpressionChangedAfterItHasBeenCheckedError
133
+ // or the corresponding issue with signals (https://github.com/angular/angular/issues/50320)
134
+ // This is relevant especially if calling the directive changes variables used in a template.
135
+ const useDirectiveForHost = (use, params) => {
136
+ const ref = inject(ElementRef);
137
+ let instance = use?.(ref.nativeElement, params);
138
+ async function destroyDirectiveInstance() {
139
+ const oldInstance = instance;
140
+ instance = undefined;
141
+ use = undefined;
142
+ if (oldInstance?.destroy) {
143
+ await 0;
144
+ oldInstance.destroy?.();
145
+ }
146
+ }
147
+ inject(DestroyRef).onDestroy(destroyDirectiveInstance);
148
+ async function update(newUse, newParams) {
149
+ if (newUse !== use) {
150
+ destroyDirectiveInstance();
151
+ use = newUse;
152
+ params = newParams;
153
+ if (newUse) {
154
+ await 0;
155
+ // checks that the directive did not change while waiting:
156
+ if (use === newUse && !instance) {
157
+ instance = use(ref.nativeElement, params);
158
+ }
159
+ }
160
+ }
161
+ else if (newParams != params) {
162
+ params = newParams;
163
+ await 0;
164
+ instance?.update?.(params);
165
+ }
166
+ }
167
+ return { update };
168
+ };
169
+ class UseDirective {
170
+ #useDirective = useDirectiveForHost();
171
+ ngOnChanges() {
172
+ this.#useDirective.update(this.use, this.params);
173
+ }
174
+ static { this.ɵfac = function UseDirective_Factory(t) { return new (t || UseDirective)(); }; }
175
+ static { this.ɵdir = /*@__PURE__*/ i0.ɵɵdefineDirective({ type: UseDirective, selectors: [["", "auUse", ""]], inputs: { use: ["auUse", "use"], params: ["auUseParams", "params"] }, standalone: true, features: [i0.ɵɵNgOnChangesFeature] }); }
176
+ }
177
+ (() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(UseDirective, [{
178
+ type: Directive,
179
+ args: [{
180
+ standalone: true,
181
+ selector: '[auUse]',
182
+ }]
183
+ }], null, { use: [{
184
+ type: Input,
185
+ args: ['auUse']
186
+ }], params: [{
187
+ type: Input,
188
+ args: ['auUseParams']
189
+ }] }); })();
7
190
 
8
191
  class ComponentTemplate {
9
192
  constructor(component, templateProp) {
@@ -11,6 +194,275 @@ class ComponentTemplate {
11
194
  this.templateProp = templateProp;
12
195
  }
13
196
  }
197
+ class SlotComponent {
198
+ static { this.ɵfac = function SlotComponent_Factory(t) { return new (t || SlotComponent)(); }; }
199
+ static { this.ɵdir = /*@__PURE__*/ i0.ɵɵdefineDirective({ type: SlotComponent, inputs: { state: "state", widget: "widget" } }); }
200
+ }
201
+ (() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(SlotComponent, [{
202
+ type: Directive
203
+ }], null, { state: [{
204
+ type: Input
205
+ }], widget: [{
206
+ type: Input
207
+ }] }); })();
208
+
209
+ const createPatchSlots = (set) => {
210
+ let lastValue = {};
211
+ return (object) => {
212
+ const newValue = {};
213
+ let hasChange = false;
214
+ for (const key of Object.keys(object)) {
215
+ const objectKey = object[key];
216
+ if (objectKey != null) {
217
+ // only use defined slots
218
+ newValue[key] = objectKey;
219
+ }
220
+ if (objectKey != lastValue[key]) {
221
+ hasChange = true;
222
+ }
223
+ }
224
+ if (hasChange) {
225
+ lastValue = newValue;
226
+ set(newValue);
227
+ }
228
+ };
229
+ };
230
+ const callWidgetFactoryWithConfig = ({ factory, defaultConfig, widgetConfig, events, afterInit, }) => {
231
+ const injector = inject(Injector);
232
+ const slots$ = writable({});
233
+ const props = {};
234
+ let initDone;
235
+ const res = {
236
+ initialized: new Promise((resolve) => {
237
+ initDone = resolve;
238
+ }),
239
+ patchSlots: createPatchSlots(slots$.set),
240
+ patch(newProps) {
241
+ // temporary function replaced in ngInit
242
+ Object.assign(props, newProps);
243
+ },
244
+ ngInit() {
245
+ runInInjectionContext(injector, () => {
246
+ const zoneWrapper = inject(ZoneWrapper);
247
+ factory = zoneWrapper.outsideNgZone(factory);
248
+ const defaultConfig$ = toReadableStore(defaultConfig);
249
+ events = zoneWrapper.insideNgZoneWrapFunctionsObject(events);
250
+ const widget = factory({
251
+ config: computed(() => ({ ...defaultConfig$(), ...widgetConfig?.(), ...slots$(), ...events })),
252
+ props,
253
+ });
254
+ const wrappedWidget = {
255
+ ...widget,
256
+ patch: zoneWrapper.outsideNgZone(widget.patch),
257
+ directives: zoneWrapper.outsideNgZoneWrapDirectivesObject(widget.directives),
258
+ actions: zoneWrapper.outsideNgZoneWrapFunctionsObject(widget.actions),
259
+ api: zoneWrapper.outsideNgZoneWrapFunctionsObject(widget.api),
260
+ };
261
+ Object.assign(res, wrappedWidget, {
262
+ widget: toSlotContextWidget(wrappedWidget),
263
+ ngState: toAngularSignal(wrappedWidget.state$),
264
+ });
265
+ afterInit?.();
266
+ initDone();
267
+ });
268
+ },
269
+ };
270
+ return res;
271
+ };
272
+ function patchSimpleChanges(patchFn, changes) {
273
+ const obj = {};
274
+ for (const [key, simpleChange] of Object.entries(changes)) {
275
+ if (simpleChange !== undefined) {
276
+ obj[key] = simpleChange.currentValue;
277
+ }
278
+ }
279
+ patchFn(obj);
280
+ }
281
+ /**
282
+ * Stores the result of the first call to the getter and returns that result directly for subsequent calls
283
+ *
284
+ * Applies to: class getters
285
+ */
286
+ const CachedProperty = (target, property, descriptor) => {
287
+ const originalGet = descriptor.get;
288
+ descriptor.get = function () {
289
+ const value = originalGet?.call(this);
290
+ Object.defineProperty(this, property, { value, writable: false });
291
+ return value;
292
+ };
293
+ };
294
+ class BaseWidgetDirective {
295
+ get api() {
296
+ return this._widget.api;
297
+ }
298
+ get state() {
299
+ return this._widget.ngState;
300
+ }
301
+ get widget() {
302
+ return this._widget.widget;
303
+ }
304
+ ngOnChanges(changes) {
305
+ patchSimpleChanges(this._widget.patch, changes);
306
+ }
307
+ ngOnInit() {
308
+ this._widget.ngInit();
309
+ }
310
+ static { this.ɵfac = function BaseWidgetDirective_Factory(t) { return new (t || BaseWidgetDirective)(); }; }
311
+ static { this.ɵdir = /*@__PURE__*/ i0.ɵɵdefineDirective({ type: BaseWidgetDirective, features: [i0.ɵɵNgOnChangesFeature] }); }
312
+ }
313
+ (() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(BaseWidgetDirective, [{
314
+ type: Directive
315
+ }], null, null); })();
316
+
317
+ const widgetsConfigFactory = (widgetsConfigInjectionToken = new InjectionToken('widgetsConfig')) => {
318
+ /**
319
+ * Creates a provider of widgets default configuration that inherits from any widgets default configuration already defined at an upper level
320
+ * in the Angular dependency injection system. It contains its own set of widgets configuration properties that override the same properties form
321
+ * the parent configuration.
322
+ *
323
+ * @remarks
324
+ * The configuration is computed from the parent configuration in two steps:
325
+ * - first step: the parent configuration is transformed by the adaptParentConfig function (if specified).
326
+ * If adaptParentConfig is not specified, this step is skipped.
327
+ * - second step: the configuration from step 1 is merged (2-levels deep) with the own$ store. The own$ store initially contains
328
+ * an empty object (i.e. no property from the parent is overridden). It can be changed by calling set on the store returned by
329
+ * {@link injectWidgetsConfig}.
330
+ *
331
+ * @param adaptParentConfig - optional function that receives a 2-levels copy of the widgets default configuration
332
+ * defined at an upper level in the Angular dependency injection system (or an empty object if there is none) and returns the widgets
333
+ * default configuration to be used.
334
+ * It is called only if the configuration is needed, and was not yet computed for the current value of the parent configuration.
335
+ * It is called in a tansu reactive context, so it can use any tansu store and will be called again if those stores change.
336
+ * It is also called in an Angular injection context, so it can call the Angular inject function to get and use dependencies from the
337
+ * Angular dependency injection system.
338
+
339
+ * @returns DI provider to be included a list of `providers` (for example at a component level or
340
+ * any other level of the Angular dependency injection system)
341
+ *
342
+ * @example
343
+ * ```typescript
344
+ * @Component({
345
+ * // ...
346
+ * providers: [
347
+ * provideWidgetsConfig((parentConfig) => {
348
+ * // first step configuration: transforms the parent configuration
349
+ * parentConfig.rating = parentConfig.rating ?? {};
350
+ * parentConfig.rating.className = `${parentConfig.rating.className ?? ''} my-rating-extra-class`
351
+ * return parentConfig;
352
+ * })
353
+ * ]
354
+ * })
355
+ * class MyComponent {
356
+ * widgetsConfig = injectWidgetsConfig();
357
+ * constructor() {
358
+ * this.widgetsConfig.set({
359
+ * // second step configuration: overrides the parent configuration
360
+ * rating: {
361
+ * slotStar: MyCustomSlotStar
362
+ * }
363
+ * });
364
+ * }
365
+ * // ...
366
+ * }
367
+ * ```
368
+ */
369
+ const provideWidgetsConfig = (adaptParentConfig) => ({
370
+ provide: widgetsConfigInjectionToken,
371
+ useFactory: (parent) => {
372
+ if (adaptParentConfig) {
373
+ const injector = inject(Injector);
374
+ const originalAdaptParentConfig = adaptParentConfig;
375
+ adaptParentConfig = (value) => runInInjectionContext(injector, () => originalAdaptParentConfig(value));
376
+ }
377
+ return createWidgetsConfig(parent ?? undefined, adaptParentConfig);
378
+ },
379
+ deps: [[new SkipSelf(), new Optional(), widgetsConfigInjectionToken]],
380
+ });
381
+ /**
382
+ * Returns the widgets default configuration store that was provided in the current injection context.
383
+ * Throws if the no widgets default configuration store was provided.
384
+ *
385
+ * @remarks
386
+ * This function must be called from an injection context, such as a constructor, a factory function, a field initializer or
387
+ * a function used with {@link https://angular.io/api/core/runInInjectionContext | runInInjectionContext}.
388
+ *
389
+ * @returns the widgets default configuration store.
390
+ */
391
+ const injectWidgetsConfig = () => inject(widgetsConfigInjectionToken);
392
+ const injectWidgetConfig = (widgetName) => {
393
+ const widgetsConfig = inject(widgetsConfigInjectionToken, { optional: true });
394
+ return computed(() => widgetsConfig?.()[widgetName]);
395
+ };
396
+ const callWidgetFactory = ({ factory, widgetName = null, defaultConfig = {}, events, afterInit, }) => callWidgetFactoryWithConfig({
397
+ factory,
398
+ widgetConfig: widgetName ? injectWidgetConfig(widgetName) : null,
399
+ defaultConfig,
400
+ events,
401
+ afterInit,
402
+ });
403
+ return {
404
+ /**
405
+ * Dependency Injection token which can be used to provide or inject the widgets default configuration store.
406
+ */
407
+ widgetsConfigInjectionToken,
408
+ provideWidgetsConfig,
409
+ injectWidgetsConfig,
410
+ injectWidgetConfig,
411
+ callWidgetFactory,
412
+ };
413
+ };
414
+ const { widgetsConfigInjectionToken, provideWidgetsConfig, injectWidgetConfig, injectWidgetsConfig, callWidgetFactory } = widgetsConfigFactory();
415
+
416
+ /**
417
+ * Transforms a value (typically a string) to a boolean.
418
+ * Intended to be used as a transform function of an input.
419
+ *
420
+ * @usageNotes
421
+ * ```typescript
422
+ * @Input({ transform: auBooleanAttribute }) status: boolean | undefined;
423
+ * ```
424
+ * @param value Value to be transformed.
425
+ */
426
+ function auBooleanAttribute(value) {
427
+ if (value === undefined) {
428
+ return undefined;
429
+ }
430
+ return booleanAttribute(value);
431
+ }
432
+ /**
433
+ * Transforms a value (typically a string) to a number.
434
+ * Intended to be used as a transform function of an input.
435
+ * @param value Value to be transformed.
436
+ *
437
+ * @usageNotes
438
+ * ```typescript
439
+ * @Input({ transform: auNumberAttribute }) id: number | undefined;
440
+ * ```
441
+ */
442
+ function auNumberAttribute(value) {
443
+ if (value === undefined) {
444
+ return undefined;
445
+ }
446
+ return numberAttribute(value);
447
+ }
448
+
449
+ class SlotDefaultDirective {
450
+ constructor() {
451
+ this.templateRef = inject((TemplateRef));
452
+ }
453
+ ngOnInit() {
454
+ this.auSlotDefault.update((value) => ({ ...value, slotDefault: this.templateRef }));
455
+ }
456
+ static { this.ɵfac = function SlotDefaultDirective_Factory(t) { return new (t || SlotDefaultDirective)(); }; }
457
+ static { this.ɵdir = /*@__PURE__*/ i0.ɵɵdefineDirective({ type: SlotDefaultDirective, selectors: [["", "auSlotDefault", ""]], inputs: { auSlotDefault: "auSlotDefault" }, standalone: true }); }
458
+ }
459
+ (() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(SlotDefaultDirective, [{
460
+ type: Directive,
461
+ args: [{ selector: '[auSlotDefault]', standalone: true }]
462
+ }], null, { auSlotDefault: [{
463
+ type: Input,
464
+ args: ['auSlotDefault']
465
+ }] }); })();
14
466
 
15
467
  class SlotHandler {
16
468
  constructor(viewContainerRef, document) {
@@ -190,251 +642,30 @@ class SlotDirective {
190
642
  this._slotHandler?.destroy();
191
643
  this._slotHandler = undefined;
192
644
  }
193
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.9", ngImport: i0, type: SlotDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
194
- static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.2.9", type: SlotDirective, isStandalone: true, selector: "[auSlot]", inputs: { slot: ["auSlot", "slot"], props: ["auSlotProps", "props"] }, usesOnChanges: true, ngImport: i0 }); }
645
+ static { this.ɵfac = function SlotDirective_Factory(t) { return new (t || SlotDirective)(); }; }
646
+ static { this.ɵdir = /*@__PURE__*/ i0.ɵɵdefineDirective({ type: SlotDirective, selectors: [["", "auSlot", ""]], inputs: { slot: ["auSlot", "slot"], props: ["auSlotProps", "props"] }, standalone: true, features: [i0.ɵɵNgOnChangesFeature] }); }
195
647
  }
196
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.9", ngImport: i0, type: SlotDirective, decorators: [{
197
- type: Directive,
198
- args: [{
199
- selector: '[auSlot]',
200
- standalone: true,
201
- }]
202
- }], propDecorators: { slot: [{
203
- type: Input,
204
- args: ['auSlot']
205
- }], props: [{
206
- type: Input,
207
- args: ['auSlotProps']
208
- }] } });
209
-
210
- class SlotDefaultDirective {
211
- constructor() {
212
- this.templateRef = inject((TemplateRef));
213
- }
214
- ngOnInit() {
215
- this.auSlotDefault.update((value) => ({ ...value, slotDefault: this.templateRef }));
216
- }
217
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.9", ngImport: i0, type: SlotDefaultDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
218
- static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.2.9", type: SlotDefaultDirective, isStandalone: true, selector: "[auSlotDefault]", inputs: { auSlotDefault: "auSlotDefault" }, ngImport: i0 }); }
219
- }
220
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.9", ngImport: i0, type: SlotDefaultDirective, decorators: [{
221
- type: Directive,
222
- args: [{ selector: '[auSlotDefault]', standalone: true }]
223
- }], propDecorators: { auSlotDefault: [{
224
- type: Input,
225
- args: ['auSlotDefault']
226
- }] } });
227
-
228
- // All calls of the directive in this class are done asynchronously (with await 0)
229
- // in order to avoid ExpressionChangedAfterItHasBeenCheckedError
230
- // or the corresponding issue with signals (https://github.com/angular/angular/issues/50320)
231
- // This is relevant especially if calling the directive changes variables used in a template.
232
- class UseDirective {
233
- #ref = inject(ElementRef);
234
- #directive;
235
- #directiveInstance;
236
- async #destroyDirectiveInstance() {
237
- const directiveInstance = this.#directiveInstance;
238
- this.#directiveInstance = undefined;
239
- if (directiveInstance?.destroy) {
240
- await 0;
241
- directiveInstance.destroy?.();
242
- }
243
- }
244
- async ngOnChanges(changes) {
245
- if (this.use !== this.#directive) {
246
- this.#destroyDirectiveInstance();
247
- const directive = this.use;
248
- this.#directive = directive;
249
- if (directive) {
250
- await 0;
251
- // checks that the directive did not change while waiting:
252
- if (directive === this.#directive && !this.#directiveInstance) {
253
- this.#directiveInstance = directive(this.#ref.nativeElement, this.params);
254
- }
255
- }
256
- }
257
- else if (changes['params']) {
258
- await 0;
259
- this.#directiveInstance?.update?.(this.params);
260
- }
261
- }
262
- ngOnDestroy() {
263
- this.#destroyDirectiveInstance();
264
- this.#directive = undefined;
265
- }
266
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.9", ngImport: i0, type: UseDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
267
- static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.2.9", type: UseDirective, isStandalone: true, selector: "[auUse]", inputs: { use: ["auUse", "use"], params: ["auUseParams", "params"] }, usesOnChanges: true, ngImport: i0 }); }
268
- }
269
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.9", ngImport: i0, type: UseDirective, decorators: [{
270
- type: Directive,
271
- args: [{
272
- standalone: true,
273
- selector: '[auUse]',
274
- }]
275
- }], propDecorators: { use: [{
276
- type: Input,
277
- args: ['auUse']
278
- }], params: [{
279
- type: Input,
280
- args: ['auUseParams']
281
- }] } });
282
-
283
- const createPatchSlots = (set) => {
284
- let lastValue = {};
285
- return (object) => {
286
- const newValue = {};
287
- let hasChange = false;
288
- for (const key of Object.keys(object)) {
289
- const objectKey = object[key];
290
- if (objectKey != null) {
291
- // only use defined slots
292
- newValue[key] = objectKey;
293
- }
294
- if (objectKey != lastValue[key]) {
295
- hasChange = true;
296
- }
297
- }
298
- if (hasChange) {
299
- lastValue = newValue;
300
- set(newValue);
301
- }
302
- };
303
- };
304
- const callWidgetFactoryWithConfig = ({ factory, defaultConfig, widgetConfig, events, }) => {
305
- const defaultConfig$ = toReadableStore(defaultConfig);
306
- const slots$ = writable({});
307
- const widget = factory({
308
- config: computed(() => ({ ...defaultConfig$(), ...widgetConfig?.(), ...slots$() })),
309
- });
310
- widget.patch(events);
311
- return {
312
- ...widget,
313
- patchSlots: createPatchSlots(slots$.set),
314
- };
315
- };
316
- function patchSimpleChanges(patchFn, changes) {
317
- const obj = {};
318
- for (const [key, simpleChange] of Object.entries(changes)) {
319
- if (simpleChange !== undefined) {
320
- obj[key] = simpleChange.currentValue;
321
- }
322
- }
323
- patchFn(obj);
324
- }
325
-
326
- const widgetsConfigFactory = (widgetsConfigInjectionToken = new InjectionToken('widgetsConfig')) => {
327
- /**
328
- * Creates a provider of widgets default configuration that inherits from any widgets default configuration already defined at an upper level
329
- * in the Angular dependency injection system. It contains its own set of widgets configuration properties that override the same properties form
330
- * the parent configuration.
331
- *
332
- * @remarks
333
- * The configuration is computed from the parent configuration in two steps:
334
- * - first step: the parent configuration is transformed by the adaptParentConfig function (if specified).
335
- * If adaptParentConfig is not specified, this step is skipped.
336
- * - second step: the configuration from step 1 is merged (2-levels deep) with the own$ store. The own$ store initially contains
337
- * an empty object (i.e. no property from the parent is overridden). It can be changed by calling set on the store returned by
338
- * {@link injectWidgetsConfig}.
339
- *
340
- * @param adaptParentConfig - optional function that receives a 2-levels copy of the widgets default configuration
341
- * defined at an upper level in the Angular dependency injection system (or an empty object if there is none) and returns the widgets
342
- * default configuration to be used.
343
- * It is called only if the configuration is needed, and was not yet computed for the current value of the parent configuration.
344
- * It is called in a tansu reactive context, so it can use any tansu store and will be called again if those stores change.
345
- * It is also called in an Angular injection context, so it can call the Angular inject function to get and use dependencies from the
346
- * Angular dependency injection system.
347
-
348
- * @returns DI provider to be included a list of `providers` (for example at a component level or
349
- * any other level of the Angular dependency injection system)
350
- *
351
- * @example
352
- * ```typescript
353
- * @Component({
354
- * // ...
355
- * providers: [
356
- * provideWidgetsConfig((parentConfig) => {
357
- * // first step configuration: transforms the parent configuration
358
- * parentConfig.rating = parentConfig.rating ?? {};
359
- * parentConfig.rating.className = `${parentConfig.rating.className ?? ''} my-rating-extra-class`
360
- * return parentConfig;
361
- * })
362
- * ]
363
- * })
364
- * class MyComponent {
365
- * widgetsConfig = injectWidgetsConfig();
366
- * constructor() {
367
- * this.widgetsConfig.set({
368
- * // second step configuration: overrides the parent configuration
369
- * rating: {
370
- * slotStar: MyCustomSlotStar
371
- * }
372
- * });
373
- * }
374
- * // ...
375
- * }
376
- * ```
377
- */
378
- const provideWidgetsConfig = (adaptParentConfig) => ({
379
- provide: widgetsConfigInjectionToken,
380
- useFactory: (parent) => {
381
- if (adaptParentConfig) {
382
- const injector = inject(Injector);
383
- const originalAdaptParentConfig = adaptParentConfig;
384
- adaptParentConfig = (value) => runInInjectionContext(injector, () => originalAdaptParentConfig(value));
385
- }
386
- return createWidgetsConfig(parent ?? undefined, adaptParentConfig);
387
- },
388
- deps: [[new SkipSelf(), new Optional(), widgetsConfigInjectionToken]],
389
- });
390
- /**
391
- * Returns the widgets default configuration store that was provided in the current injection context.
392
- * Throws if the no widgets default configuration store was provided.
393
- *
394
- * @remarks
395
- * This function must be called from an injection context, such as a constructor, a factory function, a field initializer or
396
- * a function used with {@link https://angular.io/api/core/runInInjectionContext | runInInjectionContext}.
397
- *
398
- * @returns the widgets default configuration store.
399
- */
400
- const injectWidgetsConfig = () => inject(widgetsConfigInjectionToken);
401
- const injectWidgetConfig = (widgetName) => {
402
- const widgetsConfig = inject(widgetsConfigInjectionToken, { optional: true });
403
- return computed(() => widgetsConfig?.()[widgetName]);
404
- };
405
- const callWidgetFactory = ({ factory, widgetName = null, defaultConfig = {}, events, }) => callWidgetFactoryWithConfig({
406
- factory,
407
- widgetConfig: widgetName ? injectWidgetConfig(widgetName) : null,
408
- defaultConfig,
409
- events,
410
- });
411
- return {
412
- /**
413
- * Dependency Injection token which can be used to provide or inject the widgets default configuration store.
414
- */
415
- widgetsConfigInjectionToken,
416
- provideWidgetsConfig,
417
- injectWidgetsConfig,
418
- injectWidgetConfig,
419
- callWidgetFactory,
420
- };
421
- };
422
- const { widgetsConfigInjectionToken, provideWidgetsConfig, injectWidgetConfig, injectWidgetsConfig, callWidgetFactory } = widgetsConfigFactory();
648
+ (() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(SlotDirective, [{
649
+ type: Directive,
650
+ args: [{
651
+ selector: '[auSlot]',
652
+ standalone: true,
653
+ }]
654
+ }], null, { slot: [{
655
+ type: Input,
656
+ args: ['auSlot']
657
+ }], props: [{
658
+ type: Input,
659
+ args: ['auSlotProps']
660
+ }] }); })();
423
661
 
424
662
  /*
425
663
  * Public API Surface of @agnos-ui/angular-headless
426
664
  */
427
- const createAccordion = createAccordion$1;
428
- const createAlert = createAlert$1;
429
- const createModal = createModal$1;
430
- const createPagination = createPagination$1;
431
- const createRating = createRating$1;
432
- const createSelect = createSelect$1;
433
- const createProgressbar = createProgressbar$1;
434
665
 
435
666
  /**
436
667
  * Generated bundle index. Do not edit.
437
668
  */
438
669
 
439
- export { ComponentTemplate, SlotDefaultDirective, SlotDirective, UseDirective, callWidgetFactory, callWidgetFactoryWithConfig, createAccordion, createAlert, createModal, createPagination, createProgressbar, createRating, createSelect, injectWidgetConfig, injectWidgetsConfig, patchSimpleChanges, provideWidgetsConfig, widgetsConfigFactory, widgetsConfigInjectionToken };
670
+ export { BaseWidgetDirective, CachedProperty, ComponentTemplate, SlotComponent, SlotDefaultDirective, SlotDirective, UseDirective, ZoneWrapper, auBooleanAttribute, auNumberAttribute, callWidgetFactory, callWidgetFactoryWithConfig, createAccordion, createAlert, createModal, createPagination, createProgressbar, createRating, createSelect, injectWidgetConfig, injectWidgetsConfig, provideWidgetsConfig, toAngularSignal, useDirectiveForHost, widgetsConfigFactory, widgetsConfigInjectionToken };
440
671
  //# sourceMappingURL=agnos-ui-angular-headless.mjs.map