Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffreyvr committed Oct 16, 2024
1 parent c0e11ce commit 371338b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions resources/views/editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class="paver__container"
texts: <?php echo htmlspecialchars(json_encode(paver()->getLocalizations()), ENT_QUOTES, 'UTF-8'); ?>,
content: '<?php echo htmlspecialchars($content, ENT_QUOTES, 'UTF-8'); ?>',
api: <?php echo htmlspecialchars(json_encode(paver()->api()), ENT_QUOTES, 'UTF-8'); ?>,
blocks: <?php echo htmlspecialchars(paver()->blocksJson()); ?>,
blocks: <?php echo htmlspecialchars(paver()->blocks(encode: true)); ?>,
...<?php echo htmlspecialchars(json_encode($config)); ?>
})">

Expand Down Expand Up @@ -76,7 +76,7 @@ class="paver__editor"
Whoops, we don't have any blocks (yet)!
</div>
<div x-ref="blocksInserter" class="paver__block-grid paver__sortable">
<?php foreach(paver()->blocksJson(false) as $block) : ?>
<?php foreach(paver()->blocks() as $block) : ?>
<div class="paver__sortable-item paver__block-handle" data-block="<?php echo $block['reference']; ?>">
<span><?php echo $block['icon']; ?></span>
<span><?php echo $block['name']; ?></span>
Expand Down
22 changes: 11 additions & 11 deletions src/Paver.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,22 +92,23 @@ public function api()
return $this->api;
}

public function blocks()
public function blocks($encode = false, $withInstance = false): string|array
{
return $this->blocks;
}

public function blocksJson($encode = true): string|array
{
$blocks = array_map(function ($block) {
$blocks = array_map(function ($block) use($withInstance) {
$instance = BlockFactory::createById($block);

return [
$data = [
'name' => $instance->name,
'reference' => $instance::$reference,
'icon' => $instance->getIcon(),
'childOnly' => $instance->childOnly,
];

if($withInstance) {
$data['instance'] = $instance;
}

return $data;
}, array_keys($this->blocks));

return $encode ? json_encode($blocks) : $blocks;
Expand Down Expand Up @@ -139,9 +140,8 @@ public function render(array|string|null $content = null, array $config = [])
$content = json_decode($content, true);
}

foreach (paver()->blocks() as $block) {
BlockFactory::create($block)
->beforeEditorRender();
foreach (paver()->blocks(withInstance: true) as $block) {
$block['instance']->beforeEditorRender();
}

$data = [
Expand Down

0 comments on commit 371338b

Please sign in to comment.