@operato/input 8.0.0-beta.0 → 8.0.0-beta.1

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 (98) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/package.json +7 -7
  3. package/.editorconfig +0 -29
  4. package/.storybook/main.js +0 -3
  5. package/.storybook/preview.js +0 -52
  6. package/.storybook/server.mjs +0 -8
  7. package/src/index.ts +0 -35
  8. package/src/locale/locale-codes.ts +0 -18
  9. package/src/locale/locale-picker.ts +0 -43
  10. package/src/locale/localization.ts +0 -15
  11. package/src/locales/en.ts +0 -30
  12. package/src/locales/ko.ts +0 -30
  13. package/src/locales/ms.ts +0 -30
  14. package/src/locales/zh.ts +0 -30
  15. package/src/ox-buttons-radio.ts +0 -140
  16. package/src/ox-checkbox.ts +0 -181
  17. package/src/ox-form-field.ts +0 -53
  18. package/src/ox-input-3axis.ts +0 -77
  19. package/src/ox-input-3dish.ts +0 -211
  20. package/src/ox-input-angle.ts +0 -73
  21. package/src/ox-input-barcode.ts +0 -318
  22. package/src/ox-input-code.ts +0 -139
  23. package/src/ox-input-color-gradient.ts +0 -349
  24. package/src/ox-input-color-stops.ts +0 -525
  25. package/src/ox-input-color.ts +0 -338
  26. package/src/ox-input-container.ts +0 -32
  27. package/src/ox-input-crontab.ts +0 -595
  28. package/src/ox-input-data.ts +0 -219
  29. package/src/ox-input-direction.ts +0 -92
  30. package/src/ox-input-duration.ts +0 -175
  31. package/src/ox-input-file.ts +0 -209
  32. package/src/ox-input-hashtags.ts +0 -185
  33. package/src/ox-input-i18n-label.ts +0 -140
  34. package/src/ox-input-image.ts +0 -168
  35. package/src/ox-input-key-values.ts +0 -301
  36. package/src/ox-input-layout/ox-input-card-layout.ts +0 -58
  37. package/src/ox-input-layout/ox-input-grid-layout.ts +0 -64
  38. package/src/ox-input-layout/ox-input-layout.ts +0 -77
  39. package/src/ox-input-mass-fraction.ts +0 -437
  40. package/src/ox-input-multiple-colors.ts +0 -135
  41. package/src/ox-input-options.ts +0 -216
  42. package/src/ox-input-partition-keys.ts +0 -303
  43. package/src/ox-input-privilege.ts +0 -163
  44. package/src/ox-input-quantifier.ts +0 -62
  45. package/src/ox-input-range.ts +0 -146
  46. package/src/ox-input-scene-component-id.ts +0 -73
  47. package/src/ox-input-search.ts +0 -126
  48. package/src/ox-input-select-buttons.ts +0 -75
  49. package/src/ox-input-signature.ts +0 -208
  50. package/src/ox-input-stack.ts +0 -136
  51. package/src/ox-input-switch.ts +0 -117
  52. package/src/ox-input-table-column-config.ts +0 -211
  53. package/src/ox-input-table.ts +0 -404
  54. package/src/ox-input-textarea.ts +0 -86
  55. package/src/ox-input-unit-number.ts +0 -354
  56. package/src/ox-input-value-map.ts +0 -342
  57. package/src/ox-input-value-ranges.ts +0 -363
  58. package/src/ox-input-work-shift.ts +0 -290
  59. package/src/ox-select-floor.ts +0 -246
  60. package/src/ox-select.ts +0 -219
  61. package/stories/image-for-select-floor.ts +0 -2
  62. package/stories/ox-buttons-radio.stories.ts +0 -89
  63. package/stories/ox-checkbox.stories.ts +0 -111
  64. package/stories/ox-input-3axis.stories.ts +0 -77
  65. package/stories/ox-input-3dish.stories.ts +0 -106
  66. package/stories/ox-input-angle.stories.ts +0 -84
  67. package/stories/ox-input-barcode.stories.ts +0 -117
  68. package/stories/ox-input-code.stories.ts +0 -99
  69. package/stories/ox-input-crontab.stories.ts +0 -82
  70. package/stories/ox-input-data.stories.ts +0 -82
  71. package/stories/ox-input-direction.stories.ts +0 -91
  72. package/stories/ox-input-duration.stories.ts +0 -84
  73. package/stories/ox-input-file.stories.ts +0 -111
  74. package/stories/ox-input-hashtags.stories.ts +0 -82
  75. package/stories/ox-input-i18n-label.stories.ts +0 -103
  76. package/stories/ox-input-key-values.stories.ts +0 -97
  77. package/stories/ox-input-mass-fraction.stories.ts +0 -102
  78. package/stories/ox-input-multiple-colors.stories.ts +0 -72
  79. package/stories/ox-input-options.stories.ts +0 -80
  80. package/stories/ox-input-partition-keys.stories.ts +0 -84
  81. package/stories/ox-input-privilege.stories.ts +0 -108
  82. package/stories/ox-input-quantifier.stories.ts +0 -80
  83. package/stories/ox-input-range.stories.ts +0 -89
  84. package/stories/ox-input-search.stories.ts +0 -91
  85. package/stories/ox-input-select-buttons.stories.ts +0 -118
  86. package/stories/ox-input-signature.stories.ts +0 -75
  87. package/stories/ox-input-switch.stories.ts +0 -91
  88. package/stories/ox-input-table-column-config.stories.ts +0 -109
  89. package/stories/ox-input-unit.stories.ts +0 -151
  90. package/stories/ox-input-value-map.stories.ts +0 -92
  91. package/stories/ox-input-value-ranges.stories.ts +0 -92
  92. package/stories/ox-input-work-shift.stories.ts +0 -106
  93. package/stories/ox-select-floor.stories.ts +0 -197
  94. package/stories/ox-select-set-options.stories.ts +0 -208
  95. package/stories/ox-select.stories.ts +0 -181
  96. package/tsconfig.json +0 -25
  97. package/web-dev-server.config.mjs +0 -27
  98. package/web-test-runner.config.mjs +0 -41
