2 lines
2.1 KiB
JavaScript
2 lines
2.1 KiB
JavaScript
import{t as y,a5 as N,l as p,dZ as _,z as S,L as A,aQ as g,aK as C,d_ as R,D as u,Q as m,T as d,E as b}from"./index-CEmnTf-r.js";var E=function(l){y(a,l);function a(e){var r=l.call(this,e)||this,t=e.links,s=0;if(typeof e.active<"u")s=e.active;else{var i=r.getActiveSection(t,e.active,null);s=i&&i.href?i.href:t[0]&&t[0].href||0}return r.state={active:s},r}return a.prototype.getActiveSection=function(e,r,t){var s=this;return t||(e.forEach(function(i){i.href===r?t=i:i.children&&s.getActiveSection(i.children,r,t)}),t)},a.prototype.handleSelect=function(e){this.setState({active:e})},a.prototype.locateTo=function(e){var r=this.props.links;Array.isArray(r)&&r[e]&&this.setState({active:r[e].href||e})},a.prototype.renderSections=function(e,r){var t=this,s=this.props;s.classnames,s.classPrefix;var i=s.sectionRender,f=s.render,h=s.data;e=Array.isArray(e)?e:[e];var c=[];return e.forEach(function(n,v){if(N(n,h)){var o=(r?r+"-":"")+v;c.push(p.createElement(_,S({},n,{title:A(n.title,h),key:o,name:n.href||o}),t.renderSection?t.renderSection(n,t.props,o):i?i(n,t.props,o):f("section/".concat(o),n.body||""))),n.children&&c.push.apply(c,g([],C(t.renderSections(n.children,o)),!1))}}),c.filter(function(n){return!!n})},a.prototype.render=function(){var e=this.props,r=e.classnames,t=e.classPrefix,s=e.className,i=e.style,f=e.linkClassName,h=e.sectionClassName,c=e.direction;e.sectionRender,e.render,e.data;var n=this.props.links;if(!n)return null;var v=this.renderSections(n);return p.createElement(R,{classPrefix:t,classnames:r,className:s,style:i,linkClassName:f,sectionClassName:h,onSelect:this.handleSelect,active:this.state.active,direction:c},v)},a.defaultProps={className:"",linkClassName:"",sectionClassName:""},u([m,d("design:type",Function),d("design:paramtypes",[Object]),d("design:returntype",void 0)],a.prototype,"handleSelect",null),u([m,d("design:type",Function),d("design:paramtypes",[Number]),d("design:returntype",void 0)],a.prototype,"locateTo",null),a}(p.Component),P=function(l){y(a,l);function a(){return l!==null&&l.apply(this,arguments)||this}return a=u([b({type:"anchor-nav"})],a),a}(E);export{P as AnchorNavRenderer,E as default};
|