@wpnuxt/blocks 0.0.6 → 0.0.8
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 +2 -2
- package/dist/module.mjs +5 -7
- package/dist/runtime/components/BlockComponent.vue +5 -7
- package/dist/runtime/components/BlockRenderer.vue +3 -3
- package/dist/runtime/components/blocks/CoreButton.vue +13 -2
- package/dist/runtime/components/blocks/CoreButtons.vue +14 -12
- package/dist/runtime/components/blocks/CoreHeading.vue +38 -12
- package/dist/runtime/components/blocks/CoreParagraph.vue +8 -4
- package/dist/runtime/components/blocks/CoreSpacer.vue +19 -0
- package/dist/runtime/queries/fragments/CoreSpacer.fragment.gql +11 -0
- package/dist/runtime/queries/fragments/EditorBlock.fragment.gql +2 -0
- package/dist/runtime/queries/fragments/{EditorBlocks.fragment.gql → NodeWithEditorBlocks.fragment.gql} +1 -1
- package/dist/runtime/queries/fragments/Page.fragment.gql +2 -2
- package/dist/runtime/queries/fragments/Post.fragment.gql +2 -2
- package/dist/runtime/util/attributeColor.d.ts +1 -0
- package/dist/runtime/util/attributeColor.js +4 -0
- package/dist/runtime/util/attributeFontSize.d.ts +1 -0
- package/dist/runtime/util/attributeFontSize.js +18 -0
- package/dist/runtime/util/index.d.ts +4 -0
- package/dist/runtime/util/index.js +9 -0
- package/package.json +12 -7
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { promises } from 'node:fs';
|
|
2
|
-
import { defineNuxtModule, createResolver, installModule, addComponentsDir,
|
|
2
|
+
import { defineNuxtModule, createResolver, installModule, addComponentsDir, addTemplate } from '@nuxt/kit';
|
|
3
3
|
import { genDynamicImport } from 'knitwork';
|
|
4
4
|
|
|
5
5
|
const name = "@wpnuxt/blocks";
|
|
6
|
-
const version = "0.0.
|
|
6
|
+
const version = "0.0.8";
|
|
7
7
|
|
|
8
8
|
const module = defineNuxtModule({
|
|
9
9
|
meta: {
|
|
@@ -22,10 +22,11 @@ const module = defineNuxtModule({
|
|
|
22
22
|
nuxt.options.alias["#wpnuxt/blocks"] = resolve(nuxt.options.buildDir, "wpnuxt/blocks");
|
|
23
23
|
await installModule("@nuxt/ui");
|
|
24
24
|
await installModule("@nuxt/image", {
|
|
25
|
+
// TODO: get wordpressUrl from @wpnuxt/core options
|
|
25
26
|
domains: ["wordpress.wpnuxt.com"]
|
|
26
27
|
});
|
|
27
28
|
addComponentsDir({
|
|
28
|
-
path: resolveRuntimeModule("./components
|
|
29
|
+
path: resolveRuntimeModule("./components"),
|
|
29
30
|
pathPrefix: false,
|
|
30
31
|
prefix: "",
|
|
31
32
|
global: true
|
|
@@ -46,12 +47,9 @@ const module = defineNuxtModule({
|
|
|
46
47
|
});
|
|
47
48
|
}
|
|
48
49
|
}
|
|
49
|
-
addComponent({ name: "BlockComponent", filePath: resolveRuntimeModule("./components/BlockComponent") });
|
|
50
|
-
addComponent({ name: "BlockInfo", filePath: resolveRuntimeModule("./components/BlockInfo") });
|
|
51
|
-
addComponent({ name: "BlockRenderer", filePath: resolveRuntimeModule("./components/BlockRenderer") });
|
|
52
50
|
const componentsContext = { components: [] };
|
|
53
51
|
nuxt.hook("components:extend", (newComponents) => {
|
|
54
|
-
const moduleBlocksDir = resolveRuntimeModule("./components
|
|
52
|
+
const moduleBlocksDir = resolveRuntimeModule("./components");
|
|
55
53
|
const userBlocksDir = (nuxt.options.srcDir || nuxt.options.rootDir) + "/components/blocks";
|
|
56
54
|
componentsContext.components = newComponents.filter((c) => {
|
|
57
55
|
if (c.filePath.startsWith(moduleBlocksDir) || c.filePath.startsWith(userBlocksDir)) {
|
|
@@ -27,11 +27,9 @@ const componentToRender = await findComponentToRender()
|
|
|
27
27
|
</script>
|
|
28
28
|
|
|
29
29
|
<template>
|
|
30
|
-
<
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
/>
|
|
36
|
-
</div>
|
|
30
|
+
<component
|
|
31
|
+
:is="componentToRender"
|
|
32
|
+
v-if="componentToRender"
|
|
33
|
+
:block="block"
|
|
34
|
+
/>
|
|
37
35
|
</template>
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import BlockComponent from './BlockComponent.vue'
|
|
3
|
-
import type {
|
|
3
|
+
import type { NodeWithEditorBlocksFragment } from '#build/graphql-operations'
|
|
4
4
|
|
|
5
5
|
defineProps<{
|
|
6
|
-
|
|
6
|
+
post: NodeWithEditorBlocksFragment
|
|
7
7
|
}>()
|
|
8
8
|
</script>
|
|
9
9
|
|
|
10
10
|
<template>
|
|
11
11
|
<div>
|
|
12
12
|
<BlockComponent
|
|
13
|
-
v-for="block, index in
|
|
13
|
+
v-for="block, index in post.editorBlocks"
|
|
14
14
|
:key="index"
|
|
15
15
|
:block="block"
|
|
16
16
|
/>
|
|
@@ -1,18 +1,29 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
+
import { convertFontSize, getCssClasses } from '../../util'
|
|
2
3
|
import type { CoreButton } from '#wpnuxt/blocks'
|
|
4
|
+
import { ref } from '#imports'
|
|
3
5
|
|
|
4
|
-
defineProps<{
|
|
6
|
+
const props = defineProps<{
|
|
5
7
|
block: CoreButton
|
|
6
8
|
}>()
|
|
9
|
+
const variant = ref('solid')
|
|
10
|
+
/* if (props.block.attributes?.cssClassName?.includes('is-style-outline')) {
|
|
11
|
+
variant.value = 'outline'
|
|
12
|
+
} */
|
|
13
|
+
if (props.block.attributes?.metadata) {
|
|
14
|
+
variant.value = props.block.attributes?.metadata?.replaceAll('"', '')
|
|
15
|
+
}
|
|
7
16
|
</script>
|
|
8
17
|
|
|
9
18
|
<template>
|
|
10
19
|
<UButton
|
|
11
20
|
:to="block.attributes.url"
|
|
12
21
|
:target="block.attributes.linkTarget"
|
|
13
|
-
:class="block.attributes.cssClassName"
|
|
14
22
|
:rel="block.attributes.rel"
|
|
15
23
|
:style="block.attributes.style"
|
|
24
|
+
:variant
|
|
25
|
+
:class="getCssClasses(block)"
|
|
26
|
+
:size="convertFontSize(block.attributes?.fontSize, '', 'md')"
|
|
16
27
|
>
|
|
17
28
|
<span v-sanitize="block.attributes.text" />
|
|
18
29
|
</UButton>
|
|
@@ -7,17 +7,19 @@ defineProps<{
|
|
|
7
7
|
</script>
|
|
8
8
|
|
|
9
9
|
<template>
|
|
10
|
-
<div
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
10
|
+
<div>
|
|
11
|
+
<template
|
|
12
|
+
v-for="innerBlock, index in block.innerBlocks"
|
|
13
|
+
:key="index"
|
|
14
|
+
>
|
|
15
|
+
<CoreButton
|
|
16
|
+
v-if="innerBlock.name === 'core/button'"
|
|
17
|
+
:block="innerBlock"
|
|
18
|
+
/>
|
|
19
|
+
<EditorBlock
|
|
20
|
+
v-else
|
|
21
|
+
:block="innerBlock"
|
|
22
|
+
/>
|
|
23
|
+
</template>
|
|
22
24
|
</div>
|
|
23
25
|
</template>
|
|
@@ -1,28 +1,54 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
+
import { getCssClasses } from '../../util'
|
|
2
3
|
import type { CoreHeading } from '#wpnuxt/blocks'
|
|
3
4
|
|
|
4
|
-
defineProps<{
|
|
5
|
+
const props = defineProps<{
|
|
5
6
|
block: CoreHeading
|
|
6
7
|
}>()
|
|
8
|
+
const cssClass = getCssClasses(props.block)
|
|
7
9
|
</script>
|
|
8
10
|
|
|
9
11
|
<template>
|
|
10
12
|
<template v-if="block.attributes.level === 1">
|
|
11
|
-
<h1
|
|
13
|
+
<h1
|
|
14
|
+
:id="block?.attributes?.anchor"
|
|
15
|
+
v-sanitize="block.attributes.content"
|
|
16
|
+
:class="cssClass"
|
|
17
|
+
/>
|
|
12
18
|
</template>
|
|
13
|
-
<template v-if="block.attributes.level === 2">
|
|
14
|
-
<h2
|
|
19
|
+
<template v-else-if="block.attributes.level === 2">
|
|
20
|
+
<h2
|
|
21
|
+
:id="block?.attributes?.anchor"
|
|
22
|
+
v-sanitize="block.attributes.content"
|
|
23
|
+
:class="cssClass"
|
|
24
|
+
/>
|
|
15
25
|
</template>
|
|
16
|
-
<template v-if="block.attributes.level === 3">
|
|
17
|
-
<h3
|
|
26
|
+
<template v-else-if="block.attributes.level === 3">
|
|
27
|
+
<h3
|
|
28
|
+
:id="block?.attributes?.anchor"
|
|
29
|
+
v-sanitize="block.attributes.content"
|
|
30
|
+
:class="cssClass"
|
|
31
|
+
/>
|
|
18
32
|
</template>
|
|
19
|
-
<template v-if="block.attributes.level === 4">
|
|
20
|
-
<h4
|
|
33
|
+
<template v-else-if="block.attributes.level === 4">
|
|
34
|
+
<h4
|
|
35
|
+
:id="block?.attributes?.anchor"
|
|
36
|
+
v-sanitize="block.attributes.content"
|
|
37
|
+
:class="cssClass"
|
|
38
|
+
/>
|
|
21
39
|
</template>
|
|
22
|
-
<template v-if="block.attributes.level === 5">
|
|
23
|
-
<h5
|
|
40
|
+
<template v-else-if="block.attributes.level === 5">
|
|
41
|
+
<h5
|
|
42
|
+
:id="block?.attributes?.anchor"
|
|
43
|
+
v-sanitize="block.attributes.content"
|
|
44
|
+
:class="cssClass"
|
|
45
|
+
/>
|
|
24
46
|
</template>
|
|
25
|
-
<template v-if="block.attributes.level === 6">
|
|
26
|
-
<h6
|
|
47
|
+
<template v-else-if="block.attributes.level === 6">
|
|
48
|
+
<h6
|
|
49
|
+
:id="block?.attributes?.anchor"
|
|
50
|
+
v-sanitize="block.attributes.content"
|
|
51
|
+
:class="cssClass"
|
|
52
|
+
/>
|
|
27
53
|
</template>
|
|
28
54
|
</template>
|
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
+
import { getCssClasses } from '../../util'
|
|
2
3
|
import type { CoreParagraph } from '#wpnuxt/blocks'
|
|
3
4
|
|
|
4
|
-
defineProps<{
|
|
5
|
+
const props = defineProps<{
|
|
5
6
|
block: CoreParagraph
|
|
6
7
|
}>()
|
|
7
8
|
</script>
|
|
8
9
|
|
|
9
10
|
<template>
|
|
10
|
-
<
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
<p
|
|
12
|
+
:id="block?.attributes?.anchor"
|
|
13
|
+
v-sanitize="block?.attributes?.content"
|
|
14
|
+
:class="getCssClasses(props.block)"
|
|
15
|
+
:style="block?.attributes?.style"
|
|
16
|
+
/>
|
|
13
17
|
</template>
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { getCssClasses } from '../../util'
|
|
3
|
+
import type { CoreSpacer } from '#wpnuxt/blocks'
|
|
4
|
+
|
|
5
|
+
const props = defineProps<{
|
|
6
|
+
block: CoreSpacer
|
|
7
|
+
}>()
|
|
8
|
+
const cssClass = getCssClasses(props.block)
|
|
9
|
+
</script>
|
|
10
|
+
|
|
11
|
+
<template>
|
|
12
|
+
<div
|
|
13
|
+
:class="cssClass"
|
|
14
|
+
:style="{
|
|
15
|
+
height: block.attributes?.spacerHeight,
|
|
16
|
+
width: block.attributes?.spacerWidth
|
|
17
|
+
}"
|
|
18
|
+
/>
|
|
19
|
+
</template>
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
#import '~/.queries/fragments/CoreImage.fragment.gql';
|
|
5
5
|
#import '~/.queries/fragments/CoreParagraph.fragment.gql';
|
|
6
6
|
#import '~/.queries/fragments/CoreQuote.fragment.gql';
|
|
7
|
+
#import '~/.queries/fragments/CoreSpacer.fragment.gql';
|
|
7
8
|
|
|
8
9
|
fragment EditorBlock on EditorBlock {
|
|
9
10
|
apiVersion
|
|
@@ -20,4 +21,5 @@ fragment EditorBlock on EditorBlock {
|
|
|
20
21
|
...CoreImage
|
|
21
22
|
...CoreParagraph
|
|
22
23
|
...CoreQuote
|
|
24
|
+
...CoreSpacer
|
|
23
25
|
}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
#import '~/.queries/fragments/ContentNode.fragment.gql';
|
|
2
2
|
#import '~/.queries/fragments/NodeWithFeaturedImage.fragment.gql';
|
|
3
|
-
#import '~/.queries/fragments/
|
|
3
|
+
#import '~/.queries/fragments/NodeWithEditorBlocks.fragment.gql';
|
|
4
4
|
|
|
5
5
|
fragment Page on Page {
|
|
6
6
|
...ContentNode
|
|
7
7
|
...NodeWithFeaturedImage
|
|
8
|
+
...NodeWithEditorBlocks
|
|
8
9
|
content
|
|
9
10
|
isFrontPage
|
|
10
11
|
isPostsPage
|
|
@@ -13,5 +14,4 @@ fragment Page on Page {
|
|
|
13
14
|
isRestricted
|
|
14
15
|
isRevision
|
|
15
16
|
title
|
|
16
|
-
...EditorBlocks
|
|
17
17
|
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
#import "~/.queries/fragments/NodeWithExcerpt.fragment.gql";
|
|
2
2
|
#import '~/.queries/fragments/ContentNode.fragment.gql';
|
|
3
3
|
#import '~/.queries/fragments/NodeWithFeaturedImage.fragment.gql';
|
|
4
|
-
#import '~/.queries/fragments/
|
|
4
|
+
#import '~/.queries/fragments/NodeWithEditorBlocks.fragment.gql';
|
|
5
5
|
|
|
6
6
|
fragment Post on Post {
|
|
7
7
|
...NodeWithExcerpt
|
|
8
8
|
...ContentNode
|
|
9
9
|
...NodeWithFeaturedImage
|
|
10
|
+
...NodeWithEditorBlocks
|
|
10
11
|
content
|
|
11
12
|
title
|
|
12
|
-
...EditorBlocks
|
|
13
13
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const getColor: (textColor?: string) => string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const convertFontSize: (fontSize: string, prefix?: string, defaultSize?: string) => string;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export const convertFontSize = function convertFontSize2(fontSize, prefix, defaultSize) {
|
|
2
|
+
if (!prefix) prefix = "";
|
|
3
|
+
if (fontSize && fontSize !== "" && fontSize !== "null") {
|
|
4
|
+
switch (fontSize) {
|
|
5
|
+
case "small":
|
|
6
|
+
return prefix + "sm";
|
|
7
|
+
case "medium":
|
|
8
|
+
return prefix + "md";
|
|
9
|
+
case "large":
|
|
10
|
+
return prefix + "lg";
|
|
11
|
+
case "x-large":
|
|
12
|
+
return prefix + "xl";
|
|
13
|
+
case "xx-large":
|
|
14
|
+
return prefix + "2xl";
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return defaultSize ? prefix + defaultSize : "";
|
|
18
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { convertFontSize } from "./attributeFontSize.js";
|
|
2
|
+
import { getColor } from "./attributeColor.js";
|
|
3
|
+
const getCssClasses = function getCssClasses2(block) {
|
|
4
|
+
const text = convertFontSize(block.attributes?.fontSize, "text-");
|
|
5
|
+
const color = getColor(block.attributes?.textColor);
|
|
6
|
+
const passedOn = block?.attributes?.className != null ? block?.attributes?.className + " " : " ";
|
|
7
|
+
return passedOn + text + " " + color;
|
|
8
|
+
};
|
|
9
|
+
export { getCssClasses, convertFontSize, getColor };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wpnuxt/blocks",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.8",
|
|
4
4
|
"description": "WPNuxt Blocks",
|
|
5
5
|
"repository": "wpnuxt/wpnuxt-blocks",
|
|
6
6
|
"license": "MIT",
|
|
@@ -31,21 +31,25 @@
|
|
|
31
31
|
"lint:fix": "eslint . --fix",
|
|
32
32
|
"test": "vitest run",
|
|
33
33
|
"test:watch": "vitest watch",
|
|
34
|
-
"test:types": "vue-tsc --noEmit && cd playground && vue-tsc --noEmit"
|
|
34
|
+
"test:types": "vue-tsc --noEmit && cd playground && vue-tsc --noEmit",
|
|
35
|
+
"wp-env": "wp-env",
|
|
36
|
+
"wp-env:create": "wp-env start --update && ./wordpress/wp-env-cli.sh",
|
|
37
|
+
"start": "pnpm run wp-env:create && pnpm run dev"
|
|
35
38
|
},
|
|
36
39
|
"dependencies": {
|
|
37
40
|
"@nuxt/image": "^1.7.0",
|
|
38
41
|
"@nuxt/kit": "^3.12.4",
|
|
39
42
|
"@nuxt/ui": "^2.18.4",
|
|
40
|
-
"@wpnuxt/core": "^1.0.0-edge.
|
|
43
|
+
"@wpnuxt/core": "^1.0.0-edge.8"
|
|
41
44
|
},
|
|
42
45
|
"devDependencies": {
|
|
43
46
|
"@nuxt/devtools": "^1.3.9",
|
|
44
47
|
"@nuxt/eslint-config": "^0.5.0",
|
|
45
|
-
"@nuxt/module-builder": "^0.8.
|
|
48
|
+
"@nuxt/module-builder": "^0.8.3",
|
|
46
49
|
"@nuxt/schema": "^3.12.4",
|
|
47
|
-
"@nuxt/test-utils": "^3.
|
|
48
|
-
"@types/node": "^22.
|
|
50
|
+
"@nuxt/test-utils": "^3.14.1",
|
|
51
|
+
"@types/node": "^22.4.1",
|
|
52
|
+
"@wordpress/env": "^10.5.0",
|
|
49
53
|
"changelogen": "^0.5.5",
|
|
50
54
|
"eslint": "^9.9.0",
|
|
51
55
|
"nuxt": "^3.12.4",
|
|
@@ -57,5 +61,6 @@
|
|
|
57
61
|
"peerDependencies": {
|
|
58
62
|
"knitwork": "^1.1.0",
|
|
59
63
|
"pathe": "^1.1.2"
|
|
60
|
-
}
|
|
64
|
+
},
|
|
65
|
+
"packageManager": "pnpm@9.7.0"
|
|
61
66
|
}
|