-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
LeftPanel.js
224 lines (203 loc) · 4.8 KB
/
LeftPanel.js
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
import SvgCanvas from '@svgedit/svgcanvas'
import leftPanelHTML from './LeftPanel.html'
const { $id, $qa, $click } = SvgCanvas
/*
* register actions for left panel
*/
/**
* @type {module}
*/
class LeftPanel {
/**
* @param {PlainObject} editor svgedit handler
*/
constructor (editor) {
this.editor = editor
}
/**
* This is a common function used when a tool has been clicked (chosen).
* It does several common things:
* - Removes the pressed button from whatever tool currently has it.
* - Adds the the pressed button to the button passed in.
* @function this.updateLeftPanel
* @param {string|Element} button The DOM element or string selector representing the toolbar button
* @returns {boolean} Whether the button was disabled or not
*/
updateLeftPanel (button) {
if (button.disabled) return false
// remove the pressed state on other(s) button(s)
$qa('#tools_left *[pressed]').forEach((b) => {
b.pressed = false
})
// pressed state for the clicked button
$id(button).pressed = true
return true
}
/**
* Unless the select toolbar button is disabled, sets the button
* and sets the select mode and cursor styles.
* @function module:SVGEditor.clickSelect
* @returns {void}
*/
clickSelect () {
if (this.updateLeftPanel('tool_select')) {
// this.editor.workarea.style.cursor = 'auto'
this.editor.svgCanvas.setMode('select')
}
}
/**
*
* @returns {void}
*/
clickFHPath () {
if (this.updateLeftPanel('tool_fhpath')) {
this.editor.svgCanvas.setMode('fhpath')
}
}
/**
*
* @returns {void}
*/
clickLine () {
if (this.updateLeftPanel('tool_line')) {
this.editor.svgCanvas.setMode('line')
}
}
/**
*
* @returns {void}
*/
clickSquare () {
if (this.updateLeftPanel('tool_square')) {
this.editor.svgCanvas.setMode('square')
}
}
/**
*
* @returns {void}
*/
clickRect () {
if (this.updateLeftPanel('tool_rect')) {
this.editor.svgCanvas.setMode('rect')
}
}
/**
*
* @returns {void}
*/
clickFHRect () {
if (this.updateLeftPanel('tool_fhrect')) {
this.editor.svgCanvas.setMode('fhrect')
}
}
/**
*
* @returns {void}
*/
clickCircle () {
if (this.updateLeftPanel('tool_circle')) {
this.editor.svgCanvas.setMode('circle')
}
}
/**
*
* @returns {void}
*/
clickEllipse () {
if (this.updateLeftPanel('tool_ellipse')) {
this.editor.svgCanvas.setMode('ellipse')
}
}
/**
*
* @returns {void}
*/
clickFHEllipse () {
if (this.updateLeftPanel('tool_fhellipse')) {
this.editor.svgCanvas.setMode('fhellipse')
}
}
/**
*
* @returns {void}
*/
clickImage () {
if (this.updateLeftPanel('tool_image')) {
this.editor.svgCanvas.setMode('image')
}
}
/**
*
* @returns {void}
*/
clickZoom () {
if (this.updateLeftPanel('tool_zoom')) {
this.editor.svgCanvas.setMode('zoom')
this.editor.workarea.style.cursor = this.editor.zoomInIcon
}
}
/**
*
* @returns {void}
*/
dblclickZoom () {
if (this.updateLeftPanel('tool_zoom')) {
this.editor.zoomImage()
this.clickSelect()
}
}
/**
*
* @returns {void}
*/
clickText () {
if (this.updateLeftPanel('tool_text')) {
this.editor.svgCanvas.setMode('text')
}
}
/**
*
* @returns {void}
*/
clickPath () {
if (this.updateLeftPanel('tool_path')) {
this.editor.svgCanvas.setMode('path')
}
}
/**
* @type {module}
*/
add (id, handler) {
$click($id(id), () => {
if (this.updateLeftPanel(id)) {
handler()
}
})
}
/**
* @type {module}
*/
init () {
// add Left panel
const template = document.createElement('template')
template.innerHTML = leftPanelHTML
this.editor.$svgEditor.append(template.content.cloneNode(true))
// register actions for left panel
$click($id('tool_select'), this.clickSelect.bind(this))
$click($id('tool_fhpath'), this.clickFHPath.bind(this))
$click($id('tool_text'), this.clickText.bind(this))
$click($id('tool_image'), this.clickImage.bind(this))
$click($id('tool_zoom'), this.clickZoom.bind(this))
$id('tool_zoom').addEventListener('dblclick', this.dblclickZoom.bind(this))
$click($id('tool_path'), this.clickPath.bind(this))
$click($id('tool_line'), this.clickLine.bind(this))
// flyout
$click($id('tool_rect'), this.clickRect.bind(this))
$click($id('tool_square'), this.clickSquare.bind(this))
$click($id('tool_fhrect'), this.clickFHRect.bind(this))
$click($id('tool_ellipse'), this.clickEllipse.bind(this))
$click($id('tool_circle'), this.clickCircle.bind(this))
$click($id('tool_fhellipse'), this.clickFHEllipse.bind(this))
}
}
export default LeftPanel