@ckeditor/ckeditor5-widget 0.0.0-nightly-20240415.0 → 0.0.0-nightly-20240416.0

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.

Potentially problematic release.


This version of @ckeditor/ckeditor5-widget might be problematic. Click here for more details.

package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ckeditor/ckeditor5-widget",
3
- "version": "0.0.0-nightly-20240415.0",
3
+ "version": "0.0.0-nightly-20240416.0",
4
4
  "description": "Widget API for CKEditor 5.",
5
5
  "keywords": [
6
6
  "ckeditor",
@@ -12,12 +12,12 @@
12
12
  "type": "module",
13
13
  "main": "src/index.js",
14
14
  "dependencies": {
15
- "@ckeditor/ckeditor5-core": "0.0.0-nightly-20240415.0",
16
- "@ckeditor/ckeditor5-engine": "0.0.0-nightly-20240415.0",
17
- "@ckeditor/ckeditor5-enter": "0.0.0-nightly-20240415.0",
18
- "@ckeditor/ckeditor5-ui": "0.0.0-nightly-20240415.0",
19
- "@ckeditor/ckeditor5-utils": "0.0.0-nightly-20240415.0",
20
- "@ckeditor/ckeditor5-typing": "0.0.0-nightly-20240415.0",
15
+ "@ckeditor/ckeditor5-core": "0.0.0-nightly-20240416.0",
16
+ "@ckeditor/ckeditor5-engine": "0.0.0-nightly-20240416.0",
17
+ "@ckeditor/ckeditor5-enter": "0.0.0-nightly-20240416.0",
18
+ "@ckeditor/ckeditor5-ui": "0.0.0-nightly-20240416.0",
19
+ "@ckeditor/ckeditor5-utils": "0.0.0-nightly-20240416.0",
20
+ "@ckeditor/ckeditor5-typing": "0.0.0-nightly-20240416.0",
21
21
  "lodash-es": "4.17.21"
22
22
  },
23
23
  "author": "CKSource (http://cksource.com/)",
package/src/utils.d.ts CHANGED
@@ -5,7 +5,7 @@
5
5
  /**
6
6
  * @module widget/utils
7
7
  */
8
- import { type GetCallback } from '@ckeditor/ckeditor5-utils';
8
+ import { Rect, type GetCallback } from '@ckeditor/ckeditor5-utils';
9
9
  import { type HighlightDescriptor, type MapperViewToModelPositionEvent, type DocumentSelection, type DowncastWriter, type Model, type Range, type Selection, type ViewEditableElement, type ViewElement, type ViewTypeCheckable } from '@ckeditor/ckeditor5-engine';
10
10
  /**
11
11
  * CSS class added to each widget element.
@@ -196,3 +196,20 @@ export declare function findOptimalInsertionRange(selection: Selection | Documen
196
196
  * should be applied to the given view element.
197
197
  */
198
198
  export declare function viewToModelPositionOutsideModelElement(model: Model, viewElementMatcher: (element: ViewElement) => boolean): GetCallback<MapperViewToModelPositionEvent>;
199
+ /**
200
+ * Starting from a DOM resize host element (an element that receives dimensions as a result of resizing),
201
+ * this helper returns the width of the found ancestor element.
202
+ *
203
+ * **Note**: This helper searches up to 5 levels of ancestors only.
204
+ *
205
+ * @param domResizeHost Resize host DOM element that receives dimensions as a result of resizing.
206
+ * @returns Width of ancestor element in pixels or 0 if no ancestor with a computed width has been found.
207
+ */
208
+ export declare function calculateResizeHostAncestorWidth(domResizeHost: HTMLElement): number;
209
+ /**
210
+ * Calculates a relative width of a `domResizeHost` compared to its ancestor in percents.
211
+ *
212
+ * @param domResizeHost Resize host DOM element.
213
+ * @returns Percentage value between 0 and 100.
214
+ */
215
+ export declare function calculateResizeHostPercentageWidth(domResizeHost: HTMLElement, resizeHostRect?: Rect): number;
package/src/utils.js CHANGED
@@ -5,7 +5,7 @@
5
5
  /**
6
6
  * @module widget/utils
7
7
  */
8
- import { CKEditorError, toArray } from '@ckeditor/ckeditor5-utils';
8
+ import { Rect, CKEditorError, toArray } from '@ckeditor/ckeditor5-utils';
9
9
  import { IconView } from '@ckeditor/ckeditor5-ui';
10
10
  import HighlightStack from './highlightstack.js';
11
11
  import { getTypeAroundFakeCaretPosition } from './widgettypearound/utils.js';
@@ -346,3 +346,47 @@ function addSelectionHandle(widgetElement, writer) {
346
346
  writer.insert(writer.createPositionAt(widgetElement, 0), selectionHandle);
347
347
  writer.addClass(['ck-widget_with-selection-handle'], widgetElement);
348
348
  }
349
+ /**
350
+ * Starting from a DOM resize host element (an element that receives dimensions as a result of resizing),
351
+ * this helper returns the width of the found ancestor element.
352
+ *
353
+ * **Note**: This helper searches up to 5 levels of ancestors only.
354
+ *
355
+ * @param domResizeHost Resize host DOM element that receives dimensions as a result of resizing.
356
+ * @returns Width of ancestor element in pixels or 0 if no ancestor with a computed width has been found.
357
+ */
358
+ export function calculateResizeHostAncestorWidth(domResizeHost) {
359
+ const domResizeHostParent = domResizeHost.parentElement;
360
+ if (!domResizeHostParent) {
361
+ return 0;
362
+ }
363
+ // Need to use computed style as it properly excludes parent's paddings from the returned value.
364
+ let parentWidth = parseFloat(domResizeHostParent.ownerDocument.defaultView.getComputedStyle(domResizeHostParent).width);
365
+ // Sometimes parent width cannot be accessed. If that happens we should go up in the elements tree
366
+ // and try to get width from next ancestor.
367
+ // https://github.com/ckeditor/ckeditor5/issues/10776
368
+ const ancestorLevelLimit = 5;
369
+ let currentLevel = 0;
370
+ let checkedElement = domResizeHostParent;
371
+ while (isNaN(parentWidth)) {
372
+ checkedElement = checkedElement.parentElement;
373
+ if (++currentLevel > ancestorLevelLimit) {
374
+ return 0;
375
+ }
376
+ parentWidth = parseFloat(domResizeHostParent.ownerDocument.defaultView.getComputedStyle(checkedElement).width);
377
+ }
378
+ return parentWidth;
379
+ }
380
+ /**
381
+ * Calculates a relative width of a `domResizeHost` compared to its ancestor in percents.
382
+ *
383
+ * @param domResizeHost Resize host DOM element.
384
+ * @returns Percentage value between 0 and 100.
385
+ */
386
+ export function calculateResizeHostPercentageWidth(domResizeHost, resizeHostRect = new Rect(domResizeHost)) {
387
+ const parentWidth = calculateResizeHostAncestorWidth(domResizeHost);
388
+ if (!parentWidth) {
389
+ return 0;
390
+ }
391
+ return resizeHostRect.width / parentWidth * 100;
392
+ }
@@ -6,6 +6,7 @@
6
6
  * @module widget/widgetresize/resizerstate
7
7
  */
8
8
  import { ObservableMixin, Rect } from '@ckeditor/ckeditor5-utils';
9
+ import { calculateResizeHostPercentageWidth } from '../utils.js';
9
10
  /**
10
11
  * Stores the internal state of a single resizable object.
11
12
  */
@@ -64,7 +65,7 @@ export default class ResizeState extends ObservableMixin() {
64
65
  this._originalWidthPercents = parseFloat(widthStyle);
65
66
  }
66
67
  else {
67
- this._originalWidthPercents = calculateHostPercentageWidth(domResizeHost, clientRect);
68
+ this._originalWidthPercents = calculateResizeHostPercentageWidth(domResizeHost, clientRect);
68
69
  }
69
70
  }
