Skip to content

🩹 fix: Add support for legacy blocks #336

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 25 additions & 15 deletions src/Block.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,15 @@ abstract class Block extends Composer implements BlockContract
'margin' => null,
];

/**
* The default block typography.
*
* @var array
*/
public $typography = [
'textAlign' => null,
];

/**
* The supported block features.
*
Expand Down Expand Up @@ -397,18 +406,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();
}

Expand All @@ -433,18 +430,27 @@ public function getSupportAttributes(): array
];
}

$styles = [];

if ($this->align_text) {
$styles['typography']['textAlign'] = $this->align_text;
$attributes['alignText'] = [
'type' => 'string',
'default' => $this->align_text,
];
}

$styles = [];

$spacing = array_filter($this->spacing);

if ($spacing) {
$styles['spacing'] = $spacing;
}

$typography = array_filter($this->typography);

if ($typography) {
$styles['typography'] = $typography;
}

if ($styles) {
$attributes['style'] = [
'type' => 'object',
Expand Down Expand Up @@ -490,6 +496,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";
}
Expand Down
2 changes: 1 addition & 1 deletion src/Console/BlockMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ class BlockMakeCommand extends MakeCommand
*/
protected array $supports = [
'align',
'align_text',
'align_content',
'full_height',
'anchor',
Expand All @@ -54,6 +53,7 @@ class BlockMakeCommand extends MakeCommand
'jsx',
'color' => ['background', 'text', 'gradients'],
'spacing' => ['padding', 'margin'],
'typography' => ['textAlign'],
];

/**
Expand Down
22 changes: 17 additions & 5 deletions src/Console/stubs/block.localized.stub
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
16 changes: 9 additions & 7 deletions src/Console/stubs/block.stub
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -101,6 +94,15 @@ class DummyClass extends Block
'margin' => null,
];

/**
* The default block typography.
*
* @var array
*/
public $typography = [
'textAlign' => null,
];

/**
* The supported block features.
*
Expand Down