@@ -1,354 +0,0 @@
1
- /**
2
- * @license Copyright © HatioLab Inc. All rights reserved.
3
- */
4
-
5
- import '@material/web/icon/icon.js'
6
-
7
- import { css, html, PropertyValues } from 'lit'
8
- import { customElement, property, query } from 'lit/decorators.js'
9
- import { ifDefined } from 'lit/directives/if-defined.js'
10
-
11
- import { OxPopupList } from '@operato/popup'
12
-
13
- import { OxFormField } from './ox-form-field'
14
-
15
- const UNIT_SYSTEMS: { [unit: string]: { [unit: string]: number | ((v: number) => number)[] } } = {
16
- kg: {
17
- mg: 1000000,
18
- g: 1000,
19
- ton: 0.001
20
- },
21
- rad: {
22
- degree: 180 / Math.PI
23
- },
24
- sec: {
25
- msec: 1000,
26
- min: 1 / 60,
27
- hr: 1 / 3600,
28
- day: 1 / (3600 * 24),
29
- year: 1 / (3600 * 24 * 365)
30
- },
31
- m: {
32
- mm: 1000,
33
- cm: 100,
34
- inch: 39.37008
35
- },
36
- 'g/mol': {
37
- 'kg/kmol': 1,
38
- 'g/kmol': 1000
39
- },
40
- m2: {
41
- mm2: 1000000,
42
- cm2: 1000
43
- },
44
- m3: {
45
- cm3: 1000000,
46
- L: 1000,
47
- mL: 1000000
48
- },
49
- 'kg/m3': {
50
- 'g/m3': 1000,
51
- 'g/L': 1,
52
- 'g/cm3': 0.001,
53
- 'kg/L': 0.001,
54
- 'g/mL': 0.001
55
- },
56
- 'm/sec': {
57
- 'm/min': 60,
58
- 'm/hr': 3600,
59
- 'cm/sec': 100,
60
- 'cm/min': 6000,
61
- 'cm/hr': 360000
62
- },
63
- N: {
64
- kN: 0.001,
65
- kgf: 0.101971621
66
- },
67
- Pa: {
68
- atm: 1 / 101325,
69
- bar: 1 / 100000,
70
- 'kgf/cm2': 1 / 9.80665 / 10000,
71
- MPa: 1 / 1000000,
72
- kPa: 1 / 1000,
73
- psi: 1 / 6894.76,
74
- mmH2O: 1 / 9.80665,
75
- mmHg: 1 / 133.32
76
- },
77
- 'kg/sec': {
78
- 'kg/min': 60,
79
- 'kg/hr': 3600,
80
- 'ton/hr': 3.6,
81
- 'ton/year': (60 * 60 * 24 * 365) / 1000
82
- },
83
- 'kg/m2/sec': {
84
- 'kg/m2/min': 60,
85
- 'kg/m2/hr': 3600
86
- },
87
- 'mol/sec': {
88
- 'kmol/sec': 1 / 1000
89
- },
90
- 'mol/m2/sec': {
91
- 'kmol/m2/sec': 1 / 1000
92
- },
93
- 'Sm3/sec': {
94
- 'Sm3/hr': 3600,
95
- 'Sm3/min': 60,
96
- 'SL/min': 60000,
97
- 'SL/sec': 1000,
98
- 'Scm3/min': 60000000,
99
- 'Scm3/sec': 1000000
100
- },
101
- 'Nm3/sec': {
102
- 'Nm3/hr': 3600,
103
- 'Nm3/min': 60,
104
- 'NL/min': 60000,
105
- 'NL/sec': 1000,
106
- 'Ncm3/min': 60000000,
107
- 'Ncm3/sec': 1000000
108
- },
109
- 'Am3/sec': {
110
- 'Am3/hr': 3600,
111
- 'Am3/min': 60,
112
- 'AL/min': 60000,
113
- 'AL/sec': 1000,
114
- 'Acm3/min': 60000000,
115
- 'Acm3/sec': 1000000
116
- },
117
- J: {
118
- kJ: 1 / 1000,
119
- MJ: 1 / 1000000,
120
- cal: 1 / 4.184,
121
- kcal: 1 / 4.184 / 1000
122
- },
123
- W: {
124
- kW: 1 / 1000,
125
- MW: 1 / 1000000,
126
- 'kcal/hr': 859.85 / 1000,
127
- hp: 1 / 745.7
128
- },
129
- 'W/m2': {
130
- 'kW/m2': 1 / 1000,
131
- 'W/cm2': 1 / 10000,
132
- 'kW/cm2': 1 / 10000000
133
- },
134
- 'J/kg': {
135
- 'kJ/kg': 1 / 1000,
136
- 'cal/g': 1 / 4.184 / 1000,
137
- 'cal/kg': 1 / 4.184,
138
- 'kcal/kg': 1 / 4.184 / 1000
139
- },
140
- 'J/kg/K': {
141
- 'kJ/kg/K': 1 / 1000,
142
- 'cal/kg/K': 1 / 4.184,
143
- 'kcal/kg/K': 1 / 4.184 / 1000,
144
- 'cal/g/K': 1 / 4.184 / 1000
145
- },
146
- 'W/m/K': {
147
- 'kW/m/K': 1 / 1000,
148
- 'W/cm/K': 1 / 100,
149
- 'kW/cm/K': 1 / 100 / 1000
150
- },
151
- 'W/m2/K': {
152
- 'kW/m2/K': 1 / 1000,
153
- 'kcal/hr/m2/oC': 1 / 1.163
154
- },
155
- 'N sec/m2': {
156
- 'Pa sec': 1,
157
- 'mPa sec': 1000,
158
- 'kg/m/sec': 1,
159
- 'g/cm/sec': 10,
160
- P: 10,
161
- cP: 1000
162
- },
163
- 'm2 oC/W': {
164
- 'm2 oC/kW': 1000
165
- },
166
- '%': {},
167
- ppm: {},
168
- K: {
169
- '°C': [(v: number) => v - 273.15, (v: number) => v + 273.15]
170
- }
171
- }
172
-
173
- @customElement('ox-input-unit-number')
174
- export class OxInputUnitNumber extends OxFormField {
175
- static styles = [
176
- css`
177
- :host {
178
- display: flex;
179
- flex-direction: row;
180
- align-items: center;
181
-
182
- --md-icon-size: var(--fontsize-default, 14px);
183
- }
184
-
185
- input {
186
- flex: 1;
187
- border: 0;
188
- border-bottom: 1px solid rgba(0, 0, 0, 0.15);
189
- padding: var(--spacing-tiny);
190
- font: var(--input-font);
191
- color: var(--md-sys-color-on-primary-container);
192
- min-width: 40px;
193
- }
194
-
195
- input:focus {
196
- outline: none;
197
- border-bottom: 1px solid var(--md-sys-color-on-primary-container);
198
- }
199
-
200
- input::-webkit-outer-spin-button,
201
- input::-webkit-inner-spin-button {
202
- -webkit-appearance: none;
203
- margin: 0;
204
- }
205
-
206
- input[type='number'] {
207
- text-align: right;
208
- -moz-appearance: textfield;
209
- }
210
-
211
- #unit {
212
- flex: 1;
213
- display: flex;
214
- align-items: center;
215
- position: relative;
216
- margin-left: var(--spacing-small);
217
- font: var(--label-font);
218
- color: var(--label-color, var(--md-sys-color-on-surface));
219
- min-width: 24px;
220
- }
221
-
222
- md-icon {
223
- color: var(--md-sys-color-on-primary-container, #3c3938);
224
- margin-left: auto;
225
- }
226
-
227
- ox-popup-list {
228
- right: 0;
229
- }
230
- `
231
- ]
232
-
233
- @property({ type: String }) placeholder?: string
234
- @property({ type: String, attribute: 'std-unit' }) stdUnit!: string
235
- @property({ type: String, attribute: 'user-unit' }) userUnit?: string
236
-
237
- @query('input') input!: HTMLInputElement
238
- @query('ox-popup-list') popup!: OxPopupList
239
-
240
- render() {
241
- const userUnit = this.userUnit || this.stdUnit
242
- const units = (UNIT_SYSTEMS[this.stdUnit] && Object.keys(UNIT_SYSTEMS[this.stdUnit])) || []
243
-
244
- return html`
245
- <input
246
- type="number"
247
- .value=${this._toUserUnit(this.value)}
248
- placeholder=${ifDefined(this.placeholder)}
249
- @change=${(e: Event) => this._onChangeValue(e)}
250
- ?disabled=${this.disabled}
251
- />
252
- <div
253
- id="unit"
254
- @click=${(e: Event) => {
255
- if (this.disabled) {
256
- return
257
- }
258
-
259
- const target = e.currentTarget as HTMLElement
260
- this.popup.open({
261
- right: 0,
262
- top: target.clientTop + target.offsetHeight
263
- })
264
- }}
265
- >
266
- ${userUnit}
267
- <ox-popup-list
268
- .value=${userUnit}
269
- @select=${(e: CustomEvent) => {
270
- this.userUnit = e.detail
271
- this.dispatchEvent(
272
- new CustomEvent('user-unit-change', {
273
- detail: this.userUnit
274
- })
275
- )
276
- }}
277
- >
278
- <div option value=${this.stdUnit}>${this.stdUnit}</div>
279
- ${units.map(unit => html`<div option value=${unit}>${unit}</div>`)}
280
- </ox-popup-list>
281
- <md-icon>expand_more</md-icon>
282
- </div>
283
- `
284
- }
285
-
286
- _onChangeValue(e: Event) {
287
- this.value = this._toStdUnit(this.input.value)
288
-
289
- this.dispatchEvent(
290
- new CustomEvent('change', {
291
- bubbles: true,
292
- composed: true,
293
- detail: this.value
294
- })
295
- )
296
- }
297
-
298
- _toUserUnit(stdValue: string | number | undefined) {
299
- if (!this.userUnit) {
300
- return
301
- }
302
-
303
- if (this.userUnit === this.stdUnit) {
304
- return Number(stdValue)
305
- }
306
-
307
- const converterValue = UNIT_SYSTEMS[this.stdUnit][this.userUnit]
308
-
309
- if (!converterValue) {
310
- delete this.userUnit
311
- return
312
- }
313
-
314
- if (typeof converterValue === 'number') {
315
- return this._toUserUnitByRate(stdValue, converterValue || 1)
316
- } /* should be converter function array */ else {
317
- return this._toUserUnitByFunction(stdValue, converterValue as ((v: number) => number)[])
318
- }
319
- }
320
-
321
- _toUserUnitByRate(stdValue: string | number | undefined, converterRate: number) {
322
- return Number(stdValue) * converterRate
323
- }
324
-
325
- _toUserUnitByFunction(stdValue: string | number | undefined, converterFunctions: ((v: number) => number)[]) {
326
- return converterFunctions[0](Number(stdValue))
327
- }
328
-
329
- _toStdUnit(userValue: string | number | undefined) {
330
- if (!this.userUnit) {
331
- return
332
- }
333
-
334
- if (this.userUnit === this.stdUnit) {
335
- return Number(userValue)
336
- }
337
-
338
- const converterValue = UNIT_SYSTEMS[this.stdUnit][this.userUnit]
339
-
340
- if (typeof converterValue === 'number') {
341
- return this._toStdUnitByRate(userValue, converterValue || 1)
342
- } /* should be converter function array */ else {
343
- return this._toStdUnitByFunction(userValue, converterValue as ((v: number) => number)[])
344
- }
345
- }
346
-
347
- _toStdUnitByRate(userValue: string | number | undefined, converterRate: number) {
348
- return isNaN(Number(userValue)) ? undefined : Number(userValue) / converterRate
349
- }
350
-
351
- _toStdUnitByFunction(userValue: string | number | undefined, converterFunctions: ((v: number) => number)[]) {
352
- return converterFunctions[1](Number(userValue))
353
- }
354
- }
@@ -1,342 +0,0 @@
1
- /**
2
- * @license Copyright © HatioLab Inc. All rights reserved.
3
- */
4
-
5
- import './ox-input-color'
6
-
7
- import { css, html, nothing } from 'lit'
8
- import { customElement, property } from 'lit/decorators.js'
9
- import { keyed } from 'lit/directives/keyed.js'
10
- import { ifDefined } from 'lit/directives/if-defined.js'
11
-
12
- import { OxFormField } from './ox-form-field'
13
-
14
- type ValueMap = { default?: any; [key: string]: any }
15
- type ArrayedValueMap = { key: string; value: any }
16
-
17
- /**
18
- key-value map editor element
19
-
20
- Example:
21
-
22
- <ox-input-value-map
23
- value=${map}
24
- keytype=${keytype}
25
- valuetype=${valuetype}>
26
- </ox-input-value-map>
27
- */
28
- @customElement('ox-input-value-map')
29
- export class OxInputValueMap extends OxFormField {
30
- static styles = css`
31
- :host {
32
- display: flex;
33
- flex-direction: column;
34
- border: 1px solid rgba(0, 0, 0, 0.15);
35
- padding: var(--spacing-small) var(--spacing-small) 0 var(--spacing-small);
36
-
37
- --md-icon-size: var(--fontsize-default, 14px);
38
- }
39
-
40
- div {
41
- display: flex;
42
- flex-flow: row nowrap;
43
- gap: var(--padding-default);
44
- }
45
-
46
- div:last-child {
47
- margin-bottom: var(--spacing-small);
48
- }
49
-
50
- div > * {
51
- min-width: 0px;
52
- margin: 2px;
53
- padding: 0;
54
- }
55
-
56
- button {
57
- border: var(--button-border);
58
- border-radius: var(--border-radius);
59
- background-color: var(--button-background-color);
60
- padding: var(--spacing-small) var(--padding-default);
61
- line-height: 0.8;
62
- color: var(--button-color);
63
- cursor: pointer;
64
- }
65
- button + button {
66
- margin-left: -5px;
67
- }
68
-
69
- button:focus,
70
- button:hover,
71
- button:active {
72
- border: var(--button-activ-border);
73
- background-color: var(--button-background-focus-color);
74
- color: var(--md-sys-color-primary-container);
75
- }
76
-
77
- [data-key],
78
- [data-value] {
79
- flex: 1;
80
- }
81
-
82
- input {
83
- border: 0;
84
- border-bottom: 1px solid rgba(0, 0, 0, 0.15);
85
- padding: var(--spacing-tiny);
86
- font: var(--input-font);
87
- color: var(--md-sys-color-on-primary-container);
88
- }
89
-
90
- input:focus {
91
- outline: none;
92
- border-bottom: 1px solid var(--md-sys-color-on-primary-container);
93
- }
94
-
95
- button.hidden {
96
- opacity: 0;
97
- cursor: default;
98
- }
99
-
100
- ox-input-color {
101
- margin: 1px;
102
- width: 10px;
103
- height: 10px;
104
- }
105
-
106
- input[type='checkbox'] {
107
- flex: none;
108
- width: initial;
109
- }
110
- `
111
-
112
- @property({ type: Object }) value: ValueMap = {}
113
- @property({ type: String }) valuetype: 'string' | 'boolean' | 'color' | 'number' | 'date' | string = 'string'
114
- @property({ type: String }) keytype: 'string' | 'number' = 'number'
115
- @property({ type: String, attribute: 'default-value' }) defaultValue?: string
116
-
117
- private _changingNow: boolean = false
118
-
119
- firstUpdated() {
120
- this.renderRoot.addEventListener('change', this._onChange.bind(this))
121
- }
122
-
123
- updated() {
124
- const inputs = this.renderRoot.querySelectorAll('[data-record-new] > :not([style*="display: none"])') as NodeListOf<
125
- HTMLInputElement & { value: any }
126
- >
127
-
128
- inputs[0].focus()
129
- }
130
-
131
- valueInputTemplate(value?: any) {
132
- return this.valuetype == 'boolean'
133
- ? html`
134
- <input
135
- type="checkbox"
136
- data-value
137
- .checked=${!!value}
138
- data-value-type=${this.valuetype}
139
- ?disabled=${this.disabled}
140
- />
141
- `
142
- : this.valuetype == 'color'
143
- ? html` <ox-input-color data-value value=${ifDefined(value)} ?disabled=${this.disabled}> </ox-input-color> `
144
- : html`
145
- <input
146
- type="text"
147
- data-value
148
- placeholder="value"
149
- value=${ifDefined(value)}
150
- data-value-type=${this.valuetype}
151
- ?disabled=${this.disabled}
152
- />
153
- `
154
- }
155
-
156
- render() {
157
- return html`
158
- ${this._toArray(this.value).map(
159
- item => html`
160
- <div data-record>
161
- <input type="text" data-key placeholder="key" .value=${item.key} ?disabled=${this.disabled} />
162
- ${this.valueInputTemplate(item.value)}
163
- <button
164
- class="record-action"
165
- @click=${(e: MouseEvent) => this._delete(e)}
166
- tabindex="-1"
167
- ?disabled=${this.disabled}
168
- >
169
- <md-icon>remove</md-icon>
170
- </button>
171
- </div>
172
- `
173
- )}
174
- ${this.disabled
175
- ? nothing
176
- : keyed(
177
- Date.now(),
178
- html`
179
- <div data-record-new>
180
- <input type="text" data-key placeholder="key" value="" />
181
-
182
- ${this.valueInputTemplate()}
183
- <button class="record-action" @click=${(e: MouseEvent) => this._add()} tabindex="-1">
184
- <md-icon>add</md-icon>
185
- </button>
186
- </div>
187
- `
188
- )}
189
-
190
- <div data-record>
191
- <input type="text" data-key data-default="" value="default" disabled />
192
-
193
- ${this.valueInputTemplate((this.value && this.value.default) || this._defaultValue())}
194
- <button class="record-action" @click=${() => this._sort()} tabindex="-1">
195
- <md-icon>chevron_right</md-icon>
196
- </button>
197
- </div>
198
- `
199
- }
200
-
201
- _defaultValue(type?: 'color' | 'boolean' | 'checkbox' | string) {
202
- switch (type || this.valuetype) {
203
- case 'color':
204
- return this.defaultValue || '#000000'
205
- case 'boolean':
206
- case 'checkbox':
207
- return this.defaultValue ? this.defaultValue === 'true' : false
208
- default:
209
- return this.defaultValue || ''
210
- }
211
- }
212
-
213
- _onChange(e: Event) {
214
- e.stopPropagation()
215
-
216
- if (this._changingNow) {
217
- return
218
- }
219
-
220
- this._changingNow = true
221
-
222
- const input = e.target as HTMLInputElement
223
- var value
224
-
225
- if (input.type == 'checkbox') {
226
- value = Boolean(input.checked)
227
- } else {
228
- value = input.value
229
- }
230
-
231
- const div = input.parentElement as HTMLDivElement
232
-
233
- if (div.hasAttribute('data-record') && input.hasAttribute('data-value')) {
234
- var dataList = div.querySelectorAll('[data-value]:not([hidden])') as NodeListOf<HTMLElement & { value: any }>
235
-
236
- for (var i = 0; i < dataList.length; i++) {
237
- if (dataList[i] !== input) {
238
- dataList[i].value = value || this._defaultValue()
239
- }
240
- }
241
- }
242
-
243
- if (div.hasAttribute('data-record')) {
244
- this._build()
245
- } else if (div.hasAttribute('data-record-new') && input.hasAttribute('data-value')) {
246
- this._add()
247
- }
248
-
249
- this._changingNow = false
250
- }
251
-
252
- _build(includeNewRecord?: boolean) {
253
- if (includeNewRecord) {
254
- var records = this.renderRoot.querySelectorAll('[data-record],[data-record-new]') as NodeListOf<HTMLElement>
255
- } else {
256
- var records = this.renderRoot.querySelectorAll('[data-record]') as NodeListOf<HTMLElement>
257
- }
258
-
259
- var newmap: ValueMap = {}
260
-
261
- for (var i = 0; i < records.length; i++) {
262
- var record = records[i]
263
-
264
- const key = (record.querySelector('[data-key]') as HTMLInputElement).value
265
- const inputs = record.querySelectorAll('[data-value]:not([style*="display: none"])') as NodeListOf<
266
- HTMLInputElement & { value: any }
267
- >
268
-
269
- if (!inputs || inputs.length == 0) {
270
- continue
271
- }
272
-
273
- var input = inputs[inputs.length - 1]
274
-
275
- var value
276
-
277
- if (input.type == 'checkbox') {
278
- value = Boolean(input.checked)
279
- } else {
280
- value = input.value
281
- }
282
-
283
- if (key) {
284
- newmap[key] = value || this._defaultValue()
285
- }
286
- }
287
-
288
- this.value = newmap
289
-
290
- this.dispatchEvent(new CustomEvent('change', { bubbles: true, composed: true, detail: this.value }))
291
- }
292
-
293
- /* default를 제외한 map아이템들을 template(dom-repeat)용 배열로 변환하는 함수 */
294
- _toArray(map: ValueMap) {
295
- var array: ArrayedValueMap[] = []
296
-
297
- for (var key in map) {
298
- if (key == 'default') continue
299
- array.push({
300
- key: key,
301
- value: map[key]
302
- })
303
- }
304
-
305
- return array
306
- }
307
-
308
- _sort() {
309
- const sorter =
310
- this.keytype === 'number'
311
- ? function (a: ArrayedValueMap, b: ArrayedValueMap) {
312
- return parseFloat(b.key) < parseFloat(a.key) ? 1 : -1
313
- }
314
- : function (a: ArrayedValueMap, b: ArrayedValueMap) {
315
- return b.key < a.key ? 1 : -1
316
- }
317
-
318
- var map = this._toArray(this.value)
319
- .sort(sorter)
320
- .reduce(function (sum, i) {
321
- sum[i.key] = i.value
322
- return sum
323
- }, {} as ValueMap)
324
-
325
- map.default = this.value.default
326
-
327
- this.value = map
328
- this.dispatchEvent(new CustomEvent('change', { bubbles: true, composed: true, detail: this.value }))
329
- }
330
-
331
- _add() {
332
- this._build(true)
333
- }
334
-
335
- _delete(e: MouseEvent) {
336
- const record = (e.target as HTMLElement).parentElement
337
-
338
- ;(record!.querySelector('[data-key]') as HTMLInputElement)!.value = ''
339
-
340
- this._build()
341
- }
342
- }