Skip to content
This repository was archived by the owner on Feb 6, 2024. It is now read-only.

Commit 8481374

Browse files
Merge pull request #281 from deckgo/debounce
inline-editor: debounce to solve tools appearing on continuing selection
2 parents 356ff66 + 55fccd1 commit 8481374

File tree

12 files changed

+84
-42
lines changed

12 files changed

+84
-42
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
<a name="1.0.0-rc.11"></a>
2+
# [1.0.0-rc.11](https://github.com/deckgo/deckdeckgo/compare/v1.0.0-rc.10...v1.0.0-11) (2019-09-01)
3+
4+
### Web Components
5+
* inline-editor: v1.0.0-rc.1-1 ([CHANGELOG](https://github.com/deckgo/deckdeckgo/blob/master/webcomponents/inline-editor/CHANGELOG.md))
6+
7+
### Others
8+
* utils: v1.0.0-rc.1-1 ([CHANGELOG](https://github.com/deckgo/deckdeckgo/blob/master/webcomponents/utils/CHANGELOG.md))
9+
110
<a name="1.0.0-rc.10"></a>
211
# [1.0.0-rc.10](https://github.com/deckgo/deckdeckgo/compare/v1.0.0-rc.9...v1.0.0-10) (2019-08-30)
312

studio/package-lock.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

studio/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"dependencies": {
1717
"@deckdeckgo/core": "^1.0.0-rc.1",
1818
"@deckdeckgo/highlight-code": "^1.0.0-rc.1",
19-
"@deckdeckgo/inline-editor": "^1.0.0-rc.1",
19+
"@deckdeckgo/inline-editor": "^1.0.0-rc.1-1",
2020
"@deckdeckgo/lazy-img": "^1.0.0-rc.1",
2121
"@deckdeckgo/qrcode": "^1.0.0-rc.1",
2222
"@deckdeckgo/remote": "^1.0.0-rc.1",
@@ -26,7 +26,7 @@
2626
"@deckdeckgo/slide-split": "^1.0.0-rc.1",
2727
"@deckdeckgo/slide-title": "^1.0.0-rc.1",
2828
"@deckdeckgo/slide-youtube": "^1.0.0-rc.1",
29-
"@deckdeckgo/utils": "^1.0.0-rc.1",
29+
"@deckdeckgo/utils": "^1.0.0-rc.1-1",
3030
"@ionic/core": "^4.8.1",
3131
"firebase": "^6.3.5",
3232
"idb-keyval": "^3.2.0",

webcomponents/inline-editor/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
<a name="1.0.0-rc.1-1"></a>
2+
# 1.0.0-rc.1-1 (2019-09-01)
3+
4+
### Fix
5+
6+
* debounce the display of the toolbar (useful in case of dragged selection)
7+
18
<a name="1.0.0-rc.1"></a>
29
# 1.0.0-rc.1 (2019-08-30)
310

webcomponents/inline-editor/package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

webcomponents/inline-editor/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@deckdeckgo/inline-editor",
3-
"version": "1.0.0-rc.1",
3+
"version": "1.0.0-rc.1-1",
44
"description": "A WYSIWYG HTML Inline Editor Web Component",
55
"main": "dist/index.js",
66
"module": "dist/index.mjs",
@@ -22,7 +22,7 @@
2222
"test.watch": "stencil test --spec --e2e --watchAll"
2323
},
2424
"dependencies": {
25-
"@deckdeckgo/utils": "^1.0.0-rc.1"
25+
"@deckdeckgo/utils": "^1.0.0-rc.1-1"
2626
},
2727
"devDependencies": {
2828
"@stencil/core": "^1.3.1",

webcomponents/inline-editor/src/components/inline-editor/deckdeckgo-inline-editor.scss

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
div.deckgo-tools {
22
position: absolute;
33
visibility: hidden;
4+
opacity: 0;
5+
6+
animation: 0s ease 0s 1 normal none running none;
47

58
pointer-events: none;
69

@@ -135,9 +138,8 @@ div.deckgo-tools {
135138
}
136139

137140
&.deckgo-tools-activated {
138-
transition: top 75ms ease-out, left 75ms ease-out;
139-
animation: pop-upwards 180ms forwards linear;
140141
visibility: visible;
142+
opacity: 1;
141143
}
142144

143145
&.deckgo-tools-mobile {

webcomponents/inline-editor/src/components/inline-editor/deckdeckgo-inline-editor.tsx

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {Component, Element, EventEmitter, Listen, Prop, State, Watch, Event, Method, h} from '@stencil/core';
22

3-
import {isMobile, isIOS, unifyEvent} from '@deckdeckgo/utils';
3+
import {isMobile, isIOS, unifyEvent, debounce} from '@deckdeckgo/utils';
44

55
import {DeckdeckgoInlineEditorUtils} from '../../types/inline-editor/deckdeckgo-inline-editor-utils';
66

@@ -79,6 +79,11 @@ export class DeckdeckgoInlineEditor {
7979
@State()
8080
private toolsActivated: boolean = false;
8181

82+
@State()
83+
private displayToolsActivated: boolean = false;
84+
85+
private debounceDisplayToolsActivated: Function;
86+
8287
private selection: Selection = null;
8388

8489
private anchorLink: AnchorLink = null;
@@ -121,6 +126,16 @@ export class DeckdeckgoInlineEditor {
121126
@Prop()
122127
list: boolean = true;
123128

129+
constructor() {
130+
this.resetDisplayToolsActivated();
131+
}
132+
133+
private resetDisplayToolsActivated() {
134+
this.debounceDisplayToolsActivated = debounce(() => {
135+
this.displayToolsActivated = true;
136+
});
137+
}
138+
124139
async componentWillLoad() {
125140
await this.attachListener();
126141
}
@@ -153,8 +168,8 @@ export class DeckdeckgoInlineEditor {
153168
return new Promise<void>((resolve) => {
154169
const listenerElement: HTMLElement | Document = this.attachTo ? this.attachTo : document;
155170
if (listenerElement) {
156-
listenerElement.addEventListener('mousedown', this.mousedown, {passive: true});
157-
listenerElement.addEventListener('touchstart', this.touchstart, {passive: true});
171+
listenerElement.addEventListener('mousedown', this.startSelection, {passive: true});
172+
listenerElement.addEventListener('touchstart', this.startSelection, {passive: true});
158173
}
159174

160175
resolve();
@@ -164,34 +179,28 @@ export class DeckdeckgoInlineEditor {
164179
private detachListener(listenerElement: HTMLElement | Document): Promise<void> {
165180
return new Promise<void>((resolve) => {
166181
if (listenerElement) {
167-
listenerElement.removeEventListener('mousedown', this.mousedown);
168-
listenerElement.removeEventListener('touchstart', this.touchstart);
182+
listenerElement.removeEventListener('mousedown', this.startSelection);
183+
listenerElement.removeEventListener('touchstart', this.startSelection);
169184
}
170185

171186
resolve();
172187
});
173188
}
174189

175-
private mousedown = async ($event: MouseEvent) => {
176-
if (this.toolsActivated) {
177-
await this.resetImageToolbarActions($event);
178-
179-
return;
190+
private startSelection = async ($event: MouseEvent | TouchEvent) => {
191+
if (this.toolbarActions !== ToolbarActions.IMAGE) {
192+
this.anchorEvent = $event;
180193
}
181194

182-
this.anchorEvent = $event;
183-
184-
await this.displayImageActions($event);
185-
};
186-
187-
private touchstart = async ($event: TouchEvent) => {
188195
if (this.toolsActivated) {
189196
await this.resetImageToolbarActions($event);
190197

191198
return;
192199
}
193200

194-
this.anchorEvent = $event;
201+
if (this.toolbarActions === ToolbarActions.IMAGE) {
202+
this.anchorEvent = $event;
203+
}
195204

196205
await this.displayImageActions($event);
197206
};
@@ -411,7 +420,7 @@ export class DeckdeckgoInlineEditor {
411420
return;
412421
}
413422

414-
if(this.iOSTimerScroll > 0) {
423+
if (this.iOSTimerScroll > 0) {
415424
clearTimeout(this.iOSTimerScroll);
416425
}
417426

@@ -610,6 +619,8 @@ export class DeckdeckgoInlineEditor {
610619

611620
await this.setToolsActivated(false);
612621

622+
this.resetDisplayToolsActivated();
623+
613624
this.selection = null;
614625

615626
this.toolbarActions = ToolbarActions.SELECTION;
@@ -858,6 +869,12 @@ export class DeckdeckgoInlineEditor {
858869
return new Promise<void>(async (resolve) => {
859870
this.toolsActivated = activated;
860871

872+
if (activated) {
873+
this.debounceDisplayToolsActivated();
874+
} else {
875+
this.displayToolsActivated = false;
876+
}
877+
861878
if (this.isSticky()) {
862879
this.stickyToolbarActivated.emit(this.toolsActivated);
863880
}
@@ -1020,7 +1037,7 @@ export class DeckdeckgoInlineEditor {
10201037
}
10211038

10221039
render() {
1023-
let classNames: string = this.toolsActivated ? (this.mobile ? 'deckgo-tools deckgo-tools-activated deckgo-tools-mobile' : 'deckgo-tools deckgo-tools-activated') : (this.mobile ? 'deckgo-tools deckgo-tools-mobile' : 'deckgo-tools');
1040+
let classNames: string = this.displayToolsActivated ? (this.mobile ? 'deckgo-tools deckgo-tools-activated deckgo-tools-mobile' : 'deckgo-tools deckgo-tools-activated') : (this.mobile ? 'deckgo-tools deckgo-tools-mobile' : 'deckgo-tools');
10241041

10251042
if (this.isSticky()) {
10261043
classNames += ' deckgo-tools-sticky';

webcomponents/utils/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
<a name="1.0.0-rc.1-1"></a>
2+
# 1.0.0-rc.1-1 (2019-09-01)
3+
4+
* improvate `debounce` typing
5+
16
<a name="1.0.0-rc.1"></a>
27
# 1.0.0-rc.1 (2019-08-30)
38

webcomponents/utils/package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)