Problem/Motivation
A version 5 of the JS library is currently in Beta https://github.com/dimsemenov/photoswipe/tree/v5-beta. It is designed around ESM so that it can import natively in browsers.
Proposed resolution
Create a release (separate branch) that moves to using this modern version 5 code.
Remaining tasks
Figure out the best way to handle ESM. For example, should the init js file be the one to directly import the main library?
API changes
The new library is a complete rewrite.
Data model changes
The configuration options for the library are likely different and will need to be update with possibly a migration path.
Comments
Comment #3
segovia94 commentedI created an initial proof of concept to get the ball rolling, and it works! The biggest decision will be around how to include the main library since it now would be as an ESM import. I'm not sure that there is currently a best practice for this in Drupal that I'm aware of.
Comment #4
anybodyVery cool, thank you @segovia94 for pointing this out. Long term I could imagine to support this in a separate 5.x branch when it's stable and provides all known functionality from the old release.
Regarding the esm standard I think it's more a browser compatibility problem, I guess.
Comment #5
anybodyNo activity in the repo since Oct. 2021.
Comment #6
anybodyThank you very much, very cool and I'm highly interested. We should then do this in a separate 5.x branch.
Regarding the ESM support, please look for core issues or implementation to link. I'd like to postpone this until there's a clear best practice documented / linked.
Comment #7
dariemlazaroI have the same problem. I solved this using a previous version 4.1.3. Please specify this version requirement in the documentation for avoiding head pains for other developers. Thanks for your work.
Comment #8
anybody@dariemlanzaro, see the module page:
Comment #9
anybodyAS PS5 is out now for a serious amount of time and will make things easier and better, I'll create a 5,x branch based on the MR from @segovia94. See #3301314: [5.x] Create a (7.x-)4.x branch (from (7.x-)3.x) for PS4 and a 5.x for PS5 for the plan.
Comment #10
anybodyOk before we do this, the MR should be rerolled.
Comment #11
segovia94 commentedMy concern in #3 about using ESM isn't so much about browsers but instead about how drupal has traditionally used
libraries.ymlfiles to manage css/js files and include them on the page. photoswipe.js imports the v5 library directly and does not concern itself at all with Drupal. So a photoswipe_library_info_alter() can't alter or touch these files.I personally haven't heard of how the drupal community is planning on handling esm in the future.
Comment #12
segovia94 commentedI suppose that using import maps would be the way to go once browsers fully support them.
Comment #13
grevil commented[UNRELATED]
I have to agree with @dariemlazaro in #7, even though we define the used photoswipe version on the module page, the manual and composer installation guides, point to the photoswipe 5 branch.
I updated the module page for more clearly instructions.
Comment #14
segovia94 commentedAh, they now offer a umd build. Perhaps I'll switch the code over to keep things standardized with how drupal works.
Comment #15
anybodyGood idea @segovia94. Please also have a look if the umd build is available via CDN (having a look at the current module CDN implementation / source). That would be important for making this decision.
Comment #16
Wiktor7 commentedPhotoSwipe 3.2.2 libraries 5.3.3
Comment #17
trickfun commentedI get this error:
drupal 9.5.1-beta
thank you
Comment #18
dinazaur commentedComment #19
dinazaur commentedHello.
So, it's ready for review. What was done:
1. I've removed/adjusted obsolete configuration options. And added new ones for the Caption plugin. Check photoswipe_update_9001.
2. Implemented the ability to use the Caption plugin.
3. Fixed all tests.
4. Replaced esm photoswipe library with umd as suggested in #14
The only problem that remains is Caption plugin, I didn't manage to find CDN with UMD (it exists in the repository), So I used ESM for this plugin. And if someone will want to replace it will local library, it is impossible for now. For this, we will need to add another dependency that users will need to download with the composer.
P.S. I forgot how to run tests in MR, can someone execute them?Nevermind, foundComment #20
dinazaur commentedComment #21
elamanMR has conflicts, can't be merged
Comment #22
pyrello commentedI'm not seeing any merge conflicts with the MR currently. Setting back to "Needs review"
Comment #23
vlad.dancer@dinazaur looks great!
Tested manually upgrading from 3.x and no issues found.
Note: I found cdn link with umd version for caption here unpkg.com/photoswipe-dynamic-caption-plugin@1.2.7. Looks like umd version was added into 1.2.7 release.
Comment #24
vlad.dancer@elaman, I can't also apply patch by using patch link (....14.patch), so I've changed url to use .diff instead and now apllied as expected
Comment #25
elaman@vlad.dancer thank you. The MR works, so +1 on RTBC
Comment #26
grevil commentedComment #31
grevil commentedComment #32
grevil commentedThanks, everyone, for your immense work on this issue!! 🤩
I made a few comments in code, this looks a lot, but it is mainly about moving the dynamic captions part into its own submodule 🙂. I also tried getting around rebasing everything again. Unfortunately, this wasn't possible.
Comment #33
grevil commentedUnfortunately, we currently don't have much time to implement anything by ourselves. But I hope my comments will lead in the right direction!
Comment #34
dinazaur commentedComment #35
dinazaur commentedHello, since that's not my PR I cannot mark discussions as resolved. Could someone clean up discussions there?
Comment #36
vlad.dancer@dinazaur
Wow
Wow! You are reading my mind! Awesome!
Will check new PR today.
--
Oh, I got you, this is for photoswipe_caption.js but could be useful for extending galleries in custom modules (for example adding configuration functions for zoom level, etc).
Right now I'm just altering photoswipe library definition and replacing with custom implementation.
But could do using events having the same event for caption plugin to put counter inside caption region:
new CustomEvent('photoswipeDynamicCaptionBuild', {detail: caption});What do you think?
Comment #37
dinazaur commentedHi @vlad.dancer,
I'm not sure how to alter option with your solution:
new CustomEvent('photoswipeDynamicCaptionBuild', {detail: caption});There is no documentation of how to do it, and there is no "source" code to check what's going on under the hood. Only minified versions.
Another way would be to pass options instead of the caption instance itself. E.g.
new CustomEvent('photoswipeDynamicCaptionOptions', {detail: captionOptions});That would be good for users who want to alter individual photoswipe instances. In that case, we will also need to add same event for photoswipe options too.
But even now you can alter them. You just need to make sure that your script is initialized before our and alter drupal settings. You can pass any options and they will override ours.
As you can see we merge options from settings, so captionContent will be overridden if you will pass your custom callback there.
Comment #38
grevil commentedImmense work @dinazaur! 😯
I overflew the changes, commented and resolved remaining threads!
@vlad.dancer feel free, to create a separate follow-up issue for your feature request in #36!
There are still a few points we need to resolve:
But once again, impressive work! Let's keep this going! :)
Comment #39
anybodyThanks, just one addition:
A checkbox wouldn't be good UX for this, better use radio or select. But yes, please explicitly, because of the GDPR risks, if fallback is used.
Comment #42
dinazaur commentedI don't have permission to run tests on current MR, tried to create separate branch and open new PR, but even there I don't have permission. So attaching patch here, to check if tests are running correctly.
Comment #43
dinazaur commentedComment #44
dinazaur commentedComment #45
dinazaur commentedComment #47
dinazaur commentedComment #48
dinazaur commentedComment #49
dinazaur commentedComment #50
dinazaur commentedComment #51
grevil commentedMy apologies! Automated testing was disabled for the newly created 5.x branch!
Comment #52
grevil commentedIt's activated now, might take a bit though.
Comment #53
dinazaur commentedComment #54
dinazaur commentedNice, finally I managed to fix these tests 😅. What I implement is the ability to install photoswipe library locally inside Drupal CI environment. So we will make sure that composer installation is working fine. I changed all tests to use local library. And implemented one test that checks if CDN works fine.
Done
For this I think we can wait until more people will mark it as RTBC
Same as the previous point.
I guess it is fine enough. Also with new reworking tests, we are sure that locally installed library is working correctly.
Comment #55
grevil commentedWow, that is wild @dinazaur!! Thanks a lot!
Comment #56
grevil commentedChanges are looking good! Still need to test it manually, in my local environment, when there is time, but just going over the changes everything looks very impressive! Great work! 🙂
LGTM!
(Letting this on "Needs Review" for other people to test this).
Comment #57
anybodyThis please needs to be incorporated to not reintroduce that issue in 5.x: #3371315: Photoswipe library definition license is missing URL
Comment #58
elamanI've added the Licence, as @Anybody asked. I've tested it on our website, marking it as RTBC. Thank you!
Comment #59
grevil commentedComment #60
grevil commentedNew Status Report Warnings:


and
Comment #61
anybodyThanks @Grevil, nice work! I'd suggest to remove the 2nd. CDN simply shouldn't be enabled by default, then it's all fine with the first error message!
Please simplify the first line of the error to: "Photoswipe library not found, CDN disabled" that should be enough.
Comment #62
grevil commentedAight!
Comment #63
grevil commentedAlright, the code and texts are cleaned up now! The final task will be, to move the Photoswipe field formatter caption settings into the newly added submodule!
This includes:
from "PhotoswipeFieldFormatter", which should be (probably) added through formatter third party settings, using:
https://api.drupal.org/api/drupal/core%21modules%21field_ui%21field_ui.a...
and
https://api.drupal.org/api/drupal/core!modules!field_ui!field_ui.api.php....
And "getCaption()" from the "PhotoswipePreprocessProcessor", which should get encapsulated into a submodule service.
I'll finish this tommorow!
Edit: We should also rename "photoswipe_caption" to "photoswipe_dynamic_caption", similiar to the plugin name.
Comment #64
dinazaur commentedBy the way, if we don't want to break compatibility I suggest not disabling CDN by default or leaving a clear warning on the new release that users who had not installed the library locally will have photoswipe broken.
Comment #65
grevil commented@dinazaur, good call with the warning!
We definitely need to create a clear warning in the update hook, stating that the user needs to upgrade their photoswipe version to version 5, if they have installed the library locally OR enable CDN. But I'd vote against enabling it on update due to the before mentioned GDPR reasons.
Comment #66
thomas.frobieter+1 on this point, the legal thing seems to be the more important thing.
Composer does not update the library automatically?
Comment #67
anybody@thomas.frobieter: No that's not possible, as it's an asset-packagist library and Drupal core doesn't know that repo. So it's always the administrator job to add it, if needed. Sadly, but there are reasons...
Comment #68
grevil commentedOk, last commit was quite a big one! Requesting partial review by @Anybody, afterward back to "Needs work" for final cleanup and testing.
Please review: https://git.drupalcode.org/project/photoswipe/-/merge_requests/14/diffs?...
Comment #69
anybodyBack to NW, left some comments, but don't have the time for a full review in the next months. Please test with the communities help. And release very carefully!
@Grevil do you want to fix the comments or will @dinazaur help perhaps?
Comment #70
grevil commentedAlright, all done! Further partial review please and afterward, I'll do some manual testing and we should be able to make an alpha1 release!
PS: I am still not sure about the drupalci.yml, as it could lead to unexpected test failure in the future, and already leads to different test output locally! Hence, I'd say we just plainly enable CDN for all tests (as before, using the "cdn as fallback" method) and be done with it.
Comment #71
anybodyAgree! drupalci.yml should be done in a separate issue anyway.
Let's tag an alpha1 and do a LOT of testing!
Please also add version information to the module page. 5.x should NOT be used in production, but please be tested a lot! alpha state!
Comment #72
anybodyThank you all! Especially @dinazaur and @Grevil for all the work done here! Fabulous!!
Comment #73
grevil commentedAlright! I tested the module and its formatter settings extensively, as well as the upgrade path. All seems to work flawlessly! :)
Big thanks to @dinazaur, for the amazing and vast groundwork, to make this module compatible with Photoswipe 5! Really appreciating your work done here!
I think this is ready for an alpha1 release!
Comment #74
grevil commentedAll Green! Let's do it! 🤹♂️