Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/4.6'
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasOsti committed Dec 5, 2024
2 parents c268ebf + f6b1f85 commit 597beec
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import clickOutsideHandler from '@ckeditor/ckeditor5-ui/src/bindings/clickoutsid

import IbexaCustomAttributesFormView from './ui/custom-attributes-form-view';
import IbexaButtonView from '../common/button-view/button-view';
import { setPanelContentMaxHeight } from '../helpers/custom-panel-helper';

import { getCustomAttributesElementConfig, getCustomClassesElementConfig } from './helpers/config-helper';

Expand All @@ -16,6 +17,15 @@ class IbexaAttributesUI extends Plugin {
this.formView = this.createFormView();

this.showForm = this.showForm.bind(this);

let timeoutId = null;

this.listenTo(this.balloon.view, 'change:top', () => {
clearTimeout(timeoutId);
timeoutId = setTimeout(() => {
setPanelContentMaxHeight(this.balloon.view);
}, 0);
});
}

getModelElement() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ class IbexaCustomAttributesFormView extends View {
this.setTemplate({
tag: 'div',
attributes: {
class: 'ibexa-ckeditor-balloon-form',
class: 'ibexa-ckeditor-balloon-form ibexa-custom-panel',
},
children: [
{
tag: 'div',
attributes: {
class: 'ibexa-ckeditor-balloon-form__header',
class: 'ibexa-ckeditor-balloon-form__header ibexa-custom-panel__header',
},
children: ['Custom Attributes'],
},
Expand All @@ -63,14 +63,14 @@ class IbexaCustomAttributesFormView extends View {
{
tag: 'div',
attributes: {
class: 'ibexa-ckeditor-balloon-form__fields',
class: 'ibexa-ckeditor-balloon-form__fields ibexa-custom-panel__content ibexa-custom-panel__content--overflow-with-scroll',
},
children: this.children,
},
{
tag: 'div',
attributes: {
class: 'ibexa-ckeditor-balloon-form__actions',
class: 'ibexa-ckeditor-balloon-form__actions ibexa-custom-panel__footer',
},
children: [this.saveButtonView, this.revertButtonView, this.cancelButtonView],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
import clickOutsideHandler from '@ckeditor/ckeditor5-ui/src/bindings/clickoutsidehandler';
import ClickObserver from '@ckeditor/ckeditor5-engine/src/view/observer/clickobserver';

import { setPanelContentMaxHeight } from '../helpers/panel-helper';
import { setPanelContentMaxHeight } from '../../helpers/custom-panel-helper';
import IbexaCustomTagFormView from '../ui/custom-tag-form-view';
import IbexaCustomTagAttributesView from '../ui/custom-tag-attributes-view';
import IbexaButtonView from '../../common/button-view/button-view';
Expand All @@ -19,6 +19,7 @@ class IbexaCustomTagUI extends Plugin {
this.addCustomTag = this.addCustomTag.bind(this);

this.isNew = false;
this.activeModelElement = null;

let timeoutId = null;
this.listenTo(this.balloon.view, 'change:top', () => {
Expand Down Expand Up @@ -95,8 +96,7 @@ class IbexaCustomTagUI extends Plugin {
const formView = new IbexaCustomTagFormView({ locale: this.editor.locale });

this.listenTo(formView, 'save-custom-tag', () => {
const modelElement = this.editor.model.document.selection.getSelectedElement();
const values = modelElement.getAttribute('values');
const values = this.activeModelElement.getAttribute('values');
const newValues = { ...values };

this.isNew = false;
Expand All @@ -112,7 +112,7 @@ class IbexaCustomTagUI extends Plugin {
});

this.editor.model.change((writer) => {
writer.setAttribute('values', newValues, modelElement);
writer.setAttribute('values', newValues, this.activeModelElement);
});

this.reinitAttributesView();
Expand Down Expand Up @@ -151,8 +151,9 @@ class IbexaCustomTagUI extends Plugin {
}

showForm() {
const modelElement = this.editor.model.document.selection.getSelectedElement();
const values = modelElement.getAttribute('values');
this.activeModelElement = this.editor.model.document.selection.getSelectedElement();

const values = this.activeModelElement.getAttribute('values');
const parsedValues = Object.entries(values).reduce((output, [key, value]) => {
if (this.config.attributes[key]?.type === 'boolean') {
return {
Expand Down Expand Up @@ -189,14 +190,14 @@ class IbexaCustomTagUI extends Plugin {
}

removeCustomTag() {
const modelElement = this.editor.model.document.selection.getSelectedElement();

this.editor.model.change((writer) => {
if (this.balloon.hasView(this.attributesView)) {
this.hideAttributes();
}

writer.remove(modelElement);
writer.remove(this.activeModelElement);

this.activeModelElement = null;
});
}

Expand All @@ -209,13 +210,16 @@ class IbexaCustomTagUI extends Plugin {
}

addCustomTag() {
if (this.balloon.hasView(this.formView)) {
return;
}

const values = Object.entries(this.config.attributes).reduce((outputValues, [attributeName, config]) => {
outputValues[attributeName] = config.defaultValue;

return outputValues;
}, {});

this.editor.focus();
this.editor.execute('insertIbexaCustomTag', { customTagName: this.componentName, values });

if (this.hasAttributes()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class IbexaCustomTagAttributesView extends View {
{
tag: 'div',
attributes: {
class: 'ibexa-custom-tag-attributes__header ibexa-custom-tag-panel-header',
class: 'ibexa-custom-tag-attributes__header ibexa-custom-panel__header',
},
children: [
{
Expand Down Expand Up @@ -91,7 +91,7 @@ class IbexaCustomTagAttributesView extends View {
children.push({
tag: 'div',
attributes: {
class: 'ibexa-custom-tag-attributes__items ibexa-custom-tag-panel-content',
class: 'ibexa-custom-tag-attributes__items ibexa-custom-panel__content',
},
children: items,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,13 @@ class IbexaCustomTagFormView extends View {
this.setTemplate({
tag: 'div',
attributes: {
class: 'ibexa-ckeditor-balloon-form',
class: 'ibexa-ckeditor-balloon-form ibexa-custom-panel',
},
children: [
{
tag: 'div',
attributes: {
class: 'ibexa-ckeditor-balloon-form__header ibexa-custom-tag-panel-header',
class: 'ibexa-ckeditor-balloon-form__header ibexa-custom-panel__header',
},
children: [label],
},
Expand All @@ -134,14 +134,14 @@ class IbexaCustomTagFormView extends View {
{
tag: 'div',
attributes: {
class: 'ibexa-ckeditor-balloon-form__fields ibexa-custom-tag-panel-content',
class: 'ibexa-ckeditor-balloon-form__fields ibexa-custom-panel__content ibexa-custom-panel__content--overflow-with-scroll',
},
children: this.children,
},
{
tag: 'div',
attributes: {
class: 'ibexa-ckeditor-balloon-form__actions ibexa-custom-tag-panel-footer',
class: 'ibexa-ckeditor-balloon-form__actions ibexa-custom-panel__footer',
},
children: [this.saveButtonView, this.cancelButtonView],
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
const setPanelContentMaxHeight = (balloonView) => {
const MIN_HEIGHT_VALUE = 100;
const MARGIN = 50;
const BOTTOM_ARROW_CLASSES = ['ck-balloon-panel_arrow_s', 'ck-balloon-panel_arrow_se', 'ck-balloon-panel_arrow_sw'];
const { innerHeight: windowHeight } = window;
const { element: panelNode } = balloonView;
const panelHeader = panelNode.querySelector('.ibexa-custom-tag-panel-header');
const panelContent = panelNode.querySelector('.ibexa-custom-tag-panel-content');
const panelFooter = panelNode.querySelector('.ibexa-custom-tag-panel-footer');
const panelHeader = panelNode.querySelector('.ibexa-custom-panel__header');
const panelContent = panelNode.querySelector('.ibexa-custom-panel__content');
const panelFooter = panelNode.querySelector('.ibexa-custom-panel__footer');

if (!panelContent) {
return;
}

const isBalloonAbovePivot = panelNode.classList.contains('ck-balloon-panel_arrow_s');
const isBalloonAbovePivot = [...panelNode.classList].some((className) => BOTTOM_ARROW_CLASSES.includes(className));
const panelInitialHeight = panelNode.offsetHeight;
const panelTopPosition = parseInt(panelNode.style.top, 10);
const panelHeaderHeight = panelHeader?.offsetHeight ?? 0;
Expand Down
1 change: 0 additions & 1 deletion src/bundle/Resources/public/scss/_balloon-form.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
}

&__fields {
overflow: auto;
padding: calculateRem(8px) calculateRem(16px);

&--attributes {
Expand Down
41 changes: 41 additions & 0 deletions src/bundle/Resources/public/scss/_custom-panel.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
.ibexa-custom-panel {
min-width: calculateRem(320px);

&__content {
&--overflow-with-scroll {
overflow: auto;

&.ibexa-ckeditor-balloon-form__fields {
.ck.ck-labeled-field-view {
.ck.ck-input {
width: 100%;
}

.ck.ck-dropdown {
width: 100%;

.ck.ck-button {
display: block;

.ck.ck-button__label {
width: calc(100% - calculateRem(20px));
height: fit-content;
white-space: normal;
overflow: hidden;
}
}
}

.ck-dropdown__panel-visible {
position: static;
bottom: 0;
height: fit-content;
max-height: 100%;
border: none;
box-shadow: none;
}
}
}
}
}
}
1 change: 1 addition & 0 deletions src/bundle/Resources/public/scss/ckeditor.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
@import 'general';
@import 'custom-tag';
@import 'custom-tag-attributes';
@import 'custom-panel';
@import 'elements-path';
@import 'tools';
@import 'character-counter';
Expand Down

0 comments on commit 597beec

Please sign in to comment.