@wpnuxt/blocks 2.0.0-alpha.2 → 2.0.0-alpha.3
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.d.mts +5 -0
- package/dist/module.json +1 -1
- package/dist/module.mjs +40 -2
- package/dist/runtime/components/BlockComponent.vue +12 -4
- package/dist/runtime/queries/fragments/Page.fragment.gql +18 -0
- package/dist/runtime/queries/fragments/Post.fragment.gql +22 -0
- package/package.json +1 -1
package/dist/module.d.mts
CHANGED
|
@@ -17,6 +17,11 @@ interface WPNuxtBlocksConfig {
|
|
|
17
17
|
* @default 'auto' - uses Nuxt UI if available
|
|
18
18
|
*/
|
|
19
19
|
nuxtUI?: boolean | 'auto';
|
|
20
|
+
/**
|
|
21
|
+
* Skip the WPGraphQL Content Blocks plugin check
|
|
22
|
+
* @default false
|
|
23
|
+
*/
|
|
24
|
+
skipPluginCheck?: boolean;
|
|
20
25
|
}
|
|
21
26
|
declare const _default: _nuxt_schema.NuxtModule<WPNuxtBlocksConfig, WPNuxtBlocksConfig, false>;
|
|
22
27
|
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { existsSync, cpSync, promises } from 'node:fs';
|
|
2
2
|
import { join } from 'node:path';
|
|
3
|
-
import { defineNuxtModule, createResolver, hasNuxtModule, installModule, addComponentsDir, addTemplate } from '@nuxt/kit';
|
|
3
|
+
import { useLogger, defineNuxtModule, createResolver, hasNuxtModule, installModule, addComponentsDir, addTemplate } from '@nuxt/kit';
|
|
4
4
|
|
|
5
|
+
const logger = useLogger("@wpnuxt/blocks");
|
|
5
6
|
const module$1 = defineNuxtModule({
|
|
6
7
|
meta: {
|
|
7
8
|
name: "@wpnuxt/blocks",
|
|
@@ -10,7 +11,8 @@ const module$1 = defineNuxtModule({
|
|
|
10
11
|
defaults: {
|
|
11
12
|
enabled: true,
|
|
12
13
|
imageDomains: [],
|
|
13
|
-
nuxtUI: "auto"
|
|
14
|
+
nuxtUI: "auto",
|
|
15
|
+
skipPluginCheck: false
|
|
14
16
|
},
|
|
15
17
|
async setup(options, nuxt) {
|
|
16
18
|
if (!options.enabled) {
|
|
@@ -26,6 +28,42 @@ const module$1 = defineNuxtModule({
|
|
|
26
28
|
domains: options.imageDomains
|
|
27
29
|
});
|
|
28
30
|
await installModule("@radya/nuxt-dompurify");
|
|
31
|
+
if (!options.skipPluginCheck) {
|
|
32
|
+
const wpNuxtConfig = nuxt.options.runtimeConfig?.public?.wpNuxt;
|
|
33
|
+
const wordpressUrl = wpNuxtConfig?.wordpressUrl || process.env.WPNUXT_WORDPRESS_URL;
|
|
34
|
+
const graphqlEndpoint = wpNuxtConfig?.graphqlEndpoint || process.env.WPNUXT_GRAPHQL_ENDPOINT || "/graphql";
|
|
35
|
+
if (wordpressUrl) {
|
|
36
|
+
const graphqlUrl = `${wordpressUrl}${graphqlEndpoint}`;
|
|
37
|
+
const introspectionQuery = `
|
|
38
|
+
query CheckEditorBlocks {
|
|
39
|
+
__type(name: "Post") {
|
|
40
|
+
fields {
|
|
41
|
+
name
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
`;
|
|
46
|
+
try {
|
|
47
|
+
const response = await fetch(graphqlUrl, {
|
|
48
|
+
method: "POST",
|
|
49
|
+
headers: { "Content-Type": "application/json" },
|
|
50
|
+
body: JSON.stringify({ query: introspectionQuery })
|
|
51
|
+
});
|
|
52
|
+
if (response.ok) {
|
|
53
|
+
const data = await response.json();
|
|
54
|
+
const fields = data?.data?.__type?.fields || [];
|
|
55
|
+
const hasEditorBlocks = fields.some((f) => f.name === "editorBlocks");
|
|
56
|
+
if (!hasEditorBlocks) {
|
|
57
|
+
logger.warn("WPGraphQL Content Blocks plugin not detected on WordPress.");
|
|
58
|
+
logger.warn("Install it from: https://github.com/wpengine/wp-graphql-content-blocks");
|
|
59
|
+
logger.warn("Without this plugin, BlockRenderer will not work correctly.");
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
} catch (error) {
|
|
63
|
+
logger.debug("Could not check for WPGraphQL Content Blocks plugin:", error);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
29
67
|
const blocksQueriesPath = resolveRuntimeModule("./queries");
|
|
30
68
|
const mergedQueriesFolder = join(nuxt.options.srcDir, ".queries");
|
|
31
69
|
if (existsSync(mergedQueriesFolder) && existsSync(blocksQueriesPath)) {
|
|
@@ -1,16 +1,24 @@
|
|
|
1
1
|
<script setup>
|
|
2
2
|
import { pascalCase } from "scule";
|
|
3
|
-
import { resolveComponent } from "#imports";
|
|
3
|
+
import { resolveComponent, getCurrentInstance } from "#imports";
|
|
4
4
|
const props = defineProps({
|
|
5
5
|
block: { type: null, required: true }
|
|
6
6
|
});
|
|
7
|
+
function isComponentRegistered(name) {
|
|
8
|
+
const instance = getCurrentInstance();
|
|
9
|
+
if (!instance) return false;
|
|
10
|
+
const appComponents = instance.appContext.components;
|
|
11
|
+
if (name in appComponents) return true;
|
|
12
|
+
const localComponents = instance.type.components;
|
|
13
|
+
if (localComponents && name in localComponents) return true;
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
7
16
|
const componentToRender = (() => {
|
|
8
17
|
if (props.block.parentClientId === null || props.block.parentClientId === void 0) {
|
|
9
18
|
if (props.block.name) {
|
|
10
19
|
const componentName = pascalCase(props.block.name);
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
return resolved;
|
|
20
|
+
if (isComponentRegistered(componentName)) {
|
|
21
|
+
return resolveComponent(componentName);
|
|
14
22
|
}
|
|
15
23
|
}
|
|
16
24
|
return resolveComponent("EditorBlock");
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
#import "~/.queries/fragments/ContentNode.fragment.gql"
|
|
2
|
+
#import "~/.queries/fragments/NodeWithFeaturedImage.fragment.gql"
|
|
3
|
+
#import "~/.queries/fragments/NodeWithContentEditor.fragment.gql"
|
|
4
|
+
#import "~/.queries/fragments/NodeWithEditorBlocks.fragment.gql"
|
|
5
|
+
|
|
6
|
+
fragment Page on Page {
|
|
7
|
+
...ContentNode
|
|
8
|
+
...NodeWithFeaturedImage
|
|
9
|
+
...NodeWithContentEditor
|
|
10
|
+
...NodeWithEditorBlocks
|
|
11
|
+
isFrontPage
|
|
12
|
+
isPostsPage
|
|
13
|
+
isPreview
|
|
14
|
+
isPrivacyPage
|
|
15
|
+
isRestricted
|
|
16
|
+
isRevision
|
|
17
|
+
title
|
|
18
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
#import "~/.queries/fragments/NodeWithExcerpt.fragment.gql"
|
|
2
|
+
#import "~/.queries/fragments/ContentNode.fragment.gql"
|
|
3
|
+
#import "~/.queries/fragments/NodeWithFeaturedImage.fragment.gql"
|
|
4
|
+
#import "~/.queries/fragments/NodeWithContentEditor.fragment.gql"
|
|
5
|
+
#import "~/.queries/fragments/NodeWithEditorBlocks.fragment.gql"
|
|
6
|
+
|
|
7
|
+
fragment Post on Post {
|
|
8
|
+
...NodeWithExcerpt
|
|
9
|
+
...ContentNode
|
|
10
|
+
...NodeWithFeaturedImage
|
|
11
|
+
...NodeWithContentEditor
|
|
12
|
+
...NodeWithEditorBlocks
|
|
13
|
+
title
|
|
14
|
+
categories {
|
|
15
|
+
nodes {
|
|
16
|
+
id
|
|
17
|
+
name
|
|
18
|
+
uri
|
|
19
|
+
description
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|