Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Viewport offset aware and sticky positions #10373

Merged
merged 94 commits into from
Sep 12, 2021
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
94 commits
Select commit Hold shift + click to select a range
a2c88fd
WIP: recreating #10239 from scratch
dawidurbanski Aug 10, 2021
a1ae561
WIP: new viewportStickyPosition
dawidurbanski Aug 18, 2021
9159a5b
Exclude sticky position from manual balloonpanelview test
dawidurbanski Aug 18, 2021
72e884a
Implement withArrow into Position
dawidurbanski Aug 19, 2021
0a3633a
Improve comments
dawidurbanski Aug 19, 2021
1bfa5da
Add withArrow position flag to mention package
dawidurbanski Aug 19, 2021
8d32202
Tiny improvements. Better styles in manual test
dawidurbanski Aug 19, 2021
fb3a97d
Better describe manual test for sticky balloon position
dawidurbanski Aug 19, 2021
c880054
Replace very long image with license safe one
dawidurbanski Aug 19, 2021
10d31ef
Fix typo
dawidurbanski Aug 19, 2021
4ba84a1
Docs update
dawidurbanski Aug 23, 2021
4620161
Remove script from package.json
dawidurbanski Aug 23, 2021
018a3e7
Merge branch 'master' into ck/9892-viewport-top-offset-balloons-v3
oleq Aug 24, 2021
c998a90
Make withArrow default to true
dawidurbanski Aug 27, 2021
dc25a08
Make withArrow true by default v2
dawidurbanski Aug 27, 2021
3c042b1
Update tests to use new position config
dawidurbanski Aug 27, 2021
da147a7
Use BalloonPanelView withArrow propety as default instead of default …
dawidurbanski Aug 27, 2021
621a2ba
Merge branch 'master' into ck/9892-viewport-top-offset-balloons-v3
oleq Aug 30, 2021
c0c7e57
Docs refactoring. Created the abstract positioningFunction to streaml…
oleq Aug 30, 2021
c5edb07
Docs: Used @callback instead of @function in positioning function docs.
oleq Aug 31, 2021
819ea44
Remove getBestConstrainedPosition in favour of unified getBestPosition
dawidurbanski Sep 1, 2021
c0db227
Merge pull request #10461 from ckeditor/ck/9892-viewport-top-offset-b…
dawidurbanski Sep 1, 2021
7beacec
Make withArrow default to true in ballonpanelview
dawidurbanski Sep 1, 2021
496392f
Remove unnecesary config option in mentions
dawidurbanski Sep 1, 2021
e88f02c
Update stickyVerticalOffset ASCII art to include viewport
dawidurbanski Sep 1, 2021
2066a09
More descriptive test name
dawidurbanski Sep 1, 2021
94c76b6
Add another test to check for target being fully outside the viewport
dawidurbanski Sep 1, 2021
84038ac
Add redundant tests for position utils
dawidurbanski Sep 1, 2021
6ed1cb7
Fixed arrow keys navigation when there is an inline widget at the end…
niegowski Aug 20, 2021
d4e7230
Fixed handling of non collapsed selection inside a table cell. Fixed …
niegowski Aug 20, 2021
d0d041f
Fixed collapsing selection that contains a widget at the start or end…
niegowski Aug 24, 2021
800edf5
Code cleanup.
niegowski Aug 25, 2021
c0200d6
Added custom ESLint rules in docs.
przemyslaw-zan Aug 19, 2021
0011d1f
Improved the code style guide.
pomek Aug 20, 2021
a9bf94e
Added a custom formatter for ESLint.
pomek Aug 20, 2021
0375db7
Check all packages (revert a part of the previous commit change).
pomek Aug 20, 2021
68ee5fd
Docs: language review.
godai78 Aug 20, 2021
300e3c9
Docs: a typo.
godai78 Aug 20, 2021
51fdbf4
Docs: update indicator.
godai78 Aug 24, 2021
a83da8a
Internal (build-*): Builds.
pomek Aug 25, 2021
4790c6e
Docs: migration guide comment.
godai78 Aug 30, 2021
9466490
Docs: Changelog. [skip ci]
pomek Aug 30, 2021
10bafaf
Internal (utils): Updated version of CKEditor 5.
pomek Aug 30, 2021
a4f0fbc
Docs: Corrected the changelog. [skip ci]
pomek Aug 30, 2021
2c8dda3
Docs: changelog review.
godai78 Aug 30, 2021
7cc4c06
Internal: Updated dependencies. [skip ci]
pomek Aug 31, 2021
8b0dd4f
Release: v29.2.0.
pomek Aug 31, 2021
9bc871e
Docs: Removed an invalid asterisk.
pomek Aug 31, 2021
7a70568
Docs: landing page fixes.
godai78 Aug 30, 2021
98cf88e
Update docs/features/index.md
godai78 Aug 31, 2021
1fc086a
Docs: Update packages/ckeditor5-table/src/tablekeyboard.js
oleq Aug 31, 2021
a3a86ed
Internal (table): Fixed whitespaces.
niegowski Aug 31, 2021
2fc6ab3
Move model.change() outside the loop
arkflpc Aug 31, 2021
2985e7d
Docs: Added the missing closing "</script>" tag in the DLL guide.
pomek Aug 31, 2021
ebbd669
Docs: DLL update indicator.
godai78 Sep 1, 2021
436d00f
Docs: v29.2 post-release review.
godai78 Sep 1, 2021
401163c
Script for removing node_modules directories is npm dependency free.
pomek Sep 3, 2021
a570db6
Externals of externals should be removed too.
pomek Sep 3, 2021
99fefb6
Remove node_modules within frontend and vendor/ckeditor5 directories …
pomek Sep 3, 2021
8a9bef0
Use npm/rimraf for removing nested node_modules.
pomek Sep 3, 2021
c1964b2
Docs: Code style - DLLs imports must use the full package name.
pomek Sep 3, 2021
c4175c5
Docs: typo.
godai78 Sep 6, 2021
af10026
Internal: Imports between DLLs packages must use full names. See #10375.
pomek Sep 6, 2021
0b3dd53
Remove trim in list converter
arkflpc Aug 27, 2021
e1e9ff3
Remove trim in list converter - UT
arkflpc Aug 27, 2021
c3b248a
Remove trim in list converter - UT
arkflpc Aug 31, 2021
18f68f5
Docs: Added the missing closing "</script>" tag in the DLL guide.
pomek Aug 31, 2021
4493ffb
jsdoc: Utils>Collection initialItemsOrOptions is optional
fedemp Sep 3, 2021
a153daf
jsdoc: CKEditorError: logWarning and logError return nothing
fedemp Aug 28, 2021
b850272
Change viewportTopOffset config. Make viewportTopOffset writable in r…
dawidurbanski Aug 12, 2021
307c39d
Update tests to use the new viewport offset config
dawidurbanski Aug 13, 2021
4d93b78
Make manual test to use the new top offset config
dawidurbanski Aug 13, 2021
843e972
Moved the observable #viewportOffset property to EditorUI.
oleq Aug 13, 2021
0d79691
Update TODO items. Polishing. Updating tests
dawidurbanski Aug 15, 2021
c4c1f77
Add tests for _viewportOffset() method
dawidurbanski Aug 15, 2021
7a934ed
Fix typo
dawidurbanski Aug 15, 2021
764a8b8
Update all docs snippets to use new ui.viewportOffset.top config prop…
dawidurbanski Aug 16, 2021
55b855e
Add docs to the new config.ui property
dawidurbanski Aug 16, 2021
9a87e19
Remove deprecated viewportTopOffset property from toolbar feature docs
dawidurbanski Aug 23, 2021
f4f2220
Revert imports in editorui.js
dawidurbanski Aug 23, 2021
76f8420
Update docs to cross-reference viewportOffset config to viewportTopOf…
dawidurbanski Aug 23, 2021
8ee8f63
Rename _viewportOffset() to _readViewportOffsetFromConfig(). Update t…
dawidurbanski Aug 23, 2021
10b785d
Update console spy to check calledWithMatch instead of calledOnce
dawidurbanski Aug 23, 2021
8d2cc41
Update ui.viewportOffset config property docs
dawidurbanski Aug 23, 2021
fae7e66
Better EditorUI viewportOffset example docs
dawidurbanski Aug 23, 2021
98a2368
Update manual tests to add case for changing vieport offset without f…
dawidurbanski Aug 23, 2021
655589f
Update low level UiView api docs
dawidurbanski Aug 23, 2021
6df4e2a
Extract test to check if warning is raised on legacy viewportTopOffse…
dawidurbanski Aug 23, 2021
7696b02
Docs: git commit message convention update.
godai78 Sep 7, 2021
cd508f3
Updated docs feature categories.
FilipTokarski Jul 5, 2021
83b396c
Docs: additional merge message info.
godai78 Sep 7, 2021
dd5a683
Internal: Fixed broken docs demo after merging #10352.
dawidurbanski Sep 7, 2021
ec3bc00
Merge branch 'master' into ck/9892-viewport-top-offset-balloons-v3
dawidurbanski Sep 8, 2021
aef7fbe
Merge branch 'master' into ck/9892-viewport-top-offset-balloons-v3
Reinmar Sep 12, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/ckeditor5-image/src/image/ui/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ export function getBalloonPositionData( editor ) {
defaultPositions.northArrowSouthEast,
defaultPositions.southArrowNorth,
defaultPositions.southArrowNorthWest,
defaultPositions.southArrowNorthEast
defaultPositions.southArrowNorthEast,
defaultPositions.viewportStickyNorth
]
};
}
3 changes: 2 additions & 1 deletion packages/ckeditor5-image/tests/image/ui/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ describe( 'Utils', () => {
defaultPositions.northArrowSouthEast,
defaultPositions.southArrowNorth,
defaultPositions.southArrowNorthWest,
defaultPositions.southArrowNorthEast
defaultPositions.southArrowNorthEast,
defaultPositions.viewportStickyNorth
];

let editor, converter, selection, balloon, editorElement;
Expand Down
24 changes: 19 additions & 5 deletions packages/ckeditor5-mention/src/mentionui.js
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,9 @@ export default class MentionUI extends Plugin {
this._balloon.add( {
view: this._mentionsView,
position: this._getBalloonPanelPositionData( markerMarker, this._mentionsView.position ),
withArrow: false,
config: {
withArrow: false
},
dawidurbanski marked this conversation as resolved.
Show resolved Hide resolved
singleViewMode: true
} );
}
Expand Down Expand Up @@ -586,7 +588,10 @@ function getBalloonPanelPositions( preferredPosition ) {
return {
top: targetRect.bottom + VERTICAL_SPACING,
left: targetRect.right,
name: 'caret_se'
name: 'caret_se',
config: {
withArrow: false
}
};
},

Expand All @@ -595,7 +600,10 @@ function getBalloonPanelPositions( preferredPosition ) {
return {
top: targetRect.top - balloonRect.height - VERTICAL_SPACING,
left: targetRect.right,
name: 'caret_ne'
name: 'caret_ne',
config: {
withArrow: false
}
};
},

Expand All @@ -604,7 +612,10 @@ function getBalloonPanelPositions( preferredPosition ) {
return {
top: targetRect.bottom + VERTICAL_SPACING,
left: targetRect.right - balloonRect.width,
name: 'caret_sw'
name: 'caret_sw',
config: {
withArrow: false
}
};
},

Expand All @@ -613,7 +624,10 @@ function getBalloonPanelPositions( preferredPosition ) {
return {
top: targetRect.top - balloonRect.height - VERTICAL_SPACING,
left: targetRect.right - balloonRect.width,
name: 'caret_nw'
name: 'caret_nw',
config: {
withArrow: false
}
};
}
};
Expand Down
20 changes: 16 additions & 4 deletions packages/ckeditor5-mention/tests/mentionui.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,25 +196,37 @@ describe( 'MentionUI', () => {
expect( caretSouthEast( caretRect, balloonRect ) ).to.deep.equal( {
left: 501,
name: 'caret_se',
top: 121
top: 121,
config: {
withArrow: false
}
} );

expect( caretSouthWest( caretRect, balloonRect ) ).to.deep.equal( {
left: 301,
name: 'caret_sw',
top: 121
top: 121,
config: {
withArrow: false
}
} );

expect( caretNorthEast( caretRect, balloonRect ) ).to.deep.equal( {
left: 501,
name: 'caret_ne',
top: -53
top: -53,
config: {
withArrow: false
}
} );

expect( caretNorthWest( caretRect, balloonRect ) ).to.deep.equal( {
left: 301,
name: 'caret_nw',
top: -53
top: -53,
config: {
withArrow: false
}
} );
} );
} );
Expand Down
11 changes: 3 additions & 8 deletions packages/ckeditor5-table/src/utils/ui/contextualballoon.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
* @module table/utils/ui/contextualballoon
*/

