@hammerstone/refine-stimulus
Advanced tools
Comparing version 2.2.0 to 2.2.1
@@ -1,2 +0,2 @@ | ||
import{Controller as t}from"@hotwired/stimulus";import{delegate as e,abnegate as i}from"jquery-events-to-dom-events";import{debounce as n}from"lodash";function r(t){const e=(t.match(/^(?:\.\/)?(.+)(?:[_-]controller\..+?)$/)||[])[1];if(e)return e.replace(/_/g,"-").replace(/\//g,"--")}class s extends t{connect(){console.log("Form Controller Connected"),this.state=this.getStateController(),this.blueprintInput=this.addHiddenInput("blueprint"),this.addHiddenInput("filter",this.state.filterName),this.addHiddenInput("id_suffix",this.state.idSuffix),this.finishUpdate()}getStateController(){let t=this.element;for(;t!==document.body;){const e=this.application.getControllerForElementAndIdentifier(t,"refine--state");if(e)return e;t=t.parentNode}return null}addHiddenInput(t,e){const i=document.createElement("input");return i.type="hidden",i.name=t,i.value=e||"",this.element.appendChild(i),i}finishUpdate(){this.state.finishUpdate()}startUpdate(){this.blueprintInput.value=JSON.stringify(this.state.blueprint),this.state.startUpdate()}submitForm(){this.startUpdate(),this.element.requestSubmit()}}class a extends s{criterion(){this.state.addCriterion(this.previousCriterionIdValue),this.startUpdate()}group(){this.state.addGroup(),this.startUpdate()}}a.values={previousCriterionId:Number};class l extends t{connect(){this.state=this.getStateController(),this.state.updateInput(this.criterionIdValue,this.inputValue)}getStateController(){let t=this.element;for(;t!==document.body;){const e=this.application.getControllerForElementAndIdentifier(t,"refine--state");if(e)return e;t=t.parentNode}return null}}l.values={criterionId:Number,input:Object};class o extends s{criterion(){const{state:t,criterionIdValue:e}=this;t.deleteCriterion(e),this.startUpdate()}}o.values={criterionId:Number};class d extends t{connect(){console.log("Seacrch filter connected!");const t=new URLSearchParams(window.location.search);this.existingParams=t,this.existingParams.delete("stable_id")}search(t){console.log("search!"),t.preventDefault(),this.submitFilter(),document.activeElement.blur()}submitFilter(){try{const t=this,{blueprint:e}=t.stateController;return Promise.resolve(t.stabilizeFilterController.validateBlueprint(e)).then(function(i){console.log("validationResult",i),i.stableId?t.redirectToStableId(i.stableId):t.fetchAndRenderInvalidFilter(e)})}catch(t){return Promise.reject(t)}}addHiddenInput(t){let{name:e,value:i}=t;const n=document.createElement("input");n.type="hidden",n.name=e,n.value=i,this.submissionFormTarget.appendChild(n)}get stateController(){return this.element.querySelector('[data-controller~="refine--state"]').refineStateController}get stabilizeFilterController(){return this.element.stabilizeFilterController}redirectToStableId(t){const e=new URLSearchParams;t&&e.append("stable_id",t);const i=new URLSearchParams({...Object.fromEntries(this.existingParams),...Object.fromEntries(e)}).toString(),n=window.location.pathname+"?"+i;history.pushState({},document.title,n),window.location.reload()}fetchAndRenderInvalidFilter(t){try{var e;const i=this;return console.log("this.submitUrlValue",i.submitUrlValue),Promise.resolve(fetch(i.submitUrlValue,{headers:{Accept:"application/json","Content-Type":"application/json","X-CSRF-Token":null==(e=document.querySelector("meta[name='csrf-token']"))?void 0:e.content},method:"POST",body:JSON.stringify({filter:i.stateController.filterName,blueprint:JSON.stringify(t),id_suffix:i.stateController.idSuffix})})).then(function(t){return Promise.resolve(t.json()).then(function(t){document.getElementById(t.target).outerHTML=t.template})})}catch(t){return Promise.reject(t)}}}d.values={submitUrl:String},d.targets=[],function(){if("function"==typeof window.CustomEvent)return!1;function t(t,e){e=e||{bubbles:!1,cancelable:!1,detail:void 0};var i=document.createEvent("CustomEvent");return i.initCustomEvent(t,e.bubbles,e.cancelable,e.detail),i}t.prototype=window.Event.prototype,window.CustomEvent=t}();const u=(t,e,i,n)=>{const r=new CustomEvent("filter-stabilized",{bubbles:!0,cancelable:!0,detail:{stableId:e,filterName:i,initialLoad:n}});t.dispatchEvent(r)},c=(t,e)=>{const i=new CustomEvent("blueprint-updated",{bubbles:!0,cancelable:!0,detail:{blueprint:e}});t.dispatchEvent(i)},h=(t,e,i)=>{const{meta:n,refinements:r,component:s}=i,{clauses:a,options:l}=n;let o={clause:a[0].id,selected:"option-condition"===s?[l[0].id]:void 0};return r.forEach(t=>{var e;const{meta:i,component:n}=t,{clauses:r,options:s}=i;o[t.id]={clause:r[0].id,selected:"option-condition"===n?[null==(e=s[0])?void 0:e.id]:void 0}}),{depth:e,type:"criterion",condition_id:t,input:o}};class p extends t{connect(){this.element.refineStateController=this,this.changeDelegate=e("change",["event","picker"]),this.blueprint=this.blueprintValue,this.conditions=this.conditionsValue,this.filterName=this.classNameValue,this.idSuffix=this.idSuffixValue,this.stableId=this.stableIdValue,this.conditionsLookup=this.conditions.reduce((t,e)=>(t[e.id]=e,t),{}),this.loadingTimeout=null,c(this.element,this.blueprint)}disconnect(){i("change",this.changeDelegate)}startUpdate(){this.loadingTimeout&&window.clearTimeout(this.loadingTimeout),this.loadingTimeout=window.setTimeout(()=>{document.activeElement.blur(),this.loadingTarget.classList.remove("hidden")},1e3)}finishUpdate(){this.loadingTimeout&&window.clearTimeout(this.loadingTimeout),this.loadingTarget.classList.add("hidden")}conditionConfigFor(t){return this.conditionsLookup[t]}updateStableId(t){t!==this.stableId&&(this.stableId=t)}addGroup(){const{conditions:t}=this,e=t[0];var i;this.blueprint.length>0&&this.blueprint.push({depth:i=void 0===i?0:i,type:"conjunction",word:"or"}),this.blueprint.push(h(e.id,1,e)),c(this.element,this.blueprint)}addCriterion(t){const{blueprint:e,conditions:i}=this,n=i[0];var r;e.splice(t+1,0,{depth:r=void 0===r?1:r,type:"conjunction",word:"and"},h(n.id,1,n)),c(this.element,this.blueprint)}deleteCriterion(t){const{blueprint:e}=this,i=e[t-1],n=e[t+1],r=i&&"or"===i.word,s=n&&"or"===n.word||!n,a=r||!i,l=a&&s;if(i||n?e.splice(l&&r?t-1:l&&!i||a&&!s?t:t-1,2):this.blueprint=[],0===this.blueprint.length){const t=this.conditions[0];this.blueprint.push(h(t.id,1,t))}c(this.element,this.blueprint)}replaceCriterion(t,e,i){const n=this.blueprint[t];if("criterion"!==n.type)throw new Error("You can't call updateConditionId on a non-criterion type. Trying to update "+JSON.stringify(h));this.blueprint[t]=h(e,n.depth,i),c(this.element,this.blueprint)}updateInput(t,e,i){const{blueprint:n}=this,r=n[t],s=(i=i||"input").split(", ");s.length>1?r[s[0]][s[1]]={...r[s[0]][s[1]],...e}:r[i]={...r[i],...e},c(this.element,this.blueprint)}}p.values={blueprint:Array,conditions:Array,className:String,stableId:String,idSuffix:String},p.targets=["loading"];class b extends t{connect(){this.idValue&&(t=>{const e=new CustomEvent("filter-stored",{bubbles:!0,cancelable:!0,detail:{storedFilterId:this.idValue}});window.dispatchEvent(e)})()}updateStableIdField(t){if(t.detail.filterName!=this.filterNameValue)return null;if(this.hasStableIdFieldTarget){const{detail:e}=t,{stableId:i}=e;this.stableIdFieldTarget.value=i}}activateSaveLink(t){const{detail:e}=t,{stableId:i,initialLoad:n}=e;if(t.detail.filterName!=this.filterNameValue)return null;if(this.hasEnabledSaveLinkTarget&&this.hasDisabledSaveLinkTarget&&!n){const t=new URL(this.enabledSaveLinkTarget.href);t.searchParams.set("stable_id",i),this.enabledSaveLinkTarget.setAttribute("href",t),this.disabledSaveLinkTarget.classList.add("hidden"),this.enabledSaveLinkTarget.classList.remove("hidden")}}}b.targets=["enabledSaveLink","disabledSaveLink","stableIdField"],b.values={id:Number,stableId:String,filterName:String};class m extends t{connect(){this.element.stabilizeFilterController=this,this.stableIdValue=new URLSearchParams(window.location.search).get("stable_id")}updateStableId(t){try{const e=this;(t=>{const e=new CustomEvent("filter-unstable",{bubbles:!0,cancelable:!0,detail:{blueprint:t}});window.dispatchEvent(e)})(e.blueprint);const i=t.detail.blueprint;return Promise.resolve(e.validateBlueprint(i)).then(function(t){if(t.stableId)e.stableIdValue=t.stableId,u(e.element,e.stableIdValue,e.filterNameValue),u(window,e.stableIdValue,e.filterNameValue);else{const{errors:e}=t;(t=>{let{blueprint:e,errors:i}=t;const n=new CustomEvent("filter-invalid",{bubbles:!0,cancelable:!0,detail:{blueprint:e,errors:i}});window.dispatchEvent(n)})({blueprint:i,errors:e})}})}catch(t){return Promise.reject(t)}}validateBlueprint(t){try{var e;const i=this;let n=JSON.stringify({blueprint:t,filter:i.filterNameValue}),r=null==(e=document.querySelector("meta[name='csrf-token']"))?void 0:e.content;return Promise.resolve(fetch(i.updateStableIdUrlValue,{method:"PUT",body:n,headers:{accept:"application/json","content-type":"application/json","X-CSRF-Token":r}})).then(function(t){return Promise.resolve(t.json()).then(function(e){return t.ok?{stableId:e.filter_id}:{errors:e.errors}})})}catch(t){return Promise.reject(t)}}}m.values={stableId:String,updateStableIdUrl:String,filterName:String},m.targets=[];class f extends s{initialize(){this.updateBlueprint=n((t,e,i)=>{this.value(t,e,i),this.createStableId(this.state.blueprint,this.state.filterName)},500)}connect(){s.prototype.connect.apply(this),this.state.updateStableId(this.stableIdValue)}refinedFilter(t){const{criterionIdValue:e,state:i}=this;i.updateInput(e,{id:t.target.value},t.target.dataset.inputId),this.submitForm()}clause(t){const{criterionIdValue:e,state:i}=this;i.updateInput(e,{clause:t.target.value},t.target.dataset.inputId),this.submitForm()}selected(t){const{target:e}=t,i=Array.prototype.slice.call(e.options).filter(t=>t.selected).map(t=>t.value);this.value(t,i,"selected"),this.createStableId(this.state.blueprint,this.state.filterName)}value(t,e,i){const{criterionIdValue:n,state:r}=this,s=t.target.dataset;r.updateInput(n,{[i=i||s.inputKey||"value"]:e=e||t.target.value},s.inputId)}date(t){const{picker:e}=t.detail,i=e.startDate.format("YYYY-MM-DD");this.value(t,i),this.submitForm()}createStableId(t,e){var i;const{state:n}=this;let r=JSON.stringify({blueprint:t,filter:e}),s=null==(i=document.querySelector("meta[name='csrf-token']"))?void 0:i.content;$.ajax({type:"PUT",url:"/hammerstone/update_stable_id",data:r,headers:{accept:"application/json","content-type":"application/json","X-CSRF-Token":s},success:function(t){n.updateStableId(t.filter_id)}})}condition(t){const{criterionIdValue:e,state:i}=this,n=t.target.value,r=this.state.conditionConfigFor(n);i.replaceCriterion(e,n,r),this.submitForm()}cancelEnter(t){"Enter"===t.code&&(t.preventDefault(),t.stopPropagation())}}f.values={criterionId:Number,stableId:String};const v=[[a,"refine/add-controller.js"],[l,"refine/defaults-controller.js"],[o,"refine/delete-controller.js"],[s,"refine/form-controller.js"],[d,"refine/search-filter-controller.js"],[p,"refine/state-controller.js"],[b,"refine/stored-filter-controller.js"],[m,"refine/stabilize-filter-controller.js"],[f,"refine/update-controller.js"]].map(function(t){const e=t[0];return{identifier:r(t[1]),controllerConstructor:e}});export{a as AddController,l as DefaultsController,o as DeleteController,s as FormController,d as SearchFilterController,m as StabilizeFilterController,p as StateController,b as StoredFilterController,f as UpdateController,v as controllerDefinitions}; | ||
import{Controller as t}from"@hotwired/stimulus";import{delegate as e,abnegate as i}from"jquery-events-to-dom-events";import{debounce as n}from"lodash";function r(t){const e=(t.match(/^(?:\.\/)?(.+)(?:[_-]controller\..+?)$/)||[])[1];if(e)return e.replace(/_/g,"-").replace(/\//g,"--")}class s extends t{connect(){this.state=this.getStateController(),this.blueprintInput=this.addHiddenInput("blueprint"),this.addHiddenInput("filter",this.state.filterName),this.addHiddenInput("id_suffix",this.state.idSuffix),this.finishUpdate()}getStateController(){let t=this.element;for(;t!==document.body;){const e=this.application.getControllerForElementAndIdentifier(t,"refine--state");if(e)return e;t=t.parentNode}return null}addHiddenInput(t,e){const i=document.createElement("input");return i.type="hidden",i.name=t,i.value=e||"",this.element.appendChild(i),i}finishUpdate(){this.state.finishUpdate()}startUpdate(){this.blueprintInput.value=JSON.stringify(this.state.blueprint),this.state.startUpdate()}submitForm(){this.startUpdate(),this.element.requestSubmit()}}class a extends s{criterion(){this.state.addCriterion(this.previousCriterionIdValue),this.startUpdate()}group(){this.state.addGroup(),this.startUpdate()}}a.values={previousCriterionId:Number};class l extends t{connect(){this.state=this.getStateController(),this.state.updateInput(this.criterionIdValue,this.inputValue)}getStateController(){let t=this.element;for(;t!==document.body;){const e=this.application.getControllerForElementAndIdentifier(t,"refine--state");if(e)return e;t=t.parentNode}return null}}l.values={criterionId:Number,input:Object};class o extends s{criterion(){const{state:t,criterionIdValue:e}=this;t.deleteCriterion(e),this.startUpdate()}}o.values={criterionId:Number};class d extends t{connect(){const t=new URLSearchParams(window.location.search);this.existingParams=t,this.existingParams.delete("stable_id")}search(t){t.preventDefault(),this.submitFilter(),document.activeElement.blur()}submitFilter(){try{const t=this,{blueprint:e}=t.stateController;return Promise.resolve(t.stabilizeFilterController.validateBlueprint(e)).then(function(i){i.stableId?t.redirectToStableId(i.stableId):t.fetchAndRenderInvalidFilter(e)})}catch(t){return Promise.reject(t)}}addHiddenInput(t){let{name:e,value:i}=t;const n=document.createElement("input");n.type="hidden",n.name=e,n.value=i,this.submissionFormTarget.appendChild(n)}get stateController(){return this.element.querySelector('[data-controller~="refine--state"]').refineStateController}get stabilizeFilterController(){return this.element.stabilizeFilterController}redirectToStableId(t){const e=new URLSearchParams;t&&e.append("stable_id",t);const i=new URLSearchParams({...Object.fromEntries(this.existingParams),...Object.fromEntries(e)}).toString(),n=window.location.pathname+"?"+i;history.pushState({},document.title,n),window.location.reload()}fetchAndRenderInvalidFilter(t){try{var e;const i=this;return Promise.resolve(fetch(i.submitUrlValue,{headers:{Accept:"application/json","Content-Type":"application/json","X-CSRF-Token":null==(e=document.querySelector("meta[name='csrf-token']"))?void 0:e.content},method:"POST",body:JSON.stringify({filter:i.stateController.filterName,blueprint:JSON.stringify(t),id_suffix:i.stateController.idSuffix})})).then(function(t){return Promise.resolve(t.json()).then(function(t){document.getElementById(t.target).outerHTML=t.template})})}catch(t){return Promise.reject(t)}}}d.values={submitUrl:String},d.targets=[],function(){if("function"==typeof window.CustomEvent)return!1;function t(t,e){e=e||{bubbles:!1,cancelable:!1,detail:void 0};var i=document.createEvent("CustomEvent");return i.initCustomEvent(t,e.bubbles,e.cancelable,e.detail),i}t.prototype=window.Event.prototype,window.CustomEvent=t}();const u=(t,e,i,n)=>{const r=new CustomEvent("filter-stabilized",{bubbles:!0,cancelable:!0,detail:{stableId:e,filterName:i,initialLoad:n}});t.dispatchEvent(r)},c=(t,e)=>{const i=new CustomEvent("blueprint-updated",{bubbles:!0,cancelable:!0,detail:{blueprint:e}});t.dispatchEvent(i)},h=(t,e,i)=>{const{meta:n,refinements:r,component:s}=i,{clauses:a,options:l}=n;let o={clause:a[0].id,selected:"option-condition"===s?[l[0].id]:void 0};return r.forEach(t=>{var e;const{meta:i,component:n}=t,{clauses:r,options:s}=i;o[t.id]={clause:r[0].id,selected:"option-condition"===n?[null==(e=s[0])?void 0:e.id]:void 0}}),{depth:e,type:"criterion",condition_id:t,input:o}};class p extends t{connect(){this.element.refineStateController=this,this.changeDelegate=e("change",["event","picker"]),this.blueprint=this.blueprintValue,this.conditions=this.conditionsValue,this.filterName=this.classNameValue,this.idSuffix=this.idSuffixValue,this.stableId=this.stableIdValue,this.conditionsLookup=this.conditions.reduce((t,e)=>(t[e.id]=e,t),{}),this.loadingTimeout=null,c(this.element,this.blueprint)}disconnect(){i("change",this.changeDelegate)}startUpdate(){this.loadingTimeout&&window.clearTimeout(this.loadingTimeout),this.loadingTimeout=window.setTimeout(()=>{document.activeElement.blur(),this.loadingTarget.classList.remove("hidden")},1e3)}finishUpdate(){this.loadingTimeout&&window.clearTimeout(this.loadingTimeout),this.loadingTarget.classList.add("hidden")}conditionConfigFor(t){return this.conditionsLookup[t]}updateStableId(t){t!==this.stableId&&(this.stableId=t)}addGroup(){const{conditions:t}=this,e=t[0];var i;this.blueprint.length>0&&this.blueprint.push({depth:i=void 0===i?0:i,type:"conjunction",word:"or"}),this.blueprint.push(h(e.id,1,e)),c(this.element,this.blueprint)}addCriterion(t){const{blueprint:e,conditions:i}=this,n=i[0];var r;e.splice(t+1,0,{depth:r=void 0===r?1:r,type:"conjunction",word:"and"},h(n.id,1,n)),c(this.element,this.blueprint)}deleteCriterion(t){const{blueprint:e}=this,i=e[t-1],n=e[t+1],r=i&&"or"===i.word,s=n&&"or"===n.word||!n,a=r||!i,l=a&&s;i||n?e.splice(l&&r?t-1:l&&!i||a&&!s?t:t-1,2):this.blueprint=[],c(this.element,this.blueprint)}replaceCriterion(t,e,i){const n=this.blueprint[t];if("criterion"!==n.type)throw new Error("You can't call updateConditionId on a non-criterion type. Trying to update "+JSON.stringify(h));this.blueprint[t]=h(e,n.depth,i),c(this.element,this.blueprint)}updateInput(t,e,i){const{blueprint:n}=this,r=n[t],s=(i=i||"input").split(", ");s.length>1?r[s[0]][s[1]]={...r[s[0]][s[1]],...e}:r[i]={...r[i],...e},c(this.element,this.blueprint)}}p.values={blueprint:Array,conditions:Array,className:String,stableId:String,idSuffix:String},p.targets=["loading"];class b extends t{connect(){this.idValue&&(t=>{const e=new CustomEvent("filter-stored",{bubbles:!0,cancelable:!0,detail:{storedFilterId:this.idValue}});window.dispatchEvent(e)})()}updateStableIdField(t){if(t.detail.filterName!=this.filterNameValue)return null;if(this.hasStableIdFieldTarget){const{detail:e}=t,{stableId:i}=e;this.stableIdFieldTarget.value=i}}activateSaveLink(t){const{detail:e}=t,{stableId:i,initialLoad:n}=e;if(t.detail.filterName!=this.filterNameValue)return null;if(this.hasEnabledSaveLinkTarget&&this.hasDisabledSaveLinkTarget&&!n){const t=new URL(this.enabledSaveLinkTarget.href);t.searchParams.set("stable_id",i),this.enabledSaveLinkTarget.setAttribute("href",t),this.disabledSaveLinkTarget.classList.add("hidden"),this.enabledSaveLinkTarget.classList.remove("hidden")}}}b.targets=["enabledSaveLink","disabledSaveLink","stableIdField"],b.values={id:Number,stableId:String,filterName:String};class m extends t{connect(){this.element.stabilizeFilterController=this,this.stableIdValue=new URLSearchParams(window.location.search).get("stable_id")}updateStableId(t){try{const e=this;(t=>{const e=new CustomEvent("filter-unstable",{bubbles:!0,cancelable:!0,detail:{blueprint:t}});window.dispatchEvent(e)})(e.blueprint);const i=t.detail.blueprint;return Promise.resolve(e.validateBlueprint(i)).then(function(t){if(t.stableId)e.stableIdValue=t.stableId,u(e.element,e.stableIdValue,e.filterNameValue),u(window,e.stableIdValue,e.filterNameValue);else{const{errors:e}=t;(t=>{let{blueprint:e,errors:i}=t;const n=new CustomEvent("filter-invalid",{bubbles:!0,cancelable:!0,detail:{blueprint:e,errors:i}});window.dispatchEvent(n)})({blueprint:i,errors:e})}})}catch(t){return Promise.reject(t)}}validateBlueprint(t){try{var e;const i=this;let n=JSON.stringify({blueprint:t,filter:i.filterNameValue}),r=null==(e=document.querySelector("meta[name='csrf-token']"))?void 0:e.content;return Promise.resolve(fetch(i.updateStableIdUrlValue,{method:"PUT",body:n,headers:{accept:"application/json","content-type":"application/json","X-CSRF-Token":r}})).then(function(t){return Promise.resolve(t.json()).then(function(e){return t.ok?{stableId:e.filter_id}:{errors:e.errors}})})}catch(t){return Promise.reject(t)}}}m.values={stableId:String,updateStableIdUrl:String,filterName:String},m.targets=[];class f extends s{initialize(){this.updateBlueprint=n((t,e,i)=>{this.value(t,e,i),this.createStableId(this.state.blueprint,this.state.filterName)},500)}connect(){s.prototype.connect.apply(this),this.state.updateStableId(this.stableIdValue)}refinedFilter(t){const{criterionIdValue:e,state:i}=this;i.updateInput(e,{id:t.target.value},t.target.dataset.inputId),this.submitForm()}clause(t){const{criterionIdValue:e,state:i}=this;i.updateInput(e,{clause:t.target.value},t.target.dataset.inputId),this.submitForm()}selected(t){const{target:e}=t,i=Array.prototype.slice.call(e.options).filter(t=>t.selected).map(t=>t.value);this.value(t,i,"selected"),this.createStableId(this.state.blueprint,this.state.filterName)}value(t,e,i){const{criterionIdValue:n,state:r}=this,s=t.target.dataset;r.updateInput(n,{[i=i||s.inputKey||"value"]:e=e||t.target.value},s.inputId)}date(t){const{picker:e}=t.detail,i=e.startDate.format("YYYY-MM-DD");this.value(t,i),this.submitForm()}createStableId(t,e){var i;const{state:n}=this;let r=JSON.stringify({blueprint:t,filter:e}),s=null==(i=document.querySelector("meta[name='csrf-token']"))?void 0:i.content;$.ajax({type:"PUT",url:"/hammerstone/update_stable_id",data:r,headers:{accept:"application/json","content-type":"application/json","X-CSRF-Token":s},success:function(t){n.updateStableId(t.filter_id)}})}condition(t){const{criterionIdValue:e,state:i}=this,n=t.target.value,r=this.state.conditionConfigFor(n);i.replaceCriterion(e,n,r),this.submitForm()}cancelEnter(t){"Enter"===t.code&&(t.preventDefault(),t.stopPropagation())}}f.values={criterionId:Number,stableId:String};const v=[[a,"refine/add-controller.js"],[l,"refine/defaults-controller.js"],[o,"refine/delete-controller.js"],[s,"refine/form-controller.js"],[d,"refine/search-filter-controller.js"],[p,"refine/state-controller.js"],[b,"refine/stored-filter-controller.js"],[m,"refine/stabilize-filter-controller.js"],[f,"refine/update-controller.js"]].map(function(t){const e=t[0];return{identifier:r(t[1]),controllerConstructor:e}});export{a as AddController,l as DefaultsController,o as DeleteController,s as FormController,d as SearchFilterController,m as StabilizeFilterController,p as StateController,b as StoredFilterController,f as UpdateController,v as controllerDefinitions}; | ||
//# sourceMappingURL=refine-stimulus.esm.js.map |
@@ -1,2 +0,2 @@ | ||
var t=require("@hotwired/stimulus"),e=require("jquery-events-to-dom-events"),i=require("lodash");function n(t){const e=(t.match(/^(?:\.\/)?(.+)(?:[_-]controller\..+?)$/)||[])[1];if(e)return e.replace(/_/g,"-").replace(/\//g,"--")}class r extends t.Controller{connect(){console.log("Form Controller Connected"),this.state=this.getStateController(),this.blueprintInput=this.addHiddenInput("blueprint"),this.addHiddenInput("filter",this.state.filterName),this.addHiddenInput("id_suffix",this.state.idSuffix),this.finishUpdate()}getStateController(){let t=this.element;for(;t!==document.body;){const e=this.application.getControllerForElementAndIdentifier(t,"refine--state");if(e)return e;t=t.parentNode}return null}addHiddenInput(t,e){const i=document.createElement("input");return i.type="hidden",i.name=t,i.value=e||"",this.element.appendChild(i),i}finishUpdate(){this.state.finishUpdate()}startUpdate(){this.blueprintInput.value=JSON.stringify(this.state.blueprint),this.state.startUpdate()}submitForm(){this.startUpdate(),this.element.requestSubmit()}}class s extends r{criterion(){this.state.addCriterion(this.previousCriterionIdValue),this.startUpdate()}group(){this.state.addGroup(),this.startUpdate()}}s.values={previousCriterionId:Number};class l extends t.Controller{connect(){this.state=this.getStateController(),this.state.updateInput(this.criterionIdValue,this.inputValue)}getStateController(){let t=this.element;for(;t!==document.body;){const e=this.application.getControllerForElementAndIdentifier(t,"refine--state");if(e)return e;t=t.parentNode}return null}}l.values={criterionId:Number,input:Object};class a extends r{criterion(){const{state:t,criterionIdValue:e}=this;t.deleteCriterion(e),this.startUpdate()}}a.values={criterionId:Number};class o extends t.Controller{connect(){console.log("Seacrch filter connected!");const t=new URLSearchParams(window.location.search);this.existingParams=t,this.existingParams.delete("stable_id")}search(t){console.log("search!"),t.preventDefault(),this.submitFilter(),document.activeElement.blur()}submitFilter(){try{const t=this,{blueprint:e}=t.stateController;return Promise.resolve(t.stabilizeFilterController.validateBlueprint(e)).then(function(i){console.log("validationResult",i),i.stableId?t.redirectToStableId(i.stableId):t.fetchAndRenderInvalidFilter(e)})}catch(t){return Promise.reject(t)}}addHiddenInput(t){let{name:e,value:i}=t;const n=document.createElement("input");n.type="hidden",n.name=e,n.value=i,this.submissionFormTarget.appendChild(n)}get stateController(){return this.element.querySelector('[data-controller~="refine--state"]').refineStateController}get stabilizeFilterController(){return this.element.stabilizeFilterController}redirectToStableId(t){const e=new URLSearchParams;t&&e.append("stable_id",t);const i=new URLSearchParams({...Object.fromEntries(this.existingParams),...Object.fromEntries(e)}).toString(),n=window.location.pathname+"?"+i;history.pushState({},document.title,n),window.location.reload()}fetchAndRenderInvalidFilter(t){try{var e;const i=this;return console.log("this.submitUrlValue",i.submitUrlValue),Promise.resolve(fetch(i.submitUrlValue,{headers:{Accept:"application/json","Content-Type":"application/json","X-CSRF-Token":null==(e=document.querySelector("meta[name='csrf-token']"))?void 0:e.content},method:"POST",body:JSON.stringify({filter:i.stateController.filterName,blueprint:JSON.stringify(t),id_suffix:i.stateController.idSuffix})})).then(function(t){return Promise.resolve(t.json()).then(function(t){document.getElementById(t.target).outerHTML=t.template})})}catch(t){return Promise.reject(t)}}}o.values={submitUrl:String},o.targets=[],function(){if("function"==typeof window.CustomEvent)return!1;function t(t,e){e=e||{bubbles:!1,cancelable:!1,detail:void 0};var i=document.createEvent("CustomEvent");return i.initCustomEvent(t,e.bubbles,e.cancelable,e.detail),i}t.prototype=window.Event.prototype,window.CustomEvent=t}();const d=(t,e,i,n)=>{const r=new CustomEvent("filter-stabilized",{bubbles:!0,cancelable:!0,detail:{stableId:e,filterName:i,initialLoad:n}});t.dispatchEvent(r)},u=(t,e)=>{const i=new CustomEvent("blueprint-updated",{bubbles:!0,cancelable:!0,detail:{blueprint:e}});t.dispatchEvent(i)},c=(t,e,i)=>{const{meta:n,refinements:r,component:s}=i,{clauses:l,options:a}=n;let o={clause:l[0].id,selected:"option-condition"===s?[a[0].id]:void 0};return r.forEach(t=>{var e;const{meta:i,component:n}=t,{clauses:r,options:s}=i;o[t.id]={clause:r[0].id,selected:"option-condition"===n?[null==(e=s[0])?void 0:e.id]:void 0}}),{depth:e,type:"criterion",condition_id:t,input:o}};class h extends t.Controller{connect(){this.element.refineStateController=this,this.changeDelegate=e.delegate("change",["event","picker"]),this.blueprint=this.blueprintValue,this.conditions=this.conditionsValue,this.filterName=this.classNameValue,this.idSuffix=this.idSuffixValue,this.stableId=this.stableIdValue,this.conditionsLookup=this.conditions.reduce((t,e)=>(t[e.id]=e,t),{}),this.loadingTimeout=null,u(this.element,this.blueprint)}disconnect(){e.abnegate("change",this.changeDelegate)}startUpdate(){this.loadingTimeout&&window.clearTimeout(this.loadingTimeout),this.loadingTimeout=window.setTimeout(()=>{document.activeElement.blur(),this.loadingTarget.classList.remove("hidden")},1e3)}finishUpdate(){this.loadingTimeout&&window.clearTimeout(this.loadingTimeout),this.loadingTarget.classList.add("hidden")}conditionConfigFor(t){return this.conditionsLookup[t]}updateStableId(t){t!==this.stableId&&(this.stableId=t)}addGroup(){const{conditions:t}=this,e=t[0];var i;this.blueprint.length>0&&this.blueprint.push({depth:i=void 0===i?0:i,type:"conjunction",word:"or"}),this.blueprint.push(c(e.id,1,e)),u(this.element,this.blueprint)}addCriterion(t){const{blueprint:e,conditions:i}=this,n=i[0];var r;e.splice(t+1,0,{depth:r=void 0===r?1:r,type:"conjunction",word:"and"},c(n.id,1,n)),u(this.element,this.blueprint)}deleteCriterion(t){const{blueprint:e}=this,i=e[t-1],n=e[t+1],r=i&&"or"===i.word,s=n&&"or"===n.word||!n,l=r||!i,a=l&&s;if(i||n?e.splice(a&&r?t-1:a&&!i||l&&!s?t:t-1,2):this.blueprint=[],0===this.blueprint.length){const t=this.conditions[0];this.blueprint.push(c(t.id,1,t))}u(this.element,this.blueprint)}replaceCriterion(t,e,i){const n=this.blueprint[t];if("criterion"!==n.type)throw new Error("You can't call updateConditionId on a non-criterion type. Trying to update "+JSON.stringify(c));this.blueprint[t]=c(e,n.depth,i),u(this.element,this.blueprint)}updateInput(t,e,i){const{blueprint:n}=this,r=n[t],s=(i=i||"input").split(", ");s.length>1?r[s[0]][s[1]]={...r[s[0]][s[1]],...e}:r[i]={...r[i],...e},u(this.element,this.blueprint)}}h.values={blueprint:Array,conditions:Array,className:String,stableId:String,idSuffix:String},h.targets=["loading"];class p extends t.Controller{connect(){this.idValue&&(t=>{const e=new CustomEvent("filter-stored",{bubbles:!0,cancelable:!0,detail:{storedFilterId:this.idValue}});window.dispatchEvent(e)})()}updateStableIdField(t){if(t.detail.filterName!=this.filterNameValue)return null;if(this.hasStableIdFieldTarget){const{detail:e}=t,{stableId:i}=e;this.stableIdFieldTarget.value=i}}activateSaveLink(t){const{detail:e}=t,{stableId:i,initialLoad:n}=e;if(t.detail.filterName!=this.filterNameValue)return null;if(this.hasEnabledSaveLinkTarget&&this.hasDisabledSaveLinkTarget&&!n){const t=new URL(this.enabledSaveLinkTarget.href);t.searchParams.set("stable_id",i),this.enabledSaveLinkTarget.setAttribute("href",t),this.disabledSaveLinkTarget.classList.add("hidden"),this.enabledSaveLinkTarget.classList.remove("hidden")}}}p.targets=["enabledSaveLink","disabledSaveLink","stableIdField"],p.values={id:Number,stableId:String,filterName:String};class b extends t.Controller{connect(){this.element.stabilizeFilterController=this,this.stableIdValue=new URLSearchParams(window.location.search).get("stable_id")}updateStableId(t){try{const e=this;(t=>{const e=new CustomEvent("filter-unstable",{bubbles:!0,cancelable:!0,detail:{blueprint:t}});window.dispatchEvent(e)})(e.blueprint);const i=t.detail.blueprint;return Promise.resolve(e.validateBlueprint(i)).then(function(t){if(t.stableId)e.stableIdValue=t.stableId,d(e.element,e.stableIdValue,e.filterNameValue),d(window,e.stableIdValue,e.filterNameValue);else{const{errors:e}=t;(t=>{let{blueprint:e,errors:i}=t;const n=new CustomEvent("filter-invalid",{bubbles:!0,cancelable:!0,detail:{blueprint:e,errors:i}});window.dispatchEvent(n)})({blueprint:i,errors:e})}})}catch(t){return Promise.reject(t)}}validateBlueprint(t){try{var e;const i=this;let n=JSON.stringify({blueprint:t,filter:i.filterNameValue}),r=null==(e=document.querySelector("meta[name='csrf-token']"))?void 0:e.content;return Promise.resolve(fetch(i.updateStableIdUrlValue,{method:"PUT",body:n,headers:{accept:"application/json","content-type":"application/json","X-CSRF-Token":r}})).then(function(t){return Promise.resolve(t.json()).then(function(e){return t.ok?{stableId:e.filter_id}:{errors:e.errors}})})}catch(t){return Promise.reject(t)}}}b.values={stableId:String,updateStableIdUrl:String,filterName:String},b.targets=[];class m extends r{initialize(){this.updateBlueprint=i.debounce((t,e,i)=>{this.value(t,e,i),this.createStableId(this.state.blueprint,this.state.filterName)},500)}connect(){r.prototype.connect.apply(this),this.state.updateStableId(this.stableIdValue)}refinedFilter(t){const{criterionIdValue:e,state:i}=this;i.updateInput(e,{id:t.target.value},t.target.dataset.inputId),this.submitForm()}clause(t){const{criterionIdValue:e,state:i}=this;i.updateInput(e,{clause:t.target.value},t.target.dataset.inputId),this.submitForm()}selected(t){const{target:e}=t,i=Array.prototype.slice.call(e.options).filter(t=>t.selected).map(t=>t.value);this.value(t,i,"selected"),this.createStableId(this.state.blueprint,this.state.filterName)}value(t,e,i){const{criterionIdValue:n,state:r}=this,s=t.target.dataset;r.updateInput(n,{[i=i||s.inputKey||"value"]:e=e||t.target.value},s.inputId)}date(t){const{picker:e}=t.detail,i=e.startDate.format("YYYY-MM-DD");this.value(t,i),this.submitForm()}createStableId(t,e){var i;const{state:n}=this;let r=JSON.stringify({blueprint:t,filter:e}),s=null==(i=document.querySelector("meta[name='csrf-token']"))?void 0:i.content;$.ajax({type:"PUT",url:"/hammerstone/update_stable_id",data:r,headers:{accept:"application/json","content-type":"application/json","X-CSRF-Token":s},success:function(t){n.updateStableId(t.filter_id)}})}condition(t){const{criterionIdValue:e,state:i}=this,n=t.target.value,r=this.state.conditionConfigFor(n);i.replaceCriterion(e,n,r),this.submitForm()}cancelEnter(t){"Enter"===t.code&&(t.preventDefault(),t.stopPropagation())}}m.values={criterionId:Number,stableId:String};const f=[[s,"refine/add-controller.js"],[l,"refine/defaults-controller.js"],[a,"refine/delete-controller.js"],[r,"refine/form-controller.js"],[o,"refine/search-filter-controller.js"],[h,"refine/state-controller.js"],[p,"refine/stored-filter-controller.js"],[b,"refine/stabilize-filter-controller.js"],[m,"refine/update-controller.js"]].map(function(t){const e=t[0];return{identifier:n(t[1]),controllerConstructor:e}});exports.AddController=s,exports.DefaultsController=l,exports.DeleteController=a,exports.FormController=r,exports.SearchFilterController=o,exports.StabilizeFilterController=b,exports.StateController=h,exports.StoredFilterController=p,exports.UpdateController=m,exports.controllerDefinitions=f; | ||
var t=require("@hotwired/stimulus"),e=require("jquery-events-to-dom-events"),i=require("lodash");function n(t){const e=(t.match(/^(?:\.\/)?(.+)(?:[_-]controller\..+?)$/)||[])[1];if(e)return e.replace(/_/g,"-").replace(/\//g,"--")}class r extends t.Controller{connect(){this.state=this.getStateController(),this.blueprintInput=this.addHiddenInput("blueprint"),this.addHiddenInput("filter",this.state.filterName),this.addHiddenInput("id_suffix",this.state.idSuffix),this.finishUpdate()}getStateController(){let t=this.element;for(;t!==document.body;){const e=this.application.getControllerForElementAndIdentifier(t,"refine--state");if(e)return e;t=t.parentNode}return null}addHiddenInput(t,e){const i=document.createElement("input");return i.type="hidden",i.name=t,i.value=e||"",this.element.appendChild(i),i}finishUpdate(){this.state.finishUpdate()}startUpdate(){this.blueprintInput.value=JSON.stringify(this.state.blueprint),this.state.startUpdate()}submitForm(){this.startUpdate(),this.element.requestSubmit()}}class s extends r{criterion(){this.state.addCriterion(this.previousCriterionIdValue),this.startUpdate()}group(){this.state.addGroup(),this.startUpdate()}}s.values={previousCriterionId:Number};class l extends t.Controller{connect(){this.state=this.getStateController(),this.state.updateInput(this.criterionIdValue,this.inputValue)}getStateController(){let t=this.element;for(;t!==document.body;){const e=this.application.getControllerForElementAndIdentifier(t,"refine--state");if(e)return e;t=t.parentNode}return null}}l.values={criterionId:Number,input:Object};class a extends r{criterion(){const{state:t,criterionIdValue:e}=this;t.deleteCriterion(e),this.startUpdate()}}a.values={criterionId:Number};class o extends t.Controller{connect(){const t=new URLSearchParams(window.location.search);this.existingParams=t,this.existingParams.delete("stable_id")}search(t){t.preventDefault(),this.submitFilter(),document.activeElement.blur()}submitFilter(){try{const t=this,{blueprint:e}=t.stateController;return Promise.resolve(t.stabilizeFilterController.validateBlueprint(e)).then(function(i){i.stableId?t.redirectToStableId(i.stableId):t.fetchAndRenderInvalidFilter(e)})}catch(t){return Promise.reject(t)}}addHiddenInput(t){let{name:e,value:i}=t;const n=document.createElement("input");n.type="hidden",n.name=e,n.value=i,this.submissionFormTarget.appendChild(n)}get stateController(){return this.element.querySelector('[data-controller~="refine--state"]').refineStateController}get stabilizeFilterController(){return this.element.stabilizeFilterController}redirectToStableId(t){const e=new URLSearchParams;t&&e.append("stable_id",t);const i=new URLSearchParams({...Object.fromEntries(this.existingParams),...Object.fromEntries(e)}).toString(),n=window.location.pathname+"?"+i;history.pushState({},document.title,n),window.location.reload()}fetchAndRenderInvalidFilter(t){try{var e;const i=this;return Promise.resolve(fetch(i.submitUrlValue,{headers:{Accept:"application/json","Content-Type":"application/json","X-CSRF-Token":null==(e=document.querySelector("meta[name='csrf-token']"))?void 0:e.content},method:"POST",body:JSON.stringify({filter:i.stateController.filterName,blueprint:JSON.stringify(t),id_suffix:i.stateController.idSuffix})})).then(function(t){return Promise.resolve(t.json()).then(function(t){document.getElementById(t.target).outerHTML=t.template})})}catch(t){return Promise.reject(t)}}}o.values={submitUrl:String},o.targets=[],function(){if("function"==typeof window.CustomEvent)return!1;function t(t,e){e=e||{bubbles:!1,cancelable:!1,detail:void 0};var i=document.createEvent("CustomEvent");return i.initCustomEvent(t,e.bubbles,e.cancelable,e.detail),i}t.prototype=window.Event.prototype,window.CustomEvent=t}();const d=(t,e,i,n)=>{const r=new CustomEvent("filter-stabilized",{bubbles:!0,cancelable:!0,detail:{stableId:e,filterName:i,initialLoad:n}});t.dispatchEvent(r)},u=(t,e)=>{const i=new CustomEvent("blueprint-updated",{bubbles:!0,cancelable:!0,detail:{blueprint:e}});t.dispatchEvent(i)},c=(t,e,i)=>{const{meta:n,refinements:r,component:s}=i,{clauses:l,options:a}=n;let o={clause:l[0].id,selected:"option-condition"===s?[a[0].id]:void 0};return r.forEach(t=>{var e;const{meta:i,component:n}=t,{clauses:r,options:s}=i;o[t.id]={clause:r[0].id,selected:"option-condition"===n?[null==(e=s[0])?void 0:e.id]:void 0}}),{depth:e,type:"criterion",condition_id:t,input:o}};class h extends t.Controller{connect(){this.element.refineStateController=this,this.changeDelegate=e.delegate("change",["event","picker"]),this.blueprint=this.blueprintValue,this.conditions=this.conditionsValue,this.filterName=this.classNameValue,this.idSuffix=this.idSuffixValue,this.stableId=this.stableIdValue,this.conditionsLookup=this.conditions.reduce((t,e)=>(t[e.id]=e,t),{}),this.loadingTimeout=null,u(this.element,this.blueprint)}disconnect(){e.abnegate("change",this.changeDelegate)}startUpdate(){this.loadingTimeout&&window.clearTimeout(this.loadingTimeout),this.loadingTimeout=window.setTimeout(()=>{document.activeElement.blur(),this.loadingTarget.classList.remove("hidden")},1e3)}finishUpdate(){this.loadingTimeout&&window.clearTimeout(this.loadingTimeout),this.loadingTarget.classList.add("hidden")}conditionConfigFor(t){return this.conditionsLookup[t]}updateStableId(t){t!==this.stableId&&(this.stableId=t)}addGroup(){const{conditions:t}=this,e=t[0];var i;this.blueprint.length>0&&this.blueprint.push({depth:i=void 0===i?0:i,type:"conjunction",word:"or"}),this.blueprint.push(c(e.id,1,e)),u(this.element,this.blueprint)}addCriterion(t){const{blueprint:e,conditions:i}=this,n=i[0];var r;e.splice(t+1,0,{depth:r=void 0===r?1:r,type:"conjunction",word:"and"},c(n.id,1,n)),u(this.element,this.blueprint)}deleteCriterion(t){const{blueprint:e}=this,i=e[t-1],n=e[t+1],r=i&&"or"===i.word,s=n&&"or"===n.word||!n,l=r||!i,a=l&&s;i||n?e.splice(a&&r?t-1:a&&!i||l&&!s?t:t-1,2):this.blueprint=[],u(this.element,this.blueprint)}replaceCriterion(t,e,i){const n=this.blueprint[t];if("criterion"!==n.type)throw new Error("You can't call updateConditionId on a non-criterion type. Trying to update "+JSON.stringify(c));this.blueprint[t]=c(e,n.depth,i),u(this.element,this.blueprint)}updateInput(t,e,i){const{blueprint:n}=this,r=n[t],s=(i=i||"input").split(", ");s.length>1?r[s[0]][s[1]]={...r[s[0]][s[1]],...e}:r[i]={...r[i],...e},u(this.element,this.blueprint)}}h.values={blueprint:Array,conditions:Array,className:String,stableId:String,idSuffix:String},h.targets=["loading"];class p extends t.Controller{connect(){this.idValue&&(t=>{const e=new CustomEvent("filter-stored",{bubbles:!0,cancelable:!0,detail:{storedFilterId:this.idValue}});window.dispatchEvent(e)})()}updateStableIdField(t){if(t.detail.filterName!=this.filterNameValue)return null;if(this.hasStableIdFieldTarget){const{detail:e}=t,{stableId:i}=e;this.stableIdFieldTarget.value=i}}activateSaveLink(t){const{detail:e}=t,{stableId:i,initialLoad:n}=e;if(t.detail.filterName!=this.filterNameValue)return null;if(this.hasEnabledSaveLinkTarget&&this.hasDisabledSaveLinkTarget&&!n){const t=new URL(this.enabledSaveLinkTarget.href);t.searchParams.set("stable_id",i),this.enabledSaveLinkTarget.setAttribute("href",t),this.disabledSaveLinkTarget.classList.add("hidden"),this.enabledSaveLinkTarget.classList.remove("hidden")}}}p.targets=["enabledSaveLink","disabledSaveLink","stableIdField"],p.values={id:Number,stableId:String,filterName:String};class b extends t.Controller{connect(){this.element.stabilizeFilterController=this,this.stableIdValue=new URLSearchParams(window.location.search).get("stable_id")}updateStableId(t){try{const e=this;(t=>{const e=new CustomEvent("filter-unstable",{bubbles:!0,cancelable:!0,detail:{blueprint:t}});window.dispatchEvent(e)})(e.blueprint);const i=t.detail.blueprint;return Promise.resolve(e.validateBlueprint(i)).then(function(t){if(t.stableId)e.stableIdValue=t.stableId,d(e.element,e.stableIdValue,e.filterNameValue),d(window,e.stableIdValue,e.filterNameValue);else{const{errors:e}=t;(t=>{let{blueprint:e,errors:i}=t;const n=new CustomEvent("filter-invalid",{bubbles:!0,cancelable:!0,detail:{blueprint:e,errors:i}});window.dispatchEvent(n)})({blueprint:i,errors:e})}})}catch(t){return Promise.reject(t)}}validateBlueprint(t){try{var e;const i=this;let n=JSON.stringify({blueprint:t,filter:i.filterNameValue}),r=null==(e=document.querySelector("meta[name='csrf-token']"))?void 0:e.content;return Promise.resolve(fetch(i.updateStableIdUrlValue,{method:"PUT",body:n,headers:{accept:"application/json","content-type":"application/json","X-CSRF-Token":r}})).then(function(t){return Promise.resolve(t.json()).then(function(e){return t.ok?{stableId:e.filter_id}:{errors:e.errors}})})}catch(t){return Promise.reject(t)}}}b.values={stableId:String,updateStableIdUrl:String,filterName:String},b.targets=[];class m extends r{initialize(){this.updateBlueprint=i.debounce((t,e,i)=>{this.value(t,e,i),this.createStableId(this.state.blueprint,this.state.filterName)},500)}connect(){r.prototype.connect.apply(this),this.state.updateStableId(this.stableIdValue)}refinedFilter(t){const{criterionIdValue:e,state:i}=this;i.updateInput(e,{id:t.target.value},t.target.dataset.inputId),this.submitForm()}clause(t){const{criterionIdValue:e,state:i}=this;i.updateInput(e,{clause:t.target.value},t.target.dataset.inputId),this.submitForm()}selected(t){const{target:e}=t,i=Array.prototype.slice.call(e.options).filter(t=>t.selected).map(t=>t.value);this.value(t,i,"selected"),this.createStableId(this.state.blueprint,this.state.filterName)}value(t,e,i){const{criterionIdValue:n,state:r}=this,s=t.target.dataset;r.updateInput(n,{[i=i||s.inputKey||"value"]:e=e||t.target.value},s.inputId)}date(t){const{picker:e}=t.detail,i=e.startDate.format("YYYY-MM-DD");this.value(t,i),this.submitForm()}createStableId(t,e){var i;const{state:n}=this;let r=JSON.stringify({blueprint:t,filter:e}),s=null==(i=document.querySelector("meta[name='csrf-token']"))?void 0:i.content;$.ajax({type:"PUT",url:"/hammerstone/update_stable_id",data:r,headers:{accept:"application/json","content-type":"application/json","X-CSRF-Token":s},success:function(t){n.updateStableId(t.filter_id)}})}condition(t){const{criterionIdValue:e,state:i}=this,n=t.target.value,r=this.state.conditionConfigFor(n);i.replaceCriterion(e,n,r),this.submitForm()}cancelEnter(t){"Enter"===t.code&&(t.preventDefault(),t.stopPropagation())}}m.values={criterionId:Number,stableId:String};const f=[[s,"refine/add-controller.js"],[l,"refine/defaults-controller.js"],[a,"refine/delete-controller.js"],[r,"refine/form-controller.js"],[o,"refine/search-filter-controller.js"],[h,"refine/state-controller.js"],[p,"refine/stored-filter-controller.js"],[b,"refine/stabilize-filter-controller.js"],[m,"refine/update-controller.js"]].map(function(t){const e=t[0];return{identifier:n(t[1]),controllerConstructor:e}});exports.AddController=s,exports.DefaultsController=l,exports.DeleteController=a,exports.FormController=r,exports.SearchFilterController=o,exports.StabilizeFilterController=b,exports.StateController=h,exports.StoredFilterController=p,exports.UpdateController=m,exports.controllerDefinitions=f; | ||
//# sourceMappingURL=refine-stimulus.js.map |
@@ -1,2 +0,2 @@ | ||
import{Controller as t}from"@hotwired/stimulus";import{delegate as e,abnegate as i}from"jquery-events-to-dom-events";import{debounce as n}from"lodash";function s(t){const e=(t.match(/^(?:\.\/)?(.+)(?:[_-]controller\..+?)$/)||[])[1];if(e)return e.replace(/_/g,"-").replace(/\//g,"--")}class a extends t{connect(){console.log("Form Controller Connected"),this.state=this.getStateController(),this.blueprintInput=this.addHiddenInput("blueprint"),this.addHiddenInput("filter",this.state.filterName),this.addHiddenInput("id_suffix",this.state.idSuffix),this.finishUpdate()}getStateController(){let t=this.element;for(;t!==document.body;){const e=this.application.getControllerForElementAndIdentifier(t,"refine--state");if(e)return e;t=t.parentNode}return null}addHiddenInput(t,e){const i=document.createElement("input");return i.type="hidden",i.name=t,i.value=e||"",this.element.appendChild(i),i}finishUpdate(){this.state.finishUpdate()}startUpdate(){this.blueprintInput.value=JSON.stringify(this.state.blueprint),this.state.startUpdate()}submitForm(){this.startUpdate(),this.element.requestSubmit()}}class r extends a{criterion(){this.state.addCriterion(this.previousCriterionIdValue),this.startUpdate()}group(){this.state.addGroup(),this.startUpdate()}}r.values={previousCriterionId:Number};class l extends t{connect(){this.state=this.getStateController(),this.state.updateInput(this.criterionIdValue,this.inputValue)}getStateController(){let t=this.element;for(;t!==document.body;){const e=this.application.getControllerForElementAndIdentifier(t,"refine--state");if(e)return e;t=t.parentNode}return null}}l.values={criterionId:Number,input:Object};class o extends a{criterion(){const{state:t,criterionIdValue:e}=this;t.deleteCriterion(e),this.startUpdate()}}function d(){return d=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var i=arguments[e];for(var n in i)Object.prototype.hasOwnProperty.call(i,n)&&(t[n]=i[n])}return t},d.apply(this,arguments)}o.values={criterionId:Number};class c extends t{connect(){console.log("Seacrch filter connected!");const t=new URLSearchParams(window.location.search);this.existingParams=t,this.existingParams.delete("stable_id")}search(t){console.log("search!"),t.preventDefault(),this.submitFilter(),document.activeElement.blur()}async submitFilter(){const{blueprint:t}=this.stateController,e=await this.stabilizeFilterController.validateBlueprint(t);console.log("validationResult",e),e.stableId?this.redirectToStableId(e.stableId):this.fetchAndRenderInvalidFilter(t)}addHiddenInput({name:t,value:e}){const i=document.createElement("input");i.type="hidden",i.name=t,i.value=e,this.submissionFormTarget.appendChild(i)}get stateController(){return this.element.querySelector('[data-controller~="refine--state"]').refineStateController}get stabilizeFilterController(){return this.element.stabilizeFilterController}redirectToStableId(t){const e=new URLSearchParams;t&&e.append("stable_id",t);const i=new URLSearchParams(d({},Object.fromEntries(this.existingParams),Object.fromEntries(e))).toString(),n=`${window.location.pathname}?${i}`;history.pushState({},document.title,n),window.location.reload()}async fetchAndRenderInvalidFilter(t){var e;console.log("this.submitUrlValue",this.submitUrlValue);const i=await fetch(this.submitUrlValue,{headers:{Accept:"application/json","Content-Type":"application/json","X-CSRF-Token":null==(e=document.querySelector("meta[name='csrf-token']"))?void 0:e.content},method:"POST",body:JSON.stringify({filter:this.stateController.filterName,blueprint:JSON.stringify(t),id_suffix:this.stateController.idSuffix})}),n=await i.json();document.getElementById(n.target).outerHTML=n.template}}c.values={submitUrl:String},c.targets=[],function(){if("function"==typeof window.CustomEvent)return!1;function t(t,e){e=e||{bubbles:!1,cancelable:!1,detail:void 0};var i=document.createEvent("CustomEvent");return i.initCustomEvent(t,e.bubbles,e.cancelable,e.detail),i}t.prototype=window.Event.prototype,window.CustomEvent=t}();const u=(t,e,i,n)=>{const s=new CustomEvent("filter-stabilized",{bubbles:!0,cancelable:!0,detail:{stableId:e,filterName:i,initialLoad:n}});t.dispatchEvent(s)},h=(t,e)=>{const i=new CustomEvent("blueprint-updated",{bubbles:!0,cancelable:!0,detail:{blueprint:e}});t.dispatchEvent(i)},p=(t,e,i)=>{const{meta:n,refinements:s,component:a}=i,{clauses:r,options:l}=n;let o={clause:r[0].id,selected:"option-condition"===a?[l[0].id]:void 0};return s.forEach(t=>{var e;const{meta:i,component:n}=t,{clauses:s,options:a}=i;o[t.id]={clause:s[0].id,selected:"option-condition"===n?[null==(e=a[0])?void 0:e.id]:void 0}}),{depth:e,type:"criterion",condition_id:t,input:o}};class b extends t{connect(){this.element.refineStateController=this,this.changeDelegate=e("change",["event","picker"]),this.blueprint=this.blueprintValue,this.conditions=this.conditionsValue,this.filterName=this.classNameValue,this.idSuffix=this.idSuffixValue,this.stableId=this.stableIdValue,this.conditionsLookup=this.conditions.reduce((t,e)=>(t[e.id]=e,t),{}),this.loadingTimeout=null,h(this.element,this.blueprint)}disconnect(){i("change",this.changeDelegate)}startUpdate(){this.loadingTimeout&&window.clearTimeout(this.loadingTimeout),this.loadingTimeout=window.setTimeout(()=>{document.activeElement.blur(),this.loadingTarget.classList.remove("hidden")},1e3)}finishUpdate(){this.loadingTimeout&&window.clearTimeout(this.loadingTimeout),this.loadingTarget.classList.add("hidden")}conditionConfigFor(t){return this.conditionsLookup[t]}updateStableId(t){t!==this.stableId&&(this.stableId=t)}addGroup(){const{conditions:t}=this,e=t[0];var i;this.blueprint.length>0&&this.blueprint.push({depth:i=void 0===i?0:i,type:"conjunction",word:"or"}),this.blueprint.push(p(e.id,1,e)),h(this.element,this.blueprint)}addCriterion(t){const{blueprint:e,conditions:i}=this,n=i[0];var s;e.splice(t+1,0,{depth:s=void 0===s?1:s,type:"conjunction",word:"and"},p(n.id,1,n)),h(this.element,this.blueprint)}deleteCriterion(t){const{blueprint:e}=this,i=e[t-1],n=e[t+1],s=i&&"or"===i.word,a=n&&"or"===n.word||!n,r=s||!i,l=r&&a;if(i||n?e.splice(l&&s?t-1:l&&!i||r&&!a?t:t-1,2):this.blueprint=[],0===this.blueprint.length){const t=this.conditions[0];this.blueprint.push(p(t.id,1,t))}h(this.element,this.blueprint)}replaceCriterion(t,e,i){const n=this.blueprint[t];if("criterion"!==n.type)throw new Error(`You can't call updateConditionId on a non-criterion type. Trying to update ${JSON.stringify(p)}`);this.blueprint[t]=p(e,n.depth,i),h(this.element,this.blueprint)}updateInput(t,e,i){const{blueprint:n}=this,s=n[t],a=(i=i||"input").split(", ");a.length>1?s[a[0]][a[1]]=d({},s[a[0]][a[1]],e):s[i]=d({},s[i],e),h(this.element,this.blueprint)}}b.values={blueprint:Array,conditions:Array,className:String,stableId:String,idSuffix:String},b.targets=["loading"];class m extends t{connect(){this.idValue&&(t=>{const e=new CustomEvent("filter-stored",{bubbles:!0,cancelable:!0,detail:{storedFilterId:this.idValue}});window.dispatchEvent(e)})()}updateStableIdField(t){if(t.detail.filterName!=this.filterNameValue)return null;if(this.hasStableIdFieldTarget){const{detail:e}=t,{stableId:i}=e;this.stableIdFieldTarget.value=i}}activateSaveLink(t){const{detail:e}=t,{stableId:i,initialLoad:n}=e;if(t.detail.filterName!=this.filterNameValue)return null;if(this.hasEnabledSaveLinkTarget&&this.hasDisabledSaveLinkTarget&&!n){const t=new URL(this.enabledSaveLinkTarget.href);t.searchParams.set("stable_id",i),this.enabledSaveLinkTarget.setAttribute("href",t),this.disabledSaveLinkTarget.classList.add("hidden"),this.enabledSaveLinkTarget.classList.remove("hidden")}}}m.targets=["enabledSaveLink","disabledSaveLink","stableIdField"],m.values={id:Number,stableId:String,filterName:String};class f extends t{connect(){this.element.stabilizeFilterController=this,this.stableIdValue=new URLSearchParams(window.location.search).get("stable_id")}async updateStableId(t){(t=>{const e=new CustomEvent("filter-unstable",{bubbles:!0,cancelable:!0,detail:{blueprint:this.blueprint}});window.dispatchEvent(e)})();const e=t.detail.blueprint,i=await this.validateBlueprint(e);if(i.stableId)this.stableIdValue=i.stableId,u(this.element,this.stableIdValue,this.filterNameValue),u(window,this.stableIdValue,this.filterNameValue);else{const{errors:t}=i;(({blueprint:t,errors:e})=>{const i=new CustomEvent("filter-invalid",{bubbles:!0,cancelable:!0,detail:{blueprint:t,errors:e}});window.dispatchEvent(i)})({blueprint:e,errors:t})}}async validateBlueprint(t){var e;let i=JSON.stringify({blueprint:t,filter:this.filterNameValue}),n=null==(e=document.querySelector("meta[name='csrf-token']"))?void 0:e.content;const s=await fetch(this.updateStableIdUrlValue,{method:"PUT",body:i,headers:{accept:"application/json","content-type":"application/json","X-CSRF-Token":n}}),a=await s.json();return s.ok?{stableId:a.filter_id}:{errors:a.errors}}}f.values={stableId:String,updateStableIdUrl:String,filterName:String},f.targets=[];class g extends a{initialize(){this.updateBlueprint=n((t,e,i)=>{this.value(t,e,i),this.createStableId(this.state.blueprint,this.state.filterName)},500)}connect(){a.prototype.connect.apply(this),this.state.updateStableId(this.stableIdValue)}refinedFilter(t){const{criterionIdValue:e,state:i}=this;i.updateInput(e,{id:t.target.value},t.target.dataset.inputId),this.submitForm()}clause(t){const{criterionIdValue:e,state:i}=this;i.updateInput(e,{clause:t.target.value},t.target.dataset.inputId),this.submitForm()}selected(t){const{target:e}=t,i=Array.prototype.slice.call(e.options).filter(t=>t.selected).map(t=>t.value);this.value(t,i,"selected"),this.createStableId(this.state.blueprint,this.state.filterName)}value(t,e,i){const{criterionIdValue:n,state:s}=this,a=t.target.dataset;s.updateInput(n,{[i=i||a.inputKey||"value"]:e=e||t.target.value},a.inputId)}date(t){const{picker:e}=t.detail,i=e.startDate.format("YYYY-MM-DD");this.value(t,i),this.submitForm()}createStableId(t,e){var i;const{state:n}=this;let s=JSON.stringify({blueprint:t,filter:e}),a=null==(i=document.querySelector("meta[name='csrf-token']"))?void 0:i.content;$.ajax({type:"PUT",url:"/hammerstone/update_stable_id",data:s,headers:{accept:"application/json","content-type":"application/json","X-CSRF-Token":a},success:function(t){n.updateStableId(t.filter_id)}})}condition(t){const{criterionIdValue:e,state:i}=this,n=t.target.value,s=this.state.conditionConfigFor(n);i.replaceCriterion(e,n,s),this.submitForm()}cancelEnter(t){"Enter"===t.code&&(t.preventDefault(),t.stopPropagation())}}g.values={criterionId:Number,stableId:String};const v=[[r,"refine/add-controller.js"],[l,"refine/defaults-controller.js"],[o,"refine/delete-controller.js"],[a,"refine/form-controller.js"],[c,"refine/search-filter-controller.js"],[b,"refine/state-controller.js"],[m,"refine/stored-filter-controller.js"],[f,"refine/stabilize-filter-controller.js"],[g,"refine/update-controller.js"]].map(function(t){const e=t[0];return{identifier:s(t[1]),controllerConstructor:e}});export{r as AddController,l as DefaultsController,o as DeleteController,a as FormController,c as SearchFilterController,f as StabilizeFilterController,b as StateController,m as StoredFilterController,g as UpdateController,v as controllerDefinitions}; | ||
import{Controller as t}from"@hotwired/stimulus";import{delegate as e,abnegate as i}from"jquery-events-to-dom-events";import{debounce as n}from"lodash";function a(t){const e=(t.match(/^(?:\.\/)?(.+)(?:[_-]controller\..+?)$/)||[])[1];if(e)return e.replace(/_/g,"-").replace(/\//g,"--")}class s extends t{connect(){this.state=this.getStateController(),this.blueprintInput=this.addHiddenInput("blueprint"),this.addHiddenInput("filter",this.state.filterName),this.addHiddenInput("id_suffix",this.state.idSuffix),this.finishUpdate()}getStateController(){let t=this.element;for(;t!==document.body;){const e=this.application.getControllerForElementAndIdentifier(t,"refine--state");if(e)return e;t=t.parentNode}return null}addHiddenInput(t,e){const i=document.createElement("input");return i.type="hidden",i.name=t,i.value=e||"",this.element.appendChild(i),i}finishUpdate(){this.state.finishUpdate()}startUpdate(){this.blueprintInput.value=JSON.stringify(this.state.blueprint),this.state.startUpdate()}submitForm(){this.startUpdate(),this.element.requestSubmit()}}class r extends s{criterion(){this.state.addCriterion(this.previousCriterionIdValue),this.startUpdate()}group(){this.state.addGroup(),this.startUpdate()}}r.values={previousCriterionId:Number};class l extends t{connect(){this.state=this.getStateController(),this.state.updateInput(this.criterionIdValue,this.inputValue)}getStateController(){let t=this.element;for(;t!==document.body;){const e=this.application.getControllerForElementAndIdentifier(t,"refine--state");if(e)return e;t=t.parentNode}return null}}l.values={criterionId:Number,input:Object};class o extends s{criterion(){const{state:t,criterionIdValue:e}=this;t.deleteCriterion(e),this.startUpdate()}}function d(){return d=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var i=arguments[e];for(var n in i)Object.prototype.hasOwnProperty.call(i,n)&&(t[n]=i[n])}return t},d.apply(this,arguments)}o.values={criterionId:Number};class u extends t{connect(){const t=new URLSearchParams(window.location.search);this.existingParams=t,this.existingParams.delete("stable_id")}search(t){t.preventDefault(),this.submitFilter(),document.activeElement.blur()}async submitFilter(){const{blueprint:t}=this.stateController,e=await this.stabilizeFilterController.validateBlueprint(t);e.stableId?this.redirectToStableId(e.stableId):this.fetchAndRenderInvalidFilter(t)}addHiddenInput({name:t,value:e}){const i=document.createElement("input");i.type="hidden",i.name=t,i.value=e,this.submissionFormTarget.appendChild(i)}get stateController(){return this.element.querySelector('[data-controller~="refine--state"]').refineStateController}get stabilizeFilterController(){return this.element.stabilizeFilterController}redirectToStableId(t){const e=new URLSearchParams;t&&e.append("stable_id",t);const i=new URLSearchParams(d({},Object.fromEntries(this.existingParams),Object.fromEntries(e))).toString(),n=`${window.location.pathname}?${i}`;history.pushState({},document.title,n),window.location.reload()}async fetchAndRenderInvalidFilter(t){var e;const i=await fetch(this.submitUrlValue,{headers:{Accept:"application/json","Content-Type":"application/json","X-CSRF-Token":null==(e=document.querySelector("meta[name='csrf-token']"))?void 0:e.content},method:"POST",body:JSON.stringify({filter:this.stateController.filterName,blueprint:JSON.stringify(t),id_suffix:this.stateController.idSuffix})}),n=await i.json();document.getElementById(n.target).outerHTML=n.template}}u.values={submitUrl:String},u.targets=[],function(){if("function"==typeof window.CustomEvent)return!1;function t(t,e){e=e||{bubbles:!1,cancelable:!1,detail:void 0};var i=document.createEvent("CustomEvent");return i.initCustomEvent(t,e.bubbles,e.cancelable,e.detail),i}t.prototype=window.Event.prototype,window.CustomEvent=t}();const c=(t,e,i,n)=>{const a=new CustomEvent("filter-stabilized",{bubbles:!0,cancelable:!0,detail:{stableId:e,filterName:i,initialLoad:n}});t.dispatchEvent(a)},h=(t,e)=>{const i=new CustomEvent("blueprint-updated",{bubbles:!0,cancelable:!0,detail:{blueprint:e}});t.dispatchEvent(i)},p=(t,e,i)=>{const{meta:n,refinements:a,component:s}=i,{clauses:r,options:l}=n;let o={clause:r[0].id,selected:"option-condition"===s?[l[0].id]:void 0};return a.forEach(t=>{var e;const{meta:i,component:n}=t,{clauses:a,options:s}=i;o[t.id]={clause:a[0].id,selected:"option-condition"===n?[null==(e=s[0])?void 0:e.id]:void 0}}),{depth:e,type:"criterion",condition_id:t,input:o}};class b extends t{connect(){this.element.refineStateController=this,this.changeDelegate=e("change",["event","picker"]),this.blueprint=this.blueprintValue,this.conditions=this.conditionsValue,this.filterName=this.classNameValue,this.idSuffix=this.idSuffixValue,this.stableId=this.stableIdValue,this.conditionsLookup=this.conditions.reduce((t,e)=>(t[e.id]=e,t),{}),this.loadingTimeout=null,h(this.element,this.blueprint)}disconnect(){i("change",this.changeDelegate)}startUpdate(){this.loadingTimeout&&window.clearTimeout(this.loadingTimeout),this.loadingTimeout=window.setTimeout(()=>{document.activeElement.blur(),this.loadingTarget.classList.remove("hidden")},1e3)}finishUpdate(){this.loadingTimeout&&window.clearTimeout(this.loadingTimeout),this.loadingTarget.classList.add("hidden")}conditionConfigFor(t){return this.conditionsLookup[t]}updateStableId(t){t!==this.stableId&&(this.stableId=t)}addGroup(){const{conditions:t}=this,e=t[0];var i;this.blueprint.length>0&&this.blueprint.push({depth:i=void 0===i?0:i,type:"conjunction",word:"or"}),this.blueprint.push(p(e.id,1,e)),h(this.element,this.blueprint)}addCriterion(t){const{blueprint:e,conditions:i}=this,n=i[0];var a;e.splice(t+1,0,{depth:a=void 0===a?1:a,type:"conjunction",word:"and"},p(n.id,1,n)),h(this.element,this.blueprint)}deleteCriterion(t){const{blueprint:e}=this,i=e[t-1],n=e[t+1],a=i&&"or"===i.word,s=n&&"or"===n.word||!n,r=a||!i,l=r&&s;i||n?e.splice(l&&a?t-1:l&&!i||r&&!s?t:t-1,2):this.blueprint=[],h(this.element,this.blueprint)}replaceCriterion(t,e,i){const n=this.blueprint[t];if("criterion"!==n.type)throw new Error(`You can't call updateConditionId on a non-criterion type. Trying to update ${JSON.stringify(p)}`);this.blueprint[t]=p(e,n.depth,i),h(this.element,this.blueprint)}updateInput(t,e,i){const{blueprint:n}=this,a=n[t],s=(i=i||"input").split(", ");s.length>1?a[s[0]][s[1]]=d({},a[s[0]][s[1]],e):a[i]=d({},a[i],e),h(this.element,this.blueprint)}}b.values={blueprint:Array,conditions:Array,className:String,stableId:String,idSuffix:String},b.targets=["loading"];class m extends t{connect(){this.idValue&&(t=>{const e=new CustomEvent("filter-stored",{bubbles:!0,cancelable:!0,detail:{storedFilterId:this.idValue}});window.dispatchEvent(e)})()}updateStableIdField(t){if(t.detail.filterName!=this.filterNameValue)return null;if(this.hasStableIdFieldTarget){const{detail:e}=t,{stableId:i}=e;this.stableIdFieldTarget.value=i}}activateSaveLink(t){const{detail:e}=t,{stableId:i,initialLoad:n}=e;if(t.detail.filterName!=this.filterNameValue)return null;if(this.hasEnabledSaveLinkTarget&&this.hasDisabledSaveLinkTarget&&!n){const t=new URL(this.enabledSaveLinkTarget.href);t.searchParams.set("stable_id",i),this.enabledSaveLinkTarget.setAttribute("href",t),this.disabledSaveLinkTarget.classList.add("hidden"),this.enabledSaveLinkTarget.classList.remove("hidden")}}}m.targets=["enabledSaveLink","disabledSaveLink","stableIdField"],m.values={id:Number,stableId:String,filterName:String};class f extends t{connect(){this.element.stabilizeFilterController=this,this.stableIdValue=new URLSearchParams(window.location.search).get("stable_id")}async updateStableId(t){(t=>{const e=new CustomEvent("filter-unstable",{bubbles:!0,cancelable:!0,detail:{blueprint:this.blueprint}});window.dispatchEvent(e)})();const e=t.detail.blueprint,i=await this.validateBlueprint(e);if(i.stableId)this.stableIdValue=i.stableId,c(this.element,this.stableIdValue,this.filterNameValue),c(window,this.stableIdValue,this.filterNameValue);else{const{errors:t}=i;(({blueprint:t,errors:e})=>{const i=new CustomEvent("filter-invalid",{bubbles:!0,cancelable:!0,detail:{blueprint:t,errors:e}});window.dispatchEvent(i)})({blueprint:e,errors:t})}}async validateBlueprint(t){var e;let i=JSON.stringify({blueprint:t,filter:this.filterNameValue}),n=null==(e=document.querySelector("meta[name='csrf-token']"))?void 0:e.content;const a=await fetch(this.updateStableIdUrlValue,{method:"PUT",body:i,headers:{accept:"application/json","content-type":"application/json","X-CSRF-Token":n}}),s=await a.json();return a.ok?{stableId:s.filter_id}:{errors:s.errors}}}f.values={stableId:String,updateStableIdUrl:String,filterName:String},f.targets=[];class v extends s{initialize(){this.updateBlueprint=n((t,e,i)=>{this.value(t,e,i),this.createStableId(this.state.blueprint,this.state.filterName)},500)}connect(){s.prototype.connect.apply(this),this.state.updateStableId(this.stableIdValue)}refinedFilter(t){const{criterionIdValue:e,state:i}=this;i.updateInput(e,{id:t.target.value},t.target.dataset.inputId),this.submitForm()}clause(t){const{criterionIdValue:e,state:i}=this;i.updateInput(e,{clause:t.target.value},t.target.dataset.inputId),this.submitForm()}selected(t){const{target:e}=t,i=Array.prototype.slice.call(e.options).filter(t=>t.selected).map(t=>t.value);this.value(t,i,"selected"),this.createStableId(this.state.blueprint,this.state.filterName)}value(t,e,i){const{criterionIdValue:n,state:a}=this,s=t.target.dataset;a.updateInput(n,{[i=i||s.inputKey||"value"]:e=e||t.target.value},s.inputId)}date(t){const{picker:e}=t.detail,i=e.startDate.format("YYYY-MM-DD");this.value(t,i),this.submitForm()}createStableId(t,e){var i;const{state:n}=this;let a=JSON.stringify({blueprint:t,filter:e}),s=null==(i=document.querySelector("meta[name='csrf-token']"))?void 0:i.content;$.ajax({type:"PUT",url:"/hammerstone/update_stable_id",data:a,headers:{accept:"application/json","content-type":"application/json","X-CSRF-Token":s},success:function(t){n.updateStableId(t.filter_id)}})}condition(t){const{criterionIdValue:e,state:i}=this,n=t.target.value,a=this.state.conditionConfigFor(n);i.replaceCriterion(e,n,a),this.submitForm()}cancelEnter(t){"Enter"===t.code&&(t.preventDefault(),t.stopPropagation())}}v.values={criterionId:Number,stableId:String};const g=[[r,"refine/add-controller.js"],[l,"refine/defaults-controller.js"],[o,"refine/delete-controller.js"],[s,"refine/form-controller.js"],[u,"refine/search-filter-controller.js"],[b,"refine/state-controller.js"],[m,"refine/stored-filter-controller.js"],[f,"refine/stabilize-filter-controller.js"],[v,"refine/update-controller.js"]].map(function(t){const e=t[0];return{identifier:a(t[1]),controllerConstructor:e}});export{r as AddController,l as DefaultsController,o as DeleteController,s as FormController,u as SearchFilterController,f as StabilizeFilterController,b as StateController,m as StoredFilterController,v as UpdateController,g as controllerDefinitions}; | ||
//# sourceMappingURL=refine-stimulus.modern.js.map |
@@ -1,2 +0,2 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@hotwired/stimulus"),require("jquery-events-to-dom-events"),require("lodash")):"function"==typeof define&&define.amd?define(["exports","@hotwired/stimulus","jquery-events-to-dom-events","lodash"],t):t((e||self).refineStimulus={},e.Stimulus,e.jqueryEventsToDomEvents,e.lodash)}(this,function(e,t,i,n){function r(e){const t=(e.match(/^(?:\.\/)?(.+)(?:[_-]controller\..+?)$/)||[])[1];if(t)return t.replace(/_/g,"-").replace(/\//g,"--")}class l extends t.Controller{connect(){console.log("Form Controller Connected"),this.state=this.getStateController(),this.blueprintInput=this.addHiddenInput("blueprint"),this.addHiddenInput("filter",this.state.filterName),this.addHiddenInput("id_suffix",this.state.idSuffix),this.finishUpdate()}getStateController(){let e=this.element;for(;e!==document.body;){const t=this.application.getControllerForElementAndIdentifier(e,"refine--state");if(t)return t;e=e.parentNode}return null}addHiddenInput(e,t){const i=document.createElement("input");return i.type="hidden",i.name=e,i.value=t||"",this.element.appendChild(i),i}finishUpdate(){this.state.finishUpdate()}startUpdate(){this.blueprintInput.value=JSON.stringify(this.state.blueprint),this.state.startUpdate()}submitForm(){this.startUpdate(),this.element.requestSubmit()}}class s extends l{criterion(){this.state.addCriterion(this.previousCriterionIdValue),this.startUpdate()}group(){this.state.addGroup(),this.startUpdate()}}s.values={previousCriterionId:Number};class a extends t.Controller{connect(){this.state=this.getStateController(),this.state.updateInput(this.criterionIdValue,this.inputValue)}getStateController(){let e=this.element;for(;e!==document.body;){const t=this.application.getControllerForElementAndIdentifier(e,"refine--state");if(t)return t;e=e.parentNode}return null}}a.values={criterionId:Number,input:Object};class o extends l{criterion(){const{state:e,criterionIdValue:t}=this;e.deleteCriterion(t),this.startUpdate()}}o.values={criterionId:Number};class d extends t.Controller{connect(){console.log("Seacrch filter connected!");const e=new URLSearchParams(window.location.search);this.existingParams=e,this.existingParams.delete("stable_id")}search(e){console.log("search!"),e.preventDefault(),this.submitFilter(),document.activeElement.blur()}submitFilter(){try{const e=this,{blueprint:t}=e.stateController;return Promise.resolve(e.stabilizeFilterController.validateBlueprint(t)).then(function(i){console.log("validationResult",i),i.stableId?e.redirectToStableId(i.stableId):e.fetchAndRenderInvalidFilter(t)})}catch(e){return Promise.reject(e)}}addHiddenInput(e){let{name:t,value:i}=e;const n=document.createElement("input");n.type="hidden",n.name=t,n.value=i,this.submissionFormTarget.appendChild(n)}get stateController(){return this.element.querySelector('[data-controller~="refine--state"]').refineStateController}get stabilizeFilterController(){return this.element.stabilizeFilterController}redirectToStableId(e){const t=new URLSearchParams;e&&t.append("stable_id",e);const i=new URLSearchParams({...Object.fromEntries(this.existingParams),...Object.fromEntries(t)}).toString(),n=window.location.pathname+"?"+i;history.pushState({},document.title,n),window.location.reload()}fetchAndRenderInvalidFilter(e){try{var t;const i=this;return console.log("this.submitUrlValue",i.submitUrlValue),Promise.resolve(fetch(i.submitUrlValue,{headers:{Accept:"application/json","Content-Type":"application/json","X-CSRF-Token":null==(t=document.querySelector("meta[name='csrf-token']"))?void 0:t.content},method:"POST",body:JSON.stringify({filter:i.stateController.filterName,blueprint:JSON.stringify(e),id_suffix:i.stateController.idSuffix})})).then(function(e){return Promise.resolve(e.json()).then(function(e){document.getElementById(e.target).outerHTML=e.template})})}catch(e){return Promise.reject(e)}}}d.values={submitUrl:String},d.targets=[],function(){if("function"==typeof window.CustomEvent)return!1;function e(e,t){t=t||{bubbles:!1,cancelable:!1,detail:void 0};var i=document.createEvent("CustomEvent");return i.initCustomEvent(e,t.bubbles,t.cancelable,t.detail),i}e.prototype=window.Event.prototype,window.CustomEvent=e}();const u=(e,t,i,n)=>{const r=new CustomEvent("filter-stabilized",{bubbles:!0,cancelable:!0,detail:{stableId:t,filterName:i,initialLoad:n}});e.dispatchEvent(r)},c=(e,t)=>{const i=new CustomEvent("blueprint-updated",{bubbles:!0,cancelable:!0,detail:{blueprint:t}});e.dispatchEvent(i)},h=(e,t,i)=>{const{meta:n,refinements:r,component:l}=i,{clauses:s,options:a}=n;let o={clause:s[0].id,selected:"option-condition"===l?[a[0].id]:void 0};return r.forEach(e=>{var t;const{meta:i,component:n}=e,{clauses:r,options:l}=i;o[e.id]={clause:r[0].id,selected:"option-condition"===n?[null==(t=l[0])?void 0:t.id]:void 0}}),{depth:t,type:"criterion",condition_id:e,input:o}};class p extends t.Controller{connect(){this.element.refineStateController=this,this.changeDelegate=i.delegate("change",["event","picker"]),this.blueprint=this.blueprintValue,this.conditions=this.conditionsValue,this.filterName=this.classNameValue,this.idSuffix=this.idSuffixValue,this.stableId=this.stableIdValue,this.conditionsLookup=this.conditions.reduce((e,t)=>(e[t.id]=t,e),{}),this.loadingTimeout=null,c(this.element,this.blueprint)}disconnect(){i.abnegate("change",this.changeDelegate)}startUpdate(){this.loadingTimeout&&window.clearTimeout(this.loadingTimeout),this.loadingTimeout=window.setTimeout(()=>{document.activeElement.blur(),this.loadingTarget.classList.remove("hidden")},1e3)}finishUpdate(){this.loadingTimeout&&window.clearTimeout(this.loadingTimeout),this.loadingTarget.classList.add("hidden")}conditionConfigFor(e){return this.conditionsLookup[e]}updateStableId(e){e!==this.stableId&&(this.stableId=e)}addGroup(){const{conditions:e}=this,t=e[0];var i;this.blueprint.length>0&&this.blueprint.push({depth:i=void 0===i?0:i,type:"conjunction",word:"or"}),this.blueprint.push(h(t.id,1,t)),c(this.element,this.blueprint)}addCriterion(e){const{blueprint:t,conditions:i}=this,n=i[0];var r;t.splice(e+1,0,{depth:r=void 0===r?1:r,type:"conjunction",word:"and"},h(n.id,1,n)),c(this.element,this.blueprint)}deleteCriterion(e){const{blueprint:t}=this,i=t[e-1],n=t[e+1],r=i&&"or"===i.word,l=n&&"or"===n.word||!n,s=r||!i,a=s&&l;if(i||n?t.splice(a&&r?e-1:a&&!i||s&&!l?e:e-1,2):this.blueprint=[],0===this.blueprint.length){const e=this.conditions[0];this.blueprint.push(h(e.id,1,e))}c(this.element,this.blueprint)}replaceCriterion(e,t,i){const n=this.blueprint[e];if("criterion"!==n.type)throw new Error("You can't call updateConditionId on a non-criterion type. Trying to update "+JSON.stringify(h));this.blueprint[e]=h(t,n.depth,i),c(this.element,this.blueprint)}updateInput(e,t,i){const{blueprint:n}=this,r=n[e],l=(i=i||"input").split(", ");l.length>1?r[l[0]][l[1]]={...r[l[0]][l[1]],...t}:r[i]={...r[i],...t},c(this.element,this.blueprint)}}p.values={blueprint:Array,conditions:Array,className:String,stableId:String,idSuffix:String},p.targets=["loading"];class b extends t.Controller{connect(){this.idValue&&(e=>{const t=new CustomEvent("filter-stored",{bubbles:!0,cancelable:!0,detail:{storedFilterId:this.idValue}});window.dispatchEvent(t)})()}updateStableIdField(e){if(e.detail.filterName!=this.filterNameValue)return null;if(this.hasStableIdFieldTarget){const{detail:t}=e,{stableId:i}=t;this.stableIdFieldTarget.value=i}}activateSaveLink(e){const{detail:t}=e,{stableId:i,initialLoad:n}=t;if(e.detail.filterName!=this.filterNameValue)return null;if(this.hasEnabledSaveLinkTarget&&this.hasDisabledSaveLinkTarget&&!n){const e=new URL(this.enabledSaveLinkTarget.href);e.searchParams.set("stable_id",i),this.enabledSaveLinkTarget.setAttribute("href",e),this.disabledSaveLinkTarget.classList.add("hidden"),this.enabledSaveLinkTarget.classList.remove("hidden")}}}b.targets=["enabledSaveLink","disabledSaveLink","stableIdField"],b.values={id:Number,stableId:String,filterName:String};class m extends t.Controller{connect(){this.element.stabilizeFilterController=this,this.stableIdValue=new URLSearchParams(window.location.search).get("stable_id")}updateStableId(e){try{const t=this;(e=>{const t=new CustomEvent("filter-unstable",{bubbles:!0,cancelable:!0,detail:{blueprint:e}});window.dispatchEvent(t)})(t.blueprint);const i=e.detail.blueprint;return Promise.resolve(t.validateBlueprint(i)).then(function(e){if(e.stableId)t.stableIdValue=e.stableId,u(t.element,t.stableIdValue,t.filterNameValue),u(window,t.stableIdValue,t.filterNameValue);else{const{errors:t}=e;(e=>{let{blueprint:t,errors:i}=e;const n=new CustomEvent("filter-invalid",{bubbles:!0,cancelable:!0,detail:{blueprint:t,errors:i}});window.dispatchEvent(n)})({blueprint:i,errors:t})}})}catch(e){return Promise.reject(e)}}validateBlueprint(e){try{var t;const i=this;let n=JSON.stringify({blueprint:e,filter:i.filterNameValue}),r=null==(t=document.querySelector("meta[name='csrf-token']"))?void 0:t.content;return Promise.resolve(fetch(i.updateStableIdUrlValue,{method:"PUT",body:n,headers:{accept:"application/json","content-type":"application/json","X-CSRF-Token":r}})).then(function(e){return Promise.resolve(e.json()).then(function(t){return e.ok?{stableId:t.filter_id}:{errors:t.errors}})})}catch(e){return Promise.reject(e)}}}m.values={stableId:String,updateStableIdUrl:String,filterName:String},m.targets=[];class f extends l{initialize(){this.updateBlueprint=n.debounce((e,t,i)=>{this.value(e,t,i),this.createStableId(this.state.blueprint,this.state.filterName)},500)}connect(){l.prototype.connect.apply(this),this.state.updateStableId(this.stableIdValue)}refinedFilter(e){const{criterionIdValue:t,state:i}=this;i.updateInput(t,{id:e.target.value},e.target.dataset.inputId),this.submitForm()}clause(e){const{criterionIdValue:t,state:i}=this;i.updateInput(t,{clause:e.target.value},e.target.dataset.inputId),this.submitForm()}selected(e){const{target:t}=e,i=Array.prototype.slice.call(t.options).filter(e=>e.selected).map(e=>e.value);this.value(e,i,"selected"),this.createStableId(this.state.blueprint,this.state.filterName)}value(e,t,i){const{criterionIdValue:n,state:r}=this,l=e.target.dataset;r.updateInput(n,{[i=i||l.inputKey||"value"]:t=t||e.target.value},l.inputId)}date(e){const{picker:t}=e.detail,i=t.startDate.format("YYYY-MM-DD");this.value(e,i),this.submitForm()}createStableId(e,t){var i;const{state:n}=this;let r=JSON.stringify({blueprint:e,filter:t}),l=null==(i=document.querySelector("meta[name='csrf-token']"))?void 0:i.content;$.ajax({type:"PUT",url:"/hammerstone/update_stable_id",data:r,headers:{accept:"application/json","content-type":"application/json","X-CSRF-Token":l},success:function(e){n.updateStableId(e.filter_id)}})}condition(e){const{criterionIdValue:t,state:i}=this,n=e.target.value,r=this.state.conditionConfigFor(n);i.replaceCriterion(t,n,r),this.submitForm()}cancelEnter(e){"Enter"===e.code&&(e.preventDefault(),e.stopPropagation())}}f.values={criterionId:Number,stableId:String};const v=[[s,"refine/add-controller.js"],[a,"refine/defaults-controller.js"],[o,"refine/delete-controller.js"],[l,"refine/form-controller.js"],[d,"refine/search-filter-controller.js"],[p,"refine/state-controller.js"],[b,"refine/stored-filter-controller.js"],[m,"refine/stabilize-filter-controller.js"],[f,"refine/update-controller.js"]].map(function(e){const t=e[0];return{identifier:r(e[1]),controllerConstructor:t}});e.AddController=s,e.DefaultsController=a,e.DeleteController=o,e.FormController=l,e.SearchFilterController=d,e.StabilizeFilterController=m,e.StateController=p,e.StoredFilterController=b,e.UpdateController=f,e.controllerDefinitions=v}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@hotwired/stimulus"),require("jquery-events-to-dom-events"),require("lodash")):"function"==typeof define&&define.amd?define(["exports","@hotwired/stimulus","jquery-events-to-dom-events","lodash"],t):t((e||self).refineStimulus={},e.Stimulus,e.jqueryEventsToDomEvents,e.lodash)}(this,function(e,t,i,n){function r(e){const t=(e.match(/^(?:\.\/)?(.+)(?:[_-]controller\..+?)$/)||[])[1];if(t)return t.replace(/_/g,"-").replace(/\//g,"--")}class s extends t.Controller{connect(){this.state=this.getStateController(),this.blueprintInput=this.addHiddenInput("blueprint"),this.addHiddenInput("filter",this.state.filterName),this.addHiddenInput("id_suffix",this.state.idSuffix),this.finishUpdate()}getStateController(){let e=this.element;for(;e!==document.body;){const t=this.application.getControllerForElementAndIdentifier(e,"refine--state");if(t)return t;e=e.parentNode}return null}addHiddenInput(e,t){const i=document.createElement("input");return i.type="hidden",i.name=e,i.value=t||"",this.element.appendChild(i),i}finishUpdate(){this.state.finishUpdate()}startUpdate(){this.blueprintInput.value=JSON.stringify(this.state.blueprint),this.state.startUpdate()}submitForm(){this.startUpdate(),this.element.requestSubmit()}}class l extends s{criterion(){this.state.addCriterion(this.previousCriterionIdValue),this.startUpdate()}group(){this.state.addGroup(),this.startUpdate()}}l.values={previousCriterionId:Number};class a extends t.Controller{connect(){this.state=this.getStateController(),this.state.updateInput(this.criterionIdValue,this.inputValue)}getStateController(){let e=this.element;for(;e!==document.body;){const t=this.application.getControllerForElementAndIdentifier(e,"refine--state");if(t)return t;e=e.parentNode}return null}}a.values={criterionId:Number,input:Object};class o extends s{criterion(){const{state:e,criterionIdValue:t}=this;e.deleteCriterion(t),this.startUpdate()}}o.values={criterionId:Number};class d extends t.Controller{connect(){const e=new URLSearchParams(window.location.search);this.existingParams=e,this.existingParams.delete("stable_id")}search(e){e.preventDefault(),this.submitFilter(),document.activeElement.blur()}submitFilter(){try{const e=this,{blueprint:t}=e.stateController;return Promise.resolve(e.stabilizeFilterController.validateBlueprint(t)).then(function(i){i.stableId?e.redirectToStableId(i.stableId):e.fetchAndRenderInvalidFilter(t)})}catch(e){return Promise.reject(e)}}addHiddenInput(e){let{name:t,value:i}=e;const n=document.createElement("input");n.type="hidden",n.name=t,n.value=i,this.submissionFormTarget.appendChild(n)}get stateController(){return this.element.querySelector('[data-controller~="refine--state"]').refineStateController}get stabilizeFilterController(){return this.element.stabilizeFilterController}redirectToStableId(e){const t=new URLSearchParams;e&&t.append("stable_id",e);const i=new URLSearchParams({...Object.fromEntries(this.existingParams),...Object.fromEntries(t)}).toString(),n=window.location.pathname+"?"+i;history.pushState({},document.title,n),window.location.reload()}fetchAndRenderInvalidFilter(e){try{var t;const i=this;return Promise.resolve(fetch(i.submitUrlValue,{headers:{Accept:"application/json","Content-Type":"application/json","X-CSRF-Token":null==(t=document.querySelector("meta[name='csrf-token']"))?void 0:t.content},method:"POST",body:JSON.stringify({filter:i.stateController.filterName,blueprint:JSON.stringify(e),id_suffix:i.stateController.idSuffix})})).then(function(e){return Promise.resolve(e.json()).then(function(e){document.getElementById(e.target).outerHTML=e.template})})}catch(e){return Promise.reject(e)}}}d.values={submitUrl:String},d.targets=[],function(){if("function"==typeof window.CustomEvent)return!1;function e(e,t){t=t||{bubbles:!1,cancelable:!1,detail:void 0};var i=document.createEvent("CustomEvent");return i.initCustomEvent(e,t.bubbles,t.cancelable,t.detail),i}e.prototype=window.Event.prototype,window.CustomEvent=e}();const u=(e,t,i,n)=>{const r=new CustomEvent("filter-stabilized",{bubbles:!0,cancelable:!0,detail:{stableId:t,filterName:i,initialLoad:n}});e.dispatchEvent(r)},c=(e,t)=>{const i=new CustomEvent("blueprint-updated",{bubbles:!0,cancelable:!0,detail:{blueprint:t}});e.dispatchEvent(i)},h=(e,t,i)=>{const{meta:n,refinements:r,component:s}=i,{clauses:l,options:a}=n;let o={clause:l[0].id,selected:"option-condition"===s?[a[0].id]:void 0};return r.forEach(e=>{var t;const{meta:i,component:n}=e,{clauses:r,options:s}=i;o[e.id]={clause:r[0].id,selected:"option-condition"===n?[null==(t=s[0])?void 0:t.id]:void 0}}),{depth:t,type:"criterion",condition_id:e,input:o}};class p extends t.Controller{connect(){this.element.refineStateController=this,this.changeDelegate=i.delegate("change",["event","picker"]),this.blueprint=this.blueprintValue,this.conditions=this.conditionsValue,this.filterName=this.classNameValue,this.idSuffix=this.idSuffixValue,this.stableId=this.stableIdValue,this.conditionsLookup=this.conditions.reduce((e,t)=>(e[t.id]=t,e),{}),this.loadingTimeout=null,c(this.element,this.blueprint)}disconnect(){i.abnegate("change",this.changeDelegate)}startUpdate(){this.loadingTimeout&&window.clearTimeout(this.loadingTimeout),this.loadingTimeout=window.setTimeout(()=>{document.activeElement.blur(),this.loadingTarget.classList.remove("hidden")},1e3)}finishUpdate(){this.loadingTimeout&&window.clearTimeout(this.loadingTimeout),this.loadingTarget.classList.add("hidden")}conditionConfigFor(e){return this.conditionsLookup[e]}updateStableId(e){e!==this.stableId&&(this.stableId=e)}addGroup(){const{conditions:e}=this,t=e[0];var i;this.blueprint.length>0&&this.blueprint.push({depth:i=void 0===i?0:i,type:"conjunction",word:"or"}),this.blueprint.push(h(t.id,1,t)),c(this.element,this.blueprint)}addCriterion(e){const{blueprint:t,conditions:i}=this,n=i[0];var r;t.splice(e+1,0,{depth:r=void 0===r?1:r,type:"conjunction",word:"and"},h(n.id,1,n)),c(this.element,this.blueprint)}deleteCriterion(e){const{blueprint:t}=this,i=t[e-1],n=t[e+1],r=i&&"or"===i.word,s=n&&"or"===n.word||!n,l=r||!i,a=l&&s;i||n?t.splice(a&&r?e-1:a&&!i||l&&!s?e:e-1,2):this.blueprint=[],c(this.element,this.blueprint)}replaceCriterion(e,t,i){const n=this.blueprint[e];if("criterion"!==n.type)throw new Error("You can't call updateConditionId on a non-criterion type. Trying to update "+JSON.stringify(h));this.blueprint[e]=h(t,n.depth,i),c(this.element,this.blueprint)}updateInput(e,t,i){const{blueprint:n}=this,r=n[e],s=(i=i||"input").split(", ");s.length>1?r[s[0]][s[1]]={...r[s[0]][s[1]],...t}:r[i]={...r[i],...t},c(this.element,this.blueprint)}}p.values={blueprint:Array,conditions:Array,className:String,stableId:String,idSuffix:String},p.targets=["loading"];class b extends t.Controller{connect(){this.idValue&&(e=>{const t=new CustomEvent("filter-stored",{bubbles:!0,cancelable:!0,detail:{storedFilterId:this.idValue}});window.dispatchEvent(t)})()}updateStableIdField(e){if(e.detail.filterName!=this.filterNameValue)return null;if(this.hasStableIdFieldTarget){const{detail:t}=e,{stableId:i}=t;this.stableIdFieldTarget.value=i}}activateSaveLink(e){const{detail:t}=e,{stableId:i,initialLoad:n}=t;if(e.detail.filterName!=this.filterNameValue)return null;if(this.hasEnabledSaveLinkTarget&&this.hasDisabledSaveLinkTarget&&!n){const e=new URL(this.enabledSaveLinkTarget.href);e.searchParams.set("stable_id",i),this.enabledSaveLinkTarget.setAttribute("href",e),this.disabledSaveLinkTarget.classList.add("hidden"),this.enabledSaveLinkTarget.classList.remove("hidden")}}}b.targets=["enabledSaveLink","disabledSaveLink","stableIdField"],b.values={id:Number,stableId:String,filterName:String};class m extends t.Controller{connect(){this.element.stabilizeFilterController=this,this.stableIdValue=new URLSearchParams(window.location.search).get("stable_id")}updateStableId(e){try{const t=this;(e=>{const t=new CustomEvent("filter-unstable",{bubbles:!0,cancelable:!0,detail:{blueprint:e}});window.dispatchEvent(t)})(t.blueprint);const i=e.detail.blueprint;return Promise.resolve(t.validateBlueprint(i)).then(function(e){if(e.stableId)t.stableIdValue=e.stableId,u(t.element,t.stableIdValue,t.filterNameValue),u(window,t.stableIdValue,t.filterNameValue);else{const{errors:t}=e;(e=>{let{blueprint:t,errors:i}=e;const n=new CustomEvent("filter-invalid",{bubbles:!0,cancelable:!0,detail:{blueprint:t,errors:i}});window.dispatchEvent(n)})({blueprint:i,errors:t})}})}catch(e){return Promise.reject(e)}}validateBlueprint(e){try{var t;const i=this;let n=JSON.stringify({blueprint:e,filter:i.filterNameValue}),r=null==(t=document.querySelector("meta[name='csrf-token']"))?void 0:t.content;return Promise.resolve(fetch(i.updateStableIdUrlValue,{method:"PUT",body:n,headers:{accept:"application/json","content-type":"application/json","X-CSRF-Token":r}})).then(function(e){return Promise.resolve(e.json()).then(function(t){return e.ok?{stableId:t.filter_id}:{errors:t.errors}})})}catch(e){return Promise.reject(e)}}}m.values={stableId:String,updateStableIdUrl:String,filterName:String},m.targets=[];class f extends s{initialize(){this.updateBlueprint=n.debounce((e,t,i)=>{this.value(e,t,i),this.createStableId(this.state.blueprint,this.state.filterName)},500)}connect(){s.prototype.connect.apply(this),this.state.updateStableId(this.stableIdValue)}refinedFilter(e){const{criterionIdValue:t,state:i}=this;i.updateInput(t,{id:e.target.value},e.target.dataset.inputId),this.submitForm()}clause(e){const{criterionIdValue:t,state:i}=this;i.updateInput(t,{clause:e.target.value},e.target.dataset.inputId),this.submitForm()}selected(e){const{target:t}=e,i=Array.prototype.slice.call(t.options).filter(e=>e.selected).map(e=>e.value);this.value(e,i,"selected"),this.createStableId(this.state.blueprint,this.state.filterName)}value(e,t,i){const{criterionIdValue:n,state:r}=this,s=e.target.dataset;r.updateInput(n,{[i=i||s.inputKey||"value"]:t=t||e.target.value},s.inputId)}date(e){const{picker:t}=e.detail,i=t.startDate.format("YYYY-MM-DD");this.value(e,i),this.submitForm()}createStableId(e,t){var i;const{state:n}=this;let r=JSON.stringify({blueprint:e,filter:t}),s=null==(i=document.querySelector("meta[name='csrf-token']"))?void 0:i.content;$.ajax({type:"PUT",url:"/hammerstone/update_stable_id",data:r,headers:{accept:"application/json","content-type":"application/json","X-CSRF-Token":s},success:function(e){n.updateStableId(e.filter_id)}})}condition(e){const{criterionIdValue:t,state:i}=this,n=e.target.value,r=this.state.conditionConfigFor(n);i.replaceCriterion(t,n,r),this.submitForm()}cancelEnter(e){"Enter"===e.code&&(e.preventDefault(),e.stopPropagation())}}f.values={criterionId:Number,stableId:String};const v=[[l,"refine/add-controller.js"],[a,"refine/defaults-controller.js"],[o,"refine/delete-controller.js"],[s,"refine/form-controller.js"],[d,"refine/search-filter-controller.js"],[p,"refine/state-controller.js"],[b,"refine/stored-filter-controller.js"],[m,"refine/stabilize-filter-controller.js"],[f,"refine/update-controller.js"]].map(function(e){const t=e[0];return{identifier:r(e[1]),controllerConstructor:t}});e.AddController=l,e.DefaultsController=a,e.DeleteController=o,e.FormController=s,e.SearchFilterController=d,e.StabilizeFilterController=m,e.StateController=p,e.StoredFilterController=b,e.UpdateController=f,e.controllerDefinitions=v}); | ||
//# sourceMappingURL=refine-stimulus.umd.js.map |
@@ -5,3 +5,2 @@ import { Controller } from "@hotwired/stimulus" | ||
connect() { | ||
console.log('Form Controller Connected') | ||
this.state = this.getStateController() | ||
@@ -8,0 +7,0 @@ this.blueprintInput = this.addHiddenInput('blueprint') |
@@ -10,3 +10,2 @@ import { Controller } from "@hotwired/stimulus" | ||
connect() { | ||
console.log("Seacrch filter connected!") | ||
const urlParams = new URLSearchParams(window.location.search) | ||
@@ -18,3 +17,2 @@ this.existingParams = urlParams | ||
search(event) { | ||
console.log("search!") | ||
event.preventDefault() | ||
@@ -28,3 +26,2 @@ this.submitFilter() | ||
const validationResult = await this.stabilizeFilterController.validateBlueprint(blueprint) | ||
console.log('validationResult', validationResult) | ||
if (validationResult.stableId) { | ||
@@ -74,3 +71,2 @@ this.redirectToStableId(validationResult.stableId) | ||
async fetchAndRenderInvalidFilter(blueprint) { | ||
console.log('this.submitUrlValue', this.submitUrlValue) | ||
const response = await fetch(this.submitUrlValue, { | ||
@@ -77,0 +73,0 @@ headers: { |
@@ -175,13 +175,2 @@ import { Controller } from "@hotwired/stimulus" | ||
/** | ||
* Blueprints always have an initial value so we don't have | ||
* an awkward empty state in the UI | ||
*/ | ||
if (this.blueprint.length === 0) { | ||
const condition = this.conditions[0] | ||
const { meta } = condition | ||
this.blueprint.push(criterion(condition.id, 1, condition)) | ||
} | ||
blueprintUpdatedEvent(this.element, this.blueprint) | ||
@@ -188,0 +177,0 @@ } |
@@ -1,2 +0,6 @@ | ||
### 2.2.0 2022-08-02 | ||
### 2.2.1 2022-08-30 | ||
* bug-fix | ||
* Allow deletion of single condition to blank filter state | ||
### 2.2.0 2022-08-29 | ||
* Load all stored filters when using stored filters view (bug - need to add scoping to filter) | ||
@@ -3,0 +7,0 @@ * Remove workspace_record from stored filters. Client will need to override this controller to get custom attributes on stored filters |
{ | ||
"name": "@hammerstone/refine-stimulus", | ||
"version": "2.2.0", | ||
"version": "2.2.1", | ||
"description": "Refine is a flexible query builder for your apps. It lets your users filter down to exactly what they're looking for. Completely configured on the backend.", | ||
@@ -5,0 +5,0 @@ "browserslist": [ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
222598
815