2 lines
5.9 KiB
JavaScript
2 lines
5.9 KiB
JavaScript
this.primereact=this.primereact||{},this.primereact.terminal=function(e,t,n,r){"use strict";function o(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var a=o(t);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 c(e){if(Array.isArray(e))return i(e)}function s(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}function l(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 u(){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 p(e){return c(e)||s(e)||l(e)||u()}function f(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function m(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){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function y(e,t){return y=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},y(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&&y(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 b(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 d(e)}function g(e){return g=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},g(e)}function w(){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 k,C,S,x=function(e){h(u,e);var t,o,i,c,s,l=(t=u,o=w(),function(){var e,n=g(t);if(o){var r=g(this).constructor;e=Reflect.construct(n,arguments,r)}else e=n.apply(this,arguments);return b(this,e)});function u(e){var t;return f(this,u),(t=l.call(this,e)).state={commandText:"",commands:[],index:0},t.onClick=t.onClick.bind(d(t)),t.onInputChange=t.onInputChange.bind(d(t)),t.onInputKeyDown=t.onInputKeyDown.bind(d(t)),t.response=t.response.bind(d(t)),t.clear=t.clear.bind(d(t)),t}return i=u,(c=[{key:"onClick",value:function(){this.input.focus()}},{key:"onInputChange",value:function(e){this.setState({commandText:e.target.value})}},{key:"onInputKeyDown",value:function(e){var t=this.state.commands;switch(e.which||e.keyCode){case 38:if(t&&t.length){var r=this.state.index-1<0?t.length-1:this.state.index-1;this.setState({index:r,commandText:t[r].text})}break;case 13:if(this.state.commandText){var o=p(t),a=this.state.commandText;o.push({text:a}),this.setState((function(e){return{index:e.index+1,commandText:"",commands:o}}),(function(){n.TerminalService.emit("command",a)}))}}}},{key:"response",value:function(e){var t=this.state.commands;if(t&&t.length>0){var n=p(t);n[n.length-1].response=e,this.setState({commands:n})}}},{key:"clear",value:function(){this.setState({commands:[],index:0})}},{key:"componentDidMount",value:function(){n.TerminalService.on("response",this.response),n.TerminalService.on("clear",this.clear)}},{key:"componentDidUpdate",value:function(){this.container.scrollTop=this.container.scrollHeight}},{key:"componentWillUnmount",value:function(){n.TerminalService.off("response",this.response),n.TerminalService.off("clear",this.clear)}},{key:"renderWelcomeMessage",value:function(){return this.props.welcomeMessage?a.default.createElement("div",null,this.props.welcomeMessage):null}},{key:"renderCommand",value:function(e,t){var n=e.text,r=e.response;return a.default.createElement("div",{key:"".concat(n).concat(t)},a.default.createElement("span",{className:"p-terminal-prompt"},this.props.prompt," "),a.default.createElement("span",{className:"p-terminal-command"},n),a.default.createElement("div",{className:"p-terminal-response"},r))}},{key:"renderContent",value:function(){var e=this,t=this.state.commands.map((function(t,n){return e.renderCommand(t,n)}));return a.default.createElement("div",{className:"p-terminal-content"},t)}},{key:"renderPromptContainer",value:function(){var e=this;return a.default.createElement("div",{className:"p-terminal-prompt-container"},a.default.createElement("span",{className:"p-terminal-prompt"},this.props.prompt," "),a.default.createElement("input",{ref:function(t){return e.input=t},type:"text",value:this.state.commandText,className:"p-terminal-input",autoComplete:"off",onChange:this.onInputChange,onKeyDown:this.onInputKeyDown}))}},{key:"render",value:function(){var e=this,t=r.classNames("p-terminal p-component",this.props.className),n=this.renderWelcomeMessage(),o=this.renderContent(),i=this.renderPromptContainer();return a.default.createElement("div",{ref:function(t){return e.container=t},id:this.props.id,className:t,style:this.props.style,onClick:this.onClick},n,o,i)}}])&&m(i.prototype,c),s&&m(i,s),Object.defineProperty(i,"prototype",{writable:!1}),u}(t.Component);return S={id:null,style:null,className:null,welcomeMessage:null,prompt:null},(C="defaultProps")in(k=x)?Object.defineProperty(k,C,{value:S,enumerable:!0,configurable:!0,writable:!0}):k[C]=S,e.Terminal=x,Object.defineProperty(e,"__esModule",{value:!0}),e}({},React,primereact.terminalservice,primereact.utils);
|