@operato/input 1.0.0-alpha.4 → 1.0.0-alpha.42

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.
Files changed (116) hide show
  1. package/CHANGELOG.md +327 -0
  2. package/README.md +9 -6
  3. package/assets/images/icon-editor-gradient-direction.png +0 -0
  4. package/assets/images/icon-properties-label.png +0 -0
  5. package/assets/images/icon-properties-line-type.png +0 -0
  6. package/assets/images/icon-properties-table.png +0 -0
  7. package/demo/index-color-gradient.html +35 -0
  8. package/demo/index-color-stops.html +62 -0
  9. package/demo/index-color.html +35 -0
  10. package/demo/index-crontab.html +36 -0
  11. package/demo/index-file.html +41 -0
  12. package/demo/index-image.html +1 -1
  13. package/demo/index-multiple-colors.html +37 -0
  14. package/demo/index-options.html +43 -0
  15. package/demo/index-partition-keys.html +71 -0
  16. package/demo/index-range.html +40 -0
  17. package/demo/index-select.html +21 -14
  18. package/demo/index-table.html +39 -0
  19. package/demo/index-value-map.html +80 -0
  20. package/demo/index-value-ranges.html +80 -0
  21. package/demo/index.html +23 -54
  22. package/dist/src/index.d.ts +21 -11
  23. package/dist/src/index.js +21 -11
  24. package/dist/src/index.js.map +1 -1
  25. package/dist/src/ox-checkbox.d.ts +1 -1
  26. package/dist/src/ox-checkbox.js +2 -2
  27. package/dist/src/ox-checkbox.js.map +1 -1
  28. package/dist/src/ox-input-code.d.ts +4 -4
  29. package/dist/src/ox-input-code.js +8 -8
  30. package/dist/src/ox-input-code.js.map +1 -1
  31. package/dist/src/ox-input-color-gradient.d.ts +26 -0
  32. package/dist/src/ox-input-color-gradient.js +318 -0
  33. package/dist/src/ox-input-color-gradient.js.map +1 -0
  34. package/dist/src/ox-input-color-stops.d.ts +71 -0
  35. package/dist/src/ox-input-color-stops.js +445 -0
  36. package/dist/src/ox-input-color-stops.js.map +1 -0
  37. package/dist/src/ox-input-color.d.ts +176 -0
  38. package/dist/src/ox-input-color.js +298 -0
  39. package/dist/src/ox-input-color.js.map +1 -0
  40. package/dist/src/ox-input-crontab.d.ts +23 -0
  41. package/dist/src/ox-input-crontab.js +560 -0
  42. package/dist/src/ox-input-crontab.js.map +1 -0
  43. package/dist/src/ox-input-data.d.ts +2 -2
  44. package/dist/src/ox-input-data.js +2 -2
  45. package/dist/src/ox-input-data.js.map +1 -1
  46. package/dist/src/ox-input-file.d.ts +2 -0
  47. package/dist/src/ox-input-file.js +6 -1
  48. package/dist/src/ox-input-file.js.map +1 -1
  49. package/dist/src/ox-input-layout/ox-input-card-layout.d.ts +4 -0
  50. package/dist/src/ox-input-layout/ox-input-card-layout.js +57 -0
  51. package/dist/src/ox-input-layout/ox-input-card-layout.js.map +1 -0
  52. package/dist/src/ox-input-layout/ox-input-grid-layout.d.ts +4 -0
  53. package/dist/src/ox-input-layout/ox-input-grid-layout.js +63 -0
  54. package/dist/src/ox-input-layout/ox-input-grid-layout.js.map +1 -0
  55. package/dist/src/ox-input-layout/ox-input-layout.d.ts +5 -0
  56. package/dist/src/ox-input-layout/ox-input-layout.js +73 -0
  57. package/dist/src/ox-input-layout/ox-input-layout.js.map +1 -0
  58. package/dist/src/ox-input-multiple-colors.d.ts +28 -0
  59. package/dist/src/ox-input-multiple-colors.js +113 -0
  60. package/dist/src/ox-input-multiple-colors.js.map +1 -0
  61. package/dist/src/ox-input-options.d.ts +22 -0
  62. package/dist/src/ox-input-options.js +137 -0
  63. package/dist/src/ox-input-options.js.map +1 -0
  64. package/dist/src/ox-input-partition-keys.d.ts +36 -0
  65. package/dist/src/ox-input-partition-keys.js +204 -0
  66. package/dist/src/ox-input-partition-keys.js.map +1 -0
  67. package/dist/src/ox-input-range.d.ts +4 -0
  68. package/dist/src/ox-input-range.js +161 -0
  69. package/dist/src/ox-input-range.js.map +1 -0
  70. package/dist/src/ox-input-scene-component-id.d.ts +11 -0
  71. package/dist/src/ox-input-scene-component-id.js +68 -0
  72. package/dist/src/ox-input-scene-component-id.js.map +1 -0
  73. package/dist/src/ox-input-stack.d.ts +1 -1
  74. package/dist/src/ox-input-stack.js +1 -1
  75. package/dist/src/ox-input-stack.js.map +1 -1
  76. package/dist/src/ox-input-table.d.ts +8 -0
  77. package/dist/src/ox-input-table.js +379 -0
  78. package/dist/src/ox-input-table.js.map +1 -0
  79. package/dist/src/ox-input-value-map.d.ts +41 -0
  80. package/dist/src/ox-input-value-map.js +279 -0
  81. package/dist/src/ox-input-value-map.js.map +1 -0
  82. package/dist/src/ox-input-value-ranges.d.ts +41 -0
  83. package/dist/src/ox-input-value-ranges.js +298 -0
  84. package/dist/src/ox-input-value-ranges.js.map +1 -0
  85. package/dist/src/ox-select.d.ts +3 -0
  86. package/dist/src/ox-select.js +28 -3
  87. package/dist/src/ox-select.js.map +1 -1
  88. package/dist/tsconfig.tsbuildinfo +1 -1
  89. package/package.json +25 -7
  90. package/src/index.ts +21 -11
  91. package/src/ox-checkbox.ts +3 -3
  92. package/src/ox-input-code.ts +9 -10
  93. package/src/ox-input-color-gradient.ts +343 -0
  94. package/src/ox-input-color-stops.ts +499 -0
  95. package/src/ox-input-color.ts +323 -0
  96. package/src/ox-input-crontab.ts +560 -0
  97. package/src/ox-input-data.ts +5 -5
  98. package/src/ox-input-file.ts +8 -3
  99. package/src/ox-input-layout/ox-input-card-layout.ts +58 -0
  100. package/src/ox-input-layout/ox-input-grid-layout.ts +64 -0
  101. package/src/ox-input-layout/ox-input-layout.ts +77 -0
  102. package/src/ox-input-multiple-colors.ts +113 -0
  103. package/src/ox-input-options.ts +165 -0
  104. package/src/ox-input-partition-keys.ts +243 -0
  105. package/src/ox-input-range.ts +147 -0
  106. package/src/{ox-input-id.ts → ox-input-scene-component-id.ts} +1 -1
  107. package/src/ox-input-stack.ts +1 -1
  108. package/src/ox-input-table.ts +404 -0
  109. package/src/{ox-input-keyvalues.ts.ing → ox-input-value-map.ts} +125 -94
  110. package/src/ox-input-value-ranges.ts +325 -0
  111. package/src/ox-select.ts +31 -5
  112. package/translations/en.json +1 -0
  113. package/translations/ko.json +1 -0
  114. package/translations/ms.json +1 -0
  115. package/translations/zh.json +1 -0
  116. 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 './things-editor-color'
