From b7631364ec8bba4013e9b6bc7d67975251d8aed8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1vid=20Malich?= Date: Wed, 1 Nov 2023 04:19:25 +0100 Subject: [PATCH] Added tablet preview and categories for blocks --- public/editor.js | 2 +- resources/js/editor.js | 1 + resources/views/editor.blade.php | 63 ++++++++++++++++++++++++-------- src/Blocks/Block.php | 8 ++++ 4 files changed, 57 insertions(+), 17 deletions(-) diff --git a/public/editor.js b/public/editor.js index 69d2810..b81c53c 100644 --- a/public/editor.js +++ b/public/editor.js @@ -1 +1 @@ -(()=>{var e,t={950:()=>{function e(e){return function(e){if(Array.isArray(e))return t(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||function(e,r){if(!e)return;if("string"==typeof e)return t(e,r);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return t(e,r)}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function t(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r=n&&e.clientY<=a,l=e.clientY>=i&&e.clientY<=o;return s?"before":!!l&&"after"},component:function(){return Livewire.find(frame.closest("[wire\\:id]").getAttribute("wire:id"))},undo:function(e,t){!e.ctrlKey&&!e.metaKey||e.shiftKey||"z"!==e.key||(e.preventDefault(),-1!=navigator.userAgent.indexOf("Safari")&&-1==navigator.userAgent.indexOf("Chrome")&&window.history.forward(),t.component().call("undo"))},redo:function(e,t){(e.ctrlKey||e.metaKey)&&e.shiftKey&&"z"===e.key&&(e.preventDefault(),-1!=navigator.userAgent.indexOf("Safari")&&-1==navigator.userAgent.indexOf("Chrome")&&window.history.forward(),t.component().call("redo"))}}}},611:()=>{}},r={};function n(e){var a=r[e];if(void 0!==a)return a.exports;var i=r[e]={exports:{}};return t[e](i,i.exports,n),i.exports}n.m=t,e=[],n.O=(t,r,a,i)=>{if(!r){var o=1/0;for(d=0;d=i)&&Object.keys(n.O).every((e=>n.O[e](r[l])))?r.splice(l--,1):(s=!1,i0&&e[d-1][2]>i;d--)e[d]=e[d-1];e[d]=[r,a,i]},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),(()=>{var e={192:0,982:0};n.O.j=t=>0===e[t];var t=(t,r)=>{var a,i,[o,s,l]=r,c=0;if(o.some((t=>0!==e[t]))){for(a in s)n.o(s,a)&&(n.m[a]=s[a]);if(l)var d=l(n)}for(t&&t(r);cn(950)));var a=n.O(void 0,[982],(()=>n(611)));a=n.O(a)})(); \ No newline at end of file +(()=>{var e,t={950:()=>{function e(e){return function(e){if(Array.isArray(e))return t(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||function(e,r){if(!e)return;if("string"==typeof e)return t(e,r);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return t(e,r)}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function t(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r=n&&e.clientY<=a,l=e.clientY>=i&&e.clientY<=o;return s?"before":!!l&&"after"},component:function(){return Livewire.find(frame.closest("[wire\\:id]").getAttribute("wire:id"))},undo:function(e,t){!e.ctrlKey&&!e.metaKey||e.shiftKey||"z"!==e.key||(e.preventDefault(),-1!=navigator.userAgent.indexOf("Safari")&&-1==navigator.userAgent.indexOf("Chrome")&&window.history.forward(),t.component().call("undo"))},redo:function(e,t){(e.ctrlKey||e.metaKey)&&e.shiftKey&&"z"===e.key&&(e.preventDefault(),-1!=navigator.userAgent.indexOf("Safari")&&-1==navigator.userAgent.indexOf("Chrome")&&window.history.forward(),t.component().call("redo"))}}}},611:()=>{}},r={};function n(e){var a=r[e];if(void 0!==a)return a.exports;var i=r[e]={exports:{}};return t[e](i,i.exports,n),i.exports}n.m=t,e=[],n.O=(t,r,a,i)=>{if(!r){var o=1/0;for(d=0;d=i)&&Object.keys(n.O).every((e=>n.O[e](r[l])))?r.splice(l--,1):(s=!1,i0&&e[d-1][2]>i;d--)e[d]=e[d-1];e[d]=[r,a,i]},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),(()=>{var e={192:0,982:0};n.O.j=t=>0===e[t];var t=(t,r)=>{var a,i,[o,s,l]=r,c=0;if(o.some((t=>0!==e[t]))){for(a in s)n.o(s,a)&&(n.m[a]=s[a]);if(l)var d=l(n)}for(t&&t(r);cn(950)));var a=n.O(void 0,[982],(()=>n(611)));a=n.O(a)})(); diff --git a/resources/js/editor.js b/resources/js/editor.js index e6eec28..b6a98fa 100644 --- a/resources/js/editor.js +++ b/resources/js/editor.js @@ -7,6 +7,7 @@ window.dropblockeditor = (config) => { insert: false, mobile: false, + tablet: false, lastTopPos: 0, diff --git a/resources/views/editor.blade.php b/resources/views/editor.blade.php index 6fc0518..5cca3d2 100644 --- a/resources/views/editor.blade.php +++ b/resources/views/editor.blade.php @@ -9,7 +9,8 @@
@@ -43,15 +44,24 @@ class="dropblockeditor flex flex-col min-h-screen bg-gray-100">
- +
- - + +
@else -
- @foreach(collect($blocks)->map(function($block) { - return $this->getBlockFromClassName($block['class']); - }) as $i => $block) -
- @if($block->getIcon()) -
{!! $block->getIcon() !!}
- @endif +
+ @php + $blockGroups = collect($blocks)->map(function($block, $i) { + return [ + 'original_index' => $i, + 'block' => $this->getBlockFromClassName($block['class']), + ]; + })->groupBy(function($item) { + return $item['block']->getCategory(); + }); + @endphp - {{ $block->getTitle() }} + @foreach($blockGroups as $category => $categoryBlocks) +
+

{{ $category }}

+
+ @foreach($categoryBlocks as $groupedBlock) + @php + $i = $groupedBlock['original_index']; // Retrieve the original index + $block = $groupedBlock['block']; + @endphp - - - +
+ @if($block->getIcon()) +
{!! $block->getIcon() !!}
+ @endif + + {{ $block->getTitle() }} + + + + +
+ @endforeach +
@endforeach
diff --git a/src/Blocks/Block.php b/src/Blocks/Block.php index 9cccaf0..074bd2a 100644 --- a/src/Blocks/Block.php +++ b/src/Blocks/Block.php @@ -12,6 +12,8 @@ abstract class Block public $blockEditComponent; + public $category = 'Example Category'; + public $data = []; abstract public function render(); @@ -26,6 +28,11 @@ public function getTitle() return $this->title; } + public function getCategory() + { + return $this->category; + } + public function getData() { return $this->data; @@ -57,6 +64,7 @@ public function toArray() return [ 'data' => $this->data, 'class' => get_class($this), + 'category' => $this->category, ]; } }