Skip to content

Commit

Permalink
Added support for pswpModule import without absolute path (#1764)
Browse files Browse the repository at this point in the history
  • Loading branch information
brunogrcsada authored Jun 24, 2021
1 parent 05d7eea commit b669a09
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion dist/photoswipe-lightbox.esm.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions src/js/lightbox/dynamic-import.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
export function dynamicImportModule(module) {
// TODO: polyfill import?
return import(module);
return typeof module === 'string' ? import(module) : module;
}

export function dynamicImportPlugin(pluginKey, pluginItem) {
return new Promise((resolve) => {
if (typeof pluginItem === 'string') {
if(typeof pluginItem === 'string' || typeof pluginItem === 'object'){
dynamicImportModule(pluginItem).then((module) => {
resolve({
pluginKey,
moduleClass: module.default
moduleClass: typeof module === 'string' ? module.default : module
});
}).catch(resolve);
} else {
} else{
resolve();
}
});
}
}
8 changes: 4 additions & 4 deletions src/js/lightbox/lightbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,10 @@ class PhotoSwipeLightbox extends PhotoSwipeBase {
}

// Pass data to PhotoSwipe and open init
const pswp = new module.default( // eslint-disable-line
null,
this.options
);
const pswp = typeof module === "object"
? new module.default(null, this.options) // eslint-disable-line
: new module(null, this.options);

pswp.pluginClasses = this._pluginClasses;

this.pswp = pswp;
Expand Down

0 comments on commit b669a09

Please sign in to comment.