@wp-typia/block-types 0.3.0 → 0.3.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.
- package/README.md +46 -0
- package/dist/blocks/bindings-codegen.d.ts +13 -0
- package/dist/blocks/bindings-codegen.js +210 -0
- package/dist/blocks/bindings-core.d.ts +123 -0
- package/dist/blocks/bindings-core.js +351 -0
- package/dist/blocks/bindings.d.ts +2 -132
- package/dist/blocks/bindings.js +2 -598
- package/dist/blocks/shared/diagnostics.d.ts +13 -0
- package/dist/blocks/shared/diagnostics.js +19 -0
- package/dist/blocks/shared/object-utils.d.ts +2 -0
- package/dist/blocks/shared/object-utils.js +10 -0
- package/dist/blocks/shared/static-registration.d.ts +4 -0
- package/dist/blocks/shared/static-registration.js +32 -0
- package/dist/blocks/supports.d.ts +3 -0
- package/dist/blocks/supports.js +14 -24
- package/dist/blocks/variations.d.ts +3 -0
- package/dist/blocks/variations.js +15 -55
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -108,6 +108,52 @@ generation. Non-strict mode downgrades them to warnings and recommends guarded
|
|
|
108
108
|
generation. Unknown future keys are guarded by default, or passed through only
|
|
109
109
|
when `allowUnknownFutureKeys` is enabled.
|
|
110
110
|
|
|
111
|
+
## Diagnostic output policy
|
|
112
|
+
|
|
113
|
+
Supports, Variations, and Bindings helpers keep diagnostics structured and
|
|
114
|
+
silent by default. Strict diagnostics still throw grouped errors, but non-strict
|
|
115
|
+
warnings do not write to `console.warn` unless a consumer opts into visible
|
|
116
|
+
output.
|
|
117
|
+
|
|
118
|
+
Use `onDiagnostic` when callers need callback-driven diagnostics for tests,
|
|
119
|
+
custom reporting, or UI integration:
|
|
120
|
+
|
|
121
|
+
```ts
|
|
122
|
+
const diagnostics: Array<{ message: string; severity: 'warning' | 'error' }> =
|
|
123
|
+
[];
|
|
124
|
+
|
|
125
|
+
defineSupports(
|
|
126
|
+
{
|
|
127
|
+
allowedBlocks: true,
|
|
128
|
+
minWordPress: '6.8',
|
|
129
|
+
strict: false,
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
onDiagnostic: (diagnostic) => {
|
|
133
|
+
diagnostics.push(diagnostic);
|
|
134
|
+
},
|
|
135
|
+
},
|
|
136
|
+
);
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
Use `logger` when callers want formatted warning messages without taking over
|
|
140
|
+
the structured callback path. Passing `console` restores console warning output.
|
|
141
|
+
If both `onDiagnostic` and `logger` are provided, `onDiagnostic` handles the
|
|
142
|
+
diagnostic and the logger is not called.
|
|
143
|
+
|
|
144
|
+
```ts
|
|
145
|
+
defineSupports(
|
|
146
|
+
{
|
|
147
|
+
allowedBlocks: true,
|
|
148
|
+
minWordPress: '6.8',
|
|
149
|
+
strict: false,
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
logger: console,
|
|
153
|
+
},
|
|
154
|
+
);
|
|
155
|
+
```
|
|
156
|
+
|
|
111
157
|
## Validation coverage
|
|
112
158
|
|
|
113
159
|
`@wp-typia/block-types` now validates itself with a mixed strategy that matches
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type DefinedBindingSource } from "./bindings-core.js";
|
|
2
|
+
export interface CreatePhpBindingSourceRegistrationSourceOptions {
|
|
3
|
+
readonly functionName?: string;
|
|
4
|
+
readonly hook?: string;
|
|
5
|
+
readonly includeOpeningTag?: boolean;
|
|
6
|
+
readonly textDomain?: string;
|
|
7
|
+
}
|
|
8
|
+
export interface CreateEditorBindingSourceRegistrationSourceOptions {
|
|
9
|
+
readonly functionName?: string;
|
|
10
|
+
readonly importSource?: string;
|
|
11
|
+
}
|
|
12
|
+
export declare function createPhpBindingSourceRegistrationSource(sources: DefinedBindingSource | readonly DefinedBindingSource[], options?: CreatePhpBindingSourceRegistrationSourceOptions): string;
|
|
13
|
+
export declare function createEditorBindingSourceRegistrationSource(sources: DefinedBindingSource | readonly DefinedBindingSource[], options?: CreateEditorBindingSourceRegistrationSourceOptions): string;
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import { createBindingSourceRegistrationPlan, } from "./bindings-core.js";
|
|
2
|
+
import { normalizeStaticRegistrationValue } from "./shared/static-registration.js";
|
|
3
|
+
function getBindingEvaluation(metadata, feature) {
|
|
4
|
+
return metadata.manifest.evaluations.find((evaluation) => evaluation.area === "blockBindings" && evaluation.feature === feature);
|
|
5
|
+
}
|
|
6
|
+
function shouldGenerateFeature(metadata, feature) {
|
|
7
|
+
const evaluation = getBindingEvaluation(metadata, feature);
|
|
8
|
+
return evaluation?.action === "generate";
|
|
9
|
+
}
|
|
10
|
+
function asSourceList(sources) {
|
|
11
|
+
if (Array.isArray(sources)) {
|
|
12
|
+
return sources;
|
|
13
|
+
}
|
|
14
|
+
return [sources];
|
|
15
|
+
}
|
|
16
|
+
function escapePhpSingleQuotedString(value) {
|
|
17
|
+
return value.replace(/\\/gu, "\\\\").replace(/'/gu, "\\'");
|
|
18
|
+
}
|
|
19
|
+
function phpString(value) {
|
|
20
|
+
return `'${escapePhpSingleQuotedString(value)}'`;
|
|
21
|
+
}
|
|
22
|
+
function phpStringArray(values) {
|
|
23
|
+
return values.length === 0
|
|
24
|
+
? "array()"
|
|
25
|
+
: `array( ${values.map((value) => phpString(value)).join(", ")} )`;
|
|
26
|
+
}
|
|
27
|
+
const PHP_IDENTIFIER_PATTERN = /^[A-Za-z_][A-Za-z0-9_]*$/u;
|
|
28
|
+
function sanitizePhpIdentifier(value) {
|
|
29
|
+
if (PHP_IDENTIFIER_PATTERN.test(value)) {
|
|
30
|
+
return value;
|
|
31
|
+
}
|
|
32
|
+
const sanitized = value.replace(/[^A-Za-z0-9_]/gu, "_").replace(/_+/gu, "_");
|
|
33
|
+
return /^[A-Za-z_]/u.test(sanitized) ? sanitized : `wp_typia_${sanitized}`;
|
|
34
|
+
}
|
|
35
|
+
function createPhpIdentifierHash(value) {
|
|
36
|
+
let hash = 0x811c9dc5;
|
|
37
|
+
for (const character of value) {
|
|
38
|
+
hash ^= character.codePointAt(0) ?? 0;
|
|
39
|
+
hash = Math.imul(hash, 0x01000193) >>> 0;
|
|
40
|
+
}
|
|
41
|
+
return hash.toString(36);
|
|
42
|
+
}
|
|
43
|
+
function createPhpSourceProperties(source, options) {
|
|
44
|
+
const properties = [];
|
|
45
|
+
if (source.label) {
|
|
46
|
+
const label = options.textDomain
|
|
47
|
+
? `__( ${phpString(source.label)}, ${phpString(options.textDomain)} )`
|
|
48
|
+
: phpString(source.label);
|
|
49
|
+
properties.push(`'label' => ${label}`);
|
|
50
|
+
}
|
|
51
|
+
if (source.usesContext && source.usesContext.length > 0) {
|
|
52
|
+
properties.push(`'uses_context' => ${phpStringArray(source.usesContext)}`);
|
|
53
|
+
}
|
|
54
|
+
if (source.getValueCallback) {
|
|
55
|
+
properties.push(`'get_value_callback' => ${phpString(source.getValueCallback)}`);
|
|
56
|
+
}
|
|
57
|
+
return properties;
|
|
58
|
+
}
|
|
59
|
+
function createPhpBindableAttributeFilterSource(entries, functionName) {
|
|
60
|
+
const lines = [];
|
|
61
|
+
const targets = entries.flatMap((entry) => (entry.source.bindableAttributes ?? []).map((target, index) => ({
|
|
62
|
+
index,
|
|
63
|
+
metadata: entry.metadata,
|
|
64
|
+
sourceName: entry.source.name,
|
|
65
|
+
target,
|
|
66
|
+
})));
|
|
67
|
+
if (targets.length === 0) {
|
|
68
|
+
return lines;
|
|
69
|
+
}
|
|
70
|
+
lines.push("");
|
|
71
|
+
lines.push("if ( function_exists( 'get_block_bindings_supported_attributes' ) ) {");
|
|
72
|
+
for (const [targetIndex, target] of targets.entries()) {
|
|
73
|
+
if (!shouldGenerateFeature(target.metadata, "supportedAttributesFilter")) {
|
|
74
|
+
lines.push(`\t// block_bindings_supported_attributes requires WordPress 6.9+ for ${target.target.blockName}.`);
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
const callbackSeed = [
|
|
78
|
+
functionName,
|
|
79
|
+
target.sourceName,
|
|
80
|
+
target.target.blockName,
|
|
81
|
+
String(target.index),
|
|
82
|
+
String(targetIndex),
|
|
83
|
+
].join("\0");
|
|
84
|
+
const callbackName = sanitizePhpIdentifier(`${functionName}_${target.sourceName}_${target.target.blockName}_${target.index}_${targetIndex}_${createPhpIdentifierHash(callbackSeed)}_supported_attributes`);
|
|
85
|
+
lines.push(`\tadd_filter( ${phpString(`block_bindings_supported_attributes_${target.target.blockName}`)}, ${phpString(callbackName)} );`);
|
|
86
|
+
lines.push(`\tfunction ${callbackName}( $supported_attributes ) {`);
|
|
87
|
+
lines.push(`\t\treturn array_values( array_unique( array_merge( $supported_attributes, ${phpStringArray(target.target.attributes)} ) ) );`);
|
|
88
|
+
lines.push("\t}");
|
|
89
|
+
}
|
|
90
|
+
lines.push("}");
|
|
91
|
+
return lines;
|
|
92
|
+
}
|
|
93
|
+
export function createPhpBindingSourceRegistrationSource(sources, options = {}) {
|
|
94
|
+
const functionName = sanitizePhpIdentifier(options.functionName ?? "wp_typia_register_block_binding_sources");
|
|
95
|
+
const hook = options.hook ?? "init";
|
|
96
|
+
const entries = createBindingSourceRegistrationPlan(asSourceList(sources));
|
|
97
|
+
const lines = [];
|
|
98
|
+
if (options.includeOpeningTag ?? false) {
|
|
99
|
+
lines.push("<?php");
|
|
100
|
+
lines.push("");
|
|
101
|
+
}
|
|
102
|
+
lines.push(`function ${functionName}() {`);
|
|
103
|
+
lines.push("\tif ( ! function_exists( 'register_block_bindings_source' ) ) {");
|
|
104
|
+
lines.push("\t\treturn;");
|
|
105
|
+
lines.push("\t}");
|
|
106
|
+
lines.push("");
|
|
107
|
+
for (const entry of entries) {
|
|
108
|
+
if (!shouldGenerateFeature(entry.metadata, "serverRegistration")) {
|
|
109
|
+
lines.push(`\t// register_block_bindings_source() requires WordPress 6.5+ for ${entry.source.name}.`);
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
const properties = createPhpSourceProperties(entry.source, options);
|
|
113
|
+
lines.push(`\tregister_block_bindings_source( ${phpString(entry.source.name)}, array(`);
|
|
114
|
+
for (const property of properties) {
|
|
115
|
+
lines.push(`\t\t${property},`);
|
|
116
|
+
}
|
|
117
|
+
lines.push("\t) );");
|
|
118
|
+
}
|
|
119
|
+
lines.push("}");
|
|
120
|
+
lines.push(`add_action( ${phpString(hook)}, ${phpString(functionName)} );`);
|
|
121
|
+
lines.push(...createPhpBindableAttributeFilterSource(entries, functionName));
|
|
122
|
+
lines.push("");
|
|
123
|
+
return lines.join("\n");
|
|
124
|
+
}
|
|
125
|
+
function createEditorRegistrationEntries(entries) {
|
|
126
|
+
const fields = {};
|
|
127
|
+
const skipped = [];
|
|
128
|
+
const skippedFields = [];
|
|
129
|
+
const sources = [];
|
|
130
|
+
for (const entry of entries) {
|
|
131
|
+
const editorEvaluation = getBindingEvaluation(entry.metadata, "editorRegistration");
|
|
132
|
+
if (editorEvaluation === undefined) {
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
if (editorEvaluation.action !== "generate") {
|
|
136
|
+
skipped.push(entry.source.name);
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
sources.push(normalizeStaticRegistrationValue({
|
|
140
|
+
label: entry.source.label,
|
|
141
|
+
name: entry.source.name,
|
|
142
|
+
usesContext: entry.source.usesContext,
|
|
143
|
+
}, `sources.${entry.source.name}`, { description: "binding source" }));
|
|
144
|
+
if ((entry.source.fields?.length ?? 0) === 0) {
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
if (!shouldGenerateFeature(entry.metadata, "editorFieldsList")) {
|
|
148
|
+
skippedFields.push(entry.source.name);
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
151
|
+
fields[entry.source.name] = normalizeStaticRegistrationValue(entry.source.fields, `fields.${entry.source.name}`, { description: "binding source" });
|
|
152
|
+
}
|
|
153
|
+
return {
|
|
154
|
+
fields,
|
|
155
|
+
skipped,
|
|
156
|
+
skippedFields,
|
|
157
|
+
sources,
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
export function createEditorBindingSourceRegistrationSource(sources, options = {}) {
|
|
161
|
+
const importSource = options.importSource ?? "@wordpress/blocks";
|
|
162
|
+
const functionName = options.functionName ?? "registerWpTypiaBindingSources";
|
|
163
|
+
const entries = createBindingSourceRegistrationPlan(asSourceList(sources));
|
|
164
|
+
const registration = createEditorRegistrationEntries(entries);
|
|
165
|
+
if (registration.sources.length === 0) {
|
|
166
|
+
return [
|
|
167
|
+
"// No editor block binding sources were generated.",
|
|
168
|
+
...(registration.skipped.length > 0
|
|
169
|
+
? [
|
|
170
|
+
`// Skipped editor registration for ${registration.skipped.join(", ")}; registerBlockBindingsSource() requires WordPress 6.7+.`,
|
|
171
|
+
]
|
|
172
|
+
: []),
|
|
173
|
+
"",
|
|
174
|
+
].join("\n");
|
|
175
|
+
}
|
|
176
|
+
const serializedSources = JSON.stringify(registration.sources, null, 2);
|
|
177
|
+
const serializedFields = JSON.stringify(registration.fields, null, 2);
|
|
178
|
+
const hasGeneratedFields = Object.keys(registration.fields).length > 0;
|
|
179
|
+
const lines = [
|
|
180
|
+
`import { registerBlockBindingsSource } from ${JSON.stringify(importSource)};`,
|
|
181
|
+
"",
|
|
182
|
+
`const sources = ${serializedSources};`,
|
|
183
|
+
...(hasGeneratedFields ? [`const fieldsBySource = ${serializedFields};`] : []),
|
|
184
|
+
"",
|
|
185
|
+
`export function ${functionName}() {`,
|
|
186
|
+
" if (typeof registerBlockBindingsSource !== \"function\") {",
|
|
187
|
+
" return;",
|
|
188
|
+
" }",
|
|
189
|
+
" for (const source of sources) {",
|
|
190
|
+
...(hasGeneratedFields
|
|
191
|
+
? [
|
|
192
|
+
" const fields = fieldsBySource[source.name];",
|
|
193
|
+
" registerBlockBindingsSource({",
|
|
194
|
+
" ...source,",
|
|
195
|
+
" ...(fields ? { getFieldsList: () => fields } : {}),",
|
|
196
|
+
" });",
|
|
197
|
+
]
|
|
198
|
+
: [" registerBlockBindingsSource(source);"]),
|
|
199
|
+
" }",
|
|
200
|
+
"}",
|
|
201
|
+
];
|
|
202
|
+
if (registration.skipped.length > 0) {
|
|
203
|
+
lines.push("", `// Skipped editor registration for ${registration.skipped.join(", ")}; registerBlockBindingsSource() requires WordPress 6.7+.`);
|
|
204
|
+
}
|
|
205
|
+
if (registration.skippedFields.length > 0) {
|
|
206
|
+
lines.push("", `// Skipped getFieldsList() for ${registration.skippedFields.join(", ")}; getFieldsList() requires WordPress 6.9+.`);
|
|
207
|
+
}
|
|
208
|
+
lines.push("");
|
|
209
|
+
return lines.join("\n");
|
|
210
|
+
}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import type { BlockAttributes } from "./registration.js";
|
|
2
|
+
import { type WordPressBlockApiCompatibilityDiagnostic, type WordPressBlockApiCompatibilityFeature, type WordPressBlockApiCompatibilityManifest, type WordPressCompatibilitySettings, type WordPressVersion } from "./compatibility.js";
|
|
3
|
+
import { type DiagnosticLogger } from "./shared/diagnostics.js";
|
|
4
|
+
export type BindingSourceName = `${string}/${string}`;
|
|
5
|
+
export type BindingSourceArgs = Readonly<Record<string, unknown>>;
|
|
6
|
+
export type BindingFieldType = "array" | "boolean" | "integer" | "number" | "object" | "string";
|
|
7
|
+
export interface BindingSourceField<TArgs extends BindingSourceArgs = BindingSourceArgs> {
|
|
8
|
+
readonly args?: TArgs;
|
|
9
|
+
readonly label: string;
|
|
10
|
+
readonly name: string;
|
|
11
|
+
readonly type?: BindingFieldType;
|
|
12
|
+
}
|
|
13
|
+
export type BlockBindingAttributeName<TAttributes extends BlockAttributes = BlockAttributes> = Extract<Exclude<keyof TAttributes, "metadata">, string>;
|
|
14
|
+
export interface BindingSourceBindableAttributes<TAttributes extends BlockAttributes = BlockAttributes, TBlockName extends string = string, TAttributesList extends readonly BlockBindingAttributeName<TAttributes>[] = readonly BlockBindingAttributeName<TAttributes>[]> {
|
|
15
|
+
readonly attributes: TAttributesList;
|
|
16
|
+
readonly blockName: TBlockName;
|
|
17
|
+
}
|
|
18
|
+
export interface BindingSourceDefinition<TName extends string = string, TArgs extends BindingSourceArgs = BindingSourceArgs, TFields extends readonly BindingSourceField[] = readonly BindingSourceField[]> {
|
|
19
|
+
readonly args?: TArgs;
|
|
20
|
+
readonly bindableAttributes?: readonly BindingSourceBindableAttributes[];
|
|
21
|
+
readonly fields?: TFields;
|
|
22
|
+
readonly getValueCallback?: string;
|
|
23
|
+
readonly label?: string;
|
|
24
|
+
readonly name: TName;
|
|
25
|
+
readonly usesContext?: readonly string[];
|
|
26
|
+
}
|
|
27
|
+
export interface BindingSourceVersionGates {
|
|
28
|
+
readonly editor?: WordPressVersion;
|
|
29
|
+
readonly fieldsList?: WordPressVersion;
|
|
30
|
+
readonly server?: WordPressVersion;
|
|
31
|
+
readonly supportedAttributesFilter?: WordPressVersion;
|
|
32
|
+
}
|
|
33
|
+
export interface DefineBindingSourceInlineOptions {
|
|
34
|
+
readonly allowUnknownFutureKeys?: boolean;
|
|
35
|
+
readonly editor?: boolean;
|
|
36
|
+
readonly fieldsList?: boolean;
|
|
37
|
+
readonly logger?: DiagnosticLogger<BindingSourceDiagnostic>;
|
|
38
|
+
readonly minVersion?: WordPressVersion;
|
|
39
|
+
readonly minWordPress?: WordPressVersion | BindingSourceVersionGates;
|
|
40
|
+
readonly minWordPressEditor?: WordPressVersion;
|
|
41
|
+
readonly minWordPressFieldsList?: WordPressVersion;
|
|
42
|
+
readonly minWordPressServer?: WordPressVersion;
|
|
43
|
+
readonly minWordPressSupportedAttributesFilter?: WordPressVersion;
|
|
44
|
+
readonly onDiagnostic?: (diagnostic: BindingSourceDiagnostic) => void;
|
|
45
|
+
readonly server?: boolean;
|
|
46
|
+
readonly strict?: boolean;
|
|
47
|
+
readonly supportedAttributesFilter?: boolean;
|
|
48
|
+
}
|
|
49
|
+
export interface DefineBindingSourceOptions extends WordPressCompatibilitySettings {
|
|
50
|
+
readonly editor?: boolean;
|
|
51
|
+
readonly fieldsList?: boolean;
|
|
52
|
+
readonly logger?: DiagnosticLogger<BindingSourceDiagnostic>;
|
|
53
|
+
readonly minWordPress?: WordPressVersion | BindingSourceVersionGates;
|
|
54
|
+
readonly minWordPressEditor?: WordPressVersion;
|
|
55
|
+
readonly minWordPressFieldsList?: WordPressVersion;
|
|
56
|
+
readonly minWordPressServer?: WordPressVersion;
|
|
57
|
+
readonly minWordPressSupportedAttributesFilter?: WordPressVersion;
|
|
58
|
+
readonly onDiagnostic?: (diagnostic: BindingSourceDiagnostic) => void;
|
|
59
|
+
readonly server?: boolean;
|
|
60
|
+
readonly supportedAttributesFilter?: boolean;
|
|
61
|
+
}
|
|
62
|
+
export type StripDefineBindingSourceOptions<TSource> = Omit<TSource, keyof DefineBindingSourceInlineOptions>;
|
|
63
|
+
export declare const DEFINED_BLOCK_BINDING_SOURCE_METADATA: unique symbol;
|
|
64
|
+
export type DefinedBlockBindingSourceMetadataKey = typeof DEFINED_BLOCK_BINDING_SOURCE_METADATA;
|
|
65
|
+
export interface DefinedBlockBindingSourceMetadata {
|
|
66
|
+
readonly diagnostics: readonly BindingSourceDiagnostic[];
|
|
67
|
+
readonly features: readonly WordPressBlockApiCompatibilityFeature[];
|
|
68
|
+
readonly manifest: WordPressBlockApiCompatibilityManifest;
|
|
69
|
+
}
|
|
70
|
+
export type DefinedBindingSource<TName extends string = string, TArgs extends BindingSourceArgs = BindingSourceArgs, TFields extends readonly BindingSourceField[] = readonly BindingSourceField[], TSource extends BindingSourceDefinition = BindingSourceDefinition> = Readonly<StripDefineBindingSourceOptions<TSource>> & {
|
|
71
|
+
readonly [DEFINED_BLOCK_BINDING_SOURCE_METADATA]?: DefinedBlockBindingSourceMetadata | undefined;
|
|
72
|
+
readonly __wpTypiaBindingSourceArgs?: TArgs;
|
|
73
|
+
readonly __wpTypiaBindingSourceFields?: TFields;
|
|
74
|
+
readonly name: TName;
|
|
75
|
+
};
|
|
76
|
+
export interface BlockBinding<TSourceName extends string = string, TArgs extends BindingSourceArgs = BindingSourceArgs> {
|
|
77
|
+
readonly args?: TArgs;
|
|
78
|
+
readonly source: TSourceName;
|
|
79
|
+
}
|
|
80
|
+
type BindingSourceInferredArgs<TSource> = TSource extends {
|
|
81
|
+
readonly __wpTypiaBindingSourceArgs?: infer TArgs extends BindingSourceArgs;
|
|
82
|
+
} ? TArgs : BindingSourceArgs;
|
|
83
|
+
export type Binding<TSource extends DefinedBindingSource | string, TArgs extends BindingSourceArgs = BindingSourceInferredArgs<TSource>> = TSource extends DefinedBindingSource<infer TName, infer TSourceArgs> ? TArgs extends TSourceArgs ? BlockBinding<TName, TArgs> : never : TSource extends string ? BlockBinding<TSource, TArgs> : never;
|
|
84
|
+
export type BlockBindingMap<TAttributes extends BlockAttributes = BlockAttributes> = Readonly<Partial<Record<BlockBindingAttributeName<TAttributes>, BlockBinding>>>;
|
|
85
|
+
export interface BlockMetadataBindings<TBindings extends Readonly<Record<string, BlockBinding | undefined>> = Readonly<Record<string, BlockBinding>>> {
|
|
86
|
+
readonly bindings?: TBindings;
|
|
87
|
+
}
|
|
88
|
+
export type TypedBlockMetadataBindings<TAttributes extends BlockAttributes, TBindings extends BlockBindingMap<TAttributes> = BlockBindingMap<TAttributes>> = BlockMetadataBindings<TBindings>;
|
|
89
|
+
export type BindingSourceDiagnosticCode = "duplicate-bindable-attribute" | "duplicate-field-name" | "fields-list-requires-editor" | "invalid-bindable-attribute" | "invalid-block-name" | "invalid-field-name" | "invalid-source-name" | "missing-php-callback";
|
|
90
|
+
export interface BindingSourceAuthoringDiagnostic {
|
|
91
|
+
readonly attribute?: string | undefined;
|
|
92
|
+
readonly blockName?: string | undefined;
|
|
93
|
+
readonly code: BindingSourceDiagnosticCode;
|
|
94
|
+
readonly fieldName?: string | undefined;
|
|
95
|
+
readonly message: string;
|
|
96
|
+
readonly severity: "error" | "warning";
|
|
97
|
+
readonly sourceName: string;
|
|
98
|
+
}
|
|
99
|
+
export type BindingSourceDiagnostic = BindingSourceAuthoringDiagnostic | WordPressBlockApiCompatibilityDiagnostic;
|
|
100
|
+
export interface BindingSourceRegistrationEntry {
|
|
101
|
+
readonly metadata: DefinedBlockBindingSourceMetadata;
|
|
102
|
+
readonly source: DefinedBindingSource;
|
|
103
|
+
}
|
|
104
|
+
export declare function collectBindingSourceCompatibilityFeatures(settings?: {
|
|
105
|
+
readonly editor?: boolean;
|
|
106
|
+
readonly fieldsList?: boolean;
|
|
107
|
+
readonly metadata?: boolean;
|
|
108
|
+
readonly server?: boolean;
|
|
109
|
+
readonly supportedAttributesFilter?: boolean;
|
|
110
|
+
}): readonly WordPressBlockApiCompatibilityFeature[];
|
|
111
|
+
export declare function createBindingSourceCompatibilityManifest(settings?: DefineBindingSourceOptions): WordPressBlockApiCompatibilityManifest;
|
|
112
|
+
export declare function getDefinedBindingSourceMetadata(source: unknown): DefinedBlockBindingSourceMetadata | undefined;
|
|
113
|
+
export declare function getDefinedBindingSourceCompatibilityManifest(source: unknown): WordPressBlockApiCompatibilityManifest | undefined;
|
|
114
|
+
export declare function defineBindingSource<const TSource extends BindingSourceDefinition & DefineBindingSourceInlineOptions>(source: TSource, options?: DefineBindingSourceOptions): DefinedBindingSource<Extract<TSource["name"], string>, TSource extends {
|
|
115
|
+
readonly args: infer TArgs extends BindingSourceArgs;
|
|
116
|
+
} ? TArgs : BindingSourceArgs, TSource extends {
|
|
117
|
+
readonly fields: infer TFields extends readonly BindingSourceField[];
|
|
118
|
+
} ? TFields : readonly BindingSourceField[], TSource>;
|
|
119
|
+
export declare function defineBindableAttributes<TAttributes extends BlockAttributes = BlockAttributes, const TBlockName extends string = string, const TAttributesList extends readonly BlockBindingAttributeName<TAttributes>[] = readonly BlockBindingAttributeName<TAttributes>[]>(blockName: TBlockName, attributes: TAttributesList): BindingSourceBindableAttributes<TAttributes, TBlockName, TAttributesList>;
|
|
120
|
+
export declare function defineBlockMetadataBindings<const TBindings extends Readonly<Record<string, BlockBinding | undefined>>>(bindings: TBindings): BlockMetadataBindings<TBindings>;
|
|
121
|
+
export declare function defineTypedBlockMetadataBindings<TAttributes extends BlockAttributes, const TBindings extends BlockBindingMap<TAttributes> = BlockBindingMap<TAttributes>>(bindings: TBindings): TypedBlockMetadataBindings<TAttributes, TBindings>;
|
|
122
|
+
export declare function createBindingSourceRegistrationPlan(sources: readonly DefinedBindingSource[]): readonly BindingSourceRegistrationEntry[];
|
|
123
|
+
export {};
|