webcake-ui-kit 1.1.10 → 1.1.11
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
|
@@ -184,6 +184,14 @@ export default {
|
|
|
184
184
|
}
|
|
185
185
|
},
|
|
186
186
|
|
|
187
|
+
mounted() {
|
|
188
|
+
this._syncSlotLabels()
|
|
189
|
+
},
|
|
190
|
+
|
|
191
|
+
updated() {
|
|
192
|
+
this._syncSlotLabels()
|
|
193
|
+
},
|
|
194
|
+
|
|
187
195
|
computed: {
|
|
188
196
|
effectiveValue() {
|
|
189
197
|
return this.modelValue !== null ? this.modelValue : this.value
|
|
@@ -220,8 +228,9 @@ export default {
|
|
|
220
228
|
if (this.isMultiMode) return ''
|
|
221
229
|
if (!this.effectiveValue) return ''
|
|
222
230
|
if (this.labelCache[this.effectiveValue]) return this.labelCache[this.effectiveValue]
|
|
223
|
-
|
|
224
|
-
|
|
231
|
+
const opt = this.normalizedOptions.find(o => o.value === this.effectiveValue)
|
|
232
|
+
if (opt) return opt.label
|
|
233
|
+
return this._findLabelInSlot(this.effectiveValue) || this.effectiveValue
|
|
225
234
|
},
|
|
226
235
|
selectedItems() {
|
|
227
236
|
if (!this.isMultiMode) return []
|
|
@@ -354,6 +363,42 @@ export default {
|
|
|
354
363
|
},
|
|
355
364
|
registerOption(value, label) {
|
|
356
365
|
this.labelCache = Object.assign({}, this.labelCache, { [value]: label })
|
|
366
|
+
},
|
|
367
|
+
_slotNodes() {
|
|
368
|
+
// Vue 3: $slots.default is a function; Vue 2: it's an array
|
|
369
|
+
return typeof this.$slots.default === 'function' ? this.$slots.default() : this.$slots.default || []
|
|
370
|
+
},
|
|
371
|
+
_syncSlotLabels() {
|
|
372
|
+
const collect = nodes => {
|
|
373
|
+
if (!Array.isArray(nodes)) return
|
|
374
|
+
nodes.forEach(vnode => {
|
|
375
|
+
if (!vnode) return
|
|
376
|
+
const props = vnode.props || (vnode.componentOptions && vnode.componentOptions.propsData)
|
|
377
|
+
if (props && props.value != null && props.label) {
|
|
378
|
+
this.registerOption(String(props.value), String(props.label))
|
|
379
|
+
}
|
|
380
|
+
if (Array.isArray(vnode.children)) collect(vnode.children)
|
|
381
|
+
})
|
|
382
|
+
}
|
|
383
|
+
collect(this._slotNodes())
|
|
384
|
+
},
|
|
385
|
+
_findLabelInSlot(value) {
|
|
386
|
+
const scan = nodes => {
|
|
387
|
+
if (!Array.isArray(nodes)) return null
|
|
388
|
+
for (const vnode of nodes) {
|
|
389
|
+
if (!vnode) continue
|
|
390
|
+
const props = vnode.props || (vnode.componentOptions && vnode.componentOptions.propsData)
|
|
391
|
+
if (props && String(props.value) === String(value) && props.label) {
|
|
392
|
+
return String(props.label)
|
|
393
|
+
}
|
|
394
|
+
if (Array.isArray(vnode.children)) {
|
|
395
|
+
const found = scan(vnode.children)
|
|
396
|
+
if (found) return found
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
return null
|
|
400
|
+
}
|
|
401
|
+
return scan(this._slotNodes())
|
|
357
402
|
}
|
|
358
403
|
}
|
|
359
404
|
}
|