5
+ import './ox-input-color'
6
6
 
7
- import { LitElement, css, html } from 'lit'
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-keyvalues')
22
- export default class OxInputValueMap extends LitElement {
23
- static styles = [
24
- css`
25
- :host {
26
- display: flex;
27
- flex-direction: column;
28
- align-content: center;
29
-
30
- width: 100%;
31
- overflow: hidden;
32
- border: 1px solid #ccc;
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
- div {
36
- display: flex;
37
- flex-flow: row nowrap;
38
- align-items: center;
39
+ div {
40
+ display: flex;
41
+ flex-flow: row nowrap;
42
+ align-items: center;
39
43
 
40
- border-bottom: 1px solid #c0c0c0;
41
- }
44
+ border-bottom: 1px solid #c0c0c0;
45
+ }
42
46
 
43
- div:last-child {
44
- border-bottom: none;
45
- }
47
+ div:last-child {
48
+ border-bottom: none;
49
+ }
46
50
 
47
- div > * {
48
- min-width: 0px;
49
- margin: 2px;
50
- padding: 0;
51
- }
51
+ div > * {
52
+ min-width: 0px;
53
+ margin: 2px;
54
+ padding: 0;
55
+ }
52
56
 
53
- button {
54
- width: 20px;
55
- text-align: center;
56
- }
57
+ button {
58
+ width: 20px;
59
+ text-align: center;
60
+ }
57
61
 
58
- input,
59
- things-editor-color {
60
- flex: 1;
61
- }
62
+ input,
63
+ ox-input-color {
64
+ flex: 1;
65
+ }
62
66
 
63
- things-editor-color {
64
- --things-editor-color-input-color: {
65
- margin: 1px;
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
- input[type='checkbox'] {
74
- width: initial;
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: any = {}
80
- @property({ type: Object }) valuetype: string = 'string'
81
- @property({ type: Object }) keytype: string = 'string'
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} /> ${this.valuetype == 'boolean'
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` <things-editor-color data-value .value=${item.value} tabindex="-1"> </things-editor-color> `
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` <things-editor-color data-value value="" tabindex="-1" placeholder="value"> </things-editor-color> `
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(e)} tabindex="-1">+</button>
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
- <things-editor-color
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
- </things-editor-color>
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=${e => this._sort(e)} tabindex="-1">&gt;</button>
152
+ `} <button class="record-action" @click=${() => this._sort()} tabindex="-1">&gt;</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
- var input = e.target
176
+ const input = e.target as HTMLInputElement
171
177
  var value
172
178
 
173
- if (input.type == 'checkbox') value = Boolean(input.checked)
174
- else value = input.value
179
+ if (input.type == 'checkbox') {
180
+ value = Boolean(input.checked)
181
+ } else {
182
+ value = input.value
183
+ }
175
184
 
176
- var div = input.parentElement
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
- for (var i = 0; i < dataList.length; i++)
181
- if (dataList[i] !== input) dataList[i].value = value || this._defaultValue()
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')) this._build()
185
- else if (div.hasAttribute('data-record-new') && input.hasAttribute('data-value')) this._add()
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) var records = this.renderRoot.querySelectorAll('[data-record],[data-record-new]')
192
- else var records = this.renderRoot.querySelectorAll('[data-record]')
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
- var key = record.querySelector('[data-key]').value
200
- var inputs = record.querySelectorAll('[data-value]:not([style*="display: none"])')
201
- if (!inputs || inputs.length == 0) continue
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') value = Boolean(input.checked)
208
- else value = input.value
231
+ if (input.type == 'checkbox') {
232
+ value = Boolean(input.checked)
233
+ } else {
234
+ value = input.value
235
+ }
209
236
 
210
- if (key) newmap[key] = value || this._defaultValue()
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(e) {
233
- var sorter =
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(e: MouseEvent) {
284
+ _add() {
256
285
  this._build(true)
257
286
 
258
- var inputs = this.renderRoot.querySelectorAll('[data-record-new] input:not([style*="display: none"])')
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
- var record = (e.target as HTMLElement).parentElement
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="&gt;" .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="&gt;" 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="&gt;" 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()}>&gt;</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
+ }