Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions doc/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -2845,7 +2845,7 @@ new Utils(): Utils;
static addElStyles(el, styles): void;
```

Defined in: [utils.ts:690](https://github.com/adumesny/gridstack.js/blob/master/src/utils.ts#L690)
Defined in: [utils.ts:692](https://github.com/adumesny/gridstack.js/blob/master/src/utils.ts#L692)

###### Parameters

Expand All @@ -2864,7 +2864,7 @@ Defined in: [utils.ts:690](https://github.com/adumesny/gridstack.js/blob/master/
static appendTo(el, parent): void;
```

Defined in: [utils.ts:672](https://github.com/adumesny/gridstack.js/blob/master/src/utils.ts#L672)
Defined in: [utils.ts:674](https://github.com/adumesny/gridstack.js/blob/master/src/utils.ts#L674)

###### Parameters

Expand Down Expand Up @@ -2943,7 +2943,7 @@ const overlap = Utils.areaIntercept(
static canBeRotated(n): boolean;
```

Defined in: [utils.ts:793](https://github.com/adumesny/gridstack.js/blob/master/src/utils.ts#L793)
Defined in: [utils.ts:795](https://github.com/adumesny/gridstack.js/blob/master/src/utils.ts#L795)

true if the item can be rotated (checking for prop, not space available)

Expand All @@ -2963,7 +2963,7 @@ true if the item can be rotated (checking for prop, not space available)
static clone<T>(obj): T;
```

Defined in: [utils.ts:635](https://github.com/adumesny/gridstack.js/blob/master/src/utils.ts#L635)
Defined in: [utils.ts:637](https://github.com/adumesny/gridstack.js/blob/master/src/utils.ts#L637)

single level clone, returning a new object with same top fields. This will share sub objects and arrays

Expand All @@ -2989,7 +2989,7 @@ single level clone, returning a new object with same top fields. This will share
static cloneDeep<T>(obj): T;
```

Defined in: [utils.ts:651](https://github.com/adumesny/gridstack.js/blob/master/src/utils.ts#L651)
Defined in: [utils.ts:653](https://github.com/adumesny/gridstack.js/blob/master/src/utils.ts#L653)

Recursive clone version that returns a full copy, checking for nested objects and arrays ONLY.
Note: this will use as-is any key starting with double __ (and not copy inside) some lib have circular dependencies.
Expand All @@ -3016,7 +3016,7 @@ Note: this will use as-is any key starting with double __ (and not copy inside)
static cloneNode(el): HTMLElement;
```

Defined in: [utils.ts:666](https://github.com/adumesny/gridstack.js/blob/master/src/utils.ts#L666)
Defined in: [utils.ts:668](https://github.com/adumesny/gridstack.js/blob/master/src/utils.ts#L668)

deep clone the given HTML node, removing teh unique id field

Expand Down Expand Up @@ -3226,7 +3226,7 @@ const fromShadow = Utils.getElements('.item', shadowRoot);
static getValuesFromTransformedElement(parent): DragTransform;
```

Defined in: [utils.ts:750](https://github.com/adumesny/gridstack.js/blob/master/src/utils.ts#L750)
Defined in: [utils.ts:752](https://github.com/adumesny/gridstack.js/blob/master/src/utils.ts#L752)

defines an element that is used to get the offset and scale from grid transforms
returns the scale and offsets from said element
Expand All @@ -3247,7 +3247,7 @@ returns the scale and offsets from said element
static initEvent<T>(e, info): T;
```

Defined in: [utils.ts:707](https://github.com/adumesny/gridstack.js/blob/master/src/utils.ts#L707)
Defined in: [utils.ts:709](https://github.com/adumesny/gridstack.js/blob/master/src/utils.ts#L709)

###### Type Parameters

Expand Down Expand Up @@ -3420,7 +3420,7 @@ removes field from the first object if same as the second objects (like diffing)
static removeInternalForSave(n, removeEl): void;
```

Defined in: [utils.ts:509](https://github.com/adumesny/gridstack.js/blob/master/src/utils.ts#L509)
Defined in: [utils.ts:511](https://github.com/adumesny/gridstack.js/blob/master/src/utils.ts#L511)

removes internal fields '_' and default values for saving

Expand All @@ -3441,7 +3441,7 @@ removes internal fields '_' and default values for saving
static removePositioningStyles(el): void;
```

Defined in: [utils.ts:542](https://github.com/adumesny/gridstack.js/blob/master/src/utils.ts#L542)
Defined in: [utils.ts:544](https://github.com/adumesny/gridstack.js/blob/master/src/utils.ts#L544)

###### Parameters

Expand Down Expand Up @@ -3565,7 +3565,7 @@ static simulateMouseEvent(
target?): void;
```

Defined in: [utils.ts:723](https://github.com/adumesny/gridstack.js/blob/master/src/utils.ts#L723)
Defined in: [utils.ts:725](https://github.com/adumesny/gridstack.js/blob/master/src/utils.ts#L725)

copies the MouseEvent (or convert Touch) properties and sends it as another event to the given target

Expand Down Expand Up @@ -3620,7 +3620,7 @@ static swap(
b): void;
```

Defined in: [utils.ts:774](https://github.com/adumesny/gridstack.js/blob/master/src/utils.ts#L774)
Defined in: [utils.ts:776](https://github.com/adumesny/gridstack.js/blob/master/src/utils.ts#L776)

swap the given object 2 field values

Expand All @@ -3642,7 +3642,7 @@ swap the given object 2 field values
static throttle(func, delay): () => void;
```

Defined in: [utils.ts:532](https://github.com/adumesny/gridstack.js/blob/master/src/utils.ts#L532)
Defined in: [utils.ts:534](https://github.com/adumesny/gridstack.js/blob/master/src/utils.ts#L534)

delay calling the given function for given delay, preventing new calls from happening while waiting

Expand Down
4 changes: 4 additions & 0 deletions doc/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Change log
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
**Table of Contents** *generated with [DocToc](http://doctoc.herokuapp.com/)*

- [12.3.2-dev (TBD)](#1232-dev-tbd)
- [12.3.2 (2025-08-12)](#1232-2025-08-12)
- [12.3.1 (2025-08-11)](#1231-2025-08-11)
- [12.3.0 (2025-08-10)](#1230-2025-08-10)
Expand Down Expand Up @@ -133,6 +134,9 @@ Change log

<!-- END doctoc generated TOC please keep comment here to allow auto update -->

## 12.3.2-dev (TBD)
* fix: [#3139](https://github.com/gridstack/gridstack.js/pull/3139) `Utils:removeInternalForSave()` to skip arrays

## 12.3.2 (2025-08-12)
* fix: [#3136](https://github.com/gridstack/gridstack.js/pull/3136) more tweaks to save(columnCount) option.

Expand Down
28 changes: 27 additions & 1 deletion spec/utils-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,5 +225,31 @@ describe('gridstack utils', () => {
expect(f).toEqual({first: 1, _dontskip: {second: 2}});
expect(z).toEqual({first: 1, _dontskip: {second: 'two'}});
});
});
});
describe('removeInternalAndSame', () => {
it('should remove internal and same', () => {
const a = {first: 1, second: 'text', _skip: {second: 2}, arr: [1, 'second', 3]};
const b = {first: 1, second: 'text'};
Utils.removeInternalAndSame(a, b);
expect(a).toEqual({arr: [1, 'second', 3]});
});
it('should not remove items in an array', () => {
const a = {arr: [1, 2, 3]};
const b = {arr: [1, 3]};
Utils.removeInternalAndSame(a, b);
expect(a).toEqual({arr: [1, 2, 3]});
});
it('should remove nested object, and make empty', () => {
const a = {obj1: {first: 1, nested: {second: 2}}, obj2: {first: 1, second: 2}};
const b = {obj1: {first: 1, nested: {second: 2}}, obj2: {first: 1, second: 2}};
Utils.removeInternalAndSame(a, b);
expect(a).toEqual({});
});
it('should remove nested object, and make empty - part 2', () => {
const a = {obj1: {first: 1, nested: {second: 2}}, obj2: {first: 1, second: 2}};
const b = {obj1: {first: 1}, obj2: {first: 1, second: 2}};
Utils.removeInternalAndSame(a, b);
expect(a).toEqual({obj1: {nested: {second: 2}}});
});
});
});
2 changes: 2 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,8 @@ export class Utils {
/** removes field from the first object if same as the second objects (like diffing) and internal '_' for saving */
static removeInternalAndSame(a: unknown, b: unknown):void {
if (typeof a !== 'object' || typeof b !== 'object') return;
// skip arrays as we don't know how to hydrate them (unlike object spread operator)
if (Array.isArray(a) || Array.isArray(b)) return;
for (let key in a) {
const aVal = a[key];
const bVal = b[key];
Expand Down