-
Notifications
You must be signed in to change notification settings - Fork 6.8k
refactor(drag-drop): move logic out of directives #14350
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
Conversation
15c21f3
to
f2b6d66
Compare
Hi @crisbeto! This PR has merge conflicts due to recent upstream merges. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is anything getting formally deprecated in this PR?
src/cdk/drag-drop/directives/drag.ts
Outdated
* @deprecated Use `DragRefConfig` instead. | ||
* @breaking-change 8.0.0 | ||
*/ | ||
export interface CdkDragConfig extends DragRefConfig {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this need to live in this file? Could it instead live in public-api.ts
?
src/cdk/drag-drop/directives/drag.ts
Outdated
'class': 'cdk-drag', | ||
'[class.cdk-drag-dragging]': '_dragRef.isDragging()', | ||
}, | ||
providers: [{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Collapse this provider to one line?
public element: ElementRef<HTMLElement>, | ||
/** Droppable container that the draggable is a part of. */ | ||
@Inject(CDK_DROP_LIST) @Optional() @SkipSelf() | ||
public dropContainer: CdkDropList, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you change this directive to use DropListRef
internally and have CdkDropList
provide itself as DropListRef
? The only place it's referenced directly is to get disabled
, which also exists on DropListRef
. The dropContainer
would still have to be exposed publicly as deprecated, but it could eventually get rid of it.
Another change I'd like to make for CdkDrag would be to reference the idea of the more generic "drop container" rather than the specific "drop list", where the container is the lower-level thing that just knows about receiving drops and not about lists/reordering.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regarding providing the CdkDropList
as a DropListRef
, I'm not sure whether it would be very useful if somebody got it through DI. Also I wanted to reduce the amount of deprecations and doing this will involve having to add another parameter to the constructor.
As for the more generic drop container, I agree, but it was something I was planning to do once we started implementing more container types.
@Inject(CDK_DRAG_CONFIG) private _config: DragRefConfig, | ||
@Optional() private _dir: Directionality) { | ||
|
||
const ref = this._dragRef = new DragRef(element, this._document, this._ngZone, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a pretty complex constructor. Could we simplify it by having a factory service that constructs the refs for you? Something like a DragDrop
service with a method analogous to Overlay.create
. Maybe something like dragDrop.createDraggable(...): DragRef
and dropDrop.createDropContainer(...): DropContainerRef
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, my plan was to add a service for it in a follow-up. The point of this PR was to get the more difficult part of the refactor out of the way so that we can focus on the public API for it afterwards.
let _uniqueIdCounter = 0; | ||
|
||
// tslint:disable:class-name | ||
// TODO: exclude from public-api.ts |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is something we'd have to do before the commit lands.
Since it won't be exported at all, we could use a name like CdkDropListInternal
. It would also be good to have some tooling that could enforce that certain symbols are not exported through the public api.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this the purpose of the @internal
tag? I know that we removed them to avoid downstream issues, but the symbols should be preserved if we didn't enable stripInternal
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I have no strong feelings about which tag we use
|
||
|
||
/** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add a comment above here that explains the background on why this is being removed?
* @param item Item to be sorted. | ||
* @param pointerX Position of the item along the X axis. | ||
* @param pointerY Position of the item along the Y axis. | ||
* @param pointerDeta Direction in which the pointer is moving along each axis. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pointerDeta
-> pointerDelta
src/cdk/drag-drop/drop-list-ref.ts
Outdated
/** Draggable items in the container. */ | ||
@ContentChildren(forwardRef(() => CdkDrag)) _draggables: QueryList<CdkDrag>; | ||
// tslint:disable:class-name | ||
// TODO: exclude from public-api.ts |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same this here as in drop-list.ts
* @param x Pointer position along the X axis. | ||
* @param y Pointer position along the Y axis. | ||
*/ | ||
_isOverContainer(x: number, y: number): boolean { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this function be eliminated?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It can be, I left it in to keep the CdkDropList
compatible with the CdkDropListContainer
interfaces.
src/cdk/drag-drop/drag-ref.ts
Outdated
|
||
|
||
// tslint:disable:class-name | ||
// TODO: exclude from public-api.ts |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here as other places
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jelbourn the only things being formally deprecated are the ones that we were using to avoid circular imports, however they weren't public to begin with.
public element: ElementRef<HTMLElement>, | ||
/** Droppable container that the draggable is a part of. */ | ||
@Inject(CDK_DROP_LIST) @Optional() @SkipSelf() | ||
public dropContainer: CdkDropList, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regarding providing the CdkDropList
as a DropListRef
, I'm not sure whether it would be very useful if somebody got it through DI. Also I wanted to reduce the amount of deprecations and doing this will involve having to add another parameter to the constructor.
As for the more generic drop container, I agree, but it was something I was planning to do once we started implementing more container types.
@Inject(CDK_DRAG_CONFIG) private _config: DragRefConfig, | ||
@Optional() private _dir: Directionality) { | ||
|
||
const ref = this._dragRef = new DragRef(element, this._document, this._ngZone, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, my plan was to add a service for it in a follow-up. The point of this PR was to get the more difficult part of the refactor out of the way so that we can focus on the public API for it afterwards.
let _uniqueIdCounter = 0; | ||
|
||
// tslint:disable:class-name | ||
// TODO: exclude from public-api.ts |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this the purpose of the @internal
tag? I know that we removed them to avoid downstream issues, but the symbols should be preserved if we didn't enable stripInternal
.
* @param x Pointer position along the X axis. | ||
* @param y Pointer position along the Y axis. | ||
*/ | ||
_isOverContainer(x: number, y: number): boolean { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It can be, I left it in to keep the CdkDropList
compatible with the CdkDropListContainer
interfaces.
f2b6d66
to
219beb1
Compare
All of the feedback has been addressed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
15db9c6
to
42ca449
Compare
Moves the logic for `CdkDrag` and `CdkDropList` into separate, non-Angular-specific classes. This is a first step towards allowing consumers to attach drag&drop functionality to arbitrary DOM nodes.
42ca449
to
58e8142
Compare
…from ListKeyManager" (#14467) * Revert "build: update sauce connect (#14422)" This reverts commit bc563b7. * Revert "build: changelog script not filtering duplicate entries (#14421)" This reverts commit fe46290. * Revert "build: update to angular 7.1.2 (#14418)" This reverts commit e1487df. * Revert "refactor(drag-drop): move logic out of directives (#14350)" This reverts commit 19f9bca. * Revert "fix(checkbox): redirect focus to underlying input element (#13959)" This reverts commit e0eb3df. * Revert "fix(radio): host element unable to receive focus events (#13956)" This reverts commit 41eb27e. * Revert "fix(a11y): activeItem out of date if active index is removed from ListKeyManager (#14407)" This reverts commit 014dc79.
) * Revert "Revert "fix(a11y): activeItem out of date if active index is removed from ListKeyManager" (#14467)" This reverts commit 8f790f5. * Revert "build: update sauce connect (#14422)" This reverts commit bc563b7. * Revert "build: changelog script not filtering duplicate entries (#14421)" This reverts commit fe46290. * Revert "build: update to angular 7.1.2 (#14418)" This reverts commit e1487df. * Revert "refactor(drag-drop): move logic out of directives (#14350)" This reverts commit 19f9bca. * Revert "fix(checkbox): redirect focus to underlying input element (#13959)" This reverts commit e0eb3df. * Revert "fix(radio): host element unable to receive focus events (#13956)" This reverts commit 41eb27e.
…14469) * Revert "Revert "fix(radio): host element unable to receive focus events" (#14468)" This reverts commit 4aa47c7. * Revert "Revert "fix(a11y): activeItem out of date if active index is removed from ListKeyManager" (#14467)" This reverts commit 8f790f5. * Revert "build: update sauce connect (#14422)" This reverts commit bc563b7. * Revert "build: changelog script not filtering duplicate entries (#14421)" This reverts commit fe46290. * Revert "build: update to angular 7.1.2 (#14418)" This reverts commit e1487df. * Revert "refactor(drag-drop): move logic out of directives (#14350)" This reverts commit 19f9bca. * Revert "fix(checkbox): redirect focus to underlying input element (#13959)" This reverts commit e0eb3df.
…from ListKeyManager" (#14467) * Revert "build: update sauce connect (#14422)" This reverts commit bc563b7. * Revert "build: changelog script not filtering duplicate entries (#14421)" This reverts commit fe46290. * Revert "build: update to angular 7.1.2 (#14418)" This reverts commit e1487df. * Revert "refactor(drag-drop): move logic out of directives (#14350)" This reverts commit 19f9bca. * Revert "fix(checkbox): redirect focus to underlying input element (#13959)" This reverts commit e0eb3df. * Revert "fix(radio): host element unable to receive focus events (#13956)" This reverts commit 41eb27e. * Revert "fix(a11y): activeItem out of date if active index is removed from ListKeyManager (#14407)" This reverts commit 014dc79.
) * Revert "Revert "fix(a11y): activeItem out of date if active index is removed from ListKeyManager" (#14467)" This reverts commit 8f790f5. * Revert "build: update sauce connect (#14422)" This reverts commit bc563b7. * Revert "build: changelog script not filtering duplicate entries (#14421)" This reverts commit fe46290. * Revert "build: update to angular 7.1.2 (#14418)" This reverts commit e1487df. * Revert "refactor(drag-drop): move logic out of directives (#14350)" This reverts commit 19f9bca. * Revert "fix(checkbox): redirect focus to underlying input element (#13959)" This reverts commit e0eb3df. * Revert "fix(radio): host element unable to receive focus events (#13956)" This reverts commit 41eb27e.
…14469) * Revert "Revert "fix(radio): host element unable to receive focus events" (#14468)" This reverts commit 4aa47c7. * Revert "Revert "fix(a11y): activeItem out of date if active index is removed from ListKeyManager" (#14467)" This reverts commit 8f790f5. * Revert "build: update sauce connect (#14422)" This reverts commit bc563b7. * Revert "build: changelog script not filtering duplicate entries (#14421)" This reverts commit fe46290. * Revert "build: update to angular 7.1.2 (#14418)" This reverts commit e1487df. * Revert "refactor(drag-drop): move logic out of directives (#14350)" This reverts commit 19f9bca. * Revert "fix(checkbox): redirect focus to underlying input element (#13959)" This reverts commit e0eb3df.
Moves the logic for `CdkDrag` and `CdkDropList` into separate, non-Angular-specific classes. This is a first step towards allowing consumers to attach drag&drop functionality to arbitrary DOM nodes.
…from ListKeyManager" (angular#14467) * Revert "build: update sauce connect (angular#14422)" This reverts commit bc563b7. * Revert "build: changelog script not filtering duplicate entries (angular#14421)" This reverts commit fe46290. * Revert "build: update to angular 7.1.2 (angular#14418)" This reverts commit e1487df. * Revert "refactor(drag-drop): move logic out of directives (angular#14350)" This reverts commit 19f9bca. * Revert "fix(checkbox): redirect focus to underlying input element (angular#13959)" This reverts commit e0eb3df. * Revert "fix(radio): host element unable to receive focus events (angular#13956)" This reverts commit 41eb27e. * Revert "fix(a11y): activeItem out of date if active index is removed from ListKeyManager (angular#14407)" This reverts commit 014dc79.
…ular#14468) * Revert "Revert "fix(a11y): activeItem out of date if active index is removed from ListKeyManager" (angular#14467)" This reverts commit 8f790f5. * Revert "build: update sauce connect (angular#14422)" This reverts commit bc563b7. * Revert "build: changelog script not filtering duplicate entries (angular#14421)" This reverts commit fe46290. * Revert "build: update to angular 7.1.2 (angular#14418)" This reverts commit e1487df. * Revert "refactor(drag-drop): move logic out of directives (angular#14350)" This reverts commit 19f9bca. * Revert "fix(checkbox): redirect focus to underlying input element (angular#13959)" This reverts commit e0eb3df. * Revert "fix(radio): host element unable to receive focus events (angular#13956)" This reverts commit 41eb27e.
…ngular#14469) * Revert "Revert "fix(radio): host element unable to receive focus events" (angular#14468)" This reverts commit 4aa47c7. * Revert "Revert "fix(a11y): activeItem out of date if active index is removed from ListKeyManager" (angular#14467)" This reverts commit 8f790f5. * Revert "build: update sauce connect (angular#14422)" This reverts commit bc563b7. * Revert "build: changelog script not filtering duplicate entries (angular#14421)" This reverts commit fe46290. * Revert "build: update to angular 7.1.2 (angular#14418)" This reverts commit e1487df. * Revert "refactor(drag-drop): move logic out of directives (angular#14350)" This reverts commit 19f9bca. * Revert "fix(checkbox): redirect focus to underlying input element (angular#13959)" This reverts commit e0eb3df.
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Moves the logic for
CdkDrag
andCdkDropList
into separate, non-Angular-specific classes. This is a first step towards allowing consumers to attach drag&drop functionality to arbitrary DOM nodes.Note: the intent of this PR is to move all of the logic out of the directives and to retain backwards compatibility. As such, none of the new classes are exposed via the public API. The next step will be to add a nicer API around
DragRef
andDropListRef
and to make them a bit more usable.