@firestitch/list 18.0.82 → 18.0.84

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,7 +1,7 @@
1
1
  import * as i0 from '@angular/core';
2
2
  import { Injectable, inject, NgZone, ChangeDetectorRef, ElementRef, Renderer2, Directive, Input, Pipe, EventEmitter, Component, ChangeDetectionStrategy, Output, input, effect, HostBinding, computed, TemplateRef, ViewContainerRef, ViewChild, ContentChild, isDevMode, HostListener, ContentChildren, InjectionToken, Injector, NgModule } from '@angular/core';
3
3
  import { BehaviorSubject, Subject, Observable, map as map$1, merge, of, from, combineLatest, EMPTY } from 'rxjs';
4
- import { takeUntil, map, take, distinctUntilChanged, skip, filter, tap, shareReplay, delay, switchMap, debounceTime, mapTo, catchError } from 'rxjs/operators';
4
+ import { finalize, takeUntil, map, take, distinctUntilChanged, skip, filter, tap, shareReplay, delay, switchMap, debounceTime, mapTo, catchError } from 'rxjs/operators';
5
5
  import { get, isString, isObject, isBoolean, isFunction, cloneDeep, random, mergeWith } from 'lodash-es';
6
6
  import { BreakpointObserver } from '@angular/cdk/layout';
7
7
  import { NgClass, AsyncPipe, NgTemplateOutlet, Location, DecimalPipe } from '@angular/common';
