Skip to content

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

Merged
merged 1 commit into from
Dec 7, 2018

Conversation

crisbeto
Copy link
Member

@crisbeto crisbeto commented Dec 2, 2018

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.

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 and DropListRef and to make them a bit more usable.

@crisbeto crisbeto added the target: patch This PR is targeted for the next patch release label Dec 2, 2018
@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Dec 2, 2018
@ngbot
Copy link

ngbot bot commented Dec 3, 2018

Hi @crisbeto! This PR has merge conflicts due to recent upstream merges.
Please help to unblock it by resolving these conflicts. Thanks!

Copy link
Member

@jelbourn jelbourn left a 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?

* @deprecated Use `DragRefConfig` instead.
* @breaking-change 8.0.0
*/
export interface CdkDragConfig extends DragRefConfig {}
Copy link
Member

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?

'class': 'cdk-drag',
'[class.cdk-drag-dragging]': '_dragRef.isDragging()',
},
providers: [{
Copy link
Member

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,
Copy link
Member

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.

Copy link
Member Author

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,
Copy link
Member

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

Copy link
Member Author

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
Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

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



/**
Copy link
Member

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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pointerDeta -> pointerDelta

/** Draggable items in the container. */
@ContentChildren(forwardRef(() => CdkDrag)) _draggables: QueryList<CdkDrag>;
// tslint:disable:class-name
// TODO: exclude from public-api.ts
Copy link
Member

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 {
Copy link
Member

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?

Copy link
Member Author

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.



// tslint:disable:class-name
// TODO: exclude from public-api.ts
Copy link
Member

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

Copy link
Member Author

@crisbeto crisbeto left a 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,
Copy link
Member Author

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,
Copy link
Member Author

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
Copy link
Member Author

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 {
Copy link
Member Author

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.

@crisbeto
Copy link
Member Author

crisbeto commented Dec 5, 2018

All of the feedback has been addressed.

Copy link
Member

@jelbourn jelbourn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jelbourn jelbourn added pr: lgtm action: merge The PR is ready for merge by the caretaker labels Dec 5, 2018
@ngbot
Copy link

ngbot bot commented Dec 5, 2018

I see that you just added the pr: merge ready label, but the following checks are still failing:
    failure conflicts with base branch "master"
    failure status "ci/circleci: bazel_build_test" is failing

If you want your PR to be merged, it has to pass all the CI checks.

If you can't get the PR to a green state due to flakes or broken master, please try rebasing to master and/or restarting the CI job. If that fails and you believe that the issue is not due to your change, please contact the caretaker and ask for help.

@crisbeto crisbeto force-pushed the drag-drop-refactor branch 2 times, most recently from 15db9c6 to 42ca449 Compare December 5, 2018 20:33
@mmalerba mmalerba added the P2 The issue is important to a large percentage of users, with a workaround label Dec 5, 2018
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.
@mmalerba mmalerba merged commit 19f9bca into angular:master Dec 7, 2018
mmalerba added a commit that referenced this pull request Dec 11, 2018
mmalerba added a commit that referenced this pull request Dec 11, 2018
mmalerba added a commit that referenced this pull request Dec 11, 2018
…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.
mmalerba added a commit that referenced this pull request Dec 11, 2018
mmalerba added a commit that referenced this pull request Dec 11, 2018
)

* 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.
mmalerba added a commit that referenced this pull request Dec 11, 2018
…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.
mmalerba added a commit that referenced this pull request Dec 11, 2018
…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.
mmalerba added a commit that referenced this pull request Dec 11, 2018
)

* 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.
mmalerba added a commit that referenced this pull request Dec 11, 2018
…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.
josephperrott pushed a commit to josephperrott/components that referenced this pull request Jan 14, 2019
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.
josephperrott pushed a commit to josephperrott/components that referenced this pull request Jan 14, 2019
…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.
josephperrott pushed a commit to josephperrott/components that referenced this pull request Jan 14, 2019
…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.
josephperrott pushed a commit to josephperrott/components that referenced this pull request Jan 14, 2019
…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.
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 10, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes PR author has agreed to Google's Contributor License Agreement P2 The issue is important to a large percentage of users, with a workaround target: patch This PR is targeted for the next patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants