UNPKG

amis-playground

Version:

amis-playground 是一个amis在线代码编辑器可实时预览运行效果

2 lines (1 loc) 2.15 kB
import{a as y,G as N,R as v,dL as _,e as S,n as A,ar as g,ai as C,dM as R,f as u,p as m,q as h,h as b}from"./index-7c288cb3.js";var k=function(c){y(a,c);function a(e){var r=c.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,d=s.data;e=Array.isArray(e)?e:[e];var l=[];return e.forEach(function(n,p){if(N(n,d)){var o=(r?r+"-":"")+p;l.push(v.createElement(_,S({},n,{title:A(n.title,d),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&&l.push.apply(l,g([],C(t.renderSections(n.children,o)),!1))}}),l.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,d=e.sectionClassName,l=e.direction;e.sectionRender,e.render,e.data;var n=this.props.links;if(!n)return null;var p=this.renderSections(n);return v.createElement(R,{classPrefix:t,classnames:r,className:s,style:i,linkClassName:f,sectionClassName:d,onSelect:this.handleSelect,active:this.state.active,direction:l},p)},a.defaultProps={className:"",linkClassName:"",sectionClassName:""},u([m,h("design:type",Function),h("design:paramtypes",[Object]),h("design:returntype",void 0)],a.prototype,"handleSelect",null),u([m,h("design:type",Function),h("design:paramtypes",[Number]),h("design:returntype",void 0)],a.prototype,"locateTo",null),a}(v.Component),P=function(c){y(a,c);function a(){return c!==null&&c.apply(this,arguments)||this}return a=u([b({type:"anchor-nav"})],a),a}(k);export{P as AnchorNavRenderer,k as default};