@operato/input 1.13.12 → 1.14.3
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 +19 -0
- package/dist/src/ox-input-data.d.ts +2 -1
- package/dist/src/ox-input-data.js +71 -24
- package/dist/src/ox-input-data.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/ox-input-data.ts +81 -27
- package/yarn-error.log +0 -17084
package/package.json
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
"name": "@operato/input",
|
3
3
|
"description": "Webcomponents for input following open-wc recommendations",
|
4
4
|
"author": "heartyoh@hatiolab.com",
|
5
|
-
"version": "1.
|
5
|
+
"version": "1.14.3",
|
6
6
|
"main": "dist/src/index.js",
|
7
7
|
"module": "dist/src/index.js",
|
8
8
|
"license": "MIT",
|
@@ -239,5 +239,5 @@
|
|
239
239
|
"prettier --write"
|
240
240
|
]
|
241
241
|
},
|
242
|
-
"gitHead": "
|
242
|
+
"gitHead": "cb8f455eb045bff6ea9123101394e0b0fe013707"
|
243
243
|
}
|
package/src/ox-input-data.ts
CHANGED
@@ -4,12 +4,13 @@
|
|
4
4
|
|
5
5
|
import './ox-input-code'
|
6
6
|
|
7
|
-
import { css, html
|
8
|
-
import { customElement
|
7
|
+
import { css, html } from 'lit'
|
8
|
+
import { customElement } from 'lit/decorators.js'
|
9
9
|
import { live } from 'lit/directives/live.js'
|
10
10
|
|
11
11
|
import { OxFormField } from './ox-form-field.js'
|
12
12
|
import { OxInputCode } from './ox-input-code.js'
|
13
|
+
import { isEqual } from 'lodash-es'
|
13
14
|
|
14
15
|
/**
|
15
16
|
WEB Component for code-mirror based data editor.
|
@@ -90,7 +91,16 @@ export class OxInputData extends OxFormField {
|
|
90
91
|
<mwc-icon @click=${() => this._clearData()} title="delete">delete_forever</mwc-icon>
|
91
92
|
</div>
|
92
93
|
|
93
|
-
<ox-input-code
|
94
|
+
<ox-input-code
|
95
|
+
.value=${this._getStringData(this.value)}
|
96
|
+
language="text"
|
97
|
+
editor
|
98
|
+
?disabled=${this.disabled}
|
99
|
+
@change=${(e: CustomEvent) => {
|
100
|
+
e.stopPropagation()
|
101
|
+
this._setDataTypeAndValue(valueType, (e.target as any).value)
|
102
|
+
}}
|
103
|
+
>
|
94
104
|
</ox-input-code>
|
95
105
|
`
|
96
106
|
}
|
@@ -98,39 +108,74 @@ export class OxInputData extends OxFormField {
|
|
98
108
|
firstUpdated() {
|
99
109
|
this.renderRoot.addEventListener('change', e => {
|
100
110
|
e.stopPropagation()
|
111
|
+
|
101
112
|
const target = e.target as OxInputCode
|
102
113
|
if (target.hasAttribute('editor')) {
|
114
|
+
if (this.value === undefined && target.value == '') {
|
115
|
+
return
|
116
|
+
}
|
103
117
|
this.value = target.value
|
104
118
|
}
|
105
|
-
|
106
|
-
const type = this.renderRoot.querySelector('input[name=data-type]:checked')?.getAttribute('data-value')
|
107
|
-
this._setDataType(type)
|
108
119
|
})
|
109
120
|
}
|
110
121
|
|
122
|
+
_setDataTypeAndValue(type: string | undefined | null, value: any) {
|
123
|
+
/* value must be a string */
|
124
|
+
try {
|
125
|
+
switch (type) {
|
126
|
+
case 'number':
|
127
|
+
if (!isNaN(Number(value))) {
|
128
|
+
value = Number(value)
|
129
|
+
}
|
130
|
+
break
|
131
|
+
case 'object':
|
132
|
+
value = eval('(' + value + ')')
|
133
|
+
break
|
134
|
+
}
|
135
|
+
} catch (e) {}
|
136
|
+
|
137
|
+
if (isEqual(this.value, value)) {
|
138
|
+
return
|
139
|
+
}
|
140
|
+
|
141
|
+
this.value = value
|
142
|
+
|
143
|
+
this.requestUpdate()
|
144
|
+
this._onAfterValueChange()
|
145
|
+
}
|
146
|
+
|
111
147
|
_setDataType(type: string | undefined | null) {
|
112
|
-
if (typeof this.value
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
148
|
+
if (typeof this.value == type) {
|
149
|
+
return
|
150
|
+
}
|
151
|
+
|
152
|
+
var value = this.value
|
153
|
+
|
154
|
+
try {
|
155
|
+
switch (type) {
|
156
|
+
case 'string':
|
157
|
+
value = this._getStringData(value)
|
158
|
+
break
|
159
|
+
case 'number':
|
160
|
+
if (!isNaN(value)) {
|
161
|
+
value = Number(value)
|
162
|
+
}
|
163
|
+
break
|
164
|
+
case 'object':
|
165
|
+
value = eval('(' + value + ')')
|
166
|
+
break
|
131
167
|
}
|
168
|
+
} catch (e) {
|
169
|
+
console.log(e)
|
132
170
|
}
|
133
171
|
|
172
|
+
if (isEqual(this.value, value)) {
|
173
|
+
this.requestUpdate()
|
174
|
+
return
|
175
|
+
}
|
176
|
+
|
177
|
+
this.value = value
|
178
|
+
|
134
179
|
this.requestUpdate()
|
135
180
|
this._onAfterValueChange()
|
136
181
|
}
|
@@ -140,8 +185,17 @@ export class OxInputData extends OxFormField {
|
|
140
185
|
this._onAfterValueChange()
|
141
186
|
}
|
142
187
|
|
143
|
-
|
144
|
-
|
188
|
+
_getStringData(data: any) {
|
189
|
+
const type = typeof data
|
190
|
+
|
191
|
+
switch (type) {
|
192
|
+
case 'object':
|
193
|
+
return JSON.stringify(data, null, 1)
|
194
|
+
case 'undefined':
|
195
|
+
return ''
|
196
|
+
default:
|
197
|
+
return String(data) || ''
|
198
|
+
}
|
145
199
|
}
|
146
200
|
|
147
201
|
async _onAfterValueChange() {
|