@operato/input 1.0.0-alpha.6 → 1.0.0-beta.0
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 +420 -0
- package/README.md +9 -6
- package/assets/images/icon-editor-gradient-direction.png +0 -0
- package/assets/images/icon-properties-label.png +0 -0
- package/assets/images/icon-properties-line-type.png +0 -0
- package/assets/images/icon-properties-table.png +0 -0
- package/demo/index-color-gradient.html +35 -0
- package/demo/index-color-stops.html +62 -0
- package/demo/index-color.html +35 -0
- package/demo/index-crontab.html +37 -0
- package/demo/index-multiple-colors.html +37 -0
- package/demo/index-partition-keys.html +71 -0
- package/demo/index-select.html +21 -14
- package/demo/index-table.html +39 -0
- package/demo/index-value-map.html +80 -0
- package/demo/index-value-ranges.html +80 -0
- package/demo/index-work-shift.html +59 -0
- package/demo/index.html +14 -0
- package/dist/src/index.d.ts +21 -11
- package/dist/src/index.js +21 -11
- package/dist/src/index.js.map +1 -1
- package/dist/src/ox-checkbox.d.ts +1 -1
- package/dist/src/ox-checkbox.js +1 -1
- package/dist/src/ox-checkbox.js.map +1 -1
- package/dist/src/ox-form-field.d.ts +2 -2
- package/dist/src/ox-form-field.js.map +1 -1
- package/dist/src/ox-input-barcode.d.ts +1 -1
- package/dist/src/ox-input-barcode.js +1 -1
- package/dist/src/ox-input-barcode.js.map +1 -1
- package/dist/src/ox-input-code.d.ts +4 -4
- package/dist/src/ox-input-code.js +8 -8
- package/dist/src/ox-input-code.js.map +1 -1
- package/dist/src/ox-input-color-gradient.d.ts +26 -0
- package/dist/src/ox-input-color-gradient.js +318 -0
- package/dist/src/ox-input-color-gradient.js.map +1 -0
- package/dist/src/ox-input-color-stops.d.ts +71 -0
- package/dist/src/ox-input-color-stops.js +445 -0
- package/dist/src/ox-input-color-stops.js.map +1 -0
- package/dist/src/ox-input-color.d.ts +176 -0
- package/dist/src/ox-input-color.js +298 -0
- package/dist/src/ox-input-color.js.map +1 -0
- package/dist/src/ox-input-crontab.d.ts +23 -0
- package/dist/src/ox-input-crontab.js +560 -0
- package/dist/src/ox-input-crontab.js.map +1 -0
- package/dist/src/ox-input-data.d.ts +1 -1
- package/dist/src/ox-input-data.js +1 -1
- package/dist/src/ox-input-data.js.map +1 -1
- package/dist/src/ox-input-layout/ox-input-card-layout.d.ts +4 -0
- package/dist/src/ox-input-layout/ox-input-card-layout.js +57 -0
- package/dist/src/ox-input-layout/ox-input-card-layout.js.map +1 -0
- package/dist/src/ox-input-layout/ox-input-grid-layout.d.ts +4 -0
- package/dist/src/ox-input-layout/ox-input-grid-layout.js +63 -0
- package/dist/src/ox-input-layout/ox-input-grid-layout.js.map +1 -0
- package/dist/src/ox-input-layout/ox-input-layout.d.ts +5 -0
- package/dist/src/ox-input-layout/ox-input-layout.js +73 -0
- package/dist/src/ox-input-layout/ox-input-layout.js.map +1 -0
- package/dist/src/ox-input-multiple-colors.d.ts +28 -0
- package/dist/src/ox-input-multiple-colors.js +113 -0
- package/dist/src/ox-input-multiple-colors.js.map +1 -0
- package/dist/src/ox-input-options.js.map +1 -1
- package/dist/src/ox-input-partition-keys.d.ts +36 -0
- package/dist/src/ox-input-partition-keys.js +204 -0
- package/dist/src/ox-input-partition-keys.js.map +1 -0
- package/dist/src/{ox-input-id.d.ts → ox-input-scene-component-id.d.ts} +0 -0
- package/dist/src/{ox-input-id.js → ox-input-scene-component-id.js} +2 -2
- package/dist/src/ox-input-scene-component-id.js.map +1 -0
- package/dist/src/ox-input-search.d.ts +1 -0
- package/dist/src/ox-input-search.js +7 -1
- package/dist/src/ox-input-search.js.map +1 -1
- package/dist/src/ox-input-stack.d.ts +1 -1
- package/dist/src/ox-input-stack.js +1 -1
- package/dist/src/ox-input-stack.js.map +1 -1
- package/dist/src/ox-input-table.d.ts +8 -0
- package/dist/src/ox-input-table.js +379 -0
- package/dist/src/ox-input-table.js.map +1 -0
- package/dist/src/ox-input-value-map.d.ts +41 -0
- package/dist/src/ox-input-value-map.js +279 -0
- package/dist/src/ox-input-value-map.js.map +1 -0
- package/dist/src/ox-input-value-ranges.d.ts +41 -0
- package/dist/src/ox-input-value-ranges.js +298 -0
- package/dist/src/ox-input-value-ranges.js.map +1 -0
- package/dist/src/ox-input-work-shift.d.ts +33 -0
- package/dist/src/ox-input-work-shift.js +229 -0
- package/dist/src/ox-input-work-shift.js.map +1 -0
- package/dist/src/ox-select.d.ts +3 -0
- package/dist/src/ox-select.js +28 -3
- package/dist/src/ox-select.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +24 -7
- package/src/index.ts +21 -11
- package/src/ox-checkbox.ts +2 -2
- package/src/ox-form-field.ts +2 -2
- package/src/ox-input-barcode.ts +2 -3
- package/src/ox-input-code.ts +9 -10
- package/src/ox-input-color-gradient.ts +343 -0
- package/src/ox-input-color-stops.ts +499 -0
- package/src/ox-input-color.ts +323 -0
- package/src/ox-input-crontab.ts +561 -0
- package/src/ox-input-data.ts +2 -2
- package/src/ox-input-layout/ox-input-card-layout.ts +58 -0
- package/src/ox-input-layout/ox-input-grid-layout.ts +64 -0
- package/src/ox-input-layout/ox-input-layout.ts +77 -0
- package/src/ox-input-multiple-colors.ts +113 -0
- package/src/ox-input-options.ts +1 -1
- package/src/ox-input-partition-keys.ts +243 -0
- package/src/{ox-input-id.ts → ox-input-scene-component-id.ts} +1 -1
- package/src/ox-input-search.ts +9 -1
- package/src/ox-input-stack.ts +1 -1
- package/src/ox-input-table.ts +404 -0
- package/src/{ox-input-keyvalues.ts.ing → ox-input-value-map.ts} +125 -94
- package/src/ox-input-value-ranges.ts +325 -0
- package/src/ox-input-work-shift.ts +251 -0
- package/src/ox-select.ts +31 -5
- package/translations/en.json +1 -0
- package/translations/ko.json +1 -0
- package/translations/ms.json +1 -0
- package/translations/zh.json +1 -0
- package/dist/src/ox-input-id.js.map +0 -1
- package/src/ox-input-ranges.ts.ing +0 -292
@@ -2,11 +2,16 @@
|
|
2
2
|
* @license Copyright © HatioLab Inc. All rights reserved.
|
3
3
|
*/
|
4
4
|
|
5
|
-
import './
|
5
|
+
import './ox-input-color'
|
6
6
|
|
7
|
-
import {
|
7
|
+
import { css, html } from 'lit'
|
8
8
|
import { customElement, property } from 'lit/decorators.js'
|
9
9
|
|
10
|
+
import { OxFormField } from './ox-form-field'
|
11
|
+
|
12
|
+
type ValueMap = { default?: any; [key: string]: any }
|
13
|
+
type ArrayedValueMap = { key: string; value: any }
|
14
|
+
|
10
15
|
/**
|
11
16
|
key-value map editor element
|
12
17
|
|
@@ -18,67 +23,67 @@ Example:
|
|
18
23
|
valuetype=${valuetype}>
|
19
24
|
</ox-input-value-map>
|
20
25
|
*/
|
21
|
-
@customElement('ox-input-
|
22
|
-
export
|
23
|
-
static styles =
|
24
|
-
|
25
|
-
:
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
}
|
26
|
+
@customElement('ox-input-value-map')
|
27
|
+
export class OxInputValueMap extends OxFormField {
|
28
|
+
static styles = css`
|
29
|
+
:host {
|
30
|
+
display: flex;
|
31
|
+
flex-direction: column;
|
32
|
+
align-content: center;
|
33
|
+
|
34
|
+
width: 100%;
|
35
|
+
overflow: hidden;
|
36
|
+
border: 1px solid #ccc;
|
37
|
+
}
|
34
38
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
+
div {
|
40
|
+
display: flex;
|
41
|
+
flex-flow: row nowrap;
|
42
|
+
align-items: center;
|
39
43
|
|
40
|
-
|
41
|
-
|
44
|
+
border-bottom: 1px solid #c0c0c0;
|
45
|
+
}
|
42
46
|
|
43
|
-
|
44
|
-
|
45
|
-
|
47
|
+
div:last-child {
|
48
|
+
border-bottom: none;
|
49
|
+
}
|
46
50
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
51
|
+
div > * {
|
52
|
+
min-width: 0px;
|
53
|
+
margin: 2px;
|
54
|
+
padding: 0;
|
55
|
+
}
|
52
56
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
+
button {
|
58
|
+
width: 20px;
|
59
|
+
text-align: center;
|
60
|
+
}
|
57
61
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
+
input,
|
63
|
+
ox-input-color {
|
64
|
+
flex: 1;
|
65
|
+
}
|
62
66
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
}
|
67
|
-
--things-editor-color-input-span: {
|
68
|
-
width: 10px;
|
69
|
-
height: 10px;
|
70
|
-
}
|
67
|
+
ox-input-color {
|
68
|
+
--ox-input-color-input-color: {
|
69
|
+
margin: 1px;
|
71
70
|
}
|
72
|
-
|
73
|
-
|
74
|
-
|
71
|
+
--ox-input-color-input-span: {
|
72
|
+
width: 10px;
|
73
|
+
height: 10px;
|
75
74
|
}
|
76
|
-
|
77
|
-
|
75
|
+
}
|
76
|
+
|
77
|
+
input[type='checkbox'] {
|
78
|
+
width: initial;
|
79
|
+
}
|
80
|
+
`
|
78
81
|
|
79
|
-
@property({ type: Object }) value:
|
80
|
-
@property({ type:
|
81
|
-
@property({ type:
|
82
|
+
@property({ type: Object }) value: ValueMap = {}
|
83
|
+
@property({ type: String }) valuetype: 'string' | 'boolean' | 'color' | string = 'string'
|
84
|
+
@property({ type: String }) keytype: 'string' | 'boolean' | 'color' | string = 'string'
|
85
|
+
|
86
|
+
private _changingNow: boolean = false
|
82
87
|
|
83
88
|
firstUpdated() {
|
84
89
|
this.renderRoot.addEventListener('change', this._onChange.bind(this))
|
@@ -89,10 +94,11 @@ export default class OxInputValueMap extends LitElement {
|
|
89
94
|
${this._toArray(this.value).map(
|
90
95
|
item => html`
|
91
96
|
<div data-record>
|
92
|
-
<input type="text" data-key placeholder="key" .value=${item.key} />
|
97
|
+
<input type="text" data-key placeholder="key" .value=${item.key} />
|
98
|
+
${this.valuetype == 'boolean'
|
93
99
|
? html` <input type="checkbox" data-value .checked=${item.value} data-value-type=${this.valuetype} /> `
|
94
100
|
: this.valuetype == 'color'
|
95
|
-
? html` <
|
101
|
+
? html` <ox-input-color data-value .value=${item.value} tabindex="-1"> </ox-input-color> `
|
96
102
|
: html`
|
97
103
|
<input
|
98
104
|
type="text"
|
@@ -110,9 +116,9 @@ export default class OxInputValueMap extends LitElement {
|
|
110
116
|
<input type="text" data-key placeholder="key" value="" /> ${this.valuetype == 'boolean'
|
111
117
|
? html` <input type="checkbox" data-value data-value-type=${this.valuetype} /> `
|
112
118
|
: this.valuetype == 'color'
|
113
|
-
? html` <
|
119
|
+
? html` <ox-input-color data-value value="" tabindex="-1" placeholder="value"> </ox-input-color> `
|
114
120
|
: html` <input type="text" data-value placeholder="value" value="" data-value-type=${this.valuetype} /> `}
|
115
|
-
<button class="record-action" @click=${(e: MouseEvent) => this._add(
|
121
|
+
<button class="record-action" @click=${(e: MouseEvent) => this._add()} tabindex="-1">+</button>
|
116
122
|
</div>
|
117
123
|
|
118
124
|
<div data-record>
|
@@ -127,13 +133,13 @@ export default class OxInputValueMap extends LitElement {
|
|
127
133
|
`
|
128
134
|
: this.valuetype == 'color'
|
129
135
|
? html`
|
130
|
-
<
|
136
|
+
<ox-input-color
|
131
137
|
data-value
|
132
138
|
.value=${(this.value && this.value.default) || ''}
|
133
139
|
placeholder="value"
|
134
140
|
tabindex="-1"
|
135
141
|
>
|
136
|
-
</
|
142
|
+
</ox-input-color>
|
137
143
|
`
|
138
144
|
: html`
|
139
145
|
<input
|
@@ -143,12 +149,12 @@ export default class OxInputValueMap extends LitElement {
|
|
143
149
|
.value=${(this.value && this.value.default) || ''}
|
144
150
|
data-value-type=${this.valuetype}
|
145
151
|
/>
|
146
|
-
`} <button class="record-action" @click=${
|
152
|
+
`} <button class="record-action" @click=${() => this._sort()} tabindex="-1">></button>
|
147
153
|
</div>
|
148
154
|
`
|
149
155
|
}
|
150
156
|
|
151
|
-
_defaultValue(type) {
|
157
|
+
_defaultValue(type?: 'string' | 'boolean' | 'color' | string) {
|
152
158
|
switch (type || this.valuetype) {
|
153
159
|
case 'color':
|
154
160
|
return '#000000'
|
@@ -160,63 +166,86 @@ export default class OxInputValueMap extends LitElement {
|
|
160
166
|
}
|
161
167
|
}
|
162
168
|
|
163
|
-
_onChange(e) {
|
169
|
+
_onChange(e: Event) {
|
164
170
|
if (this._changingNow) {
|
165
171
|
return
|
166
172
|
}
|
167
173
|
|
168
174
|
this._changingNow = true
|
169
175
|
|
170
|
-
|
176
|
+
const input = e.target as HTMLInputElement
|
171
177
|
var value
|
172
178
|
|
173
|
-
if (input.type == 'checkbox')
|
174
|
-
|
179
|
+
if (input.type == 'checkbox') {
|
180
|
+
value = Boolean(input.checked)
|
181
|
+
} else {
|
182
|
+
value = input.value
|
183
|
+
}
|
175
184
|
|
176
|
-
|
185
|
+
const div = input.parentElement as HTMLDivElement
|
177
186
|
|
178
187
|
if (div.hasAttribute('data-record')) {
|
179
|
-
var dataList = div.querySelectorAll('[data-value]:not([hidden])')
|
180
|
-
|
181
|
-
|
188
|
+
var dataList = div.querySelectorAll('[data-value]:not([hidden])') as NodeListOf<HTMLElement & { value: any }>
|
189
|
+
|
190
|
+
for (var i = 0; i < dataList.length; i++) {
|
191
|
+
if (dataList[i] !== input) {
|
192
|
+
dataList[i].value = value || this._defaultValue()
|
193
|
+
}
|
194
|
+
}
|
182
195
|
}
|
183
196
|
|
184
|
-
if (div.hasAttribute('data-record'))
|
185
|
-
|
197
|
+
if (div.hasAttribute('data-record')) {
|
198
|
+
this._build()
|
199
|
+
} else if (div.hasAttribute('data-record-new') && input.hasAttribute('data-value')) {
|
200
|
+
this._add()
|
201
|
+
}
|
186
202
|
|
187
203
|
this._changingNow = false
|
188
204
|
}
|
189
205
|
|
190
206
|
_build(includeNewRecord?: boolean) {
|
191
|
-
if (includeNewRecord)
|
192
|
-
|
207
|
+
if (includeNewRecord) {
|
208
|
+
var records = this.renderRoot.querySelectorAll('[data-record],[data-record-new]') as NodeListOf<HTMLElement>
|
209
|
+
} else {
|
210
|
+
var records = this.renderRoot.querySelectorAll('[data-record]') as NodeListOf<HTMLElement>
|
211
|
+
}
|
193
212
|
|
194
|
-
var newmap = {}
|
213
|
+
var newmap: ValueMap = {}
|
195
214
|
|
196
215
|
for (var i = 0; i < records.length; i++) {
|
197
216
|
var record = records[i]
|
198
217
|
|
199
|
-
|
200
|
-
|
201
|
-
|
218
|
+
const key = (record.querySelector('[data-key]') as HTMLInputElement).value
|
219
|
+
const inputs = record.querySelectorAll('[data-value]:not([style*="display: none"])') as NodeListOf<
|
220
|
+
HTMLInputElement & { value: any }
|
221
|
+
>
|
222
|
+
|
223
|
+
if (!inputs || inputs.length == 0) {
|
224
|
+
continue
|
225
|
+
}
|
202
226
|
|
203
227
|
var input = inputs[inputs.length - 1]
|
204
228
|
|
205
229
|
var value
|
206
230
|
|
207
|
-
if (input.type == 'checkbox')
|
208
|
-
|
231
|
+
if (input.type == 'checkbox') {
|
232
|
+
value = Boolean(input.checked)
|
233
|
+
} else {
|
234
|
+
value = input.value
|
235
|
+
}
|
209
236
|
|
210
|
-
if (key)
|
237
|
+
if (key) {
|
238
|
+
newmap[key] = value || this._defaultValue()
|
239
|
+
}
|
211
240
|
}
|
212
241
|
|
213
242
|
this.value = newmap
|
214
|
-
this.dispatchEvent(new CustomEvent('change', { bubbles: true, composed: true }))
|
243
|
+
this.dispatchEvent(new CustomEvent('change', { bubbles: true, composed: true, detail: this.value }))
|
215
244
|
}
|
216
245
|
|
217
246
|
/* default를 제외한 map아이템들을 template(dom-repeat)용 배열로 변환하는 함수 */
|
218
|
-
_toArray(map) {
|
219
|
-
var array = []
|
247
|
+
_toArray(map: ValueMap) {
|
248
|
+
var array: ArrayedValueMap[] = []
|
220
249
|
|
221
250
|
for (var key in map) {
|
222
251
|
if (key == 'default') continue
|
@@ -229,14 +258,14 @@ export default class OxInputValueMap extends LitElement {
|
|
229
258
|
return array
|
230
259
|
}
|
231
260
|
|
232
|
-
_sort(
|
233
|
-
|
261
|
+
_sort() {
|
262
|
+
const sorter =
|
234
263
|
this.keytype === 'number'
|
235
|
-
? function (a, b) {
|
236
|
-
return parseFloat(b.key) < parseFloat(a.key)
|
264
|
+
? function (a: ArrayedValueMap, b: ArrayedValueMap) {
|
265
|
+
return parseFloat(b.key) < parseFloat(a.key) ? 1 : -1
|
237
266
|
}
|
238
|
-
: function (a, b) {
|
239
|
-
return b.key < a.key
|
267
|
+
: function (a: ArrayedValueMap, b: ArrayedValueMap) {
|
268
|
+
return b.key < a.key ? 1 : -1
|
240
269
|
}
|
241
270
|
|
242
271
|
var map = this._toArray(this.value)
|
@@ -244,18 +273,20 @@ export default class OxInputValueMap extends LitElement {
|
|
244
273
|
.reduce(function (sum, i) {
|
245
274
|
sum[i.key] = i.value
|
246
275
|
return sum
|
247
|
-
}, {})
|
276
|
+
}, {} as ValueMap)
|
248
277
|
|
249
278
|
map.default = this.value.default
|
250
279
|
|
251
280
|
this.value = map
|
252
|
-
this.dispatchEvent(new CustomEvent('change', { bubbles: true, composed: true }))
|
281
|
+
this.dispatchEvent(new CustomEvent('change', { bubbles: true, composed: true, detail: this.value }))
|
253
282
|
}
|
254
283
|
|
255
|
-
_add(
|
284
|
+
_add() {
|
256
285
|
this._build(true)
|
257
286
|
|
258
|
-
|
287
|
+
const inputs = this.renderRoot.querySelectorAll(
|
288
|
+
'[data-record-new] input:not([style*="display: none"])'
|
289
|
+
) as NodeListOf<HTMLInputElement & { value: any }>
|
259
290
|
|
260
291
|
for (var i = 0; i < inputs.length; i++) {
|
261
292
|
let input = inputs[i]
|
@@ -268,7 +299,7 @@ export default class OxInputValueMap extends LitElement {
|
|
268
299
|
}
|
269
300
|
|
270
301
|
_delete(e: MouseEvent) {
|
271
|
-
|
302
|
+
const record = (e.target as HTMLElement).parentElement
|
272
303
|
|
273
304
|
;(record!.querySelector('[data-key]') as HTMLInputElement)!.value = ''
|
274
305
|
|
@@ -0,0 +1,325 @@
|
|
1
|
+
/**
|
2
|
+
* @license Copyright © HatioLab Inc. All rights reserved.
|
3
|
+
*/
|
4
|
+
|
5
|
+
import './ox-input-color'
|
6
|
+
|
7
|
+
import { css, html } from 'lit'
|
8
|
+
import { customElement, property } from 'lit/decorators.js'
|
9
|
+
|
10
|
+
import { OxFormField } from './ox-form-field.js'
|
11
|
+
|
12
|
+
type ValueRange = { default?: any; [fromto: string]: any }
|
13
|
+
type ArrayedRange = { from: any; to: any; value: any }
|
14
|
+
|
15
|
+
/**
|
16
|
+
range value editor element
|
17
|
+
|
18
|
+
Example:
|
19
|
+
|
20
|
+
<ox-input-value-ranges
|
21
|
+
.value=${range}
|
22
|
+
valuetype=${type}
|
23
|
+
</ox-input-value-ranges>
|
24
|
+
*/
|
25
|
+
|
26
|
+
@customElement('ox-input-value-ranges')
|
27
|
+
export class OxInputValueRange extends OxFormField {
|
28
|
+
static styles = css`
|
29
|
+
:host {
|
30
|
+
display: flex;
|
31
|
+
flex-direction: column;
|
32
|
+
align-content: center;
|
33
|
+
|
34
|
+
width: 100%;
|
35
|
+
overflow: hidden;
|
36
|
+
border: 1px solid #ccc;
|
37
|
+
}
|
38
|
+
|
39
|
+
div {
|
40
|
+
display: flex;
|
41
|
+
flex-flow: row nowrap;
|
42
|
+
align-items: center;
|
43
|
+
|
44
|
+
border-bottom: 1px solid #c0c0c0;
|
45
|
+
}
|
46
|
+
|
47
|
+
div:last-child {
|
48
|
+
border-bottom: none;
|
49
|
+
}
|
50
|
+
|
51
|
+
div > * {
|
52
|
+
min-width: 0px;
|
53
|
+
margin: 2px;
|
54
|
+
padding: 0;
|
55
|
+
}
|
56
|
+
|
57
|
+
button {
|
58
|
+
width: 20px;
|
59
|
+
text-align: center;
|
60
|
+
}
|
61
|
+
|
62
|
+
input,
|
63
|
+
ox-input-color {
|
64
|
+
flex: 1;
|
65
|
+
}
|
66
|
+
|
67
|
+
ox-input-color {
|
68
|
+
--things-editor-color-input-color: {
|
69
|
+
margin: 2px;
|
70
|
+
}
|
71
|
+
--things-editor-color-input-span: {
|
72
|
+
width: 12px;
|
73
|
+
height: 12px;
|
74
|
+
}
|
75
|
+
}
|
76
|
+
|
77
|
+
[placeholder='value'] {
|
78
|
+
flex: 2;
|
79
|
+
}
|
80
|
+
|
81
|
+
div {
|
82
|
+
border-bottom: 1px solid #c0c0c0;
|
83
|
+
}
|
84
|
+
|
85
|
+
div:last-child {
|
86
|
+
border-bottom: none;
|
87
|
+
}
|
88
|
+
|
89
|
+
input[type='checkbox'] {
|
90
|
+
width: initial;
|
91
|
+
}
|
92
|
+
`
|
93
|
+
|
94
|
+
@property({ type: Object }) value: ValueRange = {}
|
95
|
+
@property({ type: String }) valuetype: 'string' | 'boolean' | 'color' | string = 'string'
|
96
|
+
@property({ type: String }) rangetype: 'string' | 'boolean' | 'color' | string = 'number'
|
97
|
+
|
98
|
+
private _changingNow: boolean = false
|
99
|
+
|
100
|
+
firstUpdated() {
|
101
|
+
this.renderRoot.addEventListener('change', this._onChange.bind(this))
|
102
|
+
}
|
103
|
+
|
104
|
+
render() {
|
105
|
+
return html`
|
106
|
+
${this._toArray(this.value).map(
|
107
|
+
item => html`
|
108
|
+
<div data-record>
|
109
|
+
<input type="text" data-from placeholder="<=" .value=${item.from} />
|
110
|
+
<input type="text" data-to placeholder=">" .value=${item.to} />
|
111
|
+
|
112
|
+
${this.valuetype == 'boolean'
|
113
|
+
? html` <input type="checkbox" data-value .checked=${item.value} data-value-type=${this.valuetype} /> `
|
114
|
+
: this.valuetype == 'color'
|
115
|
+
? html` <ox-input-color data-value .value=${item.value}> </ox-input-color> `
|
116
|
+
: html`
|
117
|
+
<input
|
118
|
+
type="text"
|
119
|
+
data-value
|
120
|
+
placeholder="value"
|
121
|
+
.value=${item.value}
|
122
|
+
data-value-type=${this.valuetype}
|
123
|
+
/>
|
124
|
+
`} <button class="record-action" @click=${(e: Event) => this._delete(e)} tabindex="-1">-</button>
|
125
|
+
</div>
|
126
|
+
`
|
127
|
+
)}
|
128
|
+
|
129
|
+
<div data-record-new>
|
130
|
+
<input type="text" data-from placeholder="<=" value="" />
|
131
|
+
<input type="text" data-to placeholder=">" value="" />
|
132
|
+
|
133
|
+
${this.valuetype == 'boolean'
|
134
|
+
? html` <input type="checkbox" data-value data-value-type=${this.valuetype} /> `
|
135
|
+
: this.valuetype == 'color'
|
136
|
+
? html` <ox-input-color data-value value="" placeholder="value"> </ox-input-color> `
|
137
|
+
: html` <input type="text" data-value placeholder="value" value="" data-value-type=${this.valuetype} /> `}
|
138
|
+
<button class="record-action" @click=${(e: Event) => this._add()} tabindex="-1">+</button>
|
139
|
+
</div>
|
140
|
+
|
141
|
+
<div data-record>
|
142
|
+
<input type="text" data-from data-default="" disabled value="default" />
|
143
|
+
<input type="text" data-to placeholder=">" value="" hidden />
|
144
|
+
|
145
|
+
${this.valuetype == 'boolean'
|
146
|
+
? html`
|
147
|
+
<input
|
148
|
+
type="checkbox"
|
149
|
+
data-value
|
150
|
+
.checked=${this.value && this.value.default}
|
151
|
+
data-value-type=${this.valuetype}
|
152
|
+
/>
|
153
|
+
`
|
154
|
+
: this.valuetype == 'color'
|
155
|
+
? html`
|
156
|
+
<ox-input-color data-value .value=${(this.value && this.value.default) || ''} placeholder="value">
|
157
|
+
</ox-input-color>
|
158
|
+
`
|
159
|
+
: html`
|
160
|
+
<input
|
161
|
+
type="text"
|
162
|
+
data-value
|
163
|
+
.value=${(this.value && this.value.default) || ''}
|
164
|
+
placeholder="value"
|
165
|
+
class="default-value"
|
166
|
+
data-value-type=${this.valuetype}
|
167
|
+
/>
|
168
|
+
`} <button class="record-action" @click=${(e: Event) => this._sort()}>></button>
|
169
|
+
</div>
|
170
|
+
`
|
171
|
+
}
|
172
|
+
|
173
|
+
_defaultValue(type: 'color' | 'boolean' | 'checkbox' | string) {
|
174
|
+
switch (type || this.valuetype) {
|
175
|
+
case 'color':
|
176
|
+
return '#000000'
|
177
|
+
case 'boolean':
|
178
|
+
case 'checkbox':
|
179
|
+
return false
|
180
|
+
default:
|
181
|
+
return ''
|
182
|
+
}
|
183
|
+
}
|
184
|
+
|
185
|
+
_onChange(e: Event) {
|
186
|
+
if (this._changingNow) {
|
187
|
+
return
|
188
|
+
}
|
189
|
+
|
190
|
+
this._changingNow = true
|
191
|
+
|
192
|
+
const input = e.target as HTMLInputElement
|
193
|
+
var value = input.type === 'checkbox' ? Boolean(input.checked) : input.value
|
194
|
+
|
195
|
+
const div = input.parentElement as HTMLDivElement
|
196
|
+
if (input.hasAttribute('data-value')) {
|
197
|
+
const dataList = div.querySelectorAll('[data-value]:not([hidden])') as NodeListOf<HTMLElement & { value: any }>
|
198
|
+
|
199
|
+
for (var i = 0; i < dataList.length; i++) {
|
200
|
+
if (dataList[i] !== input) {
|
201
|
+
dataList[i].value = value
|
202
|
+
}
|
203
|
+
}
|
204
|
+
}
|
205
|
+
|
206
|
+
if (div.hasAttribute('data-record')) {
|
207
|
+
this._build()
|
208
|
+
} else if (div.hasAttribute('data-record-new') && input.hasAttribute('data-value')) {
|
209
|
+
this._add()
|
210
|
+
}
|
211
|
+
|
212
|
+
this._changingNow = false
|
213
|
+
}
|
214
|
+
|
215
|
+
_build(includeNewRecord?: boolean) {
|
216
|
+
if (includeNewRecord) {
|
217
|
+
var records = this.renderRoot.querySelectorAll('[data-record],[data-record-new]')
|
218
|
+
} else {
|
219
|
+
var records = this.renderRoot.querySelectorAll('[data-record]')
|
220
|
+
}
|
221
|
+
|
222
|
+
var newrange: ValueRange = {}
|
223
|
+
for (var i = 0; i < records.length; i++) {
|
224
|
+
const record = records[i]
|
225
|
+
const from = (record.querySelector('[data-from]') as HTMLInputElement).value
|
226
|
+
const to = (record.querySelector('[data-to]') as HTMLInputElement).value
|
227
|
+
const inputs = record.querySelectorAll(
|
228
|
+
'[data-value]:not([style*="display: none"])'
|
229
|
+
) as NodeListOf<HTMLInputElement>
|
230
|
+
|
231
|
+
if (!inputs || inputs.length == 0) {
|
232
|
+
continue
|
233
|
+
}
|
234
|
+
|
235
|
+
var input = inputs[inputs.length - 1]
|
236
|
+
var value
|
237
|
+
|
238
|
+
if (input.type == 'checkbox') {
|
239
|
+
value = Boolean(input.checked)
|
240
|
+
} else {
|
241
|
+
value = input.value
|
242
|
+
}
|
243
|
+
|
244
|
+
if (from) {
|
245
|
+
if (from === 'default') newrange['default'] = value || (this.valuetype == 'color' ? '#000000' : '')
|
246
|
+
else newrange[`${from}~${to}`] = value
|
247
|
+
}
|
248
|
+
}
|
249
|
+
|
250
|
+
this.value = newrange
|
251
|
+
|
252
|
+
this.dispatchEvent(new CustomEvent('change', { bubbles: true, composed: true, detail: this.value }))
|
253
|
+
}
|
254
|
+
|
255
|
+
/* default를 제외한 range아이템들을 template(dom-repeat)용 배열로 변환하는 함수 */
|
256
|
+
_toArray(range: ValueRange) {
|
257
|
+
var array: ArrayedRange[] = []
|
258
|
+
|
259
|
+
for (var key in range) {
|
260
|
+
if (key == 'default') {
|
261
|
+
continue
|
262
|
+
}
|
263
|
+
|
264
|
+
const fromto = key.split('~')
|
265
|
+
|
266
|
+
array.push({
|
267
|
+
from: fromto[0],
|
268
|
+
to: fromto[1],
|
269
|
+
value: range[key]
|
270
|
+
})
|
271
|
+
}
|
272
|
+
return array
|
273
|
+
}
|
274
|
+
|
275
|
+
_sort() {
|
276
|
+
const sorter =
|
277
|
+
this.rangetype === 'number'
|
278
|
+
? function (a: ArrayedRange, b: ArrayedRange) {
|
279
|
+
return parseFloat(b.from) < parseFloat(a.from) ? 1 : -1
|
280
|
+
}
|
281
|
+
: function (a: ArrayedRange, b: ArrayedRange) {
|
282
|
+
return b.from < a.from ? 1 : -1
|
283
|
+
}
|
284
|
+
|
285
|
+
var range: ValueRange = this._toArray(this.value)
|
286
|
+
.sort(sorter)
|
287
|
+
.reduce(function (sum, i) {
|
288
|
+
sum[`${i.from}~${i.to}`] = i.value
|
289
|
+
return sum
|
290
|
+
}, {} as ValueRange)
|
291
|
+
range.default = this.value.default
|
292
|
+
|
293
|
+
this.value = range
|
294
|
+
|
295
|
+
this.dispatchEvent(new CustomEvent('change', { bubbles: true, composed: true, detail: this.value }))
|
296
|
+
}
|
297
|
+
|
298
|
+
_add() {
|
299
|
+
this._build(true)
|
300
|
+
|
301
|
+
const inputs = this.renderRoot.querySelectorAll(
|
302
|
+
'[data-record-new] input:not([style*="display: none"])'
|
303
|
+
) as NodeListOf<HTMLInputElement & { value: any; type: string }>
|
304
|
+
|
305
|
+
for (var i = 0; i < inputs.length; i++) {
|
306
|
+
let input = inputs[i]
|
307
|
+
if (input.type == 'checkbox') {
|
308
|
+
input.checked = false
|
309
|
+
} else {
|
310
|
+
input.value = this._defaultValue(input.type)
|
311
|
+
}
|
312
|
+
}
|
313
|
+
|
314
|
+
inputs[0].focus()
|
315
|
+
}
|
316
|
+
|
317
|
+
_delete(e: Event) {
|
318
|
+
const record = (e.target as Element).parentElement
|
319
|
+
|
320
|
+
const dataFrom = record!.querySelector('[data-from]') as HTMLInputElement
|
321
|
+
dataFrom.value = ''
|
322
|
+
|
323
|
+
this._build()
|
324
|
+
}
|
325
|
+
}
|