@ckeditor/ckeditor5-widget 41.3.1 → 41.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (176) 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 +2881 -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/ar.umd.js +11 -0
  10. package/dist/translations/az.d.ts +8 -0
  11. package/dist/translations/az.js +5 -0
  12. package/dist/translations/az.umd.js +11 -0
  13. package/dist/translations/bg.d.ts +8 -0
  14. package/dist/translations/bg.js +5 -0
  15. package/dist/translations/bg.umd.js +11 -0
  16. package/dist/translations/bn.d.ts +8 -0
  17. package/dist/translations/bn.js +5 -0
  18. package/dist/translations/bn.umd.js +11 -0
  19. package/dist/translations/ca.d.ts +8 -0
  20. package/dist/translations/ca.js +5 -0
  21. package/dist/translations/ca.umd.js +11 -0
  22. package/dist/translations/cs.d.ts +8 -0
  23. package/dist/translations/cs.js +5 -0
  24. package/dist/translations/cs.umd.js +11 -0
  25. package/dist/translations/da.d.ts +8 -0
  26. package/dist/translations/da.js +5 -0
  27. package/dist/translations/da.umd.js +11 -0
  28. package/dist/translations/de-ch.d.ts +8 -0
  29. package/dist/translations/de-ch.js +5 -0
  30. package/dist/translations/de-ch.umd.js +11 -0
  31. package/dist/translations/de.d.ts +8 -0
  32. package/dist/translations/de.js +5 -0
  33. package/dist/translations/de.umd.js +11 -0
  34. package/dist/translations/el.d.ts +8 -0
  35. package/dist/translations/el.js +5 -0
  36. package/dist/translations/el.umd.js +11 -0
  37. package/dist/translations/en-au.d.ts +8 -0
  38. package/dist/translations/en-au.js +5 -0
  39. package/dist/translations/en-au.umd.js +11 -0
  40. package/dist/translations/en.d.ts +8 -0
  41. package/dist/translations/en.js +5 -0
  42. package/dist/translations/en.umd.js +11 -0
  43. package/dist/translations/es.d.ts +8 -0
  44. package/dist/translations/es.js +5 -0
  45. package/dist/translations/es.umd.js +11 -0
  46. package/dist/translations/et.d.ts +8 -0
  47. package/dist/translations/et.js +5 -0
  48. package/dist/translations/et.umd.js +11 -0
  49. package/dist/translations/fa.d.ts +8 -0
  50. package/dist/translations/fa.js +5 -0
  51. package/dist/translations/fa.umd.js +11 -0
  52. package/dist/translations/fi.d.ts +8 -0
  53. package/dist/translations/fi.js +5 -0
  54. package/dist/translations/fi.umd.js +11 -0
  55. package/dist/translations/fr.d.ts +8 -0
  56. package/dist/translations/fr.js +5 -0
  57. package/dist/translations/fr.umd.js +11 -0
  58. package/dist/translations/gl.d.ts +8 -0
  59. package/dist/translations/gl.js +5 -0
  60. package/dist/translations/gl.umd.js +11 -0
  61. package/dist/translations/he.d.ts +8 -0
  62. package/dist/translations/he.js +5 -0
  63. package/dist/translations/he.umd.js +11 -0
  64. package/dist/translations/hi.d.ts +8 -0
  65. package/dist/translations/hi.js +5 -0
  66. package/dist/translations/hi.umd.js +11 -0
  67. package/dist/translations/hr.d.ts +8 -0
  68. package/dist/translations/hr.js +5 -0
  69. package/dist/translations/hr.umd.js +11 -0
  70. package/dist/translations/hu.d.ts +8 -0
  71. package/dist/translations/hu.js +5 -0
  72. package/dist/translations/hu.umd.js +11 -0
  73. package/dist/translations/id.d.ts +8 -0
  74. package/dist/translations/id.js +5 -0
  75. package/dist/translations/id.umd.js +11 -0
  76. package/dist/translations/it.d.ts +8 -0
  77. package/dist/translations/it.js +5 -0
  78. package/dist/translations/it.umd.js +11 -0
  79. package/dist/translations/ja.d.ts +8 -0
  80. package/dist/translations/ja.js +5 -0
  81. package/dist/translations/ja.umd.js +11 -0
  82. package/dist/translations/ko.d.ts +8 -0
  83. package/dist/translations/ko.js +5 -0
  84. package/dist/translations/ko.umd.js +11 -0
  85. package/dist/translations/ku.d.ts +8 -0
  86. package/dist/translations/ku.js +5 -0
  87. package/dist/translations/ku.umd.js +11 -0
  88. package/dist/translations/lt.d.ts +8 -0
  89. package/dist/translations/lt.js +5 -0
  90. package/dist/translations/lt.umd.js +11 -0
  91. package/dist/translations/lv.d.ts +8 -0
  92. package/dist/translations/lv.js +5 -0
  93. package/dist/translations/lv.umd.js +11 -0
  94. package/dist/translations/ms.d.ts +8 -0
  95. package/dist/translations/ms.js +5 -0
  96. package/dist/translations/ms.umd.js +11 -0
  97. package/dist/translations/nl.d.ts +8 -0
  98. package/dist/translations/nl.js +5 -0
  99. package/dist/translations/nl.umd.js +11 -0
  100. package/dist/translations/no.d.ts +8 -0
  101. package/dist/translations/no.js +5 -0
  102. package/dist/translations/no.umd.js +11 -0
  103. package/dist/translations/pl.d.ts +8 -0
  104. package/dist/translations/pl.js +5 -0
  105. package/dist/translations/pl.umd.js +11 -0
  106. package/dist/translations/pt-br.d.ts +8 -0
  107. package/dist/translations/pt-br.js +5 -0
  108. package/dist/translations/pt-br.umd.js +11 -0
  109. package/dist/translations/pt.d.ts +8 -0
  110. package/dist/translations/pt.js +5 -0
  111. package/dist/translations/pt.umd.js +11 -0
  112. package/dist/translations/ro.d.ts +8 -0
  113. package/dist/translations/ro.js +5 -0
  114. package/dist/translations/ro.umd.js +11 -0
  115. package/dist/translations/ru.d.ts +8 -0
  116. package/dist/translations/ru.js +5 -0
  117. package/dist/translations/ru.umd.js +11 -0
  118. package/dist/translations/sk.d.ts +8 -0
  119. package/dist/translations/sk.js +5 -0
  120. package/dist/translations/sk.umd.js +11 -0
  121. package/dist/translations/sq.d.ts +8 -0
  122. package/dist/translations/sq.js +5 -0
  123. package/dist/translations/sq.umd.js +11 -0
  124. package/dist/translations/sr-latn.d.ts +8 -0
  125. package/dist/translations/sr-latn.js +5 -0
  126. package/dist/translations/sr-latn.umd.js +11 -0
  127. package/dist/translations/sr.d.ts +8 -0
  128. package/dist/translations/sr.js +5 -0
  129. package/dist/translations/sr.umd.js +11 -0
  130. package/dist/translations/sv.d.ts +8 -0
  131. package/dist/translations/sv.js +5 -0
  132. package/dist/translations/sv.umd.js +11 -0
  133. package/dist/translations/th.d.ts +8 -0
  134. package/dist/translations/th.js +5 -0
  135. package/dist/translations/th.umd.js +11 -0
  136. package/dist/translations/tk.d.ts +8 -0
  137. package/dist/translations/tk.js +5 -0
  138. package/dist/translations/tk.umd.js +11 -0
  139. package/dist/translations/tr.d.ts +8 -0
  140. package/dist/translations/tr.js +5 -0
  141. package/dist/translations/tr.umd.js +11 -0
  142. package/dist/translations/uk.d.ts +8 -0
  143. package/dist/translations/uk.js +5 -0
  144. package/dist/translations/uk.umd.js +11 -0
  145. package/dist/translations/ur.d.ts +8 -0
  146. package/dist/translations/ur.js +5 -0
  147. package/dist/translations/ur.umd.js +11 -0
  148. package/dist/translations/uz.d.ts +8 -0
  149. package/dist/translations/uz.js +5 -0
  150. package/dist/translations/uz.umd.js +11 -0
  151. package/dist/translations/vi.d.ts +8 -0
  152. package/dist/translations/vi.js +5 -0
  153. package/dist/translations/vi.umd.js +11 -0
  154. package/dist/translations/zh-cn.d.ts +8 -0
  155. package/dist/translations/zh-cn.js +5 -0
  156. package/dist/translations/zh-cn.umd.js +11 -0
  157. package/dist/translations/zh.d.ts +8 -0
  158. package/dist/translations/zh.js +5 -0
  159. package/dist/translations/zh.umd.js +11 -0
  160. package/dist/types/augmentation.d.ts +17 -0
  161. package/dist/types/highlightstack.d.ts +78 -0
  162. package/dist/types/index.d.ts +17 -0
  163. package/dist/types/utils.d.ts +219 -0
  164. package/dist/types/verticalnavigation.d.ts +19 -0
  165. package/dist/types/widget.d.ts +107 -0
  166. package/dist/types/widgetresize/resizer.d.ts +181 -0
  167. package/dist/types/widgetresize/resizerstate.d.ts +129 -0
  168. package/dist/types/widgetresize/sizeview.d.ts +59 -0
  169. package/dist/types/widgetresize.d.ts +129 -0
  170. package/dist/types/widgettoolbarrepository.d.ts +98 -0
  171. package/dist/types/widgettypearound/utils.d.ts +42 -0
  172. package/dist/types/widgettypearound/widgettypearound.d.ts +233 -0
  173. package/package.json +8 -7
  174. package/src/utils.d.ts +18 -1
  175. package/src/utils.js +49 -1
  176. package/src/widgetresize/resizerstate.js +2 -23
