ppbase 0.2.3__tar.gz → 0.2.4__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.3 → ppbase-0.2.4}/PKG-INFO +1 -1
- {ppbase-0.2.3 → ppbase-0.2.4}/ppbase/__main__.py +19 -0
- ppbase-0.2.3/ppbase/admin/dist/assets/_id_-D_FQrjti.js → ppbase-0.2.4/ppbase/admin/dist/assets/_id_-BOBW_G85.js +3 -3
- ppbase-0.2.3/ppbase/admin/dist/assets/arrow-right-CTJRvVop.js → ppbase-0.2.4/ppbase/admin/dist/assets/arrow-right-0CbbMiPK.js +1 -1
- ppbase-0.2.3/ppbase/admin/dist/assets/badge-Ge7Vok1k.js → ppbase-0.2.4/ppbase/admin/dist/assets/badge-Ds2sADYs.js +1 -1
- ppbase-0.2.3/ppbase/admin/dist/assets/breadcrumb-DHPmrgya.js → ppbase-0.2.4/ppbase/admin/dist/assets/breadcrumb-76nPcHet.js +1 -1
- ppbase-0.2.4/ppbase/admin/dist/assets/button-BrD63m6O.js +1 -0
- ppbase-0.2.3/ppbase/admin/dist/assets/check-ojOtQs1Z.js → ppbase-0.2.4/ppbase/admin/dist/assets/check-D2wjMIaV.js +1 -1
- ppbase-0.2.4/ppbase/admin/dist/assets/checkbox-kmiNBl7I.js +1 -0
- ppbase-0.2.3/ppbase/admin/dist/assets/chevron-left-CrmIArth.js → ppbase-0.2.4/ppbase/admin/dist/assets/chevron-left-B28RBpkY.js +1 -1
- ppbase-0.2.3/ppbase/admin/dist/assets/collection-editor-yCbBYzYS.js → ppbase-0.2.4/ppbase/admin/dist/assets/collection-editor-BGqL1OUi.js +5 -5
- ppbase-0.2.4/ppbase/admin/dist/assets/dashboard-9yLGUi0c.js +6 -0
- ppbase-0.2.3/ppbase/admin/dist/assets/empty-state-VIN2ShUA.js → ppbase-0.2.4/ppbase/admin/dist/assets/empty-state-DLoUVwRo.js +1 -1
- ppbase-0.2.4/ppbase/admin/dist/assets/hooks-DJAcTXP5.js +26 -0
- ppbase-0.2.4/ppbase/admin/dist/assets/index-Bl364kol.js +1 -0
- ppbase-0.2.3/ppbase/admin/dist/assets/index-Dyazd57h.js → ppbase-0.2.4/ppbase/admin/dist/assets/index-C7DuRwsh.js +1 -1
- ppbase-0.2.4/ppbase/admin/dist/assets/index-DIMXgOxH.css +1 -0
- ppbase-0.2.4/ppbase/admin/dist/assets/index-DQj8gSLY.js +6 -0
- ppbase-0.2.3/ppbase/admin/dist/assets/index-BWzNXVt7.js → ppbase-0.2.4/ppbase/admin/dist/assets/index-WIbkxcQr.js +37 -32
- ppbase-0.2.3/ppbase/admin/dist/assets/input-CsF2HwFH.js → ppbase-0.2.4/ppbase/admin/dist/assets/input-DH6MmAy7.js +1 -1
- ppbase-0.2.3/ppbase/admin/dist/assets/label-DHgrnS59.js → ppbase-0.2.4/ppbase/admin/dist/assets/label-BeRSewaZ.js +1 -1
- ppbase-0.2.4/ppbase/admin/dist/assets/layout-L14mn7rk.js +26 -0
- ppbase-0.2.3/ppbase/admin/dist/assets/loading-spinner-9jTlzgcl.js → ppbase-0.2.4/ppbase/admin/dist/assets/loading-spinner-DX1AeaJq.js +1 -1
- ppbase-0.2.4/ppbase/admin/dist/assets/login-B7kN7Yn-.js +1 -0
- ppbase-0.2.3/ppbase/admin/dist/assets/logs-D47HccMh.js → ppbase-0.2.4/ppbase/admin/dist/assets/logs-BZzBtR8O.js +2 -2
- ppbase-0.2.3/ppbase/admin/dist/assets/migrations-Bffnfhca.js → ppbase-0.2.4/ppbase/admin/dist/assets/migrations-D3Yj-4ht.js +2 -2
- ppbase-0.2.3/ppbase/admin/dist/assets/refresh-cw-6FWWr1B8.js → ppbase-0.2.4/ppbase/admin/dist/assets/refresh-cw-N6x8OBHp.js +1 -1
- ppbase-0.2.4/ppbase/admin/dist/assets/select-Di5ved3U.js +6 -0
- ppbase-0.2.4/ppbase/admin/dist/assets/settings-BNapQjSw.js +1 -0
- ppbase-0.2.3/ppbase/admin/dist/assets/setup-_2oR15Mh.js → ppbase-0.2.4/ppbase/admin/dist/assets/setup-wGeqZj6R.js +1 -1
- ppbase-0.2.3/ppbase/admin/dist/assets/sheet-DeMGtydc.js → ppbase-0.2.4/ppbase/admin/dist/assets/sheet-Cy7tiTuK.js +1 -1
- ppbase-0.2.4/ppbase/admin/dist/assets/tabs-DTYc7STq.js +1 -0
- ppbase-0.2.4/ppbase/admin/dist/assets/tooltip-CNbMYYPm.js +1 -0
- ppbase-0.2.4/ppbase/admin/dist/assets/triangle-alert-B0WtKTPi.js +6 -0
- ppbase-0.2.3/ppbase/admin/dist/assets/use-health-Cbydn8p0.js → ppbase-0.2.4/ppbase/admin/dist/assets/use-health-BcZid-l-.js +1 -1
- ppbase-0.2.3/ppbase/admin/dist/assets/use-logs-eXKVnJEm.js → ppbase-0.2.4/ppbase/admin/dist/assets/use-logs-DIwdR1lw.js +1 -1
- ppbase-0.2.3/ppbase/admin/dist/assets/use-migrations-CeH8SEZb.js → ppbase-0.2.4/ppbase/admin/dist/assets/use-migrations-CM7f3jNA.js +1 -1
- ppbase-0.2.3/ppbase/admin/dist/assets/use-settings-m-86BzLa.js → ppbase-0.2.4/ppbase/admin/dist/assets/use-settings-BPlWakp9.js +1 -1
- {ppbase-0.2.3 → ppbase-0.2.4}/ppbase/admin/dist/index.html +2 -2
- ppbase-0.2.4/ppbase/api/hooks.py +250 -0
- {ppbase-0.2.3 → ppbase-0.2.4}/ppbase/api/router.py +8 -0
- {ppbase-0.2.3 → ppbase-0.2.4}/ppbase/app.py +50 -1
- {ppbase-0.2.3 → ppbase-0.2.4}/ppbase/config.py +3 -0
- {ppbase-0.2.3 → ppbase-0.2.4}/ppbase/ext/flask_like_pb.py +11 -1
- {ppbase-0.2.3 → ppbase-0.2.4}/ppbase/ext/registry.py +0 -1
- ppbase-0.2.4/ppbase/services/hook_manager.py +600 -0
- ppbase-0.2.4/ppbase/services/process_control.py +95 -0
- {ppbase-0.2.3 → ppbase-0.2.4}/ppbase.egg-info/PKG-INFO +1 -1
- {ppbase-0.2.3 → ppbase-0.2.4}/ppbase.egg-info/SOURCES.txt +39 -31
- {ppbase-0.2.3 → ppbase-0.2.4}/pyproject.toml +1 -1
- ppbase-0.2.3/ppbase/admin/dist/assets/button-B7j1u3OP.js +0 -1
- ppbase-0.2.3/ppbase/admin/dist/assets/checkbox-Bhzc1DBg.js +0 -1
- ppbase-0.2.3/ppbase/admin/dist/assets/dashboard-D1l_FGZ9.js +0 -11
- ppbase-0.2.3/ppbase/admin/dist/assets/index-C_wtr7YT.css +0 -1
- ppbase-0.2.3/ppbase/admin/dist/assets/index-DNYtHn84.js +0 -1
- ppbase-0.2.3/ppbase/admin/dist/assets/layout-B8lOjqux.js +0 -26
- ppbase-0.2.3/ppbase/admin/dist/assets/login-B3DFIpss.js +0 -1
- ppbase-0.2.3/ppbase/admin/dist/assets/select-Bxmx88ff.js +0 -11
- ppbase-0.2.3/ppbase/admin/dist/assets/settings-DyFiT37Y.js +0 -1
- {ppbase-0.2.3 → ppbase-0.2.4}/README.md +0 -0
- {ppbase-0.2.3 → ppbase-0.2.4}/ppbase/__init__.py +0 -0
- {ppbase-0.2.3 → ppbase-0.2.4}/ppbase/admin/dist/fonts/Inter-Variable.woff2 +0 -0
- {ppbase-0.2.3 → ppbase-0.2.4}/ppbase/api/__init__.py +0 -0
- {ppbase-0.2.3 → ppbase-0.2.4}/ppbase/api/admins.py +0 -0
- {ppbase-0.2.3 → ppbase-0.2.4}/ppbase/api/collections.py +0 -0
- {ppbase-0.2.3 → ppbase-0.2.4}/ppbase/api/deps.py +0 -0
- {ppbase-0.2.3 → ppbase-0.2.4}/ppbase/api/files.py +0 -0
- {ppbase-0.2.3 → ppbase-0.2.4}/ppbase/api/health.py +0 -0
- {ppbase-0.2.3 → ppbase-0.2.4}/ppbase/api/logs.py +0 -0
- {ppbase-0.2.3 → ppbase-0.2.4}/ppbase/api/migrations.py +0 -0
- {ppbase-0.2.3 → ppbase-0.2.4}/ppbase/api/realtime.py +0 -0
- {ppbase-0.2.3 → ppbase-0.2.4}/ppbase/api/record_auth.py +0 -0
- {ppbase-0.2.3 → ppbase-0.2.4}/ppbase/api/records.py +0 -0
- {ppbase-0.2.3 → ppbase-0.2.4}/ppbase/api/settings.py +0 -0
- {ppbase-0.2.3 → ppbase-0.2.4}/ppbase/core/__init__.py +0 -0
- {ppbase-0.2.3 → ppbase-0.2.4}/ppbase/core/id_generator.py +0 -0
- {ppbase-0.2.3 → ppbase-0.2.4}/ppbase/db/__init__.py +0 -0
- {ppbase-0.2.3 → ppbase-0.2.4}/ppbase/db/bootstrap.py +0 -0
- {ppbase-0.2.3 → ppbase-0.2.4}/ppbase/db/engine.py +0 -0
- {ppbase-0.2.3 → ppbase-0.2.4}/ppbase/db/ensure_db.py +0 -0
- {ppbase-0.2.3 → ppbase-0.2.4}/ppbase/db/schema_manager.py +0 -0
- {ppbase-0.2.3 → ppbase-0.2.4}/ppbase/db/system_tables.py +0 -0
- {ppbase-0.2.3 → ppbase-0.2.4}/ppbase/ext/__init__.py +0 -0
- {ppbase-0.2.3 → ppbase-0.2.4}/ppbase/ext/events.py +0 -0
- {ppbase-0.2.3 → ppbase-0.2.4}/ppbase/ext/hooks.py +0 -0
- {ppbase-0.2.3 → ppbase-0.2.4}/ppbase/ext/loading.py +0 -0
- {ppbase-0.2.3 → ppbase-0.2.4}/ppbase/ext/record_repository.py +0 -0
- {ppbase-0.2.3 → ppbase-0.2.4}/ppbase/middleware/__init__.py +0 -0
- {ppbase-0.2.3 → ppbase-0.2.4}/ppbase/middleware/auth.py +0 -0
- {ppbase-0.2.3 → ppbase-0.2.4}/ppbase/middleware/cors.py +0 -0
- {ppbase-0.2.3 → ppbase-0.2.4}/ppbase/middleware/rate_limit.py +0 -0
- {ppbase-0.2.3 → ppbase-0.2.4}/ppbase/middleware/request_logger.py +0 -0
- {ppbase-0.2.3 → ppbase-0.2.4}/ppbase/models/__init__.py +0 -0
- {ppbase-0.2.3 → ppbase-0.2.4}/ppbase/models/collection.py +0 -0
- {ppbase-0.2.3 → ppbase-0.2.4}/ppbase/models/field_types.py +0 -0
- {ppbase-0.2.3 → ppbase-0.2.4}/ppbase/models/record.py +0 -0
- {ppbase-0.2.3 → ppbase-0.2.4}/ppbase/services/__init__.py +0 -0
- {ppbase-0.2.3 → ppbase-0.2.4}/ppbase/services/admin_service.py +0 -0
- {ppbase-0.2.3 → ppbase-0.2.4}/ppbase/services/auth_service.py +0 -0
- {ppbase-0.2.3 → ppbase-0.2.4}/ppbase/services/collection_service.py +0 -0
- {ppbase-0.2.3 → ppbase-0.2.4}/ppbase/services/expand_service.py +0 -0
- {ppbase-0.2.3 → ppbase-0.2.4}/ppbase/services/file_storage.py +0 -0
- {ppbase-0.2.3 → ppbase-0.2.4}/ppbase/services/filter_parser.py +0 -0
- {ppbase-0.2.3 → ppbase-0.2.4}/ppbase/services/mail_service.py +0 -0
- {ppbase-0.2.3 → ppbase-0.2.4}/ppbase/services/migration_generator.py +0 -0
- {ppbase-0.2.3 → ppbase-0.2.4}/ppbase/services/migration_runner.py +0 -0
- {ppbase-0.2.3 → ppbase-0.2.4}/ppbase/services/oauth2_service.py +0 -0
- {ppbase-0.2.3 → ppbase-0.2.4}/ppbase/services/realtime_service.py +0 -0
- {ppbase-0.2.3 → ppbase-0.2.4}/ppbase/services/record_auth_service.py +0 -0
- {ppbase-0.2.3 → ppbase-0.2.4}/ppbase/services/record_service.py +0 -0
- {ppbase-0.2.3 → ppbase-0.2.4}/ppbase/services/rule_engine.py +0 -0
- {ppbase-0.2.3 → ppbase-0.2.4}/ppbase/services/setup_service.py +0 -0
- {ppbase-0.2.3 → ppbase-0.2.4}/ppbase/storage/__init__.py +0 -0
- {ppbase-0.2.3 → ppbase-0.2.4}/ppbase.egg-info/dependency_links.txt +0 -0
- {ppbase-0.2.3 → ppbase-0.2.4}/ppbase.egg-info/entry_points.txt +0 -0
- {ppbase-0.2.3 → ppbase-0.2.4}/ppbase.egg-info/requires.txt +0 -0
- {ppbase-0.2.3 → ppbase-0.2.4}/ppbase.egg-info/top_level.txt +0 -0
- {ppbase-0.2.3 → ppbase-0.2.4}/setup.cfg +0 -0
- {ppbase-0.2.3 → ppbase-0.2.4}/tests/test_deps_optional_auth.py +0 -0
- {ppbase-0.2.3 → ppbase-0.2.4}/tests/test_oauth2_base_url.py +0 -0
|
@@ -16,6 +16,7 @@ from __future__ import annotations
|
|
|
16
16
|
import argparse
|
|
17
17
|
import asyncio
|
|
18
18
|
import getpass
|
|
19
|
+
import json
|
|
19
20
|
import os
|
|
20
21
|
import signal
|
|
21
22
|
import shutil
|
|
@@ -93,6 +94,7 @@ def _start_daemon(
|
|
|
93
94
|
data_dir: str | None = None,
|
|
94
95
|
public_dir: str | None = None,
|
|
95
96
|
migrations_dir: str | None = None,
|
|
97
|
+
hooks_dir: str | None = None,
|
|
96
98
|
hooks: list[str] | None = None,
|
|
97
99
|
automigrate: bool | None = None,
|
|
98
100
|
) -> None:
|
|
@@ -110,6 +112,8 @@ def _start_daemon(
|
|
|
110
112
|
cmd += ["--publicDir", public_dir]
|
|
111
113
|
if migrations_dir:
|
|
112
114
|
cmd += ["--migrationsDir", migrations_dir]
|
|
115
|
+
if hooks_dir:
|
|
116
|
+
cmd += ["--hooksDir", hooks_dir]
|
|
113
117
|
for target in hooks or []:
|
|
114
118
|
cmd += ["--hooks", target]
|
|
115
119
|
if automigrate is True:
|
|
@@ -150,6 +154,10 @@ def _cmd_serve(args: argparse.Namespace) -> None:
|
|
|
150
154
|
"""Start the PPBase server (foreground or daemon)."""
|
|
151
155
|
from ppbase import pb
|
|
152
156
|
|
|
157
|
+
os.environ["PPBASE_RESTART_CMD"] = json.dumps(
|
|
158
|
+
[sys.executable, "-m", "ppbase", *sys.argv[1:]]
|
|
159
|
+
)
|
|
160
|
+
|
|
153
161
|
overrides: dict = {}
|
|
154
162
|
if args.db:
|
|
155
163
|
overrides["database_url"] = args.db
|
|
@@ -159,6 +167,8 @@ def _cmd_serve(args: argparse.Namespace) -> None:
|
|
|
159
167
|
overrides["public_dir"] = args.public_dir
|
|
160
168
|
if args.migrations_dir:
|
|
161
169
|
overrides["migrations_dir"] = args.migrations_dir
|
|
170
|
+
if getattr(args, "hooks_dir", None):
|
|
171
|
+
overrides["hooks_dir"] = args.hooks_dir
|
|
162
172
|
if args.automigrate is not None:
|
|
163
173
|
overrides["auto_migrate"] = args.automigrate
|
|
164
174
|
|
|
@@ -178,6 +188,7 @@ def _cmd_serve(args: argparse.Namespace) -> None:
|
|
|
178
188
|
data_dir=args.data_dir,
|
|
179
189
|
public_dir=args.public_dir,
|
|
180
190
|
migrations_dir=args.migrations_dir,
|
|
191
|
+
hooks_dir=getattr(args, "hooks_dir", None),
|
|
181
192
|
hooks=args.hooks,
|
|
182
193
|
automigrate=args.automigrate,
|
|
183
194
|
)
|
|
@@ -640,6 +651,14 @@ def main() -> None:
|
|
|
640
651
|
default=None,
|
|
641
652
|
help="Enable/disable auto-migration (default: from settings)",
|
|
642
653
|
)
|
|
654
|
+
serve_parser.add_argument(
|
|
655
|
+
"--hooksDir",
|
|
656
|
+
"--hooks-dir",
|
|
657
|
+
dest="hooks_dir",
|
|
658
|
+
type=str,
|
|
659
|
+
default=None,
|
|
660
|
+
help="Directory for file-based hooks (default: ./pb_hooks).",
|
|
661
|
+
)
|
|
643
662
|
serve_parser.add_argument(
|
|
644
663
|
"--hooks",
|
|
645
664
|
action="append",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{c as Y,
|
|
1
|
+
import{c as Y,w as Z,x as Re,y as fe,z as ge,B as Q,r as o,j as e,f as ae,E as Ie,F as Ae,I as Ee,J as $e,C as je,i as Te,P as ye,t as Se,K as Le,M as as,Q as rs,X as Me,u as ze,h as ls,R as _,b as is,T as os,m as cs,D as ds,S as ms}from"./index-WIbkxcQr.js";import{C as us,B as hs}from"./breadcrumb-76nPcHet.js";import{B as F}from"./button-BrD63m6O.js";import{I as H}from"./input-DH6MmAy7.js";import{C as re}from"./checkbox-kmiNBl7I.js";import{F as ne,g as oe,D as Oe,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-BGqL1OUi.js";import{T as we,a as be,b as K,c as V,d as ve,e as z,C as Be,E as gs}from"./empty-state-DLoUVwRo.js";import{C as Ne}from"./chevron-left-B28RBpkY.js";import{L as E}from"./label-BeRSewaZ.js";import{S as He,a as Ve,b as Ke,c as Je,d as js,e as ys}from"./sheet-Cy7tiTuK.js";import{L as ie}from"./loading-spinner-DX1AeaJq.js";import{B as ce}from"./badge-Ds2sADYs.js";import{S as ws,a as bs,b as vs,c as Ns,d as Cs}from"./select-Di5ved3U.js";import{R as Ss}from"./refresh-cw-N6x8OBHp.js";import"./index-DQj8gSLY.js";import"./index-C7DuRwsh.js";import"./check-D2wjMIaV.js";import"./tabs-DTYc7STq.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,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 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 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>
|
|
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 zs(s,t,n){const a=Ge(n);return Re({queryKey:["records",s,t,a],queryFn:()=>$s(s,t,a),enabled:!!s&&!!t})}function Os(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,O=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(Oe,{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(z,{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(z,{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(z,{onClick:v=>v.stopPropagation(),children:e.jsx(re,{checked:n.has(d.id),onCheckedChange:v=>r(d.id,!!v)})}),A&&e.jsx(z,{className:"font-mono text-xs text-muted-foreground",children:Q(d.id)}),y.map(v=>e.jsx(z,{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(z,{className:"text-xs text-muted-foreground",children:Se(d.created)}),m&&e.jsx(z,{className:"text-xs text-muted-foreground",children:Se(d.updated)}),e.jsx(z,{})]},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,"-",O," 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),O=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,O);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(z,{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(z,{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(z,{onClick:G=>G.stopPropagation(),children:e.jsx(re,{checked:q,onCheckedChange:()=>A(f.id)})}),e.jsx(z,{className:"font-mono text-xs text-muted-foreground",children:Q(f.id)}),e.jsx(z,{className:"max-w-[420px] truncate",children:T})]},f.id)}):e.jsx(K,{children:e.jsx(z,{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]),O=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]}),O.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:O.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]}),O[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(O[0].id),disabled:!S,title:`Open related record ${O[0].id}`,children:[e.jsx("span",{className:"truncate",children:O[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]),O=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:O}),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(Oe,{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=ze(),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}=zs(n.id,a??void 0,{expand:h}),L=Os(n.id),x=qs(n.id),p=Ze(n.id),[N,D]=o.useState({}),[O,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:O,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,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 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(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(
|
|
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(z,{className:"font-medium",children:i.name}),e.jsx(z,{children:e.jsx(ce,{variant:"secondary",className:"text-xs",children:i.type})}),e.jsx(z,{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 Ht(){const{id:s}=os(),t=ze(),[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:O}=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:()=>O(),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{Ht as RecordsPage};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{j as o,
|
|
1
|
+
import{j as o,f as n}from"./index-WIbkxcQr.js";import{a}from"./button-BrD63m6O.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,
|
|
1
|
+
import{j as e,f as a}from"./index-WIbkxcQr.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};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{r as a,j as m,ap as E,U as S,aq as V,f as j}from"./index-WIbkxcQr.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};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{r as i,j as n,Y as H,a1 as _,a8 as z,$ as S,a0 as N,W as G,f as w}from"./index-WIbkxcQr.js";import{u as K}from"./index-DQj8gSLY.js";import{u as U}from"./index-C7DuRwsh.js";import{C as X}from"./check-D2wjMIaV.js";var g="Checkbox",[$]=G(g),[W,I]=$(g);function Y(t){const{__scopeCheckbox:s,checked:r,children:l,defaultChecked:a,disabled:e,form:p,name:h,onCheckedChange:d,required:m,value:k="on",internal_do_not_use_render:u}=t,[f,v]=z({prop:r,defaultProp:a??!1,onChange:d,caller:g}),[C,x]=i.useState(null),[y,o]=i.useState(null),c=i.useRef(!1),E=C?!!p||!!C.closest("form"):!0,R={checked:f,disabled:e,setChecked:v,control:C,setControl:x,name:h,form:p,value:k,hasConsumerStoppedPropagationRef:c,required:m,defaultChecked:b(a)?!1:a,isFormControl:E,bubbleInput:y,setBubbleInput:o};return n.jsx(W,{scope:s,...R,children:J(u)?u(R):l})}var B="CheckboxTrigger",M=i.forwardRef(({__scopeCheckbox:t,onKeyDown:s,onClick:r,...l},a)=>{const{control:e,value:p,disabled:h,checked:d,required:m,setControl:k,setChecked:u,hasConsumerStoppedPropagationRef:f,isFormControl:v,bubbleInput:C}=I(B,t),x=S(a,k),y=i.useRef(d);return i.useEffect(()=>{const o=e==null?void 0:e.form;if(o){const c=()=>u(y.current);return o.addEventListener("reset",c),()=>o.removeEventListener("reset",c)}},[e,u]),n.jsx(_.button,{type:"button",role:"checkbox","aria-checked":b(d)?"mixed":d,"aria-required":m,"data-state":F(d),"data-disabled":h?"":void 0,disabled:h,value:p,...l,ref:x,onKeyDown:N(s,o=>{o.key==="Enter"&&o.preventDefault()}),onClick:N(r,o=>{u(c=>b(c)?!0:!c),C&&v&&(f.current=o.isPropagationStopped(),f.current||o.stopPropagation())})})});M.displayName=B;var P=i.forwardRef((t,s)=>{const{__scopeCheckbox:r,name:l,checked:a,defaultChecked:e,required:p,disabled:h,value:d,onCheckedChange:m,form:k,...u}=t;return n.jsx(Y,{__scopeCheckbox:r,checked:a,defaultChecked:e,disabled:h,required:p,onCheckedChange:m,name:l,form:k,value:d,internal_do_not_use_render:({isFormControl:f})=>n.jsxs(n.Fragment,{children:[n.jsx(M,{...u,ref:s,__scopeCheckbox:r}),f&&n.jsx(D,{__scopeCheckbox:r})]})})});P.displayName=g;var T="CheckboxIndicator",q=i.forwardRef((t,s)=>{const{__scopeCheckbox:r,forceMount:l,...a}=t,e=I(T,r);return n.jsx(H,{present:l||b(e.checked)||e.checked===!0,children:n.jsx(_.span,{"data-state":F(e.checked),"data-disabled":e.disabled?"":void 0,...a,ref:s,style:{pointerEvents:"none",...t.style}})})});q.displayName=T;var A="CheckboxBubbleInput",D=i.forwardRef(({__scopeCheckbox:t,...s},r)=>{const{control:l,hasConsumerStoppedPropagationRef:a,checked:e,defaultChecked:p,required:h,disabled:d,name:m,value:k,form:u,bubbleInput:f,setBubbleInput:v}=I(A,t),C=S(r,v),x=K(e),y=U(l);i.useEffect(()=>{const c=f;if(!c)return;const E=window.HTMLInputElement.prototype,j=Object.getOwnPropertyDescriptor(E,"checked").set,L=!a.current;if(x!==e&&j){const O=new Event("click",{bubbles:L});c.indeterminate=b(e),j.call(c,b(e)?!1:e),c.dispatchEvent(O)}},[f,x,e,a]);const o=i.useRef(b(e)?!1:e);return n.jsx(_.input,{type:"checkbox","aria-hidden":!0,defaultChecked:p??o.current,required:h,disabled:d,name:m,value:k,form:u,...s,tabIndex:-1,ref:C,style:{...s.style,...y,position:"absolute",pointerEvents:"none",opacity:0,margin:0,transform:"translateX(-100%)"}})});D.displayName=A;function J(t){return typeof t=="function"}function b(t){return t==="indeterminate"}function F(t){return b(t)?"indeterminate":t?"checked":"unchecked"}const Q=i.forwardRef(({className:t,...s},r)=>n.jsx(P,{ref:r,className:w("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",t),...s,children:n.jsx(q,{className:w("flex items-center justify-center text-current"),children:n.jsx(X,{className:"h-3.5 w-3.5 stroke-[3]"})})}));Q.displayName=P.displayName;export{Q as C};
|