@operato/input 7.1.27 → 7.1.32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +18 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +7 -7
- package/.editorconfig +0 -29
- package/.storybook/main.js +0 -3
- package/.storybook/preview.js +0 -52
- package/.storybook/server.mjs +0 -8
- package/demo/index-3dish.html +0 -38
- package/demo/index-angle.html +0 -36
- package/demo/index-barcode.html +0 -68
- package/demo/index-button-radio.html +0 -42
- package/demo/index-checkbox.html +0 -69
- package/demo/index-code.html +0 -61
- package/demo/index-color-gradient.html +0 -35
- package/demo/index-color-stops.html +0 -62
- package/demo/index-color.html +0 -35
- package/demo/index-crontab.html +0 -37
- package/demo/index-file.html +0 -41
- package/demo/index-image.html +0 -40
- package/demo/index-multiple-colors.html +0 -52
- package/demo/index-options.html +0 -43
- package/demo/index-partition-keys.html +0 -79
- package/demo/index-range.html +0 -40
- package/demo/index-select.html +0 -136
- package/demo/index-stack.html +0 -33
- package/demo/index-table.html +0 -50
- package/demo/index-value-map.html +0 -80
- package/demo/index-value-ranges.html +0 -80
- package/demo/index-work-shift.html +0 -59
- package/demo/index.html +0 -54
- package/src/index.ts +0 -34
- package/src/locale/locale-codes.ts +0 -18
- package/src/locale/locale-picker.ts +0 -43
- package/src/locale/localization.ts +0 -15
- package/src/locales/en.ts +0 -30
- package/src/locales/ko.ts +0 -30
- package/src/locales/ms.ts +0 -30
- package/src/locales/zh.ts +0 -30
- package/src/ox-buttons-radio.ts +0 -140
- package/src/ox-checkbox.ts +0 -181
- package/src/ox-form-field.ts +0 -53
- package/src/ox-input-3axis.ts +0 -77
- package/src/ox-input-3dish.ts +0 -211
- package/src/ox-input-angle.ts +0 -73
- package/src/ox-input-barcode.ts +0 -318
- package/src/ox-input-code.ts +0 -139
- package/src/ox-input-color-gradient.ts +0 -349
- package/src/ox-input-color-stops.ts +0 -525
- package/src/ox-input-color.ts +0 -338
- package/src/ox-input-container.ts +0 -32
- package/src/ox-input-crontab.ts +0 -595
- package/src/ox-input-data.ts +0 -219
- package/src/ox-input-direction.ts +0 -65
- package/src/ox-input-duration.ts +0 -175
- package/src/ox-input-file.ts +0 -209
- package/src/ox-input-hashtags.ts +0 -185
- package/src/ox-input-i18n-label.ts +0 -140
- package/src/ox-input-image.ts +0 -168
- package/src/ox-input-key-values.ts +0 -301
- package/src/ox-input-layout/ox-input-card-layout.ts +0 -58
- package/src/ox-input-layout/ox-input-grid-layout.ts +0 -64
- package/src/ox-input-layout/ox-input-layout.ts +0 -77
- package/src/ox-input-mass-fraction.ts +0 -437
- package/src/ox-input-multiple-colors.ts +0 -135
- package/src/ox-input-options.ts +0 -216
- package/src/ox-input-partition-keys.ts +0 -303
- package/src/ox-input-privilege.ts +0 -163
- package/src/ox-input-quantifier.ts +0 -62
- package/src/ox-input-range.ts +0 -146
- package/src/ox-input-scene-component-id.ts +0 -73
- package/src/ox-input-search.ts +0 -126
- package/src/ox-input-select-buttons.ts +0 -75
- package/src/ox-input-signature.ts +0 -180
- package/src/ox-input-stack.ts +0 -136
- package/src/ox-input-table-column-config.ts +0 -211
- package/src/ox-input-table.ts +0 -404
- package/src/ox-input-textarea.ts +0 -86
- package/src/ox-input-unit-number.ts +0 -354
- package/src/ox-input-value-map.ts +0 -342
- package/src/ox-input-value-ranges.ts +0 -363
- package/src/ox-input-work-shift.ts +0 -290
- package/src/ox-select.ts +0 -219
- package/src/ox-zoomable-image.ts +0 -75
- package/stories/ox-buttons-radio.stories.ts +0 -89
- package/stories/ox-checkbox.stories.ts +0 -111
- package/stories/ox-input-3axis.stories.ts +0 -77
- package/stories/ox-input-3dish.stories.ts +0 -106
- package/stories/ox-input-angle.stories.ts +0 -84
- package/stories/ox-input-barcode.stories.ts +0 -117
- package/stories/ox-input-code.stories.ts +0 -99
- package/stories/ox-input-crontab.stories.ts +0 -82
- package/stories/ox-input-data.stories.ts +0 -82
- package/stories/ox-input-direction.stories.ts +0 -80
- package/stories/ox-input-duration.stories.ts +0 -84
- package/stories/ox-input-file.stories.ts +0 -111
- package/stories/ox-input-hashtags.stories.ts +0 -82
- package/stories/ox-input-i18n-label.stories.ts +0 -103
- package/stories/ox-input-key-values.stories.ts +0 -97
- package/stories/ox-input-mass-fraction.stories.ts +0 -102
- package/stories/ox-input-multiple-colors.stories.ts +0 -72
- package/stories/ox-input-options.stories.ts +0 -80
- package/stories/ox-input-partition-keys.stories.ts +0 -84
- package/stories/ox-input-privilege.stories.ts +0 -108
- package/stories/ox-input-quantifier.stories.ts +0 -80
- package/stories/ox-input-range.stories.ts +0 -89
- package/stories/ox-input-search.stories.ts +0 -91
- package/stories/ox-input-select-buttons.stories.ts +0 -118
- package/stories/ox-input-signature.stories.ts +0 -75
- package/stories/ox-input-table-column-config.stories.ts +0 -109
- package/stories/ox-input-unit.stories.ts +0 -151
- package/stories/ox-input-value-map.stories.ts +0 -92
- package/stories/ox-input-value-ranges.stories.ts +0 -92
- package/stories/ox-input-work-shift.stories.ts +0 -106
- package/stories/ox-select-set-options.stories.ts +0 -208
- package/stories/ox-select.stories.ts +0 -181
- package/tsconfig.json +0 -25
- package/web-dev-server.config.mjs +0 -27
- package/web-test-runner.config.mjs +0 -41
|
@@ -1,525 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright © HatioLab Inc. All rights reserved.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import './ox-input-color'
|
|
6
|
-
|
|
7
|
-
import { PropertyValues, css, html } from 'lit'
|
|
8
|
-
import { customElement, property, query } from 'lit/decorators.js'
|
|
9
|
-
|
|
10
|
-
import { OxFormField } from './ox-form-field'
|
|
11
|
-
import { OxInputColor } from './ox-input-color'
|
|
12
|
-
import deepEquals from 'lodash-es/isEqual'
|
|
13
|
-
|
|
14
|
-
export type ColorStop = {
|
|
15
|
-
color: string
|
|
16
|
-
position: number
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
범위내에서 여러 컬러셋(포지션과 색깔) 배열을 편집하는 컴포넌트이다.
|
|
21
|
-
|
|
22
|
-
미리보기 Bar에서는 gradient나, solid 형태의 컬러셋을 보여준다.
|
|
23
|
-
|
|
24
|
-
새로운 컬러셋을 추가고자 할 때는 미리보기 Bar를 더블클릭한다.
|
|
25
|
-
컬러셋을 제거하고자 할 때는 컬러셋 마커를 아래방향으로 드래깅한다.
|
|
26
|
-
컬러셋의 위치를 옮기고자 할 때는, 컬러셋 마커를 좌우로 드래깅하여 이동시키거나,
|
|
27
|
-
옮기고자하는 컬러셋 마커를 마우스로 선택하고, 포지션 입력 에디터에서 직접 수정한다.
|
|
28
|
-
컬러셋의 색상을 바꾸고자 할 때는, 컬러셋 마커를 더블클릭하여 컬러파레트를 팝업시켜서 색상을 선택하거나, 색상 입력 에디터에서 직접 색상을 수정할 수 있다.
|
|
29
|
-
|
|
30
|
-
Example:
|
|
31
|
-
|
|
32
|
-
<ox-input-color-stops type="gradient" .value=${gradient.colorStops}>
|
|
33
|
-
</ox-input-color-stops>
|
|
34
|
-
*/
|
|
35
|
-
@customElement('ox-input-color-stops')
|
|
36
|
-
export class OxInputColorStops extends OxFormField {
|
|
37
|
-
static styles = css`
|
|
38
|
-
:host {
|
|
39
|
-
display: grid;
|
|
40
|
-
grid-template-columns: repeat(10, 1fr);
|
|
41
|
-
grid-gap: 0;
|
|
42
|
-
grid-auto-rows: minmax(0, auto);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
#color-stops {
|
|
46
|
-
grid-column: 1 / 11;
|
|
47
|
-
grid-row: 1;
|
|
48
|
-
|
|
49
|
-
clear: both;
|
|
50
|
-
margin-bottom: -3px;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
#colorbar {
|
|
54
|
-
width: 95%;
|
|
55
|
-
height: 12px;
|
|
56
|
-
margin: auto;
|
|
57
|
-
margin-bottom: 25px;
|
|
58
|
-
border: 1px solid #ccc;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
#markers {
|
|
62
|
-
position: relative;
|
|
63
|
-
top: 30px;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
#markers div {
|
|
67
|
-
width: 10px;
|
|
68
|
-
height: 10px;
|
|
69
|
-
margin-top: -15px;
|
|
70
|
-
position: absolute;
|
|
71
|
-
border: 2px solid #fff;
|
|
72
|
-
cursor: pointer;
|
|
73
|
-
-webkit-box-shadow: 1px 1px 1px 0px rgba(0, 0, 0, 0.2);
|
|
74
|
-
-moz-box-shadow: 1px 1px 1px 0px rgba(0, 0, 0, 0.2);
|
|
75
|
-
box-shadow: 1px 1px 1px 0px rgba(0, 0, 0, 0.2);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
#markers div::before {
|
|
79
|
-
border-bottom: 6px solid #fff;
|
|
80
|
-
border-left: 7px solid transparent;
|
|
81
|
-
border-right: 7px solid transparent;
|
|
82
|
-
content: '';
|
|
83
|
-
width: 0;
|
|
84
|
-
height: 0;
|
|
85
|
-
left: -2px;
|
|
86
|
-
position: absolute;
|
|
87
|
-
top: -8px;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
#markers div[focused] {
|
|
91
|
-
border-color: var(--things-editor-colorbar-marker-focused-color, #585858);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
#markers div[focused]:before {
|
|
95
|
-
border-bottom: 7px solid var(--things-editor-colorbar-marker-focused-color, #585858);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
.icon-only-label {
|
|
99
|
-
background: url(/assets/images/icon-properties-label.png) no-repeat;
|
|
100
|
-
width: 30px;
|
|
101
|
-
height: 24px;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
.icon-only-label.color {
|
|
105
|
-
grid-column: 1 / 2;
|
|
106
|
-
grid-row: 2;
|
|
107
|
-
|
|
108
|
-
background-position: 70% -498px;
|
|
109
|
-
float: left;
|
|
110
|
-
margin-top: 0;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
.icon-only-label.position {
|
|
114
|
-
grid-column: 7 / 8;
|
|
115
|
-
grid-row: 2;
|
|
116
|
-
|
|
117
|
-
background-position: 70% -797px;
|
|
118
|
-
float: left;
|
|
119
|
-
margin-top: 0;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
ox-input-color {
|
|
123
|
-
grid-column: 2 / 7;
|
|
124
|
-
grid-row: 2;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
input[type='number'] {
|
|
128
|
-
grid-column: 8 / 11;
|
|
129
|
-
grid-row: 2;
|
|
130
|
-
border: 1px solid rgba(0, 0, 0, 0.2);
|
|
131
|
-
}
|
|
132
|
-
`
|
|
133
|
-
|
|
134
|
-
/**
|
|
135
|
-
* `type`은 color-stop bar의 표시 방법을 의미한다.
|
|
136
|
-
* - 'solid' : 컬러스톱위치에서 다음 컬러스톱까지 solid color로 채운다.
|
|
137
|
-
* - 'gradient' : 컬러스톱위치에서 다음 컬러스톱까지 gradient color로 채운다.
|
|
138
|
-
*/
|
|
139
|
-
@property({ type: String }) type: 'solid' | 'gradient' = 'solid'
|
|
140
|
-
/**
|
|
141
|
-
* `min`은 color-stop bar의 위치값 범위의 최소값을 의미한다.
|
|
142
|
-
*/
|
|
143
|
-
@property({ type: Number }) min: number = 0
|
|
144
|
-
/**
|
|
145
|
-
* `max`은 color-stop bar의 위치값 범위의 최대값을 의미한다.
|
|
146
|
-
*/
|
|
147
|
-
@property({ type: Number }) max: number = 1
|
|
148
|
-
/**
|
|
149
|
-
* `value`은 color-stops에 의해 만들어진 color-stop 배열을 유지한다.
|
|
150
|
-
*/
|
|
151
|
-
@property({ type: Array }) value?: ColorStop[]
|
|
152
|
-
@property({ type: Object }) focused: any
|
|
153
|
-
|
|
154
|
-
@query('#colorbar') colorbar!: HTMLElement
|
|
155
|
-
@query('#color-editor') colorEditor!: OxInputColor
|
|
156
|
-
|
|
157
|
-
private _dragImage?: HTMLImageElement
|
|
158
|
-
|
|
159
|
-
connectedCallback() {
|
|
160
|
-
super.connectedCallback()
|
|
161
|
-
|
|
162
|
-
this._dragImage = new Image()
|
|
163
|
-
this._dragImage.src = 'data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw=='
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
firstUpdated() {
|
|
167
|
-
window.addEventListener('resize', () => {
|
|
168
|
-
this.requestUpdate()
|
|
169
|
-
})
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
updated(changes: PropertyValues<this>) {
|
|
173
|
-
var needRerenderColorBar = false
|
|
174
|
-
|
|
175
|
-
if (changes.has('value') && this.value instanceof Array) {
|
|
176
|
-
var oldValue = changes.get('value')
|
|
177
|
-
if (
|
|
178
|
-
this.focused &&
|
|
179
|
-
(!oldValue ||
|
|
180
|
-
this.value.findIndex(v => v.position == this.focused.position && v.color == this.focused.color) == -1)
|
|
181
|
-
) {
|
|
182
|
-
/* 이전 값이 없었던 경우에 focused를 클리어시킨다.
|
|
183
|
-
* 이전 값이 있던 경우에도, focused는 이 에디터 내부에서만 선택될 수 있으며, 수정될 수 있으므로 동일한 포지션을 갖는 value가 없으면, 새로운 에디터가 시작된 것으로 판단하여 focused를 클리어시킨다.
|
|
184
|
-
*/
|
|
185
|
-
this.focused = null
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
if (!deepEquals(oldValue, this.value)) {
|
|
189
|
-
needRerenderColorBar = true
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
if (needRerenderColorBar || changes.has('min') || changes.has('max')) {
|
|
194
|
-
if (!this.value) {
|
|
195
|
-
this.value = [
|
|
196
|
-
{ color: 'white', position: this.min },
|
|
197
|
-
{ color: 'white', position: this.max }
|
|
198
|
-
]
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
this._renderColorBar(this.min, this.max, this.type)
|
|
202
|
-
this.requestUpdate()
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
render() {
|
|
207
|
-
return html`
|
|
208
|
-
<div id="color-stops">
|
|
209
|
-
<div id="colorbar" @dblclick=${(e: MouseEvent) => this._onDblClickColorbar(e)}>
|
|
210
|
-
<div
|
|
211
|
-
id="markers"
|
|
212
|
-
@dblclick=${(e: MouseEvent) => this._onDblClickMarkers(e)}
|
|
213
|
-
@mousedown=${(e: MouseEvent) => this._onMouseDown(e)}
|
|
214
|
-
@dragstart=${(e: DragEvent) => this._onDragStart(e)}
|
|
215
|
-
@drag=${this._throttled(100, this._onDrag.bind(this))}
|
|
216
|
-
@dragend=${(e: DragEvent) => this._onDragEnd(e)}
|
|
217
|
-
>
|
|
218
|
-
${this._refinedValue(this.value).map(
|
|
219
|
-
(item, index) => html`
|
|
220
|
-
<div
|
|
221
|
-
.style="background-color:${item.color};margin-left:${this._calculatePosition(
|
|
222
|
-
item.position,
|
|
223
|
-
this.min,
|
|
224
|
-
this.max
|
|
225
|
-
)}px;"
|
|
226
|
-
marker-index=${index}
|
|
227
|
-
draggable="true"
|
|
228
|
-
></div>
|
|
229
|
-
`
|
|
230
|
-
)}
|
|
231
|
-
</div>
|
|
232
|
-
</div>
|
|
233
|
-
</div>
|
|
234
|
-
|
|
235
|
-
<label class="icon-only-label color"></label>
|
|
236
|
-
<ox-input-color
|
|
237
|
-
id="color-editor"
|
|
238
|
-
.value=${this.focused && this.focused.color}
|
|
239
|
-
@change=${(e: Event) => this._onChangeSubComponent(e)}
|
|
240
|
-
?disabled=${this.disabled}
|
|
241
|
-
>
|
|
242
|
-
</ox-input-color>
|
|
243
|
-
|
|
244
|
-
<label class="icon-only-label position"></label>
|
|
245
|
-
<input
|
|
246
|
-
type="number"
|
|
247
|
-
id="color-position"
|
|
248
|
-
.value=${this.focused && this.focused.position}
|
|
249
|
-
@change=${(e: Event) => this._onChangeSubComponent(e)}
|
|
250
|
-
step="0.01"
|
|
251
|
-
?disabled=${this.disabled}
|
|
252
|
-
/>
|
|
253
|
-
`
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
_refinedValue(value: any) {
|
|
257
|
-
return value instanceof Array ? value : []
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
_setFocused(index: number) {
|
|
261
|
-
if (this.focused && this.focused.index === index) {
|
|
262
|
-
return
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
var marker = this.renderRoot.querySelector(`#markers div[marker-index='${index}']`) as HTMLElement
|
|
266
|
-
var olds = this.renderRoot.querySelectorAll('#markers div[focused]')
|
|
267
|
-
olds.length > 0 && olds.forEach(old => old.removeAttribute('focused'))
|
|
268
|
-
marker && marker.setAttribute('focused', '')
|
|
269
|
-
|
|
270
|
-
if (!marker) {
|
|
271
|
-
this.focused = null
|
|
272
|
-
return
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
var colorStop = this.value![index]
|
|
276
|
-
|
|
277
|
-
this._changeFocused({
|
|
278
|
-
index: index,
|
|
279
|
-
color: colorStop.color,
|
|
280
|
-
position: Math.max(this.min, Math.min(colorStop.position, this.max))
|
|
281
|
-
})
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
_changeFocused(focused: any) {
|
|
285
|
-
if (!focused) {
|
|
286
|
-
this._setFocused(-1) // clear focused marker
|
|
287
|
-
|
|
288
|
-
return
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
this.focused = focused
|
|
292
|
-
|
|
293
|
-
this.value = this.value!.map((colorStop, index): ColorStop => {
|
|
294
|
-
if (index != focused.index) {
|
|
295
|
-
return colorStop
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
return {
|
|
299
|
-
color: focused.color,
|
|
300
|
-
position: focused.position
|
|
301
|
-
}
|
|
302
|
-
}).sort((a: ColorStop, b: ColorStop) => {
|
|
303
|
-
return b.position < a.position ? 1 : -1
|
|
304
|
-
})
|
|
305
|
-
|
|
306
|
-
var colorStop = this.value[focused.index]
|
|
307
|
-
|
|
308
|
-
if (focused.position != colorStop.position || focused.color != colorStop.color) {
|
|
309
|
-
var index = -1
|
|
310
|
-
for (var i = 0; i < this.value.length; i++) {
|
|
311
|
-
colorStop = this.value[i]
|
|
312
|
-
if (focused.position == colorStop.position && focused.color == colorStop.color) {
|
|
313
|
-
index = i
|
|
314
|
-
break
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
this._setFocused(index)
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
_renderColorBar(min: number, max: number, type: 'solid' | 'gradient') {
|
|
323
|
-
var value = this._refinedValue(this.value)
|
|
324
|
-
var gradient = ''
|
|
325
|
-
|
|
326
|
-
if (value instanceof Array && value.length > 0) {
|
|
327
|
-
if (this.type == 'gradient') {
|
|
328
|
-
var stopsStrings = (value || []).map(function (stop) {
|
|
329
|
-
var position = (stop.position - min) / (max - min)
|
|
330
|
-
return `${stop.color} ${position * 100}%`
|
|
331
|
-
})
|
|
332
|
-
} else {
|
|
333
|
-
var stops = value || []
|
|
334
|
-
var last: ColorStop | undefined
|
|
335
|
-
var last_position = 0
|
|
336
|
-
var stopsStrings = stops.map(function (stop) {
|
|
337
|
-
var stop_position = (stop.position - min) / (max - min)
|
|
338
|
-
if (last) {
|
|
339
|
-
last_position = (last.position - min) / (max - min)
|
|
340
|
-
var step = `${stop.color} ${last_position * 100}%, ${stop.color} ${stop_position * 100}%`
|
|
341
|
-
} else {
|
|
342
|
-
var step = `${stop.color} ${stop_position * 100}%`
|
|
343
|
-
}
|
|
344
|
-
last = stop
|
|
345
|
-
return step
|
|
346
|
-
})
|
|
347
|
-
if (last) {
|
|
348
|
-
last_position = (last.position - min) / (max - min)
|
|
349
|
-
stopsStrings.push(`${last.color} ${last_position * 100}%, white ${last_position * 100}%, white 100%`)
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
gradient = stopsStrings.join(',')
|
|
354
|
-
} else {
|
|
355
|
-
gradient = 'black 0%, black 100%'
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
this.colorbar!.style.background = `linear-gradient(to right, ${gradient})`
|
|
359
|
-
/* W3C, IE10+, FF16+, Chrome26+, Opera12+, Safari7+ */
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
_onChangeSubComponent(e: Event) {
|
|
363
|
-
var element = e.target as HTMLInputElement
|
|
364
|
-
var id = element.id
|
|
365
|
-
|
|
366
|
-
if (!this.focused) {
|
|
367
|
-
return
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
switch (id) {
|
|
371
|
-
case 'color-editor':
|
|
372
|
-
this._changeFocused({
|
|
373
|
-
...this.focused,
|
|
374
|
-
color: element.value
|
|
375
|
-
})
|
|
376
|
-
break
|
|
377
|
-
case 'color-position':
|
|
378
|
-
this._changeFocused({
|
|
379
|
-
...this.focused,
|
|
380
|
-
position: Math.max(this.min, Math.min(Number(element.value), this.max))
|
|
381
|
-
})
|
|
382
|
-
break
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
this.dispatchEvent(new CustomEvent('change', { bubbles: true, composed: true }))
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
_onDblClickColorbar(e: MouseEvent) {
|
|
389
|
-
if (this.disabled) {
|
|
390
|
-
return
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
/* 마커를 클릭한 경우를 걸러낸다. */
|
|
394
|
-
if (e.target !== this.colorbar) return
|
|
395
|
-
|
|
396
|
-
var width = this.colorbar.offsetWidth
|
|
397
|
-
var position = this.min + (this.max - this.min) * (e.offsetX / width)
|
|
398
|
-
var colorStops = this.value ? this.value.slice() : []
|
|
399
|
-
|
|
400
|
-
for (var i = 0; i < colorStops.length; i++) {
|
|
401
|
-
if (colorStops[i].position > position) break
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
colorStops.splice(i, 0, {
|
|
405
|
-
position: position,
|
|
406
|
-
color: '#fff'
|
|
407
|
-
})
|
|
408
|
-
|
|
409
|
-
this.value = colorStops
|
|
410
|
-
|
|
411
|
-
this.focused = null
|
|
412
|
-
this._setFocused(i)
|
|
413
|
-
|
|
414
|
-
this.dispatchEvent(new CustomEvent('change', { bubbles: true, composed: true }))
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
_onDblClickMarkers(e: MouseEvent) {
|
|
418
|
-
if (this.disabled) {
|
|
419
|
-
return
|
|
420
|
-
}
|
|
421
|
-
|
|
422
|
-
this.colorEditor.showPicker()
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
_onMouseDown(e: MouseEvent) {
|
|
426
|
-
if (this.disabled) {
|
|
427
|
-
return
|
|
428
|
-
}
|
|
429
|
-
|
|
430
|
-
var marker = e.target as HTMLElement
|
|
431
|
-
var index = marker.getAttribute('marker-index')
|
|
432
|
-
|
|
433
|
-
this._setFocused(Number(index))
|
|
434
|
-
}
|
|
435
|
-
|
|
436
|
-
private dragstart: { position: number; x: number; y: number } = { position: 0, x: 0, y: 0 }
|
|
437
|
-
|
|
438
|
-
_onDragStart(e: DragEvent) {
|
|
439
|
-
if (this.disabled) {
|
|
440
|
-
return
|
|
441
|
-
}
|
|
442
|
-
|
|
443
|
-
/* drag 시에 ghost image를 보이지 않게 하려고 함 */
|
|
444
|
-
e.dataTransfer?.setDragImage(this._dragImage!, 0, 0)
|
|
445
|
-
|
|
446
|
-
this.dragstart = {
|
|
447
|
-
position: this.focused.position,
|
|
448
|
-
x: e.clientX,
|
|
449
|
-
y: e.clientY
|
|
450
|
-
}
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
// TODO onDrag 이벤트가 계속 발생하므로 처리하는 성능 저하됨. 그래서 throttling 하도록 함
|
|
454
|
-
_throttled(delay: number, fn: (...args: any[]) => any) {
|
|
455
|
-
let lastCall = 0
|
|
456
|
-
return function (...args: any[]) {
|
|
457
|
-
const now = new Date().getTime()
|
|
458
|
-
if (now - lastCall < delay) {
|
|
459
|
-
return
|
|
460
|
-
}
|
|
461
|
-
lastCall = now
|
|
462
|
-
return fn(...args)
|
|
463
|
-
}
|
|
464
|
-
}
|
|
465
|
-
|
|
466
|
-
_onDrag(e: DragEvent) {
|
|
467
|
-
if (this.disabled) {
|
|
468
|
-
return
|
|
469
|
-
}
|
|
470
|
-
|
|
471
|
-
if (e.clientX <= 0) {
|
|
472
|
-
return
|
|
473
|
-
}
|
|
474
|
-
|
|
475
|
-
var width = this.colorbar.offsetWidth
|
|
476
|
-
var position = this.dragstart.position + ((e.clientX - this.dragstart.x) / width) * (this.max - this.min)
|
|
477
|
-
|
|
478
|
-
if (position != this.focused.position) {
|
|
479
|
-
this._changeFocused({
|
|
480
|
-
...this.focused,
|
|
481
|
-
position: Math.max(this.min, Math.min(position, this.max))
|
|
482
|
-
})
|
|
483
|
-
|
|
484
|
-
this.dispatchEvent(new CustomEvent('change', { bubbles: true, composed: true }))
|
|
485
|
-
}
|
|
486
|
-
}
|
|
487
|
-
|
|
488
|
-
_onDragEnd(e: DragEvent) {
|
|
489
|
-
if (this.disabled) {
|
|
490
|
-
return
|
|
491
|
-
}
|
|
492
|
-
|
|
493
|
-
if (e.clientY - this.dragstart.y > 40) {
|
|
494
|
-
this.value!.splice(this.focused.index, 1)
|
|
495
|
-
this.value = this.value!.slice()
|
|
496
|
-
|
|
497
|
-
this._setFocused(-1)
|
|
498
|
-
|
|
499
|
-
this.dispatchEvent(new CustomEvent('change', { bubbles: true, composed: true }))
|
|
500
|
-
}
|
|
501
|
-
}
|
|
502
|
-
|
|
503
|
-
_calculatePosition(position: number, min: number, max: number) {
|
|
504
|
-
/* TODO 7 ==> 마커 폭의 절반으로 계산해야함. */
|
|
505
|
-
var calculated = position
|
|
506
|
-
|
|
507
|
-
if (calculated > this.max) calculated = this.max
|
|
508
|
-
else if (calculated < this.min) calculated = this.min
|
|
509
|
-
|
|
510
|
-
var width = (this.colorbar && this.colorbar.offsetWidth) || 0
|
|
511
|
-
|
|
512
|
-
return ((calculated - this.min) / (this.max - this.min)) * width - 7
|
|
513
|
-
}
|
|
514
|
-
|
|
515
|
-
protected appendFormData({ formData }: FormDataEvent): void {
|
|
516
|
-
if (!this.name) return
|
|
517
|
-
|
|
518
|
-
const value = this.value
|
|
519
|
-
|
|
520
|
-
formData.append(
|
|
521
|
-
this.name!,
|
|
522
|
-
typeof value === 'string' ? value : value === undefined || value === null ? '' : JSON.stringify(value)
|
|
523
|
-
)
|
|
524
|
-
}
|
|
525
|
-
}
|