block builde: add prview

This commit is contained in:
Simon Vieille 2024-05-24 15:43:15 +02:00
parent a0211026ba
commit fea5319dc5
Signed by: deblan
GPG key ID: 579388D585F70417
4 changed files with 32 additions and 0 deletions

View file

@ -21,6 +21,7 @@ class TextareaBlock extends EditorBlock
->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')
;
}
}

View file

@ -12,6 +12,7 @@ abstract class BuilderBlock
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;
@ -171,6 +172,18 @@ abstract class BuilderBlock
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)
{
}
@ -190,6 +203,7 @@ abstract class BuilderBlock
'settings' => $this->getSettings(),
'class' => $this->getClass(),
'icon' => $this->getIcon(),
'preview' => $this->getPreview(),
];
}
}

View file

@ -846,6 +846,13 @@ label.required::after {
}
}
.block-preview {
white-space: nowrap;
max-width: 30%;
text-overflow: ellipsis;
overflow: hidden;
}
dialog {
border: 0;
padding: 0;

View file

@ -31,6 +31,13 @@
</button>
</div>
<div
v-if="widget.preview && typeof item.settings[widget.preview] == 'string'"
class="block-preview"
>
{{ truncate(item.settings[widget.preview]) }}
</div>
<div>
<span class="block-id">
{{ item.id }}
@ -144,6 +151,9 @@ export default {
this.openedBlocks[this.item.id] = !this.openedBlocks[this.item.id]
this.showSettings = !this.showSettings
},
truncate(value) {
return value.replace(/(<([^>]+)>)/ig, '')
},
removeMe() {
this.$emit('remove-item')
},