@ckeditor/ckeditor5-table 36.0.1 → 37.0.0-alpha.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 (166) hide show
  1. package/build/table.js +1 -1
  2. package/package.json +34 -29
  3. package/src/commands/insertcolumncommand.d.ts +61 -0
  4. package/src/commands/insertcolumncommand.js +45 -60
  5. package/src/commands/insertrowcommand.d.ts +60 -0
  6. package/src/commands/insertrowcommand.js +44 -59
  7. package/src/commands/inserttablecommand.d.ts +50 -0
  8. package/src/commands/inserttablecommand.js +51 -68
  9. package/src/commands/mergecellcommand.d.ts +76 -0
  10. package/src/commands/mergecellcommand.js +169 -244
  11. package/src/commands/mergecellscommand.d.ts +33 -0
  12. package/src/commands/mergecellscommand.js +72 -101
  13. package/src/commands/removecolumncommand.d.ts +34 -0
  14. package/src/commands/removecolumncommand.js +88 -102
  15. package/src/commands/removerowcommand.d.ts +34 -0
  16. package/src/commands/removerowcommand.js +63 -80
  17. package/src/commands/selectcolumncommand.d.ts +38 -0
  18. package/src/commands/selectcolumncommand.js +41 -54
  19. package/src/commands/selectrowcommand.d.ts +38 -0
  20. package/src/commands/selectrowcommand.js +38 -48
  21. package/src/commands/setheadercolumncommand.d.ts +55 -0
  22. package/src/commands/setheadercolumncommand.js +48 -73
  23. package/src/commands/setheaderrowcommand.d.ts +58 -0
  24. package/src/commands/setheaderrowcommand.js +56 -85
  25. package/src/commands/splitcellcommand.d.ts +49 -0
  26. package/src/commands/splitcellcommand.js +35 -49
  27. package/src/converters/downcast.d.ts +63 -0
  28. package/src/converters/downcast.js +98 -130
  29. package/src/converters/table-caption-post-fixer.d.ts +20 -0
  30. package/src/converters/table-caption-post-fixer.js +36 -52
  31. package/src/converters/table-cell-paragraph-post-fixer.d.ts +32 -0
  32. package/src/converters/table-cell-paragraph-post-fixer.js +88 -119
  33. package/src/converters/table-cell-refresh-handler.d.ts +18 -0
  34. package/src/converters/table-cell-refresh-handler.js +29 -48
  35. package/src/converters/table-headings-refresh-handler.d.ts +17 -0
  36. package/src/converters/table-headings-refresh-handler.js +35 -54
  37. package/src/converters/table-layout-post-fixer.d.ts +226 -0
  38. package/src/converters/table-layout-post-fixer.js +276 -313
  39. package/src/converters/tableproperties.d.ts +54 -0
  40. package/src/converters/tableproperties.js +136 -168
  41. package/src/converters/upcasttable.d.ts +49 -0
  42. package/src/converters/upcasttable.js +196 -251
  43. package/src/index.d.ts +29 -0
  44. package/src/index.js +0 -2
  45. package/src/plaintableoutput.d.ts +30 -0
  46. package/src/plaintableoutput.js +107 -135
  47. package/src/table.d.ts +38 -0
  48. package/src/table.js +12 -88
  49. package/src/tablecaption/tablecaptionediting.d.ts +68 -0
  50. package/src/tablecaption/tablecaptionediting.js +104 -135
  51. package/src/tablecaption/tablecaptionui.d.ts +26 -0
  52. package/src/tablecaption/tablecaptionui.js +42 -58
  53. package/src/tablecaption/toggletablecaptioncommand.d.ts +73 -0
  54. package/src/tablecaption/toggletablecaptioncommand.js +77 -92
  55. package/src/tablecaption/utils.d.ts +42 -0
  56. package/src/tablecaption/utils.js +35 -61
  57. package/src/tablecaption.d.ts +27 -0
  58. package/src/tablecaption.js +12 -19
  59. package/src/tablecellproperties/commands/tablecellbackgroundcolorcommand.d.ts +37 -0
  60. package/src/tablecellproperties/commands/tablecellbackgroundcolorcommand.js +14 -20
  61. package/src/tablecellproperties/commands/tablecellbordercolorcommand.d.ts +42 -0
  62. package/src/tablecellproperties/commands/tablecellbordercolorcommand.js +27 -37
  63. package/src/tablecellproperties/commands/tablecellborderstylecommand.d.ts +42 -0
  64. package/src/tablecellproperties/commands/tablecellborderstylecommand.js +27 -37
  65. package/src/tablecellproperties/commands/tablecellborderwidthcommand.d.ts +56 -0
  66. package/src/tablecellproperties/commands/tablecellborderwidthcommand.js +42 -53
  67. package/src/tablecellproperties/commands/tablecellheightcommand.d.ts +51 -0
  68. package/src/tablecellproperties/commands/tablecellheightcommand.js +29 -36
  69. package/src/tablecellproperties/commands/tablecellhorizontalalignmentcommand.d.ts +37 -0
  70. package/src/tablecellproperties/commands/tablecellhorizontalalignmentcommand.js +14 -20
  71. package/src/tablecellproperties/commands/tablecellpaddingcommand.d.ts +56 -0
  72. package/src/tablecellproperties/commands/tablecellpaddingcommand.js +42 -53
  73. package/src/tablecellproperties/commands/tablecellpropertycommand.d.ts +62 -0
  74. package/src/tablecellproperties/commands/tablecellpropertycommand.js +77 -122
  75. package/src/tablecellproperties/commands/tablecellverticalalignmentcommand.d.ts +45 -0
  76. package/src/tablecellproperties/commands/tablecellverticalalignmentcommand.js +14 -20
  77. package/src/tablecellproperties/tablecellpropertiesediting.d.ts +47 -0
  78. package/src/tablecellproperties/tablecellpropertiesediting.js +194 -236
  79. package/src/tablecellproperties/tablecellpropertiesui.d.ts +117 -0
  80. package/src/tablecellproperties/tablecellpropertiesui.js +303 -456
  81. package/src/tablecellproperties/ui/tablecellpropertiesview.d.ts +227 -0
  82. package/src/tablecellproperties/ui/tablecellpropertiesview.js +509 -844
  83. package/src/tablecellproperties.d.ts +33 -0
  84. package/src/tablecellproperties.js +12 -98
  85. package/src/tablecellwidth/commands/tablecellwidthcommand.d.ts +51 -0
  86. package/src/tablecellwidth/commands/tablecellwidthcommand.js +29 -35
  87. package/src/tablecellwidth/tablecellwidthediting.d.ts +34 -0
  88. package/src/tablecellwidth/tablecellwidthediting.js +26 -38
  89. package/src/tableclipboard.d.ts +68 -0
  90. package/src/tableclipboard.js +429 -568
  91. package/src/tablecolumnresize/constants.d.ts +20 -0
  92. package/src/tablecolumnresize/constants.js +0 -10
  93. package/src/tablecolumnresize/converters.d.ts +18 -0
  94. package/src/tablecolumnresize/converters.js +35 -119
  95. package/src/tablecolumnresize/tablecolumnresizeediting.d.ts +142 -0
  96. package/src/tablecolumnresize/tablecolumnresizeediting.js +545 -711
  97. package/src/tablecolumnresize/tablewidthscommand.d.ts +38 -0
  98. package/src/tablecolumnresize/tablewidthscommand.js +61 -0
  99. package/src/tablecolumnresize/utils.d.ts +141 -0
  100. package/src/tablecolumnresize/utils.js +256 -233
  101. package/src/tablecolumnresize.d.ts +29 -0
  102. package/src/tablecolumnresize.js +12 -19
  103. package/src/tableconfig.d.ts +341 -0
  104. package/src/tableconfig.js +5 -0
  105. package/src/tableediting.d.ts +102 -0
  106. package/src/tableediting.js +157 -176
  107. package/src/tablekeyboard.d.ts +68 -0
  108. package/src/tablekeyboard.js +261 -344
  109. package/src/tablemouse/mouseeventsobserver.d.ts +62 -0
  110. package/src/tablemouse/mouseeventsobserver.js +12 -49
  111. package/src/tablemouse.d.ts +51 -0
  112. package/src/tablemouse.js +154 -202
  113. package/src/tableproperties/commands/tablealignmentcommand.d.ts +37 -0
  114. package/src/tableproperties/commands/tablealignmentcommand.js +14 -20
  115. package/src/tableproperties/commands/tablebackgroundcolorcommand.d.ts +37 -0
  116. package/src/tableproperties/commands/tablebackgroundcolorcommand.js +14 -20
  117. package/src/tableproperties/commands/tablebordercolorcommand.d.ts +42 -0
  118. package/src/tableproperties/commands/tablebordercolorcommand.js +27 -37
  119. package/src/tableproperties/commands/tableborderstylecommand.d.ts +42 -0
  120. package/src/tableproperties/commands/tableborderstylecommand.js +27 -37
  121. package/src/tableproperties/commands/tableborderwidthcommand.d.ts +56 -0
  122. package/src/tableproperties/commands/tableborderwidthcommand.js +42 -53
  123. package/src/tableproperties/commands/tableheightcommand.d.ts +51 -0
  124. package/src/tableproperties/commands/tableheightcommand.js +29 -33
  125. package/src/tableproperties/commands/tablepropertycommand.d.ts +61 -0
  126. package/src/tableproperties/commands/tablepropertycommand.js +68 -112
  127. package/src/tableproperties/commands/tablewidthcommand.d.ts +51 -0
  128. package/src/tableproperties/commands/tablewidthcommand.js +29 -33
  129. package/src/tableproperties/tablepropertiesediting.d.ts +45 -0
  130. package/src/tableproperties/tablepropertiesediting.js +164 -210
  131. package/src/tableproperties/tablepropertiesui.d.ts +119 -0
  132. package/src/tableproperties/tablepropertiesui.js +294 -439
  133. package/src/tableproperties/ui/tablepropertiesview.d.ts +203 -0
  134. package/src/tableproperties/ui/tablepropertiesview.js +427 -718
  135. package/src/tableproperties.d.ts +33 -0
  136. package/src/tableproperties.js +12 -95
  137. package/src/tableselection.d.ts +111 -0
  138. package/src/tableselection.js +279 -376
  139. package/src/tabletoolbar.d.ts +37 -0
  140. package/src/tabletoolbar.js +39 -92
  141. package/src/tableui.d.ts +58 -0
  142. package/src/tableui.js +281 -338
  143. package/src/tableutils.d.ts +453 -0
  144. package/src/tableutils.js +1015 -1229
  145. package/src/tablewalker.d.ts +323 -0
  146. package/src/tablewalker.js +308 -548
  147. package/src/ui/colorinputview.d.ts +143 -0
  148. package/src/ui/colorinputview.js +229 -366
  149. package/src/ui/formrowview.d.ts +61 -0
  150. package/src/ui/formrowview.js +38 -84
  151. package/src/ui/inserttableview.d.ts +77 -0
  152. package/src/ui/inserttableview.js +152 -242
  153. package/src/utils/common.d.ts +42 -0
  154. package/src/utils/common.js +33 -57
  155. package/src/utils/structure.d.ts +245 -0
  156. package/src/utils/structure.js +261 -379
  157. package/src/utils/table-properties.d.ts +67 -0
  158. package/src/utils/table-properties.js +60 -81
  159. package/src/utils/ui/contextualballoon.d.ts +34 -0
  160. package/src/utils/ui/contextualballoon.js +70 -89
  161. package/src/utils/ui/table-properties.d.ts +193 -0
  162. package/src/utils/ui/table-properties.js +259 -319
  163. package/src/utils/ui/widget.d.ts +16 -0
  164. package/src/utils/ui/widget.js +24 -46
  165. package/src/tablecolumnresize/tablecolumnwidthscommand.js +0 -55
  166. package/src/tablecolumnresize/tablewidthresizecommand.js +0 -65
