2019-02-19 09:49:19 +01:00
|
|
|
/**
|
|
|
|
* @class RectangleSelection
|
|
|
|
* @classdesc Manages Block selection with mouse
|
|
|
|
*
|
|
|
|
* @module RectangleSelection
|
|
|
|
* @version 1.0.0
|
|
|
|
*/
|
|
|
|
import Module from '../__module';
|
|
|
|
import $ from '../dom';
|
|
|
|
|
|
|
|
import SelectionUtils from '../selection';
|
|
|
|
import Block from '../block';
|
|
|
|
|
2020-06-03 10:17:29 +02:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
2019-02-19 09:49:19 +01:00
|
|
|
export default class RectangleSelection extends Module {
|
|
|
|
/**
|
|
|
|
* CSS classes for the Block
|
2020-06-03 10:17:29 +02:00
|
|
|
*
|
|
|
|
* @returns {{wrapper: string, content: string}}
|
2019-02-19 09:49:19 +01:00
|
|
|
*/
|
2020-06-03 10:17:29 +02:00
|
|
|
public static get CSS(): {[name: string]: string} {
|
2019-02-19 09:49:19 +01:00
|
|
|
return {
|
|
|
|
overlay: 'codex-editor-overlay',
|
|
|
|
overlayContainer: 'codex-editor-overlay__container',
|
|
|
|
rect: 'codex-editor-overlay__rectangle',
|
|
|
|
topScrollZone: 'codex-editor-overlay__scroll-zone--top',
|
2019-02-19 16:42:34 +01:00
|
|
|
bottomScrollZone: 'codex-editor-overlay__scroll-zone--bottom',
|
2019-02-19 09:49:19 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Using the selection rectangle
|
2020-06-03 10:17:29 +02:00
|
|
|
*
|
2019-02-19 09:49:19 +01:00
|
|
|
* @type {boolean}
|
|
|
|
*/
|
2020-06-03 10:17:29 +02:00
|
|
|
private isRectSelectionActivated = false;
|
2019-02-19 09:49:19 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Speed of Scrolling
|
|
|
|
*/
|
|
|
|
private readonly SCROLL_SPEED: number = 3;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Height of scroll zone on boundary of screen
|
|
|
|
*/
|
2019-03-01 22:34:08 +01:00
|
|
|
private readonly HEIGHT_OF_SCROLL_ZONE = 40;
|
2019-02-19 09:49:19 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Scroll zone type indicators
|
|
|
|
*/
|
|
|
|
private readonly BOTTOM_SCROLL_ZONE = 1;
|
|
|
|
private readonly TOP_SCROLL_ZONE = 2;
|
|
|
|
|
2019-02-28 18:04:56 +01:00
|
|
|
/**
|
|
|
|
* Id of main button for event.button
|
|
|
|
*/
|
|
|
|
private readonly MAIN_MOUSE_BUTTON = 0;
|
|
|
|
|
2019-02-19 09:49:19 +01:00
|
|
|
/**
|
|
|
|
* Mouse is clamped
|
|
|
|
*/
|
2020-06-03 10:17:29 +02:00
|
|
|
private mousedown = false;
|
2019-02-19 09:49:19 +01:00
|
|
|
|
2019-03-01 22:34:08 +01:00
|
|
|
/**
|
|
|
|
* Is scrolling now
|
|
|
|
*/
|
2020-06-03 10:17:29 +02:00
|
|
|
private isScrolling = false;
|
2019-03-01 22:34:08 +01:00
|
|
|
|
2019-02-19 09:49:19 +01:00
|
|
|
/**
|
|
|
|
* Mouse is in scroll zone
|
|
|
|
*/
|
|
|
|
private inScrollZone: number | null = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Coords of rect
|
|
|
|
*/
|
2020-06-03 10:17:29 +02:00
|
|
|
private startX = 0;
|
|
|
|
private startY = 0;
|
|
|
|
private mouseX = 0;
|
|
|
|
private mouseY = 0;
|
2019-02-19 09:49:19 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Selected blocks
|
|
|
|
*/
|
|
|
|
private stackOfSelected: number[] = [];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Does the rectangle intersect blocks
|
|
|
|
*/
|
|
|
|
private rectCrossesBlocks: boolean;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Selection rectangle
|
|
|
|
*/
|
|
|
|
private overlayRectangle: HTMLDivElement;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Module Preparation
|
|
|
|
* Creating rect and hang handlers
|
|
|
|
*/
|
|
|
|
public prepare(): void {
|
2020-06-03 10:17:29 +02:00
|
|
|
const { Listeners } = this.Editor;
|
|
|
|
const { container } = this.genHTML();
|
2019-02-19 09:49:19 +01:00
|
|
|
|
|
|
|
Listeners.on(container, 'mousedown', (event: MouseEvent) => {
|
2019-03-01 22:34:08 +01:00
|
|
|
if (event.button !== this.MAIN_MOUSE_BUTTON) {
|
|
|
|
return;
|
|
|
|
}
|
2019-02-19 09:49:19 +01:00
|
|
|
this.startSelection(event.pageX, event.pageY);
|
|
|
|
}, false);
|
|
|
|
|
2019-03-01 22:34:08 +01:00
|
|
|
Listeners.on(document.body, 'mousemove', (event: MouseEvent) => {
|
2019-02-19 09:49:19 +01:00
|
|
|
this.changingRectangle(event);
|
2019-03-01 22:34:08 +01:00
|
|
|
this.scrollByZones(event.clientY);
|
2019-02-19 09:49:19 +01:00
|
|
|
}, false);
|
|
|
|
|
2019-03-01 22:34:08 +01:00
|
|
|
Listeners.on(document.body, 'mouseleave', () => {
|
2019-02-19 09:49:19 +01:00
|
|
|
this.clearSelection();
|
|
|
|
this.endSelection();
|
|
|
|
});
|
|
|
|
|
|
|
|
Listeners.on(window, 'scroll', (event) => {
|
|
|
|
this.changingRectangle(event);
|
|
|
|
}, false);
|
|
|
|
|
2019-03-01 22:34:08 +01:00
|
|
|
Listeners.on(document.body, 'mouseup', () => {
|
2019-02-19 09:49:19 +01:00
|
|
|
this.endSelection();
|
|
|
|
}, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Init rect params
|
2020-06-03 10:17:29 +02:00
|
|
|
*
|
2019-02-19 09:49:19 +01:00
|
|
|
* @param {number} pageX - X coord of mouse
|
|
|
|
* @param {number} pageY - Y coord of mouse
|
|
|
|
*/
|
2020-06-03 10:17:29 +02:00
|
|
|
public startSelection(pageX, pageY): void {
|
2019-02-19 09:49:19 +01:00
|
|
|
const elemWhereSelectionStart = document.elementFromPoint(pageX - window.pageXOffset, pageY - window.pageYOffset);
|
2019-04-06 15:28:49 +02:00
|
|
|
|
Release/2.17 (#1063)
* 2.16.0
* [Refactor] Separate internal and external settings (#845)
* Enable flipping tools via standalone class (#830)
* Enable flipping tools via standalone class
* use flipper to refactor (#842)
* use flipper to refactor
* save changes
* update
* fix flipper on inline toolbar
* ready for testing
* requested changes
* update doc
* updates
* destroy flippers
* some requested changes
* update
* update
* ready
* update
* last changes
* update docs
* Hghl active button of CT, simplify activate/deactivate
* separate dom iterator
* unhardcode directions
* fixed a link in readme.md (#856)
* Fix Block selection via CMD+A (#829)
* Fix Block selection via CMD+A
* Delete editor.js.map
* update
* update
* Update CHANGELOG.md
* Improve style of selected blocks (#858)
* Cross-block-selection style improved
* Update CHANGELOG.md
* Fix case when property 'observer' in modificationObserver is not defined (#866)
* Bump lodash.template from 4.4.0 to 4.5.0 (#885)
Bumps [lodash.template](https://github.com/lodash/lodash) from 4.4.0 to 4.5.0.
- [Release notes](https://github.com/lodash/lodash/releases)
- [Commits](https://github.com/lodash/lodash/compare/4.4.0...4.5.0)
Signed-off-by: dependabot[bot] <support@github.com>
* Bump eslint-utils from 1.3.1 to 1.4.2 (#886)
Bumps [eslint-utils](https://github.com/mysticatea/eslint-utils) from 1.3.1 to 1.4.2.
- [Release notes](https://github.com/mysticatea/eslint-utils/releases)
- [Commits](https://github.com/mysticatea/eslint-utils/compare/v1.3.1...v1.4.2)
Signed-off-by: dependabot[bot] <support@github.com>
* Bump mixin-deep from 1.3.1 to 1.3.2 (#887)
Bumps [mixin-deep](https://github.com/jonschlinkert/mixin-deep) from 1.3.1 to 1.3.2.
- [Release notes](https://github.com/jonschlinkert/mixin-deep/releases)
- [Commits](https://github.com/jonschlinkert/mixin-deep/compare/1.3.1...1.3.2)
Signed-off-by: dependabot[bot] <support@github.com>
* update bundle and readme
* Update README.md
* upd codeowners, fix funding
* Minor Docs Fix according to main Readme (#916)
* Inline Toolbar now contains Conversion Toolbar (#932)
* Block lifecycle hooks (#906)
* [Fix] Arrow selection (#964)
* Fix arrow selection
* Add docs
* [issue-926]: fix dom iterator leafing when items are empty (#958)
* [issue-926]: fix dom iterator leafing when items are empty
* update Changelog
* Issue 869 (#963)
* Fix issue 943 (#965)
* [Draft] Feature/tooltip enhancements (#907)
* initial
* update
* make module standalone
* use tooltips as external module
* update
* build via prod mode
* add tooltips as external module
* add declaration file and options param
* add api tooltip
* update
* removed submodule
* removed due to the incorrect setip
* setup tooltips again
* wip
* update tooltip module
* toolbox, inline toolbar
* Tooltips in block tunes not uses shorthand
* shorthand in a plus and block settings
* fix doc
* Update tools-inline.md
* Delete tooltip.css
* Update CHANGELOG.md
* Update codex.tooltips
* Update api.md
* [issue-779]: Grammarly conflicts (#956)
* grammarly conflicts
* update
* upd bundle
* Submodule Header now on master
* Submodule Marker now on master
* Submodule Paragraph now on master
* Submodule InlineCode now on master
* Submodule Simple Image now on master
* [issue-868]: Deleting multiple blocks triggers back button in Firefox (#967)
* Deleting multiple blocks triggers back button in Firefox
@evgenusov
* Update editor.js
* Update CHANGELOG.md
* pass options on removeEventListener (#904)
* pass options on removeEventListener by removeAll
* rebuild
* Merge branch 'release/2.16' into pr/904
* Update CHANGELOG.md
* Update inline.ts
* [Fix] Selection rangecount (#968)
* Fix #952 (#969)
* Update codex.tooltips
* Selection bugfix (#970)
* Selection bugfix
* fix cross block selection
* close inline toolbar when blocks selected via shift
* remove inline toolbar closing on cross block selection mouse up due to the bug (#972)
* [Feature] Log levels (#971)
* Decrease margins (#973)
* Decrease margins
* Update editor.licenses.txt
* Update src/components/domIterator.ts
Co-Authored-By: Murod Khaydarov <murod.haydarov@gmail.com>
* [Fix] Fix delete blocks api method (#974)
* Update docs/usage.md
Co-Authored-By: Murod Khaydarov <murod.haydarov@gmail.com>
* rm unused
* Update yarn.lock file
* upd bundle, changelog
* Resolve Firefox issues (#981)
* Resolve Firefox issues
* use firefox hack only for empty c-e divs
* Set initial hidden Inline Toolbar position (#982)
Resolves #979
* [Fix] tooltip types (#986)
* Add tooltip as a package
* Fix to set minHeight 0px (#987)
* Release 2.16 (#966)
* 2.16.0
* [Refactor] Separate internal and external settings (#845)
* Enable flipping tools via standalone class (#830)
* Enable flipping tools via standalone class
* use flipper to refactor (#842)
* use flipper to refactor
* save changes
* update
* fix flipper on inline toolbar
* ready for testing
* requested changes
* update doc
* updates
* destroy flippers
* some requested changes
* update
* update
* ready
* update
* last changes
* update docs
* Hghl active button of CT, simplify activate/deactivate
* separate dom iterator
* unhardcode directions
* fixed a link in readme.md (#856)
* Fix Block selection via CMD+A (#829)
* Fix Block selection via CMD+A
* Delete editor.js.map
* update
* update
* Update CHANGELOG.md
* Improve style of selected blocks (#858)
* Cross-block-selection style improved
* Update CHANGELOG.md
* Fix case when property 'observer' in modificationObserver is not defined (#866)
* Bump lodash.template from 4.4.0 to 4.5.0 (#885)
Bumps [lodash.template](https://github.com/lodash/lodash) from 4.4.0 to 4.5.0.
- [Release notes](https://github.com/lodash/lodash/releases)
- [Commits](https://github.com/lodash/lodash/compare/4.4.0...4.5.0)
Signed-off-by: dependabot[bot] <support@github.com>
* Bump eslint-utils from 1.3.1 to 1.4.2 (#886)
Bumps [eslint-utils](https://github.com/mysticatea/eslint-utils) from 1.3.1 to 1.4.2.
- [Release notes](https://github.com/mysticatea/eslint-utils/releases)
- [Commits](https://github.com/mysticatea/eslint-utils/compare/v1.3.1...v1.4.2)
Signed-off-by: dependabot[bot] <support@github.com>
* Bump mixin-deep from 1.3.1 to 1.3.2 (#887)
Bumps [mixin-deep](https://github.com/jonschlinkert/mixin-deep) from 1.3.1 to 1.3.2.
- [Release notes](https://github.com/jonschlinkert/mixin-deep/releases)
- [Commits](https://github.com/jonschlinkert/mixin-deep/compare/1.3.1...1.3.2)
Signed-off-by: dependabot[bot] <support@github.com>
* update bundle and readme
* Update README.md
* upd codeowners, fix funding
* Minor Docs Fix according to main Readme (#916)
* Inline Toolbar now contains Conversion Toolbar (#932)
* Block lifecycle hooks (#906)
* [Fix] Arrow selection (#964)
* Fix arrow selection
* Add docs
* [issue-926]: fix dom iterator leafing when items are empty (#958)
* [issue-926]: fix dom iterator leafing when items are empty
* update Changelog
* Issue 869 (#963)
* Fix issue 943 (#965)
* [Draft] Feature/tooltip enhancements (#907)
* initial
* update
* make module standalone
* use tooltips as external module
* update
* build via prod mode
* add tooltips as external module
* add declaration file and options param
* add api tooltip
* update
* removed submodule
* removed due to the incorrect setip
* setup tooltips again
* wip
* update tooltip module
* toolbox, inline toolbar
* Tooltips in block tunes not uses shorthand
* shorthand in a plus and block settings
* fix doc
* Update tools-inline.md
* Delete tooltip.css
* Update CHANGELOG.md
* Update codex.tooltips
* Update api.md
* [issue-779]: Grammarly conflicts (#956)
* grammarly conflicts
* update
* upd bundle
* Submodule Header now on master
* Submodule Marker now on master
* Submodule Paragraph now on master
* Submodule InlineCode now on master
* Submodule Simple Image now on master
* [issue-868]: Deleting multiple blocks triggers back button in Firefox (#967)
* Deleting multiple blocks triggers back button in Firefox
@evgenusov
* Update editor.js
* Update CHANGELOG.md
* pass options on removeEventListener (#904)
* pass options on removeEventListener by removeAll
* rebuild
* Merge branch 'release/2.16' into pr/904
* Update CHANGELOG.md
* Update inline.ts
* [Fix] Selection rangecount (#968)
* Fix #952 (#969)
* Update codex.tooltips
* Selection bugfix (#970)
* Selection bugfix
* fix cross block selection
* close inline toolbar when blocks selected via shift
* remove inline toolbar closing on cross block selection mouse up due to the bug (#972)
* [Feature] Log levels (#971)
* Decrease margins (#973)
* Decrease margins
* Update editor.licenses.txt
* Update src/components/domIterator.ts
Co-Authored-By: Murod Khaydarov <murod.haydarov@gmail.com>
* [Fix] Fix delete blocks api method (#974)
* Update docs/usage.md
Co-Authored-By: Murod Khaydarov <murod.haydarov@gmail.com>
* rm unused
* Update yarn.lock file
* upd bundle, changelog
* Fix changeling list items (#975)
* Update changelog (#976)
* Fix to set minHeight 0px
* upd version
* Update CHANGELOG.md
* upd bundle
* [Fix] Selection issues (#988)
* [Dev] Update dependencies (#989)
* Delete codex.tooltips
* Update submodules
* Fix/hide conversion toolbar (#991)
* Hide conversion toolbar if there is no conversion tool
* update changelog
* update comment
* updates
* improve code
* Update Changelog
* Update CHANGELOG.md
* fix some problems at example
* Update CHANGELOG.md
* Fix: bind editor when calling onChange (#1048)
* Release/2.16.1 (#990)
* 2.16.0
* [Refactor] Separate internal and external settings (#845)
* Enable flipping tools via standalone class (#830)
* Enable flipping tools via standalone class
* use flipper to refactor (#842)
* use flipper to refactor
* save changes
* update
* fix flipper on inline toolbar
* ready for testing
* requested changes
* update doc
* updates
* destroy flippers
* some requested changes
* update
* update
* ready
* update
* last changes
* update docs
* Hghl active button of CT, simplify activate/deactivate
* separate dom iterator
* unhardcode directions
* fixed a link in readme.md (#856)
* Fix Block selection via CMD+A (#829)
* Fix Block selection via CMD+A
* Delete editor.js.map
* update
* update
* Update CHANGELOG.md
* Improve style of selected blocks (#858)
* Cross-block-selection style improved
* Update CHANGELOG.md
* Fix case when property 'observer' in modificationObserver is not defined (#866)
* Bump lodash.template from 4.4.0 to 4.5.0 (#885)
Bumps [lodash.template](https://github.com/lodash/lodash) from 4.4.0 to 4.5.0.
- [Release notes](https://github.com/lodash/lodash/releases)
- [Commits](https://github.com/lodash/lodash/compare/4.4.0...4.5.0)
Signed-off-by: dependabot[bot] <support@github.com>
* Bump eslint-utils from 1.3.1 to 1.4.2 (#886)
Bumps [eslint-utils](https://github.com/mysticatea/eslint-utils) from 1.3.1 to 1.4.2.
- [Release notes](https://github.com/mysticatea/eslint-utils/releases)
- [Commits](https://github.com/mysticatea/eslint-utils/compare/v1.3.1...v1.4.2)
Signed-off-by: dependabot[bot] <support@github.com>
* Bump mixin-deep from 1.3.1 to 1.3.2 (#887)
Bumps [mixin-deep](https://github.com/jonschlinkert/mixin-deep) from 1.3.1 to 1.3.2.
- [Release notes](https://github.com/jonschlinkert/mixin-deep/releases)
- [Commits](https://github.com/jonschlinkert/mixin-deep/compare/1.3.1...1.3.2)
Signed-off-by: dependabot[bot] <support@github.com>
* update bundle and readme
* Update README.md
* upd codeowners, fix funding
* Minor Docs Fix according to main Readme (#916)
* Inline Toolbar now contains Conversion Toolbar (#932)
* Block lifecycle hooks (#906)
* [Fix] Arrow selection (#964)
* Fix arrow selection
* Add docs
* [issue-926]: fix dom iterator leafing when items are empty (#958)
* [issue-926]: fix dom iterator leafing when items are empty
* update Changelog
* Issue 869 (#963)
* Fix issue 943 (#965)
* [Draft] Feature/tooltip enhancements (#907)
* initial
* update
* make module standalone
* use tooltips as external module
* update
* build via prod mode
* add tooltips as external module
* add declaration file and options param
* add api tooltip
* update
* removed submodule
* removed due to the incorrect setip
* setup tooltips again
* wip
* update tooltip module
* toolbox, inline toolbar
* Tooltips in block tunes not uses shorthand
* shorthand in a plus and block settings
* fix doc
* Update tools-inline.md
* Delete tooltip.css
* Update CHANGELOG.md
* Update codex.tooltips
* Update api.md
* [issue-779]: Grammarly conflicts (#956)
* grammarly conflicts
* update
* upd bundle
* Submodule Header now on master
* Submodule Marker now on master
* Submodule Paragraph now on master
* Submodule InlineCode now on master
* Submodule Simple Image now on master
* [issue-868]: Deleting multiple blocks triggers back button in Firefox (#967)
* Deleting multiple blocks triggers back button in Firefox
@evgenusov
* Update editor.js
* Update CHANGELOG.md
* pass options on removeEventListener (#904)
* pass options on removeEventListener by removeAll
* rebuild
* Merge branch 'release/2.16' into pr/904
* Update CHANGELOG.md
* Update inline.ts
* [Fix] Selection rangecount (#968)
* Fix #952 (#969)
* Update codex.tooltips
* Selection bugfix (#970)
* Selection bugfix
* fix cross block selection
* close inline toolbar when blocks selected via shift
* remove inline toolbar closing on cross block selection mouse up due to the bug (#972)
* [Feature] Log levels (#971)
* Decrease margins (#973)
* Decrease margins
* Update editor.licenses.txt
* Update src/components/domIterator.ts
Co-Authored-By: Murod Khaydarov <murod.haydarov@gmail.com>
* [Fix] Fix delete blocks api method (#974)
* Update docs/usage.md
Co-Authored-By: Murod Khaydarov <murod.haydarov@gmail.com>
* rm unused
* Update yarn.lock file
* upd bundle, changelog
* Resolve Firefox issues (#981)
* Resolve Firefox issues
* use firefox hack only for empty c-e divs
* Set initial hidden Inline Toolbar position (#982)
Resolves #979
* [Fix] tooltip types (#986)
* Add tooltip as a package
* Fix to set minHeight 0px (#987)
* Release 2.16 (#966)
* 2.16.0
* [Refactor] Separate internal and external settings (#845)
* Enable flipping tools via standalone class (#830)
* Enable flipping tools via standalone class
* use flipper to refactor (#842)
* use flipper to refactor
* save changes
* update
* fix flipper on inline toolbar
* ready for testing
* requested changes
* update doc
* updates
* destroy flippers
* some requested changes
* update
* update
* ready
* update
* last changes
* update docs
* Hghl active button of CT, simplify activate/deactivate
* separate dom iterator
* unhardcode directions
* fixed a link in readme.md (#856)
* Fix Block selection via CMD+A (#829)
* Fix Block selection via CMD+A
* Delete editor.js.map
* update
* update
* Update CHANGELOG.md
* Improve style of selected blocks (#858)
* Cross-block-selection style improved
* Update CHANGELOG.md
* Fix case when property 'observer' in modificationObserver is not defined (#866)
* Bump lodash.template from 4.4.0 to 4.5.0 (#885)
Bumps [lodash.template](https://github.com/lodash/lodash) from 4.4.0 to 4.5.0.
- [Release notes](https://github.com/lodash/lodash/releases)
- [Commits](https://github.com/lodash/lodash/compare/4.4.0...4.5.0)
Signed-off-by: dependabot[bot] <support@github.com>
* Bump eslint-utils from 1.3.1 to 1.4.2 (#886)
Bumps [eslint-utils](https://github.com/mysticatea/eslint-utils) from 1.3.1 to 1.4.2.
- [Release notes](https://github.com/mysticatea/eslint-utils/releases)
- [Commits](https://github.com/mysticatea/eslint-utils/compare/v1.3.1...v1.4.2)
Signed-off-by: dependabot[bot] <support@github.com>
* Bump mixin-deep from 1.3.1 to 1.3.2 (#887)
Bumps [mixin-deep](https://github.com/jonschlinkert/mixin-deep) from 1.3.1 to 1.3.2.
- [Release notes](https://github.com/jonschlinkert/mixin-deep/releases)
- [Commits](https://github.com/jonschlinkert/mixin-deep/compare/1.3.1...1.3.2)
Signed-off-by: dependabot[bot] <support@github.com>
* update bundle and readme
* Update README.md
* upd codeowners, fix funding
* Minor Docs Fix according to main Readme (#916)
* Inline Toolbar now contains Conversion Toolbar (#932)
* Block lifecycle hooks (#906)
* [Fix] Arrow selection (#964)
* Fix arrow selection
* Add docs
* [issue-926]: fix dom iterator leafing when items are empty (#958)
* [issue-926]: fix dom iterator leafing when items are empty
* update Changelog
* Issue 869 (#963)
* Fix issue 943 (#965)
* [Draft] Feature/tooltip enhancements (#907)
* initial
* update
* make module standalone
* use tooltips as external module
* update
* build via prod mode
* add tooltips as external module
* add declaration file and options param
* add api tooltip
* update
* removed submodule
* removed due to the incorrect setip
* setup tooltips again
* wip
* update tooltip module
* toolbox, inline toolbar
* Tooltips in block tunes not uses shorthand
* shorthand in a plus and block settings
* fix doc
* Update tools-inline.md
* Delete tooltip.css
* Update CHANGELOG.md
* Update codex.tooltips
* Update api.md
* [issue-779]: Grammarly conflicts (#956)
* grammarly conflicts
* update
* upd bundle
* Submodule Header now on master
* Submodule Marker now on master
* Submodule Paragraph now on master
* Submodule InlineCode now on master
* Submodule Simple Image now on master
* [issue-868]: Deleting multiple blocks triggers back button in Firefox (#967)
* Deleting multiple blocks triggers back button in Firefox
@evgenusov
* Update editor.js
* Update CHANGELOG.md
* pass options on removeEventListener (#904)
* pass options on removeEventListener by removeAll
* rebuild
* Merge branch 'release/2.16' into pr/904
* Update CHANGELOG.md
* Update inline.ts
* [Fix] Selection rangecount (#968)
* Fix #952 (#969)
* Update codex.tooltips
* Selection bugfix (#970)
* Selection bugfix
* fix cross block selection
* close inline toolbar when blocks selected via shift
* remove inline toolbar closing on cross block selection mouse up due to the bug (#972)
* [Feature] Log levels (#971)
* Decrease margins (#973)
* Decrease margins
* Update editor.licenses.txt
* Update src/components/domIterator.ts
Co-Authored-By: Murod Khaydarov <murod.haydarov@gmail.com>
* [Fix] Fix delete blocks api method (#974)
* Update docs/usage.md
Co-Authored-By: Murod Khaydarov <murod.haydarov@gmail.com>
* rm unused
* Update yarn.lock file
* upd bundle, changelog
* Fix changeling list items (#975)
* Update changelog (#976)
* Fix to set minHeight 0px
* upd version
* Update CHANGELOG.md
* upd bundle
* [Fix] Selection issues (#988)
* [Dev] Update dependencies (#989)
* Delete codex.tooltips
* Update submodules
* Fix/hide conversion toolbar (#991)
* Hide conversion toolbar if there is no conversion tool
* update changelog
* update comment
* updates
* improve code
* Update Changelog
* Update CHANGELOG.md
* Update CHANGELOG.md
* Fix: bind editor when calling onChange
fixes #999
* send api as a parameter
* upd bundle
* Update CHANGELOG.md
Co-authored-by: Peter Savchenko <specc.dev@gmail.com>
* updated some wording. (#1044)
* Release/2.16.1 (#990)
* 2.16.0
* [Refactor] Separate internal and external settings (#845)
* Enable flipping tools via standalone class (#830)
* Enable flipping tools via standalone class
* use flipper to refactor (#842)
* use flipper to refactor
* save changes
* update
* fix flipper on inline toolbar
* ready for testing
* requested changes
* update doc
* updates
* destroy flippers
* some requested changes
* update
* update
* ready
* update
* last changes
* update docs
* Hghl active button of CT, simplify activate/deactivate
* separate dom iterator
* unhardcode directions
* fixed a link in readme.md (#856)
* Fix Block selection via CMD+A (#829)
* Fix Block selection via CMD+A
* Delete editor.js.map
* update
* update
* Update CHANGELOG.md
* Improve style of selected blocks (#858)
* Cross-block-selection style improved
* Update CHANGELOG.md
* Fix case when property 'observer' in modificationObserver is not defined (#866)
* Bump lodash.template from 4.4.0 to 4.5.0 (#885)
Bumps [lodash.template](https://github.com/lodash/lodash) from 4.4.0 to 4.5.0.
- [Release notes](https://github.com/lodash/lodash/releases)
- [Commits](https://github.com/lodash/lodash/compare/4.4.0...4.5.0)
Signed-off-by: dependabot[bot] <support@github.com>
* Bump eslint-utils from 1.3.1 to 1.4.2 (#886)
Bumps [eslint-utils](https://github.com/mysticatea/eslint-utils) from 1.3.1 to 1.4.2.
- [Release notes](https://github.com/mysticatea/eslint-utils/releases)
- [Commits](https://github.com/mysticatea/eslint-utils/compare/v1.3.1...v1.4.2)
Signed-off-by: dependabot[bot] <support@github.com>
* Bump mixin-deep from 1.3.1 to 1.3.2 (#887)
Bumps [mixin-deep](https://github.com/jonschlinkert/mixin-deep) from 1.3.1 to 1.3.2.
- [Release notes](https://github.com/jonschlinkert/mixin-deep/releases)
- [Commits](https://github.com/jonschlinkert/mixin-deep/compare/1.3.1...1.3.2)
Signed-off-by: dependabot[bot] <support@github.com>
* update bundle and readme
* Update README.md
* upd codeowners, fix funding
* Minor Docs Fix according to main Readme (#916)
* Inline Toolbar now contains Conversion Toolbar (#932)
* Block lifecycle hooks (#906)
* [Fix] Arrow selection (#964)
* Fix arrow selection
* Add docs
* [issue-926]: fix dom iterator leafing when items are empty (#958)
* [issue-926]: fix dom iterator leafing when items are empty
* update Changelog
* Issue 869 (#963)
* Fix issue 943 (#965)
* [Draft] Feature/tooltip enhancements (#907)
* initial
* update
* make module standalone
* use tooltips as external module
* update
* build via prod mode
* add tooltips as external module
* add declaration file and options param
* add api tooltip
* update
* removed submodule
* removed due to the incorrect setip
* setup tooltips again
* wip
* update tooltip module
* toolbox, inline toolbar
* Tooltips in block tunes not uses shorthand
* shorthand in a plus and block settings
* fix doc
* Update tools-inline.md
* Delete tooltip.css
* Update CHANGELOG.md
* Update codex.tooltips
* Update api.md
* [issue-779]: Grammarly conflicts (#956)
* grammarly conflicts
* update
* upd bundle
* Submodule Header now on master
* Submodule Marker now on master
* Submodule Paragraph now on master
* Submodule InlineCode now on master
* Submodule Simple Image now on master
* [issue-868]: Deleting multiple blocks triggers back button in Firefox (#967)
* Deleting multiple blocks triggers back button in Firefox
@evgenusov
* Update editor.js
* Update CHANGELOG.md
* pass options on removeEventListener (#904)
* pass options on removeEventListener by removeAll
* rebuild
* Merge branch 'release/2.16' into pr/904
* Update CHANGELOG.md
* Update inline.ts
* [Fix] Selection rangecount (#968)
* Fix #952 (#969)
* Update codex.tooltips
* Selection bugfix (#970)
* Selection bugfix
* fix cross block selection
* close inline toolbar when blocks selected via shift
* remove inline toolbar closing on cross block selection mouse up due to the bug (#972)
* [Feature] Log levels (#971)
* Decrease margins (#973)
* Decrease margins
* Update editor.licenses.txt
* Update src/components/domIterator.ts
Co-Authored-By: Murod Khaydarov <murod.haydarov@gmail.com>
* [Fix] Fix delete blocks api method (#974)
* Update docs/usage.md
Co-Authored-By: Murod Khaydarov <murod.haydarov@gmail.com>
* rm unused
* Update yarn.lock file
* upd bundle, changelog
* Resolve Firefox issues (#981)
* Resolve Firefox issues
* use firefox hack only for empty c-e divs
* Set initial hidden Inline Toolbar position (#982)
Resolves #979
* [Fix] tooltip types (#986)
* Add tooltip as a package
* Fix to set minHeight 0px (#987)
* Release 2.16 (#966)
* 2.16.0
* [Refactor] Separate internal and external settings (#845)
* Enable flipping tools via standalone class (#830)
* Enable flipping tools via standalone class
* use flipper to refactor (#842)
* use flipper to refactor
* save changes
* update
* fix flipper on inline toolbar
* ready for testing
* requested changes
* update doc
* updates
* destroy flippers
* some requested changes
* update
* update
* ready
* update
* last changes
* update docs
* Hghl active button of CT, simplify activate/deactivate
* separate dom iterator
* unhardcode directions
* fixed a link in readme.md (#856)
* Fix Block selection via CMD+A (#829)
* Fix Block selection via CMD+A
* Delete editor.js.map
* update
* update
* Update CHANGELOG.md
* Improve style of selected blocks (#858)
* Cross-block-selection style improved
* Update CHANGELOG.md
* Fix case when property 'observer' in modificationObserver is not defined (#866)
* Bump lodash.template from 4.4.0 to 4.5.0 (#885)
Bumps [lodash.template](https://github.com/lodash/lodash) from 4.4.0 to 4.5.0.
- [Release notes](https://github.com/lodash/lodash/releases)
- [Commits](https://github.com/lodash/lodash/compare/4.4.0...4.5.0)
Signed-off-by: dependabot[bot] <support@github.com>
* Bump eslint-utils from 1.3.1 to 1.4.2 (#886)
Bumps [eslint-utils](https://github.com/mysticatea/eslint-utils) from 1.3.1 to 1.4.2.
- [Release notes](https://github.com/mysticatea/eslint-utils/releases)
- [Commits](https://github.com/mysticatea/eslint-utils/compare/v1.3.1...v1.4.2)
Signed-off-by: dependabot[bot] <support@github.com>
* Bump mixin-deep from 1.3.1 to 1.3.2 (#887)
Bumps [mixin-deep](https://github.com/jonschlinkert/mixin-deep) from 1.3.1 to 1.3.2.
- [Release notes](https://github.com/jonschlinkert/mixin-deep/releases)
- [Commits](https://github.com/jonschlinkert/mixin-deep/compare/1.3.1...1.3.2)
Signed-off-by: dependabot[bot] <support@github.com>
* update bundle and readme
* Update README.md
* upd codeowners, fix funding
* Minor Docs Fix according to main Readme (#916)
* Inline Toolbar now contains Conversion Toolbar (#932)
* Block lifecycle hooks (#906)
* [Fix] Arrow selection (#964)
* Fix arrow selection
* Add docs
* [issue-926]: fix dom iterator leafing when items are empty (#958)
* [issue-926]: fix dom iterator leafing when items are empty
* update Changelog
* Issue 869 (#963)
* Fix issue 943 (#965)
* [Draft] Feature/tooltip enhancements (#907)
* initial
* update
* make module standalone
* use tooltips as external module
* update
* build via prod mode
* add tooltips as external module
* add declaration file and options param
* add api tooltip
* update
* removed submodule
* removed due to the incorrect setip
* setup tooltips again
* wip
* update tooltip module
* toolbox, inline toolbar
* Tooltips in block tunes not uses shorthand
* shorthand in a plus and block settings
* fix doc
* Update tools-inline.md
* Delete tooltip.css
* Update CHANGELOG.md
* Update codex.tooltips
* Update api.md
* [issue-779]: Grammarly conflicts (#956)
* grammarly conflicts
* update
* upd bundle
* Submodule Header now on master
* Submodule Marker now on master
* Submodule Paragraph now on master
* Submodule InlineCode now on master
* Submodule Simple Image now on master
* [issue-868]: Deleting multiple blocks triggers back button in Firefox (#967)
* Deleting multiple blocks triggers back button in Firefox
@evgenusov
* Update editor.js
* Update CHANGELOG.md
* pass options on removeEventListener (#904)
* pass options on removeEventListener by removeAll
* rebuild
* Merge branch 'release/2.16' into pr/904
* Update CHANGELOG.md
* Update inline.ts
* [Fix] Selection rangecount (#968)
* Fix #952 (#969)
* Update codex.tooltips
* Selection bugfix (#970)
* Selection bugfix
* fix cross block selection
* close inline toolbar when blocks selected via shift
* remove inline toolbar closing on cross block selection mouse up due to the bug (#972)
* [Feature] Log levels (#971)
* Decrease margins (#973)
* Decrease margins
* Update editor.licenses.txt
* Update src/components/domIterator.ts
Co-Authored-By: Murod Khaydarov <murod.haydarov@gmail.com>
* [Fix] Fix delete blocks api method (#974)
* Update docs/usage.md
Co-Authored-By: Murod Khaydarov <murod.haydarov@gmail.com>
* rm unused
* Update yarn.lock file
* upd bundle, changelog
* Fix changeling list items (#975)
* Update changelog (#976)
* Fix to set minHeight 0px
* upd version
* Update CHANGELOG.md
* upd bundle
* [Fix] Selection issues (#988)
* [Dev] Update dependencies (#989)
* Delete codex.tooltips
* Update submodules
* Fix/hide conversion toolbar (#991)
* Hide conversion toolbar if there is no conversion tool
* update changelog
* update comment
* updates
* improve code
* Update Changelog
* Update CHANGELOG.md
* Update CHANGELOG.md
* updated some wording.
* Update installation.md
* Update CHANGELOG.md
Co-authored-by: Peter Savchenko <specc.dev@gmail.com>
* Fix grammar in readme.md (#1008)
* Update editor.js
* Paste listener on editors instead of document (#1025)
* Paste listener on editors instead of document
* add changelog
Co-authored-by: Peter Savchenko <specc.dev@gmail.com>
* Bump acorn from 6.4.0 to 6.4.1 (#1059)
Bumps [acorn](https://github.com/acornjs/acorn) from 6.4.0 to 6.4.1.
- [Release notes](https://github.com/acornjs/acorn/releases)
- [Commits](https://github.com/acornjs/acorn/compare/6.4.0...6.4.1)
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* Fix flipper activate/deactivate when conversionToolbarOpened (#1001)
* Fix flipper activate/deactivate when conversionToolbarOpened
* fix bug with flipping inline toolbar
* update changelog
* added comment for new condition
* upd bundle
Co-authored-by: Murod Khaydarov <murod.haydarov@gmail.com>
Co-authored-by: Peter Savchenko <specc.dev@gmail.com>
* [Issue-1057]: open new window by clicking anchor with ctrl (#1062)
* open new window when anchor clicked with ctrl
* delete source maps
* update function name
* update
* update changelog
* Fix settings box-sizing (#1013)
* Improvements: new Block Settings button style (#1064)
* [Feature] In-house copy paste (#1060)
* New block lifecycle hook and BlockToolAPI: "moved" (#1007)
* Update CHANGELOG.md
* feat: add swapped lifecycle hook
* feat: deprecate swap and add move instead
* feat: set fromIndex by default, add MoveEvent, add indices checks in blockManager
* refactor: MoveEvent interface more event-like; docs: added docs for MoveEvent
* fix asterix alignment due to tslint error
* fix tslint
* extending CustomEvent
* update bundle
* Update CHANGELOG.md
Co-authored-by: Peter Savchenko <specc.dev@gmail.com>
Co-authored-by: Murod Khaydarov <murod.haydarov@gmail.com>
* Change paste function of text/plain (#1014)
Co-authored-by: Georgy Berezhnoy <gohabereg@gmail.com>
* Improve paste function of multiple lines (#1016)
Co-authored-by: Georgy Berezhnoy <gohabereg@gmail.com>
* 2.17.0
* Update bundle
Co-authored-by: georgyb <yegor.berezhnoi@3d4medical.com>
Co-authored-by: George Berezhnoy <gohabereg@users.noreply.github.com>
Co-authored-by: Christof Jans <christof@loopfx.com>
Co-authored-by: Peter Savchenko <specc.dev@gmail.com>
Co-authored-by: VladimirZhdanov <vlzh@pm.me>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Chaitanya <yourchaitu@gmail.com>
Co-authored-by: Marina <marina.zadoyanchuk@gmail.com>
Co-authored-by: Hata <hato6502@gmail.com>
Co-authored-by: Mohamed El Bahja <mohamed.jss11@gmail.Com>
Co-authored-by: Danny Rubio <drbe4t@gmail.com>
Co-authored-by: darrelfrancis <20881844+darrelfrancis@users.noreply.github.com>
Co-authored-by: Emmanuel Francis Ramos Jr <ponnex@gmail.com>
Co-authored-by: Andrey Blinov <andrey.blinoff@gmail.com>
Co-authored-by: Stefan Natter <stefan@natter.at>
Co-authored-by: Georgy Berezhnoy <gohabereg@gmail.com>
2020-03-14 21:47:04 +01:00
|
|
|
/**
|
|
|
|
* Don't clear selected block by clicks on the Block settings
|
|
|
|
* because we need to keep highlighting working block
|
|
|
|
*/
|
|
|
|
const startsInsideToolbar = elemWhereSelectionStart.closest(`.${this.Editor.Toolbar.CSS.toolbar}`);
|
|
|
|
|
|
|
|
if (!startsInsideToolbar) {
|
|
|
|
this.Editor.BlockSelection.allBlocksSelected = false;
|
|
|
|
this.clearSelection();
|
|
|
|
this.stackOfSelected = [];
|
|
|
|
}
|
|
|
|
|
2019-04-06 15:28:49 +02:00
|
|
|
const selectorsToAvoid = [
|
|
|
|
`.${Block.CSS.content}`,
|
|
|
|
`.${this.Editor.Toolbar.CSS.toolbar}`,
|
|
|
|
`.${this.Editor.InlineToolbar.CSS.inlineToolbar}`,
|
|
|
|
];
|
|
|
|
|
|
|
|
const startsInsideEditor = elemWhereSelectionStart.closest('.' + this.Editor.UI.CSS.editorWrapper);
|
2020-06-03 10:17:29 +02:00
|
|
|
const startsInSelectorToAvoid = selectorsToAvoid.some((selector) => !!elemWhereSelectionStart.closest(selector));
|
2019-04-06 15:28:49 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* If selection starts outside of the editor or inside the blocks or on Editor UI elements, do not handle it
|
|
|
|
*/
|
|
|
|
if (!startsInsideEditor || startsInSelectorToAvoid) {
|
2019-02-19 09:49:19 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.mousedown = true;
|
|
|
|
this.startX = pageX;
|
|
|
|
this.startY = pageY;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Clear all params to end selection
|
|
|
|
*/
|
2020-06-03 10:17:29 +02:00
|
|
|
public endSelection(): void {
|
2019-02-19 09:49:19 +01:00
|
|
|
this.mousedown = false;
|
|
|
|
this.startX = 0;
|
|
|
|
this.startY = 0;
|
|
|
|
this.overlayRectangle.style.display = 'none';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* is RectSelection Activated
|
|
|
|
*/
|
2020-06-03 10:17:29 +02:00
|
|
|
public isRectActivated(): boolean {
|
2019-02-19 09:49:19 +01:00
|
|
|
return this.isRectSelectionActivated;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Mark that selection is end
|
|
|
|
*/
|
2020-06-03 10:17:29 +02:00
|
|
|
public clearSelection(): void {
|
2019-02-19 09:49:19 +01:00
|
|
|
this.isRectSelectionActivated = false;
|
|
|
|
}
|
|
|
|
|
2019-03-01 22:34:08 +01:00
|
|
|
/**
|
|
|
|
* Scroll If mouse in scroll zone
|
2020-06-03 10:17:29 +02:00
|
|
|
*
|
2019-03-01 22:34:08 +01:00
|
|
|
* @param {number} clientY - Y coord of mouse
|
|
|
|
*/
|
2020-06-03 10:17:29 +02:00
|
|
|
private scrollByZones(clientY): void {
|
2019-03-01 22:34:08 +01:00
|
|
|
this.inScrollZone = null;
|
|
|
|
if (clientY <= this.HEIGHT_OF_SCROLL_ZONE) {
|
|
|
|
this.inScrollZone = this.TOP_SCROLL_ZONE;
|
|
|
|
}
|
|
|
|
if (document.documentElement.clientHeight - clientY <= this.HEIGHT_OF_SCROLL_ZONE) {
|
|
|
|
this.inScrollZone = this.BOTTOM_SCROLL_ZONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!this.inScrollZone) {
|
|
|
|
this.isScrolling = false;
|
2020-06-03 10:17:29 +02:00
|
|
|
|
2019-03-01 22:34:08 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!this.isScrolling) {
|
|
|
|
this.scrollVertical(this.inScrollZone === this.TOP_SCROLL_ZONE ? -this.SCROLL_SPEED : this.SCROLL_SPEED);
|
|
|
|
this.isScrolling = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-03 10:17:29 +02:00
|
|
|
/**
|
|
|
|
* Generates required HTML elements
|
|
|
|
*
|
|
|
|
* @returns {object<string, Element>}
|
|
|
|
*/
|
|
|
|
private genHTML(): {container: Element; overlay: Element} {
|
|
|
|
const { UI } = this.Editor;
|
2019-03-18 17:22:22 +01:00
|
|
|
|
|
|
|
const container = UI.nodes.holder.querySelector('.' + UI.CSS.editorWrapper);
|
2019-02-19 09:49:19 +01:00
|
|
|
const overlay = $.make('div', RectangleSelection.CSS.overlay, {});
|
|
|
|
const overlayContainer = $.make('div', RectangleSelection.CSS.overlayContainer, {});
|
|
|
|
const overlayRectangle = $.make('div', RectangleSelection.CSS.rect, {});
|
|
|
|
|
|
|
|
overlayContainer.appendChild(overlayRectangle);
|
|
|
|
overlay.appendChild(overlayContainer);
|
|
|
|
container.appendChild(overlay);
|
|
|
|
|
|
|
|
this.overlayRectangle = overlayRectangle as HTMLDivElement;
|
2020-06-03 10:17:29 +02:00
|
|
|
|
2019-02-19 09:49:19 +01:00
|
|
|
return {
|
|
|
|
container,
|
|
|
|
overlay,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Activates scrolling if blockSelection is active and mouse is in scroll zone
|
2020-06-03 10:17:29 +02:00
|
|
|
*
|
2019-02-19 09:49:19 +01:00
|
|
|
* @param {number} speed - speed of scrolling
|
|
|
|
*/
|
2020-06-03 10:17:29 +02:00
|
|
|
private scrollVertical(speed): void {
|
2019-02-19 09:49:19 +01:00
|
|
|
if (!(this.inScrollZone && this.mousedown)) {
|
|
|
|
return;
|
|
|
|
}
|
2019-03-01 22:34:08 +01:00
|
|
|
const lastOffset = window.pageYOffset;
|
2020-06-03 10:17:29 +02:00
|
|
|
|
2019-02-19 09:49:19 +01:00
|
|
|
window.scrollBy(0, speed);
|
2019-03-01 22:34:08 +01:00
|
|
|
this.mouseY += window.pageYOffset - lastOffset;
|
2019-02-19 09:49:19 +01:00
|
|
|
setTimeout(() => {
|
|
|
|
this.scrollVertical(speed);
|
|
|
|
}, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handles the change in the rectangle and its effect
|
2020-06-03 10:17:29 +02:00
|
|
|
*
|
|
|
|
* @param {MouseEvent} event - mouse event
|
2019-02-19 09:49:19 +01:00
|
|
|
*/
|
2020-06-03 10:17:29 +02:00
|
|
|
private changingRectangle(event): void {
|
2019-02-19 09:49:19 +01:00
|
|
|
if (!this.mousedown) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (event.pageY !== undefined) {
|
|
|
|
this.mouseX = event.pageX;
|
|
|
|
this.mouseY = event.pageY;
|
|
|
|
}
|
|
|
|
|
2020-06-03 10:17:29 +02:00
|
|
|
const { rightPos, leftPos, index } = this.genInfoForMouseSelection();
|
2019-02-19 09:49:19 +01:00
|
|
|
// There is not new block in selection
|
|
|
|
|
|
|
|
const rectIsOnRighSideOfredactor = this.startX > rightPos && this.mouseX > rightPos;
|
|
|
|
const rectISOnLeftSideOfRedactor = this.startX < leftPos && this.mouseX < leftPos;
|
2020-06-03 10:17:29 +02:00
|
|
|
|
2019-02-19 09:49:19 +01:00
|
|
|
this.rectCrossesBlocks = !(rectIsOnRighSideOfredactor || rectISOnLeftSideOfRedactor);
|
|
|
|
|
|
|
|
if (!this.isRectSelectionActivated) {
|
|
|
|
this.rectCrossesBlocks = false;
|
|
|
|
this.isRectSelectionActivated = true;
|
|
|
|
this.shrinkRectangleToPoint();
|
|
|
|
this.overlayRectangle.style.display = 'block';
|
|
|
|
}
|
|
|
|
|
|
|
|
this.updateRectangleSize();
|
|
|
|
|
|
|
|
if (index === undefined) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.trySelectNextBlock(index);
|
|
|
|
// For case, when rect is out from blocks
|
|
|
|
this.inverseSelection();
|
|
|
|
|
|
|
|
SelectionUtils.get().removeAllRanges();
|
|
|
|
event.preventDefault();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Shrink rect to singular point
|
|
|
|
*/
|
2020-06-03 10:17:29 +02:00
|
|
|
private shrinkRectangleToPoint(): void {
|
2019-02-19 09:49:19 +01:00
|
|
|
this.overlayRectangle.style.left = `${this.startX - window.pageXOffset}px`;
|
|
|
|
this.overlayRectangle.style.top = `${this.startY - window.pageYOffset}px`;
|
|
|
|
this.overlayRectangle.style.bottom = `calc(100% - ${this.startY - window.pageYOffset}px`;
|
|
|
|
this.overlayRectangle.style.right = `calc(100% - ${this.startX - window.pageXOffset}px`;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Select or unselect all of blocks in array if rect is out or in selectable area
|
|
|
|
*/
|
2020-06-03 10:17:29 +02:00
|
|
|
private inverseSelection(): void {
|
2019-02-19 09:49:19 +01:00
|
|
|
const firstBlockInStack = this.Editor.BlockManager.getBlockByIndex(this.stackOfSelected[0]);
|
2020-06-03 10:17:29 +02:00
|
|
|
const isSelectedMode = firstBlockInStack.selected;
|
2019-02-19 09:49:19 +01:00
|
|
|
|
2020-06-03 10:17:29 +02:00
|
|
|
if (this.rectCrossesBlocks && !isSelectedMode) {
|
2019-03-01 22:34:08 +01:00
|
|
|
for (const it of this.stackOfSelected) {
|
|
|
|
this.Editor.BlockSelection.selectBlockByIndex(it);
|
2019-02-19 09:49:19 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-03 10:17:29 +02:00
|
|
|
if (!this.rectCrossesBlocks && isSelectedMode) {
|
2019-03-01 22:34:08 +01:00
|
|
|
for (const it of this.stackOfSelected) {
|
|
|
|
this.Editor.BlockSelection.unSelectBlockByIndex(it);
|
2019-02-19 09:49:19 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Updates size of rectangle
|
|
|
|
*/
|
2020-06-03 10:17:29 +02:00
|
|
|
private updateRectangleSize(): void {
|
2019-02-19 09:49:19 +01:00
|
|
|
// Depending on the position of the mouse relative to the starting point,
|
|
|
|
// change this.e distance from the desired edge of the screen*/
|
|
|
|
if (this.mouseY >= this.startY) {
|
|
|
|
this.overlayRectangle.style.top = `${this.startY - window.pageYOffset}px`;
|
|
|
|
this.overlayRectangle.style.bottom = `calc(100% - ${this.mouseY - window.pageYOffset}px`;
|
|
|
|
} else {
|
|
|
|
this.overlayRectangle.style.bottom = `calc(100% - ${this.startY - window.pageYOffset}px`;
|
|
|
|
this.overlayRectangle.style.top = `${this.mouseY - window.pageYOffset}px`;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.mouseX >= this.startX) {
|
|
|
|
this.overlayRectangle.style.left = `${this.startX - window.pageXOffset}px`;
|
|
|
|
this.overlayRectangle.style.right = `calc(100% - ${this.mouseX - window.pageXOffset}px`;
|
|
|
|
} else {
|
|
|
|
this.overlayRectangle.style.right = `calc(100% - ${this.startX - window.pageXOffset}px`;
|
|
|
|
this.overlayRectangle.style.left = `${this.mouseX - window.pageXOffset}px`;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Collects information needed to determine the behavior of the rectangle
|
2020-06-03 10:17:29 +02:00
|
|
|
*
|
|
|
|
* @returns {object} index - index next Block, leftPos - start of left border of Block, rightPos - right border
|
2019-02-19 09:49:19 +01:00
|
|
|
*/
|
2020-06-03 10:17:29 +02:00
|
|
|
private genInfoForMouseSelection(): {index: number; leftPos: number; rightPos: number} {
|
2019-02-19 09:49:19 +01:00
|
|
|
const widthOfRedactor = document.body.offsetWidth;
|
|
|
|
const centerOfRedactor = widthOfRedactor / 2;
|
2019-03-01 22:34:08 +01:00
|
|
|
const Y = this.mouseY - window.pageYOffset;
|
2019-02-19 09:49:19 +01:00
|
|
|
const elementUnderMouse = document.elementFromPoint(centerOfRedactor, Y);
|
|
|
|
const blockInCurrentPos = this.Editor.BlockManager.getBlockByChildNode(elementUnderMouse);
|
|
|
|
let index;
|
2020-06-03 10:17:29 +02:00
|
|
|
|
2019-02-19 09:49:19 +01:00
|
|
|
if (blockInCurrentPos !== undefined) {
|
|
|
|
index = this.Editor.BlockManager.blocks.findIndex((block) => block.holder === blockInCurrentPos.holder);
|
|
|
|
}
|
|
|
|
const contentElement = this.Editor.BlockManager.lastBlock.holder.querySelector('.' + Block.CSS.content);
|
|
|
|
const centerOfBlock = Number.parseInt(window.getComputedStyle(contentElement).width, 10) / 2;
|
|
|
|
const leftPos = centerOfRedactor - centerOfBlock;
|
|
|
|
const rightPos = centerOfRedactor + centerOfBlock;
|
|
|
|
|
|
|
|
return {
|
|
|
|
index,
|
|
|
|
leftPos,
|
|
|
|
rightPos,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Select block with index index
|
2020-06-03 10:17:29 +02:00
|
|
|
*
|
2019-02-19 09:49:19 +01:00
|
|
|
* @param index - index of block in redactor
|
|
|
|
*/
|
2020-06-03 10:17:29 +02:00
|
|
|
private addBlockInSelection(index): void {
|
2019-02-19 09:49:19 +01:00
|
|
|
if (this.rectCrossesBlocks) {
|
|
|
|
this.Editor.BlockSelection.selectBlockByIndex(index);
|
|
|
|
}
|
|
|
|
this.stackOfSelected.push(index);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds a block to the selection and determines which blocks should be selected
|
2020-06-03 10:17:29 +02:00
|
|
|
*
|
2019-02-19 09:49:19 +01:00
|
|
|
* @param {object} index - index of new block in the reactor
|
|
|
|
*/
|
2020-06-03 10:17:29 +02:00
|
|
|
private trySelectNextBlock(index): void {
|
2019-02-19 09:49:19 +01:00
|
|
|
const sameBlock = this.stackOfSelected[this.stackOfSelected.length - 1] === index;
|
|
|
|
const sizeStack = this.stackOfSelected.length;
|
|
|
|
const down = 1, up = -1, undef = 0;
|
|
|
|
|
|
|
|
if (sameBlock) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const blockNumbersIncrease = this.stackOfSelected[sizeStack - 1] - this.stackOfSelected[sizeStack - 2] > 0;
|
2020-06-03 10:17:29 +02:00
|
|
|
|
|
|
|
let direction = undef;
|
|
|
|
|
|
|
|
if (sizeStack > 1) {
|
|
|
|
direction = blockNumbersIncrease ? down : up;
|
|
|
|
}
|
|
|
|
|
|
|
|
const selectionInDownDirection = index > this.stackOfSelected[sizeStack - 1] && direction === down;
|
2019-02-19 09:49:19 +01:00
|
|
|
const selectionInUpDirection = index < this.stackOfSelected[sizeStack - 1] && direction === up;
|
2020-06-03 10:17:29 +02:00
|
|
|
const generalSelection = selectionInDownDirection || selectionInUpDirection || direction === undef;
|
2019-02-19 09:49:19 +01:00
|
|
|
const reduction = !generalSelection;
|
|
|
|
|
|
|
|
// When the selection is too fast, some blocks do not have time to be noticed. Fix it.
|
2019-03-01 22:34:08 +01:00
|
|
|
if (!reduction && (index > this.stackOfSelected[sizeStack - 1] ||
|
|
|
|
this.stackOfSelected[sizeStack - 1] === undefined)) {
|
|
|
|
let ind = this.stackOfSelected[sizeStack - 1] + 1 || index;
|
2019-02-19 09:49:19 +01:00
|
|
|
|
2019-03-01 22:34:08 +01:00
|
|
|
for (ind; ind <= index; ind++) {
|
|
|
|
this.addBlockInSelection(ind);
|
2019-02-19 09:49:19 +01:00
|
|
|
}
|
2020-06-03 10:17:29 +02:00
|
|
|
|
2019-02-19 09:49:19 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// for both directions
|
|
|
|
if (!reduction && (index < this.stackOfSelected[sizeStack - 1])) {
|
2019-03-01 22:34:08 +01:00
|
|
|
for (let ind = this.stackOfSelected[sizeStack - 1] - 1; ind >= index; ind--) {
|
|
|
|
this.addBlockInSelection(ind);
|
2019-02-19 09:49:19 +01:00
|
|
|
}
|
2020-06-03 10:17:29 +02:00
|
|
|
|
2019-02-19 09:49:19 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!reduction) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let i = sizeStack - 1;
|
|
|
|
let cmp;
|
|
|
|
|
|
|
|
// cmp for different directions
|
|
|
|
if (index > this.stackOfSelected[sizeStack - 1]) {
|
2020-06-03 10:17:29 +02:00
|
|
|
cmp = (): boolean => index > this.stackOfSelected[i];
|
2019-02-19 09:49:19 +01:00
|
|
|
} else {
|
2020-06-03 10:17:29 +02:00
|
|
|
cmp = (): boolean => index < this.stackOfSelected[i];
|
2019-02-19 09:49:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Remove blocks missed due to speed.
|
|
|
|
// cmp checks if we have removed all the necessary blocks
|
|
|
|
while (cmp()) {
|
|
|
|
if (this.rectCrossesBlocks) {
|
|
|
|
this.Editor.BlockSelection.unSelectBlockByIndex(this.stackOfSelected[i]);
|
|
|
|
}
|
|
|
|
this.stackOfSelected.pop();
|
|
|
|
i--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|