Ok so with NC31 it happened: the OC.dialogs API isn’t deprecated any more, but removed, with @nextcloud.dialogs as suggested replacement. Looking back at the primary design consideration in https://github.com/nextcloud/server/issues/15932#issuecomment-501194731, “those yolo apps can still use the legacy API”, which obviously isn’t the case any more.
Has there been any discussion or workaround for this issue in the meantime, or am I supposed to re-implement the whole app (or implement a wrapper package that exports what I need)?
What app are you referring to?
Generally, the @ nextcloud/dialogs library should be quite compatible. So, it would mainly mean to migrate from plain JS to something like Webpack or Vite to install dependencies and build an asset.
To be honest, this thread is 6 years old and I guess no one had this anymore in mind. I have not read anything about it.
Chris
I’m wondering if there’s any way NOT to migrate to webpack, staying on plain JS.
What is the point of it? If you have valid reason to avoid Webpack & Co, it might be interesting to hear them. Otherwise, they simply allow you to enhance your code to e.g. minify and polyfill your code. So, is it only the setup issue or is there more to it?
Discussing my reasons to avoid webpack isn’t the topic of this thread, and it wouldn’t help either.
OK, this is your opinion. I will step down in this topic and let you ask your questions in case anyone here is willing to help. Good luck!
So let’s see how this helps answering my question: I don’t want to change my deployment style since it wouldn’t give me any benefit.
Or if you like the question asked another way: Why aren’t the libraries exported to make them widely available? Has this been overlooked, with chances of timely implementation, or is this a willful decision?
Honestly just use vite, its not hard and migrating your app to it will take like an hour, but if you insist: It is absolutely (inofficially!) possible to use @nextcloud/dialogs in plain JS.
Public global variables/APIs in the nextcloud frontend are loosing their relevance, as they are versioned with the server, which means apps need to adapt to potential breaking API changes, before enabling support for new server versions. APIs packaged with the app allow independent versioning for every app, allowing them to upgrade at their own pace, allowing for faster compatibility for newer NC server versions.
So how do you use it in plain JS ?
You can use any ES Module without using a bundler like Vite or Webpack in plain JS, because JS has had native module support for many years!
If the package does not have any dependencies you just need to use an import statement with an URL where the .mjs file is hosted (the easiest option for this would be jsdelivr).
Nextcloud dialogs has dependencies (most importantly vue for the file browser), so you do need those bundeled in (because the browser cannot resolve import statements like import NcDialog from "@nextcloud/vue/components/NcDialog";), but that does not mean you have to be the one to bundle it, jsdelivr will happily do that for you (“/+esm”).
I wrote the following small snippet that works in Dev Tools, so you can test it easily:
const NcDialogs = await import('https://cdn.jsdelivr.net/npm/@nextcloud/dialogs@6.3.1/+esm');
NcDialogs.showInfo("test");
To integrate this into your app you don’t want to use a dynamic import(), but a static import from and the script from which it is called needs to be of type module (<script type="module">).
But still, just use vite.
Thanks @TessyPowder for your helpful posting!
jsdelivr seems just what I need. I was kind of stuck with *.mjs module-scripts not supporting import xx from @nextcloud/dialogs
Regards, Andreas
The premise of this question confuses me. My application is still using OC.dialogs and it’s working fine on NC 31.0.0rc3, NC 31.0.8, and NC 32.0.0rc1. Nor is there anything mentioned about the removal of OC.dialogs in Upgrade to Nextcloud 31 — Nextcloud latest Developer Manual latest documentation.
Yes, OC.dialogs isn’t fully removed, but OC.dialogs.fileexists is which hit me lately.