@operato/input 1.13.14 → 1.17.2

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/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.13.14",
5
+ "version": "1.17.2",
6
6
  "main": "dist/src/index.js",
7
7
  "module": "dist/src/index.js",
8
8
  "license": "MIT",
@@ -193,7 +193,7 @@
193
193
  "@material/mwc-icon": "^0.27.0",
194
194
  "@operato/color-picker": "^1.4.64",
195
195
  "@operato/i18n": "^1.5.14",
196
- "@operato/popup": "^1.13.9",
196
+ "@operato/popup": "^1.17.2",
197
197
  "@operato/styles": "^1.12.3",
198
198
  "@operato/utils": "^1.13.9",
199
199
  "@polymer/paper-dropdown-menu": "^3.2.0",
@@ -239,5 +239,5 @@
239
239
  "prettier --write"
240
240
  ]
241
241
  },
242
- "gitHead": "9d335c3383d9f899105fb0cd10fc0f7824da5bfb"
242
+ "gitHead": "953573e87b156ac2ce143009555fb2ec4f1162ee"
243
243
  }
@@ -4,12 +4,13 @@
4
4
 
5
5
  import './ox-input-code'
6
6
 
7
- import { css, html, PropertyValues } from 'lit'
8
- import { customElement, state } from 'lit/decorators.js'
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 .value=${this._getStringData(this.value)} language="javascript" editor ?disabled=${this.disabled}>
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
  }
@@ -109,29 +119,63 @@ export class OxInputData extends OxFormField {
109
119
  })
110
120
  }
111
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
+
112
147
  _setDataType(type: string | undefined | null) {
113
- if (typeof this.value !== type) {
114
- var value = this.value
115
-
116
- try {
117
- switch (type) {
118
- case 'string':
119
- this.value = this._getStringData(value)
120
- break
121
- case 'number':
122
- if (!isNaN(value)) {
123
- this.value = Number(value)
124
- }
125
- break
126
- case 'object':
127
- this.value = eval('(' + value + ')')
128
- break
129
- }
130
- } catch (e) {
131
- console.log(e)
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
132
167
  }
168
+ } catch (e) {
169
+ console.log(e)
133
170
  }
134
171
 
172
+ if (isEqual(this.value, value)) {
173
+ this.requestUpdate()
174
+ return
175
+ }
176
+
177
+ this.value = value
178
+
135
179
  this.requestUpdate()
136
180
  this._onAfterValueChange()
137
181
  }