@dataloop-ai/components 0.20.259 → 0.20.260

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",
3
+ "version": "0.20.260",
4
4
  "exports": {
5
5
  ".": "./index.ts",
6
6
  "./models": "./models.ts",
@@ -53,6 +53,11 @@ export default defineComponent({
53
53
  required: false,
54
54
  type: String as PropType<Mode>,
55
55
  default: Mode.text
56
+ },
57
+ autoFocus: {
58
+ required: false,
59
+ type: Boolean,
60
+ default: true
56
61
  }
57
62
  },
58
63
  emits: [
@@ -64,11 +69,20 @@ export default defineComponent({
64
69
  'blur'
65
70
  ],
66
71
  setup(props, { emit }) {
67
- const { modelValue, indentation, readonly, mode } = toRefs(props)
72
+ const { modelValue, indentation, readonly, mode, autoFocus } =
73
+ toRefs(props)
68
74
 
69
75
  const jsonEditorRef = ref(null)
70
76
  const jsonEditor = ref<JSONEditor>(null as any)
71
77
  const innerUpdate = ref(false)
78
+ const suppressNextFocus = ref(false)
79
+
80
+ const blurActiveEditorElement = () => {
81
+ const target = jsonEditorRef.value as HTMLElement | null
82
+ if (target?.contains(document.activeElement)) {
83
+ ;(document.activeElement as HTMLElement)?.blur()
84
+ }
85
+ }
72
86
 
73
87
  watch(modelValue, (val) => {
74
88
  if (innerUpdate.value) {
@@ -76,9 +90,18 @@ export default defineComponent({
76
90
  return
77
91
  }
78
92
 
93
+ if (!autoFocus.value) {
94
+ suppressNextFocus.value = true
95
+ }
79
96
  jsonEditor.value?.set({
80
97
  text: val
81
98
  })
99
+ if (!autoFocus.value) {
100
+ nextTick(() => {
101
+ blurActiveEditorElement()
102
+ suppressNextFocus.value = false
103
+ })
104
+ }
82
105
  })
83
106
 
84
107
  watch(mode, (val) => {
@@ -136,6 +159,10 @@ export default defineComponent({
136
159
  navigationBar: false,
137
160
  statusBar: false,
138
161
  onFocus: () => {
162
+ if (suppressNextFocus.value) {
163
+ blurActiveEditorElement()
164
+ return
165
+ }
139
166
  emit('focus')
140
167
  },
141
168
  onBlur: () => {
@@ -156,10 +183,15 @@ export default defineComponent({
156
183
  jsonEditor.value?.set({
157
184
  text: modelValue.value
158
185
  })
159
-
160
186
  nextTick(() => {
161
187
  jsonEditor.value?.refresh()
162
188
  })
189
+
190
+ if (!autoFocus.value) {
191
+ nextTick(() => {
192
+ blurActiveEditorElement()
193
+ })
194
+ }
163
195
  }
164
196
 
165
197
  watch(readonly, (val) => {