@wp-typia/block-types 0.2.4 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +263 -15
- package/dist/blocks/bindings.d.ts +132 -0
- package/dist/blocks/bindings.js +598 -0
- package/dist/blocks/compatibility.d.ts +296 -0
- package/dist/blocks/compatibility.js +338 -0
- package/dist/blocks/index.d.ts +3 -0
- package/dist/blocks/index.js +3 -0
- package/dist/blocks/supports.d.ts +54 -2
- package/dist/blocks/supports.js +182 -0
- package/dist/blocks/variations.d.ts +84 -0
- package/dist/blocks/variations.js +298 -0
- package/package.json +16 -1
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import type { BlockAlignment, BlockVerticalAlignment, JustifyContent, TextAlignment } from "../block-editor/alignment.js";
|
|
2
|
+
import type { BlockBorderSupportAttributes, BlockColorSupportAttributes, BlockDimensionsSupportAttributes, BlockSpacingSupportAttributes, BlockStyleAttributes, BlockTypographySupportAttributes } from "../block-editor/style-attributes.js";
|
|
2
3
|
import type { FlexWrap, LayoutType, Orientation } from "../block-editor/layout.js";
|
|
3
4
|
import type { SpacingAxis, SpacingDimension } from "../block-editor/spacing.js";
|
|
5
|
+
import { type WordPressBlockApiCompatibilityDiagnostic, type WordPressBlockApiCompatibilityFeature, type WordPressBlockApiCompatibilityManifest, type WordPressCompatibilitySettings, type WordPressVersion } from "./compatibility.js";
|
|
4
6
|
/**
|
|
5
7
|
* Derived from Gutenberg block support keys and commonly used block.json
|
|
6
8
|
* support sections.
|
|
7
9
|
*/
|
|
8
|
-
export type BlockSupportFeature = 'align' | 'alignWide' | 'anchor' | 'ariaLabel' | 'background' | 'border' | 'className' | 'color' | 'customClassName' | 'dimensions' | 'filter' | 'html' | 'inserter' | 'interactivity' | 'js' | 'layout' | 'lightbox' | 'lock' | 'locking' | 'multiple' | 'position' | 'renaming' | 'reusable' | 'shadow' | 'spacing' | 'typography';
|
|
9
|
-
export declare const BLOCK_SUPPORT_FEATURES: readonly ["align", "alignWide", "anchor", "ariaLabel", "background", "border", "className", "color", "customClassName", "dimensions", "filter", "html", "inserter", "interactivity", "js", "layout", "lightbox", "lock", "locking", "multiple", "position", "renaming", "reusable", "shadow", "spacing", "typography"];
|
|
10
|
+
export type BlockSupportFeature = 'align' | 'alignWide' | 'allowedBlocks' | 'anchor' | 'ariaLabel' | 'autoRegister' | 'background' | 'border' | 'className' | 'color' | 'contentRole' | 'customClassName' | 'dimensions' | 'filter' | 'html' | 'inserter' | 'interactivity' | 'js' | 'layout' | 'lightbox' | 'listView' | 'lock' | 'locking' | 'multiple' | 'position' | 'renaming' | 'reusable' | 'shadow' | 'spacing' | 'splitting' | 'visibility' | 'typography';
|
|
11
|
+
export declare const BLOCK_SUPPORT_FEATURES: readonly ["align", "alignWide", "allowedBlocks", "anchor", "ariaLabel", "autoRegister", "background", "border", "className", "color", "contentRole", "customClassName", "dimensions", "filter", "html", "inserter", "interactivity", "js", "layout", "lightbox", "listView", "lock", "locking", "multiple", "position", "renaming", "reusable", "shadow", "spacing", "splitting", "typography", "visibility"];
|
|
10
12
|
export type TypographySupportKey = 'fontFamily' | 'fontSize' | 'fontStyle' | 'fontWeight' | 'letterSpacing' | 'lineHeight' | 'dropCap' | 'textAlign' | 'textColumns' | 'textDecoration' | 'textTransform' | 'writingMode';
|
|
11
13
|
export declare const TYPOGRAPHY_SUPPORT_KEYS: readonly ["fontFamily", "fontSize", "fontStyle", "fontWeight", "letterSpacing", "lineHeight", "dropCap", "textAlign", "textColumns", "textDecoration", "textTransform", "writingMode"];
|
|
12
14
|
export type SpacingSupportKey = 'blockGap' | 'margin' | 'padding';
|
|
@@ -139,12 +141,15 @@ export interface BlockTypographySupport {
|
|
|
139
141
|
export interface BlockSupports {
|
|
140
142
|
readonly align?: boolean | readonly BlockAlignment[];
|
|
141
143
|
readonly alignWide?: boolean;
|
|
144
|
+
readonly allowedBlocks?: boolean;
|
|
142
145
|
readonly anchor?: boolean;
|
|
143
146
|
readonly ariaLabel?: boolean;
|
|
147
|
+
readonly autoRegister?: boolean;
|
|
144
148
|
readonly background?: boolean | BlockBackgroundSupport;
|
|
145
149
|
readonly border?: boolean | BlockBorderSupport;
|
|
146
150
|
readonly className?: boolean;
|
|
147
151
|
readonly color?: boolean | BlockColorSupport;
|
|
152
|
+
readonly contentRole?: boolean;
|
|
148
153
|
readonly customClassName?: boolean;
|
|
149
154
|
readonly dimensions?: boolean | BlockDimensionsSupport;
|
|
150
155
|
readonly filter?: boolean | BlockFilterSupport;
|
|
@@ -154,6 +159,7 @@ export interface BlockSupports {
|
|
|
154
159
|
readonly js?: boolean;
|
|
155
160
|
readonly layout?: boolean | BlockLayoutSupport;
|
|
156
161
|
readonly lightbox?: boolean | BlockLightboxSupport;
|
|
162
|
+
readonly listView?: boolean;
|
|
157
163
|
readonly lock?: boolean;
|
|
158
164
|
readonly locking?: boolean;
|
|
159
165
|
readonly multiple?: boolean;
|
|
@@ -162,6 +168,52 @@ export interface BlockSupports {
|
|
|
162
168
|
readonly reusable?: boolean;
|
|
163
169
|
readonly shadow?: boolean | BlockShadowSupport;
|
|
164
170
|
readonly spacing?: boolean | BlockSpacingSupport;
|
|
171
|
+
readonly splitting?: boolean;
|
|
165
172
|
readonly typography?: boolean | BlockTypographySupport;
|
|
173
|
+
readonly visibility?: boolean;
|
|
166
174
|
}
|
|
175
|
+
export type BlockSupportsInput = BlockSupports & Readonly<Record<string, unknown>>;
|
|
176
|
+
export interface BlockAlignSupportAttributes {
|
|
177
|
+
readonly align?: BlockAlignment;
|
|
178
|
+
}
|
|
179
|
+
export interface BlockAllowedBlocksSupportAttributes {
|
|
180
|
+
readonly allowedBlocks?: readonly string[];
|
|
181
|
+
}
|
|
182
|
+
export interface BlockLayoutSupportAttributes {
|
|
183
|
+
readonly layout?: BlockLayoutDefault;
|
|
184
|
+
}
|
|
185
|
+
export interface BlockStyleAttributeSupportAttributes {
|
|
186
|
+
readonly style?: BlockStyleAttributes;
|
|
187
|
+
}
|
|
188
|
+
type SupportTruthy<TValue> = [TValue] extends [false | null | undefined] ? false : true;
|
|
189
|
+
type HasSupport<TSupports, TKey extends PropertyKey> = TKey extends keyof TSupports ? SupportTruthy<TSupports[TKey]> : false;
|
|
190
|
+
type HasNestedSupport<TSupports, TSection extends keyof BlockSupports, TKey extends PropertyKey> = TSection extends keyof TSupports ? TSupports[TSection] extends true ? true : TSupports[TSection] extends Readonly<Record<TKey, infer TValue>> ? SupportTruthy<TValue> : false : false;
|
|
191
|
+
type IfSupport<TCondition, TAttributes> = TCondition extends true ? TAttributes : {};
|
|
192
|
+
export interface DefineSupportsInlineOptions {
|
|
193
|
+
readonly allowUnknownFutureKeys?: boolean;
|
|
194
|
+
readonly minVersion?: WordPressVersion;
|
|
195
|
+
readonly minWordPress?: WordPressVersion;
|
|
196
|
+
readonly onDiagnostic?: (diagnostic: WordPressBlockApiCompatibilityDiagnostic) => void;
|
|
197
|
+
readonly strict?: boolean;
|
|
198
|
+
}
|
|
199
|
+
export interface DefineSupportsOptions extends WordPressCompatibilitySettings {
|
|
200
|
+
readonly minWordPress?: WordPressVersion;
|
|
201
|
+
readonly onDiagnostic?: (diagnostic: WordPressBlockApiCompatibilityDiagnostic) => void;
|
|
202
|
+
}
|
|
203
|
+
export type StripDefineSupportsOptions<TSupports> = Omit<TSupports, keyof DefineSupportsInlineOptions>;
|
|
204
|
+
export declare const DEFINED_BLOCK_SUPPORTS_METADATA: unique symbol;
|
|
205
|
+
export type DefinedBlockSupportsMetadataKey = typeof DEFINED_BLOCK_SUPPORTS_METADATA;
|
|
206
|
+
export interface DefinedBlockSupportsMetadata {
|
|
207
|
+
readonly diagnostics: readonly WordPressBlockApiCompatibilityDiagnostic[];
|
|
208
|
+
readonly manifest: WordPressBlockApiCompatibilityManifest;
|
|
209
|
+
}
|
|
210
|
+
export type DefinedBlockSupports<TSupports extends BlockSupportsInput = BlockSupportsInput> = Readonly<StripDefineSupportsOptions<TSupports>> & {
|
|
211
|
+
readonly [DEFINED_BLOCK_SUPPORTS_METADATA]?: DefinedBlockSupportsMetadata;
|
|
212
|
+
};
|
|
213
|
+
export type SupportAttributes<TSupports> = TSupports extends DefinedBlockSupports<infer TDefinedSupports> ? SupportAttributesFromBlockSupports<StripDefineSupportsOptions<TDefinedSupports>> : TSupports extends BlockSupportsInput ? SupportAttributesFromBlockSupports<StripDefineSupportsOptions<TSupports>> : {};
|
|
214
|
+
export type SupportAttributesFromBlockSupports<TSupports> = IfSupport<HasSupport<TSupports, "align">, BlockAlignSupportAttributes> & IfSupport<HasSupport<TSupports, "allowedBlocks">, BlockAllowedBlocksSupportAttributes> & IfSupport<HasSupport<TSupports, "layout">, BlockLayoutSupportAttributes> & IfSupport<HasSupport<TSupports, "color">, BlockColorSupportAttributes> & IfSupport<HasSupport<TSupports, "typography">, BlockTypographySupportAttributes> & IfSupport<HasSupport<TSupports, "spacing">, BlockSpacingSupportAttributes> & IfSupport<HasSupport<TSupports, "dimensions">, BlockDimensionsSupportAttributes> & IfSupport<HasSupport<TSupports, "border">, BlockBorderSupportAttributes> & IfSupport<HasSupport<TSupports, "background">, BlockStyleAttributeSupportAttributes> & IfSupport<HasNestedSupport<TSupports, "filter", "duotone">, BlockStyleAttributeSupportAttributes> & IfSupport<HasSupport<TSupports, "position">, BlockStyleAttributeSupportAttributes> & IfSupport<HasSupport<TSupports, "shadow">, BlockStyleAttributeSupportAttributes>;
|
|
215
|
+
export declare function collectBlockSupportsCompatibilityFeatures(supports: BlockSupportsInput): readonly WordPressBlockApiCompatibilityFeature[];
|
|
216
|
+
export declare function createBlockSupportsCompatibilityManifest(supports: BlockSupportsInput, settings?: DefineSupportsOptions): WordPressBlockApiCompatibilityManifest;
|
|
217
|
+
export declare function getDefinedSupportsCompatibilityManifest(supports: unknown): WordPressBlockApiCompatibilityManifest | undefined;
|
|
218
|
+
export declare function defineSupports<const TSupports extends BlockSupportsInput & DefineSupportsInlineOptions>(supports: TSupports, options?: DefineSupportsOptions): DefinedBlockSupports<TSupports>;
|
|
167
219
|
export {};
|
package/dist/blocks/supports.js
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
|
+
import { createWordPressBlockApiCompatibilityManifest, } from "./compatibility.js";
|
|
1
2
|
export const BLOCK_SUPPORT_FEATURES = [
|
|
2
3
|
'align',
|
|
3
4
|
'alignWide',
|
|
5
|
+
'allowedBlocks',
|
|
4
6
|
'anchor',
|
|
5
7
|
'ariaLabel',
|
|
8
|
+
'autoRegister',
|
|
6
9
|
'background',
|
|
7
10
|
'border',
|
|
8
11
|
'className',
|
|
9
12
|
'color',
|
|
13
|
+
'contentRole',
|
|
10
14
|
'customClassName',
|
|
11
15
|
'dimensions',
|
|
12
16
|
'filter',
|
|
@@ -16,6 +20,7 @@ export const BLOCK_SUPPORT_FEATURES = [
|
|
|
16
20
|
'js',
|
|
17
21
|
'layout',
|
|
18
22
|
'lightbox',
|
|
23
|
+
'listView',
|
|
19
24
|
'lock',
|
|
20
25
|
'locking',
|
|
21
26
|
'multiple',
|
|
@@ -24,7 +29,9 @@ export const BLOCK_SUPPORT_FEATURES = [
|
|
|
24
29
|
'reusable',
|
|
25
30
|
'shadow',
|
|
26
31
|
'spacing',
|
|
32
|
+
'splitting',
|
|
27
33
|
'typography',
|
|
34
|
+
'visibility',
|
|
28
35
|
];
|
|
29
36
|
export const TYPOGRAPHY_SUPPORT_KEYS = [
|
|
30
37
|
'fontFamily',
|
|
@@ -45,3 +52,178 @@ export const SPACING_SUPPORT_KEYS = [
|
|
|
45
52
|
'margin',
|
|
46
53
|
'padding',
|
|
47
54
|
];
|
|
55
|
+
export const DEFINED_BLOCK_SUPPORTS_METADATA = Symbol.for("@wp-typia/block-types/defined-supports");
|
|
56
|
+
const KNOWN_BLOCK_SUPPORT_FEATURES = new Set(BLOCK_SUPPORT_FEATURES);
|
|
57
|
+
const DEFINE_SUPPORTS_INLINE_OPTION_KEYS = new Set([
|
|
58
|
+
"allowUnknownFutureKeys",
|
|
59
|
+
"minVersion",
|
|
60
|
+
"minWordPress",
|
|
61
|
+
"onDiagnostic",
|
|
62
|
+
"strict",
|
|
63
|
+
]);
|
|
64
|
+
const COLOR_COMPATIBILITY_SUPPORT_KEYS = [
|
|
65
|
+
"button",
|
|
66
|
+
"enableContrastChecker",
|
|
67
|
+
"heading",
|
|
68
|
+
];
|
|
69
|
+
const TYPOGRAPHY_COMPATIBILITY_SUPPORT_KEYS = [
|
|
70
|
+
"fontSize",
|
|
71
|
+
"letterSpacing",
|
|
72
|
+
"lineHeight",
|
|
73
|
+
"textAlign",
|
|
74
|
+
"textDecoration",
|
|
75
|
+
"textTransform",
|
|
76
|
+
];
|
|
77
|
+
const TOP_LEVEL_COMPATIBILITY_SUPPORT_KEYS = [
|
|
78
|
+
"allowedBlocks",
|
|
79
|
+
"background",
|
|
80
|
+
"contentRole",
|
|
81
|
+
"dimensions",
|
|
82
|
+
"listView",
|
|
83
|
+
"position",
|
|
84
|
+
"renaming",
|
|
85
|
+
"shadow",
|
|
86
|
+
"visibility",
|
|
87
|
+
];
|
|
88
|
+
function isSupportObject(value) {
|
|
89
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
90
|
+
}
|
|
91
|
+
function isEnabledSupportValue(value) {
|
|
92
|
+
return value !== false && value !== null && value !== undefined;
|
|
93
|
+
}
|
|
94
|
+
function isEnabledTopLevelSupportValue(value) {
|
|
95
|
+
if (!isSupportObject(value)) {
|
|
96
|
+
return isEnabledSupportValue(value);
|
|
97
|
+
}
|
|
98
|
+
return Object.entries(value).some(([key, nestedValue]) => !key.startsWith("__experimental") &&
|
|
99
|
+
isEnabledSupportValue(nestedValue));
|
|
100
|
+
}
|
|
101
|
+
function hasEnabledNestedSupport(section, key) {
|
|
102
|
+
return isSupportObject(section) && isEnabledSupportValue(section[key]);
|
|
103
|
+
}
|
|
104
|
+
function addCompatibilityFeature(features, seen, feature) {
|
|
105
|
+
const id = `blockSupports.${feature}`;
|
|
106
|
+
if (seen.has(id)) {
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
seen.add(id);
|
|
110
|
+
features.push({
|
|
111
|
+
area: "blockSupports",
|
|
112
|
+
feature,
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
export function collectBlockSupportsCompatibilityFeatures(supports) {
|
|
116
|
+
const features = [];
|
|
117
|
+
const seen = new Set();
|
|
118
|
+
for (const key of TOP_LEVEL_COMPATIBILITY_SUPPORT_KEYS) {
|
|
119
|
+
if (isEnabledTopLevelSupportValue(supports[key])) {
|
|
120
|
+
addCompatibilityFeature(features, seen, key);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
const spacing = supports.spacing;
|
|
124
|
+
for (const key of SPACING_SUPPORT_KEYS) {
|
|
125
|
+
if (hasEnabledNestedSupport(spacing, key)) {
|
|
126
|
+
addCompatibilityFeature(features, seen, `spacing.${key}`);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
const typography = supports.typography;
|
|
130
|
+
for (const key of TYPOGRAPHY_COMPATIBILITY_SUPPORT_KEYS) {
|
|
131
|
+
if (hasEnabledNestedSupport(typography, key)) {
|
|
132
|
+
addCompatibilityFeature(features, seen, `typography.${key}`);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
const color = supports.color;
|
|
136
|
+
if (isSupportObject(color)) {
|
|
137
|
+
for (const key of COLOR_COMPATIBILITY_SUPPORT_KEYS) {
|
|
138
|
+
if (isEnabledSupportValue(color[key])) {
|
|
139
|
+
addCompatibilityFeature(features, seen, `color.${key}`);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
if (hasEnabledNestedSupport(supports.filter, "duotone")) {
|
|
144
|
+
addCompatibilityFeature(features, seen, "filter.duotone");
|
|
145
|
+
}
|
|
146
|
+
for (const key of Object.keys(supports)) {
|
|
147
|
+
if (!KNOWN_BLOCK_SUPPORT_FEATURES.has(key) &&
|
|
148
|
+
!DEFINE_SUPPORTS_INLINE_OPTION_KEYS.has(key) &&
|
|
149
|
+
isEnabledTopLevelSupportValue(supports[key])) {
|
|
150
|
+
addCompatibilityFeature(features, seen, key);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
return features;
|
|
154
|
+
}
|
|
155
|
+
function splitDefineSupportsInput(supports) {
|
|
156
|
+
const normalizedSupports = {};
|
|
157
|
+
const inlineOptions = {};
|
|
158
|
+
for (const [key, value] of Object.entries(supports)) {
|
|
159
|
+
if (DEFINE_SUPPORTS_INLINE_OPTION_KEYS.has(key)) {
|
|
160
|
+
Object.assign(inlineOptions, { [key]: value });
|
|
161
|
+
continue;
|
|
162
|
+
}
|
|
163
|
+
normalizedSupports[key] = value;
|
|
164
|
+
}
|
|
165
|
+
return {
|
|
166
|
+
inlineOptions,
|
|
167
|
+
supports: normalizedSupports,
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
function resolveDefineSupportsSettings(inlineOptions, options) {
|
|
171
|
+
const settings = {};
|
|
172
|
+
const allowUnknownFutureKeys = options.allowUnknownFutureKeys ?? inlineOptions.allowUnknownFutureKeys;
|
|
173
|
+
const minVersion = options.minVersion ??
|
|
174
|
+
options.minWordPress ??
|
|
175
|
+
inlineOptions.minVersion ??
|
|
176
|
+
inlineOptions.minWordPress;
|
|
177
|
+
const strict = options.strict ?? inlineOptions.strict;
|
|
178
|
+
if (allowUnknownFutureKeys !== undefined) {
|
|
179
|
+
Object.assign(settings, { allowUnknownFutureKeys });
|
|
180
|
+
}
|
|
181
|
+
if (minVersion !== undefined) {
|
|
182
|
+
Object.assign(settings, { minVersion });
|
|
183
|
+
}
|
|
184
|
+
if (strict !== undefined) {
|
|
185
|
+
Object.assign(settings, { strict });
|
|
186
|
+
}
|
|
187
|
+
return settings;
|
|
188
|
+
}
|
|
189
|
+
export function createBlockSupportsCompatibilityManifest(supports, settings = {}) {
|
|
190
|
+
const compatibilitySettings = resolveDefineSupportsSettings({}, settings);
|
|
191
|
+
return createWordPressBlockApiCompatibilityManifest(collectBlockSupportsCompatibilityFeatures(supports), compatibilitySettings);
|
|
192
|
+
}
|
|
193
|
+
function handleDefineSupportsDiagnostics(diagnostics, onDiagnostic) {
|
|
194
|
+
const errors = diagnostics.filter((diagnostic) => diagnostic.severity === "error");
|
|
195
|
+
if (errors.length > 0) {
|
|
196
|
+
throw new Error([
|
|
197
|
+
"WordPress block supports compatibility check failed:",
|
|
198
|
+
...errors.map((diagnostic) => `- ${diagnostic.message}`),
|
|
199
|
+
].join("\n"));
|
|
200
|
+
}
|
|
201
|
+
for (const diagnostic of diagnostics) {
|
|
202
|
+
if (onDiagnostic) {
|
|
203
|
+
onDiagnostic(diagnostic);
|
|
204
|
+
continue;
|
|
205
|
+
}
|
|
206
|
+
console.warn(`[wp-typia] ${diagnostic.message}`);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
export function getDefinedSupportsCompatibilityManifest(supports) {
|
|
210
|
+
return isSupportObject(supports)
|
|
211
|
+
? supports[DEFINED_BLOCK_SUPPORTS_METADATA]?.manifest
|
|
212
|
+
: undefined;
|
|
213
|
+
}
|
|
214
|
+
export function defineSupports(supports, options = {}) {
|
|
215
|
+
const { inlineOptions, supports: normalizedSupports } = splitDefineSupportsInput(supports);
|
|
216
|
+
const settings = resolveDefineSupportsSettings(inlineOptions, options);
|
|
217
|
+
const manifest = createBlockSupportsCompatibilityManifest(normalizedSupports, settings);
|
|
218
|
+
handleDefineSupportsDiagnostics(manifest.diagnostics, options.onDiagnostic ?? inlineOptions.onDiagnostic);
|
|
219
|
+
Object.defineProperty(normalizedSupports, DEFINED_BLOCK_SUPPORTS_METADATA, {
|
|
220
|
+
configurable: false,
|
|
221
|
+
enumerable: false,
|
|
222
|
+
value: {
|
|
223
|
+
diagnostics: manifest.diagnostics,
|
|
224
|
+
manifest,
|
|
225
|
+
},
|
|
226
|
+
writable: false,
|
|
227
|
+
});
|
|
228
|
+
return normalizedSupports;
|
|
229
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import type { BlockAttributes, BlockVariation, BlockVariationScope } from "./registration.js";
|
|
2
|
+
import { type WordPressBlockApiCompatibilityDiagnostic, type WordPressBlockApiCompatibilityFeature, type WordPressBlockApiCompatibilityManifest, type WordPressCompatibilitySettings, type WordPressVersion } from "./compatibility.js";
|
|
3
|
+
export type BlockVariationAttributeMap<TAttributes extends BlockAttributes = BlockAttributes> = Partial<TAttributes> & BlockAttributes;
|
|
4
|
+
export type BlockVariationInnerBlockTemplate = readonly [
|
|
5
|
+
name: string,
|
|
6
|
+
attributes?: Readonly<BlockAttributes>,
|
|
7
|
+
innerBlocks?: readonly BlockVariationInnerBlockTemplate[]
|
|
8
|
+
];
|
|
9
|
+
export type BlockVariationInnerBlocks = readonly BlockVariationInnerBlockTemplate[];
|
|
10
|
+
export type BlockVariationIsActive<TAttributes extends BlockAttributes = BlockAttributes> = readonly Extract<keyof TAttributes, string>[] | ((blockAttributes: Readonly<BlockVariationAttributeMap<TAttributes>>, variationAttributes: Readonly<BlockVariationAttributeMap<TAttributes>>) => boolean);
|
|
11
|
+
export interface BlockVariationDefinition<TAttributes extends BlockAttributes = BlockAttributes> extends Omit<BlockVariation<BlockVariationAttributeMap<TAttributes>>, "attributes" | "example" | "innerBlocks" | "isActive" | "scope"> {
|
|
12
|
+
readonly attributes?: BlockVariationAttributeMap<TAttributes>;
|
|
13
|
+
readonly example?: BlockVariation<BlockVariationAttributeMap<TAttributes>>["example"] | {
|
|
14
|
+
readonly attributes: BlockVariationAttributeMap<TAttributes>;
|
|
15
|
+
readonly innerBlocks?: BlockVariationInnerBlocks;
|
|
16
|
+
};
|
|
17
|
+
readonly innerBlocks?: BlockVariationInnerBlocks;
|
|
18
|
+
readonly isActive?: BlockVariationIsActive<TAttributes>;
|
|
19
|
+
readonly scope?: readonly BlockVariationScope[];
|
|
20
|
+
}
|
|
21
|
+
export interface DefineVariationInlineOptions {
|
|
22
|
+
readonly allowMissingIsActive?: boolean;
|
|
23
|
+
readonly minVersion?: WordPressVersion;
|
|
24
|
+
readonly minWordPress?: WordPressVersion;
|
|
25
|
+
readonly onDiagnostic?: (diagnostic: BlockVariationDiagnostic) => void;
|
|
26
|
+
readonly requireIsActive?: boolean;
|
|
27
|
+
readonly strict?: boolean;
|
|
28
|
+
}
|
|
29
|
+
export interface DefineVariationOptions extends WordPressCompatibilitySettings {
|
|
30
|
+
readonly allowMissingIsActive?: boolean;
|
|
31
|
+
readonly minWordPress?: WordPressVersion;
|
|
32
|
+
readonly onDiagnostic?: (diagnostic: BlockVariationDiagnostic) => void;
|
|
33
|
+
readonly requireIsActive?: boolean;
|
|
34
|
+
}
|
|
35
|
+
export type StripDefineVariationOptions<TVariation> = Omit<TVariation, keyof DefineVariationInlineOptions>;
|
|
36
|
+
export declare const DEFINED_BLOCK_VARIATION_METADATA: unique symbol;
|
|
37
|
+
export declare const DEFINED_BLOCK_VARIATIONS_METADATA: unique symbol;
|
|
38
|
+
export type DefinedBlockVariationMetadataKey = typeof DEFINED_BLOCK_VARIATION_METADATA;
|
|
39
|
+
export type DefinedBlockVariationsMetadataKey = typeof DEFINED_BLOCK_VARIATIONS_METADATA;
|
|
40
|
+
export interface DefinedBlockVariationMetadata {
|
|
41
|
+
readonly blockName: string;
|
|
42
|
+
readonly diagnostics: readonly BlockVariationDiagnostic[];
|
|
43
|
+
readonly manifest: WordPressBlockApiCompatibilityManifest;
|
|
44
|
+
}
|
|
45
|
+
export interface DefinedBlockVariationsMetadata {
|
|
46
|
+
readonly diagnostics: readonly BlockVariationDiagnostic[];
|
|
47
|
+
readonly entries: readonly BlockVariationRegistrationEntry[];
|
|
48
|
+
}
|
|
49
|
+
export type DefinedBlockVariation<TBlockName extends string = string, TAttributes extends BlockAttributes = BlockAttributes, TVariation extends BlockVariationDefinition<TAttributes> = BlockVariationDefinition<TAttributes>> = Readonly<StripDefineVariationOptions<TVariation>> & {
|
|
50
|
+
readonly [DEFINED_BLOCK_VARIATION_METADATA]?: DefinedBlockVariationMetadata;
|
|
51
|
+
readonly __wpTypiaVariationAttributes?: TAttributes;
|
|
52
|
+
readonly __wpTypiaVariationTarget?: TBlockName;
|
|
53
|
+
};
|
|
54
|
+
export type DefinedBlockVariations<TVariations extends readonly DefinedBlockVariation[] = readonly DefinedBlockVariation[]> = Readonly<TVariations> & {
|
|
55
|
+
readonly [DEFINED_BLOCK_VARIATIONS_METADATA]?: DefinedBlockVariationsMetadata;
|
|
56
|
+
};
|
|
57
|
+
export type BlockVariationDiagnosticCode = "duplicate-active-marker" | "duplicate-variation-name" | "missing-is-active" | "missing-stable-marker" | "unknown-is-active-attribute";
|
|
58
|
+
export interface BlockVariationAuthoringDiagnostic {
|
|
59
|
+
readonly attribute?: string | undefined;
|
|
60
|
+
readonly blockName: string;
|
|
61
|
+
readonly code: BlockVariationDiagnosticCode;
|
|
62
|
+
readonly message: string;
|
|
63
|
+
readonly severity: "error" | "warning";
|
|
64
|
+
readonly variationName: string;
|
|
65
|
+
}
|
|
66
|
+
export type BlockVariationDiagnostic = BlockVariationAuthoringDiagnostic | WordPressBlockApiCompatibilityDiagnostic;
|
|
67
|
+
export interface BlockVariationRegistrationEntry {
|
|
68
|
+
readonly blockName: string;
|
|
69
|
+
readonly variation: Readonly<BlockVariationDefinition>;
|
|
70
|
+
}
|
|
71
|
+
export interface CreateBlockVariationRegistrationSourceOptions {
|
|
72
|
+
readonly functionName?: string;
|
|
73
|
+
readonly importSource?: string;
|
|
74
|
+
}
|
|
75
|
+
export declare function collectBlockVariationCompatibilityFeatures(): readonly WordPressBlockApiCompatibilityFeature[];
|
|
76
|
+
export declare function createBlockVariationCompatibilityManifest(settings?: DefineVariationOptions): WordPressBlockApiCompatibilityManifest;
|
|
77
|
+
export declare function getDefinedVariationMetadata(variation: unknown): DefinedBlockVariationMetadata | undefined;
|
|
78
|
+
export declare function getDefinedVariationBlockName(variation: unknown): string | undefined;
|
|
79
|
+
export declare function getDefinedVariationCompatibilityManifest(variation: unknown): WordPressBlockApiCompatibilityManifest | undefined;
|
|
80
|
+
export declare function getDefinedVariationsMetadata(variations: unknown): DefinedBlockVariationsMetadata | undefined;
|
|
81
|
+
export declare function defineVariation<TAttributes extends BlockAttributes = BlockAttributes, const TBlockName extends string = string, const TVariation extends BlockVariationDefinition<TAttributes> & DefineVariationInlineOptions = BlockVariationDefinition<TAttributes> & DefineVariationInlineOptions>(blockName: TBlockName, variation: TVariation, options?: DefineVariationOptions): DefinedBlockVariation<TBlockName, TAttributes, TVariation>;
|
|
82
|
+
export declare function createBlockVariationRegistrationPlan(variations: readonly DefinedBlockVariation[]): readonly BlockVariationRegistrationEntry[];
|
|
83
|
+
export declare function defineVariations<const TVariations extends readonly DefinedBlockVariation[]>(variations: TVariations, options?: DefineVariationOptions): DefinedBlockVariations<TVariations>;
|
|
84
|
+
export declare function createStaticBlockVariationRegistrationSource(variations: readonly DefinedBlockVariation[], options?: CreateBlockVariationRegistrationSourceOptions): string;
|