@operato/input 7.1.30 → 7.1.32

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 (119) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/dist/tsconfig.tsbuildinfo +1 -1
  3. package/package.json +7 -7
  4. package/.editorconfig +0 -29
  5. package/.storybook/main.js +0 -3
  6. package/.storybook/preview.js +0 -52
  7. package/.storybook/server.mjs +0 -8
  8. package/demo/index-3dish.html +0 -38
  9. package/demo/index-angle.html +0 -36
  10. package/demo/index-barcode.html +0 -68
  11. package/demo/index-button-radio.html +0 -42
  12. package/demo/index-checkbox.html +0 -69
  13. package/demo/index-code.html +0 -61
  14. package/demo/index-color-gradient.html +0 -35
  15. package/demo/index-color-stops.html +0 -62
  16. package/demo/index-color.html +0 -35
  17. package/demo/index-crontab.html +0 -37
  18. package/demo/index-file.html +0 -41
  19. package/demo/index-image.html +0 -40
  20. package/demo/index-multiple-colors.html +0 -52
  21. package/demo/index-options.html +0 -43
  22. package/demo/index-partition-keys.html +0 -79
  23. package/demo/index-range.html +0 -40
  24. package/demo/index-select.html +0 -136
  25. package/demo/index-stack.html +0 -33
  26. package/demo/index-table.html +0 -50
  27. package/demo/index-value-map.html +0 -80
  28. package/demo/index-value-ranges.html +0 -80
  29. package/demo/index-work-shift.html +0 -59
  30. package/demo/index.html +0 -54
  31. package/src/index.ts +0 -34
  32. package/src/locale/locale-codes.ts +0 -18
  33. package/src/locale/locale-picker.ts +0 -43
  34. package/src/locale/localization.ts +0 -15
  35. package/src/locales/en.ts +0 -30
  36. package/src/locales/ko.ts +0 -30
  37. package/src/locales/ms.ts +0 -30
  38. package/src/locales/zh.ts +0 -30
  39. package/src/ox-buttons-radio.ts +0 -140
  40. package/src/ox-checkbox.ts +0 -181
  41. package/src/ox-form-field.ts +0 -53
  42. package/src/ox-input-3axis.ts +0 -77
  43. package/src/ox-input-3dish.ts +0 -211
  44. package/src/ox-input-angle.ts +0 -73
  45. package/src/ox-input-barcode.ts +0 -318
  46. package/src/ox-input-code.ts +0 -139
  47. package/src/ox-input-color-gradient.ts +0 -349
  48. package/src/ox-input-color-stops.ts +0 -525
  49. package/src/ox-input-color.ts +0 -338
  50. package/src/ox-input-container.ts +0 -32
  51. package/src/ox-input-crontab.ts +0 -595
  52. package/src/ox-input-data.ts +0 -219
  53. package/src/ox-input-direction.ts +0 -65
  54. package/src/ox-input-duration.ts +0 -175
  55. package/src/ox-input-file.ts +0 -209
  56. package/src/ox-input-hashtags.ts +0 -185
  57. package/src/ox-input-i18n-label.ts +0 -140
  58. package/src/ox-input-image.ts +0 -168
  59. package/src/ox-input-key-values.ts +0 -301
  60. package/src/ox-input-layout/ox-input-card-layout.ts +0 -58
  61. package/src/ox-input-layout/ox-input-grid-layout.ts +0 -64
  62. package/src/ox-input-layout/ox-input-layout.ts +0 -77
  63. package/src/ox-input-mass-fraction.ts +0 -437
  64. package/src/ox-input-multiple-colors.ts +0 -135
  65. package/src/ox-input-options.ts +0 -216
  66. package/src/ox-input-partition-keys.ts +0 -303
  67. package/src/ox-input-privilege.ts +0 -163
  68. package/src/ox-input-quantifier.ts +0 -62
  69. package/src/ox-input-range.ts +0 -146
  70. package/src/ox-input-scene-component-id.ts +0 -73
  71. package/src/ox-input-search.ts +0 -126
  72. package/src/ox-input-select-buttons.ts +0 -75
  73. package/src/ox-input-signature.ts +0 -180
  74. package/src/ox-input-stack.ts +0 -136
  75. package/src/ox-input-table-column-config.ts +0 -211
  76. package/src/ox-input-table.ts +0 -404
  77. package/src/ox-input-textarea.ts +0 -86
  78. package/src/ox-input-unit-number.ts +0 -354
  79. package/src/ox-input-value-map.ts +0 -342
  80. package/src/ox-input-value-ranges.ts +0 -363
  81. package/src/ox-input-work-shift.ts +0 -290
  82. package/src/ox-select.ts +0 -219
  83. package/src/ox-zoomable-image.ts +0 -75
  84. package/stories/ox-buttons-radio.stories.ts +0 -89
  85. package/stories/ox-checkbox.stories.ts +0 -111
  86. package/stories/ox-input-3axis.stories.ts +0 -77
  87. package/stories/ox-input-3dish.stories.ts +0 -106
  88. package/stories/ox-input-angle.stories.ts +0 -84
  89. package/stories/ox-input-barcode.stories.ts +0 -117
  90. package/stories/ox-input-code.stories.ts +0 -99
  91. package/stories/ox-input-crontab.stories.ts +0 -82
  92. package/stories/ox-input-data.stories.ts +0 -82
  93. package/stories/ox-input-direction.stories.ts +0 -80
  94. package/stories/ox-input-duration.stories.ts +0 -84
  95. package/stories/ox-input-file.stories.ts +0 -111
  96. package/stories/ox-input-hashtags.stories.ts +0 -82
  97. package/stories/ox-input-i18n-label.stories.ts +0 -103
  98. package/stories/ox-input-key-values.stories.ts +0 -97
  99. package/stories/ox-input-mass-fraction.stories.ts +0 -102
  100. package/stories/ox-input-multiple-colors.stories.ts +0 -72
  101. package/stories/ox-input-options.stories.ts +0 -80
  102. package/stories/ox-input-partition-keys.stories.ts +0 -84
  103. package/stories/ox-input-privilege.stories.ts +0 -108
  104. package/stories/ox-input-quantifier.stories.ts +0 -80
  105. package/stories/ox-input-range.stories.ts +0 -89
  106. package/stories/ox-input-search.stories.ts +0 -91
  107. package/stories/ox-input-select-buttons.stories.ts +0 -118
  108. package/stories/ox-input-signature.stories.ts +0 -75
  109. package/stories/ox-input-table-column-config.stories.ts +0 -109
  110. package/stories/ox-input-unit.stories.ts +0 -151
  111. package/stories/ox-input-value-map.stories.ts +0 -92
  112. package/stories/ox-input-value-ranges.stories.ts +0 -92
  113. package/stories/ox-input-work-shift.stories.ts +0 -106
  114. package/stories/ox-select-set-options.stories.ts +0 -208
  115. package/stories/ox-select.stories.ts +0 -181
  116. package/tsconfig.json +0 -25
  117. package/web-dev-server.config.mjs +0 -27
  118. package/web-test-runner.config.mjs +0 -41
  119. package/yarn-error.log +0 -17084
