@vite-pwa/nuxt 0.3.3 → 0.3.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,6 @@
1
1
  declare module 'virtual:nuxt-pwa-configuration' {
2
2
  export const enabled: boolean
3
+ export const display: 'fullscreen' | 'standalone' | 'minimal-ui' | 'browser'
3
4
  export const installPrompt: string | undefined
4
5
  export const periodicSyncForUpdates: number
5
6
  }
package/dist/module.json CHANGED
@@ -5,5 +5,5 @@
5
5
  "nuxt": "^3.6.5",
6
6
  "bridge": false
7
7
  },
8
- "version": "0.3.3"
8
+ "version": "0.3.5"
9
9
  }
package/dist/module.mjs CHANGED
@@ -4,7 +4,7 @@ import { defineNuxtModule, createResolver, getNuxtVersion, addPlugin, addCompone
4
4
  import { VitePWA } from 'vite-plugin-pwa';
5
5
  import { resolve } from 'pathe';
6
6
 
7
- const version = "0.3.3";
7
+ const version = "0.3.5";
8
8
 
9
9
  function configurePWAOptions(nuxt3_8, options, nuxt, nitroConfig) {
10
10
  if (!options.outDir) {
@@ -128,11 +128,6 @@ const module = defineNuxtModule({
128
128
  src: resolver.resolve(runtimeDir, "plugins/pwa.client"),
129
129
  mode: "client"
130
130
  });
131
- } else {
132
- addPlugin({
133
- src: resolver.resolve(runtimeDir, "plugins/pwa.client.stub"),
134
- mode: "client"
135
- });
136
131
  }
137
132
  await Promise.all([
138
133
  addComponent({
@@ -145,8 +140,7 @@ const module = defineNuxtModule({
145
140
  })
146
141
  ]);
147
142
  nuxt.hook("prepare:types", ({ references }) => {
148
- const types = resolver.resolve(runtimeDir, "plugins/types");
149
- references.push({ path: resolver.resolve(nuxt.options.buildDir, types) });
143
+ references.push({ path: resolver.resolve(runtimeDir, "plugins/types") });
150
144
  references.push({ types: "@vite-pwa/nuxt/configuration" });
151
145
  references.push({ types: "vite-plugin-pwa/vue" });
152
146
  references.push({ types: "vite-plugin-pwa/info" });
@@ -198,8 +192,10 @@ const module = defineNuxtModule({
198
192
  },
199
193
  load(id) {
200
194
  if (id === resolvedConfiguration) {
195
+ const display = typeof options.manifest !== "boolean" ? options.manifest?.display ?? "standalone" : "standalone";
201
196
  const installPrompt = typeof client.installPrompt === "undefined" || client.installPrompt === false ? void 0 : client.installPrompt === true || client.installPrompt.trim() === "" ? "vite-pwa:hide-install" : client.installPrompt.trim();
202
197
  return `export const enabled = ${client.registerPlugin}
198
+ export const display = '${display}'
203
199
  export const installPrompt = ${JSON.stringify(installPrompt)}
204
200
  export const periodicSyncForUpdates = ${typeof client.periodicSyncForUpdates === "number" ? client.periodicSyncForUpdates : 0}
205
201
  `;
@@ -1,6 +1,6 @@
1
1
  import { nextTick, reactive, ref } from "vue";
2
2
  import { useRegisterSW } from "virtual:pwa-register/vue";
3
- import { installPrompt, periodicSyncForUpdates } from "virtual:nuxt-pwa-configuration";
3
+ import { display, installPrompt, periodicSyncForUpdates } from "virtual:nuxt-pwa-configuration";
4
4
  import { defineNuxtPlugin } from "#imports";
5
5
  const plugin = defineNuxtPlugin(() => {
6
6
  const registrationError = ref(false);
@@ -9,8 +9,14 @@ const plugin = defineNuxtPlugin(() => {
9
9
  const hideInstall = ref(!installPrompt ? true : localStorage.getItem(installPrompt) === "true");
10
10
  const ua = navigator.userAgent;
11
11
  const ios = ua.match(/iPhone|iPad|iPod/);
12
- const standalone = window.matchMedia("(display-mode: standalone)").matches;
13
- const isInstalled = !!(standalone || ios && !ua.match(/Safari/));
12
+ const useDisplay = display === "standalone" || display === "minimal-ui" ? `${display}` : "standalone";
13
+ const standalone = window.matchMedia(`(display-mode: ${useDisplay})`).matches;
14
+ const isInstalled = ref(!!(standalone || ios && !ua.match(/Safari/)));
15
+ const isPWAInstalled = ref(isInstalled.value);
16
+ window.matchMedia(`(display-mode: ${useDisplay})`).addEventListener("change", (e) => {
17
+ if (!isPWAInstalled.value && e.matches)
18
+ isPWAInstalled.value = true;
19
+ });
14
20
  let swRegistration;
15
21
  const getSWRegistration = () => swRegistration;
16
22
  const registerPeriodicSync = (swUrl, r, timeout) => {
@@ -96,6 +102,7 @@ const plugin = defineNuxtPlugin(() => {
96
102
  provide: {
97
103
  pwa: reactive({
98
104
  isInstalled,
105
+ isPWAInstalled,
99
106
  showInstallPrompt,
100
107
  cancelInstall,
101
108
  install,
@@ -2,7 +2,11 @@ import type { Ref } from 'vue'
2
2
  import type { UnwrapNestedRefs } from 'vue'
3
3
 
4
4
  export interface PwaInjection {
5
+ /**
6
+ * @deprecated use `isPWAInstalled` instead
7
+ */
5
8
  isInstalled: boolean
9
+ isPWAInstalled: Ref<boolean>
6
10
  showInstallPrompt: Ref<boolean>
7
11
  cancelInstall: () => void
8
12
  install: () => Promise<void>
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vite-pwa/nuxt",
3
3
  "type": "module",
4
- "version": "0.3.3",
4
+ "version": "0.3.5",
5
5
  "packageManager": "pnpm@8.11.0",
6
6
  "description": "Zero-config PWA for Nuxt 3",
7
7
  "author": "antfu <anthonyfu117@hotmail.com>",
@@ -43,7 +43,7 @@
43
43
  "dev:generate:netlify": "NITRO_PRESET=netlify nuxi generate playground",
44
44
  "dev:generate:vercel": "NITRO_PRESET=vercel nuxi generate playground",
45
45
  "dev:build": "nuxi build playground",
46
- "dev:prepare": "nuxt-module-build --stub && nuxt-module-build prepare && nuxi prepare playground",
46
+ "dev:prepare": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxi prepare playground",
47
47
  "dev:preview:build": "nr dev:build && node playground/.output/server/index.mjs",
48
48
  "dev:preview:generate": "nr dev:generate && serve playground/dist",
49
49
  "release": "bumpp && npm publish",
@@ -97,4 +97,4 @@
97
97
  "stackblitz": {
98
98
  "startCommand": "nr prepack && nr dev:prepare && nr dev"
99
99
  }
100
- }
100
+ }
@@ -1,7 +0,0 @@
1
- import type { UnwrapNestedRefs } from 'vue';
2
- import type { PwaInjection } from './types';
3
- import type { Plugin } from '#app';
4
- declare const plugin: Plugin<{
5
- pwa?: UnwrapNestedRefs<PwaInjection>;
6
- }>;
7
- export default plugin;
@@ -1,9 +0,0 @@
1
- import { defineNuxtPlugin } from "#imports";
2
- const plugin = defineNuxtPlugin(() => {
3
- return {
4
- provide: {
5
- pwa: void 0
6
- }
7
- };
8
- });
9
- export default plugin;