@ckeditor/ckeditor5-widget 39.0.1 → 40.0.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.
Files changed (81) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/LICENSE.md +1 -1
  3. package/README.md +3 -3
  4. package/lang/translations/ar.po +1 -0
  5. package/lang/translations/az.po +1 -0
  6. package/lang/translations/bg.po +1 -0
  7. package/lang/translations/bn.po +1 -0
  8. package/lang/translations/ca.po +1 -0
  9. package/lang/translations/cs.po +1 -0
  10. package/lang/translations/da.po +1 -0
  11. package/lang/translations/de-ch.po +1 -0
  12. package/lang/translations/de.po +1 -0
  13. package/lang/translations/el.po +1 -0
  14. package/lang/translations/en-au.po +1 -0
  15. package/lang/translations/en.po +1 -0
  16. package/lang/translations/es.po +1 -0
  17. package/lang/translations/et.po +1 -0
  18. package/lang/translations/fa.po +1 -0
  19. package/lang/translations/fi.po +1 -0
  20. package/lang/translations/fr.po +1 -0
  21. package/lang/translations/gl.po +1 -0
  22. package/lang/translations/he.po +1 -0
  23. package/lang/translations/hi.po +1 -0
  24. package/lang/translations/hr.po +1 -0
  25. package/lang/translations/hu.po +1 -0
  26. package/lang/translations/id.po +1 -0
  27. package/lang/translations/it.po +1 -0
  28. package/lang/translations/ja.po +1 -0
  29. package/lang/translations/ko.po +1 -0
  30. package/lang/translations/ku.po +1 -0
  31. package/lang/translations/lt.po +1 -0
  32. package/lang/translations/lv.po +1 -0
  33. package/lang/translations/ms.po +1 -0
  34. package/lang/translations/nl.po +1 -0
  35. package/lang/translations/no.po +1 -0
  36. package/lang/translations/pl.po +1 -0
  37. package/lang/translations/pt-br.po +1 -0
  38. package/lang/translations/pt.po +1 -0
  39. package/lang/translations/ro.po +1 -0
  40. package/lang/translations/ru.po +1 -0
  41. package/lang/translations/sk.po +1 -0
  42. package/lang/translations/sq.po +1 -0
  43. package/lang/translations/sr-latn.po +1 -0
  44. package/lang/translations/sr.po +1 -0
  45. package/lang/translations/sv.po +1 -0
  46. package/lang/translations/th.po +1 -0
  47. package/lang/translations/tk.po +1 -0
  48. package/lang/translations/tr.po +1 -0
  49. package/lang/translations/uk.po +1 -0
  50. package/lang/translations/ur.po +1 -0
  51. package/lang/translations/uz.po +1 -0
  52. package/lang/translations/vi.po +1 -0
  53. package/lang/translations/zh-cn.po +1 -0
  54. package/lang/translations/zh.po +1 -0
  55. package/package.json +7 -11
  56. package/src/augmentation.d.ts +13 -13
  57. package/src/augmentation.js +5 -5
  58. package/src/highlightstack.d.ts +74 -74
  59. package/src/highlightstack.js +129 -129
  60. package/src/index.d.ts +13 -13
  61. package/src/index.js +13 -13
  62. package/src/utils.d.ts +198 -198
  63. package/src/utils.js +348 -348
  64. package/src/verticalnavigation.d.ts +15 -15
  65. package/src/verticalnavigation.js +196 -196
  66. package/src/widget.d.ts +91 -91
  67. package/src/widget.js +380 -380
  68. package/src/widgetresize/resizer.d.ts +177 -177
  69. package/src/widgetresize/resizer.js +372 -372
  70. package/src/widgetresize/resizerstate.d.ts +125 -125
  71. package/src/widgetresize/resizerstate.js +150 -150
  72. package/src/widgetresize/sizeview.d.ts +55 -55
  73. package/src/widgetresize/sizeview.js +63 -63
  74. package/src/widgetresize.d.ts +125 -125
  75. package/src/widgetresize.js +188 -188
  76. package/src/widgettoolbarrepository.d.ts +94 -94
  77. package/src/widgettoolbarrepository.js +268 -268
  78. package/src/widgettypearound/utils.d.ts +38 -38
  79. package/src/widgettypearound/utils.js +52 -52
  80. package/src/widgettypearound/widgettypearound.d.ts +229 -229
  81. package/src/widgettypearound/widgettypearound.js +773 -773
