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

feat(ui) : the block can be drag n drop #2285

Open
wants to merge 89 commits into
base: next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 65 commits
Commits
Show all changes
89 commits
Select commit Hold shift + click to select a range
f17b567
drag and drop nodes by handle
apresmoi Apr 11, 2022
3b07911
fix linting issues
apresmoi Apr 11, 2022
3d33b0c
fix lag in settingsToggler button after move
apresmoi Apr 11, 2022
85ce277
fix naming in css
apresmoi Apr 11, 2022
0c948ed
removing commented lines and moving return to if block
apresmoi Apr 11, 2022
686ab6d
fix drop indicator classes cleaning out
apresmoi Apr 12, 2022
dfecf05
fix: removing JSON pattern
apresmoi Apr 13, 2022
0857055
fix: handling dropping block without reference
apresmoi Apr 14, 2022
28b6dc7
requested changes
apresmoi Apr 27, 2022
2a7c1ad
fix linting issues
apresmoi Apr 27, 2022
3207ec5
fix: reorder of lines
apresmoi Apr 27, 2022
ecaeba2
fix: conflicts with next branch
apresmoi Apr 27, 2022
4d4718f
fix: restoring file to original state
apresmoi Apr 28, 2022
776cb21
feat: adding processBlockDrop function impl
apresmoi Apr 28, 2022
df88f0d
Merge branch 'next' into feature/handler-drag-and-drop-838
apresmoi Apr 29, 2022
8df628a
Merge remote-tracking branch 'origin/next' into feature/handler-drag-…
apresmoi May 24, 2022
cff8039
fix: rolling back css changes for drag&drop blocks feature
apresmoi May 24, 2022
30441e7
feat: adding custom image when dragging block
apresmoi May 24, 2022
9ba3363
fix: linting changes
apresmoi May 26, 2022
25517ed
feat: proposal for drag and drop selected range
apresmoi May 26, 2022
1cc6908
Merge branch 'next' into feature/handler-drag-and-drop-838
apresmoi Jun 21, 2022
be29a63
Merge branch 'next' into feature/handler-drag-and-drop-838
apresmoi Sep 15, 2022
706c5ef
fix: flickering when dragging on top of caret
apresmoi Sep 15, 2022
8835210
Merge branch 'next' into feat/dragndrop
robonetphy Jan 31, 2023
508f7dd
content highlighting added in block settinga
robonetphy Feb 13, 2023
b5181f2
unused class removed from the PR
robonetphy Feb 13, 2023
2fefd72
add the comments from the mutable listeners
robonetphy Feb 13, 2023
9b6b517
remove the repetitive code
robonetphy Feb 13, 2023
a47584b
comments added
robonetphy Feb 13, 2023
6c770ba
remove unused binding
robonetphy Feb 13, 2023
d29dfbd
remove repetitive code
robonetphy Feb 13, 2023
49fe61c
event before clear section added
robonetphy Feb 13, 2023
92fe458
drop target added
robonetphy Feb 13, 2023
f14394d
updates the events
robonetphy Feb 15, 2023
3bbc9c2
remove unsed events
robonetphy Feb 15, 2023
a5c4c11
remove unused events
robonetphy Feb 15, 2023
7d362cc
dragenter callback addedd
robonetphy Feb 15, 2023
f1cb715
comments added
robonetphy Feb 15, 2023
4c5a199
update the enum for drop zone position
robonetphy Feb 15, 2023
96deca8
comments added
robonetphy Feb 15, 2023
445eaf3
cleardropTargets function added
robonetphy Feb 16, 2023
722eb8e
unsed logic removed
robonetphy Feb 19, 2023
b7add56
dragImage creation and removal functionality added
robonetphy Feb 19, 2023
2368264
unused code removed
robonetphy Feb 19, 2023
aa3dcd2
drop logic updated
robonetphy Feb 20, 2023
2167b91
Caret added with drag and drop
robonetphy Feb 20, 2023
fa33f11
update the Inline tool close
robonetphy Feb 21, 2023
23b7fd6
add the isDragStart getter
robonetphy Feb 21, 2023
b560b26
Merge branch 'next' into feat/dragndrop
robonetphy Feb 21, 2023
0a4d53b
comments added
robonetphy Feb 21, 2023
2f43494
updated the logic
robonetphy Feb 28, 2023
10375f9
changes added
robonetphy Mar 13, 2023
856475f
lint removed
robonetphy Mar 13, 2023
17d2503
Merge branch 'next' into feat/dragndrop
robonetphy Mar 20, 2023
55e31c0
fix dragndrop will toolbox open
robonetphy Mar 24, 2023
a210e6f
Merge branch 'next' into feat/dragndrop
robonetphy Mar 24, 2023
0c8bb9d
update the problem with chrome and safari
robonetphy Mar 26, 2023
77a37cc
Update index.ts
robonetphy Mar 26, 2023
37b9c48
cypress-file-upload added
robonetphy Mar 26, 2023
fedab19
drag and drop test case initialized
robonetphy Mar 26, 2023
1e8f689
test case for file drop added
robonetphy Mar 26, 2023
0e599f0
dragover style testcases added
robonetphy Mar 26, 2023
92845e7
scrolling feature while dragging added
robonetphy Mar 27, 2023
890d636
drag and drop single test case added
robonetphy Mar 27, 2023
0aeb6d6
multple element drag block added
robonetphy Mar 27, 2023
501f8a2
remove the block selection filter
robonetphy Mar 28, 2023
8399d54
improvements to logic
robonetphy Mar 28, 2023
d7c0cf8
undefined => false
robonetphy Mar 28, 2023
62d0789
lint removed
robonetphy Mar 28, 2023
5683a68
test cases modified
robonetphy Mar 28, 2023
8ce1a26
testcase updated
robonetphy Apr 1, 2023
960242f
file drop testcase added
robonetphy Apr 1, 2023
643eb2e
the command added
robonetphy Apr 1, 2023
e5eec78
remove the cypress-file-upload
robonetphy Apr 1, 2023
9e832b6
remove the lints
robonetphy Apr 1, 2023
728c1ca
removed the lint
robonetphy Apr 2, 2023
1e2fd9e
Merge branch 'next' into feat/dragndrop
ilyamore88 Apr 2, 2023
c16c561
refactor: rename spec file to support latest version of Cypress
ilyamore88 Apr 2, 2023
c901965
update dropTarget => dropZonePostion
robonetphy Apr 3, 2023
5664950
create image logic updated
robonetphy Apr 3, 2023
a53484f
Merge branch 'next' into feat/dragndrop
robonetphy Apr 3, 2023
09bbb9f
Update src/components/modules/dragNDrop.ts
robonetphy Apr 3, 2023
28203e5
Merge branch 'next' into feat/dragndrop
robonetphy Apr 16, 2023
2de7c7d
Merge branch 'next' into feat/dragndrop
robonetphy Jul 26, 2023
cc875f9
test case updated
robonetphy Jul 26, 2023
13d92ca
Merge branch 'next' into feat/dragndrop
robonetphy Aug 27, 2023
9f81269
get block by child element added
robonetphy Aug 28, 2023
4f95a4e
the drop block at start added
robonetphy Aug 28, 2023
8d6acaf
test case for the dropping of image added
robonetphy Aug 28, 2023
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
"css-loader": "^3.5.3",
"cssnano": "^4.1.10",
"cypress": "^6.8.0",
"cypress-file-upload": "^5.0.8",
"cypress-intellij-reporter": "^0.0.6",
"eslint": "^8.28.0",
"eslint-config-codex": "^1.7.1",
Expand Down
48 changes: 44 additions & 4 deletions src/components/block/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,15 @@ export enum BlockToolAPI {
ON_PASTE = 'onPaste',
}

