@depup/nuxt 4.3.0-depup.0 → 4.4.2-depup.1

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.
Files changed (59) hide show
  1. package/README.md +24 -107
  2. package/dist/app/components/nuxt-announcer.d.ts +26 -0
  3. package/dist/app/components/nuxt-announcer.js +59 -0
  4. package/dist/app/components/nuxt-island.js +7 -1
  5. package/dist/app/components/nuxt-layout.js +44 -21
  6. package/dist/app/components/nuxt-link.js +29 -15
  7. package/dist/app/components/nuxt-root.vue +1 -1
  8. package/dist/app/components/nuxt-route-announcer.js +11 -2
  9. package/dist/app/components/nuxt-time.vue +13 -2
  10. package/dist/app/components/test-component-wrapper.js +10 -2
  11. package/dist/app/components/utils.d.ts +7 -1
  12. package/dist/app/components/utils.js +18 -0
  13. package/dist/app/components/welcome.vue +1 -1
  14. package/dist/app/composables/announcer.d.ts +23 -0
  15. package/dist/app/composables/announcer.js +47 -0
  16. package/dist/app/composables/asyncData.d.ts +18 -36
  17. package/dist/app/composables/asyncData.js +214 -186
  18. package/dist/app/composables/chunk.js +1 -2
  19. package/dist/app/composables/cookie.d.ts +14 -0
  20. package/dist/app/composables/cookie.js +66 -17
  21. package/dist/app/composables/error.d.ts +2 -2
  22. package/dist/app/composables/error.js +11 -1
  23. package/dist/app/composables/fetch.d.ts +11 -16
  24. package/dist/app/composables/fetch.js +79 -76
  25. package/dist/app/composables/index.d.ts +2 -0
  26. package/dist/app/composables/index.js +1 -0
  27. package/dist/app/composables/manifest.d.ts +1 -1
  28. package/dist/app/composables/manifest.js +1 -4
  29. package/dist/app/composables/pages.d.ts +2 -0
  30. package/dist/app/composables/pages.js +1 -0
  31. package/dist/app/composables/payload.js +14 -5
  32. package/dist/app/composables/preload.js +1 -1
  33. package/dist/app/composables/route-announcer.d.ts +2 -2
  34. package/dist/app/composables/route-announcer.js +6 -6
  35. package/dist/app/composables/router.d.ts +7 -0
  36. package/dist/app/composables/router.js +8 -3
  37. package/dist/app/composables/ssr.d.ts +1 -1
  38. package/dist/app/composables/ssr.js +1 -1
  39. package/dist/app/composables/state.d.ts +11 -1
  40. package/dist/app/composables/state.js +11 -2
  41. package/dist/app/composables/url.d.ts +1 -1
  42. package/dist/app/composables/url.js +1 -1
  43. package/dist/app/config.d.ts +1 -2
  44. package/dist/app/index.d.ts +2 -2
  45. package/dist/app/index.js +1 -1
  46. package/dist/app/nuxt.d.ts +46 -31
  47. package/dist/app/nuxt.js +6 -2
  48. package/dist/app/plugins/restore-state.client.js +1 -2
  49. package/dist/app/plugins/revive-payload.client.js +9 -3
  50. package/dist/app/plugins/router.js +2 -2
  51. package/dist/app/plugins/view-transitions.client.js +39 -4
  52. package/dist/compiler/runtime/index.d.ts +14 -0
  53. package/dist/compiler/runtime/index.js +14 -0
  54. package/dist/index.mjs +2592 -1365
  55. package/dist/pages/runtime/page.js +11 -21
  56. package/dist/pages/runtime/plugins/router.js +20 -8
  57. package/dist/pages/runtime/router.options.js +12 -6
  58. package/meta.js +2 -1
  59. package/package.json +77 -37
@@ -3,7 +3,7 @@ import type { RouteLocationNormalizedLoaded } from 'vue-router';
3
3
  import type { Hookable } from 'hookable';
4
4
  import type { UseContext } from 'unctx';
5
5
  import type { SSRContext, createRenderer } from 'vue-bundle-renderer/runtime';
