Skip to content

Commit 41a8103

Browse files
committed
Fix availableBlocks override eachother
1 parent df08d1a commit 41a8103

File tree

7 files changed

+20
-11
lines changed

7 files changed

+20
-11
lines changed

frontend/js/components/blocks/Blocks.vue

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<a17-blocks-list :editor-name="editorName" v-slot="{ savedBlocks, availableBlocks, moveBlock, moveBlockToEditor, cloneBlock }">
2+
<a17-blocks-list :editor-name="editorName" :availability-id="availabilityId" v-slot="{ savedBlocks, availableBlocks, moveBlock, moveBlockToEditor, cloneBlock }">
33
<div class="blocks">
44
<draggable class="blocks__container"
55
:value="savedBlocks"
@@ -163,6 +163,9 @@
163163
editorName: {
164164
type: String,
165165
required: true
166+
},
167+
availabilityId: {
168+
type: String,
166169
}
167170
},
168171
data () {
@@ -179,9 +182,8 @@
179182
}),
180183
...mapGetters([
181184
'blocks',
182-
'fieldsByBlockId',
183185
'availableBlocks'
184-
])
186+
]),
185187
},
186188
methods: {
187189
setOpened: function () {
@@ -265,7 +267,7 @@
265267
}
266268
},
267269
checkIfBlockTypeIsAvailable (editorName, type) {
268-
const availableBlocks = JSON.parse(JSON.stringify(this.availableBlocks(editorName)))
270+
const availableBlocks = this.availableBlocks(editorName)
269271
const blockTypes = availableBlocks.map(block => block.component)
270272
271273
return blockTypes.indexOf(type) !== -1

frontend/js/components/blocks/BlocksList.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@ export default {
88
editorName: {
99
type: String,
1010
required: true
11+
},
12+
availabilityId: {
13+
type: String,
1114
}
1215
},
1316
computed: {
1417
availableBlocks () {
15-
const splitted = this.editorName.split('|')
16-
const editorName = splitted[splitted.length - 1]
17-
return this.getAvailableBlocks(editorName)
18+
return this.getAvailableBlocks(this.availabilityId ? this.availabilityId : this.editorName.split('|').pop())
1819
},
1920
savedBlocks () {
2021
return this.blocks(this.editorName)

src/Services/Forms/InlineRepeater.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ public function render(): View
203203
$repeater->max($this->max);
204204
}
205205

206-
$repeater->renderForBlocks = $this->renderForBlocks ?? false;
206+
$repeater->renderForBlocks($this->renderForBlocks ?? false);
207207
return $repeater->render();
208208
}
209209

src/View/Components/Fields/BlockEditor.php

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public function render(): View
5454
'value' => $this->name,
5555
'nested' => $this->renderForBlocks,
5656
],
57+
'availabilityId' => uniqid($this->name . '-')
5758
])
5859
);
5960
}

src/View/Components/Fields/TwillFormComponent.php

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace A17\Twill\View\Components\Fields;
44

5+
use A17\Twill\Services\Forms\Traits\RenderForBlocks;
56
use Illuminate\Contracts\View\View;
67
use Illuminate\Database\Eloquent\Model;
78
use Illuminate\Support\Facades\View as ViewFacade;
@@ -13,6 +14,8 @@
1314
*/
1415
abstract class TwillFormComponent extends Component
1516
{
17+
use RenderForBlocks;
18+
1619
public ?Model $item;
1720

1821
public array $form_fields;

views/partials/form/_block_editor.blade.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
@endunless
44

55
<a17-blocks title="{{ $label }}"
6+
availability-id="{{ $availabilityId }}"
67
@if ($renderForBlocks) :editor-name="nestedEditorName('{{ $name }}')" @else editor-name="{{ $name }}" @endif
7-
trigger="{{ $trigger }}" :is-settings="{{ (bool) $isSettings ? 'true' : 'false' }}">
8+
9+
trigger="{{ $trigger }}" :is-settings="{{ $isSettings ? 'true' : 'false' }}">
810
</a17-blocks>
911

1012
@push('vuexStore')
11-
window['{{ config('twill.js_namespace') }}'].STORE.form.availableBlocks['{{ $name }}'] =
13+
window['{{ config('twill.js_namespace') }}'].STORE.form.availableBlocks['{{ $availabilityId }}'] =
1214
{!! json_encode(array_values($allowedBlocks)) !!}
1315
window['{{ config('twill.js_namespace') }}'].STORE.form.editorNames.push({!! json_encode($editorName) !!})
1416
@endpush

views/partials/form/renderer/block_form.blade.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
@foreach($fields as $field)
33
@if ($fields->forBlocks())
44
@php
5-
$field->renderForBlocks = true;
5+
$field->renderForBlocks();
66
@endphp
77
@endif
88
{!! $field->render() !!}

0 commit comments

Comments
 (0)