@acorex/platform 20.4.1 → 20.5.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.
@@ -1,8 +1,8 @@
1
1
  import * as i0 from '@angular/core';
2
- import { signal, computed, Injectable, InjectionToken, inject, ElementRef, effect, Injector, ChangeDetectorRef, ViewChild, Input, ChangeDetectionStrategy, Component, EventEmitter, Output, input, output, ViewContainerRef, Directive, Optional, Inject, NgModule, createComponent } from '@angular/core';
2
+ import { computed, signal, Injectable, InjectionToken, inject, ElementRef, effect, untracked, Injector, ChangeDetectorRef, ViewChild, Input, ChangeDetectionStrategy, Component, EventEmitter, Output, input, output, ViewContainerRef, Directive, Optional, Inject, NgModule, createComponent } from '@angular/core';
3
3
  import { convertArrayToDataSource, AXDataSource } from '@acorex/cdk/common';
4
4
  import { setSmart, AXPDataSourceDefinitionProviderService, extractValue, getSmart, AXPExpressionEvaluatorService } from '@acorex/platform/core';
5
- import { set, cloneDeep, isEqual, get, merge, isNil, isUndefined, isObjectLike, sum, isEmpty, isString } from 'lodash-es';
5
+ import { cloneDeep, isEqual, get, set, merge, isNil, isUndefined, isObjectLike, sum, isEmpty, isString } from 'lodash-es';
6
6
  import { Subject, BehaviorSubject, filter } from 'rxjs';
7
7
  import { signalStore, withState, withComputed, withMethods, patchState } from '@ngrx/signals';
8
8
  import * as i1$1 from '@acorex/components/skeleton';
@@ -15,6 +15,118 @@ import { CommonModule } from '@angular/common';
15
15
  import { AXDataTableColumnComponent, AXBaseDataTable } from '@acorex/components/data-table';
16
16
  import { AXUnsubscriber } from '@acorex/core/utils';
17
17
 
18
+ class AXPWidgetCoreContextChangeEvent {
19
+ }
20
+ const AXPWidgetCoreContextStore = signalStore(
21
+ // Initial State
22
+ withState(() => ({
23
+ data: {}, // Shared context data
24
+ state: 'initiated', // Current state
25
+ initialSnapshot: {}, // Snapshot of the first initialized state
26
+ previousSnapshot: {}, // Snapshot of the previous state
27
+ lastChange: {
28
+ state: 'initiated',
29
+ }, // Last change event
30
+ })),
31
+ // Computed Signals
32
+ withComputed(({ data, state, lastChange, initialSnapshot, previousSnapshot }) => ({
33
+ isChanged: computed(() => state() === 'changed'),
34
+ isReset: computed(() => state() === 'restored'),
35
+ isInitiated: computed(() => state() === 'initiated'),
36
+ isEmpty: computed(() => Object.keys(data()).length === 0),
37
+ isDirty: computed(() => !isEqual(data(), previousSnapshot())),
38
+ snapshot: computed(() => cloneDeep(data())), // Current data snapshot
39
+ initial: computed(() => cloneDeep(initialSnapshot())), // Initial snapshot
40
+ previous: computed(() => cloneDeep(previousSnapshot())), // Previous snapshot
41
+ changeEvent: computed(() => lastChange()), // Reactive last change event
42
+ })),
43
+ // Methods for State Management
44
+ withMethods((store) => ({
45
+ // Update a specific value
46
+ update(path, value) {
47
+ const currentData = cloneDeep(store.data());
48
+ const oldValue = get(currentData, path);
49
+ // Skip if the value hasn't changed
50
+ if (isEqual(oldValue, value)) {
51
+ return;
52
+ }
53
+ // Update the value and prepare the change event
54
+ const updatedData = setSmart(currentData, path, value);
55
+ const changeEvent = {
56
+ oldValue,
57
+ newValue: value,
58
+ path,
59
+ state: 'changed',
60
+ data: updatedData,
61
+ };
62
+ // Patch the state
63
+ patchState(store, {
64
+ previousSnapshot: store.snapshot(), // Save the previous state
65
+ data: updatedData,
66
+ state: 'changed',
67
+ lastChange: changeEvent,
68
+ });
69
+ },
70
+ patch(context) {
71
+ const currentData = cloneDeep(store.data());
72
+ // Update the value and prepare the change event
73
+ const updatedData = { ...currentData, ...context };
74
+ const changeEvent = {
75
+ state: 'patch',
76
+ data: updatedData,
77
+ };
78
+ // Patch the state
79
+ patchState(store, {
80
+ previousSnapshot: store.snapshot(), // Save the previous state
81
+ data: updatedData,
82
+ state: 'changed',
83
+ lastChange: changeEvent,
84
+ });
85
+ },
86
+ // Reset to the initial state
87
+ reset() {
88
+ const initialData = store.initial();
89
+ const changeEvent = {
90
+ oldValue: cloneDeep(store.data()), // Current data becomes old value
91
+ newValue: cloneDeep(initialData), // Reset to the initial state
92
+ path: '',
93
+ state: 'restored',
94
+ data: initialData,
95
+ };
96
+ patchState(store, {
97
+ previousSnapshot: store.snapshot(), // Save the previous state
98
+ data: initialData,
99
+ state: 'restored',
100
+ lastChange: changeEvent,
101
+ });
102
+ },
103
+ // Initialize the state
104
+ set(initialData) {
105
+ const currentData = store.data();
106
+ if (isEqual(currentData, initialData)) {
107
+ return; // Skip if the current state matches the initial state
108
+ }
109
+ const changeEvent = {
110
+ oldValue: null,
111
+ newValue: cloneDeep(initialData),
112
+ path: '',
113
+ state: 'initiated',
114
+ data: initialData,
115
+ };
116
+ patchState(store, {
117
+ initialSnapshot: cloneDeep(initialData), // Save the initial state
118
+ previousSnapshot: store.snapshot(), // Save the current state as the previous
119
+ data: initialData,
120
+ state: 'initiated',
121
+ lastChange: changeEvent,
122
+ });
123
+ },
124
+ // Get a specific value
125
+ getValue(path) {
126
+ return get(store.data(), path);
127
+ },
128
+ })));
129
+
18
130
  var AXPPageStatus;
