From c0ec527bde7837994c4cfea26da53fdc4dfc9184 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20D=C4=99bi=C5=84ski?= Date: Thu, 11 Mar 2021 08:47:21 +0100 Subject: [PATCH 1/4] EZP-31632: Floating table toolbar --- .../alloyeditor/src/toolbars/config/base-fixed.js | 3 ++- .../alloyeditor/src/toolbars/config/base-table.js | 9 +++++---- .../js/alloyeditor/src/toolbars/config/base.js | 15 ++++++++++++++- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/bundle/Resources/public/js/alloyeditor/src/toolbars/config/base-fixed.js b/src/bundle/Resources/public/js/alloyeditor/src/toolbars/config/base-fixed.js index aa9965e20a..8526561236 100644 --- a/src/bundle/Resources/public/js/alloyeditor/src/toolbars/config/base-fixed.js +++ b/src/bundle/Resources/public/js/alloyeditor/src/toolbars/config/base-fixed.js @@ -10,8 +10,9 @@ export default class EzConfgiFixedBase extends EzConfigBase { const editorRect = editor.element.getClientRect(); const toolbarHeight = toolbar ? toolbar.getBoundingClientRect().height : 0; const shouldBeFixed = editorRect.top - toolbarHeight - 2 * TOOLBAR_OFFSET < 0; + const header = document.querySelector('.ez-edit-header__content-type-name'); const top = shouldBeFixed - ? TOOLBAR_OFFSET + ? TOOLBAR_OFFSET + (header ? header.offsetHeight : 0) : editorRect.top + editor.element.getWindow().getScrollPosition().y - toolbarHeight - TOOLBAR_OFFSET; if (toolbar) { diff --git a/src/bundle/Resources/public/js/alloyeditor/src/toolbars/config/base-table.js b/src/bundle/Resources/public/js/alloyeditor/src/toolbars/config/base-table.js index 1441029047..965bd91176 100644 --- a/src/bundle/Resources/public/js/alloyeditor/src/toolbars/config/base-table.js +++ b/src/bundle/Resources/public/js/alloyeditor/src/toolbars/config/base-table.js @@ -1,6 +1,6 @@ import AlloyEditor from 'alloyeditor'; -export default class EzConfigTableBase { +export default class EzConfgiFixedBase { constructor(config) { this.name = this.getConfigName(); @@ -16,12 +16,13 @@ export default class EzConfigTableBase { 'eztableremove', ...config.extraButtons[this.name], ]; - - this.getArrowBoxClasses = AlloyEditor.SelectionGetArrowBoxClasses.table; - this.setPosition = AlloyEditor.SelectionSetPosition.table; } getConfigName() { return ''; } + + getArrowBoxClasses() { + return 'ae-toolbar-floating'; + } } diff --git a/src/bundle/Resources/public/js/alloyeditor/src/toolbars/config/base.js b/src/bundle/Resources/public/js/alloyeditor/src/toolbars/config/base.js index 1385954b82..03a642b78e 100644 --- a/src/bundle/Resources/public/js/alloyeditor/src/toolbars/config/base.js +++ b/src/bundle/Resources/public/js/alloyeditor/src/toolbars/config/base.js @@ -80,16 +80,29 @@ export default class EzConfigBase { const path = editor.elementPath(); let block = path.block; - if (!block || isWidgetElement) { + if (isWidgetElement) { const inlineCustomTag = path.elements.find((element) => element.$.dataset.ezelement === 'eztemplateinline'); block = inlineCustomTag || targetElement; } + if (!block ) { + block = path.lastElement; + } + if (block.is('li')) { block = block.getParent(); } + if (block.is('td') || block.is('th')) { + for (let parent of block.getParents()) { + if (parent.getName() === 'table') { + block = parent; + break; + } + } + } + return block; } From 680b1d491a31eebb6b5377caa9fb23d3754cbae4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20D=C4=99bi=C5=84ski?= Date: Thu, 11 Mar 2021 09:42:52 +0100 Subject: [PATCH 2/4] Extended EzConfigTableBase class --- .../js/alloyeditor/src/toolbars/config/base-table.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/bundle/Resources/public/js/alloyeditor/src/toolbars/config/base-table.js b/src/bundle/Resources/public/js/alloyeditor/src/toolbars/config/base-table.js index 965bd91176..7953c495c7 100644 --- a/src/bundle/Resources/public/js/alloyeditor/src/toolbars/config/base-table.js +++ b/src/bundle/Resources/public/js/alloyeditor/src/toolbars/config/base-table.js @@ -1,7 +1,10 @@ import AlloyEditor from 'alloyeditor'; +import EzConfgiFixedBase from './base-fixed'; -export default class EzConfgiFixedBase { +export default class EzConfigTableBase extends EzConfgiFixedBase { constructor(config) { + super(config); + this.name = this.getConfigName(); const editAttributesButton = config.attributes[this.name] || config.classes[this.name] ? `${this.name}edit` : ''; @@ -16,6 +19,9 @@ export default class EzConfgiFixedBase { 'eztableremove', ...config.extraButtons[this.name], ]; + + this.getArrowBoxClasses = AlloyEditor.SelectionGetArrowBoxClasses.table; + this.setPosition = AlloyEditor.SelectionSetPosition.table; } getConfigName() { From 05ea107f6739c1611ac72e0272410ecfe891fda4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20D=C4=99bi=C5=84ski?= Date: Thu, 11 Mar 2021 09:49:45 +0100 Subject: [PATCH 3/4] Removed variables --- .../public/js/alloyeditor/src/toolbars/config/base-table.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/bundle/Resources/public/js/alloyeditor/src/toolbars/config/base-table.js b/src/bundle/Resources/public/js/alloyeditor/src/toolbars/config/base-table.js index 7953c495c7..942ab5121f 100644 --- a/src/bundle/Resources/public/js/alloyeditor/src/toolbars/config/base-table.js +++ b/src/bundle/Resources/public/js/alloyeditor/src/toolbars/config/base-table.js @@ -19,9 +19,6 @@ export default class EzConfigTableBase extends EzConfgiFixedBase { 'eztableremove', ...config.extraButtons[this.name], ]; - - this.getArrowBoxClasses = AlloyEditor.SelectionGetArrowBoxClasses.table; - this.setPosition = AlloyEditor.SelectionSetPosition.table; } getConfigName() { From 566052ac6d274a4a01c3fee3a4d765d4406b7091 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20D=C4=99bi=C5=84ski?= Date: Thu, 11 Mar 2021 09:53:56 +0100 Subject: [PATCH 4/4] removed unused import --- .../public/js/alloyeditor/src/toolbars/config/base-table.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/bundle/Resources/public/js/alloyeditor/src/toolbars/config/base-table.js b/src/bundle/Resources/public/js/alloyeditor/src/toolbars/config/base-table.js index 942ab5121f..5ba1a659b8 100644 --- a/src/bundle/Resources/public/js/alloyeditor/src/toolbars/config/base-table.js +++ b/src/bundle/Resources/public/js/alloyeditor/src/toolbars/config/base-table.js @@ -1,4 +1,3 @@ -import AlloyEditor from 'alloyeditor'; import EzConfgiFixedBase from './base-fixed'; export default class EzConfigTableBase extends EzConfgiFixedBase {