UNPKG

@cocalc/static

Version:

CoCalc's static frontend Webpack-based build system and framework

1 lines 9.83 kB
"use strict";(self.webpackChunk_cocalc_static=self.webpackChunk_cocalc_static||[]).push([[8944],{98944:(t,e,r)=>{r.r(e),r.d(e,{Actions:()=>R});var n=r(4538),o=r(24620),i=r(56160),u=r(85460),a=r(20812),c=r(32295),s=r(1527),l=r(38198),f=r(11737),h=r(94873);function _(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}function p(t,e,r,n,o,i,u){try{var a=t[i](u),c=a.value}catch(t){return void r(t)}a.done?e(c):Promise.resolve(c).then(n,o)}function d(t){return function(){var e=this,r=arguments;return new Promise((function(n,o){var i=t.apply(e,r);function u(t){p(i,n,o,u,a,"next",t)}function a(t){p(i,n,o,u,a,"throw",t)}u(void 0)}))}}function y(t){return function(t){if(Array.isArray(t))return _(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||function(t,e){if(t){if("string"==typeof t)return _(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(r):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?_(t,e):void 0}}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}var b=function(t,e){var r,n,o,i,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(i){return function(a){return function(i){if(r)throw new TypeError("Generator is already executing.");for(;u;)try{if(r=1,n&&(o=2&i[0]?n.return:i[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,i[1])).done)return o;switch(n=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return u.label++,{value:i[1],done:!1};case 5:u.label++,n=i[1],i=[0];continue;case 7:i=u.ops.pop(),u.trys.pop();continue;default:if(!((o=(o=u.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){u=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){u.label=i[1];break}if(6===i[0]&&u.label<o[1]){u.label=o[1],o=i;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(i);break}o[2]&&u.ops.pop(),u.trys.pop();continue}i=e.call(t,u)}catch(t){i=[6,t],n=0}finally{r=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,a])}}},v=(0,i.reuseInFlight)((function(t){return m.apply(this,arguments)})),g=["--log-level","info"];function m(){return(m=d((function(t){var e,r,n,i,u,a;return b(this,(function(c){switch(c.label){case 0:return e=t.project_id,r=t.path,n=t.hash,i=(0,o.path_split)(r),u=i.tail,a=["render",u].concat(y(g)),[4,(0,h.GL)({timeout:240,bash:!0,command:"quarto",args:a,project_id:e,path:i.head,err_on_exit:!1,aggregate:{value:n}})];case 1:return[2,c.sent()]}}))}))).apply(this,arguments)}function w(t,e,r,n,o,i,u){try{var a=t[i](u),c=a.value}catch(t){return void r(t)}a.done?e(c):Promise.resolve(c).then(n,o)}function S(t){return function(){var e=this,r=arguments;return new Promise((function(n,o){var i=t.apply(e,r);function u(t){w(i,n,o,u,a,"next",t)}function a(t){w(i,n,o,u,a,"throw",t)}u(void 0)}))}}function k(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function j(t,e,r){return j="undefined"!=typeof Reflect&&Reflect.get?Reflect.get:function(t,e,r){var n=function(t,e){for(;!Object.prototype.hasOwnProperty.call(t,e)&&null!==(t=x(t)););return t}(t,e);if(n){var o=Object.getOwnPropertyDescriptor(n,e);return o.get?o.get.call(r):o.value}},j(t,e,r||t)}function x(t){return x=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)},x(t)}function O(t,e){return!e||"object"!==P(e)&&"function"!=typeof e?function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t):e}function q(t,e){return q=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t},q(t,e)}var P=function(t){return t&&"undefined"!=typeof Symbol&&t.constructor===Symbol?"symbol":typeof t};var A=function(t,e){var r,n,o,i,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(i){return function(a){return function(i){if(r)throw new TypeError("Generator is already executing.");for(;u;)try{if(r=1,n&&(o=2&i[0]?n.return:i[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,i[1])).done)return o;switch(n=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return u.label++,{value:i[1],done:!1};case 5:u.label++,n=i[1],i=[0];continue;case 7:i=u.ops.pop(),u.trys.pop();continue;default:if(!((o=(o=u.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){u=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){u.label=i[1];break}if(6===i[0]&&u.label<o[1]){u.label=o[1],o=i;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(i);break}o[2]&&u.ops.pop(),u.trys.pop();continue}i=e.call(t,u)}catch(t){i=[6,t],n=0}finally{r=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,a])}}},R=function(t){!function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&q(t,e)}(h,t);var e,r,l=(e=h,r=function(){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(t){return!1}}(),function(){var t,n=x(e);if(r){var o=x(this).constructor;t=Reflect.construct(n,arguments,o)}else t=n.apply(this,arguments);return O(this,t)});function h(){var t;return k(this,h),(t=l.apply(this,arguments))._last_qmd_hash=null,t.is_building=!1,t}var _=h.prototype;return _._init2=function(){j(x(h.prototype),"_init2",this).call(this),this.is_public||(this._syncstring.once("ready",this._init_qmd_converter.bind(this)),this._check_produced_files(),this.setState({custom_pdf_error_message:"\nNo PDF file has been generated.\n"}))},_.do_implicit_builds=function(){var t=this.redux.getStore("account");return null==t||!!t.getIn(["editor_settings","build_on_save"])},_._init_qmd_converter=function(){var t,e=this;this.run_qmd_converter=(0,a.debounce)((t=S((function(t){return A(this,(function(r){switch(r.label){case 0:return[4,e._run_qmd_converter(t)];case 1:return[2,r.sent()]}}))})),function(e){return t.apply(this,arguments)}),5e3,{leading:!0,trailing:!1});var r=this,n=(0,i.reuseInFlight)(S((function(){var t;return A(this,(function(e){switch(e.label){case 0:return r.do_implicit_builds()?null==r._syncstring?[2]:(t=r._syncstring.hash_of_saved_version(),r._last_qmd_hash==t?[3,2]:(r._last_qmd_hash=t,[4,r.run_qmd_converter()])):[2];case 1:e.sent(),e.label=2;case 2:return[2]}}))})));this._syncstring.on("save-to-disk",n),this._syncstring.on("after-change",n),this.run_qmd_converter()},_.build=function(t){var e=this;return S((function(){var r;return A(this,(function(n){switch(n.label){case 0:if(t&&(r=e._get_cm(t))&&r.focus(),e.is_building)return[2];e.is_building=!0,n.label=1;case 1:return n.trys.push([1,,4,5]),[4,e.redux.getEditorActions(e.project_id,e.path).save(!1)];case 2:return n.sent(),[4,e.run_qmd_converter(Date.now())];case 3:return n.sent(),[3,5];case 4:return e.is_building=!1,[7];case 5:return[2]}}))}))()},_._check_produced_files=function(){var t=this;return S((function(){var e,r,i,a,s,l,h,_,p;return A(this,(function(d){switch(d.label){case 0:return e=function(e,r){var n=r[e],i=(0,f.l)(t.path,n);l.some((function(t){return t.get("name")===(0,o.path_split)(i).tail}))&&(h=h.add(n))},null==(r=c.redux.getProjectActions(t.project_id))?[2]:(i=(0,o.path_split)(t.path).head,[4,(0,n.callback2)(r.fetch_directory_listing,{path:i})]);case 1:if(d.sent(),null==(a=r.get_store()))return[2];if(null==(s=a.get("directory_listings")))return[2];if(null==(l=s.get(i)))return[2];for(h=(0,u.Set)(),_=0,p=["pdf","html","nb.html"];_<p.length;_++)e(_,p);return t.setState({derived_file_types:h}),[2]}}))}))()},_.set_log=function(t){this.setState({build_err:null==t?void 0:t.stderr.trim(),build_log:null==t?void 0:t.stdout.trim(),build_exit:null==t?void 0:t.exit_code})},_._run_qmd_converter=function(t){var e=this;return S((function(){var r,n,o,i,u,a,c;return A(this,(function(l){switch(l.label){case 0:if(null==e._syncstring||"ready"!=e._syncstring.get_state())return[2];if(null==e._last_qmd_hash&&(e._last_qmd_hash=e._syncstring.hash_of_saved_version()),null==(r=e._syncstring.to_str()))return[2];e.set_status("Running Quarto..."),e.setState({building:!0}),e.set_error(""),e.setState({build_log:"",build_err:""}),n="",o=void 0,l.label=1;case 1:return l.trys.push([1,6,7,8]),i=(0,s.markdown_to_html_frontmatter)(r),u=i.frontmatter,a=i.html,n=a,[4,v({project_id:e.project_id,path:e.path,frontmatter:u,hash:t||e._last_qmd_hash})];case 2:return o=l.sent(),e.set_log(o),null!=o&&0==o.exit_code?[3,3]:(e.set_error("Error compiling file using Quarto. Please check the Build Log!"),[3,5]);case 3:return e.reload(),[4,e._check_produced_files()];case 4:l.sent(),l.label=5;case 5:return[3,8];case 6:return c=l.sent(),e.set_error(c,"monospace"),e.set_log(o),[2];case 7:return e.set_status(""),e.setState({building:!1}),[7];case 8:return e.setState({value:n}),[2]}}))}))()},_._raw_default_frame_tree=function(){return this.is_public?{type:"cm"}:{direction:"col",type:"node",first:{type:"cm"},second:{type:"node",direction:"row",first:{type:"iframe"},second:{type:"build"},pos:.8}}},_.reload=function(t,e){var r=this;e=e||Date.now(),["iframe","pdfjs_canvas","markdown"].forEach((function(t){return r.set_reload(t,e)}))},_.delete_trailing_whitespace=function(){},h}(l.Actions)}}]);