@cube-nl/dmp-sdk 1.0.0-rc.3 → 1.1.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +347 -25
- package/dist/app.d.ts +36 -2
- package/dist/app.js +192 -10
- package/dist/browser.js +6 -1
- package/dist/client.d.ts +2 -0
- package/dist/cube-sdk.js +179 -2
- package/dist/cube-ui.manifest.json +971 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +4 -0
- package/dist/preview.d.ts +18 -0
- package/dist/preview.js +199 -34
- package/dist/size.json +6 -0
- package/dist/ui/aggregate-block.d.ts +73 -0
- package/dist/ui/aggregate-block.js +138 -0
- package/dist/ui/attributes.d.ts +5 -0
- package/dist/ui/attributes.js +72 -0
- package/dist/ui/block.d.ts +63 -0
- package/dist/ui/block.js +229 -0
- package/dist/ui/blocks/app-shell.d.ts +4 -0
- package/dist/ui/blocks/app-shell.js +167 -0
- package/dist/ui/blocks/board.d.ts +8 -0
- package/dist/ui/blocks/board.js +292 -0
- package/dist/ui/blocks/calc.d.ts +9 -0
- package/dist/ui/blocks/calc.js +240 -0
- package/dist/ui/blocks/chart.d.ts +7 -0
- package/dist/ui/blocks/chart.js +166 -0
- package/dist/ui/blocks/detail.d.ts +8 -0
- package/dist/ui/blocks/detail.js +270 -0
- package/dist/ui/blocks/field.d.ts +8 -0
- package/dist/ui/blocks/field.js +16 -0
- package/dist/ui/blocks/form.d.ts +8 -0
- package/dist/ui/blocks/form.js +153 -0
- package/dist/ui/blocks/gap-list.d.ts +4 -0
- package/dist/ui/blocks/gap-list.js +36 -0
- package/dist/ui/blocks/kpi.d.ts +4 -0
- package/dist/ui/blocks/kpi.js +74 -0
- package/dist/ui/blocks/period-picker.d.ts +4 -0
- package/dist/ui/blocks/period-picker.js +155 -0
- package/dist/ui/blocks/state.d.ts +4 -0
- package/dist/ui/blocks/state.js +135 -0
- package/dist/ui/blocks/table.d.ts +8 -0
- package/dist/ui/blocks/table.js +607 -0
- package/dist/ui/blocks/top.d.ts +4 -0
- package/dist/ui/blocks/top.js +67 -0
- package/dist/ui/chart-svg.d.ts +28 -0
- package/dist/ui/chart-svg.js +111 -0
- package/dist/ui/csv.d.ts +9 -0
- package/dist/ui/csv.js +55 -0
- package/dist/ui/define.d.ts +24 -0
- package/dist/ui/define.js +107 -0
- package/dist/ui/dom.d.ts +12 -0
- package/dist/ui/dom.js +57 -0
- package/dist/ui/fields.d.ts +39 -0
- package/dist/ui/fields.js +73 -0
- package/dist/ui/format.d.ts +44 -0
- package/dist/ui/format.js +214 -0
- package/dist/ui/inputs.d.ts +35 -0
- package/dist/ui/inputs.js +161 -0
- package/dist/ui/manifest.d.ts +40 -0
- package/dist/ui/manifest.js +878 -0
- package/dist/ui/period.d.ts +18 -0
- package/dist/ui/period.js +52 -0
- package/dist/ui/query.d.ts +26 -0
- package/dist/ui/query.js +98 -0
- package/dist/ui/schema.d.ts +23 -0
- package/dist/ui/schema.js +21 -0
- package/dist/ui/styles.d.ts +8 -0
- package/dist/ui/styles.js +51 -0
- package/dist/ui/texts.d.ts +134 -0
- package/dist/ui/texts.js +122 -0
- package/dist/ui/theme.d.ts +58 -0
- package/dist/ui/theme.js +311 -0
- package/dist/ui/write.d.ts +20 -0
- package/dist/ui/write.js +54 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/wireframe.d.ts +37 -0
- package/dist/wireframe.js +315 -0
- package/fonts/OFL-albert-sans.txt +93 -0
- package/fonts/OFL-ibm-plex-sans.txt +93 -0
- package/fonts/OFL-inter.txt +93 -0
- package/fonts/OFL-nunito-sans.txt +93 -0
- package/fonts/OFL-source-sans-3.txt +93 -0
- package/fonts/albert-sans.woff2 +0 -0
- package/fonts/ibm-plex-sans.woff2 +0 -0
- package/fonts/inter.woff2 +0 -0
- package/fonts/nunito-sans.woff2 +0 -0
- package/fonts/source-sans-3.woff2 +0 -0
- package/package.json +8 -3
package/dist/cube-sdk.js
CHANGED
|
@@ -1,2 +1,179 @@
|
|
|
1
|
-
/*! @cube/dmp-sdk 1.
|
|
2
|
-
"use strict";(()=>{var be=Object.defineProperty;var ke=(e,n,t)=>n in e?be(e,n,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[n]=t;var k=(e,n,t)=>ke(e,typeof n!="symbol"?n+"":n,t);var R=class extends Error{constructor(t,r,s){let i=s!==null&&typeof s=="object"?s:{},o=A(i.detail)??A(i.error_description);super(o??`HTTP ${t}`);k(this,"status");k(this,"code");k(this,"reason");k(this,"type");k(this,"title");k(this,"detail");k(this,"errors");k(this,"retryAfter");k(this,"recordVersion");k(this,"allow");k(this,"headers");k(this,"body");this.name="DmpError",this.status=t,this.code=A(i.code)??A(i.error),this.reason=A(i.reason),this.type=A(i.type),this.title=A(i.title),this.detail=o,this.errors=Re(i.errors)?i.errors:null,this.retryAfter=Te(r.get("Retry-After")),this.recordVersion=r.get("X-Dmp-Record-Version"),this.allow=r.has("Allow")?(r.get("Allow")??"").split(",").map(a=>a.trim()).filter(a=>a!==""):null,this.headers=r,this.body=s}get isProblem(){return this.code!==null}};function A(e){return typeof e=="string"?e:null}function Re(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function Te(e){if(e===null||e.trim()==="")return null;let n=Number(e);if(Number.isFinite(n))return n;let t=Date.parse(e);return Number.isNaN(t)?null:Math.max(0,Math.ceil((t-Date.now())/1e3))}function Y(e){return{async getAccessToken(){let n=typeof e=="function"?await e():e;return n===void 0||n===""?null:n}}}var $="cube-dmp-sdk.pending-login";function Z(e){let n=e.fetch??globalThis.fetch.bind(globalThis),t=e.tokenStore??M(),r=e.pendingStore??ve(),s=(e.refreshLeewaySeconds??30)*1e3,i=typeof e.scopes=="string"?e.scopes:e.scopes.join(" "),o=e.metadata??{},a=Se(o)?Promise.resolve({...o,issuer:o.issuer??e.issuer}):null,l=null,c=()=>(a??(a=_e(e.issuer,n).then(p=>({...p,...o}),p=>{throw a=null,p})),a),g=async(p,d)=>{let{token_endpoint:u}=await c(),f=new URLSearchParams(p);e.clientSecret!==void 0&&f.set("client_secret",e.clientSecret);let m=await n(u,{method:"POST",headers:{Accept:"application/json","Content-Type":"application/x-www-form-urlencoded"},body:f.toString()}),y=await ee(m);if(!m.ok||y===null||typeof y!="object"||typeof y.access_token!="string")throw new R(m.status,m.headers,y);let T={accessToken:y.access_token,refreshToken:typeof y.refresh_token=="string"?y.refresh_token:null,expiresAt:typeof y.expires_in=="number"?Date.now()+y.expires_in*1e3:null,scope:typeof y.scope=="string"?y.scope:d};return await t.set(T),T},b=()=>(l??(l=(async()=>{let p=await t.get();if(p?.refreshToken==null)throw new TypeError("No refresh token: sign in again.");try{return await g({grant_type:"refresh_token",refresh_token:p.refreshToken,client_id:e.clientId},p.scope)}catch(d){throw d instanceof R&&d.status>=400&&d.status<500&&await t.set(null),d}})().finally(()=>{l=null})),l),w=async(p={})=>{let d=await c();if(!(d.code_challenge_methods_supported??[]).includes("S256"))throw new TypeError("The authorization server does not offer PKCE S256; this SDK will not sign in without it.");let u=B(64),f=p.state??B(32),m=ne(await crypto.subtle.digest("SHA-256",new TextEncoder().encode(u))),y={verifier:u,state:f,redirectUri:e.redirectUri,clientId:e.clientId};r.setItem($,JSON.stringify(y));let T=new URL(d.authorization_endpoint);return T.search=new URLSearchParams({...p.extraParams,response_type:"code",client_id:e.clientId,redirect_uri:e.redirectUri,scope:i,state:f,code_challenge:m,code_challenge_method:"S256"}).toString(),T.toString()};return{discover:c,authorizationUrl:w,async signIn(p={}){let d=X();if(d===null)throw new TypeError("signIn() needs a browser; use authorizationUrl() and redirect yourself.");d.assign(await w(p))},async handleCallback(p){let d=p??X()?.href;if(d===void 0)throw new TypeError("handleCallback() needs the callback URL outside a browser.");let u=new URL(d),f=new URLSearchParams(u.search);if(!Oe(u,e.redirectUri)||!f.has("code")&&!f.has("error"))return null;if(p===void 0){for(let y of["code","state","error","error_description","iss"])u.searchParams.delete(y);globalThis.history?.replaceState(null,"",u.pathname+u.search+u.hash)}let m=De(r.getItem($));if(m===null||f.get("state")!==m.state)throw new TypeError("The state does not match: this callback does not belong to a sign-in started here.");if(r.removeItem($),f.has("error"))throw new R(400,new Headers,{error:f.get("error")??"access_denied",error_description:f.get("error_description")??void 0});return g({grant_type:"authorization_code",code:f.get("code")??"",redirect_uri:m.redirectUri,client_id:m.clientId,code_verifier:m.verifier},i)},refresh:b,async getTokens(){return t.get()},async setTokens(p){await t.set(p)},async signOut(){await t.set(null),r.removeItem($)},async getAccessToken(){let p=await t.get();if(p===null)return null;if(p.expiresAt!==null&&p.expiresAt-s<=Date.now()&&p.refreshToken!==null)try{return(await b()).accessToken}catch{return(await t.get())?.accessToken??null}return p.accessToken},async onUnauthorized(){if((await t.get())?.refreshToken==null)return!1;try{return await b(),!0}catch{return!1}}}}function Se(e){return typeof e.authorization_endpoint=="string"&&typeof e.token_endpoint=="string"}async function _e(e,n=globalThis.fetch.bind(globalThis)){let t=`${e.replace(/\/+$/,"")}/.well-known/oauth-authorization-server`,r=await n(t,{headers:{Accept:"application/json"}}),s=await ee(r);if(!r.ok||s===null||typeof s!="object")throw new R(r.status,r.headers,s);return s}function M(e=null){let n=e;return{get:()=>n,set:t=>{n=t}}}function Ae(){let e=new Map;return{getItem:n=>e.get(n)??null,setItem:(n,t)=>{e.set(n,t)},removeItem:n=>{e.delete(n)}}}function ve(){try{let e=globalThis.sessionStorage;if(e!==void 0)return e}catch{}return Ae()}function X(){let e=globalThis.location;return e!==void 0&&typeof e.assign=="function"?e:null}function Oe(e,n){let t=new URL(n),r=s=>s.replace(/\/+$/,"")||"/";return e.origin===t.origin&&r(e.pathname)===r(t.pathname)}function De(e){if(e===null)return null;try{let n=JSON.parse(e);return typeof n.verifier=="string"&&typeof n.state=="string"&&typeof n.redirectUri=="string"&&typeof n.clientId=="string"?n:null}catch{return null}}async function ee(e){let n=await e.text();if(n==="")return null;try{return JSON.parse(n)}catch{return n}}function B(e){return ne(crypto.getRandomValues(new Uint8Array(e)))}function ne(e){let n=e instanceof Uint8Array?e:new Uint8Array(e),t="";for(let r of n)t+=String.fromCharCode(r);return btoa(t).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}var Pe=new Set(["in","between"]);function v(e,n={}){let t=new URLSearchParams;xe(t,e,n.fields),$e(t,n.filter),P(t,"sort",n.sort),P(t,"include",n.include),P(t,"with_count",n.withCount),Ue(t,n.has),P(t,"fn",n.fn),P(t,"group",n.group),n.page?.size!==void 0&&t.append("page[size]",String(n.page.size)),n.page?.number!==void 0&&t.append("page[number]",String(n.page.number));for(let[r,s]of Object.entries(n.params??{}))t.append(r,s);return t.toString().replace(/%5B/gi,"[").replace(/%5D/gi,"]").replace(/%2C/gi,",").replace(/%28/gi,"(").replace(/%29/gi,")")}function xe(e,n,t){if(t===void 0)return;let r=Ee(t)?{[n]:t}:t;for(let[s,i]of Object.entries(r))i.length>0&&e.append(`fields[${s}]`,i.join(","))}function $e(e,n){for(let[t,r]of Object.entries(n??{})){if(Array.isArray(r))throw new TypeError(`filter.${t}: a bare list names no operator and cube/api refuses it. Write { in: [...] } (or { between: [from, to] }).`);if(r==null)throw new TypeError(`filter.${t}: write { is: 'null' } or { is: 'not_null' } to filter on null.`);if(typeof r!="object"){e.append(`filter[${t}]`,F(r));continue}for(let[s,i]of Object.entries(r))i!==void 0&&e.append(`filter[${t}][${s}]`,Me(t,s,i))}}function Me(e,n,t){if(t===null){if(n!=="is")throw new TypeError(`filter.${e}.${n}: null is only meaningful under 'is'.`);return"null"}if(Array.isArray(t)){if(!Pe.has(n))throw new TypeError(`filter.${e}.${n}: takes one value; only 'in' and 'between' take a list.`);return t.map(F).join(",")}return F(t)}function Ue(e,n){for(let[t,r]of Object.entries(n??{}))r===!0?e.append(`has[${t}]`,"1"):typeof r=="number"?e.append(`has[${t}][min]`,String(r)):(r.min!==void 0&&e.append(`has[${t}][min]`,String(r.min)),r.max!==void 0&&e.append(`has[${t}][max]`,String(r.max)))}function P(e,n,t){if(t===void 0)return;let r=typeof t=="string"?t:t.filter(s=>s!=="").join(",");r!==""&&e.append(n,r)}function F(e){return typeof e=="boolean"?e?"1":"0":String(e)}function Ee(e){return Array.isArray(e)}var Ce=/^[a-z][a-z0-9_]*$/;function re(e){let n=e.baseUrl.replace(/\/+$/,""),t=e.fetch??globalThis.fetch.bind(globalThis),r=e.auth===void 0?null:typeof e.auth=="string"||typeof e.auth=="function"?Y(e.auth):e.auth,s=e.cache??(typeof document<"u"?"no-cache":void 0),i=async(a,l,{query:c,body:g,headers:b={},signal:w}={})=>{let p=`${n}${l.startsWith("/")?l:`/${l}`}${c?`?${c}`:""}`,d=async()=>{let y=r===null?null:await r.getAccessToken(),T={method:a,headers:{Accept:"application/json",...e.headers,...y!==null?{Authorization:`Bearer ${y}`}:{},...g!==void 0?{"Content-Type":"application/json"}:{},...b}};g!==void 0&&(T.body=JSON.stringify(g)),s!==void 0&&(T.cache=s),w!==void 0&&(T.signal=w);let we=Date.now(),H=await t(p,T);return e.onResponse?.({method:a,url:p,status:H.status,ms:Date.now()-we}),H},u=await d();u.status===401&&r?.onUnauthorized!==void 0&&await r.onUnauthorized()&&(await u.body?.cancel().catch(()=>{}),u=await d());let f=await Ie(u);if(!u.ok)throw new R(u.status,u.headers,f);let m=Le(f)?f:null;return{status:u.status,data:m!==null?m.data:f,meta:m?.meta??null,headers:u.headers,etag:u.headers.get("ETag"),recordVersion:u.headers.get("X-Dmp-Record-Version"),location:u.headers.get("Location"),replayed:u.headers.get("Idempotency-Replayed")==="true",rateLimit:Ne(u.headers)}};return{async capabilities(a={}){let l=(await i("GET","/_capabilities",E({},a))).data;return{...l,resources:l.resources.map(je)}},resources:a=>{if(!Ce.test(a))throw new TypeError(`'${a}' is not a resource name: cube/api names match [a-z][a-z0-9_]*.`);let l=`/${a}`,c=d=>{let u=String(d);if(u==="")throw new TypeError(`${a}: an empty id would address the collection, not a record.`);if(ie(u))throw new TypeError(`${a}: '${u}' is not an id: it would address another path, not a record.`);return`${l}/${encodeURIComponent(u)}`},g=d=>d===void 0?"":v(a,{fields:d}),b=async(d={},u={})=>await i("GET",l,E({query:v(a,d)},u)),w=async function*(d={},u={}){let f=d.page?.number??1;for(;;){let m=await b({...d,page:{...d.page,number:f}},u);yield m;let y=m.meta.page;if(y==null||y.number>=y.pages||m.data.length===0)return;f=y.number+1}},p=async(d,u,f)=>{let m=await i("POST",d,{query:g(f.fields),body:u??{},headers:U(f)});return{...m,data:m.status===204?null:m.data,accepted:m.status===202}};return{name:a,list:b,pages:w,async*all(d={},u={}){for await(let f of w(d,u))yield*f.data},get:(d,u={},f={})=>i("GET",c(d),E({query:v(a,u)},f)),aggregate:(d,u={})=>i("GET",`${l}/_aggregate`,E({query:v(a,d)},u)),create:(d,u={})=>i("POST",l,{query:g(u.fields),body:d,headers:U(u)}),update:(d,u,f={})=>i("PATCH",c(d),{query:g(f.fields),body:u,headers:U(f)}),delete:async(d,u={})=>({...await i("DELETE",c(d),{headers:U(u)}),data:null}),operation:(d,u,f,m={})=>p(`${c(d)}/${encodeURIComponent(te(u))}`,f,m),collectionOperation:(d,u,f={})=>p(`${l}/_operations/${encodeURIComponent(te(d))}`,u,f)}},request:i}}function je(e){return{...e,operations:(e.operations??[]).map(n=>({...n,input:q(n.input)})),aggregatable:q(e.aggregatable),relations:q(e.relations)}}function q(e){return Array.isArray(e)||e===void 0||e===null?{}:e}function te(e){if(e===""||e.startsWith("_"))throw new TypeError(`'${e}' is not an operation name: the '_' namespace is reserved by the API.`);if(ie(e))throw new TypeError(`'${e}' is not an operation name: it would address another path.`);return e}function ie(e){return e==="."||e===".."}function U(e){let n={};if(e.idempotencyKey!==void 0&&(n["Idempotency-Key"]=e.idempotencyKey),e.ifMatch!==void 0){if(e.ifMatch.startsWith("W/"))throw new TypeError("ifMatch takes recordVersion (X-Dmp-Record-Version), not the weak ETag.");n["If-Match"]=e.ifMatch}return n}function E(e,n){return n.signal===void 0?e:{...e,signal:n.signal}}async function Ie(e){let n=await e.text();if(n==="")return null;try{return JSON.parse(n)}catch{return n}}function Le(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)&&"data"in e}function Ne(e){let n=t=>{let r=e.get(t);return r===null||r===""||!Number.isFinite(Number(r))?null:Number(r)};return{limit:n("X-RateLimit-Limit"),remaining:n("X-RateLimit-Remaining"),reset:n("X-RateLimit-Reset")}}var se=/^[a-z][a-z0-9_]*$/,oe=["eq","neq","gt","gte","lt","lte","in","like","ilike","is","between"],ze=[[">=","gte"],["<=","lte"],["<>","neq"],[">","gt"],["<","lt"],["=","eq"]],Q=20,V=200,Fe=50,K=200,qe="1.0",C=class{constructor(n,t=null,r=()=>{}){this.manifest=t;this.guard=r;k(this,"tables",new Map);for(let[s,i]of Object.entries(Qe(n))){if(typeof i!="object"||i===null||Array.isArray(i))continue;let o=typeof i.schema?.name=="string"&&i.schema.name!==""?i.schema.name:s;se.test(o)&&this.tables.set(o,Ve(o,i))}}resourceNames(){return[...this.tables.keys()]}resource(n){if(!se.test(n))throw new TypeError(`'${n}' is not a resource name: cube/api names match [a-z][a-z0-9_]*.`);let t=(i,o)=>Promise.resolve().then(()=>o(this.authorize(n,i))),r=(i={})=>t("list",o=>Ge(o,i)),s=async function*(i={}){let o=i.page?.number??1;for(;;){let a=await r({...i,page:{...i.page,number:o}});if(yield a,a.meta.page.number>=a.meta.page.pages||a.data.length===0)return;o=a.meta.page.number+1}};return{name:n,list:r,pages:s,async*all(i={}){for await(let o of s(i))yield*o.data},get:(i,o={})=>t("get",a=>Je(a,i,o)),aggregate:i=>t("list",o=>Ze(o,i)),create:(i,o={})=>t("create",a=>tn(a,i,o)),update:(i,o,a={})=>t("update",l=>rn(l,i,o,a)),delete:(i,o={})=>t("delete",a=>sn(a,i,o)),operation:(i,o,a,l)=>t("get",c=>{throw I(c,i),le(o)}),collectionOperation:i=>t("list",()=>{throw le(i)})}}authorize(n,t){this.guard();let r=this.tables.get(n);if(r===void 0)throw h(404,"not_found",`Unknown API resource [${n}].`);let s=this.manifest?.uses;if(s!==void 0&&!(s[n]??[]).includes(t))throw h(403,"client_scope_exceeded",`This app may not ${t} '${n}': add it to "uses" in cube-app.json.`);return r}};function Qe(e){let n=e.resources;return Object.keys(e).length===1&&fe(n)&&!("rows"in n)&&!("schema"in n)?n:e}function Ve(e,n){let t=n.schema??{},r=(n.rows??[]).map(c=>J(c)),s=new Map,i=Array.isArray(t.fields)?t.fields.map(c=>[c.name,c]):Object.entries(t.fields??{});for(let[c,g]of i)s.set(c,Ke(c,g));for(let c of s.size===0?r:[])for(let g of Object.keys(c))s.has(g)||s.set(g,{name:g,types:[],nullable:!0});let o=[...s.keys()],a=new Set(["id",...t.readonly??[],...i.filter(([,c])=>c.readonly===!0).map(([c])=>c)]),l=c=>c===void 0?null:c.filter(g=>s.has(g));return{name:e,fields:s,filterable:l(t.filters)??o,writable:new Set(o.filter(c=>!a.has(c))),summary:(l(t.summary_fields)??[]).length>0?l(t.summary_fields):o,rows:r,versions:new Map(r.map(c=>[_(c.id),1])),replays:new Map}}function Ke(e,n){let t=n.type,r=typeof t=="string"?t.split("|"):Array.isArray(t)?[...t]:[];return{name:e,types:r.filter(s=>s!=="null"&&s!==""),nullable:n.nullable===!0||r.includes("null")}}function x(e,n){return new URLSearchParams(v(e.name,n))}function Ge(e,n){let t=x(e,n),r=j(e,t),s=ce(e,t),i=Be(e,t),{size:o,number:a}=Ye(t),l=ue(e,t),c=e.rows.filter(p=>s.every(d=>de(e,p,d)));i.length>0&&(c=[...c].sort((p,d)=>{for(let{field:u,descending:f}of i){let m=S(p[u],d[u]);if(m!==0)return f?-m:m}return 0}));let g=c.length,b=c.slice((a-1)*o,a*o).map(p=>L(p,r)),w={size:o,number:a,total:g,pages:Math.max(1,Math.ceil(g/o))};return{...D(200,b,O(e,w,l)),meta:{...O(e,w,l),page:w}}}function Je(e,n,t){let r=x(e,t),s=j(e,r),i=ue(e,r),o=I(e,n);return D(200,L(o,s),O(e,null,i),N(e,o))}function j(e,n){let t=`fields[${e.name}]`,r=n.get(t);if(r===null||r==="")return e.summary;let s=r.split(",").map(o=>o.trim()),i=s.filter(o=>!e.fields.has(o));if(i.length>0)throw h(422,"query_invalid",`Unknown ${t}: ${i.join(", ")}.`,{[t]:[`Allowed values: ${[...e.fields.keys()].join(", ")}.`]});return s}function ue(e,n){let t=r=>(n.get(r)??"").split(",").filter(s=>s!=="");return[...new Set([...t("include"),...t("with_count")])]}function ce(e,n){let t=[],r=[];n.forEach((s,i)=>r.push([i,s]));for(let[s,i]of r){let o=/^filter\[([^\]]+)\](?:\[([^\]]+)\])?$/.exec(s);if(o===null)continue;let a=o[1];if(!e.filterable.includes(a))throw h(422,"query_invalid",`Unknown filter: ${a}.`,{filter:[`Allowed values: ${e.filterable.join(", ")}.`]},"not_filterable");t.push(o[2]===void 0?We(a,i):He(a,o[2],i))}if(t.length>Q)throw h(422,"query_invalid",`A query takes at most ${Q} filters.`,{filter:[`Sent ${t.length}; the limit is ${Q}.`]});return t}function We(e,n){for(let[t,r]of ze)if(n.startsWith(t))return{field:e,operator:r,value:n.slice(t.length)};return{field:e,operator:"eq",value:n}}function He(e,n,t){if(!oe.includes(n))throw h(422,"query_invalid",`Unknown filter operator: ${n}.`,{filter:[`Allowed operators: ${oe.join(", ")}.`]});if(n==="between"&&t.split(",").length!==2)throw h(422,"query_invalid",`filter[${e}][between] takes exactly 2 values.`,{filter:[`Write filter[${e}][between]=low,high. Received ${t.split(",").length} value(s).`]});if(n==="in"&&t.split(",").length>V)throw h(422,"query_invalid",`filter[${e}][in] takes at most ${V} values.`,{filter:[`Sent ${t.split(",").length}; the limit is ${V}.`]});if(n==="is"&&t!=="null"&&t!=="not_null")throw h(422,"query_invalid",`filter[${e}][is] takes null or not_null.`,{filter:[`Received: ${t}.`]});return{field:e,operator:n,value:t}}function de(e,n,t){let r=n[t.field],s=i=>ln(e.fields.get(t.field),i.trim());switch(t.operator){case"eq":return G(r,s(t.value));case"neq":return r!=null&&!G(r,s(t.value));case"gt":return r!=null&&S(r,s(t.value))>0;case"gte":return r!=null&&S(r,s(t.value))>=0;case"lt":return r!=null&&S(r,s(t.value))<0;case"lte":return r!=null&&S(r,s(t.value))<=0;case"in":return t.value.split(",").some(i=>G(r,s(i)));case"between":{let[i,o]=t.value.split(",").map(s);return r!=null&&S(r,i)>=0&&S(r,o)<=0}case"like":case"ilike":return typeof r=="string"&&Xe(r,t.value);case"is":return t.value==="null"?r==null:r!=null;default:return!1}}function Xe(e,n){let t=n.split("%").map(r=>r.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")).join(".*");return new RegExp(t,"iu").test(e)}function Be(e,n){let t=n.get("sort");if(t===null||t==="")return[];let r=t.split(",").map(i=>i.trim()).filter(i=>i!=="").map(i=>({field:i.replace(/^[-+]/,""),descending:i.startsWith("-")})),s=r.map(i=>i.field).filter(i=>!e.fields.has(i));if(s.length>0)throw h(422,"query_invalid",`Unknown sort: ${s.join(", ")}.`,{sort:[`Allowed values: ${[...e.fields.keys()].join(", ")}.`]},"not_sortable");return r}function Ye(e){let n=r=>{let s=e.get(r);if(s===null||s==="")return null;if(!/^\d+$/.test(s))throw h(422,"query_invalid",`${r} must be a positive integer.`,{[r]:["Expected a positive integer."]});return Number(s)},t=n("page[size]")??Fe;if(t>K)throw h(422,"cardinality_exceeded",`page[size] may not exceed ${K}.`,{"page.size":[`The maximum page size is ${K}.`]});return{size:Math.max(1,t),number:Math.max(1,n("page[number]")??1)}}function Ze(e,n){let t=x(e,n),r=ce(e,t),s=(t.get("fn")??"").split(",").filter(g=>g!==""),i=(t.get("group")??"").split(",").filter(g=>g!=="");if(s.length===0)throw h(422,"query_invalid","fn is required.",{fn:["Name at least one function, e.g. fn=count."]});let o=s.map(g=>en(e,g)),a=i.map(g=>nn(e,g)),l=new Map;for(let g of e.rows.filter(b=>r.every(w=>de(e,b,w)))){let b={};for(let[d,u]of i.entries())b[u]=a[d](g);let w=JSON.stringify(Object.values(b)),p=l.get(w)??{key:b,rows:[]};p.rows.push(g),l.set(w,p)}i.length===0&&l.size===0&&l.set("[]",{key:{},rows:[]});let c=[...l.values()].map(({key:g,rows:b})=>{let w={...g};for(let[p,d]of s.entries())w[d]=o[p](b);return w});return D(200,c,{...O(e,null,[]),groups:i.length===0?null:c.length})}function en(e,n){if(n==="count")return i=>i.length;let t=/^(count|sum|avg|min|max)\(([^)]+)\)$/.exec(n);if(t===null)throw h(422,"query_invalid",`Unknown function: ${n}.`,{fn:["Allowed: count, count(field), sum(field), avg(field), min(field), max(field)."]},"unknown_function");let[,r,s]=t;if(!e.fields.has(s))throw h(422,"query_invalid",`Unknown fn: ${s}.`,{fn:[`Allowed values: ${[...e.fields.keys()].join(", ")}.`]},"not_aggregatable");return i=>{let o=i.map(l=>l[s]).filter(l=>l!=null),a=o.map(Number).filter(l=>Number.isFinite(l));switch(r){case"count":return o.length;case"sum":return a.reduce((l,c)=>l+c,0);case"avg":return a.length===0?null:a.reduce((l,c)=>l+c,0)/a.length;case"min":return o.length===0?null:o.reduce((l,c)=>S(c,l)<0?c:l);default:return o.length===0?null:o.reduce((l,c)=>S(c,l)>0?c:l)}}}function nn(e,n){let[t,r]=n.split(".");if(!e.fields.has(t))throw h(422,"query_invalid",`Unknown group: ${t}.`,{group:[`Allowed values: ${[...e.fields.keys()].join(", ")}.`]},"not_groupable");let s={year:4,month:7,day:10};if(r===void 0)return o=>o[t]??null;let i=s[r];if(i===void 0)throw h(422,"query_invalid",`Unknown truncation: ${r}.`,{group:["Allowed truncations in the preview: year, month, day."]},"unknown_truncation");return o=>typeof o[t]=="string"?o[t].slice(0,i):null}function tn(e,n,t){let r=t.fields===void 0?e.summary:j(e,x(e,{fields:t.fields})),s=JSON.stringify([n,t.fields??null]);if(t.idempotencyKey!==void 0){let l=e.replays.get(t.idempotencyKey);if(l!==void 0){if(l.body!==s)throw h(422,"validation_failed","This Idempotency-Key was already used with a different request body. Use a new key, or resend the original body.");return{...l.response,replayed:!0}}}let i=pe(e,n),o={id:an(e),...i};for(let l of e.fields.keys())l in o||(o[l]=null);e.rows.push(o),e.versions.set(_(o.id),1);let a=D(201,L(o,r),O(e,null,[]),N(e,o));return t.idempotencyKey!==void 0&&e.replays.set(t.idempotencyKey,{body:s,response:a}),a}function rn(e,n,t,r){let s=r.fields===void 0?e.summary:j(e,x(e,{fields:r.fields})),i=I(e,n);return ge(e,i,r.ifMatch),Object.assign(i,pe(e,t)),e.versions.set(_(i.id),(e.versions.get(_(i.id))??1)+1),D(200,L(i,s),O(e,null,[]),N(e,i))}function sn(e,n,t){let r=I(e,n);return ge(e,r,t.ifMatch),e.rows.splice(e.rows.indexOf(r),1),e.versions.delete(_(r.id)),D(204,null,null)}function pe(e,n){let t=[...e.writable],r=t.length===0?"This resource declares no writable fields.":`Writable fields: ${t.join(", ")}.`;if(!fe(n)||Object.keys(n).length===0)throw h(422,"validation_failed","The request body must be a JSON object naming at least one writable field.",{body:[r]});let s=Object.keys(n).filter(o=>!e.writable.has(o));if(s.length>0)throw h(422,"query_invalid",`Unknown or read-only fields: ${s.join(", ")}.`,Object.fromEntries(s.map(o=>[o,[r]])));let i={};for(let[o,a]of Object.entries(n)){let l=on(e.fields.get(o),a);l!==null&&(i[o]=[l])}if(Object.keys(i).length>0)throw h(422,"validation_failed","The request body failed validation.",i);return J(n)}function on(e,n){return e===void 0||e.types.length!==1?null:n===null?e.nullable?null:ae(e):(()=>{switch(e.types[0]){case"string":return typeof n=="string";case"integer":return typeof n=="number"&&Number.isInteger(n)||typeof n=="string"&&/^[+-]?\d+$/.test(n.trim());case"number":return typeof n=="number"&&Number.isFinite(n)||typeof n=="string"&&n.trim()!==""&&Number.isFinite(Number(n));case"boolean":return[!0,!1,0,1,"0","1"].includes(n);case"array":case"object":return typeof n=="object";default:return!0}})()?null:ae(e)}function ae(e){return`The ${e.name.replace(/_/g," ")} field must be ${{string:"a string",integer:"an integer",number:"a number",boolean:"true or false",array:"an array",object:"an array"}[e.types[0]]??"valid"}.`}function ge(e,n,t){if(t===void 0)return;if(t.startsWith("W/"))throw new TypeError("ifMatch takes recordVersion (X-Dmp-Record-Version), not the weak ETag.");let r=N(e,n);if(t!==r)throw h(409,"conflict","The record changed since the version you sent.",void 0,void 0,{"X-Dmp-Record-Version":r})}function an(e){let n=e.rows.map(t=>t.id);return n.length>0&&n.every(t=>typeof t=="string")&&n.some(t=>!/^\d+$/.test(t))?crypto.randomUUID():n.reduce((t,r)=>Math.max(t,Number(r)||0),0)+1}function I(e,n){let t=_(n);if(t===""||t==="."||t==="..")throw new TypeError(`${e.name}: '${t}' is not an id.`);let r=e.rows.find(s=>_(s.id)===t);if(r===void 0)throw h(404,"not_found",`No such ${e.name} record.`);return r}function le(e){return h(404,"not_found",`No such operation [${e}]. The preview runs no custom operations.`)}function L(e,n){let t={};for(let r of n)t[r]=r in e?J(e[r]):null;return t}function N(e,n){return`"preview-${_(n.id)}-${e.versions.get(_(n.id))??1}"`}function O(e,n,t){return{resource:e.name,contract:qe,page:n,groups:null,omitted:t,pruned:[],forbidden_fields:[]}}function D(e,n,t,r=null){let s=new Headers({"X-Dmp-Preview":"true"});return r!==null&&s.set("X-Dmp-Record-Version",r),{status:e,data:n,meta:t,headers:s,etag:null,recordVersion:r,location:null,replayed:!1,rateLimit:{limit:null,remaining:null,reset:null}}}function h(e,n,t,r,s,i={}){return new R(e,new Headers({"Content-Type":"application/problem+json",...i}),{type:`https://docs.cube.nl/dmp-api/problems/${n}`,title:n.replace(/_/g," "),status:e,code:n,...s!==void 0?{reason:s}:{},detail:t,...r!==void 0?{errors:r}:{}})}function ln(e,n){let t=e?.types[0];if((t==="integer"||t==="number")&&n!==""&&Number.isFinite(Number(n)))return Number(n);if(t==="boolean"){if(n==="1"||n==="true")return!0;if(n==="0"||n==="false")return!1}return n}function G(e,n){return e==null?!1:typeof e=="boolean"&&typeof n!="boolean"?(e?"1":"0")===String(n)||String(e)===String(n):typeof e=="number"&&typeof n=="string"?String(e)===n:e===n||typeof e!="object"&&String(e)===String(n)}function S(e,n){if(e==null||n==null)return e==null?n==null?0:-1:1;if(typeof e=="number"&&typeof n=="number")return e-n;if(typeof e=="boolean"||typeof n=="boolean")return+(e===!0||e===1||e==="1")-+(n===!0||n===1||n==="1");let t=String(e),r=String(n);return t<r?-1:t>r?1:0}function _(e){return e==null?"":String(e)}function fe(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function J(e){return e===void 0?e:JSON.parse(JSON.stringify(e))}var me="1.0.0-rc.3";var cn="./cube-app.config.json",dn="./cube-mock.json",pn="./cube-app.json",gn={id:"preview",name:"Voorbeeldgebruiker",scopes:[]},ye=null;async function fn(e={}){let n=e.fetch??globalThis.fetch.bind(globalThis),t=e.pageUrl??Tn(),r=await W(n,z(cn,t));return r===null?mn(e,n,t):yn(bn(r),e,n,t)}async function mn(e,n,t){let r=e.mock??ye??await W(n,z(dn,t))??{},s=e.manifest===!1?null:e.manifest??await W(n,z(pn,t)),i=!0,o=new C(r,s,()=>{if(!i)throw new R(401,new Headers({"Content-Type":"application/problem+json"}),{type:"https://docs.cube.nl/dmp-api/problems/token_invalid",title:"token invalid",status:401,code:"token_invalid",detail:"Unauthenticated."})});return{mode:"preview",signInError:null,user:()=>i?{...gn}:null,async signIn(){i=!0},async signOut(){i=!1},resource:a=>o.resource(a)}}async function yn(e,n,t,r){let s=e.dmpUrl.replace(/\/+$/,""),i=null,o=kn(n.tokenStorage==="memory"?M():Rn(`cube-app.tokens.${e.clientId}`),g=>{i=g}),a=Z({issuer:e.issuer??s,clientId:e.clientId,redirectUri:z(e.redirectUri,r),scopes:e.scopes,fetch:t,tokenStore:o,...e.metadata!==void 0?{metadata:e.metadata}:{}}),l=re({baseUrl:e.apiUrl??`${s}/apps/api/v1`,auth:a,fetch:t}),c=null;i=await o.get();try{await a.handleCallback()}catch(g){c=g instanceof Error?g:new Error(String(g))}return i===null&&c===null&&n.autoSignIn===!0&&await a.signIn(),{mode:"live",get signInError(){return c},user:()=>i===null?null:hn(i),async signIn(){c=null,await a.signIn()},async signOut(){await a.signOut()},resource:g=>l.resources(g)}}function hn(e){let n=wn(e.accessToken),t=n?.sub,r=Array.isArray(n?.scopes)?n.scopes.map(String):null;return{id:typeof t=="string"||typeof t=="number"?String(t):null,name:null,scopes:r??(e.scope??"").split(" ").filter(s=>s!=="")}}function wn(e){let n=e.split(".")[1];if(n===void 0)return null;try{let t=n.replace(/-/g,"+").replace(/_/g,"/"),r=atob(t.padEnd(t.length+(4-t.length%4)%4,"=")),s=new TextDecoder().decode(Uint8Array.from(r,o=>o.charCodeAt(0))),i=JSON.parse(s);return i!==null&&typeof i=="object"?i:null}catch{return null}}function bn(e){let n=["dmpUrl","clientId","redirectUri"].filter(r=>typeof e[r]!="string"||e[r]===""),t=e.scopes;if(typeof t=="string"||Array.isArray(t)&&t.every(r=>typeof r=="string")||n.push("scopes"),n.length>0)throw new TypeError(`cube-app.config.json is incomplete: ${n.join(", ")} missing or not a string.`);return e}async function W(e,n){let t;try{t=await e(n,{headers:{Accept:"application/json"},...typeof document<"u"?{cache:"no-store"}:{}})}catch{return null}if(t.status===404||t.status===410)return null;if(!t.ok)throw new Error(`${n} answered ${t.status}.`);try{let r=JSON.parse(await t.text());return r!==null&&typeof r=="object"&&!Array.isArray(r)?r:null}catch{return null}}function kn(e,n){return{async get(){let t=await e.get();return n(t),t},async set(t){await e.set(t),n(t)}}}function Rn(e){let n=(()=>{try{return globalThis.sessionStorage??null}catch{return null}})();return n===null?M():{get(){try{let t=n.getItem(e);return t===null?null:JSON.parse(t)}catch{return null}},set(t){try{t===null?n.removeItem(e):n.setItem(e,JSON.stringify(t))}catch{}}}}function Tn(){let e=globalThis;return e.document?.baseURI??e.location?.href??"http://localhost/"}function z(e,n){return new URL(e,n).href}function Sn(e){ye=e}var he=Object.freeze({connect:fn,mock:Sn,version:me,sdk:"1"});globalThis.CubeApp=he;})();
|
|
1
|
+
/*! @cube-nl/dmp-sdk 1.1.0-rc.1 cube-sdk.js (window.CubeApp) | MIT */
|
|
2
|
+
"use strict";(()=>{var Nr=Object.defineProperty;var jr=(e,n,t)=>n in e?Nr(e,n,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[n]=t;var b=(e,n,t)=>jr(e,typeof n!="symbol"?n+"":n,t);var L=class extends Error{constructor(t,o,a){let i=a!==null&&typeof a=="object"?a:{},r=ee(i.detail)??ee(i.error_description);super(r??`HTTP ${t}`);b(this,"status");b(this,"code");b(this,"reason");b(this,"type");b(this,"title");b(this,"detail");b(this,"errors");b(this,"retryAfter");b(this,"recordVersion");b(this,"allow");b(this,"headers");b(this,"body");this.name="DmpError",this.status=t,this.code=ee(i.code)??ee(i.error),this.reason=ee(i.reason),this.type=ee(i.type),this.title=ee(i.title),this.detail=r,this.errors=Ir(i.errors)?i.errors:null,this.retryAfter=Br(o.get("Retry-After")),this.recordVersion=o.get("X-Dmp-Record-Version"),this.allow=o.has("Allow")?(o.get("Allow")??"").split(",").map(s=>s.trim()).filter(s=>s!==""):null,this.headers=o,this.body=a}get isProblem(){return this.code!==null}};function F(e){return e instanceof L}function ee(e){return typeof e=="string"?e:null}function Ir(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function Br(e){if(e===null||e.trim()==="")return null;let n=Number(e);if(Number.isFinite(n))return n;let t=Date.parse(e);return Number.isNaN(t)?null:Math.max(0,Math.ceil((t-Date.now())/1e3))}function Wt(e){return{async getAccessToken(){let n=typeof e=="function"?await e():e;return n===void 0||n===""?null:n}}}var Fe="cube-dmp-sdk.pending-login";function Qt(e){let n=e.fetch??globalThis.fetch.bind(globalThis),t=e.tokenStore??_e(),o=e.pendingStore??Vr(),a=(e.refreshLeewaySeconds??30)*1e3,i=typeof e.scopes=="string"?e.scopes:e.scopes.join(" "),r=e.metadata??{},s=Ur(r)?Promise.resolve({...r,issuer:r.issuer??e.issuer}):null,l=null,u=()=>(s??(s=Hr(e.issuer,n).then(m=>({...m,...r}),m=>{throw s=null,m})),s),c=async(m,d)=>{let{token_endpoint:g}=await u(),w=new URLSearchParams(m);e.clientSecret!==void 0&&w.set("client_secret",e.clientSecret);let v=await n(g,{method:"POST",headers:{Accept:"application/json","Content-Type":"application/x-www-form-urlencoded"},body:w.toString()}),k=await Jt(v);if(!v.ok||k===null||typeof k!="object"||typeof k.access_token!="string")throw new L(v.status,v.headers,k);let x={accessToken:k.access_token,refreshToken:typeof k.refresh_token=="string"?k.refresh_token:null,expiresAt:typeof k.expires_in=="number"?Date.now()+k.expires_in*1e3:null,scope:typeof k.scope=="string"?k.scope:d};return await t.set(x),x},p=()=>(l??(l=(async()=>{let m=await t.get();if(m?.refreshToken==null)throw new TypeError("No refresh token: sign in again.");try{return await c({grant_type:"refresh_token",refresh_token:m.refreshToken,client_id:e.clientId},m.scope)}catch(d){throw d instanceof L&&d.status>=400&&d.status<500&&await t.set(null),d}})().finally(()=>{l=null})),l),f=async(m={})=>{let d=await u();if(!(d.code_challenge_methods_supported??[]).includes("S256"))throw new TypeError("The authorization server does not offer PKCE S256; this SDK will not sign in without it.");let g=Gt(64),w=m.state??Gt(32),v=Yt(await crypto.subtle.digest("SHA-256",new TextEncoder().encode(g))),k={verifier:g,state:w,redirectUri:e.redirectUri,clientId:e.clientId};o.setItem(Fe,JSON.stringify(k));let x=new URL(d.authorization_endpoint);return x.search=new URLSearchParams({...m.extraParams,response_type:"code",client_id:e.clientId,redirect_uri:e.redirectUri,scope:i,state:w,code_challenge:v,code_challenge_method:"S256"}).toString(),x.toString()};return{discover:u,authorizationUrl:f,async signIn(m={}){let d=qt();if(d===null)throw new TypeError("signIn() needs a browser; use authorizationUrl() and redirect yourself.");d.assign(await f(m))},async handleCallback(m){let d=m??qt()?.href;if(d===void 0)throw new TypeError("handleCallback() needs the callback URL outside a browser.");let g=new URL(d),w=new URLSearchParams(g.search);if(!Kr(g,e.redirectUri)||!w.has("code")&&!w.has("error"))return null;if(m===void 0){for(let k of["code","state","error","error_description","iss"])g.searchParams.delete(k);globalThis.history?.replaceState(null,"",g.pathname+g.search+g.hash)}let v=qr(o.getItem(Fe));if(v===null||w.get("state")!==v.state)throw new TypeError("The state does not match: this callback does not belong to a sign-in started here.");if(o.removeItem(Fe),w.has("error"))throw new L(400,new Headers,{error:w.get("error")??"access_denied",error_description:w.get("error_description")??void 0});return c({grant_type:"authorization_code",code:w.get("code")??"",redirect_uri:v.redirectUri,client_id:v.clientId,code_verifier:v.verifier},i)},refresh:p,async getTokens(){return t.get()},async setTokens(m){await t.set(m)},async signOut(){await t.set(null),o.removeItem(Fe)},async getAccessToken(){let m=await t.get();if(m===null)return null;if(m.expiresAt!==null&&m.expiresAt-a<=Date.now()&&m.refreshToken!==null)try{return(await p()).accessToken}catch{return(await t.get())?.accessToken??null}return m.accessToken},async onUnauthorized(){if((await t.get())?.refreshToken==null)return!1;try{return await p(),!0}catch{return!1}}}}function Ur(e){return typeof e.authorization_endpoint=="string"&&typeof e.token_endpoint=="string"}async function Hr(e,n=globalThis.fetch.bind(globalThis)){let t=`${e.replace(/\/+$/,"")}/.well-known/oauth-authorization-server`,o=await n(t,{headers:{Accept:"application/json"}}),a=await Jt(o);if(!o.ok||a===null||typeof a!="object")throw new L(o.status,o.headers,a);return a}function _e(e=null){let n=e;return{get:()=>n,set:t=>{n=t}}}function zr(){let e=new Map;return{getItem:n=>e.get(n)??null,setItem:(n,t)=>{e.set(n,t)},removeItem:n=>{e.delete(n)}}}function Vr(){try{let e=globalThis.sessionStorage;if(e!==void 0)return e}catch{}return zr()}function qt(){let e=globalThis.location;return e!==void 0&&typeof e.assign=="function"?e:null}function Kr(e,n){let t=new URL(n),o=a=>a.replace(/\/+$/,"")||"/";return e.origin===t.origin&&o(e.pathname)===o(t.pathname)}function qr(e){if(e===null)return null;try{let n=JSON.parse(e);return typeof n.verifier=="string"&&typeof n.state=="string"&&typeof n.redirectUri=="string"&&typeof n.clientId=="string"?n:null}catch{return null}}async function Jt(e){let n=await e.text();if(n==="")return null;try{return JSON.parse(n)}catch{return n}}function Gt(e){return Yt(crypto.getRandomValues(new Uint8Array(e)))}function Yt(e){let n=e instanceof Uint8Array?e:new Uint8Array(e),t="";for(let o of n)t+=String.fromCharCode(o);return btoa(t).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}var Gr=new Set(["in","between"]);function te(e,n={}){let t=new URLSearchParams;Wr(t,e,n.fields),Qr(t,n.filter),be(t,"sort",n.sort),be(t,"include",n.include),be(t,"with_count",n.withCount),Yr(t,n.has),be(t,"fn",n.fn),be(t,"group",n.group),n.page?.size!==void 0&&t.append("page[size]",String(n.page.size)),n.page?.number!==void 0&&t.append("page[number]",String(n.page.number));for(let[o,a]of Object.entries(n.params??{}))t.append(o,a);return t.toString().replace(/%5B/gi,"[").replace(/%5D/gi,"]").replace(/%2C/gi,",").replace(/%28/gi,"(").replace(/%29/gi,")")}function Wr(e,n,t){if(t===void 0)return;let o=Xr(t)?{[n]:t}:t;for(let[a,i]of Object.entries(o))i.length>0&&e.append(`fields[${a}]`,i.join(","))}function Qr(e,n){for(let[t,o]of Object.entries(n??{})){if(Array.isArray(o))throw new TypeError(`filter.${t}: a bare list names no operator and cube/api refuses it. Write { in: [...] } (or { between: [from, to] }).`);if(o==null)throw new TypeError(`filter.${t}: write { is: 'null' } or { is: 'not_null' } to filter on null.`);if(typeof o!="object"){e.append(`filter[${t}]`,dt(o));continue}for(let[a,i]of Object.entries(o))i!==void 0&&e.append(`filter[${t}][${a}]`,Jr(t,a,i))}}function Jr(e,n,t){if(t===null){if(n!=="is")throw new TypeError(`filter.${e}.${n}: null is only meaningful under 'is'.`);return"null"}if(Array.isArray(t)){if(!Gr.has(n))throw new TypeError(`filter.${e}.${n}: takes one value; only 'in' and 'between' take a list.`);return t.map(dt).join(",")}return dt(t)}function Yr(e,n){for(let[t,o]of Object.entries(n??{}))o===!0?e.append(`has[${t}]`,"1"):typeof o=="number"?e.append(`has[${t}][min]`,String(o)):(o.min!==void 0&&e.append(`has[${t}][min]`,String(o.min)),o.max!==void 0&&e.append(`has[${t}][max]`,String(o.max)))}function be(e,n,t){if(t===void 0)return;let o=typeof t=="string"?t:t.filter(a=>a!=="").join(",");o!==""&&e.append(n,o)}function dt(e){return typeof e=="boolean"?e?"1":"0":String(e)}function Xr(e){return Array.isArray(e)}var Zr=/^[a-z][a-z0-9_]*$/;function Zt(e){let n=e.baseUrl.replace(/\/+$/,""),t=e.fetch??globalThis.fetch.bind(globalThis),o=e.auth===void 0?null:typeof e.auth=="string"||typeof e.auth=="function"?Wt(e.auth):e.auth,a=e.cache??(typeof document<"u"?"no-cache":void 0),i=async(s,l,{query:u,body:c,headers:p={},signal:f}={})=>{let m=`${n}${l.startsWith("/")?l:`/${l}`}${u?`?${u}`:""}`,d=async()=>{let k=o===null?null:await o.getAccessToken(),x={method:s,headers:{Accept:"application/json",...e.headers,...k!==null?{Authorization:`Bearer ${k}`}:{},...c!==void 0?{"Content-Type":"application/json"}:{},...p}};c!==void 0&&(x.body=JSON.stringify(c)),a!==void 0&&(x.cache=a),f!==void 0&&(x.signal=f);let P=Date.now(),A=await t(m,x);return e.onResponse?.({method:s,url:m,status:A.status,ms:Date.now()-P}),A},g=await d();g.status===401&&o?.onUnauthorized!==void 0&&await o.onUnauthorized()&&(await g.body?.cancel().catch(()=>{}),g=await d());let w=await to(g);if(!g.ok)throw new L(g.status,g.headers,w);let v=no(w)?w:null;return{status:g.status,data:v!==null?v.data:w,meta:v?.meta??null,headers:g.headers,etag:g.headers.get("ETag"),recordVersion:g.headers.get("X-Dmp-Record-Version"),location:g.headers.get("Location"),replayed:g.headers.get("Idempotency-Replayed")==="true",rateLimit:ro(g.headers)}};return{async capabilities(s={}){let l=(await i("GET","/_capabilities",Oe({},s))).data;return{...l,resources:l.resources.map(eo)}},resources:s=>{if(!Zr.test(s))throw new TypeError(`'${s}' is not a resource name: cube/api names match [a-z][a-z0-9_]*.`);let l=`/${s}`,u=d=>{let g=String(d);if(g==="")throw new TypeError(`${s}: an empty id would address the collection, not a record.`);if(tn(g))throw new TypeError(`${s}: '${g}' is not an id: it would address another path, not a record.`);return`${l}/${encodeURIComponent(g)}`},c=d=>d===void 0?"":te(s,{fields:d}),p=async(d={},g={})=>await i("GET",l,Oe({query:te(s,d)},g)),f=async function*(d={},g={}){let w=d.page?.number??1;for(;;){let v=await p({...d,page:{...d.page,number:w}},g);yield v;let k=v.meta.page;if(k==null||k.number>=k.pages||v.data.length===0)return;w=k.number+1}},m=async(d,g,w)=>{let v=await i("POST",d,{query:c(w.fields),body:g??{},headers:$e(w)});return{...v,data:v.status===204?null:v.data,accepted:v.status===202}};return{name:s,list:p,pages:f,async*all(d={},g={}){for await(let w of f(d,g))yield*w.data},get:(d,g={},w={})=>i("GET",u(d),Oe({query:te(s,g)},w)),aggregate:(d,g={})=>i("GET",`${l}/_aggregate`,Oe({query:te(s,d)},g)),create:(d,g={})=>i("POST",l,{query:c(g.fields),body:d,headers:$e(g)}),update:(d,g,w={})=>i("PATCH",u(d),{query:c(w.fields),body:g,headers:$e(w)}),delete:async(d,g={})=>({...await i("DELETE",u(d),{headers:$e(g)}),data:null}),operation:(d,g,w,v={})=>m(`${u(d)}/${encodeURIComponent(Xt(g))}`,w,v),collectionOperation:(d,g,w={})=>m(`${l}/_operations/${encodeURIComponent(Xt(d))}`,g,w)}},request:i}}function eo(e){return{...e,operations:(e.operations??[]).map(n=>({...n,input:pt(n.input)})),aggregatable:pt(e.aggregatable),relations:pt(e.relations)}}function pt(e){return Array.isArray(e)||e===void 0||e===null?{}:e}function en(){return crypto.randomUUID()}function Xt(e){if(e===""||e.startsWith("_"))throw new TypeError(`'${e}' is not an operation name: the '_' namespace is reserved by the API.`);if(tn(e))throw new TypeError(`'${e}' is not an operation name: it would address another path.`);return e}function tn(e){return e==="."||e===".."}function $e(e){let n={};if(e.idempotencyKey!==void 0&&(n["Idempotency-Key"]=e.idempotencyKey),e.ifMatch!==void 0){if(e.ifMatch.startsWith("W/"))throw new TypeError("ifMatch takes recordVersion (X-Dmp-Record-Version), not the weak ETag.");n["If-Match"]=e.ifMatch}return n}function Oe(e,n){return n.signal===void 0?e:{...e,signal:n.signal}}async function to(e){let n=await e.text();if(n==="")return null;try{return JSON.parse(n)}catch{return n}}function no(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)&&"data"in e}function ro(e){let n=t=>{let o=e.get(t);return o===null||o===""||!Number.isFinite(Number(o))?null:Number(o)};return{limit:n("X-RateLimit-Limit"),remaining:n("X-RateLimit-Remaining"),reset:n("X-RateLimit-Reset")}}var nn=/^[a-z][a-z0-9_]*$/,rn=["eq","neq","gt","gte","lt","lte","in","like","ilike","is","between"],oo=[[">=","gte"],["<=","lte"],["<>","neq"],[">","gt"],["<","lt"],["=","eq"]],yt=["count","sum","avg","min","max"],on=["day","week","month","quarter","year"],mt=20,ft=5,sn=1e3,gt=200,io=50,ht=200,so="1.0",J=class{constructor(n,t=null,o=()=>{}){b(this,"manifest",t);b(this,"guard",o);b(this,"tables",new Map);for(let[a,i]of Object.entries(ao(n))){if(typeof i!="object"||i===null||Array.isArray(i))continue;let r=typeof i.schema?.name=="string"&&i.schema.name!==""?i.schema.name:a;nn.test(r)&&this.tables.set(r,lo(r,i))}}rows(n){return this.tables.get(n)?.rows??[]}resourceNames(){return[...this.tables.keys()]}describe(n){let t=this.tables.get(n);return t===void 0?null:{name:n,actions:[...t.actions],fields:[...t.fields.values()].map(o=>{let a=t.choices.get(o.name);return{name:o.name,type:o.types.join("|"),format:o.format,nullable:o.nullable,readonly:!t.writable.has(o.name),enum:a===void 0?null:a.map(String),description:o.description}}),summary:[...t.summary],filterable:[...t.filterable],sortable:[...t.fields.keys()],groupable:[...t.groupable],aggregatable:Object.fromEntries([...t.aggregatable].map(([o,a])=>[o,a.filter(i=>i!=="count")]))}}resource(n){if(!nn.test(n))throw new TypeError(`'${n}' is not a resource name: cube/api names match [a-z][a-z0-9_]*.`);let t=(i,r)=>Promise.resolve().then(()=>r(this.authorize(n,i))),o=(i={})=>t("list",r=>co(r,i)),a=async function*(i={}){let r=i.page?.number??1;for(;;){let s=await o({...i,page:{...i.page,number:r}});if(yield s,s.meta.page.number>=s.meta.page.pages||s.data.length===0)return;r=s.meta.page.number+1}};return{name:n,list:o,pages:a,async*all(i={}){for await(let r of a(i))yield*r.data},get:(i,r={})=>t("get",s=>po(s,i,r)),aggregate:i=>t("aggregate",r=>yo(r,i)),create:(i,r={})=>t("create",s=>So(s,i,r)),update:(i,r,s={})=>t("update",l=>xo(l,i,r,s)),delete:(i,r={})=>t("delete",s=>To(s,i,r)),operation:(i,r,s,l)=>t("get",u=>{throw Ne(u,i),un(r)}),collectionOperation:i=>t("list",()=>{throw un(i)})}}authorize(n,t){this.guard();let o=this.tables.get(n);if(o===void 0)throw R(404,"not_found",`Unknown API resource [${n}].`);let a=this.manifest?.uses;if(a!==void 0&&!(a[n]??[]).includes(t))throw R(403,"client_scope_exceeded",`This app may not ${t} '${n}': add it to "uses" in cube-app.json.`);return o}};function ao(e){let n=e.resources;return Object.keys(e).length===1&&ye(n)&&!("rows"in n)&&!("schema"in n)?n:e}function lo(e,n){let t=n.schema??{},o=(n.rows??[]).map(p=>vt(p)),a=new Map,i=Array.isArray(t.fields)?t.fields.map(p=>[p.name,p]):Object.entries(t.fields??{});for(let[p,f]of i)a.set(p,uo(p,f));for(let p of a.size===0?o:[])for(let f of Object.keys(p))a.has(f)||a.set(f,{name:f,types:[],nullable:!0,format:null,description:null});let r=[...a.keys()],s=(ye(t.choices)?Object.entries(t.choices):[]).filter(p=>ye(p[1])&&Array.isArray(p[1].values)),l=new Set(["id",...t.readonly??[],...i.filter(([,p])=>p.readonly===!0).map(([p])=>p),...s.filter(([,p])=>p.writable===!1).map(([p])=>p)]),u=new Map;for(let[p,f]of i)Array.isArray(f.enum)&&u.set(p,f.enum);for(let[p,f]of s)u.set(p,f.values);let c=p=>Array.isArray(p)?p.filter(f=>typeof f=="string"&&a.has(f)):null;return{name:e,actions:Array.isArray(t.actions)?t.actions.filter(p=>typeof p=="string"):["list","get","create","update","delete"],fields:a,filterable:c(t.filters)??r,groupable:c(t.groupable)??r,aggregatable:new Map(ye(t.aggregatable)?Object.entries(t.aggregatable).filter(([p,f])=>a.has(p)&&Array.isArray(f)).map(([p,f])=>[p,[...f]]):r.map(p=>[p,[...yt]])),choices:u,writable:new Set(r.filter(p=>!l.has(p))),summary:(c(t.summary_fields)??[]).length>0?c(t.summary_fields):r,rows:o,versions:new Map(o.map(p=>[K(p.id),1])),replays:new Map}}function uo(e,n){let t=n.type,o=typeof t=="string"?t.split("|"):Array.isArray(t)?[...t]:[];return{name:e,types:o.filter(a=>a!=="null"&&a!==""),nullable:n.nullable===!0||o.includes("null"),format:typeof n.format=="string"?n.format:null,description:typeof n.description=="string"?n.description:null}}function we(e,n){return new URLSearchParams(te(e.name,n))}function co(e,n){let t=we(e,n),o=Pe(e,t),a=dn(e,t),i=ho(e,t),{size:r,number:s}=bo(t),l=cn(e,t),u=e.rows.filter(m=>a.every(d=>pn(e,m,d)));i.length>0&&(u=[...u].sort((m,d)=>{for(let{field:g,descending:w}of i){let v=B(m[g],d[g]);if(v!==0)return w?-v:v}return 0}));let c=u.length,p=u.slice((s-1)*r,s*r).map(m=>je(m,o)),f={size:r,number:s,total:c,pages:Math.max(1,Math.ceil(c/r))};return{...ie(200,p,oe(e,f,l)),meta:{...oe(e,f,l),page:f}}}function po(e,n,t){let o=we(e,t),a=Pe(e,o),i=cn(e,o),r=Ne(e,n);return ie(200,je(r,a),oe(e,null,i),Ie(e,r))}function Pe(e,n){let t=`fields[${e.name}]`,o=n.get(t);if(o===null||o==="")return e.summary;let a=o.split(",").map(r=>r.trim()),i=a.filter(r=>!e.fields.has(r));if(i.length>0)throw R(422,"query_invalid",`Unknown ${t}: ${i.join(", ")}.`,{[t]:[`Allowed values: ${[...e.fields.keys()].join(", ")}.`]});return a}function cn(e,n){let t=o=>(n.get(o)??"").split(",").filter(a=>a!=="");return[...new Set([...t("include"),...t("with_count")])]}function dn(e,n){let t=[],o=[];n.forEach((a,i)=>o.push([i,a]));for(let[a,i]of o){let r=/^filter\[([^\]]+)\](?:\[([^\]]+)\])?$/.exec(a);if(r===null)continue;let s=r[1];if(!e.filterable.includes(s))throw R(422,"query_invalid",`Unknown filter: ${s}.`,{filter:[`Allowed values: ${e.filterable.join(", ")}.`]},"not_filterable");t.push(r[2]===void 0?mo(s,i):fo(s,r[2],i))}if(t.length>mt)throw R(422,"query_invalid",`A query takes at most ${mt} filters.`,{filter:[`Sent ${t.length}; the limit is ${mt}.`]});return t}function mo(e,n){for(let[t,o]of oo)if(n.startsWith(t))return{field:e,operator:o,value:n.slice(t.length)};return{field:e,operator:"eq",value:n}}function fo(e,n,t){if(!rn.includes(n))throw R(422,"query_invalid",`Unknown filter operator: ${n}.`,{filter:[`Allowed operators: ${rn.join(", ")}.`]});if(n==="between"&&t.split(",").length!==2)throw R(422,"query_invalid",`filter[${e}][between] takes exactly 2 values.`,{filter:[`Write filter[${e}][between]=low,high. Received ${t.split(",").length} value(s).`]});if(n==="in"&&t.split(",").length>gt)throw R(422,"query_invalid",`filter[${e}][in] takes at most ${gt} values.`,{filter:[`Sent ${t.split(",").length}; the limit is ${gt}.`]});if(n==="is"&&t!=="null"&&t!=="not_null")throw R(422,"query_invalid",`filter[${e}][is] takes null or not_null.`,{filter:[`Received: ${t}.`]});return{field:e,operator:n,value:t}}function pn(e,n,t){let o=n[t.field],a=i=>Eo(e.fields.get(t.field),i.trim());switch(t.operator){case"eq":return bt(o,a(t.value));case"neq":return o!=null&&!bt(o,a(t.value));case"gt":return o!=null&&B(o,a(t.value))>0;case"gte":return o!=null&&B(o,a(t.value))>=0;case"lt":return o!=null&&B(o,a(t.value))<0;case"lte":return o!=null&&B(o,a(t.value))<=0;case"in":return t.value.split(",").some(i=>bt(o,a(i)));case"between":{let[i,r]=t.value.split(",").map(a);return o!=null&&B(o,i)>=0&&B(o,r)<=0}case"like":case"ilike":return typeof o=="string"&&go(o,t.value);case"is":return t.value==="null"?o==null:o!=null;default:return!1}}function go(e,n){let t=n.split("%").map(o=>o.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")).join(".*");return new RegExp(t,"iu").test(e)}function ho(e,n){let t=n.get("sort");if(t===null||t==="")return[];let o=t.split(",").map(i=>i.trim()).filter(i=>i!=="").map(i=>({field:i.replace(/^[-+]/,""),descending:i.startsWith("-")})),a=o.map(i=>i.field).filter(i=>!e.fields.has(i));if(a.length>0)throw R(422,"query_invalid",`Unknown sort: ${a.join(", ")}.`,{sort:[`Allowed values: ${[...e.fields.keys()].join(", ")}.`]},"not_sortable");return o}function bo(e){let n=o=>{let a=e.get(o);if(a===null||a==="")return null;if(!/^\d+$/.test(a))throw R(422,"query_invalid",`${o} must be a positive integer.`,{[o]:["Expected a positive integer."]});return Number(a)},t=n("page[size]")??io;if(t>ht)throw R(422,"cardinality_exceeded",`page[size] may not exceed ${ht}.`,{"page.size":[`The maximum page size is ${ht}.`]});return{size:Math.max(1,t),number:Math.max(1,n("page[number]")??1)}}function yo(e,n){let t=we(e,n),o=(t.get("fn")??"").trim();if(o==="")throw R(422,"query_invalid","fn is required: name at least one aggregation function.",{fn:[`Expected e.g. fn=count or fn=sum(field). ${wt(e)}`]});let a=o.split(",").map(m=>m.trim()),i=a.map(m=>wo(e,m));an(a,"fn");let r=(t.get("group")??"").trim(),s=r===""?[]:r.split(",").map(m=>m.trim());if(s.length>ft)throw R(422,"cardinality_exceeded",`group may not exceed ${ft} dimensions, ${s.length} given.`,{group:[`Use at most ${ft} dimensions.`]});let l=s.map(m=>vo(e,m));an(s,"group");let u=dn(e,t),c=new Map;for(let m of e.rows.filter(d=>u.every(g=>pn(e,d,g)))){let d={};for(let[v,k]of s.entries())d[k]=l[v](m);let g=JSON.stringify(Object.values(d)),w=c.get(g)??{key:d,rows:[]};w.rows.push(m),c.set(g,w)}if(s.length===0&&c.size===0&&c.set("[]",{key:{},rows:[]}),c.size>sn)throw R(422,"cardinality_exceeded","The grouping produces more groups than the configured maximum.",{groepen:["The grouping produces more groups than the configured maximum.",`Allowed values: groepeer grover, of filter eerst; maximaal ${sn} groepen.`]},"too_many_groups");let f=[...c.values()].sort((m,d)=>{for(let g of s){let w=B(m.key[g],d.key[g]);if(w!==0)return w}return 0}).map(({key:m,rows:d})=>{let g={...m};for(let[w,v]of a.entries())g[v]=i[w](d);return g});return ie(200,f,{...oe(e,null,[]),groups:f.length})}function an(e,n){let t=[...new Set(e.filter((o,a)=>e.indexOf(o)!==a))];if(t.length>0)throw R(422,"query_invalid",`Duplicate ${n} entry: ${t.join(", ")}.`,{[n]:[`List each ${n} entry once.`]})}function wt(e){return e.aggregatable.size===0?"This resource has no aggregatable fields; only bare count is available.":`Aggregatable fields: ${[...e.aggregatable.keys()].join(", ")}.`}function wo(e,n){let t=/^([a-z]+)\(([a-z0-9_]+)\)$/.exec(n);if(t===null&&!/^[a-z]+$/.test(n))throw R(422,"query_invalid",`Unparseable fn entry: ${n}.`,{fn:["Expected `count` or `function(field)`, e.g. sum(field)."]});let o=t===null?n:t[1],a=t===null?null:t[2];if(!yt.includes(o))throw R(422,"query_invalid",`Unknown aggregation function: ${o}.`,{fn:[`Allowed values: ${yt.join(", ")}.`]});if(a===null){if(o!=="count")throw R(422,"query_invalid",`${o} must be applied to a field, e.g. ${o}(field).`,{fn:[wt(e)]});return r=>r.length}let i=e.aggregatable.get(a);if(i===void 0)throw R(422,"query_invalid",`Unknown aggregatable field: ${a}.`,{fn:[wt(e)]});if(!i.includes(o))throw R(422,"query_invalid",`${o} is not allowed on ${a}.`,{fn:[`Allowed functions for ${a}: ${i.join(", ")}.`]});return r=>{let s=r.map(u=>u[a]).filter(u=>u!=null),l=s.map(Number).filter(u=>Number.isFinite(u));switch(o){case"count":return r.length;case"sum":return l.length===0?null:l.reduce((u,c)=>u+c,0);case"avg":return l.length===0?null:l.reduce((u,c)=>u+c,0)/l.length;case"min":return s.length===0?null:s.reduce((u,c)=>B(c,u)<0?c:u);default:return s.length===0?null:s.reduce((u,c)=>B(c,u)>0?c:u)}}}function vo(e,n){let t=n.split(".");if(t.length>2)throw R(422,"query_invalid",`Unparseable group entry: ${n}.`,{group:["Expected `field` or `field.unit`, e.g. published_at.month."]});let[o,a]=t;if(!e.groupable.includes(o))throw R(422,"query_invalid",`Unknown group: ${o}.`,{group:[`Allowed values: ${e.groupable.join(", ")}.`]},"not_groupable");if(a===void 0)return i=>i[o]??null;if(!on.includes(a))throw R(422,"query_invalid",`Unknown truncation unit: ${a}.`,{group:[`Allowed values: ${on.join(", ")}.`]});return i=>ko(i[o],a)}function ko(e,n){let t=typeof e=="string"?/^(\d{4})-(\d{2})-(\d{2})/.exec(e):null;if(t===null)return null;let[o,a,i]=[Number(t[1]),Number(t[2]),Number(t[3])],r=new Date(Date.UTC(o,a-1,i));if(r.getUTCFullYear()!==o||r.getUTCMonth()!==a-1||r.getUTCDate()!==i)return null;switch(n){case"day":return t[0];case"week":{let s=new Date(r.getTime()+(3-(r.getUTCDay()+6)%7)*864e5),l=s.getUTCFullYear(),u=1+Math.floor((s.getTime()-Date.UTC(l,0,1))/(7*864e5));return`${l}-W${String(u).padStart(2,"0")}`}case"month":return t[0].slice(0,7);case"quarter":return`${t[1]}-Q${Math.ceil(a/3)}`;case"year":return t[1];default:return null}}function So(e,n,t){let o=t.fields===void 0?e.summary:Pe(e,we(e,{fields:t.fields})),a=JSON.stringify([n,t.fields??null]);if(t.idempotencyKey!==void 0){let l=e.replays.get(t.idempotencyKey);if(l!==void 0){if(l.body!==a)throw R(422,"validation_failed","This Idempotency-Key was already used with a different request body. Use a new key, or resend the original body.");return{...l.response,replayed:!0}}}let i=mn(e,n),r={id:Ao(e),...i};for(let l of e.fields.keys())l in r||(r[l]=null);e.rows.push(r),e.versions.set(K(r.id),1);let s=ie(201,je(r,o),oe(e,null,[]),Ie(e,r));return t.idempotencyKey!==void 0&&e.replays.set(t.idempotencyKey,{body:a,response:s}),s}function xo(e,n,t,o){let a=o.fields===void 0?e.summary:Pe(e,we(e,{fields:o.fields})),i=Ne(e,n);return fn(e,i,o.ifMatch),Object.assign(i,mn(e,t)),e.versions.set(K(i.id),(e.versions.get(K(i.id))??1)+1),ie(200,je(i,a),oe(e,null,[]),Ie(e,i))}function To(e,n,t){let o=Ne(e,n);return fn(e,o,t.ifMatch),e.rows.splice(e.rows.indexOf(o),1),e.versions.delete(K(o.id)),ie(204,null,null)}function mn(e,n){let t=[...e.writable],o=t.length===0?"This resource declares no writable fields.":`Writable fields: ${t.join(", ")}.`;if(!ye(n)||Object.keys(n).length===0)throw R(422,"validation_failed","The request body must be a JSON object naming at least one writable field.",{body:[o]});let a=Object.keys(n).filter(r=>!e.writable.has(r));if(a.length>0)throw R(422,"query_invalid",`Unknown or read-only fields: ${a.join(", ")}.`,Object.fromEntries(a.map(r=>[r,[o]])));let i={};for(let[r,s]of Object.entries(n)){let l=e.fields.get(r),u=Co(l,s)??Ro(e,l,r,s);u!==null&&(i[r]=[u])}if(Object.keys(i).length>0)throw R(422,"validation_failed","The request body failed validation.",i);return vt(n)}function Ro(e,n,t,o){let a=e.choices.get(t);return a===void 0||o===null&&n?.nullable===!0||a.includes(o)?null:`The selected ${t.replace(/_/g," ")} is invalid.`}function Co(e,n){return e===void 0||e.types.length!==1?null:n===null?e.nullable?null:ln(e):(()=>{switch(e.types[0]){case"string":return typeof n=="string";case"integer":return typeof n=="number"&&Number.isInteger(n)||typeof n=="string"&&/^[+-]?\d+$/.test(n.trim());case"number":return typeof n=="number"&&Number.isFinite(n)||typeof n=="string"&&n.trim()!==""&&Number.isFinite(Number(n));case"boolean":return[!0,!1,0,1,"0","1"].includes(n);case"array":case"object":return typeof n=="object";default:return!0}})()?null:ln(e)}function ln(e){return`The ${e.name.replace(/_/g," ")} field must be ${{string:"a string",integer:"an integer",number:"a number",boolean:"true or false",array:"an array",object:"an array"}[e.types[0]]??"valid"}.`}function fn(e,n,t){if(t===void 0)return;if(t.startsWith("W/"))throw new TypeError("ifMatch takes recordVersion (X-Dmp-Record-Version), not the weak ETag.");let o=Ie(e,n);if(t!==o)throw R(409,"conflict","The record changed since the version you sent.",void 0,void 0,{"X-Dmp-Record-Version":o})}function Ao(e){let n=e.rows.map(t=>t.id);return n.length>0&&n.every(t=>typeof t=="string")&&n.some(t=>!/^\d+$/.test(t))?crypto.randomUUID():n.reduce((t,o)=>Math.max(t,Number(o)||0),0)+1}function Ne(e,n){let t=K(n);if(t===""||t==="."||t==="..")throw new TypeError(`${e.name}: '${t}' is not an id.`);let o=e.rows.find(a=>K(a.id)===t);if(o===void 0)throw R(404,"not_found",`No such ${e.name} record.`);return o}function un(e){return R(404,"not_found",`No such operation [${e}]. The preview runs no custom operations.`)}function je(e,n){let t={};for(let o of n)t[o]=o in e?vt(e[o]):null;return t}function Ie(e,n){return`"preview-${K(n.id)}-${e.versions.get(K(n.id))??1}"`}function oe(e,n,t){return{resource:e.name,contract:so,page:n,groups:null,omitted:t,pruned:[],forbidden_fields:[]}}function ie(e,n,t,o=null){let a=new Headers({"X-Dmp-Preview":"true"});return o!==null&&a.set("X-Dmp-Record-Version",o),{status:e,data:n,meta:t,headers:a,etag:null,recordVersion:o,location:null,replayed:!1,rateLimit:{limit:null,remaining:null,reset:null}}}function R(e,n,t,o,a,i={}){return new L(e,new Headers({"Content-Type":"application/problem+json",...i}),{type:`https://docs.cube.nl/dmp-api/problems/${n}`,title:n.replace(/_/g," "),status:e,code:n,...a!==void 0?{reason:a}:{},detail:t,...o!==void 0?{errors:o}:{}})}function Eo(e,n){let t=e?.types[0];if((t==="integer"||t==="number")&&n!==""&&Number.isFinite(Number(n)))return Number(n);if(t==="boolean"){if(n==="1"||n==="true")return!0;if(n==="0"||n==="false")return!1}return n}function bt(e,n){return e==null?!1:typeof e=="boolean"&&typeof n!="boolean"?(e?"1":"0")===String(n)||String(e)===String(n):typeof e=="number"&&typeof n=="string"?String(e)===n:e===n||typeof e!="object"&&String(e)===String(n)}function B(e,n){if(e==null||n==null)return e==null?n==null?0:-1:1;if(typeof e=="number"&&typeof n=="number")return e-n;if(typeof e=="boolean"||typeof n=="boolean")return+(e===!0||e===1||e==="1")-+(n===!0||n===1||n==="1");let t=String(e),o=String(n);return t<o?-1:t>o?1:0}function K(e){return e==null?"":String(e)}function ye(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function vt(e){return e===void 0?e:JSON.parse(JSON.stringify(e))}function gn(e){return{name:e.name,actions:[...e.actions],fields:e.fields.map(n=>({name:n.name,type:n.type,format:null,nullable:n.nullable,readonly:n.readonly,enum:null,description:n.description??null})),summary:[...e.summary],filterable:[...e.filterable],sortable:[...e.sortable],groupable:[...e.groupable],aggregatable:Object.fromEntries(Object.entries(e.aggregatable).map(([n,t])=>[n,[...t]]))}}var kt="Voorbeeldgebruiker",se={invalidPrimary:"De hoofdkleur is geen geldige hexkleur; de neutrale standaardkleur wordt gebruikt.",invalidAccent:"De accentkleur is geen geldige hexkleur; er wordt een accentkleur afgeleid.",primaryLight:"De hoofdkleur is erg licht; witte tekst erop heeft weinig contrast.",primaryDarkened:"De hoofdkleur is voor tekst donkerder gemaakt om voldoende contrast te houden."},y={loading:"Laden\u2026",empty:"Er is hier nog niets te tonen.",error:"Er ging iets mis bij het laden.",retry:"Opnieuw proberen",forbidden:"Je hebt geen toegang tot deze gegevens.",signedOut:"Je bent niet ingelogd.",signIn:"Inloggen",signOut:"Uitloggen",signedIn:"Ingelogd",previewUser:kt,pages:"Pagina's",yes:"Ja",no:"Nee",emptyValue:"\u2014",quarter:(e,n)=>`K${e} ${n}`,week:(e,n)=>`week ${e}, ${n}`,monthYear:(e,n)=>`${e} '${n.slice(-2)}`,period:{label:"Periode","this-month":"Deze maand","12m":"Laatste 12 maanden","this-year":"Dit jaar",custom:"Zelf kiezen",from:"Van",to:"Tot en met",invalidRange:"De einddatum ligt v\xF3\xF3r de begindatum.",incompleteDate:"Vul bij Van en Tot en met een volledige datum in."},noData:"geen gegevens",comparedTo:"t.o.v. vorige periode",newValue:"nieuw",higher:"hoger",lower:"lager",incomplete:"Mogelijk niet compleet: er zijn meer groepen dan de DMP in \xE9\xE9n keer teruggeeft.",asTable:"Gegevens van de grafiek",tooManyGroups:"Te veel groepen om te tonen (meer dan 1000). Kies een kortere periode of een filter.",points:e=>`${e} ${e===1?"punt":"punten"}`,change:(e,n)=>`${e} procent ${n} dan de vorige periode`,search:"Zoeken",all:"Alle",min:"Vanaf",max:"Tot en met",previous:"Vorige",next:"Volgende",pageOf:(e,n,t)=>`Pagina ${e} van ${n} \xB7 ${t} rijen`,exportCsv:"Exporteren (CSV)",exporting:e=>`${e} rijen opgehaald\u2026`,chooseRow:"Kies een rij om de details te zien.",edit:"Bewerken",save:"Opslaan",cancel:"Annuleren",saved:"Opgeslagen.",formSaved:"Opgeslagen. Dank je wel!",another:"Nog een invullen",required:"Vul dit veld in.",requiredMark:" (verplicht)",notANumber:"Vul een getal in.",notAnInteger:"Vul een geheel getal in.",conflict:"Iemand anders heeft deze rij intussen gewijzigd. Laad de nieuwste versie en probeer het opnieuw.",reload:"Opnieuw laden",saveFailed:"Opslaan is niet gelukt. Probeer het opnieuw.",exportFailed:"Exporteren is niet gelukt. Probeer het opnieuw.",formInvalid:"Niet alles is goed ingevuld.",noWritableFields:"Dit formulier heeft geen invulbare velden.",calcFailed:"De berekening lukt niet met deze invoer.",moveTo:e=>`Verplaats naar ${e}`,moveFailed:"Verplaatsen lukte niet.",tryAgain:"Probeer het opnieuw.",changedMeanwhile:"Iemand anders heeft dit intussen gewijzigd; de nieuwste stand is geladen.",more:e=>`en nog ${e}`,noColumns:'Geef de kolommen op met <cube-column value="\u2026">.',emptyColumn:"Leeg",range:(e,n)=>`Kies een waarde van ${e} tot en met ${n}.`,atLeast:e=>`Kies een waarde van ${e} of meer.`,atMost:e=>`Kies een waarde van ten hoogste ${e}.`,step:e=>`Kies een waarde in stappen van ${e}.`,example:"Voorbeeld",exampleMissing:"Voorbeeld \u2014 bestaat nog niet",exampleNotSaved:"Voorbeeld \u2014 wordt niet opgeslagen",gaps:{screen:"Scherm",what:"Wat ontbreekt",type:"Soort gegeven",why:"Waarom",none:"Er ontbreekt niets: alles in dit voorstel bestaat al in de DMP.",types:{tekst:"Tekst",getal:"Getal",bedrag:"Bedrag",datum:"Datum",keuze:"Keuze","ja/nee":"Ja/nee"}},invalid:{json:(e,n)=>`${e}: ${n} is geen geldige JSON`,number:(e,n)=>`${e}: ${n} is geen geldig getal`,attribute:e=>`${e} mag geen attribuut zijn: geen inline stijl of script`,measure:e=>`"${e}" is geen geldige meting: gebruik count of count/sum/avg/min/max(veld)`,missing:(e,n)=>`${e}: ${n} ontbreekt`,value:(e,n,t)=>`${e}: ${n} "${t}" is geen geldige waarde`,formula:"cube-calc: formula moet een functie zijn",calcSingle:"cube-calc: formula gaf \xE9\xE9n waarde, maar er zijn meer cube-results; geef een object met hun namen",dateField:e=>`${e}: date-field ontbreekt bij period`,compare:e=>`${e}: compare werkt alleen samen met period`,periodSource:e=>`Geen periodekiezer gevonden voor "${e}"`,periodEnd:e=>`"${e}" is geen geldige einddatum van de periode`,notFilterable:(e,n,t)=>`${e}: ${n} noemt "${t}", maar daarop kan niet gefilterd worden`,selector:(e,n,t)=>`${e}: ${n} "${t}" is geen geldige selector`,lookup:e=>`"${e}" is geen geldige opzoeking: gebruik resource.veld`,dimension:e=>`"${e}" is geen geldige indeling: gebruik veld of veld.day/week/month/quarter/year`},theme:se};var Sn=["color-primary","color-primary-hover","color-primary-subtle","color-primary-text","color-on-primary","color-accent","color-on-accent","color-text","color-text-muted","color-bg","color-surface","color-border","color-focus","color-danger","color-success","color-warning","color-example-bg","color-example-text","color-series-1","color-series-2","color-series-3","color-series-4","color-series-5","color-series-6","radius","radius-small","font-family"],xn={primary_colour:"#475467",corners:"normaal",font:"system"},ve={inter:{family:"Inter",files:[{file:"inter.woff2",weight:"100 900",style:"normal"}]},"albert-sans":{family:"Albert Sans",files:[{file:"albert-sans.woff2",weight:"100 900",style:"normal"}]},"source-sans-3":{family:"Source Sans 3",files:[{file:"source-sans-3.woff2",weight:"200 900",style:"normal"}]},"nunito-sans":{family:"Nunito Sans",files:[{file:"nunito-sans.woff2",weight:"200 1000",style:"normal"}]},"ibm-plex-sans":{family:"IBM Plex Sans",files:[{file:"ibm-plex-sans.woff2",weight:"100 700",style:"normal"}]}},hn='system-ui, -apple-system, "Segoe UI", Roboto, sans-serif',bn="#f6f8fa";function ae(e){if(typeof e!="string")return null;let n=/^#([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(e);if(!n||n[1]===void 0)return null;let t=n[1].toLowerCase();return t.length===3&&(t=[...t].map(o=>o+o).join("")),[parseInt(t.slice(0,2),16),parseInt(t.slice(2,4),16),parseInt(t.slice(4,6),16)]}function Rt(e){return"#"+e.map(n=>Math.max(0,Math.min(255,n)).toString(16).padStart(2,"0")).join("")}function yn(e){let[n,t,o]=e.map(a=>{let i=a/255;return i<=.03928?i/12.92:((i+.055)/1.055)**2.4});return .2126*n+.7152*t+.0722*o}function ke(e,n){let t=ae(e),o=ae(n);if(!t||!o)return 1;let a=yn(t),i=yn(o);return(Math.max(a,i)+.05)/(Math.min(a,i)+.05)}function St(e,n,t){let o=ae(e),a=ae(n);return Rt(o.map((i,r)=>Math.round(i*(1-t)+a[r]*t)))}function wn(e){return ke(e,"#ffffff")>=ke(e,"#000000")?"#ffffff":"#000000"}function Mo(e,n){let[t,o,a]=ae(e).map(k=>k/255),i=Math.max(t,o,a),r=Math.min(t,o,a),s=(i+r)/2,l=i-r,u=0,c=0;l!==0&&(c=l/(1-Math.abs(2*s-1)),i===t?u=(o-a)/l%6:i===o?u=(a-t)/l+2:u=(t-o)/l+4,u*=60),u=((u+n)%360+360)%360;let p=(1-Math.abs(2*s-1))*c,f=p*(1-Math.abs(u/60%2-1)),m=s-p/2,d=Math.floor(u/60)%6,[g,w,v]=[[p,f,0],[f,p,0],[0,p,f],[0,f,p],[f,0,p],[p,0,f]][d];return Rt([g,w,v].map(k=>Math.round((k+m)*255)))}function xt(e){let n=ae(e);return n?Rt(n):null}function Do(e){let n=[],t=xt(e.primary_colour);t===null&&(t=xt(xn.primary_colour),n.push({code:"invalid-primary",message:se.invalidPrimary}));let o=null;e.accent_colour!==void 0&&e.accent_colour!==null&&(o=xt(e.accent_colour),o===null&&n.push({code:"invalid-accent",message:se.invalidAccent})),o??(o=Mo(t,330)),ke(t,"#ffffff")<3&&n.push({code:"primary-light",message:se.primaryLight});let a=St(t,"#ffffff",.9),i=t;for(let d=0;d<=20&&(i=St(t,"#000000",d/20),!(ke(i,bn)>=4.5&&ke(i,a)>=4.5));d++);i!==t&&n.push({code:"primary-darkened-for-text",message:se.primaryDarkened});let r=wn(t),s={scherp:["0px","0px"],normaal:["6px","4px"],rond:["12px","8px"]},l=typeof e.corners=="string"&&Object.hasOwn(s,e.corners)?e.corners:"normaal",[u,c]=s[l],p=typeof e.font=="string"&&Object.hasOwn(ve,e.font)?e.font:"system",f=p==="system"?hn:`"${ve[p].family}", ${hn}`;return{tokens:{"color-primary":t,"color-primary-hover":St(t,r==="#ffffff"?"#000000":"#ffffff",.15),"color-primary-subtle":a,"color-primary-text":i,"color-on-primary":r,"color-accent":o,"color-on-accent":wn(o),"color-text":"#1f2328","color-text-muted":"#59636e","color-bg":"#ffffff","color-surface":bn,"color-border":"#d1d9e0","color-focus":i,"color-danger":"#b42318","color-success":"#067647","color-warning":"#b54708","color-example-bg":"#fef0c7","color-example-text":"#7a2e0e","color-series-1":t,"color-series-2":o,"color-series-3":"#0e9384","color-series-4":"#dc6803","color-series-5":"#7a5af8","color-series-6":"#475467",radius:u,"radius-small":c,"font-family":f},warnings:n}}var Lo=/^#[0-9a-f]{6}$/i,Fo=/^\d+(\.\d+)?(px|rem)$/,_o=/^data:image\/(svg\+xml|png);/,$o=/[;{}<>\\\u0000-\u001f]|\/\*/,vn=/["'()\\\s]/,kn=String.raw`(?:\s*"[^"]*"\s*|\s*'[^']*'\s*|[^"',]+)`,Oo=new RegExp(`^${kn}(?:,${kn})*$`);function Be(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function Po(e,n){return typeof n!="string"?!1:e.startsWith("color-")?Lo.test(n):e.startsWith("radius")?Fo.test(n):n.length>0&&n.length<=200&&!$o.test(n)&&Oo.test(n)}function Ue(e,n,t){if(typeof e!="string"||e==="")return null;if(t&&_o.test(e))return vn.test(e)?null:e;try{let o=new URL(n),a=new URL(e,o);if((a.protocol==="https:"||a.protocol==="http:")&&a.origin===o.origin&&!vn.test(a.href))return a.href}catch{}return null}function No(e,n){let t=[];for(let o of Array.isArray(e)?e:[]){if(!Be(o))continue;let a=Ue(o.src,n,!1);if(a===null)continue;let i=typeof o.weight=="string"&&/^\d{1,4}( \d{1,4})?$/.test(o.weight)?o.weight:"400";t.push({src:a,weight:i,style:o.style==="italic"?"italic":"normal"})}return t}function ne(e,n){let t=e,o=xn,a=null,i=null;Be(t)&&(Object.hasOwn(t,"source")&&Be(t.source)?(o=t.source,a=Object.hasOwn(t,"tokens")?t.tokens:null,i=Object.hasOwn(t,"font_files")?t.font_files:null):Object.hasOwn(t,"primary_colour")&&(o=t));let{tokens:r,warnings:s}=Do(o);if(Be(a))for(let c of Sn)Object.hasOwn(a,c)&&Po(c,a[c])&&(r[c]=a[c]);let l=typeof o.font=="string"&&Object.hasOwn(ve,o.font)?o.font:null,u=No(i,n);return l!==null&&u.length===0&&!Array.isArray(i)&&(u=ve[l].files.flatMap(c=>{let p=Ue("cube-theme/"+c.file,n,!1);return p===null?[]:[{src:p,weight:c.weight,style:c.style}]})),{tokens:r,logo:Ue(o.logo,n,!0),logoDark:Ue(o.logo_dark,n,!0),fontFamily:l===null?null:ve[l].family,fontFiles:u,warnings:s}}function Tn(e){return":where(:root){"+Sn.map(n=>`--cube-${n}:${e.tokens[n]}`).join(";")+"}"}var He=null,Tt=new Set;function ze(){return He??(He=ne(null,"http://localhost/")),He}function Ct(e){He=e;for(let n of[...Tt])n(e)}function Ve(e){return Tt.add(e),()=>{Tt.delete(e)}}var Rn="1.1.0-rc.1";var Y=["number","integer","currency","percent"],Mn="nl-NL",jo=["day","week","month","quarter","year"],Ke=/^(\d{4})-(\d{2})-(\d{2})$/,Io=/^\s*-?(\d+\.?\d*|\.\d+)(e[+-]?\d+)?\s*$/i,Bo=/^(count|sum|avg|min|max)(?:\(([A-Za-z_][A-Za-z0-9_]*)\))?$/,Uo=/^([A-Za-z_][A-Za-z0-9_]*)(?:\.([a-z]+))?$/,Cn=new Map,An=new Map;function At(e){let n=JSON.stringify(e),t=Cn.get(n);return t===void 0&&(t=new Intl.NumberFormat(Mn,e),Cn.set(n,t)),t}function Et(e){let n=JSON.stringify(e),t=An.get(n);return t===void 0&&(t=new Intl.DateTimeFormat(Mn,e),An.set(n,t)),t}function Se(e){return typeof e=="number"?Number.isFinite(e)?e:null:typeof e=="bigint"||typeof e=="string"&&Io.test(e)?Number(e):null}function Ho(e){return e instanceof Date?Number.isNaN(e.getTime())?null:e:typeof e=="number"?Number.isFinite(e)?new Date(e):null:typeof e=="string"?$(e):null}function _(e,n,t={}){if(e==null||e==="")return y.emptyValue;switch(n){case"number":case"integer":case"currency":case"percent":{let o=Se(e);if(o===null)return String(e);let a=t.compact===!0?{notation:"compact"}:{};if(n==="currency")return At({style:"currency",currency:t.currency??"EUR",...a}).format(o);if(n==="percent")return At({style:"percent",maximumFractionDigits:1}).format(o);let i=n==="integer"?0:t.compact===!0?1:2;return At({maximumFractionDigits:i,...a}).format(o)}case"date":case"datetime":{let o=Ho(e);if(o===null)return String(e);let a={day:"numeric",month:"short",year:"numeric"};n==="datetime"&&Object.assign(a,{hour:"2-digit",minute:"2-digit"});let i=typeof e=="string"&&Ke.test(e);return t.timeZone!==void 0&&!i&&(a.timeZone=t.timeZone),Et(a).format(o)}case"boolean":return e===!0||e==="true"||e===1?y.yes:e===!1||e==="false"||e===0?y.no:String(e);default:return Array.isArray(e)?e.map(o=>_(o,"text")).join(", "):typeof e=="object"?JSON.stringify(e):String(e)}}function Mt(e,n,t={}){switch(n){case"year":return e;case"quarter":{let o=/^(\d{4})-Q([1-4])$/.exec(e);return o?.[1]!==void 0&&o[2]!==void 0?y.quarter(o[2],o[1]):e}case"week":{let o=/^(\d{4})-W(\d{2})$/.exec(e);return o?.[1]!==void 0&&o[2]!==void 0?y.week(Number(o[2]),o[1]):e}case"month":{let o=/^(\d{4})-(\d{2})$/.exec(e);if(o?.[1]===void 0||o[2]===void 0)return e;let a=Fn(Number(o[1]),Number(o[2])-1,1);return Et(t.short===!0?{month:"short"}:{month:"short",year:"numeric"}).format(a)}case"day":{let o=Ke.test(e)?$(e):null;return o===null?e:Et({day:"numeric",month:"short"}).format(o)}default:return e}}function Dn(e){let n=Bo.exec(e.trim()),t=n?.[1];if(t===void 0||t!=="count"&&n?.[2]===void 0)throw new TypeError(y.invalid.measure(e));return{fn:t,field:n?.[2]??null}}function qe(e){let n=Uo.exec(e.trim()),t=n?.[1],o=n?.[2];if(t===void 0||o!==void 0&&!jo.includes(o))throw new TypeError(y.invalid.dimension(e));return{field:t,truncation:o??null}}function Ln(e,n){if(e?.format==="date")return"date";if(e?.format==="date-time")return"datetime";if(e?.format==="currency")return"currency";switch(e?.type){case"integer":return"integer";case"number":return"number";case"boolean":return"boolean";case"string":return En(n)??"text"}return typeof n=="boolean"?"boolean":typeof n=="number"?Number.isInteger(n)?"integer":"number":En(n)??"text"}function En(e){return typeof e!="string"?null:Ke.test(e)?$(e)===null?null:"date":/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}/.test(e)&&!Number.isNaN(Date.parse(e))?"datetime":null}function U(e){let n=e.replace(/_id$/,"").replace(/([a-z])([A-Z])/g,"$1 $2").replace(/[_\-.]+/g," ").trim().toLowerCase();return n===""?e:n.charAt(0).toUpperCase()+n.slice(1)}function $(e){let n=Ke.exec(e);if(n?.[1]!==void 0&&n[2]!==void 0&&n[3]!==void 0){let o=Fn(Number(n[1]),Number(n[2])-1,Number(n[3]));return o.getMonth()===Number(n[2])-1?o:null}let t=Date.parse(e);return Number.isNaN(t)?null:new Date(t)}function Fn(e,n,t){let o=new Date(2e3,0,1);return o.setFullYear(e,n,t),o}function O(e){let n=t=>String(t).padStart(2,"0");return`${String(e.getFullYear()).padStart(4,"0")}-${n(e.getMonth()+1)}-${n(e.getDate())}`}var On={tekst:"text",getal:"number",bedrag:"currency",datum:"date",keuze:"text","ja/nee":"boolean"},Dt=e=>typeof e=="string"&&e!=="",Ft=(e,n)=>Object.prototype.hasOwnProperty.call(e,n);function _n(e){if(typeof e!="object"||e===null)return!1;let n=e,t=n.waarden;return typeof n.resource=="string"&&/^[a-z][a-z0-9_]*$/.test(n.resource)&&(n.veld===void 0||Dt(n.veld))&&typeof n.type=="string"&&Ft(On,n.type)&&(t===void 0||Array.isArray(t)&&t.every(o=>typeof o=="string"))&&(n.type!=="keuze"||Array.isArray(t)&&t.length>0)&&Dt(n.scherm)&&Dt(n.reden)}function Pn(e){if(!Array.isArray(e))return[];let n=e.filter(_n),t=e.filter(o=>!_n(o));return t.length>0&&console.warn(`cube-app.json ontbreekt: ${t.length} malformed entries ignored`,t),n}function $n(e){return On[e]}function Ge(e,n){if(e===null)return null;let t=i=>{let r=$n(i);return r==="date"||r==="currency"?r:null},o=n.flatMap(({resource:i,veld:r,type:s,waarden:l,reden:u})=>{if(i!==e.name||r===void 0||e.fields.some(p=>p.name===r))return[];let c=$n(s);return[{name:r,type:c==="boolean"?c:c==="number"||c==="currency"?"number":"string",format:t(s),nullable:!0,readonly:!1,enum:l??null,description:u}]}),a=o.map(i=>i.name);return{...e,fields:[...e.fields.map(i=>{let r=n.find(({resource:s,veld:l})=>s===e.name&&l===i.name);return r!==void 0&&i.format==null?{...i,format:t(r.type)}:i}),...o],summary:e.summary.length>0?[...e.summary,...a]:e.summary,filterable:[...e.filterable,...a],sortable:[...e.sortable,...a]}}function zo(e){let n=2166136261;for(let t=0;t<e.length;t++)n=Math.imul(n^e.charCodeAt(t),16777619)>>>0;return n}function Vo(e,n,t){let{veld:o,type:a,waarden:i}=e,r=zo(`${e.resource}.${o}.${String(n)}`);if(o!==void 0){let s=t.filter(l=>Ft(l,o)&&l[o]!==void 0);if(s.length>0)return s[r%s.length]?.[o]}switch(a){case"tekst":return`Voorbeeld ${r%100+1}`;case"getal":return r%1e3;case"bedrag":return r%1e5/100;case"datum":return O(new Date(2026,0,1+r%365));case"keuze":return i!==void 0&&i.length>0?i[r%i.length]:null;case"ja/nee":return r%2===0}}function Nn(e,n){let t=e?.fields;return Array.isArray(t)?t:t?.[n]}async function Lt(e,n,{filter:t={},sort:o=[]}){let a=[o].flat().join(",").split(",").map(u=>u.replace(/^[-+]/,"")),i=Object.fromEntries([...n.flatMap(Object.keys),...Object.keys(t),...a].filter(u=>u!=="").map(u=>[u,{type:typeof n.find(c=>c[u]!=null)?.[u]}])),r=new Map(n.map(u=>[String(u.id),u])),s=new J({[e]:{schema:{fields:i},rows:n}}),{data:l}=await s.resource(e).list({filter:t,sort:o,page:{size:200}});return l.map(u=>r.get(String(u.id)))}function _t(e,n,t,o){let{name:a}=e,i=new Map(n.filter(f=>f.resource===a&&f.veld!==void 0).map(f=>[f.veld,f])),r=f=>f.split(/[-+(),.]/).some(m=>i.has(m)),s=(f={})=>{let m=Nn(f,a),d=m?.filter(k=>!i.has(k)),g=Object.entries(f.filter??{}),w=[f.sort??[]].flat(),v=k=>({filter:Object.fromEntries(g.filter(([x])=>i.has(x)===k)),sort:w.filter(x=>r(x)===k)});return{live:{...f,...d&&{fields:d.includes("id")?d:[...d,"id"]},...v(!1)},local:v(!0),shown:k=>m===void 0||m.includes(k)}},l=(f,m,d=!1)=>{for(let[g,w]of i)(d||m(g))&&(!Ft(f,g)||f[g]==null)&&(f[g]=Vo(w,f.id,o))},u=async(f,{local:m,shown:d})=>{let g=f.data;g.forEach(w=>l(w,d,!0)),g.length>0&&(m.sort.length>0||Object.keys(m.filter).length>0)&&(g=await Lt(a,g,m));for(let w of g)for(let v of i.keys())d(v)||delete w[v];return{...f,data:g}},c=async(f,m)=>{let d=s(f);return u(await e.list(d.live,m),d)},p=async function*(f,m){let d=s(f);for await(let g of e.pages(d.live,m))yield await u(g,d)};return{...e,list:c,pages:p,async*all(f,m){for await(let d of p(f,m))yield*d.data},async get(f,m,d){let g=s(m),w=await e.get(f,g.live,d);return l(w.data,g.shown),w},aggregate:(f,m)=>[f.fn,f.group??[],Object.keys(f.filter??{})].flat().some(r)?t.resource(a).aggregate(f):e.aggregate(f,m)}}function jn(e,n){let t=d=>String(d.id),o=new Map,a=new Map,i=new Set,r=0,s=(d,g)=>({status:d,data:g,meta:null,headers:new Headers,etag:null,recordVersion:null,location:null,replayed:!1,rateLimit:{limit:null,remaining:null,reset:null}}),l=(d,g)=>{let w=Nn(g,n);return Object.fromEntries(Object.entries(d).filter(([v])=>w?.includes(v)??!0))},u=async(d,g={})=>{let{page:w}=d.meta,v=o.size>0?await Lt(n,[...o.values()].reverse(),g):[],k=new Set(v.map(t)),x=new Set(a.size>0?(await Lt(n,[...a.values()],g)).map(t):[]),P=new Set(d.data.map(t)),A=d.data.filter(E=>!i.has(t(E))&&(!o.has(t(E))||k.has(t(E)))).map(E=>o.get(t(E))??E),D=v.filter(E=>!x.has(t(E))&&!P.has(t(E))),S=w.total-[...x].filter(E=>!k.has(E)).length+D.length;return{...d,data:(w.number===1?[...D,...A]:A).map(E=>l(E,g)),meta:{...d.meta,page:{...w,total:S}}}},c=async(d,g,w)=>{let v=o.get(String(d));if(i.has(String(d))){let k=`No such ${n} record.`;throw new L(404,new Headers,{status:404,code:"not_found",detail:k})}return v===void 0?e.get(d,g,w):s(200,l(v,g))},p=async d=>{let{data:g}=await c(d);return o.has(String(d))||a.set(String(d),g),g},f=async()=>({...s(202,null),accepted:!0}),m=async function*(d,g){for await(let w of e.pages(d,g))yield await u(w,d)};return{...e,get:c,pages:m,operation:f,collectionOperation:f,list:async(d,g)=>u(await e.list(d,g),d),async*all(d,g){for await(let w of m(d,g))yield*w.data},async create(d){let g={...d,id:`voorbeeld-${++r}`};return o.set(g.id,g),s(201,{...g})},async update(d,g){let w=await p(d),v={...w,...g,id:w.id};return o.set(String(d),v),s(200,{...v})},async delete(d){return await p(d),o.delete(String(d)),i.add(String(d)),s(204,null)}}}var qo="./cube-app.config.json",Go="./cube-mock.json",Wo="./cube-app.json",Qo="./cube-theme.json",Jo={id:"preview",name:kt,scopes:[]},Bn=null,Un=null,H=null,$t=null,We=null,In=0;function Hn(e={}){let n=H!==null&&H===$t,t=++In,o=ei(e,()=>t===In);return H=o,$t=null,o.then(()=>{n&&H===o&&Zo()},()=>{H===o&&(H=null)}),o}function Yo(){return H!==null?H:(We??(We=Xo().then(()=>{if(We=null,H!==null)return H;let e=Hn();return $t=e,e})),We)}function Xo(){let e=globalThis;return new Promise(n=>{let t=()=>{setTimeout(n,0)};e.document===void 0||e.document.readyState==="complete"||e.addEventListener===void 0?t():e.addEventListener("load",t,{once:!0})})}function Zo(){let e=globalThis.document;if(e===void 0)return;let n=e.defaultView?.CustomEvent??CustomEvent;e.dispatchEvent(new n("cube-session-change"))}async function ei(e,n){let t=e.fetch??globalThis.fetch.bind(globalThis),o=e.pageUrl??qn(),[a,i]=await Promise.all([Qe(t,xe(qo,o)),ti(e,t,o)]);return n()&&Ct(i),a===null?ni(e,t,o):ri(si(a),e,t,o)}async function ti(e,n,t){try{if(e.theme===!1)return ne(null,t);let o=e.theme??Un;if(o!==null)return ne(o,t);let a=await Qe(n,xe(Qo,t));if(a!==null&&(a.theme!==1||typeof a.source!="object"||a.source===null))throw new TypeError("cube-theme.json is not a theme file.");return ne(a,t)}catch(o){return console.warn(`cube-theme.json could not be used, the neutral theme applies: ${String(o)}`),ne(null,t)}}async function zn(e,n,t){let o=e.mock??Bn??await Qe(n,xe(Go,t))??{},a=e.manifest===!1?null:e.manifest??await Qe(n,xe(Wo,t));return[o,a]}function Vn(e,n){let t=e==="wireframe",o=t?Pn(n?.ontbreekt):[];return{soort:e??null,gaps:o,simulatesWrites:t,isExample:(a,i)=>o.some(r=>r.resource===a&&(r.veld===void 0||r.veld===i))}}function Kn(e,n){let t=new Map;return e?a=>{let i=t.get(a)??jn(n(a),a);return t.set(a,i),i}:n}async function ni(e,n,t){let[o,a]=await zn(e,n,t),i=!0,r=()=>{if(!i)throw new L(401,new Headers({"Content-Type":"application/problem+json"}),{type:"https://docs.cube.nl/dmp-api/problems/token_invalid",title:"token invalid",status:401,code:"token_invalid",detail:"Unauthenticated."})},s=Vn(a?.soort,a),l=new J(o,a,r),u=new J(o,null,r),c=p=>s.isExample(p)?u:l;return{...s,mode:"preview",signInError:null,user:()=>i?{...Jo}:null,async signIn(){i=!0},async signOut(){i=!1},resource:Kn(s.simulatesWrites,p=>{let f=c(p),m=f.resource(p),d=f.describe(p)?.fields??[],g=s.gaps.filter(({resource:w,veld:v})=>w===p&&v!==void 0&&!d.some(k=>k.name===v));return g.length>0?_t(m,g,u,u.rows(p)):m}),schema:async p=>Ge(c(p).describe(p),s.gaps)}}async function ri(e,n,t,o){let a=e.dmpUrl.replace(/\/+$/,""),i=null,r=ai(n.tokenStorage==="memory"?_e():li(`cube-app.tokens.${e.clientId}`),g=>{i=g}),s=Qt({issuer:e.issuer??a,clientId:e.clientId,redirectUri:xe(e.redirectUri,o),scopes:e.scopes,fetch:t,tokenStore:r,...e.metadata!==void 0?{metadata:e.metadata}:{}}),l=Zt({baseUrl:e.apiUrl??`${a}/apps/api/v1`,auth:s,fetch:t}),u=null,c=null,[p,f]=e.soort==="wireframe"?await zn(n,t,o):[{},null],m=Vn(e.soort,f),d=new J(p);i=await r.get();try{await s.handleCallback()}catch(g){u=g instanceof Error?g:new Error(String(g))}return i===null&&u===null&&n.autoSignIn===!0&&await s.signIn(),{...m,mode:"live",get signInError(){return u},user:()=>i===null?null:oi(i),async signIn(){u=null,await s.signIn()},async signOut(){await s.signOut()},resource:Kn(m.simulatesWrites,g=>m.isExample(g)?d.resource(g):m.gaps.some(w=>w.resource===g)?_t(l.resources(g),m.gaps,d,d.rows(g)):l.resources(g)),async schema(g){if(m.isExample(g))return Ge(d.describe(g),m.gaps);c??(c=l.capabilities());try{let w=(await c).resources.find(v=>v.name===g);return w===void 0?null:Ge(gn(w),m.gaps)}catch(w){throw c=null,w}}}}function oi(e){let n=ii(e.accessToken),t=n?.sub,o=Array.isArray(n?.scopes)?n.scopes.map(String):null;return{id:typeof t=="string"||typeof t=="number"?String(t):null,name:null,scopes:o??(e.scope??"").split(" ").filter(a=>a!=="")}}function ii(e){let n=e.split(".")[1];if(n===void 0)return null;try{let t=n.replace(/-/g,"+").replace(/_/g,"/"),o=atob(t.padEnd(t.length+(4-t.length%4)%4,"=")),a=new TextDecoder().decode(Uint8Array.from(o,r=>r.charCodeAt(0))),i=JSON.parse(a);return i!==null&&typeof i=="object"?i:null}catch{return null}}function si(e){let n=["dmpUrl","clientId","redirectUri"].filter(o=>typeof e[o]!="string"||e[o]===""),t=e.scopes;if(typeof t=="string"||Array.isArray(t)&&t.every(o=>typeof o=="string")||n.push("scopes"),n.length>0)throw new TypeError(`cube-app.config.json is incomplete: ${n.join(", ")} missing or not a string.`);return e}async function Qe(e,n){let t;try{t=await e(n,{headers:{Accept:"application/json"},...typeof document<"u"?{cache:"no-store"}:{}})}catch{return null}if(t.status===404||t.status===410)return null;if(!t.ok)throw new Error(`${n} answered ${t.status}.`);try{let o=JSON.parse(await t.text());return o!==null&&typeof o=="object"&&!Array.isArray(o)?o:null}catch{return null}}function ai(e,n){return{async get(){let t=await e.get();return n(t),t},async set(t){await e.set(t),n(t)}}}function li(e){let n=(()=>{try{return globalThis.sessionStorage??null}catch{return null}})();return n===null?_e():{get(){try{let t=n.getItem(e);return t===null?null:JSON.parse(t)}catch{return null}},set(t){try{t===null?n.removeItem(e):n.setItem(e,JSON.stringify(t))}catch{}}}}function qn(){let e=globalThis;return e.document?.baseURI??e.location?.href??"http://localhost/"}function xe(e,n){return new URL(e,n).href}function ui(e){Bn=e}function ci(e){Un=e,Ct(ne(e,qn()))}var Je=Object.freeze({connect:Hn,ready:Yo,mock:ui,theme:ci,version:Rn,sdk:"1"});var Gn={"cube-state":["kind","message","retry"],"cube-app-shell":["name","logo","logo-alt"],"cube-page":["name","label"],"cube-field":["name","label","format","multiline","options","hidden"],"cube-period-picker":["default","label","today"],"cube-kpi":["resource","measure","label","format","currency","filter","period","date-field","compare"],"cube-chart":["resource","measure","by","kind","label","format","currency","filter","period","date-field","lookup","height","limit"],"cube-top":["resource","measure","by","limit","order","label","format","currency","filter","period","date-field","lookup"],"cube-table":["resource","fields","search","filters","sort","page-size","export","detail","filter","period","date-field"],"cube-detail":["resource","record-id","fields","editable"],"cube-form":["resource","fields","submit-label","success-text"],"cube-calc":["label"],"cube-input":["name","label","type","value","min","max","step","options"],"cube-result":["name","label","format","currency","emphasis"],"cube-board":["resource","status-field","title-field","fields","sort","filter","page-size"],"cube-column":["value","label"],"cube-gap-list":["scherm"]};var di="http://www.w3.org/2000/svg";function h(e,n,t={},...o){let a=e.createElement(n);for(let[i,r]of Object.entries(t))Wn(i,r===!0||typeof r=="string"),typeof r=="function"?a.addEventListener(i.replace(/^on/,""),r):r===!0?a.setAttribute(i,""):typeof r=="string"&&a.setAttribute(i,r);return Qn(e,a,o),a}function N(e,n,t={},...o){let a=e.createElementNS(di,n);for(let[i,r]of Object.entries(t))Wn(i,!0),a.setAttribute(i,String(r));return Qn(e,a,o),a}function Wn(e,n){let t=e.toLowerCase();if(t==="style"||n&&t.startsWith("on"))throw new TypeError(y.invalid.attribute(e))}function T(e){for(;e.firstChild!==null;)e.removeChild(e.firstChild)}function Qn(e,n,t){for(let o of t)typeof o=="string"?n.appendChild(e.createTextNode(o)):o!=null&&o!==!1&&n.appendChild(o)}var Ot=`
|
|
3
|
+
:host{display:block;box-sizing:border-box;min-width:0;font-family:var(--cube-font-family,system-ui,sans-serif);
|
|
4
|
+
color:var(--cube-color-text,#1f2328);font-size:1rem;line-height:1.5}
|
|
5
|
+
:host([hidden]){display:none}
|
|
6
|
+
*,*::before,*::after{box-sizing:inherit}
|
|
7
|
+
.cube-body{display:block;min-width:0}
|
|
8
|
+
button{font:inherit;font-weight:600;cursor:pointer;display:inline-flex;align-items:center;justify-content:center;
|
|
9
|
+
gap:.375rem;min-height:2.5rem;padding:.5rem 1rem;border:1px solid var(--cube-color-primary);
|
|
10
|
+
border-radius:var(--cube-radius-small);background:var(--cube-color-primary);color:var(--cube-color-on-primary)}
|
|
11
|
+
button:hover{background:var(--cube-color-primary-hover);border-color:var(--cube-color-primary-hover)}
|
|
12
|
+
button.secondary{background:var(--cube-color-bg);color:var(--cube-color-primary-text);
|
|
13
|
+
border-color:var(--cube-color-border)}
|
|
14
|
+
button.secondary:hover{background:var(--cube-color-primary-subtle)}
|
|
15
|
+
button:disabled{cursor:not-allowed;opacity:.6}
|
|
16
|
+
input,select,textarea{font:inherit;color:inherit;max-width:100%;min-height:2.5rem;padding:.5rem .75rem;
|
|
17
|
+
border:1px solid var(--cube-color-text-muted);border-radius:var(--cube-radius-small);background:var(--cube-color-bg)}
|
|
18
|
+
a{color:var(--cube-color-primary-text)}
|
|
19
|
+
:focus-visible{outline:3px solid var(--cube-color-focus);outline-offset:2px}
|
|
20
|
+
.sr-only{position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);
|
|
21
|
+
white-space:nowrap;border:0}
|
|
22
|
+
.badge{display:inline-block;padding:.125rem .5rem;border-radius:999px;font-size:.875rem;font-weight:600;
|
|
23
|
+
background:var(--cube-color-primary-subtle);color:var(--cube-color-primary-text)}
|
|
24
|
+
.muted{color:var(--cube-color-text-muted)}
|
|
25
|
+
.example.badge,.not-saved{background:var(--cube-color-example-bg);color:var(--cube-color-example-text)}
|
|
26
|
+
p.example{margin:0 0 .5rem}
|
|
27
|
+
td.example,dd.example{text-decoration:underline dashed;text-underline-offset:.25em}
|
|
28
|
+
.not-saved{margin:0;align-self:center;padding:.125rem .5rem;border-radius:var(--cube-radius-small);font-size:.875rem;
|
|
29
|
+
font-weight:600}
|
|
30
|
+
.row{display:flex;flex-wrap:wrap;align-items:center;gap:.75rem}
|
|
31
|
+
@media (max-width:640px){.row{flex-direction:column;align-items:stretch}.row>button{width:100%}}
|
|
32
|
+
`,Jn=new WeakMap;function Ye(e,n){let t=Jn.get(e);t===void 0&&(t=new Map,Jn.set(e,t));let o=t.get(n);return o===void 0&&(o=new e.CSSStyleSheet,o.replaceSync(n),t.set(n,o)),o}var q=class extends Error{constructor(t){super(t.detail??t.kind);b(this,"state");this.state=t}};function X(e){if(e instanceof q)return e.state;if(F(e)){if(e.status===401)return{kind:"signed-out",detail:null};if(e.status===403)return{kind:"forbidden",detail:null}}return e instanceof TypeError?{kind:"error",detail:e.message}:{kind:"error",detail:null}}function pi(e){return new Promise(n=>{e.readyState==="loading"?e.addEventListener("DOMContentLoaded",()=>n(),{once:!0}):(e.defaultView?.setTimeout??setTimeout)(n,0)})}function Xe(e){return h(e,"span",{class:"badge example"},y.example,h(e,"span",{class:"sr-only"},y.exampleMissing.slice(y.example.length)))}function mi(e){return e!==null&&typeof e=="object"&&e.name==="AbortError"}function Yn(e,n={}){let t=n.session??(()=>Je.ready());class o extends e.HTMLElement{constructor(){super();b(this,"body");b(this,"current",Promise.resolve());b(this,"scheduled",!1);b(this,"controller",null);b(this,"badge",null);b(this,"onSessionChange",()=>this.schedule());b(this,"onDataChange",r=>{let s=r.detail?.resource,l=this.getAttribute("resource")?.trim()??"";typeof s=="string"&&l!==""&&s.trim()===l&&this.schedule()});let r=this.constructor,s=this.attachShadow({mode:"open"});s.adoptedStyleSheets=r.css===""?[Ye(e,Ot)]:[Ye(e,Ot),Ye(e,r.css)],this.body=h(e.document,"div",{class:"cube-body",part:"body"}),s.appendChild(this.body),s.addEventListener("cube-retry",l=>{l.stopPropagation(),this.schedule()})}static get observedAttributes(){return[...Gn[this.tag]??[]]}get updateComplete(){return(async()=>{let r;do r=this.current,await r;while(r!==this.current)})()}connectedCallback(){this.ownerDocument.addEventListener("cube-session-change",this.onSessionChange),this.ownerDocument.addEventListener("cube-data-change",this.onDataChange),this.schedule()}disconnectedCallback(){this.ownerDocument.removeEventListener("cube-session-change",this.onSessionChange),this.ownerDocument.removeEventListener("cube-data-change",this.onDataChange),this.controller?.abort(),this.controller=null,this.removeAttribute("aria-busy")}attributeChangedCallback(r,s,l){s!==l&&this.schedule()}refresh(){if(!this.isConnected)return this.current;this.controller?.abort();let r=new AbortController;this.controller=r;let s=this.run(r.signal);return this.current=s,s}schedule(){this.scheduled||!this.isConnected||(this.scheduled=!0,this.current=new Promise(r=>{queueMicrotask(()=>{this.scheduled=!1,r(this.isConnected?this.refresh():void 0)})}))}async run(r){let s=this.constructor;this.showState("loading");try{if(await pi(this.ownerDocument),r.aborted)return;let l=s.needsSession?await this.session():null;if(r.aborted)return;await this.load(r,l),r.aborted||this.mark(l)}catch(l){if(r.aborted||mi(l))return;this.badge?.remove(),this.showState(X(l))}finally{r.aborted||this.removeAttribute("aria-busy")}}session(){return t()}shownFields(){return[]}exampleField(r,s,l){return r.isExample?.(s,l)===!0&&!r.isExample(s)}notSaved(r){return r.simulatesWrites===!0?h(this.ownerDocument,"p",{class:"note not-saved"},y.exampleNotSaved):null}mark(r){let s=this.getAttribute("resource")?.trim()??"";if(!(r?.isExample!==void 0&&s!==""&&(r.isExample(s)||this.shownFields().some(u=>r.isExample(s,u))))){this.badge?.remove();return}this.badge??(this.badge=h(this.ownerDocument,"p",{class:"badge example",role:"note"},y.exampleMissing)),this.shadowRoot?.insertBefore(this.badge,this.body)}showState(r,s=null){let{kind:l,detail:u,retry:c}=typeof r=="string"?{kind:r,detail:s}:r;l==="loading"&&this.setAttribute("aria-busy","true"),T(this.body),this.body.appendChild(h(this.ownerDocument,"cube-state",{kind:l,message:u,retry:c===!1?"false":null}))}attr(r){return this.getAttribute(r)}flag(r){return this.hasAttribute(r)&&this.getAttribute(r)!=="false"}num(r,s){let l=this.getAttribute(r);if(l===null||l.trim()==="")return s;let u=Number(l);if(!Number.isFinite(u))throw new TypeError(y.invalid.number(this.localName,r));return u}json(r){let s=this.getAttribute(r);if(s===null||s.trim()==="")return null;try{return JSON.parse(s)}catch{throw new TypeError(y.invalid.json(this.localName,r))}}emit(r,s=null){let l=this.ownerDocument.defaultView?.CustomEvent??CustomEvent;return this.dispatchEvent(new l(r,{detail:s,bubbles:!0,composed:!0}))}}return b(o,"tag",""),b(o,"css",""),b(o,"needsSession",!0),o}var fi=`
|
|
33
|
+
:host{background:var(--cube-color-bg)}
|
|
34
|
+
header{display:flex;flex-wrap:wrap;align-items:center;gap:.75rem 1rem;padding:.75rem 1.5rem;
|
|
35
|
+
border-bottom:1px solid var(--cube-color-border);background:var(--cube-color-surface)}
|
|
36
|
+
.logo{display:block;height:2rem;width:auto;max-width:10rem;object-fit:contain}
|
|
37
|
+
h1{flex:1 1 auto;min-width:0;margin:0;font-size:1.25rem;line-height:1.3;overflow-wrap:anywhere}
|
|
38
|
+
.user{display:flex;flex-wrap:wrap;align-items:center;gap:.75rem;margin-left:auto}
|
|
39
|
+
nav{border-bottom:1px solid var(--cube-color-border);padding:0 1.5rem}
|
|
40
|
+
nav ul{display:flex;gap:.25rem;margin:0;padding:0;list-style:none;position:relative;overflow-x:auto}
|
|
41
|
+
nav a{display:block;padding:.75rem 1rem;white-space:nowrap;text-decoration:none;color:var(--cube-color-text-muted);
|
|
42
|
+
border-bottom:3px solid transparent}
|
|
43
|
+
nav a:hover{color:var(--cube-color-primary-text)}
|
|
44
|
+
nav a[aria-current=page]{font-weight:600;color:var(--cube-color-primary-text);
|
|
45
|
+
border-bottom-color:var(--cube-color-primary)}
|
|
46
|
+
main{padding:1.5rem}
|
|
47
|
+
::slotted(cube-page:not([hidden])){display:flex;flex-direction:column;gap:1.5rem}
|
|
48
|
+
@media (max-width:640px){header{padding:.75rem 1rem}nav{padding:0}main{padding:1rem}}
|
|
49
|
+
`,Pt="#/";function Xn(e,n){class t extends e{constructor(){super();b(this,"header");b(this,"heading");b(this,"user");b(this,"nav");b(this,"list");b(this,"main");b(this,"built","");b(this,"stopTheme",null);b(this,"onHash",()=>this.updatePages());let i=n.document;this.heading=h(i,"h1"),this.user=h(i,"div",{class:"user"}),this.header=h(i,"header",{},this.heading,this.user),this.list=h(i,"ul"),this.nav=h(i,"nav",{"aria-label":y.pages},this.list);let r=h(i,"slot",{onslotchange:()=>this.updatePages()});this.main=h(i,"main",{},r),this.body.append(this.header,this.main),this.renderHeader()}connectedCallback(){super.connectedCallback(),this.ownerDocument.defaultView?.addEventListener("hashchange",this.onHash),this.stopTheme?.(),this.stopTheme=Ve(()=>this.renderHeader()),this.renderHeader(),this.updatePages()}disconnectedCallback(){super.disconnectedCallback(),this.ownerDocument.defaultView?.removeEventListener("hashchange",this.onHash),this.stopTheme?.(),this.stopTheme=null}async load(i,r){this.renderHeader(),this.updatePages(),r!==null&&this.renderUser(r)}showState(i){let r=typeof i=="string"?i:i.kind;T(this.user),r==="signed-out"&&this.user.appendChild(this.signInButton())}renderHeader(){let i=this.attr("name")??"",r=this.attr("logo")??ze().logo,s=this.header.querySelector(".logo");if(this.heading.textContent=i,r===null||r===""){s?.remove();return}let l=h(n.document,"img",{class:"logo",src:r,alt:this.attr("logo-alt")??i});s===null?this.header.prepend(l):s.replaceWith(l)}renderUser(i){let r=n.document,s=i.user();if(T(this.user),s===null){this.user.appendChild(this.signInButton());return}this.user.append(h(r,"span",{},s.name!==null&&s.name!==""?s.name:y.signedIn),h(r,"button",{type:"button",class:"secondary",onclick:()=>{this.change(l=>l.signOut())}},y.signOut))}signInButton(){return h(n.document,"button",{type:"button",onclick:()=>{this.change(i=>i.signIn())}},y.signIn)}async change(i){try{await i(await this.session())}catch{this.refresh();return}let r=this.ownerDocument.defaultView?.CustomEvent??CustomEvent;this.ownerDocument.dispatchEvent(new r("cube-session-change"))}pages(){return Array.from(this.children).filter(i=>i.localName==="cube-page")}updatePages(){let i=this.pages(),s=(n.location??this.ownerDocument.defaultView?.location)?.hash??"",l="";if(s.startsWith(Pt))try{l=decodeURIComponent(s.slice(Pt.length))}catch{l=""}let u=i.find(p=>p.getAttribute("name")===l)??i[0];for(let p of i)p.hidden=p!==u;if(i.length<2){this.nav.remove(),T(this.list),this.built="";return}this.nav.parentNode!==this.body&&this.body.insertBefore(this.nav,this.main);let c=JSON.stringify(i.map(p=>[p.getAttribute("name"),p.getAttribute("label")]));if(c!==this.built){T(this.list);for(let p of i){let f=p.getAttribute("name")??"",m=Pt+encodeURIComponent(f),d=h(n.document,"a",{href:m},p.getAttribute("label")??f);this.list.appendChild(h(n.document,"li",{},d))}this.built=c}Array.from(this.list.querySelectorAll("a")).forEach((p,f)=>{i[f]===u?p.setAttribute("aria-current","page"):p.removeAttribute("aria-current")})}}return b(t,"tag","cube-app-shell"),b(t,"css",fi),t}var gi=/^([a-z][a-z0-9_]*)\.([A-Za-z_][A-Za-z0-9_]*)$/,Nt=200;function le(e){let n=e.getAttribute("filter");if(n===null||n.trim()==="")return{};let t;try{t=JSON.parse(n)}catch{t=null}if(t===null||typeof t!="object"||Array.isArray(t))throw new TypeError(y.invalid.json(e.localName,"filter"));return t}function hi(e){let n=e;return typeof n?.from=="string"&&typeof n.to=="string"&&typeof n.previous?.from=="string"&&typeof n.previous.to=="string"}function Ze(e,n){let t=$(n.to);if(t===null)throw new TypeError(y.invalid.periodEnd(n.to));return t.setDate(t.getDate()+1),{[e]:{gte:n.from,lt:O(t)}}}async function et(e,n){if(n===null||n==="")return null;let t=e.ownerDocument.querySelector(n),o=(e.ownerDocument.defaultView??window).customElements;if(t===null||o.get(t.localName)===void 0)throw new TypeError(y.invalid.periodSource(n));let a=t;if(await a.updateComplete,!hi(a.value))throw new TypeError(y.invalid.periodSource(n));return a}function tt(e,n,t){if(e!==null&&e!=="")return e;if(n!==null&&n!==""){let o=qe(n);if(o.truncation!==null)return o.field}throw new TypeError(y.invalid.dateField(t))}async function Zn(e,n,t,o){let a=gi.exec(n),i=a?.[1],r=a?.[2];if(i===void 0||r===void 0)throw new TypeError(y.invalid.lookup(n));let s=[...new Set(t.filter(u=>u!=null).map(u=>u))],l=new Map;for(let u=0;u<s.length;u+=Nt){o.throwIfAborted();let c=s.slice(u,u+Nt),p;try{let f={filter:{id:{in:c}},fields:["id",r],page:{size:Nt}};({data:p}=await e.resource(i).list(f,{signal:o}))}catch(f){if(o.aborted||f?.name==="AbortError")throw f;continue}for(let f of p){let m=f[r];m!=null&&l.set(String(f.id),String(m))}}return l}var bi=["number","integer","currency","percent"],M=`
|
|
50
|
+
.card{padding:1rem 1.25rem;border:1px solid var(--cube-color-border);border-radius:var(--cube-radius);
|
|
51
|
+
background:var(--cube-color-surface)}
|
|
52
|
+
`,ue=`
|
|
53
|
+
.label{margin:0 0 .5rem;font-weight:600}
|
|
54
|
+
`;function C(e,n){let t=e.getAttribute(n)?.trim()??"";if(t==="")throw new TypeError(y.invalid.missing(e.localName,n));return t}function ce(e){let n=/\(([^)]+)\)/.exec(e.getAttribute("measure")??"")?.[1]?.trim(),t=e.getAttribute("by")?.split(".")[0];return[n,t,e.getAttribute("date-field")].filter(o=>!!o)}function Te(e){if(typeof e=="string"&&e.trim()==="")return null;let n=typeof e=="number"||typeof e=="string"?Number(e):NaN;return Number.isFinite(n)?n:null}var z=class{constructor(n){b(this,"block",n);b(this,"source",null);b(this,"onChange",()=>{this.block.isConnected?this.block.refresh():this.follow(null)})}follow(n){n!==this.source&&(this.source?.removeEventListener("cube-change",this.onChange),this.source=n,n?.addEventListener("cube-change",this.onChange))}};async function de(e,n,t,o=null){let a=Dn(C(e,"measure")),i=le(e),r=e.getAttribute("period"),s=r===null||r===""?null:tt(e.getAttribute("date-field"),o,e.localName),l=await et(e,r);return t.aborted?null:(n.follow(l),{fn:a.field===null?a.fn:`${a.fn}(${a.field})`,field:a.field,count:a.fn==="count",period:l?.value??null,filterFor:u=>u===null||s===null?i:{...i,...Ze(s,u)}})}async function nt(e,n,t,o,a){try{return await e.resource(n).aggregate({fn:o.fn,group:t,filter:o.filterFor(o.period)},{signal:a})}catch(i){throw F(i)&&i.status===422&&(i.reason==="too_many_groups"||i.code==="cardinality_exceeded")?new q({kind:"error",detail:y.tooManyGroups,retry:!1}):i}}function G(e,n,t,o){let a=e.getAttribute(n),i=a===null||a.trim()===""?NaN:Number(a);return Number.isFinite(i)&&i>=t?Math.floor(i):o}async function rt(e,n,t,o,a,i){let r=a.descending?-1:1,s=t.filter(c=>c[o.by]!==null&&c[o.by]!==void 0).map(c=>({key:String(c[o.by]),value:Te(c[o.fn])})).filter(c=>c.value!==null).sort((c,p)=>r*(c.value-p.value)).slice(0,a.limit),l=e.getAttribute("lookup"),u=l===null||l===""||s.length===0?null:await Zn(n,l,s.map(c=>c.key),i);return i.aborted?null:s.map(c=>({...c,label:u===null?c.key:u.get(c.key)??`#${c.key}`}))}function pe(e,n){let t=e.getAttribute("format"),o=t!==null&&bi.includes(t)?t:n?"integer":"number",a=e.getAttribute("currency")||"EUR";return(i,r)=>_(i,o,{currency:a,compact:r===!0})}var Re=Symbol("cube-field hidden");function er(e){var n,t;return class extends(t=e.HTMLElement,n=Re,t){constructor(){super(...arguments);b(this,n)}connectedCallback(){this[Re]===void 0&&(this[Re]=this.hasAttribute("hidden")),this.hidden=!0}}}function ot(e){let n=e.field?.enum??null;return e.config?.options??(n===null?null:n.map(t=>({value:t,label:t})))}var yi=["text","number","integer","currency","percent","date","datetime","boolean"];function W(e){let n=(e??"").split(",").map(t=>t.trim()).filter(t=>t!=="");return n.length>0?n:null}function jt(e){if(e===null)return null;let n=e.split(",").map(t=>{let o=t.indexOf("="),a=(o<0?t:t.slice(0,o)).trim(),i=o<0?a:t.slice(o+1).trim();return{value:a,label:i===""?a:i}}).filter(t=>t.value!=="");return n.length>0?n:null}function V(e){let n=new Map;for(let t of Array.from(e.children)){let o=t.getAttribute("name")?.trim()??"";if(t.localName!=="cube-field"||o==="")continue;let a=t.getAttribute("format"),i=t[Re];n.set(o,{name:o,label:t.getAttribute("label"),format:a!==null&&yi.includes(a)?a:null,multiline:t.hasAttribute("multiline"),options:jt(t.getAttribute("options")),hidden:i??t.hasAttribute("hidden")})}return n}function Ce(e,n){return e.get(n)?.label??U(n)}function Q(e,n,t,o){let a=e!==null&&e.summary.length>0?e.summary:null;return(n??a??(o===void 0?[]:Object.keys(o))).filter(r=>t.get(r)?.hidden!==!0).map(r=>{let s=e?.fields.find(u=>u.name===r),l=t.get(r);return{name:r,label:Ce(t,r),format:l?.format??Ln(s,o?.[r]),field:s,config:l}})}var me=`
|
|
55
|
+
.field{display:flex;flex-direction:column;gap:.25rem;min-width:0}
|
|
56
|
+
.field label{font-weight:600}
|
|
57
|
+
.field .required{font-weight:400;color:var(--cube-color-text-muted)}
|
|
58
|
+
.field.check{flex-direction:row;align-items:center;gap:.5rem}
|
|
59
|
+
.field.check input{min-height:auto;width:1.25rem;height:1.25rem}
|
|
60
|
+
.field [aria-invalid=true]{border-color:var(--cube-color-danger,#b42318)}
|
|
61
|
+
.field-error{margin:0;color:var(--cube-color-danger,#b42318);font-size:.875rem}
|
|
62
|
+
`,wi=/^-?(\d{1,3}(\.\d{3})+|\d*)(,\d+)?$/,vi=/^-?[1-9]\d{0,2}(\.\d{3})+$/,ki=/^-?(\d+\.?\d*|\.\d+)$/,Si=0;function xi(e){return e.includes(",")?wi.test(e)&&/\d/.test(e)?Number(e.replace(/\./g,"").replace(",",".")):null:vi.test(e)?Number(e.replace(/\./g,"")):ki.test(e)?Number(e):null}var tr=e=>Number(e.toPrecision(12));function Ae(e,n){if(e.trim()==="")return{value:null};if(Y.includes(n)){let t=xi(e.replace(/[\s €%]/g,""));return t===null||!Number.isFinite(t)?{error:y.notANumber}:n==="integer"&&!Number.isInteger(t)?{error:y.notAnInteger}:{value:n==="percent"?tr(t/100):t}}if(n==="boolean")return{value:e==="true"||e==="1"};if(n==="datetime"){let t=Date.parse(e);return{value:Number.isNaN(t)?e:new Date(t).toISOString()}}return{value:e}}function nr(e){if(!F(e)||e.status!==422||e.errors===null)return null;let n={};for(let[t,o]of Object.entries(e.errors)){let a=Array.isArray(o)?o.find(i=>typeof i=="string"):void 0;a!==void 0&&(n[t]=a)}return Object.keys(n).length>0?n:null}function Ti(e,n){if(e==null)return"";if(Y.includes(n)){let t=typeof e=="number"?e:Number(e);return typeof e=="boolean"||!Number.isFinite(t)?String(e):String(n==="percent"?tr(t*100):t).replace(".",",")}if(n==="date"&&typeof e=="string")return e.slice(0,10);if(n==="datetime"&&typeof e=="string"){let t=Date.parse(e);if(Number.isNaN(t))return e;let o=new Date(t),a=i=>String(i).padStart(2,"0");return`${O(o)}T${a(o.getHours())}:${a(o.getMinutes())}`}return typeof e=="object"?JSON.stringify(e):String(e)}function Ri(e,n,t,o){let a=ot(n),i=Ti(t,n.format);if(a!==null){let u=a.some(f=>f.value===i),c=i===""||u?a:[...a,{value:i,label:i}],p=h(e,"select",{id:o,name:n.name},h(e,"option",{value:""},y.emptyValue),...c.map(f=>h(e,"option",{value:f.value},f.label)));return p.value=i,p}if(n.format==="text"&&n.config?.multiline===!0){let u=h(e,"textarea",{id:o,name:n.name,rows:"4"});return u.value=i,u}let r=Y.includes(n.format),s=n.format==="date"?"date":n.format==="datetime"?"datetime-local":"text",l=h(e,"input",{id:o,name:n.name,type:n.format==="boolean"?"checkbox":s,inputmode:r?"decimal":null});return n.format==="boolean"?l.checked=t===!0||t==="true"||t===1:l.value=i,l}function fe(e,n,t,o){let a=`cube-input-${++Si}`,i=Ri(e,n,t,a),r=i.getAttribute("type")==="checkbox";o&&!r&&i.setAttribute("aria-required","true");let s=o&&!r?h(e,"span",{class:"required","aria-hidden":"true"},y.requiredMark):null,l=h(e,"label",{for:a},n.label,s),u=h(e,"p",{id:`${a}-error`,class:"field-error",hidden:!0});return{element:h(e,"div",{class:r?"field check":"field"},...r?[i,l]:[l,i],u),name:n.name,read(){return r?{value:i.checked}:o&&i.value.trim()===""?{error:y.required}:Ae(i.value,n.format)},setError(p){u.textContent=p??"",u.hidden=p===null,p===null?(i.removeAttribute("aria-invalid"),i.removeAttribute("aria-describedby")):(i.setAttribute("aria-invalid","true"),i.setAttribute("aria-describedby",u.id))}}}var ge=`
|
|
63
|
+
form{display:flex;flex-direction:column;gap:1rem}
|
|
64
|
+
.actions{display:flex;flex-wrap:wrap;gap:.5rem;margin-top:1rem}
|
|
65
|
+
.alert{margin:0 0 1rem;padding:.75rem 1rem;border:1px solid var(--cube-color-danger,#b42318);
|
|
66
|
+
border-radius:var(--cube-radius-small)}
|
|
67
|
+
.alert p{margin:0}
|
|
68
|
+
.alert ul{margin:.5rem 0 0;padding-inline-start:1.25rem}
|
|
69
|
+
.alert button{margin-top:.5rem}
|
|
70
|
+
.status{margin:.5rem 0 0}
|
|
71
|
+
.status:empty{margin:0}
|
|
72
|
+
`;function he(e,n){return e?.body===n?e:{key:en(),body:n}}function Ee(e,n,t,o){T(n),n.append(h(e,"p",{},t),...o==null?[]:[o]),n.hidden=!1,n.focus()}function it(e,n,t,o,a){let i=nr(t);if(i!==null){for(let u of o)u.setError(i[u.name]??null);let s=Object.entries(i).filter(([u])=>!o.some(c=>c.name===u)),l=s.length===0?null:h(e,"ul",{},...s.map(([u,c])=>h(e,"li",{},`${a(u)}: ${c}`)));Ee(e,n,y.formInvalid,l);return}let r=X(t).kind;Ee(e,n,r==="forbidden"?y.forbidden:r==="signed-out"?y.signedOut:y.saveFailed)}function re(e){let n=e?.user()??null;return n===null?null:String(n.id)}var Ci=`${M}${ge}
|
|
73
|
+
.board{display:grid;grid-auto-flow:column;grid-auto-columns:minmax(14rem,1fr);gap:1rem;
|
|
74
|
+
position:relative;overflow-x:auto}
|
|
75
|
+
@media (max-width:640px){.board{grid-auto-flow:row;grid-auto-columns:auto}}
|
|
76
|
+
section{min-width:0}
|
|
77
|
+
h3{margin:0 0 .5rem;font-size:1rem}
|
|
78
|
+
article{margin-top:.5rem;padding:.75rem;border:1px solid var(--cube-color-border);
|
|
79
|
+
border-radius:var(--cube-radius-small);background:var(--cube-color-bg);overflow-wrap:anywhere}
|
|
80
|
+
article[draggable=true]{cursor:grab}
|
|
81
|
+
.title{margin:0;font-weight:600}
|
|
82
|
+
dl{display:grid;grid-template-columns:auto 1fr;gap:0 .5rem;margin:.25rem 0 0;font-size:.875rem}
|
|
83
|
+
dd{margin:0;min-width:0}
|
|
84
|
+
.moves{display:flex;flex-wrap:wrap;gap:.25rem;margin-top:.5rem}
|
|
85
|
+
.moves button{min-height:2rem;padding:.25rem .5rem;font-size:.875rem}
|
|
86
|
+
.moves button::before{content:"\\2192 "}
|
|
87
|
+
.muted{margin:.5rem 0 0}
|
|
88
|
+
.not-saved{display:inline-block;margin-bottom:.75rem}
|
|
89
|
+
`,st=e=>String(e.id);function Ai(e){if(F(e)&&(e.status===409||e.status===412))return y.changedMeanwhile;let n=X(e).kind;return n==="forbidden"?y.forbidden:n==="signed-out"?y.signedOut:y.tryAgain}function rr(e,n){let t=n.document;class o extends e{constructor(){super();b(this,"alert",h(t,"div",{class:"alert",role:"alert",hidden:!0}));b(this,"loaded",null);b(this,"tracks",new Map);b(this,"pending",0);b(this,"stale",!1);b(this,"own",!1);b(this,"dragged",null);b(this,"focusKey",null);b(this,"attempt",null);b(this,"ids",0);this.shadowRoot?.insertBefore(this.alert,this.body)}shownFields(){let r=this.loaded;return r===null?[]:[r.status,r.title,...r.fields.map(s=>s.name)]}refresh(){if(this.own)return Promise.resolve();if(this.pending>0)return this.stale=!0,Promise.resolve();this.stale=!1;let r=this.shadowRoot?.activeElement?.closest("article")?.getAttribute("data-id");return r!=null&&(this.focusKey=r),super.refresh()}async load(r,s){if(s===null)return;this.loaded=null;let l=C(this,"resource"),u=C(this,"status-field"),c=C(this,"title-field"),p=le(this),f=Math.min(G(this,"page-size",1,50),200),m=this.attr("sort")?.trim()??"",d=await s.schema(l);if(r.aborted)return;let g=d?.fields.find(D=>D.name===u),w=W(this.attr("fields")),v=w===null?[]:Q(d,w,V(this)),k={fields:[...new Set(["id",c,u,...v.map(D=>D.name)])],page:{size:f}};m!==""&&(k.sort=m);let x=s.resource(l),P=await Promise.all(this.columnValues(g?.enum??null).map(async D=>{let{data:S,meta:E}=await x.list({...k,filter:{...p,[u]:D.value}},{signal:r});return{...D,rows:[...S],total:E.page?.total??S.length}}));if(r.aborted)return;let A={session:s,user:re(s),resource:l,status:u,title:c,fields:v,columns:P,canMove:d!==null&&d.actions.includes("update")&&g?.readonly===!1};this.loaded=A,this.tracks.clear(),this.render(A)}columnValues(r){let s=Array.from(this.children).filter(u=>u.localName==="cube-column"),l=s.length>0?s.map(u=>{let c=C(u,"value");return{value:c,label:u.getAttribute("label")?.trim()||U(c)}}):(r??[]).map(u=>({value:u,label:U(u)}));if(l.length===0)throw new q({kind:"error",detail:y.noColumns,retry:!1});return l}render(r){let s=new Map;T(this.body),this.body.append(...[r.canMove&&this.notSaved(r.session),h(t,"div",{class:"board"},...r.columns.map(u=>this.column(r,u,s)))].filter(u=>!!u));let l=this.focusKey;this.focusKey=null,l!==null&&s.get(l)?.focus()}column(r,s,l){let u=`b${++this.ids}`,c=s.total-s.rows.length;return h(t,"section",{class:"card","aria-labelledby":u,ondragover:p=>{r.canMove&&this.dragged!==null&&p.preventDefault()},ondrop:p=>{p.preventDefault();let f=this.dragged;this.dragged=null,f!==null&&this.move(r,f,s.value)}},h(t,"h3",{id:u},s.label," ",h(t,"span",{class:"badge"},`${s.total}`)),...s.rows.length===0?[h(t,"p",{class:"muted"},y.emptyColumn)]:s.rows.map(p=>this.card(r,s,p,l)),c>0?h(t,"p",{class:"muted"},y.more(c)):null)}card(r,s,l,u){let c=st(l),p=`b${++this.ids}`,f=h(t,"article",{tabindex:"0",draggable:r.canMove?"true":"false","data-id":c,"aria-labelledby":p,ondragstart:m=>{this.dragged=c,m.dataTransfer?.setData("text/plain",c)},ondragend:()=>{this.dragged=null}},h(t,"p",{class:"title",id:p},_(l[r.title],"text")),r.fields.length===0?null:h(t,"dl",{},...r.fields.flatMap(m=>[h(t,"dt",{},m.label),h(t,"dd",{},_(l[m.name],m.format))])),r.canMove?h(t,"div",{class:"moves"},...r.columns.filter(m=>m!==s).map(m=>h(t,"button",{type:"button",class:"secondary","aria-label":y.moveTo(m.label),"aria-describedby":p,onclick:()=>this.move(r,c,m.value)},m.label))):null);return u.set(c,f),f}place(r,s,l){let u=r.columns.find(c=>c.value===l);for(let c of r.columns){let p=c.rows.findIndex(m=>st(m)===s),f=c.rows[p];if(!(f===void 0||u===void 0))return c.rows.splice(p,1),c.total--,u.rows.unshift(f),u.total++,{row:f,from:c.value}}return null}move(r,s,l){let u=r.columns.find(w=>w.rows.some(v=>st(v)===s));if(!r.canMove||this.loaded!==r||u===void 0||u.value===l)return;let c=this.place(r,s,l);if(c===null)return;let{row:p,from:f}=c;this.alert.hidden=!0,this.focusKey=s,this.render(r);let m=this.tracks.get(s);m===void 0&&(m={confirmed:f,tail:Promise.resolve(),generation:0},this.tracks.set(s,m));let d=m,g=d.generation;this.pending++,d.tail=d.tail.then(()=>g===d.generation?this.send(r,d,p,f,l):void 0).finally(()=>{--this.pending===0&&this.stale&&this.refresh()})}async send(r,s,l,u,c){let p=st(l),f={[r.status]:c},m=he(this.attempt,JSON.stringify([r.resource,p,f]));this.attempt=m;try{let d=await this.session();if(re(d)!==r.user){s.generation++,this.stale=!0;return}await d.resource(r.resource).update(l.id,f,{idempotencyKey:m.key}),this.attempt===m&&(this.attempt=null),s.confirmed=c,this.emit("cube-move",{resource:r.resource,id:l.id,from:u,to:c}),this.own=!0,this.emit("cube-data-change",{resource:r.resource}),queueMicrotask(()=>{this.own=!1})}catch(d){if(F(d)&&this.attempt===m&&(this.attempt=null),s.generation++,F(d)&&(d.status===409||d.status===412)&&(this.stale=!0),this.loaded!==r)return;this.place(r,p,s.confirmed),this.focusKey=p,this.render(r),T(this.alert),this.alert.append(`${y.moveFailed} ${Ai(d)}`),this.alert.hidden=!1}}}return b(o,"tag","cube-board"),b(o,"css",Ci),o}var Ei=`${M}${ue}${me}
|
|
90
|
+
.inputs{display:grid;gap:1rem;grid-template-columns:repeat(auto-fit,minmax(12rem,1fr))}
|
|
91
|
+
.inputs:empty{display:none}
|
|
92
|
+
.results{display:flex;flex-wrap:wrap;gap:1rem 2rem;margin-top:1.25rem;padding-top:1rem;
|
|
93
|
+
border-top:1px solid var(--cube-color-border)}
|
|
94
|
+
.inputs:empty+.results{margin-top:0;padding-top:0;border-top:0}
|
|
95
|
+
.result{display:flex;flex-direction:column;min-width:0}
|
|
96
|
+
.result label{font-size:.875rem;font-weight:600;color:var(--cube-color-text-muted)}
|
|
97
|
+
.result output{font-size:1.25rem;font-weight:600;font-variant-numeric:tabular-nums;overflow-wrap:anywhere}
|
|
98
|
+
.result.emphasis output{font-size:2rem;font-weight:700;line-height:1.2}
|
|
99
|
+
.alert{margin:1rem 0 0;color:var(--cube-color-danger,#b42318)}
|
|
100
|
+
`,Mi=["number","integer","currency","percent","text","select","checkbox"],Di=["number","integer","currency","percent","text"],or=0;function ir(e,n,t){let o=e.getAttribute(n)?.trim()??"",a=o===""?t[0]:o;if(!t.includes(a))throw new TypeError(y.invalid.value(e.localName,n,a));return a}function It(e,n){let t=e.getAttribute(n)?.trim()??"";if(t==="")return null;let o=Number(t);if(!Number.isFinite(o)||n==="step"&&o<=0)throw new TypeError(y.invalid.number(e.localName,n));return o}var Me=e=>_(e,"number");function sr(e){let n=e.editor.read();if("error"in n||typeof n.value!="number")return n;let t=e.format==="percent"?Number((n.value*100).toPrecision(12)):n.value,{min:o,max:a,step:i}=e;if(o!==null&&t<o||a!==null&&t>a)return{error:o===null?y.atMost(Me(a)):a===null?y.atLeast(Me(o)):y.range(Me(o),Me(a))};if(i!==null){let r=(t-(o??0))/i;if(Math.abs(r-Math.round(r))>1e-9)return{error:y.step(Me(i))}}return n}function ar(e,n){let t=n.document;class o extends e{constructor(){super();b(this,"fn",null);b(this,"drawn",null);b(this,"shownValues",{});b(this,"shownResults",{});let l=Object.getOwnPropertyDescriptor(this,"formula");l!==void 0&&(delete this.formula,this.fn=l.value)}get formula(){return typeof this.fn=="function"?this.fn:null}set formula(l){this.fn=l,this.drawn!==null&&(l===null||typeof l=="function")?this.calculate(!0):(this.drawn=null,this.refresh())}get values(){return{...this.shownValues}}get results(){return{...this.shownResults}}refresh(){return this.drawn!==null&&this.drawn.label===this.attr("label")?Promise.resolve():(this.drawn=null,super.refresh())}async load(){if(this.drawn=null,this.fn!==null&&typeof this.fn!="function")throw new q({kind:"error",detail:y.invalid.formula,retry:!1});let l=Array.from(this.children),u=l.filter(g=>g.localName==="cube-input").map(a),c=l.filter(g=>g.localName==="cube-result").map(i);if(c.length===0)throw new TypeError(y.invalid.missing(this.localName,"cube-result"));let p=this.attr("label"),f=p===null||p.trim()===""?null:h(t,"p",{class:"label",id:`cube-calc-${++or}`},p),m=h(t,"p",{class:"alert",role:"alert",hidden:!0}),d=h(t,"form",{novalidate:!0,"aria-labelledby":f?.id??null},h(t,"div",{class:"inputs"},...u.map(g=>g.editor.element)),h(t,"div",{class:"results","aria-live":"polite"},...c.map(g=>g.element)),m);d.addEventListener("submit",g=>g.preventDefault()),d.addEventListener("input",()=>this.calculate(!0)),d.addEventListener("change",()=>this.showErrors()),T(this.body),this.body.appendChild(h(t,"div",{class:"card"},f,d)),this.drawn={label:p,inputs:u,results:c,alert:m},this.showErrors(),this.calculate(!1)}showErrors(){for(let l of this.drawn?.inputs??[]){let u=sr(l);l.shown="error"in u,l.editor.setError("error"in u?u.error:null)}}calculate(l){let u=this.drawn;if(u===null)return;let c={};for(let m of u.inputs){let d=sr(m);c[m.editor.name]="error"in d?null:d.value,m.shown&&(m.shown="error"in d,m.editor.setError("error"in d?d.error:null))}let p={},f=!1;try{let m=this.formula,d=m===null?null:m({...c}),g=d===null||typeof d!="object";if(g&&d!==null&&d!==void 0&&u.results.length>1){this.drawn=null,this.showState({kind:"error",detail:y.invalid.calcSingle,retry:!1});return}for(let w of u.results){let v=g?d:d[w.name],k=typeof v=="number"&&!Number.isFinite(v);f||(f=k),p[w.name]=k||v===void 0?null:v}}catch{f=!0;for(let m of u.results)p[m.name]=null}for(let m of u.results)m.output.textContent=_(p[m.name],m.format,{currency:m.currency});f&&u.alert.hidden&&(u.alert.textContent=y.calcFailed),f||(u.alert.textContent=""),u.alert.hidden=!f,this.shownValues=c,this.shownResults=p,l&&this.emit("cube-change",{values:{...c},results:{...p}})}}b(o,"tag","cube-calc"),b(o,"css",Ei),b(o,"needsSession",!1);function a(r){let s=C(r,"name"),l=C(r,"label"),u=ir(r,"type",Mi),c=u==="select"?"text":u==="checkbox"?"boolean":u,p=u==="checkbox"?null:jt(r.getAttribute("options"));if(u==="select"&&p===null)throw new TypeError(y.invalid.missing(r.localName,"options"));let f=r.getAttribute("value"),m=f===null?{value:null}:Ae(f,c);return{editor:fe(t,{name:s,label:l,format:c,field:void 0,config:{name:s,label:l,format:c,multiline:!1,options:p,hidden:!1}},"error"in m?f:m.value,!1),format:c,min:It(r,"min"),max:It(r,"max"),step:It(r,"step"),shown:!1}}function i(r){let s=C(r,"name"),l=C(r,"label"),u=ir(r,"format",Di),c=r.getAttribute("currency")?.trim().toUpperCase()||"EUR";try{_(0,"currency",{currency:c})}catch{throw new TypeError(y.invalid.value(r.localName,"currency",c))}let p=`cube-result-${++or}`,f=h(t,"output",{id:p,name:s}),m=r.hasAttribute("emphasis")&&r.getAttribute("emphasis")!=="false",d=h(t,"div",{class:m?"result emphasis":"result"},h(t,"label",{for:p},l),f);return{name:s,format:u,currency:c,element:d,output:f}}return o}var De=56,Bt=8,lr=8,Li=24,Ut=7,ur=8;function Fi(e,n,t=4){let o=Math.min(e,0),a=Math.max(n,0);if(a<=o)return[0,1];let i=(a-o)/t,r=10**Math.floor(Math.log10(i)),s=i/r,l=(s<=1?1:s<=2?2:s<=5?5:10)*r,u=[];for(let c=Math.floor(o/l);c<=Math.ceil(a/l);c++)u.push(Number((c*l).toPrecision(12)));return u}function _i(e,n,t,o){let a=Math.max(1,Math.floor(t/Ut)),i=n.length<=a?n:`${n.slice(0,a-1)}\u2026`,r=i.length*Ut/2,s=Math.min(Math.max(o.x,o.left+r),o.right-r),l=N(e,"text",{class:"x",x:s,y:o.y},i);return i!==n&&l.append(N(e,"title",{},n)),l}function cr(e,n,t,o){let{width:a,height:i}=t,r=n.points.map(S=>S.value??0),s=Fi(Math.min(...r),Math.max(...r)),l=s[0]??0,u=(s.at(-1)??1)-l||1,c=i-lr-Li,p=Math.max(a-De-Bt,1),f=n.points.length,m=p/Math.max(f,1),d=S=>lr+c*(1-(S-l)/u),g=S=>De+m*(S+.5),w=N(e,"svg",{viewBox:`0 0 ${a} ${i}`,width:"100%",height:i,role:"img","aria-label":`${n.label}, ${y.points(f)}`});for(let S of s)w.append(N(e,"line",{class:"grid",x1:De,x2:a-Bt,y1:d(S),y2:d(S)}),N(e,"text",{class:"tick",x:De-6,y:d(S)+4},o(S,!0)));let v=n.points.map(S=>S.tick??S.label),k=Math.max(1,...v.map(S=>S.length)),x=n.categories===!0?1:Math.ceil(f/Math.max(1,Math.floor(p/(k*Ut+ur)))),P=n.points.map((S,E)=>E).filter(S=>S%x===0),A=m*x-ur/2;for(let S of P){let E={x:g(S),y:i-6,left:De,right:a-Bt};w.append(_i(e,v[S]??"",A,E))}return{root:w,band:m,x:g,y:d,title:S=>N(e,"title",{},`${S.label}: ${S.value===null?y.emptyValue:o(S.value)}`)}}function dr(e,n,t,o){let{root:a,x:i,y:r,title:s}=cr(e,n,t,o),l="",u="M";return n.points.forEach((c,p)=>{if(c.value===null){u="M";return}l+=`${u}${i(p).toFixed(1)} ${r(c.value).toFixed(1)}`,u="L"}),a.append(N(e,"path",{class:"s1",d:l})),n.points.forEach((c,p)=>{c.value!==null&&a.append(N(e,"circle",{class:"s1",cx:i(p),cy:r(c.value),r:3},s(c)))}),a}function pr(e,n,t,o){let{root:a,band:i,x:r,y:s,title:l}=cr(e,n,t,o),u=i*.7;return n.points.forEach((c,p)=>{let f=s(Math.max(c.value??0,0)),m=s(Math.min(c.value??0,0));a.append(N(e,"rect",{class:"s1",x:r(p)-u/2,y:f,width:u,height:m-f},l(c)))}),a}var Ht=864e5,$i=600,Oi=["line","bar"],Pi=`${M}${ue}
|
|
101
|
+
svg{display:block;overflow:visible}
|
|
102
|
+
.grid{stroke:var(--cube-color-border)}
|
|
103
|
+
.tick,.x{font-size:12px;fill:var(--cube-color-text-muted)}
|
|
104
|
+
.tick{text-anchor:end}
|
|
105
|
+
.x{text-anchor:middle}
|
|
106
|
+
rect.s1,circle.s1{fill:var(--cube-color-series-1)}
|
|
107
|
+
path.s1{fill:none;stroke:var(--cube-color-series-1);stroke-width:2}
|
|
108
|
+
`;function Ni(e,n){let t=e.toISOString().slice(0,10);switch(n){case"day":return t;case"week":{let o=new Date(e.getTime()+(3-(e.getUTCDay()+6)%7)*Ht),a=o.getUTCFullYear(),i=1+Math.floor((o.getTime()-Date.UTC(a,0,1))/(7*Ht));return`${a}-W${String(i).padStart(2,"0")}`}case"month":return t.slice(0,7);case"quarter":return`${t.slice(0,4)}-Q${Math.ceil((e.getUTCMonth()+1)/3)}`;case"year":return t.slice(0,4)}}function ji(e,n){let t=Mt(e,"month",{short:!0});return n||e.endsWith("-01")?y.monthYear(t,e.slice(0,4)):t}function mr(e,n,t){let o=new Set,a=Date.parse(`${n}T00:00:00Z`);for(let i=Date.parse(`${e}T00:00:00Z`);i<=a;i+=Ht)o.add(Ni(new Date(i),t));return[...o]}function fr(e,n){class t extends e{constructor(){super(...arguments);b(this,"period",new z(this));b(this,"plot",h(n.document,"div",{class:"plot"}));b(this,"observer",null);b(this,"observed",0);b(this,"drawn",0);b(this,"drawing",null)}shownFields(){return ce(this)}connectedCallback(){super.connectedCallback(),!(this.observer!==null||n.ResizeObserver===void 0)&&(this.observer=new n.ResizeObserver(i=>{let r=Math.round(i.at(-1)?.contentRect.width??0);r<=0||(this.observed=r,r!==this.drawn&&this.draw())}),this.observer.observe(this.plot))}disconnectedCallback(){super.disconnectedCallback(),this.observer?.disconnect(),this.observer=null}async load(i,r){if(r===null)return;let s=C(this,"resource"),l=C(this,"by"),{field:u,truncation:c}=qe(l),p=G(this,"height",80,240),f=G(this,"limit",1,12),m=await de(this,this.period,i,l);if(m===null)return;let{fn:d,period:g}=m,{data:w}=await nt(r,s,l,m,i);if(i.aborted)return;let v=w.filter(A=>A[l]!==null&&A[l]!==void 0);if(v.length===0){this.showState("empty");return}let k;if(c!==null){let A=new Map(v.map(j=>[String(j[l]),Te(j[d])])),D=g===null?[...A.keys()].sort():mr(g.from,g.to,c),S=g?.today??g?.to??"",E=g===null||S<g.from?new Set:new Set(mr(g.from,S<g.to?S:g.to,c));k=D.map((j,I)=>({key:j,label:Mt(j,c),...c==="month"?{tick:ji(j,I===0)}:{},value:g===null||!E.has(j)?A.get(j)??null:A.get(j)??0}))}else{let A=await rt(this,r,v,{by:l,fn:d},{descending:!0,limit:f},i);if(A===null)return;if(A.length===0){this.showState("empty");return}k=A}let x=this.attr("label")??U(m.field??d),P=this.attr("kind");this.render({label:x,points:k,categories:c===null},p,{line:Oi.includes(P??"")?P==="line":c!==null,format:pe(this,m.count),byLabel:U(u)})}render(i,r,s){let l=n.document;this.drawing={series:i,height:r,line:s.line,format:s.format};let u=c=>c===null?y.emptyValue:s.format(c);T(this.body),this.body.appendChild(h(l,"div",{class:"card"},this.attr("label")===null?"":h(l,"p",{class:"label","aria-hidden":"true"},i.label),this.plot,h(l,"div",{class:"sr-only"},h(l,"table",{},h(l,"caption",{},y.asTable),h(l,"thead",{},h(l,"tr",{},h(l,"th",{scope:"col"},s.byLabel),h(l,"th",{scope:"col"},i.label))),h(l,"tbody",{},...i.points.map(c=>h(l,"tr",{},h(l,"th",{scope:"row"},c.label),h(l,"td",{},u(c.value))))))))),this.draw()}draw(){if(this.drawing===null)return;let{series:i,height:r,line:s,format:l}=this.drawing,u=this.observed||Math.round(this.plot.clientWidth)||$i;this.drawn=u,T(this.plot),this.plot.appendChild((s?dr:pr)(n.document,i,{width:u,height:r},l))}}return b(t,"tag","cube-chart"),b(t,"css",Pi),t}var Ii=`${M}${me}${ge}
|
|
109
|
+
dl{display:grid;grid-template-columns:minmax(8rem,max-content) 1fr;gap:.5rem 1rem;margin:0}
|
|
110
|
+
dt{font-weight:600}
|
|
111
|
+
dd{margin:0;min-width:0;overflow-wrap:anywhere}
|
|
112
|
+
`,gr=e=>e.field!==void 0&&!e.field.readonly;function Bi(e,n,t){let o=n===void 0||n===""?null:n;if(o===t||o===null&&t===!1&&e.format==="boolean")return!0;if(o===null||t===null)return!1;if(e.format==="date"&&typeof o=="string"&&typeof t=="string")return o.slice(0,10)===t;if(typeof t=="number"&&typeof o=="string")return Number(o)===t;if(typeof t=="string"&&typeof o=="number")return String(o)===t;if(e.format==="datetime"&&typeof o=="string"&&typeof t=="string"){let a=i=>Math.floor(Date.parse(i)/6e4);return a(o)===a(t)}return typeof o=="object"&&JSON.stringify(o)===JSON.stringify(t)}function hr(e,n){let t=n.document;class o extends e{constructor(){super();b(this,"status",h(t,"p",{class:"status",role:"status"}));b(this,"loaded",null);b(this,"editing",null);b(this,"attempt",null);b(this,"saved",null);b(this,"edit",null);this.shadowRoot?.appendChild(this.status)}disconnectedCallback(){super.disconnectedCallback(),this.editing=null}refresh(){let r=this.editing;return r!==null&&r.resource===this.attr("resource")?.trim()&&r.id===this.recordId()&&r.user===re(this.loaded?.session)?Promise.resolve():(this.editing=null,super.refresh())}shownFields(){return this.loaded?.columns.map(r=>r.name)??[]}recordId(){let r=this.attr("record-id")?.trim()??"";return r===""?null:r}async load(r,s){if(s===null)return;this.loaded=null;let l=C(this,"resource"),u=this.recordId(),c=this.saved!==null&&this.saved.resource===l&&this.saved.id===u;if(this.saved=null,c||(this.status.textContent=""),u===null){this.showState("empty",y.chooseRow);return}let p=await s.schema(l);if(r.aborted)return;let f=W(this.attr("fields")),m=await s.resource(l).get(u,f===null?{}:{fields:f},{signal:r});if(r.aborted)return;let d=m.data,g={session:s,resource:l,id:u,columns:Q(p,f,V(this),d),row:d,version:m.recordVersion,canEdit:this.flag("editable")&&this.allowsUpdate(p)};this.loaded=g,this.renderView(g),c&&this.edit?.focus()}allowsUpdate(r){return r!==null&&r.actions.includes("update")}renderView(r){this.edit=r.canEdit&&r.columns.some(gr)?h(t,"button",{type:"button",onclick:()=>this.startEditing(r)},y.edit):null,T(this.body),this.body.appendChild(h(t,"div",{class:"card"},h(t,"dl",{},...r.columns.flatMap(s=>this.pair(r,s))),this.edit===null?null:h(t,"div",{class:"actions"},this.edit,this.notSaved(r.session))))}pair(r,s){let l=this.exampleField(r.session,r.resource,s.name);return[h(t,"dt",{},s.label,...l?[" ",Xe(t)]:[]),h(t,"dd",{class:l?"example":null},_(r.row[s.name],s.format))]}startEditing(r){this.editing={resource:r.resource,id:r.id,user:re(r.session)},this.status.textContent="";let s=[],l=r.columns.map(m=>{if(!gr(m))return h(t,"dl",{},...this.pair(r,m));let d=fe(t,m,r.row[m.name],m.field?.nullable===!1);return s.push(d),d.element}),u=h(t,"div",{class:"alert",role:"alert",tabindex:"-1",hidden:!0}),c=h(t,"button",{type:"submit"},y.save),p=h(t,"button",{type:"button",class:"secondary",onclick:()=>{this.editing=null,this.attempt=null,this.renderView(r),this.edit?.focus()}},y.cancel),f=h(t,"form",{novalidate:!0},u,...l,h(t,"div",{class:"actions"},c,p,this.notSaved(r.session)));f.addEventListener("submit",m=>{m.preventDefault(),this.save(r,s,{alert:u,save:c,cancel:p})}),T(this.body),this.body.appendChild(h(t,"div",{class:"card"},f)),s[0]?.element.querySelector("input,select,textarea")?.focus()}async save(r,s,l){if(l.save.disabled)return;let u={},c=!1;for(let m of s){let d=m.read(),g=r.columns.find(w=>w.name===m.name);if("error"in d){m.setError(d.error),c=!0;continue}m.setError(null),Bi(g,r.row[m.name],d.value)||(u[m.name]=d.value)}if(c){Ee(t,l.alert,y.formInvalid);return}if(Object.keys(u).length===0){this.editing=null,this.renderView(r),this.edit?.focus();return}let p=JSON.stringify([r.resource,r.id,u]);this.attempt=he(this.attempt,p);let f={idempotencyKey:this.attempt.key};r.version!==null&&(f.ifMatch=r.version),l.save.disabled=!0,l.cancel.disabled=!0,l.alert.hidden=!0;try{let m=await this.session();if(this.editing!==null&&this.editing.user!==re(m)){this.editing=null,this.refresh();return}let d=await m.resource(r.resource).update(r.id,u,f);this.attempt=null;let g=d.data;if(this.loaded===r&&this.editing!==null){this.editing=null;let w={...r.row,...u,...g},v={...r,row:w,version:d.recordVersion};this.loaded=v,this.saved={resource:r.resource,id:r.id},this.renderView(v),this.status.textContent=y.saved,this.edit?.focus()}this.emit("cube-saved",{resource:r.resource,id:g.id??r.id,row:g}),this.emit("cube-data-change",{resource:r.resource})}catch(m){if(this.loaded!==r||this.editing===null)return;l.cancel.disabled=!1,this.failed(m,s,l)}}failed(r,s,l){if(F(r)&&(this.attempt=null),F(r)&&(r.status===409||r.status===412)){let u=h(t,"button",{type:"button",class:"secondary",onclick:()=>{this.editing=null,this.refresh()}},y.reload);Ee(t,l.alert,y.conflict,u);return}l.save.disabled=!1,it(t,l.alert,r,s,u=>Ce(V(this),u))}}return b(o,"tag","cube-detail"),b(o,"css",Ii),o}var Ui=`${M}${me}${ge}`,Hi=["resource","fields","submit-label","success-text"];function yr(e,n){let t=n.document;class o extends e{constructor(){super();b(this,"status",h(t,"p",{class:"status",role:"status"}));b(this,"drawn",null);b(this,"shown",null);b(this,"attempt",null);this.shadowRoot?.appendChild(this.status)}shownFields(){return this.drawn?.columns.map(r=>r.name)??[]}key(){let r=this.drawn?.session.user()?.id??null;return JSON.stringify([...Hi.map(s=>this.attr(s)),r])}text(r,s){let l=this.attr(r)?.trim()??"";return l===""?s:l}refresh(){return this.shown===this.key()?Promise.resolve():(this.shown=null,super.refresh())}async load(r,s){if(s===null)return;this.drawn=null,this.attempt=null;let l=C(this,"resource"),u=await s.schema(l);if(r.aborted)return;if(u===null||!u.actions.includes("create")){this.showState({kind:"forbidden",detail:null,retry:!1});return}let c=u.fields.filter(d=>!d.readonly&&d.name!=="id"),f=(W(this.attr("fields"))??c.map(d=>d.name)).filter(d=>c.some(g=>g.name===d)),m=Q(u,f,V(this));if(m.length===0){this.showState({kind:"error",detail:y.noWritableFields,retry:!1});return}this.drawn={session:s,resource:l,columns:m},this.shown=this.key(),this.renderForm(!1)}renderForm(r){let s=this.drawn;this.status.textContent="";let l=s.columns.map(f=>fe(t,f,null,f.field?.nullable===!1&&f.format!=="boolean")),u=h(t,"div",{class:"alert",role:"alert",tabindex:"-1",hidden:!0}),c=h(t,"button",{type:"submit"},this.text("submit-label",y.save)),p=h(t,"form",{novalidate:!0},u,...l.map(f=>f.element),h(t,"div",{class:"actions"},c,this.notSaved(s.session)));p.addEventListener("submit",f=>{f.preventDefault(),this.submit(s,l,u,c)}),T(this.body),this.body.appendChild(h(t,"div",{class:"card"},p)),r&&br(l[0])?.focus()}async submit(r,s,l,u){if(u.disabled)return;let c={},p=null;for(let m of s){let d=m.read();m.setError("error"in d?d.error:null),"error"in d?p??(p=m):d.value!==null&&(c[m.name]=d.value)}if(p!==null){l.hidden=!0,br(p)?.focus();return}this.attempt=he(this.attempt,JSON.stringify([r.resource,c]));let f=this.attempt.key;u.disabled=!0,l.hidden=!0;try{let d=await(await this.session()).resource(r.resource).create(c,{idempotencyKey:f});this.attempt=null;let g=d.data;this.drawn===r&&this.done(),this.emit("cube-created",{resource:r.resource,row:g}),this.emit("cube-data-change",{resource:r.resource})}catch(m){if(F(m)&&(this.attempt=null),this.drawn!==r)return;u.disabled=!1,it(t,l,m,s,d=>Ce(V(this),d))}}done(){let r=h(t,"button",{type:"button",onclick:()=>this.renderForm(!0)},y.another);T(this.body);let s=this.drawn===null?null:this.notSaved(this.drawn.session);this.body.appendChild(h(t,"div",{class:"card"},h(t,"div",{class:"actions"},r,s))),this.status.textContent=this.text("success-text",y.formSaved),n.setTimeout(()=>{r.isConnected&&r.focus()},0)}}return b(o,"tag","cube-form"),b(o,"css",Ui),o}function br(e){return e?.element.querySelector("input,select,textarea")??null}var zi=`${M}
|
|
113
|
+
ul{list-style:none;margin:0;padding:0;display:grid;gap:.75rem}
|
|
114
|
+
h3{margin:0 0 .5rem;font-size:1rem;overflow-wrap:anywhere}
|
|
115
|
+
dl{margin:0;display:grid;gap:.375rem}
|
|
116
|
+
dl div{display:flex;flex-wrap:wrap;gap:0 .75rem}
|
|
117
|
+
dt{flex:0 0 8rem;font-weight:600}
|
|
118
|
+
dd{flex:1 1 12rem;margin:0;min-width:0;overflow-wrap:break-word}
|
|
119
|
+
p{margin:0}
|
|
120
|
+
`;function wr(e,n){let t=n.document;class o extends e{async load(i,r){if(r===null||i.aborted)return;let s=this.attr("scherm")?.trim()??"",l=(r.gaps??[]).filter(c=>s===""||c.scherm===s),u=(c,p)=>h(t,"div",{},h(t,"dt",{},c),h(t,"dd",{},p));T(this.body),this.body.appendChild(l.length===0?h(t,"div",{class:"card"},h(t,"p",{},y.gaps.none)):h(t,"ul",{role:"list","aria-label":y.gaps.what},...l.map(c=>h(t,"li",{class:"card"},h(t,"h3",{},c.veld===void 0?c.resource:`${c.resource}.${c.veld}`),h(t,"dl",{},u(y.gaps.screen,c.scherm),u(y.gaps.type,c.type==="keuze"?`${y.gaps.types.keuze}: ${(c.waarden??[]).join(", ")}`:y.gaps.types[c.type]),u(y.gaps.why,c.reden))))))}}return b(o,"tag","cube-gap-list"),b(o,"css",zi),o}var vr=new Intl.NumberFormat("nl-NL",{minimumFractionDigits:1,maximumFractionDigits:1}),Vi=`${M}
|
|
121
|
+
.kpi{display:flex;flex-direction:column;gap:.25rem}
|
|
122
|
+
.label{margin:0;font-size:.875rem;font-weight:600;color:var(--cube-color-text-muted)}
|
|
123
|
+
.value{margin:0;font-size:2rem;font-weight:700;line-height:1.2;overflow-wrap:anywhere}
|
|
124
|
+
.compare{margin:0;font-size:.875rem;color:var(--cube-color-text-muted)}
|
|
125
|
+
.compare.up{color:var(--cube-color-success)}
|
|
126
|
+
.compare.down{color:var(--cube-color-danger)}
|
|
127
|
+
`;function kr(e,n){class t extends e{constructor(){super(...arguments);b(this,"period",new z(this))}shownFields(){return ce(this)}async load(i,r){if(r===null)return;let s=C(this,"resource");if(this.flag("compare")&&!this.attr("period"))throw new TypeError(y.invalid.compare(this.localName));let l=await de(this,this.period,i);if(l===null)return;let{fn:u,period:c}=l,p=r.resource(s),f=async w=>{let{data:v}=await p.aggregate({fn:u,filter:l.filterFor(w)},{signal:i});return Te(v[0]?.[u])},m=this.flag("compare")?c?.previous??null:null,[d,g]=await Promise.all([f(c),m===null?null:f(m)]);i.aborted||this.render(d,m===null?void 0:g,l.count)}render(i,r,s){let l=n.document,u=pe(this,s),c=this.attr("label"),p=i===null?h(l,"p",{class:"value"},h(l,"span",{"aria-hidden":"true"},y.emptyValue),h(l,"span",{class:"sr-only"},y.noData)):h(l,"p",{class:"value"},h(l,"data",{value:String(i)},u(i)));T(this.body),this.body.appendChild(h(l,"div",{class:"card kpi"},c===null||c===""?null:h(l,"p",{class:"label"},c),p,r===void 0||i===null?null:this.compareLine(i,r)))}compareLine(i,r){let s=n.document;if(r===null||r===0)return h(s,"p",{class:"compare new"},y.newValue);let l=(i-r)/Math.abs(r),u=vr.format(Math.abs(l)*100);if(u===vr.format(0))return h(s,"p",{class:"compare same"},`${u}% ${y.comparedTo}`);let c=l>0;return h(s,"p",{class:c?"compare up":"compare down",role:"img","aria-label":y.change(u,c?y.higher:y.lower)},`${c?"\u25B2":"\u25BC"} ${u}% ${y.comparedTo}`)}}return b(t,"tag","cube-kpi"),b(t,"css",Vi),t}var Ki=864e5;function Z(e,n,t){let o=new Date(2e3,0,1);return o.setFullYear(e,n,t),o}function lt(e,n){return{from:O(e),to:O(n)}}function at(e,n,t){let o=e.getFullYear(),a=e.getMonth()+n;return lt(Z(o,a,1),Z(o,a+t,0))}function qi(e,n){return Math.round((Date.UTC(n.getFullYear(),n.getMonth(),n.getDate())-Date.UTC(e.getFullYear(),e.getMonth(),e.getDate()))/Ki)+1}function zt(e,n,t){switch(e){case"this-month":return{key:e,...at(n,0,1),previous:at(n,-1,1)};case"12m":return{key:e,...at(n,-11,12),previous:at(n,-23,12)};case"this-year":{let o=n.getFullYear();return{key:e,...lt(Z(o,0,1),Z(o,11,31)),previous:lt(Z(o-1,0,1),Z(o-1,11,31))}}case"custom":{let o=t===void 0?null:$(t.from),a=t===void 0?null:$(t.to);if(t===void 0||o===null||a===null||a<o)throw new TypeError("A custom period needs a valid from and to, from not after to.");let i=qi(o,a);return{key:e,from:t.from,to:t.to,previous:lt(Z(o.getFullYear(),o.getMonth(),o.getDate()-i),Z(o.getFullYear(),o.getMonth(),o.getDate()-1))}}}}var Vt=["this-month","12m","this-year","custom"],Sr="12m",Gi=`
|
|
128
|
+
.picker{display:flex;flex-wrap:wrap;align-items:flex-end;gap:.75rem}
|
|
129
|
+
.field{display:flex;flex-direction:column;gap:.25rem;min-width:0}
|
|
130
|
+
label{font-weight:600;font-size:.875rem}
|
|
131
|
+
.custom{display:flex;flex-wrap:wrap;gap:.75rem}
|
|
132
|
+
.custom[hidden]{display:none}
|
|
133
|
+
.custom .error{flex-basis:100%;margin:0;font-weight:600;color:var(--cube-color-danger)}
|
|
134
|
+
.custom .error:empty{flex-basis:0}
|
|
135
|
+
input[aria-invalid=true]{border:2px solid var(--cube-color-danger)}
|
|
136
|
+
@media (max-width:640px){.picker,.custom{flex-direction:column;align-items:stretch}}
|
|
137
|
+
`;function xr(e,n,t,o){return h(e,"div",{class:"field"},h(e,"label",{for:n},t),o)}function Tr(e,n){class t extends e{constructor(){super();b(this,"select");b(this,"label");b(this,"custom");b(this,"from");b(this,"to");b(this,"error");b(this,"chosen",null);b(this,"range",null);b(this,"announced",null);let i=n.document;this.select=h(i,"select",{id:"period",onchange:()=>this.onSelect()},...Vt.map(l=>h(i,"option",{value:l},y.period[l]))),this.label=h(i,"label",{for:"period"});let r=l=>h(i,"input",{type:"date",id:l,onchange:()=>this.onDates()});this.from=r("from"),this.to=r("to"),this.error=h(i,"p",{id:"range-error",class:"error","aria-live":"polite"}),this.custom=h(i,"div",{class:"custom",hidden:!0},xr(i,"from",y.period.from,this.from),xr(i,"to",y.period.to,this.to),this.error);let s=h(i,"div",{class:"field"},this.label,this.select);this.body.appendChild(h(i,"div",{class:"picker"},s,this.custom))}get value(){let i=this.key(),r=this.today();return{...i==="custom"&&this.range!==null?zt("custom",r,this.range):zt(i==="custom"?Sr:i,r),today:O(r)}}refresh(){return this.render(),this.changed(),Promise.resolve()}async load(){this.render()}showState(){this.render()}key(){if(this.chosen!==null)return this.chosen;let i=this.attr("default");return Vt.includes(i)?i:Sr}today(){let i=this.attr("today");return(i===null?null:$(i))??new Date}render(){let i=this.key();this.label.textContent=this.attr("label")??y.period.label,this.select.value=i,this.custom.hidden=i!=="custom",i==="custom"&&this.range===null&&this.fillDates()}fillDates(){let{from:i,to:r}=this.value;this.range={from:i,to:r},this.from.value=i,this.to.value=r,this.explain(null)}onSelect(){let i=this.select.value;Vt.includes(i)&&(i==="custom"&&this.key()!=="custom"&&(this.range=null,this.fillDates()),this.chosen=i,this.render(),this.changed())}onDates(){let i={from:this.from.value,to:this.to.value},r=$(i.from),s=$(i.to);if(r===null||s===null){this.explain(y.period.incompleteDate);return}if(s<r){this.explain(y.period.invalidRange);return}this.explain(null),this.range=i,this.changed()}changed(){let i=this.value,r=JSON.stringify(i),s=this.announced;this.announced=r,s!==null&&s!==r&&this.emit("cube-change",i)}explain(i){this.error.textContent=i??"";for(let r of[this.from,this.to])i===null?(r.removeAttribute("aria-invalid"),r.removeAttribute("aria-describedby")):(r.setAttribute("aria-invalid","true"),r.setAttribute("aria-describedby",this.error.id))}}return b(t,"tag","cube-period-picker"),b(t,"css",Gi),b(t,"needsSession",!1),t}var Wi=["loading","empty","error","forbidden","signed-out"],Qi={loading:y.loading,empty:y.empty,error:y.error,forbidden:y.forbidden,"signed-out":y.signedOut},Ji=`
|
|
138
|
+
.state{display:flex;flex-wrap:wrap;align-items:center;gap:.75rem;padding:1rem;border:1px solid var(--cube-color-border);
|
|
139
|
+
border-radius:var(--cube-radius);background:var(--cube-color-surface)}
|
|
140
|
+
.state[data-kind=error]{border-left:4px solid var(--cube-color-danger)}
|
|
141
|
+
.state[data-kind=forbidden],.state[data-kind=signed-out]{border-left:4px solid var(--cube-color-warning)}
|
|
142
|
+
.state p{margin:0;flex:1 1 12rem}
|
|
143
|
+
.state[data-kind=loading] p,.state[data-kind=empty] p{color:var(--cube-color-text-muted)}
|
|
144
|
+
`,Rr=["error","forbidden","signed-out"],ut=new WeakMap;function Cr(e,n){class t extends e{constructor(){super();b(this,"failed",!1);b(this,"kind","loading");b(this,"region");b(this,"message");b(this,"action",null);b(this,"announce",null);this.message=h(n.document,"p"),this.region=h(n.document,"div",{class:"state"},this.message)}disconnectedCallback(){super.disconnectedCallback(),ut.get(this.ownerDocument)===this&&ut.delete(this.ownerDocument),this.announce!==null&&n.clearTimeout(this.announce),this.announce=null}refresh(){return this.failed=!1,this.render(),Promise.resolve()}async load(){this.render()}showState(){this.render()}render(){let i=this.attr("kind"),r=this.failed?"error":Wi.includes(i)?i:"loading",s=this.ownerDocument;this.kind=r;let l=Rr.includes(r)&&this.claimAlert();this.action?.remove(),this.action=null,r==="signed-out"?this.action=h(s,"button",{type:"button",onclick:()=>{this.signIn()}},y.signIn):r==="error"&&(this.failed||this.attr("retry")!=="false")&&(this.action=h(s,"button",{type:"button",class:"secondary",onclick:()=>{this.emit("cube-retry")}},y.retry)),this.region.setAttribute("data-kind",r),r==="loading"?this.region.removeAttribute("role"):this.region.setAttribute("role",l?"alert":"status"),l?this.region.removeAttribute("aria-live"):this.region.setAttribute("aria-live",r==="loading"?"off":"polite"),this.action!==null&&this.region.appendChild(this.action),this.region.parentNode!==this.body&&(T(this.body),this.body.appendChild(this.region));let u=this.failed?y.error:this.attr("message")??Qi[r];if(this.announce!==null&&n.clearTimeout(this.announce),this.announce=null,this.message.textContent!==u){if(r==="loading"){this.message.textContent=u;return}this.message.textContent="",this.announce=n.setTimeout(()=>{this.announce=null,this.message.textContent=u},0)}}claimAlert(){let i=this.ownerDocument,r=ut.get(i);return r!==void 0&&r!==this&&r.isConnected&&Rr.includes(r.kind)?!1:(ut.set(i,this),!0)}async signIn(){try{await(await this.session()).signIn()}catch{this.failed=!0,this.render();return}let i=this.ownerDocument.defaultView?.CustomEvent??CustomEvent;this.ownerDocument.dispatchEvent(new i("cube-session-change"))}}return b(t,"tag","cube-state"),b(t,"css",Ji),b(t,"needsSession",!1),t}var Yi=/^[=+\-@\t\r]/,Xi=/[;"\r\n]/;function Ar(e,n){if(e==null)return"";let t=Y.includes(n)?Se(e):null,o;return t!==null?o=(String(t).includes("e")?t.toLocaleString("en-US",{useGrouping:!1,maximumFractionDigits:20}):String(t)).replace(".",","):(typeof e=="boolean"?o=e?y.yes.toLowerCase():y.no.toLowerCase():typeof e=="object"?o=JSON.stringify(e):o=String(e),Yi.test(o)&&(o=`'${o}`)),Xi.test(o)?`"${o.replace(/"/g,'""')}"`:o}function Er(e,n){return`\uFEFF${[e.map(o=>Ar(o.label,"text")),...n.map(o=>e.map(a=>Ar(o[a.name],a.format)))].map(o=>`${o.join(";")}\r
|
|
145
|
+
`).join("")}`}function Mr(e,n,t){let o=e.defaultView,a=new(o?.Blob??Blob)([t],{type:"text/csv;charset=utf-8"}),i=(o?.URL??URL).createObjectURL(a),r=h(e,"a",{href:i,download:n,hidden:!0});e.body.appendChild(r),r.click(),r.remove(),(o?.setTimeout??setTimeout)(()=>(o?.URL??URL).revokeObjectURL(i),0)}var Zi=`${M}
|
|
146
|
+
.tools{display:flex;flex-wrap:wrap;align-items:flex-end;gap:.75rem;margin-bottom:.75rem}
|
|
147
|
+
.control{display:flex;flex-direction:column;gap:.25rem;min-width:0;max-width:100%}
|
|
148
|
+
.control>label,legend{font-weight:600}
|
|
149
|
+
fieldset{display:flex;flex-wrap:wrap;gap:.5rem;min-width:0;margin:0;padding:0;border:0}
|
|
150
|
+
fieldset legend{padding:0;margin-bottom:.25rem}
|
|
151
|
+
fieldset.control{flex-direction:row;align-items:flex-end}
|
|
152
|
+
.scroll{position:relative;overflow-x:auto;max-width:100%}
|
|
153
|
+
table{width:100%;border-collapse:collapse;font-variant-numeric:tabular-nums}
|
|
154
|
+
th,td{padding:.5rem .75rem;text-align:start;border-bottom:1px solid var(--cube-color-border)}
|
|
155
|
+
th{font-weight:600;white-space:nowrap}
|
|
156
|
+
th button{min-height:auto;padding:0;border:0;background:none;color:inherit;font:inherit;font-weight:600}
|
|
157
|
+
th button:hover{background:none;text-decoration:underline}
|
|
158
|
+
th[aria-sort=ascending] button::after{content:" \u25B2";content:" \u25B2"/""}
|
|
159
|
+
th[aria-sort=descending] button::after{content:" \u25BC";content:" \u25BC"/""}
|
|
160
|
+
.num{text-align:end;white-space:nowrap}
|
|
161
|
+
tbody tr{cursor:pointer}
|
|
162
|
+
tbody tr:hover{background:var(--cube-color-primary-subtle)}
|
|
163
|
+
tbody tr:focus-visible{outline:3px solid var(--cube-color-focus);outline-offset:-3px}
|
|
164
|
+
tbody tr.chosen{background:var(--cube-color-primary-subtle);box-shadow:inset 4px 0 0 var(--cube-color-primary)}
|
|
165
|
+
.pager{display:flex;flex-wrap:wrap;align-items:center;gap:.5rem;margin-top:.75rem}
|
|
166
|
+
.pager p,.export-status{margin:0;color:var(--cube-color-text-muted)}
|
|
167
|
+
.pager p{margin-inline-end:auto}
|
|
168
|
+
`,ct=Y,Dr=200,es=50,ts=300,Lr=" search";function ns(e){let n=$(e.slice(0,10));return n===null?null:(n.setDate(n.getDate()+1),O(n))}var Le=e=>e!==null&&typeof e=="object"&&!Array.isArray(e);function Fr(e,n,t){let o=e[n];e[n]=Le(o)&&Le(t)?{...o,...t}:t}function rs(e,n){if(typeof e=="number"&&typeof n=="number")return Math.sign(e-n);let t=String(e),o=String(n);return t<o?-1:t>o?1:0}function os(e,n){if(!Le(e)||!Le(n))return e;let t={...n,...e};for(let[o,a]of[["gte",1],["gt",1],["lte",-1],["lt",-1]]){let i=e[o],r=n[o];i!=null&&r!==void 0&&r!==null&&(t[o]=rs(r,i)===a?r:i)}return t}function _r(e,n){let t=n.document;class o extends e{constructor(){super(...arguments);b(this,"period",new z(this));b(this,"context",null);b(this,"parts",new Map);b(this,"values",new Map);b(this,"sortBy",null);b(this,"page",1);b(this,"requests",0);b(this,"rowsController",null);b(this,"debounce",null);b(this,"exporting",null);b(this,"headers",new Map);b(this,"frame",null);b(this,"table",null);b(this,"pagerText",null);b(this,"previous",null);b(this,"next",null);b(this,"pager",null);b(this,"exportButton",null);b(this,"exportStatus",null);b(this,"shownResource",null);b(this,"chosen",null);b(this,"shownIds",null);b(this,"updates",0)}shownFields(){return this.context?.columns.map(r=>r.name)??[]}disconnectedCallback(){super.disconnectedCallback(),this.stopDebounce(),this.rowsController?.abort(),this.exporting?.abort(),this.exporting=null}async load(r,s){if(s===null)return;this.stopDebounce(),this.context=null,this.rowsController?.abort();let l=C(this,"resource");++this.updates,l!==this.shownResource&&(this.values.clear(),this.sortBy=null,this.page=1,this.chosen=null,this.shownIds=null,this.shownResource=l),this.detailTarget();let u=this.attr("period"),c=u===null||u===""?null:tt(this.attr("date-field"),null,this.localName),p=le(this),f=await et(this,u);if(r.aborted)return;this.period.follow(f);let m=f===null||c===null?p:{...p,...Ze(c,f.value)},d=await s.schema(l);if(r.aborted)return;let g=W(this.attr("fields")),w=d===null||d.fields.some(I=>I.name==="id"),v={session:s,resource:l,columns:[],base:m,fields:g===null?void 0:[...new Set([...w?["id"]:[],...g])],size:Math.min(G(this,"page-size",1,25),Dr)};this.exporting?.abort(),this.exporting=null,r.addEventListener("abort",()=>this.rowsController?.abort(),{once:!0});let k=W(this.attr("filters"))??[];this.checkFilterable(d,k);let x=k.filter(I=>!(I in p)||Le(p[I]));for(let I of[...this.parts.keys()])x.includes(I)||this.parts.delete(I);let P=V(this);this.context=v;let A=await this.fetchRows(v,this.query(v,v.size,this.page)),D=A===null?null:await this.lastPageIfPast(v,A);if(D===null||r.aborted)return;let S=D.data[0];v.columns=Q(d,g,P,S);let E=new Map([...P].map(([I,Pr])=>[I,{...Pr,hidden:!1}])),j=Q(d,x,E,S);this.build(v,d,j),this.renderRows(v,D)}checkFilterable(r,s){if(r===null)return;let l=this.attr("search")?.trim()??"",u=s.map(c=>["filters",c]);l!==""&&u.push(["search",l]);for(let[c,p]of u)if(!r.filterable.includes(p))throw new TypeError(y.invalid.notFilterable(this.localName,c,p))}detailTarget(){let r=this.attr("detail")?.trim()??"";if(r==="")return null;try{return t.querySelector(r)}catch{throw new TypeError(y.invalid.selector(this.localName,"detail",r))}}query(r,s,l){let u={},c=this.attr("search")?.trim()??"",p=this.values.get(Lr)?.trim()??"";c!==""&&p!==""&&Fr(u,c,{ilike:`%${p}%`});for(let[g,w]of this.parts){let v=w();v!==null&&Fr(u,g,v)}let f={...r.base};for(let[g,w]of Object.entries(u)){let v=f[g];f[g]=v===void 0?w:os(v,w)}let m=this.sortBy??(this.attr("sort")?.trim()||null),d={filter:f,page:{size:s,number:l}};return m!==null&&(d.sort=m),r.fields!==void 0&&(d.fields=r.fields),d}async fetchRows(r,s){let l=++this.requests;this.rowsController?.abort();let u=new AbortController;this.rowsController=u,this.setAttribute("aria-busy","true");try{let c=await r.session.resource(r.resource).list(s,{signal:u.signal});return l===this.requests&&!u.signal.aborted?c:null}finally{l===this.requests&&this.removeAttribute("aria-busy")}}async lastPageIfPast(r,s){let l=s.meta.page;return s.data.length>0||this.page<=1||l===void 0||l===null||l.total===0?s:(this.page=Math.max(1,l.pages),this.fetchRows(r,this.query(r,r.size,this.page)))}async update(r){let s=this.context;if(s===null||!this.isConnected)return;r&&(this.page=1);let l=++this.updates;try{let u=await this.fetchRows(s,this.query(s,s.size,this.page)),c=u===null?null:await this.lastPageIfPast(s,u);c!==null&&this.renderRows(s,c)}catch(u){if(l!==this.updates||u?.name==="AbortError")return;this.showRowsState(ss(u))}}later(r){this.stopDebounce(),this.debounce=n.setTimeout(()=>{this.debounce=null,this.update(r)},ts)}stopDebounce(){this.debounce!==null&&n.clearTimeout(this.debounce),this.debounce=null}build(r,s,l){this.parts=new Map;let u=[];if((this.attr("search")?.trim()??"")!==""){let f=h(t,"input",{type:"search"});u.push(this.control(f,Lr,y.search,!0))}for(let f of l)u.push(this.filterControl(f));this.flag("export")?(this.exportButton=h(t,"button",{type:"button",class:"secondary",onclick:()=>this.toggleExport()},y.exportCsv),this.exportStatus=h(t,"p",{class:"export-status",role:"status"}),u.push(this.exportButton,this.exportStatus)):(this.exportButton=null,this.exportStatus=null),this.headers=new Map,this.frame=h(t,"div",{class:"scroll"}),this.pagerText=h(t,"p",{"aria-live":"polite"}),this.previous=h(t,"button",{type:"button",class:"secondary",onclick:()=>this.go(-1)},y.previous),this.next=h(t,"button",{type:"button",class:"secondary",onclick:()=>this.go(1)},y.next),this.pager=h(t,"div",{class:"pager"},this.pagerText,this.previous,this.next);let p=h(t,"thead",{},h(t,"tr",{},...r.columns.map(f=>{let m=s?.sortable.includes(f.name)===!0,d=h(t,"th",{scope:"col",class:ct.includes(f.format)?"num":null},m?h(t,"button",{type:"button",onclick:()=>this.sortOn(f.name)},f.label):f.label,...this.exampleField(r.session,r.resource,f.name)?[" ",Xe(t)]:[]);return m&&this.headers.set(f.name,d),d})));this.table=h(t,"table",{},h(t,"caption",{class:"sr-only"},U(r.resource)),p,h(t,"tbody")),this.markSort(),T(this.body),this.body.appendChild(h(t,"div",{class:"card"},u.length>0?h(t,"div",{class:"tools"},...u):null,this.frame,this.pager))}control(r,s,l,u,c){let p=`cube-table-${++is}`;return r.id=p,r.value=this.values.get(s)??"",c?.(r),r.addEventListener(u?"input":"change",()=>{this.values.set(s,r.value),c?.(r),u?this.later(!0):this.update(!0)}),h(t,"div",{class:"control"},h(t,"label",{for:p},l),r)}filterControl(r){let s=r.name,l=w=>this.values.get(w)?.trim()??"",u=ot(r),c=u===null&&r.format==="boolean";if(u!==null||c){let w=u??[{value:"true",label:y.yes},{value:"false",label:y.no}],v=h(t,"select",{},h(t,"option",{value:""},y.all),...w.map(x=>h(t,"option",{value:x.value},x.label))),k=ct.includes(r.format);return this.parts.set(s,()=>{let x=l(s);return x===""?null:c?x==="true":k?Se(x)??x:x}),this.control(v,s,r.label,!1)}let p=r.format==="date"||r.format==="datetime";if(!p&&!ct.includes(r.format))return this.parts.set(s,()=>l(s)===""?null:{ilike:`%${l(s)}%`}),this.control(h(t,"input",{type:"text"}),s,r.label,!0);let f=w=>{let v=Ae(l(w),r.format);return"value"in v&&typeof v.value=="number"?v.value:null},m=w=>v=>{l(w)!==""&&f(w)===null?v.setAttribute("aria-invalid","true"):v.removeAttribute("aria-invalid")},d=w=>{let v=`${s}:${w}`,k=h(t,"input",{type:p?"date":"text",inputmode:p?null:"decimal","aria-label":`${y[w]} (${r.label})`});return this.control(k,v,y[w],!p,p?void 0:m(v))};this.parts.set(s,()=>{let w={},v=p?l(`${s}:min`)||null:f(`${s}:min`),k=p?ns(l(`${s}:max`)):f(`${s}:max`);return v!==null&&(w.gte=v),k!==null&&(w[p?"lt":"lte"]=k),Object.keys(w).length>0?w:null});let g=h(t,"legend",{},r.label);return h(t,"fieldset",{class:"control"},g,d("min"),d("max"))}sortOn(r){let s=this.sortBy??(this.attr("sort")?.trim()||null);this.sortBy=s===r?`-${r}`:r,this.markSort(),this.update(!0)}markSort(){let r=this.sortBy??(this.attr("sort")?.trim()||""),s=r.replace(/^-/,"");for(let[l,u]of this.headers)l===s?u.setAttribute("aria-sort",r.startsWith("-")?"descending":"ascending"):u.removeAttribute("aria-sort")}go(r){this.page=Math.max(1,this.page+r),this.update(!1)}renderRows(r,s){let l=this.frame,u=this.table;if(l===null||u===null)return;let c=s.meta.page,p=c?.total??s.data.length,f=Math.max(1,c?.pages??1);this.page=c?.number??this.page,T(l);let m=JSON.stringify(s.data.map(g=>g.id??null));if(m!==this.shownIds&&(this.chosen=null),this.shownIds=m,s.data.length===0){this.showRowsState({kind:"empty",detail:null});return}let d=h(t,"tbody",{},...s.data.map(g=>this.row(r,g)));u.replaceChild(d,u.querySelector("tbody")),l.appendChild(u),this.pager!==null&&(this.pager.hidden=!1),this.pagerText!==null&&(this.pagerText.textContent=y.pageOf(this.page,f,p)),this.previous!==null&&(this.previous.disabled=this.page<=1),this.next!==null&&(this.next.disabled=this.page>=f)}showRowsState(r){this.frame!==null&&(T(this.frame),this.frame.appendChild(h(t,"cube-state",{kind:r.kind,message:r.detail,retry:r.retry===!1?"false":null})),this.pager!==null&&(this.pager.hidden=!0))}row(r,s){let l=()=>this.select(r,s,p),u=f=>this.exampleField(r.session,r.resource,f.name),c=this.chosen!==null&&String(s.id??"")===this.chosen,p=h(t,"tr",{tabindex:"0",class:c?"chosen":null,"aria-current":c?"true":null,onclick:l,onkeydown:(f=>{f.key!=="Enter"&&f.key!==" "||(f.preventDefault(),l())})},...r.columns.map(f=>{let m=[ct.includes(f.format)&&"num",u(f)&&"example"];return h(t,"td",{class:m.filter(Boolean).join(" ")||null},_(s[f.name],f.format))}));return p}select(r,s,l){let u=s.id??null;this.chosen=u===null?null:String(u);for(let p of Array.from(l.parentElement?.children??[]))p.classList.toggle("chosen",p===l),p===l?p.setAttribute("aria-current","true"):p.removeAttribute("aria-current");if(this.emit("cube-select",{resource:r.resource,id:u,row:s}),u===null)return;let c=null;try{c=this.detailTarget()}catch(p){this.showState(X(p));return}c?.setAttribute("record-id",String(u))}toggleExport(){if(this.exporting!==null){this.exporting.abort(),this.exporting=null,this.exportButton!==null&&(this.exportButton.textContent=y.exportCsv),this.exportStatus!==null&&(this.exportStatus.textContent="");return}this.runExport()}async runExport(){let r=this.context,s=this.exportButton,l=this.exportStatus;if(r===null||s===null||l===null)return;let u=new AbortController;this.exporting=u;let{signal:c}=u;s.textContent=y.cancel,l.textContent=y.exporting(0);let p=[],f="";try{let m=0,d=this.query(r,Dr,1);for await(let g of r.session.resource(r.resource).pages(d,{signal:c}))if(c.aborted||(p.push(...g.data),l.textContent=y.exporting(p.length),++m>=es))break;c.aborted||Mr(t,`${r.resource}-${O(new Date)}.csv`,Er(r.columns,p))}catch(m){!c.aborted&&m?.name!=="AbortError"&&(f=y.exportFailed)}finally{this.exporting===u&&(this.exporting=null,s.textContent=y.exportCsv,l.textContent=f)}}}return b(o,"tag","cube-table"),b(o,"css",Zi),o}var is=0;function ss(e){return e instanceof TypeError?{kind:"error",detail:null}:X(e)}var as=`${M}${ue}
|
|
169
|
+
ol{margin:0;padding:0;list-style:none;display:flex;flex-direction:column;gap:.25rem}
|
|
170
|
+
button{display:grid;grid-template-columns:1fr auto;gap:.125rem .75rem;width:100%;padding:.5rem .75rem;
|
|
171
|
+
border:0;border-radius:var(--cube-radius);background:none;color:inherit;font:inherit;text-align:start;cursor:pointer}
|
|
172
|
+
button:hover{background:var(--cube-color-primary-subtle)}
|
|
173
|
+
button:focus-visible{outline:2px solid var(--cube-color-focus);outline-offset:2px}
|
|
174
|
+
.name{overflow-wrap:anywhere}
|
|
175
|
+
.value{font-weight:600;font-variant-numeric:tabular-nums}
|
|
176
|
+
svg{grid-column:1/-1;display:block;width:100%;height:.5rem}
|
|
177
|
+
rect.bar{fill:var(--cube-color-series-1)}
|
|
178
|
+
.note{margin:.5rem 0 0;font-size:.875rem;color:var(--cube-color-text-muted)}
|
|
179
|
+
`;function $r(e,n){class t extends e{constructor(){super(...arguments);b(this,"period",new z(this))}shownFields(){return ce(this)}async load(i,r){if(r===null)return;let s=C(this,"resource"),l=C(this,"by"),u=G(this,"limit",1,5),c=await de(this,this.period,i,l);if(c===null)return;let{data:p,meta:f}=await nt(r,s,l,c,i);if(i.aborted)return;let m={descending:this.attr("order")!=="asc",limit:u},d=await rt(this,r,p,{by:l,fn:c.fn},m,i);if(d===null)return;if(d.length===0){this.showState("empty");return}let g=(f?.groups??0)>p.length;this.render(d,l,pe(this,c.count),g)}render(i,r,s,l){let u=n.document,c=Math.max(...i.map(m=>m.value)),p=this.attr("label"),f={};p!==null&&p!==""&&(f["aria-label"]=p),l&&(f["aria-describedby"]="incomplete"),T(this.body),this.body.appendChild(h(u,"div",{class:"card"},...p===null||p===""?[]:[h(u,"p",{class:"label"},p)],h(u,"ol",f,...i.map(m=>h(u,"li",{},h(u,"button",{type:"button",onclick:()=>{this.emit("cube-select",{by:r,key:m.key})}},h(u,"span",{class:"name"},m.label)," ",h(u,"span",{class:"value"},s(m.value)),this.bar(m.value,c))))),...l?[h(u,"p",{class:"note",id:"incomplete",role:"note"},y.incomplete)]:[]))}bar(i,r){let s=r>0&&i>0?i/r*100:0;return N(n.document,"svg",{viewBox:"0 0 100 4",preserveAspectRatio:"none","aria-hidden":"true",focusable:"false"},N(n.document,"rect",{class:"bar",x:0,y:0,width:s,height:4}))}}return b(t,"tag","cube-top"),b(t,"css",as),t}var ls=[["cube-state",Cr],["cube-app-shell",Xn],["cube-period-picker",Tr],["cube-kpi",kr],["cube-chart",fr],["cube-top",$r],["cube-table",_r],["cube-detail",hr],["cube-form",yr],["cube-calc",ar],["cube-board",rr],["cube-gap-list",wr]],Or=new WeakMap;function us(e){return class extends e.HTMLElement{}}function cs(e,n,t){let o=e.document.fonts;if(!(n.fontFamily===null||e.FontFace===void 0||o===void 0))for(let a of n.fontFiles){let i=`${n.fontFamily}|${a.src}|${a.weight??""}|${a.style??""}`;if(!t.has(i)){t.add(i);try{let r={style:a.style??"normal"};a.weight!==void 0&&(r.weight=a.weight);let s=new e.FontFace(n.fontFamily,`url("${a.src}")`,r);o.add(s),s.load().catch(()=>{})}catch{}}}}function ds(e){let n=e.document,t=Or.get(n);t?.stop();let o=new e.CSSStyleSheet,a=t?.fonts??new Set,i=r=>{try{o.replaceSync(Tn(r)),cs(e,r,a)}catch{}};i(ze()),n.adoptedStyleSheets=[...n.adoptedStyleSheets.filter(r=>r!==t?.sheet),o],Or.set(n,{sheet:o,stop:Ve(i),fonts:a})}function Kt(e,n={}){let t=e??globalThis;if(t.customElements===void 0||t.HTMLElement===void 0||t.document===void 0)return;let o=t,a=o.customElements;ds(o);let i=Yn(o,n);for(let[r,s]of ls)a.get(r)===void 0&&a.define(r,s(i,o));a.get("cube-page")===void 0&&a.define("cube-page",us(o));for(let r of["cube-field","cube-input","cube-result","cube-column"])a.get(r)===void 0&&a.define(r,er(o))}var ps=Object.freeze({...Je,defineBlocks:Kt});globalThis.CubeApp=ps;typeof customElements<"u"&&Kt();})();
|