/**
* Available block drop zones position w.r.t. focused block.
*/
export enum BlockDropZonePosition {
Top = 'top',
Bottom = 'bottom',
// @todo - Left, Right could be added in the future
}

/**
* Names of events supported by Block class
*/
Expand All @@ -108,6 +117,8 @@ export default class Block extends EventsDispatcher<BlockEvents> {
focused: 'ce-block--focused',
selected: 'ce-block--selected',
dropTarget: 'ce-block--drop-target',
dropTargetTop: 'ce-block--drop-target-top',
dropTargetBottom: 'ce-block--drop-target-bottom',
};
}

Expand Down Expand Up @@ -544,12 +555,41 @@ export default class Block extends EventsDispatcher<BlockEvents> {
}

/**
* Toggle drop target state
* Toggle drop target state.
*
* @param {boolean} state - 'true' if block is drop target, false otherwise
* @param {undefined | BlockDropZonePosition} state - 'undefined' if block is not a drop target or
* position of drop zone.
*/
public set dropTarget(state) {
this.holder.classList.toggle(Block.CSS.dropTarget, state);
public set dropTarget(state: undefined | BlockDropZonePosition) {
if (!state || this.selected) {
/**
* If state is undefined or block is selected for drag
* then remove the drop target style
*/
this.holder.classList.remove(Block.CSS.dropTarget, Block.CSS.dropTargetTop, Block.CSS.dropTargetBottom);
} else {
/**
* Otherwise, toggle the block's drop target and drop zone position.
*/
this.holder.classList.toggle(Block.CSS.dropTarget, !!state);
this.holder.classList.toggle(Block.CSS.dropTargetTop, state === BlockDropZonePosition.Top);
this.holder.classList.toggle(Block.CSS.dropTargetBottom, state === BlockDropZonePosition.Bottom);
}
}

/**
* Return Block's dropTarget state.
*
* @returns {BlockDropZonePosition | undefined}
*/
public get dropTarget(): undefined | BlockDropZonePosition {
if (this.holder.classList.contains(Block.CSS.dropTargetTop)) {
return BlockDropZonePosition.Top;
} else if (this.holder.classList.contains(Block.CSS.dropTargetBottom)) {
return BlockDropZonePosition.Bottom;
}

return undefined;
}

/**
Expand Down
41 changes: 30 additions & 11 deletions src/components/modules/blockEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Module from '../__module';
import * as _ from '../utils';
import SelectionUtils from '../selection';
import Flipper from '../flipper';
import { BlockDropZonePosition } from '../block';

/**
*
Expand Down Expand Up @@ -142,25 +143,43 @@ export default class BlockEvents extends Module {
}

/**
* Add drop target styles
*
* All drag enter on block
* - use to clear previous drop target zone style.
*
* @param {DragEvent} event - drag over event
*/
public dragOver(event: DragEvent): void {
const block = this.Editor.BlockManager.getBlockByChildNode(event.target as Node);
public dragEnter(event: DragEvent): void {

block.dropTarget = true;
const { BlockManager } = this.Editor;
const block = BlockManager.getBlockByChildNode(event.target as Node);

/**
* Scroll to make element inside the viewport.
*/
_.scrollToView(block.holder);

/**
* Clear previous drop target zone for every block.
*/
this.Editor.BlockManager.clearDropTargets();
}

/**
* Remove drop target style
* All drag over on block.
* - Check the position of drag and suggest drop zone accordingly.
*
* @param {DragEvent} event - drag leave event
* @param {DragEvent} event - drag over event
*/
public dragLeave(event: DragEvent): void {
public dragOver(event: DragEvent): void {
const block = this.Editor.BlockManager.getBlockByChildNode(event.target as Node);
const rect = block.holder.getBoundingClientRect();

block.dropTarget = false;
/**
* Add style for target drop zone position.
*/
block.dropTarget = (rect.top + rect.height / 2 >= event.clientY) ?
BlockDropZonePosition.Top :
BlockDropZonePosition.Bottom;
}

/**
Expand Down Expand Up @@ -424,7 +443,7 @@ export default class BlockEvents extends Module {
if (this.Editor.BlockManager.currentBlock) {
this.Editor.BlockManager.currentBlock.updateCurrentInput();
}
// eslint-disable-next-line @typescript-eslint/no-magic-numbers
// eslint-disable-next-line @typescript-eslint/no-magic-numbers
}, 20)();
}

Expand Down Expand Up @@ -483,7 +502,7 @@ export default class BlockEvents extends Module {
if (this.Editor.BlockManager.currentBlock) {
this.Editor.BlockManager.currentBlock.updateCurrentInput();
}
// eslint-disable-next-line @typescript-eslint/no-magic-numbers
// eslint-disable-next-line @typescript-eslint/no-magic-numbers
}, 20)();
}

Expand Down
17 changes: 13 additions & 4 deletions src/components/modules/blockManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,15 @@ export default class BlockManager extends Module {
});
}

/**
* Remove drop targets style from all Blocks.
*/
public clearDropTargets(): void {
this.blocks.forEach((block) => {
block.dropTarget = undefined;
Copy link
Member

Choose a reason for hiding this comment

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

That looks unintuitive for me, could it be false here instead of undefined?

Copy link
Member Author

Choose a reason for hiding this comment

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

done

});
}

/**
* 1) Find first-level Block from passed child Node
* 2) Mark it as current
Expand Down Expand Up @@ -798,12 +807,12 @@ export default class BlockManager extends Module {
BlockEvents.keyup(event);
});

this.readOnlyMutableListeners.on(block.holder, 'dragover', (event: DragEvent) => {
BlockEvents.dragOver(event);
this.readOnlyMutableListeners.on(block.holder, 'dragenter', (event: DragEvent) => {
BlockEvents.dragEnter(event);
});

this.readOnlyMutableListeners.on(block.holder, 'dragleave', (event: DragEvent) => {
BlockEvents.dragLeave(event);
this.readOnlyMutableListeners.on(block.holder, 'dragover', (event: DragEvent) => {
BlockEvents.dragOver(event);
});

block.on('didMutated', (affectedBlock: Block) => {
Expand Down
12 changes: 11 additions & 1 deletion src/components/modules/blockSelection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ export default class BlockSelection extends Module {
* @param {boolean} restoreSelection - if true, restore saved selection
*/
public clearSelection(reason?: Event, restoreSelection = false): void {
const { BlockManager, Caret, RectangleSelection } = this.Editor;
const { BlockManager, Caret, RectangleSelection, Toolbar } = this.Editor;

this.needToSelectAll = false;
this.nativeInputSelected = false;
Expand All @@ -234,6 +234,16 @@ export default class BlockSelection extends Module {
const isKeyboard = reason && (reason instanceof KeyboardEvent);
const isPrintableKey = isKeyboard && _.isPrintableKey((reason as KeyboardEvent).keyCode);

/**
* Don't clear the selection during multiple element dragging.
*/
const isMouse = reason && (reason instanceof MouseEvent);
const isClickedOnSettingsToggler = isMouse && Toolbar.nodes.settingsToggler.contains(reason.target as HTMLElement);

if (isMouse && isClickedOnSettingsToggler) {
return;
}

/**
* If reason caused clear of the selection was printable key and any block is selected,
* remove selected blocks and insert pressed key
Expand Down
Loading