@@ -1,216 +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, nothing } from 'lit'
8
- import { customElement, property } from 'lit/decorators.js'
9
-
10
- import { OxFormField } from './ox-form-field'
11
-
12
- type Option = { text: string; value: string }
13
-
14
- @customElement('ox-input-options')
15
- export class OxInputOptions extends OxFormField {
16
- static styles = css`
17
- :host {
18
- display: flex;
19
- flex-direction: column;
20
- overflow: hidden;
21
- margin-bottom: var(--spacing-large);
22
-
23
- --md-icon-size: var(--fontsize-default, 14px);
24
- }
25
-
26
- div {
27
- display: flex;
28
- flex-flow: row nowrap;
29
- gap: var(--spacing-medium);
30
- margin-bottom: var(--spacing-small);
31
- }
32
-
33
- button {
34
- border: var(--button-border);
35
- border-radius: var(--border-radius);
36
- background-color: var(--button-background-color);
37
- line-height: 0.8;
38
- color: var(--button-color);
39
- cursor: pointer;
40
- }
41
- button + button {
42
- margin-left: -5px;
43
- }
44
- button:focus,
45
- button:hover,
46
- button:active {
47
- border: var(--button-activ-border);
48
- background-color: var(--button-background-focus-color);
49
- color: var(--md-sys-color-primary-container);
50
- }
51
-
52
- input {
53
- flex: 1;
54
- min-width: 80px;
55
- border: 0;
56
- border-bottom: 1px solid rgba(0, 0, 0, 0.15);
57
- padding: var(--spacing-tiny);
58
- font: var(--input-font);
59
- color: var(--md-sys-color-on-primary-container);
60
- }
61
- input:focus {
62
- outline: none;
63
- border-bottom: 1px solid var(--md-sys-color-on-primary-container);
64
- }
65
- button.hidden {
66
- opacity: 0;
67
- cursor: default;
68
- }
69
- `
70
-
71
- @property({ type: Array }) value: Option[] = []
72
-
73
- firstUpdated() {
74
- this.renderRoot.addEventListener('change', this._onChange.bind(this))
75
- }
76
-
77
- render() {
78
- const options = this.value instanceof Array ? this.value : []
79
-
80
- return html`
81
- ${(options || []).map(
82
- item => html`
83
- <div data-record>
84
- <input type="text" data-text="" placeholder="text" .value=${item.text} ?disabled=${this.disabled} />
85
- <input type="text" data-value="" placeholder="value" .value=${item.value} ?disabled=${this.disabled} />
86
- <button
87
- class="record-action"
88
- @click=${(e: MouseEvent) => this._delete(e)}
89
- tabindex="-1"
90
- ?disabled=${this.disabled}
91
- >
92
- <md-icon>remove</md-icon>
93
- </button>
94
- </div>
95
- `
96
- )}
97
- ${this.disabled
98
- ? nothing
99
- : html`
100
- <div data-record-new>
101
- <input type="text" data-text="" placeholder="text" value="" />
102
- <input type="text" data-value="" placeholder="value" value="" @change=${(e: Event) => this._add()} />
103
- <button class="record-action" @click=${(e: MouseEvent) => this._add()} tabindex="-1">
104
- <md-icon>add</md-icon>
105
- </button>
106
- </div>
107
- `}
108
- `
109
- }
110
-
111
- private _changingNow: boolean = false
112
-
113
- _onChange(e: Event) {
114
- if (this._changingNow) return
115
-
116
- this._changingNow = true
117
-
118
- var input = e.target as HTMLInputElement
119
- var value = input.value
120
-
121
- var div = input.parentElement
122
-
123
- if (div && div.hasAttribute('data-record') && input.hasAttribute('data-value')) {
124
- var dataList = div.querySelectorAll('[data-value]:not([hidden])') as NodeListOf<HTMLInputElement>
125
-
126
- for (var i = 0; i < dataList.length; i++) {
127
- if (dataList[i] !== input) {
128
- dataList[i].value = value || ''
129
- }
130
- }
131
- }
132
-
133
- if (div && div.hasAttribute('data-record')) {
134
- this._build(true)
135
- } else if (div && div.hasAttribute('data-record-new') && input.hasAttribute('data-value')) {
136
- this._add()
137
- }
138
-
139
- e.stopPropagation()
140
-
141
- this._changingNow = false
142
- }
143
-
144
- _build(includeNewRecord?: any) {
145
- if (includeNewRecord) {
146
- var records = this.renderRoot.querySelectorAll('[data-record],[data-record-new]') as NodeListOf<HTMLElement>
147
- } else {
148
- var records = this.renderRoot.querySelectorAll('[data-record]') as NodeListOf<HTMLElement>
149
- }
150
-
151
- var newoptions: Option[] = []
152
-
153
- for (var i = 0; i < records.length; i++) {
154
- var record = records[i]
155
-
156
- var text = (record.querySelector('[data-text]') as HTMLInputElement).value
157
- var inputs = record.querySelectorAll('[data-value]:not([style*="display: none"])') as NodeListOf<HTMLInputElement>
158
- if (!inputs || inputs.length == 0) continue
159
-
160
- var input = inputs[inputs.length - 1]
161
- var value = input.value
162
-
163
- if (text) newoptions.push({ text: text, value: value || text })
164
- }
165
-
166
- this.value = newoptions
167
- this.dispatchEvent(new CustomEvent('change', { bubbles: true, composed: true, detail: this.value }))
168
- }
169
-
170
- sort() {
171
- var sorter = function (a: Option, b: Option) {
172
- return b.text < a.text ? 1 : -1
173
- }
174
-
175
- this.value = [...this.value.sort(sorter)]
176
-
177
- this.dispatchEvent(new CustomEvent('change', { bubbles: true, composed: true, detail: this.value }))
178
- }
179
-
180
- _add() {
181
- this._build(true)
182
-
183
- var inputs = this.renderRoot.querySelectorAll(
184
- '[data-record-new] input:not([style*="display: none"])'
185
- ) as NodeListOf<HTMLInputElement>
186
-
187
- for (var i = 0; i < inputs.length; i++) {
188
- let input = inputs[i]
189
- input.value = ''
190
- }
191
-
192
- inputs[0].focus()
193
- }
194
-
195
- _delete(e: Event) {
196
- const record = (e.target as HTMLElement).parentElement
197
- const input = record && (record.querySelector('[data-text]') as HTMLInputElement)
198
-
199
- if (input) {
200
- input.value = ''
201
- }
202
-
203
- this._build()
204
- }
205
-
206
- protected appendFormData({ formData }: FormDataEvent): void {
207
- if (!this.name) return
208
-
209
- const value = this.value
210
-
211
- formData.append(
212
- this.name!,
213
- typeof value === 'string' ? value : value === undefined || value === null ? '' : JSON.stringify(value)
214
- )
215
- }
216
- }
@@ -1,303 +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, nothing } from 'lit'
8
- import { customElement, property, queryAll } from 'lit/decorators.js'
9
-
10
- import { OxFormField } from './ox-form-field'
11
-
12
- type PartitionKeys = { [key: string]: any }
13
- type ArrayedPartitionKeys = { key: string; value: any }
14
-
15
- /**
16
- key-value map for partitions editor element
17
-
18
- Example:
19
-
20
- <ox-input-partition-keys
21
- value=${map}
22
- </ox-input-partition-keys>
23
- */
24
- @customElement('ox-input-partition-keys')
25
- export class OxInputPartitionKeys extends OxFormField {
26
- static styles = css`
27
- :host {
28
- display: flex;
29
- flex-direction: column;
30
- overflow: hidden;
31
- margin-bottom: var(--spacing-large);
32
-
33
- --md-icon-size: var(--fontsize-default, 14px);
34
- }
35
-
36
- div {
37
- display: flex;
38
- flex-flow: row nowrap;
39
- gap: var(--spacing-medium);
40
- margin-bottom: var(--spacing-small);
41
- }
42
-
43
- button {
44
- border: var(--button-border);
45
- border-radius: var(--border-radius);
46
- background-color: var(--button-background-color);
47
- padding: var(--spacing-small) var(--padding-default);
48
- line-height: 0.8;
49
- color: var(--button-color);
50
- cursor: pointer;
51
- }
52
- button + button {
53
- margin-left: -5px;
54
- }
55
-
56
- button:focus,
57
- button:hover,
58
- button:active {
59
- border: var(--button-activ-border);
60
- background-color: var(--button-background-focus-color);
61
- color: var(--md-sys-color-primary-container);
62
- }
63
-
64
- input {
65
- flex: 1;
66
- border: 0;
67
- border-bottom: 1px solid rgba(0, 0, 0, 0.15);
68
- padding: var(--spacing-tiny);
69
- font: var(--input-font);
70
- color: var(--md-sys-color-on-primary-container);
71
- }
72
- input:focus {
73
- outline: none;
74
- border-bottom: 1px solid var(--md-sys-color-on-primary-container);
75
- }
76
- button.hidden {
77
- opacity: 0;
78
- cursor: default;
79
- }
80
- `
81
-
82
- @property({ type: Object }) value: PartitionKeys = {}
83
-
84
- private _changingNow: boolean = false
85
-
86
- firstUpdated() {
87
- this.renderRoot.addEventListener('change', this._onChange.bind(this))
88
- }
89
-
90
- render() {
91
- const value = !this.value || typeof this.value !== 'object' ? {} : this.value
92
-
93
- return html`
94
- ${this._toArray(value).map(
95
- item => html`
96
- <div data-record>
97
- <input type="text" data-key placeholder="key" .value=${item.key} ?disabled=${this.disabled} />
98
- <input
99
- type="text"
100
- data-value
101
- placeholder="value"
102
- .value=${item.value}
103
- list="value-template"
104
- ?disabled=${this.disabled}
105
- />
106
- <button
107
- class="record-action"
108
- @click=${(e: MouseEvent) => this._delete(e)}
109
- tabindex="-1"
110
- ?disabled=${this.disabled}
111
- >
112
- <md-icon>remove</md-icon>
113
- </button>
114
- <button
115
- class="record-action"
116
- @click=${(e: MouseEvent) => this._up(e)}
117
- tabindex="-1"
118
- ?disabled=${this.disabled}
119
- >
120
- <md-icon>arrow_upward</md-icon>
121
- </button>
122
- <button
123
- class="record-action"
124
- @click=${(e: MouseEvent) => this._down(e)}
125
- tabindex="-1"
126
- ?disabled=${this.disabled}
127
- >
128
- <md-icon>arrow_downward</md-icon>
129
- </button>
130
- </div>
131
- `
132
- )}
133
- ${this.disabled
134
- ? nothing
135
- : html`
136
- <div data-record-new>
137
- <input type="text" data-key placeholder="key" value="" />
138
- <input type="text" data-value placeholder="value" value="" list="value-template" />
139
- <button class="record-action" @click=${(e: MouseEvent) => this._add()} tabindex="-1">
140
- <md-icon>add</md-icon>
141
- </button>
142
- <button class="hidden"><md-icon>add</md-icon></button>
143
- <button class="hidden"><md-icon>add</md-icon></button>
144
- </div>
145
- `}
146
-
147
- <datalist id="value-template">
148
- <option value="%YYYY">year</option>
149
- <option value="%MM">month</option>
150
- <option value="%DD">day</option>
151
- <option value="%YYYYMMDD">date</option>
152
- </datalist>
153
- `
154
- }
155
-
156
- _onChange(e: Event) {
157
- if (this._changingNow) {
158
- return
159
- }
160
-
161
- this._changingNow = true
162
-
163
- const input = e.target as HTMLInputElement
164
- var value = input.value
165
-
166
- const record = (e.target as Element).closest('[data-record],[data-record-new]') as HTMLElement
167
-
168
- if (record.hasAttribute('data-record')) {
169
- this._build()
170
- } else if (record.hasAttribute('data-record-new') && input.hasAttribute('data-value')) {
171
- this._add()
172
- }
173
-
174
- this._changingNow = false
175
- }
176
-
177
- _build(includeNewRecord?: boolean) {
178
- if (includeNewRecord) {
179
- var records = this.renderRoot.querySelectorAll('[data-record],[data-record-new]') as NodeListOf<HTMLElement>
180
- } else {
181
- var records = this.renderRoot.querySelectorAll('[data-record]') as NodeListOf<HTMLElement>
182
- }
183
-
184
- var newmap: PartitionKeys = {}
185
-
186
- for (var i = 0; i < records.length; i++) {
187
- var record = records[i]
188
-
189
- const key = (record.querySelector('[data-key]') as HTMLInputElement).value
190
- const inputs = record.querySelectorAll(
191
- '[data-value]:not([style*="display: none"])'
192
- ) as NodeListOf<HTMLInputElement>
193
-
194
- if (!inputs || inputs.length == 0) {
195
- continue
196
- }
197
-
198
- var input = inputs[inputs.length - 1]
199
-
200
- var value = input.value
201
-
202
- if (key) {
203
- newmap[key] = value || ''
204
- }
205
- }
206
-
207
- this.value = newmap
208
- this.dispatchEvent(new CustomEvent('change', { bubbles: true, composed: true, detail: this.value }))
209
- }
210
-
211
- /* map아이템들을 template(dom-repeat)용 배열로 변환하는 함수 */
212
- _toArray(map: PartitionKeys) {
213
- var array: ArrayedPartitionKeys[] = []
214
-
215
- for (var key in map) {
216
- array.push({
217
- key: key,
218
- value: map[key]
219
- })
220
- }
221
-
222
- return array
223
- }
224
-
225
- _add() {
226
- this._build(true)
227
-
228
- const inputs = this.renderRoot.querySelectorAll(
229
- '[data-record-new] input:not([style*="display: none"])'
230
- ) as NodeListOf<HTMLInputElement & { value: any }>
231
-
232
- for (var i = 0; i < inputs.length; i++) {
233
- let input = inputs[i]
234
-
235
- if (input.type == 'checkbox') input.checked = false
236
- else input.value = ''
237
- }
238
-
239
- inputs[0].focus()
240
- }
241
-
242
- _delete(e: MouseEvent) {
243
- const record = (e.target as Element).closest('[data-record]') as HTMLElement
244
-
245
- ;(record!.querySelector('[data-key]') as HTMLInputElement)!.value = ''
246
-
247
- this._build()
248
- }
249
-
250
- @queryAll('[data-record]') records!: NodeListOf<HTMLElement>
251
-
252
- _up(e: MouseEvent) {
253
- const record = (e.target as Element).closest('[data-record]') as HTMLElement
254
- const array = Array.from(this.records)
255
- const index = array.indexOf(record) - 1
256
-
257
- if (index < 0) {
258
- return
259
- }
260
-
261
- const deleted = array.splice(index, 1)
262
- array.splice(index + 1, 0, ...deleted)
263
-
264
- this.value = array.reduce(
265
- (sum, record) => {
266
- const key = (record.querySelector('[data-key]') as HTMLInputElement).value
267
- const value = (record.querySelector('[data-value]') as HTMLInputElement).value
268
-
269
- sum[key] = value
270
- return sum
271
- },
272
- {} as { [key: string]: string }
273
- )
274
-
275
- this.dispatchEvent(new CustomEvent('change', { bubbles: true, composed: true, detail: this.value }))
276
- }
277
-
278
- _down(e: MouseEvent) {
279
- const record = (e.target as Element).closest('[data-record]') as HTMLElement
280
- const array = Array.from(this.records)
281
- const index = array.indexOf(record)
282
-
283
- if (index > array.length) {
284
- return
285
- }
286
-
287
- array.splice(index, 1)
288
- array.splice(index + 1, 0, record)
289
-
290
- this.value = array.reduce(
291
- (sum, record) => {
292
- const key = (record.querySelector('[data-key]') as HTMLInputElement).value
293
- const value = (record.querySelector('[data-value]') as HTMLInputElement).value
294
-
295
- sum[key] = value
296
- return sum
297
- },
298
- {} as { [key: string]: string }
299
- )
300
-
301
- this.dispatchEvent(new CustomEvent('change', { bubbles: true, composed: true, detail: this.value }))
302
- }
303
- }
@@ -1,163 +0,0 @@
1
- /**
2
- * @license Copyright © HatioLab Inc. All rights reserved.
3
- */
4
-
5
- import { css, html } from 'lit'
6
- import { customElement, property, query } from 'lit/decorators.js'
7
- import { ifDefined } from 'lit/directives/if-defined.js'
8
-
9
- import { i18next } from '@operato/i18n'
10
-
11
- import { OxFormField } from './ox-form-field'
12
-
13
- @customElement('ox-input-privilege')
14
- export class OxInputPrivilege extends OxFormField {
15
- static styles = css`
16
- :host {
17
- text-align: center;
18
- padding: 10px;
19
- }
20
-
21
- :host * {
22
- box-sizing: border-box;
23
- }
24
-
25
- :host *:focus {
26
- outline: none;
27
- }
28
-
29
- form {
30
- width: 100%;
31
- height: 100%;
32
- }
33
-
34
- select {
35
- border: 0;
36
- border-bottom: 1px solid rgba(0, 0, 0, 0.15);
37
- padding: var(--spacing-tiny);
38
- font: var(--input-font);
39
- color: var(--md-sys-color-on-primary-container);
40
-
41
- max-height: 35px;
42
- }
43
-
44
- select:focus {
45
- outline: none;
46
- border-bottom: 1px solid var(--md-sys-color-on-primary-container);
47
- }
48
-
49
- div[values] {
50
- display: grid;
51
- grid-template-columns: 1fr 1fr;
52
- grid-gap: 10px;
53
- }
54
-
55
- div[values] > [col1] {
56
- text-align: right;
57
- align-self: center;
58
- }
59
-
60
- div[values] > [col2] {
61
- text-align: left;
62
- align-self: center;
63
- margin-right: auto;
64
- }
65
-
66
- input {
67
- border: 0;
68
- border-bottom: 1px solid rgba(0, 0, 0, 0.15);
69
- padding: var(--spacing-tiny);
70
- padding-right: 0;
71
- max-width: 70px;
72
- font: var(--input-font);
73
- color: var(--md-sys-color-on-primary-container);
74
- text-align: right;
75
- }
76
-
77
- input:focus {
78
- outline: none;
79
- border-bottom: 1px solid var(--md-sys-color-on-primary-container);
80
- }
81
-
82
- label {
83
- margin-right: var(--spacing-medium);
84
- font: normal 0.8em var(--theme-font);
85
- color: var(--md-sys-color-on-primary-container);
86
- }
87
- `
88
-
89
- @property({ type: Object }) value?: {
90
- category: string
91
- privilege: string
92
- owner?: boolean
93
- super?: boolean
94
- } | null
95
-
96
- @property({ type: Array }) privileges: { privilege: string; category: string; description: string }[] = []
97
-
98
- @query('form') private form!: HTMLFormElement
99
-
100
- render() {
101
- const { category, privilege, owner, super: superUser } = this.value || {}
102
- const privileges = this.privileges || []
103
-
104
- return html`
105
- <form @change=${this.onChange.bind(this)}>
106
- <div values>
107
- <label for="privilege" col1>${i18next.t('label.privilege')}</label>
108
- <select id="privilege" name="privilege" value=${ifDefined(privilege)} ?disabled=${this.disabled}>
109
- <option value="">&nbsp;</option>
110
- ${privileges.map(
111
- p =>
112
- html`<option
113
- value=${`${p.category}:${p.privilege}`}
114
- ?selected=${category == p.category && privilege == p.privilege}
115
- >
116
- ${p.description}
117
- </option>`
118
- )}
119
- </select>
120
-
121
- <label for="owner" col1>${i18next.t('label.domain-owner')}</label>
122
- <input id="owner" type="checkbox" name="owner" ?checked=${owner} col2 ?disabled=${this.disabled} />
123
-
124
- <label for="super" col1>${i18next.t('label.superuser')}</label>
125
- <input id="super" type="checkbox" name="super" ?checked=${superUser} col2 ?disabled=${this.disabled} />
126
- </div>
127
- </form>
128
- `
129
- }
130
-
131
- buildValue() {
132
- const formData = new FormData(this.form)
133
-
134
- const [category = '', privilege = ''] = (formData.get('privilege') as string).split(':')
135
- const owner = formData.get('owner') as string
136
- const superUser = formData.get('super') as string
137
-
138
- return {
139
- category,
140
- privilege,
141
- owner: owner == 'on',
142
- super: superUser == 'on'
143
- }
144
- }
145
-
146
- firstUpdated() {
147
- ;(this.renderRoot.querySelector('input') as HTMLInputElement).focus()
148
- }
149
-
150
- onChange(e: Event) {
151
- e.stopPropagation()
152
-
153
- this.value = this.buildValue()
154
-
155
- this.dispatchEvent(
156
- new CustomEvent('change', {
157
- bubbles: true,
158
- composed: true,
159
- detail: this.value
160
- })
161
- )
162
- }
163
- }