6
- import type { EventHandlerRequest, H3Event } from 'h3';
6
+ import type { EventHandlerRequest, H3Event } from '@nuxt/nitro-server/h3';
7
7
  import type { RenderResponse } from 'nitropack/types';
8
8
  import type { LogObject } from 'consola';
9
9
  import type { VueHeadClient } from '@unhead/vue/types';
@@ -15,6 +15,7 @@ import type { AsyncDataExecuteOptions, AsyncDataRequestStatus, DebouncedReturn }
15
15
  import type { NuxtAppManifestMeta } from './composables/manifest.js';
16
16
  import type { LoadingIndicator } from './composables/loading-indicator.js';
17
17
  import type { RouteAnnouncer } from './composables/route-announcer.js';
18
+ import type { NuxtAnnouncer } from './composables/announcer.js';
18
19
  import type { AppConfig, AppConfigInput, RuntimeConfig } from 'nuxt/schema';
19
20
  export declare function getNuxtAppCtx(id?: string): UseContext<NuxtApp>;
20
21
  type HookResult = Promise<void> | void;
@@ -90,25 +91,26 @@ export interface NuxtPayload {
90
91
  [key: string]: unknown;
91
92
  }
92
93
  interface _NuxtApp {
93
- vueApp: App<Element>;
94
- versions: Record<string, string>;
95
- hooks: Hookable<RuntimeNuxtHooks>;
96
- hook: _NuxtApp['hooks']['hook'];
97
- callHook: _NuxtApp['hooks']['callHook'];
98
- runWithContext: <T extends () => any>(fn: T) => ReturnType<T> | Promise<Awaited<ReturnType<T>>>;
94
+ 'vueApp': App<Element>;
95
+ 'versions': Record<string, string>;
96
+ 'hooks': Hookable<RuntimeNuxtHooks>;
97
+ 'hook': _NuxtApp['hooks']['hook'];
98
+ 'callHook': _NuxtApp['hooks']['callHook'];
99
+ 'runWithContext': <T extends () => any>(fn: T) => ReturnType<T> | Promise<Awaited<ReturnType<T>>>;
99
100
  [key: string]: unknown;
100
101
  /** @internal */
101
- _cookies?: Record<string, unknown>;
102
+ '_cookies'?: Record<string, unknown>;
103
+ '_cookiesChanged'?: Record<string, boolean>;
102
104
  /**
103
105
  * The id of the Nuxt application.
104
106
  * @internal */
105
- _id: string;
107
+ '_id': string;
106
108
  /** @internal */
107
- _scope: EffectScope;
109
+ '_scope': EffectScope;
108
110
  /** @internal */
109
- _asyncDataPromises: Record<string, Promise<any> | undefined>;
111
+ '_asyncDataPromises': Record<string, Promise<any> | undefined>;
110
112
  /** @internal */
111
- _asyncData: Record<string, {
113
+ '_asyncData': Record<string, {
112
114
  data: Ref<unknown>;
113
115
  pending: Ref<boolean>;
114
116
  error: Ref<Error | undefined>;
@@ -130,47 +132,60 @@ interface _NuxtApp {
130
132
  _abortController?: AbortController;
131
133
  } | undefined>;
132
134
  /** @internal */
133
- _loadingIndicator?: LoadingIndicator;
135
+ '_state': Record<string, {
136
+ /** @internal */
137
+ _default: () => unknown;
138
+ } | undefined>;
139
+ /** @internal */
140
+ '_loadingIndicator'?: LoadingIndicator;
134
141
  /** @internal */
135
- _loadingIndicatorDeps?: number;
142
+ '_loadingIndicatorDeps'?: number;
136
143
  /** @internal */
137
- _middleware: {
144
+ '_middleware': {
138
145
  global: RouteMiddleware[];
139
146
  named: Record<string, RouteMiddleware>;
140
147
  };
141
148
  /** @internal */
142
- _processingMiddleware?: string | boolean;
149
+ '_processingMiddleware'?: string | boolean;
143
150
  /** @internal */
144
- _once: {
151
+ '_once': {
145
152
  [key: string]: Promise<any>;
146
153
  };
147
154
  /** @internal */
148
- _observer?: {
155
+ '_observer'?: {
149
156
  observe: (element: Element, callback: () => void) => () => void;
150
157
  };
151
158
  /** @internal */
152
- _appConfig: AppConfig;
159
+ '_appConfig': AppConfig;
153
160
  /** @internal */
154
- _route: RouteLocationNormalizedLoaded & {
161
+ '_route': RouteLocationNormalizedLoaded & {
155
162
  sync?: () => void;
156
163
  };
157
164
  /** @internal */
158
- _islandPromises?: Record<string, Promise<any>>;
165
+ '_islandPromises'?: Record<string, Promise<any>>;
166
+ /** @internal */
167
+ '_payloadRevivers': Record<string, (data: any) => any>;
168
+ /** @internal */
169
+ '_routeAnnouncer'?: RouteAnnouncer;
170
+ /** @internal */
171
+ '_routeAnnouncerDeps'?: number;
172
+ /** @internal */
173
+ '~transitionPromise'?: Promise<void>;
159
174
  /** @internal */
160
- _payloadRevivers: Record<string, (data: any) => any>;
175
+ '~transitionFinish'?: () => void;
161
176
  /** @internal */
162
- _routeAnnouncer?: RouteAnnouncer;
177
+ '_announcer'?: NuxtAnnouncer;
163
178
  /** @internal */
164
- _routeAnnouncerDeps?: number;
165
- $config: RuntimeConfig;
166
- isHydrating?: boolean;
167
- deferHydration: () => () => void | Promise<void>;
168
- ssrContext?: NuxtSSRContext;
169
- payload: NuxtPayload;
170
- static: {
179
+ '_announcerDeps'?: number;
180
+ '$config': RuntimeConfig;
181
+ 'isHydrating'?: boolean;
182
+ 'deferHydration': () => () => void | Promise<void>;
183
+ 'ssrContext'?: NuxtSSRContext;
184
+ 'payload': NuxtPayload;
185
+ 'static': {
171
186
  data: Record<string, any>;
172
187
  };
173
- provide: (name: string, value: any) => void;
188
+ 'provide': (name: string, value: any) => void;
174
189
  }
175
190
  export interface NuxtApp extends _NuxtApp {
176
191
  }
package/dist/app/nuxt.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { effectScope, getCurrentInstance, getCurrentScope, hasInjectionContext, reactive, shallowReactive } from "vue";
2
2
  import { createHooks } from "hookable";
3
3
  import { getContext } from "unctx";
4
- import { appId, chunkErrorEvent, multiApp } from "#build/nuxt.config.mjs";
4
+ import { appId, asyncCallHook, chunkErrorEvent, multiApp } from "#build/nuxt.config.mjs";
5
5
  export function getNuxtAppCtx(id = appId || "nuxt-app") {
6
6
  return getContext(id, {
7
7
  asyncContext: !!__NUXT_ASYNC_CONTEXT__ && import.meta.server
@@ -60,6 +60,7 @@ export function createNuxtApp(options) {
60
60
  },
61
61
  _asyncDataPromises: {},
62
62
  _asyncData: shallowReactive({}),
63
+ _state: shallowReactive({}),
63
64
  _payloadRevivers: {},
64
65
  ...options
65
66
  };
@@ -99,7 +100,10 @@ export function createNuxtApp(options) {
99
100
  await nuxtApp.runWithContext(() => hook(...args));
100
101
  }
101
102
  };
102
- nuxtApp.hooks.callHook = (name, ...args) => nuxtApp.hooks.callHookWith(contextCaller, name, ...args);
103
+ nuxtApp.hooks.callHook = (name, ...args) => nuxtApp.hooks.callHookWith(contextCaller, name, args);
104
+ } else if (asyncCallHook) {
105
+ const _callHook = nuxtApp.hooks.callHook;
106
+ nuxtApp.hooks.callHook = (name, ...args) => Promise.resolve().then(() => _callHook(name, ...args));
103
107
  }
104
108
  nuxtApp.callHook = nuxtApp.hooks.callHook;
105
109
  nuxtApp.provide = (name, value) => {
@@ -1,4 +1,3 @@
1
- import destr from "destr";
2
1
  import { defineNuxtPlugin, useNuxtApp } from "../nuxt.js";
3
2
  export default defineNuxtPlugin({
4
3
  name: "nuxt:restore-state",
@@ -9,7 +8,7 @@ export default defineNuxtPlugin({
9
8
  const state = sessionStorage.getItem("nuxt:reload:state");
10
9
  if (state) {
11
10
  sessionStorage.removeItem("nuxt:reload:state");
12
- Object.assign(nuxtApp.payload.state, destr(state)?.state);
11
+ Object.assign(nuxtApp.payload.state, JSON.parse(state)?.state);
13
12
  }
14
13
  } catch {
15
14
  }
@@ -1,13 +1,19 @@
1
1
  import { reactive, ref, shallowReactive, shallowRef } from "vue";
2
- import destr from "destr";
3
2
  import { definePayloadReviver, getNuxtClientPayload } from "../composables/payload.js";
4
3
  import { createError } from "../composables/error.js";
5
4
  import { defineNuxtPlugin, useNuxtApp } from "../nuxt.js";
6
5
  import { componentIslands } from "#build/nuxt.config.mjs";
6
+ function parseRevivedData(data) {
7
+ try {
8
+ return JSON.parse(data);
9
+ } catch {
10
+ return data;
11
+ }
12
+ }
7
13
  const revivers = [
8
14
  ["NuxtError", (data) => createError(data)],
9
- ["EmptyShallowRef", (data) => shallowRef(data === "_" ? void 0 : data === "0n" ? BigInt(0) : destr(data))],
10
- ["EmptyRef", (data) => ref(data === "_" ? void 0 : data === "0n" ? BigInt(0) : destr(data))],
15
+ ["EmptyShallowRef", (data) => shallowRef(data === "_" ? void 0 : data === "0n" ? BigInt(0) : parseRevivedData(data))],
16
+ ["EmptyRef", (data) => ref(data === "_" ? void 0 : data === "0n" ? BigInt(0) : parseRevivedData(data))],
11
17
  ["ShallowRef", (data) => shallowRef(data)],
12
18
  ["ShallowReactive", (data) => shallowReactive(data)],
13
19
  ["Ref", (data) => ref(data)],
@@ -1,6 +1,6 @@
1
1
  import { computed, defineComponent, h, isReadonly, reactive } from "vue";
2
2
  import { isEqual, joinURL, parseQuery, stringifyParsedURL, stringifyQuery, withoutBase } from "ufo";
3
- import { createError } from "h3";
3
+ import { createError } from "@nuxt/nitro-server/h3";
4
4
  import { defineNuxtPlugin, useRuntimeConfig } from "../nuxt.js";
5
5
  import { getRouteRules } from "../composables/manifest.js";
6
6
  import { clearError, showError } from "../composables/error.js";
@@ -57,7 +57,7 @@ export default defineNuxtPlugin({
57
57
  return;
58
58
  }
59
59
  if (typeof result === "string" && result.length) {
60
- return handleNavigation(result, true);
60
+ return await handleNavigation(result, true);
61
61
  }
62
62
  }
63
63
  for (const handler of hooks["resolve:before"]) {
@@ -23,27 +23,62 @@ export default defineNuxtPlugin((nuxtApp) => {
23
23
  }
24
24
  });
25
25
  const router = useRouter();
26
+ const normalizeViewTransitionOptions = (value) => {
27
+ if (typeof value === "boolean" || value === "always") {
28
+ return { enabled: value };
29
+ }
30
+ if (value && typeof value === "object") {
31
+ return value;
32
+ }
33
+ return {};
34
+ };
26
35
  router.beforeResolve(async (to, from) => {
27
- const viewTransitionMode = to.meta.viewTransition ?? defaultViewTransition;
36
+ if (to.matched.length === 0) {
37
+ return;
38
+ }
39
+ const toViewTransitionOptions = normalizeViewTransitionOptions(to.meta.viewTransition);
40
+ const fromViewTransitionOptions = normalizeViewTransitionOptions(from.meta.viewTransition);
41
+ const viewTransitionMode = toViewTransitionOptions.enabled ?? defaultViewTransition.enabled;
28
42
  const prefersReducedMotion = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
29
43
  const prefersNoTransition = prefersReducedMotion && viewTransitionMode !== "always";
30
44
  if (viewTransitionMode === false || prefersNoTransition || hasUAVisualTransition || !isChangingPage(to, from)) {
31
45
  return;
32
46
  }
47
+ const resolveViewTransitionTypes = (types) => {
48
+ return types ? typeof types === "function" ? types(to, from) : types : void 0;
49
+ };
50
+ const viewTransitionBaseTypes = resolveViewTransitionTypes(toViewTransitionOptions.types) ?? resolveViewTransitionTypes(defaultViewTransition.types) ?? [];
51
+ const viewTransitionFromTypes = resolveViewTransitionTypes(fromViewTransitionOptions.fromTypes) ?? [];
52
+ const viewTransitionToTypes = resolveViewTransitionTypes(toViewTransitionOptions.toTypes) ?? [];
53
+ const allTypes = [
54
+ ...viewTransitionBaseTypes,
55
+ ...viewTransitionFromTypes,
56
+ ...viewTransitionToTypes
57
+ ];
33
58
  const promise = new Promise((resolve, reject) => {
34
59
  finishTransition = resolve;
35
60
  abortTransition = reject;
36
61
  });
37
62
  let changeRoute;
38
63
  const ready = new Promise((resolve) => changeRoute = resolve);
39
- transition = document.startViewTransition(() => {
64
+ const update = () => {
40
65
  changeRoute();
41
66
  return promise;
42
- });
43
- transition.finished.then(resetTransitionState);
67
+ };
68
+ transition = allTypes.length > 0 ? document.startViewTransition({ update, types: allTypes }) : document.startViewTransition(update);
69
+ transition.finished.catch(() => {
70
+ }).finally(resetTransitionState);
44
71
  await nuxtApp.callHook("page:view-transition:start", transition);
45
72
  return ready;
46
73
  });
74
+ router.onError(() => {
75
+ abortTransition?.();
76
+ resetTransitionState();
77
+ });
78
+ nuxtApp.hook("app:error", () => {
79
+ abortTransition?.();
80
+ resetTransitionState();
81
+ });
47
82
  nuxtApp.hook("vue:error", () => {
48
83
  abortTransition?.();
49
84
  resetTransitionState();
@@ -0,0 +1,14 @@
1
+ export interface ObjectFactory<T extends Function> {
2
+ /**
3
+ * The name of the factory function.
4
+ * @example 'createUseFetch'
5
+ */
6
+ name: string;
7
+ factory: T;
8
+ }
9
+ /**
10
+ * Define a factory for a function that should be registered for automatic key injection.
11
+ * @since 4.2.0
12
+ * @param factory
13
+ */
14
+ export declare function defineKeyedFunctionFactory<T extends Function>(factory: ObjectFactory<T>): T;
@@ -0,0 +1,14 @@
1
+ export function defineKeyedFunctionFactory(factory) {
2
+ const placeholder = function() {
3
+ if (import.meta.dev) {
4
+ throw new Error(
5
+ `[nuxt:compiler] \`${factory.name}\` is a compiler macro that is only usable inside the directories scanned by the Nuxt compiler as an exported function and imported statically. Learn more: \`https://nuxt.com/docs/guide/going-further/compiler\``
6
+ );
7
+ }
8
+ throw new Error(`[nuxt] \`${factory.name}\` is a compiler macro and cannot be called at runtime.`);
9
+ };
10
+ return Object.defineProperty(placeholder, "__nuxt_factory", {
11
+ enumerable: false,
12
+ get: () => factory.factory
13
+ });
14
+ }