create-prisma-php-app 1.15.9 → 1.15.11
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.
|
@@ -38,14 +38,6 @@ class StateManager
|
|
|
38
38
|
return new \ArrayObject($this->state, \ArrayObject::ARRAY_AS_PROPS);
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
if (!array_key_exists($key, $this->state)) {
|
|
42
|
-
if ($initialValue !== null) {
|
|
43
|
-
$this->setState($key, $initialValue);
|
|
44
|
-
}
|
|
45
|
-
} elseif ($initialValue !== null && $this->state[$key] !== $initialValue) {
|
|
46
|
-
$this->setState($key, $this->state[$key]);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
41
|
$value = $this->state[$key] ?? $initialValue;
|
|
50
42
|
|
|
51
43
|
return is_array($value) ? new \ArrayObject($value, \ArrayObject::ARRAY_AS_PROPS) : $value;
|
|
@@ -59,6 +51,10 @@ class StateManager
|
|
|
59
51
|
*/
|
|
60
52
|
public function setState(string $key, mixed $value = null): void
|
|
61
53
|
{
|
|
54
|
+
if (array_key_exists($key, $GLOBALS)) {
|
|
55
|
+
$GLOBALS[$key] = $value;
|
|
56
|
+
}
|
|
57
|
+
|
|
62
58
|
$this->state[$key] = $value;
|
|
63
59
|
|
|
64
60
|
$this->notifyListeners();
|
package/dist/src/app/js/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var eventAttributes=["onclick","ondblclick","onmousedown","onmouseup","onmouseover","onmousemove","onmouseout","onwheel","onkeypress","onkeydown","onkeyup","onfocus","onblur","onchange","oninput","onselect","onsubmit","onreset","onresize","onscroll","onload","onunload","onabort","onerror","onbeforeunload","oncopy","oncut","onpaste","ondrag","ondragstart","ondragend","ondragover","ondragenter","ondragleave","ondrop","oncontextmenu","ontouchstart","ontouchmove","ontouchend","ontouchcancel","onpointerdown","onpointerup","onpointermove","onpointerover","onpointerout","onpointerenter","onpointerleave","onpointercancel"];document.addEventListener("DOMContentLoaded",attachWireFunctionEvents);const optimisticUpdates=new Map,state={checkedElements:new Set};function attachWireFunctionEvents(){handleHiddenAttribute();document.querySelectorAll("button, input, select, textarea, a, form, label, div, span").forEach((t=>{if(handleAnchorTag(t),eventAttributes.forEach((e=>{const n=t.getAttribute(e),o=e.slice(2);n&&(t.removeAttribute(e),handleDebounce(t,o,n))})),t instanceof HTMLFormElement){const e=t.getAttribute("onsubmit");e&&(t.removeAttribute("onsubmit"),handleDebounce(t,"submit",e))}}))}function handleHiddenAttribute(){document.querySelectorAll("[pp-hidden]").forEach((t=>{const e=t.getAttribute("pp-hidden");if(!e)return;const n=e.match(/^(\d+)(ms|s|m)?$/);if(n){const e=parseInt(n[1],10);let o;switch(n[2]||"ms"){case"ms":o=e;break;case"s":o=1e3*e;break;case"m":o=60*e*1e3;break;default:o=e}setTimeout((()=>{t.textContent=""}),o)}}))}async function handleDebounce(t,e,n){const o=t.getAttribute("pp-debounce"),a=t.getAttribute("pp-trigger"),s=async e=>{e.preventDefault();const o=saveOptimisticState(t);optimisticUpdates.set(t,o);try{a&&await invokeHandler(t,a),await invokeHandler(t,n)}catch(e){const n=optimisticUpdates.get(t);n&&revertOptimisticUpdate(t,n)}};if(o){const n=debounce(s,parseInt(o,10));t instanceof HTMLFormElement&&"submit"===e?t.addEventListener(e,(t=>{t.preventDefault(),n(t)})):t.addEventListener(e,n)}else t.addEventListener(e,s)}async function invokeHandler(t,e){try{const n=e.match(/^(\w+(\.\w+)*)\((.*)\)$/);if(n){const o=n[1],a=n[3],s=o.split("."),{context:c,methodName:r}=resolveContext(s);if("function"==typeof c[r]){const t=parseArguments(a);await c[r](...t)}else await handleParsedCallback(t,e)}else await handleParsedCallback(t,e)}catch(t){}}function resolveContext(t){let e=window;for(let n=0;n<t.length-1;n++)if(e=e[t[n]],!e)throw new Error(`Cannot find object ${t[n]} in the context.`);return{context:e,methodName:t[t.length-1]}}function parseArguments(t){return t?JSON.parse(`[${t}]`):[]}async function handleParsedCallback(t,e){const{funcName:n,data:o}=parseCallback(t,e);if(!n)return;const a=window[n];if("function"==typeof a){const t=Array.isArray(o.args)?o.args:[];await a(...t,o)}else await handleUndefinedFunction(n,o)}function extractStyles(t){const e={};for(let n=0;n<t.length;n++){const o=t[n];e[o]=t.getPropertyValue(o)}return e}function applyOptimisticUpdate(t,e){Object.entries(e.attributes).forEach((([e,n])=>{n?t.setAttribute(e,n):t.removeAttribute(e)})),Object.assign(t.style,e.styles),t.innerHTML=e.innerHTML||""}function revertOptimisticUpdate(t,e){"value"in e&&("checkbox"===t.type||"radio"===t.type?t.checked=!!e.value:t.value=e.value),"innerHTML"in e&&(t.innerHTML=e.innerHTML)}async function handleAnchorTag(t){t instanceof HTMLAnchorElement&&t.addEventListener("click",(t=>{const e=t.currentTarget,n=e.getAttribute("href"),o=e.getAttribute("target");if(!n||"_blank"===o||t.metaKey||t.ctrlKey)return;t.preventDefault();if(/^(https?:)?\/\//i.test(n)&&!n.startsWith(window.location.origin))window.location.href=n;else try{history.pushState(null,"",n),window.dispatchEvent(new PopStateEvent("popstate",{state:null}))}catch(t){}}))}function updateDocumentContent(t){if(t.includes("<!DOCTYPE html>")){const e=(new DOMParser).parseFromString(t,"text/html");document.replaceChild(document.adoptNode(e.documentElement),document.documentElement)}else{saveState();const e=saveScrollPositions(),n=(new DOMParser).parseFromString(t,"text/html"),o=Array.from(n.body.querySelectorAll("script")),a=n.body;diffAndPatch(document.body,a),restoreState(),restoreScrollPositions(e),o.forEach((t=>{if(t.src)loadScript(t.src);else{const e=document.createElement("script");e.textContent=t.textContent,document.body.appendChild(e),document.body.removeChild(e)}}))}attachWireFunctionEvents()}function diffAndPatch(t,e){t.nodeType===e.nodeType?t.nodeType!==Node.TEXT_NODE||e.nodeType!==Node.TEXT_NODE?t instanceof HTMLElement&&e instanceof HTMLElement&&t.replaceWith(e):t.textContent!==e.textContent&&(t.textContent=e.textContent):t.parentNode?.replaceChild(e,t)}function updateAttributes(t,e){Array.from(e.attributes).forEach((e=>{t.getAttribute(e.name)!==e.value&&t.setAttribute(e.name,e.value)})),Array.from(t.attributes).forEach((n=>{e.hasAttribute(n.name)||t.removeAttribute(n.name)}))}function updateChildren(t,e){const n=t.childNodes,o=e.childNodes,a=Math.max(n.length,o.length);for(let e=0;e<a;e++){const a=n[e],s=o[e];a?s?diffAndPatch(a,s):t.removeChild(a):t.appendChild(s)}}function loadScript(t){const e=document.createElement("script");e.src=t,document.head.appendChild(e)}function saveState(){const t=document.activeElement;state.focusId=t?.id||t?.name,state.focusValue=t?.value,state.focusSelectionStart=t?.selectionStart,state.focusSelectionEnd=t?.selectionEnd,state.checkedElements.clear(),document.querySelectorAll('input[type="checkbox"]:checked').forEach((t=>{state.checkedElements.add(t.id||t.name)}))}function restoreState(){if(state.focusId){const t=document.getElementById(state.focusId)||document.querySelector(`[name="${state.focusId}"]`);t instanceof HTMLInputElement&&(t.focus(),"search"===t.type&&(t.value=state.focusValue||""),void 0!==state.focusSelectionStart&&null!==state.focusSelectionEnd&&t.setSelectionRange(state.focusSelectionStart||null,state.focusSelectionEnd||null))}state.checkedElements.forEach((t=>{const e=document.getElementById(t);e&&(e.checked=!0)}))}function saveScrollPositions(){const t={};return document.querySelectorAll("*").forEach((e=>{(e.scrollTop||e.scrollLeft)&&(t[getElementKey(e)]={scrollTop:e.scrollTop,scrollLeft:e.scrollLeft})})),t}function restoreScrollPositions(t){document.querySelectorAll("*").forEach((e=>{const n=getElementKey(e);t[n]&&(e.scrollTop=t[n].scrollTop,e.scrollLeft=t[n].scrollLeft)}))}function getElementKey(t){return t.id||t.className||t.tagName}function parseCallback(t,e){let n={};const o=t.closest("form");if(o){new FormData(o).forEach(((t,e)=>{n[e]?Array.isArray(n[e])?n[e].push(t):n[e]=[n[e],t]:n[e]=t}))}else t instanceof HTMLInputElement?n=handleInputElement(t):(t instanceof HTMLSelectElement||t instanceof HTMLTextAreaElement)&&(n[t.name]=t.value);const a=e.match(/(\w+)\((.*)\)/);if(a){const t=a[1];let e=a[2].trim();if(e.startsWith("{")&&e.endsWith("}")){const t=e.replace(/'/g,'"');try{const e=JSON.parse(t);"object"==typeof e&&null!==e&&(n={...n,...e})}catch(t){}}else{const t=e.split(/,(?=(?:[^'"]*['"][^'"]*['"])*[^'"]*$)/).map((t=>t.trim().replace(/^['"]|['"]$/g,"")));n.args=t}return{funcName:t,data:n}}return{funcName:e,data:n}}function handleInputElement(t){let e={};return t.name?"checkbox"===t.type||"radio"===t.type?e[t.name]=t.checked:e[t.name]=t.value:"checkbox"===t.type||"radio"===t.type?e.value=t.checked:e.value=t.value,e}function captureState(t){const e={};for(const n of t.attributes)e[n.name]=n.value;return{attributes:e,styles:extractStyles(window.getComputedStyle(t)),innerHTML:t.innerHTML||""}}async function handleUndefinedFunction(t,e){const n={callback:t,...e},o={method:"POST",headers:{"Content-Type":"application/json","X-Requested-With":"XMLHttpRequest",HTTP_PPHP_WIRE_REQUEST:"true"},body:JSON.stringify(n)},a={method:"POST",headers:{"Content-Type":"application/json","X-Requested-With":"XMLHttpRequest",HTTP_PPHP_WIRE_REQUEST:"true"},body:JSON.stringify({secondRequest:!0})},s=async t=>{const e=await fetch(window.location.pathname,t);return await e.text()};try{const t=await s(o),e=await s(a);if(t.includes("redirect_7F834=")){const e=t.split("=")[1];await handleRedirect(e)}else{updateDocumentContent(t+e)}}catch(t){revertOptimisticUpdate(document.body,captureState(document.body))}}function saveOptimisticState(t){return{value:t.value||t.checked||"",attributes:Array.from(t.attributes).reduce(((t,e)=>(t[e.name]=e.value,t)),{}),styles:extractStyles(window.getComputedStyle(t)),innerHTML:t.innerHTML}}async function handleRedirect(t){if(t){history.pushState(null,"",t),window.dispatchEvent(new PopStateEvent("popstate",{state:null}));try{const e=await fetch(t,{headers:{"X-Requested-With":"XMLHttpRequest"}});updateDocumentContent(await e.text())}catch(t){}}}function debounce(t,e=300,n=!1){let o;return function(...a){const s=this;o&&clearTimeout(o),o=setTimeout((()=>{o=null,n||t.apply(s,a)}),e),n&&!o&&t.apply(s,a)}}function copyCode(t,e,n,o,a=2e3){const s=t.closest(`.${e}`)?.querySelector("pre code"),c=s?.textContent?.trim()||"";c?navigator.clipboard.writeText(c).then((()=>{const e=t.querySelector("i");e&&(e.className=o),setTimeout((()=>{e&&(e.className=n)}),a)}),(()=>{alert("Failed to copy command to clipboard")})):alert("Failed to find the code block to copy")}window.addEventListener("popstate",(async()=>{try{const t=await fetch(window.location.href,{headers:{"X-Requested-With":"XMLHttpRequest"}});updateDocumentContent(await t.text())}catch(t){}}));let api=null;if(void 0===api){class t{static instance=null;baseURL;constructor(t=window.location.origin){this.baseURL=t}static getInstance(e=window.location.origin){return t.instance||(t.instance=new t(e)),t.instance}async request(t,e,n=null,o={}){let a=`${this.baseURL}${e}`;const s={method:t,headers:{"Content-Type":"application/json","X-Requested-With":"XMLHttpRequest",...o}};if(n)if("GET"===t){a+=`?${new URLSearchParams(n).toString()}`}else"HEAD"!==t&&"OPTIONS"!==t&&(s.body=JSON.stringify(n));try{const e=await fetch(a,s);if("HEAD"===t)return e.headers;const n=e.headers.get("content-type");return n&&n.includes("application/json")?await e.json():await e.text()}catch(t){throw t}}get(t,e,n){return this.request("GET",t,e,n)}post(t,e,n){return this.request("POST",t,e,n)}put(t,e,n){return this.request("PUT",t,e,n)}delete(t,e,n){return this.request("DELETE",t,e,n)}patch(t,e,n){return this.request("PATCH",t,e,n)}head(t,e){return this.request("HEAD",t,null,e)}options(t,e){return this.request("OPTIONS",t,null,e)}}api=t.getInstance()}let store=null;if(void 0===store){class t{static instance=null;state;listeners;constructor(t={}){this.state=t,this.listeners=[]}static getInstance(e={}){return t.instance||(t.instance=new t(e),t.instance.loadState()),t.instance}setState(t,e=!1){this.state={...this.state,...t},this.listeners.forEach((t=>t(this.state))),e&&this.saveState()}subscribe(t){return this.listeners.push(t),t(this.state),()=>{this.listeners=this.listeners.filter((e=>e!==t))}}saveState(){localStorage.setItem("appState",JSON.stringify(this.state))}loadState(){const t=localStorage.getItem("appState");t&&(this.state=JSON.parse(t),this.listeners.forEach((t=>t(this.state))))}resetState(t=!1){this.state={},this.listeners.forEach((t=>t(this.state))),t&&localStorage.removeItem("appState")}}store=t.getInstance()}
|
|
1
|
+
"use strict";var eventAttributes=["onclick","ondblclick","onmousedown","onmouseup","onmouseover","onmousemove","onmouseout","onwheel","onkeypress","onkeydown","onkeyup","onfocus","onblur","onchange","oninput","onselect","onsubmit","onreset","onresize","onscroll","onload","onunload","onabort","onerror","onbeforeunload","oncopy","oncut","onpaste","ondrag","ondragstart","ondragend","ondragover","ondragenter","ondragleave","ondrop","oncontextmenu","ontouchstart","ontouchmove","ontouchend","ontouchcancel","onpointerdown","onpointerup","onpointermove","onpointerover","onpointerout","onpointerenter","onpointerleave","onpointercancel"];document.addEventListener("DOMContentLoaded",attachWireFunctionEvents);const optimisticUpdates=new Map,state={checkedElements:new Set};function attachWireFunctionEvents(){handleHiddenAttribute();document.querySelectorAll("button, input, select, textarea, a, form, label, div, span").forEach((e=>{if(handleAnchorTag(e),eventAttributes.forEach((t=>{const n=e.getAttribute(t),o=t.slice(2);n&&(e.removeAttribute(t),handleDebounce(e,o,n))})),e instanceof HTMLFormElement){const t=e.getAttribute("onsubmit");t&&(e.removeAttribute("onsubmit"),handleDebounce(e,"submit",t))}}))}function handleHiddenAttribute(){document.querySelectorAll("[pp-hidden]").forEach((e=>{let t=e.getAttribute("pp-hidden");if(t)if(isJsonLike(t))try{t=t.replace(/'/g,'"');handleElementVisibility(e,JSON.parse(t))}catch(e){}else{const n=parseTime(t);n>0&&scheduleVisibilityChange(e,n,"hidden")}}))}function isJsonLike(e){return e.trim().startsWith("{")&&e.trim().endsWith("}")}function handleElementVisibility(e,t){const n=t.start?parseTime(t.start):0,o=t.end?parseTime(t.end):0;n>0?(e.style.visibility="hidden",scheduleVisibilityChange(e,n,"visible"),o>0&&scheduleVisibilityChange(e,n+o,"hidden")):o>0&&scheduleVisibilityChange(e,o,"hidden")}function scheduleVisibilityChange(e,t,n){setTimeout((()=>{requestAnimationFrame((()=>{e.style.visibility=n}))}),t)}function parseTime(e){if("number"==typeof e)return e;const t=e.match(/^(\d+)(ms|s|m)?$/);if(t){const e=parseInt(t[1],10);switch(t[2]||"ms"){case"ms":return e;case"s":return 1e3*e;case"m":return 60*e*1e3;default:return e}}return 0}async function handleDebounce(e,t,n){const o=e.getAttribute("pp-debounce"),a=e.getAttribute("pp-trigger"),s=async t=>{t.preventDefault();const o=saveOptimisticState(e);optimisticUpdates.set(e,o);try{a&&await invokeHandler(e,a),await invokeHandler(e,n)}catch(t){const n=optimisticUpdates.get(e);n&&revertOptimisticUpdate(e,n)}};if(o){const n=debounce(s,parseTime(o));e instanceof HTMLFormElement&&"submit"===t?e.addEventListener(t,(e=>{e.preventDefault(),n(e)})):e.addEventListener(t,n)}else e.addEventListener(t,s)}async function invokeHandler(e,t){try{const n=t.match(/^(\w+(\.\w+)*)\((.*)\)$/);if(n){const o=n[1],a=n[3],s=o.split("."),{context:c,methodName:i}=resolveContext(s);if("function"==typeof c[i]){const e=parseArguments(a);await c[i](...e)}else await handleParsedCallback(e,t)}else await handleParsedCallback(e,t)}catch(e){}}function resolveContext(e){let t=window;for(let n=0;n<e.length-1;n++)if(t=t[e[n]],!t)throw new Error(`Cannot find object ${e[n]} in the context.`);return{context:t,methodName:e[e.length-1]}}function parseArguments(e){return e?JSON.parse(`[${e}]`):[]}async function handleParsedCallback(e,t){const{funcName:n,data:o}=parseCallback(e,t);if(!n)return;const a=window[n];if("function"==typeof a){const e=Array.isArray(o.args)?o.args:[];await a(...e,o)}else await handleUndefinedFunction(e,n,o)}function extractStyles(e){const t={};for(let n=0;n<e.length;n++){const o=e[n];t[o]=e.getPropertyValue(o)}return t}function applyOptimisticUpdate(e,t){Object.entries(t.attributes).forEach((([t,n])=>{n?e.setAttribute(t,n):e.removeAttribute(t)})),Object.assign(e.style,t.styles),e.innerHTML=t.innerHTML||""}function revertOptimisticUpdate(e,t){"value"in t&&("checkbox"===e.type||"radio"===e.type?e.checked=!!t.value:e.value=t.value),"innerHTML"in t&&(e.innerHTML=t.innerHTML)}async function handleAnchorTag(e){e instanceof HTMLAnchorElement&&e.addEventListener("click",(e=>{const t=e.currentTarget,n=t.getAttribute("href"),o=t.getAttribute("target");if(!n||"_blank"===o||e.metaKey||e.ctrlKey)return;e.preventDefault();if(/^(https?:)?\/\//i.test(n)&&!n.startsWith(window.location.origin))window.location.href=n;else try{history.pushState(null,"",n),window.dispatchEvent(new PopStateEvent("popstate",{state:null}))}catch(e){}}))}function updateDocumentContent(e){if(e.includes("<!DOCTYPE html>")){const t=(new DOMParser).parseFromString(e,"text/html");document.replaceChild(document.adoptNode(t.documentElement),document.documentElement)}else{saveState();const t=saveScrollPositions(),n=(new DOMParser).parseFromString(e,"text/html"),o=Array.from(n.body.querySelectorAll("script")),a=n.body;diffAndPatch(document.body,a),restoreState(),restoreScrollPositions(t),o.forEach((e=>{if(e.src)loadScript(e.src);else{const t=document.createElement("script");t.textContent=e.textContent,document.body.appendChild(t),document.body.removeChild(t)}}))}attachWireFunctionEvents()}function diffAndPatch(e,t){e.nodeType===t.nodeType?e.nodeType!==Node.TEXT_NODE||t.nodeType!==Node.TEXT_NODE?e instanceof HTMLElement&&t instanceof HTMLElement&&e.replaceWith(t):e.textContent!==t.textContent&&(e.textContent=t.textContent):e.parentNode?.replaceChild(t,e)}function updateAttributes(e,t){Array.from(t.attributes).forEach((t=>{e.getAttribute(t.name)!==t.value&&e.setAttribute(t.name,t.value)})),Array.from(e.attributes).forEach((n=>{t.hasAttribute(n.name)||e.removeAttribute(n.name)}))}function updateChildren(e,t){const n=e.childNodes,o=t.childNodes,a=Math.max(n.length,o.length);for(let t=0;t<a;t++){const a=n[t],s=o[t];a?s?diffAndPatch(a,s):e.removeChild(a):e.appendChild(s)}}function loadScript(e){const t=document.createElement("script");t.src=e,document.head.appendChild(t)}function saveState(){const e=document.activeElement;state.focusId=e?.id||e?.name,state.focusValue=e?.value,state.focusSelectionStart=e?.selectionStart,state.focusSelectionEnd=e?.selectionEnd,state.checkedElements.clear(),document.querySelectorAll('input[type="checkbox"]:checked').forEach((e=>{state.checkedElements.add(e.id||e.name)}))}function restoreState(){if(state.focusId){const e=document.getElementById(state.focusId)||document.querySelector(`[name="${state.focusId}"]`);e instanceof HTMLInputElement&&(e.focus(),"search"===e.type&&(e.value=state.focusValue||""),void 0!==state.focusSelectionStart&&null!==state.focusSelectionEnd&&e.setSelectionRange(state.focusSelectionStart||null,state.focusSelectionEnd||null))}state.checkedElements.forEach((e=>{const t=document.getElementById(e);t&&(t.checked=!0)}))}function saveScrollPositions(){const e={};return document.querySelectorAll("*").forEach((t=>{(t.scrollTop||t.scrollLeft)&&(e[getElementKey(t)]={scrollTop:t.scrollTop,scrollLeft:t.scrollLeft})})),e}function restoreScrollPositions(e){document.querySelectorAll("*").forEach((t=>{const n=getElementKey(t);e[n]&&(t.scrollTop=e[n].scrollTop,t.scrollLeft=e[n].scrollLeft)}))}function getElementKey(e){return e.id||e.className||e.tagName}async function pphpFetch(e,t){const n=await fetch(e,{...t,headers:{...t?.headers,"X-Requested-With":"XMLHttpRequest"}});return await n.text()}function parseCallback(e,t){let n={};const o=e.closest("form");if(o){new FormData(o).forEach(((e,t)=>{n[t]?Array.isArray(n[t])?n[t].push(e):n[t]=[n[t],e]:n[t]=e}))}else e instanceof HTMLInputElement?n=handleInputElement(e):(e instanceof HTMLSelectElement||e instanceof HTMLTextAreaElement)&&(n[e.name]=e.value);const a=t.match(/(\w+)\((.*)\)/);if(a){const e=a[1];let t=a[2].trim();if(t.startsWith("{")&&t.endsWith("}")){const e=t.replace(/'/g,'"');try{const t=JSON.parse(e);"object"==typeof t&&null!==t&&(n={...n,...t})}catch(e){}}else{const e=t.split(/,(?=(?:[^'"]*['"][^'"]*['"])*[^'"]*$)/).map((e=>e.trim().replace(/^['"]|['"]$/g,"")));n.args=e}return{funcName:e,data:n}}return{funcName:t,data:n}}function handleInputElement(e){let t={};return e.name?"checkbox"===e.type||"radio"===e.type?t[e.name]=e.checked:t[e.name]=e.value:"checkbox"===e.type||"radio"===e.type?t.value=e.checked:t.value=e.value,t}function captureState(e){const t={};for(const n of e.attributes)t[n.name]=n.value;return{attributes:t,styles:extractStyles(window.getComputedStyle(e)),innerHTML:e.innerHTML||""}}async function handleSuspenseElement(e){let t=e.getAttribute("pp-suspense")||"";if(t&&isJsonLike(t))try{(t=>{for(const n in t)if(t.hasOwnProperty(n))switch(n){case"innerHTML":case"textContent":e[n]=t[n];break;case"classList.add":e.classList.add(t[n]);break;case"classList.remove":e.classList.remove(t[n]);break;case"classList.toggle":e.classList.toggle(t[n]);break;case"classList.replace":const[o,a]=t[n].split(",");e.classList.replace(o,a);break;case"value":e.value=t[n];break;case"style":Object.assign(e.style,t[n]);break;default:e.setAttribute(n,t[n]);break}})(JSON.parse(t.replace(/'/g,'"')))}catch(e){}else t&&(e.textContent=t)}async function handleUndefinedFunction(e,t,n){handleSuspenseElement(e);const o={callback:t,...n},a={method:"POST",headers:{"Content-Type":"application/json",HTTP_PPHP_WIRE_REQUEST:"true"},body:JSON.stringify(o)},s={method:"POST",headers:{"Content-Type":"application/json",HTTP_PPHP_WIRE_REQUEST:"true"},body:JSON.stringify({secondRequest:!0})};try{const e=window.location.pathname,t=await pphpFetch(e,a),n=await pphpFetch(e,s);if(t.includes("redirect_7F834=")){const e=t.split("=")[1];await handleRedirect(e)}else{updateDocumentContent(t+n)}}catch(e){revertOptimisticUpdate(document.body,captureState(document.body))}}function saveOptimisticState(e){return{value:e.value||e.checked||"",attributes:Array.from(e.attributes).reduce(((e,t)=>(e[t.name]=t.value,e)),{}),styles:extractStyles(window.getComputedStyle(e)),innerHTML:e.innerHTML}}async function handleRedirect(e){if(e){history.pushState(null,"",e),window.dispatchEvent(new PopStateEvent("popstate",{state:null}));try{const t=await fetch(e,{headers:{"X-Requested-With":"XMLHttpRequest"}});updateDocumentContent(await t.text())}catch(e){}}}function debounce(e,t=300,n=!1){let o;return function(...a){const s=this;o&&clearTimeout(o),o=setTimeout((()=>{o=null,n||e.apply(s,a)}),t),n&&!o&&e.apply(s,a)}}function copyCode(e,t,n,o,a=2e3){const s=e.closest(`.${t}`)?.querySelector("pre code"),c=s?.textContent?.trim()||"";c?navigator.clipboard.writeText(c).then((()=>{const t=e.querySelector("i");t&&(t.className=o),setTimeout((()=>{t&&(t.className=n)}),a)}),(()=>{alert("Failed to copy command to clipboard")})):alert("Failed to find the code block to copy")}window.addEventListener("popstate",(async()=>{try{updateDocumentContent(await pphpFetch(window.location.href))}catch(e){}}));let store=null;if(void 0===store){class e{static instance=null;state;listeners;constructor(e={}){this.state=e,this.listeners=[]}static getInstance(t={}){return e.instance||(e.instance=new e(t),e.instance.loadState()),e.instance}setState(e,t=!1){this.state={...this.state,...e},this.listeners.forEach((e=>e(this.state))),t&&this.saveState()}subscribe(e){return this.listeners.push(e),e(this.state),()=>{this.listeners=this.listeners.filter((t=>t!==e))}}saveState(){localStorage.setItem("appState",JSON.stringify(this.state))}loadState(){const e=localStorage.getItem("appState");e&&(this.state=JSON.parse(e),this.listeners.forEach((e=>e(this.state))))}resetState(e=!1){this.state={},this.listeners.forEach((e=>e(this.state))),e&&localStorage.removeItem("appState")}}store=e.getInstance()}
|