@lucidcms/core
Version:
The core of the Lucid CMS. It's responsible for spinning up the API and serving the CMS.
1 lines • 14 kB
JavaScript
import{B as e,D as t,F as n,G as r,H as i,J as a,L as o,M as s,R as c,T as l,V as u,W as d,X as f,Y as p,_ as m,f as h,j as g,k as _,m as ee,q as v,v as y}from"./web-BWdORzMO.js";var b=Symbol(`store-raw`),x=Symbol(`store-node`),S=Symbol(`store-has`),C=Symbol(`store-self`);function w(e){let t=e[m];if(!t&&(Object.defineProperty(e,m,{value:t=new Proxy(e,M)}),!Array.isArray(e))){let n=Object.keys(e),r=Object.getOwnPropertyDescriptors(e),i=Object.getPrototypeOf(e),a=i!==null&&typeof e==`object`&&!!e&&!Array.isArray(e)&&i!==Object.prototype;if(a){let e=Object.getOwnPropertyDescriptors(i);n.push(...Object.keys(e)),Object.assign(r,e)}for(let i=0,o=n.length;i<o;i++){let o=n[i];a&&o===`constructor`||r[o].get&&Object.defineProperty(e,o,{configurable:!0,enumerable:r[o].enumerable,get:r[o].get.bind(t)})}}return t}function T(e){let t;return typeof e==`object`&&!!e&&(e[m]||!(t=Object.getPrototypeOf(e))||t===Object.prototype||Array.isArray(e))}function E(e,t=new Set){let n,r,i,a;if(n=e!=null&&e[b])return n;if(!T(e)||t.has(e))return e;if(Array.isArray(e)){Object.isFrozen(e)?e=e.slice(0):t.add(e);for(let n=0,a=e.length;n<a;n++)i=e[n],(r=E(i,t))!==i&&(e[n]=r)}else{Object.isFrozen(e)?e=Object.assign({},e):t.add(e);let n=Object.keys(e),o=Object.getOwnPropertyDescriptors(e);for(let s=0,c=n.length;s<c;s++)a=n[s],!o[a].get&&(i=e[a],(r=E(i,t))!==i&&(e[a]=r))}return e}function D(e,t){let n=e[t];return n||Object.defineProperty(e,t,{value:n=Object.create(null)}),n}function O(e,t,r){if(e[t])return e[t];let[i,a]=n(r,{equals:!1,internal:!0});return i.$=a,e[t]=i}function k(e,t){let n=Reflect.getOwnPropertyDescriptor(e,t);return!n||n.get||!n.configurable||t===m||t===x?n:(delete n.value,delete n.writable,n.get=()=>e[m][t],n)}function A(e){o()&&O(D(e,x),C)()}function j(e){return A(e),Reflect.ownKeys(e)}var M={get(e,t,n){if(t===b)return e;if(t===m)return n;if(t===y)return A(e),n;let r=D(e,x),i=r[t],a=i?i():e[t];if(t===x||t===S||t===`__proto__`)return a;if(!i){let n=Object.getOwnPropertyDescriptor(e,t);o()&&(typeof a!=`function`||e.hasOwnProperty(t))&&!(n&&n.get)&&(a=O(r,t,a)())}return T(a)?w(a):a},has(e,t){return t===b||t===m||t===y||t===x||t===S||t===`__proto__`?!0:(o()&&O(D(e,S),t)(),t in e)},set(){return!0},deleteProperty(){return!0},ownKeys:j,getOwnPropertyDescriptor:k};function N(e,t,n,r=!1){if(t===`__proto__`||!r&&e[t]===n)return;let i=e[t],a=e.length;n===void 0?(delete e[t],e[S]&&e[S][t]&&i!==void 0&&e[S][t].$()):(e[t]=n,e[S]&&e[S][t]&&i===void 0&&e[S][t].$());let o=D(e,x),s;if((s=O(o,t,i))&&s.$(()=>n),Array.isArray(e)&&e.length!==a){for(let t=e.length;t<a;t++)(s=o[t])&&s.$();(s=O(o,`length`,a))&&s.$(e.length)}(s=o[C])&&s.$()}function P(e,t){let n=Object.keys(t);for(let r=0;r<n.length;r+=1){let i=n[r];F(i)||N(e,i,t[i])}}function F(e){return e===`__proto__`||e===`constructor`||e===`prototype`}function te(e,t){if(typeof t==`function`&&(t=t(e)),t=E(t),Array.isArray(t)){if(e===t)return;let n=0,r=t.length;for(;n<r;n++){let r=t[n];e[n]!==r&&N(e,n,r)}N(e,`length`,r)}else P(e,t)}function I(e,t,n=[]){let r,i=e;if(t.length>1){r=t.shift();let a=typeof r,o=Array.isArray(e);if(a===`string`&&(r===`__proto__`||t.length>1&&F(r)))return;if(Array.isArray(r)){for(let i=0;i<r.length;i++)I(e,[r[i]].concat(t),n);return}else if(o&&a===`function`){for(let i=0;i<e.length;i++)r(e[i],i)&&I(e,[i].concat(t),n);return}else if(o&&a===`object`){let{from:i=0,to:a=e.length-1,by:o=1}=r;for(let r=i;r<=a;r+=o)I(e,[r].concat(t),n);return}else if(t.length>1){I(e[r],t,[r].concat(n));return}i=e[r],n=[r].concat(n)}let a=t[0];typeof a==`function`&&(a=a(i,n),a===i)||r===void 0&&a==null||(a=E(a),r===void 0||T(i)&&T(a)&&!Array.isArray(a)?P(i,a):N(e,r,a))}function L(...[e,t]){let n=E(e||{}),r=Array.isArray(n),i=w(n);function a(...e){l(()=>{r&&e.length===1?te(n,e[0]):I(n,e)})}return[i,a]}var R=Symbol(`store-root`);function ne(e){return e===`__proto__`||e===`constructor`||e===`prototype`}function z(e,t,n,r,i){if(ne(n))return;let a=t[n];if(e===a)return;let o=Array.isArray(e);if(n!==R&&(!T(e)||!T(a)||o!==Array.isArray(a)||i&&e[i]!==a[i])){N(t,n,e);return}if(o){if(e.length&&a.length&&(!r||i&&e[0]&&e[0][i]!=null)){let t,n,o,s,c,l,u,d;for(o=0,s=Math.min(a.length,e.length);o<s&&(a[o]===e[o]||i&&a[o]&&e[o]&&a[o][i]&&a[o][i]===e[o][i]);o++)z(e[o],a,o,r,i);let f=Array(e.length),p=new Map;for(s=a.length-1,c=e.length-1;s>=o&&c>=o&&(a[s]===e[c]||i&&a[s]&&e[c]&&a[s][i]&&a[s][i]===e[c][i]);s--,c--)f[c]=a[s];if(o>c||o>s){for(n=o;n<=c;n++)N(a,n,e[n]);for(;n<e.length;n++)N(a,n,f[n]),z(e[n],a,n,r,i);a.length>e.length&&N(a,`length`,e.length);return}for(u=Array(c+1),n=c;n>=o;n--)l=e[n],d=i&&l?l[i]:l,t=p.get(d),u[n]=t===void 0?-1:t,p.set(d,n);for(t=o;t<=s;t++)l=a[t],d=i&&l?l[i]:l,n=p.get(d),n!==void 0&&n!==-1&&(f[n]=a[t],n=u[n],p.set(d,n));for(n=o;n<e.length;n++)n in f?(N(a,n,f[n]),z(e[n],a,n,r,i)):N(a,n,e[n])}else for(let t=0,n=e.length;t<n;t++)z(e[t],a,t,r,i);a.length>e.length&&N(a,`length`,e.length);return}let s=Object.keys(e);for(let t=0,n=s.length;t<n;t++)ne(s[t])||z(e[s[t]],a,s[t],r,i);let c=Object.keys(a);for(let t=0,n=c.length;t<n;t++)e[c[t]]===void 0&&N(a,c[t],void 0)}function re(e,t={}){let{merge:n,key:r=`id`}=t,i=E(e);return e=>{if(!T(e)||!T(i))return i;let t=z(i,{[R]:e},R,n,r);return t===void 0?e:t}}var B=new WeakMap,V={get(e,t){if(t===b)return e;let n=e[t];if(t===m||t===y||t===x||t===S||t===`__proto__`)return n;let r;return T(n)?B.get(n)||(B.set(n,r=new Proxy(n,V)),r):n},set(e,t,n){return N(e,t,E(n)),!0},deleteProperty(e,t){return N(e,t,void 0,!0),!0}};function ie(e){return t=>{if(T(t)){let n;(n=B.get(t))||B.set(t,n=new Proxy(t,V)),e(n)}return t}}function H(){let e=new Set;function t(t){return e.add(t),()=>e.delete(t)}let n=!1;function r(t,r){if(n)return!(n=!1);let i={to:t,options:r,defaultPrevented:!1,preventDefault:()=>i.defaultPrevented=!0};for(let a of e)a.listener({...i,from:a.location,retry:e=>{e&&(n=!0),a.navigate(t,{...r,resolve:!1})}});return!i.defaultPrevented}return{subscribe:t,confirm:r}}var U;function W(){(!window.history.state||window.history.state._depth==null)&&window.history.replaceState({...window.history.state,_depth:window.history.length-1},``),U=window.history.state._depth}W();function ae(e){return{...e,_depth:window.history.state&&window.history.state._depth}}function oe(e,t){let n=!1;return()=>{let r=U;W();let i=r==null?null:U-r;if(n){n=!1;return}i&&t(i)?(n=!0,window.history.go(-i)):e()}}var se=/^(?:[a-z0-9]+:)?\/\//i,ce=/^\/+|(\/)\/+$/g,le=`http://sr`;function G(e,t=!1){let n=e.replace(ce,`$1`);return n?t||/^[?#]/.test(n)?n:`/`+n:``}function K(e,t,n){if(se.test(t))return;let r=G(e),i=n&&G(n),a=``;return a=!i||t.startsWith(`/`)?r:i.toLowerCase().indexOf(r.toLowerCase())===0?i:r+i,(a||`/`)+G(t,!a)}function ue(e,t){if(e==null)throw Error(t);return e}function de(e,t){return G(e).replace(/\/*(\*.*)?$/g,``)+G(t)}function fe(e){let t={};return e.searchParams.forEach((e,n)=>{n in t?Array.isArray(t[n])?t[n].push(e):t[n]=[t[n],e]:t[n]=e}),t}function pe(e,t,n){let[r,i]=e.split(`/*`,2),a=r.split(`/`).filter(Boolean),o=a.length;return e=>{let r=e.split(`/`).filter(Boolean),s=r.length-o;if(s<0||s>0&&i===void 0&&!t)return null;let c={path:o?``:`/`,params:{}},l=e=>n===void 0?void 0:n[e];for(let e=0;e<o;e++){let t=a[e],n=t[0]===`:`,i=n?r[e]:r[e].toLowerCase(),o=n?t.slice(1):t.toLowerCase();if(n&&q(i,l(o)))c.params[o]=i;else if(n||!q(i,o))return null;c.path+=`/${i}`}if(i){let e=s?r.slice(-s).join(`/`):``;if(q(e,l(i)))c.params[i]=e;else return null}return c}}function q(e,t){let n=t=>t===e;return t===void 0?!0:typeof t==`string`?n(t):typeof t==`function`?t(e):Array.isArray(t)?t.some(n):t instanceof RegExp&&t.test(e)}function me(e){let[t,n]=e.pattern.split(`/*`,2),r=t.split(`/`).filter(Boolean);return r.reduce((e,t)=>e+(t.startsWith(`:`)?2:3),r.length-(n===void 0?0:1))}function he(e){let t=new Map,n=c();return new Proxy({},{get(i,a){return t.has(a)||r(n,()=>t.set(a,g(()=>e()[a]))),t.get(a)()},getOwnPropertyDescriptor(){return{enumerable:!0,configurable:!0}},ownKeys(){return Reflect.ownKeys(e())},has(t,n){return n in e()}})}function ge(e){let t=/(\/?\:[^\/]+)\?/.exec(e);if(!t)return[e];let n=e.slice(0,t.index),r=e.slice(t.index+t[0].length),i=[n,n+=t[1]];for(;t=/^(\/\:[^\/]+)\?/.exec(r);)i.push(n+=t[1]),r=r.slice(t[0].length);return ge(r).reduce((e,t)=>[...e,...i.map(e=>e+t)],[])}var _e=100,ve=_(),J=_(),Y=()=>ue(f(ve),`<A> and 'use' router primitives can be only used inside a Route.`),ye=()=>f(J)||Y().base,be=e=>{let t=ye();return g(()=>t.resolvePath(e()))},xe=e=>{let t=Y();return g(()=>{let n=e();return n===void 0?n:t.renderPath(n)})},X=()=>Y().navigatorFactory(),Z=()=>Y().location,Se=()=>Y().params,Ce=e=>{i(Y().beforeLeave.subscribe({listener:e,location:Z(),navigate:X()}))};function we(e,t=``){let{component:n,preload:r,load:i,children:a,info:o}=e,s=!a||Array.isArray(a)&&!a.length,c={key:e,component:n,preload:r||i,info:o};return Ee(e.path).reduce((n,r)=>{for(let i of ge(r)){let a=de(t,i),o=s?a:a.split(`/*`,1)[0];o=o.split(`/`).map(e=>e.startsWith(`:`)||e.startsWith(`*`)?e:encodeURIComponent(e)).join(`/`),n.push({...c,originalPath:r,pattern:o,matcher:pe(o,!s,e.matchFilters)})}return n},[])}function Te(e,t=0){return{routes:e,score:me(e[e.length-1])*1e4-t,matcher(t){let n=[];for(let r=e.length-1;r>=0;r--){let i=e[r],a=i.matcher(t);if(!a)return null;n.unshift({...a,route:i})}return n}}}function Ee(e){return Array.isArray(e)?e:[e]}function De(e,t=``,n=[],r=[]){let i=Ee(e);for(let e=0,a=i.length;e<a;e++){let a=i[e];if(a&&typeof a==`object`){a.hasOwnProperty(`path`)||(a.path=``);let e=we(a,t);for(let t of e){n.push(t);let e=Array.isArray(a.children)&&a.children.length===0;if(a.children&&!e)De(a.children,t.pattern,n,r);else{let e=Te([...n],r.length);r.push(e)}n.pop()}}}return n.length?r:r.sort((e,t)=>t.score-e.score)}function Q(e,t){for(let n=0,r=e.length;n<r;n++){let r=e[n].matcher(t);if(r)return r}return[]}function Oe(e,t,n){let r=new URL(le),i=g(t=>{let n=e();try{return new URL(n,r)}catch{return console.error(`Invalid path ${n}`),t}},r,{equals:(e,t)=>e.href===t.href}),a=g(()=>i().pathname),o=g(()=>i().search,!0),s=g(()=>i().hash),c=()=>``,l=u(o,()=>fe(i()));return{get pathname(){return a()},get search(){return o()},get hash(){return s()},get state(){return t()},get key(){return c()},query:n?n(l):he(l)}}var $;function ke(){return $}function Ae(e){}function je(e,t,i,o={}){let{signal:[c,m],utils:h={}}=e,_=h.parsePath||(e=>e),ee=h.renderPath||(e=>e),v=h.beforeLeave||H(),y=K(``,o.base||``);if(y===void 0)throw Error(`${y} is not a valid base path`);y&&!c().value&&m({value:y,replace:!0,scroll:!1});let[b,x]=n(!1),S,C=(e,t)=>{t.value===w()&&t.state===E()||(S===void 0&&x(!0),$=e,S=t,a(()=>{S===t&&(T(S.value),D(S.state),d(),A[1](e=>e.filter(e=>e.pending)))}).finally(()=>{S===t&&l(()=>{$=void 0,e===`navigate`&&I(S),x(!1),S=void 0})}))},[w,T]=n(c().value),[E,D]=n(c().state),O=Oe(w,E,h.queryWrapper),k=[],A=n([]),j=g(()=>typeof o.transformUrl==`function`?Q(t(),o.transformUrl(O.pathname)):Q(t(),O.pathname)),M=()=>{let e=j(),t={};for(let n=0;n<e.length;n++)Object.assign(t,e[n].params);return t},N=h.paramsWrapper?h.paramsWrapper(M,t):he(M),P={pattern:y,path:()=>y,outlet:()=>null,resolvePath(e){return K(y,e)}};return s(u(c,e=>C(`native`,e),{defer:!0})),{base:P,location:O,params:N,isRouting:b,renderPath:ee,parsePath:_,navigatorFactory:te,matches:j,beforeLeave:v,preloadRoute:L,singleFlight:o.singleFlight===void 0||o.singleFlight,submissions:A};function F(e,t,n){p(()=>{if(typeof t==`number`){t&&(h.go?h.go(t):console.warn(`Router integration does not support relative routing`));return}let r=!t||t[0]===`?`,{replace:i,resolve:a,scroll:o,state:s}={replace:!1,resolve:!r,scroll:!0,...n},c=a?e.resolvePath(t):K(r&&O.pathname||``,t);if(c===void 0)throw Error(`Path '${t}' is not a routable path`);if(k.length>=_e)throw Error(`Too many redirects`);let l=w();(c!==l||s!==E())&&v.confirm(c,n)&&(k.push({value:l,replace:i,scroll:o,state:E()}),C(`navigate`,{value:c,state:s}))})}function te(e){return e=e||f(J)||P,(t,n)=>F(e,t,n)}function I(e){let t=k[0];t&&(m({...e,replace:t.replace,scroll:t.scroll}),k.length=0)}function L(e,n){let a=Q(t(),e.pathname),o=$;$=`preload`;for(let t in a){let{route:o,params:s}=a[t];o.component&&o.component.preload&&o.component.preload();let{preload:c}=o;n&&c&&r(i(),()=>c({params:s,location:{pathname:e.pathname,search:e.search,hash:e.hash,query:fe(e),state:null,key:``},intent:`preload`}))}$=o}}function Me(e,n,r,i){let{base:a,location:o,params:s}=e,{pattern:c,component:l,preload:u}=i().route,d=g(()=>i().path);l&&l.preload&&l.preload();let f=u?u({params:s,location:o,intent:$||`initial`}):void 0;return{parent:n,pattern:c,path:d,outlet:()=>l?t(l,{params:s,location:o,data:f,get children(){return r()}}):r(),resolvePath(e){return K(a.path(),e,d())}}}var Ne=ee(`<a>`);function Pe(t){t=e({inactiveClass:`inactive`,activeClass:`active`},t);let[,n]=v(t,[`href`,`state`,`class`,`activeClass`,`inactiveClass`,`end`]),r=be(()=>t.href),i=xe(r),a=Z(),o=g(()=>{let e=r();if(e===void 0)return[!1,!1];let n=G(e.split(/[?#]/,1)[0]).toLowerCase(),i=decodeURI(G(a.pathname).toLowerCase());return[t.end?n===i:i.startsWith(n+`/`)||i===n,n===i]});return(()=>{var r=Ne();return h(r,e(n,{get href(){return i()||t.href},get state(){return JSON.stringify(t.state)},get classList(){return{...t.class&&{[t.class]:!0},[t.inactiveClass]:!o()[0],[t.activeClass]:o()[0],...n.classList}},link:``,get"aria-current"(){return o()[1]?`page`:void 0}}),!1,!1),r})()}function Fe(e){let t=X(),n=Z(),{href:r,state:i}=e;return t(typeof r==`function`?r({navigate:t,location:n}):r,{replace:!0,state:i}),null}var[Ie,Le]=L({user:null,reset(){Le(`user`,null)},hasPermission(e){let t=e.filter(e=>e!==void 0);if(t.length===0)return{all:!1,some:!1};if(this.user?.superAdmin)return{all:!0,some:!0};let n=this.user?.permissions;return n?{all:t.every(e=>n.includes(e)),some:t.some(e=>n.includes(e))}:{all:!1,some:!1}}}),Re={get:Ie,set:Le};export{re as C,ie as S,H as _,ve as a,W as b,je as c,Ae as d,Ce as f,le as g,Se as h,J as i,ke as l,X as m,Pe as n,De as o,Z as p,Fe as r,Me as s,Re as t,Q as u,ae as v,E as w,L as x,oe as y};