Files
oikos/web/dist/assets/DataTable-B-TAV_HV.js
dtoro d4d99a7473
Some checks failed
ci / build-test (push) Has been cancelled
ci / docker-build (push) Has been cancelled
feat: Phase 1 — extract the client (web SPA + desktop) to dtoro/oikos-web
Problem: the hexagonal refactor churns the backend tree for nine more
phases; the UI delivery stack (web/ SPA, cmd/desktop Wails wrapper,
compose/web image) must move to its own repo first so doc/layout
rewrites land once on a backend-only tree.

Change:
- New repo git.hubris.network/dtoro/oikos-web (v0.33.0): web/, desktop/
  (updateURL repointed to oikos-web releases), compose/, own CI (web +
  desktop jobs), own deploy script (CI-green gate, TOCTOU guard,
  version-tagged images, prune-to-3), own webhook receiver on :9798 +
  launchd unit, own compose project publishing the same 8091:80.
- Cutover executed on mac-mini in order: oikos stack's web service
  stopped+removed, oikos-web project brought up on 8091; outer Caddy
  untouched (targets the published port) — serving + Authentik flow +
  /wails 404 quirk verified post-cutover.
- Stripped from oikos: web/, cmd/desktop/, compose/web/, desktop CI
  workflow, ci.yml web job, Makefile ui/desktop/desktop-package/install
  targets, the compose web service, oikos-web from deploy.sh's fallback
  prune list; wails + go-keyring dropped from go.mod, vendor synced.
- README / CONTRIBUTING / AGENTS.md / .agents dev+operations docs now
  point at the new repo; mbse + mascot design docs carry a path note.

Risk: production SPA serving depends on the new pipeline now; rollback
is versioned-image re-up of the old web service from a pre-split
checkout (port 8091). Desktop builds installed before the split still
check dtoro/oikos releases — one manual reinstall, noted in the
oikos-web release notes.

Verification: go vet, make test (race), make generate-check, golangci
(no new findings; baseline down 400→365); post-cutover curls —
localhost:8091 200, /wails/runtime.js 404, outer Caddy 302 Authentik.
2026-08-15 22:27:52 +02:00

