Compare commits
72 commits
Author | SHA1 | Date | |
---|---|---|---|
Simon Vieille | eb376dc36c | ||
Simon Vieille | 8e947b0b77 | ||
Simon Vieille | fd1a45c0e7 | ||
Simon Vieille | bc148f0b6b | ||
Simon Vieille | 4a3619919c | ||
Simon Vieille | 4054f6ccff | ||
Simon Vieille | 01ecac272e | ||
Simon Vieille | 89efd5475f | ||
Simon Vieille | 029d296bd8 | ||
Simon Vieille | 1120c20f05 | ||
Simon Vieille | f4a70bec66 | ||
Simon Vieille | d4ba8dc619 | ||
Simon Vieille | 26e422619b | ||
Simon Vieille | eb3c1a8879 | ||
Simon Vieille | 9963c4b3cf | ||
Simon Vieille | e322973e67 | ||
Simon Vieille | a15cf1559b | ||
Simon Vieille | 006b8cdbe6 | ||
Simon Vieille | 46f13d817d | ||
Simon Vieille | 0d5f248ca9 | ||
Simon Vieille | d1ca98eddd | ||
Simon Vieille | 62fbd936c6 | ||
Simon Vieille | d66fb7da78 | ||
Simon Vieille | 57dd7da162 | ||
Simon Vieille | d7ce3cb12f | ||
Simon Vieille | fea5319dc5 | ||
Simon Vieille | ff0ab092e4 | ||
Simon Vieille | a0211026ba | ||
Simon Vieille | c5dde3b184 | ||
Simon Vieille | b1ea641374 | ||
Simon Vieille | 62de6416c5 | ||
Simon Vieille | 246c249d3e | ||
Simon Vieille | be26d15b22 | ||
Simon Vieille | 3f5bd4f950 | ||
Simon Vieille | a80dc9999c | ||
Simon Vieille | b9566853ef | ||
Simon Vieille | bc7e8ef263 | ||
Simon Vieille | 25efd11ea3 | ||
Simon Vieille | e23f7d3c73 | ||
Simon Vieille | 85f054956c | ||
Simon Vieille | b12f4db16f | ||
Simon Vieille | 6bb29dd5c3 | ||
Simon Vieille | 7824e96bab | ||
Simon Vieille | 56177c14da | ||
Simon Vieille | 4f1c5b8f14 | ||
Simon Vieille | e8c9520378 | ||
Simon Vieille | 283223446a | ||
Simon Vieille | 46e01f504f | ||
Simon Vieille | a80ee03fcd | ||
Simon Vieille | d1649a4959 | ||
Simon Vieille | 38791f1d7a | ||
Simon Vieille | d74cd52711 | ||
Simon Vieille | b451df61e8 | ||
Simon Vieille | 7c124008c0 | ||
Simon Vieille | 9cf95dba64 | ||
Simon Vieille | b680946daf | ||
Simon Vieille | 1995298977 | ||
Simon Vieille | 4acba618cb | ||
Simon Vieille | 92eaaba699 | ||
Simon Vieille | 357856f8ce | ||
Simon Vieille | dfbe282d0e | ||
Simon Vieille | 857fcd9897 | ||
Simon Vieille | 48ca5a96e6 | ||
Simon Vieille | 065bb0db22 | ||
Simon Vieille | bf6777054f | ||
Simon Vieille | 51acd82432 | ||
Simon Vieille | c6cbc405e4 | ||
Simon Vieille | 150f3afd6a | ||
Simon Vieille | 4a0e616897 | ||
Simon Vieille | 4eb13a4022 | ||
Simon Vieille | 8bb6267a77 | ||
Simon Vieille | 8044ff3605 |
|
@ -1,6 +1,10 @@
|
|||
## [Unreleased]
|
||||
|
||||
# [v1.25.0] - 2024-05-12
|
||||
## [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
|
||||
* allow to use `window.tinymceModes` to add or override tinymce modes
|
||||
|
|
47
src/core/BuilderBlock/Block/Bootstrap/AlertBlock.php
Normal file
47
src/core/BuilderBlock/Block/Bootstrap/AlertBlock.php
Normal file
|
@ -0,0 +1,47 @@
|
|||
<?php
|
||||
|
||||
namespace App\Core\BuilderBlock\Block\Bootstrap;
|
||||
|
||||
use Symfony\Component\DependencyInjection\Attribute\AutoconfigureTag;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
|
||||
#[AutoconfigureTag('builder_block.widget')]
|
||||
class AlertBlock extends BootstrapBlock
|
||||
{
|
||||
public function __construct(protected TranslatorInterface $translator)
|
||||
{
|
||||
}
|
||||
|
||||
public function configure()
|
||||
{
|
||||
parent::configure();
|
||||
|
||||
$options = [];
|
||||
|
||||
foreach ([
|
||||
'Primary' => '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('<i class="fas fa-exclamation-circle"></i>')
|
||||
->setTemplate('@Core/builder_block/bootstrap/alert.html.twig')
|
||||
->addSetting(name: 'level', label: 'Level', type: 'select', extraOptions: ['options' => $options])
|
||||
;
|
||||
}
|
||||
}
|
|
@ -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-3 pr-md-1')
|
||||
->setTemplate('@Core/builder_block/bootstrap/column.html.twig')
|
||||
->setIcon('<i class="fas fa-columns"></i>')
|
||||
->addSetting(name: 'size', label: 'Extra small', type: 'number', attributes: ['min' => 0, 'max' => 12])
|
||||
|
@ -24,6 +25,7 @@ class ColumnBuilderBlock extends BootstrapBlock
|
|||
->addSetting(name: 'sizeMd', label: 'Medium', type: 'number', attributes: ['min' => 0, 'max' => 12])
|
||||
->addSetting(name: 'sizeLg', label: 'Large', type: 'number', attributes: ['min' => 0, 'max' => 12])
|
||||
->addSetting(name: 'sizeXl', label: 'Extra large', type: 'number', attributes: ['min' => 0, 'max' => 12])
|
||||
->addSetting(name: 'customClass', label: 'Custom class', type: 'text')
|
||||
;
|
||||
}
|
||||
}
|
|
@ -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,9 +16,11 @@ class ContainerBuilderBlock extends BootstrapBlock
|
|||
->setName('bsContainer')
|
||||
->setLabel('Container')
|
||||
->setIsContainer(true)
|
||||
->setOrder(1)
|
||||
->setTemplate('@Core/builder_block/bootstrap/container.html.twig')
|
||||
->setIcon('<i class="fas fa-th"></i>')
|
||||
->addSetting(name: 'isFluid', label: 'Fluid', type: 'checkbox')
|
||||
->addSetting(name: 'customClass', label: 'Custom class', type: 'text')
|
||||
;
|
||||
}
|
||||
}
|
|
@ -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,10 +15,12 @@ class RowBuilderBlock extends BootstrapBlock
|
|||
$this
|
||||
->setName('bsRow')
|
||||
->setLabel('Row')
|
||||
->setOrder(2)
|
||||
->setIsContainer(true)
|
||||
->setIcon('<i class="fas fa-align-justify"></i>')
|
||||
->setTemplate('@Core/builder_block/bootstrap/row.html.twig')
|
||||
->addWidget('bsColumn')
|
||||
->addSetting(name: 'customClass', label: 'Custom class', type: 'text')
|
||||
;
|
||||
}
|
||||
}
|
|
@ -9,6 +9,6 @@ class EditorBlock extends BuilderBlock
|
|||
{
|
||||
public function configure()
|
||||
{
|
||||
$this->setCategory('Editor');
|
||||
$this->setCategory('Editors');
|
||||
}
|
||||
}
|
||||
|
|
27
src/core/BuilderBlock/Block/Editor/TextareaBlock.php
Normal file
27
src/core/BuilderBlock/Block/Editor/TextareaBlock.php
Normal file
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
|
||||
namespace App\Core\BuilderBlock\Block\Editor;
|
||||
|
||||
use App\Core\BuilderBlock\BuilderBlock;
|
||||
use Symfony\Component\DependencyInjection\Attribute\AutoconfigureTag;
|
||||
|
||||
#[AutoconfigureTag('builder_block.widget')]
|
||||
class TextareaBlock extends EditorBlock
|
||||
{
|
||||
public function configure()
|
||||
{
|
||||
parent::configure();
|
||||
|
||||
$this
|
||||
->setName('textarea')
|
||||
->setLabel('Text')
|
||||
->setIsContainer(false)
|
||||
->setIcon('<i class="fas fa-pencil-alt"></i>')
|
||||
->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')
|
||||
->setPreview('value')
|
||||
;
|
||||
}
|
||||
}
|
|
@ -19,6 +19,7 @@ class TinymceBlock extends EditorBlock
|
|||
->setIcon('<i class="fas fa-pencil-alt"></i>')
|
||||
->setTemplate('@Core/builder_block/editor/tinymce.html.twig')
|
||||
->addSetting(name: 'value', type: 'textarea', attributes: ['data-tinymce' => ''])
|
||||
->setPreview('value')
|
||||
;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,13 +6,16 @@ abstract class BuilderBlock
|
|||
{
|
||||
protected string $name;
|
||||
protected string $label;
|
||||
protected ?string $class = null;
|
||||
protected ?string $class = 'col-12';
|
||||
protected ?string $category = null;
|
||||
protected array $settings = [];
|
||||
protected array $widgets = [];
|
||||
protected array $vars = [];
|
||||
protected string $template = '';
|
||||
protected ?string $preview = null;
|
||||
protected bool $isContainer = false;
|
||||
protected ?string $icon = null;
|
||||
protected int $order = 1;
|
||||
|
||||
abstract public function configure();
|
||||
|
||||
|
@ -108,7 +111,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;
|
||||
}
|
||||
}
|
||||
|
@ -133,19 +136,6 @@ abstract class BuilderBlock
|
|||
return $this->template;
|
||||
}
|
||||
|
||||
public function toArray(): array
|
||||
{
|
||||
return [
|
||||
'label' => $this->getLabel(),
|
||||
'category' => $this->getCategory(),
|
||||
'isContainer' => $this->getIsContainer(),
|
||||
'widgets' => $this->getWidgets(),
|
||||
'settings' => $this->getSettings(),
|
||||
'class' => $this->getClass(),
|
||||
'icon' => $this->getIcon(),
|
||||
];
|
||||
}
|
||||
|
||||
public function setClass(?string $class): self
|
||||
{
|
||||
$this->class = $class;
|
||||
|
@ -169,4 +159,51 @@ 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 setPreview(?string $preview): self
|
||||
{
|
||||
$this->preview = $preview;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getPreview(): ?string
|
||||
{
|
||||
return $this->preview;
|
||||
}
|
||||
|
||||
public function buildVars(array $data, array $context)
|
||||
{
|
||||
}
|
||||
|
||||
public function getVars(): array
|
||||
{
|
||||
return $this->vars;
|
||||
}
|
||||
|
||||
public function toArray(): array
|
||||
{
|
||||
return [
|
||||
'label' => $this->getLabel(),
|
||||
'category' => $this->getCategory(),
|
||||
'isContainer' => $this->getIsContainer(),
|
||||
'widgets' => $this->getWidgets(),
|
||||
'settings' => $this->getSettings(),
|
||||
'class' => $this->getClass(),
|
||||
'icon' => $this->getIcon(),
|
||||
'preview' => $this->getPreview(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,18 +6,34 @@ class BuilderBlockContainer
|
|||
{
|
||||
protected array $widgets = [];
|
||||
|
||||
public function addWidget(BuilderBlock $widget): void
|
||||
public function addWidget(BuilderBlock $widget): self
|
||||
{
|
||||
$widget->configure();
|
||||
|
||||
$this->widgets[$widget->getName()] = $widget;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removeWidget(string $name)
|
||||
{
|
||||
unset($this->widgets[$name]);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getWidgets(): array
|
||||
{
|
||||
usort($this->widgets, fn(BuilderBlock $a, BuilderBlock $b) => $a->getOrder() <=> $b->getOrder());
|
||||
|
||||
return $this->widgets;
|
||||
}
|
||||
|
||||
public function hasWidget(string $name)
|
||||
{
|
||||
return isset($this->widgets[$name]);
|
||||
}
|
||||
|
||||
public function getWidget(string $name): BuilderBlock
|
||||
{
|
||||
return $this->widgets[$name];
|
||||
|
|
|
@ -30,6 +30,7 @@ class BuilderBlockController extends AbstractController
|
|||
protected function translate(array $data)
|
||||
{
|
||||
$data['label'] = $this->translator->trans($data['label']);
|
||||
$data['category'] = $this->translator->trans($data['category']);
|
||||
|
||||
foreach ($data['settings'] as $key => $value) {
|
||||
$data['settings'][$key]['label'] = $this->translator->trans($data['settings'][$key]['label']);
|
||||
|
|
|
@ -27,8 +27,6 @@ class BuilderType extends AbstractType
|
|||
parent::configureOptions($resolver);
|
||||
|
||||
$resolver->setDefaults([
|
||||
'allow_add' => true,
|
||||
'allow_remove' => true,
|
||||
'compound' => false,
|
||||
]);
|
||||
}
|
||||
|
|
97
src/core/Maker/MakeBuilderBlock.php
Normal file
97
src/core/Maker/MakeBuilderBlock.php
Normal file
|
@ -0,0 +1,97 @@
|
|||
<?php
|
||||
|
||||
namespace App\Core\Maker;
|
||||
|
||||
use Doctrine\Common\Annotations\Annotation;
|
||||
use Symfony\Bundle\MakerBundle\ConsoleStyle;
|
||||
use Symfony\Bundle\MakerBundle\DependencyBuilder;
|
||||
use Symfony\Bundle\MakerBundle\Generator;
|
||||
use Symfony\Bundle\MakerBundle\InputConfiguration;
|
||||
use Symfony\Bundle\MakerBundle\Maker\AbstractMaker;
|
||||
use Symfony\Bundle\MakerBundle\Str;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Question\Question;
|
||||
use Symfony\Component\Filesystem\Filesystem;
|
||||
|
||||
class MakeBuilderBlock extends AbstractMaker
|
||||
{
|
||||
public static function getCommandName(): string
|
||||
{
|
||||
return 'make:builder-block';
|
||||
}
|
||||
|
||||
public static function getCommandDescription(): string
|
||||
{
|
||||
return 'Creates a new builder block class';
|
||||
}
|
||||
|
||||
public function configureCommand(Command $command, InputConfiguration $inputConf)
|
||||
{
|
||||
$command
|
||||
->addArgument(
|
||||
'builder-block-class',
|
||||
InputArgument::OPTIONAL,
|
||||
'Choose a name for your block class (e.g. <fg=yellow>ExampleBlock</>)'
|
||||
)
|
||||
->setHelp('')
|
||||
;
|
||||
}
|
||||
|
||||
public function generate(InputInterface $input, ConsoleStyle $io, Generator $generator)
|
||||
{
|
||||
$blockClassNameDetails = $generator->createClassNameDetails(
|
||||
$input->getArgument('builder-block-class'),
|
||||
'BuilderBlock\\',
|
||||
'Block'
|
||||
);
|
||||
|
||||
$templatePath = sprintf(
|
||||
'builder_block/%s.html.twig',
|
||||
Str::asSnakeCase(preg_replace('/Block$/', '', $blockClassNameDetails->getShortName()))
|
||||
);
|
||||
|
||||
$options = [
|
||||
'entity' => $blockClassNameDetails->getFullName(),
|
||||
'template' => $templatePath,
|
||||
'label' => Str::asHumanWords($blockClassNameDetails->getShortName())
|
||||
];
|
||||
|
||||
$blockPath = $generator->generateController(
|
||||
$blockClassNameDetails->getFullName(),
|
||||
__DIR__.'/../Resources/maker/builder/Block.tpl.php',
|
||||
$options
|
||||
);
|
||||
|
||||
$generator->writeChanges();
|
||||
$realTemplatePath = 'templates/'.$templatePath;
|
||||
|
||||
$filesystem = new Filesystem();
|
||||
|
||||
if (!$filesystem->exists($templatePath)) {
|
||||
$filesystem->mkdir(dirname($realTemplatePath));
|
||||
$filesystem->dumpFile($realTemplatePath, $this->getTemplate());
|
||||
|
||||
$io->comment(sprintf('<fg=blue>created</>: %s', $realTemplatePath));
|
||||
}
|
||||
|
||||
$this->writeSuccessMessage($io);
|
||||
}
|
||||
|
||||
protected function getTemplate(): string
|
||||
{
|
||||
return <<< EOF
|
||||
<div id="{{ id }}">
|
||||
{% for item in children %}
|
||||
{{ item|block_to_html(context) }}
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
||||
EOF;
|
||||
}
|
||||
|
||||
public function configureDependencies(DependencyBuilder $dependencies)
|
||||
{
|
||||
}
|
||||
}
|
|
@ -149,6 +149,7 @@ EOF
|
|||
'textarea' => null,
|
||||
'choice' => 'BlockEntity\\ChoiceBlock::class',
|
||||
'collection' => 'BlockEntity\\CollectionBlock::class',
|
||||
'builder' => 'BlockEntity\\BuilderBlock::class',
|
||||
'editor_js_textarea' => null,
|
||||
'file' => 'BlockEntity\\FileBlock::class',
|
||||
'file_picker' => null,
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
namespace App\Core;
|
||||
|
||||
if (!defined('MURPH_VERSION')) {
|
||||
define('MURPH_VERSION', 'v1.25.0');
|
||||
define('MURPH_VERSION', 'v1.25.1');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -769,11 +769,14 @@ label.required::after {
|
|||
background: rgba(map-get($theme-colors, 'dark-blue'), 0.02);
|
||||
}
|
||||
|
||||
> .block {
|
||||
border: 1px solid map-get($theme-colors, 'dark-blue');
|
||||
}
|
||||
|
||||
.block-header {
|
||||
.block-header-item {
|
||||
font-size: 12px;
|
||||
display: inline-block;
|
||||
margin-bottom: 10px;
|
||||
padding: 2px 6px;
|
||||
border-radius: 4px;
|
||||
margin-right: 2px;
|
||||
|
@ -781,24 +784,94 @@ label.required::after {
|
|||
}
|
||||
}
|
||||
|
||||
.block-label {
|
||||
background: map-get($theme-colors, 'dark-blue');
|
||||
border: 1px solid map-get($theme-colors, 'dark-blue');
|
||||
color: lighten(map-get($theme-colors, 'dark-blue'), 100%);
|
||||
$block-colors: #E183F5 #E3F7C6 #82DDF5 #F5BA82 #A088A6;
|
||||
$block-colors-length: length($block-colors);
|
||||
|
||||
.block .block-icon {
|
||||
> * {
|
||||
display: inline-block;
|
||||
margin-right: 3px;
|
||||
}
|
||||
}
|
||||
|
||||
.block-settings-inverse {
|
||||
background: none;
|
||||
border: 1px solid map-get($theme-colors, 'dark-blue');
|
||||
color: map-get($theme-colors, 'dark-blue');
|
||||
@for $i from 1 through 100 {
|
||||
$block-color-index: ($block-colors-length + $i) % $block-colors-length + 1;
|
||||
|
||||
.block-depth-#{$i} {
|
||||
.block-label {
|
||||
background: nth($block-colors, $block-color-index);
|
||||
border: 1px solid darken(nth($block-colors, $block-color-index), 50%);
|
||||
color: darken(nth($block-colors, $block-color-index), 50%);
|
||||
}
|
||||
|
||||
.builder-add .btn {
|
||||
background: nth($block-colors, $block-color-index);
|
||||
border: 1px solid darken(nth($block-colors, $block-color-index), 50%);
|
||||
color: darken(nth($block-colors, $block-color-index), 50%);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.builder-add {
|
||||
width: 100%;
|
||||
|
||||
&-top {
|
||||
margin-top: 7px;
|
||||
}
|
||||
|
||||
.btn {
|
||||
font-size: 12px;
|
||||
line-height: 14px;
|
||||
padding: 3px 5px;
|
||||
}
|
||||
}
|
||||
|
||||
.block-root > .container .builder-add {
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
.block-settings {
|
||||
padding: 4px;
|
||||
margin-top: 10px;
|
||||
margin-bottom: 5px;
|
||||
|
||||
.form-control {
|
||||
margin-top: 0.5rem !important;
|
||||
}
|
||||
}
|
||||
|
||||
.block .block {
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.block-id {
|
||||
font-size: 12px;
|
||||
margin-right: 5px;
|
||||
}
|
||||
|
||||
.block-show-dropzone {
|
||||
.block-dropzone {
|
||||
min-height: 40px;
|
||||
}
|
||||
}
|
||||
|
||||
.block-preview {
|
||||
white-space: nowrap;
|
||||
max-width: 30%;
|
||||
text-overflow: ellipsis;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.builder-code-editor {
|
||||
border: 0;
|
||||
padding: 0;
|
||||
background: none;
|
||||
position: fixed;
|
||||
top: 15px;
|
||||
|
||||
textarea {
|
||||
font-family: Monospace;
|
||||
min-height: 50vh;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,31 +1,70 @@
|
|||
<template>
|
||||
<div class="block" :key="blockKey" v-if="Object.keys(widgets).length">
|
||||
<BuilderBlockItem
|
||||
v-for="(block, key) in value"
|
||||
:key="block.id + '-' + key"
|
||||
:item="block"
|
||||
:widgets="widgets"
|
||||
:isFirst="key === 0"
|
||||
:isLast="key == Object.keys(value)[Object.keys(value).length -1]"
|
||||
@remove-item="removeBlock(key)"
|
||||
@move-item-up="moveBlockUp(key)"
|
||||
@move-item-down="moveBlockDown(key)"
|
||||
/>
|
||||
<div
|
||||
class="block block-root"
|
||||
v-if="Object.keys(widgets).length && value !== null"
|
||||
>
|
||||
<div class="container">
|
||||
<BuilderBlockCreate
|
||||
:container="value"
|
||||
:widgets="widgets"
|
||||
:openedBlocks="openedBlocks"
|
||||
:allowedWidgets="[]"
|
||||
v-if="value.length > 0"
|
||||
position="top"
|
||||
/>
|
||||
</div>
|
||||
<textarea :name="name" class="d-none">{{ toJson(value) }}</textarea>
|
||||
<Draggable
|
||||
v-model="value"
|
||||
:key="blockKey"
|
||||
:animation="200"
|
||||
group="children"
|
||||
ghost-class="ghost"
|
||||
@start="dragStart"
|
||||
@end="dragEnd"
|
||||
handle=".dragger"
|
||||
:class="{'block-show-dropzone': showDragDrop}"
|
||||
>
|
||||
<BuilderBlockItem
|
||||
v-for="(block, key) in value"
|
||||
:key="block.id + '-' + key"
|
||||
:item="block"
|
||||
:widgets="widgets"
|
||||
:openedBlocks="openedBlocks"
|
||||
:depth="1"
|
||||
@remove-item="removeBlock(key)"
|
||||
@drag-start="dragStart"
|
||||
@drag-end="dragEnd"
|
||||
/>
|
||||
<div class="container">
|
||||
<div class="d-flex justify-content-between">
|
||||
<BuilderBlockCreate
|
||||
:container="value"
|
||||
:widgets="widgets"
|
||||
:openedBlocks="openedBlocks"
|
||||
:allowedWidgets="[]"
|
||||
position="bottom"
|
||||
/>
|
||||
<div>
|
||||
<BuilderBlockCodeEditor
|
||||
ref="dialog"
|
||||
:value="value"
|
||||
:widgets="widgets"
|
||||
@update="codeUpdate"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<textarea :name="name" class="d-none">{{ toJson(value) }}</textarea>
|
||||
</Draggable>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import BuilderBlockItem from './BuilderBlockItem'
|
||||
import BuilderBlockCodeEditor from './BuilderBlockCodeEditor'
|
||||
import BuilderBlockCreate from './BuilderBlockCreate'
|
||||
import Routing from '../../../../../../../../../friendsofsymfony/jsrouting-bundle/Resources/public/js/router.min.js'
|
||||
import Draggable from 'vuedraggable'
|
||||
|
||||
const axios = require('axios').default
|
||||
const routes = require('../../../../../../../../../../public/js/fos_js_routes.json')
|
||||
|
@ -33,6 +72,12 @@ Routing.setRoutingData(routes)
|
|||
|
||||
export default {
|
||||
name: 'BuilderBlock',
|
||||
components: {
|
||||
BuilderBlockItem,
|
||||
BuilderBlockCreate,
|
||||
Draggable,
|
||||
BuilderBlockCodeEditor,
|
||||
},
|
||||
props: {
|
||||
id: {
|
||||
type: String,
|
||||
|
@ -49,9 +94,12 @@ export default {
|
|||
},
|
||||
data() {
|
||||
return {
|
||||
value: this.initialValue,
|
||||
value: null,
|
||||
nextValue: null,
|
||||
widgets: {},
|
||||
blockKey: 0
|
||||
openedBlocks: {},
|
||||
blockKey: 0,
|
||||
showDragDrop: false,
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
|
@ -61,25 +109,8 @@ export default {
|
|||
triggerBuilderBlockEvent() {
|
||||
document.querySelector('body').dispatchEvent(new Event('builder_block.update'))
|
||||
},
|
||||
moveBlockUp(key) {
|
||||
let newValue = this.value.map((x) => x)
|
||||
|
||||
newValue[key-1] = this.value[key]
|
||||
newValue[key] = this.value[key-1]
|
||||
|
||||
this.value = newValue
|
||||
|
||||
++this.blockKey
|
||||
},
|
||||
moveBlockDown(key) {
|
||||
let newValue = this.value.map((x) => x)
|
||||
|
||||
newValue[key+1] = this.value[key]
|
||||
newValue[key] = this.value[key+1]
|
||||
|
||||
this.value = newValue
|
||||
|
||||
++this.blockKey
|
||||
codeUpdate(nextValue) {
|
||||
this.value = nextValue
|
||||
},
|
||||
removeBlock(key) {
|
||||
let newValue = []
|
||||
|
@ -92,20 +123,52 @@ export default {
|
|||
|
||||
this.value = newValue
|
||||
|
||||
// ++this.blockKey
|
||||
++this.blockKey
|
||||
},
|
||||
dragStart() {
|
||||
this.showDragDrop = true
|
||||
},
|
||||
dragEnd() {
|
||||
this.showDragDrop = false
|
||||
|
||||
++this.blockKey
|
||||
},
|
||||
fixSettings(data) {
|
||||
if (Array.isArray(data)) {
|
||||
data.forEach((value, key) => {
|
||||
data[key] = this.fixSettings(value)
|
||||
})
|
||||
} else {
|
||||
const widget = this.widgets[data.widget]
|
||||
|
||||
if (!widget) {
|
||||
return data
|
||||
}
|
||||
|
||||
const nextSettings = {}
|
||||
|
||||
for (let setting in widget.settings) {
|
||||
if (data.settings.hasOwnProperty(setting)) {
|
||||
nextSettings[setting] = data.settings[setting]
|
||||
} else {
|
||||
nextSettings[setting] = widget.settings[setting].default
|
||||
}
|
||||
}
|
||||
|
||||
data.settings = nextSettings
|
||||
data.children = this.fixSettings(data.children)
|
||||
}
|
||||
|
||||
return data
|
||||
},
|
||||
},
|
||||
components: {
|
||||
BuilderBlockItem,
|
||||
BuilderBlockCreate,
|
||||
},
|
||||
mounted() {
|
||||
this.triggerBuilderBlockEvent()
|
||||
const that = this
|
||||
|
||||
axios.get(Routing.generate('admin_editor_builder_block_widgets'))
|
||||
.then((response) => {
|
||||
that.widgets = response.data
|
||||
that.value = that.fixSettings(that.initialValue)
|
||||
})
|
||||
},
|
||||
created() {
|
||||
|
|
|
@ -0,0 +1,163 @@
|
|||
<template>
|
||||
<div>
|
||||
<button
|
||||
type="button"
|
||||
class="btn btn-sm"
|
||||
v-on:click="open"
|
||||
>
|
||||
<i class="fas fa-code"></i>
|
||||
</button>
|
||||
<dialog ref="dialog" class="modal-dialog modal-dialog-large builder-code-editor">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title">Code editor</h5>
|
||||
<button
|
||||
type="button"
|
||||
class="close"
|
||||
v-on:click="close"
|
||||
>
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<div class="form-group">
|
||||
<textarea
|
||||
class="form-control"
|
||||
rows="10"
|
||||
ref="codeEditor"
|
||||
v-model="nextValue"
|
||||
>
|
||||
</textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button
|
||||
type="button"
|
||||
class="btn btn-secondary"
|
||||
v-on:click="close"
|
||||
>
|
||||
Close
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="btn btn-primary"
|
||||
v-on:click="checkAndSaveNextValue"
|
||||
>
|
||||
Save
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
name: 'BuilderBlockCodeEditor',
|
||||
props: {
|
||||
value: {
|
||||
type: Array,
|
||||
required: true,
|
||||
},
|
||||
widgets: {
|
||||
type: Object,
|
||||
required: true
|
||||
},
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
nextValue: null
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
toJson(value) {
|
||||
return JSON.stringify(value, null, 2)
|
||||
},
|
||||
open() {
|
||||
this.nextValue = this.toJson(this.value)
|
||||
this.$refs.dialog.showModal()
|
||||
},
|
||||
close() {
|
||||
this.$refs.codeEditor.classList.toggle('is-invalid', false)
|
||||
this.$refs.dialog.close()
|
||||
},
|
||||
isNextValueItemValueValid(item) {
|
||||
const hasId = typeof item.id === 'string'
|
||||
const hasWidget = typeof item.widget === 'string' && this.widgets[item.widget]
|
||||
const hasSettings = typeof item.settings === 'object'
|
||||
const hasChildren = Array.isArray(item.children)
|
||||
|
||||
if (!hasId || !hasWidget || !hasSettings || !hasChildren) {
|
||||
return false
|
||||
}
|
||||
|
||||
for (let child of item.children) {
|
||||
if (!this.isNextValueItemValueValid(child)) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
},
|
||||
updateNextValueRecursiveIds(data) {
|
||||
if (Array.isArray(data)) {
|
||||
data.forEach((value, key) => {
|
||||
data[key] = this.updateNextValueRecursiveIds(value)
|
||||
})
|
||||
} else {
|
||||
data.id = this.makeId()
|
||||
data.children = this.updateNextValueRecursiveIds(data.children)
|
||||
}
|
||||
|
||||
return data
|
||||
},
|
||||
checkAndSaveNextValue() {
|
||||
this.$refs.codeEditor.classList.toggle('is-invalid', false)
|
||||
let hasError = false
|
||||
|
||||
try {
|
||||
let data = JSON.parse(this.nextValue)
|
||||
|
||||
if (!Array.isArray(data)) {
|
||||
hasError = true
|
||||
} else {
|
||||
for (let item of data) {
|
||||
if (!this.isNextValueItemValueValid(item)) {
|
||||
hasError = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!hasError) {
|
||||
this.$emit('update', this.updateNextValueRecursiveIds(data))
|
||||
this.close()
|
||||
}
|
||||
|
||||
} catch (e) {
|
||||
hasError = true
|
||||
}
|
||||
|
||||
return this.$refs.codeEditor.classList.toggle('is-invalid', hasError)
|
||||
},
|
||||
makeId() {
|
||||
let result = ''
|
||||
const characters = 'abcdefghijklmnopqrstuvwxyz0123456789'
|
||||
const charactersLength = characters.length
|
||||
|
||||
for (let i = 0; i < 7; i++) {
|
||||
result += characters.charAt(Math.floor(Math.random() * charactersLength))
|
||||
}
|
||||
|
||||
return `block-${result}`
|
||||
},
|
||||
},
|
||||
components: {
|
||||
},
|
||||
mounted() {
|
||||
},
|
||||
created() {
|
||||
},
|
||||
updated() {
|
||||
}
|
||||
}
|
||||
</script>
|
|
@ -1,77 +1,92 @@
|
|||
<style scoped>
|
||||
.categories {
|
||||
padding: 10px;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.category {
|
||||
padding: 10px 0;
|
||||
}
|
||||
|
||||
.category-label {
|
||||
font-weight: bold;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
|
||||
.widget {
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.widget-content {
|
||||
background: #fff;
|
||||
padding: 10px;
|
||||
text-align: center;
|
||||
.builder-block-picker {
|
||||
padding: 8px;
|
||||
border: 1px solid #333;
|
||||
border-radius: 4px;
|
||||
background: #fff;
|
||||
}
|
||||
|
||||
.builder-block-picker-menu {
|
||||
width: 150px;
|
||||
}
|
||||
|
||||
.builder-block-picker-widgets {
|
||||
width: calc(100% - 150px - 10px);
|
||||
padding-left: 5px;
|
||||
}
|
||||
|
||||
.nav-item {
|
||||
cursor: pointer;
|
||||
margin-right: 5px;
|
||||
margin-bottom: 5px;
|
||||
border: 1px solid #1e2430;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.widget-icon {
|
||||
margin-top: 5px;
|
||||
font-size: 25px;
|
||||
margin-right: 3px;
|
||||
}
|
||||
|
||||
.widget {
|
||||
background: #fff;
|
||||
padding: 10px;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
margin-right: 7px;
|
||||
margin-bottom: 9px;
|
||||
border: 1px solid #b4b4b4;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.widget:hover {
|
||||
background: #eee;
|
||||
border: 1px solid #1e2430;
|
||||
}
|
||||
|
||||
.widget-label {
|
||||
font-weight: bold;
|
||||
.search {
|
||||
max-width: 300px;
|
||||
}
|
||||
</style>
|
||||
|
||||
<template>
|
||||
<div class="builder-add">
|
||||
<span class="btn btn-sm btn-secondary" v-on:click="togglePicker">
|
||||
<div class="builder-add" :class="{'builder-add-top': position === 'top'}">
|
||||
<button type="button" class="btn btn-secondary" v-on:click="togglePicker">
|
||||
<span class="fa fa-plus"></span>
|
||||
</span>
|
||||
</button>
|
||||
|
||||
<div class="categories mt-2 list-group" :class="{'d-none': !showPicker}">
|
||||
<div class="builder-block-picker mt-2 row" :class="{'d-none': !showPicker}">
|
||||
<div class="col-auto builder-block-picker-menu">
|
||||
<ul class="nav nav-pills pl-0">
|
||||
<li
|
||||
v-for="(category, key) in categories()"
|
||||
v-if="Object.keys(category.widgets).length"
|
||||
class="nav-item d-block"
|
||||
>
|
||||
<a
|
||||
class="nav-link d-block mb-1"
|
||||
:class="{'active': activeCategory == key}"
|
||||
v-on:click="activeCategory = key"
|
||||
>
|
||||
{{ category.label }}
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div
|
||||
v-for="category in categories()"
|
||||
v-for="(category, key) in categories()"
|
||||
v-if="Object.keys(category.widgets).length"
|
||||
class="category"
|
||||
class="col-auto builder-block-picker-widgets"
|
||||
:class="{'d-none': activeCategory !== key}"
|
||||
>
|
||||
<div
|
||||
v-if="category.label != 'none'"
|
||||
v-text="category.label"
|
||||
class="category-label row"
|
||||
></div>
|
||||
|
||||
<div
|
||||
v-for="(widget, name) in category.widgets"
|
||||
v-on:click="add(name, widget)"
|
||||
class="widget col-3"
|
||||
>
|
||||
<div class="widget-content">
|
||||
<div class="widget-label">
|
||||
{{ widget.label }}
|
||||
</div>
|
||||
|
||||
<div class="widget-icon" v-if="widget.icon" v-html="widget.icon">
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-12 mb-4">
|
||||
<input v-model="search" placeholder="Type to search..." class="form-control search">
|
||||
</div>
|
||||
<div
|
||||
v-for="(widget, name) in category.widgets"
|
||||
v-on:click="add(name, widget)"
|
||||
v-if="matchSearch(widget.label) || matchSearch(name)"
|
||||
class="widget col-auto"
|
||||
>
|
||||
<span class="widget-icon" v-if="widget.icon" v-html="widget.icon"></span>
|
||||
{{ widget.label }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -96,10 +111,20 @@ export default {
|
|||
type: Array,
|
||||
required: true
|
||||
},
|
||||
openedBlocks: {
|
||||
type: Object,
|
||||
required: true
|
||||
},
|
||||
position: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
showPicker: false,
|
||||
activeCategory: 'all',
|
||||
search: '',
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
|
@ -110,14 +135,21 @@ export default {
|
|||
settings[i] = widget.settings[i].default
|
||||
}
|
||||
|
||||
this.container.push({
|
||||
const block = {
|
||||
id: this.makeId(),
|
||||
widget: name,
|
||||
settings,
|
||||
children: [],
|
||||
})
|
||||
}
|
||||
|
||||
if (this.position === 'bottom') {
|
||||
this.container.push(block)
|
||||
} else {
|
||||
this.container.unshift(block)
|
||||
}
|
||||
|
||||
this.$emit('updateContainer', this.container)
|
||||
this.openedBlocks[block.id] = true
|
||||
this.togglePicker()
|
||||
},
|
||||
makeId() {
|
||||
|
@ -131,17 +163,26 @@ export default {
|
|||
|
||||
return `block-${result}`
|
||||
},
|
||||
matchSearch(name) {
|
||||
if (!this.search.trim().length) {
|
||||
return true
|
||||
}
|
||||
|
||||
return name.toLowerCase().includes(this.search.toLowerCase())
|
||||
},
|
||||
togglePicker() {
|
||||
this.showPicker = !this.showPicker
|
||||
},
|
||||
categories() {
|
||||
let items = {}
|
||||
let items = {
|
||||
all: {label: 'All', widgets: {}},
|
||||
}
|
||||
|
||||
for (let widgetName in this.widgets) {
|
||||
let value = this.widgets[widgetName]
|
||||
|
||||
if (!value.category) {
|
||||
value.category = 'none'
|
||||
value.category = 'all'
|
||||
}
|
||||
|
||||
if (typeof items[value.category] === 'undefined') {
|
||||
|
@ -153,6 +194,7 @@ export default {
|
|||
|
||||
if (!this.allowedWidgets.length || this.allowedWidgets.includes(widgetName)) {
|
||||
items[value.category].widgets[widgetName] = value
|
||||
items['all'].widgets[widgetName] = value
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,47 +1,68 @@
|
|||
<template>
|
||||
<div class="block" v-if="widget" :key="blockKey">
|
||||
<div class="block-header">
|
||||
<div class="float-right">
|
||||
<span class="block-id">
|
||||
{{ item.id }}
|
||||
</span>
|
||||
<div class="block-header-item text-white bg-danger" v-on:click="removeMe(item)">
|
||||
<span class="fa fa-trash"></span>
|
||||
<div
|
||||
class="block"
|
||||
:class="'block-depth-' + depth"
|
||||
v-if="widget"
|
||||
:key="blockKey"
|
||||
>
|
||||
<div class="block-header d-flex justify-content-between">
|
||||
<div>
|
||||
<div
|
||||
class="block-header-item block-label"
|
||||
:title="item.widget"
|
||||
>
|
||||
<span
|
||||
class="block-icon"
|
||||
v-if="widget.icon"
|
||||
v-html="widget.icon"
|
||||
>
|
||||
</span>
|
||||
|
||||
{{ widget.label }}
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
class="block-header-item block-label"
|
||||
:title="item.widget"
|
||||
>
|
||||
{{ widget.label }}
|
||||
</div>
|
||||
<div
|
||||
class="block-header-item block-settings-inverse"
|
||||
v-on:click="toggleSettings"
|
||||
v-if="Object.keys(widget.settings).length"
|
||||
>
|
||||
<span class="fa fa-cog"></span>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
class="block-header-item btn btn-sm btn-outline-secondary"
|
||||
v-on:click="toggleSettings"
|
||||
v-if="Object.keys(widget.settings).length"
|
||||
>
|
||||
<span class="fa fa-cog"></span>
|
||||
</button>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
class="block-header-item btn btn-sm btn-outline-secondary dragger"
|
||||
>
|
||||
<span class="fa fa-arrows-alt dragger"></span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div
|
||||
v-if="!isFirst"
|
||||
v-on:click="moveMeUp"
|
||||
class="block-header-item block-settings-inverse"
|
||||
v-if="widget.preview && typeof item.settings[widget.preview] == 'string'"
|
||||
class="block-preview"
|
||||
>
|
||||
<span class="fas fa-arrow-up"></span>
|
||||
</div>
|
||||
<div
|
||||
v-if="!isLast"
|
||||
v-on:click="moveMeDown"
|
||||
class="block-header-item block-settings-inverse"
|
||||
>
|
||||
<span class="fas fa-arrow-down"></span>
|
||||
</div>
|
||||
{{ truncate(item.settings[widget.preview]) }}
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<span class="block-id">
|
||||
{{ item.id }}
|
||||
</span>
|
||||
<button
|
||||
type="button"
|
||||
class="block-header-item btn btn-sm text-white bg-danger"
|
||||
v-on:click="removeMe(item)"
|
||||
>
|
||||
<span class="fa fa-trash dragger"></span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="block-settings" v-if="Object.keys(widget.settings).length" :class="{'d-none': !showSettings}">
|
||||
<div class="row">
|
||||
<BuilderBlockSetting
|
||||
class="mb-0"
|
||||
v-for="(params, setting) in widget.settings"
|
||||
:key="item.id + '-' + setting"
|
||||
:class="widget.class"
|
||||
|
@ -52,35 +73,76 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<BuilderBlockItem
|
||||
v-if="item.children !== null && item.children.length > 0"
|
||||
v-for="(child, key) in item.children"
|
||||
:key="child.id"
|
||||
:item="child"
|
||||
:widgets="widgets"
|
||||
:isFirst="key === 0"
|
||||
:isLast="key == Object.keys(item.children)[Object.keys(item.children).length -1]"
|
||||
@remove-item="removeBlock(key)"
|
||||
@move-item-up="moveBlockUp(key)"
|
||||
@move-item-down="moveBlockDown(key)"
|
||||
/>
|
||||
|
||||
<div v-if="widget.isContainer" class="container">
|
||||
<BuilderBlockCreate
|
||||
:container="item.children"
|
||||
:widgets="widgets"
|
||||
:openedBlocks="openedBlocks"
|
||||
:allowedWidgets="widget.widgets"
|
||||
v-if="item.children.length > 0"
|
||||
position="top"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<Draggable
|
||||
v-if="widget.isContainer"
|
||||
v-model="item.children"
|
||||
ghost-class="ghost"
|
||||
group="children"
|
||||
@start="dragStart"
|
||||
@end="dragEnd"
|
||||
:animation="200"
|
||||
handle=".dragger"
|
||||
class="block-dropzone"
|
||||
>
|
||||
<BuilderBlockItem
|
||||
v-if="item.children !== null && item.children.length > 0"
|
||||
v-for="(child, key) in item.children"
|
||||
:key="child.id"
|
||||
:item="child"
|
||||
:widgets="widgets"
|
||||
:openedBlocks="openedBlocks"
|
||||
:depth="depth + 1"
|
||||
@remove-item="removeBlock(key)"
|
||||
@drag-start="dragStart"
|
||||
@drag-end="dragEnd"
|
||||
/>
|
||||
</Draggable>
|
||||
|
||||
<div v-if="widget.isContainer" class="container">
|
||||
<div class="d-flex justify-content-between">
|
||||
<BuilderBlockCreate
|
||||
:container="item.children"
|
||||
:widgets="widgets"
|
||||
:openedBlocks="openedBlocks"
|
||||
:allowedWidgets="widget.widgets"
|
||||
position="bottom"
|
||||
/>
|
||||
<BuilderBlockCodeEditor
|
||||
ref="dialog"
|
||||
:value="item.children"
|
||||
:widgets="widgets"
|
||||
@update="codeUpdate"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import BuilderBlockCreate from './BuilderBlockCreate'
|
||||
import BuilderBlockCodeEditor from './BuilderBlockCodeEditor'
|
||||
import BuilderBlockSetting from './BuilderBlockSetting'
|
||||
import Draggable from 'vuedraggable'
|
||||
|
||||
export default {
|
||||
name: 'BuilderBlockItem',
|
||||
components: {
|
||||
BuilderBlockCreate,
|
||||
BuilderBlockSetting,
|
||||
BuilderBlockCodeEditor,
|
||||
Draggable,
|
||||
},
|
||||
props: {
|
||||
widgets: {
|
||||
type: Object,
|
||||
|
@ -90,54 +152,35 @@ export default {
|
|||
type: Object,
|
||||
required: true
|
||||
},
|
||||
isFirst: {
|
||||
type: Boolean,
|
||||
openedBlocks: {
|
||||
type: Object,
|
||||
required: true
|
||||
},
|
||||
isLast: {
|
||||
type: Boolean,
|
||||
depth: {
|
||||
type: Number,
|
||||
required: true
|
||||
}
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
widget: null,
|
||||
showSettings: false,
|
||||
blockKey: 0
|
||||
showSettings: this.openedBlocks[this.item.id] === true,
|
||||
blockKey: 0,
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
toggleSettings() {
|
||||
this.openedBlocks[this.item.id] = !this.openedBlocks[this.item.id]
|
||||
this.showSettings = !this.showSettings
|
||||
},
|
||||
truncate(value) {
|
||||
return value.replace(/(<([^>]+)>)/ig, '').trim()
|
||||
},
|
||||
removeMe() {
|
||||
this.$emit('remove-item')
|
||||
},
|
||||
moveMeUp() {
|
||||
this.$emit('move-item-up')
|
||||
},
|
||||
moveMeDown() {
|
||||
this.$emit('move-item-down')
|
||||
},
|
||||
moveBlockUp(key) {
|
||||
let newValue = this.item.children.map((x) => x)
|
||||
|
||||
newValue[key-1] = this.item.children[key]
|
||||
newValue[key] = this.item.children[key-1]
|
||||
|
||||
this.item.children = newValue
|
||||
|
||||
++this.blockKey
|
||||
},
|
||||
moveBlockDown(key) {
|
||||
let newValue = this.item.children.map((x) => x)
|
||||
|
||||
newValue[key+1] = this.item.children[key]
|
||||
newValue[key] = this.item.children[key+1]
|
||||
|
||||
this.item.children = newValue
|
||||
|
||||
++this.blockKey
|
||||
codeUpdate(nextValue) {
|
||||
this.item.children = nextValue
|
||||
},
|
||||
removeBlock(key) {
|
||||
let children = []
|
||||
|
@ -151,10 +194,13 @@ export default {
|
|||
this.item.children = children
|
||||
++this.blockKey
|
||||
},
|
||||
},
|
||||
components: {
|
||||
BuilderBlockCreate,
|
||||
BuilderBlockSetting,
|
||||
dragStart() {
|
||||
this.$emit('drag-start')
|
||||
},
|
||||
dragEnd() {
|
||||
this.$emit('drag-end')
|
||||
++this.blockKey
|
||||
},
|
||||
},
|
||||
mounted() {
|
||||
this.widget = this.widgets[this.item.widget]
|
||||
|
|
|
@ -1,10 +1,6 @@
|
|||
<template>
|
||||
<div class="form-group">
|
||||
<label
|
||||
v-if="params.label && params.type !== 'checkbox'"
|
||||
v-text="params.label"
|
||||
>
|
||||
</label>
|
||||
<label class="form-group mb-2">
|
||||
<span v-if="params.label && params.type !== 'checkbox'" v-text="params.label"></span>
|
||||
|
||||
<input
|
||||
v-if="['number', 'checkbox', 'text'].includes(params.type)"
|
||||
|
@ -14,11 +10,7 @@
|
|||
:class="{'form-control': params.type !== 'checkbox'}"
|
||||
/>
|
||||
|
||||
<label
|
||||
v-if="params.label && params.type == 'checkbox'"
|
||||
v-text="params.label"
|
||||
>
|
||||
</label>
|
||||
<span v-if="params.label && params.type == 'checkbox'" v-text="params.label"></span>
|
||||
|
||||
<textarea
|
||||
v-if="params.type == 'textarea'"
|
||||
|
@ -37,7 +29,7 @@
|
|||
{{ v.text }}
|
||||
</option>
|
||||
</select>
|
||||
</div>
|
||||
</label>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
|
@ -59,3 +51,9 @@ export default {
|
|||
},
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
label > span {
|
||||
margin-bottom: 3px;
|
||||
}
|
||||
</style>
|
||||
|
|
|
@ -202,6 +202,7 @@ import FileIcon from './FileIcon'
|
|||
|
||||
const axios = require('axios').default
|
||||
const routes = require('../../../../../../../../../../public/js/fos_js_routes.json')
|
||||
const $ = require('jquery')
|
||||
|
||||
Routing.setRoutingData(routes)
|
||||
|
||||
|
|
38
src/core/Resources/maker/builder/Block.tpl.php
Normal file
38
src/core/Resources/maker/builder/Block.tpl.php
Normal file
|
@ -0,0 +1,38 @@
|
|||
<?php echo "<?php\n"; ?>
|
||||
|
||||
namespace <?php echo $namespace; ?>;
|
||||
|
||||
use App\Core\BuilderBlock\BuilderBlock;
|
||||
use Symfony\Component\DependencyInjection\Attribute\AutoconfigureTag;
|
||||
|
||||
#[AutoconfigureTag('builder_block.widget')]
|
||||
class <?php echo $class_name; ?> extends BuilderBlock
|
||||
{
|
||||
public function configure()
|
||||
{
|
||||
$this
|
||||
->setName('<?php echo $class_name; ?>')
|
||||
->setCategory('Custom')
|
||||
->setTemplate('<?php echo $template; ?>')
|
||||
->setLabel('<?php echo $label; ?>')
|
||||
// ->setOrder(1)
|
||||
// ->setIsContainer(false)
|
||||
// ->setIcon('<i class="fas fa-pencil-alt"></i>')
|
||||
// ->setClass('col-md-12')
|
||||
// ->addSetting(name: 'value1', label: 'Text', type: 'text', attributes: [], default: '')
|
||||
// ->addSetting(name: 'value2', label: 'Checkbox', type: 'checkbox', attributes: [], default: true)
|
||||
// ->addSetting(name: 'value2', label: 'Number', type: 'checkbox', attributes: [], default: true)
|
||||
// ->addSetting(name: 'value3', label: 'Textarea', type: 'textarea', attributes: [], default: '')
|
||||
// ->addSetting(name: 'value4', label: 'Choice', type: 'select', attributes: [], default: '', extraOptions: [
|
||||
// 'options' => [
|
||||
// ['text' => 'Choice 1', 'value' => 'choice1'],
|
||||
// ['text' => 'Choice 2', 'value' => 'choice2'],
|
||||
// ],
|
||||
// ])
|
||||
;
|
||||
}
|
||||
|
||||
public function buildVars(array $data, array $context)
|
||||
{
|
||||
}
|
||||
}
|
|
@ -229,3 +229,9 @@
|
|||
"Medium": "Moyen"
|
||||
"Large": "Large"
|
||||
"Extra large": "Très large"
|
||||
"Level": "Niveau"
|
||||
"Insert line breaks": "Ajouter les retours chariot"
|
||||
'Allow HTML': "Autoriser l'HTML"
|
||||
"Custom class": "Classe personnalisée"
|
||||
"Editors": "Éditeurs"
|
||||
"All": "Tous"
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
<div class="alert {% if settings.level|default(null) %}alert-{{ settings.level }}{% endif %}" id="{{ id }}">
|
||||
{% for item in children %}
|
||||
{{ item|block_to_html(context) }}
|
||||
{% endfor %}
|
||||
</div>
|
|
@ -6,8 +6,8 @@
|
|||
'col-xl-': settings.sizeXl|default(null),
|
||||
} %}
|
||||
|
||||
<div class="col {% for i, v in sizes%}{% if v|length %}{{ i }}{{ v }} {% endif %}{% endfor -%}" id="{{ id }}">
|
||||
<div class="col {% for i, v in sizes%}{% if v|length %}{{ i }}{{ v }} {% endif %}{% endfor -%} {{ settings.customClass|default(null) }}" id="{{ id }}">
|
||||
{% for item in children %}
|
||||
{{ item|block_to_html }}
|
||||
{{ item|block_to_html(context) }}
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<div class="container{% if settings.isFluid|default(false) %}-fluid{% endif %}" id="{{ id }}">
|
||||
<div class="container{% if settings.isFluid|default(false) %}-fluid{% endif %} {{ settings.customClass|default(null) }}" id="{{ id }}">
|
||||
{% for item in children %}
|
||||
{{ item|block_to_html }}
|
||||
{{ item|block_to_html(context) }}
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<div class="row" id="{{ id }}">
|
||||
<div class="row {{ settings.customClass|default(null) }}" id="{{ id }}">
|
||||
{% for item in children %}
|
||||
{{ item|block_to_html }}
|
||||
{{ item|block_to_html(context) }}
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
|
|
@ -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 %}
|
|
@ -2,9 +2,14 @@
|
|||
|
||||
{% block builder_widget %}
|
||||
{% set row_attr = row_attr|merge({class: 'builder-widget ' ~ (row_attr.class ?? '')}) %}
|
||||
{% set value = value is iterable ? value|json_encode : value %}
|
||||
|
||||
{% if value == '' %}
|
||||
{% set value = '[]' %}
|
||||
{% endif %}
|
||||
|
||||
<div {% for attr, value in row_attr %}{{ attr }}="{{ value }}" {% endfor %}>
|
||||
<div class="builder-widget-component" data-value="{{ value is iterable ? value|json_encode : value }}" data-name="{{ full_name }}" data-id="{{ id }}">
|
||||
<div class="builder-widget-component" data-value="{{ value }}" data-name="{{ full_name }}" data-id="{{ id }}">
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
|
|
@ -7,7 +7,7 @@ use Twig\Environment;
|
|||
use Twig\Extension\AbstractExtension;
|
||||
use Twig\TwigFilter;
|
||||
|
||||
class BuilderBlockExtension extends AbstractExtension
|
||||
class BuilderExtension extends AbstractExtension
|
||||
{
|
||||
public function __construct(protected Environment $twig, protected BuilderBlockContainer $container)
|
||||
{
|
||||
|
@ -23,23 +23,40 @@ class BuilderBlockExtension extends AbstractExtension
|
|||
];
|
||||
}
|
||||
|
||||
public function buildHtml($data): string
|
||||
public function buildHtml(null|array|string $data, array $context = []): ?string
|
||||
{
|
||||
if (null === $data) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (is_string($data)) {
|
||||
$data = json_decode($data, true);
|
||||
}
|
||||
|
||||
if (!is_array($data)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (isset($data['widget'])) {
|
||||
return $this->twig->render($this->container->getWidget($data['widget'])->getTemplate(), [
|
||||
if (!$this->container->hasWidget($data['widget'])) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$widget = $this->container->getWidget($data['widget']);
|
||||
$widget->buildVars($data, $context);
|
||||
|
||||
return $this->twig->render($widget->getTemplate(), [
|
||||
'id' => $data['id'],
|
||||
'settings' => $data['settings'],
|
||||
'children' => $data['children'],
|
||||
'context' => $context,
|
||||
'vars' => $widget->getVars(),
|
||||
]);
|
||||
}
|
||||
|
||||
$render = '';
|
||||
foreach ($data as $item) {
|
||||
$render .= $this->buildHtml($item);
|
||||
$render .= $this->buildHtml($item, $context);
|
||||
}
|
||||
|
||||
return $render;
|
Loading…
Reference in a new issue