From c8e480e1f145ca1b7715fa187134bb67ff9aadbd Mon Sep 17 00:00:00 2001 From: Luc Kromer Date: Tue, 19 Aug 2025 12:43:22 +0200 Subject: [PATCH] fix($get): return containerPathCopy when path is empty Added a condition to handle empty, null, or undefined `path`. If `path` is one of ['', null, undefined], `$get` now returns `containerPathCopy` instead of containerPathCopy.path --- packages/schemas/dist/index.js | 2 +- packages/schemas/resources/js/index.js | 14 +++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/packages/schemas/dist/index.js b/packages/schemas/dist/index.js index 9625a3a690..464474e690 100644 --- a/packages/schemas/dist/index.js +++ b/packages/schemas/dist/index.js @@ -1 +1 @@ -(()=>{var m=()=>({isSticky:!1,init(){this.evaluatePageScrollPosition()},evaluatePageScrollPosition(){let n=this.$el.getBoundingClientRect(),e=n.top>window.innerHeight,i=n.topwindow.innerHeight;this.isSticky=e||i}});var c=function(n,e,i){let t=n;if(e.startsWith("/")&&(i=!0,e=e.slice(1)),i)return e;for(;e.startsWith("../");)t=t.includes(".")?t.slice(0,t.lastIndexOf(".")):null,e=e.slice(3);return["",null,void 0].includes(t)?e:`${t}.${e}`},w=n=>{let e=Alpine.findClosest(n,i=>i.__livewire);if(!e)throw"Could not find Livewire component in DOM tree.";return e.__livewire};document.addEventListener("alpine:init",()=>{window.Alpine.data("filamentSchema",({livewireId:n})=>({handleFormValidationError(e){e.detail.livewireId===n&&this.$nextTick(()=>{let i=this.$el.querySelector("[data-validation-error]");if(!i)return;let t=i;for(;t;)t.dispatchEvent(new CustomEvent("expand")),t=t.parentNode;setTimeout(()=>i.closest("[data-field-wrapper]").scrollIntoView({behavior:"smooth",block:"start",inline:"start"}),200)})}})),window.Alpine.data("filamentSchemaComponent",({path:n,containerPath:e,isLive:i,$wire:t})=>({$statePath:n,$get:(r,l)=>t.$get(c(e,r,l)),$set:(r,l,a,o=null)=>(o??(o=i),t.$set(c(e,r,a),l,o)),get $state(){return t.$get(n)}})),window.Alpine.data("filamentActionsSchemaComponent",m),Livewire.hook("commit",({component:n,commit:e,respond:i,succeed:t,fail:r})=>{t(({snapshot:l,effects:a})=>{a.dispatches?.forEach(o=>{if(!o.params?.awaitSchemaComponent)return;let s=Array.from(n.el.querySelectorAll(`[wire\\:partial="schema-component::${o.params.awaitSchemaComponent}"]`)).filter(d=>w(d)===n);if(s.length!==1){if(s.length>1)throw`Multiple schema components found with key [${o.params.awaitSchemaComponent}].`;window.addEventListener(`schema-component-${n.id}-${o.params.awaitSchemaComponent}-loaded`,()=>{window.dispatchEvent(new CustomEvent(o.name,{detail:o.params}))},{once:!0})}})})})});})(); +(()=>{var d=()=>({isSticky:!1,init(){this.evaluatePageScrollPosition()},evaluatePageScrollPosition(){let n=this.$el.getBoundingClientRect(),e=n.top>window.innerHeight,i=n.topwindow.innerHeight;this.isSticky=e||i}});var m=function(n,e,i){let t=n;if(e.startsWith("/")&&(i=!0,e=e.slice(1)),i)return e;for(;e.startsWith("../");)t=t.includes(".")?t.slice(0,t.lastIndexOf(".")):null,e=e.slice(3);return["",null,void 0].includes(t)?e:["",null,void 0].includes(e)?t:`${t}.${e}`},u=n=>{let e=Alpine.findClosest(n,i=>i.__livewire);if(!e)throw"Could not find Livewire component in DOM tree.";return e.__livewire};document.addEventListener("alpine:init",()=>{window.Alpine.data("filamentSchema",({livewireId:n})=>({handleFormValidationError(e){e.detail.livewireId===n&&this.$nextTick(()=>{let i=this.$el.querySelector("[data-validation-error]");if(!i)return;let t=i;for(;t;)t.dispatchEvent(new CustomEvent("expand")),t=t.parentNode;setTimeout(()=>i.closest("[data-field-wrapper]").scrollIntoView({behavior:"smooth",block:"start",inline:"start"}),200)})}})),window.Alpine.data("filamentSchemaComponent",({path:n,containerPath:e,isLive:i,$wire:t})=>({$statePath:n,$get:(r,l)=>t.$get(m(e,r,l)),$set:(r,l,a,o=null)=>(o??(o=i),t.$set(m(e,r,a),l,o)),get $state(){return t.$get(n)}})),window.Alpine.data("filamentActionsSchemaComponent",d),Livewire.hook("commit",({component:n,commit:e,respond:i,succeed:t,fail:r})=>{t(({snapshot:l,effects:a})=>{a.dispatches?.forEach(o=>{if(!o.params?.awaitSchemaComponent)return;let s=Array.from(n.el.querySelectorAll(`[wire\\:partial="schema-component::${o.params.awaitSchemaComponent}"]`)).filter(c=>u(c)===n);if(s.length!==1){if(s.length>1)throw`Multiple schema components found with key [${o.params.awaitSchemaComponent}].`;window.addEventListener(`schema-component-${n.id}-${o.params.awaitSchemaComponent}-loaded`,()=>{window.dispatchEvent(new CustomEvent(o.name,{detail:o.params}))},{once:!0})}})})})});})(); diff --git a/packages/schemas/resources/js/index.js b/packages/schemas/resources/js/index.js index 51db21bb01..82c09f57c6 100644 --- a/packages/schemas/resources/js/index.js +++ b/packages/schemas/resources/js/index.js @@ -24,6 +24,10 @@ const resolveRelativeStatePath = function (containerPath, path, isAbsolute) { return path } + if (['', null, undefined].includes(path)) { + return containerPathCopy + } + return `${containerPathCopy}.${path}` } @@ -38,7 +42,7 @@ const findClosestLivewireComponent = (el) => { } document.addEventListener('alpine:init', () => { - window.Alpine.data('filamentSchema', ({ livewireId }) => ({ + window.Alpine.data('filamentSchema', ({livewireId}) => ({ handleFormValidationError(event) { if (event.detail.livewireId !== livewireId) { return @@ -74,7 +78,7 @@ document.addEventListener('alpine:init', () => { window.Alpine.data( 'filamentSchemaComponent', - ({ path, containerPath, isLive, $wire }) => ({ + ({path, containerPath, isLive, $wire}) => ({ $statePath: path, $get: (path, isAbsolute) => { return $wire.$get( @@ -98,8 +102,8 @@ document.addEventListener('alpine:init', () => { window.Alpine.data('filamentActionsSchemaComponent', actions) - Livewire.hook('commit', ({ component, commit, respond, succeed, fail }) => { - succeed(({ snapshot, effects }) => { + Livewire.hook('commit', ({component, commit, respond, succeed, fail}) => { + succeed(({snapshot, effects}) => { effects.dispatches?.forEach((dispatch) => { if (!dispatch.params?.awaitSchemaComponent) { return @@ -128,7 +132,7 @@ document.addEventListener('alpine:init', () => { }), ) }, - { once: true }, + {once: true}, ) }) })