tdesign-vue
Version:
149 lines (145 loc) • 5.35 kB
JavaScript
/**
* tdesign v1.14.1
* (c) 2025 tdesign
* @license MIT
*/
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import Vue from 'vue';
import { isEmpty } from 'lodash-es';
import { ANCHOR_SHARP_REGEXP } from './utils.js';
import props from './anchor-item-props.js';
import { getClassPrefixMixins } from '../config-provider/config-receiver.js';
import mixins from '../utils/mixins.js';
import '../config-provider/context.js';
import '../_common/js/global-config/default-config.js';
import '../_common/js/global-config/locale/zh_CN.js';
import '../_chunks/dep-d2f11e9e.js';
import '@babel/runtime/helpers/typeof';
import '../_chunks/dep-05dc6583.js';
import 'dayjs';
import '../_chunks/dep-62386ed0.js';
import '../config-provider/type.js';
import '../_common/js/global-config/t.js';
import '@babel/runtime/helpers/slicedToArray';
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
var classPrefixMixins = getClassPrefixMixins("anchor");
var _AnchorItem = mixins(Vue, classPrefixMixins).extend({
name: "TAnchorItem",
props: _objectSpread(_objectSpread({}, props), {}, {
_level: {
type: Number,
"default": 0
},
href: {
type: String,
required: true,
validator: function validator(v) {
return ANCHOR_SHARP_REGEXP.test(v);
}
}
}),
inject: {
tAnchor: {
"default": void 0
}
},
watch: {
href: {
immediate: true,
handler: function handler() {
this.unregister();
this.register();
}
}
},
destroyed: function destroyed() {
this.unregister();
},
methods: {
register: function register() {
this.tAnchor.registerLink(this.href);
},
unregister: function unregister() {
var href = this.href;
if (!href) return;
this.tAnchor.unregisterLink(href);
},
handleClick: function handleClick(e) {
var href = this.href,
tAnchor = this.tAnchor,
title = this.title;
tAnchor.handleLinkClick({
href: href,
title: typeof title === "string" ? title : void 0,
e: e
});
},
renderTitle: function renderTitle() {
var title = this.title,
$scopedSlots = this.$scopedSlots;
var titleSlot = $scopedSlots.title;
var titleVal;
if (typeof title === "string") {
titleVal = title;
} else if (typeof title === "function") {
titleVal = title(this.$createElement);
} else if (titleSlot) {
titleVal = titleSlot(null);
}
return titleVal;
}
},
render: function render(h) {
var href = this.href,
target = this.target,
$scopedSlots = this.$scopedSlots,
tAnchor = this.tAnchor;
var children = $scopedSlots["default"],
titleSlot = $scopedSlots.title;
var title = this.renderTitle();
var titleAttr = typeof title === "string" ? title : null;
var isActive = tAnchor.active === href;
var wrapperClass = _defineProperty(_defineProperty({}, "".concat(this.componentName, "__item"), true), this.commonStatusClassName.active, isActive);
var titleClass = _defineProperty({}, "".concat(this.componentName, "__item-link"), true);
var newLevel = this.$props._level + 1;
var h5Tags = [];
var anchorItems = [];
if (children) {
children(null).forEach(function (child) {
if (isEmpty(child.componentOptions)) {
h5Tags.push(h(child.tag, child.data, child.children));
} else {
var _child$componentOptio, _child$componentOptio2, _child$componentOptio3;
anchorItems.push(h((_child$componentOptio = child.componentOptions) === null || _child$componentOptio === void 0 ? void 0 : _child$componentOptio.Ctor, {
props: _objectSpread(_objectSpread({}, (_child$componentOptio2 = child.componentOptions) === null || _child$componentOptio2 === void 0 ? void 0 : _child$componentOptio2.propsData), {}, {
_level: newLevel
})
}, child === null || child === void 0 || (_child$componentOptio3 = child.componentOptions) === null || _child$componentOptio3 === void 0 ? void 0 : _child$componentOptio3.children));
}
});
}
return h("div", {
"style": {
display: "contents"
}
}, [h("div", {
"class": wrapperClass,
"style": {
"--level": newLevel
}
}, [h("a", {
"attrs": {
"href": href,
"title": titleAttr,
"target": target
},
"class": titleClass,
"on": {
"click": this.handleClick
}
}, [titleSlot ? titleSlot(null) : title]), h5Tags]), anchorItems]);
}
});
export { _AnchorItem as default };
//# sourceMappingURL=anchor-item.js.map