@progress/kendo-angular-grid 19.2.0-develop.14 → 19.2.0-develop.2

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.
@@ -8,20 +8,15 @@ import { GridComponent } from '../grid.component';
8
8
  import { UndoRedoEvent } from './grid-state.models';
9
9
  import { Subscription } from 'rxjs';
10
10
  import { EditService } from '../editing/edit.service';
11
- import { filter } from 'rxjs/operators';
11
+ import { filter, tap } from 'rxjs/operators';
12
12
  import { UndoRedoService } from './undo-redo.service';
13
- import { hasObservers, isPresent } from '@progress/kendo-angular-common';
13
+ import { hasObservers } from '@progress/kendo-angular-common';
14
14
  import { ChangeNotificationService } from '../data/change-notification.service';
15
- import { ContextService } from '../common/provider.service';
16
- import { LocalDataChangesService } from '../editing/local-data-changes.service';
17
- import { recursiveFlatMap } from '../utils';
18
15
  import * as i0 from "@angular/core";
19
16
  import * as i1 from "../grid.component";
20
17
  import * as i2 from "../editing/edit.service";
21
18
  import * as i3 from "./undo-redo.service";
22
19
  import * as i4 from "../data/change-notification.service";
23
- import * as i5 from "../common/provider.service";
24
- import * as i6 from "../editing/local-data-changes.service";
25
20
  /**
26
21
  * Represents the directive that manages undo-redo operations in the Grid.
27
22
  * Use this directive to enable undo and redo functionality for user actions in the Grid.
@@ -38,17 +33,11 @@ export class UndoRedoDirective {
38
33
  editService;
39
34
  undoRedoService;
40
35
  changeNotification;
41
- ctx;
42
- localDataChangesService;
43
36
  /**
44
37
  * Sets the maximum number of actions to keep in the undo-redo stack.
45
38
  * @default 10
46
39
  */
47
40
  maxStoredStates = 10;
48
- /**
49
- * Defines the property name of the data item unique key that will be used to identify the items when performing undo-redo actions.
50
- */
51
- itemIdKey;
52
41
  /**
53
42
  * Fires when you perform the undo action. Provides the Grid state to apply.
54
43
  */
