diff --git a/CHANGELOG.md b/CHANGELOG.md index 7c715df..aaf8ec1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ ## [Unreleased] +## [v1.25.1] - 2024-05-13 +### Added +* add drag&drop in the block builder + ## [v1.25.0] - 2024-05-12 ### Added * add block builder widget diff --git a/src/core/BuilderBlock/Block/Bootstrap/AlertBlock.php b/src/core/BuilderBlock/Block/Bootstrap/AlertBlock.php new file mode 100644 index 0000000..acd3ab6 --- /dev/null +++ b/src/core/BuilderBlock/Block/Bootstrap/AlertBlock.php @@ -0,0 +1,47 @@ + 'primary', + 'Secondary' => 'secondary', + 'Info' => 'info', + 'Success' => 'success', + 'Danger' => 'danger', + 'Warning' => 'warning', + 'Light' => 'light', + 'Dark' => 'dark', + ] as $k => $v) { + $options[] = [ + 'text' => $this->translator->trans($k), + 'value' => $v, + ]; + } + + $this + ->setName('bsAlert') + ->setLabel('Alert') + ->setOrder(4) + ->setIsContainer(true) + ->setIcon('') + ->setTemplate('@Core/builder_block/bootstrap/alert.html.twig') + ->addSetting(name: 'level', label: 'Level', type: 'select', extraOptions: ['options' => $options]) + ; + } +} diff --git a/src/core/BuilderBlock/Block/Bootstrap/ColumnBuilderBlock.php b/src/core/BuilderBlock/Block/Bootstrap/ColumnBlock.php similarity index 90% rename from src/core/BuilderBlock/Block/Bootstrap/ColumnBuilderBlock.php rename to src/core/BuilderBlock/Block/Bootstrap/ColumnBlock.php index 5e2d961..b17c101 100644 --- a/src/core/BuilderBlock/Block/Bootstrap/ColumnBuilderBlock.php +++ b/src/core/BuilderBlock/Block/Bootstrap/ColumnBlock.php @@ -6,7 +6,7 @@ use App\Core\BuilderBlock\BuilderBlock; use Symfony\Component\DependencyInjection\Attribute\AutoconfigureTag; #[AutoconfigureTag('builder_block.widget')] -class ColumnBuilderBlock extends BootstrapBlock +class ColumnBlock extends BootstrapBlock { public function configure() { @@ -16,7 +16,8 @@ class ColumnBuilderBlock extends BootstrapBlock ->setName('bsColumn') ->setLabel('Column') ->setIsContainer(true) - ->setClass('col-12 col-md-2 pr-md-1') + ->setOrder(3) + ->setClass('col-12 col-lg-2 pr-md-1') ->setTemplate('@Core/builder_block/bootstrap/column.html.twig') ->setIcon('') ->addSetting(name: 'size', label: 'Extra small', type: 'number', attributes: ['min' => 0, 'max' => 12]) diff --git a/src/core/BuilderBlock/Block/Bootstrap/ContainerBuilderBlock.php b/src/core/BuilderBlock/Block/Bootstrap/ContainerBlock.php similarity index 89% rename from src/core/BuilderBlock/Block/Bootstrap/ContainerBuilderBlock.php rename to src/core/BuilderBlock/Block/Bootstrap/ContainerBlock.php index d8aed25..ff40827 100644 --- a/src/core/BuilderBlock/Block/Bootstrap/ContainerBuilderBlock.php +++ b/src/core/BuilderBlock/Block/Bootstrap/ContainerBlock.php @@ -6,7 +6,7 @@ use App\Core\BuilderBlock\BuilderBlock; use Symfony\Component\DependencyInjection\Attribute\AutoconfigureTag; #[AutoconfigureTag('builder_block.widget')] -class ContainerBuilderBlock extends BootstrapBlock +class ContainerBlock extends BootstrapBlock { public function configure() { @@ -16,6 +16,7 @@ class ContainerBuilderBlock extends BootstrapBlock ->setName('bsContainer') ->setLabel('Container') ->setIsContainer(true) + ->setOrder(1) ->setTemplate('@Core/builder_block/bootstrap/container.html.twig') ->setIcon('') ->addSetting(name: 'isFluid', label: 'Fluid', type: 'checkbox') diff --git a/src/core/BuilderBlock/Block/Bootstrap/RowBuilderBlock.php b/src/core/BuilderBlock/Block/Bootstrap/RowBlock.php similarity index 90% rename from src/core/BuilderBlock/Block/Bootstrap/RowBuilderBlock.php rename to src/core/BuilderBlock/Block/Bootstrap/RowBlock.php index 0391db5..3eb5edf 100644 --- a/src/core/BuilderBlock/Block/Bootstrap/RowBuilderBlock.php +++ b/src/core/BuilderBlock/Block/Bootstrap/RowBlock.php @@ -6,7 +6,7 @@ use App\Core\BuilderBlock\BuilderBlock; use Symfony\Component\DependencyInjection\Attribute\AutoconfigureTag; #[AutoconfigureTag('builder_block.widget')] -class RowBuilderBlock extends BootstrapBlock +class RowBlock extends BootstrapBlock { public function configure() { @@ -15,6 +15,7 @@ class RowBuilderBlock extends BootstrapBlock $this ->setName('bsRow') ->setLabel('Row') + ->setOrder(2) ->setIsContainer(true) ->setIcon('') ->setTemplate('@Core/builder_block/bootstrap/row.html.twig') diff --git a/src/core/BuilderBlock/Block/Editor/TextareaBlock.php b/src/core/BuilderBlock/Block/Editor/TextareaBlock.php new file mode 100644 index 0000000..b216eb5 --- /dev/null +++ b/src/core/BuilderBlock/Block/Editor/TextareaBlock.php @@ -0,0 +1,26 @@ +setName('textarea') + ->setLabel('Text') + ->setIsContainer(false) + ->setIcon('') + ->setTemplate('@Core/builder_block/editor/textarea.html.twig') + ->addSetting(name: 'nl2br', label: 'Insert line breaks', type: 'checkbox', default: true) + ->addSetting(name: 'allowHtml', label: 'Allow HTML', type: 'checkbox', default: false) + ->addSetting(name: 'value', type: 'textarea') + ; + } +} diff --git a/src/core/BuilderBlock/BuilderBlock.php b/src/core/BuilderBlock/BuilderBlock.php index 7baf0e3..d323cf2 100644 --- a/src/core/BuilderBlock/BuilderBlock.php +++ b/src/core/BuilderBlock/BuilderBlock.php @@ -14,6 +14,7 @@ abstract class BuilderBlock protected string $template = ''; protected bool $isContainer = false; protected ?string $icon = null; + protected int $order = 1; abstract public function configure(); @@ -109,7 +110,7 @@ abstract class BuilderBlock ]; foreach ($extraOptions as $key => $value) { - if (in_array($key, array_keys($this->settings[$name]))) { + if (!in_array($key, array_keys($this->settings[$name]))) { $this->settings[$name][$key] = $value; } } @@ -171,6 +172,18 @@ abstract class BuilderBlock return $this->icon; } + public function setOrder(int $order): self + { + $this->order = $order; + + return $this; + } + + public function getOrder(): int + { + return $this->order; + } + public function buildVars(array $data) { } diff --git a/src/core/BuilderBlock/BuilderBlockContainer.php b/src/core/BuilderBlock/BuilderBlockContainer.php index 980c8f3..0a2e4ff 100644 --- a/src/core/BuilderBlock/BuilderBlockContainer.php +++ b/src/core/BuilderBlock/BuilderBlockContainer.php @@ -15,6 +15,8 @@ class BuilderBlockContainer public function getWidgets(): array { + usort($this->widgets, fn(BuilderBlock $a, BuilderBlock $b) => $a->getOrder() <=> $b->getOrder()); + return $this->widgets; } diff --git a/src/core/Murph.php b/src/core/Murph.php index 07a1b39..2c46c1e 100644 --- a/src/core/Murph.php +++ b/src/core/Murph.php @@ -3,7 +3,7 @@ namespace App\Core; if (!defined('MURPH_VERSION')) { - define('MURPH_VERSION', 'v1.25.0'); + define('MURPH_VERSION', 'v1.25.1'); } /** diff --git a/src/core/Resources/assets/css/admin.scss b/src/core/Resources/assets/css/admin.scss index 9c091c9..c1e0729 100644 --- a/src/core/Resources/assets/css/admin.scss +++ b/src/core/Resources/assets/css/admin.scss @@ -799,10 +799,17 @@ label.required::after { .block-settings { padding: 4px; + margin-bottom: 5px; } .block-id { font-size: 12px; margin-right: 5px; } + + .block-show-dropzone { + .block-dropzone { + min-height: 40px; + } + } } diff --git a/src/core/Resources/assets/js/components/builder-block/BuilderBlock.vue b/src/core/Resources/assets/js/components/builder-block/BuilderBlock.vue index fd0229f..f80f969 100644 --- a/src/core/Resources/assets/js/components/builder-block/BuilderBlock.vue +++ b/src/core/Resources/assets/js/components/builder-block/BuilderBlock.vue @@ -1,15 +1,25 @@ + + diff --git a/src/core/Resources/translations/messages.fr.yaml b/src/core/Resources/translations/messages.fr.yaml index 0021fb2..efbbfe8 100644 --- a/src/core/Resources/translations/messages.fr.yaml +++ b/src/core/Resources/translations/messages.fr.yaml @@ -229,3 +229,6 @@ "Medium": "Moyen" "Large": "Large" "Extra large": "Très large" +"Level": "Niveau" +"Insert line breaks": "Ajouter les retours chariot" +'Allow HTML': "Autoriser l'HTML" diff --git a/src/core/Resources/views/builder_block/bootstrap/alert.html.twig b/src/core/Resources/views/builder_block/bootstrap/alert.html.twig new file mode 100644 index 0000000..819d0f1 --- /dev/null +++ b/src/core/Resources/views/builder_block/bootstrap/alert.html.twig @@ -0,0 +1,5 @@ +
+ {% for item in children %} + {{ item|block_to_html }} + {% endfor %} +
diff --git a/src/core/Resources/views/builder_block/editor/textarea.html.twig b/src/core/Resources/views/builder_block/editor/textarea.html.twig new file mode 100644 index 0000000..0e6b482 --- /dev/null +++ b/src/core/Resources/views/builder_block/editor/textarea.html.twig @@ -0,0 +1,13 @@ +{%- if settings.nl2br|default(null) -%} + {% if settings.allowHtml|default(null) %} + {{- settings.value|default(null)|raw|nl2br -}} + {%- else -%} + {{- settings.value|default(null)|nl2br -}} + {%- endif -%} +{%- else -%} + {% if settings.allowHtml|default(null) %} + {{- settings.value|default(null)|raw -}} + {%- else -%} + {{- settings.value|default(null) -}} + {%- endif -%} +{% endif %}