create-prisma-php-app 4.1.0-alpha.7 → 4.1.0-alpha.8

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.
@@ -1 +1 @@
1
- import{P as g}from"./pp-reactive-v1.js";import{c as y}from"./global-functions.js";class m extends g{cryptoKey=null;activeAbortController=null;static instance=null;navigationEnabled=!1;boundHandleLinkClick=null;boundHandlePopState=null;constructor(){super(),this.hydrated().then(()=>{document.body.hidden=!1,this.enableSPANavigation()}).catch(t=>{console.error("PPHPUtilities hydration error:",t),document.body.hidden=!1})}static getInstance(){return this.instance||(this.instance=new m),this.instance}enableSPANavigation(){this.navigationEnabled||(this.navigationEnabled=!0,this.boundHandleLinkClick=this.handleLinkClick.bind(this),this.boundHandlePopState=this.handlePopState.bind(this),document.addEventListener("click",this.boundHandleLinkClick),window.addEventListener("popstate",this.boundHandlePopState))}disableSPANavigation(){this.navigationEnabled=!1,this.boundHandleLinkClick&&(document.removeEventListener("click",this.boundHandleLinkClick),this.boundHandleLinkClick=null),this.boundHandlePopState&&(window.removeEventListener("popstate",this.boundHandlePopState),this.boundHandlePopState=null)}handleLinkClick(t){if(!this.navigationEnabled)return;const n=t.target.closest("a");if(!(!n||!n.href))try{const a=new URL(n.href),o=a.origin!==window.location.origin,i=a.pathname===window.location.pathname&&a.search===window.location.search;if(o||n.target==="_blank"||n.hasAttribute("download")||n.getAttribute("pp-no-spa")==="true"||t.ctrlKey||t.metaKey||t.shiftKey||t.altKey)return;if(t.preventDefault(),i){const s=a.hash;if(s){const r=document.querySelector(s);r&&r.scrollIntoView({behavior:"smooth"})}else window.scrollTo({top:0,behavior:"smooth"});return}this.navigateTo(a.pathname+a.search+a.hash)}catch(a){console.error("Link click navigation error:",a)}}async handlePopState(){const t=window.location.pathname+window.location.search+window.location.hash;await this.navigateTo(t,!1)}async navigateTo(t,e=!0){try{document.dispatchEvent(new CustomEvent("pp:navigation:start",{detail:{url:t}}));const n=document.getElementById("loading-file-1B87E");if(n){const c=this.findLoadingElement(n,window.location.pathname);c&&await this.updateContentWithTransition(c)}const a=await fetch(t,{headers:{"X-Requested-With":"XMLHttpRequest",Accept:"text/html"}});if(!a.ok)throw new Error(`Navigation failed: ${a.status} ${a.statusText}`);const o=await a.text(),s=new DOMParser().parseFromString(o,"text/html");s.title&&(document.title=s.title),this.cleanup(),this.reconcileHead(s);const r=s.body;document.body.innerHTML=r.innerHTML,e&&history.pushState(null,"",t),this.reinitialize(),document.body.hidden=!1;const d=new URL(t,window.location.origin).hash;if(d){const c=document.querySelector(d);c&&c.scrollIntoView({behavior:"smooth"})}else window.scrollTo({top:0,behavior:"instant"});document.dispatchEvent(new CustomEvent("pp:navigation:complete",{detail:{url:t}}))}catch(n){console.error("Navigation error:",n),document.body.hidden=!1,document.dispatchEvent(new CustomEvent("pp:navigation:error",{detail:{url:t,error:n}})),window.location.href=t}}findLoadingElement(t,e){let n=e;for(;;){const a=t.querySelector(`div[pp-loading-url='${n}']`);if(a)return a;if(n==="/")break;const o=n.lastIndexOf("/");o<=0?n="/":n=n.substring(0,o)}return t.querySelector("div[pp-loading-url='/' ]")}async updateContentWithTransition(t){const e=document.querySelector("[pp-loading-content='true']")||document.body;if(!e)return;const{fadeIn:n,fadeOut:a}=this.parseTransition(t);await this.fadeOut(e,a),e.innerHTML=t.innerHTML,this.fadeIn(e,n)}parseTransition(t){let e=250,n=250;const o=t.querySelector("[pp-loading-transition]")?.getAttribute("pp-loading-transition");if(o){let i=JSON.parse(o);i&&typeof i=="object"?(e=this.parseTime(i.fadeIn??e),n=this.parseTime(i.fadeOut??n)):console.warn("pp-loading-transition is not valid JSON → default values (250 ms) will be used. String:",o)}return{fadeIn:e,fadeOut:n}}fadeOut(t,e){return new Promise(n=>{t.style.transition=`opacity ${e}ms ease-out`,t.style.opacity="0",setTimeout(()=>{t.style.transition="",n()},e)})}fadeIn(t,e){t.style.transition=`opacity ${e}ms ease-in`,t.style.opacity="1",setTimeout(()=>{t.style.transition=""},e)}parseTime(t){if(typeof t=="number")return t;const e=t.match(/^(\d+)(ms|s|m)?$/);if(e){const n=parseInt(e[1],10);switch(e[2]||"ms"){case"ms":return n;case"s":return n*1e3;case"m":return n*60*1e3;default:return n}}return 0}reconcileHead(t){const e="pp-dynamic-script",n="pp-dynamic-meta",a="pp-dynamic-link";document.head.querySelectorAll(`[${n}]`).forEach(o=>o.remove()),document.head.querySelectorAll(`[${a}]`).forEach(o=>o.remove()),document.head.querySelectorAll(`[${e}]`).forEach(o=>o.remove()),Array.from(t.head.children).forEach(o=>{switch(o.tagName){case"SCRIPT":if(o.hasAttribute(e)){const i=document.createElement("script");Array.from(o.attributes).forEach(s=>i.setAttribute(s.name,s.value)),i.textContent=o.textContent,document.head.appendChild(i)}break;case"META":{const i=o;if(i.getAttribute("charset")||i.name==="viewport")break;const s=i.name?`meta[name="${i.name}"]`:`meta[property="${i.getAttribute("property")}"]`,r=i.cloneNode(!0),d=document.head.querySelector(s);d?document.head.replaceChild(r,d):document.head.insertBefore(r,document.head.querySelector("title")?.nextSibling||null);break}case"TITLE":{const i=o.cloneNode(!0),s=document.head.querySelector("title");s?document.head.replaceChild(i,s):document.head.appendChild(i);break}case"LINK":{const i=o;if(i.rel==="icon"){const s=i.cloneNode(!0),r=document.head.querySelector('link[rel="icon"]');r?document.head.replaceChild(s,r):document.head.appendChild(s)}else i.hasAttribute(a)&&document.head.appendChild(i.cloneNode(!0));break}}})}async redirect(t){if(t)try{const e=new URL(t,window.location.origin);e.origin!==window.location.origin?window.location.href=t:this.navigationEnabled?await this.navigateTo(e.pathname+e.search+e.hash):window.location.href=t}catch(e){console.error("Redirect error:",e)}}async initCryptoKey(){const t=document.cookie.split("; ").find(s=>s.startsWith("pp_function_call_jwt="))?.split("=",2)[1];if(!t)throw new Error("Missing function-call token");const[,e]=t.split("."),n=atob(e.replace(/-/g,"+").replace(/_/g,"/")),{k:a,exp:o}=JSON.parse(n);if(Date.now()/1e3>o)throw new Error("Function-call token expired");const i=Uint8Array.from(atob(a),s=>s.charCodeAt(0));this.cryptoKey=await crypto.subtle.importKey("raw",i,{name:"AES-CBC"},!1,["encrypt","decrypt"])}async encryptCallbackName(t){await this.initCryptoKey();const e=crypto.getRandomValues(new Uint8Array(16)),n=new TextEncoder().encode(t),a=await crypto.subtle.encrypt({name:"AES-CBC",iv:e},this.cryptoKey,n),o=btoa(String.fromCharCode(...e)),i=btoa(String.fromCharCode(...new Uint8Array(a)));return`${o}:${i}`}createFetchOptions(t){return{method:"POST",headers:{"Content-Type":"application/json",HTTP_PP_WIRE_REQUEST:"true"},body:JSON.stringify(t)}}async fetchFunction(t,e={},n=!1){let a=null;try{n&&this.activeAbortController&&(this.activeAbortController.abort(),this.activeAbortController=null),a=new AbortController,n&&(this.activeAbortController=a);const i={callback:await this.encryptCallbackName(t),...e},s=window.location.href;let r;if(Object.keys(i).some(h=>{const l=i[h];return l instanceof File||l instanceof FileList&&l.length>0})){const h=new FormData;Object.keys(i).forEach(l=>{const f=i[l];f instanceof File?h.append(l,f):f instanceof FileList?Array.from(f).forEach(S=>h.append(l,S)):h.append(l,f)}),r={method:"POST",headers:{HTTP_PP_WIRE_REQUEST:"true"},body:h,signal:a.signal}}else r={signal:a.signal,...this.createFetchOptions(i)};const c=await fetch(s,r);if(!c.ok)throw new Error(`Fetch failed with status: ${c.status} ${c.statusText}`);const w=await c.text();a&&this.activeAbortController===a&&(this.activeAbortController=null);try{return JSON.parse(w)}catch{return w}}catch(o){if(a&&this.activeAbortController===a&&(this.activeAbortController=null),o instanceof Error&&o.name==="AbortError")return console.log("Request was cancelled"),{cancelled:!0};throw console.error("Error in fetchFunction:",o),new Error("Failed to fetch data.")}}}class u{state;static instance=null;listeners;pp;STORAGE_KEY;lastSyncedState=null;constructor(t={}){this.state=t,this.listeners=[],this.pp=m.getInstance(),this.STORAGE_KEY=this.getCookie("pp_local_store_key")||"pp_local_store_59e13",this.lastSyncedState=localStorage.getItem(this.STORAGE_KEY),this.loadState()}static getInstance(t={}){return u.instance||(u.instance=new u(t)),u.instance}getCookie(t){return document.cookie.split("; ").find(e=>e.startsWith(t+"="))?.split("=")[1]||null}setState(t,e=!1){const n={...this.state,...t};if(JSON.stringify(n)!==JSON.stringify(this.state)&&(this.state=n,this.listeners.forEach(a=>a(this.state)),this.saveState(),e)){const a=localStorage.getItem(this.STORAGE_KEY);a&&a!==this.lastSyncedState&&(this.pp.fetchFunction(this.STORAGE_KEY,{[this.STORAGE_KEY]:a}),this.lastSyncedState=a)}}saveState(){localStorage.setItem(this.STORAGE_KEY,JSON.stringify(this.state))}loadState(){const t=localStorage.getItem(this.STORAGE_KEY);t&&(this.state=JSON.parse(t),this.listeners.forEach(e=>e(this.state)))}resetState(t,e=!1){if(t?(delete this.state[t],this.saveState()):(this.state={},localStorage.removeItem(this.STORAGE_KEY)),this.listeners.forEach(n=>n(this.state)),e){const n=t?localStorage.getItem(this.STORAGE_KEY):null;this.pp.fetchFunction(this.STORAGE_KEY,{[this.STORAGE_KEY]:n}),this.lastSyncedState=n}}}class p{static instance=null;listeners=[];constructor(){}static getInstance(){return p.instance||(p.instance=new p),p.instance}get params(){return new URLSearchParams(window.location.search)}get(t){return this.params.get(t)}set(t,e){const n=this.params;n.set(t,e),this.updateURL(n)}delete(t){const e=this.params;e.delete(t),this.updateURL(e)}replace(t){const e=new URLSearchParams;for(const n in t){const a=t[n];a!==null&&e.set(n,a)}this.updateURL(e,!0)}updateURL(t,e=!1){const n=`${window.location.pathname}?${t.toString()}`;e?history.replaceState(null,"",n):history.pushState(null,"",n),this.notifyListeners(t)}listen(t){this.listeners.push(t)}notifyListeners(t){for(const e of this.listeners)e(t)}enablePopStateListener(){window.addEventListener("popstate",()=>{this.notifyListeners(this.params)})}}y("pp",m);y("store",u);y("searchParams",p);
1
+ import{P as g}from"./pp-reactive-v1.js";import{c as y}from"./global-functions.js";class m extends g{cryptoKey=null;activeAbortController=null;static instance=null;navigationEnabled=!1;boundHandleLinkClick=null;boundHandlePopState=null;constructor(){super(),this.hydrated().then(()=>{document.body.hidden=!1,this.enableSPANavigation()}).catch(t=>{console.error("PPHPUtilities hydration error:",t),document.body.hidden=!1})}static getInstance(){return this.instance||(this.instance=new m),this.instance}enableSPANavigation(){this.navigationEnabled||(this.navigationEnabled=!0,this.boundHandleLinkClick=this.handleLinkClick.bind(this),this.boundHandlePopState=this.handlePopState.bind(this),document.addEventListener("click",this.boundHandleLinkClick),window.addEventListener("popstate",this.boundHandlePopState))}disableSPANavigation(){this.navigationEnabled=!1,this.boundHandleLinkClick&&(document.removeEventListener("click",this.boundHandleLinkClick),this.boundHandleLinkClick=null),this.boundHandlePopState&&(window.removeEventListener("popstate",this.boundHandlePopState),this.boundHandlePopState=null)}handleLinkClick(t){if(!this.navigationEnabled)return;const n=t.target.closest("a");if(!(!n||!n.href))try{const a=new URL(n.href),o=a.origin!==window.location.origin,i=a.pathname===window.location.pathname&&a.search===window.location.search;if(o||n.target==="_blank"||n.hasAttribute("download")||n.getAttribute("pp-no-spa")==="true"||t.ctrlKey||t.metaKey||t.shiftKey||t.altKey)return;if(t.preventDefault(),i){const s=a.hash;if(s){const r=document.querySelector(s);r&&r.scrollIntoView({behavior:"smooth"})}else window.scrollTo({top:0,behavior:"smooth"});return}this.navigateTo(a.pathname+a.search+a.hash)}catch(a){console.error("Link click navigation error:",a)}}async handlePopState(){const t=window.location.pathname+window.location.search+window.location.hash;await this.navigateTo(t,!1)}async navigateTo(t,e=!0){try{document.dispatchEvent(new CustomEvent("pp:navigation:start",{detail:{url:t}}));const n=document.getElementById("loading-file-1B87E");if(n){const c=this.findLoadingElement(n,window.location.pathname);c&&await this.updateContentWithTransition(c)}const a=await fetch(t,{headers:{"X-Requested-With":"XMLHttpRequest",Accept:"text/html"}});if(!a.ok)throw new Error(`Navigation failed: ${a.status} ${a.statusText}`);const o=await a.text(),s=new DOMParser().parseFromString(o,"text/html");s.title&&(document.title=s.title),this.cleanup(),this.reconcileHead(s);const r=s.body;document.body.innerHTML=r.innerHTML,e&&history.pushState(null,"",t),this.reinitialize();const d=new URL(t,window.location.origin).hash;if(d){const c=document.querySelector(d);c&&c.scrollIntoView({behavior:"smooth"})}else window.scrollTo({top:0,behavior:"instant"});document.dispatchEvent(new CustomEvent("pp:navigation:complete",{detail:{url:t}})),document.body.hidden=!1}catch(n){console.error("Navigation error:",n),document.body.hidden=!1,document.dispatchEvent(new CustomEvent("pp:navigation:error",{detail:{url:t,error:n}})),window.location.href=t}}findLoadingElement(t,e){let n=e;for(;;){const a=t.querySelector(`div[pp-loading-url='${n}']`);if(a)return a;if(n==="/")break;const o=n.lastIndexOf("/");o<=0?n="/":n=n.substring(0,o)}return t.querySelector("div[pp-loading-url='/' ]")}async updateContentWithTransition(t){const e=document.querySelector("[pp-loading-content='true']")||document.body;if(!e)return;const{fadeIn:n,fadeOut:a}=this.parseTransition(t);await this.fadeOut(e,a),e.innerHTML=t.innerHTML,this.fadeIn(e,n)}parseTransition(t){let e=250,n=250;const o=t.querySelector("[pp-loading-transition]")?.getAttribute("pp-loading-transition");if(o){let i=JSON.parse(o);i&&typeof i=="object"?(e=this.parseTime(i.fadeIn??e),n=this.parseTime(i.fadeOut??n)):console.warn("pp-loading-transition is not valid JSON → default values (250 ms) will be used. String:",o)}return{fadeIn:e,fadeOut:n}}fadeOut(t,e){return new Promise(n=>{t.style.transition=`opacity ${e}ms ease-out`,t.style.opacity="0",setTimeout(()=>{t.style.transition="",n()},e)})}fadeIn(t,e){t.style.transition=`opacity ${e}ms ease-in`,t.style.opacity="1",setTimeout(()=>{t.style.transition=""},e)}parseTime(t){if(typeof t=="number")return t;const e=t.match(/^(\d+)(ms|s|m)?$/);if(e){const n=parseInt(e[1],10);switch(e[2]||"ms"){case"ms":return n;case"s":return n*1e3;case"m":return n*60*1e3;default:return n}}return 0}reconcileHead(t){const e="pp-dynamic-script",n="pp-dynamic-meta",a="pp-dynamic-link";document.head.querySelectorAll(`[${n}]`).forEach(o=>o.remove()),document.head.querySelectorAll(`[${a}]`).forEach(o=>o.remove()),document.head.querySelectorAll(`[${e}]`).forEach(o=>o.remove()),Array.from(t.head.children).forEach(o=>{switch(o.tagName){case"SCRIPT":if(o.hasAttribute(e)){const i=document.createElement("script");Array.from(o.attributes).forEach(s=>i.setAttribute(s.name,s.value)),i.textContent=o.textContent,document.head.appendChild(i)}break;case"META":{const i=o;if(i.getAttribute("charset")||i.name==="viewport")break;const s=i.name?`meta[name="${i.name}"]`:`meta[property="${i.getAttribute("property")}"]`,r=i.cloneNode(!0),d=document.head.querySelector(s);d?document.head.replaceChild(r,d):document.head.insertBefore(r,document.head.querySelector("title")?.nextSibling||null);break}case"TITLE":{const i=o.cloneNode(!0),s=document.head.querySelector("title");s?document.head.replaceChild(i,s):document.head.appendChild(i);break}case"LINK":{const i=o;if(i.rel==="icon"){const s=i.cloneNode(!0),r=document.head.querySelector('link[rel="icon"]');r?document.head.replaceChild(s,r):document.head.appendChild(s)}else i.hasAttribute(a)&&document.head.appendChild(i.cloneNode(!0));break}}})}async redirect(t){if(t)try{const e=new URL(t,window.location.origin);e.origin!==window.location.origin?window.location.href=t:this.navigationEnabled?await this.navigateTo(e.pathname+e.search+e.hash):window.location.href=t}catch(e){console.error("Redirect error:",e)}}async initCryptoKey(){const t=document.cookie.split("; ").find(s=>s.startsWith("pp_function_call_jwt="))?.split("=",2)[1];if(!t)throw new Error("Missing function-call token");const[,e]=t.split("."),n=atob(e.replace(/-/g,"+").replace(/_/g,"/")),{k:a,exp:o}=JSON.parse(n);if(Date.now()/1e3>o)throw new Error("Function-call token expired");const i=Uint8Array.from(atob(a),s=>s.charCodeAt(0));this.cryptoKey=await crypto.subtle.importKey("raw",i,{name:"AES-CBC"},!1,["encrypt","decrypt"])}async encryptCallbackName(t){await this.initCryptoKey();const e=crypto.getRandomValues(new Uint8Array(16)),n=new TextEncoder().encode(t),a=await crypto.subtle.encrypt({name:"AES-CBC",iv:e},this.cryptoKey,n),o=btoa(String.fromCharCode(...e)),i=btoa(String.fromCharCode(...new Uint8Array(a)));return`${o}:${i}`}createFetchOptions(t){return{method:"POST",headers:{"Content-Type":"application/json",HTTP_PP_WIRE_REQUEST:"true"},body:JSON.stringify(t)}}async fetchFunction(t,e={},n=!1){let a=null;try{n&&this.activeAbortController&&(this.activeAbortController.abort(),this.activeAbortController=null),a=new AbortController,n&&(this.activeAbortController=a);const i={callback:await this.encryptCallbackName(t),...e},s=window.location.href;let r;if(Object.keys(i).some(h=>{const l=i[h];return l instanceof File||l instanceof FileList&&l.length>0})){const h=new FormData;Object.keys(i).forEach(l=>{const f=i[l];f instanceof File?h.append(l,f):f instanceof FileList?Array.from(f).forEach(S=>h.append(l,S)):h.append(l,f)}),r={method:"POST",headers:{HTTP_PP_WIRE_REQUEST:"true"},body:h,signal:a.signal}}else r={signal:a.signal,...this.createFetchOptions(i)};const c=await fetch(s,r);if(!c.ok)throw new Error(`Fetch failed with status: ${c.status} ${c.statusText}`);const w=await c.text();a&&this.activeAbortController===a&&(this.activeAbortController=null);try{return JSON.parse(w)}catch{return w}}catch(o){if(a&&this.activeAbortController===a&&(this.activeAbortController=null),o instanceof Error&&o.name==="AbortError")return console.log("Request was cancelled"),{cancelled:!0};throw console.error("Error in fetchFunction:",o),new Error("Failed to fetch data.")}}}class u{state;static instance=null;listeners;pp;STORAGE_KEY;lastSyncedState=null;constructor(t={}){this.state=t,this.listeners=[],this.pp=m.getInstance(),this.STORAGE_KEY=this.getCookie("pp_local_store_key")||"pp_local_store_59e13",this.lastSyncedState=localStorage.getItem(this.STORAGE_KEY),this.loadState()}static getInstance(t={}){return u.instance||(u.instance=new u(t)),u.instance}getCookie(t){return document.cookie.split("; ").find(e=>e.startsWith(t+"="))?.split("=")[1]||null}setState(t,e=!1){const n={...this.state,...t};if(JSON.stringify(n)!==JSON.stringify(this.state)&&(this.state=n,this.listeners.forEach(a=>a(this.state)),this.saveState(),e)){const a=localStorage.getItem(this.STORAGE_KEY);a&&a!==this.lastSyncedState&&(this.pp.fetchFunction(this.STORAGE_KEY,{[this.STORAGE_KEY]:a}),this.lastSyncedState=a)}}saveState(){localStorage.setItem(this.STORAGE_KEY,JSON.stringify(this.state))}loadState(){const t=localStorage.getItem(this.STORAGE_KEY);t&&(this.state=JSON.parse(t),this.listeners.forEach(e=>e(this.state)))}resetState(t,e=!1){if(t?(delete this.state[t],this.saveState()):(this.state={},localStorage.removeItem(this.STORAGE_KEY)),this.listeners.forEach(n=>n(this.state)),e){const n=t?localStorage.getItem(this.STORAGE_KEY):null;this.pp.fetchFunction(this.STORAGE_KEY,{[this.STORAGE_KEY]:n}),this.lastSyncedState=n}}}class p{static instance=null;listeners=[];constructor(){}static getInstance(){return p.instance||(p.instance=new p),p.instance}get params(){return new URLSearchParams(window.location.search)}get(t){return this.params.get(t)}set(t,e){const n=this.params;n.set(t,e),this.updateURL(n)}delete(t){const e=this.params;e.delete(t),this.updateURL(e)}replace(t){const e=new URLSearchParams;for(const n in t){const a=t[n];a!==null&&e.set(n,a)}this.updateURL(e,!0)}updateURL(t,e=!1){const n=`${window.location.pathname}?${t.toString()}`;e?history.replaceState(null,"",n):history.pushState(null,"",n),this.notifyListeners(t)}listen(t){this.listeners.push(t)}notifyListeners(t){for(const e of this.listeners)e(t)}enablePopStateListener(){window.addEventListener("popstate",()=>{this.notifyListeners(this.params)})}}y("pp",m);y("store",u);y("searchParams",p);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-prisma-php-app",
3
- "version": "4.1.0-alpha.7",
3
+ "version": "4.1.0-alpha.8",
4
4
  "description": "Prisma-PHP: A Revolutionary Library Bridging PHP with Prisma ORM",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",