@wp-typia/create 0.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/README.md +43 -0
- package/dist/cli.js +2492 -0
- package/dist/runtime/cli-core.js +222 -0
- package/dist/runtime/index.js +4 -0
- package/dist/runtime/migration-constants.js +14 -0
- package/dist/runtime/migration-diff.js +521 -0
- package/dist/runtime/migration-fixtures.js +89 -0
- package/dist/runtime/migration-manifest.js +129 -0
- package/dist/runtime/migration-project.js +167 -0
- package/dist/runtime/migration-render.js +267 -0
- package/dist/runtime/migration-types.js +1 -0
- package/dist/runtime/migration-utils.js +184 -0
- package/dist/runtime/migrations.js +232 -0
- package/dist/runtime/package-managers.js +135 -0
- package/dist/runtime/scaffold.js +334 -0
- package/dist/runtime/template-registry.js +75 -0
- package/package.json +65 -0
- package/templates/advanced/README.md.mustache +150 -0
- package/templates/advanced/block.json.mustache +43 -0
- package/templates/advanced/index.js +21 -0
- package/templates/advanced/package.json.mustache +47 -0
- package/templates/advanced/render.php.mustache +83 -0
- package/templates/advanced/scripts/lib/typia-metadata-core.ts +1413 -0
- package/templates/advanced/scripts/sync-types-to-block-json.ts.mustache +32 -0
- package/templates/advanced/src/admin/migration-dashboard.tsx.mustache +315 -0
- package/templates/advanced/src/components/ErrorBoundary.tsx.mustache +47 -0
- package/templates/advanced/src/deprecated.ts.mustache +2 -0
- package/templates/advanced/src/edit.tsx.mustache +97 -0
- package/templates/advanced/src/hooks/useDebounce.ts.mustache +20 -0
- package/templates/advanced/src/hooks/useLocalStorage.ts.mustache +31 -0
- package/templates/advanced/src/hooks.ts.mustache +56 -0
- package/templates/advanced/src/index.tsx.mustache +18 -0
- package/templates/advanced/src/migration-detector.ts.mustache +9 -0
- package/templates/advanced/src/migrations/config.ts.mustache +8 -0
- package/templates/advanced/src/migrations/examples/rename-transform-union/README.md.mustache +23 -0
- package/templates/advanced/src/migrations/examples/rename-transform-union/fixture.example.json.mustache +36 -0
- package/templates/advanced/src/migrations/examples/rename-transform-union/rule.example.ts.mustache +47 -0
- package/templates/advanced/src/migrations/fixtures/README.md.mustache +3 -0
- package/templates/advanced/src/migrations/generated/deprecated.ts.mustache +3 -0
- package/templates/advanced/src/migrations/generated/registry.ts.mustache +9 -0
- package/templates/advanced/src/migrations/generated/verify.ts.mustache +1 -0
- package/templates/advanced/src/migrations/helpers.ts.mustache +354 -0
- package/templates/advanced/src/migrations/index.ts.mustache +616 -0
- package/templates/advanced/src/migrations/rules/README.md.mustache +3 -0
- package/templates/advanced/src/migrations/versions/README.md.mustache +3 -0
- package/templates/advanced/src/save.tsx.mustache +12 -0
- package/templates/advanced/src/style.scss.mustache +84 -0
- package/templates/advanced/src/types.ts.mustache +46 -0
- package/templates/advanced/src/utils/classnames.ts.mustache +51 -0
- package/templates/advanced/src/utils/debounce.ts.mustache +37 -0
- package/templates/advanced/src/utils/index.ts.mustache +7 -0
- package/templates/advanced/src/utils/uuid.ts.mustache +17 -0
- package/templates/advanced/src/validators.ts.mustache +39 -0
- package/templates/advanced/src/view.ts.mustache +59 -0
- package/templates/advanced/tsconfig.json.mustache +20 -0
- package/templates/advanced/webpack.config.js.mustache +95 -0
- package/templates/basic/package.json.mustache +39 -0
- package/templates/basic/scripts/lib/typia-metadata-core.ts +1413 -0
- package/templates/basic/scripts/sync-types-to-block-json.ts +25 -0
- package/templates/basic/src/block.json +51 -0
- package/templates/basic/src/edit.tsx +85 -0
- package/templates/basic/src/hooks.ts +75 -0
- package/templates/basic/src/index.tsx +37 -0
- package/templates/basic/src/save.tsx +27 -0
- package/templates/basic/src/style.scss +42 -0
- package/templates/basic/src/types.ts +48 -0
- package/templates/basic/src/validators.ts +39 -0
- package/templates/basic/tsconfig.json +20 -0
- package/templates/basic/webpack.config.js +89 -0
- package/templates/full/package.json.mustache +40 -0
- package/templates/full/scripts/lib/typia-metadata-core.ts +1413 -0
- package/templates/full/scripts/sync-types-to-block-json.ts.mustache +32 -0
- package/templates/full/src/block.json.mustache +120 -0
- package/templates/full/src/edit.tsx.mustache +300 -0
- package/templates/full/src/editor.scss.mustache +251 -0
- package/templates/full/src/hooks.ts.mustache +141 -0
- package/templates/full/src/index.tsx.mustache +27 -0
- package/templates/full/src/save.tsx.mustache +39 -0
- package/templates/full/src/style.scss.mustache +224 -0
- package/templates/full/src/types.ts.mustache +35 -0
- package/templates/full/src/validators.ts.mustache +84 -0
- package/templates/full/tsconfig.json.mustache +20 -0
- package/templates/full/webpack.config.js.mustache +89 -0
- package/templates/interactivity/package.json.mustache +41 -0
- package/templates/interactivity/scripts/lib/typia-metadata-core.ts +1413 -0
- package/templates/interactivity/scripts/sync-types-to-block-json.ts.mustache +32 -0
- package/templates/interactivity/src/block.json.mustache +74 -0
- package/templates/interactivity/src/edit.tsx.mustache +206 -0
- package/templates/interactivity/src/index.tsx.mustache +20 -0
- package/templates/interactivity/src/interactivity.ts.mustache +183 -0
- package/templates/interactivity/src/save.tsx.mustache +87 -0
- package/templates/interactivity/src/style.scss.mustache +60 -0
- package/templates/interactivity/src/types.ts.mustache +30 -0
- package/templates/interactivity/tsconfig.json.mustache +20 -0
- package/templates/interactivity/webpack.config.js.mustache +89 -0
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { syncBlockMetadata } from "./lib/typia-metadata-core";
|
|
2
|
+
|
|
3
|
+
async function main() {
|
|
4
|
+
const result = await syncBlockMetadata({
|
|
5
|
+
blockJsonFile: "src/block.json",
|
|
6
|
+
manifestFile: "src/typia.manifest.json",
|
|
7
|
+
sourceTypeName: "{{pascalCase}}Attributes",
|
|
8
|
+
typesFile: "src/types.ts",
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
console.log("✅ block.json, typia.manifest.json, and typia-validator.php were generated from TypeScript types!");
|
|
12
|
+
console.log("📝 Generated attributes:", result.attributeNames);
|
|
13
|
+
|
|
14
|
+
if (result.lossyProjectionWarnings.length > 0) {
|
|
15
|
+
console.warn("⚠️ Some Typia constraints were preserved only in typia.manifest.json:");
|
|
16
|
+
for (const warning of result.lossyProjectionWarnings) {
|
|
17
|
+
console.warn(` - ${warning}`);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (result.phpGenerationWarnings.length > 0) {
|
|
22
|
+
console.warn("⚠️ Some Typia constraints are not yet enforced by typia-validator.php:");
|
|
23
|
+
for (const warning of result.phpGenerationWarnings) {
|
|
24
|
+
console.warn(` - ${warning}`);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
main().catch((error) => {
|
|
30
|
+
console.error("❌ Type sync failed:", error);
|
|
31
|
+
process.exit(1);
|
|
32
|
+
});
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://schemas.wp.org/trunk/block.json",
|
|
3
|
+
"apiVersion": 3,
|
|
4
|
+
"name": "create-block/{{slugKebabCase}}",
|
|
5
|
+
"version": "0.1.0",
|
|
6
|
+
"title": "{{title}}",
|
|
7
|
+
"category": "widgets",
|
|
8
|
+
"icon": "smiley",
|
|
9
|
+
"description": "{{description}}",
|
|
10
|
+
"example": {},
|
|
11
|
+
"supports": {
|
|
12
|
+
"html": false,
|
|
13
|
+
"align": true,
|
|
14
|
+
"anchor": true,
|
|
15
|
+
"className": true,
|
|
16
|
+
"interactivity": true
|
|
17
|
+
},
|
|
18
|
+
"attributes": {
|
|
19
|
+
"content": {
|
|
20
|
+
"type": "string",
|
|
21
|
+
"source": "html",
|
|
22
|
+
"selector": ".{{cssClassName}}__content",
|
|
23
|
+
"default": ""
|
|
24
|
+
},
|
|
25
|
+
"alignment": {
|
|
26
|
+
"type": "string",
|
|
27
|
+
"enum": ["left", "center", "right"],
|
|
28
|
+
"default": "left"
|
|
29
|
+
},
|
|
30
|
+
"isVisible": {
|
|
31
|
+
"type": "boolean",
|
|
32
|
+
"default": true
|
|
33
|
+
},
|
|
34
|
+
"interactiveMode": {
|
|
35
|
+
"type": "string",
|
|
36
|
+
"enum": ["click", "hover", "auto"],
|
|
37
|
+
"default": "click"
|
|
38
|
+
},
|
|
39
|
+
"animation": {
|
|
40
|
+
"type": "string",
|
|
41
|
+
"enum": ["none", "bounce", "pulse", "shake", "flip"],
|
|
42
|
+
"default": "none"
|
|
43
|
+
},
|
|
44
|
+
"clickCount": {
|
|
45
|
+
"type": "number",
|
|
46
|
+
"default": 0
|
|
47
|
+
},
|
|
48
|
+
"isAnimating": {
|
|
49
|
+
"type": "boolean",
|
|
50
|
+
"default": false
|
|
51
|
+
},
|
|
52
|
+
"showCounter": {
|
|
53
|
+
"type": "boolean",
|
|
54
|
+
"default": true
|
|
55
|
+
},
|
|
56
|
+
"maxClicks": {
|
|
57
|
+
"type": "number",
|
|
58
|
+
"default": 10
|
|
59
|
+
},
|
|
60
|
+
"autoPlayInterval": {
|
|
61
|
+
"type": "number",
|
|
62
|
+
"default": 0
|
|
63
|
+
},
|
|
64
|
+
"uniqueId": {
|
|
65
|
+
"type": "string",
|
|
66
|
+
"default": ""
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
"textdomain": "{{slugSnakeCase}}",
|
|
70
|
+
"editorScript": "file:./index.js",
|
|
71
|
+
"editorStyle": "file:./index.css",
|
|
72
|
+
"style": "file:./style-index.css",
|
|
73
|
+
"viewScriptModule": "file:./interactivity.js"
|
|
74
|
+
}
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import { __ } from '@wordpress/i18n';
|
|
2
|
+
import { useBlockProps, InspectorControls, RichText, BlockControls, AlignmentToolbar } from '@wordpress/block-editor';
|
|
3
|
+
import { PanelBody, ToggleControl, SelectControl, RangeControl, TextControl, Button, Notice } from '@wordpress/components';
|
|
4
|
+
import { useState, useEffect } from '@wordpress/element';
|
|
5
|
+
import type { {{pascalCase}}Attributes } from './types';
|
|
6
|
+
|
|
7
|
+
export default function Edit({ attributes, setAttributes, isSelected }: {
|
|
8
|
+
attributes: {{pascalCase}}Attributes;
|
|
9
|
+
setAttributes: (attrs: Partial<{{pascalCase}}Attributes>) => void;
|
|
10
|
+
isSelected: boolean;
|
|
11
|
+
}) {
|
|
12
|
+
const [isPreviewing, setIsPreviewing] = useState(false);
|
|
13
|
+
|
|
14
|
+
const blockProps = useBlockProps({
|
|
15
|
+
className: `wp-block-{{slugKebabCase}} wp-block-{{slugKebabCase}}--${attributes.interactiveMode}`,
|
|
16
|
+
'data-wp-interactive': '{{slugKebabCase}}',
|
|
17
|
+
'data-wp-context': JSON.stringify({
|
|
18
|
+
clicks: attributes.clickCount,
|
|
19
|
+
isAnimating: attributes.isAnimating,
|
|
20
|
+
isVisible: attributes.isVisible,
|
|
21
|
+
lastInteraction: '',
|
|
22
|
+
animation: attributes.animation,
|
|
23
|
+
interactiveMode: attributes.interactiveMode,
|
|
24
|
+
maxClicks: attributes.maxClicks,
|
|
25
|
+
autoPlayInterval: attributes.autoPlayInterval
|
|
26
|
+
})
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
const resetCounter = () => {
|
|
30
|
+
setAttributes({ clickCount: 0, isAnimating: false });
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const testAnimation = () => {
|
|
34
|
+
setAttributes({ isAnimating: true });
|
|
35
|
+
setTimeout(() => {
|
|
36
|
+
setAttributes({ isAnimating: false });
|
|
37
|
+
}, 1000);
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
return (
|
|
41
|
+
<>
|
|
42
|
+
<BlockControls>
|
|
43
|
+
<AlignmentToolbar
|
|
44
|
+
value={attributes.alignment}
|
|
45
|
+
onChange={(value) => setAttributes({ alignment: value || 'left' })}
|
|
46
|
+
/>
|
|
47
|
+
</BlockControls>
|
|
48
|
+
|
|
49
|
+
<InspectorControls>
|
|
50
|
+
<PanelBody title={__('Interactive Settings', '{{slugSnakeCase}}')}>
|
|
51
|
+
<SelectControl
|
|
52
|
+
label={__('Interactive Mode', '{{slugSnakeCase}}')}
|
|
53
|
+
value={attributes.interactiveMode}
|
|
54
|
+
options={[
|
|
55
|
+
{ label: __('Click', '{{slugSnakeCase}}'), value: 'click' },
|
|
56
|
+
{ label: __('Hover', '{{slugSnakeCase}}'), value: 'hover' },
|
|
57
|
+
{ label: __('Auto Play', '{{slugSnakeCase}}'), value: 'auto' }
|
|
58
|
+
]}
|
|
59
|
+
onChange={(value) => setAttributes({ interactiveMode: value })}
|
|
60
|
+
/>
|
|
61
|
+
|
|
62
|
+
<SelectControl
|
|
63
|
+
label={__('Animation', '{{slugSnakeCase}}')}
|
|
64
|
+
value={attributes.animation}
|
|
65
|
+
options={[
|
|
66
|
+
{ label: __('None', '{{slugSnakeCase}}'), value: 'none' },
|
|
67
|
+
{ label: __('Bounce', '{{slugSnakeCase}}'), value: 'bounce' },
|
|
68
|
+
{ label: __('Pulse', '{{slugSnakeCase}}'), value: 'pulse' },
|
|
69
|
+
{ label: __('Shake', '{{slugSnakeCase}}'), value: 'shake' },
|
|
70
|
+
{ label: __('Flip', '{{slugSnakeCase}}'), value: 'flip' }
|
|
71
|
+
]}
|
|
72
|
+
onChange={(value) => setAttributes({ animation: value })}
|
|
73
|
+
/>
|
|
74
|
+
|
|
75
|
+
<ToggleControl
|
|
76
|
+
label={__('Show Counter', '{{slugSnakeCase}}')}
|
|
77
|
+
checked={attributes.showCounter}
|
|
78
|
+
onChange={(value) => setAttributes({ showCounter: value })}
|
|
79
|
+
/>
|
|
80
|
+
|
|
81
|
+
<ToggleControl
|
|
82
|
+
label={__('Visible', '{{slugSnakeCase}}')}
|
|
83
|
+
checked={attributes.isVisible}
|
|
84
|
+
onChange={(value) => setAttributes({ isVisible: value })}
|
|
85
|
+
/>
|
|
86
|
+
</PanelBody>
|
|
87
|
+
|
|
88
|
+
<PanelBody title={__('Counter Settings', '{{slugSnakeCase}}')}>
|
|
89
|
+
<RangeControl
|
|
90
|
+
label={__('Max Clicks', '{{slugSnakeCase}}')}
|
|
91
|
+
value={attributes.maxClicks}
|
|
92
|
+
onChange={(value) => setAttributes({ maxClicks: value })}
|
|
93
|
+
min={0}
|
|
94
|
+
max={100}
|
|
95
|
+
help={__('Set to 0 for unlimited clicks', '{{slugSnakeCase}}')}
|
|
96
|
+
/>
|
|
97
|
+
|
|
98
|
+
{attributes.interactiveMode === 'auto' && (
|
|
99
|
+
<RangeControl
|
|
100
|
+
label={__('Auto Play Interval (ms)', '{{slugSnakeCase}}')}
|
|
101
|
+
value={attributes.autoPlayInterval}
|
|
102
|
+
onChange={(value) => setAttributes({ autoPlayInterval: value })}
|
|
103
|
+
min={100}
|
|
104
|
+
max={5000}
|
|
105
|
+
step={100}
|
|
106
|
+
help={__('Interval between automatic animations', '{{slugSnakeCase}}')}
|
|
107
|
+
/>
|
|
108
|
+
)}
|
|
109
|
+
|
|
110
|
+
<div style={{ display: 'flex', gap: '8px', marginTop: '16px' }}>
|
|
111
|
+
<Button
|
|
112
|
+
variant="secondary"
|
|
113
|
+
onClick={resetCounter}
|
|
114
|
+
isSmall
|
|
115
|
+
>
|
|
116
|
+
{__('Reset Counter', '{{slugSnakeCase}}')}
|
|
117
|
+
</Button>
|
|
118
|
+
<Button
|
|
119
|
+
variant="secondary"
|
|
120
|
+
onClick={testAnimation}
|
|
121
|
+
isSmall
|
|
122
|
+
>
|
|
123
|
+
{__('Test Animation', '{{slugSnakeCase}}')}
|
|
124
|
+
</Button>
|
|
125
|
+
</div>
|
|
126
|
+
|
|
127
|
+
<TextControl
|
|
128
|
+
label={__('Unique ID', '{{slugSnakeCase}}')}
|
|
129
|
+
value={attributes.uniqueId}
|
|
130
|
+
onChange={(value) => setAttributes({ uniqueId: value })}
|
|
131
|
+
help={__('Optional unique identifier for this block instance', '{{slugSnakeCase}}')}
|
|
132
|
+
/>
|
|
133
|
+
</PanelBody>
|
|
134
|
+
|
|
135
|
+
{isSelected && (
|
|
136
|
+
<PanelBody title={__('Preview', '{{slugSnakeCase}}')}>
|
|
137
|
+
<ToggleControl
|
|
138
|
+
label={__('Enable Preview Mode', '{{slugSnakeCase}}')}
|
|
139
|
+
checked={isPreviewing}
|
|
140
|
+
onChange={setIsPreviewing}
|
|
141
|
+
help={__('Test interactions in the editor', '{{slugSnakeCase}}')}
|
|
142
|
+
/>
|
|
143
|
+
|
|
144
|
+
{attributes.clickCount > 0 && (
|
|
145
|
+
<Notice status="info" isDismissible={false}>
|
|
146
|
+
{__('Current clicks:', '{{slugSnakeCase}}')} {attributes.clickCount}
|
|
147
|
+
{attributes.maxClicks > 0 && ` / ${attributes.maxClicks}`}
|
|
148
|
+
</Notice>
|
|
149
|
+
)}
|
|
150
|
+
</PanelBody>
|
|
151
|
+
)}
|
|
152
|
+
</InspectorControls>
|
|
153
|
+
|
|
154
|
+
<div {...blockProps}>
|
|
155
|
+
<div
|
|
156
|
+
className={`{{cssClassName}}__content ${attributes.isAnimating ? 'is-animating' : ''}`}
|
|
157
|
+
style={{ textAlign: attributes.alignment }}
|
|
158
|
+
data-wp-on--click={isPreviewing ? 'actions.handleClick' : undefined}
|
|
159
|
+
data-wp-on--mouseenter={isPreviewing && attributes.interactiveMode === 'hover' ? 'actions.handleMouseEnter' : undefined}
|
|
160
|
+
data-wp-on--mouseleave={isPreviewing && attributes.interactiveMode === 'hover' ? 'actions.handleMouseLeave' : undefined}
|
|
161
|
+
>
|
|
162
|
+
<RichText
|
|
163
|
+
tagName="p"
|
|
164
|
+
value={attributes.content}
|
|
165
|
+
onChange={(value) => setAttributes({ content: value })}
|
|
166
|
+
placeholder={__('{{title}} – click me to interact!', '{{slugSnakeCase}}')}
|
|
167
|
+
withoutInteractiveFormatting
|
|
168
|
+
/>
|
|
169
|
+
|
|
170
|
+
{attributes.showCounter && (
|
|
171
|
+
<div className="{{cssClassName}}__counter">
|
|
172
|
+
<span className="{{cssClassName}}__counter-label">
|
|
173
|
+
{__('Clicks:', '{{slugSnakeCase}}')}
|
|
174
|
+
</span>
|
|
175
|
+
<span
|
|
176
|
+
className="{{cssClassName}}__counter-value"
|
|
177
|
+
data-wp-text="state.clicks"
|
|
178
|
+
>
|
|
179
|
+
{attributes.clickCount}
|
|
180
|
+
</span>
|
|
181
|
+
</div>
|
|
182
|
+
)}
|
|
183
|
+
|
|
184
|
+
{attributes.maxClicks > 0 && (
|
|
185
|
+
<div className="{{cssClassName}}__progress">
|
|
186
|
+
<div
|
|
187
|
+
className="{{cssClassName}}__progress-bar"
|
|
188
|
+
style={{ width: `${(attributes.clickCount / attributes.maxClicks) * 100}%` }}
|
|
189
|
+
data-wp-style--width="state.progress + '%'"
|
|
190
|
+
/>
|
|
191
|
+
</div>
|
|
192
|
+
)}
|
|
193
|
+
|
|
194
|
+
{attributes.animation !== 'none' && (
|
|
195
|
+
<div
|
|
196
|
+
className={`{{cssClassName}}__animation ${attributes.isAnimating ? 'is-active' : ''}`}
|
|
197
|
+
data-wp-class="is-active"
|
|
198
|
+
>
|
|
199
|
+
{attributes.animation}
|
|
200
|
+
</div>
|
|
201
|
+
)}
|
|
202
|
+
</div>
|
|
203
|
+
</div>
|
|
204
|
+
</>
|
|
205
|
+
);
|
|
206
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { registerBlockType } from '@wordpress/blocks';
|
|
2
|
+
|
|
3
|
+
import Edit from './edit';
|
|
4
|
+
import Save from './save';
|
|
5
|
+
import metadata from './block.json';
|
|
6
|
+
import './style.scss';
|
|
7
|
+
|
|
8
|
+
import type { {{pascalCase}}Attributes } from './types';
|
|
9
|
+
|
|
10
|
+
registerBlockType<{{pascalCase}}Attributes>(metadata.name, {
|
|
11
|
+
title: metadata.title,
|
|
12
|
+
description: metadata.description,
|
|
13
|
+
category: metadata.category as any,
|
|
14
|
+
icon: metadata.icon as any,
|
|
15
|
+
supports: metadata.supports,
|
|
16
|
+
attributes: metadata.attributes,
|
|
17
|
+
example: metadata.example,
|
|
18
|
+
edit: Edit,
|
|
19
|
+
save: Save,
|
|
20
|
+
});
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress Interactivity API implementation for {{title}} block
|
|
3
|
+
*/
|
|
4
|
+
import { store, getContext, getElement } from '@wordpress/interactivity';
|
|
5
|
+
|
|
6
|
+
// Store configuration
|
|
7
|
+
store('{{slugKebabCase}}', {
|
|
8
|
+
// State - reactive data that updates the UI
|
|
9
|
+
state: {
|
|
10
|
+
get clicks() {
|
|
11
|
+
return getContext().clicks;
|
|
12
|
+
},
|
|
13
|
+
get isAnimating() {
|
|
14
|
+
return getContext().isAnimating;
|
|
15
|
+
},
|
|
16
|
+
get isVisible() {
|
|
17
|
+
return getContext().isVisible;
|
|
18
|
+
},
|
|
19
|
+
get animationClass() {
|
|
20
|
+
const context = getContext();
|
|
21
|
+
if (!context.isAnimating) return '';
|
|
22
|
+
|
|
23
|
+
switch (context.animation) {
|
|
24
|
+
case 'bounce':
|
|
25
|
+
return 'animate-bounce';
|
|
26
|
+
case 'pulse':
|
|
27
|
+
return 'animate-pulse';
|
|
28
|
+
case 'shake':
|
|
29
|
+
return 'animate-shake';
|
|
30
|
+
case 'flip':
|
|
31
|
+
return 'animate-flip';
|
|
32
|
+
default:
|
|
33
|
+
return '';
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
get progress() {
|
|
37
|
+
const context = getContext();
|
|
38
|
+
return context.maxClicks > 0 ? (context.clicks / context.maxClicks) * 100 : 0;
|
|
39
|
+
},
|
|
40
|
+
get isComplete() {
|
|
41
|
+
const context = getContext();
|
|
42
|
+
return context.clicks >= context.maxClicks && context.maxClicks > 0;
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
|
|
46
|
+
// Actions - user interactions
|
|
47
|
+
actions: {
|
|
48
|
+
// Handle block click
|
|
49
|
+
handleClick: () => {
|
|
50
|
+
const context = getContext();
|
|
51
|
+
const { element } = getElement();
|
|
52
|
+
|
|
53
|
+
// Increment click counter
|
|
54
|
+
context.clicks += 1;
|
|
55
|
+
context.lastInteraction = 'click';
|
|
56
|
+
|
|
57
|
+
// Trigger animation
|
|
58
|
+
if (context.animation !== 'none') {
|
|
59
|
+
context.isAnimating = true;
|
|
60
|
+
setTimeout(() => {
|
|
61
|
+
context.isAnimating = false;
|
|
62
|
+
}, 1000);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Emit custom event
|
|
66
|
+
element.dispatchEvent(new CustomEvent('{{slugKebabCase}}:click', {
|
|
67
|
+
detail: { clicks: context.clicks }
|
|
68
|
+
}));
|
|
69
|
+
|
|
70
|
+
// Check if max clicks reached
|
|
71
|
+
if (context.maxClicks > 0 && context.clicks >= context.maxClicks) {
|
|
72
|
+
element.dispatchEvent(new CustomEvent('{{slugKebabCase}}:complete', {
|
|
73
|
+
detail: { totalClicks: context.clicks }
|
|
74
|
+
}));
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
|
|
78
|
+
// Handle hover events
|
|
79
|
+
handleMouseEnter: () => {
|
|
80
|
+
const context = getContext();
|
|
81
|
+
if (context.interactiveMode === 'hover') {
|
|
82
|
+
context.isAnimating = true;
|
|
83
|
+
context.lastInteraction = 'hover';
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
|
|
87
|
+
handleMouseLeave: () => {
|
|
88
|
+
const context = getContext();
|
|
89
|
+
if (context.interactiveMode === 'hover') {
|
|
90
|
+
context.isAnimating = false;
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
|
|
94
|
+
// Toggle visibility
|
|
95
|
+
toggleVisibility: () => {
|
|
96
|
+
const context = getContext();
|
|
97
|
+
context.isVisible = !context.isVisible;
|
|
98
|
+
},
|
|
99
|
+
|
|
100
|
+
// Reset counter
|
|
101
|
+
reset: () => {
|
|
102
|
+
const context = getContext();
|
|
103
|
+
context.clicks = 0;
|
|
104
|
+
context.isAnimating = false;
|
|
105
|
+
context.lastInteraction = 'reset';
|
|
106
|
+
},
|
|
107
|
+
|
|
108
|
+
// Start/stop auto play
|
|
109
|
+
toggleAutoPlay: () => {
|
|
110
|
+
const context = getContext();
|
|
111
|
+
if (context.autoPlayInterval > 0) {
|
|
112
|
+
if (context.autoPlayTimer) {
|
|
113
|
+
clearInterval(context.autoPlayTimer);
|
|
114
|
+
context.autoPlayTimer = null;
|
|
115
|
+
} else {
|
|
116
|
+
context.autoPlayTimer = setInterval(() => {
|
|
117
|
+
context.clicks += 1;
|
|
118
|
+
context.isAnimating = true;
|
|
119
|
+
setTimeout(() => {
|
|
120
|
+
context.isAnimating = false;
|
|
121
|
+
}, 500);
|
|
122
|
+
}, context.autoPlayInterval);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
},
|
|
127
|
+
|
|
128
|
+
// Callbacks - lifecycle hooks
|
|
129
|
+
callbacks: {
|
|
130
|
+
// Initialize on mount
|
|
131
|
+
onInit: () => {
|
|
132
|
+
const context = getContext();
|
|
133
|
+
const { element } = getElement();
|
|
134
|
+
|
|
135
|
+
// Set initial state from attributes
|
|
136
|
+
context.clicks = parseInt(element.dataset.clicks || '0');
|
|
137
|
+
context.isAnimating = element.dataset.isAnimating === 'true';
|
|
138
|
+
context.isVisible = element.dataset.isVisible !== 'false';
|
|
139
|
+
|
|
140
|
+
// Set up event listeners
|
|
141
|
+
element.addEventListener('{{slugKebabCase}}:external-trigger', (event: any) => {
|
|
142
|
+
context.clicks = event.detail.clicks || context.clicks + 1;
|
|
143
|
+
});
|
|
144
|
+
},
|
|
145
|
+
|
|
146
|
+
// Log interactions
|
|
147
|
+
onInteraction: () => {
|
|
148
|
+
const context = getContext();
|
|
149
|
+
console.log(`{{slugKebabCase}} interaction:`, {
|
|
150
|
+
clicks: context.clicks,
|
|
151
|
+
type: context.lastInteraction,
|
|
152
|
+
timestamp: new Date().toISOString()
|
|
153
|
+
});
|
|
154
|
+
},
|
|
155
|
+
|
|
156
|
+
// Cleanup on unmount
|
|
157
|
+
onDestroy: () => {
|
|
158
|
+
const context = getContext();
|
|
159
|
+
if (context.autoPlayTimer) {
|
|
160
|
+
clearInterval(context.autoPlayTimer);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
// Type definitions for TypeScript
|
|
167
|
+
declare global {
|
|
168
|
+
namespace WordPress {
|
|
169
|
+
namespace Interactivity {
|
|
170
|
+
interface {{pascalCase}}Context {
|
|
171
|
+
clicks: number;
|
|
172
|
+
isAnimating: boolean;
|
|
173
|
+
isVisible: boolean;
|
|
174
|
+
lastInteraction: string;
|
|
175
|
+
animation: string;
|
|
176
|
+
interactiveMode: string;
|
|
177
|
+
maxClicks: number;
|
|
178
|
+
autoPlayInterval: number;
|
|
179
|
+
autoPlayTimer?: number;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { useBlockProps, RichText } from '@wordpress/block-editor';
|
|
2
|
+
import type { {{pascalCase}}Attributes } from './types';
|
|
3
|
+
|
|
4
|
+
export default function Save({ attributes }: { attributes: {{pascalCase}}Attributes }) {
|
|
5
|
+
const blockProps = useBlockProps.save({
|
|
6
|
+
className: `wp-block-{{slugKebabCase}} wp-block-{{slugKebabCase}}--${attributes.interactiveMode}`,
|
|
7
|
+
'data-wp-interactive': '{{slugKebabCase}}',
|
|
8
|
+
'data-wp-context': JSON.stringify({
|
|
9
|
+
clicks: attributes.clickCount,
|
|
10
|
+
isAnimating: attributes.isAnimating,
|
|
11
|
+
isVisible: attributes.isVisible,
|
|
12
|
+
lastInteraction: '',
|
|
13
|
+
animation: attributes.animation,
|
|
14
|
+
interactiveMode: attributes.interactiveMode,
|
|
15
|
+
maxClicks: attributes.maxClicks,
|
|
16
|
+
autoPlayInterval: attributes.autoPlayInterval
|
|
17
|
+
}),
|
|
18
|
+
'data-clicks': attributes.clickCount,
|
|
19
|
+
'data-is-animating': attributes.isAnimating,
|
|
20
|
+
'data-is-visible': attributes.isVisible,
|
|
21
|
+
'data-unique-id': attributes.uniqueId
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
return (
|
|
25
|
+
<div {...blockProps}>
|
|
26
|
+
<div
|
|
27
|
+
className={`{{cssClassName}}__content ${attributes.isAnimating ? 'is-animating' : ''}`}
|
|
28
|
+
style={{ textAlign: attributes.alignment }}
|
|
29
|
+
data-wp-on--click="actions.handleClick"
|
|
30
|
+
data-wp-on--mouseenter={attributes.interactiveMode === 'hover' ? 'actions.handleMouseEnter' : undefined}
|
|
31
|
+
data-wp-on--mouseleave={attributes.interactiveMode === 'hover' ? 'actions.handleMouseLeave' : undefined}
|
|
32
|
+
data-wp-bind--hidden="!state.isVisible"
|
|
33
|
+
>
|
|
34
|
+
<RichText.Content
|
|
35
|
+
tagName="p"
|
|
36
|
+
value={attributes.content}
|
|
37
|
+
className="{{cssClassName}}__text"
|
|
38
|
+
/>
|
|
39
|
+
|
|
40
|
+
{attributes.showCounter && (
|
|
41
|
+
<div className="{{cssClassName}}__counter">
|
|
42
|
+
<span className="{{cssClassName}}__counter-label">
|
|
43
|
+
Clicks:
|
|
44
|
+
</span>
|
|
45
|
+
<span
|
|
46
|
+
className="{{cssClassName}}__counter-value"
|
|
47
|
+
data-wp-text="state.clicks"
|
|
48
|
+
>
|
|
49
|
+
{attributes.clickCount}
|
|
50
|
+
</span>
|
|
51
|
+
</div>
|
|
52
|
+
)}
|
|
53
|
+
|
|
54
|
+
{attributes.maxClicks > 0 && (
|
|
55
|
+
<div className="{{cssClassName}}__progress">
|
|
56
|
+
<div
|
|
57
|
+
className="{{cssClassName}}__progress-bar"
|
|
58
|
+
data-wp-style--width="state.progress + '%'"
|
|
59
|
+
/>
|
|
60
|
+
</div>
|
|
61
|
+
)}
|
|
62
|
+
|
|
63
|
+
<div
|
|
64
|
+
className={`{{cssClassName}}__animation ${attributes.animation}`}
|
|
65
|
+
data-wp-class="is-active"
|
|
66
|
+
/>
|
|
67
|
+
|
|
68
|
+
{attributes.maxClicks > 0 && (
|
|
69
|
+
<div
|
|
70
|
+
className="{{cssClassName}}__completion"
|
|
71
|
+
data-wp-bind--hidden="!state.isComplete"
|
|
72
|
+
>
|
|
73
|
+
🎉 Complete!
|
|
74
|
+
</div>
|
|
75
|
+
)}
|
|
76
|
+
|
|
77
|
+
<button
|
|
78
|
+
className="{{cssClassName}}__reset"
|
|
79
|
+
data-wp-on--click="actions.reset"
|
|
80
|
+
aria-label="Reset counter"
|
|
81
|
+
>
|
|
82
|
+
↻
|
|
83
|
+
</button>
|
|
84
|
+
</div>
|
|
85
|
+
</div>
|
|
86
|
+
);
|
|
87
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
.wp-block-{{slugKebabCase}} {
|
|
2
|
+
position: relative;
|
|
3
|
+
padding: 1rem;
|
|
4
|
+
border: 1px solid #dcdcde;
|
|
5
|
+
border-radius: 0.75rem;
|
|
6
|
+
background: #fff;
|
|
7
|
+
|
|
8
|
+
&__content {
|
|
9
|
+
display: grid;
|
|
10
|
+
gap: 0.75rem;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
&__counter {
|
|
14
|
+
display: inline-flex;
|
|
15
|
+
gap: 0.35rem;
|
|
16
|
+
align-items: center;
|
|
17
|
+
font-size: 0.9rem;
|
|
18
|
+
font-weight: 600;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
&__progress {
|
|
22
|
+
width: 100%;
|
|
23
|
+
height: 0.5rem;
|
|
24
|
+
overflow: hidden;
|
|
25
|
+
background: #f0f0f1;
|
|
26
|
+
border-radius: 999px;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
&__progress-bar {
|
|
30
|
+
height: 100%;
|
|
31
|
+
background: #3858e9;
|
|
32
|
+
transition: width 0.2s ease;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
&__animation {
|
|
36
|
+
min-height: 1.5rem;
|
|
37
|
+
font-size: 0.85rem;
|
|
38
|
+
color: #3858e9;
|
|
39
|
+
opacity: 0;
|
|
40
|
+
transition: opacity 0.2s ease;
|
|
41
|
+
|
|
42
|
+
&.is-active {
|
|
43
|
+
opacity: 1;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
&__completion {
|
|
48
|
+
font-weight: 700;
|
|
49
|
+
color: #06752d;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
&__reset {
|
|
53
|
+
align-self: start;
|
|
54
|
+
padding: 0.4rem 0.7rem;
|
|
55
|
+
border: 1px solid #dcdcde;
|
|
56
|
+
border-radius: 999px;
|
|
57
|
+
background: transparent;
|
|
58
|
+
cursor: pointer;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { TextAlignment } from "@wp-typia/block-types/block-editor/alignment";
|
|
2
|
+
import { tags } from "typia";
|
|
3
|
+
|
|
4
|
+
export interface {{pascalCase}}Attributes {
|
|
5
|
+
content: string & tags.MinLength<1> & tags.MaxLength<1000> & tags.Default<"">;
|
|
6
|
+
alignment?: TextAlignment & tags.Default<"left">;
|
|
7
|
+
isVisible?: boolean & tags.Default<true>;
|
|
8
|
+
interactiveMode?: ('click' | 'hover' | 'auto') & tags.Default<"click">;
|
|
9
|
+
animation?: ('none' | 'bounce' | 'pulse' | 'shake' | 'flip') & tags.Default<"none">;
|
|
10
|
+
clickCount?: number & tags.Default<0>;
|
|
11
|
+
isAnimating?: boolean & tags.Default<false>;
|
|
12
|
+
showCounter?: boolean & tags.Default<true>;
|
|
13
|
+
maxClicks?: number & tags.Default<10>;
|
|
14
|
+
autoPlayInterval?: number & tags.Default<0>;
|
|
15
|
+
uniqueId?: string & tags.Default<"">;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface {{pascalCase}}Context {
|
|
19
|
+
clicks: number;
|
|
20
|
+
isAnimating: boolean;
|
|
21
|
+
isVisible: boolean;
|
|
22
|
+
lastInteraction: string;
|
|
23
|
+
animationClass: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export type {{pascalCase}}ValidationResult = {
|
|
27
|
+
isValid: boolean;
|
|
28
|
+
errors: string[];
|
|
29
|
+
data?: {{pascalCase}}Attributes;
|
|
30
|
+
};
|