@@ -0,0 +1,67 @@
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 table/utils/table-properties
7
+ */
8
+ import type { BoxSides } from 'ckeditor5/src/engine';
9
+ /**
10
+ * Returns a string if all four values of box sides are equal.
11
+ *
12
+ * If a string is passed, it is treated as a single value (pass-through).
13
+ *
14
+ * ```ts
15
+ * // Returns 'foo':
16
+ * getSingleValue( { top: 'foo', right: 'foo', bottom: 'foo', left: 'foo' } );
17
+ * getSingleValue( 'foo' );
18
+ *
19
+ * // Returns undefined:
20
+ * getSingleValue( { top: 'foo', right: 'foo', bottom: 'bar', left: 'foo' } );
21
+ * getSingleValue( { top: 'foo', right: 'foo' } );
22
+ * ```
23
+ */
24
+ export declare function getSingleValue(objectOrString: BoxSides | string | undefined): string | undefined;
25
+ /**
26
+ * Adds a unit to a value if the value is a number or a string representing a number.
27
+ *
28
+ * **Note**: It does nothing to non-numeric values.
29
+ *
30
+ * ```ts
31
+ * getSingleValue( 25, 'px' ); // '25px'
32
+ * getSingleValue( 25, 'em' ); // '25em'
33
+ * getSingleValue( '25em', 'px' ); // '25em'
34
+ * getSingleValue( 'foo', 'px' ); // 'foo'
35
+ * ```
36
+ *
37
+ * @param defaultUnit A default unit added to a numeric value.
38
+ */
39
+ export declare function addDefaultUnitToNumericValue(value: string | number | undefined, defaultUnit: string): string | number | undefined;
40
+ export interface NormalizedDefaultProperties {
41
+ borderStyle: string;
42
+ borderWidth: string;
43
+ borderColor: string;
44
+ backgroundColor: string;
45
+ width: string;
46
+ height: string;
47
+ alignment?: string;
48
+ padding?: string;
49
+ verticalAlignment?: string;
50
+ horizontalAlignment?: string;
51
+ }
52
+ /**
53
+ * Returns the normalized configuration.
54
+ *
55
+ * @param options.includeAlignmentProperty Whether the "alignment" property should be added.
56
+ * @param options.includePaddingProperty Whether the "padding" property should be added.
57
+ * @param options.includeVerticalAlignmentProperty Whether the "verticalAlignment" property should be added.
58
+ * @param options.includeHorizontalAlignmentProperty Whether the "horizontalAlignment" property should be added.
59
+ * @param options.isRightToLeftContent Whether the content is right-to-left.
60
+ */
61
+ export declare function getNormalizedDefaultProperties(config: Partial<NormalizedDefaultProperties> | undefined, options?: {
62
+ includeAlignmentProperty?: boolean;
63
+ includePaddingProperty?: boolean;
64
+ includeVerticalAlignmentProperty?: boolean;
65
+ includeHorizontalAlignmentProperty?: boolean;
66
+ isRightToLeftContent?: boolean;
67
+ }): NormalizedDefaultProperties;
@@ -2,106 +2,85 @@
2
2
  * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