import { centeredBalloonPositionForLongWidgets } from 'ckeditor5/src/widget';
import { Rect } from 'ckeditor5/src/utils';
import { BalloonPanelView } from 'ckeditor5/src/ui';

Expand All @@ -21,12 +20,8 @@ const BALLOON_POSITIONS = [
DEFAULT_BALLOON_POSITIONS.northArrowSouthEast,
DEFAULT_BALLOON_POSITIONS.southArrowNorth,
DEFAULT_BALLOON_POSITIONS.southArrowNorthWest,
DEFAULT_BALLOON_POSITIONS.southArrowNorthEast
];

const TABLE_PROPERTIES_BALLOON_POSITIONS = [
...BALLOON_POSITIONS,
centeredBalloonPositionForLongWidgets
DEFAULT_BALLOON_POSITIONS.southArrowNorthEast,
DEFAULT_BALLOON_POSITIONS.viewportStickyNorth
];

/**
Expand Down Expand Up @@ -69,7 +64,7 @@ export function getBalloonTablePositionData( editor ) {

return {
target: editor.editing.view.domConverter.viewToDom( viewTable ),
positions: TABLE_PROPERTIES_BALLOON_POSITIONS
positions: BALLOON_POSITIONS
};
}

Expand Down
9 changes: 5 additions & 4 deletions packages/ckeditor5-table/tests/utils/ui/contextualballoon.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import BalloonPanelView from '@ckeditor/ckeditor5-ui/src/panel/balloon/balloonpa

import { setData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
import { centeredBalloonPositionForLongWidgets } from '@ckeditor/ckeditor5-widget/src/utils';
import { modelTable } from '../../_utils/utils';
import { getTableCellsContainingSelection } from '../../../src/utils/selection';
import { getBalloonCellPositionData, repositionContextualBalloon } from '../../../src/utils/ui/contextualballoon';
Expand Down Expand Up @@ -79,7 +78,8 @@ describe( 'table utils', () => {
defaultPositions.northArrowSouthEast,
defaultPositions.southArrowNorth,
defaultPositions.southArrowNorthWest,
defaultPositions.southArrowNorthEast
defaultPositions.southArrowNorthEast,
defaultPositions.viewportStickyNorth
]
} );
} );
Expand Down Expand Up @@ -128,7 +128,7 @@ describe( 'table utils', () => {
defaultPositions.southArrowNorth,
defaultPositions.southArrowNorthWest,
defaultPositions.southArrowNorthEast,
centeredBalloonPositionForLongWidgets
defaultPositions.viewportStickyNorth
]
} );
} );
Expand Down Expand Up @@ -186,7 +186,8 @@ describe( 'table utils', () => {
defaultPositions.northArrowSouthEast,
defaultPositions.southArrowNorth,
defaultPositions.southArrowNorthWest,
defaultPositions.southArrowNorthEast
defaultPositions.southArrowNorthEast,
defaultPositions.viewportStickyNorth
]
} );
} );
Expand Down
64 changes: 58 additions & 6 deletions packages/ckeditor5-ui/src/panel/balloon/balloonpanelview.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,8 @@ export default class BalloonPanelView extends View {
defaultPositions.northArrowSouthMiddleWest,
defaultPositions.northArrowSouthMiddleEast,
defaultPositions.northArrowSouthWest,
defaultPositions.northArrowSouthEast
defaultPositions.northArrowSouthEast,
defaultPositions.viewportStickyNorth
],
limiter: defaultLimiterElement,
fitInViewport: true
Expand All @@ -244,9 +245,11 @@ export default class BalloonPanelView extends View {
// so it is better to use int values.
const left = parseInt( optimalPosition.left );
const top = parseInt( optimalPosition.top );
const position = optimalPosition.name;

Object.assign( this, { top, left, position } );
const { name: position, config = {} } = optimalPosition;
const { withArrow } = config;
dawidurbanski marked this conversation as resolved.
Show resolved Hide resolved

Object.assign( this, { top, left, position, withArrow } );
}

/**
Expand Down Expand Up @@ -401,7 +404,7 @@ function getDomElement( object ) {
* \|/
* >|-----|<---------------- horizontal offset
*
* @default 30
* @default 25
dawidurbanski marked this conversation as resolved.
Show resolved Hide resolved
* @member {Number} module:ui/panel/balloon/balloonpanelview~BalloonPanelView.arrowHorizontalOffset
*/
BalloonPanelView.arrowHorizontalOffset = 25;
Expand All @@ -420,11 +423,26 @@ BalloonPanelView.arrowHorizontalOffset = 25;
* -------------------------------
* ^
*
* @default 15
* @default 10
dawidurbanski marked this conversation as resolved.
Show resolved Hide resolved
* @member {Number} module:ui/panel/balloon/balloonpanelview~BalloonPanelView.arrowVerticalOffset
*/
BalloonPanelView.arrowVerticalOffset = 10;

