ppbase 0.2.1__tar.gz → 0.2.3__tar.gz
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.
- {ppbase-0.2.1 → ppbase-0.2.3}/PKG-INFO +1 -1
- ppbase-0.2.3/ppbase/__init__.py +41 -0
- ppbase-0.2.1/ppbase/admin/dist/assets/_id_-FhBtVpIr.js → ppbase-0.2.3/ppbase/admin/dist/assets/_id_-D_FQrjti.js +3 -3
- ppbase-0.2.1/ppbase/admin/dist/assets/arrow-right-oDCr_rj8.js → ppbase-0.2.3/ppbase/admin/dist/assets/arrow-right-CTJRvVop.js +1 -1
- ppbase-0.2.1/ppbase/admin/dist/assets/badge-DrRXUb2i.js → ppbase-0.2.3/ppbase/admin/dist/assets/badge-Ge7Vok1k.js +1 -1
- ppbase-0.2.1/ppbase/admin/dist/assets/breadcrumb-CRswEvYD.js → ppbase-0.2.3/ppbase/admin/dist/assets/breadcrumb-DHPmrgya.js +1 -1
- ppbase-0.2.1/ppbase/admin/dist/assets/button-BTb_K7ly.js → ppbase-0.2.3/ppbase/admin/dist/assets/button-B7j1u3OP.js +1 -1
- ppbase-0.2.1/ppbase/admin/dist/assets/check-B5gBbN7b.js → ppbase-0.2.3/ppbase/admin/dist/assets/check-ojOtQs1Z.js +1 -1
- ppbase-0.2.1/ppbase/admin/dist/assets/checkbox-Bzr8Mz_N.js → ppbase-0.2.3/ppbase/admin/dist/assets/checkbox-Bhzc1DBg.js +1 -1
- ppbase-0.2.1/ppbase/admin/dist/assets/chevron-left-CCM-Ctmg.js → ppbase-0.2.3/ppbase/admin/dist/assets/chevron-left-CrmIArth.js +1 -1
- ppbase-0.2.1/ppbase/admin/dist/assets/collection-editor-DEyrDfRW.js → ppbase-0.2.3/ppbase/admin/dist/assets/collection-editor-yCbBYzYS.js +1 -1
- ppbase-0.2.3/ppbase/admin/dist/assets/dashboard-D1l_FGZ9.js +11 -0
- ppbase-0.2.1/ppbase/admin/dist/assets/empty-state-CcADzW37.js → ppbase-0.2.3/ppbase/admin/dist/assets/empty-state-VIN2ShUA.js +1 -1
- ppbase-0.2.1/ppbase/admin/dist/assets/index-CBybCNw9.js → ppbase-0.2.3/ppbase/admin/dist/assets/index-BWzNXVt7.js +2 -2
- ppbase-0.2.1/ppbase/admin/dist/assets/index-dilaKgIE.js → ppbase-0.2.3/ppbase/admin/dist/assets/index-DNYtHn84.js +1 -1
- ppbase-0.2.1/ppbase/admin/dist/assets/index-CQBLo7m8.js → ppbase-0.2.3/ppbase/admin/dist/assets/index-Dyazd57h.js +1 -1
- ppbase-0.2.1/ppbase/admin/dist/assets/input-BqURNT6_.js → ppbase-0.2.3/ppbase/admin/dist/assets/input-CsF2HwFH.js +1 -1
- ppbase-0.2.1/ppbase/admin/dist/assets/label-DN_udu84.js → ppbase-0.2.3/ppbase/admin/dist/assets/label-DHgrnS59.js +1 -1
- ppbase-0.2.3/ppbase/admin/dist/assets/layout-B8lOjqux.js +26 -0
- ppbase-0.2.1/ppbase/admin/dist/assets/loading-spinner-CYvUxGAE.js → ppbase-0.2.3/ppbase/admin/dist/assets/loading-spinner-9jTlzgcl.js +1 -1
- ppbase-0.2.1/ppbase/admin/dist/assets/login-CtnkSvA1.js → ppbase-0.2.3/ppbase/admin/dist/assets/login-B3DFIpss.js +1 -1
- ppbase-0.2.1/ppbase/admin/dist/assets/logs-wQwpAVxN.js → ppbase-0.2.3/ppbase/admin/dist/assets/logs-D47HccMh.js +1 -1
- ppbase-0.2.1/ppbase/admin/dist/assets/migrations-Dlrt43QA.js → ppbase-0.2.3/ppbase/admin/dist/assets/migrations-Bffnfhca.js +2 -2
- ppbase-0.2.1/ppbase/admin/dist/assets/refresh-cw-GHDEIP9d.js → ppbase-0.2.3/ppbase/admin/dist/assets/refresh-cw-6FWWr1B8.js +1 -1
- ppbase-0.2.1/ppbase/admin/dist/assets/select-43JIRBNM.js → ppbase-0.2.3/ppbase/admin/dist/assets/select-Bxmx88ff.js +1 -1
- ppbase-0.2.1/ppbase/admin/dist/assets/settings-CxZsoeTc.js → ppbase-0.2.3/ppbase/admin/dist/assets/settings-DyFiT37Y.js +1 -1
- ppbase-0.2.1/ppbase/admin/dist/assets/setup-BVZXJmMR.js → ppbase-0.2.3/ppbase/admin/dist/assets/setup-_2oR15Mh.js +1 -1
- ppbase-0.2.1/ppbase/admin/dist/assets/sheet-BqcXrPMk.js → ppbase-0.2.3/ppbase/admin/dist/assets/sheet-DeMGtydc.js +1 -1
- ppbase-0.2.3/ppbase/admin/dist/assets/use-health-Cbydn8p0.js +6 -0
- ppbase-0.2.1/ppbase/admin/dist/assets/use-logs-DP2t67_K.js → ppbase-0.2.3/ppbase/admin/dist/assets/use-logs-eXKVnJEm.js +1 -1
- ppbase-0.2.1/ppbase/admin/dist/assets/use-migrations-DAeB_wNl.js → ppbase-0.2.3/ppbase/admin/dist/assets/use-migrations-CeH8SEZb.js +1 -1
- ppbase-0.2.1/ppbase/admin/dist/assets/use-settings-PsGP45fr.js → ppbase-0.2.3/ppbase/admin/dist/assets/use-settings-m-86BzLa.js +1 -1
- {ppbase-0.2.1 → ppbase-0.2.3}/ppbase/admin/dist/index.html +1 -1
- {ppbase-0.2.1 → ppbase-0.2.3}/ppbase/api/health.py +3 -1
- {ppbase-0.2.1 → ppbase-0.2.3}/ppbase/app.py +2 -1
- {ppbase-0.2.1 → ppbase-0.2.3}/ppbase/services/record_service.py +193 -127
- {ppbase-0.2.1 → ppbase-0.2.3}/ppbase.egg-info/PKG-INFO +1 -1
- {ppbase-0.2.1 → ppbase-0.2.3}/ppbase.egg-info/SOURCES.txt +30 -30
- {ppbase-0.2.1 → ppbase-0.2.3}/pyproject.toml +1 -1
- ppbase-0.2.1/ppbase/__init__.py +0 -17
- ppbase-0.2.1/ppbase/admin/dist/assets/dashboard-D4491lbj.js +0 -11
- ppbase-0.2.1/ppbase/admin/dist/assets/layout-BtS6Z6Mp.js +0 -26
- ppbase-0.2.1/ppbase/admin/dist/assets/table-2-BPWm54Rc.js +0 -6
- {ppbase-0.2.1 → ppbase-0.2.3}/README.md +0 -0
- {ppbase-0.2.1 → ppbase-0.2.3}/ppbase/__main__.py +0 -0
- {ppbase-0.2.1 → ppbase-0.2.3}/ppbase/admin/dist/assets/index-C_wtr7YT.css +0 -0
- {ppbase-0.2.1 → ppbase-0.2.3}/ppbase/admin/dist/fonts/Inter-Variable.woff2 +0 -0
- {ppbase-0.2.1 → ppbase-0.2.3}/ppbase/api/__init__.py +0 -0
- {ppbase-0.2.1 → ppbase-0.2.3}/ppbase/api/admins.py +0 -0
- {ppbase-0.2.1 → ppbase-0.2.3}/ppbase/api/collections.py +0 -0
- {ppbase-0.2.1 → ppbase-0.2.3}/ppbase/api/deps.py +0 -0
- {ppbase-0.2.1 → ppbase-0.2.3}/ppbase/api/files.py +0 -0
- {ppbase-0.2.1 → ppbase-0.2.3}/ppbase/api/logs.py +0 -0
- {ppbase-0.2.1 → ppbase-0.2.3}/ppbase/api/migrations.py +0 -0
- {ppbase-0.2.1 → ppbase-0.2.3}/ppbase/api/realtime.py +0 -0
- {ppbase-0.2.1 → ppbase-0.2.3}/ppbase/api/record_auth.py +0 -0
- {ppbase-0.2.1 → ppbase-0.2.3}/ppbase/api/records.py +0 -0
- {ppbase-0.2.1 → ppbase-0.2.3}/ppbase/api/router.py +0 -0
- {ppbase-0.2.1 → ppbase-0.2.3}/ppbase/api/settings.py +0 -0
- {ppbase-0.2.1 → ppbase-0.2.3}/ppbase/config.py +0 -0
- {ppbase-0.2.1 → ppbase-0.2.3}/ppbase/core/__init__.py +0 -0
- {ppbase-0.2.1 → ppbase-0.2.3}/ppbase/core/id_generator.py +0 -0
- {ppbase-0.2.1 → ppbase-0.2.3}/ppbase/db/__init__.py +0 -0
- {ppbase-0.2.1 → ppbase-0.2.3}/ppbase/db/bootstrap.py +0 -0
- {ppbase-0.2.1 → ppbase-0.2.3}/ppbase/db/engine.py +0 -0
- {ppbase-0.2.1 → ppbase-0.2.3}/ppbase/db/ensure_db.py +0 -0
- {ppbase-0.2.1 → ppbase-0.2.3}/ppbase/db/schema_manager.py +0 -0
- {ppbase-0.2.1 → ppbase-0.2.3}/ppbase/db/system_tables.py +0 -0
- {ppbase-0.2.1 → ppbase-0.2.3}/ppbase/ext/__init__.py +0 -0
- {ppbase-0.2.1 → ppbase-0.2.3}/ppbase/ext/events.py +0 -0
- {ppbase-0.2.1 → ppbase-0.2.3}/ppbase/ext/flask_like_pb.py +0 -0
- {ppbase-0.2.1 → ppbase-0.2.3}/ppbase/ext/hooks.py +0 -0
- {ppbase-0.2.1 → ppbase-0.2.3}/ppbase/ext/loading.py +0 -0
- {ppbase-0.2.1 → ppbase-0.2.3}/ppbase/ext/record_repository.py +0 -0
- {ppbase-0.2.1 → ppbase-0.2.3}/ppbase/ext/registry.py +0 -0
- {ppbase-0.2.1 → ppbase-0.2.3}/ppbase/middleware/__init__.py +0 -0
- {ppbase-0.2.1 → ppbase-0.2.3}/ppbase/middleware/auth.py +0 -0
- {ppbase-0.2.1 → ppbase-0.2.3}/ppbase/middleware/cors.py +0 -0
- {ppbase-0.2.1 → ppbase-0.2.3}/ppbase/middleware/rate_limit.py +0 -0
- {ppbase-0.2.1 → ppbase-0.2.3}/ppbase/middleware/request_logger.py +0 -0
- {ppbase-0.2.1 → ppbase-0.2.3}/ppbase/models/__init__.py +0 -0
- {ppbase-0.2.1 → ppbase-0.2.3}/ppbase/models/collection.py +0 -0
- {ppbase-0.2.1 → ppbase-0.2.3}/ppbase/models/field_types.py +0 -0
- {ppbase-0.2.1 → ppbase-0.2.3}/ppbase/models/record.py +0 -0
- {ppbase-0.2.1 → ppbase-0.2.3}/ppbase/services/__init__.py +0 -0
- {ppbase-0.2.1 → ppbase-0.2.3}/ppbase/services/admin_service.py +0 -0
- {ppbase-0.2.1 → ppbase-0.2.3}/ppbase/services/auth_service.py +0 -0
- {ppbase-0.2.1 → ppbase-0.2.3}/ppbase/services/collection_service.py +0 -0
- {ppbase-0.2.1 → ppbase-0.2.3}/ppbase/services/expand_service.py +0 -0
- {ppbase-0.2.1 → ppbase-0.2.3}/ppbase/services/file_storage.py +0 -0
- {ppbase-0.2.1 → ppbase-0.2.3}/ppbase/services/filter_parser.py +0 -0
- {ppbase-0.2.1 → ppbase-0.2.3}/ppbase/services/mail_service.py +0 -0
- {ppbase-0.2.1 → ppbase-0.2.3}/ppbase/services/migration_generator.py +0 -0
- {ppbase-0.2.1 → ppbase-0.2.3}/ppbase/services/migration_runner.py +0 -0
- {ppbase-0.2.1 → ppbase-0.2.3}/ppbase/services/oauth2_service.py +0 -0
- {ppbase-0.2.1 → ppbase-0.2.3}/ppbase/services/realtime_service.py +0 -0
- {ppbase-0.2.1 → ppbase-0.2.3}/ppbase/services/record_auth_service.py +0 -0
- {ppbase-0.2.1 → ppbase-0.2.3}/ppbase/services/rule_engine.py +0 -0
- {ppbase-0.2.1 → ppbase-0.2.3}/ppbase/services/setup_service.py +0 -0
- {ppbase-0.2.1 → ppbase-0.2.3}/ppbase/storage/__init__.py +0 -0
- {ppbase-0.2.1 → ppbase-0.2.3}/ppbase.egg-info/dependency_links.txt +0 -0
- {ppbase-0.2.1 → ppbase-0.2.3}/ppbase.egg-info/entry_points.txt +0 -0
- {ppbase-0.2.1 → ppbase-0.2.3}/ppbase.egg-info/requires.txt +0 -0
- {ppbase-0.2.1 → ppbase-0.2.3}/ppbase.egg-info/top_level.txt +0 -0
- {ppbase-0.2.1 → ppbase-0.2.3}/setup.cfg +0 -0
- {ppbase-0.2.1 → ppbase-0.2.3}/tests/test_deps_optional_auth.py +0 -0
- {ppbase-0.2.1 → ppbase-0.2.3}/tests/test_oauth2_base_url.py +0 -0
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"""PPBase -- a Python reimplementation of PocketBase using PostgreSQL."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from importlib.metadata import PackageNotFoundError, version
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def _resolve_version() -> str:
|
|
10
|
+
try:
|
|
11
|
+
return version("ppbase")
|
|
12
|
+
except PackageNotFoundError:
|
|
13
|
+
pyproject_path = Path(__file__).resolve().parent.parent / "pyproject.toml"
|
|
14
|
+
if pyproject_path.exists():
|
|
15
|
+
try:
|
|
16
|
+
import tomllib
|
|
17
|
+
|
|
18
|
+
data = tomllib.loads(pyproject_path.read_text(encoding="utf-8"))
|
|
19
|
+
project = data.get("project", {})
|
|
20
|
+
resolved = project.get("version")
|
|
21
|
+
if isinstance(resolved, str) and resolved.strip():
|
|
22
|
+
return resolved.strip()
|
|
23
|
+
except Exception:
|
|
24
|
+
pass
|
|
25
|
+
|
|
26
|
+
return "0.1.0"
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
__version__ = _resolve_version()
|
|
30
|
+
|
|
31
|
+
from ppbase.ext.flask_like_pb import FlaskLikePB
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class PPBase(FlaskLikePB):
|
|
35
|
+
"""Main PPBase facade."""
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
# Process-wide Flask-like singleton facade.
|
|
39
|
+
pb = PPBase()
|
|
40
|
+
|
|
41
|
+
__all__ = ["PPBase", "pb", "__version__"]
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{c as Y,
|
|
1
|
+
import{c as Y,J as Z,K as Re,M as fe,Q as ge,R as Q,r as o,j as e,g as ae,T as Ie,U as Ae,V as Ee,W as $e,C as je,s as Te,t as ye,E as Se,X as Le,Y as as,Z as rs,_ as Me,h as Oe,q as ls,$ as _,k as is,a0 as os,x as cs,F as ds,S as ms}from"./index-BWzNXVt7.js";import{C as us,B as hs}from"./breadcrumb-DHPmrgya.js";import{B as F}from"./button-B7j1u3OP.js";import{I as H}from"./input-CsF2HwFH.js";import{C as re}from"./checkbox-Bhzc1DBg.js";import{F as ne,g as oe,D as ze,a as qe,b as Ue,c as ps,d as pe,e as ke,f as ue,h as _e,E as xs,C as fs}from"./collection-editor-yCbBYzYS.js";import{T as we,a as be,b as K,c as V,d as ve,e as O,C as Be,E as gs}from"./empty-state-VIN2ShUA.js";import{C as Ne}from"./chevron-left-CrmIArth.js";import{L as E}from"./label-DHgrnS59.js";import{S as He,a as Ve,b as Ke,c as Je,d as js,e as ys}from"./sheet-DeMGtydc.js";import{L as ie}from"./loading-spinner-9jTlzgcl.js";import{B as ce}from"./badge-Ge7Vok1k.js";import{S as ws,a as bs,b as vs,c as Ns,d as Cs}from"./select-Bxmx88ff.js";import{R as Ss}from"./refresh-cw-6FWWr1B8.js";import"./index-Dyazd57h.js";import"./check-ojOtQs1Z.js";/**
|
|
2
2
|
* @license lucide-react v0.468.0 - ISC
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the ISC license.
|
|
@@ -43,7 +43,7 @@ import{c as Y,B as Z,E as Re,M as fe,Q as ge,R as Q,r as o,j as e,g as ae,T as I
|
|
|
43
43
|
*
|
|
44
44
|
* This source code is licensed under the ISC license.
|
|
45
45
|
* See the LICENSE file in the root directory of this source tree.
|
|
46
|
-
*/const As=Y("Upload",[["path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4",key:"ih7n3h"}],["polyline",{points:"17 8 12 3 7 8",key:"t8dd8p"}],["line",{x1:"12",x2:"12",y1:"3",y2:"15",key:"widbto"}]]);async function Es(s,t){const n=t?"?"+t:"";return Z.request("GET","/api/collections/"+encodeURIComponent(s)+"/records"+n)}async function $s(s,t,n){const a=n?"?"+n:"";return Z.request("GET","/api/collections/"+encodeURIComponent(s)+"/records/"+encodeURIComponent(t)+a)}function Qe(s){for(const t of Object.values(s))if(t instanceof File||Array.isArray(t)&&t.some(n=>n instanceof File))return!0;return!1}function Ye(s){const t=new FormData;for(const[n,a]of Object.entries(s))if(a!=null)if(a instanceof File)t.append(n,a);else if(Array.isArray(a))for(const r of a)r instanceof File?t.append(n,r):t.append(n,String(r));else typeof a=="object"?t.append(n,JSON.stringify(a)):t.append(n,String(a));return t}async function Ts(s,t){const n="/api/collections/"+encodeURIComponent(s)+"/records";if(Qe(t)){const a=Ye(t);return Z.requestFormData("POST",n,a)}return Z.request("POST",n,t)}async function Ls(s,t,n){const a="/api/collections/"+encodeURIComponent(s)+"/records/"+encodeURIComponent(t);if(Qe(n)){const r=Ye(n);return Z.requestFormData("PATCH",a,r)}return Z.request("PATCH",a,n)}async function Ms(s,t){return Z.request("DELETE","/api/collections/"+encodeURIComponent(s)+"/records/"+encodeURIComponent(t))}function Ge(s){if(!s)return;const t=[];return s.page&&t.push(`page=${s.page}`),s.perPage&&t.push(`perPage=${s.perPage}`),s.filter&&t.push(`filter=${encodeURIComponent(s.filter)}`),s.sort&&t.push(`sort=${encodeURIComponent(s.sort)}`),s.expand&&t.push(`expand=${encodeURIComponent(s.expand)}`),t.length>0?t.join("&"):void 0}function We(s,t){const n=Ge(t);return Re({queryKey:["records",s,n],queryFn:()=>Es(s,n),enabled:!!s})}function Os(s,t,n){const a=Ge(n);return Re({queryKey:["records",s,t,a],queryFn:()=>$s(s,t,a),enabled:!!s&&!!t})}function zs(s){const t=fe();return ge({mutationFn:n=>Ts(s,n),onSuccess:()=>{t.invalidateQueries({queryKey:["records",s]})}})}function qs(s){const t=fe();return ge({mutationFn:({id:n,data:a})=>Ls(s,n,a),onSuccess:()=>{t.invalidateQueries({queryKey:["records",s]})}})}function Ze(s){const t=fe();return ge({mutationFn:n=>Ms(s,n),onSuccess:()=>{t.invalidateQueries({queryKey:["records",s]})}})}const Us=["name","title","username","label","email","slug"];function Xe(s){return Array.isArray(s)?s.filter(t=>!!t&&typeof t=="object"):s&&typeof s=="object"?[s]:[]}function Ce(s){if(!s)return null;for(const t of Us){const n=s[t];if(typeof n=="string"&&n.trim())return n}return typeof s.id=="string"&&s.id?Q(s.id):null}function _s(s,t){var l;const a=Xe((l=s.expand)==null?void 0:l[t]).map(c=>Ce(c)).filter(c=>!!c);if(a.length>0)return a;const r=s[t];return Array.isArray(r)?r.map(c=>Q(String(c))).filter(Boolean):r?[Q(String(r))]:[]}function Bs(s,t){var r;const n=Xe((r=s.expand)==null?void 0:r[t]).map(l=>l.id).filter(l=>typeof l=="string"&&!!l);if(n.length>0)return n;const a=s[t];return Array.isArray(a)?a.map(l=>String(l)).filter(Boolean):a?[String(a)]:[]}function he(s,t){if(s==null)return"-";switch(typeof t=="string"?t:t.type){case"bool":return s?"Yes":"No";case"json":if(typeof s=="object"){const a=JSON.stringify(s);return a.length>50?a.substring(0,50)+"...":a}return String(s);case"select":return Array.isArray(s)?s.join(", "):String(s);case"relation":return Array.isArray(s)?s.length+" relation"+(s.length!==1?"s":""):Q(String(s));case"file":return Array.isArray(s)?s.length+" file"+(s.length!==1?"s":""):String(s);default:{const a=String(s);return a.length>60?a.substring(0,60)+"...":a}}}function es({collectionId:s,recordId:t,files:n,className:a,size:r="sm"}){const[l,c]=o.useState(null),h=(Array.isArray(n)?n:[n]).filter(p=>!!p),g=p=>`/api/files/${s}/${t}/${p}`,j=p=>/\.(jpg|jpeg|png|gif|webp|svg)$/i.test(p),k={sm:"h-8 w-8",md:"h-16 w-16",lg:"w-full h-auto aspect-video",fill:"h-full w-full"}[r],L=()=>{if(!l)return;const N=(h.indexOf(l)+1)%h.length;c(h[N])},x=()=>{if(!l)return;const N=(h.indexOf(l)-1+h.length)%h.length;c(h[N])};return o.useEffect(()=>{if(!l)return;const p=N=>{N.key==="ArrowRight"&&L(),N.key==="ArrowLeft"&&x(),N.key==="Escape"&&c(null)};return window.addEventListener("keydown",p),()=>window.removeEventListener("keydown",p)},[l]),h.length===0?null:e.jsxs(e.Fragment,{children:[e.jsx("div",{className:ae("flex flex-wrap gap-2",a),children:h.map((p,N)=>e.jsx("div",{className:ae("relative overflow-hidden rounded-md border bg-muted group cursor-pointer hover:ring-2 hover:ring-primary/50 transition-all isolate",k),onClick:D=>{D.stopPropagation(),c(p)},children:j(p)?e.jsx("img",{src:g(p),alt:p,className:"h-full w-full object-cover",loading:"lazy"}):e.jsx("div",{className:"flex h-full w-full items-center justify-center bg-secondary",children:e.jsx(xe,{className:"h-4 w-4 text-muted-foreground"})})},p))}),e.jsx(Ie,{open:!!l,onOpenChange:p=>!p&&c(null),children:e.jsxs(Ae,{className:"max-w-[95vw] max-h-[95vh] w-auto h-auto p-0 bg-transparent border-0 shadow-none sm:rounded-lg outline-none flex flex-col overflow-hidden",onClick:p=>p.stopPropagation(),"aria-describedby":"image-preview-description",children:[e.jsxs("div",{className:"sr-only",children:[e.jsx(Ee,{children:l||"Image Preview"}),e.jsxs($e,{id:"image-preview-description",children:["Preview of ",l]})]}),l&&e.jsxs("div",{className:"relative flex flex-col w-full h-full max-h-[90vh] bg-transparent",children:[e.jsxs("div",{className:"flex-1 flex items-center justify-center min-h-[200px] overflow-hidden relative group",children:[j(l)?e.jsx("img",{src:g(l),alt:l,className:"max-w-full max-h-[80vh] object-contain shadow-2xl rounded-t-lg bg-black/5"}):e.jsxs("div",{className:"w-[600px] h-[400px] max-w-full flex flex-col items-center justify-center bg-white rounded-t-lg shadow-2xl gap-6",children:[e.jsx(xe,{className:"h-24 w-24 text-slate-300"}),e.jsx("p",{className:"text-xl font-medium text-center break-all max-w-[80%]",children:l}),e.jsx(F,{asChild:!0,size:"lg",children:e.jsxs("a",{href:g(l),download:!0,target:"_blank",rel:"noreferrer",children:[e.jsx(Ps,{className:"mr-2 h-5 w-5"}),"Download"]})})]}),h.length>1&&e.jsxs(e.Fragment,{children:[e.jsx(F,{variant:"ghost",size:"icon",className:"absolute left-4 top-1/2 -translate-y-1/2 rounded-full bg-black/20 hover:bg-black/40 text-white h-12 w-12 opacity-0 group-hover:opacity-100 transition-opacity",onClick:p=>{p.stopPropagation(),x()},children:e.jsx(Ne,{className:"h-8 w-8"})}),e.jsx(F,{variant:"ghost",size:"icon",className:"absolute right-4 top-1/2 -translate-y-1/2 rounded-full bg-black/20 hover:bg-black/40 text-white h-12 w-12 opacity-0 group-hover:opacity-100 transition-opacity",onClick:p=>{p.stopPropagation(),L()},children:e.jsx(je,{className:"h-8 w-8"})})]})]}),e.jsxs("div",{className:"bg-white p-4 flex items-center justify-between rounded-b-lg shadow-lg shrink-0",children:[e.jsxs("div",{className:"flex items-center gap-2 overflow-hidden mr-4",children:[e.jsx("span",{className:"text-sm font-medium truncate text-slate-700",title:l,children:l}),e.jsx("a",{href:g(l),target:"_blank",rel:"noreferrer",className:"text-slate-400 hover:text-blue-600 transition-colors shrink-0",title:"Open in new tab",children:e.jsx(de,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"flex items-center gap-4 shrink-0",children:[h.length>1&&e.jsxs("span",{className:"text-xs text-muted-foreground mr-2",children:[h.indexOf(l)+1," / ",h.length]}),e.jsx(F,{variant:"ghost",size:"sm",onClick:()=>c(null),className:"text-muted-foreground hover:text-foreground font-medium",children:"Close"})]})]})]})]})})]})}const Hs=new Set(["text","editor","email","url"]);function ss(s){var a;const t=s.fields??s.schema??[],n=[{name:"id",op:"~"}];for(const r of t){if(r.hidden||r.type==="password"||r.type==="json")continue;const l=r.maxSelect??((a=r.options)==null?void 0:a.maxSelect)??1;r.type==="select"?n.push({name:r.name,op:l>1?"?~":"~"}):r.type==="file"||r.type==="relation"?n.push({name:r.name,op:l>1?"?~":"~"}):Hs.has(r.type)&&n.push({name:r.name,op:"~"})}return n}function Vs(s){const t=s.trim();return t?!!(/[a-zA-Z_][a-zA-Z0-9_]*\s*[~=!<>]=?|&&|\|\||\?~|\?=|\?!=|\?[<>]=?/.test(t)||t.includes("~")||t.includes("&&")||t.includes("||")||t.includes("=")&&(t.includes("'")||t.includes('"'))||/[<>]=?/.test(t)):!1}function Js(s){return s.replace(/'/g,"''")}function ts(s,t){const n=(s??"").trim();if(!n)return"";if(Vs(n))return n;const a=Js(n),r=t.map(l=>`${l.name}${l.op}'${a}'`);return r.length===1?r[0]:`(${r.join(" || ")})`}const Ks=["id","created","updated"],Qs=[{name:"email",type:"email"},{name:"emailVisibility",type:"bool"},{name:"verified",type:"bool"}];function Ys(s,t){const n=r=>{if(s.type!=="auth")return r;const l=new Set(r.map(i=>i.name));return[...Qs.filter(i=>!l.has(i.name)),...r]},a=s.fields??s.schema??[];if(a.length>0)return n(a);if(t.length>0){const r=new Set(["id","collectionId","collectionName","created","updated"]),l=Object.keys(t[0]).filter(c=>!r.has(c));return n(l.map(c=>({name:c,type:"text"})))}return n([])}function Gs(s){var t;return s.collectionId??((t=s.options)==null?void 0:t.collectionId)}const ns="ppbase_columns_";function Fe(s){try{const t=localStorage.getItem(ns+s);if(!t)return null;const n=JSON.parse(t);if(Array.isArray(n))return new Set(n)}catch{}return null}function De(s,t){localStorage.setItem(ns+s,JSON.stringify([...t]))}function Ws({collection:s,records:t,selectedIds:n,onSelectAll:a,onSelectRow:r,onRowClick:l,onPageChange:c,onFilterChange:i,onNewRecord:h,hidePagination:g,isLoading:j}){const[k,L]=o.useState(""),x=s.type==="view",p=Ys(s,t.items),N=t.items.length>0&&t.items.every(d=>n.has(d.id)),D=(t.page-1)*t.perPage+1,z=Math.min(t.page*t.perPage,t.totalItems),[S,B]=o.useState(()=>Fe(s.id)??new Set);o.useEffect(()=>{const d=Fe(s.id);B(d??new Set)},[s.id]);const P=o.useCallback(d=>{B(v=>{const U=new Set(v);return U.has(d)?U.delete(d):U.add(d),De(s.id,U),U})},[s.id]),$=o.useCallback(()=>{B(new Set),De(s.id,new Set)},[s.id]),y=o.useMemo(()=>p.filter(d=>!S.has(d.name)),[p,S]),A=!S.has("id"),b=!S.has("created"),m=!S.has("updated"),w=S.size,R=o.useMemo(()=>ss(s),[s]),f=o.useCallback(()=>{const d=ts(k,R);i(d)},[k,i,R]),T=o.useCallback((d,v,U)=>{d.stopPropagation();const K=`${window.location.origin}/_/collections/${encodeURIComponent(v)}?record=${encodeURIComponent(U)}`;window.open(K,"_blank","noopener,noreferrer")},[]),q=o.useCallback((d,v)=>{const U=Gs(v);if(!U)return he(d[v.name],v);const K=_s(d,v.name),se=Bs(d,v.name);return K.length===0||se.length===0?he(d[v.name],v):e.jsx("div",{className:"flex flex-wrap items-center gap-1.5",title:"Open related record in new tab",children:K.map((te,X)=>{const W=se[X];return W?e.jsxs("button",{type:"button",className:"inline-flex max-w-full items-center gap-1 rounded-md border border-slate-200 px-2 py-0.5 text-xs text-slate-700 hover:border-slate-300 hover:bg-slate-50",onClick:le=>T(le,U,W),title:`Open related record ${W}`,children:[e.jsx("span",{className:"truncate",children:te}),e.jsx(de,{className:"h-3 w-3 shrink-0"})]},`${v.name}-${W}-${X}`):e.jsx("span",{className:"text-xs text-muted-foreground",children:te},`${v.name}-${X}`)})})},[T]),G=(x?0:1)+(A?1:0)+y.length+(b?1:0)+(m?1:0)+1;return e.jsxs("div",{className:"space-y-0",children:[e.jsx("div",{className:"pb-4",children:e.jsxs("div",{className:"relative",children:[e.jsx(Te,{className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),e.jsx(H,{type:"text",placeholder:'Search term or filter like created > "2022-01-01"...',value:k,onChange:d=>L(d.target.value),onKeyDown:d=>{d.key==="Enter"&&(d.preventDefault(),f())},className:"pl-9"})]})}),e.jsx("div",{className:"rounded-md border overflow-x-auto",children:e.jsxs(we,{className:"min-w-max",children:[e.jsx(be,{children:e.jsxs(J,{className:"bg-slate-50/80",children:[!x&&e.jsx(V,{className:"w-10",children:e.jsx(re,{checked:N,onCheckedChange:d=>a(!!d)})}),A&&e.jsx(V,{className:"w-32",children:e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx(ne,{type:oe("id")}),e.jsx("span",{children:"id"})]})}),y.map(d=>e.jsx(V,{children:e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx(ne,{type:d.type}),e.jsx("span",{children:d.name})]})},d.name)),b&&e.jsx(V,{className:"w-40",children:e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx(ne,{type:oe("created")}),e.jsx("span",{children:"created"})]})}),m&&e.jsx(V,{className:"w-40",children:e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx(ne,{type:oe("updated")}),e.jsx("span",{children:"updated"})]})}),e.jsx(V,{className:"w-10 text-right",children:e.jsxs(ze,{children:[e.jsx(qe,{asChild:!0,children:e.jsxs("button",{className:"inline-flex items-center justify-center h-7 w-7 rounded hover:bg-slate-200 text-muted-foreground hover:text-foreground transition-colors relative",children:[e.jsx(Rs,{className:"h-4 w-4"}),w>0&&e.jsx("span",{className:"absolute -top-0.5 -right-0.5 flex items-center justify-center rounded-full bg-indigo-500 text-white text-[9px] font-bold h-3.5 min-w-3.5 px-0.5",children:w})]})}),e.jsxs(Ue,{align:"end",className:"w-52 max-h-80 overflow-y-auto",children:[e.jsxs(ps,{className:"flex items-center justify-between",children:[e.jsx("span",{children:"Toggle columns"}),w>0&&e.jsx("button",{onClick:$,className:"text-xs text-indigo-600 hover:underline font-normal",children:"Show all"})]}),e.jsx(pe,{}),Ks.map(d=>e.jsx(ke,{checked:!S.has(d),onCheckedChange:()=>P(d),onSelect:v=>v.preventDefault(),children:e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx(ne,{type:oe(d),className:"scale-90"}),e.jsx("span",{children:d})]})},d)),p.length>0&&e.jsx(pe,{}),p.map(d=>e.jsx(ke,{checked:!S.has(d.name),onCheckedChange:()=>P(d.name),onSelect:v=>v.preventDefault(),children:e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx(ne,{type:d.type,className:"scale-90"}),e.jsx("span",{children:d.name})]})},d.name))]})]})})]})}),e.jsx(ve,{children:j?e.jsx(J,{children:e.jsx(O,{colSpan:Math.max(1,G),className:"h-24 text-center",children:e.jsxs("div",{className:"flex items-center justify-center gap-2 py-4 text-muted-foreground text-sm",children:[e.jsx("span",{className:"inline-block h-4 w-4 animate-spin rounded-full border-2 border-current border-t-transparent"}),"Loading..."]})})}):t.items.length===0?e.jsx(J,{children:e.jsx(O,{colSpan:Math.max(1,G),className:"h-24 text-center",children:e.jsxs("div",{className:"flex flex-col items-center gap-2 py-4",children:[e.jsx("span",{className:"text-muted-foreground text-sm",children:"No records found."}),h&&!x&&e.jsxs(F,{variant:"outline",size:"sm",onClick:h,children:[e.jsx(ye,{className:"mr-1.5 h-3.5 w-3.5"}),"New record"]})]})})}):t.items.map(d=>e.jsxs(J,{className:"cursor-pointer hover:bg-muted/50",onClick:()=>l(d.id),children:[!x&&e.jsx(O,{onClick:v=>v.stopPropagation(),children:e.jsx(re,{checked:n.has(d.id),onCheckedChange:v=>r(d.id,!!v)})}),A&&e.jsx(O,{className:"font-mono text-xs text-muted-foreground",children:Q(d.id)}),y.map(v=>e.jsx(O,{className:`max-w-[260px] ${v.type==="relation"?"align-top":"truncate"}`,children:v.type==="file"?e.jsx(es,{collectionId:s.id,recordId:d.id,files:d[v.name]}):v.type==="relation"?q(d,v):he(d[v.name],v)},v.name)),b&&e.jsx(O,{className:"text-xs text-muted-foreground",children:Se(d.created)}),m&&e.jsx(O,{className:"text-xs text-muted-foreground",children:Se(d.updated)}),e.jsx(O,{})]},d.id))})]})}),!g&&t.totalItems>0&&e.jsxs("div",{className:"flex items-center justify-between px-2 pt-4",children:[e.jsxs("span",{className:"text-sm text-muted-foreground",children:[D,"-",z," of ",t.totalItems," records"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(F,{variant:"outline",size:"sm",onClick:()=>c(t.page-1),disabled:t.page<=1,children:[e.jsx(Ne,{className:"h-4 w-4"}),"Previous"]}),e.jsxs(F,{variant:"outline",size:"sm",onClick:()=>c(t.page+1),disabled:t.page>=t.totalPages,children:["Next",e.jsx(je,{className:"h-4 w-4"})]})]})]})]})}function Zs({field:s,value:t,onChange:n}){return e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs(E,{htmlFor:s.name,children:[s.name,s.required&&e.jsx("span",{className:"text-destructive ml-1",children:"*"})]}),e.jsx(H,{id:s.name,type:"text",value:t??"",onChange:a=>n(a.target.value),placeholder:`Enter ${s.name}...`})]})}function Xs({field:s,value:t,onChange:n}){const a=s.options??s,r=a.onlyInt,l=a.min,c=a.max;return e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs(E,{htmlFor:s.name,children:[s.name,s.required&&e.jsx("span",{className:"text-destructive ml-1",children:"*"})]}),e.jsx(H,{id:s.name,type:"number",step:r?1:"any",min:l,max:c,value:t==null?"":String(t),onChange:i=>{const h=i.target.value;n(h===""?null:r?parseInt(h,10):parseFloat(h))},placeholder:"0"})]})}function et({field:s,value:t,onChange:n}){return e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs(E,{htmlFor:s.name,children:[s.name,s.required&&e.jsx("span",{className:"text-destructive ml-1",children:"*"})]}),e.jsx(H,{id:s.name,type:"email",value:t??"",onChange:a=>n(a.target.value),placeholder:"user@example.com"})]})}function st({field:s,value:t,onChange:n}){return e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs(E,{htmlFor:s.name,children:[s.name,s.required&&e.jsx("span",{className:"text-destructive ml-1",children:"*"})]}),e.jsx(H,{id:s.name,type:"url",value:t??"",onChange:a=>n(a.target.value),placeholder:"https://..."})]})}function tt({field:s,value:t,onChange:n}){const a=t?String(t).replace(" ","T").substring(0,16):"";return e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs(E,{htmlFor:s.name,children:[s.name,s.required&&e.jsx("span",{className:"text-destructive ml-1",children:"*"})]}),e.jsx(H,{id:s.name,type:"datetime-local",value:a,onChange:r=>{const l=r.target.value;n(l?l.replace("T"," ")+":00.000Z":"")}})]})}function nt({field:s,value:t,onChange:n}){return e.jsxs("div",{className:"flex items-center space-x-2 py-2",children:[e.jsx(re,{id:s.name,checked:!!t,onCheckedChange:a=>n(!!a)}),e.jsx(E,{htmlFor:s.name,className:"cursor-pointer",children:s.name})]})}const me=o.forwardRef(({className:s,...t},n)=>e.jsx("textarea",{className:ae("flex min-h-[60px] w-full rounded-md border border-input bg-transparent px-3 py-2 text-sm shadow-sm placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50",s),ref:n,...t}));me.displayName="Textarea";function at({field:s,value:t,onChange:n}){const a=typeof t=="string"?t:t!=null?JSON.stringify(t,null,2):"",[r,l]=o.useState(a),[c,i]=o.useState(null),h=g=>{if(l(g),g.trim()===""){i(null),n(null);return}try{const j=JSON.parse(g);i(null),n(j)}catch{i("Invalid JSON")}};return e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs(E,{htmlFor:s.name,children:[s.name,s.required&&e.jsx("span",{className:"text-destructive ml-1",children:"*"})]}),e.jsx(me,{id:s.name,rows:4,value:r,onChange:g=>h(g.target.value),placeholder:"{}",className:c?"border-destructive":""}),c&&e.jsx("p",{className:"text-xs text-destructive",children:c})]})}function rt({field:s,value:t,onChange:n}){return e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs(E,{htmlFor:s.name,children:[s.name,s.required&&e.jsx("span",{className:"text-destructive ml-1",children:"*"})]}),e.jsx(me,{id:s.name,rows:6,value:t??"",onChange:a=>n(a.target.value),placeholder:"Enter rich text content..."})]})}function lt({field:s,value:t,onChange:n}){const a=s.options??s,r=a.values??[],c=(a.maxSelect??1)>1;if(r.length===0)return e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs(E,{htmlFor:s.name,children:[s.name,s.required&&e.jsx("span",{className:"text-destructive ml-1",children:"*"})]}),e.jsx(H,{id:s.name,type:"text",value:t??"",onChange:i=>n(i.target.value),placeholder:"Enter value..."}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"No select values configured"})]});if(c){const i=Array.isArray(t)?t:t?[String(t)]:[],h=g=>{const j=i.includes(g)?i.filter(k=>k!==g):[...i,g];n(j)};return e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(E,{children:s.name}),s.required&&e.jsx("span",{className:"text-destructive text-sm",children:"*"}),e.jsx(ce,{variant:"secondary",className:"text-xs",children:"multi"})]}),e.jsx("div",{className:"space-y-1.5 rounded-md border p-3",children:r.map(g=>e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(re,{id:`${s.name}-${g}`,checked:i.includes(g),onCheckedChange:()=>h(g)}),e.jsx(E,{htmlFor:`${s.name}-${g}`,className:"cursor-pointer font-normal",children:g})]},g))})]})}return e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs(E,{htmlFor:s.name,children:[s.name,s.required&&e.jsx("span",{className:"text-destructive ml-1",children:"*"})]}),e.jsxs(ws,{value:t??"",onValueChange:i=>n(i),children:[e.jsx(bs,{id:s.name,children:e.jsx(vs,{placeholder:"Select a value..."})}),e.jsx(Ns,{children:r.map(i=>e.jsx(Cs,{value:i,children:i},i))})]})]})}function it(s,t){var n;return s?((n=t==null?void 0:t.find(a=>a.id===s))==null?void 0:n.name)??s:"unknown"}function Pe({open:s,onOpenChange:t,targetCollectionId:n,collections:a,isMulti:r,selectedIds:l,onConfirm:c}){const[i,h]=o.useState(1),[g]=o.useState(15),[j,k]=o.useState(""),[L,x]=o.useState(""),[p,N]=o.useState(new Set(l));o.useEffect(()=>{s&&(N(new Set(l)),h(1),k(""),x(""))},[s,l]);const{data:D}=Le(n),z=o.useMemo(()=>D?ss(D):[{name:"id",op:"~"}],[D]),{data:S,isLoading:B}=We(n,{page:i,perPage:g,filter:L||void 0}),P=it(n,a),$=()=>{const f=ts(j,z);x(f),h(1)},y=()=>{k(""),x(""),h(1)},A=f=>{if(!r){c([f]),t(!1);return}N(T=>{const q=new Set(T);return q.has(f)?q.delete(f):q.add(f),q})},b=()=>{c(Array.from(p)),t(!1)},m=(S==null?void 0:S.items)??[],w=(S==null?void 0:S.totalPages)??1,R=!!n;return e.jsx(Ie,{open:s,onOpenChange:t,children:e.jsxs(Ae,{className:"max-w-3xl",children:[e.jsxs(as,{children:[e.jsxs(Ee,{children:["Select related record",r?"s":""]}),e.jsxs($e,{children:["Target collection: ",P]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(Te,{className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),e.jsx(H,{type:"text",placeholder:'Search or filter (ex: name ~ "john")...',value:j,onChange:f=>k(f.target.value),onKeyDown:f=>{f.key==="Enter"&&(f.preventDefault(),$())},className:"pl-9",disabled:!R})]}),e.jsx(F,{type:"button",variant:"outline",size:"sm",onClick:$,disabled:!R,children:"Search"}),e.jsx(F,{type:"button",variant:"ghost",size:"sm",onClick:y,disabled:!j&&!L,children:"Reset"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Tip: plain text searches across fields, full expressions are used as raw PocketBase filters."}),e.jsx("div",{className:"rounded-md border overflow-x-auto max-h-[380px] overflow-y-auto",children:e.jsxs(we,{children:[e.jsx(be,{children:e.jsxs(J,{children:[r&&e.jsx(V,{className:"w-10"}),e.jsx(V,{children:"ID"}),e.jsx(V,{children:"Display"})]})}),e.jsx(ve,{children:R?B?e.jsx(J,{children:e.jsx(O,{colSpan:r?3:2,className:"h-20 text-center",children:e.jsxs("div",{className:"inline-flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(ie,{size:"sm"}),"Loading records..."]})})}):m.length===0?e.jsx(J,{children:e.jsx(O,{colSpan:r?3:2,className:"h-20 text-center text-sm text-muted-foreground",children:"No records found."})}):m.map(f=>{const T=Ce(f)??Q(f.id),q=p.has(f.id);return e.jsxs(J,{className:`cursor-pointer hover:bg-muted/40 ${q?"bg-slate-100/70":""}`,onClick:()=>A(f.id),children:[r&&e.jsx(O,{onClick:G=>G.stopPropagation(),children:e.jsx(re,{checked:q,onCheckedChange:()=>A(f.id)})}),e.jsx(O,{className:"font-mono text-xs text-muted-foreground",children:Q(f.id)}),e.jsx(O,{className:"max-w-[420px] truncate",children:T})]},f.id)}):e.jsx(J,{children:e.jsx(O,{colSpan:r?3:2,className:"h-20 text-center text-sm text-muted-foreground",children:"No target collection configured for this relation field."})})})]})}),e.jsxs("div",{className:"flex items-center justify-between text-sm text-muted-foreground",children:[e.jsx("span",{children:r?`${p.size} selected`:"Click a row to select"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{children:["Page ",(S==null?void 0:S.page)??i," / ",w]}),e.jsx(F,{variant:"outline",size:"sm",onClick:()=>h(f=>Math.max(1,f-1)),disabled:i<=1,children:"Previous"}),e.jsx(F,{variant:"outline",size:"sm",onClick:()=>h(f=>f+1),disabled:i>=w,children:"Next"})]})]})]}),e.jsxs(rs,{children:[e.jsx(F,{variant:"outline",onClick:()=>t(!1),children:"Cancel"}),r&&e.jsxs(F,{onClick:b,children:["Apply selection (",p.size,")"]})]})]})})}function ot(s,t){if(Array.isArray(s))return s.map(a=>String(a).trim()).filter(Boolean);if(!s)return[];const n=String(s).trim();return t?n.split(",").map(a=>a.trim()).filter(Boolean):n?[n]:[]}function ct(s){return Array.isArray(s)?s.filter(t=>!!t&&typeof t=="object"&&"id"in t):s&&typeof s=="object"&&"id"in s?[s]:[]}function dt({field:s,value:t,onChange:n,collections:a,recordExpand:r,recordId:l}){const c=s.options??s,i=c.maxSelect??1,h=c.collectionId,g=i>1,j=!!l,k=a==null?void 0:a.find(y=>y.id===h),L=(k==null?void 0:k.name)??h??"unknown",[x,p]=o.useState(!1),N=o.useMemo(()=>ot(t,g),[t,g]),D=o.useMemo(()=>ct(r==null?void 0:r[s.name]),[r,s.name]),z=o.useMemo(()=>{if(D.length>0){const y=new Map(D.map(b=>[b.id,b])),A=N.map(b=>y.get(b)).filter(b=>!!b);if(A.length===N.length&&A.length>0)return A.map(b=>({id:b.id,label:Ce(b)??Q(b.id)}))}return N.map(y=>({id:y,label:Q(y)}))},[D,N]),S=!!h,B=y=>{if(!h)return;const A=`${window.location.origin}/_/collections/${encodeURIComponent(h)}?record=${encodeURIComponent(y)}`;window.open(A,"_blank","noopener,noreferrer")},P=y=>{if(g){n(y);return}n(y[0]??"")};if(g)return e.jsxs("div",{className:"space-y-2.5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(E,{htmlFor:s.name,children:s.name}),s.required&&e.jsx("span",{className:"text-destructive text-sm",children:"*"}),e.jsx(ce,{variant:"secondary",className:"text-xs",children:"relation"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(F,{type:"button",variant:"outline",size:"sm",onClick:()=>p(!0),disabled:!S,children:"Select records"}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:[N.length," selected"]})]}),e.jsx(me,{id:s.name,rows:3,value:N.join(", "),onChange:y=>{const A=y.target.value.split(",").map(b=>b.trim()).filter(Boolean);n(A)},placeholder:"Enter record IDs separated by commas...",readOnly:j,disabled:j}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Target collection: ",L]}),z.length>0&&e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-xs font-medium text-slate-600",children:"Selected relations"}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:z.map(y=>e.jsxs("button",{type:"button",className:"inline-flex max-w-full items-center gap-1 rounded-md border border-slate-200 px-2 py-0.5 text-xs text-slate-700 hover:border-slate-300 hover:bg-slate-50",onClick:()=>B(y.id),disabled:!S,title:`Open related record ${y.id}`,children:[e.jsx("span",{className:"truncate",children:y.label}),e.jsx(de,{className:"h-3 w-3 shrink-0"})]},`${s.name}-${y.id}`))})]}),e.jsx(Pe,{open:x,onOpenChange:p,targetCollectionId:h,collections:a,isMulti:!0,selectedIds:N,onConfirm:P})]});const $=N[0]??"";return e.jsxs("div",{className:"space-y-2.5",children:[e.jsxs(E,{htmlFor:s.name,children:[s.name,s.required&&e.jsx("span",{className:"text-destructive ml-1",children:"*"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(H,{id:s.name,type:"text",value:$,onChange:y=>n(y.target.value.trim()),placeholder:"Enter record ID...",readOnly:j,disabled:j}),e.jsx(F,{type:"button",variant:"outline",size:"sm",onClick:()=>p(!0),disabled:!S,children:"Select"})]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Target collection: ",L]}),z[0]&&e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-xs font-medium text-slate-600",children:"Selected relation"}),e.jsxs("button",{type:"button",className:"inline-flex max-w-full items-center gap-1 rounded-md border border-slate-200 px-2 py-0.5 text-xs text-slate-700 hover:border-slate-300 hover:bg-slate-50",onClick:()=>B(z[0].id),disabled:!S,title:`Open related record ${z[0].id}`,children:[e.jsx("span",{className:"truncate",children:z[0].label}),e.jsx(de,{className:"h-3 w-3 shrink-0"})]})]}),e.jsx(Pe,{open:x,onOpenChange:p,targetCollectionId:h,collections:a,isMulti:!1,selectedIds:$?[$]:[],onConfirm:P})]})}function mt(s){return s>=1024*1024?`${Math.round(s/1024/1024*10)/10}MB`:s>=1024?`${Math.round(s/1024)}KB`:`${s}B`}function ut({field:s,value:t,onChange:n,collectionId:a,recordId:r}){var y,A,b;const l=o.useRef(null),[c,i]=o.useState(!1),h=((y=s.options)==null?void 0:y.maxSelect)??s.maxSelect??1,g=h>1,j=((A=s.options)==null?void 0:A.maxSize)??s.maxSize,k=((b=s.options)==null?void 0:b.mimeTypes)??s.mimeTypes??[],L=()=>t?Array.isArray(t)?t.map(m=>typeof m=="string"?{name:m}:m instanceof File?{name:m.name,isNew:!0,file:m}:{name:String(m)}):typeof t=="string"?[{name:t}]:[]:[],[x,p]=o.useState(L);o.useEffect(()=>{p(L())},[t]);const N=m=>/\.(jpg|jpeg|png|gif|webp|svg)$/i.test(m),D=o.useCallback(m=>{if(m.length){if(j){for(const w of m)if(w.size>j){alert(`File "${w.name}" exceeds max size of ${Math.round(j/1024)}KB`);return}}if(k.length>0){for(const w of m)if(!k.some(f=>f.endsWith("/*")?w.type.startsWith(f.slice(0,-1)):w.type===f)){alert(`File "${w.name}" has unsupported type: ${w.type}`);return}}if(g){const w=h-x.length;if(w<=0){alert(`Maximum of ${h} files allowed.`);return}const R=m.slice(0,w);R.length<m.length&&alert(`Only ${w} more file(s) allowed. ${m.length-R.length} file(s) were ignored.`);const f=[...x,...R.map(T=>({name:T.name,isNew:!0,file:T}))];p(f),n(f.map(T=>T.file||T.name))}else{const w=m[0],R=[{name:w.name,isNew:!0,file:w}];p(R),n([w])}l.current&&(l.current.value="")}},[x,g,h,j,k,n]),z=m=>{D(Array.from(m.target.files||[]))},S=m=>{m.preventDefault(),i(!1),D(Array.from(m.dataTransfer.files||[]))},B=m=>{const w=x.filter((f,T)=>T!==m);p(w);const R=w.map(f=>f.file||f.name);n(R.length>0?R:"")},P=g?"Add files":x.length>0?"Change file":"Choose file",$=[];return j&&$.push(`Max ${mt(j)}`),k.length>0&&$.push(k.join(", ")),g&&$.push(`Up to ${h} files`),e.jsxs("div",{className:"space-y-2.5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(E,{children:s.name}),s.required&&e.jsx("span",{className:"text-destructive text-sm",children:"*"})]}),e.jsx("input",{ref:l,type:"file",multiple:g,accept:k.length>0?k.join(","):void 0,className:"hidden",onChange:z}),e.jsx("button",{type:"button",onClick:()=>{var m;return(m=l.current)==null?void 0:m.click()},onDragOver:m=>{m.preventDefault(),i(!0)},onDragLeave:m=>{m.preventDefault(),i(!1)},onDrop:S,className:ae("w-full rounded-xl border bg-slate-100/80 px-4 py-4 text-left transition-colors","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",c?"border-indigo-400 bg-indigo-50/70":"border-slate-300 hover:border-slate-400 hover:bg-slate-100"),children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"flex h-10 w-10 shrink-0 items-center justify-center rounded-full border border-slate-300 bg-white text-slate-500",children:e.jsx(As,{className:"h-4 w-4"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm font-medium text-slate-800",children:g?"Drop files here or click to browse":"Drop a file here or click to browse"}),$.length>0&&e.jsx("p",{className:"mt-0.5 truncate text-xs text-slate-500",children:$.join(" • ")})]}),e.jsxs("span",{className:"ml-auto inline-flex h-8 shrink-0 items-center gap-1 rounded-md border border-slate-300 bg-white px-2.5 text-xs font-medium text-slate-700",children:[e.jsx(ye,{className:"h-3.5 w-3.5"}),P]})]})}),x.length>0&&e.jsx("div",{className:"space-y-2",children:x.map((m,w)=>e.jsxs("div",{className:"flex items-center gap-3 rounded-lg border border-slate-200 bg-white p-2.5",children:[e.jsx("div",{className:"relative h-12 w-12 shrink-0 overflow-hidden rounded-md border bg-slate-50",children:m.isNew&&m.file&&N(m.name)?e.jsx("img",{src:URL.createObjectURL(m.file),alt:m.name,className:"h-full w-full object-cover",onLoad:R=>URL.revokeObjectURL(R.currentTarget.src)}):!m.isNew&&a&&r&&N(m.name)?e.jsx("div",{className:"absolute inset-0 p-0.5",children:e.jsx(es,{collectionId:a,recordId:r,files:m.name,className:"h-full w-full",size:"fill"})}):N(m.name)?e.jsx("div",{className:"flex h-full w-full items-center justify-center text-slate-400",children:e.jsx(Is,{className:"h-4 w-4"})}):e.jsx("div",{className:"flex h-full w-full items-center justify-center text-slate-400",children:e.jsx(xe,{className:"h-4 w-4"})})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"truncate text-sm font-medium text-slate-800",children:m.name}),e.jsx("p",{className:"text-xs text-slate-500",children:m.isNew?"New file":"Existing file"})]}),e.jsx(F,{type:"button",variant:"ghost",size:"sm",className:"h-8 w-8 p-0 text-slate-500 hover:text-destructive",onClick:()=>B(w),children:e.jsx(Me,{className:"h-4 w-4"})})]},`${m.name}-${w}`))})]})}const ht={text:Zs,editor:rt,number:Xs,bool:nt,email:et,url:st,date:tt,select:lt,json:at,file:ut,relation:dt};function pt(s){const t=ht[s.field.type];return t?e.jsx(t,{...s}):e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-sm font-medium",children:s.field.name}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Unsupported field type: ",s.field.type]})]})}function xt({record:s,trigger:t,onDuplicate:n,onDelete:a}){const r=()=>{navigator.clipboard.writeText(JSON.stringify(s,null,2))};return e.jsxs(ze,{children:[e.jsx(qe,{asChild:!0,children:t}),e.jsxs(Ue,{align:"end",children:[e.jsxs(ue,{onClick:r,children:[e.jsx(Ds,{className:"mr-2 h-4 w-4"}),"Copy raw JSON"]}),e.jsxs(ue,{onClick:n,children:[e.jsx(Fs,{className:"mr-2 h-4 w-4"}),"Duplicate"]}),e.jsx(pe,{}),e.jsxs(ue,{onClick:a,className:"text-destructive focus:text-destructive",children:[e.jsx(_e,{className:"mr-2 h-4 w-4"}),"Delete"]})]})]})}async function ft(s,t){await Z.request("POST",`/api/admins/${encodeURIComponent(s)}/change-password`,t)}const gt=[{name:"email",type:"email"},{name:"emailVisibility",type:"bool"},{name:"verified",type:"bool"}];function jt(s){const t=s.fields??s.schema??[];if(!(s.type==="auth"||s.name==="_superusers"))return t;const a=new Set(t.map(l=>l.name)),r=gt.filter(l=>!a.has(l.name));return[...t,...r]}function yt(s){const t=s.filter(n=>n.type==="relation").map(n=>n.name);if(t.length!==0)return t.join(",")}function wt({open:s,onClose:t,collection:n,recordId:a,duplicateData:r}){const l=Oe(),c=!!a,i=o.useMemo(()=>jt(n),[n.id,n.type,n.name,n.fields,n.schema]),h=o.useMemo(()=>yt(i),[i]),{data:g}=ls(),{data:j,isLoading:k}=Os(n.id,a??void 0,{expand:h}),L=zs(n.id),x=qs(n.id),p=Ze(n.id),[N,D]=o.useState({}),[z,S]=o.useState(!1),B=n.name==="_superusers",P=n.type==="auth"||B,$=i.filter(u=>!(P&&!c&&u.name==="email")),[y,A]=o.useState(!1),[b,m]=o.useState(""),[w,R]=o.useState(""),[f,T]=o.useState(!1),[q,G]=o.useState(""),[d,v]=o.useState(""),[U,K]=o.useState("");o.useEffect(()=>{if(s){if(r){const u={};for(const C of i)u[C.name]=r[C.name]??null;D(u)}else if(c&&j){const u={};for(const C of i)u[C.name]=j[C.name]??null;D(u)}else if(!c){const u={};for(const C of i)C.type==="bool"?u[C.name]=!1:u[C.name]=null;D(u)}}},[s,j,r,c,i]);const se=(u,C)=>{console.log("[RecordEditor] handleFieldChange:",u,C),D(ee=>({...ee,[u]:C}))},te=async()=>{if(console.log("[RecordEditor] handleSave formData:",JSON.stringify(N,(C,ee)=>ee instanceof File?`[File: ${ee.name}]`:ee,2)),!c&&P){if(!q){_.error("Email is required");return}if(!d){_.error("Password is required");return}if(d!==U){_.error("Passwords do not match");return}if(d.length<8){_.error("Password must be at least 8 characters");return}}const u={...N,...!c&&P?{email:q,password:d,passwordConfirm:U}:{}};try{c?(await x.mutateAsync({id:a,data:N}),_.success("Record updated successfully")):(await L.mutateAsync(u),_.success("Record created successfully")),t()}catch(C){const ee=C&&typeof C=="object"&&"message"in C?String(C.message):"Failed to save record";_.error(ee)}},X=async()=>{if(a){if(b!==w){_.error("Passwords do not match");return}if(b.length<8){_.error("Password must be at least 8 characters");return}T(!0);try{await ft(a,{password:b,passwordConfirm:w}),_.success("Password changed successfully. Please log in again."),localStorage.removeItem("ppbase_token"),localStorage.removeItem("ppbase_admin"),t(),l("/login")}catch(u){const C=u&&typeof u=="object"&&"message"in u?String(u.message):"Failed to change password";_.error(C)}finally{T(!1)}}},W=async()=>{if(a)try{await p.mutateAsync(a),_.success("Record deleted successfully"),S(!1),t()}catch(u){const C=u&&typeof u=="object"&&"message"in u?String(u.message):"Failed to delete record";_.error(C)}},le=()=>{if(!j)return;const u={};for(const C of i)u[C.name]=j[C.name]??null;window.dispatchEvent(new CustomEvent("ppbase:duplicate-record",{detail:{data:u,closeCurrent:!0}}))},I=L.isPending||x.isPending,M=c?`Edit ${n.name} record`:`New ${n.name} record`;return e.jsxs(e.Fragment,{children:[e.jsx(He,{open:s,onOpenChange:u=>!u&&t(),children:e.jsxs(Ve,{className:"sm:max-w-[700px] flex flex-col overflow-hidden",showCloseButton:!1,children:[e.jsxs(Je,{className:"shrink-0 px-6 pt-6 pb-4",children:[e.jsxs("div",{className:"flex items-center justify-end gap-3",children:[e.jsx(Ke,{className:"flex-1",children:M}),c&&j&&e.jsx(xt,{record:j,trigger:e.jsx(F,{variant:"ghost",size:"icon",className:"h-8 w-8",children:e.jsx(xs,{className:"h-4 w-4"})}),onDuplicate:le,onDelete:()=>S(!0)})]}),e.jsx(js,{children:c&&a&&e.jsxs("span",{className:"font-mono text-xs",children:["ID: ",a]})})]}),e.jsx("div",{className:"border-t shrink-0"}),e.jsx("div",{className:"flex-1 overflow-y-auto px-6",children:c&&k?e.jsx("div",{className:"flex justify-center py-12",children:e.jsx(ie,{})}):e.jsxs("div",{className:"space-y-4 py-4",children:[!c&&P&&e.jsxs("div",{className:"space-y-3 pb-2 border-b",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(E,{htmlFor:"auth-email",children:"Email *"}),e.jsx(H,{id:"auth-email",type:"email",placeholder:"user@example.com",value:q,onChange:u=>G(u.target.value)})]}),e.jsxs("div",{className:"flex gap-3",children:[e.jsxs("div",{className:"flex-1 space-y-1.5",children:[e.jsx(E,{htmlFor:"auth-password",children:"Password *"}),e.jsx(H,{id:"auth-password",type:"password",placeholder:"Min. 8 characters",value:d,onChange:u=>v(u.target.value)})]}),e.jsxs("div",{className:"flex-1 space-y-1.5",children:[e.jsx(E,{htmlFor:"auth-password-confirm",children:"Confirm *"}),e.jsx(H,{id:"auth-password-confirm",type:"password",placeholder:"Repeat password",value:U,onChange:u=>K(u.target.value)})]})]})]}),$.map(u=>e.jsx(pt,{field:u,value:N[u.name],onChange:C=>se(u.name,C),collections:g,recordId:j==null?void 0:j.id,collectionId:n.id,recordExpand:j==null?void 0:j.expand},u.name)),$.length===0&&!P&&e.jsx("p",{className:"text-sm text-muted-foreground py-4",children:"This collection has no editable fields."}),P&&c&&e.jsxs("div",{className:"border-t pt-4 mt-4 space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(re,{id:"change-password-toggle",checked:y,onCheckedChange:u=>{A(!!u),u||(m(""),R(""))}}),e.jsx(E,{htmlFor:"change-password-toggle",className:"cursor-pointer font-medium",children:"Change password"})]}),y&&e.jsxs("div",{className:"flex gap-4",children:[e.jsxs("div",{className:"flex-1 space-y-1.5",children:[e.jsx(E,{htmlFor:"new-password",children:"New Password *"}),e.jsx(H,{id:"new-password",type:"password",placeholder:"Min. 8 characters",value:b,onChange:u=>m(u.target.value)})]}),e.jsxs("div",{className:"flex-1 space-y-1.5",children:[e.jsx(E,{htmlFor:"confirm-password",children:"Confirm Password *"}),e.jsx(H,{id:"confirm-password",type:"password",placeholder:"Confirm password",value:w,onChange:u=>R(u.target.value)})]})]}),y&&e.jsxs(F,{onClick:X,disabled:f||!b||!w,variant:"destructive",children:[f&&e.jsx(ie,{size:"sm",className:"mr-2"}),"Change Password"]})]})]})}),e.jsx("div",{className:"border-t shrink-0"}),e.jsxs(ys,{className:"shrink-0 px-6 py-2.5",children:[e.jsx(F,{variant:"outline",onClick:t,disabled:I,children:"Cancel"}),e.jsxs(F,{onClick:te,disabled:I||i.length===0&&!P,children:[I&&e.jsx(ie,{size:"sm",className:"mr-2"}),c?"Save changes":"Create"]})]})]})}),e.jsx(Be,{open:z,onOpenChange:S,title:"Delete record",description:"Are you sure you want to delete this record? This action cannot be undone.",confirmLabel:"Delete",variant:"destructive",onConfirm:W})]})}function bt(s){return[{id:"list",label:"List/Search",title:`List/Search (${s})`,description:`Fetch a paginated <strong>${s}</strong> records list, supporting sorting and filtering.`,method:"GET",methodClass:"bg-green-100 text-green-700",path:`/api/collections/${s}/records`,note:"Requires superuser <code>Authorization:TOKEN</code> header",params:[{name:"page",type:"Number",desc:"The page (aka. offset) of the paginated list (default to 1)."},{name:"perPage",type:"Number",desc:"Specify the max returned records per page (default to 30)."},{name:"sort",type:"String",desc:"Specify the records order attribute(s). Add - / + (default) in front of the attribute for DESC and ASC order."},{name:"filter",type:"String",desc:"Filter expression to filter/search the returned records list."},{name:"expand",type:"String",desc:"Auto expand record relations."}],code:`<span class="hl-comment">// fetch a paginated records list</span>
|
|
46
|
+
*/const As=Y("Upload",[["path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4",key:"ih7n3h"}],["polyline",{points:"17 8 12 3 7 8",key:"t8dd8p"}],["line",{x1:"12",x2:"12",y1:"3",y2:"15",key:"widbto"}]]);async function Es(s,t){const n=t?"?"+t:"";return Z.request("GET","/api/collections/"+encodeURIComponent(s)+"/records"+n)}async function $s(s,t,n){const a=n?"?"+n:"";return Z.request("GET","/api/collections/"+encodeURIComponent(s)+"/records/"+encodeURIComponent(t)+a)}function Qe(s){for(const t of Object.values(s))if(t instanceof File||Array.isArray(t)&&t.some(n=>n instanceof File))return!0;return!1}function Ye(s){const t=new FormData;for(const[n,a]of Object.entries(s))if(a!=null)if(a instanceof File)t.append(n,a);else if(Array.isArray(a))for(const r of a)r instanceof File?t.append(n,r):t.append(n,String(r));else typeof a=="object"?t.append(n,JSON.stringify(a)):t.append(n,String(a));return t}async function Ts(s,t){const n="/api/collections/"+encodeURIComponent(s)+"/records";if(Qe(t)){const a=Ye(t);return Z.requestFormData("POST",n,a)}return Z.request("POST",n,t)}async function Ls(s,t,n){const a="/api/collections/"+encodeURIComponent(s)+"/records/"+encodeURIComponent(t);if(Qe(n)){const r=Ye(n);return Z.requestFormData("PATCH",a,r)}return Z.request("PATCH",a,n)}async function Ms(s,t){return Z.request("DELETE","/api/collections/"+encodeURIComponent(s)+"/records/"+encodeURIComponent(t))}function Ge(s){if(!s)return;const t=[];return s.page&&t.push(`page=${s.page}`),s.perPage&&t.push(`perPage=${s.perPage}`),s.filter&&t.push(`filter=${encodeURIComponent(s.filter)}`),s.sort&&t.push(`sort=${encodeURIComponent(s.sort)}`),s.expand&&t.push(`expand=${encodeURIComponent(s.expand)}`),t.length>0?t.join("&"):void 0}function We(s,t){const n=Ge(t);return Re({queryKey:["records",s,n],queryFn:()=>Es(s,n),enabled:!!s})}function Os(s,t,n){const a=Ge(n);return Re({queryKey:["records",s,t,a],queryFn:()=>$s(s,t,a),enabled:!!s&&!!t})}function zs(s){const t=fe();return ge({mutationFn:n=>Ts(s,n),onSuccess:()=>{t.invalidateQueries({queryKey:["records",s]})}})}function qs(s){const t=fe();return ge({mutationFn:({id:n,data:a})=>Ls(s,n,a),onSuccess:()=>{t.invalidateQueries({queryKey:["records",s]})}})}function Ze(s){const t=fe();return ge({mutationFn:n=>Ms(s,n),onSuccess:()=>{t.invalidateQueries({queryKey:["records",s]})}})}const Us=["name","title","username","label","email","slug"];function Xe(s){return Array.isArray(s)?s.filter(t=>!!t&&typeof t=="object"):s&&typeof s=="object"?[s]:[]}function Ce(s){if(!s)return null;for(const t of Us){const n=s[t];if(typeof n=="string"&&n.trim())return n}return typeof s.id=="string"&&s.id?Q(s.id):null}function _s(s,t){var l;const a=Xe((l=s.expand)==null?void 0:l[t]).map(c=>Ce(c)).filter(c=>!!c);if(a.length>0)return a;const r=s[t];return Array.isArray(r)?r.map(c=>Q(String(c))).filter(Boolean):r?[Q(String(r))]:[]}function Bs(s,t){var r;const n=Xe((r=s.expand)==null?void 0:r[t]).map(l=>l.id).filter(l=>typeof l=="string"&&!!l);if(n.length>0)return n;const a=s[t];return Array.isArray(a)?a.map(l=>String(l)).filter(Boolean):a?[String(a)]:[]}function he(s,t){if(s==null)return"-";switch(typeof t=="string"?t:t.type){case"bool":return s?"Yes":"No";case"json":if(typeof s=="object"){const a=JSON.stringify(s);return a.length>50?a.substring(0,50)+"...":a}return String(s);case"select":return Array.isArray(s)?s.join(", "):String(s);case"relation":return Array.isArray(s)?s.length+" relation"+(s.length!==1?"s":""):Q(String(s));case"file":return Array.isArray(s)?s.length+" file"+(s.length!==1?"s":""):String(s);default:{const a=String(s);return a.length>60?a.substring(0,60)+"...":a}}}function es({collectionId:s,recordId:t,files:n,className:a,size:r="sm"}){const[l,c]=o.useState(null),h=(Array.isArray(n)?n:[n]).filter(p=>!!p),g=p=>`/api/files/${s}/${t}/${p}`,j=p=>/\.(jpg|jpeg|png|gif|webp|svg)$/i.test(p),k={sm:"h-8 w-8",md:"h-16 w-16",lg:"w-full h-auto aspect-video",fill:"h-full w-full"}[r],L=()=>{if(!l)return;const N=(h.indexOf(l)+1)%h.length;c(h[N])},x=()=>{if(!l)return;const N=(h.indexOf(l)-1+h.length)%h.length;c(h[N])};return o.useEffect(()=>{if(!l)return;const p=N=>{N.key==="ArrowRight"&&L(),N.key==="ArrowLeft"&&x(),N.key==="Escape"&&c(null)};return window.addEventListener("keydown",p),()=>window.removeEventListener("keydown",p)},[l]),h.length===0?null:e.jsxs(e.Fragment,{children:[e.jsx("div",{className:ae("flex flex-wrap gap-2",a),children:h.map((p,N)=>e.jsx("div",{className:ae("relative overflow-hidden rounded-md border bg-muted group cursor-pointer hover:ring-2 hover:ring-primary/50 transition-all isolate",k),onClick:D=>{D.stopPropagation(),c(p)},children:j(p)?e.jsx("img",{src:g(p),alt:p,className:"h-full w-full object-cover",loading:"lazy"}):e.jsx("div",{className:"flex h-full w-full items-center justify-center bg-secondary",children:e.jsx(xe,{className:"h-4 w-4 text-muted-foreground"})})},p))}),e.jsx(Ie,{open:!!l,onOpenChange:p=>!p&&c(null),children:e.jsxs(Ae,{className:"max-w-[95vw] max-h-[95vh] w-auto h-auto p-0 bg-transparent border-0 shadow-none sm:rounded-lg outline-none flex flex-col overflow-hidden",onClick:p=>p.stopPropagation(),"aria-describedby":"image-preview-description",children:[e.jsxs("div",{className:"sr-only",children:[e.jsx(Ee,{children:l||"Image Preview"}),e.jsxs($e,{id:"image-preview-description",children:["Preview of ",l]})]}),l&&e.jsxs("div",{className:"relative flex flex-col w-full h-full max-h-[90vh] bg-transparent",children:[e.jsxs("div",{className:"flex-1 flex items-center justify-center min-h-[200px] overflow-hidden relative group",children:[j(l)?e.jsx("img",{src:g(l),alt:l,className:"max-w-full max-h-[80vh] object-contain shadow-2xl rounded-t-lg bg-black/5"}):e.jsxs("div",{className:"w-[600px] h-[400px] max-w-full flex flex-col items-center justify-center bg-white rounded-t-lg shadow-2xl gap-6",children:[e.jsx(xe,{className:"h-24 w-24 text-slate-300"}),e.jsx("p",{className:"text-xl font-medium text-center break-all max-w-[80%]",children:l}),e.jsx(F,{asChild:!0,size:"lg",children:e.jsxs("a",{href:g(l),download:!0,target:"_blank",rel:"noreferrer",children:[e.jsx(Ps,{className:"mr-2 h-5 w-5"}),"Download"]})})]}),h.length>1&&e.jsxs(e.Fragment,{children:[e.jsx(F,{variant:"ghost",size:"icon",className:"absolute left-4 top-1/2 -translate-y-1/2 rounded-full bg-black/20 hover:bg-black/40 text-white h-12 w-12 opacity-0 group-hover:opacity-100 transition-opacity",onClick:p=>{p.stopPropagation(),x()},children:e.jsx(Ne,{className:"h-8 w-8"})}),e.jsx(F,{variant:"ghost",size:"icon",className:"absolute right-4 top-1/2 -translate-y-1/2 rounded-full bg-black/20 hover:bg-black/40 text-white h-12 w-12 opacity-0 group-hover:opacity-100 transition-opacity",onClick:p=>{p.stopPropagation(),L()},children:e.jsx(je,{className:"h-8 w-8"})})]})]}),e.jsxs("div",{className:"bg-white p-4 flex items-center justify-between rounded-b-lg shadow-lg shrink-0",children:[e.jsxs("div",{className:"flex items-center gap-2 overflow-hidden mr-4",children:[e.jsx("span",{className:"text-sm font-medium truncate text-slate-700",title:l,children:l}),e.jsx("a",{href:g(l),target:"_blank",rel:"noreferrer",className:"text-slate-400 hover:text-blue-600 transition-colors shrink-0",title:"Open in new tab",children:e.jsx(de,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"flex items-center gap-4 shrink-0",children:[h.length>1&&e.jsxs("span",{className:"text-xs text-muted-foreground mr-2",children:[h.indexOf(l)+1," / ",h.length]}),e.jsx(F,{variant:"ghost",size:"sm",onClick:()=>c(null),className:"text-muted-foreground hover:text-foreground font-medium",children:"Close"})]})]})]})]})})]})}const Hs=new Set(["text","editor","email","url"]);function ss(s){var a;const t=s.fields??s.schema??[],n=[{name:"id",op:"~"}];for(const r of t){if(r.hidden||r.type==="password"||r.type==="json")continue;const l=r.maxSelect??((a=r.options)==null?void 0:a.maxSelect)??1;r.type==="select"?n.push({name:r.name,op:l>1?"?~":"~"}):r.type==="file"||r.type==="relation"?n.push({name:r.name,op:l>1?"?~":"~"}):Hs.has(r.type)&&n.push({name:r.name,op:"~"})}return n}function Vs(s){const t=s.trim();return t?!!(/[a-zA-Z_][a-zA-Z0-9_]*\s*[~=!<>]=?|&&|\|\||\?~|\?=|\?!=|\?[<>]=?/.test(t)||t.includes("~")||t.includes("&&")||t.includes("||")||t.includes("=")&&(t.includes("'")||t.includes('"'))||/[<>]=?/.test(t)):!1}function Ks(s){return s.replace(/'/g,"''")}function ts(s,t){const n=(s??"").trim();if(!n)return"";if(Vs(n))return n;const a=Ks(n),r=t.map(l=>`${l.name}${l.op}'${a}'`);return r.length===1?r[0]:`(${r.join(" || ")})`}const Js=["id","created","updated"],Qs=[{name:"email",type:"email"},{name:"emailVisibility",type:"bool"},{name:"verified",type:"bool"}];function Ys(s,t){const n=r=>{if(s.type!=="auth")return r;const l=new Set(r.map(i=>i.name));return[...Qs.filter(i=>!l.has(i.name)),...r]},a=s.fields??s.schema??[];if(a.length>0)return n(a);if(t.length>0){const r=new Set(["id","collectionId","collectionName","created","updated"]),l=Object.keys(t[0]).filter(c=>!r.has(c));return n(l.map(c=>({name:c,type:"text"})))}return n([])}function Gs(s){var t;return s.collectionId??((t=s.options)==null?void 0:t.collectionId)}const ns="ppbase_columns_";function Fe(s){try{const t=localStorage.getItem(ns+s);if(!t)return null;const n=JSON.parse(t);if(Array.isArray(n))return new Set(n)}catch{}return null}function De(s,t){localStorage.setItem(ns+s,JSON.stringify([...t]))}function Ws({collection:s,records:t,selectedIds:n,onSelectAll:a,onSelectRow:r,onRowClick:l,onPageChange:c,onFilterChange:i,onNewRecord:h,hidePagination:g,isLoading:j}){const[k,L]=o.useState(""),x=s.type==="view",p=Ys(s,t.items),N=t.items.length>0&&t.items.every(d=>n.has(d.id)),D=(t.page-1)*t.perPage+1,z=Math.min(t.page*t.perPage,t.totalItems),[S,B]=o.useState(()=>Fe(s.id)??new Set);o.useEffect(()=>{const d=Fe(s.id);B(d??new Set)},[s.id]);const P=o.useCallback(d=>{B(v=>{const U=new Set(v);return U.has(d)?U.delete(d):U.add(d),De(s.id,U),U})},[s.id]),$=o.useCallback(()=>{B(new Set),De(s.id,new Set)},[s.id]),y=o.useMemo(()=>p.filter(d=>!S.has(d.name)),[p,S]),A=!S.has("id"),b=!S.has("created"),m=!S.has("updated"),w=S.size,R=o.useMemo(()=>ss(s),[s]),f=o.useCallback(()=>{const d=ts(k,R);i(d)},[k,i,R]),T=o.useCallback((d,v,U)=>{d.stopPropagation();const J=`${window.location.origin}/_/collections/${encodeURIComponent(v)}?record=${encodeURIComponent(U)}`;window.open(J,"_blank","noopener,noreferrer")},[]),q=o.useCallback((d,v)=>{const U=Gs(v);if(!U)return he(d[v.name],v);const J=_s(d,v.name),se=Bs(d,v.name);return J.length===0||se.length===0?he(d[v.name],v):e.jsx("div",{className:"flex flex-wrap items-center gap-1.5",title:"Open related record in new tab",children:J.map((te,X)=>{const W=se[X];return W?e.jsxs("button",{type:"button",className:"inline-flex max-w-full items-center gap-1 rounded-md border border-slate-200 px-2 py-0.5 text-xs text-slate-700 hover:border-slate-300 hover:bg-slate-50",onClick:le=>T(le,U,W),title:`Open related record ${W}`,children:[e.jsx("span",{className:"truncate",children:te}),e.jsx(de,{className:"h-3 w-3 shrink-0"})]},`${v.name}-${W}-${X}`):e.jsx("span",{className:"text-xs text-muted-foreground",children:te},`${v.name}-${X}`)})})},[T]),G=(x?0:1)+(A?1:0)+y.length+(b?1:0)+(m?1:0)+1;return e.jsxs("div",{className:"space-y-0",children:[e.jsx("div",{className:"pb-4",children:e.jsxs("div",{className:"relative",children:[e.jsx(Te,{className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),e.jsx(H,{type:"text",placeholder:'Search term or filter like created > "2022-01-01"...',value:k,onChange:d=>L(d.target.value),onKeyDown:d=>{d.key==="Enter"&&(d.preventDefault(),f())},className:"pl-9"})]})}),e.jsx("div",{className:"rounded-md border overflow-x-auto",children:e.jsxs(we,{className:"min-w-max",children:[e.jsx(be,{children:e.jsxs(K,{className:"bg-slate-50/80",children:[!x&&e.jsx(V,{className:"w-10",children:e.jsx(re,{checked:N,onCheckedChange:d=>a(!!d)})}),A&&e.jsx(V,{className:"w-32",children:e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx(ne,{type:oe("id")}),e.jsx("span",{children:"id"})]})}),y.map(d=>e.jsx(V,{children:e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx(ne,{type:d.type}),e.jsx("span",{children:d.name})]})},d.name)),b&&e.jsx(V,{className:"w-40",children:e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx(ne,{type:oe("created")}),e.jsx("span",{children:"created"})]})}),m&&e.jsx(V,{className:"w-40",children:e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx(ne,{type:oe("updated")}),e.jsx("span",{children:"updated"})]})}),e.jsx(V,{className:"w-10 text-right",children:e.jsxs(ze,{children:[e.jsx(qe,{asChild:!0,children:e.jsxs("button",{className:"inline-flex items-center justify-center h-7 w-7 rounded hover:bg-slate-200 text-muted-foreground hover:text-foreground transition-colors relative",children:[e.jsx(Rs,{className:"h-4 w-4"}),w>0&&e.jsx("span",{className:"absolute -top-0.5 -right-0.5 flex items-center justify-center rounded-full bg-indigo-500 text-white text-[9px] font-bold h-3.5 min-w-3.5 px-0.5",children:w})]})}),e.jsxs(Ue,{align:"end",className:"w-52 max-h-80 overflow-y-auto",children:[e.jsxs(ps,{className:"flex items-center justify-between",children:[e.jsx("span",{children:"Toggle columns"}),w>0&&e.jsx("button",{onClick:$,className:"text-xs text-indigo-600 hover:underline font-normal",children:"Show all"})]}),e.jsx(pe,{}),Js.map(d=>e.jsx(ke,{checked:!S.has(d),onCheckedChange:()=>P(d),onSelect:v=>v.preventDefault(),children:e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx(ne,{type:oe(d),className:"scale-90"}),e.jsx("span",{children:d})]})},d)),p.length>0&&e.jsx(pe,{}),p.map(d=>e.jsx(ke,{checked:!S.has(d.name),onCheckedChange:()=>P(d.name),onSelect:v=>v.preventDefault(),children:e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx(ne,{type:d.type,className:"scale-90"}),e.jsx("span",{children:d.name})]})},d.name))]})]})})]})}),e.jsx(ve,{children:j?e.jsx(K,{children:e.jsx(O,{colSpan:Math.max(1,G),className:"h-24 text-center",children:e.jsxs("div",{className:"flex items-center justify-center gap-2 py-4 text-muted-foreground text-sm",children:[e.jsx("span",{className:"inline-block h-4 w-4 animate-spin rounded-full border-2 border-current border-t-transparent"}),"Loading..."]})})}):t.items.length===0?e.jsx(K,{children:e.jsx(O,{colSpan:Math.max(1,G),className:"h-24 text-center",children:e.jsxs("div",{className:"flex flex-col items-center gap-2 py-4",children:[e.jsx("span",{className:"text-muted-foreground text-sm",children:"No records found."}),h&&!x&&e.jsxs(F,{variant:"outline",size:"sm",onClick:h,children:[e.jsx(ye,{className:"mr-1.5 h-3.5 w-3.5"}),"New record"]})]})})}):t.items.map(d=>e.jsxs(K,{className:"cursor-pointer hover:bg-muted/50",onClick:()=>l(d.id),children:[!x&&e.jsx(O,{onClick:v=>v.stopPropagation(),children:e.jsx(re,{checked:n.has(d.id),onCheckedChange:v=>r(d.id,!!v)})}),A&&e.jsx(O,{className:"font-mono text-xs text-muted-foreground",children:Q(d.id)}),y.map(v=>e.jsx(O,{className:`max-w-[260px] ${v.type==="relation"?"align-top":"truncate"}`,children:v.type==="file"?e.jsx(es,{collectionId:s.id,recordId:d.id,files:d[v.name]}):v.type==="relation"?q(d,v):he(d[v.name],v)},v.name)),b&&e.jsx(O,{className:"text-xs text-muted-foreground",children:Se(d.created)}),m&&e.jsx(O,{className:"text-xs text-muted-foreground",children:Se(d.updated)}),e.jsx(O,{})]},d.id))})]})}),!g&&t.totalItems>0&&e.jsxs("div",{className:"flex items-center justify-between px-2 pt-4",children:[e.jsxs("span",{className:"text-sm text-muted-foreground",children:[D,"-",z," of ",t.totalItems," records"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(F,{variant:"outline",size:"sm",onClick:()=>c(t.page-1),disabled:t.page<=1,children:[e.jsx(Ne,{className:"h-4 w-4"}),"Previous"]}),e.jsxs(F,{variant:"outline",size:"sm",onClick:()=>c(t.page+1),disabled:t.page>=t.totalPages,children:["Next",e.jsx(je,{className:"h-4 w-4"})]})]})]})]})}function Zs({field:s,value:t,onChange:n}){return e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs(E,{htmlFor:s.name,children:[s.name,s.required&&e.jsx("span",{className:"text-destructive ml-1",children:"*"})]}),e.jsx(H,{id:s.name,type:"text",value:t??"",onChange:a=>n(a.target.value),placeholder:`Enter ${s.name}...`})]})}function Xs({field:s,value:t,onChange:n}){const a=s.options??s,r=a.onlyInt,l=a.min,c=a.max;return e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs(E,{htmlFor:s.name,children:[s.name,s.required&&e.jsx("span",{className:"text-destructive ml-1",children:"*"})]}),e.jsx(H,{id:s.name,type:"number",step:r?1:"any",min:l,max:c,value:t==null?"":String(t),onChange:i=>{const h=i.target.value;n(h===""?null:r?parseInt(h,10):parseFloat(h))},placeholder:"0"})]})}function et({field:s,value:t,onChange:n}){return e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs(E,{htmlFor:s.name,children:[s.name,s.required&&e.jsx("span",{className:"text-destructive ml-1",children:"*"})]}),e.jsx(H,{id:s.name,type:"email",value:t??"",onChange:a=>n(a.target.value),placeholder:"user@example.com"})]})}function st({field:s,value:t,onChange:n}){return e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs(E,{htmlFor:s.name,children:[s.name,s.required&&e.jsx("span",{className:"text-destructive ml-1",children:"*"})]}),e.jsx(H,{id:s.name,type:"url",value:t??"",onChange:a=>n(a.target.value),placeholder:"https://..."})]})}function tt({field:s,value:t,onChange:n}){const a=t?String(t).replace(" ","T").substring(0,16):"";return e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs(E,{htmlFor:s.name,children:[s.name,s.required&&e.jsx("span",{className:"text-destructive ml-1",children:"*"})]}),e.jsx(H,{id:s.name,type:"datetime-local",value:a,onChange:r=>{const l=r.target.value;n(l?l.replace("T"," ")+":00.000Z":"")}})]})}function nt({field:s,value:t,onChange:n}){return e.jsxs("div",{className:"flex items-center space-x-2 py-2",children:[e.jsx(re,{id:s.name,checked:!!t,onCheckedChange:a=>n(!!a)}),e.jsx(E,{htmlFor:s.name,className:"cursor-pointer",children:s.name})]})}const me=o.forwardRef(({className:s,...t},n)=>e.jsx("textarea",{className:ae("flex min-h-[60px] w-full rounded-md border border-input bg-transparent px-3 py-2 text-sm shadow-sm placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50",s),ref:n,...t}));me.displayName="Textarea";function at({field:s,value:t,onChange:n}){const a=typeof t=="string"?t:t!=null?JSON.stringify(t,null,2):"",[r,l]=o.useState(a),[c,i]=o.useState(null),h=g=>{if(l(g),g.trim()===""){i(null),n(null);return}try{const j=JSON.parse(g);i(null),n(j)}catch{i("Invalid JSON")}};return e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs(E,{htmlFor:s.name,children:[s.name,s.required&&e.jsx("span",{className:"text-destructive ml-1",children:"*"})]}),e.jsx(me,{id:s.name,rows:4,value:r,onChange:g=>h(g.target.value),placeholder:"{}",className:c?"border-destructive":""}),c&&e.jsx("p",{className:"text-xs text-destructive",children:c})]})}function rt({field:s,value:t,onChange:n}){return e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs(E,{htmlFor:s.name,children:[s.name,s.required&&e.jsx("span",{className:"text-destructive ml-1",children:"*"})]}),e.jsx(me,{id:s.name,rows:6,value:t??"",onChange:a=>n(a.target.value),placeholder:"Enter rich text content..."})]})}function lt({field:s,value:t,onChange:n}){const a=s.options??s,r=a.values??[],c=(a.maxSelect??1)>1;if(r.length===0)return e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs(E,{htmlFor:s.name,children:[s.name,s.required&&e.jsx("span",{className:"text-destructive ml-1",children:"*"})]}),e.jsx(H,{id:s.name,type:"text",value:t??"",onChange:i=>n(i.target.value),placeholder:"Enter value..."}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"No select values configured"})]});if(c){const i=Array.isArray(t)?t:t?[String(t)]:[],h=g=>{const j=i.includes(g)?i.filter(k=>k!==g):[...i,g];n(j)};return e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(E,{children:s.name}),s.required&&e.jsx("span",{className:"text-destructive text-sm",children:"*"}),e.jsx(ce,{variant:"secondary",className:"text-xs",children:"multi"})]}),e.jsx("div",{className:"space-y-1.5 rounded-md border p-3",children:r.map(g=>e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(re,{id:`${s.name}-${g}`,checked:i.includes(g),onCheckedChange:()=>h(g)}),e.jsx(E,{htmlFor:`${s.name}-${g}`,className:"cursor-pointer font-normal",children:g})]},g))})]})}return e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs(E,{htmlFor:s.name,children:[s.name,s.required&&e.jsx("span",{className:"text-destructive ml-1",children:"*"})]}),e.jsxs(ws,{value:t??"",onValueChange:i=>n(i),children:[e.jsx(bs,{id:s.name,children:e.jsx(vs,{placeholder:"Select a value..."})}),e.jsx(Ns,{children:r.map(i=>e.jsx(Cs,{value:i,children:i},i))})]})]})}function it(s,t){var n;return s?((n=t==null?void 0:t.find(a=>a.id===s))==null?void 0:n.name)??s:"unknown"}function Pe({open:s,onOpenChange:t,targetCollectionId:n,collections:a,isMulti:r,selectedIds:l,onConfirm:c}){const[i,h]=o.useState(1),[g]=o.useState(15),[j,k]=o.useState(""),[L,x]=o.useState(""),[p,N]=o.useState(new Set(l));o.useEffect(()=>{s&&(N(new Set(l)),h(1),k(""),x(""))},[s,l]);const{data:D}=Le(n),z=o.useMemo(()=>D?ss(D):[{name:"id",op:"~"}],[D]),{data:S,isLoading:B}=We(n,{page:i,perPage:g,filter:L||void 0}),P=it(n,a),$=()=>{const f=ts(j,z);x(f),h(1)},y=()=>{k(""),x(""),h(1)},A=f=>{if(!r){c([f]),t(!1);return}N(T=>{const q=new Set(T);return q.has(f)?q.delete(f):q.add(f),q})},b=()=>{c(Array.from(p)),t(!1)},m=(S==null?void 0:S.items)??[],w=(S==null?void 0:S.totalPages)??1,R=!!n;return e.jsx(Ie,{open:s,onOpenChange:t,children:e.jsxs(Ae,{className:"max-w-3xl",children:[e.jsxs(as,{children:[e.jsxs(Ee,{children:["Select related record",r?"s":""]}),e.jsxs($e,{children:["Target collection: ",P]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(Te,{className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),e.jsx(H,{type:"text",placeholder:'Search or filter (ex: name ~ "john")...',value:j,onChange:f=>k(f.target.value),onKeyDown:f=>{f.key==="Enter"&&(f.preventDefault(),$())},className:"pl-9",disabled:!R})]}),e.jsx(F,{type:"button",variant:"outline",size:"sm",onClick:$,disabled:!R,children:"Search"}),e.jsx(F,{type:"button",variant:"ghost",size:"sm",onClick:y,disabled:!j&&!L,children:"Reset"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Tip: plain text searches across fields, full expressions are used as raw PocketBase filters."}),e.jsx("div",{className:"rounded-md border overflow-x-auto max-h-[380px] overflow-y-auto",children:e.jsxs(we,{children:[e.jsx(be,{children:e.jsxs(K,{children:[r&&e.jsx(V,{className:"w-10"}),e.jsx(V,{children:"ID"}),e.jsx(V,{children:"Display"})]})}),e.jsx(ve,{children:R?B?e.jsx(K,{children:e.jsx(O,{colSpan:r?3:2,className:"h-20 text-center",children:e.jsxs("div",{className:"inline-flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(ie,{size:"sm"}),"Loading records..."]})})}):m.length===0?e.jsx(K,{children:e.jsx(O,{colSpan:r?3:2,className:"h-20 text-center text-sm text-muted-foreground",children:"No records found."})}):m.map(f=>{const T=Ce(f)??Q(f.id),q=p.has(f.id);return e.jsxs(K,{className:`cursor-pointer hover:bg-muted/40 ${q?"bg-slate-100/70":""}`,onClick:()=>A(f.id),children:[r&&e.jsx(O,{onClick:G=>G.stopPropagation(),children:e.jsx(re,{checked:q,onCheckedChange:()=>A(f.id)})}),e.jsx(O,{className:"font-mono text-xs text-muted-foreground",children:Q(f.id)}),e.jsx(O,{className:"max-w-[420px] truncate",children:T})]},f.id)}):e.jsx(K,{children:e.jsx(O,{colSpan:r?3:2,className:"h-20 text-center text-sm text-muted-foreground",children:"No target collection configured for this relation field."})})})]})}),e.jsxs("div",{className:"flex items-center justify-between text-sm text-muted-foreground",children:[e.jsx("span",{children:r?`${p.size} selected`:"Click a row to select"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{children:["Page ",(S==null?void 0:S.page)??i," / ",w]}),e.jsx(F,{variant:"outline",size:"sm",onClick:()=>h(f=>Math.max(1,f-1)),disabled:i<=1,children:"Previous"}),e.jsx(F,{variant:"outline",size:"sm",onClick:()=>h(f=>f+1),disabled:i>=w,children:"Next"})]})]})]}),e.jsxs(rs,{children:[e.jsx(F,{variant:"outline",onClick:()=>t(!1),children:"Cancel"}),r&&e.jsxs(F,{onClick:b,children:["Apply selection (",p.size,")"]})]})]})})}function ot(s,t){if(Array.isArray(s))return s.map(a=>String(a).trim()).filter(Boolean);if(!s)return[];const n=String(s).trim();return t?n.split(",").map(a=>a.trim()).filter(Boolean):n?[n]:[]}function ct(s){return Array.isArray(s)?s.filter(t=>!!t&&typeof t=="object"&&"id"in t):s&&typeof s=="object"&&"id"in s?[s]:[]}function dt({field:s,value:t,onChange:n,collections:a,recordExpand:r,recordId:l}){const c=s.options??s,i=c.maxSelect??1,h=c.collectionId,g=i>1,j=!!l,k=a==null?void 0:a.find(y=>y.id===h),L=(k==null?void 0:k.name)??h??"unknown",[x,p]=o.useState(!1),N=o.useMemo(()=>ot(t,g),[t,g]),D=o.useMemo(()=>ct(r==null?void 0:r[s.name]),[r,s.name]),z=o.useMemo(()=>{if(D.length>0){const y=new Map(D.map(b=>[b.id,b])),A=N.map(b=>y.get(b)).filter(b=>!!b);if(A.length===N.length&&A.length>0)return A.map(b=>({id:b.id,label:Ce(b)??Q(b.id)}))}return N.map(y=>({id:y,label:Q(y)}))},[D,N]),S=!!h,B=y=>{if(!h)return;const A=`${window.location.origin}/_/collections/${encodeURIComponent(h)}?record=${encodeURIComponent(y)}`;window.open(A,"_blank","noopener,noreferrer")},P=y=>{if(g){n(y);return}n(y[0]??"")};if(g)return e.jsxs("div",{className:"space-y-2.5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(E,{htmlFor:s.name,children:s.name}),s.required&&e.jsx("span",{className:"text-destructive text-sm",children:"*"}),e.jsx(ce,{variant:"secondary",className:"text-xs",children:"relation"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(F,{type:"button",variant:"outline",size:"sm",onClick:()=>p(!0),disabled:!S,children:"Select records"}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:[N.length," selected"]})]}),e.jsx(me,{id:s.name,rows:3,value:N.join(", "),onChange:y=>{const A=y.target.value.split(",").map(b=>b.trim()).filter(Boolean);n(A)},placeholder:"Enter record IDs separated by commas...",readOnly:j,disabled:j}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Target collection: ",L]}),z.length>0&&e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-xs font-medium text-slate-600",children:"Selected relations"}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:z.map(y=>e.jsxs("button",{type:"button",className:"inline-flex max-w-full items-center gap-1 rounded-md border border-slate-200 px-2 py-0.5 text-xs text-slate-700 hover:border-slate-300 hover:bg-slate-50",onClick:()=>B(y.id),disabled:!S,title:`Open related record ${y.id}`,children:[e.jsx("span",{className:"truncate",children:y.label}),e.jsx(de,{className:"h-3 w-3 shrink-0"})]},`${s.name}-${y.id}`))})]}),e.jsx(Pe,{open:x,onOpenChange:p,targetCollectionId:h,collections:a,isMulti:!0,selectedIds:N,onConfirm:P})]});const $=N[0]??"";return e.jsxs("div",{className:"space-y-2.5",children:[e.jsxs(E,{htmlFor:s.name,children:[s.name,s.required&&e.jsx("span",{className:"text-destructive ml-1",children:"*"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(H,{id:s.name,type:"text",value:$,onChange:y=>n(y.target.value.trim()),placeholder:"Enter record ID...",readOnly:j,disabled:j}),e.jsx(F,{type:"button",variant:"outline",size:"sm",onClick:()=>p(!0),disabled:!S,children:"Select"})]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Target collection: ",L]}),z[0]&&e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-xs font-medium text-slate-600",children:"Selected relation"}),e.jsxs("button",{type:"button",className:"inline-flex max-w-full items-center gap-1 rounded-md border border-slate-200 px-2 py-0.5 text-xs text-slate-700 hover:border-slate-300 hover:bg-slate-50",onClick:()=>B(z[0].id),disabled:!S,title:`Open related record ${z[0].id}`,children:[e.jsx("span",{className:"truncate",children:z[0].label}),e.jsx(de,{className:"h-3 w-3 shrink-0"})]})]}),e.jsx(Pe,{open:x,onOpenChange:p,targetCollectionId:h,collections:a,isMulti:!1,selectedIds:$?[$]:[],onConfirm:P})]})}function mt(s){return s>=1024*1024?`${Math.round(s/1024/1024*10)/10}MB`:s>=1024?`${Math.round(s/1024)}KB`:`${s}B`}function ut({field:s,value:t,onChange:n,collectionId:a,recordId:r}){var y,A,b;const l=o.useRef(null),[c,i]=o.useState(!1),h=((y=s.options)==null?void 0:y.maxSelect)??s.maxSelect??1,g=h>1,j=((A=s.options)==null?void 0:A.maxSize)??s.maxSize,k=((b=s.options)==null?void 0:b.mimeTypes)??s.mimeTypes??[],L=()=>t?Array.isArray(t)?t.map(m=>typeof m=="string"?{name:m}:m instanceof File?{name:m.name,isNew:!0,file:m}:{name:String(m)}):typeof t=="string"?[{name:t}]:[]:[],[x,p]=o.useState(L);o.useEffect(()=>{p(L())},[t]);const N=m=>/\.(jpg|jpeg|png|gif|webp|svg)$/i.test(m),D=o.useCallback(m=>{if(m.length){if(j){for(const w of m)if(w.size>j){alert(`File "${w.name}" exceeds max size of ${Math.round(j/1024)}KB`);return}}if(k.length>0){for(const w of m)if(!k.some(f=>f.endsWith("/*")?w.type.startsWith(f.slice(0,-1)):w.type===f)){alert(`File "${w.name}" has unsupported type: ${w.type}`);return}}if(g){const w=h-x.length;if(w<=0){alert(`Maximum of ${h} files allowed.`);return}const R=m.slice(0,w);R.length<m.length&&alert(`Only ${w} more file(s) allowed. ${m.length-R.length} file(s) were ignored.`);const f=[...x,...R.map(T=>({name:T.name,isNew:!0,file:T}))];p(f),n(f.map(T=>T.file||T.name))}else{const w=m[0],R=[{name:w.name,isNew:!0,file:w}];p(R),n([w])}l.current&&(l.current.value="")}},[x,g,h,j,k,n]),z=m=>{D(Array.from(m.target.files||[]))},S=m=>{m.preventDefault(),i(!1),D(Array.from(m.dataTransfer.files||[]))},B=m=>{const w=x.filter((f,T)=>T!==m);p(w);const R=w.map(f=>f.file||f.name);n(R.length>0?R:"")},P=g?"Add files":x.length>0?"Change file":"Choose file",$=[];return j&&$.push(`Max ${mt(j)}`),k.length>0&&$.push(k.join(", ")),g&&$.push(`Up to ${h} files`),e.jsxs("div",{className:"space-y-2.5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(E,{children:s.name}),s.required&&e.jsx("span",{className:"text-destructive text-sm",children:"*"})]}),e.jsx("input",{ref:l,type:"file",multiple:g,accept:k.length>0?k.join(","):void 0,className:"hidden",onChange:z}),e.jsx("button",{type:"button",onClick:()=>{var m;return(m=l.current)==null?void 0:m.click()},onDragOver:m=>{m.preventDefault(),i(!0)},onDragLeave:m=>{m.preventDefault(),i(!1)},onDrop:S,className:ae("w-full rounded-xl border bg-slate-100/80 px-4 py-4 text-left transition-colors","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",c?"border-indigo-400 bg-indigo-50/70":"border-slate-300 hover:border-slate-400 hover:bg-slate-100"),children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"flex h-10 w-10 shrink-0 items-center justify-center rounded-full border border-slate-300 bg-white text-slate-500",children:e.jsx(As,{className:"h-4 w-4"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm font-medium text-slate-800",children:g?"Drop files here or click to browse":"Drop a file here or click to browse"}),$.length>0&&e.jsx("p",{className:"mt-0.5 truncate text-xs text-slate-500",children:$.join(" • ")})]}),e.jsxs("span",{className:"ml-auto inline-flex h-8 shrink-0 items-center gap-1 rounded-md border border-slate-300 bg-white px-2.5 text-xs font-medium text-slate-700",children:[e.jsx(ye,{className:"h-3.5 w-3.5"}),P]})]})}),x.length>0&&e.jsx("div",{className:"space-y-2",children:x.map((m,w)=>e.jsxs("div",{className:"flex items-center gap-3 rounded-lg border border-slate-200 bg-white p-2.5",children:[e.jsx("div",{className:"relative h-12 w-12 shrink-0 overflow-hidden rounded-md border bg-slate-50",children:m.isNew&&m.file&&N(m.name)?e.jsx("img",{src:URL.createObjectURL(m.file),alt:m.name,className:"h-full w-full object-cover",onLoad:R=>URL.revokeObjectURL(R.currentTarget.src)}):!m.isNew&&a&&r&&N(m.name)?e.jsx("div",{className:"absolute inset-0 p-0.5",children:e.jsx(es,{collectionId:a,recordId:r,files:m.name,className:"h-full w-full",size:"fill"})}):N(m.name)?e.jsx("div",{className:"flex h-full w-full items-center justify-center text-slate-400",children:e.jsx(Is,{className:"h-4 w-4"})}):e.jsx("div",{className:"flex h-full w-full items-center justify-center text-slate-400",children:e.jsx(xe,{className:"h-4 w-4"})})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"truncate text-sm font-medium text-slate-800",children:m.name}),e.jsx("p",{className:"text-xs text-slate-500",children:m.isNew?"New file":"Existing file"})]}),e.jsx(F,{type:"button",variant:"ghost",size:"sm",className:"h-8 w-8 p-0 text-slate-500 hover:text-destructive",onClick:()=>B(w),children:e.jsx(Me,{className:"h-4 w-4"})})]},`${m.name}-${w}`))})]})}const ht={text:Zs,editor:rt,number:Xs,bool:nt,email:et,url:st,date:tt,select:lt,json:at,file:ut,relation:dt};function pt(s){const t=ht[s.field.type];return t?e.jsx(t,{...s}):e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-sm font-medium",children:s.field.name}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Unsupported field type: ",s.field.type]})]})}function xt({record:s,trigger:t,onDuplicate:n,onDelete:a}){const r=()=>{navigator.clipboard.writeText(JSON.stringify(s,null,2))};return e.jsxs(ze,{children:[e.jsx(qe,{asChild:!0,children:t}),e.jsxs(Ue,{align:"end",children:[e.jsxs(ue,{onClick:r,children:[e.jsx(Ds,{className:"mr-2 h-4 w-4"}),"Copy raw JSON"]}),e.jsxs(ue,{onClick:n,children:[e.jsx(Fs,{className:"mr-2 h-4 w-4"}),"Duplicate"]}),e.jsx(pe,{}),e.jsxs(ue,{onClick:a,className:"text-destructive focus:text-destructive",children:[e.jsx(_e,{className:"mr-2 h-4 w-4"}),"Delete"]})]})]})}async function ft(s,t){await Z.request("POST",`/api/admins/${encodeURIComponent(s)}/change-password`,t)}const gt=[{name:"email",type:"email"},{name:"emailVisibility",type:"bool"},{name:"verified",type:"bool"}];function jt(s){const t=s.fields??s.schema??[];if(!(s.type==="auth"||s.name==="_superusers"))return t;const a=new Set(t.map(l=>l.name)),r=gt.filter(l=>!a.has(l.name));return[...t,...r]}function yt(s){const t=s.filter(n=>n.type==="relation").map(n=>n.name);if(t.length!==0)return t.join(",")}function wt({open:s,onClose:t,collection:n,recordId:a,duplicateData:r}){const l=Oe(),c=!!a,i=o.useMemo(()=>jt(n),[n.id,n.type,n.name,n.fields,n.schema]),h=o.useMemo(()=>yt(i),[i]),{data:g}=ls(),{data:j,isLoading:k}=Os(n.id,a??void 0,{expand:h}),L=zs(n.id),x=qs(n.id),p=Ze(n.id),[N,D]=o.useState({}),[z,S]=o.useState(!1),B=n.name==="_superusers",P=n.type==="auth"||B,$=i.filter(u=>!(P&&!c&&u.name==="email")),[y,A]=o.useState(!1),[b,m]=o.useState(""),[w,R]=o.useState(""),[f,T]=o.useState(!1),[q,G]=o.useState(""),[d,v]=o.useState(""),[U,J]=o.useState("");o.useEffect(()=>{if(s){if(r){const u={};for(const C of i)u[C.name]=r[C.name]??null;D(u)}else if(c&&j){const u={};for(const C of i)u[C.name]=j[C.name]??null;D(u)}else if(!c){const u={};for(const C of i)C.type==="bool"?u[C.name]=!1:u[C.name]=null;D(u)}}},[s,j,r,c,i]);const se=(u,C)=>{console.log("[RecordEditor] handleFieldChange:",u,C),D(ee=>({...ee,[u]:C}))},te=async()=>{if(console.log("[RecordEditor] handleSave formData:",JSON.stringify(N,(C,ee)=>ee instanceof File?`[File: ${ee.name}]`:ee,2)),!c&&P){if(!q){_.error("Email is required");return}if(!d){_.error("Password is required");return}if(d!==U){_.error("Passwords do not match");return}if(d.length<8){_.error("Password must be at least 8 characters");return}}const u={...N,...!c&&P?{email:q,password:d,passwordConfirm:U}:{}};try{c?(await x.mutateAsync({id:a,data:N}),_.success("Record updated successfully")):(await L.mutateAsync(u),_.success("Record created successfully")),t()}catch(C){const ee=C&&typeof C=="object"&&"message"in C?String(C.message):"Failed to save record";_.error(ee)}},X=async()=>{if(a){if(b!==w){_.error("Passwords do not match");return}if(b.length<8){_.error("Password must be at least 8 characters");return}T(!0);try{await ft(a,{password:b,passwordConfirm:w}),_.success("Password changed successfully. Please log in again."),localStorage.removeItem("ppbase_token"),localStorage.removeItem("ppbase_admin"),t(),l("/login")}catch(u){const C=u&&typeof u=="object"&&"message"in u?String(u.message):"Failed to change password";_.error(C)}finally{T(!1)}}},W=async()=>{if(a)try{await p.mutateAsync(a),_.success("Record deleted successfully"),S(!1),t()}catch(u){const C=u&&typeof u=="object"&&"message"in u?String(u.message):"Failed to delete record";_.error(C)}},le=()=>{if(!j)return;const u={};for(const C of i)u[C.name]=j[C.name]??null;window.dispatchEvent(new CustomEvent("ppbase:duplicate-record",{detail:{data:u,closeCurrent:!0}}))},I=L.isPending||x.isPending,M=c?`Edit ${n.name} record`:`New ${n.name} record`;return e.jsxs(e.Fragment,{children:[e.jsx(He,{open:s,onOpenChange:u=>!u&&t(),children:e.jsxs(Ve,{className:"sm:max-w-[700px] flex flex-col overflow-hidden",showCloseButton:!1,children:[e.jsxs(Ke,{className:"shrink-0 px-6 pt-6 pb-4",children:[e.jsxs("div",{className:"flex items-center justify-end gap-3",children:[e.jsx(Je,{className:"flex-1",children:M}),c&&j&&e.jsx(xt,{record:j,trigger:e.jsx(F,{variant:"ghost",size:"icon",className:"h-8 w-8",children:e.jsx(xs,{className:"h-4 w-4"})}),onDuplicate:le,onDelete:()=>S(!0)})]}),e.jsx(js,{children:c&&a&&e.jsxs("span",{className:"font-mono text-xs",children:["ID: ",a]})})]}),e.jsx("div",{className:"border-t shrink-0"}),e.jsx("div",{className:"flex-1 overflow-y-auto px-6",children:c&&k?e.jsx("div",{className:"flex justify-center py-12",children:e.jsx(ie,{})}):e.jsxs("div",{className:"space-y-4 py-4",children:[!c&&P&&e.jsxs("div",{className:"space-y-3 pb-2 border-b",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(E,{htmlFor:"auth-email",children:"Email *"}),e.jsx(H,{id:"auth-email",type:"email",placeholder:"user@example.com",value:q,onChange:u=>G(u.target.value)})]}),e.jsxs("div",{className:"flex gap-3",children:[e.jsxs("div",{className:"flex-1 space-y-1.5",children:[e.jsx(E,{htmlFor:"auth-password",children:"Password *"}),e.jsx(H,{id:"auth-password",type:"password",placeholder:"Min. 8 characters",value:d,onChange:u=>v(u.target.value)})]}),e.jsxs("div",{className:"flex-1 space-y-1.5",children:[e.jsx(E,{htmlFor:"auth-password-confirm",children:"Confirm *"}),e.jsx(H,{id:"auth-password-confirm",type:"password",placeholder:"Repeat password",value:U,onChange:u=>J(u.target.value)})]})]})]}),$.map(u=>e.jsx(pt,{field:u,value:N[u.name],onChange:C=>se(u.name,C),collections:g,recordId:j==null?void 0:j.id,collectionId:n.id,recordExpand:j==null?void 0:j.expand},u.name)),$.length===0&&!P&&e.jsx("p",{className:"text-sm text-muted-foreground py-4",children:"This collection has no editable fields."}),P&&c&&e.jsxs("div",{className:"border-t pt-4 mt-4 space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(re,{id:"change-password-toggle",checked:y,onCheckedChange:u=>{A(!!u),u||(m(""),R(""))}}),e.jsx(E,{htmlFor:"change-password-toggle",className:"cursor-pointer font-medium",children:"Change password"})]}),y&&e.jsxs("div",{className:"flex gap-4",children:[e.jsxs("div",{className:"flex-1 space-y-1.5",children:[e.jsx(E,{htmlFor:"new-password",children:"New Password *"}),e.jsx(H,{id:"new-password",type:"password",placeholder:"Min. 8 characters",value:b,onChange:u=>m(u.target.value)})]}),e.jsxs("div",{className:"flex-1 space-y-1.5",children:[e.jsx(E,{htmlFor:"confirm-password",children:"Confirm Password *"}),e.jsx(H,{id:"confirm-password",type:"password",placeholder:"Confirm password",value:w,onChange:u=>R(u.target.value)})]})]}),y&&e.jsxs(F,{onClick:X,disabled:f||!b||!w,variant:"destructive",children:[f&&e.jsx(ie,{size:"sm",className:"mr-2"}),"Change Password"]})]})]})}),e.jsx("div",{className:"border-t shrink-0"}),e.jsxs(ys,{className:"shrink-0 px-6 py-2.5",children:[e.jsx(F,{variant:"outline",onClick:t,disabled:I,children:"Cancel"}),e.jsxs(F,{onClick:te,disabled:I||i.length===0&&!P,children:[I&&e.jsx(ie,{size:"sm",className:"mr-2"}),c?"Save changes":"Create"]})]})]})}),e.jsx(Be,{open:z,onOpenChange:S,title:"Delete record",description:"Are you sure you want to delete this record? This action cannot be undone.",confirmLabel:"Delete",variant:"destructive",onConfirm:W})]})}function bt(s){return[{id:"list",label:"List/Search",title:`List/Search (${s})`,description:`Fetch a paginated <strong>${s}</strong> records list, supporting sorting and filtering.`,method:"GET",methodClass:"bg-green-100 text-green-700",path:`/api/collections/${s}/records`,note:"Requires superuser <code>Authorization:TOKEN</code> header",params:[{name:"page",type:"Number",desc:"The page (aka. offset) of the paginated list (default to 1)."},{name:"perPage",type:"Number",desc:"Specify the max returned records per page (default to 30)."},{name:"sort",type:"String",desc:"Specify the records order attribute(s). Add - / + (default) in front of the attribute for DESC and ASC order."},{name:"filter",type:"String",desc:"Filter expression to filter/search the returned records list."},{name:"expand",type:"String",desc:"Auto expand record relations."}],code:`<span class="hl-comment">// fetch a paginated records list</span>
|
|
47
47
|
<span class="hl-keyword">const</span> <span class="hl-var">resultList</span> = <span class="hl-keyword">await</span> pb.<span class="hl-func">collection</span>(<span class="hl-string">'${s}'</span>).<span class="hl-func">getList</span>(1, 50, {
|
|
48
48
|
filter: <span class="hl-string">'someField1 != someField2'</span>,
|
|
49
49
|
});
|
|
@@ -62,4 +62,4 @@ import{c as Y,B as Z,E as Re,M as fe,Q as ge,R as Q,r as o,j as e,g as ae,T as I
|
|
|
62
62
|
<span class="hl-comment">// ... your data</span>
|
|
63
63
|
});`},{id:"update",label:"Update",title:`Update (${s})`,description:`Update an existing <strong>${s}</strong> record.`,method:"PATCH",methodClass:"bg-amber-100 text-amber-700",path:`/api/collections/${s}/records/:id`,params:[],code:`<span class="hl-keyword">const</span> <span class="hl-var">record</span> = <span class="hl-keyword">await</span> pb.<span class="hl-func">collection</span>(<span class="hl-string">'${s}'</span>).<span class="hl-func">update</span>(<span class="hl-string">'RECORD_ID'</span>, {
|
|
64
64
|
<span class="hl-comment">// ... your data</span>
|
|
65
|
-
});`},{id:"delete",label:"Delete",title:`Delete (${s})`,description:`Delete a single <strong>${s}</strong> record.`,method:"DELETE",methodClass:"bg-red-100 text-red-700",path:`/api/collections/${s}/records/:id`,params:[],code:`<span class="hl-keyword">await</span> pb.<span class="hl-func">collection</span>(<span class="hl-string">'${s}'</span>).<span class="hl-func">delete</span>(<span class="hl-string">'RECORD_ID'</span>);`}]}function vt({open:s,onClose:t,collection:n}){const[a,r]=o.useState("list"),l=bt(n.name),c=l.find(i=>i.id===a)||l[0];return e.jsx(He,{open:s,onOpenChange:i=>!i&&t(),children:e.jsxs(Ve,{side:"right",className:"w-full sm:max-w-4xl p-0 flex flex-col",children:[e.jsx(
|
|
65
|
+
});`},{id:"delete",label:"Delete",title:`Delete (${s})`,description:`Delete a single <strong>${s}</strong> record.`,method:"DELETE",methodClass:"bg-red-100 text-red-700",path:`/api/collections/${s}/records/:id`,params:[],code:`<span class="hl-keyword">await</span> pb.<span class="hl-func">collection</span>(<span class="hl-string">'${s}'</span>).<span class="hl-func">delete</span>(<span class="hl-string">'RECORD_ID'</span>);`}]}function vt({open:s,onClose:t,collection:n}){const[a,r]=o.useState("list"),l=bt(n.name),c=l.find(i=>i.id===a)||l[0];return e.jsx(He,{open:s,onOpenChange:i=>!i&&t(),children:e.jsxs(Ve,{side:"right",className:"w-full sm:max-w-4xl p-0 flex flex-col",children:[e.jsx(Ke,{className:"px-6 pt-6 pb-4 border-b",children:e.jsx(Je,{children:"API Preview"})}),e.jsxs("div",{className:"flex flex-1 overflow-hidden",children:[e.jsx("div",{className:"w-40 shrink-0 border-r bg-muted/30 py-2",children:l.map(i=>e.jsx("button",{className:ae("w-full text-left px-4 py-2 text-sm transition-colors mb-1",a===i.id?"bg-muted font-medium text-foreground":"text-muted-foreground hover:text-foreground hover:bg-muted"),onClick:()=>r(i.id),children:i.label},i.id))}),e.jsxs("div",{className:"flex-1 overflow-y-auto p-6 space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-base font-semibold",children:c.title}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",dangerouslySetInnerHTML:{__html:c.description}})]}),e.jsx("div",{className:"rounded-lg bg-slate-950 text-slate-50 p-4 text-sm font-mono overflow-x-auto",children:e.jsx("pre",{children:e.jsx("code",{dangerouslySetInnerHTML:{__html:c.code}})})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"JavaScript SDK"}),e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-semibold mb-2",children:"API details"}),e.jsxs("div",{className:"flex items-center gap-2 rounded-lg border p-3 bg-muted/30",children:[e.jsx(ce,{variant:"outline",className:ae("font-mono text-xs font-bold",c.methodClass),children:c.method}),e.jsx("code",{className:"text-sm font-mono",children:c.path})]}),c.note&&e.jsx("p",{className:"text-xs text-muted-foreground mt-2",dangerouslySetInnerHTML:{__html:c.note}})]}),c.params.length>0&&e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-semibold mb-2",children:"Query parameters"}),e.jsx("div",{className:"rounded-lg border",children:e.jsxs(we,{children:[e.jsx(be,{children:e.jsxs(K,{children:[e.jsx(V,{children:"Param"}),e.jsx(V,{children:"Type"}),e.jsx(V,{children:"Description"})]})}),e.jsx(ve,{children:c.params.map(i=>e.jsxs(K,{children:[e.jsx(O,{className:"font-medium",children:i.name}),e.jsx(O,{children:e.jsx(ce,{variant:"secondary",className:"text-xs",children:i.type})}),e.jsx(O,{className:"text-sm text-muted-foreground",dangerouslySetInnerHTML:{__html:i.desc}})]},i.name))})]})})]})]})]})]})})}function Nt(s){const[t,n]=o.useState(()=>typeof window>"u"?!1:window.matchMedia(s).matches);return o.useEffect(()=>{const a=window.matchMedia(s),r=()=>n(a.matches);return a.addEventListener("change",r),()=>a.removeEventListener("change",r)},[s]),t}function Ct({count:s,onReset:t,onDelete:n}){const{collectionsPanelWidth:a}=is(),r=Nt("(min-width: 768px)"),l=60+a;return s===0?null:e.jsxs("div",{className:"fixed bottom-0 left-0 right-0 z-40 flex flex-wrap items-center gap-2 sm:gap-3 border-t bg-white px-4 py-3 md:px-6 shadow-lg",style:{marginLeft:r?l:0},children:[e.jsxs("span",{className:"text-sm font-medium",children:["Selected ",s," record",s!==1?"s":""]}),e.jsxs(F,{variant:"ghost",size:"sm",onClick:t,children:[e.jsx(Me,{className:"mr-1 h-3 w-3"}),"Reset"]}),e.jsx("div",{className:"flex-1"}),e.jsxs(F,{variant:"destructive",size:"sm",onClick:n,children:[e.jsx(_e,{className:"mr-1 h-4 w-4"}),"Delete selected"]})]})}function St(s){const t=s.filter(n=>n.type==="relation").map(n=>n.name);if(t.length!==0)return t.join(",")}function _t(){const{id:s}=os(),t=Oe(),[n,a]=cs(),{data:r,isLoading:l}=Le(s),[c,i]=o.useState(1),[h]=o.useState(30),[g,j]=o.useState(""),k=o.useMemo(()=>(r==null?void 0:r.fields)??(r==null?void 0:r.schema)??[],[r]),L=o.useMemo(()=>St(k),[k]),{data:x,isLoading:p,isError:N,error:D,refetch:z}=We(s,{page:c,perPage:h,filter:g||void 0,expand:L});o.useEffect(()=>{j(""),i(1)},[s]);const S=Ze(s??""),[B,P]=o.useState(!1),[$,y]=o.useState(null),[A,b]=o.useState(null),[m,w]=o.useState(new Set),[R,f]=o.useState(!1),[T,q]=o.useState(!1),[G,d]=o.useState(!1),v=(r==null?void 0:r.type)==="view";o.useEffect(()=>{if(!r)return;const I=n.get("record");if(!I)return;y(I),b(null),P(!0);const M=new URLSearchParams(n);M.delete("record"),a(M,{replace:!0})},[r,n,a]),o.useEffect(()=>{const I=M=>{const{data:u,closeCurrent:C}=M.detail;C&&(P(!1),y(null),b(null)),setTimeout(()=>{b({...u}),P(!0)},100)};return window.addEventListener("ppbase:duplicate-record",I),()=>window.removeEventListener("ppbase:duplicate-record",I)},[]);const U=o.useCallback(I=>{y(I),b(null),P(!0)},[]),J=o.useCallback(()=>{y(null),b(null),P(!0)},[]),se=o.useCallback(()=>{P(!1),y(null),b(null)},[]),te=o.useCallback(I=>{j(I),i(1)},[]),X=o.useCallback(I=>{x&&w(I?new Set(x.items.map(M=>M.id)):new Set)},[x]),W=o.useCallback((I,M)=>{w(u=>{const C=new Set(u);return M?C.add(I):C.delete(I),C})},[]),le=async()=>{const I=Array.from(m);try{for(const M of I)await S.mutateAsync(M);_.success(`Deleted ${I.length} record${I.length!==1?"s":""}`),w(new Set),f(!1)}catch(M){const u=M&&typeof M=="object"&&"message"in M?String(M.message):"Failed to delete records";_.error(u)}};return l?e.jsx(ie,{fullPage:!0}):r?e.jsxs(e.Fragment,{children:[e.jsx(us,{left:e.jsxs(hs,{items:[{label:"Collections",onClick:()=>t("/collections")},{label:r.name,active:!0}],children:[e.jsx("button",{onClick:()=>d(!0),className:"ml-0.5 rounded p-1 text-muted-foreground hover:text-foreground hover:bg-muted",title:"Collection settings",children:e.jsx(ms,{className:"h-4.5 w-4.5"})}),e.jsx("button",{onClick:()=>z(),className:"rounded p-1 text-muted-foreground hover:text-foreground hover:bg-muted",title:"Refresh records",children:e.jsx(Ss,{className:"h-4.5 w-4.5"})})]}),right:e.jsxs(e.Fragment,{children:[e.jsxs(F,{variant:"outline",size:"sm",onClick:()=>q(!0),children:[e.jsx(ks,{className:"mr-1 h-3.5 w-3.5"}),"API Preview"]}),!v&&e.jsxs(F,{size:"sm",onClick:J,children:[e.jsx(ye,{className:"mr-1 h-3.5 w-3.5"}),"New record"]})]})}),e.jsxs("div",{className:"flex-1 overflow-auto p-4 md:p-6",children:[N&&D&&e.jsx("div",{className:"mb-4 rounded-md border border-destructive/50 bg-destructive/10 px-4 py-3 text-sm text-destructive",children:typeof D=="object"&&"message"in D?String(D.message):"Failed to load records. Check your connection and try again."}),e.jsx(Ws,{collection:r,records:x??{items:[],page:1,perPage:h,totalItems:0,totalPages:0},selectedIds:m,onSelectAll:X,onSelectRow:W,onRowClick:U,onPageChange:i,onFilterChange:te,onNewRecord:J,hidePagination:!0,isLoading:p},r.id)]}),x&&x.totalItems>0&&e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-2 border-t bg-white px-4 py-3 md:px-8",children:[e.jsxs("span",{className:"text-sm text-muted-foreground",children:[(x.page-1)*x.perPage+1,"-",Math.min(x.page*x.perPage,x.totalItems)," of"," ",x.totalItems," records"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(F,{variant:"outline",size:"sm",onClick:()=>i(x.page-1),disabled:x.page<=1,children:[e.jsx(Ne,{className:"h-4 w-4"}),"Previous"]}),e.jsxs(F,{variant:"outline",size:"sm",onClick:()=>i(x.page+1),disabled:x.page>=x.totalPages,children:["Next",e.jsx(je,{className:"h-4 w-4"})]})]})]}),m.size>0&&e.jsx(Ct,{count:m.size,onReset:()=>w(new Set),onDelete:()=>f(!0)}),e.jsx(wt,{open:B,onClose:se,collection:r,recordId:$,duplicateData:A}),e.jsx(Be,{open:R,onOpenChange:f,title:"Delete selected records",description:`Are you sure you want to delete ${m.size} record${m.size!==1?"s":""}? This action cannot be undone.`,confirmLabel:"Delete",variant:"destructive",onConfirm:le}),e.jsx(vt,{open:T,onClose:()=>q(!1),collection:r}),e.jsx(fs,{open:G,onClose:()=>d(!1),onDelete:()=>t("/collections"),mode:"edit",collectionId:r.id})]}):e.jsx(gs,{icon:e.jsx(ds,{className:"h-6 w-6"}),title:"Collection not found",description:"The collection you are looking for does not exist.",action:{label:"Back to collections",onClick:()=>t("/collections")}})}export{_t as RecordsPage};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{j as o,g as n}from"./index-
|
|
1
|
+
import{j as o,g as n}from"./index-BWzNXVt7.js";import{a}from"./button-B7j1u3OP.js";const s=a("inline-flex items-center rounded-lg border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",{variants:{variant:{default:"border-transparent bg-primary text-primary-foreground shadow-sm hover:bg-primary/80",secondary:"border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80",destructive:"border-transparent bg-destructive text-destructive-foreground shadow-sm hover:bg-destructive/80",outline:"text-foreground"}},defaultVariants:{variant:"default"}});function u({className:r,variant:e,...t}){return o.jsx("div",{className:n(s({variant:e}),r),...t})}export{u as B};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{j as e,g as a}from"./index-
|
|
1
|
+
import{j as e,g as a}from"./index-BWzNXVt7.js";function x({left:t,right:s}){return e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-3 px-6 py-4 md:px-8 md:py-4.5 border-b bg-white shrink-0 shadow-sm",children:[e.jsx("div",{className:"flex items-center gap-3 min-w-0",children:t}),s&&e.jsx("div",{className:"flex items-center gap-2.5 flex-shrink-0 flex-wrap",children:s})]})}function o({items:t,children:s}){return e.jsxs("div",{className:"flex items-center gap-2 text-[15px] md:text-[16px] min-w-0 flex-wrap",children:[t.map((n,r)=>e.jsxs("span",{className:"flex items-center gap-2",children:[r>0&&e.jsx("span",{className:"text-muted-foreground/40 font-light select-none",children:"/"}),e.jsx("span",{className:a("truncate max-w-[200px] sm:max-w-none transition-colors",n.active?"font-semibold text-foreground":"text-muted-foreground cursor-pointer hover:text-foreground"),onClick:n.onClick,title:n.label,children:n.label})]},r)),s]})}export{o as B,x as C};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as a,j as m,ao as E,a1 as S,ap as V,g as j}from"./index-
|
|
1
|
+
import{r as a,j as m,ao as E,a1 as S,ap as V,g as j}from"./index-BWzNXVt7.js";var w=Symbol.for("react.lazy"),y=E[" use ".trim().toString()];function N(e){return typeof e=="object"&&e!==null&&"then"in e}function x(e){return e!=null&&typeof e=="object"&&"$$typeof"in e&&e.$$typeof===w&&"_payload"in e&&N(e._payload)}function R(e){const n=P(e),t=a.forwardRef((o,r)=>{let{children:i,...u}=o;x(i)&&typeof y=="function"&&(i=y(i._payload));const l=a.Children.toArray(i),f=l.find(A);if(f){const s=f.props.children,d=l.map(c=>c===f?a.Children.count(s)>1?a.Children.only(null):a.isValidElement(s)?s.props.children:null:c);return m.jsx(n,{...u,ref:r,children:a.isValidElement(s)?a.cloneElement(s,void 0,d):null})}return m.jsx(n,{...u,ref:r,children:i})});return t.displayName=`${e}.Slot`,t}var O=R("Slot");function P(e){const n=a.forwardRef((t,o)=>{let{children:r,...i}=t;if(x(r)&&typeof y=="function"&&(r=y(r._payload)),a.isValidElement(r)){const u=$(r),l=k(i,r.props);return r.type!==a.Fragment&&(l.ref=o?S(o,u):u),a.cloneElement(r,l)}return a.Children.count(r)>1?a.Children.only(null):null});return n.displayName=`${e}.SlotClone`,n}var z=Symbol("radix.slottable");function A(e){return a.isValidElement(e)&&typeof e.type=="function"&&"__radixId"in e.type&&e.type.__radixId===z}function k(e,n){const t={...n};for(const o in n){const r=e[o],i=n[o];/^on[A-Z]/.test(o)?r&&i?t[o]=(...l)=>{const f=i(...l);return r(...l),f}:r&&(t[o]=r):o==="style"?t[o]={...r,...i}:o==="className"&&(t[o]=[r,i].filter(Boolean).join(" "))}return{...e,...t}}function $(e){var o,r;let n=(o=Object.getOwnPropertyDescriptor(e.props,"ref"))==null?void 0:o.get,t=n&&"isReactWarning"in n&&n.isReactWarning;return t?e.ref:(n=(r=Object.getOwnPropertyDescriptor(e,"ref"))==null?void 0:r.get,t=n&&"isReactWarning"in n&&n.isReactWarning,t?e.props.ref:e.props.ref||e.ref)}const b=e=>typeof e=="boolean"?`${e}`:e===0?"0":e,h=V,T=(e,n)=>t=>{var o;if((n==null?void 0:n.variants)==null)return h(e,t==null?void 0:t.class,t==null?void 0:t.className);const{variants:r,defaultVariants:i}=n,u=Object.keys(r).map(s=>{const d=t==null?void 0:t[s],c=i==null?void 0:i[s];if(d===null)return null;const v=b(d)||b(c);return r[s][v]}),l=t&&Object.entries(t).reduce((s,d)=>{let[c,v]=d;return v===void 0||(s[c]=v),s},{}),f=n==null||(o=n.compoundVariants)===null||o===void 0?void 0:o.reduce((s,d)=>{let{class:c,className:v,..._}=d;return Object.entries(_).every(C=>{let[g,p]=C;return Array.isArray(p)?p.includes({...i,...l}[g]):{...i,...l}[g]===p})?[...s,c,v]:s},[]);return h(e,u,f,t==null?void 0:t.class,t==null?void 0:t.className)},W=T("inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-lg font-medium transition-all duration-150 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1 disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 active:scale-[0.98]",{variants:{variant:{default:"bg-primary text-primary-foreground shadow-sm hover:bg-primary/90 hover:shadow-md",destructive:"bg-destructive text-destructive-foreground shadow-sm hover:bg-destructive/90",outline:"border border-input bg-background shadow-sm hover:bg-accent hover:text-accent-foreground hover:border-slate-300",secondary:"bg-secondary text-secondary-foreground shadow-sm hover:bg-secondary/80",ghost:"hover:bg-accent hover:text-accent-foreground",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-11 px-5 py-2.5 text-[15px] [&_svg]:size-[18px]",sm:"h-9 rounded-md px-3.5 text-sm [&_svg]:size-4",lg:"h-12 rounded-xl px-7 text-base [&_svg]:size-5",icon:"h-11 w-11 [&_svg]:size-[18px]"}},defaultVariants:{variant:"default",size:"default"}}),B=a.forwardRef(({className:e,variant:n,size:t,asChild:o=!1,...r},i)=>{const u=o?O:"button";return m.jsx(u,{className:j(W({variant:n,size:t,className:e})),ref:i,...r})});B.displayName="Button";export{B,T as a,R as c};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as a,j as c,u as q,P as y,d as R,f as L,b as O,a as B,a2 as Te,e as z,g as F}from"./index-CBybCNw9.js";import{e as ye,u as H,g as we}from"./select-43JIRBNM.js";import{u as Ee}from"./index-CQBLo7m8.js";import{C as _e}from"./check-B5gBbN7b.js";var D="rovingFocusGroup.onEntryFocus",Fe={bubbles:!1,cancelable:!0},N="RovingFocusGroup",[G,Y,Ne]=ye(N),[Se,X]=L(N,[Ne]),[Pe,je]=Se(N),J=a.forwardRef((e,t)=>c.jsx(G.Provider,{scope:e.__scopeRovingFocusGroup,children:c.jsx(G.Slot,{scope:e.__scopeRovingFocusGroup,children:c.jsx(Ae,{...e,ref:t})})}));J.displayName=N;var Ae=a.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:o,orientation:n,loop:u=!1,dir:r,currentTabStopId:i,defaultCurrentTabStopId:b,onCurrentTabStopIdChange:m,onEntryFocus:v,preventScrollOnEntryFocus:s=!1,...d}=e,p=a.useRef(null),T=O(t,p),x=H(r),[k,l]=B({prop:i,defaultProp:b??null,onChange:m,caller:N}),[f,g]=a.useState(!1),h=Te(v),I=Y(o),_=a.useRef(!1),[A,S]=a.useState(0);return a.useEffect(()=>{const C=p.current;if(C)return C.addEventListener(D,h),()=>C.removeEventListener(D,h)},[h]),c.jsx(Pe,{scope:o,orientation:n,dir:x,loop:u,currentTabStopId:k,onItemFocus:a.useCallback(C=>l(C),[l]),onItemShiftTab:a.useCallback(()=>g(!0),[]),onFocusableItemAdd:a.useCallback(()=>S(C=>C+1),[]),onFocusableItemRemove:a.useCallback(()=>S(C=>C-1),[]),children:c.jsx(y.div,{tabIndex:f||A===0?-1:0,"data-orientation":n,...d,ref:T,style:{outline:"none",...e.style},onMouseDown:R(e.onMouseDown,()=>{_.current=!0}),onFocus:R(e.onFocus,C=>{const xe=!_.current;if(C.target===C.currentTarget&&xe&&!f){const V=new CustomEvent(D,Fe);if(C.currentTarget.dispatchEvent(V),!V.defaultPrevented){const M=I().filter(E=>E.focusable),Ie=M.find(E=>E.active),ke=M.find(E=>E.id===k),Re=[Ie,ke,...M].filter(Boolean).map(E=>E.ref.current);Z(Re,s)}}_.current=!1}),onBlur:R(e.onBlur,()=>g(!1))})})}),Q="RovingFocusGroupItem",W=a.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:o,focusable:n=!0,active:u=!1,tabStopId:r,children:i,...b}=e,m=q(),v=r||m,s=je(Q,o),d=s.currentTabStopId===v,p=Y(o),{onFocusableItemAdd:T,onFocusableItemRemove:x,currentTabStopId:k}=s;return a.useEffect(()=>{if(n)return T(),()=>x()},[n,T,x]),c.jsx(G.ItemSlot,{scope:o,id:v,focusable:n,active:u,children:c.jsx(y.span,{tabIndex:d?0:-1,"data-orientation":s.orientation,...b,ref:t,onMouseDown:R(e.onMouseDown,l=>{n?s.onItemFocus(v):l.preventDefault()}),onFocus:R(e.onFocus,()=>s.onItemFocus(v)),onKeyDown:R(e.onKeyDown,l=>{if(l.key==="Tab"&&l.shiftKey){s.onItemShiftTab();return}if(l.target!==l.currentTarget)return;const f=Ge(l,s.orientation,s.dir);if(f!==void 0){if(l.metaKey||l.ctrlKey||l.altKey||l.shiftKey)return;l.preventDefault();let h=p().filter(I=>I.focusable).map(I=>I.ref.current);if(f==="last")h.reverse();else if(f==="prev"||f==="next"){f==="prev"&&h.reverse();const I=h.indexOf(l.currentTarget);h=s.loop?Le(h,I+1):h.slice(I+1)}setTimeout(()=>Z(h))}}),children:typeof i=="function"?i({isCurrentTabStop:d,hasTabStop:k!=null}):i})})});W.displayName=Q;var Me={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function De(e,t){return t!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function Ge(e,t,o){const n=De(e.key,o);if(!(t==="vertical"&&["ArrowLeft","ArrowRight"].includes(n))&&!(t==="horizontal"&&["ArrowUp","ArrowDown"].includes(n)))return Me[n]}function Z(e,t=!1){const o=document.activeElement;for(const n of e)if(n===o||(n.focus({preventScroll:t}),document.activeElement!==o))return}function Le(e,t){return e.map((o,n)=>e[(t+n)%e.length])}var Oe=J,Be=W,P="Tabs",[Ke]=L(P,[X]),ee=X(),[Ue,K]=Ke(P),te=a.forwardRef((e,t)=>{const{__scopeTabs:o,value:n,onValueChange:u,defaultValue:r,orientation:i="horizontal",dir:b,activationMode:m="automatic",...v}=e,s=H(b),[d,p]=B({prop:n,onChange:u,defaultProp:r??"",caller:P});return c.jsx(Ue,{scope:o,baseId:q(),value:d,onValueChange:p,orientation:i,dir:s,activationMode:m,children:c.jsx(y.div,{dir:s,"data-orientation":i,...v,ref:t})})});te.displayName=P;var oe="TabsList",ne=a.forwardRef((e,t)=>{const{__scopeTabs:o,loop:n=!0,...u}=e,r=K(oe,o),i=ee(o);return c.jsx(Oe,{asChild:!0,...i,orientation:r.orientation,dir:r.dir,loop:n,children:c.jsx(y.div,{role:"tablist","aria-orientation":r.orientation,...u,ref:t})})});ne.displayName=oe;var re="TabsTrigger",ae=a.forwardRef((e,t)=>{const{__scopeTabs:o,value:n,disabled:u=!1,...r}=e,i=K(re,o),b=ee(o),m=ie(i.baseId,n),v=ue(i.baseId,n),s=n===i.value;return c.jsx(Be,{asChild:!0,...b,focusable:!u,active:s,children:c.jsx(y.button,{type:"button",role:"tab","aria-selected":s,"aria-controls":v,"data-state":s?"active":"inactive","data-disabled":u?"":void 0,disabled:u,id:m,...r,ref:t,onMouseDown:R(e.onMouseDown,d=>{!u&&d.button===0&&d.ctrlKey===!1?i.onValueChange(n):d.preventDefault()}),onKeyDown:R(e.onKeyDown,d=>{[" ","Enter"].includes(d.key)&&i.onValueChange(n)}),onFocus:R(e.onFocus,()=>{const d=i.activationMode!=="manual";!s&&!u&&d&&i.onValueChange(n)})})})});ae.displayName=re;var se="TabsContent",ce=a.forwardRef((e,t)=>{const{__scopeTabs:o,value:n,forceMount:u,children:r,...i}=e,b=K(se,o),m=ie(b.baseId,n),v=ue(b.baseId,n),s=n===b.value,d=a.useRef(s);return a.useEffect(()=>{const p=requestAnimationFrame(()=>d.current=!1);return()=>cancelAnimationFrame(p)},[]),c.jsx(z,{present:u||s,children:({present:p})=>c.jsx(y.div,{"data-state":s?"active":"inactive","data-orientation":b.orientation,role:"tabpanel","aria-labelledby":m,hidden:!p,id:v,tabIndex:0,...i,ref:t,style:{...e.style,animationDuration:d.current?"0s":void 0},children:p&&r})})});ce.displayName=se;function ie(e,t){return`${e}-trigger-${t}`}function ue(e,t){return`${e}-content-${t}`}var $e=te,de=ne,le=ae,fe=ce;const nt=$e,Ve=a.forwardRef(({className:e,...t},o)=>c.jsx(de,{ref:o,className:F("inline-flex h-11 items-center justify-center rounded-xl bg-muted p-1 text-muted-foreground gap-0.5",e),...t}));Ve.displayName=de.displayName;const qe=a.forwardRef(({className:e,...t},o)=>c.jsx(le,{ref:o,className:F("inline-flex items-center justify-center whitespace-nowrap rounded-lg px-5 py-2 text-[14px] font-medium ring-offset-background transition-all duration-150 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 data-[state=active]:bg-background data-[state=active]:text-foreground data-[state=active]:shadow-sm",e),...t}));qe.displayName=le.displayName;const ze=a.forwardRef(({className:e,...t},o)=>c.jsx(fe,{ref:o,className:F("mt-3 ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 animate-fade-in",e),...t}));ze.displayName=fe.displayName;var j="Checkbox",[He]=L(j),[Ye,U]=He(j);function Xe(e){const{__scopeCheckbox:t,checked:o,children:n,defaultChecked:u,disabled:r,form:i,name:b,onCheckedChange:m,required:v,value:s="on",internal_do_not_use_render:d}=e,[p,T]=B({prop:o,defaultProp:u??!1,onChange:m,caller:j}),[x,k]=a.useState(null),[l,f]=a.useState(null),g=a.useRef(!1),h=x?!!i||!!x.closest("form"):!0,I={checked:p,disabled:r,setChecked:T,control:x,setControl:k,name:b,form:i,value:s,hasConsumerStoppedPropagationRef:g,required:v,defaultChecked:w(u)?!1:u,isFormControl:h,bubbleInput:l,setBubbleInput:f};return c.jsx(Ye,{scope:t,...I,children:Je(d)?d(I):n})}var be="CheckboxTrigger",pe=a.forwardRef(({__scopeCheckbox:e,onKeyDown:t,onClick:o,...n},u)=>{const{control:r,value:i,disabled:b,checked:m,required:v,setControl:s,setChecked:d,hasConsumerStoppedPropagationRef:p,isFormControl:T,bubbleInput:x}=U(be,e),k=O(u,s),l=a.useRef(m);return a.useEffect(()=>{const f=r==null?void 0:r.form;if(f){const g=()=>d(l.current);return f.addEventListener("reset",g),()=>f.removeEventListener("reset",g)}},[r,d]),c.jsx(y.button,{type:"button",role:"checkbox","aria-checked":w(m)?"mixed":m,"aria-required":v,"data-state":Ce(m),"data-disabled":b?"":void 0,disabled:b,value:i,...n,ref:k,onKeyDown:R(t,f=>{f.key==="Enter"&&f.preventDefault()}),onClick:R(o,f=>{d(g=>w(g)?!0:!g),x&&T&&(p.current=f.isPropagationStopped(),p.current||f.stopPropagation())})})});pe.displayName=be;var $=a.forwardRef((e,t)=>{const{__scopeCheckbox:o,name:n,checked:u,defaultChecked:r,required:i,disabled:b,value:m,onCheckedChange:v,form:s,...d}=e;return c.jsx(Xe,{__scopeCheckbox:o,checked:u,defaultChecked:r,disabled:b,required:i,onCheckedChange:v,name:n,form:s,value:m,internal_do_not_use_render:({isFormControl:p})=>c.jsxs(c.Fragment,{children:[c.jsx(pe,{...d,ref:t,__scopeCheckbox:o}),p&&c.jsx(he,{__scopeCheckbox:o})]})})});$.displayName=j;var me="CheckboxIndicator",ve=a.forwardRef((e,t)=>{const{__scopeCheckbox:o,forceMount:n,...u}=e,r=U(me,o);return c.jsx(z,{present:n||w(r.checked)||r.checked===!0,children:c.jsx(y.span,{"data-state":Ce(r.checked),"data-disabled":r.disabled?"":void 0,...u,ref:t,style:{pointerEvents:"none",...e.style}})})});ve.displayName=me;var ge="CheckboxBubbleInput",he=a.forwardRef(({__scopeCheckbox:e,...t},o)=>{const{control:n,hasConsumerStoppedPropagationRef:u,checked:r,defaultChecked:i,required:b,disabled:m,name:v,value:s,form:d,bubbleInput:p,setBubbleInput:T}=U(ge,e),x=O(o,T),k=we(r),l=Ee(n);a.useEffect(()=>{const g=p;if(!g)return;const h=window.HTMLInputElement.prototype,_=Object.getOwnPropertyDescriptor(h,"checked").set,A=!u.current;if(k!==r&&_){const S=new Event("click",{bubbles:A});g.indeterminate=w(r),_.call(g,w(r)?!1:r),g.dispatchEvent(S)}},[p,k,r,u]);const f=a.useRef(w(r)?!1:r);return c.jsx(y.input,{type:"checkbox","aria-hidden":!0,defaultChecked:i??f.current,required:b,disabled:m,name:v,value:s,form:d,...t,tabIndex:-1,ref:x,style:{...t.style,...l,position:"absolute",pointerEvents:"none",opacity:0,margin:0,transform:"translateX(-100%)"}})});he.displayName=ge;function Je(e){return typeof e=="function"}function w(e){return e==="indeterminate"}function Ce(e){return w(e)?"indeterminate":e?"checked":"unchecked"}const Qe=a.forwardRef(({className:e,...t},o)=>c.jsx($,{ref:o,className:F("peer h-5 w-5 shrink-0 rounded-md border-2 border-primary shadow-sm focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground transition-all duration-150",e),...t,children:c.jsx(ve,{className:F("flex items-center justify-center text-current"),children:c.jsx(_e,{className:"h-3.5 w-3.5 stroke-[3]"})})}));Qe.displayName=$.displayName;export{Qe as C,Be as I,Oe as R,nt as T,Ve as a,qe as b,X as c,ze as d};
|
|
1
|
+
import{r as a,j as c,u as q,P as y,d as R,f as L,b as O,a as B,a2 as Te,e as z,g as F}from"./index-BWzNXVt7.js";import{e as ye,u as H,g as we}from"./select-Bxmx88ff.js";import{u as Ee}from"./index-Dyazd57h.js";import{C as _e}from"./check-ojOtQs1Z.js";var D="rovingFocusGroup.onEntryFocus",Fe={bubbles:!1,cancelable:!0},N="RovingFocusGroup",[G,Y,Ne]=ye(N),[Se,X]=L(N,[Ne]),[Pe,je]=Se(N),J=a.forwardRef((e,t)=>c.jsx(G.Provider,{scope:e.__scopeRovingFocusGroup,children:c.jsx(G.Slot,{scope:e.__scopeRovingFocusGroup,children:c.jsx(Ae,{...e,ref:t})})}));J.displayName=N;var Ae=a.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:o,orientation:n,loop:u=!1,dir:r,currentTabStopId:i,defaultCurrentTabStopId:b,onCurrentTabStopIdChange:m,onEntryFocus:v,preventScrollOnEntryFocus:s=!1,...d}=e,p=a.useRef(null),T=O(t,p),x=H(r),[k,l]=B({prop:i,defaultProp:b??null,onChange:m,caller:N}),[f,g]=a.useState(!1),h=Te(v),I=Y(o),_=a.useRef(!1),[A,S]=a.useState(0);return a.useEffect(()=>{const C=p.current;if(C)return C.addEventListener(D,h),()=>C.removeEventListener(D,h)},[h]),c.jsx(Pe,{scope:o,orientation:n,dir:x,loop:u,currentTabStopId:k,onItemFocus:a.useCallback(C=>l(C),[l]),onItemShiftTab:a.useCallback(()=>g(!0),[]),onFocusableItemAdd:a.useCallback(()=>S(C=>C+1),[]),onFocusableItemRemove:a.useCallback(()=>S(C=>C-1),[]),children:c.jsx(y.div,{tabIndex:f||A===0?-1:0,"data-orientation":n,...d,ref:T,style:{outline:"none",...e.style},onMouseDown:R(e.onMouseDown,()=>{_.current=!0}),onFocus:R(e.onFocus,C=>{const xe=!_.current;if(C.target===C.currentTarget&&xe&&!f){const V=new CustomEvent(D,Fe);if(C.currentTarget.dispatchEvent(V),!V.defaultPrevented){const M=I().filter(E=>E.focusable),Ie=M.find(E=>E.active),ke=M.find(E=>E.id===k),Re=[Ie,ke,...M].filter(Boolean).map(E=>E.ref.current);Z(Re,s)}}_.current=!1}),onBlur:R(e.onBlur,()=>g(!1))})})}),Q="RovingFocusGroupItem",W=a.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:o,focusable:n=!0,active:u=!1,tabStopId:r,children:i,...b}=e,m=q(),v=r||m,s=je(Q,o),d=s.currentTabStopId===v,p=Y(o),{onFocusableItemAdd:T,onFocusableItemRemove:x,currentTabStopId:k}=s;return a.useEffect(()=>{if(n)return T(),()=>x()},[n,T,x]),c.jsx(G.ItemSlot,{scope:o,id:v,focusable:n,active:u,children:c.jsx(y.span,{tabIndex:d?0:-1,"data-orientation":s.orientation,...b,ref:t,onMouseDown:R(e.onMouseDown,l=>{n?s.onItemFocus(v):l.preventDefault()}),onFocus:R(e.onFocus,()=>s.onItemFocus(v)),onKeyDown:R(e.onKeyDown,l=>{if(l.key==="Tab"&&l.shiftKey){s.onItemShiftTab();return}if(l.target!==l.currentTarget)return;const f=Ge(l,s.orientation,s.dir);if(f!==void 0){if(l.metaKey||l.ctrlKey||l.altKey||l.shiftKey)return;l.preventDefault();let h=p().filter(I=>I.focusable).map(I=>I.ref.current);if(f==="last")h.reverse();else if(f==="prev"||f==="next"){f==="prev"&&h.reverse();const I=h.indexOf(l.currentTarget);h=s.loop?Le(h,I+1):h.slice(I+1)}setTimeout(()=>Z(h))}}),children:typeof i=="function"?i({isCurrentTabStop:d,hasTabStop:k!=null}):i})})});W.displayName=Q;var Me={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function De(e,t){return t!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function Ge(e,t,o){const n=De(e.key,o);if(!(t==="vertical"&&["ArrowLeft","ArrowRight"].includes(n))&&!(t==="horizontal"&&["ArrowUp","ArrowDown"].includes(n)))return Me[n]}function Z(e,t=!1){const o=document.activeElement;for(const n of e)if(n===o||(n.focus({preventScroll:t}),document.activeElement!==o))return}function Le(e,t){return e.map((o,n)=>e[(t+n)%e.length])}var Oe=J,Be=W,P="Tabs",[Ke]=L(P,[X]),ee=X(),[Ue,K]=Ke(P),te=a.forwardRef((e,t)=>{const{__scopeTabs:o,value:n,onValueChange:u,defaultValue:r,orientation:i="horizontal",dir:b,activationMode:m="automatic",...v}=e,s=H(b),[d,p]=B({prop:n,onChange:u,defaultProp:r??"",caller:P});return c.jsx(Ue,{scope:o,baseId:q(),value:d,onValueChange:p,orientation:i,dir:s,activationMode:m,children:c.jsx(y.div,{dir:s,"data-orientation":i,...v,ref:t})})});te.displayName=P;var oe="TabsList",ne=a.forwardRef((e,t)=>{const{__scopeTabs:o,loop:n=!0,...u}=e,r=K(oe,o),i=ee(o);return c.jsx(Oe,{asChild:!0,...i,orientation:r.orientation,dir:r.dir,loop:n,children:c.jsx(y.div,{role:"tablist","aria-orientation":r.orientation,...u,ref:t})})});ne.displayName=oe;var re="TabsTrigger",ae=a.forwardRef((e,t)=>{const{__scopeTabs:o,value:n,disabled:u=!1,...r}=e,i=K(re,o),b=ee(o),m=ie(i.baseId,n),v=ue(i.baseId,n),s=n===i.value;return c.jsx(Be,{asChild:!0,...b,focusable:!u,active:s,children:c.jsx(y.button,{type:"button",role:"tab","aria-selected":s,"aria-controls":v,"data-state":s?"active":"inactive","data-disabled":u?"":void 0,disabled:u,id:m,...r,ref:t,onMouseDown:R(e.onMouseDown,d=>{!u&&d.button===0&&d.ctrlKey===!1?i.onValueChange(n):d.preventDefault()}),onKeyDown:R(e.onKeyDown,d=>{[" ","Enter"].includes(d.key)&&i.onValueChange(n)}),onFocus:R(e.onFocus,()=>{const d=i.activationMode!=="manual";!s&&!u&&d&&i.onValueChange(n)})})})});ae.displayName=re;var se="TabsContent",ce=a.forwardRef((e,t)=>{const{__scopeTabs:o,value:n,forceMount:u,children:r,...i}=e,b=K(se,o),m=ie(b.baseId,n),v=ue(b.baseId,n),s=n===b.value,d=a.useRef(s);return a.useEffect(()=>{const p=requestAnimationFrame(()=>d.current=!1);return()=>cancelAnimationFrame(p)},[]),c.jsx(z,{present:u||s,children:({present:p})=>c.jsx(y.div,{"data-state":s?"active":"inactive","data-orientation":b.orientation,role:"tabpanel","aria-labelledby":m,hidden:!p,id:v,tabIndex:0,...i,ref:t,style:{...e.style,animationDuration:d.current?"0s":void 0},children:p&&r})})});ce.displayName=se;function ie(e,t){return`${e}-trigger-${t}`}function ue(e,t){return`${e}-content-${t}`}var $e=te,de=ne,le=ae,fe=ce;const nt=$e,Ve=a.forwardRef(({className:e,...t},o)=>c.jsx(de,{ref:o,className:F("inline-flex h-11 items-center justify-center rounded-xl bg-muted p-1 text-muted-foreground gap-0.5",e),...t}));Ve.displayName=de.displayName;const qe=a.forwardRef(({className:e,...t},o)=>c.jsx(le,{ref:o,className:F("inline-flex items-center justify-center whitespace-nowrap rounded-lg px-5 py-2 text-[14px] font-medium ring-offset-background transition-all duration-150 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 data-[state=active]:bg-background data-[state=active]:text-foreground data-[state=active]:shadow-sm",e),...t}));qe.displayName=le.displayName;const ze=a.forwardRef(({className:e,...t},o)=>c.jsx(fe,{ref:o,className:F("mt-3 ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 animate-fade-in",e),...t}));ze.displayName=fe.displayName;var j="Checkbox",[He]=L(j),[Ye,U]=He(j);function Xe(e){const{__scopeCheckbox:t,checked:o,children:n,defaultChecked:u,disabled:r,form:i,name:b,onCheckedChange:m,required:v,value:s="on",internal_do_not_use_render:d}=e,[p,T]=B({prop:o,defaultProp:u??!1,onChange:m,caller:j}),[x,k]=a.useState(null),[l,f]=a.useState(null),g=a.useRef(!1),h=x?!!i||!!x.closest("form"):!0,I={checked:p,disabled:r,setChecked:T,control:x,setControl:k,name:b,form:i,value:s,hasConsumerStoppedPropagationRef:g,required:v,defaultChecked:w(u)?!1:u,isFormControl:h,bubbleInput:l,setBubbleInput:f};return c.jsx(Ye,{scope:t,...I,children:Je(d)?d(I):n})}var be="CheckboxTrigger",pe=a.forwardRef(({__scopeCheckbox:e,onKeyDown:t,onClick:o,...n},u)=>{const{control:r,value:i,disabled:b,checked:m,required:v,setControl:s,setChecked:d,hasConsumerStoppedPropagationRef:p,isFormControl:T,bubbleInput:x}=U(be,e),k=O(u,s),l=a.useRef(m);return a.useEffect(()=>{const f=r==null?void 0:r.form;if(f){const g=()=>d(l.current);return f.addEventListener("reset",g),()=>f.removeEventListener("reset",g)}},[r,d]),c.jsx(y.button,{type:"button",role:"checkbox","aria-checked":w(m)?"mixed":m,"aria-required":v,"data-state":Ce(m),"data-disabled":b?"":void 0,disabled:b,value:i,...n,ref:k,onKeyDown:R(t,f=>{f.key==="Enter"&&f.preventDefault()}),onClick:R(o,f=>{d(g=>w(g)?!0:!g),x&&T&&(p.current=f.isPropagationStopped(),p.current||f.stopPropagation())})})});pe.displayName=be;var $=a.forwardRef((e,t)=>{const{__scopeCheckbox:o,name:n,checked:u,defaultChecked:r,required:i,disabled:b,value:m,onCheckedChange:v,form:s,...d}=e;return c.jsx(Xe,{__scopeCheckbox:o,checked:u,defaultChecked:r,disabled:b,required:i,onCheckedChange:v,name:n,form:s,value:m,internal_do_not_use_render:({isFormControl:p})=>c.jsxs(c.Fragment,{children:[c.jsx(pe,{...d,ref:t,__scopeCheckbox:o}),p&&c.jsx(he,{__scopeCheckbox:o})]})})});$.displayName=j;var me="CheckboxIndicator",ve=a.forwardRef((e,t)=>{const{__scopeCheckbox:o,forceMount:n,...u}=e,r=U(me,o);return c.jsx(z,{present:n||w(r.checked)||r.checked===!0,children:c.jsx(y.span,{"data-state":Ce(r.checked),"data-disabled":r.disabled?"":void 0,...u,ref:t,style:{pointerEvents:"none",...e.style}})})});ve.displayName=me;var ge="CheckboxBubbleInput",he=a.forwardRef(({__scopeCheckbox:e,...t},o)=>{const{control:n,hasConsumerStoppedPropagationRef:u,checked:r,defaultChecked:i,required:b,disabled:m,name:v,value:s,form:d,bubbleInput:p,setBubbleInput:T}=U(ge,e),x=O(o,T),k=we(r),l=Ee(n);a.useEffect(()=>{const g=p;if(!g)return;const h=window.HTMLInputElement.prototype,_=Object.getOwnPropertyDescriptor(h,"checked").set,A=!u.current;if(k!==r&&_){const S=new Event("click",{bubbles:A});g.indeterminate=w(r),_.call(g,w(r)?!1:r),g.dispatchEvent(S)}},[p,k,r,u]);const f=a.useRef(w(r)?!1:r);return c.jsx(y.input,{type:"checkbox","aria-hidden":!0,defaultChecked:i??f.current,required:b,disabled:m,name:v,value:s,form:d,...t,tabIndex:-1,ref:x,style:{...t.style,...l,position:"absolute",pointerEvents:"none",opacity:0,margin:0,transform:"translateX(-100%)"}})});he.displayName=ge;function Je(e){return typeof e=="function"}function w(e){return e==="indeterminate"}function Ce(e){return w(e)?"indeterminate":e?"checked":"unchecked"}const Qe=a.forwardRef(({className:e,...t},o)=>c.jsx($,{ref:o,className:F("peer h-5 w-5 shrink-0 rounded-md border-2 border-primary shadow-sm focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground transition-all duration-150",e),...t,children:c.jsx(ve,{className:F("flex items-center justify-center text-current"),children:c.jsx(_e,{className:"h-3.5 w-3.5 stroke-[3]"})})}));Qe.displayName=$.displayName;export{Qe as C,Be as I,Oe as R,nt as T,Ve as a,qe as b,X as c,ze as d};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{c as Ee,j as e,g as $,r as c,a1 as Me,a2 as Ke,f as We,e as ye,a3 as Wt,b as xe,d as E,P as ie,a4 as zt,a5 as qt,a6 as Ht,a7 as Xt,a8 as Yt,D as Jt,a as Qt,u as Fe,C as Zt,_ as ze,S as en,
|
|
1
|
+
import{c as Ee,j as e,g as $,r as c,a1 as Me,a2 as Ke,f as We,e as ye,a3 as Wt,b as xe,d as E,P as ie,a4 as zt,a5 as qt,a6 as Ht,a7 as Xt,a8 as Yt,D as Jt,a as Qt,u as Fe,C as Zt,_ as ze,S as en,K as tn,a9 as nn,q as sn,t as an,X as rn,aa as on,ab as ln,ac as cn,$ as z}from"./index-BWzNXVt7.js";import{S as dn,a as un,b as pn,c as mn,e as xn}from"./sheet-DeMGtydc.js";import{B as J}from"./button-B7j1u3OP.js";import{I as D}from"./input-CsF2HwFH.js";import{L as b}from"./label-DHgrnS59.js";import{u as fn,e as hn,S as ae,a as re,b as oe,c as le,d as T,C as gn,f as vn}from"./select-Bxmx88ff.js";import{R as bn,A as jn,c as qe,C as Nn,b as yn}from"./index-Dyazd57h.js";import{c as He,I as wn,R as Cn,C as ce,T as Rn,a as Sn,b as ve,d as be}from"./checkbox-Bhzc1DBg.js";import{C as En}from"./check-ojOtQs1Z.js";import{C as Mn}from"./empty-state-VIN2ShUA.js";import{B as Xe}from"./badge-Ge7Vok1k.js";import{L as Ue}from"./loading-spinner-9jTlzgcl.js";/**
|
|
2
2
|
* @license lucide-react v0.468.0 - ISC
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the ISC license.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import{c as $,r as w,q as Y,j as e,A as E,w as n,t as F,p as t,B as Z,E as v,F as ee,G as R,S as se,I as te,H as ae}from"./index-BWzNXVt7.js";import{C as ne,B as re}from"./breadcrumb-DHPmrgya.js";import{B as r}from"./button-B7j1u3OP.js";import{u as ie,a as le}from"./use-logs-eXKVnJEm.js";import{u as oe,a as ce}from"./use-migrations-CeH8SEZb.js";import{u as de}from"./use-settings-m-86BzLa.js";import{u as me,T as he}from"./use-health-Cbydn8p0.js";import{A as y}from"./arrow-right-CTJRvVop.js";/**
|
|
2
|
+
* @license lucide-react v0.468.0 - ISC
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the ISC license.
|
|
5
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/const xe=$("BookOpen",[["path",{d:"M12 7v14",key:"1akyts"}],["path",{d:"M3 18a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1h5a4 4 0 0 1 4 4 4 4 0 0 1 4-4h5a1 1 0 0 1 1 1v13a1 1 0 0 1-1 1h-6a3 3 0 0 0-3 3 3 3 0 0 0-3-3z",key:"ruj8y"}]]);/**
|
|
7
|
+
* @license lucide-react v0.468.0 - ISC
|
|
8
|
+
*
|
|
9
|
+
* This source code is licensed under the ISC license.
|
|
10
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
11
|
+
*/const ge=$("TriangleAlert",[["path",{d:"m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3",key:"wmoenq"}],["path",{d:"M12 9v4",key:"juzpu7"}],["path",{d:"M12 17h.01",key:"p32p05"}]]);function h({label:o,value:d,detail:m,icon:x,tone:l}){const c={indigo:"bg-indigo-50 text-indigo-600 border-indigo-100",green:"bg-emerald-50 text-emerald-600 border-emerald-100",amber:"bg-amber-50 text-amber-600 border-amber-100",slate:"bg-slate-100 text-slate-600 border-slate-200"}[l];return e.jsx("div",{className:"rounded-xl border bg-white p-4 shadow-sm card-lift",children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:o}),e.jsx("p",{className:"mt-2 text-3xl font-semibold tracking-tight tabular-nums",children:d}),e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:m})]}),e.jsx("span",{className:`inline-flex h-10 w-10 items-center justify-center rounded-lg border ${c}`,children:e.jsx(x,{className:"h-5 w-5"})})]})})}function Ce(){var A;const[o,d]=w.useState(!1),[m,x]=w.useState(null),{data:l=[],isLoading:c,refetch:P}=Y(),{data:i,isLoading:B,refetch:I}=ie(),{data:g,isLoading:z,refetch:O}=le({page:1,perPage:5,sort:"-created",filter:"status>=400"}),{data:a,isLoading:T,refetch:D}=oe(),{data:u,refetch:H}=ce(),{data:p,isLoading:ue,refetch:S}=de(),{data:f,isLoading:W,isError:q,refetch:U}=me(),_=l.length,j=l.filter(s=>s.type==="auth").length,G=l.filter(s=>s.type==="view").length,Q=l.filter(s=>s.type==="base").length,C=[...l].sort((s,N)=>new Date(N.updated).getTime()-new Date(s.updated).getTime()).slice(0,6),k=(g==null?void 0:g.items)??[],V=String(((A=p==null?void 0:p.meta)==null?void 0:A.appName)||"PPBase"),J=(u==null?void 0:u.totalItems)??0,K=i!=null&&i.total?i.errors/i.total*100:0,M=((a==null?void 0:a.pending)??0)>0,b=!q&&(f==null?void 0:f.code)===200,L=w.useMemo(()=>{const s=[];return b||s.push({title:"API health check failed",detail:"Dashboard cannot confirm backend readiness.",href:"/logs",tone:"danger"}),M&&s.push({title:`${(a==null?void 0:a.pending)??0} migration(s) pending`,detail:"Apply pending migrations to keep schema and code in sync.",href:"/migrations",tone:"warn"}),j===0&&s.push({title:"No auth collection configured",detail:"Create at least one auth collection for user sign-in flows.",href:"/collections?new=1",tone:"warn"}),s},[b,M,a==null?void 0:a.pending,j]),X=async()=>{d(!0);try{await Promise.all([P(),I(),O(),D(),H(),S(),U()]),x(new Date)}finally{d(!1)}};return e.jsxs(e.Fragment,{children:[e.jsx(ne,{left:e.jsx(re,{items:[{label:"Dashboard",active:!0}]}),right:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(r,{variant:"outline",size:"sm",onClick:X,disabled:o,children:[e.jsx(E,{className:`h-4 w-4 ${o?"animate-spin":""}`}),o?"Refreshing...":"Refresh overview"]}),e.jsx(r,{asChild:!0,size:"sm",children:e.jsxs(n,{to:"/collections?new=1",onMouseEnter:()=>t("collections"),onFocus:()=>t("collections"),children:[e.jsx(F,{className:"h-4 w-4"}),"New collection"]})})]})}),e.jsx("div",{className:"flex-1 overflow-auto p-4 md:p-6",children:e.jsxs("div",{className:"mx-auto max-w-7xl space-y-6",children:[e.jsx("section",{className:"rounded-2xl border bg-gradient-to-r from-indigo-600 to-indigo-500 p-6 text-white shadow-md animate-enter-up",children:e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-indigo-100",children:"Admin Overview"}),e.jsx("h1",{className:"mt-1 text-2xl font-semibold tracking-tight",children:V}),e.jsx("p",{className:"mt-2 text-sm text-indigo-100",children:"Track collections, health, logs and migrations in one place."})]}),e.jsxs("div",{className:"rounded-xl bg-white/10 px-4 py-3 text-sm backdrop-blur",children:[e.jsx("p",{className:"text-indigo-100",children:"System status"}),e.jsx("div",{className:"mt-1 flex items-center gap-2",children:W?e.jsx("span",{className:"text-white",children:"Checking..."}):b?e.jsxs(e.Fragment,{children:[e.jsx(Z,{className:"h-4 w-4 text-emerald-200"}),e.jsx("span",{className:"font-semibold text-white",children:"Healthy"})]}):e.jsxs(e.Fragment,{children:[e.jsx(ge,{className:"h-4 w-4 text-amber-200"}),e.jsx("span",{className:"font-semibold text-white",children:"Attention required"})]})}),e.jsx("p",{className:"mt-1 text-xs text-indigo-100",children:m?`Updated ${v(m.toISOString())}`:"Use refresh to reload data"})]})]})}),L.length>0&&e.jsxs("section",{className:"rounded-xl border border-amber-200 bg-amber-50 p-4 animate-enter-up animate-enter-delay-1",children:[e.jsx("h2",{className:"mb-3 text-sm font-semibold text-amber-900",children:"Attention required"}),e.jsx("div",{className:"space-y-2",children:L.map((s,N)=>e.jsxs(n,{to:s.href,className:`block rounded-lg border bg-white px-3 py-2.5 hover:bg-slate-50 ${s.tone==="danger"?"border-red-200":"border-amber-200"}`,onMouseEnter:()=>{s.href.startsWith("/logs")&&t("logs"),s.href.startsWith("/migrations")&&t("migrations"),s.href.startsWith("/collections")&&t("collections")},onFocus:()=>{s.href.startsWith("/logs")&&t("logs"),s.href.startsWith("/migrations")&&t("migrations"),s.href.startsWith("/collections")&&t("collections")},children:[e.jsx("p",{className:"text-sm font-semibold text-slate-900",children:s.title}),e.jsx("p",{className:"text-xs text-slate-600",children:s.detail})]},`${s.title}-${N}`))})]}),e.jsxs("section",{className:"grid grid-cols-1 gap-4 md:grid-cols-2 xl:grid-cols-4 animate-enter-up animate-enter-delay-1",children:[e.jsx(h,{label:"Collections",value:c?"...":_,detail:`${Q} base, ${j} auth`,icon:ee,tone:"indigo"}),e.jsx(h,{label:"View Collections",value:c?"...":G,detail:"SQL view-backed collections",icon:he,tone:"slate"}),e.jsx(h,{label:"Requests",value:B?"...":(i==null?void 0:i.total)??0,detail:`error rate ${K.toFixed(1)}%`,icon:xe,tone:"green"}),e.jsx(h,{label:"Migrations Pending",value:T?"...":(a==null?void 0:a.pending)??0,detail:`Applied ${(a==null?void 0:a.applied)??0} / ${J}`,icon:R,tone:"amber"})]}),e.jsxs("section",{className:"grid grid-cols-1 gap-4 lg:grid-cols-3 animate-enter-up animate-enter-delay-2",children:[e.jsxs("div",{className:"rounded-xl border bg-white p-5 shadow-sm lg:col-span-1 card-lift",children:[e.jsxs("div",{className:"mb-4 flex items-center justify-between",children:[e.jsx("h2",{className:"text-base font-semibold",children:"Recent collections"}),e.jsx(r,{asChild:!0,variant:"ghost",size:"sm",children:e.jsxs(n,{to:"/collections",onMouseEnter:()=>t("collections"),onFocus:()=>t("collections"),children:["Open",e.jsx(y,{className:"h-4 w-4"})]})})]}),c?e.jsx("div",{className:"space-y-2",children:[1,2,3].map(s=>e.jsx("div",{className:"h-14 rounded-lg skeleton-shimmer"},s))}):C.length===0?e.jsx("p",{className:"text-sm text-muted-foreground",children:"No collections yet."}):e.jsx("div",{className:"space-y-2",children:C.map(s=>e.jsxs(n,{to:`/collections/${s.id}`,className:"flex items-center justify-between rounded-lg border border-slate-200 px-3 py-2.5 text-sm hover:bg-slate-50 transition-all duration-200 hover:shadow-sm",onMouseEnter:()=>t("records"),onFocus:()=>t("records"),children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-foreground",children:s.name}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[s.type," · ",v(s.updated)]})]}),e.jsx(y,{className:"h-4 w-4 text-muted-foreground"})]},s.id))})]}),e.jsxs("div",{className:"rounded-xl border bg-white p-5 shadow-sm lg:col-span-1 card-lift",children:[e.jsxs("div",{className:"mb-4 flex items-center justify-between",children:[e.jsx("h2",{className:"text-base font-semibold",children:"Recent errors"}),e.jsx(r,{asChild:!0,variant:"ghost",size:"sm",children:e.jsxs(n,{to:"/logs",onMouseEnter:()=>t("logs"),onFocus:()=>t("logs"),children:["Open",e.jsx(y,{className:"h-4 w-4"})]})})]}),z?e.jsx("div",{className:"space-y-2",children:[1,2,3].map(s=>e.jsx("div",{className:"h-14 rounded-lg skeleton-shimmer"},s))}):k.length===0?e.jsx("p",{className:"text-sm text-muted-foreground",children:"No error logs recorded."}):e.jsx("div",{className:"space-y-2",children:k.map(s=>e.jsxs("div",{className:"rounded-lg border border-red-100 bg-red-50/40 px-3 py-2.5 transition-all duration-200 hover:shadow-sm",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("p",{className:"truncate text-sm font-medium text-slate-900",children:[s.method," ",s.url]}),e.jsx("span",{className:"rounded-md bg-red-100 px-2 py-0.5 text-xs font-semibold text-red-700",children:s.status})]}),e.jsx("p",{className:"mt-1 text-xs text-slate-600",children:v(s.created)})]},s.id))})]}),e.jsxs("div",{className:"rounded-xl border bg-white p-5 shadow-sm lg:col-span-1 card-lift",children:[e.jsx("h2",{className:"mb-4 text-base font-semibold",children:"Quick actions"}),e.jsxs("div",{className:"grid grid-cols-1 gap-2.5",children:[e.jsx(r,{asChild:!0,variant:"outline",className:"justify-start",children:e.jsxs(n,{to:"/collections?new=1",onMouseEnter:()=>t("collections"),onFocus:()=>t("collections"),children:[e.jsx(F,{className:"h-4 w-4"}),"Create collection"]})}),e.jsx(r,{asChild:!0,variant:"outline",className:"justify-start",children:e.jsxs(n,{to:"/migrations",onMouseEnter:()=>t("migrations"),onFocus:()=>t("migrations"),children:[e.jsx(R,{className:"h-4 w-4"}),"Review migrations"]})}),e.jsx(r,{asChild:!0,variant:"outline",className:"justify-start",children:e.jsxs(n,{to:"/logs",onMouseEnter:()=>t("logs"),onFocus:()=>t("logs"),children:[e.jsx(E,{className:"h-4 w-4"}),"Inspect logs"]})}),e.jsx(r,{asChild:!0,variant:"outline",className:"justify-start",children:e.jsxs(n,{to:"/settings",onMouseEnter:()=>t("settings"),onFocus:()=>t("settings"),children:[e.jsx(se,{className:"h-4 w-4"}),"Update settings"]})})]}),e.jsxs("div",{className:"mt-4 rounded-lg border border-slate-200 bg-slate-50 p-3",children:[e.jsx("p",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:"Access control"}),e.jsxs("p",{className:"mt-1 text-sm text-slate-700",children:["Superuser management collection:"," ",e.jsx(n,{to:"/collections/_superusers",className:"font-medium text-indigo-600 hover:underline",onMouseEnter:()=>t("records"),onFocus:()=>t("records"),children:"_superusers"})]}),e.jsxs("div",{className:"mt-2 flex items-center gap-1.5 text-xs text-slate-500",children:[e.jsx(te,{className:"h-3.5 w-3.5"}),"Admin-only area"]}),e.jsx(r,{asChild:!0,variant:"ghost",size:"sm",className:"mt-2 justify-start px-0",children:e.jsxs("a",{href:"/api/docs",target:"_blank",rel:"noreferrer",children:[e.jsx(ae,{className:"h-4 w-4"}),"Open API docs"]})})]})]})]})]})})]})}export{Ce as DashboardPage};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as l,j as e,g as r,T as p,U as u,Y as h,V as j,W as g,Z as N}from"./index-
|
|
1
|
+
import{r as l,j as e,g as r,T as p,U as u,Y as h,V as j,W as g,Z as N}from"./index-BWzNXVt7.js";import{B as i}from"./button-B7j1u3OP.js";import{L as y}from"./loading-spinner-9jTlzgcl.js";const T=l.forwardRef(({className:a,...s},t)=>e.jsx("div",{className:"relative w-full overflow-auto",children:e.jsx("table",{ref:t,className:r("w-full caption-bottom text-[15px]",a),...s})}));T.displayName="Table";const w=l.forwardRef(({className:a,...s},t)=>e.jsx("thead",{ref:t,className:r("[&_tr]:border-b bg-slate-50/80",a),...s}));w.displayName="TableHeader";const C=l.forwardRef(({className:a,...s},t)=>e.jsx("tbody",{ref:t,className:r("[&_tr:last-child]:border-0",a),...s}));C.displayName="TableBody";const R=l.forwardRef(({className:a,...s},t)=>e.jsx("tfoot",{ref:t,className:r("border-t bg-muted/50 font-medium [&>tr]:last:border-b-0",a),...s}));R.displayName="TableFooter";const v=l.forwardRef(({className:a,...s},t)=>e.jsx("tr",{ref:t,className:r("border-b transition-all duration-150 hover:bg-slate-50 data-[state=selected]:bg-indigo-50/40",a),...s}));v.displayName="TableRow";const k=l.forwardRef(({className:a,...s},t)=>e.jsx("th",{ref:t,className:r("h-12 px-4 text-left align-middle text-[11px] font-bold uppercase tracking-widest text-slate-500 [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",a),...s}));k.displayName="TableHead";const D=l.forwardRef(({className:a,...s},t)=>e.jsx("td",{ref:t,className:r("px-4 py-3.5 align-middle [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",a),...s}));D.displayName="TableCell";const H=l.forwardRef(({className:a,...s},t)=>e.jsx("caption",{ref:t,className:r("mt-4 text-sm text-muted-foreground",a),...s}));H.displayName="TableCaption";function F({open:a,onOpenChange:s,title:t,description:o,confirmLabel:c="Confirm",cancelLabel:m="Cancel",variant:x="default",onConfirm:f}){const[d,n]=l.useState(!1),b=async()=>{n(!0);try{await f()}finally{n(!1)}};return e.jsx(p,{open:a,onOpenChange:s,children:e.jsxs(u,{children:[e.jsxs(h,{children:[e.jsx(j,{children:t}),e.jsx(g,{children:o})]}),e.jsxs(N,{children:[e.jsx(i,{variant:"outline",onClick:()=>s(!1),disabled:d,children:m}),e.jsxs(i,{variant:x==="destructive"?"destructive":"default",onClick:b,disabled:d,children:[d&&e.jsx(y,{size:"sm",className:"mr-2"}),c]})]})]})})}function S({icon:a,title:s,description:t,action:o}){return e.jsxs("div",{className:"flex flex-col items-center justify-center py-16 px-4 text-center",children:[a&&e.jsx("div",{className:"flex items-center justify-center w-12 h-12 rounded-full bg-muted text-muted-foreground mb-4",children:a}),e.jsx("h3",{className:"text-lg font-semibold text-foreground mb-1",children:s}),e.jsx("p",{className:"text-sm text-muted-foreground mb-4 max-w-sm",children:t}),o&&e.jsx(i,{onClick:o.onClick,children:o.label})]})}export{F as C,S as E,T,w as a,v as b,k as c,C as d,D as e,R as f};
|