2 lines
11 KiB
JavaScript
2 lines
11 KiB
JavaScript
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("primereact/utils"),n=require("primereact/ripple");function r(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var a=r(e);function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function o(e){if(Array.isArray(e))return i(e)}function l(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}function s(e,t){if(e){if("string"==typeof e)return i(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?i(e,t):void 0}}function c(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function u(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function p(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function d(e,t,n){return t&&p(e.prototype,t),n&&p(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e}function f(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function b(e,t){return b=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},b(e,t)}function h(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&b(e,t)}function v(e){return v="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},v(e)}function y(e,t){if(t&&("object"===v(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return u(e)}function m(e){return m=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},m(e)}function w(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function k(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function g(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?k(Object(n),!0).forEach((function(t){w(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):k(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function T(e){var t=C();return function(){var n,r=m(e);if(t){var a=m(this).constructor;n=Reflect.construct(r,arguments,a)}else n=r.apply(this,arguments);return y(this,n)}}function C(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}var I=function(t){h(r,e.Component);var n=T(r);function r(){return f(this,r),n.apply(this,arguments)}return d(r)}();w(I,"defaultProps",{header:null,headerTemplate:null,leftIcon:null,rightIcon:null,closable:!1,disabled:!1,style:null,className:null,headerStyle:null,headerClassName:null,contentStyle:null,contentClassName:null});var O=function(r){h(p,e.Component);var i=T(p);function p(e){var t;f(this,p),t=i.call(this,e);var n={id:e.id,backwardIsDisabled:!0,forwardIsDisabled:!1,hiddenTabs:[]};return t.props.onTabChange||(n=g(g({},n),{},{activeIndex:e.activeIndex})),t.state=n,t.navBackward=t.navBackward.bind(u(t)),t.navForward=t.navForward.bind(u(t)),t.onScroll=t.onScroll.bind(u(t)),t}return d(p,[{key:"getActiveIndex",value:function(){return this.props.onTabChange?this.props.activeIndex:this.state.activeIndex}},{key:"isSelected",value:function(e){return e===this.getActiveIndex()}},{key:"shouldTabRender",value:function(e,t){return e&&e.type===I&&this.state.hiddenTabs.every((function(e){return e!==t}))}},{key:"findVisibleActiveTab",value:function(e){var t=this,n=a.default.Children.map(this.props.children,(function(e,n){if(t.shouldTabRender(e,n))return{tab:e,index:n}}));return n.find((function(t){return!t.tab.props.disabled&&t.index>=e}))||n.reverse().find((function(t){return!t.tab.props.disabled&&e>t.index}))}},{key:"onTabHeaderClose",value:function(e,t){var n,r=this,a=[].concat(o(n=this.state.hiddenTabs)||l(n)||s(n)||c(),[t]);this.setState({hiddenTabs:a},(function(){var n=r.findVisibleActiveTab(t);n&&r.onTabHeaderClick(e,n.tab,n.index)})),this.props.onTabClose&&this.props.onTabClose({originalEvent:e,index:t}),e.preventDefault()}},{key:"onTabHeaderClick",value:function(e,t,n){t.props.disabled||(this.props.onTabChange?this.props.onTabChange({originalEvent:e,index:n}):this.setState({activeIndex:n})),this.updateScrollBar(n),e.preventDefault()}},{key:"onKeyDown",value:function(e,t,n){"Enter"===e.code&&this.onTabHeaderClick(e,t,n)}},{key:"updateInkBar",value:function(){var e=this.getActiveIndex(),n=this["tab_".concat(e)];this.inkbar.style.width=t.DomHandler.getWidth(n)+"px",this.inkbar.style.left=t.DomHandler.getOffset(n).left-t.DomHandler.getOffset(this.nav).left+"px"}},{key:"updateScrollBar",value:function(e){var t=this["tab_".concat(e)];t&&t.scrollIntoView({block:"nearest"})}},{key:"updateButtonState",value:function(){var e=this.content,n=e.scrollLeft,r=e.scrollWidth,a=t.DomHandler.getWidth(e);this.setState({backwardIsDisabled:0===n}),this.setState({forwardIsDisabled:n===r-a})}},{key:"onScroll",value:function(e){this.props.scrollable&&this.updateButtonState(),e.preventDefault()}},{key:"getVisibleButtonWidths",value:function(){return[this.prevBtn,this.nextBtn].reduce((function(e,n){return n?e+t.DomHandler.getWidth(n):e}),0)}},{key:"navBackward",value:function(){var e=this.content,n=t.DomHandler.getWidth(e)-this.getVisibleButtonWidths(),r=e.scrollLeft-n;e.scrollLeft=r<=0?0:r}},{key:"navForward",value:function(){var e=this.content,n=t.DomHandler.getWidth(e)-this.getVisibleButtonWidths(),r=e.scrollLeft+n,a=e.scrollWidth-n;e.scrollLeft=r>=a?a:r}},{key:"reset",value:function(){var e={backwardIsDisabled:!0,forwardIsDisabled:!1,hiddenTabs:[]};this.props.onTabChange?this.props.onTabChange({index:this.props.activeIndex}):e=g(g({},e),{},{activeIndex:this.props.activeIndex}),this.setState(e)}},{key:"componentDidMount",value:function(){this.state.id||this.setState({id:t.UniqueComponentId()}),this.updateInkBar()}},{key:"componentDidUpdate",value:function(e){this.updateInkBar(),e.activeIndex!==this.props.activeIndex&&this.updateScrollBar(this.props.activeIndex)}},{key:"renderTabHeader",value:function(e,r){var i=this,o=this.isSelected(r),l=g(g({},e.props.headerStyle||{}),e.props.style||{}),s=t.classNames("p-unselectable-text",{"p-tabview-selected p-highlight":o,"p-disabled":e.props.disabled},e.props.headerClassName,e.props.className),c=this.state.id+"_header_"+r,u=this.state.id+"_content_"+r,p=e.props.disabled?null:0,d=e.props.leftIcon&&a.default.createElement("i",{className:e.props.leftIcon}),f=a.default.createElement("span",{className:"p-tabview-title"},e.props.header),b=e.props.rightIcon&&a.default.createElement("i",{className:e.props.rightIcon}),h=a.default.createElement("a",{role:"tab",className:"p-tabview-nav-link",onClick:function(t){return i.onTabHeaderClick(t,e,r)},id:c,onKeyDown:function(t){return i.onKeyDown(t,e,r)},"aria-controls":u,"aria-selected":o,tabIndex:p},d,f,b,e.props.closable&&a.default.createElement("i",{className:"p-tabview-close pi pi-times",onClick:function(e){return i.onTabHeaderClose(e,r)}}),a.default.createElement(n.Ripple,null));e.props.headerTemplate&&(h=t.ObjectUtils.getJSXElement(e.props.headerTemplate,{className:"p-tabview-nav-link",titleClassName:"p-tabview-title",onClick:function(t){return i.onTabHeaderClick(t,e,r)},onKeyDown:function(t){return i.onKeyDown(t,e,r)},leftIconElement:d,titleElement:f,rightIconElement:b,element:h,props:this.props,index:r,selected:o,ariaControls:u}));return a.default.createElement("li",{ref:function(e){return i["tab_".concat(r)]=e},className:s,style:l,role:"presentation"},h)}},{key:"renderTabHeaders",value:function(){var e=this;return a.default.Children.map(this.props.children,(function(t,n){if(e.shouldTabRender(t,n))return e.renderTabHeader(t,n)}))}},{key:"renderNavigator",value:function(){var e=this,t=this.renderTabHeaders();return a.default.createElement("div",{ref:function(t){return e.content=t},id:this.props.id,className:"p-tabview-nav-content",style:this.props.style,onScroll:this.onScroll},a.default.createElement("ul",{ref:function(t){return e.nav=t},className:"p-tabview-nav",role:"tablist"},t,a.default.createElement("li",{ref:function(t){return e.inkbar=t},className:"p-tabview-ink-bar"})))}},{key:"renderContent",value:function(){var e=this,t=a.default.Children.map(this.props.children,(function(t,n){if(e.shouldTabRender(t,n)&&(!e.props.renderActiveOnly||e.isSelected(n)))return e.createContent(t,n)}));return a.default.createElement("div",{className:"p-tabview-panels"},t)}},{key:"createContent",value:function(e,n){var r=this.isSelected(n),i=g(g({},e.props.contentStyle||{}),e.props.style||{}),o=t.classNames(e.props.contentClassName,e.props.className,"p-tabview-panel",{"p-hidden":!r});return a.default.createElement("div",{id:this.state.id+"_content_"+n,"aria-labelledby":this.state.id+"_header_"+n,"aria-hidden":!r,className:o,style:i,role:"tabpanel"},this.props.renderActiveOnly?r&&e.props.children:e.props.children)}},{key:"renderPrevButton",value:function(){var e=this;return this.props.scrollable&&!this.state.backwardIsDisabled?a.default.createElement("button",{ref:function(t){return e.prevBtn=t},className:"p-tabview-nav-prev p-tabview-nav-btn p-link",onClick:this.navBackward,type:"button"},a.default.createElement("span",{className:"pi pi-chevron-left"}),a.default.createElement(n.Ripple,null)):null}},{key:"renderNextButton",value:function(){var e=this;if(this.props.scrollable&&!this.state.forwardIsDisabled)return a.default.createElement("button",{ref:function(t){return e.nextBtn=t},className:"p-tabview-nav-next p-tabview-nav-btn p-link",onClick:this.navForward,type:"button"},a.default.createElement("span",{className:"pi pi-chevron-right"}),a.default.createElement(n.Ripple,null))}},{key:"render",value:function(){var e=t.classNames("p-tabview p-component",this.props.className,{"p-tabview-scrollable":this.props.scrollable}),n=this.renderNavigator(),r=this.renderContent(),i=this.renderPrevButton(),o=this.renderNextButton();return a.default.createElement("div",{className:e},a.default.createElement("div",{className:"p-tabview-nav-container"},i,n,o),r)}}]),p}();w(O,"defaultProps",{id:null,activeIndex:0,style:null,className:null,renderActiveOnly:!0,onTabChange:null,onTabClose:null,scrollable:!1}),exports.TabPanel=I,exports.TabView=O;
|