← Back
Editing: chunk-116.js
"use strict";(self.webpackChunkfl_assistant=self.webpackChunkfl_assistant||[]).push([[116],{3116:(e,t,a)=>{a.d(t,{u:()=>K,w:()=>Z});var n={};a.r(n),a.d(n,{getActions:()=>D});var r={};a.r(r),a.d(r,{getActions:()=>N});var s={};a.r(s),a.d(s,{getActions:()=>O});var i={};a.r(i),a.d(i,{getActions:()=>W});var l={};a.r(l),a.d(l,{getActions:()=>$});var o={};a.r(o),a.d(o,{getActions:()=>H});var c={};a.r(c),a.d(c,{code:()=>o,document:()=>i,image:()=>r,post:()=>n,settings:()=>l,svg:()=>s});var u=a(1594),m=a.n(u),d=a(9665),p=a(2470),g=a(1112),y=a(2405),_=a(6075),b=a(2578);const h=()=>{const e=(0,d.useHistory)(),{cloudUser:t}=(0,_.useSystemState)(),{pathname:a}=(0,d.useLocation)(),{isReadOnly:n,library:r,items:s,showUpload:i,setShowUpload:l,showFilters:o,setShowFilters:c}=g.uC.LibraryContext.use(),u=`/libraries/${r.id}`,h=t.id===r.permissions.permissions_user_id,{isSelecting:E,setIsSelecting:f}=b.Selection.use(),C=s&&!!s.length;if(!(r.permissions.update||r.permissions.edit_items||r.permissions.shared||h))return null;return m().createElement(m().Fragment,null,C&&!a.includes("/settings")&&m().createElement(m().Fragment,null,m().createElement(y.Button,{onClick:()=>f(!0),isSelected:E},(0,p.__)("Select")),m().createElement(y.Button,{appearance:"transparent",isSelected:o,onClick:()=>c(!o),title:(0,p.__)("Search")},m().createElement(y.Icon.Search,null))),!n&&r.permissions.edit_items&&m().createElement(y.Button,{appearance:"transparent",isSelected:i&&!a.includes("/settings"),title:(0,p.__)("Add Items"),onClick:()=>{l(!i),a!==u&&e.goBack()},style:{marginLeft:"auto"}},m().createElement(y.Icon.Plus,null)),(r.permissions.update||r.permissions.shared||h)&&m().createElement(y.Button,{appearance:"transparent",isSelected:a.includes("/settings"),title:(0,p.__)("Settings"),onClick:()=>{a===u&&e.push(`${u}/settings`)}},m().createElement(y.Icon.Cog,null)))};var E=a(8168);const f=()=>{const{isReadOnly:e,library:t,showUpload:a,uploader:n}=g.uC.LibraryContext.use();return e||!t.permissions.edit_items?null:m().createElement(m().Fragment,null,a&&m().createElement(g.uC.LibraryUpload,null),!!n.queuedFiles.length&&m().createElement(y.Layout.Box,{padY:!1},m().createElement(g.d9.FileList,{files:n.queuedFiles})))},C=()=>{const{library:e}=g.uC.LibraryContext.use();return m().createElement(m().Fragment,null,m().createElement(y.Layout.Box,{style:{textAlign:"center",padding:0}},m().createElement(y.Layout.Headline,{style:{margin:20}},e.name),e.description&&m().createElement("div",{style:{lineHeight:1.4,margin:"0 20px"}},e.description)),m().createElement(g.uC.LibraryMemberThumbs,null))},w=e=>{const{useItemsFilter:t}=(0,_.getAppHooks)("libraries"),[a,n]=t(),{defaultItemsFilter:r,showFilters:s}=(0,_.useAppState)("libraries",["defaultItemsFilter","showFilters"]),i=()=>"type"===a.viewBy?m().createElement(y.Filter.RadioGroupItem,{title:(0,p.__)("Type"),items:g.uC.getItemTypeOptions(),value:a.type,defaultValue:r.type,onChange:e=>n({...a,type:e})}):m().createElement(y.Filter.RadioGroupItem,{title:(0,p.__)("Collection"),items:g.uC.getCollectionOptions(),value:a.collection,defaultValue:r.collection,onChange:e=>n({...a,collection:e})});return m().createElement(m().Fragment,null,m().createElement(y.Filter,e,s&&m().createElement(y.Filter.TextInputItem,{className:"fl-asst-filter-item-full-width fl-asst-filter-item-search",title:(0,p.__)("Search"),placeholder:(0,p.__)("Filter..."),value:a.search,onChange:e=>n({...a,search:e})}),m().createElement(y.Filter.RadioGroupItem,{title:(0,p.__)("View By"),items:{type:(0,p.__)("Type"),collection:(0,p.__)("Collection")},value:a.viewBy,defaultValue:r.viewBy,onChange:e=>n({...a,viewBy:e})}),m().createElement(i,null),m().createElement(y.Filter.RadioGroupItem,{title:(0,p.__)("Sort By"),items:{name:(0,p.__)("Title"),created_at:(0,p.__)("Date Created"),updated_at:(0,p.__)("Last Updated")},value:a.orderBy,defaultValue:r.orderBy,onChange:e=>n({...a,orderBy:e})}),m().createElement(y.Filter.RadioGroupItem,{title:(0,p.__)("Order"),items:{ASC:(0,p.__)("Ascending"),DESC:(0,p.__)("Descending")},value:a.order,defaultValue:r.order,onChange:e=>n({...a,order:e})}),m().createElement(y.Filter.Button,{onClick:()=>n(r)},(0,p.__)("Reset Filter"))))};var v=a(816),S=a.n(v);const I=()=>{const{items:e,setItems:t}=g.uC.LibraryContext.use(),{items:a,clearSelection:n,totalSelectedItems:r}=b.Selection.use();return React.createElement(y.Button,{status:"destructive",icon:React.createElement(y.Icon.Trash,null),disabled:0>=r,onClick:()=>{confirm((0,p.__)("Do you really want to delete these items?"))&&(async(r=[])=>{S().libraries.deleteItem(r).finally((()=>{t([...e.filter((e=>!a.includes(e.id)))]),n()}))})(a)}},(0,p.__)("Delete"))};var L=a(9489);const R=()=>{const e=(0,L.getWpRest)().libraries(),t=(0,u.useRef)(0),a=(t,a,r)=>{e.importPostThumb(t.id,a.media.thumb).finally((()=>{n(t,a,r)}))},n=(a,r,s)=>{const{attachments:i}=r.media;if(void 0===i)return void s(a);const l=i[t.current];void 0===l?(t.current=0,s(a)):e.importPostMedia(a.id,l).finally((()=>{t.current++,n(a,r,s)}))};return(e,t)=>new Promise((r=>{t.media.thumb?a(e,t,r):n(e,t,r)}))},x=()=>{const{items:e,setItems:t,createNotice:a}=g.uC.LibraryContext.use(),{items:n,clearSelection:r,totalSelectedItems:s}=b.Selection.use(),[i,l]=(0,u.useState)(null),[o,c]=(0,u.useState)(0),m=R(),d=(0,L.getWpRest)().libraries();return React.createElement(React.Fragment,null,React.createElement(y.Button,{disabled:null!==i,onClick:async()=>{let t=0,s=0,i=[];const o=(()=>{const t=[];return n.forEach((a=>{const n=e.find((e=>e.id===a));n&&"settings"===n.type&&confirm((0,p.__)("Importing these settings will overwrite your existing settings, do you wish to continue?")+"\n"+n.name)&&t.push(n.id)})),t})();for(const a of n){const n=e.find((e=>e.id===a));void 0!==n&&(l(n),"color"===n.type||"code"===n.type||("post"===n.type?await S().libraries.getItem(n.id).then((async e=>{await d.importPost(e.data).then((async t=>{if(t.data.error&&"post_type_not_registered"===t.data.error_code)return i.push({name:n.name,type:t.data.post_type}),void s++;await m(t.data,e.data)}))})):"settings"===n.type?o.includes(n.id)&&await d.importSettings(n.id):await d.importItem(n))),t++,c(t)}const u=i.map((e=>React.createElement("li",{key:e.name},e.name," (",e.type,")")));a(s<t?{status:"success",shouldDismiss:!1,content:React.createElement(React.Fragment,null,(0,p.__)("Library items imported!"),s>0&&React.createElement(React.Fragment,null," ",(0,p.__)("Some items were not able to be imported due to these post types not being registered on this site: "),React.createElement("br",null),React.createElement("ul",null,u)))}:{status:"error",shouldDismiss:!1,content:React.createElement(React.Fragment,null,(0,p.__)("The selected items were not able to be imported due to these post types not being registered on this site: "),React.createElement("br",null),React.createElement("ul",null,u))}),c(0),r()}},(0,p.__)("Import")),null!==i&&React.createElement("div",{className:"fl-asst-import-bar"},React.createElement("p",null,(0,p.__)("Import in progress. Navigating away from this view will stop the import process!")),React.createElement(k,{progress:o/n.length*100}),React.createElement("p",{style:{fontStyle:"italic",fontSize:"12px",marginTop:"var(--fluid-sm-space)",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"}},(0,p.__)("Importing")," ",i.name)))},k=({progress:e})=>React.createElement("div",{style:{background:"var(--fluid-transparent-10)",borderRadius:"var(--fluid-radius)",height:"6px"}},React.createElement("div",{style:{background:"var(--fluid-transparent-4)",borderRadius:"var(--fluid-radius)",height:"6px",width:`${e}%`}})),F=({children:e,...t})=>{const{isReadOnly:a,library:n,uploader:r}=g.uC.LibraryContext.use();return!a&&n.permissions.edit_items?m().createElement(y.Layout.DropArea,(0,E.A)({onDrop:r.handleDrop},t),e):m().createElement("div",t,e)},B=()=>{const e=(0,d.useLocation)(),{items:t,showUpload:a,library:n}=g.uC.LibraryContext.use(),{defaultItemsFilter:r}=(0,_.useAppState)("libraries","defaultItemsFilter"),{useItemsFilter:s}=(0,_.getAppHooks)("libraries"),[i,l]=s(),o=g.uC.getFilteredItems(i,t),c=t&&!!t.length,{isSelecting:u}=b.Selection.use(),h=n.permissions.edit_items&&!((e,t=[])=>t.some((t=>e.endsWith(t))))(e.pathname,["/share","/settings","/collections"]);return m().createElement(F,{className:"fl-asst-library-content"},m().createElement("div",{className:"fl-asst-library-sticky"},m().createElement(w,null),u&&m().createElement(b.Selection.Toolbar,{style:{minHeight:48,flexBasis:48,width:"100%",top:"auto"},isSticky:!1},m().createElement(x,null),m().createElement(I,null))),m().createElement(b.Selection.Box,{itemSelector:".fluid-collection-item",mapElementToData:e=>parseInt(e.dataset.selectionId),isEnabled:h},m().createElement(C,null),m().createElement(f,null),m().createElement(g.uC.ItemsList,null),(()=>{const{viewBy:e,type:a,collection:n}=i;if(t&&!Object.keys(o).length){if("type"===e&&"all"!==a)return!0;if("collection"===e&&"all"!==n)return!0}return!1})()&&!a&&m().createElement(m().Fragment,null,m().createElement(y.Layout.Box,{style:{textAlign:"center"}},(0,p.__)("No results found.")),m().createElement(y.Layout.Row,null,m().createElement(y.Button,{onClick:()=>l(r)},(0,p.__)("Reset Filter")))),t&&!c&&!a&&m().createElement(y.Layout.Box,{style:{textAlign:"center"}},(0,p.__)("This library doesn't have any items yet."))))},D=(e,t)=>{const{library:a}=g.uC.LibraryContext.use();return t.unshift({component:m().createElement(P,{item:e})}),t.unshift({component:m().createElement(T,{item:e}),shouldRender:a.permissions.edit_items}),t.unshift({component:m().createElement(U,{item:e})}),t},P=({item:e})=>{const{createNotice:t}=g.uC.ItemContext.use(),[a,n]=(0,u.useState)(!1),r=(0,L.getWpRest)().libraries(),s=e=>{!e||e.data.error?t({status:"error",content:(0,p.__)("Error previewing content.")}):window.open(e.data.url)};return m().createElement(y.Button,{onClick:()=>{n(!0),r.previewPost(e).then((e=>{s(e)})).catch((()=>{s()})).finally((()=>{n(!1)}))},disabled:a},(0,p.__)("Preview"))},T=({item:e})=>{const{currentPageView:t,isLocalhost:a}=(0,_.getSystemConfig)(),{id:n,type:r,isSingular:s}=t,[i,l]=(0,u.useState)(!1),{updateItems:o}=g.uC.LibraryContext.use(),{createNotice:c,setItem:d}=g.uC.ItemContext.use(),{updateFormValues:b}=g.uC.ItemFormContext.use(),h=(0,L.getWpRest)().libraries(),E=(0,L.getWpRest)().posts(),f=[{label:(0,p.__)("Cancel"),disabled:i,onClick:({closeDialog:e})=>e()}];s&&f.push({label:i?(0,p.__)("Updating..."):(0,p.__)("Update"),isSelected:!0,disabled:i,onClick:({closeDialog:t})=>{const a=(0,p.sprintf)((0,p.__)("Do you really want to update this library item and replace its content with the current %s? This cannot be undone."),r.toLowerCase());if(!confirm(a))return;l(!0);E.findById(n).then((({data:a})=>{g.d9.screenshotUrl(a.previewUrl).then((a=>{((a="")=>{h.syncLibraryPost(n,e,{screenshot:a}).then((e=>{d(e.data),o(e.data),b(e.data),c({status:"success",content:(0,p.__)("Library item updated!"),shouldDismiss:!1})})).catch((()=>{c({status:"error",content:(0,p.__)("Error updating library item."),shouldDismiss:!1})})).finally((()=>{l(!1),t()}))})(a)}))}))}});const[C,w]=y.Modal.useDialog({title:(0,p.__)("Update this Library Item"),message:m().createElement(A,null),buttons:f});return m().createElement(m().Fragment,null,m().createElement(y.Button,{onClick:C},(0,p.__)("Update")),m().createElement(w,null))},A=()=>{const{currentPageView:e}=(0,_.getSystemConfig)(),{intro:t,name:a,type:n,isSingular:r}=e;return r?m().createElement(m().Fragment,null,m().createElement("div",{style:{padding:"var(--fluid-med-space) 0"}},m().createElement("strong",null,t,":")," ",a),m().createElement("div",null,(0,p.sprintf)((0,p.__)("Updating this library item will replace its content with the content of the current %s."),n.toLowerCase()))):(0,p.__)("Updating is currently not available. To update this library item, navigate to the post or page you'd like to update it with and click the update button again.")},U=({item:e})=>{const{currentPageView:t,contentTypes:a}=(0,_.getSystemConfig)(),{createNotice:n}=g.uC.ItemContext.use(),[r,s]=(0,u.useState)(null),[i,l]=(0,u.useState)(!1),o=(0,L.getWpRest)().libraries(),c=R(),d=e=>{const{editUrl:t,type:r,postTypeRegistered:i}=e,o=a[r]?a[r].labels.singular:(0,p.__)("Content");s(null),l(!1),e.error?n({status:"error",shouldDismiss:!1,content:(0,p.__)("Error importing library item.")}):n({status:"success",shouldDismiss:!1,content:m().createElement(m().Fragment,null,i&&(0,p.__)("Library item imported!"),!i&&m().createElement(m().Fragment,null,(0,p.__)("The library item was not able to be imported.")," ",(0,p.__)("The post type"),' "',m().createElement("strong",null,r),'" ',(0,p.__)("is not registered on this site.")),t&&m().createElement("a",{style:{textDecoration:"underline",marginLeft:"var(--fluid-sm-space)"},onClick:()=>{window.location.href=t}},(0,p.sprintf)((0,p.__)("Edit %s."),o)))})},y=e=>{s(null),l(!1),!e||e.error?n({status:"error",shouldDismiss:!1,content:(0,p.sprintf)((0,p.__)("Error replacing %s."),t.type.toLowerCase())}):(n({status:"success",shouldDismiss:!1,content:(0,p.sprintf)((0,p.__)("%s replaced!"),t.type)}),window.location.reload())};return(0,u.useEffect)((()=>{"create"===r?o.importPost(e).then((t=>{t.data.error&&"post_type_not_registered"===t.data.error_code?n({status:"error",shouldDismiss:!1,content:m().createElement(m().Fragment,null,(0,p.__)("The library item was not able to be imported.")," ",(0,p.__)("The post type"),' "',m().createElement("strong",null,t.data.post_type),'" ',(0,p.__)("is not registered on this site."))}):(l(!0),c(t.data,e).then(d))})).catch((()=>{s(null),l(!1),n({status:"error",content:(0,p.__)("Error importing library item.")})})):"replace"===r&&(()=>{if(!t.isSingular)return alert((0,p.__)("Replacing is currently not available. Navigate to the post or page you'd like to replace and click the import button again.")),void s(null);const a=(0,p.sprintf)((0,p.__)("Do you really want to replace the current %s with this library item? This cannot be undone."),t.type.toLowerCase());confirm(a)?o.syncPost(t.id,e).then((t=>{l(!0),c(t.data,e).then((()=>{y(t.data)}))})).catch((()=>{y()})):s(null)})()}),[r]),m().createElement(m().Fragment,null,m().createElement("select",{value:"",onChange:e=>s(e.target.value),disabled:r},m().createElement("option",{value:""},!i&&!r&&(0,p.__)("Import..."),!i&&r&&(0,p.__)("Importing..."),i&&(0,p.__)("Importing media...")),m().createElement("option",{value:"create"},(0,p.__)("Create New")),m().createElement("option",{value:"replace"},t.isSingular?(0,p.sprintf)((0,p.__)("Replace Current %s"),t.type):(0,p.__)("Replace Current Page"))))},N=(e,t)=>{const{createNotice:a}=g.uC.ItemContext.use(),[n,r]=(0,u.useState)(!1),s=(0,L.getWpRest)();return t.unshift({label:(0,p.__)("Import"),onClick:()=>{r(!0),s.libraries().importItem(e).then((e=>{a({status:e.data.error?"error":"success",content:e.data.error?e.data.error:(0,p.__)("Item imported!")})})).catch((e=>{a({status:"error",content:e.response.data.message})})).finally((()=>{r(!1)}))},disabled:n}),t},O=(e,t)=>{const{createNotice:a}=g.uC.ItemContext.use(),[n,r]=(0,u.useState)(!1),s=(0,L.getWpRest)();return t.unshift({label:(0,p.__)("Import"),onClick:()=>{r(!0),s.libraries().importItem(e).then((e=>{a({status:e.data.error?"error":"success",content:e.data.error?e.data.error:(0,p.__)("Item imported!")})})).catch((e=>{a({status:"error",content:e.response.data.message})})).finally((()=>{r(!1)}))},disabled:n}),t},W=(e,t)=>{const{createNotice:a}=g.uC.ItemContext.use(),[n,r]=(0,u.useState)(!1),s=(0,L.getWpRest)();return t.unshift({label:(0,p.__)("Import"),onClick:()=>{r(!0),s.libraries().importItem(e).then((e=>{a({status:e.data.error?"error":"success",content:e.data.error?e.data.error:(0,p.__)("Item imported!")})})).catch((e=>{a({status:"error",content:e.response.data.message})})).finally((()=>{r(!1)}))},disabled:n}),t},$=(e,t)=>{const{adminURLs:a,themeSlug:n,themeParentSlug:r}=(0,_.getSystemConfig)(),{createNotice:s}=g.uC.ItemContext.use(),[i,l]=(0,u.useState)(!1),o=(0,L.getWpRest)().libraries(),c=()=>{const{name:t,slug:a,parent:s}=e.data.theme;return(!s||s.slug!==n&&s.slug!==r)&&(a!==n&&a!==r&&(s?alert((0,p.sprintf)((0,p.__)('The themes "%s" or "%s" must be active to apply or preview these settings.'),s.name,t)):alert((0,p.sprintf)((0,p.__)('The theme "%s" must be active to apply or preview these settings.'),t)),!0))};return t.unshift({label:(0,p.__)("Apply Settings"),onClick:()=>{if("theme_settings"===e.subtype){if(c())return;if(!confirm((0,p.__)("Do you really want to import these theme settings? This will update your site design and cannot be undone.")))return}("bb_settings"!==e.subtype||confirm((0,p.__)("Do you really want to import these Beaver Builder settings? This may update your site design and cannot be undone.")))&&(l(!0),o.importSettings(e.id).then((e=>{l(!1),e.data.data.error?s({status:"error",content:e.data.data.error,shouldDismiss:!1}):(s({status:"success",content:(0,p.__)("Settings imported!")}),window.location.reload())})))},disabled:i}),t.unshift({label:(0,p.__)("Preview"),onClick:()=>{c()||window.open(`${a.customizeBase}?fl-asst-customizer-preview-init=${e.id}`)}}),t},H=(e,t)=>{const{createNotice:a}=g.uC.ItemContext.use(),[n,r]=(0,u.useState)(!1),s=(0,L.getWpRest)();return t.unshift({label:(0,p.__)("Import"),onClick:()=>{r(!0),s.libraries().importItem(e).then((e=>{a({status:e.data.error?"error":"success",content:e.data.error?e.data.error:(0,p.__)("Item imported!")})})).catch((e=>{a({status:"error",content:e.response.data.message})})).finally((()=>{r(!1)}))},disabled:n}),t},z=()=>m().createElement("div",{style:{display:"flex",position:"absolute",top:0,right:0,bottom:0,left:0,width:"100%"}},m().createElement(g.uC.ItemDetail,{formConfig:c})),V=()=>{const{items:e,createNotice:t}=g.uC.LibraryContext.use(),[a,n]=(0,u.useState)(null),[r,s]=(0,u.useState)([]),[i,l]=(0,u.useState)(!1),[o,c]=(0,u.useState)(0),d=R(),y=(0,L.getWpRest)().libraries(),_=async a=>{let r=0,i=0,o=0,u=[],g=[];if("all"===a)g=e.map((e=>e.id));else if("all-content"===a)g=e.filter((e=>"post"===e.type)).map((e=>e.id));else if("bb-content"===a)g=e.filter((e=>"post"===e.type&&"beaver-builder"===e.subtype)).map((e=>e.id));else if(a.startsWith("post_type:")){const t=a.replace("post_type:","");g=e.filter((e=>"post"===e.type&&e.data.post.post_type===t)).map((e=>e.id))}else"all-settings"===a?g=e.filter((e=>"settings"===e.type)).map((e=>e.id)):"theme-settings"===a?g=e.filter((e=>"settings"===e.type&&"theme_settings"===e.subtype)).map((e=>e.id)):"bb-settings"===a?g=e.filter((e=>"settings"===e.type&&"bb_settings"===e.subtype)).map((e=>e.id)):"all-images"===a&&(g=e.filter((e=>"image"===e.type||"svg"===e.type)).map((e=>e.id)));s(g),l(!1);const _=(t=>{const a=[];return t.forEach((t=>{const n=e.find((e=>e.id===t));n&&"settings"===n.type&&confirm((0,p.__)("Importing these settings will overwrite your existing settings, do you wish to continue?")+"\n"+n.name)&&a.push(n.id)})),a})(g);for(const t of g){const a=e.find((e=>e.id===t));void 0!==a&&(n(a),"color"===a.type||"code"===a.type||("post"===a.type?await S().libraries.getItem(a.id).then((async e=>{await y.importPost(e.data).then((async t=>{if(t.data.error&&"post_type_not_registered"===t.data.error_code)return u.push({name:a.name,type:t.data.post_type}),void o++;await d(t.data,e.data),i++}))})):"settings"===a.type?_.includes(a.id)&&(await y.importSettings(a.id),i++):(await y.importItem(a),i++))),r++,c(r)}const b=u.map((e=>m().createElement("li",{key:e.name},e.name," (",e.type,")")));i>0?t({status:"success",shouldDismiss:!1,content:m().createElement(m().Fragment,null,(0,p.__)("Library items imported!"),o>0&&m().createElement(m().Fragment,null," ",(0,p.__)("Some items were not able to be imported due to these post types not being registered on this site: "),m().createElement("br",null),m().createElement("ul",null,b)))}):o>0&&t({status:"error",shouldDismiss:!1,content:m().createElement(m().Fragment,null,(0,p.__)("The selected items were not able to be imported due to these post types not being registered on this site: "),m().createElement("br",null),m().createElement("ul",null,b))}),c(0),l(!0)};let b=[];e&&(b=[...new Set(e.filter((e=>"post"===e.type)).map((e=>e.data.post.post_type)))]);const h={anyContent:!1,bbContent:!1,images:!1,allSettings:!1,themeSettings:!1,bbSettings:!1};return e&&(h.anyContent=e.some((e=>"post"===e.type)),h.bbContent=e.some((e=>"post"===e.type&&"beaver-builder"===e.subtype)),h.images=e.some((e=>"image"===e.type||"svg"===e.type)),h.allSettings=e.some((e=>"settings"===e.type)),h.themeSettings=e.some((e=>"settings"===e.type&&"theme_settings"===e.subtype)),h.bbSettings=e.some((e=>"settings"===e.type&&"bb_settings"===e.subtype))),null!==a||i?m().createElement("div",{style:{gridColumn:"span 2"}},!i&&m().createElement("p",null,(0,p.__)("Import in progress. Navigating away from this view will stop the import process!")),m().createElement(Y,{progress:o/r.length*100}),m().createElement("p",{style:{fontStyle:"italic",fontSize:"12px",marginTop:"var(--fluid-sm-space)",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"}},null!==a&&!i&&(0,p.sprintf)((0,p.__)("Importing %s"),a.name),i&&(0,p.__)("Import Complete!"))):m().createElement("select",{title:(0,p.__)("Import all items in this library into your site."),onChange:e=>_(e.target.value)},m().createElement("option",{value:""},(0,p.__)("Import Library...")),m().createElement("option",{value:"all"},"All Items"),m().createElement("optgroup",{label:(0,p.__)("Content")},m().createElement("option",{value:"all-content",disabled:!h.anyContent},(0,p.__)("All Content")),m().createElement("option",{value:"bb-content",disabled:!h.bbContent},(0,p.__)("Beaver Builder Content")),b.map((e=>m().createElement("option",{key:e,value:"post_type:"+e},"Post Type: ",e)))),m().createElement("optgroup",{label:(0,p.__)("Settings")},m().createElement("option",{value:"all-settings",disabled:!h.allSettings},(0,p.__)("All Settings")),m().createElement("option",{value:"theme-settings",disabled:!h.themeSettings},(0,p.__)("Theme Settings")),m().createElement("option",{value:"bb-settings",disabled:!h.bbSettings},(0,p.__)("Beaver Builder Settings"))),m().createElement("option",{value:"all-images",disabled:!h.images},(0,p.__)("Images")))},Y=({progress:e})=>m().createElement("div",{style:{background:"var(--fluid-transparent-10)",borderRadius:"var(--fluid-radius)",height:"6px"}},m().createElement("div",{style:{background:"var(--fluid-transparent-4)",borderRadius:"var(--fluid-radius)",height:"6px",width:`${e}%`}})),M=(e,t)=>{const a=URL.createObjectURL(e),n=document.createElement("a");n.href=a,n.download=t||"library.zip",document.body.appendChild(n),n.click(),document.body.removeChild(n),URL.revokeObjectURL(a)},j=()=>{const{library:e}=g.uC.LibraryContext.use(),[t,a]=(0,u.useState)(!1),[n,r]=(0,u.useState)(null),[s,i]=(0,u.useState)(!1);return m().createElement(m().Fragment,null,m().createElement(y.Modal.Dialog,{isShowing:t,setIsShowing:a,className:"fl-asst-download-preparing-dialog",message:m().createElement(m().Fragment,null,m().createElement(y.Layout.Headline,{style:{marginBottom:"var(--fluid-lg-space)"}},n?(0,p.__)("Download issue"):(0,p.__)("Preparing your download...")),n?m().createElement("p",null,n):m().createElement(m().Fragment,null,m().createElement("p",{style:{marginBottom:"var(--fluid-lg-space)"}},(0,p.__)("Do not navigate away from this page. Your library will automatically be downloaded when ready.")),m().createElement(y.Layout.Loading,{style:{justifyContent:"center"}}))),buttons:n?[{label:(0,p.__)("Close"),onClick:({closeDialog:e})=>{r(null),e()}}]:[]}),m().createElement(y.Button,{title:(0,p.__)("Download a ZIP file of all items in this library."),disabled:s,onClick:async()=>{i(!0);try{const t=await S().libraries.requestDownload(e.id);if(202===t.status){const e=await t.data.text(),n=JSON.parse(e);if(n.download_token)return void await(async e=>{a(!0),r(null);const t=async()=>{try{const n=await S().libraries.getDownloadStatus(e);if("ready"===n.status){const t=await S().libraries.getDownloadBlob(e);return M(t.data,n.filename),a(!1),i(!1),void g.uC.loadAppState()}if("expired"===n.status)return r(n.message||(0,p.__)("Download link expired. Please try again.")),void i(!1);setTimeout(t,2e3)}catch(e){const t=e?.response?.data?.message,a=e?.response?.data?.status;r(404===e?.response?.status&&"expired"===a?e?.response?.data?.message||(0,p.__)("Download link expired. Please try again."):t&&"string"==typeof t?t:(0,p.__)("Something went wrong. Please try again.")),i(!1)}};t()})(n.download_token)}if(200===t.status){const a=t.headers["content-disposition"]?(/filename="?([^";\n]+)"?/.exec(t.headers["content-disposition"])||[])[1]:null;M(t.data,a||`${e.name||"library"}.zip`)}}catch(e){a(!0),r((0,p.__)("Download failed. Please try again."))}i(!1)}},(0,p.__)("Download ZIP")))},G=()=>{const{library:e,createNotice:t}=g.uC.LibraryContext.use(),{cloudConfig:a}=(0,_.getSystemConfig)(),n=`${(a.appUrl||"").replace(/\/$/,"")}/community/library/${e.id}`;return m().createElement(y.Button,{title:(0,p.__)("Copy the link to this library on Assistant Pro."),onClick:async()=>{await(async e=>{try{return await navigator.clipboard.writeText(e),!0}catch{const t=document.createElement("textarea");t.value=e,t.setAttribute("readonly",""),t.style.position="absolute",t.style.left="-9999px",document.body.appendChild(t),t.select();try{return document.execCommand("copy")}finally{document.body.removeChild(t)}}})(n)?t("success",(0,p.__)("Public URL copied to clipboard.")):t("error",(0,p.__)("Could not copy URL."))}},(0,p.__)("Copy Public URL"))},q=()=>{const{isReadOnly:e,library:t}=g.uC.LibraryContext.use(),{cloudUser:a}=(0,_.useSystemState)(),n=a.id===t.permissions.permissions_user_id&&!t.permissions.owner,r=t.permissions.shared&&!t.permissions.owner||n;return m().createElement(m().Fragment,null,!e&&m().createElement(y.Layout.Box,{padY:!1},m().createElement(y.Page.Section,{label:(0,p.__)("Actions")},m().createElement(y.Button.Group,{appearance:"grid"},m().createElement(V,null),m().createElement(j,null),"public"===t.visibility&&m().createElement(G,null)))),!r&&m().createElement(y.Layout.Box,{padY:!1,className:"fl-asst-library-settings"},m().createElement(y.Page.Section,{label:(0,p.__)("Library Settings"),padY:!1},m().createElement(g.uC.LibrarySettingsForm,null))),!e&&m().createElement(m().Fragment,null,(!r||r&&t.permissions.edit_collections)&&m().createElement(y.Layout.Box,{padY:!1},m().createElement(y.Page.Section,{label:(0,p.__)("Library Collections")},m().createElement(g.uC.LibraryCollectionsForm,null)))),t.permissions.delete&&m().createElement(y.Layout.Box,null,m().createElement(y.Page.Section,{label:(0,p.__)("Danger Zone")},m().createElement(y.Layout.Headline,null,(0,p.__)("Delete This Library")),m().createElement("p",{style:{margin:"0"}},(0,p.__)("Once a library has been deleted, it is gone forever. Please be sure you want to delete this library."))),m().createElement(g.uC.LibraryDeleteForm,null)))},Z=()=>{const{pathname:e}=(0,d.useLocation)();return m().createElement(g.uC.LibraryDetail,null,m().createElement("div",{style:{visibility:e.includes("/items/")?"hidden":"",width:"100%",flex:"1 1 auto",display:"flex",position:"absolute",top:0,bottom:0}},m().createElement(y.Page,{title:(0,p.__)("Library"),shouldShowBackButton:!0,actions:m().createElement(h,null),padX:!1,padY:!1},m().createElement(d.Switch,null,m().createElement(d.Route,{path:"/libraries/:id/settings",component:q}),m().createElement(d.Route,{path:"/libraries/:id",component:B})))),m().createElement(d.Switch,null,m().createElement(d.Route,{path:"/libraries/:id/item/:itemId",component:z})))},X=()=>{const{cloudConfig:e}=(0,_.getSystemConfig)(),{cloudUser:t}=(0,_.useSystemState)(),[a,n]=(0,u.useState)(!1),r=()=>m().createElement(m().Fragment,null,m().createElement(y.Menu.Item,{href:e.appUrl,target:"_blank"},(0,p.__)("Launch Cloud")),m().createElement(y.Menu.Item,{onClick:()=>S().auth.logout()},(0,p.__)("Disconnect")));return m().createElement(y.Menu,{content:m().createElement(r,null),isShowing:a,onOutsideClick:()=>n(!1),style:{zIndex:9}},m().createElement(y.Button,{onClick:()=>n(!a),className:"fl-asst-cloud-gravatar-link",appearance:"elevator",size:"sm",style:{backgroundImage:`url(${t.gravatar.sm})`,backgroundSize:"contain",height:"25px",width:"25px",minHeight:"0",minWidth:"0"}}))},J=(e,t,a)=>{const n=(e="user",t=null)=>{const n=t?a[e][t]:a[e];return n?n.map(g.tm):[]},r=n("access"),s=[{key:"user",label:e?e.name:"",avatar:e.avatar?e.avatar.sizes.thumb.url:e.gravatar.md,to:"/libraries/user",items:n(),canCreateLibraries:!0},{key:"shared",label:(0,p.__)("Shared Libraries"),avatar:m().createElement(y.Icon.Shared,null),to:"/libraries/shared",isEnabled:!!a?.shared?.length,items:n("shared"),canCreateLibraries:!1},{key:"community",label:(0,p.__)("Community Libraries"),avatar:m().createElement(y.Icon.Swirl,null),isEnabled:!!r.length,items:r,canCreateLibraries:!1},...((e=[])=>e.map((e=>({...(0,g.$R)(e),items:n("team",e.id),canCreateLibraries:e.permissions.edit_libraries}))))(t)];return s},K=({preloadedLib:e=!1,preloadedTeams:t=!1})=>{const{cloudUser:a}=(0,_.useSystemState)(),{filter:n,libraries:r,teams:s}=(0,_.useAppState)("libraries"),{owner:i,...l}=n,o=e||r,c=t||s;return m().createElement(y.Page,{title:(0,p.__)("Libraries"),icon:m().createElement(y.Icon.Library,{context:"sidebar"}),shouldShowBackButton:!1,actions:m().createElement(X,null),padX:!1,padY:!1},m().createElement(g.PH,{sections:J(a,c,o),isLoading:!1,linkSectionHeaders:!1,displayItemsAs:"grid"}))}},8168:(e,t,a)=>{function n(){return n=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var a=arguments[t];for(var n in a)({}).hasOwnProperty.call(a,n)&&(e[n]=a[n])}return e},n.apply(null,arguments)}a.d(t,{A:()=>n})}}]);
Save File
Cancel