@@ -0,0 +1,78 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
+ */
5
+ /**
6
+ * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
7
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
8
+ */
9
+ import type { DowncastWriter, HighlightDescriptor } from '@ckeditor/ckeditor5-engine';
10
+ declare const HighlightStack_base: {
11
+ new (): import("@ckeditor/ckeditor5-utils").Emitter;
12
+ prototype: import("@ckeditor/ckeditor5-utils").Emitter;
13
+ };
14
+ /**
15
+ * Class used to handle the correct order of highlights on elements.
16
+ *
17
+ * When different highlights are applied to same element the correct order should be preserved:
18
+ *
19
+ * * highlight with highest priority should be applied,
20
+ * * if two highlights have same priority - sort by CSS class provided in
21
+ * {@link module:engine/conversion/downcasthelpers~HighlightDescriptor}.
22
+ *
23
+ * This way, highlight will be applied with the same rules it is applied on texts.
24
+ */
25
+ export default class HighlightStack extends HighlightStack_base {
26
+ private readonly _stack;
27
+ /**
28
+ * Adds highlight descriptor to the stack.
29
+ *
30
+ * @fires change:top
31
+ */
32
+ add(descriptor: HighlightDescriptor, writer: DowncastWriter): void;
33
+ /**
34
+ * Removes highlight descriptor from the stack.
35
+ *
36
+ * @fires change:top
37
+ * @param id Id of the descriptor to remove.
38
+ */
39
+ remove(id: string, writer: DowncastWriter): void;
40
+ /**
41
+ * Inserts a given descriptor in correct place in the stack. It also takes care about updating information
42
+ * when descriptor with same id is already present.
43
+ */
44
+ private _insertDescriptor;
45
+ /**
46
+ * Removes descriptor with given id from the stack.
47
+ *
48
+ * @param id Descriptor's id.
49
+ */
50
+ private _removeDescriptor;
51
+ }
52
+ /**
53
+ * Fired when top element on {@link module:widget/highlightstack~HighlightStack} has been changed
54
+ *
55
+ * @eventName ~HighlightStack#change:top
56
+ */
57
+ export type HighlightStackChangeEvent = {
58
+ name: 'change' | 'change:top';
59
+ args: [HighlightStackChangeEventData];
60
+ };
61
+ /**
62
+ * Additional information about the change.
63
+ */
64
+ export type HighlightStackChangeEventData = {
65
+ /**
66
+ * Old highlight descriptor. It will be `undefined` when first descriptor is added to the stack.
67
+ */
68
+ oldDescriptor: HighlightDescriptor;
69
+ /**
70
+ * New highlight descriptor. It will be `undefined` when last descriptor is removed from the stack.
71
+ */
72
+ newDescriptor: HighlightDescriptor;
73
+ /**
74
+ * View writer that can be used to modify element.
75
+ */
76
+ writer: DowncastWriter;
77
+ };
78
+ export {};
@@ -0,0 +1,17 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
+ */
5
+ /**
6
+ * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
7
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
8
+ */
9
+ /**
10
+ * @module widget
11
+ */
12
+ export { default as Widget } from './widget.js';
13
+ export { default as WidgetToolbarRepository } from './widgettoolbarrepository.js';
14
+ export { default as WidgetResize } from './widgetresize.js';
15
+ export { default as WidgetTypeAround } from './widgettypearound/widgettypearound.js';
16
+ export * from './utils.js';
17
+ import './augmentation.js';
@@ -0,0 +1,219 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
+ */
5
+ /**
6
+ * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
7
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
8
+ */
9
+ /**
10
+ * @module widget/utils
11
+ */
12
+ import { Rect, type GetCallback } from '@ckeditor/ckeditor5-utils';
13
+ 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';
14
+ /**
15
+ * CSS class added to each widget element.
16
+ */
17
+ export declare const WIDGET_CLASS_NAME = "ck-widget";
18
+ /**
19
+ * CSS class added to currently selected widget element.
20
+ */
21
+ export declare const WIDGET_SELECTED_CLASS_NAME = "ck-widget_selected";
22
+ /**
23
+ * Returns `true` if given {@link module:engine/view/node~Node} is an {@link module:engine/view/element~Element} and a widget.
24
+ */
25
+ export declare function isWidget(node: ViewTypeCheckable): boolean;
26
+ /**
27
+ * Converts the given {@link module:engine/view/element~Element} to a widget in the following way:
28
+ *
29
+ * * sets the `contenteditable` attribute to `"false"`,
30
+ * * adds the `ck-widget` CSS class,
31
+ * * adds a custom {@link module:engine/view/element~Element#getFillerOffset `getFillerOffset()`} method returning `null`,
32
+ * * adds a custom property allowing to recognize widget elements by using {@link ~isWidget `isWidget()`},
33
+ * * implements the {@link ~setHighlightHandling view highlight on widgets}.
34
+ *
35
+ * This function needs to be used in conjunction with
36
+ * {@link module:engine/conversion/downcasthelpers~DowncastHelpers downcast conversion helpers}
37
+ * like {@link module:engine/conversion/downcasthelpers~DowncastHelpers#elementToElement `elementToElement()`}.
38
+ * Moreover, typically you will want to use `toWidget()` only for `editingDowncast`, while keeping the `dataDowncast` clean.
39
+ *
40
+ * For example, in order to convert a `<widget>` model element to `<div class="widget">` in the view, you can define
41
+ * such converters:
42
+ *
43
+ * ```ts
44
+ * editor.conversion.for( 'editingDowncast' )
45
+ * .elementToElement( {
46
+ * model: 'widget',
47
+ * view: ( modelItem, { writer } ) => {
48
+ * const div = writer.createContainerElement( 'div', { class: 'widget' } );
49
+ *
50
+ * return toWidget( div, writer, { label: 'some widget' } );
51
+ * }
52
+ * } );
53
+ *
54
+ * editor.conversion.for( 'dataDowncast' )
55
+ * .elementToElement( {
56
+ * model: 'widget',
57
+ * view: ( modelItem, { writer } ) => {
58
+ * return writer.createContainerElement( 'div', { class: 'widget' } );
59
+ * }
60
+ * } );
61
+ * ```
62
+ *
63
+ * See the full source code of the widget (with a nested editable) schema definition and converters in
64
+ * [this sample](https://github.com/ckeditor/ckeditor5-widget/blob/master/tests/manual/widget-with-nestededitable.js).
65
+ *
66
+ * @param options Additional options.
67
+ * @param options.label Element's label provided to the {@link ~setLabel} function. It can be passed as
68
+ * a plain string or a function returning a string. It represents the widget for assistive technologies (like screen readers).
69
+ * @param options.hasSelectionHandle If `true`, the widget will have a selection handle added.
70
+ * @returns Returns the same element.
71
+ */
72
+ export declare function toWidget(element: ViewElement, writer: DowncastWriter, options?: {
73
+ label?: string | (() => string);
74
+ hasSelectionHandle?: boolean;
75
+ }): ViewElement;
76
+ /**
77
+ * Sets highlight handling methods. Uses {@link module:widget/highlightstack~HighlightStack} to
78
+ * properly determine which highlight descriptor should be used at given time.
79
+ */
80
+ export declare function setHighlightHandling(element: ViewElement, writer: DowncastWriter, add?: (element: ViewElement, descriptor: HighlightDescriptor, writer: DowncastWriter) => void, remove?: (element: ViewElement, descriptor: HighlightDescriptor, writer: DowncastWriter) => void): void;
81
+ /**
82
+ * Sets label for given element.
83
+ * It can be passed as a plain string or a function returning a string. Function will be called each time label is retrieved by
84
+ * {@link ~getLabel `getLabel()`}.
85
+ */
86
+ export declare function setLabel(element: ViewElement, labelOrCreator: string | (() => string)): void;
87
+ /**
88
+ * Returns the label of the provided element.
89
+ */
90
+ export declare function getLabel(element: ViewElement): string;
91
+ /**
92
+ * Adds functionality to the provided {@link module:engine/view/editableelement~EditableElement} to act as a widget's editable:
93
+ *
94
+ * * sets the `contenteditable` attribute to `true` when {@link module:engine/view/editableelement~EditableElement#isReadOnly} is `false`,
95
+ * otherwise sets it to `false`,
96
+ * * adds the `ck-editor__editable` and `ck-editor__nested-editable` CSS classes,
97
+ * * adds the `ck-editor__nested-editable_focused` CSS class when the editable is focused and removes it when it is blurred.
98
+ * * implements the {@link ~setHighlightHandling view highlight on widget's editable}.
99
+ *
100
+ * Similarly to {@link ~toWidget `toWidget()`} this function should be used in `editingDowncast` only and it is usually
101
+ * used together with {@link module:engine/conversion/downcasthelpers~DowncastHelpers#elementToElement `elementToElement()`}.
102
+ *
103
+ * For example, in order to convert a `<nested>` model element to `<div class="nested">` in the view, you can define
104
+ * such converters:
105
+ *
106
+ * ```ts
107
+ * editor.conversion.for( 'editingDowncast' )
108
+ * .elementToElement( {
109
+ * model: 'nested',
110
+ * view: ( modelItem, { writer } ) => {
111
+ * const div = writer.createEditableElement( 'div', { class: 'nested' } );
112
+ *
113
+ * return toWidgetEditable( nested, writer, { label: 'label for editable' } );
114
+ * }
115
+ * } );
116
+ *
117
+ * editor.conversion.for( 'dataDowncast' )
118
+ * .elementToElement( {
119
+ * model: 'nested',
120
+ * view: ( modelItem, { writer } ) => {
121
+ * return writer.createContainerElement( 'div', { class: 'nested' } );
122
+ * }
123
+ * } );
124
+ * ```
125
+ *
126
+ * See the full source code of the widget (with nested editable) schema definition and converters in
127
+ * [this sample](https://github.com/ckeditor/ckeditor5-widget/blob/master/tests/manual/widget-with-nestededitable.js).
128
+ *
129
+ * @param options Additional options.
130
+ * @param options.label Editable's label used by assistive technologies (e.g. screen readers).
131
+ * @returns Returns the same element that was provided in the `editable` parameter
132
+ */
133
+ export declare function toWidgetEditable(editable: ViewEditableElement, writer: DowncastWriter, options?: {
134
+ label?: string;
135
+ }): ViewEditableElement;
136
+ /**
137
+ * Returns a model range which is optimal (in terms of UX) for inserting a widget block.
138
+ *
139
+ * For instance, if a selection is in the middle of a paragraph, the collapsed range before this paragraph
140
+ * will be returned so that it is not split. If the selection is at the end of a paragraph,
141
+ * the collapsed range after this paragraph will be returned.
142
+ *
143
+ * Note: If the selection is placed in an empty block, the range in that block will be returned. If that range
144
+ * is then passed to {@link module:engine/model/model~Model#insertContent}, the block will be fully replaced
145
+ * by the inserted widget block.
146
+ *
147
+ * @param selection The selection based on which the insertion position should be calculated.
148
+ * @param model Model instance.
149
+ * @returns The optimal range.
150
+ */
151
+ export declare function findOptimalInsertionRange(selection: Selection | DocumentSelection, model: Model): Range;
152
+ /**
153
+ * A util to be used in order to map view positions to correct model positions when implementing a widget
154
+ * which renders non-empty view element for an empty model element.
155
+ *
156
+ * For example:
157
+ *
158
+ * ```
159
+ * // Model:
160
+ * <placeholder type="name"></placeholder>
161
+ *
162
+ * // View:
163
+ * <span class="placeholder">name</span>
164
+ * ```
165
+ *
166
+ * In such case, view positions inside `<span>` cannot be correctly mapped to the model (because the model element is empty).
167
+ * To handle mapping positions inside `<span class="placeholder">` to the model use this util as follows:
168
+ *
169
+ * ```ts
170
+ * editor.editing.mapper.on(
171
+ * 'viewToModelPosition',
172
+ * viewToModelPositionOutsideModelElement( model, viewElement => viewElement.hasClass( 'placeholder' ) )
173
+ * );
174
+ * ```
175
+ *
176
+ * The callback will try to map the view offset of selection to an expected model position.
177
+ *
178
+ * 1. When the position is at the end (or in the middle) of the inline widget:
179
+ *
180
+ * ```
181
+ * // View:
182
+ * <p>foo <span class="placeholder">name|</span> bar</p>
183
+ *
184
+ * // Model:
185
+ * <paragraph>foo <placeholder type="name"></placeholder>| bar</paragraph>
186
+ * ```
187
+ *
188
+ * 2. When the position is at the beginning of the inline widget:
189
+ *
190
+ * ```
191
+ * // View:
192
+ * <p>foo <span class="placeholder">|name</span> bar</p>
193
+ *
194
+ * // Model:
195
+ * <paragraph>foo |<placeholder type="name"></placeholder> bar</paragraph>
196
+ * ```
197
+ *
198
+ * @param model Model instance on which the callback operates.
199
+ * @param viewElementMatcher Function that is passed a view element and should return `true` if the custom mapping
200
+ * should be applied to the given view element.
201
+ */
202
+ export declare function viewToModelPositionOutsideModelElement(model: Model, viewElementMatcher: (element: ViewElement) => boolean): GetCallback<MapperViewToModelPositionEvent>;
203
+ /**
204
+ * Starting from a DOM resize host element (an element that receives dimensions as a result of resizing),
205
+ * this helper returns the width of the found ancestor element.
206
+ *
207
+ * * It searches up to 5 levels of ancestors only.
208
+ *
209
+ * @param domResizeHost Resize host DOM element that receives dimensions as a result of resizing.
210
+ * @returns Width of ancestor element in pixels or 0 if no ancestor with a computed width has been found.
211
+ */
212
+ export declare function calculateResizeHostAncestorWidth(domResizeHost: HTMLElement): number;
213
+ /**
214
+ * Calculates a relative width of a `domResizeHost` compared to its ancestor in percents.
215
+ *
216
+ * @param domResizeHost Resize host DOM element.
217
+ * @returns Percentage value between 0 and 100.
218
+ */
219
+ export declare function calculateResizeHostPercentageWidth(domResizeHost: HTMLElement, resizeHostRect?: Rect): number;
@@ -0,0 +1,19 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
+ */
5
+ /**
6
+ * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
7
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
8
+ */
9
+ /**
10
+ * @module widget/verticalnavigation
11
+ */
12
+ import { type GetCallback } from '@ckeditor/ckeditor5-utils';
13
+ import type { EditingController, ViewDocumentArrowKeyEvent } from '@ckeditor/ckeditor5-engine';
14
+ /**
15
+ * Returns 'keydown' handler for up/down arrow keys that modifies the caret movement if it's in a text line next to an object.
16
+ *
17
+ * @param editing The editing controller.
18
+ */
19
+ export default function verticalNavigationHandler(editing: EditingController): GetCallback<ViewDocumentArrowKeyEvent>;
@@ -0,0 +1,107 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
+ */
5
+ /**
6
+ * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
7
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
8
+ */
9
+ /**
10
+ * @module widget/widget
11
+ */
12
+ import { Plugin } from '@ckeditor/ckeditor5-core';
13
+ import { type Element, type Node } from '@ckeditor/ckeditor5-engine';
14
+ import { Delete } from '@ckeditor/ckeditor5-typing';
15
+ import WidgetTypeAround from './widgettypearound/widgettypearound.js';
16
+ import '../theme/widget.css';
17
+ /**
18
+ * The widget plugin. It enables base support for widgets.
19
+ *
20
+ * See {@glink api/widget package page} for more details and documentation.
21
+ *
22
+ * This plugin enables multiple behaviors required by widgets:
23
+ *
24
+ * * The model to view selection converter for the editing pipeline (it handles widget custom selection rendering).
25
+ * If a converted selection wraps around a widget element, that selection is marked as
26
+ * {@link module:engine/view/selection~Selection#isFake fake}. Additionally, the `ck-widget_selected` CSS class
27
+ * is added to indicate that widget has been selected.
28
+ * * The mouse and keyboard events handling on and around widget elements.
29
+ */
30
+ export default class Widget extends Plugin {
31
+ /**
32
+ * Holds previously selected widgets.
33
+ */
34
+ private _previouslySelected;
35
+ /**
36
+ * @inheritDoc
37
+ */
38
+ static get pluginName(): "Widget";
39
+ /**
40
+ * @inheritDoc
41
+ */
42
+ static get requires(): readonly [typeof WidgetTypeAround, typeof Delete];
43
+ /**
44
+ * @inheritDoc
45
+ */
46
+ init(): void;
47
+ /**
48
+ * Handles {@link module:engine/view/document~Document#event:mousedown mousedown} events on widget elements.
49
+ */
50
+ private _onMousedown;
51
+ /**
52
+ * Selects entire block content, e.g. on triple click it selects entire paragraph.
53
+ */
54
+ private _selectBlockContent;
55
+ /**
56
+ * Handles {@link module:engine/view/document~Document#event:keydown keydown} events and changes
57
+ * the model selection when:
58
+ *
59
+ * * arrow key is pressed when the widget is selected,
60
+ * * the selection is next to a widget and the widget should become selected upon the arrow key press.
61
+ *
62
+ * See {@link #_preventDefaultOnArrowKeyPress}.
63
+ */
64
+ private _handleSelectionChangeOnArrowKeyPress;
65
+ /**
66
+ * Handles {@link module:engine/view/document~Document#event:keydown keydown} events and prevents
67
+ * the default browser behavior to make sure the fake selection is not being moved from a fake selection
68
+ * container.
69
+ *
70
+ * See {@link #_handleSelectionChangeOnArrowKeyPress}.
71
+ */
72
+ private _preventDefaultOnArrowKeyPress;
73
+ /**
74
+ * Handles delete keys: backspace and delete.
75
+ *
76
+ * @param isForward Set to true if delete was performed in forward direction.
77
+ * @returns Returns `true` if keys were handled correctly.
78
+ */
79
+ private _handleDelete;
80
+ /**
81
+ * Sets {@link module:engine/model/selection~Selection document's selection} over given element.
82
+ *
83
+ * @internal
84
+ */
85
+ _setSelectionOverElement(element: Node): void;
86
+ /**
87
+ * Checks if {@link module:engine/model/element~Element element} placed next to the current
88
+ * {@link module:engine/model/selection~Selection model selection} exists and is marked in
89
+ * {@link module:engine/model/schema~Schema schema} as `object`.
90
+ *
91
+ * @internal
92
+ * @param forward Direction of checking.
93
+ */
94
+ _getObjectElementNextToSelection(forward: boolean): Element | null;
95
+ /**
96
+ * Removes CSS class from previously selected widgets.
97
+ */
98
+ private _clearPreviouslySelectedWidgets;
99
+ /**
100
+ * Moves the document selection into the first nested editable.
101
+ */
102
+ private _selectFirstNestedEditable;
103
+ /**
104
+ * Updates the document selection so that it selects first ancestor widget.
105
+ */
106
+ private _selectAncestorWidget;
107
+ }
@@ -0,0 +1,181 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
+ */
5
+ /**
6
+ * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
7
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
8
+ */
9
+ import { Rect, type DecoratedMethodEvent } from '@ckeditor/ckeditor5-utils';
10
+ import ResizeState from './resizerstate.js';
11
+ import type { ResizerOptions } from '../widgetresize.js';
12
+ declare const Resizer_base: {
13
+ new (): import("@ckeditor/ckeditor5-utils").Observable;
14
+ prototype: import("@ckeditor/ckeditor5-utils").Observable;
15
+ };
16
+ /**
17
+ * Represents a resizer for a single resizable object.
18
+ */
19
+ export default class Resizer extends Resizer_base {
20
+ /**
21
+ * Flag that indicates whether resizer can be used.
22
+ *
23
+ * @observable
24
+ */
25
+ isEnabled: boolean;
26
+ /**
27
+ * Flag that indicates that resizer is currently focused.
28
+ *
29
+ * @observable
30
+ */
31
+ isSelected: boolean;
32
+ /**
33
+ * Flag that indicates whether resizer is rendered (visible on the screen).
34
+ *
35
+ * @readonly
36
+ * @observable
37
+ */
38
+ isVisible: boolean;
39
+ /**
40
+ * Stores the state of the resizable host geometry, such as the original width, the currently proposed height, etc.
41
+ *
42
+ * Note that a new state is created for each resize transaction.
43
+ */
44
+ private _state;
45
+ /**
46
+ * A view displaying the proposed new element size during the resizing.
47
+ */
48
+ private _sizeView;
49
+ /**
50
+ * Options passed to the {@link #constructor}.
51
+ */
52
+ private _options;
53
+ /**
54
+ * A wrapper that is controlled by the resizer. This is usually a widget element.
55
+ */
56
+ private _viewResizerWrapper;
57
+ /**
58
+ * The width of the resized {@link module:widget/widgetresize~ResizerOptions#viewElement viewElement} before the resizing started.
59
+ */
60
+ private _initialViewWidth;
61
+ /**
62
+ * @param options Resizer options.
63
+ */
64
+ constructor(options: ResizerOptions);
65
+ /**
66
+ * Stores the state of the resizable host geometry, such as the original width, the currently proposed height, etc.
67
+ *
68
+ * Note that a new state is created for each resize transaction.
69
+ */
70
+ get state(): ResizeState;
71
+ /**
72
+ * Makes resizer visible in the UI.
73
+ */
74
+ show(): void;
75
+ /**
76
+ * Hides resizer in the UI.
77
+ */
78
+ hide(): void;
79
+ /**
80
+ * Attaches the resizer to the DOM.
81
+ */
82
+ attach(): void;
83
+ /**
84
+ * Starts the resizing process.
85
+ *
86
+ * Creates a new {@link #state} for the current process.
87
+ *
88
+ * @fires begin
89
+ * @param domResizeHandle Clicked handle.
90
+ */
91
+ begin(domResizeHandle: HTMLElement): void;
92
+ /**
93
+ * Updates the proposed size based on `domEventData`.
94
+ *
95
+ * @fires updateSize
96
+ */
97
+ updateSize(domEventData: MouseEvent): void;
98
+ /**
99
+ * Applies the geometry proposed with the resizer.
100
+ *
101
+ * @fires commit
102
+ */
103
+ commit(): void;
104
+ /**
105
+ * Cancels and rejects the proposed resize dimensions, hiding the UI.
106
+ *
107
+ * @fires cancel
108
+ */
109
+ cancel(): void;
110
+ /**
111
+ * Destroys the resizer.
112
+ */
113
+ destroy(): void;
114
+ /**
115
+ * Redraws the resizer.
116
+ *
117
+ * @param handleHostRect Handle host rectangle might be given to improve performance.
118
+ */
119
+ redraw(handleHostRect?: Rect): void;
120
+ containsHandle(domElement: HTMLElement): boolean;
121
+ static isResizeHandle(domElement: HTMLElement): boolean;
122
+ /**
123
+ * Cleans up the context state.
124
+ */
125
+ private _cleanup;
126
+ /**
127
+ * Calculates the proposed size as the resize handles are dragged.
128
+ *
129
+ * @param domEventData Event data that caused the size update request. It should be used to calculate the proposed size.
130
+ */
131
+ private _proposeNewSize;
132
+ /**
133
+ * Obtains the resize host.
134
+ *
135
+ * Resize host is an object that receives dimensions which are the result of resizing.
136
+ */
137
+ private _getResizeHost;
138
+ /**
139
+ * Obtains the handle host.
140
+ *
141
+ * Handle host is an object that the handles are aligned to.
142
+ *
143
+ * Handle host will not always be an entire widget itself. Take an image as an example. The image widget
144
+ * contains an image and a caption. Only the image should be surrounded with handles.
145
+ */
146
+ private _getHandleHost;
147
+ /**
148
+ * DOM container of the entire resize UI.
149
+ *
150
+ * Note that this property will have a value only after the element bound with the resizer is rendered
151
+ * (otherwise `null`).
152
+ */
153
+ private get _domResizerWrapper();
154
+ /**
155
+ * Renders the resize handles in the DOM.
156
+ *
157
+ * @param domElement The resizer wrapper.
158
+ */
159
+ private _appendHandles;
160
+ /**
161
+ * Sets up the {@link #_sizeView} property and adds it to the passed `domElement`.
162
+ */
163
+ private _appendSizeUI;
164
+ }
165
+ /**
166
+ * @eventName ~Resizer#begin
167
+ */
168
+ export type ResizerBeginEvent = DecoratedMethodEvent<Resizer, 'begin'>;
169
+ /**
170
+ * @eventName ~Resizer#cancel
171
+ */
172
+ export type ResizerCancelEvent = DecoratedMethodEvent<Resizer, 'cancel'>;
173
+ /**
174
+ * @eventName ~Resizer#commit
175
+ */
176
+ export type ResizerCommitEvent = DecoratedMethodEvent<Resizer, 'commit'>;
177
+ /**
178
+ * @eventName ~Resizer#updateSize
179
+ */
180
+ export type ResizerUpdateSizeEvent = DecoratedMethodEvent<Resizer, 'updateSize'>;
181
+ export {};