@hammerstone/refine-stimulus
Advanced tools
Comparing version 2.1.0 to 2.2.0
@@ -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 o 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}}o.values={criterionId:Number,input:Object};class l extends a{criterion(){const{state:t,criterionIdValue:e}=this;t.deleteCriterion(e),this.startUpdate()}}l.values={criterionId:Number},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 s=new CustomEvent("filter-stabilized",{bubbles:!0,cancelable:!0,detail:{stableId:e,filterName:i,initialLoad:n}});t.dispatchEvent(s)},u=t=>{const e=new CustomEvent("filter-unstable",{detail:{blueprint:t}});window.dispatchEvent(e)},c=t=>{const e=new CustomEvent("blueprint-updated",{detail:{blueprint:t}});window.dispatchEvent(e)},h=(t,e,i)=>{const{meta:n,refinements:s,component:a}=i,{clauses:r,options:o}=n;let l={clause:r[0].id,selected:"option-condition"===a?[o[0].id]:void 0};return s.forEach(t=>{const{meta:e,component:i}=t,{clauses:n,options:s}=e;l[t.id]={clause:n[0].id,selected:"option-condition"===i?[s[0].id]:void 0}}),{depth:e,type:"criterion",condition_id:t,input:l}};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,d(this.element,this.stableId,this.filterName,!0),d(window,this.stableId,this.filterName,!0)}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,d(this.element,this.stableId,this.filterName),d(window,this.stableId,this.filterName))}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.blueprint),u(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"},h(n.id,1,n)),c(this.blueprint),u(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,o=r&&a;if(i||n?e.splice(o&&s?t-1:o&&!i||r&&!a?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.blueprint),u(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.blueprint),u(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]]={...s[a[0]][a[1]],...e}:s[i]={...s[i],...e},c(this.blueprint),u(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",{detail:{storedFilterId:this.idValue}});window.dispatchEvent(e)})()}updateStableIdField(t){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(i==this.stableIdValue&&(t.preventDefault(),t.stopPropagation()),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};class m 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())}}m.values={criterionId:Number,stableId:String};const f=[[r,"refine/add-controller.js"],[o,"refine/defaults-controller.js"],[l,"refine/delete-controller.js"],[a,"refine/form-controller.js"],[p,"refine/state-controller.js"],[b,"refine/stored-filter-controller.js"],[m,"refine/update-controller.js"]].map(function(t){const e=t[0];return{identifier:s(t[1]),controllerConstructor:e}});export{r as AddController,o as DefaultsController,l as DeleteController,a as FormController,p as StateController,b as StoredFilterController,m as UpdateController,f 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(){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}; | ||
//# 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 s 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 r extends s{criterion(){this.state.addCriterion(this.previousCriterionIdValue),this.startUpdate()}group(){this.state.addGroup(),this.startUpdate()}}r.values={previousCriterionId:Number};class a 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}}a.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},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 l=(t,e,i,n)=>{const s=new CustomEvent("filter-stabilized",{bubbles:!0,cancelable:!0,detail:{stableId:e,filterName:i,initialLoad:n}});t.dispatchEvent(s)},d=t=>{const e=new CustomEvent("filter-unstable",{detail:{blueprint:t}});window.dispatchEvent(e)},u=t=>{const e=new CustomEvent("blueprint-updated",{detail:{blueprint:t}});window.dispatchEvent(e)},c=(t,e,i)=>{const{meta:n,refinements:s,component:r}=i,{clauses:a,options:o}=n;let l={clause:a[0].id,selected:"option-condition"===r?[o[0].id]:void 0};return s.forEach(t=>{const{meta:e,component:i}=t,{clauses:n,options:s}=e;l[t.id]={clause:n[0].id,selected:"option-condition"===i?[s[0].id]:void 0}}),{depth:e,type:"criterion",condition_id:t,input:l}};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,l(this.element,this.stableId,this.filterName,!0),l(window,this.stableId,this.filterName,!0)}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,l(this.element,this.stableId,this.filterName),l(window,this.stableId,this.filterName))}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.blueprint),d(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"},c(n.id,1,n)),u(this.blueprint),d(this.blueprint)}deleteCriterion(t){const{blueprint:e}=this,i=e[t-1],n=e[t+1],s=i&&"or"===i.word,r=n&&"or"===n.word||!n,a=s||!i,o=a&&r;if(i||n?e.splice(o&&s?t-1:o&&!i||a&&!r?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.blueprint),d(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.blueprint),d(this.blueprint)}updateInput(t,e,i){const{blueprint:n}=this,s=n[t],r=(i=i||"input").split(", ");r.length>1?s[r[0]][r[1]]={...s[r[0]][r[1]],...e}:s[i]={...s[i],...e},u(this.blueprint),d(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",{detail:{storedFilterId:this.idValue}});window.dispatchEvent(e)})()}updateStableIdField(t){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(i==this.stableIdValue&&(t.preventDefault(),t.stopPropagation()),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};class b extends s{initialize(){this.updateBlueprint=i.debounce((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:s}=this,r=t.target.dataset;s.updateInput(n,{[i=i||r.inputKey||"value"]:e=e||t.target.value},r.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}),r=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":r},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())}}b.values={criterionId:Number,stableId:String};const m=[[r,"refine/add-controller.js"],[a,"refine/defaults-controller.js"],[o,"refine/delete-controller.js"],[s,"refine/form-controller.js"],[h,"refine/state-controller.js"],[p,"refine/stored-filter-controller.js"],[b,"refine/update-controller.js"]].map(function(t){const e=t[0];return{identifier:n(t[1]),controllerConstructor:e}});exports.AddController=r,exports.DefaultsController=a,exports.DeleteController=o,exports.FormController=s,exports.StateController=h,exports.StoredFilterController=p,exports.UpdateController=b,exports.controllerDefinitions=m; | ||
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; | ||
//# 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 o 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}}o.values={criterionId:Number,input:Object};class l 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)}l.values={criterionId:Number},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)},c=t=>{const e=new CustomEvent("filter-unstable",{detail:{blueprint:t}});window.dispatchEvent(e)},h=t=>{const e=new CustomEvent("blueprint-updated",{detail:{blueprint:t}});window.dispatchEvent(e)},p=(t,e,i)=>{const{meta:n,refinements:s,component:a}=i,{clauses:r,options:o}=n;let l={clause:r[0].id,selected:"option-condition"===a?[o[0].id]:void 0};return s.forEach(t=>{const{meta:e,component:i}=t,{clauses:n,options:s}=e;l[t.id]={clause:n[0].id,selected:"option-condition"===i?[s[0].id]:void 0}}),{depth:e,type:"criterion",condition_id:t,input:l}};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,u(this.element,this.stableId,this.filterName,!0),u(window,this.stableId,this.filterName,!0)}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,u(this.element,this.stableId,this.filterName),u(window,this.stableId,this.filterName))}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.blueprint),c(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.blueprint),c(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,o=r&&a;if(i||n?e.splice(o&&s?t-1:o&&!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.blueprint),c(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.blueprint),c(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.blueprint),c(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",{detail:{storedFilterId:this.idValue}});window.dispatchEvent(e)})()}updateStableIdField(t){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(i==this.stableIdValue&&(t.preventDefault(),t.stopPropagation()),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};class f 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())}}f.values={criterionId:Number,stableId:String};const v=[[r,"refine/add-controller.js"],[o,"refine/defaults-controller.js"],[l,"refine/delete-controller.js"],[a,"refine/form-controller.js"],[b,"refine/state-controller.js"],[m,"refine/stored-filter-controller.js"],[f,"refine/update-controller.js"]].map(function(t){const e=t[0];return{identifier:s(t[1]),controllerConstructor:e}});export{r as AddController,o as DefaultsController,l as DeleteController,a as FormController,b as StateController,m 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 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}; | ||
//# sourceMappingURL=refine-stimulus.modern.js.map |
@@ -1,2 +0,2 @@ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(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"],e):e((t||self).refineStimulus={},t.Stimulus,t.jqueryEventsToDomEvents,t.lodash)}(this,function(t,e,i,n){function s(t){const e=(t.match(/^(?:\.\/)?(.+)(?:[_-]controller\..+?)$/)||[])[1];if(e)return e.replace(/_/g,"-").replace(/\//g,"--")}class r extends e.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 a extends r{criterion(){this.state.addCriterion(this.previousCriterionIdValue),this.startUpdate()}group(){this.state.addGroup(),this.startUpdate()}}a.values={previousCriterionId:Number};class o extends e.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}}o.values={criterionId:Number,input:Object};class l extends r{criterion(){const{state:t,criterionIdValue:e}=this;t.deleteCriterion(e),this.startUpdate()}}l.values={criterionId:Number},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 s=new CustomEvent("filter-stabilized",{bubbles:!0,cancelable:!0,detail:{stableId:e,filterName:i,initialLoad:n}});t.dispatchEvent(s)},u=t=>{const e=new CustomEvent("filter-unstable",{detail:{blueprint:t}});window.dispatchEvent(e)},c=t=>{const e=new CustomEvent("blueprint-updated",{detail:{blueprint:t}});window.dispatchEvent(e)},h=(t,e,i)=>{const{meta:n,refinements:s,component:r}=i,{clauses:a,options:o}=n;let l={clause:a[0].id,selected:"option-condition"===r?[o[0].id]:void 0};return s.forEach(t=>{const{meta:e,component:i}=t,{clauses:n,options:s}=e;l[t.id]={clause:n[0].id,selected:"option-condition"===i?[s[0].id]:void 0}}),{depth:e,type:"criterion",condition_id:t,input:l}};class p extends e.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((t,e)=>(t[e.id]=e,t),{}),this.loadingTimeout=null,d(this.element,this.stableId,this.filterName,!0),d(window,this.stableId,this.filterName,!0)}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(t){return this.conditionsLookup[t]}updateStableId(t){t!==this.stableId&&(this.stableId=t,d(this.element,this.stableId,this.filterName),d(window,this.stableId,this.filterName))}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.blueprint),u(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"},h(n.id,1,n)),c(this.blueprint),u(this.blueprint)}deleteCriterion(t){const{blueprint:e}=this,i=e[t-1],n=e[t+1],s=i&&"or"===i.word,r=n&&"or"===n.word||!n,a=s||!i,o=a&&r;if(i||n?e.splice(o&&s?t-1:o&&!i||a&&!r?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.blueprint),u(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.blueprint),u(this.blueprint)}updateInput(t,e,i){const{blueprint:n}=this,s=n[t],r=(i=i||"input").split(", ");r.length>1?s[r[0]][r[1]]={...s[r[0]][r[1]],...e}:s[i]={...s[i],...e},c(this.blueprint),u(this.blueprint)}}p.values={blueprint:Array,conditions:Array,className:String,stableId:String,idSuffix:String},p.targets=["loading"];class b extends e.Controller{connect(){this.idValue&&(t=>{const e=new CustomEvent("filter-stored",{detail:{storedFilterId:this.idValue}});window.dispatchEvent(e)})()}updateStableIdField(t){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(i==this.stableIdValue&&(t.preventDefault(),t.stopPropagation()),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};class f extends r{initialize(){this.updateBlueprint=n.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:s}=this,r=t.target.dataset;s.updateInput(n,{[i=i||r.inputKey||"value"]:e=e||t.target.value},r.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}),r=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":r},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())}}f.values={criterionId:Number,stableId:String};const m=[[a,"refine/add-controller.js"],[o,"refine/defaults-controller.js"],[l,"refine/delete-controller.js"],[r,"refine/form-controller.js"],[p,"refine/state-controller.js"],[b,"refine/stored-filter-controller.js"],[f,"refine/update-controller.js"]].map(function(t){const e=t[0];return{identifier:s(t[1]),controllerConstructor:e}});t.AddController=a,t.DefaultsController=o,t.DeleteController=l,t.FormController=r,t.StateController=p,t.StoredFilterController=b,t.UpdateController=f,t.controllerDefinitions=m}); | ||
!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}); | ||
//# sourceMappingURL=refine-stimulus.umd.js.map |
@@ -7,4 +7,6 @@ import { identifierForContextKey } from "@hotwired/stimulus-webpack-helpers" | ||
import FormController from './refine/form-controller' | ||
import SearchFilterController from './refine/search-filter-controller' | ||
import StateController from './refine/state-controller' | ||
import StoredFilterController from './refine/stored-filter-controller' | ||
import StabilizeFilterController from './refine/stabilize-filter-controller' | ||
import UpdateController from './refine/update-controller' | ||
@@ -17,4 +19,6 @@ | ||
[FormController, 'refine/form-controller.js'], | ||
[SearchFilterController, 'refine/search-filter-controller.js'], | ||
[StateController, 'refine/state-controller.js'], | ||
[StoredFilterController, 'refine/stored-filter-controller.js'], | ||
[StabilizeFilterController, 'refine/stabilize-filter-controller.js'], | ||
[UpdateController, 'refine/update-controller.js'] | ||
@@ -35,5 +39,7 @@ ].map(function(d) { | ||
FormController, | ||
SearchFilterController, | ||
StateController, | ||
StoredFilterController, | ||
StabilizeFilterController, | ||
UpdateController | ||
} | ||
} |
import { Controller } from "@hotwired/stimulus" | ||
import { delegate, abnegate } from 'jquery-events-to-dom-events' | ||
import { filterUnstableEvent, filterStabilizedEvent, blueprintUpdatedEvent } from '../../refine/helpers' | ||
import { blueprintUpdatedEvent } from '../../refine/helpers' | ||
@@ -23,3 +23,3 @@ const criterion = (id, depth, condition) => { | ||
clause: clauses[0].id, | ||
selected: isOptionCondition ? [options[0].id] : undefined, | ||
selected: isOptionCondition ? [options[0]?.id] : undefined, | ||
} | ||
@@ -78,5 +78,3 @@ }) | ||
this.loadingTimeout = null | ||
filterStabilizedEvent(this.element, this.stableId, this.filterName, true) | ||
filterStabilizedEvent(window, this.stableId, this.filterName, true) | ||
blueprintUpdatedEvent(this.element, this.blueprint) | ||
} | ||
@@ -114,4 +112,2 @@ | ||
this.stableId = newUrl | ||
filterStabilizedEvent(this.element, this.stableId, this.filterName) | ||
filterStabilizedEvent(window, this.stableId, this.filterName) | ||
} | ||
@@ -129,4 +125,3 @@ } | ||
this.blueprint.push(criterion(condition.id, 1, condition)) | ||
blueprintUpdatedEvent(this.blueprint) | ||
filterUnstableEvent(this.blueprint) | ||
blueprintUpdatedEvent(this.element, this.blueprint) | ||
} | ||
@@ -139,4 +134,3 @@ | ||
blueprint.splice(previousCriterionId + 1, 0, and(), criterion(condition.id, 1, condition)) | ||
blueprintUpdatedEvent(this.blueprint) | ||
filterUnstableEvent(this.blueprint) | ||
blueprintUpdatedEvent(this.element, this.blueprint) | ||
} | ||
@@ -197,4 +191,3 @@ | ||
blueprintUpdatedEvent(this.blueprint) | ||
filterUnstableEvent(this.blueprint) | ||
blueprintUpdatedEvent(this.element, this.blueprint) | ||
} | ||
@@ -211,4 +204,3 @@ | ||
this.blueprint[criterionId] = criterion(conditionId, criterionRow.depth, condition) | ||
blueprintUpdatedEvent(this.blueprint) | ||
filterUnstableEvent(this.blueprint) | ||
blueprintUpdatedEvent(this.element, this.blueprint) | ||
} | ||
@@ -228,5 +220,4 @@ | ||
} | ||
blueprintUpdatedEvent(this.blueprint) | ||
filterUnstableEvent(this.blueprint) | ||
blueprintUpdatedEvent(this.element, this.blueprint) | ||
} | ||
} |
@@ -6,3 +6,3 @@ import { Controller } from "@hotwired/stimulus" | ||
static targets = ['enabledSaveLink', 'disabledSaveLink', 'stableIdField'] | ||
static values = { id: Number, stableId: String } | ||
static values = { id: Number, stableId: String, filterName: String } | ||
@@ -16,2 +16,3 @@ connect() { | ||
updateStableIdField(event) { | ||
if (event.detail.filterName != this.filterNameValue) { return null } | ||
if (this.hasStableIdFieldTarget) { | ||
@@ -28,8 +29,3 @@ const { detail } = event | ||
// Don't bubble the filterStabilized event if | ||
// it's not different | ||
if (stableId == this.stableIdValue) { | ||
event.preventDefault() | ||
event.stopPropagation() | ||
} | ||
if (event.detail.filterName != this.filterNameValue) { return null } | ||
if (this.hasEnabledSaveLinkTarget && this.hasDisabledSaveLinkTarget && !initialLoad) { | ||
@@ -36,0 +32,0 @@ const saveUrl = new URL(this.enabledSaveLinkTarget.href) |
@@ -36,2 +36,4 @@ // Polyfill for custom events in IE9-11 | ||
const event = new CustomEvent('filter-unstable', { | ||
bubbles: true, | ||
cancelable: true, | ||
detail: { | ||
@@ -44,4 +46,18 @@ blueprint, | ||
export const filterInvalidEvent = ({blueprint, errors}) => { | ||
const event = new CustomEvent('filter-invalid', { | ||
bubbles: true, | ||
cancelable: true, | ||
detail: { | ||
blueprint, | ||
errors, | ||
}, | ||
}) | ||
window.dispatchEvent(event) | ||
} | ||
export const filterStoredEvent = (storedFilterId) => { | ||
const event = new CustomEvent('filter-stored', { | ||
bubbles: true, | ||
cancelable: true, | ||
detail: { | ||
@@ -54,9 +70,11 @@ storedFilterId, | ||
export const blueprintUpdatedEvent = (blueprint) => { | ||
export const blueprintUpdatedEvent = (element, blueprint) => { | ||
const event = new CustomEvent('blueprint-updated', { | ||
bubbles: true, | ||
cancelable: true, | ||
detail: { | ||
blueprint, | ||
blueprint | ||
}, | ||
}) | ||
window.dispatchEvent(event) | ||
element.dispatchEvent(event) | ||
} |
@@ -0,19 +1,40 @@ | ||
### 2.2.0 2022-08-02 | ||
* Load all stored filters when using stored filters view (bug - need to add scoping to filter) | ||
* Remove workspace_record from stored filters. Client will need to override this controller to get custom attributes on stored filters | ||
* bug-fix | ||
* Add back and save to locales file | ||
* bug-fix | ||
* Allow for option condition to have no values https://github.com/hammerstonedev/refine-rails/pull/40 | ||
* updates | ||
* All filters can be deleted using the delete button - there is no "default" condition | ||
* Load the turbo frame with a "Create a filter" button instead of default condition | ||
* Use @form in `refine_helper` instead of `@refine_filter` for consistency | ||
* https://github.com/hammerstonedev/refine-rails/pull/41 | ||
* updates https://github.com/hammerstonedev/refine-rails/pull/43 | ||
* Add `Filter` button back to `filter_builder_dropdown` partial | ||
* Rename and add `search-filter-controller` Stimulus controller as a helper to get up and running fast | ||
* updates https://github.com/hammerstonedev/refine-rails/pull/42 | ||
* Use blueprint as source of truth - emit `blueprintStabilized` event as main piece of information coming from Refine | ||
* Add stimulus controllers for BT integration -> `stabilize-filter-controller` and `search-filter-controller` to get and push stableId. Optional controllers customers can use for quick setup. | ||
### 2.1.0 2022-08-02 | ||
* updates | ||
* Update from Stiumulus 2 to Stimulus 3. All updates are on the javascript/npm package side, this release updates package.json to use the new package on Stimulus 3. | ||
### 2.0.2 2022-07-24 | ||
* bug-fix | ||
* Move the hammerstone filter application controller helper to controllers/hammerstone so it is accessible via client's application controller if desired. | ||
* bug-fix | ||
* Move the hammerstone filter application controller helper to controllers/hammerstone so it is accessible via client's application controller if desired. | ||
### 2.0.1 2022-07-24 | ||
* bug-fix | ||
* _date_picker.html.erb remove `blur` listener, keep `$change` and add `change` to comply with updated bullet-train_fields npm package. | ||
* bug-fix | ||
* _date_picker.html.erb remove `blur` listener, keep `$change` and add `change` to comply with updated bullet-train_fields npm package. | ||
### 2.0.0 2022-07-24 | ||
* enhancements | ||
* Create app/controllers/concerns/hammerstone_filter.rb that the client can include in their application_controller. This can then be referenced in their controller they want filtered with something like @refine_filter = apply_filter(DevelopersFilter) (If in the developer_controller and want to apply DevelopersFilter) | ||
Reference in client application_controller.rb include HammerstoneFilter | ||
* Add the search_filter_controller to the npm package. Note: this is not in the refine folder b/c it's not necessarily required | ||
* Allow client to use ENV or Rails credentials. Need a better solution here. | ||
* Add filter_builder_dropdown to ship with the gem so they can just render the partial. In their index view they can simply -> <%= render partial: 'hammerstone/filter_builder_dropdown' %> | ||
* Add locales | ||
* Add routes | ||
* enhancements | ||
* Create app/controllers/concerns/hammerstone_filter.rb that the client can include in their application_controller. This can then be referenced in their controller they want filtered with something like @refine_filter = apply_filter(DevelopersFilter) (If in the developer_controller and want to apply DevelopersFilter) | ||
Reference in client application_controller.rb include HammerstoneFilter | ||
* Add the search_filter_controller to the npm package. Note: this is not in the refine folder b/c it's not necessarily required | ||
* Allow client to use ENV or Rails credentials. Need a better solution here. | ||
* Add filter_builder_dropdown to ship with the gem so they can just render the partial. In their index view they can simply -> <%= render partial: 'hammerstone/filter_builder_dropdown' %> | ||
* Add locales | ||
* Add routes |
{ | ||
"name": "@hammerstone/refine-stimulus", | ||
"version": "2.0.0", | ||
"version": "2.2.0", | ||
"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": [ |
@@ -68,3 +68,10 @@ ## Adding Refine to a non Bullet Train application | ||
10. Add jquery | ||
``` | ||
// import { Application } from "stimulus" | ||
import { controllerDefinitions as refineControllers } from "@hammerstone/refine-stimulus" | ||
// window.Stimulus = Application.start() | ||
Stimulus.load(refineControllers) | ||
``` | ||
10. Add jquery (necessary for date picker) | ||
`yarn add jquery` | ||
@@ -121,3 +128,3 @@ | ||
If loading in Bullet Train,the load command is | ||
`application.load(refineControllers)` | ||
`application.load(refineControllers)` and the file is `app/javascript/controllers/index.js` | ||
@@ -169,3 +176,3 @@ To manually register (or extend or provide your own replacement for) each Stimulus controller: | ||
yalc add @hammerstone/refine-stimulus | ||
yalc link @hammerstone/refine-stimulus | ||
``` | ||
@@ -177,3 +184,3 @@ | ||
# From this repo (refine-rails) | ||
yarn | ||
yarn build | ||
yalc push | ||
@@ -180,0 +187,0 @@ ``` |
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
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
227784
23
834
223
10