@ckeditor/ckeditor5-widget 41.3.1 → 41.4.0-alpha.0
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/index-content.css +4 -0
- package/dist/index-editor.css +144 -0
- package/dist/index.css +257 -0
- package/dist/index.css.map +1 -0
- package/dist/index.js +2877 -0
- package/dist/index.js.map +1 -0
- package/dist/translations/ar.d.ts +8 -0
- package/dist/translations/ar.js +5 -0
- package/dist/translations/az.d.ts +8 -0
- package/dist/translations/az.js +5 -0
- package/dist/translations/bg.d.ts +8 -0
- package/dist/translations/bg.js +5 -0
- package/dist/translations/bn.d.ts +8 -0
- package/dist/translations/bn.js +5 -0
- package/dist/translations/ca.d.ts +8 -0
- package/dist/translations/ca.js +5 -0
- package/dist/translations/cs.d.ts +8 -0
- package/dist/translations/cs.js +5 -0
- package/dist/translations/da.d.ts +8 -0
- package/dist/translations/da.js +5 -0
- package/dist/translations/de-ch.d.ts +8 -0
- package/dist/translations/de-ch.js +5 -0
- package/dist/translations/de.d.ts +8 -0
- package/dist/translations/de.js +5 -0
- package/dist/translations/el.d.ts +8 -0
- package/dist/translations/el.js +5 -0
- package/dist/translations/en-au.d.ts +8 -0
- package/dist/translations/en-au.js +5 -0
- package/dist/translations/en.d.ts +8 -0
- package/dist/translations/en.js +5 -0
- package/dist/translations/es.d.ts +8 -0
- package/dist/translations/es.js +5 -0
- package/dist/translations/et.d.ts +8 -0
- package/dist/translations/et.js +5 -0
- package/dist/translations/fa.d.ts +8 -0
- package/dist/translations/fa.js +5 -0
- package/dist/translations/fi.d.ts +8 -0
- package/dist/translations/fi.js +5 -0
- package/dist/translations/fr.d.ts +8 -0
- package/dist/translations/fr.js +5 -0
- package/dist/translations/gl.d.ts +8 -0
- package/dist/translations/gl.js +5 -0
- package/dist/translations/he.d.ts +8 -0
- package/dist/translations/he.js +5 -0
- package/dist/translations/hi.d.ts +8 -0
- package/dist/translations/hi.js +5 -0
- package/dist/translations/hr.d.ts +8 -0
- package/dist/translations/hr.js +5 -0
- package/dist/translations/hu.d.ts +8 -0
- package/dist/translations/hu.js +5 -0
- package/dist/translations/id.d.ts +8 -0
- package/dist/translations/id.js +5 -0
- package/dist/translations/it.d.ts +8 -0
- package/dist/translations/it.js +5 -0
- package/dist/translations/ja.d.ts +8 -0
- package/dist/translations/ja.js +5 -0
- package/dist/translations/ko.d.ts +8 -0
- package/dist/translations/ko.js +5 -0
- package/dist/translations/ku.d.ts +8 -0
- package/dist/translations/ku.js +5 -0
- package/dist/translations/lt.d.ts +8 -0
- package/dist/translations/lt.js +5 -0
- package/dist/translations/lv.d.ts +8 -0
- package/dist/translations/lv.js +5 -0
- package/dist/translations/ms.d.ts +8 -0
- package/dist/translations/ms.js +5 -0
- package/dist/translations/nl.d.ts +8 -0
- package/dist/translations/nl.js +5 -0
- package/dist/translations/no.d.ts +8 -0
- package/dist/translations/no.js +5 -0
- package/dist/translations/pl.d.ts +8 -0
- package/dist/translations/pl.js +5 -0
- package/dist/translations/pt-br.d.ts +8 -0
- package/dist/translations/pt-br.js +5 -0
- package/dist/translations/pt.d.ts +8 -0
- package/dist/translations/pt.js +5 -0
- package/dist/translations/ro.d.ts +8 -0
- package/dist/translations/ro.js +5 -0
- package/dist/translations/ru.d.ts +8 -0
- package/dist/translations/ru.js +5 -0
- package/dist/translations/sk.d.ts +8 -0
- package/dist/translations/sk.js +5 -0
- package/dist/translations/sq.d.ts +8 -0
- package/dist/translations/sq.js +5 -0
- package/dist/translations/sr-latn.d.ts +8 -0
- package/dist/translations/sr-latn.js +5 -0
- package/dist/translations/sr.d.ts +8 -0
- package/dist/translations/sr.js +5 -0
- package/dist/translations/sv.d.ts +8 -0
- package/dist/translations/sv.js +5 -0
- package/dist/translations/th.d.ts +8 -0
- package/dist/translations/th.js +5 -0
- package/dist/translations/tk.d.ts +8 -0
- package/dist/translations/tk.js +5 -0
- package/dist/translations/tr.d.ts +8 -0
- package/dist/translations/tr.js +5 -0
- package/dist/translations/uk.d.ts +8 -0
- package/dist/translations/uk.js +5 -0
- package/dist/translations/ur.d.ts +8 -0
- package/dist/translations/ur.js +5 -0
- package/dist/translations/uz.d.ts +8 -0
- package/dist/translations/uz.js +5 -0
- package/dist/translations/vi.d.ts +8 -0
- package/dist/translations/vi.js +5 -0
- package/dist/translations/zh-cn.d.ts +8 -0
- package/dist/translations/zh-cn.js +5 -0
- package/dist/translations/zh.d.ts +8 -0
- package/dist/translations/zh.js +5 -0
- package/dist/types/augmentation.d.ts +17 -0
- package/dist/types/highlightstack.d.ts +78 -0
- package/dist/types/index.d.ts +17 -0
- package/dist/types/utils.d.ts +219 -0
- package/dist/types/verticalnavigation.d.ts +19 -0
- package/dist/types/widget.d.ts +107 -0
- package/dist/types/widgetresize/resizer.d.ts +181 -0
- package/dist/types/widgetresize/resizerstate.d.ts +129 -0
- package/dist/types/widgetresize/sizeview.d.ts +59 -0
- package/dist/types/widgetresize.d.ts +129 -0
- package/dist/types/widgettoolbarrepository.d.ts +98 -0
- package/dist/types/widgettypearound/utils.d.ts +42 -0
- package/dist/types/widgettypearound/widgettypearound.d.ts +233 -0
- package/package.json +8 -7
- package/src/utils.d.ts +18 -1
- package/src/utils.js +45 -1
- package/src/widgetresize/resizerstate.js +2 -23
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 =
|
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
|
*
|