text: define(["exports","meta","require","../../../../@polymer/polymer/polymer-element.js","../../../../@polymer/polymer/lib/utils/settings.js","../../../../@polymer/polymer/lib/mixins/element-mixin.js","../../../../@polymer/polymer/lib/utils/render-status.js","../../../../@polymer/polymer/lib/legacy/polymer.dom.js","../../../../@polymer/polymer/lib/utils/resolve-url.js","../../../../@polymer/polymer/lib/utils/async.js","../../../hax-body/lib/haxutils.js","../../../../mobx/lib/mobx.module.js","./haxcms-site-store.js","../../../json-outline-schema/json-outline-schema.js","../../../simple-toast/simple-toast.js","../../../simple-modal/simple-modal.js","../../../../@polymer/iron-ajax/iron-ajax.js","../../../../@polymer/paper-progress/paper-progress.js","./haxcms-site-router.js","./haxcms-editor-builder.js"],function(_exports,meta,_require,_polymerElement,_settings,_elementMixin,_renderStatus,_polymerDom,_resolveUrl,_async,_haxutils,_mobxModule,_haxcmsSiteStore){"use strict";Object.defineProperty(_exports,"__esModule",{value:!0});_exports.HAXCMSSiteBuilder=void 0;meta=babelHelpers.interopRequireWildcard(meta);_require=babelHelpers.interopRequireWildcard(_require);function _templateObject_09cc24e056d411e99e8143b72aec9f54(){var data=babelHelpers.taggedTemplateLiteral(["\n      <style>\n        :host {\n          display: block;\n        }\n        :host #slot {\n          transition: all 0.2s ease-in-out;\n          background-color: var(--haxcms-color, white);\n          opacity: 0.2;\n          visibility: hidden;\n        }\n        :host([theme-loaded]) #slot {\n          opacity: 1;\n          visibility: visible;\n        }\n        paper-progress {\n          display: block;\n          width: 100%;\n          position: fixed;\n          top: 0;\n          left: 0;\n          right: 0;\n          background-color: transparent;\n          z-index: 1000;\n          --paper-progress-active-color: var(\n            --haxcms-color,\n            rgba(255, 255, 255, 0.5)\n          );\n          --paper-progress-container-color: transparent;\n        }\n      </style>\n      <haxcms-site-router base-uri=\"[[baseURI]]\"></haxcms-site-router>\n      <paper-progress hidden$=\"[[!loading]]\" indeterminate></paper-progress>\n      <iron-ajax\n        id=\"manifest\"\n        url=\"[[outlineLocation]][[file]][[__timeStamp]]\"\n        handle-as=\"json\"\n        debounce-duration=\"250\"\n        last-response=\"{{manifest}}\"\n      ></iron-ajax>\n      <iron-ajax\n        id=\"activecontent\"\n        url=\"[[outlineLocation]][[activeItem.location]][[__timeStamp]]\"\n        handle-as=\"text\"\n        loading=\"{{loading}}\"\n        debounce-duration=\"250\"\n        last-response=\"{{activeItemContent}}\"\n      ></iron-ajax>\n      <div id=\"slot\"><slot></slot></div>\n    "],["\n      <style>\n        :host {\n          display: block;\n        }\n        :host #slot {\n          transition: all 0.2s ease-in-out;\n          background-color: var(--haxcms-color, white);\n          opacity: 0.2;\n          visibility: hidden;\n        }\n        :host([theme-loaded]) #slot {\n          opacity: 1;\n          visibility: visible;\n        }\n        paper-progress {\n          display: block;\n          width: 100%;\n          position: fixed;\n          top: 0;\n          left: 0;\n          right: 0;\n          background-color: transparent;\n          z-index: 1000;\n          --paper-progress-active-color: var(\n            --haxcms-color,\n            rgba(255, 255, 255, 0.5)\n          );\n          --paper-progress-container-color: transparent;\n        }\n      </style>\n      <haxcms-site-router base-uri=\"[[baseURI]]\"></haxcms-site-router>\n      <paper-progress hidden\\$=\"[[!loading]]\" indeterminate></paper-progress>\n      <iron-ajax\n        id=\"manifest\"\n        url=\"[[outlineLocation]][[file]][[__timeStamp]]\"\n        handle-as=\"json\"\n        debounce-duration=\"250\"\n        last-response=\"{{manifest}}\"\n      ></iron-ajax>\n      <iron-ajax\n        id=\"activecontent\"\n        url=\"[[outlineLocation]][[activeItem.location]][[__timeStamp]]\"\n        handle-as=\"text\"\n        loading=\"{{loading}}\"\n        debounce-duration=\"250\"\n        last-response=\"{{activeItemContent}}\"\n      ></iron-ajax>\n      <div id=\"slot\"><slot></slot></div>\n    "]);_templateObject_09cc24e056d411e99e8143b72aec9f54=function(){return data};return data}var HAXCMSSiteBuilder=function(_PolymerElement){var _Mathfloor=Math.floor;babelHelpers.inherits(HAXCMSSiteBuilder,_PolymerElement);babelHelpers.createClass(HAXCMSSiteBuilder,null,[{key:"tag",get:function get(){return"haxcms-site-builder"}},{key:"template",get:function get(){return(0,_polymerElement.html)(_templateObject_09cc24e056d411e99e8143b72aec9f54())}},{key:"properties",get:function get(){return{queryParams:{type:Object},loading:{type:Boolean,value:!1,reflectToAttribute:!0},outlineLocation:{type:String,notify:!0,reflectToAttribute:!0},manifest:{type:Object,notify:!0,observer:"_manifestChanged"},themeData:{type:Object,observer:"_themeChanged"},themeElement:{type:Object},__imported:{type:Object,value:{}},themeLoaded:{type:Boolean,reflectToAttribute:!0,value:!1},activeItem:{type:Object,notify:!0,observer:"_activeItemChanged"},activeItemContent:{type:String,notify:!0,observer:"_activeItemContentChanged"},file:{type:String,observer:"_fileChanged"},baseURI:{type:String}}}}]);function HAXCMSSiteBuilder(){var _this;babelHelpers.classCallCheck(this,HAXCMSSiteBuilder);_this=babelHelpers.possibleConstructorReturn(this,babelHelpers.getPrototypeOf(HAXCMSSiteBuilder).call(this));if(document.getElementById("haxcmsoutdatedfallback")){document.body.removeChild(document.getElementById("haxcmsoutdatedfallback"))}_this.__timeStamp="";(0,_settings.setPassiveTouchGestures)(!0);window.JSONOutlineSchema.requestAvailability();(0,_renderStatus.afterNextRender)(babelHelpers.assertThisInitialized(babelHelpers.assertThisInitialized(_this)),function(){window.addEventListener("haxcms-trigger-update",this._triggerUpdatedData.bind(this));window.addEventListener("haxcms-trigger-update-node",this._triggerUpdatedNode.bind(this));window.SimpleToast.requestAvailability()});return _this}babelHelpers.createClass(HAXCMSSiteBuilder,[{key:"ready",value:function ready(){var _this2=this;babelHelpers.get(babelHelpers.getPrototypeOf(HAXCMSSiteBuilder.prototype),"ready",this).call(this);this.__disposer=[];(0,_mobxModule.autorun)(function(reaction){_this2.themeData=(0,_mobxModule.toJS)(_haxcmsSiteStore.store.themeData);_this2.__disposer.push(reaction)})}},{key:"connectedCallback",value:function connectedCallback(){babelHelpers.get(babelHelpers.getPrototypeOf(HAXCMSSiteBuilder.prototype),"connectedCallback",this).call(this);(0,_renderStatus.afterNextRender)(this,function(){var _this3=this;window.SimpleModal.requestAvailability();this.editorBuilder=document.createElement("haxcms-editor-builder");document.body.appendChild(this.editorBuilder);if("published"!==this.editorBuilder.getContext()){this.__timeStamp="?"+_Mathfloor(Date.now()/1e3)}(0,_mobxModule.autorun)(function(reaction){_this3.activeItem=(0,_mobxModule.toJS)(_haxcmsSiteStore.store.activeItem);_this3.__disposer.push(reaction)});this.dispatchEvent(new CustomEvent("haxcms-ready",{bubbles:!0,composed:!0,cancelable:!1,detail:this}))})}},{key:"disconnectedCallback",value:function disconnectedCallback(){window.removeEventListener("haxcms-trigger-update",this._triggerUpdatedData.bind(this));window.removeEventListener("haxcms-trigger-update-node",this._triggerUpdatedNode.bind(this));for(var i in this.__disposer){this.__disposer[i].dispose()}babelHelpers.get(babelHelpers.getPrototypeOf(HAXCMSSiteBuilder.prototype),"disconnectedCallback",this).call(this)}},{key:"_activeItemContentChanged",value:function _activeItemContentChanged(newValue){var _this4=this;if(newValue){var html=newValue;if(null!==html){(0,_haxutils.wipeSlot)(this.themeElement,"*");html=(0,_haxutils.encapScript)(newValue);_haxcmsSiteStore.store.activeItemContent=html;_async.microTask.run(function(){setTimeout(function(){var frag=document.createRange().createContextualFragment(html);(0,_polymerDom.dom)(_this4.themeElement).appendChild(frag);_this4.dispatchEvent(new CustomEvent("json-outline-schema-active-body-changed",{bubbles:!0,composed:!0,cancelable:!1,detail:html}));if(!window.HaxStore||!window.HaxStore.ready){setTimeout(function(){if(window.cmsSiteEditor.instance&&window.cmsSiteEditor.haxCmsSiteEditorUIElement){window.HaxStore.instance.activeHaxBody.importContent(html)}},2e3)}},5)});if(this.manifest.metadata.dynamicElementLoader){var i;(function(){var tagsFound=(0,_haxutils.findTagsInHTML)(html),basePath=(0,_resolveUrl.pathFromUrl)(decodeURIComponent(meta.url)),_loop=function(){var tagName=tagsFound[i];if(_this4.manifest.metadata.dynamicElementLoader[tagName]&&!window.customElements.get(tagName)){new Promise(function(res,rej){return _require.default(["".concat(basePath,"../../../../").concat(_this4.manifest.metadata.dynamicElementLoader[tagName])],res,rej)}).then(function(){}).catch(function(error){console.log(error)})}};for(i in tagsFound){_loop()}})()}}}}},{key:"_activeItemChanged",value:function _activeItemChanged(newValue,oldValue){if(newValue&&babelHelpers.typeof(newValue.id)!=="undefined"){this.set("queryParams.nodeId",newValue.id);this.notifyPath("queryParams.nodeId");if("published"!==this.editorBuilder.getContext()){this.__timeStamp="?"+_Mathfloor(Date.now()/1e3)}this.$.activecontent.generateRequest()}else if(oldValue&&!newValue){this.dispatchEvent(new CustomEvent("json-outline-schema-active-body-changed",{bubbles:!0,composed:!0,cancelable:!1,detail:null}))}}},{key:"_triggerUpdatedData",value:function _triggerUpdatedData(){if("published"!==this.editorBuilder.getContext()){this.__timeStamp="?"+_Mathfloor(Date.now()/1e3)}this.$.manifest.generateRequest()}},{key:"_triggerUpdatedNode",value:function _triggerUpdatedNode(){if("published"!==this.editorBuilder.getContext()){this.__timeStamp="?"+_Mathfloor(Date.now()/1e3)}if(this.activeItem.location){this.$.activecontent.generateRequest()}}},{key:"_fileChanged",value:function _fileChanged(newValue){if(babelHelpers.typeof(newValue)!=="undefined"){this.$.manifest.generateRequest()}}},{key:"_manifestChanged",value:function _manifestChanged(newValue){if(newValue&&newValue.metadata&&newValue.items){if(!newValue.metadata.dynamicElementLoader){newValue.metadata.dynamicElementLoader={"a11y-gif-player":"@lrnwebcomponents/a11y-gif-player/a11y-gif-player.js","citation-element":"@lrnwebcomponents/citation-element/citation-element.js","hero-banner":"@lrnwebcomponents/hero-banner/hero-banner.js","image-compare-slider":"@lrnwebcomponents/image-compare-slider/image-compare-slider.js","license-element":"@lrnwebcomponents/license-element/license-element.js","lrn-aside":"@lrnwebcomponents/lrn-aside/lrn-aside.js","lrn-calendar":"@lrnwebcomponents/lrn-calendar/lrn-calendar.js","lrn-math":"@lrnwebcomponents/lrn-math/lrn-math.js","lrn-table":"@lrnwebcomponents/lrn-table/lrn-table.js","lrn-vocab":"@lrnwebcomponents/lrn-vocab/lrn-vocab.js","lrndesign-blockquote":"@lrnwebcomponents/lrndesign-blockquote/lrndesign-blockquote.js","magazine-cover":"@lrnwebcomponents/magazine-cover/magazine-cover.js","media-behaviors":"@lrnwebcomponents/media-behaviors/media-behaviors.js","media-image":"@lrnwebcomponents/media-image/media-image.js","meme-maker":"@lrnwebcomponents/meme-maker/meme-maker.js","multiple-choice":"@lrnwebcomponents/multiple-choice/multiple-choice.js","paper-audio-player":"@lrnwebcomponents/paper-audio-player/paper-audio-player.js","person-testimonial":"@lrnwebcomponents/person-testimonial/person-testimonial.js","place-holder":"@lrnwebcomponents/place-holder/place-holder.js","q-r":"@lrnwebcomponents/q-r/q-r.js","full-width-image":"@lrnwebcomponents/full-width-image/full-width-image.js","self-check":"@lrnwebcomponents/self-check/self-check.js","simple-concept-network":"@lrnwebcomponents/simple-concept-network/simple-concept-network.js","stop-note":"@lrnwebcomponents/stop-note/stop-note.js","tab-list":"@lrnwebcomponents/tab-list/tab-list.js","task-list":"@lrnwebcomponents/task-list/task-list.js","video-player":"@lrnwebcomponents/video-player/video-player.js","wave-player":"@lrnwebcomponents/wave-player/wave-player.js","wikipedia-query":"@lrnwebcomponents/wikipedia-query/wikipedia-query.js"}}_haxcmsSiteStore.store.manifest=newValue;this.dispatchEvent(new CustomEvent("json-outline-schema-changed",{bubbles:!0,composed:!0,cancelable:!1,detail:newValue}))}}},{key:"_themeChanged",value:function _themeChanged(newValue,oldValue){var _this5=this;if(newValue&&oldValue){if(window.cmsSiteEditor&&window.cmsSiteEditor.instance&&babelHelpers.typeof(window.cmsSiteEditor.instance.haxCmsSiteEditorElement)!=="undefined"){window.cmsSiteEditor.instance.appendChild(window.cmsSiteEditor.instance.haxCmsSiteEditorElement)}}if(newValue){this.themeLoaded=!1;var theme=newValue;(0,_haxutils.wipeSlot)(this,"*");this.themeElement=document.createElement(theme.element);if(babelHelpers.typeof(this.__imported[theme.element])!=="undefined"){(0,_polymerDom.dom)(this).appendChild(this.themeElement);this.themeLoaded=!0}else{try{new Promise(function(res,rej){return _require.default([(0,_resolveUrl.pathFromUrl)(decodeURIComponent(meta.url))+"../../../../"+newValue.path],res,rej)}).then(function(){(0,_polymerDom.dom)(_this5).appendChild(_this5.themeElement);_this5.__imported[theme.element]=theme.element;_this5.themeLoaded=!0})}catch(err){(0,_polymerDom.dom)(this).appendChild(this.themeElement);this.themeLoaded=!0}}setTimeout(function(){(0,_elementMixin.updateStyles)()},500)}}}]);return HAXCMSSiteBuilder}(_polymerElement.PolymerElement);_exports.HAXCMSSiteBuilder=HAXCMSSiteBuilder;window.customElements.define(HAXCMSSiteBuilder.tag,HAXCMSSiteBuilder)});