forked from BuilderIO/demo-editor
-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path265.39e6d4a6.chunk.js.download
1 lines (1 loc) · 8.55 KB
/
265.39e6d4a6.chunk.js.download
1
(this["[email protected]/app"]=this["[email protected]/app"]||[]).push([[265],{2672:function(module,exports){},2711:function(module,exports){},2822:function(module,__webpack_exports__,__webpack_require__){"use strict";__webpack_require__.d(__webpack_exports__,"a",function(){return EDITOR_OVERLAYS}),__webpack_require__.d(__webpack_exports__,"b",function(){return EDITOR_OVERLAYS_ELEVATED_1}),__webpack_require__.d(__webpack_exports__,"c",function(){return EDITOR_OVERLAYS_ELEVATED_2});const EDITOR_OVERLAYS=100,EDITOR_OVERLAYS_ELEVATED_1=101,EDITOR_OVERLAYS_ELEVATED_2=102},5014:function(module,__webpack_exports__,__webpack_require__){"use strict";__webpack_require__.r(__webpack_exports__),__webpack_require__.d(__webpack_exports__,"installHASAppKey",function(){return installHASAppKey}),__webpack_require__.d(__webpack_exports__,"installTemplateKey",function(){return installTemplateKey}),__webpack_require__.d(__webpack_exports__,"copyContentKey",function(){return copyContentKey}),__webpack_require__.d(__webpack_exports__,"InstallHeadlessAppOverlay",function(){return InstallHeadlessAppOverlay});var emotion_react_jsx_runtime_browser_esm=__webpack_require__(0),mobx_state_tree_module=__webpack_require__(2),Paper=__webpack_require__(126),Paper_default=__webpack_require__.n(Paper),IconButton=__webpack_require__(113),IconButton_default=__webpack_require__.n(IconButton),Button=__webpack_require__(40),Button_default=__webpack_require__.n(Button),Typography=__webpack_require__(105),Typography_default=__webpack_require__.n(Typography),Close=__webpack_require__(573),Close_default=__webpack_require__.n(Close),src=__webpack_require__(2043);function jsxLiteToSymbol(jsx){var _a;const parsed=Object(src.parseJsx)(jsx),json=Object(src.componentToBuilder)()({component:parsed}),inputs=((_a=parsed.meta.metadataHook)===null||_a===void 0?void 0:_a.propTypes)||[];return{"@type":"@builder.io/sdk:Element",groupLocked:!0,component:{name:"Symbol",options:{symbol:{inline:!0,data:inputs.reduce((memo,option)=>(option.defaultValue!==void 0&&(memo[option.name]=option.defaultValue),memo),{}),content:Object.assign(Object.assign({},json),{data:Object.assign(Object.assign({},json.data),{inputs:inputs.map(item=>Object.assign({"@type":"@builder.io/core:Field"},item))})})}}}}}function fetchAt(array,idx){const item=array[idx];if(item)return item;throw"Index out of bounds"}const templateToSymbol=(app,opts)=>{const template="template"in opts?opts.template:fetchAt(opts.templates,opts.idx),json=jsxLiteToSymbol(template.code);return json.layerName=`${app.title} - ${template.name}`,json};var lodash=__webpack_require__(6),es=__webpack_require__(90),app_state_constant=__webpack_require__(1);const headlessAppStoreBuilderPublicKey="c33bcd23c29e45789677ba9aaaa7ce1d";var organization_ids_constant=__webpack_require__(705),fast_clone_function=__webpack_require__(25),get_query_param_function=__webpack_require__(82);const GROUP_LOCKED_CONTENT_REGEX=/"groupLocked"\s*:\s*true/;function hasGroupLockedContent(content){return!!(typeof content=="string"?content:JSON.stringify(content)).match(GROUP_LOCKED_CONTENT_REGEX)}var update_query_param_function=__webpack_require__(100),use_reaction=__webpack_require__(132),ls_sync=__webpack_require__(38),track_function=__webpack_require__(14),z_index=__webpack_require__(2822);const installHASAppKey="installHASApp",installTemplateKey="installTemplate",copyContentKey="copyContent";for(const key of[installHASAppKey,installTemplateKey]){const queryParamValue=Object(get_query_param_function.a)(window.location.href,key);queryParamValue&&Object(ls_sync.e)(key,queryParamValue)}function InstallHeadlessAppOverlay(){const state=Object(es.f)(()=>({loading:!1,app:null,template:null,content:null,installApp:Object(ls_sync.d)(installHASAppKey),installTemplate:Object(ls_sync.d)(installTemplateKey),installContent:Object(ls_sync.d)(copyContentKey),get installAppId(){var _a;return(_a=this.installApp)===null||_a===void 0?void 0:_a.split(":")[0]},get installAppTemplate(){var _a;return Number((_a=this.installApp)===null||_a===void 0?void 0:_a.split(":")[1])||0},clearApp(){sessionStorage.removeItem(installHASAppKey),state.app=null,state.installApp=null},clearTemplate(){sessionStorage.removeItem(installTemplateKey),state.template=null,state.installTemplate=null},clearContent(){sessionStorage.removeItem(copyContentKey),state.content=null,state.installContent=null}}));return Object(use_reaction.a)(()=>state.installApp,async app=>{app&&(state.loading=!0,state.app=await fetch(`${app_state_constant.appState.config.contentApiRoot()}/app/${state.installAppId}?apiKey=${headlessAppStoreBuilderPublicKey}`).then(res=>res.json()),state.loading=!1)}),Object(use_reaction.a)(()=>state.installContent,async contentJson=>{contentJson&&(state.content=contentJson)}),Object(use_reaction.a)(()=>state.installTemplate,async templateId=>{var _a;if(templateId){state.loading=!0;const json=await fetch(`${app_state_constant.appState.config.assetsTemplateRoot(!0,"templates")}?collection=templates&query._id=${templateId}&apiKey=${organization_ids_constant.a.builder}`,{headers:app_state_constant.appState.user.authHeaders}).then(res=>res.json()),result=(_a=json?.results)===null||_a===void 0?void 0:_a[0];result&&result.blockString&&(result.block=JSON.parse(result.blockString),hasGroupLockedContent(result.blockString)||(result.block.groupLocked=!0)),state.template=result,state.loading=!1}}),Object(es.g)(()=>{const{app,template,content}=state;return app||template||content?Object(emotion_react_jsx_runtime_browser_esm.c)(Paper_default.a,Object.assign({elevation:12,css:{padding:15,position:"fixed",bottom:20,right:100,zIndex:z_index.b,width:240,display:"flex",alignItems:"center",flexDirection:"column",background:"var(--background)",borderRadius:4,"&:hover .close-button":{opacity:.5,transition:"opacity 0.15s ease-in-out"}}},{children:[Object(emotion_react_jsx_runtime_browser_esm.b)(IconButton_default.a,Object.assign({className:"close-button",css:{position:"absolute",opacity:0,top:0,right:0,zIndex:10},onClick:async()=>{await app_state_constant.appState.dialogs.confirm(content?"Cancel copying this content?":state.installTemplate?"Cancel adding this template?":"Cancel installing this app?")&&(state.installTemplate?state.clearTemplate():state.installContent?state.clearContent():state.clearApp())}},{children:Object(emotion_react_jsx_runtime_browser_esm.b)(Close_default.a,{})})),Object(emotion_react_jsx_runtime_browser_esm.b)("img",{css:{height:120,width:200,margin:10,padding:10,objectFit:"contain"},src:Object(update_query_param_function.b)(content?content.previewUrl||"https://cdn.builder.io/api/v1/image/assets%2FYJIGb4i01jvw0SRdL5Bt%2Fba7a7ea7ffca42d1b5079c263f69559c":template?template.previewImage:app.data.image,{width:"400",height:"240"}),onError:({currentTarget})=>{currentTarget.onerror=null,currentTarget.src="https://cdn.builder.io/api/v1/image/assets%2FYJIGb4i01jvw0SRdL5Bt%2Fba7a7ea7ffca42d1b5079c263f69559c"}}),Object(emotion_react_jsx_runtime_browser_esm.b)("div",{children:content?content.name:template?template.name:app.data.title}),app_state_constant.appState.location.pathname.startsWith("/content/")?Object(emotion_react_jsx_runtime_browser_esm.b)(Button_default.a,Object.assign({css:{marginTop:10},disabled:!app_state_constant.appState.editor.content,onClick:()=>{if(state.installContent){const useContent=Object.assign(Object.assign({},app_state_constant.appState.editor.content.snapshot),Object(lodash.omit)(Object(lodash.pick)(Object(fast_clone_function.b)(content),"data","variations","testRatio","name"),"data.themeId","data.view","data.liquidTargeting","data.templatePath"));Object(mobx_state_tree_module.applySnapshot)(app_state_constant.appState.editor.content,useContent),Object(track_function.c)("copy to space successful",{}),state.clearContent()}else if(state.installTemplate)app_state_constant.appState.designerState.draggingInItem=template.block,app_state_constant.appState.editor.selectOptionsTab.next(),state.clearTemplate();else{const symbol=templateToSymbol({title:app.data.title},{idx:state.installAppTemplate,templates:app.data.templates});app_state_constant.appState.designerState.draggingInItem=symbol,app_state_constant.appState.editor.selectOptionsTab.next(),state.clearApp()}},fullWidth:!0,color:"primary",variant:"contained"},{children:state.installContent?"Copy content":state.installTemplate?"Add template":"Install App"})):Object(emotion_react_jsx_runtime_browser_esm.c)(Typography_default.a,Object.assign({css:{marginTop:8,paddingBottom:5,textAlign:"center"},variant:"caption"},{children:["Choose or create a piece of content to"," ",state.installContent?"copy this content":state.installTemplate?"add this template":"install this app"," ","to"]}))]})):null})}}}]);