70
71
  update(newSize) {
@@ -75,28 +76,6 @@ export default class ResizeState extends ObservableMixin() {
75
76
  this.proposedHandleHostHeight = newSize.handleHostHeight;
76
77
  }
77
78
  }
78
- /**
79
- * Calculates a relative width of a `domResizeHost` compared to its ancestor in percents.
80
- */
81
- function calculateHostPercentageWidth(domResizeHost, resizeHostRect) {
82
- const domResizeHostParent = domResizeHost.parentElement;
83
- // Need to use computed style as it properly excludes parent's paddings from the returned value.
84
- let parentWidth = parseFloat(domResizeHostParent.ownerDocument.defaultView.getComputedStyle(domResizeHostParent).width);
85
- // Sometimes parent width cannot be accessed. If that happens we should go up in the elements tree
86
- // and try to get width from next ancestor.
87
- // https://github.com/ckeditor/ckeditor5/issues/10776
88
- const ancestorLevelLimit = 5;
89
- let currentLevel = 0;
90
- let checkedElement = domResizeHostParent;
91
- while (isNaN(parentWidth)) {
92
- checkedElement = checkedElement.parentElement;
93
- if (++currentLevel > ancestorLevelLimit) {
94
- return 0;
95
- }
96
- parentWidth = parseFloat(domResizeHostParent.ownerDocument.defaultView.getComputedStyle(checkedElement).width);
97
- }
98
- return resizeHostRect.width / parentWidth * 100;
99
- }
100
79
  /**
101
80
  * Returns coordinates of the top-left corner of an element, relative to the document's top-left corner.
102
81
  *