@@ -66,17 +55,24 @@ export class UndoRedoDirective {
66
55
  stack;
67
56
  subs = new Subscription();
68
57
  addToState = true;
69
- constructor(host, editService, undoRedoService, changeNotification, ctx, localDataChangesService) {
58
+ constructor(host, editService, undoRedoService, changeNotification) {
70
59
  this.host = host;
71
60
  this.editService = editService;
72
61
  this.undoRedoService = undoRedoService;
73
62
  this.changeNotification = changeNotification;
74
- this.ctx = ctx;
75
- this.localDataChangesService = localDataChangesService;
76
63
  this.host.undoRedoService = this.undoRedoService;
77
64
  }
78
65
  ngOnInit() {
79
66
  this.stack = new UndoRedoStack(this.maxStoredStates);
67
+ this.stack.add({
68
+ originalEvent: {
69
+ skip: this.host.skip,
70
+ take: this.host.pageSize,
71
+ sort: this.host.sort,
72
+ filter: this.host.filter,
73
+ group: this.host.group
74
+ }, gridState: structuredClone(this.host.currentState)
75
+ });
80
76
  this.subs = this.host.gridStateChange.subscribe((state) => {
81
77
  if (this.addToState) {
82
78
  this.stack.add({
@@ -87,7 +83,7 @@ export class UndoRedoDirective {
87
83
  filter: state.filter,
88
84
  group: state.group
89
85
  },
90
- gridState: state
86
+ gridState: structuredClone(state)
91
87
  });
92
88
  }
93
89
  let stackEndPointReached;
@@ -100,83 +96,36 @@ export class UndoRedoDirective {
100
96
  this.undoRedoService.stackEndReached.next(stackEndPointReached);
101
97
  });
102
98
  this.subs.add(this.editService.changes
103
- .pipe(filter((event) => event.action === 'save' || event.action === 'remove'))
99
+ .pipe(filter(event => event.action === 'save' || event.action === 'remove'), tap(event => this.undoRedoService.originalEvent = event))
104
100
  .subscribe(event => {
105
101
  this.stack.add({
106
- originalEvent: { ...event, dataItem: structuredClone(event.dataItem) },
107
- gridState: this.host.currentState
102
+ originalEvent: event,
103
+ gridState: structuredClone(this.host.currentState)
108
104
  });
109
105
  this.addToState = false;
110
106
  this.host.gridStateChange.emit(this.stack.current.gridState);
111
107
  this.addToState = true;
112
108
  this.updateUndoRedoDisabled();
113
109
  }));
114
- this.subs.add(this.changeNotification.changes.subscribe(() => {
115
- if (!this.ctx.dataBindingDirective) {
116
- this.stack.current.gridState = this.host.currentState;
117
- }
118
- }));
110
+ this.subs.add(this.changeNotification.changes.subscribe(() => this.stack.current.gridState = this.host.currentState));
119
111
  ['Undo', 'Redo'].forEach((action) => {
120
112
  this.subs.add(this.undoRedoService[`on${action}`].subscribe(() => {
121
113
  if (!this.stack[`can${action}`]) {
122
114
  return;
123
115
  }
124
- let eventData;
125
- if (action === 'Undo') {
126
- const isSaveOrRemove = this.stack.current.originalEvent.action === 'save' || this.stack.current.originalEvent.action === 'remove';
127
- eventData = isSaveOrRemove ? this.stack.current : this.stack.peekPrev();
128
- }
129
- else {
130
- eventData = this.stack.peekNext();
131
- }
132
- const event = new UndoRedoEvent(eventData);
116
+ this.stack[`${action.toLowerCase()}`]();
133
117
  if (hasObservers(this[`on${action}`])) {
118
+ const event = new UndoRedoEvent(this.stack.current);
134
119
  this[`on${action}`].emit(event);
135
120
  if (event.isDefaultPrevented()) {
136
121
  return;
137
122
  }
138
123
  }
139
- this.stack[`${action.toLowerCase()}`]();
140
124
  this.updateUndoRedoDisabled();
141
- const originalAction = event.originalEvent.action;
142
- const isLocalData = isPresent(this.ctx?.dataBindingDirective);
143
- if (!isLocalData) {
144
- return;
145
- }
146
- const isSaveOrRemove = originalAction === 'save' || originalAction === 'remove';
147
- if (isSaveOrRemove) {
148
- if (originalAction === 'save') {
149
- const stateItem = this.getGridDataItems(this.stack.current.gridState.currentData).find(item => item[this.itemIdKey] === event.originalEvent.dataItem[this.itemIdKey]);
150
- this.localDataChangesService?.data.splice(event.originalEvent.rowIndex, 1, stateItem);
151
- }
152
- else if (action === 'Undo') {
153
- this.localDataChangesService?.data.splice(event.originalEvent.rowIndex, 0, event.originalEvent.dataItem);
154
- }
155
- else {
156
- this.localDataChangesService?.data.splice(event.originalEvent.rowIndex, 1);
157
- }
158
- this.localDataChangesService?.changes.emit();
159
- }
160
- else {
161
- this.host.loadState({ ...this.stack.current.gridState, currentData: null });
162
- if (this.isDataStateChangeEvent(event.originalEvent)) {
163
- const { skip, take, sort, filter, group } = event.gridState;
164
- this.host.dataStateChange.emit({ skip, take, sort, filter, group });
165
- }
166
- }
125
+ this.host.loadState(this.stack.current.gridState);
167
126
  }));
168
127
  });
169
- }
170
- ngAfterViewInit() {
171
- this.stack.add({
172
- originalEvent: {
173
- skip: this.host.skip,
174
- take: this.host.pageSize,
175
- sort: this.host.sort,
176
- filter: this.host.filter,
177
- group: this.host.group
178
- }, gridState: this.host.currentState
179
- });
128
+ this.subs.add(this.undoRedoService.setState.subscribe((state) => this.stack.add({ originalEvent: 'dataChange', gridState: state })));
180
129
  }
181
130
  ngOnDestroy() {
182
131
  this.stack.clear();
@@ -218,15 +167,8 @@ export class UndoRedoDirective {
218
167
  }
219
168
  this.undoRedoService.stackEndReached.next(false);
220
169
  }
221
- getGridDataItems(data) {
222
- return Array.isArray(data) ? data.flatMap(recursiveFlatMap) :
223
- data.data.flatMap(recursiveFlatMap);
224
- }
225
- isDataStateChangeEvent(event) {
226
- return event && ['skip', 'take', 'sort', 'filter', 'group'].some(prop => prop in event);
227
- }
228
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: UndoRedoDirective, deps: [{ token: i1.GridComponent }, { token: i2.EditService }, { token: i3.UndoRedoService }, { token: i4.ChangeNotificationService }, { token: i5.ContextService }, { token: i6.LocalDataChangesService }], target: i0.ɵɵFactoryTarget.Directive });
229
- static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.2.12", type: UndoRedoDirective, isStandalone: true, selector: "[kendoGridUndoRedo]", inputs: { maxStoredStates: "maxStoredStates", itemIdKey: "itemIdKey" }, outputs: { onUndo: "undo", onRedo: "redo" }, providers: [UndoRedoService], exportAs: ["kendoGridUndoRedo"], ngImport: i0 });
170
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: UndoRedoDirective, deps: [{ token: i1.GridComponent }, { token: i2.EditService }, { token: i3.UndoRedoService }, { token: i4.ChangeNotificationService }], target: i0.ɵɵFactoryTarget.Directive });
171
+ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.2.12", type: UndoRedoDirective, isStandalone: true, selector: "[kendoGridUndoRedo]", inputs: { maxStoredStates: "maxStoredStates" }, outputs: { onUndo: "undo", onRedo: "redo" }, providers: [UndoRedoService], exportAs: ["kendoGridUndoRedo"], ngImport: i0 });
230
172
  }
