From 5cc8b213190bbc82c563a05a189a128a5b8d1ec5 Mon Sep 17 00:00:00 2001 From: Tom Broucke Date: Sun, 6 Apr 2025 14:20:14 +0200 Subject: [PATCH 1/5] =?UTF-8?q?=F0=9F=A9=B9=20fix:=20Add=20support=20for?= =?UTF-8?q?=20legacy=20blocks?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Don't move `supports['align_text']` to `supports['typography']['textAlign']` and re-add `align-text-*` class to legacy blocks. New blocks now have text alignment in `supports['typography']['textAlign']`. --- src/Block.php | 20 ++++---------------- src/Console/BlockMakeCommand.php | 2 +- 2 files changed, 5 insertions(+), 17 deletions(-) diff --git a/src/Block.php b/src/Block.php index 566cac0d..b7941396 100644 --- a/src/Block.php +++ b/src/Block.php @@ -397,18 +397,6 @@ public function getSupports(): array ->mapWithKeys(fn ($value, $key) => [Str::camel($key) => $value]) ->merge($this->supports); - $typography = $supports->get('typography', []); - - if ($supports->has('alignText')) { - $typography['textAlign'] = $supports->get('alignText'); - - $supports->forget(['alignText', 'align_text']); - } - - if ($typography) { - $supports->put('typography', $typography); - } - return $supports->all(); } @@ -435,10 +423,6 @@ public function getSupportAttributes(): array $styles = []; - if ($this->align_text) { - $styles['typography']['textAlign'] = $this->align_text; - } - $spacing = array_filter($this->spacing); if ($spacing) { @@ -490,6 +474,10 @@ public function getClasses(): string $class = "{$class} is-position-{$alignContent}"; } + if ($alignText = $this->block->alignText ?? $this->block->align_text ?? null) { + $class = "{$class} align-text-{$alignText}"; + } + if ($this->block->fullHeight ?? $this->block->full_height ?? null) { $class = "{$class} full-height"; } diff --git a/src/Console/BlockMakeCommand.php b/src/Console/BlockMakeCommand.php index 1d3e2270..d6767e06 100644 --- a/src/Console/BlockMakeCommand.php +++ b/src/Console/BlockMakeCommand.php @@ -45,7 +45,6 @@ class BlockMakeCommand extends MakeCommand */ protected array $supports = [ 'align', - 'align_text', 'align_content', 'full_height', 'anchor', @@ -54,6 +53,7 @@ class BlockMakeCommand extends MakeCommand 'jsx', 'color' => ['background', 'text', 'gradients'], 'spacing' => ['padding', 'margin'], + 'typography' => ['textAlign'], ]; /** From 00c32c269069ba80658b6fdab5be45b36644c7a3 Mon Sep 17 00:00:00 2001 From: Tom Broucke Date: Mon, 7 Apr 2025 09:44:35 +0200 Subject: [PATCH 2/5] =?UTF-8?q?=F0=9F=A9=B9=20fix:=20Default=20alignment?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixed default alignment for both blocks with `align_text` and `typography['textAlign']` --- src/Block.php | 22 ++++++++++++++++++++++ src/Console/stubs/block.stub | 16 +++++++++------- 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/src/Block.php b/src/Block.php index b7941396..74b0bded 100644 --- a/src/Block.php +++ b/src/Block.php @@ -207,6 +207,15 @@ abstract class Block extends Composer implements BlockContract 'margin' => null, ]; + /** + * The default block typography. + * + * @var array + */ + public $typography = [ + 'textAlign' => 'center', + ]; + /** * The supported block features. * @@ -421,6 +430,13 @@ public function getSupportAttributes(): array ]; } + if ($this->align_text) { + $attributes['alignText'] = [ + 'type' => 'string', + 'default' => $this->align_text, + ]; + } + $styles = []; $spacing = array_filter($this->spacing); @@ -429,6 +445,12 @@ public function getSupportAttributes(): array $styles['spacing'] = $spacing; } + $typography = array_filter($this->typography); + + if ($typography) { + $styles['typography'] = $typography; + } + if ($styles) { $attributes['style'] = [ 'type' => 'object', diff --git a/src/Console/stubs/block.stub b/src/Console/stubs/block.stub index efbf125b..7627aa3a 100644 --- a/src/Console/stubs/block.stub +++ b/src/Console/stubs/block.stub @@ -77,13 +77,6 @@ class DummyClass extends Block */ public $align = ''; - /** - * The default block text alignment. - * - * @var string - */ - public $align_text = ''; - /** * The default block content alignment. * @@ -101,6 +94,15 @@ class DummyClass extends Block 'margin' => null, ]; + /** + * The default block typography. + * + * @var array + */ + public $typography = [ + 'textAlign' => 'center', + ]; + /** * The supported block features. * From 1d1c74e888459301841dc72b024d52d5383ad1f3 Mon Sep 17 00:00:00 2001 From: Tom Broucke Date: Mon, 7 Apr 2025 09:45:02 +0200 Subject: [PATCH 3/5] =?UTF-8?q?=F0=9F=A9=B9=20fix:=20Remove=20default=20al?= =?UTF-8?q?ignment?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Block.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Block.php b/src/Block.php index 74b0bded..dab52edc 100644 --- a/src/Block.php +++ b/src/Block.php @@ -213,7 +213,7 @@ abstract class Block extends Composer implements BlockContract * @var array */ public $typography = [ - 'textAlign' => 'center', + 'textAlign' => null, ]; /** From 5f0b10bb62832051386a6e51da092b2be7357c4a Mon Sep 17 00:00:00 2001 From: Tom Broucke Date: Mon, 7 Apr 2025 10:00:51 +0200 Subject: [PATCH 4/5] =?UTF-8?q?=F0=9F=A9=B9=20fix:=20Set=20default=20text?= =?UTF-8?q?=20alignment=20to=20null?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Console/stubs/block.stub | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Console/stubs/block.stub b/src/Console/stubs/block.stub index 7627aa3a..24775ab3 100644 --- a/src/Console/stubs/block.stub +++ b/src/Console/stubs/block.stub @@ -100,7 +100,7 @@ class DummyClass extends Block * @var array */ public $typography = [ - 'textAlign' => 'center', + 'textAlign' => null, ]; /** From 9af9fc7e96e49f87e57699df5f61f5eb533562b7 Mon Sep 17 00:00:00 2001 From: Tom Broucke Date: Mon, 7 Apr 2025 10:24:10 +0200 Subject: [PATCH 5/5] =?UTF-8?q?=E2=9C=A8=20feat:=20Synchronise=20propertie?= =?UTF-8?q?s=20with=20block=20stub?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Console/stubs/block.localized.stub | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/Console/stubs/block.localized.stub b/src/Console/stubs/block.localized.stub index 6cf48b07..4b0faf05 100644 --- a/src/Console/stubs/block.localized.stub +++ b/src/Console/stubs/block.localized.stub @@ -71,18 +71,30 @@ class DummyClass extends Block public $align = ''; /** - * The default block text alignment. + * The default block content alignment. * * @var string */ - public $align_text = ''; + public $align_content = ''; /** - * The default block content alignment. + * The default block spacing. * - * @var string + * @var array */ - public $align_content = ''; + public $spacing = [ + 'padding' => null, + 'margin' => null, + ]; + + /** + * The default block typography. + * + * @var array + */ + public $typography = [ + 'textAlign' => null, + ]; /** * The supported block features.