19
131
  (function (AXPPageStatus) {
20
132
  // Idle statuses
@@ -165,118 +277,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.4", ngImpor
165
277
  type: Injectable
166
278
  }] });
167
279
 
168
- class AXPWidgetCoreContextChangeEvent {
169
- }
170
- const AXPWidgetCoreContextStore = signalStore(
171
- // Initial State
172
- withState(() => ({
173
- data: {}, // Shared context data
174
- state: 'initiated', // Current state
175
- initialSnapshot: {}, // Snapshot of the first initialized state
176
- previousSnapshot: {}, // Snapshot of the previous state
177
- lastChange: {
178
- state: 'initiated',
179
- }, // Last change event
180
- })),
181
- // Computed Signals
182
- withComputed(({ data, state, lastChange, initialSnapshot, previousSnapshot }) => ({
183
- isChanged: computed(() => state() === 'changed'),
184
- isReset: computed(() => state() === 'restored'),
185
- isInitiated: computed(() => state() === 'initiated'),
186
- isEmpty: computed(() => Object.keys(data()).length === 0),
187
- isDirty: computed(() => !isEqual(data(), previousSnapshot())),
188
- snapshot: computed(() => cloneDeep(data())), // Current data snapshot
189
- initial: computed(() => cloneDeep(initialSnapshot())), // Initial snapshot
190
- previous: computed(() => cloneDeep(previousSnapshot())), // Previous snapshot
191
- changeEvent: computed(() => lastChange()), // Reactive last change event
192
- })),
193
- // Methods for State Management
194
- withMethods((store) => ({
195
- // Update a specific value
196
- update(path, value) {
197
- const currentData = cloneDeep(store.data());
198
- const oldValue = get(currentData, path);
199
- // Skip if the value hasn't changed
200
- if (isEqual(oldValue, value)) {
201
- return;
202
- }
203
- // Update the value and prepare the change event
204
- const updatedData = setSmart(currentData, path, value);
205
- const changeEvent = {
206
- oldValue,
207
- newValue: value,
208
- path,
209
- state: 'changed',
210
- data: updatedData,
211
- };
212
- // Patch the state
213
- patchState(store, {
214
- previousSnapshot: store.snapshot(), // Save the previous state
215
- data: updatedData,
216
- state: 'changed',
217
- lastChange: changeEvent,
218
- });
219
- },
220
- patch(context) {
221
- const currentData = cloneDeep(store.data());
222
- // Update the value and prepare the change event
223
- const updatedData = { ...currentData, ...context };
224
- const changeEvent = {
225
- state: 'patch',
226
- data: updatedData,
227
- };
228
- // Patch the state
229
- patchState(store, {
230
- previousSnapshot: store.snapshot(), // Save the previous state
231
- data: updatedData,
232
- state: 'changed',
233
- lastChange: changeEvent,
234
- });
235
- },
236
- // Reset to the initial state
237
- reset() {
238
- const initialData = store.initial();
239
- const changeEvent = {
240
- oldValue: cloneDeep(store.data()), // Current data becomes old value
241
- newValue: cloneDeep(initialData), // Reset to the initial state
242
- path: '',
243
- state: 'restored',
244
- data: initialData,
245
- };
246
- patchState(store, {
247
- previousSnapshot: store.snapshot(), // Save the previous state
248
- data: initialData,
249
- state: 'restored',
250
- lastChange: changeEvent,
251
- });
252
- },
253
- // Initialize the state
254
- set(initialData) {
255
- const currentData = store.data();
256
- if (isEqual(currentData, initialData)) {
257
- return; // Skip if the current state matches the initial state
258
- }
259
- const changeEvent = {
260
- oldValue: null,
261
- newValue: cloneDeep(initialData),
262
- path: '',
263
- state: 'initiated',
264
- data: initialData,
265
- };
266
- patchState(store, {
267
- initialSnapshot: cloneDeep(initialData), // Save the initial state
268
- previousSnapshot: store.snapshot(), // Save the current state as the previous
269
- data: initialData,
270
- state: 'initiated',
271
- lastChange: changeEvent,
272
- });
273
- },
274
- // Get a specific value
275
- getValue(path) {
276
- return get(store.data(), path);
277
- },
278
- })));
279
-
280
280
  const AXPWidgetsCatalog = {
281
281
  timeDuration: 'time-duration',
282
282
  timeDurationFilter: 'time-duration-filter',
@@ -666,58 +666,64 @@ class AXPDataListWidgetComponent extends AXPValueWidgetComponent {
666
666
  this.rf = effect(async () => {
667
667
  const rawValue = this.options()['dataSource'];
668
668
  // static datasource class
669
- if (rawValue instanceof AXDataSource) {
670
- this.dataSource.set(rawValue);
671
- }
672
- // static array datasource
673
- else if (Array.isArray(rawValue)) {
674
- const ds = new AXDataSource({
675
- key: this.valueField(),
676
- pageSize: 10,
677
- load: async (e) => {
678
- const raw = this.options()['dataSource'];
679
- return {
680
- items: raw,
681
- total: raw.length,
682
- };
683
- },
684
- byKey: (key) => {
685
- const raw = this.options()['dataSource'];
686
- const item = raw.filter((c) => c[this.valueField()] == key);
687
- return Promise.resolve(item[0]);
688
- },
689
- });
690
- this.dataSource.set(ds);
691
- }
692
- // resolve data source by name
693
- else if (rawValue && (typeof rawValue == 'string' || typeof rawValue == 'object')) {
694
- const id = typeof rawValue == 'object' ? rawValue['id'] : rawValue;
695
- const c = await this.dataService.get(id);
696
- if (this.mode == 'designer' && c?.samples?.length) {
697
- this.dataSource.set(convertArrayToDataSource(c.samples, {
698
- key: this.valueField(),
699
- pageSize: 500,
700
- }));
701
- }
702
- else {
703
- const ds = c?.source();
704
- if (ds && ds instanceof Promise) {
705
- const d = await ds;
706
- this.dataSource.set(d);
669
+ untracked(async () => {
670
+ if (!isEqual(this.options()['dataSource'].config, this.dataSource().config)) {
671
+ if (rawValue instanceof AXDataSource) {
672
+ this.dataSource.set(rawValue);
707
673
  }
708
- else if (ds) {
674
+ // static array datasource
675
+ else if (Array.isArray(rawValue)) {
676
+ const ds = new AXDataSource({
677
+ key: this.valueField(),
678
+ pageSize: 10,
679
+ load: async (e) => {
680
+ const raw = this.options()['dataSource'];
681
+ const skip = e.skip ?? 0;
682
+ const take = e.take ?? raw.length;
683
+ return {
684
+ items: raw.slice(skip, skip + take),
685
+ total: raw.length,
686
+ };
687
+ },
688
+ byKey: (key) => {
689
+ const raw = this.options()['dataSource'];
690
+ const item = raw.filter((c) => c[this.valueField()] == key);
691
+ return Promise.resolve(item[0]);
692
+ },
693
+ });
709
694
  this.dataSource.set(ds);
710
695
  }
696
+ // resolve data source by name
697
+ else if (rawValue && (typeof rawValue == 'string' || typeof rawValue == 'object')) {
698
+ const id = typeof rawValue == 'object' ? rawValue['id'] : rawValue;
699
+ const c = await this.dataService.get(id);
700
+ if (this.mode == 'designer' && c?.samples?.length) {
701
+ this.dataSource.set(convertArrayToDataSource(c.samples, {
702
+ key: this.valueField(),
703
+ pageSize: 500,
704
+ }));
705
+ }
706
+ else {
707
+ const ds = c?.source();
708
+ if (ds && ds instanceof Promise) {
709
+ const d = await ds;
710
+ this.dataSource.set(d);
711
+ }
712
+ else if (ds) {
713
+ this.dataSource.set(ds);
714
+ }
715
+ // empty datasource
716
+ else {
717
+ this.dataSource.set(convertArrayToDataSource([]));
718
+ }
719
+ }
720
+ }
711
721
  // empty datasource
712
722
  else {
713
723
  this.dataSource.set(convertArrayToDataSource([]));
714
724
  }
715
725
  }
716
- }
717
- // empty datasource
718
- else {
719
- this.dataSource.set(convertArrayToDataSource([]));
720
- }
726
+ });
721
727
  }, ...(ngDevMode ? [{ debugName: "rf" }] : []));
722
728
  this.effect2 = effect(async () => {
723
729
  const value = this.getValue();