@ckeditor/ckeditor5-table 45.0.0-alpha.6 → 45.0.0-alpha.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ckeditor/ckeditor5-table",
3
- "version": "45.0.0-alpha.6",
3
+ "version": "45.0.0-alpha.7",
4
4
  "description": "Table feature for CKEditor 5.",
5
5
  "keywords": [
6
6
  "ckeditor",
@@ -13,14 +13,14 @@
13
13
  "type": "module",
14
14
  "main": "src/index.js",
15
15
  "dependencies": {
16
- "ckeditor5": "45.0.0-alpha.6",
17
- "@ckeditor/ckeditor5-clipboard": "45.0.0-alpha.6",
18
- "@ckeditor/ckeditor5-core": "45.0.0-alpha.6",
19
- "@ckeditor/ckeditor5-engine": "45.0.0-alpha.6",
20
- "@ckeditor/ckeditor5-icons": "45.0.0-alpha.6",
21
- "@ckeditor/ckeditor5-ui": "45.0.0-alpha.6",
22
- "@ckeditor/ckeditor5-utils": "45.0.0-alpha.6",
23
- "@ckeditor/ckeditor5-widget": "45.0.0-alpha.6",
16
+ "ckeditor5": "45.0.0-alpha.7",
17
+ "@ckeditor/ckeditor5-clipboard": "45.0.0-alpha.7",
18
+ "@ckeditor/ckeditor5-core": "45.0.0-alpha.7",
19
+ "@ckeditor/ckeditor5-engine": "45.0.0-alpha.7",
20
+ "@ckeditor/ckeditor5-icons": "45.0.0-alpha.7",
21
+ "@ckeditor/ckeditor5-ui": "45.0.0-alpha.7",
22
+ "@ckeditor/ckeditor5-utils": "45.0.0-alpha.7",
23
+ "@ckeditor/ckeditor5-widget": "45.0.0-alpha.7",
24
24
  "es-toolkit": "1.32.0"
25
25
  },
26
26
  "author": "CKSource (http://cksource.com/)",
@@ -104,6 +104,34 @@ export default class TableColumnResizeEditing extends Plugin {
104
104
  * Registers listeners to handle resizing process.
105
105
  */
106
106
  private _registerResizingListeners;
107
+ /**
108
+ * Calculate and set `top` and `bottom` styles to the column resizer element to fit the height of the table.
109
+ *
110
+ * @param viewResizer The column resizer element.
111
+ */
112
+ private _recalculateResizerElement;
113
+ /**
114
+ * Remove `top` and `bottom` styles of the column resizer element.
115
+ *
116
+ * @param viewResizer The column resizer element.
117
+ */
118
+ private _resetResizerStyles;
119
+ /**
120
+ * Handles the `mouseover` event on column resizer element.
121
+ * Recalculates the `top` and `bottom` styles of the column resizer element to fit the height of the table.
122
+ *
123
+ * @param eventInfo An object containing information about the fired event.
124
+ * @param domEventData The data related to the DOM event.
125
+ */
126
+ private _onMouseOverHandler;
127
+ /**
128
+ * Handles the `mouseout` event on column resizer element.
129
+ * When resizing is not active, it resets the `top` and `bottom` styles of the column resizer element.
130
+ *
131
+ * @param eventInfo An object containing information about the fired event.
132
+ * @param domEventData The data related to the DOM event.
133
+ */
134
+ private _onMouseOutHandler;
107
135
  /**
108
136
  * Handles the `mousedown` event on column resizer element:
109
137
  * * calculates the initial column pixel widths,
@@ -6,7 +6,7 @@
6
6
  * @module table/tablecolumnresize/tablecolumnresizeediting
7
7
  */
8
8
  import { throttle, isEqual } from 'es-toolkit/compat';
9
- import { global, DomEmitterMixin } from 'ckeditor5/src/utils.js';
9
+ import { global, DomEmitterMixin, Rect, toUnit } from 'ckeditor5/src/utils.js';
10
10
  import { Plugin } from 'ckeditor5/src/core.js';
11
11
  import MouseEventsObserver from '../../src/tablemouse/mouseeventsobserver.js';
12
12
  import TableEditing from '../tableediting.js';
@@ -16,6 +16,7 @@ import TableWidthsCommand from './tablewidthscommand.js';
16
16
  import { downcastTableResizedClass, upcastColgroupElement } from './converters.js';
17
17
  import { clamp, createFilledArray, sumArray, getColumnEdgesIndexes, getChangedResizedTables, getColumnMinWidthAsPercentage, getElementWidthInPixels, getTableWidthInPixels, normalizeColumnWidths, toPrecision, getDomCellOuterWidth, updateColumnElements, getColumnGroupElement, getTableColumnElements, getTableColumnsWidths } from './utils.js';
18
18
  import { COLUMN_MIN_WIDTH_IN_PIXELS, COLUMN_RESIZE_DISTANCE_THRESHOLD } from './constants.js';
19
+ const toPx = /* #__PURE__ */ toUnit('px');
19
20
  /**
20
21
  * The table column resize editing plugin.
21
22
  */
@@ -326,10 +327,83 @@ export default class TableColumnResizeEditing extends Plugin {
326
327
  _registerResizingListeners() {
327
328
  const editingView = this.editor.editing.view;
328
329
  editingView.addObserver(MouseEventsObserver);
330
+ editingView.document.on('mouseover', this._onMouseOverHandler.bind(this), { priority: 'high' });
329
331
  editingView.document.on('mousedown', this._onMouseDownHandler.bind(this), { priority: 'high' });
332
+ editingView.document.on('mouseout', this._onMouseOutHandler.bind(this), { priority: 'high' });
330
333
  this._domEmitter.listenTo(global.window.document, 'mousemove', throttle(this._onMouseMoveHandler.bind(this), 50));
331
334
  this._domEmitter.listenTo(global.window.document, 'mouseup', this._onMouseUpHandler.bind(this));
332
335
  }
336
+ /**
337
+ * Calculate and set `top` and `bottom` styles to the column resizer element to fit the height of the table.
338
+ *
339
+ * @param viewResizer The column resizer element.
340
+ */
341
+ _recalculateResizerElement(viewResizer) {
342
+ const editor = this.editor;
343
+ const domConverter = editor.editing.view.domConverter;
344
+ // Get DOM target figure ancestor element.
345
+ const domTable = domConverter.mapViewToDom(viewResizer.findAncestor('table'));
346
+ // Get DOM table cell element.
347
+ const domCell = domConverter.mapViewToDom(viewResizer.findAncestor(item => ['td', 'th'].includes(item.name)));
348
+ const rectTable = new Rect(domTable);
349
+ const rectCell = new Rect(domCell);
350
+ // Calculate the top, and bottom positions of the column resizer element.
351
+ const targetTopPosition = toPx(Number((rectTable.top - rectCell.top).toFixed(4)));
352
+ const targetBottomPosition = toPx(Number((rectCell.bottom - rectTable.bottom).toFixed(4)));
353
+ // Set `top` and `bottom` styles to the column resizer element.
354
+ editor.editing.view.change(viewWriter => {
355
+ viewWriter.setStyle('top', targetTopPosition, viewResizer);
356
+ viewWriter.setStyle('bottom', targetBottomPosition, viewResizer);
357
+ });
358
+ }
359
+ /**
360
+ * Remove `top` and `bottom` styles of the column resizer element.
361
+ *
362
+ * @param viewResizer The column resizer element.
363
+ */
364
+ _resetResizerStyles(viewResizer) {
365
+ this.editor.editing.view.change(viewWriter => {
366
+ viewWriter.removeStyle('top', viewResizer);
367
+ viewWriter.removeStyle('bottom', viewResizer);
368
+ });
369
+ }
370
+ /**
371
+ * Handles the `mouseover` event on column resizer element.
372
+ * Recalculates the `top` and `bottom` styles of the column resizer element to fit the height of the table.
373
+ *
374
+ * @param eventInfo An object containing information about the fired event.
375
+ * @param domEventData The data related to the DOM event.
376
+ */
377
+ _onMouseOverHandler(eventInfo, domEventData) {
378
+ const target = domEventData.target;
379
+ if (!target.hasClass('ck-table-column-resizer')) {
380
+ return;
381
+ }
382
+ if (!this._isResizingAllowed) {
383
+ return;
384
+ }
385
+ this._recalculateResizerElement(target);
386
+ }
387
+ /**
388
+ * Handles the `mouseout` event on column resizer element.
389
+ * When resizing is not active, it resets the `top` and `bottom` styles of the column resizer element.
390
+ *
391
+ * @param eventInfo An object containing information about the fired event.
392
+ * @param domEventData The data related to the DOM event.
393
+ */
394
+ _onMouseOutHandler(eventInfo, domEventData) {
395
+ const target = domEventData.target;
396
+ if (!target.hasClass('ck-table-column-resizer')) {
397
+ return;
398
+ }
399
+ if (!this._isResizingAllowed) {
400
+ return;
401
+ }
402
+ if (this._isResizingActive) {
403
+ return;
404
+ }
405
+ this._resetResizerStyles(target);
406
+ }
333
407
  /**
334
408
  * Handles the `mousedown` event on column resizer element:
335
409
  * * calculates the initial column pixel widths,
@@ -461,7 +535,7 @@ export default class TableColumnResizeEditing extends Plugin {
461
535
  this._onMouseUpHandler();
462
536
  return;
463
537
  }
464
- const { columnPosition, flags: { isRightEdge, isTableCentered, isLtrContent }, elements: { viewFigure, viewLeftColumn, viewRightColumn }, widths: { viewFigureParentWidth, tableWidth, leftColumnWidth, rightColumnWidth } } = this._resizingData;
538
+ const { columnPosition, flags: { isRightEdge, isTableCentered, isLtrContent }, elements: { viewFigure, viewLeftColumn, viewRightColumn, viewResizer }, widths: { viewFigureParentWidth, tableWidth, leftColumnWidth, rightColumnWidth } } = this._resizingData;
465
539
  const dxLowerBound = -leftColumnWidth + COLUMN_MIN_WIDTH_IN_PIXELS;
466
540
  const dxUpperBound = isRightEdge ?
467
541
  viewFigureParentWidth - tableWidth :
@@ -486,6 +560,7 @@ export default class TableColumnResizeEditing extends Plugin {
486
560
  writer.setStyle('width', `${rightColumnWidthAsPercentage}%`, viewRightColumn);
487
561
  }
488
562
  });
563
+ this._recalculateResizerElement(viewResizer);
489
564
  }
490
565
  /**
491
566
  * Handles the `mouseup` event.
@@ -556,6 +631,10 @@ export default class TableColumnResizeEditing extends Plugin {
556
631
  editingView.change(writer => {
557
632
  writer.removeClass('ck-table-column-resizer__active', viewResizer);
558
633
  });
634
+ const element = editingView.domConverter.mapViewToDom(viewResizer);
635
+ if (!element.matches(':hover')) {
636
+ this._resetResizerStyles(viewResizer);
637
+ }
559
638
  this._isResizingActive = false;
560
639
  this._resizingData = null;
561
640
  }
@@ -16,10 +16,6 @@
16
16
  table-layout: fixed;
17
17
  }
18
18
 
19
- .ck-content .table table {
20
- overflow: hidden;
21
- }
22
-
23
19
  .ck-content .table td,
24
20
  .ck-content .table th {
25
21
  /* To prevent text overflowing beyond its cell when columns are resized by resize handler
@@ -58,12 +54,6 @@
58
54
  .ck.ck-editor__editable .table .ck-table-column-resizer__active {
59
55
  background-color: var(--ck-color-selector-column-resizer-hover);
60
56
  opacity: 0.25;
61
- /* The resizer element resides in each cell so to occupy the entire height of the table, which is unknown from a CSS point of view,
62
- it is extended to an extremely high height. Even for screens with a very high pixel density, the resizer will fulfill its role as
63
- it should, i.e. for a screen of 476 ppi the total height of the resizer will take over 350 sheets of A4 format, which is totally
64
- unrealistic height for a single table. */
65
- top: -999999px;
66
- bottom: -999999px;
67
57
  }
68
58
 
69
59
  .ck.ck-editor__editable[dir=rtl] .table .ck-table-column-resizer {