/**
* A vertical offset of the balloon panel from the edge of the viewport if sticky.
* It helps in accessing toolbar buttons underneath the balloon panel.
*
* Toolbar /-- vertical offset
* +-----------------------------V--------------------+
* | +-------------+ |
* +------------------| Balloon |-----------------+
* +-------------+
dawidurbanski marked this conversation as resolved.
Show resolved Hide resolved
*
* @default 20
* @member {Number} module:ui/panel/balloon/balloonpanelview~BalloonPanelView.stickyVerticalOffset
*/
BalloonPanelView.stickyVerticalOffset = 20;

/**
* Function used to calculate the optimal position for the balloon.
*
Expand Down Expand Up @@ -702,6 +720,22 @@ BalloonPanelView._getOptimalPosition = getOptimalPosition;
* | Balloon |
* +-----------------+
*
* * `viewportStickyNorth`
*
* +---------------------------+
* | [ Target ] |
* | |
* +-----------------------------------+
* | | +-----------------+ | |
* | | | Balloon | | |
* | | +-----------------+ | |
* | | | |
* | | | |
* | | | |
* | | | |
* | +---------------------------+ |
* | Viewport |
* +-----------------------------------+
*
* See {@link module:ui/panel/balloon/balloonpanelview~BalloonPanelView#attachTo}.
*
Expand Down Expand Up @@ -791,6 +825,7 @@ BalloonPanelView.defaultPositions = {
left: targetRect.right - ( balloonRect.width * .25 ) - BalloonPanelView.arrowHorizontalOffset,
name: 'arrow_smw'
} ),

northEastArrowSouth: ( targetRect, balloonRect ) => ( {
top: getNorthTop( targetRect, balloonRect ),
left: targetRect.right - balloonRect.width / 2,
Expand All @@ -808,6 +843,7 @@ BalloonPanelView.defaultPositions = {
left: targetRect.right - balloonRect.width + BalloonPanelView.arrowHorizontalOffset,
name: 'arrow_se'
} ),

// ------- South west

southWestArrowNorthWest: ( targetRect, balloonRect ) => ( {
Expand Down Expand Up @@ -901,8 +937,24 @@ BalloonPanelView.defaultPositions = {
top: getSouthTop( targetRect, balloonRect ),
left: targetRect.right - balloonRect.width + BalloonPanelView.arrowHorizontalOffset,
name: 'arrow_ne'
} )
} ),

// ------- Sticky

viewportStickyNorth: ( targetRect, balloonRect, viewportRect ) => {
if ( !targetRect.getIntersection( viewportRect ) ) {
return null;
}

return {
top: viewportRect.top + BalloonPanelView.stickyVerticalOffset,
left: targetRect.left + targetRect.width / 2 - balloonRect.width / 2,
name: 'arrowless',
config: {
withArrow: false
}
};
}
};

// Returns the top coordinate for positions starting with `north*`.
Expand Down
13 changes: 10 additions & 3 deletions packages/ckeditor5-ui/src/panel/balloon/contextualballoon.js
Original file line number Diff line number Diff line change
Expand Up @@ -498,11 +498,18 @@ export default class ContextualBalloon extends Plugin {
_getBalloonPosition() {
let position = Array.from( this._visibleStack.values() ).pop().position;

// Use the default limiter if none has been specified.
if ( position && !position.limiter ) {
if ( position ) {
// Use the default limiter if none has been specified.
if ( !position.limiter ) {
// Don't modify the original options object.
position = Object.assign( {}, position, {
limiter: this.positionLimiter
} );
}

// Don't modify the original options object.
position = Object.assign( {}, position, {
limiter: this.positionLimiter
viewportOffsetConfig: this.editor.config.get( 'ui.viewportOffset' )
} );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ import BalloonPanelView from '../../../../src/panel/balloon/balloonpanelview';
const defaultPositions = BalloonPanelView.defaultPositions;
const container = document.querySelector( '#container' );

// It makes no sense to test the sticky position in this context,
// thus exclude it from this manual test.
delete defaultPositions.viewportStickyNorth;

let currentHeading = '';

for ( const i in defaultPositions ) {
Expand Down
Loading