Skip to content

Commit

Permalink
Fix availableBlocks override eachother
Browse files Browse the repository at this point in the history
  • Loading branch information
Tofandel committed Feb 27, 2024
1 parent df08d1a commit cc173bd
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 11 deletions.
10 changes: 6 additions & 4 deletions frontend/js/components/blocks/Blocks.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<a17-blocks-list :editor-name="editorName" v-slot="{ savedBlocks, availableBlocks, moveBlock, moveBlockToEditor, cloneBlock }">
<a17-blocks-list :editor-name="editorName" :availability-id="availabilityId" v-slot="{ savedBlocks, availableBlocks, moveBlock, moveBlockToEditor, cloneBlock }">
<div class="blocks">
<draggable class="blocks__container"
:value="savedBlocks"
Expand Down Expand Up @@ -163,6 +163,9 @@
editorName: {
type: String,
required: true
},
availabilityId: {
type: String,
}
},
data () {
Expand All @@ -179,9 +182,8 @@
}),
...mapGetters([
'blocks',
'fieldsByBlockId',
'availableBlocks'
])
]),
},
methods: {
setOpened: function () {
Expand Down Expand Up @@ -265,7 +267,7 @@
}
},
checkIfBlockTypeIsAvailable (editorName, type) {
const availableBlocks = JSON.parse(JSON.stringify(this.availableBlocks(editorName)))
const availableBlocks = this.availableBlocks(editorName)
const blockTypes = availableBlocks.map(block => block.component)
return blockTypes.indexOf(type) !== -1
Expand Down
7 changes: 4 additions & 3 deletions frontend/js/components/blocks/BlocksList.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ export default {
editorName: {
type: String,
required: true
},
availabilityId: {
type: String,
}
},
computed: {
availableBlocks () {
const splitted = this.editorName.split('|')
const editorName = splitted[splitted.length - 1]
return this.getAvailableBlocks(editorName)
return this.getAvailableBlocks(this.availabilityId ? this.availabilityId : this.editorName.split('|').pop())
},
savedBlocks () {
return this.blocks(this.editorName)
Expand Down
2 changes: 1 addition & 1 deletion src/Services/Forms/InlineRepeater.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ public function render(): View
$repeater->max($this->max);
}

$repeater->renderForBlocks = $this->renderForBlocks ?? false;
$repeater->renderForBlocks($this->renderForBlocks ?? false);
return $repeater->render();
}

Expand Down
1 change: 1 addition & 0 deletions src/View/Components/Fields/BlockEditor.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public function render(): View
'value' => $this->name,
'nested' => $this->renderForBlocks,
],
'availabilityId' => uniqid($this->name.'-')
])
);
}
Expand Down
3 changes: 3 additions & 0 deletions src/View/Components/Fields/TwillFormComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace A17\Twill\View\Components\Fields;

use A17\Twill\Services\Forms\Traits\RenderForBlocks;
use Illuminate\Contracts\View\View;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\View as ViewFacade;
Expand All @@ -13,6 +14,8 @@
*/
abstract class TwillFormComponent extends Component

Check failure on line 15 in src/View/Components/Fields/TwillFormComponent.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 - LARAVEL 9.*

A17\Twill\View\Components\Fields\TwillFormComponent and A17\Twill\Services\Forms\Traits\RenderForBlocks define the same property ($renderForBlocks) in the composition of A17\Twill\View\Components\Fields\TwillFormComponent. However, the definition differs and is considered incompatible. Class was composed

Check failure on line 15 in src/View/Components/Fields/TwillFormComponent.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 - LARAVEL 10.*

A17\Twill\View\Components\Fields\TwillFormComponent and A17\Twill\Services\Forms\Traits\RenderForBlocks define the same property ($renderForBlocks) in the composition of A17\Twill\View\Components\Fields\TwillFormComponent. However, the definition differs and is considered incompatible. Class was composed

Check failure on line 15 in src/View/Components/Fields/TwillFormComponent.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 - LARAVEL 9.*

A17\Twill\View\Components\Fields\TwillFormComponent and A17\Twill\Services\Forms\Traits\RenderForBlocks define the same property ($renderForBlocks) in the composition of A17\Twill\View\Components\Fields\TwillFormComponent. However, the definition differs and is considered incompatible. Class was composed

Check failure on line 15 in src/View/Components/Fields/TwillFormComponent.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 - LARAVEL 10.*

A17\Twill\View\Components\Fields\TwillFormComponent and A17\Twill\Services\Forms\Traits\RenderForBlocks define the same property ($renderForBlocks) in the composition of A17\Twill\View\Components\Fields\TwillFormComponent. However, the definition differs and is considered incompatible. Class was composed

Check failure on line 15 in src/View/Components/Fields/TwillFormComponent.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 - LARAVEL 9.*

A17\Twill\View\Components\Fields\TwillFormComponent and A17\Twill\Services\Forms\Traits\RenderForBlocks define the same property ($renderForBlocks) in the composition of A17\Twill\View\Components\Fields\TwillFormComponent. However, the definition differs and is considered incompatible. Class was composed

Check failure on line 15 in src/View/Components/Fields/TwillFormComponent.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 - LARAVEL 10.*

A17\Twill\View\Components\Fields\TwillFormComponent and A17\Twill\Services\Forms\Traits\RenderForBlocks define the same property ($renderForBlocks) in the composition of A17\Twill\View\Components\Fields\TwillFormComponent. However, the definition differs and is considered incompatible. Class was composed

Check failure on line 15 in src/View/Components/Fields/TwillFormComponent.php

View workflow job for this annotation

GitHub Actions / PHP 8 - LARAVEL 9.*

A17\Twill\View\Components\Fields\TwillFormComponent and A17\Twill\Services\Forms\Traits\RenderForBlocks define the same property ($renderForBlocks) in the composition of A17\Twill\View\Components\Fields\TwillFormComponent. However, the definition differs and is considered incompatible. Class was composed
{
use RenderForBlocks;

public ?Model $item;

public array $form_fields;
Expand Down
6 changes: 4 additions & 2 deletions views/partials/form/_block_editor.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
@endunless

<a17-blocks title="{{ $label }}"
availability-id="{{ $availabilityId ?? '' }}"
@if ($renderForBlocks) :editor-name="nestedEditorName('{{ $name }}')" @else editor-name="{{ $name }}" @endif
trigger="{{ $trigger }}" :is-settings="{{ (bool) $isSettings ? 'true' : 'false' }}">

trigger="{{ $trigger }}" :is-settings="{{ $isSettings ? 'true' : 'false' }}">
</a17-blocks>

@push('vuexStore')
window['{{ config('twill.js_namespace') }}'].STORE.form.availableBlocks['{{ $name }}'] =
window['{{ config('twill.js_namespace') }}'].STORE.form.availableBlocks['{{ $availabilityId ?: $name }}'] =
{!! json_encode(array_values($allowedBlocks)) !!}
window['{{ config('twill.js_namespace') }}'].STORE.form.editorNames.push({!! json_encode($editorName) !!})
@endpush
Expand Down
2 changes: 1 addition & 1 deletion views/partials/form/renderer/block_form.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
@foreach($fields as $field)
@if ($fields->forBlocks())
@php
$field->renderForBlocks = true;
$field->renderForBlocks();
@endphp
@endif
{!! $field->render() !!}
Expand Down

0 comments on commit cc173bd

Please sign in to comment.