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