Skip to content

Commit

Permalink
add clone button in block edior preview item
Browse files Browse the repository at this point in the history
  • Loading branch information
thingasd authored and haringsrob committed Oct 14, 2022
1 parent 75b732a commit 30ca715
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 3 deletions.
15 changes: 13 additions & 2 deletions frontend/js/components/blocks/BlockEditorModel.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { BLOCKS } from '@/store/mutations'
import { mapGetters, mapState } from 'vuex'

import ACTIONS from '@/store/actions'
import { BLOCKS } from '@/store/mutations'

export default {
props: {
block: {
Expand Down Expand Up @@ -75,6 +77,14 @@ export default {
index: this.blockIndex
})
},
cloneBlock () {
this.$store.dispatch(ACTIONS.DUPLICATE_BLOCK, {
editorName: this.editorName,
futureIndex: this.blockIndex + 1,
block: this.block,
id: Date.now() + Math.floor(Math.random() * 1000)
})
},
setBlockID () {
return Date.now() + Math.floor(Math.random() * 1000)
}
Expand All @@ -89,7 +99,8 @@ export default {
isActive: this.isActive,
remove: this.remove,
move: this.move,
duplicate: this.duplicate
duplicate: this.duplicate,
cloneBlock: this.cloneBlock
})
}
}
8 changes: 7 additions & 1 deletion frontend/js/components/editor/EditorPreview.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<a17-blockeditor-model :block="savedBlock"
:key="savedBlock.id"
:editor-name="editorName"
v-slot="{ block, isActive, blockIndex, move, remove, edit, unEdit }">
v-slot="{ block, isActive, blockIndex, move, remove, edit, unEdit, cloneBlock }">
<a17-editor-block-preview :ref="block.id"
:block="block"
:blockIndex="blockIndex"
Expand All @@ -28,6 +28,7 @@
@block:select="_selectBlock(edit, blockIndex)"
@block:unselect="_unselectBlock(unEdit, blockIndex)"
@block:move="move"
@block:clone="_cloneBlock(cloneBlock, blockIndex)"
@block:delete="_deleteBlock(remove)"
@scroll-to="scrollToActive"/>
</a17-blockeditor-model>
Expand Down Expand Up @@ -149,6 +150,11 @@
this.unSubscribe()
this.deleteBlock(fn)
},
_cloneBlock (fn, index) {
// Clone block and refresh preview
this.cloneBlock(fn)
this.getPreview(index + 1)
},
unSubscribe () {
if (!this._unSubscribeInternal) return
Expand Down
5 changes: 5 additions & 0 deletions frontend/js/components/editor/EditorPreviewBlockItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
</div>
<div class="editorPreview__header">
<a17-buttonbar variant="visible">
<button type="button"
@click="cloneBlock">
<span v-svg
symbol="add"></span>
</button>
<a17-dropdown v-if="blocksLength > 1"
class="f--small"
position="bottom-left"
Expand Down
4 changes: 4 additions & 0 deletions frontend/js/mixins/blockEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ export default {
moveBlock (index) {
this.$emit('block:move', index)
},
cloneBlock (fn) {
fn()
this.$emit('block:clone')
},
deleteBlock (fn) {
if (this.$root.$refs.warningContentEditor) {
this.$root.$refs.warningContentEditor.open(() => {
Expand Down
3 changes: 3 additions & 0 deletions frontend/js/mixins/blockEditorItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ export default {
moveBlock (index) {
this.$emit('block:move', index)
},
cloneBlock () {
this.$emit('block:clone')
},
toggleBlockDropdown () {
if (this.blocksLength > 1 && this.$refs.blockDropdown) {
this.$refs.blockDropdown.toggle()
Expand Down

0 comments on commit 30ca715

Please sign in to comment.