4
  */
5
-
6
- /**
7
- * @module table/utils/table-properties
8
- */
9
-
10
5
  import { isObject } from 'lodash-es';
11
-
12
6
  /**
13
7
  * Returns a string if all four values of box sides are equal.
14
8
  *
15
9
  * If a string is passed, it is treated as a single value (pass-through).
16
10
  *
17
- * // Returns 'foo':
18
- * getSingleValue( { top: 'foo', right: 'foo', bottom: 'foo', left: 'foo' } );
19
- * getSingleValue( 'foo' );
20
- *
21
- * // Returns undefined:
22
- * getSingleValue( { top: 'foo', right: 'foo', bottom: 'bar', left: 'foo' } );
23
- * getSingleValue( { top: 'foo', right: 'foo' } );
11
+ * ```ts
12
+ * // Returns 'foo':
13
+ * getSingleValue( { top: 'foo', right: 'foo', bottom: 'foo', left: 'foo' } );
14
+ * getSingleValue( 'foo' );
24
15
  *
25
- * @param objectOrString
26
- * @returns {module:engine/view/stylesmap~BoxSides|String}
16
+ * // Returns undefined:
17
+ * getSingleValue( { top: 'foo', right: 'foo', bottom: 'bar', left: 'foo' } );
18
+ * getSingleValue( { top: 'foo', right: 'foo' } );
19
+ * ```
27
20
  */
