@wpnuxt/core 2.0.0 → 2.1.0

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.
package/dist/module.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wpnuxt/core",
3
- "version": "2.0.0",
3
+ "version": "2.1.0",
4
4
  "configKey": "wpNuxt",
5
5
  "compatibility": {
6
6
  "nuxt": ">=4.0.0"
package/dist/module.mjs CHANGED
@@ -8,7 +8,7 @@ import { parse, GraphQLError, visit, print } from 'graphql';
8
8
  import { execSync } from 'node:child_process';
9
9
  import { consola } from 'consola';
10
10
 
11
- const version = "2.0.0";
11
+ const version = "2.1.0";
12
12
 
13
13
  function createModuleError(module, message) {
14
14
  return new Error(formatErrorMessage(module, message));
@@ -275,7 +275,7 @@ async function prepareContext(ctx) {
275
275
  if (!typed) {
276
276
  return `export const ${functionName} = (params, options) => useWPContent('${q.name}', [${formatNodes(q.nodes)}], false, params, options)`;
277
277
  }
278
- return ` export const ${functionName}: (params?: ${q.name}QueryVariables, options?: WPContentOptions) => WPContentResult<${getFragmentType(q)}>`;
278
+ return ` export const ${functionName}: (params?: MaybeRefOrGetter<${q.name}QueryVariables>, options?: WPContentOptions) => WPContentResult<${getFragmentType(q)}>`;
279
279
  };
280
280
  const mutationFnExp = (m, typed = false) => {
281
281
  const functionName = mutationFnName(m.name);
@@ -321,7 +321,7 @@ async function prepareContext(ctx) {
321
321
  ctx.generateDeclarations = () => {
322
322
  const declarations = [
323
323
  `import type { ${[...typeSet].join(", ")} } from '#build/graphql-operations'`,
324
- "import type { ComputedRef, Ref } from 'vue'",
324
+ "import type { ComputedRef, MaybeRefOrGetter, Ref } from 'vue'",
325
325
  "import type { AsyncDataRequestStatus } from '#app'",
326
326
  "import type { GraphqlResponse } from 'nuxt-graphql-middleware/types'",
327
327
  "",
@@ -948,7 +948,12 @@ const module$1 = defineNuxtModule({
948
948
  { name: "getRelativeImagePath", as: "getRelativeImagePath", from: resolver.resolve("./runtime/util/images") },
949
949
  { name: "isInternalLink", as: "isInternalLink", from: resolver.resolve("./runtime/util/links") },
950
950
  { name: "toRelativePath", as: "toRelativePath", from: resolver.resolve("./runtime/util/links") },
951
- { name: "usePrevNextPost", as: "usePrevNextPost", from: resolver.resolve("./runtime/composables/usePrevNextPost") }
951
+ { name: "usePrevNextPost", as: "usePrevNextPost", from: resolver.resolve("./runtime/composables/usePrevNextPost") },
952
+ { name: "isPage", as: "isPage", from: resolver.resolve("./runtime/util/content-type") },
953
+ { name: "isPost", as: "isPost", from: resolver.resolve("./runtime/util/content-type") },
954
+ { name: "isContentType", as: "isContentType", from: resolver.resolve("./runtime/util/content-type") },
955
+ { name: "unwrapScalar", as: "unwrapScalar", from: resolver.resolve("./runtime/util/acf") },
956
+ { name: "unwrapConnection", as: "unwrapConnection", from: resolver.resolve("./runtime/util/acf") }
952
957
  // Note: useGraphqlMutation is auto-imported via nuxt-graphql-middleware with includeComposables: true
953
958
  ]);
954
959
  addComponentsDir({
@@ -1,5 +1,5 @@
1
1
  import { transformData, normalizeUriParam } from "../util/content.js";
2
- import { computed, ref, watch as vueWatch, useAsyncGraphqlQuery, useRuntimeConfig } from "#imports";
2
+ import { computed, ref, toValue, watch as vueWatch, useAsyncGraphqlQuery, useRuntimeConfig } from "#imports";
3
3
  const defaultGetCachedData = (key, app, ctx) => {
4
4
  if (app.isHydrating) {
5
5
  return app.payload.data[key];
@@ -21,7 +21,8 @@ export const useWPContent = (queryName, nodes, fixImagePaths, params, options) =
21
21
  timeout: timeoutOption,
22
22
  ...restOptions
23
23
  } = options ?? {};
24
- const normalizedParams = normalizeUriParam(params);
24
+ const isReactiveParams = typeof params === "function" || params !== null && typeof params === "object" && "__v_isRef" in params;
25
+ const resolvedParams = isReactiveParams ? computed(() => normalizeUriParam(toValue(params)) ?? {}) : normalizeUriParam(params) ?? {};
25
26
  const maxRetries = retryOption === false ? 0 : retryOption ?? 0;
26
27
  const baseRetryDelay = retryDelayOption ?? 1e3;
27
28
  const retryCount = ref(0);
@@ -55,7 +56,7 @@ export const useWPContent = (queryName, nodes, fixImagePaths, params, options) =
55
56
  };
56
57
  const asyncResult = useAsyncGraphqlQuery(
57
58
  String(queryName),
58
- normalizedParams ?? {},
59
+ resolvedParams,
59
60
  asyncDataOptions
60
61
  );
61
62
  const { data, pending, refresh, execute, clear, error, status } = asyncResult;
@@ -10,6 +10,7 @@ import type { NuxtApp } from 'nuxt/app'
10
10
  // Stub for #imports - Vue reactivity & lifecycle
11
11
  export function computed<T>(getter: () => T): ComputedRef<T>
12
12
  export function ref<T>(value: T): Ref<T>
13
+ export function toValue<T>(source: Ref<T> | ComputedRef<T> | (() => T) | T): T
13
14
  export function resolveComponent(name: string): Component | string
14
15
  export function onMounted(callback: () => void): void
15
16
  export function onBeforeUnmount(callback: () => void): void
@@ -29,7 +30,7 @@ export function navigateTo(to: string): Promise<void>
29
30
  // Stub for #imports - nuxt-graphql-middleware
30
31
  export function useAsyncGraphqlQuery<T = unknown>(
31
32
  name: string,
32
- params?: Record<string, unknown>,
33
+ params?: Record<string, unknown> | Ref<Record<string, unknown>> | ComputedRef<Record<string, unknown>>,
33
34
  options?: Record<string, unknown>
34
35
  ): {
35
36
  data: Ref<T | null>
File without changes
@@ -0,0 +1,9 @@
1
+ function unwrapScalar(value) {
2
+ if (value == null) return void 0;
3
+ if (Array.isArray(value)) return value[0];
4
+ return value;
5
+ }
6
+ function unwrapConnection(connection) {
7
+ return connection?.nodes?.[0];
8
+ }
9
+ export { unwrapScalar, unwrapConnection };
File without changes
@@ -0,0 +1,10 @@
1
+ function isPage(node) {
2
+ return node?.contentTypeName === "page";
3
+ }
4
+ function isPost(node) {
5
+ return node?.contentTypeName === "post";
6
+ }
7
+ function isContentType(node, typeName) {
8
+ return node?.contentTypeName === typeName;
9
+ }
10
+ export { isPage, isPost, isContentType };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wpnuxt/core",
3
- "version": "2.0.0",
3
+ "version": "2.1.0",
4
4
  "description": "Nuxt module for WordPress integration via GraphQL (WPGraphQL)",
5
5
  "keywords": [
6
6
  "nuxt",