@dataloop-ai/components 0.20.259-new-json.0 → 0.20.259-new-json.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dataloop-ai/components",
3
- "version": "0.20.259-new-json.0",
3
+ "version": "0.20.259-new-json.1",
4
4
  "exports": {
5
5
  ".": "./index.ts",
6
6
  "./models": "./models.ts",
@@ -42,7 +42,7 @@
42
42
  "tokenizr": "^1.7.0",
43
43
  "uuid": "^8.3.2",
44
44
  "v-wave": "^1.5.0",
45
- "vanilla-jsoneditor": "^0.15.1",
45
+ "vanilla-jsoneditor": "^0.10.4",
46
46
  "vue-demi": "^0.14.5",
47
47
  "vue-sortable": "^0.1.3",
48
48
  "vue2-teleport": "^1.0.1"
@@ -75,6 +75,28 @@ export default defineComponent({
75
75
  const jsonEditorRef = ref(null)
76
76
  const jsonEditor = ref<JSONEditor>(null as any)
77
77
  const innerUpdate = ref(false)
78
+ const suppressProgrammaticFocus = ref(false)
79
+
80
+ const blurEditorIfFocused = () => {
81
+ const target = jsonEditorRef.value as HTMLElement | null
82
+ if (target?.contains(document.activeElement)) {
83
+ ;(document.activeElement as HTMLElement)?.blur()
84
+ }
85
+ }
86
+
87
+ const runWithoutAutoFocus = (fn: () => void) => {
88
+ if (autoFocus.value) {
89
+ fn()
90
+ return
91
+ }
92
+
93
+ suppressProgrammaticFocus.value = true
94
+ fn()
95
+ nextTick(() => {
96
+ blurEditorIfFocused()
97
+ suppressProgrammaticFocus.value = false
98
+ })
99
+ }
78
100
 
79
101
  watch(modelValue, (val) => {
80
102
  if (innerUpdate.value) {
@@ -82,15 +104,19 @@ export default defineComponent({
82
104
  return
83
105
  }
84
106
 
85
- jsonEditor.value?.set({
86
- text: val
107
+ runWithoutAutoFocus(() => {
108
+ jsonEditor.value?.set({
109
+ text: val
110
+ })
87
111
  })
88
112
  })
89
113
 
90
114
  watch(mode, (val) => {
91
- jsonEditor.value?.updateProps({
92
- mode: val,
93
- readOnly: val === Mode.tree
115
+ runWithoutAutoFocus(() => {
116
+ jsonEditor.value?.updateProps({
117
+ mode: val,
118
+ readOnly: val === Mode.tree
119
+ })
94
120
  })
95
121
  })
96
122
 
@@ -142,6 +168,10 @@ export default defineComponent({
142
168
  navigationBar: false,
143
169
  statusBar: false,
144
170
  onFocus: () => {
171
+ if (suppressProgrammaticFocus.value) {
172
+ blurEditorIfFocused()
173
+ return
174
+ }
145
175
  emit('focus')
146
176
  },
147
177
  onBlur: () => {
@@ -159,21 +189,22 @@ export default defineComponent({
159
189
  props: initialAttrs
160
190
  })
161
191
 
162
- jsonEditor.value?.set({
163
- text: modelValue.value
164
- })
192
+ runWithoutAutoFocus(() => {
193
+ jsonEditor.value?.set({
194
+ text: modelValue.value
195
+ })
165
196
 
166
- nextTick(() => {
167
- jsonEditor.value?.refresh()
168
- if (autoFocus.value) {
169
- jsonEditor.value?.focus()
170
- }
197
+ nextTick(() => {
198
+ jsonEditor.value?.refresh()
199
+ })
171
200
  })
172
201
  }
173
202
 
174
203
  watch(readonly, (val) => {
175
- jsonEditor.value?.updateProps({
176
- readOnly: val || mode.value === Mode.tree
204
+ runWithoutAutoFocus(() => {
205
+ jsonEditor.value?.updateProps({
206
+ readOnly: val || mode.value === Mode.tree
207
+ })
177
208
  })
178
209
  })
179
210