28
- export function getSingleValue( objectOrString ) {
29
- if ( !objectOrString || !isObject( objectOrString ) ) {
30
- return objectOrString;
31
- }
32
-
33
- const { top, right, bottom, left } = objectOrString;
34
-
35
- if ( top == right && right == bottom && bottom == left ) {
36
- return top;
37
- }
21
+ export function getSingleValue(objectOrString) {
22
+ if (!objectOrString || !isObject(objectOrString)) {
23
+ return objectOrString;
24
+ }
25
+ const { top, right, bottom, left } = objectOrString;
26
+ if (top == right && right == bottom && bottom == left) {
27
+ return top;
28
+ }
38
29
  }
39
-
40
30
  /**
41
31
  * Adds a unit to a value if the value is a number or a string representing a number.
42
32
  *
43
33
  * **Note**: It does nothing to non-numeric values.
44
34
  *
45
- * getSingleValue( 25, 'px' ); // '25px'
46
- * getSingleValue( 25, 'em' ); // '25em'
47
- * getSingleValue( '25em', 'px' ); // '25em'
48
- * getSingleValue( 'foo', 'px' ); // 'foo'
35
+ * ```ts
36
+ * getSingleValue( 25, 'px' ); // '25px'
37
+ * getSingleValue( 25, 'em' ); // '25em'
38
+ * getSingleValue( '25em', 'px' ); // '25em'
39
+ * getSingleValue( 'foo', 'px' ); // 'foo'
40
+ * ```
49
41
  *
50
- * @param {*} value
51
- * @param {String} defaultUnit A default unit added to a numeric value.
52
- * @returns {String|*}
42
+ * @param defaultUnit A default unit added to a numeric value.
53
43
  */
54
- export function addDefaultUnitToNumericValue( value, defaultUnit ) {
55
- const numericValue = parseFloat( value );
56
-
57
- if ( Number.isNaN( numericValue ) ) {
58
- return value;
59
- }
60
-
61
- if ( String( numericValue ) !== String( value ) ) {
62
- return value;
63
- }
64
-
65
- return `${ numericValue }${ defaultUnit }`;
44
+ export function addDefaultUnitToNumericValue(value, defaultUnit) {
45
+ const numericValue = parseFloat(value);
46
+ if (Number.isNaN(numericValue)) {
47
+ return value;
48
+ }
49
+ if (String(numericValue) !== String(value)) {
50
+ return value;
51
+ }
52
+ return `${numericValue}${defaultUnit}`;
66
53
  }
67
-
68
54
  /**
69
55
  * Returns the normalized configuration.
70
56
  *
71
- * @param {Object} config
72
- * @param {Object} [options={}]
73
- * @param {Boolean} [options.includeAlignmentProperty=false] Whether the "alignment" property should be added.
74
- * @param {Boolean} [options.includePaddingProperty=false] Whether the "padding" property should be added.
75
- * @param {Boolean} [options.includeVerticalAlignmentProperty=false] Whether the "verticalAlignment" property should be added.
76
- * @param {Boolean} [options.includeHorizontalAlignmentProperty=false] Whether the "horizontalAlignment" property should be added.
77
- * @param {Boolean} [options.isRightToLeftContent=false] Whether the content is right-to-left.
78
- * @returns {Object}
57
+ * @param options.includeAlignmentProperty Whether the "alignment" property should be added.
58
+ * @param options.includePaddingProperty Whether the "padding" property should be added.
59
+ * @param options.includeVerticalAlignmentProperty Whether the "verticalAlignment" property should be added.
60
+ * @param options.includeHorizontalAlignmentProperty Whether the "horizontalAlignment" property should be added.
61
+ * @param options.isRightToLeftContent Whether the content is right-to-left.
79
62
  */
80
- export function getNormalizedDefaultProperties( config, options = {} ) {
81
- const normalizedConfig = Object.assign( {
82
- borderStyle: 'none',
83
- borderWidth: '',
84
- borderColor: '',
85
- backgroundColor: '',
86
- width: '',
87
- height: ''
88
- }, config );
89
-
90
- if ( options.includeAlignmentProperty && !normalizedConfig.alignment ) {
91
- normalizedConfig.alignment = 'center';
92
- }
93
-
94
- if ( options.includePaddingProperty && !normalizedConfig.padding ) {
95
- normalizedConfig.padding = '';
96
- }
97
-
98
- if ( options.includeVerticalAlignmentProperty && !normalizedConfig.verticalAlignment ) {
99
- normalizedConfig.verticalAlignment = 'middle';
100
- }
101
-
102
- if ( options.includeHorizontalAlignmentProperty && !normalizedConfig.horizontalAlignment ) {
103
- normalizedConfig.horizontalAlignment = options.isRightToLeftContent ? 'right' : 'left';
104
- }
105
-
106
- return normalizedConfig;
63
+ export function getNormalizedDefaultProperties(config, options = {}) {
64
+ const normalizedConfig = {
65
+ borderStyle: 'none',
66
+ borderWidth: '',
67
+ borderColor: '',
68
+ backgroundColor: '',
69
+ width: '',
70
+ height: '',
71
+ ...config
72
+ };
73
+ if (options.includeAlignmentProperty && !normalizedConfig.alignment) {
74
+ normalizedConfig.alignment = 'center';
75
+ }
76
+ if (options.includePaddingProperty && !normalizedConfig.padding) {
77
+ normalizedConfig.padding = '';
78
+ }
79
+ if (options.includeVerticalAlignmentProperty && !normalizedConfig.verticalAlignment) {
80
+ normalizedConfig.verticalAlignment = 'middle';
81
+ }
82
+ if (options.includeHorizontalAlignmentProperty && !normalizedConfig.horizontalAlignment) {
83
+ normalizedConfig.horizontalAlignment = options.isRightToLeftContent ? 'right' : 'left';
84
+ }
85
+ return normalizedConfig;
107
86
  }
@@ -0,0 +1,34 @@
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 table/utils/ui/contextualballoon
7
+ */
8
+ import { type PositionOptions } from 'ckeditor5/src/utils';
9
+ import type { Editor } from 'ckeditor5/src/core';
10
+ /**
11
+ * A helper utility that positions the
12
+ * {@link module:ui/panel/balloon/contextualballoon~ContextualBalloon contextual balloon} instance
13
+ * with respect to the table in the editor content, if one is selected.
14
+ *
15
+ * @param editor The editor instance.
16
+ * @param target Either "cell" or "table". Determines the target the balloon will be attached to.
17
+ */
18
+ export declare function repositionContextualBalloon(editor: Editor, target: string): void;
19
+ /**
20
+ * Returns the positioning options that control the geometry of the
21
+ * {@link module:ui/panel/balloon/contextualballoon~ContextualBalloon contextual balloon} with respect
22
+ * to the selected table in the editor content.
23
+ *
24
+ * @param editor The editor instance.
25
+ */
26
+ export declare function getBalloonTablePositionData(editor: Editor): Partial<PositionOptions>;
27
+ /**
28
+ * Returns the positioning options that control the geometry of the
29
+ * {@link module:ui/panel/balloon/contextualballoon~ContextualBalloon contextual balloon} with respect
30
+ * to the selected table cell in the editor content.
31
+ *
32
+ * @param editor The editor instance.
33
+ */
34
+ export declare function getBalloonCellPositionData(editor: Editor): Partial<PositionOptions>;
@@ -2,124 +2,105 @@
2
2
  * @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
3
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
4
  */
5
-
6
5
  /**
7
6
  * @module table/utils/ui/contextualballoon
8
7
  */
9
-
10
8
  import { Rect } from 'ckeditor5/src/utils';
11
9
  import { BalloonPanelView } from 'ckeditor5/src/ui';
12
-
13
10
  import { getTableWidgetAncestor } from './widget';
14
-
15
11
  const DEFAULT_BALLOON_POSITIONS = BalloonPanelView.defaultPositions;
16
-
17
12
  const BALLOON_POSITIONS = [
18
- DEFAULT_BALLOON_POSITIONS.northArrowSouth,
19
- DEFAULT_BALLOON_POSITIONS.northArrowSouthWest,
20
- DEFAULT_BALLOON_POSITIONS.northArrowSouthEast,
21
- DEFAULT_BALLOON_POSITIONS.southArrowNorth,
22
- DEFAULT_BALLOON_POSITIONS.southArrowNorthWest,
23
- DEFAULT_BALLOON_POSITIONS.southArrowNorthEast,
24
- DEFAULT_BALLOON_POSITIONS.viewportStickyNorth
13
+ DEFAULT_BALLOON_POSITIONS.northArrowSouth,
14
+ DEFAULT_BALLOON_POSITIONS.northArrowSouthWest,
15
+ DEFAULT_BALLOON_POSITIONS.northArrowSouthEast,
16
+ DEFAULT_BALLOON_POSITIONS.southArrowNorth,
17
+ DEFAULT_BALLOON_POSITIONS.southArrowNorthWest,
18
+ DEFAULT_BALLOON_POSITIONS.southArrowNorthEast,
19
+ DEFAULT_BALLOON_POSITIONS.viewportStickyNorth
25
20
  ];
26
-
27
21
  /**
28
22
  * A helper utility that positions the
29
23
  * {@link module:ui/panel/balloon/contextualballoon~ContextualBalloon contextual balloon} instance
30
24
  * with respect to the table in the editor content, if one is selected.
31
25
  *
32
- * @param {module:core/editor/editor~Editor} editor The editor instance.
33
- * @param {String} target Either "cell" or "table". Determines the target the balloon will
34
- * be attached to.
26
+ * @param editor The editor instance.
27
+ * @param target Either "cell" or "table". Determines the target the balloon will be attached to.
35
28
  */
36
- export function repositionContextualBalloon( editor, target ) {
37
- const balloon = editor.plugins.get( 'ContextualBalloon' );
38
-
39
- if ( getTableWidgetAncestor( editor.editing.view.document.selection ) ) {
40
- let position;
41
-
42
- if ( target === 'cell' ) {
43
- position = getBalloonCellPositionData( editor );
44
- } else {
45
- position = getBalloonTablePositionData( editor );
46
- }
47
-
48
- balloon.updatePosition( position );
49
- }
29
+ export function repositionContextualBalloon(editor, target) {
30
+ const balloon = editor.plugins.get('ContextualBalloon');
31
+ if (getTableWidgetAncestor(editor.editing.view.document.selection)) {
32
+ let position;
33
+ if (target === 'cell') {
34
+ position = getBalloonCellPositionData(editor);
35
+ }
36
+ else {
37
+ position = getBalloonTablePositionData(editor);
38
+ }
39
+ balloon.updatePosition(position);
40
+ }
50
41
  }
51
-
52
42
  /**
53
43
  * Returns the positioning options that control the geometry of the
54
44
  * {@link module:ui/panel/balloon/contextualballoon~ContextualBalloon contextual balloon} with respect
55
45
  * to the selected table in the editor content.
56
46
  *
57
- * @param {module:core/editor/editor~Editor} editor The editor instance.
58
- * @returns {module:utils/dom/position~Options}
47
+ * @param editor The editor instance.
59
48
  */
60
- export function getBalloonTablePositionData( editor ) {
61
- const firstPosition = editor.model.document.selection.getFirstPosition();
62
- const modelTable = firstPosition.findAncestor( 'table' );
63
- const viewTable = editor.editing.mapper.toViewElement( modelTable );
64
-
65
- return {
66
- target: editor.editing.view.domConverter.mapViewToDom( viewTable ),
67
- positions: BALLOON_POSITIONS
68
- };
49
+ export function getBalloonTablePositionData(editor) {
50
+ const firstPosition = editor.model.document.selection.getFirstPosition();
51
+ const modelTable = firstPosition.findAncestor('table');
52
+ const viewTable = editor.editing.mapper.toViewElement(modelTable);
53
+ return {
54
+ target: editor.editing.view.domConverter.mapViewToDom(viewTable),
55
+ positions: BALLOON_POSITIONS
56
+ };
69
57
  }
70
-
71
58
  /**
72
59
  * Returns the positioning options that control the geometry of the
73
60
  * {@link module:ui/panel/balloon/contextualballoon~ContextualBalloon contextual balloon} with respect
74
61
  * to the selected table cell in the editor content.
75
62
  *
76
- * @param {module:core/editor/editor~Editor} editor The editor instance.
77
- * @returns {module:utils/dom/position~Options}
63
+ * @param editor The editor instance.
78
64
  */
79
- export function getBalloonCellPositionData( editor ) {
80
- const mapper = editor.editing.mapper;
81
- const domConverter = editor.editing.view.domConverter;
82
- const selection = editor.model.document.selection;
83
-
84
- if ( selection.rangeCount > 1 ) {
85
- return {
86
- target: () => createBoundingRect( selection.getRanges(), editor ),
87
- positions: BALLOON_POSITIONS
88
- };
89
- }
90
-
91
- const modelTableCell = getTableCellAtPosition( selection.getFirstPosition() );
92
- const viewTableCell = mapper.toViewElement( modelTableCell );
93
-
94
- return {
95
- target: domConverter.mapViewToDom( viewTableCell ),
96
- positions: BALLOON_POSITIONS
97
- };
65
+ export function getBalloonCellPositionData(editor) {
66
+ const mapper = editor.editing.mapper;
67
+ const domConverter = editor.editing.view.domConverter;
68
+ const selection = editor.model.document.selection;
69
+ if (selection.rangeCount > 1) {
70
+ return {
71
+ target: () => createBoundingRect(selection.getRanges(), editor),
72
+ positions: BALLOON_POSITIONS
73
+ };
74
+ }
75
+ const modelTableCell = getTableCellAtPosition(selection.getFirstPosition());
76
+ const viewTableCell = mapper.toViewElement(modelTableCell);
77
+ return {
78
+ target: domConverter.mapViewToDom(viewTableCell),
79
+ positions: BALLOON_POSITIONS
80
+ };
98
81
  }
99
-
100
- // Returns the first selected table cell from a multi-cell or in-cell selection.
101
- //
102
- // @param {module:engine/model/position~Position} position Document position.
103
- // @returns {module:engine/model/element~Element}
104
- function getTableCellAtPosition( position ) {
105
- const isTableCellSelected = position.nodeAfter && position.nodeAfter.is( 'element', 'tableCell' );
106
-
107
- return isTableCellSelected ? position.nodeAfter : position.findAncestor( 'tableCell' );
82
+ /**
83
+ * Returns the first selected table cell from a multi-cell or in-cell selection.
84
+ *
85
+ * @param position Document position.
86
+ */
87
+ function getTableCellAtPosition(position) {
88
+ const isTableCellSelected = position.nodeAfter && position.nodeAfter.is('element', 'tableCell');
89
+ return isTableCellSelected ? position.nodeAfter : position.findAncestor('tableCell');
108
90
  }
109
-
110
- // Returns bounding rectangle for given model ranges.
111
- //
112
- // @param {Iterable.<module:engine/model/range~Range>} ranges Model ranges that the bounding rect should be returned for.
113
- // @param {module:core/editor/editor~Editor} editor The editor instance.
114
- // @returns {module:utils/dom/rect~Rect}
115
- function createBoundingRect( ranges, editor ) {
116
- const mapper = editor.editing.mapper;
117
- const domConverter = editor.editing.view.domConverter;
118
- const rects = Array.from( ranges ).map( range => {
119
- const modelTableCell = getTableCellAtPosition( range.start );
120
- const viewTableCell = mapper.toViewElement( modelTableCell );
121
- return new Rect( domConverter.mapViewToDom( viewTableCell ) );
122
- } );
123
-
124
- return Rect.getBoundingRect( rects );
91
+ /**
92
+ * Returns bounding rectangle for given model ranges.
93
+ *
94
+ * @param ranges Model ranges that the bounding rect should be returned for.
95
+ * @param editor The editor instance.
96
+ */
97
+ function createBoundingRect(ranges, editor) {
98
+ const mapper = editor.editing.mapper;
99
+ const domConverter = editor.editing.view.domConverter;
100
+ const rects = Array.from(ranges).map(range => {
101
+ const modelTableCell = getTableCellAtPosition(range.start);
102
+ const viewTableCell = mapper.toViewElement(modelTableCell);
103
+ return new Rect(domConverter.mapViewToDom(viewTableCell));
104
+ });
105
+ return Rect.getBoundingRect(rects);
125
106
  }
@@ -0,0 +1,193 @@
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 table/utils/ui/table-properties
7
+ */
8
+ import { type ColorOption, type LabeledFieldView, type ListDropdownItemDefinition, type NormalizedColorOption, type ToolbarView, type View } from 'ckeditor5/src/ui';
9
+ import { Collection, type LocaleTranslate } from 'ckeditor5/src/utils';
10
+ import type TableCellPropertiesView from '../../tablecellproperties/ui/tablecellpropertiesview';
11
+ import type TablePropertiesView from '../../tableproperties/ui/tablepropertiesview';
12
+ import ColorInputView from '../../ui/colorinputview';
13
+ /**
14
+ * Returns an object containing pairs of CSS border style values and their localized UI
15
+ * labels. Used by {@link module:table/tablecellproperties/ui/tablecellpropertiesview~TableCellPropertiesView}
16
+ * and {@link module:table/tableproperties/ui/tablepropertiesview~TablePropertiesView}.
17
+ *
18
+ * @param t The "t" function provided by the editor that is used to localize strings.
19
+ */
20
+ export declare function getBorderStyleLabels(t: LocaleTranslate): Record<string, string>;
21
+ /**
22
+ * Returns a localized error string that can be displayed next to color (background, border)
23
+ * fields that have an invalid value.
24
+ *
25
+ * @param t The "t" function provided by the editor that is used to localize strings.
26
+ */
27
+ export declare function getLocalizedColorErrorText(t: LocaleTranslate): string;
28
+ /**
29
+ * Returns a localized error string that can be displayed next to length (padding, border width)
30
+ * fields that have an invalid value.
31
+ *
32
+ * @param t The "t" function provided by the editor that is used to localize strings.
33
+ */
34
+ export declare function getLocalizedLengthErrorText(t: LocaleTranslate): string;
35
+ /**
36
+ * Returns `true` when the passed value is an empty string or a valid CSS color expression.
37
+ * Otherwise, `false` is returned.
38
+ *
39
+ * See {@link module:engine/view/styles/utils~isColor}.
40
+ */
41
+ export declare function colorFieldValidator(value: string): boolean;
42
+ /**
43
+ * Returns `true` when the passed value is an empty string, a number without a unit or a valid CSS length expression.
44
+ * Otherwise, `false` is returned.
45
+ *
46
+ * See {@link module:engine/view/styles/utils~isLength}.
47
+ * See {@link module:engine/view/styles/utils~isPercentage}.
48
+ */
49
+ export declare function lengthFieldValidator(value: string): boolean;
50
+ /**
51
+ * Returns `true` when the passed value is an empty string, a number without a unit or a valid CSS length expression.
52
+ * Otherwise, `false` is returned.
53
+ *
54
+ * See {@link module:engine/view/styles/utils~isLength}.
55
+ */
56
+ export declare function lineWidthFieldValidator(value: string): boolean;
57
+ /**
58
+ * Generates item definitions for a UI dropdown that allows changing the border style of a table or a table cell.
59
+ *
60
+ * @param defaultStyle The default border.
61
+ */
62
+ export declare function getBorderStyleDefinitions(view: TableCellPropertiesView | TablePropertiesView, defaultStyle: string): Collection<ListDropdownItemDefinition>;
63
+ /**
64
+ * A helper that fills a toolbar with buttons that:
65
+ *
66
+ * * have some labels,
67
+ * * have some icons,
68
+ * * set a certain UI view property value upon execution.
69
+ *
70
+ * @param nameToValue A function that maps a button name to a value. By default names are the same as values.
71
+ */
72
+ export declare function fillToolbar<TView extends View, TPropertyName extends keyof TView>(options: {
73
+ view: TView;
74
+ icons: Record<string, string>;
75
+ toolbar: ToolbarView;
76
+ labels: Record<number, string>;
77
+ propertyName: TPropertyName;
78
+ nameToValue?: (name: string) => string;
79
+ defaultValue?: string;
80
+ }): void;
81
+ /**
82
+ * A default color palette used by various user interfaces related to tables, for instance,
83
+ * by {@link module:table/tablecellproperties/tablecellpropertiesui~TableCellPropertiesUI} or
84
+ * {@link module:table/tableproperties/tablepropertiesui~TablePropertiesUI}.
85
+ *
86
+ * The color palette follows the {@link module:table/tableconfig~TableColorConfig table color configuration format}
87
+ * and contains the following color definitions:
88
+ *
89
+ * ```ts
90
+ * const defaultColors = [
91
+ * {
92
+ * color: 'hsl(0, 0%, 0%)',
93
+ * label: 'Black'
94
+ * },
95
+ * {
96
+ * color: 'hsl(0, 0%, 30%)',
97
+ * label: 'Dim grey'
98
+ * },
99
+ * {
100
+ * color: 'hsl(0, 0%, 60%)',
101
+ * label: 'Grey'
102
+ * },
103
+ * {
104
+ * color: 'hsl(0, 0%, 90%)',
105
+ * label: 'Light grey'
106
+ * },
107
+ * {
108
+ * color: 'hsl(0, 0%, 100%)',
109
+ * label: 'White',
110
+ * hasBorder: true
111
+ * },
112
+ * {
113
+ * color: 'hsl(0, 75%, 60%)',
114
+ * label: 'Red'
115
+ * },
116
+ * {
117
+ * color: 'hsl(30, 75%, 60%)',
118
+ * label: 'Orange'
119
+ * },
120
+ * {
121
+ * color: 'hsl(60, 75%, 60%)',
122
+ * label: 'Yellow'
123
+ * },
124
+ * {
125
+ * color: 'hsl(90, 75%, 60%)',
126
+ * label: 'Light green'
127
+ * },
128
+ * {
129
+ * color: 'hsl(120, 75%, 60%)',
130
+ * label: 'Green'
131
+ * },
132
+ * {
133
+ * color: 'hsl(150, 75%, 60%)',
134
+ * label: 'Aquamarine'
135
+ * },
136
+ * {
137
+ * color: 'hsl(180, 75%, 60%)',
138
+ * label: 'Turquoise'
139
+ * },
140
+ * {
141
+ * color: 'hsl(210, 75%, 60%)',
142
+ * label: 'Light blue'
143
+ * },
144
+ * {
145
+ * color: 'hsl(240, 75%, 60%)',
146
+ * label: 'Blue'
147
+ * },
148
+ * {
149
+ * color: 'hsl(270, 75%, 60%)',
150
+ * label: 'Purple'
151
+ * }
152
+ * ];
153
+ * ```
154
+ */
155
+ export declare const defaultColors: Array<ColorOption>;
156
+ /**
157
+ * Returns a creator for a color input with a label.
158
+ *
159
+ * For given options, it returns a function that creates an instance of a
160
+ * {@link module:table/ui/colorinputview~ColorInputView color input} logically related to
161
+ * a {@link module:ui/labeledfield/labeledfieldview~LabeledFieldView labeled view} in the DOM.
162
+ *
163
+ * The helper does the following:
164
+ *
165
+ * * It sets the color input `id` and `ariaDescribedById` attributes.
166
+ * * It binds the color input `isReadOnly` to the labeled view.
167
+ * * It binds the color input `hasError` to the labeled view.
168
+ * * It enables a logic that cleans up the error when the user starts typing in the color input.
169
+ *
170
+ * Usage:
171
+ *
172
+ * ```ts
173
+ * const colorInputCreator = getLabeledColorInputCreator( {
174
+ * colorConfig: [ ... ],
175
+ * columns: 3,
176
+ * } );
177
+ *
178
+ * const labeledInputView = new LabeledFieldView( locale, colorInputCreator );
179
+ * console.log( labeledInputView.view ); // A color input instance.
180
+ * ```
181
+ *
182
+ * @internal
183
+ * @param options Color input options.
184
+ * @param options.colorConfig The configuration of the color palette displayed in the input's dropdown.
185
+ * @param options.columns The configuration of the number of columns the color palette consists of in the input's dropdown.
186
+ * @param options.defaultColorValue If specified, the color input view will replace the "Remove color" button with
187
+ * the "Restore default" button. Instead of clearing the input field, the default color value will be set.
188
+ */
189
+ export declare function getLabeledColorInputCreator(options: {
190
+ colorConfig: Array<NormalizedColorOption>;
191
+ columns: number;
192
+ defaultColorValue?: string;
193
+ }): (labeledFieldView: LabeledFieldView, viewUid: string, statusUid: string) => ColorInputView;