Skip to content

Commit

Permalink
bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
hoseinzadehashraf committed May 27, 2024
1 parent 8cfa45f commit fe2d289
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 18 deletions.
20 changes: 14 additions & 6 deletions dist/bundle-built.js
Original file line number Diff line number Diff line change
Expand Up @@ -37934,7 +37934,7 @@ define('app/masonryGrid',["require", "exports", "jquery"], function (require, ex
this.parent = document.querySelector(this.options.parentSelector);
this.items = !this.parent
? undefined
: this.parent.querySelectorAll(this.options.parentSelector + ' > ' + this.options.itemsSelector);
: Array.from(this.parent.querySelectorAll(this.options.parentSelector + ' > ' + this.options.itemsSelector));
if (!this.parent || !this.items || !this.items.length)
throw "invalid board dom structure";
const o = function (entries) {
Expand All @@ -37943,6 +37943,7 @@ define('app/masonryGrid',["require", "exports", "jquery"], function (require, ex
this.resizeObserver = new ResizeObserver(o);
this.resizeObserver.observe(this.parent);
this.items.forEach(item => this.resizeObserver.observe(item));
this.drawGrid();
}
catch (error) {
console.log(error);
Expand All @@ -37956,6 +37957,7 @@ define('app/masonryGrid',["require", "exports", "jquery"], function (require, ex
this.drawGrid();
}
drawGrid() {
var _a;
if (this.resizeId) {
clearTimeout(this.resizeId);
}
Expand All @@ -37966,10 +37968,16 @@ define('app/masonryGrid',["require", "exports", "jquery"], function (require, ex
const parentWidth = this.parent.clientWidth;
const columnCount = Math.max(Math.floor(parentWidth / this.options.minColumnWidth), 1);
const newItems = this.parent.querySelectorAll(this.options.parentSelector + ' > ' + this.options.itemsSelector);
const newSchematic = this.generateSchematic(columnCount);
if (this.lastSchematic && this.areEqualSchematics(this.lastSchematic, newSchematic))
return;
this.lastSchematic = newSchematic;
if (!newItems.length) {
const newSchematic = this.generateSchematic(columnCount);
if (this.lastSchematic && this.areEqualSchematics(this.lastSchematic, newSchematic))
return;
this.lastSchematic = newSchematic;
}
else {
this.items = Array.from(this.parent.querySelectorAll(this.options.parentSelector + ' > ' + this.options.itemsSelector));
this.lastSchematic = this.generateSchematic(columnCount);
}
this.items.forEach(item => {
if (item.parentElement != this.parent)
this.parent.appendChild(item);
Expand All @@ -37987,7 +37995,7 @@ define('app/masonryGrid',["require", "exports", "jquery"], function (require, ex
}
}
newItems.forEach(item => this.resizeObserver.observe(item));
}.bind(this), 500);
}.bind(this), (_a = this.options.redrawInterval) !== null && _a !== void 0 ? _a : 100);
}
areEqualSchematics(a, b) {
return JSON.stringify(a) === JSON.stringify(b);
Expand Down
2 changes: 1 addition & 1 deletion dist/bundle-built.min.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion dist/types/hub/masonryGrid.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ export interface MasonaryOptions {
minColumnWidth: number;
parentSelector: string;
itemsSelector: string;
redrawInterval: number;
}
export default class MasonryGrid {
options: MasonaryOptions;
parent: HTMLElement;
items: NodeListOf<Element>;
items: Element[];
resizeObserver: ResizeObserver;
resizeId: number | undefined;
lastSchematic: Array<Array<number>>;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"url": "git://github.com/Geeksltd/Olive.Microservices.HubJs.git"
},
"author": "Geeks Ltd",
"version": "4.2.68",
"version": "4.2.69",
"license": "GPL-3.0",
"private": false,
"files": [
Expand Down
24 changes: 15 additions & 9 deletions src/masonryGrid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ export interface MasonaryOptions {
minColumnWidth: number
parentSelector: string
itemsSelector: string
redrawInterval: number
}

export default class MasonryGrid {
options: MasonaryOptions;
parent: HTMLElement;
items: NodeListOf<Element>;
items: Element[];
resizeObserver: ResizeObserver;
resizeId: number | undefined;
lastSchematic: Array<Array<number>> = [[]];
Expand All @@ -24,7 +25,7 @@ export default class MasonryGrid {
this.parent = document.querySelector<HTMLElement>(this.options.parentSelector);
this.items = !this.parent
? undefined
: this.parent.querySelectorAll(this.options.parentSelector + ' > ' + this.options.itemsSelector);
: Array.from(this.parent.querySelectorAll(this.options.parentSelector + ' > ' + this.options.itemsSelector));

if (!this.parent || !this.items || !this.items.length) throw "invalid board dom structure";

Expand All @@ -35,6 +36,8 @@ export default class MasonryGrid {

this.resizeObserver.observe(this.parent);
this.items.forEach(item => this.resizeObserver.observe(item));

this.drawGrid();
} catch (error) {
console.log(error);
setTimeout(() => {
Expand Down Expand Up @@ -63,12 +66,15 @@ export default class MasonryGrid {

const newItems = this.parent.querySelectorAll(this.options.parentSelector + ' > ' + this.options.itemsSelector);

const newSchematic = this.generateSchematic(columnCount);

if (this.lastSchematic && this.areEqualSchematics(this.lastSchematic, newSchematic))
return;

this.lastSchematic = newSchematic;
if (!newItems.length) {
const newSchematic = this.generateSchematic(columnCount);
if (this.lastSchematic && this.areEqualSchematics(this.lastSchematic, newSchematic))
return;
this.lastSchematic = newSchematic;
} else {
this.items = Array.from(this.parent.querySelectorAll(this.options.parentSelector + ' > ' + this.options.itemsSelector));
this.lastSchematic = this.generateSchematic(columnCount);
}

this.items.forEach(item => {
if (item.parentElement != this.parent)
Expand All @@ -91,7 +97,7 @@ export default class MasonryGrid {
}

newItems.forEach(item => this.resizeObserver.observe(item));
}.bind(this), 500);
}.bind(this), this.options.redrawInterval ?? 100);
}

areEqualSchematics(a, b) {
Expand Down

0 comments on commit fe2d289

Please sign in to comment.