3 lines
30 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
var qt=Object.defineProperty;var ft=r=>{throw TypeError(r)};var jt=(r,e,t)=>e in r?qt(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var h=(r,e,t)=>jt(r,typeof e!="symbol"?e+"":e,t),Et=(r,e,t)=>e.has(r)||ft("Cannot "+t);var n=(r,e,t)=>(Et(r,e,"read from private field"),t?t.call(r):e.get(r)),b=(r,e,t)=>e.has(r)?ft("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(r):e.set(r,t);import{a3 as Nt,U as nt,a2 as Ft,x as $,y as P,g as i,D as f,a6 as ie,u as m,ag as It,p as fe,W as C,aH as zt,s as L,as as Ot,R as T,t as A,aI as se,d as re,a as g,b as ge,c as R,aJ as Tt,C as ct,f as E,aK as Mt,Q as M,j as F,a7 as oe,a8 as le,e as J,i as ae,E as ht,_ as Lt,a0 as Dt,B as Wt,ad as Vt,ab as Jt,aL as Qt,af as gt,aa as at,a9 as Kt,ac as Ut}from"./index-B5w8gw75.js";import{s as Xt}from"./clone-bSRBQ4eT.js";import{S as Gt,E as Yt,a as Zt,H as $t}from"./StatusBadgeRenderer-BEdJTFrn.js";import{S as es,a as ts,b as ss,c as rs}from"./select-trigger-BFw7c3mx.js";var is=new Set(["$$slots","$$events","$$legacy"]);function as(r,e){let t=Ft(e,is);const s=[["path",{d:"m15 18-6-6 6-6"}]];Nt(r,nt({name:"chevron-left"},()=>t,{get iconNode(){return s}}))}$(["click"]);$(["click"]);$(["input"]);$(["click"]);$(["input"]);$(["change"]);class ls{constructor(){h(this,"listeners",{change:[],clearFilters:[],clearSearch:[]});h(this,"queue",new Set)}add(e,t){this.listeners[e].push(t)}async dispatch(e){this.queue.add(e),await new Promise(t=>setTimeout(t,40)),this.queue.size>0&&this.run(),this.queue.clear()}run(){for(const e of this.queue)for(const t of this.listeners[e])t()}}const he=r=>r==null||r==="",ut=r=>!he(r),we=(r=null)=>String(r).toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g,""),ns=r=>typeof r!="object"||r===null?!1:!(Array.isArray(r)&&ut(r[0])&&typeof r[0]!="object"),ue={isLike:(r,e)=>we(r).includes(we(e)),isEqualTo:(r,e)=>we(r)===we(e),whereIn:(r,e=[])=>{if(e.length===0)return!1;for(const{value:t,check:s}of e){if(t!=null&&t.key)return cs(r,t,s);if(s(r,t))return!0}return!1},match:(r,e)=>{const t=e.match(/^([\/~@;%#'])(.*?)\1([gimsuy]*)$/),s=t?new RegExp(t[2],t[3].split("").filter((l,a,c)=>c.indexOf(l)===a).join("")):new RegExp(e);return!!we(r).match(s)}},cs=(r,e,t)=>{if(!(e!=null&&e.key))return!1;const{key:s,value:l}=e;return!!(Array.isArray(r)===!1&&typeof r=="object"&&Object.keys(r).includes(s)&&t(r[s],l))},de=(r,e,t)=>(t.check=t.check??ue.isLike,he(e)?!0:ns(r)?Object.keys(r).some(s=>de(r[s],e,t)):t.check(r,e)),ot=(r,e,t)=>(Array.isArray(r)&&(r=r.filter(s=>{const l=t.isRecursive===!0?de(s,e,t):!0;if(typeof s=="object"&&l===!0)for(const a of Object.keys(s))s[a]=ot(s[a],e,t);return l})),t.highlight&&(typeof r=="string"||typeof r=="number")&&typeof e=="string"&&de(r,e,t)?wt(r,e):r),wt=(r,e)=>{const t=e.replace(/a/g,"[aàâáä]").replace(/e/g,"[eèêéë]").replace(/i/g,"[iìîíï]").replace(/o/g,"[oòôо́ö]").replace(/u/g,"[uùûúü]").replace(/y/g,"[yỳŷýÿ]"),s=new RegExp(`${t}`,"gi");return String(r).replace(s,'<u class="highlight">$&</u>')},bt=(r,e,t)=>{const s=t.toString().split("=>")[1].replace(/\(\)/g,"").replace(/\?/g,"").split(".").splice(1).join(".").trim();return s.indexOf(" ")>-1?r:os(r,s,e)},os=(r,e,t)=>{const s=r,l=e.replace(/\[/g,".[").split(".");try{for(let a=0;a<l.length;a++){let c=l[a],o=l[a+1];c.includes("[")&&(c=String(parseInt(c.substring(1,c.length-1)))),o&&o.includes("[")&&(o=String(parseInt(o.substring(1,o.length-1)))),o!==void 0?r[c]=r[c]?r[c]:isNaN(Number(o))?{}:[]:r[c]=wt(r[c],t),r=r[c]}return s}catch{return s}},Z=(r,e)=>{if(typeof r=="string")return{callback:t=>t[r],id:e,key:r};if(typeof r=="function")return{callback:r,id:e,key:void 0};throw new Error(`Invalid field argument: ${String(r)}`)},Ye={search:(r,{scope:e,isRecursive:t,value:s,check:l},a=!1)=>r.filter(c=>{const d=(e??Object.keys(c)).map(p=>Z(p));for(const{key:p,callback:B}of d)p?c[p]=ot(c[p],s,{highlight:a,isRecursive:t===!0}):a&&(c=bt(c,s,B));return d.some(({callback:p})=>de(p(c),s,{check:l}))}),filter:(r,{callback:e,isRecursive:t,value:s,check:l,key:a},c=!1)=>r.filter(o=>{const d=de(e(o),s,{check:l});return a?o[a]=ot(o[a],s,{highlight:c,check:l,isRecursive:t!==!1}):c&&d&&s&&typeof s=="string"&&(o=bt(o,s,e)),d}),query:(r,{path:e,value:t,check:s})=>r.filter(l=>{if(e.length===0)return s(l,t);let a=l,c=1,o=!1;for(const d of e){if(c===1&&c<e.length){a=a[d];for(const p of a[d]);}c===e.length&&(console.log(d,a),a[d]=Ye.query(a[d],{path:[],value:t,check:s}),a[d].length>0&&(o=!0)),a=a[d],c++}return o})},Ze={asc:(r,e,t,s)=>r===e?0:he(r)?1:he(e)?-1:typeof r=="boolean"?r===!1?1:-1:typeof r=="string"?r.localeCompare(e,t,s):typeof r=="number"?r-e:typeof r=="object"?JSON.stringify(r).localeCompare(JSON.stringify(e),t,s):String(r).localeCompare(String(e),t,s),desc:(r,e,t,s)=>r===e?0:he(r)?1:he(e)?-1:typeof e=="boolean"?e===!1?1:-1:typeof e=="string"?e.localeCompare(r,t,s):typeof e=="number"?e-r:typeof e=="object"?JSON.stringify(e).localeCompare(JSON.stringify(r),t,s):String(e).localeCompare(String(r),t,s)};var me,ye,ke,Pe,Se,xe,Re,_e,He,Ce,Ae,Be,qe,je,Ee,Ne,Fe,Ie,ze;class hs{constructor(e,t){h(this,"selectBy");b(this,me,P("currentPage"));h(this,"highlight");h(this,"event",new ls);b(this,ye,P([]));b(this,ke,P(ie({value:null})));b(this,Pe,P(ie({})));b(this,Se,P(ie([])));b(this,xe,P(ie([])));b(this,Re,P(10));b(this,_e,P(1));b(this,He,P(void 0));b(this,Ce,P(1e3));b(this,Ae,m(()=>this.filters.length));b(this,Be,m(()=>this.createAllRows()));b(this,qe,m(()=>this.createRows()));b(this,je,m(()=>this.createRowCount()));b(this,Ee,m(()=>this.createPages()));b(this,Ne,m(()=>this.pages.length));b(this,Fe,m(()=>this.createPagesWithEllipsis()));b(this,Ie,P(ie([])));b(this,ze,m(()=>this.createIsAllSelected()));this.rawRows=e,this.rowsPerPage=t.rowsPerPage??null,this.highlight=t.highlight??!1,this.selectBy=t.selectBy}get selectScope(){return i(n(this,me))}set selectScope(e){f(n(this,me),e,!0)}get rawRows(){return i(n(this,ye))}set rawRows(e){f(n(this,ye),e)}get search(){return i(n(this,ke))}set search(e){f(n(this,ke),e,!0)}get sort(){return i(n(this,Pe))}set sort(e){f(n(this,Pe),e,!0)}get filters(){return i(n(this,Se))}set filters(e){f(n(this,Se),e,!0)}get queries(){return i(n(this,xe))}set queries(e){f(n(this,xe),e,!0)}get rowsPerPage(){return i(n(this,Re))}set rowsPerPage(e){f(n(this,Re),e,!0)}get currentPage(){return i(n(this,_e))}set currentPage(e){f(n(this,_e),e,!0)}get element(){return i(n(this,He))}set element(e){f(n(this,He),e,!0)}get clientWidth(){return i(n(this,Ce))}set clientWidth(e){f(n(this,Ce),e,!0)}get filterCount(){return i(n(this,Ae))}set filterCount(e){f(n(this,Ae),e)}get allRows(){return i(n(this,Be))}set allRows(e){f(n(this,Be),e)}get rows(){return i(n(this,qe))}set rows(e){f(n(this,qe),e)}get rowCount(){return i(n(this,je))}set rowCount(e){f(n(this,je),e)}get pages(){return i(n(this,Ee))}set pages(e){f(n(this,Ee),e)}get pageCount(){return i(n(this,Ne))}set pageCount(e){f(n(this,Ne),e)}get pagesWithEllipsis(){return i(n(this,Fe))}set pagesWithEllipsis(e){f(n(this,Fe),e)}get selected(){return i(n(this,Ie))}set selected(e){f(n(this,Ie),e,!0)}get isAllSelected(){return i(n(this,ze))}set isAllSelected(e){f(n(this,ze),e)}createAllRows(){let e=Xt(this.rawRows);if(this.search.value)e=Ye.search(e,this.search,this.highlight),this.event.dispatch("change");else if(this.filters.length>0){for(const t of this.filters)e=Ye.filter(e,t,this.highlight);this.event.dispatch("change")}else if(this.queries.length>0){for(const t of this.queries)e=Ye.query(e,t);this.event.dispatch("change")}return e}createRows(){return this.rowsPerPage?this.allRows.slice((this.currentPage-1)*this.rowsPerPage,this.currentPage*this.rowsPerPage):this.allRows}createRowCount(){const e=this.allRows.length;return this.rowsPerPage?{total:e,start:this.currentPage*this.rowsPerPage-this.rowsPerPage+1,end:Math.min(this.currentPage*this.rowsPerPage,e),selected:this.selected.length}:{total:e,start:1,end:e,selected:this.selected.length}}createPages(){return this.rowsPerPage?Array.from(Array(Math.ceil(this.allRows.length/this.rowsPerPage))).map((t,s)=>s+1):[1]}createPagesWithEllipsis(){if(this.pageCount<=7)return this.pages;const e=null,t=1,s=this.pageCount;return this.currentPage<=4?[...this.pages.slice(0,5),e,s]:this.currentPage<s-3?[t,e,...this.pages.slice(this.currentPage-2,this.currentPage+1),e,s]:[t,e,...this.pages.slice(s-5,s)]}createIsAllSelected(){if(this.rowCount.total===0||!this.selectBy)return!1;const{callback:e}=Z(this.selectBy);return this.selectScope==="all"?this.allRows.map(e).every(l=>this.selected.includes(l)):this.rows.map(e).every(s=>this.selected.includes(s))}}me=new WeakMap,ye=new WeakMap,ke=new WeakMap,Pe=new WeakMap,Se=new WeakMap,xe=new WeakMap,Re=new WeakMap,_e=new WeakMap,He=new WeakMap,Ce=new WeakMap,Ae=new WeakMap,Be=new WeakMap,qe=new WeakMap,je=new WeakMap,Ee=new WeakMap,Ne=new WeakMap,Fe=new WeakMap,Ie=new WeakMap,ze=new WeakMap;class us{constructor(e){h(this,"backup");h(this,"table");this.table=e,this.backup=[]}set(e,t,s={}){this.table.sort.id!==t&&(this.table.sort.direction=null),this.table.sort.direction===null||this.table.sort.direction==="desc"?this.asc(e,t,s):this.table.sort.direction==="asc"&&this.desc(e,t,s)}asc(e,t,{locales:s,options:l}={}){if(!e)return;const{callback:a,key:c}=Z(e,t);this.table.sort={id:t,callback:a,direction:"asc",key:c},this.table.rawRows=[...this.table.rawRows].sort((o,d)=>{const[p,B]=[a(o),a(d)];return Ze.asc(p,B,s,l)}),this.save({id:t,callback:a,direction:"asc"}),this.table.setPage(1)}desc(e,t,{locales:s,options:l}={}){if(!e)return;const{callback:a,key:c}=Z(e,t);this.table.sort={id:t,callback:a,direction:"desc",key:c},this.table.rawRows=[...this.table.rawRows].sort((o,d)=>{const[p,B]=[a(o),a(d)];return Ze.desc(p,B,s,l)}),this.save({id:t,callback:a,direction:"desc"}),this.table.setPage(1)}clear(){this.backup=[],this.table.sort={}}restore(){for(const{key:e,callback:t,direction:s,id:l}of this.backup){const a=e??t;this[s](a,l)}}save(e){if(this.backup=this.backup.filter(t=>t.id!==e.id),this.backup.length>=3){const[t,s,l]=this.backup;this.backup=[s,l,e]}else this.backup=[...this.backup,e]}}class ds{constructor(e){h(this,"table");this.table=e}set(e,t,s=null,l,a=!0){this.table.setPage(1);const{callback:c,key:o}=Z(t,l),d={value:e,id:l,callback:c,check:s,key:o,isRecursive:a};this.table.filters=this.table.filters.filter(p=>p.id!==l),ut(e)&&this.table.filters.push(d)}unset(e){this.table.setPage(1),this.table.filters=this.table.filters.filter(t=>t.id!==e)}}class fs{constructor(e){h(this,"table");this.table=e}set(e,t,s,l){this.table.setPage(1),this.table.queries=this.table.queries.filter(a=>a.id!==l),this.table.queries.push({path:e,value:t,check:s,id:l})}unset(e){this.table.setPage(1),this.table.queries=this.table.queries.filter(t=>t.id!==e)}}class gs{constructor(e){h(this,"table");this.table=e}set(e){this.table.selected.includes(e)?this.table.selected=this.table.selected.filter(t=>t!==e):this.table.selected=[e,...this.table.selected]}all(e){const t=e==="currentPage"?this.table.rows:this.table.allRows,{callback:s}=Z(this.table.selectBy),l=t.map(s);e==="currentPage"?this.table.isAllSelected?this.table.selected=this.table.selected.filter(a=>l.includes(a)===!1):this.table.selected=[...new Set([...l,...this.table.selected])]:this.table.isAllSelected?this.clear():this.table.selected=l}clear(){this.table.selected=[]}getRows(){const{callback:e}=Z(this.table.selectBy);return this.table.rawRows.filter(t=>this.table.selected.includes(e(t)))}}class bs{constructor(e){h(this,"table");this.table=e}goto(e){this.table.rowsPerPage&&e>=1&&e<=this.table.pageCount&&(this.table.currentPage=e,this.table.event.dispatch("change"))}previous(){this.goto(this.table.currentPage-1)}next(){this.goto(this.table.currentPage+1)}last(){this.goto(this.table.pageCount)}}class vs{constructor(e){h(this,"table");this.table=e}set(e,t){this.table.setPage(1),this.table.search={value:e,scope:t}}recursive(e,t){this.table.setPage(1),this.table.search={value:e,scope:t,isRecursive:!0}}regex(e,t){this.table.setPage(1),this.table.search={value:e,scope:t,check:ue.match}}clear(){this.table.setPage(1),this.table.search={value:""}}}var Oe;class ps{constructor(e,t){b(this,Oe,P(ie([])));h(this,"table");h(this,"interval");h(this,"mutation");this.table=e,this.columns=[],this.interval=setInterval(()=>this.createColumns(t),200)}get columns(){return i(n(this,Oe))}set columns(e){f(n(this,Oe),e,!0)}toggle(e){if(!this.table.element)return;const t=this.columns.find(s=>s.name===e);t&&t.toggle()}createColumns(e){var t;(t=this.table)!=null&&t.element&&(clearInterval(this.interval),this.columns=e.map(({name:s,index:l,isVisible:a,isFrozen:c})=>({name:s,index:l,isVisible:a!==!1,isFrozen:c===!0,element:this.table.element,toggle(){this.isVisible=!this.isVisible,this.element.querySelectorAll(`tr > *:nth-child(${this.index+1})`).forEach(o=>{o.classList.toggle("hidden")})}})),this.preset(),this.mutation=new MutationObserver(()=>{setTimeout(()=>{this.preset()},2)}),this.mutation.observe(this.table.element,{childList:!0,subtree:!0}))}preset(){let e=0;for(const{isVisible:t,isFrozen:s,index:l}of this.columns)s===!0&&(e+=this.freeze(l,e)),t===!1&&this.table.element.querySelectorAll(`tr > *:nth-child(${l+1})`).forEach(a=>{a.classList.add("hidden")})}freeze(e,t=0){const s=this.table.element.querySelector(`thead th:nth-child(${e+1})`),{width:l}=s.getBoundingClientRect();return this.table.element.querySelectorAll(`tr > *:nth-child(${e+1})`).forEach(a=>{a.style.position="sticky",a.style.left=t+"px",a.style.width=l+"px"}),l}setPosition(e,t){this.table.element.querySelectorAll("tr").forEach(s=>{const l=[].slice.call(s.querySelectorAll("th, td"));e>t?l[t].parentNode.insertBefore(l[e],l[t]):l[t].parentNode.insertBefore(l[e],l[t].nextSibling)})}}Oe=new WeakMap;var Te;class ws{constructor(e,t){b(this,Te,P(""));h(this,"scope");h(this,"searchHandler");this.searchHandler=e,this.scope=t,this.cleanup()}get value(){return i(n(this,Te))}set value(e){f(n(this,Te),e,!0)}set(){this.searchHandler.set(this.value,this.scope)}init(e){return this.value=e,this.set(),this}recursive(){this.searchHandler.recursive(this.value,this.scope)}regex(){this.searchHandler.regex(this.value,this.scope)}clear(){this.value="",this.searchHandler.clear()}cleanup(){this.searchHandler.table.on("clearSearch",()=>this.clear())}}Te=new WeakMap;var Me;class ms{constructor(e,t,s){b(this,Me,P(""));h(this,"id",Math.random().toString(36).substring(2,15));h(this,"filterHandler");h(this,"field");h(this,"check");h(this,"isRecursive",!0);this.filterHandler=e,this.field=t,this.check=s??ue.isLike,this.cleanup()}get value(){return i(n(this,Me))}set value(e){f(n(this,Me),e,!0)}set(e){this.filterHandler.set(this.value,this.field,e??this.check,this.id,this.isRecursive)}init(e){return this.value=e,this.set(),this}isNotRecursive(){return this.isRecursive=!1,this}clear(){this.value="",this.filterHandler.unset(this.id)}cleanup(){this.filterHandler.table.on("clearFilters",()=>this.clear())}}Me=new WeakMap;var Le;class ys{constructor(e){b(this,Le,P(""));h(this,"id",Math.random().toString(36).substring(2,15));h(this,"queryHandler");h(this,"path",[]);h(this,"check");this.queryHandler=e,this.cleanup()}get value(){return i(n(this,Le))}set value(e){f(n(this,Le),e,!0)}from(e){return this.path=e,this}where(e){return this.check=e,this}set(e){e&&(this.value=e),this.queryHandler.set(this.path,this.value,this.check,this.id)}clear(){this.value="",this.queryHandler.unset(this.id)}cleanup(){this.queryHandler.table.on("clearFilters",()=>this.clear())}}Le=new WeakMap;var De;class ks{constructor(e,t,s){b(this,De,P(ie([])));h(this,"id",Math.random().toString(36).substring(2,15));h(this,"filterHandler");h(this,"collection");h(this,"field");h(this,"check");h(this,"isRecursive",!0);this.filterHandler=e,this.field=t,this.collection=[],this.check=s??ue.isEqualTo,this.cleanup()}get criteria(){return i(n(this,De))}set criteria(e){f(n(this,De),e,!0)}set(e,t){if(this.collection.find(s=>s.value===e)?this.collection=this.collection.filter(s=>s.value!==e):this.collection=[{value:e,check:t??this.check},...this.collection],this.collection.length===0)return this.clear();this.filterHandler.set(this.collection,this.field,ue.whereIn,this.id,this.isRecursive),this.criteria=this.collection.map(s=>s.value)}isNotRecursive(){return this.isRecursive=!1,this}clear(){this.collection=[],this.criteria=[],this.filterHandler.unset(this.id)}cleanup(){this.filterHandler.table.on("clearFilters",()=>this.clear())}}De=new WeakMap;class Ps{constructor(e,t){h(this,"callback");h(this,"precision");h(this,"table");this.table=e,this.callback=Z(t).callback}distinct(e){const s=this.table.allRows.map(a=>this.callback(a)).reduce((a,c)=>{if(Array.isArray(c)){for(const o of c)a[o]=(a[o]??0)+1;return a}return a[c]=(a[c]??0)+1,a},{}),l=Object.entries(s).map(([a,c])=>({value:a,count:c}));if(e!=null&&e.sort){const[a,c]=e.sort;a==="count"&&l.sort((o,d)=>Ze.asc(o.value,d.value)),l.sort((o,d)=>Ze[c](o[a],d[a]))}return l}avg(e){if(this.precision=(e==null?void 0:e.precision)??2,this.table.allRows.length===0)return 0;const t=this.table.allRows.map(s=>this.callback(s)).filter(Boolean);return this.round(t.reduce((s,l)=>s+l,0)/t.length)}sum(e){this.precision=(e==null?void 0:e.precision)??2;const t=this.table.allRows.map(s=>this.callback(s));return this.round(t.reduce((s,l)=>s+l,0))}median(e){this.precision=(e==null?void 0:e.precision)??2;const t=[...this.table.allRows.map(l=>this.callback(l))].sort((l,a)=>l-a).filter(Boolean);if(t.length===0)return null;const s=Math.floor(t.length/2);return t.length%2?t[s]:this.round((t[s-1]+t[s])/2)}bounds(){const t=this.table.allRows.map(s=>this.callback(s)).filter(Boolean);return t.length===0?[null,null]:[Math.min(...t),Math.max(...t)]}round(e){return Number(e.toFixed(this.precision))}}var We,Ve;class Ss{constructor(e,t,s){b(this,We,m(()=>this.createDirection()));b(this,Ve,m(()=>this.createIsActive()));h(this,"id",Math.random().toString(36).substring(2,15));h(this,"sortHandler");h(this,"field");h(this,"params");this.sortHandler=e,this.field=t,this.params=s??{}}get direction(){return i(n(this,We))}set direction(e){f(n(this,We),e)}get isActive(){return i(n(this,Ve))}set isActive(e){f(n(this,Ve),e)}set(){this.sortHandler.set(this.field,this.id,this.params)}init(e){return e?(this[e](),this):this}asc(){this.sortHandler.asc(this.field,this.id,this.params)}desc(){this.sortHandler.desc(this.field,this.id,this.params)}clear(){this.sortHandler.clear()}createIsActive(){var e;return this.id===((e=this.sortHandler.table.sort)==null?void 0:e.id)}createDirection(){var e;return this.isActive===!1?null:(e=this.sortHandler.table.sort)==null?void 0:e.direction}}We=new WeakMap,Ve=new WeakMap;class xs{constructor(e){h(this,"table");this.table=e}download(e){const t=this.get(),s=document.createElement("a");s.setAttribute("href","data:text/plain;charset=utf-8,"+encodeURIComponent(t)),s.setAttribute("download",e),s.style.display="none",document.body.appendChild(s),s.click(),document.body.removeChild(s)}get(){const e=this.getRows();return e.unshift(this.getHeader().join(",")),e.join(`\r
`)}getRows(){return this.table.allRows.map(e=>Object.entries(e).map(([s,l])=>l===null?"":typeof l=="number"?l:`"${l}"`).join(","))}getHeader(){const[e]=this.table.allRows;return Object.entries(e).map(([t,s])=>`"${t}"`)}}var Je,Qe,Ke,Ue;class Rs{constructor(e){b(this,Je,P(""));b(this,Qe,m(()=>this.createRecords()));b(this,Ke,P([]));b(this,Ue,P(""));this.rawRecords=e}get value(){return i(n(this,Je))}set value(e){f(n(this,Je),e,!0)}get records(){return i(n(this,Qe))}set records(e){f(n(this,Qe),e)}get rawRecords(){return i(n(this,Ke))}set rawRecords(e){f(n(this,Ke),e)}get filter(){return i(n(this,Ue))}set filter(e){f(n(this,Ue),e,!0)}set(){this.filter=this.value}createRecords(){return ut(this.filter)?this.rawRecords.filter(e=>de(e,this.filter,{check:ue.isLike})):this.rawRecords}}Je=new WeakMap,Qe=new WeakMap,Ke=new WeakMap,Ue=new WeakMap;class _s extends hs{constructor(t=[],s={rowsPerPage:null}){super(t,s);h(this,"i18n");h(this,"view");h(this,"sortHandler");h(this,"filterHandler");h(this,"queryHandler");h(this,"selectHandler");h(this,"pageHandler");h(this,"searchHandler");this.translate(s.i18n),this.sortHandler=new us(this),this.filterHandler=new ds(this),this.queryHandler=new fs(this),this.selectHandler=new gs(this),this.pageHandler=new bs(this),this.searchHandler=new vs(this)}setRows(t){var l;const s=((l=this.element)==null?void 0:l.scrollTop)??0;this.rawRows=t,It(()=>{this.event.dispatch("change"),this.sortHandler.restore(),this.element&&setTimeout(()=>this.element.scrollTop=s,2)})}setRowsPerPage(t){this.rowsPerPage=t,this.setPage(1)}setPage(t){switch(t){case"previous":return this.pageHandler.previous();case"next":return this.pageHandler.next();case"last":return this.pageHandler.last();default:return this.pageHandler.goto(t)}}createSearch(t){return new ws(this.searchHandler,t)}clearSearch(){this.searchHandler.clear(),this.event.dispatch("clearSearch"),this.setPage(1)}createRecordFilter(t){return new Rs(t)}createSort(t,s){return new Ss(this.sortHandler,t,s)}clearSort(){this.sortHandler.clear()}clearFilters(){this.filters=[],this.event.dispatch("clearFilters"),this.setPage(1)}createAdvancedFilter(t,s){return new ks(this.filterHandler,t,s)}createFilter(t,s){return new ms(this.filterHandler,t,s)}createQuery(){return new ys(this.queryHandler)}select(t){this.selectHandler.set(t)}selectAll(t={}){this.selectScope=t.scope==="all"?"all":"currentPage",this.selectHandler.all(this.selectScope)}getSelectedRows(){return this.selectHandler.getRows()}clearSelection(){this.selectHandler.clear()}on(t,s){this.event.add(t,s)}createCalculation(t){return new Ps(this,t)}createCSV(){return new xs(this)}createView(t){return this.view=new ps(this,t),this.view}getView(){return this.view}translate(t){this.i18n={search:"Search...",show:"Show",entries:"entries",filter:"Filter",rowCount:"Showing {start} to {end} of {total} entries",noRows:"No entries found",previous:"Previous",next:"Next",...t}}}var Hs=E('<button type="button" class="absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground"><!></button>'),Cs=E("<div><!> <!> <!></div>");function As(r,e){fe(e,!0),C(e,"value",3,"");let t=C(e,"placeholder",3,"Search..."),s=P("");const l=Mt(w=>{var S;(S=e.onSearch)==null||S.call(e,w)},200);function a(w){const S=w.target;f(s,S.value,!0),l(i(s))}function c(){var w;f(s,""),(w=e.onSearch)==null||w.call(e,"")}var o=Cs(),d=R(o);zt(d,{class:"absolute left-2 top-1/2 size-4 -translate-y-1/2 text-muted-foreground"});var p=L(d,2);Ot(p,{type:"text",get placeholder(){return t()},get value(){return i(s)},oninput:a,class:"h-8 pl-8 pr-8 text-xs"});var B=L(p,2);{var _=w=>{var S=Hs(),x=R(S);Tt(x,{class:"size-3"}),ct("click",S,c),g(w,S)};T(B,w=>{i(s)&&w(_)})}A(w=>re(o,1,w),[()=>se(["relative",e.class].filter(Boolean).join(" "))]),g(r,o),ge()}$(["click"]);var Bs=E("<!> <!>",1);function qs(r,e){fe(e,!0);const t=[10,20,50,100];let s=P("20");function l(o){o&&(f(s,o,!0),e.table.setRowsPerPage(parseInt(o)))}var a=M(),c=F(a);oe(c,()=>rs,(o,d)=>{d(o,{type:"single",get value(){return i(s)},onValueChange:l,children:(p,B)=>{var _=Bs(),w=F(_);oe(w,()=>es,(x,U)=>{U(x,{size:"sm",get class(){return e.class},children:(ee,I)=>{var q=le();A(()=>J(q,i(s))),g(ee,q)},$$slots:{default:!0}})});var S=L(w,2);oe(S,()=>ts,(x,U)=>{U(x,{children:(ee,I)=>{var q=M(),X=F(q);ae(X,17,()=>t,ht,(Q,te)=>{var G=M(),N=F(G);{let Y=m(()=>String(i(te)));oe(N,()=>ss,(be,Xe)=>{Xe(be,{get value(){return i(Y)},children:($e,dt)=>{var Ge=le();A(()=>J(Ge,`${i(te)??""} / page`)),g($e,Ge)},$$slots:{default:!0}})})}g(Q,G)}),g(ee,q)},$$slots:{default:!0}})}),g(p,_)},$$slots:{default:!0}})}),g(r,a),ge()}var js=E('<div class="flex items-center gap-2 px-1 py-2"><!> <div class="flex-1"></div> <!> <!></div>');function Es(r,e){let t=C(e,"searchable",3,!1),s=C(e,"paginated",3,!1);var l=M(),a=F(l);{var c=o=>{var d=js(),p=R(d);{var B=x=>{As(x,{placeholder:"Search...",get onSearch(){return e.onSearchChange},class:"w-64"})};T(p,x=>{t()&&x(B)})}var _=L(p,4);Lt(_,()=>e.children??Dt);var w=L(_,2);{var S=x=>{qs(x,{get table(){return e.table}})};T(w,x=>{s()&&x(S)})}g(o,d)};T(a,o=>{(t()||s()||e.children)&&o(c)})}g(r,l)}function lt(r,e){let t=C(e,"disabled",3,!1),s=C(e,"size",3,"xs");{let l=m(()=>e.active?"default":"outline");Wt(r,{get size(){return s()},get variant(){return i(l)},get disabled(){return t()},get onclick(){return e.onclick},children:(a,c)=>{var o=le();A(d=>J(o,d),[()=>String(e.page)]),g(a,o)},$$slots:{default:!0}})}}var Ns=E('<span class="px-1 text-xs text-muted-foreground">…</span>'),Fs=E('<div class="flex items-center justify-between gap-2 px-2 py-1.5"><span class="text-xs text-muted-foreground"> </span> <div class="flex items-center gap-1"><!> <!> <!></div></div>');function Is(r,e){fe(e,!0);const t=m(()=>e.table.pagesWithEllipsis),s=m(()=>e.table.currentPage),l=m(()=>e.table.pageCount),a=m(()=>e.table.rowCount);var c=M(),o=F(c);{var d=p=>{var B=Fs(),_=R(B),w=R(_),S=L(_,2),x=R(S);{let I=m(()=>i(s)===1);lt(x,{get page(){return as},get disabled(){return i(I)},onclick:()=>e.table.setPage("previous")})}var U=L(x,2);ae(U,17,()=>i(t),ht,(I,q)=>{var X=M(),Q=F(X);{var te=N=>{var Y=Ns();g(N,Y)},G=N=>{{let Y=m(()=>i(q)===i(s));lt(N,{get page(){return i(q)},get active(){return i(Y)},onclick:()=>e.table.setPage(i(q))})}};T(Q,N=>{i(q)==="..."?N(te):N(G,-1)})}g(I,X)});var ee=L(U,2);{let I=m(()=>i(s)===i(l));lt(ee,{get page(){return Vt},get disabled(){return i(I)},onclick:()=>e.table.setPage("next")})}A(()=>J(w,`${i(a)??""} rows`)),g(p,B)};T(o,p=>{i(l)>1&&p(d)})}g(r,c),ge()}function zs(r,e){let t=C(e,"variant",3,"outline");Jt(r,{get variant(){return t()},children:(s,l)=>{var a=le();A(c=>J(a,c),[()=>String(e.value??"—")]),g(s,a)},$$slots:{default:!0}})}var Os=E('<span class="text-xs text-muted-foreground"> </span>');function Ts(r,e){fe(e,!0);var t=Os(),s=R(t);A(l=>J(s,l),[()=>Qt(String(e.value??""))]),g(r,t),ge()}var Ms=E('<span class="text-xs text-muted-foreground"> </span>');function Ls(r,e){fe(e,!0);function t(a){if(!a)return"—";try{return new Date(String(a)).toLocaleString()}catch{return String(a)}}var s=Ms(),l=R(s);A(a=>J(l,a),[()=>t(e.value)]),g(r,s),ge()}function vt(r,e){if(e.accessor)return e.accessor(r);if(e.key in r)return r[e.key]}var Ds=E("<th><!></th>"),pt=E("<td><!></td>"),Ws=E('<tr class="border-b transition-colors hover:bg-transparent"></tr>'),Vs=E("<tr></tr>"),Js=E('<div><!> <div><table class="w-full caption-bottom text-sm table-fixed"><thead class="[&amp;_tr]:border-b"><tr></tr></thead></table> <div class="min-h-0 flex-1 overflow-y-auto"><table class="w-full caption-bottom text-sm table-fixed"><tbody class="[&amp;_tr:last-child]:border-0"><!></tbody></table></div></div> <!></div>');function Ys(r,e){fe(e,!0);const t={badge:zs,"health-dot":$t,"relative-time":Ts,date:Ls,"status-badge":Zt};let s=C(e,"data",19,()=>[]),l=C(e,"pageSize",3,20),a=C(e,"paginated",3,!1),c=C(e,"searchable",3,!1),o=C(e,"bordered",3,!0),d=C(e,"loading",3,!1),p=C(e,"emptyMessage",3,"No items."),B=C(e,"selected",11,null),_=C(e,"onRowClick",3,void 0);const w=new _s([],{pageSize:20}),S=new Map;function x(u){return S.has(u.key)||S.set(u.key,w.createSort(u.accessor??u.key)),S.get(u.key)}let U=w.createSearch({filterFunction:(u,y)=>{if(!y)return!0;const D=y.toLowerCase();for(const z of e.columns){if(z.hidden)continue;if(String(vt(u,z)??"").toLowerCase().includes(D))return!0}return!1}});gt(()=>{w.setRowsPerPage(l())}),gt(()=>{w.setRows(s())});function ee(u){U.set(u),a()&&w.setPage(1)}function I(u){return u.align==="right"?"text-right":u.align==="center"?"text-center":""}function q(u){return u.truncate?"min-w-0 overflow-hidden text-ellipsis":""}function X(u){if(!u.width)return;const y=typeof u.width=="number"?u.width+"px":u.width;return`width: ${y}; min-width: ${y}`}const Q=m(()=>e.columns.filter(u=>!u.hidden)),te=m(()=>w.rows),G=["w-24","w-20","w-28","w-16","w-24","w-20","w-28","w-16"];var N=Js(),Y=R(N);Es(Y,{get table(){return w},get searchable(){return c()},get paginated(){return a()},onSearchChange:ee,get children(){return e.children}});var be=L(Y,2),Xe=R(be),$e=R(Xe),dt=R($e);ae(dt,21,()=>i(Q),u=>u.key,(u,y)=>{var D=Ds(),z=R(D);{var j=k=>{const v=m(()=>x(i(y)));{let H=m(()=>i(v).direction??"asc");Gt(k,{get label(){return i(y).header},get sorted(){return i(v).isActive},get direction(){return i(H)},onclick:()=>i(v).set()})}},W=k=>{var v=le();A(()=>J(v,i(y).header)),g(k,v)};T(z,k=>{i(y).sortable!==!1?k(j):k(W,-1)})}A((k,v)=>{re(D,1,k),at(D,v)},[()=>se(["text-foreground h-10 px-2 text-left align-middle font-medium whitespace-nowrap","bg-card/95",i(y).headerClass,I(i(y))].filter(Boolean).join(" ")),()=>X(i(y))]),g(u,D)});var Ge=L(Xe,2),mt=R(Ge),yt=R(mt),kt=R(yt);{var Pt=u=>{var y=M(),D=F(y);ae(D,17,()=>G,ht,(z,j,W)=>{var k=Ws();ae(k,21,()=>i(Q),v=>v.key,(v,H)=>{var K=pt(),et=R(K);{let ve=m(()=>G[(W+i(Q).indexOf(i(H)))%G.length]);Kt(et,{get class(){return`h-4 ${i(ve)??""}`}})}A((ve,tt)=>{re(K,1,ve),at(K,tt)},[()=>se([i(H).class,I(i(H)),q(i(H))].filter(Boolean).join(" ")),()=>X(i(H))]),g(v,K)}),g(z,k)}),g(u,y)},St=u=>{Yt(u,{get message(){return p()},get colspan(){return i(Q).length}})},xt=u=>{var y=M(),D=F(y);ae(D,19,()=>i(te),(z,j)=>z.id??z.slug??`row-${j}`,(z,j)=>{var W=Vs();ae(W,21,()=>i(Q),k=>k.key,(k,v)=>{const H=m(()=>vt(i(j),i(v)));var K=pt(),et=R(K);{var ve=O=>{const V=m(()=>t[i(v).render]);var ne=M(),st=F(ne);{var rt=ce=>{var pe=M(),it=F(pe);oe(it,()=>i(V),(At,Bt)=>{Bt(At,nt({get value(){return i(H)},get row(){return i(j)}},()=>i(v).renderProps??{}))}),g(ce,pe)},Ct=ce=>{var pe=le();A(it=>J(pe,it),[()=>String(i(H)??"—")]),g(ce,pe)};T(st,ce=>{i(V)?ce(rt):ce(Ct,-1)})}g(O,ne)},tt=O=>{var V=M(),ne=F(V);oe(ne,()=>i(v).render,(st,rt)=>{rt(st,nt({get row(){return i(j)},get value(){return i(H)}},()=>i(v).renderProps??{}))}),g(O,V)},Ht=O=>{var V=le();A(ne=>J(V,ne),[()=>String(i(H)??"—")]),g(O,V)};T(et,O=>{typeof i(v).render=="string"?O(ve):typeof i(v).render=="function"?O(tt,1):O(Ht,-1)})}A((O,V)=>{re(K,1,O),at(K,V)},[()=>se(["p-2 align-middle whitespace-nowrap",i(v).class,I(i(v)),q(i(v))].filter(Boolean).join(" ")),()=>X(i(v))]),g(k,K)}),A(k=>{re(W,1,k),Ut(W,"tabindex",_()?0:void 0)},[()=>se(["border-b transition-colors hover:bg-muted/50",_()?"cursor-pointer":"",B()===(i(j).id??i(j).slug)?"bg-muted":""].filter(Boolean).join(" "))]),ct("click",W,function(...k){var v;(v=_()?()=>_()(i(j)):void 0)==null||v.apply(this,k)}),ct("keydown",W,function(...k){var v;(v=_()?H=>{(H.key==="Enter"||H.key===" ")&&(H.preventDefault(),_()(i(j)))}:void 0)==null||v.apply(this,k)}),g(z,W)}),g(u,y)};T(kt,u=>{d()?u(Pt):i(te).length===0?u(St,1):u(xt,-1)})}var Rt=L(be,2);{var _t=u=>{Is(u,{get table(){return w}})};T(Rt,u=>{a()&&u(_t)})}A((u,y)=>{re(N,1,u),re(be,1,y)},[()=>se(["flex flex-col h-full min-h-0",e.class].filter(Boolean).join(" ")),()=>se(["flex flex-col min-h-0 flex-1",o()?"rounded-xl border":""].filter(Boolean).join(" "))]),g(r,N),ge()}$(["click","keydown"]);export{Ys as D};