package/src/utils.d.ts CHANGED
@@ -1,198 +1,198 @@
1
- /**
2
- * @license Copyright (c) 2003-2023, 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
- * @module widget/utils
7
- */
8
- import { type GetCallback } from '@ckeditor/ckeditor5-utils';
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
- /**
11
- * CSS class added to each widget element.
12
- */
13
- export declare const WIDGET_CLASS_NAME = "ck-widget";
14
- /**
15
- * CSS class added to currently selected widget element.
16
- */
17
- export declare const WIDGET_SELECTED_CLASS_NAME = "ck-widget_selected";
18
- /**
19
- * Returns `true` if given {@link module:engine/view/node~Node} is an {@link module:engine/view/element~Element} and a widget.
20
- */
21
- export declare function isWidget(node: ViewTypeCheckable): boolean;
22
- /**
23
- * Converts the given {@link module:engine/view/element~Element} to a widget in the following way:
24
- *
25
- * * sets the `contenteditable` attribute to `"false"`,
26
- * * adds the `ck-widget` CSS class,
27
- * * adds a custom {@link module:engine/view/element~Element#getFillerOffset `getFillerOffset()`} method returning `null`,
28
- * * adds a custom property allowing to recognize widget elements by using {@link ~isWidget `isWidget()`},
29
- * * implements the {@link ~setHighlightHandling view highlight on widgets}.
30
- *
31
- * This function needs to be used in conjunction with
32
- * {@link module:engine/conversion/downcasthelpers~DowncastHelpers downcast conversion helpers}
33
- * like {@link module:engine/conversion/downcasthelpers~DowncastHelpers#elementToElement `elementToElement()`}.
34
- * Moreover, typically you will want to use `toWidget()` only for `editingDowncast`, while keeping the `dataDowncast` clean.
35
- *
36
- * For example, in order to convert a `<widget>` model element to `<div class="widget">` in the view, you can define
37
- * such converters:
38
- *
39
- * ```ts
40
- * editor.conversion.for( 'editingDowncast' )
41
- * .elementToElement( {
42
- * model: 'widget',
43
- * view: ( modelItem, { writer } ) => {
44
- * const div = writer.createContainerElement( 'div', { class: 'widget' } );
45
- *
46
- * return toWidget( div, writer, { label: 'some widget' } );
47
- * }
48
- * } );
49
- *
50
- * editor.conversion.for( 'dataDowncast' )
51
- * .elementToElement( {
52
- * model: 'widget',
53
- * view: ( modelItem, { writer } ) => {
54
- * return writer.createContainerElement( 'div', { class: 'widget' } );
55
- * }
56
- * } );
57
- * ```
58
- *
59
- * See the full source code of the widget (with a nested editable) schema definition and converters in
60
- * [this sample](https://github.com/ckeditor/ckeditor5-widget/blob/master/tests/manual/widget-with-nestededitable.js).
61
- *
62
- * @param options Additional options.
63
- * @param options.label Element's label provided to the {@link ~setLabel} function. It can be passed as
64
- * a plain string or a function returning a string. It represents the widget for assistive technologies (like screen readers).
65
- * @param options.hasSelectionHandle If `true`, the widget will have a selection handle added.
66
- * @returns Returns the same element.
67
- */
68
- export declare function toWidget(element: ViewElement, writer: DowncastWriter, options?: {
69
- label?: string | (() => string);
70
- hasSelectionHandle?: boolean;
71
- }): ViewElement;
72
- /**
73
- * Sets highlight handling methods. Uses {@link module:widget/highlightstack~HighlightStack} to
74
- * properly determine which highlight descriptor should be used at given time.
75
- */
76
- 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;
77
- /**
78
- * Sets label for given element.
79
- * It can be passed as a plain string or a function returning a string. Function will be called each time label is retrieved by
80
- * {@link ~getLabel `getLabel()`}.
81
- */
82
- export declare function setLabel(element: ViewElement, labelOrCreator: string | (() => string)): void;
83
- /**
84
- * Returns the label of the provided element.
85
- */
86
- export declare function getLabel(element: ViewElement): string;
87
- /**
88
- * Adds functionality to the provided {@link module:engine/view/editableelement~EditableElement} to act as a widget's editable:
89
- *
90
- * * sets the `contenteditable` attribute to `true` when {@link module:engine/view/editableelement~EditableElement#isReadOnly} is `false`,
91
- * otherwise sets it to `false`,
92
- * * adds the `ck-editor__editable` and `ck-editor__nested-editable` CSS classes,
93
- * * adds the `ck-editor__nested-editable_focused` CSS class when the editable is focused and removes it when it is blurred.
94
- * * implements the {@link ~setHighlightHandling view highlight on widget's editable}.
95
- *
96
- * Similarly to {@link ~toWidget `toWidget()`} this function should be used in `editingDowncast` only and it is usually
97
- * used together with {@link module:engine/conversion/downcasthelpers~DowncastHelpers#elementToElement `elementToElement()`}.
98
- *
99
- * For example, in order to convert a `<nested>` model element to `<div class="nested">` in the view, you can define
100
- * such converters:
101
- *
102
- * ```ts
103
- * editor.conversion.for( 'editingDowncast' )
104
- * .elementToElement( {
105
- * model: 'nested',
106
- * view: ( modelItem, { writer } ) => {
107
- * const div = writer.createEditableElement( 'div', { class: 'nested' } );
108
- *
109
- * return toWidgetEditable( nested, writer, { label: 'label for editable' } );
110
- * }
111
- * } );
112
- *
113
- * editor.conversion.for( 'dataDowncast' )
114
- * .elementToElement( {
115
- * model: 'nested',
116
- * view: ( modelItem, { writer } ) => {
117
- * return writer.createContainerElement( 'div', { class: 'nested' } );
118
- * }
119
- * } );
120
- * ```
121
- *
122
- * See the full source code of the widget (with nested editable) schema definition and converters in
123
- * [this sample](https://github.com/ckeditor/ckeditor5-widget/blob/master/tests/manual/widget-with-nestededitable.js).
124
- *
125
- * @param options Additional options.
126
- * @param options.label Editable's label used by assistive technologies (e.g. screen readers).
127
- * @returns Returns the same element that was provided in the `editable` parameter
128
- */
129
- export declare function toWidgetEditable(editable: ViewEditableElement, writer: DowncastWriter, options?: {
130
- label?: string;
131
- }): ViewEditableElement;
132
- /**
133
- * Returns a model range which is optimal (in terms of UX) for inserting a widget block.
134
- *
135
- * For instance, if a selection is in the middle of a paragraph, the collapsed range before this paragraph
136
- * will be returned so that it is not split. If the selection is at the end of a paragraph,
137
- * the collapsed range after this paragraph will be returned.
138
- *
139
- * Note: If the selection is placed in an empty block, the range in that block will be returned. If that range
140
- * is then passed to {@link module:engine/model/model~Model#insertContent}, the block will be fully replaced
141
- * by the inserted widget block.
142
- *
143
- * @param selection The selection based on which the insertion position should be calculated.
144
- * @param model Model instance.
145
- * @returns The optimal range.
146
- */
147
- export declare function findOptimalInsertionRange(selection: Selection | DocumentSelection, model: Model): Range;
148
- /**
149
- * A util to be used in order to map view positions to correct model positions when implementing a widget
150
- * which renders non-empty view element for an empty model element.
151
- *
152
- * For example:
153
- *
154
- * ```
155
- * // Model:
156
- * <placeholder type="name"></placeholder>
157
- *
158
- * // View:
159
- * <span class="placeholder">name</span>
160
- * ```
161
- *
162
- * In such case, view positions inside `<span>` cannot be correctly mapped to the model (because the model element is empty).
163
- * To handle mapping positions inside `<span class="placeholder">` to the model use this util as follows:
164
- *
165
- * ```ts
166
- * editor.editing.mapper.on(
167
- * 'viewToModelPosition',
168
- * viewToModelPositionOutsideModelElement( model, viewElement => viewElement.hasClass( 'placeholder' ) )
169
- * );
170
- * ```
171
- *
172
- * The callback will try to map the view offset of selection to an expected model position.
173
- *
174
- * 1. When the position is at the end (or in the middle) of the inline widget:
175
- *
176
- * ```
177
- * // View:
178
- * <p>foo <span class="placeholder">name|</span> bar</p>
179
- *
180
- * // Model:
181
- * <paragraph>foo <placeholder type="name"></placeholder>| bar</paragraph>
182
- * ```
183
- *
184
- * 2. When the position is at the beginning of the inline widget:
185
- *
186
- * ```
187
- * // View:
188
- * <p>foo <span class="placeholder">|name</span> bar</p>
189
- *
190
- * // Model:
191
- * <paragraph>foo |<placeholder type="name"></placeholder> bar</paragraph>
192
- * ```
193
- *
194
- * @param model Model instance on which the callback operates.
195
- * @param viewElementMatcher Function that is passed a view element and should return `true` if the custom mapping
196
- * should be applied to the given view element.
197
- */
198
- export declare function viewToModelPositionOutsideModelElement(model: Model, viewElementMatcher: (element: ViewElement) => boolean): GetCallback<MapperViewToModelPositionEvent>;
1
+ /**
2
+ * @license Copyright (c) 2003-2023, 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
+ * @module widget/utils
7
+ */
8
+ import { type GetCallback } from '@ckeditor/ckeditor5-utils';
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
+ /**
11
+ * CSS class added to each widget element.
12
+ */
13
+ export declare const WIDGET_CLASS_NAME = "ck-widget";
14
+ /**
15
+ * CSS class added to currently selected widget element.
16
+ */
17
+ export declare const WIDGET_SELECTED_CLASS_NAME = "ck-widget_selected";
18
+ /**
19
+ * Returns `true` if given {@link module:engine/view/node~Node} is an {@link module:engine/view/element~Element} and a widget.
20
+ */
21
+ export declare function isWidget(node: ViewTypeCheckable): boolean;
22
+ /**
23
+ * Converts the given {@link module:engine/view/element~Element} to a widget in the following way:
24
+ *
25
+ * * sets the `contenteditable` attribute to `"false"`,
26
+ * * adds the `ck-widget` CSS class,
27
+ * * adds a custom {@link module:engine/view/element~Element#getFillerOffset `getFillerOffset()`} method returning `null`,
28
+ * * adds a custom property allowing to recognize widget elements by using {@link ~isWidget `isWidget()`},
29
+ * * implements the {@link ~setHighlightHandling view highlight on widgets}.
30
+ *
31
+ * This function needs to be used in conjunction with
32
+ * {@link module:engine/conversion/downcasthelpers~DowncastHelpers downcast conversion helpers}
33
+ * like {@link module:engine/conversion/downcasthelpers~DowncastHelpers#elementToElement `elementToElement()`}.
34
+ * Moreover, typically you will want to use `toWidget()` only for `editingDowncast`, while keeping the `dataDowncast` clean.
35
+ *
36
+ * For example, in order to convert a `<widget>` model element to `<div class="widget">` in the view, you can define
37
+ * such converters:
38
+ *
39
+ * ```ts
40
+ * editor.conversion.for( 'editingDowncast' )
41
+ * .elementToElement( {
42
+ * model: 'widget',
43
+ * view: ( modelItem, { writer } ) => {
44
+ * const div = writer.createContainerElement( 'div', { class: 'widget' } );
45
+ *
46
+ * return toWidget( div, writer, { label: 'some widget' } );
47
+ * }
48
+ * } );
49
+ *
50
+ * editor.conversion.for( 'dataDowncast' )
51
+ * .elementToElement( {
52
+ * model: 'widget',
53
+ * view: ( modelItem, { writer } ) => {
54
+ * return writer.createContainerElement( 'div', { class: 'widget' } );
55
+ * }
56
+ * } );
57
+ * ```
58
+ *
59
+ * See the full source code of the widget (with a nested editable) schema definition and converters in
60
+ * [this sample](https://github.com/ckeditor/ckeditor5-widget/blob/master/tests/manual/widget-with-nestededitable.js).
61
+ *
62
+ * @param options Additional options.
63
+ * @param options.label Element's label provided to the {@link ~setLabel} function. It can be passed as
64
+ * a plain string or a function returning a string. It represents the widget for assistive technologies (like screen readers).
65
+ * @param options.hasSelectionHandle If `true`, the widget will have a selection handle added.
66
+ * @returns Returns the same element.
67
+ */
68
+ export declare function toWidget(element: ViewElement, writer: DowncastWriter, options?: {
69
+ label?: string | (() => string);
70
+ hasSelectionHandle?: boolean;
71
+ }): ViewElement;
72
+ /**
73
+ * Sets highlight handling methods. Uses {@link module:widget/highlightstack~HighlightStack} to
74
+ * properly determine which highlight descriptor should be used at given time.
75
+ */
76
+ 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;
77
+ /**
78
+ * Sets label for given element.
79
+ * It can be passed as a plain string or a function returning a string. Function will be called each time label is retrieved by
80
+ * {@link ~getLabel `getLabel()`}.
81
+ */
82
+ export declare function setLabel(element: ViewElement, labelOrCreator: string | (() => string)): void;
83
+ /**
84
+ * Returns the label of the provided element.
85
+ */
86
+ export declare function getLabel(element: ViewElement): string;
87
+ /**
88
+ * Adds functionality to the provided {@link module:engine/view/editableelement~EditableElement} to act as a widget's editable:
89
+ *
90
+ * * sets the `contenteditable` attribute to `true` when {@link module:engine/view/editableelement~EditableElement#isReadOnly} is `false`,
91
+ * otherwise sets it to `false`,
92
+ * * adds the `ck-editor__editable` and `ck-editor__nested-editable` CSS classes,
93
+ * * adds the `ck-editor__nested-editable_focused` CSS class when the editable is focused and removes it when it is blurred.
94
+ * * implements the {@link ~setHighlightHandling view highlight on widget's editable}.
95
+ *
96
+ * Similarly to {@link ~toWidget `toWidget()`} this function should be used in `editingDowncast` only and it is usually
97
+ * used together with {@link module:engine/conversion/downcasthelpers~DowncastHelpers#elementToElement `elementToElement()`}.
98
+ *
99
+ * For example, in order to convert a `<nested>` model element to `<div class="nested">` in the view, you can define
100
+ * such converters:
101
+ *
102
+ * ```ts
103
+ * editor.conversion.for( 'editingDowncast' )
104
+ * .elementToElement( {
105
+ * model: 'nested',
106
+ * view: ( modelItem, { writer } ) => {
107
+ * const div = writer.createEditableElement( 'div', { class: 'nested' } );
108
+ *
109
+ * return toWidgetEditable( nested, writer, { label: 'label for editable' } );
110
+ * }
111
+ * } );
112
+ *
113
+ * editor.conversion.for( 'dataDowncast' )
114
+ * .elementToElement( {
115
+ * model: 'nested',
116
+ * view: ( modelItem, { writer } ) => {
117
+ * return writer.createContainerElement( 'div', { class: 'nested' } );
118
+ * }
119
+ * } );
120
+ * ```
121
+ *
122
+ * See the full source code of the widget (with nested editable) schema definition and converters in
123
+ * [this sample](https://github.com/ckeditor/ckeditor5-widget/blob/master/tests/manual/widget-with-nestededitable.js).
124
+ *
125
+ * @param options Additional options.
126
+ * @param options.label Editable's label used by assistive technologies (e.g. screen readers).
127
+ * @returns Returns the same element that was provided in the `editable` parameter
128
+ */
129
+ export declare function toWidgetEditable(editable: ViewEditableElement, writer: DowncastWriter, options?: {
130
+ label?: string;
131
+ }): ViewEditableElement;
132
+ /**
133
+ * Returns a model range which is optimal (in terms of UX) for inserting a widget block.
134
+ *
135
+ * For instance, if a selection is in the middle of a paragraph, the collapsed range before this paragraph
136
+ * will be returned so that it is not split. If the selection is at the end of a paragraph,
137
+ * the collapsed range after this paragraph will be returned.
138
+ *
139
+ * Note: If the selection is placed in an empty block, the range in that block will be returned. If that range
140
+ * is then passed to {@link module:engine/model/model~Model#insertContent}, the block will be fully replaced
141
+ * by the inserted widget block.
142
+ *
143
+ * @param selection The selection based on which the insertion position should be calculated.
144
+ * @param model Model instance.
145
+ * @returns The optimal range.
146
+ */
147
+ export declare function findOptimalInsertionRange(selection: Selection | DocumentSelection, model: Model): Range;
148
+ /**
149
+ * A util to be used in order to map view positions to correct model positions when implementing a widget
150
+ * which renders non-empty view element for an empty model element.
151
+ *
152
+ * For example:
153
+ *
154
+ * ```
155
+ * // Model:
156
+ * <placeholder type="name"></placeholder>
157
+ *
158
+ * // View:
159
+ * <span class="placeholder">name</span>
160
+ * ```
161
+ *
162
+ * In such case, view positions inside `<span>` cannot be correctly mapped to the model (because the model element is empty).
163
+ * To handle mapping positions inside `<span class="placeholder">` to the model use this util as follows:
164
+ *
165
+ * ```ts
166
+ * editor.editing.mapper.on(
167
+ * 'viewToModelPosition',
168
+ * viewToModelPositionOutsideModelElement( model, viewElement => viewElement.hasClass( 'placeholder' ) )
169
+ * );
170
+ * ```
171
+ *
172
+ * The callback will try to map the view offset of selection to an expected model position.
173
+ *
174
+ * 1. When the position is at the end (or in the middle) of the inline widget:
175
+ *
176
+ * ```
177
+ * // View:
178
+ * <p>foo <span class="placeholder">name|</span> bar</p>
179
+ *
180
+ * // Model:
181
+ * <paragraph>foo <placeholder type="name"></placeholder>| bar</paragraph>
182
+ * ```
183
+ *
184
+ * 2. When the position is at the beginning of the inline widget:
185
+ *
186
+ * ```
187
+ * // View:
188
+ * <p>foo <span class="placeholder">|name</span> bar</p>
189
+ *
190
+ * // Model:
191
+ * <paragraph>foo |<placeholder type="name"></placeholder> bar</paragraph>
192
+ * ```
193
+ *
194
+ * @param model Model instance on which the callback operates.
195
+ * @param viewElementMatcher Function that is passed a view element and should return `true` if the custom mapping
196
+ * should be applied to the given view element.
197
+ */
198
+ export declare function viewToModelPositionOutsideModelElement(model: Model, viewElementMatcher: (element: ViewElement) => boolean): GetCallback<MapperViewToModelPositionEvent>;