@ckeditor/ckeditor5-widget 41.3.0 → 41.4.0-alpha.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (125) hide show
  1. package/dist/index-content.css +4 -0
  2. package/dist/index-editor.css +144 -0
  3. package/dist/index.css +257 -0
  4. package/dist/index.css.map +1 -0
  5. package/dist/index.js +2877 -0
  6. package/dist/index.js.map +1 -0
  7. package/dist/translations/ar.d.ts +8 -0
  8. package/dist/translations/ar.js +5 -0
  9. package/dist/translations/az.d.ts +8 -0
  10. package/dist/translations/az.js +5 -0
  11. package/dist/translations/bg.d.ts +8 -0
  12. package/dist/translations/bg.js +5 -0
  13. package/dist/translations/bn.d.ts +8 -0
  14. package/dist/translations/bn.js +5 -0
  15. package/dist/translations/ca.d.ts +8 -0
  16. package/dist/translations/ca.js +5 -0
  17. package/dist/translations/cs.d.ts +8 -0
  18. package/dist/translations/cs.js +5 -0
  19. package/dist/translations/da.d.ts +8 -0
  20. package/dist/translations/da.js +5 -0
  21. package/dist/translations/de-ch.d.ts +8 -0
  22. package/dist/translations/de-ch.js +5 -0
  23. package/dist/translations/de.d.ts +8 -0
  24. package/dist/translations/de.js +5 -0
  25. package/dist/translations/el.d.ts +8 -0
  26. package/dist/translations/el.js +5 -0
  27. package/dist/translations/en-au.d.ts +8 -0
  28. package/dist/translations/en-au.js +5 -0
  29. package/dist/translations/en.d.ts +8 -0
  30. package/dist/translations/en.js +5 -0
  31. package/dist/translations/es.d.ts +8 -0
  32. package/dist/translations/es.js +5 -0
  33. package/dist/translations/et.d.ts +8 -0
  34. package/dist/translations/et.js +5 -0
  35. package/dist/translations/fa.d.ts +8 -0
  36. package/dist/translations/fa.js +5 -0
  37. package/dist/translations/fi.d.ts +8 -0
  38. package/dist/translations/fi.js +5 -0
  39. package/dist/translations/fr.d.ts +8 -0
  40. package/dist/translations/fr.js +5 -0
  41. package/dist/translations/gl.d.ts +8 -0
  42. package/dist/translations/gl.js +5 -0
  43. package/dist/translations/he.d.ts +8 -0
  44. package/dist/translations/he.js +5 -0
  45. package/dist/translations/hi.d.ts +8 -0
  46. package/dist/translations/hi.js +5 -0
  47. package/dist/translations/hr.d.ts +8 -0
  48. package/dist/translations/hr.js +5 -0
  49. package/dist/translations/hu.d.ts +8 -0
  50. package/dist/translations/hu.js +5 -0
  51. package/dist/translations/id.d.ts +8 -0
  52. package/dist/translations/id.js +5 -0
  53. package/dist/translations/it.d.ts +8 -0
  54. package/dist/translations/it.js +5 -0
  55. package/dist/translations/ja.d.ts +8 -0
  56. package/dist/translations/ja.js +5 -0
  57. package/dist/translations/ko.d.ts +8 -0
  58. package/dist/translations/ko.js +5 -0
  59. package/dist/translations/ku.d.ts +8 -0
  60. package/dist/translations/ku.js +5 -0
  61. package/dist/translations/lt.d.ts +8 -0
  62. package/dist/translations/lt.js +5 -0
  63. package/dist/translations/lv.d.ts +8 -0
  64. package/dist/translations/lv.js +5 -0
  65. package/dist/translations/ms.d.ts +8 -0
  66. package/dist/translations/ms.js +5 -0
  67. package/dist/translations/nl.d.ts +8 -0
  68. package/dist/translations/nl.js +5 -0
  69. package/dist/translations/no.d.ts +8 -0
  70. package/dist/translations/no.js +5 -0
  71. package/dist/translations/pl.d.ts +8 -0
  72. package/dist/translations/pl.js +5 -0
  73. package/dist/translations/pt-br.d.ts +8 -0
  74. package/dist/translations/pt-br.js +5 -0
  75. package/dist/translations/pt.d.ts +8 -0
  76. package/dist/translations/pt.js +5 -0
  77. package/dist/translations/ro.d.ts +8 -0
  78. package/dist/translations/ro.js +5 -0
  79. package/dist/translations/ru.d.ts +8 -0
  80. package/dist/translations/ru.js +5 -0
  81. package/dist/translations/sk.d.ts +8 -0
  82. package/dist/translations/sk.js +5 -0
  83. package/dist/translations/sq.d.ts +8 -0
  84. package/dist/translations/sq.js +5 -0
  85. package/dist/translations/sr-latn.d.ts +8 -0
  86. package/dist/translations/sr-latn.js +5 -0
  87. package/dist/translations/sr.d.ts +8 -0
  88. package/dist/translations/sr.js +5 -0
  89. package/dist/translations/sv.d.ts +8 -0
  90. package/dist/translations/sv.js +5 -0
  91. package/dist/translations/th.d.ts +8 -0
  92. package/dist/translations/th.js +5 -0
  93. package/dist/translations/tk.d.ts +8 -0
  94. package/dist/translations/tk.js +5 -0
  95. package/dist/translations/tr.d.ts +8 -0
  96. package/dist/translations/tr.js +5 -0
  97. package/dist/translations/uk.d.ts +8 -0
  98. package/dist/translations/uk.js +5 -0
  99. package/dist/translations/ur.d.ts +8 -0
  100. package/dist/translations/ur.js +5 -0
  101. package/dist/translations/uz.d.ts +8 -0
  102. package/dist/translations/uz.js +5 -0
  103. package/dist/translations/vi.d.ts +8 -0
  104. package/dist/translations/vi.js +5 -0
  105. package/dist/translations/zh-cn.d.ts +8 -0
  106. package/dist/translations/zh-cn.js +5 -0
  107. package/dist/translations/zh.d.ts +8 -0
  108. package/dist/translations/zh.js +5 -0
  109. package/dist/types/augmentation.d.ts +17 -0
  110. package/dist/types/highlightstack.d.ts +78 -0
  111. package/dist/types/index.d.ts +17 -0
  112. package/dist/types/utils.d.ts +219 -0
  113. package/dist/types/verticalnavigation.d.ts +19 -0
  114. package/dist/types/widget.d.ts +107 -0
  115. package/dist/types/widgetresize/resizer.d.ts +181 -0
  116. package/dist/types/widgetresize/resizerstate.d.ts +129 -0
  117. package/dist/types/widgetresize/sizeview.d.ts +59 -0
  118. package/dist/types/widgetresize.d.ts +129 -0
  119. package/dist/types/widgettoolbarrepository.d.ts +98 -0
  120. package/dist/types/widgettypearound/utils.d.ts +42 -0
  121. package/dist/types/widgettypearound/widgettypearound.d.ts +233 -0
  122. package/package.json +8 -7
  123. package/src/utils.d.ts +18 -1
  124. package/src/utils.js +45 -1
  125. 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 = 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
  *