231
173
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: UndoRedoDirective, decorators: [{
232
174
  type: Directive,
@@ -236,9 +178,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImpo
236
178
  exportAs: 'kendoGridUndoRedo',
237
179
  providers: [UndoRedoService]
238
180
  }]
239
- }], ctorParameters: function () { return [{ type: i1.GridComponent }, { type: i2.EditService }, { type: i3.UndoRedoService }, { type: i4.ChangeNotificationService }, { type: i5.ContextService }, { type: i6.LocalDataChangesService }]; }, propDecorators: { maxStoredStates: [{
240
- type: Input
241
- }], itemIdKey: [{
181
+ }], ctorParameters: function () { return [{ type: i1.GridComponent }, { type: i2.EditService }, { type: i3.UndoRedoService }, { type: i4.ChangeNotificationService }]; }, propDecorators: { maxStoredStates: [{
242
182
  type: Input
243
183
  }], onUndo: [{
244
184
  type: Output,
@@ -13,6 +13,7 @@ export class UndoRedoService {
13
13
  onUndo = new Subject();
14
14
  onRedo = new Subject();
15
15
  stackEndReached = new Subject();
16
+ setState = new Subject();
16
17
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: UndoRedoService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
17
18
  static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: UndoRedoService });
18
19
  }
@@ -139,12 +139,6 @@ export class UndoRedoStack {
139
139
  this.currentNode = this.currentNode.previous;
140
140
  return this.currentNode.state;
141
141
  }
142
- peekNext() {
143
- return this.currentNode.next?.state || null;
144
- }
145
- peekPrev() {
146
- return this.currentNode.previous?.state || null;
147
- }
148
142
  /**
149
143
  * Performs a redo operation, moving to the next state
150
144
  * @returns The next state or null if can't redo
package/esm2022/utils.mjs CHANGED
@@ -4,7 +4,6 @@
4
4
  *-------------------------------------------------------------------------------------------*/
5
5
  import { InjectionToken } from '@angular/core';
6
6
  import { merge, of } from 'rxjs';
7
- import { isDocumentAvailable } from '@progress/kendo-angular-common';
8
7
  export { isChanged, anyChanged, hasObservers } from '@progress/kendo-angular-common';
9
8
  const EMPTY_REGEX = /^\s*$/;
10
9
  /**
@@ -206,9 +205,6 @@ export const isMultipleRangesEnabled = (selectableSettings) => {
206
205
  */
207
206
  export const calcRowHeight = (tableBody) => {
208
207
  let result = 0;
209
- if (!isDocumentAvailable()) {
210
- return result;
211
- }
212
208
  if (tableBody) {
213
209
  const row = tableBody.insertRow(0);
214
210
  const cell = row.insertCell(0);