@40q/40q-cli 1.0.3 → 1.0.5
Sign up to get free protection for your applications and to get access to all the features.
- package/package.json +1 -1
- package/src/commands/Codegen/Codegen.types.ts +4 -2
- package/src/commands/Codegen/Generators/GenerateBlock.ts +11 -7
- package/src/config.ts +6 -0
- package/templates/blocks/default/php.txt +2 -0
- package/templates/blocks/section-header/php.txt +17 -0
- package/templates/blocks/section-header/tsx.txt +120 -0
package/package.json
CHANGED
@@ -1,5 +1,7 @@
|
|
1
|
-
|
1
|
+
import { config } from '../../config';
|
2
|
+
|
3
|
+
export const typeChoices = config.typeChoices;
|
2
4
|
export type Types = (typeof typeChoices)[number];
|
3
5
|
|
4
|
-
export const templateChoices =
|
6
|
+
export const templateChoices = config.templateChoices.block;
|
5
7
|
export type Templates = (typeof templateChoices)[number] | 'default';
|
@@ -42,7 +42,7 @@ export class GenerateBlock {
|
|
42
42
|
process.cwd(),
|
43
43
|
`resources/views/blocks/${this.name}.blade.php`
|
44
44
|
),
|
45
|
-
''
|
45
|
+
this.getTemplate('blade')
|
46
46
|
);
|
47
47
|
|
48
48
|
fs.writeFileSync(
|
@@ -71,11 +71,15 @@ export class GenerateBlock {
|
|
71
71
|
}
|
72
72
|
|
73
73
|
private getTemplate(name: string) {
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
74
|
+
try {
|
75
|
+
const cliRoot = findCliRoot(__dirname);
|
76
|
+
const templateFolder = `templates/blocks/${this.template}`;
|
77
|
+
return fs.readFileSync(
|
78
|
+
path.join(cliRoot, `${templateFolder}/${name}.txt`),
|
79
|
+
'utf8'
|
80
|
+
);
|
81
|
+
} catch (e) {
|
82
|
+
return '';
|
83
|
+
}
|
80
84
|
}
|
81
85
|
}
|
package/src/config.ts
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
<?php
|
2
|
+
|
3
|
+
namespace App\Blocks;
|
4
|
+
|
5
|
+
use BlockHandler\Contracts\BlockHandler;
|
6
|
+
|
7
|
+
class {{camelCaseName}} extends BlockHandler
|
8
|
+
{
|
9
|
+
public function __invoke($block_content, $block)
|
10
|
+
{
|
11
|
+
return view('blocks.{{name}}', [
|
12
|
+
'eyebrow' => $block['attrs']['eyebrow'] ?? null,
|
13
|
+
'title' => $block['attrs']['title'] ?? null,
|
14
|
+
'description' => $block['attrs']['description'] ?? null,
|
15
|
+
]);
|
16
|
+
}
|
17
|
+
}
|
@@ -0,0 +1,120 @@
|
|
1
|
+
import { __ } from "@wordpress/i18n";
|
2
|
+
import { PanelBody, ToggleControl } from "@wordpress/components";
|
3
|
+
import {
|
4
|
+
InspectorControls,
|
5
|
+
RichText,
|
6
|
+
useBlockProps,
|
7
|
+
useInnerBlocksProps,
|
8
|
+
} from "@wordpress/block-editor";
|
9
|
+
|
10
|
+
/* Block name */
|
11
|
+
export const name = "by40q/{{name}}";
|
12
|
+
|
13
|
+
/* Block title */
|
14
|
+
export const title = __("{{title}}", "40q");
|
15
|
+
|
16
|
+
/* Block category */
|
17
|
+
export const category = "text";
|
18
|
+
|
19
|
+
/* Block attributes */
|
20
|
+
export const attributes = {
|
21
|
+
showEyebrow: {
|
22
|
+
type: "boolean",
|
23
|
+
default: true,
|
24
|
+
},
|
25
|
+
eyebrow: {
|
26
|
+
type: "string",
|
27
|
+
default: "Introducing",
|
28
|
+
},
|
29
|
+
title: {
|
30
|
+
type: "string",
|
31
|
+
default: "40Q",
|
32
|
+
},
|
33
|
+
showDescription: {
|
34
|
+
type: "boolean",
|
35
|
+
default: true,
|
36
|
+
},
|
37
|
+
description: {
|
38
|
+
type: "string",
|
39
|
+
default:
|
40
|
+
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed euismod, diam id tincidunt ultrices, nunc nisl ultrices nunc, vitae aliquam nisl nunc eu nisl. Sed euismod, diam id tincidunt ultrices, nunc nisl ultrices nunc, vitae aliquam nisl nunc eu nisl.",
|
41
|
+
},
|
42
|
+
showCta: {
|
43
|
+
type: "boolean",
|
44
|
+
default: false,
|
45
|
+
},
|
46
|
+
};
|
47
|
+
|
48
|
+
/* Block edit */
|
49
|
+
export const edit = ({ attributes, setAttributes }) => {
|
50
|
+
const { showEyeBrow, eyebrow, title, showDescription, description, showCta } =
|
51
|
+
attributes;
|
52
|
+
|
53
|
+
const blockProps = useBlockProps();
|
54
|
+
|
55
|
+
const innerBlocksProps = useInnerBlocksProps(blockProps, {
|
56
|
+
template: [["core/button"]],
|
57
|
+
allowedBlocks: [],
|
58
|
+
templateLock: "all",
|
59
|
+
});
|
60
|
+
|
61
|
+
return (
|
62
|
+
<>
|
63
|
+
<InspectorControls>
|
64
|
+
<PanelBody title={__("Section Header Settings")} initialOpen>
|
65
|
+
<ToggleControl
|
66
|
+
label="Eyebrow"
|
67
|
+
checked={!!showEyeBrow}
|
68
|
+
onChange={(showEyeBrow) => setAttributes({ showEyeBrow })}
|
69
|
+
/>
|
70
|
+
<ToggleControl
|
71
|
+
label="Description"
|
72
|
+
checked={!!showDescription}
|
73
|
+
onChange={(showDescription) => setAttributes({ showDescription })}
|
74
|
+
/>
|
75
|
+
|
76
|
+
<ToggleControl
|
77
|
+
label="Cta"
|
78
|
+
checked={!!showCta}
|
79
|
+
onChange={(showCta) => setAttributes({ showCta })}
|
80
|
+
/>
|
81
|
+
</PanelBody>
|
82
|
+
</InspectorControls>
|
83
|
+
|
84
|
+
<div {...blockProps}>
|
85
|
+
{!!showEyeBrow && (
|
86
|
+
<RichText
|
87
|
+
className=""
|
88
|
+
tagName="p"
|
89
|
+
placeholder={__("Eyebrow")}
|
90
|
+
value={eyebrow}
|
91
|
+
onChange={(eyebrow) => setAttributes({ eyebrow })}
|
92
|
+
/>
|
93
|
+
)}
|
94
|
+
<RichText
|
95
|
+
className=""
|
96
|
+
tagName="h2"
|
97
|
+
placeholder={__("40Q")}
|
98
|
+
value={title}
|
99
|
+
onChange={(title) => setAttributes({ title })}
|
100
|
+
/>
|
101
|
+
{!!showDescription && (
|
102
|
+
<RichText
|
103
|
+
className=""
|
104
|
+
tagName="p"
|
105
|
+
placeholder={__("Lorem ipsum dolor sit amet.")}
|
106
|
+
value={description}
|
107
|
+
onChange={(description) => setAttributes({ description })}
|
108
|
+
/>
|
109
|
+
)}
|
110
|
+
{!!showCta && <div {...innerBlocksProps} />}
|
111
|
+
</div>
|
112
|
+
</>
|
113
|
+
);
|
114
|
+
};
|
115
|
+
|
116
|
+
/* Block save */
|
117
|
+
export const save = <></>;
|
118
|
+
|
119
|
+
/* Block styles */
|
120
|
+
export const styles = [];
|