diff --git a/CHANGELOG.md b/CHANGELOG.md index 4d92583f..41069929 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ - Added backups list scroll container ([#7655](https://github.com/pocketbase/pocketbase/issues/7655)). -- Optimized record upsert panel loading to minimize layout jumps. +- Optimized record upsert and preview modals loading to minimize layout jumps. ## v0.37.3 diff --git a/ui/dist/assets/index-CzeH6zOJ.js b/ui/dist/assets/index-C2jyM0t-.js similarity index 99% rename from ui/dist/assets/index-CzeH6zOJ.js rename to ui/dist/assets/index-C2jyM0t-.js index c80d694a..08a502e1 100644 --- a/ui/dist/assets/index-CzeH6zOJ.js +++ b/ui/dist/assets/index-C2jyM0t-.js @@ -25,7 +25,7 @@ import{a as e,n,r,t as i}from"./pocketbase.es-B_4DUNUU.js";var a=Object.create,o `;let _=g.querySelector(`.paths-group`);return a=t.div({tabIndex:-1,rid:n.rid,id:()=>n.id,hidden:()=>n.hidden,inert:()=>n.inert,className:()=>`erd ${n.className} ${i.isUpdating?`updating`:``} ${i.isPanning?`panning`:``} ${i.activeCollection?`active`:``}`,onkeydown:e=>{(e.ctrlKey||e.metaKey)&&e.key==`0`&&f()},onmount:async e=>{e.addEventListener(`wheel`,r=>{r.preventDefault();let a=e.getBoundingClientRect(),o=r.clientX-a.left,s=r.clientY-a.top,c=(o-i.viewX)/n.scale,l=(s-i.viewY)/n.scale,u=Math.min(Math.max(-r.deltaY*.001+n.scale,$e),Qe);i.viewX=o-c*u,i.viewY=s-l*u,n.scale=u}),e.addEventListener(`pointerdown`,e=>{e.buttons==1&&(i.isPanning=!0,i.panStartX=e.clientX-i.viewX,i.panStartY=e.clientY-i.viewY)}),e._ondragging=function(e){i.isPanning&&(i.viewX=e.clientX-i.panStartX,i.viewY=e.clientY-i.panStartY)},e._ondragstop=function(){i.isPanning=!1},window.addEventListener(`pointermove`,e._ondragging),window.addEventListener(`pointerup`,e._ondragstop),c()},onunmount:e=>{window.removeEventListener(`pointermove`,e._ondragging),window.removeEventListener(`pointerup`,e._ondragstop),r.forEach(e=>e?.unwatch())}},t.div({className:`erd-area`,style:()=>`transform: translate(${i.viewX}px, ${i.viewY}px) scale(${n.scale});`},m,t.div({className:`erd-tables`},()=>n.collections.map(e=>t.div({style:()=>`left:${i.positions[e.id]?.x||0}px;top:${i.positions[e.id]?.y||0}px`,className:()=>`erd-table type-${e.type} ${p(e)?`active`:``} ${e.system?`system`:``}`,"html-data-collection-id":()=>e.id,"html-data-collection-name":()=>e.name,onmouseenter:()=>{h.querySelectorAll(`[data-to="${e.id}"]`)?.forEach(e=>{e.classList.add(`active-to`),_.append(e)}),h.querySelectorAll(`[data-from="${e.id}"]`)?.forEach(e=>{e.classList.add(`active-from`),_.append(e)}),i.activeCollection=e},onmouseleave:()=>{for(let e of _.children)e.classList.remove(`active-from`,`active-to`);h.append(..._.children),i.activeCollection=null}},t.div({className:`erd-table-row header`},()=>e.name),()=>e.fields?.map(e=>t.div({className:`erd-table-row type-${e.type} ${e.primaryKey?`primary-key`:``}`,"html-data-field-id":()=>e.id,"html-data-field-name":()=>e.name},t.i({ariaHidden:!0,title:()=>e.type,className:()=>`field-icon ${app.fieldTypes[e.type].icon||app.utils.fallbackFieldIcon}`}),t.span({className:`field-name`},()=>e.name),()=>{if(e.hidden)return t.span({className:`label danger field-hidden-label`},`Hidden`)},()=>{if(e.maxSelect!==void 0)return t.span({className:`meta`},e.maxSelect>1?`multiple`:`single`)}))))),g),t.nav({className:`erd-nav`,onmousedown:e=>{e.stopImmediatePropagation()}},t.button({type:`button`,className:`btn sm circle secondary`,title:`Zoom in`,onclick:()=>{n.scale+=.05}},t.i({className:`ri-add-line`,ariaHidden:!0})),t.button({type:`button`,className:`btn sm circle secondary`,title:`Zoom out`,onclick:()=>{n.scale-=.05}},t.i({className:`ri-subtract-line`,ariaHidden:!0})))),a};function tt(e,n,r=1,i=``,a=``,o=2){if(!e||!n)return;let s=e.closest(`.erd-area`).getBoundingClientRect(),c=e.getBoundingClientRect(),l=n.getBoundingClientRect();o*=r;let u=c.top-s.top+c.height/2,d=l.top-s.top+l.height/2,f,p;c.leftl.left?(f=c.left-s.left-o,p=l.left-s.left+l.width+o):(f=c.left-s.left-o,p=l.left-s.left-o),f/=r,p/=r,u/=r,d/=r;let m=f+(p-f)/2;f==p&&(m-=20);let h=`M ${f} ${u} L ${m} ${u} L ${m} ${d} - L ${p} ${d}`,g=document.createElementNS(`http://www.w3.org/2000/svg`,`path`);return g.setAttribute(`class`,`relation-path`),g.setAttribute(`data-from`,i||``),g.setAttribute(`data-to`,a||``),g.setAttribute(`d`,h),g}window.app=window.app||{},window.app.components=window.app.components||{};var N=1e3;window.app.components.pageSidebar=function(e={},...n){let r,i=store({rid:void 0,id:void 0,hidden:void 0,inert:void 0,className:``,widthHistoryKey:`pbPageSidebarWidth`,onmount:void 0,onunmount:void 0}),a=app.utils.extendStore(i,e),o=store({responsiveShow:!1}),s;function c(){if(r){if(window.innerWidth>N){o.responsiveShow=!1,r.dataset.responsive=!1,s?.remove(),s=null;return}r.dataset.responsive=!0,s||(s=t.button({type:`button`,className:`btn transparent secondary responsive-sidebar-btn`,title:`Toggle sidebar`,onclick:e=>{e.stopPropagation(),o.responsiveShow=!o.responsiveShow}},t.i({className:`ri-menu-2-line`,ariaHidden:!0})),document.body.querySelector(`.page-header .breadcrumbs`).before(s))}}function l(e){if(e.target.closest(`.responsive-close`)){o.responsiveShow=!1;return}if(!(e.target.closest(`.page-sidebar`)||e.target.closest(`.app-header`)||e.target.closest(`.modal`)))return e.preventDefault(),e.stopImmediatePropagation(),o.responsiveShow=!1,!1}return a.push(watch(()=>o.responsiveShow,e=>{e?window.addEventListener(`click`,l,!0):window.removeEventListener(`click`,l,!0)})),r=t.aside({pbEvent:`pageSidebar`,rid:i.rid,id:()=>i.id,hidden:()=>i.hidden,inert:()=>i.inert,className:()=>`page-sidebar ${i.className} ${o.responsiveShow?`active`:``}`,onmount:e=>{c(e),window.addEventListener(`resize`,c),i.onmount?.(e)},onunmount:e=>{i.onunmount?.(e),window.removeEventListener(`click`,l,!0),window.removeEventListener(`resize`,c),s?.remove(),a.forEach(e=>e?.unwatch())}},e=>{let n;return i.widthHistoryKey&&(n=localStorage.getItem(i.widthHistoryKey),n&&(e.style.width=n)),app.components.dragline({ondragstart:n=>{e._startWidth=e.offsetWidth},ondragging:(r,a,o)=>{n=e._startWidth+a+`px`,e.style.width=n,i.widthHistoryKey&&localStorage.setItem(i.widthHistoryKey,n)}})},...n),r};var P=`modulepreload`,nt=function(e,n){return new URL(e,n).href},rt={},F=function(e,n,r){let i=Promise.resolve();if(n&&n.length>0){let e=document.getElementsByTagName(`link`),a=document.querySelector(`meta[property=csp-nonce]`),o=a?.nonce||a?.getAttribute(`nonce`);function s(e){return Promise.all(e.map(e=>Promise.resolve(e).then(e=>({status:`fulfilled`,value:e}),e=>({status:`rejected`,reason:e}))))}i=s(n.map(n=>{if(n=nt(n,r),n in rt)return;rt[n]=!0;let i=n.endsWith(`.css`),a=i?`[rel="stylesheet"]`:``;if(r)for(let r=e.length-1;r>=0;r--){let a=e[r];if(a.href===n&&(!i||a.rel===`stylesheet`))return}else if(document.querySelector(`link[href="${n}"]${a}`))return;let s=document.createElement(`link`);if(s.rel=i?`stylesheet`:P,i||(s.as=`script`),s.crossOrigin=``,s.href=n,o&&s.setAttribute(`nonce`,o),document.head.appendChild(s),i)return new Promise((e,r)=>{s.addEventListener(`load`,e),s.addEventListener(`error`,()=>r(Error(`Unable to preload CSS for ${n}`)))})}))}function a(e){let n=new Event(`vite:preloadError`,{cancelable:!0});if(n.payload=e,window.dispatchEvent(n),!n.defaultPrevented)throw e}return i.then(n=>{for(let e of n||[])e.status===`rejected`&&a(e.reason);return e().catch(a)})};window.app=window.app||{},window.app.modals=window.app.modals||{},window.app.modals.openApiPreview=function(e,n={onbeforeopen:null,onafteropen:null,onbeforeclose:null,onafterclose:null}){let r=it(e,n);r&&(document.body.appendChild(r),app.modals.open(r))};function it(e,n){if(!e){console.warn(`[apiPreviewModal] missing required collection`);return}let r,i=store({activeTab:`List/Search`,tabEl:null,isLoading:!1}),a={"List/Search":async e=>{let{docsList:n}=await F(async()=>{let{docsList:e}=await import(`./docsList-BAfVNUIM.js`);return{docsList:e}},__vite__mapDeps([0,1,2,3]),import.meta.url);return i.tabEl=n(e)},View:async e=>{let{docsView:n}=await F(async()=>{let{docsView:e}=await import(`./docsView-Be6Uhvcf.js`);return{docsView:e}},__vite__mapDeps([4,1,2]),import.meta.url);return i.tabEl=n(e)}};e.type!=`view`&&(a.Create=async e=>{let{docsCreate:n}=await F(async()=>{let{docsCreate:e}=await import(`./docsCreate-Be3S3y5K.js`);return{docsCreate:e}},__vite__mapDeps([5,1,2]),import.meta.url);return i.tabEl=n(e)},a.Update=async e=>{let{docsUpdate:n}=await F(async()=>{let{docsUpdate:e}=await import(`./docsUpdate-LtD8DbWI.js`);return{docsUpdate:e}},__vite__mapDeps([6,5,1,2]),import.meta.url);return i.tabEl=n(e)},a.Delete=async e=>{let{docsDelete:n}=await F(async()=>{let{docsDelete:e}=await import(`./docsDelete-CybOn5jy.js`);return{docsDelete:e}},[],import.meta.url);return i.tabEl=n(e)},a.Realtime=async e=>{let{docsRealtime:n}=await F(async()=>{let{docsRealtime:e}=await import(`./docsRealtime-PMESvmJN.js`);return{docsRealtime:e}},[],import.meta.url);return i.tabEl=n(e)},a.Batch=async e=>{let{docsBatch:n}=await F(async()=>{let{docsBatch:e}=await import(`./docsBatch-DNJl1NTn.js`);return{docsBatch:e}},[],import.meta.url);return i.tabEl=n(e)}),e.type==`auth`&&(a[``]=null,a[`List auth methods`]=async e=>{let{docsListAuthMethods:n}=await F(async()=>{let{docsListAuthMethods:e}=await import(`./docsListAuthMethods-9feSopQX.js`);return{docsListAuthMethods:e}},__vite__mapDeps([7,2]),import.meta.url);return i.tabEl=n(e)},a[`Auth with password`]=e.passwordAuth?.enabled?async e=>{let{docsAuthWithPassword:n}=await F(async()=>{let{docsAuthWithPassword:e}=await import(`./docsAuthWithPassword-DEWj8Jyn.js`);return{docsAuthWithPassword:e}},__vite__mapDeps([8,1,2]),import.meta.url);return i.tabEl=n(e)}:null,e.name!=`_superusers`&&(a[`Auth with OAuth2`]=e.oauth2?.enabled?async e=>{let{docsAuthWithOAuth2:n}=await F(async()=>{let{docsAuthWithOAuth2:e}=await import(`./docsAuthWithOAuth2-DUIE4EoY.js`);return{docsAuthWithOAuth2:e}},__vite__mapDeps([9,1,2]),import.meta.url);return i.tabEl=n(e)}:null),a[`Auth with OTP`]=e.otp?.enabled?async e=>{let{docsAuthWithOTP:n}=await F(async()=>{let{docsAuthWithOTP:e}=await import(`./docsAuthWithOTP-B7z2VJzp.js`);return{docsAuthWithOTP:e}},__vite__mapDeps([10,1,2]),import.meta.url);return i.tabEl=n(e)}:null,a[`Auth refresh`]=async e=>{let{docsAuthRefresh:n}=await F(async()=>{let{docsAuthRefresh:e}=await import(`./docsAuthRefresh-UjveHHwo.js`);return{docsAuthRefresh:e}},__vite__mapDeps([11,1,2]),import.meta.url);return i.tabEl=n(e)},e.name!=`_superusers`&&(a.Verification=async e=>{let{docsVerification:n}=await F(async()=>{let{docsVerification:e}=await import(`./docsVerification-B_Nb90xU.js`);return{docsVerification:e}},[],import.meta.url);return i.tabEl=n(e)}),a[`Password reset`]=async e=>{let{docsPasswordReset:n}=await F(async()=>{let{docsPasswordReset:e}=await import(`./docsPasswordReset-vLO_ZWrq.js`);return{docsPasswordReset:e}},[],import.meta.url);return i.tabEl=n(e)},a[`Email change`]=async e=>{let{docsEmailChange:n}=await F(async()=>{let{docsEmailChange:e}=await import(`./docsEmailChange-B---6FKV.js`);return{docsEmailChange:e}},[],import.meta.url);return i.tabEl=n(e)});let o=[watch(()=>i.activeTab,async()=>{i.isLoading=!0,await a[i.activeTab]?.(e),i.isLoading=!1})];return r=t.div({pbEvent:`apiPreviewModal`,className:`modal api-preview-modal`,onbeforeopen:e=>n.onbeforeopen?.(e),onafteropen:e=>{n.onafteropen?.(e)},onbeforeclose:e=>n.onbeforeclose?.(e),onafterclose:e=>{n.onafterclose?.(e),o.forEach(e=>e?.unwatch()),e?.remove()},onmount:e=>{},onunmount:e=>{o.forEach(e=>e?.unwatch())}},t.div({className:`modal-content`},t.aside({className:`api-preview-sidebar`},t.nav({className:`api-preview-nav`},()=>{let e=[];for(let n in a){if(!n){e.push(t.hr());continue}let r=!a[n];e.push(t.button({type:`button`,className:()=>`nav-item ${i.activeTab==n?`active`:``}`,disabled:r,ariaDescription:app.attrs.tooltip(()=>r?`Not enabled for the collection`:``,`left`),onclick:()=>{r||(i.activeTab=n)}},n))}return e})),t.div({className:()=>`api-preview-content ${i.isLoading?`faded`:``}`,scrollTop:()=>i.activeTab?0:null},t.header({className:`api-preview-content-header`},t.h6(null,()=>i.activeTab+` (${e.name})`),t.button({type:`button`,className:()=>`btn sm circle transparent secondary m-l-auto preview-close-btn ${i.isLoading?`loading`:``}`,title:`Close`,onclick:()=>app.modals.close(r)},t.i({className:`ri-close-line`,ariaHidden:!0}))),()=>i.tabEl))),r}window.app=window.app||{},window.app.modals=window.app.modals||{},window.app.modals.openMailTest=function(e=``,n=``){let r=at(e,n);document.body.appendChild(r),app.modals.open(r)};function at(e=``,n=``){let r=`mail_test_`+app.utils.randomString(),i=`pbLastTestEmail`,a=`email_test_request`,o=[{label:`Verification`,value:`verification`},{label:`Password reset`,value:`password-reset`},{label:`Confirm email change`,value:`email-change`},{label:`OTP`,value:`otp`},{label:`Login alert`,value:`login-alert`}],s=store({email:localStorage.getItem(i)||app.store.superuser?.email||``,template:n||o[0].value,isSending:!1,collectionIdOrName:e,get isAuthCollectionsLoading(){return app.store.isCollectionsLoading},get authCollections(){return app.utils.sortedCollections(app.store.collections.filter(e=>e.type==`auth`))},get canSubmit(){return!!s.email&&!!s.template&&!!s.collectionIdOrName}}),c;async function l(){if(!(s.isSending||!s.canSubmit)){s.isSending=!0,clearTimeout(c),c=setTimeout(()=>{s.isSending=!1,app.pb.cancelRequest(a),app.modals.close(),app.toasts.error(`Test email send timeout.`)},15e3);try{s.email!=app.pb.authStore.record?.email&&localStorage.setItem(i,s.email),await app.pb.settings.testEmail(s.collectionIdOrName,s.email,s.template,{requestKey:a}),app.toasts.success(`Successfully sent test email.`),app.modals.close()}catch(e){app.checkApiError(e)}s.isSending=!1,clearTimeout(c)}}let u=[];return t.div({className:`modal popup sm`,onbeforeopen:e=>{u.push(watch(()=>s.isAuthCollectionsLoading,e=>{!e&&!s.collectionIdOrName&&(s.collectionIdOrName=s.authCollections[0]?.id||``)}))},onafterclose:e=>{clearTimeout(c),e?.remove()},onunmount:()=>{clearTimeout(c),u.forEach(e=>e?.unwatch())}},t.header({className:`modal-header`},t.h5({className:`m-auto`},`Send test email`)),t.form({id:r,className:`modal-content mail-settings-test-form`,onsubmit:e=>{e.preventDefault(),l()}},t.div({className:`grid`},t.div({className:`col-lg-12`},()=>o.map((e,n)=>t.field({className:()=>`field ${n>0?`m-t-10`:``}`},t.input({type:`radio`,id:r+`.template.`+e.value,name:`template`,checked:()=>s.template==e.value,onchange:n=>s.template=e.value}),t.label({htmlFor:r+`.template.`+e.value},e.label||e.value)))),()=>{if(!e)return t.div({className:`col-lg-12`},t.div({className:`field`},t.label({htmlFor:r+`.collection`},`Auth collection`),app.components.select({id:r+`.collection`,name:`collection`,required:!0,placeholder:()=>s.isAuthCollectionsLoading?`Loading auth collections...`:`Select auth collection`,options:()=>s.authCollections.map(e=>({value:e.id,label:e.name})),value:()=>s.collectionIdOrName||``,onchange:e=>{s.collectionIdOrName=e?.[0]?.value}})))},t.div({className:`col-lg-12`},t.div({className:`field`},t.label({htmlFor:r+`.email`},`To email address`),t.input({id:r+`.email`,name:`email`,type:`email`,required:!0,value:()=>s.email||``,oninput:e=>s.email=e.target.value}))))),t.footer({className:`modal-footer`},t.button({type:`button`,className:`btn transparent m-r-auto`,onclick:()=>app.modals.close(),disabled:()=>s.isSending},t.span({className:`txt`},`Close`)),t.button({"html-form":r,type:`submit`,className:()=>`btn expanded ${s.isSending?`loading`:``}`,disabled:()=>s.isSending||!s.canSubmit},t.i({className:`ri-mail-send-line`,ariaHidden:!0}),t.span({className:`txt`},`Send`))))}function ot(e={}){let n=store({rid:void 0,collectionA:null,collectionB:null,deleteMissing:!1,className:``}),r=app.utils.extendStore(n,e),i=store({hasAnyChange:!1,get isDeleteDiff(){return!n.collectionB?.id&&!n.collectionB?.name},get isCreateDiff(){return!i.isDeleteDiff&&!n.collectionA?.id},get hasAnyChange(){return app.utils.hasCollectionChanges(n.collectionA,n.collectionB,n.deleteMissing)},get fieldsListA(){return Array.isArray(n.collectionA?.fields)?n.collectionA?.fields:[]},get fieldsListB(){let e=Array.isArray(n.collectionB?.fields)?n.collectionB?.fields:[];return n.deleteMissing||(e=e.concat(n.collectionA?.fields?.filter(n=>!e.find(e=>n.id==e.id))||[])),e},get mainModelProps(){return app.utils.mergeUnique(Object.keys(n.collectionA||{}),Object.keys(n.collectionB||{})).filter(e=>![`fields`,`created`,`updated`].includes(e))},get removedFields(){return i.fieldsListA.filter(e=>!i.fieldsListB.find(n=>e.id==n.id))},get sharedFields(){return i.fieldsListB.filter(e=>i.fieldsListA.find(n=>n.id==e.id))},get addedFields(){return i.fieldsListB.filter(e=>!i.fieldsListA.find(n=>n.id==e.id))}});function a(e){return e===void 0?``:app.utils.isObject(e)?JSON.stringify(e,null,4):``+e}function o(e,n){return e===n?!1:JSON.stringify(e)!=JSON.stringify(n)}function s(e,n){return(e||[]).find(e=>e.id==n)}return t.div({rid:n.rid,pbEvent:`collectionsDiffTableWrapper`,className:()=>`collections-diff-table-wrapper ${n.className}`,onunmount:()=>{r.forEach(e=>e?.unwatch())}},t.div({className:`collections-diff-table-title`},()=>n.collectionA?.id?n.collectionB?.id?[t.span({hidden:()=>!i.hasAnyChange,className:`label import-change-label warning`,textContent:`Changed`}),t.div({className:`inline-flex gap-5`},()=>{if(n.collectionA?.name!=n.collectionB?.name)return[t.strong({className:`txt-strikethrough txt-hint`,textContent:n.collectionA?.name}),t.i({className:`ri-arrow-right-line txt-sm`,ariaHidden:!0})]},t.strong({textContent:()=>n.collectionB?.name}))]:[t.span({className:`label import-change-label danger`,textContent:`Deleted`}),t.strong({textContent:()=>n.collectionA?.name})]:[t.span({className:`label import-change-label success`,textContent:`Added`}),t.strong({textContent:()=>n.collectionB?.name})]),t.table({className:`collections-diff-table`},t.thead(null,t.tr(null,t.th({className:`min-width`},`Props`),t.th({width:`40%`},`Old`),t.th({width:`40%`},`New`))),t.tbody(null,()=>i.mainModelProps.map(e=>{let r=o(n.collectionA?.[e],n.collectionB?.[e]);return t.tr({className:r?`txt-primary`:``},t.td({className:`min-width`},e),t.td({className:()=>i.isCreateDiff?`changed-non-col`:r?`changed-old-col`:``},t.pre({className:`txt diff-value`},a(n.collectionA?.[e]))),t.td({className:()=>i.isDeleteDiff?`changed-non-col`:r?`changed-new-col`:``},t.pre({className:`txt diff-value`},a(n.collectionB?.[e]))))}),()=>{if(!n.deleteMissing&&!i.isDeleteDiff)return;let e=[];for(let n of i.removedFields){e.push(t.tr(null,t.th({className:`min-width`,colSpan:3},t.span({className:`txt`},`field: `,n.name),t.span({className:`label danger m-l-5`},`Deleted - `,t.small(null,`All stored data related to '${n.name}' will be deleted!`)))));for(let r in n){let i=n[r];e.push(t.tr(null,t.td({className:`min-width field-key-col`},r),t.td({className:`changed-old-col`},t.pre({className:`txt`},a(i))),t.td({className:`changed-none-col`})))}}return e},()=>{let e=[];for(let n of i.sharedFields){let r=s(i.fieldsListA,n.id),c=o(r,s(i.fieldsListB,n.id));e.push(t.tr(null,t.th({className:`min-width`,colSpan:3},t.span({className:`txt`},`field: `,n.name),t.span({className:`label warning m-l-5 ${c?``:`hidden`}`,textContent:`Changed`}))));for(let i in n){let s=n[i],c=o(r?.[i],s);e.push(t.tr({className:c?`txt-primary`:``},t.td({className:`min-width field-key-col`},i),t.td({className:c?`changed-old-col`:``},t.pre({className:`txt`},a(r?.[i]))),t.td({className:c?`changed-new-col`:``},t.pre({className:`txt`},a(s)))))}}return e},()=>{let e=[];for(let n of i.addedFields){e.push(t.tr(null,t.th({className:`min-width`,colSpan:3},t.span({className:`txt`},`field: `,n.name),t.span({className:`label success m-l-5`},`Added`))));for(let r in n){let i=n[r];e.push(t.tr({className:`txt-primary`},t.td({className:`min-width field-key-col`},r),t.td({className:`changed-none-col`}),t.td({className:`changed-new-col`},t.pre({className:`txt`},a(i)))))}}return e})))}window.app=window.app||{},window.app.modals=window.app.modals||{},window.app.modals.openImportCollectionsReview=function(e,n,r={deleteMissing:!1,onsubmit:null}){let i=st(e,n,r);i&&(document.body.appendChild(i),app.modals.open(i))};function st(e,n,r){let i,a=store({deleteMissing:!1,onsubmit:function(e){}}),o=app.utils.extendStore(a,r),s=store({isImporting:!1,pairs:[]});function c(){let r=[];for(let i of e){let e=n.find(e=>e.id==i.id);(a.deleteMissing&&!e?.id||e?.id&&app.utils.hasCollectionChanges(i,e,a.deleteMissing))&&r.push({old:i,new:e})}for(let i of n){let n=e.find(e=>e.id==i.id);n?.id||r.push({old:n,new:i})}s.pairs=r}function l(){let r=[];if(a.deleteMissing)for(let i of e){let e=n.find(e=>e.id==i.id);if(!e)r.push(i.name+`.*`);else{let n=Array.isArray(i.fields)?i.fields:[];for(let a of n)e.fields.find(e=>e.id==a.id)||r.push(`${i.name}.${a.name} (${a.id})`)}}r.length?app.modals.confirm([t.h6(null,`Do you really want to delete the following collection fields and their related records data:`),t.ul(null,()=>r.map(e=>t.li(null,e)))],()=>u()):u()}async function u(){if(!s.isImporting){s.isImporting=!0;try{await app.pb.collections.import(n,a.deleteMissing),await app.store.loadCollections(),a.onsubmit?.(JSON.parse(JSON.stringify(app.store.collections))),app.toasts.success(`Successfully imported collections configuration.`)}catch(e){app.checkApiError(e)}s.isImporting=!1,app.modals.close(i)}}return i=t.div({pbEvent:`importCollectionsReviewModal`,className:`modal popup full import-collections-review-modal`,onbeforeopen:()=>{c()},onbeforeclose:()=>!s.isImporting,onafterclose:e=>{e?.remove()},onunmount:()=>{o.forEach(e=>e?.unwatch())}},t.header({className:`modal-header`},t.h5(null,`Side-by-side diff`)),t.div({className:`modal-content`},()=>s.pairs.map(e=>ot({collectionA:e.old,collectionB:e.new,deleteMissing:a.deleteMissing}))),t.footer({className:`modal-footer`},t.button({type:`button`,className:`btn transparent m-r-auto`,disabled:()=>s.isImporting,onclick:()=>app.modals.close(i)},t.span({className:`txt`},`Close`)),t.button({type:`button`,className:()=>`btn expanded ${s.isImporting?`loading`:``}`,disabled:()=>s.isImporting,onclick:()=>l()},t.span({className:`txt`},`Confirm and import`)))),i}window.app=window.app||{},window.app.components=window.app.components||{},window.app.components.recordSummary=function(e,n=null){let r=store({get collection(){return app.store.collections.find(n=>n.id==e.collectionId||n.name==e.collectionName)},get presentableFields(){if(!r.collection?.id)return[];let e=r.collection.fields.filter(e=>e.presentable).sort((e,n)=>{let r=app.fieldTypes[e.type].summaryPriority||0,i=app.fieldTypes[n.type].summaryPriority||0;return r>i?1:re.name==n);if(i){e.push(i);break}}return e}});return t.div({className:`label record-summary`},t.i({ariaHidden:!0,className:`ri-eye-line link-hint record-preview-icon`,onclick:e=>{e.stopImmediatePropagation(),e.preventDefault()},onmouseenter:n=>{lt(n.target,e,100)},onmouseleave:e=>{ct(e.target,100)},onunmount:e=>{ct(e,0)}}),()=>{let i=[];function a(e){(e==null||e==``)&&(e=t.span({className:`missing-value`})),i.push(e)}for(let i of r.presentableFields){let r=app.fieldTypes[i.type]?.view;if(r)a(r({short:!0,get record(){return e},get field(){return i},get meta(){return n}}));else{let n=app.utils.toArray(e[i.name]).splice(0,3);for(let e of n)a(e)}}return i})};function ct(e,n=150){if(e){if(clearTimeout(e._summaryDropdownTimeoutId),n<=0){e?._summaryDropdown?.hidePopover?.();return}e._summaryDropdownTimeoutId=setTimeout(()=>{e?._summaryDropdown?.hidePopover?.()},n)}}function lt(e,n,r=150){if(e){if(clearTimeout(e._summaryDropdownTimeoutId),r<=0){ut(e,n);return}e._summaryDropdownTimeoutId=setTimeout(()=>{ut(e,n)},r)}}var ut=function(e,n){e&&(e._summaryDropdown||(e._summaryDropdown=t.div({className:`dropdown record-summary-dropdown`,popover:`manual`,onclick:e=>{e.stopImmediatePropagation(),e.preventDefault()}},t.div({className:`record-header`},t.a({className:`link-hint txt-bold m-r-auto`,target:`_blank`,href:`#/collections?collection=${n.collectionName}&record=${n.id}`,onclick:e=>{e.stopImmediatePropagation()}},t.span({className:`txt`},`Edit relation record`),t.i({className:`ri-external-link-line`,ariaHidden:!0})),t.button({type:`button`,className:`link-hint`,title:`Close`,onclick:()=>ct(e,0)},t.i({className:`ri-close-line`,ariaHidden:!0}))),t.hr(),t.pre({className:`record-json`},()=>{let e=app.store.collections.find(e=>e.id==n.collectionId||e.name==n.collectionName)?.fields||[];if(!e.length)return;let r={collectionId:n.collectionId,collectionName:n.collectionName};for(let i of e)r[i.name]=n[i.name];return JSON.stringify(app.utils.truncateObject(r,27),null,2)})),e.appendChild(e._summaryDropdown)),e._summaryDropdown?.showPopover({source:e}))};window.app=window.app||{},window.app.components=window.app.components||{},window.app.components.recordsSearchbar=function(e={}){let n=store({rid:void 0,id:void 0,hidden:void 0,inert:void 0,disabled:void 0,value:``,className:``,collection:void 0,onsubmit:e=>{}}),r=app.utils.extendStore(n,e);return t.div({rid:n.rid,id:()=>n.id,hidden:()=>n.hidden,inert:()=>n.inert,className:()=>`full-width records-searchbar-wrapper ${n.className}`,onunmount:()=>{r.forEach(e=>e?.unwatch())}},app.components.searchbar({placeholder:()=>!n.disabled&&!n.collection?.id?`Loading...`:`Search term or filter...`,historyKey:()=>`pbRecordsSearchHistory_`+n.collection?.id,disabled:()=>n.disabled||!n.collection,value:()=>n.value,autocomplete:e=>app.utils.collectionAutocompleteKeys(n.collection,e,{requestKeys:!1,collectionJoinKeys:!1}),onsubmit:n.onsubmit}))},window.app=window.app||{},window.app.components=window.app.components||{};var dt={max:10,pending:new Set,processing:new Set};function ft(e){return dt.pending.add(e),dt.processing.size<=dt.max&&pt(),()=>{dt.pending.delete(e),dt.processing.delete(e),dt.processing.sizen.id,hidden:()=>n.hidden,inert:()=>n.inert,type:`button`,draggable:!1,className:()=>`thumb ${n.extraClasses} ${i.isPreviewLoading?`loading`:``}`,title:()=>(i.hasPreview?`Preview`:`Download`)+` `+n.filename,onclick:async e=>{e.stopPropagation();async function r(){let e=await app.getFileToken(n.record.collectionId);return app.pb.files.getURL(n.record,n.filename,{token:e})}if(i.hasPreview)app.modals.openFilePreview(r);else{let e=await r();app.utils.download(e,n.filename)}},onunmount:()=>{r.forEach(e=>e?.unwatch())}},()=>{if(i.fileType==`image`){let e=t.img({draggable:!1,alt:()=>`Thumb of `+n.filename,src:()=>i.previewURL,onerror:n=>{console.warn(`[recordFileThumb] load err:`,n),i.isPreviewLoading=!1,e?._semaphoreRelease?.()},onload:()=>{i.isPreviewLoading=!1,e?._semaphoreRelease?.()},onmount:e=>{i.isPreviewLoading=!0,e._semaphoreRelease=ft(async()=>{try{i.previewToken=await app.getFileToken(n.record.collectionId),i.previewURL=app.pb.files.getURL(n.record,n.filename,{thumb:`100x100`,token:i.previewToken})}catch(e){console.warn(e)}})},onunmount:e=>{i.isPreviewLoading=!1,e._semaphoreRelease?.()}});return e}return t.i({className:app.utils.fileTypeIcons[i.fileType]||`ri-file-line`,ariaHidden:!0})})},window.app=window.app||{},window.app.modals=window.app.modals||{};var mt=100,ht={btnText:`Insert`,fileTypes:[],onselect:function(e){}},gt=`pbLastRecordFilePickerCollection`,_t=`listFilePickerRecords`;window.app.modals.openRecordFilePicker=function(e={}){e=Object.assign({},ht,e);let n=vt(e);document.body.appendChild(n),app.modals.open(n)};function vt(e=ht){let n,r=`file_picker_`+app.utils.randomString(),i=store({selectedFile:{},records:[],activeCollectionId:``,searchTerm:``,lastRecordsPage:1,lastTotalRecords:0,isLoadingRecords:!1,get collections(){return app.utils.sortedCollections(app.store.collections.filter(e=>e.type==`view`?!1:!!e.fields?.find(e=>e.type===`file`&&!e.protected)))},get activeCollection(){return i.collections.find(e=>e.id==i.activeCollectionId)||i.collections[0]},get activeCollectionFileFields(){return i.activeCollection?.fields?.filter(e=>e.type===`file`&&!e.protected)||[]},get isLoading(){return app.store.isLoadingCollections||i.isLoadingRecords},get canLoadMore(){return!i.isLoadingRecords&&i.lastTotalRecords==mt},get hasAtleastOneFile(){return!!i.records.find(e=>c(e).length>0)}}),a=[];a.push(watch(()=>{i.activeCollectionId?(window.localStorage.setItem(gt,i.activeCollectionId),i.searchTerm=``):i.activeCollectionId=window.localStorage.getItem(gt)})),a.push(watch(()=>[i.activeCollection,i.searchTerm],()=>s(!0)));function o(){app.pb.cancelRequest(_t),i.isLoadingRecords=!1,i.records=[],i.lastTotalRecords=0,i.lastRecordsPage=1,i.selectedFile={}}async function s(e=!1){if(!i.activeCollection){o();return}e&&o(),i.isLoadingRecords=!0;try{let n=e?1:i.lastRecordsPage+1,r=app.utils.getAllCollectionIdentifiers(i.activeCollection),a=app.utils.normalizeSearchFilter(i.searchTerm,r)||``;a&&(a+=` && `),a+=`(`+i.activeCollectionFileFields.map(e=>`${e.name}:length>0`).join(`||`)+`)`;let o=await app.pb.collection(i.activeCollection.id).getList(n,mt,{requestKey:_t,filter:a,skipTotal:1,sort:i.activeCollection.type==`view`?``:`-@rowid`});i.lastRecordsPage=o.page,i.lastTotalRecords=o.items.length,i.records=app.utils.filterDuplicatesByKey(i.records.concat(o.items)),i.isLoadingRecords=!1}catch(e){e.isAbort||(i.isLoadingRecords=!1,app.checkApiError(e))}}function c(n){let r=[];for(let a of i.activeCollectionFileFields){let i=app.utils.toArray(n[a.name]);for(let n of i)(app.utils.isEmpty(e.fileTypes)||e.fileTypes?.includes(app.utils.getFileType(n)))&&r.push(n)}return r}function l(e,n){i.selectedFile={record:e,name:n,thumb:``}}function u(e,n){return i.selectedFile?.name==n&&i.selectedFile?.record?.id==e?.id}let d={"record:create":e=>{e.detail.collectionId==i.activeCollection?.id&&(i.selectedFile?.record?.id==e.detail.id&&(i.selectedFile.record=e.detail),s(!0))},"record:delete":e=>{e.detail.collectionId!=i.activeCollection?.id&&e.detail.collectionName!=i.activeCollection?.name||(i.selectedFile?.record?.id==e.detail.id&&(i.selectedFile={}),s(!0))}};return n=t.div({className:`modal popup record-file-picker-modal`,onafterclose:e=>{e?.remove()},onmount:e=>{for(let e in d)document.addEventListener(e,d[e])},onunmount:e=>{a.forEach(e=>e?.unwatch());for(let e in d)document.removeEventListener(e,d[e])}},t.header({className:`modal-header`},t.button({className:()=>`btn primary outline record-file-picker-collection-select-btn ${app.store.isLoadingCollections?`loading`:``}`,disabled:()=>app.store.isLoadingCollections,"html-popovertarget":`collections_dropdown`+r},t.span({className:`txt-lg collection-name m-r-auto`},()=>i.activeCollection?.name||`Select collection`),t.i({className:`ri-arrow-drop-down-line`,ariaHidden:!0})),t.div({id:`collections_dropdown`+r,className:`dropdown`,popover:`hint`},()=>i.collections.map(e=>t.button({type:`button`,className:()=>`dropdown-item ${i.activeCollectionId==e.id?`active`:``}`,onclick:n=>{i.activeCollectionId=e.id,n.target?.closest(`.dropdown`)?.hidePopover()}},e.name))),app.components.recordsSearchbar({disabled:()=>!i.activeCollection?.id,collection:()=>i.activeCollection,value:()=>i.searchTerm,onsubmit:e=>i.searchTerm=e}),t.button({type:`button`,className:`btn circle transparent`,ariaLabel:app.attrs.tooltip(`Add new record`),onclick:()=>app.modals.openRecordUpsert(i.activeCollection)},t.i({className:`ri-add-line txt-hint`,ariaHidden:!0}))),t.div({className:`modal-content`},t.div({className:`block txt-center`,hidden:()=>i.hasAtleastOneFile||!i.isLoading},t.span({className:`loader`})),t.div({className:`record-file-picker-list`},()=>{let e=[];for(let n of i.records){let r=c(n);for(let i of r)e.push(t.button({rid:n.id+`:`+i,className:()=>`list-item thumb ${u(n,i)?`success`:``}`,ariaDescription:app.attrs.tooltip(i,`bottom`),onclick:()=>l(n,i)},()=>{if(app.utils.hasImageExtension(i))return t.img({loading:`lazy`,src:app.pb.files.getURL(n,i,{thumb:`100x100`}),alt:i});let e=app.utils.getFileType(i);return t.i({className:app.utils.fileTypeIcons[e]||`ri-file-line`,ariaHidden:!0})}))}return e}),t.div({hidden:()=>!i.canLoadMore||!i.hasAtleastOneFile,className:`block txt-center`},t.button({className:()=>`btn secondary expanded-lg m-t-base ${i.isLoadingRecords?`loading`:``}`,disabled:()=>i.isLoadingRecords,onclick:()=>s()},t.span({className:`txt`},`Load more`))),t.div({className:`block txt-center txt-hint p-t-10 p-b-10`,hidden:()=>i.hasAtleastOneFile||i.isLoading},()=>app.utils.isEmpty(e.fileTypes)?t.p(null,`No records with selectable files found.`):t.p(null,`No "${e.fileTypes.join(`", "`)}" files found.`),t.button({type:`button`,className:`btn sm secondary`,textContent:`Clear search`,hidden:()=>!i.searchTerm?.length,onclick:()=>{i.searchTerm=``}}))),t.footer({className:`modal-footer`},t.button({type:`button`,className:`btn transparent m-r-auto`,onclick:()=>app.modals.close(n)},t.span({className:`txt`},`Close`)),()=>{if(!i.selectedFile?.name||!app.utils.hasImageExtension(i.selectedFile.name))return;let e=[{value:``,label:`Original size`},{value:`100x100`,label:`100x100 thumb`}],n=i.activeCollectionFileFields.find(e=>i.selectedFile.record[e.name].includes(i.selectedFile.name)),r=app.utils.toArray(n.thumbs);for(let n of r)e.push({value:n,label:`${n} thumb`});return t.div({className:`record-file-picker-thumb-select`},app.components.select({required:!0,value:i.selectedFile.thumb||``,options:e,onchange:e=>{i.selectedFile.thumb=e?.[0].value}}))},t.button({type:`button`,className:`btn expanded`,disabled:()=>i.isLoading||!i.selectedFile?.name,onclick:()=>{let r=JSON.parse(JSON.stringify(i.selectedFile));if(e.onselect&&e.onselect(r)===!1)return!1;app.modals.close(n)}},t.span({className:`txt`},()=>e.btnText||ht.btnText)))),n}window.app=window.app||{},window.app.modals=window.app.modals||{};var yt=50,bt=100,xt=`listRelationPickerRecords`,St={collection:``,selectedIds:[],maxSelect:1,btnText:`Set selection`,onselect:function(e){}};window.app.modals.openRecordsPicker=function(e={}){e=Object.assign({},St,e);let n=Ct(e);document.body.appendChild(n),app.modals.open(n)};function Ct(e=St){let n,r=store({searchTerm:``,selected:[],preselected:[],isLoadingPreselected:!1,records:[],isLoadingRecords:!1,lastRecordsPage:1,lastRecordsTotal:0,get collection(){let n=e.collection;return typeof e.collection==`object`&&e.collection?.id&&(n=e.collection?.id),app.store.collections.find(e=>e.id==n||e.name==n)},get isLoading(){return r.isLoadingPreselected||r.isLoadingRecords},get canLoadMore(){return!r.isLoadingRecords&&r.lastRecordsTotal==yt}}),i=[watch(()=>[e.collection,e.selectedIds],()=>{o()}),watch(()=>[r.collection,r.searchTerm],()=>{s(!0)})];function a(){setTimeout(()=>app.modals.close(n),0)}async function o(){let n=app.utils.toArray(e.selectedIds),i=e.collection?.id||e.collection;if(!i||!n.length)return;r.isLoadingSelected=!0;let a=[],o=n.slice(),s=[];for(;o.length>0;){let e=[],n=o.splice(0,bt);for(let r of n)e.push(`id="${r}"`);s.push(app.pb.collection(i).getFullList({requestKey:null,filter:e.join(`||`)}))}try{await Promise.all(s).then(e=>{a=a.concat(...e)});let e=[];for(let r of n){let n=a.find(e=>e.id==r);n&&e.push(n)}r.searchTerm.trim()||(r.records=app.utils.filterDuplicatesByKey(e.concat(r.records))),r.selected=e,r.isLoadingSelected=!1}catch(e){e.isAbort||(app.checkApiError(e),r.isLoadingSelected=!1)}}async function s(e=!1){if(r.collection?.id){e&&(c(),r.searchTerm.trim()||(r.records=r.selected.slice())),r.isLoadingRecords=!0;try{let n=e?1:r.lastRecordsPage+1,i=app.utils.getAllCollectionIdentifiers(r.collection),a=app.utils.normalizeSearchFilter(r.searchTerm,i)||``,o=await app.pb.collection(r.collection.id).getList(n,yt,{requestKey:xt,filter:a,skipTotal:1,sort:r.collection.type==`view`?``:`-@rowid`});r.lastRecordsPage=o.page,r.lastRecordsTotal=o.items.length,r.records=app.utils.filterDuplicatesByKey(r.records.concat(o.items)),r.isLoadingRecords=!1}catch(e){e.isAbort||(r.isLoadingRecords=!1,app.checkApiError(e))}}}function c(){app.pb.cancelRequest(xt),r.isLoadingRecords=!1,r.records=[],r.lastTotalRecords=0,r.lastRecordsPage=1}function l(e){e.target.scrollHeight-e.target.clientHeight-e.target.scrollTop<=100&&r.canLoadMore&&s()}function u(n){let i=r.selected.findIndex(e=>e.id==n.id);if(i>=0)r.selected.splice(i,1);else{let i=e.maxSelect||1,a=r.selected.length-i;for(;a>=0;)r.selected.pop(),a--;r.selected.push(n)}}function d(e){return r.selected.findIndex(n=>n.id==e.id)>=0}let f={"record:save":e=>{if(e.detail.collectionId!=r.collection?.id)return;let n=r.selected?.findIndex(n=>n.id==e.detail.id);n>=0&&(r.selected[n]=e.detail),app.utils.pushOrReplaceObject(r.records,e.detail),s(!0)},"record:delete":e=>{e.detail.collectionId!=r.collection?.id&&e.detail.collectionName!=r.collection?.name||(d(e.detail)&&u(e.detail),app.utils.removeByKey(r.records,`id`,e.detail.id),s(!0))}};return n=t.div({className:`modal popup lg records-picker-modal`,onafterclose:e=>{e.remove()},onmount:e=>{for(let e in f)document.addEventListener(e,f[e])},onunmount:e=>{i.forEach(e=>e?.unwatch());for(let e in f)document.removeEventListener(e,f[e])}},t.header({className:`modal-header`},t.h6({className:`collection-name`},()=>r.collection.name),app.components.recordsSearchbar({disabled:()=>!r.collection?.id,collection:()=>r.collection,value:()=>r.searchTerm,onsubmit:e=>r.searchTerm=e}),t.button({type:`button`,className:`btn circle transparent`,ariaLabel:app.attrs.tooltip(`Add new record`),onclick:()=>{app.modals.openRecordUpsert(r.collection)}},t.i({className:`ri-add-line txt-hint`,ariaHidden:!0}))),t.div({className:`modal-content`,hidden:()=>r.isLoadingCollection},t.div({className:`list records-picker-list`,onscroll:l,onresize:l},()=>r.records.map(e=>t.div({tabIndex:0,className:`list-item handle`,onclick:()=>{u(e),document.activeElement?.blur()}},t.div({className:`content`},t.span({className:`state-icon`},t.i({ariaHidden:!0,className:()=>d(e)?`ri-checkbox-circle-fill txt-success`:`ri-checkbox-blank-circle-line txt-disabled`})),()=>app.components.recordSummary(e)),t.div({className:`actions autohide`},t.button({className:`btn sm secondary transparent circle`,ariaLabel:app.attrs.tooltip(`Edit`),onclick:n=>{n.stopPropagation(),app.modals.openRecordUpsert(r.collection,e)}},t.i({className:`ri-pencil-line`,ariaHidden:!0}))))),t.div({className:`list-item`,hidden:()=>!r.isLoading},t.div({className:`skeleton-loader`})),t.div({className:`list-item`,hidden:()=>r.records.length||r.isLoading},t.div({className:`content txt-hint`},t.span({className:`txt`},`No records found.`),t.button({type:`button`,className:`btn sm secondary`,textContent:`Clear search`,hidden:()=>!r.searchTerm.trim().length,onclick:()=>{r.searchTerm=``}})))),t.div({className:`block m-t-base`},t.p({className:`txt-bold`},()=>`Selected (${r.selected.length} of max ${e.maxSelect||1})`),t.span({className:`txt-hint`,hidden:()=>r.selected},`No selected records.`),app.components.sortable({className:`records-picker-selected-list`,data:()=>r.selected,dataItem:(e,n)=>t.div({rid:e,className:`label handle`},()=>app.components.recordSummary(e,[],!0),t.span({className:`link-hint`,title:`Remove`,role:`button`,onclick:()=>u(e)},t.i({className:`ri-close-line`,ariaHidden:!0}))),onchange:(e,n,i)=>{r.selected=e}}))),t.footer({className:`modal-footer`},t.button({type:`button`,className:`btn transparent m-r-auto`,onclick:()=>a()},t.span({className:`txt`},`Close`)),()=>{if(!r.selectedFile?.name||!app.utils.hasImageExtension(r.selectedFile.name))return;let e=[{value:``,label:`Original size`},{value:`100x100`,label:`100x100 thumb`}],n=r.activeCollectionFileFields.find(e=>r.selectedFile.record[e.name].includes(r.selectedFile.name)),i=app.utils.toArray(n.thumbs);for(let n of i)e.push({value:n,label:`${n} thumb`});return t.div({className:`record-file-picker-thumb-select`},app.components.select({required:!0,value:r.selectedFile.thumb||``,options:e,onchange:e=>{r.selectedFile.thumb=e?.[0].value}}))},t.button({type:`button`,className:`btn expanded`,disabled:()=>r.isLoadingCollection,onclick:()=>{let n=JSON.parse(JSON.stringify(r.selected));if(e.onselect&&e.onselect(n)===!1)return!1;a()}},t.span({className:`txt`},e.btnText||St.btnText)))),n}window.app=window.app||{},window.app.modals=window.app.modals||{},window.app.modals.openRecordPreview=function(e,n={onbeforeopen:null,onafteropen:null,onbeforeclose:null,onafterclose:null}){let r=I(e,n);r&&(document.body.appendChild(r),app.modals.open(r))};function wt(e){e.expand&&(e=Object.assign({},e),delete e.expand),app.utils.downloadJSON(e,e.collectionName+`_`+e.id+`.json`)}function Tt(e){e.expand&&(e=Object.assign({},e),delete e.expand),app.utils.copyToClipboard(JSON.stringify(e,null,2)),app.toasts.success(`Record copied to clipboard!`)}function I(e,n){let r,i=app.utils.randomString(),a=store({isLoading:!1,record:null,get collection(){return app.store.collections.find(n=>n.id==e.collectionId||n.name==e.collectionName)}});async function o(){if(!e?.id){app.toasts.error(`Failed to load record.`),setTimeout(()=>app.modals.close(r),0),console.warn(`[recordPreviewModal] missing required record id field:`,e);return}if(!e.collectionId&&!e.collectionName){app.toasts.error(`Failed to load record.`),setTimeout(()=>app.modals.close(r),0),console.warn(`[recordPreviewModal] missing required collectionId or collectionName field:`,e);return}a.isLoading=!0;try{let n=[],r=a.collection?.fields?.filter(e=>!e.hidden&&e.presentable&&e.type==`relation`)||[];for(let e of r)n.push(e.name);a.record=await app.pb.collection(e.collectionId||e.collectionName).getOne(e.id,{requestKey:`record_preview_`+e.id,expand:n.join(`,`)||void 0}),a.isLoading=!1}catch(e){e?.isAbort||(a.isLoading=!1,app.checkApiError(e),setTimeout(()=>app.modals.close(r),0))}}return r=t.div({pbEvent:`recordPreviewModal`,className:`modal record-preview-modal`,onbeforeopen:e=>(o(),n.onbeforeopen?.(e)),onafteropen:e=>{n.onafteropen?.(e)},onbeforeclose:e=>n.onbeforeclose?.(e),onafterclose:e=>{n.onafterclose?.(e),e?.remove()},onmount:e=>{},onunmount:e=>{}},t.header({className:`modal-header`},t.h6(null,t.strong(null,()=>e?.collectionName||a.collection?.name),` record preview`),t.button({title:`More options`,className:`btn sm circle transparent m-l-auto`,"html-popovertarget":i+`preview-dropdown`},t.i({className:`ri-more-line`,ariaHidden:!0})),t.div({id:i+`preview-dropdown`,className:`dropdown`,popover:`auto`},e=>t.button({className:`dropdown-item`,onclick:()=>{Tt(a.record),e.hidePopover()}},t.i({className:`ri-braces-line`,ariaHidden:!0}),t.span({className:`txt`},`Copy JSON`)))),t.div({className:`modal-content`},()=>a.isLoading||!a.record?.id||!a.collection?.id?t.table(null,t.tbody(null,()=>{let e=a.collection?.fields?.filter(e=>e.type!=`password`).length||1,n=[];for(let r=0;r(a.collection?.fields?.filter(e=>e.type!=`password`)||[]).map(e=>t.tr(null,t.th({className:()=>`min-width p-r-0 col-field-name-${e.name}`},e.name),t.td({className:()=>`col-field-name-${e.name}`},()=>app.fieldTypes[e.type]?.view?app.fieldTypes[e.type].view({short:!1,get record(){return a.record},get field(){return e}}):app.utils.displayValue(a.record[e.name],1e3))))))),t.footer({className:`modal-footer`},t.button({type:`button`,className:`btn transparent m-r-auto`,onclick:()=>app.modals.close(r)},t.span({className:`txt`},`Close`)),t.button({type:`button`,className:`btn`,onclick:()=>wt(a.record)},t.i({className:`ri-download-line`,ariaHidden:!0}),t.span({className:`txt`},`Download JSON`)))),r}window.app=window.app||{},window.app.modals=window.app.modals||{},window.app.modals.openRecordImpersontate=function(e){let n=R(e);document.body.appendChild(n),app.modals.open(n)};function R(e){let n=`impersonate_`+app.utils.randomString(),r=store({isLoading:!1,token:``,duration:0,get collection(){return app.store.collections.find(n=>n.id==e.collectionId||n.name==e.collectionName)}}),i=app.utils.getApiExampleURL();async function a(){if(!r.isLoading){r.isLoading=!0;try{r.token=(await app.pb.collection(r.collection.name).impersonate(e.id,r.duration)).authStore.token}catch(e){app.checkApiError(e)}r.isLoading=!1}}function o(){r.token=``,r.duration=0}return t.div({className:`modal popup record-impersonate-auth-modal`,onbeforeclose:()=>!r.isLoading,onafterclose:e=>{e?.remove()}},t.header({className:`modal-header`},t.h6(null,`Generate nonrenewable auth token for `,t.strong(null,()=>e.email||e.id))),t.div({className:`modal-content`},t.form({id:n+`_form`,hidden:()=>r.token,className:`block`,onsubmit:e=>{e.preventDefault(),a()}},t.div({className:`field`},t.label({htmlFor:n+`_duration`},`Token duration (in seconds)`),t.input({id:n+`_duration`,type:`number`,name:`duration`,min:0,step:1,placeholder:()=>`Default to the collection settings (${r.collection?.authToken?.duration||0}s)`,value:e=>r.duration||``,oninput:e=>r.duration=parseInt(e.target.value,10)}))),t.div({hidden:()=>!r.token,className:`alert success impersonate-success`},t.strong(null,()=>r.token),` `,app.components.copyButton(()=>r.token)),app.components.codeBlockTabs({hidden:()=>!r.token,className:`sdk-examples m-t-base`,tabs:[{title:`JS SDK`,language:`js`,value:` + L ${p} ${d}`,g=document.createElementNS(`http://www.w3.org/2000/svg`,`path`);return g.setAttribute(`class`,`relation-path`),g.setAttribute(`data-from`,i||``),g.setAttribute(`data-to`,a||``),g.setAttribute(`d`,h),g}window.app=window.app||{},window.app.components=window.app.components||{};var N=1e3;window.app.components.pageSidebar=function(e={},...n){let r,i=store({rid:void 0,id:void 0,hidden:void 0,inert:void 0,className:``,widthHistoryKey:`pbPageSidebarWidth`,onmount:void 0,onunmount:void 0}),a=app.utils.extendStore(i,e),o=store({responsiveShow:!1}),s;function c(){if(r){if(window.innerWidth>N){o.responsiveShow=!1,r.dataset.responsive=!1,s?.remove(),s=null;return}r.dataset.responsive=!0,s||(s=t.button({type:`button`,className:`btn transparent secondary responsive-sidebar-btn`,title:`Toggle sidebar`,onclick:e=>{e.stopPropagation(),o.responsiveShow=!o.responsiveShow}},t.i({className:`ri-menu-2-line`,ariaHidden:!0})),document.body.querySelector(`.page-header .breadcrumbs`).before(s))}}function l(e){if(e.target.closest(`.responsive-close`)){o.responsiveShow=!1;return}if(!(e.target.closest(`.page-sidebar`)||e.target.closest(`.app-header`)||e.target.closest(`.modal`)))return e.preventDefault(),e.stopImmediatePropagation(),o.responsiveShow=!1,!1}return a.push(watch(()=>o.responsiveShow,e=>{e?window.addEventListener(`click`,l,!0):window.removeEventListener(`click`,l,!0)})),r=t.aside({pbEvent:`pageSidebar`,rid:i.rid,id:()=>i.id,hidden:()=>i.hidden,inert:()=>i.inert,className:()=>`page-sidebar ${i.className} ${o.responsiveShow?`active`:``}`,onmount:e=>{c(e),window.addEventListener(`resize`,c),i.onmount?.(e)},onunmount:e=>{i.onunmount?.(e),window.removeEventListener(`click`,l,!0),window.removeEventListener(`resize`,c),s?.remove(),a.forEach(e=>e?.unwatch())}},e=>{let n;return i.widthHistoryKey&&(n=localStorage.getItem(i.widthHistoryKey),n&&(e.style.width=n)),app.components.dragline({ondragstart:n=>{e._startWidth=e.offsetWidth},ondragging:(r,a,o)=>{n=e._startWidth+a+`px`,e.style.width=n,i.widthHistoryKey&&localStorage.setItem(i.widthHistoryKey,n)}})},...n),r};var P=`modulepreload`,nt=function(e,n){return new URL(e,n).href},rt={},F=function(e,n,r){let i=Promise.resolve();if(n&&n.length>0){let e=document.getElementsByTagName(`link`),a=document.querySelector(`meta[property=csp-nonce]`),o=a?.nonce||a?.getAttribute(`nonce`);function s(e){return Promise.all(e.map(e=>Promise.resolve(e).then(e=>({status:`fulfilled`,value:e}),e=>({status:`rejected`,reason:e}))))}i=s(n.map(n=>{if(n=nt(n,r),n in rt)return;rt[n]=!0;let i=n.endsWith(`.css`),a=i?`[rel="stylesheet"]`:``;if(r)for(let r=e.length-1;r>=0;r--){let a=e[r];if(a.href===n&&(!i||a.rel===`stylesheet`))return}else if(document.querySelector(`link[href="${n}"]${a}`))return;let s=document.createElement(`link`);if(s.rel=i?`stylesheet`:P,i||(s.as=`script`),s.crossOrigin=``,s.href=n,o&&s.setAttribute(`nonce`,o),document.head.appendChild(s),i)return new Promise((e,r)=>{s.addEventListener(`load`,e),s.addEventListener(`error`,()=>r(Error(`Unable to preload CSS for ${n}`)))})}))}function a(e){let n=new Event(`vite:preloadError`,{cancelable:!0});if(n.payload=e,window.dispatchEvent(n),!n.defaultPrevented)throw e}return i.then(n=>{for(let e of n||[])e.status===`rejected`&&a(e.reason);return e().catch(a)})};window.app=window.app||{},window.app.modals=window.app.modals||{},window.app.modals.openApiPreview=function(e,n={onbeforeopen:null,onafteropen:null,onbeforeclose:null,onafterclose:null}){let r=it(e,n);r&&(document.body.appendChild(r),app.modals.open(r))};function it(e,n){if(!e){console.warn(`[apiPreviewModal] missing required collection`);return}let r,i=store({activeTab:`List/Search`,tabEl:null,isLoading:!1}),a={"List/Search":async e=>{let{docsList:n}=await F(async()=>{let{docsList:e}=await import(`./docsList-BAfVNUIM.js`);return{docsList:e}},__vite__mapDeps([0,1,2,3]),import.meta.url);return i.tabEl=n(e)},View:async e=>{let{docsView:n}=await F(async()=>{let{docsView:e}=await import(`./docsView-Be6Uhvcf.js`);return{docsView:e}},__vite__mapDeps([4,1,2]),import.meta.url);return i.tabEl=n(e)}};e.type!=`view`&&(a.Create=async e=>{let{docsCreate:n}=await F(async()=>{let{docsCreate:e}=await import(`./docsCreate-Be3S3y5K.js`);return{docsCreate:e}},__vite__mapDeps([5,1,2]),import.meta.url);return i.tabEl=n(e)},a.Update=async e=>{let{docsUpdate:n}=await F(async()=>{let{docsUpdate:e}=await import(`./docsUpdate-LtD8DbWI.js`);return{docsUpdate:e}},__vite__mapDeps([6,5,1,2]),import.meta.url);return i.tabEl=n(e)},a.Delete=async e=>{let{docsDelete:n}=await F(async()=>{let{docsDelete:e}=await import(`./docsDelete-CybOn5jy.js`);return{docsDelete:e}},[],import.meta.url);return i.tabEl=n(e)},a.Realtime=async e=>{let{docsRealtime:n}=await F(async()=>{let{docsRealtime:e}=await import(`./docsRealtime-PMESvmJN.js`);return{docsRealtime:e}},[],import.meta.url);return i.tabEl=n(e)},a.Batch=async e=>{let{docsBatch:n}=await F(async()=>{let{docsBatch:e}=await import(`./docsBatch-DNJl1NTn.js`);return{docsBatch:e}},[],import.meta.url);return i.tabEl=n(e)}),e.type==`auth`&&(a[``]=null,a[`List auth methods`]=async e=>{let{docsListAuthMethods:n}=await F(async()=>{let{docsListAuthMethods:e}=await import(`./docsListAuthMethods-9feSopQX.js`);return{docsListAuthMethods:e}},__vite__mapDeps([7,2]),import.meta.url);return i.tabEl=n(e)},a[`Auth with password`]=e.passwordAuth?.enabled?async e=>{let{docsAuthWithPassword:n}=await F(async()=>{let{docsAuthWithPassword:e}=await import(`./docsAuthWithPassword-DEWj8Jyn.js`);return{docsAuthWithPassword:e}},__vite__mapDeps([8,1,2]),import.meta.url);return i.tabEl=n(e)}:null,e.name!=`_superusers`&&(a[`Auth with OAuth2`]=e.oauth2?.enabled?async e=>{let{docsAuthWithOAuth2:n}=await F(async()=>{let{docsAuthWithOAuth2:e}=await import(`./docsAuthWithOAuth2-DUIE4EoY.js`);return{docsAuthWithOAuth2:e}},__vite__mapDeps([9,1,2]),import.meta.url);return i.tabEl=n(e)}:null),a[`Auth with OTP`]=e.otp?.enabled?async e=>{let{docsAuthWithOTP:n}=await F(async()=>{let{docsAuthWithOTP:e}=await import(`./docsAuthWithOTP-B7z2VJzp.js`);return{docsAuthWithOTP:e}},__vite__mapDeps([10,1,2]),import.meta.url);return i.tabEl=n(e)}:null,a[`Auth refresh`]=async e=>{let{docsAuthRefresh:n}=await F(async()=>{let{docsAuthRefresh:e}=await import(`./docsAuthRefresh-UjveHHwo.js`);return{docsAuthRefresh:e}},__vite__mapDeps([11,1,2]),import.meta.url);return i.tabEl=n(e)},e.name!=`_superusers`&&(a.Verification=async e=>{let{docsVerification:n}=await F(async()=>{let{docsVerification:e}=await import(`./docsVerification-B_Nb90xU.js`);return{docsVerification:e}},[],import.meta.url);return i.tabEl=n(e)}),a[`Password reset`]=async e=>{let{docsPasswordReset:n}=await F(async()=>{let{docsPasswordReset:e}=await import(`./docsPasswordReset-vLO_ZWrq.js`);return{docsPasswordReset:e}},[],import.meta.url);return i.tabEl=n(e)},a[`Email change`]=async e=>{let{docsEmailChange:n}=await F(async()=>{let{docsEmailChange:e}=await import(`./docsEmailChange-B---6FKV.js`);return{docsEmailChange:e}},[],import.meta.url);return i.tabEl=n(e)});let o=[watch(()=>i.activeTab,async()=>{i.isLoading=!0,await a[i.activeTab]?.(e),i.isLoading=!1})];return r=t.div({pbEvent:`apiPreviewModal`,className:`modal api-preview-modal`,onbeforeopen:e=>n.onbeforeopen?.(e),onafteropen:e=>{n.onafteropen?.(e)},onbeforeclose:e=>n.onbeforeclose?.(e),onafterclose:e=>{n.onafterclose?.(e),o.forEach(e=>e?.unwatch()),e?.remove()},onmount:e=>{},onunmount:e=>{o.forEach(e=>e?.unwatch())}},t.div({className:`modal-content`},t.aside({className:`api-preview-sidebar`},t.nav({className:`api-preview-nav`},()=>{let e=[];for(let n in a){if(!n){e.push(t.hr());continue}let r=!a[n];e.push(t.button({type:`button`,className:()=>`nav-item ${i.activeTab==n?`active`:``}`,disabled:r,ariaDescription:app.attrs.tooltip(()=>r?`Not enabled for the collection`:``,`left`),onclick:()=>{r||(i.activeTab=n)}},n))}return e})),t.div({className:()=>`api-preview-content ${i.isLoading?`faded`:``}`,scrollTop:()=>i.activeTab?0:null},t.header({className:`api-preview-content-header`},t.h6(null,()=>i.activeTab+` (${e.name})`),t.button({type:`button`,className:()=>`btn sm circle transparent secondary m-l-auto preview-close-btn ${i.isLoading?`loading`:``}`,title:`Close`,onclick:()=>app.modals.close(r)},t.i({className:`ri-close-line`,ariaHidden:!0}))),()=>i.tabEl))),r}window.app=window.app||{},window.app.modals=window.app.modals||{},window.app.modals.openMailTest=function(e=``,n=``){let r=at(e,n);document.body.appendChild(r),app.modals.open(r)};function at(e=``,n=``){let r=`mail_test_`+app.utils.randomString(),i=`pbLastTestEmail`,a=`email_test_request`,o=[{label:`Verification`,value:`verification`},{label:`Password reset`,value:`password-reset`},{label:`Confirm email change`,value:`email-change`},{label:`OTP`,value:`otp`},{label:`Login alert`,value:`login-alert`}],s=store({email:localStorage.getItem(i)||app.store.superuser?.email||``,template:n||o[0].value,isSending:!1,collectionIdOrName:e,get isAuthCollectionsLoading(){return app.store.isCollectionsLoading},get authCollections(){return app.utils.sortedCollections(app.store.collections.filter(e=>e.type==`auth`))},get canSubmit(){return!!s.email&&!!s.template&&!!s.collectionIdOrName}}),c;async function l(){if(!(s.isSending||!s.canSubmit)){s.isSending=!0,clearTimeout(c),c=setTimeout(()=>{s.isSending=!1,app.pb.cancelRequest(a),app.modals.close(),app.toasts.error(`Test email send timeout.`)},15e3);try{s.email!=app.pb.authStore.record?.email&&localStorage.setItem(i,s.email),await app.pb.settings.testEmail(s.collectionIdOrName,s.email,s.template,{requestKey:a}),app.toasts.success(`Successfully sent test email.`),app.modals.close()}catch(e){app.checkApiError(e)}s.isSending=!1,clearTimeout(c)}}let u=[];return t.div({className:`modal popup sm`,onbeforeopen:e=>{u.push(watch(()=>s.isAuthCollectionsLoading,e=>{!e&&!s.collectionIdOrName&&(s.collectionIdOrName=s.authCollections[0]?.id||``)}))},onafterclose:e=>{clearTimeout(c),e?.remove()},onunmount:()=>{clearTimeout(c),u.forEach(e=>e?.unwatch())}},t.header({className:`modal-header`},t.h5({className:`m-auto`},`Send test email`)),t.form({id:r,className:`modal-content mail-settings-test-form`,onsubmit:e=>{e.preventDefault(),l()}},t.div({className:`grid`},t.div({className:`col-lg-12`},()=>o.map((e,n)=>t.field({className:()=>`field ${n>0?`m-t-10`:``}`},t.input({type:`radio`,id:r+`.template.`+e.value,name:`template`,checked:()=>s.template==e.value,onchange:n=>s.template=e.value}),t.label({htmlFor:r+`.template.`+e.value},e.label||e.value)))),()=>{if(!e)return t.div({className:`col-lg-12`},t.div({className:`field`},t.label({htmlFor:r+`.collection`},`Auth collection`),app.components.select({id:r+`.collection`,name:`collection`,required:!0,placeholder:()=>s.isAuthCollectionsLoading?`Loading auth collections...`:`Select auth collection`,options:()=>s.authCollections.map(e=>({value:e.id,label:e.name})),value:()=>s.collectionIdOrName||``,onchange:e=>{s.collectionIdOrName=e?.[0]?.value}})))},t.div({className:`col-lg-12`},t.div({className:`field`},t.label({htmlFor:r+`.email`},`To email address`),t.input({id:r+`.email`,name:`email`,type:`email`,required:!0,value:()=>s.email||``,oninput:e=>s.email=e.target.value}))))),t.footer({className:`modal-footer`},t.button({type:`button`,className:`btn transparent m-r-auto`,onclick:()=>app.modals.close(),disabled:()=>s.isSending},t.span({className:`txt`},`Close`)),t.button({"html-form":r,type:`submit`,className:()=>`btn expanded ${s.isSending?`loading`:``}`,disabled:()=>s.isSending||!s.canSubmit},t.i({className:`ri-mail-send-line`,ariaHidden:!0}),t.span({className:`txt`},`Send`))))}function ot(e={}){let n=store({rid:void 0,collectionA:null,collectionB:null,deleteMissing:!1,className:``}),r=app.utils.extendStore(n,e),i=store({hasAnyChange:!1,get isDeleteDiff(){return!n.collectionB?.id&&!n.collectionB?.name},get isCreateDiff(){return!i.isDeleteDiff&&!n.collectionA?.id},get hasAnyChange(){return app.utils.hasCollectionChanges(n.collectionA,n.collectionB,n.deleteMissing)},get fieldsListA(){return Array.isArray(n.collectionA?.fields)?n.collectionA?.fields:[]},get fieldsListB(){let e=Array.isArray(n.collectionB?.fields)?n.collectionB?.fields:[];return n.deleteMissing||(e=e.concat(n.collectionA?.fields?.filter(n=>!e.find(e=>n.id==e.id))||[])),e},get mainModelProps(){return app.utils.mergeUnique(Object.keys(n.collectionA||{}),Object.keys(n.collectionB||{})).filter(e=>![`fields`,`created`,`updated`].includes(e))},get removedFields(){return i.fieldsListA.filter(e=>!i.fieldsListB.find(n=>e.id==n.id))},get sharedFields(){return i.fieldsListB.filter(e=>i.fieldsListA.find(n=>n.id==e.id))},get addedFields(){return i.fieldsListB.filter(e=>!i.fieldsListA.find(n=>n.id==e.id))}});function a(e){return e===void 0?``:app.utils.isObject(e)?JSON.stringify(e,null,4):``+e}function o(e,n){return e===n?!1:JSON.stringify(e)!=JSON.stringify(n)}function s(e,n){return(e||[]).find(e=>e.id==n)}return t.div({rid:n.rid,pbEvent:`collectionsDiffTableWrapper`,className:()=>`collections-diff-table-wrapper ${n.className}`,onunmount:()=>{r.forEach(e=>e?.unwatch())}},t.div({className:`collections-diff-table-title`},()=>n.collectionA?.id?n.collectionB?.id?[t.span({hidden:()=>!i.hasAnyChange,className:`label import-change-label warning`,textContent:`Changed`}),t.div({className:`inline-flex gap-5`},()=>{if(n.collectionA?.name!=n.collectionB?.name)return[t.strong({className:`txt-strikethrough txt-hint`,textContent:n.collectionA?.name}),t.i({className:`ri-arrow-right-line txt-sm`,ariaHidden:!0})]},t.strong({textContent:()=>n.collectionB?.name}))]:[t.span({className:`label import-change-label danger`,textContent:`Deleted`}),t.strong({textContent:()=>n.collectionA?.name})]:[t.span({className:`label import-change-label success`,textContent:`Added`}),t.strong({textContent:()=>n.collectionB?.name})]),t.table({className:`collections-diff-table`},t.thead(null,t.tr(null,t.th({className:`min-width`},`Props`),t.th({width:`40%`},`Old`),t.th({width:`40%`},`New`))),t.tbody(null,()=>i.mainModelProps.map(e=>{let r=o(n.collectionA?.[e],n.collectionB?.[e]);return t.tr({className:r?`txt-primary`:``},t.td({className:`min-width`},e),t.td({className:()=>i.isCreateDiff?`changed-non-col`:r?`changed-old-col`:``},t.pre({className:`txt diff-value`},a(n.collectionA?.[e]))),t.td({className:()=>i.isDeleteDiff?`changed-non-col`:r?`changed-new-col`:``},t.pre({className:`txt diff-value`},a(n.collectionB?.[e]))))}),()=>{if(!n.deleteMissing&&!i.isDeleteDiff)return;let e=[];for(let n of i.removedFields){e.push(t.tr(null,t.th({className:`min-width`,colSpan:3},t.span({className:`txt`},`field: `,n.name),t.span({className:`label danger m-l-5`},`Deleted - `,t.small(null,`All stored data related to '${n.name}' will be deleted!`)))));for(let r in n){let i=n[r];e.push(t.tr(null,t.td({className:`min-width field-key-col`},r),t.td({className:`changed-old-col`},t.pre({className:`txt`},a(i))),t.td({className:`changed-none-col`})))}}return e},()=>{let e=[];for(let n of i.sharedFields){let r=s(i.fieldsListA,n.id),c=o(r,s(i.fieldsListB,n.id));e.push(t.tr(null,t.th({className:`min-width`,colSpan:3},t.span({className:`txt`},`field: `,n.name),t.span({className:`label warning m-l-5 ${c?``:`hidden`}`,textContent:`Changed`}))));for(let i in n){let s=n[i],c=o(r?.[i],s);e.push(t.tr({className:c?`txt-primary`:``},t.td({className:`min-width field-key-col`},i),t.td({className:c?`changed-old-col`:``},t.pre({className:`txt`},a(r?.[i]))),t.td({className:c?`changed-new-col`:``},t.pre({className:`txt`},a(s)))))}}return e},()=>{let e=[];for(let n of i.addedFields){e.push(t.tr(null,t.th({className:`min-width`,colSpan:3},t.span({className:`txt`},`field: `,n.name),t.span({className:`label success m-l-5`},`Added`))));for(let r in n){let i=n[r];e.push(t.tr({className:`txt-primary`},t.td({className:`min-width field-key-col`},r),t.td({className:`changed-none-col`}),t.td({className:`changed-new-col`},t.pre({className:`txt`},a(i)))))}}return e})))}window.app=window.app||{},window.app.modals=window.app.modals||{},window.app.modals.openImportCollectionsReview=function(e,n,r={deleteMissing:!1,onsubmit:null}){let i=st(e,n,r);i&&(document.body.appendChild(i),app.modals.open(i))};function st(e,n,r){let i,a=store({deleteMissing:!1,onsubmit:function(e){}}),o=app.utils.extendStore(a,r),s=store({isImporting:!1,pairs:[]});function c(){let r=[];for(let i of e){let e=n.find(e=>e.id==i.id);(a.deleteMissing&&!e?.id||e?.id&&app.utils.hasCollectionChanges(i,e,a.deleteMissing))&&r.push({old:i,new:e})}for(let i of n){let n=e.find(e=>e.id==i.id);n?.id||r.push({old:n,new:i})}s.pairs=r}function l(){let r=[];if(a.deleteMissing)for(let i of e){let e=n.find(e=>e.id==i.id);if(!e)r.push(i.name+`.*`);else{let n=Array.isArray(i.fields)?i.fields:[];for(let a of n)e.fields.find(e=>e.id==a.id)||r.push(`${i.name}.${a.name} (${a.id})`)}}r.length?app.modals.confirm([t.h6(null,`Do you really want to delete the following collection fields and their related records data:`),t.ul(null,()=>r.map(e=>t.li(null,e)))],()=>u()):u()}async function u(){if(!s.isImporting){s.isImporting=!0;try{await app.pb.collections.import(n,a.deleteMissing),await app.store.loadCollections(),a.onsubmit?.(JSON.parse(JSON.stringify(app.store.collections))),app.toasts.success(`Successfully imported collections configuration.`)}catch(e){app.checkApiError(e)}s.isImporting=!1,app.modals.close(i)}}return i=t.div({pbEvent:`importCollectionsReviewModal`,className:`modal popup full import-collections-review-modal`,onbeforeopen:()=>{c()},onbeforeclose:()=>!s.isImporting,onafterclose:e=>{e?.remove()},onunmount:()=>{o.forEach(e=>e?.unwatch())}},t.header({className:`modal-header`},t.h5(null,`Side-by-side diff`)),t.div({className:`modal-content`},()=>s.pairs.map(e=>ot({collectionA:e.old,collectionB:e.new,deleteMissing:a.deleteMissing}))),t.footer({className:`modal-footer`},t.button({type:`button`,className:`btn transparent m-r-auto`,disabled:()=>s.isImporting,onclick:()=>app.modals.close(i)},t.span({className:`txt`},`Close`)),t.button({type:`button`,className:()=>`btn expanded ${s.isImporting?`loading`:``}`,disabled:()=>s.isImporting,onclick:()=>l()},t.span({className:`txt`},`Confirm and import`)))),i}window.app=window.app||{},window.app.components=window.app.components||{},window.app.components.recordSummary=function(e,n=null){let r=store({get collection(){return app.store.collections.find(n=>n.id==e.collectionId||n.name==e.collectionName)},get presentableFields(){if(!r.collection?.id)return[];let e=r.collection.fields.filter(e=>e.presentable).sort((e,n)=>{let r=app.fieldTypes[e.type].summaryPriority||0,i=app.fieldTypes[n.type].summaryPriority||0;return r>i?1:re.name==n);if(i){e.push(i);break}}return e}});return t.div({className:`label record-summary`},t.i({ariaHidden:!0,className:`ri-eye-line link-hint record-preview-icon`,onclick:e=>{e.stopImmediatePropagation(),e.preventDefault()},onmouseenter:n=>{lt(n.target,e,100)},onmouseleave:e=>{ct(e.target,100)},onunmount:e=>{ct(e,0)}}),()=>{let i=[];function a(e){(e==null||e==``)&&(e=t.span({className:`missing-value`})),i.push(e)}for(let i of r.presentableFields){let r=app.fieldTypes[i.type]?.view;if(r)a(r({short:!0,get record(){return e},get field(){return i},get meta(){return n}}));else{let n=app.utils.toArray(e[i.name]).splice(0,3);for(let e of n)a(e)}}return i})};function ct(e,n=150){if(e){if(clearTimeout(e._summaryDropdownTimeoutId),n<=0){e?._summaryDropdown?.hidePopover?.();return}e._summaryDropdownTimeoutId=setTimeout(()=>{e?._summaryDropdown?.hidePopover?.()},n)}}function lt(e,n,r=150){if(e){if(clearTimeout(e._summaryDropdownTimeoutId),r<=0){ut(e,n);return}e._summaryDropdownTimeoutId=setTimeout(()=>{ut(e,n)},r)}}var ut=function(e,n){e&&(e._summaryDropdown||(e._summaryDropdown=t.div({className:`dropdown record-summary-dropdown`,popover:`manual`,onclick:e=>{e.stopImmediatePropagation(),e.preventDefault()}},t.div({className:`record-header`},t.a({className:`link-hint txt-bold m-r-auto`,target:`_blank`,href:`#/collections?collection=${n.collectionName}&record=${n.id}`,onclick:e=>{e.stopImmediatePropagation()}},t.span({className:`txt`},`Edit relation record`),t.i({className:`ri-external-link-line`,ariaHidden:!0})),t.button({type:`button`,className:`link-hint`,title:`Close`,onclick:()=>ct(e,0)},t.i({className:`ri-close-line`,ariaHidden:!0}))),t.hr(),t.pre({className:`record-json`},()=>{let e=app.store.collections.find(e=>e.id==n.collectionId||e.name==n.collectionName)?.fields||[];if(!e.length)return;let r={collectionId:n.collectionId,collectionName:n.collectionName};for(let i of e)r[i.name]=n[i.name];return JSON.stringify(app.utils.truncateObject(r,27),null,2)})),e.appendChild(e._summaryDropdown)),e._summaryDropdown?.showPopover({source:e}))};window.app=window.app||{},window.app.components=window.app.components||{},window.app.components.recordsSearchbar=function(e={}){let n=store({rid:void 0,id:void 0,hidden:void 0,inert:void 0,disabled:void 0,value:``,className:``,collection:void 0,onsubmit:e=>{}}),r=app.utils.extendStore(n,e);return t.div({rid:n.rid,id:()=>n.id,hidden:()=>n.hidden,inert:()=>n.inert,className:()=>`full-width records-searchbar-wrapper ${n.className}`,onunmount:()=>{r.forEach(e=>e?.unwatch())}},app.components.searchbar({placeholder:()=>!n.disabled&&!n.collection?.id?`Loading...`:`Search term or filter...`,historyKey:()=>`pbRecordsSearchHistory_`+n.collection?.id,disabled:()=>n.disabled||!n.collection,value:()=>n.value,autocomplete:e=>app.utils.collectionAutocompleteKeys(n.collection,e,{requestKeys:!1,collectionJoinKeys:!1}),onsubmit:n.onsubmit}))},window.app=window.app||{},window.app.components=window.app.components||{};var dt={max:10,pending:new Set,processing:new Set};function ft(e){return dt.pending.add(e),dt.processing.size<=dt.max&&pt(),()=>{dt.pending.delete(e),dt.processing.delete(e),dt.processing.sizen.id,hidden:()=>n.hidden,inert:()=>n.inert,type:`button`,draggable:!1,className:()=>`thumb ${n.extraClasses} ${i.isPreviewLoading?`loading`:``}`,title:()=>(i.hasPreview?`Preview`:`Download`)+` `+n.filename,onclick:async e=>{e.stopPropagation();async function r(){let e=await app.getFileToken(n.record.collectionId);return app.pb.files.getURL(n.record,n.filename,{token:e})}if(i.hasPreview)app.modals.openFilePreview(r);else{let e=await r();app.utils.download(e,n.filename)}},onunmount:()=>{r.forEach(e=>e?.unwatch())}},()=>{if(i.fileType==`image`){let e=t.img({draggable:!1,alt:()=>`Thumb of `+n.filename,src:()=>i.previewURL,onerror:n=>{console.warn(`[recordFileThumb] load err:`,n),i.isPreviewLoading=!1,e?._semaphoreRelease?.()},onload:()=>{i.isPreviewLoading=!1,e?._semaphoreRelease?.()},onmount:e=>{i.isPreviewLoading=!0,e._semaphoreRelease=ft(async()=>{try{i.previewToken=await app.getFileToken(n.record.collectionId),i.previewURL=app.pb.files.getURL(n.record,n.filename,{thumb:`100x100`,token:i.previewToken})}catch(e){console.warn(e)}})},onunmount:e=>{i.isPreviewLoading=!1,e._semaphoreRelease?.()}});return e}return t.i({className:app.utils.fileTypeIcons[i.fileType]||`ri-file-line`,ariaHidden:!0})})},window.app=window.app||{},window.app.modals=window.app.modals||{};var mt=100,ht={btnText:`Insert`,fileTypes:[],onselect:function(e){}},gt=`pbLastRecordFilePickerCollection`,_t=`listFilePickerRecords`;window.app.modals.openRecordFilePicker=function(e={}){e=Object.assign({},ht,e);let n=vt(e);document.body.appendChild(n),app.modals.open(n)};function vt(e=ht){let n,r=`file_picker_`+app.utils.randomString(),i=store({selectedFile:{},records:[],activeCollectionId:``,searchTerm:``,lastRecordsPage:1,lastTotalRecords:0,isLoadingRecords:!1,get collections(){return app.utils.sortedCollections(app.store.collections.filter(e=>e.type==`view`?!1:!!e.fields?.find(e=>e.type===`file`&&!e.protected)))},get activeCollection(){return i.collections.find(e=>e.id==i.activeCollectionId)||i.collections[0]},get activeCollectionFileFields(){return i.activeCollection?.fields?.filter(e=>e.type===`file`&&!e.protected)||[]},get isLoading(){return app.store.isLoadingCollections||i.isLoadingRecords},get canLoadMore(){return!i.isLoadingRecords&&i.lastTotalRecords==mt},get hasAtleastOneFile(){return!!i.records.find(e=>c(e).length>0)}}),a=[];a.push(watch(()=>{i.activeCollectionId?(window.localStorage.setItem(gt,i.activeCollectionId),i.searchTerm=``):i.activeCollectionId=window.localStorage.getItem(gt)})),a.push(watch(()=>[i.activeCollection,i.searchTerm],()=>s(!0)));function o(){app.pb.cancelRequest(_t),i.isLoadingRecords=!1,i.records=[],i.lastTotalRecords=0,i.lastRecordsPage=1,i.selectedFile={}}async function s(e=!1){if(!i.activeCollection){o();return}e&&o(),i.isLoadingRecords=!0;try{let n=e?1:i.lastRecordsPage+1,r=app.utils.getAllCollectionIdentifiers(i.activeCollection),a=app.utils.normalizeSearchFilter(i.searchTerm,r)||``;a&&(a+=` && `),a+=`(`+i.activeCollectionFileFields.map(e=>`${e.name}:length>0`).join(`||`)+`)`;let o=await app.pb.collection(i.activeCollection.id).getList(n,mt,{requestKey:_t,filter:a,skipTotal:1,sort:i.activeCollection.type==`view`?``:`-@rowid`});i.lastRecordsPage=o.page,i.lastTotalRecords=o.items.length,i.records=app.utils.filterDuplicatesByKey(i.records.concat(o.items)),i.isLoadingRecords=!1}catch(e){e.isAbort||(i.isLoadingRecords=!1,app.checkApiError(e))}}function c(n){let r=[];for(let a of i.activeCollectionFileFields){let i=app.utils.toArray(n[a.name]);for(let n of i)(app.utils.isEmpty(e.fileTypes)||e.fileTypes?.includes(app.utils.getFileType(n)))&&r.push(n)}return r}function l(e,n){i.selectedFile={record:e,name:n,thumb:``}}function u(e,n){return i.selectedFile?.name==n&&i.selectedFile?.record?.id==e?.id}let d={"record:create":e=>{e.detail.collectionId==i.activeCollection?.id&&(i.selectedFile?.record?.id==e.detail.id&&(i.selectedFile.record=e.detail),s(!0))},"record:delete":e=>{e.detail.collectionId!=i.activeCollection?.id&&e.detail.collectionName!=i.activeCollection?.name||(i.selectedFile?.record?.id==e.detail.id&&(i.selectedFile={}),s(!0))}};return n=t.div({className:`modal popup record-file-picker-modal`,onafterclose:e=>{e?.remove()},onmount:e=>{for(let e in d)document.addEventListener(e,d[e])},onunmount:e=>{a.forEach(e=>e?.unwatch());for(let e in d)document.removeEventListener(e,d[e])}},t.header({className:`modal-header`},t.button({className:()=>`btn primary outline record-file-picker-collection-select-btn ${app.store.isLoadingCollections?`loading`:``}`,disabled:()=>app.store.isLoadingCollections,"html-popovertarget":`collections_dropdown`+r},t.span({className:`txt-lg collection-name m-r-auto`},()=>i.activeCollection?.name||`Select collection`),t.i({className:`ri-arrow-drop-down-line`,ariaHidden:!0})),t.div({id:`collections_dropdown`+r,className:`dropdown`,popover:`hint`},()=>i.collections.map(e=>t.button({type:`button`,className:()=>`dropdown-item ${i.activeCollectionId==e.id?`active`:``}`,onclick:n=>{i.activeCollectionId=e.id,n.target?.closest(`.dropdown`)?.hidePopover()}},e.name))),app.components.recordsSearchbar({disabled:()=>!i.activeCollection?.id,collection:()=>i.activeCollection,value:()=>i.searchTerm,onsubmit:e=>i.searchTerm=e}),t.button({type:`button`,className:`btn circle transparent`,ariaLabel:app.attrs.tooltip(`Add new record`),onclick:()=>app.modals.openRecordUpsert(i.activeCollection)},t.i({className:`ri-add-line txt-hint`,ariaHidden:!0}))),t.div({className:`modal-content`},t.div({className:`block txt-center`,hidden:()=>i.hasAtleastOneFile||!i.isLoading},t.span({className:`loader`})),t.div({className:`record-file-picker-list`},()=>{let e=[];for(let n of i.records){let r=c(n);for(let i of r)e.push(t.button({rid:n.id+`:`+i,className:()=>`list-item thumb ${u(n,i)?`success`:``}`,ariaDescription:app.attrs.tooltip(i,`bottom`),onclick:()=>l(n,i)},()=>{if(app.utils.hasImageExtension(i))return t.img({loading:`lazy`,src:app.pb.files.getURL(n,i,{thumb:`100x100`}),alt:i});let e=app.utils.getFileType(i);return t.i({className:app.utils.fileTypeIcons[e]||`ri-file-line`,ariaHidden:!0})}))}return e}),t.div({hidden:()=>!i.canLoadMore||!i.hasAtleastOneFile,className:`block txt-center`},t.button({className:()=>`btn secondary expanded-lg m-t-base ${i.isLoadingRecords?`loading`:``}`,disabled:()=>i.isLoadingRecords,onclick:()=>s()},t.span({className:`txt`},`Load more`))),t.div({className:`block txt-center txt-hint p-t-10 p-b-10`,hidden:()=>i.hasAtleastOneFile||i.isLoading},()=>app.utils.isEmpty(e.fileTypes)?t.p(null,`No records with selectable files found.`):t.p(null,`No "${e.fileTypes.join(`", "`)}" files found.`),t.button({type:`button`,className:`btn sm secondary`,textContent:`Clear search`,hidden:()=>!i.searchTerm?.length,onclick:()=>{i.searchTerm=``}}))),t.footer({className:`modal-footer`},t.button({type:`button`,className:`btn transparent m-r-auto`,onclick:()=>app.modals.close(n)},t.span({className:`txt`},`Close`)),()=>{if(!i.selectedFile?.name||!app.utils.hasImageExtension(i.selectedFile.name))return;let e=[{value:``,label:`Original size`},{value:`100x100`,label:`100x100 thumb`}],n=i.activeCollectionFileFields.find(e=>i.selectedFile.record[e.name].includes(i.selectedFile.name)),r=app.utils.toArray(n.thumbs);for(let n of r)e.push({value:n,label:`${n} thumb`});return t.div({className:`record-file-picker-thumb-select`},app.components.select({required:!0,value:i.selectedFile.thumb||``,options:e,onchange:e=>{i.selectedFile.thumb=e?.[0].value}}))},t.button({type:`button`,className:`btn expanded`,disabled:()=>i.isLoading||!i.selectedFile?.name,onclick:()=>{let r=JSON.parse(JSON.stringify(i.selectedFile));if(e.onselect&&e.onselect(r)===!1)return!1;app.modals.close(n)}},t.span({className:`txt`},()=>e.btnText||ht.btnText)))),n}window.app=window.app||{},window.app.modals=window.app.modals||{};var yt=50,bt=100,xt=`listRelationPickerRecords`,St={collection:``,selectedIds:[],maxSelect:1,btnText:`Set selection`,onselect:function(e){}};window.app.modals.openRecordsPicker=function(e={}){e=Object.assign({},St,e);let n=Ct(e);document.body.appendChild(n),app.modals.open(n)};function Ct(e=St){let n,r=store({searchTerm:``,selected:[],preselected:[],isLoadingPreselected:!1,records:[],isLoadingRecords:!1,lastRecordsPage:1,lastRecordsTotal:0,get collection(){let n=e.collection;return typeof e.collection==`object`&&e.collection?.id&&(n=e.collection?.id),app.store.collections.find(e=>e.id==n||e.name==n)},get isLoading(){return r.isLoadingPreselected||r.isLoadingRecords},get canLoadMore(){return!r.isLoadingRecords&&r.lastRecordsTotal==yt}}),i=[watch(()=>[e.collection,e.selectedIds],()=>{o()}),watch(()=>[r.collection,r.searchTerm],()=>{s(!0)})];function a(){setTimeout(()=>app.modals.close(n),0)}async function o(){let n=app.utils.toArray(e.selectedIds),i=e.collection?.id||e.collection;if(!i||!n.length)return;r.isLoadingSelected=!0;let a=[],o=n.slice(),s=[];for(;o.length>0;){let e=[],n=o.splice(0,bt);for(let r of n)e.push(`id="${r}"`);s.push(app.pb.collection(i).getFullList({requestKey:null,filter:e.join(`||`)}))}try{await Promise.all(s).then(e=>{a=a.concat(...e)});let e=[];for(let r of n){let n=a.find(e=>e.id==r);n&&e.push(n)}r.searchTerm.trim()||(r.records=app.utils.filterDuplicatesByKey(e.concat(r.records))),r.selected=e,r.isLoadingSelected=!1}catch(e){e.isAbort||(app.checkApiError(e),r.isLoadingSelected=!1)}}async function s(e=!1){if(r.collection?.id){e&&(c(),r.searchTerm.trim()||(r.records=r.selected.slice())),r.isLoadingRecords=!0;try{let n=e?1:r.lastRecordsPage+1,i=app.utils.getAllCollectionIdentifiers(r.collection),a=app.utils.normalizeSearchFilter(r.searchTerm,i)||``,o=await app.pb.collection(r.collection.id).getList(n,yt,{requestKey:xt,filter:a,skipTotal:1,sort:r.collection.type==`view`?``:`-@rowid`});r.lastRecordsPage=o.page,r.lastRecordsTotal=o.items.length,r.records=app.utils.filterDuplicatesByKey(r.records.concat(o.items)),r.isLoadingRecords=!1}catch(e){e.isAbort||(r.isLoadingRecords=!1,app.checkApiError(e))}}}function c(){app.pb.cancelRequest(xt),r.isLoadingRecords=!1,r.records=[],r.lastTotalRecords=0,r.lastRecordsPage=1}function l(e){e.target.scrollHeight-e.target.clientHeight-e.target.scrollTop<=100&&r.canLoadMore&&s()}function u(n){let i=r.selected.findIndex(e=>e.id==n.id);if(i>=0)r.selected.splice(i,1);else{let i=e.maxSelect||1,a=r.selected.length-i;for(;a>=0;)r.selected.pop(),a--;r.selected.push(n)}}function d(e){return r.selected.findIndex(n=>n.id==e.id)>=0}let f={"record:save":e=>{if(e.detail.collectionId!=r.collection?.id)return;let n=r.selected?.findIndex(n=>n.id==e.detail.id);n>=0&&(r.selected[n]=e.detail),app.utils.pushOrReplaceObject(r.records,e.detail),s(!0)},"record:delete":e=>{e.detail.collectionId!=r.collection?.id&&e.detail.collectionName!=r.collection?.name||(d(e.detail)&&u(e.detail),app.utils.removeByKey(r.records,`id`,e.detail.id),s(!0))}};return n=t.div({className:`modal popup lg records-picker-modal`,onafterclose:e=>{e.remove()},onmount:e=>{for(let e in f)document.addEventListener(e,f[e])},onunmount:e=>{i.forEach(e=>e?.unwatch());for(let e in f)document.removeEventListener(e,f[e])}},t.header({className:`modal-header`},t.h6({className:`collection-name`},()=>r.collection.name),app.components.recordsSearchbar({disabled:()=>!r.collection?.id,collection:()=>r.collection,value:()=>r.searchTerm,onsubmit:e=>r.searchTerm=e}),t.button({type:`button`,className:`btn circle transparent`,ariaLabel:app.attrs.tooltip(`Add new record`),onclick:()=>{app.modals.openRecordUpsert(r.collection)}},t.i({className:`ri-add-line txt-hint`,ariaHidden:!0}))),t.div({className:`modal-content`,hidden:()=>r.isLoadingCollection},t.div({className:`list records-picker-list`,onscroll:l,onresize:l},()=>r.records.map(e=>t.div({tabIndex:0,className:`list-item handle`,onclick:()=>{u(e),document.activeElement?.blur()}},t.div({className:`content`},t.span({className:`state-icon`},t.i({ariaHidden:!0,className:()=>d(e)?`ri-checkbox-circle-fill txt-success`:`ri-checkbox-blank-circle-line txt-disabled`})),()=>app.components.recordSummary(e)),t.div({className:`actions autohide`},t.button({className:`btn sm secondary transparent circle`,ariaLabel:app.attrs.tooltip(`Edit`),onclick:n=>{n.stopPropagation(),app.modals.openRecordUpsert(r.collection,e)}},t.i({className:`ri-pencil-line`,ariaHidden:!0}))))),t.div({className:`list-item`,hidden:()=>!r.isLoading},t.div({className:`skeleton-loader`})),t.div({className:`list-item`,hidden:()=>r.records.length||r.isLoading},t.div({className:`content txt-hint`},t.span({className:`txt`},`No records found.`),t.button({type:`button`,className:`btn sm secondary`,textContent:`Clear search`,hidden:()=>!r.searchTerm.trim().length,onclick:()=>{r.searchTerm=``}})))),t.div({className:`block m-t-base`},t.p({className:`txt-bold`},()=>`Selected (${r.selected.length} of max ${e.maxSelect||1})`),t.span({className:`txt-hint`,hidden:()=>r.selected},`No selected records.`),app.components.sortable({className:`records-picker-selected-list`,data:()=>r.selected,dataItem:(e,n)=>t.div({rid:e,className:`label handle`},()=>app.components.recordSummary(e,[],!0),t.span({className:`link-hint`,title:`Remove`,role:`button`,onclick:()=>u(e)},t.i({className:`ri-close-line`,ariaHidden:!0}))),onchange:(e,n,i)=>{r.selected=e}}))),t.footer({className:`modal-footer`},t.button({type:`button`,className:`btn transparent m-r-auto`,onclick:()=>a()},t.span({className:`txt`},`Close`)),()=>{if(!r.selectedFile?.name||!app.utils.hasImageExtension(r.selectedFile.name))return;let e=[{value:``,label:`Original size`},{value:`100x100`,label:`100x100 thumb`}],n=r.activeCollectionFileFields.find(e=>r.selectedFile.record[e.name].includes(r.selectedFile.name)),i=app.utils.toArray(n.thumbs);for(let n of i)e.push({value:n,label:`${n} thumb`});return t.div({className:`record-file-picker-thumb-select`},app.components.select({required:!0,value:r.selectedFile.thumb||``,options:e,onchange:e=>{r.selectedFile.thumb=e?.[0].value}}))},t.button({type:`button`,className:`btn expanded`,disabled:()=>r.isLoadingCollection,onclick:()=>{let n=JSON.parse(JSON.stringify(r.selected));if(e.onselect&&e.onselect(n)===!1)return!1;a()}},t.span({className:`txt`},e.btnText||St.btnText)))),n}window.app=window.app||{},window.app.modals=window.app.modals||{},window.app.modals.openRecordPreview=function(e,n={onbeforeopen:null,onafteropen:null,onbeforeclose:null,onafterclose:null}){let r=I(e,n);r&&(document.body.appendChild(r),app.modals.open(r))};function wt(e){e.expand&&(e=Object.assign({},e),delete e.expand),app.utils.downloadJSON(e,e.collectionName+`_`+e.id+`.json`)}function Tt(e){e.expand&&(e=Object.assign({},e),delete e.expand),app.utils.copyToClipboard(JSON.stringify(e,null,2)),app.toasts.success(`Record copied to clipboard!`)}function I(e,n){if(!e?.id){app.toasts.error(`Failed to load record.`),console.warn(`[recordPreviewModal] missing required record id field:`,e);return}if(!e.collectionId&&!e.collectionName){app.toasts.error(`Failed to load record.`),console.warn(`[recordPreviewModal] missing required collectionId or collectionName field:`,e);return}let r,i=app.utils.randomString(),a=store({isLoading:!1,record:null,get collection(){return app.store.collections.find(n=>n.id==e.collectionId||n.name==e.collectionName)}});async function o(){a.isLoading=!0;try{a.record=JSON.parse(JSON.stringify(e));let n=[],r=a.collection?.fields?.filter(e=>!e.hidden&&e.type==`relation`)||[];for(let e of r)n.push(e.name);let i=await app.pb.collection(e.collectionName||e.collectionId).getOne(e.id,{requestKey:`record_preview_`+e.id,expand:n.join(`,`)||void 0});Object.assign(a.record,i),a.isLoading=!1}catch(e){e?.isAbort||(a.isLoading=!1,app.checkApiError(e),setTimeout(()=>app.modals.close(r),0))}}return r=t.div({pbEvent:`recordPreviewModal`,className:`modal record-preview-modal`,onbeforeopen:e=>(o(),n.onbeforeopen?.(e)),onafteropen:e=>{n.onafteropen?.(e)},onbeforeclose:e=>n.onbeforeclose?.(e),onafterclose:e=>{n.onafterclose?.(e),e?.remove()}},t.header({className:`modal-header`},t.h6(null,t.strong(null,()=>e?.collectionName||a.collection?.name),` record preview`),t.button({title:`More options`,className:()=>`btn sm circle transparent m-l-auto ${a.isLoading?`loading`:``}`,disabled:()=>a.isLoading,"html-popovertarget":i+`preview-dropdown`},t.i({className:`ri-more-line`,ariaHidden:!0})),t.div({id:i+`preview-dropdown`,className:`dropdown`,popover:`auto`},e=>t.button({className:`dropdown-item`,onclick:()=>{Tt(a.record),e.hidePopover()}},t.i({className:`ri-braces-line`,ariaHidden:!0}),t.span({className:`txt`},`Copy JSON`)))),t.div({className:`modal-content`},t.table({pbEvent:`recordPreviewTable`,className:`record-preview-table responsive-table`},t.tbody(null,()=>(a.collection?.fields?.filter(e=>e.type!=`password`)||[]).map(e=>t.tr(null,t.th({className:()=>`min-width p-r-0 col-field-name-${e.name}`},e.name),t.td({className:()=>`col-field-name-${e.name}`},()=>app.fieldTypes[e.type]?.view?app.fieldTypes[e.type].view({short:!1,get record(){return a.record},get field(){return e}}):app.utils.displayValue(a.record[e.name],1e3))))))),t.footer({className:`modal-footer`},t.button({type:`button`,className:`btn transparent m-r-auto`,onclick:()=>app.modals.close(r)},t.span({className:`txt`},`Close`)),t.button({type:`button`,className:()=>`btn ${a.isLoading?`loading`:``}`,disabled:()=>a.isLoading,onclick:()=>wt(a.record)},t.i({className:`ri-download-line`,ariaHidden:!0}),t.span({className:`txt`},`Download JSON`)))),r}window.app=window.app||{},window.app.modals=window.app.modals||{},window.app.modals.openRecordImpersontate=function(e){let n=R(e);document.body.appendChild(n),app.modals.open(n)};function R(e){let n=`impersonate_`+app.utils.randomString(),r=store({isLoading:!1,token:``,duration:0,get collection(){return app.store.collections.find(n=>n.id==e.collectionId||n.name==e.collectionName)}}),i=app.utils.getApiExampleURL();async function a(){if(!r.isLoading){r.isLoading=!0;try{r.token=(await app.pb.collection(r.collection.name).impersonate(e.id,r.duration)).authStore.token}catch(e){app.checkApiError(e)}r.isLoading=!1}}function o(){r.token=``,r.duration=0}return t.div({className:`modal popup record-impersonate-auth-modal`,onbeforeclose:()=>!r.isLoading,onafterclose:e=>{e?.remove()}},t.header({className:`modal-header`},t.h6(null,`Generate nonrenewable auth token for `,t.strong(null,()=>e.email||e.id))),t.div({className:`modal-content`},t.form({id:n+`_form`,hidden:()=>r.token,className:`block`,onsubmit:e=>{e.preventDefault(),a()}},t.div({className:`field`},t.label({htmlFor:n+`_duration`},`Token duration (in seconds)`),t.input({id:n+`_duration`,type:`number`,name:`duration`,min:0,step:1,placeholder:()=>`Default to the collection settings (${r.collection?.authToken?.duration||0}s)`,value:e=>r.duration||``,oninput:e=>r.duration=parseInt(e.target.value,10)}))),t.div({hidden:()=>!r.token,className:`alert success impersonate-success`},t.strong(null,()=>r.token),` `,app.components.copyButton(()=>r.token)),app.components.codeBlockTabs({hidden:()=>!r.token,className:`sdk-examples m-t-base`,tabs:[{title:`JS SDK`,language:`js`,value:` import PocketBase from 'pocketbase'; const pb = new PocketBase('${i}'); diff --git a/ui/dist/index.html b/ui/dist/index.html index b5eb2cf5..c277dfba 100644 --- a/ui/dist/index.html +++ b/ui/dist/index.html @@ -13,7 +13,7 @@ - + diff --git a/ui/src/records/recordPreviewModal.js b/ui/src/records/recordPreviewModal.js index 2e4c7909..d0c9fa90 100644 --- a/ui/src/records/recordPreviewModal.js +++ b/ui/src/records/recordPreviewModal.js @@ -54,6 +54,18 @@ function copyJSON(record) { } function recordPreviewModal(rawRecord, modalSettings) { + if (!rawRecord?.id) { + app.toasts.error("Failed to load record."); + console.warn("[recordPreviewModal] missing required record id field:", rawRecord); + return; + } + + if (!rawRecord.collectionId && !rawRecord.collectionName) { + app.toasts.error("Failed to load record."); + console.warn("[recordPreviewModal] missing required collectionId or collectionName field:", rawRecord); + return; + } + let modal; const uniqueId = app.utils.randomString(); @@ -69,39 +81,31 @@ function recordPreviewModal(rawRecord, modalSettings) { }); async function loadRecord() { - if (!rawRecord?.id) { - app.toasts.error("Failed to load record."); - setTimeout(() => app.modals.close(modal), 0); - console.warn("[recordPreviewModal] missing required record id field:", rawRecord); - return; - } - - if (!rawRecord.collectionId && !rawRecord.collectionName) { - app.toasts.error("Failed to load record."); - setTimeout(() => app.modals.close(modal), 0); - console.warn("[recordPreviewModal] missing required collectionId or collectionName field:", rawRecord); - return; - } - data.isLoading = true; try { - // eagerly expand first level presentable relations (if any and the collections are loaded) + // preload to minimize content jumps + data.record = JSON.parse(JSON.stringify(rawRecord)); + + // eagerly expand first level relations (if any and the collections are loaded) let relExpands = []; const presentableRelationFields = data.collection?.fields?.filter( - (f) => !f.hidden && f.presentable && f.type == "relation", + (f) => !f.hidden && f.type == "relation", ) || []; for (let field of presentableRelationFields) { relExpands.push(field.name); } - data.record = await app.pb - .collection(rawRecord.collectionId || rawRecord.collectionName) + const record = await app.pb + .collection(rawRecord.collectionName || rawRecord.collectionId) .getOne(rawRecord.id, { requestKey: "record_preview_" + rawRecord.id, expand: relExpands.join(",") || undefined, }); + // populate with an up-to-date fields + Object.assign(data.record, record); + data.isLoading = false; } catch (err) { if (!err?.isAbort) { @@ -130,10 +134,6 @@ function recordPreviewModal(rawRecord, modalSettings) { modalSettings.onafterclose?.(el); el?.remove(); }, - onmount: (el) => { - }, - onunmount: (el) => { - }, }, t.header( { className: "modal-header" }, @@ -145,45 +145,32 @@ function recordPreviewModal(rawRecord, modalSettings) { t.button( { title: "More options", - className: "btn sm circle transparent m-l-auto", + className: () => `btn sm circle transparent m-l-auto ${data.isLoading ? "loading" : ""}`, + disabled: () => data.isLoading, "html-popovertarget": uniqueId + "preview-dropdown", }, t.i({ className: "ri-more-line", ariaHidden: true }), ), - t.div({ id: uniqueId + "preview-dropdown", className: "dropdown", popover: "auto" }, (el) => { - return t.button( - { - className: "dropdown-item", - onclick: () => { - copyJSON(data.record); - el.hidePopover(); + t.div( + { id: uniqueId + "preview-dropdown", className: "dropdown", popover: "auto" }, + (el) => { + return t.button( + { + className: "dropdown-item", + onclick: () => { + copyJSON(data.record); + el.hidePopover(); + }, }, - }, - t.i({ className: "ri-braces-line", ariaHidden: true }), - t.span({ className: "txt" }, "Copy JSON"), - ); - }), + t.i({ className: "ri-braces-line", ariaHidden: true }), + t.span({ className: "txt" }, "Copy JSON"), + ); + }, + ), ), - t.div({ className: "modal-content" }, () => { - // loader - if (data.isLoading || !data.record?.id || !data.collection?.id) { - return t.table( - null, - t.tbody(null, () => { - const totalRows = data.collection?.fields?.filter((f) => f.type != "password").length || 1; - const rows = []; - - for (let i = 0; i < totalRows; i++) { - rows.push(t.tr(null, t.td(null, t.span({ className: "skeleton-loader" })))); - } - - return rows; - }), - ); - } - - // attrs - return t.table( + t.div( + { className: "modal-content" }, + t.table( { pbEvent: "recordPreviewTable", className: "record-preview-table responsive-table", @@ -219,8 +206,8 @@ function recordPreviewModal(rawRecord, modalSettings) { ); }); }), - ); - }), + ), + ), t.footer( { className: "modal-footer" }, t.button( @@ -234,7 +221,8 @@ function recordPreviewModal(rawRecord, modalSettings) { t.button( { type: "button", - className: "btn", + className: () => `btn ${data.isLoading ? "loading" : ""}`, + disabled: () => data.isLoading, onclick: () => downloadJSON(data.record), }, t.i({ className: "ri-download-line", ariaHidden: true }),