@@ -148,10 +148,14 @@ class ReorderController {
148
148
  if (returnedValue && returnedValue instanceof Observable) {
149
149
  this.disableReorderAction();
150
150
  returnedValue
151
- .pipe(takeUntil(this._destroy$))
151
+ .pipe(
152
+ // finalize, not the next handler: a start callback that errors would otherwise
153
+ // leave the reorder action disabled for good.
154
+ finalize(() => {
155
+ this.enableReorderAction();
156
+ }), takeUntil(this._destroy$))
152
157
  .subscribe(() => {
153
158
  this.enabled = true;
154
- this.enableReorderAction();
155
159
  });
156
160
  return;
157
161
  }
@@ -164,10 +168,14 @@ class ReorderController {
164
168
  if (returnedValue && returnedValue instanceof Observable) {
165
169
  this.disableReorderAction();
166
170
  returnedValue
167
- .pipe(takeUntil(this._destroy$))
171
+ .pipe(
172
+ // finalize, not the next handler: a done callback that errors would otherwise
173
+ // leave the reorder action disabled for good.
174
+ finalize(() => {
175
+ this.enableReorderAction();
176
+ }), takeUntil(this._destroy$))
168
177
  .subscribe(() => {
169
178
  this.enabled = false;
170
- this.enableReorderAction();
171
179
  });
172
180
  return;
173
181
  }
@@ -1098,6 +1106,9 @@ class FsListDraggableListDirective {
1098
1106
  _draggableElementHeight;
1099
1107
  _draggableElementIndex;
1100
1108
  _draggableElementStartIndex;
1109
+ // Snapshotted at drag start next to the row dims, so the clamp and the hit-test always
1110
+ // describe the same frozen layout.
1111
+ _containerBounds;
1101
1112
  // Handlers
1102
1113
  _dragToHandler = this.dragTo.bind(this);
1103
1114
  _dragEndHandler = this.dragEnd.bind(this);
@@ -1105,6 +1116,18 @@ class FsListDraggableListDirective {
1105
1116
  _childRowElements;
1106
1117
  _dragStart$ = new Subject();
1107
1118
  _dragEnd$ = new Subject();
1119
+ /**
1120
+ * A reload that swaps the array out from under an in-flight drag leaves the frozen geometry
1121
+ * cache describing rows that no longer exist -- the hit-test then indexes past the end of
1122
+ * `_rows`. Drop the drag instead of dragging against a stale snapshot. Safe because
1123
+ * `swapWithIndex()` mutates the array in place, so its identity is stable within a drag.
1124
+ */
1125
+ set rows(value) {
1126
+ if (this._rows && value !== this._rows) {
1127
+ this._cleanupDrag();
1128
+ }
1129
+ this._rows = value;
1130
+ }
1108
1131
  _rows;
1109
1132
  _draggableChildrenDirectives = [];
1110
1133
  _selectedRowsDirectives = [];
@@ -1176,7 +1199,7 @@ class FsListDraggableListDirective {
1176
1199
  const targetRow = this._rows[elemIndex];
1177
1200
  if (this._multipleDraggableElementPreview) {
1178
1201
  this._multipleDraggableElementPreview.style.left = `${event.clientX}px`;
1179
- this._multipleDraggableElementPreview.style.top = `${event.clientY}px`;
1202
+ this._multipleDraggableElementPreview.style.top = `${this._clampPreviewTop(event.clientY, 0)}px`;
1180
1203
  }
1181
1204
  // Can not drag before first group and after last group
1182
1205
  const swapWithBoundaryGroupElement = (elemIndex === 0 || elemIndex === this._rows.length - 1)
@@ -1197,25 +1220,39 @@ class FsListDraggableListDirective {
1197
1220
  }
1198
1221
  }
1199
1222
  }
1200
- // FIXME
1201
1223
  if (this._draggableElementPreview) {
1202
- const topOffset = (event.y || event.clientY) - (this._draggableElementHeight / 2);
1224
+ const topOffset = this._clampPreviewTop(event.y || event.clientY, this._draggableElementHeight ?? 0);
1203
1225
  this._draggableElementPreview.style.top = `${topOffset}px`;
1204
1226
  }
1205
1227
  }
1206
1228
  }
1207
1229
  /**
1208
- * Remove events and classes after drag finish
1230
+ * Finish the drag: tear the drag down first, then tell the consumer.
1231
+ *
1232
+ * Teardown must never sit downstream of the consumer callbacks. `doneCallback` runs inside
1233
+ * `_zone.run()`, which re-throws synchronously, so a consumer that threw used to abort the rest
1234
+ * of this method -- leaving the cloned preview in the DOM and the document `mousemove` listener
1235
+ * attached, i.e. a row that follows the cursor forever and can only be cleared by a refresh.
1236
+ *
1237
+ * Nothing after `_cleanupDrag()` reads drag state: `finishReorder()` and both callbacks work off
1238
+ * the data controller alone. The one value that does -- whether the row actually moved -- is
1239
+ * snapshotted first.
1209
1240
  */
1210
1241
  dragEnd() {
1211
- this._dragInProgress = false;
1212
- this._breakpoints?.resume();
1242
+ // On touch, `touchend` and the compatibility `mouseup` both fire. Without this the second
1243
+ // pass tears down state that is already null.
1244
+ if (!this._dragInProgress) {
1245
+ return;
1246
+ }
1247
+ const moved = this._draggableElementStartIndex !== this._draggableElementIndex;
1248
+ this._cleanupDrag();
1213
1249
  this._reorderController.dataController.finishReorder();
1214
- if (this._reorderController.movedCallback
1215
- && this._draggableElementStartIndex !== this._draggableElementIndex) {
1250
+ if (this._reorderController.movedCallback && moved) {
1216
1251
  this._reorderController.movedCallback(this._reorderController.dataController.reorderData);
1217
1252
  }
1218
- if (this._reorderController.strategy === ReorderStrategy.Always) {
1253
+ // There is no drag threshold, so a bare click on the handle opens and closes a drag. Only
1254
+ // report a reorder the user actually performed.
1255
+ if (moved && this._reorderController.strategy === ReorderStrategy.Always) {
1219
1256
  this._zone.run(() => {
1220
1257
  if (this._reorderController.doneCallback) {
1221
1258
  const result = this._reorderController.doneCallback(this._reorderController.dataController.reorderData);
@@ -1223,31 +1260,11 @@ class FsListDraggableListDirective {
1223
1260
  }
1224
1261
  });
1225
1262
  }
1226
- // this._reorderController.dataController.updateOrderByRows(this._rows);
1227
- ///
1228
- this._containerElement.nativeElement.classList.remove('drag-hidden');
1229
- this._draggableElement.classList.remove('draggable-elem');
1230
- window.document.body.classList.remove('reorder-in-progress');
1231
- this._draggableElement = null;
1232
- if (this._draggableElementPreview) {
1233
- this._draggableElementPreview.remove();
1234
- this._draggableElementPreview = null;
1235
- }
1236
- else {
1237
- this._renderer.removeChild(document.body, this._multipleDraggableElementPreview);
1238
- this._multipleDraggableElementPreview = null;
1239
- }
1240
- this._draggableElementHeight = null;
1241
- this._draggableElementIndex = null;
1242
- this._draggableElementStartIndex = null;
1243
- this._selectedRowsDirectives = [];
1244
- window.removeEventListener('touchmove', this._windowTouchMoveHandler);
1245
- window.document.removeEventListener('mousemove', this._dragToHandler);
1246
- window.document.removeEventListener('touchmove', this._dragToHandler);
1247
- window.document.removeEventListener('mouseup', this._dragEndHandler);
1248
- window.document.removeEventListener('touchend', this._dragEndHandler);
1249
- window.document.removeEventListener('touchcancel', this._dragEndHandler);
1250
- this._dragEnd$.next(null);
1263
+ }
1264
+ ngOnDestroy() {
1265
+ this._cleanupDrag();
1266
+ this._destroy$.next(null);
1267
+ this._destroy$.complete();
1251
1268
  }
1252
1269
  get _isMultipleDrag() {
1253
1270
  return this._reorderController.multiple && this._selectedRowsDirectives.length > 1;
@@ -1256,6 +1273,7 @@ class FsListDraggableListDirective {
1256
1273
  * looking row elements and save their dims
1257
1274
  */
1258
1275
  prepareElements() {
1276
+ this._containerBounds = this._containerElement.nativeElement.getBoundingClientRect();
1259
1277
  this.lookupChildElements();
1260
1278
  this.calcElementsDimensions();
1261
1279
  }
@@ -1374,14 +1392,81 @@ class FsListDraggableListDirective {
1374
1392
  draggableCells[index].style.width = `${dims.width}px`;
1375
1393
  });
1376
1394
  }
1395
+ /**
1396
+ * Drop every trace of the in-flight drag: document listeners first, so nothing can re-enter
1397
+ * mid-teardown, then the DOM classes and the preview clone. Safe to call when no drag is
1398
+ * running, and deliberately free of consumer callbacks so it can never be skipped by one.
1399
+ */
1400
+ _cleanupDrag() {
1401
+ if (!this._dragInProgress) {
1402
+ return;
1403
+ }
1404
+ this._dragInProgress = false;
1405
+ this._removeDragListeners();
1406
+ this._breakpoints?.resume();
1407
+ this._containerElement.nativeElement.classList.remove('drag-hidden');
1408
+ window.document.body.classList.remove('reorder-in-progress');
1409
+ this._draggableElement?.classList.remove('draggable-elem');
1410
+ this._draggableElement = null;
1411
+ this._removeDragPreviews();
1412
+ this._draggableElementHeight = null;
1413
+ this._draggableElementIndex = null;
1414
+ this._draggableElementStartIndex = null;
1415
+ this._containerBounds = null;
1416
+ this._selectedRowsDirectives = [];
1417
+ this._dragEnd$.next(null);
1418
+ }
1419
+ /**
1420
+ * Independent checks, not if/else: a single drag creates only the cloned row, a multiple drag
1421
+ * only the preview block, and a drag torn down early may have neither. The old if/else fed a
1422
+ * null into Renderer2.removeChild(), which is `oldChild.remove()` and throws.
1423
+ */
1424
+ _removeDragPreviews() {
1425
+ if (this._draggableElementPreview) {
1426
+ this._draggableElementPreview.remove();
1427
+ this._draggableElementPreview = null;
1428
+ }
1429
+ if (this._multipleDraggableElementPreview) {
1430
+ this._renderer.removeChild(document.body, this._multipleDraggableElementPreview);
1431
+ this._multipleDraggableElementPreview = null;
1432
+ }
1433
+ }
1434
+ /**
1435
+ * Detach everything `dragStart()` bound to the document. Called first during teardown so no
1436
+ * pointer event can re-enter the drag while its state is half-released.
1437
+ */
1438
+ _removeDragListeners() {
1439
+ window.removeEventListener('touchmove', this._windowTouchMoveHandler);
1440
+ window.document.removeEventListener('mousemove', this._dragToHandler);
1441
+ window.document.removeEventListener('touchmove', this._dragToHandler);
1442
+ window.document.removeEventListener('mouseup', this._dragEndHandler);
1443
+ window.document.removeEventListener('touchend', this._dragEndHandler);
1444
+ window.document.removeEventListener('touchcancel', this._dragEndHandler);
1445
+ }
1446
+ /**
1447
+ * Keep the preview inside the list. Unclamped it follows the pointer anywhere on the page --
1448
+ * over the app header, out of a dialog -- which reads as a row that escaped and cannot be
1449
+ * dropped.
1450
+ */
1451
+ _clampPreviewTop(pointerY, height) {
1452
+ const top = pointerY - (height / 2);
1453
+ const bounds = this._containerBounds;
1454
+ if (!bounds) {
1455
+ return top;
1456
+ }
1457
+ return Math.min(Math.max(top, bounds.top), Math.max(bounds.top, bounds.bottom - height));
1458
+ }
1377
1459
  _waitUntilIsNotDone(doneResult) {
1378
1460
  if (doneResult instanceof Observable) {
1379
1461
  this._reorderController.disableReorderAction();
1380
1462
  doneResult
1381
- .pipe(takeUntil(this._destroy$))
1382
- .subscribe(() => {
1463
+ .pipe(
1464
+ // finalize, not the next handler: a done callback that errors would otherwise leave
1465
+ // the reorder action disabled for good.
1466
+ finalize(() => {
1383
1467
  this._reorderController.enableReorderAction();
1384
- });
1468
+ }), takeUntil(this._destroy$))
1469
+ .subscribe();
1385
1470
  }
1386
1471
  }
1387
1472
  _detectSelectedRows() {
@@ -1409,7 +1494,7 @@ class FsListDraggableListDirective {
1409
1494
  }
1410
1495
  }
1411
1496
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.7", ngImport: i0, type: FsListDraggableListDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive });
1412
- static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "18.2.7", type: FsListDraggableListDirective, isStandalone: true, selector: "[fsListDraggableList]", inputs: { _rows: ["rows", "_rows"] }, ngImport: i0 });
1497
+ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "18.2.7", type: FsListDraggableListDirective, isStandalone: true, selector: "[fsListDraggableList]", inputs: { rows: "rows" }, ngImport: i0 });
1413
1498
  }
