@wp-typia/project-tools 0.11.1

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.
Files changed (187) hide show
  1. package/README.md +32 -0
  2. package/dist/runtime/cli-add.d.ts +38 -0
  3. package/dist/runtime/cli-add.js +561 -0
  4. package/dist/runtime/cli-core.d.ts +25 -0
  5. package/dist/runtime/cli-core.js +25 -0
  6. package/dist/runtime/cli-doctor.d.ts +34 -0
  7. package/dist/runtime/cli-doctor.js +131 -0
  8. package/dist/runtime/cli-help.d.ts +9 -0
  9. package/dist/runtime/cli-help.js +37 -0
  10. package/dist/runtime/cli-prompt.d.ts +21 -0
  11. package/dist/runtime/cli-prompt.js +53 -0
  12. package/dist/runtime/cli-scaffold.d.ts +79 -0
  13. package/dist/runtime/cli-scaffold.js +206 -0
  14. package/dist/runtime/cli-templates.d.ts +30 -0
  15. package/dist/runtime/cli-templates.js +61 -0
  16. package/dist/runtime/index.d.ts +9 -0
  17. package/dist/runtime/index.js +7 -0
  18. package/dist/runtime/json-utils.d.ts +10 -0
  19. package/dist/runtime/json-utils.js +12 -0
  20. package/dist/runtime/local-dev-presets.d.ts +26 -0
  21. package/dist/runtime/local-dev-presets.js +132 -0
  22. package/dist/runtime/metadata-analysis.d.ts +11 -0
  23. package/dist/runtime/metadata-analysis.js +285 -0
  24. package/dist/runtime/metadata-model.d.ts +84 -0
  25. package/dist/runtime/metadata-model.js +59 -0
  26. package/dist/runtime/metadata-parser.d.ts +53 -0
  27. package/dist/runtime/metadata-parser.js +794 -0
  28. package/dist/runtime/metadata-php-render.d.ts +29 -0
  29. package/dist/runtime/metadata-php-render.js +549 -0
  30. package/dist/runtime/metadata-projection.d.ts +7 -0
  31. package/dist/runtime/metadata-projection.js +233 -0
  32. package/dist/runtime/migration-constants.d.ts +15 -0
  33. package/dist/runtime/migration-constants.js +16 -0
  34. package/dist/runtime/migration-diff.d.ts +2 -0
  35. package/dist/runtime/migration-diff.js +537 -0
  36. package/dist/runtime/migration-fixtures.d.ts +8 -0
  37. package/dist/runtime/migration-fixtures.js +94 -0
  38. package/dist/runtime/migration-fuzz-plan.d.ts +2 -0
  39. package/dist/runtime/migration-fuzz-plan.js +50 -0
  40. package/dist/runtime/migration-manifest.d.ts +19 -0
  41. package/dist/runtime/migration-manifest.js +129 -0
  42. package/dist/runtime/migration-project.d.ts +94 -0
  43. package/dist/runtime/migration-project.js +1101 -0
  44. package/dist/runtime/migration-render.d.ts +11 -0
  45. package/dist/runtime/migration-render.js +741 -0
  46. package/dist/runtime/migration-risk.d.ts +4 -0
  47. package/dist/runtime/migration-risk.js +52 -0
  48. package/dist/runtime/migration-types.d.ts +249 -0
  49. package/dist/runtime/migration-types.js +1 -0
  50. package/dist/runtime/migration-ui-capability.d.ts +17 -0
  51. package/dist/runtime/migration-ui-capability.js +190 -0
  52. package/dist/runtime/migration-utils.d.ts +69 -0
  53. package/dist/runtime/migration-utils.js +246 -0
  54. package/dist/runtime/migrations.d.ts +249 -0
  55. package/dist/runtime/migrations.js +1061 -0
  56. package/dist/runtime/object-utils.d.ts +12 -0
  57. package/dist/runtime/object-utils.js +14 -0
  58. package/dist/runtime/package-managers.d.ts +28 -0
  59. package/dist/runtime/package-managers.js +156 -0
  60. package/dist/runtime/package-versions.d.ts +10 -0
  61. package/dist/runtime/package-versions.js +68 -0
  62. package/dist/runtime/scaffold-onboarding.d.ts +32 -0
  63. package/dist/runtime/scaffold-onboarding.js +99 -0
  64. package/dist/runtime/scaffold.d.ts +146 -0
  65. package/dist/runtime/scaffold.js +612 -0
  66. package/dist/runtime/schema-core.d.ts +267 -0
  67. package/dist/runtime/schema-core.js +597 -0
  68. package/dist/runtime/starter-manifests.d.ts +25 -0
  69. package/dist/runtime/starter-manifests.js +383 -0
  70. package/dist/runtime/string-case.d.ts +36 -0
  71. package/dist/runtime/string-case.js +69 -0
  72. package/dist/runtime/template-builtins.d.ts +38 -0
  73. package/dist/runtime/template-builtins.js +72 -0
  74. package/dist/runtime/template-defaults.d.ts +75 -0
  75. package/dist/runtime/template-defaults.js +65 -0
  76. package/dist/runtime/template-registry.d.ts +36 -0
  77. package/dist/runtime/template-registry.js +94 -0
  78. package/dist/runtime/template-render.d.ts +24 -0
  79. package/dist/runtime/template-render.js +113 -0
  80. package/dist/runtime/template-source.d.ts +71 -0
  81. package/dist/runtime/template-source.js +821 -0
  82. package/dist/runtime/typia-tags.d.ts +1 -0
  83. package/dist/runtime/typia-tags.js +1 -0
  84. package/package.json +79 -0
  85. package/templates/_shared/base/languages/.gitkeep +1 -0
  86. package/templates/_shared/base/package.json.mustache +41 -0
  87. package/templates/_shared/base/scripts/sync-types-to-block-json.ts.mustache +118 -0
  88. package/templates/_shared/base/src/hooks.ts.mustache +19 -0
  89. package/templates/_shared/base/src/validator-toolkit.ts.mustache +31 -0
  90. package/templates/_shared/base/tsconfig.json.mustache +21 -0
  91. package/templates/_shared/base/webpack.config.js.mustache +99 -0
  92. package/templates/_shared/base/{{slugKebabCase}}.php.mustache +53 -0
  93. package/templates/_shared/compound/core/package.json.mustache +45 -0
  94. package/templates/_shared/compound/core/scripts/add-compound-child.ts.mustache +559 -0
  95. package/templates/_shared/compound/core/scripts/block-config.ts.mustache +13 -0
  96. package/templates/_shared/compound/core/scripts/sync-types-to-block-json.ts.mustache +53 -0
  97. package/templates/_shared/compound/core/webpack.config.js.mustache +141 -0
  98. package/templates/_shared/compound/core/{{slugKebabCase}}.php.mustache +51 -0
  99. package/templates/_shared/compound/persistence/package.json.mustache +50 -0
  100. package/templates/_shared/compound/persistence/scripts/block-config.ts.mustache +59 -0
  101. package/templates/_shared/compound/persistence/scripts/sync-rest-contracts.ts.mustache +101 -0
  102. package/templates/_shared/compound/persistence/src/blocks/{{slugKebabCase}}/api-types.ts.mustache +21 -0
  103. package/templates/_shared/compound/persistence/src/blocks/{{slugKebabCase}}/api-validators.ts.mustache +32 -0
  104. package/templates/_shared/compound/persistence/src/blocks/{{slugKebabCase}}/api.ts.mustache +68 -0
  105. package/templates/_shared/compound/persistence/src/blocks/{{slugKebabCase}}/block.json.mustache +52 -0
  106. package/templates/_shared/compound/persistence/src/blocks/{{slugKebabCase}}/data.ts.mustache +192 -0
  107. package/templates/_shared/compound/persistence/src/blocks/{{slugKebabCase}}/edit.tsx.mustache +123 -0
  108. package/templates/_shared/compound/persistence/src/blocks/{{slugKebabCase}}/hooks.ts.mustache +11 -0
  109. package/templates/_shared/compound/persistence/src/blocks/{{slugKebabCase}}/interactivity.ts.mustache +132 -0
  110. package/templates/_shared/compound/persistence/src/blocks/{{slugKebabCase}}/render.php.mustache +158 -0
  111. package/templates/_shared/compound/persistence/src/blocks/{{slugKebabCase}}/save.tsx.mustache +3 -0
  112. package/templates/_shared/compound/persistence/src/blocks/{{slugKebabCase}}/types.ts.mustache +56 -0
  113. package/templates/_shared/compound/persistence/src/blocks/{{slugKebabCase}}/validators.ts.mustache +32 -0
  114. package/templates/_shared/compound/persistence-auth/{{slugKebabCase}}.php.mustache +294 -0
  115. package/templates/_shared/compound/persistence-public/{{slugKebabCase}}.php.mustache +312 -0
  116. package/templates/_shared/migration-ui/common/src/admin/migration-dashboard.tsx +394 -0
  117. package/templates/_shared/migration-ui/common/src/migration-detector.ts +9 -0
  118. package/templates/_shared/migration-ui/common/src/migrations/helpers.ts +490 -0
  119. package/templates/_shared/migration-ui/common/src/migrations/index.ts +886 -0
  120. package/templates/_shared/persistence/auth/{{slugKebabCase}}.php.mustache +290 -0
  121. package/templates/_shared/persistence/core/package.json.mustache +46 -0
  122. package/templates/_shared/persistence/core/scripts/sync-rest-contracts.ts.mustache +113 -0
  123. package/templates/_shared/persistence/core/scripts/sync-types-to-block-json.ts.mustache +125 -0
  124. package/templates/_shared/persistence/core/src/api-types.ts.mustache +21 -0
  125. package/templates/_shared/persistence/core/src/api-validators.ts.mustache +32 -0
  126. package/templates/_shared/persistence/core/src/api.ts.mustache +68 -0
  127. package/templates/_shared/persistence/core/src/data.ts.mustache +192 -0
  128. package/templates/_shared/persistence/core/src/index.tsx.mustache +25 -0
  129. package/templates/_shared/persistence/core/src/interactivity.ts.mustache +134 -0
  130. package/templates/_shared/persistence/core/src/save.tsx.mustache +5 -0
  131. package/templates/_shared/persistence/core/src/validators.ts.mustache +32 -0
  132. package/templates/_shared/persistence/core/{{slugKebabCase}}.php.mustache +336 -0
  133. package/templates/_shared/persistence/public/{{slugKebabCase}}.php.mustache +308 -0
  134. package/templates/_shared/presets/test-preset/.wp-env.test.json.mustache +16 -0
  135. package/templates/_shared/presets/test-preset/playwright.config.ts.mustache +22 -0
  136. package/templates/_shared/presets/test-preset/scripts/wait-for-wp-env.mjs.mustache +102 -0
  137. package/templates/_shared/presets/test-preset/scripts/wp-env-utils.cjs.mustache +32 -0
  138. package/templates/_shared/presets/test-preset/tests/e2e/smoke.spec.ts.mustache +34 -0
  139. package/templates/_shared/presets/wp-env/.wp-env.json.mustache +16 -0
  140. package/templates/_shared/rest-helpers/auth/inc/rest-auth.php.mustache +37 -0
  141. package/templates/_shared/rest-helpers/public/inc/rest-public.php.mustache +314 -0
  142. package/templates/_shared/rest-helpers/shared/inc/rest-shared.php.mustache +58 -0
  143. package/templates/_shared/workspace/persistence-auth/inc/rest-auth.php.mustache +36 -0
  144. package/templates/_shared/workspace/persistence-auth/inc/rest-shared.php.mustache +55 -0
  145. package/templates/_shared/workspace/persistence-auth/server.php.mustache +237 -0
  146. package/templates/_shared/workspace/persistence-public/inc/rest-public.php.mustache +273 -0
  147. package/templates/_shared/workspace/persistence-public/inc/rest-shared.php.mustache +55 -0
  148. package/templates/_shared/workspace/persistence-public/server.php.mustache +252 -0
  149. package/templates/basic/src/block.json.mustache +51 -0
  150. package/templates/basic/src/edit.tsx.mustache +128 -0
  151. package/templates/basic/src/editor.scss.mustache +8 -0
  152. package/templates/basic/src/hooks.ts.mustache +18 -0
  153. package/templates/basic/src/index.tsx.mustache +45 -0
  154. package/templates/basic/src/save.tsx.mustache +30 -0
  155. package/templates/basic/src/style.scss.mustache +40 -0
  156. package/templates/basic/src/types.ts.mustache +56 -0
  157. package/templates/basic/src/validators.ts.mustache +26 -0
  158. package/templates/compound/src/blocks/{{slugKebabCase}}/block.json.mustache +37 -0
  159. package/templates/compound/src/blocks/{{slugKebabCase}}/children.ts.mustache +25 -0
  160. package/templates/compound/src/blocks/{{slugKebabCase}}/edit.tsx.mustache +93 -0
  161. package/templates/compound/src/blocks/{{slugKebabCase}}/hooks.ts.mustache +11 -0
  162. package/templates/compound/src/blocks/{{slugKebabCase}}/index.tsx.mustache +25 -0
  163. package/templates/compound/src/blocks/{{slugKebabCase}}/save.tsx.mustache +32 -0
  164. package/templates/compound/src/blocks/{{slugKebabCase}}/style.scss.mustache +31 -0
  165. package/templates/compound/src/blocks/{{slugKebabCase}}/types.ts.mustache +13 -0
  166. package/templates/compound/src/blocks/{{slugKebabCase}}/validators.ts.mustache +17 -0
  167. package/templates/compound/src/blocks/{{slugKebabCase}}-item/block.json.mustache +35 -0
  168. package/templates/compound/src/blocks/{{slugKebabCase}}-item/edit.tsx.mustache +50 -0
  169. package/templates/compound/src/blocks/{{slugKebabCase}}-item/hooks.ts.mustache +11 -0
  170. package/templates/compound/src/blocks/{{slugKebabCase}}-item/index.tsx.mustache +25 -0
  171. package/templates/compound/src/blocks/{{slugKebabCase}}-item/save.tsx.mustache +24 -0
  172. package/templates/compound/src/blocks/{{slugKebabCase}}-item/types.ts.mustache +12 -0
  173. package/templates/compound/src/blocks/{{slugKebabCase}}-item/validators.ts.mustache +17 -0
  174. package/templates/interactivity/package.json.mustache +42 -0
  175. package/templates/interactivity/src/block.json.mustache +73 -0
  176. package/templates/interactivity/src/edit.tsx.mustache +270 -0
  177. package/templates/interactivity/src/index.tsx.mustache +32 -0
  178. package/templates/interactivity/src/interactivity.ts.mustache +152 -0
  179. package/templates/interactivity/src/save.tsx.mustache +101 -0
  180. package/templates/interactivity/src/style.scss.mustache +60 -0
  181. package/templates/interactivity/src/types.ts.mustache +32 -0
  182. package/templates/interactivity/src/validators.ts.mustache +36 -0
  183. package/templates/persistence/src/block.json.mustache +52 -0
  184. package/templates/persistence/src/edit.tsx.mustache +165 -0
  185. package/templates/persistence/src/render.php.mustache +126 -0
  186. package/templates/persistence/src/style.scss.mustache +46 -0
  187. package/templates/persistence/src/types.ts.mustache +55 -0
