@acorex/components 20.3.46 → 20.3.48

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.
@@ -172,6 +172,19 @@ class AXGridLayoutWidgetComponent {
172
172
  ? removeUndefinedKeys(convertGridStackNodeToAXGridLayoutNode(gridstackNode))
173
173
  : { ...this.options(), element: this.elementRef.nativeElement };
174
174
  }
175
+ /**
176
+ * Returns the widget options from the Angular input binding (stored/desired positions),
177
+ * bypassing the live gridstackNode which may have been auto-reflowed.
178
+ * Used by the container to load correct per-breakpoint layouts after column changes.
179
+ *
180
+ * @returns AXGridLayoutNode - The widget options from the input signal.
181
+ */
182
+ getInputOptions() {
183
+ const opts = this.options();
184
+ return opts
185
+ ? { ...opts, element: this.elementRef.nativeElement }
186
+ : { element: this.elementRef.nativeElement };
187
+ }
175
188
  /**
176
189
  * Returns the native DOM element of the widget.
177
190
  *
@@ -244,9 +257,12 @@ class AXGridLayoutContainerComponent extends NXComponent {
244
257
  untracked(() => {
245
258
  this.ngZone.runOutsideAngular(() => {
246
259
  const gridStackOptions = removeUndefinedKeys(convertAXGridLayoutOptionsToGridStackOptions(newOptions));
247
- // Apply each option individually
260
+ // Detect whether the column count is changing — requires loading from stored input positions
261
+ const isColumnChange = gridStackOptions.column !== undefined && gridStackOptions.column !== this.grid?.opts?.column;
262
+ // Use 'none' layout mode to prevent GridStack from auto-reflowing widget positions.
263
+ // The correct per-breakpoint positions will be loaded explicitly via updateAll(true).
248
264
  if (gridStackOptions.column !== undefined) {
249
- this.grid?.column(gridStackOptions.column);
265
+ this.grid?.column(gridStackOptions.column, 'none');
250
266
  }
251
267
  if (gridStackOptions.cellHeight !== undefined) {
252
268
  this.grid?.cellHeight(gridStackOptions.cellHeight);
@@ -266,8 +282,10 @@ class AXGridLayoutContainerComponent extends NXComponent {
266
282
  if (gridStackOptions.animate !== undefined) {
267
283
  this.grid?.setAnimation(gridStackOptions.animate);
268
284
  }
269
- // Update the layout after options have been applied
270
- this.updateAll();
285
+ // When column count changes, read from Angular inputs (stored per-breakpoint positions)
286
+ // to avoid using stale gridstackNode positions from the old column layout.
287
+ // For non-column changes, read from gridstackNode to preserve live drag/resize state.
288
+ this.updateAll(isColumnChange);
271
289
  });
272
290
  });
273
291
  }
@@ -285,11 +303,17 @@ class AXGridLayoutContainerComponent extends NXComponent {
285
303
  }
286
304
  //#endregion
287
305
  //#region Internal Methods
288
- updateAll() {
306
+ /**
307
+ * Synchronizes the grid layout with the current widget list.
308
+ *
309
+ * @param useInputValues - When true, reads positions from Angular input bindings
310
+ * (stored per-breakpoint positions). When false, reads from live gridstackNode
311
+ * (preserving user drag/resize state). Use true after column/breakpoint changes.
312
+ */
313
+ updateAll(useInputValues = false) {
289
314
  if (!this.grid)
290
315
  return;
291
316
  const arrays = this.gridstackItems?.toArray() ?? [];
292
- // If there are no items, remove all widgets first
293
317
  if (arrays.length === 0) {
294
318
  this.grid.removeAll(true);
295
319
  this.checkEmpty();
@@ -297,13 +321,11 @@ class AXGridLayoutContainerComponent extends NXComponent {
297
321
  }
298
322
  const layout = [];
299
323
  arrays.forEach((item) => {
300
- const widgetOptions = item.getOptions();
324
+ const widgetOptions = useInputValues ? item.getInputOptions() : item.getOptions();
301
325
  if (widgetOptions) {
302
326
  layout.push(removeUndefinedKeys(convertAXGridLayoutNodeToGridStackNode(widgetOptions)));
303
327
  }
304
328
  });
305
- // Clear existing widgets before loading new ones
306
- //this.grid.removeAll(false);//TODO COMMENTED FOR PERFORMANCE
307
329
  this.grid.load(layout);
308
330
  this.checkEmpty();
309
331
  }