@@ -13,28 +13,6 @@ import BalloonPanelView from '@ckeditor/ckeditor5-ui/src/panel/balloon/balloonpa
1313import ToolbarView from '@ckeditor/ckeditor5-ui/src/toolbar/toolbarview' ;
1414import Template from '@ckeditor/ckeditor5-ui/src/template' ;
1515
16- // A set of positioning functions used by the
17- // {@link module:editor-inline/inlineeditoruiview~InlineEditableUIView#panel }.
18- //
19- // @private
20- // @type {module:utils/dom/position~Options#positions }
21- const panelPositions = [
22- ( editableRect , panelRect ) => {
23- return {
24- top : getPanelPositionTop ( editableRect , panelRect ) ,
25- left : editableRect . left ,
26- name : 'toolbar_west'
27- } ;
28- } ,
29- ( editableRect , panelRect ) => {
30- return {
31- top : getPanelPositionTop ( editableRect , panelRect ) ,
32- left : editableRect . left + editableRect . width - panelRect . width ,
33- name : 'toolbar_east'
34- } ;
35- }
36- ] ;
37-
3816/**
3917 * Inline editor UI view. Uses inline editable and floating toolbar.
4018 *
@@ -57,6 +35,21 @@ export default class InlineEditorUIView extends EditorUIView {
5735 */
5836 this . toolbar = new ToolbarView ( locale ) ;
5937
38+ /**
39+ * The offset from the top edge of the web browser's viewport which makes the
40+ * UI become sticky. The default value is `0`, which means the UI becomes
41+ * sticky when it's upper edge touches the top of the page viewport.
42+ *
43+ * This attribute is useful when the web page has UI elements positioned to the top
44+ * either using `position: fixed` or `position: sticky`, which would cover the
45+ * UI or vice–versa (depending on the `z-index` hierarchy).
46+ *
47+ * @readonly
48+ * @observable
49+ * @member {Number} #viewportTopOffset
50+ */
51+ this . set ( 'viewportTopOffset' , 0 ) ;
52+
6053 Template . extend ( this . toolbar . template , {
6154 attributes : {
6255 class : [
@@ -78,6 +71,53 @@ export default class InlineEditorUIView extends EditorUIView {
7871
7972 this . panel . withArrow = false ;
8073
74+ /**
75+ * A set of positioning functions used by the {@link #panel} to float around
76+ * {@link #editableElement}.
77+ *
78+ * The positioning functions are as follows:
79+ *
80+ * * West:
81+ *
82+ * [ Panel ]
83+ * +------------------+
84+ * | #editableElement |
85+ * +------------------+
86+ *
87+ * +------------------+
88+ * | #editableElement |
89+ * |[ Panel ] |
90+ * | |
91+ * +------------------+
92+ *
93+ * +------------------+
94+ * | #editableElement |
95+ * +------------------+
96+ * [ Panel ]
97+ *
98+ * * East:
99+ *
100+ * [ Panel ]
101+ * +------------------+
102+ * | #editableElement |
103+ * +------------------+
104+ *
105+ * +------------------+
106+ * | #editableElement |
107+ * | [ Panel ]|
108+ * | |
109+ * +------------------+
110+ *
111+ * +------------------+
112+ * | #editableElement |
113+ * +------------------+
114+ * [ Panel ]
115+ *
116+ * @readonly
117+ * @type {module:utils/dom/position~Options#positions }
118+ */
119+ this . panelPositions = this . _getPanelPositions ( ) ;
120+
81121 Template . extend ( this . panel . template , {
82122 attributes : {
83123 class : 'ck-toolbar-container'
@@ -113,73 +153,50 @@ export default class InlineEditorUIView extends EditorUIView {
113153 }
114154
115155 /**
116- * A set of positioning functions used by the {@link #panel} to float around
117- * {@link #editableElement}.
118- *
119- * The positioning functions are as follows:
120- *
121- * * West:
122- *
123- * [ Panel ]
124- * +------------------+
125- * | #editableElement |
126- * +------------------+
127- *
128- * +------------------+
129- * | #editableElement |
130- * |[ Panel ] |
131- * | |
132- * +------------------+
133- *
134- * +------------------+
135- * | #editableElement |
136- * +------------------+
137- * [ Panel ]
138- *
139- * * East:
156+ * Determines panel top position of the {@link #panel} in {@link #panelPositions}.
140157 *
141- * [ Panel ]
142- * +------------------+
143- * | #editableElement |
144- * +------------------+
145- *
146- * +------------------+
147- * | #editableElement |
148- * | [ Panel ]|
149- * | |
150- * +------------------+
151- *
152- * +------------------+
153- * | #editableElement |
154- * +------------------+
155- * [ Panel ]
156- *
157- * @readonly
158- * @type {module:utils/dom/position~Options#positions }
158+ * @private
159+ * @param {module:utils/dom/rect~Rect } editableRect Rect of the
160+ * {@link module:editor-inline/inlineeditoruiview~InlineEditableUIView#editableElement}.
161+ * @param {module:utils/dom/rect~Rect } panelRect Rect of the
162+ * {@link module:editor-inline/inlineeditoruiview~InlineEditableUIView#panel}.
159163 */
160- get panelPositions ( ) {
161- return panelPositions ;
164+ _getPanelPositionTop ( editableRect , panelRect ) {
165+ let top ;
166+
167+ if ( editableRect . top > panelRect . height + this . viewportTopOffset ) {
168+ top = editableRect . top - panelRect . height ;
169+ } else if ( editableRect . bottom > panelRect . height + this . viewportTopOffset + 50 ) {
170+ top = this . viewportTopOffset ;
171+ } else {
172+ top = editableRect . bottom ;
173+ }
174+
175+ return top ;
162176 }
163- }
164177
165- // Determines panel top position for
166- // {@link module:editor-inline/inlineeditoruiview~InlineEditableUIView#panelPositions }
167- //
168- // @private
169- // @param {module:utils/dom/rect~Rect } editableRect Rect of the
170- // {@link module:editor-inline/inlineeditoruiview~InlineEditableUIView#editableElement }.
171- // @param {module:utils/dom/rect~Rect } panelRect Rect of the
172- // {@link module:editor-inline/inlineeditoruiview~InlineEditableUIView#panel }.
173- function getPanelPositionTop ( editableRect , panelRect ) {
174- let top ;
175-
176- if ( editableRect . top > panelRect . height ) {
177- top = editableRect . top - panelRect . height ;
178- } else if ( editableRect . bottom > panelRect . height + 50 ) {
179- top = 0 ;
180- } else {
181- top = editableRect . bottom ;
178+ /**
179+ * Returns the positions for {@link #panelPositions}.
180+ *
181+ * @private
182+ * @returns module:utils/dom/position~Options#positions
183+ */
184+ _getPanelPositions ( ) {
185+ return [
186+ ( editableRect , panelRect ) => {
187+ return {
188+ top : this . _getPanelPositionTop ( editableRect , panelRect ) ,
189+ left : editableRect . left ,
190+ name : 'toolbar_west'
191+ } ;
192+ } ,
193+ ( editableRect , panelRect ) => {
194+ return {
195+ top : this . _getPanelPositionTop ( editableRect , panelRect ) ,
196+ left : editableRect . left + editableRect . width - panelRect . width ,
197+ name : 'toolbar_east'
198+ } ;
199+ }
200+ ] ;
182201 }
183-
184- return top ;
185202}
0 commit comments