@ckeditor/ckeditor5-ui 38.0.1 → 38.1.1

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 (127) hide show
  1. package/lang/translations/it.po +1 -1
  2. package/package.json +3 -32
  3. package/src/augmentation.d.ts +86 -86
  4. package/src/augmentation.js +5 -5
  5. package/src/bindings/addkeyboardhandlingforgrid.d.ts +27 -27
  6. package/src/bindings/addkeyboardhandlingforgrid.js +107 -107
  7. package/src/bindings/clickoutsidehandler.d.ts +28 -28
  8. package/src/bindings/clickoutsidehandler.js +36 -36
  9. package/src/bindings/csstransitiondisablermixin.d.ts +40 -40
  10. package/src/bindings/csstransitiondisablermixin.js +55 -55
  11. package/src/bindings/injectcsstransitiondisabler.d.ts +59 -59
  12. package/src/bindings/injectcsstransitiondisabler.js +71 -71
  13. package/src/bindings/preventdefault.d.ts +33 -33
  14. package/src/bindings/preventdefault.js +34 -34
  15. package/src/bindings/submithandler.d.ts +57 -57
  16. package/src/bindings/submithandler.js +47 -47
  17. package/src/button/button.d.ts +178 -178
  18. package/src/button/button.js +5 -5
  19. package/src/button/buttonview.d.ts +177 -177
  20. package/src/button/buttonview.js +231 -231
  21. package/src/button/switchbuttonview.d.ts +45 -45
  22. package/src/button/switchbuttonview.js +75 -75
  23. package/src/colorgrid/colorgridview.d.ts +132 -132
  24. package/src/colorgrid/colorgridview.js +124 -124
  25. package/src/colorgrid/colortileview.d.ts +28 -28
  26. package/src/colorgrid/colortileview.js +40 -40
  27. package/src/colorgrid/utils.d.ts +47 -47
  28. package/src/colorgrid/utils.js +84 -84
  29. package/src/colorpicker/colorpickerview.d.ts +110 -110
  30. package/src/colorpicker/colorpickerview.js +253 -250
  31. package/src/colorpicker/utils.d.ts +35 -35
  32. package/src/colorpicker/utils.js +99 -99
  33. package/src/componentfactory.d.ts +81 -81
  34. package/src/componentfactory.js +104 -104
  35. package/src/dropdown/button/dropdownbutton.d.ts +25 -25
  36. package/src/dropdown/button/dropdownbutton.js +5 -5
  37. package/src/dropdown/button/dropdownbuttonview.d.ts +48 -48
  38. package/src/dropdown/button/dropdownbuttonview.js +66 -66
  39. package/src/dropdown/button/splitbuttonview.d.ts +161 -161
  40. package/src/dropdown/button/splitbuttonview.js +152 -152
  41. package/src/dropdown/dropdownpanelfocusable.d.ts +21 -21
  42. package/src/dropdown/dropdownpanelfocusable.js +5 -5
  43. package/src/dropdown/dropdownpanelview.d.ts +62 -62
  44. package/src/dropdown/dropdownpanelview.js +96 -96
  45. package/src/dropdown/dropdownview.d.ts +315 -315
  46. package/src/dropdown/dropdownview.js +378 -378
  47. package/src/dropdown/utils.d.ts +221 -221
  48. package/src/dropdown/utils.js +434 -434
  49. package/src/editableui/editableuiview.d.ts +72 -72
  50. package/src/editableui/editableuiview.js +112 -112
  51. package/src/editableui/inline/inlineeditableuiview.d.ts +40 -40
  52. package/src/editableui/inline/inlineeditableuiview.js +48 -48
  53. package/src/editorui/bodycollection.d.ts +55 -51
  54. package/src/editorui/bodycollection.js +84 -78
  55. package/src/editorui/boxed/boxededitoruiview.d.ts +40 -40
  56. package/src/editorui/boxed/boxededitoruiview.js +81 -81
  57. package/src/editorui/editorui.d.ts +282 -274
  58. package/src/editorui/editorui.js +410 -388
  59. package/src/editorui/editoruiview.d.ts +39 -39
  60. package/src/editorui/editoruiview.js +38 -38
  61. package/src/editorui/poweredby.d.ts +71 -76
  62. package/src/editorui/poweredby.js +294 -291
  63. package/src/focuscycler.d.ts +183 -183
  64. package/src/focuscycler.js +220 -220
  65. package/src/formheader/formheaderview.d.ts +53 -53
  66. package/src/formheader/formheaderview.js +63 -63
  67. package/src/icon/iconview.d.ts +78 -78
  68. package/src/icon/iconview.js +112 -112
  69. package/src/iframe/iframeview.d.ts +50 -50
  70. package/src/iframe/iframeview.js +63 -63
  71. package/src/index.d.ts +62 -61
  72. package/src/index.js +61 -60
  73. package/src/input/inputview.d.ts +121 -121
  74. package/src/input/inputview.js +106 -106
  75. package/src/inputnumber/inputnumberview.d.ts +49 -49
  76. package/src/inputnumber/inputnumberview.js +40 -40
  77. package/src/inputtext/inputtextview.d.ts +18 -18
  78. package/src/inputtext/inputtextview.js +27 -27
  79. package/src/label/labelview.d.ts +36 -36
  80. package/src/label/labelview.js +41 -41
  81. package/src/labeledfield/labeledfieldview.d.ts +182 -182
  82. package/src/labeledfield/labeledfieldview.js +157 -157
  83. package/src/labeledfield/utils.d.ts +93 -93
  84. package/src/labeledfield/utils.js +131 -131
  85. package/src/labeledinput/labeledinputview.d.ts +125 -125
  86. package/src/labeledinput/labeledinputview.js +125 -125
  87. package/src/list/listitemview.d.ts +35 -35
  88. package/src/list/listitemview.js +40 -40
  89. package/src/list/listseparatorview.d.ts +18 -18
  90. package/src/list/listseparatorview.js +28 -28
  91. package/src/list/listview.d.ts +65 -65
  92. package/src/list/listview.js +90 -90
  93. package/src/model.d.ts +22 -22
  94. package/src/model.js +31 -31
  95. package/src/notification/notification.d.ts +211 -211
  96. package/src/notification/notification.js +187 -187
  97. package/src/panel/balloon/balloonpanelview.d.ts +685 -685
  98. package/src/panel/balloon/balloonpanelview.js +988 -988
  99. package/src/panel/balloon/contextualballoon.d.ts +299 -299
  100. package/src/panel/balloon/contextualballoon.js +572 -572
  101. package/src/panel/sticky/stickypanelview.d.ts +132 -132
  102. package/src/panel/sticky/stickypanelview.js +139 -139
  103. package/src/template.d.ts +942 -942
  104. package/src/template.js +1294 -1294
  105. package/src/toolbar/balloon/balloontoolbar.d.ts +122 -122
  106. package/src/toolbar/balloon/balloontoolbar.js +300 -300
  107. package/src/toolbar/block/blockbuttonview.d.ts +35 -35
  108. package/src/toolbar/block/blockbuttonview.js +41 -41
  109. package/src/toolbar/block/blocktoolbar.d.ts +161 -153
  110. package/src/toolbar/block/blocktoolbar.js +391 -374
  111. package/src/toolbar/normalizetoolbarconfig.d.ts +39 -39
  112. package/src/toolbar/normalizetoolbarconfig.js +51 -51
  113. package/src/toolbar/toolbarlinebreakview.d.ts +18 -18
  114. package/src/toolbar/toolbarlinebreakview.js +28 -28
  115. package/src/toolbar/toolbarseparatorview.d.ts +18 -18
  116. package/src/toolbar/toolbarseparatorview.js +28 -28
  117. package/src/toolbar/toolbarview.d.ts +265 -265
  118. package/src/toolbar/toolbarview.js +717 -717
  119. package/src/tooltipmanager.d.ts +180 -180
  120. package/src/tooltipmanager.js +353 -353
  121. package/src/view.d.ts +422 -422
  122. package/src/view.js +396 -396
  123. package/src/viewcollection.d.ts +139 -139
  124. package/src/viewcollection.js +206 -206
  125. package/theme/components/colorpicker/colorpicker.css +4 -4
  126. package/theme/globals/_poweredby.css +5 -1
  127. package/theme/icons/project-logo.svg +1 -1
