@dflat-core/web 1.7.2086 → 1.7.2087

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.
@@ -19058,25 +19058,42 @@ var DataGridComponent = class DataGridComponent {
19058
19058
  onRowDragEnd() {
19059
19059
  const drag = this.pendingRowDrag;
19060
19060
  if (!drag) return;
19061
- const moved = !!this.draggedRow;
19061
+ const moved = this.draggedRow;
19062
19062
  this.pendingRowDrag = void 0;
19063
19063
  this.draggedRow = void 0;
19064
19064
  document.body.classList.remove(DataGridComponent.DraggingBodyClass);
19065
19065
  if (!moved) return;
19066
+ const rows = this.data.Values;
19067
+ const index = rows.findIndex((r) => r.Id === moved.Id);
19068
+ if (index < 0 || drag.initial.findIndex((r) => r.Id === moved.Id) === index) return;
19066
19069
  const property = this.rowOrderProperty;
19067
- let values = drag.initial.map((r) => r[property]).sort((a, b) => a - b);
19070
+ const values = drag.initial.map((r) => r[property]);
19071
+ let changed;
19068
19072
  if (values.some((v) => Utilities.IsNil(v)) || new Set(values).size !== values.length) {
19069
19073
  const offset = this.facade.filter.filter$.value?.Offset ?? 0;
19070
- values = drag.initial.map((_, i) => offset + i + 1);
19071
- }
19072
- const changed = this.data.Values.map((row, i) => ({
19073
- row,
19074
- value: values[i]
19075
- })).filter((x) => x.row[property] !== x.value).map((x) => ({
19076
- ...x.row,
19077
- [property]: x.value
19078
- }));
19079
- if (changed.length > 0) this.facade.change.emitUpdated(changed);
19074
+ changed = rows.map((row, i) => ({
19075
+ row,
19076
+ value: offset + i + 1
19077
+ })).filter((x) => x.row[property] !== x.value).map((x) => ({
19078
+ ...x.row,
19079
+ [property]: x.value
19080
+ }));
19081
+ } else {
19082
+ const previous = rows[index - 1]?.[property];
19083
+ const next = rows[index + 1]?.[property];
19084
+ const value = Utilities.IsNil(previous) ? next - 1 : Utilities.IsNil(next) ? previous + 1 : (previous + next) / 2;
19085
+ changed = [{
19086
+ ...moved,
19087
+ [property]: value
19088
+ }];
19089
+ }
19090
+ const rank = this.facade.config.rowRankProperty;
19091
+ if (rank) {
19092
+ const ranks = drag.initial.map((r) => r[rank]);
19093
+ rows.forEach((row, i) => row[rank] = ranks[i]);
19094
+ changed.forEach((c) => c[rank] = ranks[rows.findIndex((r) => r.Id === c.Id)]);
19095
+ }
19096
+ this.facade.change.emitUpdated(changed);
19080
19097
  this.cd.markForCheck();
19081
19098
  }
19082
19099
  static {