@@ -0,0 +1,252 @@
1
+ <?php
2
+
3
+ if ( ! defined( 'ABSPATH' ) ) {
4
+ exit;
5
+ }
6
+
7
+ require_once __DIR__ . '/inc/rest-shared.php';
8
+ require_once __DIR__ . '/inc/rest-public.php';
9
+
10
+ function {{phpPrefix}}_get_rest_build_dir() {
11
+ return dirname( __DIR__, 3 ) . '/build/blocks/{{slugKebabCase}}';
12
+ }
13
+
14
+ function {{phpPrefix}}_get_counter_table_name() {
15
+ global $wpdb;
16
+ return $wpdb->prefix . '{{phpPrefix}}_counters';
17
+ }
18
+
19
+ function {{phpPrefix}}_get_counter_lock_name( $post_id, $resource_key ) {
20
+ return 'wpt_pcl_' . md5(
21
+ '{{phpPrefix}}|' . (int) $post_id . '|' . (string) $resource_key
22
+ );
23
+ }
24
+
25
+ function {{phpPrefix}}_with_counter_lock( $post_id, $resource_key, $callback ) {
26
+ global $wpdb;
27
+
28
+ $lock_name = {{phpPrefix}}_get_counter_lock_name( $post_id, $resource_key );
29
+ $acquired = (int) $wpdb->get_var(
30
+ $wpdb->prepare(
31
+ 'SELECT GET_LOCK(%s, 5)',
32
+ $lock_name
33
+ )
34
+ );
35
+
36
+ if ( 1 !== $acquired ) {
37
+ return new WP_Error( 'counter_lock_timeout', 'Could not acquire the counter lock.', array( 'status' => 503 ) );
38
+ }
39
+
40
+ try {
41
+ return $callback();
42
+ } finally {
43
+ $wpdb->get_var(
44
+ $wpdb->prepare(
45
+ 'SELECT RELEASE_LOCK(%s)',
46
+ $lock_name
47
+ )
48
+ );
49
+ }
50
+ }
51
+
52
+ function {{phpPrefix}}_maybe_install_storage() {
53
+ if ( 'custom-table' !== '{{dataStorageMode}}' ) {
54
+ return;
55
+ }
56
+
57
+ global $wpdb;
58
+ require_once ABSPATH . 'wp-admin/includes/upgrade.php';
59
+
60
+ $table_name = {{phpPrefix}}_get_counter_table_name();
61
+ $charset_collate = $wpdb->get_charset_collate();
62
+ $sql = "CREATE TABLE {$table_name} (
63
+ post_id bigint(20) unsigned NOT NULL,
64
+ resource_key varchar(100) NOT NULL,
65
+ count bigint(20) unsigned NOT NULL DEFAULT 0,
66
+ updated_at datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
67
+ PRIMARY KEY (post_id, resource_key)
68
+ ) {$charset_collate};";
69
+
70
+ dbDelta( $sql );
71
+ $table_exists = $wpdb->get_var(
72
+ $wpdb->prepare(
73
+ 'SHOW TABLES LIKE %s',
74
+ $table_name
75
+ )
76
+ );
77
+
78
+ if ( $table_name === $table_exists ) {
79
+ update_option( '{{phpPrefix}}_storage_version', '1.0.0' );
80
+ }
81
+ }
82
+
83
+ function {{phpPrefix}}_ensure_storage_installed() {
84
+ if ( 'custom-table' === '{{dataStorageMode}}' && '1.0.0' !== get_option( '{{phpPrefix}}_storage_version', '' ) ) {
85
+ {{phpPrefix}}_maybe_install_storage();
86
+ }
87
+ }
88
+
89
+ function {{phpPrefix}}_get_counter( $post_id, $resource_key ) {
90
+ global $wpdb;
91
+
92
+ if ( 'custom-table' === '{{dataStorageMode}}' ) {
93
+ $table_name = {{phpPrefix}}_get_counter_table_name();
94
+ $count = $wpdb->get_var(
95
+ $wpdb->prepare(
96
+ // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- Table name comes from an internal helper.
97
+ "SELECT count FROM {$table_name} WHERE post_id = %d AND resource_key = %s",
98
+ $post_id,
99
+ $resource_key
100
+ )
101
+ );
102
+
103
+ return null === $count ? 0 : (int) $count;
104
+ }
105
+
106
+ $meta_key = '_' . '{{phpPrefix}}' . '_counter_' . sanitize_key( $resource_key );
107
+ return (int) get_post_meta( $post_id, $meta_key, true );
108
+ }
109
+
110
+ function {{phpPrefix}}_increment_counter( $post_id, $resource_key, $delta ) {
111
+ global $wpdb;
112
+
113
+ if ( 'custom-table' === '{{dataStorageMode}}' ) {
114
+ $table_name = {{phpPrefix}}_get_counter_table_name();
115
+ $delta_value = (int) $delta;
116
+ $initial_count = max( 0, $delta_value );
117
+ $result = $wpdb->query(
118
+ $wpdb->prepare(
119
+ // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- Table name comes from an internal helper.
120
+ "INSERT INTO {$table_name} (post_id, resource_key, count, updated_at)
121
+ VALUES (%d, %s, %d, %s)
122
+ ON DUPLICATE KEY UPDATE
123
+ count = GREATEST(0, count + %d),
124
+ updated_at = VALUES(updated_at)",
125
+ $post_id,
126
+ $resource_key,
127
+ $initial_count,
128
+ current_time( 'mysql', true ),
129
+ $delta_value
130
+ )
131
+ );
132
+
133
+ if ( false === $result ) {
134
+ return new WP_Error( 'counter_update_failed', 'Failed to update the counter.', array( 'status' => 500 ) );
135
+ }
136
+
137
+ return {{phpPrefix}}_get_counter( $post_id, $resource_key );
138
+ }
139
+
140
+ return {{phpPrefix}}_with_counter_lock(
141
+ $post_id,
142
+ $resource_key,
143
+ function () use ( $delta, $post_id, $resource_key ) {
144
+ $meta_key = '_' . '{{phpPrefix}}' . '_counter_' . sanitize_key( $resource_key );
145
+ $next_count = max( 0, {{phpPrefix}}_get_counter( $post_id, $resource_key ) + (int) $delta );
146
+ update_post_meta( $post_id, $meta_key, $next_count );
147
+ return $next_count;
148
+ }
149
+ );
150
+ }
151
+
152
+ function {{phpPrefix}}_build_state_response( $post_id, $resource_key, $count ) {
153
+ return array(
154
+ 'postId' => (int) $post_id,
155
+ 'resourceKey' => (string) $resource_key,
156
+ 'count' => (int) $count,
157
+ 'storage' => '{{dataStorageMode}}',
158
+ );
159
+ }
160
+
161
+ function {{phpPrefix}}_handle_get_state( WP_REST_Request $request ) {
162
+ $payload = {{phpPrefix}}_validate_and_sanitize_request(
163
+ array(
164
+ 'postId' => $request->get_param( 'postId' ),
165
+ 'resourceKey' => $request->get_param( 'resourceKey' ),
166
+ ),
167
+ {{phpPrefix}}_get_rest_build_dir(),
168
+ 'state-query',
169
+ 'query'
170
+ );
171
+
172
+ if ( is_wp_error( $payload ) ) {
173
+ return $payload;
174
+ }
175
+
176
+ $count = {{phpPrefix}}_get_counter( (int) $payload['postId'], (string) $payload['resourceKey'] );
177
+ return rest_ensure_response(
178
+ {{phpPrefix}}_build_state_response(
179
+ (int) $payload['postId'],
180
+ (string) $payload['resourceKey'],
181
+ $count
182
+ )
183
+ );
184
+ }
185
+
186
+ function {{phpPrefix}}_handle_write_state( WP_REST_Request $request ) {
187
+ $payload = {{phpPrefix}}_validate_and_sanitize_request(
188
+ $request->get_json_params(),
189
+ {{phpPrefix}}_get_rest_build_dir(),
190
+ 'write-state-request',
191
+ 'body'
192
+ );
193
+
194
+ if ( is_wp_error( $payload ) ) {
195
+ return $payload;
196
+ }
197
+
198
+ $request_consumed = {{phpPrefix}}_consume_public_write_request_id(
199
+ (int) $payload['postId'],
200
+ (string) $payload['resourceKey'],
201
+ isset( $payload['publicWriteRequestId'] ) ? (string) $payload['publicWriteRequestId'] : ''
202
+ );
203
+
204
+ if ( is_wp_error( $request_consumed ) ) {
205
+ return $request_consumed;
206
+ }
207
+
208
+ $count = {{phpPrefix}}_increment_counter(
209
+ (int) $payload['postId'],
210
+ (string) $payload['resourceKey'],
211
+ isset( $payload['delta'] ) ? (int) $payload['delta'] : 1
212
+ );
213
+
214
+ if ( is_wp_error( $count ) ) {
215
+ {{phpPrefix}}_release_public_write_request_id(
216
+ (int) $payload['postId'],
217
+ (string) $payload['resourceKey'],
218
+ isset( $payload['publicWriteRequestId'] ) ? (string) $payload['publicWriteRequestId'] : ''
219
+ );
220
+ return $count;
221
+ }
222
+
223
+ return rest_ensure_response(
224
+ {{phpPrefix}}_build_state_response(
225
+ (int) $payload['postId'],
226
+ (string) $payload['resourceKey'],
227
+ $count
228
+ )
229
+ );
230
+ }
231
+
232
+ function {{phpPrefix}}_register_routes() {
233
+ register_rest_route(
234
+ '{{namespace}}/v1',
235
+ '/{{slugKebabCase}}/state',
236
+ array(
237
+ array(
238
+ 'methods' => WP_REST_Server::READABLE,
239
+ 'callback' => '{{phpPrefix}}_handle_get_state',
240
+ 'permission_callback' => '__return_true',
241
+ ),
242
+ array(
243
+ 'methods' => WP_REST_Server::CREATABLE,
244
+ 'callback' => '{{phpPrefix}}_handle_write_state',
245
+ 'permission_callback' => '{{phpPrefix}}_can_write_publicly',
246
+ ),
247
+ )
248
+ );
249
+ }
250
+
251
+ add_action( 'init', '{{phpPrefix}}_ensure_storage_installed' );
252
+ add_action( 'rest_api_init', '{{phpPrefix}}_register_routes' );
@@ -0,0 +1,51 @@
1
+ {
2
+ "$schema": "https://schemas.wp.org/trunk/block.json",
3
+ "apiVersion": 3,
4
+ "name": "{{namespace}}/{{slug}}",
5
+ "version": "{{blockMetadataVersion}}",
6
+ "title": "{{title}}",
7
+ "category": "{{category}}",
8
+ "icon": "{{icon}}",
9
+ "description": "{{description}}",
10
+ "keywords": ["{{keyword}}", "typia", "block"],
11
+ "example": {
12
+ "attributes": {
13
+ "content": "Example content",
14
+ "alignment": "center",
15
+ "isVisible": true
16
+ }
17
+ },
18
+ "supports": {
19
+ "html": false
20
+ },
21
+ "textdomain": "{{textDomain}}",
22
+ "editorScript": "file:./index.js",
23
+ "editorStyle": "file:./index.css",
24
+ "style": "file:./style-index.css",
25
+ "attributes": {
26
+ "content": {
27
+ "type": "string",
28
+ "default": ""
29
+ },
30
+ "alignment": {
31
+ "type": "string",
32
+ "enum": ["left", "center", "right", "justify"],
33
+ "default": "left"
34
+ },
35
+ "className": {
36
+ "type": "string",
37
+ "default": ""
38
+ },
39
+ "isVisible": {
40
+ "type": "boolean",
41
+ "default": true
42
+ },
43
+ "id": {
44
+ "type": "string"
45
+ },
46
+ "schemaVersion": {
47
+ "type": "number",
48
+ "default": 1
49
+ }
50
+ }
51
+ }
@@ -0,0 +1,128 @@
1
+ /**
2
+ * Editor component for {{title}} Block
3
+ */
4
+
5
+ import { BlockEditProps } from '@wordpress/blocks';
6
+ import {
7
+ InspectorControls,
8
+ RichText,
9
+ useBlockProps,
10
+ } from '@wordpress/block-editor';
11
+ import { Notice, PanelBody, TextControl } from '@wordpress/components';
12
+ import { __ } from '@wordpress/i18n';
13
+ import currentManifest from './typia.manifest.json';
14
+ import {
15
+ InspectorFromManifest,
16
+ type ManifestDocument,
17
+ useEditorFields,
18
+ useTypedAttributeUpdater,
19
+ } from '@wp-typia/block-runtime/inspector';
20
+ import { {{pascalCase}}Attributes } from './types';
21
+ import {
22
+ sanitize{{pascalCase}}Attributes,
23
+ validate{{pascalCase}}Attributes,
24
+ } from './validators';
25
+ import { useTypiaValidation } from './hooks';
26
+
27
+ type EditProps = BlockEditProps<{{pascalCase}}Attributes>;
28
+
29
+ function Edit({ attributes, setAttributes }: EditProps) {
30
+ const isVisible = attributes.isVisible !== false;
31
+ const blockProps = useBlockProps({
32
+ className: isVisible ? undefined : 'is-hidden',
33
+ });
34
+ const editorFields = useEditorFields(currentManifest as ManifestDocument, {
35
+ hidden: ['id', 'schemaVersion'],
36
+ manual: ['content'],
37
+ labels: {
38
+ alignment: __('Alignment', '{{textDomain}}'),
39
+ className: __('CSS Class', '{{textDomain}}'),
40
+ content: __('Content', '{{textDomain}}'),
41
+ isVisible: __('Visible', '{{textDomain}}'),
42
+ },
43
+ });
44
+ const classNameField = editorFields.getField('className');
45
+ const { errorMessages, isValid } = useTypiaValidation(
46
+ attributes,
47
+ validate{{pascalCase}}Attributes
48
+ );
49
+ const validateEditorUpdate = (nextAttributes: {{pascalCase}}Attributes) => {
50
+ try {
51
+ return {
52
+ data: sanitize{{pascalCase}}Attributes(nextAttributes),
53
+ errors: [],
54
+ isValid: true as const,
55
+ };
56
+ } catch {
57
+ return validate{{pascalCase}}Attributes(nextAttributes);
58
+ }
59
+ };
60
+ const { updateField } = useTypedAttributeUpdater(
61
+ attributes,
62
+ setAttributes,
63
+ validateEditorUpdate
64
+ );
65
+
66
+ return (
67
+ <>
68
+ <InspectorControls>
69
+ <InspectorFromManifest
70
+ attributes={attributes}
71
+ fieldLookup={editorFields}
72
+ onChange={updateField}
73
+ paths={['alignment', 'isVisible']}
74
+ title={__('Settings', '{{textDomain}}')}
75
+ >
76
+ <TextControl
77
+ label={__('Content', '{{textDomain}}')}
78
+ value={attributes.content || ''}
79
+ onChange={(value) => updateField('content', value)}
80
+ help={__('Mirrors the main block content.', '{{textDomain}}')}
81
+ />
82
+
83
+ <TextControl
84
+ label={classNameField?.label || __('CSS Class', '{{textDomain}}')}
85
+ value={attributes.className || ''}
86
+ onChange={(value) => updateField('className', value)}
87
+ help={__('Add an optional CSS class name.', '{{textDomain}}')}
88
+ />
89
+ </InspectorFromManifest>
90
+
91
+ {!isValid && (
92
+ <PanelBody title={__('Validation Errors', '{{textDomain}}')} initialOpen>
93
+ {errorMessages.map((error, index) => (
94
+ <div key={index} style={{ color: '#cc1818', fontSize: '12px' }}>
95
+ • {error}
96
+ </div>
97
+ ))}
98
+ </PanelBody>
99
+ )}
100
+ </InspectorControls>
101
+
102
+ <div {...blockProps}>
103
+ <div className="{{cssClassName}}__content">
104
+ <RichText
105
+ tagName="p"
106
+ value={attributes.content || ''}
107
+ onChange={(value) => updateField('content', value)}
108
+ placeholder={__('Add your content...', '{{textDomain}}')}
109
+ />
110
+ </div>
111
+ {!isValid && (
112
+ <Notice status="error" isDismissible={false}>
113
+ <p>
114
+ <strong>{__('Validation Errors', '{{textDomain}}')}</strong>
115
+ </p>
116
+ <ul style={{ margin: 0, paddingLeft: '1em' }}>
117
+ {errorMessages.map((error, index) => (
118
+ <li key={index}>{error}</li>
119
+ ))}
120
+ </ul>
121
+ </Notice>
122
+ )}
123
+ </div>
124
+ </>
125
+ );
126
+ }
127
+
128
+ export default Edit;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * {{title}} Block Editor Styles
3
+ */
4
+
5
+ .{{cssClassName}} {
6
+ outline: 1px dashed #ddd;
7
+ outline-offset: -1px;
8
+ }
@@ -0,0 +1,18 @@
1
+ import { useMemo } from '@wordpress/element';
2
+ import {
3
+ createUseTypiaValidationHook,
4
+ formatValidationError,
5
+ formatValidationErrors,
6
+ } from '@wp-typia/block-runtime/validation';
7
+
8
+ export {
9
+ formatValidationError,
10
+ formatValidationErrors,
11
+ type TypiaValidationError,
12
+ type ValidationResult,
13
+ type ValidationState,
14
+ } from '@wp-typia/block-runtime/validation';
15
+
16
+ export const useTypiaValidation = createUseTypiaValidationHook( {
17
+ useMemo,
18
+ } );
@@ -0,0 +1,45 @@
1
+ /**
2
+ * WordPress {{title}} Block
3
+ *
4
+ * Typia-powered type-safe block
5
+ */
6
+
7
+ import { registerBlockType } from '@wordpress/blocks';
8
+ import type { BlockConfiguration } from '@wordpress/blocks';
9
+ import type { BlockSupports } from '@wp-typia/block-types/blocks/supports';
10
+ import { __ } from '@wordpress/i18n';
11
+ import {
12
+ buildScaffoldBlockRegistration,
13
+ type ScaffoldBlockMetadata,
14
+ } from '@wp-typia/block-runtime/blocks';
15
+
16
+ // Import components
17
+ import Edit from './edit';
18
+ import Save from './save';
19
+ import metadata from './block.json';
20
+ import './editor.scss';
21
+ import './style.scss';
22
+
23
+ // Import types
24
+ import { {{pascalCase}}Attributes } from './types';
25
+ import { validators } from './validators';
26
+
27
+ const scaffoldSupports = {
28
+ html: false,
29
+ multiple: true,
30
+ align: ['wide', 'full'],
31
+ } satisfies BlockSupports;
32
+
33
+ // Register the block
34
+ const registration = buildScaffoldBlockRegistration<
35
+ BlockConfiguration<{{pascalCase}}Attributes>
36
+ >(metadata as ScaffoldBlockMetadata, {
37
+ supports: scaffoldSupports,
38
+ example: {
39
+ attributes: validators.random(),
40
+ },
41
+ edit: Edit,
42
+ save: Save,
43
+ });
44
+
45
+ registerBlockType<{{pascalCase}}Attributes>(registration.name, registration.settings);
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Save/Frontend component for {{title}} Block
3
+ */
4
+
5
+ import { RichText, useBlockProps } from '@wordpress/block-editor';
6
+ import { {{pascalCase}}Attributes } from './types';
7
+
8
+ interface SaveProps {
9
+ attributes: {{pascalCase}}Attributes;
10
+ }
11
+
12
+ export default function Save({ attributes }: SaveProps) {
13
+ const isVisible = attributes.isVisible !== false;
14
+ const blockProps = useBlockProps.save({
15
+ className: isVisible ? undefined : 'is-hidden',
16
+ hidden: isVisible ? undefined : true,
17
+ 'aria-hidden': isVisible ? undefined : 'true',
18
+ });
19
+
20
+ return (
21
+ <div {...blockProps}>
22
+ <div
23
+ className="{{cssClassName}}__content"
24
+ data-align={attributes.alignment || 'left'}
25
+ >
26
+ <RichText.Content tagName="p" value={attributes.content} />
27
+ </div>
28
+ </div>
29
+ );
30
+ }
@@ -0,0 +1,40 @@
1
+ /**
2
+ * {{title}} Block Styles
3
+ */
4
+
5
+ .{{cssClassName}} {
6
+ padding: 20px;
7
+ border: 1px solid #ddd;
8
+ border-radius: 4px;
9
+ background-color: #fff;
10
+ box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
11
+
12
+ &.is-hidden {
13
+ display: none;
14
+ }
15
+
16
+ &__content {
17
+ font-size: 16px;
18
+ line-height: 1.6;
19
+ color: #333;
20
+
21
+ // Alignment styles
22
+ &[data-align="center"] {
23
+ text-align: center;
24
+ }
25
+
26
+ &[data-align="right"] {
27
+ text-align: right;
28
+ }
29
+
30
+ &[data-align="justify"] {
31
+ text-align: justify;
32
+ }
33
+ }
34
+
35
+ // Hover state
36
+ &:hover {
37
+ box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
38
+ transition: box-shadow 0.2s ease;
39
+ }
40
+ }
@@ -0,0 +1,56 @@
1
+ import type { TextAlignment } from "@wp-typia/block-types/block-editor/alignment";
2
+ import type {
3
+ TypiaValidationError,
4
+ ValidationResult,
5
+ } from "@wp-typia/block-runtime/validation";
6
+ import { tags } from "typia";
7
+
8
+ export type { TypiaValidationError, ValidationResult } from "@wp-typia/block-runtime/validation";
9
+
10
+ /**
11
+ * Block attributes interface
12
+ * Typia tags define runtime validation rules
13
+ */
14
+ export interface {{pascalCase}}Attributes {
15
+ /**
16
+ * Main block content
17
+ */
18
+ content: string &
19
+ tags.MinLength<1> &
20
+ tags.MaxLength<1000> &
21
+ tags.Default<"">;
22
+
23
+ /**
24
+ * Alignment
25
+ */
26
+ alignment?: TextAlignment &
27
+ tags.Default<"left">;
28
+
29
+ /**
30
+ * Visibility toggle
31
+ */
32
+ isVisible?: boolean &
33
+ tags.Default<true>;
34
+
35
+ /**
36
+ * Custom CSS class
37
+ */
38
+ className?: string &
39
+ tags.MaxLength<100> &
40
+ tags.Default<"">;
41
+
42
+ /**
43
+ * Generated runtime ID
44
+ */
45
+ id?: string &
46
+ tags.Format<"uuid">;
47
+
48
+ /**
49
+ * Block version for migrations
50
+ */
51
+ schemaVersion?: number &
52
+ tags.Type<"uint32"> &
53
+ tags.Default<1>;
54
+ }
55
+
56
+ export type {{pascalCase}}ValidationResult = ValidationResult<{{pascalCase}}Attributes>;
@@ -0,0 +1,26 @@
1
+ import currentManifest from "./typia.manifest.json";
2
+ import { {{pascalCase}}Attributes, {{pascalCase}}ValidationResult } from "./types";
3
+ import { generateBlockId } from "@wp-typia/block-runtime/identifiers";
4
+ import { createTemplateValidatorToolkit } from "./validator-toolkit";
5
+
6
+ const scaffoldValidators = createTemplateValidatorToolkit<{{pascalCase}}Attributes>({
7
+ manifest: currentManifest,
8
+ finalize: (normalized) => ({
9
+ ...normalized,
10
+ id: normalized.id && normalized.id.length > 0 ? normalized.id : generateBlockId(),
11
+ }),
12
+ });
13
+
14
+ export const validate{{pascalCase}}Attributes =
15
+ scaffoldValidators.validateAttributes as (
16
+ attributes: unknown,
17
+ ) => {{pascalCase}}ValidationResult;
18
+
19
+ export const validators = scaffoldValidators.validators;
20
+
21
+ export const sanitize{{pascalCase}}Attributes =
22
+ scaffoldValidators.sanitizeAttributes as (
23
+ attributes: Partial<{{pascalCase}}Attributes>,
24
+ ) => {{pascalCase}}Attributes;
25
+
26
+ export const createAttributeUpdater = scaffoldValidators.createAttributeUpdater;
@@ -0,0 +1,37 @@
1
+ {
2
+ "$schema": "https://schemas.wp.org/trunk/block.json",
3
+ "apiVersion": 3,
4
+ "name": "{{namespace}}/{{slugKebabCase}}",
5
+ "version": "{{blockMetadataVersion}}",
6
+ "title": {{titleJson}},
7
+ "category": "{{category}}",
8
+ "icon": "{{icon}}",
9
+ "description": "{{description}}",
10
+ "example": {},
11
+ "supports": {
12
+ "html": false,
13
+ "anchor": true,
14
+ "className": true
15
+ },
16
+ "attributes": {
17
+ "heading": {
18
+ "type": "string",
19
+ "source": "html",
20
+ "selector": ".{{cssClassName}}__heading",
21
+ "default": {{titleJson}}
22
+ },
23
+ "intro": {
24
+ "type": "string",
25
+ "source": "html",
26
+ "selector": ".{{cssClassName}}__intro",
27
+ "default": "Add and reorder internal items inside this compound block."
28
+ },
29
+ "showDividers": {
30
+ "type": "boolean",
31
+ "default": true
32
+ }
33
+ },
34
+ "textdomain": "{{textDomain}}",
35
+ "editorScript": "file:./index.js",
36
+ "style": "file:./style-index.css"
37
+ }