Skip to content

Commit

Permalink
feat(destroy): allow to destroy without DOM element (#163)
Browse files Browse the repository at this point in the history
  • Loading branch information
roman-rr committed Dec 6, 2021
1 parent 6196a4e commit 44a0d18
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 64 deletions.
9 changes: 7 additions & 2 deletions dist/cupertino-pane.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -1561,8 +1561,10 @@ class CupertinoPane {
present(conf = { animate: false }) {
var _a;
return __awaiter(this, void 0, void 0, function* () {
if (!this.el)
if (!this.el || !document.body.contains(this.el)) {
console.warn('Cupertino Pane: specified DOM element must be attached to the DOM');
return;
}
// Pane already exist and was rendered
if (this.isPanePresented() && this.rendered) {
this.moveToBreak(this.settings.initialBreak);
Expand Down Expand Up @@ -1724,6 +1726,7 @@ class CupertinoPane {
this.overflowEl.style.overflowY = (val >= this.breakpoints.bottomer) ? 'auto' : 'hidden';
}
}
// TODO: replace with body.contains()
isPanePresented() {
// Check through all presented panes
let wrappers = Array.from(document.querySelectorAll(`.cupertino-pane-wrapper.rendered`));
Expand Down Expand Up @@ -1904,7 +1907,9 @@ class CupertinoPane {
destroyButton: false
}) {
return __awaiter(this, void 0, void 0, function* () {
if (!this.isPanePresented()) {
// Experimentally allow to destroy, even if not currently in DOM,
// instead of this.isPanePresented() check with rendered (#163 issue)
if (!this.rendered) {
console.warn(`Cupertino Pane: Present pane before call destroy()`);
return null;
}
Expand Down
28 changes: 0 additions & 28 deletions dist/cupertino-pane.esm.min.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/cupertino-pane.esm.min.js.map

This file was deleted.

9 changes: 7 additions & 2 deletions dist/cupertino-pane.js
Original file line number Diff line number Diff line change
Expand Up @@ -1567,8 +1567,10 @@
present(conf = { animate: false }) {
var _a;
return __awaiter(this, void 0, void 0, function* () {
if (!this.el)
if (!this.el || !document.body.contains(this.el)) {
console.warn('Cupertino Pane: specified DOM element must be attached to the DOM');
return;
}
// Pane already exist and was rendered
if (this.isPanePresented() && this.rendered) {
this.moveToBreak(this.settings.initialBreak);
Expand Down Expand Up @@ -1730,6 +1732,7 @@
this.overflowEl.style.overflowY = (val >= this.breakpoints.bottomer) ? 'auto' : 'hidden';
}
}
// TODO: replace with body.contains()
isPanePresented() {
// Check through all presented panes
let wrappers = Array.from(document.querySelectorAll(`.cupertino-pane-wrapper.rendered`));
Expand Down Expand Up @@ -1910,7 +1913,9 @@
destroyButton: false
}) {
return __awaiter(this, void 0, void 0, function* () {
if (!this.isPanePresented()) {
// Experimentally allow to destroy, even if not currently in DOM,
// instead of this.isPanePresented() check with rendered (#163 issue)
if (!this.rendered) {
console.warn(`Cupertino Pane: Present pane before call destroy()`);
return null;
}
Expand Down
28 changes: 0 additions & 28 deletions dist/cupertino-pane.min.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/cupertino-pane.min.js.map

This file was deleted.

10 changes: 8 additions & 2 deletions src/cupertino-pane.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,10 @@ export class CupertinoPane {
}

async present(conf: {animate: boolean} = {animate: false}): Promise<CupertinoPane> {
if (!this.el) return;
if (!this.el || !document.body.contains(this.el)) {
console.warn('Cupertino Pane: specified DOM element must be attached to the DOM');
return;
}

// Pane already exist and was rendered
if (this.isPanePresented() && this.rendered) {
Expand Down Expand Up @@ -429,6 +432,7 @@ export class CupertinoPane {
}
}

// TODO: replace with body.contains()
public isPanePresented():boolean {
// Check through all presented panes
let wrappers = Array.from(document.querySelectorAll(`.cupertino-pane-wrapper.rendered`));
Expand Down Expand Up @@ -686,7 +690,9 @@ export class CupertinoPane {
destroyButton: false
}): Promise<true> {

if (!this.isPanePresented()) {
// Experimentally allow to destroy, even if not currently in DOM,
// instead of this.isPanePresented() check with rendered (#163 issue)
if (!this.rendered) {
console.warn(`Cupertino Pane: Present pane before call destroy()`);
return null;
}
Expand Down

0 comments on commit 44a0d18

Please sign in to comment.