WordPressのblock.json、Block API機能一覧と対応プロパティ(ver.3対応)2024年5月版

自身の勉強のため、データをまとめている最中の書きかけのページです。以下のBlock API リファレンスなどを参考にしています。

また、以下の日本語の解説も参考にしています。

ブロックの基本のメタデータ

block.json のプロパティを通して、ブロックの一意な識別方法や検索方法、ブロックエディターに表示されるブロックの情報を定義できます。

プロパティ必須設定値機能説明
$schemahttps://schemas.wp.org/trunk/block.jsonスキーマ定義ファイル“$schema”: “https://schemas.wp.org/trunk/block.json”
apiVersion3ブロックが使用する API のバージョン
namespace/block-name
“apiVersion”: 3
namemy-plugin/notice名前空間を含むブロックの一意な識別子“name”: “core/heading”
titleブロック名ブロックの表示タイトル“title”: “Heading”
categorytext
media
design
widgets
theme
embed
インサーターパネルでのブロックのカテゴリー“category”: “text”
parent[ “my-block/product” ]parent を設定すると、ブロックは、指定したブロック内にネストされた場合のみ利用可能になります。たとえば、「カートに追加」ブロックを、「商品」ブロック内でのみ利用可能にすることができます。要するに、小ブロックに設定する。“parent”: [ “my-block/product” ]
ancestor[ “my-block/product” ]ancestor プロパティは、指定されたブロックタイプの中で、祖先ブロックサブツリーの任意の位置において、ブロックを利用可能にします。例えば、Column ブロックが Comment Template ブロック内のどこかにいる限り、Comment Content ブロックを Column ブロックの中に配置できます。parent プロパティと比較すると、 ancestor を指定したブロックはサブツリーのどこにでも配置できますが、 parent を指定したブロックは直接の子である必要があります。要するに、親戚同士でブロックを固める際に利用。“ancestor”: [ “my-block/product” ]
allowedBlocks[ “my-block/product” ]小ブロックとして使用できるブロックを指定。“allowedBlocks”: [ “my-block/product” ]
icontext,links
など(詳しくはリンクより。SVGで指定も可能)
Dashiconスラッグまたはカスタム SVG アイコン
https://developer.wordpress.org/resource/dashicons/#align-wide
“icon”: “smile”
descriptionブロックの簡易解説ブロックインスペクタに表示される短い説明“description”: “Introduce new sections and organize content to help visitors”
}
keywords[ “alert”, “message” ] などブロックをインサータで検索する際に使用“keywords”: [ “keyword1”, “keyword2” ]
textdomain作者のユニークな文字列を入れる?プラグインのテキストドメイン (翻訳などで重要)“textdomain”: “my-plugin”
version1.0.3 などプラグインの開発バージョン“version”: “1.0.3”

supports によるブロックの UI 設定パネルの有効化

コアブロックを含む多くのブロックは、同種のカスタマイズオプションを提供します。例えば、背景色の変更、テキスト色の変更、パディングのカスタマイズオプションの追加など。

block.json の supports プロパティは、ブロックの特定機能のサポートを宣言します。ユーザーは設定サイドバーから特定の設定 (色やマージンなど) をカスタマイズできます。

利用可能なブロック supports を使用することで、ブロックの動作をコアブロックに合わせられ、同じ機能を自分で繰り返さずにすみます。

supports: {
    anchor: true,
    align: true
}
プロパティ設定値初期値画像機能説明
anchortrue
false
false“anchor”: true
aligntrue
false
[ “left”, “center”, “right”, “wide”, “full” ]
false“align”: true
“align”: [ “left”, “right”, “full” ]
alignWidetrue
false
true“alignWide”: false
ariaLabeltrue
false
false“ariaLabel”: true
classNametrue
false
true“className”: false
customClassNametrue
false
true“customClassName”: false
htmltrue
false
true“html”: false
insertertrue
false
true“inserter”: false
locktrue
false
true“lock”: false
multipletrue
false
true“multiple”: false
renamingtrue
false
true“renaming”: false
reusabletrue
false
true“reusable”: false
shadowtrue
false
false
“shadow”: true
backgroundnull
background.backgroundImagetrue
false
false“background”: {
“backgroundImage”: true
}
background.backgroundSizetrue
false
false“background”: {
“backgroundSize”: true
}
colortrue
false
null
color.backgroundtrue
false
true
color.buttontrue
false
false
color.enableContrastCheckertrue
false
true
color.gradientstrue
false
false
color.headingtrue
false
false
color.linktrue
false
false
color.texttrue
false
true
dimensionsnull
dimensions.aspectRatiotrue
false
false
dimensions.minHeighttrue
false
false
filter
filter.duotonetrue
false
false“filter”: {
“duotone”: true
}
interactivity
interactivity.clientNavigationtrue
false
false
interactivity.interactivetrue
false
false
layout
layout.allowEditingtrue
false
true
layout.allowSwitchingtrue
false
false
layout.allowInheritingtrue
false
true
layout.allowSizingOnChildrentrue
false
false
layout.allowVerticalAlignmenttrue
false
true
layout.allowJustificationtrue
false
true
layout.allowOrientationtrue
false
true
layout.allowCustomContentAndWideSizetrue
false
true
layout.defaultnull
positionnull
position.stickytrue
false
false
spacingnull
spacing.margintrue
false
[ “top”, “right”, “bottom”, “left” ]
false
“spacing”: {“margin”: true}
“spacing”: {“margin”:[ “left”, “right” ]}
spacing.paddingtrue
false
[ “top”, “right”, “bottom”, “left” ]
false“spacing”: {“padding”: true}
“spacing”: {“padding”:[ “left”, “right” ]}
spacing.blockGaptrue
false
[ “horizontal”, “vertical” ]
false
typographynull
typography.fontSizetrue
false
false“typography”: {
“fontSize”: true
}
typography.lineHeighttrue
false
false“typography”: {
“lineHeight”: true
}
typography.textAligntrue
false
[ ‘left’, ‘center’, ‘right’ ]
false“typography”: {
“textAlign”: true
}
stylenull



Comments

“WordPressのblock.json、Block API機能一覧と対応プロパティ(ver.3対応)2024年5月版” への1件のコメント

  1. […] block.jsonの役割は、以下のようなものとなります。詳しくは、こちらのページを参考にしてください。 […]

Wordpressブロック開発の始め方 2024年5月版 – PICOT へ返信する コメントをキャンセル

メールアドレスが公開されることはありません。 が付いている欄は必須項目です