@10up/block-renderer-core 0.1.4
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 +376 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/types/block-definition.d.ts +62 -0
- package/dist/types/block-definition.d.ts.map +1 -0
- package/dist/types/block-definition.js +2 -0
- package/dist/types/block-definition.js.map +1 -0
- package/dist/types/block-json.d.ts +262 -0
- package/dist/types/block-json.d.ts.map +1 -0
- package/dist/types/block-json.js +7 -0
- package/dist/types/block-json.js.map +1 -0
- package/dist/types/block-template.d.ts +41 -0
- package/dist/types/block-template.d.ts.map +1 -0
- package/dist/types/block-template.js +18 -0
- package/dist/types/block-template.js.map +1 -0
- package/dist/types/block-tree.d.ts +95 -0
- package/dist/types/block-tree.d.ts.map +1 -0
- package/dist/types/block-tree.js +19 -0
- package/dist/types/block-tree.js.map +1 -0
- package/dist/types/php-transforms.d.ts +27 -0
- package/dist/types/php-transforms.d.ts.map +1 -0
- package/dist/types/php-transforms.js +9 -0
- package/dist/types/php-transforms.js.map +1 -0
- package/package.json +49 -0
package/README.md
ADDED
|
@@ -0,0 +1,376 @@
|
|
|
1
|
+
# @10up/block-renderer-core
|
|
2
|
+
|
|
3
|
+
Shared TypeScript types and Zod schemas for the JSON Block Renderer ecosystem. This package provides the foundational types used across all other packages in the monorepo.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @10up/block-renderer-core
|
|
9
|
+
# or
|
|
10
|
+
pnpm add @10up/block-renderer-core
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Overview
|
|
14
|
+
|
|
15
|
+
This package exports three categories of types:
|
|
16
|
+
|
|
17
|
+
1. **Block Tree Types** - The JSON format for representing WordPress blocks
|
|
18
|
+
2. **Block Definition Types** - Metadata and schemas for block validation
|
|
19
|
+
3. **Block JSON Types** - TypeScript definitions for WordPress `block.json` files
|
|
20
|
+
|
|
21
|
+
## Block Tree Format
|
|
22
|
+
|
|
23
|
+
The block tree uses a **flat structure with key references** instead of deep nesting. This design (inspired by [Vercel's json-render](https://github.com/vercel-labs/json-render)) makes it easier for AI to generate valid structures.
|
|
24
|
+
|
|
25
|
+
### BlockElement
|
|
26
|
+
|
|
27
|
+
A single block element in the tree:
|
|
28
|
+
|
|
29
|
+
```typescript
|
|
30
|
+
interface BlockElement {
|
|
31
|
+
/** Unique identifier for this element */
|
|
32
|
+
key: string;
|
|
33
|
+
/** Block name, e.g., "core/paragraph", "core/group" */
|
|
34
|
+
type: string;
|
|
35
|
+
/** Block attributes/props */
|
|
36
|
+
props: Record<string, unknown>;
|
|
37
|
+
/** Keys of child elements (for blocks with InnerBlocks) */
|
|
38
|
+
children?: string[];
|
|
39
|
+
/** Key of the parent element */
|
|
40
|
+
parentKey?: string;
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### BlockTree
|
|
45
|
+
|
|
46
|
+
The complete block tree structure:
|
|
47
|
+
|
|
48
|
+
```typescript
|
|
49
|
+
interface BlockTree {
|
|
50
|
+
/** Key of the root element */
|
|
51
|
+
root: string;
|
|
52
|
+
/** Map of element keys to BlockElement objects */
|
|
53
|
+
elements: Record<string, BlockElement>;
|
|
54
|
+
}
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### Example
|
|
58
|
+
|
|
59
|
+
```typescript
|
|
60
|
+
import type { BlockTree, BlockElement } from '@10up/block-renderer-core';
|
|
61
|
+
|
|
62
|
+
const tree: BlockTree = {
|
|
63
|
+
root: 'group-1',
|
|
64
|
+
elements: {
|
|
65
|
+
'group-1': {
|
|
66
|
+
key: 'group-1',
|
|
67
|
+
type: 'core/group',
|
|
68
|
+
props: { layout: { type: 'constrained' } },
|
|
69
|
+
children: ['heading-1', 'para-1']
|
|
70
|
+
},
|
|
71
|
+
'heading-1': {
|
|
72
|
+
key: 'heading-1',
|
|
73
|
+
type: 'core/heading',
|
|
74
|
+
props: { content: 'Welcome', level: 2 },
|
|
75
|
+
parentKey: 'group-1'
|
|
76
|
+
},
|
|
77
|
+
'para-1': {
|
|
78
|
+
key: 'para-1',
|
|
79
|
+
type: 'core/paragraph',
|
|
80
|
+
props: { content: 'Hello world' },
|
|
81
|
+
parentKey: 'group-1'
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## Block Template Format
|
|
88
|
+
|
|
89
|
+
An alternative PHP-style nested array format, useful for migration scripts and server-side rendering:
|
|
90
|
+
|
|
91
|
+
### BlockTemplateEntry
|
|
92
|
+
|
|
93
|
+
A single entry in a block template:
|
|
94
|
+
|
|
95
|
+
```typescript
|
|
96
|
+
type BlockTemplateEntry =
|
|
97
|
+
| [string] // Just block type
|
|
98
|
+
| [string, Record<string, unknown>] // Block type + attributes
|
|
99
|
+
| [string, Record<string, unknown>, BlockTemplateEntry[]]; // Full entry with children
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### BlockTemplate
|
|
103
|
+
|
|
104
|
+
An array of block template entries:
|
|
105
|
+
|
|
106
|
+
```typescript
|
|
107
|
+
type BlockTemplate = BlockTemplateEntry[];
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### Example
|
|
111
|
+
|
|
112
|
+
```typescript
|
|
113
|
+
import type { BlockTemplate, BlockTemplateEntry } from '@10up/block-renderer-core';
|
|
114
|
+
|
|
115
|
+
const template: BlockTemplate = [
|
|
116
|
+
['core/group', { layout: { type: 'constrained' } }, [
|
|
117
|
+
['core/heading', { content: 'Welcome', level: 2 }],
|
|
118
|
+
['core/paragraph', { content: 'Hello world' }],
|
|
119
|
+
]],
|
|
120
|
+
];
|
|
121
|
+
|
|
122
|
+
// This corresponds to the WordPress PHP format:
|
|
123
|
+
// array(
|
|
124
|
+
// array( 'core/group', array( 'layout' => array( 'type' => 'constrained' ) ), array(
|
|
125
|
+
// array( 'core/heading', array( 'content' => 'Welcome', 'level' => 2 ) ),
|
|
126
|
+
// array( 'core/paragraph', array( 'content' => 'Hello world' ) ),
|
|
127
|
+
// )),
|
|
128
|
+
// )
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### When to Use Each Format
|
|
132
|
+
|
|
133
|
+
| Format | Best For |
|
|
134
|
+
|--------|----------|
|
|
135
|
+
| **BlockTree** (flat) | AI generation, complex validation, IDE tooling |
|
|
136
|
+
| **BlockTemplate** (nested) | Migration scripts, PHP-to-JS conversion, manual authoring |
|
|
137
|
+
|
|
138
|
+
## Block Definition Types
|
|
139
|
+
|
|
140
|
+
Used for validation and prompt generation:
|
|
141
|
+
|
|
142
|
+
### BlockDefinition
|
|
143
|
+
|
|
144
|
+
```typescript
|
|
145
|
+
interface BlockDefinition {
|
|
146
|
+
/** Block name, e.g., "core/paragraph" */
|
|
147
|
+
name: string;
|
|
148
|
+
/** Human-readable title */
|
|
149
|
+
title?: string;
|
|
150
|
+
/** Block description */
|
|
151
|
+
description?: string;
|
|
152
|
+
/** Zod schema for validating block attributes */
|
|
153
|
+
schema: z.ZodObject<z.ZodRawShape>;
|
|
154
|
+
/** Valid parent blocks (direct parent) */
|
|
155
|
+
parent?: string[];
|
|
156
|
+
/** Valid ancestor blocks (anywhere in tree path) */
|
|
157
|
+
ancestor?: string[];
|
|
158
|
+
/** Valid child blocks, or true for any */
|
|
159
|
+
allowedBlocks?: string[] | true;
|
|
160
|
+
/** Whether block supports InnerBlocks (children) */
|
|
161
|
+
hasInnerBlocks: boolean;
|
|
162
|
+
/** Whether block is dynamic (server-rendered) */
|
|
163
|
+
isDynamic: boolean;
|
|
164
|
+
/** Block category */
|
|
165
|
+
category?: string;
|
|
166
|
+
/** Block keywords for search */
|
|
167
|
+
keywords?: string[];
|
|
168
|
+
}
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
### BlockCatalog
|
|
172
|
+
|
|
173
|
+
A map of block names to their definitions:
|
|
174
|
+
|
|
175
|
+
```typescript
|
|
176
|
+
type BlockCatalog = Map<string, BlockDefinition>;
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
### Validation Result Types
|
|
180
|
+
|
|
181
|
+
```typescript
|
|
182
|
+
interface ValidationResult {
|
|
183
|
+
valid: boolean;
|
|
184
|
+
errors: string[];
|
|
185
|
+
warnings?: string[];
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
interface TreeValidationResult extends ValidationResult {
|
|
189
|
+
/** Per-element validation results keyed by element key */
|
|
190
|
+
elementResults?: Record<string, ValidationResult>;
|
|
191
|
+
}
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
## Block JSON Types
|
|
195
|
+
|
|
196
|
+
TypeScript definitions matching the WordPress [block.json schema](https://developer.wordpress.org/block-editor/reference-guides/block-api/block-metadata/):
|
|
197
|
+
|
|
198
|
+
### BlockJson
|
|
199
|
+
|
|
200
|
+
```typescript
|
|
201
|
+
interface BlockJson {
|
|
202
|
+
name: string; // Required: Block name
|
|
203
|
+
title: string; // Required: Display title
|
|
204
|
+
category?: string; // Block category
|
|
205
|
+
description?: string; // Block description
|
|
206
|
+
keywords?: string[]; // Search keywords
|
|
207
|
+
attributes?: Record<string, BlockAttributeDefinition>;
|
|
208
|
+
supports?: BlockSupports; // Feature support flags
|
|
209
|
+
parent?: string[]; // Direct parent constraints
|
|
210
|
+
ancestor?: string[]; // Ancestor constraints
|
|
211
|
+
allowedBlocks?: string[]; // Allowed child blocks
|
|
212
|
+
providesContext?: Record<string, string>; // Context provided to children
|
|
213
|
+
usesContext?: string[]; // Context consumed from parents
|
|
214
|
+
styles?: Array<{ name: string; label: string; isDefault?: boolean }>;
|
|
215
|
+
variations?: Array<BlockVariation>;
|
|
216
|
+
render?: string; // Server-side render callback
|
|
217
|
+
// ... and more
|
|
218
|
+
}
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
### BlockAttributeDefinition
|
|
222
|
+
|
|
223
|
+
```typescript
|
|
224
|
+
interface BlockAttributeDefinition {
|
|
225
|
+
type?: BlockAttributeType | BlockAttributeType[];
|
|
226
|
+
enum?: (string | number | boolean)[];
|
|
227
|
+
default?: unknown;
|
|
228
|
+
source?: 'attribute' | 'text' | 'html' | 'query' | 'meta' | 'raw';
|
|
229
|
+
selector?: string;
|
|
230
|
+
attribute?: string;
|
|
231
|
+
items?: BlockAttributeDefinition; // For array types
|
|
232
|
+
properties?: Record<string, BlockAttributeDefinition>; // For object types
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
type BlockAttributeType =
|
|
236
|
+
| 'string' | 'number' | 'integer' | 'boolean'
|
|
237
|
+
| 'object' | 'array' | 'null' | 'rich-text';
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
### BlockSupports
|
|
241
|
+
|
|
242
|
+
Comprehensive type for WordPress block supports:
|
|
243
|
+
|
|
244
|
+
```typescript
|
|
245
|
+
interface BlockSupports {
|
|
246
|
+
anchor?: boolean;
|
|
247
|
+
align?: boolean | ('left' | 'center' | 'right' | 'wide' | 'full')[];
|
|
248
|
+
className?: boolean;
|
|
249
|
+
color?: boolean | {
|
|
250
|
+
background?: boolean;
|
|
251
|
+
gradients?: boolean;
|
|
252
|
+
link?: boolean;
|
|
253
|
+
text?: boolean;
|
|
254
|
+
};
|
|
255
|
+
typography?: boolean | {
|
|
256
|
+
fontSize?: boolean;
|
|
257
|
+
lineHeight?: boolean;
|
|
258
|
+
fontFamily?: boolean;
|
|
259
|
+
fontWeight?: boolean;
|
|
260
|
+
// ... and more
|
|
261
|
+
};
|
|
262
|
+
spacing?: boolean | {
|
|
263
|
+
margin?: boolean | ('top' | 'right' | 'bottom' | 'left')[];
|
|
264
|
+
padding?: boolean | ('top' | 'right' | 'bottom' | 'left')[];
|
|
265
|
+
blockGap?: boolean | ('horizontal' | 'vertical')[];
|
|
266
|
+
};
|
|
267
|
+
border?: boolean | { color?: boolean; radius?: boolean; style?: boolean; width?: boolean };
|
|
268
|
+
layout?: boolean | { default?: { type?: 'constrained' | 'flex' | 'flow' | 'grid' } };
|
|
269
|
+
// ... and more
|
|
270
|
+
}
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
## Zod Schemas
|
|
274
|
+
|
|
275
|
+
Runtime validation schemas for block trees:
|
|
276
|
+
|
|
277
|
+
```typescript
|
|
278
|
+
import { blockTreeSchema, blockElementSchema } from '@10up/block-renderer-core';
|
|
279
|
+
|
|
280
|
+
// Validate a complete tree
|
|
281
|
+
const result = blockTreeSchema.safeParse(input);
|
|
282
|
+
if (result.success) {
|
|
283
|
+
const tree: BlockTree = result.data;
|
|
284
|
+
} else {
|
|
285
|
+
console.error(result.error.issues);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
// Validate a single element
|
|
289
|
+
const elementResult = blockElementSchema.safeParse(element);
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
### Schema Definitions
|
|
293
|
+
|
|
294
|
+
```typescript
|
|
295
|
+
// BlockElement schema
|
|
296
|
+
const blockElementSchema = z.object({
|
|
297
|
+
key: z.string().min(1),
|
|
298
|
+
type: z.string().min(1),
|
|
299
|
+
props: z.record(z.unknown()),
|
|
300
|
+
children: z.array(z.string()).optional(),
|
|
301
|
+
parentKey: z.string().optional(),
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
// BlockTree schema
|
|
305
|
+
const blockTreeSchema = z.object({
|
|
306
|
+
root: z.string().min(1),
|
|
307
|
+
elements: z.record(blockElementSchema),
|
|
308
|
+
});
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
## PHP Pattern Options
|
|
312
|
+
|
|
313
|
+
Options for transforming rendered markup into production-ready PHP patterns with internationalization:
|
|
314
|
+
|
|
315
|
+
```typescript
|
|
316
|
+
interface PhpPatternOptions {
|
|
317
|
+
/** Theme text domain for translation functions (required) */
|
|
318
|
+
textDomain: string;
|
|
319
|
+
/** Asset directory name for image path detection (default: 'assets') */
|
|
320
|
+
assetDirectory?: string;
|
|
321
|
+
}
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
### Example
|
|
325
|
+
|
|
326
|
+
```typescript
|
|
327
|
+
import type { PhpPatternOptions } from '@10up/block-renderer-core';
|
|
328
|
+
|
|
329
|
+
const options: PhpPatternOptions = {
|
|
330
|
+
textDomain: 'my-theme',
|
|
331
|
+
assetDirectory: 'assets'
|
|
332
|
+
};
|
|
333
|
+
|
|
334
|
+
// When used with renderBlockTree, text content will be wrapped:
|
|
335
|
+
// "Hello World" → <?php echo esc_html__( 'Hello World', 'my-theme' ); ?>
|
|
336
|
+
// Image paths will use get_template_directory_uri()
|
|
337
|
+
```
|
|
338
|
+
|
|
339
|
+
## Complete Exports
|
|
340
|
+
|
|
341
|
+
### Types
|
|
342
|
+
|
|
343
|
+
| Type | Description |
|
|
344
|
+
|------|-------------|
|
|
345
|
+
| `BlockElement` | Single block in the tree |
|
|
346
|
+
| `BlockTree` | Complete block tree structure |
|
|
347
|
+
| `BlockElementSchema` | Zod inferred type for BlockElement |
|
|
348
|
+
| `BlockTreeSchema` | Zod inferred type for BlockTree |
|
|
349
|
+
| `BlockTemplate` | PHP-style nested array format |
|
|
350
|
+
| `BlockTemplateEntry` | Single entry in a BlockTemplate |
|
|
351
|
+
| `BlockTemplateEntrySchema` | Zod inferred type for BlockTemplateEntry |
|
|
352
|
+
| `BlockTemplateSchema` | Zod inferred type for BlockTemplate |
|
|
353
|
+
| `BlockDefinition` | Block schema and metadata for validation |
|
|
354
|
+
| `BlockCatalog` | Map of block names to definitions |
|
|
355
|
+
| `ValidationResult` | Single element validation result |
|
|
356
|
+
| `TreeValidationResult` | Full tree validation result |
|
|
357
|
+
| `BlockJson` | WordPress block.json structure |
|
|
358
|
+
| `BlockSupports` | Block supports configuration |
|
|
359
|
+
| `BlockAttributeDefinition` | Block attribute definition |
|
|
360
|
+
| `BlockAttributeType` | Attribute type union |
|
|
361
|
+
| `PhpPatternOptions` | Options for PHP pattern transformation |
|
|
362
|
+
| `PhpPatternOptionsSchema` | Zod inferred type for PhpPatternOptions |
|
|
363
|
+
|
|
364
|
+
### Schemas
|
|
365
|
+
|
|
366
|
+
| Schema | Description |
|
|
367
|
+
|--------|-------------|
|
|
368
|
+
| `blockElementSchema` | Zod schema for validating BlockElement |
|
|
369
|
+
| `blockTreeSchema` | Zod schema for validating BlockTree |
|
|
370
|
+
| `blockTemplateEntrySchema` | Zod schema for validating BlockTemplateEntry |
|
|
371
|
+
| `blockTemplateSchema` | Zod schema for validating BlockTemplate |
|
|
372
|
+
| `phpPatternOptionsSchema` | Zod schema for validating PhpPatternOptions |
|
|
373
|
+
|
|
374
|
+
## License
|
|
375
|
+
|
|
376
|
+
MIT
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export type { BlockElement, BlockTree, BlockElementSchema, BlockTreeSchema, } from './types/block-tree.js';
|
|
2
|
+
export { blockElementSchema, blockTreeSchema } from './types/block-tree.js';
|
|
3
|
+
export type { BlockDefinition, BlockCatalog, ValidationResult, TreeValidationResult, } from './types/block-definition.js';
|
|
4
|
+
export type { BlockAttributeType, BlockAttributeDefinition, BlockSupports, BlockJson, } from './types/block-json.js';
|
|
5
|
+
export type { BlockTemplate, BlockTemplateEntry, BlockTemplateEntrySchema, BlockTemplateSchema, } from './types/block-template.js';
|
|
6
|
+
export { blockTemplateEntrySchema, blockTemplateSchema, } from './types/block-template.js';
|
|
7
|
+
export type { PhpPatternOptions, PhpPatternOptionsSchema, } from './types/php-transforms.js';
|
|
8
|
+
export { phpPatternOptionsSchema } from './types/php-transforms.js';
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,YAAY,EACV,YAAY,EACZ,SAAS,EACT,kBAAkB,EAClB,eAAe,GAChB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAG5E,YAAY,EACV,eAAe,EACf,YAAY,EACZ,gBAAgB,EAChB,oBAAoB,GACrB,MAAM,6BAA6B,CAAC;AAGrC,YAAY,EACV,kBAAkB,EAClB,wBAAwB,EACxB,aAAa,EACb,SAAS,GACV,MAAM,uBAAuB,CAAC;AAG/B,YAAY,EACV,aAAa,EACb,kBAAkB,EAClB,wBAAwB,EACxB,mBAAmB,GACpB,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EACL,wBAAwB,EACxB,mBAAmB,GACpB,MAAM,2BAA2B,CAAC;AAGnC,YAAY,EACV,iBAAiB,EACjB,uBAAuB,GACxB,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { blockElementSchema, blockTreeSchema } from './types/block-tree.js';
|
|
2
|
+
export { blockTemplateEntrySchema, blockTemplateSchema, } from './types/block-template.js';
|
|
3
|
+
export { phpPatternOptionsSchema } from './types/php-transforms.js';
|
|
4
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AA0B5E,OAAO,EACL,wBAAwB,EACxB,mBAAmB,GACpB,MAAM,2BAA2B,CAAC;AAQnC,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { z } from 'zod';
|
|
2
|
+
import type { BlockAttributeDefinition } from './block-json.js';
|
|
3
|
+
/**
|
|
4
|
+
* Complete definition of a block type including schema and metadata.
|
|
5
|
+
* Used for validation, prompt generation, and rendering.
|
|
6
|
+
*/
|
|
7
|
+
export interface BlockDefinition {
|
|
8
|
+
/** Block name, e.g., "core/paragraph" */
|
|
9
|
+
name: string;
|
|
10
|
+
/** Human-readable title */
|
|
11
|
+
title?: string;
|
|
12
|
+
/** Block description */
|
|
13
|
+
description?: string;
|
|
14
|
+
/** Zod schema for validating block attributes */
|
|
15
|
+
schema: z.ZodObject<z.ZodRawShape>;
|
|
16
|
+
/** Raw attribute definitions from block.json */
|
|
17
|
+
attributes?: Record<string, BlockAttributeDefinition>;
|
|
18
|
+
/** Valid parent blocks (direct parent) */
|
|
19
|
+
parent?: string[];
|
|
20
|
+
/** Valid ancestor blocks (anywhere in tree path) */
|
|
21
|
+
ancestor?: string[];
|
|
22
|
+
/** Valid child blocks, or true for any */
|
|
23
|
+
allowedBlocks?: string[] | true;
|
|
24
|
+
/** Whether block can be used multiple times per post */
|
|
25
|
+
multiple?: boolean;
|
|
26
|
+
/** Whether block can be converted to reusable block */
|
|
27
|
+
reusable?: boolean;
|
|
28
|
+
/** Whether block supports InnerBlocks (children) */
|
|
29
|
+
hasInnerBlocks: boolean;
|
|
30
|
+
/** Whether block is dynamic (server-rendered, save = null) */
|
|
31
|
+
isDynamic: boolean;
|
|
32
|
+
/** Block category */
|
|
33
|
+
category?: string;
|
|
34
|
+
/** Block icon */
|
|
35
|
+
icon?: string;
|
|
36
|
+
/** Block keywords for search */
|
|
37
|
+
keywords?: string[];
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Catalog of all available block definitions.
|
|
41
|
+
* Maps block name to its definition.
|
|
42
|
+
*/
|
|
43
|
+
export type BlockCatalog = Map<string, BlockDefinition>;
|
|
44
|
+
/**
|
|
45
|
+
* Result of validating a block element against its definition.
|
|
46
|
+
*/
|
|
47
|
+
export interface ValidationResult {
|
|
48
|
+
/** Whether validation passed */
|
|
49
|
+
valid: boolean;
|
|
50
|
+
/** List of validation error messages */
|
|
51
|
+
errors: string[];
|
|
52
|
+
/** List of validation warning messages */
|
|
53
|
+
warnings?: string[];
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Result of validating an entire block tree.
|
|
57
|
+
*/
|
|
58
|
+
export interface TreeValidationResult extends ValidationResult {
|
|
59
|
+
/** Per-element validation results keyed by element key */
|
|
60
|
+
elementResults?: Record<string, ValidationResult>;
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=block-definition.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"block-definition.d.ts","sourceRoot":"","sources":["../../src/types/block-definition.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAC7B,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAC;AAEhE;;;GAGG;AACH,MAAM,WAAW,eAAe;IAC9B,yCAAyC;IACzC,IAAI,EAAE,MAAM,CAAC;IACb,2BAA2B;IAC3B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,wBAAwB;IACxB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,iDAAiD;IACjD,MAAM,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC;IACnC,gDAAgD;IAChD,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,wBAAwB,CAAC,CAAC;IACtD,0CAA0C;IAC1C,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,oDAAoD;IACpD,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,0CAA0C;IAC1C,aAAa,CAAC,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;IAChC,wDAAwD;IACxD,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,uDAAuD;IACvD,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,oDAAoD;IACpD,cAAc,EAAE,OAAO,CAAC;IACxB,8DAA8D;IAC9D,SAAS,EAAE,OAAO,CAAC;IACnB,qBAAqB;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,iBAAiB;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,gCAAgC;IAChC,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;CACrB;AAED;;;GAGG;AACH,MAAM,MAAM,YAAY,GAAG,GAAG,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;AAExD;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,gCAAgC;IAChC,KAAK,EAAE,OAAO,CAAC;IACf,wCAAwC;IACxC,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,0CAA0C;IAC1C,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,WAAW,oBAAqB,SAAQ,gBAAgB;IAC5D,0DAA0D;IAC1D,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;CACnD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"block-definition.js","sourceRoot":"","sources":["../../src/types/block-definition.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress block.json type definitions.
|
|
3
|
+
* Based on the official block.json schema from Gutenberg.
|
|
4
|
+
* @see https://developer.wordpress.org/block-editor/reference-guides/block-api/block-metadata/
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Attribute type as defined in block.json
|
|
8
|
+
*/
|
|
9
|
+
export type BlockAttributeType = 'string' | 'number' | 'integer' | 'boolean' | 'object' | 'array' | 'null' | 'rich-text';
|
|
10
|
+
/**
|
|
11
|
+
* Single attribute definition from block.json
|
|
12
|
+
*/
|
|
13
|
+
export interface BlockAttributeDefinition {
|
|
14
|
+
/** Attribute type or array of types for union */
|
|
15
|
+
type?: BlockAttributeType | BlockAttributeType[];
|
|
16
|
+
/** Enum values for string attributes */
|
|
17
|
+
enum?: (string | number | boolean)[];
|
|
18
|
+
/** Default value */
|
|
19
|
+
default?: unknown;
|
|
20
|
+
/** Attribute source (for parsing from saved content) */
|
|
21
|
+
source?: 'attribute' | 'text' | 'html' | 'query' | 'meta' | 'raw';
|
|
22
|
+
/** CSS selector for source */
|
|
23
|
+
selector?: string;
|
|
24
|
+
/** HTML attribute name for source */
|
|
25
|
+
attribute?: string;
|
|
26
|
+
/** Allow multiple elements for query source */
|
|
27
|
+
multiline?: string | boolean;
|
|
28
|
+
/** Query object for nested attributes */
|
|
29
|
+
query?: Record<string, BlockAttributeDefinition>;
|
|
30
|
+
/** Items schema for array type */
|
|
31
|
+
items?: BlockAttributeDefinition;
|
|
32
|
+
/** Properties schema for object type */
|
|
33
|
+
properties?: Record<string, BlockAttributeDefinition>;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Block supports configuration.
|
|
37
|
+
* @see https://developer.wordpress.org/block-editor/reference-guides/block-api/block-supports/
|
|
38
|
+
*/
|
|
39
|
+
export interface BlockSupports {
|
|
40
|
+
/** Support for anchor/id */
|
|
41
|
+
anchor?: boolean;
|
|
42
|
+
/** Support for alignment */
|
|
43
|
+
align?: boolean | ('left' | 'center' | 'right' | 'wide' | 'full')[];
|
|
44
|
+
/** Support for text alignment */
|
|
45
|
+
alignWide?: boolean;
|
|
46
|
+
/** Support for custom class name */
|
|
47
|
+
className?: boolean;
|
|
48
|
+
customClassName?: boolean;
|
|
49
|
+
/** Support for HTML editing */
|
|
50
|
+
html?: boolean;
|
|
51
|
+
/** Support for inserter visibility */
|
|
52
|
+
inserter?: boolean;
|
|
53
|
+
/** Support for multiple instances */
|
|
54
|
+
multiple?: boolean;
|
|
55
|
+
/** Support for reusable blocks */
|
|
56
|
+
reusable?: boolean;
|
|
57
|
+
/** Support for lock UI */
|
|
58
|
+
lock?: boolean;
|
|
59
|
+
/** Support for mode switching */
|
|
60
|
+
mode?: boolean;
|
|
61
|
+
/** Color supports */
|
|
62
|
+
color?: boolean | {
|
|
63
|
+
background?: boolean;
|
|
64
|
+
gradients?: boolean;
|
|
65
|
+
link?: boolean;
|
|
66
|
+
text?: boolean;
|
|
67
|
+
enableContrastChecker?: boolean;
|
|
68
|
+
/** Specific palette colors to use */
|
|
69
|
+
__experimentalDuotone?: string;
|
|
70
|
+
heading?: boolean;
|
|
71
|
+
button?: boolean;
|
|
72
|
+
caption?: boolean;
|
|
73
|
+
};
|
|
74
|
+
/** Typography supports */
|
|
75
|
+
typography?: boolean | {
|
|
76
|
+
fontSize?: boolean;
|
|
77
|
+
lineHeight?: boolean;
|
|
78
|
+
textAlign?: boolean | ('left' | 'center' | 'right')[];
|
|
79
|
+
/** @deprecated Use fontFamily */
|
|
80
|
+
__experimentalFontFamily?: boolean;
|
|
81
|
+
fontFamily?: boolean;
|
|
82
|
+
/** @deprecated Use fontStyle */
|
|
83
|
+
__experimentalFontStyle?: boolean;
|
|
84
|
+
fontStyle?: boolean;
|
|
85
|
+
/** @deprecated Use fontWeight */
|
|
86
|
+
__experimentalFontWeight?: boolean;
|
|
87
|
+
fontWeight?: boolean;
|
|
88
|
+
/** @deprecated Use letterSpacing */
|
|
89
|
+
__experimentalLetterSpacing?: boolean;
|
|
90
|
+
letterSpacing?: boolean;
|
|
91
|
+
/** @deprecated Use textDecoration */
|
|
92
|
+
__experimentalTextDecoration?: boolean;
|
|
93
|
+
textDecoration?: boolean;
|
|
94
|
+
/** @deprecated Use textTransform */
|
|
95
|
+
__experimentalTextTransform?: boolean;
|
|
96
|
+
textTransform?: boolean;
|
|
97
|
+
/** @deprecated Use writingMode */
|
|
98
|
+
__experimentalWritingMode?: boolean;
|
|
99
|
+
writingMode?: boolean;
|
|
100
|
+
};
|
|
101
|
+
/** Spacing supports */
|
|
102
|
+
spacing?: boolean | {
|
|
103
|
+
margin?: boolean | ('top' | 'right' | 'bottom' | 'left')[];
|
|
104
|
+
padding?: boolean | ('top' | 'right' | 'bottom' | 'left')[];
|
|
105
|
+
blockGap?: boolean | ('horizontal' | 'vertical')[];
|
|
106
|
+
/** @deprecated Use margin/padding */
|
|
107
|
+
__experimentalSkipSerialization?: boolean | string[];
|
|
108
|
+
};
|
|
109
|
+
/** Border supports */
|
|
110
|
+
border?: boolean | {
|
|
111
|
+
color?: boolean;
|
|
112
|
+
radius?: boolean;
|
|
113
|
+
style?: boolean;
|
|
114
|
+
width?: boolean;
|
|
115
|
+
/** @deprecated Use individual properties */
|
|
116
|
+
__experimentalSkipSerialization?: boolean | string[];
|
|
117
|
+
__experimentalDefaultControls?: {
|
|
118
|
+
color?: boolean;
|
|
119
|
+
radius?: boolean;
|
|
120
|
+
style?: boolean;
|
|
121
|
+
width?: boolean;
|
|
122
|
+
};
|
|
123
|
+
};
|
|
124
|
+
/** Dimensions supports */
|
|
125
|
+
dimensions?: boolean | {
|
|
126
|
+
minHeight?: boolean;
|
|
127
|
+
aspectRatio?: boolean;
|
|
128
|
+
};
|
|
129
|
+
/** Position supports */
|
|
130
|
+
position?: boolean | {
|
|
131
|
+
sticky?: boolean;
|
|
132
|
+
};
|
|
133
|
+
/** Shadow support */
|
|
134
|
+
shadow?: boolean;
|
|
135
|
+
/** Layout support */
|
|
136
|
+
layout?: boolean | {
|
|
137
|
+
default?: {
|
|
138
|
+
type?: 'constrained' | 'flex' | 'flow' | 'grid';
|
|
139
|
+
justifyContent?: string;
|
|
140
|
+
orientation?: 'horizontal' | 'vertical';
|
|
141
|
+
};
|
|
142
|
+
allowSwitching?: boolean;
|
|
143
|
+
allowEditing?: boolean;
|
|
144
|
+
allowInheriting?: boolean;
|
|
145
|
+
allowSizingOnChildren?: boolean;
|
|
146
|
+
allowVerticalAlignment?: boolean;
|
|
147
|
+
allowJustification?: boolean;
|
|
148
|
+
allowOrientation?: boolean;
|
|
149
|
+
allowCustomContentAndWideSize?: boolean;
|
|
150
|
+
};
|
|
151
|
+
/** Background support */
|
|
152
|
+
background?: boolean | {
|
|
153
|
+
backgroundImage?: boolean;
|
|
154
|
+
backgroundSize?: boolean;
|
|
155
|
+
};
|
|
156
|
+
/** Interactivity support */
|
|
157
|
+
interactivity?: boolean | {
|
|
158
|
+
clientNavigation?: boolean;
|
|
159
|
+
interactive?: boolean;
|
|
160
|
+
};
|
|
161
|
+
/** Splitting support for text blocks */
|
|
162
|
+
splitting?: boolean;
|
|
163
|
+
/** Renaming support */
|
|
164
|
+
renaming?: boolean;
|
|
165
|
+
/** Allow additional CSS class names */
|
|
166
|
+
[key: `__experimental${string}`]: unknown;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Complete block.json structure.
|
|
170
|
+
* @see https://developer.wordpress.org/block-editor/reference-guides/block-api/block-metadata/
|
|
171
|
+
*/
|
|
172
|
+
export interface BlockJson {
|
|
173
|
+
/** JSON schema reference */
|
|
174
|
+
$schema?: string;
|
|
175
|
+
/** API version */
|
|
176
|
+
apiVersion?: number;
|
|
177
|
+
/** Block name (required) */
|
|
178
|
+
name: string;
|
|
179
|
+
/** Block title (required) */
|
|
180
|
+
title: string;
|
|
181
|
+
/** Block category */
|
|
182
|
+
category?: string;
|
|
183
|
+
/** Parent blocks that can contain this block */
|
|
184
|
+
parent?: string[];
|
|
185
|
+
/** Ancestor blocks (any level up) */
|
|
186
|
+
ancestor?: string[];
|
|
187
|
+
/** Allowed child blocks */
|
|
188
|
+
allowedBlocks?: string[];
|
|
189
|
+
/** Block icon */
|
|
190
|
+
icon?: string;
|
|
191
|
+
/** Block description */
|
|
192
|
+
description?: string;
|
|
193
|
+
/** Search keywords */
|
|
194
|
+
keywords?: string[];
|
|
195
|
+
/** Version string */
|
|
196
|
+
version?: string;
|
|
197
|
+
/** Text domain for translations */
|
|
198
|
+
textdomain?: string;
|
|
199
|
+
/** Block attributes */
|
|
200
|
+
attributes?: Record<string, BlockAttributeDefinition>;
|
|
201
|
+
/** Provides context to child blocks */
|
|
202
|
+
providesContext?: Record<string, string>;
|
|
203
|
+
/** Uses context from parent blocks */
|
|
204
|
+
usesContext?: string[];
|
|
205
|
+
/** Block supports */
|
|
206
|
+
supports?: BlockSupports;
|
|
207
|
+
/** Block styles */
|
|
208
|
+
styles?: Array<{
|
|
209
|
+
name: string;
|
|
210
|
+
label: string;
|
|
211
|
+
isDefault?: boolean;
|
|
212
|
+
}>;
|
|
213
|
+
/** Example for block preview */
|
|
214
|
+
example?: {
|
|
215
|
+
attributes?: Record<string, unknown>;
|
|
216
|
+
innerBlocks?: Array<{
|
|
217
|
+
name: string;
|
|
218
|
+
attributes?: Record<string, unknown>;
|
|
219
|
+
innerBlocks?: unknown[];
|
|
220
|
+
}>;
|
|
221
|
+
viewportWidth?: number;
|
|
222
|
+
};
|
|
223
|
+
/** Editor script handle or path */
|
|
224
|
+
editorScript?: string | string[];
|
|
225
|
+
/** Frontend script handle or path */
|
|
226
|
+
script?: string | string[];
|
|
227
|
+
/** Frontend script handle or path (non-admin) */
|
|
228
|
+
viewScript?: string | string[];
|
|
229
|
+
/** Editor style handle or path */
|
|
230
|
+
editorStyle?: string | string[];
|
|
231
|
+
/** Frontend style handle or path */
|
|
232
|
+
style?: string | string[];
|
|
233
|
+
/** View style (non-admin, non-editor) */
|
|
234
|
+
viewStyle?: string | string[];
|
|
235
|
+
/** Render callback path */
|
|
236
|
+
render?: string;
|
|
237
|
+
/** Block variations */
|
|
238
|
+
variations?: Array<{
|
|
239
|
+
name: string;
|
|
240
|
+
title: string;
|
|
241
|
+
description?: string;
|
|
242
|
+
category?: string;
|
|
243
|
+
icon?: string;
|
|
244
|
+
isDefault?: boolean;
|
|
245
|
+
attributes?: Record<string, unknown>;
|
|
246
|
+
innerBlocks?: Array<{
|
|
247
|
+
name: string;
|
|
248
|
+
attributes?: Record<string, unknown>;
|
|
249
|
+
innerBlocks?: unknown[];
|
|
250
|
+
}>;
|
|
251
|
+
example?: Record<string, unknown>;
|
|
252
|
+
scope?: ('inserter' | 'block' | 'transform')[];
|
|
253
|
+
keywords?: string[];
|
|
254
|
+
isActive?: string[] | ((blockAttributes: Record<string, unknown>, variationAttributes: Record<string, unknown>) => boolean);
|
|
255
|
+
}>;
|
|
256
|
+
/** Block bindings sources */
|
|
257
|
+
selectors?: Record<string, string | {
|
|
258
|
+
source: string;
|
|
259
|
+
args?: Record<string, unknown>;
|
|
260
|
+
}>;
|
|
261
|
+
}
|
|
262
|
+
//# sourceMappingURL=block-json.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"block-json.d.ts","sourceRoot":"","sources":["../../src/types/block-json.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAC1B,QAAQ,GACR,QAAQ,GACR,SAAS,GACT,SAAS,GACT,QAAQ,GACR,OAAO,GACP,MAAM,GACN,WAAW,CAAC;AAEhB;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACvC,iDAAiD;IACjD,IAAI,CAAC,EAAE,kBAAkB,GAAG,kBAAkB,EAAE,CAAC;IACjD,wCAAwC;IACxC,IAAI,CAAC,EAAE,CAAC,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,EAAE,CAAC;IACrC,oBAAoB;IACpB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,wDAAwD;IACxD,MAAM,CAAC,EAAE,WAAW,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,GAAG,KAAK,CAAC;IAClE,8BAA8B;IAC9B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,qCAAqC;IACrC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,+CAA+C;IAC/C,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;IAC7B,yCAAyC;IACzC,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,wBAAwB,CAAC,CAAC;IACjD,kCAAkC;IAClC,KAAK,CAAC,EAAE,wBAAwB,CAAC;IACjC,wCAAwC;IACxC,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,wBAAwB,CAAC,CAAC;CACvD;AAED;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC5B,4BAA4B;IAC5B,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,4BAA4B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,CAAC;QACd,SAAS,CAAC,EAAE,OAAO,CAAC;QACpB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QACrC,WAAW,CAAC,EAAE,KAAK,CAAC;YAClB,IAAI,EAAE,MAAM,CAAC;YACb,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;YACrC,WAAW,CAAC,EAAE,OAAO,EAAE,CAAC;SACzB,CAAC,CAAC;QACH,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAClC,KAAK,CAAC,EAAE,CAAC,UAAU,GAAG,OAAO,GAAG,WAAW,CAAC,EAAE,CAAC;QAC/C,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;QACpB,QAAQ,CAAC,EAAE,MAAM,EAAE,GAAG,CAAC,CAAC,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,mBAAmB,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,OAAO,CAAC,CAAC;KAC7H,CAAC,CAAC;IACH,6BAA6B;IAC7B,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KAAE,CAAC,CAAC;CACzF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"block-json.js","sourceRoot":"","sources":["../../src/types/block-json.ts"],"names":[],"mappings":"AAAA;;;;GAIG"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* A single entry in a WordPress block template.
|
|
4
|
+
* Format: [blockType, attributes?, innerBlocks?]
|
|
5
|
+
*
|
|
6
|
+
* This matches the PHP array format used in WordPress templates:
|
|
7
|
+
* ```php
|
|
8
|
+
* array(
|
|
9
|
+
* 'core/paragraph',
|
|
10
|
+
* array( 'content' => 'Hello world' ),
|
|
11
|
+
* array() // inner blocks
|
|
12
|
+
* )
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export type BlockTemplateEntry = [string] | [string, Record<string, unknown>] | [string, Record<string, unknown>, BlockTemplateEntry[]];
|
|
16
|
+
/**
|
|
17
|
+
* A WordPress block template (array of template entries).
|
|
18
|
+
* This is the PHP-style nested array format used in WordPress block templates.
|
|
19
|
+
*
|
|
20
|
+
* Example:
|
|
21
|
+
* ```typescript
|
|
22
|
+
* const template: BlockTemplate = [
|
|
23
|
+
* ['core/group', { layout: { type: 'constrained' } }, [
|
|
24
|
+
* ['core/heading', { content: 'Title', level: 2 }],
|
|
25
|
+
* ['core/paragraph', { content: 'Content' }],
|
|
26
|
+
* ]],
|
|
27
|
+
* ];
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export type BlockTemplate = BlockTemplateEntry[];
|
|
31
|
+
/**
|
|
32
|
+
* Zod schema for recursive BlockTemplateEntry validation.
|
|
33
|
+
*/
|
|
34
|
+
export declare const blockTemplateEntrySchema: z.ZodType<BlockTemplateEntry>;
|
|
35
|
+
/**
|
|
36
|
+
* Zod schema for BlockTemplate validation.
|
|
37
|
+
*/
|
|
38
|
+
export declare const blockTemplateSchema: z.ZodArray<z.ZodType<BlockTemplateEntry, z.ZodTypeDef, BlockTemplateEntry>, "many">;
|
|
39
|
+
export type BlockTemplateEntrySchema = z.infer<typeof blockTemplateEntrySchema>;
|
|
40
|
+
export type BlockTemplateSchema = z.infer<typeof blockTemplateSchema>;
|
|
41
|
+
//# sourceMappingURL=block-template.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"block-template.d.ts","sourceRoot":"","sources":["../../src/types/block-template.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,kBAAkB,GAC1B,CAAC,MAAM,CAAC,GACR,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GACjC,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,kBAAkB,EAAE,CAAC,CAAC;AAE5D;;;;;;;;;;;;;GAaG;AACH,MAAM,MAAM,aAAa,GAAG,kBAAkB,EAAE,CAAC;AAEjD;;GAEG;AACH,eAAO,MAAM,wBAAwB,EAAE,CAAC,CAAC,OAAO,CAAC,kBAAkB,CAWlE,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,mBAAmB,qFAAoC,CAAC;AAErE,MAAM,MAAM,wBAAwB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,wBAAwB,CAAC,CAAC;AAChF,MAAM,MAAM,mBAAmB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* Zod schema for recursive BlockTemplateEntry validation.
|
|
4
|
+
*/
|
|
5
|
+
export const blockTemplateEntrySchema = z.lazy(() => z.union([
|
|
6
|
+
z.tuple([z.string().min(1)]),
|
|
7
|
+
z.tuple([z.string().min(1), z.record(z.unknown())]),
|
|
8
|
+
z.tuple([
|
|
9
|
+
z.string().min(1),
|
|
10
|
+
z.record(z.unknown()),
|
|
11
|
+
z.array(blockTemplateEntrySchema),
|
|
12
|
+
]),
|
|
13
|
+
]));
|
|
14
|
+
/**
|
|
15
|
+
* Zod schema for BlockTemplate validation.
|
|
16
|
+
*/
|
|
17
|
+
export const blockTemplateSchema = z.array(blockTemplateEntrySchema);
|
|
18
|
+
//# sourceMappingURL=block-template.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"block-template.js","sourceRoot":"","sources":["../../src/types/block-template.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAoCxB;;GAEG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAkC,CAAC,CAAC,IAAI,CAC3E,GAAG,EAAE,CACH,CAAC,CAAC,KAAK,CAAC;IACN,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IAC5B,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;IACnD,CAAC,CAAC,KAAK,CAAC;QACN,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;QACjB,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC;QACrB,CAAC,CAAC,KAAK,CAAC,wBAAwB,CAAC;KAClC,CAAC;CACH,CAAC,CACL,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAC,KAAK,CAAC,wBAAwB,CAAC,CAAC"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* A single block element in the tree.
|
|
4
|
+
* Uses a flat structure with key references instead of deep nesting.
|
|
5
|
+
*/
|
|
6
|
+
export interface BlockElement {
|
|
7
|
+
/** Unique identifier for this element */
|
|
8
|
+
key: string;
|
|
9
|
+
/** Block name, e.g., "core/paragraph", "core/group" */
|
|
10
|
+
type: string;
|
|
11
|
+
/** Block attributes/props */
|
|
12
|
+
props: Record<string, unknown>;
|
|
13
|
+
/** Keys of child elements (for blocks with InnerBlocks) */
|
|
14
|
+
children?: string[];
|
|
15
|
+
/** Key of the parent element */
|
|
16
|
+
parentKey?: string;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* The complete block tree structure.
|
|
20
|
+
* Inspired by Vercel's json-render - uses a flat map with key references.
|
|
21
|
+
*/
|
|
22
|
+
export interface BlockTree {
|
|
23
|
+
/** Key of the root element */
|
|
24
|
+
root: string;
|
|
25
|
+
/** Map of element keys to BlockElement objects */
|
|
26
|
+
elements: Record<string, BlockElement>;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Zod schema for BlockElement
|
|
30
|
+
*/
|
|
31
|
+
export declare const blockElementSchema: z.ZodObject<{
|
|
32
|
+
key: z.ZodString;
|
|
33
|
+
type: z.ZodString;
|
|
34
|
+
props: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
35
|
+
children: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
36
|
+
parentKey: z.ZodOptional<z.ZodString>;
|
|
37
|
+
}, "strip", z.ZodTypeAny, {
|
|
38
|
+
key: string;
|
|
39
|
+
type: string;
|
|
40
|
+
props: Record<string, unknown>;
|
|
41
|
+
children?: string[] | undefined;
|
|
42
|
+
parentKey?: string | undefined;
|
|
43
|
+
}, {
|
|
44
|
+
key: string;
|
|
45
|
+
type: string;
|
|
46
|
+
props: Record<string, unknown>;
|
|
47
|
+
children?: string[] | undefined;
|
|
48
|
+
parentKey?: string | undefined;
|
|
49
|
+
}>;
|
|
50
|
+
/**
|
|
51
|
+
* Zod schema for BlockTree
|
|
52
|
+
*/
|
|
53
|
+
export declare const blockTreeSchema: z.ZodObject<{
|
|
54
|
+
root: z.ZodString;
|
|
55
|
+
elements: z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
56
|
+
key: z.ZodString;
|
|
57
|
+
type: z.ZodString;
|
|
58
|
+
props: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
59
|
+
children: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
60
|
+
parentKey: z.ZodOptional<z.ZodString>;
|
|
61
|
+
}, "strip", z.ZodTypeAny, {
|
|
62
|
+
key: string;
|
|
63
|
+
type: string;
|
|
64
|
+
props: Record<string, unknown>;
|
|
65
|
+
children?: string[] | undefined;
|
|
66
|
+
parentKey?: string | undefined;
|
|
67
|
+
}, {
|
|
68
|
+
key: string;
|
|
69
|
+
type: string;
|
|
70
|
+
props: Record<string, unknown>;
|
|
71
|
+
children?: string[] | undefined;
|
|
72
|
+
parentKey?: string | undefined;
|
|
73
|
+
}>>;
|
|
74
|
+
}, "strip", z.ZodTypeAny, {
|
|
75
|
+
root: string;
|
|
76
|
+
elements: Record<string, {
|
|
77
|
+
key: string;
|
|
78
|
+
type: string;
|
|
79
|
+
props: Record<string, unknown>;
|
|
80
|
+
children?: string[] | undefined;
|
|
81
|
+
parentKey?: string | undefined;
|
|
82
|
+
}>;
|
|
83
|
+
}, {
|
|
84
|
+
root: string;
|
|
85
|
+
elements: Record<string, {
|
|
86
|
+
key: string;
|
|
87
|
+
type: string;
|
|
88
|
+
props: Record<string, unknown>;
|
|
89
|
+
children?: string[] | undefined;
|
|
90
|
+
parentKey?: string | undefined;
|
|
91
|
+
}>;
|
|
92
|
+
}>;
|
|
93
|
+
export type BlockElementSchema = z.infer<typeof blockElementSchema>;
|
|
94
|
+
export type BlockTreeSchema = z.infer<typeof blockTreeSchema>;
|
|
95
|
+
//# sourceMappingURL=block-tree.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"block-tree.d.ts","sourceRoot":"","sources":["../../src/types/block-tree.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;GAGG;AACH,MAAM,WAAW,YAAY;IAC3B,yCAAyC;IACzC,GAAG,EAAE,MAAM,CAAC;IACZ,uDAAuD;IACvD,IAAI,EAAE,MAAM,CAAC;IACb,6BAA6B;IAC7B,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,2DAA2D;IAC3D,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,gCAAgC;IAChC,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;GAGG;AACH,MAAM,WAAW,SAAS;IACxB,8BAA8B;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,kDAAkD;IAClD,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;CACxC;AAED;;GAEG;AACH,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;EAM7B,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAG1B,CAAC;AAEH,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAC;AACpE,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,eAAe,CAAC,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* Zod schema for BlockElement
|
|
4
|
+
*/
|
|
5
|
+
export const blockElementSchema = z.object({
|
|
6
|
+
key: z.string().min(1),
|
|
7
|
+
type: z.string().min(1),
|
|
8
|
+
props: z.record(z.unknown()),
|
|
9
|
+
children: z.array(z.string()).optional(),
|
|
10
|
+
parentKey: z.string().optional(),
|
|
11
|
+
});
|
|
12
|
+
/**
|
|
13
|
+
* Zod schema for BlockTree
|
|
14
|
+
*/
|
|
15
|
+
export const blockTreeSchema = z.object({
|
|
16
|
+
root: z.string().min(1),
|
|
17
|
+
elements: z.record(blockElementSchema),
|
|
18
|
+
});
|
|
19
|
+
//# sourceMappingURL=block-tree.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"block-tree.js","sourceRoot":"","sources":["../../src/types/block-tree.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AA8BxB;;GAEG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,CAAC,MAAM,CAAC;IACzC,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IACtB,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IACvB,KAAK,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC;IAC5B,QAAQ,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,QAAQ,EAAE;IACxC,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;CACjC,CAAC,CAAC;AAEH;;GAEG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,CAAC,MAAM,CAAC;IACtC,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IACvB,QAAQ,EAAE,CAAC,CAAC,MAAM,CAAC,kBAAkB,CAAC;CACvC,CAAC,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* Options for PHP pattern transformation.
|
|
4
|
+
* Enables conversion of rendered block markup to PHP pattern format
|
|
5
|
+
* with translatable strings and dynamic asset URLs.
|
|
6
|
+
*/
|
|
7
|
+
export interface PhpPatternOptions {
|
|
8
|
+
/** Theme text domain for translation functions (e.g., 'theme-slug') */
|
|
9
|
+
textDomain: string;
|
|
10
|
+
/** Asset directory name for image path transformation (default: 'assets') */
|
|
11
|
+
assetDirectory?: string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Zod schema for PhpPatternOptions
|
|
15
|
+
*/
|
|
16
|
+
export declare const phpPatternOptionsSchema: z.ZodObject<{
|
|
17
|
+
textDomain: z.ZodString;
|
|
18
|
+
assetDirectory: z.ZodOptional<z.ZodString>;
|
|
19
|
+
}, "strip", z.ZodTypeAny, {
|
|
20
|
+
textDomain: string;
|
|
21
|
+
assetDirectory?: string | undefined;
|
|
22
|
+
}, {
|
|
23
|
+
textDomain: string;
|
|
24
|
+
assetDirectory?: string | undefined;
|
|
25
|
+
}>;
|
|
26
|
+
export type PhpPatternOptionsSchema = z.infer<typeof phpPatternOptionsSchema>;
|
|
27
|
+
//# sourceMappingURL=php-transforms.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"php-transforms.d.ts","sourceRoot":"","sources":["../../src/types/php-transforms.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;;GAIG;AACH,MAAM,WAAW,iBAAiB;IAChC,uEAAuE;IACvE,UAAU,EAAE,MAAM,CAAC;IACnB,6EAA6E;IAC7E,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED;;GAEG;AACH,eAAO,MAAM,uBAAuB;;;;;;;;;EAGlC,CAAC;AAEH,MAAM,MAAM,uBAAuB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,uBAAuB,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"php-transforms.js","sourceRoot":"","sources":["../../src/types/php-transforms.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAcxB;;GAEG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC9C,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IAC7B,cAAc,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;CACtC,CAAC,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@10up/block-renderer-core",
|
|
3
|
+
"version": "0.1.4",
|
|
4
|
+
"description": "Core types and interfaces for block-renderer",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"zod": "^3.24.0"
|
|
20
|
+
},
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"typescript": "^5.7.0",
|
|
23
|
+
"vitest": "^2.1.0"
|
|
24
|
+
},
|
|
25
|
+
"keywords": [
|
|
26
|
+
"wordpress",
|
|
27
|
+
"blocks",
|
|
28
|
+
"gutenberg",
|
|
29
|
+
"json",
|
|
30
|
+
"renderer"
|
|
31
|
+
],
|
|
32
|
+
"license": "MIT",
|
|
33
|
+
"repository": {
|
|
34
|
+
"type": "git",
|
|
35
|
+
"url": "https://github.com/10up/json-block-renderer",
|
|
36
|
+
"directory": "packages/core"
|
|
37
|
+
},
|
|
38
|
+
"publishConfig": {
|
|
39
|
+
"access": "public"
|
|
40
|
+
},
|
|
41
|
+
"scripts": {
|
|
42
|
+
"build": "tsc -p tsconfig.build.json",
|
|
43
|
+
"dev": "tsc -p tsconfig.build.json --watch",
|
|
44
|
+
"typecheck": "tsc --noEmit",
|
|
45
|
+
"clean": "rm -rf dist",
|
|
46
|
+
"test": "vitest run",
|
|
47
|
+
"test:watch": "vitest"
|
|
48
|
+
}
|
|
49
|
+
}
|