Skip to content

Commit

Permalink
CKEditor: Fix for tables and default styles (#2815)
Browse files Browse the repository at this point in the history
  • Loading branch information
maurofmferrao authored Dec 16, 2024
1 parent 858fb5b commit 19c0abb
Show file tree
Hide file tree
Showing 81 changed files with 233 additions and 95 deletions.
90 changes: 89 additions & 1 deletion ui/src/helpers/form-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,7 @@ const formHelpers = function() {
$container.css('transform-origin', '0 0');
$container.css('word-wrap', 'inherit');
$container.css('line-height', 'normal');
$container.css('padding', '0');
$container
.css('outline-width', (CKEDITOR_OVERLAY_WIDTH / scale));

Expand All @@ -751,7 +752,9 @@ const formHelpers = function() {
scale: scale,
});

$container.find('p').css('margin', '0 0 16px');
$container.find('p')
.css('margin', '0 0 16px')
.css('margin-top', 0);
$container.show();
} else {
$('#cke_' + field + ' iframe').contents().find('head').append(
Expand Down Expand Up @@ -924,6 +927,15 @@ const formHelpers = function() {
});
}

// If we have a detached editor, we need to add a property
// to the main bar to help with CSS styling
$(
'.ck-editor-body-detached .ck-body-wrapper ' +
'.ck-balloon-panel > .ck-toolbar',
).each((_idx, el) => {
$(el).parent().attr('data-main-toolbar', 1);
});

return false;
});
});
Expand Down Expand Up @@ -1123,6 +1135,82 @@ const formHelpers = function() {
$sourceElement = $sourceElement.siblings('textarea');
}

// Add CKEditor default CSS to the content to match the editor
// Convert into temporary DOM element
const $tempObj = $('<div>' + data + '</div>');

// Inject necessary CSS
const setCSSDefaultRules = function(els, rules) {
$(els).each(function(_idx, el) {
const $el = $(el);

for (const rule in rules) {
if (Object.hasOwn(rules, rule)) {
const value = rules[rule];
const oldStyle = $el.attr('style');

$el.attr('style', `${rule}: ${value}; ${oldStyle}`);
}
}
});
};

// Tables
$tempObj.find('.table').each((_idx, table) => {
const $table = $(table);

setCSSDefaultRules(
$table,
{
margin: '0.9em auto',
display: 'table',
},
);

setCSSDefaultRules(
$table.find('.ck-table-resized'),
{
'table-layout': 'fixed',
},
);

setCSSDefaultRules(
$table.find('table'),
{
overflow: 'hidden',
'border-collapse': 'collapse',
'border-spacing': '0',
width: '100%',
height: '100%',
border: '1px double hsl(0, 0%, 70%)',
},
);

setCSSDefaultRules(
$table.find('td, th'),
{
'text-align': 'left',
'overflow-wrap': 'break-word',
position: 'relative',
'min-width': '2em',
padding: '.4em',
border: '1px solid hsl(0, 0%, 75%)',
},
);

setCSSDefaultRules(
$table.find('th'),
{
'font-weight': 'bold',
'background-color': 'hsla(0, 0%, 0%, 5%)',
},
);
});

// Save object back to data string
// and inhect necessary CSS
data = $tempObj.html();

$sourceElement.val(data);

// If we're not saving, trigger change for saving
Expand Down
25 changes: 23 additions & 2 deletions ui/src/style/forms.scss
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,32 @@
z-index: calc($properties-panel-rich-text-container-z-index + 1) !important;
}

.ck-editor-body-detached .ck-body-wrapper .ck-balloon-panel.ck-toolbar-container {
.ck-editor-body-detached .ck-body-wrapper .ck-balloon-panel[data-main-toolbar] {
z-index: calc($properties-panel-rich-text-container-z-index + 2) !important;
right: 150px !important;
left: auto !important;
top: 66px ! important;
top: auto !important;
bottom: calc(100vh - 100px) !important;
width: calc(100vw - 300px) !important;
display: block;

&::before, &:after {
display: none;
}
}

.ck-editor-body-detached .ck-body-wrapper .ck-balloon-panel:not(.ck-powered-by-balloon):not([data-main-toolbar]) {
top: 148px !important;
left: 160px !important;
opacity: 0.95;
}

.ck-editor-body-detached .ck-body-wrapper .ck-balloon-panel.ck-powered-by-balloon {
top: auto !important;
left: auto !important;
bottom: 16px !important;
right: 16px !important;
display: block;
}

.rich-text-main-container {
Expand Down
4 changes: 4 additions & 0 deletions ui/src/vendor/ckeditor/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Changelog
=========

All changes in the package are documented in https://github.com/ckeditor/ckeditor5/blob/master/CHANGELOG.md.
4 changes: 4 additions & 0 deletions ui/src/vendor/ckeditor/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Contributing
========================================

See the [official contributors' guide to CKEditor&nbsp;5](https://ckeditor.com/docs/ckeditor5/latest/framework/contributing/contributing.html) to learn more.
4 changes: 2 additions & 2 deletions ui/src/vendor/ckeditor/build/ckeditor.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion ui/src/vendor/ckeditor/build/ckeditor.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion ui/src/vendor/ckeditor/build/translations/af.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion ui/src/vendor/ckeditor/build/translations/ar.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion ui/src/vendor/ckeditor/build/translations/ast.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion ui/src/vendor/ckeditor/build/translations/az.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion ui/src/vendor/ckeditor/build/translations/bg.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion ui/src/vendor/ckeditor/build/translations/bn.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion ui/src/vendor/ckeditor/build/translations/bs.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion ui/src/vendor/ckeditor/build/translations/ca.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion ui/src/vendor/ckeditor/build/translations/cs.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion ui/src/vendor/ckeditor/build/translations/da.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion ui/src/vendor/ckeditor/build/translations/de-ch.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion ui/src/vendor/ckeditor/build/translations/de.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion ui/src/vendor/ckeditor/build/translations/el.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion ui/src/vendor/ckeditor/build/translations/en-au.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion ui/src/vendor/ckeditor/build/translations/en-gb.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion ui/src/vendor/ckeditor/build/translations/eo.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion ui/src/vendor/ckeditor/build/translations/es-co.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion ui/src/vendor/ckeditor/build/translations/es.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion ui/src/vendor/ckeditor/build/translations/et.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion ui/src/vendor/ckeditor/build/translations/eu.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion ui/src/vendor/ckeditor/build/translations/fa.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion ui/src/vendor/ckeditor/build/translations/fi.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion ui/src/vendor/ckeditor/build/translations/fr.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion ui/src/vendor/ckeditor/build/translations/gl.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion ui/src/vendor/ckeditor/build/translations/gu.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion ui/src/vendor/ckeditor/build/translations/he.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion ui/src/vendor/ckeditor/build/translations/hi.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion ui/src/vendor/ckeditor/build/translations/hr.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion ui/src/vendor/ckeditor/build/translations/hu.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion ui/src/vendor/ckeditor/build/translations/hy.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion ui/src/vendor/ckeditor/build/translations/id.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion ui/src/vendor/ckeditor/build/translations/it.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion ui/src/vendor/ckeditor/build/translations/ja.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion ui/src/vendor/ckeditor/build/translations/jv.js

Large diffs are not rendered by default.

Loading

0 comments on commit 19c0abb

Please sign in to comment.