1414
1499
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.7", ngImport: i0, type: FsListDraggableListDirective, decorators: [{
1415
1500
  type: Directive,
@@ -1417,7 +1502,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.7", ngImpor
1417
1502
  selector: '[fsListDraggableList]',
1418
1503
  standalone: true,
1419
1504
  }]
1420
- }], propDecorators: { _rows: [{
1505
+ }], propDecorators: { rows: [{
1421
1506
  type: Input,
1422
1507
  args: ['rows']
1423
1508
  }] } });
@@ -1544,7 +1629,12 @@ class RowAction {
1544
1629
  this.menu = value.menu ?? true;
1545
1630
  this.remove = value.remove;
1546
1631
  this.className = value.className;
1547
- this.type = this.menu && this.icon && !this.label && !value.type ? ActionType.Icon : value.type ?? ActionType.Basic;
1632
+ // An icon-only action renders as an icon button whether it sits in the menu or inline.
1633
+ // This used to be gated on `menu`, so an inline action came out Basic and
1634
+ // FsRowInlineActionComponent corrected `type` from its ngOnInit. That correction silently
1635
+ // stopped happening once a reload re-bound a new RowAction into a reused view, flipping the
1636
+ // template's @switch and blanking the action.
1637
+ this.type = value.type ?? (this.icon && !this.label ? ActionType.Icon : ActionType.Basic);
1548
1638
  this.show = value.show;
1549
1639
  this.restore = value.restore;
1550
1640
  this.rowActions = value.rowActions
@@ -1720,11 +1810,6 @@ class FsRowInlineActionComponent {
1720
1810
  actionClick(event) {
1721
1811
  this.clicked.emit(event);
1722
1812
  }
1723
- ngOnInit() {
1724
- if (!this.rowAction.label && this.rowAction.icon) {
1725
- this.rowAction.type = ActionType.Icon;
1726
- }
1727
- }
1728
1813
  fileSelected(event) {
1729
1814
  this.fileSelect.emit(event);
1730
1815
  }
@@ -3996,7 +4081,12 @@ class DataController {
3996
4081
  this.visibleRows = [];
3997
4082
  }
3998
4083
  /**
3999
- * Update data for specified row
4084
+ * Shallow-merge new values into the matching row's data.
4085
+ *
4086
+ * The merge is a spread, so the result is always a plain object: a row whose data is a class
4087
+ * instance loses its prototype here, and anything exposed through a prototype getter is
4088
+ * dropped rather than copied. Reload the list instead when rows hold models.
4089
+ *
4000
4090
  * @param rows
4001
4091
  * @param trackBy
4002
4092
  */