-
Notifications
You must be signed in to change notification settings - Fork 320
Expand file tree
/
Copy pathhotkeys.element.js
More file actions
71 lines (60 loc) · 2.3 KB
/
hotkeys.element.js
File metadata and controls
71 lines (60 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import $ from 'blingblingjs'
import hotkeys from 'hotkeys-js'
import { metaKey } from '../../utilities/'
import { GuidesHotkeys } from './guides.element'
import { InspectorHotkeys } from './inspector.element'
import { AccessibilityHotkeys } from './accessibility.element'
import { MoveHotkeys } from './move.element'
import { MarginHotkeys } from './margin.element'
import { PaddingHotkeys } from './padding.element'
import { AlignHotkeys } from './align.element'
import { HueshiftHotkeys } from './hueshift.element'
import { BoxshadowHotkeys } from './boxshadow.element'
import { PositionHotkeys } from './position.element'
import { FontHotkeys } from './font.element'
import { TextHotkeys } from './text.element'
import { SearchHotkeys } from './search.element'
import { undoLastEvent, redoLastEvent } from '../../features/history'
export class Hotkeys extends HTMLElement {
constructor() {
super()
this.tool_map = {
guides: document.createElement('hotkeys-guides'),
inspector: document.createElement('hotkeys-inspector'),
accessibility: document.createElement('hotkeys-accessibility'),
move: document.createElement('hotkeys-move'),
margin: document.createElement('hotkeys-margin'),
padding: document.createElement('hotkeys-padding'),
align: document.createElement('hotkeys-align'),
hueshift: document.createElement('hotkeys-hueshift'),
boxshadow: document.createElement('hotkeys-boxshadow'),
position: document.createElement('hotkeys-position'),
font: document.createElement('hotkeys-font'),
text: document.createElement('hotkeys-text'),
search: document.createElement('hotkeys-search'),
}
Object.values(this.tool_map).forEach(tool =>
this.appendChild(tool))
}
connectedCallback() {
hotkeys('shift+/', e =>
this.cur_tool
? this.hideTool()
: this.showTool())
hotkeys('esc', e => this.hideTool())
hotkeys(`${metaKey}+z`, (e) => undoLastEvent());
hotkeys(`${metaKey}+shift+z`, (e) => redoLastEvent());
}
disconnectedCallback() { }
hideTool() {
if (!this.cur_tool) return
this.cur_tool.hide()
this.cur_tool = null
}
showTool() {
this.cur_tool = this.tool_map[
$('vis-bug')[0].activeTool]
this.cur_tool.show()
}
}
customElements.define('visbug-hotkeys', Hotkeys)