strapi-plugin-navigation 3.3.1-beta.1 → 3.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/admin/index.js +2 -2
- package/dist/admin/index.mjs +317 -312
- package/package.json +3 -3
package/dist/admin/index.js
CHANGED
|
@@ -177,8 +177,8 @@
|
|
|
177
177
|
@media (min-width: 768px) {
|
|
178
178
|
order: ${({orderMedium:e})=>e??"unset"};
|
|
179
179
|
}
|
|
180
|
-
`,Ka=()=>{const{formatMessage:e}=E.useIntl(),{values:n,onChange:a,handleChange:i,renderError:s,canUpdate:r}=ne();return t.jsx(Ua,{alignItems:"flex-start",col:4,m:4,xs:12,orderInitial:1,orderMedium:2,children:t.jsx(N.Field,{name:"autoSync",label:e(l("popup.item.form.autoSync.label","Read fields from related")),error:s("autoSync"),children:t.jsx(o.Toggle,{name:"autoSync",checked:n.autoSync,onChange:c=>i(c,!n.autoSync,a),disabled:!r,onLabel:"Enabled",offLabel:"Disabled"})})},"autoSync")},Wa=({contentTypeItems:e,current:n,isSingleSelected:a})=>{const{formatMessage:i}=E.useIntl(),s=W(),{values:r,onChange:c,handleChange:u,renderError:g,canUpdate:m}=ne(),p=r.type==="EXTERNAL"?"externalPath":"path",C=r.type==="INTERNAL"?r:{related:void 0,relatedType:void 0},b=Oa({currentPath:r.path,isExternal:r.type==="EXTERNAL",current:n,currentType:r.type,config:s.data,contentTypeItems:e,currentRelated:C.related,currentRelatedType:C.relatedType,isSingleSelected:a}),v=!m||r.autoSync&&r.type==="INTERNAL",x=C.relatedType?s.data?.pathDefaultFields?.[C.relatedType]??[]:[],y=e?.find(({documentId:f})=>f===C.related),I=x.find(f=>y?.[f]);return t.jsx(o.Grid.Item,{alignItems:"flex-start",col:12,children:t.jsx(N.Field,{name:p,label:i(l(`popup.item.form.${p}.label`,"Path")),error:g(p,`popup.item.form.${p}.validation.type`),hint:[i(l(`popup.item.form.${p}.placeholder`,"e.g. Blog")),b?i(l("popup.item.form.type.external.description"),{value:b}):"",v?i(l("popup.item.form.type.internal.source"),{value:I||"id"}):""].join(" "),children:t.jsx(o.TextInput,{disabled:v,name:p,onChange:(f,T)=>u(f,T,c),value:(r.type==="EXTERNAL"?r.externalPath:r.path)||"",width:"100%"})})},"title")},Ha="",Xa={type:"media",required:!1,attribute:{multiple:!1,allowedTypes:["files","images","videos","audios"]},pluginOptions:{i18n:{localized:!1}}},Za=({name:e,field:n,isLoading:a,onChange:i,onChangeEnhancer:s,value:r,disabled:c})=>{const{toggleNotification:u}=F.useNotification(),{formatMessage:g}=E.useIntl(),p=F.useStrapiApp("AdditionalFieldInput",b=>b.fields).media,C=j.useMemo(()=>({id:n.name,name:e||n.name,disabled:a||c,placeholder:n.placeholder}),[n,a]);switch(j.useEffect(()=>{if(n.type==="media"){const b=S.isNull(r)?void 0:r;s(C.name,b,i)}},[r]),n.type){case"boolean":return t.jsx(o.Toggle,{...C,checked:!!r,onChange:b=>s(b,!r,i),onLabel:"true",offLabel:"false",type:"checkbox"});case"string":return t.jsx(o.Textarea,{...C,onChange:(b,v)=>s(b,v,i),value:r||Ha});case"select":return n.multi?t.jsx(o.MultiSelect,{...C,onChange:b=>s(C.name,b,i),value:S.isNil(r)?n.multi?[]:null:r,multi:n.multi,withTags:n.multi,children:n.options.map((b,v)=>t.jsx(o.MultiSelectOption,{value:b,children:b},`${n.name}-option-${v}`))}):t.jsx(o.SingleSelect,{...C,onChange:b=>s(C.name,b,i),value:S.isNil(r)?n.multi?[]:null:r,multi:n.multi,withTags:n.multi,children:n.options.map((b,v)=>t.jsx(o.SingleSelectOption,{value:b,children:b},`${n.name}-option-${v}`))});case"media":return t.jsx(p,{...C,...Xa,value:r});default:throw u({type:"warning",message:g(l("notification.error.customField.type"))}),new Error("Type of custom field is unsupported")}},Ja=({additionalField:e})=>{const{canUpdate:n,isLoading:a,onChange:i,handleChange:s,renderError:r,values:c}=ne();return t.jsx(o.Grid.Item,{alignItems:"flex-start",s:6,xs:12,children:t.jsx(N.Field,{name:`additionalFields.${e.name}`,label:e.label,hint:e.description,required:e.required,error:r(`additionalFields.${e.name}`),children:t.jsx(Za,{name:`additionalFields.${e.name}`,field:e,isLoading:a,onChange:i,onChangeEnhancer:s,value:S.get(c?.additionalFields,e.name),disabled:!n})})},e.name)},Ya=()=>{const{formatMessage:e}=E.useIntl(),a=W().data?.availableAudience??[],i=j.useMemo(()=>a.map(m=>({value:m.documentId??0,label:m.name??" "})),[a]),{isLoading:s,renderError:r,onChange:c,handleChange:u,values:g}=ne();return t.jsx(o.Grid.Item,{alignItems:"flex-start",col:12,children:t.jsx(N.Field,{name:"audience",label:e(l("popup.item.form.audience.label")),error:r("audience"),hint:!s&&S.isEmpty(i)?e(l("popup.item.form.title.placeholder","e.g. Blog")):void 0,children:t.jsx(o.MultiSelect,{name:"audience",value:g.audience,onChange:m=>u("audience",m,c),width:"100%",children:i.map(({value:m,label:p})=>t.jsx(o.MultiSelectOption,{value:m,children:p},m))})})},"audience")},eo=()=>{const e=W();if(!e.data?.additionalFields||S.isEmpty(e.data.additionalFields))return null;const n=e.data.additionalFields.filter(i=>i!=="audience"),a=e.data.additionalFields.find(i=>i==="audience");return t.jsxs(t.Fragment,{children:[t.jsx(o.Grid.Root,{gap:5,paddingTop:1,paddingBottom:1,children:t.jsx(o.Grid.Item,{col:12,children:t.jsx(o.Divider,{width:"100%"})})}),t.jsxs(o.Grid.Root,{gap:5,paddingTop:1,paddingBottom:1,children:[n.map(i=>t.jsx(Ja,{additionalField:i},i.name)),a&&t.jsx(Ya,{})]}),t.jsx(o.Grid.Root,{gap:5,paddingTop:1,paddingBottom:1,children:t.jsx(o.Grid.Item,{col:12,children:t.jsx(o.Divider,{width:"100%"})})})]})},to=({availableLocale:e,current:n,currentNavigation:a,setIsLoading:i,setFormValuesItems:s})=>{const{formatMessage:r}=E.useIntl(),[c,u]=j.useState(),g=Nn(),m=Ge(),{canUpdate:p,isLoading:C}=ne(),b=j.useMemo(()=>e.map((x,y)=>({key:`${x}-${y}`,value:x,label:x})),[e]),v=j.useCallback(async x=>{x.preventDefault(),x.stopPropagation();const y=m.data?.find(({locale:I})=>I===c);y&&(i(!0),g.mutate({target:a.documentId,structureId:n.structureId,source:y.documentId},{onSuccess(I){g.reset();const{type:f,externalPath:T,path:L,related:B,title:P,uiRouterKey:w}=I;s({type:f,externalPath:T,path:L,title:P,uiRouterKey:w,related:B})},onSettled(){i(!1)}}))},[i,g,m]);return!b||b.length<1?null:t.jsx(o.Grid.Root,{gap:5,paddingTop:1,paddingBottom:1,children:t.jsxs(o.Grid.Item,{alignItems:"flex-start",col:12,children:[t.jsx(o.Divider,{marginTop:5,marginBottom:5}),t.jsxs(o.Grid.Root,{gap:5,children:[t.jsx(o.Grid.Item,{alignItems:"flex-start",col:6,lg:12,children:t.jsx(N.Field,{name:"i18n.locale",label:r(l("popup.item.form.i18n.locale.label","Copy details from")),children:t.jsx(o.SingleSelect,{name:"i18n.locale",onChange:u,value:c,disabled:C||!p,placeholder:r(l("popup.item.form.i18n.locale.placeholder","locale")),children:b.map(({key:x,label:y,value:I})=>t.jsx(o.SingleSelectOption,{value:I,children:y},x))})})}),p&&t.jsx(o.Grid.Item,{alignItems:"flex-start",col:6,lg:12,paddingTop:6,children:t.jsx(o.Box,{children:t.jsx(o.Button,{variant:"tertiary",onClick:v,disabled:C||!c,children:r(l("popup.item.form.i18n.locale.button"))})})})]})]},"title")})},at=(e,n)=>n?e.find(a=>a.value===n)?.label??"":"",vt=({name:e,onClear:n,onChange:a,options:i,value:s,disabled:r})=>{const[c,u]=j.useState(at(i,s));return j.useEffect(()=>{u(at(i,s))},[s,i]),t.jsx(o.Combobox,{name:e,autocomplete:"list",onClear:n,onChange:a,onTextValueChange:u,value:s,textValue:c,options:i,disabled:r,width:"100%",children:i.map(({key:g,label:m,value:p})=>t.jsx(o.ComboboxOption,{value:p,children:m},g))})},no=({contentTypeItems:e,current:n,currentRelatedType:a,isSingleSelected:i,setFormValuesItems:s,setIsSingleSelected:r})=>{const{formatMessage:c}=E.useIntl(),u=W(),{canUpdate:g,isLoading:m,renderError:p,setFormValueItem:C,values:b}=ne(),v=j.useMemo(()=>S.sortBy(u.data?.contentTypes.map(x=>({key:x.uid,value:x.uid,label:x.label})),x=>x.label),[u.data,a]);return j.useEffect(()=>{if(!a)return;const x=u.data?.contentTypes.find(y=>y.uid===a);if(x&&(r(x.isSingle),x.isSingle&&e?.length)){const y=e[0];y&&C("related",y.documentId)}},[a,u.data,e]),j.useEffect(()=>{a===""&&C("relatedType",u.data?.defaultContentType)},[u.data?.defaultContentType,b.type,a]),t.jsx(o.Grid.Item,{alignItems:"flex-start",m:a&&!i?6:12,xs:12,children:t.jsx(N.Field,{name:"relatedType",label:c(l("popup.item.form.relatedType.label","Related Type")),error:p("relatedType"),hint:!m&&S.isEmpty(v)?c(l("popup.item.form.relatedType.empty","There are no more content types")):void 0,children:t.jsx(vt,{name:"relatedType",onClear:()=>s({related:void 0,relatedType:void 0,title:b.autoSync?"":b.title}),onChange:x=>s({related:void 0,relatedType:x,title:b.autoSync?"":b.title}),value:a,options:v,disabled:!u.data?.contentTypes.length||!g})})})},ao=(e,n,a)=>{const i=W();j.useEffect(()=>{if(!e.autoSync||!e.related||!e.relatedType||!i.data)return;const s=n?.find(m=>m.documentId===e.related);if(!s)return;const{contentTypesNameFields:r,pathDefaultFields:c}=i.data,u=(c[e.relatedType]?.reduce((m,p)=>m||s?.[p],void 0)||s.id).toString(),g=(r[e.relatedType]??[]).concat(r.default??[]).reduce((m,p)=>m?m.toString():s?.[p],void 0);u&&e.path,g&&e.title,a({path:u,title:g})},[e.autoSync,e.related,e.relatedType,n,i.data])},oo=({appendLabelPublicationStatus:e,contentTypeItems:n,isSingleSelected:a,values:i,setFormValuesItems:s})=>{const{formatMessage:r}=E.useIntl(),c=W(),{canUpdate:u,isLoading:g,handleChange:m,onChange:p,renderError:C}=ne(),b=S.sortBy(n?.map(x=>{const I=e(Fe({...x,__collectionUid:i.relatedType},c.data),x,!1)+(x?.id?` (id: ${x.id})`:"");return{key:x?.documentId?.toString(),value:x?.documentId?.toString(),label:I}})??[],x=>x.label),v=S.isEmpty(b);return ao(i,n,s),!i.relatedType||a?null:t.jsx(o.Grid.Item,{alignItems:"flex-start",m:6,xs:12,children:t.jsx(N.Field,{name:"related",label:r(l("popup.item.form.related.label","Related")),error:C("related"),hint:!g&&v?r(l("popup.item.form.related.empty","There are no more entities"),{contentTypeName:i.relatedType}):void 0,children:t.jsx(vt,{name:"related",onClear:()=>m("related",void 0,p),onChange:x=>m("related",x,p),value:i.related,options:b,disabled:g||v||!u})})})},io=[],so=({availableLocale:e,isLoading:n,current:a=nt,onSubmit:i,onCancel:s,appendLabelPublicationStatus:r=ro,locale:c,permissions:u={},currentNavigation:g})=>{const{formatMessage:m}=E.useIntl(),[p,C]=j.useState(n),{canUpdate:b}=u,[v,x]=j.useState(!1),y=W(),I=y.data?.contentTypes??[],{toggleNotification:f}=F.useNotification(),{formValue:T,renderError:L,setFormError:B,handleChange:P,setFormValue:w,setFormValueItem:M,setFormValuesItems:D}=qa(),{encodePayload:Z,decodePayload:O}=za(),J=T.type==="INTERNAL",ae=J&&!T.related&&!v||p,U=gt({uid:J?T.relatedType:"",locale:c}),xe=async(Q,A)=>{Q.preventDefault();const _=Z(A),{success:Y,data:G,error:ce}=Pa({isSingleSelected:v,additionalFields:y.data?.additionalFields??io}).safeParse(_);if(Y){const oe=G.title.trim()?G.title.trim():G.type==="INTERNAL"?de(G?.related?.toString(),G.relatedType,v):"";C(!0);const ie=await Ba(G.type==="INTERNAL"?{slugify:te.mutateAsync,title:oe,related:G.related,relatedType:G.relatedType}:{slugify:te.mutateAsync,title:oe});if(te.reset(),C(!1),!ie){f({type:"warning",message:m(l("popup.item.form.uiRouter.unableToRender"))});return}i(G.type==="INTERNAL"?{...G,title:oe,uiRouterKey:ie}:{...G,title:oe,uiRouterKey:ie})}else ce&&B(ce.issues.reduce((oe,ie)=>({...oe,[ie.path.join(".")]:ie.message}),{}))},te=ka(),de=j.useCallback((Q,A,_)=>{let Y;if(_){if(Y=U.data?.find(G=>G.uid===A||G.__collectionUid===A),!Y)return I.find(G=>G.uid===A)?.contentTypeName}else Y={...U.data?.find(({documentId:ce})=>ce===Q)||{documentId:null},__collectionUid:A};return Fe(Y,y.data)},[U.data,y.data,I]);return j.useEffect(()=>{w(O({...nt,...a}))},[a]),t.jsxs(t.Fragment,{children:[t.jsx(o.Modal.Body,{children:t.jsx(F.Form,{width:"auto",height:"auto",method:"POST",initialValues:T,children:({values:Q,onChange:A})=>t.jsxs(Ct.Provider,{value:{values:Q,onChange:A,handleChange:P,renderError:L,setFormValueItem:M,canUpdate:b,isLoading:p},children:[t.jsxs(o.Grid.Root,{gap:5,paddingBottom:1,children:[t.jsx(Ga,{}),t.jsx(Va,{current:a})]}),t.jsxs(o.Grid.Root,{gap:5,paddingTop:1,paddingBottom:1,children:[t.jsx(_a,{}),Q.type==="INTERNAL"&&t.jsx(Ka,{})]}),t.jsx(o.Grid.Root,{gap:5,paddingTop:1,paddingBottom:1,children:t.jsx(Wa,{contentTypeItems:U.data,current:a,isSingleSelected:v})}),Q.type==="INTERNAL"&&t.jsxs(o.Grid.Root,{gap:5,paddingTop:1,paddingBottom:1,children:[t.jsx(no,{contentTypeItems:U.data,current:a,currentRelatedType:Q.relatedType,isSingleSelected:v,setFormValuesItems:D,setIsSingleSelected:x}),t.jsx(oo,{appendLabelPublicationStatus:r,contentTypeItems:U.data,values:Q,isSingleSelected:v,setFormValuesItems:D})]}),Q.type!=="INTERNAL"&&t.jsx(o.Grid.Root,{display:"none",children:t.jsx(o.Box,{display:"none",children:t.jsx(o.Combobox,{})})}),t.jsx(eo,{}),t.jsx(to,{availableLocale:e,current:a,currentNavigation:g,setIsLoading:C,setFormValuesItems:D}),t.jsx(o.Grid.Root,{gap:5,children:t.jsx(o.Grid.Item,{alignItems:"flex-start",col:12},"title")})]})})}),t.jsx(Aa,{handleSubmit:Q=>xe(Q,T),handleCancel:s,submitDisabled:ae,canUpdate:b})]})},ro=()=>"",lo=({isNewItem:e,canUpdate:n})=>{const{formatMessage:a}=E.useIntl();let i="view";return n&&(i=e?"new":"edit"),t.jsx(o.Modal.Header,{children:t.jsx(o.Typography,{variant:"omega",fontWeight:"bold",textColor:"neutral800",as:"h2",id:"asset-dialog-title",children:a(l(`popup.item.header.${i}`))})})},co=({availableLocale:e,isOpen:n,isLoading:a,currentItem:i={},onSubmit:s,onClose:r,locale:c,permissions:u,currentNavigation:g})=>{const{formatMessage:m}=E.useIntl(),p=v=>{s(v)},C=(v,x,y)=>`${On({relatedRef:x,type:x.isSingle?"INTERNAL":x.type,isCollection:y})?"":`[${m(l("notification.navigation.item.relation.status.draft"))}] `.toUpperCase()}${v}`,b=!!i.viewId;return t.jsx(o.Modal.Root,{labelledBy:"condition-modal-breadcrumbs",onOpenChange:v=>{v||r({preventDefault(){},stopPropagation(){},target:{}})},open:n,children:t.jsxs(o.Modal.Content,{children:[t.jsx(lo,{isNewItem:!b,canUpdate:u?.canUpdate}),t.jsx(so,{availableLocale:e,current:i,isLoading:a,onSubmit:p,onCancel:r,appendLabelPublicationStatus:C,locale:c,permissions:u,currentNavigation:g})]})})},Pe=0,uo=({value:e,setValue:n,initialIndex:a=Pe})=>{const[i,s]=j.useState(e),[r,c]=j.useState(e),[u,g]=j.useState(a),{isSmallMobile:m}=je(),[p,C]=j.useState(!!e||m),b=j.useRef(null),{formatMessage:v}=E.useIntl();j.useEffect(()=>{p&&setTimeout(()=>{b.current?.querySelector("input")?.focus()},0)},[p]),j.useEffect(()=>{u&&i===r&&n({value:i,index:u})},[u,i,r]),j.useEffect(()=>{i!==r&&(c(i),g(Pe),n({value:i,index:Pe}))},[i,r]);const x=j.useCallback(f=>{f.code.toLowerCase()==="enter"&&g(T=>T+1)},[]),y=j.useCallback(f=>{s(f.target.value)},[s]),I=j.useCallback(()=>{s(""),C(!1)},[s,C]);return p?t.jsxs("div",{ref:b,style:{width:"100%"},children:[t.jsx(o.Searchbar,{name:"searchbar",onClear:I,value:e,size:"S",onChange:y,clearLabel:"Clearing the search",placeholder:v(l("pages.main.search.placeholder","Type to start searching...")),onKeyDown:x,children:"Search for navigation items"}),t.jsx(o.Typography,{variant:"pi",fontColor:"neutral150",style:{margin:"3px 0 0"},display:{initial:"none",medium:"inline-block"},children:v(l("pages.main.search.subLabel","press ENTER to highlight next item"))})]}):t.jsx(o.IconButton,{children:t.jsx(R.Search,{}),onClick:()=>C(!p)})},po=({currentNavigation:e,setCurrentNavigation:n,canUpdate:a,addNewNavigationItem:i})=>{const{formatMessage:s}=E.useIntl(),r=j.useCallback(()=>{e&&n({...e,items:e.items.map(m=>he(m,!1))})},[n,e,he]),c=j.useCallback(()=>{e&&n({...e,items:e.items.map(m=>he(m,!0))})},[n,e,he]),u=j.useCallback(m=>{const p=(e?.items??[]).reduce((C,{order:b})=>Math.max(C,b),0);i(m,void 0,!0,"",!0,e?.items.length.toString(),p+1)},[i,e?.items]),g=[{onClick:r,type:"submit",variant:"tertiary",tradId:"header.action.expandAll",margin:"8px"},{onClick:c,type:"submit",variant:"tertiary",tradId:"header.action.collapseAll",margin:"8px"}];return a&&g.push({onClick:u,type:"submit",variant:"primary",tradId:"header.action.newItem",startIcon:t.jsx(R.Plus,{}),margin:"8px"}),g.map(({tradId:m,margin:p,...C},b)=>t.jsx(o.Box,{marginLeft:{initial:0,small:p},children:t.jsxs(o.Button,{...C,children:[" ",s(l(m))," "]})},b))},mo=({canUpdate:e,addNewNavigationItem:n,availableLocale:a,availableNavigations:i,currentNavigation:s,setCurrentNavigation:r})=>{const c=An(),{formatMessage:u}=E.useIntl(),g=vn(),m=Cn(),{i18nCopyItemsModal:p,i18nCopySourceLocale:C,setI18nCopyModalOpened:b,setI18nCopySourceLocale:v}=Mn(j.useCallback(y=>{const I=i.find(({locale:f,documentId:T})=>f===y&&T===s?.documentId);I&&I.documentId&&s?.documentId&&c.mutate({source:I.locale,target:s.locale,documentId:I.documentId},{onSuccess(f){c.reset(),r({...f.data,items:f.data.items.map(Te)}),g(),m()}})},[s])),x=j.useCallback(()=>{C&&b(!0)},[b,C]);return t.jsxs(o.Flex,{direction:"column",minHeight:"400px",justifyContent:"center",children:[t.jsx(o.Box,{padding:4,children:t.jsx(o.Typography,{variant:"beta",textColor:"neutral600",children:u(l("empty.description"))})}),e&&t.jsx(o.Button,{variant:"secondary",startIcon:t.jsx(R.ListPlus,{}),label:u(l("empty.cta")),onClick:n,children:u(l("empty.cta"))}),e&&!!a.length&&t.jsxs(o.Flex,{direction:"column",justifyContent:"center",children:[t.jsx(o.Box,{paddingTop:3,paddingBottom:3,children:t.jsx(o.Typography,{variant:"beta",textColor:"neutral600",children:u(l("view.i18n.fill.cta.header"))})}),t.jsxs(o.Flex,{direction:"row",justifyContent:"center",alignItems:"center",children:[t.jsx(o.Box,{paddingLeft:1,paddingRight:1,children:t.jsx(o.SingleSelect,{onChange:v,value:C,size:"S",children:a.map(y=>t.jsx(o.SingleSelectOption,{value:y,children:u(l("view.i18n.fill.option"),{locale:y})},y))})}),t.jsx(o.Box,{paddingLeft:1,paddingRight:1,children:t.jsx(o.Button,{variant:"tertiary",onClick:x,disabled:!C,size:"S",children:u(l("view.i18n.fill.cta.button"))})})]})]}),e&&p]})},go=new $.QueryClient,ho=()=>{const{formatMessage:e}=E.useIntl(),n=Ge(),a=W(),i=ft(),{toggleNotification:s}=F.useNotification(),[r,c]=j.useState(),[u,g]=j.useState(),[m,p]=j.useState(!1),{canAccess:C,canUpdate:b,isLoadingForPermissions:v}=Dn(),{localeData:x,currentLocale:y,isChangeLanguageVisible:I,changeCurrentLocaleAction:f,availableLocales:T}=zn(n.data,p),{searchValue:L,setSearchValue:B,isSearchEmpty:P,filteredList:w}=Bn(u),{activeNavigationItem:M,addNewNavigationItem:D,editNavigationItem:Z,closeNavigationItemPopup:O,isItemPopupVisible:J}=qn(b),ae=xt([n,{isPending:v}]),U=ht({onError:A=>{s({type:"danger",message:e(l("notification.navigation.update.error"))});try{console.error(A),console.log(A.response.data.error)}catch{}},onSuccess:A=>{g({...A,items:A.items.map(Te)}),c({documentId:A.documentId,id:A.id}),p(!1)}}),xe=()=>{u&&U.mutate(u)},te=A=>{A.preventDefault(),A.stopPropagation(),A.target.tagName!=="HTML"&&O()},de=A=>{if(u&&a.data){const _=fe(A,u?.items??[],a.data);g({...u,items:_}),p(!0),O()}},Q=P?u?.items??[]:w;return j.useEffect(()=>{if(!u&&n.data?.[0]){let A;r?.documentId&&(A=n.data.find(_=>_.documentId===r.documentId&&_.id===r.id)),c(void 0),g(A||S.first(n.data))}},[n.data,u]),j.useEffect(()=>{if(u&&y!==u.locale){c(void 0);const A=n.data?.find(_=>_.documentId===u.documentId&&_.locale===y);A&&A.documentId===u.documentId&&A.locale!==u.locale&&g(A)}},[u,y,n.data]),Pn(),!n.data||!x||ae?t.jsx(F.Page.Loading,{}):t.jsxs(F.Layouts.Root,{children:[t.jsx(F.Page.Title,{children:e(l("header.title","UI Navigation"))}),t.jsxs(F.Page.Main,{children:[t.jsx(ua,{availableNavigations:n.data,activeNavigation:u,handleCachePurge:()=>i.mutate(void 0),handleChangeSelection:g,handleLocalizationSelection:m?f.trigger:f.perform,handleSave:xe,locale:x,structureHasChanged:m,isSaving:U.isPending,permissions:{canUpdate:b},currentLocale:y}),t.jsxs(F.Layouts.Content,{children:[t.jsx(ma,{startActions:t.jsx(uo,{value:L,setValue:B}),endActions:t.jsx(po,{currentNavigation:u,setCurrentNavigation:g,canUpdate:b,addNewNavigationItem:D})}),u?.items.length?t.jsx(It,{items:Q,onItemLevelAdd:D,onItemEdit:Z,onItemSubmit:de,displayFlat:!P,isParentAttachedToMenu:!0,permissions:{canUpdate:b,canAccess:C},structurePrefix:"",locale:y??""}):t.jsx(mo,{canUpdate:b,addNewNavigationItem:D,availableLocale:T,availableNavigations:n.data,currentNavigation:u,setCurrentNavigation:g}),J&&y&&u&&t.jsx(co,{availableLocale:T,currentItem:M,onSubmit:de,onClose:te,locale:y,permissions:{canUpdate:b},isOpen:J,isLoading:v,currentNavigation:u}),I&&t.jsx(pa,{onCancel:()=>f.cancel(),onConfirm:()=>f.perform()})]})]})]})};function fo(){return t.jsx($.QueryClientProvider,{client:go,children:t.jsx(ho,{})})}const yo=()=>t.jsx(ze.DndProvider,{backend:Pt.HTML5Backend,children:t.jsxs(Re.Routes,{children:[t.jsx(Re.Route,{path:"/",index:!0,Component:fo}),t.jsx(Re.Route,{path:"/*",Component:F.Page.Error})]})}),xo=/^(?<type>[a-z0-9-]+)\:{2}(?<api>[a-z0-9-]+)\.{1}(?<contentType>[a-z0-9-]+)$/i,bo=(e="",n={})=>{const{allowedContentTypes:a=[],restrictedContentTypes:i=[],contentTypes:s=[],preferCustomContentTypes:r=!1}=n,u=(r?["api::",...s]:a).filter(m=>e.includes(m)||e===m).length>0,g=i.filter(m=>e.includes(m)||e===m).length===0;return!!e&&u&&g},jo=(e="")=>{const n=r=>r.split("-").map(c=>S.capitalize(c)).join(""),[a,i,s]=Io(e);return a==="api"?n(s):`${n(i)}${n(s)}`},Io=(e="")=>e.split(xo).filter(n=>n&&n.length>0),ot="SERVER OFFLINE",Tt=(e,n)=>new Promise(a=>{fetch(`${window.strapi.backendURL}/_health`,{method:"HEAD",mode:"no-cors",headers:{"Content-Type":"application/json","Keep-Alive":"false"}}).then(i=>{if(i.status>=400)throw new Error;if(!n)throw new Error(ot);a(e)}).catch(i=>{setTimeout(()=>Tt(e,i.message!==ot).then(a),100)})}),_e=()=>{const e=F.getFetchClient(),n=z(e);return $.useQuery({queryKey:n.readSettingsConfigIndex(),queryFn(){return n.readSettingsConfig()},staleTime:1e3*60*5})},St=()=>{const e=F.getFetchClient(),n=z(e),a=$.useQuery({queryKey:n.healthCheckIndex(),queryFn:()=>n.healthCheck(),retry:!0,retryDelay:1e3*5,enabled:!1});return $.useMutation({mutationFn:()=>n.restart().then(()=>a.refetch())})},Ft=()=>{const e=F.getFetchClient(),n=z(e);return $.useMutation({mutationFn:()=>n.restoreConfig()})},we=()=>{const e=F.getFetchClient(),n=z(e);return $.useQuery({queryKey:n.readContentTypeIndex(),queryFn:()=>n.readContentType(),staleTime:1/0})},Co=()=>{const e=F.getFetchClient(),n=z(e);return $.useMutation({mutationFn(a){return n.updateConfig({...a,contentTypesNameFields:Object.fromEntries(a.contentTypesNameFields.map(({key:i,fields:s})=>[i,s])),contentTypesPopulate:Object.fromEntries(a.contentTypesPopulate.map(({key:i,fields:s})=>[i,s])),pathDefaultFields:Object.fromEntries(a.pathDefaultFields.map(({key:i,fields:s})=>[i,s])),additionalFields:a.audienceFieldChecked?[...a.additionalFields,"audience"]:a.additionalFields,gql:{navigationItemRelated:a.contentTypes.map(i=>jo(i))}})}})},ke=(e,n)=>{const a=n.map(s=>({key:s,fields:e[s]??[]}));return Object.entries(e).filter(([s,r])=>!n.includes(s)).map(([s,r])=>({key:s,fields:r})).concat(a)},vo=({config:e,setFormValue:n})=>{j.useEffect(()=>{if(e){const{additionalFields:a,contentTypes:i,contentTypesNameFields:s,contentTypesPopulate:r,pathDefaultFields:c}=e;n({...e,additionalFields:a.filter(u=>typeof u!="string"),audienceFieldChecked:a.includes("audience"),contentTypesNameFields:ke(s,i),contentTypesPopulate:ke(r,i),pathDefaultFields:ke(c,i)})}},[e])},To=["string","boolean","select","media"],Ie={background:"neutral0",hasRadius:!0,shadow:"filterShadow",padding:6},wt=j.createContext({values:{},onChange:()=>null,handleChange:()=>null,restartStatus:{required:!1},setRestartStatus:()=>null,renderError:()=>"",setFormValueItem:()=>null}),le=()=>j.useContext(wt),So=({hasSettingsReadPermissions:e})=>{const{formatMessage:n}=E.useIntl(),a=Ft(),{setRestartStatus:i}=le(),[s,r]=j.useState(!1),c=async u=>{r(!1),u&&(a.mutate(),i({required:!0}))};return t.jsx(o.Box,{...Ie,width:"100%",children:t.jsxs(o.Flex,{direction:"column",alignItems:"flex-start",gap:2,children:[t.jsx(o.Typography,{variant:"delta",as:"h2",children:n(l("pages.settings.restoring.title"))}),t.jsxs(o.Grid.Root,{gap:4,width:"100%",children:[t.jsx(o.Grid.Item,{col:12,s:12,xs:12,children:t.jsx(o.Typography,{children:n(l("pages.settings.actions.restore.description"))})}),t.jsxs(o.Grid.Item,{col:12,s:12,xs:12,children:[e&&t.jsx(o.Button,{variant:"danger-light",startIcon:t.jsx(R.Check,{}),onClick:()=>r(!0),children:n(l("pages.settings.actions.restore.label"))}),t.jsx(Se,{isVisible:s,header:n(l("pages.settings.actions.restore.confirmation.header")),labelConfirm:n(l("pages.settings.actions.restore.confirmation.confirm")),iconConfirm:t.jsx(R.Typhoon,{}),onConfirm:()=>c(!0),onCancel:()=>c(!1),children:n(l("pages.settings.actions.restore.confirmation.description"))})]})]})]})})},Fo=X.default(o.Alert)`
|
|
180
|
+
`,Ka=()=>{const{formatMessage:e}=E.useIntl(),{values:n,onChange:a,handleChange:i,renderError:s,canUpdate:r}=ne();return t.jsx(Ua,{alignItems:"flex-start",col:4,m:4,xs:12,orderInitial:1,orderMedium:2,children:t.jsx(N.Field,{name:"autoSync",label:e(l("popup.item.form.autoSync.label","Read fields from related")),error:s("autoSync"),children:t.jsx(o.Toggle,{name:"autoSync",checked:n.autoSync,onChange:c=>i(c,!n.autoSync,a),disabled:!r,onLabel:"Enabled",offLabel:"Disabled"})})},"autoSync")},Wa=({contentTypeItems:e,current:n,isSingleSelected:a})=>{const{formatMessage:i}=E.useIntl(),s=W(),{values:r,onChange:c,handleChange:u,renderError:g,canUpdate:m}=ne(),p=r.type==="EXTERNAL"?"externalPath":"path",C=r.type==="INTERNAL"?r:{related:void 0,relatedType:void 0},b=Oa({currentPath:r.path,isExternal:r.type==="EXTERNAL",current:n,currentType:r.type,config:s.data,contentTypeItems:e,currentRelated:C.related,currentRelatedType:C.relatedType,isSingleSelected:a}),v=!m||r.autoSync&&r.type==="INTERNAL",x=C.relatedType?s.data?.pathDefaultFields?.[C.relatedType]??[]:[],y=e?.find(({documentId:f})=>f===C.related),I=x.find(f=>y?.[f]);return t.jsx(o.Grid.Item,{alignItems:"flex-start",col:12,children:t.jsx(N.Field,{name:p,label:i(l(`popup.item.form.${p}.label`,"Path")),error:g(p,`popup.item.form.${p}.validation.type`),hint:[i(l(`popup.item.form.${p}.placeholder`,"e.g. Blog")),b?i(l("popup.item.form.type.external.description"),{value:b}):"",v?i(l("popup.item.form.type.internal.source"),{value:I||"id"}):""].join(" "),children:t.jsx(o.TextInput,{disabled:v,name:p,onChange:(f,T)=>u(f,T,c),value:(r.type==="EXTERNAL"?r.externalPath:r.path)||"",width:"100%"})})},"title")},Ha="",Xa={type:"media",required:!1,attribute:{multiple:!1,allowedTypes:["files","images","videos","audios"]},pluginOptions:{i18n:{localized:!1}}},Za=({name:e,field:n,isLoading:a,onChange:i,onChangeEnhancer:s,value:r,disabled:c})=>{const{toggleNotification:u}=F.useNotification(),{formatMessage:g}=E.useIntl(),p=F.useStrapiApp("AdditionalFieldInput",b=>b.fields).media,C=j.useMemo(()=>({id:n.name,name:e||n.name,disabled:a||c,placeholder:n.placeholder}),[n,a]);switch(j.useEffect(()=>{if(n.type==="media"){const b=S.isNull(r)?void 0:r;s(C.name,b,i)}},[r]),n.type){case"boolean":return t.jsx(o.Toggle,{...C,checked:!!r,onChange:b=>s(b,!r,i),onLabel:"true",offLabel:"false",type:"checkbox"});case"string":return t.jsx(o.Textarea,{...C,onChange:(b,v)=>s(b,v,i),value:r||Ha});case"select":return n.multi?t.jsx(o.MultiSelect,{...C,onChange:b=>s(C.name,b,i),value:S.isNil(r)?n.multi?[]:null:r,multi:n.multi,withTags:n.multi,children:n.options.map((b,v)=>t.jsx(o.MultiSelectOption,{value:b,children:b},`${n.name}-option-${v}`))}):t.jsx(o.SingleSelect,{...C,onChange:b=>s(C.name,b,i),value:S.isNil(r)?n.multi?[]:null:r,multi:n.multi,withTags:n.multi,children:n.options.map((b,v)=>t.jsx(o.SingleSelectOption,{value:b,children:b},`${n.name}-option-${v}`))});case"media":return t.jsx(p,{...C,...Xa,value:r});default:throw u({type:"warning",message:g(l("notification.error.customField.type"))}),new Error("Type of custom field is unsupported")}},Ja=({additionalField:e})=>{const{canUpdate:n,isLoading:a,onChange:i,handleChange:s,renderError:r,values:c}=ne();return t.jsx(o.Grid.Item,{alignItems:"flex-start",s:6,xs:12,children:t.jsx(N.Field,{name:`additionalFields.${e.name}`,label:e.label,hint:e.description,required:e.required,error:r(`additionalFields.${e.name}`),children:t.jsx(Za,{name:`additionalFields.${e.name}`,field:e,isLoading:a,onChange:i,onChangeEnhancer:s,value:S.get(c?.additionalFields,e.name),disabled:!n})})},e.name)},Ya=()=>{const{formatMessage:e}=E.useIntl(),a=W().data?.availableAudience??[],i=j.useMemo(()=>a.map(m=>({value:m.documentId??0,label:m.name??" "})),[a]),{isLoading:s,renderError:r,onChange:c,handleChange:u,values:g}=ne();return t.jsx(o.Grid.Item,{alignItems:"flex-start",col:12,children:t.jsx(N.Field,{name:"audience",label:e(l("popup.item.form.audience.label")),error:r("audience"),hint:!s&&S.isEmpty(i)?e(l("popup.item.form.title.placeholder","e.g. Blog")):void 0,children:t.jsx(o.MultiSelect,{name:"audience",value:g.audience,onChange:m=>u("audience",m,c),width:"100%",children:i.map(({value:m,label:p})=>t.jsx(o.MultiSelectOption,{value:m,children:p},m))})})},"audience")},eo=()=>{const e=W();if(!e.data?.additionalFields||S.isEmpty(e.data.additionalFields))return null;const n=e.data.additionalFields.filter(i=>i!=="audience"),a=e.data.additionalFields.find(i=>i==="audience");return t.jsxs(t.Fragment,{children:[t.jsx(o.Grid.Root,{gap:5,paddingTop:1,paddingBottom:1,children:t.jsx(o.Grid.Item,{col:12,children:t.jsx(o.Divider,{width:"100%"})})}),t.jsxs(o.Grid.Root,{gap:5,paddingTop:1,paddingBottom:1,children:[n.map(i=>t.jsx(Ja,{additionalField:i},i.name)),a&&t.jsx(Ya,{})]}),t.jsx(o.Grid.Root,{gap:5,paddingTop:1,paddingBottom:1,children:t.jsx(o.Grid.Item,{col:12,children:t.jsx(o.Divider,{width:"100%"})})})]})},to=({availableLocale:e,current:n,currentNavigation:a,setIsLoading:i,setFormValuesItems:s})=>{const{formatMessage:r}=E.useIntl(),[c,u]=j.useState(),g=Nn(),m=Ge(),{canUpdate:p,isLoading:C}=ne(),b=j.useMemo(()=>e.map((x,y)=>({key:`${x}-${y}`,value:x,label:x})),[e]),v=j.useCallback(async x=>{x.preventDefault(),x.stopPropagation();const y=m.data?.find(({locale:I})=>I===c);y&&(i(!0),g.mutate({target:a.documentId,structureId:n.structureId,source:y.documentId},{onSuccess(I){g.reset();const{type:f,externalPath:T,path:L,related:B,title:P,uiRouterKey:w}=I;s({type:f,externalPath:T,path:L,title:P,uiRouterKey:w,related:B})},onSettled(){i(!1)}}))},[i,g,m]);return!b||b.length<1?null:t.jsx(o.Grid.Root,{gap:5,paddingTop:1,paddingBottom:1,children:t.jsxs(o.Grid.Item,{alignItems:"flex-start",col:12,children:[t.jsx(o.Divider,{marginTop:5,marginBottom:5}),t.jsxs(o.Grid.Root,{gap:5,children:[t.jsx(o.Grid.Item,{alignItems:"flex-start",col:6,lg:12,children:t.jsx(N.Field,{name:"i18n.locale",label:r(l("popup.item.form.i18n.locale.label","Copy details from")),children:t.jsx(o.SingleSelect,{name:"i18n.locale",onChange:u,value:c,disabled:C||!p,placeholder:r(l("popup.item.form.i18n.locale.placeholder","locale")),children:b.map(({key:x,label:y,value:I})=>t.jsx(o.SingleSelectOption,{value:I,children:y},x))})})}),p&&t.jsx(o.Grid.Item,{alignItems:"flex-start",col:6,lg:12,paddingTop:6,children:t.jsx(o.Box,{children:t.jsx(o.Button,{variant:"tertiary",onClick:v,disabled:C||!c,children:r(l("popup.item.form.i18n.locale.button"))})})})]})]},"title")})},at=(e,n)=>n?e.find(a=>a.value===n)?.label??"":"",vt=({name:e,onClear:n,onChange:a,options:i,value:s,disabled:r})=>{const[c,u]=j.useState(at(i,s));return j.useEffect(()=>{u(at(i,s))},[s,i]),t.jsx(o.Combobox,{name:e,autocomplete:"list",onClear:n,onChange:a,onTextValueChange:u,value:s,textValue:c,options:i,disabled:r,width:"100%",children:i.map(({key:g,label:m,value:p})=>t.jsx(o.ComboboxOption,{value:p,children:m},g))})},no=({contentTypeItems:e,current:n,currentRelatedType:a,isSingleSelected:i,setFormValuesItems:s,setIsSingleSelected:r})=>{const{formatMessage:c}=E.useIntl(),u=W(),{canUpdate:g,isLoading:m,renderError:p,setFormValueItem:C,values:b}=ne(),v=j.useMemo(()=>S.sortBy(u.data?.contentTypes.map(x=>({key:x.uid,value:x.uid,label:x.label})),x=>x.label),[u.data,a]);return j.useEffect(()=>{if(!a)return;const x=u.data?.contentTypes.find(y=>y.uid===a);if(x&&(r(x.isSingle),x.isSingle&&e?.length)){const y=e[0];y&&C("related",y.documentId)}},[a,u.data,e]),j.useEffect(()=>{a===""&&C("relatedType",u.data?.defaultContentType)},[u.data?.defaultContentType,b.type,a]),t.jsx(o.Grid.Item,{alignItems:"flex-start",m:a&&!i?6:12,xs:12,children:t.jsx(N.Field,{name:"relatedType",label:c(l("popup.item.form.relatedType.label","Related Type")),error:p("relatedType"),hint:!m&&S.isEmpty(v)?c(l("popup.item.form.relatedType.empty","There are no more content types")):void 0,children:t.jsx(vt,{name:"relatedType",onClear:()=>s({related:void 0,relatedType:void 0,title:b.autoSync?"":b.title}),onChange:x=>s({related:void 0,relatedType:x,title:b.autoSync?"":b.title}),value:a,options:v,disabled:!u.data?.contentTypes.length||!g})})})},ao=(e,n,a)=>{const i=W();j.useEffect(()=>{if(!e.autoSync||!e.related||!e.relatedType||!i.data)return;const s=n?.find(m=>m.documentId===e.related);if(!s)return;const{contentTypesNameFields:r,pathDefaultFields:c}=i.data,u=(c[e.relatedType]?.reduce((m,p)=>m||s?.[p],void 0)||s.id).toString(),g=(r[e.relatedType]??[]).concat(r.default??[]).reduce((m,p)=>m?m.toString():s?.[p],void 0);u&&e.path,g&&e.title,a({path:u,title:g})},[e.autoSync,e.related,e.relatedType,n,i.data])},oo=({appendLabelPublicationStatus:e,contentTypeItems:n,isSingleSelected:a,values:i,setFormValuesItems:s})=>{const{formatMessage:r}=E.useIntl(),c=W(),{canUpdate:u,isLoading:g,handleChange:m,onChange:p,renderError:C}=ne(),b=S.sortBy(n?.map(x=>{const I=e(Fe({...x,__collectionUid:i.relatedType},c.data),x,!1)+(x?.id?` (id: ${x.id})`:"");return{key:x?.documentId?.toString(),value:x?.documentId?.toString(),label:I}})??[],x=>x.label),v=S.isEmpty(b);return ao(i,n,s),!i.relatedType||a?null:t.jsx(o.Grid.Item,{alignItems:"flex-start",m:6,xs:12,children:t.jsx(N.Field,{name:"related",label:r(l("popup.item.form.related.label","Related")),error:C("related"),hint:!g&&v?r(l("popup.item.form.related.empty","There are no more entities"),{contentTypeName:i.relatedType}):void 0,children:t.jsx(vt,{name:"related",onClear:()=>m("related",void 0,p),onChange:x=>m("related",x,p),value:i.related,options:b,disabled:g||v||!u})})})},io=[],so=({availableLocale:e,isLoading:n,current:a=nt,onSubmit:i,onCancel:s,appendLabelPublicationStatus:r=ro,locale:c,permissions:u={},currentNavigation:g})=>{const{formatMessage:m}=E.useIntl(),[p,C]=j.useState(n),{canUpdate:b}=u,[v,x]=j.useState(!1),y=W(),I=y.data?.contentTypes??[],{toggleNotification:f}=F.useNotification(),{formValue:T,renderError:L,setFormError:B,handleChange:P,setFormValue:w,setFormValueItem:M,setFormValuesItems:D}=qa(),{encodePayload:Z,decodePayload:O}=za(),J=T.type==="INTERNAL",ae=J&&!T.related&&!v||p,U=gt({uid:J?T.relatedType:"",locale:c}),xe=async(Q,A)=>{Q.preventDefault();const _=Z(A),{success:Y,data:G,error:ce}=Pa({isSingleSelected:v,additionalFields:y.data?.additionalFields??io}).safeParse(_);if(Y){const oe=G.title.trim()?G.title.trim():G.type==="INTERNAL"?de(G?.related?.toString(),G.relatedType,v):"";C(!0);const ie=await Ba(G.type==="INTERNAL"?{slugify:te.mutateAsync,title:oe,related:G.related,relatedType:G.relatedType}:{slugify:te.mutateAsync,title:oe});if(te.reset(),C(!1),!ie){f({type:"warning",message:m(l("popup.item.form.uiRouter.unableToRender"))});return}i(G.type==="INTERNAL"?{...G,title:oe,uiRouterKey:ie}:{...G,title:oe,uiRouterKey:ie})}else ce&&B(ce.issues.reduce((oe,ie)=>({...oe,[ie.path.join(".")]:ie.message}),{}))},te=ka(),de=j.useCallback((Q,A,_)=>{let Y;if(_){if(Y=U.data?.find(G=>G.uid===A||G.__collectionUid===A),!Y)return I.find(G=>G.uid===A)?.contentTypeName}else Y={...U.data?.find(({documentId:ce})=>ce===Q)||{documentId:null},__collectionUid:A};return Fe(Y,y.data)},[U.data,y.data,I]);return j.useEffect(()=>{w(O({...nt,...a}))},[a]),t.jsxs(t.Fragment,{children:[t.jsx(o.Modal.Body,{children:t.jsx(F.Form,{width:"auto",height:"auto",method:"POST",initialValues:T,children:({values:Q,onChange:A})=>t.jsxs(Ct.Provider,{value:{values:Q,onChange:A,handleChange:P,renderError:L,setFormValueItem:M,canUpdate:b,isLoading:p},children:[t.jsxs(o.Grid.Root,{gap:5,paddingBottom:1,children:[t.jsx(Ga,{}),t.jsx(Va,{current:a})]}),t.jsxs(o.Grid.Root,{gap:5,paddingTop:1,paddingBottom:1,children:[t.jsx(_a,{}),Q.type==="INTERNAL"&&t.jsx(Ka,{})]}),t.jsx(o.Grid.Root,{gap:5,paddingTop:1,paddingBottom:1,children:t.jsx(Wa,{contentTypeItems:U.data,current:a,isSingleSelected:v})}),Q.type==="INTERNAL"&&t.jsxs(o.Grid.Root,{gap:5,paddingTop:1,paddingBottom:1,children:[t.jsx(no,{contentTypeItems:U.data,current:a,currentRelatedType:Q.relatedType,isSingleSelected:v,setFormValuesItems:D,setIsSingleSelected:x}),t.jsx(oo,{appendLabelPublicationStatus:r,contentTypeItems:U.data,values:Q,isSingleSelected:v,setFormValuesItems:D})]}),Q.type!=="INTERNAL"&&t.jsx(o.Grid.Root,{display:"none",children:t.jsx(o.Box,{display:"none",children:t.jsx(o.Combobox,{})})}),t.jsx(eo,{}),t.jsx(to,{availableLocale:e,current:a,currentNavigation:g,setIsLoading:C,setFormValuesItems:D}),t.jsx(o.Grid.Root,{gap:5,children:t.jsx(o.Grid.Item,{alignItems:"flex-start",col:12},"title")})]})})}),t.jsx(Aa,{handleSubmit:Q=>xe(Q,T),handleCancel:s,submitDisabled:ae,canUpdate:b})]})},ro=()=>"",lo=({isNewItem:e,canUpdate:n})=>{const{formatMessage:a}=E.useIntl();let i="view";return n&&(i=e?"new":"edit"),t.jsx(o.Modal.Header,{children:t.jsx(o.Typography,{variant:"omega",fontWeight:"bold",textColor:"neutral800",as:"h2",id:"asset-dialog-title",children:a(l(`popup.item.header.${i}`))})})},co=({availableLocale:e,isOpen:n,isLoading:a,currentItem:i={},onSubmit:s,onClose:r,locale:c,permissions:u,currentNavigation:g})=>{const{formatMessage:m}=E.useIntl(),p=v=>{s(v)},C=(v,x,y)=>`${On({relatedRef:x,type:x.isSingle?"INTERNAL":x.type,isCollection:y})?"":`[${m(l("notification.navigation.item.relation.status.draft"))}] `.toUpperCase()}${v}`,b=!!i.viewId;return t.jsx(o.Modal.Root,{labelledBy:"condition-modal-breadcrumbs",onOpenChange:v=>{v||r({preventDefault(){},stopPropagation(){},target:{}})},open:n,children:t.jsxs(o.Modal.Content,{children:[t.jsx(lo,{isNewItem:!b,canUpdate:u?.canUpdate}),t.jsx(so,{availableLocale:e,current:i,isLoading:a,onSubmit:p,onCancel:r,appendLabelPublicationStatus:C,locale:c,permissions:u,currentNavigation:g})]})})},Pe=0,uo=({value:e,setValue:n,initialIndex:a=Pe})=>{const[i,s]=j.useState(e),[r,c]=j.useState(e),[u,g]=j.useState(a),{isSmallMobile:m}=je(),[p,C]=j.useState(!!e||m),b=j.useRef(null),{formatMessage:v}=E.useIntl();j.useEffect(()=>{p&&setTimeout(()=>{b.current?.querySelector("input")?.focus()},0)},[p]),j.useEffect(()=>{u&&i===r&&n({value:i,index:u})},[u,i,r]),j.useEffect(()=>{i!==r&&(c(i),g(Pe),n({value:i,index:Pe}))},[i,r]);const x=j.useCallback(f=>{f.code.toLowerCase()==="enter"&&g(T=>T+1)},[]),y=j.useCallback(f=>{s(f.target.value)},[s]),I=j.useCallback(()=>{s(""),C(!1)},[s,C]);return p?t.jsxs("div",{ref:b,style:{width:"100%"},children:[t.jsx(o.Searchbar,{name:"searchbar",onClear:I,value:e,size:"S",onChange:y,clearLabel:"Clearing the search",placeholder:v(l("pages.main.search.placeholder","Type to start searching...")),onKeyDown:x,children:"Search for navigation items"}),t.jsx(o.Typography,{variant:"pi",fontColor:"neutral150",style:{margin:"3px 0 0"},display:{initial:"none",medium:"inline-block"},children:v(l("pages.main.search.subLabel","press ENTER to highlight next item"))})]}):t.jsx(o.IconButton,{children:t.jsx(R.Search,{}),onClick:()=>C(!p)})},po=({currentNavigation:e,setCurrentNavigation:n,canUpdate:a,addNewNavigationItem:i})=>{const{formatMessage:s}=E.useIntl(),r=j.useCallback(()=>{e&&n({...e,items:e.items.map(m=>he(m,!1))})},[n,e,he]),c=j.useCallback(()=>{e&&n({...e,items:e.items.map(m=>he(m,!0))})},[n,e,he]),u=j.useCallback(m=>{const p=(e?.items??[]).reduce((C,{order:b})=>Math.max(C,b),0);i(m,void 0,!0,"",!0,e?.items.length.toString(),p+1)},[i,e?.items]),g=[{onClick:r,type:"submit",variant:"tertiary",tradId:"header.action.expandAll",margin:"8px"},{onClick:c,type:"submit",variant:"tertiary",tradId:"header.action.collapseAll",margin:"8px"}];return a&&g.push({onClick:u,type:"submit",variant:"primary",tradId:"header.action.newItem",startIcon:t.jsx(R.Plus,{}),margin:"8px"}),g.map(({tradId:m,margin:p,...C},b)=>t.jsx(o.Box,{marginLeft:{initial:0,small:p},children:t.jsxs(o.Button,{...C,children:[" ",s(l(m))," "]})},b))},mo=({canUpdate:e,addNewNavigationItem:n,availableLocale:a,availableNavigations:i,currentNavigation:s,setCurrentNavigation:r})=>{const c=An(),{formatMessage:u}=E.useIntl(),g=vn(),m=Cn(),{i18nCopyItemsModal:p,i18nCopySourceLocale:C,setI18nCopyModalOpened:b,setI18nCopySourceLocale:v}=Mn(j.useCallback(y=>{const I=i.find(({locale:f,documentId:T})=>f===y&&T===s?.documentId);I&&I.documentId&&s?.documentId&&c.mutate({source:I.locale,target:s.locale,documentId:I.documentId},{onSuccess(f){c.reset(),r({...f.data,items:f.data.items.map(Te)}),g(),m()}})},[s])),x=j.useCallback(()=>{C&&b(!0)},[b,C]);return t.jsxs(o.Flex,{direction:"column",minHeight:"400px",justifyContent:"center",children:[t.jsx(o.Box,{padding:4,children:t.jsx(o.Typography,{variant:"beta",textColor:"neutral600",children:u(l("empty.description"))})}),e&&t.jsx(o.Button,{variant:"secondary",startIcon:t.jsx(R.ListPlus,{}),label:u(l("empty.cta")),onClick:n,children:u(l("empty.cta"))}),e&&!!a.length&&t.jsxs(o.Flex,{direction:"column",justifyContent:"center",children:[t.jsx(o.Box,{paddingTop:3,paddingBottom:3,children:t.jsx(o.Typography,{variant:"beta",textColor:"neutral600",children:u(l("view.i18n.fill.cta.header"))})}),t.jsxs(o.Flex,{direction:"row",justifyContent:"center",alignItems:"center",children:[t.jsx(o.Box,{paddingLeft:1,paddingRight:1,children:t.jsx(o.SingleSelect,{onChange:v,value:C,size:"S",children:a.map(y=>t.jsx(o.SingleSelectOption,{value:y,children:u(l("view.i18n.fill.option"),{locale:y})},y))})}),t.jsx(o.Box,{paddingLeft:1,paddingRight:1,children:t.jsx(o.Button,{variant:"tertiary",onClick:x,disabled:!C,size:"S",children:u(l("view.i18n.fill.cta.button"))})})]})]}),e&&p]})},go=new $.QueryClient,ho=()=>{const{formatMessage:e}=E.useIntl(),n=Ge(),a=W(),i=ft(),{toggleNotification:s}=F.useNotification(),[r,c]=j.useState(),[u,g]=j.useState(),[m,p]=j.useState(!1),{canAccess:C,canUpdate:b,isLoadingForPermissions:v}=Dn(),{localeData:x,currentLocale:y,isChangeLanguageVisible:I,changeCurrentLocaleAction:f,availableLocales:T}=zn(n.data,p),{searchValue:L,setSearchValue:B,isSearchEmpty:P,filteredList:w}=Bn(u),{activeNavigationItem:M,addNewNavigationItem:D,editNavigationItem:Z,closeNavigationItemPopup:O,isItemPopupVisible:J}=qn(b),ae=xt([n,{isPending:v}]),U=ht({onError:A=>{s({type:"danger",message:e(l("notification.navigation.update.error"))});try{console.error(A),console.log(A.response.data.error)}catch{}},onSuccess:A=>{g({...A,items:A.items.map(Te)}),c({documentId:A.documentId,id:A.id}),p(!1)}}),xe=()=>{u&&U.mutate(u)},te=A=>{A.preventDefault(),A.stopPropagation(),A.target.tagName!=="HTML"&&O()},de=A=>{if(u&&a.data){const _=fe(A,u?.items??[],a.data);g({...u,items:_}),p(!0),O()}},Q=P?u?.items??[]:w;return j.useEffect(()=>{if(!u&&n.data?.[0]){let A;r?.documentId&&(A=n.data.find(_=>_.documentId===r.documentId&&_.id===r.id)),c(void 0),g(A||S.first(n.data))}},[n.data,u]),j.useEffect(()=>{if(u&&y!==u.locale){c(void 0);const A=n.data?.find(_=>_.documentId===u.documentId&&_.locale===y);A&&A.documentId===u.documentId&&A.locale!==u.locale&&g(A)}},[u,y,n.data]),Pn(),!n.data||!x||ae?t.jsx(F.Page.Loading,{}):t.jsxs(F.Layouts.Root,{children:[t.jsx(F.Page.Title,{children:e(l("header.title","UI Navigation"))}),t.jsxs(F.Page.Main,{children:[t.jsx(ua,{availableNavigations:n.data,activeNavigation:u,handleCachePurge:()=>i.mutate(void 0),handleChangeSelection:g,handleLocalizationSelection:m?f.trigger:f.perform,handleSave:xe,locale:x,structureHasChanged:m,isSaving:U.isPending,permissions:{canUpdate:b},currentLocale:y}),t.jsxs(F.Layouts.Content,{children:[t.jsx(ma,{startActions:t.jsx(uo,{value:L,setValue:B}),endActions:t.jsx(po,{currentNavigation:u,setCurrentNavigation:g,canUpdate:b,addNewNavigationItem:D})}),u?.items.length?t.jsx(It,{items:Q,onItemLevelAdd:D,onItemEdit:Z,onItemSubmit:de,displayFlat:!P,isParentAttachedToMenu:!0,permissions:{canUpdate:b,canAccess:C},structurePrefix:"",locale:y??""}):t.jsx(mo,{canUpdate:b,addNewNavigationItem:D,availableLocale:T,availableNavigations:n.data,currentNavigation:u,setCurrentNavigation:g}),J&&y&&u&&t.jsx(co,{availableLocale:T,currentItem:M,onSubmit:de,onClose:te,locale:y,permissions:{canUpdate:b},isOpen:J,isLoading:v,currentNavigation:u}),I&&t.jsx(pa,{onCancel:()=>f.cancel(),onConfirm:()=>f.perform()})]})]})]})};function fo(){const e=N.usePluginTheme();return t.jsx($.QueryClientProvider,{client:go,children:t.jsx(o.DesignSystemProvider,{theme:e,children:t.jsx(ho,{})})})}const yo=()=>t.jsx(ze.DndProvider,{backend:Pt.HTML5Backend,children:t.jsxs(Re.Routes,{children:[t.jsx(Re.Route,{path:"/",index:!0,Component:fo}),t.jsx(Re.Route,{path:"/*",Component:F.Page.Error})]})}),xo=/^(?<type>[a-z0-9-]+)\:{2}(?<api>[a-z0-9-]+)\.{1}(?<contentType>[a-z0-9-]+)$/i,bo=(e="",n={})=>{const{allowedContentTypes:a=[],restrictedContentTypes:i=[],contentTypes:s=[],preferCustomContentTypes:r=!1}=n,u=(r?["api::",...s]:a).filter(m=>e.includes(m)||e===m).length>0,g=i.filter(m=>e.includes(m)||e===m).length===0;return!!e&&u&&g},jo=(e="")=>{const n=r=>r.split("-").map(c=>S.capitalize(c)).join(""),[a,i,s]=Io(e);return a==="api"?n(s):`${n(i)}${n(s)}`},Io=(e="")=>e.split(xo).filter(n=>n&&n.length>0),ot="SERVER OFFLINE",Tt=(e,n)=>new Promise(a=>{fetch(`${window.strapi.backendURL}/_health`,{method:"HEAD",mode:"no-cors",headers:{"Content-Type":"application/json","Keep-Alive":"false"}}).then(i=>{if(i.status>=400)throw new Error;if(!n)throw new Error(ot);a(e)}).catch(i=>{setTimeout(()=>Tt(e,i.message!==ot).then(a),100)})}),_e=()=>{const e=F.getFetchClient(),n=z(e);return $.useQuery({queryKey:n.readSettingsConfigIndex(),queryFn(){return n.readSettingsConfig()},staleTime:1e3*60*5})},St=()=>{const e=F.getFetchClient(),n=z(e),a=$.useQuery({queryKey:n.healthCheckIndex(),queryFn:()=>n.healthCheck(),retry:!0,retryDelay:1e3*5,enabled:!1});return $.useMutation({mutationFn:()=>n.restart().then(()=>a.refetch())})},Ft=()=>{const e=F.getFetchClient(),n=z(e);return $.useMutation({mutationFn:()=>n.restoreConfig()})},we=()=>{const e=F.getFetchClient(),n=z(e);return $.useQuery({queryKey:n.readContentTypeIndex(),queryFn:()=>n.readContentType(),staleTime:1/0})},Co=()=>{const e=F.getFetchClient(),n=z(e);return $.useMutation({mutationFn(a){return n.updateConfig({...a,contentTypesNameFields:Object.fromEntries(a.contentTypesNameFields.map(({key:i,fields:s})=>[i,s])),contentTypesPopulate:Object.fromEntries(a.contentTypesPopulate.map(({key:i,fields:s})=>[i,s])),pathDefaultFields:Object.fromEntries(a.pathDefaultFields.map(({key:i,fields:s})=>[i,s])),additionalFields:a.audienceFieldChecked?[...a.additionalFields,"audience"]:a.additionalFields,gql:{navigationItemRelated:a.contentTypes.map(i=>jo(i))}})}})},ke=(e,n)=>{const a=n.map(s=>({key:s,fields:e[s]??[]}));return Object.entries(e).filter(([s,r])=>!n.includes(s)).map(([s,r])=>({key:s,fields:r})).concat(a)},vo=({config:e,setFormValue:n})=>{j.useEffect(()=>{if(e){const{additionalFields:a,contentTypes:i,contentTypesNameFields:s,contentTypesPopulate:r,pathDefaultFields:c}=e;n({...e,additionalFields:a.filter(u=>typeof u!="string"),audienceFieldChecked:a.includes("audience"),contentTypesNameFields:ke(s,i),contentTypesPopulate:ke(r,i),pathDefaultFields:ke(c,i)})}},[e])},To=["string","boolean","select","media"],Ie={background:"neutral0",hasRadius:!0,shadow:"filterShadow",padding:6},wt=j.createContext({values:{},onChange:()=>null,handleChange:()=>null,restartStatus:{required:!1},setRestartStatus:()=>null,renderError:()=>"",setFormValueItem:()=>null}),le=()=>j.useContext(wt),So=({hasSettingsReadPermissions:e})=>{const{formatMessage:n}=E.useIntl(),a=Ft(),{setRestartStatus:i}=le(),[s,r]=j.useState(!1),c=async u=>{r(!1),u&&(a.mutate(),i({required:!0}))};return t.jsx(o.Box,{...Ie,width:"100%",children:t.jsxs(o.Flex,{direction:"column",alignItems:"flex-start",gap:2,children:[t.jsx(o.Typography,{variant:"delta",as:"h2",children:n(l("pages.settings.restoring.title"))}),t.jsxs(o.Grid.Root,{gap:4,width:"100%",children:[t.jsx(o.Grid.Item,{col:12,s:12,xs:12,children:t.jsx(o.Typography,{children:n(l("pages.settings.actions.restore.description"))})}),t.jsxs(o.Grid.Item,{col:12,s:12,xs:12,children:[e&&t.jsx(o.Button,{variant:"danger-light",startIcon:t.jsx(R.Check,{}),onClick:()=>r(!0),children:n(l("pages.settings.actions.restore.label"))}),t.jsx(Se,{isVisible:s,header:n(l("pages.settings.actions.restore.confirmation.header")),labelConfirm:n(l("pages.settings.actions.restore.confirmation.confirm")),iconConfirm:t.jsx(R.Typhoon,{}),onConfirm:()=>c(!0),onCancel:()=>c(!1),children:n(l("pages.settings.actions.restore.confirmation.description"))})]})]})]})})},Fo=X.default(o.Alert)`
|
|
181
181
|
[role='status'] {
|
|
182
182
|
flex-direction: column;
|
|
183
183
|
}
|
|
184
|
-
`,wo=({setIsReloading:e})=>{const{formatMessage:n}=E.useIntl(),a=St(),{restartStatus:i,setRestartStatus:s}=le(),r=async()=>{a.mutate(void 0,{onSuccess(){e(!0),Tt(!0).then(u=>{u&&window.location.reload()})},onError(){s({required:!1})}})},c=()=>s({required:!1});return i.required?t.jsx(o.Box,{...Ie,width:"100%",children:t.jsx(Fo,{closeLabel:n(l("pages.settings.actions.restart.alert.cancel")),title:n(l("pages.settings.actions.restart.alert.title")),action:t.jsx(o.Box,{children:t.jsx(o.Button,{onClick:r,startIcon:t.jsx(R.Play,{}),children:n(l("pages.settings.actions.restart.label"))})}),onClose:c,children:t.jsxs(t.Fragment,{children:[t.jsx(o.Box,{paddingBottom:1,children:n(l("pages.settings.actions.restart.alert.description"))}),i.reasons?.map((u,g)=>t.jsx(o.Box,{paddingBottom:1,children:n(l(`pages.settings.actions.restart.alert.reason.${u}`))},g))]})})}):null},Eo=()=>{const e=_e(),{formatMessage:n}=E.useIntl(),{values:a,onChange:i,handleChange:s,restartStatus:r}=le();return t.jsx(o.Box,{...Ie,width:"100%",children:t.jsxs(o.Flex,{direction:"column",alignItems:"flex-start",gap:2,children:[t.jsx(o.Typography,{variant:"delta",as:"h2",children:n(l("pages.settings.additional.title"))}),t.jsxs(o.Grid.Root,{gap:4,width:"100%",children:[t.jsx(o.Grid.Item,{col:4,s:12,xs:12,children:t.jsx(o.Box,{width:"100%",children:t.jsx(N.Field,{name:"allowedLevels",label:n(l("pages.settings.form.allowedLevels.label")),hint:n(l("pages.settings.form.allowedLevels.hint")),children:t.jsx(o.NumberInput,{width:"100%",name:"allowedLevels",type:"number",placeholder:n(l("pages.settings.form.allowedLevels.placeholder")),onChange:(c,u)=>{if(S.isObject(c)){const g=parseInt(c.target.value);return s(c.target.name,isNaN(g)?0:g,i)}return s(c,u,i)},value:a.allowedLevels,disabled:r.required})})})}),t.jsx(o.Grid.Item,{col:4,s:12,xs:12,children:t.jsx(N.Field,{name:"cascadeMenuAttached",label:n(l("pages.settings.form.cascadeMenuAttached.label")),hint:n(l("pages.settings.form.cascadeMenuAttached.hint")),children:t.jsx(o.Toggle,{width:"100%",name:"cascadeMenuAttached",checked:a.cascadeMenuAttached,onChange:c=>s(c,!a.cascadeMenuAttached,i),onLabel:n(l("components.toggle.enabled")),offLabel:n(l("components.toggle.disabled")),disabled:r.required})})}),t.jsx(o.Grid.Item,{col:4,s:12,xs:12,children:t.jsx(N.Field,{name:"audienceFieldChecked",label:n(l("pages.settings.form.audience.label")),hint:n(l("pages.settings.form.audience.hint")),children:t.jsx(o.Toggle,{name:"audienceFieldChecked",checked:a.audienceFieldChecked,onChange:c=>s(c,!a.audienceFieldChecked,i),onLabel:n(l("components.toggle.enabled")),offLabel:n(l("components.toggle.disabled")),disabled:r.required,width:"100%"})})}),e.data?.isCachePluginEnabled&&t.jsx(o.Grid.Item,{col:12,s:12,xs:12,children:t.jsx(N.Field,{name:"isCacheEnabled",label:n(l("pages.settings.form.cache.label")),hint:n(l("pages.settings.form.cache.hint")),children:t.jsx(o.Toggle,{name:"isCacheEnabled",checked:a.isCacheEnabled,onChange:c=>s(c,!a.isCacheEnabled,i),onLabel:n(l("components.toggle.enabled")),offLabel:n(l("components.toggle.disabled")),disabled:r.required,width:"100%"})})})]})]})})},No=()=>{const{formatMessage:e}=E.useIntl(),{values:n,onChange:a,handleChange:i,restartStatus:s}=le();return t.jsx(o.Grid.Item,{col:4,s:12,xs:12,children:t.jsx(N.Field,{name:"preferCustomContentTypes",label:e(l("pages.settings.form.preferCustomContentTypes.label")),hint:e(l("pages.settings.form.preferCustomContentTypes.hint")),children:t.jsx(o.Toggle,{name:"preferCustomContentTypes",checked:n.preferCustomContentTypes,onChange:r=>i(r,!n.preferCustomContentTypes,a),onLabel:e(l("components.toggle.enabled")),offLabel:e(l("components.toggle.disabled")),disabled:s.required,width:"100%"})})})},Ao=()=>{const e=_e(),n=we(),{formatMessage:a}=E.useIntl(),{values:i,onChange:s,handleChange:r,restartStatus:c,setFormValueItem:u,renderError:g}=le(),{contentTypes:m,preferCustomContentTypes:p}=i,C=S.sortBy(Object.values(n.data??[]).filter(({uid:b})=>bo(b,{allowedContentTypes:e.data?.allowedContentTypes,restrictedContentTypes:e.data?.restrictedContentTypes,preferCustomContentTypes:p,contentTypes:m})).map(b=>{const v=n.data?.find(x=>x.uid===b.uid);if(v){const{isDisplayed:x,kind:y}=v;return{...b,available:x,isSingle:y==="singleType"}}return b}),b=>b.info.displayName);return t.jsx(o.Grid.Item,{col:4,s:12,xs:12,children:t.jsx(N.Field,{name:"contentTypes",label:a(l("pages.settings.form.contentTypes.label")),hint:a(l("pages.settings.form.contentTypes.hint")),children:t.jsx(o.MultiSelect,{name:"contentTypes",label:a(l("pages.settings.form.contentTypes.label")),"aria-label":a(l("pages.settings.form.contentTypes.label")),placeholder:a(l("pages.settings.form.contentTypes.placeholder")),value:i.contentTypes,onChange:b=>{r("contentTypes",b,s);const{contentTypesNameFields:v=[],contentTypesPopulate:x=[],pathDefaultFields:y=[]}=i,I=b.filter(T=>!v.find(L=>L.key===T))??[],f=v.filter(T=>!b.includes(T.key)||T.key==="default").map(({key:T})=>T)??[];u("contentTypesNameFields",[...v.filter(({key:T})=>!f.includes(T)||T==="default")??[],...I.map(T=>({key:T,fields:[]}))]),u("contentTypesPopulate",[...x.filter(({key:T})=>!f.includes(T)||T==="default")??[],...I.map(T=>({key:T,fields:[]}))]),u("pathDefaultFields",[...y.filter(({key:T})=>!f.includes(T)||T==="default")??[],...I.map(T=>({key:T,fields:[]}))])},disabled:c.required,error:g("contentTypes"),withTags:!0,width:"100%",children:C.map(b=>t.jsx(o.MultiSelectOption,{value:b.uid,children:b.info.displayName},b.uid))})})})},Ro=()=>{const e=we(),{formatMessage:n}=E.useIntl(),{values:a,onChange:i,handleChange:s,restartStatus:r,renderError:c}=le(),u=j.useMemo(()=>a.contentTypes?.map(g=>e.data?.find(({uid:m})=>m===g)).filter(g=>g!==void 0)||[],[a.contentTypes,e.data]);return j.useEffect(()=>{a.defaultContentType&&(a.contentTypes.includes(a.defaultContentType)||s("defaultContentType",void 0,i))},[a.contentTypes]),t.jsx(o.Grid.Item,{col:4,s:12,xs:12,children:t.jsx(N.Field,{name:"defaultContentType",label:n(l("pages.settings.form.defaultContentType.label")),hint:n(l("pages.settings.form.defaultContentType.hint")),children:t.jsx(o.SingleSelect,{name:"defaultContentType",label:n(l("pages.settings.form.defaultContentType.label")),"aria-label":n(l("pages.settings.form.defaultContentType.label")),placeholder:n(l("pages.settings.form.defaultContentType.placeholder")),value:a.defaultContentType,onChange:g=>s("defaultContentType",g,i),onClear:()=>s("defaultContentType",void 0,i),disabled:r.required,error:c("defaultContentType"),withTags:!0,width:"100%",children:u.map(g=>t.jsx(o.SingleSelectOption,{value:g.uid,children:g.info.displayName},g.uid))})})})},Lo=["relation","media","component","dynamiczone"],$o=()=>{const e=we(),{formatMessage:n}=E.useIntl(),{values:a,onChange:i,handleChange:s,restartStatus:r,renderError:c}=le(),{contentTypes:u,contentTypesNameFields:g}=a;return t.jsx(o.Grid.Item,{col:12,s:12,xs:12,children:u?.length?t.jsx(o.Accordion.Root,{style:{width:"100%"},children:g.map((m,p)=>{const C=e.data?.find(({uid:y})=>y===m.key),b=C?.attributes??{},v=Object.keys(b).sort(),x=v.filter(y=>Lo.includes(b[y]?.type));return C?t.jsxs(o.Accordion.Item,{value:m.key,children:[t.jsx(o.Accordion.Header,{children:t.jsx(o.Accordion.Trigger,{children:C?.info.displayName??n(l("pages.settings.form.nameField.default"))})}),t.jsx(o.Accordion.Content,{children:t.jsxs(o.Grid.Root,{gap:4,padding:2,children:[t.jsx(o.Grid.Item,{col:12,s:12,xs:12,children:t.jsx(N.Field,{name:`contentTypesNameFields[${p}]`,label:n(l("pages.settings.form.nameField.label")),hint:n(l(`pages.settings.form.nameField.${S.isEmpty(S.get(a,`contentTypesNameFields[${p}].fields`,[]))?"empty":"hint"}`)),children:t.jsx(o.MultiSelect,{name:`contentTypesNameFields[${p}]`,placeholder:n(l("pages.settings.form.nameField.placeholder")),value:S.get(a,`contentTypesNameFields[${p}].fields`),onChange:y=>{const I=S.get(a,"contentTypesNameFields",[]).map((f,T)=>T===p?{...f,fields:y}:f);return s("contentTypesNameFields",I,i)},disabled:r.required,error:c(`contentTypesNameFields[${p}]`),withTags:!0,children:v.map(y=>t.jsx(o.MultiSelectOption,{value:y,children:y},y))})})}),t.jsx(o.Grid.Item,{col:12,s:12,xs:12,children:t.jsx(N.Field,{name:`contentTypesPopulate[${p-1}]`,label:n(l("pages.settings.form.populate.label")),hint:n(l(`pages.settings.form.populate.${S.isEmpty(S.get(a,`contentTypesPopulate[${p-1}]fields`,[]))?"empty":"hint"}`)),children:t.jsx(o.MultiSelect,{width:"100%",name:`contentTypesPopulate[${p-1}]`,placeholder:n(l("pages.settings.form.populate.placeholder")),value:S.get(a,`contentTypesPopulate[${p-1}].fields`,[]),onChange:y=>{const I=S.get(a,"contentTypesPopulate",[]).map((f,T)=>T===p-1?{...f,fields:y}:f);return s("contentTypesPopulate",I,i)},disabled:r.required,error:c(`contentTypesPopulate[${p-1}]`),withTags:!0,children:x.map(y=>t.jsx(o.MultiSelectOption,{value:y,children:y},y))})})}),t.jsx(o.Grid.Item,{col:12,s:12,xs:12,children:t.jsx(N.Field,{name:`pathDefaultFields[${p-1}]`,label:n(l("pages.settings.form.pathDefaultFields.label")),hint:n(l(`pages.settings.form.pathDefaultFields.${S.isEmpty(S.get(a,`pathDefaultFields[${p-1}].fields`,[]))?"empty":"hint"}`)),children:t.jsx(o.MultiSelect,{name:`pathDefaultFields[${p-1}]`,width:"100%",placeholder:n(l("pages.settings.form.pathDefaultFields.placeholder")),value:S.get(a,`pathDefaultFields[${p-1}].fields`,[]),onChange:y=>{const I=S.get(a,"pathDefaultFields",[]).map((f,T)=>T===p-1?{...f,fields:y}:f);return s("pathDefaultFields",I,i)},disabled:r.required,error:c(`pathDefaultFields[${p-1}]`),withTags:!0,children:v.map(y=>t.jsx(o.MultiSelectOption,{value:y,children:y},y))})})})]})})]},m.key):null})}):null})},Mo=()=>{const{formatMessage:e}=E.useIntl();return t.jsx(o.Box,{...Ie,width:"100%",children:t.jsxs(o.Flex,{direction:"column",alignItems:"flex-start",gap:2,children:[t.jsx(o.Typography,{variant:"delta",as:"h2",children:e(l("pages.settings.general.title"))}),t.jsx(o.Grid.Root,{gap:4,width:"100%",children:t.jsx(o.Grid.Item,{col:12,s:12,xs:12,children:t.jsxs(o.Grid.Root,{gap:4,width:"100%",children:[t.jsx(No,{}),t.jsx(Ao,{}),t.jsx(Ro,{}),t.jsx($o,{})]})})})]})})},it=t.jsx(R.PriceTag,{}),Po=t.jsx(R.Plus,{}),H="pages.settings.form.customFields.table.",ko=({data:e=[],onOpenModal:n,onRemoveCustomField:a,onToggleCustomField:i})=>{const[s,r]=j.useState(!1),[c,u]=j.useState(null),{toggleNotification:g}=F.useNotification(),m=j.useMemo(()=>S.sortBy(e,"name"),[e]),{formatMessage:p}=E.useIntl(),C=j.useCallback(x=>{u(x),r(!0)},[u,r]),b=j.useCallback(()=>{u(null),r(!1)},[u,r]),v=j.useCallback(()=>{c===null?g({type:"warning",message:p(l(`${H}confirmation.error`))}):a(c),b()},[b,c,qe,a,g]);return t.jsxs(t.Fragment,{children:[t.jsx(Se,{isVisible:s,header:p(l(`${H}confirmation.header`)),children:p(l(`${H}confirmation.message`)),labelConfirm:p(l(`${H}confirmation.confirm`)),iconConfirm:it,mainIcon:it,onConfirm:v,onCancel:b}),t.jsxs(o.Table,{width:"100%",colCount:4,rowCount:e.length+1,footer:t.jsx(o.TFooter,{onClick:x=>{x.preventDefault(),n(null)},icon:Po,children:p(l(`${H}footer`))}),children:[t.jsx(o.Thead,{children:t.jsxs(o.Tr,{children:[t.jsx(o.Th,{width:"20%",children:t.jsx(o.Typography,{variant:"sigma",textColor:"neutral600",children:p(l(`${H}header.name`))})}),t.jsx(o.Th,{width:"60%",children:t.jsx(o.Typography,{variant:"sigma",textColor:"neutral600",children:p(l(`${H}header.label`))})}),t.jsx(o.Th,{width:"15%",children:t.jsx(o.Typography,{variant:"sigma",textColor:"neutral600",children:p(l(`${H}header.type`))})}),t.jsx(o.Th,{width:"5%",children:t.jsx(o.Typography,{variant:"sigma",textColor:"neutral600",children:p(l(`${H}header.required`))})}),t.jsx(o.Th,{children:t.jsx(o.VisuallyHidden,{})})]})}),t.jsx(o.Tbody,{children:m.map(x=>typeof x!="string"?t.jsxs(o.Tr,{children:[t.jsx(o.Td,{width:"20%",children:t.jsx(o.Typography,{fontWeight:"semiBold",textColor:"neutral800",children:x.name})}),t.jsx(o.Td,{width:"60%",children:t.jsx(o.Typography,{textColor:"neutral800",children:x.label})}),t.jsx(o.Td,{width:"15%",children:t.jsx(o.Typography,{textColor:"neutral800",children:x.type})}),t.jsx(o.Td,{width:"5%",children:t.jsx(o.Tooltip,{description:p(l(`${H}${x.required?"required":"notRequired"}`)),children:t.jsx(o.Typography,{textColor:"neutral800",children:x.required?t.jsx(R.Check,{}):t.jsx(R.Minus,{})})})}),t.jsx(o.Td,{children:t.jsx(o.Flex,{width:"100%",justifyContent:"flex-end",alignItems:"center",children:t.jsxs(o.IconButtonGroup,{children:[t.jsx(o.IconButton,{onClick:()=>i(x),label:p(l(`${H}${x.enabled?"disable":"enable"}`)),variant:x.enabled?"success-light":"tertiary",children:x.enabled?t.jsx(R.Eye,{}):t.jsx(R.EyeStriked,{}),style:{minWidth:50}}),t.jsx(o.IconButton,{onClick:()=>n(x),label:p(l(`${H}edit`)),children:t.jsx(R.Pencil,{}),style:{minWidth:50}}),t.jsx(o.IconButton,{onClick:()=>C(x),label:p(l(`${H}remove`)),children:t.jsx(R.Trash,{}),style:{minWidth:50}})]})})})]},x.name):null)})]})]})},zo=({onChange:e,initialValue:n,...a})=>{const[i,s]=j.useState(S.isArray(n)?n.reduce((c,u)=>`${c}${u}; `,""):""),r=c=>{const u=c?.target.value??"",g=u.split(";").map(m=>m.trim()).filter(m=>!!m.length);s(u??""),e(g)};return t.jsx(o.TextInput,{...a,onChange:r,value:i})},q="pages.settings.form.customFields.popup.",qo=e=>e.map((n,a)=>({key:`${n}-${a}`,metadatas:{intlLabel:{id:n,defaultMessage:n},hidden:!1,disabled:!1},value:n,label:n})),Bo=({isEditForm:e,customField:n,onSubmit:a,onClose:i})=>{const s=qo(To),{formatMessage:r}=E.useIntl(),[c,u]=j.useState({name:"",label:"",type:"string",required:!1,multi:!1,enabled:!0}),[g,m]=j.useState(),{type:p}=c;j.useEffect(()=>{n&&u({...n})},[n]);const C=(y,I,f)=>{if(f){let T=y,L=I;if(S.isObject(y)){const{name:B,value:P}=y.target;T=B,L=S.isNil(L)?P:L}return S.isString(T)&&b(T,L),f(y,L)}},b=(y,I)=>{u(S.set({...c},y,I))},v=y=>{const I=S.get(g,y);if(I)return r(l(`${q}${y}.${I}`))},x=(y,I)=>{const{success:f,data:T,error:L}=ct.safeParse(I);f?a(T):L&&m(L.issues.reduce((B,P)=>({...B,[P.path.join(".")]:P.message}),{}))};return t.jsxs(t.Fragment,{children:[t.jsx(o.Modal.Body,{children:t.jsx(F.Form,{method:"POST",width:"auto",height:"auto",initialValues:c,children:({values:y,onChange:I})=>t.jsxs(o.Grid.Root,{gap:5,children:[t.jsx(o.Grid.Item,{col:12,children:t.jsx(N.Field,{name:"name",label:r(l(`${q}name.label`)),hint:r(l(`${q}name.description`)),error:v("name"),required:!0,children:t.jsx(o.TextInput,{name:"name",value:y.name,onChange:(f,T)=>C(f,T,I),placeholder:r(l(`${q}name.placeholder`)),type:"string",disabled:e,width:"100%"})})},"name"),t.jsx(o.Grid.Item,{col:12,children:t.jsx(N.Field,{name:"label",label:r(l(`${q}label.label`)),hint:r(l(`${q}label.description`)),error:v("label"),required:!0,children:t.jsx(o.TextInput,{name:"label",value:y.label,onChange:(f,T)=>C(f,T,I),placeholder:r(l(`${q}label.placeholder`)),type:"string",width:"100%"})})},"label"),t.jsx(o.Grid.Item,{col:12,children:t.jsx(N.Field,{name:"description",label:r(l(`${q}description.label`)),hint:r(l(`${q}description.description`)),error:v("description"),children:t.jsx(o.TextInput,{name:"description",value:y.description,onChange:(f,T)=>C(f,T,I),placeholder:r(l(`${q}description.placeholder`)),type:"string",width:"100%"})})},"description"),t.jsx(o.Grid.Item,{col:12,children:t.jsx(N.Field,{name:"placeholder",label:r(l(`${q}placeholder.label`)),hint:r(l(`${q}placeholder.description`)),error:v("placeholder"),children:t.jsx(o.TextInput,{name:"placeholder",value:y.placeholder,onChange:(f,T)=>C(f,T,I),placeholder:r(l(`${q}placeholder.placeholder`)),type:"string",width:"100%"})})},"placeholder"),t.jsx(o.Grid.Item,{col:12,children:t.jsx(N.Field,{name:"type",label:r(l(`${q}type.label`)),hint:r(l(`${q}type.description`)),required:!0,children:t.jsx(o.SingleSelect,{name:"type",value:y.type,onChange:f=>C("type",f,I),disabled:e,width:"100%",children:s.map(({key:f,label:T,value:L})=>t.jsx(o.SingleSelectOption,{value:L,children:T},f))})})},"type"),p==="select"&&t.jsxs(t.Fragment,{children:[t.jsx(o.Grid.Item,{col:12,children:t.jsx(N.Field,{name:"multi",label:r(l(`${q}multi.label`)),hint:r(l(`${q}multi.description`)),error:v("multi"),children:t.jsx(o.Toggle,{name:"multi",checked:y.multi,onChange:f=>C(f,!y.multi,I),onLabel:"true",offLabel:"false",width:"100%"})})},"multi"),t.jsx(o.Grid.Item,{col:12,children:t.jsx(N.Field,{name:"options",label:r(l(`${q}options.label`)),hint:r(l(`${q}options.description`)),error:v("options"),children:t.jsx(zo,{name:"options",onChange:f=>C("options",f,I),initialValue:y.options})})},"options")]}),t.jsx(o.Grid.Item,{col:12,children:t.jsx(N.Field,{name:"required",label:r(l(`${q}required.label`)),hint:r(l(`${q}required.description`)),error:v("required"),children:t.jsx(o.Toggle,{name:"required",placeholder:r(l(`${q}required.placeholder`)),checked:y.required,onChange:f=>C(f,!y.required,I),onLabel:"true",offLabel:"false",width:"100%"})})},"required")]})})}),t.jsxs(o.Modal.Footer,{children:[t.jsx(o.Modal.Close,{children:t.jsx(o.Button,{onClick:i,variant:"tertiary",children:r(l("popup.item.form.button.cancel"))})}),t.jsx(o.Button,{onClick:y=>x(y,c),children:r(l("popup.item.form.button.save"))})]})]})},Do=({isOpen:e,onClose:n,onSubmit:a,data:i})=>{const s=!!i,{formatMessage:r}=E.useIntl();return t.jsx(o.Modal.Root,{onOpenChange:c=>{c||n()},open:e,labelledBy:"custom-field-modal",children:t.jsxs(o.Modal.Content,{children:[t.jsx(o.Modal.Header,{children:t.jsx(o.Typography,{variant:"omega",fontWeight:"bold",textColor:"neutral800",as:"h2",id:"asset-dialog-title",children:r(l(`pages.settings.form.customFields.popup.header.${s?"edit":"new"}`))})}),t.jsx(Bo,{isEditForm:s,customField:i,onSubmit:a,onClose:n})]})})},Oo=()=>{const{formatMessage:e}=E.useIntl(),{values:{additionalFields:n},setFormValueItem:a}=le(),[i,s]=j.useState(!1),[r,c]=j.useState(null),u=C=>{c(C),s(!0)},g=C=>{const b=n.filter(v=>typeof v!="string"?v.name!==C.name:!0);a("additionalFields",b),c(null),s(!1)},m=C=>{const b={...C,enabled:!C.enabled},v=n.map(x=>typeof x!="string"&&C.name===x.name?b:x);a("additionalFields",v)},p=C=>{const v=!!n.find(x=>typeof x!="string"?x.name===C.name:!1)?n.map(x=>typeof x!="string"&&C.name===x.name?C:x):[...n,C];a("additionalFields",v),c(null),s(!1)};return t.jsxs(o.Box,{...Ie,width:"100%",children:[t.jsx(o.Typography,{variant:"delta",as:"h2",children:e(l("pages.settings.customFields.title"))}),t.jsx(o.Box,{padding:1}),t.jsx(ko,{data:n,onOpenModal:u,onRemoveCustomField:g,onToggleCustomField:m}),i&&t.jsx(Do,{onClose:()=>s(!1),onSubmit:p,isOpen:i,data:r})]})},Go=Kt.omit({contentTypesNameFields:!0}).extend({audienceFieldChecked:h.z.boolean(),contentTypesNameFields:h.z.object({key:h.z.string(),fields:h.z.string().array()}).array(),contentTypesPopulate:h.z.object({key:h.z.string(),fields:h.z.string().array()}).array(),pathDefaultFields:h.z.object({key:h.z.string(),fields:h.z.string().array()}).array()}),st=new $.QueryClient,Vo=()=>{const e=_e(),n=we(),a=Co(),i=Ft(),s=St(),{formatMessage:r}=E.useIntl(),[c,u]=j.useState({required:!1}),[g,m]=j.useState(!1),p=F.useAuth("SettingsPage",w=>w.permissions),C=j.useMemo(()=>!!p.find(({action:w})=>w===ue.settings[0].action),[p]),b=j.useMemo(()=>!!p.find(({action:w})=>w===ue.access[0].action),[p]),v=e.isPending||n.isPending||a.isPending||s.isPending||i.isPending,[x,y]=j.useState({}),[I,f]=j.useState(),T=(w,M,D)=>{if(D){let Z=w,O=M;if(S.isObject(w)){const{name:J,value:ae}=w.target;Z=J,O=S.isNil(O)?ae:O}return S.isString(Z)&&L(Z,O),D(w,O)}},L=(w,M)=>{y(D=>S.set({...D},w,M))},B=w=>{if(S.get(I,w))return r(l(w))},P=(w,M)=>{const{success:D,data:Z,error:O}=Go.safeParse(M);D?a.mutate(Z,{onSuccess(){u({required:!0}),a.reset()}}):O&&(f(O.issues.reduce((J,ae)=>({...J,[ae.path.join(".")]:ae.message}),{})),console.warn("Invalid form data",O))};return vo({config:e.data,setFormValue:y}),C?v||g?t.jsx(F.Page.Loading,{}):t.jsx(F.Layouts.Root,{children:t.jsxs(F.Page.Main,{children:[t.jsx(F.Page.Title,{children:r(l("pages.settings.header.title"))}),t.jsx(F.Layouts.Header,{title:r(l("pages.settings.header.title")),subtitle:r(l("pages.settings.header.description")),primaryAction:b?t.jsx(o.Button,{startIcon:t.jsx(R.Check,{}),disabled:c.required,onClick:w=>P(w,x),children:r(l("pages.settings.actions.submit"))}):null}),t.jsx(F.Layouts.Content,{children:t.jsx(F.Form,{method:"POST",width:"auto",height:"auto",initialValues:x,children:({values:w,onChange:M})=>t.jsx(wt.Provider,{value:{values:w,onChange:M,handleChange:T,restartStatus:c,setRestartStatus:u,renderError:B,setFormValueItem:L},children:t.jsxs(o.Flex,{direction:"column",gap:4,children:[t.jsx(wo,{setIsReloading:m}),t.jsx(Mo,{}),t.jsx(Eo,{}),t.jsx(Oo,{}),t.jsx(So,{hasSettingsReadPermissions:b})]})})})})]})}):t.jsx(F.Page.NoPermissions,{})};function Qo(){st.invalidateQueries();const e=N.usePluginTheme();return t.jsx($.QueryClientProvider,{client:st,children:t.jsx(o.DesignSystemProvider,{theme:e,children:t.jsx(Vo,{})})})}const _o="navigation",rt="Navigation",Uo={register(e){e.createSettingSection({id:ee,intlLabel:{id:`${ee}.plugin.section.name`,defaultMessage:`${rt} plugin`}},[{intlLabel:{id:`${ee}.plugin.section.item`,defaultMessage:"Configuration"},id:"navigation",to:ee,Component(){return Qo},permissions:ue.settings}]),e.addMenuLink({to:`plugins/${ee}`,icon:Gt,intlLabel:{id:`${ee}.plugin.name`,defaultMessage:rt},Component(){return yo},permissions:ue.access,position:1}),e.registerPlugin({id:ee,initializer:qt,isReady:!1,name:_o})},registerTrads:async function({locales:e=[]}){return Promise.all(e.map(async n=>n in We?We[n]().then(({default:i})=>({data:N.prefixPluginTranslations(N.flattenObject(i),ee),locale:n})):{data:N.prefixPluginTranslations(N.flattenObject({}),ee),locale:n}))}};module.exports=Uo;
|
|
184
|
+
`,wo=({setIsReloading:e})=>{const{formatMessage:n}=E.useIntl(),a=St(),{restartStatus:i,setRestartStatus:s}=le(),r=async()=>{a.mutate(void 0,{onSuccess(){e(!0),Tt(!0).then(u=>{u&&window.location.reload()})},onError(){s({required:!1})}})},c=()=>s({required:!1});return i.required?t.jsx(o.Box,{...Ie,width:"100%",children:t.jsx(Fo,{closeLabel:n(l("pages.settings.actions.restart.alert.cancel")),title:n(l("pages.settings.actions.restart.alert.title")),action:t.jsx(o.Box,{children:t.jsx(o.Button,{onClick:r,startIcon:t.jsx(R.Play,{}),children:n(l("pages.settings.actions.restart.label"))})}),onClose:c,children:t.jsxs(t.Fragment,{children:[t.jsx(o.Box,{paddingBottom:1,children:n(l("pages.settings.actions.restart.alert.description"))}),i.reasons?.map((u,g)=>t.jsx(o.Box,{paddingBottom:1,children:n(l(`pages.settings.actions.restart.alert.reason.${u}`))},g))]})})}):null},Eo=()=>{const e=_e(),{formatMessage:n}=E.useIntl(),{values:a,onChange:i,handleChange:s,restartStatus:r}=le();return t.jsx(o.Box,{...Ie,width:"100%",children:t.jsxs(o.Flex,{direction:"column",alignItems:"flex-start",gap:2,children:[t.jsx(o.Typography,{variant:"delta",as:"h2",children:n(l("pages.settings.additional.title"))}),t.jsxs(o.Grid.Root,{gap:4,width:"100%",children:[t.jsx(o.Grid.Item,{col:4,s:12,xs:12,children:t.jsx(o.Box,{width:"100%",children:t.jsx(N.Field,{name:"allowedLevels",label:n(l("pages.settings.form.allowedLevels.label")),hint:n(l("pages.settings.form.allowedLevels.hint")),children:t.jsx(o.NumberInput,{width:"100%",name:"allowedLevels",type:"number",placeholder:n(l("pages.settings.form.allowedLevels.placeholder")),onChange:(c,u)=>{if(S.isObject(c)){const g=parseInt(c.target.value);return s(c.target.name,isNaN(g)?0:g,i)}return s(c,u,i)},value:a.allowedLevels,disabled:r.required})})})}),t.jsx(o.Grid.Item,{col:4,s:12,xs:12,children:t.jsx(N.Field,{name:"cascadeMenuAttached",label:n(l("pages.settings.form.cascadeMenuAttached.label")),hint:n(l("pages.settings.form.cascadeMenuAttached.hint")),children:t.jsx(o.Toggle,{width:"100%",name:"cascadeMenuAttached",checked:a.cascadeMenuAttached,onChange:c=>s(c,!a.cascadeMenuAttached,i),onLabel:n(l("components.toggle.enabled")),offLabel:n(l("components.toggle.disabled")),disabled:r.required})})}),t.jsx(o.Grid.Item,{col:4,s:12,xs:12,children:t.jsx(N.Field,{name:"audienceFieldChecked",label:n(l("pages.settings.form.audience.label")),hint:n(l("pages.settings.form.audience.hint")),children:t.jsx(o.Toggle,{name:"audienceFieldChecked",checked:a.audienceFieldChecked,onChange:c=>s(c,!a.audienceFieldChecked,i),onLabel:n(l("components.toggle.enabled")),offLabel:n(l("components.toggle.disabled")),disabled:r.required,width:"100%"})})}),e.data?.isCachePluginEnabled&&t.jsx(o.Grid.Item,{col:12,s:12,xs:12,children:t.jsx(N.Field,{name:"isCacheEnabled",label:n(l("pages.settings.form.cache.label")),hint:n(l("pages.settings.form.cache.hint")),children:t.jsx(o.Toggle,{name:"isCacheEnabled",checked:a.isCacheEnabled,onChange:c=>s(c,!a.isCacheEnabled,i),onLabel:n(l("components.toggle.enabled")),offLabel:n(l("components.toggle.disabled")),disabled:r.required,width:"100%"})})})]})]})})},No=()=>{const{formatMessage:e}=E.useIntl(),{values:n,onChange:a,handleChange:i,restartStatus:s}=le();return t.jsx(o.Grid.Item,{col:4,s:12,xs:12,children:t.jsx(N.Field,{name:"preferCustomContentTypes",label:e(l("pages.settings.form.preferCustomContentTypes.label")),hint:e(l("pages.settings.form.preferCustomContentTypes.hint")),children:t.jsx(o.Toggle,{name:"preferCustomContentTypes",checked:n.preferCustomContentTypes,onChange:r=>i(r,!n.preferCustomContentTypes,a),onLabel:e(l("components.toggle.enabled")),offLabel:e(l("components.toggle.disabled")),disabled:s.required,width:"100%"})})})},Ao=()=>{const e=_e(),n=we(),{formatMessage:a}=E.useIntl(),{values:i,onChange:s,handleChange:r,restartStatus:c,setFormValueItem:u,renderError:g}=le(),{contentTypes:m,preferCustomContentTypes:p}=i,C=S.sortBy(Object.values(n.data??[]).filter(({uid:b})=>bo(b,{allowedContentTypes:e.data?.allowedContentTypes,restrictedContentTypes:e.data?.restrictedContentTypes,preferCustomContentTypes:p,contentTypes:m})).map(b=>{const v=n.data?.find(x=>x.uid===b.uid);if(v){const{isDisplayed:x,kind:y}=v;return{...b,available:x,isSingle:y==="singleType"}}return b}),b=>b.info.displayName);return t.jsx(o.Grid.Item,{col:4,s:12,xs:12,children:t.jsx(N.Field,{name:"contentTypes",label:a(l("pages.settings.form.contentTypes.label")),hint:a(l("pages.settings.form.contentTypes.hint")),children:t.jsx(o.MultiSelect,{name:"contentTypes",label:a(l("pages.settings.form.contentTypes.label")),"aria-label":a(l("pages.settings.form.contentTypes.label")),placeholder:a(l("pages.settings.form.contentTypes.placeholder")),value:i.contentTypes,onChange:b=>{r("contentTypes",b,s);const{contentTypesNameFields:v=[],contentTypesPopulate:x=[],pathDefaultFields:y=[]}=i,I=b.filter(T=>!v.find(L=>L.key===T))??[],f=v.filter(T=>!b.includes(T.key)||T.key==="default").map(({key:T})=>T)??[];u("contentTypesNameFields",[...v.filter(({key:T})=>!f.includes(T)||T==="default")??[],...I.map(T=>({key:T,fields:[]}))]),u("contentTypesPopulate",[...x.filter(({key:T})=>!f.includes(T)||T==="default")??[],...I.map(T=>({key:T,fields:[]}))]),u("pathDefaultFields",[...y.filter(({key:T})=>!f.includes(T)||T==="default")??[],...I.map(T=>({key:T,fields:[]}))])},disabled:c.required,error:g("contentTypes"),withTags:!0,width:"100%",children:C.map(b=>t.jsx(o.MultiSelectOption,{value:b.uid,children:b.info.displayName},b.uid))})})})},Ro=()=>{const e=we(),{formatMessage:n}=E.useIntl(),{values:a,onChange:i,handleChange:s,restartStatus:r,renderError:c}=le(),u=j.useMemo(()=>a.contentTypes?.map(g=>e.data?.find(({uid:m})=>m===g)).filter(g=>g!==void 0)||[],[a.contentTypes,e.data]);return j.useEffect(()=>{a.defaultContentType&&(a.contentTypes.includes(a.defaultContentType)||s("defaultContentType",void 0,i))},[a.contentTypes]),t.jsx(o.Grid.Item,{col:4,s:12,xs:12,children:t.jsx(N.Field,{name:"defaultContentType",label:n(l("pages.settings.form.defaultContentType.label")),hint:n(l("pages.settings.form.defaultContentType.hint")),children:t.jsx(o.SingleSelect,{name:"defaultContentType",label:n(l("pages.settings.form.defaultContentType.label")),"aria-label":n(l("pages.settings.form.defaultContentType.label")),placeholder:n(l("pages.settings.form.defaultContentType.placeholder")),value:a.defaultContentType,onChange:g=>s("defaultContentType",g,i),onClear:()=>s("defaultContentType",void 0,i),disabled:r.required,error:c("defaultContentType"),withTags:!0,width:"100%",children:u.map(g=>t.jsx(o.SingleSelectOption,{value:g.uid,children:g.info.displayName},g.uid))})})})},Lo=["relation","media","component","dynamiczone"],$o=()=>{const e=we(),{formatMessage:n}=E.useIntl(),{values:a,onChange:i,handleChange:s,restartStatus:r,renderError:c}=le(),{contentTypes:u,contentTypesNameFields:g}=a;return t.jsx(o.Grid.Item,{col:12,s:12,xs:12,children:u?.length?t.jsx(o.Accordion.Root,{style:{width:"100%"},children:g.map((m,p)=>{const C=e.data?.find(({uid:y})=>y===m.key),b=C?.attributes??{},v=Object.keys(b).sort(),x=v.filter(y=>Lo.includes(b[y]?.type));return C?t.jsxs(o.Accordion.Item,{value:m.key,children:[t.jsx(o.Accordion.Header,{children:t.jsx(o.Accordion.Trigger,{children:C?.info.displayName??n(l("pages.settings.form.nameField.default"))})}),t.jsx(o.Accordion.Content,{children:t.jsxs(o.Grid.Root,{gap:4,padding:2,children:[t.jsx(o.Grid.Item,{col:12,s:12,xs:12,children:t.jsx(N.Field,{name:`contentTypesNameFields[${p}]`,label:n(l("pages.settings.form.nameField.label")),hint:n(l(`pages.settings.form.nameField.${S.isEmpty(S.get(a,`contentTypesNameFields[${p}].fields`,[]))?"empty":"hint"}`)),children:t.jsx(o.MultiSelect,{name:`contentTypesNameFields[${p}]`,placeholder:n(l("pages.settings.form.nameField.placeholder")),value:S.get(a,`contentTypesNameFields[${p}].fields`),onChange:y=>{const I=S.get(a,"contentTypesNameFields",[]).map((f,T)=>T===p?{...f,fields:y}:f);return s("contentTypesNameFields",I,i)},disabled:r.required,error:c(`contentTypesNameFields[${p}]`),withTags:!0,children:v.map(y=>t.jsx(o.MultiSelectOption,{value:y,children:y},y))})})}),t.jsx(o.Grid.Item,{col:12,s:12,xs:12,children:t.jsx(N.Field,{name:`contentTypesPopulate[${p-1}]`,label:n(l("pages.settings.form.populate.label")),hint:n(l(`pages.settings.form.populate.${S.isEmpty(S.get(a,`contentTypesPopulate[${p-1}]fields`,[]))?"empty":"hint"}`)),children:t.jsx(o.MultiSelect,{width:"100%",name:`contentTypesPopulate[${p-1}]`,placeholder:n(l("pages.settings.form.populate.placeholder")),value:S.get(a,`contentTypesPopulate[${p-1}].fields`,[]),onChange:y=>{const I=S.get(a,"contentTypesPopulate",[]).map((f,T)=>T===p-1?{...f,fields:y}:f);return s("contentTypesPopulate",I,i)},disabled:r.required,error:c(`contentTypesPopulate[${p-1}]`),withTags:!0,children:x.map(y=>t.jsx(o.MultiSelectOption,{value:y,children:y},y))})})}),t.jsx(o.Grid.Item,{col:12,s:12,xs:12,children:t.jsx(N.Field,{name:`pathDefaultFields[${p-1}]`,label:n(l("pages.settings.form.pathDefaultFields.label")),hint:n(l(`pages.settings.form.pathDefaultFields.${S.isEmpty(S.get(a,`pathDefaultFields[${p-1}].fields`,[]))?"empty":"hint"}`)),children:t.jsx(o.MultiSelect,{name:`pathDefaultFields[${p-1}]`,width:"100%",placeholder:n(l("pages.settings.form.pathDefaultFields.placeholder")),value:S.get(a,`pathDefaultFields[${p-1}].fields`,[]),onChange:y=>{const I=S.get(a,"pathDefaultFields",[]).map((f,T)=>T===p-1?{...f,fields:y}:f);return s("pathDefaultFields",I,i)},disabled:r.required,error:c(`pathDefaultFields[${p-1}]`),withTags:!0,children:v.map(y=>t.jsx(o.MultiSelectOption,{value:y,children:y},y))})})})]})})]},m.key):null})}):null})},Mo=()=>{const{formatMessage:e}=E.useIntl();return t.jsx(o.Box,{...Ie,width:"100%",children:t.jsxs(o.Flex,{direction:"column",alignItems:"flex-start",gap:2,children:[t.jsx(o.Typography,{variant:"delta",as:"h2",children:e(l("pages.settings.general.title"))}),t.jsx(o.Grid.Root,{gap:4,width:"100%",children:t.jsx(o.Grid.Item,{col:12,s:12,xs:12,children:t.jsxs(o.Grid.Root,{gap:4,width:"100%",children:[t.jsx(No,{}),t.jsx(Ao,{}),t.jsx(Ro,{}),t.jsx($o,{})]})})})]})})},it=t.jsx(R.PriceTag,{}),Po=t.jsx(R.Plus,{}),H="pages.settings.form.customFields.table.",ko=({data:e=[],onOpenModal:n,onRemoveCustomField:a,onToggleCustomField:i})=>{const[s,r]=j.useState(!1),[c,u]=j.useState(null),{toggleNotification:g}=F.useNotification(),m=j.useMemo(()=>S.sortBy(e,"name"),[e]),{formatMessage:p}=E.useIntl(),C=j.useCallback(x=>{u(x),r(!0)},[u,r]),b=j.useCallback(()=>{u(null),r(!1)},[u,r]),v=j.useCallback(()=>{c===null?g({type:"warning",message:p(l(`${H}confirmation.error`))}):a(c),b()},[b,c,qe,a,g]);return t.jsxs(t.Fragment,{children:[t.jsx(Se,{isVisible:s,header:p(l(`${H}confirmation.header`)),children:p(l(`${H}confirmation.message`)),labelConfirm:p(l(`${H}confirmation.confirm`)),iconConfirm:it,mainIcon:it,onConfirm:v,onCancel:b}),t.jsxs(o.Table,{width:"100%",colCount:4,rowCount:e.length+1,footer:t.jsx(o.TFooter,{onClick:x=>{x.preventDefault(),n(null)},icon:Po,children:p(l(`${H}footer`))}),children:[t.jsx(o.Thead,{children:t.jsxs(o.Tr,{children:[t.jsx(o.Th,{width:"20%",children:t.jsx(o.Typography,{variant:"sigma",textColor:"neutral600",children:p(l(`${H}header.name`))})}),t.jsx(o.Th,{width:"60%",children:t.jsx(o.Typography,{variant:"sigma",textColor:"neutral600",children:p(l(`${H}header.label`))})}),t.jsx(o.Th,{width:"15%",children:t.jsx(o.Typography,{variant:"sigma",textColor:"neutral600",children:p(l(`${H}header.type`))})}),t.jsx(o.Th,{width:"5%",children:t.jsx(o.Typography,{variant:"sigma",textColor:"neutral600",children:p(l(`${H}header.required`))})}),t.jsx(o.Th,{children:t.jsx(o.VisuallyHidden,{})})]})}),t.jsx(o.Tbody,{children:m.map(x=>typeof x!="string"?t.jsxs(o.Tr,{children:[t.jsx(o.Td,{width:"20%",children:t.jsx(o.Typography,{fontWeight:"semiBold",textColor:"neutral800",children:x.name})}),t.jsx(o.Td,{width:"60%",children:t.jsx(o.Typography,{textColor:"neutral800",children:x.label})}),t.jsx(o.Td,{width:"15%",children:t.jsx(o.Typography,{textColor:"neutral800",children:x.type})}),t.jsx(o.Td,{width:"5%",children:t.jsx(o.Tooltip,{description:p(l(`${H}${x.required?"required":"notRequired"}`)),children:t.jsx(o.Typography,{textColor:"neutral800",children:x.required?t.jsx(R.Check,{}):t.jsx(R.Minus,{})})})}),t.jsx(o.Td,{children:t.jsx(o.Flex,{width:"100%",justifyContent:"flex-end",alignItems:"center",children:t.jsxs(o.IconButtonGroup,{children:[t.jsx(o.IconButton,{onClick:()=>i(x),label:p(l(`${H}${x.enabled?"disable":"enable"}`)),variant:x.enabled?"success-light":"tertiary",children:x.enabled?t.jsx(R.Eye,{}):t.jsx(R.EyeStriked,{}),style:{minWidth:50}}),t.jsx(o.IconButton,{onClick:()=>n(x),label:p(l(`${H}edit`)),children:t.jsx(R.Pencil,{}),style:{minWidth:50}}),t.jsx(o.IconButton,{onClick:()=>C(x),label:p(l(`${H}remove`)),children:t.jsx(R.Trash,{}),style:{minWidth:50}})]})})})]},x.name):null)})]})]})},zo=({onChange:e,initialValue:n,...a})=>{const[i,s]=j.useState(S.isArray(n)?n.join(";"):""),r=c=>{const u=c?.target.value??"",g=u.split(";").map(m=>m.trim()).filter(m=>!!m.length);s(u??""),e(g)};return t.jsx(o.TextInput,{...a,onChange:r,value:i})},q="pages.settings.form.customFields.popup.",qo=e=>e.map((n,a)=>({key:`${n}-${a}`,metadatas:{intlLabel:{id:n,defaultMessage:n},hidden:!1,disabled:!1},value:n,label:n})),Bo=({isEditForm:e,customField:n,onSubmit:a,onClose:i})=>{const s=qo(To),{formatMessage:r}=E.useIntl(),[c,u]=j.useState(n?{...n}:{name:"",label:"",type:"string",required:!1,multi:!1,enabled:!0}),[g,m]=j.useState(),{type:p}=c;j.useEffect(()=>{n&&u({...n})},[n]);const C=(y,I,f)=>{if(f){let T=y,L=I;if(S.isObject(y)){const{name:B,value:P}=y.target;T=B,L=S.isNil(L)?P:L}return S.isString(T)&&b(T,L),f(y,L)}},b=(y,I)=>{u(S.set({...c},y,I))},v=y=>{const I=S.get(g,y);if(I)return r(l(`${q}${y}.${I}`))},x=(y,I)=>{const{success:f,data:T,error:L}=ct.safeParse(I);f?a(T):L&&m(L.issues.reduce((B,P)=>({...B,[P.path.join(".")]:P.message}),{}))};return t.jsxs(t.Fragment,{children:[t.jsx(o.Modal.Body,{children:t.jsx(F.Form,{method:"POST",width:"auto",height:"auto",initialValues:c,children:({values:y,onChange:I})=>t.jsxs(o.Grid.Root,{gap:5,children:[t.jsx(o.Grid.Item,{col:12,children:t.jsx(N.Field,{name:"name",label:r(l(`${q}name.label`)),hint:r(l(`${q}name.description`)),error:v("name"),required:!0,children:t.jsx(o.TextInput,{name:"name",value:y.name,onChange:(f,T)=>C(f,T,I),placeholder:r(l(`${q}name.placeholder`)),type:"string",disabled:e,width:"100%"})})},"name"),t.jsx(o.Grid.Item,{col:12,children:t.jsx(N.Field,{name:"label",label:r(l(`${q}label.label`)),hint:r(l(`${q}label.description`)),error:v("label"),required:!0,children:t.jsx(o.TextInput,{name:"label",value:y.label,onChange:(f,T)=>C(f,T,I),placeholder:r(l(`${q}label.placeholder`)),type:"string",width:"100%"})})},"label"),t.jsx(o.Grid.Item,{col:12,children:t.jsx(N.Field,{name:"description",label:r(l(`${q}description.label`)),hint:r(l(`${q}description.description`)),error:v("description"),children:t.jsx(o.TextInput,{name:"description",value:y.description,onChange:(f,T)=>C(f,T,I),placeholder:r(l(`${q}description.placeholder`)),type:"string",width:"100%"})})},"description"),t.jsx(o.Grid.Item,{col:12,children:t.jsx(N.Field,{name:"placeholder",label:r(l(`${q}placeholder.label`)),hint:r(l(`${q}placeholder.description`)),error:v("placeholder"),children:t.jsx(o.TextInput,{name:"placeholder",value:y.placeholder,onChange:(f,T)=>C(f,T,I),placeholder:r(l(`${q}placeholder.placeholder`)),type:"string",width:"100%"})})},"placeholder"),t.jsx(o.Grid.Item,{col:12,children:t.jsx(N.Field,{name:"type",label:r(l(`${q}type.label`)),hint:r(l(`${q}type.description`)),required:!0,children:t.jsx(o.SingleSelect,{name:"type",value:y.type,onChange:f=>C("type",f,I),disabled:e,width:"100%",children:s.map(({key:f,label:T,value:L})=>t.jsx(o.SingleSelectOption,{value:L,children:T},f))})})},"type"),p==="select"&&t.jsxs(t.Fragment,{children:[t.jsx(o.Grid.Item,{col:12,children:t.jsx(N.Field,{name:"multi",label:r(l(`${q}multi.label`)),hint:r(l(`${q}multi.description`)),error:v("multi"),children:t.jsx(o.Toggle,{name:"multi",checked:y.multi,onChange:f=>C(f,!y.multi,I),onLabel:"true",offLabel:"false",width:"100%"})})},"multi"),t.jsx(o.Grid.Item,{col:12,children:t.jsx(N.Field,{name:"options",label:r(l(`${q}options.label`)),hint:r(l(`${q}options.description`)),error:v("options"),children:t.jsx(zo,{name:"options",onChange:f=>C("options",f,I),initialValue:y.options})})},"options")]}),t.jsx(o.Grid.Item,{col:12,children:t.jsx(N.Field,{name:"required",label:r(l(`${q}required.label`)),hint:r(l(`${q}required.description`)),error:v("required"),children:t.jsx(o.Toggle,{name:"required",placeholder:r(l(`${q}required.placeholder`)),checked:y.required,onChange:f=>C(f,!y.required,I),onLabel:"true",offLabel:"false",width:"100%"})})},"required")]})})}),t.jsxs(o.Modal.Footer,{children:[t.jsx(o.Modal.Close,{children:t.jsx(o.Button,{onClick:i,variant:"tertiary",children:r(l("popup.item.form.button.cancel"))})}),t.jsx(o.Button,{onClick:y=>x(y,c),children:r(l("popup.item.form.button.save"))})]})]})},Do=({isOpen:e,onClose:n,onSubmit:a,data:i})=>{const s=!!i,{formatMessage:r}=E.useIntl();return t.jsx(o.Modal.Root,{onOpenChange:c=>{c||n()},open:e,labelledBy:"custom-field-modal",children:t.jsxs(o.Modal.Content,{children:[t.jsx(o.Modal.Header,{children:t.jsx(o.Typography,{variant:"omega",fontWeight:"bold",textColor:"neutral800",as:"h2",id:"asset-dialog-title",children:r(l(`pages.settings.form.customFields.popup.header.${s?"edit":"new"}`))})}),t.jsx(Bo,{isEditForm:s,customField:i,onSubmit:a,onClose:n})]})})},Oo=()=>{const{formatMessage:e}=E.useIntl(),{values:{additionalFields:n},setFormValueItem:a}=le(),[i,s]=j.useState(!1),[r,c]=j.useState(null),u=C=>{c(C),s(!0)},g=C=>{const b=n.filter(v=>typeof v!="string"?v.name!==C.name:!0);a("additionalFields",b),c(null),s(!1)},m=C=>{const b={...C,enabled:!C.enabled},v=n.map(x=>typeof x!="string"&&C.name===x.name?b:x);a("additionalFields",v)},p=C=>{const v=!!n.find(x=>typeof x!="string"?x.name===C.name:!1)?n.map(x=>typeof x!="string"&&C.name===x.name?C:x):[...n,C];a("additionalFields",v),c(null),s(!1)};return t.jsxs(o.Box,{...Ie,width:"100%",children:[t.jsx(o.Typography,{variant:"delta",as:"h2",children:e(l("pages.settings.customFields.title"))}),t.jsx(o.Box,{padding:1}),t.jsx(ko,{data:n,onOpenModal:u,onRemoveCustomField:g,onToggleCustomField:m}),i&&t.jsx(Do,{onClose:()=>s(!1),onSubmit:p,isOpen:i,data:r})]})},Go=Kt.omit({contentTypesNameFields:!0}).extend({audienceFieldChecked:h.z.boolean(),contentTypesNameFields:h.z.object({key:h.z.string(),fields:h.z.string().array()}).array(),contentTypesPopulate:h.z.object({key:h.z.string(),fields:h.z.string().array()}).array(),pathDefaultFields:h.z.object({key:h.z.string(),fields:h.z.string().array()}).array()}),st=new $.QueryClient,Vo=()=>{const e=_e(),n=we(),a=Co(),i=Ft(),s=St(),{formatMessage:r}=E.useIntl(),[c,u]=j.useState({required:!1}),[g,m]=j.useState(!1),p=F.useAuth("SettingsPage",w=>w.permissions),C=j.useMemo(()=>!!p.find(({action:w})=>w===ue.settings[0].action),[p]),b=j.useMemo(()=>!!p.find(({action:w})=>w===ue.access[0].action),[p]),v=e.isPending||n.isPending||a.isPending||s.isPending||i.isPending,[x,y]=j.useState({}),[I,f]=j.useState(),T=(w,M,D)=>{if(D){let Z=w,O=M;if(S.isObject(w)){const{name:J,value:ae}=w.target;Z=J,O=S.isNil(O)?ae:O}return S.isString(Z)&&L(Z,O),D(w,O)}},L=(w,M)=>{y(D=>S.set({...D},w,M))},B=w=>{if(S.get(I,w))return r(l(w))},P=(w,M)=>{const{success:D,data:Z,error:O}=Go.safeParse(M);D?a.mutate(Z,{onSuccess(){u({required:!0}),a.reset()}}):O&&(f(O.issues.reduce((J,ae)=>({...J,[ae.path.join(".")]:ae.message}),{})),console.warn("Invalid form data",O))};return vo({config:e.data,setFormValue:y}),C?v||g?t.jsx(F.Page.Loading,{}):t.jsx(F.Layouts.Root,{children:t.jsxs(F.Page.Main,{children:[t.jsx(F.Page.Title,{children:r(l("pages.settings.header.title"))}),t.jsx(F.Layouts.Header,{title:r(l("pages.settings.header.title")),subtitle:r(l("pages.settings.header.description")),primaryAction:b?t.jsx(o.Button,{startIcon:t.jsx(R.Check,{}),disabled:c.required,onClick:w=>P(w,x),children:r(l("pages.settings.actions.submit"))}):null}),t.jsx(F.Layouts.Content,{children:t.jsx(F.Form,{method:"POST",width:"auto",height:"auto",initialValues:x,children:({values:w,onChange:M})=>t.jsx(wt.Provider,{value:{values:w,onChange:M,handleChange:T,restartStatus:c,setRestartStatus:u,renderError:B,setFormValueItem:L},children:t.jsxs(o.Flex,{direction:"column",gap:4,children:[t.jsx(wo,{setIsReloading:m}),t.jsx(Mo,{}),t.jsx(Eo,{}),t.jsx(Oo,{}),t.jsx(So,{hasSettingsReadPermissions:b})]})})})})]})}):t.jsx(F.Page.NoPermissions,{})};function Qo(){st.invalidateQueries();const e=N.usePluginTheme();return t.jsx($.QueryClientProvider,{client:st,children:t.jsx(o.DesignSystemProvider,{theme:e,children:t.jsx(Vo,{})})})}const _o="navigation",rt="Navigation",Uo={register(e){e.createSettingSection({id:ee,intlLabel:{id:`${ee}.plugin.section.name`,defaultMessage:`${rt} plugin`}},[{intlLabel:{id:`${ee}.plugin.section.item`,defaultMessage:"Configuration"},id:"navigation",to:ee,Component(){return Qo},permissions:ue.settings}]),e.addMenuLink({to:`plugins/${ee}`,icon:Gt,intlLabel:{id:`${ee}.plugin.name`,defaultMessage:rt},Component(){return yo},permissions:ue.access,position:1}),e.registerPlugin({id:ee,initializer:qt,isReady:!1,name:_o})},registerTrads:async function({locales:e=[]}){return Promise.all(e.map(async n=>n in We?We[n]().then(({default:i})=>({data:N.prefixPluginTranslations(N.flattenObject(i),ee),locale:n})):{data:N.prefixPluginTranslations(N.flattenObject({}),ee),locale:n}))}};module.exports=Uo;
|