@@ -1,988 +1,988 @@
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 ui/panel/balloon/balloonpanelview
7
- */
8
- import View from '../../view';
9
- import { getOptimalPosition, global, isRange, toUnit } from '@ckeditor/ckeditor5-utils';
10
- import { isElement } from 'lodash-es';
11
- import '../../../theme/components/panel/balloonpanel.css';
12
- const toPx = toUnit('px');
13
- const defaultLimiterElement = global.document.body;
14
- /**
15
- * The balloon panel view class.
16
- *
17
- * A floating container which can
18
- * {@link module:ui/panel/balloon/balloonpanelview~BalloonPanelView#pin pin} to any
19
- * {@link module:utils/dom/position~Options#target target} in the DOM and remain in that position
20
- * e.g. when the web page is scrolled.
21
- *
22
- * The balloon panel can be used to display contextual, non-blocking UI like forms, toolbars and
23
- * the like in its {@link module:ui/panel/balloon/balloonpanelview~BalloonPanelView#content} view
24
- * collection.
25
- *
26
- * There is a number of {@link module:ui/panel/balloon/balloonpanelview~BalloonPanelView.defaultPositions}
27
- * that the balloon can use, automatically switching from one to another when the viewport space becomes
28
- * scarce to keep the balloon visible to the user as long as it is possible. The balloon will also
29
- * accept any custom position set provided by the user compatible with the
30
- * {@link module:utils/dom/position~Options options}.
31
- *
32
- * ```ts
33
- * const panel = new BalloonPanelView( locale );
34
- * const childView = new ChildView();
35
- * const positions = BalloonPanelView.defaultPositions;
36
- *
37
- * panel.render();
38
- *
39
- * // Add a child view to the panel's content collection.
40
- * panel.content.add( childView );
41
- *
42
- * // Start pinning the panel to an element with the "target" id DOM.
43
- * // The balloon will remain pinned until unpin() is called.
44
- * panel.pin( {
45
- * target: document.querySelector( '#target' ),
46
- * positions: [
47
- * positions.northArrowSouth,
48
- * positions.southArrowNorth
49
- * ]
50
- * } );
51
- * ```
52
- */
53
- export default class BalloonPanelView extends View {
54
- /**
55
- * @inheritDoc
56
- */
57
- constructor(locale) {
58
- super(locale);
59
- const bind = this.bindTemplate;
60
- this.set('top', 0);
61
- this.set('left', 0);
62
- this.set('position', 'arrow_nw');
63
- this.set('isVisible', false);
64
- this.set('withArrow', true);
65
- this.set('class', undefined);
66
- this._pinWhenIsVisibleCallback = null;
67
- this.content = this.createCollection();
68
- this.setTemplate({
69
- tag: 'div',
70
- attributes: {
71
- class: [
72
- 'ck',
73
- 'ck-balloon-panel',
74
- bind.to('position', value => `ck-balloon-panel_${value}`),
75
- bind.if('isVisible', 'ck-balloon-panel_visible'),
76
- bind.if('withArrow', 'ck-balloon-panel_with-arrow'),
77
- bind.to('class')
78
- ],
79
- style: {
80
- top: bind.to('top', toPx),
81
- left: bind.to('left', toPx)
82
- }
83
- },
84
- children: this.content
85
- });
86
- }
87
- /**
88
- * Shows the panel.
89
- *
90
- * See {@link #isVisible}.
91
- */
92
- show() {
93
- this.isVisible = true;
94
- }
95
- /**
96
- * Hides the panel.
97
- *
98
- * See {@link #isVisible}.
99
- */
100
- hide() {
101
- this.isVisible = false;
102
- }
103
- /**
104
- * Attaches the panel to a specified {@link module:utils/dom/position~Options#target} with a
105
- * smart positioning heuristics that chooses from available positions to make sure the panel
106
- * is visible to the user i.e. within the limits of the viewport.
107
- *
108
- * This method accepts configuration {@link module:utils/dom/position~Options options}
109
- * to set the `target`, optional `limiter` and `positions` the balloon should choose from.
110
- *
111
- * ```ts
112
- * const panel = new BalloonPanelView( locale );
113
- * const positions = BalloonPanelView.defaultPositions;
114
- *
115
- * panel.render();
116
- *
117
- * // Attach the panel to an element with the "target" id DOM.
118
- * panel.attachTo( {
119
- * target: document.querySelector( '#target' ),
120
- * positions: [
121
- * positions.northArrowSouth,
122
- * positions.southArrowNorth
123
- * ]
124
- * } );
125
- * ```
126
- *
127
- * **Note**: Attaching the panel will also automatically {@link #show} it.
128
- *
129
- * **Note**: An attached panel will not follow its target when the window is scrolled or resized.
130
- * See the {@link #pin} method for a more permanent positioning strategy.
131
- *
132
- * @param options Positioning options compatible with {@link module:utils/dom/position~getOptimalPosition}.
133
- * Default `positions` array is {@link module:ui/panel/balloon/balloonpanelview~BalloonPanelView.defaultPositions}.
134
- */
135
- attachTo(options) {
136
- this.show();
137
- const defaultPositions = BalloonPanelView.defaultPositions;
138
- const positionOptions = Object.assign({}, {
139
- element: this.element,
140
- positions: [
141
- defaultPositions.southArrowNorth,
142
- defaultPositions.southArrowNorthMiddleWest,
143
- defaultPositions.southArrowNorthMiddleEast,
144
- defaultPositions.southArrowNorthWest,
145
- defaultPositions.southArrowNorthEast,
146
- defaultPositions.northArrowSouth,
147
- defaultPositions.northArrowSouthMiddleWest,
148
- defaultPositions.northArrowSouthMiddleEast,
149
- defaultPositions.northArrowSouthWest,
150
- defaultPositions.northArrowSouthEast,
151
- defaultPositions.viewportStickyNorth
152
- ],
153
- limiter: defaultLimiterElement,
154
- fitInViewport: true
155
- }, options);
156
- const optimalPosition = BalloonPanelView._getOptimalPosition(positionOptions);
157
- // Usually browsers make some problems with super accurate values like 104.345px
158
- // so it is better to use int values.
159
- const left = parseInt(optimalPosition.left);
160
- const top = parseInt(optimalPosition.top);
161
- const position = optimalPosition.name;
162
- const config = optimalPosition.config || {};
163
- const { withArrow = true } = config;
164
- this.top = top;
165
- this.left = left;
166
- this.position = position;
167
- this.withArrow = withArrow;
168
- }
169
- /**
170
- * Works the same way as the {@link #attachTo} method except that the position of the panel is
171
- * continuously updated when:
172
- *
173
- * * any ancestor of the {@link module:utils/dom/position~Options#target}
174
- * or {@link module:utils/dom/position~Options#limiter} is scrolled,
175
- * * the browser window gets resized or scrolled.
176
- *
177
- * Thanks to that, the panel always sticks to the {@link module:utils/dom/position~Options#target}
178
- * and is immune to the changing environment.
179
- *
180
- * ```ts
181
- * const panel = new BalloonPanelView( locale );
182
- * const positions = BalloonPanelView.defaultPositions;
183
- *
184
- * panel.render();
185
- *
186
- * // Pin the panel to an element with the "target" id DOM.
187
- * panel.pin( {
188
- * target: document.querySelector( '#target' ),
189
- * positions: [
190
- * positions.northArrowSouth,
191
- * positions.southArrowNorth
192
- * ]
193
- * } );
194
- * ```
195
- *
196
- * To leave the pinned state, use the {@link #unpin} method.
197
- *
198
- * **Note**: Pinning the panel will also automatically {@link #show} it.
199
- *
200
- * @param options Positioning options compatible with {@link module:utils/dom/position~getOptimalPosition}.
201
- * Default `positions` array is {@link module:ui/panel/balloon/balloonpanelview~BalloonPanelView.defaultPositions}.
202
- */
203
- pin(options) {
204
- this.unpin();
205
- this._pinWhenIsVisibleCallback = () => {
206
- if (this.isVisible) {
207
- this._startPinning(options);
208
- }
209
- else {
210
- this._stopPinning();
211
- }
212
- };
213
- this._startPinning(options);
214
- // Control the state of the listeners depending on whether the panel is visible
215
- // or not.
216
- // TODO: Use on() (https://github.com/ckeditor/ckeditor5-utils/issues/144).
217
- this.listenTo(this, 'change:isVisible', this._pinWhenIsVisibleCallback);
218
- }
219
- /**
220
- * Stops pinning the panel, as set up by {@link #pin}.
221
- */
222
- unpin() {
223
- if (this._pinWhenIsVisibleCallback) {
224
- // Deactivate listeners attached by pin().
225
- this._stopPinning();
226
- // Deactivate the panel pin() control logic.
227
- // TODO: Use off() (https://github.com/ckeditor/ckeditor5-utils/issues/144).
228
- this.stopListening(this, 'change:isVisible', this._pinWhenIsVisibleCallback);
229
- this._pinWhenIsVisibleCallback = null;
230
- this.hide();
231
- }
232
- }
233
- /**
234
- * Starts managing the pinned state of the panel. See {@link #pin}.
235
- *
236
- * @param options Positioning options compatible with {@link module:utils/dom/position~getOptimalPosition}.
237
- */
238
- _startPinning(options) {
239
- this.attachTo(options);
240
- const targetElement = getDomElement(options.target);
241
- const limiterElement = options.limiter ? getDomElement(options.limiter) : defaultLimiterElement;
242
- // Then we need to listen on scroll event of eny element in the document.
243
- this.listenTo(global.document, 'scroll', (evt, domEvt) => {
244
- const scrollTarget = domEvt.target;
245
- // The position needs to be updated if the positioning target is within the scrolled element.
246
- const isWithinScrollTarget = targetElement && scrollTarget.contains(targetElement);
247
- // The position needs to be updated if the positioning limiter is within the scrolled element.
248
- const isLimiterWithinScrollTarget = limiterElement && scrollTarget.contains(limiterElement);
249
- // The positioning target and/or limiter can be a Rect, object etc..
250
- // There's no way to optimize the listener then.
251
- if (isWithinScrollTarget || isLimiterWithinScrollTarget || !targetElement || !limiterElement) {
252
- this.attachTo(options);
253
- }
254
- }, { useCapture: true });
255
- // We need to listen on window resize event and update position.
256
- this.listenTo(global.window, 'resize', () => {
257
- this.attachTo(options);
258
- });
259
- }
260
- /**
261
- * Stops managing the pinned state of the panel. See {@link #pin}.
262
- */
263
- _stopPinning() {
264
- this.stopListening(global.document, 'scroll');
265
- this.stopListening(global.window, 'resize');
266
- }
267
- }
268
- /**
269
- * A side offset of the arrow tip from the edge of the balloon. Controlled by CSS.
270
- *
271
- * ```
272
- * ┌───────────────────────┐
273
- * │ │
274
- * │ Balloon │
275
- * │ Content │
276
- * │ │
277
- * └──+ +───────────────┘
278
- * | \ /
279
- * | \/
280
- * >┼─────┼< ─────────────────────── side offset
281
- *
282
- * ```
283
- *
284
- * @default 25
285
- */
286
- BalloonPanelView.arrowSideOffset = 25;
287
- /**
288
- * A height offset of the arrow from the edge of the balloon. Controlled by CSS.
289
- *
290
- * ```
291
- * ┌───────────────────────┐
292
- * │ │
293
- * │ Balloon │
294
- * │ Content │ ╱-- arrow height offset
295
- * │ │ V
296
- * └──+ +───────────────┘ --- ─┼───────
297
- * \ / │
298
- * \/ │
299
- * ────────────────────────────────┼───────
300
- * ^
301
- *
302
- *
303
- * >┼────┼< arrow height offset
304
- * │ │
305
- * │ ┌────────────────────────┐
306
- * │ │ │
307
- * │ ╱ │
308
- * │ ╱ Balloon │
309
- * │ ╲ Content │
310
- * │ ╲ │
311
- * │ │ │
312
- * │ └────────────────────────┘
313
- * ```
314
- *
315
- * @default 10
316
- */
317
- BalloonPanelView.arrowHeightOffset = 10;
318
- /**
319
- * A vertical offset of the balloon panel from the edge of the viewport if sticky.
320
- * It helps in accessing toolbar buttons underneath the balloon panel.
321
- *
322
- * ```
323
- * ┌───────────────────────────────────────────────────┐
324
- * │ Target │
325
- * │ │
326
- * │ /── vertical offset │
327
- * ┌─────────────────────────────V─────────────────────────┐
328
- * │ Toolbar ┌─────────────┐ │
329
- * ├────────────────────│ Balloon │────────────────────┤
330
- * │ │ └─────────────┘ │ │
331
- * │ │ │ │
332
- * │ │ │ │
333
- * │ │ │ │
334
- * │ └───────────────────────────────────────────────────┘ │
335
- * │ Viewport │
336
- * └───────────────────────────────────────────────────────┘
337
- * ```
338
- *
339
- * @default 20
340
- */
341
- BalloonPanelView.stickyVerticalOffset = 20;
342
- /**
343
- * Function used to calculate the optimal position for the balloon.
344
- */
345
- BalloonPanelView._getOptimalPosition = getOptimalPosition;
346
- /**
347
- * A default set of positioning functions used by the balloon panel view
348
- * when attaching using the {@link module:ui/panel/balloon/balloonpanelview~BalloonPanelView#attachTo} method.
349
- *
350
- * The available positioning functions are as follows:
351
- *
352
- * **North west**
353
- *
354
- * * `northWestArrowSouthWest`
355
- *
356
- * ```
357
- * +-----------------+
358
- * | Balloon |
359
- * +-----------------+
360
- * V
361
- * [ Target ]
362
- * ```
363
- *
364
- * * `northWestArrowSouthMiddleWest`
365
- *
366
- * ```
367
- * +-----------------+
368
- * | Balloon |
369
- * +-----------------+
370
- * V
371
- * [ Target ]
372
- * ```
373
- *
374
- * * `northWestArrowSouth`
375
- *
376
- * ```
377
- * +-----------------+
378
- * | Balloon |
379
- * +-----------------+
380
- * V
381
- * [ Target ]
382
- * ```
383
- *
384
- * * `northWestArrowSouthMiddleEast`
385
- *
386
- * ```
387
- * +-----------------+
388
- * | Balloon |
389
- * +-----------------+
390
- * V
391
- * [ Target ]
392
- * ```
393
- *
394
- * * `northWestArrowSouthEast`
395
- *
396
- * ```
397
- * +-----------------+
398
- * | Balloon |
399
- * +-----------------+
400
- * V
401
- * [ Target ]
402
- * ```
403
- *
404
- * **North**
405
- *
406
- * * `northArrowSouthWest`
407
- *
408
- * ```
409
- * +-----------------+
410
- * | Balloon |
411
- * +-----------------+
412
- * V
413
- * [ Target ]
414
- * ```
415
- *
416
- * * `northArrowSouthMiddleWest`
417
- *
418
- * ```
419
- * +-----------------+
420
- * | Balloon |
421
- * +-----------------+
422
- * V
423
- * [ Target ]
424
- * ```
425
- * * `northArrowSouth`
426
- *
427
- * ```
428
- * +-----------------+
429
- * | Balloon |
430
- * +-----------------+
431
- * V
432
- * [ Target ]
433
- * ```
434
- *
435
- * * `northArrowSouthMiddleEast`
436
- *
437
- * ```
438
- * +-----------------+
439
- * | Balloon |
440
- * +-----------------+
441
- * V
442
- * [ Target ]
443
- * ```
444
- *
445
- * * `northArrowSouthEast`
446
- *
447
- * ```
448
- * +-----------------+
449
- * | Balloon |
450
- * +-----------------+
451
- * V
452
- * [ Target ]
453
- * ```
454
- *
455
- * **North east**
456
- *
457
- * * `northEastArrowSouthWest`
458
- *
459
- * ```
460
- * +-----------------+
461
- * | Balloon |
462
- * +-----------------+
463
- * V
464
- * [ Target ]
465
- * ```
466
- *
467
- * * `northEastArrowSouthMiddleWest`
468
- *
469
- * ```
470
- * +-----------------+
471
- * | Balloon |
472
- * +-----------------+
473
- * V
474
- * [ Target ]
475
- * ```
476
- *
477
- * * `northEastArrowSouth`
478
- *
479
- * ```
480
- * +-----------------+
481
- * | Balloon |
482
- * +-----------------+
483
- * V
484
- * [ Target ]
485
- * ```
486
- *
487
- * * `northEastArrowSouthMiddleEast`
488
- *
489
- * ```
490
- * +-----------------+
491
- * | Balloon |
492
- * +-----------------+
493
- * V
494
- * [ Target ]
495
- * ```
496
- *
497
- * * `northEastArrowSouthEast`
498
- *
499
- * ```
500
- * +-----------------+
501
- * | Balloon |
502
- * +-----------------+
503
- * V
504
- * [ Target ]
505
- * ```
506
- *
507
- * **South**
508
- *
509
- * * `southArrowNorthWest`
510
- *
511
- * ```
512
- * [ Target ]
513
- * ^
514
- * +-----------------+
515
- * | Balloon |
516
- * +-----------------+
517
- * ```
518
- *
519
- * * `southArrowNorthMiddleWest`
520
- *
521
- * ```
522
- * [ Target ]
523
- * ^
524
- * +-----------------+
525
- * | Balloon |
526
- * +-----------------+
527
- * ```
528
- *
529
- * * `southArrowNorth`
530
- *
531
- * ```
532
- * [ Target ]
533
- * ^
534
- * +-----------------+
535
- * | Balloon |
536
- * +-----------------+
537
- * ```
538
- *
539
- * * `southArrowNorthMiddleEast`
540
- *
541
- * ```
542
- * [ Target ]
543
- * ^
544
- * +-----------------+
545
- * | Balloon |
546
- * +-----------------+
547
- * ```
548
- *
549
- * * `southArrowNorthEast`
550
- *
551
- * ```
552
- * [ Target ]
553
- * ^
554
- * +-----------------+
555
- * | Balloon |
556
- * +-----------------+
557
- * ```
558
- *
559
- * **South west**
560
- *
561
- * * `southWestArrowNorthWest`
562
- *
563
- *
564
- * ```
565
- * [ Target ]
566
- * ^
567
- * +-----------------+
568
- * | Balloon |
569
- * +-----------------+
570
- * ```
571
- *
572
- * * `southWestArrowNorthMiddleWest`
573
- *
574
- * ```
575
- * [ Target ]
576
- * ^
577
- * +-----------------+
578
- * | Balloon |
579
- * +-----------------+
580
- * ```
581
- *
582
- * * `southWestArrowNorth`
583
- *
584
- * ```
585
- * [ Target ]
586
- * ^
587
- * +-----------------+
588
- * | Balloon |
589
- * +-----------------+
590
- * ```
591
- *
592
- * * `southWestArrowNorthMiddleEast`
593
- *
594
- * ```
595
- * [ Target ]
596
- * ^
597
- * +-----------------+
598
- * | Balloon |
599
- * +-----------------+
600
- * ```
601
- *
602
- * * `southWestArrowNorthEast`
603
- *
604
- * ```
605
- * [ Target ]
606
- * ^
607
- * +-----------------+
608
- * | Balloon |
609
- * +-----------------+
610
- * ```
611
- *
612
- * **South east**
613
- *
614
- * * `southEastArrowNorthWest`
615
- *
616
- * ```
617
- * [ Target ]
618
- * ^
619
- * +-----------------+
620
- * | Balloon |
621
- * +-----------------+
622
- * ```
623
- *
624
- * * `southEastArrowNorthMiddleWest`
625
- *
626
- * ```
627
- * [ Target ]
628
- * ^
629
- * +-----------------+
630
- * | Balloon |
631
- * +-----------------+
632
- * ```
633
- *
634
- * * `southEastArrowNorth`
635
- *
636
- * ```
637
- * [ Target ]
638
- * ^
639
- * +-----------------+
640
- * | Balloon |
641
- * +-----------------+
642
- * ```
643
- *
644
- * * `southEastArrowNorthMiddleEast`
645
- *
646
- * ```
647
- * [ Target ]
648
- * ^
649
- * +-----------------+
650
- * | Balloon |
651
- * +-----------------+
652
- * ```
653
- *
654
- * * `southEastArrowNorthEast`
655
- *
656
- * ```
657
- * [ Target ]
658
- * ^
659
- * +-----------------+
660
- * | Balloon |
661
- * +-----------------+
662
- * ```
663
- *
664
- * **West**
665
- *
666
- * * `westArrowEast`
667
- *
668
- * ```
669
- * +-----------------+
670
- * | Balloon |>[ Target ]
671
- * +-----------------+
672
- * ```
673
- *
674
- * **East**
675
- *
676
- * * `eastArrowWest`
677
- *
678
- * ```
679
- * +-----------------+
680
- * [ Target ]<| Balloon |
681
- * +-----------------+
682
- * ```
683
- *
684
- * **Sticky**
685
- *
686
- * * `viewportStickyNorth`
687
- *
688
- * ```
689
- * +---------------------------+
690
- * | [ Target ] |
691
- * | |
692
- * +-----------------------------------+
693
- * | | +-----------------+ | |
694
- * | | | Balloon | | |
695
- * | | +-----------------+ | |
696
- * | | | |
697
- * | | | |
698
- * | | | |
699
- * | | | |
700
- * | +---------------------------+ |
701
- * | Viewport |
702
- * +-----------------------------------+
703
- * ```
704
- *
705
- * See {@link module:ui/panel/balloon/balloonpanelview~BalloonPanelView#attachTo}.
706
- *
707
- * Positioning functions must be compatible with {@link module:utils/dom/position~Position}.
708
- *
709
- * Default positioning functions with customized offsets can be generated using
710
- * {@link module:ui/panel/balloon/balloonpanelview~generatePositions}.
711
- *
712
- * The name that the position function returns will be reflected in the balloon panel's class that
713
- * controls the placement of the "arrow". See {@link #position} to learn more.
714
- */
715
- BalloonPanelView.defaultPositions = generatePositions();
716
- /**
717
- * Returns the DOM element for given object or null, if there is none,
718
- * e.g. when the passed object is a Rect instance or so.
719
- */
720
- function getDomElement(object) {
721
- if (isElement(object)) {
722
- return object;
723
- }
724
- if (isRange(object)) {
725
- return object.commonAncestorContainer;
726
- }
727
- if (typeof object == 'function') {
728
- return getDomElement(object());
729
- }
730
- return null;
731
- }
732
- /**
733
- * Returns available {@link module:ui/panel/balloon/balloonpanelview~BalloonPanelView}
734
- * {@link module:utils/dom/position~PositioningFunction positioning functions} adjusted by the specific offsets.
735
- *
736
- * @internal
737
- * @param options Options to generate positions. If not specified, this helper will simply return
738
- * {@link module:ui/panel/balloon/balloonpanelview~BalloonPanelView.defaultPositions}.
739
- * @param options.sideOffset A custom side offset (in pixels) of each position. If
740
- * not specified, {@link module:ui/panel/balloon/balloonpanelview~BalloonPanelView.arrowSideOffset the default value}
741
- * will be used.
742
- * @param options.heightOffset A custom height offset (in pixels) of each position. If
743
- * not specified, {@link module:ui/panel/balloon/balloonpanelview~BalloonPanelView.arrowHeightOffset the default value}
744
- * will be used.
745
- * @param options.stickyVerticalOffset A custom offset (in pixels) of the `viewportStickyNorth` positioning function.
746
- * If not specified, {@link module:ui/panel/balloon/balloonpanelview~BalloonPanelView.stickyVerticalOffset the default value}
747
- * will be used.
748
- * @param options.config Additional configuration of the balloon balloon panel view.
749
- * Currently only {@link module:ui/panel/balloon/balloonpanelview~BalloonPanelView#withArrow} is supported. Learn more
750
- * about {@link module:utils/dom/position~PositioningFunction positioning functions}.
751
- */
752
- export function generatePositions(options = {}) {
753
- const { sideOffset = BalloonPanelView.arrowSideOffset, heightOffset = BalloonPanelView.arrowHeightOffset, stickyVerticalOffset = BalloonPanelView.stickyVerticalOffset, config } = options;
754
- return {
755
- // ------- North west
756
- northWestArrowSouthWest: (targetRect, balloonRect) => ({
757
- top: getNorthTop(targetRect, balloonRect),
758
- left: targetRect.left - sideOffset,
759
- name: 'arrow_sw',
760
- ...(config && { config })
761
- }),
762
- northWestArrowSouthMiddleWest: (targetRect, balloonRect) => ({
763
- top: getNorthTop(targetRect, balloonRect),
764
- left: targetRect.left - (balloonRect.width * .25) - sideOffset,
765
- name: 'arrow_smw',
766
- ...(config && { config })
767
- }),
768
- northWestArrowSouth: (targetRect, balloonRect) => ({
769
- top: getNorthTop(targetRect, balloonRect),
770
- left: targetRect.left - balloonRect.width / 2,
771
- name: 'arrow_s',
772
- ...(config && { config })
773
- }),
774
- northWestArrowSouthMiddleEast: (targetRect, balloonRect) => ({
775
- top: getNorthTop(targetRect, balloonRect),
776
- left: targetRect.left - (balloonRect.width * .75) + sideOffset,
777
- name: 'arrow_sme',
778
- ...(config && { config })
779
- }),
780
- northWestArrowSouthEast: (targetRect, balloonRect) => ({
781
- top: getNorthTop(targetRect, balloonRect),
782
- left: targetRect.left - balloonRect.width + sideOffset,
783
- name: 'arrow_se',
784
- ...(config && { config })
785
- }),
786
- // ------- North
787
- northArrowSouthWest: (targetRect, balloonRect) => ({
788
- top: getNorthTop(targetRect, balloonRect),
789
- left: targetRect.left + targetRect.width / 2 - sideOffset,
790
- name: 'arrow_sw',
791
- ...(config && { config })
792
- }),
793
- northArrowSouthMiddleWest: (targetRect, balloonRect) => ({
794
- top: getNorthTop(targetRect, balloonRect),
795
- left: targetRect.left + targetRect.width / 2 - (balloonRect.width * .25) - sideOffset,
796
- name: 'arrow_smw',
797
- ...(config && { config })
798
- }),
799
- northArrowSouth: (targetRect, balloonRect) => ({
800
- top: getNorthTop(targetRect, balloonRect),
801
- left: targetRect.left + targetRect.width / 2 - balloonRect.width / 2,
802
- name: 'arrow_s',
803
- ...(config && { config })
804
- }),
805
- northArrowSouthMiddleEast: (targetRect, balloonRect) => ({
806
- top: getNorthTop(targetRect, balloonRect),
807
- left: targetRect.left + targetRect.width / 2 - (balloonRect.width * .75) + sideOffset,
808
- name: 'arrow_sme',
809
- ...(config && { config })
810
- }),
811
- northArrowSouthEast: (targetRect, balloonRect) => ({
812
- top: getNorthTop(targetRect, balloonRect),
813
- left: targetRect.left + targetRect.width / 2 - balloonRect.width + sideOffset,
814
- name: 'arrow_se',
815
- ...(config && { config })
816
- }),
817
- // ------- North east
818
- northEastArrowSouthWest: (targetRect, balloonRect) => ({
819
- top: getNorthTop(targetRect, balloonRect),
820
- left: targetRect.right - sideOffset,
821
- name: 'arrow_sw',
822
- ...(config && { config })
823
- }),
824
- northEastArrowSouthMiddleWest: (targetRect, balloonRect) => ({
825
- top: getNorthTop(targetRect, balloonRect),
826
- left: targetRect.right - (balloonRect.width * .25) - sideOffset,
827
- name: 'arrow_smw',
828
- ...(config && { config })
829
- }),
830
- northEastArrowSouth: (targetRect, balloonRect) => ({
831
- top: getNorthTop(targetRect, balloonRect),
832
- left: targetRect.right - balloonRect.width / 2,
833
- name: 'arrow_s',
834
- ...(config && { config })
835
- }),
836
- northEastArrowSouthMiddleEast: (targetRect, balloonRect) => ({
837
- top: getNorthTop(targetRect, balloonRect),
838
- left: targetRect.right - (balloonRect.width * .75) + sideOffset,
839
- name: 'arrow_sme',
840
- ...(config && { config })
841
- }),
842
- northEastArrowSouthEast: (targetRect, balloonRect) => ({
843
- top: getNorthTop(targetRect, balloonRect),
844
- left: targetRect.right - balloonRect.width + sideOffset,
845
- name: 'arrow_se',
846
- ...(config && { config })
847
- }),
848
- // ------- South west
849
- southWestArrowNorthWest: targetRect => ({
850
- top: getSouthTop(targetRect),
851
- left: targetRect.left - sideOffset,
852
- name: 'arrow_nw',
853
- ...(config && { config })
854
- }),
855
- southWestArrowNorthMiddleWest: (targetRect, balloonRect) => ({
856
- top: getSouthTop(targetRect),
857
- left: targetRect.left - (balloonRect.width * .25) - sideOffset,
858
- name: 'arrow_nmw',
859
- ...(config && { config })
860
- }),
861
- southWestArrowNorth: (targetRect, balloonRect) => ({
862
- top: getSouthTop(targetRect),
863
- left: targetRect.left - balloonRect.width / 2,
864
- name: 'arrow_n',
865
- ...(config && { config })
866
- }),
867
- southWestArrowNorthMiddleEast: (targetRect, balloonRect) => ({
868
- top: getSouthTop(targetRect),
869
- left: targetRect.left - (balloonRect.width * .75) + sideOffset,
870
- name: 'arrow_nme',
871
- ...(config && { config })
872
- }),
873
- southWestArrowNorthEast: (targetRect, balloonRect) => ({
874
- top: getSouthTop(targetRect),
875
- left: targetRect.left - balloonRect.width + sideOffset,
876
- name: 'arrow_ne',
877
- ...(config && { config })
878
- }),
879
- // ------- South
880
- southArrowNorthWest: targetRect => ({
881
- top: getSouthTop(targetRect),
882
- left: targetRect.left + targetRect.width / 2 - sideOffset,
883
- name: 'arrow_nw',
884
- ...(config && { config })
885
- }),
886
- southArrowNorthMiddleWest: (targetRect, balloonRect) => ({
887
- top: getSouthTop(targetRect),
888
- left: targetRect.left + targetRect.width / 2 - (balloonRect.width * 0.25) - sideOffset,
889
- name: 'arrow_nmw',
890
- ...(config && { config })
891
- }),
892
- southArrowNorth: (targetRect, balloonRect) => ({
893
- top: getSouthTop(targetRect),
894
- left: targetRect.left + targetRect.width / 2 - balloonRect.width / 2,
895
- name: 'arrow_n',
896
- ...(config && { config })
897
- }),
898
- southArrowNorthMiddleEast: (targetRect, balloonRect) => ({
899
- top: getSouthTop(targetRect),
900
- left: targetRect.left + targetRect.width / 2 - (balloonRect.width * 0.75) + sideOffset,
901
- name: 'arrow_nme',
902
- ...(config && { config })
903
- }),
904
- southArrowNorthEast: (targetRect, balloonRect) => ({
905
- top: getSouthTop(targetRect),
906
- left: targetRect.left + targetRect.width / 2 - balloonRect.width + sideOffset,
907
- name: 'arrow_ne',
908
- ...(config && { config })
909
- }),
910
- // ------- South east
911
- southEastArrowNorthWest: targetRect => ({
912
- top: getSouthTop(targetRect),
913
- left: targetRect.right - sideOffset,
914
- name: 'arrow_nw',
915
- ...(config && { config })
916
- }),
917
- southEastArrowNorthMiddleWest: (targetRect, balloonRect) => ({
918
- top: getSouthTop(targetRect),
919
- left: targetRect.right - (balloonRect.width * .25) - sideOffset,
920
- name: 'arrow_nmw',
921
- ...(config && { config })
922
- }),
923
- southEastArrowNorth: (targetRect, balloonRect) => ({
924
- top: getSouthTop(targetRect),
925
- left: targetRect.right - balloonRect.width / 2,
926
- name: 'arrow_n',
927
- ...(config && { config })
928
- }),
929
- southEastArrowNorthMiddleEast: (targetRect, balloonRect) => ({
930
- top: getSouthTop(targetRect),
931
- left: targetRect.right - (balloonRect.width * .75) + sideOffset,
932
- name: 'arrow_nme',
933
- ...(config && { config })
934
- }),
935
- southEastArrowNorthEast: (targetRect, balloonRect) => ({
936
- top: getSouthTop(targetRect),
937
- left: targetRect.right - balloonRect.width + sideOffset,
938
- name: 'arrow_ne',
939
- ...(config && { config })
940
- }),
941
- // ------- West
942
- westArrowEast: (targetRect, balloonRect) => ({
943
- top: targetRect.top + targetRect.height / 2 - balloonRect.height / 2,
944
- left: targetRect.left - balloonRect.width - heightOffset,
945
- name: 'arrow_e',
946
- ...(config && { config })
947
- }),
948
- // ------- East
949
- eastArrowWest: (targetRect, balloonRect) => ({
950
- top: targetRect.top + targetRect.height / 2 - balloonRect.height / 2,
951
- left: targetRect.right + heightOffset,
952
- name: 'arrow_w',
953
- ...(config && { config })
954
- }),
955
- // ------- Sticky
956
- viewportStickyNorth: (targetRect, balloonRect, viewportRect) => {
957
- if (!targetRect.getIntersection(viewportRect)) {
958
- return null;
959
- }
960
- return {
961
- top: viewportRect.top + stickyVerticalOffset,
962
- left: targetRect.left + targetRect.width / 2 - balloonRect.width / 2,
963
- name: 'arrowless',
964
- config: {
965
- withArrow: false,
966
- ...config
967
- }
968
- };
969
- }
970
- };
971
- /**
972
- * Returns the top coordinate for positions starting with `north*`.
973
- *
974
- * @param targetRect A rect of the target.
975
- * @param balloonRect A rect of the balloon.
976
- */
977
- function getNorthTop(targetRect, balloonRect) {
978
- return targetRect.top - balloonRect.height - heightOffset;
979
- }
980
- /**
981
- * Returns the top coordinate for positions starting with `south*`.
982
- *
983
- * @param targetRect A rect of the target.
984
- */
985
- function getSouthTop(targetRect) {
986
- return targetRect.bottom + heightOffset;
987
- }
988
- }
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 ui/panel/balloon/balloonpanelview
7
+ */
8
+ import View from '../../view';
9
+ import { getOptimalPosition, global, isRange, toUnit } from '@ckeditor/ckeditor5-utils';
10
+ import { isElement } from 'lodash-es';
11
+ import '../../../theme/components/panel/balloonpanel.css';
12
+ const toPx = toUnit('px');
13
+ const defaultLimiterElement = global.document.body;
14
+ /**
15
+ * The balloon panel view class.
16
+ *
17
+ * A floating container which can
18
+ * {@link module:ui/panel/balloon/balloonpanelview~BalloonPanelView#pin pin} to any
19
+ * {@link module:utils/dom/position~Options#target target} in the DOM and remain in that position
20
+ * e.g. when the web page is scrolled.
21
+ *
22
+ * The balloon panel can be used to display contextual, non-blocking UI like forms, toolbars and
23
+ * the like in its {@link module:ui/panel/balloon/balloonpanelview~BalloonPanelView#content} view
24
+ * collection.
25
+ *
26
+ * There is a number of {@link module:ui/panel/balloon/balloonpanelview~BalloonPanelView.defaultPositions}
27
+ * that the balloon can use, automatically switching from one to another when the viewport space becomes
28
+ * scarce to keep the balloon visible to the user as long as it is possible. The balloon will also
29
+ * accept any custom position set provided by the user compatible with the
30
+ * {@link module:utils/dom/position~Options options}.
31
+ *
32
+ * ```ts
33
+ * const panel = new BalloonPanelView( locale );
34
+ * const childView = new ChildView();
35
+ * const positions = BalloonPanelView.defaultPositions;
36
+ *
37
+ * panel.render();
38
+ *
39
+ * // Add a child view to the panel's content collection.
40
+ * panel.content.add( childView );
41
+ *
42
+ * // Start pinning the panel to an element with the "target" id DOM.
43
+ * // The balloon will remain pinned until unpin() is called.
44
+ * panel.pin( {
45
+ * target: document.querySelector( '#target' ),
46
+ * positions: [
47
+ * positions.northArrowSouth,
48
+ * positions.southArrowNorth
49
+ * ]
50
+ * } );
51
+ * ```
52
+ */
53
+ export default class BalloonPanelView extends View {
54
+ /**
55
+ * @inheritDoc
56
+ */
57
+ constructor(locale) {
58
+ super(locale);
59
+ const bind = this.bindTemplate;
60
+ this.set('top', 0);
61
+ this.set('left', 0);
62
+ this.set('position', 'arrow_nw');
63
+ this.set('isVisible', false);
64
+ this.set('withArrow', true);
65
+ this.set('class', undefined);
66
+ this._pinWhenIsVisibleCallback = null;
67
+ this.content = this.createCollection();
68
+ this.setTemplate({
69
+ tag: 'div',
70
+ attributes: {
71
+ class: [
72
+ 'ck',
73
+ 'ck-balloon-panel',
74
+ bind.to('position', value => `ck-balloon-panel_${value}`),
75
+ bind.if('isVisible', 'ck-balloon-panel_visible'),
76
+ bind.if('withArrow', 'ck-balloon-panel_with-arrow'),
77
+ bind.to('class')
78
+ ],
79
+ style: {
80
+ top: bind.to('top', toPx),
81
+ left: bind.to('left', toPx)
82
+ }
83
+ },
84
+ children: this.content
85
+ });
86
+ }
87
+ /**
88
+ * Shows the panel.
89
+ *
90
+ * See {@link #isVisible}.
91
+ */
92
+ show() {
93
+ this.isVisible = true;
94
+ }
95
+ /**
96
+ * Hides the panel.
97
+ *
98
+ * See {@link #isVisible}.
99
+ */
100
+ hide() {
101
+ this.isVisible = false;
102
+ }
103
+ /**
104
+ * Attaches the panel to a specified {@link module:utils/dom/position~Options#target} with a
105
+ * smart positioning heuristics that chooses from available positions to make sure the panel
106
+ * is visible to the user i.e. within the limits of the viewport.
107
+ *
108
+ * This method accepts configuration {@link module:utils/dom/position~Options options}
109
+ * to set the `target`, optional `limiter` and `positions` the balloon should choose from.
110
+ *
111
+ * ```ts
112
+ * const panel = new BalloonPanelView( locale );
113
+ * const positions = BalloonPanelView.defaultPositions;
114
+ *
115
+ * panel.render();
116
+ *
117
+ * // Attach the panel to an element with the "target" id DOM.
118
+ * panel.attachTo( {
119
+ * target: document.querySelector( '#target' ),
120
+ * positions: [
121
+ * positions.northArrowSouth,
122
+ * positions.southArrowNorth
123
+ * ]
124
+ * } );
125
+ * ```
126
+ *
127
+ * **Note**: Attaching the panel will also automatically {@link #show} it.
128
+ *
129
+ * **Note**: An attached panel will not follow its target when the window is scrolled or resized.
130
+ * See the {@link #pin} method for a more permanent positioning strategy.
131
+ *
132
+ * @param options Positioning options compatible with {@link module:utils/dom/position~getOptimalPosition}.
133
+ * Default `positions` array is {@link module:ui/panel/balloon/balloonpanelview~BalloonPanelView.defaultPositions}.
134
+ */
135
+ attachTo(options) {
136
+ this.show();
137
+ const defaultPositions = BalloonPanelView.defaultPositions;
138
+ const positionOptions = Object.assign({}, {
139
+ element: this.element,
140
+ positions: [
141
+ defaultPositions.southArrowNorth,
142
+ defaultPositions.southArrowNorthMiddleWest,
143
+ defaultPositions.southArrowNorthMiddleEast,
144
+ defaultPositions.southArrowNorthWest,
145
+ defaultPositions.southArrowNorthEast,
146
+ defaultPositions.northArrowSouth,
147
+ defaultPositions.northArrowSouthMiddleWest,
148
+ defaultPositions.northArrowSouthMiddleEast,
149
+ defaultPositions.northArrowSouthWest,
150
+ defaultPositions.northArrowSouthEast,
151
+ defaultPositions.viewportStickyNorth
152
+ ],
153
+ limiter: defaultLimiterElement,
154
+ fitInViewport: true
155
+ }, options);
156
+ const optimalPosition = BalloonPanelView._getOptimalPosition(positionOptions);
157
+ // Usually browsers make some problems with super accurate values like 104.345px
158
+ // so it is better to use int values.
159
+ const left = parseInt(optimalPosition.left);
160
+ const top = parseInt(optimalPosition.top);
161
+ const position = optimalPosition.name;
162
+ const config = optimalPosition.config || {};
163
+ const { withArrow = true } = config;
164
+ this.top = top;
165
+ this.left = left;
166
+ this.position = position;
167
+ this.withArrow = withArrow;
168
+ }
169
+ /**
170
+ * Works the same way as the {@link #attachTo} method except that the position of the panel is
171
+ * continuously updated when:
172
+ *
173
+ * * any ancestor of the {@link module:utils/dom/position~Options#target}
174
+ * or {@link module:utils/dom/position~Options#limiter} is scrolled,
175
+ * * the browser window gets resized or scrolled.
176
+ *
177
+ * Thanks to that, the panel always sticks to the {@link module:utils/dom/position~Options#target}
178
+ * and is immune to the changing environment.
179
+ *
180
+ * ```ts
181
+ * const panel = new BalloonPanelView( locale );
182
+ * const positions = BalloonPanelView.defaultPositions;
183
+ *
184
+ * panel.render();
185
+ *
186
+ * // Pin the panel to an element with the "target" id DOM.
187
+ * panel.pin( {
188
+ * target: document.querySelector( '#target' ),
189
+ * positions: [
190
+ * positions.northArrowSouth,
191
+ * positions.southArrowNorth
192
+ * ]
193
+ * } );
194
+ * ```
195
+ *
196
+ * To leave the pinned state, use the {@link #unpin} method.
197
+ *
198
+ * **Note**: Pinning the panel will also automatically {@link #show} it.
199
+ *
200
+ * @param options Positioning options compatible with {@link module:utils/dom/position~getOptimalPosition}.
201
+ * Default `positions` array is {@link module:ui/panel/balloon/balloonpanelview~BalloonPanelView.defaultPositions}.
202
+ */
203
+ pin(options) {
204
+ this.unpin();
205
+ this._pinWhenIsVisibleCallback = () => {
206
+ if (this.isVisible) {
207
+ this._startPinning(options);
208
+ }
209
+ else {
210
+ this._stopPinning();
211
+ }
212
+ };
213
+ this._startPinning(options);
214
+ // Control the state of the listeners depending on whether the panel is visible
215
+ // or not.
216
+ // TODO: Use on() (https://github.com/ckeditor/ckeditor5-utils/issues/144).
217
+ this.listenTo(this, 'change:isVisible', this._pinWhenIsVisibleCallback);
218
+ }
219
+ /**
220
+ * Stops pinning the panel, as set up by {@link #pin}.
221
+ */
222
+ unpin() {
223
+ if (this._pinWhenIsVisibleCallback) {
224
+ // Deactivate listeners attached by pin().
225
+ this._stopPinning();
226
+ // Deactivate the panel pin() control logic.
227
+ // TODO: Use off() (https://github.com/ckeditor/ckeditor5-utils/issues/144).
228
+ this.stopListening(this, 'change:isVisible', this._pinWhenIsVisibleCallback);
229
+ this._pinWhenIsVisibleCallback = null;
230
+ this.hide();
231
+ }
232
+ }
233
+ /**
234
+ * Starts managing the pinned state of the panel. See {@link #pin}.
235
+ *
236
+ * @param options Positioning options compatible with {@link module:utils/dom/position~getOptimalPosition}.
237
+ */
238
+ _startPinning(options) {
239
+ this.attachTo(options);
240
+ const targetElement = getDomElement(options.target);
241
+ const limiterElement = options.limiter ? getDomElement(options.limiter) : defaultLimiterElement;
242
+ // Then we need to listen on scroll event of eny element in the document.
243
+ this.listenTo(global.document, 'scroll', (evt, domEvt) => {
244
+ const scrollTarget = domEvt.target;
245
+ // The position needs to be updated if the positioning target is within the scrolled element.
246
+ const isWithinScrollTarget = targetElement && scrollTarget.contains(targetElement);
247
+ // The position needs to be updated if the positioning limiter is within the scrolled element.
248
+ const isLimiterWithinScrollTarget = limiterElement && scrollTarget.contains(limiterElement);
249
+ // The positioning target and/or limiter can be a Rect, object etc..
250
+ // There's no way to optimize the listener then.
251
+ if (isWithinScrollTarget || isLimiterWithinScrollTarget || !targetElement || !limiterElement) {
252
+ this.attachTo(options);
253
+ }
254
+ }, { useCapture: true });
255
+ // We need to listen on window resize event and update position.
256
+ this.listenTo(global.window, 'resize', () => {
257
+ this.attachTo(options);
258
+ });
259
+ }
260
+ /**
261
+ * Stops managing the pinned state of the panel. See {@link #pin}.
262
+ */
263
+ _stopPinning() {
264
+ this.stopListening(global.document, 'scroll');
265
+ this.stopListening(global.window, 'resize');
266
+ }
267
+ }
268
+ /**
269
+ * A side offset of the arrow tip from the edge of the balloon. Controlled by CSS.
270
+ *
271
+ * ```
272
+ * ┌───────────────────────┐
273
+ * │ │
274
+ * │ Balloon │
275
+ * │ Content │
276
+ * │ │
277
+ * └──+ +───────────────┘
278
+ * | \ /
279
+ * | \/
280
+ * >┼─────┼< ─────────────────────── side offset
281
+ *
282
+ * ```
283
+ *
284
+ * @default 25
285
+ */
286
+ BalloonPanelView.arrowSideOffset = 25;
287
+ /**
288
+ * A height offset of the arrow from the edge of the balloon. Controlled by CSS.
289
+ *
290
+ * ```
291
+ * ┌───────────────────────┐
292
+ * │ │
293
+ * │ Balloon │
294
+ * │ Content │ ╱-- arrow height offset
295
+ * │ │ V
296
+ * └──+ +───────────────┘ --- ─┼───────
297
+ * \ / │
298
+ * \/ │
299
+ * ────────────────────────────────┼───────
300
+ * ^
301
+ *
302
+ *
303
+ * >┼────┼< arrow height offset
304
+ * │ │
305
+ * │ ┌────────────────────────┐
306
+ * │ │ │
307
+ * │ ╱ │
308
+ * │ ╱ Balloon │
309
+ * │ ╲ Content │
310
+ * │ ╲ │
311
+ * │ │ │
312
+ * │ └────────────────────────┘
313
+ * ```
314
+ *
315
+ * @default 10
316
+ */
317
+ BalloonPanelView.arrowHeightOffset = 10;
318
+ /**
319
+ * A vertical offset of the balloon panel from the edge of the viewport if sticky.
320
+ * It helps in accessing toolbar buttons underneath the balloon panel.
321
+ *
322
+ * ```
323
+ * ┌───────────────────────────────────────────────────┐
324
+ * │ Target │
325
+ * │ │
326
+ * │ /── vertical offset │
327
+ * ┌─────────────────────────────V─────────────────────────┐
328
+ * │ Toolbar ┌─────────────┐ │
329
+ * ├────────────────────│ Balloon │────────────────────┤
330
+ * │ │ └─────────────┘ │ │
331
+ * │ │ │ │
332
+ * │ │ │ │
333
+ * │ │ │ │
334
+ * │ └───────────────────────────────────────────────────┘ │
335
+ * │ Viewport │
336
+ * └───────────────────────────────────────────────────────┘
337
+ * ```
338
+ *
339
+ * @default 20
340
+ */
341
+ BalloonPanelView.stickyVerticalOffset = 20;
342
+ /**
343
+ * Function used to calculate the optimal position for the balloon.
344
+ */
345
+ BalloonPanelView._getOptimalPosition = getOptimalPosition;
346
+ /**
347
+ * A default set of positioning functions used by the balloon panel view
348
+ * when attaching using the {@link module:ui/panel/balloon/balloonpanelview~BalloonPanelView#attachTo} method.
349
+ *
350
+ * The available positioning functions are as follows:
351
+ *
352
+ * **North west**
353
+ *
354
+ * * `northWestArrowSouthWest`
355
+ *
356
+ * ```
357
+ * +-----------------+
358
+ * | Balloon |
359
+ * +-----------------+
360
+ * V
361
+ * [ Target ]
362
+ * ```
363
+ *
364
+ * * `northWestArrowSouthMiddleWest`
365
+ *
366
+ * ```
367
+ * +-----------------+
368
+ * | Balloon |
369
+ * +-----------------+
370
+ * V
371
+ * [ Target ]
372
+ * ```
373
+ *
374
+ * * `northWestArrowSouth`
375
+ *
376
+ * ```
377
+ * +-----------------+
378
+ * | Balloon |
379
+ * +-----------------+
380
+ * V
381
+ * [ Target ]
382
+ * ```
383
+ *
384
+ * * `northWestArrowSouthMiddleEast`
385
+ *
386
+ * ```
387
+ * +-----------------+
388
+ * | Balloon |
389
+ * +-----------------+
390
+ * V
391
+ * [ Target ]
392
+ * ```
393
+ *
394
+ * * `northWestArrowSouthEast`
395
+ *
396
+ * ```
397
+ * +-----------------+
398
+ * | Balloon |
399
+ * +-----------------+
400
+ * V
401
+ * [ Target ]
402
+ * ```
403
+ *
404
+ * **North**
405
+ *
406
+ * * `northArrowSouthWest`
407
+ *
408
+ * ```
409
+ * +-----------------+
410
+ * | Balloon |
411
+ * +-----------------+
412
+ * V
413
+ * [ Target ]
414
+ * ```
415
+ *
416
+ * * `northArrowSouthMiddleWest`
417
+ *
418
+ * ```
419
+ * +-----------------+
420
+ * | Balloon |
421
+ * +-----------------+
422
+ * V
423
+ * [ Target ]
424
+ * ```
425
+ * * `northArrowSouth`
426
+ *
427
+ * ```
428
+ * +-----------------+
429
+ * | Balloon |
430
+ * +-----------------+
431
+ * V
432
+ * [ Target ]
433
+ * ```
434
+ *
435
+ * * `northArrowSouthMiddleEast`
436
+ *
437
+ * ```
438
+ * +-----------------+
439
+ * | Balloon |
440
+ * +-----------------+
441
+ * V
442
+ * [ Target ]
443
+ * ```
444
+ *
445
+ * * `northArrowSouthEast`
446
+ *
447
+ * ```
448
+ * +-----------------+
449
+ * | Balloon |
450
+ * +-----------------+
451
+ * V
452
+ * [ Target ]
453
+ * ```
454
+ *
455
+ * **North east**
456
+ *
457
+ * * `northEastArrowSouthWest`
458
+ *
459
+ * ```
460
+ * +-----------------+
461
+ * | Balloon |
462
+ * +-----------------+
463
+ * V
464
+ * [ Target ]
465
+ * ```
466
+ *
467
+ * * `northEastArrowSouthMiddleWest`
468
+ *
469
+ * ```
470
+ * +-----------------+
471
+ * | Balloon |
472
+ * +-----------------+
473
+ * V
474
+ * [ Target ]
475
+ * ```
476
+ *
477
+ * * `northEastArrowSouth`
478
+ *
479
+ * ```
480
+ * +-----------------+
481
+ * | Balloon |
482
+ * +-----------------+
483
+ * V
484
+ * [ Target ]
485
+ * ```
486
+ *
487
+ * * `northEastArrowSouthMiddleEast`
488
+ *
489
+ * ```
490
+ * +-----------------+
491
+ * | Balloon |
492
+ * +-----------------+
493
+ * V
494
+ * [ Target ]
495
+ * ```
496
+ *
497
+ * * `northEastArrowSouthEast`
498
+ *
499
+ * ```
500
+ * +-----------------+
501
+ * | Balloon |
502
+ * +-----------------+
503
+ * V
504
+ * [ Target ]
505
+ * ```
506
+ *
507
+ * **South**
508
+ *
509
+ * * `southArrowNorthWest`
510
+ *
511
+ * ```
512
+ * [ Target ]
513
+ * ^
514
+ * +-----------------+
515
+ * | Balloon |
516
+ * +-----------------+
517
+ * ```
518
+ *
519
+ * * `southArrowNorthMiddleWest`
520
+ *
521
+ * ```
522
+ * [ Target ]
523
+ * ^
524
+ * +-----------------+
525
+ * | Balloon |
526
+ * +-----------------+
527
+ * ```
528
+ *
529
+ * * `southArrowNorth`
530
+ *
531
+ * ```
532
+ * [ Target ]
533
+ * ^
534
+ * +-----------------+
535
+ * | Balloon |
536
+ * +-----------------+
537
+ * ```
538
+ *
539
+ * * `southArrowNorthMiddleEast`
540
+ *
541
+ * ```
542
+ * [ Target ]
543
+ * ^
544
+ * +-----------------+
545
+ * | Balloon |
546
+ * +-----------------+
547
+ * ```
548
+ *
549
+ * * `southArrowNorthEast`
550
+ *
551
+ * ```
552
+ * [ Target ]
553
+ * ^
554
+ * +-----------------+
555
+ * | Balloon |
556
+ * +-----------------+
557
+ * ```
558
+ *
559
+ * **South west**
560
+ *
561
+ * * `southWestArrowNorthWest`
562
+ *
563
+ *
564
+ * ```
565
+ * [ Target ]
566
+ * ^
567
+ * +-----------------+
568
+ * | Balloon |
569
+ * +-----------------+
570
+ * ```
571
+ *
572
+ * * `southWestArrowNorthMiddleWest`
573
+ *
574
+ * ```
575
+ * [ Target ]
576
+ * ^
577
+ * +-----------------+
578
+ * | Balloon |
579
+ * +-----------------+
580
+ * ```
581
+ *
582
+ * * `southWestArrowNorth`
583
+ *
584
+ * ```
585
+ * [ Target ]
586
+ * ^
587
+ * +-----------------+
588
+ * | Balloon |
589
+ * +-----------------+
590
+ * ```
591
+ *
592
+ * * `southWestArrowNorthMiddleEast`
593
+ *
594
+ * ```
595
+ * [ Target ]
596
+ * ^
597
+ * +-----------------+
598
+ * | Balloon |
599
+ * +-----------------+
600
+ * ```
601
+ *
602
+ * * `southWestArrowNorthEast`
603
+ *
604
+ * ```
605
+ * [ Target ]
606
+ * ^
607
+ * +-----------------+
608
+ * | Balloon |
609
+ * +-----------------+
610
+ * ```
611
+ *
612
+ * **South east**
613
+ *
614
+ * * `southEastArrowNorthWest`
615
+ *
616
+ * ```
617
+ * [ Target ]
618
+ * ^
619
+ * +-----------------+
620
+ * | Balloon |
621
+ * +-----------------+
622
+ * ```
623
+ *
624
+ * * `southEastArrowNorthMiddleWest`
625
+ *
626
+ * ```
627
+ * [ Target ]
628
+ * ^
629
+ * +-----------------+
630
+ * | Balloon |
631
+ * +-----------------+
632
+ * ```
633
+ *
634
+ * * `southEastArrowNorth`
635
+ *
636
+ * ```
637
+ * [ Target ]
638
+ * ^
639
+ * +-----------------+
640
+ * | Balloon |
641
+ * +-----------------+
642
+ * ```
643
+ *
644
+ * * `southEastArrowNorthMiddleEast`
645
+ *
646
+ * ```
647
+ * [ Target ]
648
+ * ^
649
+ * +-----------------+
650
+ * | Balloon |
651
+ * +-----------------+
652
+ * ```
653
+ *
654
+ * * `southEastArrowNorthEast`
655
+ *
656
+ * ```
657
+ * [ Target ]
658
+ * ^
659
+ * +-----------------+
660
+ * | Balloon |
661
+ * +-----------------+
662
+ * ```
663
+ *
664
+ * **West**
665
+ *
666
+ * * `westArrowEast`
667
+ *
668
+ * ```
669
+ * +-----------------+
670
+ * | Balloon |>[ Target ]
671
+ * +-----------------+
672
+ * ```
673
+ *
674
+ * **East**
675
+ *
676
+ * * `eastArrowWest`
677
+ *
678
+ * ```
679
+ * +-----------------+
680
+ * [ Target ]<| Balloon |
681
+ * +-----------------+
682
+ * ```
683
+ *
684
+ * **Sticky**
685
+ *
686
+ * * `viewportStickyNorth`
687
+ *
688
+ * ```
689
+ * +---------------------------+
690
+ * | [ Target ] |
691
+ * | |
692
+ * +-----------------------------------+
693
+ * | | +-----------------+ | |
694
+ * | | | Balloon | | |
695
+ * | | +-----------------+ | |
696
+ * | | | |
697
+ * | | | |
698
+ * | | | |
699
+ * | | | |
700
+ * | +---------------------------+ |
701
+ * | Viewport |
702
+ * +-----------------------------------+
703
+ * ```
704
+ *
705
+ * See {@link module:ui/panel/balloon/balloonpanelview~BalloonPanelView#attachTo}.
706
+ *
707
+ * Positioning functions must be compatible with {@link module:utils/dom/position~Position}.
708
+ *
709
+ * Default positioning functions with customized offsets can be generated using
710
+ * {@link module:ui/panel/balloon/balloonpanelview~generatePositions}.
711
+ *
712
+ * The name that the position function returns will be reflected in the balloon panel's class that
713
+ * controls the placement of the "arrow". See {@link #position} to learn more.
714
+ */
715
+ BalloonPanelView.defaultPositions = generatePositions();
716
+ /**
717
+ * Returns the DOM element for given object or null, if there is none,
718
+ * e.g. when the passed object is a Rect instance or so.
719
+ */
720
+ function getDomElement(object) {
721
+ if (isElement(object)) {
722
+ return object;
723
+ }
724
+ if (isRange(object)) {
725
+ return object.commonAncestorContainer;
726
+ }
727
+ if (typeof object == 'function') {
728
+ return getDomElement(object());
729
+ }
730
+ return null;
731
+ }
732
+ /**
733
+ * Returns available {@link module:ui/panel/balloon/balloonpanelview~BalloonPanelView}
734
+ * {@link module:utils/dom/position~PositioningFunction positioning functions} adjusted by the specific offsets.
735
+ *
736
+ * @internal
737
+ * @param options Options to generate positions. If not specified, this helper will simply return
738
+ * {@link module:ui/panel/balloon/balloonpanelview~BalloonPanelView.defaultPositions}.
739
+ * @param options.sideOffset A custom side offset (in pixels) of each position. If
740
+ * not specified, {@link module:ui/panel/balloon/balloonpanelview~BalloonPanelView.arrowSideOffset the default value}
741
+ * will be used.
742
+ * @param options.heightOffset A custom height offset (in pixels) of each position. If
743
+ * not specified, {@link module:ui/panel/balloon/balloonpanelview~BalloonPanelView.arrowHeightOffset the default value}
744
+ * will be used.
745
+ * @param options.stickyVerticalOffset A custom offset (in pixels) of the `viewportStickyNorth` positioning function.
746
+ * If not specified, {@link module:ui/panel/balloon/balloonpanelview~BalloonPanelView.stickyVerticalOffset the default value}
747
+ * will be used.
748
+ * @param options.config Additional configuration of the balloon balloon panel view.
749
+ * Currently only {@link module:ui/panel/balloon/balloonpanelview~BalloonPanelView#withArrow} is supported. Learn more
750
+ * about {@link module:utils/dom/position~PositioningFunction positioning functions}.
751
+ */
752
+ export function generatePositions(options = {}) {
753
+ const { sideOffset = BalloonPanelView.arrowSideOffset, heightOffset = BalloonPanelView.arrowHeightOffset, stickyVerticalOffset = BalloonPanelView.stickyVerticalOffset, config } = options;
754
+ return {
755
+ // ------- North west
756
+ northWestArrowSouthWest: (targetRect, balloonRect) => ({
757
+ top: getNorthTop(targetRect, balloonRect),
758
+ left: targetRect.left - sideOffset,
759
+ name: 'arrow_sw',
760
+ ...(config && { config })
761
+ }),
762
+ northWestArrowSouthMiddleWest: (targetRect, balloonRect) => ({
763
+ top: getNorthTop(targetRect, balloonRect),
764
+ left: targetRect.left - (balloonRect.width * .25) - sideOffset,
765
+ name: 'arrow_smw',
766
+ ...(config && { config })
767
+ }),
768
+ northWestArrowSouth: (targetRect, balloonRect) => ({
769
+ top: getNorthTop(targetRect, balloonRect),
770
+ left: targetRect.left - balloonRect.width / 2,
771
+ name: 'arrow_s',
772
+ ...(config && { config })
773
+ }),
774
+ northWestArrowSouthMiddleEast: (targetRect, balloonRect) => ({
775
+ top: getNorthTop(targetRect, balloonRect),
776
+ left: targetRect.left - (balloonRect.width * .75) + sideOffset,
777
+ name: 'arrow_sme',
778
+ ...(config && { config })
779
+ }),
780
+ northWestArrowSouthEast: (targetRect, balloonRect) => ({
781
+ top: getNorthTop(targetRect, balloonRect),
782
+ left: targetRect.left - balloonRect.width + sideOffset,
783
+ name: 'arrow_se',
784
+ ...(config && { config })
785
+ }),
786
+ // ------- North
787
+ northArrowSouthWest: (targetRect, balloonRect) => ({
788
+ top: getNorthTop(targetRect, balloonRect),
789
+ left: targetRect.left + targetRect.width / 2 - sideOffset,
790
+ name: 'arrow_sw',
791
+ ...(config && { config })
792
+ }),
793
+ northArrowSouthMiddleWest: (targetRect, balloonRect) => ({
794
+ top: getNorthTop(targetRect, balloonRect),
795
+ left: targetRect.left + targetRect.width / 2 - (balloonRect.width * .25) - sideOffset,
796
+ name: 'arrow_smw',
797
+ ...(config && { config })
798
+ }),
799
+ northArrowSouth: (targetRect, balloonRect) => ({
800
+ top: getNorthTop(targetRect, balloonRect),
801
+ left: targetRect.left + targetRect.width / 2 - balloonRect.width / 2,
802
+ name: 'arrow_s',
803
+ ...(config && { config })
804
+ }),
805
+ northArrowSouthMiddleEast: (targetRect, balloonRect) => ({
806
+ top: getNorthTop(targetRect, balloonRect),
807
+ left: targetRect.left + targetRect.width / 2 - (balloonRect.width * .75) + sideOffset,
808
+ name: 'arrow_sme',
809
+ ...(config && { config })
810
+ }),
811
+ northArrowSouthEast: (targetRect, balloonRect) => ({
812
+ top: getNorthTop(targetRect, balloonRect),
813
+ left: targetRect.left + targetRect.width / 2 - balloonRect.width + sideOffset,
814
+ name: 'arrow_se',
815
+ ...(config && { config })
816
+ }),
817
+ // ------- North east
818
+ northEastArrowSouthWest: (targetRect, balloonRect) => ({
819
+ top: getNorthTop(targetRect, balloonRect),
820
+ left: targetRect.right - sideOffset,
821
+ name: 'arrow_sw',
822
+ ...(config && { config })
823
+ }),
824
+ northEastArrowSouthMiddleWest: (targetRect, balloonRect) => ({
825
+ top: getNorthTop(targetRect, balloonRect),
826
+ left: targetRect.right - (balloonRect.width * .25) - sideOffset,
827
+ name: 'arrow_smw',
828
+ ...(config && { config })
829
+ }),
830
+ northEastArrowSouth: (targetRect, balloonRect) => ({
831
+ top: getNorthTop(targetRect, balloonRect),
832
+ left: targetRect.right - balloonRect.width / 2,
833
+ name: 'arrow_s',
834
+ ...(config && { config })
835
+ }),
836
+ northEastArrowSouthMiddleEast: (targetRect, balloonRect) => ({
837
+ top: getNorthTop(targetRect, balloonRect),
838
+ left: targetRect.right - (balloonRect.width * .75) + sideOffset,
839
+ name: 'arrow_sme',
840
+ ...(config && { config })
841
+ }),
842
+ northEastArrowSouthEast: (targetRect, balloonRect) => ({
843
+ top: getNorthTop(targetRect, balloonRect),
844
+ left: targetRect.right - balloonRect.width + sideOffset,
845
+ name: 'arrow_se',
846
+ ...(config && { config })
847
+ }),
848
+ // ------- South west
849
+ southWestArrowNorthWest: targetRect => ({
850
+ top: getSouthTop(targetRect),
851
+ left: targetRect.left - sideOffset,
852
+ name: 'arrow_nw',
853
+ ...(config && { config })
854
+ }),
855
+ southWestArrowNorthMiddleWest: (targetRect, balloonRect) => ({
856
+ top: getSouthTop(targetRect),
857
+ left: targetRect.left - (balloonRect.width * .25) - sideOffset,
858
+ name: 'arrow_nmw',
859
+ ...(config && { config })
860
+ }),
861
+ southWestArrowNorth: (targetRect, balloonRect) => ({
862
+ top: getSouthTop(targetRect),
863
+ left: targetRect.left - balloonRect.width / 2,
864
+ name: 'arrow_n',
865
+ ...(config && { config })
866
+ }),
867
+ southWestArrowNorthMiddleEast: (targetRect, balloonRect) => ({
868
+ top: getSouthTop(targetRect),
869
+ left: targetRect.left - (balloonRect.width * .75) + sideOffset,
870
+ name: 'arrow_nme',
871
+ ...(config && { config })
872
+ }),
873
+ southWestArrowNorthEast: (targetRect, balloonRect) => ({
874
+ top: getSouthTop(targetRect),
875
+ left: targetRect.left - balloonRect.width + sideOffset,
876
+ name: 'arrow_ne',
877
+ ...(config && { config })
878
+ }),
879
+ // ------- South
880
+ southArrowNorthWest: targetRect => ({
881
+ top: getSouthTop(targetRect),
882
+ left: targetRect.left + targetRect.width / 2 - sideOffset,
883
+ name: 'arrow_nw',
884
+ ...(config && { config })
885
+ }),
886
+ southArrowNorthMiddleWest: (targetRect, balloonRect) => ({
887
+ top: getSouthTop(targetRect),
888
+ left: targetRect.left + targetRect.width / 2 - (balloonRect.width * 0.25) - sideOffset,
889
+ name: 'arrow_nmw',
890
+ ...(config && { config })
891
+ }),
892
+ southArrowNorth: (targetRect, balloonRect) => ({
893
+ top: getSouthTop(targetRect),
894
+ left: targetRect.left + targetRect.width / 2 - balloonRect.width / 2,
895
+ name: 'arrow_n',
896
+ ...(config && { config })
897
+ }),
898
+ southArrowNorthMiddleEast: (targetRect, balloonRect) => ({
899
+ top: getSouthTop(targetRect),
900
+ left: targetRect.left + targetRect.width / 2 - (balloonRect.width * 0.75) + sideOffset,
901
+ name: 'arrow_nme',
902
+ ...(config && { config })
903
+ }),
904
+ southArrowNorthEast: (targetRect, balloonRect) => ({
905
+ top: getSouthTop(targetRect),
906
+ left: targetRect.left + targetRect.width / 2 - balloonRect.width + sideOffset,
907
+ name: 'arrow_ne',
908
+ ...(config && { config })
909
+ }),
910
+ // ------- South east
911
+ southEastArrowNorthWest: targetRect => ({
912
+ top: getSouthTop(targetRect),
913
+ left: targetRect.right - sideOffset,
914
+ name: 'arrow_nw',
915
+ ...(config && { config })
916
+ }),
917
+ southEastArrowNorthMiddleWest: (targetRect, balloonRect) => ({
918
+ top: getSouthTop(targetRect),
919
+ left: targetRect.right - (balloonRect.width * .25) - sideOffset,
920
+ name: 'arrow_nmw',
921
+ ...(config && { config })
922
+ }),
923
+ southEastArrowNorth: (targetRect, balloonRect) => ({
924
+ top: getSouthTop(targetRect),
925
+ left: targetRect.right - balloonRect.width / 2,
926
+ name: 'arrow_n',
927
+ ...(config && { config })
928
+ }),
929
+ southEastArrowNorthMiddleEast: (targetRect, balloonRect) => ({
930
+ top: getSouthTop(targetRect),
931
+ left: targetRect.right - (balloonRect.width * .75) + sideOffset,
932
+ name: 'arrow_nme',
933
+ ...(config && { config })
934
+ }),
935
+ southEastArrowNorthEast: (targetRect, balloonRect) => ({
936
+ top: getSouthTop(targetRect),
937
+ left: targetRect.right - balloonRect.width + sideOffset,
938
+ name: 'arrow_ne',
939
+ ...(config && { config })
940
+ }),
941
+ // ------- West
942
+ westArrowEast: (targetRect, balloonRect) => ({
943
+ top: targetRect.top + targetRect.height / 2 - balloonRect.height / 2,
944
+ left: targetRect.left - balloonRect.width - heightOffset,
945
+ name: 'arrow_e',
946
+ ...(config && { config })
947
+ }),
948
+ // ------- East
949
+ eastArrowWest: (targetRect, balloonRect) => ({
950
+ top: targetRect.top + targetRect.height / 2 - balloonRect.height / 2,
951
+ left: targetRect.right + heightOffset,
952
+ name: 'arrow_w',
953
+ ...(config && { config })
954
+ }),
955
+ // ------- Sticky
956
+ viewportStickyNorth: (targetRect, balloonRect, viewportRect) => {
957
+ if (!targetRect.getIntersection(viewportRect)) {
958
+ return null;
959
+ }
960
+ return {
961
+ top: viewportRect.top + stickyVerticalOffset,
962
+ left: targetRect.left + targetRect.width / 2 - balloonRect.width / 2,
963
+ name: 'arrowless',
964
+ config: {
965
+ withArrow: false,
966
+ ...config
967
+ }
968
+ };
969
+ }
970
+ };
971
+ /**
972
+ * Returns the top coordinate for positions starting with `north*`.
973
+ *
974
+ * @param targetRect A rect of the target.
975
+ * @param balloonRect A rect of the balloon.
976
+ */
977
+ function getNorthTop(targetRect, balloonRect) {
978
+ return targetRect.top - balloonRect.height - heightOffset;
979
+ }
980
+ /**
981
+ * Returns the top coordinate for positions starting with `south*`.
982
+ *
983
+ * @param targetRect A rect of the target.
984
+ */
985
+ function getSouthTop(targetRect) {
986
+ return targetRect.bottom + heightOffset;
987
+ }
988
+ }