@operato/input 1.0.0-alpha.5 → 1.0.0-alpha.50
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 +396 -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
@@ -0,0 +1,279 @@
|
|
1
|
+
/**
|
2
|
+
* @license Copyright © HatioLab Inc. All rights reserved.
|
3
|
+
*/
|
4
|
+
import { __decorate } from "tslib";
|
5
|
+
import './ox-input-color';
|
6
|
+
import { css, html } from 'lit';
|
7
|
+
import { customElement, property } from 'lit/decorators.js';
|
8
|
+
import { OxFormField } from './ox-form-field';
|
9
|
+
/**
|
10
|
+
key-value map editor element
|
11
|
+
|
12
|
+
Example:
|
13
|
+
|
14
|
+
<ox-input-value-map
|
15
|
+
value=${map}
|
16
|
+
keytype=${keytype}
|
17
|
+
valuetype=${valuetype}>
|
18
|
+
</ox-input-value-map>
|
19
|
+
*/
|
20
|
+
let OxInputValueMap = class OxInputValueMap extends OxFormField {
|
21
|
+
constructor() {
|
22
|
+
super(...arguments);
|
23
|
+
this.value = {};
|
24
|
+
this.valuetype = 'string';
|
25
|
+
this.keytype = 'string';
|
26
|
+
this._changingNow = false;
|
27
|
+
}
|
28
|
+
static { this.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
|
+
--ox-input-color-input-color: {
|
69
|
+
margin: 1px;
|
70
|
+
}
|
71
|
+
--ox-input-color-input-span: {
|
72
|
+
width: 10px;
|
73
|
+
height: 10px;
|
74
|
+
}
|
75
|
+
}
|
76
|
+
|
77
|
+
input[type='checkbox'] {
|
78
|
+
width: initial;
|
79
|
+
}
|
80
|
+
`; }
|
81
|
+
firstUpdated() {
|
82
|
+
this.renderRoot.addEventListener('change', this._onChange.bind(this));
|
83
|
+
}
|
84
|
+
render() {
|
85
|
+
return html `
|
86
|
+
${this._toArray(this.value).map(item => html `
|
87
|
+
<div data-record>
|
88
|
+
<input type="text" data-key placeholder="key" .value=${item.key} />
|
89
|
+
${this.valuetype == 'boolean'
|
90
|
+
? html ` <input type="checkbox" data-value .checked=${item.value} data-value-type=${this.valuetype} /> `
|
91
|
+
: this.valuetype == 'color'
|
92
|
+
? html ` <ox-input-color data-value .value=${item.value} tabindex="-1"> </ox-input-color> `
|
93
|
+
: html `
|
94
|
+
<input
|
95
|
+
type="text"
|
96
|
+
data-value
|
97
|
+
placeholder="value"
|
98
|
+
.value=${item.value}
|
99
|
+
data-value-type=${this.valuetype}
|
100
|
+
/>
|
101
|
+
`} <button class="record-action" @click=${(e) => this._delete(e)} tabindex="-1">-</button>
|
102
|
+
</div>
|
103
|
+
`)}
|
104
|
+
|
105
|
+
<div data-record-new>
|
106
|
+
<input type="text" data-key placeholder="key" value="" /> ${this.valuetype == 'boolean'
|
107
|
+
? html ` <input type="checkbox" data-value data-value-type=${this.valuetype} /> `
|
108
|
+
: this.valuetype == 'color'
|
109
|
+
? html ` <ox-input-color data-value value="" tabindex="-1" placeholder="value"> </ox-input-color> `
|
110
|
+
: html ` <input type="text" data-value placeholder="value" value="" data-value-type=${this.valuetype} /> `}
|
111
|
+
<button class="record-action" @click=${(e) => this._add()} tabindex="-1">+</button>
|
112
|
+
</div>
|
113
|
+
|
114
|
+
<div data-record>
|
115
|
+
<input type="text" data-key data-default="" value="default" disabled /> ${this.valuetype == 'boolean'
|
116
|
+
? html `
|
117
|
+
<input
|
118
|
+
type="checkbox"
|
119
|
+
data-value
|
120
|
+
.checked=${this.value && this.value.default}
|
121
|
+
data-value-type=${this.valuetype}
|
122
|
+
/>
|
123
|
+
`
|
124
|
+
: this.valuetype == 'color'
|
125
|
+
? html `
|
126
|
+
<ox-input-color
|
127
|
+
data-value
|
128
|
+
.value=${(this.value && this.value.default) || ''}
|
129
|
+
placeholder="value"
|
130
|
+
tabindex="-1"
|
131
|
+
>
|
132
|
+
</ox-input-color>
|
133
|
+
`
|
134
|
+
: html `
|
135
|
+
<input
|
136
|
+
type="text"
|
137
|
+
data-value
|
138
|
+
placeholder="value"
|
139
|
+
.value=${(this.value && this.value.default) || ''}
|
140
|
+
data-value-type=${this.valuetype}
|
141
|
+
/>
|
142
|
+
`} <button class="record-action" @click=${() => this._sort()} tabindex="-1">></button>
|
143
|
+
</div>
|
144
|
+
`;
|
145
|
+
}
|
146
|
+
_defaultValue(type) {
|
147
|
+
switch (type || this.valuetype) {
|
148
|
+
case 'color':
|
149
|
+
return '#000000';
|
150
|
+
case 'boolean':
|
151
|
+
case 'checkbox':
|
152
|
+
return false;
|
153
|
+
default:
|
154
|
+
return '';
|
155
|
+
}
|
156
|
+
}
|
157
|
+
_onChange(e) {
|
158
|
+
if (this._changingNow) {
|
159
|
+
return;
|
160
|
+
}
|
161
|
+
this._changingNow = true;
|
162
|
+
const input = e.target;
|
163
|
+
var value;
|
164
|
+
if (input.type == 'checkbox') {
|
165
|
+
value = Boolean(input.checked);
|
166
|
+
}
|
167
|
+
else {
|
168
|
+
value = input.value;
|
169
|
+
}
|
170
|
+
const div = input.parentElement;
|
171
|
+
if (div.hasAttribute('data-record')) {
|
172
|
+
var dataList = div.querySelectorAll('[data-value]:not([hidden])');
|
173
|
+
for (var i = 0; i < dataList.length; i++) {
|
174
|
+
if (dataList[i] !== input) {
|
175
|
+
dataList[i].value = value || this._defaultValue();
|
176
|
+
}
|
177
|
+
}
|
178
|
+
}
|
179
|
+
if (div.hasAttribute('data-record')) {
|
180
|
+
this._build();
|
181
|
+
}
|
182
|
+
else if (div.hasAttribute('data-record-new') && input.hasAttribute('data-value')) {
|
183
|
+
this._add();
|
184
|
+
}
|
185
|
+
this._changingNow = false;
|
186
|
+
}
|
187
|
+
_build(includeNewRecord) {
|
188
|
+
if (includeNewRecord) {
|
189
|
+
var records = this.renderRoot.querySelectorAll('[data-record],[data-record-new]');
|
190
|
+
}
|
191
|
+
else {
|
192
|
+
var records = this.renderRoot.querySelectorAll('[data-record]');
|
193
|
+
}
|
194
|
+
var newmap = {};
|
195
|
+
for (var i = 0; i < records.length; i++) {
|
196
|
+
var record = records[i];
|
197
|
+
const key = record.querySelector('[data-key]').value;
|
198
|
+
const inputs = record.querySelectorAll('[data-value]:not([style*="display: none"])');
|
199
|
+
if (!inputs || inputs.length == 0) {
|
200
|
+
continue;
|
201
|
+
}
|
202
|
+
var input = inputs[inputs.length - 1];
|
203
|
+
var value;
|
204
|
+
if (input.type == 'checkbox') {
|
205
|
+
value = Boolean(input.checked);
|
206
|
+
}
|
207
|
+
else {
|
208
|
+
value = input.value;
|
209
|
+
}
|
210
|
+
if (key) {
|
211
|
+
newmap[key] = value || this._defaultValue();
|
212
|
+
}
|
213
|
+
}
|
214
|
+
this.value = newmap;
|
215
|
+
this.dispatchEvent(new CustomEvent('change', { bubbles: true, composed: true, detail: this.value }));
|
216
|
+
}
|
217
|
+
/* default를 제외한 map아이템들을 template(dom-repeat)용 배열로 변환하는 함수 */
|
218
|
+
_toArray(map) {
|
219
|
+
var array = [];
|
220
|
+
for (var key in map) {
|
221
|
+
if (key == 'default')
|
222
|
+
continue;
|
223
|
+
array.push({
|
224
|
+
key: key,
|
225
|
+
value: map[key]
|
226
|
+
});
|
227
|
+
}
|
228
|
+
return array;
|
229
|
+
}
|
230
|
+
_sort() {
|
231
|
+
const sorter = this.keytype === 'number'
|
232
|
+
? function (a, b) {
|
233
|
+
return parseFloat(b.key) < parseFloat(a.key) ? 1 : -1;
|
234
|
+
}
|
235
|
+
: function (a, b) {
|
236
|
+
return b.key < a.key ? 1 : -1;
|
237
|
+
};
|
238
|
+
var map = this._toArray(this.value)
|
239
|
+
.sort(sorter)
|
240
|
+
.reduce(function (sum, i) {
|
241
|
+
sum[i.key] = i.value;
|
242
|
+
return sum;
|
243
|
+
}, {});
|
244
|
+
map.default = this.value.default;
|
245
|
+
this.value = map;
|
246
|
+
this.dispatchEvent(new CustomEvent('change', { bubbles: true, composed: true, detail: this.value }));
|
247
|
+
}
|
248
|
+
_add() {
|
249
|
+
this._build(true);
|
250
|
+
const inputs = this.renderRoot.querySelectorAll('[data-record-new] input:not([style*="display: none"])');
|
251
|
+
for (var i = 0; i < inputs.length; i++) {
|
252
|
+
let input = inputs[i];
|
253
|
+
if (input.type == 'checkbox')
|
254
|
+
input.checked = false;
|
255
|
+
else
|
256
|
+
input.value = this._defaultValue(input.type);
|
257
|
+
}
|
258
|
+
inputs[0].focus();
|
259
|
+
}
|
260
|
+
_delete(e) {
|
261
|
+
const record = e.target.parentElement;
|
262
|
+
record.querySelector('[data-key]').value = '';
|
263
|
+
this._build();
|
264
|
+
}
|
265
|
+
};
|
266
|
+
__decorate([
|
267
|
+
property({ type: Object })
|
268
|
+
], OxInputValueMap.prototype, "value", void 0);
|
269
|
+
__decorate([
|
270
|
+
property({ type: String })
|
271
|
+
], OxInputValueMap.prototype, "valuetype", void 0);
|
272
|
+
__decorate([
|
273
|
+
property({ type: String })
|
274
|
+
], OxInputValueMap.prototype, "keytype", void 0);
|
275
|
+
OxInputValueMap = __decorate([
|
276
|
+
customElement('ox-input-value-map')
|
277
|
+
], OxInputValueMap);
|
278
|
+
export { OxInputValueMap };
|
279
|
+
//# sourceMappingURL=ox-input-value-map.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"ox-input-value-map.js","sourceRoot":"","sources":["../../src/ox-input-value-map.ts"],"names":[],"mappings":"AAAA;;GAEG;;AAEH,OAAO,kBAAkB,CAAA;AAEzB,OAAO,EAAE,GAAG,EAAE,IAAI,EA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gB,CAC7C,uDAAuD,CACP,CAAA;QAElD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;YACtC,IAAI,KAAK,GAAG,MAAM,CAAC,CAAC,CAAC,CAAA;YAErB,IAAI,KAAK,CAAC,IAAI,IAAI,UAAU;gBAAE,KAAK,CAAC,OAAO,GAAG,KAAK,CAAA;;gBAC9C,KAAK,CAAC,KAAK,GAAG,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;SAClD;QAED,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,CAAA;IACnB,CAAC;IAED,OAAO,CAAC,CAAa;QACnB,MAAM,MAAM,GAAI,CAAC,CAAC,MAAsB,CAAC,aAAa,CAErD;QAAC,MAAO,CAAC,aAAa,CAAC,YAAY,CAAuB,CAAC,KAAK,GAAG,EAAE,CAAA;QAEtE,IAAI,CAAC,MAAM,EAAE,CAAA;IACf,CAAC;CACF,CAAA;AAlO6B;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;8CAAqB;AACpB;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;kDAA8D;AAC7D;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;gDAA4D;AAzD5E,eAAe;IAD3B,aAAa,CAAC,oBAAoB,CAAC;GACvB,eAAe,CAyR3B;SAzRY,eAAe","sourcesContent":["/**\n * @license Copyright © HatioLab Inc. All rights reserved.\n */\n\nimport './ox-input-color'\n\nimport { css, html } from 'lit'\nimport { customElement, property } from 'lit/decorators.js'\n\nimport { OxFormField } from './ox-form-field'\n\ntype ValueMap = { default?: any; [key: string]: any }\ntype ArrayedValueMap = { key: string; value: any }\n\n/**\nkey-value map editor element\n\nExample:\n\n <ox-input-value-map \n value=${map}\n keytype=${keytype}\n valuetype=${valuetype}>\n </ox-input-value-map>\n*/\n@customElement('ox-input-value-map')\nexport class OxInputValueMap extends OxFormField {\n static styles = css`\n :host {\n display: flex;\n flex-direction: column;\n align-content: center;\n\n width: 100%;\n overflow: hidden;\n border: 1px solid #ccc;\n }\n\n div {\n display: flex;\n flex-flow: row nowrap;\n align-items: center;\n\n border-bottom: 1px solid #c0c0c0;\n }\n\n div:last-child {\n border-bottom: none;\n }\n\n div > * {\n min-width: 0px;\n margin: 2px;\n padding: 0;\n }\n\n button {\n width: 20px;\n text-align: center;\n }\n\n input,\n ox-input-color {\n flex: 1;\n }\n\n ox-input-color {\n --ox-input-color-input-color: {\n margin: 1px;\n }\n --ox-input-color-input-span: {\n width: 10px;\n height: 10px;\n }\n }\n\n input[type='checkbox'] {\n width: initial;\n }\n `\n\n @property({ type: Object }) value: ValueMap = {}\n @property({ type: String }) valuetype: 'string' | 'boolean' | 'color' | string = 'string'\n @property({ type: String }) keytype: 'string' | 'boolean' | 'color' | string = 'string'\n\n private _changingNow: boolean = false\n\n firstUpdated() {\n this.renderRoot.addEventListener('change', this._onChange.bind(this))\n }\n\n render() {\n return html`\n ${this._toArray(this.value).map(\n item => html`\n <div data-record>\n <input type=\"text\" data-key placeholder=\"key\" .value=${item.key} />\n ${this.valuetype == 'boolean'\n ? html` <input type=\"checkbox\" data-value .checked=${item.value} data-value-type=${this.valuetype} /> `\n : this.valuetype == 'color'\n ? html` <ox-input-color data-value .value=${item.value} tabindex=\"-1\"> </ox-input-color> `\n : html`\n <input\n type=\"text\"\n data-value\n placeholder=\"value\"\n .value=${item.value}\n data-value-type=${this.valuetype}\n />\n `} <button class=\"record-action\" @click=${(e: MouseEvent) => this._delete(e)} tabindex=\"-1\">-</button>\n </div>\n `\n )}\n\n <div data-record-new>\n <input type=\"text\" data-key placeholder=\"key\" value=\"\" /> ${this.valuetype == 'boolean'\n ? html` <input type=\"checkbox\" data-value data-value-type=${this.valuetype} /> `\n : this.valuetype == 'color'\n ? html` <ox-input-color data-value value=\"\" tabindex=\"-1\" placeholder=\"value\"> </ox-input-color> `\n : html` <input type=\"text\" data-value placeholder=\"value\" value=\"\" data-value-type=${this.valuetype} /> `}\n <button class=\"record-action\" @click=${(e: MouseEvent) => this._add()} tabindex=\"-1\">+</button>\n </div>\n\n <div data-record>\n <input type=\"text\" data-key data-default=\"\" value=\"default\" disabled /> ${this.valuetype == 'boolean'\n ? html`\n <input\n type=\"checkbox\"\n data-value\n .checked=${this.value && this.value.default}\n data-value-type=${this.valuetype}\n />\n `\n : this.valuetype == 'color'\n ? html`\n <ox-input-color\n data-value\n .value=${(this.value && this.value.default) || ''}\n placeholder=\"value\"\n tabindex=\"-1\"\n >\n </ox-input-color>\n `\n : html`\n <input\n type=\"text\"\n data-value\n placeholder=\"value\"\n .value=${(this.value && this.value.default) || ''}\n data-value-type=${this.valuetype}\n />\n `} <button class=\"record-action\" @click=${() => this._sort()} tabindex=\"-1\">></button>\n </div>\n `\n }\n\n _defaultValue(type?: 'string' | 'boolean' | 'color' | string) {\n switch (type || this.valuetype) {\n case 'color':\n return '#000000'\n case 'boolean':\n case 'checkbox':\n return false\n default:\n return ''\n }\n }\n\n _onChange(e: Event) {\n if (this._changingNow) {\n return\n }\n\n this._changingNow = true\n\n const input = e.target as HTMLInputElement\n var value\n\n if (input.type == 'checkbox') {\n value = Boolean(input.checked)\n } else {\n value = input.value\n }\n\n const div = input.parentElement as HTMLDivElement\n\n if (div.hasAttribute('data-record')) {\n var dataList = div.querySelectorAll('[data-value]:not([hidden])') as NodeListOf<HTMLElement & { value: any }>\n\n for (var i = 0; i < dataList.length; i++) {\n if (dataList[i] !== input) {\n dataList[i].value = value || this._defaultValue()\n }\n }\n }\n\n if (div.hasAttribute('data-record')) {\n this._build()\n } else if (div.hasAttribute('data-record-new') && input.hasAttribute('data-value')) {\n this._add()\n }\n\n this._changingNow = false\n }\n\n _build(includeNewRecord?: boolean) {\n if (includeNewRecord) {\n var records = this.renderRoot.querySelectorAll('[data-record],[data-record-new]') as NodeListOf<HTMLElement>\n } else {\n var records = this.renderRoot.querySelectorAll('[data-record]') as NodeListOf<HTMLElement>\n }\n\n var newmap: ValueMap = {}\n\n for (var i = 0; i < records.length; i++) {\n var record = records[i]\n\n const key = (record.querySelector('[data-key]') as HTMLInputElement).value\n const inputs = record.querySelectorAll('[data-value]:not([style*=\"display: none\"])') as NodeListOf<\n HTMLInputElement & { value: any }\n >\n\n if (!inputs || inputs.length == 0) {\n continue\n }\n\n var input = inputs[inputs.length - 1]\n\n var value\n\n if (input.type == 'checkbox') {\n value = Boolean(input.checked)\n } else {\n value = input.value\n }\n\n if (key) {\n newmap[key] = value || this._defaultValue()\n }\n }\n\n this.value = newmap\n this.dispatchEvent(new CustomEvent('change', { bubbles: true, composed: true, detail: this.value }))\n }\n\n /* default를 제외한 map아이템들을 template(dom-repeat)용 배열로 변환하는 함수 */\n _toArray(map: ValueMap) {\n var array: ArrayedValueMap[] = []\n\n for (var key in map) {\n if (key == 'default') continue\n array.push({\n key: key,\n value: map[key]\n })\n }\n\n return array\n }\n\n _sort() {\n const sorter =\n this.keytype === 'number'\n ? function (a: ArrayedValueMap, b: ArrayedValueMap) {\n return parseFloat(b.key) < parseFloat(a.key) ? 1 : -1\n }\n : function (a: ArrayedValueMap, b: ArrayedValueMap) {\n return b.key < a.key ? 1 : -1\n }\n\n var map = this._toArray(this.value)\n .sort(sorter)\n .reduce(function (sum, i) {\n sum[i.key] = i.value\n return sum\n }, {} as ValueMap)\n\n map.default = this.value.default\n\n this.value = map\n this.dispatchEvent(new CustomEvent('change', { bubbles: true, composed: true, detail: this.value }))\n }\n\n _add() {\n this._build(true)\n\n const inputs = this.renderRoot.querySelectorAll(\n '[data-record-new] input:not([style*=\"display: none\"])'\n ) as NodeListOf<HTMLInputElement & { value: any }>\n\n for (var i = 0; i < inputs.length; i++) {\n let input = inputs[i]\n\n if (input.type == 'checkbox') input.checked = false\n else input.value = this._defaultValue(input.type)\n }\n\n inputs[0].focus()\n }\n\n _delete(e: MouseEvent) {\n const record = (e.target as HTMLElement).parentElement\n\n ;(record!.querySelector('[data-key]') as HTMLInputElement)!.value = ''\n\n this._build()\n }\n}\n"]}
|
@@ -0,0 +1,41 @@
|
|
1
|
+
/**
|
2
|
+
* @license Copyright © HatioLab Inc. All rights reserved.
|
3
|
+
*/
|
4
|
+
import './ox-input-color';
|
5
|
+
import { OxFormField } from './ox-form-field.js';
|
6
|
+
declare type ValueRange = {
|
7
|
+
default?: any;
|
8
|
+
[fromto: string]: any;
|
9
|
+
};
|
10
|
+
declare type ArrayedRange = {
|
11
|
+
from: any;
|
12
|
+
to: any;
|
13
|
+
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
|
+
export declare class OxInputValueRange extends OxFormField {
|
26
|
+
static styles: import("lit").CSSResult;
|
27
|
+
value: ValueRange;
|
28
|
+
valuetype: 'string' | 'boolean' | 'color' | string;
|
29
|
+
rangetype: 'string' | 'boolean' | 'color' | string;
|
30
|
+
private _changingNow;
|
31
|
+
firstUpdated(): void;
|
32
|
+
render(): import("lit-html").TemplateResult<1>;
|
33
|
+
_defaultValue(type: 'color' | 'boolean' | 'checkbox' | string): false | "" | "#000000";
|
34
|
+
_onChange(e: Event): void;
|
35
|
+
_build(includeNewRecord?: boolean): void;
|
36
|
+
_toArray(range: ValueRange): ArrayedRange[];
|
37
|
+
_sort(): void;
|
38
|
+
_add(): void;
|
39
|
+
_delete(e: Event): void;
|
40
|
+
}
|
41
|
+
export {};
|
@@ -0,0 +1,298 @@
|
|
1
|
+
/**
|
2
|
+
* @license Copyright © HatioLab Inc. All rights reserved.
|
3
|
+
*/
|
4
|
+
import { __decorate } from "tslib";
|
5
|
+
import './ox-input-color';
|
6
|
+
import { css, html } from 'lit';
|
7
|
+
import { customElement, property } from 'lit/decorators.js';
|
8
|
+
import { OxFormField } from './ox-form-field.js';
|
9
|
+
/**
|
10
|
+
range value editor element
|
11
|
+
|
12
|
+
Example:
|
13
|
+
|
14
|
+
<ox-input-value-ranges
|
15
|
+
.value=${range}
|
16
|
+
valuetype=${type}
|
17
|
+
</ox-input-value-ranges>
|
18
|
+
*/
|
19
|
+
let OxInputValueRange = class OxInputValueRange extends OxFormField {
|
20
|
+
constructor() {
|
21
|
+
super(...arguments);
|
22
|
+
this.value = {};
|
23
|
+
this.valuetype = 'string';
|
24
|
+
this.rangetype = 'number';
|
25
|
+
this._changingNow = false;
|
26
|
+
}
|
27
|
+
static { this.styles = css `
|
28
|
+
:host {
|
29
|
+
display: flex;
|
30
|
+
flex-direction: column;
|
31
|
+
align-content: center;
|
32
|
+
|
33
|
+
width: 100%;
|
34
|
+
overflow: hidden;
|
35
|
+
border: 1px solid #ccc;
|
36
|
+
}
|
37
|
+
|
38
|
+
div {
|
39
|
+
display: flex;
|
40
|
+
flex-flow: row nowrap;
|
41
|
+
align-items: center;
|
42
|
+
|
43
|
+
border-bottom: 1px solid #c0c0c0;
|
44
|
+
}
|
45
|
+
|
46
|
+
div:last-child {
|
47
|
+
border-bottom: none;
|
48
|
+
}
|
49
|
+
|
50
|
+
div > * {
|
51
|
+
min-width: 0px;
|
52
|
+
margin: 2px;
|
53
|
+
padding: 0;
|
54
|
+
}
|
55
|
+
|
56
|
+
button {
|
57
|
+
width: 20px;
|
58
|
+
text-align: center;
|
59
|
+
}
|
60
|
+
|
61
|
+
input,
|
62
|
+
ox-input-color {
|
63
|
+
flex: 1;
|
64
|
+
}
|
65
|
+
|
66
|
+
ox-input-color {
|
67
|
+
--things-editor-color-input-color: {
|
68
|
+
margin: 2px;
|
69
|
+
}
|
70
|
+
--things-editor-color-input-span: {
|
71
|
+
width: 12px;
|
72
|
+
height: 12px;
|
73
|
+
}
|
74
|
+
}
|
75
|
+
|
76
|
+
[placeholder='value'] {
|
77
|
+
flex: 2;
|
78
|
+
}
|
79
|
+
|
80
|
+
div {
|
81
|
+
border-bottom: 1px solid #c0c0c0;
|
82
|
+
}
|
83
|
+
|
84
|
+
div:last-child {
|
85
|
+
border-bottom: none;
|
86
|
+
}
|
87
|
+
|
88
|
+
input[type='checkbox'] {
|
89
|
+
width: initial;
|
90
|
+
}
|
91
|
+
`; }
|
92
|
+
firstUpdated() {
|
93
|
+
this.renderRoot.addEventListener('change', this._onChange.bind(this));
|
94
|
+
}
|
95
|
+
render() {
|
96
|
+
return html `
|
97
|
+
${this._toArray(this.value).map(item => html `
|
98
|
+
<div data-record>
|
99
|
+
<input type="text" data-from placeholder="<=" .value=${item.from} />
|
100
|
+
<input type="text" data-to placeholder=">" .value=${item.to} />
|
101
|
+
|
102
|
+
${this.valuetype == 'boolean'
|
103
|
+
? html ` <input type="checkbox" data-value .checked=${item.value} data-value-type=${this.valuetype} /> `
|
104
|
+
: this.valuetype == 'color'
|
105
|
+
? html ` <ox-input-color data-value .value=${item.value}> </ox-input-color> `
|
106
|
+
: html `
|
107
|
+
<input
|
108
|
+
type="text"
|
109
|
+
data-value
|
110
|
+
placeholder="value"
|
111
|
+
.value=${item.value}
|
112
|
+
data-value-type=${this.valuetype}
|
113
|
+
/>
|
114
|
+
`} <button class="record-action" @click=${(e) => this._delete(e)} tabindex="-1">-</button>
|
115
|
+
</div>
|
116
|
+
`)}
|
117
|
+
|
118
|
+
<div data-record-new>
|
119
|
+
<input type="text" data-from placeholder="<=" value="" />
|
120
|
+
<input type="text" data-to placeholder=">" value="" />
|
121
|
+
|
122
|
+
${this.valuetype == 'boolean'
|
123
|
+
? html ` <input type="checkbox" data-value data-value-type=${this.valuetype} /> `
|
124
|
+
: this.valuetype == 'color'
|
125
|
+
? html ` <ox-input-color data-value value="" placeholder="value"> </ox-input-color> `
|
126
|
+
: html ` <input type="text" data-value placeholder="value" value="" data-value-type=${this.valuetype} /> `}
|
127
|
+
<button class="record-action" @click=${(e) => this._add()} tabindex="-1">+</button>
|
128
|
+
</div>
|
129
|
+
|
130
|
+
<div data-record>
|
131
|
+
<input type="text" data-from data-default="" disabled value="default" />
|
132
|
+
<input type="text" data-to placeholder=">" value="" hidden />
|
133
|
+
|
134
|
+
${this.valuetype == 'boolean'
|
135
|
+
? html `
|
136
|
+
<input
|
137
|
+
type="checkbox"
|
138
|
+
data-value
|
139
|
+
.checked=${this.value && this.value.default}
|
140
|
+
data-value-type=${this.valuetype}
|
141
|
+
/>
|
142
|
+
`
|
143
|
+
: this.valuetype == 'color'
|
144
|
+
? html `
|
145
|
+
<ox-input-color data-value .value=${(this.value && this.value.default) || ''} placeholder="value">
|
146
|
+
</ox-input-color>
|
147
|
+
`
|
148
|
+
: html `
|
149
|
+
<input
|
150
|
+
type="text"
|
151
|
+
data-value
|
152
|
+
.value=${(this.value && this.value.default) || ''}
|
153
|
+
placeholder="value"
|
154
|
+
class="default-value"
|
155
|
+
data-value-type=${this.valuetype}
|
156
|
+
/>
|
157
|
+
`} <button class="record-action" @click=${(e) => this._sort()}>></button>
|
158
|
+
</div>
|
159
|
+
`;
|
160
|
+
}
|
161
|
+
_defaultValue(type) {
|
162
|
+
switch (type || this.valuetype) {
|
163
|
+
case 'color':
|
164
|
+
return '#000000';
|
165
|
+
case 'boolean':
|
166
|
+
case 'checkbox':
|
167
|
+
return false;
|
168
|
+
default:
|
169
|
+
return '';
|
170
|
+
}
|
171
|
+
}
|
172
|
+
_onChange(e) {
|
173
|
+
if (this._changingNow) {
|
174
|
+
return;
|
175
|
+
}
|
176
|
+
this._changingNow = true;
|
177
|
+
const input = e.target;
|
178
|
+
var value = input.type === 'checkbox' ? Boolean(input.checked) : input.value;
|
179
|
+
const div = input.parentElement;
|
180
|
+
if (input.hasAttribute('data-value')) {
|
181
|
+
const dataList = div.querySelectorAll('[data-value]:not([hidden])');
|
182
|
+
for (var i = 0; i < dataList.length; i++) {
|
183
|
+
if (dataList[i] !== input) {
|
184
|
+
dataList[i].value = value;
|
185
|
+
}
|
186
|
+
}
|
187
|
+
}
|
188
|
+
if (div.hasAttribute('data-record')) {
|
189
|
+
this._build();
|
190
|
+
}
|
191
|
+
else if (div.hasAttribute('data-record-new') && input.hasAttribute('data-value')) {
|
192
|
+
this._add();
|
193
|
+
}
|
194
|
+
this._changingNow = false;
|
195
|
+
}
|
196
|
+
_build(includeNewRecord) {
|
197
|
+
if (includeNewRecord) {
|
198
|
+
var records = this.renderRoot.querySelectorAll('[data-record],[data-record-new]');
|
199
|
+
}
|
200
|
+
else {
|
201
|
+
var records = this.renderRoot.querySelectorAll('[data-record]');
|
202
|
+
}
|
203
|
+
var newrange = {};
|
204
|
+
for (var i = 0; i < records.length; i++) {
|
205
|
+
const record = records[i];
|
206
|
+
const from = record.querySelector('[data-from]').value;
|
207
|
+
const to = record.querySelector('[data-to]').value;
|
208
|
+
const inputs = record.querySelectorAll('[data-value]:not([style*="display: none"])');
|
209
|
+
if (!inputs || inputs.length == 0) {
|
210
|
+
continue;
|
211
|
+
}
|
212
|
+
var input = inputs[inputs.length - 1];
|
213
|
+
var value;
|
214
|
+
if (input.type == 'checkbox') {
|
215
|
+
value = Boolean(input.checked);
|
216
|
+
}
|
217
|
+
else {
|
218
|
+
value = input.value;
|
219
|
+
}
|
220
|
+
if (from) {
|
221
|
+
if (from === 'default')
|
222
|
+
newrange['default'] = value || (this.valuetype == 'color' ? '#000000' : '');
|
223
|
+
else
|
224
|
+
newrange[`${from}~${to}`] = value;
|
225
|
+
}
|
226
|
+
}
|
227
|
+
this.value = newrange;
|
228
|
+
this.dispatchEvent(new CustomEvent('change', { bubbles: true, composed: true, detail: this.value }));
|
229
|
+
}
|
230
|
+
/* default를 제외한 range아이템들을 template(dom-repeat)용 배열로 변환하는 함수 */
|
231
|
+
_toArray(range) {
|
232
|
+
var array = [];
|
233
|
+
for (var key in range) {
|
234
|
+
if (key == 'default') {
|
235
|
+
continue;
|
236
|
+
}
|
237
|
+
const fromto = key.split('~');
|
238
|
+
array.push({
|
239
|
+
from: fromto[0],
|
240
|
+
to: fromto[1],
|
241
|
+
value: range[key]
|
242
|
+
});
|
243
|
+
}
|
244
|
+
return array;
|
245
|
+
}
|
246
|
+
_sort() {
|
247
|
+
const sorter = this.rangetype === 'number'
|
248
|
+
? function (a, b) {
|
249
|
+
return parseFloat(b.from) < parseFloat(a.from) ? 1 : -1;
|
250
|
+
}
|
251
|
+
: function (a, b) {
|
252
|
+
return b.from < a.from ? 1 : -1;
|
253
|
+
};
|
254
|
+
var range = this._toArray(this.value)
|
255
|
+
.sort(sorter)
|
256
|
+
.reduce(function (sum, i) {
|
257
|
+
sum[`${i.from}~${i.to}`] = i.value;
|
258
|
+
return sum;
|
259
|
+
}, {});
|
260
|
+
range.default = this.value.default;
|
261
|
+
this.value = range;
|
262
|
+
this.dispatchEvent(new CustomEvent('change', { bubbles: true, composed: true, detail: this.value }));
|
263
|
+
}
|
264
|
+
_add() {
|
265
|
+
this._build(true);
|
266
|
+
const inputs = this.renderRoot.querySelectorAll('[data-record-new] input:not([style*="display: none"])');
|
267
|
+
for (var i = 0; i < inputs.length; i++) {
|
268
|
+
let input = inputs[i];
|
269
|
+
if (input.type == 'checkbox') {
|
270
|
+
input.checked = false;
|
271
|
+
}
|
272
|
+
else {
|
273
|
+
input.value = this._defaultValue(input.type);
|
274
|
+
}
|
275
|
+
}
|
276
|
+
inputs[0].focus();
|
277
|
+
}
|
278
|
+
_delete(e) {
|
279
|
+
const record = e.target.parentElement;
|
280
|
+
const dataFrom = record.querySelector('[data-from]');
|
281
|
+
dataFrom.value = '';
|
282
|
+
this._build();
|
283
|
+
}
|
284
|
+
};
|
285
|
+
__decorate([
|
286
|
+
property({ type: Object })
|
287
|
+
], OxInputValueRange.prototype, "value", void 0);
|
288
|
+
__decorate([
|
289
|
+
property({ type: String })
|
290
|
+
], OxInputValueRange.prototype, "valuetype", void 0);
|
291
|
+
__decorate([
|
292
|
+
property({ type: String })
|
293
|
+
], OxInputValueRange.prototype, "rangetype", void 0);
|
294
|
+
OxInputValueRange = __decorate([
|
295
|
+
customElement('ox-input-value-ranges')
|
296
|
+
], OxInputValueRange);
|
297
|
+
export { OxInputValueRange };
|
298
|
+
//# sourceMappingURL=ox-input-value-ranges.js.map
|